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

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

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

readstat_convert:
    7|   253k|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|   257k|    while (src_len && (src[src_len-1] == ' ' || src[src_len-1] == '\0')) {
  ------------------
  |  Branch (10:12): [True: 214k, False: 42.3k]
  |  Branch (10:24): [True: 2.36k, False: 212k]
  |  Branch (10:49): [True: 1.55k, False: 210k]
  ------------------
   11|  3.91k|        src_len--;
   12|  3.91k|    }
   13|   253k|    if (dst_len == 0) {
  ------------------
  |  Branch (13:9): [True: 0, False: 253k]
  ------------------
   14|      0|        return READSTAT_ERROR_CONVERT_LONG_STRING;
   15|   253k|    } else if (converter) {
  ------------------
  |  Branch (15:16): [True: 251k, False: 1.60k]
  ------------------
   16|   251k|        size_t dst_left = dst_len - 1;
   17|   251k|        char *dst_end = dst;
   18|   251k|        size_t status = iconv(converter, (readstat_iconv_inbuf_t)&src, &src_len, &dst_end, &dst_left);
   19|   251k|        if (status == (size_t)-1) {
  ------------------
  |  Branch (19:13): [True: 1.71k, False: 249k]
  ------------------
   20|  1.71k|            if (errno == E2BIG) {
  ------------------
  |  Branch (20:17): [True: 1, False: 1.71k]
  ------------------
   21|      1|                return READSTAT_ERROR_CONVERT_LONG_STRING;
   22|  1.71k|            } else if (errno == EILSEQ) {
  ------------------
  |  Branch (22:24): [True: 1.71k, False: 0]
  ------------------
   23|  1.71k|                return READSTAT_ERROR_CONVERT_BAD_STRING;
   24|  1.71k|            } 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.71k|        }
   28|   249k|        dst[dst_len - dst_left - 1] = '\0';
   29|   249k|    } else if (src_len + 1 > dst_len) {
  ------------------
  |  Branch (29:16): [True: 15, False: 1.59k]
  ------------------
   30|     15|        return READSTAT_ERROR_CONVERT_LONG_STRING;
   31|  1.59k|    } else {
   32|  1.59k|        memcpy(dst, src, src_len);
   33|  1.59k|        dst[src_len] = '\0';
   34|  1.59k|    }
   35|   251k|    return READSTAT_OK;
   36|   253k|}

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

readstat_malloc:
   10|  91.8k|void *readstat_malloc(size_t len) {
   11|  91.8k|    if (len > MAX_MALLOC_SIZE || len == 0) {
  ------------------
  |  |    3|   183k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
  |  Branch (11:9): [True: 39, False: 91.8k]
  |  Branch (11:34): [True: 0, False: 91.8k]
  ------------------
   12|     39|        return NULL;
   13|     39|    }
   14|  91.8k|    return malloc(len);
   15|  91.8k|}
