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

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

machine_is_little_endian:
   11|  5.07k|int machine_is_little_endian(void) {
   12|  5.07k|    int test_byte_order = 1;
   13|  5.07k|    return ((char *)&test_byte_order)[0];
   14|  5.07k|}
byteswap4:
   44|   685k|uint32_t byteswap4(uint32_t num) {
   45|   685k|    num = ((num & 0xFFFF0000) >> 16) | ((num & 0x0000FFFF) << 16);
   46|   685k|    return ((num & 0xFF00FF00) >> 8) | ((num & 0x00FF00FF) << 8);
   47|   685k|}
byteswap8:
   49|  3.55M|uint64_t byteswap8(uint64_t num) {
   50|  3.55M|    num = ((num & 0xFFFFFFFF00000000) >> 32) | ((num & 0x00000000FFFFFFFF) << 32);
   51|  3.55M|    num = ((num & 0xFFFF0000FFFF0000) >> 16) | ((num & 0x0000FFFF0000FFFF) << 16);
   52|  3.55M|    return ((num & 0xFF00FF00FF00FF00) >> 8) | ((num & 0x00FF00FF00FF00FF) << 8);
   53|  3.55M|}
byteswap_double:
   63|  2.19M|double byteswap_double(double num) {
   64|  2.19M|    uint64_t answer = 0;
   65|  2.19M|    memcpy(&answer, &num, 8);
   66|  2.19M|    answer = byteswap8(answer);
   67|  2.19M|    memcpy(&num, &answer, 8);
   68|  2.19M|    return num;
   69|  2.19M|}

readstat_convert:
    7|  2.10M|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|  19.2M|    while (src_len && (src[src_len-1] == ' ' || src[src_len-1] == '\0')) {
  ------------------
  |  Branch (10:12): [True: 19.1M, False: 16.7k]
  |  Branch (10:24): [True: 2.19M, False: 17.0M]
  |  Branch (10:49): [True: 14.9M, False: 2.08M]
  ------------------
   11|  17.1M|        src_len--;
   12|  17.1M|    }
   13|  2.10M|    if (dst_len == 0) {
  ------------------
  |  Branch (13:9): [True: 0, False: 2.10M]
  ------------------
   14|      0|        return READSTAT_ERROR_CONVERT_LONG_STRING;
   15|  2.10M|    } else if (converter) {
  ------------------
  |  Branch (15:16): [True: 1.29k, False: 2.10M]
  ------------------
   16|  1.29k|        size_t dst_left = dst_len - 1;
   17|  1.29k|        char *dst_end = dst;
   18|  1.29k|        size_t status = iconv(converter, (readstat_iconv_inbuf_t)&src, &src_len, &dst_end, &dst_left);
   19|  1.29k|        if (status == (size_t)-1) {
  ------------------
  |  Branch (19:13): [True: 682, False: 610]
  ------------------
   20|    682|            if (errno == E2BIG) {
  ------------------
  |  Branch (20:17): [True: 1, False: 681]
  ------------------
   21|      1|                return READSTAT_ERROR_CONVERT_LONG_STRING;
   22|    681|            } else if (errno == EILSEQ) {
  ------------------
  |  Branch (22:24): [True: 409, False: 272]
  ------------------
   23|    409|                return READSTAT_ERROR_CONVERT_BAD_STRING;
   24|    409|            } else if (errno != EINVAL) { /* EINVAL indicates improper truncation; accept it */
  ------------------
  |  Branch (24:24): [True: 0, False: 272]
  ------------------
   25|      0|                return READSTAT_ERROR_CONVERT;
   26|      0|            }
   27|    682|        }
   28|    882|        dst[dst_len - dst_left - 1] = '\0';
   29|  2.10M|    } else if (src_len + 1 > dst_len) {
  ------------------
  |  Branch (29:16): [True: 20, False: 2.10M]
  ------------------
   30|     20|        return READSTAT_ERROR_CONVERT_LONG_STRING;
   31|  2.10M|    } else {
   32|  2.10M|        memcpy(dst, src, src_len);
   33|  2.10M|        dst[src_len] = '\0';
   34|  2.10M|    }
   35|  2.10M|    return READSTAT_OK;
   36|  2.10M|}

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

readstat_malloc:
   10|  94.6k|void *readstat_malloc(size_t len) {
   11|  94.6k|    if (len > MAX_MALLOC_SIZE || len == 0) {
  ------------------
  |  |    3|   189k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
  |  Branch (11:9): [True: 167, False: 94.4k]
  |  Branch (11:34): [True: 1.33k, False: 93.1k]
  ------------------
   12|  1.50k|        return NULL;
   13|  1.50k|    }
   14|  93.1k|    return malloc(len);
   15|  94.6k|}
