fuzzer_parser_init:
   33|  4.48k|readstat_parser_t *fuzzer_parser_init(const uint8_t *Data, size_t Size) {
   34|  4.48k|    readstat_parser_t *parser = readstat_parser_init();
   35|  4.48k|    readstat_set_open_handler(parser, rt_open_handler);
   36|  4.48k|    readstat_set_close_handler(parser, rt_close_handler);
   37|  4.48k|    readstat_set_seek_handler(parser, rt_seek_handler);
   38|  4.48k|    readstat_set_read_handler(parser, rt_read_handler);
   39|  4.48k|    readstat_set_update_handler(parser, rt_update_handler);
   40|       |
   41|  4.48k|    readstat_set_metadata_handler(parser, &handle_metadata);
   42|  4.48k|    readstat_set_note_handler(parser, &handle_note);
   43|  4.48k|    readstat_set_variable_handler(parser, &handle_variable);
   44|  4.48k|    readstat_set_fweight_handler(parser, &handle_fweight);
   45|  4.48k|    readstat_set_value_handler(parser, &handle_value);
   46|  4.48k|    readstat_set_value_label_handler(parser, &handle_value_label);
   47|       |
   48|  4.48k|    return parser;
   49|  4.48k|}
fuzz_format.c:handle_metadata:
    8|  3.37k|static int handle_metadata(readstat_metadata_t *metadata, void *ctx) {
    9|  3.37k|    return READSTAT_HANDLER_OK;
  ------------------
  |  |   22|  3.37k|#define READSTAT_HANDLER_OK             0
  ------------------
   10|  3.37k|}
fuzz_format.c:handle_note:
   12|    232|static int handle_note(int index, const char *note, void *ctx) {
   13|    232|    return READSTAT_HANDLER_OK;
  ------------------
  |  |   22|    232|#define READSTAT_HANDLER_OK             0
  ------------------
   14|    232|}
fuzz_format.c:handle_variable:
   21|  35.7k|                           const char *val_labels, void *ctx) {
   22|  35.7k|    return READSTAT_HANDLER_OK;
  ------------------
  |  |   22|  35.7k|#define READSTAT_HANDLER_OK             0
  ------------------
   23|  35.7k|}
fuzz_format.c:handle_value:
   25|  69.4k|static int handle_value(int obs_index, readstat_variable_t *variable, readstat_value_t value, void *ctx) {
   26|  69.4k|    return READSTAT_HANDLER_OK;
  ------------------
  |  |   22|  69.4k|#define READSTAT_HANDLER_OK             0
  ------------------
   27|  69.4k|}
fuzz_format.c:handle_value_label:
   29|  41.4k|static int handle_value_label(const char *val_labels, readstat_value_t value, const char *label, void *ctx) {
   30|  41.4k|    return READSTAT_HANDLER_OK;
  ------------------
  |  |   22|  41.4k|#define READSTAT_HANDLER_OK             0
  ------------------
   31|  41.4k|}

LLVMFuzzerTestOneInput:
   10|  4.48k|int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
   11|  4.48k|    rt_buffer_t buffer = { .bytes = (char *)Data, .size = Size, .used = Size };
   12|  4.48k|    rt_buffer_ctx_t buffer_ctx = { .buffer = &buffer };
   13|       |
   14|  4.48k|    readstat_parser_t *parser = fuzzer_parser_init(Data, Size);
   15|  4.48k|    readstat_set_io_ctx(parser, &buffer_ctx);
   16|       |
   17|  4.48k|    readstat_parse_dta(parser, NULL, NULL);
   18|  4.48k|    readstat_parser_free(parser);
   19|  4.48k|    return 0;
   20|  4.48k|}

machine_is_little_endian:
   11|  8.05k|int machine_is_little_endian(void) {
   12|  8.05k|    int test_byte_order = 1;
   13|  8.05k|    return ((char *)&test_byte_order)[0];
   14|  8.05k|}
byteswap2:
   40|   180k|uint16_t byteswap2(uint16_t num) {
   41|   180k|    return ((num & 0xFF00) >> 8) | ((num & 0x00FF) << 8);
   42|   180k|}
byteswap4:
   44|  19.9k|uint32_t byteswap4(uint32_t num) {
   45|  19.9k|    num = ((num & 0xFFFF0000) >> 16) | ((num & 0x0000FFFF) << 16);
   46|  19.9k|    return ((num & 0xFF00FF00) >> 8) | ((num & 0x00FF00FF) << 8);
   47|  19.9k|}
byteswap8:
   49|  4.45k|uint64_t byteswap8(uint64_t num) {
   50|  4.45k|    num = ((num & 0xFFFFFFFF00000000) >> 32) | ((num & 0x00000000FFFFFFFF) << 32);
   51|  4.45k|    num = ((num & 0xFFFF0000FFFF0000) >> 16) | ((num & 0x0000FFFF0000FFFF) << 16);
   52|  4.45k|    return ((num & 0xFF00FF00FF00FF00) >> 8) | ((num & 0x00FF00FF00FF00FF) << 8);
   53|  4.45k|}

readstat_convert:
   39|   313k|readstat_error_t readstat_convert(char *dst, size_t dst_len, const char *src, size_t src_len, iconv_t converter) {
   40|   313k|    return readstat_convert_impl(dst, dst_len, src, src_len, converter, 1);
   41|   313k|}
readstat_convert_notrim:
   43|  4.22k|readstat_error_t readstat_convert_notrim(char *dst, size_t dst_len, const char *src, size_t src_len, iconv_t converter) {
   44|  4.22k|    return readstat_convert_impl(dst, dst_len, src, src_len, converter, 0);
   45|  4.22k|}
readstat_convert.c:readstat_convert_impl:
    8|   317k|        iconv_t converter, int trim_spaces) {
    9|       |    /* strip off spaces from the input because the programs use ASCII space
   10|       |     * padding even with non-ASCII encoding. */
   11|   334k|    while (src_len && ((trim_spaces && src[src_len-1] == ' ') || src[src_len-1] == '\0')) {
  ------------------
  |  Branch (11:12): [True: 140k, False: 194k]
  |  Branch (11:25): [True: 136k, False: 3.55k]
  |  Branch (11:40): [True: 4.66k, False: 131k]
  |  Branch (11:66): [True: 12.1k, False: 123k]
  ------------------
   12|  16.8k|        src_len--;
   13|  16.8k|    }
   14|   317k|    if (dst_len == 0) {
  ------------------
  |  Branch (14:9): [True: 0, False: 317k]
  ------------------
   15|      0|        return READSTAT_ERROR_CONVERT_LONG_STRING;
   16|   317k|    } else if (converter) {
  ------------------
  |  Branch (16:16): [True: 315k, False: 2.30k]
  ------------------
   17|   315k|        size_t dst_left = dst_len - 1;
   18|   315k|        char *dst_end = dst;
   19|   315k|        size_t status = iconv(converter, (readstat_iconv_inbuf_t)&src, &src_len, &dst_end, &dst_left);
   20|   315k|        if (status == (size_t)-1) {
  ------------------
  |  Branch (20:13): [True: 1.14k, False: 314k]
  ------------------
   21|  1.14k|            if (errno == E2BIG) {
  ------------------
  |  Branch (21:17): [True: 1, False: 1.14k]
  ------------------
   22|      1|                return READSTAT_ERROR_CONVERT_LONG_STRING;
   23|  1.14k|            } else if (errno == EILSEQ) {
  ------------------
  |  Branch (23:24): [True: 1.14k, False: 0]
  ------------------
   24|  1.14k|                return READSTAT_ERROR_CONVERT_BAD_STRING;
   25|  1.14k|            } else if (errno != EINVAL) { /* EINVAL indicates improper truncation; accept it */
  ------------------
  |  Branch (25:24): [True: 0, False: 0]
  ------------------
   26|      0|                return READSTAT_ERROR_CONVERT;
   27|      0|            }
   28|  1.14k|        }
   29|   314k|        dst[dst_len - dst_left - 1] = '\0';
   30|   314k|    } else if (src_len + 1 > dst_len) {
  ------------------
  |  Branch (30:16): [True: 18, False: 2.28k]
  ------------------
   31|     18|        return READSTAT_ERROR_CONVERT_LONG_STRING;
   32|  2.28k|    } else {
   33|  2.28k|        memcpy(dst, src, src_len);
   34|  2.28k|        dst[src_len] = '\0';
   35|  2.28k|    }
   36|   316k|    return READSTAT_OK;
   37|   317k|}

unistd_io_init:
  121|  4.48k|readstat_error_t unistd_io_init(readstat_parser_t *parser) {
  122|  4.48k|    readstat_error_t retval = READSTAT_OK;
  123|  4.48k|    unistd_io_ctx_t *io_ctx = NULL;
  124|       |
  125|  4.48k|    if ((retval = readstat_set_open_handler(parser, unistd_open_handler)) != READSTAT_OK)
  ------------------
  |  Branch (125:9): [True: 0, False: 4.48k]
  ------------------
  126|      0|        return retval;
  127|       |
  128|  4.48k|    if ((retval = readstat_set_close_handler(parser, unistd_close_handler)) != READSTAT_OK)
  ------------------
  |  Branch (128:9): [True: 0, False: 4.48k]
  ------------------
  129|      0|        return retval;
  130|       |
  131|  4.48k|    if ((retval = readstat_set_seek_handler(parser, unistd_seek_handler)) != READSTAT_OK)
  ------------------
  |  Branch (131:9): [True: 0, False: 4.48k]
  ------------------
  132|      0|        return retval;
  133|       |
  134|  4.48k|    if ((retval = readstat_set_read_handler(parser, unistd_read_handler)) != READSTAT_OK)
  ------------------
  |  Branch (134:9): [True: 0, False: 4.48k]
  ------------------
  135|      0|        return retval;
  136|       |
  137|  4.48k|    if ((readstat_set_update_handler(parser, unistd_update_handler)) != READSTAT_OK)
  ------------------
  |  Branch (137:9): [True: 0, False: 4.48k]
  ------------------
  138|      0|        return retval;
  139|       |
  140|  4.48k|    io_ctx = calloc(1, sizeof(unistd_io_ctx_t));
  141|  4.48k|    io_ctx->fd = -1;
  142|       |
  143|  4.48k|    retval = readstat_set_io_ctx(parser, (void*) io_ctx);
  144|  4.48k|    parser->io->io_ctx_needs_free = 1;
  145|       |
  146|  4.48k|    return retval;
  147|  4.48k|}

readstat_malloc:
   10|  13.8k|void *readstat_malloc(size_t len) {
   11|  13.8k|    if (len > MAX_MALLOC_SIZE || len == 0) {
  ------------------
  |  |    3|  27.7k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
  |  Branch (11:9): [True: 0, False: 13.8k]
  |  Branch (11:34): [True: 0, False: 13.8k]
  ------------------
   12|      0|        return NULL;
   13|      0|    }
   14|  13.8k|    return malloc(len);
   15|  13.8k|}
readstat_realloc:
   27|  6.36k|void *readstat_realloc(void *ptr, size_t len) {
   28|  6.36k|    if (len > MAX_MALLOC_SIZE || len == 0) {
  ------------------
  |  |    3|  12.7k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
  |  Branch (28:9): [True: 77, False: 6.28k]
  |  Branch (28:34): [True: 0, False: 6.28k]
  ------------------
   29|     77|        if (ptr)
  ------------------
  |  Branch (29:13): [True: 10, False: 67]
  ------------------
   30|     10|            free(ptr);
   31|     77|        return NULL;
   32|     77|    }
   33|  6.28k|    return realloc(ptr, len);
   34|  6.36k|}

readstat_parser_init:
    6|  4.48k|readstat_parser_t *readstat_parser_init(void) {
    7|  4.48k|    readstat_parser_t *parser = calloc(1, sizeof(readstat_parser_t));
    8|  4.48k|    parser->io = calloc(1, sizeof(readstat_io_t));
    9|  4.48k|    if (unistd_io_init(parser) != READSTAT_OK) {
  ------------------
  |  Branch (9:9): [True: 0, False: 4.48k]
  ------------------
   10|      0|        readstat_parser_free(parser);
   11|      0|        return NULL;
   12|      0|    }
   13|  4.48k|    parser->output_encoding = "UTF-8";
   14|  4.48k|    return parser;
   15|  4.48k|}
readstat_parser_free:
   17|  4.48k|void readstat_parser_free(readstat_parser_t *parser) {
   18|  4.48k|    if (parser) {
  ------------------
  |  Branch (18:9): [True: 4.48k, False: 0]
  ------------------
   19|  4.48k|        if (parser->io) {
  ------------------
  |  Branch (19:13): [True: 4.48k, False: 0]
  ------------------
   20|       |            readstat_set_io_ctx(parser, NULL);
   21|  4.48k|            free(parser->io);
   22|  4.48k|        }
   23|  4.48k|        free(parser);
   24|  4.48k|    }
   25|  4.48k|}
readstat_set_metadata_handler:
   27|  4.48k|readstat_error_t readstat_set_metadata_handler(readstat_parser_t *parser, readstat_metadata_handler metadata_handler) {
   28|  4.48k|    parser->handlers.metadata = metadata_handler;
   29|  4.48k|    return READSTAT_OK;
   30|  4.48k|}
readstat_set_note_handler:
   32|  4.48k|readstat_error_t readstat_set_note_handler(readstat_parser_t *parser, readstat_note_handler note_handler) {
   33|  4.48k|    parser->handlers.note = note_handler;
   34|  4.48k|    return READSTAT_OK;
   35|  4.48k|}
readstat_set_variable_handler:
   37|  4.48k|readstat_error_t readstat_set_variable_handler(readstat_parser_t *parser, readstat_variable_handler variable_handler) {
   38|  4.48k|    parser->handlers.variable = variable_handler;
   39|  4.48k|    return READSTAT_OK;
   40|  4.48k|}
readstat_set_value_handler:
   42|  4.48k|readstat_error_t readstat_set_value_handler(readstat_parser_t *parser, readstat_value_handler value_handler) {
   43|  4.48k|    parser->handlers.value = value_handler;
   44|  4.48k|    return READSTAT_OK;
   45|  4.48k|}
readstat_set_value_label_handler:
   47|  4.48k|readstat_error_t readstat_set_value_label_handler(readstat_parser_t *parser, readstat_value_label_handler label_handler) {
   48|  4.48k|    parser->handlers.value_label = label_handler;
   49|  4.48k|    return READSTAT_OK;
   50|  4.48k|}
readstat_set_fweight_handler:
   62|  4.48k|readstat_error_t readstat_set_fweight_handler(readstat_parser_t *parser, readstat_fweight_handler fweight_handler) {
   63|  4.48k|    parser->handlers.fweight = fweight_handler;
   64|  4.48k|    return READSTAT_OK;
   65|  4.48k|}
readstat_set_open_handler:
   67|  8.97k|readstat_error_t readstat_set_open_handler(readstat_parser_t *parser, readstat_open_handler open_handler) {
   68|  8.97k|    parser->io->open = open_handler;
   69|  8.97k|    return READSTAT_OK;
   70|  8.97k|}
readstat_set_close_handler:
   72|  8.97k|readstat_error_t readstat_set_close_handler(readstat_parser_t *parser, readstat_close_handler close_handler) {
   73|  8.97k|    parser->io->close = close_handler;
   74|  8.97k|    return READSTAT_OK;
   75|  8.97k|}
readstat_set_seek_handler:
   77|  8.97k|readstat_error_t readstat_set_seek_handler(readstat_parser_t *parser, readstat_seek_handler seek_handler) {
   78|  8.97k|    parser->io->seek = seek_handler;
   79|  8.97k|    return READSTAT_OK;
   80|  8.97k|}
readstat_set_read_handler:
   82|  8.97k|readstat_error_t readstat_set_read_handler(readstat_parser_t *parser, readstat_read_handler read_handler) {
   83|  8.97k|    parser->io->read = read_handler;
   84|  8.97k|    return READSTAT_OK;
   85|  8.97k|}
readstat_set_update_handler:
   87|  8.97k|readstat_error_t readstat_set_update_handler(readstat_parser_t *parser, readstat_update_handler update_handler) {
   88|  8.97k|    parser->io->update = update_handler;
   89|  8.97k|    return READSTAT_OK;
   90|  8.97k|}
readstat_set_io_ctx:
   92|  13.4k|readstat_error_t readstat_set_io_ctx(readstat_parser_t *parser, void *io_ctx) {
   93|  13.4k|    if (parser->io->io_ctx_needs_free) {
  ------------------
  |  Branch (93:9): [True: 4.48k, False: 8.97k]
  ------------------
   94|  4.48k|        free(parser->io->io_ctx);
   95|  4.48k|    }
   96|       |
   97|  13.4k|    parser->io->io_ctx = io_ctx;
   98|  13.4k|    parser->io->io_ctx_needs_free = 0;
   99|       |
  100|  13.4k|    return READSTAT_OK;
  101|  13.4k|}

dta_format_is_supported:
   19|  4.01k|int dta_format_is_supported(int ds_format) {
   20|  4.01k|    switch (ds_format) {
  ------------------
  |  Branch (20:13): [True: 4.00k, False: 10]
  ------------------
   21|  1.24k|        case 104: case 105: case 108: case 110: case 111:
  ------------------
  |  Branch (21:9): [True: 670, False: 3.34k]
  |  Branch (21:19): [True: 297, False: 3.71k]
  |  Branch (21:29): [True: 243, False: 3.77k]
  |  Branch (21:39): [True: 22, False: 3.99k]
  |  Branch (21:49): [True: 15, False: 4.00k]
  ------------------
   22|  4.00k|        case 113: case 114: case 115: case 117: case 118: case 119:
  ------------------
  |  Branch (22:9): [True: 406, False: 3.61k]
  |  Branch (22:19): [True: 66, False: 3.95k]
  |  Branch (22:29): [True: 32, False: 3.98k]
  |  Branch (22:39): [True: 1.75k, False: 2.25k]
  |  Branch (22:49): [True: 339, False: 3.67k]
  |  Branch (22:59): [True: 159, False: 3.85k]
  ------------------
   23|  4.00k|            return 1;
   24|  4.01k|    }
   25|     10|    return 0;
   26|  4.01k|}
dta_ctx_alloc:
   28|  4.48k|dta_ctx_t *dta_ctx_alloc(readstat_io_t *io) {
   29|  4.48k|    dta_ctx_t *ctx = calloc(1, sizeof(dta_ctx_t));
   30|  4.48k|    if (ctx == NULL) {
  ------------------
  |  Branch (30:9): [True: 0, False: 4.48k]
  ------------------
   31|      0|        return NULL;
   32|      0|    }
   33|       |
   34|  4.48k|    ctx->io = io;
   35|  4.48k|    ctx->initialized = 0;
   36|       |
   37|  4.48k|    return ctx;
   38|  4.48k|}
