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

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

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

readstat_convert:
   39|  28.4M|readstat_error_t readstat_convert(char *dst, size_t dst_len, const char *src, size_t src_len, iconv_t converter) {
   40|  28.4M|    return readstat_convert_impl(dst, dst_len, src, src_len, converter, 1);
   41|  28.4M|}
readstat_convert.c:readstat_convert_impl:
    8|  28.4M|        iconv_t converter, int trim_spaces) {
    9|       |    /* strip off spaces from the input because the programs use ASCII space
   10|       |     * padding even with non-ASCII encoding. */
   11|  28.4M|    while (src_len && ((trim_spaces && src[src_len-1] == ' ') || src[src_len-1] == '\0')) {
  ------------------
  |  Branch (11:12): [True: 59.0k, False: 28.4M]
  |  Branch (11:25): [True: 59.0k, False: 0]
  |  Branch (11:40): [True: 4.56k, False: 54.5k]
  |  Branch (11:66): [True: 35.7k, False: 18.7k]
  ------------------
   12|  40.3k|        src_len--;
   13|  40.3k|    }
   14|  28.4M|    if (dst_len == 0) {
  ------------------
  |  Branch (14:9): [True: 0, False: 28.4M]
  ------------------
   15|      0|        return READSTAT_ERROR_CONVERT_LONG_STRING;
   16|  28.4M|    } else if (converter) {
  ------------------
  |  Branch (16:16): [True: 7.13M, False: 21.2M]
  ------------------
   17|  7.13M|        size_t dst_left = dst_len - 1;
   18|  7.13M|        char *dst_end = dst;
   19|  7.13M|        size_t status = iconv(converter, (readstat_iconv_inbuf_t)&src, &src_len, &dst_end, &dst_left);
   20|  7.13M|        if (status == (size_t)-1) {
  ------------------
  |  Branch (20:13): [True: 2.92k, False: 7.12M]
  ------------------
   21|  2.92k|            if (errno == E2BIG) {
  ------------------
  |  Branch (21:17): [True: 4, False: 2.92k]
  ------------------
   22|      4|                return READSTAT_ERROR_CONVERT_LONG_STRING;
   23|  2.92k|            } else if (errno == EILSEQ) {
  ------------------
  |  Branch (23:24): [True: 15, False: 2.90k]
  ------------------
   24|     15|                return READSTAT_ERROR_CONVERT_BAD_STRING;
   25|  2.90k|            } else if (errno != EINVAL) { /* EINVAL indicates improper truncation; accept it */
  ------------------
  |  Branch (25:24): [True: 0, False: 2.90k]
  ------------------
   26|      0|                return READSTAT_ERROR_CONVERT;
   27|      0|            }
   28|  2.92k|        }
   29|  7.13M|        dst[dst_len - dst_left - 1] = '\0';
   30|  21.2M|    } else if (src_len + 1 > dst_len) {
  ------------------
  |  Branch (30:16): [True: 20, False: 21.2M]
  ------------------
   31|     20|        return READSTAT_ERROR_CONVERT_LONG_STRING;
   32|  21.2M|    } else {
   33|  21.2M|        memcpy(dst, src, src_len);
   34|  21.2M|        dst[src_len] = '\0';
   35|  21.2M|    }
   36|  28.4M|    return READSTAT_OK;
   37|  28.4M|}

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

readstat_malloc:
   10|  10.6k|void *readstat_malloc(size_t len) {
   11|  10.6k|    if (len > MAX_MALLOC_SIZE || len == 0) {
  ------------------
  |  |    3|  21.2k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
  |  Branch (11:9): [True: 0, False: 10.6k]
  |  Branch (11:34): [True: 0, False: 10.6k]
  ------------------
   12|      0|        return NULL;
   13|      0|    }
   14|  10.6k|    return malloc(len);
   15|  10.6k|}
