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

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

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

readstat_convert:
   39|  47.3M|readstat_error_t readstat_convert(char *dst, size_t dst_len, const char *src, size_t src_len, iconv_t converter) {
   40|  47.3M|    return readstat_convert_impl(dst, dst_len, src, src_len, converter, 1);
   41|  47.3M|}
readstat_convert.c:readstat_convert_impl:
    8|  47.3M|        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|  47.3M|    while (src_len && ((trim_spaces && src[src_len-1] == ' ') || src[src_len-1] == '\0')) {
  ------------------
  |  Branch (11:12): [True: 65.6k, False: 47.3M]
  |  Branch (11:25): [True: 65.6k, False: 0]
  |  Branch (11:40): [True: 4.27k, False: 61.4k]
  |  Branch (11:66): [True: 41.1k, False: 20.2k]
  ------------------
   12|  45.4k|        src_len--;
   13|  45.4k|    }
   14|  47.3M|    if (dst_len == 0) {
  ------------------
  |  Branch (14:9): [True: 0, False: 47.3M]
  ------------------
   15|      0|        return READSTAT_ERROR_CONVERT_LONG_STRING;
   16|  47.3M|    } else if (converter) {
  ------------------
  |  Branch (16:16): [True: 650k, False: 46.6M]
  ------------------
   17|   650k|        size_t dst_left = dst_len - 1;
   18|   650k|        char *dst_end = dst;
   19|   650k|        size_t status = iconv(converter, (readstat_iconv_inbuf_t)&src, &src_len, &dst_end, &dst_left);
   20|   650k|        if (status == (size_t)-1) {
  ------------------
  |  Branch (20:13): [True: 2.16k, False: 647k]
  ------------------
   21|  2.16k|            if (errno == E2BIG) {
  ------------------
  |  Branch (21:17): [True: 4, False: 2.15k]
  ------------------
   22|      4|                return READSTAT_ERROR_CONVERT_LONG_STRING;
   23|  2.15k|            } else if (errno == EILSEQ) {
  ------------------
  |  Branch (23:24): [True: 24, False: 2.13k]
  ------------------
   24|     24|                return READSTAT_ERROR_CONVERT_BAD_STRING;
   25|  2.13k|            } else if (errno != EINVAL) { /* EINVAL indicates improper truncation; accept it */
  ------------------
  |  Branch (25:24): [True: 0, False: 2.13k]
  ------------------
   26|      0|                return READSTAT_ERROR_CONVERT;
   27|      0|            }
   28|  2.16k|        }
   29|   650k|        dst[dst_len - dst_left - 1] = '\0';
   30|  46.6M|    } else if (src_len + 1 > dst_len) {
  ------------------
  |  Branch (30:16): [True: 21, False: 46.6M]
  ------------------
   31|     21|        return READSTAT_ERROR_CONVERT_LONG_STRING;
   32|  46.6M|    } else {
   33|  46.6M|        memcpy(dst, src, src_len);
   34|  46.6M|        dst[src_len] = '\0';
   35|  46.6M|    }
   36|  47.3M|    return READSTAT_OK;
   37|  47.3M|}

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

readstat_malloc:
   10|  12.8k|void *readstat_malloc(size_t len) {
   11|  12.8k|    if (len > MAX_MALLOC_SIZE || len == 0) {
  ------------------
  |  |    3|  25.6k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
  |  Branch (11:9): [True: 0, False: 12.8k]
  |  Branch (11:34): [True: 0, False: 12.8k]
  ------------------
   12|      0|        return NULL;
   13|      0|    }
   14|  12.8k|    return malloc(len);
   15|  12.8k|}
