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

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

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

readstat_convert:
   39|   130k|readstat_error_t readstat_convert(char *dst, size_t dst_len, const char *src, size_t src_len, iconv_t converter) {
   40|   130k|    return readstat_convert_impl(dst, dst_len, src, src_len, converter, 1);
   41|   130k|}
readstat_convert_notrim:
   43|  3.18k|readstat_error_t readstat_convert_notrim(char *dst, size_t dst_len, const char *src, size_t src_len, iconv_t converter) {
   44|  3.18k|    return readstat_convert_impl(dst, dst_len, src, src_len, converter, 0);
   45|  3.18k|}
readstat_convert.c:readstat_convert_impl:
    8|   133k|        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|   136k|    while (src_len && ((trim_spaces && src[src_len-1] == ' ') || src[src_len-1] == '\0')) {
  ------------------
  |  Branch (11:12): [True: 99.4k, False: 36.7k]
  |  Branch (11:25): [True: 96.5k, False: 2.89k]
  |  Branch (11:40): [True: 1.36k, False: 95.1k]
  |  Branch (11:66): [True: 1.31k, False: 96.7k]
  ------------------
   12|  2.68k|        src_len--;
   13|  2.68k|    }
   14|   133k|    if (dst_len == 0) {
  ------------------
  |  Branch (14:9): [True: 0, False: 133k]
  ------------------
   15|      0|        return READSTAT_ERROR_CONVERT_LONG_STRING;
   16|   133k|    } else if (converter) {
  ------------------
  |  Branch (16:16): [True: 131k, False: 2.40k]
  ------------------
   17|   131k|        size_t dst_left = dst_len - 1;
   18|   131k|        char *dst_end = dst;
   19|   131k|        size_t status = iconv(converter, (readstat_iconv_inbuf_t)&src, &src_len, &dst_end, &dst_left);
   20|   131k|        if (status == (size_t)-1) {
  ------------------
  |  Branch (20:13): [True: 354, False: 130k]
  ------------------
   21|    354|            if (errno == E2BIG) {
  ------------------
  |  Branch (21:17): [True: 0, False: 354]
  ------------------
   22|      0|                return READSTAT_ERROR_CONVERT_LONG_STRING;
   23|    354|            } else if (errno == EILSEQ) {
  ------------------
  |  Branch (23:24): [True: 354, False: 0]
  ------------------
   24|    354|                return READSTAT_ERROR_CONVERT_BAD_STRING;
   25|    354|            } 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|    354|        }
   29|   130k|        dst[dst_len - dst_left - 1] = '\0';
   30|   130k|    } else if (src_len + 1 > dst_len) {
  ------------------
  |  Branch (30:16): [True: 4, False: 2.40k]
  ------------------
   31|      4|        return READSTAT_ERROR_CONVERT_LONG_STRING;
   32|  2.40k|    } else {
   33|  2.40k|        memcpy(dst, src, src_len);
   34|  2.40k|        dst[src_len] = '\0';
   35|  2.40k|    }
   36|   133k|    return READSTAT_OK;
   37|   133k|}

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

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

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

dta_format_is_supported:
   19|  3.90k|int dta_format_is_supported(int ds_format) {
   20|  3.90k|    switch (ds_format) {
  ------------------
  |  Branch (20:13): [True: 3.69k, False: 201]
  ------------------
   21|  1.20k|        case 104: case 105: case 108: case 110: case 111:
  ------------------
  |  Branch (21:9): [True: 742, False: 3.15k]
  |  Branch (21:19): [True: 451, False: 3.44k]
  |  Branch (21:29): [True: 5, False: 3.89k]
  |  Branch (21:39): [True: 3, False: 3.89k]
  |  Branch (21:49): [True: 6, False: 3.89k]
  ------------------
   22|  3.69k|        case 113: case 114: case 115: case 117: case 118: case 119:
  ------------------
  |  Branch (22:9): [True: 257, False: 3.64k]
  |  Branch (22:19): [True: 11, False: 3.88k]
  |  Branch (22:29): [True: 8, False: 3.89k]
  |  Branch (22:39): [True: 1.73k, False: 2.16k]
  |  Branch (22:49): [True: 313, False: 3.58k]
  |  Branch (22:59): [True: 165, False: 3.73k]
  ------------------
   23|  3.69k|            return 1;
   24|  3.90k|    }
   25|    201|    return 0;
   26|  3.90k|}
dta_ctx_alloc:
   28|  4.36k|dta_ctx_t *dta_ctx_alloc(readstat_io_t *io) {
   29|  4.36k|    dta_ctx_t *ctx = calloc(1, sizeof(dta_ctx_t));
   30|  4.36k|    if (ctx == NULL) {
  ------------------
  |  Branch (30:9): [True: 0, False: 4.36k]
  ------------------
   31|      0|        return NULL;
   32|      0|    }
   33|       |
   34|  4.36k|    ctx->io = io;
   35|  4.36k|    ctx->initialized = 0;
   36|       |
   37|  4.36k|    return ctx;
   38|  4.36k|}
