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

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

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

readstat_convert:
    7|   461k|readstat_error_t readstat_convert(char *dst, size_t dst_len, const char *src, size_t src_len, iconv_t converter) {
    8|       |    /* strip off spaces from the input because the programs use ASCII space
    9|       |     * padding even with non-ASCII encoding. */
   10|   462k|    while (src_len && (src[src_len-1] == ' ' || src[src_len-1] == '\0')) {
  ------------------
  |  Branch (10:12): [True: 428k, False: 34.4k]
  |  Branch (10:24): [True: 1.31k, False: 426k]
  |  Branch (10:49): [True: 258, False: 426k]
  ------------------
   11|  1.57k|        src_len--;
   12|  1.57k|    }
   13|   461k|    if (dst_len == 0) {
  ------------------
  |  Branch (13:9): [True: 0, False: 461k]
  ------------------
   14|      0|        return READSTAT_ERROR_CONVERT_LONG_STRING;
   15|   461k|    } else if (converter) {
  ------------------
  |  Branch (15:16): [True: 458k, False: 2.94k]
  ------------------
   16|   458k|        size_t dst_left = dst_len - 1;
   17|   458k|        char *dst_end = dst;
   18|   458k|        size_t status = iconv(converter, (readstat_iconv_inbuf_t)&src, &src_len, &dst_end, &dst_left);
   19|   458k|        if (status == (size_t)-1) {
  ------------------
  |  Branch (19:13): [True: 1.70k, False: 456k]
  ------------------
   20|  1.70k|            if (errno == E2BIG) {
  ------------------
  |  Branch (20:17): [True: 1, False: 1.69k]
  ------------------
   21|      1|                return READSTAT_ERROR_CONVERT_LONG_STRING;
   22|  1.69k|            } else if (errno == EILSEQ) {
  ------------------
  |  Branch (22:24): [True: 1.69k, False: 0]
  ------------------
   23|  1.69k|                return READSTAT_ERROR_CONVERT_BAD_STRING;
   24|  1.69k|            } else if (errno != EINVAL) { /* EINVAL indicates improper truncation; accept it */
  ------------------
  |  Branch (24:24): [True: 0, False: 0]
  ------------------
   25|      0|                return READSTAT_ERROR_CONVERT;
   26|      0|            }
   27|  1.70k|        }
   28|   456k|        dst[dst_len - dst_left - 1] = '\0';
   29|   456k|    } else if (src_len + 1 > dst_len) {
  ------------------
  |  Branch (29:16): [True: 3, False: 2.93k]
  ------------------
   30|      3|        return READSTAT_ERROR_CONVERT_LONG_STRING;
   31|  2.93k|    } else {
   32|  2.93k|        memcpy(dst, src, src_len);
   33|  2.93k|        dst[src_len] = '\0';
   34|  2.93k|    }
   35|   459k|    return READSTAT_OK;
   36|   461k|}

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

readstat_malloc:
   10|   237k|void *readstat_malloc(size_t len) {
   11|   237k|    if (len > MAX_MALLOC_SIZE || len == 0) {
  ------------------
  |  |    3|   474k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
  |  Branch (11:9): [True: 39, False: 237k]
  |  Branch (11:34): [True: 0, False: 237k]
  ------------------
   12|     39|        return NULL;
   13|     39|    }
   14|   237k|    return malloc(len);
   15|   237k|}