readstat_calloc:
   17|   347k|void *readstat_calloc(size_t count, size_t size) {
   18|   347k|    if (count > MAX_MALLOC_SIZE || size > MAX_MALLOC_SIZE || count * size > MAX_MALLOC_SIZE) {
  ------------------
  |  |    3|   694k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
                  if (count > MAX_MALLOC_SIZE || size > MAX_MALLOC_SIZE || count * size > MAX_MALLOC_SIZE) {
  ------------------
  |  |    3|   694k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
                  if (count > MAX_MALLOC_SIZE || size > MAX_MALLOC_SIZE || count * size > MAX_MALLOC_SIZE) {
  ------------------
  |  |    3|   347k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
  |  Branch (18:9): [True: 22, False: 347k]
  |  Branch (18:36): [True: 0, False: 347k]
  |  Branch (18:62): [True: 1, False: 347k]
  ------------------
   19|     23|        return NULL;
   20|     23|    }
   21|   347k|    if (count == 0 || size == 0) {
  ------------------
  |  Branch (21:9): [True: 7, False: 347k]
  |  Branch (21:23): [True: 0, False: 347k]
  ------------------
   22|      7|        return NULL;
   23|      7|    }
   24|   347k|    return calloc(count, size);
   25|   347k|}
readstat_realloc:
   27|  3.64k|void *readstat_realloc(void *ptr, size_t len) {
   28|  3.64k|    if (len > MAX_MALLOC_SIZE || len == 0) {
  ------------------
  |  |    3|  7.29k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
  |  Branch (28:9): [True: 134, False: 3.51k]
  |  Branch (28:34): [True: 3, False: 3.50k]
  ------------------
   29|    137|        if (ptr)
  ------------------
  |  Branch (29:13): [True: 74, False: 63]
  ------------------
   30|     74|            free(ptr);
   31|    137|        return NULL;
   32|    137|    }
   33|  3.50k|    return realloc(ptr, len);
   34|  3.64k|}

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

sav_ctx_init:
   23|  5.11k|sav_ctx_t *sav_ctx_init(sav_file_header_record_t *header, readstat_io_t *io) {
   24|  5.11k|    sav_ctx_t *ctx = readstat_calloc(1, sizeof(sav_ctx_t));
   25|  5.11k|    if (ctx == NULL) {
  ------------------
  |  Branch (25:9): [True: 0, False: 5.11k]
  ------------------
   26|      0|        return NULL;
   27|      0|    }
   28|       |
   29|  5.11k|    if (memcmp(&header->rec_type, "$FL2", 4) == 0) {
  ------------------
  |  Branch (29:9): [True: 2.85k, False: 2.25k]
  ------------------
   30|  2.85k|        ctx->format_version = 2;
   31|  2.85k|    } else if (memcmp(&header->rec_type, "$FL3", 4) == 0) {
  ------------------
  |  Branch (31:16): [True: 2.22k, False: 32]
  ------------------
   32|  2.22k|        ctx->format_version = 3;
   33|  2.22k|    } else {
   34|     32|        sav_ctx_free(ctx);
   35|     32|        return NULL;
   36|     32|    }
   37|       |    
   38|  5.07k|    ctx->bswap = !(header->layout_code == 2 || header->layout_code == 3);
  ------------------
  |  Branch (38:20): [True: 3.39k, False: 1.68k]
  |  Branch (38:48): [True: 87, False: 1.59k]
  ------------------
   39|  5.07k|    ctx->endianness = (machine_is_little_endian() ^ ctx->bswap) ? READSTAT_ENDIAN_LITTLE : READSTAT_ENDIAN_BIG;
  ------------------
  |  Branch (39:23): [True: 3.48k, False: 1.59k]
  ------------------
   40|       |
   41|  5.07k|    if (header->compression == 1 || byteswap4(header->compression) == 1) {
  ------------------
  |  Branch (41:9): [True: 353, False: 4.72k]
  |  Branch (41:37): [True: 246, False: 4.48k]
  ------------------
   42|    599|        ctx->compression = READSTAT_COMPRESS_ROWS;
   43|  4.48k|    } else if (header->compression == 2 || byteswap4(header->compression) == 2) {
  ------------------
  |  Branch (43:16): [True: 561, False: 3.91k]
  |  Branch (43:44): [True: 47, False: 3.87k]
  ------------------
   44|    608|        ctx->compression = READSTAT_COMPRESS_BINARY;
   45|    608|    }
   46|  5.07k|    ctx->record_count = ctx->bswap ? byteswap4(header->ncases) : header->ncases;
  ------------------
  |  Branch (46:25): [True: 1.59k, False: 3.48k]
  ------------------
   47|  5.07k|    ctx->fweight_index = ctx->bswap ? byteswap4(header->weight_index) : header->weight_index;
  ------------------
  |  Branch (47:26): [True: 1.59k, False: 3.48k]
  ------------------
   48|       |
   49|  5.07k|    ctx->missing_double = SAV_MISSING_DOUBLE;
  ------------------
  |  |   43|  5.07k|#define SAV_MISSING_DOUBLE   0xFFEFFFFFFFFFFFFFUL
  ------------------
   50|  5.07k|    ctx->lowest_double = SAV_LOWEST_DOUBLE;
  ------------------
  |  |   44|  5.07k|#define SAV_LOWEST_DOUBLE    0xFFEFFFFFFFFFFFFEUL
  ------------------
   51|  5.07k|    ctx->highest_double = SAV_HIGHEST_DOUBLE;
  ------------------
  |  |   42|  5.07k|#define SAV_HIGHEST_DOUBLE   0x7FEFFFFFFFFFFFFFUL
  ------------------
   52|       |    
   53|  5.07k|    ctx->bias = ctx->bswap ? byteswap_double(header->bias) : header->bias;
  ------------------
  |  Branch (53:17): [True: 1.59k, False: 3.48k]
  ------------------
   54|       |    
   55|  5.07k|    ctx->varinfo_capacity = SAV_VARINFO_INITIAL_CAPACITY;
  ------------------
  |  |   21|  5.07k|#define SAV_VARINFO_INITIAL_CAPACITY  512
  ------------------
   56|       |    
   57|  5.07k|    if ((ctx->varinfo = readstat_calloc(ctx->varinfo_capacity, sizeof(spss_varinfo_t *))) == NULL) {
  ------------------
  |  Branch (57:9): [True: 0, False: 5.07k]
  ------------------
   58|      0|        sav_ctx_free(ctx);
   59|      0|        return NULL;
   60|      0|    }
   61|       |
   62|  5.07k|    ctx->io = io;
   63|       |    
   64|  5.07k|    return ctx;
   65|  5.07k|}
sav_ctx_free:
   67|  5.11k|void sav_ctx_free(sav_ctx_t *ctx) {
   68|  5.11k|    if (ctx->varinfo) {
  ------------------
  |  Branch (68:9): [True: 5.07k, False: 32]
  ------------------
   69|  5.07k|        int i;
   70|   338k|        for (i=0; i<ctx->var_index; i++) {
  ------------------
  |  Branch (70:19): [True: 333k, False: 5.07k]
  ------------------
   71|   333k|            spss_varinfo_free(ctx->varinfo[i]);
   72|   333k|        }
   73|  5.07k|        free(ctx->varinfo);
   74|  5.07k|    }
   75|  5.11k|    if (ctx->variables) {
  ------------------
  |  Branch (75:9): [True: 1.47k, False: 3.63k]
  ------------------
   76|  1.47k|        int i;
   77|   202k|        for (i=0; i<ctx->var_count; i++) {
  ------------------
  |  Branch (77:19): [True: 200k, False: 1.47k]
  ------------------
   78|   200k|            if (ctx->variables[i])
  ------------------
  |  Branch (78:17): [True: 200k, False: 225]
  ------------------
   79|   200k|                free(ctx->variables[i]);
   80|   200k|        }
   81|  1.47k|        free(ctx->variables);
   82|  1.47k|    }
   83|  5.11k|    if (ctx->raw_string)
  ------------------
  |  Branch (83:9): [True: 1.41k, False: 3.69k]
  ------------------
   84|  1.41k|        free(ctx->raw_string);
   85|  5.11k|    if (ctx->utf8_string)
  ------------------
  |  Branch (85:9): [True: 1.40k, False: 3.70k]
  ------------------
   86|  1.40k|        free(ctx->utf8_string);
   87|  5.11k|    if (ctx->converter)
  ------------------
  |  Branch (87:9): [True: 94, False: 5.01k]
  ------------------
   88|     94|        iconv_close(ctx->converter);
   89|  5.11k|    if (ctx->variable_display_values) {
  ------------------
  |  Branch (89:9): [True: 236, False: 4.87k]
  ------------------
   90|    236|        free(ctx->variable_display_values);
   91|    236|    }
   92|  5.11k|    free(ctx);
   93|  5.11k|}

sav_decompress_row:
   77|  2.24M|void sav_decompress_row(struct sav_row_stream_s *state) {
   78|  2.24M|    double fp_value;
   79|  2.24M|    uint64_t missing_value = state->bswap ? byteswap8(state->missing_value) : state->missing_value;
  ------------------
  |  Branch (79:30): [True: 1.34M, False: 901k]
  ------------------
   80|  2.24M|    int i = 8 - state->i;
   81|  2.48M|    while (1) {
  ------------------
  |  Branch (81:12): [Folded - Ignored]
  ------------------
   82|  2.48M|        if (i == 8) {
  ------------------
  |  Branch (82:13): [True: 521k, False: 1.96M]
  ------------------
   83|   521k|            if (state->avail_in < 8) {
  ------------------
  |  Branch (83:17): [True: 308, False: 521k]
  ------------------
   84|    308|                state->status = SAV_ROW_STREAM_NEED_DATA;
   85|    308|                goto done;
   86|    308|            }
   87|       |
   88|   521k|            memcpy(state->chunk, state->next_in, 8);
   89|   521k|            state->next_in += 8;
   90|   521k|            state->avail_in -= 8;
   91|   521k|            i = 0;
   92|   521k|        }
   93|       |
   94|  4.41M|        while (i<8) {
  ------------------
  |  Branch (94:16): [True: 4.16M, False: 241k]
  ------------------
   95|  4.16M|            switch (state->chunk[i]) {
   96|  1.63M|                case 0:
  ------------------
  |  Branch (96:17): [True: 1.63M, False: 2.53M]
  ------------------
   97|  1.63M|                    break;
   98|     60|                case 252:
  ------------------
  |  Branch (98:17): [True: 60, False: 4.16M]
  ------------------
   99|     60|                    state->status = SAV_ROW_STREAM_FINISHED_ALL;
  100|     60|                    goto done;
  101|  95.1k|                case 253:
  ------------------
  |  Branch (101:17): [True: 95.1k, False: 4.07M]
  ------------------
  102|  95.1k|                    if (state->avail_in < 8) {
  ------------------
  |  Branch (102:25): [True: 50, False: 95.1k]
  ------------------
  103|     50|                        state->status = SAV_ROW_STREAM_NEED_DATA;
  104|     50|                        goto done;
  105|     50|                    }
  106|  95.1k|                    memcpy(state->next_out, state->next_in, 8);
  107|  95.1k|                    state->next_out += 8;
  108|  95.1k|                    state->avail_out -= 8;
  109|  95.1k|                    state->next_in += 8;
  110|  95.1k|                    state->avail_in -= 8;
  111|  95.1k|                    break;
  112|  3.60k|                case 254:
  ------------------
  |  Branch (112:17): [True: 3.60k, False: 4.16M]
  ------------------
  113|  3.60k|                    memset(state->next_out, ' ', 8);
  114|  3.60k|                    state->next_out += 8;
  115|  3.60k|                    state->avail_out -= 8;
  116|  3.60k|                    break;
  117|   111k|                case 255:
  ------------------
  |  Branch (117:17): [True: 111k, False: 4.05M]
  ------------------
  118|   111k|                    memcpy(state->next_out, &missing_value, sizeof(uint64_t));
  119|   111k|                    state->next_out += 8;
  120|   111k|                    state->avail_out -= 8;
  121|   111k|                    break;
  122|  2.32M|                default:
  ------------------
  |  Branch (122:17): [True: 2.32M, False: 1.84M]
  ------------------
  123|  2.32M|                    fp_value = state->chunk[i] - state->bias;
  124|  2.32M|                    fp_value = state->bswap ? byteswap_double(fp_value) : fp_value;
  ------------------
  |  Branch (124:32): [True: 1.24M, False: 1.07M]
  ------------------
  125|  2.32M|                    memcpy(state->next_out, &fp_value, sizeof(double));
  126|  2.32M|                    state->next_out += 8;
  127|  2.32M|                    state->avail_out -= 8;
  128|  2.32M|                    break;
  129|  4.16M|            }
  130|  4.16M|            i++;
  131|  4.16M|            if (state->avail_out < 8) {
  ------------------
  |  Branch (131:17): [True: 2.24M, False: 1.92M]
  ------------------
  132|  2.24M|                state->status = SAV_ROW_STREAM_FINISHED_ROW;
  133|  2.24M|                goto done;
  134|  2.24M|            }
  135|  4.16M|        }
  136|  2.48M|    }
  137|  2.24M|done:
  138|  2.24M|    state->i = 8 - i;
  139|  2.24M|}

sav_parse_long_variable_names_record:
  329|  1.21k|readstat_error_t sav_parse_long_variable_names_record(void *data, int count, sav_ctx_t *ctx) {
  330|  1.21k|	unsigned char *c_data = (unsigned char *)data;
  331|  1.21k|	int var_count = count_vars(ctx);
  332|  1.21k|	readstat_error_t retval = READSTAT_OK;
  333|       |	
  334|  1.21k|	char temp_key[8+1];
  335|  1.21k|	char temp_val[64+1];
  336|  1.21k|	unsigned char *str_start = NULL;
  337|  1.21k|	size_t str_len = 0;
  338|       |	
  339|  1.21k|	char error_buf[8192];
  340|  1.21k|	unsigned char *p = c_data;
  341|  1.21k|	unsigned char *pe = c_data + count;
  342|       |	
  343|  1.21k|	varlookup_t *table = build_lookup_table(var_count, ctx);
  344|       |	
  345|  1.21k|	unsigned char *eof = pe;
  346|       |	
  347|  1.21k|	int cs;
  348|       |	
  349|       |	
  350|  1.21k|#line 351 "src/spss/readstat_sav_parse.c"
  351|  1.21k|	{
  352|  1.21k|		cs = (int)sav_long_variable_parse_start;
  353|  1.21k|	}
  354|       |	
  355|  1.21k|#line 356 "src/spss/readstat_sav_parse.c"
  356|  1.21k|	{
  357|  1.21k|		int _klen;
  358|  1.21k|		unsigned int _trans = 0;
  359|  1.21k|		const unsigned char * _keys;
  360|  1.21k|		const signed char * _acts;
  361|  1.21k|		unsigned int _nacts;
  362|  9.99k|		_resume: {}
  363|  9.99k|		if ( p == pe && p != eof )
  ------------------
  |  Branch (363:8): [True: 1.16k, False: 8.83k]
  |  Branch (363:19): [True: 0, False: 1.16k]
  ------------------
  364|      0|			goto _out;
  365|  9.99k|		if ( p == eof ) {
  ------------------
  |  Branch (365:8): [True: 1.16k, False: 8.83k]
  ------------------
  366|  1.16k|			if ( _sav_long_variable_parse_eof_trans[cs] > 0 ) {
  ------------------
  |  Branch (366:9): [True: 1.16k, False: 0]
  ------------------
  367|  1.16k|				_trans = (unsigned int)_sav_long_variable_parse_eof_trans[cs] - 1;
  368|  1.16k|			}
  369|  1.16k|		}
  370|  8.83k|		else {
  371|  8.83k|			_keys = ( _sav_long_variable_parse_trans_keys + (_sav_long_variable_parse_key_offsets[cs]));
  372|  8.83k|			_trans = (unsigned int)_sav_long_variable_parse_index_offsets[cs];
  373|       |			
  374|  8.83k|			_klen = (int)_sav_long_variable_parse_single_lengths[cs];
  375|  8.83k|			if ( _klen > 0 ) {
  ------------------
  |  Branch (375:9): [True: 8.83k, False: 0]
  ------------------
  376|  8.83k|				const unsigned char *_lower = _keys;
  377|  8.83k|				const unsigned char *_upper = _keys + _klen - 1;
  378|  8.83k|				const unsigned char *_mid;
  379|  17.9k|				while ( 1 ) {
  ------------------
  |  Branch (379:13): [Folded - Ignored]
  ------------------
  380|  17.9k|					if ( _upper < _lower ) {
  ------------------
  |  Branch (380:11): [True: 5.80k, False: 12.1k]
  ------------------
  381|  5.80k|						_keys += _klen;
  382|  5.80k|						_trans += (unsigned int)_klen;
  383|  5.80k|						break;
  384|  5.80k|					}
  385|       |					
  386|  12.1k|					_mid = _lower + ((_upper-_lower) >> 1);
  387|  12.1k|					if ( ( (*( p))) < (*( _mid)) )
  ------------------
  |  Branch (387:11): [True: 6.90k, False: 5.25k]
  ------------------
  388|  6.90k|						_upper = _mid - 1;
  389|  5.25k|					else if ( ( (*( p))) > (*( _mid)) )
  ------------------
  |  Branch (389:16): [True: 2.23k, False: 3.02k]
  ------------------
  390|  2.23k|						_lower = _mid + 1;
  391|  3.02k|					else {
  392|  3.02k|						_trans += (unsigned int)(_mid - _keys);
  393|  3.02k|						goto _match;
  394|  3.02k|					}
  395|  12.1k|				}
  396|  8.83k|			}
  397|       |			
  398|  5.80k|			_klen = (int)_sav_long_variable_parse_range_lengths[cs];
  399|  5.80k|			if ( _klen > 0 ) {
  ------------------
  |  Branch (399:9): [True: 5.80k, False: 4]
  ------------------
  400|  5.80k|				const unsigned char *_lower = _keys;
  401|  5.80k|				const unsigned char *_upper = _keys + (_klen<<1) - 2;
  402|  5.80k|				const unsigned char *_mid;
  403|  15.1k|				while ( 1 ) {
  ------------------
  |  Branch (403:13): [Folded - Ignored]
  ------------------
  404|  15.1k|					if ( _upper < _lower ) {
  ------------------
  |  Branch (404:11): [True: 5.76k, False: 9.37k]
  ------------------
  405|  5.76k|						_trans += (unsigned int)_klen;
  406|  5.76k|						break;
  407|  5.76k|					}
  408|       |					
  409|  9.37k|					_mid = _lower + (((_upper-_lower) >> 1) & ~1);
  410|  9.37k|					if ( ( (*( p))) < (*( _mid)) )
  ------------------
  |  Branch (410:11): [True: 1.72k, False: 7.65k]
  ------------------
  411|  1.72k|						_upper = _mid - 2;
  412|  7.65k|					else if ( ( (*( p))) > (*( _mid + 1)) )
  ------------------
  |  Branch (412:16): [True: 7.60k, False: 44]
  ------------------
  413|  7.60k|						_lower = _mid + 2;
  414|     44|					else {
  415|     44|						_trans += (unsigned int)((_mid - _keys)>>1);
  416|     44|						break;
  417|     44|					}
  418|  9.37k|				}
  419|  5.80k|			}
  420|       |			
  421|  8.83k|			_match: {}
  422|  8.83k|		}
  423|  9.99k|		cs = (int)_sav_long_variable_parse_cond_targs[_trans];
  424|       |		
  425|  9.99k|		if ( _sav_long_variable_parse_cond_actions[_trans] != 0 ) {
  ------------------
  |  Branch (425:8): [True: 8.22k, False: 1.76k]
  ------------------
  426|       |			
  427|  8.22k|			_acts = ( _sav_long_variable_parse_actions + (_sav_long_variable_parse_cond_actions[_trans]));
  428|  8.22k|			_nacts = (unsigned int)(*( _acts));
  429|  8.22k|			_acts += 1;
  430|  22.5k|			while ( _nacts > 0 ) {
  ------------------
  |  Branch (430:12): [True: 14.2k, False: 8.22k]
  ------------------
  431|  14.2k|				switch ( (*( _acts)) )
  ------------------
  |  Branch (431:14): [True: 0, False: 14.2k]
  ------------------
  432|  14.2k|				{
  433|  2.02k|					case 0:  {
  ------------------
  |  Branch (433:6): [True: 2.02k, False: 12.2k]
  ------------------
  434|  2.02k|						{
  435|  2.02k|#line 13 "src/spss/readstat_sav_parse.rl"
  436|       |							
  437|  2.02k|							memcpy(temp_key, str_start, str_len);
  438|  2.02k|							temp_key[str_len] = '\0';
  439|  2.02k|						}
  440|       |						
  441|  2.02k|#line 442 "src/spss/readstat_sav_parse.c"
  442|       |						
  443|  2.02k|						break; 
  444|      0|					}
  445|  2.16k|					case 1:  {
  ------------------
  |  Branch (445:6): [True: 2.16k, False: 12.1k]
  ------------------
  446|  2.16k|						{
  447|  2.16k|#line 20 "src/spss/readstat_sav_parse.rl"
  448|  2.16k|							str_start = p; }
  449|       |						
  450|  2.16k|#line 451 "src/spss/readstat_sav_parse.c"
  451|       |						
  452|  2.16k|						break; 
  453|      0|					}
  454|  2.02k|					case 2:  {
  ------------------
  |  Branch (454:6): [True: 2.02k, False: 12.2k]
  ------------------
  455|  2.02k|						{
  456|  2.02k|#line 20 "src/spss/readstat_sav_parse.rl"
  457|  2.02k|							str_len = p - str_start; }
  458|       |						
  459|  2.02k|#line 460 "src/spss/readstat_sav_parse.c"
  460|       |						
  461|  2.02k|						break; 
  462|      0|					}
  463|  2.01k|					case 3:  {
  ------------------
  |  Branch (463:6): [True: 2.01k, False: 12.2k]
  ------------------
  464|  2.01k|						{
  465|  2.01k|#line 102 "src/spss/readstat_sav_parse.rl"
  466|       |							
  467|  2.01k|							varlookup_t *found = bsearch(temp_key, table, var_count, sizeof(varlookup_t), &compare_key_varlookup);
  468|  2.01k|							if (found) {
  ------------------
  |  Branch (468:12): [True: 197, False: 1.82k]
  ------------------
  469|    197|								spss_varinfo_t *info = ctx->varinfo[found->index];
  470|    197|								memcpy(info->longname, temp_val, str_len);
  471|    197|								info->longname[str_len] = '\0';
  472|  1.82k|							} else if (ctx->handle.error) {
  ------------------
  |  Branch (472:19): [True: 0, False: 1.82k]
  ------------------
  473|      0|								snprintf(error_buf, sizeof(error_buf), "Failed to find %s", temp_key);
  474|      0|								ctx->handle.error(error_buf, ctx->user_ctx);
  475|      0|							}
  476|  2.01k|						}
  477|       |						
  478|  2.01k|#line 479 "src/spss/readstat_sav_parse.c"
  479|       |						
  480|  2.01k|						break; 
  481|      0|					}
  482|  2.01k|					case 4:  {
  ------------------
  |  Branch (482:6): [True: 2.01k, False: 12.2k]
  ------------------
  483|  2.01k|						{
  484|  2.01k|#line 114 "src/spss/readstat_sav_parse.rl"
  485|       |							
  486|  2.01k|							memcpy(temp_val, str_start, str_len);
  487|  2.01k|							temp_val[str_len] = '\0';
  488|  2.01k|						}
  489|       |						
  490|  2.01k|#line 491 "src/spss/readstat_sav_parse.c"
  491|       |						
  492|  2.01k|						break; 
  493|      0|					}
  494|  2.02k|					case 5:  {
  ------------------
  |  Branch (494:6): [True: 2.02k, False: 12.2k]
  ------------------
  495|  2.02k|						{
  496|  2.02k|#line 119 "src/spss/readstat_sav_parse.rl"
  497|  2.02k|							str_start = p; }
  498|       |						
  499|  2.02k|#line 500 "src/spss/readstat_sav_parse.c"
  500|       |						
  501|  2.02k|						break; 
  502|      0|					}
  503|  2.01k|					case 6:  {
  ------------------
  |  Branch (503:6): [True: 2.01k, False: 12.2k]
  ------------------
  504|  2.01k|						{
  505|  2.01k|#line 119 "src/spss/readstat_sav_parse.rl"
  506|  2.01k|							str_len = p - str_start; }
  507|       |						
  508|  2.01k|#line 509 "src/spss/readstat_sav_parse.c"
  509|       |						
  510|  2.01k|						break; 
  511|      0|					}
  512|  14.2k|				}
  513|  14.2k|				_nacts -= 1;
  514|  14.2k|				_acts += 1;
  515|  14.2k|			}
  516|       |			
  517|  8.22k|		}
  518|       |		
  519|  9.99k|		if ( p == eof ) {
  ------------------
  |  Branch (519:8): [True: 1.16k, False: 8.83k]
  ------------------
  520|  1.16k|			if ( cs >= 11 )
  ------------------
  |  Branch (520:9): [True: 1.03k, False: 125]
  ------------------
  521|  1.03k|				goto _out;
  522|  1.16k|		}
  523|  8.83k|		else {
  524|  8.83k|			if ( cs != 0 ) {
  ------------------
  |  Branch (524:9): [True: 8.77k, False: 55]
  ------------------
  525|  8.77k|				p += 1;
  526|  8.77k|				goto _resume;
  527|  8.77k|			}
  528|  8.83k|		}
  529|  1.21k|		_out: {}
  530|  1.21k|	}
  531|       |	
  532|      0|#line 127 "src/spss/readstat_sav_parse.rl"
  533|       |	
  534|       |	
  535|  1.21k|	if (cs < 
  ------------------
  |  Branch (535:6): [True: 180, False: 1.03k]
  ------------------
  536|  1.21k|#line 537 "src/spss/readstat_sav_parse.c"
  537|  1.21k|	11
  538|  1.21k|#line 129 "src/spss/readstat_sav_parse.rl"
  539|  1.21k|	|| p != pe) {
  ------------------
  |  Branch (539:5): [True: 0, False: 1.03k]
  ------------------
  540|    180|		if (ctx->handle.error) {
  ------------------
  |  Branch (540:7): [True: 0, False: 180]
  ------------------
  541|      0|			snprintf(error_buf, sizeof(error_buf), "Error parsing string \"%.*s\" around byte #%ld/%d, character %c", 
  542|      0|			count, (char *)data, (long)(p - c_data), count, *p);
  543|      0|			ctx->handle.error(error_buf, ctx->user_ctx);
  544|      0|		}
  545|    180|		retval = READSTAT_ERROR_PARSE;
  546|    180|	}
  547|       |	
  548|       |	
  549|  1.21k|	if (table)
  ------------------
  |  Branch (549:6): [True: 585, False: 630]
  ------------------
  550|    585|		free(table);
  551|       |	
  552|       |	/* suppress warning */
  553|  1.21k|	(void)sav_long_variable_parse_en_main;
  554|       |	
  555|  1.21k|	return retval;
  556|  9.99k|}
sav_parse_very_long_string_record:
  648|  2.01k|readstat_error_t sav_parse_very_long_string_record(void *data, int count, sav_ctx_t *ctx) {
  649|  2.01k|	unsigned char *c_data = (unsigned char *)data;
  650|  2.01k|	int var_count = count_vars(ctx);
  651|  2.01k|	readstat_error_t retval = READSTAT_OK;
  652|       |	
  653|  2.01k|	char temp_key[8*4+1];
  654|  2.01k|	unsigned int temp_val = 0;
  655|  2.01k|	unsigned char *str_start = NULL;
  656|  2.01k|	size_t str_len = 0;
  657|       |	
  658|  2.01k|	size_t error_buf_len = 1024 + count;
  659|  2.01k|	char *error_buf = NULL;
  660|  2.01k|	unsigned char *p = c_data;
  661|  2.01k|	unsigned char *pe = c_data + count;
  662|  2.01k|	unsigned char *eof = pe;
  663|       |	
  664|  2.01k|	varlookup_t *table = NULL;
  665|  2.01k|	int cs;
  666|       |	
  667|  2.01k|	error_buf = readstat_malloc(error_buf_len);
  668|  2.01k|	table = build_lookup_table(var_count, ctx);
  669|       |	
  670|       |	
  671|  2.01k|#line 672 "src/spss/readstat_sav_parse.c"
  672|  2.01k|	{
  673|  2.01k|		cs = (int)sav_very_long_string_parse_start;
  674|  2.01k|	}
  675|       |	
  676|  2.01k|#line 677 "src/spss/readstat_sav_parse.c"
  677|  2.01k|	{
  678|  2.01k|		int _klen;
  679|  2.01k|		unsigned int _trans = 0;
  680|  2.01k|		const unsigned char * _keys;
  681|  2.01k|		const signed char * _acts;
  682|  2.01k|		unsigned int _nacts;
  683|  19.1k|		_resume: {}
  684|  19.1k|		if ( p == pe && p != eof )
  ------------------
  |  Branch (684:8): [True: 1.70k, False: 17.4k]
  |  Branch (684:19): [True: 0, False: 1.70k]
  ------------------
  685|      0|			goto _out;
  686|  19.1k|		if ( p == eof ) {
  ------------------
  |  Branch (686:8): [True: 1.70k, False: 17.4k]
  ------------------
  687|  1.70k|			if ( _sav_very_long_string_parse_eof_trans[cs] > 0 ) {
  ------------------
  |  Branch (687:9): [True: 1.70k, False: 0]
  ------------------
  688|  1.70k|				_trans = (unsigned int)_sav_very_long_string_parse_eof_trans[cs] - 1;
  689|  1.70k|			}
  690|  1.70k|		}
  691|  17.4k|		else {
  692|  17.4k|			_keys = ( _sav_very_long_string_parse_trans_keys + (_sav_very_long_string_parse_key_offsets[cs]));
  693|  17.4k|			_trans = (unsigned int)_sav_very_long_string_parse_index_offsets[cs];
  694|       |			
  695|  17.4k|			_klen = (int)_sav_very_long_string_parse_single_lengths[cs];
  696|  17.4k|			if ( _klen > 0 ) {
  ------------------
  |  Branch (696:9): [True: 14.8k, False: 2.62k]
  ------------------
  697|  14.8k|				const unsigned char *_lower = _keys;
  698|  14.8k|				const unsigned char *_upper = _keys + _klen - 1;
  699|  14.8k|				const unsigned char *_mid;
  700|  31.6k|				while ( 1 ) {
  ------------------
  |  Branch (700:13): [Folded - Ignored]
  ------------------
  701|  31.6k|					if ( _upper < _lower ) {
  ------------------
  |  Branch (701:11): [True: 9.15k, False: 22.4k]
  ------------------
  702|  9.15k|						_keys += _klen;
  703|  9.15k|						_trans += (unsigned int)_klen;
  704|  9.15k|						break;
  705|  9.15k|					}
  706|       |					
  707|  22.4k|					_mid = _lower + ((_upper-_lower) >> 1);
  708|  22.4k|					if ( ( (*( p))) < (*( _mid)) )
  ------------------
  |  Branch (708:11): [True: 4.51k, False: 17.9k]
  ------------------
  709|  4.51k|						_upper = _mid - 1;
  710|  17.9k|					else if ( ( (*( p))) > (*( _mid)) )
  ------------------
  |  Branch (710:16): [True: 12.3k, False: 5.65k]
  ------------------
  711|  12.3k|						_lower = _mid + 1;
  712|  5.65k|					else {
  713|  5.65k|						_trans += (unsigned int)(_mid - _keys);
  714|  5.65k|						goto _match;
  715|  5.65k|					}
  716|  22.4k|				}
  717|  14.8k|			}
  718|       |			
  719|  11.7k|			_klen = (int)_sav_very_long_string_parse_range_lengths[cs];
  720|  11.7k|			if ( _klen > 0 ) {
  ------------------
  |  Branch (720:9): [True: 11.7k, False: 8]
  ------------------
  721|  11.7k|				const unsigned char *_lower = _keys;
  722|  11.7k|				const unsigned char *_upper = _keys + (_klen<<1) - 2;
  723|  11.7k|				const unsigned char *_mid;
  724|  21.5k|				while ( 1 ) {
  ------------------
  |  Branch (724:13): [Folded - Ignored]
  ------------------
  725|  21.5k|					if ( _upper < _lower ) {
  ------------------
  |  Branch (725:11): [True: 4.34k, False: 17.2k]
  ------------------
  726|  4.34k|						_trans += (unsigned int)_klen;
  727|  4.34k|						break;
  728|  4.34k|					}
  729|       |					
  730|  17.2k|					_mid = _lower + (((_upper-_lower) >> 1) & ~1);
  731|  17.2k|					if ( ( (*( p))) < (*( _mid)) )
  ------------------
  |  Branch (731:11): [True: 2.84k, False: 14.3k]
  ------------------
  732|  2.84k|						_upper = _mid - 2;
  733|  14.3k|					else if ( ( (*( p))) > (*( _mid + 1)) )
  ------------------
  |  Branch (733:16): [True: 6.94k, False: 7.42k]
  ------------------
  734|  6.94k|						_lower = _mid + 2;
  735|  7.42k|					else {
  736|  7.42k|						_trans += (unsigned int)((_mid - _keys)>>1);
  737|  7.42k|						break;
  738|  7.42k|					}
  739|  17.2k|				}
  740|  11.7k|			}
  741|       |			
  742|  17.4k|			_match: {}
  743|  17.4k|		}
  744|  19.1k|		cs = (int)_sav_very_long_string_parse_cond_targs[_trans];
  745|       |		
  746|  19.1k|		if ( _sav_very_long_string_parse_cond_actions[_trans] != 0 ) {
  ------------------
  |  Branch (746:8): [True: 15.1k, False: 4.02k]
  ------------------
  747|       |			
  748|  15.1k|			_acts = ( _sav_very_long_string_parse_actions + (_sav_very_long_string_parse_cond_actions[_trans]));
  749|  15.1k|			_nacts = (unsigned int)(*( _acts));
  750|  15.1k|			_acts += 1;
  751|  35.2k|			while ( _nacts > 0 ) {
  ------------------
  |  Branch (751:12): [True: 20.3k, False: 14.8k]
  ------------------
  752|  20.3k|				switch ( (*( _acts)) )
  ------------------
  |  Branch (752:14): [True: 0, False: 20.3k]
  ------------------
  753|  20.3k|				{
  754|  2.63k|					case 0:  {
  ------------------
  |  Branch (754:6): [True: 2.63k, False: 17.7k]
  ------------------
  755|  2.63k|						{
  756|  2.63k|#line 13 "src/spss/readstat_sav_parse.rl"
  757|       |							
  758|  2.63k|							memcpy(temp_key, str_start, str_len);
  759|  2.63k|							temp_key[str_len] = '\0';
  760|  2.63k|						}
  761|       |						
  762|  2.63k|#line 763 "src/spss/readstat_sav_parse.c"
  763|       |						
  764|  2.63k|						break; 
  765|      0|					}
  766|  2.72k|					case 1:  {
  ------------------
  |  Branch (766:6): [True: 2.72k, False: 17.6k]
  ------------------
  767|  2.72k|						{
  768|  2.72k|#line 20 "src/spss/readstat_sav_parse.rl"
  769|  2.72k|							str_start = p; }
  770|       |						
  771|  2.72k|#line 772 "src/spss/readstat_sav_parse.c"
  772|       |						
  773|  2.72k|						break; 
  774|      0|					}
  775|  2.63k|					case 2:  {
  ------------------
  |  Branch (775:6): [True: 2.63k, False: 17.7k]
  ------------------
  776|  2.63k|						{
  777|  2.63k|#line 20 "src/spss/readstat_sav_parse.rl"
  778|  2.63k|							str_len = p - str_start; }
  779|       |						
  780|  2.63k|#line 781 "src/spss/readstat_sav_parse.c"
  781|       |						
  782|  2.63k|						break; 
  783|      0|					}
  784|  2.39k|					case 3:  {
  ------------------
  |  Branch (784:6): [True: 2.39k, False: 17.9k]
  ------------------
  785|  2.39k|						{
  786|  2.39k|#line 178 "src/spss/readstat_sav_parse.rl"
  787|       |							
  788|  2.39k|							varlookup_t *found = bsearch(temp_key, table, var_count, sizeof(varlookup_t), &compare_key_varlookup);
  789|  2.39k|							if (found) {
  ------------------
  |  Branch (789:12): [True: 786, False: 1.60k]
  ------------------
  790|    786|								ctx->varinfo[found->index]->string_length = temp_val;
  791|    786|								ctx->varinfo[found->index]->write_format.width = temp_val;
  792|    786|								ctx->varinfo[found->index]->print_format.width = temp_val;
  793|    786|							}
  794|  2.39k|						}
  795|       |						
  796|  2.39k|#line 797 "src/spss/readstat_sav_parse.c"
  797|       |						
  798|  2.39k|						break; 
  799|      0|					}
  800|  7.35k|					case 4:  {
  ------------------
  |  Branch (800:6): [True: 7.35k, False: 13.0k]
  ------------------
  801|  7.35k|						{
  802|  7.35k|#line 187 "src/spss/readstat_sav_parse.rl"
  803|       |							
  804|  7.35k|							if ((( (*( p)))) != '\0') {
  ------------------
  |  Branch (804:12): [True: 7.35k, False: 0]
  ------------------
  805|  7.35k|								unsigned char digit = (( (*( p)))) - '0';
  806|  7.35k|								if (temp_val <= (UINT_MAX - digit) / 10) {
  ------------------
  |  Branch (806:13): [True: 7.13k, False: 226]
  ------------------
  807|  7.13k|									temp_val = 10 * temp_val + digit;
  808|  7.13k|								} else {
  809|    226|									{p += 1; goto _out; }
  810|    226|								}
  811|  7.35k|							}
  812|  7.35k|						}
  813|       |						
  814|  7.13k|#line 815 "src/spss/readstat_sav_parse.c"
  815|       |						
  816|  7.13k|						break; 
  817|  7.35k|					}
  818|  7.13k|					case 5:  {
  ------------------
  |  Branch (818:6): [True: 2.62k, False: 17.7k]
  ------------------
  819|  2.62k|						{
  820|  2.62k|#line 198 "src/spss/readstat_sav_parse.rl"
  821|  2.62k|							temp_val = 0; }
  822|       |						
  823|  2.62k|#line 824 "src/spss/readstat_sav_parse.c"
  824|       |						
  825|  2.62k|						break; 
  826|  7.35k|					}
  827|  20.3k|				}
  828|  20.1k|				_nacts -= 1;
  829|  20.1k|				_acts += 1;
  830|  20.1k|			}
  831|       |			
  832|  15.1k|		}
  833|       |		
  834|  18.9k|		if ( p == eof ) {
  ------------------
  |  Branch (834:8): [True: 1.70k, False: 17.2k]
  ------------------
  835|  1.70k|			if ( cs >= 11 )
  ------------------
  |  Branch (835:9): [True: 1.61k, False: 91]
  ------------------
  836|  1.61k|				goto _out;
  837|  1.70k|		}
  838|  17.2k|		else {
  839|  17.2k|			if ( cs != 0 ) {
  ------------------
  |  Branch (839:9): [True: 17.1k, False: 86]
  ------------------
  840|  17.1k|				p += 1;
  841|  17.1k|				goto _resume;
  842|  17.1k|			}
  843|  17.2k|		}
  844|  2.01k|		_out: {}
  845|  2.01k|	}
  846|       |	
  847|      0|#line 206 "src/spss/readstat_sav_parse.rl"
  848|       |	
  849|       |	
  850|  2.01k|	if (cs < 
  ------------------
  |  Branch (850:6): [True: 177, False: 1.83k]
  ------------------
  851|  2.01k|#line 852 "src/spss/readstat_sav_parse.c"
  852|  2.01k|	11
  853|  2.01k|#line 208 "src/spss/readstat_sav_parse.rl"
  854|  2.01k|	|| p != pe) {
  ------------------
  |  Branch (854:5): [True: 1, False: 1.83k]
  ------------------
  855|    178|		if (ctx->handle.error) {
  ------------------
  |  Branch (855:7): [True: 0, False: 178]
  ------------------
  856|      0|			snprintf(error_buf, error_buf_len, "Parsed %ld of %ld bytes. Remaining bytes: %.*s",
  857|      0|			(long)(p - c_data), (long)(pe - c_data), (int)(pe - p), p);
  858|      0|			ctx->handle.error(error_buf, ctx->user_ctx);
  859|      0|		}
  860|    178|		retval = READSTAT_ERROR_PARSE;
  861|    178|	}
  862|       |	
  863|  2.01k|	if (table)
  ------------------
  |  Branch (863:6): [True: 1.31k, False: 703]
  ------------------
  864|  1.31k|		free(table);
  865|  2.01k|	if (error_buf)
  ------------------
  |  Branch (865:6): [True: 2.01k, False: 0]
  ------------------
  866|  2.01k|		free(error_buf);
  867|       |	
  868|       |	/* suppress warning */
  869|  2.01k|	(void)sav_very_long_string_parse_en_main;
  870|       |	
  871|  2.01k|	return retval;
  872|  18.9k|}
readstat_sav_parse.c:count_vars:
   32|  3.23k|static int count_vars(sav_ctx_t *ctx) {
   33|  3.23k|	int i;
   34|  3.23k|	spss_varinfo_t *last_info = NULL;
   35|  3.23k|	int var_count = 0;
   36|   754k|	for (i=0; i<ctx->var_index; i++) {
  ------------------
  |  Branch (36:12): [True: 751k, False: 3.23k]
  ------------------
   37|   751k|		spss_varinfo_t *info = ctx->varinfo[i];
   38|   751k|		if (last_info == NULL || strcmp(info->name, last_info->name) != 0) {
  ------------------
  |  Branch (38:7): [True: 1.89k, False: 749k]
  |  Branch (38:28): [True: 716k, False: 32.3k]
  ------------------
   39|   718k|			var_count++;
   40|   718k|		}
   41|   751k|		last_info = info;
   42|   751k|	}
   43|  3.23k|	return var_count;
   44|  3.23k|}
readstat_sav_parse.c:build_lookup_table:
   46|  3.23k|static varlookup_t *build_lookup_table(int var_count, sav_ctx_t *ctx) {
   47|  3.23k|	varlookup_t *table = readstat_malloc(var_count * sizeof(varlookup_t));
   48|  3.23k|	int offset = 0;
   49|  3.23k|	int i;
   50|  3.23k|	spss_varinfo_t *last_info = NULL;
   51|   754k|	for (i=0; i<ctx->var_index; i++) {
  ------------------
  |  Branch (51:12): [True: 751k, False: 3.23k]
  ------------------
   52|   751k|		spss_varinfo_t *info = ctx->varinfo[i];
   53|       |		
   54|   751k|		if (last_info == NULL || strcmp(info->name, last_info->name) != 0) {
  ------------------
  |  Branch (54:7): [True: 1.89k, False: 749k]
  |  Branch (54:28): [True: 716k, False: 32.3k]
  ------------------
   55|   718k|			varlookup_t *entry = &table[offset++];
   56|       |			
   57|   718k|			memcpy(entry->name, info->name, sizeof(info->name));
   58|   718k|			entry->index = info->index;
   59|   718k|		}
   60|   751k|		last_info = info;
   61|   751k|	}
   62|  3.23k|	qsort(table, var_count, sizeof(varlookup_t), &compare_varlookups);
   63|  3.23k|	return table;
   64|  3.23k|}
readstat_sav_parse.c:compare_varlookups:
   26|  7.45M|static int compare_varlookups(const void *elem1, const void *elem2) {
   27|  7.45M|	const varlookup_t *v1 = (const varlookup_t *)elem1;
   28|  7.45M|	const varlookup_t *v2 = (const varlookup_t *)elem2;
   29|  7.45M|	return strcasecmp(v1->name, v2->name);
   30|  7.45M|}
readstat_sav_parse.c:compare_key_varlookup:
   20|  5.70k|static int compare_key_varlookup(const void *elem1, const void *elem2) {
   21|  5.70k|	const char *key = (const char *)elem1;
   22|  5.70k|	const varlookup_t *v = (const varlookup_t *)elem2;
   23|  5.70k|	return strcasecmp(key, v->name);
   24|  5.70k|}

sav_parse_time:
   73|  5.07k|readstat_error_handler error_cb, void *user_ctx) {
   74|  5.07k|	readstat_error_t retval = READSTAT_OK;
   75|  5.07k|	char error_buf[8192];
   76|  5.07k|	const char *p = data;
   77|  5.07k|	const char *pe = p + len;
   78|  5.07k|	const char *eof = pe;
   79|  5.07k|	int cs;
   80|  5.07k|	int temp_val = 0;
   81|       |	
   82|  5.07k|#line 83 "src/spss/readstat_sav_parse_timestamp.c"
   83|  5.07k|	{
   84|  5.07k|		cs = (int)sav_time_parse_start;
   85|  5.07k|	}
   86|       |	
   87|  5.07k|#line 88 "src/spss/readstat_sav_parse_timestamp.c"
   88|  5.07k|	{
   89|  5.07k|		int _klen;
   90|  5.07k|		unsigned int _trans = 0;
   91|  5.07k|		const char * _keys;
   92|  5.07k|		const signed char * _acts;
   93|  5.07k|		unsigned int _nacts;
   94|  14.9k|		_resume: {}
   95|  14.9k|		if ( p == pe && p != eof )
  ------------------
  |  Branch (95:8): [True: 1.00k, False: 13.9k]
  |  Branch (95:19): [True: 0, False: 1.00k]
  ------------------
   96|      0|			goto _out;
   97|  14.9k|		if ( p == eof ) {
  ------------------
  |  Branch (97:8): [True: 1.00k, False: 13.9k]
  ------------------
   98|  1.00k|			if ( _sav_time_parse_eof_trans[cs] > 0 ) {
  ------------------
  |  Branch (98:9): [True: 1.00k, False: 0]
  ------------------
   99|  1.00k|				_trans = (unsigned int)_sav_time_parse_eof_trans[cs] - 1;
  100|  1.00k|			}
  101|  1.00k|		}
  102|  13.9k|		else {
  103|  13.9k|			_keys = ( _sav_time_parse_trans_keys + (_sav_time_parse_key_offsets[cs]));
  104|  13.9k|			_trans = (unsigned int)_sav_time_parse_index_offsets[cs];
  105|       |			
  106|  13.9k|			_klen = (int)_sav_time_parse_single_lengths[cs];
  107|  13.9k|			if ( _klen > 0 ) {
  ------------------
  |  Branch (107:9): [True: 9.99k, False: 3.94k]
  ------------------
  108|  9.99k|				const char *_lower = _keys;
  109|  9.99k|				const char *_upper = _keys + _klen - 1;
  110|  9.99k|				const char *_mid;
  111|  17.3k|				while ( 1 ) {
  ------------------
  |  Branch (111:13): [Folded - Ignored]
  ------------------
  112|  17.3k|					if ( _upper < _lower ) {
  ------------------
  |  Branch (112:11): [True: 7.38k, False: 9.99k]
  ------------------
  113|  7.38k|						_keys += _klen;
  114|  7.38k|						_trans += (unsigned int)_klen;
  115|  7.38k|						break;
  116|  7.38k|					}
  117|       |					
  118|  9.99k|					_mid = _lower + ((_upper-_lower) >> 1);
  119|  9.99k|					if ( ( (*( p))) < (*( _mid)) )
  ------------------
  |  Branch (119:11): [True: 2.80k, False: 7.18k]
  ------------------
  120|  2.80k|						_upper = _mid - 1;
  121|  7.18k|					else if ( ( (*( p))) > (*( _mid)) )
  ------------------
  |  Branch (121:16): [True: 4.58k, False: 2.60k]
  ------------------
  122|  4.58k|						_lower = _mid + 1;
  123|  2.60k|					else {
  124|  2.60k|						_trans += (unsigned int)(_mid - _keys);
  125|  2.60k|						goto _match;
  126|  2.60k|					}
  127|  9.99k|				}
  128|  9.99k|			}
  129|       |			
  130|  11.3k|			_klen = (int)_sav_time_parse_range_lengths[cs];
  131|  11.3k|			if ( _klen > 0 ) {
  ------------------
  |  Branch (131:9): [True: 11.1k, False: 195]
  ------------------
  132|  11.1k|				const char *_lower = _keys;
  133|  11.1k|				const char *_upper = _keys + (_klen<<1) - 2;
  134|  11.1k|				const char *_mid;
  135|  15.0k|				while ( 1 ) {
  ------------------
  |  Branch (135:13): [Folded - Ignored]
  ------------------
  136|  15.0k|					if ( _upper < _lower ) {
  ------------------
  |  Branch (136:11): [True: 3.87k, False: 11.1k]
  ------------------
  137|  3.87k|						_trans += (unsigned int)_klen;
  138|  3.87k|						break;
  139|  3.87k|					}
  140|       |					
  141|  11.1k|					_mid = _lower + (((_upper-_lower) >> 1) & ~1);
  142|  11.1k|					if ( ( (*( p))) < (*( _mid)) )
  ------------------
  |  Branch (142:11): [True: 3.12k, False: 8.00k]
  ------------------
  143|  3.12k|						_upper = _mid - 2;
  144|  8.00k|					else if ( ( (*( p))) > (*( _mid + 1)) )
  ------------------
  |  Branch (144:16): [True: 748, False: 7.25k]
  ------------------
  145|    748|						_lower = _mid + 2;
  146|  7.25k|					else {
  147|  7.25k|						_trans += (unsigned int)((_mid - _keys)>>1);
  148|  7.25k|						break;
  149|  7.25k|					}
  150|  11.1k|				}
  151|  11.1k|			}
  152|       |			
  153|  13.9k|			_match: {}
  154|  13.9k|		}
  155|  14.9k|		cs = (int)_sav_time_parse_cond_targs[_trans];
  156|       |		
  157|  14.9k|		if ( _sav_time_parse_cond_actions[_trans] != 0 ) {
  ------------------
  |  Branch (157:8): [True: 10.6k, False: 4.31k]
  ------------------
  158|       |			
  159|  10.6k|			_acts = ( _sav_time_parse_actions + (_sav_time_parse_cond_actions[_trans]));
  160|  10.6k|			_nacts = (unsigned int)(*( _acts));
  161|  10.6k|			_acts += 1;
  162|  21.3k|			while ( _nacts > 0 ) {
  ------------------
  |  Branch (162:12): [True: 10.6k, False: 10.6k]
  ------------------
  163|  10.6k|				switch ( (*( _acts)) )
  ------------------
  |  Branch (163:14): [True: 0, False: 10.6k]
  ------------------
  164|  10.6k|				{
  165|  3.56k|					case 0:  {
  ------------------
  |  Branch (165:6): [True: 3.56k, False: 7.13k]
  ------------------
  166|  3.56k|						{
  167|  3.56k|#line 24 "src/spss/readstat_sav_parse_timestamp.rl"
  168|       |							
  169|  3.56k|							temp_val = 10 * temp_val + ((( (*( p)))) - '0');
  170|  3.56k|						}
  171|       |						
  172|  3.56k|#line 173 "src/spss/readstat_sav_parse_timestamp.c"
  173|       |						
  174|  3.56k|						break; 
  175|      0|					}
  176|     75|					case 1:  {
  ------------------
  |  Branch (176:6): [True: 75, False: 10.6k]
  ------------------
  177|     75|						{
  178|     75|#line 28 "src/spss/readstat_sav_parse_timestamp.rl"
  179|     75|							temp_val = 0; }
  180|       |						
  181|     75|#line 182 "src/spss/readstat_sav_parse_timestamp.c"
  182|       |						
  183|     75|						break; 
  184|      0|					}
  185|  3.69k|					case 2:  {
  ------------------
  |  Branch (185:6): [True: 3.69k, False: 7.00k]
  ------------------
  186|  3.69k|						{
  187|  3.69k|#line 28 "src/spss/readstat_sav_parse_timestamp.rl"
  188|  3.69k|							temp_val = (( (*( p)))) - '0'; }
  189|       |						
  190|  3.69k|#line 191 "src/spss/readstat_sav_parse_timestamp.c"
  191|       |						
  192|  3.69k|						break; 
  193|      0|					}
  194|  1.26k|					case 3:  {
  ------------------
  |  Branch (194:6): [True: 1.26k, False: 9.43k]
  ------------------
  195|  1.26k|						{
  196|  1.26k|#line 30 "src/spss/readstat_sav_parse_timestamp.rl"
  197|  1.26k|							timestamp->tm_hour = temp_val; }
  198|       |						
  199|  1.26k|#line 200 "src/spss/readstat_sav_parse_timestamp.c"
  200|       |						
  201|  1.26k|						break; 
  202|      0|					}
  203|  1.09k|					case 4:  {
  ------------------
  |  Branch (203:6): [True: 1.09k, False: 9.60k]
  ------------------
  204|  1.09k|						{
  205|  1.09k|#line 32 "src/spss/readstat_sav_parse_timestamp.rl"
  206|  1.09k|							timestamp->tm_min = temp_val; }
  207|       |						
  208|  1.09k|#line 209 "src/spss/readstat_sav_parse_timestamp.c"
  209|       |						
  210|  1.09k|						break; 
  211|      0|					}
  212|  1.00k|					case 5:  {
  ------------------
  |  Branch (212:6): [True: 1.00k, False: 9.69k]
  ------------------
  213|  1.00k|						{
  214|  1.00k|#line 34 "src/spss/readstat_sav_parse_timestamp.rl"
  215|  1.00k|							timestamp->tm_sec = temp_val; }
  216|       |						
  217|  1.00k|#line 218 "src/spss/readstat_sav_parse_timestamp.c"
  218|       |						
  219|  1.00k|						break; 
  220|      0|					}
  221|  10.6k|				}
  222|  10.6k|				_nacts -= 1;
  223|  10.6k|				_acts += 1;
  224|  10.6k|			}
  225|       |			
  226|  10.6k|		}
  227|       |		
  228|  14.9k|		if ( p == eof ) {
  ------------------
  |  Branch (228:8): [True: 1.00k, False: 13.9k]
  ------------------
  229|  1.00k|			if ( cs >= 12 )
  ------------------
  |  Branch (229:9): [True: 1.00k, False: 0]
  ------------------
  230|  1.00k|				goto _out;
  231|  1.00k|		}
  232|  13.9k|		else {
  233|  13.9k|			if ( cs != 0 ) {
  ------------------
  |  Branch (233:9): [True: 9.86k, False: 4.07k]
  ------------------
  234|  9.86k|				p += 1;
  235|  9.86k|				goto _resume;
  236|  9.86k|			}
  237|  13.9k|		}
  238|  5.07k|		_out: {}
  239|  5.07k|	}
  240|       |	
  241|      0|#line 40 "src/spss/readstat_sav_parse_timestamp.rl"
  242|       |	
  243|       |	
  244|  5.07k|	if (cs < 
  ------------------
  |  Branch (244:6): [True: 4.07k, False: 1.00k]
  ------------------
  245|  5.07k|#line 246 "src/spss/readstat_sav_parse_timestamp.c"
  246|  5.07k|	12
  247|  5.07k|#line 42 "src/spss/readstat_sav_parse_timestamp.rl"
  248|  5.07k|	|| p != pe) {
  ------------------
  |  Branch (248:5): [True: 0, False: 1.00k]
  ------------------
  249|  4.07k|		if (error_cb) {
  ------------------
  |  Branch (249:7): [True: 0, False: 4.07k]
  ------------------
  250|      0|			snprintf(error_buf, sizeof(error_buf),
  251|      0|			"Invalid time string (length=%d): %.*s", (int)len, (int)len, data);
  252|      0|			error_cb(error_buf, user_ctx);
  253|      0|		}
  254|  4.07k|		retval = READSTAT_ERROR_BAD_TIMESTAMP_STRING;
  255|  4.07k|	}
  256|       |	
  257|  5.07k|	(void)sav_time_parse_en_main;
  258|       |	
  259|  5.07k|	return retval;
  260|  14.9k|}
sav_parse_date:
  398|  1.00k|readstat_error_handler error_cb, void *user_ctx) {
  399|  1.00k|	readstat_error_t retval = READSTAT_OK;
  400|  1.00k|	char error_buf[8192];
  401|  1.00k|	const char *p = data;
  402|  1.00k|	const char *pe = p + len;
  403|  1.00k|	const char *eof = pe;
  404|  1.00k|	int cs;
  405|  1.00k|	int temp_val = 0;
  406|       |	
  407|  1.00k|#line 408 "src/spss/readstat_sav_parse_timestamp.c"
  408|  1.00k|	{
  409|  1.00k|		cs = (int)sav_date_parse_start;
  410|  1.00k|	}
  411|       |	
  412|  1.00k|#line 413 "src/spss/readstat_sav_parse_timestamp.c"
  413|  1.00k|	{
  414|  1.00k|		int _klen;
  415|  1.00k|		unsigned int _trans = 0;
  416|  1.00k|		const char * _keys;
  417|  1.00k|		const signed char * _acts;
  418|  1.00k|		unsigned int _nacts;
  419|  8.14k|		_resume: {}
  420|  8.14k|		if ( p == pe && p != eof )
  ------------------
  |  Branch (420:8): [True: 726, False: 7.42k]
  |  Branch (420:19): [True: 0, False: 726]
  ------------------
  421|      0|			goto _out;
  422|  8.14k|		if ( p == eof ) {
  ------------------
  |  Branch (422:8): [True: 726, False: 7.42k]
  ------------------
  423|    726|			if ( _sav_date_parse_eof_trans[cs] > 0 ) {
  ------------------
  |  Branch (423:9): [True: 726, False: 0]
  ------------------
  424|    726|				_trans = (unsigned int)_sav_date_parse_eof_trans[cs] - 1;
  425|    726|			}
  426|    726|		}
  427|  7.42k|		else {
  428|  7.42k|			_keys = ( _sav_date_parse_trans_keys + (_sav_date_parse_key_offsets[cs]));
  429|  7.42k|			_trans = (unsigned int)_sav_date_parse_index_offsets[cs];
  430|       |			
  431|  7.42k|			_klen = (int)_sav_date_parse_single_lengths[cs];
  432|  7.42k|			if ( _klen > 0 ) {
  ------------------
  |  Branch (432:9): [True: 7.42k, False: 0]
  ------------------
  433|  7.42k|				const char *_lower = _keys;
  434|  7.42k|				const char *_upper = _keys + _klen - 1;
  435|  7.42k|				const char *_mid;
  436|  12.5k|				while ( 1 ) {
  ------------------
  |  Branch (436:13): [Folded - Ignored]
  ------------------
  437|  12.5k|					if ( _upper < _lower ) {
  ------------------
  |  Branch (437:11): [True: 3.42k, False: 9.07k]
  ------------------
  438|  3.42k|						_keys += _klen;
  439|  3.42k|						_trans += (unsigned int)_klen;
  440|  3.42k|						break;
  441|  3.42k|					}
  442|       |					
  443|  9.07k|					_mid = _lower + ((_upper-_lower) >> 1);
  444|  9.07k|					if ( ( (*( p))) < (*( _mid)) )
  ------------------
  |  Branch (444:11): [True: 457, False: 8.62k]
  ------------------
  445|    457|						_upper = _mid - 1;
  446|  8.62k|					else if ( ( (*( p))) > (*( _mid)) )
  ------------------
  |  Branch (446:16): [True: 4.62k, False: 4.00k]
  ------------------
  447|  4.62k|						_lower = _mid + 1;
  448|  4.00k|					else {
  449|  4.00k|						_trans += (unsigned int)(_mid - _keys);
  450|  4.00k|						goto _match;
  451|  4.00k|					}
  452|  9.07k|				}
  453|  7.42k|			}
  454|       |			
  455|  3.42k|			_klen = (int)_sav_date_parse_range_lengths[cs];
  456|  3.42k|			if ( _klen > 0 ) {
  ------------------
  |  Branch (456:9): [True: 3.30k, False: 116]
  ------------------
  457|  3.30k|				const char *_lower = _keys;
  458|  3.30k|				const char *_upper = _keys + (_klen<<1) - 2;
  459|  3.30k|				const char *_mid;
  460|  3.47k|				while ( 1 ) {
  ------------------
  |  Branch (460:13): [Folded - Ignored]
  ------------------
  461|  3.47k|					if ( _upper < _lower ) {
  ------------------
  |  Branch (461:11): [True: 167, False: 3.30k]
  ------------------
  462|    167|						_trans += (unsigned int)_klen;
  463|    167|						break;
  464|    167|					}
  465|       |					
  466|  3.30k|					_mid = _lower + (((_upper-_lower) >> 1) & ~1);
  467|  3.30k|					if ( ( (*( p))) < (*( _mid)) )
  ------------------
  |  Branch (467:11): [True: 98, False: 3.20k]
  ------------------
  468|     98|						_upper = _mid - 2;
  469|  3.20k|					else if ( ( (*( p))) > (*( _mid + 1)) )
  ------------------
  |  Branch (469:16): [True: 69, False: 3.13k]
  ------------------
  470|     69|						_lower = _mid + 2;
  471|  3.13k|					else {
  472|  3.13k|						_trans += (unsigned int)((_mid - _keys)>>1);
  473|  3.13k|						break;
  474|  3.13k|					}
  475|  3.30k|				}
  476|  3.30k|			}
  477|       |			
  478|  7.42k|			_match: {}
  479|  7.42k|		}
  480|  8.14k|		cs = (int)_sav_date_parse_cond_targs[_trans];
  481|       |		
  482|  8.14k|		if ( _sav_date_parse_cond_actions[_trans] != 0 ) {
  ------------------
  |  Branch (482:8): [True: 5.50k, False: 2.64k]
  ------------------
  483|       |			
  484|  5.50k|			_acts = ( _sav_date_parse_actions + (_sav_date_parse_cond_actions[_trans]));
  485|  5.50k|			_nacts = (unsigned int)(*( _acts));
  486|  5.50k|			_acts += 1;
  487|  12.6k|			while ( _nacts > 0 ) {
  ------------------
  |  Branch (487:12): [True: 7.12k, False: 5.50k]
  ------------------
  488|  7.12k|				switch ( (*( _acts)) )
  ------------------
  |  Branch (488:14): [True: 0, False: 7.12k]
  ------------------
  489|  7.12k|				{
  490|  3.20k|					case 0:  {
  ------------------
  |  Branch (490:6): [True: 3.20k, False: 3.92k]
  ------------------
  491|  3.20k|						{
  492|  3.20k|#line 71 "src/spss/readstat_sav_parse_timestamp.rl"
  493|       |							
  494|  3.20k|							char digit = ((( (*( p)))) - '0');
  495|  3.20k|							if (digit >= 0 && digit <= 9) {
  ------------------
  |  Branch (495:12): [True: 3.13k, False: 66]
  |  Branch (495:26): [True: 3.13k, False: 0]
  ------------------
  496|  3.13k|								temp_val = 10 * temp_val + digit;
  497|  3.13k|							}
  498|  3.20k|						}
  499|       |						
  500|  3.20k|#line 501 "src/spss/readstat_sav_parse_timestamp.c"
  501|       |						
  502|  3.20k|						break; 
  503|      0|					}
  504|    726|					case 1:  {
  ------------------
  |  Branch (504:6): [True: 726, False: 6.39k]
  ------------------
  505|    726|						{
  506|    726|#line 78 "src/spss/readstat_sav_parse_timestamp.rl"
  507|       |							
  508|    726|							if (temp_val < 70) {
  ------------------
  |  Branch (508:12): [True: 601, False: 125]
  ------------------
  509|    601|								timestamp->tm_year = 100 + temp_val;
  510|    601|							} else {
  511|    125|								timestamp->tm_year = temp_val;
  512|    125|							}
  513|    726|						}
  514|       |						
  515|    726|#line 516 "src/spss/readstat_sav_parse_timestamp.c"
  516|       |						
  517|    726|						break; 
  518|      0|					}
  519|  1.62k|					case 2:  {
  ------------------
  |  Branch (519:6): [True: 1.62k, False: 5.50k]
  ------------------
  520|  1.62k|						{
  521|  1.62k|#line 87 "src/spss/readstat_sav_parse_timestamp.rl"
  522|  1.62k|							temp_val = 0; }
  523|       |						
  524|  1.62k|#line 525 "src/spss/readstat_sav_parse_timestamp.c"
  525|       |						
  526|  1.62k|						break; 
  527|      0|					}
  528|    831|					case 3:  {
  ------------------
  |  Branch (528:6): [True: 831, False: 6.29k]
  ------------------
  529|    831|						{
  530|    831|#line 89 "src/spss/readstat_sav_parse_timestamp.rl"
  531|    831|							timestamp->tm_mday = temp_val; }
  532|       |						
  533|    831|#line 534 "src/spss/readstat_sav_parse_timestamp.c"
  534|       |						
  535|    831|						break; 
  536|      0|					}
  537|    354|					case 4:  {
  ------------------
  |  Branch (537:6): [True: 354, False: 6.77k]
  ------------------
  538|    354|						{
  539|    354|#line 94 "src/spss/readstat_sav_parse_timestamp.rl"
  540|    354|							timestamp->tm_mon = 0; }
  541|       |						
  542|    354|#line 543 "src/spss/readstat_sav_parse_timestamp.c"
  543|       |						
  544|    354|						break; 
  545|      0|					}
  546|      1|					case 5:  {
  ------------------
  |  Branch (546:6): [True: 1, False: 7.12k]
  ------------------
  547|      1|						{
  548|      1|#line 95 "src/spss/readstat_sav_parse_timestamp.rl"
  549|      1|							timestamp->tm_mon = 1; }
  550|       |						
  551|      1|#line 552 "src/spss/readstat_sav_parse_timestamp.c"
  552|       |						
  553|      1|						break; 
  554|      0|					}
  555|     59|					case 6:  {
  ------------------
  |  Branch (555:6): [True: 59, False: 7.06k]
  ------------------
  556|     59|						{
  557|     59|#line 96 "src/spss/readstat_sav_parse_timestamp.rl"
  558|     59|							timestamp->tm_mon = 2; }
  559|       |						
  560|     59|#line 561 "src/spss/readstat_sav_parse_timestamp.c"
  561|       |						
  562|     59|						break; 
  563|      0|					}
  564|     16|					case 7:  {
  ------------------
  |  Branch (564:6): [True: 16, False: 7.10k]
  ------------------
  565|     16|						{
  566|     16|#line 97 "src/spss/readstat_sav_parse_timestamp.rl"
  567|     16|							timestamp->tm_mon = 3; }
  568|       |						
  569|     16|#line 570 "src/spss/readstat_sav_parse_timestamp.c"
  570|       |						
  571|     16|						break; 
  572|      0|					}
  573|      1|					case 8:  {
  ------------------
  |  Branch (573:6): [True: 1, False: 7.12k]
  ------------------
  574|      1|						{
  575|      1|#line 98 "src/spss/readstat_sav_parse_timestamp.rl"
  576|      1|							timestamp->tm_mon = 4; }
  577|       |						
  578|      1|#line 579 "src/spss/readstat_sav_parse_timestamp.c"
  579|       |						
  580|      1|						break; 
  581|      0|					}
  582|    179|					case 9:  {
  ------------------
  |  Branch (582:6): [True: 179, False: 6.94k]
  ------------------
  583|    179|						{
  584|    179|#line 99 "src/spss/readstat_sav_parse_timestamp.rl"
  585|    179|							timestamp->tm_mon = 5; }
  586|       |						
  587|    179|#line 588 "src/spss/readstat_sav_parse_timestamp.c"
  588|       |						
  589|    179|						break; 
  590|      0|					}
  591|      7|					case 10:  {
  ------------------
  |  Branch (591:6): [True: 7, False: 7.11k]
  ------------------
  592|      7|						{
  593|      7|#line 100 "src/spss/readstat_sav_parse_timestamp.rl"
  594|      7|							timestamp->tm_mon = 6; }
  595|       |						
  596|      7|#line 597 "src/spss/readstat_sav_parse_timestamp.c"
  597|       |						
  598|      7|						break; 
  599|      0|					}
  600|     15|					case 11:  {
  ------------------
  |  Branch (600:6): [True: 15, False: 7.11k]
  ------------------
  601|     15|						{
  602|     15|#line 101 "src/spss/readstat_sav_parse_timestamp.rl"
  603|     15|							timestamp->tm_mon = 7; }
  604|       |						
  605|     15|#line 606 "src/spss/readstat_sav_parse_timestamp.c"
  606|       |						
  607|     15|						break; 
  608|      0|					}
  609|      6|					case 12:  {
  ------------------
  |  Branch (609:6): [True: 6, False: 7.11k]
  ------------------
  610|      6|						{
  611|      6|#line 102 "src/spss/readstat_sav_parse_timestamp.rl"
  612|      6|							timestamp->tm_mon = 8; }
  613|       |						
  614|      6|#line 615 "src/spss/readstat_sav_parse_timestamp.c"
  615|       |						
  616|      6|						break; 
  617|      0|					}
  618|      2|					case 13:  {
  ------------------
  |  Branch (618:6): [True: 2, False: 7.12k]
  ------------------
  619|      2|						{
  620|      2|#line 103 "src/spss/readstat_sav_parse_timestamp.rl"
  621|      2|							timestamp->tm_mon = 9; }
  622|       |						
  623|      2|#line 624 "src/spss/readstat_sav_parse_timestamp.c"
  624|       |						
  625|      2|						break; 
  626|      0|					}
  627|      4|					case 14:  {
  ------------------
  |  Branch (627:6): [True: 4, False: 7.12k]
  ------------------
  628|      4|						{
  629|      4|#line 104 "src/spss/readstat_sav_parse_timestamp.rl"
  630|      4|							timestamp->tm_mon = 10; }
  631|       |						
  632|      4|#line 633 "src/spss/readstat_sav_parse_timestamp.c"
  633|       |						
  634|      4|						break; 
  635|      0|					}
  636|     99|					case 15:  {
  ------------------
  |  Branch (636:6): [True: 99, False: 7.02k]
  ------------------
  637|     99|						{
  638|     99|#line 105 "src/spss/readstat_sav_parse_timestamp.rl"
  639|     99|							timestamp->tm_mon = 11; }
  640|       |						
  641|     99|#line 642 "src/spss/readstat_sav_parse_timestamp.c"
  642|       |						
  643|     99|						break; 
  644|      0|					}
  645|  7.12k|				}
  646|  7.12k|				_nacts -= 1;
  647|  7.12k|				_acts += 1;
  648|  7.12k|			}
  649|       |			
  650|  5.50k|		}
  651|       |		
  652|  8.14k|		if ( p == eof ) {
  ------------------
  |  Branch (652:8): [True: 726, False: 7.42k]
  ------------------
  653|    726|			if ( cs >= 47 )
  ------------------
  |  Branch (653:9): [True: 726, False: 0]
  ------------------
  654|    726|				goto _out;
  655|    726|		}
  656|  7.42k|		else {
  657|  7.42k|			if ( cs != 0 ) {
  ------------------
  |  Branch (657:9): [True: 7.14k, False: 283]
  ------------------
  658|  7.14k|				p += 1;
  659|  7.14k|				goto _resume;
  660|  7.14k|			}
  661|  7.42k|		}
  662|  1.00k|		_out: {}
  663|  1.00k|	}
  664|       |	
  665|      0|#line 112 "src/spss/readstat_sav_parse_timestamp.rl"
  666|       |	
  667|       |	
  668|  1.00k|	if (cs < 
  ------------------
  |  Branch (668:6): [True: 283, False: 726]
  ------------------
  669|  1.00k|#line 670 "src/spss/readstat_sav_parse_timestamp.c"
  670|  1.00k|	47
  671|  1.00k|#line 114 "src/spss/readstat_sav_parse_timestamp.rl"
  672|  1.00k|	|| p != pe) {
  ------------------
  |  Branch (672:5): [True: 0, False: 726]
  ------------------
  673|    283|		if (error_cb) {
  ------------------
  |  Branch (673:7): [True: 0, False: 283]
  ------------------
  674|      0|			snprintf(error_buf, sizeof(error_buf),
  675|      0|			"Invalid date string (length=%d): %.*s", (int)len, (int)len, data);
  676|      0|			error_cb(error_buf, user_ctx);
  677|      0|		}
  678|    283|		retval = READSTAT_ERROR_BAD_TIMESTAMP_STRING;
  679|    283|	}
  680|       |	
  681|  1.00k|	(void)sav_date_parse_en_main;
  682|       |	
  683|  1.00k|	return retval;
  684|  8.14k|}