dta_ctx_init:
   42|  3.90k|        const char *input_encoding, const char *output_encoding) {
   43|  3.90k|    readstat_error_t retval = READSTAT_OK;
   44|  3.90k|    int machine_byteorder = DTA_HILO;
  ------------------
  |  |  129|  3.90k|#define DTA_HILO  0x01
  ------------------
   45|  3.90k|    if (!dta_format_is_supported(ds_format))
  ------------------
  |  Branch (45:9): [True: 201, False: 3.69k]
  ------------------
   46|    201|        return READSTAT_ERROR_UNSUPPORTED_FILE_FORMAT_VERSION;
   47|       |
   48|  3.69k|    if (machine_is_little_endian()) {
  ------------------
  |  Branch (48:9): [True: 3.69k, False: 0]
  ------------------
   49|  3.69k|        machine_byteorder = DTA_LOHI;
  ------------------
  |  |  130|  3.69k|#define DTA_LOHI  0x02
  ------------------
   50|  3.69k|    }
   51|       |
   52|  3.69k|    ctx->bswap = (byteorder != machine_byteorder);
   53|  3.69k|    ctx->ds_format = ds_format;
   54|  3.69k|    ctx->endianness = byteorder == DTA_LOHI ? READSTAT_ENDIAN_LITTLE : READSTAT_ENDIAN_BIG;
  ------------------
  |  |  130|  3.69k|#define DTA_LOHI  0x02
  ------------------
  |  Branch (54:23): [True: 1.25k, False: 2.44k]
  ------------------
   55|       |
   56|  3.69k|    ctx->nvar = nvar;
   57|  3.69k|    ctx->nobs = nobs;
   58|       |
   59|  3.69k|    if (ctx->nvar) {
  ------------------
  |  Branch (59:9): [True: 2.46k, False: 1.23k]
  ------------------
   60|  2.46k|        if ((ctx->variables = calloc(ctx->nvar, sizeof(readstat_variable_t *))) == NULL) {
  ------------------
  |  Branch (60:13): [True: 46, False: 2.41k]
  ------------------
   61|     46|            retval = READSTAT_ERROR_MALLOC;
   62|     46|            goto cleanup;
   63|     46|        }
   64|  2.46k|    }
   65|       |
   66|  3.65k|    ctx->machine_is_twos_complement = READSTAT_MACHINE_IS_TWOS_COMPLEMENT;
  ------------------
  |  |    8|  3.65k|#define READSTAT_MACHINE_IS_TWOS_COMPLEMENT 0
  ------------------
   67|       |
   68|  3.65k|    if (ds_format < 105) {
  ------------------
  |  Branch (68:9): [True: 742, False: 2.91k]
  ------------------
   69|    742|        ctx->fmtlist_entry_len = 7;
   70|  2.91k|    } else if (ds_format < 114) {
  ------------------
  |  Branch (70:16): [True: 722, False: 2.18k]
  ------------------
   71|    722|        ctx->fmtlist_entry_len = 12;
   72|  2.18k|    } else if (ds_format < 118) {
  ------------------
  |  Branch (72:16): [True: 1.75k, False: 432]
  ------------------
   73|  1.75k|        ctx->fmtlist_entry_len = 49;
   74|  1.75k|    } else {
   75|    432|        ctx->fmtlist_entry_len = 57;
   76|    432|    }
   77|       |    
   78|  3.65k|    if (ds_format >= 117) {
  ------------------
  |  Branch (78:9): [True: 2.17k, False: 1.48k]
  ------------------
   79|  2.17k|        ctx->typlist_version = 117;
   80|  2.17k|    } else if (ds_format >= 111) {
  ------------------
  |  Branch (80:16): [True: 282, False: 1.20k]
  ------------------
   81|    282|        ctx->typlist_version = 111;
   82|  1.20k|    } else {
   83|  1.20k|        ctx->typlist_version = 0;
   84|  1.20k|    }
   85|       |
   86|  3.65k|    if (ds_format >= 119) {
  ------------------
  |  Branch (86:9): [True: 119, False: 3.53k]
  ------------------
   87|       |        /* The 8-byte (v,o) field in the data is a 3-byte v and a 5-byte o */
   88|    119|        ctx->data_label_len_len = 2;
   89|    119|        ctx->strl_v_len = 3;
   90|    119|        ctx->strl_o_len = 5;
   91|  3.53k|    } else if (ds_format >= 118) {
  ------------------
  |  Branch (91:16): [True: 313, False: 3.22k]
  ------------------
   92|    313|        ctx->data_label_len_len = 2;
   93|    313|        ctx->strl_v_len = 2;
   94|    313|        ctx->strl_o_len = 6;
   95|  3.22k|    } else if (ds_format >= 117) {
  ------------------
  |  Branch (95:16): [True: 1.73k, False: 1.48k]
  ------------------
   96|  1.73k|        ctx->data_label_len_len = 1;
   97|  1.73k|        ctx->strl_v_len = 4;
   98|  1.73k|        ctx->strl_o_len = 4;
   99|  1.73k|    }
  100|       |
  101|  3.65k|    if (ds_format < 105) {
  ------------------
  |  Branch (101:9): [True: 742, False: 2.91k]
  ------------------
  102|    742|        ctx->expansion_len_len = 0;
  103|  2.91k|    } else if (ds_format < 110) {
  ------------------
  |  Branch (103:16): [True: 456, False: 2.45k]
  ------------------
  104|    456|        ctx->expansion_len_len = 2;
  105|  2.45k|    } else {
  106|  2.45k|        ctx->expansion_len_len = 4;
  107|  2.45k|    }
  108|       |    
  109|  3.65k|    if (ds_format < 110) {
  ------------------
  |  Branch (109:9): [True: 1.19k, False: 2.45k]
  ------------------
  110|  1.19k|        ctx->lbllist_entry_len = 9;
  111|  1.19k|        ctx->variable_name_len = 9;
  112|  1.19k|        ctx->ch_metadata_len = 9;
  113|  2.45k|    } else if (ds_format < 118) {
  ------------------
  |  Branch (113:16): [True: 2.02k, False: 432]
  ------------------
  114|  2.02k|        ctx->lbllist_entry_len = 33;
  115|  2.02k|        ctx->variable_name_len = 33;
  116|  2.02k|        ctx->ch_metadata_len = 33;
  117|  2.02k|    } else {
  118|    432|        ctx->lbllist_entry_len = 129;
  119|    432|        ctx->variable_name_len = 129;
  120|    432|        ctx->ch_metadata_len = 129;
  121|    432|    }
  122|       |
  123|  3.65k|    if (ds_format < 108) {
  ------------------
  |  Branch (123:9): [True: 1.19k, False: 2.46k]
  ------------------
  124|  1.19k|        ctx->variable_labels_entry_len = 32;
  125|  1.19k|        ctx->data_label_len = 32;
  126|  2.46k|    } else if (ds_format < 118) {
  ------------------
  |  Branch (126:16): [True: 2.02k, False: 432]
  ------------------
  127|  2.02k|        ctx->variable_labels_entry_len = 81;
  128|  2.02k|        ctx->data_label_len = 81;
  129|  2.02k|    } else {
  130|    432|        ctx->variable_labels_entry_len = 321;
  131|    432|        ctx->data_label_len = 321;
  132|    432|    }
  133|       |
  134|  3.65k|    if (ds_format < 105) {
  ------------------
  |  Branch (134:9): [True: 742, False: 2.91k]
  ------------------
  135|    742|        ctx->timestamp_len = 0;
  136|  2.91k|    } else {
  137|  2.91k|        ctx->timestamp_len = 18;
  138|  2.91k|    }
  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.65k|    if (ds_format < 108) {
  ------------------
  |  Branch (144:9): [True: 1.19k, False: 2.46k]
  ------------------
  145|  1.19k|        ctx->value_label_table_len_len = 2;
  146|  1.19k|        ctx->value_label_table_labname_len = 9;
  147|  1.19k|        ctx->value_label_table_padding_len = 1;
  148|  2.46k|    } else {
  149|  2.46k|        ctx->value_label_table_len_len = 4;
  150|  2.46k|        if (ds_format < 110) {
  ------------------
  |  Branch (150:13): [True: 5, False: 2.45k]
  ------------------
  151|      5|            ctx->value_label_table_labname_len = 9;
  152|  2.45k|        } else if (ds_format < 118) {
  ------------------
  |  Branch (152:20): [True: 2.02k, False: 432]
  ------------------
  153|  2.02k|            ctx->value_label_table_labname_len = 33;
  154|  2.02k|        } else {
  155|    432|            ctx->value_label_table_labname_len = 129;
  156|    432|        }
  157|  2.46k|        ctx->value_label_table_padding_len = 3;
  158|  2.46k|    }
  159|       |
  160|  3.65k|    if (ds_format < 117) {
  ------------------
  |  Branch (160:9): [True: 1.48k, False: 2.17k]
  ------------------
  161|  1.48k|        ctx->typlist_entry_len = 1;
  162|  1.48k|        ctx->file_is_xmlish = 0;
  163|  2.17k|    } else {
  164|  2.17k|        ctx->typlist_entry_len = 2;
  165|  2.17k|        ctx->file_is_xmlish = 1;
  166|  2.17k|    }
  167|       |
  168|  3.65k|    if (ds_format < 113) {
  ------------------
  |  Branch (168:9): [True: 1.20k, False: 2.44k]
  ------------------
  169|  1.20k|        ctx->max_int8 = DTA_OLD_MAX_INT8;
  ------------------
  |  |  132|  1.20k|#define DTA_OLD_MAX_INT8                     0x7e
  ------------------
  170|  1.20k|        ctx->max_int16 = DTA_OLD_MAX_INT16;
  ------------------
  |  |  133|  1.20k|#define DTA_OLD_MAX_INT16                  0x7ffe
  ------------------
  171|  1.20k|        ctx->max_int32 = DTA_OLD_MAX_INT32;
  ------------------
  |  |  134|  1.20k|#define DTA_OLD_MAX_INT32              0x7ffffffe
  ------------------
  172|  1.20k|        ctx->max_float = DTA_OLD_MAX_FLOAT;
  ------------------
  |  |  135|  1.20k|#define DTA_OLD_MAX_FLOAT              0x7effffff // +1.7e38f
  ------------------
  173|  1.20k|        ctx->max_double = DTA_OLD_MAX_DOUBLE;
  ------------------
  |  |  136|  1.20k|#define DTA_OLD_MAX_DOUBLE     0x7fdfffffffffffffL // +8.9e307
  ------------------
  174|  2.44k|    } else {
  175|  2.44k|        ctx->max_int8 = DTA_113_MAX_INT8;
  ------------------
  |  |  144|  2.44k|#define DTA_113_MAX_INT8                    0x64
  ------------------
  176|  2.44k|        ctx->max_int16 = DTA_113_MAX_INT16;
  ------------------
  |  |  145|  2.44k|#define DTA_113_MAX_INT16                 0x7fe4
  ------------------
  177|  2.44k|        ctx->max_int32 = DTA_113_MAX_INT32;
  ------------------
  |  |  146|  2.44k|#define DTA_113_MAX_INT32             0x7fffffe4
  ------------------
  178|  2.44k|        ctx->max_float = DTA_113_MAX_FLOAT;
  ------------------
  |  |  147|  2.44k|#define DTA_113_MAX_FLOAT             0x7effffff // +1.7e38f
  ------------------
  179|  2.44k|        ctx->max_double = DTA_113_MAX_DOUBLE;
  ------------------
  |  |  148|  2.44k|#define DTA_113_MAX_DOUBLE    0x7fdfffffffffffffL // +8.9e307
  ------------------
  180|       |
  181|  2.44k|        ctx->supports_tagged_missing = 1;
  182|  2.44k|    }
  183|       |
  184|  3.65k|    if (output_encoding) {
  ------------------
  |  Branch (184:9): [True: 3.65k, False: 0]
  ------------------
  185|  3.65k|        if (input_encoding) {
  ------------------
  |  Branch (185:13): [True: 0, False: 3.65k]
  ------------------
  186|      0|            ctx->converter = iconv_open(output_encoding, input_encoding);
  187|  3.65k|        } else if (ds_format < 118) {
  ------------------
  |  Branch (187:20): [True: 3.22k, False: 432]
  ------------------
  188|  3.22k|            ctx->converter = iconv_open(output_encoding, "WINDOWS-1252");
  189|  3.22k|        } else if (strcmp(output_encoding, "UTF-8") != 0) {
  ------------------
  |  Branch (189:20): [True: 0, False: 432]
  ------------------
  190|      0|            ctx->converter = iconv_open(output_encoding, "UTF-8");
  191|      0|        }
  192|  3.65k|        if (ctx->converter == (iconv_t)-1) {
  ------------------
  |  Branch (192:13): [True: 0, False: 3.65k]
  ------------------
  193|      0|            ctx->converter = NULL;
  194|      0|            retval = READSTAT_ERROR_UNSUPPORTED_CHARSET;
  195|      0|            goto cleanup;
  196|      0|        }
  197|  3.65k|    }
  198|       |
  199|  3.65k|    if (ds_format < 119) {
  ------------------
  |  Branch (199:9): [True: 3.53k, False: 119]
  ------------------
  200|  3.53k|        ctx->srtlist_len = (ctx->nvar + 1) * sizeof(int16_t);
  201|  3.53k|    } else {
  202|    119|        ctx->srtlist_len = (ctx->nvar + 1) * sizeof(int32_t);
  203|    119|    }
  204|       |
  205|  3.65k|    if ((ctx->srtlist = malloc(ctx->srtlist_len)) == NULL) {
  ------------------
  |  Branch (205:9): [True: 0, False: 3.65k]
  ------------------
  206|      0|        retval = READSTAT_ERROR_MALLOC;
  207|      0|        goto cleanup;
  208|      0|    }
  209|       |
  210|  3.65k|    if (ctx->nvar > 0) {
  ------------------
  |  Branch (210:9): [True: 2.41k, False: 1.23k]
  ------------------
  211|  2.41k|        if (ctx->file_size > 0) {
  ------------------
  |  Branch (211:13): [True: 2.41k, 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.41k|            size_t bytes_per_var = ctx->typlist_entry_len + ctx->variable_name_len
  216|  2.41k|                + ctx->fmtlist_entry_len + ctx->lbllist_entry_len + ctx->variable_labels_entry_len
  217|  2.41k|                + (ds_format < 119 ? sizeof(int16_t) : sizeof(int32_t));
  ------------------
  |  Branch (217:20): [True: 2.33k, False: 81]
  ------------------
  218|  2.41k|            if ((uint64_t)ctx->nvar * bytes_per_var > ctx->file_size) {
  ------------------
  |  Branch (218:17): [True: 116, False: 2.30k]
  ------------------
  219|    116|                retval = READSTAT_ERROR_PARSE;
  220|    116|                goto cleanup;
  221|    116|            }
  222|  2.41k|        }
  223|  2.30k|        ctx->typlist_len = ctx->nvar * sizeof(uint16_t);
  224|  2.30k|        ctx->varlist_len = ctx->variable_name_len * ctx->nvar * sizeof(char);
  225|  2.30k|        ctx->fmtlist_len = ctx->fmtlist_entry_len * ctx->nvar * sizeof(char);
  226|  2.30k|        ctx->lbllist_len = ctx->lbllist_entry_len * ctx->nvar * sizeof(char);
  227|  2.30k|        ctx->variable_labels_len = ctx->variable_labels_entry_len * ctx->nvar * sizeof(char);
  228|       |
  229|  2.30k|        if ((ctx->typlist = malloc(ctx->typlist_len)) == NULL) {
  ------------------
  |  Branch (229:13): [True: 0, False: 2.30k]
  ------------------
  230|      0|            retval = READSTAT_ERROR_MALLOC;
  231|      0|            goto cleanup;
  232|      0|        }
  233|  2.30k|        if ((ctx->varlist = malloc(ctx->varlist_len)) == NULL) {
  ------------------
  |  Branch (233:13): [True: 0, False: 2.30k]
  ------------------
  234|      0|            retval = READSTAT_ERROR_MALLOC;
  235|      0|            goto cleanup;
  236|      0|        }
  237|  2.30k|        if ((ctx->fmtlist = malloc(ctx->fmtlist_len)) == NULL) {
  ------------------
  |  Branch (237:13): [True: 0, False: 2.30k]
  ------------------
  238|      0|            retval = READSTAT_ERROR_MALLOC;
  239|      0|            goto cleanup;
  240|      0|        }
  241|  2.30k|        if ((ctx->lbllist = malloc(ctx->lbllist_len)) == NULL) {
  ------------------
  |  Branch (241:13): [True: 0, False: 2.30k]
  ------------------
  242|      0|            retval = READSTAT_ERROR_MALLOC;
  243|      0|            goto cleanup;
  244|      0|        }
  245|  2.30k|        if ((ctx->variable_labels = malloc(ctx->variable_labels_len)) == NULL) {
  ------------------
  |  Branch (245:13): [True: 0, False: 2.30k]
  ------------------
  246|      0|            retval = READSTAT_ERROR_MALLOC;
  247|      0|            goto cleanup;
  248|      0|        }
  249|  2.30k|    }
  250|       |
  251|  3.53k|    ctx->initialized = 1;
  252|       |
  253|  3.69k|cleanup:
  254|  3.69k|    return retval;
  255|  3.53k|}
dta_ctx_free:
  257|  4.36k|void dta_ctx_free(dta_ctx_t *ctx) {
  258|  4.36k|    if (ctx->typlist)
  ------------------
  |  Branch (258:9): [True: 2.30k, False: 2.06k]
  ------------------
  259|  2.30k|        free(ctx->typlist);
  260|  4.36k|    if (ctx->varlist)
  ------------------
  |  Branch (260:9): [True: 2.30k, False: 2.06k]
  ------------------
  261|  2.30k|        free(ctx->varlist);
  262|  4.36k|    if (ctx->srtlist)
  ------------------
  |  Branch (262:9): [True: 3.65k, False: 715]
  ------------------
  263|  3.65k|        free(ctx->srtlist);
  264|  4.36k|    if (ctx->fmtlist)
  ------------------
  |  Branch (264:9): [True: 2.30k, False: 2.06k]
  ------------------
  265|  2.30k|        free(ctx->fmtlist);
  266|  4.36k|    if (ctx->lbllist)
  ------------------
  |  Branch (266:9): [True: 2.30k, False: 2.06k]
  ------------------
  267|  2.30k|        free(ctx->lbllist);
  268|  4.36k|    if (ctx->variable_labels)
  ------------------
  |  Branch (268:9): [True: 2.30k, False: 2.06k]
  ------------------
  269|  2.30k|        free(ctx->variable_labels);
  270|  4.36k|    if (ctx->converter)
  ------------------
  |  Branch (270:9): [True: 3.22k, False: 1.14k]
  ------------------
  271|  3.22k|        iconv_close(ctx->converter);
  272|  4.36k|    if (ctx->data_label)
  ------------------
  |  Branch (272:9): [True: 3.32k, False: 1.04k]
  ------------------
  273|  3.32k|        free(ctx->data_label);
  274|  4.36k|    if (ctx->variables) {
  ------------------
  |  Branch (274:9): [True: 2.41k, False: 1.95k]
  ------------------
  275|  2.41k|        int i;
  276|  10.5G|        for (i=0; i<ctx->nvar; i++) {
  ------------------
  |  Branch (276:19): [True: 10.5G, False: 2.41k]
  ------------------
  277|  10.5G|            if (ctx->variables[i])
  ------------------
  |  Branch (277:17): [True: 6.70k, False: 10.5G]
  ------------------
  278|  6.70k|                free(ctx->variables[i]);
  279|  10.5G|        }
  280|  2.41k|        free(ctx->variables);
  281|  2.41k|    }
  282|  4.36k|    if (ctx->strls) {
  ------------------
  |  Branch (282:9): [True: 866, False: 3.50k]
  ------------------
  283|    866|        int i;
  284|  82.5k|        for (i=0; i<ctx->strls_count; i++) {
  ------------------
  |  Branch (284:19): [True: 81.6k, False: 866]
  ------------------
  285|  81.6k|            free(ctx->strls[i]);
  286|  81.6k|        }
  287|    866|        free(ctx->strls);
  288|    866|    }
  289|  4.36k|    free(ctx);
  290|  4.36k|}
dta_type_info:
  293|  80.1k|        size_t *max_len, readstat_type_t *out_type) {
  294|  80.1k|    readstat_error_t retval = READSTAT_OK;
  295|  80.1k|    size_t len = 0;
  296|  80.1k|    readstat_type_t type = READSTAT_TYPE_STRING;
  297|  80.1k|    if (ctx->typlist_version == 111) {
  ------------------
  |  Branch (297:9): [True: 37.0k, False: 43.0k]
  ------------------
  298|  37.0k|        switch (typecode) {
  299|    852|            case DTA_111_TYPE_CODE_INT8:
  ------------------
  |  |  172|    852|#define DTA_111_TYPE_CODE_INT8     0xFB
  ------------------
  |  Branch (299:13): [True: 852, False: 36.2k]
  ------------------
  300|    852|                len = 1; type = READSTAT_TYPE_INT8; break;
  301|    419|            case DTA_111_TYPE_CODE_INT16:
  ------------------
  |  |  173|    419|#define DTA_111_TYPE_CODE_INT16    0xFC
  ------------------
  |  Branch (301:13): [True: 419, False: 36.6k]
  ------------------
  302|    419|                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: 25.1k]
  ------------------
  304|  11.9k|                len = 4; type = READSTAT_TYPE_INT32; break;
  305|    442|            case DTA_111_TYPE_CODE_FLOAT:
  ------------------
  |  |  175|    442|#define DTA_111_TYPE_CODE_FLOAT    0xFE
  ------------------
  |  Branch (305:13): [True: 442, False: 36.6k]
  ------------------
  306|    442|                len = 4; type = READSTAT_TYPE_FLOAT; break;
  307|  1.14k|            case DTA_111_TYPE_CODE_DOUBLE:
  ------------------
  |  |  176|  1.14k|#define DTA_111_TYPE_CODE_DOUBLE   0xFF
  ------------------
  |  Branch (307:13): [True: 1.14k, False: 35.9k]
  ------------------
  308|  1.14k|                len = 8; type = READSTAT_TYPE_DOUBLE; break;
  309|  22.2k|            default:
  ------------------
  |  Branch (309:13): [True: 22.2k, False: 14.8k]
  ------------------
  310|  22.2k|                len = typecode; type = READSTAT_TYPE_STRING; break;
  311|  37.0k|        }
  312|  43.0k|    } else if (ctx->typlist_version == 117) {
  ------------------
  |  Branch (312:16): [True: 22.5k, False: 20.5k]
  ------------------
  313|  22.5k|        switch (typecode) {
  314|  1.36k|            case DTA_117_TYPE_CODE_INT8:
  ------------------
  |  |  165|  1.36k|#define DTA_117_TYPE_CODE_INT8     0xFFFA
  ------------------
  |  Branch (314:13): [True: 1.36k, False: 21.2k]
  ------------------
  315|  1.36k|                len = 1; type = READSTAT_TYPE_INT8; break;
  316|  5.30k|            case DTA_117_TYPE_CODE_INT16:
  ------------------
  |  |  166|  5.30k|#define DTA_117_TYPE_CODE_INT16    0xFFF9
  ------------------
  |  Branch (316:13): [True: 5.30k, False: 17.2k]
  ------------------
  317|  5.30k|                len = 2; type = READSTAT_TYPE_INT16; break;
  318|  1.82k|            case DTA_117_TYPE_CODE_INT32:
  ------------------
  |  |  167|  1.82k|#define DTA_117_TYPE_CODE_INT32    0xFFF8
  ------------------
  |  Branch (318:13): [True: 1.82k, False: 20.7k]
  ------------------
  319|  1.82k|                len = 4; type = READSTAT_TYPE_INT32; break;
  320|    797|            case DTA_117_TYPE_CODE_FLOAT:
  ------------------
  |  |  168|    797|#define DTA_117_TYPE_CODE_FLOAT    0xFFF7
  ------------------
  |  Branch (320:13): [True: 797, False: 21.7k]
  ------------------
  321|    797|                len = 4; type = READSTAT_TYPE_FLOAT; break;
  322|    850|            case DTA_117_TYPE_CODE_DOUBLE:
  ------------------
  |  |  169|    850|#define DTA_117_TYPE_CODE_DOUBLE   0xFFF6
  ------------------
  |  Branch (322:13): [True: 850, False: 21.7k]
  ------------------
  323|    850|                len = 8; type = READSTAT_TYPE_DOUBLE; break;
  324|  9.01k|            case DTA_117_TYPE_CODE_STRL:
  ------------------
  |  |  170|  9.01k|#define DTA_117_TYPE_CODE_STRL     0x8000
  ------------------
  |  Branch (324:13): [True: 9.01k, False: 13.5k]
  ------------------
  325|  9.01k|                len = 8; type = READSTAT_TYPE_STRING_REF; break;
  326|  3.43k|            default:
  ------------------
  |  Branch (326:13): [True: 3.43k, False: 19.1k]
  ------------------
  327|  3.43k|                len = typecode; type = READSTAT_TYPE_STRING; break;
  328|  22.5k|        }
  329|  22.5k|    } else if (typecode < 0x7F) {
  ------------------
  |  Branch (329:16): [True: 13.2k, False: 7.28k]
  ------------------
  330|  13.2k|        switch (typecode) {
  331|  10.3k|            case DTA_OLD_TYPE_CODE_INT8:
  ------------------
  |  |  178|  10.3k|#define DTA_OLD_TYPE_CODE_INT8     'b'
  ------------------
  |  Branch (331:13): [True: 10.3k, False: 2.83k]
  ------------------
  332|  10.3k|                len = 1; type = READSTAT_TYPE_INT8; break;
  333|    937|            case DTA_OLD_TYPE_CODE_INT16:
  ------------------
  |  |  179|    937|#define DTA_OLD_TYPE_CODE_INT16    'i'
  ------------------
  |  Branch (333:13): [True: 937, False: 12.2k]
  ------------------
  334|    937|                len = 2; type = READSTAT_TYPE_INT16; break;
  335|    589|            case DTA_OLD_TYPE_CODE_INT32:
  ------------------
  |  |  180|    589|#define DTA_OLD_TYPE_CODE_INT32    'l'
  ------------------
  |  Branch (335:13): [True: 589, False: 12.6k]
  ------------------
  336|    589|                len = 4; type = READSTAT_TYPE_INT32; break;
  337|    658|            case DTA_OLD_TYPE_CODE_FLOAT:
  ------------------
  |  |  181|    658|#define DTA_OLD_TYPE_CODE_FLOAT    'f'
  ------------------
  |  Branch (337:13): [True: 658, False: 12.5k]
  ------------------
  338|    658|                len = 4; type = READSTAT_TYPE_FLOAT; break;
  339|    628|            case DTA_OLD_TYPE_CODE_DOUBLE:
  ------------------
  |  |  182|    628|#define DTA_OLD_TYPE_CODE_DOUBLE   'd'
  ------------------
  |  Branch (339:13): [True: 628, False: 12.5k]
  ------------------
  340|    628|                len = 8; type = READSTAT_TYPE_DOUBLE; break;
  341|     18|            default:
  ------------------
  |  Branch (341:13): [True: 18, False: 13.1k]
  ------------------
  342|     18|                retval = READSTAT_ERROR_PARSE; break;
  343|  13.2k|        }
  344|  13.2k|    } else {
  345|  7.28k|        len = typecode - 0x7F;
  346|  7.28k|        type = READSTAT_TYPE_STRING;
  347|  7.28k|    }
  348|       |    
  349|  80.1k|    if (max_len)
  ------------------
  |  Branch (349:9): [True: 80.1k, False: 0]
  ------------------
  350|  80.1k|        *max_len = len;
  351|  80.1k|    if (out_type)
  ------------------
  |  Branch (351:9): [True: 44.9k, False: 35.2k]
  ------------------
  352|  44.9k|        *out_type = type;
  353|       |
  354|  80.1k|    return retval;
  355|  80.1k|}