readstat_calloc:
   17|  2.99k|void *readstat_calloc(size_t count, size_t size) {
   18|  2.99k|    if (count > MAX_MALLOC_SIZE || size > MAX_MALLOC_SIZE || count * size > MAX_MALLOC_SIZE) {
  ------------------
  |  |    3|  5.99k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
                  if (count > MAX_MALLOC_SIZE || size > MAX_MALLOC_SIZE || count * size > MAX_MALLOC_SIZE) {
  ------------------
  |  |    3|  5.93k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
                  if (count > MAX_MALLOC_SIZE || size > MAX_MALLOC_SIZE || count * size > MAX_MALLOC_SIZE) {
  ------------------
  |  |    3|  2.93k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
  |  Branch (18:9): [True: 59, False: 2.93k]
  |  Branch (18:36): [True: 0, False: 2.93k]
  |  Branch (18:62): [True: 25, False: 2.91k]
  ------------------
   19|     84|        return NULL;
   20|     84|    }
   21|  2.91k|    if (count == 0 || size == 0) {
  ------------------
  |  Branch (21:9): [True: 0, False: 2.91k]
  |  Branch (21:23): [True: 0, False: 2.91k]
  ------------------
   22|      0|        return NULL;
   23|      0|    }
   24|  2.91k|    return calloc(count, size);
   25|  2.91k|}
readstat_realloc:
   27|  7.65k|void *readstat_realloc(void *ptr, size_t len) {
   28|  7.65k|    if (len > MAX_MALLOC_SIZE || len == 0) {
  ------------------
  |  |    3|  15.3k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
  |  Branch (28:9): [True: 44, False: 7.61k]
  |  Branch (28:34): [True: 4, False: 7.61k]
  ------------------
   29|     48|        if (ptr)
  ------------------
  |  Branch (29:13): [True: 6, False: 42]
  ------------------
   30|      6|            free(ptr);
   31|     48|        return NULL;
   32|     48|    }
   33|  7.61k|    return realloc(ptr, len);
   34|  7.65k|}

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

dta_ctx_alloc:
   17|  4.39k|dta_ctx_t *dta_ctx_alloc(readstat_io_t *io) {
   18|  4.39k|    dta_ctx_t *ctx = calloc(1, sizeof(dta_ctx_t));
   19|  4.39k|    if (ctx == NULL) {
  ------------------
  |  Branch (19:9): [True: 0, False: 4.39k]
  ------------------
   20|      0|        return NULL;
   21|      0|    }
   22|       |
   23|  4.39k|    ctx->io = io;
   24|  4.39k|    ctx->initialized = 0;
   25|       |
   26|  4.39k|    return ctx;
   27|  4.39k|}
dta_ctx_init:
   31|  3.92k|        const char *input_encoding, const char *output_encoding) {
   32|  3.92k|    readstat_error_t retval = READSTAT_OK;
   33|  3.92k|    int machine_byteorder = DTA_HILO;
  ------------------
  |  |  129|  3.92k|#define DTA_HILO  0x01
  ------------------
   34|  3.92k|    if (ds_format < DTA_MIN_VERSION || ds_format > DTA_MAX_VERSION)
  ------------------
  |  |   14|  7.85k|#define DTA_MIN_VERSION 104
  ------------------
                  if (ds_format < DTA_MIN_VERSION || ds_format > DTA_MAX_VERSION)
  ------------------
  |  |   15|  3.91k|#define DTA_MAX_VERSION 119
  ------------------
  |  Branch (34:9): [True: 15, False: 3.91k]
  |  Branch (34:40): [True: 3, False: 3.90k]
  ------------------
   35|     18|        return READSTAT_ERROR_UNSUPPORTED_FILE_FORMAT_VERSION;
   36|       |
   37|  3.90k|    if (machine_is_little_endian()) {
  ------------------
  |  Branch (37:9): [True: 3.90k, False: 0]
  ------------------
   38|  3.90k|        machine_byteorder = DTA_LOHI;
  ------------------
  |  |  130|  3.90k|#define DTA_LOHI  0x02
  ------------------
   39|  3.90k|    }
   40|       |
   41|  3.90k|    ctx->bswap = (byteorder != machine_byteorder);
   42|  3.90k|    ctx->ds_format = ds_format;
   43|  3.90k|    ctx->endianness = byteorder == DTA_LOHI ? READSTAT_ENDIAN_LITTLE : READSTAT_ENDIAN_BIG;
  ------------------
  |  |  130|  3.90k|#define DTA_LOHI  0x02
  ------------------
  |  Branch (43:23): [True: 1.28k, False: 2.62k]
  ------------------
   44|       |
   45|  3.90k|    ctx->nvar = nvar;
   46|  3.90k|    ctx->nobs = nobs;
   47|       |
   48|  3.90k|    if (ctx->nvar) {
  ------------------
  |  Branch (48:9): [True: 2.99k, False: 910]
  ------------------
   49|  2.99k|        if ((ctx->variables = readstat_calloc(ctx->nvar, sizeof(readstat_variable_t *))) == NULL) {
  ------------------
  |  Branch (49:13): [True: 84, False: 2.91k]
  ------------------
   50|     84|            retval = READSTAT_ERROR_MALLOC;
   51|     84|            goto cleanup;
   52|     84|        }
   53|  2.99k|    }
   54|       |
   55|  3.82k|    ctx->machine_is_twos_complement = READSTAT_MACHINE_IS_TWOS_COMPLEMENT;
  ------------------
  |  |    8|  3.82k|#define READSTAT_MACHINE_IS_TWOS_COMPLEMENT 0
  ------------------
   56|       |
   57|  3.82k|    if (ds_format < 105) {
  ------------------
  |  Branch (57:9): [True: 759, False: 3.06k]
  ------------------
   58|    759|        ctx->fmtlist_entry_len = 7;
   59|  3.06k|    } else if (ds_format < 114) {
  ------------------
  |  Branch (59:16): [True: 861, False: 2.20k]
  ------------------
   60|    861|        ctx->fmtlist_entry_len = 12;
   61|  2.20k|    } else if (ds_format < 118) {
  ------------------
  |  Branch (61:16): [True: 1.82k, False: 380]
  ------------------
   62|  1.82k|        ctx->fmtlist_entry_len = 49;
   63|  1.82k|    } else {
   64|    380|        ctx->fmtlist_entry_len = 57;
   65|    380|    }
   66|       |    
   67|  3.82k|    if (ds_format >= 117) {
  ------------------
  |  Branch (67:9): [True: 2.15k, False: 1.66k]
  ------------------
   68|  2.15k|        ctx->typlist_version = 117;
   69|  2.15k|    } else if (ds_format >= 111) {
  ------------------
  |  Branch (69:16): [True: 327, False: 1.34k]
  ------------------
   70|    327|        ctx->typlist_version = 111;
   71|  1.34k|    } else {
   72|  1.34k|        ctx->typlist_version = 0;
   73|  1.34k|    }
   74|       |
   75|  3.82k|    if (ds_format >= 118) {
  ------------------
  |  Branch (75:9): [True: 380, False: 3.44k]
  ------------------
   76|    380|        ctx->data_label_len_len = 2;
   77|    380|        ctx->strl_v_len = 2;
   78|    380|        ctx->strl_o_len = 6;
   79|  3.44k|    } else if (ds_format >= 117) {
  ------------------
  |  Branch (79:16): [True: 1.77k, False: 1.66k]
  ------------------
   80|  1.77k|        ctx->data_label_len_len = 1;
   81|  1.77k|        ctx->strl_v_len = 4;
   82|  1.77k|        ctx->strl_o_len = 4;
   83|  1.77k|    }
   84|       |
   85|  3.82k|    if (ds_format < 105) {
  ------------------
  |  Branch (85:9): [True: 759, False: 3.06k]
  ------------------
   86|    759|        ctx->expansion_len_len = 0;
   87|  3.06k|    } else if (ds_format < 110) {
  ------------------
  |  Branch (87:16): [True: 581, False: 2.48k]
  ------------------
   88|    581|        ctx->expansion_len_len = 2;
   89|  2.48k|    } else {
   90|  2.48k|        ctx->expansion_len_len = 4;
   91|  2.48k|    }
   92|       |    
   93|  3.82k|    if (ds_format < 110) {
  ------------------
  |  Branch (93:9): [True: 1.34k, False: 2.48k]
  ------------------
   94|  1.34k|        ctx->lbllist_entry_len = 9;
   95|  1.34k|        ctx->variable_name_len = 9;
   96|  1.34k|        ctx->ch_metadata_len = 9;
   97|  2.48k|    } else if (ds_format < 118) {
  ------------------
  |  Branch (97:16): [True: 2.10k, False: 380]
  ------------------
   98|  2.10k|        ctx->lbllist_entry_len = 33;
   99|  2.10k|        ctx->variable_name_len = 33;
  100|  2.10k|        ctx->ch_metadata_len = 33;
  101|  2.10k|    } else {
  102|    380|        ctx->lbllist_entry_len = 129;
  103|    380|        ctx->variable_name_len = 129;
  104|    380|        ctx->ch_metadata_len = 129;
  105|    380|    }
  106|       |
  107|  3.82k|    if (ds_format < 108) {
  ------------------
  |  Branch (107:9): [True: 1.33k, False: 2.48k]
  ------------------
  108|  1.33k|        ctx->variable_labels_entry_len = 32;
  109|  1.33k|        ctx->data_label_len = 32;
  110|  2.48k|    } else if (ds_format < 118) {
  ------------------
  |  Branch (110:16): [True: 2.10k, False: 380]
  ------------------
  111|  2.10k|        ctx->variable_labels_entry_len = 81;
  112|  2.10k|        ctx->data_label_len = 81;
  113|  2.10k|    } else {
  114|    380|        ctx->variable_labels_entry_len = 321;
  115|    380|        ctx->data_label_len = 321;
  116|    380|    }
  117|       |
  118|  3.82k|    if (ds_format < 105) {
  ------------------
  |  Branch (118:9): [True: 759, False: 3.06k]
  ------------------
  119|    759|        ctx->timestamp_len = 0;
  120|    759|        ctx->value_label_table_len_len = 2;
  121|    759|        ctx->value_label_table_labname_len = 12;
  122|    759|        ctx->value_label_table_padding_len = 2;
  123|  3.06k|    } else {
  124|  3.06k|        ctx->timestamp_len = 18;
  125|  3.06k|        ctx->value_label_table_len_len = 4;
  126|  3.06k|        if (ds_format < 118) {
  ------------------
  |  Branch (126:13): [True: 2.68k, False: 380]
  ------------------
  127|  2.68k|            ctx->value_label_table_labname_len = 33;
  128|  2.68k|        } else {
  129|    380|            ctx->value_label_table_labname_len = 129;
  130|    380|        }
  131|  3.06k|        ctx->value_label_table_padding_len = 3;
  132|  3.06k|    }
  133|       |
  134|  3.82k|    if (ds_format < 117) {
  ------------------
  |  Branch (134:9): [True: 1.66k, False: 2.15k]
  ------------------
  135|  1.66k|        ctx->typlist_entry_len = 1;
  136|  1.66k|        ctx->file_is_xmlish = 0;
  137|  2.15k|    } else {
  138|  2.15k|        ctx->typlist_entry_len = 2;
  139|  2.15k|        ctx->file_is_xmlish = 1;
  140|  2.15k|    }
  141|       |
  142|  3.82k|    if (ds_format < 113) {
  ------------------
  |  Branch (142:9): [True: 1.37k, False: 2.44k]
  ------------------
  143|  1.37k|        ctx->max_int8 = DTA_OLD_MAX_INT8;
  ------------------
  |  |  132|  1.37k|#define DTA_OLD_MAX_INT8                     0x7e
  ------------------
  144|  1.37k|        ctx->max_int16 = DTA_OLD_MAX_INT16;
  ------------------
  |  |  133|  1.37k|#define DTA_OLD_MAX_INT16                  0x7ffe
  ------------------
  145|  1.37k|        ctx->max_int32 = DTA_OLD_MAX_INT32;
  ------------------
  |  |  134|  1.37k|#define DTA_OLD_MAX_INT32              0x7ffffffe
  ------------------
  146|  1.37k|        ctx->max_float = DTA_OLD_MAX_FLOAT;
  ------------------
  |  |  135|  1.37k|#define DTA_OLD_MAX_FLOAT              0x7effffff // +1.7e38f
  ------------------
  147|  1.37k|        ctx->max_double = DTA_OLD_MAX_DOUBLE;
  ------------------
  |  |  136|  1.37k|#define DTA_OLD_MAX_DOUBLE     0x7fdfffffffffffffL // +8.9e307
  ------------------
  148|  2.44k|    } else {
  149|  2.44k|        ctx->max_int8 = DTA_113_MAX_INT8;
  ------------------
  |  |  144|  2.44k|#define DTA_113_MAX_INT8                    0x64
  ------------------
  150|  2.44k|        ctx->max_int16 = DTA_113_MAX_INT16;
  ------------------
  |  |  145|  2.44k|#define DTA_113_MAX_INT16                 0x7fe4
  ------------------
  151|  2.44k|        ctx->max_int32 = DTA_113_MAX_INT32;
  ------------------
  |  |  146|  2.44k|#define DTA_113_MAX_INT32             0x7fffffe4
  ------------------
  152|  2.44k|        ctx->max_float = DTA_113_MAX_FLOAT;
  ------------------
  |  |  147|  2.44k|#define DTA_113_MAX_FLOAT             0x7effffff // +1.7e38f
  ------------------
  153|  2.44k|        ctx->max_double = DTA_113_MAX_DOUBLE;
  ------------------
  |  |  148|  2.44k|#define DTA_113_MAX_DOUBLE    0x7fdfffffffffffffL // +8.9e307
  ------------------
  154|       |
  155|  2.44k|        ctx->supports_tagged_missing = 1;
  156|  2.44k|    }
  157|       |
  158|  3.82k|    if (output_encoding) {
  ------------------
  |  Branch (158:9): [True: 3.82k, False: 0]
  ------------------
  159|  3.82k|        if (input_encoding) {
  ------------------
  |  Branch (159:13): [True: 0, False: 3.82k]
  ------------------
  160|      0|            ctx->converter = iconv_open(output_encoding, input_encoding);
  161|  3.82k|        } else if (ds_format < 118) {
  ------------------
  |  Branch (161:20): [True: 3.44k, False: 380]
  ------------------
  162|  3.44k|            ctx->converter = iconv_open(output_encoding, "WINDOWS-1252");
  163|  3.44k|        } else if (strcmp(output_encoding, "UTF-8") != 0) {
  ------------------
  |  Branch (163:20): [True: 0, False: 380]
  ------------------
  164|      0|            ctx->converter = iconv_open(output_encoding, "UTF-8");
  165|      0|        }
  166|  3.82k|        if (ctx->converter == (iconv_t)-1) {
  ------------------
  |  Branch (166:13): [True: 0, False: 3.82k]
  ------------------
  167|      0|            ctx->converter = NULL;
  168|      0|            retval = READSTAT_ERROR_UNSUPPORTED_CHARSET;
  169|      0|            goto cleanup;
  170|      0|        }
  171|  3.82k|    }
  172|       |
  173|  3.82k|    if (ds_format < 119) {
  ------------------
  |  Branch (173:9): [True: 3.76k, False: 63]
  ------------------
  174|  3.76k|        ctx->srtlist_len = (ctx->nvar + 1) * sizeof(int16_t);
  175|  3.76k|    } else {
  176|     63|        ctx->srtlist_len = (ctx->nvar + 1) * sizeof(int32_t);
  177|     63|    }
  178|       |
  179|  3.82k|    if ((ctx->srtlist = readstat_malloc(ctx->srtlist_len)) == NULL) {
  ------------------
  |  Branch (179:9): [True: 0, False: 3.82k]
  ------------------
  180|      0|        retval = READSTAT_ERROR_MALLOC;
  181|      0|        goto cleanup;
  182|      0|    }
  183|       |
  184|  3.82k|    if (ctx->nvar > 0) {
  ------------------
  |  Branch (184:9): [True: 2.91k, False: 910]
  ------------------
  185|  2.91k|        ctx->typlist_len = ctx->nvar * sizeof(uint16_t);
  186|  2.91k|        ctx->varlist_len = ctx->variable_name_len * ctx->nvar * sizeof(char);
  187|  2.91k|        ctx->fmtlist_len = ctx->fmtlist_entry_len * ctx->nvar * sizeof(char);
  188|  2.91k|        ctx->lbllist_len = ctx->lbllist_entry_len * ctx->nvar * sizeof(char);
  189|  2.91k|        ctx->variable_labels_len = ctx->variable_labels_entry_len * ctx->nvar * sizeof(char);
  190|       |
  191|  2.91k|        if ((ctx->typlist = readstat_malloc(ctx->typlist_len)) == NULL) {
  ------------------
  |  Branch (191:13): [True: 0, False: 2.91k]
  ------------------
  192|      0|            retval = READSTAT_ERROR_MALLOC;
  193|      0|            goto cleanup;
  194|      0|        }
  195|  2.91k|        if ((ctx->varlist = readstat_malloc(ctx->varlist_len)) == NULL) {
  ------------------
  |  Branch (195:13): [True: 25, False: 2.88k]
  ------------------
  196|     25|            retval = READSTAT_ERROR_MALLOC;
  197|     25|            goto cleanup;
  198|     25|        }
  199|  2.88k|        if ((ctx->fmtlist = readstat_malloc(ctx->fmtlist_len)) == NULL) {
  ------------------
  |  Branch (199:13): [True: 0, False: 2.88k]
  ------------------
  200|      0|            retval = READSTAT_ERROR_MALLOC;
  201|      0|            goto cleanup;
  202|      0|        }
  203|  2.88k|        if ((ctx->lbllist = readstat_malloc(ctx->lbllist_len)) == NULL) {
  ------------------
  |  Branch (203:13): [True: 0, False: 2.88k]
  ------------------
  204|      0|            retval = READSTAT_ERROR_MALLOC;
  205|      0|            goto cleanup;
  206|      0|        }
  207|  2.88k|        if ((ctx->variable_labels = readstat_malloc(ctx->variable_labels_len)) == NULL) {
  ------------------
  |  Branch (207:13): [True: 3, False: 2.88k]
  ------------------
  208|      3|            retval = READSTAT_ERROR_MALLOC;
  209|      3|            goto cleanup;
  210|      3|        }
  211|  2.88k|    }
  212|       |
  213|  3.79k|    ctx->initialized = 1;
  214|       |
  215|  3.90k|cleanup:
  216|  3.90k|    return retval;
  217|  3.79k|}
dta_ctx_free:
  219|  4.39k|void dta_ctx_free(dta_ctx_t *ctx) {
  220|  4.39k|    if (ctx->typlist)
  ------------------
  |  Branch (220:9): [True: 2.91k, False: 1.48k]
  ------------------
  221|  2.91k|        free(ctx->typlist);
  222|  4.39k|    if (ctx->varlist)
  ------------------
  |  Branch (222:9): [True: 2.88k, False: 1.51k]
  ------------------
  223|  2.88k|        free(ctx->varlist);
  224|  4.39k|    if (ctx->srtlist)
  ------------------
  |  Branch (224:9): [True: 3.82k, False: 575]
  ------------------
  225|  3.82k|        free(ctx->srtlist);
  226|  4.39k|    if (ctx->fmtlist)
  ------------------
  |  Branch (226:9): [True: 2.88k, False: 1.51k]
  ------------------
  227|  2.88k|        free(ctx->fmtlist);
  228|  4.39k|    if (ctx->lbllist)
  ------------------
  |  Branch (228:9): [True: 2.88k, False: 1.51k]
  ------------------
  229|  2.88k|        free(ctx->lbllist);
  230|  4.39k|    if (ctx->variable_labels)
  ------------------
  |  Branch (230:9): [True: 2.88k, False: 1.51k]
  ------------------
  231|  2.88k|        free(ctx->variable_labels);
  232|  4.39k|    if (ctx->converter)
  ------------------
  |  Branch (232:9): [True: 3.44k, False: 955]
  ------------------
  233|  3.44k|        iconv_close(ctx->converter);
  234|  4.39k|    if (ctx->data_label)
  ------------------
  |  Branch (234:9): [True: 3.55k, False: 849]
  ------------------
  235|  3.55k|        free(ctx->data_label);
  236|  4.39k|    if (ctx->variables) {
  ------------------
  |  Branch (236:9): [True: 2.91k, False: 1.48k]
  ------------------
  237|  2.91k|        int i;
  238|  56.6M|        for (i=0; i<ctx->nvar; i++) {
  ------------------
  |  Branch (238:19): [True: 56.6M, False: 2.91k]
  ------------------
  239|  56.6M|            if (ctx->variables[i])
  ------------------
  |  Branch (239:17): [True: 66.7k, False: 56.5M]
  ------------------
  240|  66.7k|                free(ctx->variables[i]);
  241|  56.6M|        }
  242|  2.91k|        free(ctx->variables);
  243|  2.91k|    }
  244|  4.39k|    if (ctx->strls) {
  ------------------
  |  Branch (244:9): [True: 851, False: 3.54k]
  ------------------
  245|    851|        int i;
  246|   206k|        for (i=0; i<ctx->strls_count; i++) {
  ------------------
  |  Branch (246:19): [True: 205k, False: 851]
  ------------------
  247|   205k|            free(ctx->strls[i]);
  248|   205k|        }
  249|    851|        free(ctx->strls);
  250|    851|    }
  251|  4.39k|    free(ctx);
  252|  4.39k|}
dta_type_info:
  255|   156k|        size_t *max_len, readstat_type_t *out_type) {
  256|   156k|    readstat_error_t retval = READSTAT_OK;
  257|   156k|    size_t len = 0;
  258|   156k|    readstat_type_t type = READSTAT_TYPE_STRING;
  259|   156k|    if (ctx->typlist_version == 111) {
  ------------------
  |  Branch (259:9): [True: 25.5k, False: 130k]
  ------------------
  260|  25.5k|        switch (typecode) {
  261|    877|            case DTA_111_TYPE_CODE_INT8:
  ------------------
  |  |  172|    877|#define DTA_111_TYPE_CODE_INT8     0xFB
  ------------------
  |  Branch (261:13): [True: 877, False: 24.6k]
  ------------------
  262|    877|                len = 1; type = READSTAT_TYPE_INT8; break;
  263|    434|            case DTA_111_TYPE_CODE_INT16:
  ------------------
  |  |  173|    434|#define DTA_111_TYPE_CODE_INT16    0xFC
  ------------------
  |  Branch (263:13): [True: 434, False: 25.1k]
  ------------------
  264|    434|                len = 2; type = READSTAT_TYPE_INT16; break;
  265|    434|            case DTA_111_TYPE_CODE_INT32:
  ------------------
  |  |  174|    434|#define DTA_111_TYPE_CODE_INT32    0xFD
  ------------------
  |  Branch (265:13): [True: 434, False: 25.1k]
  ------------------
  266|    434|                len = 4; type = READSTAT_TYPE_INT32; break;
  267|    489|            case DTA_111_TYPE_CODE_FLOAT:
  ------------------
  |  |  175|    489|#define DTA_111_TYPE_CODE_FLOAT    0xFE
  ------------------
  |  Branch (267:13): [True: 489, False: 25.0k]
  ------------------
  268|    489|                len = 4; type = READSTAT_TYPE_FLOAT; break;
  269|  1.07k|            case DTA_111_TYPE_CODE_DOUBLE:
  ------------------
  |  |  176|  1.07k|#define DTA_111_TYPE_CODE_DOUBLE   0xFF
  ------------------
  |  Branch (269:13): [True: 1.07k, False: 24.4k]
  ------------------
  270|  1.07k|                len = 8; type = READSTAT_TYPE_DOUBLE; break;
  271|  22.2k|            default:
  ------------------
  |  Branch (271:13): [True: 22.2k, False: 3.31k]
  ------------------
  272|  22.2k|                len = typecode; type = READSTAT_TYPE_STRING; break;
  273|  25.5k|        }
  274|   130k|    } else if (ctx->typlist_version == 117) {
  ------------------
  |  Branch (274:16): [True: 18.6k, False: 112k]
  ------------------
  275|  18.6k|        switch (typecode) {
  276|    850|            case DTA_117_TYPE_CODE_INT8:
  ------------------
  |  |  165|    850|#define DTA_117_TYPE_CODE_INT8     0xFFFA
  ------------------
  |  Branch (276:13): [True: 850, False: 17.8k]
  ------------------
  277|    850|                len = 1; type = READSTAT_TYPE_INT8; break;
  278|    576|            case DTA_117_TYPE_CODE_INT16:
  ------------------
  |  |  166|    576|#define DTA_117_TYPE_CODE_INT16    0xFFF9
  ------------------
  |  Branch (278:13): [True: 576, False: 18.0k]
  ------------------
  279|    576|                len = 2; type = READSTAT_TYPE_INT16; break;
  280|    464|            case DTA_117_TYPE_CODE_INT32:
  ------------------
  |  |  167|    464|#define DTA_117_TYPE_CODE_INT32    0xFFF8
  ------------------
  |  Branch (280:13): [True: 464, False: 18.2k]
  ------------------
  281|    464|                len = 4; type = READSTAT_TYPE_INT32; break;
  282|    481|            case DTA_117_TYPE_CODE_FLOAT:
  ------------------
  |  |  168|    481|#define DTA_117_TYPE_CODE_FLOAT    0xFFF7
  ------------------
  |  Branch (282:13): [True: 481, False: 18.1k]
  ------------------
  283|    481|                len = 4; type = READSTAT_TYPE_FLOAT; break;
  284|    515|            case DTA_117_TYPE_CODE_DOUBLE:
  ------------------
  |  |  169|    515|#define DTA_117_TYPE_CODE_DOUBLE   0xFFF6
  ------------------
  |  Branch (284:13): [True: 515, False: 18.1k]
  ------------------
  285|    515|                len = 8; type = READSTAT_TYPE_DOUBLE; break;
  286|  10.7k|            case DTA_117_TYPE_CODE_STRL:
  ------------------
  |  |  170|  10.7k|#define DTA_117_TYPE_CODE_STRL     0x8000
  ------------------
  |  Branch (286:13): [True: 10.7k, False: 7.95k]
  ------------------
  287|  10.7k|                len = 8; type = READSTAT_TYPE_STRING_REF; break;
  288|  5.06k|            default:
  ------------------
  |  Branch (288:13): [True: 5.06k, False: 13.6k]
  ------------------
  289|  5.06k|                len = typecode; type = READSTAT_TYPE_STRING; break;
  290|  18.6k|        }
  291|   112k|    } else if (typecode < 0x7F) {
  ------------------
  |  Branch (291:16): [True: 54.3k, False: 57.7k]
  ------------------
  292|  54.3k|        switch (typecode) {
  293|  50.6k|            case DTA_OLD_TYPE_CODE_INT8:
  ------------------
  |  |  178|  50.6k|#define DTA_OLD_TYPE_CODE_INT8     'b'
  ------------------
  |  Branch (293:13): [True: 50.6k, False: 3.72k]
  ------------------
  294|  50.6k|                len = 1; type = READSTAT_TYPE_INT8; break;
  295|    812|            case DTA_OLD_TYPE_CODE_INT16:
  ------------------
  |  |  179|    812|#define DTA_OLD_TYPE_CODE_INT16    'i'
  ------------------
  |  Branch (295:13): [True: 812, False: 53.5k]
  ------------------
  296|    812|                len = 2; type = READSTAT_TYPE_INT16; break;
  297|  1.01k|            case DTA_OLD_TYPE_CODE_INT32:
  ------------------
  |  |  180|  1.01k|#define DTA_OLD_TYPE_CODE_INT32    'l'
  ------------------
  |  Branch (297:13): [True: 1.01k, False: 53.3k]
  ------------------
  298|  1.01k|                len = 4; type = READSTAT_TYPE_INT32; break;
  299|    872|            case DTA_OLD_TYPE_CODE_FLOAT:
  ------------------
  |  |  181|    872|#define DTA_OLD_TYPE_CODE_FLOAT    'f'
  ------------------
  |  Branch (299:13): [True: 872, False: 53.5k]
  ------------------
  300|    872|                len = 4; type = READSTAT_TYPE_FLOAT; break;
  301|  1.00k|            case DTA_OLD_TYPE_CODE_DOUBLE:
  ------------------
  |  |  182|  1.00k|#define DTA_OLD_TYPE_CODE_DOUBLE   'd'
  ------------------
  |  Branch (301:13): [True: 1.00k, False: 53.3k]
  ------------------
  302|  1.00k|                len = 8; type = READSTAT_TYPE_DOUBLE; break;
  303|     19|            default:
  ------------------
  |  Branch (303:13): [True: 19, False: 54.3k]
  ------------------
  304|     19|                retval = READSTAT_ERROR_PARSE; break;
  305|  54.3k|        }
  306|  57.7k|    } else {
  307|  57.7k|        len = typecode - 0x7F;
  308|  57.7k|        type = READSTAT_TYPE_STRING;
  309|  57.7k|    }
  310|       |    
  311|   156k|    if (max_len)
  ------------------
  |  Branch (311:9): [True: 156k, False: 0]
  ------------------
  312|   156k|        *max_len = len;
  313|   156k|    if (out_type)
  ------------------
  |  Branch (313:9): [True: 89.6k, False: 66.7k]
  ------------------
  314|  89.6k|        *out_type = type;
  315|       |
  316|   156k|    return retval;
  317|   156k|}

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