sav_parse_timestamp:
 1550|  5.07k|readstat_error_t sav_parse_timestamp(sav_ctx_t *ctx, sav_file_header_record_t *header) {
 1551|  5.07k|    readstat_error_t retval = READSTAT_OK;
 1552|  5.07k|    struct tm timestamp = { .tm_isdst = -1 };
 1553|       |
 1554|  5.07k|    if ((retval = sav_parse_time(header->creation_time, sizeof(header->creation_time),
  ------------------
  |  Branch (1554:9): [True: 4.07k, False: 1.00k]
  ------------------
 1555|  5.07k|                    &timestamp, ctx->handle.error, ctx->user_ctx)) 
 1556|  5.07k|            != READSTAT_OK)
 1557|  4.07k|        goto cleanup;
 1558|       |
 1559|  1.00k|    if ((retval = sav_parse_date(header->creation_date, sizeof(header->creation_date),
  ------------------
  |  Branch (1559:9): [True: 283, False: 726]
  ------------------
 1560|  1.00k|                    &timestamp, ctx->handle.error, ctx->user_ctx)) 
 1561|  1.00k|            != READSTAT_OK)
 1562|    283|        goto cleanup;
 1563|       |
 1564|    726|    ctx->timestamp = mktime(&timestamp);
 1565|       |
 1566|  5.07k|cleanup:
 1567|  5.07k|    return retval;
 1568|    726|}