readstat_calloc:
   17|  3.27M|void *readstat_calloc(size_t count, size_t size) {
   18|  3.27M|    if (count > MAX_MALLOC_SIZE || size > MAX_MALLOC_SIZE || count * size > MAX_MALLOC_SIZE) {
  ------------------
  |  |    3|  6.54M|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
                  if (count > MAX_MALLOC_SIZE || size > MAX_MALLOC_SIZE || count * size > MAX_MALLOC_SIZE) {
  ------------------
  |  |    3|  6.54M|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
                  if (count > MAX_MALLOC_SIZE || size > MAX_MALLOC_SIZE || count * size > MAX_MALLOC_SIZE) {
  ------------------
  |  |    3|  3.27M|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
  |  Branch (18:9): [True: 0, False: 3.27M]
  |  Branch (18:36): [True: 0, False: 3.27M]
  |  Branch (18:62): [True: 0, False: 3.27M]
  ------------------
   19|      0|        return NULL;
   20|      0|    }
   21|  3.27M|    if (count == 0 || size == 0) {
  ------------------
  |  Branch (21:9): [True: 0, False: 3.27M]
  |  Branch (21:23): [True: 0, False: 3.27M]
  ------------------
   22|      0|        return NULL;
   23|      0|    }
   24|  3.27M|    return calloc(count, size);
   25|  3.27M|}
readstat_realloc:
   27|  60.7k|void *readstat_realloc(void *ptr, size_t len) {
   28|  60.7k|    if (len > MAX_MALLOC_SIZE || len == 0) {
  ------------------
  |  |    3|   121k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
  |  Branch (28:9): [True: 94, False: 60.6k]
  |  Branch (28:34): [True: 1, False: 60.6k]
  ------------------
   29|     95|        if (ptr)
  ------------------
  |  Branch (29:13): [True: 43, False: 52]
  ------------------
   30|     43|            free(ptr);
   31|     95|        return NULL;
   32|     95|    }
   33|  60.6k|    return realloc(ptr, len);
   34|  60.7k|}

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

sas_read8:
  147|  98.0k|uint64_t sas_read8(const char *data, int bswap) {
  148|  98.0k|    uint64_t tmp;
  149|  98.0k|    memcpy(&tmp, data, 8);
  150|  98.0k|    return bswap ? byteswap8(tmp) : tmp;
  ------------------
  |  Branch (150:12): [True: 86.5k, False: 11.4k]
  ------------------
  151|  98.0k|}
sas_read4:
  153|   295k|uint32_t sas_read4(const char *data, int bswap) {
  154|   295k|    uint32_t tmp;
  155|   295k|    memcpy(&tmp, data, 4);
  156|   295k|    return bswap ? byteswap4(tmp) : tmp;
  ------------------
  |  Branch (156:12): [True: 227k, False: 67.9k]
  ------------------
  157|   295k|}
sas_read2:
  159|   193k|uint16_t sas_read2(const char *data, int bswap) {
  160|   193k|    uint16_t tmp;
  161|   193k|    memcpy(&tmp, data, 2);
  162|   193k|    return bswap ? byteswap2(tmp) : tmp;
  ------------------
  |  Branch (162:12): [True: 108k, False: 85.4k]
  ------------------
  163|   193k|}
sas_subheader_remainder:
  165|  11.3k|size_t sas_subheader_remainder(size_t len, size_t signature_len) {
  166|  11.3k|    return len - (4+2*signature_len);
  167|  11.3k|}
sas_read_header:
  170|  4.50k|        readstat_error_handler error_handler, void *user_ctx) {
  171|  4.50k|    sas_header_start_t  header_start;
  172|  4.50k|    sas_header_end_t    header_end;
  173|  4.50k|    int retval = READSTAT_OK;
  174|  4.50k|    char error_buf[1024];
  175|  4.50k|    time_t epoch = sas_epoch();
  176|       |
  177|  4.50k|    if (io->read(&header_start, sizeof(sas_header_start_t), io->io_ctx) < sizeof(sas_header_start_t)) {
  ------------------
  |  Branch (177:9): [True: 20, False: 4.48k]
  ------------------
  178|     20|        retval = READSTAT_ERROR_READ;
  179|     20|        goto cleanup;
  180|     20|    }
  181|  4.48k|    if (memcmp(header_start.magic, sas7bdat_magic_number, sizeof(sas7bdat_magic_number)) != 0 &&
  ------------------
  |  Branch (181:9): [True: 2.12k, False: 2.36k]
  ------------------
  182|  2.12k|            memcmp(header_start.magic, sas7bdat_magic_number_alt, sizeof(sas7bdat_magic_number_alt)) != 0 &&
  ------------------
  |  Branch (182:13): [True: 2.10k, False: 17]
  ------------------
  183|  2.10k|            memcmp(header_start.magic, sas7bcat_magic_number, sizeof(sas7bcat_magic_number)) != 0) {
  ------------------
  |  Branch (183:13): [True: 134, False: 1.97k]
  ------------------
  184|    134|        retval = READSTAT_ERROR_PARSE;
  185|    134|        goto cleanup;
  186|    134|    }
  187|  4.35k|    if (header_start.a1 == SAS_ALIGNMENT_OFFSET_4) {
  ------------------
  |  |   88|  4.35k|#define SAS_ALIGNMENT_OFFSET_4  0x33
  ------------------
  |  Branch (187:9): [True: 12, False: 4.33k]
  ------------------
  188|     12|        hinfo->pad1 = 4;
  189|     12|    }
  190|  4.35k|    if (header_start.a2 == SAS_ALIGNMENT_OFFSET_4) {
  ------------------
  |  |   88|  4.35k|#define SAS_ALIGNMENT_OFFSET_4  0x33
  ------------------
  |  Branch (190:9): [True: 2.43k, False: 1.92k]
  ------------------
  191|  2.43k|        hinfo->u64 = 1;
  192|  2.43k|    }
  193|  4.35k|    int bswap = 0;
  194|  4.35k|    if (header_start.endian == SAS_ENDIAN_BIG) {
  ------------------
  |  |   81|  4.35k|#define SAS_ENDIAN_BIG       0x00
  ------------------
  |  Branch (194:9): [True: 3.14k, False: 1.20k]
  ------------------
  195|  3.14k|        bswap = machine_is_little_endian();
  196|  3.14k|        hinfo->little_endian = 0;
  197|  3.14k|    } else if (header_start.endian == SAS_ENDIAN_LITTLE) {
  ------------------
  |  |   82|  1.20k|#define SAS_ENDIAN_LITTLE    0x01
  ------------------
  |  Branch (197:16): [True: 1.19k, False: 11]
  ------------------
  198|  1.19k|        bswap = !machine_is_little_endian();
  199|  1.19k|        hinfo->little_endian = 1;
  200|  1.19k|    } else {
  201|     11|        retval = READSTAT_ERROR_PARSE;
  202|     11|        goto cleanup;
  203|     11|    }
  204|  4.34k|    int i;
  205|   205k|    for (i=0; i<sizeof(_charset_table)/sizeof(_charset_table[0]); i++) {
  ------------------
  |  Branch (205:15): [True: 203k, False: 2.42k]
  ------------------
  206|   203k|        if (header_start.encoding == _charset_table[i].code) {
  ------------------
  |  Branch (206:13): [True: 1.91k, False: 201k]
  ------------------
  207|  1.91k|            hinfo->encoding = _charset_table[i].name;
  208|  1.91k|            break;
  209|  1.91k|        }
  210|   203k|    }
  211|  4.34k|    if (hinfo->encoding == NULL && header_start.encoding != 0) {
  ------------------
  |  Branch (211:9): [True: 2.42k, False: 1.91k]
  |  Branch (211:36): [True: 11, False: 2.41k]
  ------------------
  212|     11|        if (error_handler) {
  ------------------
  |  Branch (212:13): [True: 0, False: 11]
  ------------------
  213|      0|            snprintf(error_buf, sizeof(error_buf), "Unsupported character set code: %d", header_start.encoding);
  214|      0|            error_handler(error_buf, user_ctx);
  215|      0|        }
  216|     11|        retval = READSTAT_ERROR_UNSUPPORTED_CHARSET;
  217|     11|        goto cleanup;
  218|     11|    }
  219|  4.32k|    memcpy(hinfo->table_name, header_start.table_name, sizeof(header_start.table_name));
  220|  4.32k|    if (io->seek(hinfo->pad1, READSTAT_SEEK_CUR, io->io_ctx) == -1) {
  ------------------
  |  Branch (220:9): [True: 7, False: 4.32k]
  ------------------
  221|      7|        retval = READSTAT_ERROR_SEEK;
  222|      7|        goto cleanup;
  223|      7|    }
  224|       |
  225|  4.32k|    double creation_time, modification_time, creation_time_diff, modification_time_diff;
  226|       |
  227|  4.32k|    if (io->read(&creation_time, sizeof(double), io->io_ctx) < sizeof(double)) {
  ------------------
  |  Branch (227:9): [True: 10, False: 4.31k]
  ------------------
  228|     10|        retval = READSTAT_ERROR_READ;
  229|     10|        goto cleanup;
  230|     10|    }
  231|  4.31k|    if (bswap)
  ------------------
  |  Branch (231:9): [True: 3.12k, False: 1.19k]
  ------------------
  232|  3.12k|        creation_time = byteswap_double(creation_time);
  233|       |
  234|  4.31k|    if (io->read(&modification_time, sizeof(double), io->io_ctx) < sizeof(double)) {
  ------------------
  |  Branch (234:9): [True: 6, False: 4.30k]
  ------------------
  235|      6|        retval = READSTAT_ERROR_READ;
  236|      6|        goto cleanup;
  237|      6|    }
  238|  4.30k|    if (bswap)
  ------------------
  |  Branch (238:9): [True: 3.11k, False: 1.18k]
  ------------------
  239|  3.11k|        modification_time = byteswap_double(modification_time);
  240|       |
  241|  4.30k|    if (io->read(&creation_time_diff, sizeof(double), io->io_ctx) < sizeof(double)) {
  ------------------
  |  Branch (241:9): [True: 6, False: 4.30k]
  ------------------
  242|      6|        retval = READSTAT_ERROR_READ;
  243|      6|        goto cleanup;
  244|      6|    }
  245|  4.30k|    if (bswap)
  ------------------
  |  Branch (245:9): [True: 3.11k, False: 1.18k]
  ------------------
  246|  3.11k|        creation_time_diff = byteswap_double(creation_time_diff);
  247|       |    
  248|  4.30k|    if (io->read(&modification_time_diff, sizeof(double), io->io_ctx) < sizeof(double)) {
  ------------------
  |  Branch (248:9): [True: 6, False: 4.29k]
  ------------------
  249|      6|        retval = READSTAT_ERROR_READ;
  250|      6|        goto cleanup;
  251|      6|    }
  252|  4.29k|    if (bswap)
  ------------------
  |  Branch (252:9): [True: 3.11k, False: 1.18k]
  ------------------
  253|  3.11k|        modification_time_diff = byteswap_double(modification_time_diff);
  254|       |    
  255|  4.29k|    hinfo->creation_time = sas_convert_time(creation_time, creation_time_diff, epoch);
  256|  4.29k|    hinfo->modification_time = sas_convert_time(modification_time, modification_time_diff, epoch);
  257|       |
  258|  4.29k|    uint32_t header_size, page_size;
  259|       |
  260|  4.29k|    if (io->read(&header_size, sizeof(uint32_t), io->io_ctx) < sizeof(uint32_t)) {
  ------------------
  |  Branch (260:9): [True: 8, False: 4.28k]
  ------------------
  261|      8|        retval = READSTAT_ERROR_READ;
  262|      8|        goto cleanup;
  263|      8|    }
  264|  4.28k|    if (io->read(&page_size, sizeof(uint32_t), io->io_ctx) < sizeof(uint32_t)) {
  ------------------
  |  Branch (264:9): [True: 3, False: 4.28k]
  ------------------
  265|      3|        retval = READSTAT_ERROR_READ;
  266|      3|        goto cleanup;
  267|      3|    }
  268|       |
  269|  4.28k|    hinfo->header_size = bswap ? byteswap4(header_size) : header_size;
  ------------------
  |  Branch (269:26): [True: 3.10k, False: 1.17k]
  ------------------
  270|  4.28k|    hinfo->page_size = bswap ? byteswap4(page_size) : page_size;
  ------------------
  |  Branch (270:24): [True: 3.10k, False: 1.17k]
  ------------------
  271|       |
  272|  4.28k|    if (hinfo->header_size < 1024 || hinfo->page_size < 1024) {
  ------------------
  |  Branch (272:9): [True: 10, False: 4.27k]
  |  Branch (272:38): [True: 11, False: 4.26k]
  ------------------
  273|     21|        retval = READSTAT_ERROR_PARSE;
  274|     21|        goto cleanup;
  275|     21|    }
  276|  4.26k|    if (hinfo->header_size > (1<<24) || hinfo->page_size > (1<<24)) {
  ------------------
  |  Branch (276:9): [True: 16, False: 4.24k]
  |  Branch (276:41): [True: 24, False: 4.22k]
  ------------------
  277|     40|        retval = READSTAT_ERROR_PARSE;
  278|     40|        goto cleanup;
  279|     40|    }
  280|       |
  281|  4.22k|    if (hinfo->u64) {
  ------------------
  |  Branch (281:9): [True: 2.38k, False: 1.84k]
  ------------------
  282|  2.38k|        hinfo->page_header_size = SAS_PAGE_HEADER_SIZE_64BIT;
  ------------------
  |  |  124|  2.38k|#define SAS_PAGE_HEADER_SIZE_64BIT  40
  ------------------
  283|  2.38k|        hinfo->subheader_pointer_size = SAS_SUBHEADER_POINTER_SIZE_64BIT;
  ------------------
  |  |  121|  2.38k|#define SAS_SUBHEADER_POINTER_SIZE_64BIT    24
  ------------------
  284|  2.38k|    } else {
  285|  1.84k|        hinfo->page_header_size = SAS_PAGE_HEADER_SIZE_32BIT;
  ------------------
  |  |  123|  1.84k|#define SAS_PAGE_HEADER_SIZE_32BIT  24
  ------------------
  286|  1.84k|        hinfo->subheader_pointer_size = SAS_SUBHEADER_POINTER_SIZE_32BIT;
  ------------------
  |  |  120|  1.84k|#define SAS_SUBHEADER_POINTER_SIZE_32BIT    12
  ------------------
  287|  1.84k|    }
  288|       |
  289|  4.22k|    if (hinfo->u64) {
  ------------------
  |  Branch (289:9): [True: 2.38k, False: 1.84k]
  ------------------
  290|  2.38k|        uint64_t page_count;
  291|  2.38k|        if (io->read(&page_count, sizeof(uint64_t), io->io_ctx) < sizeof(uint64_t)) {
  ------------------
  |  Branch (291:13): [True: 18, False: 2.36k]
  ------------------
  292|     18|            retval = READSTAT_ERROR_READ;
  293|     18|            goto cleanup;
  294|     18|        }
  295|  2.36k|        hinfo->page_count = bswap ? byteswap8(page_count) : page_count;
  ------------------
  |  Branch (295:29): [True: 1.82k, False: 542]
  ------------------
  296|  2.36k|    } else {
  297|  1.84k|        uint32_t page_count;
  298|  1.84k|        if (io->read(&page_count, sizeof(uint32_t), io->io_ctx) < sizeof(uint32_t)) {
  ------------------
  |  Branch (298:13): [True: 23, False: 1.81k]
  ------------------
  299|     23|            retval = READSTAT_ERROR_READ;
  300|     23|            goto cleanup;
  301|     23|        }
  302|  1.81k|        hinfo->page_count = bswap ? byteswap4(page_count) : page_count;
  ------------------
  |  Branch (302:29): [True: 1.20k, False: 617]
  ------------------
  303|  1.81k|    }
  304|  4.18k|    if (hinfo->page_count > (1<<24)) {
  ------------------
  |  Branch (304:9): [True: 14, False: 4.16k]
  ------------------
  305|     14|        retval = READSTAT_ERROR_PARSE;
  306|     14|        goto cleanup;
  307|     14|    }
  308|       |    
  309|  4.16k|    if (io->seek(8, READSTAT_SEEK_CUR, io->io_ctx) == -1) {
  ------------------
  |  Branch (309:9): [True: 75, False: 4.09k]
  ------------------
  310|     75|        retval = READSTAT_ERROR_SEEK;
  311|     75|        if (error_handler) {
  ------------------
  |  Branch (311:13): [True: 0, False: 75]
  ------------------
  312|      0|            snprintf(error_buf, sizeof(error_buf), "ReadStat: Failed to seek forward by %d", 8);
  313|      0|            error_handler(error_buf, user_ctx);
  314|      0|        }
  315|     75|        goto cleanup;
  316|     75|    }
  317|  4.09k|    if (io->read(&header_end, sizeof(sas_header_end_t), io->io_ctx) < sizeof(sas_header_end_t)) {
  ------------------
  |  Branch (317:9): [True: 16, False: 4.07k]
  ------------------
  318|     16|        retval = READSTAT_ERROR_READ;
  319|     16|        goto cleanup;
  320|     16|    }
  321|  4.07k|    char major, revision_tag, revision;
  322|  4.07k|    int minor;
  323|       |    /* The release field is not NUL-terminated in the file; copy it into a
  324|       |     * terminated buffer before handing it to sscanf, which calls strlen on it. */
  325|  4.07k|    char release[sizeof(header_end.release)+1];
  326|  4.07k|    memcpy(release, header_end.release, sizeof(header_end.release));
  327|  4.07k|    release[sizeof(header_end.release)] = '\0';
  328|  4.07k|    if (sscanf(release, "%c.%04d%c%c", &major, &minor, &revision_tag, &revision) != 4) {
  ------------------
  |  Branch (328:9): [True: 4, False: 4.07k]
  ------------------
  329|      4|        retval = READSTAT_ERROR_PARSE;
  330|      4|        goto cleanup;
  331|      4|    }
  332|       |
  333|  4.07k|    if (major >= '1' && major <= '9') {
  ------------------
  |  Branch (333:9): [True: 4.06k, False: 11]
  |  Branch (333:25): [True: 4.05k, False: 9]
  ------------------
  334|  4.05k|        hinfo->major_version = major - '0';
  335|  4.05k|    } else if (major == 'V') {
  ------------------
  |  Branch (335:16): [True: 2, False: 18]
  ------------------
  336|       |        // It appears that SAS Visual Forecaster reports the major version as "V"
  337|       |        // Treat it as version 9 for all intents and purposes
  338|      2|        hinfo->major_version = 9;
  339|     18|    } else {
  340|     18|        retval = READSTAT_ERROR_PARSE;
  341|     18|        goto cleanup;
  342|     18|    }
  343|       |    // revision_tag is usually M, but J has been observed in the wild (not created with SAS?)
  344|       |    // files have also been observed with TK in place of the revision details.
  345|  4.05k|    if ((major == '8' || major == '9') && revision_tag != 'M' && revision_tag != 'J' && revision_tag != 'T') {
  ------------------
  |  Branch (345:10): [True: 291, False: 3.76k]
  |  Branch (345:26): [True: 158, False: 3.60k]
  |  Branch (345:43): [True: 45, False: 404]
  |  Branch (345:66): [True: 30, False: 15]
  |  Branch (345:89): [True: 16, False: 14]
  ------------------
  346|     16|        retval = READSTAT_ERROR_PARSE;
  347|     16|        goto cleanup;
  348|     16|    }
  349|  4.03k|    hinfo->minor_version = minor;
  350|  4.03k|    if (revision >= '0' && revision <= '9') {
  ------------------
  |  Branch (350:9): [True: 4.02k, False: 13]
  |  Branch (350:28): [True: 4.00k, False: 16]
  ------------------
  351|  4.00k|        hinfo->revision = revision - '0';
  352|  4.00k|    } else if (revision_tag == 'T' && revision == 'K') {
  ------------------
  |  Branch (352:16): [True: 17, False: 12]
  |  Branch (352:39): [True: 5, False: 12]
  ------------------
  353|       |        // files have been observed with TK in place of the revision details.
  354|      5|        hinfo->revision = 0;
  355|     24|    } else {
  356|     24|        retval = READSTAT_ERROR_PARSE;
  357|     24|        goto cleanup;
  358|     24|    }
  359|       |
  360|  4.01k|    if ((major == '8' || major == '9') && minor == 0 && hinfo->revision == 0) {
  ------------------
  |  Branch (360:10): [True: 269, False: 3.74k]
  |  Branch (360:26): [True: 155, False: 3.59k]
  |  Branch (360:43): [True: 120, False: 304]
  |  Branch (360:57): [True: 83, False: 37]
  ------------------
  361|       |        /* A bit of a hack, but most SAS installations are running a minor update */
  362|     83|        hinfo->vendor = READSTAT_VENDOR_STAT_TRANSFER;
  363|  3.93k|    } else {
  364|  3.93k|        hinfo->vendor = READSTAT_VENDOR_SAS;
  365|  3.93k|    }
  366|  4.01k|    if (io->seek(hinfo->header_size, READSTAT_SEEK_SET, io->io_ctx) == -1) {
  ------------------
  |  Branch (366:9): [True: 51, False: 3.96k]
  ------------------
  367|     51|        retval = READSTAT_ERROR_SEEK;
  368|     51|        if (error_handler) {
  ------------------
  |  Branch (368:13): [True: 0, False: 51]
  ------------------
  369|      0|            snprintf(error_buf, sizeof(error_buf), 
  370|      0|                    "ReadStat: Failed to seek to position %" PRId64, hinfo->header_size);
  371|      0|            error_handler(error_buf, user_ctx);
  372|      0|        }
  373|     51|        goto cleanup;
  374|     51|    }
  375|       |
  376|  4.50k|cleanup:
  377|  4.50k|    return retval;
  378|  4.01k|}
sas_validate_tag:
  599|  4.93k|readstat_error_t sas_validate_tag(char tag) {
  600|  4.93k|    if (tag == '_' || (tag >= 'A' && tag <= 'Z'))
  ------------------
  |  Branch (600:9): [True: 2.30k, False: 2.62k]
  |  Branch (600:24): [True: 1.11k, False: 1.51k]
  |  Branch (600:38): [True: 862, False: 253]
  ------------------
  601|  3.16k|        return READSTAT_OK;
  602|       |
  603|  1.76k|    return READSTAT_ERROR_TAGGED_VALUE_IS_OUT_OF_RANGE;
  604|  4.93k|}
sas_assign_tag:
  639|  4.93k|void sas_assign_tag(readstat_value_t *value, uint8_t tag) {
  640|       |    /* We accommodate two tag schemes. In the first, the tag is an ASCII code
  641|       |     * given by uint8_t tag above. System missing is represented by an ASCII
  642|       |     * period. In the second scheme, (tag-2) is an offset from 'A', except when
  643|       |     * tag == 0, in which case it represents an underscore, or tag == 1, in
  644|       |     * which case it represents system-missing.
  645|       |     */
  646|  4.93k|    if (tag == 0) {
  ------------------
  |  Branch (646:9): [True: 2.30k, False: 2.62k]
  ------------------
  647|  2.30k|        tag = '_';
  648|  2.62k|    } else if (tag >= 2 && tag < 28) {
  ------------------
  |  Branch (648:16): [True: 2.27k, False: 351]
  |  Branch (648:28): [True: 824, False: 1.45k]
  ------------------
  649|    824|        tag = 'A' + (tag - 2);
  650|    824|    }
  651|  4.93k|    if (sas_validate_tag(tag) == READSTAT_OK) {
  ------------------
  |  Branch (651:9): [True: 3.16k, False: 1.76k]
  ------------------
  652|  3.16k|        value->tag = tag;
  653|  3.16k|        value->is_tagged_missing = 1;
  654|  3.16k|    } else {
  655|  1.76k|        value->tag = 0;
  656|  1.76k|        value->is_system_missing = 1;
  657|  1.76k|    }
  658|  4.93k|}
readstat_sas.c:sas_epoch:
  131|  4.50k|static time_t sas_epoch(void) {
  132|  4.50k|    return - 3653 * 86400; // seconds between 01-01-1960 and 01-01-1970
  133|  4.50k|}
readstat_sas.c:sas_convert_time:
  135|  8.58k|static time_t sas_convert_time(double time, double time_diff, time_t epoch) {
  136|  8.58k|    time -= time_diff;
  137|  8.58k|    time += epoch;
  138|  8.58k|    if (isnan(time))
  ------------------
  |  Branch (138:9): [True: 848, False: 7.74k]
  ------------------
  139|    848|        return 0;
  140|  7.74k|    if (time > (double)LONG_MAX)
  ------------------
  |  Branch (140:9): [True: 2.02k, False: 5.71k]
  ------------------
  141|  2.02k|        return LONG_MAX;
  142|  5.71k|    if (time < (double)LONG_MIN)
  ------------------
  |  Branch (142:9): [True: 1.23k, False: 4.48k]
  ------------------
  143|  1.23k|        return LONG_MIN;
  144|  4.48k|    return time;
  145|  5.71k|}

readstat_parse_sas7bdat:
 1422|  4.50k|readstat_error_t readstat_parse_sas7bdat(readstat_parser_t *parser, const char *path, void *user_ctx) {
 1423|  4.50k|    int64_t last_examined_page_pass1 = 0;
 1424|  4.50k|    readstat_error_t retval = READSTAT_OK;
 1425|  4.50k|    readstat_io_t *io = parser->io;
 1426|       |
 1427|  4.50k|    sas7bdat_ctx_t  *ctx = calloc(1, sizeof(sas7bdat_ctx_t));
 1428|  4.50k|    sas_header_info_t  *hinfo = calloc(1, sizeof(sas_header_info_t));
 1429|       |
 1430|  4.50k|    if (ctx == NULL || hinfo == NULL) {
  ------------------
  |  Branch (1430:9): [True: 0, False: 4.50k]
  |  Branch (1430:24): [True: 0, False: 4.50k]
  ------------------
 1431|      0|        retval = READSTAT_ERROR_MALLOC;
 1432|      0|        goto cleanup;
 1433|      0|    }
 1434|       |
 1435|  4.50k|    ctx->handle = parser->handlers;
 1436|  4.50k|    ctx->input_encoding = parser->input_encoding;
 1437|  4.50k|    ctx->output_encoding = parser->output_encoding;
 1438|  4.50k|    ctx->user_ctx = user_ctx;
 1439|  4.50k|    ctx->io = parser->io;
 1440|  4.50k|    ctx->row_limit = parser->row_limit;
 1441|  4.50k|    ctx->moved_page_index = -1;
 1442|  4.50k|    if (parser->row_offset > 0)
  ------------------
  |  Branch (1442:9): [True: 0, False: 4.50k]
  ------------------
 1443|      0|        ctx->row_offset = parser->row_offset;
 1444|       |
 1445|  4.50k|    if (io->open(path, io->io_ctx) == -1) {
  ------------------
  |  Branch (1445:9): [True: 0, False: 4.50k]
  ------------------
 1446|      0|        retval = READSTAT_ERROR_OPEN;
 1447|      0|        goto cleanup;
 1448|      0|    }
 1449|       |
 1450|  4.50k|    if ((ctx->file_size = io->seek(0, READSTAT_SEEK_END, io->io_ctx)) == -1) {
  ------------------
  |  Branch (1450:9): [True: 0, False: 4.50k]
  ------------------
 1451|      0|        retval = READSTAT_ERROR_SEEK;
 1452|      0|        if (ctx->handle.error) {
  ------------------
  |  Branch (1452:13): [True: 0, False: 0]
  ------------------
 1453|      0|            snprintf(ctx->error_buf, sizeof(ctx->error_buf), "ReadStat: Failed to seek to end of file");
 1454|      0|            ctx->handle.error(ctx->error_buf, ctx->user_ctx);
 1455|      0|        }
 1456|      0|        goto cleanup;
 1457|      0|    }
 1458|       |
 1459|  4.50k|    if (io->seek(0, READSTAT_SEEK_SET, io->io_ctx) == -1) {
  ------------------
  |  Branch (1459:9): [True: 0, False: 4.50k]
  ------------------
 1460|      0|        retval = READSTAT_ERROR_SEEK;
 1461|      0|        if (ctx->handle.error) {
  ------------------
  |  Branch (1461:13): [True: 0, False: 0]
  ------------------
 1462|      0|            snprintf(ctx->error_buf, sizeof(ctx->error_buf), "ReadStat: Failed to seek to beginning of file");
 1463|      0|            ctx->handle.error(ctx->error_buf, ctx->user_ctx);
 1464|      0|        }
 1465|      0|        goto cleanup;
 1466|      0|    }
 1467|       |
 1468|  4.50k|    if ((retval = sas_read_header(io, hinfo, ctx->handle.error, user_ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1468:9): [True: 542, False: 3.96k]
  ------------------
 1469|    542|        goto cleanup;
 1470|    542|    }
 1471|       |
 1472|  3.96k|    ctx->u64 = hinfo->u64;
 1473|  3.96k|    ctx->little_endian = hinfo->little_endian;
 1474|  3.96k|    ctx->vendor = hinfo->vendor;
 1475|  3.96k|    ctx->bswap = machine_is_little_endian() ^ hinfo->little_endian;
 1476|  3.96k|    ctx->header_size = hinfo->header_size;
 1477|  3.96k|    ctx->page_count = hinfo->page_count;
 1478|  3.96k|    ctx->page_size = hinfo->page_size;
 1479|  3.96k|    ctx->page_header_size = hinfo->page_header_size;
 1480|  3.96k|    ctx->subheader_pointer_size = hinfo->subheader_pointer_size;
 1481|  3.96k|    ctx->subheader_signature_size = ctx->u64 ? 8 : 4;
  ------------------
  |  Branch (1481:37): [True: 2.30k, False: 1.65k]
  ------------------
 1482|  3.96k|    ctx->ctime = hinfo->creation_time;
 1483|  3.96k|    ctx->mtime = hinfo->modification_time;
 1484|  3.96k|    ctx->version = hinfo->major_version;
 1485|  3.96k|    if (ctx->input_encoding == NULL) {
  ------------------
  |  Branch (1485:9): [True: 3.96k, False: 0]
  ------------------
 1486|  3.96k|        ctx->input_encoding = hinfo->encoding;
 1487|  3.96k|    }
 1488|  3.96k|    if ((ctx->page = readstat_malloc(ctx->page_size)) == NULL) {
  ------------------
  |  Branch (1488:9): [True: 0, False: 3.96k]
  ------------------
 1489|      0|        retval = READSTAT_ERROR_MALLOC;
 1490|      0|        goto cleanup;
 1491|      0|    }
 1492|       |
 1493|  3.96k|    const char *input_encoding = ctx->input_encoding;
 1494|  3.96k|    if (input_encoding == NULL) {
  ------------------
  |  Branch (1494:9): [True: 2.20k, False: 1.75k]
  ------------------
 1495|  2.20k|        input_encoding = SAS_DEFAULT_STRING_ENCODING;
  ------------------
  |  |  142|  2.20k|#define SAS_DEFAULT_STRING_ENCODING "WINDOWS-1252"
  ------------------
 1496|  2.20k|    }
 1497|  3.96k|    if (ctx->output_encoding && strcmp(input_encoding, ctx->output_encoding) != 0) {
  ------------------
  |  Branch (1497:9): [True: 3.96k, False: 0]
  |  Branch (1497:33): [True: 2.66k, False: 1.30k]
  ------------------
 1498|  2.66k|        iconv_t converter = iconv_open(ctx->output_encoding, input_encoding);
 1499|  2.66k|        if (converter == (iconv_t)-1) {
  ------------------
  |  Branch (1499:13): [True: 1, False: 2.66k]
  ------------------
 1500|      1|            retval = READSTAT_ERROR_UNSUPPORTED_CHARSET;
 1501|      1|            goto cleanup;
 1502|      1|        }
 1503|  2.66k|        ctx->converter = converter;
 1504|  2.66k|    }
 1505|       |
 1506|  3.96k|    if ((retval = readstat_convert(ctx->table_name, sizeof(ctx->table_name),
  ------------------
  |  Branch (1506:9): [True: 2, False: 3.96k]
  ------------------
 1507|  3.96k|                hinfo->table_name, sizeof(hinfo->table_name), ctx->converter)) != READSTAT_OK) {
 1508|      2|        goto cleanup;
 1509|      2|    }
 1510|       |
 1511|  3.96k|    if ((retval = sas7bdat_parse_meta_pages_pass1(ctx, &last_examined_page_pass1)) != READSTAT_OK) {
  ------------------
  |  Branch (1511:9): [True: 233, False: 3.72k]
  ------------------
 1512|    233|        goto cleanup;
 1513|    233|    }
 1514|       |
 1515|  3.72k|    if ((retval = sas7bdat_parse_amd_pages_pass1(last_examined_page_pass1, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1515:9): [True: 1.20k, False: 2.51k]
  ------------------
 1516|  1.20k|        goto cleanup;
 1517|  1.20k|    }
 1518|       |
 1519|  2.51k|    if (io->seek(ctx->header_size, READSTAT_SEEK_SET, io->io_ctx) == -1) {
  ------------------
  |  Branch (1519:9): [True: 0, False: 2.51k]
  ------------------
 1520|      0|        retval = READSTAT_ERROR_SEEK;
 1521|      0|        if (ctx->handle.error) {
  ------------------
  |  Branch (1521:13): [True: 0, False: 0]
  ------------------
 1522|      0|            snprintf(ctx->error_buf, sizeof(ctx->error_buf), "ReadStat: Failed to seek to position %" PRId64, 
 1523|      0|                    ctx->header_size);
 1524|      0|            ctx->handle.error(ctx->error_buf, ctx->user_ctx);
 1525|      0|        }
 1526|      0|        goto cleanup;
 1527|      0|    }
 1528|       |
 1529|  2.51k|    if ((retval = sas7bdat_parse_all_pages_pass2(ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1529:9): [True: 2.20k, False: 315]
  ------------------
 1530|  2.20k|        goto cleanup;
 1531|  2.20k|    }
 1532|       |    
 1533|    315|    if ((retval = sas7bdat_submit_columns_if_needed(ctx, 0)) != READSTAT_OK) {
  ------------------
  |  Branch (1533:9): [True: 79, False: 236]
  ------------------
 1534|     79|        goto cleanup;
 1535|     79|    }
 1536|       |
 1537|    236|    if (ctx->handle.value && ctx->parsed_row_count != ctx->row_limit) {
  ------------------
  |  Branch (1537:9): [True: 236, False: 0]
  |  Branch (1537:30): [True: 115, False: 121]
  ------------------
 1538|    115|        retval = READSTAT_ERROR_ROW_COUNT_MISMATCH;
 1539|    115|        if (ctx->handle.error) {
  ------------------
  |  Branch (1539:13): [True: 0, False: 115]
  ------------------
 1540|      0|            snprintf(ctx->error_buf, sizeof(ctx->error_buf), "ReadStat: Expected %d rows in file, found %d",
 1541|      0|                    ctx->row_limit, ctx->parsed_row_count);
 1542|      0|            ctx->handle.error(ctx->error_buf, ctx->user_ctx);
 1543|      0|        }
 1544|    115|        goto cleanup;
 1545|    115|    }
 1546|       |
 1547|    121|    if ((retval = sas7bdat_update_progress(ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1547:9): [True: 0, False: 121]
  ------------------
 1548|      0|        goto cleanup;
 1549|      0|    }
 1550|       |
 1551|  4.50k|cleanup:
 1552|  4.50k|    io->close(io->io_ctx);
 1553|       |
 1554|  4.50k|    if (retval == READSTAT_ERROR_OPEN ||
  ------------------
  |  Branch (1554:9): [True: 0, False: 4.50k]
  ------------------
 1555|  4.50k|            retval == READSTAT_ERROR_READ ||
  ------------------
  |  Branch (1555:13): [True: 622, False: 3.88k]
  ------------------
 1556|  3.88k|            retval == READSTAT_ERROR_SEEK) {
  ------------------
  |  Branch (1556:13): [True: 767, False: 3.11k]
  ------------------
 1557|  1.38k|        if (ctx->handle.error) {
  ------------------
  |  Branch (1557:13): [True: 0, False: 1.38k]
  ------------------
 1558|      0|            snprintf(ctx->error_buf, sizeof(ctx->error_buf), "ReadStat: %s (retval = %d): %s (errno = %d)", 
 1559|      0|                    readstat_error_message(retval), retval, strerror(errno), errno);
 1560|      0|            ctx->handle.error(ctx->error_buf, user_ctx);
 1561|      0|        }
 1562|  1.38k|    }
 1563|       |
 1564|  4.50k|    if (ctx)
  ------------------
  |  Branch (1564:9): [True: 4.50k, False: 0]
  ------------------
 1565|  4.50k|        sas7bdat_ctx_free(ctx);
 1566|  4.50k|    if (hinfo)
  ------------------
  |  Branch (1566:9): [True: 4.50k, False: 0]
  ------------------
 1567|  4.50k|        free(hinfo);
 1568|       |
 1569|  4.50k|    return retval;
 1570|    121|}
readstat_sas7bdat_read.c:sas7bdat_parse_meta_pages_pass1:
 1263|  3.96k|static readstat_error_t sas7bdat_parse_meta_pages_pass1(sas7bdat_ctx_t *ctx, int64_t *outLastExaminedPage) {
 1264|  3.96k|    readstat_error_t retval = READSTAT_OK;
 1265|  3.96k|    readstat_io_t *io = ctx->io;
 1266|  3.96k|    int64_t i;
 1267|       |
 1268|       |    /* look for META and MIX pages at beginning... */
 1269|  10.6k|    for (i=0; i<ctx->page_count; i++) {
  ------------------
  |  Branch (1269:15): [True: 7.84k, False: 2.80k]
  ------------------
 1270|  7.84k|        if (io->seek(ctx->header_size + i*ctx->page_size, READSTAT_SEEK_SET, io->io_ctx) == -1) {
  ------------------
  |  Branch (1270:13): [True: 9, False: 7.83k]
  ------------------
 1271|      9|            retval = READSTAT_ERROR_SEEK;
 1272|      9|            if (ctx->handle.error) {
  ------------------
  |  Branch (1272:17): [True: 0, False: 9]
  ------------------
 1273|      0|                snprintf(ctx->error_buf, sizeof(ctx->error_buf), "ReadStat: Failed to seek to position %" PRId64 
 1274|      0|                        " (= %" PRId64 " + %" PRId64 "*%" PRId64 ")",
 1275|      0|                        ctx->header_size + i*ctx->page_size, ctx->header_size, i, ctx->page_size);
 1276|      0|                ctx->handle.error(ctx->error_buf, ctx->user_ctx);
 1277|      0|            }
 1278|      9|            goto cleanup;
 1279|      9|        }
 1280|       |
 1281|  7.83k|        readstat_off_t off = 0;
 1282|  7.83k|        if (ctx->u64)
  ------------------
  |  Branch (1282:13): [True: 5.60k, False: 2.23k]
  ------------------
 1283|  5.60k|            off = 16;
 1284|       |
 1285|  7.83k|        size_t head_len = off + 16 + 2;
 1286|  7.83k|        size_t tail_len = ctx->page_size - head_len;
 1287|       |
 1288|  7.83k|        if (io->read(ctx->page, head_len, io->io_ctx) < head_len) {
  ------------------
  |  Branch (1288:13): [True: 149, False: 7.68k]
  ------------------
 1289|    149|            retval = READSTAT_ERROR_READ;
 1290|    149|            goto cleanup;
 1291|    149|        }
 1292|       |
 1293|  7.68k|        uint16_t page_type = sas_read2(&ctx->page[off+16], ctx->bswap);
 1294|       |
 1295|  7.68k|        if ((page_type & SAS_PAGE_TYPE_MASK) == SAS_PAGE_TYPE_DATA)
  ------------------
  |  |  113|  7.68k|#define SAS_PAGE_TYPE_MASK   0x0F00
  ------------------
                      if ((page_type & SAS_PAGE_TYPE_MASK) == SAS_PAGE_TYPE_DATA)
  ------------------
  |  |  110|  7.68k|#define SAS_PAGE_TYPE_DATA   0x0100
  ------------------
  |  Branch (1295:13): [True: 922, False: 6.76k]
  ------------------
 1296|    922|            break;
 1297|  6.76k|        if ((page_type & SAS_PAGE_TYPE_COMP))
  ------------------
  |  |  118|  6.76k|#define SAS_PAGE_TYPE_COMP          0x9000
  ------------------
  |  Branch (1297:13): [True: 1.24k, False: 5.51k]
  ------------------
 1298|  1.24k|            continue;
 1299|       |
 1300|  5.51k|        if (io->read(ctx->page + head_len, tail_len, io->io_ctx) < tail_len) {
  ------------------
  |  Branch (1300:13): [True: 26, False: 5.49k]
  ------------------
 1301|     26|            retval = READSTAT_ERROR_READ;
 1302|     26|            goto cleanup;
 1303|     26|        }
 1304|       |
 1305|  5.49k|        if ((retval = sas7bdat_parse_page_pass1(ctx->page, ctx->page_size, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1305:13): [True: 49, False: 5.44k]
  ------------------
 1306|     49|            if (ctx->handle.error && retval != READSTAT_ERROR_USER_ABORT) {
  ------------------
  |  Branch (1306:17): [True: 0, False: 49]
  |  Branch (1306:38): [True: 0, False: 0]
  ------------------
 1307|      0|                int64_t pos = io->seek(0, READSTAT_SEEK_CUR, io->io_ctx);
 1308|      0|                snprintf(ctx->error_buf, sizeof(ctx->error_buf), 
 1309|      0|                        "ReadStat: Error parsing page %" PRId64 ", bytes %" PRId64 "-%" PRId64, 
 1310|      0|                        i, pos - ctx->page_size, pos-1);
 1311|      0|                ctx->handle.error(ctx->error_buf, ctx->user_ctx);
 1312|      0|            }
 1313|     49|            goto cleanup;
 1314|     49|        }
 1315|  5.49k|    }
 1316|       |
 1317|  3.96k|cleanup:
 1318|  3.96k|    if (outLastExaminedPage)
  ------------------
  |  Branch (1318:9): [True: 3.96k, False: 0]
  ------------------
 1319|  3.96k|        *outLastExaminedPage = i;
 1320|       |
 1321|  3.96k|    return retval;
 1322|  3.96k|}
readstat_sas7bdat_read.c:sas7bdat_parse_page_pass1:
  965|  8.53k|static readstat_error_t sas7bdat_parse_page_pass1(const char *page, size_t page_size, sas7bdat_ctx_t *ctx) {
  966|  8.53k|    readstat_error_t retval = READSTAT_OK;
  967|       |
  968|  8.53k|    uint16_t subheader_count = sas_read2(&page[ctx->page_header_size-4], ctx->bswap);
  969|       |
  970|  8.53k|    int i;
  971|  8.53k|    const char *shp = &page[ctx->page_header_size];
  972|  8.53k|    int lshp = ctx->subheader_pointer_size;
  973|       |
  974|  8.53k|    if (ctx->page_header_size + subheader_count*lshp > page_size) {
  ------------------
  |  Branch (974:9): [True: 34, False: 8.50k]
  ------------------
  975|     34|        retval = READSTAT_ERROR_PARSE;
  976|     34|        goto cleanup;
  977|     34|    }
  978|       |
  979|  94.8k|    for (i=0; i<subheader_count; i++) {
  ------------------
  |  Branch (979:15): [True: 86.9k, False: 7.82k]
  ------------------
  980|  86.9k|        subheader_pointer_t shp_info = { 0 };
  981|  86.9k|        if ((retval = sas7bdat_parse_subheader_pointer(shp, page + page_size - shp, &shp_info, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (981:13): [True: 0, False: 86.9k]
  ------------------
  982|      0|            goto cleanup;
  983|      0|        }
  984|  86.9k|        if (shp_info.len > 0 && shp_info.compression != SAS_COMPRESSION_TRUNC && shp_info.compression != SAS_COMPRESSION_REFERENCE) {
  ------------------
  |  |  127|   144k|#define SAS_COMPRESSION_TRUNC              0x01
  ------------------
                      if (shp_info.len > 0 && shp_info.compression != SAS_COMPRESSION_TRUNC && shp_info.compression != SAS_COMPRESSION_REFERENCE) {
  ------------------
  |  |  129|  50.1k|#define SAS_COMPRESSION_REFERENCE          0x03
  ------------------
  |  Branch (984:13): [True: 57.2k, False: 29.7k]
  |  Branch (984:33): [True: 50.1k, False: 7.05k]
  |  Branch (984:82): [True: 48.3k, False: 1.82k]
  ------------------
  985|  48.3k|            if ((retval = sas7bdat_validate_subheader_pointer(&shp_info, page_size, subheader_count, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (985:17): [True: 593, False: 47.7k]
  ------------------
  986|    593|                goto cleanup;
  987|    593|            }
  988|  47.7k|            if (shp_info.compression == SAS_COMPRESSION_NONE) {
  ------------------
  |  |  126|  47.7k|#define SAS_COMPRESSION_NONE               0x00
  ------------------
  |  Branch (988:17): [True: 38.4k, False: 9.27k]
  ------------------
  989|  38.4k|                sas_subheader_type_t subheader_type = sas7bdat_parse_subheader_type(page + shp_info.offset, ctx);
  990|  38.4k|                if (subheader_type == SAS_SUBHEADER_TYPE_COLUMN_TEXT) {
  ------------------
  |  Branch (990:21): [True: 6.20k, False: 32.2k]
  ------------------
  991|  6.20k|                    if ((retval = sas7bdat_parse_subheader(subheader_type, page + shp_info.offset, shp_info.len, ctx))
  ------------------
  |  Branch (991:25): [True: 54, False: 6.15k]
  ------------------
  992|  6.20k|                            != READSTAT_OK) {
  993|     54|                        goto cleanup;
  994|     54|                    }
  995|  6.20k|                }
  996|  38.4k|            } else if (shp_info.compression == SAS_COMPRESSION_ROW || shp_info.compression == SAS_COMPRESSION_DELETED_ROW
  ------------------
  |  |  130|  18.5k|#define SAS_COMPRESSION_ROW                0x04
  ------------------
                          } else if (shp_info.compression == SAS_COMPRESSION_ROW || shp_info.compression == SAS_COMPRESSION_DELETED_ROW
  ------------------
  |  |  131|  13.0k|#define SAS_COMPRESSION_DELETED_ROW        0x05
  ------------------
  |  Branch (996:24): [True: 5.47k, False: 3.79k]
  |  Branch (996:71): [True: 744, False: 3.05k]
  ------------------
  997|  9.24k|                    || sas7bdat_is_moved_row(shp_info.compression)) {
  ------------------
  |  Branch (997:24): [True: 3.02k, False: 32]
  ------------------
  998|       |                /* void */
  999|  9.24k|            } else {
 1000|     32|                retval = READSTAT_ERROR_UNSUPPORTED_COMPRESSION;
 1001|     32|                goto cleanup;
 1002|     32|            }
 1003|  47.7k|        }
 1004|       |
 1005|  86.3k|        shp += lshp;
 1006|  86.3k|    }
 1007|       |
 1008|  8.53k|cleanup:
 1009|       |
 1010|  8.53k|    return retval;
 1011|  8.50k|}
readstat_sas7bdat_read.c:sas7bdat_parse_subheader_pointer:
  912|   140k|        subheader_pointer_t *info, sas7bdat_ctx_t *ctx) {
  913|   140k|    readstat_error_t retval = READSTAT_OK;
  914|   140k|    if (ctx->u64) {
  ------------------
  |  Branch (914:9): [True: 44.7k, False: 95.2k]
  ------------------
  915|  44.7k|        if (shp_size <= 17) {
  ------------------
  |  Branch (915:13): [True: 0, False: 44.7k]
  ------------------
  916|      0|            retval = READSTAT_ERROR_PARSE;
  917|      0|            goto cleanup;
  918|      0|        }
  919|  44.7k|        info->offset = sas_read8(&shp[0], ctx->bswap);
  920|  44.7k|        info->len = sas_read8(&shp[8], ctx->bswap);
  921|  44.7k|        info->compression = shp[16];
  922|  44.7k|        info->is_compressed_data = shp[17];
  923|  95.2k|    } else {
  924|  95.2k|        if (shp_size <= 9) {
  ------------------
  |  Branch (924:13): [True: 0, False: 95.2k]
  ------------------
  925|      0|            retval = READSTAT_ERROR_PARSE;
  926|      0|            goto cleanup;
  927|      0|        }
  928|  95.2k|        info->offset = sas_read4(&shp[0], ctx->bswap);
  929|  95.2k|        info->len = sas_read4(&shp[4], ctx->bswap);
  930|  95.2k|        info->compression = shp[8];
  931|  95.2k|        info->is_compressed_data = shp[9];
  932|  95.2k|    }
  933|   140k|cleanup:
  934|   140k|    return retval;
  935|   140k|}
readstat_sas7bdat_read.c:sas7bdat_validate_subheader_pointer:
  938|  77.1k|        uint16_t subheader_count, sas7bdat_ctx_t *ctx) {
  939|  77.1k|    if (shp_info->offset > page_size)
  ------------------
  |  Branch (939:9): [True: 533, False: 76.6k]
  ------------------
  940|    533|        return READSTAT_ERROR_PARSE;
  941|  76.6k|    if (shp_info->len > page_size)
  ------------------
  |  Branch (941:9): [True: 406, False: 76.2k]
  ------------------
  942|    406|        return READSTAT_ERROR_PARSE;
  943|  76.2k|    if (shp_info->offset + shp_info->len > page_size)
  ------------------
  |  Branch (943:9): [True: 52, False: 76.2k]
  ------------------
  944|     52|        return READSTAT_ERROR_PARSE;
  945|  76.2k|    if (shp_info->offset < ctx->page_header_size + subheader_count*ctx->subheader_pointer_size)
  ------------------
  |  Branch (945:9): [True: 35, False: 76.1k]
  ------------------
  946|     35|        return READSTAT_ERROR_PARSE;
  947|  76.1k|    if (shp_info->compression == SAS_COMPRESSION_NONE || shp_info->compression == SAS_COMPRESSION_NONE_MOVED) {
  ------------------
  |  |  126|   152k|#define SAS_COMPRESSION_NONE               0x00
  ------------------
                  if (shp_info->compression == SAS_COMPRESSION_NONE || shp_info->compression == SAS_COMPRESSION_NONE_MOVED) {
  ------------------
  |  |  128|  14.2k|#define SAS_COMPRESSION_NONE_MOVED         0x02
  ------------------
  |  Branch (947:9): [True: 61.9k, False: 14.2k]
  |  Branch (947:58): [True: 1.22k, False: 13.0k]
  ------------------
  948|  63.1k|        if (shp_info->len < ctx->subheader_signature_size)
  ------------------
  |  Branch (948:13): [True: 10, False: 63.1k]
  ------------------
  949|     10|            return READSTAT_ERROR_PARSE;
  950|  63.1k|        if (shp_info->offset + ctx->subheader_signature_size > page_size)
  ------------------
  |  Branch (950:13): [True: 0, False: 63.1k]
  ------------------
  951|      0|            return READSTAT_ERROR_PARSE;
  952|  63.1k|    }
  953|       |    
  954|  76.1k|    return READSTAT_OK;
  955|  76.1k|}
readstat_sas7bdat_read.c:sas7bdat_parse_subheader_type:
  876|  61.9k|static sas_subheader_type_t sas7bdat_parse_subheader_type(const char* subheader, sas7bdat_ctx_t* ctx) {
  877|  61.9k|    if (!ctx->u64) {
  ------------------
  |  Branch (877:9): [True: 35.8k, False: 26.0k]
  ------------------
  878|  35.8k|        uint32_t signature_32 = sas_read4(subheader, ctx->bswap);
  879|  35.8k|        return sas7bdat_parse_subheader_type_32(signature_32);
  880|  35.8k|    }
  881|       |
  882|  26.0k|    if (!ctx->little_endian) {
  ------------------
  |  Branch (882:9): [True: 23.3k, False: 2.73k]
  ------------------
  883|       |        /* Big-endian 64-bit files lay out signatures differently from
  884|       |         * little-endian ones: ROW_SIZE and COLUMN_SIZE occupy only the first
  885|       |         * four bytes (the remaining four are unspecified), while the 0xFFFF...
  886|       |         * family is written as 0xFFFFFFFF followed by the 32-bit signature. */
  887|  23.3k|        uint32_t signature_32 = sas_read4(subheader, ctx->bswap);
  888|  23.3k|        if (signature_32 == SAS_SUBHEADER_SIGNATURE_ROW_SIZE) {
  ------------------
  |  |   93|  23.3k|#define SAS_SUBHEADER_SIGNATURE_ROW_SIZE       0xF7F7F7F7
  ------------------
  |  Branch (888:13): [True: 1.02k, False: 22.2k]
  ------------------
  889|  1.02k|            return SAS_SUBHEADER_TYPE_ROW_SIZE;
  890|  22.2k|        } else if (signature_32 == SAS_SUBHEADER_SIGNATURE_COLUMN_SIZE) {
  ------------------
  |  |   94|  22.2k|#define SAS_SUBHEADER_SIGNATURE_COLUMN_SIZE    0xF6F6F6F6
  ------------------
  |  Branch (890:20): [True: 297, False: 21.9k]
  ------------------
  891|    297|            return SAS_SUBHEADER_TYPE_COLUMN_SIZE;
  892|  21.9k|        } else if (signature_32 != SAS_SUBHEADER_SIGNATURE_COLUMN_NAME) {
  ------------------
  |  |  104|  21.9k|#define SAS_SUBHEADER_SIGNATURE_COLUMN_NAME    0xFFFFFFFF
  ------------------
  |  Branch (892:20): [True: 1.14k, False: 20.8k]
  ------------------
  893|  1.14k|            return SAS_SUBHEADER_TYPE_DATA;
  894|  1.14k|        }
  895|  20.8k|        return sas7bdat_parse_subheader_type_32(sas_read4(&subheader[4], ctx->bswap));
  896|  23.3k|    }
  897|       |
  898|  2.73k|    uint64_t signature = sas_read8(subheader, ctx->bswap);
  899|  2.73k|    if (signature == SAS_SUBHEADER_SIGNATURE_ROW_SIZE) {
  ------------------
  |  |   93|  2.73k|#define SAS_SUBHEADER_SIGNATURE_ROW_SIZE       0xF7F7F7F7
  ------------------
  |  Branch (899:9): [True: 185, False: 2.54k]
  ------------------
  900|    185|        return SAS_SUBHEADER_TYPE_ROW_SIZE;
  901|  2.54k|    } else if (signature == SAS_SUBHEADER_SIGNATURE_COLUMN_SIZE) {
  ------------------
  |  |   94|  2.54k|#define SAS_SUBHEADER_SIGNATURE_COLUMN_SIZE    0xF6F6F6F6
  ------------------
  |  Branch (901:16): [True: 184, False: 2.36k]
  ------------------
  902|    184|        return SAS_SUBHEADER_TYPE_COLUMN_SIZE;
  903|  2.36k|    } else if ((signature & SAS_SUBHEADER_SIGNATURE_64BIT_MASK) != SAS_SUBHEADER_SIGNATURE_64BIT_MASK) {
  ------------------
  |  |  106|  2.36k|#define SAS_SUBHEADER_SIGNATURE_64BIT_MASK     0xFFFFFFFF00000000
  ------------------
                  } else if ((signature & SAS_SUBHEADER_SIGNATURE_64BIT_MASK) != SAS_SUBHEADER_SIGNATURE_64BIT_MASK) {
  ------------------
  |  |  106|  2.36k|#define SAS_SUBHEADER_SIGNATURE_64BIT_MASK     0xFFFFFFFF00000000
  ------------------
  |  Branch (903:16): [True: 594, False: 1.77k]
  ------------------
  904|    594|        return SAS_SUBHEADER_TYPE_DATA;
  905|    594|    }
  906|       |
  907|  1.77k|    uint32_t lower_bytes = (uint32_t)(signature & SAS_SUBHEADER_SIGNATURE_32BIT_MASK);
  ------------------
  |  |  107|  1.77k|#define SAS_SUBHEADER_SIGNATURE_32BIT_MASK     0x00000000FFFFFFFF
  ------------------
  908|  1.77k|    return sas7bdat_parse_subheader_type_32(lower_bytes);
  909|  2.73k|}
readstat_sas7bdat_read.c:sas7bdat_parse_subheader_type_32:
  850|  58.5k|static sas_subheader_type_t sas7bdat_parse_subheader_type_32(uint32_t signature) {
  851|  58.5k|    switch (signature) {
  852|  6.65k|        case SAS_SUBHEADER_SIGNATURE_ROW_SIZE:
  ------------------
  |  |   93|  6.65k|#define SAS_SUBHEADER_SIGNATURE_ROW_SIZE       0xF7F7F7F7
  ------------------
  |  Branch (852:9): [True: 6.65k, False: 51.8k]
  ------------------
  853|  6.65k|            return SAS_SUBHEADER_TYPE_ROW_SIZE;
  854|  3.76k|        case SAS_SUBHEADER_SIGNATURE_COLUMN_SIZE:
  ------------------
  |  |   94|  3.76k|#define SAS_SUBHEADER_SIGNATURE_COLUMN_SIZE    0xF6F6F6F6
  ------------------
  |  Branch (854:9): [True: 3.76k, False: 54.7k]
  ------------------
  855|  3.76k|            return SAS_SUBHEADER_TYPE_COLUMN_SIZE;
  856|  5.18k|        case SAS_SUBHEADER_SIGNATURE_COUNTS:
  ------------------
  |  |   95|  5.18k|#define SAS_SUBHEADER_SIGNATURE_COUNTS         0xFFFFFC00
  ------------------
  |  Branch (856:9): [True: 5.18k, False: 53.3k]
  ------------------
  857|  5.18k|            return SAS_SUBHEADER_TYPE_COUNTS;
  858|  10.5k|        case SAS_SUBHEADER_SIGNATURE_COLUMN_FORMAT:
  ------------------
  |  |   96|  10.5k|#define SAS_SUBHEADER_SIGNATURE_COLUMN_FORMAT  0xFFFFFBFE
  ------------------
  |  Branch (858:9): [True: 10.5k, False: 47.9k]
  ------------------
  859|  10.5k|            return SAS_SUBHEADER_TYPE_COLUMN_FORMAT;
  860|  4.99k|        case SAS_SUBHEADER_SIGNATURE_COLUMN_ATTRS:
  ------------------
  |  |  101|  4.99k|#define SAS_SUBHEADER_SIGNATURE_COLUMN_ATTRS   0xFFFFFFFC
  ------------------
  |  Branch (860:9): [True: 4.99k, False: 53.5k]
  ------------------
  861|  4.99k|            return SAS_SUBHEADER_TYPE_COLUMN_ATTRS;
  862|  10.9k|        case SAS_SUBHEADER_SIGNATURE_COLUMN_TEXT:
  ------------------
  |  |  102|  10.9k|#define SAS_SUBHEADER_SIGNATURE_COLUMN_TEXT    0xFFFFFFFD
  ------------------
  |  Branch (862:9): [True: 10.9k, False: 47.5k]
  ------------------
  863|  10.9k|            return SAS_SUBHEADER_TYPE_COLUMN_TEXT;
  864|  2.05k|        case SAS_SUBHEADER_SIGNATURE_COLUMN_LIST:
  ------------------
  |  |  103|  2.05k|#define SAS_SUBHEADER_SIGNATURE_COLUMN_LIST    0xFFFFFFFE
  ------------------
  |  Branch (864:9): [True: 2.05k, False: 56.4k]
  ------------------
  865|  2.05k|            return SAS_SUBHEADER_TYPE_COLUMN_LIST;
  866|  8.96k|        case SAS_SUBHEADER_SIGNATURE_COLUMN_NAME:
  ------------------
  |  |  104|  8.96k|#define SAS_SUBHEADER_SIGNATURE_COLUMN_NAME    0xFFFFFFFF
  ------------------
  |  Branch (866:9): [True: 8.96k, False: 49.5k]
  ------------------
  867|  8.96k|            return SAS_SUBHEADER_TYPE_COLUMN_NAME;
  868|  5.38k|        default:
  ------------------
  |  Branch (868:9): [True: 5.38k, False: 53.1k]
  ------------------
  869|  5.38k|            if ((signature & SAS_SUBHEADER_SIGNATURE_COLUMN_MASK) == SAS_SUBHEADER_SIGNATURE_COLUMN_MASK) {
  ------------------
  |  |   98|  5.38k|#define SAS_SUBHEADER_SIGNATURE_COLUMN_MASK    0xFFFFFFF8
  ------------------
                          if ((signature & SAS_SUBHEADER_SIGNATURE_COLUMN_MASK) == SAS_SUBHEADER_SIGNATURE_COLUMN_MASK) {
  ------------------
  |  |   98|  5.38k|#define SAS_SUBHEADER_SIGNATURE_COLUMN_MASK    0xFFFFFFF8
  ------------------
  |  Branch (869:17): [True: 2.04k, False: 3.34k]
  ------------------
  870|  2.04k|                return SAS_SUBHEADER_TYPE_UNKNOWN;
  871|  2.04k|            }
  872|  3.34k|            return SAS_SUBHEADER_TYPE_DATA;
  873|  58.5k|    }
  874|  58.5k|}
readstat_sas7bdat_read.c:sas7bdat_parse_subheader:
  636|  24.4k|        size_t len, sas7bdat_ctx_t *ctx) {
  637|  24.4k|    readstat_error_t retval = READSTAT_OK;
  638|       |
  639|  24.4k|    if (len < 2 + ctx->subheader_signature_size) {
  ------------------
  |  Branch (639:9): [True: 5, False: 24.3k]
  ------------------
  640|      5|        retval = READSTAT_ERROR_PARSE;
  641|      5|        goto cleanup;
  642|      5|    }
  643|  24.3k|    if (subheader_type == SAS_SUBHEADER_TYPE_ROW_SIZE) {
  ------------------
  |  Branch (643:9): [True: 3.09k, False: 21.3k]
  ------------------
  644|  3.09k|        retval = sas7bdat_parse_row_size_subheader(subheader, len, ctx);
  645|  21.3k|    } else if (subheader_type == SAS_SUBHEADER_TYPE_COLUMN_SIZE) {
  ------------------
  |  Branch (645:16): [True: 1.53k, False: 19.7k]
  ------------------
  646|  1.53k|        retval = sas7bdat_parse_column_size_subheader(subheader, len, ctx);
  647|  19.7k|    } else if (subheader_type == SAS_SUBHEADER_TYPE_COUNTS) {
  ------------------
  |  Branch (647:16): [True: 2.39k, False: 17.3k]
  ------------------
  648|       |        /* void */
  649|  17.3k|    } else if (subheader_type == SAS_SUBHEADER_TYPE_COLUMN_TEXT) {
  ------------------
  |  Branch (649:16): [True: 6.20k, False: 11.1k]
  ------------------
  650|  6.20k|        retval = sas7bdat_parse_column_text_subheader(subheader, len, ctx);
  651|  11.1k|    } else if (subheader_type == SAS_SUBHEADER_TYPE_COLUMN_NAME) {
  ------------------
  |  Branch (651:16): [True: 3.18k, False: 7.98k]
  ------------------
  652|  3.18k|        retval = sas7bdat_parse_column_name_subheader(subheader, len, ctx);
  653|  7.98k|    } else if (subheader_type == SAS_SUBHEADER_TYPE_COLUMN_ATTRS) {
  ------------------
  |  Branch (653:16): [True: 1.93k, False: 6.04k]
  ------------------
  654|  1.93k|        retval = sas7bdat_parse_column_attributes_subheader(subheader, len, ctx);
  655|  6.04k|    } else if (subheader_type == SAS_SUBHEADER_TYPE_COLUMN_FORMAT) {
  ------------------
  |  Branch (655:16): [True: 4.48k, False: 1.56k]
  ------------------
  656|  4.48k|        retval = sas7bdat_parse_column_format_subheader(subheader, len, ctx);
  657|  4.48k|    } else if (subheader_type == SAS_SUBHEADER_TYPE_COLUMN_LIST) {
  ------------------
  |  Branch (657:16): [True: 736, False: 832]
  ------------------
  658|       |        /* void */
  659|    832|    } else if (subheader_type == SAS_SUBHEADER_TYPE_UNKNOWN) {
  ------------------
  |  Branch (659:16): [True: 796, False: 36]
  ------------------
  660|       |        /* void */
  661|    796|    } else {
  662|     36|        retval = READSTAT_ERROR_PARSE;
  663|     36|    }
  664|       |
  665|  24.4k|cleanup:
  666|       |
  667|  24.4k|    return retval;
  668|  24.3k|}
readstat_sas7bdat_read.c:sas7bdat_parse_row_size_subheader:
  246|  3.09k|static readstat_error_t sas7bdat_parse_row_size_subheader(const char *subheader, size_t len, sas7bdat_ctx_t *ctx) {
  247|  3.09k|    readstat_error_t retval = READSTAT_OK;
  248|  3.09k|    uint64_t total_row_count;
  249|  3.09k|    uint64_t row_length, deleted_row_count, page_row_count;
  250|       |
  251|  3.09k|    if (len < (ctx->u64 ? 250: 190)) {
  ------------------
  |  Branch (251:9): [True: 7, False: 3.09k]
  |  Branch (251:16): [True: 964, False: 2.13k]
  ------------------
  252|      7|        retval = READSTAT_ERROR_PARSE;
  253|      7|        goto cleanup;
  254|      7|    }
  255|       |
  256|  3.09k|    if (ctx->u64) {
  ------------------
  |  Branch (256:9): [True: 962, False: 2.12k]
  ------------------
  257|    962|        row_length = sas_read8(&subheader[40], ctx->bswap);
  258|    962|        total_row_count = sas_read8(&subheader[48], ctx->bswap);
  259|    962|        deleted_row_count = sas_read8(&subheader[56], ctx->bswap);
  260|    962|        page_row_count = sas_read8(&subheader[120], ctx->bswap);
  261|  2.12k|    } else {
  262|  2.12k|        row_length = sas_read4(&subheader[20], ctx->bswap);
  263|  2.12k|        total_row_count = sas_read4(&subheader[24], ctx->bswap);
  264|  2.12k|        deleted_row_count = sas_read4(&subheader[28], ctx->bswap);
  265|  2.12k|        page_row_count = sas_read4(&subheader[60], ctx->bswap);
  266|  2.12k|    }
  267|       |
  268|  3.09k|    if (deleted_row_count > total_row_count) {
  ------------------
  |  Branch (268:9): [True: 23, False: 3.06k]
  ------------------
  269|     23|        retval = READSTAT_ERROR_PARSE;
  270|     23|        goto cleanup;
  271|     23|    }
  272|  3.06k|    ctx->total_row_count = total_row_count;
  273|  3.06k|    ctx->deleted_row_count = deleted_row_count;
  274|       |
  275|  3.06k|    sas_text_ref_t file_label_ref = sas7bdat_parse_text_ref(&subheader[len-130], ctx);
  276|  3.06k|    if (file_label_ref.length) {
  ------------------
  |  Branch (276:9): [True: 677, False: 2.39k]
  ------------------
  277|    677|        if ((retval = sas7bdat_copy_text_ref(ctx->file_label, sizeof(ctx->file_label),
  ------------------
  |  Branch (277:13): [True: 40, False: 637]
  ------------------
  278|    677|                        file_label_ref, ctx)) != READSTAT_OK) {
  279|     40|            goto cleanup;
  280|     40|        }
  281|    677|    }
  282|       |
  283|  3.02k|    sas_text_ref_t compression_ref = sas7bdat_parse_text_ref(&subheader[len-118], ctx);
  284|  3.02k|    if (compression_ref.length) {
  ------------------
  |  Branch (284:9): [True: 1.03k, False: 1.99k]
  ------------------
  285|  1.03k|        char compression[9];
  286|  1.03k|        if ((retval = sas7bdat_copy_text_ref(compression, sizeof(compression),
  ------------------
  |  Branch (286:13): [True: 36, False: 997]
  ------------------
  287|  1.03k|                        compression_ref, ctx)) != READSTAT_OK) {
  288|     36|            goto cleanup;
  289|     36|        }
  290|    997|        ctx->rdc_compression = (memcmp(compression, SAS_COMPRESSION_SIGNATURE_RDC, 8) == 0);
  ------------------
  |  |  137|    997|#define SAS_COMPRESSION_SIGNATURE_RDC  "SASYZCR2"
  ------------------
  291|    997|    }
  292|       |
  293|  2.99k|    ctx->row_length = row_length;
  294|  2.99k|    ctx->row = readstat_realloc(ctx->row, ctx->row_length);
  295|  2.99k|    if (ctx->row == NULL) {
  ------------------
  |  Branch (295:9): [True: 8, False: 2.98k]
  ------------------
  296|      8|        retval = READSTAT_ERROR_MALLOC;
  297|      8|        goto cleanup;
  298|      8|    }
  299|       |
  300|  2.98k|    ctx->page_row_count = page_row_count;
  301|  2.98k|    uint64_t live_row_count = total_row_count - deleted_row_count;
  302|  2.98k|    uint64_t total_row_count_after_skipping = live_row_count;
  303|  2.98k|    if (live_row_count > ctx->row_offset) {
  ------------------
  |  Branch (303:9): [True: 2.62k, False: 360]
  ------------------
  304|  2.62k|        total_row_count_after_skipping -= ctx->row_offset;
  305|  2.62k|    } else {
  306|    360|        total_row_count_after_skipping = 0;
  307|    360|        ctx->row_offset = live_row_count;
  308|    360|    }
  309|  2.98k|    if (ctx->row_limit == 0 || total_row_count_after_skipping < ctx->row_limit)
  ------------------
  |  Branch (309:9): [True: 1.18k, False: 1.80k]
  |  Branch (309:32): [True: 89, False: 1.71k]
  ------------------
  310|  1.27k|        ctx->row_limit = total_row_count_after_skipping;
  311|       |
  312|  3.09k|cleanup:
  313|  3.09k|    return retval;
  314|  2.98k|}
readstat_sas7bdat_read.c:sas7bdat_parse_text_ref:
  147|  42.9k|static sas_text_ref_t sas7bdat_parse_text_ref(const char *data, sas7bdat_ctx_t *ctx) {
  148|  42.9k|    sas_text_ref_t  ref;
  149|       |
  150|  42.9k|    ref.index = sas_read2(&data[0], ctx->bswap);
  151|  42.9k|    ref.offset = sas_read2(&data[2], ctx->bswap);
  152|  42.9k|    ref.length = sas_read2(&data[4], ctx->bswap);
  153|       |
  154|  42.9k|    return ref;
  155|  42.9k|}
readstat_sas7bdat_read.c:sas7bdat_copy_text_ref:
  157|  13.0M|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) {
  158|  13.0M|    if (text_ref.index >= ctx->text_blob_count)
  ------------------
  |  Branch (158:9): [True: 127, False: 13.0M]
  ------------------
  159|    127|        return READSTAT_ERROR_PARSE;
  160|       |    
  161|  13.0M|    if (text_ref.length == 0) {
  ------------------
  |  Branch (161:9): [True: 13.0M, False: 4.82k]
  ------------------
  162|  13.0M|        out_buffer[0] = '\0';
  163|  13.0M|        return READSTAT_OK;
  164|  13.0M|    }
  165|       |
  166|  4.82k|    char *blob = ctx->text_blobs[text_ref.index];
  167|       |
  168|  4.82k|    if (text_ref.offset + text_ref.length > ctx->text_blob_lengths[text_ref.index])
  ------------------
  |  Branch (168:9): [True: 85, False: 4.73k]
  ------------------
  169|     85|        return READSTAT_ERROR_PARSE;
  170|       |
  171|  4.73k|    return readstat_convert(out_buffer, out_buffer_len, &blob[text_ref.offset], text_ref.length,
  172|  4.73k|            ctx->converter);
  173|  4.82k|}
readstat_sas7bdat_read.c:sas7bdat_parse_column_size_subheader:
  218|  1.53k|static readstat_error_t sas7bdat_parse_column_size_subheader(const char *subheader, size_t len, sas7bdat_ctx_t *ctx) {
  219|  1.53k|    uint64_t col_count;
  220|  1.53k|    readstat_error_t retval = READSTAT_OK;
  221|       |
  222|  1.53k|    if (ctx->column_count || ctx->did_submit_columns) {
  ------------------
  |  Branch (222:9): [True: 20, False: 1.51k]
  |  Branch (222:30): [True: 2, False: 1.51k]
  ------------------
  223|     22|        retval = READSTAT_ERROR_PARSE;
  224|     22|        goto cleanup;
  225|     22|    }
  226|       |
  227|  1.51k|    if (len < (ctx->u64 ? 16 : 8)) {
  ------------------
  |  Branch (227:9): [True: 3, False: 1.51k]
  |  Branch (227:16): [True: 517, False: 996]
  ------------------
  228|      3|        retval = READSTAT_ERROR_PARSE;
  229|      3|        goto cleanup;
  230|      3|    }
  231|       |
  232|  1.51k|    if (ctx->u64) {
  ------------------
  |  Branch (232:9): [True: 515, False: 995]
  ------------------
  233|    515|        col_count = sas_read8(&subheader[8], ctx->bswap);
  234|    995|    } else {
  235|    995|        col_count = sas_read4(&subheader[4], ctx->bswap);
  236|    995|    }
  237|       |
  238|  1.51k|    ctx->column_count = col_count;
  239|       |
  240|  1.51k|    retval = sas7bdat_realloc_col_info(ctx, ctx->column_count);
  241|       |
  242|  1.53k|cleanup:
  243|  1.53k|    return retval;
  244|  1.51k|}
readstat_sas7bdat_read.c:sas7bdat_realloc_col_info:
  205|  10.9k|static readstat_error_t sas7bdat_realloc_col_info(sas7bdat_ctx_t *ctx, size_t count) {
  206|  10.9k|    if (ctx->col_info_count < count) {
  ------------------
  |  Branch (206:9): [True: 3.86k, False: 7.12k]
  ------------------
  207|  3.86k|        size_t old_count = ctx->col_info_count;
  208|  3.86k|        ctx->col_info_count = count;
  209|  3.86k|        ctx->col_info = readstat_realloc(ctx->col_info, ctx->col_info_count * sizeof(col_info_t));
  210|  3.86k|        if (ctx->col_info == NULL) {
  ------------------
  |  Branch (210:13): [True: 84, False: 3.78k]
  ------------------
  211|     84|            return READSTAT_ERROR_MALLOC;
  212|     84|        }
  213|  3.78k|        memset(ctx->col_info + old_count, 0, (count - old_count) * sizeof(col_info_t));
  214|  3.78k|    }
  215|  10.9k|    return READSTAT_OK;
  216|  10.9k|}
readstat_sas7bdat_read.c:sas7bdat_parse_column_text_subheader:
  175|  6.20k|static readstat_error_t sas7bdat_parse_column_text_subheader(const char *subheader, size_t len, sas7bdat_ctx_t *ctx) {
  176|  6.20k|    readstat_error_t retval = READSTAT_OK;
  177|  6.20k|    size_t signature_len = ctx->subheader_signature_size;
  178|  6.20k|    uint16_t remainder = sas_read2(&subheader[signature_len], ctx->bswap);
  179|  6.20k|    char *blob = NULL;
  180|  6.20k|    if (remainder != sas_subheader_remainder(len, signature_len)) {
  ------------------
  |  Branch (180:9): [True: 53, False: 6.15k]
  ------------------
  181|     53|        retval = READSTAT_ERROR_PARSE;
  182|     53|        goto cleanup;
  183|     53|    }
  184|  6.15k|    ctx->text_blob_count++;
  185|  6.15k|    ctx->text_blobs = readstat_realloc(ctx->text_blobs, ctx->text_blob_count * sizeof(char *));
  186|  6.15k|    ctx->text_blob_lengths = readstat_realloc(ctx->text_blob_lengths,
  187|  6.15k|            ctx->text_blob_count * sizeof(ctx->text_blob_lengths[0]));
  188|  6.15k|    if (ctx->text_blobs == NULL || ctx->text_blob_lengths == NULL) {
  ------------------
  |  Branch (188:9): [True: 0, False: 6.15k]
  |  Branch (188:36): [True: 0, False: 6.15k]
  ------------------
  189|      0|        retval = READSTAT_ERROR_MALLOC;
  190|      0|        goto cleanup;
  191|      0|    }
  192|       |
  193|  6.15k|    if ((blob = readstat_malloc(len-signature_len)) == NULL) {
  ------------------
  |  Branch (193:9): [True: 0, False: 6.15k]
  ------------------
  194|      0|        retval = READSTAT_ERROR_MALLOC;
  195|      0|        goto cleanup;
  196|      0|    }
  197|  6.15k|    memcpy(blob, subheader+signature_len, len-signature_len);
  198|  6.15k|    ctx->text_blob_lengths[ctx->text_blob_count-1] = len-signature_len;
  199|  6.15k|    ctx->text_blobs[ctx->text_blob_count-1] = blob;
  200|       |
  201|  6.20k|cleanup:
  202|  6.20k|    return retval;
  203|  6.15k|}
readstat_sas7bdat_read.c:sas7bdat_parse_column_name_subheader:
  316|  3.18k|static readstat_error_t sas7bdat_parse_column_name_subheader(const char *subheader, size_t len, sas7bdat_ctx_t *ctx) {
  317|  3.18k|    readstat_error_t retval = READSTAT_OK;
  318|  3.18k|    size_t signature_len = ctx->subheader_signature_size;
  319|  3.18k|    int cmax = ctx->u64 ? (len-28)/8 : (len-20)/8;
  ------------------
  |  Branch (319:16): [True: 2.07k, False: 1.11k]
  ------------------
  320|  3.18k|    int i;
  321|  3.18k|    const char *cnp = &subheader[signature_len+8];
  322|  3.18k|    uint16_t remainder = sas_read2(&subheader[signature_len], ctx->bswap);
  323|       |
  324|  3.18k|    if (remainder != sas_subheader_remainder(len, signature_len)) {
  ------------------
  |  Branch (324:9): [True: 63, False: 3.12k]
  ------------------
  325|     63|        retval = READSTAT_ERROR_PARSE;
  326|     63|        goto cleanup;
  327|     63|    }
  328|       |
  329|  3.12k|    ctx->col_names_count += cmax;
  330|       |
  331|  3.12k|    if ((retval = sas7bdat_realloc_col_info(ctx, ctx->col_names_count)) != READSTAT_OK)
  ------------------
  |  Branch (331:9): [True: 15, False: 3.10k]
  ------------------
  332|     15|        goto cleanup;
  333|       |
  334|  26.5k|    for (i=ctx->col_names_count-cmax; i<ctx->col_names_count; i++) {
  ------------------
  |  Branch (334:39): [True: 23.4k, False: 3.10k]
  ------------------
  335|  23.4k|        ctx->col_info[i].name_ref = sas7bdat_parse_text_ref(cnp, ctx);
  336|  23.4k|        cnp += 8;
  337|  23.4k|    }
  338|       |
  339|  3.18k|cleanup:
  340|       |
  341|  3.18k|    return retval;
  342|  3.10k|}
readstat_sas7bdat_read.c:sas7bdat_parse_column_attributes_subheader:
  344|  1.93k|static readstat_error_t sas7bdat_parse_column_attributes_subheader(const char *subheader, size_t len, sas7bdat_ctx_t *ctx) {
  345|  1.93k|    readstat_error_t retval = READSTAT_OK;
  346|  1.93k|    size_t signature_len = ctx->subheader_signature_size;
  347|  1.93k|    int cmax = ctx->u64 ? (len-28)/16 : (len-20)/12;
  ------------------
  |  Branch (347:16): [True: 325, False: 1.61k]
  ------------------
  348|  1.93k|    int i;
  349|  1.93k|    const char *cap = &subheader[signature_len+8];
  350|  1.93k|    uint16_t remainder = sas_read2(&subheader[signature_len], ctx->bswap);
  351|       |
  352|  1.93k|    if (remainder != sas_subheader_remainder(len, signature_len)) {
  ------------------
  |  Branch (352:9): [True: 51, False: 1.88k]
  ------------------
  353|     51|        retval = READSTAT_ERROR_PARSE;
  354|     51|        goto cleanup;
  355|     51|    }
  356|  1.88k|    ctx->col_attrs_count += cmax;
  357|  1.88k|    if ((retval = sas7bdat_realloc_col_info(ctx, ctx->col_attrs_count)) != READSTAT_OK)
  ------------------
  |  Branch (357:9): [True: 9, False: 1.87k]
  ------------------
  358|      9|        goto cleanup;
  359|       |
  360|  10.1k|    for (i=ctx->col_attrs_count-cmax; i<ctx->col_attrs_count; i++) {
  ------------------
  |  Branch (360:39): [True: 8.25k, False: 1.85k]
  ------------------
  361|  8.25k|        if (ctx->u64) {
  ------------------
  |  Branch (361:13): [True: 931, False: 7.32k]
  ------------------
  362|    931|            ctx->col_info[i].offset = sas_read8(&cap[0], ctx->bswap);
  363|  7.32k|        } else {
  364|  7.32k|            ctx->col_info[i].offset = sas_read4(&cap[0], ctx->bswap);
  365|  7.32k|        }
  366|       |
  367|  8.25k|        readstat_off_t off=4;
  368|  8.25k|        if (ctx->u64)
  ------------------
  |  Branch (368:13): [True: 931, False: 7.32k]
  ------------------
  369|    931|            off=8;
  370|       |
  371|  8.25k|        ctx->col_info[i].width = sas_read4(&cap[off], ctx->bswap);
  372|  8.25k|        if (ctx->col_info[i].width > ctx->max_col_width)
  ------------------
  |  Branch (372:13): [True: 794, False: 7.45k]
  ------------------
  373|    794|            ctx->max_col_width = ctx->col_info[i].width;
  374|       |
  375|  8.25k|        if (cap[off+6] == SAS_COLUMN_TYPE_NUM) {
  ------------------
  |  |   90|  8.25k|#define SAS_COLUMN_TYPE_NUM  0x01
  ------------------
  |  Branch (375:13): [True: 4.71k, False: 3.54k]
  ------------------
  376|  4.71k|            ctx->col_info[i].type = READSTAT_TYPE_DOUBLE;
  377|  4.71k|        } else if (cap[off+6] == SAS_COLUMN_TYPE_CHR) {
  ------------------
  |  |   91|  3.54k|#define SAS_COLUMN_TYPE_CHR  0x02
  ------------------
  |  Branch (377:20): [True: 3.52k, False: 20]
  ------------------
  378|  3.52k|            ctx->col_info[i].type = READSTAT_TYPE_STRING;
  379|  3.52k|        } else {
  380|     20|            retval = READSTAT_ERROR_PARSE;
  381|     20|            goto cleanup;
  382|     20|        }
  383|  8.23k|        ctx->col_info[i].index = i;
  384|  8.23k|        cap += off+8;
  385|  8.23k|    }
  386|       |
  387|  1.93k|cleanup:
  388|       |
  389|  1.93k|    return retval;
  390|  1.87k|}
readstat_sas7bdat_read.c:sas7bdat_parse_column_format_subheader:
  392|  4.48k|static readstat_error_t sas7bdat_parse_column_format_subheader(const char *subheader, size_t len, sas7bdat_ctx_t *ctx) {
  393|  4.48k|    readstat_error_t retval = READSTAT_OK;
  394|       |
  395|  4.48k|    if (len < (ctx->u64 ? 58 : 46)) {
  ------------------
  |  Branch (395:9): [True: 1, False: 4.47k]
  |  Branch (395:16): [True: 373, False: 4.10k]
  ------------------
  396|      1|        retval = READSTAT_ERROR_PARSE;
  397|      1|        goto cleanup;
  398|      1|    }
  399|       |
  400|  4.47k|    ctx->col_formats_count++;
  401|  4.47k|    if ((retval = sas7bdat_realloc_col_info(ctx, ctx->col_formats_count)) != READSTAT_OK)
  ------------------
  |  Branch (401:9): [True: 0, False: 4.47k]
  ------------------
  402|      0|        goto cleanup;
  403|       |
  404|  4.47k|    col_info_t *col_info = &ctx->col_info[ctx->col_formats_count-1];
  405|  4.47k|    if (ctx->u64) {
  ------------------
  |  Branch (405:9): [True: 373, False: 4.10k]
  ------------------
  406|    373|        col_info->format_width = sas_read2(&subheader[24], ctx->bswap);
  407|    373|        col_info->format_digits = sas_read2(&subheader[26], ctx->bswap);
  408|    373|        col_info->informat_width = sas_read2(&subheader[28], ctx->bswap);
  409|    373|        col_info->informat_digits = sas_read2(&subheader[30], ctx->bswap);
  410|  4.10k|    } else {
  411|  4.10k|        col_info->format_width = sas_read2(&subheader[12], ctx->bswap);
  412|  4.10k|        col_info->format_digits = sas_read2(&subheader[14], ctx->bswap);
  413|  4.10k|        col_info->informat_width = sas_read2(&subheader[16], ctx->bswap);
  414|  4.10k|        col_info->informat_digits = sas_read2(&subheader[18], ctx->bswap);
  415|  4.10k|    }
  416|  4.47k|    col_info->informat_ref = sas7bdat_parse_text_ref(
  417|  4.47k|            ctx->u64 ? &subheader[40] : &subheader[28], ctx);
  ------------------
  |  Branch (417:13): [True: 373, False: 4.10k]
  ------------------
  418|  4.47k|    col_info->format_ref = sas7bdat_parse_text_ref(
  419|  4.47k|            ctx->u64 ? &subheader[46] : &subheader[34], ctx);
  ------------------
  |  Branch (419:13): [True: 373, False: 4.10k]
  ------------------
  420|  4.47k|    col_info->label_ref = sas7bdat_parse_text_ref(
  421|  4.47k|            ctx->u64 ? &subheader[52] : &subheader[40], ctx);
  ------------------
  |  Branch (421:13): [True: 373, False: 4.10k]
  ------------------
  422|       |
  423|  4.48k|cleanup:
  424|  4.48k|    return retval;
  425|  4.47k|}
readstat_sas7bdat_read.c:sas7bdat_is_moved_row:
  957|  5.17k|static int sas7bdat_is_moved_row(unsigned char compression) {
  958|  5.17k|    return compression == SAS_COMPRESSION_ROW_MOVED
  ------------------
  |  |  132|  10.3k|#define SAS_COMPRESSION_ROW_MOVED          0x06
  ------------------
  |  Branch (958:12): [True: 1.39k, False: 3.77k]
  ------------------
  959|  3.77k|        || compression == SAS_COMPRESSION_NONE_MOVED
  ------------------
  |  |  128|  8.94k|#define SAS_COMPRESSION_NONE_MOVED         0x02
  ------------------
  |  Branch (959:12): [True: 1.18k, False: 2.59k]
  ------------------
  960|  2.59k|        || compression == SAS_COMPRESSION_ROW_UNREFERENCED
  ------------------
  |  |  134|  7.76k|#define SAS_COMPRESSION_ROW_UNREFERENCED   0x0d
  ------------------
  |  Branch (960:12): [True: 1.33k, False: 1.25k]
  ------------------
  961|  1.25k|        || compression == SAS_COMPRESSION_NONE_UNREFERENCED;
  ------------------
  |  |  133|  1.25k|#define SAS_COMPRESSION_NONE_UNREFERENCED  0x09
  ------------------
  |  Branch (961:12): [True: 1.20k, False: 48]
  ------------------
  962|  5.17k|}
readstat_sas7bdat_read.c:sas7bdat_parse_amd_pages_pass1:
 1324|  3.72k|static readstat_error_t sas7bdat_parse_amd_pages_pass1(int64_t last_examined_page_pass1, sas7bdat_ctx_t *ctx) {
 1325|  3.72k|    readstat_error_t retval = READSTAT_OK;
 1326|  3.72k|    readstat_io_t *io = ctx->io;
 1327|  3.72k|    uint64_t i;
 1328|  3.72k|    uint64_t amd_page_count = 0;
 1329|       |
 1330|       |    /* ...then AMD pages at the end */
 1331|  7.58k|    for (i=ctx->page_count-1; i>last_examined_page_pass1; i--) {
  ------------------
  |  Branch (1331:31): [True: 5.75k, False: 1.83k]
  ------------------
 1332|  5.75k|        if (io->seek(ctx->header_size + i*ctx->page_size, READSTAT_SEEK_SET, io->io_ctx) == -1) {
  ------------------
  |  Branch (1332:13): [True: 516, False: 5.24k]
  ------------------
 1333|    516|            retval = READSTAT_ERROR_SEEK;
 1334|    516|            if (ctx->handle.error) {
  ------------------
  |  Branch (1334:17): [True: 0, False: 516]
  ------------------
 1335|      0|                snprintf(ctx->error_buf, sizeof(ctx->error_buf), "ReadStat: Failed to seek to position %" PRId64 
 1336|      0|                        " (= %" PRId64 " + %" PRId64 "*%" PRId64 ")",
 1337|      0|                        ctx->header_size + i*ctx->page_size, ctx->header_size, i, ctx->page_size);
 1338|      0|                ctx->handle.error(ctx->error_buf, ctx->user_ctx);
 1339|      0|            }
 1340|    516|            goto cleanup;
 1341|    516|        }
 1342|       |
 1343|  5.24k|        readstat_off_t off = 0;
 1344|  5.24k|        if (ctx->u64)
  ------------------
  |  Branch (1344:13): [True: 4.53k, False: 706]
  ------------------
 1345|  4.53k|            off = 16;
 1346|       |
 1347|  5.24k|        size_t head_len = off + 16 + 2;
 1348|  5.24k|        size_t tail_len = ctx->page_size - head_len;
 1349|       |
 1350|  5.24k|        if (io->read(ctx->page, head_len, io->io_ctx) < head_len) {
  ------------------
  |  Branch (1350:13): [True: 10, False: 5.23k]
  ------------------
 1351|     10|            retval = READSTAT_ERROR_READ;
 1352|     10|            goto cleanup;
 1353|     10|        }
 1354|       |
 1355|  5.23k|        uint16_t page_type = sas_read2(&ctx->page[off+16], ctx->bswap);
 1356|       |
 1357|  5.23k|        if ((page_type & SAS_PAGE_TYPE_MASK) == SAS_PAGE_TYPE_DATA) {
  ------------------
  |  |  113|  5.23k|#define SAS_PAGE_TYPE_MASK   0x0F00
  ------------------
                      if ((page_type & SAS_PAGE_TYPE_MASK) == SAS_PAGE_TYPE_DATA) {
  ------------------
  |  |  110|  5.23k|#define SAS_PAGE_TYPE_DATA   0x0100
  ------------------
  |  Branch (1357:13): [True: 1.23k, False: 3.99k]
  ------------------
 1358|       |            /* Usually AMD pages are at the end but sometimes data pages appear after them */
 1359|  1.23k|            if (amd_page_count > 0)
  ------------------
  |  Branch (1359:17): [True: 688, False: 545]
  ------------------
 1360|    688|                break;
 1361|    545|            continue;
 1362|  1.23k|        }
 1363|  3.99k|        if ((page_type & SAS_PAGE_TYPE_COMP))
  ------------------
  |  |  118|  3.99k|#define SAS_PAGE_TYPE_COMP          0x9000
  ------------------
  |  Branch (1363:13): [True: 932, False: 3.06k]
  ------------------
 1364|    932|            continue;
 1365|       |
 1366|  3.06k|        if (io->read(ctx->page + head_len, tail_len, io->io_ctx) < tail_len) {
  ------------------
  |  Branch (1366:13): [True: 18, False: 3.04k]
  ------------------
 1367|     18|            retval = READSTAT_ERROR_READ;
 1368|     18|            goto cleanup;
 1369|     18|        }
 1370|       |
 1371|  3.04k|        if ((retval = sas7bdat_parse_page_pass1(ctx->page, ctx->page_size, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1371:13): [True: 664, False: 2.38k]
  ------------------
 1372|    664|            if (ctx->handle.error && retval != READSTAT_ERROR_USER_ABORT) {
  ------------------
  |  Branch (1372:17): [True: 0, False: 664]
  |  Branch (1372:38): [True: 0, False: 0]
  ------------------
 1373|      0|                int64_t pos = io->seek(0, READSTAT_SEEK_CUR, io->io_ctx);
 1374|      0|                snprintf(ctx->error_buf, sizeof(ctx->error_buf), 
 1375|      0|                        "ReadStat: Error parsing page %" PRId64 ", bytes %" PRId64 "-%" PRId64, 
 1376|      0|                        i, pos - ctx->page_size, pos-1);
 1377|      0|                ctx->handle.error(ctx->error_buf, ctx->user_ctx);
 1378|      0|            }
 1379|    664|            goto cleanup;
 1380|    664|        }
 1381|       |
 1382|  2.38k|        amd_page_count++;
 1383|  2.38k|    }
 1384|       |
 1385|  3.72k|cleanup:
 1386|       |
 1387|  3.72k|    return retval;
 1388|  3.72k|}
readstat_sas7bdat_read.c:sas7bdat_parse_all_pages_pass2:
 1390|  2.51k|static readstat_error_t sas7bdat_parse_all_pages_pass2(sas7bdat_ctx_t *ctx) {
 1391|  2.51k|    readstat_error_t retval = READSTAT_OK;
 1392|  2.51k|    readstat_io_t *io = ctx->io;
 1393|  2.51k|    int64_t i;
 1394|       |
 1395|  7.29k|    for (i=0; i<ctx->page_count; i++) {
  ------------------
  |  Branch (1395:15): [True: 6.98k, False: 306]
  ------------------
 1396|  6.98k|        if ((retval = sas7bdat_update_progress(ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1396:13): [True: 0, False: 6.98k]
  ------------------
 1397|      0|            goto cleanup;
 1398|      0|        }
 1399|  6.98k|        if (io->read(ctx->page, ctx->page_size, io->io_ctx) < ctx->page_size) {
  ------------------
  |  Branch (1399:13): [True: 156, False: 6.82k]
  ------------------
 1400|    156|            retval = READSTAT_ERROR_READ;
 1401|    156|            goto cleanup;
 1402|    156|        }
 1403|       |
 1404|  6.82k|        if ((retval = sas7bdat_parse_page_pass2(ctx->page, ctx->page_size, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1404:13): [True: 2.04k, False: 4.78k]
  ------------------
 1405|  2.04k|            if (ctx->handle.error && retval != READSTAT_ERROR_USER_ABORT) {
  ------------------
  |  Branch (1405:17): [True: 0, False: 2.04k]
  |  Branch (1405:38): [True: 0, False: 0]
  ------------------
 1406|      0|                int64_t pos = io->seek(0, READSTAT_SEEK_CUR, io->io_ctx);
 1407|      0|                snprintf(ctx->error_buf, sizeof(ctx->error_buf), 
 1408|      0|                        "ReadStat: Error parsing page %" PRId64 ", bytes %" PRId64 "-%" PRId64, 
 1409|      0|                        i, pos - ctx->page_size, pos-1);
 1410|      0|                ctx->handle.error(ctx->error_buf, ctx->user_ctx);
 1411|      0|            }
 1412|  2.04k|            goto cleanup;
 1413|  2.04k|        }
 1414|  4.78k|        if (ctx->row_limit > 0 && ctx->parsed_row_count == ctx->row_limit)
  ------------------
  |  Branch (1414:13): [True: 949, False: 3.83k]
  |  Branch (1414:35): [True: 9, False: 940]
  ------------------
 1415|      9|            break;
 1416|  4.78k|    }
 1417|  2.51k|cleanup:
 1418|       |
 1419|  2.51k|    return retval;
 1420|  2.51k|}
readstat_sas7bdat_read.c:sas7bdat_parse_page_pass2:
 1145|  6.82k|static readstat_error_t sas7bdat_parse_page_pass2(const char *page, size_t page_size, sas7bdat_ctx_t *ctx) {
 1146|  6.82k|    uint16_t page_type;
 1147|       |
 1148|  6.82k|    readstat_error_t retval = READSTAT_OK;
 1149|       |
 1150|  6.82k|    page_type = sas_read2(&page[ctx->page_header_size-8], ctx->bswap);
 1151|       |
 1152|  6.82k|    const char *data = NULL;
 1153|       |
 1154|  6.82k|    if ((page_type & SAS_PAGE_TYPE_MASK) == SAS_PAGE_TYPE_DATA) {
  ------------------
  |  |  113|  6.82k|#define SAS_PAGE_TYPE_MASK   0x0F00
  ------------------
                  if ((page_type & SAS_PAGE_TYPE_MASK) == SAS_PAGE_TYPE_DATA) {
  ------------------
  |  |  110|  6.82k|#define SAS_PAGE_TYPE_DATA   0x0100
  ------------------
  |  Branch (1154:9): [True: 800, False: 6.02k]
  ------------------
 1155|    800|        ctx->page_row_count = sas_read2(&page[ctx->page_header_size-6], ctx->bswap);
 1156|    800|        data = &page[ctx->page_header_size];
 1157|  6.02k|    } else if (!(page_type & SAS_PAGE_TYPE_COMP)) {
  ------------------
  |  |  118|  6.02k|#define SAS_PAGE_TYPE_COMP          0x9000
  ------------------
  |  Branch (1157:16): [True: 5.38k, False: 648]
  ------------------
 1158|  5.38k|        uint16_t subheader_count = sas_read2(&page[ctx->page_header_size-4], ctx->bswap);
 1159|       |
 1160|  5.38k|        int i;
 1161|  5.38k|        const char *shp = &page[ctx->page_header_size];
 1162|  5.38k|        int lshp = ctx->subheader_pointer_size;
 1163|       |
 1164|  5.38k|        if (ctx->page_header_size + subheader_count*lshp > page_size) {
  ------------------
  |  Branch (1164:13): [True: 30, False: 5.35k]
  ------------------
 1165|     30|            retval = READSTAT_ERROR_PARSE;
 1166|     30|            goto cleanup;
 1167|     30|        }
 1168|       |
 1169|  56.2k|        for (i=0; i<subheader_count; i++) {
  ------------------
  |  Branch (1169:19): [True: 52.5k, False: 3.70k]
  ------------------
 1170|  52.5k|            subheader_pointer_t shp_info = { 0 };
 1171|  52.5k|            if ((retval = sas7bdat_parse_subheader_pointer(shp, page + page_size - shp, &shp_info, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1171:17): [True: 0, False: 52.5k]
  ------------------
 1172|      0|                goto cleanup;
 1173|      0|            }
 1174|  52.5k|            if (shp_info.len > 0 && shp_info.compression == SAS_COMPRESSION_REFERENCE) {
  ------------------
  |  |  129|  34.0k|#define SAS_COMPRESSION_REFERENCE          0x03
  ------------------
  |  Branch (1174:17): [True: 34.0k, False: 18.4k]
  |  Branch (1174:37): [True: 811, False: 33.2k]
  ------------------
 1175|    811|                uint64_t page_index = shp_info.offset - 1;
 1176|    811|                uint64_t subheader_index = shp_info.len - 1;
 1177|    811|                if ((retval = sas7bdat_parse_moved_row(page_index, subheader_index, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1177:21): [True: 603, False: 208]
  ------------------
 1178|    603|                    goto cleanup;
 1179|    603|                }
 1180|  51.7k|            } else if (shp_info.len > 0 && shp_info.compression != SAS_COMPRESSION_TRUNC) {
  ------------------
  |  |  127|  33.2k|#define SAS_COMPRESSION_TRUNC              0x01
  ------------------
  |  Branch (1180:24): [True: 33.2k, False: 18.4k]
  |  Branch (1180:44): [True: 28.3k, False: 4.88k]
  ------------------
 1181|  28.3k|                if ((retval = sas7bdat_validate_subheader_pointer(&shp_info, page_size, subheader_count, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1181:21): [True: 223, False: 28.1k]
  ------------------
 1182|    223|                    goto cleanup;
 1183|    223|                }
 1184|  28.1k|                if (shp_info.compression == SAS_COMPRESSION_NONE) {
  ------------------
  |  |  126|  28.1k|#define SAS_COMPRESSION_NONE               0x00
  ------------------
  |  Branch (1184:21): [True: 23.4k, False: 4.73k]
  ------------------
 1185|  23.4k|                    sas_subheader_type_t subheader_type = sas7bdat_parse_subheader_type(page + shp_info.offset, ctx);
 1186|  23.4k|                    if (shp_info.is_compressed_data && subheader_type == SAS_SUBHEADER_TYPE_DATA) {
  ------------------
  |  Branch (1186:25): [True: 14.5k, False: 8.91k]
  |  Branch (1186:56): [True: 512, False: 14.0k]
  ------------------
 1187|    512|                        if (shp_info.len != ctx->row_length) {
  ------------------
  |  Branch (1187:29): [True: 70, False: 442]
  ------------------
 1188|     70|                            retval = READSTAT_ERROR_ROW_WIDTH_MISMATCH;
 1189|     70|                            goto cleanup;
 1190|     70|                        }
 1191|    442|                        if ((retval = sas7bdat_submit_columns_if_needed(ctx, 1)) != READSTAT_OK) {
  ------------------
  |  Branch (1191:29): [True: 2, False: 440]
  ------------------
 1192|      2|                            goto cleanup;
 1193|      2|                        }
 1194|    440|                        if ((retval = sas7bdat_parse_single_row(page + shp_info.offset, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1194:29): [True: 9, False: 431]
  ------------------
 1195|      9|                            goto cleanup;
 1196|      9|                        }
 1197|  22.9k|                    } else {
 1198|  22.9k|                        if (subheader_type != SAS_SUBHEADER_TYPE_COLUMN_TEXT) {
  ------------------
  |  Branch (1198:29): [True: 18.1k, False: 4.71k]
  ------------------
 1199|  18.1k|                            if ((retval = sas7bdat_parse_subheader(subheader_type, page + shp_info.offset, shp_info.len, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1199:33): [True: 398, False: 17.7k]
  ------------------
 1200|    398|                                goto cleanup;
 1201|    398|                            }
 1202|  18.1k|                        }
 1203|  22.9k|                    }
 1204|  23.4k|                } else if (shp_info.compression == SAS_COMPRESSION_ROW) {
  ------------------
  |  |  130|  4.73k|#define SAS_COMPRESSION_ROW                0x04
  ------------------
  |  Branch (1204:28): [True: 2.24k, False: 2.48k]
  ------------------
 1205|  2.24k|                    if ((retval = sas7bdat_submit_columns_if_needed(ctx, 1)) != READSTAT_OK) {
  ------------------
  |  Branch (1205:25): [True: 47, False: 2.20k]
  ------------------
 1206|     47|                        goto cleanup;
 1207|     47|                    }
 1208|  2.20k|                    if ((retval = sas7bdat_parse_subheader_compressed(page + shp_info.offset, shp_info.len, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1208:25): [True: 278, False: 1.92k]
  ------------------
 1209|    278|                        goto cleanup;
 1210|    278|                    }
 1211|  2.48k|                } else if (shp_info.compression == SAS_COMPRESSION_DELETED_ROW) {
  ------------------
  |  |  131|  2.48k|#define SAS_COMPRESSION_DELETED_ROW        0x05
  ------------------
  |  Branch (1211:28): [True: 369, False: 2.11k]
  ------------------
 1212|    369|                    if ((retval = sas7bdat_register_deleted_row(ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1212:25): [True: 1, False: 368]
  ------------------
 1213|      1|                        goto cleanup;
 1214|      1|                    }
 1215|  2.11k|                } else if (sas7bdat_is_moved_row(shp_info.compression)) {
  ------------------
  |  Branch (1215:28): [True: 2.10k, False: 16]
  ------------------
 1216|       |                    /* void */
 1217|  2.10k|                } else {
 1218|     16|                    retval = READSTAT_ERROR_UNSUPPORTED_COMPRESSION;
 1219|     16|                    goto cleanup;
 1220|     16|                }
 1221|  28.1k|            }
 1222|       |
 1223|  50.9k|            shp += lshp;
 1224|  50.9k|        }
 1225|       |
 1226|  3.70k|        if ((page_type & SAS_PAGE_TYPE_MASK) == SAS_PAGE_TYPE_MIX) {
  ------------------
  |  |  113|  3.70k|#define SAS_PAGE_TYPE_MASK   0x0F00
  ------------------
                      if ((page_type & SAS_PAGE_TYPE_MASK) == SAS_PAGE_TYPE_MIX) {
  ------------------
  |  |  111|  3.70k|#define SAS_PAGE_TYPE_MIX    0x0200
  ------------------
  |  Branch (1226:13): [True: 1.90k, False: 1.80k]
  ------------------
 1227|       |            /* HACK - this is supposed to obey 8-byte boundaries but
 1228|       |             * some files created by Stat/Transfer don't. So verify that the
 1229|       |             * padding is { 0, 0, 0, 0 } or { ' ', ' ', ' ', ' ' } (or that
 1230|       |             * the file is not from Stat/Transfer) before skipping it */
 1231|  1.90k|            if ((shp-page)%8 == 4 && shp + 4 <= page + page_size &&
  ------------------
  |  Branch (1231:17): [True: 348, False: 1.55k]
  |  Branch (1231:38): [True: 345, False: 3]
  ------------------
 1232|    345|                    (*(uint32_t *)shp == 0x00000000 ||
  ------------------
  |  Branch (1232:22): [True: 81, False: 264]
  ------------------
 1233|    264|                     *(uint32_t *)shp == 0x20202020 ||
  ------------------
  |  Branch (1233:22): [True: 41, False: 223]
  ------------------
 1234|    311|                     ctx->vendor != READSTAT_VENDOR_STAT_TRANSFER)) {
  ------------------
  |  Branch (1234:22): [True: 189, False: 34]
  ------------------
 1235|    311|                data = shp + 4;
 1236|  1.59k|            } else {
 1237|  1.59k|                data = shp;
 1238|  1.59k|            }
 1239|  1.90k|        }
 1240|  3.70k|    }
 1241|  5.15k|    if (data) {
  ------------------
  |  Branch (1241:9): [True: 2.70k, False: 2.44k]
  ------------------
 1242|  2.70k|        if ((retval = sas7bdat_submit_columns_if_needed(ctx, 0)) != READSTAT_OK) {
  ------------------
  |  Branch (1242:13): [True: 108, False: 2.59k]
  ------------------
 1243|    108|            goto cleanup;
 1244|    108|        }
 1245|  2.59k|        if (ctx->handle.value) {
  ------------------
  |  Branch (1245:13): [True: 2.59k, False: 0]
  ------------------
 1246|  2.59k|            const unsigned char *deleted_row_bitmap = NULL;
 1247|  2.59k|            uint32_t deleted_row_bitmap_row_count = 0;
 1248|  2.59k|            if (page_type & SAS_PAGE_TYPE_DELETED_ROWS) {
  ------------------
  |  |  115|  2.59k|#define SAS_PAGE_TYPE_DELETED_ROWS  0x0080
  ------------------
  |  Branch (1248:17): [True: 668, False: 1.92k]
  ------------------
 1249|    668|                if ((retval = sas7bdat_parse_deleted_row_bitmap(page, data, page_size,
  ------------------
  |  Branch (1249:21): [True: 111, False: 557]
  ------------------
 1250|    668|                        &deleted_row_bitmap, &deleted_row_bitmap_row_count, ctx)) != READSTAT_OK) {
 1251|    111|                    goto cleanup;
 1252|    111|                }
 1253|    668|            }
 1254|  2.48k|            retval = sas7bdat_parse_rows(data, page + page_size - data,
 1255|  2.48k|                    deleted_row_bitmap, deleted_row_bitmap_row_count, ctx);
 1256|  2.48k|        }
 1257|  2.59k|    } 
 1258|  6.82k|cleanup:
 1259|       |
 1260|  6.82k|    return retval;
 1261|  5.15k|}
readstat_sas7bdat_read.c:sas7bdat_parse_moved_row:
 1034|    811|static readstat_error_t sas7bdat_parse_moved_row(uint64_t page_index, uint64_t subheader_index, sas7bdat_ctx_t *ctx) {
 1035|    811|    readstat_error_t retval = READSTAT_OK;
 1036|    811|    readstat_io_t *io = ctx->io;
 1037|       |
 1038|    811|    const uint64_t page_size = ctx->page_size;
 1039|    811|    int64_t saved_pos = -1;
 1040|       |
 1041|    811|    if (page_index >= ctx->page_count) {
  ------------------
  |  Branch (1041:9): [True: 98, False: 713]
  ------------------
 1042|     98|        retval = READSTAT_ERROR_PARSE;
 1043|     98|        goto cleanup;
 1044|     98|    }
 1045|       |
 1046|    713|    if (ctx->moved_page == NULL) {
  ------------------
  |  Branch (1046:9): [True: 526, False: 187]
  ------------------
 1047|    526|        if ((ctx->moved_page = readstat_malloc(page_size)) == NULL) {
  ------------------
  |  Branch (1047:13): [True: 0, False: 526]
  ------------------
 1048|      0|            retval = READSTAT_ERROR_MALLOC;
 1049|      0|            goto cleanup;
 1050|      0|        }
 1051|    526|        ctx->moved_page_index = -1;
 1052|    526|    }
 1053|    713|    char *page = ctx->moved_page;
 1054|       |
 1055|    713|    if (ctx->moved_page_index != (int64_t)page_index) {
  ------------------
  |  Branch (1055:9): [True: 577, False: 136]
  ------------------
 1056|    577|        saved_pos = io->seek(0, READSTAT_SEEK_CUR, io->io_ctx);
 1057|    577|        if (saved_pos == -1) {
  ------------------
  |  Branch (1057:13): [True: 0, False: 577]
  ------------------
 1058|      0|            retval = READSTAT_ERROR_SEEK;
 1059|      0|            goto cleanup;
 1060|      0|        }
 1061|    577|        if (io->seek(ctx->header_size + page_index * page_size, READSTAT_SEEK_SET, io->io_ctx) == -1) {
  ------------------
  |  Branch (1061:13): [True: 109, False: 468]
  ------------------
 1062|    109|            retval = READSTAT_ERROR_SEEK;
 1063|    109|            if (ctx->handle.error) {
  ------------------
  |  Branch (1063:17): [True: 0, False: 109]
  ------------------
 1064|      0|                snprintf(ctx->error_buf, sizeof(ctx->error_buf), "ReadStat: Failed to seek to position %" PRId64
 1065|      0|                        " (= %" PRId64 " + %" PRId64 "*%" PRId64 ")",
 1066|      0|                        ctx->header_size + page_index * page_size, ctx->header_size, page_index, page_size);
 1067|      0|                ctx->handle.error(ctx->error_buf, ctx->user_ctx);
 1068|      0|            }
 1069|    109|            goto cleanup;
 1070|    109|        }
 1071|    468|        ssize_t bytes_read = io->read(page, page_size, io->io_ctx);
 1072|    468|        if (bytes_read < 0 || (uint64_t)bytes_read < page_size) {
  ------------------
  |  Branch (1072:13): [True: 0, False: 468]
  |  Branch (1072:31): [True: 5, False: 463]
  ------------------
 1073|      5|            retval = READSTAT_ERROR_READ;
 1074|      5|            goto cleanup;
 1075|      5|        }
 1076|    463|        ctx->moved_page_index = (int64_t)page_index;
 1077|    463|    }
 1078|       |
 1079|    599|    uint16_t page_type = sas_read2(&page[ctx->page_header_size - 8], ctx->bswap);
 1080|    599|    if ((page_type & SAS_PAGE_TYPE_MASK) == SAS_PAGE_TYPE_DATA || page_type & SAS_PAGE_TYPE_COMP) {
  ------------------
  |  |  113|    599|#define SAS_PAGE_TYPE_MASK   0x0F00
  ------------------
                  if ((page_type & SAS_PAGE_TYPE_MASK) == SAS_PAGE_TYPE_DATA || page_type & SAS_PAGE_TYPE_COMP) {
  ------------------
  |  |  110|  1.19k|#define SAS_PAGE_TYPE_DATA   0x0100
  ------------------
                  if ((page_type & SAS_PAGE_TYPE_MASK) == SAS_PAGE_TYPE_DATA || page_type & SAS_PAGE_TYPE_COMP) {
  ------------------
  |  |  118|    594|#define SAS_PAGE_TYPE_COMP          0x9000
  ------------------
  |  Branch (1080:9): [True: 5, False: 594]
  |  Branch (1080:67): [True: 3, False: 591]
  ------------------
 1081|      8|        retval = READSTAT_ERROR_READ;
 1082|      8|        goto cleanup;
 1083|      8|    }
 1084|    591|    uint16_t subheader_count = sas_read2(&page[ctx->page_header_size - 4], ctx->bswap);
 1085|    591|    if (subheader_index >= subheader_count) {
  ------------------
  |  Branch (1085:9): [True: 106, False: 485]
  ------------------
 1086|    106|        retval = READSTAT_ERROR_READ;
 1087|    106|        goto cleanup;
 1088|    106|    }
 1089|    485|    uint64_t shp_offset = ctx->page_header_size + subheader_index * ctx->subheader_pointer_size;
 1090|    485|    if (shp_offset + ctx->subheader_pointer_size > page_size) {
  ------------------
  |  Branch (1090:9): [True: 21, False: 464]
  ------------------
 1091|     21|        retval = READSTAT_ERROR_READ;
 1092|     21|        goto cleanup;
 1093|     21|    }
 1094|       |
 1095|    464|    const char *shp = &page[shp_offset];
 1096|    464|    subheader_pointer_t shp_info = { 0 };
 1097|    464|    if ((retval = sas7bdat_parse_subheader_pointer(shp, page + page_size - shp, &shp_info, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1097:9): [True: 0, False: 464]
  ------------------
 1098|      0|        goto cleanup;
 1099|      0|    }
 1100|    464|    if ((retval = sas7bdat_validate_subheader_pointer(&shp_info, page_size, subheader_count, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1100:9): [True: 220, False: 244]
  ------------------
 1101|    220|        goto cleanup;
 1102|    220|    }
 1103|    244|    if ((retval = sas7bdat_submit_columns_if_needed(ctx, 1)) != READSTAT_OK) {
  ------------------
  |  Branch (1103:9): [True: 7, False: 237]
  ------------------
 1104|      7|        goto cleanup;
 1105|      7|    }
 1106|       |
 1107|    237|    if (shp_info.compression == SAS_COMPRESSION_NONE_MOVED) {
  ------------------
  |  |  128|    237|#define SAS_COMPRESSION_NONE_MOVED         0x02
  ------------------
  |  Branch (1107:9): [True: 36, False: 201]
  ------------------
 1108|     36|        sas_subheader_type_t subheader_type = sas7bdat_parse_subheader_type(page + shp_info.offset, ctx);
 1109|     36|        if (!shp_info.is_compressed_data || subheader_type != SAS_SUBHEADER_TYPE_DATA) {
  ------------------
  |  Branch (1109:13): [True: 2, False: 34]
  |  Branch (1109:45): [True: 5, False: 29]
  ------------------
 1110|      7|            retval = READSTAT_ERROR_READ;
 1111|      7|            goto cleanup;
 1112|      7|        }
 1113|     29|        if (shp_info.len != ctx->row_length) {
  ------------------
  |  Branch (1113:13): [True: 11, False: 18]
  ------------------
 1114|     11|            retval = READSTAT_ERROR_ROW_WIDTH_MISMATCH;
 1115|     11|            goto cleanup;
 1116|     11|        }
 1117|     18|        if ((retval = sas7bdat_parse_single_row(page + shp_info.offset, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1117:13): [True: 0, False: 18]
  ------------------
 1118|      0|            goto cleanup;
 1119|      0|        }
 1120|    201|    } else if (shp_info.compression == SAS_COMPRESSION_ROW_MOVED) {
  ------------------
  |  |  132|    201|#define SAS_COMPRESSION_ROW_MOVED          0x06
  ------------------
  |  Branch (1120:16): [True: 190, False: 11]
  ------------------
 1121|    190|        if ((retval = sas7bdat_parse_subheader_compressed(page + shp_info.offset, shp_info.len, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1121:13): [True: 0, False: 190]
  ------------------
 1122|      0|            goto cleanup;
 1123|      0|        }
 1124|    190|    } else {
 1125|     11|        retval = READSTAT_ERROR_UNSUPPORTED_COMPRESSION;
 1126|     11|        goto cleanup;
 1127|     11|    }
 1128|       |
 1129|    811|cleanup:
 1130|       |
 1131|    811|    if (saved_pos != -1) {
  ------------------
  |  Branch (1131:9): [True: 577, False: 234]
  ------------------
 1132|    577|        if (io->seek(saved_pos, READSTAT_SEEK_SET, io->io_ctx) == -1 && retval == READSTAT_OK) {
  ------------------
  |  Branch (1132:13): [True: 0, False: 577]
  |  Branch (1132:73): [True: 0, False: 0]
  ------------------
 1133|      0|            retval = READSTAT_ERROR_SEEK;
 1134|      0|            if (ctx->handle.error) {
  ------------------
  |  Branch (1134:17): [True: 0, False: 0]
  ------------------
 1135|      0|                snprintf(ctx->error_buf, sizeof(ctx->error_buf),
 1136|      0|                        "ReadStat: Failed to seek to position %" PRId64, saved_pos);
 1137|      0|                ctx->handle.error(ctx->error_buf, ctx->user_ctx);
 1138|      0|            }
 1139|      0|        }
 1140|    577|    }
 1141|       |
 1142|    811|    return retval;
 1143|    237|}
readstat_sas7bdat_read.c:sas7bdat_parse_single_row:
  499|  41.7k|static readstat_error_t sas7bdat_parse_single_row(const char *data, sas7bdat_ctx_t *ctx) {
  500|  41.7k|    if (ctx->parsed_row_count == ctx->row_limit)
  ------------------
  |  Branch (500:9): [True: 160, False: 41.5k]
  ------------------
  501|    160|        return READSTAT_OK;
  502|  41.5k|    if (ctx->row_offset) {
  ------------------
  |  Branch (502:9): [True: 0, False: 41.5k]
  ------------------
  503|      0|        ctx->row_offset--;
  504|      0|        return READSTAT_OK;
  505|      0|    }
  506|       |
  507|  41.5k|    readstat_error_t retval = READSTAT_OK;
  508|  41.5k|    int j;
  509|  41.5k|    if (ctx->handle.value) {
  ------------------
  |  Branch (509:9): [True: 41.5k, False: 0]
  ------------------
  510|  41.5k|        ctx->scratch_buffer_len = 4*ctx->max_col_width+1;
  511|  41.5k|        ctx->scratch_buffer = readstat_realloc(ctx->scratch_buffer, ctx->scratch_buffer_len);
  512|  41.5k|        if (ctx->scratch_buffer == NULL) {
  ------------------
  |  Branch (512:13): [True: 3, False: 41.5k]
  ------------------
  513|      3|            retval = READSTAT_ERROR_MALLOC;
  514|      3|            goto cleanup;
  515|      3|        }
  516|       |
  517|  28.5M|        for (j=0; j<ctx->column_count; j++) {
  ------------------
  |  Branch (517:19): [True: 28.5M, False: 41.4k]
  ------------------
  518|  28.5M|            col_info_t *col_info = &ctx->col_info[j];
  519|  28.5M|            readstat_variable_t *variable = ctx->variables[j];
  520|  28.5M|            if (variable->skip)
  ------------------
  |  Branch (520:17): [True: 0, False: 28.5M]
  ------------------
  521|      0|                continue;
  522|       |
  523|  28.5M|            if (col_info->offset > ctx->row_length || col_info->offset + col_info->width > ctx->row_length) {
  ------------------
  |  Branch (523:17): [True: 88, False: 28.5M]
  |  Branch (523:55): [True: 17, False: 28.5M]
  ------------------
  524|    105|                retval = READSTAT_ERROR_PARSE;
  525|    105|                goto cleanup;
  526|    105|            }
  527|  28.5M|            retval = sas7bdat_handle_data_value(variable, col_info, &data[col_info->offset], ctx);
  528|  28.5M|            if (retval != READSTAT_OK) {
  ------------------
  |  Branch (528:17): [True: 16, False: 28.5M]
  ------------------
  529|     16|                goto cleanup;
  530|     16|            }
  531|  28.5M|        }
  532|  41.5k|    }
  533|  41.4k|    ctx->parsed_row_count++;
  534|       |
  535|  41.5k|cleanup:
  536|  41.5k|    return retval;
  537|  41.4k|}
readstat_sas7bdat_read.c:sas7bdat_handle_data_value:
  436|  28.5M|        col_info_t *col_info, const char *col_data, sas7bdat_ctx_t *ctx) {
  437|  28.5M|    readstat_error_t retval = READSTAT_OK;
  438|  28.5M|    int cb_retval = 0;
  439|  28.5M|    readstat_value_t value;
  440|  28.5M|    memset(&value, 0, sizeof(readstat_value_t));
  441|       |
  442|  28.5M|    value.type = col_info->type;
  443|       |
  444|  28.5M|    if (col_info->type == READSTAT_TYPE_STRING) {
  ------------------
  |  Branch (444:9): [True: 28.4M, False: 90.4k]
  ------------------
  445|  28.4M|        retval = readstat_convert(ctx->scratch_buffer, ctx->scratch_buffer_len,
  446|  28.4M|                col_data, col_info->width, ctx->converter);
  447|  28.4M|        if (retval != READSTAT_OK) {
  ------------------
  |  Branch (447:13): [True: 7, False: 28.4M]
  ------------------
  448|      7|            if (ctx->handle.error) {
  ------------------
  |  Branch (448:17): [True: 0, False: 7]
  ------------------
  449|      0|                snprintf(ctx->error_buf, sizeof(ctx->error_buf),
  450|      0|                        "ReadStat: Error converting string (row=%u, col=%u) to specified encoding: %.*s",
  451|      0|                        ctx->parsed_row_count+1, col_info->index+1, col_info->width, col_data);
  452|      0|                ctx->handle.error(ctx->error_buf, ctx->user_ctx);
  453|      0|            }
  454|      7|            goto cleanup;
  455|      7|        }
  456|       |
  457|  28.4M|        value.v.string_value = ctx->scratch_buffer;
  458|  28.4M|    } else if (col_info->type == READSTAT_TYPE_DOUBLE) {
  ------------------
  |  Branch (458:16): [True: 90.4k, False: 0]
  ------------------
  459|  90.4k|        uint64_t  val = 0;
  460|  90.4k|        double dval = NAN;
  461|  90.4k|        if (col_info->width < 1 || col_info->width > 8) {
  ------------------
  |  Branch (461:13): [True: 1, False: 90.4k]
  |  Branch (461:36): [True: 8, False: 90.4k]
  ------------------
  462|       |            /* A DOUBLE is 3-8 bytes on disk, but col_info can be mutated by a
  463|       |             * COLUMN_ATTRS subheader after the columns were validated. Guard
  464|       |             * here so a corrupt width can't produce an undefined shift below. */
  465|      9|            retval = READSTAT_ERROR_PARSE;
  466|      9|            goto cleanup;
  467|      9|        }
  468|  90.4k|        if (ctx->little_endian) {
  ------------------
  |  Branch (468:13): [True: 90.4k, False: 0]
  ------------------
  469|  90.4k|            int k;
  470|   569k|            for (k=0; k<col_info->width; k++) {
  ------------------
  |  Branch (470:23): [True: 479k, False: 90.4k]
  ------------------
  471|   479k|                val = (val << 8) | (unsigned char)col_data[col_info->width-1-k];
  472|   479k|            }
  473|  90.4k|        } else {
  474|      0|            int k;
  475|      0|            for (k=0; k<col_info->width; k++) {
  ------------------
  |  Branch (475:23): [True: 0, False: 0]
  ------------------
  476|      0|                val = (val << 8) | (unsigned char)col_data[k];
  477|      0|            }
  478|      0|        }
  479|  90.4k|        val <<= (8-col_info->width)*8;
  480|       |
  481|  90.4k|        memcpy(&dval, &val, 8);
  482|       |
  483|  90.4k|        if (isnan(dval)) {
  ------------------
  |  Branch (483:13): [True: 4.93k, False: 85.5k]
  ------------------
  484|  4.93k|            value.v.double_value = NAN;
  485|  4.93k|            sas_assign_tag(&value, ~((val >> 40) & 0xFF));
  486|  85.5k|        } else {
  487|  85.5k|            value.v.double_value = dval;
  488|  85.5k|        }
  489|  90.4k|    }
  490|  28.5M|    cb_retval = ctx->handle.value(ctx->parsed_row_count, variable, value, ctx->user_ctx);
  491|       |
  492|  28.5M|    if (cb_retval != READSTAT_HANDLER_OK)
  ------------------
  |  |   22|  28.5M|#define READSTAT_HANDLER_OK             0
  ------------------
  |  Branch (492:9): [True: 0, False: 28.5M]
  ------------------
  493|      0|        retval = READSTAT_ERROR_USER_ABORT;
  494|       |
  495|  28.5M|cleanup:
  496|  28.5M|    return retval;
  497|  28.5M|}
readstat_sas7bdat_read.c:sas7bdat_parse_subheader_compressed:
  628|  2.39k|static readstat_error_t sas7bdat_parse_subheader_compressed(const char *subheader, size_t len, sas7bdat_ctx_t *ctx) {
  629|  2.39k|    if (ctx->rdc_compression)
  ------------------
  |  Branch (629:9): [True: 678, False: 1.71k]
  ------------------
  630|    678|        return sas7bdat_parse_subheader_rdc(subheader, len, ctx);
  631|       |
  632|  1.71k|    return sas7bdat_parse_subheader_rle(subheader, len, ctx);
  633|  2.39k|}
readstat_sas7bdat_read.c:sas7bdat_parse_subheader_rdc:
  576|    678|static readstat_error_t sas7bdat_parse_subheader_rdc(const char *subheader, size_t len, sas7bdat_ctx_t *ctx) {
  577|    678|    if (ctx->row_limit == ctx->parsed_row_count)
  ------------------
  |  Branch (577:9): [True: 280, False: 398]
  ------------------
  578|    280|        return READSTAT_OK;
  579|       |
  580|    398|    readstat_error_t retval = READSTAT_OK;
  581|    398|    ssize_t bytes_decompressed = 0;
  582|       |
  583|    398|    if (ctx->row == NULL)
  ------------------
  |  Branch (583:9): [True: 0, False: 398]
  ------------------
  584|      0|        return READSTAT_ERROR_PARSE;
  585|       |
  586|    398|    bytes_decompressed = sas_rdc_decompress(ctx->row, ctx->row_length, subheader, len);
  587|       |
  588|    398|    if (bytes_decompressed != ctx->row_length) {
  ------------------
  |  Branch (588:9): [True: 104, False: 294]
  ------------------
  589|    104|        retval = READSTAT_ERROR_ROW_WIDTH_MISMATCH;
  590|    104|        if (ctx->handle.error) {
  ------------------
  |  Branch (590:13): [True: 0, False: 104]
  ------------------
  591|      0|            snprintf(ctx->error_buf, sizeof(ctx->error_buf),
  592|      0|                    "ReadStat: Row #%d decompressed to %ld bytes (expected %d bytes)",
  593|      0|                    ctx->parsed_row_count, (long)(bytes_decompressed), ctx->row_length);
  594|      0|            ctx->handle.error(ctx->error_buf, ctx->user_ctx);
  595|      0|        }
  596|    104|        goto cleanup;
  597|    104|    }
  598|    294|    retval = sas7bdat_parse_single_row(ctx->row, ctx);
  599|    398|cleanup:
  600|    398|    return retval;
  601|    294|}
readstat_sas7bdat_read.c:sas7bdat_parse_subheader_rle:
  603|  1.71k|static readstat_error_t sas7bdat_parse_subheader_rle(const char *subheader, size_t len, sas7bdat_ctx_t *ctx) {
  604|  1.71k|    if (ctx->row_limit == ctx->parsed_row_count)
  ------------------
  |  Branch (604:9): [True: 1.30k, False: 405]
  ------------------
  605|  1.30k|        return READSTAT_OK;
  606|       |
  607|    405|    readstat_error_t retval = READSTAT_OK;
  608|    405|    ssize_t bytes_decompressed = 0;
  609|       |
  610|    405|    bytes_decompressed = sas_rle_decompress(ctx->row, ctx->row_length, subheader, len);
  611|       |
  612|    405|    if (bytes_decompressed != ctx->row_length) {
  ------------------
  |  Branch (612:9): [True: 130, False: 275]
  ------------------
  613|    130|        retval = READSTAT_ERROR_ROW_WIDTH_MISMATCH;
  614|    130|        if (ctx->handle.error) {
  ------------------
  |  Branch (614:13): [True: 0, False: 130]
  ------------------
  615|      0|            snprintf(ctx->error_buf, sizeof(ctx->error_buf), 
  616|      0|                    "ReadStat: Row #%d decompressed to %ld bytes (expected %d bytes)",
  617|      0|                    ctx->parsed_row_count, (long)(bytes_decompressed), ctx->row_length);
  618|      0|            ctx->handle.error(ctx->error_buf, ctx->user_ctx);
  619|      0|        }
  620|    130|        goto cleanup;
  621|    130|    }
  622|    275|    retval = sas7bdat_parse_single_row(ctx->row, ctx);
  623|       |
  624|    405|cleanup:
  625|    405|    return retval;
  626|    275|}
readstat_sas7bdat_read.c:sas7bdat_register_deleted_row:
  427|  4.40k|static readstat_error_t sas7bdat_register_deleted_row(sas7bdat_ctx_t *ctx) {
  428|  4.40k|    if (ctx->parsed_deleted_row_count >= ctx->deleted_row_count) {
  ------------------
  |  Branch (428:9): [True: 4, False: 4.39k]
  ------------------
  429|      4|        return READSTAT_ERROR_PARSE;
  430|      4|    }
  431|  4.39k|    ctx->parsed_deleted_row_count++;
  432|  4.39k|    return READSTAT_OK;
  433|  4.40k|}
readstat_sas7bdat_read.c:sas7bdat_parse_deleted_row_bitmap:
 1015|    668|        sas7bdat_ctx_t *ctx) {
 1016|    668|    uint64_t page_unused_bytes;
 1017|    668|    if (ctx->u64) {
  ------------------
  |  Branch (1017:9): [True: 524, False: 144]
  ------------------
 1018|    524|        page_unused_bytes = sas_read8(&page[24], ctx->bswap);
 1019|    524|    } else {
 1020|    144|        page_unused_bytes = sas_read4(&page[12], ctx->bswap);
 1021|    144|    }
 1022|    668|    uint32_t row_count = ctx->page_row_count < ctx->total_row_count ? ctx->page_row_count : ctx->total_row_count;
  ------------------
  |  Branch (1022:26): [True: 325, False: 343]
  ------------------
 1023|    668|    uint64_t deleted_row_bitmap_offset = (uint64_t)row_count * ctx->row_length + page_unused_bytes;
 1024|    668|    uint32_t required_bytes = row_count / CHAR_BIT + (row_count % CHAR_BIT == 0 ? 0 : 1);
  ------------------
  |  Branch (1024:55): [True: 573, False: 95]
  ------------------
 1025|       |
 1026|    668|    if ((data - page) + deleted_row_bitmap_offset + required_bytes > page_size) {
  ------------------
  |  Branch (1026:9): [True: 111, False: 557]
  ------------------
 1027|    111|        return READSTAT_ERROR_PARSE;
 1028|    111|    }
 1029|    557|    *deleted_row_bitmap = (const unsigned char *)data + deleted_row_bitmap_offset;
 1030|    557|    *deleted_row_bitmap_row_count = row_count;
 1031|    557|    return READSTAT_OK;
 1032|    668|}
readstat_sas7bdat_read.c:sas7bdat_parse_rows:
  547|  2.48k|        const unsigned char *deleted_bitmap, uint32_t deleted_bitmap_row_count, sas7bdat_ctx_t *ctx) {
  548|  2.48k|    readstat_error_t retval = READSTAT_OK;
  549|  2.48k|    uint32_t i;
  550|  2.48k|    size_t row_offset=0;
  551|  47.1k|    for (i=0; i<ctx->page_row_count && ctx->parsed_row_count < ctx->row_limit; i++) {
  ------------------
  |  Branch (551:15): [True: 45.5k, False: 1.61k]
  |  Branch (551:40): [True: 44.7k, False: 715]
  ------------------
  552|  44.7k|        if (row_offset + ctx->row_length > len) {
  ------------------
  |  Branch (552:13): [True: 75, False: 44.7k]
  ------------------
  553|     75|            retval = READSTAT_ERROR_ROW_WIDTH_MISMATCH;
  554|     75|            goto cleanup;
  555|     75|        }
  556|  44.7k|        if (deleted_bitmap != NULL && i >= deleted_bitmap_row_count) {
  ------------------
  |  Branch (556:13): [True: 13.3k, False: 31.4k]
  |  Branch (556:39): [True: 3, False: 13.3k]
  ------------------
  557|       |            /* The page claims more rows than the deleted-row bitmap covers */
  558|      3|            retval = READSTAT_ERROR_PARSE;
  559|      3|            goto cleanup;
  560|      3|        }
  561|  44.7k|        if (deleted_bitmap != NULL && sas7bdat_read_bitmap(deleted_bitmap, i)) {
  ------------------
  |  Branch (561:13): [True: 13.3k, False: 31.4k]
  |  Branch (561:39): [True: 4.03k, False: 9.27k]
  ------------------
  562|  4.03k|            if ((retval = sas7bdat_register_deleted_row(ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (562:17): [True: 3, False: 4.02k]
  ------------------
  563|      3|                goto cleanup;
  564|      3|            }
  565|  40.6k|        } else if ((retval = sas7bdat_parse_single_row(&data[row_offset], ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (565:20): [True: 71, False: 40.6k]
  ------------------
  566|     71|            goto cleanup;
  567|     71|        }
  568|       |
  569|  44.6k|        row_offset += ctx->row_length;
  570|  44.6k|    }
  571|       |
  572|  2.48k|cleanup:
  573|  2.48k|    return retval;
  574|  2.48k|}
readstat_sas7bdat_read.c:sas7bdat_read_bitmap:
  539|  13.3k|static unsigned char sas7bdat_read_bitmap(const unsigned char *bitmap, int index) {
  540|  13.3k|    unsigned char current_byte = bitmap[index / CHAR_BIT];
  541|  13.3k|    unsigned char mask = 1 << (CHAR_BIT - 1 - index % CHAR_BIT);
  542|       |
  543|  13.3k|    return current_byte & mask;
  544|  13.3k|}
readstat_sas7bdat_read.c:sas7bdat_submit_columns_if_needed:
  838|  5.95k|static readstat_error_t sas7bdat_submit_columns_if_needed(sas7bdat_ctx_t *ctx, int compressed) {
  839|  5.95k|    readstat_error_t retval = READSTAT_OK;
  840|  5.95k|    if (!ctx->did_submit_columns) {
  ------------------
  |  Branch (840:9): [True: 1.58k, False: 4.37k]
  ------------------
  841|  1.58k|        if ((retval = sas7bdat_submit_columns(ctx, compressed)) != READSTAT_OK) {
  ------------------
  |  Branch (841:13): [True: 243, False: 1.33k]
  ------------------
  842|    243|            goto cleanup;
  843|    243|        }
  844|  1.33k|        ctx->did_submit_columns = 1;
  845|  1.33k|    }
  846|  5.95k|cleanup:
  847|  5.95k|    return retval;
  848|  5.95k|}
readstat_sas7bdat_read.c:sas7bdat_submit_columns:
  777|  1.58k|static readstat_error_t sas7bdat_submit_columns(sas7bdat_ctx_t *ctx, int compressed) {
  778|  1.58k|    readstat_error_t retval = READSTAT_OK;
  779|  1.58k|    if (ctx->handle.metadata) {
  ------------------
  |  Branch (779:9): [True: 1.58k, False: 0]
  ------------------
  780|  1.58k|        readstat_metadata_t metadata = {
  781|  1.58k|            .row_count = ctx->row_limit,
  782|  1.58k|            .var_count = ctx->column_count,
  783|  1.58k|            .table_name = ctx->table_name,
  784|  1.58k|            .file_label = ctx->file_label,
  785|  1.58k|            .file_encoding = ctx->input_encoding, /* orig encoding? */
  786|  1.58k|            .creation_time = ctx->ctime,
  787|  1.58k|            .modified_time = ctx->mtime,
  788|  1.58k|            .file_format_version = ctx->version,
  789|  1.58k|            .compression = READSTAT_COMPRESS_NONE,
  790|  1.58k|            .endianness = ctx->little_endian ? READSTAT_ENDIAN_LITTLE : READSTAT_ENDIAN_BIG,
  ------------------
  |  Branch (790:27): [True: 292, False: 1.29k]
  ------------------
  791|  1.58k|            .is64bit = ctx->u64
  792|  1.58k|        };
  793|  1.58k|        if (compressed) {
  ------------------
  |  Branch (793:13): [True: 676, False: 906]
  ------------------
  794|    676|            if (ctx->rdc_compression) {
  ------------------
  |  Branch (794:17): [True: 113, False: 563]
  ------------------
  795|    113|                metadata.compression = READSTAT_COMPRESS_BINARY;
  796|    563|            } else {
  797|    563|                metadata.compression = READSTAT_COMPRESS_ROWS;
  798|    563|            }
  799|    676|        }
  800|  1.58k|        if (ctx->handle.metadata(&metadata, ctx->user_ctx) != READSTAT_HANDLER_OK) {
  ------------------
  |  |   22|  1.58k|#define READSTAT_HANDLER_OK             0
  ------------------
  |  Branch (800:13): [True: 0, False: 1.58k]
  ------------------
  801|      0|            retval = READSTAT_ERROR_USER_ABORT;
  802|      0|            goto cleanup;
  803|      0|        }
  804|  1.58k|    }
  805|  1.58k|    if (ctx->column_count == 0)
  ------------------
  |  Branch (805:9): [True: 1.10k, False: 480]
  ------------------
  806|  1.10k|        goto cleanup;
  807|       |
  808|    480|    if ((ctx->variables = readstat_calloc(ctx->column_count, sizeof(readstat_variable_t *))) == NULL) {
  ------------------
  |  Branch (808:9): [True: 0, False: 480]
  ------------------
  809|      0|        retval = READSTAT_ERROR_MALLOC;
  810|      0|        goto cleanup;
  811|      0|    }
  812|    480|    int i;
  813|    480|    int index_after_skipping = 0;
  814|  3.27M|    for (i=0; i<ctx->column_count; i++) {
  ------------------
  |  Branch (814:15): [True: 3.27M, False: 237]
  ------------------
  815|  3.27M|        ctx->variables[i] = sas7bdat_init_variable(ctx, i, index_after_skipping, &retval);
  816|  3.27M|        if (ctx->variables[i] == NULL)
  ------------------
  |  Branch (816:13): [True: 243, False: 3.27M]
  ------------------
  817|    243|            break;
  818|       |
  819|  3.27M|        int cb_retval = READSTAT_HANDLER_OK;
  ------------------
  |  |   22|  3.27M|#define READSTAT_HANDLER_OK             0
  ------------------
  820|  3.27M|        if (ctx->handle.variable) {
  ------------------
  |  Branch (820:13): [True: 3.27M, False: 0]
  ------------------
  821|  3.27M|            cb_retval = ctx->handle.variable(i, ctx->variables[i], ctx->variables[i]->format, ctx->user_ctx);
  822|  3.27M|        }
  823|  3.27M|        if (cb_retval == READSTAT_HANDLER_ABORT) {
  ------------------
  |  |   23|  3.27M|#define READSTAT_HANDLER_ABORT          1
  ------------------
  |  Branch (823:13): [True: 0, False: 3.27M]
  ------------------
  824|      0|            retval = READSTAT_ERROR_USER_ABORT;
  825|      0|            goto cleanup;
  826|      0|        }
  827|       |
  828|  3.27M|        if (cb_retval == READSTAT_HANDLER_SKIP_VARIABLE) {
  ------------------
  |  |   24|  3.27M|#define READSTAT_HANDLER_SKIP_VARIABLE  2
  ------------------
  |  Branch (828:13): [True: 0, False: 3.27M]
  ------------------
  829|      0|            ctx->variables[i]->skip = 1;
  830|  3.27M|        } else {
  831|  3.27M|            index_after_skipping++;
  832|  3.27M|        }
  833|  3.27M|    }
  834|  1.58k|cleanup:
  835|  1.58k|    return retval;
  836|    480|}
readstat_sas7bdat_read.c:sas7bdat_init_variable:
  724|  3.27M|        int index_after_skipping, readstat_error_t *out_retval) {
  725|  3.27M|    readstat_error_t retval = READSTAT_OK;
  726|  3.27M|    readstat_variable_t *variable = readstat_calloc(1, sizeof(readstat_variable_t));
  727|       |
  728|  3.27M|    variable->index = i;
  729|  3.27M|    variable->index_after_skipping = index_after_skipping;
  730|  3.27M|    variable->type = ctx->col_info[i].type;
  731|  3.27M|    variable->storage_width = ctx->col_info[i].width;
  732|       |
  733|  3.27M|    if ((retval = sas7bdat_validate_column(&ctx->col_info[i])) != READSTAT_OK) {
  ------------------
  |  Branch (733:9): [True: 54, False: 3.27M]
  ------------------
  734|     54|        goto cleanup;
  735|     54|    }
  736|  3.27M|    if ((retval = sas7bdat_copy_text_ref(variable->name, sizeof(variable->name), 
  ------------------
  |  Branch (736:9): [True: 54, False: 3.27M]
  ------------------
  737|  3.27M|                    ctx->col_info[i].name_ref, ctx)) != READSTAT_OK) {
  738|     54|        goto cleanup;
  739|     54|    }
  740|  3.27M|    if ((retval = sas7bdat_construct_format(variable->format, sizeof(variable->format),
  ------------------
  |  Branch (740:9): [True: 49, False: 3.27M]
  ------------------
  741|  3.27M|                    ctx->col_info[i].format_ref, ctx->col_info[i].format_width,
  742|  3.27M|                    ctx->col_info[i].format_digits, ctx)) != READSTAT_OK) {
  743|     49|        goto cleanup;
  744|     49|    }
  745|  3.27M|    if ((retval = sas7bdat_construct_format(variable->informat, sizeof(variable->informat),
  ------------------
  |  Branch (745:9): [True: 39, False: 3.27M]
  ------------------
  746|  3.27M|                    ctx->col_info[i].informat_ref, ctx->col_info[i].informat_width,
  747|  3.27M|                    ctx->col_info[i].informat_digits, ctx)) != READSTAT_OK) {
  748|     39|        goto cleanup;
  749|     39|    }
  750|  3.27M|    if ((retval = sas7bdat_copy_text_ref(variable->label, sizeof(variable->label), 
  ------------------
  |  Branch (750:9): [True: 47, False: 3.27M]
  ------------------
  751|  3.27M|                    ctx->col_info[i].label_ref, ctx)) != READSTAT_OK) {
  752|     47|        goto cleanup;
  753|     47|    }
  754|       |
  755|  3.27M|cleanup:
  756|  3.27M|    if (retval != READSTAT_OK) {
  ------------------
  |  Branch (756:9): [True: 243, False: 3.27M]
  ------------------
  757|    243|        if (out_retval)
  ------------------
  |  Branch (757:13): [True: 243, False: 0]
  ------------------
  758|    243|            *out_retval = retval;
  759|       |
  760|    243|        if (retval == READSTAT_ERROR_CONVERT_BAD_STRING) {
  ------------------
  |  Branch (760:13): [True: 6, False: 237]
  ------------------
  761|      6|            if (ctx->handle.error) {
  ------------------
  |  Branch (761:17): [True: 0, False: 6]
  ------------------
  762|      0|                snprintf(ctx->error_buf, sizeof(ctx->error_buf),
  763|      0|                        "ReadStat: Error converting variable #%d info to specified encoding: %s %s (%s)",
  764|      0|                        i, variable->name, variable->format, variable->label);
  765|      0|                ctx->handle.error(ctx->error_buf, ctx->user_ctx);
  766|      0|            }
  767|      6|        }
  768|       |
  769|    243|        free(variable);
  770|       |
  771|    243|        return NULL;
  772|    243|    }
  773|       |
  774|  3.27M|    return variable;
  775|  3.27M|}
readstat_sas7bdat_read.c:sas7bdat_validate_column:
  670|  3.27M|static readstat_error_t sas7bdat_validate_column(col_info_t *col_info) {
  671|  3.27M|    if (col_info->type == READSTAT_TYPE_DOUBLE) {
  ------------------
  |  Branch (671:9): [True: 1.11k, False: 3.27M]
  ------------------
  672|  1.11k|        if (col_info->width > 8 || col_info->width < 3) {
  ------------------
  |  Branch (672:13): [True: 26, False: 1.08k]
  |  Branch (672:36): [True: 1, False: 1.08k]
  ------------------
  673|     27|            return READSTAT_ERROR_PARSE;
  674|     27|        }
  675|  1.11k|    }
  676|  3.27M|    if (col_info->type == READSTAT_TYPE_STRING) {
  ------------------
  |  Branch (676:9): [True: 3.27M, False: 1.08k]
  ------------------
  677|  3.27M|        if (col_info->width > INT16_MAX) {
  ------------------
  |  Branch (677:13): [True: 27, False: 3.27M]
  ------------------
  678|     27|            return READSTAT_ERROR_PARSE;
  679|     27|        }
  680|  3.27M|    }
  681|  3.27M|    return READSTAT_OK;
  682|  3.27M|}
readstat_sas7bdat_read.c:sas7bdat_construct_format:
  685|  6.54M|        sas_text_ref_t text_ref, int width, int digits, sas7bdat_ctx_t *ctx) {
  686|  6.54M|    readstat_error_t retval = sas7bdat_copy_text_ref(dst, dst_len, text_ref, ctx);
  687|  6.54M|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (687:9): [True: 65, False: 6.54M]
  ------------------
  688|     65|        return retval;
  689|       |
  690|       |    /* Digits require a width */
  691|  6.54M|    if (width == 0 && digits != 0)
  ------------------
  |  Branch (691:9): [True: 6.54M, False: 1.19k]
  |  Branch (691:23): [True: 16, False: 6.54M]
  ------------------
  692|     16|        return READSTAT_ERROR_PARSE;
  693|       |
  694|  6.54M|    if (strchr(dst, '.')) {
  ------------------
  |  Branch (694:9): [True: 88, False: 6.54M]
  ------------------
  695|       |        /* Legacy layout: earlier ReadStat writers stored the full format
  696|       |         * string (e.g. "YYMMDD10." or "BEST.") verbatim as the name, with
  697|       |         * width and digits both 0. Return it unchanged. */
  698|     88|        if (width == 0 && digits == 0)
  ------------------
  |  Branch (698:13): [True: 85, False: 3]
  |  Branch (698:27): [True: 85, False: 0]
  ------------------
  699|     85|            return READSTAT_OK;
  700|      3|        return READSTAT_ERROR_PARSE;
  701|     88|    }
  702|       |
  703|       |    /* No format at all */
  704|  6.54M|    if (dst[0] == '\0' && width == 0)
  ------------------
  |  Branch (704:9): [True: 6.54M, False: 619]
  |  Branch (704:27): [True: 6.54M, False: 898]
  ------------------
  705|  6.54M|        return READSTAT_OK;
  706|       |
  707|       |    /* NAME. / NAMEw. / NAMEw.d (NAME may be empty, as in the w.d format) */
  708|  1.51k|    size_t len = strlen(dst);
  709|  1.51k|    int written;
  710|  1.51k|    if (digits) {
  ------------------
  |  Branch (710:9): [True: 814, False: 703]
  ------------------
  711|    814|        written = snprintf(dst + len, dst_len - len, "%d.%d", width, digits);
  712|    814|    } else if (width) {
  ------------------
  |  Branch (712:16): [True: 380, False: 323]
  ------------------
  713|    380|        written = snprintf(dst + len, dst_len - len, "%d.", width);
  714|    380|    } else {
  715|    323|        written = snprintf(dst + len, dst_len - len, ".");
  716|    323|    }
  717|  1.51k|    if (written < 0 || (size_t)written >= dst_len - len)
  ------------------
  |  Branch (717:9): [True: 0, False: 1.51k]
  |  Branch (717:24): [True: 4, False: 1.51k]
  ------------------
  718|      4|        return READSTAT_ERROR_PARSE;
  719|       |
  720|  1.51k|    return READSTAT_OK;
  721|  1.51k|}
readstat_sas7bdat_read.c:sas7bdat_update_progress:
  142|  7.10k|static readstat_error_t sas7bdat_update_progress(sas7bdat_ctx_t *ctx) {
  143|  7.10k|    readstat_io_t *io = ctx->io;
  144|  7.10k|    return io->update(ctx->file_size, ctx->handle.progress, ctx->user_ctx, io->io_ctx);
  145|  7.10k|}
readstat_sas7bdat_read.c:sas7bdat_ctx_free:
  105|  4.50k|static void sas7bdat_ctx_free(sas7bdat_ctx_t *ctx) {
  106|  4.50k|    int i;
  107|  4.50k|    if (ctx->text_blobs) {
  ------------------
  |  Branch (107:9): [True: 919, False: 3.58k]
  ------------------
  108|  7.07k|        for (i=0; i<ctx->text_blob_count; i++) {
  ------------------
  |  Branch (108:19): [True: 6.15k, False: 919]
  ------------------
  109|  6.15k|            free(ctx->text_blobs[i]);
  110|  6.15k|        }
  111|    919|        free(ctx->text_blobs);
  112|    919|        free(ctx->text_blob_lengths);
  113|    919|    }
  114|  4.50k|    if (ctx->variables) {
  ------------------
  |  Branch (114:9): [True: 480, False: 4.02k]
  ------------------
  115|  15.1M|        for (i=0; i<ctx->column_count; i++) {
  ------------------
  |  Branch (115:19): [True: 15.1M, False: 480]
  ------------------
  116|  15.1M|            if (ctx->variables[i])
  ------------------
  |  Branch (116:17): [True: 3.27M, False: 11.8M]
  ------------------
  117|  3.27M|                free(ctx->variables[i]);
  118|  15.1M|        }
  119|    480|        free(ctx->variables);
  120|    480|    }
  121|  4.50k|    if (ctx->col_info)
  ------------------
  |  Branch (121:9): [True: 687, False: 3.81k]
  ------------------
  122|    687|        free(ctx->col_info);
  123|       |
  124|  4.50k|    if (ctx->scratch_buffer)
  ------------------
  |  Branch (124:9): [True: 325, False: 4.18k]
  ------------------
  125|    325|        free(ctx->scratch_buffer);
  126|       |
  127|  4.50k|    if (ctx->page)
  ------------------
  |  Branch (127:9): [True: 3.96k, False: 542]
  ------------------
  128|  3.96k|        free(ctx->page);
  129|       |
  130|  4.50k|    if (ctx->moved_page)
  ------------------
  |  Branch (130:9): [True: 526, False: 3.97k]
  ------------------
  131|    526|        free(ctx->moved_page);
  132|       |
  133|  4.50k|    if (ctx->row)
  ------------------
  |  Branch (133:9): [True: 866, False: 3.63k]
  ------------------
  134|    866|        free(ctx->row);
  135|       |
  136|  4.50k|    if (ctx->converter)
  ------------------
  |  Branch (136:9): [True: 2.66k, False: 1.84k]
  ------------------
  137|  2.66k|        iconv_close(ctx->converter);
  138|       |
  139|  4.50k|    free(ctx);
  140|  4.50k|}

sas_rdc_decompress:
   39|    398|        const void *input_buf, size_t input_len) {
   40|    398|    const unsigned char *input = (const unsigned char *)input_buf;
   41|    398|    const unsigned char *input_end = input + input_len;
   42|    398|    unsigned char *buffer = (unsigned char *)output_buf;
   43|    398|    size_t out = 0;
   44|       |
   45|  2.73k|    while (input + 2 <= input_end) {
  ------------------
  |  Branch (45:12): [True: 2.40k, False: 324]
  ------------------
   46|  2.40k|        int i;
   47|  2.40k|        unsigned short prefix = (input[0] << 8) + input[1];
   48|  2.40k|        input += 2;
   49|  36.9k|        for (i=0; i<16; i++) {
  ------------------
  |  Branch (49:19): [True: 34.9k, False: 2.02k]
  ------------------
   50|  34.9k|            if ((prefix & (1 << (15 - i))) == 0) {
  ------------------
  |  Branch (50:17): [True: 25.7k, False: 9.18k]
  ------------------
   51|  25.7k|                if (input + 1 > input_end)
  ------------------
  |  Branch (51:21): [True: 312, False: 25.4k]
  ------------------
   52|    312|                    break;
   53|  25.4k|                if (buffer) {
  ------------------
  |  Branch (53:21): [True: 25.4k, False: 0]
  ------------------
   54|  25.4k|                    if (out + 1 > output_len)
  ------------------
  |  Branch (54:25): [True: 4, False: 25.4k]
  ------------------
   55|      4|                        return -1;
   56|  25.4k|                    buffer[out] = *input;
   57|  25.4k|                }
   58|  25.4k|                input++;
   59|  25.4k|                out++;
   60|  25.4k|                continue;
   61|  25.4k|            }
   62|       |
   63|  9.18k|            if (input + 2 > input_end)
  ------------------
  |  Branch (63:17): [True: 4, False: 9.17k]
  ------------------
   64|      4|                return -1;
   65|       |
   66|  9.17k|            unsigned char marker_byte = *input++;
   67|  9.17k|            unsigned char next_byte = *input++;
   68|  9.17k|            size_t insert_len = 0, copy_len = 0;
   69|  9.17k|            unsigned char insert_byte = 0x00;
   70|  9.17k|            size_t back_offset = 0;
   71|       |
   72|  9.17k|            if (marker_byte <= 0x0F) {
  ------------------
  |  Branch (72:17): [True: 3.60k, False: 5.57k]
  ------------------
   73|  3.60k|                insert_len = 3 + marker_byte;
   74|  3.60k|                insert_byte = next_byte;
   75|  5.57k|            } else if ((marker_byte >> 4) == 1) {
  ------------------
  |  Branch (75:24): [True: 2.33k, False: 3.24k]
  ------------------
   76|  2.33k|                if (input + 1 > input_end)
  ------------------
  |  Branch (76:21): [True: 2, False: 2.33k]
  ------------------
   77|      2|                    return -1;
   78|  2.33k|                insert_len = 19 + (marker_byte & 0x0F) + next_byte * 16;
   79|  2.33k|                insert_byte = *input++;
   80|  3.24k|            } else if ((marker_byte >> 4) == 2) {
  ------------------
  |  Branch (80:24): [True: 462, False: 2.78k]
  ------------------
   81|    462|                if (input + 1 > input_end)
  ------------------
  |  Branch (81:21): [True: 1, False: 461]
  ------------------
   82|      1|                    return -1;
   83|    461|                copy_len = 16 + (*input++);
   84|    461|                back_offset = 3 + (marker_byte & 0x0F) + next_byte * 16;
   85|  2.78k|            } else {
   86|  2.78k|                copy_len = (marker_byte >> 4);
   87|  2.78k|                back_offset = 3 + (marker_byte & 0x0F) + next_byte * 16;
   88|  2.78k|            }
   89|       |
   90|  9.17k|            if (insert_len) {
  ------------------
  |  Branch (90:17): [True: 5.93k, False: 3.24k]
  ------------------
   91|  5.93k|                if (buffer) {
  ------------------
  |  Branch (91:21): [True: 5.93k, False: 0]
  ------------------
   92|  5.93k|                    if (out + insert_len > output_len)
  ------------------
  |  Branch (92:25): [True: 16, False: 5.91k]
  ------------------
   93|     16|                        return -1;
   94|  5.91k|                    memset(&buffer[out], insert_byte, insert_len);
   95|  5.91k|                }
   96|  5.91k|                out += insert_len;
   97|  5.91k|            } else if (copy_len) {
  ------------------
  |  Branch (97:24): [True: 3.24k, False: 0]
  ------------------
   98|  3.24k|                if (out < back_offset || copy_len > back_offset)
  ------------------
  |  Branch (98:21): [True: 15, False: 3.22k]
  |  Branch (98:42): [True: 24, False: 3.20k]
  ------------------
   99|     39|                    return -1;
  100|  3.20k|                if (buffer) {
  ------------------
  |  Branch (100:21): [True: 3.20k, False: 0]
  ------------------
  101|  3.20k|                    if (out + copy_len > output_len)
  ------------------
  |  Branch (101:25): [True: 8, False: 3.19k]
  ------------------
  102|      8|                        return -1;
  103|  3.19k|                    memcpy(&buffer[out], &buffer[out - back_offset], copy_len);
  104|  3.19k|                }
  105|  3.19k|                out += copy_len;
  106|  3.19k|            }
  107|  9.17k|        }
  108|  2.40k|    }
  109|       |
  110|    324|    return out;
  111|    398|}

sas_rle_decompress:
   47|    405|        const void *input_buf, size_t input_len) {
   48|    405|    unsigned char *buffer = (unsigned char *)output_buf;
   49|    405|    unsigned char *output = buffer;
   50|    405|    size_t output_written = 0;
   51|       |
   52|    405|    const unsigned char *input = (const unsigned char *)input_buf;
   53|       |
   54|  95.5k|    while (input < (const unsigned char *)input_buf + input_len) {
  ------------------
  |  Branch (54:12): [True: 95.2k, False: 283]
  ------------------
   55|  95.2k|        unsigned char control = *input++;
   56|  95.2k|        unsigned char command = (control & 0xF0) >> 4;
   57|  95.2k|        unsigned char length = (control & 0x0F);
   58|  95.2k|        int copy_len = 0;
   59|  95.2k|        int insert_len = 0;
   60|  95.2k|        unsigned char insert_byte = '\0';
   61|  95.2k|        if (input + command_lengths[command] > (const unsigned char *)input_buf + input_len) {
  ------------------
  |  Branch (61:13): [True: 6, False: 95.2k]
  ------------------
   62|      6|            return -1;
   63|      6|        }
   64|  95.2k|        switch (command) {
   65|  6.14k|            case SAS_RLE_COMMAND_COPY64:
  ------------------
  |  |   13|  6.14k|#define SAS_RLE_COMMAND_COPY64          0
  ------------------
  |  Branch (65:13): [True: 6.14k, False: 89.1k]
  ------------------
   66|  6.14k|                copy_len = (*input++) + 64 + length * 256;
   67|  6.14k|                break;
   68|    223|            case SAS_RLE_COMMAND_COPY64_PLUS_4096:
  ------------------
  |  |   14|    223|#define SAS_RLE_COMMAND_COPY64_PLUS_4096 1
  ------------------
  |  Branch (68:13): [True: 223, False: 95.0k]
  ------------------
   69|    223|                copy_len = (*input++) + 64 + length * 256 + 4096;
   70|    223|                break;
   71|    619|            case SAS_RLE_COMMAND_COPY96: copy_len = length + 96; break;
  ------------------
  |  |   15|    619|#define SAS_RLE_COMMAND_COPY96          2
  ------------------
  |  Branch (71:13): [True: 619, False: 94.6k]
  ------------------
   72|  1.49k|            case SAS_RLE_COMMAND_INSERT_BYTE18:
  ------------------
  |  |   16|  1.49k|#define SAS_RLE_COMMAND_INSERT_BYTE18   4
  ------------------
  |  Branch (72:13): [True: 1.49k, False: 93.7k]
  ------------------
   73|  1.49k|                insert_len = (*input++) + 18 + length * 256;
   74|  1.49k|                insert_byte = *input++;
   75|  1.49k|                break;
   76|    895|            case SAS_RLE_COMMAND_INSERT_AT17:
  ------------------
  |  |   17|    895|#define SAS_RLE_COMMAND_INSERT_AT17     5
  ------------------
  |  Branch (76:13): [True: 895, False: 94.3k]
  ------------------
   77|    895|                insert_len = (*input++) + 17 + length * 256;
   78|    895|                insert_byte = '@';
   79|    895|                break;
   80|    821|            case SAS_RLE_COMMAND_INSERT_BLANK17:
  ------------------
  |  |   18|    821|#define SAS_RLE_COMMAND_INSERT_BLANK17  6
  ------------------
  |  Branch (80:13): [True: 821, False: 94.4k]
  ------------------
   81|    821|                insert_len = (*input++) + 17 + length * 256;
   82|    821|                insert_byte = ' ';
   83|    821|                break;
   84|  52.8k|            case SAS_RLE_COMMAND_INSERT_ZERO17:
  ------------------
  |  |   19|  52.8k|#define SAS_RLE_COMMAND_INSERT_ZERO17   7
  ------------------
  |  Branch (84:13): [True: 52.8k, False: 42.4k]
  ------------------
   85|  52.8k|                insert_len = (*input++) + 17 + length * 256;
   86|  52.8k|                insert_byte = '\0';
   87|  52.8k|                break;
   88|  1.14k|            case SAS_RLE_COMMAND_COPY1:  copy_len = length + 1; break;
  ------------------
  |  |   20|  1.14k|#define SAS_RLE_COMMAND_COPY1           8
  ------------------
  |  Branch (88:13): [True: 1.14k, False: 94.1k]
  ------------------
   89|  1.01k|            case SAS_RLE_COMMAND_COPY17: copy_len = length + 17; break;
  ------------------
  |  |   21|  1.01k|#define SAS_RLE_COMMAND_COPY17          9
  ------------------
  |  Branch (89:13): [True: 1.01k, False: 94.2k]
  ------------------
   90|    972|            case SAS_RLE_COMMAND_COPY33: copy_len = length + 33; break;
  ------------------
  |  |   22|    972|#define SAS_RLE_COMMAND_COPY33         10
  ------------------
  |  Branch (90:13): [True: 972, False: 94.3k]
  ------------------
   91|    341|            case SAS_RLE_COMMAND_COPY49: copy_len = length + 49; break;
  ------------------
  |  |   23|    341|#define SAS_RLE_COMMAND_COPY49         11
  ------------------
  |  Branch (91:13): [True: 341, False: 94.9k]
  ------------------
   92|    596|            case SAS_RLE_COMMAND_INSERT_BYTE3:
  ------------------
  |  |   24|    596|#define SAS_RLE_COMMAND_INSERT_BYTE3   12
  ------------------
  |  Branch (92:13): [True: 596, False: 94.6k]
  ------------------
   93|    596|                insert_byte = *input++;
   94|    596|                insert_len = length + 3;
   95|    596|                break;
   96|  2.16k|            case SAS_RLE_COMMAND_INSERT_AT2:
  ------------------
  |  |   25|  2.16k|#define SAS_RLE_COMMAND_INSERT_AT2     13
  ------------------
  |  Branch (96:13): [True: 2.16k, False: 93.1k]
  ------------------
   97|  2.16k|                insert_byte = '@';
   98|  2.16k|                insert_len = length + 2;
   99|  2.16k|                break;
  100|  12.9k|            case SAS_RLE_COMMAND_INSERT_BLANK2:
  ------------------
  |  |   26|  12.9k|#define SAS_RLE_COMMAND_INSERT_BLANK2  14
  ------------------
  |  Branch (100:13): [True: 12.9k, False: 82.3k]
  ------------------
  101|  12.9k|                insert_byte = ' ';
  102|  12.9k|                insert_len = length + 2;
  103|  12.9k|                break;
  104|  9.68k|            case SAS_RLE_COMMAND_INSERT_ZERO2:
  ------------------
  |  |   27|  9.68k|#define SAS_RLE_COMMAND_INSERT_ZERO2   15
  ------------------
  |  Branch (104:13): [True: 9.68k, False: 85.5k]
  ------------------
  105|  9.68k|                insert_byte = '\0';
  106|  9.68k|                insert_len = length + 2;
  107|  9.68k|                break;
  108|  3.33k|            default:
  ------------------
  |  Branch (108:13): [True: 3.33k, False: 91.9k]
  ------------------
  109|       |                /* error out here? */
  110|  3.33k|                break;
  111|  95.2k|        }
  112|  95.2k|        if (copy_len) {
  ------------------
  |  Branch (112:13): [True: 10.4k, False: 84.8k]
  ------------------
  113|  10.4k|            if (output_written + copy_len > output_len) {
  ------------------
  |  Branch (113:17): [True: 20, False: 10.4k]
  ------------------
  114|     20|                return -1;
  115|     20|            }
  116|  10.4k|            if (input + copy_len > (const unsigned char *)input_buf + input_len) {
  ------------------
  |  Branch (116:17): [True: 80, False: 10.3k]
  ------------------
  117|     80|                return -1;
  118|     80|            }
  119|  10.3k|            if (output) {
  ------------------
  |  Branch (119:17): [True: 10.3k, False: 0]
  ------------------
  120|  10.3k|                memcpy(&output[output_written], input, copy_len);
  121|  10.3k|            }
  122|  10.3k|            input += copy_len;
  123|  10.3k|            output_written += copy_len;
  124|  10.3k|        }
  125|  95.1k|        if (insert_len) {
  ------------------
  |  Branch (125:13): [True: 81.4k, False: 13.6k]
  ------------------
  126|  81.4k|            if (output_written + insert_len > output_len) {
  ------------------
  |  Branch (126:17): [True: 16, False: 81.4k]
  ------------------
  127|     16|                return -1;
  128|     16|            }
  129|  81.4k|            if (output) {
  ------------------
  |  Branch (129:17): [True: 81.4k, False: 0]
  ------------------
  130|  81.4k|                memset(&output[output_written], insert_byte, insert_len);
  131|  81.4k|            }
  132|  81.4k|            output_written += insert_len;
  133|  81.4k|        }
  134|  95.1k|    }
  135|       |
  136|    283|    return output_written;
  137|    405|}

rt_open_handler:
    8|  4.50k|int rt_open_handler(const char *path, void *io_ctx) {
    9|  4.50k|    return 0;
   10|  4.50k|}
rt_close_handler:
   12|  4.50k|int rt_close_handler(void *io_ctx) {
   13|  4.50k|    return 0;
   14|  4.50k|}
rt_seek_handler:
   17|  39.3k|        readstat_io_flags_t whence, void *io_ctx) {
   18|  39.3k|    rt_buffer_ctx_t *buffer_ctx = (rt_buffer_ctx_t *)io_ctx;
   19|  39.3k|    readstat_off_t newpos = -1;
   20|  39.3k|    if (whence == READSTAT_SEEK_SET) {
  ------------------
  |  Branch (20:9): [True: 25.7k, False: 13.5k]
  ------------------
   21|  25.7k|        newpos = offset;
   22|  25.7k|    } else if (whence == READSTAT_SEEK_CUR) {
  ------------------
  |  Branch (22:16): [True: 9.07k, False: 4.50k]
  ------------------
   23|  9.07k|        newpos = buffer_ctx->pos + offset;
   24|  9.07k|    } else if (whence == READSTAT_SEEK_END) {
  ------------------
  |  Branch (24:16): [True: 4.50k, False: 0]
  ------------------
   25|  4.50k|        newpos = buffer_ctx->buffer->used + offset;
   26|  4.50k|    }
   27|       |
   28|  39.3k|    if (newpos < 0)
  ------------------
  |  Branch (28:9): [True: 494, False: 38.8k]
  ------------------
   29|    494|        return -1;
   30|       |
   31|  38.8k|    if (newpos > buffer_ctx->buffer->used)
  ------------------
  |  Branch (31:9): [True: 273, False: 38.6k]
  ------------------
   32|    273|        return -1;
   33|       |
   34|  38.6k|    buffer_ctx->pos = newpos;
   35|  38.6k|    return newpos;
   36|  38.8k|}
rt_read_handler:
   38|  67.7k|ssize_t rt_read_handler(void *buf, size_t nbytes, void *io_ctx) {
   39|  67.7k|    rt_buffer_ctx_t *buffer_ctx = (rt_buffer_ctx_t *)io_ctx;
   40|  67.7k|    ssize_t bytes_copied = 0;
   41|  67.7k|    ssize_t bytes_left = buffer_ctx->buffer->used - buffer_ctx->pos;
   42|  67.7k|    if (nbytes <= bytes_left) {
  ------------------
  |  Branch (42:9): [True: 67.2k, False: 480]
  ------------------
   43|  67.2k|        memcpy(buf, buffer_ctx->buffer->bytes + buffer_ctx->pos, nbytes);
   44|  67.2k|        bytes_copied = nbytes;
   45|  67.2k|    } else if (bytes_left > 0) {
  ------------------
  |  Branch (45:16): [True: 245, False: 235]
  ------------------
   46|    245|        memcpy(buf, buffer_ctx->buffer->bytes + buffer_ctx->pos, bytes_left);
   47|    245|        bytes_copied = bytes_left;
   48|    245|    }
   49|  67.7k|    buffer_ctx->pos += bytes_copied;
   50|  67.7k|    return bytes_copied;
   51|  67.7k|}
rt_update_handler:
   54|  7.10k|        void *user_ctx, void *io_ctx) {
   55|  7.10k|    if (!progress_handler)
  ------------------
  |  Branch (55:9): [True: 7.10k, False: 0]
  ------------------
   56|  7.10k|        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|}

