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

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

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

readstat_convert:
    7|  7.15M|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|  7.20M|    while (src_len && (src[src_len-1] == ' ' || src[src_len-1] == '\0')) {
  ------------------
  |  Branch (10:12): [True: 66.9k, False: 7.13M]
  |  Branch (10:24): [True: 4.11k, False: 62.8k]
  |  Branch (10:49): [True: 43.2k, False: 19.5k]
  ------------------
   11|  47.4k|        src_len--;
   12|  47.4k|    }
   13|  7.15M|    if (dst_len == 0) {
  ------------------
  |  Branch (13:9): [True: 0, False: 7.15M]
  ------------------
   14|      0|        return READSTAT_ERROR_CONVERT_LONG_STRING;
   15|  7.15M|    } else if (converter) {
  ------------------
  |  Branch (15:16): [True: 6.08M, False: 1.06M]
  ------------------
   16|  6.08M|        size_t dst_left = dst_len - 1;
   17|  6.08M|        char *dst_end = dst;
   18|  6.08M|        size_t status = iconv(converter, (readstat_iconv_inbuf_t)&src, &src_len, &dst_end, &dst_left);
   19|  6.08M|        if (status == (size_t)-1) {
  ------------------
  |  Branch (19:13): [True: 3.37k, False: 6.08M]
  ------------------
   20|  3.37k|            if (errno == E2BIG) {
  ------------------
  |  Branch (20:17): [True: 6, False: 3.36k]
  ------------------
   21|      6|                return READSTAT_ERROR_CONVERT_LONG_STRING;
   22|  3.36k|            } else if (errno == EILSEQ) {
  ------------------
  |  Branch (22:24): [True: 32, False: 3.33k]
  ------------------
   23|     32|                return READSTAT_ERROR_CONVERT_BAD_STRING;
   24|  3.33k|            } else if (errno != EINVAL) { /* EINVAL indicates improper truncation; accept it */
  ------------------
  |  Branch (24:24): [True: 0, False: 3.33k]
  ------------------
   25|      0|                return READSTAT_ERROR_CONVERT;
   26|      0|            }
   27|  3.37k|        }
   28|  6.08M|        dst[dst_len - dst_left - 1] = '\0';
   29|  6.08M|    } else if (src_len + 1 > dst_len) {
  ------------------
  |  Branch (29:16): [True: 14, False: 1.06M]
  ------------------
   30|     14|        return READSTAT_ERROR_CONVERT_LONG_STRING;
   31|  1.06M|    } else {
   32|  1.06M|        memcpy(dst, src, src_len);
   33|  1.06M|        dst[src_len] = '\0';
   34|  1.06M|    }
   35|  7.15M|    return READSTAT_OK;
   36|  7.15M|}

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

readstat_malloc:
   10|  5.97k|void *readstat_malloc(size_t len) {
   11|  5.97k|    if (len > MAX_MALLOC_SIZE || len == 0) {
  ------------------
  |  |    3|  11.9k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
  |  Branch (11:9): [True: 0, False: 5.97k]
  |  Branch (11:34): [True: 0, False: 5.97k]
  ------------------
   12|      0|        return NULL;
   13|      0|    }
   14|  5.97k|    return malloc(len);
   15|  5.97k|}