readstat_parse_dta:
 1133|  4.39k|readstat_error_t readstat_parse_dta(readstat_parser_t *parser, const char *path, void *user_ctx) {
 1134|  4.39k|    readstat_error_t retval = READSTAT_OK;
 1135|  4.39k|    readstat_io_t *io = parser->io;
 1136|  4.39k|    int i;
 1137|  4.39k|    dta_ctx_t    *ctx;
 1138|  4.39k|    size_t file_size = 0;
 1139|       |
 1140|  4.39k|    ctx = dta_ctx_alloc(io);
 1141|       |
 1142|  4.39k|    if (io->open(path, io->io_ctx) == -1) {
  ------------------
  |  Branch (1142:9): [True: 0, False: 4.39k]
  ------------------
 1143|      0|        retval = READSTAT_ERROR_OPEN;
 1144|      0|        goto cleanup;
 1145|      0|    }
 1146|       |
 1147|  4.39k|    char magic[4];
 1148|  4.39k|    if (io->read(magic, 4, io->io_ctx) != 4) {
  ------------------
  |  Branch (1148:9): [True: 2, False: 4.39k]
  ------------------
 1149|      2|        retval = READSTAT_ERROR_READ;
 1150|      2|        goto cleanup;
 1151|      2|    }
 1152|       |
 1153|  4.39k|    file_size = io->seek(0, READSTAT_SEEK_END, io->io_ctx);
 1154|  4.39k|    if (file_size == -1) {
  ------------------
  |  Branch (1154:9): [True: 0, False: 4.39k]
  ------------------
 1155|      0|        if (ctx->handle.error) {
  ------------------
  |  Branch (1155:13): [True: 0, False: 0]
  ------------------
 1156|      0|            snprintf(ctx->error_buf, sizeof(ctx->error_buf), "Failed to seek to end of file");
 1157|      0|            ctx->handle.error(ctx->error_buf, ctx->user_ctx);
 1158|      0|        }
 1159|      0|        retval = READSTAT_ERROR_SEEK;
 1160|      0|        goto cleanup;
 1161|      0|    }
 1162|       |
 1163|  4.39k|    if (io->seek(0, READSTAT_SEEK_SET, io->io_ctx) == -1) {
  ------------------
  |  Branch (1163:9): [True: 0, False: 4.39k]
  ------------------
 1164|      0|        if (ctx->handle.error) {
  ------------------
  |  Branch (1164:13): [True: 0, False: 0]
  ------------------
 1165|      0|            snprintf(ctx->error_buf, sizeof(ctx->error_buf), "Failed to seek to start of file");
 1166|      0|            ctx->handle.error(ctx->error_buf, ctx->user_ctx);
 1167|      0|        }
 1168|      0|        retval = READSTAT_ERROR_SEEK;
 1169|      0|        goto cleanup;
 1170|      0|    }
 1171|       |
 1172|  4.39k|    if (strncmp(magic, "<sta", 4) == 0) {
  ------------------
  |  Branch (1172:9): [True: 965, False: 3.43k]
  ------------------
 1173|    965|        dta_header64_t header;
 1174|    965|        if ((retval = dta_read_xmlish_header(ctx, &header)) != READSTAT_OK) {
  ------------------
  |  Branch (1174:13): [True: 432, False: 533]
  ------------------
 1175|    432|            goto cleanup;
 1176|    432|        }
 1177|    533|        retval = dta_ctx_init(ctx, header.nvar, header.nobs, header.byteorder, header.ds_format,
 1178|    533|                parser->input_encoding, parser->output_encoding);
 1179|  3.43k|    } else {
 1180|  3.43k|        dta_header_t header;
 1181|  3.43k|        if ((retval = dta_read_header(ctx, &header)) != READSTAT_OK) {
  ------------------
  |  Branch (1181:13): [True: 39, False: 3.39k]
  ------------------
 1182|     39|            goto cleanup;
 1183|     39|        }
 1184|  3.39k|        retval = dta_ctx_init(ctx, header.nvar, header.nobs, header.byteorder, header.ds_format,
 1185|  3.39k|                parser->input_encoding, parser->output_encoding);
 1186|  3.39k|    }
 1187|  3.92k|    if (retval != READSTAT_OK) {
  ------------------
  |  Branch (1187:9): [True: 130, False: 3.79k]
  ------------------
 1188|    130|        goto cleanup;
 1189|    130|    }
 1190|       |
 1191|  3.79k|    ctx->user_ctx = user_ctx;
 1192|  3.79k|    ctx->file_size = file_size;
 1193|  3.79k|    ctx->handle = parser->handlers;
 1194|  3.79k|    if (parser->row_offset > 0)
  ------------------
  |  Branch (1194:9): [True: 0, False: 3.79k]
  ------------------
 1195|      0|        ctx->row_offset = parser->row_offset;
 1196|  3.79k|    int64_t nobs_after_skipping = ctx->nobs - ctx->row_offset;
 1197|  3.79k|    if (nobs_after_skipping < 0) {
  ------------------
  |  Branch (1197:9): [True: 177, False: 3.61k]
  ------------------
 1198|    177|        nobs_after_skipping = 0;
 1199|    177|        ctx->row_offset = ctx->nobs;
 1200|    177|    }
 1201|  3.79k|    ctx->row_limit = nobs_after_skipping;
 1202|  3.79k|    if (parser->row_limit > 0 && parser->row_limit < nobs_after_skipping)
  ------------------
  |  Branch (1202:9): [True: 0, False: 3.79k]
  |  Branch (1202:34): [True: 0, False: 0]
  ------------------
 1203|      0|        ctx->row_limit = parser->row_limit;
 1204|       |
 1205|  3.79k|    retval = dta_update_progress(ctx);
 1206|  3.79k|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (1206:9): [True: 0, False: 3.79k]
  ------------------
 1207|      0|        goto cleanup;
 1208|       |    
 1209|  3.79k|    if ((retval = dta_read_label_and_timestamp(ctx)) != READSTAT_OK)
  ------------------
  |  Branch (1209:9): [True: 566, False: 3.23k]
  ------------------
 1210|    566|        goto cleanup;
 1211|       |
 1212|  3.23k|    if ((retval = dta_read_tag(ctx, "</header>")) != READSTAT_OK) {
  ------------------
  |  Branch (1212:9): [True: 2, False: 3.22k]
  ------------------
 1213|      2|        goto cleanup;
 1214|      2|    }
 1215|       |
 1216|  3.22k|    if (ctx->handle.metadata) {
  ------------------
  |  Branch (1216:9): [True: 3.22k, False: 0]
  ------------------
 1217|  3.22k|        readstat_metadata_t metadata = {
 1218|  3.22k|            .row_count = ctx->row_limit,
 1219|  3.22k|            .var_count = ctx->nvar,
 1220|  3.22k|            .file_label = ctx->data_label,
 1221|  3.22k|            .creation_time = ctx->timestamp,
 1222|  3.22k|            .modified_time = ctx->timestamp,
 1223|  3.22k|            .file_format_version = ctx->ds_format,
 1224|  3.22k|            .is64bit = ctx->ds_format >= 118,
 1225|  3.22k|            .endianness = ctx->endianness
 1226|  3.22k|        };
 1227|  3.22k|        if (ctx->handle.metadata(&metadata, user_ctx) != READSTAT_HANDLER_OK) {
  ------------------
  |  Branch (1227:13): [True: 0, False: 3.22k]
  ------------------
 1228|      0|            retval = READSTAT_ERROR_USER_ABORT;
 1229|      0|            goto cleanup;
 1230|      0|        }
 1231|  3.22k|    }
 1232|       |
 1233|  3.22k|    if ((retval = dta_read_map(ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1233:9): [True: 4, False: 3.22k]
  ------------------
 1234|      4|        retval = READSTAT_ERROR_READ;
 1235|      4|        goto cleanup;
 1236|      4|    }
 1237|       |
 1238|  3.22k|    if ((retval = dta_read_descriptors(ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1238:9): [True: 166, False: 3.05k]
  ------------------
 1239|    166|        goto cleanup;
 1240|    166|    }
 1241|       |
 1242|  69.8k|    for (i=0; i<ctx->nvar; i++) {
  ------------------
  |  Branch (1242:15): [True: 66.7k, False: 3.03k]
  ------------------
 1243|  66.7k|        size_t      max_len;
 1244|  66.7k|        if ((retval = dta_type_info(ctx->typlist[i], ctx, &max_len, NULL)) != READSTAT_OK)
  ------------------
  |  Branch (1244:13): [True: 19, False: 66.7k]
  ------------------
 1245|     19|            goto cleanup;
 1246|       |
 1247|  66.7k|        ctx->record_len += max_len;
 1248|  66.7k|    }
 1249|       |
 1250|  3.03k|    if ((ctx->nvar > 0 || ctx->nobs > 0) && ctx->record_len == 0) {
  ------------------
  |  Branch (1250:10): [True: 2.20k, False: 839]
  |  Branch (1250:27): [True: 33, False: 806]
  |  Branch (1250:45): [True: 36, False: 2.19k]
  ------------------
 1251|     36|        retval = READSTAT_ERROR_PARSE;
 1252|     36|        goto cleanup;
 1253|     36|    }
 1254|       |
 1255|  3.00k|    if ((retval = dta_handle_variables(ctx)) != READSTAT_OK)
  ------------------
  |  Branch (1255:9): [True: 0, False: 3.00k]
  ------------------
 1256|      0|        goto cleanup;
 1257|       |
 1258|  3.00k|    if ((retval = dta_read_expansion_fields(ctx)) != READSTAT_OK)
  ------------------
  |  Branch (1258:9): [True: 651, False: 2.35k]
  ------------------
 1259|    651|        goto cleanup;
 1260|       |
 1261|  2.35k|    if (!ctx->file_is_xmlish) {
  ------------------
  |  Branch (1261:9): [True: 1.28k, False: 1.06k]
  ------------------
 1262|  1.28k|        ctx->data_offset = io->seek(0, READSTAT_SEEK_CUR, io->io_ctx);
 1263|  1.28k|        if (ctx->data_offset == -1) {
  ------------------
  |  Branch (1263:13): [True: 0, False: 1.28k]
  ------------------
 1264|      0|            retval = READSTAT_ERROR_SEEK;
 1265|      0|            goto cleanup;
 1266|      0|        }
 1267|  1.28k|        ctx->value_labels_offset = ctx->data_offset + ctx->record_len * ctx->nobs;
 1268|  1.28k|    }
 1269|       |
 1270|  2.35k|    if ((retval = dta_read_strls(ctx)) != READSTAT_OK)
  ------------------
  |  Branch (1270:9): [True: 442, False: 1.91k]
  ------------------
 1271|    442|        goto cleanup;
 1272|       |
 1273|  1.91k|    if ((retval = dta_read_data(ctx)) != READSTAT_OK)
  ------------------
  |  Branch (1273:9): [True: 1.11k, False: 794]
  ------------------
 1274|  1.11k|        goto cleanup;
 1275|       |
 1276|    794|    if ((retval = dta_handle_value_labels(ctx)) != READSTAT_OK)
  ------------------
  |  Branch (1276:9): [True: 292, False: 502]
  ------------------
 1277|    292|        goto cleanup;
 1278|       |
 1279|  4.39k|cleanup:
 1280|  4.39k|    io->close(io->io_ctx);
 1281|  4.39k|    if (ctx)
  ------------------
  |  Branch (1281:9): [True: 4.39k, False: 0]
  ------------------
 1282|  4.39k|        dta_ctx_free(ctx);
 1283|       |
 1284|  4.39k|    return retval;
 1285|    794|}
readstat_dta_read.c:dta_read_xmlish_header:
  751|    965|static readstat_error_t dta_read_xmlish_header(dta_ctx_t *ctx, dta_header64_t *header) {
  752|    965|    readstat_error_t retval = READSTAT_OK;
  753|       |    
  754|    965|    if ((retval = dta_read_tag(ctx, "<stata_dta>")) != READSTAT_OK) {
  ------------------
  |  Branch (754:9): [True: 69, False: 896]
  ------------------
  755|     69|        goto cleanup;
  756|     69|    }
  757|    896|    if ((retval = dta_read_tag(ctx, "<header>")) != READSTAT_OK) {
  ------------------
  |  Branch (757:9): [True: 77, False: 819]
  ------------------
  758|     77|        goto cleanup;
  759|     77|    }
  760|       |
  761|    819|    char ds_format[3];
  762|    819|    if ((retval = dta_read_chunk(ctx, "<release>", ds_format,
  ------------------
  |  Branch (762:9): [True: 174, False: 645]
  ------------------
  763|    819|                    sizeof(ds_format), "</release>")) != READSTAT_OK) {
  764|    174|        goto cleanup;
  765|    174|    }
  766|       |
  767|    645|    header->ds_format = 100 * (ds_format[0] - '0') + 10 * (ds_format[1] - '0') + (ds_format[2] - '0');
  768|       |
  769|    645|    char byteorder[3];
  770|    645|    int byteswap = 0;
  771|    645|    if ((retval = dta_read_chunk(ctx, "<byteorder>", byteorder, 
  ------------------
  |  Branch (771:9): [True: 39, False: 606]
  ------------------
  772|    645|                    sizeof(byteorder), "</byteorder>")) != READSTAT_OK) {
  773|     39|        goto cleanup;
  774|     39|    }
  775|    606|    if (strncmp(byteorder, "MSF", 3) == 0) {
  ------------------
  |  Branch (775:9): [True: 74, False: 532]
  ------------------
  776|     74|        header->byteorder = DTA_HILO;
  ------------------
  |  |  129|     74|#define DTA_HILO  0x01
  ------------------
  777|    532|    } else if (strncmp(byteorder, "LSF", 3) == 0) {
  ------------------
  |  Branch (777:16): [True: 489, False: 43]
  ------------------
  778|    489|        header->byteorder = DTA_LOHI;
  ------------------
  |  |  130|    489|#define DTA_LOHI  0x02
  ------------------
  779|    489|    } else {
  780|     43|        retval = READSTAT_ERROR_PARSE;
  781|     43|        goto cleanup;
  782|     43|    }
  783|    563|    byteswap = (header->byteorder == DTA_LOHI) ^ machine_is_little_endian();
  ------------------
  |  |  130|    563|#define DTA_LOHI  0x02
  ------------------
  784|       |
  785|    563|    if (header->ds_format >= 119) {
  ------------------
  |  Branch (785:9): [True: 115, False: 448]
  ------------------
  786|    115|        uint32_t nvar;
  787|    115|        if ((retval = dta_read_chunk(ctx, "<K>", &nvar, 
  ------------------
  |  Branch (787:13): [True: 4, False: 111]
  ------------------
  788|    115|                        sizeof(uint32_t), "</K>")) != READSTAT_OK) {
  789|      4|            goto cleanup;
  790|      4|        }
  791|    111|        header->nvar = byteswap ? byteswap4(nvar) : nvar;
  ------------------
  |  Branch (791:24): [True: 60, False: 51]
  ------------------
  792|    448|    } else {
  793|    448|        uint16_t nvar;
  794|    448|        if ((retval = dta_read_chunk(ctx, "<K>", &nvar, 
  ------------------
  |  Branch (794:13): [True: 9, False: 439]
  ------------------
  795|    448|                        sizeof(uint16_t), "</K>")) != READSTAT_OK) {
  796|      9|            goto cleanup;
  797|      9|        }
  798|    439|        header->nvar = byteswap ? byteswap2(nvar) : nvar;
  ------------------
  |  Branch (798:24): [True: 12, False: 427]
  ------------------
  799|    439|    }
  800|       |
  801|    550|    if (header->ds_format >= 118) {
  ------------------
  |  Branch (801:9): [True: 394, False: 156]
  ------------------
  802|    394|        uint64_t nobs;
  803|    394|        if ((retval = dta_read_chunk(ctx, "<N>", &nobs, 
  ------------------
  |  Branch (803:13): [True: 4, False: 390]
  ------------------
  804|    394|                        sizeof(uint64_t), "</N>")) != READSTAT_OK) {
  805|      4|            goto cleanup;
  806|      4|        }
  807|    390|        header->nobs = byteswap ? byteswap8(nobs) : nobs;
  ------------------
  |  Branch (807:24): [True: 68, False: 322]
  ------------------
  808|    390|    } else {
  809|    156|        uint32_t nobs;
  810|    156|        if ((retval = dta_read_chunk(ctx, "<N>", &nobs, 
  ------------------
  |  Branch (810:13): [True: 13, False: 143]
  ------------------
  811|    156|                        sizeof(uint32_t), "</N>")) != READSTAT_OK) {
  812|     13|            goto cleanup;
  813|     13|        }
  814|    143|        header->nobs = byteswap ? byteswap4(nobs) : nobs;
  ------------------
  |  Branch (814:24): [True: 1, False: 142]
  ------------------
  815|    143|    }
  816|       |
  817|    965|cleanup:
  818|    965|    return retval;
  819|    550|}
readstat_dta_read.c:dta_read_chunk:
   87|  22.7k|        const char *end_tag) {
   88|  22.7k|    char *dst_buffer = (char *)dst;
   89|  22.7k|    readstat_io_t *io = ctx->io;
   90|  22.7k|    readstat_error_t retval = READSTAT_OK;
   91|       |
   92|  22.7k|    if ((retval = dta_read_tag(ctx, start_tag)) != READSTAT_OK)
  ------------------
  |  Branch (92:9): [True: 196, False: 22.5k]
  ------------------
   93|    196|        goto cleanup;
   94|       |
   95|  22.5k|    if (io->read(dst_buffer, dst_len, io->io_ctx) != dst_len) {
  ------------------
  |  Branch (95:9): [True: 65, False: 22.5k]
  ------------------
   96|     65|        retval = READSTAT_ERROR_READ;
   97|     65|        goto cleanup;
   98|     65|    }
   99|       |
  100|  22.5k|    if ((retval = dta_read_tag(ctx, end_tag)) != READSTAT_OK)
  ------------------
  |  Branch (100:9): [True: 152, False: 22.3k]
  ------------------
  101|    152|        goto cleanup;
  102|       |
  103|  22.7k|cleanup:
  104|       |
  105|  22.7k|    return retval;
  106|  22.5k|}
readstat_dta_read.c:dta_read_header:
  734|  3.43k|static readstat_error_t dta_read_header(dta_ctx_t *ctx, dta_header_t *header) {
  735|  3.43k|    readstat_error_t retval = READSTAT_OK;
  736|  3.43k|    readstat_io_t *io = ctx->io;
  737|  3.43k|    int bswap = 0;
  738|       |
  739|  3.43k|    if (io->read(header, sizeof(dta_header_t), io->io_ctx) != sizeof(dta_header_t)) {
  ------------------
  |  Branch (739:9): [True: 39, False: 3.39k]
  ------------------
  740|     39|        retval = READSTAT_ERROR_READ;
  741|     39|        goto cleanup;
  742|     39|    }
  743|  3.39k|    bswap = (header->byteorder == DTA_LOHI) ^ machine_is_little_endian();
  ------------------
  |  |  130|  3.39k|#define DTA_LOHI  0x02
  ------------------
  744|  3.39k|    header->nvar = bswap ? byteswap2(header->nvar) : header->nvar;
  ------------------
  |  Branch (744:20): [True: 2.56k, False: 825]
  ------------------
  745|  3.39k|    header->nobs = bswap ? byteswap4(header->nobs) : header->nobs;
  ------------------
  |  Branch (745:20): [True: 2.56k, False: 825]
  ------------------
  746|       |
  747|  3.43k|cleanup:
  748|  3.43k|    return retval;
  749|  3.39k|}
readstat_dta_read.c:dta_update_progress:
   29|  27.8k|static readstat_error_t dta_update_progress(dta_ctx_t *ctx) {
   30|  27.8k|    double progress = 0.0;
   31|  27.8k|    if (ctx->row_limit > 0)
  ------------------
  |  Branch (31:9): [True: 25.5k, False: 2.28k]
  ------------------
   32|  25.5k|        progress = 1.0 * ctx->current_row / ctx->row_limit;
   33|  27.8k|    if (ctx->handle.progress && ctx->handle.progress(progress, ctx->user_ctx) != READSTAT_HANDLER_OK)
  ------------------
  |  Branch (33:9): [True: 0, False: 27.8k]
  |  Branch (33:33): [True: 0, False: 0]
  ------------------
   34|      0|        return READSTAT_ERROR_USER_ABORT;
   35|  27.8k|    return READSTAT_OK;
   36|  27.8k|}
readstat_dta_read.c:dta_read_label_and_timestamp:
  821|  3.79k|static readstat_error_t dta_read_label_and_timestamp(dta_ctx_t *ctx) {
  822|  3.79k|    readstat_io_t *io = ctx->io;
  823|  3.79k|    readstat_error_t retval = READSTAT_OK;
  824|  3.79k|    char *data_label_buffer = NULL;
  825|  3.79k|    char *timestamp_buffer = NULL;
  826|  3.79k|    uint16_t label_len = 0;
  827|  3.79k|    unsigned char timestamp_len = 0;
  828|  3.79k|    char last_data_label_char = 0;
  829|  3.79k|    struct tm timestamp = { .tm_isdst = -1 };
  830|       |
  831|  3.79k|    if (ctx->file_is_xmlish) {
  ------------------
  |  Branch (831:9): [True: 2.12k, False: 1.66k]
  ------------------
  832|  2.12k|        if ((retval = dta_read_tag(ctx, "<label>")) != READSTAT_OK) {
  ------------------
  |  Branch (832:13): [True: 196, False: 1.93k]
  ------------------
  833|    196|            goto cleanup;
  834|    196|        }
  835|       |        
  836|  1.93k|        if (ctx->data_label_len_len == 2) {
  ------------------
  |  Branch (836:13): [True: 226, False: 1.70k]
  ------------------
  837|    226|            if (io->read(&label_len, sizeof(uint16_t), io->io_ctx) != sizeof(uint16_t)) {
  ------------------
  |  Branch (837:17): [True: 2, False: 224]
  ------------------
  838|      2|                retval = READSTAT_ERROR_READ;
  839|      2|                goto cleanup;
  840|      2|            }
  841|    224|            label_len = ctx->bswap ? byteswap2(label_len) : label_len;
  ------------------
  |  Branch (841:25): [True: 33, False: 191]
  ------------------
  842|  1.70k|        } else if (ctx->data_label_len_len == 1) {
  ------------------
  |  Branch (842:20): [True: 1.70k, False: 0]
  ------------------
  843|  1.70k|            unsigned char label_len_char;
  844|  1.70k|            if (io->read(&label_len_char, sizeof(unsigned char), io->io_ctx) != sizeof(unsigned char)) {
  ------------------
  |  Branch (844:17): [True: 1, False: 1.70k]
  ------------------
  845|      1|                retval = READSTAT_ERROR_READ;
  846|      1|                goto cleanup;
  847|      1|            }
  848|  1.70k|            label_len = label_len_char;
  849|  1.70k|        }
  850|  1.93k|    } else {
  851|  1.66k|        label_len = ctx->data_label_len;
  852|  1.66k|    }
  853|       |
  854|  3.59k|    if ((data_label_buffer = readstat_malloc(label_len+1)) == NULL) {
  ------------------
  |  Branch (854:9): [True: 0, False: 3.59k]
  ------------------
  855|      0|        retval = READSTAT_ERROR_MALLOC;
  856|      0|        goto cleanup;
  857|      0|    }
  858|       |
  859|  3.59k|    if (io->read(data_label_buffer, label_len, io->io_ctx) != label_len) {
  ------------------
  |  Branch (859:9): [True: 47, False: 3.55k]
  ------------------
  860|     47|        retval = READSTAT_ERROR_READ;
  861|     47|        goto cleanup;
  862|     47|    }
  863|       |
  864|  3.55k|    if (!ctx->file_is_xmlish) {
  ------------------
  |  Branch (864:9): [True: 1.64k, False: 1.90k]
  ------------------
  865|  1.64k|        last_data_label_char = data_label_buffer[label_len-1];
  866|  1.64k|        data_label_buffer[label_len] = '\0';
  867|  1.64k|        label_len = strlen(data_label_buffer);
  868|  1.64k|    }
  869|       |
  870|  3.55k|    if ((ctx->data_label = readstat_malloc(4*label_len+1)) == NULL) {
  ------------------
  |  Branch (870:9): [True: 0, False: 3.55k]
  ------------------
  871|      0|        retval = READSTAT_ERROR_MALLOC;
  872|      0|        goto cleanup;
  873|      0|    }
  874|       |
  875|  3.55k|    if ((retval = readstat_convert(ctx->data_label, 4*label_len+1,
  ------------------
  |  Branch (875:9): [True: 2, False: 3.54k]
  ------------------
  876|  3.55k|                    data_label_buffer, label_len, ctx->converter)) != READSTAT_OK)
  877|      2|        goto cleanup;
  878|       |
  879|  3.54k|    if (ctx->file_is_xmlish) {
  ------------------
  |  Branch (879:9): [True: 1.90k, False: 1.64k]
  ------------------
  880|  1.90k|        if ((retval = dta_read_tag(ctx, "</label>")) != READSTAT_OK) {
  ------------------
  |  Branch (880:13): [True: 123, False: 1.78k]
  ------------------
  881|    123|            goto cleanup;
  882|    123|        }
  883|       |        
  884|  1.78k|        if ((retval = dta_read_tag(ctx, "<timestamp>")) != READSTAT_OK) {
  ------------------
  |  Branch (884:13): [True: 99, False: 1.68k]
  ------------------
  885|     99|            goto cleanup;
  886|     99|        }
  887|       |        
  888|  1.68k|        if (io->read(&timestamp_len, 1, io->io_ctx) != 1) {
  ------------------
  |  Branch (888:13): [True: 1, False: 1.68k]
  ------------------
  889|      1|            retval = READSTAT_ERROR_READ;
  890|      1|            goto cleanup;
  891|      1|        }
  892|  1.68k|    } else {
  893|  1.64k|        timestamp_len = ctx->timestamp_len;
  894|  1.64k|    }
  895|       |
  896|  3.32k|    if (timestamp_len) {
  ------------------
  |  Branch (896:9): [True: 1.64k, False: 1.68k]
  ------------------
  897|  1.64k|        timestamp_buffer = readstat_malloc(timestamp_len);
  898|       |        
  899|  1.64k|        if (io->read(timestamp_buffer, timestamp_len, io->io_ctx) != timestamp_len) {
  ------------------
  |  Branch (899:13): [True: 8, False: 1.63k]
  ------------------
  900|      8|            retval = READSTAT_ERROR_READ;
  901|      8|            goto cleanup;
  902|      8|        }
  903|       |
  904|  1.63k|        if (!ctx->file_is_xmlish)
  ------------------
  |  Branch (904:13): [True: 887, False: 750]
  ------------------
  905|    887|            timestamp_len--;
  906|       |
  907|  1.63k|        if (timestamp_buffer[0]) {
  ------------------
  |  Branch (907:13): [True: 1.26k, False: 377]
  ------------------
  908|  1.26k|            if (timestamp_buffer[timestamp_len-1] == '\0' && last_data_label_char != '\0') {
  ------------------
  |  Branch (908:17): [True: 177, False: 1.08k]
  |  Branch (908:62): [True: 116, False: 61]
  ------------------
  909|       |                /* Stupid hack for miswritten files with off-by-one timestamp, DTA 114 era? */
  910|    116|                memmove(timestamp_buffer+1, timestamp_buffer, timestamp_len-1);
  911|    116|                timestamp_buffer[0] = last_data_label_char;
  912|    116|            }
  913|  1.26k|            if (dta_parse_timestamp(timestamp_buffer, timestamp_len,
  ------------------
  |  Branch (913:17): [True: 50, False: 1.21k]
  ------------------
  914|  1.26k|                        &timestamp, ctx->handle.error, ctx->user_ctx) == READSTAT_OK) {
  915|     50|                ctx->timestamp = mktime(&timestamp);
  916|     50|            }
  917|  1.26k|        }
  918|  1.63k|    }
  919|       |
  920|  3.31k|    if ((retval = dta_read_tag(ctx, "</timestamp>")) != READSTAT_OK) {
  ------------------
  |  Branch (920:9): [True: 87, False: 3.23k]
  ------------------
  921|     87|        goto cleanup;
  922|     87|    }
  923|       |
  924|  3.79k|cleanup:
  925|  3.79k|    if (data_label_buffer)
  ------------------
  |  Branch (925:9): [True: 3.59k, False: 199]
  ------------------
  926|  3.59k|        free(data_label_buffer);
  927|  3.79k|    if (timestamp_buffer)
  ------------------
  |  Branch (927:9): [True: 1.64k, False: 2.15k]
  ------------------
  928|  1.64k|        free(timestamp_buffer);
  929|       |
  930|  3.79k|    return retval;
  931|  3.31k|}
readstat_dta_read.c:dta_read_tag:
  298|  76.9k|static readstat_error_t dta_read_tag(dta_ctx_t *ctx, const char *tag) {
  299|  76.9k|    readstat_error_t retval = READSTAT_OK;
  300|  76.9k|    if (ctx->initialized && !ctx->file_is_xmlish)
  ------------------
  |  Branch (300:9): [True: 70.0k, False: 6.88k]
  |  Branch (300:29): [True: 32.9k, False: 37.0k]
  ------------------
  301|  32.9k|        return retval;
  302|       |
  303|  43.9k|    char buffer[256];
  304|  43.9k|    size_t len = strlen(tag);
  305|  43.9k|    if (ctx->io->read(buffer, len, ctx->io->io_ctx) != len) {
  ------------------
  |  Branch (305:9): [True: 450, False: 43.4k]
  ------------------
  306|    450|        retval = READSTAT_ERROR_READ;
  307|    450|        goto cleanup;
  308|    450|    }
  309|  43.4k|    if (strncmp(buffer, tag, len) != 0) {
  ------------------
  |  Branch (309:9): [True: 1.40k, False: 42.0k]
  ------------------
  310|  1.40k|        retval = READSTAT_ERROR_PARSE;
  311|  1.40k|        goto cleanup;
  312|  1.40k|    }
  313|  43.9k|cleanup:
  314|  43.9k|    return retval;
  315|  43.4k|}
readstat_dta_read.c:dta_read_map:
  108|  3.22k|static readstat_error_t dta_read_map(dta_ctx_t *ctx) {
  109|  3.22k|    if (!ctx->file_is_xmlish)
  ------------------
  |  Branch (109:9): [True: 1.64k, False: 1.58k]
  ------------------
  110|  1.64k|        return READSTAT_OK;
  111|       |
  112|  1.58k|    readstat_error_t retval = READSTAT_OK;
  113|  1.58k|    uint64_t map_buffer[14];
  114|       |
  115|  1.58k|    if ((retval = dta_read_chunk(ctx, "<map>", map_buffer, 
  ------------------
  |  Branch (115:9): [True: 4, False: 1.58k]
  ------------------
  116|  1.58k|                    sizeof(map_buffer), "</map>")) != READSTAT_OK) {
  117|      4|        goto cleanup;
  118|      4|    }
  119|       |
  120|  1.58k|    ctx->data_offset = ctx->bswap ? byteswap8(map_buffer[9]) : map_buffer[9];
  ------------------
  |  Branch (120:24): [True: 1.24k, False: 336]
  ------------------
  121|  1.58k|    ctx->strls_offset = ctx->bswap ? byteswap8(map_buffer[10]) : map_buffer[10];
  ------------------
  |  Branch (121:25): [True: 1.24k, False: 336]
  ------------------
  122|  1.58k|    ctx->value_labels_offset = ctx->bswap ? byteswap8(map_buffer[11]) : map_buffer[11];
  ------------------
  |  Branch (122:32): [True: 1.24k, False: 336]
  ------------------
  123|       |
  124|  1.58k|cleanup:
  125|  1.58k|    return retval;
  126|  1.58k|}
readstat_dta_read.c:dta_read_descriptors:
  128|  3.22k|static readstat_error_t dta_read_descriptors(dta_ctx_t *ctx) {
  129|  3.22k|    readstat_error_t retval = READSTAT_OK;
  130|  3.22k|    size_t buffer_len = ctx->nvar * ctx->typlist_entry_len;
  131|  3.22k|    unsigned char *buffer = NULL;
  132|  3.22k|    int i;
  133|       |
  134|  3.22k|    if (ctx->nvar && (buffer = readstat_malloc(buffer_len)) == NULL) {
  ------------------
  |  Branch (134:9): [True: 2.35k, False: 868]
  |  Branch (134:22): [True: 0, False: 2.35k]
  ------------------
  135|      0|        retval = READSTAT_ERROR_MALLOC;
  136|      0|        goto cleanup;
  137|      0|    }
  138|       |
  139|  3.22k|    if ((retval = dta_read_chunk(ctx, "<variable_types>", buffer, 
  ------------------
  |  Branch (139:9): [True: 109, False: 3.11k]
  ------------------
  140|  3.22k|                    buffer_len, "</variable_types>")) != READSTAT_OK)
  141|    109|        goto cleanup;
  142|       |
  143|  3.11k|    if (ctx->typlist_entry_len == 1) {
  ------------------
  |  Branch (143:9): [True: 1.61k, False: 1.49k]
  ------------------
  144|   317k|        for (i=0; i<ctx->nvar; i++) {
  ------------------
  |  Branch (144:19): [True: 315k, False: 1.61k]
  ------------------
  145|   315k|            ctx->typlist[i] = buffer[i];
  146|   315k|        }
  147|  1.61k|    } else if (ctx->typlist_entry_len == 2) {
  ------------------
  |  Branch (147:16): [True: 1.49k, False: 0]
  ------------------
  148|  1.49k|        memcpy(ctx->typlist, buffer, buffer_len);
  149|  1.49k|        if (ctx->bswap) {
  ------------------
  |  Branch (149:13): [True: 1.17k, False: 327]
  ------------------
  150|  2.53k|            for (i=0; i<ctx->nvar; i++) {
  ------------------
  |  Branch (150:23): [True: 1.36k, False: 1.17k]
  ------------------
  151|  1.36k|                ctx->typlist[i] = byteswap2(ctx->typlist[i]);
  152|  1.36k|            }
  153|  1.17k|        }
  154|  1.49k|    }
  155|       |
  156|  3.11k|    if ((retval = dta_read_chunk(ctx, "<varnames>", ctx->varlist, 
  ------------------
  |  Branch (156:9): [True: 40, False: 3.07k]
  ------------------
  157|  3.11k|                    ctx->varlist_len, "</varnames>")) != READSTAT_OK)
  158|     40|        goto cleanup;
  159|       |
  160|  3.07k|    if ((retval = dta_read_chunk(ctx, "<sortlist>", ctx->srtlist, 
  ------------------
  |  Branch (160:9): [True: 10, False: 3.06k]
  ------------------
  161|  3.07k|                    ctx->srtlist_len, "</sortlist>")) != READSTAT_OK)
  162|     10|        goto cleanup;
  163|       |
  164|  3.06k|    if ((retval = dta_read_chunk(ctx, "<formats>", ctx->fmtlist, 
  ------------------
  |  Branch (164:9): [True: 3, False: 3.06k]
  ------------------
  165|  3.06k|                    ctx->fmtlist_len, "</formats>")) != READSTAT_OK)
  166|      3|        goto cleanup;
  167|       |
  168|  3.06k|    if ((retval = dta_read_chunk(ctx, "<value_label_names>", ctx->lbllist, 
  ------------------
  |  Branch (168:9): [True: 4, False: 3.05k]
  ------------------
  169|  3.06k|                    ctx->lbllist_len, "</value_label_names>")) != READSTAT_OK)
  170|      4|        goto cleanup;
  171|       |
  172|  3.05k|    if ((retval = dta_read_chunk(ctx, "<variable_labels>", ctx->variable_labels, 
  ------------------
  |  Branch (172:9): [True: 0, False: 3.05k]
  ------------------
  173|  3.05k|                    ctx->variable_labels_len, "</variable_labels>")) != READSTAT_OK)
  174|      0|        goto cleanup;
  175|       |
  176|  3.22k|cleanup:
  177|  3.22k|    if (buffer)
  ------------------
  |  Branch (177:9): [True: 2.35k, False: 868]
  ------------------
  178|  2.35k|        free(buffer);
  179|       |
  180|  3.22k|    return retval;
  181|  3.05k|}
readstat_dta_read.c:dta_handle_variables:
  933|  3.00k|static readstat_error_t dta_handle_variables(dta_ctx_t *ctx) {
  934|  3.00k|    if (!ctx->handle.variable)
  ------------------
  |  Branch (934:9): [True: 0, False: 3.00k]
  ------------------
  935|      0|        return READSTAT_OK;
  936|       |
  937|  3.00k|    readstat_error_t retval = READSTAT_OK;
  938|  3.00k|    int i;
  939|  3.00k|    int index_after_skipping = 0;
  940|       |
  941|  69.7k|    for (i=0; i<ctx->nvar; i++) {
  ------------------
  |  Branch (941:15): [True: 66.7k, False: 3.00k]
  ------------------
  942|  66.7k|        size_t      max_len;
  943|  66.7k|        readstat_type_t type;
  944|  66.7k|        retval = dta_type_info(ctx->typlist[i], ctx, &max_len, &type);
  945|  66.7k|        if (retval != READSTAT_OK)
  ------------------
  |  Branch (945:13): [True: 0, False: 66.7k]
  ------------------
  946|      0|            goto cleanup;
  947|       |
  948|  66.7k|        if (type == READSTAT_TYPE_STRING)
  ------------------
  |  Branch (948:13): [True: 40.8k, False: 25.9k]
  ------------------
  949|  40.8k|            max_len++; /* might append NULL */
  950|  66.7k|        if (type == READSTAT_TYPE_STRING_REF) {
  ------------------
  |  Branch (950:13): [True: 143, False: 66.6k]
  ------------------
  951|    143|            type = READSTAT_TYPE_STRING;
  952|    143|            max_len = 0;
  953|    143|        }
  954|       |
  955|  66.7k|        ctx->variables[i] = dta_init_variable(ctx, i, index_after_skipping, type, max_len);
  956|       |
  957|  66.7k|        const char *value_labels = NULL;
  958|       |
  959|  66.7k|        if (ctx->lbllist[ctx->lbllist_entry_len*i])
  ------------------
  |  Branch (959:13): [True: 27.7k, False: 38.9k]
  ------------------
  960|  27.7k|            value_labels = &ctx->lbllist[ctx->lbllist_entry_len*i];
  961|       |
  962|  66.7k|        int cb_retval = ctx->handle.variable(i, ctx->variables[i], value_labels, ctx->user_ctx);
  963|       |
  964|  66.7k|        if (cb_retval == READSTAT_HANDLER_ABORT) {
  ------------------
  |  Branch (964:13): [True: 0, False: 66.7k]
  ------------------
  965|      0|            retval = READSTAT_ERROR_USER_ABORT;
  966|      0|            goto cleanup;
  967|      0|        }
  968|       |
  969|  66.7k|        if (cb_retval == READSTAT_HANDLER_SKIP_VARIABLE) {
  ------------------
  |  Branch (969:13): [True: 0, False: 66.7k]
  ------------------
  970|      0|            ctx->variables[i]->skip = 1;
  971|  66.7k|        } else {
  972|  66.7k|            index_after_skipping++;
  973|  66.7k|        }
  974|  66.7k|    }
  975|  3.00k|cleanup:
  976|  3.00k|    return retval;
  977|  3.00k|}
readstat_dta_read.c:dta_init_variable:
   39|  66.7k|        readstat_type_t type, size_t max_len) {
   40|  66.7k|    readstat_variable_t *variable = calloc(1, sizeof(readstat_variable_t));
   41|       |
   42|  66.7k|    variable->type = type;
   43|  66.7k|    variable->index = i;
   44|  66.7k|    variable->index_after_skipping = index_after_skipping;
   45|  66.7k|    variable->storage_width = max_len;
   46|       |
   47|  66.7k|    readstat_convert(variable->name, sizeof(variable->name), 
   48|  66.7k|            &ctx->varlist[ctx->variable_name_len*i],
   49|  66.7k|            strnlen(&ctx->varlist[ctx->variable_name_len*i], ctx->variable_name_len),
   50|  66.7k|            ctx->converter);
   51|       |
   52|  66.7k|    if (ctx->variable_labels[ctx->variable_labels_entry_len*i]) {
  ------------------
  |  Branch (52:9): [True: 28.6k, False: 38.1k]
  ------------------
   53|  28.6k|        readstat_convert(variable->label, sizeof(variable->label),
   54|  28.6k|                &ctx->variable_labels[ctx->variable_labels_entry_len*i],
   55|  28.6k|                strnlen(&ctx->variable_labels[ctx->variable_labels_entry_len*i], ctx->variable_labels_entry_len),
   56|  28.6k|                ctx->converter);
   57|  28.6k|    }
   58|       |
   59|  66.7k|    if (ctx->fmtlist[ctx->fmtlist_entry_len*i]) {
  ------------------
  |  Branch (59:9): [True: 32.6k, False: 34.1k]
  ------------------
   60|  32.6k|        readstat_convert(variable->format, sizeof(variable->format),
   61|  32.6k|                &ctx->fmtlist[ctx->fmtlist_entry_len*i],
   62|  32.6k|                strnlen(&ctx->fmtlist[ctx->fmtlist_entry_len*i], ctx->fmtlist_entry_len),
   63|  32.6k|                ctx->converter);
   64|  32.6k|        if (variable->format[0] == '%') {
  ------------------
  |  Branch (64:13): [True: 3.34k, False: 29.2k]
  ------------------
   65|  3.34k|            if (variable->format[1] == '-') {
  ------------------
  |  Branch (65:17): [True: 648, False: 2.69k]
  ------------------
   66|    648|                variable->alignment = READSTAT_ALIGNMENT_LEFT;
   67|  2.69k|            } else if (variable->format[1] == '~') {
  ------------------
  |  Branch (67:24): [True: 253, False: 2.44k]
  ------------------
   68|    253|                variable->alignment = READSTAT_ALIGNMENT_CENTER;
   69|  2.44k|            } else {
   70|  2.44k|                variable->alignment = READSTAT_ALIGNMENT_RIGHT;
   71|  2.44k|            }
   72|  3.34k|        }
   73|  32.6k|        int display_width;
   74|  32.6k|        if (sscanf(variable->format, "%%%ds", &display_width) == 1 ||
  ------------------
  |  Branch (74:13): [True: 1.08k, False: 31.5k]
  ------------------
   75|  32.6k|                sscanf(variable->format, "%%-%ds", &display_width) == 1) {
  ------------------
  |  Branch (75:17): [True: 351, False: 31.2k]
  ------------------
   76|  1.43k|            variable->display_width = display_width;
   77|  1.43k|        }
   78|  32.6k|    }
   79|       |
   80|  66.7k|    return variable;
   81|  66.7k|}
