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

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

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

readstat_convert:
   39|   379k|readstat_error_t readstat_convert(char *dst, size_t dst_len, const char *src, size_t src_len, iconv_t converter) {
   40|   379k|    return readstat_convert_impl(dst, dst_len, src, src_len, converter, 1);
   41|   379k|}
readstat_convert_notrim:
   43|  5.37k|readstat_error_t readstat_convert_notrim(char *dst, size_t dst_len, const char *src, size_t src_len, iconv_t converter) {
   44|  5.37k|    return readstat_convert_impl(dst, dst_len, src, src_len, converter, 0);
   45|  5.37k|}
readstat_convert.c:readstat_convert_impl:
    8|   385k|        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|   393k|    while (src_len && ((trim_spaces && src[src_len-1] == ' ') || src[src_len-1] == '\0')) {
  ------------------
  |  Branch (11:12): [True: 147k, False: 246k]
  |  Branch (11:25): [True: 142k, False: 4.25k]
  |  Branch (11:40): [True: 3.77k, False: 138k]
  |  Branch (11:66): [True: 4.74k, False: 138k]
  ------------------
   12|  8.51k|        src_len--;
   13|  8.51k|    }
   14|   385k|    if (dst_len == 0) {
  ------------------
  |  Branch (14:9): [True: 0, False: 385k]
  ------------------
   15|      0|        return READSTAT_ERROR_CONVERT_LONG_STRING;
   16|   385k|    } else if (converter) {
  ------------------
  |  Branch (16:16): [True: 382k, False: 2.42k]
  ------------------
   17|   382k|        size_t dst_left = dst_len - 1;
   18|   382k|        char *dst_end = dst;
   19|   382k|        size_t status = iconv(converter, (readstat_iconv_inbuf_t)&src, &src_len, &dst_end, &dst_left);
   20|   382k|        if (status == (size_t)-1) {
  ------------------
  |  Branch (20:13): [True: 1.00k, False: 381k]
  ------------------
   21|  1.00k|            if (errno == E2BIG) {
  ------------------
  |  Branch (21:17): [True: 1, False: 999]
  ------------------
   22|      1|                return READSTAT_ERROR_CONVERT_LONG_STRING;
   23|    999|            } else if (errno == EILSEQ) {
  ------------------
  |  Branch (23:24): [True: 999, False: 0]
  ------------------
   24|    999|                return READSTAT_ERROR_CONVERT_BAD_STRING;
   25|    999|            } else if (errno != EINVAL) { /* EINVAL indicates improper truncation; accept it */
  ------------------
  |  Branch (25:24): [True: 0, False: 0]
  ------------------
   26|      0|                return READSTAT_ERROR_CONVERT;
   27|      0|            }
   28|  1.00k|        }
   29|   381k|        dst[dst_len - dst_left - 1] = '\0';
   30|   381k|    } else if (src_len + 1 > dst_len) {
  ------------------
  |  Branch (30:16): [True: 20, False: 2.40k]
  ------------------
   31|     20|        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|   384k|    return READSTAT_OK;
   37|   385k|}

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

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

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

dta_format_is_supported:
   19|  4.00k|int dta_format_is_supported(int ds_format) {
   20|  4.00k|    switch (ds_format) {
  ------------------
  |  Branch (20:13): [True: 3.99k, False: 10]
  ------------------
   21|  1.18k|        case 104: case 105: case 108: case 110: case 111:
  ------------------
  |  Branch (21:9): [True: 662, False: 3.34k]
  |  Branch (21:19): [True: 310, False: 3.69k]
  |  Branch (21:29): [True: 176, False: 3.82k]
  |  Branch (21:39): [True: 18, False: 3.98k]
  |  Branch (21:49): [True: 14, False: 3.99k]
  ------------------
   22|  3.99k|        case 113: case 114: case 115: case 117: case 118: case 119:
  ------------------
  |  Branch (22:9): [True: 446, False: 3.55k]
  |  Branch (22:19): [True: 88, False: 3.91k]
  |  Branch (22:29): [True: 32, False: 3.97k]
  |  Branch (22:39): [True: 1.77k, False: 2.23k]
  |  Branch (22:49): [True: 336, False: 3.66k]
  |  Branch (22:59): [True: 140, False: 3.86k]
  ------------------
   23|  3.99k|            return 1;
   24|  4.00k|    }
   25|     10|    return 0;
   26|  4.00k|}