readstat_parse_sav:
 1570|  5.12k|readstat_error_t readstat_parse_sav(readstat_parser_t *parser, const char *path, void *user_ctx) {
 1571|  5.12k|    readstat_error_t retval = READSTAT_OK;
 1572|  5.12k|    readstat_io_t *io = parser->io;
 1573|  5.12k|    sav_file_header_record_t header;
 1574|  5.12k|    sav_ctx_t *ctx = NULL;
 1575|  5.12k|    size_t file_size = 0;
 1576|       |    
 1577|  5.12k|    if (io->open(path, io->io_ctx) == -1) {
  ------------------
  |  Branch (1577:9): [True: 0, False: 5.12k]
  ------------------
 1578|      0|        return READSTAT_ERROR_OPEN;
 1579|      0|    }
 1580|       |
 1581|  5.12k|    file_size = io->seek(0, READSTAT_SEEK_END, io->io_ctx);
 1582|  5.12k|    if (file_size == -1) {
  ------------------
  |  Branch (1582:9): [True: 0, False: 5.12k]
  ------------------
 1583|      0|        retval = READSTAT_ERROR_SEEK;
 1584|      0|        goto cleanup;
 1585|      0|    }
 1586|       |
 1587|  5.12k|    if (io->seek(0, READSTAT_SEEK_SET, io->io_ctx) == -1) {
  ------------------
  |  Branch (1587:9): [True: 0, False: 5.12k]
  ------------------
 1588|      0|        retval = READSTAT_ERROR_SEEK;
 1589|      0|        goto cleanup;
 1590|      0|    }
 1591|       |
 1592|  5.12k|    if (io->read(&header, sizeof(sav_file_header_record_t), io->io_ctx) < sizeof(sav_file_header_record_t)) {
  ------------------
  |  Branch (1592:9): [True: 18, False: 5.11k]
  ------------------
 1593|     18|        retval = READSTAT_ERROR_READ;
 1594|     18|        goto cleanup;
 1595|     18|    }
 1596|       |
 1597|  5.11k|    ctx = sav_ctx_init(&header, io);
 1598|  5.11k|    if (ctx == NULL) {
  ------------------
  |  Branch (1598:9): [True: 32, False: 5.07k]
  ------------------
 1599|     32|        retval = READSTAT_ERROR_PARSE;
 1600|     32|        goto cleanup;
 1601|     32|    }
 1602|       |
 1603|  5.07k|    ctx->handle = parser->handlers;
 1604|  5.07k|    ctx->input_encoding = parser->input_encoding;
 1605|  5.07k|    ctx->output_encoding = parser->output_encoding;
 1606|  5.07k|    ctx->user_ctx = user_ctx;
 1607|  5.07k|    ctx->file_size = file_size;
 1608|  5.07k|    if (parser->row_offset > 0)
  ------------------
  |  Branch (1608:9): [True: 0, False: 5.07k]
  ------------------
 1609|      0|        ctx->row_offset = parser->row_offset;
 1610|  5.07k|    if (ctx->record_count >= 0) {
  ------------------
  |  Branch (1610:9): [True: 3.64k, False: 1.43k]
  ------------------
 1611|  3.64k|        int record_count_after_skipping = ctx->record_count - ctx->row_offset;
 1612|  3.64k|        if (record_count_after_skipping < 0) {
  ------------------
  |  Branch (1612:13): [True: 0, False: 3.64k]
  ------------------
 1613|      0|            record_count_after_skipping = 0;
 1614|      0|            ctx->row_offset = ctx->record_count;
 1615|      0|        }
 1616|  3.64k|        ctx->row_limit = record_count_after_skipping;
 1617|  3.64k|        if (parser->row_limit > 0 && parser->row_limit < record_count_after_skipping) 
  ------------------
  |  Branch (1617:13): [True: 0, False: 3.64k]
  |  Branch (1617:38): [True: 0, False: 0]
  ------------------
 1618|      0|            ctx->row_limit = parser->row_limit;
 1619|  3.64k|    } else if (parser->row_limit > 0) {
  ------------------
  |  Branch (1619:16): [True: 0, False: 1.43k]
  ------------------
 1620|      0|        ctx->row_limit = parser->row_limit;
 1621|      0|    }
 1622|       |    
 1623|       |    /* ignore errors */
 1624|  5.07k|    sav_parse_timestamp(ctx, &header);
 1625|       |
 1626|  5.07k|    if ((retval = sav_parse_records_pass1(ctx)) != READSTAT_OK)
  ------------------
  |  Branch (1626:9): [True: 961, False: 4.11k]
  ------------------
 1627|    961|        goto cleanup;
 1628|       |    
 1629|  4.11k|    if (io->seek(sizeof(sav_file_header_record_t), READSTAT_SEEK_SET, io->io_ctx) == -1) {
  ------------------
  |  Branch (1629:9): [True: 0, False: 4.11k]
  ------------------
 1630|      0|        retval = READSTAT_ERROR_SEEK;
 1631|      0|        goto cleanup;
 1632|      0|    }
 1633|       |
 1634|  4.11k|    if ((retval = sav_update_progress(ctx)) != READSTAT_OK)
  ------------------
  |  Branch (1634:9): [True: 0, False: 4.11k]
  ------------------
 1635|      0|        goto cleanup;
 1636|       |
 1637|  4.11k|    if ((retval = sav_parse_records_pass2(ctx)) != READSTAT_OK)
  ------------------
  |  Branch (1637:9): [True: 2.60k, False: 1.51k]
  ------------------
 1638|  2.60k|        goto cleanup;
 1639|       | 
 1640|  1.51k|    if ((retval = sav_set_n_segments_and_var_count(ctx)) != READSTAT_OK)
  ------------------
  |  Branch (1640:9): [True: 32, False: 1.47k]
  ------------------
 1641|     32|        goto cleanup;
 1642|       |
 1643|  1.47k|    if (ctx->var_count == 0) {
  ------------------
  |  Branch (1643:9): [True: 7, False: 1.47k]
  ------------------
 1644|      7|        retval = READSTAT_ERROR_PARSE;
 1645|      7|        goto cleanup;
 1646|      7|    }
 1647|       |
 1648|  1.47k|    if (ctx->handle.metadata) {
  ------------------
  |  Branch (1648:9): [True: 1.47k, False: 0]
  ------------------
 1649|  1.47k|        readstat_metadata_t metadata = {
 1650|  1.47k|            .row_count = ctx->record_count < 0 ? -1 : ctx->row_limit,
  ------------------
  |  Branch (1650:26): [True: 465, False: 1.00k]
  ------------------
 1651|  1.47k|            .var_count = ctx->var_count,
 1652|  1.47k|            .file_encoding = ctx->input_encoding,
 1653|  1.47k|            .file_format_version = ctx->format_version,
 1654|  1.47k|            .creation_time = ctx->timestamp,
 1655|  1.47k|            .modified_time = ctx->timestamp,
 1656|  1.47k|            .compression = ctx->compression,
 1657|  1.47k|            .endianness = ctx->endianness
 1658|  1.47k|        };
 1659|  1.47k|        if ((retval = readstat_convert(ctx->file_label, sizeof(ctx->file_label),
  ------------------
  |  Branch (1659:13): [True: 1, False: 1.47k]
  ------------------
 1660|  1.47k|                        header.file_label, sizeof(header.file_label), ctx->converter)) != READSTAT_OK)
 1661|      1|            goto cleanup;
 1662|       |
 1663|  1.47k|        metadata.file_label = ctx->file_label;
 1664|       |
 1665|  1.47k|        if (ctx->handle.metadata(&metadata, ctx->user_ctx) != READSTAT_HANDLER_OK) {
  ------------------
  |  Branch (1665:13): [True: 0, False: 1.47k]
  ------------------
 1666|      0|            retval = READSTAT_ERROR_USER_ABORT;
 1667|      0|            goto cleanup;
 1668|      0|        }
 1669|  1.47k|    }
 1670|       |
 1671|  1.47k|    if ((retval = sav_parse_variable_display_parameter_record(ctx)) != READSTAT_OK)
  ------------------
  |  Branch (1671:9): [True: 36, False: 1.43k]
  ------------------
 1672|     36|        goto cleanup;
 1673|       |
 1674|  1.43k|    if ((retval = sav_handle_variables(ctx)) != READSTAT_OK)
  ------------------
  |  Branch (1674:9): [True: 0, False: 1.43k]
  ------------------
 1675|      0|        goto cleanup;
 1676|       |
 1677|  1.43k|    if ((retval = sav_handle_fweight(ctx)) != READSTAT_OK)
  ------------------
  |  Branch (1677:9): [True: 0, False: 1.43k]
  ------------------
 1678|      0|        goto cleanup;
 1679|       |
 1680|  1.43k|    if (ctx->handle.value) {
  ------------------
  |  Branch (1680:9): [True: 1.43k, False: 0]
  ------------------
 1681|  1.43k|        retval = sav_read_data(ctx);
 1682|  1.43k|    }
 1683|       |    
 1684|  5.12k|cleanup:
 1685|  5.12k|    io->close(io->io_ctx);
 1686|  5.12k|    if (ctx)
  ------------------
  |  Branch (1686:9): [True: 5.07k, False: 50]
  ------------------
 1687|  5.07k|        sav_ctx_free(ctx);
 1688|       |    
 1689|  5.12k|    return retval;
 1690|  1.43k|}
readstat_sav_read.c:sav_parse_records_pass1:
 1275|  5.07k|static readstat_error_t sav_parse_records_pass1(sav_ctx_t *ctx) {
 1276|  5.07k|    char data_buf[4096];
 1277|  5.07k|    readstat_error_t retval = READSTAT_OK;
 1278|  5.07k|    readstat_io_t *io = ctx->io;
 1279|   379k|    while (1) {
  ------------------
  |  Branch (1279:12): [Folded - Ignored]
  ------------------
 1280|   379k|        uint32_t rec_type;
 1281|   379k|        uint32_t extra_info[3];
 1282|   379k|        size_t data_len = 0;
 1283|   379k|        int i;
 1284|   379k|        int done = 0;
 1285|   379k|        if (io->read(&rec_type, sizeof(uint32_t), io->io_ctx) < sizeof(uint32_t)) {
  ------------------
  |  Branch (1285:13): [True: 305, False: 378k]
  ------------------
 1286|    305|            retval = READSTAT_ERROR_READ;
 1287|    305|            goto cleanup;
 1288|    305|        }
 1289|       |        
 1290|   378k|        if (ctx->bswap) {
  ------------------
  |  Branch (1290:13): [True: 54.6k, False: 324k]
  ------------------
 1291|  54.6k|            rec_type = byteswap4(rec_type);
 1292|  54.6k|        }
 1293|       |        
 1294|   378k|        switch (rec_type) {
 1295|   321k|            case SAV_RECORD_TYPE_VARIABLE:
  ------------------
  |  |  111|   321k|#define SAV_RECORD_TYPE_VARIABLE                2
  ------------------
  |  Branch (1295:13): [True: 321k, False: 56.9k]
  ------------------
 1296|   321k|                retval = sav_skip_variable_record(ctx);
 1297|   321k|                if (retval != READSTAT_OK)
  ------------------
  |  Branch (1297:21): [True: 134, False: 321k]
  ------------------
 1298|    134|                    goto cleanup;
 1299|   321k|                break;
 1300|   321k|            case SAV_RECORD_TYPE_VALUE_LABEL:
  ------------------
  |  |  112|  42.4k|#define SAV_RECORD_TYPE_VALUE_LABEL             3
  ------------------
  |  Branch (1300:13): [True: 42.4k, False: 336k]
  ------------------
 1301|  42.4k|                retval = sav_skip_value_label_record(ctx);
 1302|  42.4k|                if (retval != READSTAT_OK)
  ------------------
  |  Branch (1302:21): [True: 179, False: 42.3k]
  ------------------
 1303|    179|                    goto cleanup;
 1304|  42.3k|                break;
 1305|  42.3k|            case SAV_RECORD_TYPE_DOCUMENT:
  ------------------
  |  |  114|  1.81k|#define SAV_RECORD_TYPE_DOCUMENT                6
  ------------------
  |  Branch (1305:13): [True: 1.81k, False: 377k]
  ------------------
 1306|  1.81k|                retval = sav_skip_document_record(ctx);
 1307|  1.81k|                if (retval != READSTAT_OK)
  ------------------
  |  Branch (1307:21): [True: 52, False: 1.76k]
  ------------------
 1308|     52|                    goto cleanup;
 1309|  1.76k|                break;
 1310|  4.11k|            case SAV_RECORD_TYPE_DICT_TERMINATION:
  ------------------
  |  |  116|  4.11k|#define SAV_RECORD_TYPE_DICT_TERMINATION        999
  ------------------
  |  Branch (1310:13): [True: 4.11k, False: 374k]
  ------------------
 1311|  4.11k|                done = 1;
 1312|  4.11k|                break;
 1313|  8.48k|            case SAV_RECORD_TYPE_HAS_DATA:
  ------------------
  |  |  115|  8.48k|#define SAV_RECORD_TYPE_HAS_DATA                7
  ------------------
  |  Branch (1313:13): [True: 8.48k, False: 370k]
  ------------------
 1314|  8.48k|                if (io->read(extra_info, sizeof(extra_info), io->io_ctx) < sizeof(extra_info)) {
  ------------------
  |  Branch (1314:21): [True: 7, False: 8.47k]
  ------------------
 1315|      7|                    retval = READSTAT_ERROR_READ;
 1316|      7|                    goto cleanup;
 1317|      7|                }
 1318|  8.47k|                if (ctx->bswap) {
  ------------------
  |  Branch (1318:21): [True: 2.48k, False: 5.99k]
  ------------------
 1319|  9.93k|                    for (i=0; i<3; i++)
  ------------------
  |  Branch (1319:31): [True: 7.44k, False: 2.48k]
  ------------------
 1320|  7.44k|                        extra_info[i] = byteswap4(extra_info[i]);
 1321|  2.48k|                }
 1322|  8.47k|                uint32_t subtype = extra_info[0];
 1323|  8.47k|                size_t size = extra_info[1];
 1324|  8.47k|                size_t count = extra_info[2];
 1325|  8.47k|                data_len = size * count;
 1326|  8.47k|                if (subtype == SAV_RECORD_SUBTYPE_INTEGER_INFO) {
  ------------------
  |  |  118|  8.47k|#define SAV_RECORD_SUBTYPE_INTEGER_INFO       3
  ------------------
  |  Branch (1326:21): [True: 875, False: 7.60k]
  ------------------
 1327|    875|                    if (data_len > sizeof(data_buf)) {
  ------------------
  |  Branch (1327:25): [True: 60, False: 815]
  ------------------
 1328|     60|                        retval = READSTAT_ERROR_PARSE;
 1329|     60|                        goto cleanup;
 1330|     60|                    }
 1331|    815|                    if (io->read(data_buf, data_len, io->io_ctx) < data_len) {
  ------------------
  |  Branch (1331:25): [True: 16, False: 799]
  ------------------
 1332|     16|                        retval = READSTAT_ERROR_PARSE;
 1333|     16|                        goto cleanup;
 1334|     16|                    }
 1335|    799|                    retval = sav_parse_machine_integer_info_record(data_buf, data_len, ctx);
 1336|    799|                    if (retval != READSTAT_OK)
  ------------------
  |  Branch (1336:25): [True: 33, False: 766]
  ------------------
 1337|     33|                        goto cleanup;
 1338|  7.60k|                } else {
 1339|  7.60k|                    if (io->seek(data_len, READSTAT_SEEK_CUR, io->io_ctx) == -1) {
  ------------------
  |  Branch (1339:25): [True: 100, False: 7.50k]
  ------------------
 1340|    100|                        retval = READSTAT_ERROR_SEEK;
 1341|    100|                        goto cleanup;
 1342|    100|                    }
 1343|  7.60k|                }
 1344|  8.26k|                break;
 1345|  8.26k|            default:
  ------------------
  |  Branch (1345:13): [True: 75, False: 378k]
  ------------------
 1346|     75|                retval = READSTAT_ERROR_PARSE;
 1347|     75|                goto cleanup;
 1348|      0|                break;
 1349|   378k|        }
 1350|   378k|        if (done)
  ------------------
  |  Branch (1350:13): [True: 4.11k, False: 374k]
  ------------------
 1351|  4.11k|            break;
 1352|   378k|    }
 1353|  5.07k|cleanup:
 1354|  5.07k|    return retval;
 1355|  5.07k|}
readstat_sav_read.c:sav_skip_variable_record:
  168|   321k|static readstat_error_t sav_skip_variable_record(sav_ctx_t *ctx) {
  169|   321k|    sav_variable_record_t variable;
  170|   321k|    readstat_error_t retval = READSTAT_OK;
  171|   321k|    readstat_io_t *io = ctx->io;
  172|   321k|    if (io->read(&variable, sizeof(sav_variable_record_t), io->io_ctx) < sizeof(sav_variable_record_t)) {
  ------------------
  |  Branch (172:9): [True: 9, False: 321k]
  ------------------
  173|      9|        retval = READSTAT_ERROR_READ;
  174|      9|        goto cleanup;
  175|      9|    }
  176|   321k|    if (variable.has_var_label) {
  ------------------
  |  Branch (176:9): [True: 6.13k, False: 315k]
  ------------------
  177|  6.13k|        uint32_t label_len;
  178|  6.13k|        if (io->read(&label_len, sizeof(uint32_t), io->io_ctx) < sizeof(uint32_t)) {
  ------------------
  |  Branch (178:13): [True: 46, False: 6.09k]
  ------------------
  179|     46|            retval = READSTAT_ERROR_READ;
  180|     46|            goto cleanup;
  181|     46|        }
  182|  6.09k|        label_len = ctx->bswap ? byteswap4(label_len) : label_len;
  ------------------
  |  Branch (182:21): [True: 5.10k, False: 983]
  ------------------
  183|  6.09k|        uint32_t label_capacity = (label_len + 3) / 4 * 4;
  184|  6.09k|        if (io->seek(label_capacity, READSTAT_SEEK_CUR, io->io_ctx) == -1) {
  ------------------
  |  Branch (184:13): [True: 7, False: 6.08k]
  ------------------
  185|      7|            retval = READSTAT_ERROR_SEEK;
  186|      7|            goto cleanup;
  187|      7|        }
  188|  6.09k|    }
  189|   321k|    if (variable.n_missing_values) {
  ------------------
  |  Branch (189:9): [True: 7.72k, False: 314k]
  ------------------
  190|  7.72k|        int n_missing_values = ctx->bswap ? byteswap4(variable.n_missing_values) : variable.n_missing_values;
  ------------------
  |  Branch (190:32): [True: 5.65k, False: 2.07k]
  ------------------
  191|  7.72k|        if (io->seek(abs(n_missing_values) * sizeof(double), READSTAT_SEEK_CUR, io->io_ctx) == -1) {
  ------------------
  |  Branch (191:13): [True: 72, False: 7.65k]
  ------------------
  192|     72|            retval = READSTAT_ERROR_SEEK;
  193|     72|            goto cleanup;
  194|     72|        }
  195|  7.72k|    }
  196|   321k|cleanup:
  197|   321k|    return retval;
  198|   321k|}
readstat_sav_read.c:sav_skip_value_label_record:
  403|  42.4k|static readstat_error_t sav_skip_value_label_record(sav_ctx_t *ctx) {
  404|  42.4k|    uint32_t label_count;
  405|  42.4k|    uint32_t rec_type;
  406|  42.4k|    uint32_t var_count;
  407|  42.4k|    readstat_error_t retval = READSTAT_OK;
  408|  42.4k|    readstat_io_t *io = ctx->io;
  409|  42.4k|    if (io->read(&label_count, sizeof(uint32_t), io->io_ctx) < sizeof(uint32_t)) {
  ------------------
  |  Branch (409:9): [True: 3, False: 42.4k]
  ------------------
  410|      3|        retval = READSTAT_ERROR_READ;
  411|      3|        goto cleanup;
  412|      3|    }
  413|  42.4k|    if (ctx->bswap)
  ------------------
  |  Branch (413:9): [True: 41.1k, False: 1.30k]
  ------------------
  414|  41.1k|        label_count = byteswap4(label_count);
  415|  42.4k|    int i;
  416|   241k|    for (i=0; i<label_count; i++) {
  ------------------
  |  Branch (416:15): [True: 199k, False: 42.3k]
  ------------------
  417|   199k|        unsigned char unpadded_len = 0;
  418|   199k|        size_t padded_len = 0;
  419|   199k|        if (io->seek(8, READSTAT_SEEK_CUR, io->io_ctx) == -1) {
  ------------------
  |  Branch (419:13): [True: 71, False: 199k]
  ------------------
  420|     71|            retval = READSTAT_ERROR_SEEK;
  421|     71|            goto cleanup;
  422|     71|        }
  423|   199k|        if (io->read(&unpadded_len, 1, io->io_ctx) < 1) {
  ------------------
  |  Branch (423:13): [True: 21, False: 199k]
  ------------------
  424|     21|            retval = READSTAT_ERROR_READ;
  425|     21|            goto cleanup;
  426|     21|        }
  427|   199k|        padded_len = (unpadded_len + 8) / 8 * 8 - 1;
  428|   199k|        if (io->seek(padded_len, READSTAT_SEEK_CUR, io->io_ctx) == -1) {
  ------------------
  |  Branch (428:13): [True: 2, False: 199k]
  ------------------
  429|      2|            retval = READSTAT_ERROR_SEEK;
  430|      2|            goto cleanup;
  431|      2|        }
  432|   199k|    }
  433|       |
  434|  42.3k|    if (io->read(&rec_type, sizeof(uint32_t), io->io_ctx) < sizeof(uint32_t)) {
  ------------------
  |  Branch (434:9): [True: 23, False: 42.3k]
  ------------------
  435|     23|        retval = READSTAT_ERROR_READ;
  436|     23|        goto cleanup;
  437|     23|    }
  438|  42.3k|    if (ctx->bswap)
  ------------------
  |  Branch (438:9): [True: 41.0k, False: 1.26k]
  ------------------
  439|  41.0k|        rec_type = byteswap4(rec_type);
  440|       |    
  441|  42.3k|    if (rec_type != 4) {
  ------------------
  |  Branch (441:9): [True: 48, False: 42.3k]
  ------------------
  442|     48|        retval = READSTAT_ERROR_PARSE;
  443|     48|        goto cleanup;
  444|     48|    }
  445|  42.3k|    if (io->read(&var_count, sizeof(uint32_t), io->io_ctx) < sizeof(uint32_t)) {
  ------------------
  |  Branch (445:9): [True: 4, False: 42.3k]
  ------------------
  446|      4|        retval = READSTAT_ERROR_READ;
  447|      4|        goto cleanup;
  448|      4|    }
  449|  42.3k|    if (ctx->bswap)
  ------------------
  |  Branch (449:9): [True: 41.0k, False: 1.23k]
  ------------------
  450|  41.0k|        var_count = byteswap4(var_count);
  451|       |    
  452|  42.3k|    if (io->seek(var_count * sizeof(uint32_t), READSTAT_SEEK_CUR, io->io_ctx) == -1) {
  ------------------
  |  Branch (452:9): [True: 7, False: 42.3k]
  ------------------
  453|      7|        retval = READSTAT_ERROR_SEEK;
  454|      7|        goto cleanup;
  455|      7|    }
  456|       |
  457|  42.4k|cleanup:
  458|  42.4k|    return retval;
  459|  42.3k|}
readstat_sav_read.c:sav_skip_document_record:
  615|  1.81k|static readstat_error_t sav_skip_document_record(sav_ctx_t *ctx) {
  616|  1.81k|    uint32_t n_lines;
  617|  1.81k|    readstat_error_t retval = READSTAT_OK;
  618|  1.81k|    readstat_io_t *io = ctx->io;
  619|  1.81k|    if (io->read(&n_lines, sizeof(uint32_t), io->io_ctx) < sizeof(uint32_t)) {
  ------------------
  |  Branch (619:9): [True: 3, False: 1.81k]
  ------------------
  620|      3|        retval = READSTAT_ERROR_READ;
  621|      3|        goto cleanup;
  622|      3|    }
  623|  1.81k|    if (ctx->bswap)
  ------------------
  |  Branch (623:9): [True: 1.27k, False: 536]
  ------------------
  624|  1.27k|        n_lines = byteswap4(n_lines);
  625|  1.81k|    if (io->seek(n_lines * SPSS_DOC_LINE_SIZE, READSTAT_SEEK_CUR, io->io_ctx) == -1) {
  ------------------
  |  |   40|  1.81k|#define SPSS_DOC_LINE_SIZE  80
  ------------------
  |  Branch (625:9): [True: 49, False: 1.76k]
  ------------------
  626|     49|        retval = READSTAT_ERROR_SEEK;
  627|     49|        goto cleanup;
  628|     49|    }
  629|       |    
  630|  1.81k|cleanup:
  631|  1.81k|    return retval;
  632|  1.81k|}
readstat_sav_read.c:sav_parse_machine_integer_info_record:
  917|    799|static readstat_error_t sav_parse_machine_integer_info_record(const void *data, size_t data_len, sav_ctx_t *ctx) {
  918|    799|    if (data_len != 32)
  ------------------
  |  Branch (918:9): [True: 10, False: 789]
  ------------------
  919|     10|        return READSTAT_ERROR_PARSE;
  920|       |
  921|    789|    const char *src_charset = NULL;
  922|    789|    const char *dst_charset = ctx->output_encoding;
  923|    789|    sav_machine_integer_info_record_t record;
  924|    789|    memcpy(&record, data, data_len);
  925|    789|    if (ctx->bswap) {
  ------------------
  |  Branch (925:9): [True: 385, False: 404]
  ------------------
  926|    385|        record.character_code = byteswap4(record.character_code);
  927|    385|    }
  928|    789|    if (ctx->input_encoding) {
  ------------------
  |  Branch (928:9): [True: 672, False: 117]
  ------------------
  929|    672|        src_charset = ctx->input_encoding;
  930|    672|    } else {
  931|    117|        int i;
  932|  6.95k|        for (i=0; i<sizeof(_charset_table)/sizeof(_charset_table[0]); i++) {
  ------------------
  |  Branch (932:19): [True: 6.93k, False: 22]
  ------------------
  933|  6.93k|            if (record.character_code  == _charset_table[i].code) {
  ------------------
  |  Branch (933:17): [True: 95, False: 6.83k]
  ------------------
  934|     95|                src_charset = _charset_table[i].name;
  935|     95|                break;
  936|     95|            }
  937|  6.93k|        }
  938|    117|        if (src_charset == NULL) {
  ------------------
  |  Branch (938:13): [True: 22, False: 95]
  ------------------
  939|     22|            if (ctx->handle.error) {
  ------------------
  |  Branch (939:17): [True: 0, False: 22]
  ------------------
  940|      0|                char error_buf[1024];
  941|      0|                snprintf(error_buf, sizeof(error_buf), "Unsupported character set: %d\n", record.character_code);
  942|      0|                ctx->handle.error(error_buf, ctx->user_ctx);
  943|      0|            }
  944|     22|            return READSTAT_ERROR_UNSUPPORTED_CHARSET;
  945|     22|        }
  946|     95|        ctx->input_encoding = src_charset;
  947|     95|    }
  948|    767|    if (src_charset && dst_charset) {
  ------------------
  |  Branch (948:9): [True: 767, False: 0]
  |  Branch (948:24): [True: 767, False: 0]
  ------------------
  949|       |        // You might be tempted to skip the charset conversion when src_charset
  950|       |        // and dst_charset are the same. However, some versions of SPSS insert
  951|       |        // illegally truncated strings (e.g. the last character is three bytes
  952|       |        // but the field only has room for two bytes). So to prevent the client
  953|       |        // from receiving an invalid byte sequence, we ram everything through
  954|       |        // our iconv machinery.
  955|    767|        iconv_t converter = iconv_open(dst_charset, src_charset);
  956|    767|        if (converter == (iconv_t)-1) {
  ------------------
  |  Branch (956:13): [True: 1, False: 766]
  ------------------
  957|      1|            return READSTAT_ERROR_UNSUPPORTED_CHARSET;
  958|      1|        }
  959|    766|        if (ctx->converter) {
  ------------------
  |  Branch (959:13): [True: 672, False: 94]
  ------------------
  960|    672|            iconv_close(ctx->converter);
  961|    672|        }
  962|    766|        ctx->converter = converter;
  963|    766|    }
  964|    766|    return READSTAT_OK;
  965|    767|}
readstat_sav_read.c:sav_update_progress:
  163|  5.96k|static readstat_error_t sav_update_progress(sav_ctx_t *ctx) {
  164|  5.96k|    readstat_io_t *io = ctx->io;
  165|  5.96k|    return io->update(ctx->file_size, ctx->handle.progress, ctx->user_ctx, io->io_ctx);
  166|  5.96k|}