readstat_calloc:
   17|  3.15M|void *readstat_calloc(size_t count, size_t size) {
   18|  3.15M|    if (count > MAX_MALLOC_SIZE || size > MAX_MALLOC_SIZE || count * size > MAX_MALLOC_SIZE) {
  ------------------
  |  |    3|  6.30M|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
                  if (count > MAX_MALLOC_SIZE || size > MAX_MALLOC_SIZE || count * size > MAX_MALLOC_SIZE) {
  ------------------
  |  |    3|  6.30M|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
                  if (count > MAX_MALLOC_SIZE || size > MAX_MALLOC_SIZE || count * size > MAX_MALLOC_SIZE) {
  ------------------
  |  |    3|  3.15M|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
  |  Branch (18:9): [True: 0, False: 3.15M]
  |  Branch (18:36): [True: 0, False: 3.15M]
  |  Branch (18:62): [True: 0, False: 3.15M]
  ------------------
   19|      0|        return NULL;
   20|      0|    }
   21|  3.15M|    if (count == 0 || size == 0) {
  ------------------
  |  Branch (21:9): [True: 0, False: 3.15M]
  |  Branch (21:23): [True: 0, False: 3.15M]
  ------------------
   22|      0|        return NULL;
   23|      0|    }
   24|  3.15M|    return calloc(count, size);
   25|  3.15M|}
readstat_realloc:
   27|   154k|void *readstat_realloc(void *ptr, size_t len) {
   28|   154k|    if (len > MAX_MALLOC_SIZE || len == 0) {
  ------------------
  |  |    3|   308k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
  |  Branch (28:9): [True: 89, False: 154k]
  |  Branch (28:34): [True: 1, False: 154k]
  ------------------
   29|     90|        if (ptr)
  ------------------
  |  Branch (29:13): [True: 56, False: 34]
  ------------------
   30|     56|            free(ptr);
   31|     90|        return NULL;
   32|     90|    }
   33|   154k|    return realloc(ptr, len);
   34|   154k|}

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

sas_read8:
  139|  45.0k|uint64_t sas_read8(const char *data, int bswap) {
  140|  45.0k|    uint64_t tmp;
  141|  45.0k|    memcpy(&tmp, data, 8);
  142|  45.0k|    return bswap ? byteswap8(tmp) : tmp;
  ------------------
  |  Branch (142:12): [True: 39.1k, False: 5.91k]
  ------------------
  143|  45.0k|}
sas_read4:
  145|   229k|uint32_t sas_read4(const char *data, int bswap) {
  146|   229k|    uint32_t tmp;
  147|   229k|    memcpy(&tmp, data, 4);
  148|   229k|    return bswap ? byteswap4(tmp) : tmp;
  ------------------
  |  Branch (148:12): [True: 175k, False: 53.3k]
  ------------------
  149|   229k|}
sas_read2:
  151|   195k|uint16_t sas_read2(const char *data, int bswap) {
  152|   195k|    uint16_t tmp;
  153|   195k|    memcpy(&tmp, data, 2);
  154|   195k|    return bswap ? byteswap2(tmp) : tmp;
  ------------------
  |  Branch (154:12): [True: 75.3k, False: 120k]
  ------------------
  155|   195k|}
sas_subheader_remainder:
  157|  6.07k|size_t sas_subheader_remainder(size_t len, size_t signature_len) {
  158|  6.07k|    return len - (4+2*signature_len);
  159|  6.07k|}
sas_read_header:
  162|  3.67k|        readstat_error_handler error_handler, void *user_ctx) {
  163|  3.67k|    sas_header_start_t  header_start;
  164|  3.67k|    sas_header_end_t    header_end;
  165|  3.67k|    int retval = READSTAT_OK;
  166|  3.67k|    char error_buf[1024];
  167|  3.67k|    time_t epoch = sas_epoch();
  168|       |
  169|  3.67k|    if (io->read(&header_start, sizeof(sas_header_start_t), io->io_ctx) < sizeof(sas_header_start_t)) {
  ------------------
  |  Branch (169:9): [True: 19, False: 3.65k]
  ------------------
  170|     19|        retval = READSTAT_ERROR_READ;
  171|     19|        goto cleanup;
  172|     19|    }
  173|  3.65k|    if (memcmp(header_start.magic, sas7bdat_magic_number, sizeof(sas7bdat_magic_number)) != 0 &&
  ------------------
  |  Branch (173:9): [True: 1.73k, False: 1.92k]
  ------------------
  174|  1.73k|            memcmp(header_start.magic, sas7bcat_magic_number, sizeof(sas7bcat_magic_number)) != 0) {
  ------------------
  |  Branch (174:13): [True: 135, False: 1.59k]
  ------------------
  175|    135|        retval = READSTAT_ERROR_PARSE;
  176|    135|        goto cleanup;
  177|    135|    }
  178|  3.52k|    if (header_start.a1 == SAS_ALIGNMENT_OFFSET_4) {
  ------------------
  |  |   87|  3.52k|#define SAS_ALIGNMENT_OFFSET_4  0x33
  ------------------
  |  Branch (178:9): [True: 7, False: 3.51k]
  ------------------
  179|      7|        hinfo->pad1 = 4;
  180|      7|    }
  181|  3.52k|    if (header_start.a2 == SAS_ALIGNMENT_OFFSET_4) {
  ------------------
  |  |   87|  3.52k|#define SAS_ALIGNMENT_OFFSET_4  0x33
  ------------------
  |  Branch (181:9): [True: 1.61k, False: 1.90k]
  ------------------
  182|  1.61k|        hinfo->u64 = 1;
  183|  1.61k|    }
  184|  3.52k|    int bswap = 0;
  185|  3.52k|    if (header_start.endian == SAS_ENDIAN_BIG) {
  ------------------
  |  |   80|  3.52k|#define SAS_ENDIAN_BIG       0x00
  ------------------
  |  Branch (185:9): [True: 2.91k, False: 605]
  ------------------
  186|  2.91k|        bswap = machine_is_little_endian();
  187|  2.91k|        hinfo->little_endian = 0;
  188|  2.91k|    } else if (header_start.endian == SAS_ENDIAN_LITTLE) {
  ------------------
  |  |   81|    605|#define SAS_ENDIAN_LITTLE    0x01
  ------------------
  |  Branch (188:16): [True: 591, False: 14]
  ------------------
  189|    591|        bswap = !machine_is_little_endian();
  190|    591|        hinfo->little_endian = 1;
  191|    591|    } else {
  192|     14|        retval = READSTAT_ERROR_PARSE;
  193|     14|        goto cleanup;
  194|     14|    }
  195|  3.50k|    int i;
  196|  26.1k|    for (i=0; i<sizeof(_charset_table)/sizeof(_charset_table[0]); i++) {
  ------------------
  |  Branch (196:15): [True: 26.1k, False: 6]
  ------------------
  197|  26.1k|        if (header_start.encoding == _charset_table[i].code) {
  ------------------
  |  Branch (197:13): [True: 3.50k, False: 22.6k]
  ------------------
  198|  3.50k|            hinfo->encoding = _charset_table[i].name;
  199|  3.50k|            break;
  200|  3.50k|        }
  201|  26.1k|    }
  202|  3.50k|    if (hinfo->encoding == NULL) {
  ------------------
  |  Branch (202:9): [True: 6, False: 3.50k]
  ------------------
  203|      6|        if (error_handler) {
  ------------------
  |  Branch (203:13): [True: 0, False: 6]
  ------------------
  204|      0|            snprintf(error_buf, sizeof(error_buf), "Unsupported character set code: %d", header_start.encoding);
  205|      0|            error_handler(error_buf, user_ctx);
  206|      0|        }
  207|      6|        retval = READSTAT_ERROR_UNSUPPORTED_CHARSET;
  208|      6|        goto cleanup;
  209|      6|    }
  210|  3.50k|    memcpy(hinfo->table_name, header_start.table_name, sizeof(header_start.table_name));
  211|  3.50k|    if (io->seek(hinfo->pad1, READSTAT_SEEK_CUR, io->io_ctx) == -1) {
  ------------------
  |  Branch (211:9): [True: 3, False: 3.49k]
  ------------------
  212|      3|        retval = READSTAT_ERROR_SEEK;
  213|      3|        goto cleanup;
  214|      3|    }
  215|       |
  216|  3.49k|    double creation_time, modification_time, creation_time_diff, modification_time_diff;
  217|       |
  218|  3.49k|    if (io->read(&creation_time, sizeof(double), io->io_ctx) < sizeof(double)) {
  ------------------
  |  Branch (218:9): [True: 12, False: 3.48k]
  ------------------
  219|     12|        retval = READSTAT_ERROR_READ;
  220|     12|        goto cleanup;
  221|     12|    }
  222|  3.48k|    if (bswap)
  ------------------
  |  Branch (222:9): [True: 2.89k, False: 587]
  ------------------
  223|  2.89k|        creation_time = byteswap_double(creation_time);
  224|       |
  225|  3.48k|    if (io->read(&modification_time, sizeof(double), io->io_ctx) < sizeof(double)) {
  ------------------
  |  Branch (225:9): [True: 6, False: 3.47k]
  ------------------
  226|      6|        retval = READSTAT_ERROR_READ;
  227|      6|        goto cleanup;
  228|      6|    }
  229|  3.47k|    if (bswap)
  ------------------
  |  Branch (229:9): [True: 2.89k, False: 585]
  ------------------
  230|  2.89k|        modification_time = byteswap_double(modification_time);
  231|       |
  232|  3.47k|    if (io->read(&creation_time_diff, sizeof(double), io->io_ctx) < sizeof(double)) {
  ------------------
  |  Branch (232:9): [True: 6, False: 3.47k]
  ------------------
  233|      6|        retval = READSTAT_ERROR_READ;
  234|      6|        goto cleanup;
  235|      6|    }
  236|  3.47k|    if (bswap)
  ------------------
  |  Branch (236:9): [True: 2.89k, False: 583]
  ------------------
  237|  2.89k|        creation_time_diff = byteswap_double(creation_time_diff);
  238|       |    
  239|  3.47k|    if (io->read(&modification_time_diff, sizeof(double), io->io_ctx) < sizeof(double)) {
  ------------------
  |  Branch (239:9): [True: 6, False: 3.46k]
  ------------------
  240|      6|        retval = READSTAT_ERROR_READ;
  241|      6|        goto cleanup;
  242|      6|    }
  243|  3.46k|    if (bswap)
  ------------------
  |  Branch (243:9): [True: 2.88k, False: 581]
  ------------------
  244|  2.88k|        modification_time_diff = byteswap_double(modification_time_diff);
  245|       |    
  246|  3.46k|    hinfo->creation_time = sas_convert_time(creation_time, creation_time_diff, epoch);
  247|  3.46k|    hinfo->modification_time = sas_convert_time(modification_time, modification_time_diff, epoch);
  248|       |
  249|  3.46k|    uint32_t header_size, page_size;
  250|       |
  251|  3.46k|    if (io->read(&header_size, sizeof(uint32_t), io->io_ctx) < sizeof(uint32_t)) {
  ------------------
  |  Branch (251:9): [True: 9, False: 3.45k]
  ------------------
  252|      9|        retval = READSTAT_ERROR_READ;
  253|      9|        goto cleanup;
  254|      9|    }
  255|  3.45k|    if (io->read(&page_size, sizeof(uint32_t), io->io_ctx) < sizeof(uint32_t)) {
  ------------------
  |  Branch (255:9): [True: 3, False: 3.45k]
  ------------------
  256|      3|        retval = READSTAT_ERROR_READ;
  257|      3|        goto cleanup;
  258|      3|    }
  259|       |
  260|  3.45k|    hinfo->header_size = bswap ? byteswap4(header_size) : header_size;
  ------------------
  |  Branch (260:26): [True: 2.87k, False: 579]
  ------------------
  261|  3.45k|    hinfo->page_size = bswap ? byteswap4(page_size) : page_size;
  ------------------
  |  Branch (261:24): [True: 2.87k, False: 579]
  ------------------
  262|       |
  263|  3.45k|    if (hinfo->header_size < 1024 || hinfo->page_size < 1024) {
  ------------------
  |  Branch (263:9): [True: 11, False: 3.44k]
  |  Branch (263:38): [True: 9, False: 3.43k]
  ------------------
  264|     20|        retval = READSTAT_ERROR_PARSE;
  265|     20|        goto cleanup;
  266|     20|    }
  267|  3.43k|    if (hinfo->header_size > (1<<24) || hinfo->page_size > (1<<24)) {
  ------------------
  |  Branch (267:9): [True: 20, False: 3.41k]
  |  Branch (267:41): [True: 30, False: 3.38k]
  ------------------
  268|     50|        retval = READSTAT_ERROR_PARSE;
  269|     50|        goto cleanup;
  270|     50|    }
  271|       |
  272|  3.38k|    if (hinfo->u64) {
  ------------------
  |  Branch (272:9): [True: 1.56k, False: 1.81k]
  ------------------
  273|  1.56k|        hinfo->page_header_size = SAS_PAGE_HEADER_SIZE_64BIT;
  ------------------
  |  |  121|  1.56k|#define SAS_PAGE_HEADER_SIZE_64BIT  40
  ------------------
  274|  1.56k|        hinfo->subheader_pointer_size = SAS_SUBHEADER_POINTER_SIZE_64BIT;
  ------------------
  |  |  118|  1.56k|#define SAS_SUBHEADER_POINTER_SIZE_64BIT    24
  ------------------
  275|  1.81k|    } else {
  276|  1.81k|        hinfo->page_header_size = SAS_PAGE_HEADER_SIZE_32BIT;
  ------------------
  |  |  120|  1.81k|#define SAS_PAGE_HEADER_SIZE_32BIT  24
  ------------------
  277|  1.81k|        hinfo->subheader_pointer_size = SAS_SUBHEADER_POINTER_SIZE_32BIT;
  ------------------
  |  |  117|  1.81k|#define SAS_SUBHEADER_POINTER_SIZE_32BIT    12
  ------------------
  278|  1.81k|    }
  279|       |
  280|  3.38k|    if (hinfo->u64) {
  ------------------
  |  Branch (280:9): [True: 1.56k, False: 1.81k]
  ------------------
  281|  1.56k|        uint64_t page_count;
  282|  1.56k|        if (io->read(&page_count, sizeof(uint64_t), io->io_ctx) < sizeof(uint64_t)) {
  ------------------
  |  Branch (282:13): [True: 22, False: 1.54k]
  ------------------
  283|     22|            retval = READSTAT_ERROR_READ;
  284|     22|            goto cleanup;
  285|     22|        }
  286|  1.54k|        hinfo->page_count = bswap ? byteswap8(page_count) : page_count;
  ------------------
  |  Branch (286:29): [True: 1.45k, False: 94]
  ------------------
  287|  1.81k|    } else {
  288|  1.81k|        uint32_t page_count;
  289|  1.81k|        if (io->read(&page_count, sizeof(uint32_t), io->io_ctx) < sizeof(uint32_t)) {
  ------------------
  |  Branch (289:13): [True: 16, False: 1.80k]
  ------------------
  290|     16|            retval = READSTAT_ERROR_READ;
  291|     16|            goto cleanup;
  292|     16|        }
  293|  1.80k|        hinfo->page_count = bswap ? byteswap4(page_count) : page_count;
  ------------------
  |  Branch (293:29): [True: 1.32k, False: 476]
  ------------------
  294|  1.80k|    }
  295|  3.34k|    if (hinfo->page_count > (1<<24)) {
  ------------------
  |  Branch (295:9): [True: 16, False: 3.33k]
  ------------------
  296|     16|        retval = READSTAT_ERROR_PARSE;
  297|     16|        goto cleanup;
  298|     16|    }
  299|       |    
  300|  3.33k|    if (io->seek(8, READSTAT_SEEK_CUR, io->io_ctx) == -1) {
  ------------------
  |  Branch (300:9): [True: 65, False: 3.26k]
  ------------------
  301|     65|        retval = READSTAT_ERROR_SEEK;
  302|     65|        if (error_handler) {
  ------------------
  |  Branch (302:13): [True: 0, False: 65]
  ------------------
  303|      0|            snprintf(error_buf, sizeof(error_buf), "ReadStat: Failed to seek forward by %d", 8);
  304|      0|            error_handler(error_buf, user_ctx);
  305|      0|        }
  306|     65|        goto cleanup;
  307|     65|    }
  308|  3.26k|    if (io->read(&header_end, sizeof(sas_header_end_t), io->io_ctx) < sizeof(sas_header_end_t)) {
  ------------------
  |  Branch (308:9): [True: 20, False: 3.24k]
  ------------------
  309|     20|        retval = READSTAT_ERROR_READ;
  310|     20|        goto cleanup;
  311|     20|    }
  312|  3.24k|    char major, revision_tag;
  313|  3.24k|    int minor, revision;
  314|  3.24k|    if (sscanf(header_end.release, "%c.%04d%c%1d", &major, &minor, &revision_tag, &revision) != 4) {
  ------------------
  |  Branch (314:9): [True: 4, False: 3.24k]
  ------------------
  315|      4|        retval = READSTAT_ERROR_PARSE;
  316|      4|        goto cleanup;
  317|      4|    }
  318|       |
  319|  3.24k|    if (major >= '1' && major <= '9') {
  ------------------
  |  Branch (319:9): [True: 3.23k, False: 10]
  |  Branch (319:25): [True: 3.22k, False: 8]
  ------------------
  320|  3.22k|        hinfo->major_version = major - '0';
  321|  3.22k|    } else if (major == 'V') {
  ------------------
  |  Branch (321:16): [True: 1, False: 17]
  ------------------
  322|       |        // It appears that SAS Visual Forecaster reports the major version as "V"
  323|       |        // Treat it as version 9 for all intents and purposes
  324|      1|        hinfo->major_version = 9;
  325|     17|    } else {
  326|     17|        retval = READSTAT_ERROR_PARSE;
  327|     17|        goto cleanup;
  328|     17|    }
  329|       |    // revision_tag is usually M, but J has been observed in the wild (not created with SAS?)
  330|  3.22k|    if (revision_tag != 'M' && revision_tag != 'J') {
  ------------------
  |  Branch (330:9): [True: 27, False: 3.19k]
  |  Branch (330:32): [True: 15, False: 12]
  ------------------
  331|     15|        retval = READSTAT_ERROR_PARSE;
  332|     15|        goto cleanup;
  333|     15|    }
  334|  3.21k|    hinfo->minor_version = minor;
  335|  3.21k|    hinfo->revision = revision;
  336|       |
  337|  3.21k|    if ((major == '8' || major == '9') && minor == 0 && revision == 0) {
  ------------------
  |  Branch (337:10): [True: 282, False: 2.92k]
  |  Branch (337:26): [True: 148, False: 2.78k]
  |  Branch (337:43): [True: 101, False: 329]
  |  Branch (337:57): [True: 85, False: 16]
  ------------------
  338|       |        /* A bit of a hack, but most SAS installations are running a minor update */
  339|     85|        hinfo->vendor = READSTAT_VENDOR_STAT_TRANSFER;
  340|  3.12k|    } else {
  341|  3.12k|        hinfo->vendor = READSTAT_VENDOR_SAS;
  342|  3.12k|    }
  343|  3.21k|    if (io->seek(hinfo->header_size, READSTAT_SEEK_SET, io->io_ctx) == -1) {
  ------------------
  |  Branch (343:9): [True: 53, False: 3.15k]
  ------------------
  344|     53|        retval = READSTAT_ERROR_SEEK;
  345|     53|        if (error_handler) {
  ------------------
  |  Branch (345:13): [True: 0, False: 53]
  ------------------
  346|      0|            snprintf(error_buf, sizeof(error_buf), 
  347|      0|                    "ReadStat: Failed to seek to position %" PRId64, hinfo->header_size);
  348|      0|            error_handler(error_buf, user_ctx);
  349|      0|        }
  350|     53|        goto cleanup;
  351|     53|    }
  352|       |
  353|  3.67k|cleanup:
  354|  3.67k|    return retval;
  355|  3.21k|}
sas_validate_tag:
  507|  7.98k|readstat_error_t sas_validate_tag(char tag) {
  508|  7.98k|    if (tag == '_' || (tag >= 'A' && tag <= 'Z'))
  ------------------
  |  Branch (508:9): [True: 4.43k, False: 3.55k]
  |  Branch (508:24): [True: 1.43k, False: 2.11k]
  |  Branch (508:38): [True: 888, False: 544]
  ------------------
  509|  5.32k|        return READSTAT_OK;
  510|       |
  511|  2.66k|    return READSTAT_ERROR_TAGGED_VALUE_IS_OUT_OF_RANGE;
  512|  7.98k|}
sas_assign_tag:
  514|  7.98k|void sas_assign_tag(readstat_value_t *value, uint8_t tag) {
  515|       |    /* We accommodate two tag schemes. In the first, the tag is an ASCII code
  516|       |     * given by uint8_t tag above. System missing is represented by an ASCII
  517|       |     * period. In the second scheme, (tag-2) is an offset from 'A', except when
  518|       |     * tag == 0, in which case it represents an underscore, or tag == 1, in
  519|       |     * which case it represents system-missing.
  520|       |     */
  521|  7.98k|    if (tag == 0) {
  ------------------
  |  Branch (521:9): [True: 4.43k, False: 3.55k]
  ------------------
  522|  4.43k|        tag = '_';
  523|  4.43k|    } else if (tag >= 2 && tag < 28) {
  ------------------
  |  Branch (523:16): [True: 3.19k, False: 354]
  |  Branch (523:28): [True: 711, False: 2.48k]
  ------------------
  524|    711|        tag = 'A' + (tag - 2);
  525|    711|    }
  526|  7.98k|    if (sas_validate_tag(tag) == READSTAT_OK) {
  ------------------
  |  Branch (526:9): [True: 5.32k, False: 2.66k]
  ------------------
  527|  5.32k|        value->tag = tag;
  528|  5.32k|        value->is_tagged_missing = 1;
  529|  5.32k|    } else {
  530|  2.66k|        value->tag = 0;
  531|  2.66k|        value->is_system_missing = 1;
  532|  2.66k|    }
  533|  7.98k|}
readstat_sas.c:sas_epoch:
  123|  3.67k|static time_t sas_epoch(void) {
  124|  3.67k|    return - 3653 * 86400; // seconds between 01-01-1960 and 01-01-1970
  125|  3.67k|}
readstat_sas.c:sas_convert_time:
  127|  6.93k|static time_t sas_convert_time(double time, double time_diff, time_t epoch) {
  128|  6.93k|    time -= time_diff;
  129|  6.93k|    time += epoch;
  130|  6.93k|    if (isnan(time))
  ------------------
  |  Branch (130:9): [True: 847, False: 6.08k]
  ------------------
  131|    847|        return 0;
  132|  6.08k|    if (time > (double)LONG_MAX)
  ------------------
  |  Branch (132:9): [True: 1.72k, False: 4.36k]
  ------------------
  133|  1.72k|        return LONG_MAX;
  134|  4.36k|    if (time < (double)LONG_MIN)
  ------------------
  |  Branch (134:9): [True: 1.37k, False: 2.99k]
  ------------------
  135|  1.37k|        return LONG_MIN;
  136|  2.99k|    return time;
  137|  4.36k|}

readstat_parse_sas7bdat:
 1206|  3.67k|readstat_error_t readstat_parse_sas7bdat(readstat_parser_t *parser, const char *path, void *user_ctx) {
 1207|  3.67k|    int64_t last_examined_page_pass1 = 0;
 1208|  3.67k|    readstat_error_t retval = READSTAT_OK;
 1209|  3.67k|    readstat_io_t *io = parser->io;
 1210|       |
 1211|  3.67k|    sas7bdat_ctx_t  *ctx = calloc(1, sizeof(sas7bdat_ctx_t));
 1212|  3.67k|    sas_header_info_t  *hinfo = calloc(1, sizeof(sas_header_info_t));
 1213|       |
 1214|  3.67k|    ctx->handle = parser->handlers;
 1215|  3.67k|    ctx->input_encoding = parser->input_encoding;
 1216|  3.67k|    ctx->output_encoding = parser->output_encoding;
 1217|  3.67k|    ctx->user_ctx = user_ctx;
 1218|  3.67k|    ctx->io = parser->io;
 1219|  3.67k|    ctx->row_limit = parser->row_limit;
 1220|  3.67k|    if (parser->row_offset > 0)
  ------------------
  |  Branch (1220:9): [True: 0, False: 3.67k]
  ------------------
 1221|      0|        ctx->row_offset = parser->row_offset;
 1222|       |
 1223|  3.67k|    if (io->open(path, io->io_ctx) == -1) {
  ------------------
  |  Branch (1223:9): [True: 0, False: 3.67k]
  ------------------
 1224|      0|        retval = READSTAT_ERROR_OPEN;
 1225|      0|        goto cleanup;
 1226|      0|    }
 1227|       |
 1228|  3.67k|    if ((ctx->file_size = io->seek(0, READSTAT_SEEK_END, io->io_ctx)) == -1) {
  ------------------
  |  Branch (1228:9): [True: 0, False: 3.67k]
  ------------------
 1229|      0|        retval = READSTAT_ERROR_SEEK;
 1230|      0|        if (ctx->handle.error) {
  ------------------
  |  Branch (1230:13): [True: 0, False: 0]
  ------------------
 1231|      0|            snprintf(ctx->error_buf, sizeof(ctx->error_buf), "ReadStat: Failed to seek to end of file");
 1232|      0|            ctx->handle.error(ctx->error_buf, ctx->user_ctx);
 1233|      0|        }
 1234|      0|        goto cleanup;
 1235|      0|    }
 1236|       |
 1237|  3.67k|    if (io->seek(0, READSTAT_SEEK_SET, io->io_ctx) == -1) {
  ------------------
  |  Branch (1237:9): [True: 0, False: 3.67k]
  ------------------
 1238|      0|        retval = READSTAT_ERROR_SEEK;
 1239|      0|        if (ctx->handle.error) {
  ------------------
  |  Branch (1239:13): [True: 0, False: 0]
  ------------------
 1240|      0|            snprintf(ctx->error_buf, sizeof(ctx->error_buf), "ReadStat: Failed to seek to beginning of file");
 1241|      0|            ctx->handle.error(ctx->error_buf, ctx->user_ctx);
 1242|      0|        }
 1243|      0|        goto cleanup;
 1244|      0|    }
 1245|       |
 1246|  3.67k|    if ((retval = sas_read_header(io, hinfo, ctx->handle.error, user_ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1246:9): [True: 517, False: 3.15k]
  ------------------
 1247|    517|        goto cleanup;
 1248|    517|    }
 1249|       |
 1250|  3.15k|    ctx->u64 = hinfo->u64;
 1251|  3.15k|    ctx->little_endian = hinfo->little_endian;
 1252|  3.15k|    ctx->vendor = hinfo->vendor;
 1253|  3.15k|    ctx->bswap = machine_is_little_endian() ^ hinfo->little_endian;
 1254|  3.15k|    ctx->header_size = hinfo->header_size;
 1255|  3.15k|    ctx->page_count = hinfo->page_count;
 1256|  3.15k|    ctx->page_size = hinfo->page_size;
 1257|  3.15k|    ctx->page_header_size = hinfo->page_header_size;
 1258|  3.15k|    ctx->subheader_pointer_size = hinfo->subheader_pointer_size;
 1259|  3.15k|    ctx->subheader_signature_size = ctx->u64 ? 8 : 4;
  ------------------
  |  Branch (1259:37): [True: 1.49k, False: 1.66k]
  ------------------
 1260|  3.15k|    ctx->ctime = hinfo->creation_time;
 1261|  3.15k|    ctx->mtime = hinfo->modification_time;
 1262|  3.15k|    ctx->version = hinfo->major_version;
 1263|  3.15k|    if (ctx->input_encoding == NULL) {
  ------------------
  |  Branch (1263:9): [True: 3.15k, False: 0]
  ------------------
 1264|  3.15k|        ctx->input_encoding = hinfo->encoding;
 1265|  3.15k|    }
 1266|  3.15k|    if ((ctx->page = readstat_malloc(ctx->page_size)) == NULL) {
  ------------------
  |  Branch (1266:9): [True: 0, False: 3.15k]
  ------------------
 1267|      0|        retval = READSTAT_ERROR_MALLOC;
 1268|      0|        goto cleanup;
 1269|      0|    }
 1270|       |
 1271|  3.15k|    if (ctx->input_encoding && ctx->output_encoding && strcmp(ctx->input_encoding, ctx->output_encoding) != 0) {
  ------------------
  |  Branch (1271:9): [True: 3.15k, False: 0]
  |  Branch (1271:32): [True: 3.15k, False: 0]
  |  Branch (1271:56): [True: 2.35k, False: 805]
  ------------------
 1272|  2.35k|        iconv_t converter = iconv_open(ctx->output_encoding, ctx->input_encoding);
 1273|  2.35k|        if (converter == (iconv_t)-1) {
  ------------------
  |  Branch (1273:13): [True: 1, False: 2.35k]
  ------------------
 1274|      1|            retval = READSTAT_ERROR_UNSUPPORTED_CHARSET;
 1275|      1|            goto cleanup;
 1276|      1|        }
 1277|  2.35k|        ctx->converter = converter;
 1278|  2.35k|    }
 1279|       |
 1280|  3.15k|    if ((retval = readstat_convert(ctx->table_name, sizeof(ctx->table_name),
  ------------------
  |  Branch (1280:9): [True: 7, False: 3.14k]
  ------------------
 1281|  3.15k|                hinfo->table_name, sizeof(hinfo->table_name), ctx->converter)) != READSTAT_OK) {
 1282|      7|        goto cleanup;
 1283|      7|    }
 1284|       |
 1285|  3.14k|    if ((retval = sas7bdat_parse_meta_pages_pass1(ctx, &last_examined_page_pass1)) != READSTAT_OK) {
  ------------------
  |  Branch (1285:9): [True: 223, False: 2.92k]
  ------------------
 1286|    223|        goto cleanup;
 1287|    223|    }
 1288|       |
 1289|  2.92k|    if ((retval = sas7bdat_parse_amd_pages_pass1(last_examined_page_pass1, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1289:9): [True: 1.07k, False: 1.85k]
  ------------------
 1290|  1.07k|        goto cleanup;
 1291|  1.07k|    }
 1292|       |
 1293|  1.85k|    if (io->seek(ctx->header_size, READSTAT_SEEK_SET, io->io_ctx) == -1) {
  ------------------
  |  Branch (1293:9): [True: 0, False: 1.85k]
  ------------------
 1294|      0|        retval = READSTAT_ERROR_SEEK;
 1295|      0|        if (ctx->handle.error) {
  ------------------
  |  Branch (1295:13): [True: 0, False: 0]
  ------------------
 1296|      0|            snprintf(ctx->error_buf, sizeof(ctx->error_buf), "ReadStat: Failed to seek to position %" PRId64, 
 1297|      0|                    ctx->header_size);
 1298|      0|            ctx->handle.error(ctx->error_buf, ctx->user_ctx);
 1299|      0|        }
 1300|      0|        goto cleanup;
 1301|      0|    }
 1302|       |
 1303|  1.85k|    if ((retval = sas7bdat_parse_all_pages_pass2(ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1303:9): [True: 1.49k, False: 355]
  ------------------
 1304|  1.49k|        goto cleanup;
 1305|  1.49k|    }
 1306|       |    
 1307|    355|    if ((retval = sas7bdat_submit_columns_if_needed(ctx, 0)) != READSTAT_OK) {
  ------------------
  |  Branch (1307:9): [True: 88, False: 267]
  ------------------
 1308|     88|        goto cleanup;
 1309|     88|    }
 1310|       |
 1311|    267|    if (ctx->handle.value && ctx->parsed_row_count != ctx->row_limit) {
  ------------------
  |  Branch (1311:9): [True: 267, False: 0]
  |  Branch (1311:30): [True: 108, False: 159]
  ------------------
 1312|    108|        retval = READSTAT_ERROR_ROW_COUNT_MISMATCH;
 1313|    108|        if (ctx->handle.error) {
  ------------------
  |  Branch (1313:13): [True: 0, False: 108]
  ------------------
 1314|      0|            snprintf(ctx->error_buf, sizeof(ctx->error_buf), "ReadStat: Expected %d rows in file, found %d",
 1315|      0|                    ctx->row_limit, ctx->parsed_row_count);
 1316|      0|            ctx->handle.error(ctx->error_buf, ctx->user_ctx);
 1317|      0|        }
 1318|    108|        goto cleanup;
 1319|    108|    }
 1320|       |
 1321|    159|    if ((retval = sas7bdat_update_progress(ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1321:9): [True: 0, False: 159]
  ------------------
 1322|      0|        goto cleanup;
 1323|      0|    }
 1324|       |
 1325|  3.67k|cleanup:
 1326|  3.67k|    io->close(io->io_ctx);
 1327|       |
 1328|  3.67k|    if (retval == READSTAT_ERROR_OPEN ||
  ------------------
  |  Branch (1328:9): [True: 0, False: 3.67k]
  ------------------
 1329|  3.67k|            retval == READSTAT_ERROR_READ ||
  ------------------
  |  Branch (1329:13): [True: 432, False: 3.24k]
  ------------------
 1330|  3.24k|            retval == READSTAT_ERROR_SEEK) {
  ------------------
  |  Branch (1330:13): [True: 332, False: 2.91k]
  ------------------
 1331|    764|        if (ctx->handle.error) {
  ------------------
  |  Branch (1331:13): [True: 0, False: 764]
  ------------------
 1332|      0|            snprintf(ctx->error_buf, sizeof(ctx->error_buf), "ReadStat: %s (retval = %d): %s (errno = %d)", 
 1333|      0|                    readstat_error_message(retval), retval, strerror(errno), errno);
 1334|      0|            ctx->handle.error(ctx->error_buf, user_ctx);
 1335|      0|        }
 1336|    764|    }
 1337|       |
 1338|  3.67k|    if (ctx)
  ------------------
  |  Branch (1338:9): [True: 3.67k, False: 0]
  ------------------
 1339|  3.67k|        sas7bdat_ctx_free(ctx);
 1340|  3.67k|    if (hinfo)
  ------------------
  |  Branch (1340:9): [True: 3.67k, False: 0]
  ------------------
 1341|  3.67k|        free(hinfo);
 1342|       |
 1343|  3.67k|    return retval;
 1344|    159|}
readstat_sas7bdat_read.c:sas7bdat_parse_meta_pages_pass1:
 1047|  3.14k|static readstat_error_t sas7bdat_parse_meta_pages_pass1(sas7bdat_ctx_t *ctx, int64_t *outLastExaminedPage) {
 1048|  3.14k|    readstat_error_t retval = READSTAT_OK;
 1049|  3.14k|    readstat_io_t *io = ctx->io;
 1050|  3.14k|    int64_t i;
 1051|       |
 1052|       |    /* look for META and MIX pages at beginning... */
 1053|  8.17k|    for (i=0; i<ctx->page_count; i++) {
  ------------------
  |  Branch (1053:15): [True: 5.79k, False: 2.38k]
  ------------------
 1054|  5.79k|        if (io->seek(ctx->header_size + i*ctx->page_size, READSTAT_SEEK_SET, io->io_ctx) == -1) {
  ------------------
  |  Branch (1054:13): [True: 7, False: 5.78k]
  ------------------
 1055|      7|            retval = READSTAT_ERROR_SEEK;
 1056|      7|            if (ctx->handle.error) {
  ------------------
  |  Branch (1056:17): [True: 0, False: 7]
  ------------------
 1057|      0|                snprintf(ctx->error_buf, sizeof(ctx->error_buf), "ReadStat: Failed to seek to position %" PRId64 
 1058|      0|                        " (= %" PRId64 " + %" PRId64 "*%" PRId64 ")",
 1059|      0|                        ctx->header_size + i*ctx->page_size, ctx->header_size, i, ctx->page_size);
 1060|      0|                ctx->handle.error(ctx->error_buf, ctx->user_ctx);
 1061|      0|            }
 1062|      7|            goto cleanup;
 1063|      7|        }
 1064|       |
 1065|  5.78k|        readstat_off_t off = 0;
 1066|  5.78k|        if (ctx->u64)
  ------------------
  |  Branch (1066:13): [True: 3.81k, False: 1.97k]
  ------------------
 1067|  3.81k|            off = 16;
 1068|       |
 1069|  5.78k|        size_t head_len = off + 16 + 2;
 1070|  5.78k|        size_t tail_len = ctx->page_size - head_len;
 1071|       |
 1072|  5.78k|        if (io->read(ctx->page, head_len, io->io_ctx) < head_len) {
  ------------------
  |  Branch (1072:13): [True: 139, False: 5.65k]
  ------------------
 1073|    139|            retval = READSTAT_ERROR_READ;
 1074|    139|            goto cleanup;
 1075|    139|        }
 1076|       |
 1077|  5.65k|        uint16_t page_type = sas_read2(&ctx->page[off+16], ctx->bswap);
 1078|       |
 1079|  5.65k|        if ((page_type & SAS_PAGE_TYPE_MASK) == SAS_PAGE_TYPE_DATA)
  ------------------
  |  |  112|  5.65k|#define SAS_PAGE_TYPE_MASK   0x0F00
  ------------------
                      if ((page_type & SAS_PAGE_TYPE_MASK) == SAS_PAGE_TYPE_DATA)
  ------------------
  |  |  109|  5.65k|#define SAS_PAGE_TYPE_DATA   0x0100
  ------------------
  |  Branch (1079:13): [True: 546, False: 5.10k]
  ------------------
 1080|    546|            break;
 1081|  5.10k|        if ((page_type & SAS_PAGE_TYPE_COMP))
  ------------------
  |  |  115|  5.10k|#define SAS_PAGE_TYPE_COMP   0x9000
  ------------------
  |  Branch (1081:13): [True: 1.15k, False: 3.95k]
  ------------------
 1082|  1.15k|            continue;
 1083|       |
 1084|  3.95k|        if (io->read(ctx->page + head_len, tail_len, io->io_ctx) < tail_len) {
  ------------------
  |  Branch (1084:13): [True: 28, False: 3.92k]
  ------------------
 1085|     28|            retval = READSTAT_ERROR_READ;
 1086|     28|            goto cleanup;
 1087|     28|        }
 1088|       |
 1089|  3.92k|        if ((retval = sas7bdat_parse_page_pass1(ctx->page, ctx->page_size, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1089:13): [True: 49, False: 3.87k]
  ------------------
 1090|     49|            if (ctx->handle.error && retval != READSTAT_ERROR_USER_ABORT) {
  ------------------
  |  Branch (1090:17): [True: 0, False: 49]
  |  Branch (1090:38): [True: 0, False: 0]
  ------------------
 1091|      0|                int64_t pos = io->seek(0, READSTAT_SEEK_CUR, io->io_ctx);
 1092|      0|                snprintf(ctx->error_buf, sizeof(ctx->error_buf), 
 1093|      0|                        "ReadStat: Error parsing page %" PRId64 ", bytes %" PRId64 "-%" PRId64, 
 1094|      0|                        i, pos - ctx->page_size, pos-1);
 1095|      0|                ctx->handle.error(ctx->error_buf, ctx->user_ctx);
 1096|      0|            }
 1097|     49|            goto cleanup;
 1098|     49|        }
 1099|  3.92k|    }
 1100|       |
 1101|  3.14k|cleanup:
 1102|  3.14k|    if (outLastExaminedPage)
  ------------------
  |  Branch (1102:9): [True: 3.14k, False: 0]
  ------------------
 1103|  3.14k|        *outLastExaminedPage = i;
 1104|       |
 1105|  3.14k|    return retval;
 1106|  3.14k|}
readstat_sas7bdat_read.c:sas7bdat_parse_page_pass1:
  903|  6.72k|static readstat_error_t sas7bdat_parse_page_pass1(const char *page, size_t page_size, sas7bdat_ctx_t *ctx) {
  904|  6.72k|    readstat_error_t retval = READSTAT_OK;
  905|       |
  906|  6.72k|    uint16_t subheader_count = sas_read2(&page[ctx->page_header_size-4], ctx->bswap);
  907|       |
  908|  6.72k|    int i;
  909|  6.72k|    const char *shp = &page[ctx->page_header_size];
  910|  6.72k|    int lshp = ctx->subheader_pointer_size;
  911|       |
  912|  6.72k|    if (ctx->page_header_size + subheader_count*lshp > page_size) {
  ------------------
  |  Branch (912:9): [True: 39, False: 6.68k]
  ------------------
  913|     39|        retval = READSTAT_ERROR_PARSE;
  914|     39|        goto cleanup;
  915|     39|    }
  916|       |
  917|  70.3k|    for (i=0; i<subheader_count; i++) {
  ------------------
  |  Branch (917:15): [True: 64.4k, False: 5.82k]
  ------------------
  918|  64.4k|        subheader_pointer_t shp_info = { 0 };
  919|  64.4k|        if ((retval = sas7bdat_parse_subheader_pointer(shp, page + page_size - shp, &shp_info, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (919:13): [True: 0, False: 64.4k]
  ------------------
  920|      0|            goto cleanup;
  921|      0|        }
  922|  64.4k|        if (shp_info.len > 0 && shp_info.compression != SAS_COMPRESSION_TRUNC) {
  ------------------
  |  |  124|  40.0k|#define SAS_COMPRESSION_TRUNC  0x01
  ------------------
  |  Branch (922:13): [True: 40.0k, False: 24.4k]
  |  Branch (922:33): [True: 34.0k, False: 5.95k]
  ------------------
  923|  34.0k|            if ((retval = sas7bdat_validate_subheader_pointer(&shp_info, page_size, subheader_count, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (923:17): [True: 781, False: 33.2k]
  ------------------
  924|    781|                goto cleanup;
  925|    781|            }
  926|  33.2k|            if (shp_info.compression == SAS_COMPRESSION_NONE) {
  ------------------
  |  |  123|  33.2k|#define SAS_COMPRESSION_NONE   0x00
  ------------------
  |  Branch (926:17): [True: 30.4k, False: 2.87k]
  ------------------
  927|  30.4k|                sas_subheader_type_t subheader_type = sas7bdat_parse_subheader_type(page + shp_info.offset, ctx);
  928|  30.4k|                if (subheader_type == SAS_SUBHEADER_TYPE_COLUMN_TEXT) {
  ------------------
  |  Branch (928:21): [True: 2.88k, False: 27.5k]
  ------------------
  929|  2.88k|                    if ((retval = sas7bdat_parse_subheader(subheader_type, page + shp_info.offset, shp_info.len, ctx))
  ------------------
  |  Branch (929:25): [True: 61, False: 2.82k]
  ------------------
  930|  2.88k|                            != READSTAT_OK) {
  931|     61|                        goto cleanup;
  932|     61|                    }
  933|  2.88k|                }
  934|  30.4k|            } else if (shp_info.compression == SAS_COMPRESSION_ROW) {
  ------------------
  |  |  125|  2.87k|#define SAS_COMPRESSION_ROW    0x04
  ------------------
  |  Branch (934:24): [True: 2.86k, False: 16]
  ------------------
  935|       |                /* void */
  936|  2.86k|            } else {
  937|     16|                retval = READSTAT_ERROR_UNSUPPORTED_COMPRESSION;
  938|     16|                goto cleanup;
  939|     16|            }
  940|  33.2k|        }
  941|       |
  942|  63.6k|        shp += lshp;
  943|  63.6k|    }
  944|       |
  945|  6.72k|cleanup:
  946|       |
  947|  6.72k|    return retval;
  948|  6.68k|}
readstat_sas7bdat_read.c:sas7bdat_parse_subheader_pointer:
  857|   100k|        subheader_pointer_t *info, sas7bdat_ctx_t *ctx) {
  858|   100k|    readstat_error_t retval = READSTAT_OK;
  859|   100k|    if (ctx->u64) {
  ------------------
  |  Branch (859:9): [True: 16.1k, False: 84.4k]
  ------------------
  860|  16.1k|        if (shp_size <= 17) {
  ------------------
  |  Branch (860:13): [True: 0, False: 16.1k]
  ------------------
  861|      0|            retval = READSTAT_ERROR_PARSE;
  862|      0|            goto cleanup;
  863|      0|        }
  864|  16.1k|        info->offset = sas_read8(&shp[0], ctx->bswap);
  865|  16.1k|        info->len = sas_read8(&shp[8], ctx->bswap);
  866|  16.1k|        info->compression = shp[16];
  867|  16.1k|        info->is_compressed_data = shp[17];
  868|  84.4k|    } else {
  869|  84.4k|        if (shp_size <= 9) {
  ------------------
  |  Branch (869:13): [True: 0, False: 84.4k]
  ------------------
  870|      0|            retval = READSTAT_ERROR_PARSE;
  871|      0|            goto cleanup;
  872|      0|        }
  873|  84.4k|        info->offset = sas_read4(&shp[0], ctx->bswap);
  874|  84.4k|        info->len = sas_read4(&shp[4], ctx->bswap);
  875|  84.4k|        info->compression = shp[8];
  876|  84.4k|        info->is_compressed_data = shp[9];
  877|  84.4k|    }
  878|   100k|cleanup:
  879|   100k|    return retval;
  880|   100k|}
readstat_sas7bdat_read.c:sas7bdat_validate_subheader_pointer:
  883|  51.6k|        uint16_t subheader_count, sas7bdat_ctx_t *ctx) {
  884|  51.6k|    if (shp_info->offset > page_size)
  ------------------
  |  Branch (884:9): [True: 548, False: 51.1k]
  ------------------
  885|    548|        return READSTAT_ERROR_PARSE;
  886|  51.1k|    if (shp_info->len > page_size)
  ------------------
  |  Branch (886:9): [True: 340, False: 50.7k]
  ------------------
  887|    340|        return READSTAT_ERROR_PARSE;
  888|  50.7k|    if (shp_info->offset + shp_info->len > page_size)
  ------------------
  |  Branch (888:9): [True: 58, False: 50.7k]
  ------------------
  889|     58|        return READSTAT_ERROR_PARSE;
  890|  50.7k|    if (shp_info->offset < ctx->page_header_size + subheader_count*ctx->subheader_pointer_size)
  ------------------
  |  Branch (890:9): [True: 19, False: 50.6k]
  ------------------
  891|     19|        return READSTAT_ERROR_PARSE;
  892|  50.6k|    if (shp_info->compression == SAS_COMPRESSION_NONE) {
  ------------------
  |  |  123|  50.6k|#define SAS_COMPRESSION_NONE   0x00
  ------------------
  |  Branch (892:9): [True: 46.3k, False: 4.31k]
  ------------------
  893|  46.3k|        if (shp_info->len < ctx->subheader_signature_size)
  ------------------
  |  Branch (893:13): [True: 7, False: 46.3k]
  ------------------
  894|      7|            return READSTAT_ERROR_PARSE;
  895|  46.3k|        if (shp_info->offset + ctx->subheader_signature_size > page_size)
  ------------------
  |  Branch (895:13): [True: 0, False: 46.3k]
  ------------------
  896|      0|            return READSTAT_ERROR_PARSE;
  897|  46.3k|    }
  898|       |    
  899|  50.6k|    return READSTAT_OK;
  900|  50.6k|}
readstat_sas7bdat_read.c:sas7bdat_parse_subheader_type:
  837|  46.3k|static sas_subheader_type_t sas7bdat_parse_subheader_type(const char* subheader, sas7bdat_ctx_t* ctx) {
  838|  46.3k|    if (!ctx->u64) {
  ------------------
  |  Branch (838:9): [True: 37.1k, False: 9.16k]
  ------------------
  839|  37.1k|        uint32_t signature_32 = sas_read4(subheader, ctx->bswap);
  840|  37.1k|        return sas7bdat_parse_subheader_type_32(signature_32);
  841|  37.1k|    }
  842|       |
  843|  9.16k|    uint64_t signature = sas_read8(subheader, ctx->bswap);
  844|  9.16k|    if (signature == SAS_SUBHEADER_SIGNATURE_ROW_SIZE) {
  ------------------
  |  |   92|  9.16k|#define SAS_SUBHEADER_SIGNATURE_ROW_SIZE       0xF7F7F7F7
  ------------------
  |  Branch (844:9): [True: 2.01k, False: 7.15k]
  ------------------
  845|  2.01k|        return SAS_SUBHEADER_TYPE_ROW_SIZE;
  846|  7.15k|    } else if (signature == SAS_SUBHEADER_SIGNATURE_COLUMN_SIZE) {
  ------------------
  |  |   93|  7.15k|#define SAS_SUBHEADER_SIGNATURE_COLUMN_SIZE    0xF6F6F6F6
  ------------------
  |  Branch (846:16): [True: 386, False: 6.76k]
  ------------------
  847|    386|        return SAS_SUBHEADER_TYPE_COLUMN_SIZE;
  848|  6.76k|    } else if ((signature & SAS_SUBHEADER_SIGNATURE_64BIT_MASK) != SAS_SUBHEADER_SIGNATURE_64BIT_MASK) {
  ------------------
  |  |  105|  6.76k|#define SAS_SUBHEADER_SIGNATURE_64BIT_MASK     0xFFFFFFFF00000000
  ------------------
                  } else if ((signature & SAS_SUBHEADER_SIGNATURE_64BIT_MASK) != SAS_SUBHEADER_SIGNATURE_64BIT_MASK) {
  ------------------
  |  |  105|  6.76k|#define SAS_SUBHEADER_SIGNATURE_64BIT_MASK     0xFFFFFFFF00000000
  ------------------
  |  Branch (848:16): [True: 1.97k, False: 4.78k]
  ------------------
  849|  1.97k|        return SAS_SUBHEADER_TYPE_DATA;
  850|  1.97k|    }
  851|       |
  852|  4.78k|    uint32_t lower_bytes = (uint32_t)(signature & SAS_SUBHEADER_SIGNATURE_32BIT_MASK);
  ------------------
  |  |  106|  4.78k|#define SAS_SUBHEADER_SIGNATURE_32BIT_MASK     0x00000000FFFFFFFF
  ------------------
  853|  4.78k|    return sas7bdat_parse_subheader_type_32(lower_bytes);
  854|  9.16k|}
readstat_sas7bdat_read.c:sas7bdat_parse_subheader_type_32:
  811|  41.9k|static sas_subheader_type_t sas7bdat_parse_subheader_type_32(uint32_t signature) {
  812|  41.9k|    switch (signature) {
  813|  6.66k|        case SAS_SUBHEADER_SIGNATURE_ROW_SIZE:
  ------------------
  |  |   92|  6.66k|#define SAS_SUBHEADER_SIGNATURE_ROW_SIZE       0xF7F7F7F7
  ------------------
  |  Branch (813:9): [True: 6.66k, False: 35.3k]
  ------------------
  814|  6.66k|            return SAS_SUBHEADER_TYPE_ROW_SIZE;
  815|  3.26k|        case SAS_SUBHEADER_SIGNATURE_COLUMN_SIZE:
  ------------------
  |  |   93|  3.26k|#define SAS_SUBHEADER_SIGNATURE_COLUMN_SIZE    0xF6F6F6F6
  ------------------
  |  Branch (815:9): [True: 3.26k, False: 38.7k]
  ------------------
  816|  3.26k|            return SAS_SUBHEADER_TYPE_COLUMN_SIZE;
  817|  2.89k|        case SAS_SUBHEADER_SIGNATURE_COUNTS:
  ------------------
  |  |   94|  2.89k|#define SAS_SUBHEADER_SIGNATURE_COUNTS         0xFFFFFC00
  ------------------
  |  Branch (817:9): [True: 2.89k, False: 39.0k]
  ------------------
  818|  2.89k|            return SAS_SUBHEADER_TYPE_COUNTS;
  819|  7.99k|        case SAS_SUBHEADER_SIGNATURE_COLUMN_FORMAT:
  ------------------
  |  |   95|  7.99k|#define SAS_SUBHEADER_SIGNATURE_COLUMN_FORMAT  0xFFFFFBFE
  ------------------
  |  Branch (819:9): [True: 7.99k, False: 33.9k]
  ------------------
  820|  7.99k|            return SAS_SUBHEADER_TYPE_COLUMN_FORMAT;
  821|  5.31k|        case SAS_SUBHEADER_SIGNATURE_COLUMN_ATTRS:
  ------------------
  |  |  100|  5.31k|#define SAS_SUBHEADER_SIGNATURE_COLUMN_ATTRS   0xFFFFFFFC
  ------------------
  |  Branch (821:9): [True: 5.31k, False: 36.6k]
  ------------------
  822|  5.31k|            return SAS_SUBHEADER_TYPE_COLUMN_ATTRS;
  823|  4.34k|        case SAS_SUBHEADER_SIGNATURE_COLUMN_TEXT:
  ------------------
  |  |  101|  4.34k|#define SAS_SUBHEADER_SIGNATURE_COLUMN_TEXT    0xFFFFFFFD
  ------------------
  |  Branch (823:9): [True: 4.34k, False: 37.6k]
  ------------------
  824|  4.34k|            return SAS_SUBHEADER_TYPE_COLUMN_TEXT;
  825|  1.77k|        case SAS_SUBHEADER_SIGNATURE_COLUMN_LIST:
  ------------------
  |  |  102|  1.77k|#define SAS_SUBHEADER_SIGNATURE_COLUMN_LIST    0xFFFFFFFE
  ------------------
  |  Branch (825:9): [True: 1.77k, False: 40.2k]
  ------------------
  826|  1.77k|            return SAS_SUBHEADER_TYPE_COLUMN_LIST;
  827|  3.50k|        case SAS_SUBHEADER_SIGNATURE_COLUMN_NAME:
  ------------------
  |  |  103|  3.50k|#define SAS_SUBHEADER_SIGNATURE_COLUMN_NAME    0xFFFFFFFF
  ------------------
  |  Branch (827:9): [True: 3.50k, False: 38.4k]
  ------------------
  828|  3.50k|            return SAS_SUBHEADER_TYPE_COLUMN_NAME;
  829|  6.23k|        default:
  ------------------
  |  Branch (829:9): [True: 6.23k, False: 35.7k]
  ------------------
  830|  6.23k|            if ((signature & SAS_SUBHEADER_SIGNATURE_COLUMN_MASK) == SAS_SUBHEADER_SIGNATURE_COLUMN_MASK) {
  ------------------
  |  |   97|  6.23k|#define SAS_SUBHEADER_SIGNATURE_COLUMN_MASK    0xFFFFFFF8
  ------------------
                          if ((signature & SAS_SUBHEADER_SIGNATURE_COLUMN_MASK) == SAS_SUBHEADER_SIGNATURE_COLUMN_MASK) {
  ------------------
  |  |   97|  6.23k|#define SAS_SUBHEADER_SIGNATURE_COLUMN_MASK    0xFFFFFFF8
  ------------------
  |  Branch (830:17): [True: 1.67k, False: 4.56k]
  ------------------
  831|  1.67k|                return SAS_SUBHEADER_TYPE_UNKNOWN;
  832|  1.67k|            }
  833|  4.56k|            return SAS_SUBHEADER_TYPE_DATA;
  834|  41.9k|    }
  835|  41.9k|}
readstat_sas7bdat_read.c:sas7bdat_parse_subheader:
  633|  16.6k|        size_t len, sas7bdat_ctx_t *ctx) {
  634|  16.6k|    readstat_error_t retval = READSTAT_OK;
  635|       |
  636|  16.6k|    if (len < 2 + ctx->subheader_signature_size) {
  ------------------
  |  Branch (636:9): [True: 7, False: 16.6k]
  ------------------
  637|      7|        retval = READSTAT_ERROR_PARSE;
  638|      7|        goto cleanup;
  639|      7|    }
  640|  16.6k|    if (subheader_type == SAS_SUBHEADER_TYPE_ROW_SIZE) {
  ------------------
  |  Branch (640:9): [True: 3.30k, False: 13.3k]
  ------------------
  641|  3.30k|        retval = sas7bdat_parse_row_size_subheader(subheader, len, ctx);
  642|  13.3k|    } else if (subheader_type == SAS_SUBHEADER_TYPE_COLUMN_SIZE) {
  ------------------
  |  Branch (642:16): [True: 1.23k, False: 12.0k]
  ------------------
  643|  1.23k|        retval = sas7bdat_parse_column_size_subheader(subheader, len, ctx);
  644|  12.0k|    } else if (subheader_type == SAS_SUBHEADER_TYPE_COUNTS) {
  ------------------
  |  Branch (644:16): [True: 1.18k, False: 10.9k]
  ------------------
  645|       |        /* void */
  646|  10.9k|    } else if (subheader_type == SAS_SUBHEADER_TYPE_COLUMN_TEXT) {
  ------------------
  |  Branch (646:16): [True: 2.88k, False: 8.02k]
  ------------------
  647|  2.88k|        retval = sas7bdat_parse_column_text_subheader(subheader, len, ctx);
  648|  8.02k|    } else if (subheader_type == SAS_SUBHEADER_TYPE_COLUMN_NAME) {
  ------------------
  |  Branch (648:16): [True: 1.17k, False: 6.84k]
  ------------------
  649|  1.17k|        retval = sas7bdat_parse_column_name_subheader(subheader, len, ctx);
  650|  6.84k|    } else if (subheader_type == SAS_SUBHEADER_TYPE_COLUMN_ATTRS) {
  ------------------
  |  Branch (650:16): [True: 2.01k, False: 4.83k]
  ------------------
  651|  2.01k|        retval = sas7bdat_parse_column_attributes_subheader(subheader, len, ctx);
  652|  4.83k|    } else if (subheader_type == SAS_SUBHEADER_TYPE_COLUMN_FORMAT) {
  ------------------
  |  Branch (652:16): [True: 3.50k, False: 1.32k]
  ------------------
  653|  3.50k|        retval = sas7bdat_parse_column_format_subheader(subheader, len, ctx);
  654|  3.50k|    } else if (subheader_type == SAS_SUBHEADER_TYPE_COLUMN_LIST) {
  ------------------
  |  Branch (654:16): [True: 604, False: 721]
  ------------------
  655|       |        /* void */
  656|    721|    } else if (subheader_type == SAS_SUBHEADER_TYPE_UNKNOWN) {
  ------------------
  |  Branch (656:16): [True: 669, False: 52]
  ------------------
  657|       |        /* void */
  658|    669|    } else {
  659|     52|        retval = READSTAT_ERROR_PARSE;
  660|     52|    }
  661|       |
  662|  16.6k|cleanup:
  663|       |
  664|  16.6k|    return retval;
  665|  16.6k|}
readstat_sas7bdat_read.c:sas7bdat_parse_row_size_subheader:
  232|  3.30k|static readstat_error_t sas7bdat_parse_row_size_subheader(const char *subheader, size_t len, sas7bdat_ctx_t *ctx) {
  233|  3.30k|    readstat_error_t retval = READSTAT_OK;
  234|  3.30k|    uint64_t total_row_count;
  235|  3.30k|    uint64_t row_length, page_row_count;
  236|       |
  237|  3.30k|    if (len < (ctx->u64 ? 250: 190)) {
  ------------------
  |  Branch (237:9): [True: 10, False: 3.29k]
  |  Branch (237:16): [True: 886, False: 2.41k]
  ------------------
  238|     10|        retval = READSTAT_ERROR_PARSE;
  239|     10|        goto cleanup;
  240|     10|    }
  241|       |
  242|  3.29k|    if (ctx->u64) {
  ------------------
  |  Branch (242:9): [True: 885, False: 2.40k]
  ------------------
  243|    885|        row_length = sas_read8(&subheader[40], ctx->bswap);
  244|    885|        total_row_count = sas_read8(&subheader[48], ctx->bswap);
  245|    885|        page_row_count = sas_read8(&subheader[120], ctx->bswap);
  246|  2.40k|    } else {
  247|  2.40k|        row_length = sas_read4(&subheader[20], ctx->bswap);
  248|  2.40k|        total_row_count = sas_read4(&subheader[24], ctx->bswap);
  249|  2.40k|        page_row_count = sas_read4(&subheader[60], ctx->bswap);
  250|  2.40k|    }
  251|       |
  252|  3.29k|    sas_text_ref_t file_label_ref = sas7bdat_parse_text_ref(&subheader[len-130], ctx);
  253|  3.29k|    if (file_label_ref.length) {
  ------------------
  |  Branch (253:9): [True: 858, False: 2.43k]
  ------------------
  254|    858|        if ((retval = sas7bdat_copy_text_ref(ctx->file_label, sizeof(ctx->file_label),
  ------------------
  |  Branch (254:13): [True: 38, False: 820]
  ------------------
  255|    858|                        file_label_ref, ctx)) != READSTAT_OK) {
  256|     38|            goto cleanup;
  257|     38|        }
  258|    858|    }
  259|       |
  260|  3.25k|    sas_text_ref_t compression_ref = sas7bdat_parse_text_ref(&subheader[len-118], ctx);
  261|  3.25k|    if (compression_ref.length) {
  ------------------
  |  Branch (261:9): [True: 1.23k, False: 2.01k]
  ------------------
  262|  1.23k|        char compression[9];
  263|  1.23k|        if ((retval = sas7bdat_copy_text_ref(compression, sizeof(compression),
  ------------------
  |  Branch (263:13): [True: 35, False: 1.20k]
  ------------------
  264|  1.23k|                        compression_ref, ctx)) != READSTAT_OK) {
  265|     35|            goto cleanup;
  266|     35|        }
  267|  1.20k|        ctx->rdc_compression = (memcmp(compression, SAS_COMPRESSION_SIGNATURE_RDC, 8) == 0);
  ------------------
  |  |  128|  1.20k|#define SAS_COMPRESSION_SIGNATURE_RDC  "SASYZCR2"
  ------------------
  268|  1.20k|    }
  269|       |
  270|  3.21k|    ctx->row_length = row_length;
  271|  3.21k|    ctx->row = readstat_realloc(ctx->row, ctx->row_length);
  272|  3.21k|    if (ctx->row == NULL) {
  ------------------
  |  Branch (272:9): [True: 10, False: 3.20k]
  ------------------
  273|     10|        retval = READSTAT_ERROR_MALLOC;
  274|     10|        goto cleanup;
  275|     10|    }
  276|       |
  277|  3.20k|    ctx->page_row_count = page_row_count;
  278|  3.20k|    uint64_t total_row_count_after_skipping = total_row_count;
  279|  3.20k|    if (total_row_count > ctx->row_offset) {
  ------------------
  |  Branch (279:9): [True: 2.95k, False: 250]
  ------------------
  280|  2.95k|        total_row_count_after_skipping -= ctx->row_offset;
  281|  2.95k|    } else {
  282|    250|        total_row_count_after_skipping = 0;
  283|    250|        ctx->row_offset = total_row_count;
  284|    250|    }
  285|  3.20k|    if (ctx->row_limit == 0 || total_row_count_after_skipping < ctx->row_limit)
  ------------------
  |  Branch (285:9): [True: 1.24k, False: 1.96k]
  |  Branch (285:32): [True: 143, False: 1.82k]
  ------------------
  286|  1.38k|        ctx->row_limit = total_row_count_after_skipping;
  287|       |
  288|  3.30k|cleanup:
  289|  3.30k|    return retval;
  290|  3.20k|}
readstat_sas7bdat_read.c:sas7bdat_parse_text_ref:
  133|  52.5k|static sas_text_ref_t sas7bdat_parse_text_ref(const char *data, sas7bdat_ctx_t *ctx) {
  134|  52.5k|    sas_text_ref_t  ref;
  135|       |
  136|  52.5k|    ref.index = sas_read2(&data[0], ctx->bswap);
  137|  52.5k|    ref.offset = sas_read2(&data[2], ctx->bswap);
  138|  52.5k|    ref.length = sas_read2(&data[4], ctx->bswap);
  139|       |
  140|  52.5k|    return ref;
  141|  52.5k|}
readstat_sas7bdat_read.c:sas7bdat_copy_text_ref:
  143|  9.45M|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) {
  144|  9.45M|    if (text_ref.index >= ctx->text_blob_count)
  ------------------
  |  Branch (144:9): [True: 134, False: 9.45M]
  ------------------
  145|    134|        return READSTAT_ERROR_PARSE;
  146|       |    
  147|  9.45M|    if (text_ref.length == 0) {
  ------------------
  |  Branch (147:9): [True: 9.45M, False: 3.69k]
  ------------------
  148|  9.45M|        out_buffer[0] = '\0';
  149|  9.45M|        return READSTAT_OK;
  150|  9.45M|    }
  151|       |
  152|  3.69k|    char *blob = ctx->text_blobs[text_ref.index];
  153|       |
  154|  3.69k|    if (text_ref.offset + text_ref.length > ctx->text_blob_lengths[text_ref.index])
  ------------------
  |  Branch (154:9): [True: 82, False: 3.61k]
  ------------------
  155|     82|        return READSTAT_ERROR_PARSE;
  156|       |
  157|  3.61k|    return readstat_convert(out_buffer, out_buffer_len, &blob[text_ref.offset], text_ref.length,
  158|  3.61k|            ctx->converter);
  159|  3.69k|}
readstat_sas7bdat_read.c:sas7bdat_parse_column_size_subheader:
  204|  1.23k|static readstat_error_t sas7bdat_parse_column_size_subheader(const char *subheader, size_t len, sas7bdat_ctx_t *ctx) {
  205|  1.23k|    uint64_t col_count;
  206|  1.23k|    readstat_error_t retval = READSTAT_OK;
  207|       |
  208|  1.23k|    if (ctx->column_count || ctx->did_submit_columns) {
  ------------------
  |  Branch (208:9): [True: 20, False: 1.21k]
  |  Branch (208:30): [True: 2, False: 1.21k]
  ------------------
  209|     22|        retval = READSTAT_ERROR_PARSE;
  210|     22|        goto cleanup;
  211|     22|    }
  212|       |
  213|  1.21k|    if (len < (ctx->u64 ? 16 : 8)) {
  ------------------
  |  Branch (213:9): [True: 2, False: 1.21k]
  |  Branch (213:16): [True: 346, False: 869]
  ------------------
  214|      2|        retval = READSTAT_ERROR_PARSE;
  215|      2|        goto cleanup;
  216|      2|    }
  217|       |
  218|  1.21k|    if (ctx->u64) {
  ------------------
  |  Branch (218:9): [True: 346, False: 867]
  ------------------
  219|    346|        col_count = sas_read8(&subheader[8], ctx->bswap);
  220|    867|    } else {
  221|    867|        col_count = sas_read4(&subheader[4], ctx->bswap);
  222|    867|    }
  223|       |
  224|  1.21k|    ctx->column_count = col_count;
  225|       |
  226|  1.21k|    retval = sas7bdat_realloc_col_info(ctx, ctx->column_count);
  227|       |
  228|  1.23k|cleanup:
  229|  1.23k|    return retval;
  230|  1.21k|}
readstat_sas7bdat_read.c:sas7bdat_realloc_col_info:
  191|  7.80k|static readstat_error_t sas7bdat_realloc_col_info(sas7bdat_ctx_t *ctx, size_t count) {
  192|  7.80k|    if (ctx->col_info_count < count) {
  ------------------
  |  Branch (192:9): [True: 3.46k, False: 4.33k]
  ------------------
  193|  3.46k|        size_t old_count = ctx->col_info_count;
  194|  3.46k|        ctx->col_info_count = count;
  195|  3.46k|        ctx->col_info = readstat_realloc(ctx->col_info, ctx->col_info_count * sizeof(col_info_t));
  196|  3.46k|        if (ctx->col_info == NULL) {
  ------------------
  |  Branch (196:13): [True: 77, False: 3.39k]
  ------------------
  197|     77|            return READSTAT_ERROR_MALLOC;
  198|     77|        }
  199|  3.39k|        memset(ctx->col_info + old_count, 0, (count - old_count) * sizeof(col_info_t));
  200|  3.39k|    }
  201|  7.72k|    return READSTAT_OK;
  202|  7.80k|}
readstat_sas7bdat_read.c:sas7bdat_parse_column_text_subheader:
  161|  2.88k|static readstat_error_t sas7bdat_parse_column_text_subheader(const char *subheader, size_t len, sas7bdat_ctx_t *ctx) {
  162|  2.88k|    readstat_error_t retval = READSTAT_OK;
  163|  2.88k|    size_t signature_len = ctx->subheader_signature_size;
  164|  2.88k|    uint16_t remainder = sas_read2(&subheader[signature_len], ctx->bswap);
  165|  2.88k|    char *blob = NULL;
  166|  2.88k|    if (remainder != sas_subheader_remainder(len, signature_len)) {
  ------------------
  |  Branch (166:9): [True: 60, False: 2.82k]
  ------------------
  167|     60|        retval = READSTAT_ERROR_PARSE;
  168|     60|        goto cleanup;
  169|     60|    }
  170|  2.82k|    ctx->text_blob_count++;
  171|  2.82k|    ctx->text_blobs = readstat_realloc(ctx->text_blobs, ctx->text_blob_count * sizeof(char *));
  172|  2.82k|    ctx->text_blob_lengths = readstat_realloc(ctx->text_blob_lengths,
  173|  2.82k|            ctx->text_blob_count * sizeof(ctx->text_blob_lengths[0]));
  174|  2.82k|    if (ctx->text_blobs == NULL || ctx->text_blob_lengths == NULL) {
  ------------------
  |  Branch (174:9): [True: 0, False: 2.82k]
  |  Branch (174:36): [True: 0, False: 2.82k]
  ------------------
  175|      0|        retval = READSTAT_ERROR_MALLOC;
  176|      0|        goto cleanup;
  177|      0|    }
  178|       |
  179|  2.82k|    if ((blob = readstat_malloc(len-signature_len)) == NULL) {
  ------------------
  |  Branch (179:9): [True: 0, False: 2.82k]
  ------------------
  180|      0|        retval = READSTAT_ERROR_MALLOC;
  181|      0|        goto cleanup;
  182|      0|    }
  183|  2.82k|    memcpy(blob, subheader+signature_len, len-signature_len);
  184|  2.82k|    ctx->text_blob_lengths[ctx->text_blob_count-1] = len-signature_len;
  185|  2.82k|    ctx->text_blobs[ctx->text_blob_count-1] = blob;
  186|       |
  187|  2.88k|cleanup:
  188|  2.88k|    return retval;
  189|  2.82k|}
readstat_sas7bdat_read.c:sas7bdat_parse_column_name_subheader:
  292|  1.17k|static readstat_error_t sas7bdat_parse_column_name_subheader(const char *subheader, size_t len, sas7bdat_ctx_t *ctx) {
  293|  1.17k|    readstat_error_t retval = READSTAT_OK;
  294|  1.17k|    size_t signature_len = ctx->subheader_signature_size;
  295|  1.17k|    int cmax = ctx->u64 ? (len-28)/8 : (len-20)/8;
  ------------------
  |  Branch (295:16): [True: 139, False: 1.04k]
  ------------------
  296|  1.17k|    int i;
  297|  1.17k|    const char *cnp = &subheader[signature_len+8];
  298|  1.17k|    uint16_t remainder = sas_read2(&subheader[signature_len], ctx->bswap);
  299|       |
  300|  1.17k|    if (remainder != sas_subheader_remainder(len, signature_len)) {
  ------------------
  |  Branch (300:9): [True: 62, False: 1.11k]
  ------------------
  301|     62|        retval = READSTAT_ERROR_PARSE;
  302|     62|        goto cleanup;
  303|     62|    }
  304|       |
  305|  1.11k|    ctx->col_names_count += cmax;
  306|       |
  307|  1.11k|    if ((retval = sas7bdat_realloc_col_info(ctx, ctx->col_names_count)) != READSTAT_OK)
  ------------------
  |  Branch (307:9): [True: 15, False: 1.10k]
  ------------------
  308|     15|        goto cleanup;
  309|       |
  310|  40.0k|    for (i=ctx->col_names_count-cmax; i<ctx->col_names_count; i++) {
  ------------------
  |  Branch (310:39): [True: 38.9k, False: 1.10k]
  ------------------
  311|  38.9k|        ctx->col_info[i].name_ref = sas7bdat_parse_text_ref(cnp, ctx);
  312|  38.9k|        cnp += 8;
  313|  38.9k|    }
  314|       |
  315|  1.17k|cleanup:
  316|       |
  317|  1.17k|    return retval;
  318|  1.10k|}
readstat_sas7bdat_read.c:sas7bdat_parse_column_attributes_subheader:
  320|  2.01k|static readstat_error_t sas7bdat_parse_column_attributes_subheader(const char *subheader, size_t len, sas7bdat_ctx_t *ctx) {
  321|  2.01k|    readstat_error_t retval = READSTAT_OK;
  322|  2.01k|    size_t signature_len = ctx->subheader_signature_size;
  323|  2.01k|    int cmax = ctx->u64 ? (len-28)/16 : (len-20)/12;
  ------------------
  |  Branch (323:16): [True: 97, False: 1.91k]
  ------------------
  324|  2.01k|    int i;
  325|  2.01k|    const char *cap = &subheader[signature_len+8];
  326|  2.01k|    uint16_t remainder = sas_read2(&subheader[signature_len], ctx->bswap);
  327|       |
  328|  2.01k|    if (remainder != sas_subheader_remainder(len, signature_len)) {
  ------------------
  |  Branch (328:9): [True: 45, False: 1.96k]
  ------------------
  329|     45|        retval = READSTAT_ERROR_PARSE;
  330|     45|        goto cleanup;
  331|     45|    }
  332|  1.96k|    ctx->col_attrs_count += cmax;
  333|  1.96k|    if ((retval = sas7bdat_realloc_col_info(ctx, ctx->col_attrs_count)) != READSTAT_OK)
  ------------------
  |  Branch (333:9): [True: 7, False: 1.96k]
  ------------------
  334|      7|        goto cleanup;
  335|       |
  336|  9.76k|    for (i=ctx->col_attrs_count-cmax; i<ctx->col_attrs_count; i++) {
  ------------------
  |  Branch (336:39): [True: 7.81k, False: 1.94k]
  ------------------
  337|  7.81k|        if (ctx->u64) {
  ------------------
  |  Branch (337:13): [True: 608, False: 7.21k]
  ------------------
  338|    608|            ctx->col_info[i].offset = sas_read8(&cap[0], ctx->bswap);
  339|  7.21k|        } else {
  340|  7.21k|            ctx->col_info[i].offset = sas_read4(&cap[0], ctx->bswap);
  341|  7.21k|        }
  342|       |
  343|  7.81k|        readstat_off_t off=4;
  344|  7.81k|        if (ctx->u64)
  ------------------
  |  Branch (344:13): [True: 608, False: 7.21k]
  ------------------
  345|    608|            off=8;
  346|       |
  347|  7.81k|        ctx->col_info[i].width = sas_read4(&cap[off], ctx->bswap);
  348|  7.81k|        if (ctx->col_info[i].width > ctx->max_col_width)
  ------------------
  |  Branch (348:13): [True: 920, False: 6.89k]
  ------------------
  349|    920|            ctx->max_col_width = ctx->col_info[i].width;
  350|       |
  351|  7.81k|        if (cap[off+6] == SAS_COLUMN_TYPE_NUM) {
  ------------------
  |  |   89|  7.81k|#define SAS_COLUMN_TYPE_NUM  0x01
  ------------------
  |  Branch (351:13): [True: 4.59k, False: 3.22k]
  ------------------
  352|  4.59k|            ctx->col_info[i].type = READSTAT_TYPE_DOUBLE;
  353|  4.59k|        } else if (cap[off+6] == SAS_COLUMN_TYPE_CHR) {
  ------------------
  |  |   90|  3.22k|#define SAS_COLUMN_TYPE_CHR  0x02
  ------------------
  |  Branch (353:20): [True: 3.21k, False: 15]
  ------------------
  354|  3.21k|            ctx->col_info[i].type = READSTAT_TYPE_STRING;
  355|  3.21k|        } else {
  356|     15|            retval = READSTAT_ERROR_PARSE;
  357|     15|            goto cleanup;
  358|     15|        }
  359|  7.80k|        ctx->col_info[i].index = i;
  360|  7.80k|        cap += off+8;
  361|  7.80k|    }
  362|       |
  363|  2.01k|cleanup:
  364|       |
  365|  2.01k|    return retval;
  366|  1.96k|}
readstat_sas7bdat_read.c:sas7bdat_parse_column_format_subheader:
  368|  3.50k|static readstat_error_t sas7bdat_parse_column_format_subheader(const char *subheader, size_t len, sas7bdat_ctx_t *ctx) {
  369|  3.50k|    readstat_error_t retval = READSTAT_OK;
  370|       |
  371|  3.50k|    if (len < (ctx->u64 ? 58 : 46)) {
  ------------------
  |  Branch (371:9): [True: 2, False: 3.50k]
  |  Branch (371:16): [True: 310, False: 3.19k]
  ------------------
  372|      2|        retval = READSTAT_ERROR_PARSE;
  373|      2|        goto cleanup;
  374|      2|    }
  375|       |
  376|  3.50k|    ctx->col_formats_count++;
  377|  3.50k|    if ((retval = sas7bdat_realloc_col_info(ctx, ctx->col_formats_count)) != READSTAT_OK)
  ------------------
  |  Branch (377:9): [True: 0, False: 3.50k]
  ------------------
  378|      0|        goto cleanup;
  379|       |
  380|  3.50k|    if (ctx->u64) {
  ------------------
  |  Branch (380:9): [True: 310, False: 3.19k]
  ------------------
  381|    310|        ctx->col_info[ctx->col_formats_count-1].format_width = sas_read2(&subheader[24], ctx->bswap);
  382|    310|        ctx->col_info[ctx->col_formats_count-1].format_digits = sas_read2(&subheader[26], ctx->bswap);
  383|  3.19k|    } else {
  384|  3.19k|        ctx->col_info[ctx->col_formats_count-1].format_width = sas_read2(&subheader[12], ctx->bswap);
  385|  3.19k|        ctx->col_info[ctx->col_formats_count-1].format_digits = sas_read2(&subheader[14], ctx->bswap);
  386|  3.19k|    }
  387|  3.50k|    ctx->col_info[ctx->col_formats_count-1].format_ref = sas7bdat_parse_text_ref(
  388|  3.50k|            ctx->u64 ? &subheader[46] : &subheader[34], ctx);
  ------------------
  |  Branch (388:13): [True: 310, False: 3.19k]
  ------------------
  389|  3.50k|    ctx->col_info[ctx->col_formats_count-1].label_ref = sas7bdat_parse_text_ref(
  390|  3.50k|            ctx->u64 ? &subheader[52] : &subheader[40], ctx);
  ------------------
  |  Branch (390:13): [True: 310, False: 3.19k]
  ------------------
  391|       |
  392|  3.50k|cleanup:
  393|  3.50k|    return retval;
  394|  3.50k|}
readstat_sas7bdat_read.c:sas7bdat_parse_amd_pages_pass1:
 1108|  2.92k|static readstat_error_t sas7bdat_parse_amd_pages_pass1(int64_t last_examined_page_pass1, sas7bdat_ctx_t *ctx) {
 1109|  2.92k|    readstat_error_t retval = READSTAT_OK;
 1110|  2.92k|    readstat_io_t *io = ctx->io;
 1111|  2.92k|    uint64_t i;
 1112|  2.92k|    uint64_t amd_page_count = 0;
 1113|       |
 1114|       |    /* ...then AMD pages at the end */
 1115|  6.81k|    for (i=ctx->page_count-1; i>last_examined_page_pass1; i--) {
  ------------------
  |  Branch (1115:31): [True: 5.32k, False: 1.49k]
  ------------------
 1116|  5.32k|        if (io->seek(ctx->header_size + i*ctx->page_size, READSTAT_SEEK_SET, io->io_ctx) == -1) {
  ------------------
  |  Branch (1116:13): [True: 204, False: 5.12k]
  ------------------
 1117|    204|            retval = READSTAT_ERROR_SEEK;
 1118|    204|            if (ctx->handle.error) {
  ------------------
  |  Branch (1118:17): [True: 0, False: 204]
  ------------------
 1119|      0|                snprintf(ctx->error_buf, sizeof(ctx->error_buf), "ReadStat: Failed to seek to position %" PRId64 
 1120|      0|                        " (= %" PRId64 " + %" PRId64 "*%" PRId64 ")",
 1121|      0|                        ctx->header_size + i*ctx->page_size, ctx->header_size, i, ctx->page_size);
 1122|      0|                ctx->handle.error(ctx->error_buf, ctx->user_ctx);
 1123|      0|            }
 1124|    204|            goto cleanup;
 1125|    204|        }
 1126|       |
 1127|  5.12k|        readstat_off_t off = 0;
 1128|  5.12k|        if (ctx->u64)
  ------------------
  |  Branch (1128:13): [True: 4.07k, False: 1.04k]
  ------------------
 1129|  4.07k|            off = 16;
 1130|       |
 1131|  5.12k|        size_t head_len = off + 16 + 2;
 1132|  5.12k|        size_t tail_len = ctx->page_size - head_len;
 1133|       |
 1134|  5.12k|        if (io->read(ctx->page, head_len, io->io_ctx) < head_len) {
  ------------------
  |  Branch (1134:13): [True: 6, False: 5.11k]
  ------------------
 1135|      6|            retval = READSTAT_ERROR_READ;
 1136|      6|            goto cleanup;
 1137|      6|        }
 1138|       |
 1139|  5.11k|        uint16_t page_type = sas_read2(&ctx->page[off+16], ctx->bswap);
 1140|       |
 1141|  5.11k|        if ((page_type & SAS_PAGE_TYPE_MASK) == SAS_PAGE_TYPE_DATA) {
  ------------------
  |  |  112|  5.11k|#define SAS_PAGE_TYPE_MASK   0x0F00
  ------------------
                      if ((page_type & SAS_PAGE_TYPE_MASK) == SAS_PAGE_TYPE_DATA) {
  ------------------
  |  |  109|  5.11k|#define SAS_PAGE_TYPE_DATA   0x0100
  ------------------
  |  Branch (1141:13): [True: 1.32k, False: 3.78k]
  ------------------
 1142|       |            /* Usually AMD pages are at the end but sometimes data pages appear after them */
 1143|  1.32k|            if (amd_page_count > 0)
  ------------------
  |  Branch (1143:17): [True: 362, False: 966]
  ------------------
 1144|    362|                break;
 1145|    966|            continue;
 1146|  1.32k|        }
 1147|  3.78k|        if ((page_type & SAS_PAGE_TYPE_COMP))
  ------------------
  |  |  115|  3.78k|#define SAS_PAGE_TYPE_COMP   0x9000
  ------------------
  |  Branch (1147:13): [True: 971, False: 2.81k]
  ------------------
 1148|    971|            continue;
 1149|       |
 1150|  2.81k|        if (io->read(ctx->page + head_len, tail_len, io->io_ctx) < tail_len) {
  ------------------
  |  Branch (1150:13): [True: 15, False: 2.80k]
  ------------------
 1151|     15|            retval = READSTAT_ERROR_READ;
 1152|     15|            goto cleanup;
 1153|     15|        }
 1154|       |
 1155|  2.80k|        if ((retval = sas7bdat_parse_page_pass1(ctx->page, ctx->page_size, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1155:13): [True: 848, False: 1.95k]
  ------------------
 1156|    848|            if (ctx->handle.error && retval != READSTAT_ERROR_USER_ABORT) {
  ------------------
  |  Branch (1156:17): [True: 0, False: 848]
  |  Branch (1156:38): [True: 0, False: 0]
  ------------------
 1157|      0|                int64_t pos = io->seek(0, READSTAT_SEEK_CUR, io->io_ctx);
 1158|      0|                snprintf(ctx->error_buf, sizeof(ctx->error_buf), 
 1159|      0|                        "ReadStat: Error parsing page %" PRId64 ", bytes %" PRId64 "-%" PRId64, 
 1160|      0|                        i, pos - ctx->page_size, pos-1);
 1161|      0|                ctx->handle.error(ctx->error_buf, ctx->user_ctx);
 1162|      0|            }
 1163|    848|            goto cleanup;
 1164|    848|        }
 1165|       |
 1166|  1.95k|        amd_page_count++;
 1167|  1.95k|    }
 1168|       |
 1169|  2.92k|cleanup:
 1170|       |
 1171|  2.92k|    return retval;
 1172|  2.92k|}
readstat_sas7bdat_read.c:sas7bdat_parse_all_pages_pass2:
 1174|  1.85k|static readstat_error_t sas7bdat_parse_all_pages_pass2(sas7bdat_ctx_t *ctx) {
 1175|  1.85k|    readstat_error_t retval = READSTAT_OK;
 1176|  1.85k|    readstat_io_t *io = ctx->io;
 1177|  1.85k|    int64_t i;
 1178|       |
 1179|  4.31k|    for (i=0; i<ctx->page_count; i++) {
  ------------------
  |  Branch (1179:15): [True: 4.19k, False: 119]
  ------------------
 1180|  4.19k|        if ((retval = sas7bdat_update_progress(ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1180:13): [True: 0, False: 4.19k]
  ------------------
 1181|      0|            goto cleanup;
 1182|      0|        }
 1183|  4.19k|        if (io->read(ctx->page, ctx->page_size, io->io_ctx) < ctx->page_size) {
  ------------------
  |  Branch (1183:13): [True: 125, False: 4.07k]
  ------------------
 1184|    125|            retval = READSTAT_ERROR_READ;
 1185|    125|            goto cleanup;
 1186|    125|        }
 1187|       |
 1188|  4.07k|        if ((retval = sas7bdat_parse_page_pass2(ctx->page, ctx->page_size, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1188:13): [True: 1.37k, False: 2.70k]
  ------------------
 1189|  1.37k|            if (ctx->handle.error && retval != READSTAT_ERROR_USER_ABORT) {
  ------------------
  |  Branch (1189:17): [True: 0, False: 1.37k]
  |  Branch (1189:38): [True: 0, False: 0]
  ------------------
 1190|      0|                int64_t pos = io->seek(0, READSTAT_SEEK_CUR, io->io_ctx);
 1191|      0|                snprintf(ctx->error_buf, sizeof(ctx->error_buf), 
 1192|      0|                        "ReadStat: Error parsing page %" PRId64 ", bytes %" PRId64 "-%" PRId64, 
 1193|      0|                        i, pos - ctx->page_size, pos-1);
 1194|      0|                ctx->handle.error(ctx->error_buf, ctx->user_ctx);
 1195|      0|            }
 1196|  1.37k|            goto cleanup;
 1197|  1.37k|        }
 1198|  2.70k|        if (ctx->parsed_row_count == ctx->row_limit)
  ------------------
  |  Branch (1198:13): [True: 236, False: 2.46k]
  ------------------
 1199|    236|            break;
 1200|  2.70k|    }
 1201|  1.85k|cleanup:
 1202|       |
 1203|  1.85k|    return retval;
 1204|  1.85k|}
readstat_sas7bdat_read.c:sas7bdat_parse_page_pass2:
  950|  4.07k|static readstat_error_t sas7bdat_parse_page_pass2(const char *page, size_t page_size, sas7bdat_ctx_t *ctx) {
  951|  4.07k|    uint16_t page_type;
  952|       |
  953|  4.07k|    readstat_error_t retval = READSTAT_OK;
  954|       |
  955|  4.07k|    page_type = sas_read2(&page[ctx->page_header_size-8], ctx->bswap);
  956|       |
  957|  4.07k|    const char *data = NULL;
  958|       |
  959|  4.07k|    if ((page_type & SAS_PAGE_TYPE_MASK) == SAS_PAGE_TYPE_DATA) {
  ------------------
  |  |  112|  4.07k|#define SAS_PAGE_TYPE_MASK   0x0F00
  ------------------
                  if ((page_type & SAS_PAGE_TYPE_MASK) == SAS_PAGE_TYPE_DATA) {
  ------------------
  |  |  109|  4.07k|#define SAS_PAGE_TYPE_DATA   0x0100
  ------------------
  |  Branch (959:9): [True: 407, False: 3.66k]
  ------------------
  960|    407|        ctx->page_row_count = sas_read2(&page[ctx->page_header_size-6], ctx->bswap);
  961|    407|        data = &page[ctx->page_header_size];
  962|  3.66k|    } else if (!(page_type & SAS_PAGE_TYPE_COMP)) {
  ------------------
  |  |  115|  3.66k|#define SAS_PAGE_TYPE_COMP   0x9000
  ------------------
  |  Branch (962:16): [True: 3.08k, False: 584]
  ------------------
  963|  3.08k|        uint16_t subheader_count = sas_read2(&page[ctx->page_header_size-4], ctx->bswap);
  964|       |
  965|  3.08k|        int i;
  966|  3.08k|        const char *shp = &page[ctx->page_header_size];
  967|  3.08k|        int lshp = ctx->subheader_pointer_size;
  968|       |
  969|  3.08k|        if (ctx->page_header_size + subheader_count*lshp > page_size) {
  ------------------
  |  Branch (969:13): [True: 15, False: 3.06k]
  ------------------
  970|     15|            retval = READSTAT_ERROR_PARSE;
  971|     15|            goto cleanup;
  972|     15|        }
  973|       |
  974|  38.0k|        for (i=0; i<subheader_count; i++) {
  ------------------
  |  Branch (974:19): [True: 36.0k, False: 2.00k]
  ------------------
  975|  36.0k|            subheader_pointer_t shp_info = { 0 };
  976|  36.0k|            if ((retval = sas7bdat_parse_subheader_pointer(shp, page + page_size - shp, &shp_info, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (976:17): [True: 0, False: 36.0k]
  ------------------
  977|      0|                goto cleanup;
  978|      0|            }
  979|  36.0k|            if (shp_info.len > 0 && shp_info.compression != SAS_COMPRESSION_TRUNC) {
  ------------------
  |  |  124|  21.1k|#define SAS_COMPRESSION_TRUNC  0x01
  ------------------
  |  Branch (979:17): [True: 21.1k, False: 14.9k]
  |  Branch (979:37): [True: 17.5k, False: 3.58k]
  ------------------
  980|  17.5k|                if ((retval = sas7bdat_validate_subheader_pointer(&shp_info, page_size, subheader_count, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (980:21): [True: 191, False: 17.3k]
  ------------------
  981|    191|                    goto cleanup;
  982|    191|                }
  983|  17.3k|                if (shp_info.compression == SAS_COMPRESSION_NONE) {
  ------------------
  |  |  123|  17.3k|#define SAS_COMPRESSION_NONE   0x00
  ------------------
  |  Branch (983:21): [True: 15.9k, False: 1.43k]
  ------------------
  984|  15.9k|                    sas_subheader_type_t subheader_type = sas7bdat_parse_subheader_type(page + shp_info.offset, ctx);
  985|  15.9k|                    if (shp_info.is_compressed_data && subheader_type == SAS_SUBHEADER_TYPE_DATA) {
  ------------------
  |  Branch (985:25): [True: 12.1k, False: 3.81k]
  |  Branch (985:56): [True: 742, False: 11.3k]
  ------------------
  986|    742|                        if (shp_info.len != ctx->row_length) {
  ------------------
  |  Branch (986:29): [True: 177, False: 565]
  ------------------
  987|    177|                            retval = READSTAT_ERROR_ROW_WIDTH_MISMATCH;
  988|    177|                            goto cleanup;
  989|    177|                        }
  990|    565|                        if ((retval = sas7bdat_submit_columns_if_needed(ctx, 1)) != READSTAT_OK) {
  ------------------
  |  Branch (990:29): [True: 14, False: 551]
  ------------------
  991|     14|                            goto cleanup;
  992|     14|                        }
  993|    551|                        if ((retval = sas7bdat_parse_single_row(page + shp_info.offset, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (993:29): [True: 9, False: 542]
  ------------------
  994|      9|                            goto cleanup;
  995|      9|                        }
  996|  15.2k|                    } else {
  997|  15.2k|                        if (subheader_type != SAS_SUBHEADER_TYPE_COLUMN_TEXT) {
  ------------------
  |  Branch (997:29): [True: 13.7k, False: 1.45k]
  ------------------
  998|  13.7k|                            if ((retval = sas7bdat_parse_subheader(subheader_type, page + shp_info.offset, shp_info.len, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (998:33): [True: 376, False: 13.3k]
  ------------------
  999|    376|                                goto cleanup;
 1000|    376|                            }
 1001|  13.7k|                        }
 1002|  15.2k|                    }
 1003|  15.9k|                } else if (shp_info.compression == SAS_COMPRESSION_ROW) {
  ------------------
  |  |  125|  1.43k|#define SAS_COMPRESSION_ROW    0x04
  ------------------
  |  Branch (1003:28): [True: 1.42k, False: 12]
  ------------------
 1004|  1.42k|                    if ((retval = sas7bdat_submit_columns_if_needed(ctx, 1)) != READSTAT_OK) {
  ------------------
  |  Branch (1004:25): [True: 28, False: 1.39k]
  ------------------
 1005|     28|                        goto cleanup;
 1006|     28|                    }
 1007|  1.39k|                    if ((retval = sas7bdat_parse_subheader_compressed(page + shp_info.offset, shp_info.len, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1007:25): [True: 256, False: 1.14k]
  ------------------
 1008|    256|                        goto cleanup;
 1009|    256|                    }
 1010|  1.39k|                } else {
 1011|     12|                    retval = READSTAT_ERROR_UNSUPPORTED_COMPRESSION;
 1012|     12|                    goto cleanup;
 1013|     12|                }
 1014|  17.3k|            }
 1015|       |
 1016|  35.0k|            shp += lshp;
 1017|  35.0k|        }
 1018|       |
 1019|  2.00k|        if ((page_type & SAS_PAGE_TYPE_MASK) == SAS_PAGE_TYPE_MIX) {
  ------------------
  |  |  112|  2.00k|#define SAS_PAGE_TYPE_MASK   0x0F00
  ------------------
                      if ((page_type & SAS_PAGE_TYPE_MASK) == SAS_PAGE_TYPE_MIX) {
  ------------------
  |  |  110|  2.00k|#define SAS_PAGE_TYPE_MIX    0x0200
  ------------------
  |  Branch (1019:13): [True: 1.19k, False: 814]
  ------------------
 1020|       |            /* HACK - this is supposed to obey 8-byte boundaries but
 1021|       |             * some files created by Stat/Transfer don't. So verify that the
 1022|       |             * padding is { 0, 0, 0, 0 } or { ' ', ' ', ' ', ' ' } (or that
 1023|       |             * the file is not from Stat/Transfer) before skipping it */
 1024|  1.19k|            if ((shp-page)%8 == 4 && shp + 4 <= page + page_size &&
  ------------------
  |  Branch (1024:17): [True: 307, False: 883]
  |  Branch (1024:38): [True: 304, False: 3]
  ------------------
 1025|    304|                    (*(uint32_t *)shp == 0x00000000 ||
  ------------------
  |  Branch (1025:22): [True: 47, False: 257]
  ------------------
 1026|    257|                     *(uint32_t *)shp == 0x20202020 ||
  ------------------
  |  Branch (1026:22): [True: 32, False: 225]
  ------------------
 1027|    255|                     ctx->vendor != READSTAT_VENDOR_STAT_TRANSFER)) {
  ------------------
  |  Branch (1027:22): [True: 176, False: 49]
  ------------------
 1028|    255|                data = shp + 4;
 1029|    935|            } else {
 1030|    935|                data = shp;
 1031|    935|            }
 1032|  1.19k|        }
 1033|  2.00k|    }
 1034|  2.99k|    if (data) {
  ------------------
  |  Branch (1034:9): [True: 1.59k, False: 1.39k]
  ------------------
 1035|  1.59k|        if ((retval = sas7bdat_submit_columns_if_needed(ctx, 0)) != READSTAT_OK) {
  ------------------
  |  Branch (1035:13): [True: 130, False: 1.46k]
  ------------------
 1036|    130|            goto cleanup;
 1037|    130|        }
 1038|  1.46k|        if (ctx->handle.value) {
  ------------------
  |  Branch (1038:13): [True: 1.46k, False: 0]
  ------------------
 1039|  1.46k|            retval = sas7bdat_parse_rows(data, page + page_size - data, ctx);
 1040|  1.46k|        }
 1041|  1.46k|    } 
 1042|  4.07k|cleanup:
 1043|       |
 1044|  4.07k|    return retval;
 1045|  2.99k|}
readstat_sas7bdat_read.c:sas7bdat_parse_single_row:
  453|   142k|static readstat_error_t sas7bdat_parse_single_row(const char *data, sas7bdat_ctx_t *ctx) {
  454|   142k|    if (ctx->parsed_row_count == ctx->row_limit)
  ------------------
  |  Branch (454:9): [True: 417, False: 141k]
  ------------------
  455|    417|        return READSTAT_OK;
  456|   141k|    if (ctx->row_offset) {
  ------------------
  |  Branch (456:9): [True: 0, False: 141k]
  ------------------
  457|      0|        ctx->row_offset--;
  458|      0|        return READSTAT_OK;
  459|      0|    }
  460|       |
  461|   141k|    readstat_error_t retval = READSTAT_OK;
  462|   141k|    int j;
  463|   141k|    if (ctx->handle.value) {
  ------------------
  |  Branch (463:9): [True: 141k, False: 0]
  ------------------
  464|   141k|        ctx->scratch_buffer_len = 4*ctx->max_col_width+1;
  465|   141k|        ctx->scratch_buffer = readstat_realloc(ctx->scratch_buffer, ctx->scratch_buffer_len);
  466|   141k|        if (ctx->scratch_buffer == NULL) {
  ------------------
  |  Branch (466:13): [True: 3, False: 141k]
  ------------------
  467|      3|            retval = READSTAT_ERROR_MALLOC;
  468|      3|            goto cleanup;
  469|      3|        }
  470|       |
  471|  7.39M|        for (j=0; j<ctx->column_count; j++) {
  ------------------
  |  Branch (471:19): [True: 7.25M, False: 141k]
  ------------------
  472|  7.25M|            col_info_t *col_info = &ctx->col_info[j];
  473|  7.25M|            readstat_variable_t *variable = ctx->variables[j];
  474|  7.25M|            if (variable->skip)
  ------------------
  |  Branch (474:17): [True: 0, False: 7.25M]
  ------------------
  475|      0|                continue;
  476|       |
  477|  7.25M|            if (col_info->offset > ctx->row_length || col_info->offset + col_info->width > ctx->row_length) {
  ------------------
  |  Branch (477:17): [True: 87, False: 7.25M]
  |  Branch (477:55): [True: 15, False: 7.25M]
  ------------------
  478|    102|                retval = READSTAT_ERROR_PARSE;
  479|    102|                goto cleanup;
  480|    102|            }
  481|  7.25M|            retval = sas7bdat_handle_data_value(variable, col_info, &data[col_info->offset], ctx);
  482|  7.25M|            if (retval != READSTAT_OK) {
  ------------------
  |  Branch (482:17): [True: 14, False: 7.25M]
  ------------------
  483|     14|                goto cleanup;
  484|     14|            }
  485|  7.25M|        }
  486|   141k|    }
  487|   141k|    ctx->parsed_row_count++;
  488|       |
  489|   141k|cleanup:
  490|   141k|    return retval;
  491|   141k|}
readstat_sas7bdat_read.c:sas7bdat_handle_data_value:
  397|  7.25M|        col_info_t *col_info, const char *col_data, sas7bdat_ctx_t *ctx) {
  398|  7.25M|    readstat_error_t retval = READSTAT_OK;
  399|  7.25M|    int cb_retval = 0;
  400|  7.25M|    readstat_value_t value;
  401|  7.25M|    memset(&value, 0, sizeof(readstat_value_t));
  402|       |
  403|  7.25M|    value.type = col_info->type;
  404|       |
  405|  7.25M|    if (col_info->type == READSTAT_TYPE_STRING) {
  ------------------
  |  Branch (405:9): [True: 7.15M, False: 101k]
  ------------------
  406|  7.15M|        retval = readstat_convert(ctx->scratch_buffer, ctx->scratch_buffer_len,
  407|  7.15M|                col_data, col_info->width, ctx->converter);
  408|  7.15M|        if (retval != READSTAT_OK) {
  ------------------
  |  Branch (408:13): [True: 14, False: 7.15M]
  ------------------
  409|     14|            if (ctx->handle.error) {
  ------------------
  |  Branch (409:17): [True: 0, False: 14]
  ------------------
  410|      0|                snprintf(ctx->error_buf, sizeof(ctx->error_buf),
  411|      0|                        "ReadStat: Error converting string (row=%u, col=%u) to specified encoding: %.*s",
  412|      0|                        ctx->parsed_row_count+1, col_info->index+1, col_info->width, col_data);
  413|      0|                ctx->handle.error(ctx->error_buf, ctx->user_ctx);
  414|      0|            }
  415|     14|            goto cleanup;
  416|     14|        }
  417|       |
  418|  7.15M|        value.v.string_value = ctx->scratch_buffer;
  419|  7.15M|    } else if (col_info->type == READSTAT_TYPE_DOUBLE) {
  ------------------
  |  Branch (419:16): [True: 101k, False: 0]
  ------------------
  420|   101k|        uint64_t  val = 0;
  421|   101k|        double dval = NAN;
  422|   101k|        if (ctx->little_endian) {
  ------------------
  |  Branch (422:13): [True: 101k, False: 0]
  ------------------
  423|   101k|            int k;
  424|   574k|            for (k=0; k<col_info->width; k++) {
  ------------------
  |  Branch (424:23): [True: 473k, False: 101k]
  ------------------
  425|   473k|                val = (val << 8) | (unsigned char)col_data[col_info->width-1-k];
  426|   473k|            }
  427|   101k|        } else {
  428|      0|            int k;
  429|      0|            for (k=0; k<col_info->width; k++) {
  ------------------
  |  Branch (429:23): [True: 0, False: 0]
  ------------------
  430|      0|                val = (val << 8) | (unsigned char)col_data[k];
  431|      0|            }
  432|      0|        }
  433|   101k|        val <<= (8-col_info->width)*8;
  434|       |
  435|   101k|        memcpy(&dval, &val, 8);
  436|       |
  437|   101k|        if (isnan(dval)) {
  ------------------
  |  Branch (437:13): [True: 7.98k, False: 93.1k]
  ------------------
  438|  7.98k|            value.v.double_value = NAN;
  439|  7.98k|            sas_assign_tag(&value, ~((val >> 40) & 0xFF));
  440|  93.1k|        } else {
  441|  93.1k|            value.v.double_value = dval;
  442|  93.1k|        }
  443|   101k|    }
  444|  7.25M|    cb_retval = ctx->handle.value(ctx->parsed_row_count, variable, value, ctx->user_ctx);
  445|       |
  446|  7.25M|    if (cb_retval != READSTAT_HANDLER_OK)
  ------------------
  |  Branch (446:9): [True: 0, False: 7.25M]
  ------------------
  447|      0|        retval = READSTAT_ERROR_USER_ABORT;
  448|       |
  449|  7.25M|cleanup:
  450|  7.25M|    return retval;
  451|  7.25M|}
readstat_sas7bdat_read.c:sas7bdat_parse_subheader_compressed:
  625|  1.39k|static readstat_error_t sas7bdat_parse_subheader_compressed(const char *subheader, size_t len, sas7bdat_ctx_t *ctx) {
  626|  1.39k|    if (ctx->rdc_compression)
  ------------------
  |  Branch (626:9): [True: 416, False: 982]
  ------------------
  627|    416|        return sas7bdat_parse_subheader_rdc(subheader, len, ctx);
  628|       |
  629|    982|    return sas7bdat_parse_subheader_rle(subheader, len, ctx);
  630|  1.39k|}
readstat_sas7bdat_read.c:sas7bdat_parse_subheader_rdc:
  512|    416|static readstat_error_t sas7bdat_parse_subheader_rdc(const char *subheader, size_t len, sas7bdat_ctx_t *ctx) {
  513|    416|    readstat_error_t retval = READSTAT_OK;
  514|    416|    const unsigned char *input = (const unsigned char *)subheader;
  515|    416|    char *buffer = malloc(ctx->row_length);
  516|    416|    char *output = buffer;
  517|  2.02k|    while (input + 2 <= (const unsigned char *)subheader + len) {
  ------------------
  |  Branch (517:12): [True: 1.64k, False: 375]
  ------------------
  518|  1.64k|        int i;
  519|  1.64k|        unsigned short prefix = (input[0] << 8) + input[1];
  520|  1.64k|        input += 2;
  521|  23.2k|        for (i=0; i<16; i++) {
  ------------------
  |  Branch (521:19): [True: 22.0k, False: 1.24k]
  ------------------
  522|  22.0k|            if ((prefix & (1 << (15 - i))) == 0) {
  ------------------
  |  Branch (522:17): [True: 15.7k, False: 6.23k]
  ------------------
  523|  15.7k|                if (input + 1 > (const unsigned char *)subheader + len) {
  ------------------
  |  Branch (523:21): [True: 366, False: 15.4k]
  ------------------
  524|    366|                    break;
  525|    366|                }
  526|  15.4k|                if (output + 1 > buffer + ctx->row_length) {
  ------------------
  |  Branch (526:21): [True: 3, False: 15.4k]
  ------------------
  527|      3|                    retval = READSTAT_ERROR_ROW_WIDTH_MISMATCH;
  528|      3|                    goto cleanup;
  529|      3|                }
  530|  15.4k|                *output++ = *input++;
  531|  15.4k|                continue;
  532|  15.4k|            }
  533|       |
  534|  6.23k|            if (input + 2 > (const unsigned char *)subheader + len) {
  ------------------
  |  Branch (534:17): [True: 5, False: 6.22k]
  ------------------
  535|      5|                retval = READSTAT_ERROR_PARSE;
  536|      5|                goto cleanup;
  537|      5|            }
  538|       |
  539|  6.22k|            unsigned char marker_byte = *input++;
  540|  6.22k|            unsigned char next_byte = *input++;
  541|  6.22k|            size_t insert_len = 0, copy_len = 0;
  542|  6.22k|            unsigned char insert_byte = 0x00;
  543|  6.22k|            size_t back_offset = 0;
  544|       |
  545|  6.22k|            if (marker_byte <= 0x0F) {
  ------------------
  |  Branch (545:17): [True: 2.87k, False: 3.34k]
  ------------------
  546|  2.87k|                insert_len = 3 + marker_byte;
  547|  2.87k|                insert_byte = next_byte;
  548|  3.34k|            } else if ((marker_byte >> 4) == 1) {
  ------------------
  |  Branch (548:24): [True: 881, False: 2.46k]
  ------------------
  549|    881|                if (input + 1 > (const unsigned char *)subheader + len) {
  ------------------
  |  Branch (549:21): [True: 1, False: 880]
  ------------------
  550|      1|                    retval = READSTAT_ERROR_PARSE;
  551|      1|                    goto cleanup;
  552|      1|                }
  553|    880|                insert_len = 19 + (marker_byte & 0x0F) + next_byte * 16;
  554|    880|                insert_byte = *input++;
  555|  2.46k|            } else if ((marker_byte >> 4) == 2) {
  ------------------
  |  Branch (555:24): [True: 242, False: 2.22k]
  ------------------
  556|    242|                if (input + 1 > (const unsigned char *)subheader + len) {
  ------------------
  |  Branch (556:21): [True: 1, False: 241]
  ------------------
  557|      1|                    retval = READSTAT_ERROR_PARSE;
  558|      1|                    goto cleanup;
  559|      1|                }
  560|    241|                copy_len = 16 + (*input++);
  561|    241|                back_offset = 3 + (marker_byte & 0x0F) + next_byte * 16;
  562|  2.22k|            } else {
  563|  2.22k|                copy_len = (marker_byte >> 4);
  564|  2.22k|                back_offset = 3 + (marker_byte & 0x0F) + next_byte * 16;
  565|  2.22k|            }
  566|       |
  567|  6.22k|            if (insert_len) {
  ------------------
  |  Branch (567:17): [True: 3.75k, False: 2.46k]
  ------------------
  568|  3.75k|                if (output + insert_len > buffer + ctx->row_length) {
  ------------------
  |  Branch (568:21): [True: 2, False: 3.75k]
  ------------------
  569|      2|                    retval = READSTAT_ERROR_ROW_WIDTH_MISMATCH;
  570|      2|                    goto cleanup;
  571|      2|                }
  572|  3.75k|                memset(output, insert_byte, insert_len);
  573|  3.75k|                output += insert_len;
  574|  3.75k|            } else if (copy_len) {
  ------------------
  |  Branch (574:24): [True: 2.46k, False: 0]
  ------------------
  575|  2.46k|                if (output - buffer < back_offset || copy_len > back_offset) {
  ------------------
  |  Branch (575:21): [True: 12, False: 2.45k]
  |  Branch (575:54): [True: 16, False: 2.43k]
  ------------------
  576|     28|                    retval = READSTAT_ERROR_PARSE;
  577|     28|                    goto cleanup;
  578|     28|                }
  579|  2.43k|                if (output + copy_len > buffer + ctx->row_length) {
  ------------------
  |  Branch (579:21): [True: 1, False: 2.43k]
  ------------------
  580|      1|                    retval = READSTAT_ERROR_ROW_WIDTH_MISMATCH;
  581|      1|                    goto cleanup;
  582|      1|                }
  583|  2.43k|                memcpy(output, output - back_offset, copy_len);
  584|  2.43k|                output += copy_len;
  585|  2.43k|            }
  586|  6.22k|        }
  587|  1.64k|    }
  588|       |
  589|    375|    if (output - buffer != ctx->row_length) {
  ------------------
  |  Branch (589:9): [True: 28, False: 347]
  ------------------
  590|     28|        retval = READSTAT_ERROR_ROW_WIDTH_MISMATCH;
  591|     28|        goto cleanup;
  592|     28|    }
  593|    347|    retval = sas7bdat_parse_single_row(buffer, ctx);
  594|    416|cleanup:
  595|    416|    free(buffer);
  596|       |
  597|    416|    return retval;
  598|    347|}
readstat_sas7bdat_read.c:sas7bdat_parse_subheader_rle:
  600|    982|static readstat_error_t sas7bdat_parse_subheader_rle(const char *subheader, size_t len, sas7bdat_ctx_t *ctx) {
  601|    982|    if (ctx->row_limit == ctx->parsed_row_count)
  ------------------
  |  Branch (601:9): [True: 513, False: 469]
  ------------------
  602|    513|        return READSTAT_OK;
  603|       |
  604|    469|    readstat_error_t retval = READSTAT_OK;
  605|    469|    ssize_t bytes_decompressed = 0;
  606|       |
  607|    469|    bytes_decompressed = sas_rle_decompress(ctx->row, ctx->row_length, subheader, len);
  608|       |
  609|    469|    if (bytes_decompressed != ctx->row_length) {
  ------------------
  |  Branch (609:9): [True: 148, False: 321]
  ------------------
  610|    148|        retval = READSTAT_ERROR_ROW_WIDTH_MISMATCH;
  611|    148|        if (ctx->handle.error) {
  ------------------
  |  Branch (611:13): [True: 0, False: 148]
  ------------------
  612|      0|            snprintf(ctx->error_buf, sizeof(ctx->error_buf), 
  613|      0|                    "ReadStat: Row #%d decompressed to %ld bytes (expected %d bytes)",
  614|      0|                    ctx->parsed_row_count, (long)(bytes_decompressed), ctx->row_length);
  615|      0|            ctx->handle.error(ctx->error_buf, ctx->user_ctx);
  616|      0|        }
  617|    148|        goto cleanup;
  618|    148|    }
  619|    321|    retval = sas7bdat_parse_single_row(ctx->row, ctx);
  620|       |
  621|    469|cleanup:
  622|    469|    return retval;
  623|    321|}
readstat_sas7bdat_read.c:sas7bdat_parse_rows:
  493|  1.46k|static readstat_error_t sas7bdat_parse_rows(const char *data, size_t len, sas7bdat_ctx_t *ctx) {
  494|  1.46k|    readstat_error_t retval = READSTAT_OK;
  495|  1.46k|    int i;
  496|  1.46k|    size_t row_offset=0;
  497|   142k|    for (i=0; i<ctx->page_row_count && ctx->parsed_row_count < ctx->row_limit; i++) {
  ------------------
  |  Branch (497:15): [True: 141k, False: 1.27k]
  |  Branch (497:40): [True: 141k, False: 28]
  ------------------
  498|   141k|        if (row_offset + ctx->row_length > len) {
  ------------------
  |  Branch (498:13): [True: 94, False: 141k]
  ------------------
  499|     94|            retval = READSTAT_ERROR_ROW_WIDTH_MISMATCH;
  500|     94|            goto cleanup;
  501|     94|        }
  502|   141k|        if ((retval = sas7bdat_parse_single_row(&data[row_offset], ctx)) != READSTAT_OK)
  ------------------
  |  Branch (502:13): [True: 71, False: 141k]
  ------------------
  503|     71|            goto cleanup;
  504|       |
  505|   141k|        row_offset += ctx->row_length;
  506|   141k|    }
  507|       |
  508|  1.46k|cleanup:
  509|  1.46k|    return retval;
  510|  1.46k|}
readstat_sas7bdat_read.c:sas7bdat_submit_columns_if_needed:
  799|  3.94k|static readstat_error_t sas7bdat_submit_columns_if_needed(sas7bdat_ctx_t *ctx, int compressed) {
  800|  3.94k|    readstat_error_t retval = READSTAT_OK;
  801|  3.94k|    if (!ctx->did_submit_columns) {
  ------------------
  |  Branch (801:9): [True: 1.33k, False: 2.60k]
  ------------------
  802|  1.33k|        if ((retval = sas7bdat_submit_columns(ctx, compressed)) != READSTAT_OK) {
  ------------------
  |  Branch (802:13): [True: 260, False: 1.07k]
  ------------------
  803|    260|            goto cleanup;
  804|    260|        }
  805|  1.07k|        ctx->did_submit_columns = 1;
  806|  1.07k|    }
  807|  3.94k|cleanup:
  808|  3.94k|    return retval;
  809|  3.94k|}
readstat_sas7bdat_read.c:sas7bdat_submit_columns:
  738|  1.33k|static readstat_error_t sas7bdat_submit_columns(sas7bdat_ctx_t *ctx, int compressed) {
  739|  1.33k|    readstat_error_t retval = READSTAT_OK;
  740|  1.33k|    if (ctx->handle.metadata) {
  ------------------
  |  Branch (740:9): [True: 1.33k, False: 0]
  ------------------
  741|  1.33k|        readstat_metadata_t metadata = {
  742|  1.33k|            .row_count = ctx->row_limit,
  743|  1.33k|            .var_count = ctx->column_count,
  744|  1.33k|            .table_name = ctx->table_name,
  745|  1.33k|            .file_label = ctx->file_label,
  746|  1.33k|            .file_encoding = ctx->input_encoding, /* orig encoding? */
  747|  1.33k|            .creation_time = ctx->ctime,
  748|  1.33k|            .modified_time = ctx->mtime,
  749|  1.33k|            .file_format_version = ctx->version,
  750|  1.33k|            .compression = READSTAT_COMPRESS_NONE,
  751|  1.33k|            .endianness = ctx->little_endian ? READSTAT_ENDIAN_LITTLE : READSTAT_ENDIAN_BIG,
  ------------------
  |  Branch (751:27): [True: 268, False: 1.07k]
  ------------------
  752|  1.33k|            .is64bit = ctx->u64
  753|  1.33k|        };
  754|  1.33k|        if (compressed) {
  ------------------
  |  Branch (754:13): [True: 542, False: 797]
  ------------------
  755|    542|            if (ctx->rdc_compression) {
  ------------------
  |  Branch (755:17): [True: 60, False: 482]
  ------------------
  756|     60|                metadata.compression = READSTAT_COMPRESS_BINARY;
  757|    482|            } else {
  758|    482|                metadata.compression = READSTAT_COMPRESS_ROWS;
  759|    482|            }
  760|    542|        }
  761|  1.33k|        if (ctx->handle.metadata(&metadata, ctx->user_ctx) != READSTAT_HANDLER_OK) {
  ------------------
  |  Branch (761:13): [True: 0, False: 1.33k]
  ------------------
  762|      0|            retval = READSTAT_ERROR_USER_ABORT;
  763|      0|            goto cleanup;
  764|      0|        }
  765|  1.33k|    }
  766|  1.33k|    if (ctx->column_count == 0)
  ------------------
  |  Branch (766:9): [True: 859, False: 480]
  ------------------
  767|    859|        goto cleanup;
  768|       |
  769|    480|    if ((ctx->variables = readstat_calloc(ctx->column_count, sizeof(readstat_variable_t *))) == NULL) {
  ------------------
  |  Branch (769:9): [True: 0, False: 480]
  ------------------
  770|      0|        retval = READSTAT_ERROR_MALLOC;
  771|      0|        goto cleanup;
  772|      0|    }
  773|    480|    int i;
  774|    480|    int index_after_skipping = 0;
  775|  3.15M|    for (i=0; i<ctx->column_count; i++) {
  ------------------
  |  Branch (775:15): [True: 3.15M, False: 220]
  ------------------
  776|  3.15M|        ctx->variables[i] = sas7bdat_init_variable(ctx, i, index_after_skipping, &retval);
  777|  3.15M|        if (ctx->variables[i] == NULL)
  ------------------
  |  Branch (777:13): [True: 260, False: 3.15M]
  ------------------
  778|    260|            break;
  779|       |
  780|  3.15M|        int cb_retval = READSTAT_HANDLER_OK;
  781|  3.15M|        if (ctx->handle.variable) {
  ------------------
  |  Branch (781:13): [True: 3.15M, False: 0]
  ------------------
  782|  3.15M|            cb_retval = ctx->handle.variable(i, ctx->variables[i], ctx->variables[i]->format, ctx->user_ctx);
  783|  3.15M|        }
  784|  3.15M|        if (cb_retval == READSTAT_HANDLER_ABORT) {
  ------------------
  |  Branch (784:13): [True: 0, False: 3.15M]
  ------------------
  785|      0|            retval = READSTAT_ERROR_USER_ABORT;
  786|      0|            goto cleanup;
  787|      0|        }
  788|       |
  789|  3.15M|        if (cb_retval == READSTAT_HANDLER_SKIP_VARIABLE) {
  ------------------
  |  Branch (789:13): [True: 0, False: 3.15M]
  ------------------
  790|      0|            ctx->variables[i]->skip = 1;
  791|  3.15M|        } else {
  792|  3.15M|            index_after_skipping++;
  793|  3.15M|        }
  794|  3.15M|    }
  795|  1.33k|cleanup:
  796|  1.33k|    return retval;
  797|    480|}
readstat_sas7bdat_read.c:sas7bdat_init_variable:
  682|  3.15M|        int index_after_skipping, readstat_error_t *out_retval) {
  683|  3.15M|    readstat_error_t retval = READSTAT_OK;
  684|  3.15M|    readstat_variable_t *variable = readstat_calloc(1, sizeof(readstat_variable_t));
  685|       |
  686|  3.15M|    variable->index = i;
  687|  3.15M|    variable->index_after_skipping = index_after_skipping;
  688|  3.15M|    variable->type = ctx->col_info[i].type;
  689|  3.15M|    variable->storage_width = ctx->col_info[i].width;
  690|       |
  691|  3.15M|    if ((retval = sas7bdat_validate_column(&ctx->col_info[i])) != READSTAT_OK) {
  ------------------
  |  Branch (691:9): [True: 86, False: 3.15M]
  ------------------
  692|     86|        goto cleanup;
  693|     86|    }
  694|  3.15M|    if ((retval = sas7bdat_copy_text_ref(variable->name, sizeof(variable->name), 
  ------------------
  |  Branch (694:9): [True: 63, False: 3.15M]
  ------------------
  695|  3.15M|                    ctx->col_info[i].name_ref, ctx)) != READSTAT_OK) {
  696|     63|        goto cleanup;
  697|     63|    }
  698|  3.15M|    if ((retval = sas7bdat_copy_text_ref(variable->format, sizeof(variable->format),
  ------------------
  |  Branch (698:9): [True: 54, False: 3.15M]
  ------------------
  699|  3.15M|                    ctx->col_info[i].format_ref, ctx)) != READSTAT_OK) {
  700|     54|        goto cleanup;
  701|     54|    }
  702|  3.15M|    size_t len = strlen(variable->format);
  703|  3.15M|    if (ctx->col_info[i].format_width) {
  ------------------
  |  Branch (703:9): [True: 440, False: 3.15M]
  ------------------
  704|    440|        len += snprintf(variable->format + len, sizeof(variable->format) - len,
  705|    440|                "%d", ctx->col_info[i].format_width);
  706|    440|    }
  707|  3.15M|    if (len && ctx->col_info[i].format_digits) {
  ------------------
  |  Branch (707:9): [True: 466, False: 3.15M]
  |  Branch (707:16): [True: 296, False: 170]
  ------------------
  708|    296|        len += snprintf(variable->format + len, sizeof(variable->format) - len,
  709|    296|                ".%d", ctx->col_info[i].format_digits);
  710|    296|    }
  711|  3.15M|    if ((retval = sas7bdat_copy_text_ref(variable->label, sizeof(variable->label), 
  ------------------
  |  Branch (711:9): [True: 57, False: 3.15M]
  ------------------
  712|  3.15M|                    ctx->col_info[i].label_ref, ctx)) != READSTAT_OK) {
  713|     57|        goto cleanup;
  714|     57|    }
  715|       |
  716|  3.15M|cleanup:
  717|  3.15M|    if (retval != READSTAT_OK) {
  ------------------
  |  Branch (717:9): [True: 260, False: 3.15M]
  ------------------
  718|    260|        if (out_retval)
  ------------------
  |  Branch (718:13): [True: 260, False: 0]
  ------------------
  719|    260|            *out_retval = retval;
  720|       |
  721|    260|        if (retval == READSTAT_ERROR_CONVERT_BAD_STRING) {
  ------------------
  |  Branch (721:13): [True: 11, False: 249]
  ------------------
  722|     11|            if (ctx->handle.error) {
  ------------------
  |  Branch (722:17): [True: 0, False: 11]
  ------------------
  723|      0|                snprintf(ctx->error_buf, sizeof(ctx->error_buf),
  724|      0|                        "ReadStat: Error converting variable #%d info to specified encoding: %s %s (%s)",
  725|      0|                        i, variable->name, variable->format, variable->label);
  726|      0|                ctx->handle.error(ctx->error_buf, ctx->user_ctx);
  727|      0|            }
  728|     11|        }
  729|       |
  730|    260|        free(variable);
  731|       |
  732|    260|        return NULL;
  733|    260|    }
  734|       |
  735|  3.15M|    return variable;
  736|  3.15M|}
readstat_sas7bdat_read.c:sas7bdat_validate_column:
  667|  3.15M|static readstat_error_t sas7bdat_validate_column(col_info_t *col_info) {
  668|  3.15M|    if (col_info->type == READSTAT_TYPE_DOUBLE) {
  ------------------
  |  Branch (668:9): [True: 824, False: 3.15M]
  ------------------
  669|    824|        if (col_info->width > 8 || col_info->width < 3) {
  ------------------
  |  Branch (669:13): [True: 48, False: 776]
  |  Branch (669:36): [True: 2, False: 774]
  ------------------
  670|     50|            return READSTAT_ERROR_PARSE;
  671|     50|        }
  672|    824|    }
  673|  3.15M|    if (col_info->type == READSTAT_TYPE_STRING) {
  ------------------
  |  Branch (673:9): [True: 3.15M, False: 774]
  ------------------
  674|  3.15M|        if (col_info->width > INT16_MAX) {
  ------------------
  |  Branch (674:13): [True: 36, False: 3.15M]
  ------------------
  675|     36|            return READSTAT_ERROR_PARSE;
  676|     36|        }
  677|  3.15M|    }
  678|  3.15M|    return READSTAT_OK;
  679|  3.15M|}
readstat_sas7bdat_read.c:sas7bdat_update_progress:
  128|  4.35k|static readstat_error_t sas7bdat_update_progress(sas7bdat_ctx_t *ctx) {
  129|  4.35k|    readstat_io_t *io = ctx->io;
  130|  4.35k|    return io->update(ctx->file_size, ctx->handle.progress, ctx->user_ctx, io->io_ctx);
  131|  4.35k|}
readstat_sas7bdat_read.c:sas7bdat_ctx_free:
   94|  3.67k|static void sas7bdat_ctx_free(sas7bdat_ctx_t *ctx) {
   95|  3.67k|    int i;
   96|  3.67k|    if (ctx->text_blobs) {
  ------------------
  |  Branch (96:9): [True: 895, False: 2.77k]
  ------------------
   97|  3.71k|        for (i=0; i<ctx->text_blob_count; i++) {
  ------------------
  |  Branch (97:19): [True: 2.82k, False: 895]
  ------------------
   98|  2.82k|            free(ctx->text_blobs[i]);
   99|  2.82k|        }
  100|    895|        free(ctx->text_blobs);
  101|    895|        free(ctx->text_blob_lengths);
  102|    895|    }
  103|  3.67k|    if (ctx->variables) {
  ------------------
  |  Branch (103:9): [True: 480, False: 3.19k]
  ------------------
  104|  22.2M|        for (i=0; i<ctx->column_count; i++) {
  ------------------
  |  Branch (104:19): [True: 22.2M, False: 480]
  ------------------
  105|  22.2M|            if (ctx->variables[i])
  ------------------
  |  Branch (105:17): [True: 3.15M, False: 19.1M]
  ------------------
  106|  3.15M|                free(ctx->variables[i]);
  107|  22.2M|        }
  108|    480|        free(ctx->variables);
  109|    480|    }
  110|  3.67k|    if (ctx->col_info)
  ------------------
  |  Branch (110:9): [True: 639, False: 3.03k]
  ------------------
  111|    639|        free(ctx->col_info);
  112|       |
  113|  3.67k|    if (ctx->scratch_buffer)
  ------------------
  |  Branch (113:9): [True: 539, False: 3.13k]
  ------------------
  114|    539|        free(ctx->scratch_buffer);
  115|       |
  116|  3.67k|    if (ctx->page)
  ------------------
  |  Branch (116:9): [True: 3.15k, False: 517]
  ------------------
  117|  3.15k|        free(ctx->page);
  118|       |
  119|  3.67k|    if (ctx->row)
  ------------------
  |  Branch (119:9): [True: 992, False: 2.68k]
  ------------------
  120|    992|        free(ctx->row);
  121|       |
  122|  3.67k|    if (ctx->converter)
  ------------------
  |  Branch (122:9): [True: 2.35k, False: 1.32k]
  ------------------
  123|  2.35k|        iconv_close(ctx->converter);
  124|       |
  125|  3.67k|    free(ctx);
  126|  3.67k|}

sas_rle_decompress:
   47|    469|        const void *input_buf, size_t input_len) {
   48|    469|    unsigned char *buffer = (unsigned char *)output_buf;
   49|    469|    unsigned char *output = buffer;
   50|    469|    size_t output_written = 0;
   51|       |
   52|    469|    const unsigned char *input = (const unsigned char *)input_buf;
   53|       |
   54|  33.2k|    while (input < (const unsigned char *)input_buf + input_len) {
  ------------------
  |  Branch (54:12): [True: 32.9k, False: 348]
  ------------------
   55|  32.9k|        unsigned char control = *input++;
   56|  32.9k|        unsigned char command = (control & 0xF0) >> 4;
   57|  32.9k|        unsigned char length = (control & 0x0F);
   58|  32.9k|        int copy_len = 0;
   59|  32.9k|        int insert_len = 0;
   60|  32.9k|        unsigned char insert_byte = '\0';
   61|  32.9k|        if (input + command_lengths[command] > (const unsigned char *)input_buf + input_len) {
  ------------------
  |  Branch (61:13): [True: 5, False: 32.9k]
  ------------------
   62|      5|            return -1;
   63|      5|        }
   64|  32.9k|        switch (command) {
   65|  4.37k|            case SAS_RLE_COMMAND_COPY64:
  ------------------
  |  |   13|  4.37k|#define SAS_RLE_COMMAND_COPY64          0
  ------------------
  |  Branch (65:13): [True: 4.37k, False: 28.5k]
  ------------------
   66|  4.37k|                copy_len = (*input++) + 64 + length * 256;
   67|  4.37k|                break;
   68|    144|            case SAS_RLE_COMMAND_COPY64_PLUS_4096:
  ------------------
  |  |   14|    144|#define SAS_RLE_COMMAND_COPY64_PLUS_4096 1
  ------------------
  |  Branch (68:13): [True: 144, False: 32.7k]
  ------------------
   69|    144|                copy_len = (*input++) + 64 + length * 256 + 4096;
   70|    144|                break;
   71|    941|            case SAS_RLE_COMMAND_COPY96: copy_len = length + 96; break;
  ------------------
  |  |   15|    941|#define SAS_RLE_COMMAND_COPY96          2
  ------------------
  |  Branch (71:13): [True: 941, False: 31.9k]
  ------------------
   72|    498|            case SAS_RLE_COMMAND_INSERT_BYTE18:
  ------------------
  |  |   16|    498|#define SAS_RLE_COMMAND_INSERT_BYTE18   4
  ------------------
  |  Branch (72:13): [True: 498, False: 32.4k]
  ------------------
   73|    498|                insert_len = (*input++) + 18 + length * 256;
   74|    498|                insert_byte = *input++;
   75|    498|                break;
   76|    702|            case SAS_RLE_COMMAND_INSERT_AT17:
  ------------------
  |  |   17|    702|#define SAS_RLE_COMMAND_INSERT_AT17     5
  ------------------
  |  Branch (76:13): [True: 702, False: 32.2k]
  ------------------
   77|    702|                insert_len = (*input++) + 17 + length * 256;
   78|    702|                insert_byte = '@';
   79|    702|                break;
   80|    851|            case SAS_RLE_COMMAND_INSERT_BLANK17:
  ------------------
  |  |   18|    851|#define SAS_RLE_COMMAND_INSERT_BLANK17  6
  ------------------
  |  Branch (80:13): [True: 851, False: 32.0k]
  ------------------
   81|    851|                insert_len = (*input++) + 17 + length * 256;
   82|    851|                insert_byte = ' ';
   83|    851|                break;
   84|  1.17k|            case SAS_RLE_COMMAND_INSERT_ZERO17:
  ------------------
  |  |   19|  1.17k|#define SAS_RLE_COMMAND_INSERT_ZERO17   7
  ------------------
  |  Branch (84:13): [True: 1.17k, False: 31.7k]
  ------------------
   85|  1.17k|                insert_len = (*input++) + 17 + length * 256;
   86|  1.17k|                insert_byte = '\0';
   87|  1.17k|                break;
   88|  1.06k|            case SAS_RLE_COMMAND_COPY1:  copy_len = length + 1; break;
  ------------------
  |  |   20|  1.06k|#define SAS_RLE_COMMAND_COPY1           8
  ------------------
  |  Branch (88:13): [True: 1.06k, False: 31.8k]
  ------------------
   89|    393|            case SAS_RLE_COMMAND_COPY17: copy_len = length + 17; break;
  ------------------
  |  |   21|    393|#define SAS_RLE_COMMAND_COPY17          9
  ------------------
  |  Branch (89:13): [True: 393, False: 32.5k]
  ------------------
   90|    743|            case SAS_RLE_COMMAND_COPY33: copy_len = length + 33; break;
  ------------------
  |  |   22|    743|#define SAS_RLE_COMMAND_COPY33         10
  ------------------
  |  Branch (90:13): [True: 743, False: 32.1k]
  ------------------
   91|    457|            case SAS_RLE_COMMAND_COPY49: copy_len = length + 49; break;
  ------------------
  |  |   23|    457|#define SAS_RLE_COMMAND_COPY49         11
  ------------------
  |  Branch (91:13): [True: 457, False: 32.4k]
  ------------------
   92|  1.79k|            case SAS_RLE_COMMAND_INSERT_BYTE3:
  ------------------
  |  |   24|  1.79k|#define SAS_RLE_COMMAND_INSERT_BYTE3   12
  ------------------
  |  Branch (92:13): [True: 1.79k, False: 31.1k]
  ------------------
   93|  1.79k|                insert_byte = *input++;
   94|  1.79k|                insert_len = length + 3;
   95|  1.79k|                break;
   96|  1.19k|            case SAS_RLE_COMMAND_INSERT_AT2:
  ------------------
  |  |   25|  1.19k|#define SAS_RLE_COMMAND_INSERT_AT2     13
  ------------------
  |  Branch (96:13): [True: 1.19k, False: 31.7k]
  ------------------
   97|  1.19k|                insert_byte = '@';
   98|  1.19k|                insert_len = length + 2;
   99|  1.19k|                break;
  100|  8.39k|            case SAS_RLE_COMMAND_INSERT_BLANK2:
  ------------------
  |  |   26|  8.39k|#define SAS_RLE_COMMAND_INSERT_BLANK2  14
  ------------------
  |  Branch (100:13): [True: 8.39k, False: 24.5k]
  ------------------
  101|  8.39k|                insert_byte = ' ';
  102|  8.39k|                insert_len = length + 2;
  103|  8.39k|                break;
  104|  7.13k|            case SAS_RLE_COMMAND_INSERT_ZERO2:
  ------------------
  |  |   27|  7.13k|#define SAS_RLE_COMMAND_INSERT_ZERO2   15
  ------------------
  |  Branch (104:13): [True: 7.13k, False: 25.7k]
  ------------------
  105|  7.13k|                insert_byte = '\0';
  106|  7.13k|                insert_len = length + 2;
  107|  7.13k|                break;
  108|  3.02k|            default:
  ------------------
  |  Branch (108:13): [True: 3.02k, False: 29.8k]
  ------------------
  109|       |                /* error out here? */
  110|  3.02k|                break;
  111|  32.9k|        }
  112|  32.9k|        if (copy_len) {
  ------------------
  |  Branch (112:13): [True: 8.12k, False: 24.7k]
  ------------------
  113|  8.12k|            if (output_written + copy_len > output_len) {
  ------------------
  |  Branch (113:17): [True: 21, False: 8.10k]
  ------------------
  114|     21|                return -1;
  115|     21|            }
  116|  8.10k|            if (input + copy_len > (const unsigned char *)input_buf + input_len) {
  ------------------
  |  Branch (116:17): [True: 82, False: 8.02k]
  ------------------
  117|     82|                return -1;
  118|     82|            }
  119|  8.02k|            if (output) {
  ------------------
  |  Branch (119:17): [True: 8.02k, False: 0]
  ------------------
  120|  8.02k|                memcpy(&output[output_written], input, copy_len);
  121|  8.02k|            }
  122|  8.02k|            input += copy_len;
  123|  8.02k|            output_written += copy_len;
  124|  8.02k|        }
  125|  32.8k|        if (insert_len) {
  ------------------
  |  Branch (125:13): [True: 21.7k, False: 11.0k]
  ------------------
  126|  21.7k|            if (output_written + insert_len > output_len) {
  ------------------
  |  Branch (126:17): [True: 13, False: 21.7k]
  ------------------
  127|     13|                return -1;
  128|     13|            }
  129|  21.7k|            if (output) {
  ------------------
  |  Branch (129:17): [True: 21.7k, False: 0]
  ------------------
  130|  21.7k|                memset(&output[output_written], insert_byte, insert_len);
  131|  21.7k|            }
  132|  21.7k|            output_written += insert_len;
  133|  21.7k|        }
  134|  32.8k|    }
  135|       |
  136|    348|    return output_written;
  137|    469|}

rt_open_handler:
    8|  3.67k|int rt_open_handler(const char *path, void *io_ctx) {
    9|  3.67k|    return 0;
   10|  3.67k|}
rt_close_handler:
   12|  3.67k|int rt_close_handler(void *io_ctx) {
   13|  3.67k|    return 0;
   14|  3.67k|}
rt_seek_handler:
   17|  30.3k|        readstat_io_flags_t whence, void *io_ctx) {
   18|  30.3k|    rt_buffer_ctx_t *buffer_ctx = (rt_buffer_ctx_t *)io_ctx;
   19|  30.3k|    readstat_off_t newpos = -1;
   20|  30.3k|    if (whence == READSTAT_SEEK_SET) {
  ------------------
  |  Branch (20:9): [True: 19.8k, False: 10.5k]
  ------------------
   21|  19.8k|        newpos = offset;
   22|  19.8k|    } else if (whence == READSTAT_SEEK_CUR) {
  ------------------
  |  Branch (22:16): [True: 6.83k, False: 3.67k]
  ------------------
   23|  6.83k|        newpos = buffer_ctx->pos + offset;
   24|  6.83k|    } else if (whence == READSTAT_SEEK_END) {
  ------------------
  |  Branch (24:16): [True: 3.67k, False: 0]
  ------------------
   25|  3.67k|        newpos = buffer_ctx->buffer->used + offset;
   26|  3.67k|    }
   27|       |
   28|  30.3k|    if (newpos < 0)
  ------------------
  |  Branch (28:9): [True: 116, False: 30.2k]
  ------------------
   29|    116|        return -1;
   30|       |
   31|  30.2k|    if (newpos > buffer_ctx->buffer->used)
  ------------------
  |  Branch (31:9): [True: 216, False: 30.0k]
  ------------------
   32|    216|        return -1;
   33|       |
   34|  30.0k|    buffer_ctx->pos = newpos;
   35|  30.0k|    return newpos;
   36|  30.2k|}
rt_read_handler:
   38|  53.0k|ssize_t rt_read_handler(void *buf, size_t nbytes, void *io_ctx) {
   39|  53.0k|    rt_buffer_ctx_t *buffer_ctx = (rt_buffer_ctx_t *)io_ctx;
   40|  53.0k|    ssize_t bytes_copied = 0;
   41|  53.0k|    ssize_t bytes_left = buffer_ctx->buffer->used - buffer_ctx->pos;
   42|  53.0k|    if (nbytes <= bytes_left) {
  ------------------
  |  Branch (42:9): [True: 52.6k, False: 432]
  ------------------
   43|  52.6k|        memcpy(buf, buffer_ctx->buffer->bytes + buffer_ctx->pos, nbytes);
   44|  52.6k|        bytes_copied = nbytes;
   45|  52.6k|    } else if (bytes_left > 0) {
  ------------------
  |  Branch (45:16): [True: 226, False: 206]
  ------------------
   46|    226|        memcpy(buf, buffer_ctx->buffer->bytes + buffer_ctx->pos, bytes_left);
   47|    226|        bytes_copied = bytes_left;
   48|    226|    }
   49|  53.0k|    buffer_ctx->pos += bytes_copied;
   50|  53.0k|    return bytes_copied;
   51|  53.0k|}
rt_update_handler:
   54|  4.35k|        void *user_ctx, void *io_ctx) {
   55|  4.35k|    if (!progress_handler)
  ------------------
  |  Branch (55:9): [True: 4.35k, False: 0]
  ------------------
   56|  4.35k|        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|}