readstat_dta_read.c:dta_read_expansion_fields:
  183|  3.00k|static readstat_error_t dta_read_expansion_fields(dta_ctx_t *ctx) {
  184|  3.00k|    readstat_error_t retval = READSTAT_OK;
  185|  3.00k|    readstat_io_t *io = ctx->io;
  186|  3.00k|    char *buffer = NULL;
  187|       |
  188|  3.00k|    if (ctx->expansion_len_len == 0)
  ------------------
  |  Branch (188:9): [True: 658, False: 2.34k]
  ------------------
  189|    658|        return READSTAT_OK;
  190|       |
  191|  2.34k|    if (ctx->file_is_xmlish && !ctx->handle.note) {
  ------------------
  |  Branch (191:9): [True: 1.47k, False: 869]
  |  Branch (191:32): [True: 0, False: 1.47k]
  ------------------
  192|      0|        if (io->seek(ctx->data_offset, READSTAT_SEEK_SET, io->io_ctx) == -1) {
  ------------------
  |  Branch (192:13): [True: 0, False: 0]
  ------------------
  193|      0|            if (ctx->handle.error) {
  ------------------
  |  Branch (193:17): [True: 0, False: 0]
  ------------------
  194|      0|                snprintf(ctx->error_buf, sizeof(ctx->error_buf),
  195|      0|                        "Failed to seek to data section (offset=%" PRId64 ")",
  196|      0|                        ctx->data_offset);
  197|      0|                ctx->handle.error(ctx->error_buf, ctx->user_ctx);
  198|      0|            }
  199|      0|            return READSTAT_ERROR_SEEK;
  200|      0|        }
  201|      0|        return READSTAT_OK;
  202|      0|    }
  203|       |
  204|  2.34k|    retval = dta_read_tag(ctx, "<characteristics>");
  205|  2.34k|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (205:9): [True: 194, False: 2.15k]
  ------------------
  206|    194|        goto cleanup;
  207|       |
  208|  6.12k|    while (1) {
  ------------------
  |  Branch (208:12): [Folded - Ignored]
  ------------------
  209|  6.12k|        size_t len;
  210|  6.12k|        char data_type;
  211|       |
  212|  6.12k|        if (ctx->file_is_xmlish) {
  ------------------
  |  Branch (212:13): [True: 1.84k, False: 4.27k]
  ------------------
  213|  1.84k|            char start[4];
  214|  1.84k|            if (io->read(start, sizeof(start), io->io_ctx) != sizeof(start)) {
  ------------------
  |  Branch (214:17): [True: 11, False: 1.83k]
  ------------------
  215|     11|                retval = READSTAT_ERROR_READ;
  216|     11|                goto cleanup;
  217|     11|            }
  218|  1.83k|            if (memcmp(start, "</ch", sizeof(start)) == 0) {
  ------------------
  |  Branch (218:17): [True: 1.19k, False: 644]
  ------------------
  219|  1.19k|                retval = dta_read_tag(ctx, "aracteristics>");
  220|  1.19k|                if (retval != READSTAT_OK)
  ------------------
  |  Branch (220:21): [True: 126, False: 1.06k]
  ------------------
  221|    126|                    goto cleanup;
  222|       |
  223|  1.06k|                break;
  224|  1.19k|            } else if (memcmp(start, "<ch>", sizeof(start)) != 0) {
  ------------------
  |  Branch (224:24): [True: 18, False: 626]
  ------------------
  225|     18|                retval = READSTAT_ERROR_PARSE;
  226|     18|                goto cleanup;
  227|     18|            }
  228|    626|            data_type = 1;
  229|  4.27k|        } else {
  230|  4.27k|            if (io->read(&data_type, 1, io->io_ctx) != 1) {
  ------------------
  |  Branch (230:17): [True: 98, False: 4.17k]
  ------------------
  231|     98|                retval = READSTAT_ERROR_READ;
  232|     98|                goto cleanup;
  233|     98|            }
  234|  4.27k|        }
  235|       |
  236|  4.80k|        if (ctx->expansion_len_len == 2) {
  ------------------
  |  Branch (236:13): [True: 3.03k, False: 1.76k]
  ------------------
  237|  3.03k|            uint16_t len16;
  238|  3.03k|            if (io->read(&len16, sizeof(uint16_t), io->io_ctx) != sizeof(uint16_t)) {
  ------------------
  |  Branch (238:17): [True: 11, False: 3.02k]
  ------------------
  239|     11|                retval = READSTAT_ERROR_READ;
  240|     11|                goto cleanup;
  241|     11|            }
  242|  3.02k|            len = ctx->bswap ? byteswap2(len16) : len16;
  ------------------
  |  Branch (242:19): [True: 1.94k, False: 1.07k]
  ------------------
  243|  3.02k|        } else {
  244|  1.76k|            uint32_t len32;
  245|  1.76k|            if (io->read(&len32, sizeof(uint32_t), io->io_ctx) != sizeof(uint32_t)) {
  ------------------
  |  Branch (245:17): [True: 14, False: 1.75k]
  ------------------
  246|     14|                retval = READSTAT_ERROR_READ;
  247|     14|                goto cleanup;
  248|     14|            }
  249|  1.75k|            len = ctx->bswap ? byteswap4(len32) : len32;
  ------------------
  |  Branch (249:19): [True: 1.31k, False: 438]
  ------------------
  250|  1.75k|        }
  251|       |
  252|  4.77k|        if (data_type == 0 && len == 0)
  ------------------
  |  Branch (252:13): [True: 664, False: 4.11k]
  |  Branch (252:31): [True: 627, False: 37]
  ------------------
  253|    627|            break;
  254|       |        
  255|  4.14k|        if (data_type != 1 || len > (1<<20)) {
  ------------------
  |  Branch (255:13): [True: 55, False: 4.09k]
  |  Branch (255:31): [True: 11, False: 4.08k]
  ------------------
  256|     66|            retval = READSTAT_ERROR_NOTE_IS_TOO_LONG;
  257|     66|            goto cleanup;
  258|     66|        }
  259|       |
  260|  4.08k|        if (ctx->handle.note && len >= 2 * ctx->ch_metadata_len) {
  ------------------
  |  Branch (260:13): [True: 4.08k, False: 0]
  |  Branch (260:33): [True: 861, False: 3.22k]
  ------------------
  261|    861|            if ((buffer = readstat_realloc(buffer, len + 1)) == NULL) {
  ------------------
  |  Branch (261:17): [True: 0, False: 861]
  ------------------
  262|      0|                retval = READSTAT_ERROR_MALLOC;
  263|      0|                goto cleanup;
  264|      0|            }
  265|    861|            buffer[len] = '\0';
  266|       |
  267|    861|            if (io->read(buffer, len, io->io_ctx) != len) {
  ------------------
  |  Branch (267:17): [True: 52, False: 809]
  ------------------
  268|     52|                retval = READSTAT_ERROR_READ;
  269|     52|                goto cleanup;
  270|     52|            }
  271|    809|            int index = 0;
  272|    809|            if (strncmp(&buffer[0], "_dta", 4) == 0 &&
  ------------------
  |  Branch (272:17): [True: 414, False: 395]
  ------------------
  273|    809|                    sscanf(&buffer[ctx->ch_metadata_len], "note%d", &index) == 1) {
  ------------------
  |  Branch (273:21): [True: 203, False: 211]
  ------------------
  274|    203|                if (ctx->handle.note(index, &buffer[2*ctx->ch_metadata_len], ctx->user_ctx) != READSTAT_HANDLER_OK) {
  ------------------
  |  Branch (274:21): [True: 0, False: 203]
  ------------------
  275|      0|                    retval = READSTAT_ERROR_USER_ABORT;
  276|      0|                    goto cleanup;
  277|      0|                }
  278|    203|            }
  279|  3.22k|        } else {
  280|  3.22k|            if (io->seek(len, READSTAT_SEEK_CUR, io->io_ctx) == -1) {
  ------------------
  |  Branch (280:17): [True: 9, False: 3.21k]
  ------------------
  281|      9|                retval = READSTAT_ERROR_SEEK;
  282|      9|                goto cleanup;
  283|      9|            }
  284|  3.22k|        }
  285|       |
  286|  4.02k|        retval = dta_read_tag(ctx, "</ch>");
  287|  4.02k|        if (retval != READSTAT_OK)
  ------------------
  |  Branch (287:13): [True: 52, False: 3.96k]
  ------------------
  288|     52|            goto cleanup;
  289|  4.02k|    }
  290|       |
  291|  2.34k|cleanup:
  292|  2.34k|    if (buffer)
  ------------------
  |  Branch (292:9): [True: 132, False: 2.21k]
  ------------------
  293|    132|        free(buffer);
  294|       |
  295|  2.34k|    return retval;
  296|  2.15k|}
