fuzzer_parser_init:
   33|  4.38k|readstat_parser_t *fuzzer_parser_init(const uint8_t *Data, size_t Size) {
   34|  4.38k|    readstat_parser_t *parser = readstat_parser_init();
   35|  4.38k|    readstat_set_open_handler(parser, rt_open_handler);
   36|  4.38k|    readstat_set_close_handler(parser, rt_close_handler);
   37|  4.38k|    readstat_set_seek_handler(parser, rt_seek_handler);
   38|  4.38k|    readstat_set_read_handler(parser, rt_read_handler);
   39|  4.38k|    readstat_set_update_handler(parser, rt_update_handler);
   40|       |
   41|  4.38k|    readstat_set_metadata_handler(parser, &handle_metadata);
   42|  4.38k|    readstat_set_note_handler(parser, &handle_note);
   43|  4.38k|    readstat_set_variable_handler(parser, &handle_variable);
   44|  4.38k|    readstat_set_fweight_handler(parser, &handle_fweight);
   45|  4.38k|    readstat_set_value_handler(parser, &handle_value);
   46|  4.38k|    readstat_set_value_label_handler(parser, &handle_value_label);
   47|       |
   48|  4.38k|    return parser;
   49|  4.38k|}
fuzz_format.c:handle_metadata:
    8|  3.21k|static int handle_metadata(readstat_metadata_t *metadata, void *ctx) {
    9|  3.21k|    return READSTAT_HANDLER_OK;
   10|  3.21k|}
fuzz_format.c:handle_note:
   12|    195|static int handle_note(int index, const char *note, void *ctx) {
   13|    195|    return READSTAT_HANDLER_OK;
   14|    195|}
fuzz_format.c:handle_variable:
   21|  35.1k|                           const char *val_labels, void *ctx) {
   22|  35.1k|    return READSTAT_HANDLER_OK;
   23|  35.1k|}
fuzz_format.c:handle_value:
   25|   215k|static int handle_value(int obs_index, readstat_variable_t *variable, readstat_value_t value, void *ctx) {
   26|   215k|    return READSTAT_HANDLER_OK;
   27|   215k|}
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.38k|int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
   11|  4.38k|    rt_buffer_t buffer = { .bytes = (char *)Data, .size = Size, .used = Size };
   12|  4.38k|    rt_buffer_ctx_t buffer_ctx = { .buffer = &buffer };
   13|       |
   14|  4.38k|    readstat_parser_t *parser = fuzzer_parser_init(Data, Size);
   15|  4.38k|    readstat_set_io_ctx(parser, &buffer_ctx);
   16|       |
   17|  4.38k|    readstat_parse_dta(parser, NULL, NULL);
   18|  4.38k|    readstat_parser_free(parser);
   19|  4.38k|    return 0;
   20|  4.38k|}

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

readstat_convert:
    7|   209k|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|   213k|    while (src_len && (src[src_len-1] == ' ' || src[src_len-1] == '\0')) {
  ------------------
  |  Branch (10:12): [True: 188k, False: 25.0k]
  |  Branch (10:24): [True: 2.33k, False: 185k]
  |  Branch (10:49): [True: 1.53k, False: 184k]
  ------------------
   11|  3.87k|        src_len--;
   12|  3.87k|    }
   13|   209k|    if (dst_len == 0) {
  ------------------
  |  Branch (13:9): [True: 0, False: 209k]
  ------------------
   14|      0|        return READSTAT_ERROR_CONVERT_LONG_STRING;
   15|   209k|    } else if (converter) {
  ------------------
  |  Branch (15:16): [True: 207k, False: 2.19k]
  ------------------
   16|   207k|        size_t dst_left = dst_len - 1;
   17|   207k|        char *dst_end = dst;
   18|   207k|        size_t status = iconv(converter, (readstat_iconv_inbuf_t)&src, &src_len, &dst_end, &dst_left);
   19|   207k|        if (status == (size_t)-1) {
  ------------------
  |  Branch (19:13): [True: 1.42k, False: 205k]
  ------------------
   20|  1.42k|            if (errno == E2BIG) {
  ------------------
  |  Branch (20:17): [True: 1, False: 1.42k]
  ------------------
   21|      1|                return READSTAT_ERROR_CONVERT_LONG_STRING;
   22|  1.42k|            } else if (errno == EILSEQ) {
  ------------------
  |  Branch (22:24): [True: 1.42k, False: 0]
  ------------------
   23|  1.42k|                return READSTAT_ERROR_CONVERT_BAD_STRING;
   24|  1.42k|            } 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.42k|        }
   28|   205k|        dst[dst_len - dst_left - 1] = '\0';
   29|   205k|    } else if (src_len + 1 > dst_len) {
  ------------------
  |  Branch (29:16): [True: 14, False: 2.18k]
  ------------------
   30|     14|        return READSTAT_ERROR_CONVERT_LONG_STRING;
   31|  2.18k|    } else {
   32|  2.18k|        memcpy(dst, src, src_len);
   33|  2.18k|        dst[src_len] = '\0';
   34|  2.18k|    }
   35|   208k|    return READSTAT_OK;
   36|   209k|}

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

readstat_malloc:
   10|  63.8k|void *readstat_malloc(size_t len) {
   11|  63.8k|    if (len > MAX_MALLOC_SIZE || len == 0) {
  ------------------
  |  |    3|   127k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
  |  Branch (11:9): [True: 38, False: 63.7k]
  |  Branch (11:34): [True: 0, False: 63.7k]
  ------------------
   12|     38|        return NULL;
   13|     38|    }
   14|  63.7k|    return malloc(len);
   15|  63.8k|}