dta_ctx_init:
   42|  4.01k|        const char *input_encoding, const char *output_encoding) {
   43|  4.01k|    readstat_error_t retval = READSTAT_OK;
   44|  4.01k|    int machine_byteorder = DTA_HILO;
  ------------------
  |  |  129|  4.01k|#define DTA_HILO  0x01
  ------------------
   45|  4.01k|    if (!dta_format_is_supported(ds_format))
  ------------------
  |  Branch (45:9): [True: 10, False: 4.00k]
  ------------------
   46|     10|        return READSTAT_ERROR_UNSUPPORTED_FILE_FORMAT_VERSION;
   47|       |
   48|  4.00k|    if (machine_is_little_endian()) {
  ------------------
  |  Branch (48:9): [True: 4.00k, False: 0]
  ------------------
   49|  4.00k|        machine_byteorder = DTA_LOHI;
  ------------------
  |  |  130|  4.00k|#define DTA_LOHI  0x02
  ------------------
   50|  4.00k|    }
   51|       |
   52|  4.00k|    ctx->bswap = (byteorder != machine_byteorder);
   53|  4.00k|    ctx->ds_format = ds_format;
   54|  4.00k|    ctx->endianness = byteorder == DTA_LOHI ? READSTAT_ENDIAN_LITTLE : READSTAT_ENDIAN_BIG;
  ------------------
  |  |  130|  4.00k|#define DTA_LOHI  0x02
  ------------------
  |  Branch (54:23): [True: 1.67k, False: 2.33k]
  ------------------
   55|       |
   56|  4.00k|    ctx->nvar = nvar;
   57|  4.00k|    ctx->nobs = nobs;
   58|       |
   59|  4.00k|    if (ctx->nvar) {
  ------------------
  |  Branch (59:9): [True: 2.59k, False: 1.40k]
  ------------------
   60|  2.59k|        if ((ctx->variables = calloc(ctx->nvar, sizeof(readstat_variable_t *))) == NULL) {
  ------------------
  |  Branch (60:13): [True: 27, False: 2.57k]
  ------------------
   61|     27|            retval = READSTAT_ERROR_MALLOC;
   62|     27|            goto cleanup;
   63|     27|        }
   64|  2.59k|    }
   65|       |
   66|  3.97k|    ctx->machine_is_twos_complement = READSTAT_MACHINE_IS_TWOS_COMPLEMENT;
  ------------------
  |  |    8|  3.97k|#define READSTAT_MACHINE_IS_TWOS_COMPLEMENT 0
  ------------------
   67|       |
   68|  3.97k|    if (ds_format < 105) {
  ------------------
  |  Branch (68:9): [True: 670, False: 3.30k]
  ------------------
   69|    670|        ctx->fmtlist_entry_len = 7;
   70|  3.30k|    } else if (ds_format < 114) {
  ------------------
  |  Branch (70:16): [True: 983, False: 2.32k]
  ------------------
   71|    983|        ctx->fmtlist_entry_len = 12;
   72|  2.32k|    } else if (ds_format < 118) {
  ------------------
  |  Branch (72:16): [True: 1.85k, False: 471]
  ------------------
   73|  1.85k|        ctx->fmtlist_entry_len = 49;
   74|  1.85k|    } else {
   75|    471|        ctx->fmtlist_entry_len = 57;
   76|    471|    }
   77|       |    
   78|  3.97k|    if (ds_format >= 117) {
  ------------------
  |  Branch (78:9): [True: 2.22k, False: 1.75k]
  ------------------
   79|  2.22k|        ctx->typlist_version = 117;
   80|  2.22k|    } else if (ds_format >= 111) {
  ------------------
  |  Branch (80:16): [True: 519, False: 1.23k]
  ------------------
   81|    519|        ctx->typlist_version = 111;
   82|  1.23k|    } else {
   83|  1.23k|        ctx->typlist_version = 0;
   84|  1.23k|    }
   85|       |
   86|  3.97k|    if (ds_format >= 119) {
  ------------------
  |  Branch (86:9): [True: 132, False: 3.84k]
  ------------------
   87|       |        /* The 8-byte (v,o) field in the data is a 3-byte v and a 5-byte o */
   88|    132|        ctx->data_label_len_len = 2;
   89|    132|        ctx->strl_v_len = 3;
   90|    132|        ctx->strl_o_len = 5;
   91|  3.84k|    } else if (ds_format >= 118) {
  ------------------
  |  Branch (91:16): [True: 339, False: 3.50k]
  ------------------
   92|    339|        ctx->data_label_len_len = 2;
   93|    339|        ctx->strl_v_len = 2;
   94|    339|        ctx->strl_o_len = 6;
   95|  3.50k|    } else if (ds_format >= 117) {
  ------------------
  |  Branch (95:16): [True: 1.75k, False: 1.75k]
  ------------------
   96|  1.75k|        ctx->data_label_len_len = 1;
   97|  1.75k|        ctx->strl_v_len = 4;
   98|  1.75k|        ctx->strl_o_len = 4;
   99|  1.75k|    }
  100|       |
  101|  3.97k|    if (ds_format < 105) {
  ------------------
  |  Branch (101:9): [True: 670, False: 3.30k]
  ------------------
  102|    670|        ctx->expansion_len_len = 0;
  103|  3.30k|    } else if (ds_format < 110) {
  ------------------
  |  Branch (103:16): [True: 540, False: 2.76k]
  ------------------
  104|    540|        ctx->expansion_len_len = 2;
  105|  2.76k|    } else {
  106|  2.76k|        ctx->expansion_len_len = 4;
  107|  2.76k|    }
  108|       |    
  109|  3.97k|    if (ds_format < 110) {
  ------------------
  |  Branch (109:9): [True: 1.21k, False: 2.76k]
  ------------------
  110|  1.21k|        ctx->lbllist_entry_len = 9;
  111|  1.21k|        ctx->variable_name_len = 9;
  112|  1.21k|        ctx->ch_metadata_len = 9;
  113|  2.76k|    } else if (ds_format < 118) {
  ------------------
  |  Branch (113:16): [True: 2.29k, False: 471]
  ------------------
  114|  2.29k|        ctx->lbllist_entry_len = 33;
  115|  2.29k|        ctx->variable_name_len = 33;
  116|  2.29k|        ctx->ch_metadata_len = 33;
  117|  2.29k|    } else {
  118|    471|        ctx->lbllist_entry_len = 129;
  119|    471|        ctx->variable_name_len = 129;
  120|    471|        ctx->ch_metadata_len = 129;
  121|    471|    }
  122|       |
  123|  3.97k|    if (ds_format < 108) {
  ------------------
  |  Branch (123:9): [True: 967, False: 3.01k]
  ------------------
  124|    967|        ctx->variable_labels_entry_len = 32;
  125|    967|        ctx->data_label_len = 32;
  126|  3.01k|    } else if (ds_format < 118) {
  ------------------
  |  Branch (126:16): [True: 2.54k, False: 471]
  ------------------
  127|  2.54k|        ctx->variable_labels_entry_len = 81;
  128|  2.54k|        ctx->data_label_len = 81;
  129|  2.54k|    } else {
  130|    471|        ctx->variable_labels_entry_len = 321;
  131|    471|        ctx->data_label_len = 321;
  132|    471|    }
  133|       |
  134|  3.97k|    if (ds_format < 105) {
  ------------------
  |  Branch (134:9): [True: 670, False: 3.30k]
  ------------------
  135|    670|        ctx->timestamp_len = 0;
  136|  3.30k|    } else {
  137|  3.30k|        ctx->timestamp_len = 18;
  138|  3.30k|    }
  139|       |
  140|       |    /* Value label tables. Formats 105 and earlier use the "old" layout:
  141|       |     * n (int16), labname (9 bytes), 1 byte of padding, n int16 codes, then n
  142|       |     * 8-byte labels. Format 108 uses the modern layout but with a 9-byte
  143|       |     * label name; later formats widen the name with the variable name. */
  144|  3.97k|    if (ds_format < 108) {
  ------------------
  |  Branch (144:9): [True: 967, False: 3.01k]
  ------------------
  145|    967|        ctx->value_label_table_len_len = 2;
  146|    967|        ctx->value_label_table_labname_len = 9;
  147|    967|        ctx->value_label_table_padding_len = 1;
  148|  3.01k|    } else {
  149|  3.01k|        ctx->value_label_table_len_len = 4;
  150|  3.01k|        if (ds_format < 110) {
  ------------------
  |  Branch (150:13): [True: 243, False: 2.76k]
  ------------------
  151|    243|            ctx->value_label_table_labname_len = 9;
  152|  2.76k|        } else if (ds_format < 118) {
  ------------------
  |  Branch (152:20): [True: 2.29k, False: 471]
  ------------------
  153|  2.29k|            ctx->value_label_table_labname_len = 33;
  154|  2.29k|        } else {
  155|    471|            ctx->value_label_table_labname_len = 129;
  156|    471|        }
  157|  3.01k|        ctx->value_label_table_padding_len = 3;
  158|  3.01k|    }
  159|       |
  160|  3.97k|    if (ds_format < 117) {
  ------------------
  |  Branch (160:9): [True: 1.75k, False: 2.22k]
  ------------------
  161|  1.75k|        ctx->typlist_entry_len = 1;
  162|  1.75k|        ctx->file_is_xmlish = 0;
  163|  2.22k|    } else {
  164|  2.22k|        ctx->typlist_entry_len = 2;
  165|  2.22k|        ctx->file_is_xmlish = 1;
  166|  2.22k|    }
  167|       |
  168|  3.97k|    if (ds_format < 113) {
  ------------------
  |  Branch (168:9): [True: 1.24k, False: 2.73k]
  ------------------
  169|  1.24k|        ctx->max_int8 = DTA_OLD_MAX_INT8;
  ------------------
  |  |  132|  1.24k|#define DTA_OLD_MAX_INT8                     0x7e
  ------------------
  170|  1.24k|        ctx->max_int16 = DTA_OLD_MAX_INT16;
  ------------------
  |  |  133|  1.24k|#define DTA_OLD_MAX_INT16                  0x7ffe
  ------------------
  171|  1.24k|        ctx->max_int32 = DTA_OLD_MAX_INT32;
  ------------------
  |  |  134|  1.24k|#define DTA_OLD_MAX_INT32              0x7ffffffe
  ------------------
  172|  1.24k|        ctx->max_float = DTA_OLD_MAX_FLOAT;
  ------------------
  |  |  135|  1.24k|#define DTA_OLD_MAX_FLOAT              0x7effffff // +1.7e38f
  ------------------
  173|  1.24k|        ctx->max_double = DTA_OLD_MAX_DOUBLE;
  ------------------
  |  |  136|  1.24k|#define DTA_OLD_MAX_DOUBLE     0x7fdfffffffffffffL // +8.9e307
  ------------------
  174|  2.73k|    } else {
  175|  2.73k|        ctx->max_int8 = DTA_113_MAX_INT8;
  ------------------
  |  |  144|  2.73k|#define DTA_113_MAX_INT8                    0x64
  ------------------
  176|  2.73k|        ctx->max_int16 = DTA_113_MAX_INT16;
  ------------------
  |  |  145|  2.73k|#define DTA_113_MAX_INT16                 0x7fe4
  ------------------
  177|  2.73k|        ctx->max_int32 = DTA_113_MAX_INT32;
  ------------------
  |  |  146|  2.73k|#define DTA_113_MAX_INT32             0x7fffffe4
  ------------------
  178|  2.73k|        ctx->max_float = DTA_113_MAX_FLOAT;
  ------------------
  |  |  147|  2.73k|#define DTA_113_MAX_FLOAT             0x7effffff // +1.7e38f
  ------------------
  179|  2.73k|        ctx->max_double = DTA_113_MAX_DOUBLE;
  ------------------
  |  |  148|  2.73k|#define DTA_113_MAX_DOUBLE    0x7fdfffffffffffffL // +8.9e307
  ------------------
  180|       |
  181|  2.73k|        ctx->supports_tagged_missing = 1;
  182|  2.73k|    }
  183|       |
  184|  3.97k|    if (output_encoding) {
  ------------------
  |  Branch (184:9): [True: 3.97k, False: 0]
  ------------------
  185|  3.97k|        if (input_encoding) {
  ------------------
  |  Branch (185:13): [True: 0, False: 3.97k]
  ------------------
  186|      0|            ctx->converter = iconv_open(output_encoding, input_encoding);
  187|  3.97k|        } else if (ds_format < 118) {
  ------------------
  |  Branch (187:20): [True: 3.50k, False: 471]
  ------------------
  188|  3.50k|            ctx->converter = iconv_open(output_encoding, "WINDOWS-1252");
  189|  3.50k|        } else if (strcmp(output_encoding, "UTF-8") != 0) {
  ------------------
  |  Branch (189:20): [True: 0, False: 471]
  ------------------
  190|      0|            ctx->converter = iconv_open(output_encoding, "UTF-8");
  191|      0|        }
  192|  3.97k|        if (ctx->converter == (iconv_t)-1) {
  ------------------
  |  Branch (192:13): [True: 0, False: 3.97k]
  ------------------
  193|      0|            ctx->converter = NULL;
  194|      0|            retval = READSTAT_ERROR_UNSUPPORTED_CHARSET;
  195|      0|            goto cleanup;
  196|      0|        }
  197|  3.97k|    }
  198|       |
  199|  3.97k|    if (ds_format < 119) {
  ------------------
  |  Branch (199:9): [True: 3.84k, False: 132]
  ------------------
  200|  3.84k|        ctx->srtlist_len = (ctx->nvar + 1) * sizeof(int16_t);
  201|  3.84k|    } else {
  202|    132|        ctx->srtlist_len = (ctx->nvar + 1) * sizeof(int32_t);
  203|    132|    }
  204|       |
  205|  3.97k|    if ((ctx->srtlist = malloc(ctx->srtlist_len)) == NULL) {
  ------------------
  |  Branch (205:9): [True: 0, False: 3.97k]
  ------------------
  206|      0|        retval = READSTAT_ERROR_MALLOC;
  207|      0|        goto cleanup;
  208|      0|    }
  209|       |
  210|  3.97k|    if (ctx->nvar > 0) {
  ------------------
  |  Branch (210:9): [True: 2.57k, False: 1.40k]
  ------------------
  211|  2.57k|        if (ctx->file_size > 0) {
  ------------------
  |  Branch (211:13): [True: 2.57k, False: 0]
  ------------------
  212|       |            /* Every variable has a mandatory entry in each descriptor list, so
  213|       |             * a variable count whose descriptors alone exceed the file size
  214|       |             * cannot be read. Reject it here rather than allocating for it. */
  215|  2.57k|            size_t bytes_per_var = ctx->typlist_entry_len + ctx->variable_name_len
  216|  2.57k|                + ctx->fmtlist_entry_len + ctx->lbllist_entry_len + ctx->variable_labels_entry_len
  217|  2.57k|                + (ds_format < 119 ? sizeof(int16_t) : sizeof(int32_t));
  ------------------
  |  Branch (217:20): [True: 2.48k, False: 84]
  ------------------
  218|  2.57k|            if ((uint64_t)ctx->nvar * bytes_per_var > ctx->file_size) {
  ------------------
  |  Branch (218:17): [True: 78, False: 2.49k]
  ------------------
  219|     78|                retval = READSTAT_ERROR_PARSE;
  220|     78|                goto cleanup;
  221|     78|            }
  222|  2.57k|        }
  223|  2.49k|        ctx->typlist_len = ctx->nvar * sizeof(uint16_t);
  224|  2.49k|        ctx->varlist_len = ctx->variable_name_len * ctx->nvar * sizeof(char);
  225|  2.49k|        ctx->fmtlist_len = ctx->fmtlist_entry_len * ctx->nvar * sizeof(char);
  226|  2.49k|        ctx->lbllist_len = ctx->lbllist_entry_len * ctx->nvar * sizeof(char);
  227|  2.49k|        ctx->variable_labels_len = ctx->variable_labels_entry_len * ctx->nvar * sizeof(char);
  228|       |
  229|  2.49k|        if ((ctx->typlist = malloc(ctx->typlist_len)) == NULL) {
  ------------------
  |  Branch (229:13): [True: 0, False: 2.49k]
  ------------------
  230|      0|            retval = READSTAT_ERROR_MALLOC;
  231|      0|            goto cleanup;
  232|      0|        }
  233|  2.49k|        if ((ctx->varlist = malloc(ctx->varlist_len)) == NULL) {
  ------------------
  |  Branch (233:13): [True: 0, False: 2.49k]
  ------------------
  234|      0|            retval = READSTAT_ERROR_MALLOC;
  235|      0|            goto cleanup;
  236|      0|        }
  237|  2.49k|        if ((ctx->fmtlist = malloc(ctx->fmtlist_len)) == NULL) {
  ------------------
  |  Branch (237:13): [True: 0, False: 2.49k]
  ------------------
  238|      0|            retval = READSTAT_ERROR_MALLOC;
  239|      0|            goto cleanup;
  240|      0|        }
  241|  2.49k|        if ((ctx->lbllist = malloc(ctx->lbllist_len)) == NULL) {
  ------------------
  |  Branch (241:13): [True: 0, False: 2.49k]
  ------------------
  242|      0|            retval = READSTAT_ERROR_MALLOC;
  243|      0|            goto cleanup;
  244|      0|        }
  245|  2.49k|        if ((ctx->variable_labels = malloc(ctx->variable_labels_len)) == NULL) {
  ------------------
  |  Branch (245:13): [True: 0, False: 2.49k]
  ------------------
  246|      0|            retval = READSTAT_ERROR_MALLOC;
  247|      0|            goto cleanup;
  248|      0|        }
  249|  2.49k|    }
  250|       |
  251|  3.90k|    ctx->initialized = 1;
  252|       |
  253|  4.00k|cleanup:
  254|  4.00k|    return retval;
  255|  3.90k|}
dta_ctx_free:
  257|  4.48k|void dta_ctx_free(dta_ctx_t *ctx) {
  258|  4.48k|    if (ctx->typlist)
  ------------------
  |  Branch (258:9): [True: 2.49k, False: 1.99k]
  ------------------
  259|  2.49k|        free(ctx->typlist);
  260|  4.48k|    if (ctx->varlist)
  ------------------
  |  Branch (260:9): [True: 2.49k, False: 1.99k]
  ------------------
  261|  2.49k|        free(ctx->varlist);
  262|  4.48k|    if (ctx->srtlist)
  ------------------
  |  Branch (262:9): [True: 3.97k, False: 506]
  ------------------
  263|  3.97k|        free(ctx->srtlist);
  264|  4.48k|    if (ctx->fmtlist)
  ------------------
  |  Branch (264:9): [True: 2.49k, False: 1.99k]
  ------------------
  265|  2.49k|        free(ctx->fmtlist);
  266|  4.48k|    if (ctx->lbllist)
  ------------------
  |  Branch (266:9): [True: 2.49k, False: 1.99k]
  ------------------
  267|  2.49k|        free(ctx->lbllist);
  268|  4.48k|    if (ctx->variable_labels)
  ------------------
  |  Branch (268:9): [True: 2.49k, False: 1.99k]
  ------------------
  269|  2.49k|        free(ctx->variable_labels);
  270|  4.48k|    if (ctx->converter)
  ------------------
  |  Branch (270:9): [True: 3.50k, False: 977]
  ------------------
  271|  3.50k|        iconv_close(ctx->converter);
  272|  4.48k|    if (ctx->data_label)
  ------------------
  |  Branch (272:9): [True: 3.70k, False: 783]
  ------------------
  273|  3.70k|        free(ctx->data_label);
  274|  4.48k|    if (ctx->variables) {
  ------------------
  |  Branch (274:9): [True: 2.57k, False: 1.91k]
  ------------------
  275|  2.57k|        int i;
  276|  2.66G|        for (i=0; i<ctx->nvar; i++) {
  ------------------
  |  Branch (276:19): [True: 2.66G, False: 2.57k]
  ------------------
  277|  2.66G|            if (ctx->variables[i])
  ------------------
  |  Branch (277:17): [True: 35.7k, False: 2.66G]
  ------------------
  278|  35.7k|                free(ctx->variables[i]);
  279|  2.66G|        }
  280|  2.57k|        free(ctx->variables);
  281|  2.57k|    }
  282|  4.48k|    if (ctx->strls) {
  ------------------
  |  Branch (282:9): [True: 958, False: 3.52k]
  ------------------
  283|    958|        int i;
  284|   124k|        for (i=0; i<ctx->strls_count; i++) {
  ------------------
  |  Branch (284:19): [True: 123k, False: 958]
  ------------------
  285|   123k|            free(ctx->strls[i]);
  286|   123k|        }
  287|    958|        free(ctx->strls);
  288|    958|    }
  289|  4.48k|    free(ctx);
  290|  4.48k|}
dta_type_info:
  293|   160k|        size_t *max_len, readstat_type_t *out_type) {
  294|   160k|    readstat_error_t retval = READSTAT_OK;
  295|   160k|    size_t len = 0;
  296|   160k|    readstat_type_t type = READSTAT_TYPE_STRING;
  297|   160k|    if (ctx->typlist_version == 111) {
  ------------------
  |  Branch (297:9): [True: 77.3k, False: 82.8k]
  ------------------
  298|  77.3k|        switch (typecode) {
  299|    628|            case DTA_111_TYPE_CODE_INT8:
  ------------------
  |  |  172|    628|#define DTA_111_TYPE_CODE_INT8     0xFB
  ------------------
  |  Branch (299:13): [True: 628, False: 76.7k]
  ------------------
  300|    628|                len = 1; type = READSTAT_TYPE_INT8; break;
  301|    693|            case DTA_111_TYPE_CODE_INT16:
  ------------------
  |  |  173|    693|#define DTA_111_TYPE_CODE_INT16    0xFC
  ------------------
  |  Branch (301:13): [True: 693, False: 76.6k]
  ------------------
  302|    693|                len = 2; type = READSTAT_TYPE_INT16; break;
  303|  11.9k|            case DTA_111_TYPE_CODE_INT32:
  ------------------
  |  |  174|  11.9k|#define DTA_111_TYPE_CODE_INT32    0xFD
  ------------------
  |  Branch (303:13): [True: 11.9k, False: 65.3k]
  ------------------
  304|  11.9k|                len = 4; type = READSTAT_TYPE_INT32; break;
  305|  3.87k|            case DTA_111_TYPE_CODE_FLOAT:
  ------------------
  |  |  175|  3.87k|#define DTA_111_TYPE_CODE_FLOAT    0xFE
  ------------------
  |  Branch (305:13): [True: 3.87k, False: 73.5k]
  ------------------
  306|  3.87k|                len = 4; type = READSTAT_TYPE_FLOAT; break;
  307|  8.18k|            case DTA_111_TYPE_CODE_DOUBLE:
  ------------------
  |  |  176|  8.18k|#define DTA_111_TYPE_CODE_DOUBLE   0xFF
  ------------------
  |  Branch (307:13): [True: 8.18k, False: 69.1k]
  ------------------
  308|  8.18k|                len = 8; type = READSTAT_TYPE_DOUBLE; break;
  309|  52.0k|            default:
  ------------------
  |  Branch (309:13): [True: 52.0k, False: 25.3k]
  ------------------
  310|  52.0k|                len = typecode; type = READSTAT_TYPE_STRING; break;
  311|  77.3k|        }
  312|  82.8k|    } else if (ctx->typlist_version == 117) {
  ------------------
  |  Branch (312:16): [True: 36.9k, False: 45.8k]
  ------------------
  313|  36.9k|        switch (typecode) {
  314|  1.27k|            case DTA_117_TYPE_CODE_INT8:
  ------------------
  |  |  165|  1.27k|#define DTA_117_TYPE_CODE_INT8     0xFFFA
  ------------------
  |  Branch (314:13): [True: 1.27k, False: 35.6k]
  ------------------
  315|  1.27k|                len = 1; type = READSTAT_TYPE_INT8; break;
  316|  1.71k|            case DTA_117_TYPE_CODE_INT16:
  ------------------
  |  |  166|  1.71k|#define DTA_117_TYPE_CODE_INT16    0xFFF9
  ------------------
  |  Branch (316:13): [True: 1.71k, False: 35.2k]
  ------------------
  317|  1.71k|                len = 2; type = READSTAT_TYPE_INT16; break;
  318|  1.50k|            case DTA_117_TYPE_CODE_INT32:
  ------------------
  |  |  167|  1.50k|#define DTA_117_TYPE_CODE_INT32    0xFFF8
  ------------------
  |  Branch (318:13): [True: 1.50k, False: 35.4k]
  ------------------
  319|  1.50k|                len = 4; type = READSTAT_TYPE_INT32; break;
  320|    806|            case DTA_117_TYPE_CODE_FLOAT:
  ------------------
  |  |  168|    806|#define DTA_117_TYPE_CODE_FLOAT    0xFFF7
  ------------------
  |  Branch (320:13): [True: 806, False: 36.1k]
  ------------------
  321|    806|                len = 4; type = READSTAT_TYPE_FLOAT; break;
  322|    911|            case DTA_117_TYPE_CODE_DOUBLE:
  ------------------
  |  |  169|    911|#define DTA_117_TYPE_CODE_DOUBLE   0xFFF6
  ------------------
  |  Branch (322:13): [True: 911, False: 36.0k]
  ------------------
  323|    911|                len = 8; type = READSTAT_TYPE_DOUBLE; break;
  324|  27.9k|            case DTA_117_TYPE_CODE_STRL:
  ------------------
  |  |  170|  27.9k|#define DTA_117_TYPE_CODE_STRL     0x8000
  ------------------
  |  Branch (324:13): [True: 27.9k, False: 8.93k]
  ------------------
  325|  27.9k|                len = 8; type = READSTAT_TYPE_STRING_REF; break;
  326|  2.72k|            default:
  ------------------
  |  Branch (326:13): [True: 2.72k, False: 34.2k]
  ------------------
  327|  2.72k|                len = typecode; type = READSTAT_TYPE_STRING; break;
  328|  36.9k|        }
  329|  45.8k|    } else if (typecode < 0x7F) {
  ------------------
  |  Branch (329:16): [True: 32.2k, False: 13.6k]
  ------------------
  330|  32.2k|        switch (typecode) {
  331|  28.7k|            case DTA_OLD_TYPE_CODE_INT8:
  ------------------
  |  |  178|  28.7k|#define DTA_OLD_TYPE_CODE_INT8     'b'
  ------------------
  |  Branch (331:13): [True: 28.7k, False: 3.56k]
  ------------------
  332|  28.7k|                len = 1; type = READSTAT_TYPE_INT8; break;
  333|  1.24k|            case DTA_OLD_TYPE_CODE_INT16:
  ------------------
  |  |  179|  1.24k|#define DTA_OLD_TYPE_CODE_INT16    'i'
  ------------------
  |  Branch (333:13): [True: 1.24k, False: 31.0k]
  ------------------
  334|  1.24k|                len = 2; type = READSTAT_TYPE_INT16; break;
  335|    654|            case DTA_OLD_TYPE_CODE_INT32:
  ------------------
  |  |  180|    654|#define DTA_OLD_TYPE_CODE_INT32    'l'
  ------------------
  |  Branch (335:13): [True: 654, False: 31.6k]
  ------------------
  336|    654|                len = 4; type = READSTAT_TYPE_INT32; break;
  337|    727|            case DTA_OLD_TYPE_CODE_FLOAT:
  ------------------
  |  |  181|    727|#define DTA_OLD_TYPE_CODE_FLOAT    'f'
  ------------------
  |  Branch (337:13): [True: 727, False: 31.5k]
  ------------------
  338|    727|                len = 4; type = READSTAT_TYPE_FLOAT; break;
  339|    920|            case DTA_OLD_TYPE_CODE_DOUBLE:
  ------------------
  |  |  182|    920|#define DTA_OLD_TYPE_CODE_DOUBLE   'd'
  ------------------
  |  Branch (339:13): [True: 920, False: 31.3k]
  ------------------
  340|    920|                len = 8; type = READSTAT_TYPE_DOUBLE; break;
  341|     13|            default:
  ------------------
  |  Branch (341:13): [True: 13, False: 32.2k]
  ------------------
  342|     13|                retval = READSTAT_ERROR_PARSE; break;
  343|  32.2k|        }
  344|  32.2k|    } else {
  345|  13.6k|        len = typecode - 0x7F;
  346|  13.6k|        type = READSTAT_TYPE_STRING;
  347|  13.6k|    }
  348|       |    
  349|   160k|    if (max_len)
  ------------------
  |  Branch (349:9): [True: 160k, False: 0]
  ------------------
  350|   160k|        *max_len = len;
  351|   160k|    if (out_type)
  ------------------
  |  Branch (351:9): [True: 105k, False: 54.9k]
  ------------------
  352|   105k|        *out_type = type;
  353|       |
  354|   160k|    return retval;
  355|   160k|}