readstat_dta_read.c:dta_read_strls:
  403|  2.35k|static readstat_error_t dta_read_strls(dta_ctx_t *ctx) {
  404|  2.35k|    if (!ctx->file_is_xmlish)
  ------------------
  |  Branch (404:9): [True: 1.28k, False: 1.06k]
  ------------------
  405|  1.28k|        return READSTAT_OK;
  406|       |
  407|  1.06k|    readstat_error_t retval = READSTAT_OK;
  408|  1.06k|    readstat_io_t *io = ctx->io;
  409|       |
  410|  1.06k|    if (io->seek(ctx->strls_offset, READSTAT_SEEK_SET, io->io_ctx) == -1) {
  ------------------
  |  Branch (410:9): [True: 137, False: 930]
  ------------------
  411|    137|        if (ctx->handle.error) {
  ------------------
  |  Branch (411:13): [True: 0, False: 137]
  ------------------
  412|      0|            snprintf(ctx->error_buf, sizeof(ctx->error_buf), "Failed to seek to strls section (offset=%" PRId64 ")",
  413|      0|                    ctx->strls_offset);
  414|      0|            ctx->handle.error(ctx->error_buf, ctx->user_ctx);
  415|      0|        }
  416|    137|        retval = READSTAT_ERROR_SEEK;
  417|    137|        goto cleanup;
  418|    137|    }
  419|       |
  420|    930|    retval = dta_read_tag(ctx, "<strls>");
  421|    930|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (421:9): [True: 79, False: 851]
  ------------------
  422|     79|        goto cleanup;
  423|       |
  424|    851|    ctx->strls_capacity = 100;
  425|    851|    ctx->strls = readstat_malloc(ctx->strls_capacity * sizeof(dta_strl_t *));
  426|       |
  427|   207k|    while (1) {
  ------------------
  |  Branch (427:12): [Folded - Ignored]
  ------------------
  428|   207k|        char tag[3];
  429|   207k|        if (io->read(tag, sizeof(tag), io->io_ctx) != sizeof(tag)) {
  ------------------
  |  Branch (429:13): [True: 35, False: 207k]
  ------------------
  430|     35|            retval = READSTAT_ERROR_READ;
  431|     35|            goto cleanup;
  432|     35|        }
  433|       |
  434|   207k|        if (memcmp(tag, "GSO", sizeof(tag)) == 0) {
  ------------------
  |  Branch (434:13): [True: 206k, False: 743]
  ------------------
  435|   206k|            dta_strl_t strl;
  436|   206k|            retval = dta_read_strl(ctx, &strl);
  437|   206k|            if (retval != READSTAT_OK)
  ------------------
  |  Branch (437:17): [True: 17, False: 206k]
  ------------------
  438|     17|                goto cleanup;
  439|       |
  440|   206k|            if (strl.type != DTA_GSO_TYPE_ASCII)
  ------------------
  |  |  163|   206k|#define DTA_GSO_TYPE_ASCII         0x82
  ------------------
  |  Branch (440:17): [True: 994, False: 205k]
  ------------------
  441|    994|                continue;
  442|       |
  443|   205k|            if (ctx->strls_count == ctx->strls_capacity) {
  ------------------
  |  Branch (443:17): [True: 132, False: 205k]
  ------------------
  444|    132|                ctx->strls_capacity *= 2;
  445|    132|                if ((ctx->strls = readstat_realloc(ctx->strls, sizeof(dta_strl_t *) * ctx->strls_capacity)) == NULL) {
  ------------------
  |  Branch (445:21): [True: 0, False: 132]
  ------------------
  446|      0|                    retval = READSTAT_ERROR_MALLOC;
  447|      0|                    goto cleanup;
  448|      0|                }
  449|    132|            }
  450|       |
  451|   205k|            dta_strl_t *strl_ptr = readstat_malloc(sizeof(dta_strl_t) + strl.len);
  452|   205k|            if (strl_ptr == NULL) {
  ------------------
  |  Branch (452:17): [True: 11, False: 205k]
  ------------------
  453|     11|                retval = READSTAT_ERROR_MALLOC;
  454|     11|                goto cleanup;
  455|     11|            }
  456|   205k|            memcpy(strl_ptr, &strl, sizeof(dta_strl_t));
  457|       |
  458|   205k|            ctx->strls[ctx->strls_count++] = strl_ptr;
  459|       |
  460|   205k|            if (io->read(&strl_ptr->data[0], strl_ptr->len, io->io_ctx) != strl_ptr->len) {
  ------------------
  |  Branch (460:17): [True: 45, False: 205k]
  ------------------
  461|     45|                retval = READSTAT_ERROR_READ;
  462|     45|                goto cleanup;
  463|     45|            }
  464|   205k|        } else if (memcmp(tag, "</s", sizeof(tag)) == 0) {
  ------------------
  |  Branch (464:20): [True: 669, False: 74]
  ------------------
  465|    669|            retval = dta_read_tag(ctx, "trls>");
  466|    669|            if (retval != READSTAT_OK)
  ------------------
  |  Branch (466:17): [True: 44, False: 625]
  ------------------
  467|     44|                goto cleanup;
  468|    625|            break;
  469|    669|        } else {
  470|     74|            retval = READSTAT_ERROR_PARSE;
  471|     74|            goto cleanup;
  472|     74|        }
  473|   207k|    }
  474|       |
  475|  1.06k|cleanup:
  476|  1.06k|    return retval;
  477|    851|}