dta_ctx_alloc:
   28|  4.47k|dta_ctx_t *dta_ctx_alloc(readstat_io_t *io) {
   29|  4.47k|    dta_ctx_t *ctx = calloc(1, sizeof(dta_ctx_t));
   30|  4.47k|    if (ctx == NULL) {
  ------------------
  |  Branch (30:9): [True: 0, False: 4.47k]
  ------------------
   31|      0|        return NULL;
   32|      0|    }
   33|       |
   34|  4.47k|    ctx->io = io;
   35|  4.47k|    ctx->initialized = 0;
   36|       |
   37|  4.47k|    return ctx;
   38|  4.47k|}
dta_ctx_init:
   42|  4.00k|        const char *input_encoding, const char *output_encoding) {
   43|  4.00k|    readstat_error_t retval = READSTAT_OK;
   44|  4.00k|    int machine_byteorder = DTA_HILO;
  ------------------
  |  |  129|  4.00k|#define DTA_HILO  0x01
  ------------------
   45|  4.00k|    if (!dta_format_is_supported(ds_format))
  ------------------
  |  Branch (45:9): [True: 10, False: 3.99k]
  ------------------
   46|     10|        return READSTAT_ERROR_UNSUPPORTED_FILE_FORMAT_VERSION;
   47|       |
   48|  3.99k|    if (machine_is_little_endian()) {
  ------------------
  |  Branch (48:9): [True: 3.99k, False: 0]
  ------------------
   49|  3.99k|        machine_byteorder = DTA_LOHI;
  ------------------
  |  |  130|  3.99k|#define DTA_LOHI  0x02
  ------------------
   50|  3.99k|    }
   51|       |
   52|  3.99k|    ctx->bswap = (byteorder != machine_byteorder);
   53|  3.99k|    ctx->ds_format = ds_format;
   54|  3.99k|    ctx->endianness = byteorder == DTA_LOHI ? READSTAT_ENDIAN_LITTLE : READSTAT_ENDIAN_BIG;
  ------------------
  |  |  130|  3.99k|#define DTA_LOHI  0x02
  ------------------
  |  Branch (54:23): [True: 1.67k, False: 2.31k]
  ------------------
   55|       |
   56|  3.99k|    ctx->nvar = nvar;
   57|  3.99k|    ctx->nobs = nobs;
   58|       |
   59|  3.99k|    if (ctx->nvar) {
  ------------------
  |  Branch (59:9): [True: 2.63k, False: 1.35k]
  ------------------
   60|  2.63k|        if ((ctx->variables = calloc(ctx->nvar, sizeof(readstat_variable_t *))) == NULL) {
  ------------------
  |  Branch (60:13): [True: 26, False: 2.61k]
  ------------------
   61|     26|            retval = READSTAT_ERROR_MALLOC;
   62|     26|            goto cleanup;
   63|     26|        }
   64|  2.63k|    }
   65|       |
   66|  3.96k|    ctx->machine_is_twos_complement = READSTAT_MACHINE_IS_TWOS_COMPLEMENT;
  ------------------
  |  |    8|  3.96k|#define READSTAT_MACHINE_IS_TWOS_COMPLEMENT 0
  ------------------
   67|       |
   68|  3.96k|    if (ds_format < 105) {
  ------------------
  |  Branch (68:9): [True: 662, False: 3.30k]
  ------------------
   69|    662|        ctx->fmtlist_entry_len = 7;
   70|  3.30k|    } else if (ds_format < 114) {
  ------------------
  |  Branch (70:16): [True: 964, False: 2.34k]
  ------------------
   71|    964|        ctx->fmtlist_entry_len = 12;
   72|  2.34k|    } else if (ds_format < 118) {
  ------------------
  |  Branch (72:16): [True: 1.89k, False: 450]
  ------------------
   73|  1.89k|        ctx->fmtlist_entry_len = 49;
   74|  1.89k|    } else {
   75|    450|        ctx->fmtlist_entry_len = 57;
   76|    450|    }
   77|       |    
   78|  3.96k|    if (ds_format >= 117) {
  ------------------
  |  Branch (78:9): [True: 2.22k, False: 1.74k]
  ------------------
   79|  2.22k|        ctx->typlist_version = 117;
   80|  2.22k|    } else if (ds_format >= 111) {
  ------------------
  |  Branch (80:16): [True: 580, False: 1.16k]
  ------------------
   81|    580|        ctx->typlist_version = 111;
   82|  1.16k|    } else {
   83|  1.16k|        ctx->typlist_version = 0;
   84|  1.16k|    }
   85|       |
   86|  3.96k|    if (ds_format >= 119) {
  ------------------
  |  Branch (86:9): [True: 114, False: 3.85k]
  ------------------
   87|       |        /* The 8-byte (v,o) field in the data is a 3-byte v and a 5-byte o */
   88|    114|        ctx->data_label_len_len = 2;
   89|    114|        ctx->strl_v_len = 3;
   90|    114|        ctx->strl_o_len = 5;
   91|  3.85k|    } else if (ds_format >= 118) {
  ------------------
  |  Branch (91:16): [True: 336, False: 3.51k]
  ------------------
   92|    336|        ctx->data_label_len_len = 2;
   93|    336|        ctx->strl_v_len = 2;
   94|    336|        ctx->strl_o_len = 6;
   95|  3.51k|    } else if (ds_format >= 117) {
  ------------------
  |  Branch (95:16): [True: 1.77k, False: 1.74k]
  ------------------
   96|  1.77k|        ctx->data_label_len_len = 1;
   97|  1.77k|        ctx->strl_v_len = 4;
   98|  1.77k|        ctx->strl_o_len = 4;
   99|  1.77k|    }
  100|       |
  101|  3.96k|    if (ds_format < 105) {
  ------------------
  |  Branch (101:9): [True: 662, False: 3.30k]
  ------------------
  102|    662|        ctx->expansion_len_len = 0;
  103|  3.30k|    } else if (ds_format < 110) {
  ------------------
  |  Branch (103:16): [True: 486, False: 2.82k]
  ------------------
  104|    486|        ctx->expansion_len_len = 2;
  105|  2.82k|    } else {
  106|  2.82k|        ctx->expansion_len_len = 4;
  107|  2.82k|    }
  108|       |    
  109|  3.96k|    if (ds_format < 110) {
  ------------------
  |  Branch (109:9): [True: 1.14k, False: 2.82k]
  ------------------
  110|  1.14k|        ctx->lbllist_entry_len = 9;
  111|  1.14k|        ctx->variable_name_len = 9;
  112|  1.14k|        ctx->ch_metadata_len = 9;
  113|  2.82k|    } else if (ds_format < 118) {
  ------------------
  |  Branch (113:16): [True: 2.37k, False: 450]
  ------------------
  114|  2.37k|        ctx->lbllist_entry_len = 33;
  115|  2.37k|        ctx->variable_name_len = 33;
  116|  2.37k|        ctx->ch_metadata_len = 33;
  117|  2.37k|    } else {
  118|    450|        ctx->lbllist_entry_len = 129;
  119|    450|        ctx->variable_name_len = 129;
  120|    450|        ctx->ch_metadata_len = 129;
  121|    450|    }
  122|       |
  123|  3.96k|    if (ds_format < 108) {
  ------------------
  |  Branch (123:9): [True: 972, False: 2.99k]
  ------------------
  124|    972|        ctx->variable_labels_entry_len = 32;
  125|    972|        ctx->data_label_len = 32;
  126|  2.99k|    } else if (ds_format < 118) {
  ------------------
  |  Branch (126:16): [True: 2.54k, False: 450]
  ------------------
  127|  2.54k|        ctx->variable_labels_entry_len = 81;
  128|  2.54k|        ctx->data_label_len = 81;
  129|  2.54k|    } else {
  130|    450|        ctx->variable_labels_entry_len = 321;
  131|    450|        ctx->data_label_len = 321;
  132|    450|    }
  133|       |
  134|  3.96k|    if (ds_format < 105) {
  ------------------
  |  Branch (134:9): [True: 662, False: 3.30k]
  ------------------
  135|    662|        ctx->timestamp_len = 0;
  136|  3.30k|    } else {
  137|  3.30k|        ctx->timestamp_len = 18;
  138|  3.30k|    }
  139|       |
  140|       |    /* Value label tables. Formats 105 and earlier use the "old" layout:
  141|       |     * n (int16), labname (9 bytes), 1 byte of padding, n int16 codes, then n
  142|       |     * 8-byte labels. Format 108 uses the modern layout but with a 9-byte
  143|       |     * label name; later formats widen the name with the variable name. */
  144|  3.96k|    if (ds_format < 108) {
  ------------------
  |  Branch (144:9): [True: 972, False: 2.99k]
  ------------------
  145|    972|        ctx->value_label_table_len_len = 2;
  146|    972|        ctx->value_label_table_labname_len = 9;
  147|    972|        ctx->value_label_table_padding_len = 1;
  148|  2.99k|    } else {
  149|  2.99k|        ctx->value_label_table_len_len = 4;
  150|  2.99k|        if (ds_format < 110) {
  ------------------
  |  Branch (150:13): [True: 176, False: 2.82k]
  ------------------
  151|    176|            ctx->value_label_table_labname_len = 9;
  152|  2.82k|        } else if (ds_format < 118) {
  ------------------
  |  Branch (152:20): [True: 2.37k, False: 450]
  ------------------
  153|  2.37k|            ctx->value_label_table_labname_len = 33;
  154|  2.37k|        } else {
  155|    450|            ctx->value_label_table_labname_len = 129;
  156|    450|        }
  157|  2.99k|        ctx->value_label_table_padding_len = 3;
  158|  2.99k|    }
  159|       |
  160|  3.96k|    if (ds_format < 117) {
  ------------------
  |  Branch (160:9): [True: 1.74k, False: 2.22k]
  ------------------
  161|  1.74k|        ctx->typlist_entry_len = 1;
  162|  1.74k|        ctx->file_is_xmlish = 0;
  163|  2.22k|    } else {
  164|  2.22k|        ctx->typlist_entry_len = 2;
  165|  2.22k|        ctx->file_is_xmlish = 1;
  166|  2.22k|    }
  167|       |
  168|  3.96k|    if (ds_format < 113) {
  ------------------
  |  Branch (168:9): [True: 1.18k, False: 2.78k]
  ------------------
  169|  1.18k|        ctx->max_int8 = DTA_OLD_MAX_INT8;
  ------------------
  |  |  132|  1.18k|#define DTA_OLD_MAX_INT8                     0x7e
  ------------------
  170|  1.18k|        ctx->max_int16 = DTA_OLD_MAX_INT16;
  ------------------
  |  |  133|  1.18k|#define DTA_OLD_MAX_INT16                  0x7ffe
  ------------------
  171|  1.18k|        ctx->max_int32 = DTA_OLD_MAX_INT32;
  ------------------
  |  |  134|  1.18k|#define DTA_OLD_MAX_INT32              0x7ffffffe
  ------------------
  172|  1.18k|        ctx->max_float = DTA_OLD_MAX_FLOAT;
  ------------------
  |  |  135|  1.18k|#define DTA_OLD_MAX_FLOAT              0x7effffff // +1.7e38f
  ------------------
  173|  1.18k|        ctx->max_double = DTA_OLD_MAX_DOUBLE;
  ------------------
  |  |  136|  1.18k|#define DTA_OLD_MAX_DOUBLE     0x7fdfffffffffffffL // +8.9e307
  ------------------
  174|  2.78k|    } else {
  175|  2.78k|        ctx->max_int8 = DTA_113_MAX_INT8;
  ------------------
  |  |  144|  2.78k|#define DTA_113_MAX_INT8                    0x64
  ------------------
  176|  2.78k|        ctx->max_int16 = DTA_113_MAX_INT16;
  ------------------
  |  |  145|  2.78k|#define DTA_113_MAX_INT16                 0x7fe4
  ------------------
  177|  2.78k|        ctx->max_int32 = DTA_113_MAX_INT32;
  ------------------
  |  |  146|  2.78k|#define DTA_113_MAX_INT32             0x7fffffe4
  ------------------
  178|  2.78k|        ctx->max_float = DTA_113_MAX_FLOAT;
  ------------------
  |  |  147|  2.78k|#define DTA_113_MAX_FLOAT             0x7effffff // +1.7e38f
  ------------------
  179|  2.78k|        ctx->max_double = DTA_113_MAX_DOUBLE;
  ------------------
  |  |  148|  2.78k|#define DTA_113_MAX_DOUBLE    0x7fdfffffffffffffL // +8.9e307
  ------------------
  180|       |
  181|  2.78k|        ctx->supports_tagged_missing = 1;
  182|  2.78k|    }
  183|       |
  184|  3.96k|    if (output_encoding) {
  ------------------
  |  Branch (184:9): [True: 3.96k, False: 0]
  ------------------
  185|  3.96k|        if (input_encoding) {
  ------------------
  |  Branch (185:13): [True: 0, False: 3.96k]
  ------------------
  186|      0|            ctx->converter = iconv_open(output_encoding, input_encoding);
  187|  3.96k|        } else if (ds_format < 118) {
  ------------------
  |  Branch (187:20): [True: 3.51k, False: 450]
  ------------------
  188|  3.51k|            ctx->converter = iconv_open(output_encoding, "WINDOWS-1252");
  189|  3.51k|        } else if (strcmp(output_encoding, "UTF-8") != 0) {
  ------------------
  |  Branch (189:20): [True: 0, False: 450]
  ------------------
  190|      0|            ctx->converter = iconv_open(output_encoding, "UTF-8");
  191|      0|        }
  192|  3.96k|        if (ctx->converter == (iconv_t)-1) {
  ------------------
  |  Branch (192:13): [True: 0, False: 3.96k]
  ------------------
  193|      0|            ctx->converter = NULL;
  194|      0|            retval = READSTAT_ERROR_UNSUPPORTED_CHARSET;
  195|      0|            goto cleanup;
  196|      0|        }
  197|  3.96k|    }
  198|       |
  199|  3.96k|    if (ds_format < 119) {
  ------------------
  |  Branch (199:9): [True: 3.85k, False: 114]
  ------------------
  200|  3.85k|        ctx->srtlist_len = (ctx->nvar + 1) * sizeof(int16_t);
  201|  3.85k|    } else {
  202|    114|        ctx->srtlist_len = (ctx->nvar + 1) * sizeof(int32_t);
  203|    114|    }
  204|       |
  205|  3.96k|    if ((ctx->srtlist = malloc(ctx->srtlist_len)) == NULL) {
  ------------------
  |  Branch (205:9): [True: 0, False: 3.96k]
  ------------------
  206|      0|        retval = READSTAT_ERROR_MALLOC;
  207|      0|        goto cleanup;
  208|      0|    }
  209|       |
  210|  3.96k|    if (ctx->nvar > 0) {
  ------------------
  |  Branch (210:9): [True: 2.61k, False: 1.35k]
  ------------------
  211|  2.61k|        if (ctx->file_size > 0) {
  ------------------
  |  Branch (211:13): [True: 2.61k, 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.61k|            size_t bytes_per_var = ctx->typlist_entry_len + ctx->variable_name_len
  216|  2.61k|                + ctx->fmtlist_entry_len + ctx->lbllist_entry_len + ctx->variable_labels_entry_len
  217|  2.61k|                + (ds_format < 119 ? sizeof(int16_t) : sizeof(int32_t));
  ------------------
  |  Branch (217:20): [True: 2.54k, False: 70]
  ------------------
  218|  2.61k|            if ((uint64_t)ctx->nvar * bytes_per_var > ctx->file_size) {
  ------------------
  |  Branch (218:17): [True: 74, False: 2.53k]
  ------------------
  219|     74|                retval = READSTAT_ERROR_PARSE;
  220|     74|                goto cleanup;
  221|     74|            }
  222|  2.61k|        }
  223|  2.53k|        ctx->typlist_len = ctx->nvar * sizeof(uint16_t);
  224|  2.53k|        ctx->varlist_len = ctx->variable_name_len * ctx->nvar * sizeof(char);
  225|  2.53k|        ctx->fmtlist_len = ctx->fmtlist_entry_len * ctx->nvar * sizeof(char);
  226|  2.53k|        ctx->lbllist_len = ctx->lbllist_entry_len * ctx->nvar * sizeof(char);
  227|  2.53k|        ctx->variable_labels_len = ctx->variable_labels_entry_len * ctx->nvar * sizeof(char);
  228|       |
  229|  2.53k|        if ((ctx->typlist = malloc(ctx->typlist_len)) == NULL) {
  ------------------
  |  Branch (229:13): [True: 0, False: 2.53k]
  ------------------
  230|      0|            retval = READSTAT_ERROR_MALLOC;
  231|      0|            goto cleanup;
  232|      0|        }
  233|  2.53k|        if ((ctx->varlist = malloc(ctx->varlist_len)) == NULL) {
  ------------------
  |  Branch (233:13): [True: 0, False: 2.53k]
  ------------------
  234|      0|            retval = READSTAT_ERROR_MALLOC;
  235|      0|            goto cleanup;
  236|      0|        }
  237|  2.53k|        if ((ctx->fmtlist = malloc(ctx->fmtlist_len)) == NULL) {
  ------------------
  |  Branch (237:13): [True: 0, False: 2.53k]
  ------------------
  238|      0|            retval = READSTAT_ERROR_MALLOC;
  239|      0|            goto cleanup;
  240|      0|        }
  241|  2.53k|        if ((ctx->lbllist = malloc(ctx->lbllist_len)) == NULL) {
  ------------------
  |  Branch (241:13): [True: 0, False: 2.53k]
  ------------------
  242|      0|            retval = READSTAT_ERROR_MALLOC;
  243|      0|            goto cleanup;
  244|      0|        }
  245|  2.53k|        if ((ctx->variable_labels = malloc(ctx->variable_labels_len)) == NULL) {
  ------------------
  |  Branch (245:13): [True: 0, False: 2.53k]
  ------------------
  246|      0|            retval = READSTAT_ERROR_MALLOC;
  247|      0|            goto cleanup;
  248|      0|        }
  249|  2.53k|    }
  250|       |
  251|  3.89k|    ctx->initialized = 1;
  252|       |
  253|  3.99k|cleanup:
  254|  3.99k|    return retval;
  255|  3.89k|}
dta_ctx_free:
  257|  4.47k|void dta_ctx_free(dta_ctx_t *ctx) {
  258|  4.47k|    if (ctx->typlist)
  ------------------
  |  Branch (258:9): [True: 2.53k, False: 1.93k]
  ------------------
  259|  2.53k|        free(ctx->typlist);
  260|  4.47k|    if (ctx->varlist)
  ------------------
  |  Branch (260:9): [True: 2.53k, False: 1.93k]
  ------------------
  261|  2.53k|        free(ctx->varlist);
  262|  4.47k|    if (ctx->srtlist)
  ------------------
  |  Branch (262:9): [True: 3.96k, False: 509]
  ------------------
  263|  3.96k|        free(ctx->srtlist);
  264|  4.47k|    if (ctx->fmtlist)
  ------------------
  |  Branch (264:9): [True: 2.53k, False: 1.93k]
  ------------------
  265|  2.53k|        free(ctx->fmtlist);
  266|  4.47k|    if (ctx->lbllist)
  ------------------
  |  Branch (266:9): [True: 2.53k, False: 1.93k]
  ------------------
  267|  2.53k|        free(ctx->lbllist);
  268|  4.47k|    if (ctx->variable_labels)
  ------------------
  |  Branch (268:9): [True: 2.53k, False: 1.93k]
  ------------------
  269|  2.53k|        free(ctx->variable_labels);
  270|  4.47k|    if (ctx->converter)
  ------------------
  |  Branch (270:9): [True: 3.51k, False: 959]
  ------------------
  271|  3.51k|        iconv_close(ctx->converter);
  272|  4.47k|    if (ctx->data_label)
  ------------------
  |  Branch (272:9): [True: 3.71k, False: 767]
  ------------------
  273|  3.71k|        free(ctx->data_label);
  274|  4.47k|    if (ctx->variables) {
  ------------------
  |  Branch (274:9): [True: 2.61k, False: 1.86k]
  ------------------
  275|  2.61k|        int i;
  276|  2.55G|        for (i=0; i<ctx->nvar; i++) {
  ------------------
  |  Branch (276:19): [True: 2.55G, False: 2.61k]
  ------------------
  277|  2.55G|            if (ctx->variables[i])
  ------------------
  |  Branch (277:17): [True: 32.3k, False: 2.55G]
  ------------------
  278|  32.3k|                free(ctx->variables[i]);
  279|  2.55G|        }
  280|  2.61k|        free(ctx->variables);
  281|  2.61k|    }
  282|  4.47k|    if (ctx->strls) {
  ------------------
  |  Branch (282:9): [True: 981, False: 3.49k]
  ------------------
  283|    981|        int i;
  284|   117k|        for (i=0; i<ctx->strls_count; i++) {
  ------------------
  |  Branch (284:19): [True: 116k, False: 981]
  ------------------
  285|   116k|            free(ctx->strls[i]);
  286|   116k|        }
  287|    981|        free(ctx->strls);
  288|    981|    }
  289|  4.47k|    free(ctx);
  290|  4.47k|}
dta_type_info:
  293|   195k|        size_t *max_len, readstat_type_t *out_type) {
  294|   195k|    readstat_error_t retval = READSTAT_OK;
  295|   195k|    size_t len = 0;
  296|   195k|    readstat_type_t type = READSTAT_TYPE_STRING;
  297|   195k|    if (ctx->typlist_version == 111) {
  ------------------
  |  Branch (297:9): [True: 111k, False: 84.5k]
  ------------------
  298|   111k|        switch (typecode) {
  299|    639|            case DTA_111_TYPE_CODE_INT8:
  ------------------
  |  |  172|    639|#define DTA_111_TYPE_CODE_INT8     0xFB
  ------------------
  |  Branch (299:13): [True: 639, False: 110k]
  ------------------
  300|    639|                len = 1; type = READSTAT_TYPE_INT8; break;
  301|    428|            case DTA_111_TYPE_CODE_INT16:
  ------------------
  |  |  173|    428|#define DTA_111_TYPE_CODE_INT16    0xFC
  ------------------
  |  Branch (301:13): [True: 428, False: 110k]
  ------------------
  302|    428|                len = 2; type = READSTAT_TYPE_INT16; break;
  303|  35.0k|            case DTA_111_TYPE_CODE_INT32:
  ------------------
  |  |  174|  35.0k|#define DTA_111_TYPE_CODE_INT32    0xFD
  ------------------
  |  Branch (303:13): [True: 35.0k, False: 76.1k]
  ------------------
  304|  35.0k|                len = 4; type = READSTAT_TYPE_INT32; break;
  305|  15.7k|            case DTA_111_TYPE_CODE_FLOAT:
  ------------------
  |  |  175|  15.7k|#define DTA_111_TYPE_CODE_FLOAT    0xFE
  ------------------
  |  Branch (305:13): [True: 15.7k, False: 95.5k]
  ------------------
  306|  15.7k|                len = 4; type = READSTAT_TYPE_FLOAT; break;
  307|  14.6k|            case DTA_111_TYPE_CODE_DOUBLE:
  ------------------
  |  |  176|  14.6k|#define DTA_111_TYPE_CODE_DOUBLE   0xFF
  ------------------
  |  Branch (307:13): [True: 14.6k, False: 96.6k]
  ------------------
  308|  14.6k|                len = 8; type = READSTAT_TYPE_DOUBLE; break;
  309|  44.7k|            default:
  ------------------
  |  Branch (309:13): [True: 44.7k, False: 66.5k]
  ------------------
  310|  44.7k|                len = typecode; type = READSTAT_TYPE_STRING; break;
  311|   111k|        }
  312|   111k|    } else if (ctx->typlist_version == 117) {
  ------------------
  |  Branch (312:16): [True: 36.7k, False: 47.8k]
  ------------------
  313|  36.7k|        switch (typecode) {
  314|  1.13k|            case DTA_117_TYPE_CODE_INT8:
  ------------------
  |  |  165|  1.13k|#define DTA_117_TYPE_CODE_INT8     0xFFFA
  ------------------
  |  Branch (314:13): [True: 1.13k, False: 35.5k]
  ------------------
  315|  1.13k|                len = 1; type = READSTAT_TYPE_INT8; break;
  316|  1.72k|            case DTA_117_TYPE_CODE_INT16:
  ------------------
  |  |  166|  1.72k|#define DTA_117_TYPE_CODE_INT16    0xFFF9
  ------------------
  |  Branch (316:13): [True: 1.72k, False: 35.0k]
  ------------------
  317|  1.72k|                len = 2; type = READSTAT_TYPE_INT16; break;
  318|  1.51k|            case DTA_117_TYPE_CODE_INT32:
  ------------------
  |  |  167|  1.51k|#define DTA_117_TYPE_CODE_INT32    0xFFF8
  ------------------
  |  Branch (318:13): [True: 1.51k, False: 35.2k]
  ------------------
  319|  1.51k|                len = 4; type = READSTAT_TYPE_INT32; break;
  320|    792|            case DTA_117_TYPE_CODE_FLOAT:
  ------------------
  |  |  168|    792|#define DTA_117_TYPE_CODE_FLOAT    0xFFF7
  ------------------
  |  Branch (320:13): [True: 792, False: 35.9k]
  ------------------
  321|    792|                len = 4; type = READSTAT_TYPE_FLOAT; break;
  322|    927|            case DTA_117_TYPE_CODE_DOUBLE:
  ------------------
  |  |  169|    927|#define DTA_117_TYPE_CODE_DOUBLE   0xFFF6
  ------------------
  |  Branch (322:13): [True: 927, False: 35.7k]
  ------------------
  323|    927|                len = 8; type = READSTAT_TYPE_DOUBLE; break;
  324|  27.7k|            case DTA_117_TYPE_CODE_STRL:
  ------------------
  |  |  170|  27.7k|#define DTA_117_TYPE_CODE_STRL     0x8000
  ------------------
  |  Branch (324:13): [True: 27.7k, False: 9.02k]
  ------------------
  325|  27.7k|                len = 8; type = READSTAT_TYPE_STRING_REF; break;
  326|  2.93k|            default:
  ------------------
  |  Branch (326:13): [True: 2.93k, False: 33.7k]
  ------------------
  327|  2.93k|                len = typecode; type = READSTAT_TYPE_STRING; break;
  328|  36.7k|        }
  329|  47.8k|    } else if (typecode < 0x7F) {
  ------------------
  |  Branch (329:16): [True: 32.5k, False: 15.2k]
  ------------------
  330|  32.5k|        switch (typecode) {
  331|  29.0k|            case DTA_OLD_TYPE_CODE_INT8:
  ------------------
  |  |  178|  29.0k|#define DTA_OLD_TYPE_CODE_INT8     'b'
  ------------------
  |  Branch (331:13): [True: 29.0k, False: 3.49k]
  ------------------
  332|  29.0k|                len = 1; type = READSTAT_TYPE_INT8; break;
  333|  1.10k|            case DTA_OLD_TYPE_CODE_INT16:
  ------------------
  |  |  179|  1.10k|#define DTA_OLD_TYPE_CODE_INT16    'i'
  ------------------
  |  Branch (333:13): [True: 1.10k, False: 31.4k]
  ------------------
  334|  1.10k|                len = 2; type = READSTAT_TYPE_INT16; break;
  335|    720|            case DTA_OLD_TYPE_CODE_INT32:
  ------------------
  |  |  180|    720|#define DTA_OLD_TYPE_CODE_INT32    'l'
  ------------------
  |  Branch (335:13): [True: 720, False: 31.8k]
  ------------------
  336|    720|                len = 4; type = READSTAT_TYPE_INT32; break;
  337|    508|            case DTA_OLD_TYPE_CODE_FLOAT:
  ------------------
  |  |  181|    508|#define DTA_OLD_TYPE_CODE_FLOAT    'f'
  ------------------
  |  Branch (337:13): [True: 508, False: 32.0k]
  ------------------
  338|    508|                len = 4; type = READSTAT_TYPE_FLOAT; break;
  339|  1.14k|            case DTA_OLD_TYPE_CODE_DOUBLE:
  ------------------
  |  |  182|  1.14k|#define DTA_OLD_TYPE_CODE_DOUBLE   'd'
  ------------------
  |  Branch (339:13): [True: 1.14k, False: 31.4k]
  ------------------
  340|  1.14k|                len = 8; type = READSTAT_TYPE_DOUBLE; break;
  341|     13|            default:
  ------------------
  |  Branch (341:13): [True: 13, False: 32.5k]
  ------------------
  342|     13|                retval = READSTAT_ERROR_PARSE; break;
  343|  32.5k|        }
  344|  32.5k|    } else {
  345|  15.2k|        len = typecode - 0x7F;
  346|  15.2k|        type = READSTAT_TYPE_STRING;
  347|  15.2k|    }
  348|       |    
  349|   195k|    if (max_len)
  ------------------
  |  Branch (349:9): [True: 195k, False: 0]
  ------------------
  350|   195k|        *max_len = len;
  351|   195k|    if (out_type)
  ------------------
  |  Branch (351:9): [True: 144k, False: 51.3k]
  ------------------
  352|   144k|        *out_type = type;
  353|       |
  354|   195k|    return retval;
  355|   195k|}

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

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

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