readstat_sav_read.c:sav_parse_records_pass2:
 1357|  4.11k|static readstat_error_t sav_parse_records_pass2(sav_ctx_t *ctx) {
 1358|  4.11k|    void *data_buf = NULL;
 1359|  4.11k|    size_t data_buf_capacity = 4096;
 1360|  4.11k|    readstat_error_t retval = READSTAT_OK;
 1361|  4.11k|    readstat_io_t *io = ctx->io;
 1362|       |
 1363|  4.11k|    if ((data_buf = readstat_malloc(data_buf_capacity)) == NULL) {
  ------------------
  |  Branch (1363:9): [True: 0, False: 4.11k]
  ------------------
 1364|      0|        retval = READSTAT_ERROR_MALLOC;
 1365|      0|        goto cleanup;
 1366|      0|    }
 1367|       |
 1368|   380k|    while (1) {
  ------------------
  |  Branch (1368:12): [Folded - Ignored]
  ------------------
 1369|   380k|        uint32_t rec_type;
 1370|   380k|        uint32_t extra_info[3];
 1371|   380k|        size_t data_len = 0;
 1372|   380k|        int i;
 1373|   380k|        int done = 0;
 1374|   380k|        if (io->read(&rec_type, sizeof(uint32_t), io->io_ctx) < sizeof(uint32_t)) {
  ------------------
  |  Branch (1374:13): [True: 32, False: 380k]
  ------------------
 1375|     32|            retval = READSTAT_ERROR_READ;
 1376|     32|            goto cleanup;
 1377|     32|        }
 1378|       |        
 1379|   380k|        if (ctx->bswap) {
  ------------------
  |  Branch (1379:13): [True: 41.3k, False: 339k]
  ------------------
 1380|  41.3k|            rec_type = byteswap4(rec_type);
 1381|  41.3k|        }
 1382|       |        
 1383|   380k|        switch (rec_type) {
 1384|   335k|            case SAV_RECORD_TYPE_VARIABLE:
  ------------------
  |  |  111|   335k|#define SAV_RECORD_TYPE_VARIABLE                2
  ------------------
  |  Branch (1384:13): [True: 335k, False: 44.8k]
  ------------------
 1385|   335k|                if ((retval = sav_read_variable_record(ctx)) != READSTAT_OK)
  ------------------
  |  Branch (1385:21): [True: 165, False: 335k]
  ------------------
 1386|    165|                    goto cleanup;
 1387|   335k|                break;
 1388|   335k|            case SAV_RECORD_TYPE_VALUE_LABEL:
  ------------------
  |  |  112|  34.5k|#define SAV_RECORD_TYPE_VALUE_LABEL             3
  ------------------
  |  Branch (1388:13): [True: 34.5k, False: 345k]
  ------------------
 1389|  34.5k|                if ((retval = sav_read_value_label_record(ctx)) != READSTAT_OK)
  ------------------
  |  Branch (1389:21): [True: 159, False: 34.3k]
  ------------------
 1390|    159|                    goto cleanup;
 1391|  34.3k|                break;
 1392|  34.3k|            case SAV_RECORD_TYPE_DOCUMENT:
  ------------------
  |  |  114|  1.10k|#define SAV_RECORD_TYPE_DOCUMENT                6
  ------------------
  |  Branch (1392:13): [True: 1.10k, False: 379k]
  ------------------
 1393|  1.10k|                if ((retval = sav_read_document_record(ctx)) != READSTAT_OK)
  ------------------
  |  Branch (1393:21): [True: 65, False: 1.03k]
  ------------------
 1394|     65|                    goto cleanup;
 1395|  1.03k|                break;
 1396|  2.64k|            case SAV_RECORD_TYPE_DICT_TERMINATION:
  ------------------
  |  |  116|  2.64k|#define SAV_RECORD_TYPE_DICT_TERMINATION        999
  ------------------
  |  Branch (1396:13): [True: 2.64k, False: 377k]
  ------------------
 1397|  2.64k|                if ((retval = sav_read_dictionary_termination_record(ctx)) != READSTAT_OK)
  ------------------
  |  Branch (1397:21): [True: 1.13k, False: 1.51k]
  ------------------
 1398|  1.13k|                    goto cleanup;
 1399|  1.51k|                done = 1;
 1400|  1.51k|                break;
 1401|  6.54k|            case SAV_RECORD_TYPE_HAS_DATA:
  ------------------
  |  |  115|  6.54k|#define SAV_RECORD_TYPE_HAS_DATA                7
  ------------------
  |  Branch (1401:13): [True: 6.54k, False: 373k]
  ------------------
 1402|  6.54k|                if (io->read(extra_info, sizeof(extra_info), io->io_ctx) < sizeof(extra_info)) {
  ------------------
  |  Branch (1402:21): [True: 7, False: 6.53k]
  ------------------
 1403|      7|                    retval = READSTAT_ERROR_READ;
 1404|      7|                    goto cleanup;
 1405|      7|                }
 1406|  6.53k|                if (ctx->bswap) {
  ------------------
  |  Branch (1406:21): [True: 1.75k, False: 4.78k]
  ------------------
 1407|  7.00k|                    for (i=0; i<3; i++)
  ------------------
  |  Branch (1407:31): [True: 5.25k, False: 1.75k]
  ------------------
 1408|  5.25k|                        extra_info[i] = byteswap4(extra_info[i]);
 1409|  1.75k|                }
 1410|  6.53k|                uint32_t subtype = extra_info[0];
 1411|  6.53k|                size_t size = extra_info[1];
 1412|  6.53k|                size_t count = extra_info[2];
 1413|  6.53k|                data_len = size * count;
 1414|  6.53k|                if (data_buf_capacity < data_len) {
  ------------------
  |  Branch (1414:21): [True: 168, False: 6.36k]
  ------------------
 1415|    168|                    if ((data_buf = readstat_realloc(data_buf, data_buf_capacity = data_len)) == NULL) {
  ------------------
  |  Branch (1415:25): [True: 64, False: 104]
  ------------------
 1416|     64|                        retval = READSTAT_ERROR_MALLOC;
 1417|     64|                        goto cleanup;
 1418|     64|                    }
 1419|    168|                }
 1420|  6.46k|                if (data_len == 0 || io->read(data_buf, data_len, io->io_ctx) < data_len) {
  ------------------
  |  Branch (1420:21): [True: 16, False: 6.45k]
  |  Branch (1420:38): [True: 37, False: 6.41k]
  ------------------
 1421|     53|                    retval = READSTAT_ERROR_PARSE;
 1422|     53|                    goto cleanup;
 1423|     53|                }
 1424|       |                
 1425|  6.41k|                switch (subtype) {
 1426|     68|                    case SAV_RECORD_SUBTYPE_INTEGER_INFO:
  ------------------
  |  |  118|     68|#define SAV_RECORD_SUBTYPE_INTEGER_INFO       3
  ------------------
  |  Branch (1426:21): [True: 68, False: 6.34k]
  ------------------
 1427|       |                        /* parsed in pass 1 */
 1428|     68|                        break;
 1429|    472|                    case SAV_RECORD_SUBTYPE_FP_INFO:
  ------------------
  |  |  119|    472|#define SAV_RECORD_SUBTYPE_FP_INFO            4
  ------------------
  |  Branch (1429:21): [True: 472, False: 5.94k]
  ------------------
 1430|    472|                        retval = sav_parse_machine_floating_point_record(data_buf, size, count, ctx);
 1431|    472|                        if (retval != READSTAT_OK)
  ------------------
  |  Branch (1431:29): [True: 38, False: 434]
  ------------------
 1432|     38|                            goto cleanup;
 1433|    434|                        break;
 1434|    454|                    case SAV_RECORD_SUBTYPE_VAR_DISPLAY:
  ------------------
  |  |  121|    454|#define SAV_RECORD_SUBTYPE_VAR_DISPLAY       11
  ------------------
  |  Branch (1434:21): [True: 454, False: 5.96k]
  ------------------
 1435|    454|                        retval = sav_store_variable_display_parameter_record(data_buf, size, count, ctx);
 1436|    454|                        if (retval != READSTAT_OK)
  ------------------
  |  Branch (1436:29): [True: 9, False: 445]
  ------------------
 1437|      9|                            goto cleanup;
 1438|    445|                        break;
 1439|  1.21k|                    case SAV_RECORD_SUBTYPE_LONG_VAR_NAME:
  ------------------
  |  |  122|  1.21k|#define SAV_RECORD_SUBTYPE_LONG_VAR_NAME     13
  ------------------
  |  Branch (1439:21): [True: 1.21k, False: 5.20k]
  ------------------
 1440|  1.21k|                        retval = sav_parse_long_variable_names_record(data_buf, count, ctx);
 1441|  1.21k|                        if (retval != READSTAT_OK)
  ------------------
  |  Branch (1441:29): [True: 180, False: 1.03k]
  ------------------
 1442|    180|                            goto cleanup;
 1443|  1.03k|                        break;
 1444|  2.01k|                    case SAV_RECORD_SUBTYPE_VERY_LONG_STR:
  ------------------
  |  |  123|  2.01k|#define SAV_RECORD_SUBTYPE_VERY_LONG_STR     14
  ------------------
  |  Branch (1444:21): [True: 2.01k, False: 4.40k]
  ------------------
 1445|  2.01k|                        retval = sav_parse_very_long_string_record(data_buf, count, ctx);
 1446|  2.01k|                        if (retval != READSTAT_OK)
  ------------------
  |  Branch (1446:29): [True: 178, False: 1.83k]
  ------------------
 1447|    178|                            goto cleanup;
 1448|  1.83k|                        break;
 1449|  1.83k|                    case SAV_RECORD_SUBTYPE_LONG_STRING_VALUE_LABELS:
  ------------------
  |  |  128|    731|#define SAV_RECORD_SUBTYPE_LONG_STRING_VALUE_LABELS   21
  ------------------
  |  Branch (1449:21): [True: 731, False: 5.68k]
  ------------------
 1450|    731|                        retval = sav_parse_long_string_value_labels_record(data_buf, size, count, ctx);
 1451|    731|                        if (retval != READSTAT_OK)
  ------------------
  |  Branch (1451:29): [True: 265, False: 466]
  ------------------
 1452|    265|                            goto cleanup;
 1453|    466|                        break;
 1454|    466|                    case SAV_RECORD_SUBTYPE_LONG_STRING_MISSING_VALUES:
  ------------------
  |  |  129|    461|#define SAV_RECORD_SUBTYPE_LONG_STRING_MISSING_VALUES 22
  ------------------
  |  Branch (1454:21): [True: 461, False: 5.95k]
  ------------------
 1455|    461|                        retval = sav_parse_long_string_missing_values_record(data_buf, size, count, ctx);
 1456|    461|                        if (retval != READSTAT_OK)
  ------------------
  |  Branch (1456:29): [True: 189, False: 272]
  ------------------
 1457|    189|                            goto cleanup;
 1458|    272|                        break;
 1459|    999|                    default: /* misc. info */
  ------------------
  |  Branch (1459:21): [True: 999, False: 5.41k]
  ------------------
 1460|    999|                        break;
 1461|  6.41k|                }
 1462|  5.55k|                break;
 1463|  5.55k|            default:
  ------------------
  |  Branch (1463:13): [True: 66, False: 380k]
  ------------------
 1464|     66|                retval = READSTAT_ERROR_PARSE;
 1465|     66|                goto cleanup;
 1466|      0|                break;
 1467|   380k|        }
 1468|   377k|        if (done)
  ------------------
  |  Branch (1468:13): [True: 1.51k, False: 376k]
  ------------------
 1469|  1.51k|            break;
 1470|   377k|    }
 1471|  4.11k|cleanup:
 1472|  4.11k|    if (data_buf)
  ------------------
  |  Branch (1472:9): [True: 4.05k, False: 64]
  ------------------
 1473|  4.05k|        free(data_buf);
 1474|  4.11k|    return retval;
 1475|  4.11k|}
