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

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

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

readstat_convert:
    7|   392k|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|   394k|    while (src_len && (src[src_len-1] == ' ' || src[src_len-1] == '\0')) {
  ------------------
  |  Branch (10:12): [True: 362k, False: 32.5k]
  |  Branch (10:24): [True: 1.76k, False: 360k]
  |  Branch (10:49): [True: 211, False: 360k]
  ------------------
   11|  1.97k|        src_len--;
   12|  1.97k|    }
   13|   392k|    if (dst_len == 0) {
  ------------------
  |  Branch (13:9): [True: 0, False: 392k]
  ------------------
   14|      0|        return READSTAT_ERROR_CONVERT_LONG_STRING;
   15|   392k|    } else if (converter) {
  ------------------
  |  Branch (15:16): [True: 391k, False: 1.45k]
  ------------------
   16|   391k|        size_t dst_left = dst_len - 1;
   17|   391k|        char *dst_end = dst;
   18|   391k|        size_t status = iconv(converter, (readstat_iconv_inbuf_t)&src, &src_len, &dst_end, &dst_left);
   19|   391k|        if (status == (size_t)-1) {
  ------------------
  |  Branch (19:13): [True: 1.52k, False: 390k]
  ------------------
   20|  1.52k|            if (errno == E2BIG) {
  ------------------
  |  Branch (20:17): [True: 1, False: 1.52k]
  ------------------
   21|      1|                return READSTAT_ERROR_CONVERT_LONG_STRING;
   22|  1.52k|            } else if (errno == EILSEQ) {
  ------------------
  |  Branch (22:24): [True: 1.52k, False: 0]
  ------------------
   23|  1.52k|                return READSTAT_ERROR_CONVERT_BAD_STRING;
   24|  1.52k|            } 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.52k|        }
   28|   390k|        dst[dst_len - dst_left - 1] = '\0';
   29|   390k|    } else if (src_len + 1 > dst_len) {
  ------------------
  |  Branch (29:16): [True: 2, False: 1.44k]
  ------------------
   30|      2|        return READSTAT_ERROR_CONVERT_LONG_STRING;
   31|  1.44k|    } else {
   32|  1.44k|        memcpy(dst, src, src_len);
   33|  1.44k|        dst[src_len] = '\0';
   34|  1.44k|    }
   35|   391k|    return READSTAT_OK;
   36|   392k|}

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

readstat_malloc:
   10|   236k|void *readstat_malloc(size_t len) {
   11|   236k|    if (len > MAX_MALLOC_SIZE || len == 0) {
  ------------------
  |  |    3|   472k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
  |  Branch (11:9): [True: 37, False: 236k]
  |  Branch (11:34): [True: 0, False: 236k]
  ------------------
   12|     37|        return NULL;
   13|     37|    }
   14|   236k|    return malloc(len);
   15|   236k|}