dta_parse_timestamp:
  145|    772|readstat_error_handler error_handler, void *user_ctx) {
  146|    772|	readstat_error_t retval = READSTAT_OK;
  147|    772|	const char *p = data;
  148|    772|	const char *pe = p + len;
  149|    772|	const char *eof = pe;
  150|    772|	int cs;
  151|    772|	unsigned int temp_val = 0;
  152|       |	
  153|    772|#line 154 "src/stata/readstat_dta_parse_timestamp.c"
  154|    772|	{
  155|    772|		cs = (int)dta_timestamp_parse_start;
  156|    772|	}
  157|       |	
  158|    772|#line 159 "src/stata/readstat_dta_parse_timestamp.c"
  159|    772|	{
  160|    772|		int _klen;
  161|    772|		unsigned int _trans = 0;
  162|    772|		const char * _keys;
  163|    772|		const signed char * _acts;
  164|    772|		unsigned int _nacts;
  165|  3.41k|		_resume: {}
  166|  3.41k|		if ( p == pe && p != eof )
  ------------------
  |  Branch (166:8): [True: 66, False: 3.34k]
  |  Branch (166:19): [True: 0, False: 66]
  ------------------
  167|      0|			goto _out;
  168|  3.41k|		if ( p == eof ) {
  ------------------
  |  Branch (168:8): [True: 66, False: 3.34k]
  ------------------
  169|     66|			if ( _dta_timestamp_parse_eof_trans[cs] > 0 ) {
  ------------------
  |  Branch (169:9): [True: 66, False: 0]
  ------------------
  170|     66|				_trans = (unsigned int)_dta_timestamp_parse_eof_trans[cs] - 1;
  171|     66|			}
  172|     66|		}
  173|  3.34k|		else {
  174|  3.34k|			_keys = ( _dta_timestamp_parse_trans_keys + (_dta_timestamp_parse_key_offsets[cs]));
  175|  3.34k|			_trans = (unsigned int)_dta_timestamp_parse_index_offsets[cs];
  176|       |			
  177|  3.34k|			_klen = (int)_dta_timestamp_parse_single_lengths[cs];
  178|  3.34k|			if ( _klen > 0 ) {
  ------------------
  |  Branch (178:9): [True: 2.85k, False: 488]
  ------------------
  179|  2.85k|				const char *_lower = _keys;
  180|  2.85k|				const char *_upper = _keys + _klen - 1;
  181|  2.85k|				const char *_mid;
  182|  5.47k|				while ( 1 ) {
  ------------------
  |  Branch (182:13): [True: 5.47k, Folded]
  ------------------
  183|  5.47k|					if ( _upper < _lower ) {
  ------------------
  |  Branch (183:11): [True: 1.99k, False: 3.47k]
  ------------------
  184|  1.99k|						_keys += _klen;
  185|  1.99k|						_trans += (unsigned int)_klen;
  186|  1.99k|						break;
  187|  1.99k|					}
  188|       |					
  189|  3.47k|					_mid = _lower + ((_upper-_lower) >> 1);
  190|  3.47k|					if ( ( (*( p))) < (*( _mid)) )
  ------------------
  |  Branch (190:11): [True: 752, False: 2.72k]
  ------------------
  191|    752|						_upper = _mid - 1;
  192|  2.72k|					else if ( ( (*( p))) > (*( _mid)) )
  ------------------
  |  Branch (192:16): [True: 1.86k, False: 858]
  ------------------
  193|  1.86k|						_lower = _mid + 1;
  194|    858|					else {
  195|    858|						_trans += (unsigned int)(_mid - _keys);
  196|    858|						goto _match;
  197|    858|					}
  198|  3.47k|				}
  199|  2.85k|			}
  200|       |			
  201|  2.48k|			_klen = (int)_dta_timestamp_parse_range_lengths[cs];
  202|  2.48k|			if ( _klen > 0 ) {
  ------------------
  |  Branch (202:9): [True: 2.46k, False: 25]
  ------------------
  203|  2.46k|				const char *_lower = _keys;
  204|  2.46k|				const char *_upper = _keys + (_klen<<1) - 2;
  205|  2.46k|				const char *_mid;
  206|  3.14k|				while ( 1 ) {
  ------------------
  |  Branch (206:13): [True: 3.14k, Folded]
  ------------------
  207|  3.14k|					if ( _upper < _lower ) {
  ------------------
  |  Branch (207:11): [True: 681, False: 2.46k]
  ------------------
  208|    681|						_trans += (unsigned int)_klen;
  209|    681|						break;
  210|    681|					}
  211|       |					
  212|  2.46k|					_mid = _lower + (((_upper-_lower) >> 1) & ~1);
  213|  2.46k|					if ( ( (*( p))) < (*( _mid)) )
  ------------------
  |  Branch (213:11): [True: 364, False: 2.09k]
  ------------------
  214|    364|						_upper = _mid - 2;
  215|  2.09k|					else if ( ( (*( p))) > (*( _mid + 1)) )
  ------------------
  |  Branch (215:16): [True: 317, False: 1.78k]
  ------------------
  216|    317|						_lower = _mid + 2;
  217|  1.78k|					else {
  218|  1.78k|						_trans += (unsigned int)((_mid - _keys)>>1);
  219|  1.78k|						break;
  220|  1.78k|					}
  221|  2.46k|				}
  222|  2.46k|			}
  223|       |			
  224|  3.34k|			_match: {}
  225|  3.34k|		}
  226|  3.41k|		cs = (int)_dta_timestamp_parse_cond_targs[_trans];
  227|       |		
  228|  3.41k|		if ( _dta_timestamp_parse_cond_actions[_trans] != 0 ) {
  ------------------
  |  Branch (228:8): [True: 2.17k, False: 1.24k]
  ------------------
  229|       |			
  230|  2.17k|			_acts = ( _dta_timestamp_parse_actions + (_dta_timestamp_parse_cond_actions[_trans]));
  231|  2.17k|			_nacts = (unsigned int)(*( _acts));
  232|  2.17k|			_acts += 1;
  233|  4.85k|			while ( _nacts > 0 ) {
  ------------------
  |  Branch (233:12): [True: 2.68k, False: 2.17k]
  ------------------
  234|  2.68k|				switch ( (*( _acts)) )
  ------------------
  |  Branch (234:14): [True: 2.68k, False: 0]
  ------------------
  235|  2.68k|				{
  236|  1.78k|					case 0:  {
  ------------------
  |  Branch (236:6): [True: 1.78k, False: 905]
  ------------------
  237|  1.78k|						{
  238|  1.78k|#line 20 "src/stata/readstat_dta_parse_timestamp.rl"
  239|       |							
  240|  1.78k|							temp_val = 10 * temp_val + ((( (*( p)))) - '0');
  241|  1.78k|						}
  242|       |						
  243|  1.78k|#line 244 "src/stata/readstat_dta_parse_timestamp.c"
  244|       |						
  245|  1.78k|						break; 
  246|      0|					}
  247|    515|					case 1:  {
  ------------------
  |  Branch (247:6): [True: 515, False: 2.17k]
  ------------------
  248|    515|						{
  249|    515|#line 24 "src/stata/readstat_dta_parse_timestamp.rl"
  250|    515|							temp_val = 0; }
  251|       |						
  252|    515|#line 253 "src/stata/readstat_dta_parse_timestamp.c"
  253|       |						
  254|    515|						break; 
  255|      0|					}
  256|    131|					case 2:  {
  ------------------
  |  Branch (256:6): [True: 131, False: 2.55k]
  ------------------
  257|    131|						{
  258|    131|#line 26 "src/stata/readstat_dta_parse_timestamp.rl"
  259|    131|							timestamp->tm_mday = temp_val; }
  260|       |						
  261|    131|#line 262 "src/stata/readstat_dta_parse_timestamp.c"
  262|       |						
  263|    131|						break; 
  264|      0|					}
  265|     22|					case 3:  {
  ------------------
  |  Branch (265:6): [True: 22, False: 2.66k]
  ------------------
  266|     22|						{
  267|     22|#line 29 "src/stata/readstat_dta_parse_timestamp.rl"
  268|     22|							timestamp->tm_mon = 0; }
  269|       |						
  270|     22|#line 271 "src/stata/readstat_dta_parse_timestamp.c"
  271|       |						
  272|     22|						break; 
  273|      0|					}
  274|      1|					case 4:  {
  ------------------
  |  Branch (274:6): [True: 1, False: 2.68k]
  ------------------
  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|      1|					case 5:  {
  ------------------
  |  Branch (283:6): [True: 1, False: 2.68k]
  ------------------
  284|      1|						{
  285|      1|#line 31 "src/stata/readstat_dta_parse_timestamp.rl"
  286|      1|							timestamp->tm_mon = 2; }
  287|       |						
  288|      1|#line 289 "src/stata/readstat_dta_parse_timestamp.c"
  289|       |						
  290|      1|						break; 
  291|      0|					}
  292|     13|					case 6:  {
  ------------------
  |  Branch (292:6): [True: 13, False: 2.67k]
  ------------------
  293|     13|						{
  294|     13|#line 32 "src/stata/readstat_dta_parse_timestamp.rl"
  295|     13|							timestamp->tm_mon = 3; }
  296|       |						
  297|     13|#line 298 "src/stata/readstat_dta_parse_timestamp.c"
  298|       |						
  299|     13|						break; 
  300|      0|					}
  301|     18|					case 7:  {
  ------------------
  |  Branch (301:6): [True: 18, False: 2.66k]
  ------------------
  302|     18|						{
  303|     18|#line 33 "src/stata/readstat_dta_parse_timestamp.rl"
  304|     18|							timestamp->tm_mon = 4; }
  305|       |						
  306|     18|#line 307 "src/stata/readstat_dta_parse_timestamp.c"
  307|       |						
  308|     18|						break; 
  309|      0|					}
  310|     15|					case 8:  {
  ------------------
  |  Branch (310:6): [True: 15, False: 2.67k]
  ------------------
  311|     15|						{
  312|     15|#line 34 "src/stata/readstat_dta_parse_timestamp.rl"
  313|     15|							timestamp->tm_mon = 5; }
  314|       |						
  315|     15|#line 316 "src/stata/readstat_dta_parse_timestamp.c"
  316|       |						
  317|     15|						break; 
  318|      0|					}
  319|      1|					case 9:  {
  ------------------
  |  Branch (319:6): [True: 1, False: 2.68k]
  ------------------
  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|      1|					case 10:  {
  ------------------
  |  Branch (328:6): [True: 1, False: 2.68k]
  ------------------
  329|      1|						{
  330|      1|#line 36 "src/stata/readstat_dta_parse_timestamp.rl"
  331|      1|							timestamp->tm_mon = 7; }
  332|       |						
  333|      1|#line 334 "src/stata/readstat_dta_parse_timestamp.c"
  334|       |						
  335|      1|						break; 
  336|      0|					}
  337|      4|					case 11:  {
  ------------------
  |  Branch (337:6): [True: 4, False: 2.68k]
  ------------------
  338|      4|						{
  339|      4|#line 37 "src/stata/readstat_dta_parse_timestamp.rl"
  340|      4|							timestamp->tm_mon = 8; }
  341|       |						
  342|      4|#line 343 "src/stata/readstat_dta_parse_timestamp.c"
  343|       |						
  344|      4|						break; 
  345|      0|					}
  346|     17|					case 12:  {
  ------------------
  |  Branch (346:6): [True: 17, False: 2.66k]
  ------------------
  347|     17|						{
  348|     17|#line 38 "src/stata/readstat_dta_parse_timestamp.rl"
  349|     17|							timestamp->tm_mon = 9; }
  350|       |						
  351|     17|#line 352 "src/stata/readstat_dta_parse_timestamp.c"
  352|       |						
  353|     17|						break; 
  354|      0|					}
  355|      1|					case 13:  {
  ------------------
  |  Branch (355:6): [True: 1, False: 2.68k]
  ------------------
  356|      1|						{
  357|      1|#line 39 "src/stata/readstat_dta_parse_timestamp.rl"
  358|      1|							timestamp->tm_mon = 10; }
  359|       |						
  360|      1|#line 361 "src/stata/readstat_dta_parse_timestamp.c"
  361|       |						
  362|      1|						break; 
  363|      0|					}
  364|      1|					case 14:  {
  ------------------
  |  Branch (364:6): [True: 1, False: 2.68k]
  ------------------
  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|     75|					case 15:  {
  ------------------
  |  Branch (373:6): [True: 75, False: 2.61k]
  ------------------
  374|     75|						{
  375|     75|#line 42 "src/stata/readstat_dta_parse_timestamp.rl"
  376|     75|							timestamp->tm_year = temp_val - 1900; }
  377|       |						
  378|     75|#line 379 "src/stata/readstat_dta_parse_timestamp.c"
  379|       |						
  380|     75|						break; 
  381|      0|					}
  382|     50|					case 16:  {
  ------------------
  |  Branch (382:6): [True: 50, False: 2.63k]
  ------------------
  383|     50|						{
  384|     50|#line 44 "src/stata/readstat_dta_parse_timestamp.rl"
  385|     50|							timestamp->tm_hour = temp_val; }
  386|       |						
  387|     50|#line 388 "src/stata/readstat_dta_parse_timestamp.c"
  388|       |						
  389|     50|						break; 
  390|      0|					}
  391|     39|					case 17:  {
  ------------------
  |  Branch (391:6): [True: 39, False: 2.64k]
  ------------------
  392|     39|						{
  393|     39|#line 46 "src/stata/readstat_dta_parse_timestamp.rl"
  394|     39|							timestamp->tm_min = temp_val; }
  395|       |						
  396|     39|#line 397 "src/stata/readstat_dta_parse_timestamp.c"
  397|       |						
  398|     39|						break; 
  399|      0|					}
  400|  2.68k|				}
  401|  2.68k|				_nacts -= 1;
  402|  2.68k|				_acts += 1;
  403|  2.68k|			}
  404|       |			
  405|  2.17k|		}
  406|       |		
  407|  3.41k|		if ( p == eof ) {
  ------------------
  |  Branch (407:8): [True: 66, False: 3.34k]
  ------------------
  408|     66|			if ( cs >= 44 )
  ------------------
  |  Branch (408:9): [True: 39, False: 27]
  ------------------
  409|     39|				goto _out;
  410|     66|		}
  411|  3.34k|		else {
  412|  3.34k|			if ( cs != 0 ) {
  ------------------
  |  Branch (412:9): [True: 2.63k, False: 706]
  ------------------
  413|  2.63k|				p += 1;
  414|  2.63k|				goto _resume;
  415|  2.63k|			}
  416|  3.34k|		}
  417|    772|		_out: {}
  418|    772|	}
  419|       |	
  420|      0|#line 52 "src/stata/readstat_dta_parse_timestamp.rl"
  421|       |	
  422|       |	
  423|    772|	if (cs < 
  ------------------
  |  Branch (423:6): [True: 733, False: 39]
  ------------------
  424|    772|#line 425 "src/stata/readstat_dta_parse_timestamp.c"
  425|    772|	44
  426|     39|#line 54 "src/stata/readstat_dta_parse_timestamp.rl"
  427|    733|	|| p != pe) {
  ------------------
  |  Branch (427:5): [True: 0, False: 39]
  ------------------
  428|    733|		char error_buf[1024];
  429|    733|		if (error_handler) {
  ------------------
  |  Branch (429:7): [True: 0, False: 733]
  ------------------
  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|    733|		retval = READSTAT_ERROR_BAD_TIMESTAMP_STRING;
  434|    733|	}
  435|       |	
  436|    772|	(void)dta_timestamp_parse_en_main;
  437|       |	
  438|    772|	return retval;
  439|  3.41k|}

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

rt_open_handler:
    8|  4.36k|int rt_open_handler(const char *path, void *io_ctx) {
    9|  4.36k|    return 0;
   10|  4.36k|}
rt_close_handler:
   12|  4.36k|int rt_close_handler(void *io_ctx) {
   13|  4.36k|    return 0;
   14|  4.36k|}
rt_seek_handler:
   17|   100k|        readstat_io_flags_t whence, void *io_ctx) {
   18|   100k|    rt_buffer_ctx_t *buffer_ctx = (rt_buffer_ctx_t *)io_ctx;
   19|   100k|    readstat_off_t newpos = -1;
   20|   100k|    if (whence == READSTAT_SEEK_SET) {
  ------------------
  |  Branch (20:9): [True: 7.82k, False: 92.7k]
  ------------------
   21|  7.82k|        newpos = offset;
   22|  92.7k|    } else if (whence == READSTAT_SEEK_CUR) {
  ------------------
  |  Branch (22:16): [True: 88.3k, False: 4.36k]
  ------------------
   23|  88.3k|        newpos = buffer_ctx->pos + offset;
   24|  88.3k|    } else if (whence == READSTAT_SEEK_END) {
  ------------------
  |  Branch (24:16): [True: 4.36k, False: 0]
  ------------------
   25|  4.36k|        newpos = buffer_ctx->buffer->used + offset;
   26|  4.36k|    }
   27|       |
   28|   100k|    if (newpos < 0)
  ------------------
  |  Branch (28:9): [True: 126, False: 100k]
  ------------------
   29|    126|        return -1;
   30|       |
   31|   100k|    if (newpos > buffer_ctx->buffer->used)
  ------------------
  |  Branch (31:9): [True: 148, False: 100k]
  ------------------
   32|    148|        return -1;
   33|       |
   34|   100k|    buffer_ctx->pos = newpos;
   35|   100k|    return newpos;
   36|   100k|}
rt_read_handler:
   38|  48.0G|ssize_t rt_read_handler(void *buf, size_t nbytes, void *io_ctx) {
   39|  48.0G|    rt_buffer_ctx_t *buffer_ctx = (rt_buffer_ctx_t *)io_ctx;
   40|  48.0G|    ssize_t bytes_copied = 0;
   41|  48.0G|    ssize_t bytes_left = buffer_ctx->buffer->used - buffer_ctx->pos;
   42|  48.0G|    if (nbytes <= bytes_left) {
  ------------------
  |  Branch (42:9): [True: 48.0G, False: 1.95k]
  ------------------
   43|  48.0G|        memcpy(buf, buffer_ctx->buffer->bytes + buffer_ctx->pos, nbytes);
   44|  48.0G|        bytes_copied = nbytes;
   45|  48.0G|    } else if (bytes_left > 0) {
  ------------------
  |  Branch (45:16): [True: 679, False: 1.27k]
  ------------------
   46|    679|        memcpy(buf, buffer_ctx->buffer->bytes + buffer_ctx->pos, bytes_left);
   47|    679|        bytes_copied = bytes_left;
   48|    679|    }
   49|  48.0G|    buffer_ctx->pos += bytes_copied;
   50|  48.0G|    return bytes_copied;
   51|  48.0G|}

