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

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

machine_is_little_endian:
   11|  5.93k|int machine_is_little_endian() {
   12|  5.93k|    int test_byte_order = 1;
   13|  5.93k|    return ((char *)&test_byte_order)[0];
   14|  5.93k|}
byteswap2:
   40|   102k|uint16_t byteswap2(uint16_t num) {
   41|   102k|    return ((num & 0xFF00) >> 8) | ((num & 0x00FF) << 8);
   42|   102k|}
byteswap4:
   44|   179k|uint32_t byteswap4(uint32_t num) {
   45|   179k|    num = ((num & 0xFFFF0000) >> 16) | ((num & 0x0000FFFF) << 16);
   46|   179k|    return ((num & 0xFF00FF00) >> 8) | ((num & 0x00FF00FF) << 8);
   47|   179k|}
byteswap8:
   49|  79.2k|uint64_t byteswap8(uint64_t num) {
   50|  79.2k|    num = ((num & 0xFFFFFFFF00000000) >> 32) | ((num & 0x00000000FFFFFFFF) << 32);
   51|  79.2k|    num = ((num & 0xFFFF0000FFFF0000) >> 16) | ((num & 0x0000FFFF0000FFFF) << 16);
   52|  79.2k|    return ((num & 0xFF00FF00FF00FF00) >> 8) | ((num & 0x00FF00FF00FF00FF) << 8);
   53|  79.2k|}
byteswap_double:
   63|  5.03k|double byteswap_double(double num) {
   64|  5.03k|    uint64_t answer = 0;
   65|  5.03k|    memcpy(&answer, &num, 8);
   66|  5.03k|    answer = byteswap8(answer);
   67|  5.03k|    memcpy(&num, &answer, 8);
   68|  5.03k|    return num;
   69|  5.03k|}

readstat_convert:
    7|  21.8k|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|  47.9k|    while (src_len && (src[src_len-1] == ' ' || src[src_len-1] == '\0')) {
  ------------------
  |  Branch (10:12): [True: 40.8k, False: 7.13k]
  |  Branch (10:24): [True: 2.01k, False: 38.7k]
  |  Branch (10:49): [True: 24.0k, False: 14.7k]
  ------------------
   11|  26.1k|        src_len--;
   12|  26.1k|    }
   13|  21.8k|    if (dst_len == 0) {
  ------------------
  |  Branch (13:9): [True: 0, False: 21.8k]
  ------------------
   14|      0|        return READSTAT_ERROR_CONVERT_LONG_STRING;
   15|  21.8k|    } else if (converter) {
  ------------------
  |  Branch (15:16): [True: 11.5k, False: 10.3k]
  ------------------
   16|  11.5k|        size_t dst_left = dst_len - 1;
   17|  11.5k|        char *dst_end = dst;
   18|  11.5k|        size_t status = iconv(converter, (readstat_iconv_inbuf_t)&src, &src_len, &dst_end, &dst_left);
   19|  11.5k|        if (status == (size_t)-1) {
  ------------------
  |  Branch (19:13): [True: 492, False: 11.0k]
  ------------------
   20|    492|            if (errno == E2BIG) {
  ------------------
  |  Branch (20:17): [True: 8, False: 484]
  ------------------
   21|      8|                return READSTAT_ERROR_CONVERT_LONG_STRING;
   22|    484|            } else if (errno == EILSEQ) {
  ------------------
  |  Branch (22:24): [True: 27, False: 457]
  ------------------
   23|     27|                return READSTAT_ERROR_CONVERT_BAD_STRING;
   24|    457|            } else if (errno != EINVAL) { /* EINVAL indicates improper truncation; accept it */
  ------------------
  |  Branch (24:24): [True: 0, False: 457]
  ------------------
   25|      0|                return READSTAT_ERROR_CONVERT;
   26|      0|            }
   27|    492|        }
   28|  11.4k|        dst[dst_len - dst_left - 1] = '\0';
   29|  11.4k|    } else if (src_len + 1 > dst_len) {
  ------------------
  |  Branch (29:16): [True: 23, False: 10.2k]
  ------------------
   30|     23|        return READSTAT_ERROR_CONVERT_LONG_STRING;
   31|  10.2k|    } else {
   32|  10.2k|        memcpy(dst, src, src_len);
   33|  10.2k|        dst[src_len] = '\0';
   34|  10.2k|    }
   35|  21.7k|    return READSTAT_OK;
   36|  21.8k|}

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

readstat_malloc:
   10|  5.73k|void *readstat_malloc(size_t len) {
   11|  5.73k|    if (len > MAX_MALLOC_SIZE || len == 0) {
  ------------------
  |  |    3|  11.4k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
  |  Branch (11:9): [True: 0, False: 5.73k]
  |  Branch (11:34): [True: 0, False: 5.73k]
  ------------------
   12|      0|        return NULL;
   13|      0|    }
   14|  5.73k|    return malloc(len);
   15|  5.73k|}
