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

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

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

readstat_convert:
    7|   217k|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|   222k|    while (src_len && (src[src_len-1] == ' ' || src[src_len-1] == '\0')) {
  ------------------
  |  Branch (10:12): [True: 193k, False: 28.9k]
  |  Branch (10:24): [True: 2.56k, False: 190k]
  |  Branch (10:49): [True: 1.61k, False: 188k]
  ------------------
   11|  4.18k|        src_len--;
   12|  4.18k|    }
   13|   217k|    if (dst_len == 0) {
  ------------------
  |  Branch (13:9): [True: 0, False: 217k]
  ------------------
   14|      0|        return READSTAT_ERROR_CONVERT_LONG_STRING;
   15|   217k|    } else if (converter) {
  ------------------
  |  Branch (15:16): [True: 215k, False: 1.87k]
  ------------------
   16|   215k|        size_t dst_left = dst_len - 1;
   17|   215k|        char *dst_end = dst;
   18|   215k|        size_t status = iconv(converter, (readstat_iconv_inbuf_t)&src, &src_len, &dst_end, &dst_left);
   19|   215k|        if (status == (size_t)-1) {
  ------------------
  |  Branch (19:13): [True: 1.47k, False: 214k]
  ------------------
   20|  1.47k|            if (errno == E2BIG) {
  ------------------
  |  Branch (20:17): [True: 1, False: 1.47k]
  ------------------
   21|      1|                return READSTAT_ERROR_CONVERT_LONG_STRING;
   22|  1.47k|            } else if (errno == EILSEQ) {
  ------------------
  |  Branch (22:24): [True: 1.47k, False: 0]
  ------------------
   23|  1.47k|                return READSTAT_ERROR_CONVERT_BAD_STRING;
   24|  1.47k|            } 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.47k|        }
   28|   214k|        dst[dst_len - dst_left - 1] = '\0';
   29|   214k|    } else if (src_len + 1 > dst_len) {
  ------------------
  |  Branch (29:16): [True: 16, False: 1.85k]
  ------------------
   30|     16|        return READSTAT_ERROR_CONVERT_LONG_STRING;
   31|  1.85k|    } else {
   32|  1.85k|        memcpy(dst, src, src_len);
   33|  1.85k|        dst[src_len] = '\0';
   34|  1.85k|    }
   35|   216k|    return READSTAT_OK;
   36|   217k|}

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

readstat_malloc:
   10|   165k|void *readstat_malloc(size_t len) {
   11|   165k|    if (len > MAX_MALLOC_SIZE || len == 0) {
  ------------------
  |  |    3|   330k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
  |  Branch (11:9): [True: 36, False: 165k]
  |  Branch (11:34): [True: 0, False: 165k]
  ------------------
   12|     36|        return NULL;
   13|     36|    }
   14|   165k|    return malloc(len);
   15|   165k|}