readstat_calloc:
   17|  2.98k|void *readstat_calloc(size_t count, size_t size) {
   18|  2.98k|    if (count > MAX_MALLOC_SIZE || size > MAX_MALLOC_SIZE || count * size > MAX_MALLOC_SIZE) {
  ------------------
  |  |    3|  5.97k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
                  if (count > MAX_MALLOC_SIZE || size > MAX_MALLOC_SIZE || count * size > MAX_MALLOC_SIZE) {
  ------------------
  |  |    3|  5.91k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
                  if (count > MAX_MALLOC_SIZE || size > MAX_MALLOC_SIZE || count * size > MAX_MALLOC_SIZE) {
  ------------------
  |  |    3|  2.92k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
  |  Branch (18:9): [True: 61, False: 2.92k]
  |  Branch (18:36): [True: 0, False: 2.92k]
  |  Branch (18:62): [True: 26, False: 2.90k]
  ------------------
   19|     87|        return NULL;
   20|     87|    }
   21|  2.90k|    if (count == 0 || size == 0) {
  ------------------
  |  Branch (21:9): [True: 0, False: 2.90k]
  |  Branch (21:23): [True: 0, False: 2.90k]
  ------------------
   22|      0|        return NULL;
   23|      0|    }
   24|  2.90k|    return calloc(count, size);
   25|  2.90k|}
readstat_realloc:
   27|  6.34k|void *readstat_realloc(void *ptr, size_t len) {
   28|  6.34k|    if (len > MAX_MALLOC_SIZE || len == 0) {
  ------------------
  |  |    3|  12.6k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
  |  Branch (28:9): [True: 43, False: 6.30k]
  |  Branch (28:34): [True: 6, False: 6.29k]
  ------------------
   29|     49|        if (ptr)
  ------------------
  |  Branch (29:13): [True: 7, False: 42]
  ------------------
   30|      7|            free(ptr);
   31|     49|        return NULL;
   32|     49|    }
   33|  6.29k|    return realloc(ptr, len);
   34|  6.34k|}

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

dta_ctx_alloc:
   17|  4.38k|dta_ctx_t *dta_ctx_alloc(readstat_io_t *io) {
   18|  4.38k|    dta_ctx_t *ctx = calloc(1, sizeof(dta_ctx_t));
   19|  4.38k|    if (ctx == NULL) {
  ------------------
  |  Branch (19:9): [True: 0, False: 4.38k]
  ------------------
   20|      0|        return NULL;
   21|      0|    }
   22|       |
   23|  4.38k|    ctx->io = io;
   24|  4.38k|    ctx->initialized = 0;
   25|       |
   26|  4.38k|    return ctx;
   27|  4.38k|}
dta_ctx_init:
   31|  3.91k|        const char *input_encoding, const char *output_encoding) {
   32|  3.91k|    readstat_error_t retval = READSTAT_OK;
   33|  3.91k|    int machine_byteorder = DTA_HILO;
  ------------------
  |  |  129|  3.91k|#define DTA_HILO  0x01
  ------------------
   34|  3.91k|    if (ds_format < DTA_MIN_VERSION || ds_format > DTA_MAX_VERSION)
  ------------------
  |  |   14|  7.83k|#define DTA_MIN_VERSION 104
  ------------------
                  if (ds_format < DTA_MIN_VERSION || ds_format > DTA_MAX_VERSION)
  ------------------
  |  |   15|  3.91k|#define DTA_MAX_VERSION 119
  ------------------
  |  Branch (34:9): [True: 7, False: 3.91k]
  |  Branch (34:40): [True: 7, False: 3.90k]
  ------------------
   35|     14|        return READSTAT_ERROR_UNSUPPORTED_FILE_FORMAT_VERSION;
   36|       |
   37|  3.90k|    if (machine_is_little_endian()) {
  ------------------
  |  Branch (37:9): [True: 3.90k, False: 0]
  ------------------
   38|  3.90k|        machine_byteorder = DTA_LOHI;
  ------------------
  |  |  130|  3.90k|#define DTA_LOHI  0x02
  ------------------
   39|  3.90k|    }
   40|       |
   41|  3.90k|    ctx->bswap = (byteorder != machine_byteorder);
   42|  3.90k|    ctx->ds_format = ds_format;
   43|  3.90k|    ctx->endianness = byteorder == DTA_LOHI ? READSTAT_ENDIAN_LITTLE : READSTAT_ENDIAN_BIG;
  ------------------
  |  |  130|  3.90k|#define DTA_LOHI  0x02
  ------------------
  |  Branch (43:23): [True: 1.35k, False: 2.54k]
  ------------------
   44|       |
   45|  3.90k|    ctx->nvar = nvar;
   46|  3.90k|    ctx->nobs = nobs;
   47|       |
   48|  3.90k|    if (ctx->nvar) {
  ------------------
  |  Branch (48:9): [True: 2.98k, False: 915]
  ------------------
   49|  2.98k|        if ((ctx->variables = readstat_calloc(ctx->nvar, sizeof(readstat_variable_t *))) == NULL) {
  ------------------
  |  Branch (49:13): [True: 87, False: 2.90k]
  ------------------
   50|     87|            retval = READSTAT_ERROR_MALLOC;
   51|     87|            goto cleanup;
   52|     87|        }
   53|  2.98k|    }
   54|       |
   55|  3.81k|    ctx->machine_is_twos_complement = READSTAT_MACHINE_IS_TWOS_COMPLEMENT;
  ------------------
  |  |    8|  3.81k|#define READSTAT_MACHINE_IS_TWOS_COMPLEMENT 0
  ------------------
   56|       |
   57|  3.81k|    if (ds_format < 105) {
  ------------------
  |  Branch (57:9): [True: 761, False: 3.05k]
  ------------------
   58|    761|        ctx->fmtlist_entry_len = 7;
   59|  3.05k|    } else if (ds_format < 114) {
  ------------------
  |  Branch (59:16): [True: 909, False: 2.14k]
  ------------------
   60|    909|        ctx->fmtlist_entry_len = 12;
   61|  2.14k|    } else if (ds_format < 118) {
  ------------------
  |  Branch (61:16): [True: 1.73k, False: 408]
  ------------------
   62|  1.73k|        ctx->fmtlist_entry_len = 49;
   63|  1.73k|    } else {
   64|    408|        ctx->fmtlist_entry_len = 57;
   65|    408|    }
   66|       |    
   67|  3.81k|    if (ds_format >= 117) {
  ------------------
  |  Branch (67:9): [True: 2.11k, False: 1.69k]
  ------------------
   68|  2.11k|        ctx->typlist_version = 117;
   69|  2.11k|    } else if (ds_format >= 111) {
  ------------------
  |  Branch (69:16): [True: 318, False: 1.38k]
  ------------------
   70|    318|        ctx->typlist_version = 111;
   71|  1.38k|    } else {
   72|  1.38k|        ctx->typlist_version = 0;
   73|  1.38k|    }
   74|       |
   75|  3.81k|    if (ds_format >= 118) {
  ------------------
  |  Branch (75:9): [True: 408, False: 3.40k]
  ------------------
   76|    408|        ctx->data_label_len_len = 2;
   77|    408|        ctx->strl_v_len = 2;
   78|    408|        ctx->strl_o_len = 6;
   79|  3.40k|    } else if (ds_format >= 117) {
  ------------------
  |  Branch (79:16): [True: 1.70k, False: 1.69k]
  ------------------
   80|  1.70k|        ctx->data_label_len_len = 1;
   81|  1.70k|        ctx->strl_v_len = 4;
   82|  1.70k|        ctx->strl_o_len = 4;
   83|  1.70k|    }
   84|       |
   85|  3.81k|    if (ds_format < 105) {
  ------------------
  |  Branch (85:9): [True: 761, False: 3.05k]
  ------------------
   86|    761|        ctx->expansion_len_len = 0;
   87|  3.05k|    } else if (ds_format < 110) {
  ------------------
  |  Branch (87:16): [True: 617, False: 2.43k]
  ------------------
   88|    617|        ctx->expansion_len_len = 2;
   89|  2.43k|    } else {
   90|  2.43k|        ctx->expansion_len_len = 4;
   91|  2.43k|    }
   92|       |    
   93|  3.81k|    if (ds_format < 110) {
  ------------------
  |  Branch (93:9): [True: 1.37k, False: 2.43k]
  ------------------
   94|  1.37k|        ctx->lbllist_entry_len = 9;
   95|  1.37k|        ctx->variable_name_len = 9;
   96|  1.37k|        ctx->ch_metadata_len = 9;
   97|  2.43k|    } else if (ds_format < 118) {
  ------------------
  |  Branch (97:16): [True: 2.03k, False: 408]
  ------------------
   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|    408|        ctx->lbllist_entry_len = 129;
  103|    408|        ctx->variable_name_len = 129;
  104|    408|        ctx->ch_metadata_len = 129;
  105|    408|    }
  106|       |
  107|  3.81k|    if (ds_format < 108) {
  ------------------
  |  Branch (107:9): [True: 1.37k, False: 2.44k]
  ------------------
  108|  1.37k|        ctx->variable_labels_entry_len = 32;
  109|  1.37k|        ctx->data_label_len = 32;
  110|  2.44k|    } else if (ds_format < 118) {
  ------------------
  |  Branch (110:16): [True: 2.03k, False: 408]
  ------------------
  111|  2.03k|        ctx->variable_labels_entry_len = 81;
  112|  2.03k|        ctx->data_label_len = 81;
  113|  2.03k|    } else {
  114|    408|        ctx->variable_labels_entry_len = 321;
  115|    408|        ctx->data_label_len = 321;
  116|    408|    }
  117|       |
  118|  3.81k|    if (ds_format < 105) {
  ------------------
  |  Branch (118:9): [True: 761, False: 3.05k]
  ------------------
  119|    761|        ctx->timestamp_len = 0;
  120|    761|        ctx->value_label_table_len_len = 2;
  121|    761|        ctx->value_label_table_labname_len = 12;
  122|    761|        ctx->value_label_table_padding_len = 2;
  123|  3.05k|    } else {
  124|  3.05k|        ctx->timestamp_len = 18;
  125|  3.05k|        ctx->value_label_table_len_len = 4;
  126|  3.05k|        if (ds_format < 118) {
  ------------------
  |  Branch (126:13): [True: 2.64k, False: 408]
  ------------------
  127|  2.64k|            ctx->value_label_table_labname_len = 33;
  128|  2.64k|        } else {
  129|    408|            ctx->value_label_table_labname_len = 129;
  130|    408|        }
  131|  3.05k|        ctx->value_label_table_padding_len = 3;
  132|  3.05k|    }
  133|       |
  134|  3.81k|    if (ds_format < 117) {
  ------------------
  |  Branch (134:9): [True: 1.69k, False: 2.11k]
  ------------------
  135|  1.69k|        ctx->typlist_entry_len = 1;
  136|  1.69k|        ctx->file_is_xmlish = 0;
  137|  2.11k|    } else {
  138|  2.11k|        ctx->typlist_entry_len = 2;
  139|  2.11k|        ctx->file_is_xmlish = 1;
  140|  2.11k|    }
  141|       |
  142|  3.81k|    if (ds_format < 113) {
  ------------------
  |  Branch (142:9): [True: 1.38k, False: 2.42k]
  ------------------
  143|  1.38k|        ctx->max_int8 = DTA_OLD_MAX_INT8;
  ------------------
  |  |  132|  1.38k|#define DTA_OLD_MAX_INT8                     0x7e
  ------------------
  144|  1.38k|        ctx->max_int16 = DTA_OLD_MAX_INT16;
  ------------------
  |  |  133|  1.38k|#define DTA_OLD_MAX_INT16                  0x7ffe
  ------------------
  145|  1.38k|        ctx->max_int32 = DTA_OLD_MAX_INT32;
  ------------------
  |  |  134|  1.38k|#define DTA_OLD_MAX_INT32              0x7ffffffe
  ------------------
  146|  1.38k|        ctx->max_float = DTA_OLD_MAX_FLOAT;
  ------------------
  |  |  135|  1.38k|#define DTA_OLD_MAX_FLOAT              0x7effffff // +1.7e38f
  ------------------
  147|  1.38k|        ctx->max_double = DTA_OLD_MAX_DOUBLE;
  ------------------
  |  |  136|  1.38k|#define DTA_OLD_MAX_DOUBLE     0x7fdfffffffffffffL // +8.9e307
  ------------------
  148|  2.42k|    } else {
  149|  2.42k|        ctx->max_int8 = DTA_113_MAX_INT8;
  ------------------
  |  |  144|  2.42k|#define DTA_113_MAX_INT8                    0x64
  ------------------
  150|  2.42k|        ctx->max_int16 = DTA_113_MAX_INT16;
  ------------------
  |  |  145|  2.42k|#define DTA_113_MAX_INT16                 0x7fe4
  ------------------
  151|  2.42k|        ctx->max_int32 = DTA_113_MAX_INT32;
  ------------------
  |  |  146|  2.42k|#define DTA_113_MAX_INT32             0x7fffffe4
  ------------------
  152|  2.42k|        ctx->max_float = DTA_113_MAX_FLOAT;
  ------------------
  |  |  147|  2.42k|#define DTA_113_MAX_FLOAT             0x7effffff // +1.7e38f
  ------------------
  153|  2.42k|        ctx->max_double = DTA_113_MAX_DOUBLE;
  ------------------
  |  |  148|  2.42k|#define DTA_113_MAX_DOUBLE    0x7fdfffffffffffffL // +8.9e307
  ------------------
  154|       |
  155|  2.42k|        ctx->supports_tagged_missing = 1;
  156|  2.42k|    }
  157|       |
  158|  3.81k|    if (output_encoding) {
  ------------------
  |  Branch (158:9): [True: 3.81k, False: 0]
  ------------------
  159|  3.81k|        if (input_encoding) {
  ------------------
  |  Branch (159:13): [True: 0, False: 3.81k]
  ------------------
  160|      0|            ctx->converter = iconv_open(output_encoding, input_encoding);
  161|  3.81k|        } else if (ds_format < 118) {
  ------------------
  |  Branch (161:20): [True: 3.40k, False: 408]
  ------------------
  162|  3.40k|            ctx->converter = iconv_open(output_encoding, "WINDOWS-1252");
  163|  3.40k|        } else if (strcmp(output_encoding, "UTF-8") != 0) {
  ------------------
  |  Branch (163:20): [True: 0, False: 408]
  ------------------
  164|      0|            ctx->converter = iconv_open(output_encoding, "UTF-8");
  165|      0|        }
  166|  3.81k|        if (ctx->converter == (iconv_t)-1) {
  ------------------
  |  Branch (166:13): [True: 0, False: 3.81k]
  ------------------
  167|      0|            ctx->converter = NULL;
  168|      0|            retval = READSTAT_ERROR_UNSUPPORTED_CHARSET;
  169|      0|            goto cleanup;
  170|      0|        }
  171|  3.81k|    }
  172|       |
  173|  3.81k|    if (ds_format < 119) {
  ------------------
  |  Branch (173:9): [True: 3.73k, False: 86]
  ------------------
  174|  3.73k|        ctx->srtlist_len = (ctx->nvar + 1) * sizeof(int16_t);
  175|  3.73k|    } else {
  176|     86|        ctx->srtlist_len = (ctx->nvar + 1) * sizeof(int32_t);
  177|     86|    }
  178|       |
  179|  3.81k|    if ((ctx->srtlist = readstat_malloc(ctx->srtlist_len)) == NULL) {
  ------------------
  |  Branch (179:9): [True: 0, False: 3.81k]
  ------------------
  180|      0|        retval = READSTAT_ERROR_MALLOC;
  181|      0|        goto cleanup;
  182|      0|    }
  183|       |
  184|  3.81k|    if (ctx->nvar > 0) {
  ------------------
  |  Branch (184:9): [True: 2.90k, False: 915]
  ------------------
  185|  2.90k|        ctx->typlist_len = ctx->nvar * sizeof(uint16_t);
  186|  2.90k|        ctx->varlist_len = ctx->variable_name_len * ctx->nvar * sizeof(char);
  187|  2.90k|        ctx->fmtlist_len = ctx->fmtlist_entry_len * ctx->nvar * sizeof(char);
  188|  2.90k|        ctx->lbllist_len = ctx->lbllist_entry_len * ctx->nvar * sizeof(char);
  189|  2.90k|        ctx->variable_labels_len = ctx->variable_labels_entry_len * ctx->nvar * sizeof(char);
  190|       |
  191|  2.90k|        if ((ctx->typlist = readstat_malloc(ctx->typlist_len)) == NULL) {
  ------------------
  |  Branch (191:13): [True: 0, False: 2.90k]
  ------------------
  192|      0|            retval = READSTAT_ERROR_MALLOC;
  193|      0|            goto cleanup;
  194|      0|        }
  195|  2.90k|        if ((ctx->varlist = readstat_malloc(ctx->varlist_len)) == NULL) {
  ------------------
  |  Branch (195:13): [True: 27, False: 2.87k]
  ------------------
  196|     27|            retval = READSTAT_ERROR_MALLOC;
  197|     27|            goto cleanup;
  198|     27|        }
  199|  2.87k|        if ((ctx->fmtlist = readstat_malloc(ctx->fmtlist_len)) == NULL) {
  ------------------
  |  Branch (199:13): [True: 0, False: 2.87k]
  ------------------
  200|      0|            retval = READSTAT_ERROR_MALLOC;
  201|      0|            goto cleanup;
  202|      0|        }
  203|  2.87k|        if ((ctx->lbllist = readstat_malloc(ctx->lbllist_len)) == NULL) {
  ------------------
  |  Branch (203:13): [True: 0, False: 2.87k]
  ------------------
  204|      0|            retval = READSTAT_ERROR_MALLOC;
  205|      0|            goto cleanup;
  206|      0|        }
  207|  2.87k|        if ((ctx->variable_labels = readstat_malloc(ctx->variable_labels_len)) == NULL) {
  ------------------
  |  Branch (207:13): [True: 5, False: 2.86k]
  ------------------
  208|      5|            retval = READSTAT_ERROR_MALLOC;
  209|      5|            goto cleanup;
  210|      5|        }
  211|  2.87k|    }
  212|       |
  213|  3.78k|    ctx->initialized = 1;
  214|       |
  215|  3.90k|cleanup:
  216|  3.90k|    return retval;
  217|  3.78k|}
dta_ctx_free:
  219|  4.38k|void dta_ctx_free(dta_ctx_t *ctx) {
  220|  4.38k|    if (ctx->typlist)
  ------------------
  |  Branch (220:9): [True: 2.90k, False: 1.48k]
  ------------------
  221|  2.90k|        free(ctx->typlist);
  222|  4.38k|    if (ctx->varlist)
  ------------------
  |  Branch (222:9): [True: 2.87k, False: 1.50k]
  ------------------
  223|  2.87k|        free(ctx->varlist);
  224|  4.38k|    if (ctx->srtlist)
  ------------------
  |  Branch (224:9): [True: 3.81k, False: 567]
  ------------------
  225|  3.81k|        free(ctx->srtlist);
  226|  4.38k|    if (ctx->fmtlist)
  ------------------
  |  Branch (226:9): [True: 2.87k, False: 1.50k]
  ------------------
  227|  2.87k|        free(ctx->fmtlist);
  228|  4.38k|    if (ctx->lbllist)
  ------------------
  |  Branch (228:9): [True: 2.87k, False: 1.50k]
  ------------------
  229|  2.87k|        free(ctx->lbllist);
  230|  4.38k|    if (ctx->variable_labels)
  ------------------
  |  Branch (230:9): [True: 2.86k, False: 1.51k]
  ------------------
  231|  2.86k|        free(ctx->variable_labels);
  232|  4.38k|    if (ctx->converter)
  ------------------
  |  Branch (232:9): [True: 3.40k, False: 975]
  ------------------
  233|  3.40k|        iconv_close(ctx->converter);
  234|  4.38k|    if (ctx->data_label)
  ------------------
  |  Branch (234:9): [True: 3.53k, False: 848]
  ------------------
  235|  3.53k|        free(ctx->data_label);
  236|  4.38k|    if (ctx->variables) {
  ------------------
  |  Branch (236:9): [True: 2.90k, False: 1.48k]
  ------------------
  237|  2.90k|        int i;
  238|  60.0M|        for (i=0; i<ctx->nvar; i++) {
  ------------------
  |  Branch (238:19): [True: 60.0M, False: 2.90k]
  ------------------
  239|  60.0M|            if (ctx->variables[i])
  ------------------
  |  Branch (239:17): [True: 35.1k, False: 60.0M]
  ------------------
  240|  35.1k|                free(ctx->variables[i]);
  241|  60.0M|        }
  242|  2.90k|        free(ctx->variables);
  243|  2.90k|    }
  244|  4.38k|    if (ctx->strls) {
  ------------------
  |  Branch (244:9): [True: 863, False: 3.52k]
  ------------------
  245|    863|        int i;
  246|  33.5k|        for (i=0; i<ctx->strls_count; i++) {
  ------------------
  |  Branch (246:19): [True: 32.6k, False: 863]
  ------------------
  247|  32.6k|            free(ctx->strls[i]);
  248|  32.6k|        }
  249|    863|        free(ctx->strls);
  250|    863|    }
  251|  4.38k|    free(ctx);
  252|  4.38k|}
dta_type_info:
  255|   285k|        size_t *max_len, readstat_type_t *out_type) {
  256|   285k|    readstat_error_t retval = READSTAT_OK;
  257|   285k|    size_t len = 0;
  258|   285k|    readstat_type_t type = READSTAT_TYPE_STRING;
  259|   285k|    if (ctx->typlist_version == 111) {
  ------------------
  |  Branch (259:9): [True: 41.2k, False: 244k]
  ------------------
  260|  41.2k|        switch (typecode) {
  261|    879|            case DTA_111_TYPE_CODE_INT8:
  ------------------
  |  |  172|    879|#define DTA_111_TYPE_CODE_INT8     0xFB
  ------------------
  |  Branch (261:13): [True: 879, False: 40.4k]
  ------------------
  262|    879|                len = 1; type = READSTAT_TYPE_INT8; break;
  263|    437|            case DTA_111_TYPE_CODE_INT16:
  ------------------
  |  |  173|    437|#define DTA_111_TYPE_CODE_INT16    0xFC
  ------------------
  |  Branch (263:13): [True: 437, False: 40.8k]
  ------------------
  264|    437|                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: 29.3k]
  ------------------
  266|  11.9k|                len = 4; type = READSTAT_TYPE_INT32; break;
  267|    492|            case DTA_111_TYPE_CODE_FLOAT:
  ------------------
  |  |  175|    492|#define DTA_111_TYPE_CODE_FLOAT    0xFE
  ------------------
  |  Branch (267:13): [True: 492, False: 40.8k]
  ------------------
  268|    492|                len = 4; type = READSTAT_TYPE_FLOAT; break;
  269|    939|            case DTA_111_TYPE_CODE_DOUBLE:
  ------------------
  |  |  176|    939|#define DTA_111_TYPE_CODE_DOUBLE   0xFF
  ------------------
  |  Branch (269:13): [True: 939, False: 40.3k]
  ------------------
  270|    939|                len = 8; type = READSTAT_TYPE_DOUBLE; break;
  271|  26.5k|            default:
  ------------------
  |  Branch (271:13): [True: 26.5k, False: 14.7k]
  ------------------
  272|  26.5k|                len = typecode; type = READSTAT_TYPE_STRING; break;
  273|  41.2k|        }
  274|   244k|    } else if (ctx->typlist_version == 117) {
  ------------------
  |  Branch (274:16): [True: 61.5k, False: 183k]
  ------------------
  275|  61.5k|        switch (typecode) {
  276|  1.35k|            case DTA_117_TYPE_CODE_INT8:
  ------------------
  |  |  165|  1.35k|#define DTA_117_TYPE_CODE_INT8     0xFFFA
  ------------------
  |  Branch (276:13): [True: 1.35k, False: 60.1k]
  ------------------
  277|  1.35k|                len = 1; type = READSTAT_TYPE_INT8; break;
  278|  1.24k|            case DTA_117_TYPE_CODE_INT16:
  ------------------
  |  |  166|  1.24k|#define DTA_117_TYPE_CODE_INT16    0xFFF9
  ------------------
  |  Branch (278:13): [True: 1.24k, False: 60.2k]
  ------------------
  279|  1.24k|                len = 2; type = READSTAT_TYPE_INT16; break;
  280|  1.86k|            case DTA_117_TYPE_CODE_INT32:
  ------------------
  |  |  167|  1.86k|#define DTA_117_TYPE_CODE_INT32    0xFFF8
  ------------------
  |  Branch (280:13): [True: 1.86k, False: 59.6k]
  ------------------
  281|  1.86k|                len = 4; type = READSTAT_TYPE_INT32; break;
  282|    735|            case DTA_117_TYPE_CODE_FLOAT:
  ------------------
  |  |  168|    735|#define DTA_117_TYPE_CODE_FLOAT    0xFFF7
  ------------------
  |  Branch (282:13): [True: 735, False: 60.7k]
  ------------------
  283|    735|                len = 4; type = READSTAT_TYPE_FLOAT; break;
  284|    833|            case DTA_117_TYPE_CODE_DOUBLE:
  ------------------
  |  |  169|    833|#define DTA_117_TYPE_CODE_DOUBLE   0xFFF6
  ------------------
  |  Branch (284:13): [True: 833, False: 60.6k]
  ------------------
  285|    833|                len = 8; type = READSTAT_TYPE_DOUBLE; break;
  286|  51.9k|            case DTA_117_TYPE_CODE_STRL:
  ------------------
  |  |  170|  51.9k|#define DTA_117_TYPE_CODE_STRL     0x8000
  ------------------
  |  Branch (286:13): [True: 51.9k, False: 9.58k]
  ------------------
  287|  51.9k|                len = 8; type = READSTAT_TYPE_STRING_REF; break;
  288|  3.54k|            default:
  ------------------
  |  Branch (288:13): [True: 3.54k, False: 57.9k]
  ------------------
  289|  3.54k|                len = typecode; type = READSTAT_TYPE_STRING; break;
  290|  61.5k|        }
  291|   183k|    } else if (typecode < 0x7F) {
  ------------------
  |  Branch (291:16): [True: 166k, False: 16.6k]
  ------------------
  292|   166k|        switch (typecode) {
  293|  31.5k|            case DTA_OLD_TYPE_CODE_INT8:
  ------------------
  |  |  178|  31.5k|#define DTA_OLD_TYPE_CODE_INT8     'b'
  ------------------
  |  Branch (293:13): [True: 31.5k, False: 134k]
  ------------------
  294|  31.5k|                len = 1; type = READSTAT_TYPE_INT8; break;
  295|  1.60k|            case DTA_OLD_TYPE_CODE_INT16:
  ------------------
  |  |  179|  1.60k|#define DTA_OLD_TYPE_CODE_INT16    'i'
  ------------------
  |  Branch (295:13): [True: 1.60k, False: 164k]
  ------------------
  296|  1.60k|                len = 2; type = READSTAT_TYPE_INT16; break;
  297|    715|            case DTA_OLD_TYPE_CODE_INT32:
  ------------------
  |  |  180|    715|#define DTA_OLD_TYPE_CODE_INT32    'l'
  ------------------
  |  Branch (297:13): [True: 715, False: 165k]
  ------------------
  298|    715|                len = 4; type = READSTAT_TYPE_INT32; break;
  299|    780|            case DTA_OLD_TYPE_CODE_FLOAT:
  ------------------
  |  |  181|    780|#define DTA_OLD_TYPE_CODE_FLOAT    'f'
  ------------------
  |  Branch (299:13): [True: 780, False: 165k]
  ------------------
  300|    780|                len = 4; type = READSTAT_TYPE_FLOAT; break;
  301|   131k|            case DTA_OLD_TYPE_CODE_DOUBLE:
  ------------------
  |  |  182|   131k|#define DTA_OLD_TYPE_CODE_DOUBLE   'd'
  ------------------
  |  Branch (301:13): [True: 131k, False: 34.6k]
  ------------------
  302|   131k|                len = 8; type = READSTAT_TYPE_DOUBLE; break;
  303|     16|            default:
  ------------------
  |  Branch (303:13): [True: 16, False: 166k]
  ------------------
  304|     16|                retval = READSTAT_ERROR_PARSE; break;
  305|   166k|        }
  306|   166k|    } else {
  307|  16.6k|        len = typecode - 0x7F;
  308|  16.6k|        type = READSTAT_TYPE_STRING;
  309|  16.6k|    }
  310|       |    
  311|   285k|    if (max_len)
  ------------------
  |  Branch (311:9): [True: 285k, False: 0]
  ------------------
  312|   285k|        *max_len = len;
  313|   285k|    if (out_type)
  ------------------
  |  Branch (313:9): [True: 250k, False: 35.2k]
  ------------------
  314|   250k|        *out_type = type;
  315|       |
  316|   285k|    return retval;
  317|   285k|}