readstat_sav_read.c:sav_read_variable_record:
  315|   335k|static readstat_error_t sav_read_variable_record(sav_ctx_t *ctx) {
  316|   335k|    readstat_io_t *io = ctx->io;
  317|   335k|    sav_variable_record_t variable = { 0 };
  318|   335k|    spss_varinfo_t *info = NULL;
  319|   335k|    readstat_error_t retval = READSTAT_OK;
  320|   335k|    if (ctx->var_index == ctx->varinfo_capacity) {
  ------------------
  |  Branch (320:9): [True: 194, False: 335k]
  ------------------
  321|    194|        if ((ctx->varinfo = readstat_realloc(ctx->varinfo, (ctx->varinfo_capacity *= 2) * sizeof(spss_varinfo_t *))) == NULL) {
  ------------------
  |  Branch (321:13): [True: 0, False: 194]
  ------------------
  322|      0|            retval = READSTAT_ERROR_MALLOC;
  323|      0|            goto cleanup;
  324|      0|        }
  325|    194|    }
  326|   335k|    if (io->read(&variable, sizeof(sav_variable_record_t), io->io_ctx) < sizeof(sav_variable_record_t)) {
  ------------------
  |  Branch (326:9): [True: 8, False: 335k]
  ------------------
  327|      8|        retval = READSTAT_ERROR_READ;
  328|      8|        goto cleanup;
  329|      8|    }
  330|   335k|    variable.print = ctx->bswap ? byteswap4(variable.print) : variable.print;
  ------------------
  |  Branch (330:22): [True: 4.74k, False: 330k]
  ------------------
  331|   335k|    variable.write = ctx->bswap ? byteswap4(variable.write) : variable.write;
  ------------------
  |  Branch (331:22): [True: 4.74k, False: 330k]
  ------------------
  332|       |
  333|   335k|    int32_t type = ctx->bswap ? byteswap4(variable.type) : variable.type;
  ------------------
  |  Branch (333:20): [True: 4.74k, False: 330k]
  ------------------
  334|   335k|    if (type < 0) {
  ------------------
  |  Branch (334:9): [True: 2.35k, False: 333k]
  ------------------
  335|  2.35k|        if (ctx->var_index == 0) {
  ------------------
  |  Branch (335:13): [True: 32, False: 2.32k]
  ------------------
  336|     32|            return READSTAT_ERROR_PARSE;
  337|     32|        }
  338|  2.32k|        ctx->var_offset++;
  339|  2.32k|        ctx->varinfo[ctx->var_index-1]->width++;
  340|  2.32k|        return 0;
  341|  2.35k|    }
  342|       |
  343|   333k|    if ((info = readstat_calloc(1, sizeof(spss_varinfo_t))) == NULL) {
  ------------------
  |  Branch (343:9): [True: 0, False: 333k]
  ------------------
  344|      0|        retval = READSTAT_ERROR_MALLOC;
  345|      0|        goto cleanup;
  346|      0|    }
  347|   333k|    info->width = 1;
  348|   333k|    info->n_segments = 1;
  349|   333k|    info->index = ctx->var_index;
  350|   333k|    info->offset = ctx->var_offset;
  351|   333k|    info->labels_index = -1;
  352|       |
  353|   333k|    retval = readstat_convert(info->name, sizeof(info->name),
  354|   333k|            variable.name, sizeof(variable.name), NULL);
  355|   333k|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (355:9): [True: 0, False: 333k]
  ------------------
  356|      0|        goto cleanup;
  357|       |
  358|   333k|    retval = readstat_convert(info->longname, sizeof(info->longname), 
  359|   333k|            variable.name, sizeof(variable.name), NULL);
  360|   333k|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (360:9): [True: 0, False: 333k]
  ------------------
  361|      0|        goto cleanup;
  362|       |
  363|   333k|    info->print_format.decimal_places = (variable.print & 0x000000FF);
  364|   333k|    info->print_format.width = (variable.print & 0x0000FF00) >> 8;
  365|   333k|    info->print_format.type = (variable.print  & 0x00FF0000) >> 16;
  366|       |
  367|   333k|    info->write_format.decimal_places = (variable.write & 0x000000FF);
  368|   333k|    info->write_format.width = (variable.write & 0x0000FF00) >> 8;
  369|   333k|    info->write_format.type = (variable.write  & 0x00FF0000) >> 16;
  370|       |
  371|   333k|    if (type > 0 || info->print_format.type == SPSS_FORMAT_TYPE_A || info->write_format.type == SPSS_FORMAT_TYPE_A) {
  ------------------
  |  |    2|   571k|#define SPSS_FORMAT_TYPE_A        1
  ------------------
                  if (type > 0 || info->print_format.type == SPSS_FORMAT_TYPE_A || info->write_format.type == SPSS_FORMAT_TYPE_A) {
  ------------------
  |  |    2|   141k|#define SPSS_FORMAT_TYPE_A        1
  ------------------
  |  Branch (371:9): [True: 94.9k, False: 238k]
  |  Branch (371:21): [True: 96.6k, False: 141k]
  |  Branch (371:70): [True: 80.9k, False: 60.7k]
  ------------------
  372|   272k|        info->type = READSTAT_TYPE_STRING;
  373|   272k|    } else {
  374|  60.7k|        info->type = READSTAT_TYPE_DOUBLE;
  375|  60.7k|    }
  376|       |    
  377|   333k|    if (variable.has_var_label) {
  ------------------
  |  Branch (377:9): [True: 3.61k, False: 329k]
  ------------------
  378|  3.61k|        if ((retval = sav_read_variable_label(info, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (378:13): [True: 63, False: 3.55k]
  ------------------
  379|     63|            goto cleanup;
  380|     63|        }
  381|  3.61k|    }
  382|       |    
  383|   333k|    if (variable.n_missing_values) {
  ------------------
  |  Branch (383:9): [True: 3.91k, False: 329k]
  ------------------
  384|  3.91k|        info->n_missing_values = ctx->bswap ? byteswap4(variable.n_missing_values) : variable.n_missing_values;
  ------------------
  |  Branch (384:34): [True: 2.19k, False: 1.72k]
  ------------------
  385|  3.91k|        if ((retval = sav_read_variable_missing_values(info, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (385:13): [True: 62, False: 3.85k]
  ------------------
  386|     62|            goto cleanup;
  387|     62|        }
  388|  3.91k|    }
  389|       |    
  390|   333k|    ctx->varinfo[ctx->var_index] = info;
  391|       |
  392|   333k|    ctx->var_index++;
  393|   333k|    ctx->var_offset++;
  394|       |    
  395|   333k|cleanup:
  396|   333k|    if (retval != READSTAT_OK) {
  ------------------
  |  Branch (396:9): [True: 133, False: 333k]
  ------------------
  397|    133|        spss_varinfo_free(info);
  398|    133|    }
  399|       |
  400|   333k|    return retval;
  401|   333k|}
readstat_sav_read.c:sav_read_variable_label:
  200|  3.61k|static readstat_error_t sav_read_variable_label(spss_varinfo_t *info, sav_ctx_t *ctx) {
  201|  3.61k|    readstat_io_t *io = ctx->io;
  202|  3.61k|    readstat_error_t retval = READSTAT_OK;
  203|  3.61k|    uint32_t label_len, label_capacity;
  204|  3.61k|    size_t out_label_len;
  205|  3.61k|    char *label_buf = NULL;
  206|  3.61k|    if (io->read(&label_len, sizeof(uint32_t), io->io_ctx) < sizeof(uint32_t)) {
  ------------------
  |  Branch (206:9): [True: 5, False: 3.60k]
  ------------------
  207|      5|        retval = READSTAT_ERROR_READ;
  208|      5|        goto cleanup;
  209|      5|    }
  210|  3.60k|    label_len = ctx->bswap ? byteswap4(label_len) : label_len;
  ------------------
  |  Branch (210:17): [True: 2.45k, False: 1.15k]
  ------------------
  211|       |
  212|  3.60k|    if (label_len == 0)
  ------------------
  |  Branch (212:9): [True: 2.66k, False: 941]
  ------------------
  213|  2.66k|        goto cleanup;
  214|       |
  215|    941|    label_capacity = (label_len + 3) / 4 * 4;
  216|    941|    if ((label_buf = readstat_malloc(label_capacity)) == NULL) {
  ------------------
  |  Branch (216:9): [True: 34, False: 907]
  ------------------
  217|     34|        retval = READSTAT_ERROR_MALLOC;
  218|     34|        goto cleanup;
  219|     34|    }
  220|       |
  221|    907|    out_label_len = (size_t)label_len*4+1;
  222|    907|    if ((info->label = readstat_malloc(out_label_len)) == NULL) {
  ------------------
  |  Branch (222:9): [True: 1, False: 906]
  ------------------
  223|      1|        retval = READSTAT_ERROR_MALLOC;
  224|      1|        goto cleanup;
  225|      1|    }
  226|       |
  227|    906|    if (io->read(label_buf, label_capacity, io->io_ctx) < label_capacity) {
  ------------------
  |  Branch (227:9): [True: 22, False: 884]
  ------------------
  228|     22|        retval = READSTAT_ERROR_READ;
  229|     22|        goto cleanup;
  230|     22|    }
  231|       |
  232|    884|    retval = readstat_convert(info->label, out_label_len, label_buf, label_len, ctx->converter);
  233|    884|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (233:9): [True: 1, False: 883]
  ------------------
  234|      1|        goto cleanup;
  235|       |
  236|  3.61k|cleanup:
  237|  3.61k|    if (label_buf)
  ------------------
  |  Branch (237:9): [True: 907, False: 2.70k]
  ------------------
  238|    907|        free(label_buf);
  239|       |
  240|  3.61k|    if (retval != READSTAT_OK) {
  ------------------
  |  Branch (240:9): [True: 63, False: 3.55k]
  ------------------
  241|     63|        if (info->label) {
  ------------------
  |  Branch (241:13): [True: 23, False: 40]
  ------------------
  242|     23|            free(info->label);
  243|     23|            info->label = NULL;
  244|     23|        }
  245|     63|    }
  246|       |
  247|  3.61k|    return retval;
  248|    884|}
readstat_sav_read.c:sav_read_variable_missing_values:
  299|  3.91k|static readstat_error_t sav_read_variable_missing_values(spss_varinfo_t *info, sav_ctx_t *ctx) {
  300|  3.91k|    if (info->n_missing_values > 3 || info->n_missing_values < -3) {
  ------------------
  |  Branch (300:9): [True: 2, False: 3.91k]
  |  Branch (300:39): [True: 45, False: 3.86k]
  ------------------
  301|     47|        return READSTAT_ERROR_PARSE;
  302|     47|    }
  303|  3.86k|    if (info->n_missing_values < 0) {
  ------------------
  |  Branch (303:9): [True: 1.27k, False: 2.59k]
  ------------------
  304|  1.27k|        info->missing_range = 1;
  305|  1.27k|        info->n_missing_values = abs(info->n_missing_values);
  306|  2.59k|    } else {
  307|  2.59k|        info->missing_range = 0;
  308|  2.59k|    }
  309|  3.86k|    if (info->type == READSTAT_TYPE_DOUBLE) {
  ------------------
  |  Branch (309:9): [True: 2.72k, False: 1.14k]
  ------------------
  310|  2.72k|        return sav_read_variable_missing_double_values(info, ctx);
  311|  2.72k|    }
  312|  1.14k|    return sav_read_variable_missing_string_values(info, ctx);
  313|  3.86k|}
readstat_sav_read.c:sav_read_variable_missing_double_values:
  250|  2.72k|static readstat_error_t sav_read_variable_missing_double_values(spss_varinfo_t *info, sav_ctx_t *ctx) {
  251|  2.72k|    readstat_io_t *io = ctx->io;
  252|  2.72k|    int i;
  253|  2.72k|    readstat_error_t retval = READSTAT_OK;
  254|  2.72k|    if (io->read(info->missing_double_values, info->n_missing_values * sizeof(double), io->io_ctx)
  ------------------
  |  Branch (254:9): [True: 8, False: 2.71k]
  ------------------
  255|  2.72k|            < info->n_missing_values * sizeof(double)) {
  256|      8|        retval = READSTAT_ERROR_READ;
  257|      8|        goto cleanup;
  258|      8|    }
  259|  9.66k|    for (i=0; i<info->n_missing_values; i++) {
  ------------------
  |  Branch (259:15): [True: 6.95k, False: 2.71k]
  ------------------
  260|  6.95k|        if (ctx->bswap) {
  ------------------
  |  Branch (260:13): [True: 4.99k, False: 1.95k]
  ------------------
  261|  4.99k|            info->missing_double_values[i] = byteswap_double(info->missing_double_values[i]);
  262|  4.99k|        }
  263|       |
  264|  6.95k|        uint64_t long_value = 0;
  265|  6.95k|        memcpy(&long_value, &info->missing_double_values[i], 8);
  266|       |
  267|  6.95k|        if (long_value == ctx->missing_double)
  ------------------
  |  Branch (267:13): [True: 204, False: 6.74k]
  ------------------
  268|    204|            info->missing_double_values[i] = NAN;
  269|  6.95k|        if (long_value == ctx->lowest_double)
  ------------------
  |  Branch (269:13): [True: 265, False: 6.68k]
  ------------------
  270|    265|            info->missing_double_values[i] = -HUGE_VAL;
  271|  6.95k|        if (long_value == ctx->highest_double)
  ------------------
  |  Branch (271:13): [True: 268, False: 6.68k]
  ------------------
  272|    268|            info->missing_double_values[i] = HUGE_VAL;
  273|  6.95k|    }
  274|       |
  275|  2.72k|cleanup:
  276|  2.72k|    return retval;
  277|  2.71k|}
readstat_sav_read.c:sav_read_variable_missing_string_values:
  279|  1.14k|static readstat_error_t sav_read_variable_missing_string_values(spss_varinfo_t *info, sav_ctx_t *ctx) {
  280|  1.14k|    readstat_io_t *io = ctx->io;
  281|  1.14k|    int i;
  282|  1.14k|    readstat_error_t retval = READSTAT_OK;
  283|  3.49k|    for (i=0; i<info->n_missing_values; i++) {
  ------------------
  |  Branch (283:15): [True: 2.35k, False: 1.13k]
  ------------------
  284|  2.35k|        char missing_value[8];
  285|  2.35k|        if (io->read(missing_value, sizeof(missing_value), io->io_ctx) < sizeof(missing_value)) {
  ------------------
  |  Branch (285:13): [True: 6, False: 2.35k]
  ------------------
  286|      6|            retval = READSTAT_ERROR_READ;
  287|      6|            goto cleanup;
  288|      6|        }
  289|  2.35k|        retval = readstat_convert(info->missing_string_values[i], sizeof(info->missing_string_values[0]),
  290|  2.35k|                missing_value, sizeof(missing_value), ctx->converter);
  291|  2.35k|        if (retval != READSTAT_OK)
  ------------------
  |  Branch (291:13): [True: 1, False: 2.35k]
  ------------------
  292|      1|            goto cleanup;
  293|  2.35k|    }
  294|       |
  295|  1.14k|cleanup:
  296|  1.14k|    return retval;
  297|  1.14k|}
readstat_sav_read.c:sav_read_value_label_record:
  480|  34.5k|static readstat_error_t sav_read_value_label_record(sav_ctx_t *ctx) {
  481|  34.5k|    uint32_t label_count;
  482|  34.5k|    readstat_error_t retval = READSTAT_OK;
  483|  34.5k|    readstat_io_t *io = ctx->io;
  484|  34.5k|    uint32_t *vars = NULL;
  485|  34.5k|    uint32_t var_count;
  486|  34.5k|    int32_t rec_type;
  487|  34.5k|    readstat_type_t value_type = READSTAT_TYPE_STRING;
  488|  34.5k|    char label_buf[256];
  489|  34.5k|    value_label_t *value_labels = NULL;
  490|       |
  491|  34.5k|    if (io->read(&label_count, sizeof(uint32_t), io->io_ctx) < sizeof(uint32_t)) {
  ------------------
  |  Branch (491:9): [True: 3, False: 34.5k]
  ------------------
  492|      3|        retval = READSTAT_ERROR_READ;
  493|      3|        goto cleanup;
  494|      3|    }
  495|  34.5k|    if (ctx->bswap)
  ------------------
  |  Branch (495:9): [True: 33.4k, False: 1.05k]
  ------------------
  496|  33.4k|        label_count = byteswap4(label_count);
  497|       |    
  498|  34.5k|    if (label_count && (value_labels = readstat_calloc(label_count, sizeof(value_label_t))) == NULL) {
  ------------------
  |  Branch (498:9): [True: 2.49k, False: 32.0k]
  |  Branch (498:24): [True: 23, False: 2.47k]
  ------------------
  499|     23|        retval = READSTAT_ERROR_MALLOC;
  500|     23|        goto cleanup;
  501|     23|    }
  502|       |    
  503|  34.5k|    int i;
  504|   106k|    for (i=0; i<label_count; i++) {
  ------------------
  |  Branch (504:15): [True: 72.0k, False: 34.4k]
  ------------------
  505|  72.0k|        value_label_t *vlabel = &value_labels[i];
  506|  72.0k|        unsigned char unpadded_label_len = 0;
  507|  72.0k|        size_t padded_label_len = 0, utf8_label_len = 0;
  508|       |
  509|  72.0k|        if (io->read(vlabel->raw_value, 8, io->io_ctx) < 8) {
  ------------------
  |  Branch (509:13): [True: 24, False: 72.0k]
  ------------------
  510|     24|            retval = READSTAT_ERROR_READ;
  511|     24|            goto cleanup;
  512|     24|        }
  513|  72.0k|        if (io->read(&unpadded_label_len, 1, io->io_ctx) < 1) {
  ------------------
  |  Branch (513:13): [True: 1, False: 72.0k]
  ------------------
  514|      1|            retval = READSTAT_ERROR_READ;
  515|      1|            goto cleanup;
  516|      1|        }
  517|       |
  518|  72.0k|        padded_label_len = (unpadded_label_len + 8) / 8 * 8 - 1;
  519|  72.0k|        if (io->read(label_buf, padded_label_len, io->io_ctx) < padded_label_len) {
  ------------------
  |  Branch (519:13): [True: 2, False: 72.0k]
  ------------------
  520|      2|            retval = READSTAT_ERROR_READ;
  521|      2|            goto cleanup;
  522|      2|        }
  523|       |
  524|  72.0k|        utf8_label_len = padded_label_len*4+1;
  525|  72.0k|        if ((vlabel->label = readstat_malloc(utf8_label_len)) == NULL) {
  ------------------
  |  Branch (525:13): [True: 0, False: 72.0k]
  ------------------
  526|      0|            retval = READSTAT_ERROR_MALLOC;
  527|      0|            goto cleanup;
  528|      0|        }
  529|       |
  530|  72.0k|        retval = readstat_convert(vlabel->label, utf8_label_len, label_buf, padded_label_len, ctx->converter);
  531|  72.0k|        if (retval != READSTAT_OK)
  ------------------
  |  Branch (531:13): [True: 1, False: 72.0k]
  ------------------
  532|      1|            goto cleanup;
  533|  72.0k|    }
  534|       |
  535|  34.4k|    if (io->read(&rec_type, sizeof(int32_t), io->io_ctx) < sizeof(int32_t)) {
  ------------------
  |  Branch (535:9): [True: 3, False: 34.4k]
  ------------------
  536|      3|        retval = READSTAT_ERROR_READ;
  537|      3|        goto cleanup;
  538|      3|    }
  539|  34.4k|    if (ctx->bswap)
  ------------------
  |  Branch (539:9): [True: 33.4k, False: 1.00k]
  ------------------
  540|  33.4k|        rec_type = byteswap4(rec_type);
  541|       |    
  542|  34.4k|    if (rec_type != 4) {
  ------------------
  |  Branch (542:9): [True: 41, False: 34.4k]
  ------------------
  543|     41|        retval = READSTAT_ERROR_PARSE;
  544|     41|        goto cleanup;
  545|     41|    }
  546|  34.4k|    if (io->read(&var_count, sizeof(uint32_t), io->io_ctx) < sizeof(uint32_t)) {
  ------------------
  |  Branch (546:9): [True: 3, False: 34.4k]
  ------------------
  547|      3|        retval = READSTAT_ERROR_READ;
  548|      3|        goto cleanup;
  549|      3|    }
  550|  34.4k|    if (ctx->bswap)
  ------------------
  |  Branch (550:9): [True: 33.4k, False: 995]
  ------------------
  551|  33.4k|        var_count = byteswap4(var_count);
  552|       |    
  553|  34.4k|    if (var_count && (vars = readstat_malloc(var_count * sizeof(uint32_t))) == NULL) {
  ------------------
  |  Branch (553:9): [True: 7.11k, False: 27.3k]
  |  Branch (553:22): [True: 32, False: 7.08k]
  ------------------
  554|     32|        retval = READSTAT_ERROR_MALLOC;
  555|     32|        goto cleanup;
  556|     32|    }
  557|  34.3k|    if (io->read(vars, var_count * sizeof(uint32_t), io->io_ctx) < var_count * sizeof(uint32_t)) {
  ------------------
  |  Branch (557:9): [True: 25, False: 34.3k]
  ------------------
  558|     25|        retval = READSTAT_ERROR_READ;
  559|     25|        goto cleanup;
  560|     25|    }
  561|   126k|    for (i=0; i<var_count; i++) {
  ------------------
  |  Branch (561:15): [True: 92.2k, False: 34.3k]
  ------------------
  562|  92.2k|        uint32_t var_offset = vars[i];
  563|  92.2k|        if (ctx->bswap)
  ------------------
  |  Branch (563:13): [True: 21.0k, False: 71.2k]
  ------------------
  564|  21.0k|            var_offset = byteswap4(var_offset);
  565|       |
  566|  92.2k|        var_offset--; // Why subtract 1????
  567|  92.2k|        spss_varinfo_t **var = bsearch(&var_offset, ctx->varinfo, ctx->var_index, sizeof(spss_varinfo_t *),
  568|  92.2k|                &spss_varinfo_compare);
  569|  92.2k|        if (var) {
  ------------------
  |  Branch (569:13): [True: 17.7k, False: 74.5k]
  ------------------
  570|  17.7k|            (*var)->labels_index = ctx->value_labels_count;
  571|  17.7k|            value_type = (*var)->type;
  572|  17.7k|        }
  573|  92.2k|    }
  574|       |
  575|   106k|    for (i=0; i<label_count; i++) {
  ------------------
  |  Branch (575:15): [True: 72.0k, False: 34.3k]
  ------------------
  576|  72.0k|        value_label_t *vlabel = &value_labels[i];
  577|  72.0k|        double val_d = 0.0;
  578|  72.0k|        vlabel->final_value.type = value_type;
  579|  72.0k|        if (value_type == READSTAT_TYPE_DOUBLE) {
  ------------------
  |  Branch (579:13): [True: 6.84k, False: 65.1k]
  ------------------
  580|  6.84k|            memcpy(&val_d, vlabel->raw_value, 8);
  581|  6.84k|            if (ctx->bswap)
  ------------------
  |  Branch (581:17): [True: 6.19k, False: 651]
  ------------------
  582|  6.19k|                val_d = byteswap_double(val_d);
  583|       |
  584|  6.84k|            vlabel->final_value.v.double_value = val_d;
  585|  6.84k|            sav_tag_missing_double(&vlabel->final_value, ctx);
  586|  65.1k|        } else {
  587|  65.1k|            retval = readstat_convert(vlabel->utf8_string_value, sizeof(vlabel->utf8_string_value),
  588|  65.1k|                    vlabel->raw_value, 8, ctx->converter);
  589|  65.1k|            if (retval != READSTAT_OK)
  ------------------
  |  Branch (589:17): [True: 1, False: 65.1k]
  ------------------
  590|      1|                break;
  591|       |
  592|  65.1k|            vlabel->final_value.v.string_value = vlabel->utf8_string_value;
  593|  65.1k|        }
  594|  72.0k|    }
  595|       |
  596|  34.3k|    if (ctx->handle.value_label) {
  ------------------
  |  Branch (596:9): [True: 34.3k, False: 0]
  ------------------
  597|  34.3k|        sav_submit_value_labels(value_labels, label_count, value_type, ctx);
  598|  34.3k|    }
  599|  34.3k|    ctx->value_labels_count++;
  600|  34.5k|cleanup:
  601|  34.5k|    if (vars)
  ------------------
  |  Branch (601:9): [True: 7.08k, False: 27.4k]
  ------------------
  602|  7.08k|        free(vars);
  603|  34.5k|    if (value_labels) {
  ------------------
  |  Branch (603:9): [True: 2.47k, False: 32.0k]
  ------------------
  604|  5.31M|        for (i=0; i<label_count; i++) {
  ------------------
  |  Branch (604:19): [True: 5.30M, False: 2.47k]
  ------------------
  605|  5.30M|            value_label_t *vlabel = &value_labels[i];
  606|  5.30M|            if (vlabel->label)
  ------------------
  |  Branch (606:17): [True: 72.0k, False: 5.23M]
  ------------------
  607|  72.0k|                free(vlabel->label);
  608|  5.30M|        }
  609|  2.47k|        free(value_labels);
  610|  2.47k|    }
  611|       |    
  612|  34.5k|    return retval;
  613|  34.3k|}
readstat_sav_read.c:sav_tag_missing_double:
  149|  1.19M|static void sav_tag_missing_double(readstat_value_t *value, sav_ctx_t *ctx) {
  150|  1.19M|    double fp_value = value->v.double_value;
  151|  1.19M|    uint64_t long_value = 0;
  152|  1.19M|    memcpy(&long_value, &fp_value, 8);
  153|  1.19M|    if (long_value == ctx->missing_double)
  ------------------
  |  Branch (153:9): [True: 64.0k, False: 1.13M]
  ------------------
  154|  64.0k|        value->is_system_missing = 1;
  155|  1.19M|    if (long_value == ctx->lowest_double)
  ------------------
  |  Branch (155:9): [True: 518, False: 1.19M]
  ------------------
  156|    518|        value->is_system_missing = 1;
  157|  1.19M|    if (long_value == ctx->highest_double)
  ------------------
  |  Branch (157:9): [True: 1.12k, False: 1.19M]
  ------------------
  158|  1.12k|        value->is_system_missing = 1;
  159|  1.19M|    if (isnan(fp_value))
  160|    671|        value->is_system_missing = 1;
  161|  1.19M|}
readstat_sav_read.c:sav_submit_value_labels:
  462|  34.3k|        readstat_type_t value_type, sav_ctx_t *ctx) {
  463|  34.3k|    char label_name_buf[256];
  464|  34.3k|    readstat_error_t retval = READSTAT_OK;
  465|  34.3k|    int32_t i;
  466|       |
  467|  34.3k|    snprintf(label_name_buf, sizeof(label_name_buf), SAV_LABEL_NAME_PREFIX "%d", ctx->value_labels_count);
  ------------------
  |  |  115|  34.3k|#define SAV_LABEL_NAME_PREFIX         "labels"
  ------------------
  468|       |
  469|   106k|    for (i=0; i<label_count; i++) {
  ------------------
  |  Branch (469:15): [True: 72.0k, False: 34.3k]
  ------------------
  470|  72.0k|        value_label_t *vlabel = &value_labels[i];
  471|  72.0k|        if (ctx->handle.value_label(label_name_buf, vlabel->final_value, vlabel->label, ctx->user_ctx) != READSTAT_HANDLER_OK) {
  ------------------
  |  Branch (471:13): [True: 0, False: 72.0k]
  ------------------
  472|      0|            retval = READSTAT_ERROR_USER_ABORT;
  473|      0|            goto cleanup;
  474|      0|        }
  475|  72.0k|    }
  476|  34.3k|cleanup:
  477|  34.3k|    return retval;
  478|  34.3k|}
readstat_sav_read.c:sav_read_document_record:
  634|  1.10k|static readstat_error_t sav_read_document_record(sav_ctx_t *ctx) {
  635|  1.10k|    if (!ctx->handle.note)
  ------------------
  |  Branch (635:9): [True: 0, False: 1.10k]
  ------------------
  636|      0|        return sav_skip_document_record(ctx);
  637|       |
  638|  1.10k|    uint32_t n_lines;
  639|  1.10k|    readstat_error_t retval = READSTAT_OK;
  640|  1.10k|    readstat_io_t *io = ctx->io;
  641|  1.10k|    if (io->read(&n_lines, sizeof(uint32_t), io->io_ctx) < sizeof(uint32_t)) {
  ------------------
  |  Branch (641:9): [True: 4, False: 1.10k]
  ------------------
  642|      4|        retval = READSTAT_ERROR_READ;
  643|      4|        goto cleanup;
  644|      4|    }
  645|  1.10k|    if (ctx->bswap)
  ------------------
  |  Branch (645:9): [True: 633, False: 467]
  ------------------
  646|    633|        n_lines = byteswap4(n_lines);
  647|       |
  648|  1.10k|    char raw_buffer[SPSS_DOC_LINE_SIZE];
  649|  1.10k|    char utf8_buffer[4*SPSS_DOC_LINE_SIZE+1];
  650|  1.10k|    int i;
  651|  1.48k|    for (i=0; i<n_lines; i++) {
  ------------------
  |  Branch (651:15): [True: 449, False: 1.03k]
  ------------------
  652|    449|        if (io->read(raw_buffer, SPSS_DOC_LINE_SIZE, io->io_ctx) < SPSS_DOC_LINE_SIZE) {
  ------------------
  |  |   40|    449|#define SPSS_DOC_LINE_SIZE  80
  ------------------
                      if (io->read(raw_buffer, SPSS_DOC_LINE_SIZE, io->io_ctx) < SPSS_DOC_LINE_SIZE) {
  ------------------
  |  |   40|    449|#define SPSS_DOC_LINE_SIZE  80
  ------------------
  |  Branch (652:13): [True: 60, False: 389]
  ------------------
  653|     60|            retval = READSTAT_ERROR_READ;
  654|     60|            goto cleanup;
  655|     60|        }
  656|       |
  657|    389|        retval = readstat_convert(utf8_buffer, sizeof(utf8_buffer),
  658|    389|                raw_buffer, sizeof(raw_buffer), ctx->converter);
  659|    389|        if (retval != READSTAT_OK)
  ------------------
  |  Branch (659:13): [True: 1, False: 388]
  ------------------
  660|      1|            goto cleanup;
  661|       |
  662|    388|        if (ctx->handle.note(i, utf8_buffer, ctx->user_ctx) != READSTAT_HANDLER_OK) {
  ------------------
  |  Branch (662:13): [True: 0, False: 388]
  ------------------
  663|      0|            retval = READSTAT_ERROR_USER_ABORT;
  664|      0|            goto cleanup;
  665|      0|        }
  666|    388|    }
  667|       |
  668|  1.10k|cleanup:
  669|  1.10k|    return retval;
  670|  1.10k|}
readstat_sav_read.c:sav_read_dictionary_termination_record:
  672|  2.64k|static readstat_error_t sav_read_dictionary_termination_record(sav_ctx_t *ctx) {
  673|  2.64k|    int32_t filler;
  674|  2.64k|    readstat_error_t retval = READSTAT_OK;
  675|  2.64k|    readstat_io_t *io = ctx->io;
  676|  2.64k|    if (io->read(&filler, sizeof(int32_t), io->io_ctx) < sizeof(int32_t)) {
  ------------------
  |  Branch (676:9): [True: 1.13k, False: 1.51k]
  ------------------
  677|  1.13k|        retval = READSTAT_ERROR_READ;
  678|  1.13k|    }
  679|  2.64k|    return retval;
  680|  2.64k|}
readstat_sav_read.c:sav_parse_machine_floating_point_record:
  967|    472|static readstat_error_t sav_parse_machine_floating_point_record(const void *data, size_t size, size_t count, sav_ctx_t *ctx) {
  968|    472|    if (size != 8 || count != 3)
  ------------------
  |  Branch (968:9): [True: 21, False: 451]
  |  Branch (968:22): [True: 17, False: 434]
  ------------------
  969|     38|        return READSTAT_ERROR_PARSE;
  970|       |
  971|    434|    sav_machine_floating_point_info_record_t fp_info;
  972|    434|    memcpy(&fp_info, data, sizeof(sav_machine_floating_point_info_record_t));
  973|       |
  974|    434|    ctx->missing_double = ctx->bswap ? byteswap8(fp_info.sysmis) : fp_info.sysmis;
  ------------------
  |  Branch (974:27): [True: 203, False: 231]
  ------------------
  975|    434|    ctx->highest_double = ctx->bswap ? byteswap8(fp_info.highest) : fp_info.highest;
  ------------------
  |  Branch (975:27): [True: 203, False: 231]
  ------------------
  976|    434|    ctx->lowest_double = ctx->bswap ? byteswap8(fp_info.lowest) : fp_info.lowest;
  ------------------
  |  Branch (976:26): [True: 203, False: 231]
  ------------------
  977|       |
  978|    434|    return READSTAT_OK;
  979|    472|}
readstat_sav_read.c:sav_store_variable_display_parameter_record:
  983|    454|static readstat_error_t sav_store_variable_display_parameter_record(const void *data, size_t size, size_t count, sav_ctx_t *ctx) {
  984|    454|    if (size != 4)
  ------------------
  |  Branch (984:9): [True: 9, False: 445]
  ------------------
  985|      9|        return READSTAT_ERROR_PARSE;
  986|       |
  987|    445|    const uint32_t *data_ptr = data;
  988|    445|    int i;
  989|       |
  990|    445|    ctx->variable_display_values = readstat_realloc(ctx->variable_display_values, count * sizeof(uint32_t));
  991|    445|    if (count > 0 && ctx->variable_display_values == NULL)
  ------------------
  |  Branch (991:9): [True: 445, False: 0]
  |  Branch (991:22): [True: 0, False: 445]
  ------------------
  992|      0|        return READSTAT_ERROR_MALLOC;
  993|       |
  994|    445|    ctx->variable_display_values_count = count;
  995|   984k|    for (i=0; i<count; i++) {
  ------------------
  |  Branch (995:15): [True: 983k, False: 445]
  ------------------
  996|   983k|        ctx->variable_display_values[i] = ctx->bswap ? byteswap4(data_ptr[i]) : data_ptr[i];
  ------------------
  |  Branch (996:43): [True: 265k, False: 718k]
  ------------------
  997|   983k|    }
  998|    445|    return READSTAT_OK;
  999|    445|}
readstat_sav_read.c:sav_parse_long_string_value_labels_record:
 1061|    731|static readstat_error_t sav_parse_long_string_value_labels_record(const void *data, size_t size, size_t count, sav_ctx_t *ctx) {
 1062|    731|    if (!ctx->handle.value_label)
  ------------------
  |  Branch (1062:9): [True: 0, False: 731]
  ------------------
 1063|      0|        return READSTAT_OK;
 1064|    731|    if (size != 1)
  ------------------
  |  Branch (1064:9): [True: 17, False: 714]
  ------------------
 1065|     17|        return READSTAT_ERROR_PARSE;
 1066|       |
 1067|    714|    readstat_error_t retval = READSTAT_OK;
 1068|    714|    uint32_t label_count = 0;
 1069|    714|    uint32_t i = 0;
 1070|    714|    const char *data_ptr = data;
 1071|    714|    const char *data_end = data_ptr + count;
 1072|    714|    char var_name_buf[256+1]; // unconverted
 1073|    714|    char label_name_buf[256];
 1074|    714|    char *value_buffer = NULL;
 1075|    714|    char *label_buffer = NULL;
 1076|       |    
 1077|  2.72k|    while (data_ptr < data_end) {
  ------------------
  |  Branch (1077:12): [True: 2.26k, False: 466]
  ------------------
 1078|  2.26k|        memset(label_name_buf, '\0', sizeof(label_name_buf));
 1079|       |
 1080|  2.26k|        retval = sav_read_pascal_string(var_name_buf, sizeof(var_name_buf),
 1081|  2.26k|                &data_ptr, data_end - data_ptr, ctx);
 1082|  2.26k|        if (retval != READSTAT_OK)
  ------------------
  |  Branch (1082:13): [True: 43, False: 2.22k]
  ------------------
 1083|     43|            goto cleanup;
 1084|       |
 1085|  19.2k|        for (i=0; i<ctx->var_index;) {
  ------------------
  |  Branch (1085:19): [True: 19.1k, False: 95]
  ------------------
 1086|  19.1k|            spss_varinfo_t *info = ctx->varinfo[i];
 1087|  19.1k|            if (strcmp(var_name_buf, info->longname) == 0) {
  ------------------
  |  Branch (1087:17): [True: 2.12k, False: 17.0k]
  ------------------
 1088|  2.12k|                info->labels_index = ctx->value_labels_count++;
 1089|  2.12k|                snprintf(label_name_buf, sizeof(label_name_buf),
 1090|  2.12k|                        SAV_LABEL_NAME_PREFIX "%d", info->labels_index);
  ------------------
  |  |  115|  2.12k|#define SAV_LABEL_NAME_PREFIX         "labels"
  ------------------
 1091|  2.12k|                break;
 1092|  2.12k|            }
 1093|  17.0k|            i += info->n_segments;
 1094|  17.0k|        }
 1095|       |
 1096|  2.22k|        if (label_name_buf[0] == '\0') {
  ------------------
  |  Branch (1096:13): [True: 95, False: 2.12k]
  ------------------
 1097|     95|            retval = READSTAT_ERROR_PARSE;
 1098|     95|            goto cleanup;
 1099|     95|        }
 1100|       |
 1101|  2.12k|        data_ptr += sizeof(uint32_t);
 1102|       |
 1103|  2.12k|        if (data_ptr + sizeof(uint32_t) > data_end) {
  ------------------
  |  Branch (1103:13): [True: 19, False: 2.10k]
  ------------------
 1104|     19|            retval = READSTAT_ERROR_PARSE;
 1105|     19|            goto cleanup;
 1106|     19|        }
 1107|       |
 1108|  2.10k|        memcpy(&label_count, data_ptr, sizeof(uint32_t));
 1109|  2.10k|        if (ctx->bswap)
  ------------------
  |  Branch (1109:13): [True: 856, False: 1.25k]
  ------------------
 1110|    856|            label_count = byteswap4(label_count);
 1111|       |
 1112|  2.10k|        data_ptr += sizeof(uint32_t);
 1113|       |
 1114|  3.37k|        for (i=0; i<label_count; i++) {
  ------------------
  |  Branch (1114:19): [True: 1.35k, False: 2.01k]
  ------------------
 1115|  1.35k|            uint32_t value_len = 0, label_len = 0;
 1116|  1.35k|            uint32_t value_buffer_len = 0, label_buffer_len = 0;
 1117|       |
 1118|  1.35k|            if (data_ptr + sizeof(uint32_t) > data_end) {
  ------------------
  |  Branch (1118:17): [True: 58, False: 1.30k]
  ------------------
 1119|     58|                retval = READSTAT_ERROR_PARSE;
 1120|     58|                goto cleanup;
 1121|     58|            }
 1122|       |
 1123|  1.30k|            memcpy(&value_len, data_ptr, sizeof(uint32_t));
 1124|  1.30k|            if (ctx->bswap)
  ------------------
  |  Branch (1124:17): [True: 744, False: 556]
  ------------------
 1125|    744|                value_len = byteswap4(value_len);
 1126|       |
 1127|  1.30k|            data_ptr += sizeof(uint32_t);
 1128|       |
 1129|  1.30k|            value_buffer_len = value_len*4+1;
 1130|  1.30k|            value_buffer = readstat_realloc(value_buffer, value_buffer_len);
 1131|  1.30k|            if (value_buffer == NULL) {
  ------------------
  |  Branch (1131:17): [True: 11, False: 1.28k]
  ------------------
 1132|     11|                retval = READSTAT_ERROR_MALLOC;
 1133|     11|                goto cleanup;
 1134|     11|            }
 1135|       |
 1136|  1.28k|            if (data_ptr + value_len > data_end) {
  ------------------
  |  Branch (1136:17): [True: 4, False: 1.28k]
  ------------------
 1137|      4|                retval = READSTAT_ERROR_PARSE;
 1138|      4|                goto cleanup;
 1139|      4|            }
 1140|       |
 1141|  1.28k|            retval = readstat_convert(value_buffer, value_buffer_len, data_ptr, value_len, ctx->converter);
 1142|  1.28k|            if (retval != READSTAT_OK)
  ------------------
  |  Branch (1142:17): [True: 1, False: 1.28k]
  ------------------
 1143|      1|                goto cleanup;
 1144|       |
 1145|  1.28k|            data_ptr += value_len;
 1146|       |
 1147|  1.28k|            if (data_ptr + sizeof(uint32_t) > data_end) {
  ------------------
  |  Branch (1147:17): [True: 5, False: 1.27k]
  ------------------
 1148|      5|                retval = READSTAT_ERROR_PARSE;
 1149|      5|                goto cleanup;
 1150|      5|            }
 1151|       |
 1152|  1.27k|            memcpy(&label_len, data_ptr, sizeof(uint32_t));
 1153|  1.27k|            if (ctx->bswap)
  ------------------
  |  Branch (1153:17): [True: 737, False: 542]
  ------------------
 1154|    737|                label_len = byteswap4(label_len);
 1155|       |
 1156|  1.27k|            data_ptr += sizeof(uint32_t);
 1157|       |
 1158|  1.27k|            label_buffer_len = label_len*4+1;
 1159|  1.27k|            label_buffer = readstat_realloc(label_buffer, label_buffer_len);
 1160|  1.27k|            if (label_buffer == NULL) {
  ------------------
  |  Branch (1160:17): [True: 6, False: 1.27k]
  ------------------
 1161|      6|                retval = READSTAT_ERROR_MALLOC;
 1162|      6|                goto cleanup;
 1163|      6|            }
 1164|       |
 1165|  1.27k|            if (data_ptr + label_len > data_end) {
  ------------------
  |  Branch (1165:17): [True: 5, False: 1.26k]
  ------------------
 1166|      5|                retval = READSTAT_ERROR_PARSE;
 1167|      5|                goto cleanup;
 1168|      5|            }
 1169|       |
 1170|  1.26k|            retval = readstat_convert(label_buffer, label_buffer_len, data_ptr, label_len, ctx->converter);
 1171|  1.26k|            if (retval != READSTAT_OK)
  ------------------
  |  Branch (1171:17): [True: 1, False: 1.26k]
  ------------------
 1172|      1|                goto cleanup;
 1173|       |
 1174|  1.26k|            data_ptr += label_len;
 1175|       |
 1176|  1.26k|            readstat_value_t value = { .type = READSTAT_TYPE_STRING };
 1177|  1.26k|            value.v.string_value = value_buffer;
 1178|       |
 1179|  1.26k|            if (ctx->handle.value_label(label_name_buf, value, label_buffer, ctx->user_ctx) != READSTAT_HANDLER_OK) {
  ------------------
  |  Branch (1179:17): [True: 0, False: 1.26k]
  ------------------
 1180|      0|                retval = READSTAT_ERROR_USER_ABORT;
 1181|      0|                goto cleanup;
 1182|      0|            }
 1183|  1.26k|        }
 1184|  2.10k|    }
 1185|       |
 1186|    466|    if (data_ptr != data_end) {
  ------------------
  |  Branch (1186:9): [True: 0, False: 466]
  ------------------
 1187|      0|        retval = READSTAT_ERROR_PARSE;
 1188|      0|    }
 1189|       |
 1190|    714|cleanup:
 1191|    714|    if (value_buffer)
  ------------------
  |  Branch (1191:9): [True: 274, False: 440]
  ------------------
 1192|    274|        free(value_buffer);
 1193|    714|    if (label_buffer)
  ------------------
  |  Branch (1193:9): [True: 270, False: 444]
  ------------------
 1194|    270|        free(label_buffer);
 1195|    714|    return retval;
 1196|    466|}
readstat_sav_read.c:sav_read_pascal_string:
 1027|  3.26k|        const char **inout_data_ptr, size_t data_ptr_len, sav_ctx_t *ctx) {
 1028|  3.26k|    const char *data_ptr = *inout_data_ptr;
 1029|  3.26k|    const char *data_end = data_ptr + data_ptr_len;
 1030|  3.26k|    readstat_error_t retval = READSTAT_OK;
 1031|  3.26k|    uint32_t var_name_len = 0;
 1032|       |
 1033|  3.26k|    if (data_ptr + sizeof(uint32_t) > data_end) {
  ------------------
  |  Branch (1033:9): [True: 32, False: 3.23k]
  ------------------
 1034|     32|        retval = READSTAT_ERROR_PARSE;
 1035|     32|        goto cleanup;
 1036|     32|    }
 1037|       |
 1038|  3.23k|    memcpy(&var_name_len, data_ptr, sizeof(uint32_t));
 1039|  3.23k|    if (ctx->bswap)
  ------------------
  |  Branch (1039:9): [True: 1.30k, False: 1.92k]
  ------------------
 1040|  1.30k|        var_name_len = byteswap4(var_name_len);
 1041|       |
 1042|  3.23k|    data_ptr += sizeof(uint32_t);
 1043|       |
 1044|  3.23k|    if (data_ptr + var_name_len > data_end) {
  ------------------
  |  Branch (1044:9): [True: 29, False: 3.20k]
  ------------------
 1045|     29|        retval = READSTAT_ERROR_PARSE;
 1046|     29|        goto cleanup;
 1047|     29|    }
 1048|       |
 1049|  3.20k|    retval = readstat_convert(buf, buf_len, data_ptr, var_name_len, NULL);
 1050|  3.20k|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (1050:9): [True: 18, False: 3.18k]
  ------------------
 1051|     18|        goto cleanup;
 1052|       |
 1053|  3.18k|    data_ptr += var_name_len;
 1054|       |
 1055|  3.26k|cleanup:
 1056|  3.26k|    *inout_data_ptr = data_ptr;
 1057|       |
 1058|  3.26k|    return retval;
 1059|  3.18k|}
readstat_sav_read.c:sav_parse_long_string_missing_values_record:
 1198|    461|static readstat_error_t sav_parse_long_string_missing_values_record(const void *data, size_t size, size_t count, sav_ctx_t *ctx) {
 1199|    461|    if (size != 1)
  ------------------
  |  Branch (1199:9): [True: 14, False: 447]
  ------------------
 1200|     14|        return READSTAT_ERROR_PARSE;
 1201|       |
 1202|    447|    readstat_error_t retval = READSTAT_OK;
 1203|    447|    uint32_t i = 0, j = 0;
 1204|    447|    const char *data_ptr = data;
 1205|    447|    const char *data_end = data_ptr + count;
 1206|    447|    char var_name_buf[256+1];
 1207|       |
 1208|  1.27k|    while (data_ptr < data_end) {
  ------------------
  |  Branch (1208:12): [True: 1.00k, False: 272]
  ------------------
 1209|  1.00k|        retval = sav_read_pascal_string(var_name_buf, sizeof(var_name_buf),
 1210|  1.00k|                &data_ptr, data_end - data_ptr, ctx);
 1211|  1.00k|        if (retval != READSTAT_OK)
  ------------------
  |  Branch (1211:13): [True: 36, False: 969]
  ------------------
 1212|     36|            goto cleanup;
 1213|       |
 1214|    969|        if (data_ptr == data_end) {
  ------------------
  |  Branch (1214:13): [True: 18, False: 951]
  ------------------
 1215|     18|            retval = READSTAT_ERROR_PARSE;
 1216|     18|            goto cleanup;
 1217|     18|        }
 1218|       |
 1219|    951|        char n_missing_values = *data_ptr++;
 1220|    951|        if (n_missing_values < 1 || n_missing_values > 3) {
  ------------------
  |  Branch (1220:13): [True: 13, False: 938]
  |  Branch (1220:37): [True: 13, False: 925]
  ------------------
 1221|     26|            retval = READSTAT_ERROR_PARSE;
 1222|     26|            goto cleanup;
 1223|     26|        }
 1224|       |
 1225|  67.1k|        for (i=0; i<ctx->var_index;) {
  ------------------
  |  Branch (1225:19): [True: 67.1k, False: 81]
  ------------------
 1226|  67.1k|            spss_varinfo_t *info = ctx->varinfo[i];
 1227|  67.1k|            if (strcmp(var_name_buf, info->longname) == 0) {
  ------------------
  |  Branch (1227:17): [True: 844, False: 66.2k]
  ------------------
 1228|    844|                info->n_missing_values = n_missing_values;
 1229|       |
 1230|    844|                uint32_t var_name_len = 0;
 1231|       |
 1232|    844|                if (data_ptr + sizeof(uint32_t) > data_end) {
  ------------------
  |  Branch (1232:21): [True: 4, False: 840]
  ------------------
 1233|      4|                    retval = READSTAT_ERROR_PARSE;
 1234|      4|                    goto cleanup;
 1235|      4|                }
 1236|       |
 1237|    840|                memcpy(&var_name_len, data_ptr, sizeof(uint32_t));
 1238|    840|                if (ctx->bswap)
  ------------------
  |  Branch (1238:21): [True: 351, False: 489]
  ------------------
 1239|    351|                    var_name_len = byteswap4(var_name_len);
 1240|       |
 1241|    840|                data_ptr += sizeof(uint32_t);
 1242|       |
 1243|  3.04k|                for (j=0; j<n_missing_values; j++) {
  ------------------
  |  Branch (1243:27): [True: 2.21k, False: 830]
  ------------------
 1244|  2.21k|                    if (data_ptr + var_name_len > data_end) {
  ------------------
  |  Branch (1244:25): [True: 6, False: 2.21k]
  ------------------
 1245|      6|                        retval = READSTAT_ERROR_PARSE;
 1246|      6|                        goto cleanup;
 1247|      6|                    }
 1248|       |
 1249|  2.21k|                    retval = readstat_convert(info->missing_string_values[j],
 1250|  2.21k|                            sizeof(info->missing_string_values[0]),
 1251|  2.21k|                            data_ptr, var_name_len, ctx->converter);
 1252|  2.21k|                    if (retval != READSTAT_OK)
  ------------------
  |  Branch (1252:25): [True: 4, False: 2.20k]
  ------------------
 1253|      4|                        goto cleanup;
 1254|       |
 1255|  2.20k|                    data_ptr += var_name_len;
 1256|  2.20k|                }
 1257|    830|                break;
 1258|    840|            }
 1259|  66.2k|            i += info->n_segments;
 1260|  66.2k|        }
 1261|    911|        if (i == ctx->var_index) {
  ------------------
  |  Branch (1261:13): [True: 81, False: 830]
  ------------------
 1262|     81|            retval = READSTAT_ERROR_PARSE;
 1263|     81|            goto cleanup;
 1264|     81|        }
 1265|    911|    }
 1266|       |
 1267|    272|    if (data_ptr != data_end) {
  ------------------
  |  Branch (1267:9): [True: 0, False: 272]
  ------------------
 1268|      0|        retval = READSTAT_ERROR_PARSE;
 1269|      0|    }
 1270|       |
 1271|    447|cleanup:
 1272|    447|    return retval;
 1273|    272|}
readstat_sav_read.c:sav_set_n_segments_and_var_count:
 1477|  1.51k|static readstat_error_t sav_set_n_segments_and_var_count(sav_ctx_t *ctx) {
 1478|  1.51k|    int i;
 1479|  1.51k|    ctx->var_count = 0;
 1480|   202k|    for (i=0; i<ctx->var_index;) {
  ------------------
  |  Branch (1480:15): [True: 200k, False: 1.47k]
  ------------------
 1481|   200k|        spss_varinfo_t *info = ctx->varinfo[i];
 1482|   200k|        if (info->string_length > VERY_LONG_STRING_MAX_LENGTH)
  ------------------
  |  |   28|   200k|#define VERY_LONG_STRING_MAX_LENGTH INT_MAX
  ------------------
  |  Branch (1482:13): [True: 32, False: 200k]
  ------------------
 1483|     32|            return READSTAT_ERROR_PARSE;
 1484|   200k|        if (info->string_length) {
  ------------------
  |  Branch (1484:13): [True: 382, False: 200k]
  ------------------
 1485|    382|            info->n_segments = (info->string_length + 251) / 252;
 1486|    382|        }
 1487|   200k|        info->index = ctx->var_count++;
 1488|   200k|        i += info->n_segments;
 1489|   200k|    }
 1490|  1.47k|    ctx->variables = readstat_calloc(ctx->var_count, sizeof(readstat_variable_t *));
 1491|  1.47k|    return READSTAT_OK;
 1492|  1.51k|}
readstat_sav_read.c:sav_parse_variable_display_parameter_record:
 1001|  1.47k|static readstat_error_t sav_parse_variable_display_parameter_record(sav_ctx_t *ctx) {
 1002|  1.47k|    if (!ctx->variable_display_values)
  ------------------
  |  Branch (1002:9): [True: 1.29k, False: 180]
  ------------------
 1003|  1.29k|        return READSTAT_OK;
 1004|       |
 1005|    180|    int i;
 1006|    180|    long count = ctx->variable_display_values_count;
 1007|    180|    if (count != 2 * ctx->var_index && count != 3 * ctx->var_index) {
  ------------------
  |  Branch (1007:9): [True: 53, False: 127]
  |  Branch (1007:40): [True: 36, False: 17]
  ------------------
 1008|     36|        return READSTAT_ERROR_PARSE;
 1009|     36|    }
 1010|    144|    int has_display_width = ctx->var_index > 0 && (count / ctx->var_index == 3);
  ------------------
  |  Branch (1010:29): [True: 144, False: 0]
  |  Branch (1010:51): [True: 17, False: 127]
  ------------------
 1011|    144|    int offset = 0;
 1012|  5.80k|    for (i=0; i<ctx->var_index;) {
  ------------------
  |  Branch (1012:15): [True: 5.66k, False: 144]
  ------------------
 1013|  5.66k|        spss_varinfo_t *info = ctx->varinfo[i];
 1014|  5.66k|        offset = (2 + has_display_width)*i;
 1015|  5.66k|        info->measure = spss_measure_to_readstat_measure(ctx->variable_display_values[offset++]);
 1016|  5.66k|        if (has_display_width) {
  ------------------
  |  Branch (1016:13): [True: 614, False: 5.04k]
  ------------------
 1017|    614|            info->display_width = ctx->variable_display_values[offset++];
 1018|    614|        }
 1019|  5.66k|        info->alignment = spss_alignment_to_readstat_alignment(ctx->variable_display_values[offset++]);
 1020|       |
 1021|  5.66k|        i += info->n_segments;
 1022|  5.66k|    }
 1023|    144|    return READSTAT_OK;
 1024|    180|}
readstat_sav_read.c:sav_handle_variables:
 1494|  1.43k|static readstat_error_t sav_handle_variables(sav_ctx_t *ctx) {
 1495|  1.43k|    int i;
 1496|  1.43k|    int index_after_skipping = 0;
 1497|  1.43k|    readstat_error_t retval = READSTAT_OK;
 1498|       |
 1499|  1.43k|    if (!ctx->handle.variable)
  ------------------
  |  Branch (1499:9): [True: 0, False: 1.43k]
  ------------------
 1500|      0|        return retval;
 1501|       |
 1502|   202k|    for (i=0; i<ctx->var_index;) {
  ------------------
  |  Branch (1502:15): [True: 200k, False: 1.43k]
  ------------------
 1503|   200k|        char label_name_buf[256];
 1504|   200k|        spss_varinfo_t *info = ctx->varinfo[i];
 1505|   200k|        ctx->variables[info->index] = spss_init_variable_for_info(info, index_after_skipping, ctx->converter);
 1506|       |
 1507|   200k|        snprintf(label_name_buf, sizeof(label_name_buf), SAV_LABEL_NAME_PREFIX "%d", info->labels_index);
  ------------------
  |  |  115|   200k|#define SAV_LABEL_NAME_PREFIX         "labels"
  ------------------
 1508|       |
 1509|   200k|        int cb_retval = ctx->handle.variable(info->index, ctx->variables[info->index],
 1510|   200k|                info->labels_index == -1 ? NULL : label_name_buf,
  ------------------
  |  Branch (1510:17): [True: 200k, False: 246]
  ------------------
 1511|   200k|                ctx->user_ctx);
 1512|       |
 1513|   200k|        if (cb_retval == READSTAT_HANDLER_ABORT) {
  ------------------
  |  Branch (1513:13): [True: 0, False: 200k]
  ------------------
 1514|      0|            retval = READSTAT_ERROR_USER_ABORT;
 1515|      0|            goto cleanup;
 1516|      0|        }
 1517|       |
 1518|   200k|        if (cb_retval == READSTAT_HANDLER_SKIP_VARIABLE) {
  ------------------
  |  Branch (1518:13): [True: 0, False: 200k]
  ------------------
 1519|      0|            ctx->variables[info->index]->skip = 1;
 1520|   200k|        } else {
 1521|   200k|            index_after_skipping++;
 1522|   200k|        }
 1523|       |
 1524|   200k|        i += info->n_segments;
 1525|   200k|    }
 1526|  1.43k|cleanup:
 1527|  1.43k|    return retval;
 1528|  1.43k|}
readstat_sav_read.c:sav_handle_fweight:
 1530|  1.43k|static readstat_error_t sav_handle_fweight(sav_ctx_t *ctx) {
 1531|  1.43k|    readstat_error_t retval = READSTAT_OK;
 1532|  1.43k|    int i;
 1533|  1.43k|    if (ctx->handle.fweight && ctx->fweight_index >= 0) {
  ------------------
  |  Branch (1533:9): [True: 1.43k, False: 0]
  |  Branch (1533:32): [True: 994, False: 441]
  ------------------
 1534|   148k|        for (i=0; i<ctx->var_index;) {
  ------------------
  |  Branch (1534:19): [True: 147k, False: 981]
  ------------------
 1535|   147k|            spss_varinfo_t *info = ctx->varinfo[i];
 1536|   147k|            if (info->offset == ctx->fweight_index - 1) {
  ------------------
  |  Branch (1536:17): [True: 13, False: 147k]
  ------------------
 1537|     13|                if (ctx->handle.fweight(ctx->variables[info->index], ctx->user_ctx) != READSTAT_HANDLER_OK) {
  ------------------
  |  Branch (1537:21): [True: 0, False: 13]
  ------------------
 1538|      0|                    retval = READSTAT_ERROR_USER_ABORT;
 1539|      0|                    goto cleanup;
 1540|      0|                }
 1541|     13|                break;
 1542|     13|            }
 1543|   147k|            i += info->n_segments;
 1544|   147k|        }
 1545|    994|    }
 1546|  1.43k|cleanup:
 1547|  1.43k|    return retval;
 1548|  1.43k|}
readstat_sav_read.c:sav_read_data:
  766|  1.43k|static readstat_error_t sav_read_data(sav_ctx_t *ctx) {
  767|  1.43k|    readstat_error_t retval = READSTAT_OK;
  768|  1.43k|    size_t longest_string = 256;
  769|  1.43k|    int i;
  770|       |
  771|   202k|    for (i=0; i<ctx->var_index;) {
  ------------------
  |  Branch (771:15): [True: 200k, False: 1.43k]
  ------------------
  772|   200k|        spss_varinfo_t *info = ctx->varinfo[i];
  773|   200k|        if (info->string_length > longest_string) {
  ------------------
  |  Branch (773:13): [True: 154, False: 200k]
  ------------------
  774|    154|            longest_string = info->string_length;
  775|    154|        }
  776|   200k|        i += info->n_segments;
  777|   200k|    }
  778|       |
  779|  1.43k|    ctx->raw_string_len = longest_string + sizeof(SAV_EIGHT_SPACES)-2;
  ------------------
  |  |  138|  1.43k|#define SAV_EIGHT_SPACES              "        "
  ------------------
  780|  1.43k|    ctx->raw_string = readstat_malloc(ctx->raw_string_len);
  781|       |
  782|  1.43k|    ctx->utf8_string_len = 4*longest_string+1 + sizeof(SAV_EIGHT_SPACES)-2;
  ------------------
  |  |  138|  1.43k|#define SAV_EIGHT_SPACES              "        "
  ------------------
  783|  1.43k|    ctx->utf8_string = readstat_malloc(ctx->utf8_string_len);
  784|       |
  785|  1.43k|    if (ctx->raw_string == NULL || ctx->utf8_string == NULL) {
  ------------------
  |  Branch (785:9): [True: 20, False: 1.41k]
  |  Branch (785:36): [True: 9, False: 1.40k]
  ------------------
  786|     29|        retval = READSTAT_ERROR_MALLOC;
  787|     29|        goto done;
  788|     29|    }
  789|       |
  790|  1.40k|    if (ctx->compression == READSTAT_COMPRESS_ROWS) {
  ------------------
  |  Branch (790:9): [True: 395, False: 1.01k]
  ------------------
  791|    395|        retval = sav_read_compressed_data(ctx, &sav_process_row);
  792|  1.01k|    } else if (ctx->compression == READSTAT_COMPRESS_BINARY) {
  ------------------
  |  Branch (792:16): [True: 494, False: 517]
  ------------------
  793|    494|#if HAVE_ZLIB
  794|    494|        retval = zsav_read_compressed_data(ctx, &sav_process_row);
  795|       |#else
  796|       |        retval = READSTAT_ERROR_UNSUPPORTED_COMPRESSION;
  797|       |#endif
  798|    517|    } else {
  799|    517|        retval = sav_read_uncompressed_data(ctx, &sav_process_row);
  800|    517|    }
  801|  1.40k|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (801:9): [True: 464, False: 942]
  ------------------
  802|    464|        goto done;
  803|       |
  804|    942|    if (ctx->record_count >= 0 && ctx->current_row != ctx->row_limit) {
  ------------------
  |  Branch (804:9): [True: 708, False: 234]
  |  Branch (804:35): [True: 658, False: 50]
  ------------------
  805|    658|        retval = READSTAT_ERROR_ROW_COUNT_MISMATCH;
  806|    658|    }
  807|       |
  808|  1.43k|done:
  809|  1.43k|    return retval;
  810|    942|}
readstat_sav_read.c:sav_read_compressed_data:
  850|    395|        readstat_error_t (*row_handler)(unsigned char *, size_t, sav_ctx_t *)) {
  851|    395|    readstat_error_t retval = READSTAT_OK;
  852|    395|    readstat_io_t *io = ctx->io;
  853|    395|    readstat_off_t data_offset = 0;
  854|    395|    unsigned char buffer[DATA_BUFFER_SIZE];
  855|    395|    int buffer_used = 0;
  856|       |
  857|    395|    size_t uncompressed_row_len = ctx->var_offset * 8;
  858|    395|    readstat_off_t uncompressed_offset = 0;
  859|    395|    unsigned char *uncompressed_row = NULL;
  860|       |
  861|    395|    struct sav_row_stream_s state = { 
  862|    395|        .missing_value = ctx->missing_double,
  863|    395|        .bias = ctx->bias,
  864|    395|        .bswap = ctx->bswap };
  865|       |
  866|    395|    if (uncompressed_row_len && (uncompressed_row = readstat_malloc(uncompressed_row_len)) == NULL) {
  ------------------
  |  Branch (866:9): [True: 395, False: 0]
  |  Branch (866:33): [True: 0, False: 395]
  ------------------
  867|      0|        retval = READSTAT_ERROR_MALLOC;
  868|      0|        goto done;
  869|      0|    }
  870|       |
  871|    753|    while (1) {
  ------------------
  |  Branch (871:12): [Folded - Ignored]
  ------------------
  872|    753|        retval = sav_update_progress(ctx);
  873|    753|        if (retval != READSTAT_OK)
  ------------------
  |  Branch (873:13): [True: 0, False: 753]
  ------------------
  874|      0|            goto done;
  875|       |
  876|    753|        buffer_used = io->read(buffer, sizeof(buffer), io->io_ctx);
  877|    753|        if (buffer_used == -1 || buffer_used == 0 || (buffer_used % 8) != 0)
  ------------------
  |  Branch (877:13): [True: 0, False: 753]
  |  Branch (877:34): [True: 321, False: 432]
  |  Branch (877:54): [True: 36, False: 396]
  ------------------
  878|    357|            goto done;
  879|       |
  880|    396|        state.status = SAV_ROW_STREAM_HAVE_DATA;
  881|    396|        data_offset = 0;
  882|       |
  883|  2.24M|        while (state.status != SAV_ROW_STREAM_NEED_DATA) {
  ------------------
  |  Branch (883:16): [True: 2.24M, False: 358]
  ------------------
  884|  2.24M|            state.next_in = &buffer[data_offset];
  885|  2.24M|            state.avail_in = buffer_used - data_offset;
  886|       |
  887|  2.24M|            state.next_out = &uncompressed_row[uncompressed_offset];
  888|  2.24M|            state.avail_out = uncompressed_row_len - uncompressed_offset;
  889|       |
  890|  2.24M|            sav_decompress_row(&state);
  891|       |
  892|  2.24M|            uncompressed_offset = uncompressed_row_len - state.avail_out;
  893|  2.24M|            data_offset = buffer_used - state.avail_in;
  894|       |
  895|  2.24M|            if (state.status == SAV_ROW_STREAM_FINISHED_ROW) {
  ------------------
  |  Branch (895:17): [True: 2.24M, False: 375]
  ------------------
  896|  2.24M|                retval = row_handler(uncompressed_row, uncompressed_row_len, ctx);
  897|  2.24M|                if (retval != READSTAT_OK)
  ------------------
  |  Branch (897:21): [True: 14, False: 2.24M]
  ------------------
  898|     14|                    goto done;
  899|       |
  900|  2.24M|                uncompressed_offset = 0;
  901|  2.24M|            }
  902|       |
  903|  2.24M|            if (state.status == SAV_ROW_STREAM_FINISHED_ALL)
  ------------------
  |  Branch (903:17): [True: 17, False: 2.24M]
  ------------------
  904|     17|                goto done;
  905|  2.24M|            if (ctx->row_limit > 0 && ctx->current_row == ctx->row_limit)
  ------------------
  |  Branch (905:17): [True: 232k, False: 2.01M]
  |  Branch (905:39): [True: 7, False: 232k]
  ------------------
  906|      7|                goto done;
  907|  2.24M|        }
  908|    396|    }
  909|       |
  910|    395|done:
  911|    395|    if (uncompressed_row)
  ------------------
  |  Branch (911:9): [True: 395, False: 0]
  ------------------
  912|    395|        free(uncompressed_row);
  913|       |
  914|    395|    return retval;
  915|    395|}
readstat_sav_read.c:sav_process_row:
  682|  2.24M|static readstat_error_t sav_process_row(unsigned char *buffer, size_t buffer_len, sav_ctx_t *ctx) {
  683|  2.24M|    if (ctx->row_offset) {
  ------------------
  |  Branch (683:9): [True: 0, False: 2.24M]
  ------------------
  684|      0|        ctx->row_offset--;
  685|      0|        return READSTAT_OK;
  686|      0|    }
  687|       |
  688|  2.24M|    readstat_error_t retval = READSTAT_OK;
  689|  2.24M|    double fp_value;
  690|  2.24M|    int offset = 0;
  691|  2.24M|    readstat_off_t data_offset = 0;
  692|  2.24M|    size_t raw_str_used = 0;
  693|  2.24M|    int segment_offset = 0;
  694|  2.24M|    int var_index = 0, col = 0;
  695|  2.24M|    int raw_str_is_utf8 = ctx->input_encoding && !strcmp(ctx->input_encoding, "UTF-8");
  ------------------
  |  Branch (695:27): [True: 793, False: 2.24M]
  |  Branch (695:50): [True: 767, False: 26]
  ------------------
  696|       |
  697|  4.52M|    while (data_offset < buffer_len && col < ctx->var_index && var_index < ctx->var_index) {
  ------------------
  |  Branch (697:12): [True: 2.52M, False: 1.99M]
  |  Branch (697:40): [True: 2.27M, False: 248k]
  |  Branch (697:64): [True: 2.27M, False: 0]
  ------------------
  698|  2.27M|        spss_varinfo_t *col_info = ctx->varinfo[col];
  699|  2.27M|        spss_varinfo_t *var_info = ctx->varinfo[var_index];
  700|  2.27M|        readstat_value_t value = { .type = var_info->type };
  701|  2.27M|        if (offset > 31) {
  ------------------
  |  Branch (701:13): [True: 2, False: 2.27M]
  ------------------
  702|      2|            retval = READSTAT_ERROR_PARSE;
  703|      2|            goto done;
  704|      2|        }
  705|  2.27M|        if (var_info->type == READSTAT_TYPE_STRING) {
  ------------------
  |  Branch (705:13): [True: 1.09M, False: 1.18M]
  ------------------
  706|  1.09M|            if (raw_str_used + 8 <= ctx->raw_string_len) {
  ------------------
  |  Branch (706:17): [True: 1.09M, False: 241]
  ------------------
  707|  1.09M|                if (raw_str_is_utf8) {
  ------------------
  |  Branch (707:21): [True: 970, False: 1.08M]
  ------------------
  708|       |                    /* Skip null bytes, see https://github.com/tidyverse/haven/issues/560  */
  709|    970|                    char c;
  710|  8.73k|                    for (int i=0; i<8; i++)
  ------------------
  |  Branch (710:35): [True: 7.76k, False: 970]
  ------------------
  711|  7.76k|                        if ((c = buffer[data_offset+i]))
  ------------------
  |  Branch (711:29): [True: 3.76k, False: 3.99k]
  ------------------
  712|  3.76k|                            ctx->raw_string[raw_str_used++] = c;
  713|  1.08M|                } else {
  714|  1.08M|                    memcpy(ctx->raw_string + raw_str_used, &buffer[data_offset], 8);
  715|  1.08M|                    raw_str_used += 8;
  716|  1.08M|                }
  717|  1.09M|            }
  718|  1.09M|            if (++offset == col_info->width) {
  ------------------
  |  Branch (718:17): [True: 1.08M, False: 1.12k]
  ------------------
  719|  1.08M|                if (++segment_offset < var_info->n_segments) {
  ------------------
  |  Branch (719:21): [True: 590, False: 1.08M]
  ------------------
  720|    590|                    raw_str_used--;
  721|    590|                }
  722|  1.08M|                offset = 0;
  723|  1.08M|                col++;
  724|  1.08M|            }
  725|  1.09M|            if (segment_offset == var_info->n_segments) {
  ------------------
  |  Branch (725:17): [True: 1.08M, False: 1.71k]
  ------------------
  726|  1.08M|                if (!ctx->variables[var_info->index]->skip) {
  ------------------
  |  Branch (726:21): [True: 1.08M, False: 0]
  ------------------
  727|  1.08M|                    retval = readstat_convert(ctx->utf8_string, ctx->utf8_string_len, 
  728|  1.08M|                            ctx->raw_string, raw_str_used, ctx->converter);
  729|  1.08M|                    if (retval != READSTAT_OK)
  ------------------
  |  Branch (729:25): [True: 18, False: 1.08M]
  ------------------
  730|     18|                        goto done;
  731|  1.08M|                    value.v.string_value = ctx->utf8_string;
  732|  1.08M|                    if (ctx->handle.value(ctx->current_row, ctx->variables[var_info->index],
  ------------------
  |  Branch (732:25): [True: 0, False: 1.08M]
  ------------------
  733|  1.08M|                                value, ctx->user_ctx) != READSTAT_HANDLER_OK) {
  734|      0|                        retval = READSTAT_ERROR_USER_ABORT;
  735|      0|                        goto done;
  736|      0|                    }
  737|  1.08M|                }
  738|  1.08M|                raw_str_used = 0;
  739|  1.08M|                segment_offset = 0;
  740|  1.08M|                var_index += var_info->n_segments;
  741|  1.08M|            }
  742|  1.18M|        } else if (var_info->type == READSTAT_TYPE_DOUBLE) {
  ------------------
  |  Branch (742:20): [True: 1.18M, False: 0]
  ------------------
  743|  1.18M|            if (!ctx->variables[var_info->index]->skip) {
  ------------------
  |  Branch (743:17): [True: 1.18M, False: 0]
  ------------------
  744|  1.18M|                memcpy(&fp_value, &buffer[data_offset], 8);
  745|  1.18M|                if (ctx->bswap) {
  ------------------
  |  Branch (745:21): [True: 930k, False: 257k]
  ------------------
  746|   930k|                    fp_value = byteswap_double(fp_value);
  747|   930k|                }
  748|  1.18M|                value.v.double_value = fp_value;
  749|  1.18M|                sav_tag_missing_double(&value, ctx);
  750|  1.18M|                if (ctx->handle.value(ctx->current_row, ctx->variables[var_info->index],
  ------------------
  |  Branch (750:21): [True: 0, False: 1.18M]
  ------------------
  751|  1.18M|                            value, ctx->user_ctx) != READSTAT_HANDLER_OK) {
  752|      0|                    retval = READSTAT_ERROR_USER_ABORT;
  753|      0|                    goto done;
  754|      0|                }
  755|  1.18M|            }
  756|  1.18M|            var_index += var_info->n_segments;
  757|  1.18M|            col++;
  758|  1.18M|        }
  759|  2.27M|        data_offset += 8;
  760|  2.27M|    }
  761|  2.24M|    ctx->current_row++;
  762|  2.24M|done:
  763|  2.24M|    return retval;
  764|  2.24M|}
readstat_sav_read.c:sav_read_uncompressed_data:
  813|    517|        readstat_error_t (*row_handler)(unsigned char *, size_t, sav_ctx_t *)) {
  814|    517|    readstat_error_t retval = READSTAT_OK;
  815|    517|    readstat_io_t *io = ctx->io;
  816|    517|    unsigned char *buffer = NULL;
  817|    517|    size_t bytes_read = 0;
  818|    517|    size_t buffer_len = ctx->var_offset * 8;
  819|       |
  820|    517|    buffer = readstat_malloc(buffer_len);
  821|       |
  822|    517|    if (ctx->row_offset) {
  ------------------
  |  Branch (822:9): [True: 0, False: 517]
  ------------------
  823|      0|        if (io->seek(buffer_len * ctx->row_offset, READSTAT_SEEK_CUR, io->io_ctx) == -1) {
  ------------------
  |  Branch (823:13): [True: 0, False: 0]
  ------------------
  824|      0|            retval = READSTAT_ERROR_SEEK;
  825|      0|            goto done;
  826|      0|        }
  827|      0|        ctx->row_offset = 0;
  828|      0|    }
  829|       |
  830|  1.27k|    while (ctx->row_limit == -1 || ctx->current_row < ctx->row_limit) {
  ------------------
  |  Branch (830:12): [True: 0, False: 1.27k]
  |  Branch (830:36): [True: 1.09k, False: 180]
  ------------------
  831|  1.09k|        retval = sav_update_progress(ctx);
  832|  1.09k|        if (retval != READSTAT_OK)
  ------------------
  |  Branch (832:13): [True: 0, False: 1.09k]
  ------------------
  833|      0|            goto done;
  834|       |
  835|  1.09k|        if ((bytes_read = io->read(buffer, buffer_len, io->io_ctx)) != buffer_len)
  ------------------
  |  Branch (835:13): [True: 333, False: 759]
  ------------------
  836|    333|            goto done;
  837|       |
  838|    759|        retval = row_handler(buffer, buffer_len, ctx);
  839|    759|        if (retval != READSTAT_OK)
  ------------------
  |  Branch (839:13): [True: 4, False: 755]
  ------------------
  840|      4|            goto done;
  841|    759|    }
  842|    517|done:
  843|    517|    if (buffer)
  ------------------
  |  Branch (843:9): [True: 517, False: 0]
  ------------------
  844|    517|        free(buffer);
  845|       |
  846|    517|    return retval;
  847|    517|}

spss_format:
   51|   200k|int spss_format(char *buffer, size_t len, spss_format_t *format) {
   52|   200k|    if (format->type < 0 
  ------------------
  |  Branch (52:9): [True: 0, False: 200k]
  ------------------
   53|   200k|            || format->type >= sizeof(spss_type_strings)/sizeof(spss_type_strings[0])
  ------------------
  |  Branch (53:16): [True: 2.93k, False: 197k]
  ------------------
   54|   200k|            || spss_type_strings[format->type][0] == '\0') {
  ------------------
  |  Branch (54:16): [True: 22.4k, False: 175k]
  ------------------
   55|  25.4k|        return 0;
   56|  25.4k|    }
   57|   175k|    char *string = spss_type_strings[format->type];
   58|       |
   59|   175k|    if (format->decimal_places || format->type == SPSS_FORMAT_TYPE_F) {
  ------------------
  |  |    6|   117k|#define SPSS_FORMAT_TYPE_F        5
  ------------------
  |  Branch (59:9): [True: 57.2k, False: 117k]
  |  Branch (59:35): [True: 353, False: 117k]
  ------------------
   60|  57.6k|        snprintf(buffer, len, "%s%d.%d", string, format->width, format->decimal_places);
   61|   117k|    } else if (format->width) {
  ------------------
  |  Branch (61:16): [True: 71.1k, False: 46.4k]
  ------------------
   62|  71.1k|        snprintf(buffer, len, "%s%d", string, format->width);
   63|  71.1k|    } else {
   64|  46.4k|        snprintf(buffer, len, "%s", string);
   65|  46.4k|    }
   66|       |
   67|   175k|    return 1;
   68|   200k|}
spss_varinfo_compare:
   70|   681k|int spss_varinfo_compare(const void *elem1, const void *elem2) {
   71|   681k|    int offset = *(int *)elem1;
   72|   681k|    const spss_varinfo_t *v = *(const spss_varinfo_t **)elem2;
   73|   681k|    if (offset < v->offset)
  ------------------
  |  Branch (73:9): [True: 366k, False: 314k]
  ------------------
   74|   366k|        return -1;
   75|   314k|    return (offset > v->offset);
   76|   681k|}
spss_varinfo_free:
   78|   333k|void spss_varinfo_free(spss_varinfo_t *info) {
   79|   333k|    if (info) {
  ------------------
  |  Branch (79:9): [True: 333k, False: 8]
  ------------------
   80|   333k|        if (info->label)
  ------------------
  |  Branch (80:13): [True: 883, False: 332k]
  ------------------
   81|    883|            free(info->label);
   82|   333k|        free(info);
   83|   333k|    }
   84|   333k|}
spss_missingness_for_info:
  127|   200k|readstat_missingness_t spss_missingness_for_info(spss_varinfo_t *info) {
  128|   200k|    readstat_missingness_t missingness;
  129|   200k|    memset(&missingness, '\0', sizeof(readstat_missingness_t));
  130|       |
  131|   200k|    if (info->missing_range) {
  ------------------
  |  Branch (131:9): [True: 829, False: 199k]
  ------------------
  132|    829|        missingness.missing_ranges_count++;
  133|    829|        missingness.missing_ranges[0] = spss_boxed_missing_value(info, 0);
  134|    829|        missingness.missing_ranges[1] = spss_boxed_missing_value(info, 1);
  135|       |
  136|    829|        if (info->n_missing_values == 3) {
  ------------------
  |  Branch (136:13): [True: 388, False: 441]
  ------------------
  137|    388|            missingness.missing_ranges_count++;
  138|    388|            missingness.missing_ranges[2] = missingness.missing_ranges[3] = spss_boxed_missing_value(info, 2);
  139|    388|        }
  140|   199k|    } else if (info->n_missing_values > 0) {
  ------------------
  |  Branch (140:16): [True: 1.80k, False: 198k]
  ------------------
  141|  1.80k|        missingness.missing_ranges_count = info->n_missing_values;
  142|  1.80k|        int i=0;
  143|  6.75k|        for (i=0; i<info->n_missing_values; i++) {
  ------------------
  |  Branch (143:19): [True: 4.95k, False: 1.80k]
  ------------------
  144|  4.95k|            missingness.missing_ranges[2*i] = missingness.missing_ranges[2*i+1] = spss_boxed_missing_value(info, i);
  145|  4.95k|        }
  146|  1.80k|    }
  147|   200k|    return missingness;
  148|   200k|}
spss_init_variable_for_info:
  151|   200k|        iconv_t converter) {
  152|   200k|    readstat_variable_t *variable = calloc(1, sizeof(readstat_variable_t));
  153|       |
  154|   200k|    variable->index = info->index;
  155|   200k|    variable->index_after_skipping = index_after_skipping;
  156|   200k|    variable->type = info->type;
  157|   200k|    if (info->string_length) {
  ------------------
  |  Branch (157:9): [True: 382, False: 200k]
  ------------------
  158|    382|        variable->storage_width = info->string_length;
  159|   200k|    } else {
  160|   200k|        variable->storage_width = 8 * info->width;
  161|   200k|    }
  162|       |
  163|   200k|    if (info->longname[0]) {
  ------------------
  |  Branch (163:9): [True: 196k, False: 4.49k]
  ------------------
  164|   196k|        readstat_convert(variable->name, sizeof(variable->name),
  165|   196k|                info->longname, sizeof(info->longname), converter);
  166|   196k|    } else {
  167|  4.49k|        readstat_convert(variable->name, sizeof(variable->name),
  168|  4.49k|                info->name, sizeof(info->name), converter);
  169|  4.49k|    }
  170|   200k|    if (info->label) {
  ------------------
  |  Branch (170:9): [True: 337, False: 200k]
  ------------------
  171|    337|        snprintf(variable->label, sizeof(variable->label), "%s", info->label);
  172|    337|    }
  173|       |
  174|   200k|    spss_format(variable->format, sizeof(variable->format), &info->print_format);
  175|       |
  176|   200k|    variable->missingness = spss_missingness_for_info(info);
  177|   200k|    variable->measure = info->measure;
  178|   200k|    if (info->display_width) {
  ------------------
  |  Branch (178:9): [True: 428, False: 200k]
  ------------------
  179|    428|        variable->display_width = info->display_width;
  180|   200k|    } else {
  181|   200k|        variable->display_width = info->print_format.width;
  182|   200k|    }
  183|       |
  184|   200k|    return variable;
  185|   200k|}
spss_measure_to_readstat_measure:
  199|  5.66k|readstat_measure_t spss_measure_to_readstat_measure(uint32_t sav_measure) {
  200|  5.66k|    if (sav_measure == SAV_MEASURE_NOMINAL)
  ------------------
  |  |   47|  5.66k|#define SAV_MEASURE_NOMINAL     1
  ------------------
  |  Branch (200:9): [True: 247, False: 5.41k]
  ------------------
  201|    247|        return READSTAT_MEASURE_NOMINAL;
  202|  5.41k|    if (sav_measure == SAV_MEASURE_ORDINAL)
  ------------------
  |  |   48|  5.41k|#define SAV_MEASURE_ORDINAL     2
  ------------------
  |  Branch (202:9): [True: 415, False: 4.99k]
  ------------------
  203|    415|        return READSTAT_MEASURE_ORDINAL;
  204|  4.99k|    if (sav_measure == SAV_MEASURE_SCALE)
  ------------------
  |  |   49|  4.99k|#define SAV_MEASURE_SCALE       3
  ------------------
  |  Branch (204:9): [True: 243, False: 4.75k]
  ------------------
  205|    243|        return READSTAT_MEASURE_SCALE;
  206|  4.75k|    return READSTAT_MEASURE_UNKNOWN;
  207|  4.99k|}
spss_alignment_to_readstat_alignment:
  221|  5.66k|readstat_alignment_t spss_alignment_to_readstat_alignment(uint32_t sav_alignment) {
  222|  5.66k|    if (sav_alignment == SAV_ALIGNMENT_LEFT)
  ------------------
  |  |   51|  5.66k|#define SAV_ALIGNMENT_LEFT      0
  ------------------
  |  Branch (222:9): [True: 1.62k, False: 4.03k]
  ------------------
  223|  1.62k|        return READSTAT_ALIGNMENT_LEFT;
  224|  4.03k|    if (sav_alignment == SAV_ALIGNMENT_CENTER)
  ------------------
  |  |   53|  4.03k|#define SAV_ALIGNMENT_CENTER    2
  ------------------
  |  Branch (224:9): [True: 237, False: 3.79k]
  ------------------
  225|    237|        return READSTAT_ALIGNMENT_CENTER;
  226|  3.79k|    if (sav_alignment == SAV_ALIGNMENT_RIGHT)
  ------------------
  |  |   52|  3.79k|#define SAV_ALIGNMENT_RIGHT     1
  ------------------
  |  Branch (226:9): [True: 234, False: 3.56k]
  ------------------
  227|    234|        return READSTAT_ALIGNMENT_RIGHT;
  228|  3.56k|    return READSTAT_ALIGNMENT_UNKNOWN;
  229|  3.79k|}
readstat_spss.c:spss_boxed_missing_value:
  120|  6.99k|static readstat_value_t spss_boxed_missing_value(spss_varinfo_t *info, int i) {
  121|  6.99k|    if (info->type == READSTAT_TYPE_DOUBLE) {
  ------------------
  |  Branch (121:9): [True: 5.06k, False: 1.93k]
  ------------------
  122|  5.06k|        return spss_boxed_double_value(info->missing_double_values[i]);
  123|  5.06k|    }
  124|  1.93k|    return spss_boxed_string_value(info->missing_string_values[i]);
  125|  6.99k|}
readstat_spss.c:spss_boxed_double_value:
  103|  5.06k|static readstat_value_t spss_boxed_double_value(double fp_value) {
  104|  5.06k|    readstat_value_t value = {
  105|  5.06k|        .type = READSTAT_TYPE_DOUBLE,
  106|  5.06k|        .v = { .double_value = fp_value },
  107|  5.06k|        .is_system_missing = isnan(fp_value)
  108|  5.06k|    };
  109|  5.06k|    return value;
  110|  5.06k|}
readstat_spss.c:spss_boxed_string_value:
  112|  1.93k|static readstat_value_t spss_boxed_string_value(const char *string) {
  113|  1.93k|    readstat_value_t value = {
  114|  1.93k|        .type = READSTAT_TYPE_STRING,
  115|  1.93k|        .v = { .string_value = string }
  116|  1.93k|    };
  117|  1.93k|    return value;
  118|  1.93k|}

zsav_read_compressed_data:
   32|    494|        readstat_error_t (*row_handler)(unsigned char *, size_t, sav_ctx_t *)) {
   33|    494|    readstat_error_t retval = READSTAT_OK;
   34|    494|    readstat_io_t *io = ctx->io;
   35|    494|    readstat_off_t data_offset = 0;
   36|       |
   37|    494|    size_t uncompressed_row_len = ctx->var_offset * 8;
   38|    494|    readstat_off_t uncompressed_offset = 0;
   39|    494|    unsigned char *uncompressed_row = NULL;
   40|       |
   41|    494|    uLongf uncompressed_block_len = 0;
   42|    494|    unsigned char *compressed_block = NULL, *uncompressed_block = NULL;
   43|       |
   44|    494|    struct sav_row_stream_s state = { 
   45|    494|        .missing_value = ctx->missing_double,
   46|    494|        .bias = ctx->bias,
   47|    494|        .bswap = ctx->bswap };
   48|       |
   49|    494|    struct zheader zheader;
   50|    494|    struct ztrailer ztrailer;
   51|    494|    struct ztrailer_entry *ztrailer_entries = NULL;
   52|       |
   53|    494|    int n_blocks = 0;
   54|    494|    int block_i = 0;
   55|    494|    int i;
   56|       |
   57|    494|    if (io->read(&zheader, sizeof(struct zheader), io->io_ctx) < sizeof(struct zheader)) {
  ------------------
  |  Branch (57:9): [True: 22, False: 472]
  ------------------
   58|     22|        retval = READSTAT_ERROR_READ;
   59|     22|        goto cleanup;
   60|     22|    }
   61|       |
   62|    472|    zheader.zheader_ofs = ctx->bswap ? byteswap8(zheader.zheader_ofs) : zheader.zheader_ofs;
  ------------------
  |  Branch (62:27): [True: 233, False: 239]
  ------------------
   63|    472|    zheader.ztrailer_ofs = ctx->bswap ? byteswap8(zheader.ztrailer_ofs) : zheader.ztrailer_ofs;
  ------------------
  |  Branch (63:28): [True: 233, False: 239]
  ------------------
   64|    472|    zheader.ztrailer_len = ctx->bswap ? byteswap8(zheader.ztrailer_len) : zheader.ztrailer_len;
  ------------------
  |  Branch (64:28): [True: 233, False: 239]
  ------------------
   65|       |
   66|    472|    if (zheader.zheader_ofs != io->seek(0, READSTAT_SEEK_CUR, io->io_ctx) - sizeof(struct zheader)) {
  ------------------
  |  Branch (66:9): [True: 98, False: 374]
  ------------------
   67|     98|        retval = READSTAT_ERROR_PARSE;
   68|     98|        goto cleanup;
   69|     98|    }
   70|       |
   71|    374|    n_blocks = (zheader.ztrailer_len - 24) / 24;
   72|       |
   73|    374|    if (io->seek(zheader.ztrailer_ofs, READSTAT_SEEK_SET, io->io_ctx) == -1) {
  ------------------
  |  Branch (73:9): [True: 25, False: 349]
  ------------------
   74|     25|        retval = READSTAT_ERROR_SEEK;
   75|     25|        goto cleanup;
   76|     25|    }
   77|       |
   78|    349|    if (io->read(&ztrailer, sizeof(struct ztrailer), io->io_ctx) < sizeof(struct ztrailer)) {
  ------------------
  |  Branch (78:9): [True: 20, False: 329]
  ------------------
   79|     20|        retval = READSTAT_ERROR_READ;
   80|     20|        goto cleanup;
   81|     20|    }
   82|       |
   83|    329|    ztrailer.bias = ctx->bswap ? byteswap8(ztrailer.bias) : ztrailer.bias;
  ------------------
  |  Branch (83:21): [True: 150, False: 179]
  ------------------
   84|    329|    ztrailer.zero = ctx->bswap ? byteswap8(ztrailer.zero) : ztrailer.zero;
  ------------------
  |  Branch (84:21): [True: 150, False: 179]
  ------------------
   85|    329|    ztrailer.block_size = ctx->bswap ? byteswap4(ztrailer.block_size) : ztrailer.block_size;
  ------------------
  |  Branch (85:27): [True: 150, False: 179]
  ------------------
   86|    329|    ztrailer.n_blocks = ctx->bswap ? byteswap4(ztrailer.n_blocks) : ztrailer.n_blocks;
  ------------------
  |  Branch (86:25): [True: 150, False: 179]
  ------------------
   87|       |
   88|    329|    if (n_blocks != ztrailer.n_blocks) {
  ------------------
  |  Branch (88:9): [True: 48, False: 281]
  ------------------
   89|     48|        retval = READSTAT_ERROR_PARSE;
   90|     48|        goto cleanup;
   91|     48|    }
   92|       |
   93|    281|    if (n_blocks && (ztrailer_entries = readstat_malloc(n_blocks * sizeof(struct ztrailer_entry))) == NULL) {
  ------------------
  |  Branch (93:9): [True: 280, False: 1]
  |  Branch (93:21): [True: 53, False: 227]
  ------------------
   94|     53|        retval = READSTAT_ERROR_MALLOC;
   95|     53|        goto cleanup;
   96|     53|    }
   97|       |
   98|    228|    if (io->read(ztrailer_entries, n_blocks * sizeof(struct ztrailer_entry), io->io_ctx) < 
  ------------------
  |  Branch (98:9): [True: 34, False: 194]
  ------------------
   99|    228|            n_blocks * sizeof(struct ztrailer_entry)) {
  100|     34|        retval = READSTAT_ERROR_READ;
  101|     34|        goto cleanup;
  102|     34|    }
  103|       |
  104|  31.0k|    for (i=0; i<n_blocks; i++) {
  ------------------
  |  Branch (104:15): [True: 30.8k, False: 194]
  ------------------
  105|  30.8k|        struct ztrailer_entry *entry = &ztrailer_entries[i];
  106|       |
  107|  30.8k|        entry->uncompressed_ofs = ctx->bswap ? byteswap8(entry->uncompressed_ofs) : entry->uncompressed_ofs;
  ------------------
  |  Branch (107:35): [True: 9.41k, False: 21.4k]
  ------------------
  108|  30.8k|        entry->compressed_ofs = ctx->bswap ? byteswap8(entry->compressed_ofs) : entry->compressed_ofs;
  ------------------
  |  Branch (108:33): [True: 9.41k, False: 21.4k]
  ------------------
  109|  30.8k|        entry->uncompressed_size = ctx->bswap ? byteswap4(entry->uncompressed_size) : entry->uncompressed_size;
  ------------------
  |  Branch (109:36): [True: 9.41k, False: 21.4k]
  ------------------
  110|  30.8k|        entry->compressed_size = ctx->bswap ? byteswap4(entry->compressed_size) : entry->compressed_size;
  ------------------
  |  Branch (110:34): [True: 9.41k, False: 21.4k]
  ------------------
  111|  30.8k|    }
  112|       |
  113|    194|    if (uncompressed_row_len && (uncompressed_row = readstat_malloc(uncompressed_row_len)) == NULL) {
  ------------------
  |  Branch (113:9): [True: 194, False: 0]
  |  Branch (113:33): [True: 0, False: 194]
  ------------------
  114|      0|        retval = READSTAT_ERROR_MALLOC;
  115|      0|        goto cleanup;
  116|      0|    }
  117|       |
  118|    194|    while (1) {
  ------------------
  |  Branch (118:12): [Folded - Ignored]
  ------------------
  119|    194|        if (block_i == n_blocks)
  ------------------
  |  Branch (119:13): [True: 1, False: 193]
  ------------------
  120|      1|            goto cleanup;
  121|       |
  122|    193|        struct ztrailer_entry *entry = &ztrailer_entries[block_i];
  123|    193|        if (io->seek(entry->compressed_ofs, READSTAT_SEEK_SET, io->io_ctx) == -1) {
  ------------------
  |  Branch (123:13): [True: 19, False: 174]
  ------------------
  124|     19|            retval = READSTAT_ERROR_SEEK;
  125|     19|            goto cleanup;
  126|     19|        }
  127|    174|        if ((compressed_block = readstat_realloc(compressed_block, entry->compressed_size)) == NULL) {
  ------------------
  |  Branch (127:13): [True: 43, False: 131]
  ------------------
  128|     43|            retval = READSTAT_ERROR_MALLOC;
  129|     43|            goto cleanup;
  130|     43|        }
  131|    131|        if (io->read(compressed_block, entry->compressed_size, io->io_ctx) != entry->compressed_size) {
  ------------------
  |  Branch (131:13): [True: 45, False: 86]
  ------------------
  132|     45|            retval = READSTAT_ERROR_READ;
  133|     45|            goto cleanup;
  134|     45|        }
  135|       |
  136|     86|        uncompressed_block_len = entry->uncompressed_size;
  137|     86|        if ((uncompressed_block = readstat_realloc(uncompressed_block, uncompressed_block_len)) == NULL) {
  ------------------
  |  Branch (137:13): [True: 13, False: 73]
  ------------------
  138|     13|            retval = READSTAT_ERROR_MALLOC;
  139|     13|            goto cleanup;
  140|     13|        }
  141|     73|        int status = uncompress(uncompressed_block, &uncompressed_block_len,
  142|     73|                compressed_block, entry->compressed_size);
  143|     73|        if (status != Z_OK || uncompressed_block_len != entry->uncompressed_size) {
  ------------------
  |  Branch (143:13): [True: 1, False: 72]
  |  Branch (143:31): [True: 23, False: 49]
  ------------------
  144|     24|            retval = READSTAT_ERROR_PARSE;
  145|     24|            goto cleanup;
  146|     24|        }
  147|       |
  148|     49|        block_i++;
  149|     49|        state.status = SAV_ROW_STREAM_HAVE_DATA;
  150|     49|        data_offset = 0;
  151|       |
  152|    165|        while (state.status != SAV_ROW_STREAM_NEED_DATA) {
  ------------------
  |  Branch (152:16): [True: 165, False: 0]
  ------------------
  153|    165|            state.next_in = &uncompressed_block[data_offset];
  154|    165|            state.avail_in = uncompressed_block_len - data_offset;
  155|       |
  156|    165|            state.next_out = &uncompressed_row[uncompressed_offset];
  157|    165|            state.avail_out = uncompressed_row_len - uncompressed_offset;
  158|       |
  159|    165|            sav_decompress_row(&state);
  160|       |
  161|    165|            uncompressed_offset = uncompressed_row_len - state.avail_out;
  162|    165|            data_offset = uncompressed_block_len - state.avail_in;
  163|       |
  164|    165|            if (state.status == SAV_ROW_STREAM_FINISHED_ROW) {
  ------------------
  |  Branch (164:17): [True: 122, False: 43]
  ------------------
  165|    122|                retval = row_handler(uncompressed_row, uncompressed_row_len, ctx);
  166|    122|                if (retval != READSTAT_OK)
  ------------------
  |  Branch (166:21): [True: 2, False: 120]
  ------------------
  167|      2|                    goto cleanup;
  168|       |
  169|    120|                uncompressed_offset = 0;
  170|    120|            }
  171|       |
  172|    163|            if (state.status == SAV_ROW_STREAM_FINISHED_ALL)
  ------------------
  |  Branch (172:17): [True: 43, False: 120]
  ------------------
  173|     43|                goto cleanup;
  174|    120|            if (ctx->row_limit > 0 && ctx->current_row == ctx->row_limit)
  ------------------
  |  Branch (174:17): [True: 77, False: 43]
  |  Branch (174:39): [True: 4, False: 73]
  ------------------
  175|      4|                goto cleanup;
  176|    120|        }
  177|     49|    }
  178|       |
  179|    494|cleanup:
  180|    494|    if (uncompressed_row)
  ------------------
  |  Branch (180:9): [True: 194, False: 300]
  ------------------
  181|    194|        free(uncompressed_row);
  182|    494|    if (ztrailer_entries)
  ------------------
  |  Branch (182:9): [True: 227, False: 267]
  ------------------
  183|    227|        free(ztrailer_entries);
  184|    494|    if (compressed_block)
  ------------------
  |  Branch (184:9): [True: 131, False: 363]
  ------------------
  185|    131|        free(compressed_block);
  186|    494|    if (uncompressed_block)
  ------------------
  |  Branch (186:9): [True: 73, False: 421]
  ------------------
  187|     73|        free(uncompressed_block);
  188|       |
  189|    494|    return retval;
  190|    194|}