readstat_dta_read.c:dta_read_strl:
  396|   206k|static readstat_error_t dta_read_strl(dta_ctx_t *ctx, dta_strl_t *strl) {
  397|   206k|    if (ctx->strl_o_len > 4) {
  ------------------
  |  Branch (397:9): [True: 348, False: 206k]
  ------------------
  398|    348|        return dta_118_read_strl(ctx, strl);
  399|    348|    }
  400|   206k|    return dta_117_read_strl(ctx, strl);
  401|   206k|}
readstat_dta_read.c:dta_118_read_strl:
  377|    348|static readstat_error_t dta_118_read_strl(dta_ctx_t *ctx, dta_strl_t *strl) {
  378|    348|    readstat_error_t retval = READSTAT_OK;
  379|    348|    readstat_io_t *io = ctx->io;
  380|    348|    dta_118_strl_header_t header;
  381|       |
  382|    348|    if (io->read(&header, SIZEOF_DTA_118_STRL_HEADER_T, io->io_ctx) != SIZEOF_DTA_118_STRL_HEADER_T) {
  ------------------
  |  |   43|    348|#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|    348|#define SIZEOF_DTA_118_STRL_HEADER_T 17
  ------------------
  |  Branch (382:9): [True: 6, False: 342]
  ------------------
  383|      6|        retval = READSTAT_ERROR_READ;
  384|      6|        goto cleanup;
  385|      6|    }
  386|       |
  387|    342|    strl->v = ctx->bswap ? byteswap4(header.v) : header.v;
  ------------------
  |  Branch (387:15): [True: 0, False: 342]
  ------------------
  388|    342|    strl->o = ctx->bswap ? byteswap8(header.o) : header.o;
  ------------------
  |  Branch (388:15): [True: 0, False: 342]
  ------------------
  389|    342|    strl->type = header.type;
  390|    342|    strl->len = ctx->bswap ? byteswap4(header.len) : header.len;
  ------------------
  |  Branch (390:17): [True: 0, False: 342]
  ------------------
  391|       |
  392|    348|cleanup:
  393|    348|    return retval;
  394|    342|}
readstat_dta_read.c:dta_117_read_strl:
  358|   206k|static readstat_error_t dta_117_read_strl(dta_ctx_t *ctx, dta_strl_t *strl) {
  359|   206k|    readstat_error_t retval = READSTAT_OK;
  360|   206k|    readstat_io_t *io = ctx->io;
  361|   206k|    dta_117_strl_header_t header;
  362|       |
  363|   206k|    if (io->read(&header, SIZEOF_DTA_117_STRL_HEADER_T, io->io_ctx) != SIZEOF_DTA_117_STRL_HEADER_T) {
  ------------------
  |  |   34|   206k|#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|   206k|#define SIZEOF_DTA_117_STRL_HEADER_T 13
  ------------------
  |  Branch (363:9): [True: 11, False: 206k]
  ------------------
  364|     11|        retval = READSTAT_ERROR_READ;
  365|     11|        goto cleanup;
  366|     11|    }
  367|       |
  368|   206k|    strl->v = ctx->bswap ? byteswap4(header.v) : header.v;
  ------------------
  |  Branch (368:15): [True: 6.57k, False: 199k]
  ------------------
  369|   206k|    strl->o = ctx->bswap ? byteswap4(header.o) : header.o;
  ------------------
  |  Branch (369:15): [True: 6.57k, False: 199k]
  ------------------
  370|   206k|    strl->type = header.type;
  371|   206k|    strl->len = ctx->bswap ? byteswap4(header.len) : header.len;
  ------------------
  |  Branch (371:17): [True: 6.57k, False: 199k]
  ------------------
  372|       |
  373|   206k|cleanup:
  374|   206k|    return retval;
  375|   206k|}
readstat_dta_read.c:dta_read_data:
  700|  1.91k|static readstat_error_t dta_read_data(dta_ctx_t *ctx) {
  701|  1.91k|    readstat_error_t retval = READSTAT_OK;
  702|  1.91k|    readstat_io_t *io = ctx->io;
  703|       |
  704|  1.91k|    if (!ctx->handle.value) {
  ------------------
  |  Branch (704:9): [True: 0, False: 1.91k]
  ------------------
  705|      0|        return READSTAT_OK;
  706|      0|    }
  707|       |
  708|  1.91k|    if (io->seek(ctx->data_offset, READSTAT_SEEK_SET, io->io_ctx) == -1) {
  ------------------
  |  Branch (708:9): [True: 10, False: 1.90k]
  ------------------
  709|     10|        if (ctx->handle.error) {
  ------------------
  |  Branch (709:13): [True: 0, False: 10]
  ------------------
  710|      0|            snprintf(ctx->error_buf, sizeof(ctx->error_buf), "Failed to seek to data section (offset=%" PRId64 ")",
  711|      0|                    ctx->data_offset);
  712|      0|            ctx->handle.error(ctx->error_buf, ctx->user_ctx);
  713|      0|        }
  714|     10|        retval = READSTAT_ERROR_SEEK;
  715|     10|        goto cleanup;
  716|     10|    }
  717|       |
  718|  1.90k|    if ((retval = dta_read_tag(ctx, "<data>")) != READSTAT_OK)
  ------------------
  |  Branch (718:9): [True: 57, False: 1.84k]
  ------------------
  719|     57|        goto cleanup;
  720|       |
  721|  1.84k|    if ((retval = dta_update_progress(ctx)) != READSTAT_OK)
  ------------------
  |  Branch (721:9): [True: 0, False: 1.84k]
  ------------------
  722|      0|        goto cleanup;
  723|       |
  724|  1.84k|    if ((retval = dta_handle_rows(ctx)) != READSTAT_OK)
  ------------------
  |  Branch (724:9): [True: 931, False: 912]
  ------------------
  725|    931|        goto cleanup;
  726|       |
  727|    912|    if ((retval = dta_read_tag(ctx, "</data>")) != READSTAT_OK)
  ------------------
  |  Branch (727:9): [True: 118, False: 794]
  ------------------
  728|    118|        goto cleanup;
  729|       |
  730|  1.91k|cleanup:
  731|  1.91k|    return retval;
  732|    912|}