readstat_calloc:
   17|  2.30M|void *readstat_calloc(size_t count, size_t size) {
   18|  2.30M|    if (count > MAX_MALLOC_SIZE || size > MAX_MALLOC_SIZE || count * size > MAX_MALLOC_SIZE) {
  ------------------
  |  |    3|  4.61M|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
                  if (count > MAX_MALLOC_SIZE || size > MAX_MALLOC_SIZE || count * size > MAX_MALLOC_SIZE) {
  ------------------
  |  |    3|  4.61M|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
                  if (count > MAX_MALLOC_SIZE || size > MAX_MALLOC_SIZE || count * size > MAX_MALLOC_SIZE) {
  ------------------
  |  |    3|  2.30M|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
  |  Branch (18:9): [True: 0, False: 2.30M]
  |  Branch (18:36): [True: 0, False: 2.30M]
  |  Branch (18:62): [True: 0, False: 2.30M]
  ------------------
   19|      0|        return NULL;
   20|      0|    }
   21|  2.30M|    if (count == 0 || size == 0) {
  ------------------
  |  Branch (21:9): [True: 0, False: 2.30M]
  |  Branch (21:23): [True: 0, False: 2.30M]
  ------------------
   22|      0|        return NULL;
   23|      0|    }
   24|  2.30M|    return calloc(count, size);
   25|  2.30M|}
readstat_realloc:
   27|   215k|void *readstat_realloc(void *ptr, size_t len) {
   28|   215k|    if (len > MAX_MALLOC_SIZE || len == 0) {
  ------------------
  |  |    3|   431k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
  |  Branch (28:9): [True: 96, False: 215k]
  |  Branch (28:34): [True: 3, False: 215k]
  ------------------
   29|     99|        if (ptr)
  ------------------
  |  Branch (29:13): [True: 46, False: 53]
  ------------------
   30|     46|            free(ptr);
   31|     99|        return NULL;
   32|     99|    }
   33|   215k|    return realloc(ptr, len);
   34|   215k|}

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

sas_read8:
  148|  98.4k|uint64_t sas_read8(const char *data, int bswap) {
  149|  98.4k|    uint64_t tmp;
  150|  98.4k|    memcpy(&tmp, data, 8);
  151|  98.4k|    return bswap ? byteswap8(tmp) : tmp;
  ------------------
  |  Branch (151:12): [True: 87.1k, False: 11.2k]
  ------------------
  152|  98.4k|}
sas_read4:
  154|   292k|uint32_t sas_read4(const char *data, int bswap) {
  155|   292k|    uint32_t tmp;
  156|   292k|    memcpy(&tmp, data, 4);
  157|   292k|    return bswap ? byteswap4(tmp) : tmp;
  ------------------
  |  Branch (157:12): [True: 223k, False: 69.0k]
  ------------------
  158|   292k|}
sas_read2:
  160|   207k|uint16_t sas_read2(const char *data, int bswap) {
  161|   207k|    uint16_t tmp;
  162|   207k|    memcpy(&tmp, data, 2);
  163|   207k|    return bswap ? byteswap2(tmp) : tmp;
  ------------------
  |  Branch (163:12): [True: 105k, False: 102k]
  ------------------
  164|   207k|}
sas_subheader_remainder:
  166|  12.9k|size_t sas_subheader_remainder(size_t len, size_t signature_len) {
  167|  12.9k|    return len - (4+2*signature_len);
  168|  12.9k|}
sas_read_header:
  171|  4.47k|        readstat_error_handler error_handler, void *user_ctx) {
  172|  4.47k|    sas_header_start_t  header_start;
  173|  4.47k|    sas_header_end_t    header_end;
  174|  4.47k|    int retval = READSTAT_OK;
  175|  4.47k|    char error_buf[1024];
  176|  4.47k|    time_t epoch = sas_epoch();
  177|       |
  178|  4.47k|    if (io->read(&header_start, sizeof(sas_header_start_t), io->io_ctx) < sizeof(sas_header_start_t)) {
  ------------------
  |  Branch (178:9): [True: 20, False: 4.45k]
  ------------------
  179|     20|        retval = READSTAT_ERROR_READ;
  180|     20|        goto cleanup;
  181|     20|    }
  182|  4.45k|    if (memcmp(header_start.magic, sas7bdat_magic_number, sizeof(sas7bdat_magic_number)) != 0 &&
  ------------------
  |  Branch (182:9): [True: 2.04k, False: 2.40k]
  ------------------
  183|  2.04k|            memcmp(header_start.magic, sas7bdat_magic_number_alt, sizeof(sas7bdat_magic_number_alt)) != 0 &&
  ------------------
  |  Branch (183:13): [True: 2.04k, False: 6]
  ------------------
  184|  2.04k|            memcmp(header_start.magic, sas7bcat_magic_number, sizeof(sas7bcat_magic_number)) != 0) {
  ------------------
  |  Branch (184:13): [True: 135, False: 1.90k]
  ------------------
  185|    135|        retval = READSTAT_ERROR_PARSE;
  186|    135|        goto cleanup;
  187|    135|    }
  188|  4.32k|    if (header_start.a1 == SAS_ALIGNMENT_OFFSET_4) {
  ------------------
  |  |   88|  4.32k|#define SAS_ALIGNMENT_OFFSET_4  0x33
  ------------------
  |  Branch (188:9): [True: 7, False: 4.31k]
  ------------------
  189|      7|        hinfo->pad1 = 4;
  190|      7|    }
  191|  4.32k|    if (header_start.a2 == SAS_ALIGNMENT_OFFSET_4) {
  ------------------
  |  |   88|  4.32k|#define SAS_ALIGNMENT_OFFSET_4  0x33
  ------------------
  |  Branch (191:9): [True: 2.35k, False: 1.96k]
  ------------------
  192|  2.35k|        hinfo->u64 = 1;
  193|  2.35k|    }
  194|  4.32k|    int bswap = 0;
  195|  4.32k|    if (header_start.endian == SAS_ENDIAN_BIG) {
  ------------------
  |  |   81|  4.32k|#define SAS_ENDIAN_BIG       0x00
  ------------------
  |  Branch (195:9): [True: 3.22k, False: 1.09k]
  ------------------
  196|  3.22k|        bswap = machine_is_little_endian();
  197|  3.22k|        hinfo->little_endian = 0;
  198|  3.22k|    } else if (header_start.endian == SAS_ENDIAN_LITTLE) {
  ------------------
  |  |   82|  1.09k|#define SAS_ENDIAN_LITTLE    0x01
  ------------------
  |  Branch (198:16): [True: 1.08k, False: 15]
  ------------------
  199|  1.08k|        bswap = !machine_is_little_endian();
  200|  1.08k|        hinfo->little_endian = 1;
  201|  1.08k|    } else {
  202|     15|        retval = READSTAT_ERROR_PARSE;
  203|     15|        goto cleanup;
  204|     15|    }
  205|  4.30k|    int i;
  206|  26.7k|    for (i=0; i<sizeof(_charset_table)/sizeof(_charset_table[0]); i++) {
  ------------------
  |  Branch (206:15): [True: 26.7k, False: 7]
  ------------------
  207|  26.7k|        if (header_start.encoding == _charset_table[i].code) {
  ------------------
  |  Branch (207:13): [True: 4.30k, False: 22.4k]
  ------------------
  208|  4.30k|            hinfo->encoding = _charset_table[i].name;
  209|  4.30k|            break;
  210|  4.30k|        }
  211|  26.7k|    }
  212|  4.30k|    if (hinfo->encoding == NULL) {
  ------------------
  |  Branch (212:9): [True: 7, False: 4.30k]
  ------------------
  213|      7|        if (error_handler) {
  ------------------
  |  Branch (213:13): [True: 0, False: 7]
  ------------------
  214|      0|            snprintf(error_buf, sizeof(error_buf), "Unsupported character set code: %d", header_start.encoding);
  215|      0|            error_handler(error_buf, user_ctx);
  216|      0|        }
  217|      7|        retval = READSTAT_ERROR_UNSUPPORTED_CHARSET;
  218|      7|        goto cleanup;
  219|      7|    }
  220|  4.30k|    memcpy(hinfo->table_name, header_start.table_name, sizeof(header_start.table_name));
  221|  4.30k|    if (io->seek(hinfo->pad1, READSTAT_SEEK_CUR, io->io_ctx) == -1) {
  ------------------
  |  Branch (221:9): [True: 4, False: 4.29k]
  ------------------
  222|      4|        retval = READSTAT_ERROR_SEEK;
  223|      4|        goto cleanup;
  224|      4|    }
  225|       |
  226|  4.29k|    double creation_time, modification_time, creation_time_diff, modification_time_diff;
  227|       |
  228|  4.29k|    if (io->read(&creation_time, sizeof(double), io->io_ctx) < sizeof(double)) {
  ------------------
  |  Branch (228:9): [True: 13, False: 4.28k]
  ------------------
  229|     13|        retval = READSTAT_ERROR_READ;
  230|     13|        goto cleanup;
  231|     13|    }
  232|  4.28k|    if (bswap)
  ------------------
  |  Branch (232:9): [True: 3.20k, False: 1.07k]
  ------------------
  233|  3.20k|        creation_time = byteswap_double(creation_time);
  234|       |
  235|  4.28k|    if (io->read(&modification_time, sizeof(double), io->io_ctx) < sizeof(double)) {
  ------------------
  |  Branch (235:9): [True: 6, False: 4.27k]
  ------------------
  236|      6|        retval = READSTAT_ERROR_READ;
  237|      6|        goto cleanup;
  238|      6|    }
  239|  4.27k|    if (bswap)
  ------------------
  |  Branch (239:9): [True: 3.20k, False: 1.07k]
  ------------------
  240|  3.20k|        modification_time = byteswap_double(modification_time);
  241|       |
  242|  4.27k|    if (io->read(&creation_time_diff, sizeof(double), io->io_ctx) < sizeof(double)) {
  ------------------
  |  Branch (242:9): [True: 6, False: 4.27k]
  ------------------
  243|      6|        retval = READSTAT_ERROR_READ;
  244|      6|        goto cleanup;
  245|      6|    }
  246|  4.27k|    if (bswap)
  ------------------
  |  Branch (246:9): [True: 3.19k, False: 1.07k]
  ------------------
  247|  3.19k|        creation_time_diff = byteswap_double(creation_time_diff);
  248|       |    
  249|  4.27k|    if (io->read(&modification_time_diff, sizeof(double), io->io_ctx) < sizeof(double)) {
  ------------------
  |  Branch (249:9): [True: 6, False: 4.26k]
  ------------------
  250|      6|        retval = READSTAT_ERROR_READ;
  251|      6|        goto cleanup;
  252|      6|    }
  253|  4.26k|    if (bswap)
  ------------------
  |  Branch (253:9): [True: 3.19k, False: 1.07k]
  ------------------
  254|  3.19k|        modification_time_diff = byteswap_double(modification_time_diff);
  255|       |    
  256|  4.26k|    hinfo->creation_time = sas_convert_time(creation_time, creation_time_diff, epoch);
  257|  4.26k|    hinfo->modification_time = sas_convert_time(modification_time, modification_time_diff, epoch);
  258|       |
  259|  4.26k|    uint32_t header_size, page_size;
  260|       |
  261|  4.26k|    if (io->read(&header_size, sizeof(uint32_t), io->io_ctx) < sizeof(uint32_t)) {
  ------------------
  |  Branch (261:9): [True: 8, False: 4.25k]
  ------------------
  262|      8|        retval = READSTAT_ERROR_READ;
  263|      8|        goto cleanup;
  264|      8|    }
  265|  4.25k|    if (io->read(&page_size, sizeof(uint32_t), io->io_ctx) < sizeof(uint32_t)) {
  ------------------
  |  Branch (265:9): [True: 3, False: 4.25k]
  ------------------
  266|      3|        retval = READSTAT_ERROR_READ;
  267|      3|        goto cleanup;
  268|      3|    }
  269|       |
  270|  4.25k|    hinfo->header_size = bswap ? byteswap4(header_size) : header_size;
  ------------------
  |  Branch (270:26): [True: 3.18k, False: 1.06k]
  ------------------
  271|  4.25k|    hinfo->page_size = bswap ? byteswap4(page_size) : page_size;
  ------------------
  |  Branch (271:24): [True: 3.18k, False: 1.06k]
  ------------------
  272|       |
  273|  4.25k|    if (hinfo->header_size < 1024 || hinfo->page_size < 1024) {
  ------------------
  |  Branch (273:9): [True: 11, False: 4.24k]
  |  Branch (273:38): [True: 12, False: 4.23k]
  ------------------
  274|     23|        retval = READSTAT_ERROR_PARSE;
  275|     23|        goto cleanup;
  276|     23|    }
  277|  4.23k|    if (hinfo->header_size > (1<<24) || hinfo->page_size > (1<<24)) {
  ------------------
  |  Branch (277:9): [True: 15, False: 4.21k]
  |  Branch (277:41): [True: 24, False: 4.19k]
  ------------------
  278|     39|        retval = READSTAT_ERROR_PARSE;
  279|     39|        goto cleanup;
  280|     39|    }
  281|       |
  282|  4.19k|    if (hinfo->u64) {
  ------------------
  |  Branch (282:9): [True: 2.29k, False: 1.89k]
  ------------------
  283|  2.29k|        hinfo->page_header_size = SAS_PAGE_HEADER_SIZE_64BIT;
  ------------------
  |  |  123|  2.29k|#define SAS_PAGE_HEADER_SIZE_64BIT  40
  ------------------
  284|  2.29k|        hinfo->subheader_pointer_size = SAS_SUBHEADER_POINTER_SIZE_64BIT;
  ------------------
  |  |  120|  2.29k|#define SAS_SUBHEADER_POINTER_SIZE_64BIT    24
  ------------------
  285|  2.29k|    } else {
  286|  1.89k|        hinfo->page_header_size = SAS_PAGE_HEADER_SIZE_32BIT;
  ------------------
  |  |  122|  1.89k|#define SAS_PAGE_HEADER_SIZE_32BIT  24
  ------------------
  287|  1.89k|        hinfo->subheader_pointer_size = SAS_SUBHEADER_POINTER_SIZE_32BIT;
  ------------------
  |  |  119|  1.89k|#define SAS_SUBHEADER_POINTER_SIZE_32BIT    12
  ------------------
  288|  1.89k|    }
  289|       |
  290|  4.19k|    if (hinfo->u64) {
  ------------------
  |  Branch (290:9): [True: 2.29k, False: 1.89k]
  ------------------
  291|  2.29k|        uint64_t page_count;
  292|  2.29k|        if (io->read(&page_count, sizeof(uint64_t), io->io_ctx) < sizeof(uint64_t)) {
  ------------------
  |  Branch (292:13): [True: 20, False: 2.27k]
  ------------------
  293|     20|            retval = READSTAT_ERROR_READ;
  294|     20|            goto cleanup;
  295|     20|        }
  296|  2.27k|        hinfo->page_count = bswap ? byteswap8(page_count) : page_count;
  ------------------
  |  Branch (296:29): [True: 1.85k, False: 425]
  ------------------
  297|  2.27k|    } else {
  298|  1.89k|        uint32_t page_count;
  299|  1.89k|        if (io->read(&page_count, sizeof(uint32_t), io->io_ctx) < sizeof(uint32_t)) {
  ------------------
  |  Branch (299:13): [True: 26, False: 1.86k]
  ------------------
  300|     26|            retval = READSTAT_ERROR_READ;
  301|     26|            goto cleanup;
  302|     26|        }
  303|  1.86k|        hinfo->page_count = bswap ? byteswap4(page_count) : page_count;
  ------------------
  |  Branch (303:29): [True: 1.23k, False: 630]
  ------------------
  304|  1.86k|    }
  305|  4.14k|    if (hinfo->page_count > (1<<24)) {
  ------------------
  |  Branch (305:9): [True: 13, False: 4.13k]
  ------------------
  306|     13|        retval = READSTAT_ERROR_PARSE;
  307|     13|        goto cleanup;
  308|     13|    }
  309|       |    
  310|  4.13k|    if (io->seek(8, READSTAT_SEEK_CUR, io->io_ctx) == -1) {
  ------------------
  |  Branch (310:9): [True: 73, False: 4.06k]
  ------------------
  311|     73|        retval = READSTAT_ERROR_SEEK;
  312|     73|        if (error_handler) {
  ------------------
  |  Branch (312:13): [True: 0, False: 73]
  ------------------
  313|      0|            snprintf(error_buf, sizeof(error_buf), "ReadStat: Failed to seek forward by %d", 8);
  314|      0|            error_handler(error_buf, user_ctx);
  315|      0|        }
  316|     73|        goto cleanup;
  317|     73|    }
  318|  4.06k|    if (io->read(&header_end, sizeof(sas_header_end_t), io->io_ctx) < sizeof(sas_header_end_t)) {
  ------------------
  |  Branch (318:9): [True: 17, False: 4.04k]
  ------------------
  319|     17|        retval = READSTAT_ERROR_READ;
  320|     17|        goto cleanup;
  321|     17|    }
  322|  4.04k|    char major, revision_tag, revision;
  323|  4.04k|    int minor;
  324|       |    /* The release field is not NUL-terminated in the file; copy it into a
  325|       |     * terminated buffer before handing it to sscanf, which calls strlen on it. */
  326|  4.04k|    char release[sizeof(header_end.release)+1];
  327|  4.04k|    memcpy(release, header_end.release, sizeof(header_end.release));
  328|  4.04k|    release[sizeof(header_end.release)] = '\0';
  329|  4.04k|    if (sscanf(release, "%c.%04d%c%c", &major, &minor, &revision_tag, &revision) != 4) {
  ------------------
  |  Branch (329:9): [True: 4, False: 4.04k]
  ------------------
  330|      4|        retval = READSTAT_ERROR_PARSE;
  331|      4|        goto cleanup;
  332|      4|    }
  333|       |
  334|  4.04k|    if (major >= '1' && major <= '9') {
  ------------------
  |  Branch (334:9): [True: 4.02k, False: 11]
  |  Branch (334:25): [True: 4.02k, False: 7]
  ------------------
  335|  4.02k|        hinfo->major_version = major - '0';
  336|  4.02k|    } else if (major == 'V') {
  ------------------
  |  Branch (336:16): [True: 2, False: 16]
  ------------------
  337|       |        // It appears that SAS Visual Forecaster reports the major version as "V"
  338|       |        // Treat it as version 9 for all intents and purposes
  339|      2|        hinfo->major_version = 9;
  340|     16|    } else {
  341|     16|        retval = READSTAT_ERROR_PARSE;
  342|     16|        goto cleanup;
  343|     16|    }
  344|       |    // revision_tag is usually M, but J has been observed in the wild (not created with SAS?)
  345|       |    // files have also been observed with TK in place of the revision details.
  346|  4.02k|    if ((major == '8' || major == '9') && revision_tag != 'M' && revision_tag != 'J' && revision_tag != 'T') {
  ------------------
  |  Branch (346:10): [True: 342, False: 3.68k]
  |  Branch (346:26): [True: 161, False: 3.52k]
  |  Branch (346:43): [True: 39, False: 464]
  |  Branch (346:66): [True: 25, False: 14]
  |  Branch (346:89): [True: 18, False: 7]
  ------------------
  347|     18|        retval = READSTAT_ERROR_PARSE;
  348|     18|        goto cleanup;
  349|     18|    }
  350|  4.00k|    hinfo->minor_version = minor;
  351|  4.00k|    if (revision >= '0' && revision <= '9') {
  ------------------
  |  Branch (351:9): [True: 3.98k, False: 17]
  |  Branch (351:28): [True: 3.97k, False: 16]
  ------------------
  352|  3.97k|        hinfo->revision = revision - '0';
  353|  3.97k|    } else if (revision_tag == 'T' && revision == 'K') {
  ------------------
  |  Branch (353:16): [True: 14, False: 19]
  |  Branch (353:39): [True: 1, False: 13]
  ------------------
  354|       |        // files have been observed with TK in place of the revision details.
  355|      1|        hinfo->revision = 0;
  356|     32|    } else {
  357|     32|        retval = READSTAT_ERROR_PARSE;
  358|     32|        goto cleanup;
  359|     32|    }
  360|       |
  361|  3.97k|    if ((major == '8' || major == '9') && minor == 0 && hinfo->revision == 0) {
  ------------------
  |  Branch (361:10): [True: 321, False: 3.65k]
  |  Branch (361:26): [True: 158, False: 3.49k]
  |  Branch (361:43): [True: 126, False: 353]
  |  Branch (361:57): [True: 88, False: 38]
  ------------------
  362|       |        /* A bit of a hack, but most SAS installations are running a minor update */
  363|     88|        hinfo->vendor = READSTAT_VENDOR_STAT_TRANSFER;
  364|  3.88k|    } else {
  365|  3.88k|        hinfo->vendor = READSTAT_VENDOR_SAS;
  366|  3.88k|    }
  367|  3.97k|    if (io->seek(hinfo->header_size, READSTAT_SEEK_SET, io->io_ctx) == -1) {
  ------------------
  |  Branch (367:9): [True: 49, False: 3.92k]
  ------------------
  368|     49|        retval = READSTAT_ERROR_SEEK;
  369|     49|        if (error_handler) {
  ------------------
  |  Branch (369:13): [True: 0, False: 49]
  ------------------
  370|      0|            snprintf(error_buf, sizeof(error_buf), 
  371|      0|                    "ReadStat: Failed to seek to position %" PRId64, hinfo->header_size);
  372|      0|            error_handler(error_buf, user_ctx);
  373|      0|        }
  374|     49|        goto cleanup;
  375|     49|    }
  376|       |
  377|  4.47k|cleanup:
  378|  4.47k|    return retval;
  379|  3.97k|}
sas_validate_tag:
  600|  8.77k|readstat_error_t sas_validate_tag(char tag) {
  601|  8.77k|    if (tag == '_' || (tag >= 'A' && tag <= 'Z'))
  ------------------
  |  Branch (601:9): [True: 5.88k, False: 2.88k]
  |  Branch (601:24): [True: 985, False: 1.90k]
  |  Branch (601:38): [True: 570, False: 415]
  ------------------
  602|  6.45k|        return READSTAT_OK;
  603|       |
  604|  2.31k|    return READSTAT_ERROR_TAGGED_VALUE_IS_OUT_OF_RANGE;
  605|  8.77k|}
sas_assign_tag:
  640|  8.77k|void sas_assign_tag(readstat_value_t *value, uint8_t tag) {
  641|       |    /* We accommodate two tag schemes. In the first, the tag is an ASCII code
  642|       |     * given by uint8_t tag above. System missing is represented by an ASCII
  643|       |     * period. In the second scheme, (tag-2) is an offset from 'A', except when
  644|       |     * tag == 0, in which case it represents an underscore, or tag == 1, in
  645|       |     * which case it represents system-missing.
  646|       |     */
  647|  8.77k|    if (tag == 0) {
  ------------------
  |  Branch (647:9): [True: 5.88k, False: 2.88k]
  ------------------
  648|  5.88k|        tag = '_';
  649|  5.88k|    } else if (tag >= 2 && tag < 28) {
  ------------------
  |  Branch (649:16): [True: 2.54k, False: 346]
  |  Branch (649:28): [True: 494, False: 2.04k]
  ------------------
  650|    494|        tag = 'A' + (tag - 2);
  651|    494|    }
  652|  8.77k|    if (sas_validate_tag(tag) == READSTAT_OK) {
  ------------------
  |  Branch (652:9): [True: 6.45k, False: 2.31k]
  ------------------
  653|  6.45k|        value->tag = tag;
  654|  6.45k|        value->is_tagged_missing = 1;
  655|  6.45k|    } else {
  656|  2.31k|        value->tag = 0;
  657|  2.31k|        value->is_system_missing = 1;
  658|  2.31k|    }
  659|  8.77k|}
readstat_sas.c:sas_epoch:
  132|  4.47k|static time_t sas_epoch(void) {
  133|  4.47k|    return - 3653 * 86400; // seconds between 01-01-1960 and 01-01-1970
  134|  4.47k|}
readstat_sas.c:sas_convert_time:
  136|  8.53k|static time_t sas_convert_time(double time, double time_diff, time_t epoch) {
  137|  8.53k|    time -= time_diff;
  138|  8.53k|    time += epoch;
  139|  8.53k|    if (isnan(time))
  ------------------
  |  Branch (139:9): [True: 1.01k, False: 7.51k]
  ------------------
  140|  1.01k|        return 0;
  141|  7.51k|    if (time > (double)LONG_MAX)
  ------------------
  |  Branch (141:9): [True: 1.87k, False: 5.63k]
  ------------------
  142|  1.87k|        return LONG_MAX;
  143|  5.63k|    if (time < (double)LONG_MIN)
  ------------------
  |  Branch (143:9): [True: 1.20k, False: 4.43k]
  ------------------
  144|  1.20k|        return LONG_MIN;
  145|  4.43k|    return time;
  146|  5.63k|}

readstat_parse_sas7bdat:
 1461|  4.47k|readstat_error_t readstat_parse_sas7bdat(readstat_parser_t *parser, const char *path, void *user_ctx) {
 1462|  4.47k|    int64_t last_examined_page_pass1 = 0;
 1463|  4.47k|    readstat_error_t retval = READSTAT_OK;
 1464|  4.47k|    readstat_io_t *io = parser->io;
 1465|       |
 1466|  4.47k|    sas7bdat_ctx_t  *ctx = calloc(1, sizeof(sas7bdat_ctx_t));
 1467|  4.47k|    sas_header_info_t  *hinfo = calloc(1, sizeof(sas_header_info_t));
 1468|       |
 1469|  4.47k|    if (ctx == NULL || hinfo == NULL) {
  ------------------
  |  Branch (1469:9): [True: 0, False: 4.47k]
  |  Branch (1469:24): [True: 0, False: 4.47k]
  ------------------
 1470|      0|        retval = READSTAT_ERROR_MALLOC;
 1471|      0|        goto cleanup;
 1472|      0|    }
 1473|       |
 1474|  4.47k|    ctx->handle = parser->handlers;
 1475|  4.47k|    ctx->input_encoding = parser->input_encoding;
 1476|  4.47k|    ctx->output_encoding = parser->output_encoding;
 1477|  4.47k|    ctx->user_ctx = user_ctx;
 1478|  4.47k|    ctx->io = parser->io;
 1479|  4.47k|    ctx->row_limit = parser->row_limit;
 1480|  4.47k|    ctx->moved_page_index = -1;
 1481|  4.47k|    if (parser->row_offset > 0)
  ------------------
  |  Branch (1481:9): [True: 0, False: 4.47k]
  ------------------
 1482|      0|        ctx->row_offset = parser->row_offset;
 1483|       |
 1484|  4.47k|    if (io->open(path, io->io_ctx) == -1) {
  ------------------
  |  Branch (1484:9): [True: 0, False: 4.47k]
  ------------------
 1485|      0|        retval = READSTAT_ERROR_OPEN;
 1486|      0|        goto cleanup;
 1487|      0|    }
 1488|       |
 1489|  4.47k|    if ((ctx->file_size = io->seek(0, READSTAT_SEEK_END, io->io_ctx)) == -1) {
  ------------------
  |  Branch (1489:9): [True: 0, False: 4.47k]
  ------------------
 1490|      0|        retval = READSTAT_ERROR_SEEK;
 1491|      0|        if (ctx->handle.error) {
  ------------------
  |  Branch (1491:13): [True: 0, False: 0]
  ------------------
 1492|      0|            snprintf(ctx->error_buf, sizeof(ctx->error_buf), "ReadStat: Failed to seek to end of file");
 1493|      0|            ctx->handle.error(ctx->error_buf, ctx->user_ctx);
 1494|      0|        }
 1495|      0|        goto cleanup;
 1496|      0|    }
 1497|       |
 1498|  4.47k|    if (io->seek(0, READSTAT_SEEK_SET, io->io_ctx) == -1) {
  ------------------
  |  Branch (1498:9): [True: 0, False: 4.47k]
  ------------------
 1499|      0|        retval = READSTAT_ERROR_SEEK;
 1500|      0|        if (ctx->handle.error) {
  ------------------
  |  Branch (1500:13): [True: 0, False: 0]
  ------------------
 1501|      0|            snprintf(ctx->error_buf, sizeof(ctx->error_buf), "ReadStat: Failed to seek to beginning of file");
 1502|      0|            ctx->handle.error(ctx->error_buf, ctx->user_ctx);
 1503|      0|        }
 1504|      0|        goto cleanup;
 1505|      0|    }
 1506|       |
 1507|  4.47k|    if ((retval = sas_read_header(io, hinfo, ctx->handle.error, user_ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1507:9): [True: 553, False: 3.92k]
  ------------------
 1508|    553|        goto cleanup;
 1509|    553|    }
 1510|       |
 1511|  3.92k|    ctx->u64 = hinfo->u64;
 1512|  3.92k|    ctx->little_endian = hinfo->little_endian;
 1513|  3.92k|    ctx->vendor = hinfo->vendor;
 1514|  3.92k|    ctx->bswap = machine_is_little_endian() ^ hinfo->little_endian;
 1515|  3.92k|    ctx->header_size = hinfo->header_size;
 1516|  3.92k|    ctx->page_count = hinfo->page_count;
 1517|  3.92k|    ctx->page_size = hinfo->page_size;
 1518|  3.92k|    ctx->page_header_size = hinfo->page_header_size;
 1519|  3.92k|    ctx->subheader_pointer_size = hinfo->subheader_pointer_size;
 1520|  3.92k|    ctx->subheader_signature_size = ctx->u64 ? 8 : 4;
  ------------------
  |  Branch (1520:37): [True: 2.21k, False: 1.70k]
  ------------------
 1521|  3.92k|    ctx->ctime = hinfo->creation_time;
 1522|  3.92k|    ctx->mtime = hinfo->modification_time;
 1523|  3.92k|    ctx->version = hinfo->major_version;
 1524|  3.92k|    if (ctx->input_encoding == NULL) {
  ------------------
  |  Branch (1524:9): [True: 3.92k, False: 0]
  ------------------
 1525|  3.92k|        ctx->input_encoding = hinfo->encoding;
 1526|  3.92k|    }
 1527|  3.92k|    if ((ctx->page = readstat_malloc(ctx->page_size)) == NULL) {
  ------------------
  |  Branch (1527:9): [True: 0, False: 3.92k]
  ------------------
 1528|      0|        retval = READSTAT_ERROR_MALLOC;
 1529|      0|        goto cleanup;
 1530|      0|    }
 1531|       |
 1532|  3.92k|    if (ctx->input_encoding && ctx->output_encoding && strcmp(ctx->input_encoding, ctx->output_encoding) != 0) {
  ------------------
  |  Branch (1532:9): [True: 3.92k, False: 0]
  |  Branch (1532:32): [True: 3.92k, False: 0]
  |  Branch (1532:56): [True: 2.75k, False: 1.16k]
  ------------------
 1533|  2.75k|        iconv_t converter = iconv_open(ctx->output_encoding, ctx->input_encoding);
 1534|  2.75k|        if (converter == (iconv_t)-1) {
  ------------------
  |  Branch (1534:13): [True: 1, False: 2.75k]
  ------------------
 1535|      1|            retval = READSTAT_ERROR_UNSUPPORTED_CHARSET;
 1536|      1|            goto cleanup;
 1537|      1|        }
 1538|  2.75k|        ctx->converter = converter;
 1539|  2.75k|    }
 1540|       |
 1541|  3.92k|    if ((retval = readstat_convert(ctx->table_name, sizeof(ctx->table_name),
  ------------------
  |  Branch (1541:9): [True: 2, False: 3.92k]
  ------------------
 1542|  3.92k|                hinfo->table_name, sizeof(hinfo->table_name), ctx->converter)) != READSTAT_OK) {
 1543|      2|        goto cleanup;
 1544|      2|    }
 1545|       |
 1546|  3.92k|    if ((retval = sas7bdat_parse_meta_pages_pass1(ctx, &last_examined_page_pass1)) != READSTAT_OK) {
  ------------------
  |  Branch (1546:9): [True: 220, False: 3.70k]
  ------------------
 1547|    220|        goto cleanup;
 1548|    220|    }
 1549|       |
 1550|  3.70k|    if ((retval = sas7bdat_parse_amd_pages_pass1(last_examined_page_pass1, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1550:9): [True: 1.19k, False: 2.50k]
  ------------------
 1551|  1.19k|        goto cleanup;
 1552|  1.19k|    }
 1553|       |
 1554|  2.50k|    if (io->seek(ctx->header_size, READSTAT_SEEK_SET, io->io_ctx) == -1) {
  ------------------
  |  Branch (1554:9): [True: 0, False: 2.50k]
  ------------------
 1555|      0|        retval = READSTAT_ERROR_SEEK;
 1556|      0|        if (ctx->handle.error) {
  ------------------
  |  Branch (1556:13): [True: 0, False: 0]
  ------------------
 1557|      0|            snprintf(ctx->error_buf, sizeof(ctx->error_buf), "ReadStat: Failed to seek to position %" PRId64, 
 1558|      0|                    ctx->header_size);
 1559|      0|            ctx->handle.error(ctx->error_buf, ctx->user_ctx);
 1560|      0|        }
 1561|      0|        goto cleanup;
 1562|      0|    }
 1563|       |
 1564|  2.50k|    if ((retval = sas7bdat_parse_all_pages_pass2(ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1564:9): [True: 2.17k, False: 331]
  ------------------
 1565|  2.17k|        goto cleanup;
 1566|  2.17k|    }
 1567|       |    
 1568|    331|    if ((retval = sas7bdat_submit_columns_if_needed(ctx, 0)) != READSTAT_OK) {
  ------------------
  |  Branch (1568:9): [True: 79, False: 252]
  ------------------
 1569|     79|        goto cleanup;
 1570|     79|    }
 1571|       |
 1572|    252|    if (ctx->handle.value && ctx->parsed_row_count != ctx->row_limit) {
  ------------------
  |  Branch (1572:9): [True: 252, False: 0]
  |  Branch (1572:30): [True: 125, False: 127]
  ------------------
 1573|    125|        retval = READSTAT_ERROR_ROW_COUNT_MISMATCH;
 1574|    125|        if (ctx->handle.error) {
  ------------------
  |  Branch (1574:13): [True: 0, False: 125]
  ------------------
 1575|      0|            snprintf(ctx->error_buf, sizeof(ctx->error_buf), "ReadStat: Expected %d rows in file, found %d",
 1576|      0|                    ctx->row_limit, ctx->parsed_row_count);
 1577|      0|            ctx->handle.error(ctx->error_buf, ctx->user_ctx);
 1578|      0|        }
 1579|    125|        goto cleanup;
 1580|    125|    }
 1581|       |
 1582|    127|    if ((retval = sas7bdat_update_progress(ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1582:9): [True: 0, False: 127]
  ------------------
 1583|      0|        goto cleanup;
 1584|      0|    }
 1585|       |
 1586|  4.47k|cleanup:
 1587|  4.47k|    io->close(io->io_ctx);
 1588|       |
 1589|  4.47k|    if (retval == READSTAT_ERROR_OPEN ||
  ------------------
  |  Branch (1589:9): [True: 0, False: 4.47k]
  ------------------
 1590|  4.47k|            retval == READSTAT_ERROR_READ ||
  ------------------
  |  Branch (1590:13): [True: 640, False: 3.83k]
  ------------------
 1591|  3.83k|            retval == READSTAT_ERROR_SEEK) {
  ------------------
  |  Branch (1591:13): [True: 393, False: 3.44k]
  ------------------
 1592|  1.03k|        if (ctx->handle.error) {
  ------------------
  |  Branch (1592:13): [True: 0, False: 1.03k]
  ------------------
 1593|      0|            snprintf(ctx->error_buf, sizeof(ctx->error_buf), "ReadStat: %s (retval = %d): %s (errno = %d)", 
 1594|      0|                    readstat_error_message(retval), retval, strerror(errno), errno);
 1595|      0|            ctx->handle.error(ctx->error_buf, user_ctx);
 1596|      0|        }
 1597|  1.03k|    }
 1598|       |
 1599|  4.47k|    if (ctx)
  ------------------
  |  Branch (1599:9): [True: 4.47k, False: 0]
  ------------------
 1600|  4.47k|        sas7bdat_ctx_free(ctx);
 1601|  4.47k|    if (hinfo)
  ------------------
  |  Branch (1601:9): [True: 4.47k, False: 0]
  ------------------
 1602|  4.47k|        free(hinfo);
 1603|       |
 1604|  4.47k|    return retval;
 1605|    127|}
readstat_sas7bdat_read.c:sas7bdat_parse_meta_pages_pass1:
 1302|  3.92k|static readstat_error_t sas7bdat_parse_meta_pages_pass1(sas7bdat_ctx_t *ctx, int64_t *outLastExaminedPage) {
 1303|  3.92k|    readstat_error_t retval = READSTAT_OK;
 1304|  3.92k|    readstat_io_t *io = ctx->io;
 1305|  3.92k|    int64_t i;
 1306|       |
 1307|       |    /* look for META and MIX pages at beginning... */
 1308|  11.2k|    for (i=0; i<ctx->page_count; i++) {
  ------------------
  |  Branch (1308:15): [True: 8.50k, False: 2.79k]
  ------------------
 1309|  8.50k|        if (io->seek(ctx->header_size + i*ctx->page_size, READSTAT_SEEK_SET, io->io_ctx) == -1) {
  ------------------
  |  Branch (1309:13): [True: 8, False: 8.49k]
  ------------------
 1310|      8|            retval = READSTAT_ERROR_SEEK;
 1311|      8|            if (ctx->handle.error) {
  ------------------
  |  Branch (1311:17): [True: 0, False: 8]
  ------------------
 1312|      0|                snprintf(ctx->error_buf, sizeof(ctx->error_buf), "ReadStat: Failed to seek to position %" PRId64 
 1313|      0|                        " (= %" PRId64 " + %" PRId64 "*%" PRId64 ")",
 1314|      0|                        ctx->header_size + i*ctx->page_size, ctx->header_size, i, ctx->page_size);
 1315|      0|                ctx->handle.error(ctx->error_buf, ctx->user_ctx);
 1316|      0|            }
 1317|      8|            goto cleanup;
 1318|      8|        }
 1319|       |
 1320|  8.49k|        readstat_off_t off = 0;
 1321|  8.49k|        if (ctx->u64)
  ------------------
  |  Branch (1321:13): [True: 6.18k, False: 2.31k]
  ------------------
 1322|  6.18k|            off = 16;
 1323|       |
 1324|  8.49k|        size_t head_len = off + 16 + 2;
 1325|  8.49k|        size_t tail_len = ctx->page_size - head_len;
 1326|       |
 1327|  8.49k|        if (io->read(ctx->page, head_len, io->io_ctx) < head_len) {
  ------------------
  |  Branch (1327:13): [True: 143, False: 8.35k]
  ------------------
 1328|    143|            retval = READSTAT_ERROR_READ;
 1329|    143|            goto cleanup;
 1330|    143|        }
 1331|       |
 1332|  8.35k|        uint16_t page_type = sas_read2(&ctx->page[off+16], ctx->bswap);
 1333|       |
 1334|  8.35k|        if ((page_type & SAS_PAGE_TYPE_MASK) == SAS_PAGE_TYPE_DATA)
  ------------------
  |  |  113|  8.35k|#define SAS_PAGE_TYPE_MASK   0x0F00
  ------------------
                      if ((page_type & SAS_PAGE_TYPE_MASK) == SAS_PAGE_TYPE_DATA)
  ------------------
  |  |  110|  8.35k|#define SAS_PAGE_TYPE_DATA   0x0100
  ------------------
  |  Branch (1334:13): [True: 910, False: 7.44k]
  ------------------
 1335|    910|            break;
 1336|  7.44k|        if ((page_type & SAS_PAGE_TYPE_COMP))
  ------------------
  |  |  117|  7.44k|#define SAS_PAGE_TYPE_COMP          0x9000
  ------------------
  |  Branch (1336:13): [True: 1.44k, False: 5.99k]
  ------------------
 1337|  1.44k|            continue;
 1338|       |
 1339|  5.99k|        if (io->read(ctx->page + head_len, tail_len, io->io_ctx) < tail_len) {
  ------------------
  |  Branch (1339:13): [True: 30, False: 5.96k]
  ------------------
 1340|     30|            retval = READSTAT_ERROR_READ;
 1341|     30|            goto cleanup;
 1342|     30|        }
 1343|       |
 1344|  5.96k|        if ((retval = sas7bdat_parse_page_pass1(ctx->page, ctx->page_size, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1344:13): [True: 39, False: 5.92k]
  ------------------
 1345|     39|            if (ctx->handle.error && retval != READSTAT_ERROR_USER_ABORT) {
  ------------------
  |  Branch (1345:17): [True: 0, False: 39]
  |  Branch (1345:38): [True: 0, False: 0]
  ------------------
 1346|      0|                int64_t pos = io->seek(0, READSTAT_SEEK_CUR, io->io_ctx);
 1347|      0|                snprintf(ctx->error_buf, sizeof(ctx->error_buf), 
 1348|      0|                        "ReadStat: Error parsing page %" PRId64 ", bytes %" PRId64 "-%" PRId64, 
 1349|      0|                        i, pos - ctx->page_size, pos-1);
 1350|      0|                ctx->handle.error(ctx->error_buf, ctx->user_ctx);
 1351|      0|            }
 1352|     39|            goto cleanup;
 1353|     39|        }
 1354|  5.96k|    }
 1355|       |
 1356|  3.92k|cleanup:
 1357|  3.92k|    if (outLastExaminedPage)
  ------------------
  |  Branch (1357:9): [True: 3.92k, False: 0]
  ------------------
 1358|  3.92k|        *outLastExaminedPage = i;
 1359|       |
 1360|  3.92k|    return retval;
 1361|  3.92k|}
readstat_sas7bdat_read.c:sas7bdat_parse_page_pass1:
 1004|  9.40k|static readstat_error_t sas7bdat_parse_page_pass1(const char *page, size_t page_size, sas7bdat_ctx_t *ctx) {
 1005|  9.40k|    readstat_error_t retval = READSTAT_OK;
 1006|       |
 1007|  9.40k|    uint16_t subheader_count = sas_read2(&page[ctx->page_header_size-4], ctx->bswap);
 1008|       |
 1009|  9.40k|    int i;
 1010|  9.40k|    const char *shp = &page[ctx->page_header_size];
 1011|  9.40k|    int lshp = ctx->subheader_pointer_size;
 1012|       |
 1013|  9.40k|    if (ctx->page_header_size + subheader_count*lshp > page_size) {
  ------------------
  |  Branch (1013:9): [True: 35, False: 9.36k]
  ------------------
 1014|     35|        retval = READSTAT_ERROR_PARSE;
 1015|     35|        goto cleanup;
 1016|     35|    }
 1017|       |
 1018|  95.5k|    for (i=0; i<subheader_count; i++) {
  ------------------
  |  Branch (1018:15): [True: 87.1k, False: 8.44k]
  ------------------
 1019|  87.1k|        subheader_pointer_t shp_info = { 0 };
 1020|  87.1k|        if ((retval = sas7bdat_parse_subheader_pointer(shp, page + page_size - shp, &shp_info, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1020:13): [True: 0, False: 87.1k]
  ------------------
 1021|      0|            goto cleanup;
 1022|      0|        }
 1023|  87.1k|        if (shp_info.len > 0 && shp_info.compression != SAS_COMPRESSION_TRUNC && shp_info.compression != SAS_COMPRESSION_REFERENCE) {
  ------------------
  |  |  126|   144k|#define SAS_COMPRESSION_TRUNC              0x01
  ------------------
                      if (shp_info.len > 0 && shp_info.compression != SAS_COMPRESSION_TRUNC && shp_info.compression != SAS_COMPRESSION_REFERENCE) {
  ------------------
  |  |  128|  50.8k|#define SAS_COMPRESSION_REFERENCE          0x03
  ------------------
  |  Branch (1023:13): [True: 57.7k, False: 29.3k]
  |  Branch (1023:33): [True: 50.8k, False: 6.97k]
  |  Branch (1023:82): [True: 48.9k, False: 1.84k]
  ------------------
 1024|  48.9k|            if ((retval = sas7bdat_validate_subheader_pointer(&shp_info, page_size, subheader_count, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1024:17): [True: 829, False: 48.1k]
  ------------------
 1025|    829|                goto cleanup;
 1026|    829|            }
 1027|  48.1k|            if (shp_info.compression == SAS_COMPRESSION_NONE) {
  ------------------
  |  |  125|  48.1k|#define SAS_COMPRESSION_NONE               0x00
  ------------------
  |  Branch (1027:17): [True: 39.2k, False: 8.87k]
  ------------------
 1028|  39.2k|                sas_subheader_type_t subheader_type = sas7bdat_parse_subheader_type(page + shp_info.offset, ctx);
 1029|  39.2k|                if (subheader_type == SAS_SUBHEADER_TYPE_COLUMN_TEXT) {
  ------------------
  |  Branch (1029:21): [True: 8.50k, False: 30.7k]
  ------------------
 1030|  8.50k|                    if ((retval = sas7bdat_parse_subheader(subheader_type, page + shp_info.offset, shp_info.len, ctx))
  ------------------
  |  Branch (1030:25): [True: 57, False: 8.45k]
  ------------------
 1031|  8.50k|                            != READSTAT_OK) {
 1032|     57|                        goto cleanup;
 1033|     57|                    }
 1034|  8.50k|                }
 1035|  39.2k|            } else if (shp_info.compression == SAS_COMPRESSION_ROW || shp_info.compression == SAS_COMPRESSION_DELETED_ROW
  ------------------
  |  |  129|  17.7k|#define SAS_COMPRESSION_ROW                0x04
  ------------------
                          } else if (shp_info.compression == SAS_COMPRESSION_ROW || shp_info.compression == SAS_COMPRESSION_DELETED_ROW
  ------------------
  |  |  130|  11.9k|#define SAS_COMPRESSION_DELETED_ROW        0x05
  ------------------
  |  Branch (1035:24): [True: 5.82k, False: 3.04k]
  |  Branch (1035:71): [True: 536, False: 2.51k]
  ------------------
 1036|  8.83k|                    || sas7bdat_is_moved_row(shp_info.compression)) {
  ------------------
  |  Branch (1036:24): [True: 2.47k, False: 36]
  ------------------
 1037|       |                /* void */
 1038|  8.83k|            } else {
 1039|     36|                retval = READSTAT_ERROR_UNSUPPORTED_COMPRESSION;
 1040|     36|                goto cleanup;
 1041|     36|            }
 1042|  48.1k|        }
 1043|       |
 1044|  86.2k|        shp += lshp;
 1045|  86.2k|    }
 1046|       |
 1047|  9.40k|cleanup:
 1048|       |
 1049|  9.40k|    return retval;
 1050|  9.36k|}
readstat_sas7bdat_read.c:sas7bdat_parse_subheader_pointer:
  951|   137k|        subheader_pointer_t *info, sas7bdat_ctx_t *ctx) {
  952|   137k|    readstat_error_t retval = READSTAT_OK;
  953|   137k|    if (ctx->u64) {
  ------------------
  |  Branch (953:9): [True: 45.0k, False: 92.6k]
  ------------------
  954|  45.0k|        if (shp_size <= 17) {
  ------------------
  |  Branch (954:13): [True: 0, False: 45.0k]
  ------------------
  955|      0|            retval = READSTAT_ERROR_PARSE;
  956|      0|            goto cleanup;
  957|      0|        }
  958|  45.0k|        info->offset = sas_read8(&shp[0], ctx->bswap);
  959|  45.0k|        info->len = sas_read8(&shp[8], ctx->bswap);
  960|  45.0k|        info->compression = shp[16];
  961|  45.0k|        info->is_compressed_data = shp[17];
  962|  92.6k|    } else {
  963|  92.6k|        if (shp_size <= 9) {
  ------------------
  |  Branch (963:13): [True: 0, False: 92.6k]
  ------------------
  964|      0|            retval = READSTAT_ERROR_PARSE;
  965|      0|            goto cleanup;
  966|      0|        }
  967|  92.6k|        info->offset = sas_read4(&shp[0], ctx->bswap);
  968|  92.6k|        info->len = sas_read4(&shp[4], ctx->bswap);
  969|  92.6k|        info->compression = shp[8];
  970|  92.6k|        info->is_compressed_data = shp[9];
  971|  92.6k|    }
  972|   137k|cleanup:
  973|   137k|    return retval;
  974|   137k|}
readstat_sas7bdat_read.c:sas7bdat_validate_subheader_pointer:
  977|  77.0k|        uint16_t subheader_count, sas7bdat_ctx_t *ctx) {
  978|  77.0k|    if (shp_info->offset > page_size)
  ------------------
  |  Branch (978:9): [True: 627, False: 76.4k]
  ------------------
  979|    627|        return READSTAT_ERROR_PARSE;
  980|  76.4k|    if (shp_info->len > page_size)
  ------------------
  |  Branch (980:9): [True: 541, False: 75.8k]
  ------------------
  981|    541|        return READSTAT_ERROR_PARSE;
  982|  75.8k|    if (shp_info->offset + shp_info->len > page_size)
  ------------------
  |  Branch (982:9): [True: 51, False: 75.8k]
  ------------------
  983|     51|        return READSTAT_ERROR_PARSE;
  984|  75.8k|    if (shp_info->offset < ctx->page_header_size + subheader_count*ctx->subheader_pointer_size)
  ------------------
  |  Branch (984:9): [True: 33, False: 75.7k]
  ------------------
  985|     33|        return READSTAT_ERROR_PARSE;
  986|  75.7k|    if (shp_info->compression == SAS_COMPRESSION_NONE || shp_info->compression == SAS_COMPRESSION_NONE_MOVED) {
  ------------------
  |  |  125|   151k|#define SAS_COMPRESSION_NONE               0x00
  ------------------
                  if (shp_info->compression == SAS_COMPRESSION_NONE || shp_info->compression == SAS_COMPRESSION_NONE_MOVED) {
  ------------------
  |  |  127|  13.0k|#define SAS_COMPRESSION_NONE_MOVED         0x02
  ------------------
  |  Branch (986:9): [True: 62.7k, False: 13.0k]
  |  Branch (986:58): [True: 980, False: 12.0k]
  ------------------
  987|  63.7k|        if (shp_info->len < ctx->subheader_signature_size)
  ------------------
  |  Branch (987:13): [True: 13, False: 63.6k]
  ------------------
  988|     13|            return READSTAT_ERROR_PARSE;
  989|  63.6k|        if (shp_info->offset + ctx->subheader_signature_size > page_size)
  ------------------
  |  Branch (989:13): [True: 0, False: 63.6k]
  ------------------
  990|      0|            return READSTAT_ERROR_PARSE;
  991|  63.6k|    }
  992|       |    
  993|  75.7k|    return READSTAT_OK;
  994|  75.7k|}
readstat_sas7bdat_read.c:sas7bdat_parse_subheader_type:
  915|  62.7k|static sas_subheader_type_t sas7bdat_parse_subheader_type(const char* subheader, sas7bdat_ctx_t* ctx) {
  916|  62.7k|    if (!ctx->u64) {
  ------------------
  |  Branch (916:9): [True: 35.7k, False: 27.0k]
  ------------------
  917|  35.7k|        uint32_t signature_32 = sas_read4(subheader, ctx->bswap);
  918|  35.7k|        return sas7bdat_parse_subheader_type_32(signature_32);
  919|  35.7k|    }
  920|       |
  921|  27.0k|    if (!ctx->little_endian) {
  ------------------
  |  Branch (921:9): [True: 24.6k, False: 2.35k]
  ------------------
  922|       |        /* Big-endian 64-bit files lay out signatures differently from
  923|       |         * little-endian ones: ROW_SIZE and COLUMN_SIZE occupy only the first
  924|       |         * four bytes (the remaining four are unspecified), while the 0xFFFF...
  925|       |         * family is written as 0xFFFFFFFF followed by the 32-bit signature. */
  926|  24.6k|        uint32_t signature_32 = sas_read4(subheader, ctx->bswap);
  927|  24.6k|        if (signature_32 == SAS_SUBHEADER_SIGNATURE_ROW_SIZE) {
  ------------------
  |  |   93|  24.6k|#define SAS_SUBHEADER_SIGNATURE_ROW_SIZE       0xF7F7F7F7
  ------------------
  |  Branch (927:13): [True: 963, False: 23.7k]
  ------------------
  928|    963|            return SAS_SUBHEADER_TYPE_ROW_SIZE;
  929|  23.7k|        } else if (signature_32 == SAS_SUBHEADER_SIGNATURE_COLUMN_SIZE) {
  ------------------
  |  |   94|  23.7k|#define SAS_SUBHEADER_SIGNATURE_COLUMN_SIZE    0xF6F6F6F6
  ------------------
  |  Branch (929:20): [True: 345, False: 23.3k]
  ------------------
  930|    345|            return SAS_SUBHEADER_TYPE_COLUMN_SIZE;
  931|  23.3k|        } else if (signature_32 != SAS_SUBHEADER_SIGNATURE_COLUMN_NAME) {
  ------------------
  |  |  104|  23.3k|#define SAS_SUBHEADER_SIGNATURE_COLUMN_NAME    0xFFFFFFFF
  ------------------
  |  Branch (931:20): [True: 1.19k, False: 22.1k]
  ------------------
  932|  1.19k|            return SAS_SUBHEADER_TYPE_DATA;
  933|  1.19k|        }
  934|  22.1k|        return sas7bdat_parse_subheader_type_32(sas_read4(&subheader[4], ctx->bswap));
  935|  24.6k|    }
  936|       |
  937|  2.35k|    uint64_t signature = sas_read8(subheader, ctx->bswap);
  938|  2.35k|    if (signature == SAS_SUBHEADER_SIGNATURE_ROW_SIZE) {
  ------------------
  |  |   93|  2.35k|#define SAS_SUBHEADER_SIGNATURE_ROW_SIZE       0xF7F7F7F7
  ------------------
  |  Branch (938:9): [True: 143, False: 2.21k]
  ------------------
  939|    143|        return SAS_SUBHEADER_TYPE_ROW_SIZE;
  940|  2.21k|    } else if (signature == SAS_SUBHEADER_SIGNATURE_COLUMN_SIZE) {
  ------------------
  |  |   94|  2.21k|#define SAS_SUBHEADER_SIGNATURE_COLUMN_SIZE    0xF6F6F6F6
  ------------------
  |  Branch (940:16): [True: 147, False: 2.06k]
  ------------------
  941|    147|        return SAS_SUBHEADER_TYPE_COLUMN_SIZE;
  942|  2.06k|    } else if ((signature & SAS_SUBHEADER_SIGNATURE_64BIT_MASK) != SAS_SUBHEADER_SIGNATURE_64BIT_MASK) {
  ------------------
  |  |  106|  2.06k|#define SAS_SUBHEADER_SIGNATURE_64BIT_MASK     0xFFFFFFFF00000000
  ------------------
                  } else if ((signature & SAS_SUBHEADER_SIGNATURE_64BIT_MASK) != SAS_SUBHEADER_SIGNATURE_64BIT_MASK) {
  ------------------
  |  |  106|  2.06k|#define SAS_SUBHEADER_SIGNATURE_64BIT_MASK     0xFFFFFFFF00000000
  ------------------
  |  Branch (942:16): [True: 602, False: 1.46k]
  ------------------
  943|    602|        return SAS_SUBHEADER_TYPE_DATA;
  944|    602|    }
  945|       |
  946|  1.46k|    uint32_t lower_bytes = (uint32_t)(signature & SAS_SUBHEADER_SIGNATURE_32BIT_MASK);
  ------------------
  |  |  107|  1.46k|#define SAS_SUBHEADER_SIGNATURE_32BIT_MASK     0x00000000FFFFFFFF
  ------------------
  947|  1.46k|    return sas7bdat_parse_subheader_type_32(lower_bytes);
  948|  2.35k|}
readstat_sas7bdat_read.c:sas7bdat_parse_subheader_type_32:
  889|  59.3k|static sas_subheader_type_t sas7bdat_parse_subheader_type_32(uint32_t signature) {
  890|  59.3k|    switch (signature) {
  891|  6.99k|        case SAS_SUBHEADER_SIGNATURE_ROW_SIZE:
  ------------------
  |  |   93|  6.99k|#define SAS_SUBHEADER_SIGNATURE_ROW_SIZE       0xF7F7F7F7
  ------------------
  |  Branch (891:9): [True: 6.99k, False: 52.3k]
  ------------------
  892|  6.99k|            return SAS_SUBHEADER_TYPE_ROW_SIZE;
  893|  3.86k|        case SAS_SUBHEADER_SIGNATURE_COLUMN_SIZE:
  ------------------
  |  |   94|  3.86k|#define SAS_SUBHEADER_SIGNATURE_COLUMN_SIZE    0xF6F6F6F6
  ------------------
  |  Branch (893:9): [True: 3.86k, False: 55.4k]
  ------------------
  894|  3.86k|            return SAS_SUBHEADER_TYPE_COLUMN_SIZE;
  895|  4.56k|        case SAS_SUBHEADER_SIGNATURE_COUNTS:
  ------------------
  |  |   95|  4.56k|#define SAS_SUBHEADER_SIGNATURE_COUNTS         0xFFFFFC00
  ------------------
  |  Branch (895:9): [True: 4.56k, False: 54.7k]
  ------------------
  896|  4.56k|            return SAS_SUBHEADER_TYPE_COUNTS;
  897|  9.47k|        case SAS_SUBHEADER_SIGNATURE_COLUMN_FORMAT:
  ------------------
  |  |   96|  9.47k|#define SAS_SUBHEADER_SIGNATURE_COLUMN_FORMAT  0xFFFFFBFE
  ------------------
  |  Branch (897:9): [True: 9.47k, False: 49.8k]
  ------------------
  898|  9.47k|            return SAS_SUBHEADER_TYPE_COLUMN_FORMAT;
  899|  4.91k|        case SAS_SUBHEADER_SIGNATURE_COLUMN_ATTRS:
  ------------------
  |  |  101|  4.91k|#define SAS_SUBHEADER_SIGNATURE_COLUMN_ATTRS   0xFFFFFFFC
  ------------------
  |  Branch (899:9): [True: 4.91k, False: 54.4k]
  ------------------
  900|  4.91k|            return SAS_SUBHEADER_TYPE_COLUMN_ATTRS;
  901|  14.8k|        case SAS_SUBHEADER_SIGNATURE_COLUMN_TEXT:
  ------------------
  |  |  102|  14.8k|#define SAS_SUBHEADER_SIGNATURE_COLUMN_TEXT    0xFFFFFFFD
  ------------------
  |  Branch (901:9): [True: 14.8k, False: 44.4k]
  ------------------
  902|  14.8k|            return SAS_SUBHEADER_TYPE_COLUMN_TEXT;
  903|  2.11k|        case SAS_SUBHEADER_SIGNATURE_COLUMN_LIST:
  ------------------
  |  |  103|  2.11k|#define SAS_SUBHEADER_SIGNATURE_COLUMN_LIST    0xFFFFFFFE
  ------------------
  |  Branch (903:9): [True: 2.11k, False: 57.2k]
  ------------------
  904|  2.11k|            return SAS_SUBHEADER_TYPE_COLUMN_LIST;
  905|  7.15k|        case SAS_SUBHEADER_SIGNATURE_COLUMN_NAME:
  ------------------
  |  |  104|  7.15k|#define SAS_SUBHEADER_SIGNATURE_COLUMN_NAME    0xFFFFFFFF
  ------------------
  |  Branch (905:9): [True: 7.15k, False: 52.2k]
  ------------------
  906|  7.15k|            return SAS_SUBHEADER_TYPE_COLUMN_NAME;
  907|  5.40k|        default:
  ------------------
  |  Branch (907:9): [True: 5.40k, False: 53.9k]
  ------------------
  908|  5.40k|            if ((signature & SAS_SUBHEADER_SIGNATURE_COLUMN_MASK) == SAS_SUBHEADER_SIGNATURE_COLUMN_MASK) {
  ------------------
  |  |   98|  5.40k|#define SAS_SUBHEADER_SIGNATURE_COLUMN_MASK    0xFFFFFFF8
  ------------------
                          if ((signature & SAS_SUBHEADER_SIGNATURE_COLUMN_MASK) == SAS_SUBHEADER_SIGNATURE_COLUMN_MASK) {
  ------------------
  |  |   98|  5.40k|#define SAS_SUBHEADER_SIGNATURE_COLUMN_MASK    0xFFFFFFF8
  ------------------
  |  Branch (908:17): [True: 2.00k, False: 3.39k]
  ------------------
  909|  2.00k|                return SAS_SUBHEADER_TYPE_UNKNOWN;
  910|  2.00k|            }
  911|  3.39k|            return SAS_SUBHEADER_TYPE_DATA;
  912|  59.3k|    }
  913|  59.3k|}
readstat_sas7bdat_read.c:sas7bdat_parse_subheader:
  697|  25.0k|        size_t len, sas7bdat_ctx_t *ctx) {
  698|  25.0k|    readstat_error_t retval = READSTAT_OK;
  699|       |
  700|  25.0k|    if (len < 2 + ctx->subheader_signature_size) {
  ------------------
  |  Branch (700:9): [True: 9, False: 25.0k]
  ------------------
  701|      9|        retval = READSTAT_ERROR_PARSE;
  702|      9|        goto cleanup;
  703|      9|    }
  704|  25.0k|    if (subheader_type == SAS_SUBHEADER_TYPE_ROW_SIZE) {
  ------------------
  |  Branch (704:9): [True: 3.18k, False: 21.8k]
  ------------------
  705|  3.18k|        retval = sas7bdat_parse_row_size_subheader(subheader, len, ctx);
  706|  21.8k|    } else if (subheader_type == SAS_SUBHEADER_TYPE_COLUMN_SIZE) {
  ------------------
  |  Branch (706:16): [True: 1.53k, False: 20.3k]
  ------------------
  707|  1.53k|        retval = sas7bdat_parse_column_size_subheader(subheader, len, ctx);
  708|  20.3k|    } else if (subheader_type == SAS_SUBHEADER_TYPE_COUNTS) {
  ------------------
  |  Branch (708:16): [True: 1.83k, False: 18.5k]
  ------------------
  709|       |        /* void */
  710|  18.5k|    } else if (subheader_type == SAS_SUBHEADER_TYPE_COLUMN_TEXT) {
  ------------------
  |  Branch (710:16): [True: 8.50k, False: 10.0k]
  ------------------
  711|  8.50k|        retval = sas7bdat_parse_column_text_subheader(subheader, len, ctx);
  712|  10.0k|    } else if (subheader_type == SAS_SUBHEADER_TYPE_COLUMN_NAME) {
  ------------------
  |  Branch (712:16): [True: 2.56k, False: 7.44k]
  ------------------
  713|  2.56k|        retval = sas7bdat_parse_column_name_subheader(subheader, len, ctx);
  714|  7.44k|    } else if (subheader_type == SAS_SUBHEADER_TYPE_COLUMN_ATTRS) {
  ------------------
  |  Branch (714:16): [True: 1.89k, False: 5.54k]
  ------------------
  715|  1.89k|        retval = sas7bdat_parse_column_attributes_subheader(subheader, len, ctx);
  716|  5.54k|    } else if (subheader_type == SAS_SUBHEADER_TYPE_COLUMN_FORMAT) {
  ------------------
  |  Branch (716:16): [True: 3.94k, False: 1.60k]
  ------------------
  717|  3.94k|        retval = sas7bdat_parse_column_format_subheader(subheader, len, ctx);
  718|  3.94k|    } else if (subheader_type == SAS_SUBHEADER_TYPE_COLUMN_LIST) {
  ------------------
  |  Branch (718:16): [True: 824, False: 776]
  ------------------
  719|       |        /* void */
  720|    824|    } else if (subheader_type == SAS_SUBHEADER_TYPE_UNKNOWN) {
  ------------------
  |  Branch (720:16): [True: 745, False: 31]
  ------------------
  721|       |        /* void */
  722|    745|    } else {
  723|     31|        retval = READSTAT_ERROR_PARSE;
  724|     31|    }
  725|       |
  726|  25.0k|cleanup:
  727|       |
  728|  25.0k|    return retval;
  729|  25.0k|}
readstat_sas7bdat_read.c:sas7bdat_parse_row_size_subheader:
  245|  3.18k|static readstat_error_t sas7bdat_parse_row_size_subheader(const char *subheader, size_t len, sas7bdat_ctx_t *ctx) {
  246|  3.18k|    readstat_error_t retval = READSTAT_OK;
  247|  3.18k|    uint64_t total_row_count;
  248|  3.18k|    uint64_t row_length, deleted_row_count, page_row_count;
  249|       |
  250|  3.18k|    if (len < (ctx->u64 ? 250: 190)) {
  ------------------
  |  Branch (250:9): [True: 4, False: 3.17k]
  |  Branch (250:16): [True: 978, False: 2.20k]
  ------------------
  251|      4|        retval = READSTAT_ERROR_PARSE;
  252|      4|        goto cleanup;
  253|      4|    }
  254|       |
  255|  3.17k|    if (ctx->u64) {
  ------------------
  |  Branch (255:9): [True: 976, False: 2.20k]
  ------------------
  256|    976|        row_length = sas_read8(&subheader[40], ctx->bswap);
  257|    976|        total_row_count = sas_read8(&subheader[48], ctx->bswap);
  258|    976|        deleted_row_count = sas_read8(&subheader[56], ctx->bswap);
  259|    976|        page_row_count = sas_read8(&subheader[120], ctx->bswap);
  260|  2.20k|    } else {
  261|  2.20k|        row_length = sas_read4(&subheader[20], ctx->bswap);
  262|  2.20k|        total_row_count = sas_read4(&subheader[24], ctx->bswap);
  263|  2.20k|        deleted_row_count = sas_read4(&subheader[28], ctx->bswap);
  264|  2.20k|        page_row_count = sas_read4(&subheader[60], ctx->bswap);
  265|  2.20k|    }
  266|       |
  267|  3.17k|    if (deleted_row_count > total_row_count) {
  ------------------
  |  Branch (267:9): [True: 38, False: 3.14k]
  ------------------
  268|     38|        retval = READSTAT_ERROR_PARSE;
  269|     38|        goto cleanup;
  270|     38|    }
  271|  3.14k|    ctx->total_row_count = total_row_count;
  272|  3.14k|    ctx->deleted_row_count = deleted_row_count;
  273|       |
  274|  3.14k|    sas_text_ref_t file_label_ref = sas7bdat_parse_text_ref(&subheader[len-130], ctx);
  275|  3.14k|    if (file_label_ref.length) {
  ------------------
  |  Branch (275:9): [True: 665, False: 2.47k]
  ------------------
  276|    665|        if ((retval = sas7bdat_copy_text_ref(ctx->file_label, sizeof(ctx->file_label),
  ------------------
  |  Branch (276:13): [True: 43, False: 622]
  ------------------
  277|    665|                        file_label_ref, ctx)) != READSTAT_OK) {
  278|     43|            goto cleanup;
  279|     43|        }
  280|    665|    }
  281|       |
  282|  3.09k|    sas_text_ref_t compression_ref = sas7bdat_parse_text_ref(&subheader[len-118], ctx);
  283|  3.09k|    if (compression_ref.length) {
  ------------------
  |  Branch (283:9): [True: 1.11k, False: 1.97k]
  ------------------
  284|  1.11k|        char compression[9];
  285|  1.11k|        if ((retval = sas7bdat_copy_text_ref(compression, sizeof(compression),
  ------------------
  |  Branch (285:13): [True: 41, False: 1.07k]
  ------------------
  286|  1.11k|                        compression_ref, ctx)) != READSTAT_OK) {
  287|     41|            goto cleanup;
  288|     41|        }
  289|  1.07k|        ctx->rdc_compression = (memcmp(compression, SAS_COMPRESSION_SIGNATURE_RDC, 8) == 0);
  ------------------
  |  |  136|  1.07k|#define SAS_COMPRESSION_SIGNATURE_RDC  "SASYZCR2"
  ------------------
  290|  1.07k|    }
  291|       |
  292|  3.05k|    ctx->row_length = row_length;
  293|  3.05k|    ctx->row = readstat_realloc(ctx->row, ctx->row_length);
  294|  3.05k|    if (ctx->row == NULL) {
  ------------------
  |  Branch (294:9): [True: 14, False: 3.04k]
  ------------------
  295|     14|        retval = READSTAT_ERROR_MALLOC;
  296|     14|        goto cleanup;
  297|     14|    }
  298|       |
  299|  3.04k|    ctx->page_row_count = page_row_count;
  300|  3.04k|    uint64_t live_row_count = total_row_count - deleted_row_count;
  301|  3.04k|    uint64_t total_row_count_after_skipping = live_row_count;
  302|  3.04k|    if (live_row_count > ctx->row_offset) {
  ------------------
  |  Branch (302:9): [True: 2.72k, False: 320]
  ------------------
  303|  2.72k|        total_row_count_after_skipping -= ctx->row_offset;
  304|  2.72k|    } else {
  305|    320|        total_row_count_after_skipping = 0;
  306|    320|        ctx->row_offset = live_row_count;
  307|    320|    }
  308|  3.04k|    if (ctx->row_limit == 0 || total_row_count_after_skipping < ctx->row_limit)
  ------------------
  |  Branch (308:9): [True: 1.16k, False: 1.88k]
  |  Branch (308:32): [True: 92, False: 1.78k]
  ------------------
  309|  1.25k|        ctx->row_limit = total_row_count_after_skipping;
  310|       |
  311|  3.18k|cleanup:
  312|  3.18k|    return retval;
  313|  3.04k|}
readstat_sas7bdat_read.c:sas7bdat_parse_text_ref:
  146|  47.1k|static sas_text_ref_t sas7bdat_parse_text_ref(const char *data, sas7bdat_ctx_t *ctx) {
  147|  47.1k|    sas_text_ref_t  ref;
  148|       |
  149|  47.1k|    ref.index = sas_read2(&data[0], ctx->bswap);
  150|  47.1k|    ref.offset = sas_read2(&data[2], ctx->bswap);
  151|  47.1k|    ref.length = sas_read2(&data[4], ctx->bswap);
  152|       |
  153|  47.1k|    return ref;
  154|  47.1k|}
readstat_sas7bdat_read.c:sas7bdat_copy_text_ref:
  156|  9.23M|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) {
  157|  9.23M|    if (text_ref.index >= ctx->text_blob_count)
  ------------------
  |  Branch (157:9): [True: 138, False: 9.23M]
  ------------------
  158|    138|        return READSTAT_ERROR_PARSE;
  159|       |    
  160|  9.23M|    if (text_ref.length == 0) {
  ------------------
  |  Branch (160:9): [True: 9.22M, False: 4.44k]
  ------------------
  161|  9.22M|        out_buffer[0] = '\0';
  162|  9.22M|        return READSTAT_OK;
  163|  9.22M|    }
  164|       |
  165|  4.44k|    char *blob = ctx->text_blobs[text_ref.index];
  166|       |
  167|  4.44k|    if (text_ref.offset + text_ref.length > ctx->text_blob_lengths[text_ref.index])
  ------------------
  |  Branch (167:9): [True: 82, False: 4.36k]
  ------------------
  168|     82|        return READSTAT_ERROR_PARSE;
  169|       |
  170|  4.36k|    return readstat_convert(out_buffer, out_buffer_len, &blob[text_ref.offset], text_ref.length,
  171|  4.36k|            ctx->converter);
  172|  4.44k|}
readstat_sas7bdat_read.c:sas7bdat_parse_column_size_subheader:
  217|  1.53k|static readstat_error_t sas7bdat_parse_column_size_subheader(const char *subheader, size_t len, sas7bdat_ctx_t *ctx) {
  218|  1.53k|    uint64_t col_count;
  219|  1.53k|    readstat_error_t retval = READSTAT_OK;
  220|       |
  221|  1.53k|    if (ctx->column_count || ctx->did_submit_columns) {
  ------------------
  |  Branch (221:9): [True: 22, False: 1.51k]
  |  Branch (221:30): [True: 1, False: 1.51k]
  ------------------
  222|     23|        retval = READSTAT_ERROR_PARSE;
  223|     23|        goto cleanup;
  224|     23|    }
  225|       |
  226|  1.51k|    if (len < (ctx->u64 ? 16 : 8)) {
  ------------------
  |  Branch (226:9): [True: 3, False: 1.50k]
  |  Branch (226:16): [True: 492, False: 1.01k]
  ------------------
  227|      3|        retval = READSTAT_ERROR_PARSE;
  228|      3|        goto cleanup;
  229|      3|    }
  230|       |
  231|  1.50k|    if (ctx->u64) {
  ------------------
  |  Branch (231:9): [True: 490, False: 1.01k]
  ------------------
  232|    490|        col_count = sas_read8(&subheader[8], ctx->bswap);
  233|  1.01k|    } else {
  234|  1.01k|        col_count = sas_read4(&subheader[4], ctx->bswap);
  235|  1.01k|    }
  236|       |
  237|  1.50k|    ctx->column_count = col_count;
  238|       |
  239|  1.50k|    retval = sas7bdat_realloc_col_info(ctx, ctx->column_count);
  240|       |
  241|  1.53k|cleanup:
  242|  1.53k|    return retval;
  243|  1.50k|}
readstat_sas7bdat_read.c:sas7bdat_realloc_col_info:
  204|  9.79k|static readstat_error_t sas7bdat_realloc_col_info(sas7bdat_ctx_t *ctx, size_t count) {
  205|  9.79k|    if (ctx->col_info_count < count) {
  ------------------
  |  Branch (205:9): [True: 3.74k, False: 6.05k]
  ------------------
  206|  3.74k|        size_t old_count = ctx->col_info_count;
  207|  3.74k|        ctx->col_info_count = count;
  208|  3.74k|        ctx->col_info = readstat_realloc(ctx->col_info, ctx->col_info_count * sizeof(col_info_t));
  209|  3.74k|        if (ctx->col_info == NULL) {
  ------------------
  |  Branch (209:13): [True: 83, False: 3.66k]
  ------------------
  210|     83|            return READSTAT_ERROR_MALLOC;
  211|     83|        }
  212|  3.66k|        memset(ctx->col_info + old_count, 0, (count - old_count) * sizeof(col_info_t));
  213|  3.66k|    }
  214|  9.71k|    return READSTAT_OK;
  215|  9.79k|}
readstat_sas7bdat_read.c:sas7bdat_parse_column_text_subheader:
  174|  8.50k|static readstat_error_t sas7bdat_parse_column_text_subheader(const char *subheader, size_t len, sas7bdat_ctx_t *ctx) {
  175|  8.50k|    readstat_error_t retval = READSTAT_OK;
  176|  8.50k|    size_t signature_len = ctx->subheader_signature_size;
  177|  8.50k|    uint16_t remainder = sas_read2(&subheader[signature_len], ctx->bswap);
  178|  8.50k|    char *blob = NULL;
  179|  8.50k|    if (remainder != sas_subheader_remainder(len, signature_len)) {
  ------------------
  |  Branch (179:9): [True: 52, False: 8.45k]
  ------------------
  180|     52|        retval = READSTAT_ERROR_PARSE;
  181|     52|        goto cleanup;
  182|     52|    }
  183|  8.45k|    ctx->text_blob_count++;
  184|  8.45k|    ctx->text_blobs = readstat_realloc(ctx->text_blobs, ctx->text_blob_count * sizeof(char *));
  185|  8.45k|    ctx->text_blob_lengths = readstat_realloc(ctx->text_blob_lengths,
  186|  8.45k|            ctx->text_blob_count * sizeof(ctx->text_blob_lengths[0]));
  187|  8.45k|    if (ctx->text_blobs == NULL || ctx->text_blob_lengths == NULL) {
  ------------------
  |  Branch (187:9): [True: 0, False: 8.45k]
  |  Branch (187:36): [True: 0, False: 8.45k]
  ------------------
  188|      0|        retval = READSTAT_ERROR_MALLOC;
  189|      0|        goto cleanup;
  190|      0|    }
  191|       |
  192|  8.45k|    if ((blob = readstat_malloc(len-signature_len)) == NULL) {
  ------------------
  |  Branch (192:9): [True: 0, False: 8.45k]
  ------------------
  193|      0|        retval = READSTAT_ERROR_MALLOC;
  194|      0|        goto cleanup;
  195|      0|    }
  196|  8.45k|    memcpy(blob, subheader+signature_len, len-signature_len);
  197|  8.45k|    ctx->text_blob_lengths[ctx->text_blob_count-1] = len-signature_len;
  198|  8.45k|    ctx->text_blobs[ctx->text_blob_count-1] = blob;
  199|       |
  200|  8.50k|cleanup:
  201|  8.50k|    return retval;
  202|  8.45k|}
readstat_sas7bdat_read.c:sas7bdat_parse_column_name_subheader:
  315|  2.56k|static readstat_error_t sas7bdat_parse_column_name_subheader(const char *subheader, size_t len, sas7bdat_ctx_t *ctx) {
  316|  2.56k|    readstat_error_t retval = READSTAT_OK;
  317|  2.56k|    size_t signature_len = ctx->subheader_signature_size;
  318|  2.56k|    int cmax = ctx->u64 ? (len-28)/8 : (len-20)/8;
  ------------------
  |  Branch (318:16): [True: 1.42k, False: 1.14k]
  ------------------
  319|  2.56k|    int i;
  320|  2.56k|    const char *cnp = &subheader[signature_len+8];
  321|  2.56k|    uint16_t remainder = sas_read2(&subheader[signature_len], ctx->bswap);
  322|       |
  323|  2.56k|    if (remainder != sas_subheader_remainder(len, signature_len)) {
  ------------------
  |  Branch (323:9): [True: 59, False: 2.50k]
  ------------------
  324|     59|        retval = READSTAT_ERROR_PARSE;
  325|     59|        goto cleanup;
  326|     59|    }
  327|       |
  328|  2.50k|    ctx->col_names_count += cmax;
  329|       |
  330|  2.50k|    if ((retval = sas7bdat_realloc_col_info(ctx, ctx->col_names_count)) != READSTAT_OK)
  ------------------
  |  Branch (330:9): [True: 14, False: 2.49k]
  ------------------
  331|     14|        goto cleanup;
  332|       |
  333|  31.5k|    for (i=ctx->col_names_count-cmax; i<ctx->col_names_count; i++) {
  ------------------
  |  Branch (333:39): [True: 29.0k, False: 2.49k]
  ------------------
  334|  29.0k|        ctx->col_info[i].name_ref = sas7bdat_parse_text_ref(cnp, ctx);
  335|  29.0k|        cnp += 8;
  336|  29.0k|    }
  337|       |
  338|  2.56k|cleanup:
  339|       |
  340|  2.56k|    return retval;
  341|  2.49k|}
readstat_sas7bdat_read.c:sas7bdat_parse_column_attributes_subheader:
  343|  1.89k|static readstat_error_t sas7bdat_parse_column_attributes_subheader(const char *subheader, size_t len, sas7bdat_ctx_t *ctx) {
  344|  1.89k|    readstat_error_t retval = READSTAT_OK;
  345|  1.89k|    size_t signature_len = ctx->subheader_signature_size;
  346|  1.89k|    int cmax = ctx->u64 ? (len-28)/16 : (len-20)/12;
  ------------------
  |  Branch (346:16): [True: 328, False: 1.56k]
  ------------------
  347|  1.89k|    int i;
  348|  1.89k|    const char *cap = &subheader[signature_len+8];
  349|  1.89k|    uint16_t remainder = sas_read2(&subheader[signature_len], ctx->bswap);
  350|       |
  351|  1.89k|    if (remainder != sas_subheader_remainder(len, signature_len)) {
  ------------------
  |  Branch (351:9): [True: 59, False: 1.83k]
  ------------------
  352|     59|        retval = READSTAT_ERROR_PARSE;
  353|     59|        goto cleanup;
  354|     59|    }
  355|  1.83k|    ctx->col_attrs_count += cmax;
  356|  1.83k|    if ((retval = sas7bdat_realloc_col_info(ctx, ctx->col_attrs_count)) != READSTAT_OK)
  ------------------
  |  Branch (356:9): [True: 11, False: 1.82k]
  ------------------
  357|     11|        goto cleanup;
  358|       |
  359|  9.51k|    for (i=ctx->col_attrs_count-cmax; i<ctx->col_attrs_count; i++) {
  ------------------
  |  Branch (359:39): [True: 7.70k, False: 1.80k]
  ------------------
  360|  7.70k|        if (ctx->u64) {
  ------------------
  |  Branch (360:13): [True: 962, False: 6.74k]
  ------------------
  361|    962|            ctx->col_info[i].offset = sas_read8(&cap[0], ctx->bswap);
  362|  6.74k|        } else {
  363|  6.74k|            ctx->col_info[i].offset = sas_read4(&cap[0], ctx->bswap);
  364|  6.74k|        }
  365|       |
  366|  7.70k|        readstat_off_t off=4;
  367|  7.70k|        if (ctx->u64)
  ------------------
  |  Branch (367:13): [True: 962, False: 6.74k]
  ------------------
  368|    962|            off=8;
  369|       |
  370|  7.70k|        ctx->col_info[i].width = sas_read4(&cap[off], ctx->bswap);
  371|  7.70k|        if (ctx->col_info[i].width > ctx->max_col_width)
  ------------------
  |  Branch (371:13): [True: 793, False: 6.91k]
  ------------------
  372|    793|            ctx->max_col_width = ctx->col_info[i].width;
  373|       |
  374|  7.70k|        if (cap[off+6] == SAS_COLUMN_TYPE_NUM) {
  ------------------
  |  |   90|  7.70k|#define SAS_COLUMN_TYPE_NUM  0x01
  ------------------
  |  Branch (374:13): [True: 4.57k, False: 3.12k]
  ------------------
  375|  4.57k|            ctx->col_info[i].type = READSTAT_TYPE_DOUBLE;
  376|  4.57k|        } else if (cap[off+6] == SAS_COLUMN_TYPE_CHR) {
  ------------------
  |  |   91|  3.12k|#define SAS_COLUMN_TYPE_CHR  0x02
  ------------------
  |  Branch (376:20): [True: 3.10k, False: 19]
  ------------------
  377|  3.10k|            ctx->col_info[i].type = READSTAT_TYPE_STRING;
  378|  3.10k|        } else {
  379|     19|            retval = READSTAT_ERROR_PARSE;
  380|     19|            goto cleanup;
  381|     19|        }
  382|  7.68k|        ctx->col_info[i].index = i;
  383|  7.68k|        cap += off+8;
  384|  7.68k|    }
  385|       |
  386|  1.89k|cleanup:
  387|       |
  388|  1.89k|    return retval;
  389|  1.82k|}
readstat_sas7bdat_read.c:sas7bdat_parse_column_format_subheader:
  391|  3.94k|static readstat_error_t sas7bdat_parse_column_format_subheader(const char *subheader, size_t len, sas7bdat_ctx_t *ctx) {
  392|  3.94k|    readstat_error_t retval = READSTAT_OK;
  393|       |
  394|  3.94k|    if (len < (ctx->u64 ? 58 : 46)) {
  ------------------
  |  Branch (394:9): [True: 1, False: 3.94k]
  |  Branch (394:16): [True: 379, False: 3.56k]
  ------------------
  395|      1|        retval = READSTAT_ERROR_PARSE;
  396|      1|        goto cleanup;
  397|      1|    }
  398|       |
  399|  3.94k|    ctx->col_formats_count++;
  400|  3.94k|    if ((retval = sas7bdat_realloc_col_info(ctx, ctx->col_formats_count)) != READSTAT_OK)
  ------------------
  |  Branch (400:9): [True: 0, False: 3.94k]
  ------------------
  401|      0|        goto cleanup;
  402|       |
  403|  3.94k|    col_info_t *col_info = &ctx->col_info[ctx->col_formats_count-1];
  404|  3.94k|    if (ctx->u64) {
  ------------------
  |  Branch (404:9): [True: 379, False: 3.56k]
  ------------------
  405|    379|        col_info->format_width = sas_read2(&subheader[24], ctx->bswap);
  406|    379|        col_info->format_digits = sas_read2(&subheader[26], ctx->bswap);
  407|    379|        col_info->informat_width = sas_read2(&subheader[28], ctx->bswap);
  408|    379|        col_info->informat_digits = sas_read2(&subheader[30], ctx->bswap);
  409|  3.56k|    } else {
  410|  3.56k|        col_info->format_width = sas_read2(&subheader[12], ctx->bswap);
  411|  3.56k|        col_info->format_digits = sas_read2(&subheader[14], ctx->bswap);
  412|  3.56k|        col_info->informat_width = sas_read2(&subheader[16], ctx->bswap);
  413|  3.56k|        col_info->informat_digits = sas_read2(&subheader[18], ctx->bswap);
  414|  3.56k|    }
  415|  3.94k|    col_info->informat_ref = sas7bdat_parse_text_ref(
  416|  3.94k|            ctx->u64 ? &subheader[40] : &subheader[28], ctx);
  ------------------
  |  Branch (416:13): [True: 379, False: 3.56k]
  ------------------
  417|  3.94k|    col_info->format_ref = sas7bdat_parse_text_ref(
  418|  3.94k|            ctx->u64 ? &subheader[46] : &subheader[34], ctx);
  ------------------
  |  Branch (418:13): [True: 379, False: 3.56k]
  ------------------
  419|  3.94k|    col_info->label_ref = sas7bdat_parse_text_ref(
  420|  3.94k|            ctx->u64 ? &subheader[52] : &subheader[40], ctx);
  ------------------
  |  Branch (420:13): [True: 379, False: 3.56k]
  ------------------
  421|       |
  422|  3.94k|cleanup:
  423|  3.94k|    return retval;
  424|  3.94k|}
readstat_sas7bdat_read.c:sas7bdat_is_moved_row:
  996|  4.19k|static int sas7bdat_is_moved_row(unsigned char compression) {
  997|  4.19k|    return compression == SAS_COMPRESSION_ROW_MOVED
  ------------------
  |  |  131|  8.38k|#define SAS_COMPRESSION_ROW_MOVED          0x06
  ------------------
  |  Branch (997:12): [True: 1.21k, False: 2.97k]
  ------------------
  998|  2.97k|        || compression == SAS_COMPRESSION_NONE_MOVED
  ------------------
  |  |  127|  7.16k|#define SAS_COMPRESSION_NONE_MOVED         0x02
  ------------------
  |  Branch (998:12): [True: 930, False: 2.04k]
  ------------------
  999|  2.04k|        || compression == SAS_COMPRESSION_ROW_UNREFERENCED
  ------------------
  |  |  133|  6.23k|#define SAS_COMPRESSION_ROW_UNREFERENCED   0x0d
  ------------------
  |  Branch (999:12): [True: 1.08k, False: 963]
  ------------------
 1000|    963|        || compression == SAS_COMPRESSION_NONE_UNREFERENCED;
  ------------------
  |  |  132|    963|#define SAS_COMPRESSION_NONE_UNREFERENCED  0x09
  ------------------
  |  Branch (1000:12): [True: 913, False: 50]
  ------------------
 1001|  4.19k|}
readstat_sas7bdat_read.c:sas7bdat_parse_amd_pages_pass1:
 1363|  3.70k|static readstat_error_t sas7bdat_parse_amd_pages_pass1(int64_t last_examined_page_pass1, sas7bdat_ctx_t *ctx) {
 1364|  3.70k|    readstat_error_t retval = READSTAT_OK;
 1365|  3.70k|    readstat_io_t *io = ctx->io;
 1366|  3.70k|    uint64_t i;
 1367|  3.70k|    uint64_t amd_page_count = 0;
 1368|       |
 1369|       |    /* ...then AMD pages at the end */
 1370|  7.67k|    for (i=ctx->page_count-1; i>last_examined_page_pass1; i--) {
  ------------------
  |  Branch (1370:31): [True: 5.80k, False: 1.87k]
  ------------------
 1371|  5.80k|        if (io->seek(ctx->header_size + i*ctx->page_size, READSTAT_SEEK_SET, io->io_ctx) == -1) {
  ------------------
  |  Branch (1371:13): [True: 247, False: 5.55k]
  ------------------
 1372|    247|            retval = READSTAT_ERROR_SEEK;
 1373|    247|            if (ctx->handle.error) {
  ------------------
  |  Branch (1373:17): [True: 0, False: 247]
  ------------------
 1374|      0|                snprintf(ctx->error_buf, sizeof(ctx->error_buf), "ReadStat: Failed to seek to position %" PRId64 
 1375|      0|                        " (= %" PRId64 " + %" PRId64 "*%" PRId64 ")",
 1376|      0|                        ctx->header_size + i*ctx->page_size, ctx->header_size, i, ctx->page_size);
 1377|      0|                ctx->handle.error(ctx->error_buf, ctx->user_ctx);
 1378|      0|            }
 1379|    247|            goto cleanup;
 1380|    247|        }
 1381|       |
 1382|  5.55k|        readstat_off_t off = 0;
 1383|  5.55k|        if (ctx->u64)
  ------------------
  |  Branch (1383:13): [True: 4.83k, False: 726]
  ------------------
 1384|  4.83k|            off = 16;
 1385|       |
 1386|  5.55k|        size_t head_len = off + 16 + 2;
 1387|  5.55k|        size_t tail_len = ctx->page_size - head_len;
 1388|       |
 1389|  5.55k|        if (io->read(ctx->page, head_len, io->io_ctx) < head_len) {
  ------------------
  |  Branch (1389:13): [True: 11, False: 5.54k]
  ------------------
 1390|     11|            retval = READSTAT_ERROR_READ;
 1391|     11|            goto cleanup;
 1392|     11|        }
 1393|       |
 1394|  5.54k|        uint16_t page_type = sas_read2(&ctx->page[off+16], ctx->bswap);
 1395|       |
 1396|  5.54k|        if ((page_type & SAS_PAGE_TYPE_MASK) == SAS_PAGE_TYPE_DATA) {
  ------------------
  |  |  113|  5.54k|#define SAS_PAGE_TYPE_MASK   0x0F00
  ------------------
                      if ((page_type & SAS_PAGE_TYPE_MASK) == SAS_PAGE_TYPE_DATA) {
  ------------------
  |  |  110|  5.54k|#define SAS_PAGE_TYPE_DATA   0x0100
  ------------------
  |  Branch (1396:13): [True: 1.17k, False: 4.37k]
  ------------------
 1397|       |            /* Usually AMD pages are at the end but sometimes data pages appear after them */
 1398|  1.17k|            if (amd_page_count > 0)
  ------------------
  |  Branch (1398:17): [True: 634, False: 537]
  ------------------
 1399|    634|                break;
 1400|    537|            continue;
 1401|  1.17k|        }
 1402|  4.37k|        if ((page_type & SAS_PAGE_TYPE_COMP))
  ------------------
  |  |  117|  4.37k|#define SAS_PAGE_TYPE_COMP          0x9000
  ------------------
  |  Branch (1402:13): [True: 920, False: 3.45k]
  ------------------
 1403|    920|            continue;
 1404|       |
 1405|  3.45k|        if (io->read(ctx->page + head_len, tail_len, io->io_ctx) < tail_len) {
  ------------------
  |  Branch (1405:13): [True: 18, False: 3.43k]
  ------------------
 1406|     18|            retval = READSTAT_ERROR_READ;
 1407|     18|            goto cleanup;
 1408|     18|        }
 1409|       |
 1410|  3.43k|        if ((retval = sas7bdat_parse_page_pass1(ctx->page, ctx->page_size, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1410:13): [True: 918, False: 2.51k]
  ------------------
 1411|    918|            if (ctx->handle.error && retval != READSTAT_ERROR_USER_ABORT) {
  ------------------
  |  Branch (1411:17): [True: 0, False: 918]
  |  Branch (1411:38): [True: 0, False: 0]
  ------------------
 1412|      0|                int64_t pos = io->seek(0, READSTAT_SEEK_CUR, io->io_ctx);
 1413|      0|                snprintf(ctx->error_buf, sizeof(ctx->error_buf), 
 1414|      0|                        "ReadStat: Error parsing page %" PRId64 ", bytes %" PRId64 "-%" PRId64, 
 1415|      0|                        i, pos - ctx->page_size, pos-1);
 1416|      0|                ctx->handle.error(ctx->error_buf, ctx->user_ctx);
 1417|      0|            }
 1418|    918|            goto cleanup;
 1419|    918|        }
 1420|       |
 1421|  2.51k|        amd_page_count++;
 1422|  2.51k|    }
 1423|       |
 1424|  3.70k|cleanup:
 1425|       |
 1426|  3.70k|    return retval;
 1427|  3.70k|}
readstat_sas7bdat_read.c:sas7bdat_parse_all_pages_pass2:
 1429|  2.50k|static readstat_error_t sas7bdat_parse_all_pages_pass2(sas7bdat_ctx_t *ctx) {
 1430|  2.50k|    readstat_error_t retval = READSTAT_OK;
 1431|  2.50k|    readstat_io_t *io = ctx->io;
 1432|  2.50k|    int64_t i;
 1433|       |
 1434|  7.35k|    for (i=0; i<ctx->page_count; i++) {
  ------------------
  |  Branch (1434:15): [True: 7.03k, False: 318]
  ------------------
 1435|  7.03k|        if ((retval = sas7bdat_update_progress(ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1435:13): [True: 0, False: 7.03k]
  ------------------
 1436|      0|            goto cleanup;
 1437|      0|        }
 1438|  7.03k|        if (io->read(ctx->page, ctx->page_size, io->io_ctx) < ctx->page_size) {
  ------------------
  |  Branch (1438:13): [True: 163, False: 6.87k]
  ------------------
 1439|    163|            retval = READSTAT_ERROR_READ;
 1440|    163|            goto cleanup;
 1441|    163|        }
 1442|       |
 1443|  6.87k|        if ((retval = sas7bdat_parse_page_pass2(ctx->page, ctx->page_size, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1443:13): [True: 2.01k, False: 4.86k]
  ------------------
 1444|  2.01k|            if (ctx->handle.error && retval != READSTAT_ERROR_USER_ABORT) {
  ------------------
  |  Branch (1444:17): [True: 0, False: 2.01k]
  |  Branch (1444:38): [True: 0, False: 0]
  ------------------
 1445|      0|                int64_t pos = io->seek(0, READSTAT_SEEK_CUR, io->io_ctx);
 1446|      0|                snprintf(ctx->error_buf, sizeof(ctx->error_buf), 
 1447|      0|                        "ReadStat: Error parsing page %" PRId64 ", bytes %" PRId64 "-%" PRId64, 
 1448|      0|                        i, pos - ctx->page_size, pos-1);
 1449|      0|                ctx->handle.error(ctx->error_buf, ctx->user_ctx);
 1450|      0|            }
 1451|  2.01k|            goto cleanup;
 1452|  2.01k|        }
 1453|  4.86k|        if (ctx->row_limit > 0 && ctx->parsed_row_count == ctx->row_limit)
  ------------------
  |  Branch (1453:13): [True: 949, False: 3.91k]
  |  Branch (1453:35): [True: 13, False: 936]
  ------------------
 1454|     13|            break;
 1455|  4.86k|    }
 1456|  2.50k|cleanup:
 1457|       |
 1458|  2.50k|    return retval;
 1459|  2.50k|}
readstat_sas7bdat_read.c:sas7bdat_parse_page_pass2:
 1184|  6.87k|static readstat_error_t sas7bdat_parse_page_pass2(const char *page, size_t page_size, sas7bdat_ctx_t *ctx) {
 1185|  6.87k|    uint16_t page_type;
 1186|       |
 1187|  6.87k|    readstat_error_t retval = READSTAT_OK;
 1188|       |
 1189|  6.87k|    page_type = sas_read2(&page[ctx->page_header_size-8], ctx->bswap);
 1190|       |
 1191|  6.87k|    const char *data = NULL;
 1192|       |
 1193|  6.87k|    if ((page_type & SAS_PAGE_TYPE_MASK) == SAS_PAGE_TYPE_DATA) {
  ------------------
  |  |  113|  6.87k|#define SAS_PAGE_TYPE_MASK   0x0F00
  ------------------
                  if ((page_type & SAS_PAGE_TYPE_MASK) == SAS_PAGE_TYPE_DATA) {
  ------------------
  |  |  110|  6.87k|#define SAS_PAGE_TYPE_DATA   0x0100
  ------------------
  |  Branch (1193:9): [True: 732, False: 6.14k]
  ------------------
 1194|    732|        ctx->page_row_count = sas_read2(&page[ctx->page_header_size-6], ctx->bswap);
 1195|    732|        data = &page[ctx->page_header_size];
 1196|  6.14k|    } else if (!(page_type & SAS_PAGE_TYPE_COMP)) {
  ------------------
  |  |  117|  6.14k|#define SAS_PAGE_TYPE_COMP          0x9000
  ------------------
  |  Branch (1196:16): [True: 5.53k, False: 610]
  ------------------
 1197|  5.53k|        uint16_t subheader_count = sas_read2(&page[ctx->page_header_size-4], ctx->bswap);
 1198|       |
 1199|  5.53k|        int i;
 1200|  5.53k|        const char *shp = &page[ctx->page_header_size];
 1201|  5.53k|        int lshp = ctx->subheader_pointer_size;
 1202|       |
 1203|  5.53k|        if (ctx->page_header_size + subheader_count*lshp > page_size) {
  ------------------
  |  Branch (1203:13): [True: 30, False: 5.50k]
  ------------------
 1204|     30|            retval = READSTAT_ERROR_PARSE;
 1205|     30|            goto cleanup;
 1206|     30|        }
 1207|       |
 1208|  54.0k|        for (i=0; i<subheader_count; i++) {
  ------------------
  |  Branch (1208:19): [True: 50.1k, False: 3.92k]
  ------------------
 1209|  50.1k|            subheader_pointer_t shp_info = { 0 };
 1210|  50.1k|            if ((retval = sas7bdat_parse_subheader_pointer(shp, page + page_size - shp, &shp_info, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1210:17): [True: 0, False: 50.1k]
  ------------------
 1211|      0|                goto cleanup;
 1212|      0|            }
 1213|  50.1k|            if (shp_info.len > 0 && shp_info.compression == SAS_COMPRESSION_REFERENCE) {
  ------------------
  |  |  128|  33.1k|#define SAS_COMPRESSION_REFERENCE          0x03
  ------------------
  |  Branch (1213:17): [True: 33.1k, False: 17.0k]
  |  Branch (1213:37): [True: 684, False: 32.4k]
  ------------------
 1214|    684|                uint64_t page_index = shp_info.offset - 1;
 1215|    684|                uint64_t subheader_index = shp_info.len - 1;
 1216|    684|                if ((retval = sas7bdat_parse_moved_row(page_index, subheader_index, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1216:21): [True: 506, False: 178]
  ------------------
 1217|    506|                    goto cleanup;
 1218|    506|                }
 1219|  49.4k|            } else if (shp_info.len > 0 && shp_info.compression != SAS_COMPRESSION_TRUNC) {
  ------------------
  |  |  126|  32.4k|#define SAS_COMPRESSION_TRUNC              0x01
  ------------------
  |  Branch (1219:24): [True: 32.4k, False: 17.0k]
  |  Branch (1219:44): [True: 27.6k, False: 4.78k]
  ------------------
 1220|  27.6k|                if ((retval = sas7bdat_validate_subheader_pointer(&shp_info, page_size, subheader_count, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1220:21): [True: 227, False: 27.4k]
  ------------------
 1221|    227|                    goto cleanup;
 1222|    227|                }
 1223|  27.4k|                if (shp_info.compression == SAS_COMPRESSION_NONE) {
  ------------------
  |  |  125|  27.4k|#define SAS_COMPRESSION_NONE               0x00
  ------------------
  |  Branch (1223:21): [True: 23.4k, False: 3.98k]
  ------------------
 1224|  23.4k|                    sas_subheader_type_t subheader_type = sas7bdat_parse_subheader_type(page + shp_info.offset, ctx);
 1225|  23.4k|                    if (shp_info.is_compressed_data && subheader_type == SAS_SUBHEADER_TYPE_DATA) {
  ------------------
  |  Branch (1225:25): [True: 14.6k, False: 8.81k]
  |  Branch (1225:56): [True: 506, False: 14.1k]
  ------------------
 1226|    506|                        if (shp_info.len != ctx->row_length) {
  ------------------
  |  Branch (1226:29): [True: 87, False: 419]
  ------------------
 1227|     87|                            retval = READSTAT_ERROR_ROW_WIDTH_MISMATCH;
 1228|     87|                            goto cleanup;
 1229|     87|                        }
 1230|    419|                        if ((retval = sas7bdat_submit_columns_if_needed(ctx, 1)) != READSTAT_OK) {
  ------------------
  |  Branch (1230:29): [True: 9, False: 410]
  ------------------
 1231|      9|                            goto cleanup;
 1232|      9|                        }
 1233|    410|                        if ((retval = sas7bdat_parse_single_row(page + shp_info.offset, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1233:29): [True: 7, False: 403]
  ------------------
 1234|      7|                            goto cleanup;
 1235|      7|                        }
 1236|  22.9k|                    } else {
 1237|  22.9k|                        if (subheader_type != SAS_SUBHEADER_TYPE_COLUMN_TEXT) {
  ------------------
  |  Branch (1237:29): [True: 16.5k, False: 6.35k]
  ------------------
 1238|  16.5k|                            if ((retval = sas7bdat_parse_subheader(subheader_type, page + shp_info.offset, shp_info.len, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1238:33): [True: 422, False: 16.1k]
  ------------------
 1239|    422|                                goto cleanup;
 1240|    422|                            }
 1241|  16.5k|                        }
 1242|  22.9k|                    }
 1243|  23.4k|                } else if (shp_info.compression == SAS_COMPRESSION_ROW) {
  ------------------
  |  |  129|  3.98k|#define SAS_COMPRESSION_ROW                0x04
  ------------------
  |  Branch (1243:28): [True: 2.06k, False: 1.92k]
  ------------------
 1244|  2.06k|                    if ((retval = sas7bdat_submit_columns_if_needed(ctx, 1)) != READSTAT_OK) {
  ------------------
  |  Branch (1244:25): [True: 35, False: 2.02k]
  ------------------
 1245|     35|                        goto cleanup;
 1246|     35|                    }
 1247|  2.02k|                    if ((retval = sas7bdat_parse_subheader_compressed(page + shp_info.offset, shp_info.len, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1247:25): [True: 266, False: 1.76k]
  ------------------
 1248|    266|                        goto cleanup;
 1249|    266|                    }
 1250|  2.02k|                } else if (shp_info.compression == SAS_COMPRESSION_DELETED_ROW) {
  ------------------
  |  |  130|  1.92k|#define SAS_COMPRESSION_DELETED_ROW        0x05
  ------------------
  |  Branch (1250:28): [True: 242, False: 1.68k]
  ------------------
 1251|    242|                    if ((retval = sas7bdat_register_deleted_row(ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1251:25): [True: 4, False: 238]
  ------------------
 1252|      4|                        goto cleanup;
 1253|      4|                    }
 1254|  1.68k|                } else if (sas7bdat_is_moved_row(shp_info.compression)) {
  ------------------
  |  Branch (1254:28): [True: 1.66k, False: 14]
  ------------------
 1255|       |                    /* void */
 1256|  1.66k|                } else {
 1257|     14|                    retval = READSTAT_ERROR_UNSUPPORTED_COMPRESSION;
 1258|     14|                    goto cleanup;
 1259|     14|                }
 1260|  27.4k|            }
 1261|       |
 1262|  48.5k|            shp += lshp;
 1263|  48.5k|        }
 1264|       |
 1265|  3.92k|        if ((page_type & SAS_PAGE_TYPE_MASK) == SAS_PAGE_TYPE_MIX) {
  ------------------
  |  |  113|  3.92k|#define SAS_PAGE_TYPE_MASK   0x0F00
  ------------------
                      if ((page_type & SAS_PAGE_TYPE_MASK) == SAS_PAGE_TYPE_MIX) {
  ------------------
  |  |  111|  3.92k|#define SAS_PAGE_TYPE_MIX    0x0200
  ------------------
  |  Branch (1265:13): [True: 1.86k, False: 2.05k]
  ------------------
 1266|       |            /* HACK - this is supposed to obey 8-byte boundaries but
 1267|       |             * some files created by Stat/Transfer don't. So verify that the
 1268|       |             * padding is { 0, 0, 0, 0 } or { ' ', ' ', ' ', ' ' } (or that
 1269|       |             * the file is not from Stat/Transfer) before skipping it */
 1270|  1.86k|            if ((shp-page)%8 == 4 && shp + 4 <= page + page_size &&
  ------------------
  |  Branch (1270:17): [True: 357, False: 1.51k]
  |  Branch (1270:38): [True: 354, False: 3]
  ------------------
 1271|    354|                    (*(uint32_t *)shp == 0x00000000 ||
  ------------------
  |  Branch (1271:22): [True: 88, False: 266]
  ------------------
 1272|    266|                     *(uint32_t *)shp == 0x20202020 ||
  ------------------
  |  Branch (1272:22): [True: 40, False: 226]
  ------------------
 1273|    314|                     ctx->vendor != READSTAT_VENDOR_STAT_TRANSFER)) {
  ------------------
  |  Branch (1273:22): [True: 186, False: 40]
  ------------------
 1274|    314|                data = shp + 4;
 1275|  1.55k|            } else {
 1276|  1.55k|                data = shp;
 1277|  1.55k|            }
 1278|  1.86k|        }
 1279|  3.92k|    }
 1280|  5.26k|    if (data) {
  ------------------
  |  Branch (1280:9): [True: 2.60k, False: 2.66k]
  ------------------
 1281|  2.60k|        if ((retval = sas7bdat_submit_columns_if_needed(ctx, 0)) != READSTAT_OK) {
  ------------------
  |  Branch (1281:13): [True: 107, False: 2.49k]
  ------------------
 1282|    107|            goto cleanup;
 1283|    107|        }
 1284|  2.49k|        if (ctx->handle.value) {
  ------------------
  |  Branch (1284:13): [True: 2.49k, False: 0]
  ------------------
 1285|  2.49k|            const unsigned char *deleted_row_bitmap = NULL;
 1286|  2.49k|            uint32_t deleted_row_bitmap_row_count = 0;
 1287|  2.49k|            if (page_type & SAS_PAGE_TYPE_DELETED_ROWS) {
  ------------------
  |  |  115|  2.49k|#define SAS_PAGE_TYPE_DELETED_ROWS  0x0080
  ------------------
  |  Branch (1287:17): [True: 727, False: 1.76k]
  ------------------
 1288|    727|                if ((retval = sas7bdat_parse_deleted_row_bitmap(page, data, page_size,
  ------------------
  |  Branch (1288:21): [True: 118, False: 609]
  ------------------
 1289|    727|                        &deleted_row_bitmap, &deleted_row_bitmap_row_count, ctx)) != READSTAT_OK) {
 1290|    118|                    goto cleanup;
 1291|    118|                }
 1292|    727|            }
 1293|  2.37k|            retval = sas7bdat_parse_rows(data, page + page_size - data,
 1294|  2.37k|                    deleted_row_bitmap, deleted_row_bitmap_row_count, ctx);
 1295|  2.37k|        }
 1296|  2.49k|    } 
 1297|  6.87k|cleanup:
 1298|       |
 1299|  6.87k|    return retval;
 1300|  5.26k|}
readstat_sas7bdat_read.c:sas7bdat_parse_moved_row:
 1073|    684|static readstat_error_t sas7bdat_parse_moved_row(uint64_t page_index, uint64_t subheader_index, sas7bdat_ctx_t *ctx) {
 1074|    684|    readstat_error_t retval = READSTAT_OK;
 1075|    684|    readstat_io_t *io = ctx->io;
 1076|       |
 1077|    684|    const uint64_t page_size = ctx->page_size;
 1078|    684|    int64_t saved_pos = -1;
 1079|       |
 1080|    684|    if (page_index >= ctx->page_count) {
  ------------------
  |  Branch (1080:9): [True: 95, False: 589]
  ------------------
 1081|     95|        retval = READSTAT_ERROR_PARSE;
 1082|     95|        goto cleanup;
 1083|     95|    }
 1084|       |
 1085|    589|    if (ctx->moved_page == NULL) {
  ------------------
  |  Branch (1085:9): [True: 424, False: 165]
  ------------------
 1086|    424|        if ((ctx->moved_page = readstat_malloc(page_size)) == NULL) {
  ------------------
  |  Branch (1086:13): [True: 0, False: 424]
  ------------------
 1087|      0|            retval = READSTAT_ERROR_MALLOC;
 1088|      0|            goto cleanup;
 1089|      0|        }
 1090|    424|        ctx->moved_page_index = -1;
 1091|    424|    }
 1092|    589|    char *page = ctx->moved_page;
 1093|       |
 1094|    589|    if (ctx->moved_page_index != (int64_t)page_index) {
  ------------------
  |  Branch (1094:9): [True: 425, False: 164]
  ------------------
 1095|    425|        saved_pos = io->seek(0, READSTAT_SEEK_CUR, io->io_ctx);
 1096|    425|        if (saved_pos == -1) {
  ------------------
  |  Branch (1096:13): [True: 0, False: 425]
  ------------------
 1097|      0|            retval = READSTAT_ERROR_SEEK;
 1098|      0|            goto cleanup;
 1099|      0|        }
 1100|    425|        if (io->seek(ctx->header_size + page_index * page_size, READSTAT_SEEK_SET, io->io_ctx) == -1) {
  ------------------
  |  Branch (1100:13): [True: 12, False: 413]
  ------------------
 1101|     12|            retval = READSTAT_ERROR_SEEK;
 1102|     12|            if (ctx->handle.error) {
  ------------------
  |  Branch (1102:17): [True: 0, False: 12]
  ------------------
 1103|      0|                snprintf(ctx->error_buf, sizeof(ctx->error_buf), "ReadStat: Failed to seek to position %" PRId64
 1104|      0|                        " (= %" PRId64 " + %" PRId64 "*%" PRId64 ")",
 1105|      0|                        ctx->header_size + page_index * page_size, ctx->header_size, page_index, page_size);
 1106|      0|                ctx->handle.error(ctx->error_buf, ctx->user_ctx);
 1107|      0|            }
 1108|     12|            goto cleanup;
 1109|     12|        }
 1110|    413|        ssize_t bytes_read = io->read(page, page_size, io->io_ctx);
 1111|    413|        if (bytes_read < 0 || (uint64_t)bytes_read < page_size) {
  ------------------
  |  Branch (1111:13): [True: 0, False: 413]
  |  Branch (1111:31): [True: 9, False: 404]
  ------------------
 1112|      9|            retval = READSTAT_ERROR_READ;
 1113|      9|            goto cleanup;
 1114|      9|        }
 1115|    404|        ctx->moved_page_index = (int64_t)page_index;
 1116|    404|    }
 1117|       |
 1118|    568|    uint16_t page_type = sas_read2(&page[ctx->page_header_size - 8], ctx->bswap);
 1119|    568|    if ((page_type & SAS_PAGE_TYPE_MASK) == SAS_PAGE_TYPE_DATA || page_type & SAS_PAGE_TYPE_COMP) {
  ------------------
  |  |  113|    568|#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.13k|#define SAS_PAGE_TYPE_DATA   0x0100
  ------------------
                  if ((page_type & SAS_PAGE_TYPE_MASK) == SAS_PAGE_TYPE_DATA || page_type & SAS_PAGE_TYPE_COMP) {
  ------------------
  |  |  117|    567|#define SAS_PAGE_TYPE_COMP          0x9000
  ------------------
  |  Branch (1119:9): [True: 1, False: 567]
  |  Branch (1119:67): [True: 2, False: 565]
  ------------------
 1120|      3|        retval = READSTAT_ERROR_READ;
 1121|      3|        goto cleanup;
 1122|      3|    }
 1123|    565|    uint16_t subheader_count = sas_read2(&page[ctx->page_header_size - 4], ctx->bswap);
 1124|    565|    if (subheader_index >= subheader_count) {
  ------------------
  |  Branch (1124:9): [True: 113, False: 452]
  ------------------
 1125|    113|        retval = READSTAT_ERROR_READ;
 1126|    113|        goto cleanup;
 1127|    113|    }
 1128|    452|    uint64_t shp_offset = ctx->page_header_size + subheader_index * ctx->subheader_pointer_size;
 1129|    452|    if (shp_offset + ctx->subheader_pointer_size > page_size) {
  ------------------
  |  Branch (1129:9): [True: 21, False: 431]
  ------------------
 1130|     21|        retval = READSTAT_ERROR_READ;
 1131|     21|        goto cleanup;
 1132|     21|    }
 1133|       |
 1134|    431|    const char *shp = &page[shp_offset];
 1135|    431|    subheader_pointer_t shp_info = { 0 };
 1136|    431|    if ((retval = sas7bdat_parse_subheader_pointer(shp, page + page_size - shp, &shp_info, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1136:9): [True: 0, False: 431]
  ------------------
 1137|      0|        goto cleanup;
 1138|      0|    }
 1139|    431|    if ((retval = sas7bdat_validate_subheader_pointer(&shp_info, page_size, subheader_count, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1139:9): [True: 209, False: 222]
  ------------------
 1140|    209|        goto cleanup;
 1141|    209|    }
 1142|    222|    if ((retval = sas7bdat_submit_columns_if_needed(ctx, 1)) != READSTAT_OK) {
  ------------------
  |  Branch (1142:9): [True: 2, False: 220]
  ------------------
 1143|      2|        goto cleanup;
 1144|      2|    }
 1145|       |
 1146|    220|    if (shp_info.compression == SAS_COMPRESSION_NONE_MOVED) {
  ------------------
  |  |  127|    220|#define SAS_COMPRESSION_NONE_MOVED         0x02
  ------------------
  |  Branch (1146:9): [True: 50, False: 170]
  ------------------
 1147|     50|        sas_subheader_type_t subheader_type = sas7bdat_parse_subheader_type(page + shp_info.offset, ctx);
 1148|     50|        if (!shp_info.is_compressed_data || subheader_type != SAS_SUBHEADER_TYPE_DATA) {
  ------------------
  |  Branch (1148:13): [True: 2, False: 48]
  |  Branch (1148:45): [True: 2, False: 46]
  ------------------
 1149|      4|            retval = READSTAT_ERROR_READ;
 1150|      4|            goto cleanup;
 1151|      4|        }
 1152|     46|        if (shp_info.len != ctx->row_length) {
  ------------------
  |  Branch (1152:13): [True: 29, False: 17]
  ------------------
 1153|     29|            retval = READSTAT_ERROR_ROW_WIDTH_MISMATCH;
 1154|     29|            goto cleanup;
 1155|     29|        }
 1156|     17|        if ((retval = sas7bdat_parse_single_row(page + shp_info.offset, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1156:13): [True: 0, False: 17]
  ------------------
 1157|      0|            goto cleanup;
 1158|      0|        }
 1159|    170|    } else if (shp_info.compression == SAS_COMPRESSION_ROW_MOVED) {
  ------------------
  |  |  131|    170|#define SAS_COMPRESSION_ROW_MOVED          0x06
  ------------------
  |  Branch (1159:16): [True: 161, False: 9]
  ------------------
 1160|    161|        if ((retval = sas7bdat_parse_subheader_compressed(page + shp_info.offset, shp_info.len, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1160:13): [True: 0, False: 161]
  ------------------
 1161|      0|            goto cleanup;
 1162|      0|        }
 1163|    161|    } else {
 1164|      9|        retval = READSTAT_ERROR_UNSUPPORTED_COMPRESSION;
 1165|      9|        goto cleanup;
 1166|      9|    }
 1167|       |
 1168|    684|cleanup:
 1169|       |
 1170|    684|    if (saved_pos != -1) {
  ------------------
  |  Branch (1170:9): [True: 425, False: 259]
  ------------------
 1171|    425|        if (io->seek(saved_pos, READSTAT_SEEK_SET, io->io_ctx) == -1 && retval == READSTAT_OK) {
  ------------------
  |  Branch (1171:13): [True: 0, False: 425]
  |  Branch (1171:73): [True: 0, False: 0]
  ------------------
 1172|      0|            retval = READSTAT_ERROR_SEEK;
 1173|      0|            if (ctx->handle.error) {
  ------------------
  |  Branch (1173:17): [True: 0, False: 0]
  ------------------
 1174|      0|                snprintf(ctx->error_buf, sizeof(ctx->error_buf),
 1175|      0|                        "ReadStat: Failed to seek to position %" PRId64, saved_pos);
 1176|      0|                ctx->handle.error(ctx->error_buf, ctx->user_ctx);
 1177|      0|            }
 1178|      0|        }
 1179|    425|    }
 1180|       |
 1181|    684|    return retval;
 1182|    220|}
readstat_sas7bdat_read.c:sas7bdat_parse_single_row:
  498|   192k|static readstat_error_t sas7bdat_parse_single_row(const char *data, sas7bdat_ctx_t *ctx) {
  499|   192k|    if (ctx->parsed_row_count == ctx->row_limit)
  ------------------
  |  Branch (499:9): [True: 326, False: 192k]
  ------------------
  500|    326|        return READSTAT_OK;
  501|   192k|    if (ctx->row_offset) {
  ------------------
  |  Branch (501:9): [True: 0, False: 192k]
  ------------------
  502|      0|        ctx->row_offset--;
  503|      0|        return READSTAT_OK;
  504|      0|    }
  505|       |
  506|   192k|    readstat_error_t retval = READSTAT_OK;
  507|   192k|    int j;
  508|   192k|    if (ctx->handle.value) {
  ------------------
  |  Branch (508:9): [True: 192k, False: 0]
  ------------------
  509|   192k|        ctx->scratch_buffer_len = 4*ctx->max_col_width+1;
  510|   192k|        ctx->scratch_buffer = readstat_realloc(ctx->scratch_buffer, ctx->scratch_buffer_len);
  511|   192k|        if (ctx->scratch_buffer == NULL) {
  ------------------
  |  Branch (511:13): [True: 2, False: 192k]
  ------------------
  512|      2|            retval = READSTAT_ERROR_MALLOC;
  513|      2|            goto cleanup;
  514|      2|        }
  515|       |
  516|  47.6M|        for (j=0; j<ctx->column_count; j++) {
  ------------------
  |  Branch (516:19): [True: 47.4M, False: 192k]
  ------------------
  517|  47.4M|            col_info_t *col_info = &ctx->col_info[j];
  518|  47.4M|            readstat_variable_t *variable = ctx->variables[j];
  519|  47.4M|            if (variable->skip)
  ------------------
  |  Branch (519:17): [True: 0, False: 47.4M]
  ------------------
  520|      0|                continue;
  521|       |
  522|  47.4M|            if (col_info->offset > ctx->row_length || col_info->offset + col_info->width > ctx->row_length) {
  ------------------
  |  Branch (522:17): [True: 88, False: 47.4M]
  |  Branch (522:55): [True: 20, False: 47.4M]
  ------------------
  523|    108|                retval = READSTAT_ERROR_PARSE;
  524|    108|                goto cleanup;
  525|    108|            }
  526|  47.4M|            retval = sas7bdat_handle_data_value(variable, col_info, &data[col_info->offset], ctx);
  527|  47.4M|            if (retval != READSTAT_OK) {
  ------------------
  |  Branch (527:17): [True: 15, False: 47.4M]
  ------------------
  528|     15|                goto cleanup;
  529|     15|            }
  530|  47.4M|        }
  531|   192k|    }
  532|   192k|    ctx->parsed_row_count++;
  533|       |
  534|   192k|cleanup:
  535|   192k|    return retval;
  536|   192k|}
readstat_sas7bdat_read.c:sas7bdat_handle_data_value:
  435|  47.4M|        col_info_t *col_info, const char *col_data, sas7bdat_ctx_t *ctx) {
  436|  47.4M|    readstat_error_t retval = READSTAT_OK;
  437|  47.4M|    int cb_retval = 0;
  438|  47.4M|    readstat_value_t value;
  439|  47.4M|    memset(&value, 0, sizeof(readstat_value_t));
  440|       |
  441|  47.4M|    value.type = col_info->type;
  442|       |
  443|  47.4M|    if (col_info->type == READSTAT_TYPE_STRING) {
  ------------------
  |  Branch (443:9): [True: 47.3M, False: 110k]
  ------------------
  444|  47.3M|        retval = readstat_convert(ctx->scratch_buffer, ctx->scratch_buffer_len,
  445|  47.3M|                col_data, col_info->width, ctx->converter);
  446|  47.3M|        if (retval != READSTAT_OK) {
  ------------------
  |  Branch (446:13): [True: 12, False: 47.3M]
  ------------------
  447|     12|            if (ctx->handle.error) {
  ------------------
  |  Branch (447:17): [True: 0, False: 12]
  ------------------
  448|      0|                snprintf(ctx->error_buf, sizeof(ctx->error_buf),
  449|      0|                        "ReadStat: Error converting string (row=%u, col=%u) to specified encoding: %.*s",
  450|      0|                        ctx->parsed_row_count+1, col_info->index+1, col_info->width, col_data);
  451|      0|                ctx->handle.error(ctx->error_buf, ctx->user_ctx);
  452|      0|            }
  453|     12|            goto cleanup;
  454|     12|        }
  455|       |
  456|  47.3M|        value.v.string_value = ctx->scratch_buffer;
  457|  47.3M|    } else if (col_info->type == READSTAT_TYPE_DOUBLE) {
  ------------------
  |  Branch (457:16): [True: 110k, False: 0]
  ------------------
  458|   110k|        uint64_t  val = 0;
  459|   110k|        double dval = NAN;
  460|   110k|        if (col_info->width < 1 || col_info->width > 8) {
  ------------------
  |  Branch (460:13): [True: 1, False: 110k]
  |  Branch (460:36): [True: 2, False: 110k]
  ------------------
  461|       |            /* A DOUBLE is 3-8 bytes on disk, but col_info can be mutated by a
  462|       |             * COLUMN_ATTRS subheader after the columns were validated. Guard
  463|       |             * here so a corrupt width can't produce an undefined shift below. */
  464|      3|            retval = READSTAT_ERROR_PARSE;
  465|      3|            goto cleanup;
  466|      3|        }
  467|   110k|        if (ctx->little_endian) {
  ------------------
  |  Branch (467:13): [True: 110k, False: 0]
  ------------------
  468|   110k|            int k;
  469|   742k|            for (k=0; k<col_info->width; k++) {
  ------------------
  |  Branch (469:23): [True: 631k, False: 110k]
  ------------------
  470|   631k|                val = (val << 8) | (unsigned char)col_data[col_info->width-1-k];
  471|   631k|            }
  472|   110k|        } else {
  473|      0|            int k;
  474|      0|            for (k=0; k<col_info->width; k++) {
  ------------------
  |  Branch (474:23): [True: 0, False: 0]
  ------------------
  475|      0|                val = (val << 8) | (unsigned char)col_data[k];
  476|      0|            }
  477|      0|        }
  478|   110k|        val <<= (8-col_info->width)*8;
  479|       |
  480|   110k|        memcpy(&dval, &val, 8);
  481|       |
  482|   110k|        if (isnan(dval)) {
  ------------------
  |  Branch (482:13): [True: 8.77k, False: 102k]
  ------------------
  483|  8.77k|            value.v.double_value = NAN;
  484|  8.77k|            sas_assign_tag(&value, ~((val >> 40) & 0xFF));
  485|   102k|        } else {
  486|   102k|            value.v.double_value = dval;
  487|   102k|        }
  488|   110k|    }
  489|  47.4M|    cb_retval = ctx->handle.value(ctx->parsed_row_count, variable, value, ctx->user_ctx);
  490|       |
  491|  47.4M|    if (cb_retval != READSTAT_HANDLER_OK)
  ------------------
  |  |   22|  47.4M|#define READSTAT_HANDLER_OK             0
  ------------------
  |  Branch (491:9): [True: 0, False: 47.4M]
  ------------------
  492|      0|        retval = READSTAT_ERROR_USER_ABORT;
  493|       |
  494|  47.4M|cleanup:
  495|  47.4M|    return retval;
  496|  47.4M|}
readstat_sas7bdat_read.c:sas7bdat_parse_subheader_compressed:
  689|  2.18k|static readstat_error_t sas7bdat_parse_subheader_compressed(const char *subheader, size_t len, sas7bdat_ctx_t *ctx) {
  690|  2.18k|    if (ctx->rdc_compression)
  ------------------
  |  Branch (690:9): [True: 441, False: 1.74k]
  ------------------
  691|    441|        return sas7bdat_parse_subheader_rdc(subheader, len, ctx);
  692|       |
  693|  1.74k|    return sas7bdat_parse_subheader_rle(subheader, len, ctx);
  694|  2.18k|}
readstat_sas7bdat_read.c:sas7bdat_parse_subheader_rdc:
  575|    441|static readstat_error_t sas7bdat_parse_subheader_rdc(const char *subheader, size_t len, sas7bdat_ctx_t *ctx) {
  576|    441|    readstat_error_t retval = READSTAT_OK;
  577|    441|    const unsigned char *input = (const unsigned char *)subheader;
  578|    441|    char *buffer = malloc(ctx->row_length);
  579|    441|    if (buffer == NULL) return READSTAT_ERROR_MALLOC;
  ------------------
  |  Branch (579:9): [True: 0, False: 441]
  ------------------
  580|    441|    char *output = buffer;
  581|  2.07k|    while (input + 2 <= (const unsigned char *)subheader + len) {
  ------------------
  |  Branch (581:12): [True: 1.67k, False: 402]
  ------------------
  582|  1.67k|        int i;
  583|  1.67k|        unsigned short prefix = (input[0] << 8) + input[1];
  584|  1.67k|        input += 2;
  585|  23.6k|        for (i=0; i<16; i++) {
  ------------------
  |  Branch (585:19): [True: 22.4k, False: 1.24k]
  ------------------
  586|  22.4k|            if ((prefix & (1 << (15 - i))) == 0) {
  ------------------
  |  Branch (586:17): [True: 16.7k, False: 5.61k]
  ------------------
  587|  16.7k|                if (input + 1 > (const unsigned char *)subheader + len) {
  ------------------
  |  Branch (587:21): [True: 389, False: 16.4k]
  ------------------
  588|    389|                    break;
  589|    389|                }
  590|  16.4k|                if (output + 1 > buffer + ctx->row_length) {
  ------------------
  |  Branch (590:21): [True: 3, False: 16.4k]
  ------------------
  591|      3|                    retval = READSTAT_ERROR_ROW_WIDTH_MISMATCH;
  592|      3|                    goto cleanup;
  593|      3|                }
  594|  16.4k|                *output++ = *input++;
  595|  16.4k|                continue;
  596|  16.4k|            }
  597|       |
  598|  5.61k|            if (input + 2 > (const unsigned char *)subheader + len) {
  ------------------
  |  Branch (598:17): [True: 2, False: 5.60k]
  ------------------
  599|      2|                retval = READSTAT_ERROR_PARSE;
  600|      2|                goto cleanup;
  601|      2|            }
  602|       |
  603|  5.60k|            unsigned char marker_byte = *input++;
  604|  5.60k|            unsigned char next_byte = *input++;
  605|  5.60k|            size_t insert_len = 0, copy_len = 0;
  606|  5.60k|            unsigned char insert_byte = 0x00;
  607|  5.60k|            size_t back_offset = 0;
  608|       |
  609|  5.60k|            if (marker_byte <= 0x0F) {
  ------------------
  |  Branch (609:17): [True: 2.32k, False: 3.28k]
  ------------------
  610|  2.32k|                insert_len = 3 + marker_byte;
  611|  2.32k|                insert_byte = next_byte;
  612|  3.28k|            } else if ((marker_byte >> 4) == 1) {
  ------------------
  |  Branch (612:24): [True: 1.27k, False: 2.01k]
  ------------------
  613|  1.27k|                if (input + 1 > (const unsigned char *)subheader + len) {
  ------------------
  |  Branch (613:21): [True: 2, False: 1.26k]
  ------------------
  614|      2|                    retval = READSTAT_ERROR_PARSE;
  615|      2|                    goto cleanup;
  616|      2|                }
  617|  1.26k|                insert_len = 19 + (marker_byte & 0x0F) + next_byte * 16;
  618|  1.26k|                insert_byte = *input++;
  619|  2.01k|            } else if ((marker_byte >> 4) == 2) {
  ------------------
  |  Branch (619:24): [True: 411, False: 1.60k]
  ------------------
  620|    411|                if (input + 1 > (const unsigned char *)subheader + len) {
  ------------------
  |  Branch (620:21): [True: 2, False: 409]
  ------------------
  621|      2|                    retval = READSTAT_ERROR_PARSE;
  622|      2|                    goto cleanup;
  623|      2|                }
  624|    409|                copy_len = 16 + (*input++);
  625|    409|                back_offset = 3 + (marker_byte & 0x0F) + next_byte * 16;
  626|  1.60k|            } else {
  627|  1.60k|                copy_len = (marker_byte >> 4);
  628|  1.60k|                back_offset = 3 + (marker_byte & 0x0F) + next_byte * 16;
  629|  1.60k|            }
  630|       |
  631|  5.60k|            if (insert_len) {
  ------------------
  |  Branch (631:17): [True: 3.59k, False: 2.01k]
  ------------------
  632|  3.59k|                if (output + insert_len > buffer + ctx->row_length) {
  ------------------
  |  Branch (632:21): [True: 2, False: 3.59k]
  ------------------
  633|      2|                    retval = READSTAT_ERROR_ROW_WIDTH_MISMATCH;
  634|      2|                    goto cleanup;
  635|      2|                }
  636|  3.59k|                memset(output, insert_byte, insert_len);
  637|  3.59k|                output += insert_len;
  638|  3.59k|            } else if (copy_len) {
  ------------------
  |  Branch (638:24): [True: 2.01k, False: 0]
  ------------------
  639|  2.01k|                if (output - buffer < back_offset || copy_len > back_offset) {
  ------------------
  |  Branch (639:21): [True: 11, False: 1.99k]
  |  Branch (639:54): [True: 15, False: 1.98k]
  ------------------
  640|     26|                    retval = READSTAT_ERROR_PARSE;
  641|     26|                    goto cleanup;
  642|     26|                }
  643|  1.98k|                if (output + copy_len > buffer + ctx->row_length) {
  ------------------
  |  Branch (643:21): [True: 2, False: 1.98k]
  ------------------
  644|      2|                    retval = READSTAT_ERROR_ROW_WIDTH_MISMATCH;
  645|      2|                    goto cleanup;
  646|      2|                }
  647|  1.98k|                memcpy(output, output - back_offset, copy_len);
  648|  1.98k|                output += copy_len;
  649|  1.98k|            }
  650|  5.60k|        }
  651|  1.67k|    }
  652|       |
  653|    402|    if (output - buffer != ctx->row_length) {
  ------------------
  |  Branch (653:9): [True: 24, False: 378]
  ------------------
  654|     24|        retval = READSTAT_ERROR_ROW_WIDTH_MISMATCH;
  655|     24|        goto cleanup;
  656|     24|    }
  657|    378|    retval = sas7bdat_parse_single_row(buffer, ctx);
  658|    441|cleanup:
  659|    441|    free(buffer);
  660|       |
  661|    441|    return retval;
  662|    378|}
readstat_sas7bdat_read.c:sas7bdat_parse_subheader_rle:
  664|  1.74k|static readstat_error_t sas7bdat_parse_subheader_rle(const char *subheader, size_t len, sas7bdat_ctx_t *ctx) {
  665|  1.74k|    if (ctx->row_limit == ctx->parsed_row_count)
  ------------------
  |  Branch (665:9): [True: 1.26k, False: 482]
  ------------------
  666|  1.26k|        return READSTAT_OK;
  667|       |
  668|    482|    readstat_error_t retval = READSTAT_OK;
  669|    482|    ssize_t bytes_decompressed = 0;
  670|       |
  671|    482|    bytes_decompressed = sas_rle_decompress(ctx->row, ctx->row_length, subheader, len);
  672|       |
  673|    482|    if (bytes_decompressed != ctx->row_length) {
  ------------------
  |  Branch (673:9): [True: 159, False: 323]
  ------------------
  674|    159|        retval = READSTAT_ERROR_ROW_WIDTH_MISMATCH;
  675|    159|        if (ctx->handle.error) {
  ------------------
  |  Branch (675:13): [True: 0, False: 159]
  ------------------
  676|      0|            snprintf(ctx->error_buf, sizeof(ctx->error_buf), 
  677|      0|                    "ReadStat: Row #%d decompressed to %ld bytes (expected %d bytes)",
  678|      0|                    ctx->parsed_row_count, (long)(bytes_decompressed), ctx->row_length);
  679|      0|            ctx->handle.error(ctx->error_buf, ctx->user_ctx);
  680|      0|        }
  681|    159|        goto cleanup;
  682|    159|    }
  683|    323|    retval = sas7bdat_parse_single_row(ctx->row, ctx);
  684|       |
  685|    482|cleanup:
  686|    482|    return retval;
  687|    323|}
readstat_sas7bdat_read.c:sas7bdat_register_deleted_row:
  426|  4.39k|static readstat_error_t sas7bdat_register_deleted_row(sas7bdat_ctx_t *ctx) {
  427|  4.39k|    if (ctx->parsed_deleted_row_count >= ctx->deleted_row_count) {
  ------------------
  |  Branch (427:9): [True: 10, False: 4.38k]
  ------------------
  428|     10|        return READSTAT_ERROR_PARSE;
  429|     10|    }
  430|  4.38k|    ctx->parsed_deleted_row_count++;
  431|  4.38k|    return READSTAT_OK;
  432|  4.39k|}
readstat_sas7bdat_read.c:sas7bdat_parse_deleted_row_bitmap:
 1054|    727|        sas7bdat_ctx_t *ctx) {
 1055|    727|    uint64_t page_unused_bytes;
 1056|    727|    if (ctx->u64) {
  ------------------
  |  Branch (1056:9): [True: 581, False: 146]
  ------------------
 1057|    581|        page_unused_bytes = sas_read8(&page[24], ctx->bswap);
 1058|    581|    } else {
 1059|    146|        page_unused_bytes = sas_read4(&page[12], ctx->bswap);
 1060|    146|    }
 1061|    727|    uint32_t row_count = ctx->page_row_count < ctx->total_row_count ? ctx->page_row_count : ctx->total_row_count;
  ------------------
  |  Branch (1061:26): [True: 336, False: 391]
  ------------------
 1062|    727|    uint64_t deleted_row_bitmap_offset = (uint64_t)row_count * ctx->row_length + page_unused_bytes;
 1063|    727|    uint32_t required_bytes = row_count / CHAR_BIT + (row_count % CHAR_BIT == 0 ? 0 : 1);
  ------------------
  |  Branch (1063:55): [True: 642, False: 85]
  ------------------
 1064|       |
 1065|    727|    if ((data - page) + deleted_row_bitmap_offset + required_bytes > page_size) {
  ------------------
  |  Branch (1065:9): [True: 118, False: 609]
  ------------------
 1066|    118|        return READSTAT_ERROR_PARSE;
 1067|    118|    }
 1068|    609|    *deleted_row_bitmap = (const unsigned char *)data + deleted_row_bitmap_offset;
 1069|    609|    *deleted_row_bitmap_row_count = row_count;
 1070|    609|    return READSTAT_OK;
 1071|    727|}
readstat_sas7bdat_read.c:sas7bdat_parse_rows:
  546|  2.37k|        const unsigned char *deleted_bitmap, uint32_t deleted_bitmap_row_count, sas7bdat_ctx_t *ctx) {
  547|  2.37k|    readstat_error_t retval = READSTAT_OK;
  548|  2.37k|    uint32_t i;
  549|  2.37k|    size_t row_offset=0;
  550|   197k|    for (i=0; i<ctx->page_row_count && ctx->parsed_row_count < ctx->row_limit; i++) {
  ------------------
  |  Branch (550:15): [True: 196k, False: 1.61k]
  |  Branch (550:40): [True: 195k, False: 582]
  ------------------
  551|   195k|        if (row_offset + ctx->row_length > len) {
  ------------------
  |  Branch (551:13): [True: 94, False: 195k]
  ------------------
  552|     94|            retval = READSTAT_ERROR_ROW_WIDTH_MISMATCH;
  553|     94|            goto cleanup;
  554|     94|        }
  555|   195k|        if (deleted_bitmap != NULL && i >= deleted_bitmap_row_count) {
  ------------------
  |  Branch (555:13): [True: 14.0k, False: 181k]
  |  Branch (555:39): [True: 8, False: 14.0k]
  ------------------
  556|       |            /* The page claims more rows than the deleted-row bitmap covers */
  557|      8|            retval = READSTAT_ERROR_PARSE;
  558|      8|            goto cleanup;
  559|      8|        }
  560|   195k|        if (deleted_bitmap != NULL && sas7bdat_read_bitmap(deleted_bitmap, i)) {
  ------------------
  |  Branch (560:13): [True: 14.0k, False: 181k]
  |  Branch (560:39): [True: 4.14k, False: 9.91k]
  ------------------
  561|  4.14k|            if ((retval = sas7bdat_register_deleted_row(ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (561:17): [True: 6, False: 4.14k]
  ------------------
  562|      6|                goto cleanup;
  563|      6|            }
  564|   191k|        } else if ((retval = sas7bdat_parse_single_row(&data[row_offset], ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (564:20): [True: 74, False: 191k]
  ------------------
  565|     74|            goto cleanup;
  566|     74|        }
  567|       |
  568|   195k|        row_offset += ctx->row_length;
  569|   195k|    }
  570|       |
  571|  2.37k|cleanup:
  572|  2.37k|    return retval;
  573|  2.37k|}
readstat_sas7bdat_read.c:sas7bdat_read_bitmap:
  538|  14.0k|static unsigned char sas7bdat_read_bitmap(const unsigned char *bitmap, int index) {
  539|  14.0k|    unsigned char current_byte = bitmap[index / CHAR_BIT];
  540|  14.0k|    unsigned char mask = 1 << (CHAR_BIT - 1 - index % CHAR_BIT);
  541|       |
  542|  14.0k|    return current_byte & mask;
  543|  14.0k|}
readstat_sas7bdat_read.c:sas7bdat_submit_columns_if_needed:
  877|  5.63k|static readstat_error_t sas7bdat_submit_columns_if_needed(sas7bdat_ctx_t *ctx, int compressed) {
  878|  5.63k|    readstat_error_t retval = READSTAT_OK;
  879|  5.63k|    if (!ctx->did_submit_columns) {
  ------------------
  |  Branch (879:9): [True: 1.61k, False: 4.02k]
  ------------------
  880|  1.61k|        if ((retval = sas7bdat_submit_columns(ctx, compressed)) != READSTAT_OK) {
  ------------------
  |  Branch (880:13): [True: 232, False: 1.37k]
  ------------------
  881|    232|            goto cleanup;
  882|    232|        }
  883|  1.37k|        ctx->did_submit_columns = 1;
  884|  1.37k|    }
  885|  5.63k|cleanup:
  886|  5.63k|    return retval;
  887|  5.63k|}
readstat_sas7bdat_read.c:sas7bdat_submit_columns:
  816|  1.61k|static readstat_error_t sas7bdat_submit_columns(sas7bdat_ctx_t *ctx, int compressed) {
  817|  1.61k|    readstat_error_t retval = READSTAT_OK;
  818|  1.61k|    if (ctx->handle.metadata) {
  ------------------
  |  Branch (818:9): [True: 1.61k, False: 0]
  ------------------
  819|  1.61k|        readstat_metadata_t metadata = {
  820|  1.61k|            .row_count = ctx->row_limit,
  821|  1.61k|            .var_count = ctx->column_count,
  822|  1.61k|            .table_name = ctx->table_name,
  823|  1.61k|            .file_label = ctx->file_label,
  824|  1.61k|            .file_encoding = ctx->input_encoding, /* orig encoding? */
  825|  1.61k|            .creation_time = ctx->ctime,
  826|  1.61k|            .modified_time = ctx->mtime,
  827|  1.61k|            .file_format_version = ctx->version,
  828|  1.61k|            .compression = READSTAT_COMPRESS_NONE,
  829|  1.61k|            .endianness = ctx->little_endian ? READSTAT_ENDIAN_LITTLE : READSTAT_ENDIAN_BIG,
  ------------------
  |  Branch (829:27): [True: 277, False: 1.33k]
  ------------------
  830|  1.61k|            .is64bit = ctx->u64
  831|  1.61k|        };
  832|  1.61k|        if (compressed) {
  ------------------
  |  Branch (832:13): [True: 640, False: 971]
  ------------------
  833|    640|            if (ctx->rdc_compression) {
  ------------------
  |  Branch (833:17): [True: 62, False: 578]
  ------------------
  834|     62|                metadata.compression = READSTAT_COMPRESS_BINARY;
  835|    578|            } else {
  836|    578|                metadata.compression = READSTAT_COMPRESS_ROWS;
  837|    578|            }
  838|    640|        }
  839|  1.61k|        if (ctx->handle.metadata(&metadata, ctx->user_ctx) != READSTAT_HANDLER_OK) {
  ------------------
  |  |   22|  1.61k|#define READSTAT_HANDLER_OK             0
  ------------------
  |  Branch (839:13): [True: 0, False: 1.61k]
  ------------------
  840|      0|            retval = READSTAT_ERROR_USER_ABORT;
  841|      0|            goto cleanup;
  842|      0|        }
  843|  1.61k|    }
  844|  1.61k|    if (ctx->column_count == 0)
  ------------------
  |  Branch (844:9): [True: 1.13k, False: 475]
  ------------------
  845|  1.13k|        goto cleanup;
  846|       |
  847|    475|    if ((ctx->variables = readstat_calloc(ctx->column_count, sizeof(readstat_variable_t *))) == NULL) {
  ------------------
  |  Branch (847:9): [True: 0, False: 475]
  ------------------
  848|      0|        retval = READSTAT_ERROR_MALLOC;
  849|      0|        goto cleanup;
  850|      0|    }
  851|    475|    int i;
  852|    475|    int index_after_skipping = 0;
  853|  2.30M|    for (i=0; i<ctx->column_count; i++) {
  ------------------
  |  Branch (853:15): [True: 2.30M, False: 243]
  ------------------
  854|  2.30M|        ctx->variables[i] = sas7bdat_init_variable(ctx, i, index_after_skipping, &retval);
  855|  2.30M|        if (ctx->variables[i] == NULL)
  ------------------
  |  Branch (855:13): [True: 232, False: 2.30M]
  ------------------
  856|    232|            break;
  857|       |
  858|  2.30M|        int cb_retval = READSTAT_HANDLER_OK;
  ------------------
  |  |   22|  2.30M|#define READSTAT_HANDLER_OK             0
  ------------------
  859|  2.30M|        if (ctx->handle.variable) {
  ------------------
  |  Branch (859:13): [True: 2.30M, False: 0]
  ------------------
  860|  2.30M|            cb_retval = ctx->handle.variable(i, ctx->variables[i], ctx->variables[i]->format, ctx->user_ctx);
  861|  2.30M|        }
  862|  2.30M|        if (cb_retval == READSTAT_HANDLER_ABORT) {
  ------------------
  |  |   23|  2.30M|#define READSTAT_HANDLER_ABORT          1
  ------------------
  |  Branch (862:13): [True: 0, False: 2.30M]
  ------------------
  863|      0|            retval = READSTAT_ERROR_USER_ABORT;
  864|      0|            goto cleanup;
  865|      0|        }
  866|       |
  867|  2.30M|        if (cb_retval == READSTAT_HANDLER_SKIP_VARIABLE) {
  ------------------
  |  |   24|  2.30M|#define READSTAT_HANDLER_SKIP_VARIABLE  2
  ------------------
  |  Branch (867:13): [True: 0, False: 2.30M]
  ------------------
  868|      0|            ctx->variables[i]->skip = 1;
  869|  2.30M|        } else {
  870|  2.30M|            index_after_skipping++;
  871|  2.30M|        }
  872|  2.30M|    }
  873|  1.61k|cleanup:
  874|  1.61k|    return retval;
  875|    475|}
readstat_sas7bdat_read.c:sas7bdat_init_variable:
  763|  2.30M|        int index_after_skipping, readstat_error_t *out_retval) {
  764|  2.30M|    readstat_error_t retval = READSTAT_OK;
  765|  2.30M|    readstat_variable_t *variable = readstat_calloc(1, sizeof(readstat_variable_t));
  766|       |
  767|  2.30M|    variable->index = i;
  768|  2.30M|    variable->index_after_skipping = index_after_skipping;
  769|  2.30M|    variable->type = ctx->col_info[i].type;
  770|  2.30M|    variable->storage_width = ctx->col_info[i].width;
  771|       |
  772|  2.30M|    if ((retval = sas7bdat_validate_column(&ctx->col_info[i])) != READSTAT_OK) {
  ------------------
  |  Branch (772:9): [True: 61, False: 2.30M]
  ------------------
  773|     61|        goto cleanup;
  774|     61|    }
  775|  2.30M|    if ((retval = sas7bdat_copy_text_ref(variable->name, sizeof(variable->name), 
  ------------------
  |  Branch (775:9): [True: 49, False: 2.30M]
  ------------------
  776|  2.30M|                    ctx->col_info[i].name_ref, ctx)) != READSTAT_OK) {
  777|     49|        goto cleanup;
  778|     49|    }
  779|  2.30M|    if ((retval = sas7bdat_construct_format(variable->format, sizeof(variable->format),
  ------------------
  |  Branch (779:9): [True: 43, False: 2.30M]
  ------------------
  780|  2.30M|                    ctx->col_info[i].format_ref, ctx->col_info[i].format_width,
  781|  2.30M|                    ctx->col_info[i].format_digits, ctx)) != READSTAT_OK) {
  782|     43|        goto cleanup;
  783|     43|    }
  784|  2.30M|    if ((retval = sas7bdat_construct_format(variable->informat, sizeof(variable->informat),
  ------------------
  |  Branch (784:9): [True: 27, False: 2.30M]
  ------------------
  785|  2.30M|                    ctx->col_info[i].informat_ref, ctx->col_info[i].informat_width,
  786|  2.30M|                    ctx->col_info[i].informat_digits, ctx)) != READSTAT_OK) {
  787|     27|        goto cleanup;
  788|     27|    }
  789|  2.30M|    if ((retval = sas7bdat_copy_text_ref(variable->label, sizeof(variable->label), 
  ------------------
  |  Branch (789:9): [True: 52, False: 2.30M]
  ------------------
  790|  2.30M|                    ctx->col_info[i].label_ref, ctx)) != READSTAT_OK) {
  791|     52|        goto cleanup;
  792|     52|    }
  793|       |
  794|  2.30M|cleanup:
  795|  2.30M|    if (retval != READSTAT_OK) {
  ------------------
  |  Branch (795:9): [True: 232, False: 2.30M]
  ------------------
  796|    232|        if (out_retval)
  ------------------
  |  Branch (796:13): [True: 232, False: 0]
  ------------------
  797|    232|            *out_retval = retval;
  798|       |
  799|    232|        if (retval == READSTAT_ERROR_CONVERT_BAD_STRING) {
  ------------------
  |  Branch (799:13): [True: 10, False: 222]
  ------------------
  800|     10|            if (ctx->handle.error) {
  ------------------
  |  Branch (800:17): [True: 0, False: 10]
  ------------------
  801|      0|                snprintf(ctx->error_buf, sizeof(ctx->error_buf),
  802|      0|                        "ReadStat: Error converting variable #%d info to specified encoding: %s %s (%s)",
  803|      0|                        i, variable->name, variable->format, variable->label);
  804|      0|                ctx->handle.error(ctx->error_buf, ctx->user_ctx);
  805|      0|            }
  806|     10|        }
  807|       |
  808|    232|        free(variable);
  809|       |
  810|    232|        return NULL;
  811|    232|    }
  812|       |
  813|  2.30M|    return variable;
  814|  2.30M|}
readstat_sas7bdat_read.c:sas7bdat_validate_column:
  731|  2.30M|static readstat_error_t sas7bdat_validate_column(col_info_t *col_info) {
  732|  2.30M|    if (col_info->type == READSTAT_TYPE_DOUBLE) {
  ------------------
  |  Branch (732:9): [True: 1.15k, False: 2.30M]
  ------------------
  733|  1.15k|        if (col_info->width > 8 || col_info->width < 3) {
  ------------------
  |  Branch (733:13): [True: 31, False: 1.12k]
  |  Branch (733:36): [True: 1, False: 1.11k]
  ------------------
  734|     32|            return READSTAT_ERROR_PARSE;
  735|     32|        }
  736|  1.15k|    }
  737|  2.30M|    if (col_info->type == READSTAT_TYPE_STRING) {
  ------------------
  |  Branch (737:9): [True: 2.30M, False: 1.11k]
  ------------------
  738|  2.30M|        if (col_info->width > INT16_MAX) {
  ------------------
  |  Branch (738:13): [True: 29, False: 2.30M]
  ------------------
  739|     29|            return READSTAT_ERROR_PARSE;
  740|     29|        }
  741|  2.30M|    }
  742|  2.30M|    return READSTAT_OK;
  743|  2.30M|}
readstat_sas7bdat_read.c:sas7bdat_construct_format:
  746|  4.61M|        sas_text_ref_t text_ref, int width, int digits, sas7bdat_ctx_t *ctx) {
  747|  4.61M|    readstat_error_t retval = sas7bdat_copy_text_ref(dst, dst_len, text_ref, ctx);
  748|  4.61M|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (748:9): [True: 70, False: 4.61M]
  ------------------
  749|     70|        return retval;
  750|       |
  751|  4.61M|    size_t len = strlen(dst);
  752|  4.61M|    if (width && len < dst_len - 1) {
  ------------------
  |  Branch (752:9): [True: 1.10k, False: 4.61M]
  |  Branch (752:18): [True: 1.09k, False: 4]
  ------------------
  753|  1.09k|        snprintf(dst + len, dst_len - len, "%d", width);
  754|  1.09k|        len = strlen(dst);
  755|  1.09k|    }
  756|  4.61M|    if (len && digits && len < dst_len - 1) {
  ------------------
  |  Branch (756:9): [True: 1.15k, False: 4.61M]
  |  Branch (756:16): [True: 641, False: 514]
  |  Branch (756:26): [True: 634, False: 7]
  ------------------
  757|    634|        snprintf(dst + len, dst_len - len, ".%d", digits);
  758|    634|    }
  759|  4.61M|    return READSTAT_OK;
  760|  4.61M|}
readstat_sas7bdat_read.c:sas7bdat_update_progress:
  141|  7.16k|static readstat_error_t sas7bdat_update_progress(sas7bdat_ctx_t *ctx) {
  142|  7.16k|    readstat_io_t *io = ctx->io;
  143|  7.16k|    return io->update(ctx->file_size, ctx->handle.progress, ctx->user_ctx, io->io_ctx);
  144|  7.16k|}
readstat_sas7bdat_read.c:sas7bdat_ctx_free:
  104|  4.47k|static void sas7bdat_ctx_free(sas7bdat_ctx_t *ctx) {
  105|  4.47k|    int i;
  106|  4.47k|    if (ctx->text_blobs) {
  ------------------
  |  Branch (106:9): [True: 951, False: 3.52k]
  ------------------
  107|  9.40k|        for (i=0; i<ctx->text_blob_count; i++) {
  ------------------
  |  Branch (107:19): [True: 8.45k, False: 951]
  ------------------
  108|  8.45k|            free(ctx->text_blobs[i]);
  109|  8.45k|        }
  110|    951|        free(ctx->text_blobs);
  111|    951|        free(ctx->text_blob_lengths);
  112|    951|    }
  113|  4.47k|    if (ctx->variables) {
  ------------------
  |  Branch (113:9): [True: 475, False: 4.00k]
  ------------------
  114|  11.4M|        for (i=0; i<ctx->column_count; i++) {
  ------------------
  |  Branch (114:19): [True: 11.4M, False: 475]
  ------------------
  115|  11.4M|            if (ctx->variables[i])
  ------------------
  |  Branch (115:17): [True: 2.30M, False: 9.11M]
  ------------------
  116|  2.30M|                free(ctx->variables[i]);
  117|  11.4M|        }
  118|    475|        free(ctx->variables);
  119|    475|    }
  120|  4.47k|    if (ctx->col_info)
  ------------------
  |  Branch (120:9): [True: 691, False: 3.78k]
  ------------------
  121|    691|        free(ctx->col_info);
  122|       |
  123|  4.47k|    if (ctx->scratch_buffer)
  ------------------
  |  Branch (123:9): [True: 346, False: 4.13k]
  ------------------
  124|    346|        free(ctx->scratch_buffer);
  125|       |
  126|  4.47k|    if (ctx->page)
  ------------------
  |  Branch (126:9): [True: 3.92k, False: 553]
  ------------------
  127|  3.92k|        free(ctx->page);
  128|       |
  129|  4.47k|    if (ctx->moved_page)
  ------------------
  |  Branch (129:9): [True: 424, False: 4.05k]
  ------------------
  130|    424|        free(ctx->moved_page);
  131|       |
  132|  4.47k|    if (ctx->row)
  ------------------
  |  Branch (132:9): [True: 907, False: 3.57k]
  ------------------
  133|    907|        free(ctx->row);
  134|       |
  135|  4.47k|    if (ctx->converter)
  ------------------
  |  Branch (135:9): [True: 2.75k, False: 1.72k]
  ------------------
  136|  2.75k|        iconv_close(ctx->converter);
  137|       |
  138|  4.47k|    free(ctx);
  139|  4.47k|}

sas_rle_decompress:
   47|    482|        const void *input_buf, size_t input_len) {
   48|    482|    unsigned char *buffer = (unsigned char *)output_buf;
   49|    482|    unsigned char *output = buffer;
   50|    482|    size_t output_written = 0;
   51|       |
   52|    482|    const unsigned char *input = (const unsigned char *)input_buf;
   53|       |
   54|  68.6k|    while (input < (const unsigned char *)input_buf + input_len) {
  ------------------
  |  Branch (54:12): [True: 68.2k, False: 348]
  ------------------
   55|  68.2k|        unsigned char control = *input++;
   56|  68.2k|        unsigned char command = (control & 0xF0) >> 4;
   57|  68.2k|        unsigned char length = (control & 0x0F);
   58|  68.2k|        int copy_len = 0;
   59|  68.2k|        int insert_len = 0;
   60|  68.2k|        unsigned char insert_byte = '\0';
   61|  68.2k|        if (input + command_lengths[command] > (const unsigned char *)input_buf + input_len) {
  ------------------
  |  Branch (61:13): [True: 6, False: 68.2k]
  ------------------
   62|      6|            return -1;
   63|      6|        }
   64|  68.2k|        switch (command) {
   65|  5.78k|            case SAS_RLE_COMMAND_COPY64:
  ------------------
  |  |   13|  5.78k|#define SAS_RLE_COMMAND_COPY64          0
  ------------------
  |  Branch (65:13): [True: 5.78k, False: 62.5k]
  ------------------
   66|  5.78k|                copy_len = (*input++) + 64 + length * 256;
   67|  5.78k|                break;
   68|    275|            case SAS_RLE_COMMAND_COPY64_PLUS_4096:
  ------------------
  |  |   14|    275|#define SAS_RLE_COMMAND_COPY64_PLUS_4096 1
  ------------------
  |  Branch (68:13): [True: 275, False: 68.0k]
  ------------------
   69|    275|                copy_len = (*input++) + 64 + length * 256 + 4096;
   70|    275|                break;
   71|    572|            case SAS_RLE_COMMAND_COPY96: copy_len = length + 96; break;
  ------------------
  |  |   15|    572|#define SAS_RLE_COMMAND_COPY96          2
  ------------------
  |  Branch (71:13): [True: 572, False: 67.7k]
  ------------------
   72|    937|            case SAS_RLE_COMMAND_INSERT_BYTE18:
  ------------------
  |  |   16|    937|#define SAS_RLE_COMMAND_INSERT_BYTE18   4
  ------------------
  |  Branch (72:13): [True: 937, False: 67.3k]
  ------------------
   73|    937|                insert_len = (*input++) + 18 + length * 256;
   74|    937|                insert_byte = *input++;
   75|    937|                break;
   76|    774|            case SAS_RLE_COMMAND_INSERT_AT17:
  ------------------
  |  |   17|    774|#define SAS_RLE_COMMAND_INSERT_AT17     5
  ------------------
  |  Branch (76:13): [True: 774, False: 67.5k]
  ------------------
   77|    774|                insert_len = (*input++) + 17 + length * 256;
   78|    774|                insert_byte = '@';
   79|    774|                break;
   80|  1.94k|            case SAS_RLE_COMMAND_INSERT_BLANK17:
  ------------------
  |  |   18|  1.94k|#define SAS_RLE_COMMAND_INSERT_BLANK17  6
  ------------------
  |  Branch (80:13): [True: 1.94k, False: 66.3k]
  ------------------
   81|  1.94k|                insert_len = (*input++) + 17 + length * 256;
   82|  1.94k|                insert_byte = ' ';
   83|  1.94k|                break;
   84|  19.2k|            case SAS_RLE_COMMAND_INSERT_ZERO17:
  ------------------
  |  |   19|  19.2k|#define SAS_RLE_COMMAND_INSERT_ZERO17   7
  ------------------
  |  Branch (84:13): [True: 19.2k, False: 49.0k]
  ------------------
   85|  19.2k|                insert_len = (*input++) + 17 + length * 256;
   86|  19.2k|                insert_byte = '\0';
   87|  19.2k|                break;
   88|  1.36k|            case SAS_RLE_COMMAND_COPY1:  copy_len = length + 1; break;
  ------------------
  |  |   20|  1.36k|#define SAS_RLE_COMMAND_COPY1           8
  ------------------
  |  Branch (88:13): [True: 1.36k, False: 66.9k]
  ------------------
   89|  1.32k|            case SAS_RLE_COMMAND_COPY17: copy_len = length + 17; break;
  ------------------
  |  |   21|  1.32k|#define SAS_RLE_COMMAND_COPY17          9
  ------------------
  |  Branch (89:13): [True: 1.32k, False: 66.9k]
  ------------------
   90|    577|            case SAS_RLE_COMMAND_COPY33: copy_len = length + 33; break;
  ------------------
  |  |   22|    577|#define SAS_RLE_COMMAND_COPY33         10
  ------------------
  |  Branch (90:13): [True: 577, False: 67.7k]
  ------------------
   91|    460|            case SAS_RLE_COMMAND_COPY49: copy_len = length + 49; break;
  ------------------
  |  |   23|    460|#define SAS_RLE_COMMAND_COPY49         11
  ------------------
  |  Branch (91:13): [True: 460, False: 67.8k]
  ------------------
   92|  1.15k|            case SAS_RLE_COMMAND_INSERT_BYTE3:
  ------------------
  |  |   24|  1.15k|#define SAS_RLE_COMMAND_INSERT_BYTE3   12
  ------------------
  |  Branch (92:13): [True: 1.15k, False: 67.1k]
  ------------------
   93|  1.15k|                insert_byte = *input++;
   94|  1.15k|                insert_len = length + 3;
   95|  1.15k|                break;
   96|  1.82k|            case SAS_RLE_COMMAND_INSERT_AT2:
  ------------------
  |  |   25|  1.82k|#define SAS_RLE_COMMAND_INSERT_AT2     13
  ------------------
  |  Branch (96:13): [True: 1.82k, False: 66.4k]
  ------------------
   97|  1.82k|                insert_byte = '@';
   98|  1.82k|                insert_len = length + 2;
   99|  1.82k|                break;
  100|  22.6k|            case SAS_RLE_COMMAND_INSERT_BLANK2:
  ------------------
  |  |   26|  22.6k|#define SAS_RLE_COMMAND_INSERT_BLANK2  14
  ------------------
  |  Branch (100:13): [True: 22.6k, False: 45.5k]
  ------------------
  101|  22.6k|                insert_byte = ' ';
  102|  22.6k|                insert_len = length + 2;
  103|  22.6k|                break;
  104|  5.97k|            case SAS_RLE_COMMAND_INSERT_ZERO2:
  ------------------
  |  |   27|  5.97k|#define SAS_RLE_COMMAND_INSERT_ZERO2   15
  ------------------
  |  Branch (104:13): [True: 5.97k, False: 62.3k]
  ------------------
  105|  5.97k|                insert_byte = '\0';
  106|  5.97k|                insert_len = length + 2;
  107|  5.97k|                break;
  108|  3.39k|            default:
  ------------------
  |  Branch (108:13): [True: 3.39k, False: 64.8k]
  ------------------
  109|       |                /* error out here? */
  110|  3.39k|                break;
  111|  68.2k|        }
  112|  68.2k|        if (copy_len) {
  ------------------
  |  Branch (112:13): [True: 10.3k, False: 57.9k]
  ------------------
  113|  10.3k|            if (output_written + copy_len > output_len) {
  ------------------
  |  Branch (113:17): [True: 16, False: 10.3k]
  ------------------
  114|     16|                return -1;
  115|     16|            }
  116|  10.3k|            if (input + copy_len > (const unsigned char *)input_buf + input_len) {
  ------------------
  |  Branch (116:17): [True: 97, False: 10.2k]
  ------------------
  117|     97|                return -1;
  118|     97|            }
  119|  10.2k|            if (output) {
  ------------------
  |  Branch (119:17): [True: 10.2k, False: 0]
  ------------------
  120|  10.2k|                memcpy(&output[output_written], input, copy_len);
  121|  10.2k|            }
  122|  10.2k|            input += copy_len;
  123|  10.2k|            output_written += copy_len;
  124|  10.2k|        }
  125|  68.1k|        if (insert_len) {
  ------------------
  |  Branch (125:13): [True: 54.5k, False: 13.6k]
  ------------------
  126|  54.5k|            if (output_written + insert_len > output_len) {
  ------------------
  |  Branch (126:17): [True: 15, False: 54.5k]
  ------------------
  127|     15|                return -1;
  128|     15|            }
  129|  54.5k|            if (output) {
  ------------------
  |  Branch (129:17): [True: 54.5k, False: 0]
  ------------------
  130|  54.5k|                memset(&output[output_written], insert_byte, insert_len);
  131|  54.5k|            }
  132|  54.5k|            output_written += insert_len;
  133|  54.5k|        }
  134|  68.1k|    }
  135|       |
  136|    348|    return output_written;
  137|    482|}

rt_open_handler:
    8|  4.47k|int rt_open_handler(const char *path, void *io_ctx) {
    9|  4.47k|    return 0;
   10|  4.47k|}
rt_close_handler:
   12|  4.47k|int rt_close_handler(void *io_ctx) {
   13|  4.47k|    return 0;
   14|  4.47k|}
rt_seek_handler:
   17|  39.4k|        readstat_io_flags_t whence, void *io_ctx) {
   18|  39.4k|    rt_buffer_ctx_t *buffer_ctx = (rt_buffer_ctx_t *)io_ctx;
   19|  39.4k|    readstat_off_t newpos = -1;
   20|  39.4k|    if (whence == READSTAT_SEEK_SET) {
  ------------------
  |  Branch (20:9): [True: 26.1k, False: 13.3k]
  ------------------
   21|  26.1k|        newpos = offset;
   22|  26.1k|    } else if (whence == READSTAT_SEEK_CUR) {
  ------------------
  |  Branch (22:16): [True: 8.86k, False: 4.47k]
  ------------------
   23|  8.86k|        newpos = buffer_ctx->pos + offset;
   24|  8.86k|    } else if (whence == READSTAT_SEEK_END) {
  ------------------
  |  Branch (24:16): [True: 4.47k, False: 0]
  ------------------
   25|  4.47k|        newpos = buffer_ctx->buffer->used + offset;
   26|  4.47k|    }
   27|       |
   28|  39.4k|    if (newpos < 0)
  ------------------
  |  Branch (28:9): [True: 159, False: 39.2k]
  ------------------
   29|    159|        return -1;
   30|       |
   31|  39.2k|    if (newpos > buffer_ctx->buffer->used)
  ------------------
  |  Branch (31:9): [True: 234, False: 39.0k]
  ------------------
   32|    234|        return -1;
   33|       |
   34|  39.0k|    buffer_ctx->pos = newpos;
   35|  39.0k|    return newpos;
   36|  39.2k|}
rt_read_handler:
   38|  69.3k|ssize_t rt_read_handler(void *buf, size_t nbytes, void *io_ctx) {
   39|  69.3k|    rt_buffer_ctx_t *buffer_ctx = (rt_buffer_ctx_t *)io_ctx;
   40|  69.3k|    ssize_t bytes_copied = 0;
   41|  69.3k|    ssize_t bytes_left = buffer_ctx->buffer->used - buffer_ctx->pos;
   42|  69.3k|    if (nbytes <= bytes_left) {
  ------------------
  |  Branch (42:9): [True: 68.8k, False: 499]
  ------------------
   43|  68.8k|        memcpy(buf, buffer_ctx->buffer->bytes + buffer_ctx->pos, nbytes);
   44|  68.8k|        bytes_copied = nbytes;
   45|  68.8k|    } else if (bytes_left > 0) {
  ------------------
  |  Branch (45:16): [True: 272, False: 227]
  ------------------
   46|    272|        memcpy(buf, buffer_ctx->buffer->bytes + buffer_ctx->pos, bytes_left);
   47|    272|        bytes_copied = bytes_left;
   48|    272|    }
   49|  69.3k|    buffer_ctx->pos += bytes_copied;
   50|  69.3k|    return bytes_copied;
   51|  69.3k|}
rt_update_handler:
   54|  7.16k|        void *user_ctx, void *io_ctx) {
   55|  7.16k|    if (!progress_handler)
  ------------------
  |  Branch (55:9): [True: 7.16k, False: 0]
  ------------------
   56|  7.16k|        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|}