dta_parse_timestamp:
  145|  1.22k|readstat_error_handler error_handler, void *user_ctx) {
  146|  1.22k|	readstat_error_t retval = READSTAT_OK;
  147|  1.22k|	const char *p = data;
  148|  1.22k|	const char *pe = p + len;
  149|  1.22k|	const char *eof = pe;
  150|  1.22k|	int cs;
  151|  1.22k|	unsigned int temp_val = 0;
  152|       |	
  153|  1.22k|#line 154 "src/stata/readstat_dta_parse_timestamp.c"
  154|  1.22k|	{
  155|  1.22k|		cs = (int)dta_timestamp_parse_start;
  156|  1.22k|	}
  157|       |	
  158|  1.22k|#line 159 "src/stata/readstat_dta_parse_timestamp.c"
  159|  1.22k|	{
  160|  1.22k|		int _klen;
  161|  1.22k|		unsigned int _trans = 0;
  162|  1.22k|		const char * _keys;
  163|  1.22k|		const signed char * _acts;
  164|  1.22k|		unsigned int _nacts;
  165|  5.75k|		_resume: {}
  166|  5.75k|		if ( p == pe && p != eof )
  ------------------
  |  Branch (166:8): [True: 144, False: 5.60k]
  |  Branch (166:19): [True: 0, False: 144]
  ------------------
  167|      0|			goto _out;
  168|  5.75k|		if ( p == eof ) {
  ------------------
  |  Branch (168:8): [True: 144, False: 5.60k]
  ------------------
  169|    144|			if ( _dta_timestamp_parse_eof_trans[cs] > 0 ) {
  ------------------
  |  Branch (169:9): [True: 144, False: 0]
  ------------------
  170|    144|				_trans = (unsigned int)_dta_timestamp_parse_eof_trans[cs] - 1;
  171|    144|			}
  172|    144|		}
  173|  5.60k|		else {
  174|  5.60k|			_keys = ( _dta_timestamp_parse_trans_keys + (_dta_timestamp_parse_key_offsets[cs]));
  175|  5.60k|			_trans = (unsigned int)_dta_timestamp_parse_index_offsets[cs];
  176|       |			
  177|  5.60k|			_klen = (int)_dta_timestamp_parse_single_lengths[cs];
  178|  5.60k|			if ( _klen > 0 ) {
  ------------------
  |  Branch (178:9): [True: 4.95k, False: 655]
  ------------------
  179|  4.95k|				const char *_lower = _keys;
  180|  4.95k|				const char *_upper = _keys + _klen - 1;
  181|  4.95k|				const char *_mid;
  182|  9.53k|				while ( 1 ) {
  ------------------
  |  Branch (182:13): [True: 9.53k, Folded]
  ------------------
  183|  9.53k|					if ( _upper < _lower ) {
  ------------------
  |  Branch (183:11): [True: 3.27k, False: 6.25k]
  ------------------
  184|  3.27k|						_keys += _klen;
  185|  3.27k|						_trans += (unsigned int)_klen;
  186|  3.27k|						break;
  187|  3.27k|					}
  188|       |					
  189|  6.25k|					_mid = _lower + ((_upper-_lower) >> 1);
  190|  6.25k|					if ( ( (*( p))) < (*( _mid)) )
  ------------------
  |  Branch (190:11): [True: 1.24k, False: 5.01k]
  ------------------
  191|  1.24k|						_upper = _mid - 1;
  192|  5.01k|					else if ( ( (*( p))) > (*( _mid)) )
  ------------------
  |  Branch (192:16): [True: 3.34k, False: 1.67k]
  ------------------
  193|  3.34k|						_lower = _mid + 1;
  194|  1.67k|					else {
  195|  1.67k|						_trans += (unsigned int)(_mid - _keys);
  196|  1.67k|						goto _match;
  197|  1.67k|					}
  198|  6.25k|				}
  199|  4.95k|			}
  200|       |			
  201|  3.93k|			_klen = (int)_dta_timestamp_parse_range_lengths[cs];
  202|  3.93k|			if ( _klen > 0 ) {
  ------------------
  |  Branch (202:9): [True: 3.86k, False: 62]
  ------------------
  203|  3.86k|				const char *_lower = _keys;
  204|  3.86k|				const char *_upper = _keys + (_klen<<1) - 2;
  205|  3.86k|				const char *_mid;
  206|  4.88k|				while ( 1 ) {
  ------------------
  |  Branch (206:13): [True: 4.88k, Folded]
  ------------------
  207|  4.88k|					if ( _upper < _lower ) {
  ------------------
  |  Branch (207:11): [True: 1.01k, False: 3.86k]
  ------------------
  208|  1.01k|						_trans += (unsigned int)_klen;
  209|  1.01k|						break;
  210|  1.01k|					}
  211|       |					
  212|  3.86k|					_mid = _lower + (((_upper-_lower) >> 1) & ~1);
  213|  3.86k|					if ( ( (*( p))) < (*( _mid)) )
  ------------------
  |  Branch (213:11): [True: 618, False: 3.25k]
  ------------------
  214|    618|						_upper = _mid - 2;
  215|  3.25k|					else if ( ( (*( p))) > (*( _mid + 1)) )
  ------------------
  |  Branch (215:16): [True: 398, False: 2.85k]
  ------------------
  216|    398|						_lower = _mid + 2;
  217|  2.85k|					else {
  218|  2.85k|						_trans += (unsigned int)((_mid - _keys)>>1);
  219|  2.85k|						break;
  220|  2.85k|					}
  221|  3.86k|				}
  222|  3.86k|			}
  223|       |			
  224|  5.60k|			_match: {}
  225|  5.60k|		}
  226|  5.75k|		cs = (int)_dta_timestamp_parse_cond_targs[_trans];
  227|       |		
  228|  5.75k|		if ( _dta_timestamp_parse_cond_actions[_trans] != 0 ) {
  ------------------
  |  Branch (228:8): [True: 3.78k, False: 1.96k]
  ------------------
  229|       |			
  230|  3.78k|			_acts = ( _dta_timestamp_parse_actions + (_dta_timestamp_parse_cond_actions[_trans]));
  231|  3.78k|			_nacts = (unsigned int)(*( _acts));
  232|  3.78k|			_acts += 1;
  233|  8.57k|			while ( _nacts > 0 ) {
  ------------------
  |  Branch (233:12): [True: 4.78k, False: 3.78k]
  ------------------
  234|  4.78k|				switch ( (*( _acts)) )
  ------------------
  |  Branch (234:14): [True: 4.78k, False: 0]
  ------------------
  235|  4.78k|				{
  236|  2.85k|					case 0:  {
  ------------------
  |  Branch (236:6): [True: 2.85k, False: 1.93k]
  ------------------
  237|  2.85k|						{
  238|  2.85k|#line 20 "src/stata/readstat_dta_parse_timestamp.rl"
  239|       |							
  240|  2.85k|							temp_val = 10 * temp_val + ((( (*( p)))) - '0');
  241|  2.85k|						}
  242|       |						
  243|  2.85k|#line 244 "src/stata/readstat_dta_parse_timestamp.c"
  244|       |						
  245|  2.85k|						break; 
  246|      0|					}
  247|  1.00k|					case 1:  {
  ------------------
  |  Branch (247:6): [True: 1.00k, False: 3.78k]
  ------------------
  248|  1.00k|						{
  249|  1.00k|#line 24 "src/stata/readstat_dta_parse_timestamp.rl"
  250|  1.00k|							temp_val = 0; }
  251|       |						
  252|  1.00k|#line 253 "src/stata/readstat_dta_parse_timestamp.c"
  253|       |						
  254|  1.00k|						break; 
  255|      0|					}
  256|    287|					case 2:  {
  ------------------
  |  Branch (256:6): [True: 287, False: 4.49k]
  ------------------
  257|    287|						{
  258|    287|#line 26 "src/stata/readstat_dta_parse_timestamp.rl"
  259|    287|							timestamp->tm_mday = temp_val; }
  260|       |						
  261|    287|#line 262 "src/stata/readstat_dta_parse_timestamp.c"
  262|       |						
  263|    287|						break; 
  264|      0|					}
  265|     23|					case 3:  {
  ------------------
  |  Branch (265:6): [True: 23, False: 4.76k]
  ------------------
  266|     23|						{
  267|     23|#line 29 "src/stata/readstat_dta_parse_timestamp.rl"
  268|     23|							timestamp->tm_mon = 0; }
  269|       |						
  270|     23|#line 271 "src/stata/readstat_dta_parse_timestamp.c"
  271|       |						
  272|     23|						break; 
  273|      0|					}
  274|      1|					case 4:  {
  ------------------
  |  Branch (274:6): [True: 1, False: 4.78k]
  ------------------
  275|      1|						{
  276|      1|#line 30 "src/stata/readstat_dta_parse_timestamp.rl"
  277|      1|							timestamp->tm_mon = 1; }
  278|       |						
  279|      1|#line 280 "src/stata/readstat_dta_parse_timestamp.c"
  280|       |						
  281|      1|						break; 
  282|      0|					}
  283|      3|					case 5:  {
  ------------------
  |  Branch (283:6): [True: 3, False: 4.78k]
  ------------------
  284|      3|						{
  285|      3|#line 31 "src/stata/readstat_dta_parse_timestamp.rl"
  286|      3|							timestamp->tm_mon = 2; }
  287|       |						
  288|      3|#line 289 "src/stata/readstat_dta_parse_timestamp.c"
  289|       |						
  290|      3|						break; 
  291|      0|					}
  292|      8|					case 6:  {
  ------------------
  |  Branch (292:6): [True: 8, False: 4.77k]
  ------------------
  293|      8|						{
  294|      8|#line 32 "src/stata/readstat_dta_parse_timestamp.rl"
  295|      8|							timestamp->tm_mon = 3; }
  296|       |						
  297|      8|#line 298 "src/stata/readstat_dta_parse_timestamp.c"
  298|       |						
  299|      8|						break; 
  300|      0|					}
  301|     44|					case 7:  {
  ------------------
  |  Branch (301:6): [True: 44, False: 4.74k]
  ------------------
  302|     44|						{
  303|     44|#line 33 "src/stata/readstat_dta_parse_timestamp.rl"
  304|     44|							timestamp->tm_mon = 4; }
  305|       |						
  306|     44|#line 307 "src/stata/readstat_dta_parse_timestamp.c"
  307|       |						
  308|     44|						break; 
  309|      0|					}
  310|     21|					case 8:  {
  ------------------
  |  Branch (310:6): [True: 21, False: 4.76k]
  ------------------
  311|     21|						{
  312|     21|#line 34 "src/stata/readstat_dta_parse_timestamp.rl"
  313|     21|							timestamp->tm_mon = 5; }
  314|       |						
  315|     21|#line 316 "src/stata/readstat_dta_parse_timestamp.c"
  316|       |						
  317|     21|						break; 
  318|      0|					}
  319|      1|					case 9:  {
  ------------------
  |  Branch (319:6): [True: 1, False: 4.78k]
  ------------------
  320|      1|						{
  321|      1|#line 35 "src/stata/readstat_dta_parse_timestamp.rl"
  322|      1|							timestamp->tm_mon = 6; }
  323|       |						
  324|      1|#line 325 "src/stata/readstat_dta_parse_timestamp.c"
  325|       |						
  326|      1|						break; 
  327|      0|					}
  328|      3|					case 10:  {
  ------------------
  |  Branch (328:6): [True: 3, False: 4.78k]
  ------------------
  329|      3|						{
  330|      3|#line 36 "src/stata/readstat_dta_parse_timestamp.rl"
  331|      3|							timestamp->tm_mon = 7; }
  332|       |						
  333|      3|#line 334 "src/stata/readstat_dta_parse_timestamp.c"
  334|       |						
  335|      3|						break; 
  336|      0|					}
  337|     33|					case 11:  {
  ------------------
  |  Branch (337:6): [True: 33, False: 4.75k]
  ------------------
  338|     33|						{
  339|     33|#line 37 "src/stata/readstat_dta_parse_timestamp.rl"
  340|     33|							timestamp->tm_mon = 8; }
  341|       |						
  342|     33|#line 343 "src/stata/readstat_dta_parse_timestamp.c"
  343|       |						
  344|     33|						break; 
  345|      0|					}
  346|     70|					case 12:  {
  ------------------
  |  Branch (346:6): [True: 70, False: 4.71k]
  ------------------
  347|     70|						{
  348|     70|#line 38 "src/stata/readstat_dta_parse_timestamp.rl"
  349|     70|							timestamp->tm_mon = 9; }
  350|       |						
  351|     70|#line 352 "src/stata/readstat_dta_parse_timestamp.c"
  352|       |						
  353|     70|						break; 
  354|      0|					}
  355|      8|					case 13:  {
  ------------------
  |  Branch (355:6): [True: 8, False: 4.77k]
  ------------------
  356|      8|						{
  357|      8|#line 39 "src/stata/readstat_dta_parse_timestamp.rl"
  358|      8|							timestamp->tm_mon = 10; }
  359|       |						
  360|      8|#line 361 "src/stata/readstat_dta_parse_timestamp.c"
  361|       |						
  362|      8|						break; 
  363|      0|					}
  364|      1|					case 14:  {
  ------------------
  |  Branch (364:6): [True: 1, False: 4.78k]
  ------------------
  365|      1|						{
  366|      1|#line 40 "src/stata/readstat_dta_parse_timestamp.rl"
  367|      1|							timestamp->tm_mon = 11; }
  368|       |						
  369|      1|#line 370 "src/stata/readstat_dta_parse_timestamp.c"
  370|       |						
  371|      1|						break; 
  372|      0|					}
  373|    171|					case 15:  {
  ------------------
  |  Branch (373:6): [True: 171, False: 4.61k]
  ------------------
  374|    171|						{
  375|    171|#line 42 "src/stata/readstat_dta_parse_timestamp.rl"
  376|    171|							timestamp->tm_year = temp_val - 1900; }
  377|       |						
  378|    171|#line 379 "src/stata/readstat_dta_parse_timestamp.c"
  379|       |						
  380|    171|						break; 
  381|      0|					}
  382|    133|					case 16:  {
  ------------------
  |  Branch (382:6): [True: 133, False: 4.65k]
  ------------------
  383|    133|						{
  384|    133|#line 44 "src/stata/readstat_dta_parse_timestamp.rl"
  385|    133|							timestamp->tm_hour = temp_val; }
  386|       |						
  387|    133|#line 388 "src/stata/readstat_dta_parse_timestamp.c"
  388|       |						
  389|    133|						break; 
  390|      0|					}
  391|    125|					case 17:  {
  ------------------
  |  Branch (391:6): [True: 125, False: 4.66k]
  ------------------
  392|    125|						{
  393|    125|#line 46 "src/stata/readstat_dta_parse_timestamp.rl"
  394|    125|							timestamp->tm_min = temp_val; }
  395|       |						
  396|    125|#line 397 "src/stata/readstat_dta_parse_timestamp.c"
  397|       |						
  398|    125|						break; 
  399|      0|					}
  400|  4.78k|				}
  401|  4.78k|				_nacts -= 1;
  402|  4.78k|				_acts += 1;
  403|  4.78k|			}
  404|       |			
  405|  3.78k|		}
  406|       |		
  407|  5.75k|		if ( p == eof ) {
  ------------------
  |  Branch (407:8): [True: 144, False: 5.60k]
  ------------------
  408|    144|			if ( cs >= 44 )
  ------------------
  |  Branch (408:9): [True: 125, False: 19]
  ------------------
  409|    125|				goto _out;
  410|    144|		}
  411|  5.60k|		else {
  412|  5.60k|			if ( cs != 0 ) {
  ------------------
  |  Branch (412:9): [True: 4.52k, False: 1.07k]
  ------------------
  413|  4.52k|				p += 1;
  414|  4.52k|				goto _resume;
  415|  4.52k|			}
  416|  5.60k|		}
  417|  1.22k|		_out: {}
  418|  1.22k|	}
  419|       |	
  420|      0|#line 52 "src/stata/readstat_dta_parse_timestamp.rl"
  421|       |	
  422|       |	
  423|  1.22k|	if (cs < 
  ------------------
  |  Branch (423:6): [True: 1.09k, False: 125]
  ------------------
  424|  1.22k|#line 425 "src/stata/readstat_dta_parse_timestamp.c"
  425|  1.22k|	44
  426|    125|#line 54 "src/stata/readstat_dta_parse_timestamp.rl"
  427|  1.09k|	|| p != pe) {
  ------------------
  |  Branch (427:5): [True: 0, False: 125]
  ------------------
  428|  1.09k|		char error_buf[1024];
  429|  1.09k|		if (error_handler) {
  ------------------
  |  Branch (429:7): [True: 0, False: 1.09k]
  ------------------
  430|      0|			snprintf(error_buf, sizeof(error_buf), "Invalid timestamp string (length=%d): %.*s", (int)len, (int)len, data);
  431|      0|			error_handler(error_buf, user_ctx);
  432|      0|		}
  433|  1.09k|		retval = READSTAT_ERROR_BAD_TIMESTAMP_STRING;
  434|  1.09k|	}
  435|       |	
  436|  1.22k|	(void)dta_timestamp_parse_en_main;
  437|       |	
  438|  1.22k|	return retval;
  439|  5.75k|}