readstat_calloc:
   17|  2.94k|void *readstat_calloc(size_t count, size_t size) {
   18|  2.94k|    if (count > MAX_MALLOC_SIZE || size > MAX_MALLOC_SIZE || count * size > MAX_MALLOC_SIZE) {
  ------------------
  |  |    3|  5.88k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
                  if (count > MAX_MALLOC_SIZE || size > MAX_MALLOC_SIZE || count * size > MAX_MALLOC_SIZE) {
  ------------------
  |  |    3|  5.83k|#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: 50, False: 2.89k]
  |  Branch (18:36): [True: 0, False: 2.89k]
  |  Branch (18:62): [True: 17, False: 2.87k]
  ------------------
   19|     67|        return NULL;
   20|     67|    }
   21|  2.87k|    if (count == 0 || size == 0) {
  ------------------
  |  Branch (21:9): [True: 0, False: 2.87k]
  |  Branch (21:23): [True: 0, False: 2.87k]
  ------------------
   22|      0|        return NULL;
   23|      0|    }
   24|  2.87k|    return calloc(count, size);
   25|  2.87k|}
readstat_realloc:
   27|  6.51k|void *readstat_realloc(void *ptr, size_t len) {
   28|  6.51k|    if (len > MAX_MALLOC_SIZE || len == 0) {
  ------------------
  |  |    3|  13.0k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
  |  Branch (28:9): [True: 45, False: 6.46k]
  |  Branch (28:34): [True: 6, False: 6.46k]
  ------------------
   29|     51|        if (ptr)
  ------------------
  |  Branch (29:13): [True: 7, False: 44]
  ------------------
   30|      7|            free(ptr);
   31|     51|        return NULL;
   32|     51|    }
   33|  6.46k|    return realloc(ptr, len);
   34|  6.51k|}

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

dta_ctx_alloc:
   17|  4.32k|dta_ctx_t *dta_ctx_alloc(readstat_io_t *io) {
   18|  4.32k|    dta_ctx_t *ctx = calloc(1, sizeof(dta_ctx_t));
   19|  4.32k|    if (ctx == NULL) {
  ------------------
  |  Branch (19:9): [True: 0, False: 4.32k]
  ------------------
   20|      0|        return NULL;
   21|      0|    }
   22|       |
   23|  4.32k|    ctx->io = io;
   24|  4.32k|    ctx->initialized = 0;
   25|       |
   26|  4.32k|    return ctx;
   27|  4.32k|}
dta_ctx_init:
   31|  3.85k|        const char *input_encoding, const char *output_encoding) {
   32|  3.85k|    readstat_error_t retval = READSTAT_OK;
   33|  3.85k|    int machine_byteorder = DTA_HILO;
  ------------------
  |  |  129|  3.85k|#define DTA_HILO  0x01
  ------------------
   34|  3.85k|    if (ds_format < DTA_MIN_VERSION || ds_format > DTA_MAX_VERSION)
  ------------------
  |  |   14|  7.71k|#define DTA_MIN_VERSION 104
  ------------------
                  if (ds_format < DTA_MIN_VERSION || ds_format > DTA_MAX_VERSION)
  ------------------
  |  |   15|  3.85k|#define DTA_MAX_VERSION 119
  ------------------
  |  Branch (34:9): [True: 6, False: 3.85k]
  |  Branch (34:40): [True: 8, False: 3.84k]
  ------------------
   35|     14|        return READSTAT_ERROR_UNSUPPORTED_FILE_FORMAT_VERSION;
   36|       |
   37|  3.84k|    if (machine_is_little_endian()) {
  ------------------
  |  Branch (37:9): [True: 3.84k, False: 0]
  ------------------
   38|  3.84k|        machine_byteorder = DTA_LOHI;
  ------------------
  |  |  130|  3.84k|#define DTA_LOHI  0x02
  ------------------
   39|  3.84k|    }
   40|       |
   41|  3.84k|    ctx->bswap = (byteorder != machine_byteorder);
   42|  3.84k|    ctx->ds_format = ds_format;
   43|  3.84k|    ctx->endianness = byteorder == DTA_LOHI ? READSTAT_ENDIAN_LITTLE : READSTAT_ENDIAN_BIG;
  ------------------
  |  |  130|  3.84k|#define DTA_LOHI  0x02
  ------------------
  |  Branch (43:23): [True: 1.32k, False: 2.52k]
  ------------------
   44|       |
   45|  3.84k|    ctx->nvar = nvar;
   46|  3.84k|    ctx->nobs = nobs;
   47|       |
   48|  3.84k|    if (ctx->nvar) {
  ------------------
  |  Branch (48:9): [True: 2.94k, False: 901]
  ------------------
   49|  2.94k|        if ((ctx->variables = readstat_calloc(ctx->nvar, sizeof(readstat_variable_t *))) == NULL) {
  ------------------
  |  Branch (49:13): [True: 67, False: 2.87k]
  ------------------
   50|     67|            retval = READSTAT_ERROR_MALLOC;
   51|     67|            goto cleanup;
   52|     67|        }
   53|  2.94k|    }
   54|       |
   55|  3.77k|    ctx->machine_is_twos_complement = READSTAT_MACHINE_IS_TWOS_COMPLEMENT;
  ------------------
  |  |    8|  3.77k|#define READSTAT_MACHINE_IS_TWOS_COMPLEMENT 0
  ------------------
   56|       |
   57|  3.77k|    if (ds_format < 105) {
  ------------------
  |  Branch (57:9): [True: 730, False: 3.04k]
  ------------------
   58|    730|        ctx->fmtlist_entry_len = 7;
   59|  3.04k|    } else if (ds_format < 114) {
  ------------------
  |  Branch (59:16): [True: 881, False: 2.16k]
  ------------------
   60|    881|        ctx->fmtlist_entry_len = 12;
   61|  2.16k|    } else if (ds_format < 118) {
  ------------------
  |  Branch (61:16): [True: 1.75k, False: 409]
  ------------------
   62|  1.75k|        ctx->fmtlist_entry_len = 49;
   63|  1.75k|    } else {
   64|    409|        ctx->fmtlist_entry_len = 57;
   65|    409|    }
   66|       |    
   67|  3.77k|    if (ds_format >= 117) {
  ------------------
  |  Branch (67:9): [True: 2.12k, False: 1.65k]
  ------------------
   68|  2.12k|        ctx->typlist_version = 117;
   69|  2.12k|    } else if (ds_format >= 111) {
  ------------------
  |  Branch (69:16): [True: 315, False: 1.33k]
  ------------------
   70|    315|        ctx->typlist_version = 111;
   71|  1.33k|    } else {
   72|  1.33k|        ctx->typlist_version = 0;
   73|  1.33k|    }
   74|       |
   75|  3.77k|    if (ds_format >= 118) {
  ------------------
  |  Branch (75:9): [True: 409, False: 3.36k]
  ------------------
   76|    409|        ctx->data_label_len_len = 2;
   77|    409|        ctx->strl_v_len = 2;
   78|    409|        ctx->strl_o_len = 6;
   79|  3.36k|    } else if (ds_format >= 117) {
  ------------------
  |  Branch (79:16): [True: 1.71k, False: 1.65k]
  ------------------
   80|  1.71k|        ctx->data_label_len_len = 1;
   81|  1.71k|        ctx->strl_v_len = 4;
   82|  1.71k|        ctx->strl_o_len = 4;
   83|  1.71k|    }
   84|       |
   85|  3.77k|    if (ds_format < 105) {
  ------------------
  |  Branch (85:9): [True: 730, False: 3.04k]
  ------------------
   86|    730|        ctx->expansion_len_len = 0;
   87|  3.04k|    } else if (ds_format < 110) {
  ------------------
  |  Branch (87:16): [True: 605, False: 2.44k]
  ------------------
   88|    605|        ctx->expansion_len_len = 2;
   89|  2.44k|    } else {
   90|  2.44k|        ctx->expansion_len_len = 4;
   91|  2.44k|    }
   92|       |    
   93|  3.77k|    if (ds_format < 110) {
  ------------------
  |  Branch (93:9): [True: 1.33k, False: 2.44k]
  ------------------
   94|  1.33k|        ctx->lbllist_entry_len = 9;
   95|  1.33k|        ctx->variable_name_len = 9;
   96|  1.33k|        ctx->ch_metadata_len = 9;
   97|  2.44k|    } else if (ds_format < 118) {
  ------------------
  |  Branch (97:16): [True: 2.03k, False: 409]
  ------------------
   98|  2.03k|        ctx->lbllist_entry_len = 33;
   99|  2.03k|        ctx->variable_name_len = 33;
  100|  2.03k|        ctx->ch_metadata_len = 33;
  101|  2.03k|    } else {
  102|    409|        ctx->lbllist_entry_len = 129;
  103|    409|        ctx->variable_name_len = 129;
  104|    409|        ctx->ch_metadata_len = 129;
  105|    409|    }
  106|       |
  107|  3.77k|    if (ds_format < 108) {
  ------------------
  |  Branch (107:9): [True: 1.33k, False: 2.44k]
  ------------------
  108|  1.33k|        ctx->variable_labels_entry_len = 32;
  109|  1.33k|        ctx->data_label_len = 32;
  110|  2.44k|    } else if (ds_format < 118) {
  ------------------
  |  Branch (110:16): [True: 2.03k, False: 409]
  ------------------
  111|  2.03k|        ctx->variable_labels_entry_len = 81;
  112|  2.03k|        ctx->data_label_len = 81;
  113|  2.03k|    } else {
  114|    409|        ctx->variable_labels_entry_len = 321;
  115|    409|        ctx->data_label_len = 321;
  116|    409|    }
  117|       |
  118|  3.77k|    if (ds_format < 105) {
  ------------------
  |  Branch (118:9): [True: 730, False: 3.04k]
  ------------------
  119|    730|        ctx->timestamp_len = 0;
  120|    730|        ctx->value_label_table_len_len = 2;
  121|    730|        ctx->value_label_table_labname_len = 12;
  122|    730|        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.63k, False: 409]
  ------------------
  127|  2.63k|            ctx->value_label_table_labname_len = 33;
  128|  2.63k|        } else {
  129|    409|            ctx->value_label_table_labname_len = 129;
  130|    409|        }
  131|  3.04k|        ctx->value_label_table_padding_len = 3;
  132|  3.04k|    }
  133|       |
  134|  3.77k|    if (ds_format < 117) {
  ------------------
  |  Branch (134:9): [True: 1.65k, False: 2.12k]
  ------------------
  135|  1.65k|        ctx->typlist_entry_len = 1;
  136|  1.65k|        ctx->file_is_xmlish = 0;
  137|  2.12k|    } else {
  138|  2.12k|        ctx->typlist_entry_len = 2;
  139|  2.12k|        ctx->file_is_xmlish = 1;
  140|  2.12k|    }
  141|       |
  142|  3.77k|    if (ds_format < 113) {
  ------------------
  |  Branch (142:9): [True: 1.34k, False: 2.43k]
  ------------------
  143|  1.34k|        ctx->max_int8 = DTA_OLD_MAX_INT8;
  ------------------
  |  |  132|  1.34k|#define DTA_OLD_MAX_INT8                     0x7e
  ------------------
  144|  1.34k|        ctx->max_int16 = DTA_OLD_MAX_INT16;
  ------------------
  |  |  133|  1.34k|#define DTA_OLD_MAX_INT16                  0x7ffe
  ------------------
  145|  1.34k|        ctx->max_int32 = DTA_OLD_MAX_INT32;
  ------------------
  |  |  134|  1.34k|#define DTA_OLD_MAX_INT32              0x7ffffffe
  ------------------
  146|  1.34k|        ctx->max_float = DTA_OLD_MAX_FLOAT;
  ------------------
  |  |  135|  1.34k|#define DTA_OLD_MAX_FLOAT              0x7effffff // +1.7e38f
  ------------------
  147|  1.34k|        ctx->max_double = DTA_OLD_MAX_DOUBLE;
  ------------------
  |  |  136|  1.34k|#define DTA_OLD_MAX_DOUBLE     0x7fdfffffffffffffL // +8.9e307
  ------------------
  148|  2.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.77k|    if (output_encoding) {
  ------------------
  |  Branch (158:9): [True: 3.77k, False: 0]
  ------------------
  159|  3.77k|        if (input_encoding) {
  ------------------
  |  Branch (159:13): [True: 0, False: 3.77k]
  ------------------
  160|      0|            ctx->converter = iconv_open(output_encoding, input_encoding);
  161|  3.77k|        } else if (ds_format < 118) {
  ------------------
  |  Branch (161:20): [True: 3.36k, False: 409]
  ------------------
  162|  3.36k|            ctx->converter = iconv_open(output_encoding, "WINDOWS-1252");
  163|  3.36k|        } else if (strcmp(output_encoding, "UTF-8") != 0) {
  ------------------
  |  Branch (163:20): [True: 0, False: 409]
  ------------------
  164|      0|            ctx->converter = iconv_open(output_encoding, "UTF-8");
  165|      0|        }
  166|  3.77k|        if (ctx->converter == (iconv_t)-1) {
  ------------------
  |  Branch (166:13): [True: 0, False: 3.77k]
  ------------------
  167|      0|            ctx->converter = NULL;
  168|      0|            retval = READSTAT_ERROR_UNSUPPORTED_CHARSET;
  169|      0|            goto cleanup;
  170|      0|        }
  171|  3.77k|    }
  172|       |
  173|  3.77k|    if (ds_format < 119) {
  ------------------
  |  Branch (173:9): [True: 3.68k, False: 91]
  ------------------
  174|  3.68k|        ctx->srtlist_len = (ctx->nvar + 1) * sizeof(int16_t);
  175|  3.68k|    } else {
  176|     91|        ctx->srtlist_len = (ctx->nvar + 1) * sizeof(int32_t);
  177|     91|    }
  178|       |
  179|  3.77k|    if ((ctx->srtlist = readstat_malloc(ctx->srtlist_len)) == NULL) {
  ------------------
  |  Branch (179:9): [True: 0, False: 3.77k]
  ------------------
  180|      0|        retval = READSTAT_ERROR_MALLOC;
  181|      0|        goto cleanup;
  182|      0|    }
  183|       |
  184|  3.77k|    if (ctx->nvar > 0) {
  ------------------
  |  Branch (184:9): [True: 2.87k, False: 901]
  ------------------
  185|  2.87k|        ctx->typlist_len = ctx->nvar * sizeof(uint16_t);
  186|  2.87k|        ctx->varlist_len = ctx->variable_name_len * ctx->nvar * sizeof(char);
  187|  2.87k|        ctx->fmtlist_len = ctx->fmtlist_entry_len * ctx->nvar * sizeof(char);
  188|  2.87k|        ctx->lbllist_len = ctx->lbllist_entry_len * ctx->nvar * sizeof(char);
  189|  2.87k|        ctx->variable_labels_len = ctx->variable_labels_entry_len * ctx->nvar * sizeof(char);
  190|       |
  191|  2.87k|        if ((ctx->typlist = readstat_malloc(ctx->typlist_len)) == NULL) {
  ------------------
  |  Branch (191:13): [True: 0, False: 2.87k]
  ------------------
  192|      0|            retval = READSTAT_ERROR_MALLOC;
  193|      0|            goto cleanup;
  194|      0|        }
  195|  2.87k|        if ((ctx->varlist = readstat_malloc(ctx->varlist_len)) == NULL) {
  ------------------
  |  Branch (195:13): [True: 25, False: 2.85k]
  ------------------
  196|     25|            retval = READSTAT_ERROR_MALLOC;
  197|     25|            goto cleanup;
  198|     25|        }
  199|  2.85k|        if ((ctx->fmtlist = readstat_malloc(ctx->fmtlist_len)) == NULL) {
  ------------------
  |  Branch (199:13): [True: 0, False: 2.85k]
  ------------------
  200|      0|            retval = READSTAT_ERROR_MALLOC;
  201|      0|            goto cleanup;
  202|      0|        }
  203|  2.85k|        if ((ctx->lbllist = readstat_malloc(ctx->lbllist_len)) == NULL) {
  ------------------
  |  Branch (203:13): [True: 0, False: 2.85k]
  ------------------
  204|      0|            retval = READSTAT_ERROR_MALLOC;
  205|      0|            goto cleanup;
  206|      0|        }
  207|  2.85k|        if ((ctx->variable_labels = readstat_malloc(ctx->variable_labels_len)) == NULL) {
  ------------------
  |  Branch (207:13): [True: 5, False: 2.84k]
  ------------------
  208|      5|            retval = READSTAT_ERROR_MALLOC;
  209|      5|            goto cleanup;
  210|      5|        }
  211|  2.85k|    }
  212|       |
  213|  3.74k|    ctx->initialized = 1;
  214|       |
  215|  3.84k|cleanup:
  216|  3.84k|    return retval;
  217|  3.74k|}