dta_parse_timestamp:
  145|    900|readstat_error_handler error_handler, void *user_ctx) {
  146|    900|	readstat_error_t retval = READSTAT_OK;
  147|    900|	const char *p = data;
  148|    900|	const char *pe = p + len;
  149|    900|	const char *eof = pe;
  150|    900|	int cs;
  151|    900|	unsigned int temp_val = 0;
  152|       |	
  153|    900|#line 154 "src/stata/readstat_dta_parse_timestamp.c"
  154|    900|	{
  155|    900|		cs = (int)dta_timestamp_parse_start;
  156|    900|	}
  157|       |	
  158|    900|#line 159 "src/stata/readstat_dta_parse_timestamp.c"
  159|    900|	{
  160|    900|		int _klen;
  161|    900|		unsigned int _trans = 0;
  162|    900|		const char * _keys;
  163|    900|		const signed char * _acts;
  164|    900|		unsigned int _nacts;
  165|  3.23k|		_resume: {}
  166|  3.23k|		if ( p == pe && p != eof )
  ------------------
  |  Branch (166:8): [True: 83, False: 3.15k]
  |  Branch (166:19): [True: 0, False: 83]
  ------------------
  167|      0|			goto _out;
  168|  3.23k|		if ( p == eof ) {
  ------------------
  |  Branch (168:8): [True: 83, False: 3.15k]
  ------------------
  169|     83|			if ( _dta_timestamp_parse_eof_trans[cs] > 0 ) {
  ------------------
  |  Branch (169:9): [True: 83, False: 0]
  ------------------
  170|     83|				_trans = (unsigned int)_dta_timestamp_parse_eof_trans[cs] - 1;
  171|     83|			}
  172|     83|		}
  173|  3.15k|		else {
  174|  3.15k|			_keys = ( _dta_timestamp_parse_trans_keys + (_dta_timestamp_parse_key_offsets[cs]));
  175|  3.15k|			_trans = (unsigned int)_dta_timestamp_parse_index_offsets[cs];
  176|       |			
  177|  3.15k|			_klen = (int)_dta_timestamp_parse_single_lengths[cs];
  178|  3.15k|			if ( _klen > 0 ) {
  ------------------
  |  Branch (178:9): [True: 2.83k, False: 323]
  ------------------
  179|  2.83k|				const char *_lower = _keys;
  180|  2.83k|				const char *_upper = _keys + _klen - 1;
  181|  2.83k|				const char *_mid;
  182|  5.43k|				while ( 1 ) {
  ------------------
  |  Branch (182:13): [True: 5.43k, Folded]
  ------------------
  183|  5.43k|					if ( _upper < _lower ) {
  ------------------
  |  Branch (183:11): [True: 2.03k, False: 3.39k]
  ------------------
  184|  2.03k|						_keys += _klen;
  185|  2.03k|						_trans += (unsigned int)_klen;
  186|  2.03k|						break;
  187|  2.03k|					}
  188|       |					
  189|  3.39k|					_mid = _lower + ((_upper-_lower) >> 1);
  190|  3.39k|					if ( ( (*( p))) < (*( _mid)) )
  ------------------
  |  Branch (190:11): [True: 821, False: 2.57k]
  ------------------
  191|    821|						_upper = _mid - 1;
  192|  2.57k|					else if ( ( (*( p))) > (*( _mid)) )
  ------------------
  |  Branch (192:16): [True: 1.78k, False: 794]
  ------------------
  193|  1.78k|						_lower = _mid + 1;
  194|    794|					else {
  195|    794|						_trans += (unsigned int)(_mid - _keys);
  196|    794|						goto _match;
  197|    794|					}
  198|  3.39k|				}
  199|  2.83k|			}
  200|       |			
  201|  2.36k|			_klen = (int)_dta_timestamp_parse_range_lengths[cs];
  202|  2.36k|			if ( _klen > 0 ) {
  ------------------
  |  Branch (202:9): [True: 2.33k, False: 22]
  ------------------
  203|  2.33k|				const char *_lower = _keys;
  204|  2.33k|				const char *_upper = _keys + (_klen<<1) - 2;
  205|  2.33k|				const char *_mid;
  206|  3.13k|				while ( 1 ) {
  ------------------
  |  Branch (206:13): [True: 3.13k, Folded]
  ------------------
  207|  3.13k|					if ( _upper < _lower ) {
  ------------------
  |  Branch (207:11): [True: 795, False: 2.33k]
  ------------------
  208|    795|						_trans += (unsigned int)_klen;
  209|    795|						break;
  210|    795|					}
  211|       |					
  212|  2.33k|					_mid = _lower + (((_upper-_lower) >> 1) & ~1);
  213|  2.33k|					if ( ( (*( p))) < (*( _mid)) )
  ------------------
  |  Branch (213:11): [True: 441, False: 1.89k]
  ------------------
  214|    441|						_upper = _mid - 2;
  215|  1.89k|					else if ( ( (*( p))) > (*( _mid + 1)) )
  ------------------
  |  Branch (215:16): [True: 354, False: 1.54k]
  ------------------
  216|    354|						_lower = _mid + 2;
  217|  1.54k|					else {
  218|  1.54k|						_trans += (unsigned int)((_mid - _keys)>>1);
  219|  1.54k|						break;
  220|  1.54k|					}
  221|  2.33k|				}
  222|  2.33k|			}
  223|       |			
  224|  3.15k|			_match: {}
  225|  3.15k|		}
  226|  3.23k|		cs = (int)_dta_timestamp_parse_cond_targs[_trans];
  227|       |		
  228|  3.23k|		if ( _dta_timestamp_parse_cond_actions[_trans] != 0 ) {
  ------------------
  |  Branch (228:8): [True: 1.88k, False: 1.35k]
  ------------------
  229|       |			
  230|  1.88k|			_acts = ( _dta_timestamp_parse_actions + (_dta_timestamp_parse_cond_actions[_trans]));
  231|  1.88k|			_nacts = (unsigned int)(*( _acts));
  232|  1.88k|			_acts += 1;
  233|  4.24k|			while ( _nacts > 0 ) {
  ------------------
  |  Branch (233:12): [True: 2.36k, False: 1.88k]
  ------------------
  234|  2.36k|				switch ( (*( _acts)) )
  ------------------
  |  Branch (234:14): [True: 2.36k, False: 0]
  ------------------
  235|  2.36k|				{
  236|  1.54k|					case 0:  {
  ------------------
  |  Branch (236:6): [True: 1.54k, False: 819]
  ------------------
  237|  1.54k|						{
  238|  1.54k|#line 20 "src/stata/readstat_dta_parse_timestamp.rl"
  239|       |							
  240|  1.54k|							temp_val = 10 * temp_val + ((( (*( p)))) - '0');
  241|  1.54k|						}
  242|       |						
  243|  1.54k|#line 244 "src/stata/readstat_dta_parse_timestamp.c"
  244|       |						
  245|  1.54k|						break; 
  246|      0|					}
  247|    479|					case 1:  {
  ------------------
  |  Branch (247:6): [True: 479, False: 1.88k]
  ------------------
  248|    479|						{
  249|    479|#line 24 "src/stata/readstat_dta_parse_timestamp.rl"
  250|    479|							temp_val = 0; }
  251|       |						
  252|    479|#line 253 "src/stata/readstat_dta_parse_timestamp.c"
  253|       |						
  254|    479|						break; 
  255|      0|					}
  256|    124|					case 2:  {
  ------------------
  |  Branch (256:6): [True: 124, False: 2.23k]
  ------------------
  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|     22|					case 3:  {
  ------------------
  |  Branch (265:6): [True: 22, False: 2.34k]
  ------------------
  266|     22|						{
  267|     22|#line 29 "src/stata/readstat_dta_parse_timestamp.rl"
  268|     22|							timestamp->tm_mon = 0; }
  269|       |						
  270|     22|#line 271 "src/stata/readstat_dta_parse_timestamp.c"
  271|       |						
  272|     22|						break; 
  273|      0|					}
  274|      3|					case 4:  {
  ------------------
  |  Branch (274:6): [True: 3, False: 2.36k]
  ------------------
  275|      3|						{
  276|      3|#line 30 "src/stata/readstat_dta_parse_timestamp.rl"
  277|      3|							timestamp->tm_mon = 1; }
  278|       |						
  279|      3|#line 280 "src/stata/readstat_dta_parse_timestamp.c"
  280|       |						
  281|      3|						break; 
  282|      0|					}
  283|      2|					case 5:  {
  ------------------
  |  Branch (283:6): [True: 2, False: 2.36k]
  ------------------
  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|     18|					case 6:  {
  ------------------
  |  Branch (292:6): [True: 18, False: 2.34k]
  ------------------
  293|     18|						{
  294|     18|#line 32 "src/stata/readstat_dta_parse_timestamp.rl"
  295|     18|							timestamp->tm_mon = 3; }
  296|       |						
  297|     18|#line 298 "src/stata/readstat_dta_parse_timestamp.c"
  298|       |						
  299|     18|						break; 
  300|      0|					}
  301|     15|					case 7:  {
  ------------------
  |  Branch (301:6): [True: 15, False: 2.34k]
  ------------------
  302|     15|						{
  303|     15|#line 33 "src/stata/readstat_dta_parse_timestamp.rl"
  304|     15|							timestamp->tm_mon = 4; }
  305|       |						
  306|     15|#line 307 "src/stata/readstat_dta_parse_timestamp.c"
  307|       |						
  308|     15|						break; 
  309|      0|					}
  310|     14|					case 8:  {
  ------------------
  |  Branch (310:6): [True: 14, False: 2.34k]
  ------------------
  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.36k]
  ------------------
  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.36k]
  ------------------
  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.36k]
  ------------------
  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|      4|					case 12:  {
  ------------------
  |  Branch (346:6): [True: 4, False: 2.35k]
  ------------------
  347|      4|						{
  348|      4|#line 38 "src/stata/readstat_dta_parse_timestamp.rl"
  349|      4|							timestamp->tm_mon = 9; }
  350|       |						
  351|      4|#line 352 "src/stata/readstat_dta_parse_timestamp.c"
  352|       |						
  353|      4|						break; 
  354|      0|					}
  355|      1|					case 13:  {
  ------------------
  |  Branch (355:6): [True: 1, False: 2.36k]
  ------------------
  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.36k]
  ------------------
  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|     63|					case 15:  {
  ------------------
  |  Branch (373:6): [True: 63, False: 2.30k]
  ------------------
  374|     63|						{
  375|     63|#line 42 "src/stata/readstat_dta_parse_timestamp.rl"
  376|     63|							timestamp->tm_year = temp_val - 1900; }
  377|       |						
  378|     63|#line 379 "src/stata/readstat_dta_parse_timestamp.c"
  379|       |						
  380|     63|						break; 
  381|      0|					}
  382|     35|					case 16:  {
  ------------------
  |  Branch (382:6): [True: 35, False: 2.32k]
  ------------------
  383|     35|						{
  384|     35|#line 44 "src/stata/readstat_dta_parse_timestamp.rl"
  385|     35|							timestamp->tm_hour = temp_val; }
  386|       |						
  387|     35|#line 388 "src/stata/readstat_dta_parse_timestamp.c"
  388|       |						
  389|     35|						break; 
  390|      0|					}
  391|     33|					case 17:  {
  ------------------
  |  Branch (391:6): [True: 33, False: 2.33k]
  ------------------
  392|     33|						{
  393|     33|#line 46 "src/stata/readstat_dta_parse_timestamp.rl"
  394|     33|							timestamp->tm_min = temp_val; }
  395|       |						
  396|     33|#line 397 "src/stata/readstat_dta_parse_timestamp.c"
  397|       |						
  398|     33|						break; 
  399|      0|					}
  400|  2.36k|				}
  401|  2.36k|				_nacts -= 1;
  402|  2.36k|				_acts += 1;
  403|  2.36k|			}
  404|       |			
  405|  1.88k|		}
  406|       |		
  407|  3.23k|		if ( p == eof ) {
  ------------------
  |  Branch (407:8): [True: 83, False: 3.15k]
  ------------------
  408|     83|			if ( cs >= 44 )
  ------------------
  |  Branch (408:9): [True: 33, False: 50]
  ------------------
  409|     33|				goto _out;
  410|     83|		}
  411|  3.15k|		else {
  412|  3.15k|			if ( cs != 0 ) {
  ------------------
  |  Branch (412:9): [True: 2.33k, False: 817]
  ------------------
  413|  2.33k|				p += 1;
  414|  2.33k|				goto _resume;
  415|  2.33k|			}
  416|  3.15k|		}
  417|    900|		_out: {}
  418|    900|	}
  419|       |	
  420|      0|#line 52 "src/stata/readstat_dta_parse_timestamp.rl"
  421|       |	
  422|       |	
  423|    900|	if (cs < 
  ------------------
  |  Branch (423:6): [True: 867, False: 33]
  ------------------
  424|    900|#line 425 "src/stata/readstat_dta_parse_timestamp.c"
  425|    900|	44
  426|     33|#line 54 "src/stata/readstat_dta_parse_timestamp.rl"
  427|    867|	|| p != pe) {
  ------------------
  |  Branch (427:5): [True: 0, False: 33]
  ------------------
  428|    867|		char error_buf[1024];
  429|    867|		if (error_handler) {
  ------------------
  |  Branch (429:7): [True: 0, False: 867]
  ------------------
  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|    867|		retval = READSTAT_ERROR_BAD_TIMESTAMP_STRING;
  434|    867|	}
  435|       |	
  436|    900|	(void)dta_timestamp_parse_en_main;
  437|       |	
  438|    900|	return retval;
  439|  3.23k|}

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

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