readstat_calloc:
   17|  3.03k|void *readstat_calloc(size_t count, size_t size) {
   18|  3.03k|    if (count > MAX_MALLOC_SIZE || size > MAX_MALLOC_SIZE || count * size > MAX_MALLOC_SIZE) {
  ------------------
  |  |    3|  6.06k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
                  if (count > MAX_MALLOC_SIZE || size > MAX_MALLOC_SIZE || count * size > MAX_MALLOC_SIZE) {
  ------------------
  |  |    3|  6.00k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
                  if (count > MAX_MALLOC_SIZE || size > MAX_MALLOC_SIZE || count * size > MAX_MALLOC_SIZE) {
  ------------------
  |  |    3|  2.97k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
  |  Branch (18:9): [True: 59, False: 2.97k]
  |  Branch (18:36): [True: 0, False: 2.97k]
  |  Branch (18:62): [True: 17, False: 2.95k]
  ------------------
   19|     76|        return NULL;
   20|     76|    }
   21|  2.95k|    if (count == 0 || size == 0) {
  ------------------
  |  Branch (21:9): [True: 0, False: 2.95k]
  |  Branch (21:23): [True: 0, False: 2.95k]
  ------------------
   22|      0|        return NULL;
   23|      0|    }
   24|  2.95k|    return calloc(count, size);
   25|  2.95k|}
readstat_realloc:
   27|  6.67k|void *readstat_realloc(void *ptr, size_t len) {
   28|  6.67k|    if (len > MAX_MALLOC_SIZE || len == 0) {
  ------------------
  |  |    3|  13.3k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
  |  Branch (28:9): [True: 44, False: 6.63k]
  |  Branch (28:34): [True: 6, False: 6.62k]
  ------------------
   29|     50|        if (ptr)
  ------------------
  |  Branch (29:13): [True: 6, False: 44]
  ------------------
   30|      6|            free(ptr);
   31|     50|        return NULL;
   32|     50|    }
   33|  6.62k|    return realloc(ptr, len);
   34|  6.67k|}

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

dta_ctx_alloc:
   17|  4.46k|dta_ctx_t *dta_ctx_alloc(readstat_io_t *io) {
   18|  4.46k|    dta_ctx_t *ctx = calloc(1, sizeof(dta_ctx_t));
   19|  4.46k|    if (ctx == NULL) {
  ------------------
  |  Branch (19:9): [True: 0, False: 4.46k]
  ------------------
   20|      0|        return NULL;
   21|      0|    }
   22|       |
   23|  4.46k|    ctx->io = io;
   24|  4.46k|    ctx->initialized = 0;
   25|       |
   26|  4.46k|    return ctx;
   27|  4.46k|}
dta_ctx_init:
   31|  3.99k|        const char *input_encoding, const char *output_encoding) {
   32|  3.99k|    readstat_error_t retval = READSTAT_OK;
   33|  3.99k|    int machine_byteorder = DTA_HILO;
  ------------------
  |  |  129|  3.99k|#define DTA_HILO  0x01
  ------------------
   34|  3.99k|    if (ds_format < DTA_MIN_VERSION || ds_format > DTA_MAX_VERSION)
  ------------------
  |  |   14|  7.98k|#define DTA_MIN_VERSION 104
  ------------------
                  if (ds_format < DTA_MIN_VERSION || ds_format > DTA_MAX_VERSION)
  ------------------
  |  |   15|  3.98k|#define DTA_MAX_VERSION 119
  ------------------
  |  Branch (34:9): [True: 7, False: 3.98k]
  |  Branch (34:40): [True: 8, False: 3.97k]
  ------------------
   35|     15|        return READSTAT_ERROR_UNSUPPORTED_FILE_FORMAT_VERSION;
   36|       |
   37|  3.97k|    if (machine_is_little_endian()) {
  ------------------
  |  Branch (37:9): [True: 3.97k, False: 0]
  ------------------
   38|  3.97k|        machine_byteorder = DTA_LOHI;
  ------------------
  |  |  130|  3.97k|#define DTA_LOHI  0x02
  ------------------
   39|  3.97k|    }
   40|       |
   41|  3.97k|    ctx->bswap = (byteorder != machine_byteorder);
   42|  3.97k|    ctx->ds_format = ds_format;
   43|  3.97k|    ctx->endianness = byteorder == DTA_LOHI ? READSTAT_ENDIAN_LITTLE : READSTAT_ENDIAN_BIG;
  ------------------
  |  |  130|  3.97k|#define DTA_LOHI  0x02
  ------------------
  |  Branch (43:23): [True: 1.33k, False: 2.64k]
  ------------------
   44|       |
   45|  3.97k|    ctx->nvar = nvar;
   46|  3.97k|    ctx->nobs = nobs;
   47|       |
   48|  3.97k|    if (ctx->nvar) {
  ------------------
  |  Branch (48:9): [True: 3.03k, False: 945]
  ------------------
   49|  3.03k|        if ((ctx->variables = readstat_calloc(ctx->nvar, sizeof(readstat_variable_t *))) == NULL) {
  ------------------
  |  Branch (49:13): [True: 76, False: 2.95k]
  ------------------
   50|     76|            retval = READSTAT_ERROR_MALLOC;
   51|     76|            goto cleanup;
   52|     76|        }
   53|  3.03k|    }
   54|       |
   55|  3.90k|    ctx->machine_is_twos_complement = READSTAT_MACHINE_IS_TWOS_COMPLEMENT;
  ------------------
  |  |    8|  3.90k|#define READSTAT_MACHINE_IS_TWOS_COMPLEMENT 0
  ------------------
   56|       |
   57|  3.90k|    if (ds_format < 105) {
  ------------------
  |  Branch (57:9): [True: 796, False: 3.10k]
  ------------------
   58|    796|        ctx->fmtlist_entry_len = 7;
   59|  3.10k|    } else if (ds_format < 114) {
  ------------------
  |  Branch (59:16): [True: 908, False: 2.19k]
  ------------------
   60|    908|        ctx->fmtlist_entry_len = 12;
   61|  2.19k|    } else if (ds_format < 118) {
  ------------------
  |  Branch (61:16): [True: 1.78k, False: 412]
  ------------------
   62|  1.78k|        ctx->fmtlist_entry_len = 49;
   63|  1.78k|    } else {
   64|    412|        ctx->fmtlist_entry_len = 57;
   65|    412|    }
   66|       |    
   67|  3.90k|    if (ds_format >= 117) {
  ------------------
  |  Branch (67:9): [True: 2.16k, False: 1.74k]
  ------------------
   68|  2.16k|        ctx->typlist_version = 117;
   69|  2.16k|    } else if (ds_format >= 111) {
  ------------------
  |  Branch (69:16): [True: 318, False: 1.42k]
  ------------------
   70|    318|        ctx->typlist_version = 111;
   71|  1.42k|    } else {
   72|  1.42k|        ctx->typlist_version = 0;
   73|  1.42k|    }
   74|       |
   75|  3.90k|    if (ds_format >= 118) {
  ------------------
  |  Branch (75:9): [True: 412, False: 3.49k]
  ------------------
   76|    412|        ctx->data_label_len_len = 2;
   77|    412|        ctx->strl_v_len = 2;
   78|    412|        ctx->strl_o_len = 6;
   79|  3.49k|    } else if (ds_format >= 117) {
  ------------------
  |  Branch (79:16): [True: 1.75k, False: 1.74k]
  ------------------
   80|  1.75k|        ctx->data_label_len_len = 1;
   81|  1.75k|        ctx->strl_v_len = 4;
   82|  1.75k|        ctx->strl_o_len = 4;
   83|  1.75k|    }
   84|       |
   85|  3.90k|    if (ds_format < 105) {
  ------------------
  |  Branch (85:9): [True: 796, False: 3.10k]
  ------------------
   86|    796|        ctx->expansion_len_len = 0;
   87|  3.10k|    } else if (ds_format < 110) {
  ------------------
  |  Branch (87:16): [True: 621, False: 2.48k]
  ------------------
   88|    621|        ctx->expansion_len_len = 2;
   89|  2.48k|    } else {
   90|  2.48k|        ctx->expansion_len_len = 4;
   91|  2.48k|    }
   92|       |    
   93|  3.90k|    if (ds_format < 110) {
  ------------------
  |  Branch (93:9): [True: 1.41k, False: 2.48k]
  ------------------
   94|  1.41k|        ctx->lbllist_entry_len = 9;
   95|  1.41k|        ctx->variable_name_len = 9;
   96|  1.41k|        ctx->ch_metadata_len = 9;
   97|  2.48k|    } else if (ds_format < 118) {
  ------------------
  |  Branch (97:16): [True: 2.07k, False: 412]
  ------------------
   98|  2.07k|        ctx->lbllist_entry_len = 33;
   99|  2.07k|        ctx->variable_name_len = 33;
  100|  2.07k|        ctx->ch_metadata_len = 33;
  101|  2.07k|    } else {
  102|    412|        ctx->lbllist_entry_len = 129;
  103|    412|        ctx->variable_name_len = 129;
  104|    412|        ctx->ch_metadata_len = 129;
  105|    412|    }
  106|       |
  107|  3.90k|    if (ds_format < 108) {
  ------------------
  |  Branch (107:9): [True: 1.41k, False: 2.48k]
  ------------------
  108|  1.41k|        ctx->variable_labels_entry_len = 32;
  109|  1.41k|        ctx->data_label_len = 32;
  110|  2.48k|    } else if (ds_format < 118) {
  ------------------
  |  Branch (110:16): [True: 2.07k, False: 412]
  ------------------
  111|  2.07k|        ctx->variable_labels_entry_len = 81;
  112|  2.07k|        ctx->data_label_len = 81;
  113|  2.07k|    } else {
  114|    412|        ctx->variable_labels_entry_len = 321;
  115|    412|        ctx->data_label_len = 321;
  116|    412|    }
  117|       |
  118|  3.90k|    if (ds_format < 105) {
  ------------------
  |  Branch (118:9): [True: 796, False: 3.10k]
  ------------------
  119|    796|        ctx->timestamp_len = 0;
  120|    796|        ctx->value_label_table_len_len = 2;
  121|    796|        ctx->value_label_table_labname_len = 12;
  122|    796|        ctx->value_label_table_padding_len = 2;
  123|  3.10k|    } else {
  124|  3.10k|        ctx->timestamp_len = 18;
  125|  3.10k|        ctx->value_label_table_len_len = 4;
  126|  3.10k|        if (ds_format < 118) {
  ------------------
  |  Branch (126:13): [True: 2.69k, False: 412]
  ------------------
  127|  2.69k|            ctx->value_label_table_labname_len = 33;
  128|  2.69k|        } else {
  129|    412|            ctx->value_label_table_labname_len = 129;
  130|    412|        }
  131|  3.10k|        ctx->value_label_table_padding_len = 3;
  132|  3.10k|    }
  133|       |
  134|  3.90k|    if (ds_format < 117) {
  ------------------
  |  Branch (134:9): [True: 1.74k, False: 2.16k]
  ------------------
  135|  1.74k|        ctx->typlist_entry_len = 1;
  136|  1.74k|        ctx->file_is_xmlish = 0;
  137|  2.16k|    } else {
  138|  2.16k|        ctx->typlist_entry_len = 2;
  139|  2.16k|        ctx->file_is_xmlish = 1;
  140|  2.16k|    }
  141|       |
  142|  3.90k|    if (ds_format < 113) {
  ------------------
  |  Branch (142:9): [True: 1.43k, False: 2.47k]
  ------------------
  143|  1.43k|        ctx->max_int8 = DTA_OLD_MAX_INT8;
  ------------------
  |  |  132|  1.43k|#define DTA_OLD_MAX_INT8                     0x7e
  ------------------
  144|  1.43k|        ctx->max_int16 = DTA_OLD_MAX_INT16;
  ------------------
  |  |  133|  1.43k|#define DTA_OLD_MAX_INT16                  0x7ffe
  ------------------
  145|  1.43k|        ctx->max_int32 = DTA_OLD_MAX_INT32;
  ------------------
  |  |  134|  1.43k|#define DTA_OLD_MAX_INT32              0x7ffffffe
  ------------------
  146|  1.43k|        ctx->max_float = DTA_OLD_MAX_FLOAT;
  ------------------
  |  |  135|  1.43k|#define DTA_OLD_MAX_FLOAT              0x7effffff // +1.7e38f
  ------------------
  147|  1.43k|        ctx->max_double = DTA_OLD_MAX_DOUBLE;
  ------------------
  |  |  136|  1.43k|#define DTA_OLD_MAX_DOUBLE     0x7fdfffffffffffffL // +8.9e307
  ------------------
  148|  2.47k|    } else {
  149|  2.47k|        ctx->max_int8 = DTA_113_MAX_INT8;
  ------------------
  |  |  144|  2.47k|#define DTA_113_MAX_INT8                    0x64
  ------------------
  150|  2.47k|        ctx->max_int16 = DTA_113_MAX_INT16;
  ------------------
  |  |  145|  2.47k|#define DTA_113_MAX_INT16                 0x7fe4
  ------------------
  151|  2.47k|        ctx->max_int32 = DTA_113_MAX_INT32;
  ------------------
  |  |  146|  2.47k|#define DTA_113_MAX_INT32             0x7fffffe4
  ------------------
  152|  2.47k|        ctx->max_float = DTA_113_MAX_FLOAT;
  ------------------
  |  |  147|  2.47k|#define DTA_113_MAX_FLOAT             0x7effffff // +1.7e38f
  ------------------
  153|  2.47k|        ctx->max_double = DTA_113_MAX_DOUBLE;
  ------------------
  |  |  148|  2.47k|#define DTA_113_MAX_DOUBLE    0x7fdfffffffffffffL // +8.9e307
  ------------------
  154|       |
  155|  2.47k|        ctx->supports_tagged_missing = 1;
  156|  2.47k|    }
  157|       |
  158|  3.90k|    if (output_encoding) {
  ------------------
  |  Branch (158:9): [True: 3.90k, False: 0]
  ------------------
  159|  3.90k|        if (input_encoding) {
  ------------------
  |  Branch (159:13): [True: 0, False: 3.90k]
  ------------------
  160|      0|            ctx->converter = iconv_open(output_encoding, input_encoding);
  161|  3.90k|        } else if (ds_format < 118) {
  ------------------
  |  Branch (161:20): [True: 3.49k, False: 412]
  ------------------
  162|  3.49k|            ctx->converter = iconv_open(output_encoding, "WINDOWS-1252");
  163|  3.49k|        } else if (strcmp(output_encoding, "UTF-8") != 0) {
  ------------------
  |  Branch (163:20): [True: 0, False: 412]
  ------------------
  164|      0|            ctx->converter = iconv_open(output_encoding, "UTF-8");
  165|      0|        }
  166|  3.90k|        if (ctx->converter == (iconv_t)-1) {
  ------------------
  |  Branch (166:13): [True: 0, False: 3.90k]
  ------------------
  167|      0|            ctx->converter = NULL;
  168|      0|            retval = READSTAT_ERROR_UNSUPPORTED_CHARSET;
  169|      0|            goto cleanup;
  170|      0|        }
  171|  3.90k|    }
  172|       |
  173|  3.90k|    if (ds_format < 119) {
  ------------------
  |  Branch (173:9): [True: 3.81k, False: 88]
  ------------------
  174|  3.81k|        ctx->srtlist_len = (ctx->nvar + 1) * sizeof(int16_t);
  175|  3.81k|    } else {
  176|     88|        ctx->srtlist_len = (ctx->nvar + 1) * sizeof(int32_t);
  177|     88|    }
  178|       |
  179|  3.90k|    if ((ctx->srtlist = readstat_malloc(ctx->srtlist_len)) == NULL) {
  ------------------
  |  Branch (179:9): [True: 0, False: 3.90k]
  ------------------
  180|      0|        retval = READSTAT_ERROR_MALLOC;
  181|      0|        goto cleanup;
  182|      0|    }
  183|       |
  184|  3.90k|    if (ctx->nvar > 0) {
  ------------------
  |  Branch (184:9): [True: 2.95k, False: 945]
  ------------------
  185|  2.95k|        ctx->typlist_len = ctx->nvar * sizeof(uint16_t);
  186|  2.95k|        ctx->varlist_len = ctx->variable_name_len * ctx->nvar * sizeof(char);
  187|  2.95k|        ctx->fmtlist_len = ctx->fmtlist_entry_len * ctx->nvar * sizeof(char);
  188|  2.95k|        ctx->lbllist_len = ctx->lbllist_entry_len * ctx->nvar * sizeof(char);
  189|  2.95k|        ctx->variable_labels_len = ctx->variable_labels_entry_len * ctx->nvar * sizeof(char);
  190|       |
  191|  2.95k|        if ((ctx->typlist = readstat_malloc(ctx->typlist_len)) == NULL) {
  ------------------
  |  Branch (191:13): [True: 0, False: 2.95k]
  ------------------
  192|      0|            retval = READSTAT_ERROR_MALLOC;
  193|      0|            goto cleanup;
  194|      0|        }
  195|  2.95k|        if ((ctx->varlist = readstat_malloc(ctx->varlist_len)) == NULL) {
  ------------------
  |  Branch (195:13): [True: 25, False: 2.93k]
  ------------------
  196|     25|            retval = READSTAT_ERROR_MALLOC;
  197|     25|            goto cleanup;
  198|     25|        }
  199|  2.93k|        if ((ctx->fmtlist = readstat_malloc(ctx->fmtlist_len)) == NULL) {
  ------------------
  |  Branch (199:13): [True: 0, False: 2.93k]
  ------------------
  200|      0|            retval = READSTAT_ERROR_MALLOC;
  201|      0|            goto cleanup;
  202|      0|        }
  203|  2.93k|        if ((ctx->lbllist = readstat_malloc(ctx->lbllist_len)) == NULL) {
  ------------------
  |  Branch (203:13): [True: 0, False: 2.93k]
  ------------------
  204|      0|            retval = READSTAT_ERROR_MALLOC;
  205|      0|            goto cleanup;
  206|      0|        }
  207|  2.93k|        if ((ctx->variable_labels = readstat_malloc(ctx->variable_labels_len)) == NULL) {
  ------------------
  |  Branch (207:13): [True: 7, False: 2.92k]
  ------------------
  208|      7|            retval = READSTAT_ERROR_MALLOC;
  209|      7|            goto cleanup;
  210|      7|        }
  211|  2.93k|    }
  212|       |
  213|  3.87k|    ctx->initialized = 1;
  214|       |
  215|  3.97k|cleanup:
  216|  3.97k|    return retval;
  217|  3.87k|}
dta_ctx_free:
  219|  4.46k|void dta_ctx_free(dta_ctx_t *ctx) {
  220|  4.46k|    if (ctx->typlist)
  ------------------
  |  Branch (220:9): [True: 2.95k, False: 1.50k]
  ------------------
  221|  2.95k|        free(ctx->typlist);
  222|  4.46k|    if (ctx->varlist)
  ------------------
  |  Branch (222:9): [True: 2.93k, False: 1.53k]
  ------------------
  223|  2.93k|        free(ctx->varlist);
  224|  4.46k|    if (ctx->srtlist)
  ------------------
  |  Branch (224:9): [True: 3.90k, False: 562]
  ------------------
  225|  3.90k|        free(ctx->srtlist);
  226|  4.46k|    if (ctx->fmtlist)
  ------------------
  |  Branch (226:9): [True: 2.93k, False: 1.53k]
  ------------------
  227|  2.93k|        free(ctx->fmtlist);
  228|  4.46k|    if (ctx->lbllist)
  ------------------
  |  Branch (228:9): [True: 2.93k, False: 1.53k]
  ------------------
  229|  2.93k|        free(ctx->lbllist);
  230|  4.46k|    if (ctx->variable_labels)
  ------------------
  |  Branch (230:9): [True: 2.92k, False: 1.53k]
  ------------------
  231|  2.92k|        free(ctx->variable_labels);
  232|  4.46k|    if (ctx->converter)
  ------------------
  |  Branch (232:9): [True: 3.49k, False: 974]
  ------------------
  233|  3.49k|        iconv_close(ctx->converter);
  234|  4.46k|    if (ctx->data_label)
  ------------------
  |  Branch (234:9): [True: 3.61k, False: 848]
  ------------------
  235|  3.61k|        free(ctx->data_label);
  236|  4.46k|    if (ctx->variables) {
  ------------------
  |  Branch (236:9): [True: 2.95k, False: 1.50k]
  ------------------
  237|  2.95k|        int i;
  238|  56.2M|        for (i=0; i<ctx->nvar; i++) {
  ------------------
  |  Branch (238:19): [True: 56.2M, False: 2.95k]
  ------------------
  239|  56.2M|            if (ctx->variables[i])
  ------------------
  |  Branch (239:17): [True: 57.9k, False: 56.2M]
  ------------------
  240|  57.9k|                free(ctx->variables[i]);
  241|  56.2M|        }
  242|  2.95k|        free(ctx->variables);
  243|  2.95k|    }
  244|  4.46k|    if (ctx->strls) {
  ------------------
  |  Branch (244:9): [True: 830, False: 3.63k]
  ------------------
  245|    830|        int i;
  246|  60.9k|        for (i=0; i<ctx->strls_count; i++) {
  ------------------
  |  Branch (246:19): [True: 60.1k, False: 830]
  ------------------
  247|  60.1k|            free(ctx->strls[i]);
  248|  60.1k|        }
  249|    830|        free(ctx->strls);
  250|    830|    }
  251|  4.46k|    free(ctx);
  252|  4.46k|}
dta_type_info:
  255|   326k|        size_t *max_len, readstat_type_t *out_type) {
  256|   326k|    readstat_error_t retval = READSTAT_OK;
  257|   326k|    size_t len = 0;
  258|   326k|    readstat_type_t type = READSTAT_TYPE_STRING;
  259|   326k|    if (ctx->typlist_version == 111) {
  ------------------
  |  Branch (259:9): [True: 87.3k, False: 239k]
  ------------------
  260|  87.3k|        switch (typecode) {
  261|    882|            case DTA_111_TYPE_CODE_INT8:
  ------------------
  |  |  172|    882|#define DTA_111_TYPE_CODE_INT8     0xFB
  ------------------
  |  Branch (261:13): [True: 882, False: 86.4k]
  ------------------
  262|    882|                len = 1; type = READSTAT_TYPE_INT8; break;
  263|    422|            case DTA_111_TYPE_CODE_INT16:
  ------------------
  |  |  173|    422|#define DTA_111_TYPE_CODE_INT16    0xFC
  ------------------
  |  Branch (263:13): [True: 422, False: 86.9k]
  ------------------
  264|    422|                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: 75.3k]
  ------------------
  266|  11.9k|                len = 4; type = READSTAT_TYPE_INT32; break;
  267|    486|            case DTA_111_TYPE_CODE_FLOAT:
  ------------------
  |  |  175|    486|#define DTA_111_TYPE_CODE_FLOAT    0xFE
  ------------------
  |  Branch (267:13): [True: 486, False: 86.8k]
  ------------------
  268|    486|                len = 4; type = READSTAT_TYPE_FLOAT; break;
  269|  3.15k|            case DTA_111_TYPE_CODE_DOUBLE:
  ------------------
  |  |  176|  3.15k|#define DTA_111_TYPE_CODE_DOUBLE   0xFF
  ------------------
  |  Branch (269:13): [True: 3.15k, False: 84.1k]
  ------------------
  270|  3.15k|                len = 8; type = READSTAT_TYPE_DOUBLE; break;
  271|  70.4k|            default:
  ------------------
  |  Branch (271:13): [True: 70.4k, False: 16.9k]
  ------------------
  272|  70.4k|                len = typecode; type = READSTAT_TYPE_STRING; break;
  273|  87.3k|        }
  274|   239k|    } else if (ctx->typlist_version == 117) {
  ------------------
  |  Branch (274:16): [True: 58.6k, False: 180k]
  ------------------
  275|  58.6k|        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: 57.3k]
  ------------------
  277|  1.35k|                len = 1; type = READSTAT_TYPE_INT8; break;
  278|    727|            case DTA_117_TYPE_CODE_INT16:
  ------------------
  |  |  166|    727|#define DTA_117_TYPE_CODE_INT16    0xFFF9
  ------------------
  |  Branch (278:13): [True: 727, False: 57.9k]
  ------------------
  279|    727|                len = 2; type = READSTAT_TYPE_INT16; break;
  280|  1.79k|            case DTA_117_TYPE_CODE_INT32:
  ------------------
  |  |  167|  1.79k|#define DTA_117_TYPE_CODE_INT32    0xFFF8
  ------------------
  |  Branch (280:13): [True: 1.79k, False: 56.8k]
  ------------------
  281|  1.79k|                len = 4; type = READSTAT_TYPE_INT32; break;
  282|    807|            case DTA_117_TYPE_CODE_FLOAT:
  ------------------
  |  |  168|    807|#define DTA_117_TYPE_CODE_FLOAT    0xFFF7
  ------------------
  |  Branch (282:13): [True: 807, False: 57.8k]
  ------------------
  283|    807|                len = 4; type = READSTAT_TYPE_FLOAT; break;
  284|    757|            case DTA_117_TYPE_CODE_DOUBLE:
  ------------------
  |  |  169|    757|#define DTA_117_TYPE_CODE_DOUBLE   0xFFF6
  ------------------
  |  Branch (284:13): [True: 757, False: 57.9k]
  ------------------
  285|    757|                len = 8; type = READSTAT_TYPE_DOUBLE; break;
  286|  50.0k|            case DTA_117_TYPE_CODE_STRL:
  ------------------
  |  |  170|  50.0k|#define DTA_117_TYPE_CODE_STRL     0x8000
  ------------------
  |  Branch (286:13): [True: 50.0k, False: 8.57k]
  ------------------
  287|  50.0k|                len = 8; type = READSTAT_TYPE_STRING_REF; break;
  288|  3.13k|            default:
  ------------------
  |  Branch (288:13): [True: 3.13k, False: 55.5k]
  ------------------
  289|  3.13k|                len = typecode; type = READSTAT_TYPE_STRING; break;
  290|  58.6k|        }
  291|   180k|    } else if (typecode < 0x7F) {
  ------------------
  |  Branch (291:16): [True: 165k, False: 15.3k]
  ------------------
  292|   165k|        switch (typecode) {
  293|  31.1k|            case DTA_OLD_TYPE_CODE_INT8:
  ------------------
  |  |  178|  31.1k|#define DTA_OLD_TYPE_CODE_INT8     'b'
  ------------------
  |  Branch (293:13): [True: 31.1k, False: 134k]
  ------------------
  294|  31.1k|                len = 1; type = READSTAT_TYPE_INT8; break;
  295|    960|            case DTA_OLD_TYPE_CODE_INT16:
  ------------------
  |  |  179|    960|#define DTA_OLD_TYPE_CODE_INT16    'i'
  ------------------
  |  Branch (295:13): [True: 960, False: 164k]
  ------------------
  296|    960|                len = 2; type = READSTAT_TYPE_INT16; break;
  297|    898|            case DTA_OLD_TYPE_CODE_INT32:
  ------------------
  |  |  180|    898|#define DTA_OLD_TYPE_CODE_INT32    'l'
  ------------------
  |  Branch (297:13): [True: 898, False: 164k]
  ------------------
  298|    898|                len = 4; type = READSTAT_TYPE_INT32; break;
  299|    706|            case DTA_OLD_TYPE_CODE_FLOAT:
  ------------------
  |  |  181|    706|#define DTA_OLD_TYPE_CODE_FLOAT    'f'
  ------------------
  |  Branch (299:13): [True: 706, False: 164k]
  ------------------
  300|    706|                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: 33.7k]
  ------------------
  302|   131k|                len = 8; type = READSTAT_TYPE_DOUBLE; break;
  303|     17|            default:
  ------------------
  |  Branch (303:13): [True: 17, False: 165k]
  ------------------
  304|     17|                retval = READSTAT_ERROR_PARSE; break;
  305|   165k|        }
  306|   165k|    } else {
  307|  15.3k|        len = typecode - 0x7F;
  308|  15.3k|        type = READSTAT_TYPE_STRING;
  309|  15.3k|    }
  310|       |    
  311|   326k|    if (max_len)
  ------------------
  |  Branch (311:9): [True: 326k, False: 0]
  ------------------
  312|   326k|        *max_len = len;
  313|   326k|    if (out_type)
  ------------------
  |  Branch (313:9): [True: 268k, False: 58.0k]
  ------------------
  314|   268k|        *out_type = type;
  315|       |
  316|   326k|    return retval;
  317|   326k|}

