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

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

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

readstat_convert:
    7|   219k|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|   223k|    while (src_len && (src[src_len-1] == ' ' || src[src_len-1] == '\0')) {
  ------------------
  |  Branch (10:12): [True: 194k, False: 29.1k]
  |  Branch (10:24): [True: 2.69k, False: 191k]
  |  Branch (10:49): [True: 1.52k, False: 190k]
  ------------------
   11|  4.21k|        src_len--;
   12|  4.21k|    }
   13|   219k|    if (dst_len == 0) {
  ------------------
  |  Branch (13:9): [True: 0, False: 219k]
  ------------------
   14|      0|        return READSTAT_ERROR_CONVERT_LONG_STRING;
   15|   219k|    } else if (converter) {
  ------------------
  |  Branch (15:16): [True: 217k, False: 2.29k]
  ------------------
   16|   217k|        size_t dst_left = dst_len - 1;
   17|   217k|        char *dst_end = dst;
   18|   217k|        size_t status = iconv(converter, (readstat_iconv_inbuf_t)&src, &src_len, &dst_end, &dst_left);
   19|   217k|        if (status == (size_t)-1) {
  ------------------
  |  Branch (19:13): [True: 1.45k, False: 215k]
  ------------------
   20|  1.45k|            if (errno == E2BIG) {
  ------------------
  |  Branch (20:17): [True: 1, False: 1.45k]
  ------------------
   21|      1|                return READSTAT_ERROR_CONVERT_LONG_STRING;
   22|  1.45k|            } else if (errno == EILSEQ) {
  ------------------
  |  Branch (22:24): [True: 1.45k, False: 0]
  ------------------
   23|  1.45k|                return READSTAT_ERROR_CONVERT_BAD_STRING;
   24|  1.45k|            } 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.45k|        }
   28|   215k|        dst[dst_len - dst_left - 1] = '\0';
   29|   215k|    } else if (src_len + 1 > dst_len) {
  ------------------
  |  Branch (29:16): [True: 15, False: 2.27k]
  ------------------
   30|     15|        return READSTAT_ERROR_CONVERT_LONG_STRING;
   31|  2.27k|    } else {
   32|  2.27k|        memcpy(dst, src, src_len);
   33|  2.27k|        dst[src_len] = '\0';
   34|  2.27k|    }
   35|   217k|    return READSTAT_OK;
   36|   219k|}

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

readstat_malloc:
   10|   137k|void *readstat_malloc(size_t len) {
   11|   137k|    if (len > MAX_MALLOC_SIZE || len == 0) {
  ------------------
  |  |    3|   274k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
  |  Branch (11:9): [True: 36, False: 137k]
  |  Branch (11:34): [True: 0, False: 137k]
  ------------------
   12|     36|        return NULL;
   13|     36|    }
   14|   137k|    return malloc(len);
   15|   137k|}