readstat_parse_dta:
 1244|  4.48k|readstat_error_t readstat_parse_dta(readstat_parser_t *parser, const char *path, void *user_ctx) {
 1245|  4.48k|    readstat_error_t retval = READSTAT_OK;
 1246|  4.48k|    readstat_io_t *io = parser->io;
 1247|  4.48k|    int i;
 1248|  4.48k|    dta_ctx_t    *ctx;
 1249|  4.48k|    size_t file_size = 0;
 1250|       |
 1251|  4.48k|    ctx = dta_ctx_alloc(io);
 1252|       |
 1253|  4.48k|    if (io->open(path, io->io_ctx) == -1) {
  ------------------
  |  Branch (1253:9): [True: 0, False: 4.48k]
  ------------------
 1254|      0|        retval = READSTAT_ERROR_OPEN;
 1255|      0|        goto cleanup;
 1256|      0|    }
 1257|       |
 1258|  4.48k|    char magic[4];
 1259|  4.48k|    if (io->read(magic, 4, io->io_ctx) != 4) {
  ------------------
  |  Branch (1259:9): [True: 2, False: 4.48k]
  ------------------
 1260|      2|        retval = READSTAT_ERROR_READ;
 1261|      2|        goto cleanup;
 1262|      2|    }
 1263|       |
 1264|  4.48k|    file_size = io->seek(0, READSTAT_SEEK_END, io->io_ctx);
 1265|  4.48k|    if (file_size == -1) {
  ------------------
  |  Branch (1265:9): [True: 0, False: 4.48k]
  ------------------
 1266|      0|        if (ctx->handle.error) {
  ------------------
  |  Branch (1266:13): [True: 0, False: 0]
  ------------------
 1267|      0|            snprintf(ctx->error_buf, sizeof(ctx->error_buf), "Failed to seek to end of file");
 1268|      0|            ctx->handle.error(ctx->error_buf, ctx->user_ctx);
 1269|      0|        }
 1270|      0|        retval = READSTAT_ERROR_SEEK;
 1271|      0|        goto cleanup;
 1272|      0|    }
 1273|       |
 1274|  4.48k|    if (io->seek(0, READSTAT_SEEK_SET, io->io_ctx) == -1) {
  ------------------
  |  Branch (1274:9): [True: 0, False: 4.48k]
  ------------------
 1275|      0|        if (ctx->handle.error) {
  ------------------
  |  Branch (1275:13): [True: 0, False: 0]
  ------------------
 1276|      0|            snprintf(ctx->error_buf, sizeof(ctx->error_buf), "Failed to seek to start of file");
 1277|      0|            ctx->handle.error(ctx->error_buf, ctx->user_ctx);
 1278|      0|        }
 1279|      0|        retval = READSTAT_ERROR_SEEK;
 1280|      0|        goto cleanup;
 1281|      0|    }
 1282|       |
 1283|  4.48k|    ctx->file_size = file_size;
 1284|       |
 1285|  4.48k|    if (strncmp(magic, "<sta", 4) == 0) {
  ------------------
  |  Branch (1285:9): [True: 1.12k, False: 3.36k]
  ------------------
 1286|  1.12k|        dta_header64_t header;
 1287|  1.12k|        if ((retval = dta_read_xmlish_header(ctx, &header)) != READSTAT_OK) {
  ------------------
  |  Branch (1287:13): [True: 427, False: 694]
  ------------------
 1288|    427|            goto cleanup;
 1289|    427|        }
 1290|    694|        retval = dta_ctx_init(ctx, header.nvar, header.nobs, header.byteorder, header.ds_format,
 1291|    694|                parser->input_encoding, parser->output_encoding);
 1292|  3.36k|    } else {
 1293|  3.36k|        dta_header_t header;
 1294|  3.36k|        if ((retval = dta_read_header(ctx, &header)) != READSTAT_OK) {
  ------------------
  |  Branch (1294:13): [True: 40, False: 3.32k]
  ------------------
 1295|     40|            goto cleanup;
 1296|     40|        }
 1297|  3.32k|        retval = dta_ctx_init(ctx, header.nvar, header.nobs, header.byteorder, header.ds_format,
 1298|  3.32k|                parser->input_encoding, parser->output_encoding);
 1299|  3.32k|    }
 1300|  4.01k|    if (retval != READSTAT_OK) {
  ------------------
  |  Branch (1300:9): [True: 115, False: 3.90k]
  ------------------
 1301|    115|        goto cleanup;
 1302|    115|    }
 1303|       |
 1304|  3.90k|    ctx->user_ctx = user_ctx;
 1305|  3.90k|    ctx->handle = parser->handlers;
 1306|  3.90k|    if (parser->row_offset > 0)
  ------------------
  |  Branch (1306:9): [True: 0, False: 3.90k]
  ------------------
 1307|      0|        ctx->row_offset = parser->row_offset;
 1308|  3.90k|    int64_t nobs_after_skipping = ctx->nobs - ctx->row_offset;
 1309|  3.90k|    if (nobs_after_skipping < 0) {
  ------------------
  |  Branch (1309:9): [True: 163, False: 3.73k]
  ------------------
 1310|    163|        nobs_after_skipping = 0;
 1311|    163|        ctx->row_offset = ctx->nobs;
 1312|    163|    }
 1313|  3.90k|    ctx->row_limit = nobs_after_skipping;
 1314|  3.90k|    if (parser->row_limit > 0 && parser->row_limit < nobs_after_skipping)
  ------------------
  |  Branch (1314:9): [True: 0, False: 3.90k]
  |  Branch (1314:34): [True: 0, False: 0]
  ------------------
 1315|      0|        ctx->row_limit = parser->row_limit;
 1316|       |
 1317|  3.90k|    retval = dta_update_progress(ctx);
 1318|  3.90k|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (1318:9): [True: 0, False: 3.90k]
  ------------------
 1319|      0|        goto cleanup;
 1320|       |    
 1321|  3.90k|    if ((retval = dta_read_label_and_timestamp(ctx)) != READSTAT_OK)
  ------------------
  |  Branch (1321:9): [True: 519, False: 3.38k]
  ------------------
 1322|    519|        goto cleanup;
 1323|       |
 1324|  3.38k|    if ((retval = dta_read_tag(ctx, "</header>")) != READSTAT_OK) {
  ------------------
  |  Branch (1324:9): [True: 5, False: 3.37k]
  ------------------
 1325|      5|        goto cleanup;
 1326|      5|    }
 1327|       |
 1328|  3.37k|    if (ctx->handle.metadata) {
  ------------------
  |  Branch (1328:9): [True: 3.37k, False: 0]
  ------------------
 1329|  3.37k|        readstat_metadata_t metadata = {
 1330|  3.37k|            .row_count = ctx->row_limit,
 1331|  3.37k|            .var_count = ctx->nvar,
 1332|  3.37k|            .file_label = ctx->data_label,
 1333|  3.37k|            .creation_time = ctx->timestamp,
 1334|  3.37k|            .modified_time = ctx->timestamp,
 1335|  3.37k|            .file_format_version = ctx->ds_format,
 1336|  3.37k|            .is64bit = ctx->ds_format >= 118,
 1337|  3.37k|            .endianness = ctx->endianness
 1338|  3.37k|        };
 1339|  3.37k|        if (ctx->handle.metadata(&metadata, user_ctx) != READSTAT_HANDLER_OK) {
  ------------------
  |  |   22|  3.37k|#define READSTAT_HANDLER_OK             0
  ------------------
  |  Branch (1339:13): [True: 0, False: 3.37k]
  ------------------
 1340|      0|            retval = READSTAT_ERROR_USER_ABORT;
 1341|      0|            goto cleanup;
 1342|      0|        }
 1343|  3.37k|    }
 1344|       |
 1345|  3.37k|    if ((retval = dta_read_map(ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1345:9): [True: 10, False: 3.36k]
  ------------------
 1346|     10|        retval = READSTAT_ERROR_READ;
 1347|     10|        goto cleanup;
 1348|     10|    }
 1349|       |
 1350|  3.36k|    if ((retval = dta_read_descriptors(ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1350:9): [True: 161, False: 3.20k]
  ------------------
 1351|    161|        goto cleanup;
 1352|    161|    }
 1353|       |
 1354|  58.1k|    for (i=0; i<ctx->nvar; i++) {
  ------------------
  |  Branch (1354:15): [True: 54.9k, False: 3.19k]
  ------------------
 1355|  54.9k|        size_t      max_len;
 1356|  54.9k|        if ((retval = dta_type_info(ctx->typlist[i], ctx, &max_len, NULL)) != READSTAT_OK)
  ------------------
  |  Branch (1356:13): [True: 13, False: 54.9k]
  ------------------
 1357|     13|            goto cleanup;
 1358|       |
 1359|  54.9k|        ctx->record_len += max_len;
 1360|  54.9k|    }
 1361|       |
 1362|  3.19k|    if (ctx->nvar > 0 && ctx->record_len == 0) {
  ------------------
  |  Branch (1362:9): [True: 2.32k, False: 871]
  |  Branch (1362:26): [True: 4, False: 2.31k]
  ------------------
 1363|      4|        retval = READSTAT_ERROR_PARSE;
 1364|      4|        goto cleanup;
 1365|      4|    }
 1366|       |
 1367|  3.18k|    if ((retval = dta_handle_variables(ctx)) != READSTAT_OK)
  ------------------
  |  Branch (1367:9): [True: 20, False: 3.16k]
  ------------------
 1368|     20|        goto cleanup;
 1369|       |
 1370|  3.16k|    if ((retval = dta_read_expansion_fields(ctx)) != READSTAT_OK)
  ------------------
  |  Branch (1370:9): [True: 728, False: 2.44k]
  ------------------
 1371|    728|        goto cleanup;
 1372|       |
 1373|  2.44k|    if (!ctx->file_is_xmlish) {
  ------------------
  |  Branch (1373:9): [True: 1.31k, False: 1.12k]
  ------------------
 1374|  1.31k|        ctx->data_offset = io->seek(0, READSTAT_SEEK_CUR, io->io_ctx);
 1375|  1.31k|        if (ctx->data_offset == -1) {
  ------------------
  |  Branch (1375:13): [True: 0, False: 1.31k]
  ------------------
 1376|      0|            retval = READSTAT_ERROR_SEEK;
 1377|      0|            goto cleanup;
 1378|      0|        }
 1379|  1.31k|        ctx->value_labels_offset = ctx->data_offset + ctx->record_len * ctx->nobs;
 1380|  1.31k|    }
 1381|       |
 1382|  2.44k|    if ((retval = dta_read_strls(ctx)) != READSTAT_OK)
  ------------------
  |  Branch (1382:9): [True: 389, False: 2.05k]
  ------------------
 1383|    389|        goto cleanup;
 1384|       |
 1385|  2.05k|    if ((retval = dta_read_data(ctx)) != READSTAT_OK)
  ------------------
  |  Branch (1385:9): [True: 1.20k, False: 846]
  ------------------
 1386|  1.20k|        goto cleanup;
 1387|       |
 1388|    846|    if ((retval = dta_handle_value_labels(ctx)) != READSTAT_OK)
  ------------------
  |  Branch (1388:9): [True: 351, False: 495]
  ------------------
 1389|    351|        goto cleanup;
 1390|       |
 1391|  4.48k|cleanup:
 1392|  4.48k|    io->close(io->io_ctx);
 1393|  4.48k|    if (ctx)
  ------------------
  |  Branch (1393:9): [True: 4.48k, False: 0]
  ------------------
 1394|  4.48k|        dta_ctx_free(ctx);
 1395|       |
 1396|  4.48k|    return retval;
 1397|    846|}
readstat_dta_read.c:dta_read_xmlish_header:
  838|  1.12k|static readstat_error_t dta_read_xmlish_header(dta_ctx_t *ctx, dta_header64_t *header) {
  839|  1.12k|    readstat_error_t retval = READSTAT_OK;
  840|       |    
  841|  1.12k|    if ((retval = dta_read_tag(ctx, "<stata_dta>")) != READSTAT_OK) {
  ------------------
  |  Branch (841:9): [True: 69, False: 1.05k]
  ------------------
  842|     69|        goto cleanup;
  843|     69|    }
  844|  1.05k|    if ((retval = dta_read_tag(ctx, "<header>")) != READSTAT_OK) {
  ------------------
  |  Branch (844:9): [True: 71, False: 981]
  ------------------
  845|     71|        goto cleanup;
  846|     71|    }
  847|       |
  848|    981|    char ds_format[3];
  849|    981|    if ((retval = dta_read_chunk(ctx, "<release>", ds_format,
  ------------------
  |  Branch (849:9): [True: 176, False: 805]
  ------------------
  850|    981|                    sizeof(ds_format), "</release>")) != READSTAT_OK) {
  851|    176|        goto cleanup;
  852|    176|    }
  853|       |
  854|    805|    header->ds_format = 100 * (ds_format[0] - '0') + 10 * (ds_format[1] - '0') + (ds_format[2] - '0');
  855|       |
  856|    805|    char byteorder[3];
  857|    805|    int byteswap = 0;
  858|    805|    if ((retval = dta_read_chunk(ctx, "<byteorder>", byteorder, 
  ------------------
  |  Branch (858:9): [True: 39, False: 766]
  ------------------
  859|    805|                    sizeof(byteorder), "</byteorder>")) != READSTAT_OK) {
  860|     39|        goto cleanup;
  861|     39|    }
  862|    766|    if (strncmp(byteorder, "MSF", 3) == 0) {
  ------------------
  |  Branch (862:9): [True: 45, False: 721]
  ------------------
  863|     45|        header->byteorder = DTA_HILO;
  ------------------
  |  |  129|     45|#define DTA_HILO  0x01
  ------------------
  864|    721|    } else if (strncmp(byteorder, "LSF", 3) == 0) {
  ------------------
  |  Branch (864:16): [True: 678, False: 43]
  ------------------
  865|    678|        header->byteorder = DTA_LOHI;
  ------------------
  |  |  130|    678|#define DTA_LOHI  0x02
  ------------------
  866|    678|    } else {
  867|     43|        retval = READSTAT_ERROR_PARSE;
  868|     43|        goto cleanup;
  869|     43|    }
  870|    723|    byteswap = (header->byteorder == DTA_LOHI) ^ machine_is_little_endian();
  ------------------
  |  |  130|    723|#define DTA_LOHI  0x02
  ------------------
  871|       |
  872|    723|    if (header->ds_format >= 119) {
  ------------------
  |  Branch (872:9): [True: 100, False: 623]
  ------------------
  873|    100|        uint32_t nvar;
  874|    100|        if ((retval = dta_read_chunk(ctx, "<K>", &nvar, 
  ------------------
  |  Branch (874:13): [True: 5, False: 95]
  ------------------
  875|    100|                        sizeof(uint32_t), "</K>")) != READSTAT_OK) {
  876|      5|            goto cleanup;
  877|      5|        }
  878|     95|        header->nvar = byteswap ? byteswap4(nvar) : nvar;
  ------------------
  |  Branch (878:24): [True: 33, False: 62]
  ------------------
  879|    623|    } else {
  880|    623|        uint16_t nvar;
  881|    623|        if ((retval = dta_read_chunk(ctx, "<K>", &nvar, 
  ------------------
  |  Branch (881:13): [True: 10, False: 613]
  ------------------
  882|    623|                        sizeof(uint16_t), "</K>")) != READSTAT_OK) {
  883|     10|            goto cleanup;
  884|     10|        }
  885|    613|        header->nvar = byteswap ? byteswap2(nvar) : nvar;
  ------------------
  |  Branch (885:24): [True: 6, False: 607]
  ------------------
  886|    613|    }
  887|       |
  888|    708|    if (header->ds_format >= 118) {
  ------------------
  |  Branch (888:9): [True: 424, False: 284]
  ------------------
  889|    424|        uint64_t nobs;
  890|    424|        if ((retval = dta_read_chunk(ctx, "<N>", &nobs, 
  ------------------
  |  Branch (890:13): [True: 4, False: 420]
  ------------------
  891|    424|                        sizeof(uint64_t), "</N>")) != READSTAT_OK) {
  892|      4|            goto cleanup;
  893|      4|        }
  894|    420|        header->nobs = byteswap ? byteswap8(nobs) : nobs;
  ------------------
  |  Branch (894:24): [True: 33, False: 387]
  ------------------
  895|    420|    } else {
  896|    284|        uint32_t nobs;
  897|    284|        if ((retval = dta_read_chunk(ctx, "<N>", &nobs, 
  ------------------
  |  Branch (897:13): [True: 10, False: 274]
  ------------------
  898|    284|                        sizeof(uint32_t), "</N>")) != READSTAT_OK) {
  899|     10|            goto cleanup;
  900|     10|        }
  901|    274|        header->nobs = byteswap ? byteswap4(nobs) : nobs;
  ------------------
  |  Branch (901:24): [True: 1, False: 273]
  ------------------
  902|    274|    }
  903|       |
  904|  1.12k|cleanup:
  905|  1.12k|    return retval;
  906|    708|}
readstat_dta_read.c:dta_read_chunk:
   92|  24.5k|        const char *end_tag) {
   93|  24.5k|    char *dst_buffer = (char *)dst;
   94|  24.5k|    readstat_io_t *io = ctx->io;
   95|  24.5k|    readstat_error_t retval = READSTAT_OK;
   96|       |
   97|  24.5k|    if ((retval = dta_read_tag(ctx, start_tag)) != READSTAT_OK)
  ------------------
  |  Branch (97:9): [True: 192, False: 24.3k]
  ------------------
   98|    192|        goto cleanup;
   99|       |
  100|  24.3k|    if (io->read(dst_buffer, dst_len, io->io_ctx) != dst_len) {
  ------------------
  |  Branch (100:9): [True: 58, False: 24.2k]
  ------------------
  101|     58|        retval = READSTAT_ERROR_READ;
  102|     58|        goto cleanup;
  103|     58|    }
  104|       |
  105|  24.2k|    if ((retval = dta_read_tag(ctx, end_tag)) != READSTAT_OK)
  ------------------
  |  Branch (105:9): [True: 165, False: 24.0k]
  ------------------
  106|    165|        goto cleanup;
  107|       |
  108|  24.5k|cleanup:
  109|       |
  110|  24.5k|    return retval;
  111|  24.2k|}
readstat_dta_read.c:dta_read_header:
  821|  3.36k|static readstat_error_t dta_read_header(dta_ctx_t *ctx, dta_header_t *header) {
  822|  3.36k|    readstat_error_t retval = READSTAT_OK;
  823|  3.36k|    readstat_io_t *io = ctx->io;
  824|  3.36k|    int bswap = 0;
  825|       |
  826|  3.36k|    if (io->read(header, sizeof(dta_header_t), io->io_ctx) != sizeof(dta_header_t)) {
  ------------------
  |  Branch (826:9): [True: 40, False: 3.32k]
  ------------------
  827|     40|        retval = READSTAT_ERROR_READ;
  828|     40|        goto cleanup;
  829|     40|    }
  830|  3.32k|    bswap = (header->byteorder == DTA_LOHI) ^ machine_is_little_endian();
  ------------------
  |  |  130|  3.32k|#define DTA_LOHI  0x02
  ------------------
  831|  3.32k|    header->nvar = bswap ? byteswap2(header->nvar) : header->nvar;
  ------------------
  |  Branch (831:20): [True: 2.30k, False: 1.01k]
  ------------------
  832|  3.32k|    header->nobs = bswap ? byteswap4(header->nobs) : header->nobs;
  ------------------
  |  Branch (832:20): [True: 2.30k, False: 1.01k]
  ------------------
  833|       |
  834|  3.36k|cleanup:
  835|  3.36k|    return retval;
  836|  3.32k|}
readstat_dta_read.c:dta_update_progress:
   29|   730M|static readstat_error_t dta_update_progress(dta_ctx_t *ctx) {
   30|   730M|    double progress = 0.0;
   31|   730M|    if (ctx->row_limit > 0)
  ------------------
  |  Branch (31:9): [True: 730M, False: 1.35k]
  ------------------
   32|   730M|        progress = 1.0 * ctx->current_row / ctx->row_limit;
   33|   730M|    if (ctx->handle.progress && ctx->handle.progress(progress, ctx->user_ctx) != READSTAT_HANDLER_OK)
  ------------------
  |  |   22|      0|#define READSTAT_HANDLER_OK             0
  ------------------
  |  Branch (33:9): [True: 0, False: 730M]
  |  Branch (33:33): [True: 0, False: 0]
  ------------------
   34|      0|        return READSTAT_ERROR_USER_ABORT;
   35|   730M|    return READSTAT_OK;
   36|   730M|}
readstat_dta_read.c:dta_read_label_and_timestamp:
  908|  3.90k|static readstat_error_t dta_read_label_and_timestamp(dta_ctx_t *ctx) {
  909|  3.90k|    readstat_io_t *io = ctx->io;
  910|  3.90k|    readstat_error_t retval = READSTAT_OK;
  911|  3.90k|    char *data_label_buffer = NULL;
  912|  3.90k|    char *timestamp_buffer = NULL;
  913|  3.90k|    uint16_t label_len = 0;
  914|  3.90k|    unsigned char timestamp_len = 0;
  915|  3.90k|    char last_data_label_char = 0;
  916|  3.90k|    struct tm timestamp = { .tm_isdst = -1 };
  917|       |
  918|  3.90k|    if (ctx->file_is_xmlish) {
  ------------------
  |  Branch (918:9): [True: 2.17k, False: 1.72k]
  ------------------
  919|  2.17k|        if ((retval = dta_read_tag(ctx, "<label>")) != READSTAT_OK) {
  ------------------
  |  Branch (919:13): [True: 146, False: 2.03k]
  ------------------
  920|    146|            goto cleanup;
  921|    146|        }
  922|       |        
  923|  2.03k|        if (ctx->data_label_len_len == 2) {
  ------------------
  |  Branch (923:13): [True: 360, False: 1.67k]
  ------------------
  924|    360|            if (io->read(&label_len, sizeof(uint16_t), io->io_ctx) != sizeof(uint16_t)) {
  ------------------
  |  Branch (924:17): [True: 2, False: 358]
  ------------------
  925|      2|                retval = READSTAT_ERROR_READ;
  926|      2|                goto cleanup;
  927|      2|            }
  928|    358|            label_len = ctx->bswap ? byteswap2(label_len) : label_len;
  ------------------
  |  Branch (928:25): [True: 48, False: 310]
  ------------------
  929|  1.67k|        } else if (ctx->data_label_len_len == 1) {
  ------------------
  |  Branch (929:20): [True: 1.67k, False: 0]
  ------------------
  930|  1.67k|            unsigned char label_len_char;
  931|  1.67k|            if (io->read(&label_len_char, sizeof(unsigned char), io->io_ctx) != sizeof(unsigned char)) {
  ------------------
  |  Branch (931:17): [True: 1, False: 1.66k]
  ------------------
  932|      1|                retval = READSTAT_ERROR_READ;
  933|      1|                goto cleanup;
  934|      1|            }
  935|  1.66k|            label_len = label_len_char;
  936|  1.66k|        }
  937|  2.03k|    } else {
  938|  1.72k|        label_len = ctx->data_label_len;
  939|  1.72k|    }
  940|       |
  941|  3.75k|    if ((data_label_buffer = readstat_malloc(label_len+1)) == NULL) {
  ------------------
  |  Branch (941:9): [True: 0, False: 3.75k]
  ------------------
  942|      0|        retval = READSTAT_ERROR_MALLOC;
  943|      0|        goto cleanup;
  944|      0|    }
  945|       |
  946|  3.75k|    if (io->read(data_label_buffer, label_len, io->io_ctx) != label_len) {
  ------------------
  |  Branch (946:9): [True: 50, False: 3.70k]
  ------------------
  947|     50|        retval = READSTAT_ERROR_READ;
  948|     50|        goto cleanup;
  949|     50|    }
  950|       |
  951|  3.70k|    if (!ctx->file_is_xmlish) {
  ------------------
  |  Branch (951:9): [True: 1.70k, False: 1.99k]
  ------------------
  952|  1.70k|        last_data_label_char = data_label_buffer[label_len-1];
  953|  1.70k|        data_label_buffer[label_len] = '\0';
  954|  1.70k|        label_len = strlen(data_label_buffer);
  955|  1.70k|    }
  956|       |
  957|  3.70k|    if ((ctx->data_label = readstat_malloc(4*label_len+1)) == NULL) {
  ------------------
  |  Branch (957:9): [True: 0, False: 3.70k]
  ------------------
  958|      0|        retval = READSTAT_ERROR_MALLOC;
  959|      0|        goto cleanup;
  960|      0|    }
  961|       |
  962|  3.70k|    if ((retval = readstat_convert(ctx->data_label, 4*label_len+1,
  ------------------
  |  Branch (962:9): [True: 3, False: 3.69k]
  ------------------
  963|  3.70k|                    data_label_buffer, label_len, ctx->converter)) != READSTAT_OK)
  964|      3|        goto cleanup;
  965|       |
  966|  3.69k|    if (ctx->file_is_xmlish) {
  ------------------
  |  Branch (966:9): [True: 1.99k, False: 1.70k]
  ------------------
  967|  1.99k|        if ((retval = dta_read_tag(ctx, "</label>")) != READSTAT_OK) {
  ------------------
  |  Branch (967:13): [True: 135, False: 1.85k]
  ------------------
  968|    135|            goto cleanup;
  969|    135|        }
  970|       |        
  971|  1.85k|        if ((retval = dta_read_tag(ctx, "<timestamp>")) != READSTAT_OK) {
  ------------------
  |  Branch (971:13): [True: 98, False: 1.75k]
  ------------------
  972|     98|            goto cleanup;
  973|     98|        }
  974|       |        
  975|  1.75k|        if (io->read(&timestamp_len, 1, io->io_ctx) != 1) {
  ------------------
  |  Branch (975:13): [True: 1, False: 1.75k]
  ------------------
  976|      1|            retval = READSTAT_ERROR_READ;
  977|      1|            goto cleanup;
  978|      1|        }
  979|  1.75k|    } else {
  980|  1.70k|        timestamp_len = ctx->timestamp_len;
  981|  1.70k|    }
  982|       |
  983|  3.46k|    if (timestamp_len) {
  ------------------
  |  Branch (983:9): [True: 1.66k, False: 1.79k]
  ------------------
  984|  1.66k|        if ((timestamp_buffer = readstat_malloc(timestamp_len)) == NULL) {
  ------------------
  |  Branch (984:13): [True: 0, False: 1.66k]
  ------------------
  985|      0|            retval = READSTAT_ERROR_MALLOC;
  986|      0|            goto cleanup;
  987|      0|        }
  988|       |
  989|  1.66k|        if (io->read(timestamp_buffer, timestamp_len, io->io_ctx) != timestamp_len) {
  ------------------
  |  Branch (989:13): [True: 16, False: 1.65k]
  ------------------
  990|     16|            retval = READSTAT_ERROR_READ;
  991|     16|            goto cleanup;
  992|     16|        }
  993|       |
  994|  1.65k|        if (!ctx->file_is_xmlish)
  ------------------
  |  Branch (994:13): [True: 1.04k, False: 605]
  ------------------
  995|  1.04k|            timestamp_len--;
  996|       |
  997|  1.65k|        if (timestamp_buffer[0]) {
  ------------------
  |  Branch (997:13): [True: 1.22k, False: 431]
  ------------------
  998|  1.22k|            if (timestamp_buffer[timestamp_len-1] == '\0' && last_data_label_char != '\0') {
  ------------------
  |  Branch (998:17): [True: 200, False: 1.02k]
  |  Branch (998:62): [True: 139, False: 61]
  ------------------
  999|       |                /* Stupid hack for miswritten files with off-by-one timestamp, DTA 114 era? */
 1000|    139|                memmove(timestamp_buffer+1, timestamp_buffer, timestamp_len-1);
 1001|    139|                timestamp_buffer[0] = last_data_label_char;
 1002|    139|            }
 1003|  1.22k|            if (dta_parse_timestamp(timestamp_buffer, timestamp_len,
  ------------------
  |  Branch (1003:17): [True: 125, False: 1.09k]
  ------------------
 1004|  1.22k|                        &timestamp, ctx->handle.error, ctx->user_ctx) == READSTAT_OK) {
 1005|    125|                ctx->timestamp = mktime(&timestamp);
 1006|    125|            }
 1007|  1.22k|        }
 1008|  1.65k|    }
 1009|       |
 1010|  3.44k|    if ((retval = dta_read_tag(ctx, "</timestamp>")) != READSTAT_OK) {
  ------------------
  |  Branch (1010:9): [True: 67, False: 3.38k]
  ------------------
 1011|     67|        goto cleanup;
 1012|     67|    }
 1013|       |
 1014|  3.90k|cleanup:
 1015|  3.90k|    if (data_label_buffer)
  ------------------
  |  Branch (1015:9): [True: 3.75k, False: 149]
  ------------------
 1016|  3.75k|        free(data_label_buffer);
 1017|  3.90k|    if (timestamp_buffer)
  ------------------
  |  Branch (1017:9): [True: 1.66k, False: 2.23k]
  ------------------
 1018|  1.66k|        free(timestamp_buffer);
 1019|       |
 1020|  3.90k|    return retval;
 1021|  3.44k|}
readstat_dta_read.c:dta_read_tag:
  317|   100k|static readstat_error_t dta_read_tag(dta_ctx_t *ctx, const char *tag) {
  318|   100k|    readstat_error_t retval = READSTAT_OK;
  319|   100k|    if (ctx->initialized && !ctx->file_is_xmlish)
  ------------------
  |  Branch (319:9): [True: 91.7k, False: 8.47k]
  |  Branch (319:29): [True: 51.5k, False: 40.1k]
  ------------------
  320|  51.5k|        return retval;
  321|       |
  322|  48.6k|    char buffer[256];
  323|  48.6k|    size_t len = strlen(tag);
  324|  48.6k|    if (ctx->io->read(buffer, len, ctx->io->io_ctx) != len) {
  ------------------
  |  Branch (324:9): [True: 344, False: 48.2k]
  ------------------
  325|    344|        retval = READSTAT_ERROR_READ;
  326|    344|        goto cleanup;
  327|    344|    }
  328|  48.2k|    if (strncmp(buffer, tag, len) != 0) {
  ------------------
  |  Branch (328:9): [True: 1.44k, False: 46.8k]
  ------------------
  329|  1.44k|        retval = READSTAT_ERROR_PARSE;
  330|  1.44k|        goto cleanup;
  331|  1.44k|    }
  332|  48.6k|cleanup:
  333|  48.6k|    return retval;
  334|  48.2k|}
readstat_dta_read.c:dta_read_map:
  113|  3.37k|static readstat_error_t dta_read_map(dta_ctx_t *ctx) {
  114|  3.37k|    if (!ctx->file_is_xmlish)
  ------------------
  |  Branch (114:9): [True: 1.70k, False: 1.67k]
  ------------------
  115|  1.70k|        return READSTAT_OK;
  116|       |
  117|  1.67k|    readstat_error_t retval = READSTAT_OK;
  118|  1.67k|    uint64_t map_buffer[14];
  119|       |
  120|  1.67k|    if ((retval = dta_read_chunk(ctx, "<map>", map_buffer, 
  ------------------
  |  Branch (120:9): [True: 10, False: 1.66k]
  ------------------
  121|  1.67k|                    sizeof(map_buffer), "</map>")) != READSTAT_OK) {
  122|     10|        goto cleanup;
  123|     10|    }
  124|       |
  125|  1.66k|    ctx->data_offset = ctx->bswap ? byteswap8(map_buffer[9]) : map_buffer[9];
  ------------------
  |  Branch (125:24): [True: 1.10k, False: 566]
  ------------------
  126|  1.66k|    ctx->strls_offset = ctx->bswap ? byteswap8(map_buffer[10]) : map_buffer[10];
  ------------------
  |  Branch (126:25): [True: 1.10k, False: 566]
  ------------------
  127|  1.66k|    ctx->value_labels_offset = ctx->bswap ? byteswap8(map_buffer[11]) : map_buffer[11];
  ------------------
  |  Branch (127:32): [True: 1.10k, False: 566]
  ------------------
  128|       |
  129|  1.67k|cleanup:
  130|  1.67k|    return retval;
  131|  1.66k|}
readstat_dta_read.c:dta_read_descriptors:
  133|  3.36k|static readstat_error_t dta_read_descriptors(dta_ctx_t *ctx) {
  134|  3.36k|    readstat_error_t retval = READSTAT_OK;
  135|  3.36k|    size_t buffer_len = ctx->nvar * ctx->typlist_entry_len;
  136|  3.36k|    unsigned char *buffer = NULL;
  137|  3.36k|    int i;
  138|       |
  139|  3.36k|    if (ctx->nvar && (buffer = readstat_malloc(buffer_len)) == NULL) {
  ------------------
  |  Branch (139:9): [True: 2.44k, False: 926]
  |  Branch (139:22): [True: 0, False: 2.44k]
  ------------------
  140|      0|        retval = READSTAT_ERROR_MALLOC;
  141|      0|        goto cleanup;
  142|      0|    }
  143|       |
  144|  3.36k|    if ((retval = dta_read_chunk(ctx, "<variable_types>", buffer, 
  ------------------
  |  Branch (144:9): [True: 91, False: 3.27k]
  ------------------
  145|  3.36k|                    buffer_len, "</variable_types>")) != READSTAT_OK)
  146|     91|        goto cleanup;
  147|       |
  148|  3.27k|    if (ctx->typlist_entry_len == 1) {
  ------------------
  |  Branch (148:9): [True: 1.69k, False: 1.57k]
  ------------------
  149|   113k|        for (i=0; i<ctx->nvar; i++) {
  ------------------
  |  Branch (149:19): [True: 111k, False: 1.69k]
  ------------------
  150|   111k|            ctx->typlist[i] = buffer[i];
  151|   111k|        }
  152|  1.69k|    } else if (ctx->typlist_entry_len == 2) {
  ------------------
  |  Branch (152:16): [True: 1.57k, False: 0]
  ------------------
  153|  1.57k|        memcpy(ctx->typlist, buffer, buffer_len);
  154|  1.57k|        if (ctx->bswap) {
  ------------------
  |  Branch (154:13): [True: 1.03k, False: 543]
  ------------------
  155|  2.15k|            for (i=0; i<ctx->nvar; i++) {
  ------------------
  |  Branch (155:23): [True: 1.12k, False: 1.03k]
  ------------------
  156|  1.12k|                ctx->typlist[i] = byteswap2(ctx->typlist[i]);
  157|  1.12k|            }
  158|  1.03k|        }
  159|  1.57k|    }
  160|       |
  161|  3.27k|    if ((retval = dta_read_chunk(ctx, "<varnames>", ctx->varlist, 
  ------------------
  |  Branch (161:9): [True: 15, False: 3.26k]
  ------------------
  162|  3.27k|                    ctx->varlist_len, "</varnames>")) != READSTAT_OK)
  163|     15|        goto cleanup;
  164|       |
  165|  3.26k|    if ((retval = dta_read_chunk(ctx, "<sortlist>", ctx->srtlist, 
  ------------------
  |  Branch (165:9): [True: 19, False: 3.24k]
  ------------------
  166|  3.26k|                    ctx->srtlist_len, "</sortlist>")) != READSTAT_OK)
  167|     19|        goto cleanup;
  168|       |
  169|  3.24k|    if ((retval = dta_read_chunk(ctx, "<formats>", ctx->fmtlist, 
  ------------------
  |  Branch (169:9): [True: 4, False: 3.23k]
  ------------------
  170|  3.24k|                    ctx->fmtlist_len, "</formats>")) != READSTAT_OK)
  171|      4|        goto cleanup;
  172|       |
  173|  3.23k|    if ((retval = dta_read_chunk(ctx, "<value_label_names>", ctx->lbllist, 
  ------------------
  |  Branch (173:9): [True: 4, False: 3.23k]
  ------------------
  174|  3.23k|                    ctx->lbllist_len, "</value_label_names>")) != READSTAT_OK)
  175|      4|        goto cleanup;
  176|       |
  177|  3.23k|    if ((retval = dta_read_chunk(ctx, "<variable_labels>", ctx->variable_labels, 
  ------------------
  |  Branch (177:9): [True: 28, False: 3.20k]
  ------------------
  178|  3.23k|                    ctx->variable_labels_len, "</variable_labels>")) != READSTAT_OK)
  179|     28|        goto cleanup;
  180|       |
  181|  3.36k|cleanup:
  182|  3.36k|    if (buffer)
  ------------------
  |  Branch (182:9): [True: 2.44k, False: 926]
  ------------------
  183|  2.44k|        free(buffer);
  184|       |
  185|  3.36k|    return retval;
  186|  3.23k|}
readstat_dta_read.c:dta_handle_variables:
 1023|  3.18k|static readstat_error_t dta_handle_variables(dta_ctx_t *ctx) {
 1024|  3.18k|    readstat_error_t retval = READSTAT_OK;
 1025|  3.18k|    int i;
 1026|  3.18k|    int index_after_skipping = 0;
 1027|  3.18k|    char label_set_name[4*129+1];
 1028|       |
 1029|  38.9k|    for (i=0; i<ctx->nvar; i++) {
  ------------------
  |  Branch (1029:15): [True: 35.7k, False: 3.16k]
  ------------------
 1030|  35.7k|        size_t      max_len;
 1031|  35.7k|        readstat_type_t type;
 1032|  35.7k|        retval = dta_type_info(ctx->typlist[i], ctx, &max_len, &type);
 1033|  35.7k|        if (retval != READSTAT_OK)
  ------------------
  |  Branch (1033:13): [True: 0, False: 35.7k]
  ------------------
 1034|      0|            goto cleanup;
 1035|       |
 1036|  35.7k|        if (type == READSTAT_TYPE_STRING)
  ------------------
  |  Branch (1036:13): [True: 25.2k, False: 10.5k]
  ------------------
 1037|  25.2k|            max_len++; /* might append NULL */
 1038|  35.7k|        if (type == READSTAT_TYPE_STRING_REF) {
  ------------------
  |  Branch (1038:13): [True: 372, False: 35.4k]
  ------------------
 1039|    372|            type = READSTAT_TYPE_STRING;
 1040|    372|            max_len = 0;
 1041|    372|        }
 1042|       |
 1043|  35.7k|        ctx->variables[i] = dta_init_variable(ctx, i, index_after_skipping, type, max_len, &retval);
 1044|  35.7k|        if (ctx->variables[i] == NULL)
  ------------------
  |  Branch (1044:13): [True: 0, False: 35.7k]
  ------------------
 1045|      0|            goto cleanup;
 1046|       |
 1047|  35.7k|        const char *value_labels = NULL;
 1048|  35.7k|        const char *lbllist_entry = &ctx->lbllist[ctx->lbllist_entry_len*i];
 1049|       |
 1050|  35.7k|        if (lbllist_entry[0]) {
  ------------------
  |  Branch (1050:13): [True: 27.8k, False: 7.89k]
  ------------------
 1051|  27.8k|            retval = readstat_convert(label_set_name, sizeof(label_set_name),
 1052|  27.8k|                    lbllist_entry, strnlen(lbllist_entry, ctx->lbllist_entry_len), ctx->converter);
 1053|  27.8k|            if (retval != READSTAT_OK)
  ------------------
  |  Branch (1053:17): [True: 20, False: 27.8k]
  ------------------
 1054|     20|                goto cleanup;
 1055|  27.8k|            value_labels = label_set_name;
 1056|  27.8k|        }
 1057|       |
 1058|  35.7k|        int cb_retval = READSTAT_HANDLER_OK;
  ------------------
  |  |   22|  35.7k|#define READSTAT_HANDLER_OK             0
  ------------------
 1059|  35.7k|        if (ctx->handle.variable)
  ------------------
  |  Branch (1059:13): [True: 35.7k, False: 0]
  ------------------
 1060|  35.7k|            cb_retval = ctx->handle.variable(i, ctx->variables[i], value_labels, ctx->user_ctx);
 1061|       |
 1062|  35.7k|        if (cb_retval == READSTAT_HANDLER_ABORT) {
  ------------------
  |  |   23|  35.7k|#define READSTAT_HANDLER_ABORT          1
  ------------------
  |  Branch (1062:13): [True: 0, False: 35.7k]
  ------------------
 1063|      0|            retval = READSTAT_ERROR_USER_ABORT;
 1064|      0|            goto cleanup;
 1065|      0|        }
 1066|       |
 1067|  35.7k|        if (cb_retval == READSTAT_HANDLER_SKIP_VARIABLE) {
  ------------------
  |  |   24|  35.7k|#define READSTAT_HANDLER_SKIP_VARIABLE  2
  ------------------
  |  Branch (1067:13): [True: 0, False: 35.7k]
  ------------------
 1068|      0|            ctx->variables[i]->skip = 1;
 1069|  35.7k|        } else {
 1070|  35.7k|            index_after_skipping++;
 1071|  35.7k|        }
 1072|  35.7k|    }
 1073|  3.18k|cleanup:
 1074|  3.18k|    return retval;
 1075|  3.18k|}
readstat_dta_read.c:dta_init_variable:
   39|  35.7k|        readstat_type_t type, size_t max_len, readstat_error_t *out_retval) {
   40|  35.7k|    readstat_variable_t *variable = calloc(1, sizeof(readstat_variable_t));
   41|       |
   42|  35.7k|    if (variable == NULL) {
  ------------------
  |  Branch (42:9): [True: 0, False: 35.7k]
  ------------------
   43|      0|        if (out_retval) *out_retval = READSTAT_ERROR_MALLOC;
  ------------------
  |  Branch (43:13): [True: 0, False: 0]
  ------------------
   44|      0|        return NULL;
   45|      0|    }
   46|       |
   47|  35.7k|    variable->type = type;
   48|  35.7k|    variable->index = i;
   49|  35.7k|    variable->index_after_skipping = index_after_skipping;
   50|  35.7k|    variable->storage_width = max_len;
   51|       |
   52|  35.7k|    readstat_convert(variable->name, sizeof(variable->name), 
   53|  35.7k|            &ctx->varlist[ctx->variable_name_len*i],
   54|  35.7k|            strnlen(&ctx->varlist[ctx->variable_name_len*i], ctx->variable_name_len),
   55|  35.7k|            ctx->converter);
   56|       |
   57|  35.7k|    if (ctx->variable_labels[ctx->variable_labels_entry_len*i]) {
  ------------------
  |  Branch (57:9): [True: 12.7k, False: 23.0k]
  ------------------
   58|  12.7k|        readstat_convert(variable->label, sizeof(variable->label),
   59|  12.7k|                &ctx->variable_labels[ctx->variable_labels_entry_len*i],
   60|  12.7k|                strnlen(&ctx->variable_labels[ctx->variable_labels_entry_len*i], ctx->variable_labels_entry_len),
   61|  12.7k|                ctx->converter);
   62|  12.7k|    }
   63|       |
   64|  35.7k|    if (ctx->fmtlist[ctx->fmtlist_entry_len*i]) {
  ------------------
  |  Branch (64:9): [True: 15.2k, False: 20.5k]
  ------------------
   65|  15.2k|        readstat_convert(variable->format, sizeof(variable->format),
   66|  15.2k|                &ctx->fmtlist[ctx->fmtlist_entry_len*i],
   67|  15.2k|                strnlen(&ctx->fmtlist[ctx->fmtlist_entry_len*i], ctx->fmtlist_entry_len),
   68|  15.2k|                ctx->converter);
   69|  15.2k|        if (variable->format[0] == '%') {
  ------------------
  |  Branch (69:13): [True: 2.98k, False: 12.2k]
  ------------------
   70|  2.98k|            if (variable->format[1] == '-') {
  ------------------
  |  Branch (70:17): [True: 644, False: 2.33k]
  ------------------
   71|    644|                variable->alignment = READSTAT_ALIGNMENT_LEFT;
   72|  2.33k|            } else if (variable->format[1] == '~') {
  ------------------
  |  Branch (72:24): [True: 247, False: 2.09k]
  ------------------
   73|    247|                variable->alignment = READSTAT_ALIGNMENT_CENTER;
   74|  2.09k|            } else {
   75|  2.09k|                variable->alignment = READSTAT_ALIGNMENT_RIGHT;
   76|  2.09k|            }
   77|  2.98k|        }
   78|  15.2k|        int display_width;
   79|  15.2k|        if (sscanf(variable->format, "%%%ds", &display_width) == 1 ||
  ------------------
  |  Branch (79:13): [True: 1.16k, False: 14.0k]
  ------------------
   80|  14.0k|                sscanf(variable->format, "%%-%ds", &display_width) == 1) {
  ------------------
  |  Branch (80:17): [True: 327, False: 13.7k]
  ------------------
   81|  1.49k|            variable->display_width = display_width;
   82|  1.49k|        }
   83|  15.2k|    }
   84|       |
   85|  35.7k|    return variable;
   86|  35.7k|}