readstat_calloc:
   17|  2.95k|void *readstat_calloc(size_t count, size_t size) {
   18|  2.95k|    if (count > MAX_MALLOC_SIZE || size > MAX_MALLOC_SIZE || count * size > MAX_MALLOC_SIZE) {
  ------------------
  |  |    3|  5.90k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
                  if (count > MAX_MALLOC_SIZE || size > MAX_MALLOC_SIZE || count * size > MAX_MALLOC_SIZE) {
  ------------------
  |  |    3|  5.84k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
                  if (count > MAX_MALLOC_SIZE || size > MAX_MALLOC_SIZE || count * size > MAX_MALLOC_SIZE) {
  ------------------
  |  |    3|  2.89k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
  |  Branch (18:9): [True: 57, False: 2.89k]
  |  Branch (18:36): [True: 0, False: 2.89k]
  |  Branch (18:62): [True: 28, False: 2.86k]
  ------------------
   19|     85|        return NULL;
   20|     85|    }
   21|  2.86k|    if (count == 0 || size == 0) {
  ------------------
  |  Branch (21:9): [True: 0, False: 2.86k]
  |  Branch (21:23): [True: 0, False: 2.86k]
  ------------------
   22|      0|        return NULL;
   23|      0|    }
   24|  2.86k|    return calloc(count, size);
   25|  2.86k|}
readstat_realloc:
   27|  7.18k|void *readstat_realloc(void *ptr, size_t len) {
   28|  7.18k|    if (len > MAX_MALLOC_SIZE || len == 0) {
  ------------------
  |  |    3|  14.3k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
  |  Branch (28:9): [True: 42, False: 7.14k]
  |  Branch (28:34): [True: 8, False: 7.13k]
  ------------------
   29|     50|        if (ptr)
  ------------------
  |  Branch (29:13): [True: 7, False: 43]
  ------------------
   30|      7|            free(ptr);
   31|     50|        return NULL;
   32|     50|    }
   33|  7.13k|    return realloc(ptr, len);
   34|  7.18k|}

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

dta_ctx_alloc:
   17|  4.36k|dta_ctx_t *dta_ctx_alloc(readstat_io_t *io) {
   18|  4.36k|    dta_ctx_t *ctx = calloc(1, sizeof(dta_ctx_t));
   19|  4.36k|    if (ctx == NULL) {
  ------------------
  |  Branch (19:9): [True: 0, False: 4.36k]
  ------------------
   20|      0|        return NULL;
   21|      0|    }
   22|       |
   23|  4.36k|    ctx->io = io;
   24|  4.36k|    ctx->initialized = 0;
   25|       |
   26|  4.36k|    return ctx;
   27|  4.36k|}
dta_ctx_init:
   31|  3.89k|        const char *input_encoding, const char *output_encoding) {
   32|  3.89k|    readstat_error_t retval = READSTAT_OK;
   33|  3.89k|    int machine_byteorder = DTA_HILO;
  ------------------
  |  |  129|  3.89k|#define DTA_HILO  0x01
  ------------------
   34|  3.89k|    if (ds_format < DTA_MIN_VERSION || ds_format > DTA_MAX_VERSION)
  ------------------
  |  |   14|  7.78k|#define DTA_MIN_VERSION 104
  ------------------
                  if (ds_format < DTA_MIN_VERSION || ds_format > DTA_MAX_VERSION)
  ------------------
  |  |   15|  3.87k|#define DTA_MAX_VERSION 119
  ------------------
  |  Branch (34:9): [True: 14, False: 3.87k]
  |  Branch (34:40): [True: 4, False: 3.87k]
  ------------------
   35|     18|        return READSTAT_ERROR_UNSUPPORTED_FILE_FORMAT_VERSION;
   36|       |
   37|  3.87k|    if (machine_is_little_endian()) {
  ------------------
  |  Branch (37:9): [True: 3.87k, False: 0]
  ------------------
   38|  3.87k|        machine_byteorder = DTA_LOHI;
  ------------------
  |  |  130|  3.87k|#define DTA_LOHI  0x02
  ------------------
   39|  3.87k|    }
   40|       |
   41|  3.87k|    ctx->bswap = (byteorder != machine_byteorder);
   42|  3.87k|    ctx->ds_format = ds_format;
   43|  3.87k|    ctx->endianness = byteorder == DTA_LOHI ? READSTAT_ENDIAN_LITTLE : READSTAT_ENDIAN_BIG;
  ------------------
  |  |  130|  3.87k|#define DTA_LOHI  0x02
  ------------------
  |  Branch (43:23): [True: 1.26k, False: 2.60k]
  ------------------
   44|       |
   45|  3.87k|    ctx->nvar = nvar;
   46|  3.87k|    ctx->nobs = nobs;
   47|       |
   48|  3.87k|    if (ctx->nvar) {
  ------------------
  |  Branch (48:9): [True: 2.95k, False: 921]
  ------------------
   49|  2.95k|        if ((ctx->variables = readstat_calloc(ctx->nvar, sizeof(readstat_variable_t *))) == NULL) {
  ------------------
  |  Branch (49:13): [True: 85, False: 2.86k]
  ------------------
   50|     85|            retval = READSTAT_ERROR_MALLOC;
   51|     85|            goto cleanup;
   52|     85|        }
   53|  2.95k|    }
   54|       |
   55|  3.78k|    ctx->machine_is_twos_complement = READSTAT_MACHINE_IS_TWOS_COMPLEMENT;
  ------------------
  |  |    8|  3.78k|#define READSTAT_MACHINE_IS_TWOS_COMPLEMENT 0
  ------------------
   56|       |
   57|  3.78k|    if (ds_format < 105) {
  ------------------
  |  Branch (57:9): [True: 741, False: 3.04k]
  ------------------
   58|    741|        ctx->fmtlist_entry_len = 7;
   59|  3.04k|    } else if (ds_format < 114) {
  ------------------
  |  Branch (59:16): [True: 868, False: 2.17k]
  ------------------
   60|    868|        ctx->fmtlist_entry_len = 12;
   61|  2.17k|    } else if (ds_format < 118) {
  ------------------
  |  Branch (61:16): [True: 1.81k, False: 361]
  ------------------
   62|  1.81k|        ctx->fmtlist_entry_len = 49;
   63|  1.81k|    } else {
   64|    361|        ctx->fmtlist_entry_len = 57;
   65|    361|    }
   66|       |    
   67|  3.78k|    if (ds_format >= 117) {
  ------------------
  |  Branch (67:9): [True: 2.14k, False: 1.64k]
  ------------------
   68|  2.14k|        ctx->typlist_version = 117;
   69|  2.14k|    } else if (ds_format >= 111) {
  ------------------
  |  Branch (69:16): [True: 328, False: 1.31k]
  ------------------
   70|    328|        ctx->typlist_version = 111;
   71|  1.31k|    } else {
   72|  1.31k|        ctx->typlist_version = 0;
   73|  1.31k|    }
   74|       |
   75|  3.78k|    if (ds_format >= 118) {
  ------------------
  |  Branch (75:9): [True: 361, False: 3.42k]
  ------------------
   76|    361|        ctx->data_label_len_len = 2;
   77|    361|        ctx->strl_v_len = 2;
   78|    361|        ctx->strl_o_len = 6;
   79|  3.42k|    } else if (ds_format >= 117) {
  ------------------
  |  Branch (79:16): [True: 1.78k, False: 1.64k]
  ------------------
   80|  1.78k|        ctx->data_label_len_len = 1;
   81|  1.78k|        ctx->strl_v_len = 4;
   82|  1.78k|        ctx->strl_o_len = 4;
   83|  1.78k|    }
   84|       |
   85|  3.78k|    if (ds_format < 105) {
  ------------------
  |  Branch (85:9): [True: 741, False: 3.04k]
  ------------------
   86|    741|        ctx->expansion_len_len = 0;
   87|  3.04k|    } else if (ds_format < 110) {
  ------------------
  |  Branch (87:16): [True: 567, False: 2.48k]
  ------------------
   88|    567|        ctx->expansion_len_len = 2;
   89|  2.48k|    } else {
   90|  2.48k|        ctx->expansion_len_len = 4;
   91|  2.48k|    }
   92|       |    
   93|  3.78k|    if (ds_format < 110) {
  ------------------
  |  Branch (93:9): [True: 1.30k, False: 2.48k]
  ------------------
   94|  1.30k|        ctx->lbllist_entry_len = 9;
   95|  1.30k|        ctx->variable_name_len = 9;
   96|  1.30k|        ctx->ch_metadata_len = 9;
   97|  2.48k|    } else if (ds_format < 118) {
  ------------------
  |  Branch (97:16): [True: 2.11k, False: 361]
  ------------------
   98|  2.11k|        ctx->lbllist_entry_len = 33;
   99|  2.11k|        ctx->variable_name_len = 33;
  100|  2.11k|        ctx->ch_metadata_len = 33;
  101|  2.11k|    } else {
  102|    361|        ctx->lbllist_entry_len = 129;
  103|    361|        ctx->variable_name_len = 129;
  104|    361|        ctx->ch_metadata_len = 129;
  105|    361|    }
  106|       |
  107|  3.78k|    if (ds_format < 108) {
  ------------------
  |  Branch (107:9): [True: 1.30k, False: 2.48k]
  ------------------
  108|  1.30k|        ctx->variable_labels_entry_len = 32;
  109|  1.30k|        ctx->data_label_len = 32;
  110|  2.48k|    } else if (ds_format < 118) {
  ------------------
  |  Branch (110:16): [True: 2.12k, False: 361]
  ------------------
  111|  2.12k|        ctx->variable_labels_entry_len = 81;
  112|  2.12k|        ctx->data_label_len = 81;
  113|  2.12k|    } else {
  114|    361|        ctx->variable_labels_entry_len = 321;
  115|    361|        ctx->data_label_len = 321;
  116|    361|    }
  117|       |
  118|  3.78k|    if (ds_format < 105) {
  ------------------
  |  Branch (118:9): [True: 741, False: 3.04k]
  ------------------
  119|    741|        ctx->timestamp_len = 0;
  120|    741|        ctx->value_label_table_len_len = 2;
  121|    741|        ctx->value_label_table_labname_len = 12;
  122|    741|        ctx->value_label_table_padding_len = 2;
  123|  3.04k|    } else {
  124|  3.04k|        ctx->timestamp_len = 18;
  125|  3.04k|        ctx->value_label_table_len_len = 4;
  126|  3.04k|        if (ds_format < 118) {
  ------------------
  |  Branch (126:13): [True: 2.68k, False: 361]
  ------------------
  127|  2.68k|            ctx->value_label_table_labname_len = 33;
  128|  2.68k|        } else {
  129|    361|            ctx->value_label_table_labname_len = 129;
  130|    361|        }
  131|  3.04k|        ctx->value_label_table_padding_len = 3;
  132|  3.04k|    }
  133|       |
  134|  3.78k|    if (ds_format < 117) {
  ------------------
  |  Branch (134:9): [True: 1.64k, False: 2.14k]
  ------------------
  135|  1.64k|        ctx->typlist_entry_len = 1;
  136|  1.64k|        ctx->file_is_xmlish = 0;
  137|  2.14k|    } else {
  138|  2.14k|        ctx->typlist_entry_len = 2;
  139|  2.14k|        ctx->file_is_xmlish = 1;
  140|  2.14k|    }
  141|       |
  142|  3.78k|    if (ds_format < 113) {
  ------------------
  |  Branch (142:9): [True: 1.35k, False: 2.43k]
  ------------------
  143|  1.35k|        ctx->max_int8 = DTA_OLD_MAX_INT8;
  ------------------
  |  |  132|  1.35k|#define DTA_OLD_MAX_INT8                     0x7e
  ------------------
  144|  1.35k|        ctx->max_int16 = DTA_OLD_MAX_INT16;
  ------------------
  |  |  133|  1.35k|#define DTA_OLD_MAX_INT16                  0x7ffe
  ------------------
  145|  1.35k|        ctx->max_int32 = DTA_OLD_MAX_INT32;
  ------------------
  |  |  134|  1.35k|#define DTA_OLD_MAX_INT32              0x7ffffffe
  ------------------
  146|  1.35k|        ctx->max_float = DTA_OLD_MAX_FLOAT;
  ------------------
  |  |  135|  1.35k|#define DTA_OLD_MAX_FLOAT              0x7effffff // +1.7e38f
  ------------------
  147|  1.35k|        ctx->max_double = DTA_OLD_MAX_DOUBLE;
  ------------------
  |  |  136|  1.35k|#define DTA_OLD_MAX_DOUBLE     0x7fdfffffffffffffL // +8.9e307
  ------------------
  148|  2.43k|    } else {
  149|  2.43k|        ctx->max_int8 = DTA_113_MAX_INT8;
  ------------------
  |  |  144|  2.43k|#define DTA_113_MAX_INT8                    0x64
  ------------------
  150|  2.43k|        ctx->max_int16 = DTA_113_MAX_INT16;
  ------------------
  |  |  145|  2.43k|#define DTA_113_MAX_INT16                 0x7fe4
  ------------------
  151|  2.43k|        ctx->max_int32 = DTA_113_MAX_INT32;
  ------------------
  |  |  146|  2.43k|#define DTA_113_MAX_INT32             0x7fffffe4
  ------------------
  152|  2.43k|        ctx->max_float = DTA_113_MAX_FLOAT;
  ------------------
  |  |  147|  2.43k|#define DTA_113_MAX_FLOAT             0x7effffff // +1.7e38f
  ------------------
  153|  2.43k|        ctx->max_double = DTA_113_MAX_DOUBLE;
  ------------------
  |  |  148|  2.43k|#define DTA_113_MAX_DOUBLE    0x7fdfffffffffffffL // +8.9e307
  ------------------
  154|       |
  155|  2.43k|        ctx->supports_tagged_missing = 1;
  156|  2.43k|    }
  157|       |
  158|  3.78k|    if (output_encoding) {
  ------------------
  |  Branch (158:9): [True: 3.78k, False: 0]
  ------------------
  159|  3.78k|        if (input_encoding) {
  ------------------
  |  Branch (159:13): [True: 0, False: 3.78k]
  ------------------
  160|      0|            ctx->converter = iconv_open(output_encoding, input_encoding);
  161|  3.78k|        } else if (ds_format < 118) {
  ------------------
  |  Branch (161:20): [True: 3.42k, False: 361]
  ------------------
  162|  3.42k|            ctx->converter = iconv_open(output_encoding, "WINDOWS-1252");
  163|  3.42k|        } else if (strcmp(output_encoding, "UTF-8") != 0) {
  ------------------
  |  Branch (163:20): [True: 0, False: 361]
  ------------------
  164|      0|            ctx->converter = iconv_open(output_encoding, "UTF-8");
  165|      0|        }
  166|  3.78k|        if (ctx->converter == (iconv_t)-1) {
  ------------------
  |  Branch (166:13): [True: 0, False: 3.78k]
  ------------------
  167|      0|            ctx->converter = NULL;
  168|      0|            retval = READSTAT_ERROR_UNSUPPORTED_CHARSET;
  169|      0|            goto cleanup;
  170|      0|        }
  171|  3.78k|    }
  172|       |
  173|  3.78k|    if (ds_format < 119) {
  ------------------
  |  Branch (173:9): [True: 3.72k, False: 62]
  ------------------
  174|  3.72k|        ctx->srtlist_len = (ctx->nvar + 1) * sizeof(int16_t);
  175|  3.72k|    } else {
  176|     62|        ctx->srtlist_len = (ctx->nvar + 1) * sizeof(int32_t);
  177|     62|    }
  178|       |
  179|  3.78k|    if ((ctx->srtlist = readstat_malloc(ctx->srtlist_len)) == NULL) {
  ------------------
  |  Branch (179:9): [True: 0, False: 3.78k]
  ------------------
  180|      0|        retval = READSTAT_ERROR_MALLOC;
  181|      0|        goto cleanup;
  182|      0|    }
  183|       |
  184|  3.78k|    if (ctx->nvar > 0) {
  ------------------
  |  Branch (184:9): [True: 2.86k, False: 921]
  ------------------
  185|  2.86k|        ctx->typlist_len = ctx->nvar * sizeof(uint16_t);
  186|  2.86k|        ctx->varlist_len = ctx->variable_name_len * ctx->nvar * sizeof(char);
  187|  2.86k|        ctx->fmtlist_len = ctx->fmtlist_entry_len * ctx->nvar * sizeof(char);
  188|  2.86k|        ctx->lbllist_len = ctx->lbllist_entry_len * ctx->nvar * sizeof(char);
  189|  2.86k|        ctx->variable_labels_len = ctx->variable_labels_entry_len * ctx->nvar * sizeof(char);
  190|       |
  191|  2.86k|        if ((ctx->typlist = readstat_malloc(ctx->typlist_len)) == NULL) {
  ------------------
  |  Branch (191:13): [True: 0, False: 2.86k]
  ------------------
  192|      0|            retval = READSTAT_ERROR_MALLOC;
  193|      0|            goto cleanup;
  194|      0|        }
  195|  2.86k|        if ((ctx->varlist = readstat_malloc(ctx->varlist_len)) == NULL) {
  ------------------
  |  Branch (195:13): [True: 22, False: 2.84k]
  ------------------
  196|     22|            retval = READSTAT_ERROR_MALLOC;
  197|     22|            goto cleanup;
  198|     22|        }
  199|  2.84k|        if ((ctx->fmtlist = readstat_malloc(ctx->fmtlist_len)) == NULL) {
  ------------------
  |  Branch (199:13): [True: 0, False: 2.84k]
  ------------------
  200|      0|            retval = READSTAT_ERROR_MALLOC;
  201|      0|            goto cleanup;
  202|      0|        }
  203|  2.84k|        if ((ctx->lbllist = readstat_malloc(ctx->lbllist_len)) == NULL) {
  ------------------
  |  Branch (203:13): [True: 0, False: 2.84k]
  ------------------
  204|      0|            retval = READSTAT_ERROR_MALLOC;
  205|      0|            goto cleanup;
  206|      0|        }
  207|  2.84k|        if ((ctx->variable_labels = readstat_malloc(ctx->variable_labels_len)) == NULL) {
  ------------------
  |  Branch (207:13): [True: 2, False: 2.84k]
  ------------------
  208|      2|            retval = READSTAT_ERROR_MALLOC;
  209|      2|            goto cleanup;
  210|      2|        }
  211|  2.84k|    }
  212|       |
  213|  3.76k|    ctx->initialized = 1;
  214|       |
  215|  3.87k|cleanup:
  216|  3.87k|    return retval;
  217|  3.76k|}
dta_ctx_free:
  219|  4.36k|void dta_ctx_free(dta_ctx_t *ctx) {
  220|  4.36k|    if (ctx->typlist)
  ------------------
  |  Branch (220:9): [True: 2.86k, False: 1.49k]
  ------------------
  221|  2.86k|        free(ctx->typlist);
  222|  4.36k|    if (ctx->varlist)
  ------------------
  |  Branch (222:9): [True: 2.84k, False: 1.52k]
  ------------------
  223|  2.84k|        free(ctx->varlist);
  224|  4.36k|    if (ctx->srtlist)
  ------------------
  |  Branch (224:9): [True: 3.78k, False: 577]
  ------------------
  225|  3.78k|        free(ctx->srtlist);
  226|  4.36k|    if (ctx->fmtlist)
  ------------------
  |  Branch (226:9): [True: 2.84k, False: 1.52k]
  ------------------
  227|  2.84k|        free(ctx->fmtlist);
  228|  4.36k|    if (ctx->lbllist)
  ------------------
  |  Branch (228:9): [True: 2.84k, False: 1.52k]
  ------------------
  229|  2.84k|        free(ctx->lbllist);
  230|  4.36k|    if (ctx->variable_labels)
  ------------------
  |  Branch (230:9): [True: 2.84k, False: 1.52k]
  ------------------
  231|  2.84k|        free(ctx->variable_labels);
  232|  4.36k|    if (ctx->converter)
  ------------------
  |  Branch (232:9): [True: 3.42k, False: 938]
  ------------------
  233|  3.42k|        iconv_close(ctx->converter);
  234|  4.36k|    if (ctx->data_label)
  ------------------
  |  Branch (234:9): [True: 3.51k, False: 851]
  ------------------
  235|  3.51k|        free(ctx->data_label);
  236|  4.36k|    if (ctx->variables) {
  ------------------
  |  Branch (236:9): [True: 2.86k, False: 1.49k]
  ------------------
  237|  2.86k|        int i;
  238|  49.1M|        for (i=0; i<ctx->nvar; i++) {
  ------------------
  |  Branch (238:19): [True: 49.1M, False: 2.86k]
  ------------------
  239|  49.1M|            if (ctx->variables[i])
  ------------------
  |  Branch (239:17): [True: 64.7k, False: 49.0M]
  ------------------
  240|  64.7k|                free(ctx->variables[i]);
  241|  49.1M|        }
  242|  2.86k|        free(ctx->variables);
  243|  2.86k|    }
  244|  4.36k|    if (ctx->strls) {
  ------------------
  |  Branch (244:9): [True: 829, False: 3.53k]
  ------------------
  245|    829|        int i;
  246|   206k|        for (i=0; i<ctx->strls_count; i++) {
  ------------------
  |  Branch (246:19): [True: 205k, False: 829]
  ------------------
  247|   205k|            free(ctx->strls[i]);
  248|   205k|        }
  249|    829|        free(ctx->strls);
  250|    829|    }
  251|  4.36k|    free(ctx);
  252|  4.36k|}
dta_type_info:
  255|   153k|        size_t *max_len, readstat_type_t *out_type) {
  256|   153k|    readstat_error_t retval = READSTAT_OK;
  257|   153k|    size_t len = 0;
  258|   153k|    readstat_type_t type = READSTAT_TYPE_STRING;
  259|   153k|    if (ctx->typlist_version == 111) {
  ------------------
  |  Branch (259:9): [True: 21.4k, False: 132k]
  ------------------
  260|  21.4k|        switch (typecode) {
  261|    870|            case DTA_111_TYPE_CODE_INT8:
  ------------------
  |  |  172|    870|#define DTA_111_TYPE_CODE_INT8     0xFB
  ------------------
  |  Branch (261:13): [True: 870, False: 20.5k]
  ------------------
  262|    870|                len = 1; type = READSTAT_TYPE_INT8; break;
  263|    436|            case DTA_111_TYPE_CODE_INT16:
  ------------------
  |  |  173|    436|#define DTA_111_TYPE_CODE_INT16    0xFC
  ------------------
  |  Branch (263:13): [True: 436, False: 21.0k]
  ------------------
  264|    436|                len = 2; type = READSTAT_TYPE_INT16; break;
  265|    438|            case DTA_111_TYPE_CODE_INT32:
  ------------------
  |  |  174|    438|#define DTA_111_TYPE_CODE_INT32    0xFD
  ------------------
  |  Branch (265:13): [True: 438, False: 21.0k]
  ------------------
  266|    438|                len = 4; type = READSTAT_TYPE_INT32; break;
  267|    491|            case DTA_111_TYPE_CODE_FLOAT:
  ------------------
  |  |  175|    491|#define DTA_111_TYPE_CODE_FLOAT    0xFE
  ------------------
  |  Branch (267:13): [True: 491, False: 20.9k]
  ------------------
  268|    491|                len = 4; type = READSTAT_TYPE_FLOAT; break;
  269|    640|            case DTA_111_TYPE_CODE_DOUBLE:
  ------------------
  |  |  176|    640|#define DTA_111_TYPE_CODE_DOUBLE   0xFF
  ------------------
  |  Branch (269:13): [True: 640, False: 20.8k]
  ------------------
  270|    640|                len = 8; type = READSTAT_TYPE_DOUBLE; break;
  271|  18.5k|            default:
  ------------------
  |  Branch (271:13): [True: 18.5k, False: 2.87k]
  ------------------
  272|  18.5k|                len = typecode; type = READSTAT_TYPE_STRING; break;
  273|  21.4k|        }
  274|   132k|    } else if (ctx->typlist_version == 117) {
  ------------------
  |  Branch (274:16): [True: 20.1k, False: 111k]
  ------------------
  275|  20.1k|        switch (typecode) {
  276|  2.93k|            case DTA_117_TYPE_CODE_INT8:
  ------------------
  |  |  165|  2.93k|#define DTA_117_TYPE_CODE_INT8     0xFFFA
  ------------------
  |  Branch (276:13): [True: 2.93k, False: 17.2k]
  ------------------
  277|  2.93k|                len = 1; type = READSTAT_TYPE_INT8; break;
  278|  1.73k|            case DTA_117_TYPE_CODE_INT16:
  ------------------
  |  |  166|  1.73k|#define DTA_117_TYPE_CODE_INT16    0xFFF9
  ------------------
  |  Branch (278:13): [True: 1.73k, False: 18.4k]
  ------------------
  279|  1.73k|                len = 2; type = READSTAT_TYPE_INT16; break;
  280|    481|            case DTA_117_TYPE_CODE_INT32:
  ------------------
  |  |  167|    481|#define DTA_117_TYPE_CODE_INT32    0xFFF8
  ------------------
  |  Branch (280:13): [True: 481, False: 19.6k]
  ------------------
  281|    481|                len = 4; type = READSTAT_TYPE_INT32; break;
  282|    618|            case DTA_117_TYPE_CODE_FLOAT:
  ------------------
  |  |  168|    618|#define DTA_117_TYPE_CODE_FLOAT    0xFFF7
  ------------------
  |  Branch (282:13): [True: 618, False: 19.5k]
  ------------------
  283|    618|                len = 4; type = READSTAT_TYPE_FLOAT; break;
  284|    805|            case DTA_117_TYPE_CODE_DOUBLE:
  ------------------
  |  |  169|    805|#define DTA_117_TYPE_CODE_DOUBLE   0xFFF6
  ------------------
  |  Branch (284:13): [True: 805, False: 19.3k]
  ------------------
  285|    805|                len = 8; type = READSTAT_TYPE_DOUBLE; break;
  286|  9.96k|            case DTA_117_TYPE_CODE_STRL:
  ------------------
  |  |  170|  9.96k|#define DTA_117_TYPE_CODE_STRL     0x8000
  ------------------
  |  Branch (286:13): [True: 9.96k, False: 10.1k]
  ------------------
  287|  9.96k|                len = 8; type = READSTAT_TYPE_STRING_REF; break;
  288|  3.62k|            default:
  ------------------
  |  Branch (288:13): [True: 3.62k, False: 16.5k]
  ------------------
  289|  3.62k|                len = typecode; type = READSTAT_TYPE_STRING; break;
  290|  20.1k|        }
  291|   111k|    } else if (typecode < 0x7F) {
  ------------------
  |  Branch (291:16): [True: 53.7k, False: 58.1k]
  ------------------
  292|  53.7k|        switch (typecode) {
  293|  50.5k|            case DTA_OLD_TYPE_CODE_INT8:
  ------------------
  |  |  178|  50.5k|#define DTA_OLD_TYPE_CODE_INT8     'b'
  ------------------
  |  Branch (293:13): [True: 50.5k, False: 3.22k]
  ------------------
  294|  50.5k|                len = 1; type = READSTAT_TYPE_INT8; break;
  295|    973|            case DTA_OLD_TYPE_CODE_INT16:
  ------------------
  |  |  179|    973|#define DTA_OLD_TYPE_CODE_INT16    'i'
  ------------------
  |  Branch (295:13): [True: 973, False: 52.7k]
  ------------------
  296|    973|                len = 2; type = READSTAT_TYPE_INT16; break;
  297|    750|            case DTA_OLD_TYPE_CODE_INT32:
  ------------------
  |  |  180|    750|#define DTA_OLD_TYPE_CODE_INT32    'l'
  ------------------
  |  Branch (297:13): [True: 750, False: 53.0k]
  ------------------
  298|    750|                len = 4; type = READSTAT_TYPE_INT32; break;
  299|    695|            case DTA_OLD_TYPE_CODE_FLOAT:
  ------------------
  |  |  181|    695|#define DTA_OLD_TYPE_CODE_FLOAT    'f'
  ------------------
  |  Branch (299:13): [True: 695, False: 53.0k]
  ------------------
  300|    695|                len = 4; type = READSTAT_TYPE_FLOAT; break;
  301|    787|            case DTA_OLD_TYPE_CODE_DOUBLE:
  ------------------
  |  |  182|    787|#define DTA_OLD_TYPE_CODE_DOUBLE   'd'
  ------------------
  |  Branch (301:13): [True: 787, False: 52.9k]
  ------------------
  302|    787|                len = 8; type = READSTAT_TYPE_DOUBLE; break;
  303|     16|            default:
  ------------------
  |  Branch (303:13): [True: 16, False: 53.7k]
  ------------------
  304|     16|                retval = READSTAT_ERROR_PARSE; break;
  305|  53.7k|        }
  306|  58.1k|    } else {
  307|  58.1k|        len = typecode - 0x7F;
  308|  58.1k|        type = READSTAT_TYPE_STRING;
  309|  58.1k|    }
  310|       |    
  311|   153k|    if (max_len)
  ------------------
  |  Branch (311:9): [True: 153k, False: 0]
  ------------------
  312|   153k|        *max_len = len;
  313|   153k|    if (out_type)
  ------------------
  |  Branch (313:9): [True: 88.7k, False: 64.8k]
  ------------------
  314|  88.7k|        *out_type = type;
  315|       |
  316|   153k|    return retval;
  317|   153k|}

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

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

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