readstat_calloc:
   17|  2.89k|void *readstat_calloc(size_t count, size_t size) {
   18|  2.89k|    if (count > MAX_MALLOC_SIZE || size > MAX_MALLOC_SIZE || count * size > MAX_MALLOC_SIZE) {
  ------------------
  |  |    3|  5.78k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
                  if (count > MAX_MALLOC_SIZE || size > MAX_MALLOC_SIZE || count * size > MAX_MALLOC_SIZE) {
  ------------------
  |  |    3|  5.73k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
                  if (count > MAX_MALLOC_SIZE || size > MAX_MALLOC_SIZE || count * size > MAX_MALLOC_SIZE) {
  ------------------
  |  |    3|  2.84k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
  |  Branch (18:9): [True: 53, False: 2.84k]
  |  Branch (18:36): [True: 0, False: 2.84k]
  |  Branch (18:62): [True: 19, False: 2.82k]
  ------------------
   19|     72|        return NULL;
   20|     72|    }
   21|  2.82k|    if (count == 0 || size == 0) {
  ------------------
  |  Branch (21:9): [True: 0, False: 2.82k]
  |  Branch (21:23): [True: 0, False: 2.82k]
  ------------------
   22|      0|        return NULL;
   23|      0|    }
   24|  2.82k|    return calloc(count, size);
   25|  2.82k|}
readstat_realloc:
   27|  6.55k|void *readstat_realloc(void *ptr, size_t len) {
   28|  6.55k|    if (len > MAX_MALLOC_SIZE || len == 0) {
  ------------------
  |  |    3|  13.1k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
  |  Branch (28:9): [True: 44, False: 6.50k]
  |  Branch (28:34): [True: 5, False: 6.50k]
  ------------------
   29|     49|        if (ptr)
  ------------------
  |  Branch (29:13): [True: 7, False: 42]
  ------------------
   30|      7|            free(ptr);
   31|     49|        return NULL;
   32|     49|    }
   33|  6.50k|    return realloc(ptr, len);
   34|  6.55k|}

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

dta_ctx_alloc:
   17|  4.28k|dta_ctx_t *dta_ctx_alloc(readstat_io_t *io) {
   18|  4.28k|    dta_ctx_t *ctx = calloc(1, sizeof(dta_ctx_t));
   19|  4.28k|    if (ctx == NULL) {
  ------------------
  |  Branch (19:9): [True: 0, False: 4.28k]
  ------------------
   20|      0|        return NULL;
   21|      0|    }
   22|       |
   23|  4.28k|    ctx->io = io;
   24|  4.28k|    ctx->initialized = 0;
   25|       |
   26|  4.28k|    return ctx;
   27|  4.28k|}
dta_ctx_init:
   31|  3.81k|        const char *input_encoding, const char *output_encoding) {
   32|  3.81k|    readstat_error_t retval = READSTAT_OK;
   33|  3.81k|    int machine_byteorder = DTA_HILO;
  ------------------
  |  |  129|  3.81k|#define DTA_HILO  0x01
  ------------------
   34|  3.81k|    if (ds_format < DTA_MIN_VERSION || ds_format > DTA_MAX_VERSION)
  ------------------
  |  |   14|  7.63k|#define DTA_MIN_VERSION 104
  ------------------
                  if (ds_format < DTA_MIN_VERSION || ds_format > DTA_MAX_VERSION)
  ------------------
  |  |   15|  3.80k|#define DTA_MAX_VERSION 119
  ------------------
  |  Branch (34:9): [True: 7, False: 3.80k]
  |  Branch (34:40): [True: 6, False: 3.80k]
  ------------------
   35|     13|        return READSTAT_ERROR_UNSUPPORTED_FILE_FORMAT_VERSION;
   36|       |
   37|  3.80k|    if (machine_is_little_endian()) {
  ------------------
  |  Branch (37:9): [True: 3.80k, False: 0]
  ------------------
   38|  3.80k|        machine_byteorder = DTA_LOHI;
  ------------------
  |  |  130|  3.80k|#define DTA_LOHI  0x02
  ------------------
   39|  3.80k|    }
   40|       |
   41|  3.80k|    ctx->bswap = (byteorder != machine_byteorder);
   42|  3.80k|    ctx->ds_format = ds_format;
   43|  3.80k|    ctx->endianness = byteorder == DTA_LOHI ? READSTAT_ENDIAN_LITTLE : READSTAT_ENDIAN_BIG;
  ------------------
  |  |  130|  3.80k|#define DTA_LOHI  0x02
  ------------------
  |  Branch (43:23): [True: 1.25k, False: 2.55k]
  ------------------
   44|       |
   45|  3.80k|    ctx->nvar = nvar;
   46|  3.80k|    ctx->nobs = nobs;
   47|       |
   48|  3.80k|    if (ctx->nvar) {
  ------------------
  |  Branch (48:9): [True: 2.89k, False: 908]
  ------------------
   49|  2.89k|        if ((ctx->variables = readstat_calloc(ctx->nvar, sizeof(readstat_variable_t *))) == NULL) {
  ------------------
  |  Branch (49:13): [True: 72, False: 2.82k]
  ------------------
   50|     72|            retval = READSTAT_ERROR_MALLOC;
   51|     72|            goto cleanup;
   52|     72|        }
   53|  2.89k|    }
   54|       |
   55|  3.73k|    ctx->machine_is_twos_complement = READSTAT_MACHINE_IS_TWOS_COMPLEMENT;
  ------------------
  |  |    8|  3.73k|#define READSTAT_MACHINE_IS_TWOS_COMPLEMENT 0
  ------------------
   56|       |
   57|  3.73k|    if (ds_format < 105) {
  ------------------
  |  Branch (57:9): [True: 723, False: 3.00k]
  ------------------
   58|    723|        ctx->fmtlist_entry_len = 7;
   59|  3.00k|    } else if (ds_format < 114) {
  ------------------
  |  Branch (59:16): [True: 880, False: 2.12k]
  ------------------
   60|    880|        ctx->fmtlist_entry_len = 12;
   61|  2.12k|    } else if (ds_format < 118) {
  ------------------
  |  Branch (61:16): [True: 1.73k, False: 388]
  ------------------
   62|  1.73k|        ctx->fmtlist_entry_len = 49;
   63|  1.73k|    } else {
   64|    388|        ctx->fmtlist_entry_len = 57;
   65|    388|    }
   66|       |    
   67|  3.73k|    if (ds_format >= 117) {
  ------------------
  |  Branch (67:9): [True: 2.09k, False: 1.63k]
  ------------------
   68|  2.09k|        ctx->typlist_version = 117;
   69|  2.09k|    } else if (ds_format >= 111) {
  ------------------
  |  Branch (69:16): [True: 308, False: 1.33k]
  ------------------
   70|    308|        ctx->typlist_version = 111;
   71|  1.33k|    } else {
   72|  1.33k|        ctx->typlist_version = 0;
   73|  1.33k|    }
   74|       |
   75|  3.73k|    if (ds_format >= 118) {
  ------------------
  |  Branch (75:9): [True: 388, False: 3.34k]
  ------------------
   76|    388|        ctx->data_label_len_len = 2;
   77|    388|        ctx->strl_v_len = 2;
   78|    388|        ctx->strl_o_len = 6;
   79|  3.34k|    } else if (ds_format >= 117) {
  ------------------
  |  Branch (79:16): [True: 1.70k, False: 1.63k]
  ------------------
   80|  1.70k|        ctx->data_label_len_len = 1;
   81|  1.70k|        ctx->strl_v_len = 4;
   82|  1.70k|        ctx->strl_o_len = 4;
   83|  1.70k|    }
   84|       |
   85|  3.73k|    if (ds_format < 105) {
  ------------------
  |  Branch (85:9): [True: 723, False: 3.00k]
  ------------------
   86|    723|        ctx->expansion_len_len = 0;
   87|  3.00k|    } else if (ds_format < 110) {
  ------------------
  |  Branch (87:16): [True: 604, False: 2.40k]
  ------------------
   88|    604|        ctx->expansion_len_len = 2;
   89|  2.40k|    } else {
   90|  2.40k|        ctx->expansion_len_len = 4;
   91|  2.40k|    }
   92|       |    
   93|  3.73k|    if (ds_format < 110) {
  ------------------
  |  Branch (93:9): [True: 1.32k, False: 2.40k]
  ------------------
   94|  1.32k|        ctx->lbllist_entry_len = 9;
   95|  1.32k|        ctx->variable_name_len = 9;
   96|  1.32k|        ctx->ch_metadata_len = 9;
   97|  2.40k|    } else if (ds_format < 118) {
  ------------------
  |  Branch (97:16): [True: 2.01k, False: 388]
  ------------------
   98|  2.01k|        ctx->lbllist_entry_len = 33;
   99|  2.01k|        ctx->variable_name_len = 33;
  100|  2.01k|        ctx->ch_metadata_len = 33;
  101|  2.01k|    } else {
  102|    388|        ctx->lbllist_entry_len = 129;
  103|    388|        ctx->variable_name_len = 129;
  104|    388|        ctx->ch_metadata_len = 129;
  105|    388|    }
  106|       |
  107|  3.73k|    if (ds_format < 108) {
  ------------------
  |  Branch (107:9): [True: 1.32k, False: 2.40k]
  ------------------
  108|  1.32k|        ctx->variable_labels_entry_len = 32;
  109|  1.32k|        ctx->data_label_len = 32;
  110|  2.40k|    } else if (ds_format < 118) {
  ------------------
  |  Branch (110:16): [True: 2.01k, False: 388]
  ------------------
  111|  2.01k|        ctx->variable_labels_entry_len = 81;
  112|  2.01k|        ctx->data_label_len = 81;
  113|  2.01k|    } else {
  114|    388|        ctx->variable_labels_entry_len = 321;
  115|    388|        ctx->data_label_len = 321;
  116|    388|    }
  117|       |
  118|  3.73k|    if (ds_format < 105) {
  ------------------
  |  Branch (118:9): [True: 723, False: 3.00k]
  ------------------
  119|    723|        ctx->timestamp_len = 0;
  120|    723|        ctx->value_label_table_len_len = 2;
  121|    723|        ctx->value_label_table_labname_len = 12;
  122|    723|        ctx->value_label_table_padding_len = 2;
  123|  3.00k|    } else {
  124|  3.00k|        ctx->timestamp_len = 18;
  125|  3.00k|        ctx->value_label_table_len_len = 4;
  126|  3.00k|        if (ds_format < 118) {
  ------------------
  |  Branch (126:13): [True: 2.61k, False: 388]
  ------------------
  127|  2.61k|            ctx->value_label_table_labname_len = 33;
  128|  2.61k|        } else {
  129|    388|            ctx->value_label_table_labname_len = 129;
  130|    388|        }
  131|  3.00k|        ctx->value_label_table_padding_len = 3;
  132|  3.00k|    }
  133|       |
  134|  3.73k|    if (ds_format < 117) {
  ------------------
  |  Branch (134:9): [True: 1.63k, False: 2.09k]
  ------------------
  135|  1.63k|        ctx->typlist_entry_len = 1;
  136|  1.63k|        ctx->file_is_xmlish = 0;
  137|  2.09k|    } else {
  138|  2.09k|        ctx->typlist_entry_len = 2;
  139|  2.09k|        ctx->file_is_xmlish = 1;
  140|  2.09k|    }
  141|       |
  142|  3.73k|    if (ds_format < 113) {
  ------------------
  |  Branch (142:9): [True: 1.34k, False: 2.38k]
  ------------------
  143|  1.34k|        ctx->max_int8 = DTA_OLD_MAX_INT8;
  ------------------
  |  |  132|  1.34k|#define DTA_OLD_MAX_INT8                     0x7e
  ------------------
  144|  1.34k|        ctx->max_int16 = DTA_OLD_MAX_INT16;
  ------------------
  |  |  133|  1.34k|#define DTA_OLD_MAX_INT16                  0x7ffe
  ------------------
  145|  1.34k|        ctx->max_int32 = DTA_OLD_MAX_INT32;
  ------------------
  |  |  134|  1.34k|#define DTA_OLD_MAX_INT32              0x7ffffffe
  ------------------
  146|  1.34k|        ctx->max_float = DTA_OLD_MAX_FLOAT;
  ------------------
  |  |  135|  1.34k|#define DTA_OLD_MAX_FLOAT              0x7effffff // +1.7e38f
  ------------------
  147|  1.34k|        ctx->max_double = DTA_OLD_MAX_DOUBLE;
  ------------------
  |  |  136|  1.34k|#define DTA_OLD_MAX_DOUBLE     0x7fdfffffffffffffL // +8.9e307
  ------------------
  148|  2.38k|    } else {
  149|  2.38k|        ctx->max_int8 = DTA_113_MAX_INT8;
  ------------------
  |  |  144|  2.38k|#define DTA_113_MAX_INT8                    0x64
  ------------------
  150|  2.38k|        ctx->max_int16 = DTA_113_MAX_INT16;
  ------------------
  |  |  145|  2.38k|#define DTA_113_MAX_INT16                 0x7fe4
  ------------------
  151|  2.38k|        ctx->max_int32 = DTA_113_MAX_INT32;
  ------------------
  |  |  146|  2.38k|#define DTA_113_MAX_INT32             0x7fffffe4
  ------------------
  152|  2.38k|        ctx->max_float = DTA_113_MAX_FLOAT;
  ------------------
  |  |  147|  2.38k|#define DTA_113_MAX_FLOAT             0x7effffff // +1.7e38f
  ------------------
  153|  2.38k|        ctx->max_double = DTA_113_MAX_DOUBLE;
  ------------------
  |  |  148|  2.38k|#define DTA_113_MAX_DOUBLE    0x7fdfffffffffffffL // +8.9e307
  ------------------
  154|       |
  155|  2.38k|        ctx->supports_tagged_missing = 1;
  156|  2.38k|    }
  157|       |
  158|  3.73k|    if (output_encoding) {
  ------------------
  |  Branch (158:9): [True: 3.73k, False: 0]
  ------------------
  159|  3.73k|        if (input_encoding) {
  ------------------
  |  Branch (159:13): [True: 0, False: 3.73k]
  ------------------
  160|      0|            ctx->converter = iconv_open(output_encoding, input_encoding);
  161|  3.73k|        } else if (ds_format < 118) {
  ------------------
  |  Branch (161:20): [True: 3.34k, False: 388]
  ------------------
  162|  3.34k|            ctx->converter = iconv_open(output_encoding, "WINDOWS-1252");
  163|  3.34k|        } else if (strcmp(output_encoding, "UTF-8") != 0) {
  ------------------
  |  Branch (163:20): [True: 0, False: 388]
  ------------------
  164|      0|            ctx->converter = iconv_open(output_encoding, "UTF-8");
  165|      0|        }
  166|  3.73k|        if (ctx->converter == (iconv_t)-1) {
  ------------------
  |  Branch (166:13): [True: 0, False: 3.73k]
  ------------------
  167|      0|            ctx->converter = NULL;
  168|      0|            retval = READSTAT_ERROR_UNSUPPORTED_CHARSET;
  169|      0|            goto cleanup;
  170|      0|        }
  171|  3.73k|    }
  172|       |
  173|  3.73k|    if (ds_format < 119) {
  ------------------
  |  Branch (173:9): [True: 3.64k, False: 88]
  ------------------
  174|  3.64k|        ctx->srtlist_len = (ctx->nvar + 1) * sizeof(int16_t);
  175|  3.64k|    } else {
  176|     88|        ctx->srtlist_len = (ctx->nvar + 1) * sizeof(int32_t);
  177|     88|    }
  178|       |
  179|  3.73k|    if ((ctx->srtlist = readstat_malloc(ctx->srtlist_len)) == NULL) {
  ------------------
  |  Branch (179:9): [True: 0, False: 3.73k]
  ------------------
  180|      0|        retval = READSTAT_ERROR_MALLOC;
  181|      0|        goto cleanup;
  182|      0|    }
  183|       |
  184|  3.73k|    if (ctx->nvar > 0) {
  ------------------
  |  Branch (184:9): [True: 2.82k, False: 908]
  ------------------
  185|  2.82k|        ctx->typlist_len = ctx->nvar * sizeof(uint16_t);
  186|  2.82k|        ctx->varlist_len = ctx->variable_name_len * ctx->nvar * sizeof(char);
  187|  2.82k|        ctx->fmtlist_len = ctx->fmtlist_entry_len * ctx->nvar * sizeof(char);
  188|  2.82k|        ctx->lbllist_len = ctx->lbllist_entry_len * ctx->nvar * sizeof(char);
  189|  2.82k|        ctx->variable_labels_len = ctx->variable_labels_entry_len * ctx->nvar * sizeof(char);
  190|       |
  191|  2.82k|        if ((ctx->typlist = readstat_malloc(ctx->typlist_len)) == NULL) {
  ------------------
  |  Branch (191:13): [True: 0, False: 2.82k]
  ------------------
  192|      0|            retval = READSTAT_ERROR_MALLOC;
  193|      0|            goto cleanup;
  194|      0|        }
  195|  2.82k|        if ((ctx->varlist = readstat_malloc(ctx->varlist_len)) == NULL) {
  ------------------
  |  Branch (195:13): [True: 25, False: 2.79k]
  ------------------
  196|     25|            retval = READSTAT_ERROR_MALLOC;
  197|     25|            goto cleanup;
  198|     25|        }
  199|  2.79k|        if ((ctx->fmtlist = readstat_malloc(ctx->fmtlist_len)) == NULL) {
  ------------------
  |  Branch (199:13): [True: 0, False: 2.79k]
  ------------------
  200|      0|            retval = READSTAT_ERROR_MALLOC;
  201|      0|            goto cleanup;
  202|      0|        }
  203|  2.79k|        if ((ctx->lbllist = readstat_malloc(ctx->lbllist_len)) == NULL) {
  ------------------
  |  Branch (203:13): [True: 0, False: 2.79k]
  ------------------
  204|      0|            retval = READSTAT_ERROR_MALLOC;
  205|      0|            goto cleanup;
  206|      0|        }
  207|  2.79k|        if ((ctx->variable_labels = readstat_malloc(ctx->variable_labels_len)) == NULL) {
  ------------------
  |  Branch (207:13): [True: 5, False: 2.79k]
  ------------------
  208|      5|            retval = READSTAT_ERROR_MALLOC;
  209|      5|            goto cleanup;
  210|      5|        }
  211|  2.79k|    }
  212|       |
  213|  3.70k|    ctx->initialized = 1;
  214|       |
  215|  3.80k|cleanup:
  216|  3.80k|    return retval;
  217|  3.70k|}
dta_ctx_free:
  219|  4.28k|void dta_ctx_free(dta_ctx_t *ctx) {
  220|  4.28k|    if (ctx->typlist)
  ------------------
  |  Branch (220:9): [True: 2.82k, False: 1.46k]
  ------------------
  221|  2.82k|        free(ctx->typlist);
  222|  4.28k|    if (ctx->varlist)
  ------------------
  |  Branch (222:9): [True: 2.79k, False: 1.48k]
  ------------------
  223|  2.79k|        free(ctx->varlist);
  224|  4.28k|    if (ctx->srtlist)
  ------------------
  |  Branch (224:9): [True: 3.73k, False: 556]
  ------------------
  225|  3.73k|        free(ctx->srtlist);
  226|  4.28k|    if (ctx->fmtlist)
  ------------------
  |  Branch (226:9): [True: 2.79k, False: 1.48k]
  ------------------
  227|  2.79k|        free(ctx->fmtlist);
  228|  4.28k|    if (ctx->lbllist)
  ------------------
  |  Branch (228:9): [True: 2.79k, False: 1.48k]
  ------------------
  229|  2.79k|        free(ctx->lbllist);
  230|  4.28k|    if (ctx->variable_labels)
  ------------------
  |  Branch (230:9): [True: 2.79k, False: 1.49k]
  ------------------
  231|  2.79k|        free(ctx->variable_labels);
  232|  4.28k|    if (ctx->converter)
  ------------------
  |  Branch (232:9): [True: 3.34k, False: 944]
  ------------------
  233|  3.34k|        iconv_close(ctx->converter);
  234|  4.28k|    if (ctx->data_label)
  ------------------
  |  Branch (234:9): [True: 3.45k, False: 827]
  ------------------
  235|  3.45k|        free(ctx->data_label);
  236|  4.28k|    if (ctx->variables) {
  ------------------
  |  Branch (236:9): [True: 2.82k, False: 1.46k]
  ------------------
  237|  2.82k|        int i;
  238|  54.4M|        for (i=0; i<ctx->nvar; i++) {
  ------------------
  |  Branch (238:19): [True: 54.4M, False: 2.82k]
  ------------------
  239|  54.4M|            if (ctx->variables[i])
  ------------------
  |  Branch (239:17): [True: 41.4k, False: 54.3M]
  ------------------
  240|  41.4k|                free(ctx->variables[i]);
  241|  54.4M|        }
  242|  2.82k|        free(ctx->variables);
  243|  2.82k|    }
  244|  4.28k|    if (ctx->strls) {
  ------------------
  |  Branch (244:9): [True: 812, False: 3.47k]
  ------------------
  245|    812|        int i;
  246|   107k|        for (i=0; i<ctx->strls_count; i++) {
  ------------------
  |  Branch (246:19): [True: 107k, False: 812]
  ------------------
  247|   107k|            free(ctx->strls[i]);
  248|   107k|        }
  249|    812|        free(ctx->strls);
  250|    812|    }
  251|  4.28k|    free(ctx);
  252|  4.28k|}
dta_type_info:
  255|   157k|        size_t *max_len, readstat_type_t *out_type) {
  256|   157k|    readstat_error_t retval = READSTAT_OK;
  257|   157k|    size_t len = 0;
  258|   157k|    readstat_type_t type = READSTAT_TYPE_STRING;
  259|   157k|    if (ctx->typlist_version == 111) {
  ------------------
  |  Branch (259:9): [True: 53.1k, False: 104k]
  ------------------
  260|  53.1k|        switch (typecode) {
  261|    887|            case DTA_111_TYPE_CODE_INT8:
  ------------------
  |  |  172|    887|#define DTA_111_TYPE_CODE_INT8     0xFB
  ------------------
  |  Branch (261:13): [True: 887, False: 52.2k]
  ------------------
  262|    887|                len = 1; type = READSTAT_TYPE_INT8; break;
  263|    424|            case DTA_111_TYPE_CODE_INT16:
  ------------------
  |  |  173|    424|#define DTA_111_TYPE_CODE_INT16    0xFC
  ------------------
  |  Branch (263:13): [True: 424, False: 52.7k]
  ------------------
  264|    424|                len = 2; type = READSTAT_TYPE_INT16; break;
  265|  11.9k|            case DTA_111_TYPE_CODE_INT32:
  ------------------
  |  |  174|  11.9k|#define DTA_111_TYPE_CODE_INT32    0xFD
  ------------------
  |  Branch (265:13): [True: 11.9k, False: 41.2k]
  ------------------
  266|  11.9k|                len = 4; type = READSTAT_TYPE_INT32; break;
  267|    486|            case DTA_111_TYPE_CODE_FLOAT:
  ------------------
  |  |  175|    486|#define DTA_111_TYPE_CODE_FLOAT    0xFE
  ------------------
  |  Branch (267:13): [True: 486, False: 52.6k]
  ------------------
  268|    486|                len = 4; type = READSTAT_TYPE_FLOAT; break;
  269|  1.43k|            case DTA_111_TYPE_CODE_DOUBLE:
  ------------------
  |  |  176|  1.43k|#define DTA_111_TYPE_CODE_DOUBLE   0xFF
  ------------------
  |  Branch (269:13): [True: 1.43k, False: 51.7k]
  ------------------
  270|  1.43k|                len = 8; type = READSTAT_TYPE_DOUBLE; break;
  271|  37.9k|            default:
  ------------------
  |  Branch (271:13): [True: 37.9k, False: 15.1k]
  ------------------
  272|  37.9k|                len = typecode; type = READSTAT_TYPE_STRING; break;
  273|  53.1k|        }
  274|   104k|    } else if (ctx->typlist_version == 117) {
  ------------------
  |  Branch (274:16): [True: 55.9k, False: 48.6k]
  ------------------
  275|  55.9k|        switch (typecode) {
  276|  1.19k|            case DTA_117_TYPE_CODE_INT8:
  ------------------
  |  |  165|  1.19k|#define DTA_117_TYPE_CODE_INT8     0xFFFA
  ------------------
  |  Branch (276:13): [True: 1.19k, False: 54.7k]
  ------------------
  277|  1.19k|                len = 1; type = READSTAT_TYPE_INT8; break;
  278|    741|            case DTA_117_TYPE_CODE_INT16:
  ------------------
  |  |  166|    741|#define DTA_117_TYPE_CODE_INT16    0xFFF9
  ------------------
  |  Branch (278:13): [True: 741, False: 55.2k]
  ------------------
  279|    741|                len = 2; type = READSTAT_TYPE_INT16; break;
  280|  1.73k|            case DTA_117_TYPE_CODE_INT32:
  ------------------
  |  |  167|  1.73k|#define DTA_117_TYPE_CODE_INT32    0xFFF8
  ------------------
  |  Branch (280:13): [True: 1.73k, False: 54.2k]
  ------------------
  281|  1.73k|                len = 4; type = READSTAT_TYPE_INT32; break;
  282|    757|            case DTA_117_TYPE_CODE_FLOAT:
  ------------------
  |  |  168|    757|#define DTA_117_TYPE_CODE_FLOAT    0xFFF7
  ------------------
  |  Branch (282:13): [True: 757, False: 55.2k]
  ------------------
  283|    757|                len = 4; type = READSTAT_TYPE_FLOAT; break;
  284|    764|            case DTA_117_TYPE_CODE_DOUBLE:
  ------------------
  |  |  169|    764|#define DTA_117_TYPE_CODE_DOUBLE   0xFFF6
  ------------------
  |  Branch (284:13): [True: 764, False: 55.1k]
  ------------------
  285|    764|                len = 8; type = READSTAT_TYPE_DOUBLE; break;
  286|  47.1k|            case DTA_117_TYPE_CODE_STRL:
  ------------------
  |  |  170|  47.1k|#define DTA_117_TYPE_CODE_STRL     0x8000
  ------------------
  |  Branch (286:13): [True: 47.1k, False: 8.85k]
  ------------------
  287|  47.1k|                len = 8; type = READSTAT_TYPE_STRING_REF; break;
  288|  3.66k|            default:
  ------------------
  |  Branch (288:13): [True: 3.66k, False: 52.2k]
  ------------------
  289|  3.66k|                len = typecode; type = READSTAT_TYPE_STRING; break;
  290|  55.9k|        }
  291|  55.9k|    } else if (typecode < 0x7F) {
  ------------------
  |  Branch (291:16): [True: 33.9k, False: 14.7k]
  ------------------
  292|  33.9k|        switch (typecode) {
  293|  30.7k|            case DTA_OLD_TYPE_CODE_INT8:
  ------------------
  |  |  178|  30.7k|#define DTA_OLD_TYPE_CODE_INT8     'b'
  ------------------
  |  Branch (293:13): [True: 30.7k, False: 3.15k]
  ------------------
  294|  30.7k|                len = 1; type = READSTAT_TYPE_INT8; break;
  295|    893|            case DTA_OLD_TYPE_CODE_INT16:
  ------------------
  |  |  179|    893|#define DTA_OLD_TYPE_CODE_INT16    'i'
  ------------------
  |  Branch (295:13): [True: 893, False: 33.0k]
  ------------------
  296|    893|                len = 2; type = READSTAT_TYPE_INT16; break;
  297|    891|            case DTA_OLD_TYPE_CODE_INT32:
  ------------------
  |  |  180|    891|#define DTA_OLD_TYPE_CODE_INT32    'l'
  ------------------
  |  Branch (297:13): [True: 891, False: 33.0k]
  ------------------
  298|    891|                len = 4; type = READSTAT_TYPE_INT32; break;
  299|    564|            case DTA_OLD_TYPE_CODE_FLOAT:
  ------------------
  |  |  181|    564|#define DTA_OLD_TYPE_CODE_FLOAT    'f'
  ------------------
  |  Branch (299:13): [True: 564, False: 33.3k]
  ------------------
  300|    564|                len = 4; type = READSTAT_TYPE_FLOAT; break;
  301|    795|            case DTA_OLD_TYPE_CODE_DOUBLE:
  ------------------
  |  |  182|    795|#define DTA_OLD_TYPE_CODE_DOUBLE   'd'
  ------------------
  |  Branch (301:13): [True: 795, False: 33.1k]
  ------------------
  302|    795|                len = 8; type = READSTAT_TYPE_DOUBLE; break;
  303|     16|            default:
  ------------------
  |  Branch (303:13): [True: 16, False: 33.8k]
  ------------------
  304|     16|                retval = READSTAT_ERROR_PARSE; break;
  305|  33.9k|        }
  306|  33.9k|    } else {
  307|  14.7k|        len = typecode - 0x7F;
  308|  14.7k|        type = READSTAT_TYPE_STRING;
  309|  14.7k|    }
  310|       |    
  311|   157k|    if (max_len)
  ------------------
  |  Branch (311:9): [True: 157k, False: 0]
  ------------------
  312|   157k|        *max_len = len;
  313|   157k|    if (out_type)
  ------------------
  |  Branch (313:9): [True: 116k, False: 41.4k]
  ------------------
  314|   116k|        *out_type = type;
  315|       |
  316|   157k|    return retval;
  317|   157k|}

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

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