rt_open_handler:
    8|  5.12k|int rt_open_handler(const char *path, void *io_ctx) {
    9|  5.12k|    return 0;
   10|  5.12k|}
rt_close_handler:
   12|  5.12k|int rt_close_handler(void *io_ctx) {
   13|  5.12k|    return 0;
   14|  5.12k|}
rt_seek_handler:
   17|   479k|        readstat_io_flags_t whence, void *io_ctx) {
   18|   479k|    rt_buffer_ctx_t *buffer_ctx = (rt_buffer_ctx_t *)io_ctx;
   19|   479k|    readstat_off_t newpos = -1;
   20|   479k|    if (whence == READSTAT_SEEK_SET) {
  ------------------
  |  Branch (20:9): [True: 9.81k, False: 470k]
  ------------------
   21|  9.81k|        newpos = offset;
   22|   470k|    } else if (whence == READSTAT_SEEK_CUR) {
  ------------------
  |  Branch (22:16): [True: 465k, False: 5.12k]
  ------------------
   23|   465k|        newpos = buffer_ctx->pos + offset;
   24|   465k|    } else if (whence == READSTAT_SEEK_END) {
  ------------------
  |  Branch (24:16): [True: 5.12k, False: 0]
  ------------------
   25|  5.12k|        newpos = buffer_ctx->buffer->used + offset;
   26|  5.12k|    }
   27|       |
   28|   479k|    if (newpos < 0)
  ------------------
  |  Branch (28:9): [True: 71, False: 479k]
  ------------------
   29|     71|        return -1;
   30|       |
   31|   479k|    if (newpos > buffer_ctx->buffer->used)
  ------------------
  |  Branch (31:9): [True: 281, False: 479k]
  ------------------
   32|    281|        return -1;
   33|       |
   34|   479k|    buffer_ctx->pos = newpos;
   35|   479k|    return newpos;
   36|   479k|}