dta_parse_timestamp:
  145|    888|readstat_error_handler error_handler, void *user_ctx) {
  146|    888|	readstat_error_t retval = READSTAT_OK;
  147|    888|	const char *p = data;
  148|    888|	const char *pe = p + len;
  149|    888|	const char *eof = pe;
  150|    888|	int cs;
  151|    888|	unsigned int temp_val = 0;
  152|       |	
  153|    888|#line 154 "src/stata/readstat_dta_parse_timestamp.c"
  154|    888|	{
  155|    888|		cs = (int)dta_timestamp_parse_start;
  156|    888|	}
  157|       |	
  158|    888|#line 159 "src/stata/readstat_dta_parse_timestamp.c"
  159|    888|	{
  160|    888|		int _klen;
  161|    888|		unsigned int _trans = 0;
  162|    888|		const char * _keys;
  163|    888|		const signed char * _acts;
  164|    888|		unsigned int _nacts;
  165|  3.07k|		_resume: {}
  166|  3.07k|		if ( p == pe && p != eof )
  ------------------
  |  Branch (166:8): [True: 80, False: 2.99k]
  |  Branch (166:19): [True: 0, False: 80]
  ------------------
  167|      0|			goto _out;
  168|  3.07k|		if ( p == eof ) {
  ------------------
  |  Branch (168:8): [True: 80, False: 2.99k]
  ------------------
  169|     80|			if ( _dta_timestamp_parse_eof_trans[cs] > 0 ) {
  ------------------
  |  Branch (169:9): [True: 80, False: 0]
  ------------------
  170|     80|				_trans = (unsigned int)_dta_timestamp_parse_eof_trans[cs] - 1;
  171|     80|			}
  172|     80|		}
  173|  2.99k|		else {
  174|  2.99k|			_keys = ( _dta_timestamp_parse_trans_keys + (_dta_timestamp_parse_key_offsets[cs]));
  175|  2.99k|			_trans = (unsigned int)_dta_timestamp_parse_index_offsets[cs];
  176|       |			
  177|  2.99k|			_klen = (int)_dta_timestamp_parse_single_lengths[cs];
  178|  2.99k|			if ( _klen > 0 ) {
  ------------------
  |  Branch (178:9): [True: 2.68k, False: 307]
  ------------------
  179|  2.68k|				const char *_lower = _keys;
  180|  2.68k|				const char *_upper = _keys + _klen - 1;
  181|  2.68k|				const char *_mid;
  182|  5.15k|				while ( 1 ) {
  ------------------
  |  Branch (182:13): [True: 5.15k, Folded]
  ------------------
  183|  5.15k|					if ( _upper < _lower ) {
  ------------------
  |  Branch (183:11): [True: 1.93k, False: 3.22k]
  ------------------
  184|  1.93k|						_keys += _klen;
  185|  1.93k|						_trans += (unsigned int)_klen;
  186|  1.93k|						break;
  187|  1.93k|					}
  188|       |					
  189|  3.22k|					_mid = _lower + ((_upper-_lower) >> 1);
  190|  3.22k|					if ( ( (*( p))) < (*( _mid)) )
  ------------------
  |  Branch (190:11): [True: 806, False: 2.41k]
  ------------------
  191|    806|						_upper = _mid - 1;
  192|  2.41k|					else if ( ( (*( p))) > (*( _mid)) )
  ------------------
  |  Branch (192:16): [True: 1.65k, False: 755]
  ------------------
  193|  1.65k|						_lower = _mid + 1;
  194|    755|					else {
  195|    755|						_trans += (unsigned int)(_mid - _keys);
  196|    755|						goto _match;
  197|    755|					}
  198|  3.22k|				}
  199|  2.68k|			}
  200|       |			
  201|  2.23k|			_klen = (int)_dta_timestamp_parse_range_lengths[cs];
  202|  2.23k|			if ( _klen > 0 ) {
  ------------------
  |  Branch (202:9): [True: 2.21k, False: 19]
  ------------------
  203|  2.21k|				const char *_lower = _keys;
  204|  2.21k|				const char *_upper = _keys + (_klen<<1) - 2;
  205|  2.21k|				const char *_mid;
  206|  3.00k|				while ( 1 ) {
  ------------------
  |  Branch (206:13): [True: 3.00k, Folded]
  ------------------
  207|  3.00k|					if ( _upper < _lower ) {
  ------------------
  |  Branch (207:11): [True: 789, False: 2.21k]
  ------------------
  208|    789|						_trans += (unsigned int)_klen;
  209|    789|						break;
  210|    789|					}
  211|       |					
  212|  2.21k|					_mid = _lower + (((_upper-_lower) >> 1) & ~1);
  213|  2.21k|					if ( ( (*( p))) < (*( _mid)) )
  ------------------
  |  Branch (213:11): [True: 453, False: 1.76k]
  ------------------
  214|    453|						_upper = _mid - 2;
  215|  1.76k|					else if ( ( (*( p))) > (*( _mid + 1)) )
  ------------------
  |  Branch (215:16): [True: 336, False: 1.43k]
  ------------------
  216|    336|						_lower = _mid + 2;
  217|  1.43k|					else {
  218|  1.43k|						_trans += (unsigned int)((_mid - _keys)>>1);
  219|  1.43k|						break;
  220|  1.43k|					}
  221|  2.21k|				}
  222|  2.21k|			}
  223|       |			
  224|  2.99k|			_match: {}
  225|  2.99k|		}
  226|  3.07k|		cs = (int)_dta_timestamp_parse_cond_targs[_trans];
  227|       |		
  228|  3.07k|		if ( _dta_timestamp_parse_cond_actions[_trans] != 0 ) {
  ------------------
  |  Branch (228:8): [True: 1.74k, False: 1.32k]
  ------------------
  229|       |			
  230|  1.74k|			_acts = ( _dta_timestamp_parse_actions + (_dta_timestamp_parse_cond_actions[_trans]));
  231|  1.74k|			_nacts = (unsigned int)(*( _acts));
  232|  1.74k|			_acts += 1;
  233|  3.94k|			while ( _nacts > 0 ) {
  ------------------
  |  Branch (233:12): [True: 2.19k, False: 1.74k]
  ------------------
  234|  2.19k|				switch ( (*( _acts)) )
  ------------------
  |  Branch (234:14): [True: 2.19k, False: 0]
  ------------------
  235|  2.19k|				{
  236|  1.43k|					case 0:  {
  ------------------
  |  Branch (236:6): [True: 1.43k, False: 766]
  ------------------
  237|  1.43k|						{
  238|  1.43k|#line 20 "src/stata/readstat_dta_parse_timestamp.rl"
  239|       |							
  240|  1.43k|							temp_val = 10 * temp_val + ((( (*( p)))) - '0');
  241|  1.43k|						}
  242|       |						
  243|  1.43k|#line 244 "src/stata/readstat_dta_parse_timestamp.c"
  244|       |						
  245|  1.43k|						break; 
  246|      0|					}
  247|    451|					case 1:  {
  ------------------
  |  Branch (247:6): [True: 451, False: 1.74k]
  ------------------
  248|    451|						{
  249|    451|#line 24 "src/stata/readstat_dta_parse_timestamp.rl"
  250|    451|							temp_val = 0; }
  251|       |						
  252|    451|#line 253 "src/stata/readstat_dta_parse_timestamp.c"
  253|       |						
  254|    451|						break; 
  255|      0|					}
  256|    116|					case 2:  {
  ------------------
  |  Branch (256:6): [True: 116, False: 2.08k]
  ------------------
  257|    116|						{
  258|    116|#line 26 "src/stata/readstat_dta_parse_timestamp.rl"
  259|    116|							timestamp->tm_mday = temp_val; }
  260|       |						
  261|    116|#line 262 "src/stata/readstat_dta_parse_timestamp.c"
  262|       |						
  263|    116|						break; 
  264|      0|					}
  265|     17|					case 3:  {
  ------------------
  |  Branch (265:6): [True: 17, False: 2.17k]
  ------------------
  266|     17|						{
  267|     17|#line 29 "src/stata/readstat_dta_parse_timestamp.rl"
  268|     17|							timestamp->tm_mon = 0; }
  269|       |						
  270|     17|#line 271 "src/stata/readstat_dta_parse_timestamp.c"
  271|       |						
  272|     17|						break; 
  273|      0|					}
  274|      2|					case 4:  {
  ------------------
  |  Branch (274:6): [True: 2, False: 2.19k]
  ------------------
  275|      2|						{
  276|      2|#line 30 "src/stata/readstat_dta_parse_timestamp.rl"
  277|      2|							timestamp->tm_mon = 1; }
  278|       |						
  279|      2|#line 280 "src/stata/readstat_dta_parse_timestamp.c"
  280|       |						
  281|      2|						break; 
  282|      0|					}
  283|      2|					case 5:  {
  ------------------
  |  Branch (283:6): [True: 2, False: 2.19k]
  ------------------
  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|     17|					case 6:  {
  ------------------
  |  Branch (292:6): [True: 17, False: 2.17k]
  ------------------
  293|     17|						{
  294|     17|#line 32 "src/stata/readstat_dta_parse_timestamp.rl"
  295|     17|							timestamp->tm_mon = 3; }
  296|       |						
  297|     17|#line 298 "src/stata/readstat_dta_parse_timestamp.c"
  298|       |						
  299|     17|						break; 
  300|      0|					}
  301|     14|					case 7:  {
  ------------------
  |  Branch (301:6): [True: 14, False: 2.18k]
  ------------------
  302|     14|						{
  303|     14|#line 33 "src/stata/readstat_dta_parse_timestamp.rl"
  304|     14|							timestamp->tm_mon = 4; }
  305|       |						
  306|     14|#line 307 "src/stata/readstat_dta_parse_timestamp.c"
  307|       |						
  308|     14|						break; 
  309|      0|					}
  310|     14|					case 8:  {
  ------------------
  |  Branch (310:6): [True: 14, False: 2.18k]
  ------------------
  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.19k]
  ------------------
  320|      1|						{
  321|      1|#line 35 "src/stata/readstat_dta_parse_timestamp.rl"
  322|      1|							timestamp->tm_mon = 6; }
  323|       |						
  324|      1|#line 325 "src/stata/readstat_dta_parse_timestamp.c"
  325|       |						
  326|      1|						break; 
  327|      0|					}
  328|      3|					case 10:  {
  ------------------
  |  Branch (328:6): [True: 3, False: 2.19k]
  ------------------
  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|      2|					case 11:  {
  ------------------
  |  Branch (337:6): [True: 2, False: 2.19k]
  ------------------
  338|      2|						{
  339|      2|#line 37 "src/stata/readstat_dta_parse_timestamp.rl"
  340|      2|							timestamp->tm_mon = 8; }
  341|       |						
  342|      2|#line 343 "src/stata/readstat_dta_parse_timestamp.c"
  343|       |						
  344|      2|						break; 
  345|      0|					}
  346|      7|					case 12:  {
  ------------------
  |  Branch (346:6): [True: 7, False: 2.18k]
  ------------------
  347|      7|						{
  348|      7|#line 38 "src/stata/readstat_dta_parse_timestamp.rl"
  349|      7|							timestamp->tm_mon = 9; }
  350|       |						
  351|      7|#line 352 "src/stata/readstat_dta_parse_timestamp.c"
  352|       |						
  353|      7|						break; 
  354|      0|					}
  355|      1|					case 13:  {
  ------------------
  |  Branch (355:6): [True: 1, False: 2.19k]
  ------------------
  356|      1|						{
  357|      1|#line 39 "src/stata/readstat_dta_parse_timestamp.rl"
  358|      1|							timestamp->tm_mon = 10; }
  359|       |						
  360|      1|#line 361 "src/stata/readstat_dta_parse_timestamp.c"
  361|       |						
  362|      1|						break; 
  363|      0|					}
  364|      1|					case 14:  {
  ------------------
  |  Branch (364:6): [True: 1, False: 2.19k]
  ------------------
  365|      1|						{
  366|      1|#line 40 "src/stata/readstat_dta_parse_timestamp.rl"
  367|      1|							timestamp->tm_mon = 11; }
  368|       |						
  369|      1|#line 370 "src/stata/readstat_dta_parse_timestamp.c"
  370|       |						
  371|      1|						break; 
  372|      0|					}
  373|     59|					case 15:  {
  ------------------
  |  Branch (373:6): [True: 59, False: 2.13k]
  ------------------
  374|     59|						{
  375|     59|#line 42 "src/stata/readstat_dta_parse_timestamp.rl"
  376|     59|							timestamp->tm_year = temp_val - 1900; }
  377|       |						
  378|     59|#line 379 "src/stata/readstat_dta_parse_timestamp.c"
  379|       |						
  380|     59|						break; 
  381|      0|					}
  382|     30|					case 16:  {
  ------------------
  |  Branch (382:6): [True: 30, False: 2.16k]
  ------------------
  383|     30|						{
  384|     30|#line 44 "src/stata/readstat_dta_parse_timestamp.rl"
  385|     30|							timestamp->tm_hour = temp_val; }
  386|       |						
  387|     30|#line 388 "src/stata/readstat_dta_parse_timestamp.c"
  388|       |						
  389|     30|						break; 
  390|      0|					}
  391|     29|					case 17:  {
  ------------------
  |  Branch (391:6): [True: 29, False: 2.16k]
  ------------------
  392|     29|						{
  393|     29|#line 46 "src/stata/readstat_dta_parse_timestamp.rl"
  394|     29|							timestamp->tm_min = temp_val; }
  395|       |						
  396|     29|#line 397 "src/stata/readstat_dta_parse_timestamp.c"
  397|       |						
  398|     29|						break; 
  399|      0|					}
  400|  2.19k|				}
  401|  2.19k|				_nacts -= 1;
  402|  2.19k|				_acts += 1;
  403|  2.19k|			}
  404|       |			
  405|  1.74k|		}
  406|       |		
  407|  3.07k|		if ( p == eof ) {
  ------------------
  |  Branch (407:8): [True: 80, False: 2.99k]
  ------------------
  408|     80|			if ( cs >= 44 )
  ------------------
  |  Branch (408:9): [True: 29, False: 51]
  ------------------
  409|     29|				goto _out;
  410|     80|		}
  411|  2.99k|		else {
  412|  2.99k|			if ( cs != 0 ) {
  ------------------
  |  Branch (412:9): [True: 2.18k, False: 808]
  ------------------
  413|  2.18k|				p += 1;
  414|  2.18k|				goto _resume;
  415|  2.18k|			}
  416|  2.99k|		}
  417|    888|		_out: {}
  418|    888|	}
  419|       |	
  420|      0|#line 52 "src/stata/readstat_dta_parse_timestamp.rl"
  421|       |	
  422|       |	
  423|    888|	if (cs < 
  ------------------
  |  Branch (423:6): [True: 859, False: 29]
  ------------------
  424|    888|#line 425 "src/stata/readstat_dta_parse_timestamp.c"
  425|    888|	44
  426|     29|#line 54 "src/stata/readstat_dta_parse_timestamp.rl"
  427|    859|	|| p != pe) {
  ------------------
  |  Branch (427:5): [True: 0, False: 29]
  ------------------
  428|    859|		char error_buf[1024];
  429|    859|		if (error_handler) {
  ------------------
  |  Branch (429:7): [True: 0, False: 859]
  ------------------
  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|    859|		retval = READSTAT_ERROR_BAD_TIMESTAMP_STRING;
  434|    859|	}
  435|       |	
  436|    888|	(void)dta_timestamp_parse_en_main;
  437|       |	
  438|    888|	return retval;
  439|  3.07k|}

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

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