readstat_dta_read.c:dta_read_expansion_fields:
  188|  3.16k|static readstat_error_t dta_read_expansion_fields(dta_ctx_t *ctx) {
  189|  3.16k|    readstat_error_t retval = READSTAT_OK;
  190|  3.16k|    readstat_io_t *io = ctx->io;
  191|  3.16k|    char *buffer = NULL;
  192|  3.16k|    char *note_buffer = NULL;
  193|       |
  194|  3.16k|    if (ctx->expansion_len_len == 0)
  ------------------
  |  Branch (194:9): [True: 596, False: 2.57k]
  ------------------
  195|    596|        return READSTAT_OK;
  196|       |
  197|  2.57k|    if (ctx->file_is_xmlish && !ctx->handle.note) {
  ------------------
  |  Branch (197:9): [True: 1.55k, False: 1.02k]
  |  Branch (197:32): [True: 0, False: 1.55k]
  ------------------
  198|      0|        if (io->seek(ctx->data_offset, READSTAT_SEEK_SET, io->io_ctx) == -1) {
  ------------------
  |  Branch (198:13): [True: 0, False: 0]
  ------------------
  199|      0|            if (ctx->handle.error) {
  ------------------
  |  Branch (199:17): [True: 0, False: 0]
  ------------------
  200|      0|                snprintf(ctx->error_buf, sizeof(ctx->error_buf),
  201|      0|                        "Failed to seek to data section (offset=%" PRId64 ")",
  202|      0|                        ctx->data_offset);
  203|      0|                ctx->handle.error(ctx->error_buf, ctx->user_ctx);
  204|      0|            }
  205|      0|            return READSTAT_ERROR_SEEK;
  206|      0|        }
  207|      0|        return READSTAT_OK;
  208|      0|    }
  209|       |
  210|  2.57k|    retval = dta_read_tag(ctx, "<characteristics>");
  211|  2.57k|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (211:9): [True: 190, False: 2.38k]
  ------------------
  212|    190|        goto cleanup;
  213|       |
  214|  22.9k|    while (1) {
  ------------------
  |  Branch (214:12): [True: 22.9k, Folded]
  ------------------
  215|  22.9k|        size_t len;
  216|  22.9k|        char data_type;
  217|       |
  218|  22.9k|        if (ctx->file_is_xmlish) {
  ------------------
  |  Branch (218:13): [True: 1.84k, False: 21.1k]
  ------------------
  219|  1.84k|            char start[4];
  220|  1.84k|            if (io->read(start, sizeof(start), io->io_ctx) != sizeof(start)) {
  ------------------
  |  Branch (220:17): [True: 12, False: 1.83k]
  ------------------
  221|     12|                retval = READSTAT_ERROR_READ;
  222|     12|                goto cleanup;
  223|     12|            }
  224|  1.83k|            if (memcmp(start, "</ch", sizeof(start)) == 0) {
  ------------------
  |  Branch (224:17): [True: 1.26k, False: 577]
  ------------------
  225|  1.26k|                retval = dta_read_tag(ctx, "aracteristics>");
  226|  1.26k|                if (retval != READSTAT_OK)
  ------------------
  |  Branch (226:21): [True: 131, False: 1.12k]
  ------------------
  227|    131|                    goto cleanup;
  228|       |
  229|  1.12k|                break;
  230|  1.26k|            } else if (memcmp(start, "<ch>", sizeof(start)) != 0) {
  ------------------
  |  Branch (230:24): [True: 32, False: 545]
  ------------------
  231|     32|                retval = READSTAT_ERROR_PARSE;
  232|     32|                goto cleanup;
  233|     32|            }
  234|    545|            data_type = 1;
  235|  21.1k|        } else {
  236|  21.1k|            if (io->read(&data_type, 1, io->io_ctx) != 1) {
  ------------------
  |  Branch (236:17): [True: 72, False: 21.0k]
  ------------------
  237|     72|                retval = READSTAT_ERROR_READ;
  238|     72|                goto cleanup;
  239|     72|            }
  240|  21.1k|        }
  241|       |
  242|  21.6k|        if (ctx->expansion_len_len == 2) {
  ------------------
  |  Branch (242:13): [True: 19.6k, False: 1.95k]
  ------------------
  243|  19.6k|            uint16_t len16;
  244|  19.6k|            if (io->read(&len16, sizeof(uint16_t), io->io_ctx) != sizeof(uint16_t)) {
  ------------------
  |  Branch (244:17): [True: 20, False: 19.6k]
  ------------------
  245|     20|                retval = READSTAT_ERROR_READ;
  246|     20|                goto cleanup;
  247|     20|            }
  248|  19.6k|            len = ctx->bswap ? byteswap2(len16) : len16;
  ------------------
  |  Branch (248:19): [True: 2.09k, False: 17.5k]
  ------------------
  249|  19.6k|        } else {
  250|  1.95k|            uint32_t len32;
  251|  1.95k|            if (io->read(&len32, sizeof(uint32_t), io->io_ctx) != sizeof(uint32_t)) {
  ------------------
  |  Branch (251:17): [True: 13, False: 1.94k]
  ------------------
  252|     13|                retval = READSTAT_ERROR_READ;
  253|     13|                goto cleanup;
  254|     13|            }
  255|  1.94k|            len = ctx->bswap ? byteswap4(len32) : len32;
  ------------------
  |  Branch (255:19): [True: 912, False: 1.03k]
  ------------------
  256|  1.94k|        }
  257|       |
  258|  21.5k|        if (data_type == 0 && len == 0)
  ------------------
  |  Branch (258:13): [True: 1.05k, False: 20.5k]
  |  Branch (258:31): [True: 716, False: 334]
  ------------------
  259|    716|            break;
  260|       |        
  261|  20.8k|        if (len > (1<<20)) {
  ------------------
  |  Branch (261:13): [True: 24, False: 20.8k]
  ------------------
  262|     24|            retval = READSTAT_ERROR_NOTE_IS_TOO_LONG;
  263|     24|            goto cleanup;
  264|     24|        }
  265|       |
  266|  20.8k|        if (data_type == 1 && ctx->handle.note && len >= 2 * ctx->ch_metadata_len) {
  ------------------
  |  Branch (266:13): [True: 20.1k, False: 737]
  |  Branch (266:31): [True: 20.1k, False: 0]
  |  Branch (266:51): [True: 2.07k, False: 18.0k]
  ------------------
  267|  2.07k|            if ((buffer = readstat_realloc(buffer, len + 1)) == NULL) {
  ------------------
  |  Branch (267:17): [True: 0, False: 2.07k]
  ------------------
  268|      0|                retval = READSTAT_ERROR_MALLOC;
  269|      0|                goto cleanup;
  270|      0|            }
  271|  2.07k|            buffer[len] = '\0';
  272|       |
  273|  2.07k|            if (io->read(buffer, len, io->io_ctx) != len) {
  ------------------
  |  Branch (273:17): [True: 58, False: 2.01k]
  ------------------
  274|     58|                retval = READSTAT_ERROR_READ;
  275|     58|                goto cleanup;
  276|     58|            }
  277|  2.01k|            int index = 0;
  278|       |            /* _dta[note0] holds the number of notes, not a note */
  279|  2.01k|            if (strcmp(&buffer[0], "_dta") == 0 &&
  ------------------
  |  Branch (279:17): [True: 539, False: 1.47k]
  ------------------
  280|    539|                    sscanf(&buffer[ctx->ch_metadata_len], "note%d", &index) == 1 && index > 0) {
  ------------------
  |  Branch (280:21): [True: 302, False: 237]
  |  Branch (280:85): [True: 233, False: 69]
  ------------------
  281|    233|                const char *note = &buffer[2*ctx->ch_metadata_len];
  282|    233|                size_t note_len = strlen(note);
  283|    233|                if ((note_buffer = readstat_realloc(note_buffer, 4*note_len+1)) == NULL) {
  ------------------
  |  Branch (283:21): [True: 0, False: 233]
  ------------------
  284|      0|                    retval = READSTAT_ERROR_MALLOC;
  285|      0|                    goto cleanup;
  286|      0|                }
  287|    233|                retval = readstat_convert(note_buffer, 4*note_len+1, note, note_len, ctx->converter);
  288|    233|                if (retval != READSTAT_OK)
  ------------------
  |  Branch (288:21): [True: 1, False: 232]
  ------------------
  289|      1|                    goto cleanup;
  290|       |
  291|    232|                if (ctx->handle.note(index, note_buffer, ctx->user_ctx) != READSTAT_HANDLER_OK) {
  ------------------
  |  |   22|    232|#define READSTAT_HANDLER_OK             0
  ------------------
  |  Branch (291:21): [True: 0, False: 232]
  ------------------
  292|      0|                    retval = READSTAT_ERROR_USER_ABORT;
  293|      0|                    goto cleanup;
  294|      0|                }
  295|    232|            }
  296|  18.7k|        } else {
  297|  18.7k|            if (io->seek(len, READSTAT_SEEK_CUR, io->io_ctx) == -1) {
  ------------------
  |  Branch (297:17): [True: 125, False: 18.6k]
  ------------------
  298|    125|                retval = READSTAT_ERROR_SEEK;
  299|    125|                goto cleanup;
  300|    125|            }
  301|  18.7k|        }
  302|       |
  303|  20.6k|        retval = dta_read_tag(ctx, "</ch>");
  304|  20.6k|        if (retval != READSTAT_OK)
  ------------------
  |  Branch (304:13): [True: 50, False: 20.6k]
  ------------------
  305|     50|            goto cleanup;
  306|  20.6k|    }
  307|       |
  308|  2.57k|cleanup:
  309|  2.57k|    if (buffer)
  ------------------
  |  Branch (309:9): [True: 187, False: 2.38k]
  ------------------
  310|    187|        free(buffer);
  311|  2.57k|    if (note_buffer)
  ------------------
  |  Branch (311:9): [True: 28, False: 2.54k]
  ------------------
  312|     28|        free(note_buffer);
  313|       |
  314|  2.57k|    return retval;
  315|  2.38k|}