readstat_dta_read.c:dta_handle_rows:
  656|  1.84k|static readstat_error_t dta_handle_rows(dta_ctx_t *ctx) {
  657|  1.84k|    readstat_io_t *io = ctx->io;
  658|  1.84k|    unsigned char *buf = NULL;
  659|  1.84k|    int i;
  660|  1.84k|    readstat_error_t retval = READSTAT_OK;
  661|       |
  662|  1.84k|    if (ctx->record_len && (buf = readstat_malloc(ctx->record_len)) == NULL) {
  ------------------
  |  Branch (662:9): [True: 1.26k, False: 578]
  |  Branch (662:28): [True: 0, False: 1.26k]
  ------------------
  663|      0|        retval = READSTAT_ERROR_MALLOC;
  664|      0|        goto cleanup;
  665|      0|    }
  666|       |
  667|  1.84k|    if (ctx->row_offset) {
  ------------------
  |  Branch (667:9): [True: 103, False: 1.74k]
  ------------------
  668|    103|        if (io->seek(ctx->record_len * ctx->row_offset, READSTAT_SEEK_CUR, io->io_ctx) == -1) {
  ------------------
  |  Branch (668:13): [True: 87, False: 16]
  ------------------
  669|     87|            retval = READSTAT_ERROR_SEEK;
  670|     87|            goto cleanup;
  671|     87|        }
  672|    103|    }
  673|       |
  674|  23.9k|    for (i=0; i<ctx->row_limit; i++) {
  ------------------
  |  Branch (674:15): [True: 23.0k, False: 912]
  ------------------
  675|  23.0k|        if (io->read(buf, ctx->record_len, io->io_ctx) != ctx->record_len) {
  ------------------
  |  Branch (675:13): [True: 834, False: 22.2k]
  ------------------
  676|    834|            retval = READSTAT_ERROR_READ;
  677|    834|            goto cleanup;
  678|    834|        }
  679|  22.2k|        if ((retval = dta_handle_row(buf, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (679:13): [True: 10, False: 22.2k]
  ------------------
  680|     10|            goto cleanup;
  681|     10|        }
  682|  22.2k|        ctx->current_row++;
  683|  22.2k|        if ((retval = dta_update_progress(ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (683:13): [True: 0, False: 22.2k]
  ------------------
  684|      0|            goto cleanup;
  685|      0|        }
  686|  22.2k|    }
  687|       |
  688|    912|    if (ctx->row_limit < ctx->nobs - ctx->row_offset) {
  ------------------
  |  Branch (688:9): [True: 0, False: 912]
  ------------------
  689|      0|        if (io->seek(ctx->record_len * (ctx->nobs - ctx->row_offset - ctx->row_limit), READSTAT_SEEK_CUR, io->io_ctx) == -1)
  ------------------
  |  Branch (689:13): [True: 0, False: 0]
  ------------------
  690|      0|            retval = READSTAT_ERROR_SEEK;
  691|      0|    }
  692|       |
  693|  1.84k|cleanup:
  694|  1.84k|    if (buf)
  ------------------
  |  Branch (694:9): [True: 1.26k, False: 578]
  ------------------
  695|  1.26k|        free(buf);
  696|       |
  697|  1.84k|    return retval;
  698|    912|}
readstat_dta_read.c:dta_handle_row:
  591|  22.2k|static readstat_error_t dta_handle_row(const unsigned char *buf, dta_ctx_t *ctx) {
  592|  22.2k|    char  str_buf[2048];
  593|  22.2k|    int j;
  594|  22.2k|    readstat_off_t offset = 0;
  595|  22.2k|    readstat_error_t retval = READSTAT_OK;
  596|  45.1k|    for (j=0; j<ctx->nvar; j++) {
  ------------------
  |  Branch (596:15): [True: 22.8k, False: 22.2k]
  ------------------
  597|  22.8k|        size_t max_len;
  598|  22.8k|        readstat_value_t value = { { 0 } };
  599|       |
  600|  22.8k|        retval = dta_type_info(ctx->typlist[j], ctx, &max_len, &value.type);
  601|  22.8k|        if (retval != READSTAT_OK)
  ------------------
  |  Branch (601:13): [True: 0, False: 22.8k]
  ------------------
  602|      0|            goto cleanup;
  603|       |
  604|  22.8k|        if (ctx->variables[j]->skip) {
  ------------------
  |  Branch (604:13): [True: 0, False: 22.8k]
  ------------------
  605|      0|            offset += max_len;
  606|      0|            continue;
  607|      0|        }
  608|       |
  609|  22.8k|        if (offset + max_len > ctx->record_len) {
  ------------------
  |  Branch (609:13): [True: 0, False: 22.8k]
  ------------------
  610|      0|            retval = READSTAT_ERROR_PARSE;
  611|      0|            goto cleanup;
  612|      0|        }
  613|       |
  614|  22.8k|        if (value.type == READSTAT_TYPE_STRING) {
  ------------------
  |  Branch (614:13): [True: 3.48k, False: 19.3k]
  ------------------
  615|  3.48k|            if (max_len == 0) {
  ------------------
  |  Branch (615:17): [True: 2, False: 3.48k]
  ------------------
  616|      2|                retval = READSTAT_ERROR_PARSE;
  617|      2|                goto cleanup;
  618|      2|            }
  619|  3.48k|            size_t str_len = strnlen((const char *)&buf[offset], max_len);
  620|  3.48k|            retval = readstat_convert(str_buf, sizeof(str_buf),
  621|  3.48k|                    (const char *)&buf[offset], str_len, ctx->converter);
  622|  3.48k|            if (retval != READSTAT_OK)
  ------------------
  |  Branch (622:17): [True: 8, False: 3.47k]
  ------------------
  623|      8|                goto cleanup;
  624|  3.47k|            value.v.string_value = str_buf;
  625|  19.3k|        } else if (value.type == READSTAT_TYPE_STRING_REF) {
  ------------------
  |  Branch (625:20): [True: 10.4k, False: 8.94k]
  ------------------
  626|  10.4k|            dta_strl_t key = dta_interpret_strl_vo_bytes(ctx, &buf[offset]);
  627|  10.4k|            dta_strl_t **found = bsearch(&key, ctx->strls, ctx->strls_count, sizeof(dta_strl_t *), &dta_compare_strls);
  628|       |
  629|  10.4k|            if (found) {
  ------------------
  |  Branch (629:17): [True: 2.33k, False: 8.10k]
  ------------------
  630|  2.33k|                value.v.string_value = (*found)->data;
  631|  2.33k|            }
  632|  10.4k|            value.type = READSTAT_TYPE_STRING;
  633|  10.4k|        } else if (value.type == READSTAT_TYPE_INT8) {
  ------------------
  |  Branch (633:20): [True: 2.72k, False: 6.22k]
  ------------------
  634|  2.72k|            value = dta_interpret_int8_bytes(ctx, &buf[offset]);
  635|  6.22k|        } else if (value.type == READSTAT_TYPE_INT16) {
  ------------------
  |  Branch (635:20): [True: 1.65k, False: 4.57k]
  ------------------
  636|  1.65k|            value = dta_interpret_int16_bytes(ctx, &buf[offset]);
  637|  4.57k|        } else if (value.type == READSTAT_TYPE_INT32) {
  ------------------
  |  Branch (637:20): [True: 1.43k, False: 3.13k]
  ------------------
  638|  1.43k|            value = dta_interpret_int32_bytes(ctx, &buf[offset]);
  639|  3.13k|        } else if (value.type == READSTAT_TYPE_FLOAT) {
  ------------------
  |  Branch (639:20): [True: 1.53k, False: 1.59k]
  ------------------
  640|  1.53k|            value = dta_interpret_float_bytes(ctx, &buf[offset]);
  641|  1.59k|        } else if (value.type == READSTAT_TYPE_DOUBLE) {
  ------------------
  |  Branch (641:20): [True: 1.59k, False: 0]
  ------------------
  642|  1.59k|            value = dta_interpret_double_bytes(ctx, &buf[offset]);
  643|  1.59k|        }
  644|       |
  645|  22.8k|        if (ctx->handle.value(ctx->current_row, ctx->variables[j], value, ctx->user_ctx) != READSTAT_HANDLER_OK) {
  ------------------
  |  Branch (645:13): [True: 0, False: 22.8k]
  ------------------
  646|      0|            retval = READSTAT_ERROR_USER_ABORT;
  647|      0|            goto cleanup;
  648|      0|        }
  649|       |
  650|  22.8k|        offset += max_len;
  651|  22.8k|    }
  652|  22.2k|cleanup:
  653|  22.2k|    return retval;
  654|  22.2k|}
readstat_dta_read.c:dta_interpret_strl_vo_bytes:
  326|  10.4k|static dta_strl_t dta_interpret_strl_vo_bytes(dta_ctx_t *ctx, const unsigned char *vo_bytes) {
  327|  10.4k|    dta_strl_t strl = {0};
  328|       |
  329|  10.4k|    if (ctx->strl_v_len == 2) {
  ------------------
  |  Branch (329:9): [True: 1.07k, False: 9.35k]
  ------------------
  330|  1.07k|        if (ctx->endianness == READSTAT_ENDIAN_BIG) {
  ------------------
  |  Branch (330:13): [True: 0, False: 1.07k]
  ------------------
  331|      0|            strl.v = (vo_bytes[0] << 8) + vo_bytes[1];
  332|      0|            strl.o = (((uint64_t)vo_bytes[2] << 40)
  333|      0|                    + ((uint64_t)vo_bytes[3] << 32)
  334|      0|                    + ((uint64_t)vo_bytes[4] << 24)
  335|      0|                    + (vo_bytes[5] << 16)
  336|      0|                    + (vo_bytes[6] << 8)
  337|      0|                    + vo_bytes[7]);
  338|  1.07k|        } else {
  339|  1.07k|            strl.v = vo_bytes[0] + (vo_bytes[1] << 8);
  340|  1.07k|            strl.o = (vo_bytes[2] + (vo_bytes[3] << 8)
  341|  1.07k|                    + (vo_bytes[4] << 16)
  342|  1.07k|                    + ((uint64_t)vo_bytes[5] << 24)
  343|  1.07k|                    + ((uint64_t)vo_bytes[6] << 32)
  344|  1.07k|                    + ((uint64_t)vo_bytes[7] << 40));
  345|  1.07k|        }
  346|  9.35k|    } else if (ctx->strl_v_len == 4) {
  ------------------
  |  Branch (346:16): [True: 9.35k, False: 0]
  ------------------
  347|  9.35k|        uint32_t v, o;
  348|       |
  349|  9.35k|        memcpy(&v, &vo_bytes[0], sizeof(uint32_t));
  350|  9.35k|        memcpy(&o, &vo_bytes[4], sizeof(uint32_t));
  351|       |
  352|  9.35k|        strl.v = ctx->bswap ? byteswap4(v) : v;
  ------------------
  |  Branch (352:18): [True: 200, False: 9.15k]
  ------------------
  353|  9.35k|        strl.o = ctx->bswap ? byteswap4(o) : o;
  ------------------
  |  Branch (353:18): [True: 200, False: 9.15k]
  ------------------
  354|  9.35k|    }
  355|  10.4k|    return strl;
  356|  10.4k|}
readstat_dta_read.c:dta_compare_strls:
  317|  42.1k|static int dta_compare_strls(const void *elem1, const void *elem2) {
  318|  42.1k|    const dta_strl_t *key = (const dta_strl_t *)elem1;
  319|  42.1k|    const dta_strl_t *target = *(const dta_strl_t **)elem2;
  320|  42.1k|    if (key->o == target->o)
  ------------------
  |  Branch (320:9): [True: 3.13k, False: 39.0k]
  ------------------
  321|  3.13k|        return key->v - target->v;
  322|       |
  323|  39.0k|    return key->o - target->o;
  324|  42.1k|}
readstat_dta_read.c:dta_interpret_int8_bytes:
  479|  2.72k|static readstat_value_t dta_interpret_int8_bytes(dta_ctx_t *ctx, const void *buf) {
  480|  2.72k|    readstat_value_t value = { .type = READSTAT_TYPE_INT8 };
  481|  2.72k|    int8_t byte = 0;
  482|  2.72k|    memcpy(&byte, buf, sizeof(int8_t));
  483|  2.72k|    if (ctx->machine_is_twos_complement) {
  ------------------
  |  Branch (483:9): [True: 0, False: 2.72k]
  ------------------
  484|      0|        byte = ones_to_twos_complement1(byte);
  485|      0|    }
  486|  2.72k|    if (byte > ctx->max_int8) {
  ------------------
  |  Branch (486:9): [True: 902, False: 1.82k]
  ------------------
  487|    902|        if (ctx->supports_tagged_missing && byte > DTA_113_MISSING_INT8) {
  ------------------
  |  |  150|    696|#define DTA_113_MISSING_INT8                 0x65
  ------------------
  |  Branch (487:13): [True: 696, False: 206]
  |  Branch (487:45): [True: 468, False: 228]
  ------------------
  488|    468|            value.tag = 'a' + (byte - DTA_113_MISSING_INT8_A);
  ------------------
  |  |  156|    468|#define DTA_113_MISSING_INT8_A    (DTA_113_MISSING_INT8+1)
  |  |  ------------------
  |  |  |  |  150|    468|#define DTA_113_MISSING_INT8                 0x65
  |  |  ------------------
  ------------------
  489|    468|            value.is_tagged_missing = 1;
  490|    468|        } else {
  491|    434|            value.is_system_missing = 1;
  492|    434|        }
  493|    902|    }
  494|  2.72k|    value.v.i8_value = byte;
  495|       |
  496|  2.72k|    return value;
  497|  2.72k|}
readstat_dta_read.c:dta_interpret_int16_bytes:
  499|  1.65k|static readstat_value_t dta_interpret_int16_bytes(dta_ctx_t *ctx, const void *buf) {
  500|  1.65k|    readstat_value_t value = { .type = READSTAT_TYPE_INT16 };
  501|  1.65k|    int16_t num = 0;
  502|  1.65k|    memcpy(&num, buf, sizeof(int16_t));
  503|  1.65k|    if (ctx->bswap) {
  ------------------
  |  Branch (503:9): [True: 406, False: 1.24k]
  ------------------
  504|    406|        num = byteswap2(num);
  505|    406|    }
  506|  1.65k|    if (ctx->machine_is_twos_complement) {
  ------------------
  |  Branch (506:9): [True: 0, False: 1.65k]
  ------------------
  507|      0|        num = ones_to_twos_complement2(num);
  508|      0|    }
  509|  1.65k|    if (num > ctx->max_int16) {
  ------------------
  |  Branch (509:9): [True: 590, False: 1.06k]
  ------------------
  510|    590|        if (ctx->supports_tagged_missing && num > DTA_113_MISSING_INT16) {
  ------------------
  |  |  151|    395|#define DTA_113_MISSING_INT16              0x7FE5
  ------------------
  |  Branch (510:13): [True: 395, False: 195]
  |  Branch (510:45): [True: 201, False: 194]
  ------------------
  511|    201|            value.tag = 'a' + (num - DTA_113_MISSING_INT16_A);
  ------------------
  |  |  157|    201|#define DTA_113_MISSING_INT16_A   (DTA_113_MISSING_INT16+1)
  |  |  ------------------
  |  |  |  |  151|    201|#define DTA_113_MISSING_INT16              0x7FE5
  |  |  ------------------
  ------------------
  512|    201|            value.is_tagged_missing = 1;
  513|    389|        } else {
  514|    389|            value.is_system_missing = 1;
  515|    389|        }
  516|    590|    }
  517|  1.65k|    value.v.i16_value = num;
  518|       |
  519|  1.65k|    return value;
  520|  1.65k|}
readstat_dta_read.c:dta_interpret_int32_bytes:
  522|  3.34k|static readstat_value_t dta_interpret_int32_bytes(dta_ctx_t *ctx, const void *buf) {
  523|  3.34k|    readstat_value_t value = { .type = READSTAT_TYPE_INT32 };
  524|  3.34k|    int32_t num = 0;
  525|  3.34k|    memcpy(&num, buf, sizeof(int32_t));
  526|  3.34k|    if (ctx->bswap) {
  ------------------
  |  Branch (526:9): [True: 1.59k, False: 1.75k]
  ------------------
  527|  1.59k|        num = byteswap4(num);
  528|  1.59k|    }
  529|  3.34k|    if (ctx->machine_is_twos_complement) {
  ------------------
  |  Branch (529:9): [True: 0, False: 3.34k]
  ------------------
  530|      0|        num = ones_to_twos_complement4(num);
  531|      0|    }
  532|  3.34k|    if (num > ctx->max_int32) {
  ------------------
  |  Branch (532:9): [True: 1.19k, False: 2.14k]
  ------------------
  533|  1.19k|        if (ctx->supports_tagged_missing && num > DTA_113_MISSING_INT32) {
  ------------------
  |  |  152|    789|#define DTA_113_MISSING_INT32          0x7FFFFFE5
  ------------------
  |  Branch (533:13): [True: 789, False: 410]
  |  Branch (533:45): [True: 398, False: 391]
  ------------------
  534|    398|            value.tag = 'a' + (num - DTA_113_MISSING_INT32_A);
  ------------------
  |  |  158|    398|#define DTA_113_MISSING_INT32_A   (DTA_113_MISSING_INT32+1)
  |  |  ------------------
  |  |  |  |  152|    398|#define DTA_113_MISSING_INT32          0x7FFFFFE5
  |  |  ------------------
  ------------------
  535|    398|            value.is_tagged_missing = 1;
  536|    801|        } else {
  537|    801|            value.is_system_missing = 1;
  538|    801|        }
  539|  1.19k|    }
  540|  3.34k|    value.v.i32_value = num;
  541|       |
  542|  3.34k|    return value;
  543|  3.34k|}
readstat_dta_read.c:dta_interpret_float_bytes:
  545|  1.53k|static readstat_value_t dta_interpret_float_bytes(dta_ctx_t *ctx, const void *buf) {
  546|  1.53k|    readstat_value_t value = { .type = READSTAT_TYPE_FLOAT };
  547|  1.53k|    float f_num = NAN;
  548|  1.53k|    int32_t num = 0;
  549|  1.53k|    memcpy(&num, buf, sizeof(int32_t));
  550|  1.53k|    if (ctx->bswap) {
  ------------------
  |  Branch (550:9): [True: 449, False: 1.08k]
  ------------------
  551|    449|        num = byteswap4(num);
  552|    449|    }
  553|  1.53k|    if (num > ctx->max_float) {
  ------------------
  |  Branch (553:9): [True: 642, False: 892]
  ------------------
  554|    642|        if (ctx->supports_tagged_missing && num > DTA_113_MISSING_FLOAT) {
  ------------------
  |  |  153|    415|#define DTA_113_MISSING_FLOAT          0x7F000000
  ------------------
  |  Branch (554:13): [True: 415, False: 227]
  |  Branch (554:45): [True: 221, False: 194]
  ------------------
  555|    221|            value.tag = 'a' + ((num - DTA_113_MISSING_FLOAT_A) >> 11);
  ------------------
  |  |  159|    221|#define DTA_113_MISSING_FLOAT_A   (DTA_113_MISSING_FLOAT+0x0800)
  |  |  ------------------
  |  |  |  |  153|    221|#define DTA_113_MISSING_FLOAT          0x7F000000
  |  |  ------------------
  ------------------
  556|    221|            value.is_tagged_missing = 1;
  557|    421|        } else {
  558|    421|            value.is_system_missing = 1;
  559|    421|        }
  560|    892|    } else {
  561|    892|        memcpy(&f_num, &num, sizeof(int32_t));
  562|    892|    }
  563|  1.53k|    value.v.float_value = f_num;
  564|       |
  565|  1.53k|    return value;
  566|  1.53k|}
readstat_dta_read.c:dta_interpret_double_bytes:
  568|  1.59k|static readstat_value_t dta_interpret_double_bytes(dta_ctx_t *ctx, const void *buf) {
  569|  1.59k|    readstat_value_t value = { .type = READSTAT_TYPE_DOUBLE };
  570|  1.59k|    double d_num = NAN;
  571|  1.59k|    int64_t num = 0;
  572|  1.59k|    memcpy(&num, buf, sizeof(int64_t));
  573|  1.59k|    if (ctx->bswap) {
  ------------------
  |  Branch (573:9): [True: 397, False: 1.20k]
  ------------------
  574|    397|        num = byteswap8(num);
  575|    397|    }
  576|  1.59k|    if (num > ctx->max_double) {
  ------------------
  |  Branch (576:9): [True: 725, False: 874]
  ------------------
  577|    725|        if (ctx->supports_tagged_missing && num > DTA_113_MISSING_DOUBLE) {
  ------------------
  |  |  154|    446|#define DTA_113_MISSING_DOUBLE 0x7FE0000000000000L
  ------------------
  |  Branch (577:13): [True: 446, False: 279]
  |  Branch (577:45): [True: 252, False: 194]
  ------------------
  578|    252|            value.tag = 'a' + ((num - DTA_113_MISSING_DOUBLE_A) >> 40);
  ------------------
  |  |  160|    252|#define DTA_113_MISSING_DOUBLE_A  (DTA_113_MISSING_DOUBLE+0x010000000000)
  |  |  ------------------
  |  |  |  |  154|    252|#define DTA_113_MISSING_DOUBLE 0x7FE0000000000000L
  |  |  ------------------
  ------------------
  579|    252|            value.is_tagged_missing = 1;
  580|    473|        } else {
  581|    473|            value.is_system_missing = 1;
  582|    473|        }
  583|    874|    } else {
  584|    874|        memcpy(&d_num, &num, sizeof(int64_t));
  585|    874|    }
  586|  1.59k|    value.v.double_value = d_num;
  587|       |
  588|  1.59k|    return value;
  589|  1.59k|}
readstat_dta_read.c:dta_handle_value_labels:
  979|    794|static readstat_error_t dta_handle_value_labels(dta_ctx_t *ctx) {
  980|    794|    readstat_io_t *io = ctx->io;
  981|    794|    readstat_error_t retval = READSTAT_OK;
  982|    794|    char *table_buffer = NULL;
  983|    794|    char *utf8_buffer = NULL;
  984|       |
  985|    794|    if (io->seek(ctx->value_labels_offset, READSTAT_SEEK_SET, io->io_ctx) == -1) {
  ------------------
  |  Branch (985:9): [True: 2, False: 792]
  ------------------
  986|      2|        if (ctx->handle.error) {
  ------------------
  |  Branch (986:13): [True: 0, False: 2]
  ------------------
  987|      0|            snprintf(ctx->error_buf, sizeof(ctx->error_buf), "Failed to seek to value labels section (offset=%" PRId64 ")",
  988|      0|                    ctx->value_labels_offset);
  989|      0|            ctx->handle.error(ctx->error_buf, ctx->user_ctx);
  990|      0|        }
  991|      2|        retval = READSTAT_ERROR_SEEK;
  992|      2|        goto cleanup;
  993|      2|    }
  994|    792|    if ((retval = dta_read_tag(ctx, "<value_labels>")) != READSTAT_OK) {
  ------------------
  |  Branch (994:9): [True: 129, False: 663]
  ------------------
  995|    129|        goto cleanup;
  996|    129|    }
  997|       |
  998|    663|    if (!ctx->handle.value_label) {
  ------------------
  |  Branch (998:9): [True: 0, False: 663]
  ------------------
  999|      0|        return READSTAT_OK;
 1000|      0|    }
 1001|       |
 1002|  7.03k|    while (1) {
  ------------------
  |  Branch (1002:12): [Folded - Ignored]
  ------------------
 1003|  7.03k|        size_t len = 0;
 1004|  7.03k|        char labname[129];
 1005|  7.03k|        uint32_t i = 0, n = 0;
 1006|       |
 1007|  7.03k|        if (ctx->value_label_table_len_len == 2) {
  ------------------
  |  Branch (1007:13): [True: 4.13k, False: 2.90k]
  ------------------
 1008|  4.13k|            int16_t table_header_len;
 1009|  4.13k|            if (io->read(&table_header_len, sizeof(int16_t), io->io_ctx) < sizeof(int16_t))
  ------------------
  |  Branch (1009:17): [True: 58, False: 4.07k]
  ------------------
 1010|     58|                break;
 1011|       |
 1012|  4.07k|            len = table_header_len;
 1013|       |
 1014|  4.07k|            if (ctx->bswap)
  ------------------
  |  Branch (1014:17): [True: 3.63k, False: 436]
  ------------------
 1015|  3.63k|                len = byteswap2(table_header_len);
 1016|       |
 1017|  4.07k|            n = len / 8;
 1018|  4.07k|        } else {
 1019|  2.90k|            if (dta_read_tag(ctx, "<lbl>") != READSTAT_OK) {
  ------------------
  |  Branch (1019:17): [True: 53, False: 2.84k]
  ------------------
 1020|     53|                break;
 1021|     53|            }
 1022|       |
 1023|  2.84k|            int32_t table_header_len;
 1024|  2.84k|            if (io->read(&table_header_len, sizeof(int32_t), io->io_ctx) < sizeof(int32_t))
  ------------------
  |  Branch (1024:17): [True: 215, False: 2.63k]
  ------------------
 1025|    215|                break;
 1026|       |
 1027|  2.63k|            len = table_header_len;
 1028|       |
 1029|  2.63k|            if (ctx->bswap)
  ------------------
  |  Branch (1029:17): [True: 1.25k, False: 1.37k]
  ------------------
 1030|  1.25k|                len = byteswap4(table_header_len);
 1031|  2.63k|        }
 1032|       |
 1033|  6.70k|        if (io->read(labname, ctx->value_label_table_labname_len, io->io_ctx) < ctx->value_label_table_labname_len)
  ------------------
  |  Branch (1033:13): [True: 41, False: 6.66k]
  ------------------
 1034|     41|            break;
 1035|       |
 1036|  6.66k|        if (io->seek(ctx->value_label_table_padding_len, READSTAT_SEEK_CUR, io->io_ctx) == -1)
  ------------------
  |  Branch (1036:13): [True: 2, False: 6.66k]
  ------------------
 1037|      2|            break;
 1038|       |
 1039|  6.66k|        if ((table_buffer = readstat_realloc(table_buffer, len)) == NULL) {
  ------------------
  |  Branch (1039:13): [True: 48, False: 6.61k]
  ------------------
 1040|     48|            retval = READSTAT_ERROR_MALLOC;
 1041|     48|            goto cleanup;
 1042|     48|        }
 1043|       |
 1044|  6.61k|        if (io->read(table_buffer, len, io->io_ctx) < len) {
  ------------------
  |  Branch (1044:13): [True: 67, False: 6.55k]
  ------------------
 1045|     67|            break;
 1046|     67|        }
 1047|       |
 1048|  6.55k|        if (ctx->value_label_table_len_len == 2) {
  ------------------
  |  Branch (1048:13): [True: 3.99k, False: 2.55k]
  ------------------
 1049|   328k|            for (i=0; i<n; i++) {
  ------------------
  |  Branch (1049:23): [True: 324k, False: 3.98k]
  ------------------
 1050|   324k|                readstat_value_t value = { .v = { .i32_value = i }, .type = READSTAT_TYPE_INT32 };
 1051|   324k|                char label_buf[4*8+1];
 1052|       |
 1053|   324k|                retval = readstat_convert(label_buf, sizeof(label_buf),
 1054|   324k|                        &table_buffer[8*i], strnlen(&table_buffer[8*i], 8), ctx->converter);
 1055|   324k|                if (retval != READSTAT_OK)
  ------------------
  |  Branch (1055:21): [True: 9, False: 324k]
  ------------------
 1056|      9|                    goto cleanup;
 1057|       |
 1058|   324k|                if (label_buf[0] && ctx->handle.value_label(labname, value, label_buf, ctx->user_ctx) != READSTAT_HANDLER_OK) {
  ------------------
  |  Branch (1058:21): [True: 319k, False: 4.27k]
  |  Branch (1058:37): [True: 0, False: 319k]
  ------------------
 1059|      0|                    retval = READSTAT_ERROR_USER_ABORT;
 1060|      0|                    goto cleanup;
 1061|      0|                }
 1062|   324k|            }
 1063|  3.99k|        } else if (len >= 8) {
  ------------------
  |  Branch (1063:20): [True: 1.74k, False: 813]
  ------------------
 1064|  1.74k|            if ((retval = dta_read_tag(ctx, "</lbl>")) != READSTAT_OK) {
  ------------------
  |  Branch (1064:17): [True: 4, False: 1.73k]
  ------------------
 1065|      4|                goto cleanup;
 1066|      4|            }
 1067|       |
 1068|  1.73k|            n = *(uint32_t *)table_buffer;
 1069|       |
 1070|  1.73k|            uint32_t txtlen = *((uint32_t *)table_buffer+1);
 1071|  1.73k|            if (ctx->bswap) {
  ------------------
  |  Branch (1071:17): [True: 642, False: 1.09k]
  ------------------
 1072|    642|                n = byteswap4(n);
 1073|    642|                txtlen = byteswap4(txtlen);
 1074|    642|            }
 1075|       |
 1076|  1.73k|            if (txtlen > len - 8 || n > (len - 8 - txtlen) / 8) {
  ------------------
  |  Branch (1076:17): [True: 37, False: 1.70k]
  |  Branch (1076:37): [True: 29, False: 1.67k]
  ------------------
 1077|     66|                break;
 1078|     66|            }
 1079|       |
 1080|  1.67k|            uint32_t *off = (uint32_t *)table_buffer+2;
 1081|  1.67k|            uint32_t *val = (uint32_t *)table_buffer+2+n;
 1082|  1.67k|            char *txt = &table_buffer[8LL*n+8];
 1083|  1.67k|            size_t utf8_buffer_len = 4*txtlen+1;
 1084|  1.67k|            if (txtlen > MAX_VALUE_LABEL_LEN+1)
  ------------------
  |  |   21|  1.67k|#define MAX_VALUE_LABEL_LEN 32000
  ------------------
  |  Branch (1084:17): [True: 17, False: 1.65k]
  ------------------
 1085|     17|                utf8_buffer_len = 4*MAX_VALUE_LABEL_LEN+1;
  ------------------
  |  |   21|     17|#define MAX_VALUE_LABEL_LEN 32000
  ------------------
 1086|       |
 1087|  1.67k|            utf8_buffer = realloc(utf8_buffer, utf8_buffer_len);
 1088|       |            /* Much bigger than we need but whatever */
 1089|  1.67k|            if (utf8_buffer == NULL) {
  ------------------
  |  Branch (1089:17): [True: 0, False: 1.67k]
  ------------------
 1090|      0|                retval = READSTAT_ERROR_MALLOC;
 1091|      0|                goto cleanup;
 1092|      0|            }
 1093|       |
 1094|  1.67k|            if (ctx->bswap) {
  ------------------
  |  Branch (1094:17): [True: 616, False: 1.05k]
  ------------------
 1095|   202k|                for (i=0; i<n; i++) {
  ------------------
  |  Branch (1095:27): [True: 202k, False: 616]
  ------------------
 1096|   202k|                    off[i] = byteswap4(off[i]);
 1097|   202k|                }
 1098|    616|            }
 1099|       |
 1100|  3.56k|            for (i=0; i<n; i++) {
  ------------------
  |  Branch (1100:23): [True: 1.99k, False: 1.57k]
  ------------------
 1101|  1.99k|                if (off[i] >= txtlen) {
  ------------------
  |  Branch (1101:21): [True: 90, False: 1.90k]
  ------------------
 1102|     90|                    retval = READSTAT_ERROR_PARSE;
 1103|     90|                    goto cleanup;
 1104|     90|                }
 1105|       |
 1106|  1.90k|                readstat_value_t value = dta_interpret_int32_bytes(ctx, &val[i]);
 1107|  1.90k|                size_t max_label_len = txtlen - off[i];
 1108|  1.90k|                if (max_label_len > MAX_VALUE_LABEL_LEN)
  ------------------
  |  |   21|  1.90k|#define MAX_VALUE_LABEL_LEN 32000
  ------------------
  |  Branch (1108:21): [True: 337, False: 1.56k]
  ------------------
 1109|    337|                    max_label_len = MAX_VALUE_LABEL_LEN;
  ------------------
  |  |   21|    337|#define MAX_VALUE_LABEL_LEN 32000
  ------------------
 1110|  1.90k|                size_t label_len = strnlen(&txt[off[i]], max_label_len);
 1111|       |
 1112|  1.90k|                retval = readstat_convert(utf8_buffer, utf8_buffer_len, &txt[off[i]], label_len, ctx->converter);
 1113|  1.90k|                if (retval != READSTAT_OK)
  ------------------
  |  Branch (1113:21): [True: 10, False: 1.89k]
  ------------------
 1114|     10|                    goto cleanup;
 1115|       |
 1116|  1.89k|                if (ctx->handle.value_label(labname, value, utf8_buffer, ctx->user_ctx) != READSTAT_HANDLER_OK) {
  ------------------
  |  Branch (1116:21): [True: 0, False: 1.89k]
  ------------------
 1117|      0|                    retval = READSTAT_ERROR_USER_ABORT;
 1118|      0|                    goto cleanup;
 1119|      0|                }
 1120|  1.89k|            }
 1121|  1.67k|        }
 1122|  6.55k|    }
 1123|       |
 1124|    794|cleanup:
 1125|    794|    if (table_buffer)
  ------------------
  |  Branch (1125:9): [True: 510, False: 284]
  ------------------
 1126|    510|        free(table_buffer);
 1127|    794|    if (utf8_buffer)
  ------------------
  |  Branch (1127:9): [True: 274, False: 520]
  ------------------
 1128|    274|        free(utf8_buffer);
 1129|       |
 1130|    794|    return retval;
 1131|    663|}

rt_open_handler:
    8|  4.39k|int rt_open_handler(const char *path, void *io_ctx) {
    9|  4.39k|    return 0;
   10|  4.39k|}
rt_close_handler:
   12|  4.39k|int rt_close_handler(void *io_ctx) {
   13|  4.39k|    return 0;
   14|  4.39k|}
rt_seek_handler:
   17|  23.8k|        readstat_io_flags_t whence, void *io_ctx) {
   18|  23.8k|    rt_buffer_ctx_t *buffer_ctx = (rt_buffer_ctx_t *)io_ctx;
   19|  23.8k|    readstat_off_t newpos = -1;
   20|  23.8k|    if (whence == READSTAT_SEEK_SET) {
  ------------------
  |  Branch (20:9): [True: 8.16k, False: 15.6k]
  ------------------
   21|  8.16k|        newpos = offset;
   22|  15.6k|    } else if (whence == READSTAT_SEEK_CUR) {
  ------------------
  |  Branch (22:16): [True: 11.2k, False: 4.39k]
  ------------------
   23|  11.2k|        newpos = buffer_ctx->pos + offset;
   24|  11.2k|    } else if (whence == READSTAT_SEEK_END) {
  ------------------
  |  Branch (24:16): [True: 4.39k, False: 0]
  ------------------
   25|  4.39k|        newpos = buffer_ctx->buffer->used + offset;
   26|  4.39k|    }
   27|       |
   28|  23.8k|    if (newpos < 0)
  ------------------
  |  Branch (28:9): [True: 138, False: 23.7k]
  ------------------
   29|    138|        return -1;
   30|       |
   31|  23.7k|    if (newpos > buffer_ctx->buffer->used)
  ------------------
  |  Branch (31:9): [True: 109, False: 23.5k]
  ------------------
   32|    109|        return -1;
   33|       |
   34|  23.5k|    buffer_ctx->pos = newpos;
   35|  23.5k|    return newpos;
   36|  23.7k|}
rt_read_handler:
   38|   757k|ssize_t rt_read_handler(void *buf, size_t nbytes, void *io_ctx) {
   39|   757k|    rt_buffer_ctx_t *buffer_ctx = (rt_buffer_ctx_t *)io_ctx;
   40|   757k|    ssize_t bytes_copied = 0;
   41|   757k|    ssize_t bytes_left = buffer_ctx->buffer->used - buffer_ctx->pos;
   42|   757k|    if (nbytes <= bytes_left) {
  ------------------
  |  Branch (42:9): [True: 755k, False: 2.11k]
  ------------------
   43|   755k|        memcpy(buf, buffer_ctx->buffer->bytes + buffer_ctx->pos, nbytes);
   44|   755k|        bytes_copied = nbytes;
   45|   755k|    } else if (bytes_left > 0) {
  ------------------
  |  Branch (45:16): [True: 280, False: 1.83k]
  ------------------
   46|    280|        memcpy(buf, buffer_ctx->buffer->bytes + buffer_ctx->pos, bytes_left);
   47|    280|        bytes_copied = bytes_left;
   48|    280|    }
   49|   757k|    buffer_ctx->pos += bytes_copied;
   50|   757k|    return bytes_copied;
   51|   757k|}