dta_ctx_free:
  219|  4.32k|void dta_ctx_free(dta_ctx_t *ctx) {
  220|  4.32k|    if (ctx->typlist)
  ------------------
  |  Branch (220:9): [True: 2.87k, False: 1.44k]
  ------------------
  221|  2.87k|        free(ctx->typlist);
  222|  4.32k|    if (ctx->varlist)
  ------------------
  |  Branch (222:9): [True: 2.85k, False: 1.47k]
  ------------------
  223|  2.85k|        free(ctx->varlist);
  224|  4.32k|    if (ctx->srtlist)
  ------------------
  |  Branch (224:9): [True: 3.77k, False: 545]
  ------------------
  225|  3.77k|        free(ctx->srtlist);
  226|  4.32k|    if (ctx->fmtlist)
  ------------------
  |  Branch (226:9): [True: 2.85k, False: 1.47k]
  ------------------
  227|  2.85k|        free(ctx->fmtlist);
  228|  4.32k|    if (ctx->lbllist)
  ------------------
  |  Branch (228:9): [True: 2.85k, False: 1.47k]
  ------------------
  229|  2.85k|        free(ctx->lbllist);
  230|  4.32k|    if (ctx->variable_labels)
  ------------------
  |  Branch (230:9): [True: 2.84k, False: 1.47k]
  ------------------
  231|  2.84k|        free(ctx->variable_labels);
  232|  4.32k|    if (ctx->converter)
  ------------------
  |  Branch (232:9): [True: 3.36k, False: 954]
  ------------------
  233|  3.36k|        iconv_close(ctx->converter);
  234|  4.32k|    if (ctx->data_label)
  ------------------
  |  Branch (234:9): [True: 3.51k, False: 812]
  ------------------
  235|  3.51k|        free(ctx->data_label);
  236|  4.32k|    if (ctx->variables) {
  ------------------
  |  Branch (236:9): [True: 2.87k, False: 1.44k]
  ------------------
  237|  2.87k|        int i;
  238|  55.3M|        for (i=0; i<ctx->nvar; i++) {
  ------------------
  |  Branch (238:19): [True: 55.3M, False: 2.87k]
  ------------------
  239|  55.3M|            if (ctx->variables[i])
  ------------------
  |  Branch (239:17): [True: 41.5k, False: 55.3M]
  ------------------
  240|  41.5k|                free(ctx->variables[i]);
  241|  55.3M|        }
  242|  2.87k|        free(ctx->variables);
  243|  2.87k|    }
  244|  4.32k|    if (ctx->strls) {
  ------------------
  |  Branch (244:9): [True: 841, False: 3.48k]
  ------------------
  245|    841|        int i;
  246|   135k|        for (i=0; i<ctx->strls_count; i++) {
  ------------------
  |  Branch (246:19): [True: 134k, False: 841]
  ------------------
  247|   134k|            free(ctx->strls[i]);
  248|   134k|        }
  249|    841|        free(ctx->strls);
  250|    841|    }
  251|  4.32k|    free(ctx);
  252|  4.32k|}