readstat_calloc:
   17|  2.76k|void *readstat_calloc(size_t count, size_t size) {
   18|  2.76k|    if (count > MAX_MALLOC_SIZE || size > MAX_MALLOC_SIZE || count * size > MAX_MALLOC_SIZE) {
  ------------------
  |  |    3|  5.53k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
                  if (count > MAX_MALLOC_SIZE || size > MAX_MALLOC_SIZE || count * size > MAX_MALLOC_SIZE) {
  ------------------
  |  |    3|  5.53k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
                  if (count > MAX_MALLOC_SIZE || size > MAX_MALLOC_SIZE || count * size > MAX_MALLOC_SIZE) {
  ------------------
  |  |    3|  2.76k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
  |  Branch (18:9): [True: 0, False: 2.76k]
  |  Branch (18:36): [True: 0, False: 2.76k]
  |  Branch (18:62): [True: 0, False: 2.76k]
  ------------------
   19|      0|        return NULL;
   20|      0|    }
   21|  2.76k|    if (count == 0 || size == 0) {
  ------------------
  |  Branch (21:9): [True: 0, False: 2.76k]
  |  Branch (21:23): [True: 0, False: 2.76k]
  ------------------
   22|      0|        return NULL;
   23|      0|    }
   24|  2.76k|    return calloc(count, size);
   25|  2.76k|}
readstat_realloc:
   27|   173k|void *readstat_realloc(void *ptr, size_t len) {
   28|   173k|    if (len > MAX_MALLOC_SIZE || len == 0) {
  ------------------
  |  |    3|   346k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
  |  Branch (28:9): [True: 92, False: 173k]
  |  Branch (28:34): [True: 4, False: 173k]
  ------------------
   29|     96|        if (ptr)
  ------------------
  |  Branch (29:13): [True: 52, False: 44]
  ------------------
   30|     52|            free(ptr);
   31|     96|        return NULL;
   32|     96|    }
   33|   173k|    return realloc(ptr, len);
   34|   173k|}

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

sas_read8:
  138|  78.7k|uint64_t sas_read8(const char *data, int bswap) {
  139|  78.7k|    uint64_t tmp;
  140|  78.7k|    memcpy(&tmp, data, 8);
  141|  78.7k|    return bswap ? byteswap8(tmp) : tmp;
  ------------------
  |  Branch (141:12): [True: 72.7k, False: 6.06k]
  ------------------
  142|  78.7k|}
sas_read4:
  144|   233k|uint32_t sas_read4(const char *data, int bswap) {
  145|   233k|    uint32_t tmp;
  146|   233k|    memcpy(&tmp, data, 4);
  147|   233k|    return bswap ? byteswap4(tmp) : tmp;
  ------------------
  |  Branch (147:12): [True: 173k, False: 59.9k]
  ------------------
  148|   233k|}
sas_read2:
  150|   169k|uint16_t sas_read2(const char *data, int bswap) {
  151|   169k|    uint16_t tmp;
  152|   169k|    memcpy(&tmp, data, 2);
  153|   169k|    return bswap ? byteswap2(tmp) : tmp;
  ------------------
  |  Branch (153:12): [True: 102k, False: 67.3k]
  ------------------
  154|   169k|}
sas_subheader_remainder:
  156|  7.21k|size_t sas_subheader_remainder(size_t len, size_t signature_len) {
  157|  7.21k|    return len - (4+2*signature_len);
  158|  7.21k|}
sas_read_header:
  161|  3.31k|        readstat_error_handler error_handler, void *user_ctx) {
  162|  3.31k|    sas_header_start_t  header_start;
  163|  3.31k|    sas_header_end_t    header_end;
  164|  3.31k|    int retval = READSTAT_OK;
  165|  3.31k|    char error_buf[1024];
  166|  3.31k|    time_t epoch = sas_epoch();
  167|       |
  168|  3.31k|    if (io->read(&header_start, sizeof(sas_header_start_t), io->io_ctx) < sizeof(sas_header_start_t)) {
  ------------------
  |  Branch (168:9): [True: 20, False: 3.29k]
  ------------------
  169|     20|        retval = READSTAT_ERROR_READ;
  170|     20|        goto cleanup;
  171|     20|    }
  172|  3.29k|    if (memcmp(header_start.magic, sas7bdat_magic_number, sizeof(sas7bdat_magic_number)) != 0 &&
  ------------------
  |  Branch (172:9): [True: 1.45k, False: 1.83k]
  ------------------
  173|  3.29k|            memcmp(header_start.magic, sas7bcat_magic_number, sizeof(sas7bcat_magic_number)) != 0) {
  ------------------
  |  Branch (173:13): [True: 138, False: 1.31k]
  ------------------
  174|    138|        retval = READSTAT_ERROR_PARSE;
  175|    138|        goto cleanup;
  176|    138|    }
  177|  3.15k|    if (header_start.a1 == SAS_ALIGNMENT_OFFSET_4) {
  ------------------
  |  |   74|  3.15k|#define SAS_ALIGNMENT_OFFSET_4  0x33
  ------------------
  |  Branch (177:9): [True: 8, False: 3.14k]
  ------------------
  178|      8|        hinfo->pad1 = 4;
  179|      8|    }
  180|  3.15k|    if (header_start.a2 == SAS_ALIGNMENT_OFFSET_4) {
  ------------------
  |  |   74|  3.15k|#define SAS_ALIGNMENT_OFFSET_4  0x33
  ------------------
  |  Branch (180:9): [True: 1.68k, False: 1.47k]
  ------------------
  181|  1.68k|        hinfo->u64 = 1;
  182|  1.68k|    }
  183|  3.15k|    int bswap = 0;
  184|  3.15k|    if (header_start.endian == SAS_ENDIAN_BIG) {
  ------------------
  |  |   67|  3.15k|#define SAS_ENDIAN_BIG       0x00
  ------------------
  |  Branch (184:9): [True: 2.53k, False: 617]
  ------------------
  185|  2.53k|        bswap = machine_is_little_endian();
  186|  2.53k|        hinfo->little_endian = 0;
  187|  2.53k|    } else if (header_start.endian == SAS_ENDIAN_LITTLE) {
  ------------------
  |  |   68|    617|#define SAS_ENDIAN_LITTLE    0x01
  ------------------
  |  Branch (187:16): [True: 603, False: 14]
  ------------------
  188|    603|        bswap = !machine_is_little_endian();
  189|    603|        hinfo->little_endian = 1;
  190|    603|    } else {
  191|     14|        retval = READSTAT_ERROR_PARSE;
  192|     14|        goto cleanup;
  193|     14|    }
  194|  3.13k|    int i;
  195|  29.3k|    for (i=0; i<sizeof(_charset_table)/sizeof(_charset_table[0]); i++) {
  ------------------
  |  Branch (195:15): [True: 29.3k, False: 5]
  ------------------
  196|  29.3k|        if (header_start.encoding == _charset_table[i].code) {
  ------------------
  |  Branch (196:13): [True: 3.13k, False: 26.2k]
  ------------------
  197|  3.13k|            hinfo->encoding = _charset_table[i].name;
  198|  3.13k|            break;
  199|  3.13k|        }
  200|  29.3k|    }
  201|  3.13k|    if (hinfo->encoding == NULL) {
  ------------------
  |  Branch (201:9): [True: 5, False: 3.13k]
  ------------------
  202|      5|        if (error_handler) {
  ------------------
  |  Branch (202:13): [True: 0, False: 5]
  ------------------
  203|      0|            snprintf(error_buf, sizeof(error_buf), "Unsupported character set code: %d", header_start.encoding);
  204|      0|            error_handler(error_buf, user_ctx);
  205|      0|        }
  206|      5|        retval = READSTAT_ERROR_UNSUPPORTED_CHARSET;
  207|      5|        goto cleanup;
  208|      5|    }
  209|  3.13k|    memcpy(hinfo->table_name, header_start.table_name, sizeof(header_start.table_name));
  210|  3.13k|    if (io->seek(hinfo->pad1, READSTAT_SEEK_CUR, io->io_ctx) == -1) {
  ------------------
  |  Branch (210:9): [True: 3, False: 3.13k]
  ------------------
  211|      3|        retval = READSTAT_ERROR_SEEK;
  212|      3|        goto cleanup;
  213|      3|    }
  214|       |
  215|  3.13k|    double creation_time, modification_time;
  216|       |
  217|  3.13k|    if (io->read(&creation_time, sizeof(double), io->io_ctx) < sizeof(double)) {
  ------------------
  |  Branch (217:9): [True: 13, False: 3.11k]
  ------------------
  218|     13|        retval = READSTAT_ERROR_READ;
  219|     13|        goto cleanup;
  220|     13|    }
  221|  3.11k|    if (bswap)
  ------------------
  |  Branch (221:9): [True: 2.52k, False: 598]
  ------------------
  222|  2.52k|        creation_time = byteswap_double(creation_time);
  223|       |
  224|  3.11k|    if (io->read(&modification_time, sizeof(double), io->io_ctx) < sizeof(double)) {
  ------------------
  |  Branch (224:9): [True: 6, False: 3.11k]
  ------------------
  225|      6|        retval = READSTAT_ERROR_READ;
  226|      6|        goto cleanup;
  227|      6|    }
  228|  3.11k|    if (bswap)
  ------------------
  |  Branch (228:9): [True: 2.51k, False: 597]
  ------------------
  229|  2.51k|        modification_time = byteswap_double(modification_time);
  230|       |
  231|  3.11k|    hinfo->creation_time = sas_convert_time(creation_time, epoch);
  232|  3.11k|    hinfo->modification_time = sas_convert_time(modification_time, epoch);
  233|       |
  234|  3.11k|    if (io->seek(16, READSTAT_SEEK_CUR, io->io_ctx) == -1) {
  ------------------
  |  Branch (234:9): [True: 8, False: 3.10k]
  ------------------
  235|      8|        retval = READSTAT_ERROR_SEEK;
  236|      8|        goto cleanup;
  237|      8|    }
  238|       |
  239|  3.10k|    uint32_t header_size, page_size;
  240|       |
  241|  3.10k|    if (io->read(&header_size, sizeof(uint32_t), io->io_ctx) < sizeof(uint32_t)) {
  ------------------
  |  Branch (241:9): [True: 3, False: 3.10k]
  ------------------
  242|      3|        retval = READSTAT_ERROR_READ;
  243|      3|        goto cleanup;
  244|      3|    }
  245|  3.10k|    if (io->read(&page_size, sizeof(uint32_t), io->io_ctx) < sizeof(uint32_t)) {
  ------------------
  |  Branch (245:9): [True: 3, False: 3.09k]
  ------------------
  246|      3|        retval = READSTAT_ERROR_READ;
  247|      3|        goto cleanup;
  248|      3|    }
  249|       |
  250|  3.09k|    hinfo->header_size = bswap ? byteswap4(header_size) : header_size;
  ------------------
  |  Branch (250:26): [True: 2.50k, False: 596]
  ------------------
  251|  3.09k|    hinfo->page_size = bswap ? byteswap4(page_size) : page_size;
  ------------------
  |  Branch (251:24): [True: 2.50k, False: 596]
  ------------------
  252|       |
  253|  3.09k|    if (hinfo->header_size < 1024 || hinfo->page_size < 1024) {
  ------------------
  |  Branch (253:9): [True: 11, False: 3.08k]
  |  Branch (253:38): [True: 12, False: 3.07k]
  ------------------
  254|     23|        retval = READSTAT_ERROR_PARSE;
  255|     23|        goto cleanup;
  256|     23|    }
  257|  3.07k|    if (hinfo->header_size > (1<<24) || hinfo->page_size > (1<<24)) {
  ------------------
  |  Branch (257:9): [True: 22, False: 3.05k]
  |  Branch (257:41): [True: 33, False: 3.02k]
  ------------------
  258|     55|        retval = READSTAT_ERROR_PARSE;
  259|     55|        goto cleanup;
  260|     55|    }
  261|       |
  262|  3.02k|    if (hinfo->u64) {
  ------------------
  |  Branch (262:9): [True: 1.63k, False: 1.38k]
  ------------------
  263|  1.63k|        hinfo->page_header_size = SAS_PAGE_HEADER_SIZE_64BIT;
  ------------------
  |  |  105|  1.63k|#define SAS_PAGE_HEADER_SIZE_64BIT  40
  ------------------
  264|  1.63k|        hinfo->subheader_pointer_size = SAS_SUBHEADER_POINTER_SIZE_64BIT;
  ------------------
  |  |  102|  1.63k|#define SAS_SUBHEADER_POINTER_SIZE_64BIT    24
  ------------------
  265|  1.63k|    } else {
  266|  1.38k|        hinfo->page_header_size = SAS_PAGE_HEADER_SIZE_32BIT;
  ------------------
  |  |  104|  1.38k|#define SAS_PAGE_HEADER_SIZE_32BIT  24
  ------------------
  267|  1.38k|        hinfo->subheader_pointer_size = SAS_SUBHEADER_POINTER_SIZE_32BIT;
  ------------------
  |  |  101|  1.38k|#define SAS_SUBHEADER_POINTER_SIZE_32BIT    12
  ------------------
  268|  1.38k|    }
  269|       |
  270|  3.02k|    if (hinfo->u64) {
  ------------------
  |  Branch (270:9): [True: 1.63k, False: 1.38k]
  ------------------
  271|  1.63k|        uint64_t page_count;
  272|  1.63k|        if (io->read(&page_count, sizeof(uint64_t), io->io_ctx) < sizeof(uint64_t)) {
  ------------------
  |  Branch (272:13): [True: 19, False: 1.61k]
  ------------------
  273|     19|            retval = READSTAT_ERROR_READ;
  274|     19|            goto cleanup;
  275|     19|        }
  276|  1.61k|        hinfo->page_count = bswap ? byteswap8(page_count) : page_count;
  ------------------
  |  Branch (276:29): [True: 1.50k, False: 108]
  ------------------
  277|  1.61k|    } else {
  278|  1.38k|        uint32_t page_count;
  279|  1.38k|        if (io->read(&page_count, sizeof(uint32_t), io->io_ctx) < sizeof(uint32_t)) {
  ------------------
  |  Branch (279:13): [True: 22, False: 1.36k]
  ------------------
  280|     22|            retval = READSTAT_ERROR_READ;
  281|     22|            goto cleanup;
  282|     22|        }
  283|  1.36k|        hinfo->page_count = bswap ? byteswap4(page_count) : page_count;
  ------------------
  |  Branch (283:29): [True: 891, False: 473]
  ------------------
  284|  1.36k|    }
  285|  2.97k|    if (hinfo->page_count > (1<<24)) {
  ------------------
  |  Branch (285:9): [True: 15, False: 2.96k]
  ------------------
  286|     15|        retval = READSTAT_ERROR_PARSE;
  287|     15|        goto cleanup;
  288|     15|    }
  289|       |    
  290|  2.96k|    if (io->seek(8, READSTAT_SEEK_CUR, io->io_ctx) == -1) {
  ------------------
  |  Branch (290:9): [True: 75, False: 2.88k]
  ------------------
  291|     75|        retval = READSTAT_ERROR_SEEK;
  292|     75|        if (error_handler) {
  ------------------
  |  Branch (292:13): [True: 0, False: 75]
  ------------------
  293|      0|            snprintf(error_buf, sizeof(error_buf), "ReadStat: Failed to seek forward by %d", 8);
  294|      0|            error_handler(error_buf, user_ctx);
  295|      0|        }
  296|     75|        goto cleanup;
  297|     75|    }
  298|  2.88k|    if (io->read(&header_end, sizeof(sas_header_end_t), io->io_ctx) < sizeof(sas_header_end_t)) {
  ------------------
  |  Branch (298:9): [True: 16, False: 2.87k]
  ------------------
  299|     16|        retval = READSTAT_ERROR_READ;
  300|     16|        goto cleanup;
  301|     16|    }
  302|  2.87k|    char major;
  303|  2.87k|    int minor, revision;
  304|  2.87k|    if (sscanf(header_end.release, "%c.%04dM%1d", &major, &minor, &revision) != 3) {
  ------------------
  |  Branch (304:9): [True: 4, False: 2.86k]
  ------------------
  305|      4|        retval = READSTAT_ERROR_PARSE;
  306|      4|        goto cleanup;
  307|      4|    }
  308|       |
  309|  2.86k|    if (major >= '1' && major <= '9') {
  ------------------
  |  Branch (309:9): [True: 2.85k, False: 11]
  |  Branch (309:25): [True: 2.84k, False: 12]
  ------------------
  310|  2.84k|        hinfo->major_version = major - '0';
  311|  2.84k|    } else if (major == 'V') {
  ------------------
  |  Branch (311:16): [True: 4, False: 19]
  ------------------
  312|       |        // It appears that SAS Visual Forecaster reports the major version as "V"
  313|       |        // Treat it as version 9 for all intents and purposes
  314|      4|        hinfo->major_version = 9;
  315|     19|    } else {
  316|     19|        retval = READSTAT_ERROR_PARSE;
  317|     19|        goto cleanup;
  318|     19|    }
  319|  2.85k|    hinfo->minor_version = minor;
  320|  2.85k|    hinfo->revision = revision;
  321|       |
  322|  2.85k|    if ((major == '8' || major == '9') && minor == 0 && revision == 0) {
  ------------------
  |  Branch (322:10): [True: 366, False: 2.48k]
  |  Branch (322:26): [True: 99, False: 2.38k]
  |  Branch (322:43): [True: 76, False: 389]
  |  Branch (322:57): [True: 47, False: 29]
  ------------------
  323|       |        /* A bit of a hack, but most SAS installations are running a minor update */
  324|     47|        hinfo->vendor = READSTAT_VENDOR_STAT_TRANSFER;
  325|  2.80k|    } else {
  326|  2.80k|        hinfo->vendor = READSTAT_VENDOR_SAS;
  327|  2.80k|    }
  328|  2.85k|    if (io->seek(hinfo->header_size, READSTAT_SEEK_SET, io->io_ctx) == -1) {
  ------------------
  |  Branch (328:9): [True: 52, False: 2.79k]
  ------------------
  329|     52|        retval = READSTAT_ERROR_SEEK;
  330|     52|        if (error_handler) {
  ------------------
  |  Branch (330:13): [True: 0, False: 52]
  ------------------
  331|      0|            snprintf(error_buf, sizeof(error_buf), 
  332|      0|                    "ReadStat: Failed to seek to position %" PRId64, hinfo->header_size);
  333|      0|            error_handler(error_buf, user_ctx);
  334|      0|        }
  335|     52|        goto cleanup;
  336|     52|    }
  337|       |
  338|  3.31k|cleanup:
  339|  3.31k|    return retval;
  340|  2.85k|}
sas_validate_tag:
  492|  4.31k|readstat_error_t sas_validate_tag(char tag) {
  493|  4.31k|    if (tag == '_' || (tag >= 'A' && tag <= 'Z'))
  ------------------
  |  Branch (493:9): [True: 2.06k, False: 2.24k]
  |  Branch (493:24): [True: 875, False: 1.37k]
  |  Branch (493:38): [True: 612, False: 263]
  ------------------
  494|  2.67k|        return READSTAT_OK;
  495|       |
  496|  1.63k|    return READSTAT_ERROR_TAGGED_VALUE_IS_OUT_OF_RANGE;
  497|  4.31k|}
sas_assign_tag:
  499|  4.31k|void sas_assign_tag(readstat_value_t *value, uint8_t tag) {
  500|       |    /* We accommodate two tag schemes. In the first, the tag is an ASCII code
  501|       |     * given by uint8_t tag above. System missing is represented by an ASCII
  502|       |     * period. In the second scheme, (tag-2) is an offset from 'A', except when
  503|       |     * tag == 0, in which case it represents an underscore, or tag == 1, in
  504|       |     * which case it represents system-missing.
  505|       |     */
  506|  4.31k|    if (tag == 0) {
  ------------------
  |  Branch (506:9): [True: 2.06k, False: 2.24k]
  ------------------
  507|  2.06k|        tag = '_';
  508|  2.24k|    } else if (tag >= 2 && tag < 28) {
  ------------------
  |  Branch (508:16): [True: 1.96k, False: 282]
  |  Branch (508:28): [True: 593, False: 1.37k]
  ------------------
  509|    593|        tag = 'A' + (tag - 2);
  510|    593|    }
  511|  4.31k|    if (sas_validate_tag(tag) == READSTAT_OK) {
  ------------------
  |  Branch (511:9): [True: 2.67k, False: 1.63k]
  ------------------
  512|  2.67k|        value->tag = tag;
  513|  2.67k|        value->is_tagged_missing = 1;
  514|  2.67k|    } else {
  515|  1.63k|        value->tag = 0;
  516|  1.63k|        value->is_system_missing = 1;
  517|  1.63k|    }
  518|  4.31k|}
readstat_sas.c:sas_epoch:
  123|  3.31k|static time_t sas_epoch() {
  124|  3.31k|    return - 3653 * 86400; // seconds between 01-01-1960 and 01-01-1970
  125|  3.31k|}
readstat_sas.c:sas_convert_time:
  127|  6.22k|static time_t sas_convert_time(double time, time_t epoch) {
  128|  6.22k|    time += epoch;
  129|  6.22k|    if (isnan(time))
  130|    778|        return 0;
  131|  5.44k|    if (time > (double)LONG_MAX)
  ------------------
  |  Branch (131:9): [True: 1.08k, False: 4.36k]
  ------------------
  132|  1.08k|        return LONG_MAX;
  133|  4.36k|    if (time < (double)LONG_MIN)
  ------------------
  |  Branch (133:9): [True: 1.27k, False: 3.08k]
  ------------------
  134|  1.27k|        return LONG_MIN;
  135|  3.08k|    return time;
  136|  4.36k|}

readstat_parse_sas7bdat:
 1166|  3.31k|readstat_error_t readstat_parse_sas7bdat(readstat_parser_t *parser, const char *path, void *user_ctx) {
 1167|  3.31k|    int64_t last_examined_page_pass1 = 0;
 1168|  3.31k|    readstat_error_t retval = READSTAT_OK;
 1169|  3.31k|    readstat_io_t *io = parser->io;
 1170|       |
 1171|  3.31k|    sas7bdat_ctx_t  *ctx = calloc(1, sizeof(sas7bdat_ctx_t));
 1172|  3.31k|    sas_header_info_t  *hinfo = calloc(1, sizeof(sas_header_info_t));
 1173|       |
 1174|  3.31k|    ctx->handle = parser->handlers;
 1175|  3.31k|    ctx->input_encoding = parser->input_encoding;
 1176|  3.31k|    ctx->output_encoding = parser->output_encoding;
 1177|  3.31k|    ctx->user_ctx = user_ctx;
 1178|  3.31k|    ctx->io = parser->io;
 1179|  3.31k|    ctx->row_limit = parser->row_limit;
 1180|  3.31k|    if (parser->row_offset > 0)
  ------------------
  |  Branch (1180:9): [True: 0, False: 3.31k]
  ------------------
 1181|      0|        ctx->row_offset = parser->row_offset;
 1182|       |
 1183|  3.31k|    if (io->open(path, io->io_ctx) == -1) {
  ------------------
  |  Branch (1183:9): [True: 0, False: 3.31k]
  ------------------
 1184|      0|        retval = READSTAT_ERROR_OPEN;
 1185|      0|        goto cleanup;
 1186|      0|    }
 1187|       |
 1188|  3.31k|    if ((ctx->file_size = io->seek(0, READSTAT_SEEK_END, io->io_ctx)) == -1) {
  ------------------
  |  Branch (1188:9): [True: 0, False: 3.31k]
  ------------------
 1189|      0|        retval = READSTAT_ERROR_SEEK;
 1190|      0|        if (ctx->handle.error) {
  ------------------
  |  Branch (1190:13): [True: 0, False: 0]
  ------------------
 1191|      0|            snprintf(ctx->error_buf, sizeof(ctx->error_buf), "ReadStat: Failed to seek to end of file");
 1192|      0|            ctx->handle.error(ctx->error_buf, ctx->user_ctx);
 1193|      0|        }
 1194|      0|        goto cleanup;
 1195|      0|    }
 1196|       |
 1197|  3.31k|    if (io->seek(0, READSTAT_SEEK_SET, io->io_ctx) == -1) {
  ------------------
  |  Branch (1197:9): [True: 0, False: 3.31k]
  ------------------
 1198|      0|        retval = READSTAT_ERROR_SEEK;
 1199|      0|        if (ctx->handle.error) {
  ------------------
  |  Branch (1199:13): [True: 0, False: 0]
  ------------------
 1200|      0|            snprintf(ctx->error_buf, sizeof(ctx->error_buf), "ReadStat: Failed to seek to beginning of file");
 1201|      0|            ctx->handle.error(ctx->error_buf, ctx->user_ctx);
 1202|      0|        }
 1203|      0|        goto cleanup;
 1204|      0|    }
 1205|       |
 1206|  3.31k|    if ((retval = sas_read_header(io, hinfo, ctx->handle.error, user_ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1206:9): [True: 513, False: 2.79k]
  ------------------
 1207|    513|        goto cleanup;
 1208|    513|    }
 1209|       |
 1210|  2.79k|    ctx->u64 = hinfo->u64;
 1211|  2.79k|    ctx->little_endian = hinfo->little_endian;
 1212|  2.79k|    ctx->vendor = hinfo->vendor;
 1213|  2.79k|    ctx->bswap = machine_is_little_endian() ^ hinfo->little_endian;
 1214|  2.79k|    ctx->header_size = hinfo->header_size;
 1215|  2.79k|    ctx->page_count = hinfo->page_count;
 1216|  2.79k|    ctx->page_size = hinfo->page_size;
 1217|  2.79k|    ctx->page_header_size = hinfo->page_header_size;
 1218|  2.79k|    ctx->subheader_pointer_size = hinfo->subheader_pointer_size;
 1219|  2.79k|    ctx->subheader_signature_size = ctx->u64 ? 8 : 4;
  ------------------
  |  Branch (1219:37): [True: 1.55k, False: 1.23k]
  ------------------
 1220|  2.79k|    ctx->ctime = hinfo->creation_time;
 1221|  2.79k|    ctx->mtime = hinfo->modification_time;
 1222|  2.79k|    ctx->version = hinfo->major_version;
 1223|  2.79k|    if (ctx->input_encoding == NULL) {
  ------------------
  |  Branch (1223:9): [True: 2.79k, False: 0]
  ------------------
 1224|  2.79k|        ctx->input_encoding = hinfo->encoding;
 1225|  2.79k|    }
 1226|  2.79k|    if ((ctx->page = readstat_malloc(ctx->page_size)) == NULL) {
  ------------------
  |  Branch (1226:9): [True: 0, False: 2.79k]
  ------------------
 1227|      0|        retval = READSTAT_ERROR_MALLOC;
 1228|      0|        goto cleanup;
 1229|      0|    }
 1230|       |
 1231|  2.79k|    if (ctx->input_encoding && ctx->output_encoding && strcmp(ctx->input_encoding, ctx->output_encoding) != 0) {
  ------------------
  |  Branch (1231:9): [True: 2.79k, False: 0]
  |  Branch (1231:32): [True: 2.79k, False: 0]
  |  Branch (1231:56): [True: 1.94k, False: 851]
  ------------------
 1232|  1.94k|        iconv_t converter = iconv_open(ctx->output_encoding, ctx->input_encoding);
 1233|  1.94k|        if (converter == (iconv_t)-1) {
  ------------------
  |  Branch (1233:13): [True: 1, False: 1.94k]
  ------------------
 1234|      1|            retval = READSTAT_ERROR_UNSUPPORTED_CHARSET;
 1235|      1|            goto cleanup;
 1236|      1|        }
 1237|  1.94k|        ctx->converter = converter;
 1238|  1.94k|    }
 1239|       |
 1240|  2.79k|    if ((retval = readstat_convert(ctx->table_name, sizeof(ctx->table_name),
  ------------------
  |  Branch (1240:9): [True: 4, False: 2.79k]
  ------------------
 1241|  2.79k|                hinfo->table_name, sizeof(hinfo->table_name), ctx->converter)) != READSTAT_OK) {
 1242|      4|        goto cleanup;
 1243|      4|    }
 1244|       |
 1245|  2.79k|    if ((retval = sas7bdat_parse_meta_pages_pass1(ctx, &last_examined_page_pass1)) != READSTAT_OK) {
  ------------------
  |  Branch (1245:9): [True: 235, False: 2.55k]
  ------------------
 1246|    235|        goto cleanup;
 1247|    235|    }
 1248|       |
 1249|  2.55k|    if ((retval = sas7bdat_parse_amd_pages_pass1(last_examined_page_pass1, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1249:9): [True: 593, False: 1.96k]
  ------------------
 1250|    593|        goto cleanup;
 1251|    593|    }
 1252|       |
 1253|  1.96k|    if (io->seek(ctx->header_size, READSTAT_SEEK_SET, io->io_ctx) == -1) {
  ------------------
  |  Branch (1253:9): [True: 0, False: 1.96k]
  ------------------
 1254|      0|        retval = READSTAT_ERROR_SEEK;
 1255|      0|        if (ctx->handle.error) {
  ------------------
  |  Branch (1255:13): [True: 0, False: 0]
  ------------------
 1256|      0|            snprintf(ctx->error_buf, sizeof(ctx->error_buf), "ReadStat: Failed to seek to position %" PRId64, 
 1257|      0|                    ctx->header_size);
 1258|      0|            ctx->handle.error(ctx->error_buf, ctx->user_ctx);
 1259|      0|        }
 1260|      0|        goto cleanup;
 1261|      0|    }
 1262|       |
 1263|  1.96k|    if ((retval = sas7bdat_parse_all_pages_pass2(ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1263:9): [True: 1.61k, False: 352]
  ------------------
 1264|  1.61k|        goto cleanup;
 1265|  1.61k|    }
 1266|       |    
 1267|    352|    if ((retval = sas7bdat_submit_columns_if_needed(ctx, 0)) != READSTAT_OK) {
  ------------------
  |  Branch (1267:9): [True: 112, False: 240]
  ------------------
 1268|    112|        goto cleanup;
 1269|    112|    }
 1270|       |
 1271|    240|    if (ctx->handle.value && ctx->parsed_row_count != ctx->row_limit) {
  ------------------
  |  Branch (1271:9): [True: 240, False: 0]
  |  Branch (1271:30): [True: 105, False: 135]
  ------------------
 1272|    105|        retval = READSTAT_ERROR_ROW_COUNT_MISMATCH;
 1273|    105|        if (ctx->handle.error) {
  ------------------
  |  Branch (1273:13): [True: 0, False: 105]
  ------------------
 1274|      0|            snprintf(ctx->error_buf, sizeof(ctx->error_buf), "ReadStat: Expected %d rows in file, found %d",
 1275|      0|                    ctx->row_limit, ctx->parsed_row_count);
 1276|      0|            ctx->handle.error(ctx->error_buf, ctx->user_ctx);
 1277|      0|        }
 1278|    105|        goto cleanup;
 1279|    105|    }
 1280|       |
 1281|    135|    if ((retval = sas7bdat_update_progress(ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1281:9): [True: 0, False: 135]
  ------------------
 1282|      0|        goto cleanup;
 1283|      0|    }
 1284|       |
 1285|  3.31k|cleanup:
 1286|  3.31k|    io->close(io->io_ctx);
 1287|       |
 1288|  3.31k|    if (retval == READSTAT_ERROR_OPEN ||
  ------------------
  |  Branch (1288:9): [True: 0, False: 3.31k]
  ------------------
 1289|  3.31k|            retval == READSTAT_ERROR_READ ||
  ------------------
  |  Branch (1289:13): [True: 397, False: 2.91k]
  ------------------
 1290|  3.31k|            retval == READSTAT_ERROR_SEEK) {
  ------------------
  |  Branch (1290:13): [True: 382, False: 2.53k]
  ------------------
 1291|    779|        if (ctx->handle.error) {
  ------------------
  |  Branch (1291:13): [True: 0, False: 779]
  ------------------
 1292|      0|            snprintf(ctx->error_buf, sizeof(ctx->error_buf), "ReadStat: %s (retval = %d): %s (errno = %d)", 
 1293|      0|                    readstat_error_message(retval), retval, strerror(errno), errno);
 1294|      0|            ctx->handle.error(ctx->error_buf, user_ctx);
 1295|      0|        }
 1296|    779|    }
 1297|       |
 1298|  3.31k|    if (ctx)
  ------------------
  |  Branch (1298:9): [True: 3.31k, False: 0]
  ------------------
 1299|  3.31k|        sas7bdat_ctx_free(ctx);
 1300|  3.31k|    if (hinfo)
  ------------------
  |  Branch (1300:9): [True: 3.31k, False: 0]
  ------------------
 1301|  3.31k|        free(hinfo);
 1302|       |
 1303|  3.31k|    return retval;
 1304|    135|}
readstat_sas7bdat_read.c:sas7bdat_parse_meta_pages_pass1:
 1007|  2.79k|static readstat_error_t sas7bdat_parse_meta_pages_pass1(sas7bdat_ctx_t *ctx, int64_t *outLastExaminedPage) {
 1008|  2.79k|    readstat_error_t retval = READSTAT_OK;
 1009|  2.79k|    readstat_io_t *io = ctx->io;
 1010|  2.79k|    int64_t i;
 1011|       |
 1012|       |    /* look for META and MIX pages at beginning... */
 1013|  7.81k|    for (i=0; i<ctx->page_count; i++) {
  ------------------
  |  Branch (1013:15): [True: 5.77k, False: 2.03k]
  ------------------
 1014|  5.77k|        if (io->seek(ctx->header_size + i*ctx->page_size, READSTAT_SEEK_SET, io->io_ctx) == -1) {
  ------------------
  |  Branch (1014:13): [True: 8, False: 5.76k]
  ------------------
 1015|      8|            retval = READSTAT_ERROR_SEEK;
 1016|      8|            if (ctx->handle.error) {
  ------------------
  |  Branch (1016:17): [True: 0, False: 8]
  ------------------
 1017|      0|                snprintf(ctx->error_buf, sizeof(ctx->error_buf), "ReadStat: Failed to seek to position %" PRId64 
 1018|      0|                        " (= %" PRId64 " + %" PRId64 "*%" PRId64 ")",
 1019|      0|                        ctx->header_size + i*ctx->page_size, ctx->header_size, i, ctx->page_size);
 1020|      0|                ctx->handle.error(ctx->error_buf, ctx->user_ctx);
 1021|      0|            }
 1022|      8|            goto cleanup;
 1023|      8|        }
 1024|       |
 1025|  5.76k|        readstat_off_t off = 0;
 1026|  5.76k|        if (ctx->u64)
  ------------------
  |  Branch (1026:13): [True: 4.02k, False: 1.74k]
  ------------------
 1027|  4.02k|            off = 16;
 1028|       |
 1029|  5.76k|        size_t head_len = off + 16 + 2;
 1030|  5.76k|        size_t tail_len = ctx->page_size - head_len;
 1031|       |
 1032|  5.76k|        if (io->read(ctx->page, head_len, io->io_ctx) < head_len) {
  ------------------
  |  Branch (1032:13): [True: 156, False: 5.61k]
  ------------------
 1033|    156|            retval = READSTAT_ERROR_READ;
 1034|    156|            goto cleanup;
 1035|    156|        }
 1036|       |
 1037|  5.61k|        uint16_t page_type = sas_read2(&ctx->page[off+16], ctx->bswap);
 1038|       |
 1039|  5.61k|        if ((page_type & SAS_PAGE_TYPE_MASK) == SAS_PAGE_TYPE_DATA)
  ------------------
  |  |   96|  5.61k|#define SAS_PAGE_TYPE_MASK   0x0F00
  ------------------
                      if ((page_type & SAS_PAGE_TYPE_MASK) == SAS_PAGE_TYPE_DATA)
  ------------------
  |  |   93|  5.61k|#define SAS_PAGE_TYPE_DATA   0x0100
  ------------------
  |  Branch (1039:13): [True: 519, False: 5.09k]
  ------------------
 1040|    519|            break;
 1041|  5.09k|        if ((page_type & SAS_PAGE_TYPE_COMP))
  ------------------
  |  |   99|  5.09k|#define SAS_PAGE_TYPE_COMP   0x9000
  ------------------
  |  Branch (1041:13): [True: 1.20k, False: 3.88k]
  ------------------
 1042|  1.20k|            continue;
 1043|       |
 1044|  3.88k|        if (io->read(ctx->page + head_len, tail_len, io->io_ctx) < tail_len) {
  ------------------
  |  Branch (1044:13): [True: 24, False: 3.86k]
  ------------------
 1045|     24|            retval = READSTAT_ERROR_READ;
 1046|     24|            goto cleanup;
 1047|     24|        }
 1048|       |
 1049|  3.86k|        if ((retval = sas7bdat_parse_page_pass1(ctx->page, ctx->page_size, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1049:13): [True: 47, False: 3.81k]
  ------------------
 1050|     47|            if (ctx->handle.error && retval != READSTAT_ERROR_USER_ABORT) {
  ------------------
  |  Branch (1050:17): [True: 0, False: 47]
  |  Branch (1050:38): [True: 0, False: 0]
  ------------------
 1051|      0|                int64_t pos = io->seek(0, READSTAT_SEEK_CUR, io->io_ctx);
 1052|      0|                snprintf(ctx->error_buf, sizeof(ctx->error_buf), 
 1053|      0|                        "ReadStat: Error parsing page %" PRId64 ", bytes %" PRId64 "-%" PRId64, 
 1054|      0|                        i, pos - ctx->page_size, pos-1);
 1055|      0|                ctx->handle.error(ctx->error_buf, ctx->user_ctx);
 1056|      0|            }
 1057|     47|            goto cleanup;
 1058|     47|        }
 1059|  3.86k|    }
 1060|       |
 1061|  2.79k|cleanup:
 1062|  2.79k|    if (outLastExaminedPage)
  ------------------
  |  Branch (1062:9): [True: 2.79k, False: 0]
  ------------------
 1063|  2.79k|        *outLastExaminedPage = i;
 1064|       |
 1065|  2.79k|    return retval;
 1066|  2.79k|}
readstat_sas7bdat_read.c:sas7bdat_parse_page_pass1:
  854|  6.39k|static readstat_error_t sas7bdat_parse_page_pass1(const char *page, size_t page_size, sas7bdat_ctx_t *ctx) {
  855|  6.39k|    readstat_error_t retval = READSTAT_OK;
  856|       |
  857|  6.39k|    uint16_t subheader_count = sas_read2(&page[ctx->page_header_size-4], ctx->bswap);
  858|       |
  859|  6.39k|    int i;
  860|  6.39k|    const char *shp = &page[ctx->page_header_size];
  861|  6.39k|    int lshp = ctx->subheader_pointer_size;
  862|       |
  863|  6.39k|    if (ctx->page_header_size + subheader_count*lshp > page_size) {
  ------------------
  |  Branch (863:9): [True: 33, False: 6.35k]
  ------------------
  864|     33|        retval = READSTAT_ERROR_PARSE;
  865|     33|        goto cleanup;
  866|     33|    }
  867|       |
  868|  68.4k|    for (i=0; i<subheader_count; i++) {
  ------------------
  |  Branch (868:15): [True: 62.4k, False: 5.99k]
  ------------------
  869|  62.4k|        subheader_pointer_t shp_info = { 0 };
  870|  62.4k|        uint32_t signature = 0;
  871|  62.4k|        size_t signature_len = ctx->subheader_signature_size;
  872|  62.4k|        if ((retval = sas7bdat_parse_subheader_pointer(shp, page + page_size - shp, &shp_info, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (872:13): [True: 0, False: 62.4k]
  ------------------
  873|      0|            goto cleanup;
  874|      0|        }
  875|  62.4k|        if (shp_info.len > 0 && shp_info.compression != SAS_COMPRESSION_TRUNC) {
  ------------------
  |  |  108|  39.7k|#define SAS_COMPRESSION_TRUNC  0x01
  ------------------
  |  Branch (875:13): [True: 39.7k, False: 22.7k]
  |  Branch (875:33): [True: 33.3k, False: 6.37k]
  ------------------
  876|  33.3k|            if ((retval = sas7bdat_validate_subheader_pointer(&shp_info, page_size, subheader_count, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (876:17): [True: 292, False: 33.0k]
  ------------------
  877|    292|                goto cleanup;
  878|    292|            }
  879|  33.0k|            if (shp_info.compression == SAS_COMPRESSION_NONE) {
  ------------------
  |  |  107|  33.0k|#define SAS_COMPRESSION_NONE   0x00
  ------------------
  |  Branch (879:17): [True: 29.8k, False: 3.22k]
  ------------------
  880|  29.8k|                signature = sas_read4(page + shp_info.offset, ctx->bswap);
  881|  29.8k|                if (!ctx->little_endian && signature == -1 && signature_len == 8) {
  ------------------
  |  Branch (881:21): [True: 23.5k, False: 6.30k]
  |  Branch (881:44): [True: 3.01k, False: 20.4k]
  |  Branch (881:63): [True: 1.78k, False: 1.22k]
  ------------------
  882|  1.78k|                    signature = sas_read4(page + shp_info.offset + 4, ctx->bswap);
  883|  1.78k|                }
  884|  29.8k|                if (signature == SAS_SUBHEADER_SIGNATURE_COLUMN_TEXT) {
  ------------------
  |  |   88|  29.8k|#define SAS_SUBHEADER_SIGNATURE_COLUMN_TEXT    0xFFFFFFFD
  ------------------
  |  Branch (884:21): [True: 2.99k, False: 26.8k]
  ------------------
  885|  2.99k|                    if ((retval = sas7bdat_parse_subheader(signature, page + shp_info.offset, shp_info.len, ctx))
  ------------------
  |  Branch (885:25): [True: 60, False: 2.93k]
  ------------------
  886|  2.99k|                            != READSTAT_OK) {
  887|     60|                        goto cleanup;
  888|     60|                    }
  889|  2.99k|                }
  890|  29.8k|            } else if (shp_info.compression == SAS_COMPRESSION_ROW) {
  ------------------
  |  |  109|  3.22k|#define SAS_COMPRESSION_ROW    0x04
  ------------------
  |  Branch (890:24): [True: 3.21k, False: 11]
  ------------------
  891|       |                /* void */
  892|  3.21k|            } else {
  893|     11|                retval = READSTAT_ERROR_UNSUPPORTED_COMPRESSION;
  894|     11|                goto cleanup;
  895|     11|            }
  896|  33.0k|        }
  897|       |
  898|  62.1k|        shp += lshp;
  899|  62.1k|    }
  900|       |
  901|  6.39k|cleanup:
  902|       |
  903|  6.39k|    return retval;
  904|  6.35k|}
readstat_sas7bdat_read.c:sas7bdat_parse_subheader_pointer:
  808|   105k|        subheader_pointer_t *info, sas7bdat_ctx_t *ctx) {
  809|   105k|    readstat_error_t retval = READSTAT_OK;
  810|   105k|    if (ctx->u64) {
  ------------------
  |  Branch (810:9): [True: 29.7k, False: 75.8k]
  ------------------
  811|  29.7k|        if (shp_size <= 17) {
  ------------------
  |  Branch (811:13): [True: 0, False: 29.7k]
  ------------------
  812|      0|            retval = READSTAT_ERROR_PARSE;
  813|      0|            goto cleanup;
  814|      0|        }
  815|  29.7k|        info->offset = sas_read8(&shp[0], ctx->bswap);
  816|  29.7k|        info->len = sas_read8(&shp[8], ctx->bswap);
  817|  29.7k|        info->compression = shp[16];
  818|  29.7k|        info->is_compressed_data = shp[17];
  819|  75.8k|    } else {
  820|  75.8k|        if (shp_size <= 9) {
  ------------------
  |  Branch (820:13): [True: 0, False: 75.8k]
  ------------------
  821|      0|            retval = READSTAT_ERROR_PARSE;
  822|      0|            goto cleanup;
  823|      0|        }
  824|  75.8k|        info->offset = sas_read4(&shp[0], ctx->bswap);
  825|  75.8k|        info->len = sas_read4(&shp[4], ctx->bswap);
  826|  75.8k|        info->compression = shp[8];
  827|  75.8k|        info->is_compressed_data = shp[9];
  828|  75.8k|    }
  829|   105k|cleanup:
  830|   105k|    return retval;
  831|   105k|}
readstat_sas7bdat_read.c:sas7bdat_validate_subheader_pointer:
  834|  58.7k|        uint16_t subheader_count, sas7bdat_ctx_t *ctx) {
  835|  58.7k|    if (shp_info->offset > page_size)
  ------------------
  |  Branch (835:9): [True: 233, False: 58.5k]
  ------------------
  836|    233|        return READSTAT_ERROR_PARSE;
  837|  58.5k|    if (shp_info->len > page_size)
  ------------------
  |  Branch (837:9): [True: 209, False: 58.3k]
  ------------------
  838|    209|        return READSTAT_ERROR_PARSE;
  839|  58.3k|    if (shp_info->offset + shp_info->len > page_size)
  ------------------
  |  Branch (839:9): [True: 33, False: 58.2k]
  ------------------
  840|     33|        return READSTAT_ERROR_PARSE;
  841|  58.2k|    if (shp_info->offset < ctx->page_header_size + subheader_count*ctx->subheader_pointer_size)
  ------------------
  |  Branch (841:9): [True: 9, False: 58.2k]
  ------------------
  842|      9|        return READSTAT_ERROR_PARSE;
  843|  58.2k|    if (shp_info->compression == SAS_COMPRESSION_NONE) {
  ------------------
  |  |  107|  58.2k|#define SAS_COMPRESSION_NONE   0x00
  ------------------
  |  Branch (843:9): [True: 53.5k, False: 4.68k]
  ------------------
  844|  53.5k|        if (shp_info->len < ctx->subheader_signature_size)
  ------------------
  |  Branch (844:13): [True: 3, False: 53.5k]
  ------------------
  845|      3|            return READSTAT_ERROR_PARSE;
  846|  53.5k|        if (shp_info->offset + ctx->subheader_signature_size > page_size)
  ------------------
  |  Branch (846:13): [True: 0, False: 53.5k]
  ------------------
  847|      0|            return READSTAT_ERROR_PARSE;
  848|  53.5k|    }
  849|       |    
  850|  58.2k|    return READSTAT_OK;
  851|  58.2k|}
readstat_sas7bdat_read.c:sas7bdat_parse_subheader:
  626|  23.0k|static readstat_error_t sas7bdat_parse_subheader(uint32_t signature, const char *subheader, size_t len, sas7bdat_ctx_t *ctx) {
  627|  23.0k|    readstat_error_t retval = READSTAT_OK;
  628|       |
  629|  23.0k|    if (len < 2 + ctx->subheader_signature_size) {
  ------------------
  |  Branch (629:9): [True: 10, False: 23.0k]
  ------------------
  630|     10|        retval = READSTAT_ERROR_PARSE;
  631|     10|        goto cleanup;
  632|     10|    }
  633|  23.0k|    if (signature == SAS_SUBHEADER_SIGNATURE_ROW_SIZE) {
  ------------------
  |  |   79|  23.0k|#define SAS_SUBHEADER_SIGNATURE_ROW_SIZE       0xF7F7F7F7
  ------------------
  |  Branch (633:9): [True: 7.54k, False: 15.4k]
  ------------------
  634|  7.54k|        retval = sas7bdat_parse_row_size_subheader(subheader, len, ctx);
  635|  15.4k|    } else if (signature == SAS_SUBHEADER_SIGNATURE_COLUMN_SIZE) {
  ------------------
  |  |   80|  15.4k|#define SAS_SUBHEADER_SIGNATURE_COLUMN_SIZE    0xF6F6F6F6
  ------------------
  |  Branch (635:16): [True: 1.23k, False: 14.2k]
  ------------------
  636|  1.23k|        retval = sas7bdat_parse_column_size_subheader(subheader, len, ctx);
  637|  14.2k|    } else if (signature == SAS_SUBHEADER_SIGNATURE_COUNTS) {
  ------------------
  |  |   81|  14.2k|#define SAS_SUBHEADER_SIGNATURE_COUNTS         0xFFFFFC00
  ------------------
  |  Branch (637:16): [True: 903, False: 13.3k]
  ------------------
  638|       |        /* void */
  639|  13.3k|    } else if (signature == SAS_SUBHEADER_SIGNATURE_COLUMN_TEXT) {
  ------------------
  |  |   88|  13.3k|#define SAS_SUBHEADER_SIGNATURE_COLUMN_TEXT    0xFFFFFFFD
  ------------------
  |  Branch (639:16): [True: 2.99k, False: 10.3k]
  ------------------
  640|  2.99k|        retval = sas7bdat_parse_column_text_subheader(subheader, len, ctx);
  641|  10.3k|    } else if (signature == SAS_SUBHEADER_SIGNATURE_COLUMN_NAME) {
  ------------------
  |  |   90|  10.3k|#define SAS_SUBHEADER_SIGNATURE_COLUMN_NAME    0xFFFFFFFF
  ------------------
  |  Branch (641:16): [True: 1.49k, False: 8.84k]
  ------------------
  642|  1.49k|        retval = sas7bdat_parse_column_name_subheader(subheader, len, ctx);
  643|  8.84k|    } else if (signature == SAS_SUBHEADER_SIGNATURE_COLUMN_ATTRS) {
  ------------------
  |  |   87|  8.84k|#define SAS_SUBHEADER_SIGNATURE_COLUMN_ATTRS   0xFFFFFFFC
  ------------------
  |  Branch (643:16): [True: 2.73k, False: 6.11k]
  ------------------
  644|  2.73k|        retval = sas7bdat_parse_column_attributes_subheader(subheader, len, ctx);
  645|  6.11k|    } else if (signature == SAS_SUBHEADER_SIGNATURE_COLUMN_FORMAT) {
  ------------------
  |  |   82|  6.11k|#define SAS_SUBHEADER_SIGNATURE_COLUMN_FORMAT  0xFFFFFBFE
  ------------------
  |  Branch (645:16): [True: 4.30k, False: 1.81k]
  ------------------
  646|  4.30k|        retval = sas7bdat_parse_column_format_subheader(subheader, len, ctx);
  647|  4.30k|    } else if (signature == SAS_SUBHEADER_SIGNATURE_COLUMN_LIST) {
  ------------------
  |  |   89|  1.81k|#define SAS_SUBHEADER_SIGNATURE_COLUMN_LIST    0xFFFFFFFE
  ------------------
  |  Branch (647:16): [True: 1.12k, False: 684]
  ------------------
  648|       |        /* void */
  649|  1.12k|    } else if ((signature & SAS_SUBHEADER_SIGNATURE_COLUMN_MASK) == SAS_SUBHEADER_SIGNATURE_COLUMN_MASK) {
  ------------------
  |  |   84|    684|#define SAS_SUBHEADER_SIGNATURE_COLUMN_MASK    0xFFFFFFF8
  ------------------
                  } else if ((signature & SAS_SUBHEADER_SIGNATURE_COLUMN_MASK) == SAS_SUBHEADER_SIGNATURE_COLUMN_MASK) {
  ------------------
  |  |   84|    684|#define SAS_SUBHEADER_SIGNATURE_COLUMN_MASK    0xFFFFFFF8
  ------------------
  |  Branch (649:16): [True: 516, False: 168]
  ------------------
  650|       |        /* void */
  651|    516|    } else {
  652|    168|        retval = READSTAT_ERROR_PARSE;
  653|    168|    }
  654|       |
  655|  23.0k|cleanup:
  656|       |
  657|  23.0k|    return retval;
  658|  23.0k|}
readstat_sas7bdat_read.c:sas7bdat_parse_row_size_subheader:
  231|  7.54k|static readstat_error_t sas7bdat_parse_row_size_subheader(const char *subheader, size_t len, sas7bdat_ctx_t *ctx) {
  232|  7.54k|    readstat_error_t retval = READSTAT_OK;
  233|  7.54k|    uint64_t total_row_count;
  234|  7.54k|    uint64_t row_length, page_row_count;
  235|       |
  236|  7.54k|    if (len < (ctx->u64 ? 250: 190)) {
  ------------------
  |  Branch (236:9): [True: 15, False: 7.52k]
  |  Branch (236:16): [True: 5.79k, False: 1.75k]
  ------------------
  237|     15|        retval = READSTAT_ERROR_PARSE;
  238|     15|        goto cleanup;
  239|     15|    }
  240|       |
  241|  7.52k|    if (ctx->u64) {
  ------------------
  |  Branch (241:9): [True: 5.78k, False: 1.74k]
  ------------------
  242|  5.78k|        row_length = sas_read8(&subheader[40], ctx->bswap);
  243|  5.78k|        total_row_count = sas_read8(&subheader[48], ctx->bswap);
  244|  5.78k|        page_row_count = sas_read8(&subheader[120], ctx->bswap);
  245|  5.78k|    } else {
  246|  1.74k|        row_length = sas_read4(&subheader[20], ctx->bswap);
  247|  1.74k|        total_row_count = sas_read4(&subheader[24], ctx->bswap);
  248|  1.74k|        page_row_count = sas_read4(&subheader[60], ctx->bswap);
  249|  1.74k|    }
  250|       |
  251|  7.52k|    sas_text_ref_t file_label_ref = sas7bdat_parse_text_ref(&subheader[len-130], ctx);
  252|  7.52k|    if (file_label_ref.length) {
  ------------------
  |  Branch (252:9): [True: 737, False: 6.79k]
  ------------------
  253|    737|        if ((retval = sas7bdat_copy_text_ref(ctx->file_label, sizeof(ctx->file_label),
  ------------------
  |  Branch (253:13): [True: 52, False: 685]
  ------------------
  254|    737|                        file_label_ref, ctx)) != READSTAT_OK) {
  255|     52|            goto cleanup;
  256|     52|        }
  257|    737|    }
  258|       |
  259|  7.47k|    sas_text_ref_t compression_ref = sas7bdat_parse_text_ref(&subheader[len-118], ctx);
  260|  7.47k|    if (compression_ref.length) {
  ------------------
  |  Branch (260:9): [True: 838, False: 6.63k]
  ------------------
  261|    838|        char compression[9];
  262|    838|        if ((retval = sas7bdat_copy_text_ref(compression, sizeof(compression),
  ------------------
  |  Branch (262:13): [True: 46, False: 792]
  ------------------
  263|    838|                        compression_ref, ctx)) != READSTAT_OK) {
  264|     46|            goto cleanup;
  265|     46|        }
  266|    792|        ctx->rdc_compression = (memcmp(compression, SAS_COMPRESSION_SIGNATURE_RDC, 8) == 0);
  ------------------
  |  |  112|    792|#define SAS_COMPRESSION_SIGNATURE_RDC  "SASYZCR2"
  ------------------
  267|    792|    }
  268|       |
  269|  7.43k|    ctx->row_length = row_length;
  270|  7.43k|    ctx->row = readstat_realloc(ctx->row, ctx->row_length);
  271|  7.43k|    if (ctx->row == NULL) {
  ------------------
  |  Branch (271:9): [True: 13, False: 7.41k]
  ------------------
  272|     13|        retval = READSTAT_ERROR_MALLOC;
  273|     13|        goto cleanup;
  274|     13|    }
  275|       |
  276|  7.41k|    ctx->page_row_count = page_row_count;
  277|  7.41k|    uint64_t total_row_count_after_skipping = total_row_count;
  278|  7.41k|    if (total_row_count > ctx->row_offset) {
  ------------------
  |  Branch (278:9): [True: 5.21k, False: 2.20k]
  ------------------
  279|  5.21k|        total_row_count_after_skipping -= ctx->row_offset;
  280|  5.21k|    } else {
  281|  2.20k|        total_row_count_after_skipping = 0;
  282|  2.20k|        ctx->row_offset = total_row_count;
  283|  2.20k|    }
  284|  7.41k|    if (ctx->row_limit == 0 || total_row_count_after_skipping < ctx->row_limit)
  ------------------
  |  Branch (284:9): [True: 3.67k, False: 3.74k]
  |  Branch (284:32): [True: 872, False: 2.87k]
  ------------------
  285|  4.54k|        ctx->row_limit = total_row_count_after_skipping;
  286|       |
  287|  7.54k|cleanup:
  288|  7.54k|    return retval;
  289|  7.41k|}
readstat_sas7bdat_read.c:sas7bdat_parse_text_ref:
  132|  45.4k|static sas_text_ref_t sas7bdat_parse_text_ref(const char *data, sas7bdat_ctx_t *ctx) {
  133|  45.4k|    sas_text_ref_t  ref;
  134|       |
  135|  45.4k|    ref.index = sas_read2(&data[0], ctx->bswap);
  136|  45.4k|    ref.offset = sas_read2(&data[2], ctx->bswap);
  137|  45.4k|    ref.length = sas_read2(&data[4], ctx->bswap);
  138|       |
  139|  45.4k|    return ref;
  140|  45.4k|}
readstat_sas7bdat_read.c:sas7bdat_copy_text_ref:
  142|  8.05k|static readstat_error_t sas7bdat_copy_text_ref(char *out_buffer, size_t out_buffer_len, sas_text_ref_t text_ref, sas7bdat_ctx_t *ctx) {
  143|  8.05k|    if (text_ref.index >= ctx->text_blob_count)
  ------------------
  |  Branch (143:9): [True: 119, False: 7.93k]
  ------------------
  144|    119|        return READSTAT_ERROR_PARSE;
  145|       |    
  146|  7.93k|    if (text_ref.length == 0) {
  ------------------
  |  Branch (146:9): [True: 5.01k, False: 2.91k]
  ------------------
  147|  5.01k|        out_buffer[0] = '\0';
  148|  5.01k|        return READSTAT_OK;
  149|  5.01k|    }
  150|       |
  151|  2.91k|    char *blob = ctx->text_blobs[text_ref.index];
  152|       |
  153|  2.91k|    if (text_ref.offset + text_ref.length > ctx->text_blob_lengths[text_ref.index])
  ------------------
  |  Branch (153:9): [True: 86, False: 2.82k]
  ------------------
  154|     86|        return READSTAT_ERROR_PARSE;
  155|       |
  156|  2.82k|    return readstat_convert(out_buffer, out_buffer_len, &blob[text_ref.offset], text_ref.length,
  157|  2.82k|            ctx->converter);
  158|  2.91k|}
readstat_sas7bdat_read.c:sas7bdat_parse_column_size_subheader:
  203|  1.23k|static readstat_error_t sas7bdat_parse_column_size_subheader(const char *subheader, size_t len, sas7bdat_ctx_t *ctx) {
  204|  1.23k|    uint64_t col_count;
  205|  1.23k|    readstat_error_t retval = READSTAT_OK;
  206|       |
  207|  1.23k|    if (ctx->column_count || ctx->did_submit_columns) {
  ------------------
  |  Branch (207:9): [True: 20, False: 1.21k]
  |  Branch (207:30): [True: 1, False: 1.21k]
  ------------------
  208|     21|        retval = READSTAT_ERROR_PARSE;
  209|     21|        goto cleanup;
  210|     21|    }
  211|       |
  212|  1.21k|    if (len < (ctx->u64 ? 16 : 8)) {
  ------------------
  |  Branch (212:9): [True: 1, False: 1.21k]
  |  Branch (212:16): [True: 303, False: 911]
  ------------------
  213|      1|        retval = READSTAT_ERROR_PARSE;
  214|      1|        goto cleanup;
  215|      1|    }
  216|       |
  217|  1.21k|    if (ctx->u64) {
  ------------------
  |  Branch (217:9): [True: 303, False: 910]
  ------------------
  218|    303|        col_count = sas_read8(&subheader[8], ctx->bswap);
  219|    910|    } else {
  220|    910|        col_count = sas_read4(&subheader[4], ctx->bswap);
  221|    910|    }
  222|       |
  223|  1.21k|    ctx->column_count = col_count;
  224|       |
  225|  1.21k|    retval = sas7bdat_realloc_col_info(ctx, ctx->column_count);
  226|       |
  227|  1.23k|cleanup:
  228|  1.23k|    return retval;
  229|  1.21k|}
readstat_sas7bdat_read.c:sas7bdat_realloc_col_info:
  190|  9.61k|static readstat_error_t sas7bdat_realloc_col_info(sas7bdat_ctx_t *ctx, size_t count) {
  191|  9.61k|    if (ctx->col_info_count < count) {
  ------------------
  |  Branch (191:9): [True: 4.71k, False: 4.90k]
  ------------------
  192|  4.71k|        size_t old_count = ctx->col_info_count;
  193|  4.71k|        ctx->col_info_count = count;
  194|  4.71k|        ctx->col_info = readstat_realloc(ctx->col_info, ctx->col_info_count * sizeof(col_info_t));
  195|  4.71k|        if (ctx->col_info == NULL) {
  ------------------
  |  Branch (195:13): [True: 78, False: 4.63k]
  ------------------
  196|     78|            return READSTAT_ERROR_MALLOC;
  197|     78|        }
  198|  4.63k|        memset(ctx->col_info + old_count, 0, (count - old_count) * sizeof(col_info_t));
  199|  4.63k|    }
  200|  9.54k|    return READSTAT_OK;
  201|  9.61k|}
readstat_sas7bdat_read.c:sas7bdat_parse_column_text_subheader:
  160|  2.99k|static readstat_error_t sas7bdat_parse_column_text_subheader(const char *subheader, size_t len, sas7bdat_ctx_t *ctx) {
  161|  2.99k|    readstat_error_t retval = READSTAT_OK;
  162|  2.99k|    size_t signature_len = ctx->subheader_signature_size;
  163|  2.99k|    uint16_t remainder = sas_read2(&subheader[signature_len], ctx->bswap);
  164|  2.99k|    char *blob = NULL;
  165|  2.99k|    if (remainder != sas_subheader_remainder(len, signature_len)) {
  ------------------
  |  Branch (165:9): [True: 58, False: 2.93k]
  ------------------
  166|     58|        retval = READSTAT_ERROR_PARSE;
  167|     58|        goto cleanup;
  168|     58|    }
  169|  2.93k|    ctx->text_blob_count++;
  170|  2.93k|    ctx->text_blobs = readstat_realloc(ctx->text_blobs, ctx->text_blob_count * sizeof(char *));
  171|  2.93k|    ctx->text_blob_lengths = readstat_realloc(ctx->text_blob_lengths,
  172|  2.93k|            ctx->text_blob_count * sizeof(ctx->text_blob_lengths[0]));
  173|  2.93k|    if (ctx->text_blobs == NULL || ctx->text_blob_lengths == NULL) {
  ------------------
  |  Branch (173:9): [True: 0, False: 2.93k]
  |  Branch (173:36): [True: 0, False: 2.93k]
  ------------------
  174|      0|        retval = READSTAT_ERROR_MALLOC;
  175|      0|        goto cleanup;
  176|      0|    }
  177|       |
  178|  2.93k|    if ((blob = readstat_malloc(len-signature_len)) == NULL) {
  ------------------
  |  Branch (178:9): [True: 0, False: 2.93k]
  ------------------
  179|      0|        retval = READSTAT_ERROR_MALLOC;
  180|      0|        goto cleanup;
  181|      0|    }
  182|  2.93k|    memcpy(blob, subheader+signature_len, len-signature_len);
  183|  2.93k|    ctx->text_blob_lengths[ctx->text_blob_count-1] = len-signature_len;
  184|  2.93k|    ctx->text_blobs[ctx->text_blob_count-1] = blob;
  185|       |
  186|  2.99k|cleanup:
  187|  2.99k|    return retval;
  188|  2.93k|}
readstat_sas7bdat_read.c:sas7bdat_parse_column_name_subheader:
  291|  1.49k|static readstat_error_t sas7bdat_parse_column_name_subheader(const char *subheader, size_t len, sas7bdat_ctx_t *ctx) {
  292|  1.49k|    readstat_error_t retval = READSTAT_OK;
  293|  1.49k|    size_t signature_len = ctx->subheader_signature_size;
  294|  1.49k|    int cmax = ctx->u64 ? (len-28)/8 : (len-20)/8;
  ------------------
  |  Branch (294:16): [True: 161, False: 1.33k]
  ------------------
  295|  1.49k|    int i;
  296|  1.49k|    const char *cnp = &subheader[signature_len+8];
  297|  1.49k|    uint16_t remainder = sas_read2(&subheader[signature_len], ctx->bswap);
  298|       |
  299|  1.49k|    if (remainder != sas_subheader_remainder(len, signature_len)) {
  ------------------
  |  Branch (299:9): [True: 64, False: 1.43k]
  ------------------
  300|     64|        retval = READSTAT_ERROR_PARSE;
  301|     64|        goto cleanup;
  302|     64|    }
  303|       |
  304|  1.43k|    ctx->col_names_count += cmax;
  305|       |
  306|  1.43k|    if ((retval = sas7bdat_realloc_col_info(ctx, ctx->col_names_count)) != READSTAT_OK)
  ------------------
  |  Branch (306:9): [True: 18, False: 1.41k]
  ------------------
  307|     18|        goto cleanup;
  308|       |
  309|  23.2k|    for (i=ctx->col_names_count-cmax; i<ctx->col_names_count; i++) {
  ------------------
  |  Branch (309:39): [True: 21.8k, False: 1.41k]
  ------------------
  310|  21.8k|        ctx->col_info[i].name_ref = sas7bdat_parse_text_ref(cnp, ctx);
  311|  21.8k|        cnp += 8;
  312|  21.8k|    }
  313|       |
  314|  1.49k|cleanup:
  315|       |
  316|  1.49k|    return retval;
  317|  1.41k|}
readstat_sas7bdat_read.c:sas7bdat_parse_column_attributes_subheader:
  319|  2.73k|static readstat_error_t sas7bdat_parse_column_attributes_subheader(const char *subheader, size_t len, sas7bdat_ctx_t *ctx) {
  320|  2.73k|    readstat_error_t retval = READSTAT_OK;
  321|  2.73k|    size_t signature_len = ctx->subheader_signature_size;
  322|  2.73k|    int cmax = ctx->u64 ? (len-28)/16 : (len-20)/12;
  ------------------
  |  Branch (322:16): [True: 611, False: 2.12k]
  ------------------
  323|  2.73k|    int i;
  324|  2.73k|    const char *cap = &subheader[signature_len+8];
  325|  2.73k|    uint16_t remainder = sas_read2(&subheader[signature_len], ctx->bswap);
  326|       |
  327|  2.73k|    if (remainder != sas_subheader_remainder(len, signature_len)) {
  ------------------
  |  Branch (327:9): [True: 56, False: 2.67k]
  ------------------
  328|     56|        retval = READSTAT_ERROR_PARSE;
  329|     56|        goto cleanup;
  330|     56|    }
  331|  2.67k|    ctx->col_attrs_count += cmax;
  332|  2.67k|    if ((retval = sas7bdat_realloc_col_info(ctx, ctx->col_attrs_count)) != READSTAT_OK)
  ------------------
  |  Branch (332:9): [True: 13, False: 2.66k]
  ------------------
  333|     13|        goto cleanup;
  334|       |
  335|  13.0k|    for (i=ctx->col_attrs_count-cmax; i<ctx->col_attrs_count; i++) {
  ------------------
  |  Branch (335:39): [True: 10.4k, False: 2.64k]
  ------------------
  336|  10.4k|        if (ctx->u64) {
  ------------------
  |  Branch (336:13): [True: 1.56k, False: 8.87k]
  ------------------
  337|  1.56k|            ctx->col_info[i].offset = sas_read8(&cap[0], ctx->bswap);
  338|  8.87k|        } else {
  339|  8.87k|            ctx->col_info[i].offset = sas_read4(&cap[0], ctx->bswap);
  340|  8.87k|        }
  341|       |
  342|  10.4k|        readstat_off_t off=4;
  343|  10.4k|        if (ctx->u64)
  ------------------
  |  Branch (343:13): [True: 1.56k, False: 8.87k]
  ------------------
  344|  1.56k|            off=8;
  345|       |
  346|  10.4k|        ctx->col_info[i].width = sas_read4(&cap[off], ctx->bswap);
  347|  10.4k|        if (ctx->col_info[i].width > ctx->max_col_width)
  ------------------
  |  Branch (347:13): [True: 1.33k, False: 9.09k]
  ------------------
  348|  1.33k|            ctx->max_col_width = ctx->col_info[i].width;
  349|       |
  350|  10.4k|        if (cap[off+6] == SAS_COLUMN_TYPE_NUM) {
  ------------------
  |  |   76|  10.4k|#define SAS_COLUMN_TYPE_NUM  0x01
  ------------------
  |  Branch (350:13): [True: 4.73k, False: 5.70k]
  ------------------
  351|  4.73k|            ctx->col_info[i].type = READSTAT_TYPE_DOUBLE;
  352|  5.70k|        } else if (cap[off+6] == SAS_COLUMN_TYPE_CHR) {
  ------------------
  |  |   77|  5.70k|#define SAS_COLUMN_TYPE_CHR  0x02
  ------------------
  |  Branch (352:20): [True: 5.68k, False: 19]
  ------------------
  353|  5.68k|            ctx->col_info[i].type = READSTAT_TYPE_STRING;
  354|  5.68k|        } else {
  355|     19|            retval = READSTAT_ERROR_PARSE;
  356|     19|            goto cleanup;
  357|     19|        }
  358|  10.4k|        ctx->col_info[i].index = i;
  359|  10.4k|        cap += off+8;
  360|  10.4k|    }
  361|       |
  362|  2.73k|cleanup:
  363|       |
  364|  2.73k|    return retval;
  365|  2.66k|}
readstat_sas7bdat_read.c:sas7bdat_parse_column_format_subheader:
  367|  4.30k|static readstat_error_t sas7bdat_parse_column_format_subheader(const char *subheader, size_t len, sas7bdat_ctx_t *ctx) {
  368|  4.30k|    readstat_error_t retval = READSTAT_OK;
  369|       |
  370|  4.30k|    if (len < (ctx->u64 ? 58 : 46)) {
  ------------------
  |  Branch (370:9): [True: 6, False: 4.29k]
  |  Branch (370:16): [True: 705, False: 3.59k]
  ------------------
  371|      6|        retval = READSTAT_ERROR_PARSE;
  372|      6|        goto cleanup;
  373|      6|    }
  374|       |
  375|  4.29k|    ctx->col_formats_count++;
  376|  4.29k|    if ((retval = sas7bdat_realloc_col_info(ctx, ctx->col_formats_count)) != READSTAT_OK)
  ------------------
  |  Branch (376:9): [True: 0, False: 4.29k]
  ------------------
  377|      0|        goto cleanup;
  378|       |
  379|  4.29k|    if (ctx->u64)
  ------------------
  |  Branch (379:9): [True: 705, False: 3.59k]
  ------------------
  380|    705|        ctx->col_info[ctx->col_formats_count-1].format_len = sas_read2(&subheader[24], ctx->bswap);
  381|  4.29k|    ctx->col_info[ctx->col_formats_count-1].format_ref = sas7bdat_parse_text_ref(
  382|  4.29k|            ctx->u64 ? &subheader[46] : &subheader[34], ctx);
  ------------------
  |  Branch (382:13): [True: 705, False: 3.59k]
  ------------------
  383|  4.29k|    ctx->col_info[ctx->col_formats_count-1].label_ref = sas7bdat_parse_text_ref(
  384|  4.29k|            ctx->u64 ? &subheader[52] : &subheader[40], ctx);
  ------------------
  |  Branch (384:13): [True: 705, False: 3.59k]
  ------------------
  385|       |
  386|  4.30k|cleanup:
  387|  4.30k|    return retval;
  388|  4.29k|}
readstat_sas7bdat_read.c:sas7bdat_parse_amd_pages_pass1:
 1068|  2.55k|static readstat_error_t sas7bdat_parse_amd_pages_pass1(int64_t last_examined_page_pass1, sas7bdat_ctx_t *ctx) {
 1069|  2.55k|    readstat_error_t retval = READSTAT_OK;
 1070|  2.55k|    readstat_io_t *io = ctx->io;
 1071|  2.55k|    uint64_t i;
 1072|  2.55k|    uint64_t amd_page_count = 0;
 1073|       |
 1074|       |    /* ...then AMD pages at the end */
 1075|  6.23k|    for (i=ctx->page_count-1; i>last_examined_page_pass1; i--) {
  ------------------
  |  Branch (1075:31): [True: 4.60k, False: 1.63k]
  ------------------
 1076|  4.60k|        if (io->seek(ctx->header_size + i*ctx->page_size, READSTAT_SEEK_SET, io->io_ctx) == -1) {
  ------------------
  |  Branch (1076:13): [True: 236, False: 4.36k]
  ------------------
 1077|    236|            retval = READSTAT_ERROR_SEEK;
 1078|    236|            if (ctx->handle.error) {
  ------------------
  |  Branch (1078:17): [True: 0, False: 236]
  ------------------
 1079|      0|                snprintf(ctx->error_buf, sizeof(ctx->error_buf), "ReadStat: Failed to seek to position %" PRId64 
 1080|      0|                        " (= %" PRId64 " + %" PRId64 "*%" PRId64 ")",
 1081|      0|                        ctx->header_size + i*ctx->page_size, ctx->header_size, i, ctx->page_size);
 1082|      0|                ctx->handle.error(ctx->error_buf, ctx->user_ctx);
 1083|      0|            }
 1084|    236|            goto cleanup;
 1085|    236|        }
 1086|       |
 1087|  4.36k|        readstat_off_t off = 0;
 1088|  4.36k|        if (ctx->u64)
  ------------------
  |  Branch (1088:13): [True: 3.92k, False: 435]
  ------------------
 1089|  3.92k|            off = 16;
 1090|       |
 1091|  4.36k|        size_t head_len = off + 16 + 2;
 1092|  4.36k|        size_t tail_len = ctx->page_size - head_len;
 1093|       |
 1094|  4.36k|        if (io->read(ctx->page, head_len, io->io_ctx) < head_len) {
  ------------------
  |  Branch (1094:13): [True: 7, False: 4.35k]
  ------------------
 1095|      7|            retval = READSTAT_ERROR_READ;
 1096|      7|            goto cleanup;
 1097|      7|        }
 1098|       |
 1099|  4.35k|        uint16_t page_type = sas_read2(&ctx->page[off+16], ctx->bswap);
 1100|       |
 1101|  4.35k|        if ((page_type & SAS_PAGE_TYPE_MASK) == SAS_PAGE_TYPE_DATA) {
  ------------------
  |  |   96|  4.35k|#define SAS_PAGE_TYPE_MASK   0x0F00
  ------------------
                      if ((page_type & SAS_PAGE_TYPE_MASK) == SAS_PAGE_TYPE_DATA) {
  ------------------
  |  |   93|  4.35k|#define SAS_PAGE_TYPE_DATA   0x0100
  ------------------
  |  Branch (1101:13): [True: 945, False: 3.41k]
  ------------------
 1102|       |            /* Usually AMD pages are at the end but sometimes data pages appear after them */
 1103|    945|            if (amd_page_count > 0)
  ------------------
  |  Branch (1103:17): [True: 331, False: 614]
  ------------------
 1104|    331|                break;
 1105|    614|            continue;
 1106|    945|        }
 1107|  3.41k|        if ((page_type & SAS_PAGE_TYPE_COMP))
  ------------------
  |  |   99|  3.41k|#define SAS_PAGE_TYPE_COMP   0x9000
  ------------------
  |  Branch (1107:13): [True: 879, False: 2.53k]
  ------------------
 1108|    879|            continue;
 1109|       |
 1110|  2.53k|        if (io->read(ctx->page + head_len, tail_len, io->io_ctx) < tail_len) {
  ------------------
  |  Branch (1110:13): [True: 1, False: 2.53k]
  ------------------
 1111|      1|            retval = READSTAT_ERROR_READ;
 1112|      1|            goto cleanup;
 1113|      1|        }
 1114|       |
 1115|  2.53k|        if ((retval = sas7bdat_parse_page_pass1(ctx->page, ctx->page_size, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1115:13): [True: 349, False: 2.18k]
  ------------------
 1116|    349|            if (ctx->handle.error && retval != READSTAT_ERROR_USER_ABORT) {
  ------------------
  |  Branch (1116:17): [True: 0, False: 349]
  |  Branch (1116:38): [True: 0, False: 0]
  ------------------
 1117|      0|                int64_t pos = io->seek(0, READSTAT_SEEK_CUR, io->io_ctx);
 1118|      0|                snprintf(ctx->error_buf, sizeof(ctx->error_buf), 
 1119|      0|                        "ReadStat: Error parsing page %" PRId64 ", bytes %" PRId64 "-%" PRId64, 
 1120|      0|                        i, pos - ctx->page_size, pos-1);
 1121|      0|                ctx->handle.error(ctx->error_buf, ctx->user_ctx);
 1122|      0|            }
 1123|    349|            goto cleanup;
 1124|    349|        }
 1125|       |
 1126|  2.18k|        amd_page_count++;
 1127|  2.18k|    }
 1128|       |
 1129|  2.55k|cleanup:
 1130|       |
 1131|  2.55k|    return retval;
 1132|  2.55k|}
readstat_sas7bdat_read.c:sas7bdat_parse_all_pages_pass2:
 1134|  1.96k|static readstat_error_t sas7bdat_parse_all_pages_pass2(sas7bdat_ctx_t *ctx) {
 1135|  1.96k|    readstat_error_t retval = READSTAT_OK;
 1136|  1.96k|    readstat_io_t *io = ctx->io;
 1137|  1.96k|    int64_t i;
 1138|       |
 1139|  4.75k|    for (i=0; i<ctx->page_count; i++) {
  ------------------
  |  Branch (1139:15): [True: 4.63k, False: 120]
  ------------------
 1140|  4.63k|        if ((retval = sas7bdat_update_progress(ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1140:13): [True: 0, False: 4.63k]
  ------------------
 1141|      0|            goto cleanup;
 1142|      0|        }
 1143|  4.63k|        if (io->read(ctx->page, ctx->page_size, io->io_ctx) < ctx->page_size) {
  ------------------
  |  Branch (1143:13): [True: 107, False: 4.52k]
  ------------------
 1144|    107|            retval = READSTAT_ERROR_READ;
 1145|    107|            goto cleanup;
 1146|    107|        }
 1147|       |
 1148|  4.52k|        if ((retval = sas7bdat_parse_page_pass2(ctx->page, ctx->page_size, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1148:13): [True: 1.50k, False: 3.01k]
  ------------------
 1149|  1.50k|            if (ctx->handle.error && retval != READSTAT_ERROR_USER_ABORT) {
  ------------------
  |  Branch (1149:17): [True: 0, False: 1.50k]
  |  Branch (1149:38): [True: 0, False: 0]
  ------------------
 1150|      0|                int64_t pos = io->seek(0, READSTAT_SEEK_CUR, io->io_ctx);
 1151|      0|                snprintf(ctx->error_buf, sizeof(ctx->error_buf), 
 1152|      0|                        "ReadStat: Error parsing page %" PRId64 ", bytes %" PRId64 "-%" PRId64, 
 1153|      0|                        i, pos - ctx->page_size, pos-1);
 1154|      0|                ctx->handle.error(ctx->error_buf, ctx->user_ctx);
 1155|      0|            }
 1156|  1.50k|            goto cleanup;
 1157|  1.50k|        }
 1158|  3.01k|        if (ctx->parsed_row_count == ctx->row_limit)
  ------------------
  |  Branch (1158:13): [True: 232, False: 2.78k]
  ------------------
 1159|    232|            break;
 1160|  3.01k|    }
 1161|  1.96k|cleanup:
 1162|       |
 1163|  1.96k|    return retval;
 1164|  1.96k|}
readstat_sas7bdat_read.c:sas7bdat_parse_page_pass2:
  906|  4.52k|static readstat_error_t sas7bdat_parse_page_pass2(const char *page, size_t page_size, sas7bdat_ctx_t *ctx) {
  907|  4.52k|    uint16_t page_type;
  908|       |
  909|  4.52k|    readstat_error_t retval = READSTAT_OK;
  910|       |
  911|  4.52k|    page_type = sas_read2(&page[ctx->page_header_size-8], ctx->bswap);
  912|       |
  913|  4.52k|    const char *data = NULL;
  914|       |
  915|  4.52k|    if ((page_type & SAS_PAGE_TYPE_MASK) == SAS_PAGE_TYPE_DATA) {
  ------------------
  |  |   96|  4.52k|#define SAS_PAGE_TYPE_MASK   0x0F00
  ------------------
                  if ((page_type & SAS_PAGE_TYPE_MASK) == SAS_PAGE_TYPE_DATA) {
  ------------------
  |  |   93|  4.52k|#define SAS_PAGE_TYPE_DATA   0x0100
  ------------------
  |  Branch (915:9): [True: 689, False: 3.83k]
  ------------------
  916|    689|        ctx->page_row_count = sas_read2(&page[ctx->page_header_size-6], ctx->bswap);
  917|    689|        data = &page[ctx->page_header_size];
  918|  3.83k|    } else if (!(page_type & SAS_PAGE_TYPE_COMP)) {
  ------------------
  |  |   99|  3.83k|#define SAS_PAGE_TYPE_COMP   0x9000
  ------------------
  |  Branch (918:16): [True: 3.63k, False: 201]
  ------------------
  919|  3.63k|        uint16_t subheader_count = sas_read2(&page[ctx->page_header_size-4], ctx->bswap);
  920|       |
  921|  3.63k|        int i;
  922|  3.63k|        const char *shp = &page[ctx->page_header_size];
  923|  3.63k|        int lshp = ctx->subheader_pointer_size;
  924|       |
  925|  3.63k|        if (ctx->page_header_size + subheader_count*lshp > page_size) {
  ------------------
  |  Branch (925:13): [True: 29, False: 3.60k]
  ------------------
  926|     29|            retval = READSTAT_ERROR_PARSE;
  927|     29|            goto cleanup;
  928|     29|        }
  929|       |
  930|  45.4k|        for (i=0; i<subheader_count; i++) {
  ------------------
  |  Branch (930:19): [True: 43.1k, False: 2.38k]
  ------------------
  931|  43.1k|            subheader_pointer_t shp_info = { 0 };
  932|  43.1k|            uint32_t signature = 0;
  933|  43.1k|            if ((retval = sas7bdat_parse_subheader_pointer(shp, page + page_size - shp, &shp_info, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (933:17): [True: 0, False: 43.1k]
  ------------------
  934|      0|                goto cleanup;
  935|      0|            }
  936|  43.1k|            if (shp_info.len > 0 && shp_info.compression != SAS_COMPRESSION_TRUNC) {
  ------------------
  |  |  108|  29.5k|#define SAS_COMPRESSION_TRUNC  0x01
  ------------------
  |  Branch (936:17): [True: 29.5k, False: 13.5k]
  |  Branch (936:37): [True: 25.4k, False: 4.17k]
  ------------------
  937|  25.4k|                if ((retval = sas7bdat_validate_subheader_pointer(&shp_info, page_size, subheader_count, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (937:21): [True: 195, False: 25.2k]
  ------------------
  938|    195|                    goto cleanup;
  939|    195|                }
  940|  25.2k|                if (shp_info.compression == SAS_COMPRESSION_NONE) {
  ------------------
  |  |  107|  25.2k|#define SAS_COMPRESSION_NONE   0x00
  ------------------
  |  Branch (940:21): [True: 23.7k, False: 1.45k]
  ------------------
  941|  23.7k|                    signature = sas_read4(page + shp_info.offset, ctx->bswap);
  942|  23.7k|                    if (!ctx->little_endian && signature == -1 && ctx->u64) {
  ------------------
  |  Branch (942:25): [True: 19.1k, False: 4.62k]
  |  Branch (942:48): [True: 1.68k, False: 17.4k]
  |  Branch (942:67): [True: 1.08k, False: 599]
  ------------------
  943|  1.08k|                        signature = sas_read4(page + shp_info.offset + 4, ctx->bswap);
  944|  1.08k|                    }
  945|  23.7k|                    if (shp_info.is_compressed_data && !sas7bdat_signature_is_recognized(signature)) {
  ------------------
  |  Branch (945:25): [True: 18.7k, False: 5.05k]
  |  Branch (945:56): [True: 1.81k, False: 16.9k]
  ------------------
  946|  1.81k|                        if (shp_info.len != ctx->row_length) {
  ------------------
  |  Branch (946:29): [True: 167, False: 1.64k]
  ------------------
  947|    167|                            retval = READSTAT_ERROR_ROW_WIDTH_MISMATCH;
  948|    167|                            goto cleanup;
  949|    167|                        }
  950|  1.64k|                        if ((retval = sas7bdat_submit_columns_if_needed(ctx, 1)) != READSTAT_OK) {
  ------------------
  |  Branch (950:29): [True: 1, False: 1.64k]
  ------------------
  951|      1|                            goto cleanup;
  952|      1|                        }
  953|  1.64k|                        if ((retval = sas7bdat_parse_single_row(page + shp_info.offset, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (953:29): [True: 1, False: 1.64k]
  ------------------
  954|      1|                            goto cleanup;
  955|      1|                        }
  956|  21.9k|                    } else {
  957|  21.9k|                        if (signature != SAS_SUBHEADER_SIGNATURE_COLUMN_TEXT) {
  ------------------
  |  |   88|  21.9k|#define SAS_SUBHEADER_SIGNATURE_COLUMN_TEXT    0xFFFFFFFD
  ------------------
  |  Branch (957:29): [True: 20.0k, False: 1.93k]
  ------------------
  958|  20.0k|                            if ((retval = sas7bdat_parse_subheader(signature, page + shp_info.offset, shp_info.len, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (958:33): [True: 547, False: 19.4k]
  ------------------
  959|    547|                                goto cleanup;
  960|    547|                            }
  961|  20.0k|                        }
  962|  21.9k|                    }
  963|  23.7k|                } else if (shp_info.compression == SAS_COMPRESSION_ROW) {
  ------------------
  |  |  109|  1.45k|#define SAS_COMPRESSION_ROW    0x04
  ------------------
  |  Branch (963:28): [True: 1.45k, False: 9]
  ------------------
  964|  1.45k|                    if ((retval = sas7bdat_submit_columns_if_needed(ctx, 1)) != READSTAT_OK) {
  ------------------
  |  Branch (964:25): [True: 73, False: 1.37k]
  ------------------
  965|     73|                        goto cleanup;
  966|     73|                    }
  967|  1.37k|                    if ((retval = sas7bdat_parse_subheader_compressed(page + shp_info.offset, shp_info.len, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (967:25): [True: 223, False: 1.15k]
  ------------------
  968|    223|                        goto cleanup;
  969|    223|                    }
  970|  1.37k|                } else {
  971|      9|                    retval = READSTAT_ERROR_UNSUPPORTED_COMPRESSION;
  972|      9|                    goto cleanup;
  973|      9|                }
  974|  25.2k|            }
  975|       |
  976|  41.8k|            shp += lshp;
  977|  41.8k|        }
  978|       |
  979|  2.38k|        if ((page_type & SAS_PAGE_TYPE_MASK) == SAS_PAGE_TYPE_MIX) {
  ------------------
  |  |   96|  2.38k|#define SAS_PAGE_TYPE_MASK   0x0F00
  ------------------
                      if ((page_type & SAS_PAGE_TYPE_MASK) == SAS_PAGE_TYPE_MIX) {
  ------------------
  |  |   94|  2.38k|#define SAS_PAGE_TYPE_MIX    0x0200
  ------------------
  |  Branch (979:13): [True: 1.19k, False: 1.19k]
  ------------------
  980|       |            /* HACK - this is supposed to obey 8-byte boundaries but
  981|       |             * some files created by Stat/Transfer don't. So verify that the
  982|       |             * padding is { 0, 0, 0, 0 } or { ' ', ' ', ' ', ' ' } (or that
  983|       |             * the file is not from Stat/Transfer) before skipping it */
  984|  1.19k|            if ((shp-page)%8 == 4 && shp + 4 <= page + page_size &&
  ------------------
  |  Branch (984:17): [True: 204, False: 991]
  |  Branch (984:38): [True: 204, False: 0]
  ------------------
  985|  1.19k|                    (*(uint32_t *)shp == 0x00000000 ||
  ------------------
  |  Branch (985:22): [True: 31, False: 173]
  ------------------
  986|    204|                     *(uint32_t *)shp == 0x20202020 ||
  ------------------
  |  Branch (986:22): [True: 13, False: 160]
  ------------------
  987|    204|                     ctx->vendor != READSTAT_VENDOR_STAT_TRANSFER)) {
  ------------------
  |  Branch (987:22): [True: 124, False: 36]
  ------------------
  988|    168|                data = shp + 4;
  989|  1.02k|            } else {
  990|  1.02k|                data = shp;
  991|  1.02k|            }
  992|  1.19k|        }
  993|  2.38k|    }
  994|  3.27k|    if (data) {
  ------------------
  |  Branch (994:9): [True: 1.88k, False: 1.39k]
  ------------------
  995|  1.88k|        if ((retval = sas7bdat_submit_columns_if_needed(ctx, 0)) != READSTAT_OK) {
  ------------------
  |  Branch (995:13): [True: 81, False: 1.80k]
  ------------------
  996|     81|            goto cleanup;
  997|     81|        }
  998|  1.80k|        if (ctx->handle.value) {
  ------------------
  |  Branch (998:13): [True: 1.80k, False: 0]
  ------------------
  999|  1.80k|            retval = sas7bdat_parse_rows(data, page + page_size - data, ctx);
 1000|  1.80k|        }
 1001|  1.80k|    } 
 1002|  4.52k|cleanup:
 1003|       |
 1004|  4.52k|    return retval;
 1005|  3.27k|}
readstat_sas7bdat_read.c:sas7bdat_signature_is_recognized:
  799|  18.7k|static int sas7bdat_signature_is_recognized(uint32_t signature) {
  800|  18.7k|    return (signature == SAS_SUBHEADER_SIGNATURE_ROW_SIZE ||
  ------------------
  |  |   79|  37.4k|#define SAS_SUBHEADER_SIGNATURE_ROW_SIZE       0xF7F7F7F7
  ------------------
  |  Branch (800:13): [True: 6.10k, False: 12.6k]
  ------------------
  801|  18.7k|            signature == SAS_SUBHEADER_SIGNATURE_COLUMN_SIZE ||
  ------------------
  |  |   80|  31.3k|#define SAS_SUBHEADER_SIGNATURE_COLUMN_SIZE    0xF6F6F6F6
  ------------------
  |  Branch (801:13): [True: 892, False: 11.7k]
  ------------------
  802|  18.7k|            signature == SAS_SUBHEADER_SIGNATURE_COUNTS ||
  ------------------
  |  |   81|  30.4k|#define SAS_SUBHEADER_SIGNATURE_COUNTS         0xFFFFFC00
  ------------------
  |  Branch (802:13): [True: 641, False: 11.0k]
  ------------------
  803|  18.7k|            signature == SAS_SUBHEADER_SIGNATURE_COLUMN_FORMAT ||
  ------------------
  |  |   82|  29.8k|#define SAS_SUBHEADER_SIGNATURE_COLUMN_FORMAT  0xFFFFFBFE
  ------------------
  |  Branch (803:13): [True: 3.65k, False: 7.42k]
  ------------------
  804|  18.7k|            (signature & SAS_SUBHEADER_SIGNATURE_COLUMN_MASK) == SAS_SUBHEADER_SIGNATURE_COLUMN_MASK);
  ------------------
  |  |   84|  7.42k|#define SAS_SUBHEADER_SIGNATURE_COLUMN_MASK    0xFFFFFFF8
  ------------------
                          (signature & SAS_SUBHEADER_SIGNATURE_COLUMN_MASK) == SAS_SUBHEADER_SIGNATURE_COLUMN_MASK);
  ------------------
  |  |   84|  7.42k|#define SAS_SUBHEADER_SIGNATURE_COLUMN_MASK    0xFFFFFFF8
  ------------------
  |  Branch (804:13): [True: 5.61k, False: 1.81k]
  ------------------
  805|  18.7k|}
readstat_sas7bdat_read.c:sas7bdat_parse_single_row:
  447|   155k|static readstat_error_t sas7bdat_parse_single_row(const char *data, sas7bdat_ctx_t *ctx) {
  448|   155k|    if (ctx->parsed_row_count == ctx->row_limit)
  ------------------
  |  Branch (448:9): [True: 514, False: 155k]
  ------------------
  449|    514|        return READSTAT_OK;
  450|   155k|    if (ctx->row_offset) {
  ------------------
  |  Branch (450:9): [True: 0, False: 155k]
  ------------------
  451|      0|        ctx->row_offset--;
  452|      0|        return READSTAT_OK;
  453|      0|    }
  454|       |
  455|   155k|    readstat_error_t retval = READSTAT_OK;
  456|   155k|    int j;
  457|   155k|    if (ctx->handle.value) {
  ------------------
  |  Branch (457:9): [True: 155k, False: 0]
  ------------------
  458|   155k|        ctx->scratch_buffer_len = 4*ctx->max_col_width+1;
  459|   155k|        ctx->scratch_buffer = readstat_realloc(ctx->scratch_buffer, ctx->scratch_buffer_len);
  460|   155k|        if (ctx->scratch_buffer == NULL) {
  ------------------
  |  Branch (460:13): [True: 5, False: 155k]
  ------------------
  461|      5|            retval = READSTAT_ERROR_MALLOC;
  462|      5|            goto cleanup;
  463|      5|        }
  464|       |
  465|   209k|        for (j=0; j<ctx->column_count; j++) {
  ------------------
  |  Branch (465:19): [True: 54.4k, False: 155k]
  ------------------
  466|  54.4k|            col_info_t *col_info = &ctx->col_info[j];
  467|  54.4k|            readstat_variable_t *variable = ctx->variables[j];
  468|  54.4k|            if (variable->skip)
  ------------------
  |  Branch (468:17): [True: 0, False: 54.4k]
  ------------------
  469|      0|                continue;
  470|       |
  471|  54.4k|            if (col_info->offset > ctx->row_length || col_info->offset + col_info->width > ctx->row_length) {
  ------------------
  |  Branch (471:17): [True: 104, False: 54.3k]
  |  Branch (471:55): [True: 3, False: 54.3k]
  ------------------
  472|    107|                retval = READSTAT_ERROR_PARSE;
  473|    107|                goto cleanup;
  474|    107|            }
  475|  54.3k|            retval = sas7bdat_handle_data_value(variable, col_info, &data[col_info->offset], ctx);
  476|  54.3k|            if (retval != READSTAT_OK) {
  ------------------
  |  Branch (476:17): [True: 15, False: 54.3k]
  ------------------
  477|     15|                goto cleanup;
  478|     15|            }
  479|  54.3k|        }
  480|   155k|    }
  481|   155k|    ctx->parsed_row_count++;
  482|       |
  483|   155k|cleanup:
  484|   155k|    return retval;
  485|   155k|}
readstat_sas7bdat_read.c:sas7bdat_handle_data_value:
  391|  54.3k|        col_info_t *col_info, const char *col_data, sas7bdat_ctx_t *ctx) {
  392|  54.3k|    readstat_error_t retval = READSTAT_OK;
  393|  54.3k|    int cb_retval = 0;
  394|  54.3k|    readstat_value_t value;
  395|  54.3k|    memset(&value, 0, sizeof(readstat_value_t));
  396|       |
  397|  54.3k|    value.type = col_info->type;
  398|       |
  399|  54.3k|    if (col_info->type == READSTAT_TYPE_STRING) {
  ------------------
  |  Branch (399:9): [True: 16.2k, False: 38.1k]
  ------------------
  400|  16.2k|        retval = readstat_convert(ctx->scratch_buffer, ctx->scratch_buffer_len,
  401|  16.2k|                col_data, col_info->width, ctx->converter);
  402|  16.2k|        if (retval != READSTAT_OK) {
  ------------------
  |  Branch (402:13): [True: 15, False: 16.2k]
  ------------------
  403|     15|            if (ctx->handle.error) {
  ------------------
  |  Branch (403:17): [True: 0, False: 15]
  ------------------
  404|      0|                snprintf(ctx->error_buf, sizeof(ctx->error_buf),
  405|      0|                        "ReadStat: Error converting string (row=%u, col=%u) to specified encoding: %.*s",
  406|      0|                        ctx->parsed_row_count+1, col_info->index+1, col_info->width, col_data);
  407|      0|                ctx->handle.error(ctx->error_buf, ctx->user_ctx);
  408|      0|            }
  409|     15|            goto cleanup;
  410|     15|        }
  411|       |
  412|  16.2k|        value.v.string_value = ctx->scratch_buffer;
  413|  38.1k|    } else if (col_info->type == READSTAT_TYPE_DOUBLE) {
  ------------------
  |  Branch (413:16): [True: 38.1k, False: 0]
  ------------------
  414|  38.1k|        uint64_t  val = 0;
  415|  38.1k|        double dval = NAN;
  416|  38.1k|        if (ctx->little_endian) {
  ------------------
  |  Branch (416:13): [True: 38.1k, False: 0]
  ------------------
  417|  38.1k|            int k;
  418|   201k|            for (k=0; k<col_info->width; k++) {
  ------------------
  |  Branch (418:23): [True: 163k, False: 38.1k]
  ------------------
  419|   163k|                val = (val << 8) | (unsigned char)col_data[col_info->width-1-k];
  420|   163k|            }
  421|  38.1k|        } else {
  422|      0|            int k;
  423|      0|            for (k=0; k<col_info->width; k++) {
  ------------------
  |  Branch (423:23): [True: 0, False: 0]
  ------------------
  424|      0|                val = (val << 8) | (unsigned char)col_data[k];
  425|      0|            }
  426|      0|        }
  427|  38.1k|        val <<= (8-col_info->width)*8;
  428|       |
  429|  38.1k|        memcpy(&dval, &val, 8);
  430|       |
  431|  38.1k|        if (isnan(dval)) {
  432|  4.31k|            value.v.double_value = NAN;
  433|  4.31k|            sas_assign_tag(&value, ~((val >> 40) & 0xFF));
  434|  33.7k|        } else {
  435|  33.7k|            value.v.double_value = dval;
  436|  33.7k|        }
  437|  38.1k|    }
  438|  54.3k|    cb_retval = ctx->handle.value(ctx->parsed_row_count, variable, value, ctx->user_ctx);
  439|       |
  440|  54.3k|    if (cb_retval != READSTAT_HANDLER_OK)
  ------------------
  |  Branch (440:9): [True: 0, False: 54.3k]
  ------------------
  441|      0|        retval = READSTAT_ERROR_USER_ABORT;
  442|       |
  443|  54.3k|cleanup:
  444|  54.3k|    return retval;
  445|  54.3k|}
readstat_sas7bdat_read.c:sas7bdat_parse_subheader_compressed:
  619|  1.37k|static readstat_error_t sas7bdat_parse_subheader_compressed(const char *subheader, size_t len, sas7bdat_ctx_t *ctx) {
  620|  1.37k|    if (ctx->rdc_compression)
  ------------------
  |  Branch (620:9): [True: 353, False: 1.02k]
  ------------------
  621|    353|        return sas7bdat_parse_subheader_rdc(subheader, len, ctx);
  622|       |
  623|  1.02k|    return sas7bdat_parse_subheader_rle(subheader, len, ctx);
  624|  1.37k|}
readstat_sas7bdat_read.c:sas7bdat_parse_subheader_rdc:
  506|    353|static readstat_error_t sas7bdat_parse_subheader_rdc(const char *subheader, size_t len, sas7bdat_ctx_t *ctx) {
  507|    353|    readstat_error_t retval = READSTAT_OK;
  508|    353|    const unsigned char *input = (const unsigned char *)subheader;
  509|    353|    char *buffer = malloc(ctx->row_length);
  510|    353|    char *output = buffer;
  511|  2.27k|    while (input + 2 <= (const unsigned char *)subheader + len) {
  ------------------
  |  Branch (511:12): [True: 1.96k, False: 314]
  ------------------
  512|  1.96k|        int i;
  513|  1.96k|        unsigned short prefix = (input[0] << 8) + input[1];
  514|  1.96k|        input += 2;
  515|  29.3k|        for (i=0; i<16; i++) {
  ------------------
  |  Branch (515:19): [True: 27.7k, False: 1.61k]
  ------------------
  516|  27.7k|            if ((prefix & (1 << (15 - i))) == 0) {
  ------------------
  |  Branch (516:17): [True: 19.4k, False: 8.22k]
  ------------------
  517|  19.4k|                if (input + 1 > (const unsigned char *)subheader + len) {
  ------------------
  |  Branch (517:21): [True: 311, False: 19.1k]
  ------------------
  518|    311|                    break;
  519|    311|                }
  520|  19.1k|                if (output + 1 > buffer + ctx->row_length) {
  ------------------
  |  Branch (520:21): [True: 1, False: 19.1k]
  ------------------
  521|      1|                    retval = READSTAT_ERROR_ROW_WIDTH_MISMATCH;
  522|      1|                    goto cleanup;
  523|      1|                }
  524|  19.1k|                *output++ = *input++;
  525|  19.1k|                continue;
  526|  19.1k|            }
  527|       |
  528|  8.22k|            if (input + 2 > (const unsigned char *)subheader + len) {
  ------------------
  |  Branch (528:17): [True: 2, False: 8.22k]
  ------------------
  529|      2|                retval = READSTAT_ERROR_PARSE;
  530|      2|                goto cleanup;
  531|      2|            }
  532|       |
  533|  8.22k|            unsigned char marker_byte = *input++;
  534|  8.22k|            unsigned char next_byte = *input++;
  535|  8.22k|            size_t insert_len = 0, copy_len = 0;
  536|  8.22k|            unsigned char insert_byte = 0x00;
  537|  8.22k|            size_t back_offset = 0;
  538|       |
  539|  8.22k|            if (marker_byte <= 0x0F) {
  ------------------
  |  Branch (539:17): [True: 3.63k, False: 4.59k]
  ------------------
  540|  3.63k|                insert_len = 3 + marker_byte;
  541|  3.63k|                insert_byte = next_byte;
  542|  4.59k|            } else if ((marker_byte >> 4) == 1) {
  ------------------
  |  Branch (542:24): [True: 1.17k, False: 3.42k]
  ------------------
  543|  1.17k|                if (input + 1 > (const unsigned char *)subheader + len) {
  ------------------
  |  Branch (543:21): [True: 1, False: 1.17k]
  ------------------
  544|      1|                    retval = READSTAT_ERROR_PARSE;
  545|      1|                    goto cleanup;
  546|      1|                }
  547|  1.17k|                insert_len = 19 + (marker_byte & 0x0F) + next_byte * 16;
  548|  1.17k|                insert_byte = *input++;
  549|  3.42k|            } else if ((marker_byte >> 4) == 2) {
  ------------------
  |  Branch (549:24): [True: 554, False: 2.86k]
  ------------------
  550|    554|                if (input + 1 > (const unsigned char *)subheader + len) {
  ------------------
  |  Branch (550:21): [True: 2, False: 552]
  ------------------
  551|      2|                    retval = READSTAT_ERROR_PARSE;
  552|      2|                    goto cleanup;
  553|      2|                }
  554|    552|                copy_len = 16 + (*input++);
  555|    552|                back_offset = 3 + (marker_byte & 0x0F) + next_byte * 16;
  556|  2.86k|            } else {
  557|  2.86k|                copy_len = (marker_byte >> 4);
  558|  2.86k|                back_offset = 3 + (marker_byte & 0x0F) + next_byte * 16;
  559|  2.86k|            }
  560|       |
  561|  8.22k|            if (insert_len) {
  ------------------
  |  Branch (561:17): [True: 4.80k, False: 3.42k]
  ------------------
  562|  4.80k|                if (output + insert_len > buffer + ctx->row_length) {
  ------------------
  |  Branch (562:21): [True: 2, False: 4.80k]
  ------------------
  563|      2|                    retval = READSTAT_ERROR_ROW_WIDTH_MISMATCH;
  564|      2|                    goto cleanup;
  565|      2|                }
  566|  4.80k|                memset(output, insert_byte, insert_len);
  567|  4.80k|                output += insert_len;
  568|  4.80k|            } else if (copy_len) {
  ------------------
  |  Branch (568:24): [True: 3.42k, False: 0]
  ------------------
  569|  3.42k|                if (output - buffer < back_offset || copy_len > back_offset) {
  ------------------
  |  Branch (569:21): [True: 13, False: 3.40k]
  |  Branch (569:54): [True: 17, False: 3.39k]
  ------------------
  570|     30|                    retval = READSTAT_ERROR_PARSE;
  571|     30|                    goto cleanup;
  572|     30|                }
  573|  3.39k|                if (output + copy_len > buffer + ctx->row_length) {
  ------------------
  |  Branch (573:21): [True: 1, False: 3.39k]
  ------------------
  574|      1|                    retval = READSTAT_ERROR_ROW_WIDTH_MISMATCH;
  575|      1|                    goto cleanup;
  576|      1|                }
  577|  3.39k|                memcpy(output, output - back_offset, copy_len);
  578|  3.39k|                output += copy_len;
  579|  3.39k|            }
  580|  8.22k|        }
  581|  1.96k|    }
  582|       |
  583|    314|    if (output - buffer != ctx->row_length) {
  ------------------
  |  Branch (583:9): [True: 16, False: 298]
  ------------------
  584|     16|        retval = READSTAT_ERROR_ROW_WIDTH_MISMATCH;
  585|     16|        goto cleanup;
  586|     16|    }
  587|    298|    retval = sas7bdat_parse_single_row(buffer, ctx);
  588|    353|cleanup:
  589|    353|    free(buffer);
  590|       |
  591|    353|    return retval;
  592|    298|}
readstat_sas7bdat_read.c:sas7bdat_parse_subheader_rle:
  594|  1.02k|static readstat_error_t sas7bdat_parse_subheader_rle(const char *subheader, size_t len, sas7bdat_ctx_t *ctx) {
  595|  1.02k|    if (ctx->row_limit == ctx->parsed_row_count)
  ------------------
  |  Branch (595:9): [True: 665, False: 359]
  ------------------
  596|    665|        return READSTAT_OK;
  597|       |
  598|    359|    readstat_error_t retval = READSTAT_OK;
  599|    359|    ssize_t bytes_decompressed = 0;
  600|       |
  601|    359|    bytes_decompressed = sas_rle_decompress(ctx->row, ctx->row_length, subheader, len);
  602|       |
  603|    359|    if (bytes_decompressed != ctx->row_length) {
  ------------------
  |  Branch (603:9): [True: 116, False: 243]
  ------------------
  604|    116|        retval = READSTAT_ERROR_ROW_WIDTH_MISMATCH;
  605|    116|        if (ctx->handle.error) {
  ------------------
  |  Branch (605:13): [True: 0, False: 116]
  ------------------
  606|      0|            snprintf(ctx->error_buf, sizeof(ctx->error_buf), 
  607|      0|                    "ReadStat: Row #%d decompressed to %ld bytes (expected %d bytes)",
  608|      0|                    ctx->parsed_row_count, (long)(bytes_decompressed), ctx->row_length);
  609|      0|            ctx->handle.error(ctx->error_buf, ctx->user_ctx);
  610|      0|        }
  611|    116|        goto cleanup;
  612|    116|    }
  613|    243|    retval = sas7bdat_parse_single_row(ctx->row, ctx);
  614|       |
  615|    359|cleanup:
  616|    359|    return retval;
  617|    243|}
readstat_sas7bdat_read.c:sas7bdat_parse_rows:
  487|  1.80k|static readstat_error_t sas7bdat_parse_rows(const char *data, size_t len, sas7bdat_ctx_t *ctx) {
  488|  1.80k|    readstat_error_t retval = READSTAT_OK;
  489|  1.80k|    int i;
  490|  1.80k|    size_t row_offset=0;
  491|   155k|    for (i=0; i<ctx->page_row_count && ctx->parsed_row_count < ctx->row_limit; i++) {
  ------------------
  |  Branch (491:15): [True: 154k, False: 1.39k]
  |  Branch (491:40): [True: 153k, False: 230]
  ------------------
  492|   153k|        if (row_offset + ctx->row_length > len) {
  ------------------
  |  Branch (492:13): [True: 106, False: 153k]
  ------------------
  493|    106|            retval = READSTAT_ERROR_ROW_WIDTH_MISMATCH;
  494|    106|            goto cleanup;
  495|    106|        }
  496|   153k|        if ((retval = sas7bdat_parse_single_row(&data[row_offset], ctx)) != READSTAT_OK)
  ------------------
  |  Branch (496:13): [True: 74, False: 153k]
  ------------------
  497|     74|            goto cleanup;
  498|       |
  499|   153k|        row_offset += ctx->row_length;
  500|   153k|    }
  501|       |
  502|  1.80k|cleanup:
  503|  1.80k|    return retval;
  504|  1.80k|}
readstat_sas7bdat_read.c:sas7bdat_submit_columns_if_needed:
  787|  5.32k|static readstat_error_t sas7bdat_submit_columns_if_needed(sas7bdat_ctx_t *ctx, int compressed) {
  788|  5.32k|    readstat_error_t retval = READSTAT_OK;
  789|  5.32k|    if (!ctx->did_submit_columns) {
  ------------------
  |  Branch (789:9): [True: 1.32k, False: 4.00k]
  ------------------
  790|  1.32k|        if ((retval = sas7bdat_submit_columns(ctx, compressed)) != READSTAT_OK) {
  ------------------
  |  Branch (790:13): [True: 267, False: 1.06k]
  ------------------
  791|    267|            goto cleanup;
  792|    267|        }
  793|  1.06k|        ctx->did_submit_columns = 1;
  794|  1.06k|    }
  795|  5.32k|cleanup:
  796|  5.32k|    return retval;
  797|  5.32k|}
readstat_sas7bdat_read.c:sas7bdat_submit_columns:
  726|  1.32k|static readstat_error_t sas7bdat_submit_columns(sas7bdat_ctx_t *ctx, int compressed) {
  727|  1.32k|    readstat_error_t retval = READSTAT_OK;
  728|  1.32k|    if (ctx->handle.metadata) {
  ------------------
  |  Branch (728:9): [True: 1.32k, False: 0]
  ------------------
  729|  1.32k|        readstat_metadata_t metadata = {
  730|  1.32k|            .row_count = ctx->row_limit,
  731|  1.32k|            .var_count = ctx->column_count,
  732|  1.32k|            .table_name = ctx->table_name,
  733|  1.32k|            .file_label = ctx->file_label,
  734|  1.32k|            .file_encoding = ctx->input_encoding, /* orig encoding? */
  735|  1.32k|            .creation_time = ctx->ctime,
  736|  1.32k|            .modified_time = ctx->mtime,
  737|  1.32k|            .file_format_version = ctx->version,
  738|  1.32k|            .compression = READSTAT_COMPRESS_NONE,
  739|  1.32k|            .endianness = ctx->little_endian ? READSTAT_ENDIAN_LITTLE : READSTAT_ENDIAN_BIG,
  ------------------
  |  Branch (739:27): [True: 258, False: 1.07k]
  ------------------
  740|  1.32k|            .is64bit = ctx->u64
  741|  1.32k|        };
  742|  1.32k|        if (compressed) {
  ------------------
  |  Branch (742:13): [True: 548, False: 780]
  ------------------
  743|    548|            if (ctx->rdc_compression) {
  ------------------
  |  Branch (743:17): [True: 27, False: 521]
  ------------------
  744|     27|                metadata.compression = READSTAT_COMPRESS_BINARY;
  745|    521|            } else {
  746|    521|                metadata.compression = READSTAT_COMPRESS_ROWS;
  747|    521|            }
  748|    548|        }
  749|  1.32k|        if (ctx->handle.metadata(&metadata, ctx->user_ctx) != READSTAT_HANDLER_OK) {
  ------------------
  |  Branch (749:13): [True: 0, False: 1.32k]
  ------------------
  750|      0|            retval = READSTAT_ERROR_USER_ABORT;
  751|      0|            goto cleanup;
  752|      0|        }
  753|  1.32k|    }
  754|  1.32k|    if (ctx->column_count == 0)
  ------------------
  |  Branch (754:9): [True: 887, False: 441]
  ------------------
  755|    887|        goto cleanup;
  756|       |
  757|    441|    if ((ctx->variables = readstat_calloc(ctx->column_count, sizeof(readstat_variable_t *))) == NULL) {
  ------------------
  |  Branch (757:9): [True: 0, False: 441]
  ------------------
  758|      0|        retval = READSTAT_ERROR_MALLOC;
  759|      0|        goto cleanup;
  760|      0|    }
  761|    441|    int i;
  762|    441|    int index_after_skipping = 0;
  763|  2.50k|    for (i=0; i<ctx->column_count; i++) {
  ------------------
  |  Branch (763:15): [True: 2.32k, False: 174]
  ------------------
  764|  2.32k|        ctx->variables[i] = sas7bdat_init_variable(ctx, i, index_after_skipping, &retval);
  765|  2.32k|        if (ctx->variables[i] == NULL)
  ------------------
  |  Branch (765:13): [True: 267, False: 2.06k]
  ------------------
  766|    267|            break;
  767|       |
  768|  2.06k|        int cb_retval = READSTAT_HANDLER_OK;
  769|  2.06k|        if (ctx->handle.variable) {
  ------------------
  |  Branch (769:13): [True: 2.06k, False: 0]
  ------------------
  770|  2.06k|            cb_retval = ctx->handle.variable(i, ctx->variables[i], ctx->variables[i]->format, ctx->user_ctx);
  771|  2.06k|        }
  772|  2.06k|        if (cb_retval == READSTAT_HANDLER_ABORT) {
  ------------------
  |  Branch (772:13): [True: 0, False: 2.06k]
  ------------------
  773|      0|            retval = READSTAT_ERROR_USER_ABORT;
  774|      0|            goto cleanup;
  775|      0|        }
  776|       |
  777|  2.06k|        if (cb_retval == READSTAT_HANDLER_SKIP_VARIABLE) {
  ------------------
  |  Branch (777:13): [True: 0, False: 2.06k]
  ------------------
  778|      0|            ctx->variables[i]->skip = 1;
  779|  2.06k|        } else {
  780|  2.06k|            index_after_skipping++;
  781|  2.06k|        }
  782|  2.06k|    }
  783|  1.32k|cleanup:
  784|  1.32k|    return retval;
  785|    441|}
readstat_sas7bdat_read.c:sas7bdat_init_variable:
  675|  2.32k|        int index_after_skipping, readstat_error_t *out_retval) {
  676|  2.32k|    readstat_error_t retval = READSTAT_OK;
  677|  2.32k|    readstat_variable_t *variable = readstat_calloc(1, sizeof(readstat_variable_t));
  678|       |
  679|  2.32k|    variable->index = i;
  680|  2.32k|    variable->index_after_skipping = index_after_skipping;
  681|  2.32k|    variable->type = ctx->col_info[i].type;
  682|  2.32k|    variable->storage_width = ctx->col_info[i].width;
  683|       |
  684|  2.32k|    if ((retval = sas7bdat_validate_column(&ctx->col_info[i])) != READSTAT_OK) {
  ------------------
  |  Branch (684:9): [True: 121, False: 2.20k]
  ------------------
  685|    121|        goto cleanup;
  686|    121|    }
  687|  2.20k|    if ((retval = sas7bdat_copy_text_ref(variable->name, sizeof(variable->name), 
  ------------------
  |  Branch (687:9): [True: 50, False: 2.15k]
  ------------------
  688|  2.20k|                    ctx->col_info[i].name_ref, ctx)) != READSTAT_OK) {
  689|     50|        goto cleanup;
  690|     50|    }
  691|  2.15k|    if ((retval = sas7bdat_copy_text_ref(variable->format, sizeof(variable->format),
  ------------------
  |  Branch (691:9): [True: 46, False: 2.11k]
  ------------------
  692|  2.15k|                    ctx->col_info[i].format_ref, ctx)) != READSTAT_OK) {
  693|     46|        goto cleanup;
  694|     46|    }
  695|  2.11k|    size_t len = strlen(variable->format);
  696|  2.11k|    if (len && ctx->col_info[i].format_len) {
  ------------------
  |  Branch (696:9): [True: 399, False: 1.71k]
  |  Branch (696:16): [True: 168, False: 231]
  ------------------
  697|    168|        snprintf(variable->format + len, sizeof(variable->format) - len, "%d", ctx->col_info[i].format_len);
  698|    168|    }
  699|  2.11k|    if ((retval = sas7bdat_copy_text_ref(variable->label, sizeof(variable->label), 
  ------------------
  |  Branch (699:9): [True: 50, False: 2.06k]
  ------------------
  700|  2.11k|                    ctx->col_info[i].label_ref, ctx)) != READSTAT_OK) {
  701|     50|        goto cleanup;
  702|     50|    }
  703|       |
  704|  2.32k|cleanup:
  705|  2.32k|    if (retval != READSTAT_OK) {
  ------------------
  |  Branch (705:9): [True: 267, False: 2.06k]
  ------------------
  706|    267|        if (out_retval)
  ------------------
  |  Branch (706:13): [True: 267, False: 0]
  ------------------
  707|    267|            *out_retval = retval;
  708|       |
  709|    267|        if (retval == READSTAT_ERROR_CONVERT_BAD_STRING) {
  ------------------
  |  Branch (709:13): [True: 8, False: 259]
  ------------------
  710|      8|            if (ctx->handle.error) {
  ------------------
  |  Branch (710:17): [True: 0, False: 8]
  ------------------
  711|      0|                snprintf(ctx->error_buf, sizeof(ctx->error_buf),
  712|      0|                        "ReadStat: Error converting variable #%d info to specified encoding: %s %s (%s)",
  713|      0|                        i, variable->name, variable->format, variable->label);
  714|      0|                ctx->handle.error(ctx->error_buf, ctx->user_ctx);
  715|      0|            }
  716|      8|        }
  717|       |
  718|    267|        free(variable);
  719|       |
  720|    267|        return NULL;
  721|    267|    }
  722|       |
  723|  2.06k|    return variable;
  724|  2.32k|}
readstat_sas7bdat_read.c:sas7bdat_validate_column:
  660|  2.32k|static readstat_error_t sas7bdat_validate_column(col_info_t *col_info) {
  661|  2.32k|    if (col_info->type == READSTAT_TYPE_DOUBLE) {
  ------------------
  |  Branch (661:9): [True: 896, False: 1.43k]
  ------------------
  662|    896|        if (col_info->width > 8 || col_info->width < 3) {
  ------------------
  |  Branch (662:13): [True: 50, False: 846]
  |  Branch (662:36): [True: 3, False: 843]
  ------------------
  663|     53|            return READSTAT_ERROR_PARSE;
  664|     53|        }
  665|    896|    }
  666|  2.27k|    if (col_info->type == READSTAT_TYPE_STRING) {
  ------------------
  |  Branch (666:9): [True: 1.43k, False: 843]
  ------------------
  667|  1.43k|        if (col_info->width > INT16_MAX || col_info->width == 0) {
  ------------------
  |  Branch (667:13): [True: 26, False: 1.40k]
  |  Branch (667:44): [True: 42, False: 1.36k]
  ------------------
  668|     68|            return READSTAT_ERROR_PARSE;
  669|     68|        }
  670|  1.43k|    }
  671|  2.20k|    return READSTAT_OK;
  672|  2.27k|}
readstat_sas7bdat_read.c:sas7bdat_update_progress:
  127|  4.76k|static readstat_error_t sas7bdat_update_progress(sas7bdat_ctx_t *ctx) {
  128|  4.76k|    readstat_io_t *io = ctx->io;
  129|  4.76k|    return io->update(ctx->file_size, ctx->handle.progress, ctx->user_ctx, io->io_ctx);
  130|  4.76k|}
readstat_sas7bdat_read.c:sas7bdat_ctx_free:
   93|  3.31k|static void sas7bdat_ctx_free(sas7bdat_ctx_t *ctx) {
   94|  3.31k|    int i;
   95|  3.31k|    if (ctx->text_blobs) {
  ------------------
  |  Branch (95:9): [True: 875, False: 2.43k]
  ------------------
   96|  3.80k|        for (i=0; i<ctx->text_blob_count; i++) {
  ------------------
  |  Branch (96:19): [True: 2.93k, False: 875]
  ------------------
   97|  2.93k|            free(ctx->text_blobs[i]);
   98|  2.93k|        }
   99|    875|        free(ctx->text_blobs);
  100|    875|        free(ctx->text_blob_lengths);
  101|    875|    }
  102|  3.31k|    if (ctx->variables) {
  ------------------
  |  Branch (102:9): [True: 441, False: 2.87k]
  ------------------
  103|  13.7M|        for (i=0; i<ctx->column_count; i++) {
  ------------------
  |  Branch (103:19): [True: 13.7M, False: 441]
  ------------------
  104|  13.7M|            if (ctx->variables[i])
  ------------------
  |  Branch (104:17): [True: 2.06k, False: 13.7M]
  ------------------
  105|  2.06k|                free(ctx->variables[i]);
  106|  13.7M|        }
  107|    441|        free(ctx->variables);
  108|    441|    }
  109|  3.31k|    if (ctx->col_info)
  ------------------
  |  Branch (109:9): [True: 658, False: 2.65k]
  ------------------
  110|    658|        free(ctx->col_info);
  111|       |
  112|  3.31k|    if (ctx->scratch_buffer)
  ------------------
  |  Branch (112:9): [True: 530, False: 2.78k]
  ------------------
  113|    530|        free(ctx->scratch_buffer);
  114|       |
  115|  3.31k|    if (ctx->page)
  ------------------
  |  Branch (115:9): [True: 2.79k, False: 513]
  ------------------
  116|  2.79k|        free(ctx->page);
  117|       |
  118|  3.31k|    if (ctx->row)
  ------------------
  |  Branch (118:9): [True: 968, False: 2.34k]
  ------------------
  119|    968|        free(ctx->row);
  120|       |
  121|  3.31k|    if (ctx->converter)
  ------------------
  |  Branch (121:9): [True: 1.94k, False: 1.36k]
  ------------------
  122|  1.94k|        iconv_close(ctx->converter);
  123|       |
  124|  3.31k|    free(ctx);
  125|  3.31k|}

sas_rle_decompress:
   47|    359|        const void *input_buf, size_t input_len) {
   48|    359|    unsigned char *buffer = (unsigned char *)output_buf;
   49|    359|    unsigned char *output = buffer;
   50|    359|    size_t output_written = 0;
   51|       |
   52|    359|    const unsigned char *input = (const unsigned char *)input_buf;
   53|       |
   54|  12.8k|    while (input < (const unsigned char *)input_buf + input_len) {
  ------------------
  |  Branch (54:12): [True: 12.5k, False: 252]
  ------------------
   55|  12.5k|        unsigned char control = *input++;
   56|  12.5k|        unsigned char command = (control & 0xF0) >> 4;
   57|  12.5k|        unsigned char length = (control & 0x0F);
   58|  12.5k|        int copy_len = 0;
   59|  12.5k|        int insert_len = 0;
   60|  12.5k|        unsigned char insert_byte = '\0';
   61|  12.5k|        if (input + command_lengths[command] > (const unsigned char *)input_buf + input_len) {
  ------------------
  |  Branch (61:13): [True: 1, False: 12.5k]
  ------------------
   62|      1|            return -1;
   63|      1|        }
   64|  12.5k|        switch (command) {
   65|    808|            case SAS_RLE_COMMAND_COPY64:
  ------------------
  |  |   13|    808|#define SAS_RLE_COMMAND_COPY64          0
  ------------------
  |  Branch (65:13): [True: 808, False: 11.7k]
  ------------------
   66|    808|                copy_len = (*input++) + 64 + length * 256;
   67|    808|                break;
   68|     36|            case SAS_RLE_COMMAND_COPY64_PLUS_4096:
  ------------------
  |  |   14|     36|#define SAS_RLE_COMMAND_COPY64_PLUS_4096 1
  ------------------
  |  Branch (68:13): [True: 36, False: 12.5k]
  ------------------
   69|     36|                copy_len = (*input++) + 64 + length * 256 + 4096;
   70|     36|                break;
   71|    363|            case SAS_RLE_COMMAND_COPY96: copy_len = length + 96; break;
  ------------------
  |  |   15|    363|#define SAS_RLE_COMMAND_COPY96          2
  ------------------
  |  Branch (71:13): [True: 363, False: 12.2k]
  ------------------
   72|    604|            case SAS_RLE_COMMAND_INSERT_BYTE18:
  ------------------
  |  |   16|    604|#define SAS_RLE_COMMAND_INSERT_BYTE18   4
  ------------------
  |  Branch (72:13): [True: 604, False: 11.9k]
  ------------------
   73|    604|                insert_len = (*input++) + 18 + length * 256;
   74|    604|                insert_byte = *input++;
   75|    604|                break;
   76|    575|            case SAS_RLE_COMMAND_INSERT_AT17:
  ------------------
  |  |   17|    575|#define SAS_RLE_COMMAND_INSERT_AT17     5
  ------------------
  |  Branch (76:13): [True: 575, False: 12.0k]
  ------------------
   77|    575|                insert_len = (*input++) + 17 + length * 256;
   78|    575|                insert_byte = '@';
   79|    575|                break;
   80|    826|            case SAS_RLE_COMMAND_INSERT_BLANK17:
  ------------------
  |  |   18|    826|#define SAS_RLE_COMMAND_INSERT_BLANK17  6
  ------------------
  |  Branch (80:13): [True: 826, False: 11.7k]
  ------------------
   81|    826|                insert_len = (*input++) + 17 + length * 256;
   82|    826|                insert_byte = ' ';
   83|    826|                break;
   84|    418|            case SAS_RLE_COMMAND_INSERT_ZERO17:
  ------------------
  |  |   19|    418|#define SAS_RLE_COMMAND_INSERT_ZERO17   7
  ------------------
  |  Branch (84:13): [True: 418, False: 12.1k]
  ------------------
   85|    418|                insert_len = (*input++) + 17 + length * 256;
   86|    418|                insert_byte = '\0';
   87|    418|                break;
   88|    618|            case SAS_RLE_COMMAND_COPY1:  copy_len = length + 1; break;
  ------------------
  |  |   20|    618|#define SAS_RLE_COMMAND_COPY1           8
  ------------------
  |  Branch (88:13): [True: 618, False: 11.9k]
  ------------------
   89|    387|            case SAS_RLE_COMMAND_COPY17: copy_len = length + 17; break;
  ------------------
  |  |   21|    387|#define SAS_RLE_COMMAND_COPY17          9
  ------------------
  |  Branch (89:13): [True: 387, False: 12.1k]
  ------------------
   90|    347|            case SAS_RLE_COMMAND_COPY33: copy_len = length + 33; break;
  ------------------
  |  |   22|    347|#define SAS_RLE_COMMAND_COPY33         10
  ------------------
  |  Branch (90:13): [True: 347, False: 12.2k]
  ------------------
   91|    306|            case SAS_RLE_COMMAND_COPY49: copy_len = length + 49; break;
  ------------------
  |  |   23|    306|#define SAS_RLE_COMMAND_COPY49         11
  ------------------
  |  Branch (91:13): [True: 306, False: 12.2k]
  ------------------
   92|    843|            case SAS_RLE_COMMAND_INSERT_BYTE3:
  ------------------
  |  |   24|    843|#define SAS_RLE_COMMAND_INSERT_BYTE3   12
  ------------------
  |  Branch (92:13): [True: 843, False: 11.7k]
  ------------------
   93|    843|                insert_byte = *input++;
   94|    843|                insert_len = length + 3;
   95|    843|                break;
   96|  1.10k|            case SAS_RLE_COMMAND_INSERT_AT2:
  ------------------
  |  |   25|  1.10k|#define SAS_RLE_COMMAND_INSERT_AT2     13
  ------------------
  |  Branch (96:13): [True: 1.10k, False: 11.4k]
  ------------------
   97|  1.10k|                insert_byte = '@';
   98|  1.10k|                insert_len = length + 2;
   99|  1.10k|                break;
  100|    814|            case SAS_RLE_COMMAND_INSERT_BLANK2:
  ------------------
  |  |   26|    814|#define SAS_RLE_COMMAND_INSERT_BLANK2  14
  ------------------
  |  Branch (100:13): [True: 814, False: 11.7k]
  ------------------
  101|    814|                insert_byte = ' ';
  102|    814|                insert_len = length + 2;
  103|    814|                break;
  104|  2.89k|            case SAS_RLE_COMMAND_INSERT_ZERO2:
  ------------------
  |  |   27|  2.89k|#define SAS_RLE_COMMAND_INSERT_ZERO2   15
  ------------------
  |  Branch (104:13): [True: 2.89k, False: 9.68k]
  ------------------
  105|  2.89k|                insert_byte = '\0';
  106|  2.89k|                insert_len = length + 2;
  107|  2.89k|                break;
  108|  1.63k|            default:
  ------------------
  |  Branch (108:13): [True: 1.63k, False: 10.9k]
  ------------------
  109|       |                /* error out here? */
  110|  1.63k|                break;
  111|  12.5k|        }
  112|  12.5k|        if (copy_len) {
  ------------------
  |  Branch (112:13): [True: 2.86k, False: 9.71k]
  ------------------
  113|  2.86k|            if (output_written + copy_len > output_len) {
  ------------------
  |  Branch (113:17): [True: 23, False: 2.84k]
  ------------------
  114|     23|                return -1;
  115|     23|            }
  116|  2.84k|            if (input + copy_len > (const unsigned char *)input_buf + input_len) {
  ------------------
  |  Branch (116:17): [True: 59, False: 2.78k]
  ------------------
  117|     59|                return -1;
  118|     59|            }
  119|  2.78k|            if (output) {
  ------------------
  |  Branch (119:17): [True: 2.78k, False: 0]
  ------------------
  120|  2.78k|                memcpy(&output[output_written], input, copy_len);
  121|  2.78k|            }
  122|  2.78k|            input += copy_len;
  123|  2.78k|            output_written += copy_len;
  124|  2.78k|        }
  125|  12.4k|        if (insert_len) {
  ------------------
  |  Branch (125:13): [True: 8.07k, False: 4.41k]
  ------------------
  126|  8.07k|            if (output_written + insert_len > output_len) {
  ------------------
  |  Branch (126:17): [True: 24, False: 8.05k]
  ------------------
  127|     24|                return -1;
  128|     24|            }
  129|  8.05k|            if (output) {
  ------------------
  |  Branch (129:17): [True: 8.05k, False: 0]
  ------------------
  130|  8.05k|                memset(&output[output_written], insert_byte, insert_len);
  131|  8.05k|            }
  132|  8.05k|            output_written += insert_len;
  133|  8.05k|        }
  134|  12.4k|    }
  135|       |
  136|    252|    return output_written;
  137|    359|}

rt_open_handler:
    8|  3.31k|int rt_open_handler(const char *path, void *io_ctx) {
    9|  3.31k|    return 0;
   10|  3.31k|}
rt_close_handler:
   12|  3.31k|int rt_close_handler(void *io_ctx) {
   13|  3.31k|    return 0;
   14|  3.31k|}
rt_seek_handler:
   17|  31.0k|        readstat_io_flags_t whence, void *io_ctx) {
   18|  31.0k|    rt_buffer_ctx_t *buffer_ctx = (rt_buffer_ctx_t *)io_ctx;
   19|  31.0k|    readstat_off_t newpos = -1;
   20|  31.0k|    if (whence == READSTAT_SEEK_SET) {
  ------------------
  |  Branch (20:9): [True: 18.5k, False: 12.5k]
  ------------------
   21|  18.5k|        newpos = offset;
   22|  18.5k|    } else if (whence == READSTAT_SEEK_CUR) {
  ------------------
  |  Branch (22:16): [True: 9.21k, False: 3.31k]
  ------------------
   23|  9.21k|        newpos = buffer_ctx->pos + offset;
   24|  9.21k|    } else if (whence == READSTAT_SEEK_END) {
  ------------------
  |  Branch (24:16): [True: 3.31k, False: 0]
  ------------------
   25|  3.31k|        newpos = buffer_ctx->buffer->used + offset;
   26|  3.31k|    }
   27|       |
   28|  31.0k|    if (newpos < 0)
  ------------------
  |  Branch (28:9): [True: 148, False: 30.8k]
  ------------------
   29|    148|        return -1;
   30|       |
   31|  30.8k|    if (newpos > buffer_ctx->buffer->used)
  ------------------
  |  Branch (31:9): [True: 234, False: 30.6k]
  ------------------
   32|    234|        return -1;
   33|       |
   34|  30.6k|    buffer_ctx->pos = newpos;
   35|  30.6k|    return newpos;
   36|  30.8k|}
rt_read_handler:
   38|  42.8k|ssize_t rt_read_handler(void *buf, size_t nbytes, void *io_ctx) {
   39|  42.8k|    rt_buffer_ctx_t *buffer_ctx = (rt_buffer_ctx_t *)io_ctx;
   40|  42.8k|    ssize_t bytes_copied = 0;
   41|  42.8k|    ssize_t bytes_left = buffer_ctx->buffer->used - buffer_ctx->pos;
   42|  42.8k|    if (nbytes <= bytes_left) {
  ------------------
  |  Branch (42:9): [True: 42.4k, False: 397]
  ------------------
   43|  42.4k|        memcpy(buf, buffer_ctx->buffer->bytes + buffer_ctx->pos, nbytes);
   44|  42.4k|        bytes_copied = nbytes;
   45|  42.4k|    } else if (bytes_left > 0) {
  ------------------
  |  Branch (45:16): [True: 145, False: 252]
  ------------------
   46|    145|        memcpy(buf, buffer_ctx->buffer->bytes + buffer_ctx->pos, bytes_left);
   47|    145|        bytes_copied = bytes_left;
   48|    145|    }
   49|  42.8k|    buffer_ctx->pos += bytes_copied;
   50|  42.8k|    return bytes_copied;
   51|  42.8k|}
rt_update_handler:
   54|  4.76k|        void *user_ctx, void *io_ctx) {
   55|  4.76k|    if (!progress_handler)
  ------------------
  |  Branch (55:9): [True: 4.76k, False: 0]
  ------------------
   56|  4.76k|        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|}