rt_open_handler:
    8|  4.28k|int rt_open_handler(const char *path, void *io_ctx) {
    9|  4.28k|    return 0;
   10|  4.28k|}
rt_close_handler:
   12|  4.28k|int rt_close_handler(void *io_ctx) {
   13|  4.28k|    return 0;
   14|  4.28k|}
rt_seek_handler:
   17|  22.6k|        readstat_io_flags_t whence, void *io_ctx) {
   18|  22.6k|    rt_buffer_ctx_t *buffer_ctx = (rt_buffer_ctx_t *)io_ctx;
   19|  22.6k|    readstat_off_t newpos = -1;
   20|  22.6k|    if (whence == READSTAT_SEEK_SET) {
  ------------------
  |  Branch (20:9): [True: 7.93k, False: 14.7k]
  ------------------
   21|  7.93k|        newpos = offset;
   22|  14.7k|    } else if (whence == READSTAT_SEEK_CUR) {
  ------------------
  |  Branch (22:16): [True: 10.4k, False: 4.28k]
  ------------------
   23|  10.4k|        newpos = buffer_ctx->pos + offset;
   24|  10.4k|    } else if (whence == READSTAT_SEEK_END) {
  ------------------
  |  Branch (24:16): [True: 4.28k, False: 0]
  ------------------
   25|  4.28k|        newpos = buffer_ctx->buffer->used + offset;
   26|  4.28k|    }
   27|       |
   28|  22.6k|    if (newpos < 0)
  ------------------
  |  Branch (28:9): [True: 136, False: 22.5k]
  ------------------
   29|    136|        return -1;
   30|       |
   31|  22.5k|    if (newpos > buffer_ctx->buffer->used)
  ------------------
  |  Branch (31:9): [True: 111, False: 22.4k]
  ------------------
   32|    111|        return -1;
   33|       |
   34|  22.4k|    buffer_ctx->pos = newpos;
   35|  22.4k|    return newpos;
   36|  22.5k|}
rt_read_handler:
   38|   506k|ssize_t rt_read_handler(void *buf, size_t nbytes, void *io_ctx) {
   39|   506k|    rt_buffer_ctx_t *buffer_ctx = (rt_buffer_ctx_t *)io_ctx;
   40|   506k|    ssize_t bytes_copied = 0;
   41|   506k|    ssize_t bytes_left = buffer_ctx->buffer->used - buffer_ctx->pos;
   42|   506k|    if (nbytes <= bytes_left) {
  ------------------
  |  Branch (42:9): [True: 504k, False: 2.02k]
  ------------------
   43|   504k|        memcpy(buf, buffer_ctx->buffer->bytes + buffer_ctx->pos, nbytes);
   44|   504k|        bytes_copied = nbytes;
   45|   504k|    } else if (bytes_left > 0) {
  ------------------
  |  Branch (45:16): [True: 309, False: 1.71k]
  ------------------
   46|    309|        memcpy(buf, buffer_ctx->buffer->bytes + buffer_ctx->pos, bytes_left);
   47|    309|        bytes_copied = bytes_left;
   48|    309|    }
   49|   506k|    buffer_ctx->pos += bytes_copied;
   50|   506k|    return bytes_copied;
   51|   506k|}