dta_type_info:
  255|   168k|        size_t *max_len, readstat_type_t *out_type) {
  256|   168k|    readstat_error_t retval = READSTAT_OK;
  257|   168k|    size_t len = 0;
  258|   168k|    readstat_type_t type = READSTAT_TYPE_STRING;
  259|   168k|    if (ctx->typlist_version == 111) {
  ------------------
  |  Branch (259:9): [True: 53.2k, False: 115k]
  ------------------
  260|  53.2k|        switch (typecode) {
  261|    896|            case DTA_111_TYPE_CODE_INT8:
  ------------------
  |  |  172|    896|#define DTA_111_TYPE_CODE_INT8     0xFB
  ------------------
  |  Branch (261:13): [True: 896, False: 52.3k]
  ------------------
  262|    896|                len = 1; type = READSTAT_TYPE_INT8; break;
  263|    431|            case DTA_111_TYPE_CODE_INT16:
  ------------------
  |  |  173|    431|#define DTA_111_TYPE_CODE_INT16    0xFC
  ------------------
  |  Branch (263:13): [True: 431, False: 52.8k]
  ------------------
  264|    431|                len = 2; type = READSTAT_TYPE_INT16; break;
  265|  11.9k|            case DTA_111_TYPE_CODE_INT32:
  ------------------
  |  |  174|  11.9k|#define DTA_111_TYPE_CODE_INT32    0xFD
  ------------------
  |  Branch (265:13): [True: 11.9k, False: 41.2k]
  ------------------
  266|  11.9k|                len = 4; type = READSTAT_TYPE_INT32; break;
  267|    509|            case DTA_111_TYPE_CODE_FLOAT:
  ------------------
  |  |  175|    509|#define DTA_111_TYPE_CODE_FLOAT    0xFE
  ------------------
  |  Branch (267:13): [True: 509, False: 52.7k]
  ------------------
  268|    509|                len = 4; type = READSTAT_TYPE_FLOAT; break;
  269|  1.46k|            case DTA_111_TYPE_CODE_DOUBLE:
  ------------------
  |  |  176|  1.46k|#define DTA_111_TYPE_CODE_DOUBLE   0xFF
  ------------------
  |  Branch (269:13): [True: 1.46k, False: 51.7k]
  ------------------
  270|  1.46k|                len = 8; type = READSTAT_TYPE_DOUBLE; break;
  271|  37.9k|            default:
  ------------------
  |  Branch (271:13): [True: 37.9k, False: 15.2k]
  ------------------
  272|  37.9k|                len = typecode; type = READSTAT_TYPE_STRING; break;
  273|  53.2k|        }
  274|   115k|    } else if (ctx->typlist_version == 117) {
  ------------------
  |  Branch (274:16): [True: 66.0k, False: 49.1k]
  ------------------
  275|  66.0k|        switch (typecode) {
  276|    902|            case DTA_117_TYPE_CODE_INT8:
  ------------------
  |  |  165|    902|#define DTA_117_TYPE_CODE_INT8     0xFFFA
  ------------------
  |  Branch (276:13): [True: 902, False: 65.1k]
  ------------------
  277|    902|                len = 1; type = READSTAT_TYPE_INT8; break;
  278|    743|            case DTA_117_TYPE_CODE_INT16:
  ------------------
  |  |  166|    743|#define DTA_117_TYPE_CODE_INT16    0xFFF9
  ------------------
  |  Branch (278:13): [True: 743, False: 65.3k]
  ------------------
  279|    743|                len = 2; type = READSTAT_TYPE_INT16; break;
  280|  1.76k|            case DTA_117_TYPE_CODE_INT32:
  ------------------
  |  |  167|  1.76k|#define DTA_117_TYPE_CODE_INT32    0xFFF8
  ------------------
  |  Branch (280:13): [True: 1.76k, False: 64.3k]
  ------------------
  281|  1.76k|                len = 4; type = READSTAT_TYPE_INT32; break;
  282|    848|            case DTA_117_TYPE_CODE_FLOAT:
  ------------------
  |  |  168|    848|#define DTA_117_TYPE_CODE_FLOAT    0xFFF7
  ------------------
  |  Branch (282:13): [True: 848, False: 65.2k]
  ------------------
  283|    848|                len = 4; type = READSTAT_TYPE_FLOAT; break;
  284|    904|            case DTA_117_TYPE_CODE_DOUBLE:
  ------------------
  |  |  169|    904|#define DTA_117_TYPE_CODE_DOUBLE   0xFFF6
  ------------------
  |  Branch (284:13): [True: 904, False: 65.1k]
  ------------------
  285|    904|                len = 8; type = READSTAT_TYPE_DOUBLE; break;
  286|  57.8k|            case DTA_117_TYPE_CODE_STRL:
  ------------------
  |  |  170|  57.8k|#define DTA_117_TYPE_CODE_STRL     0x8000
  ------------------
  |  Branch (286:13): [True: 57.8k, False: 8.17k]
  ------------------
  287|  57.8k|                len = 8; type = READSTAT_TYPE_STRING_REF; break;
  288|  3.01k|            default:
  ------------------
  |  Branch (288:13): [True: 3.01k, False: 63.0k]
  ------------------
  289|  3.01k|                len = typecode; type = READSTAT_TYPE_STRING; break;
  290|  66.0k|        }
  291|  66.0k|    } else if (typecode < 0x7F) {
  ------------------
  |  Branch (291:16): [True: 33.8k, False: 15.3k]
  ------------------
  292|  33.8k|        switch (typecode) {
  293|  30.7k|            case DTA_OLD_TYPE_CODE_INT8:
  ------------------
  |  |  178|  30.7k|#define DTA_OLD_TYPE_CODE_INT8     'b'
  ------------------
  |  Branch (293:13): [True: 30.7k, False: 3.04k]
  ------------------
  294|  30.7k|                len = 1; type = READSTAT_TYPE_INT8; break;
  295|    948|            case DTA_OLD_TYPE_CODE_INT16:
  ------------------
  |  |  179|    948|#define DTA_OLD_TYPE_CODE_INT16    'i'
  ------------------
  |  Branch (295:13): [True: 948, False: 32.8k]
  ------------------
  296|    948|                len = 2; type = READSTAT_TYPE_INT16; break;
  297|    699|            case DTA_OLD_TYPE_CODE_INT32:
  ------------------
  |  |  180|    699|#define DTA_OLD_TYPE_CODE_INT32    'l'
  ------------------
  |  Branch (297:13): [True: 699, False: 33.1k]
  ------------------
  298|    699|                len = 4; type = READSTAT_TYPE_INT32; break;
  299|    586|            case DTA_OLD_TYPE_CODE_FLOAT:
  ------------------
  |  |  181|    586|#define DTA_OLD_TYPE_CODE_FLOAT    'f'
  ------------------
  |  Branch (299:13): [True: 586, False: 33.2k]
  ------------------
  300|    586|                len = 4; type = READSTAT_TYPE_FLOAT; break;
  301|    797|            case DTA_OLD_TYPE_CODE_DOUBLE:
  ------------------
  |  |  182|    797|#define DTA_OLD_TYPE_CODE_DOUBLE   'd'
  ------------------
  |  Branch (301:13): [True: 797, False: 33.0k]
  ------------------
  302|    797|                len = 8; type = READSTAT_TYPE_DOUBLE; break;
  303|     16|            default:
  ------------------
  |  Branch (303:13): [True: 16, False: 33.8k]
  ------------------
  304|     16|                retval = READSTAT_ERROR_PARSE; break;
  305|  33.8k|        }
  306|  33.8k|    } else {
  307|  15.3k|        len = typecode - 0x7F;
  308|  15.3k|        type = READSTAT_TYPE_STRING;
  309|  15.3k|    }
  310|       |    
  311|   168k|    if (max_len)
  ------------------
  |  Branch (311:9): [True: 168k, False: 0]
  ------------------
  312|   168k|        *max_len = len;
  313|   168k|    if (out_type)
  ------------------
  |  Branch (313:9): [True: 126k, False: 41.6k]
  ------------------
  314|   126k|        *out_type = type;
  315|       |
  316|   168k|    return retval;
  317|   168k|}

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

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

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