readstat_dta_read.c:dta_read_strls:
  441|  2.44k|static readstat_error_t dta_read_strls(dta_ctx_t *ctx) {
  442|  2.44k|    if (!ctx->file_is_xmlish)
  ------------------
  |  Branch (442:9): [True: 1.31k, False: 1.12k]
  ------------------
  443|  1.31k|        return READSTAT_OK;
  444|       |
  445|  1.12k|    readstat_error_t retval = READSTAT_OK;
  446|  1.12k|    readstat_io_t *io = ctx->io;
  447|       |
  448|  1.12k|    if (io->seek(ctx->strls_offset, READSTAT_SEEK_SET, io->io_ctx) == -1) {
  ------------------
  |  Branch (448:9): [True: 95, False: 1.03k]
  ------------------
  449|     95|        if (ctx->handle.error) {
  ------------------
  |  Branch (449:13): [True: 0, False: 95]
  ------------------
  450|      0|            snprintf(ctx->error_buf, sizeof(ctx->error_buf), "Failed to seek to strls section (offset=%" PRId64 ")",
  451|      0|                    ctx->strls_offset);
  452|      0|            ctx->handle.error(ctx->error_buf, ctx->user_ctx);
  453|      0|        }
  454|     95|        retval = READSTAT_ERROR_SEEK;
  455|     95|        goto cleanup;
  456|     95|    }
  457|       |
  458|  1.03k|    retval = dta_read_tag(ctx, "<strls>");
  459|  1.03k|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (459:9): [True: 76, False: 958]
  ------------------
  460|     76|        goto cleanup;
  461|       |
  462|    958|    ctx->strls_capacity = 100;
  463|    958|    if ((ctx->strls = readstat_malloc(ctx->strls_capacity * sizeof(dta_strl_t *))) == NULL) {
  ------------------
  |  Branch (463:9): [True: 0, False: 958]
  ------------------
  464|      0|        retval = READSTAT_ERROR_MALLOC;
  465|      0|        goto cleanup;
  466|      0|    }
  467|       |
  468|   125k|    while (1) {
  ------------------
  |  Branch (468:12): [True: 125k, Folded]
  ------------------
  469|   125k|        char tag[3];
  470|   125k|        if (io->read(tag, sizeof(tag), io->io_ctx) != sizeof(tag)) {
  ------------------
  |  Branch (470:13): [True: 23, False: 125k]
  ------------------
  471|     23|            retval = READSTAT_ERROR_READ;
  472|     23|            goto cleanup;
  473|     23|        }
  474|       |
  475|   125k|        if (memcmp(tag, "GSO", sizeof(tag)) == 0) {
  ------------------
  |  Branch (475:13): [True: 124k, False: 836]
  ------------------
  476|   124k|            dta_strl_t strl;
  477|   124k|            retval = dta_read_strl(ctx, &strl);
  478|   124k|            if (retval != READSTAT_OK)
  ------------------
  |  Branch (478:17): [True: 23, False: 124k]
  ------------------
  479|     23|                goto cleanup;
  480|       |
  481|   124k|            readstat_off_t pos = io->seek(0, READSTAT_SEEK_CUR, io->io_ctx);
  482|   124k|            if (pos == -1) {
  ------------------
  |  Branch (482:17): [True: 0, False: 124k]
  ------------------
  483|      0|                retval = READSTAT_ERROR_SEEK;
  484|      0|                goto cleanup;
  485|      0|            }
  486|   124k|            if (strl.len > ctx->file_size - pos) {
  ------------------
  |  Branch (486:17): [True: 76, False: 124k]
  ------------------
  487|     76|                if (ctx->handle.error) {
  ------------------
  |  Branch (487:21): [True: 0, False: 76]
  ------------------
  488|      0|                    snprintf(ctx->error_buf, sizeof(ctx->error_buf),
  489|      0|                            "strL length (%zu) exceeds remaining file size (%" PRId64 ")",
  490|      0|                            strl.len, (int64_t)(ctx->file_size - pos));
  491|      0|                    ctx->handle.error(ctx->error_buf, ctx->user_ctx);
  492|      0|                }
  493|     76|                retval = READSTAT_ERROR_PARSE;
  494|     76|                goto cleanup;
  495|     76|            }
  496|       |
  497|   124k|            if (strl.type != DTA_GSO_TYPE_ASCII && strl.type != DTA_GSO_TYPE_BINARY) {
  ------------------
  |  |  163|   248k|#define DTA_GSO_TYPE_ASCII         0x82
  ------------------
                          if (strl.type != DTA_GSO_TYPE_ASCII && strl.type != DTA_GSO_TYPE_BINARY) {
  ------------------
  |  |  162|    361|#define DTA_GSO_TYPE_BINARY        0x81
  ------------------
  |  Branch (497:17): [True: 361, False: 123k]
  |  Branch (497:52): [True: 325, False: 36]
  ------------------
  498|       |                /* Unknown record type: skip its contents */
  499|    325|                if (io->seek(strl.len, READSTAT_SEEK_CUR, io->io_ctx) == -1) {
  ------------------
  |  Branch (499:21): [True: 0, False: 325]
  ------------------
  500|      0|                    retval = READSTAT_ERROR_SEEK;
  501|      0|                    goto cleanup;
  502|      0|                }
  503|    325|                continue;
  504|    325|            }
  505|       |
  506|   123k|            if (ctx->strls_count == ctx->strls_capacity) {
  ------------------
  |  Branch (506:17): [True: 158, False: 123k]
  ------------------
  507|       |                /* Every entry corresponds to a GSO record already read from the
  508|       |                 * file, so the pointer array is bounded by the file size. Use
  509|       |                 * plain realloc rather than the capped readstat_realloc, which
  510|       |                 * fails at around 1.6 million strLs. */
  511|    158|                dta_strl_t **new_strls = realloc(ctx->strls, sizeof(dta_strl_t *) * ctx->strls_capacity * 2);
  512|    158|                if (new_strls == NULL) {
  ------------------
  |  Branch (512:21): [True: 0, False: 158]
  ------------------
  513|      0|                    retval = READSTAT_ERROR_MALLOC;
  514|      0|                    goto cleanup;
  515|      0|                }
  516|    158|                ctx->strls = new_strls;
  517|    158|                ctx->strls_capacity *= 2;
  518|    158|            }
  519|       |
  520|       |            /* The record's own length is bounded by the file size above, so
  521|       |             * a plain malloc is safe; Stata allows strLs up to 2 GB. Binary
  522|       |             * strLs (type 129) are kept too and delivered up to their first
  523|       |             * NUL, since the value API only carries C strings. */
  524|   123k|            dta_strl_t *strl_ptr = malloc(sizeof(dta_strl_t) + strl.len + 1);
  525|   123k|            if (strl_ptr == NULL) {
  ------------------
  |  Branch (525:17): [True: 0, False: 123k]
  ------------------
  526|      0|                retval = READSTAT_ERROR_MALLOC;
  527|      0|                goto cleanup;
  528|      0|            }
  529|   123k|            memcpy(strl_ptr, &strl, sizeof(dta_strl_t));
  530|       |
  531|   123k|            ctx->strls[ctx->strls_count++] = strl_ptr;
  532|       |
  533|   123k|            if (io->read(&strl_ptr->data[0], strl_ptr->len, io->io_ctx) != strl_ptr->len) {
  ------------------
  |  Branch (533:17): [True: 0, False: 123k]
  ------------------
  534|      0|                retval = READSTAT_ERROR_READ;
  535|      0|                goto cleanup;
  536|      0|            }
  537|       |            /* Type 130 records must already end in NUL, but don't trust it */
  538|   123k|            strl_ptr->data[strl_ptr->len] = '\0';
  539|   123k|        } else if (memcmp(tag, "</s", sizeof(tag)) == 0) {
  ------------------
  |  Branch (539:20): [True: 788, False: 48]
  ------------------
  540|    788|            retval = dta_read_tag(ctx, "trls>");
  541|    788|            if (retval != READSTAT_OK)
  ------------------
  |  Branch (541:17): [True: 48, False: 740]
  ------------------
  542|     48|                goto cleanup;
  543|       |            /* Stata writes the records in (o,v) order, which the lookup
  544|       |             * relies on; sort in case another writer did not */
  545|    740|            qsort(ctx->strls, ctx->strls_count, sizeof(dta_strl_t *), &dta_compare_strl_ptrs);
  546|    740|            break;
  547|    788|        } else {
  548|     48|            retval = READSTAT_ERROR_PARSE;
  549|     48|            goto cleanup;
  550|     48|        }
  551|   125k|    }
  552|       |
  553|  1.12k|cleanup:
  554|  1.12k|    return retval;
  555|    958|}
readstat_dta_read.c:dta_read_strl:
  434|   124k|static readstat_error_t dta_read_strl(dta_ctx_t *ctx, dta_strl_t *strl) {
  435|   124k|    if (ctx->strl_o_len > 4) {
  ------------------
  |  Branch (435:9): [True: 160, False: 124k]
  ------------------
  436|    160|        return dta_118_read_strl(ctx, strl);
  437|    160|    }
  438|   124k|    return dta_117_read_strl(ctx, strl);
  439|   124k|}
readstat_dta_read.c:dta_118_read_strl:
  415|    160|static readstat_error_t dta_118_read_strl(dta_ctx_t *ctx, dta_strl_t *strl) {
  416|    160|    readstat_error_t retval = READSTAT_OK;
  417|    160|    readstat_io_t *io = ctx->io;
  418|    160|    dta_118_strl_header_t header;
  419|       |
  420|    160|    if (io->read(&header, SIZEOF_DTA_118_STRL_HEADER_T, io->io_ctx) != SIZEOF_DTA_118_STRL_HEADER_T) {
  ------------------
  |  |   43|    160|#define SIZEOF_DTA_118_STRL_HEADER_T 17
  ------------------
                  if (io->read(&header, SIZEOF_DTA_118_STRL_HEADER_T, io->io_ctx) != SIZEOF_DTA_118_STRL_HEADER_T) {
  ------------------
  |  |   43|    160|#define SIZEOF_DTA_118_STRL_HEADER_T 17
  ------------------
  |  Branch (420:9): [True: 4, False: 156]
  ------------------
  421|      4|        retval = READSTAT_ERROR_READ;
  422|      4|        goto cleanup;
  423|      4|    }
  424|       |
  425|    156|    strl->v = ctx->bswap ? byteswap4(header.v) : header.v;
  ------------------
  |  Branch (425:15): [True: 0, False: 156]
  ------------------
  426|    156|    strl->o = ctx->bswap ? byteswap8(header.o) : header.o;
  ------------------
  |  Branch (426:15): [True: 0, False: 156]
  ------------------
  427|    156|    strl->type = header.type;
  428|    156|    strl->len = ctx->bswap ? byteswap4(header.len) : header.len;
  ------------------
  |  Branch (428:17): [True: 0, False: 156]
  ------------------
  429|       |
  430|    160|cleanup:
  431|    160|    return retval;
  432|    156|}
readstat_dta_read.c:dta_117_read_strl:
  396|   124k|static readstat_error_t dta_117_read_strl(dta_ctx_t *ctx, dta_strl_t *strl) {
  397|   124k|    readstat_error_t retval = READSTAT_OK;
  398|   124k|    readstat_io_t *io = ctx->io;
  399|   124k|    dta_117_strl_header_t header;
  400|       |
  401|   124k|    if (io->read(&header, SIZEOF_DTA_117_STRL_HEADER_T, io->io_ctx) != SIZEOF_DTA_117_STRL_HEADER_T) {
  ------------------
  |  |   34|   124k|#define SIZEOF_DTA_117_STRL_HEADER_T 13
  ------------------
                  if (io->read(&header, SIZEOF_DTA_117_STRL_HEADER_T, io->io_ctx) != SIZEOF_DTA_117_STRL_HEADER_T) {
  ------------------
  |  |   34|   124k|#define SIZEOF_DTA_117_STRL_HEADER_T 13
  ------------------
  |  Branch (401:9): [True: 19, False: 124k]
  ------------------
  402|     19|        retval = READSTAT_ERROR_READ;
  403|     19|        goto cleanup;
  404|     19|    }
  405|       |
  406|   124k|    strl->v = ctx->bswap ? byteswap4(header.v) : header.v;
  ------------------
  |  Branch (406:15): [True: 1.37k, False: 122k]
  ------------------
  407|   124k|    strl->o = ctx->bswap ? byteswap4(header.o) : header.o;
  ------------------
  |  Branch (407:15): [True: 1.37k, False: 122k]
  ------------------
  408|   124k|    strl->type = header.type;
  409|   124k|    strl->len = ctx->bswap ? byteswap4(header.len) : header.len;
  ------------------
  |  Branch (409:17): [True: 1.37k, False: 122k]
  ------------------
  410|       |
  411|   124k|cleanup:
  412|   124k|    return retval;
  413|   124k|}
readstat_dta_read.c:dta_compare_strl_ptrs:
  345|  47.0k|static int dta_compare_strl_ptrs(const void *elem1, const void *elem2) {
  346|  47.0k|    const dta_strl_t *key = *(const dta_strl_t **)elem1;
  347|  47.0k|    return dta_compare_strls(key, elem2);
  348|  47.0k|}
readstat_dta_read.c:dta_compare_strls:
  336|   224k|static int dta_compare_strls(const void *elem1, const void *elem2) {
  337|   224k|    const dta_strl_t *key = (const dta_strl_t *)elem1;
  338|   224k|    const dta_strl_t *target = *(const dta_strl_t **)elem2;
  339|   224k|    if (key->o != target->o)
  ------------------
  |  Branch (339:9): [True: 178k, False: 46.1k]
  ------------------
  340|   178k|        return (key->o > target->o) - (key->o < target->o);
  341|  46.1k|    return (key->v > target->v) - (key->v < target->v);
  342|   224k|}
readstat_dta_read.c:dta_read_data:
  787|  2.05k|static readstat_error_t dta_read_data(dta_ctx_t *ctx) {
  788|  2.05k|    readstat_error_t retval = READSTAT_OK;
  789|  2.05k|    readstat_io_t *io = ctx->io;
  790|       |
  791|  2.05k|    if (!ctx->handle.value) {
  ------------------
  |  Branch (791:9): [True: 0, False: 2.05k]
  ------------------
  792|      0|        return READSTAT_OK;
  793|      0|    }
  794|       |
  795|  2.05k|    if (io->seek(ctx->data_offset, READSTAT_SEEK_SET, io->io_ctx) == -1) {
  ------------------
  |  Branch (795:9): [True: 31, False: 2.02k]
  ------------------
  796|     31|        if (ctx->handle.error) {
  ------------------
  |  Branch (796:13): [True: 0, False: 31]
  ------------------
  797|      0|            snprintf(ctx->error_buf, sizeof(ctx->error_buf), "Failed to seek to data section (offset=%" PRId64 ")",
  798|      0|                    ctx->data_offset);
  799|      0|            ctx->handle.error(ctx->error_buf, ctx->user_ctx);
  800|      0|        }
  801|     31|        retval = READSTAT_ERROR_SEEK;
  802|     31|        goto cleanup;
  803|     31|    }
  804|       |
  805|  2.02k|    if ((retval = dta_read_tag(ctx, "<data>")) != READSTAT_OK)
  ------------------
  |  Branch (805:9): [True: 48, False: 1.97k]
  ------------------
  806|     48|        goto cleanup;
  807|       |
  808|  1.97k|    if ((retval = dta_update_progress(ctx)) != READSTAT_OK)
  ------------------
  |  Branch (808:9): [True: 0, False: 1.97k]
  ------------------
  809|      0|        goto cleanup;
  810|       |
  811|  1.97k|    if ((retval = dta_handle_rows(ctx)) != READSTAT_OK)
  ------------------
  |  Branch (811:9): [True: 1.02k, False: 944]
  ------------------
  812|  1.02k|        goto cleanup;
  813|       |
  814|    944|    if ((retval = dta_read_tag(ctx, "</data>")) != READSTAT_OK)
  ------------------
  |  Branch (814:9): [True: 98, False: 846]
  ------------------
  815|     98|        goto cleanup;
  816|       |
  817|  2.05k|cleanup:
  818|  2.05k|    return retval;
  819|    944|}
readstat_dta_read.c:dta_handle_rows:
  743|  1.97k|static readstat_error_t dta_handle_rows(dta_ctx_t *ctx) {
  744|  1.97k|    readstat_io_t *io = ctx->io;
  745|  1.97k|    unsigned char *buf = NULL;
  746|  1.97k|    int64_t i;
  747|  1.97k|    readstat_error_t retval = READSTAT_OK;
  748|       |
  749|  1.97k|    if (ctx->record_len && (buf = readstat_malloc(ctx->record_len)) == NULL) {
  ------------------
  |  Branch (749:9): [True: 1.37k, False: 598]
  |  Branch (749:28): [True: 0, False: 1.37k]
  ------------------
  750|      0|        retval = READSTAT_ERROR_MALLOC;
  751|      0|        goto cleanup;
  752|      0|    }
  753|       |
  754|  1.97k|    if (ctx->row_offset) {
  ------------------
  |  Branch (754:9): [True: 95, False: 1.87k]
  ------------------
  755|     95|        if (io->seek(ctx->record_len * ctx->row_offset, READSTAT_SEEK_CUR, io->io_ctx) == -1) {
  ------------------
  |  Branch (755:13): [True: 85, False: 10]
  ------------------
  756|     85|            retval = READSTAT_ERROR_SEEK;
  757|     85|            goto cleanup;
  758|     85|        }
  759|     95|    }
  760|       |
  761|   730M|    for (i=0; i<ctx->row_limit; i++) {
  ------------------
  |  Branch (761:15): [True: 730M, False: 944]
  ------------------
  762|   730M|        if (io->read(buf, ctx->record_len, io->io_ctx) != ctx->record_len) {
  ------------------
  |  Branch (762:13): [True: 916, False: 730M]
  ------------------
  763|    916|            retval = READSTAT_ERROR_READ;
  764|    916|            goto cleanup;
  765|    916|        }
  766|   730M|        if ((retval = dta_handle_row(buf, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (766:13): [True: 28, False: 730M]
  ------------------
  767|     28|            goto cleanup;
  768|     28|        }
  769|   730M|        ctx->current_row++;
  770|   730M|        if ((retval = dta_update_progress(ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (770:13): [True: 0, False: 730M]
  ------------------
  771|      0|            goto cleanup;
  772|      0|        }
  773|   730M|    }
  774|       |
  775|    944|    if (ctx->row_limit < ctx->nobs - ctx->row_offset) {
  ------------------
  |  Branch (775:9): [True: 0, False: 944]
  ------------------
  776|      0|        if (io->seek(ctx->record_len * (ctx->nobs - ctx->row_offset - ctx->row_limit), READSTAT_SEEK_CUR, io->io_ctx) == -1)
  ------------------
  |  Branch (776:13): [True: 0, False: 0]
  ------------------
  777|      0|            retval = READSTAT_ERROR_SEEK;
  778|      0|    }
  779|       |
  780|  1.97k|cleanup:
  781|  1.97k|    if (buf)
  ------------------
  |  Branch (781:9): [True: 1.37k, False: 598]
  ------------------
  782|  1.37k|        free(buf);
  783|       |
  784|  1.97k|    return retval;
  785|    944|}
readstat_dta_read.c:dta_handle_row:
  675|   730M|static readstat_error_t dta_handle_row(const unsigned char *buf, dta_ctx_t *ctx) {
  676|   730M|    char  str_buf[4*2045+1]; /* str2045 in a legacy code page, converted to UTF-8 */
  677|   730M|    int j;
  678|   730M|    readstat_off_t offset = 0;
  679|   730M|    readstat_error_t retval = READSTAT_OK;
  680|   730M|    for (j=0; j<ctx->nvar; j++) {
  ------------------
  |  Branch (680:15): [True: 69.4k, False: 730M]
  ------------------
  681|  69.4k|        size_t max_len;
  682|  69.4k|        readstat_value_t value = { { 0 } };
  683|       |
  684|  69.4k|        retval = dta_type_info(ctx->typlist[j], ctx, &max_len, &value.type);
  685|  69.4k|        if (retval != READSTAT_OK)
  ------------------
  |  Branch (685:13): [True: 0, False: 69.4k]
  ------------------
  686|      0|            goto cleanup;
  687|       |
  688|  69.4k|        if (ctx->variables[j]->skip) {
  ------------------
  |  Branch (688:13): [True: 0, False: 69.4k]
  ------------------
  689|      0|            offset += max_len;
  690|      0|            continue;
  691|      0|        }
  692|       |
  693|  69.4k|        if (offset + max_len > ctx->record_len) {
  ------------------
  |  Branch (693:13): [True: 0, False: 69.4k]
  ------------------
  694|      0|            retval = READSTAT_ERROR_PARSE;
  695|      0|            goto cleanup;
  696|      0|        }
  697|       |
  698|  69.4k|        if (value.type == READSTAT_TYPE_STRING) {
  ------------------
  |  Branch (698:13): [True: 4.22k, False: 65.2k]
  ------------------
  699|  4.22k|            if (max_len == 0) {
  ------------------
  |  Branch (699:17): [True: 2, False: 4.22k]
  ------------------
  700|      2|                retval = READSTAT_ERROR_PARSE;
  701|      2|                goto cleanup;
  702|      2|            }
  703|  4.22k|            size_t str_len = strnlen((const char *)&buf[offset], max_len);
  704|       |            /* Leading and trailing blanks are significant in Stata */
  705|  4.22k|            retval = readstat_convert_notrim(str_buf, sizeof(str_buf),
  706|  4.22k|                    (const char *)&buf[offset], str_len, ctx->converter);
  707|  4.22k|            if (retval != READSTAT_OK)
  ------------------
  |  Branch (707:17): [True: 26, False: 4.19k]
  ------------------
  708|     26|                goto cleanup;
  709|  4.19k|            value.v.string_value = str_buf;
  710|  65.2k|        } else if (value.type == READSTAT_TYPE_STRING_REF) {
  ------------------
  |  Branch (710:20): [True: 27.2k, False: 38.0k]
  ------------------
  711|  27.2k|            dta_strl_t key = dta_interpret_strl_vo_bytes(ctx, &buf[offset]);
  712|  27.2k|            dta_strl_t **found = bsearch(&key, ctx->strls, ctx->strls_count, sizeof(dta_strl_t *), &dta_compare_strls);
  713|       |
  714|  27.2k|            if (found) {
  ------------------
  |  Branch (714:17): [True: 272, False: 26.9k]
  ------------------
  715|    272|                value.v.string_value = (*found)->data;
  716|  26.9k|            } else if (key.v == 0 && key.o == 0) {
  ------------------
  |  Branch (716:24): [True: 1.62k, False: 25.3k]
  |  Branch (716:38): [True: 622, False: 1.00k]
  ------------------
  717|    622|                value.v.string_value = ""; /* the predefined empty strL */
  718|    622|            }
  719|  27.2k|            value.type = READSTAT_TYPE_STRING;
  720|  38.0k|        } else if (value.type == READSTAT_TYPE_INT8) {
  ------------------
  |  Branch (720:20): [True: 7.20k, False: 30.8k]
  ------------------
  721|  7.20k|            value = dta_interpret_int8_bytes(ctx, &buf[offset]);
  722|  30.8k|        } else if (value.type == READSTAT_TYPE_INT16) {
  ------------------
  |  Branch (722:20): [True: 3.07k, False: 27.7k]
  ------------------
  723|  3.07k|            value = dta_interpret_int16_bytes(ctx, &buf[offset]);
  724|  27.7k|        } else if (value.type == READSTAT_TYPE_INT32) {
  ------------------
  |  Branch (724:20): [True: 13.4k, False: 14.2k]
  ------------------
  725|  13.4k|            value = dta_interpret_int32_bytes(ctx, &buf[offset]);
  726|  14.2k|        } else if (value.type == READSTAT_TYPE_FLOAT) {
  ------------------
  |  Branch (726:20): [True: 5.09k, False: 9.14k]
  ------------------
  727|  5.09k|            value = dta_interpret_float_bytes(ctx, &buf[offset]);
  728|  9.14k|        } else if (value.type == READSTAT_TYPE_DOUBLE) {
  ------------------
  |  Branch (728:20): [True: 9.14k, False: 0]
  ------------------
  729|  9.14k|            value = dta_interpret_double_bytes(ctx, &buf[offset]);
  730|  9.14k|        }
  731|       |
  732|  69.4k|        if (ctx->handle.value(ctx->current_row, ctx->variables[j], value, ctx->user_ctx) != READSTAT_HANDLER_OK) {
  ------------------
  |  |   22|  69.4k|#define READSTAT_HANDLER_OK             0
  ------------------
  |  Branch (732:13): [True: 0, False: 69.4k]
  ------------------
  733|      0|            retval = READSTAT_ERROR_USER_ABORT;
  734|      0|            goto cleanup;
  735|      0|        }
  736|       |
  737|  69.4k|        offset += max_len;
  738|  69.4k|    }
  739|   730M|cleanup:
  740|   730M|    return retval;
  741|   730M|}
readstat_dta_read.c:dta_interpret_strl_vo_bytes:
  350|  27.2k|static dta_strl_t dta_interpret_strl_vo_bytes(dta_ctx_t *ctx, const unsigned char *vo_bytes) {
  351|  27.2k|    dta_strl_t strl = {0};
  352|       |
  353|  27.2k|    if (ctx->strl_v_len == 2) {
  ------------------
  |  Branch (353:9): [True: 2.18k, False: 25.0k]
  ------------------
  354|  2.18k|        if (ctx->endianness == READSTAT_ENDIAN_BIG) {
  ------------------
  |  Branch (354:13): [True: 0, False: 2.18k]
  ------------------
  355|      0|            strl.v = (vo_bytes[0] << 8) + vo_bytes[1];
  356|      0|            strl.o = (((uint64_t)vo_bytes[2] << 40)
  357|      0|                    + ((uint64_t)vo_bytes[3] << 32)
  358|      0|                    + ((uint64_t)vo_bytes[4] << 24)
  359|      0|                    + (vo_bytes[5] << 16)
  360|      0|                    + (vo_bytes[6] << 8)
  361|      0|                    + vo_bytes[7]);
  362|  2.18k|        } else {
  363|  2.18k|            strl.v = vo_bytes[0] + (vo_bytes[1] << 8);
  364|  2.18k|            strl.o = (vo_bytes[2] + (vo_bytes[3] << 8)
  365|  2.18k|                    + (vo_bytes[4] << 16)
  366|  2.18k|                    + ((uint64_t)vo_bytes[5] << 24)
  367|  2.18k|                    + ((uint64_t)vo_bytes[6] << 32)
  368|  2.18k|                    + ((uint64_t)vo_bytes[7] << 40));
  369|  2.18k|        }
  370|  25.0k|    } else if (ctx->strl_v_len == 3) {
  ------------------
  |  Branch (370:16): [True: 892, False: 24.1k]
  ------------------
  371|       |        /* Format 119 and later: 3-byte v followed by 5-byte o */
  372|    892|        int i;
  373|    892|        if (ctx->endianness == READSTAT_ENDIAN_BIG) {
  ------------------
  |  Branch (373:13): [True: 0, False: 892]
  ------------------
  374|      0|            strl.v = ((uint32_t)vo_bytes[0] << 16) + ((uint32_t)vo_bytes[1] << 8) + vo_bytes[2];
  375|      0|            for (i=3; i<8; i++) {
  ------------------
  |  Branch (375:23): [True: 0, False: 0]
  ------------------
  376|      0|                strl.o = (strl.o << 8) + vo_bytes[i];
  377|      0|            }
  378|    892|        } else {
  379|    892|            strl.v = vo_bytes[0] + ((uint32_t)vo_bytes[1] << 8) + ((uint32_t)vo_bytes[2] << 16);
  380|  5.35k|            for (i=7; i>=3; i--) {
  ------------------
  |  Branch (380:23): [True: 4.46k, False: 892]
  ------------------
  381|  4.46k|                strl.o = (strl.o << 8) + vo_bytes[i];
  382|  4.46k|            }
  383|    892|        }
  384|  24.1k|    } else if (ctx->strl_v_len == 4) {
  ------------------
  |  Branch (384:16): [True: 24.1k, False: 0]
  ------------------
  385|  24.1k|        uint32_t v, o;
  386|       |
  387|  24.1k|        memcpy(&v, &vo_bytes[0], sizeof(uint32_t));
  388|  24.1k|        memcpy(&o, &vo_bytes[4], sizeof(uint32_t));
  389|       |
  390|  24.1k|        strl.v = ctx->bswap ? byteswap4(v) : v;
  ------------------
  |  Branch (390:18): [True: 2.75k, False: 21.4k]
  ------------------
  391|  24.1k|        strl.o = ctx->bswap ? byteswap4(o) : o;
  ------------------
  |  Branch (391:18): [True: 2.75k, False: 21.4k]
  ------------------
  392|  24.1k|    }
  393|  27.2k|    return strl;
  394|  27.2k|}
readstat_dta_read.c:dta_interpret_int8_bytes:
  557|  7.20k|static readstat_value_t dta_interpret_int8_bytes(dta_ctx_t *ctx, const void *buf) {
  558|  7.20k|    readstat_value_t value = { .type = READSTAT_TYPE_INT8 };
  559|  7.20k|    int8_t byte = 0;
  560|  7.20k|    memcpy(&byte, buf, sizeof(int8_t));
  561|  7.20k|    if (ctx->machine_is_twos_complement) {
  ------------------
  |  Branch (561:9): [True: 0, False: 7.20k]
  ------------------
  562|      0|        byte = ones_to_twos_complement1(byte);
  563|      0|    }
  564|  7.20k|    if (byte > ctx->max_int8) {
  ------------------
  |  Branch (564:9): [True: 961, False: 6.24k]
  ------------------
  565|    961|        if (ctx->supports_tagged_missing && byte > DTA_113_MISSING_INT8) {
  ------------------
  |  |  150|    706|#define DTA_113_MISSING_INT8                 0x65
  ------------------
  |  Branch (565:13): [True: 706, False: 255]
  |  Branch (565:45): [True: 478, False: 228]
  ------------------
  566|    478|            value.tag = 'a' + (byte - DTA_113_MISSING_INT8_A);
  ------------------
  |  |  156|    478|#define DTA_113_MISSING_INT8_A    (DTA_113_MISSING_INT8+1)
  |  |  ------------------
  |  |  |  |  150|    478|#define DTA_113_MISSING_INT8                 0x65
  |  |  ------------------
  ------------------
  567|    478|            value.is_tagged_missing = 1;
  568|    483|        } else {
  569|    483|            value.is_system_missing = 1;
  570|    483|        }
  571|    961|    }
  572|  7.20k|    value.v.i8_value = byte;
  573|       |
  574|  7.20k|    return value;
  575|  7.20k|}
readstat_dta_read.c:dta_interpret_int16_bytes:
  577|  3.07k|static readstat_value_t dta_interpret_int16_bytes(dta_ctx_t *ctx, const void *buf) {
  578|  3.07k|    readstat_value_t value = { .type = READSTAT_TYPE_INT16 };
  579|  3.07k|    int16_t num = 0;
  580|  3.07k|    memcpy(&num, buf, sizeof(int16_t));
  581|  3.07k|    if (ctx->bswap) {
  ------------------
  |  Branch (581:9): [True: 2.40k, False: 679]
  ------------------
  582|  2.40k|        num = byteswap2(num);
  583|  2.40k|    }
  584|  3.07k|    if (ctx->machine_is_twos_complement) {
  ------------------
  |  Branch (584:9): [True: 0, False: 3.07k]
  ------------------
  585|      0|        num = ones_to_twos_complement2(num);
  586|      0|    }
  587|  3.07k|    if (num > ctx->max_int16) {
  ------------------
  |  Branch (587:9): [True: 730, False: 2.34k]
  ------------------
  588|    730|        if (ctx->supports_tagged_missing && num > DTA_113_MISSING_INT16) {
  ------------------
  |  |  151|    400|#define DTA_113_MISSING_INT16              0x7FE5
  ------------------
  |  Branch (588:13): [True: 400, False: 330]
  |  Branch (588:45): [True: 202, False: 198]
  ------------------
  589|    202|            value.tag = 'a' + (num - DTA_113_MISSING_INT16_A);
  ------------------
  |  |  157|    202|#define DTA_113_MISSING_INT16_A   (DTA_113_MISSING_INT16+1)
  |  |  ------------------
  |  |  |  |  151|    202|#define DTA_113_MISSING_INT16              0x7FE5
  |  |  ------------------
  ------------------
  590|    202|            value.is_tagged_missing = 1;
  591|    528|        } else {
  592|    528|            value.is_system_missing = 1;
  593|    528|        }
  594|    730|    }
  595|  3.07k|    value.v.i16_value = num;
  596|       |
  597|  3.07k|    return value;
  598|  3.07k|}
readstat_dta_read.c:dta_interpret_int32_bytes:
  600|  15.9k|static readstat_value_t dta_interpret_int32_bytes(dta_ctx_t *ctx, const void *buf) {
  601|  15.9k|    readstat_value_t value = { .type = READSTAT_TYPE_INT32 };
  602|  15.9k|    int32_t num = 0;
  603|  15.9k|    memcpy(&num, buf, sizeof(int32_t));
  604|  15.9k|    if (ctx->bswap) {
  ------------------
  |  Branch (604:9): [True: 2.11k, False: 13.8k]
  ------------------
  605|  2.11k|        num = byteswap4(num);
  606|  2.11k|    }
  607|  15.9k|    if (ctx->machine_is_twos_complement) {
  ------------------
  |  Branch (607:9): [True: 0, False: 15.9k]
  ------------------
  608|      0|        num = ones_to_twos_complement4(num);
  609|      0|    }
  610|  15.9k|    if (num > ctx->max_int32) {
  ------------------
  |  Branch (610:9): [True: 1.74k, False: 14.2k]
  ------------------
  611|  1.74k|        if (ctx->supports_tagged_missing && num > DTA_113_MISSING_INT32) {
  ------------------
  |  |  152|  1.47k|#define DTA_113_MISSING_INT32          0x7FFFFFE5
  ------------------
  |  Branch (611:13): [True: 1.47k, False: 269]
  |  Branch (611:45): [True: 525, False: 948]
  ------------------
  612|    525|            value.tag = 'a' + (num - DTA_113_MISSING_INT32_A);
  ------------------
  |  |  158|    525|#define DTA_113_MISSING_INT32_A   (DTA_113_MISSING_INT32+1)
  |  |  ------------------
  |  |  |  |  152|    525|#define DTA_113_MISSING_INT32          0x7FFFFFE5
  |  |  ------------------
  ------------------
  613|    525|            value.is_tagged_missing = 1;
  614|  1.21k|        } else {
  615|  1.21k|            value.is_system_missing = 1;
  616|  1.21k|        }
  617|  1.74k|    }
  618|  15.9k|    value.v.i32_value = num;
  619|       |
  620|  15.9k|    return value;
  621|  15.9k|}
readstat_dta_read.c:dta_interpret_float_bytes:
  623|  5.09k|static readstat_value_t dta_interpret_float_bytes(dta_ctx_t *ctx, const void *buf) {
  624|  5.09k|    readstat_value_t value = { .type = READSTAT_TYPE_FLOAT };
  625|  5.09k|    float f_num = NAN;
  626|  5.09k|    int32_t num = 0;
  627|  5.09k|    memcpy(&num, buf, sizeof(int32_t));
  628|  5.09k|    if (ctx->bswap) {
  ------------------
  |  Branch (628:9): [True: 919, False: 4.17k]
  ------------------
  629|    919|        num = byteswap4(num);
  630|    919|    }
  631|  5.09k|    if (num > ctx->max_float) {
  ------------------
  |  Branch (631:9): [True: 1.13k, False: 3.96k]
  ------------------
  632|  1.13k|        int32_t tag_index = (num - DTA_113_MISSING_FLOAT_A) >> 11;
  ------------------
  |  |  159|  1.13k|#define DTA_113_MISSING_FLOAT_A   (DTA_113_MISSING_FLOAT+0x0800)
  |  |  ------------------
  |  |  |  |  153|  1.13k|#define DTA_113_MISSING_FLOAT          0x7F000000
  |  |  ------------------
  ------------------
  633|  1.13k|        if (ctx->supports_tagged_missing && num >= DTA_113_MISSING_FLOAT_A && tag_index <= 25) {
  ------------------
  |  |  159|  2.03k|#define DTA_113_MISSING_FLOAT_A   (DTA_113_MISSING_FLOAT+0x0800)
  |  |  ------------------
  |  |  |  |  153|    902|#define DTA_113_MISSING_FLOAT          0x7F000000
  |  |  ------------------
  ------------------
  |  Branch (633:13): [True: 902, False: 230]
  |  Branch (633:45): [True: 618, False: 284]
  |  Branch (633:79): [True: 201, False: 417]
  ------------------
  634|    201|            value.tag = 'a' + tag_index;
  635|    201|            value.is_tagged_missing = 1;
  636|    931|        } else {
  637|    931|            value.is_system_missing = 1;
  638|    931|        }
  639|  3.96k|    } else {
  640|  3.96k|        memcpy(&f_num, &num, sizeof(int32_t));
  641|  3.96k|        if (isnan(f_num)) /* negative NaN: not a Stata value */
  ------------------
  |  Branch (641:13): [True: 439, False: 3.52k]
  ------------------
  642|    439|            value.is_system_missing = 1;
  643|  3.96k|    }
  644|  5.09k|    value.v.float_value = f_num;
  645|       |
  646|  5.09k|    return value;
  647|  5.09k|}
readstat_dta_read.c:dta_interpret_double_bytes:
  649|  9.14k|static readstat_value_t dta_interpret_double_bytes(dta_ctx_t *ctx, const void *buf) {
  650|  9.14k|    readstat_value_t value = { .type = READSTAT_TYPE_DOUBLE };
  651|  9.14k|    double d_num = NAN;
  652|  9.14k|    int64_t num = 0;
  653|  9.14k|    memcpy(&num, buf, sizeof(int64_t));
  654|  9.14k|    if (ctx->bswap) {
  ------------------
  |  Branch (654:9): [True: 1.12k, False: 8.02k]
  ------------------
  655|  1.12k|        num = byteswap8(num);
  656|  1.12k|    }
  657|  9.14k|    if (num > ctx->max_double) {
  ------------------
  |  Branch (657:9): [True: 1.09k, False: 8.05k]
  ------------------
  658|  1.09k|        int64_t tag_index = (num - DTA_113_MISSING_DOUBLE_A) >> 40;
  ------------------
  |  |  160|  1.09k|#define DTA_113_MISSING_DOUBLE_A  (DTA_113_MISSING_DOUBLE+0x010000000000)
  |  |  ------------------
  |  |  |  |  154|  1.09k|#define DTA_113_MISSING_DOUBLE 0x7FE0000000000000L
  |  |  ------------------
  ------------------
  659|  1.09k|        if (ctx->supports_tagged_missing && num >= DTA_113_MISSING_DOUBLE_A && tag_index <= 25) {
  ------------------
  |  |  160|  1.93k|#define DTA_113_MISSING_DOUBLE_A  (DTA_113_MISSING_DOUBLE+0x010000000000)
  |  |  ------------------
  |  |  |  |  154|    842|#define DTA_113_MISSING_DOUBLE 0x7FE0000000000000L
  |  |  ------------------
  ------------------
  |  Branch (659:13): [True: 842, False: 249]
  |  Branch (659:45): [True: 484, False: 358]
  |  Branch (659:80): [True: 218, False: 266]
  ------------------
  660|    218|            value.tag = 'a' + tag_index;
  661|    218|            value.is_tagged_missing = 1;
  662|    873|        } else {
  663|    873|            value.is_system_missing = 1;
  664|    873|        }
  665|  8.05k|    } else {
  666|  8.05k|        memcpy(&d_num, &num, sizeof(int64_t));
  667|  8.05k|        if (isnan(d_num)) /* negative NaN: not a Stata value */
  ------------------
  |  Branch (667:13): [True: 593, False: 7.46k]
  ------------------
  668|    593|            value.is_system_missing = 1;
  669|  8.05k|    }
  670|  9.14k|    value.v.double_value = d_num;
  671|       |
  672|  9.14k|    return value;
  673|  9.14k|}
readstat_dta_read.c:dta_handle_value_labels:
 1077|    846|static readstat_error_t dta_handle_value_labels(dta_ctx_t *ctx) {
 1078|    846|    readstat_io_t *io = ctx->io;
 1079|    846|    readstat_error_t retval = READSTAT_OK;
 1080|    846|    char *table_buffer = NULL;
 1081|    846|    char *utf8_buffer = NULL;
 1082|       |
 1083|    846|    if (io->seek(ctx->value_labels_offset, READSTAT_SEEK_SET, io->io_ctx) == -1) {
  ------------------
  |  Branch (1083:9): [True: 6, False: 840]
  ------------------
 1084|      6|        if (ctx->handle.error) {
  ------------------
  |  Branch (1084:13): [True: 0, False: 6]
  ------------------
 1085|      0|            snprintf(ctx->error_buf, sizeof(ctx->error_buf), "Failed to seek to value labels section (offset=%" PRId64 ")",
 1086|      0|                    ctx->value_labels_offset);
 1087|      0|            ctx->handle.error(ctx->error_buf, ctx->user_ctx);
 1088|      0|        }
 1089|      6|        retval = READSTAT_ERROR_SEEK;
 1090|      6|        goto cleanup;
 1091|      6|    }
 1092|    840|    if ((retval = dta_read_tag(ctx, "<value_labels>")) != READSTAT_OK) {
  ------------------
  |  Branch (1092:9): [True: 127, False: 713]
  ------------------
 1093|    127|        goto cleanup;
 1094|    127|    }
 1095|       |
 1096|    713|    if (!ctx->handle.value_label) {
  ------------------
  |  Branch (1096:9): [True: 0, False: 713]
  ------------------
 1097|      0|        return READSTAT_OK;
 1098|      0|    }
 1099|       |
 1100|  98.9k|    while (1) {
  ------------------
  |  Branch (1100:12): [True: 98.9k, Folded]
  ------------------
 1101|  98.9k|        size_t len = 0;
 1102|  98.9k|        char raw_labname[129+1];
 1103|  98.9k|        char labname[4*129+1];
 1104|  98.9k|        uint32_t i = 0, n = 0;
 1105|       |
 1106|  98.9k|        if (ctx->value_label_table_len_len == 2) {
  ------------------
  |  Branch (1106:13): [True: 94.3k, False: 4.61k]
  ------------------
 1107|       |            /* Formats 105 and earlier: n (int16), labname, 1 byte of padding,
 1108|       |             * n int16 codes, then n 8-byte labels */
 1109|  94.3k|            uint16_t n16;
 1110|  94.3k|            if (io->read(&n16, sizeof(uint16_t), io->io_ctx) < sizeof(uint16_t))
  ------------------
  |  Branch (1110:17): [True: 93, False: 94.2k]
  ------------------
 1111|     93|                break;
 1112|       |
 1113|  94.2k|            n = ctx->bswap ? byteswap2(n16) : n16;
  ------------------
  |  Branch (1113:17): [True: 90.1k, False: 4.12k]
  ------------------
 1114|  94.2k|            len = 10 * n;
 1115|  94.2k|        } else {
 1116|  4.61k|            if (dta_read_tag(ctx, "<lbl>") != READSTAT_OK) {
  ------------------
  |  Branch (1116:17): [True: 68, False: 4.54k]
  ------------------
 1117|     68|                break;
 1118|     68|            }
 1119|       |
 1120|  4.54k|            int32_t table_header_len;
 1121|  4.54k|            if (io->read(&table_header_len, sizeof(int32_t), io->io_ctx) < sizeof(int32_t))
  ------------------
  |  Branch (1121:17): [True: 68, False: 4.47k]
  ------------------
 1122|     68|                break;
 1123|       |
 1124|  4.47k|            len = table_header_len;
 1125|       |
 1126|  4.47k|            if (ctx->bswap)
  ------------------
  |  Branch (1126:17): [True: 1.31k, False: 3.16k]
  ------------------
 1127|  1.31k|                len = byteswap4(table_header_len);
 1128|  4.47k|        }
 1129|       |
 1130|  98.7k|        if (io->read(raw_labname, ctx->value_label_table_labname_len, io->io_ctx) < ctx->value_label_table_labname_len)
  ------------------
  |  Branch (1130:13): [True: 92, False: 98.6k]
  ------------------
 1131|     92|            break;
 1132|  98.6k|        retval = readstat_convert(labname, sizeof(labname), raw_labname,
 1133|  98.6k|                strnlen(raw_labname, ctx->value_label_table_labname_len), ctx->converter);
 1134|  98.6k|        if (retval != READSTAT_OK)
  ------------------
  |  Branch (1134:13): [True: 5, False: 98.6k]
  ------------------
 1135|      5|            goto cleanup;
 1136|       |
 1137|  98.6k|        if (io->seek(ctx->value_label_table_padding_len, READSTAT_SEEK_CUR, io->io_ctx) == -1)
  ------------------
  |  Branch (1137:13): [True: 9, False: 98.6k]
  ------------------
 1138|      9|            break;
 1139|       |
 1140|  98.6k|        if (len == 0)
  ------------------
  |  Branch (1140:13): [True: 96.1k, False: 2.49k]
  ------------------
 1141|  96.1k|            continue;
 1142|       |
 1143|  2.49k|        if ((table_buffer = readstat_realloc(table_buffer, len)) == NULL) {
  ------------------
  |  Branch (1143:13): [True: 77, False: 2.42k]
  ------------------
 1144|     77|            retval = READSTAT_ERROR_MALLOC;
 1145|     77|            goto cleanup;
 1146|     77|        }
 1147|       |
 1148|  2.42k|        if (io->read(table_buffer, len, io->io_ctx) < len) {
  ------------------
  |  Branch (1148:13): [True: 82, False: 2.34k]
  ------------------
 1149|     82|            break;
 1150|     82|        }
 1151|       |
 1152|  2.34k|        if (ctx->value_label_table_len_len == 2) {
  ------------------
  |  Branch (1152:13): [True: 359, False: 1.98k]
  ------------------
 1153|   116k|            for (i=0; i<n; i++) {
  ------------------
  |  Branch (1153:23): [True: 116k, False: 350]
  ------------------
 1154|   116k|                int16_t code = 0;
 1155|   116k|                char label_buf[4*8+1];
 1156|   116k|                const char *label_bytes = &table_buffer[2*n + 8*i];
 1157|       |
 1158|   116k|                memcpy(&code, &table_buffer[2*i], sizeof(int16_t));
 1159|   116k|                if (ctx->bswap)
  ------------------
  |  Branch (1159:21): [True: 82.2k, False: 34.3k]
  ------------------
 1160|  82.2k|                    code = byteswap2(code);
 1161|       |
 1162|   116k|                readstat_value_t value = { .v = { .i32_value = code }, .type = READSTAT_TYPE_INT32 };
 1163|       |
 1164|   116k|                retval = readstat_convert(label_buf, sizeof(label_buf),
 1165|   116k|                        label_bytes, strnlen(label_bytes, 8), ctx->converter);
 1166|   116k|                if (retval != READSTAT_OK)
  ------------------
  |  Branch (1166:21): [True: 9, False: 116k]
  ------------------
 1167|      9|                    goto cleanup;
 1168|       |
 1169|   116k|                if (label_buf[0] && ctx->handle.value_label(labname, value, label_buf, ctx->user_ctx) != READSTAT_HANDLER_OK) {
  ------------------
  |  |   22|  38.9k|#define READSTAT_HANDLER_OK             0
  ------------------
  |  Branch (1169:21): [True: 38.9k, False: 77.6k]
  |  Branch (1169:37): [True: 0, False: 38.9k]
  ------------------
 1170|      0|                    retval = READSTAT_ERROR_USER_ABORT;
 1171|      0|                    goto cleanup;
 1172|      0|                }
 1173|   116k|            }
 1174|  1.98k|        } else if (len >= 8) {
  ------------------
  |  Branch (1174:20): [True: 1.64k, False: 337]
  ------------------
 1175|  1.64k|            if ((retval = dta_read_tag(ctx, "</lbl>")) != READSTAT_OK) {
  ------------------
  |  Branch (1175:17): [True: 6, False: 1.63k]
  ------------------
 1176|      6|                goto cleanup;
 1177|      6|            }
 1178|       |
 1179|  1.63k|            n = *(uint32_t *)table_buffer;
 1180|       |
 1181|  1.63k|            uint32_t txtlen = *((uint32_t *)table_buffer+1);
 1182|  1.63k|            if (ctx->bswap) {
  ------------------
  |  Branch (1182:17): [True: 492, False: 1.14k]
  ------------------
 1183|    492|                n = byteswap4(n);
 1184|    492|                txtlen = byteswap4(txtlen);
 1185|    492|            }
 1186|       |
 1187|  1.63k|            if (txtlen > len - 8 || n > (len - 8 - txtlen) / 8) {
  ------------------
  |  Branch (1187:17): [True: 40, False: 1.59k]
  |  Branch (1187:37): [True: 43, False: 1.55k]
  ------------------
 1188|     83|                break;
 1189|     83|            }
 1190|       |
 1191|  1.55k|            uint32_t *off = (uint32_t *)table_buffer+2;
 1192|  1.55k|            uint32_t *val = (uint32_t *)table_buffer+2+n;
 1193|  1.55k|            char *txt = &table_buffer[8LL*n+8];
 1194|  1.55k|            size_t utf8_buffer_len = 4*txtlen+1;
 1195|  1.55k|            if (txtlen > MAX_VALUE_LABEL_LEN+1)
  ------------------
  |  |   21|  1.55k|#define MAX_VALUE_LABEL_LEN 32000
  ------------------
  |  Branch (1195:17): [True: 12, False: 1.54k]
  ------------------
 1196|     12|                utf8_buffer_len = 4*MAX_VALUE_LABEL_LEN+1;
  ------------------
  |  |   21|     12|#define MAX_VALUE_LABEL_LEN 32000
  ------------------
 1197|       |
 1198|  1.55k|            utf8_buffer = readstat_realloc(utf8_buffer, utf8_buffer_len);
 1199|       |            /* Much bigger than we need but whatever */
 1200|  1.55k|            if (utf8_buffer == NULL) {
  ------------------
  |  Branch (1200:17): [True: 0, False: 1.55k]
  ------------------
 1201|      0|                retval = READSTAT_ERROR_MALLOC;
 1202|      0|                goto cleanup;
 1203|      0|            }
 1204|       |
 1205|  1.55k|            if (ctx->bswap) {
  ------------------
  |  Branch (1205:17): [True: 426, False: 1.12k]
  ------------------
 1206|  2.15k|                for (i=0; i<n; i++) {
  ------------------
  |  Branch (1206:27): [True: 1.72k, False: 426]
  ------------------
 1207|  1.72k|                    off[i] = byteswap4(off[i]);
 1208|  1.72k|                }
 1209|    426|            }
 1210|       |
 1211|  4.00k|            for (i=0; i<n; i++) {
  ------------------
  |  Branch (1211:23): [True: 2.57k, False: 1.43k]
  ------------------
 1212|  2.57k|                if (off[i] >= txtlen) {
  ------------------
  |  Branch (1212:21): [True: 117, False: 2.45k]
  ------------------
 1213|    117|                    retval = READSTAT_ERROR_PARSE;
 1214|    117|                    goto cleanup;
 1215|    117|                }
 1216|       |
 1217|  2.45k|                readstat_value_t value = dta_interpret_int32_bytes(ctx, &val[i]);
 1218|  2.45k|                size_t max_label_len = txtlen - off[i];
 1219|  2.45k|                if (max_label_len > MAX_VALUE_LABEL_LEN)
  ------------------
  |  |   21|  2.45k|#define MAX_VALUE_LABEL_LEN 32000
  ------------------
  |  Branch (1219:21): [True: 723, False: 1.73k]
  ------------------
 1220|    723|                    max_label_len = MAX_VALUE_LABEL_LEN;
  ------------------
  |  |   21|    723|#define MAX_VALUE_LABEL_LEN 32000
  ------------------
 1221|  2.45k|                size_t label_len = strnlen(&txt[off[i]], max_label_len);
 1222|       |
 1223|  2.45k|                retval = readstat_convert(utf8_buffer, utf8_buffer_len, &txt[off[i]], label_len, ctx->converter);
 1224|  2.45k|                if (retval != READSTAT_OK)
  ------------------
  |  Branch (1224:21): [True: 4, False: 2.45k]
  ------------------
 1225|      4|                    goto cleanup;
 1226|       |
 1227|  2.45k|                if (ctx->handle.value_label(labname, value, utf8_buffer, ctx->user_ctx) != READSTAT_HANDLER_OK) {
  ------------------
  |  |   22|  2.45k|#define READSTAT_HANDLER_OK             0
  ------------------
  |  Branch (1227:21): [True: 0, False: 2.45k]
  ------------------
 1228|      0|                    retval = READSTAT_ERROR_USER_ABORT;
 1229|      0|                    goto cleanup;
 1230|      0|                }
 1231|  2.45k|            }
 1232|  1.55k|        }
 1233|  2.34k|    }
 1234|       |
 1235|    846|cleanup:
 1236|    846|    if (table_buffer)
  ------------------
  |  Branch (1236:9): [True: 460, False: 386]
  ------------------
 1237|    460|        free(table_buffer);
 1238|    846|    if (utf8_buffer)
  ------------------
  |  Branch (1238:9): [True: 241, False: 605]
  ------------------
 1239|    241|        free(utf8_buffer);
 1240|       |
 1241|    846|    return retval;
 1242|    713|}

rt_open_handler:
    8|  4.48k|int rt_open_handler(const char *path, void *io_ctx) {
    9|  4.48k|    return 0;
   10|  4.48k|}
rt_close_handler:
   12|  4.48k|int rt_close_handler(void *io_ctx) {
   13|  4.48k|    return 0;
   14|  4.48k|}
rt_seek_handler:
   17|   256k|        readstat_io_flags_t whence, void *io_ctx) {
   18|   256k|    rt_buffer_ctx_t *buffer_ctx = (rt_buffer_ctx_t *)io_ctx;
   19|   256k|    readstat_off_t newpos = -1;
   20|   256k|    if (whence == READSTAT_SEEK_SET) {
  ------------------
  |  Branch (20:9): [True: 8.51k, False: 247k]
  ------------------
   21|  8.51k|        newpos = offset;
   22|   247k|    } else if (whence == READSTAT_SEEK_CUR) {
  ------------------
  |  Branch (22:16): [True: 243k, False: 4.48k]
  ------------------
   23|   243k|        newpos = buffer_ctx->pos + offset;
   24|   243k|    } else if (whence == READSTAT_SEEK_END) {
  ------------------
  |  Branch (24:16): [True: 4.48k, False: 0]
  ------------------
   25|  4.48k|        newpos = buffer_ctx->buffer->used + offset;
   26|  4.48k|    }
   27|       |
   28|   256k|    if (newpos < 0)
  ------------------
  |  Branch (28:9): [True: 123, False: 256k]
  ------------------
   29|    123|        return -1;
   30|       |
   31|   256k|    if (newpos > buffer_ctx->buffer->used)
  ------------------
  |  Branch (31:9): [True: 228, False: 255k]
  ------------------
   32|    228|        return -1;
   33|       |
   34|   255k|    buffer_ctx->pos = newpos;
   35|   255k|    return newpos;
   36|   256k|}
rt_read_handler:
   38|   731M|ssize_t rt_read_handler(void *buf, size_t nbytes, void *io_ctx) {
   39|   731M|    rt_buffer_ctx_t *buffer_ctx = (rt_buffer_ctx_t *)io_ctx;
   40|   731M|    ssize_t bytes_copied = 0;
   41|   731M|    ssize_t bytes_left = buffer_ctx->buffer->used - buffer_ctx->pos;
   42|   731M|    if (nbytes <= bytes_left) {
  ------------------
  |  Branch (42:9): [True: 731M, False: 1.98k]
  ------------------
   43|   731M|        memcpy(buf, buffer_ctx->buffer->bytes + buffer_ctx->pos, nbytes);
   44|   731M|        bytes_copied = nbytes;
   45|   731M|    } else if (bytes_left > 0) {
  ------------------
  |  Branch (45:16): [True: 796, False: 1.19k]
  ------------------
   46|    796|        memcpy(buf, buffer_ctx->buffer->bytes + buffer_ctx->pos, bytes_left);
   47|    796|        bytes_copied = bytes_left;
   48|    796|    }
   49|   731M|    buffer_ctx->pos += bytes_copied;
   50|   731M|    return bytes_copied;
   51|   731M|}