rt_read_handler:
   38|  2.14M|ssize_t rt_read_handler(void *buf, size_t nbytes, void *io_ctx) {
   39|  2.14M|    rt_buffer_ctx_t *buffer_ctx = (rt_buffer_ctx_t *)io_ctx;
   40|  2.14M|    ssize_t bytes_copied = 0;
   41|  2.14M|    ssize_t bytes_left = buffer_ctx->buffer->used - buffer_ctx->pos;
   42|  2.14M|    if (nbytes <= bytes_left) {
  ------------------
  |  Branch (42:9): [True: 2.14M, False: 2.97k]
  ------------------
   43|  2.14M|        memcpy(buf, buffer_ctx->buffer->bytes + buffer_ctx->pos, nbytes);
   44|  2.14M|        bytes_copied = nbytes;
   45|  2.14M|    } else if (bytes_left > 0) {
  ------------------
  |  Branch (45:16): [True: 723, False: 2.25k]
  ------------------
   46|    723|        memcpy(buf, buffer_ctx->buffer->bytes + buffer_ctx->pos, bytes_left);
   47|    723|        bytes_copied = bytes_left;
   48|    723|    }
   49|  2.14M|    buffer_ctx->pos += bytes_copied;
   50|  2.14M|    return bytes_copied;
   51|  2.14M|}
rt_update_handler:
   54|  5.96k|        void *user_ctx, void *io_ctx) {
   55|  5.96k|    if (!progress_handler)
  ------------------
  |  Branch (55:9): [True: 5.96k, False: 0]
  ------------------
   56|  5.96k|        return READSTAT_OK;
   57|       |
   58|      0|    rt_buffer_ctx_t *buffer_ctx = (rt_buffer_ctx_t *)io_ctx;
   59|       |
   60|      0|    if (progress_handler(1.0 * buffer_ctx->pos / buffer_ctx->buffer->used, user_ctx))
  ------------------
  |  Branch (60:9): [True: 0, False: 0]
  ------------------
   61|      0|        return READSTAT_ERROR_USER_ABORT;
   62|       |
   63|      0|    return READSTAT_OK;
   64|      0|}

