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

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

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

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

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

readstat_malloc:
   10|  5.77k|void *readstat_malloc(size_t len) {
   11|  5.77k|    if (len > MAX_MALLOC_SIZE || len == 0) {
  ------------------
  |  |    3|  11.5k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
  |  Branch (11:9): [True: 0, False: 5.77k]
  |  Branch (11:34): [True: 0, False: 5.77k]
  ------------------
   12|      0|        return NULL;
   13|      0|    }
   14|  5.77k|    return malloc(len);
   15|  5.77k|}
readstat_calloc:
   17|  1.90M|void *readstat_calloc(size_t count, size_t size) {
   18|  1.90M|    if (count > MAX_MALLOC_SIZE || size > MAX_MALLOC_SIZE || count * size > MAX_MALLOC_SIZE) {
  ------------------
  |  |    3|  3.80M|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
                  if (count > MAX_MALLOC_SIZE || size > MAX_MALLOC_SIZE || count * size > MAX_MALLOC_SIZE) {
  ------------------
  |  |    3|  3.80M|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
                  if (count > MAX_MALLOC_SIZE || size > MAX_MALLOC_SIZE || count * size > MAX_MALLOC_SIZE) {
  ------------------
  |  |    3|  1.90M|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
  |  Branch (18:9): [True: 0, False: 1.90M]
  |  Branch (18:36): [True: 0, False: 1.90M]
  |  Branch (18:62): [True: 0, False: 1.90M]
  ------------------
   19|      0|        return NULL;
   20|      0|    }
   21|  1.90M|    if (count == 0 || size == 0) {
  ------------------
  |  Branch (21:9): [True: 0, False: 1.90M]
  |  Branch (21:23): [True: 0, False: 1.90M]
  ------------------
   22|      0|        return NULL;
   23|      0|    }
   24|  1.90M|    return calloc(count, size);
   25|  1.90M|}
readstat_realloc:
   27|  53.5k|void *readstat_realloc(void *ptr, size_t len) {
   28|  53.5k|    if (len > MAX_MALLOC_SIZE || len == 0) {
  ------------------
  |  |    3|   107k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
  |  Branch (28:9): [True: 109, False: 53.4k]
  |  Branch (28:34): [True: 1, False: 53.4k]
  ------------------
   29|    110|        if (ptr)
  ------------------
  |  Branch (29:13): [True: 64, False: 46]
  ------------------
   30|     64|            free(ptr);
   31|    110|        return NULL;
   32|    110|    }
   33|  53.4k|    return realloc(ptr, len);
   34|  53.5k|}

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

sas_read8:
  140|  42.4k|uint64_t sas_read8(const char *data, int bswap) {
  141|  42.4k|    uint64_t tmp;
  142|  42.4k|    memcpy(&tmp, data, 8);
  143|  42.4k|    return bswap ? byteswap8(tmp) : tmp;
  ------------------
  |  Branch (143:12): [True: 37.5k, False: 4.94k]
  ------------------
  144|  42.4k|}
sas_read4:
  146|   244k|uint32_t sas_read4(const char *data, int bswap) {
  147|   244k|    uint32_t tmp;
  148|   244k|    memcpy(&tmp, data, 4);
  149|   244k|    return bswap ? byteswap4(tmp) : tmp;
  ------------------
  |  Branch (149:12): [True: 176k, False: 68.3k]
  ------------------
  150|   244k|}
sas_read2:
  152|   175k|uint16_t sas_read2(const char *data, int bswap) {
  153|   175k|    uint16_t tmp;
  154|   175k|    memcpy(&tmp, data, 2);
  155|   175k|    return bswap ? byteswap2(tmp) : tmp;
  ------------------
  |  Branch (155:12): [True: 78.7k, False: 96.2k]
  ------------------
  156|   175k|}
sas_subheader_remainder:
  158|  5.70k|size_t sas_subheader_remainder(size_t len, size_t signature_len) {
  159|  5.70k|    return len - (4+2*signature_len);
  160|  5.70k|}
sas_read_header:
  163|  3.67k|        readstat_error_handler error_handler, void *user_ctx) {
  164|  3.67k|    sas_header_start_t  header_start;
  165|  3.67k|    sas_header_end_t    header_end;
  166|  3.67k|    int retval = READSTAT_OK;
  167|  3.67k|    char error_buf[1024];
  168|  3.67k|    time_t epoch = sas_epoch();
  169|       |
  170|  3.67k|    if (io->read(&header_start, sizeof(sas_header_start_t), io->io_ctx) < sizeof(sas_header_start_t)) {
  ------------------
  |  Branch (170:9): [True: 20, False: 3.65k]
  ------------------
  171|     20|        retval = READSTAT_ERROR_READ;
  172|     20|        goto cleanup;
  173|     20|    }
  174|  3.65k|    if (memcmp(header_start.magic, sas7bdat_magic_number, sizeof(sas7bdat_magic_number)) != 0 &&
  ------------------
  |  Branch (174:9): [True: 1.55k, False: 2.10k]
  ------------------
  175|  1.55k|            memcmp(header_start.magic, sas7bcat_magic_number, sizeof(sas7bcat_magic_number)) != 0) {
  ------------------
  |  Branch (175:13): [True: 130, False: 1.42k]
  ------------------
  176|    130|        retval = READSTAT_ERROR_PARSE;
  177|    130|        goto cleanup;
  178|    130|    }
  179|  3.52k|    if (header_start.a1 == SAS_ALIGNMENT_OFFSET_4) {
  ------------------
  |  |   88|  3.52k|#define SAS_ALIGNMENT_OFFSET_4  0x33
  ------------------
  |  Branch (179:9): [True: 6, False: 3.51k]
  ------------------
  180|      6|        hinfo->pad1 = 4;
  181|      6|    }
  182|  3.52k|    if (header_start.a2 == SAS_ALIGNMENT_OFFSET_4) {
  ------------------
  |  |   88|  3.52k|#define SAS_ALIGNMENT_OFFSET_4  0x33
  ------------------
  |  Branch (182:9): [True: 1.71k, False: 1.80k]
  ------------------
  183|  1.71k|        hinfo->u64 = 1;
  184|  1.71k|    }
  185|  3.52k|    int bswap = 0;
  186|  3.52k|    if (header_start.endian == SAS_ENDIAN_BIG) {
  ------------------
  |  |   81|  3.52k|#define SAS_ENDIAN_BIG       0x00
  ------------------
  |  Branch (186:9): [True: 2.74k, False: 776]
  ------------------
  187|  2.74k|        bswap = machine_is_little_endian();
  188|  2.74k|        hinfo->little_endian = 0;
  189|  2.74k|    } else if (header_start.endian == SAS_ENDIAN_LITTLE) {
  ------------------
  |  |   82|    776|#define SAS_ENDIAN_LITTLE    0x01
  ------------------
  |  Branch (189:16): [True: 764, False: 12]
  ------------------
  190|    764|        bswap = !machine_is_little_endian();
  191|    764|        hinfo->little_endian = 1;
  192|    764|    } else {
  193|     12|        retval = READSTAT_ERROR_PARSE;
  194|     12|        goto cleanup;
  195|     12|    }
  196|  3.51k|    int i;
  197|  23.0k|    for (i=0; i<sizeof(_charset_table)/sizeof(_charset_table[0]); i++) {
  ------------------
  |  Branch (197:15): [True: 23.0k, False: 5]
  ------------------
  198|  23.0k|        if (header_start.encoding == _charset_table[i].code) {
  ------------------
  |  Branch (198:13): [True: 3.50k, False: 19.5k]
  ------------------
  199|  3.50k|            hinfo->encoding = _charset_table[i].name;
  200|  3.50k|            break;
  201|  3.50k|        }
  202|  23.0k|    }
  203|  3.51k|    if (hinfo->encoding == NULL) {
  ------------------
  |  Branch (203:9): [True: 5, False: 3.50k]
  ------------------
  204|      5|        if (error_handler) {
  ------------------
  |  Branch (204:13): [True: 0, False: 5]
  ------------------
  205|      0|            snprintf(error_buf, sizeof(error_buf), "Unsupported character set code: %d", header_start.encoding);
  206|      0|            error_handler(error_buf, user_ctx);
  207|      0|        }
  208|      5|        retval = READSTAT_ERROR_UNSUPPORTED_CHARSET;
  209|      5|        goto cleanup;
  210|      5|    }
  211|  3.50k|    memcpy(hinfo->table_name, header_start.table_name, sizeof(header_start.table_name));
  212|  3.50k|    if (io->seek(hinfo->pad1, READSTAT_SEEK_CUR, io->io_ctx) == -1) {
  ------------------
  |  Branch (212:9): [True: 3, False: 3.50k]
  ------------------
  213|      3|        retval = READSTAT_ERROR_SEEK;
  214|      3|        goto cleanup;
  215|      3|    }
  216|       |
  217|  3.50k|    double creation_time, modification_time, creation_time_diff, modification_time_diff;
  218|       |
  219|  3.50k|    if (io->read(&creation_time, sizeof(double), io->io_ctx) < sizeof(double)) {
  ------------------
  |  Branch (219:9): [True: 12, False: 3.49k]
  ------------------
  220|     12|        retval = READSTAT_ERROR_READ;
  221|     12|        goto cleanup;
  222|     12|    }
  223|  3.49k|    if (bswap)
  ------------------
  |  Branch (223:9): [True: 2.73k, False: 759]
  ------------------
  224|  2.73k|        creation_time = byteswap_double(creation_time);
  225|       |
  226|  3.49k|    if (io->read(&modification_time, sizeof(double), io->io_ctx) < sizeof(double)) {
  ------------------
  |  Branch (226:9): [True: 6, False: 3.48k]
  ------------------
  227|      6|        retval = READSTAT_ERROR_READ;
  228|      6|        goto cleanup;
  229|      6|    }
  230|  3.48k|    if (bswap)
  ------------------
  |  Branch (230:9): [True: 2.72k, False: 758]
  ------------------
  231|  2.72k|        modification_time = byteswap_double(modification_time);
  232|       |
  233|  3.48k|    if (io->read(&creation_time_diff, sizeof(double), io->io_ctx) < sizeof(double)) {
  ------------------
  |  Branch (233:9): [True: 6, False: 3.48k]
  ------------------
  234|      6|        retval = READSTAT_ERROR_READ;
  235|      6|        goto cleanup;
  236|      6|    }
  237|  3.48k|    if (bswap)
  ------------------
  |  Branch (237:9): [True: 2.72k, False: 755]
  ------------------
  238|  2.72k|        creation_time_diff = byteswap_double(creation_time_diff);
  239|       |    
  240|  3.48k|    if (io->read(&modification_time_diff, sizeof(double), io->io_ctx) < sizeof(double)) {
  ------------------
  |  Branch (240:9): [True: 6, False: 3.47k]
  ------------------
  241|      6|        retval = READSTAT_ERROR_READ;
  242|      6|        goto cleanup;
  243|      6|    }
  244|  3.47k|    if (bswap)
  ------------------
  |  Branch (244:9): [True: 2.72k, False: 752]
  ------------------
  245|  2.72k|        modification_time_diff = byteswap_double(modification_time_diff);
  246|       |    
  247|  3.47k|    hinfo->creation_time = sas_convert_time(creation_time, creation_time_diff, epoch);
  248|  3.47k|    hinfo->modification_time = sas_convert_time(modification_time, modification_time_diff, epoch);
  249|       |
  250|  3.47k|    uint32_t header_size, page_size;
  251|       |
  252|  3.47k|    if (io->read(&header_size, sizeof(uint32_t), io->io_ctx) < sizeof(uint32_t)) {
  ------------------
  |  Branch (252:9): [True: 9, False: 3.46k]
  ------------------
  253|      9|        retval = READSTAT_ERROR_READ;
  254|      9|        goto cleanup;
  255|      9|    }
  256|  3.46k|    if (io->read(&page_size, sizeof(uint32_t), io->io_ctx) < sizeof(uint32_t)) {
  ------------------
  |  Branch (256:9): [True: 3, False: 3.46k]
  ------------------
  257|      3|        retval = READSTAT_ERROR_READ;
  258|      3|        goto cleanup;
  259|      3|    }
  260|       |
  261|  3.46k|    hinfo->header_size = bswap ? byteswap4(header_size) : header_size;
  ------------------
  |  Branch (261:26): [True: 2.71k, False: 749]
  ------------------
  262|  3.46k|    hinfo->page_size = bswap ? byteswap4(page_size) : page_size;
  ------------------
  |  Branch (262:24): [True: 2.71k, False: 749]
  ------------------
  263|       |
  264|  3.46k|    if (hinfo->header_size < 1024 || hinfo->page_size < 1024) {
  ------------------
  |  Branch (264:9): [True: 11, False: 3.45k]
  |  Branch (264:38): [True: 12, False: 3.44k]
  ------------------
  265|     23|        retval = READSTAT_ERROR_PARSE;
  266|     23|        goto cleanup;
  267|     23|    }
  268|  3.44k|    if (hinfo->header_size > (1<<24) || hinfo->page_size > (1<<24)) {
  ------------------
  |  Branch (268:9): [True: 20, False: 3.42k]
  |  Branch (268:41): [True: 28, False: 3.39k]
  ------------------
  269|     48|        retval = READSTAT_ERROR_PARSE;
  270|     48|        goto cleanup;
  271|     48|    }
  272|       |
  273|  3.39k|    if (hinfo->u64) {
  ------------------
  |  Branch (273:9): [True: 1.67k, False: 1.71k]
  ------------------
  274|  1.67k|        hinfo->page_header_size = SAS_PAGE_HEADER_SIZE_64BIT;
  ------------------
  |  |  123|  1.67k|#define SAS_PAGE_HEADER_SIZE_64BIT  40
  ------------------
  275|  1.67k|        hinfo->subheader_pointer_size = SAS_SUBHEADER_POINTER_SIZE_64BIT;
  ------------------
  |  |  120|  1.67k|#define SAS_SUBHEADER_POINTER_SIZE_64BIT    24
  ------------------
  276|  1.71k|    } else {
  277|  1.71k|        hinfo->page_header_size = SAS_PAGE_HEADER_SIZE_32BIT;
  ------------------
  |  |  122|  1.71k|#define SAS_PAGE_HEADER_SIZE_32BIT  24
  ------------------
  278|  1.71k|        hinfo->subheader_pointer_size = SAS_SUBHEADER_POINTER_SIZE_32BIT;
  ------------------
  |  |  119|  1.71k|#define SAS_SUBHEADER_POINTER_SIZE_32BIT    12
  ------------------
  279|  1.71k|    }
  280|       |
  281|  3.39k|    if (hinfo->u64) {
  ------------------
  |  Branch (281:9): [True: 1.67k, False: 1.71k]
  ------------------
  282|  1.67k|        uint64_t page_count;
  283|  1.67k|        if (io->read(&page_count, sizeof(uint64_t), io->io_ctx) < sizeof(uint64_t)) {
  ------------------
  |  Branch (283:13): [True: 18, False: 1.66k]
  ------------------
  284|     18|            retval = READSTAT_ERROR_READ;
  285|     18|            goto cleanup;
  286|     18|        }
  287|  1.66k|        hinfo->page_count = bswap ? byteswap8(page_count) : page_count;
  ------------------
  |  Branch (287:29): [True: 1.57k, False: 90]
  ------------------
  288|  1.71k|    } else {
  289|  1.71k|        uint32_t page_count;
  290|  1.71k|        if (io->read(&page_count, sizeof(uint32_t), io->io_ctx) < sizeof(uint32_t)) {
  ------------------
  |  Branch (290:13): [True: 16, False: 1.69k]
  ------------------
  291|     16|            retval = READSTAT_ERROR_READ;
  292|     16|            goto cleanup;
  293|     16|        }
  294|  1.69k|        hinfo->page_count = bswap ? byteswap4(page_count) : page_count;
  ------------------
  |  Branch (294:29): [True: 1.05k, False: 644]
  ------------------
  295|  1.69k|    }
  296|  3.35k|    if (hinfo->page_count > (1<<24)) {
  ------------------
  |  Branch (296:9): [True: 13, False: 3.34k]
  ------------------
  297|     13|        retval = READSTAT_ERROR_PARSE;
  298|     13|        goto cleanup;
  299|     13|    }
  300|       |    
  301|  3.34k|    if (io->seek(8, READSTAT_SEEK_CUR, io->io_ctx) == -1) {
  ------------------
  |  Branch (301:9): [True: 77, False: 3.26k]
  ------------------
  302|     77|        retval = READSTAT_ERROR_SEEK;
  303|     77|        if (error_handler) {
  ------------------
  |  Branch (303:13): [True: 0, False: 77]
  ------------------
  304|      0|            snprintf(error_buf, sizeof(error_buf), "ReadStat: Failed to seek forward by %d", 8);
  305|      0|            error_handler(error_buf, user_ctx);
  306|      0|        }
  307|     77|        goto cleanup;
  308|     77|    }
  309|  3.26k|    if (io->read(&header_end, sizeof(sas_header_end_t), io->io_ctx) < sizeof(sas_header_end_t)) {
  ------------------
  |  Branch (309:9): [True: 17, False: 3.25k]
  ------------------
  310|     17|        retval = READSTAT_ERROR_READ;
  311|     17|        goto cleanup;
  312|     17|    }
  313|  3.25k|    char major, revision_tag;
  314|  3.25k|    int minor, revision;
  315|       |    /* The release field is not NUL-terminated in the file; copy it into a
  316|       |     * terminated buffer before handing it to sscanf, which calls strlen on it. */
  317|  3.25k|    char release[sizeof(header_end.release)+1];
  318|  3.25k|    memcpy(release, header_end.release, sizeof(header_end.release));
  319|  3.25k|    release[sizeof(header_end.release)] = '\0';
  320|  3.25k|    if (sscanf(release, "%c.%04d%c%1d", &major, &minor, &revision_tag, &revision) != 4) {
  ------------------
  |  Branch (320:9): [True: 4, False: 3.24k]
  ------------------
  321|      4|        retval = READSTAT_ERROR_PARSE;
  322|      4|        goto cleanup;
  323|      4|    }
  324|       |
  325|  3.24k|    if (major >= '1' && major <= '9') {
  ------------------
  |  Branch (325:9): [True: 3.23k, False: 12]
  |  Branch (325:25): [True: 3.22k, False: 9]
  ------------------
  326|  3.22k|        hinfo->major_version = major - '0';
  327|  3.22k|    } else if (major == 'V') {
  ------------------
  |  Branch (327:16): [True: 3, False: 18]
  ------------------
  328|       |        // It appears that SAS Visual Forecaster reports the major version as "V"
  329|       |        // Treat it as version 9 for all intents and purposes
  330|      3|        hinfo->major_version = 9;
  331|     18|    } else {
  332|     18|        retval = READSTAT_ERROR_PARSE;
  333|     18|        goto cleanup;
  334|     18|    }
  335|       |    // revision_tag is usually M, but J has been observed in the wild (not created with SAS?)
  336|  3.22k|    if ((major == '8' || major == '9') && revision_tag != 'M' && revision_tag != 'J') {
  ------------------
  |  Branch (336:10): [True: 276, False: 2.95k]
  |  Branch (336:26): [True: 149, False: 2.80k]
  |  Branch (336:43): [True: 12, False: 413]
  |  Branch (336:66): [True: 2, False: 10]
  ------------------
  337|      2|        retval = READSTAT_ERROR_PARSE;
  338|      2|        goto cleanup;
  339|      2|    }
  340|  3.22k|    hinfo->minor_version = minor;
  341|  3.22k|    hinfo->revision = revision;
  342|       |
  343|  3.22k|    if ((major == '8' || major == '9') && minor == 0 && revision == 0) {
  ------------------
  |  Branch (343:10): [True: 274, False: 2.95k]
  |  Branch (343:26): [True: 149, False: 2.80k]
  |  Branch (343:43): [True: 92, False: 331]
  |  Branch (343:57): [True: 58, False: 34]
  ------------------
  344|       |        /* A bit of a hack, but most SAS installations are running a minor update */
  345|     58|        hinfo->vendor = READSTAT_VENDOR_STAT_TRANSFER;
  346|  3.16k|    } else {
  347|  3.16k|        hinfo->vendor = READSTAT_VENDOR_SAS;
  348|  3.16k|    }
  349|  3.22k|    if (io->seek(hinfo->header_size, READSTAT_SEEK_SET, io->io_ctx) == -1) {
  ------------------
  |  Branch (349:9): [True: 66, False: 3.16k]
  ------------------
  350|     66|        retval = READSTAT_ERROR_SEEK;
  351|     66|        if (error_handler) {
  ------------------
  |  Branch (351:13): [True: 0, False: 66]
  ------------------
  352|      0|            snprintf(error_buf, sizeof(error_buf), 
  353|      0|                    "ReadStat: Failed to seek to position %" PRId64, hinfo->header_size);
  354|      0|            error_handler(error_buf, user_ctx);
  355|      0|        }
  356|     66|        goto cleanup;
  357|     66|    }
  358|       |
  359|  3.67k|cleanup:
  360|  3.67k|    return retval;
  361|  3.22k|}
sas_validate_tag:
  576|  8.56k|readstat_error_t sas_validate_tag(char tag) {
  577|  8.56k|    if (tag == '_' || (tag >= 'A' && tag <= 'Z'))
  ------------------
  |  Branch (577:9): [True: 4.35k, False: 4.20k]
  |  Branch (577:24): [True: 1.53k, False: 2.67k]
  |  Branch (577:38): [True: 1.19k, False: 346]
  ------------------
  578|  5.54k|        return READSTAT_OK;
  579|       |
  580|  3.01k|    return READSTAT_ERROR_TAGGED_VALUE_IS_OUT_OF_RANGE;
  581|  8.56k|}
sas_assign_tag:
  583|  8.56k|void sas_assign_tag(readstat_value_t *value, uint8_t tag) {
  584|       |    /* We accommodate two tag schemes. In the first, the tag is an ASCII code
  585|       |     * given by uint8_t tag above. System missing is represented by an ASCII
  586|       |     * period. In the second scheme, (tag-2) is an offset from 'A', except when
  587|       |     * tag == 0, in which case it represents an underscore, or tag == 1, in
  588|       |     * which case it represents system-missing.
  589|       |     */
  590|  8.56k|    if (tag == 0) {
  ------------------
  |  Branch (590:9): [True: 4.35k, False: 4.20k]
  ------------------
  591|  4.35k|        tag = '_';
  592|  4.35k|    } else if (tag >= 2 && tag < 28) {
  ------------------
  |  Branch (592:16): [True: 3.68k, False: 528]
  |  Branch (592:28): [True: 1.12k, False: 2.56k]
  ------------------
  593|  1.12k|        tag = 'A' + (tag - 2);
  594|  1.12k|    }
  595|  8.56k|    if (sas_validate_tag(tag) == READSTAT_OK) {
  ------------------
  |  Branch (595:9): [True: 5.54k, False: 3.01k]
  ------------------
  596|  5.54k|        value->tag = tag;
  597|  5.54k|        value->is_tagged_missing = 1;
  598|  5.54k|    } else {
  599|  3.01k|        value->tag = 0;
  600|  3.01k|        value->is_system_missing = 1;
  601|  3.01k|    }
  602|  8.56k|}
readstat_sas.c:sas_epoch:
  124|  3.67k|static time_t sas_epoch(void) {
  125|  3.67k|    return - 3653 * 86400; // seconds between 01-01-1960 and 01-01-1970
  126|  3.67k|}
readstat_sas.c:sas_convert_time:
  128|  6.95k|static time_t sas_convert_time(double time, double time_diff, time_t epoch) {
  129|  6.95k|    time -= time_diff;
  130|  6.95k|    time += epoch;
  131|  6.95k|    if (isnan(time))
  ------------------
  |  Branch (131:9): [True: 733, False: 6.21k]
  ------------------
  132|    733|        return 0;
  133|  6.21k|    if (time > (double)LONG_MAX)
  ------------------
  |  Branch (133:9): [True: 1.69k, False: 4.52k]
  ------------------
  134|  1.69k|        return LONG_MAX;
  135|  4.52k|    if (time < (double)LONG_MIN)
  ------------------
  |  Branch (135:9): [True: 1.09k, False: 3.42k]
  ------------------
  136|  1.09k|        return LONG_MIN;
  137|  3.42k|    return time;
  138|  4.52k|}

readstat_parse_sas7bdat:
 1460|  3.67k|readstat_error_t readstat_parse_sas7bdat(readstat_parser_t *parser, const char *path, void *user_ctx) {
 1461|  3.67k|    int64_t last_examined_page_pass1 = 0;
 1462|  3.67k|    readstat_error_t retval = READSTAT_OK;
 1463|  3.67k|    readstat_io_t *io = parser->io;
 1464|       |
 1465|  3.67k|    sas7bdat_ctx_t  *ctx = calloc(1, sizeof(sas7bdat_ctx_t));
 1466|  3.67k|    sas_header_info_t  *hinfo = calloc(1, sizeof(sas_header_info_t));
 1467|       |
 1468|  3.67k|    if (ctx == NULL || hinfo == NULL) {
  ------------------
  |  Branch (1468:9): [True: 0, False: 3.67k]
  |  Branch (1468:24): [True: 0, False: 3.67k]
  ------------------
 1469|      0|        retval = READSTAT_ERROR_MALLOC;
 1470|      0|        goto cleanup;
 1471|      0|    }
 1472|       |
 1473|  3.67k|    ctx->handle = parser->handlers;
 1474|  3.67k|    ctx->input_encoding = parser->input_encoding;
 1475|  3.67k|    ctx->output_encoding = parser->output_encoding;
 1476|  3.67k|    ctx->user_ctx = user_ctx;
 1477|  3.67k|    ctx->io = parser->io;
 1478|  3.67k|    ctx->row_limit = parser->row_limit;
 1479|  3.67k|    ctx->moved_page_index = -1;
 1480|  3.67k|    if (parser->row_offset > 0)
  ------------------
  |  Branch (1480:9): [True: 0, False: 3.67k]
  ------------------
 1481|      0|        ctx->row_offset = parser->row_offset;
 1482|       |
 1483|  3.67k|    if (io->open(path, io->io_ctx) == -1) {
  ------------------
  |  Branch (1483:9): [True: 0, False: 3.67k]
  ------------------
 1484|      0|        retval = READSTAT_ERROR_OPEN;
 1485|      0|        goto cleanup;
 1486|      0|    }
 1487|       |
 1488|  3.67k|    if ((ctx->file_size = io->seek(0, READSTAT_SEEK_END, io->io_ctx)) == -1) {
  ------------------
  |  Branch (1488:9): [True: 0, False: 3.67k]
  ------------------
 1489|      0|        retval = READSTAT_ERROR_SEEK;
 1490|      0|        if (ctx->handle.error) {
  ------------------
  |  Branch (1490:13): [True: 0, False: 0]
  ------------------
 1491|      0|            snprintf(ctx->error_buf, sizeof(ctx->error_buf), "ReadStat: Failed to seek to end of file");
 1492|      0|            ctx->handle.error(ctx->error_buf, ctx->user_ctx);
 1493|      0|        }
 1494|      0|        goto cleanup;
 1495|      0|    }
 1496|       |
 1497|  3.67k|    if (io->seek(0, READSTAT_SEEK_SET, io->io_ctx) == -1) {
  ------------------
  |  Branch (1497:9): [True: 0, False: 3.67k]
  ------------------
 1498|      0|        retval = READSTAT_ERROR_SEEK;
 1499|      0|        if (ctx->handle.error) {
  ------------------
  |  Branch (1499:13): [True: 0, False: 0]
  ------------------
 1500|      0|            snprintf(ctx->error_buf, sizeof(ctx->error_buf), "ReadStat: Failed to seek to beginning of file");
 1501|      0|            ctx->handle.error(ctx->error_buf, ctx->user_ctx);
 1502|      0|        }
 1503|      0|        goto cleanup;
 1504|      0|    }
 1505|       |
 1506|  3.67k|    if ((retval = sas_read_header(io, hinfo, ctx->handle.error, user_ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1506:9): [True: 514, False: 3.16k]
  ------------------
 1507|    514|        goto cleanup;
 1508|    514|    }
 1509|       |
 1510|  3.16k|    ctx->u64 = hinfo->u64;
 1511|  3.16k|    ctx->little_endian = hinfo->little_endian;
 1512|  3.16k|    ctx->vendor = hinfo->vendor;
 1513|  3.16k|    ctx->bswap = machine_is_little_endian() ^ hinfo->little_endian;
 1514|  3.16k|    ctx->header_size = hinfo->header_size;
 1515|  3.16k|    ctx->page_count = hinfo->page_count;
 1516|  3.16k|    ctx->page_size = hinfo->page_size;
 1517|  3.16k|    ctx->page_header_size = hinfo->page_header_size;
 1518|  3.16k|    ctx->subheader_pointer_size = hinfo->subheader_pointer_size;
 1519|  3.16k|    ctx->subheader_signature_size = ctx->u64 ? 8 : 4;
  ------------------
  |  Branch (1519:37): [True: 1.59k, False: 1.56k]
  ------------------
 1520|  3.16k|    ctx->ctime = hinfo->creation_time;
 1521|  3.16k|    ctx->mtime = hinfo->modification_time;
 1522|  3.16k|    ctx->version = hinfo->major_version;
 1523|  3.16k|    if (ctx->input_encoding == NULL) {
  ------------------
  |  Branch (1523:9): [True: 3.16k, False: 0]
  ------------------
 1524|  3.16k|        ctx->input_encoding = hinfo->encoding;
 1525|  3.16k|    }
 1526|  3.16k|    if ((ctx->page = readstat_malloc(ctx->page_size)) == NULL) {
  ------------------
  |  Branch (1526:9): [True: 0, False: 3.16k]
  ------------------
 1527|      0|        retval = READSTAT_ERROR_MALLOC;
 1528|      0|        goto cleanup;
 1529|      0|    }
 1530|       |
 1531|  3.16k|    if (ctx->input_encoding && ctx->output_encoding && strcmp(ctx->input_encoding, ctx->output_encoding) != 0) {
  ------------------
  |  Branch (1531:9): [True: 3.16k, False: 0]
  |  Branch (1531:32): [True: 3.16k, False: 0]
  |  Branch (1531:56): [True: 2.10k, False: 1.05k]
  ------------------
 1532|  2.10k|        iconv_t converter = iconv_open(ctx->output_encoding, ctx->input_encoding);
 1533|  2.10k|        if (converter == (iconv_t)-1) {
  ------------------
  |  Branch (1533:13): [True: 2, False: 2.10k]
  ------------------
 1534|      2|            retval = READSTAT_ERROR_UNSUPPORTED_CHARSET;
 1535|      2|            goto cleanup;
 1536|      2|        }
 1537|  2.10k|        ctx->converter = converter;
 1538|  2.10k|    }
 1539|       |
 1540|  3.15k|    if ((retval = readstat_convert(ctx->table_name, sizeof(ctx->table_name),
  ------------------
  |  Branch (1540:9): [True: 2, False: 3.15k]
  ------------------
 1541|  3.15k|                hinfo->table_name, sizeof(hinfo->table_name), ctx->converter)) != READSTAT_OK) {
 1542|      2|        goto cleanup;
 1543|      2|    }
 1544|       |
 1545|  3.15k|    if ((retval = sas7bdat_parse_meta_pages_pass1(ctx, &last_examined_page_pass1)) != READSTAT_OK) {
  ------------------
  |  Branch (1545:9): [True: 239, False: 2.91k]
  ------------------
 1546|    239|        goto cleanup;
 1547|    239|    }
 1548|       |
 1549|  2.91k|    if ((retval = sas7bdat_parse_amd_pages_pass1(last_examined_page_pass1, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1549:9): [True: 921, False: 1.99k]
  ------------------
 1550|    921|        goto cleanup;
 1551|    921|    }
 1552|       |
 1553|  1.99k|    if (io->seek(ctx->header_size, READSTAT_SEEK_SET, io->io_ctx) == -1) {
  ------------------
  |  Branch (1553:9): [True: 0, False: 1.99k]
  ------------------
 1554|      0|        retval = READSTAT_ERROR_SEEK;
 1555|      0|        if (ctx->handle.error) {
  ------------------
  |  Branch (1555:13): [True: 0, False: 0]
  ------------------
 1556|      0|            snprintf(ctx->error_buf, sizeof(ctx->error_buf), "ReadStat: Failed to seek to position %" PRId64, 
 1557|      0|                    ctx->header_size);
 1558|      0|            ctx->handle.error(ctx->error_buf, ctx->user_ctx);
 1559|      0|        }
 1560|      0|        goto cleanup;
 1561|      0|    }
 1562|       |
 1563|  1.99k|    if ((retval = sas7bdat_parse_all_pages_pass2(ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1563:9): [True: 1.67k, False: 321]
  ------------------
 1564|  1.67k|        goto cleanup;
 1565|  1.67k|    }
 1566|       |    
 1567|    321|    if ((retval = sas7bdat_submit_columns_if_needed(ctx, 0)) != READSTAT_OK) {
  ------------------
  |  Branch (1567:9): [True: 76, False: 245]
  ------------------
 1568|     76|        goto cleanup;
 1569|     76|    }
 1570|       |
 1571|    245|    if (ctx->handle.value && ctx->parsed_row_count != ctx->row_limit) {
  ------------------
  |  Branch (1571:9): [True: 245, False: 0]
  |  Branch (1571:30): [True: 140, False: 105]
  ------------------
 1572|    140|        retval = READSTAT_ERROR_ROW_COUNT_MISMATCH;
 1573|    140|        if (ctx->handle.error) {
  ------------------
  |  Branch (1573:13): [True: 0, False: 140]
  ------------------
 1574|      0|            snprintf(ctx->error_buf, sizeof(ctx->error_buf), "ReadStat: Expected %d rows in file, found %d",
 1575|      0|                    ctx->row_limit, ctx->parsed_row_count);
 1576|      0|            ctx->handle.error(ctx->error_buf, ctx->user_ctx);
 1577|      0|        }
 1578|    140|        goto cleanup;
 1579|    140|    }
 1580|       |
 1581|    105|    if ((retval = sas7bdat_update_progress(ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1581:9): [True: 0, False: 105]
  ------------------
 1582|      0|        goto cleanup;
 1583|      0|    }
 1584|       |
 1585|  3.67k|cleanup:
 1586|  3.67k|    io->close(io->io_ctx);
 1587|       |
 1588|  3.67k|    if (retval == READSTAT_ERROR_OPEN ||
  ------------------
  |  Branch (1588:9): [True: 0, False: 3.67k]
  ------------------
 1589|  3.67k|            retval == READSTAT_ERROR_READ ||
  ------------------
  |  Branch (1589:13): [True: 419, False: 3.25k]
  ------------------
 1590|  3.25k|            retval == READSTAT_ERROR_SEEK) {
  ------------------
  |  Branch (1590:13): [True: 375, False: 2.88k]
  ------------------
 1591|    794|        if (ctx->handle.error) {
  ------------------
  |  Branch (1591:13): [True: 0, False: 794]
  ------------------
 1592|      0|            snprintf(ctx->error_buf, sizeof(ctx->error_buf), "ReadStat: %s (retval = %d): %s (errno = %d)", 
 1593|      0|                    readstat_error_message(retval), retval, strerror(errno), errno);
 1594|      0|            ctx->handle.error(ctx->error_buf, user_ctx);
 1595|      0|        }
 1596|    794|    }
 1597|       |
 1598|  3.67k|    if (ctx)
  ------------------
  |  Branch (1598:9): [True: 3.67k, False: 0]
  ------------------
 1599|  3.67k|        sas7bdat_ctx_free(ctx);
 1600|  3.67k|    if (hinfo)
  ------------------
  |  Branch (1600:9): [True: 3.67k, False: 0]
  ------------------
 1601|  3.67k|        free(hinfo);
 1602|       |
 1603|  3.67k|    return retval;
 1604|    105|}
readstat_sas7bdat_read.c:sas7bdat_parse_meta_pages_pass1:
 1301|  3.15k|static readstat_error_t sas7bdat_parse_meta_pages_pass1(sas7bdat_ctx_t *ctx, int64_t *outLastExaminedPage) {
 1302|  3.15k|    readstat_error_t retval = READSTAT_OK;
 1303|  3.15k|    readstat_io_t *io = ctx->io;
 1304|  3.15k|    int64_t i;
 1305|       |
 1306|       |    /* look for META and MIX pages at beginning... */
 1307|  8.35k|    for (i=0; i<ctx->page_count; i++) {
  ------------------
  |  Branch (1307:15): [True: 6.10k, False: 2.24k]
  ------------------
 1308|  6.10k|        if (io->seek(ctx->header_size + i*ctx->page_size, READSTAT_SEEK_SET, io->io_ctx) == -1) {
  ------------------
  |  Branch (1308:13): [True: 9, False: 6.09k]
  ------------------
 1309|      9|            retval = READSTAT_ERROR_SEEK;
 1310|      9|            if (ctx->handle.error) {
  ------------------
  |  Branch (1310:17): [True: 0, False: 9]
  ------------------
 1311|      0|                snprintf(ctx->error_buf, sizeof(ctx->error_buf), "ReadStat: Failed to seek to position %" PRId64 
 1312|      0|                        " (= %" PRId64 " + %" PRId64 "*%" PRId64 ")",
 1313|      0|                        ctx->header_size + i*ctx->page_size, ctx->header_size, i, ctx->page_size);
 1314|      0|                ctx->handle.error(ctx->error_buf, ctx->user_ctx);
 1315|      0|            }
 1316|      9|            goto cleanup;
 1317|      9|        }
 1318|       |
 1319|  6.09k|        readstat_off_t off = 0;
 1320|  6.09k|        if (ctx->u64)
  ------------------
  |  Branch (1320:13): [True: 3.86k, False: 2.22k]
  ------------------
 1321|  3.86k|            off = 16;
 1322|       |
 1323|  6.09k|        size_t head_len = off + 16 + 2;
 1324|  6.09k|        size_t tail_len = ctx->page_size - head_len;
 1325|       |
 1326|  6.09k|        if (io->read(ctx->page, head_len, io->io_ctx) < head_len) {
  ------------------
  |  Branch (1326:13): [True: 145, False: 5.94k]
  ------------------
 1327|    145|            retval = READSTAT_ERROR_READ;
 1328|    145|            goto cleanup;
 1329|    145|        }
 1330|       |
 1331|  5.94k|        uint16_t page_type = sas_read2(&ctx->page[off+16], ctx->bswap);
 1332|       |
 1333|  5.94k|        if ((page_type & SAS_PAGE_TYPE_MASK) == SAS_PAGE_TYPE_DATA)
  ------------------
  |  |  113|  5.94k|#define SAS_PAGE_TYPE_MASK   0x0F00
  ------------------
                      if ((page_type & SAS_PAGE_TYPE_MASK) == SAS_PAGE_TYPE_DATA)
  ------------------
  |  |  110|  5.94k|#define SAS_PAGE_TYPE_DATA   0x0100
  ------------------
  |  Branch (1333:13): [True: 669, False: 5.27k]
  ------------------
 1334|    669|            break;
 1335|  5.27k|        if ((page_type & SAS_PAGE_TYPE_COMP))
  ------------------
  |  |  117|  5.27k|#define SAS_PAGE_TYPE_COMP          0x9000
  ------------------
  |  Branch (1335:13): [True: 1.46k, False: 3.81k]
  ------------------
 1336|  1.46k|            continue;
 1337|       |
 1338|  3.81k|        if (io->read(ctx->page + head_len, tail_len, io->io_ctx) < tail_len) {
  ------------------
  |  Branch (1338:13): [True: 33, False: 3.78k]
  ------------------
 1339|     33|            retval = READSTAT_ERROR_READ;
 1340|     33|            goto cleanup;
 1341|     33|        }
 1342|       |
 1343|  3.78k|        if ((retval = sas7bdat_parse_page_pass1(ctx->page, ctx->page_size, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1343:13): [True: 52, False: 3.73k]
  ------------------
 1344|     52|            if (ctx->handle.error && retval != READSTAT_ERROR_USER_ABORT) {
  ------------------
  |  Branch (1344:17): [True: 0, False: 52]
  |  Branch (1344:38): [True: 0, False: 0]
  ------------------
 1345|      0|                int64_t pos = io->seek(0, READSTAT_SEEK_CUR, io->io_ctx);
 1346|      0|                snprintf(ctx->error_buf, sizeof(ctx->error_buf), 
 1347|      0|                        "ReadStat: Error parsing page %" PRId64 ", bytes %" PRId64 "-%" PRId64, 
 1348|      0|                        i, pos - ctx->page_size, pos-1);
 1349|      0|                ctx->handle.error(ctx->error_buf, ctx->user_ctx);
 1350|      0|            }
 1351|     52|            goto cleanup;
 1352|     52|        }
 1353|  3.78k|    }
 1354|       |
 1355|  3.15k|cleanup:
 1356|  3.15k|    if (outLastExaminedPage)
  ------------------
  |  Branch (1356:9): [True: 3.15k, False: 0]
  ------------------
 1357|  3.15k|        *outLastExaminedPage = i;
 1358|       |
 1359|  3.15k|    return retval;
 1360|  3.15k|}
readstat_sas7bdat_read.c:sas7bdat_parse_page_pass1:
 1003|  6.31k|static readstat_error_t sas7bdat_parse_page_pass1(const char *page, size_t page_size, sas7bdat_ctx_t *ctx) {
 1004|  6.31k|    readstat_error_t retval = READSTAT_OK;
 1005|       |
 1006|  6.31k|    uint16_t subheader_count = sas_read2(&page[ctx->page_header_size-4], ctx->bswap);
 1007|       |
 1008|  6.31k|    int i;
 1009|  6.31k|    const char *shp = &page[ctx->page_header_size];
 1010|  6.31k|    int lshp = ctx->subheader_pointer_size;
 1011|       |
 1012|  6.31k|    if (ctx->page_header_size + subheader_count*lshp > page_size) {
  ------------------
  |  Branch (1012:9): [True: 35, False: 6.27k]
  ------------------
 1013|     35|        retval = READSTAT_ERROR_PARSE;
 1014|     35|        goto cleanup;
 1015|     35|    }
 1016|       |
 1017|  70.2k|    for (i=0; i<subheader_count; i++) {
  ------------------
  |  Branch (1017:15): [True: 64.7k, False: 5.58k]
  ------------------
 1018|  64.7k|        subheader_pointer_t shp_info = { 0 };
 1019|  64.7k|        if ((retval = sas7bdat_parse_subheader_pointer(shp, page + page_size - shp, &shp_info, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1019:13): [True: 0, False: 64.7k]
  ------------------
 1020|      0|            goto cleanup;
 1021|      0|        }
 1022|  64.7k|        if (shp_info.len > 0 && shp_info.compression != SAS_COMPRESSION_TRUNC && shp_info.compression != SAS_COMPRESSION_REFERENCE) {
  ------------------
  |  |  126|   106k|#define SAS_COMPRESSION_TRUNC              0x01
  ------------------
                      if (shp_info.len > 0 && shp_info.compression != SAS_COMPRESSION_TRUNC && shp_info.compression != SAS_COMPRESSION_REFERENCE) {
  ------------------
  |  |  128|  35.2k|#define SAS_COMPRESSION_REFERENCE          0x03
  ------------------
  |  Branch (1022:13): [True: 41.9k, False: 22.7k]
  |  Branch (1022:33): [True: 35.2k, False: 6.75k]
  |  Branch (1022:82): [True: 35.2k, False: 3]
  ------------------
 1023|  35.2k|            if ((retval = sas7bdat_validate_subheader_pointer(&shp_info, page_size, subheader_count, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1023:17): [True: 607, False: 34.6k]
  ------------------
 1024|    607|                goto cleanup;
 1025|    607|            }
 1026|  34.6k|            if (shp_info.compression == SAS_COMPRESSION_NONE) {
  ------------------
  |  |  125|  34.6k|#define SAS_COMPRESSION_NONE               0x00
  ------------------
  |  Branch (1026:17): [True: 31.0k, False: 3.58k]
  ------------------
 1027|  31.0k|                sas_subheader_type_t subheader_type = sas7bdat_parse_subheader_type(page + shp_info.offset, ctx);
 1028|  31.0k|                if (subheader_type == SAS_SUBHEADER_TYPE_COLUMN_TEXT) {
  ------------------
  |  Branch (1028:21): [True: 2.67k, False: 28.3k]
  ------------------
 1029|  2.67k|                    if ((retval = sas7bdat_parse_subheader(subheader_type, page + shp_info.offset, shp_info.len, ctx))
  ------------------
  |  Branch (1029:25): [True: 66, False: 2.61k]
  ------------------
 1030|  2.67k|                            != READSTAT_OK) {
 1031|     66|                        goto cleanup;
 1032|     66|                    }
 1033|  2.67k|                }
 1034|  31.0k|            } else if (shp_info.compression == SAS_COMPRESSION_ROW || shp_info.compression == SAS_COMPRESSION_DELETED_ROW
  ------------------
  |  |  129|  7.16k|#define SAS_COMPRESSION_ROW                0x04
  ------------------
                          } else if (shp_info.compression == SAS_COMPRESSION_ROW || shp_info.compression == SAS_COMPRESSION_DELETED_ROW
  ------------------
  |  |  130|  3.97k|#define SAS_COMPRESSION_DELETED_ROW        0x05
  ------------------
  |  Branch (1034:24): [True: 3.19k, False: 387]
  |  Branch (1034:71): [True: 367, False: 20]
  ------------------
 1035|  3.56k|                    || sas7bdat_is_moved_row(shp_info.compression)) {
  ------------------
  |  Branch (1035:24): [True: 2, False: 18]
  ------------------
 1036|       |                /* void */
 1037|  3.56k|            } else {
 1038|     18|                retval = READSTAT_ERROR_UNSUPPORTED_COMPRESSION;
 1039|     18|                goto cleanup;
 1040|     18|            }
 1041|  34.6k|        }
 1042|       |
 1043|  64.0k|        shp += lshp;
 1044|  64.0k|    }
 1045|       |
 1046|  6.31k|cleanup:
 1047|       |
 1048|  6.31k|    return retval;
 1049|  6.27k|}
readstat_sas7bdat_read.c:sas7bdat_parse_subheader_pointer:
  950|   101k|        subheader_pointer_t *info, sas7bdat_ctx_t *ctx) {
  951|   101k|    readstat_error_t retval = READSTAT_OK;
  952|   101k|    if (ctx->u64) {
  ------------------
  |  Branch (952:9): [True: 18.9k, False: 82.4k]
  ------------------
  953|  18.9k|        if (shp_size <= 17) {
  ------------------
  |  Branch (953:13): [True: 0, False: 18.9k]
  ------------------
  954|      0|            retval = READSTAT_ERROR_PARSE;
  955|      0|            goto cleanup;
  956|      0|        }
  957|  18.9k|        info->offset = sas_read8(&shp[0], ctx->bswap);
  958|  18.9k|        info->len = sas_read8(&shp[8], ctx->bswap);
  959|  18.9k|        info->compression = shp[16];
  960|  18.9k|        info->is_compressed_data = shp[17];
  961|  82.4k|    } else {
  962|  82.4k|        if (shp_size <= 9) {
  ------------------
  |  Branch (962:13): [True: 0, False: 82.4k]
  ------------------
  963|      0|            retval = READSTAT_ERROR_PARSE;
  964|      0|            goto cleanup;
  965|      0|        }
  966|  82.4k|        info->offset = sas_read4(&shp[0], ctx->bswap);
  967|  82.4k|        info->len = sas_read4(&shp[4], ctx->bswap);
  968|  82.4k|        info->compression = shp[8];
  969|  82.4k|        info->is_compressed_data = shp[9];
  970|  82.4k|    }
  971|   101k|cleanup:
  972|   101k|    return retval;
  973|   101k|}
readstat_sas7bdat_read.c:sas7bdat_validate_subheader_pointer:
  976|  53.3k|        uint16_t subheader_count, sas7bdat_ctx_t *ctx) {
  977|  53.3k|    if (shp_info->offset > page_size)
  ------------------
  |  Branch (977:9): [True: 369, False: 52.9k]
  ------------------
  978|    369|        return READSTAT_ERROR_PARSE;
  979|  52.9k|    if (shp_info->len > page_size)
  ------------------
  |  Branch (979:9): [True: 197, False: 52.7k]
  ------------------
  980|    197|        return READSTAT_ERROR_PARSE;
  981|  52.7k|    if (shp_info->offset + shp_info->len > page_size)
  ------------------
  |  Branch (981:9): [True: 28, False: 52.7k]
  ------------------
  982|     28|        return READSTAT_ERROR_PARSE;
  983|  52.7k|    if (shp_info->offset < ctx->page_header_size + subheader_count*ctx->subheader_pointer_size)
  ------------------
  |  Branch (983:9): [True: 11, False: 52.7k]
  ------------------
  984|     11|        return READSTAT_ERROR_PARSE;
  985|  52.7k|    if (shp_info->compression == SAS_COMPRESSION_NONE || shp_info->compression == SAS_COMPRESSION_NONE_MOVED) {
  ------------------
  |  |  125|   105k|#define SAS_COMPRESSION_NONE               0x00
  ------------------
                  if (shp_info->compression == SAS_COMPRESSION_NONE || shp_info->compression == SAS_COMPRESSION_NONE_MOVED) {
  ------------------
  |  |  127|  5.50k|#define SAS_COMPRESSION_NONE_MOVED         0x02
  ------------------
  |  Branch (985:9): [True: 47.2k, False: 5.50k]
  |  Branch (985:58): [True: 2, False: 5.49k]
  ------------------
  986|  47.2k|        if (shp_info->len < ctx->subheader_signature_size)
  ------------------
  |  Branch (986:13): [True: 3, False: 47.2k]
  ------------------
  987|      3|            return READSTAT_ERROR_PARSE;
  988|  47.2k|        if (shp_info->offset + ctx->subheader_signature_size > page_size)
  ------------------
  |  Branch (988:13): [True: 0, False: 47.2k]
  ------------------
  989|      0|            return READSTAT_ERROR_PARSE;
  990|  47.2k|    }
  991|       |    
  992|  52.7k|    return READSTAT_OK;
  993|  52.7k|}
readstat_sas7bdat_read.c:sas7bdat_parse_subheader_type:
  914|  47.2k|static sas_subheader_type_t sas7bdat_parse_subheader_type(const char* subheader, sas7bdat_ctx_t* ctx) {
  915|  47.2k|    if (!ctx->u64) {
  ------------------
  |  Branch (915:9): [True: 35.8k, False: 11.3k]
  ------------------
  916|  35.8k|        uint32_t signature_32 = sas_read4(subheader, ctx->bswap);
  917|  35.8k|        return sas7bdat_parse_subheader_type_32(signature_32);
  918|  35.8k|    }
  919|       |
  920|  11.3k|    if (!ctx->little_endian) {
  ------------------
  |  Branch (920:9): [True: 10.2k, False: 1.11k]
  ------------------
  921|       |        /* Big-endian 64-bit files lay out signatures differently from
  922|       |         * little-endian ones: ROW_SIZE and COLUMN_SIZE occupy only the first
  923|       |         * four bytes (the remaining four are unspecified), while the 0xFFFF...
  924|       |         * family is written as 0xFFFFFFFF followed by the 32-bit signature. */
  925|  10.2k|        uint32_t signature_32 = sas_read4(subheader, ctx->bswap);
  926|  10.2k|        if (signature_32 == SAS_SUBHEADER_SIGNATURE_ROW_SIZE) {
  ------------------
  |  |   93|  10.2k|#define SAS_SUBHEADER_SIGNATURE_ROW_SIZE       0xF7F7F7F7
  ------------------
  |  Branch (926:13): [True: 274, False: 9.94k]
  ------------------
  927|    274|            return SAS_SUBHEADER_TYPE_ROW_SIZE;
  928|  9.94k|        } else if (signature_32 == SAS_SUBHEADER_SIGNATURE_COLUMN_SIZE) {
  ------------------
  |  |   94|  9.94k|#define SAS_SUBHEADER_SIGNATURE_COLUMN_SIZE    0xF6F6F6F6
  ------------------
  |  Branch (928:20): [True: 68, False: 9.87k]
  ------------------
  929|     68|            return SAS_SUBHEADER_TYPE_COLUMN_SIZE;
  930|  9.87k|        } else if (signature_32 != SAS_SUBHEADER_SIGNATURE_COLUMN_NAME) {
  ------------------
  |  |  104|  9.87k|#define SAS_SUBHEADER_SIGNATURE_COLUMN_NAME    0xFFFFFFFF
  ------------------
  |  Branch (930:20): [True: 2.48k, False: 7.39k]
  ------------------
  931|  2.48k|            return SAS_SUBHEADER_TYPE_DATA;
  932|  2.48k|        }
  933|  7.39k|        return sas7bdat_parse_subheader_type_32(sas_read4(&subheader[4], ctx->bswap));
  934|  10.2k|    }
  935|       |
  936|  1.11k|    uint64_t signature = sas_read8(subheader, ctx->bswap);
  937|  1.11k|    if (signature == SAS_SUBHEADER_SIGNATURE_ROW_SIZE) {
  ------------------
  |  |   93|  1.11k|#define SAS_SUBHEADER_SIGNATURE_ROW_SIZE       0xF7F7F7F7
  ------------------
  |  Branch (937:9): [True: 102, False: 1.01k]
  ------------------
  938|    102|        return SAS_SUBHEADER_TYPE_ROW_SIZE;
  939|  1.01k|    } else if (signature == SAS_SUBHEADER_SIGNATURE_COLUMN_SIZE) {
  ------------------
  |  |   94|  1.01k|#define SAS_SUBHEADER_SIGNATURE_COLUMN_SIZE    0xF6F6F6F6
  ------------------
  |  Branch (939:16): [True: 102, False: 913]
  ------------------
  940|    102|        return SAS_SUBHEADER_TYPE_COLUMN_SIZE;
  941|    913|    } else if ((signature & SAS_SUBHEADER_SIGNATURE_64BIT_MASK) != SAS_SUBHEADER_SIGNATURE_64BIT_MASK) {
  ------------------
  |  |  106|    913|#define SAS_SUBHEADER_SIGNATURE_64BIT_MASK     0xFFFFFFFF00000000
  ------------------
                  } else if ((signature & SAS_SUBHEADER_SIGNATURE_64BIT_MASK) != SAS_SUBHEADER_SIGNATURE_64BIT_MASK) {
  ------------------
  |  |  106|    913|#define SAS_SUBHEADER_SIGNATURE_64BIT_MASK     0xFFFFFFFF00000000
  ------------------
  |  Branch (941:16): [True: 28, False: 885]
  ------------------
  942|     28|        return SAS_SUBHEADER_TYPE_DATA;
  943|     28|    }
  944|       |
  945|    885|    uint32_t lower_bytes = (uint32_t)(signature & SAS_SUBHEADER_SIGNATURE_32BIT_MASK);
  ------------------
  |  |  107|    885|#define SAS_SUBHEADER_SIGNATURE_32BIT_MASK     0x00000000FFFFFFFF
  ------------------
  946|    885|    return sas7bdat_parse_subheader_type_32(lower_bytes);
  947|  1.11k|}
readstat_sas7bdat_read.c:sas7bdat_parse_subheader_type_32:
  888|  44.1k|static sas_subheader_type_t sas7bdat_parse_subheader_type_32(uint32_t signature) {
  889|  44.1k|    switch (signature) {
  890|  7.74k|        case SAS_SUBHEADER_SIGNATURE_ROW_SIZE:
  ------------------
  |  |   93|  7.74k|#define SAS_SUBHEADER_SIGNATURE_ROW_SIZE       0xF7F7F7F7
  ------------------
  |  Branch (890:9): [True: 7.74k, False: 36.3k]
  ------------------
  891|  7.74k|            return SAS_SUBHEADER_TYPE_ROW_SIZE;
  892|  3.12k|        case SAS_SUBHEADER_SIGNATURE_COLUMN_SIZE:
  ------------------
  |  |   94|  3.12k|#define SAS_SUBHEADER_SIGNATURE_COLUMN_SIZE    0xF6F6F6F6
  ------------------
  |  Branch (892:9): [True: 3.12k, False: 41.0k]
  ------------------
  893|  3.12k|            return SAS_SUBHEADER_TYPE_COLUMN_SIZE;
  894|  2.80k|        case SAS_SUBHEADER_SIGNATURE_COUNTS:
  ------------------
  |  |   95|  2.80k|#define SAS_SUBHEADER_SIGNATURE_COUNTS         0xFFFFFC00
  ------------------
  |  Branch (894:9): [True: 2.80k, False: 41.3k]
  ------------------
  895|  2.80k|            return SAS_SUBHEADER_TYPE_COUNTS;
  896|  8.14k|        case SAS_SUBHEADER_SIGNATURE_COLUMN_FORMAT:
  ------------------
  |  |   96|  8.14k|#define SAS_SUBHEADER_SIGNATURE_COLUMN_FORMAT  0xFFFFFBFE
  ------------------
  |  Branch (896:9): [True: 8.14k, False: 35.9k]
  ------------------
  897|  8.14k|            return SAS_SUBHEADER_TYPE_COLUMN_FORMAT;
  898|  4.78k|        case SAS_SUBHEADER_SIGNATURE_COLUMN_ATTRS:
  ------------------
  |  |  101|  4.78k|#define SAS_SUBHEADER_SIGNATURE_COLUMN_ATTRS   0xFFFFFFFC
  ------------------
  |  Branch (898:9): [True: 4.78k, False: 39.3k]
  ------------------
  899|  4.78k|            return SAS_SUBHEADER_TYPE_COLUMN_ATTRS;
  900|  4.42k|        case SAS_SUBHEADER_SIGNATURE_COLUMN_TEXT:
  ------------------
  |  |  102|  4.42k|#define SAS_SUBHEADER_SIGNATURE_COLUMN_TEXT    0xFFFFFFFD
  ------------------
  |  Branch (900:9): [True: 4.42k, False: 39.7k]
  ------------------
  901|  4.42k|            return SAS_SUBHEADER_TYPE_COLUMN_TEXT;
  902|  2.33k|        case SAS_SUBHEADER_SIGNATURE_COLUMN_LIST:
  ------------------
  |  |  103|  2.33k|#define SAS_SUBHEADER_SIGNATURE_COLUMN_LIST    0xFFFFFFFE
  ------------------
  |  Branch (902:9): [True: 2.33k, False: 41.8k]
  ------------------
  903|  2.33k|            return SAS_SUBHEADER_TYPE_COLUMN_LIST;
  904|  5.49k|        case SAS_SUBHEADER_SIGNATURE_COLUMN_NAME:
  ------------------
  |  |  104|  5.49k|#define SAS_SUBHEADER_SIGNATURE_COLUMN_NAME    0xFFFFFFFF
  ------------------
  |  Branch (904:9): [True: 5.49k, False: 38.6k]
  ------------------
  905|  5.49k|            return SAS_SUBHEADER_TYPE_COLUMN_NAME;
  906|  5.28k|        default:
  ------------------
  |  Branch (906:9): [True: 5.28k, False: 38.8k]
  ------------------
  907|  5.28k|            if ((signature & SAS_SUBHEADER_SIGNATURE_COLUMN_MASK) == SAS_SUBHEADER_SIGNATURE_COLUMN_MASK) {
  ------------------
  |  |   98|  5.28k|#define SAS_SUBHEADER_SIGNATURE_COLUMN_MASK    0xFFFFFFF8
  ------------------
                          if ((signature & SAS_SUBHEADER_SIGNATURE_COLUMN_MASK) == SAS_SUBHEADER_SIGNATURE_COLUMN_MASK) {
  ------------------
  |  |   98|  5.28k|#define SAS_SUBHEADER_SIGNATURE_COLUMN_MASK    0xFFFFFFF8
  ------------------
  |  Branch (907:17): [True: 1.72k, False: 3.55k]
  ------------------
  908|  1.72k|                return SAS_SUBHEADER_TYPE_UNKNOWN;
  909|  1.72k|            }
  910|  3.55k|            return SAS_SUBHEADER_TYPE_DATA;
  911|  44.1k|    }
  912|  44.1k|}
readstat_sas7bdat_read.c:sas7bdat_parse_subheader:
  697|  16.1k|        size_t len, sas7bdat_ctx_t *ctx) {
  698|  16.1k|    readstat_error_t retval = READSTAT_OK;
  699|       |
  700|  16.1k|    if (len < 2 + ctx->subheader_signature_size) {
  ------------------
  |  Branch (700:9): [True: 4, False: 16.1k]
  ------------------
  701|      4|        retval = READSTAT_ERROR_PARSE;
  702|      4|        goto cleanup;
  703|      4|    }
  704|  16.1k|    if (subheader_type == SAS_SUBHEADER_TYPE_ROW_SIZE) {
  ------------------
  |  Branch (704:9): [True: 3.11k, False: 13.0k]
  ------------------
  705|  3.11k|        retval = sas7bdat_parse_row_size_subheader(subheader, len, ctx);
  706|  13.0k|    } else if (subheader_type == SAS_SUBHEADER_TYPE_COLUMN_SIZE) {
  ------------------
  |  Branch (706:16): [True: 1.10k, False: 11.9k]
  ------------------
  707|  1.10k|        retval = sas7bdat_parse_column_size_subheader(subheader, len, ctx);
  708|  11.9k|    } else if (subheader_type == SAS_SUBHEADER_TYPE_COUNTS) {
  ------------------
  |  Branch (708:16): [True: 1.21k, False: 10.7k]
  ------------------
  709|       |        /* void */
  710|  10.7k|    } else if (subheader_type == SAS_SUBHEADER_TYPE_COLUMN_TEXT) {
  ------------------
  |  Branch (710:16): [True: 2.67k, False: 8.03k]
  ------------------
  711|  2.67k|        retval = sas7bdat_parse_column_text_subheader(subheader, len, ctx);
  712|  8.03k|    } else if (subheader_type == SAS_SUBHEADER_TYPE_COLUMN_NAME) {
  ------------------
  |  Branch (712:16): [True: 1.21k, False: 6.82k]
  ------------------
  713|  1.21k|        retval = sas7bdat_parse_column_name_subheader(subheader, len, ctx);
  714|  6.82k|    } else if (subheader_type == SAS_SUBHEADER_TYPE_COLUMN_ATTRS) {
  ------------------
  |  Branch (714:16): [True: 1.82k, False: 5.00k]
  ------------------
  715|  1.82k|        retval = sas7bdat_parse_column_attributes_subheader(subheader, len, ctx);
  716|  5.00k|    } else if (subheader_type == SAS_SUBHEADER_TYPE_COLUMN_FORMAT) {
  ------------------
  |  Branch (716:16): [True: 3.52k, False: 1.47k]
  ------------------
  717|  3.52k|        retval = sas7bdat_parse_column_format_subheader(subheader, len, ctx);
  718|  3.52k|    } else if (subheader_type == SAS_SUBHEADER_TYPE_COLUMN_LIST) {
  ------------------
  |  Branch (718:16): [True: 691, False: 786]
  ------------------
  719|       |        /* void */
  720|    786|    } else if (subheader_type == SAS_SUBHEADER_TYPE_UNKNOWN) {
  ------------------
  |  Branch (720:16): [True: 748, False: 38]
  ------------------
  721|       |        /* void */
  722|    748|    } else {
  723|     38|        retval = READSTAT_ERROR_PARSE;
  724|     38|    }
  725|       |
  726|  16.1k|cleanup:
  727|       |
  728|  16.1k|    return retval;
  729|  16.1k|}
readstat_sas7bdat_read.c:sas7bdat_parse_row_size_subheader:
  245|  3.11k|static readstat_error_t sas7bdat_parse_row_size_subheader(const char *subheader, size_t len, sas7bdat_ctx_t *ctx) {
  246|  3.11k|    readstat_error_t retval = READSTAT_OK;
  247|  3.11k|    uint64_t total_row_count;
  248|  3.11k|    uint64_t row_length, deleted_row_count, page_row_count;
  249|       |
  250|  3.11k|    if (len < (ctx->u64 ? 250: 190)) {
  ------------------
  |  Branch (250:9): [True: 3, False: 3.11k]
  |  Branch (250:16): [True: 598, False: 2.51k]
  ------------------
  251|      3|        retval = READSTAT_ERROR_PARSE;
  252|      3|        goto cleanup;
  253|      3|    }
  254|       |
  255|  3.11k|    if (ctx->u64) {
  ------------------
  |  Branch (255:9): [True: 598, False: 2.51k]
  ------------------
  256|    598|        row_length = sas_read8(&subheader[40], ctx->bswap);
  257|    598|        total_row_count = sas_read8(&subheader[48], ctx->bswap);
  258|    598|        deleted_row_count = sas_read8(&subheader[56], ctx->bswap);
  259|    598|        page_row_count = sas_read8(&subheader[120], ctx->bswap);
  260|  2.51k|    } else {
  261|  2.51k|        row_length = sas_read4(&subheader[20], ctx->bswap);
  262|  2.51k|        total_row_count = sas_read4(&subheader[24], ctx->bswap);
  263|  2.51k|        deleted_row_count = sas_read4(&subheader[28], ctx->bswap);
  264|  2.51k|        page_row_count = sas_read4(&subheader[60], ctx->bswap);
  265|  2.51k|    }
  266|       |
  267|  3.11k|    if (deleted_row_count > total_row_count) {
  ------------------
  |  Branch (267:9): [True: 58, False: 3.05k]
  ------------------
  268|     58|        retval = READSTAT_ERROR_PARSE;
  269|     58|        goto cleanup;
  270|     58|    }
  271|  3.05k|    ctx->total_row_count = total_row_count;
  272|  3.05k|    ctx->deleted_row_count = deleted_row_count;
  273|       |
  274|  3.05k|    sas_text_ref_t file_label_ref = sas7bdat_parse_text_ref(&subheader[len-130], ctx);
  275|  3.05k|    if (file_label_ref.length) {
  ------------------
  |  Branch (275:9): [True: 1.03k, False: 2.01k]
  ------------------
  276|  1.03k|        if ((retval = sas7bdat_copy_text_ref(ctx->file_label, sizeof(ctx->file_label),
  ------------------
  |  Branch (276:13): [True: 45, False: 989]
  ------------------
  277|  1.03k|                        file_label_ref, ctx)) != READSTAT_OK) {
  278|     45|            goto cleanup;
  279|     45|        }
  280|  1.03k|    }
  281|       |
  282|  3.00k|    sas_text_ref_t compression_ref = sas7bdat_parse_text_ref(&subheader[len-118], ctx);
  283|  3.00k|    if (compression_ref.length) {
  ------------------
  |  Branch (283:9): [True: 1.41k, False: 1.59k]
  ------------------
  284|  1.41k|        char compression[9];
  285|  1.41k|        if ((retval = sas7bdat_copy_text_ref(compression, sizeof(compression),
  ------------------
  |  Branch (285:13): [True: 56, False: 1.35k]
  ------------------
  286|  1.41k|                        compression_ref, ctx)) != READSTAT_OK) {
  287|     56|            goto cleanup;
  288|     56|        }
  289|  1.35k|        ctx->rdc_compression = (memcmp(compression, SAS_COMPRESSION_SIGNATURE_RDC, 8) == 0);
  ------------------
  |  |  136|  1.35k|#define SAS_COMPRESSION_SIGNATURE_RDC  "SASYZCR2"
  ------------------
  290|  1.35k|    }
  291|       |
  292|  2.95k|    ctx->row_length = row_length;
  293|  2.95k|    ctx->row = readstat_realloc(ctx->row, ctx->row_length);
  294|  2.95k|    if (ctx->row == NULL) {
  ------------------
  |  Branch (294:9): [True: 9, False: 2.94k]
  ------------------
  295|      9|        retval = READSTAT_ERROR_MALLOC;
  296|      9|        goto cleanup;
  297|      9|    }
  298|       |
  299|  2.94k|    ctx->page_row_count = page_row_count;
  300|  2.94k|    uint64_t live_row_count = total_row_count - deleted_row_count;
  301|  2.94k|    uint64_t total_row_count_after_skipping = live_row_count;
  302|  2.94k|    if (live_row_count > ctx->row_offset) {
  ------------------
  |  Branch (302:9): [True: 2.63k, False: 313]
  ------------------
  303|  2.63k|        total_row_count_after_skipping -= ctx->row_offset;
  304|  2.63k|    } else {
  305|    313|        total_row_count_after_skipping = 0;
  306|    313|        ctx->row_offset = live_row_count;
  307|    313|    }
  308|  2.94k|    if (ctx->row_limit == 0 || total_row_count_after_skipping < ctx->row_limit)
  ------------------
  |  Branch (308:9): [True: 1.07k, False: 1.87k]
  |  Branch (308:32): [True: 68, False: 1.80k]
  ------------------
  309|  1.13k|        ctx->row_limit = total_row_count_after_skipping;
  310|       |
  311|  3.11k|cleanup:
  312|  3.11k|    return retval;
  313|  2.94k|}
readstat_sas7bdat_read.c:sas7bdat_parse_text_ref:
  146|  44.3k|static sas_text_ref_t sas7bdat_parse_text_ref(const char *data, sas7bdat_ctx_t *ctx) {
  147|  44.3k|    sas_text_ref_t  ref;
  148|       |
  149|  44.3k|    ref.index = sas_read2(&data[0], ctx->bswap);
  150|  44.3k|    ref.offset = sas_read2(&data[2], ctx->bswap);
  151|  44.3k|    ref.length = sas_read2(&data[4], ctx->bswap);
  152|       |
  153|  44.3k|    return ref;
  154|  44.3k|}
readstat_sas7bdat_read.c:sas7bdat_copy_text_ref:
  156|  7.60M|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|  7.60M|    if (text_ref.index >= ctx->text_blob_count)
  ------------------
  |  Branch (157:9): [True: 169, False: 7.60M]
  ------------------
  158|    169|        return READSTAT_ERROR_PARSE;
  159|       |    
  160|  7.60M|    if (text_ref.length == 0) {
  ------------------
  |  Branch (160:9): [True: 7.60M, False: 3.37k]
  ------------------
  161|  7.60M|        out_buffer[0] = '\0';
  162|  7.60M|        return READSTAT_OK;
  163|  7.60M|    }
  164|       |
  165|  3.37k|    char *blob = ctx->text_blobs[text_ref.index];
  166|       |
  167|  3.37k|    if (text_ref.offset + text_ref.length > ctx->text_blob_lengths[text_ref.index])
  ------------------
  |  Branch (167:9): [True: 62, False: 3.31k]
  ------------------
  168|     62|        return READSTAT_ERROR_PARSE;
  169|       |
  170|  3.31k|    return readstat_convert(out_buffer, out_buffer_len, &blob[text_ref.offset], text_ref.length,
  171|  3.31k|            ctx->converter);
  172|  3.37k|}
readstat_sas7bdat_read.c:sas7bdat_parse_column_size_subheader:
  217|  1.10k|static readstat_error_t sas7bdat_parse_column_size_subheader(const char *subheader, size_t len, sas7bdat_ctx_t *ctx) {
  218|  1.10k|    uint64_t col_count;
  219|  1.10k|    readstat_error_t retval = READSTAT_OK;
  220|       |
  221|  1.10k|    if (ctx->column_count || ctx->did_submit_columns) {
  ------------------
  |  Branch (221:9): [True: 5, False: 1.10k]
  |  Branch (221:30): [True: 3, False: 1.09k]
  ------------------
  222|      8|        retval = READSTAT_ERROR_PARSE;
  223|      8|        goto cleanup;
  224|      8|    }
  225|       |
  226|  1.09k|    if (len < (ctx->u64 ? 16 : 8)) {
  ------------------
  |  Branch (226:9): [True: 3, False: 1.09k]
  |  Branch (226:16): [True: 83, False: 1.01k]
  ------------------
  227|      3|        retval = READSTAT_ERROR_PARSE;
  228|      3|        goto cleanup;
  229|      3|    }
  230|       |
  231|  1.09k|    if (ctx->u64) {
  ------------------
  |  Branch (231:9): [True: 82, False: 1.01k]
  ------------------
  232|     82|        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.09k|    ctx->column_count = col_count;
  238|       |
  239|  1.09k|    retval = sas7bdat_realloc_col_info(ctx, ctx->column_count);
  240|       |
  241|  1.10k|cleanup:
  242|  1.10k|    return retval;
  243|  1.09k|}
readstat_sas7bdat_read.c:sas7bdat_realloc_col_info:
  204|  7.54k|static readstat_error_t sas7bdat_realloc_col_info(sas7bdat_ctx_t *ctx, size_t count) {
  205|  7.54k|    if (ctx->col_info_count < count) {
  ------------------
  |  Branch (205:9): [True: 3.73k, False: 3.81k]
  ------------------
  206|  3.73k|        size_t old_count = ctx->col_info_count;
  207|  3.73k|        ctx->col_info_count = count;
  208|  3.73k|        ctx->col_info = readstat_realloc(ctx->col_info, ctx->col_info_count * sizeof(col_info_t));
  209|  3.73k|        if (ctx->col_info == NULL) {
  ------------------
  |  Branch (209:13): [True: 97, False: 3.63k]
  ------------------
  210|     97|            return READSTAT_ERROR_MALLOC;
  211|     97|        }
  212|  3.63k|        memset(ctx->col_info + old_count, 0, (count - old_count) * sizeof(col_info_t));
  213|  3.63k|    }
  214|  7.44k|    return READSTAT_OK;
  215|  7.54k|}
readstat_sas7bdat_read.c:sas7bdat_parse_column_text_subheader:
  174|  2.67k|static readstat_error_t sas7bdat_parse_column_text_subheader(const char *subheader, size_t len, sas7bdat_ctx_t *ctx) {
  175|  2.67k|    readstat_error_t retval = READSTAT_OK;
  176|  2.67k|    size_t signature_len = ctx->subheader_signature_size;
  177|  2.67k|    uint16_t remainder = sas_read2(&subheader[signature_len], ctx->bswap);
  178|  2.67k|    char *blob = NULL;
  179|  2.67k|    if (remainder != sas_subheader_remainder(len, signature_len)) {
  ------------------
  |  Branch (179:9): [True: 65, False: 2.61k]
  ------------------
  180|     65|        retval = READSTAT_ERROR_PARSE;
  181|     65|        goto cleanup;
  182|     65|    }
  183|  2.61k|    ctx->text_blob_count++;
  184|  2.61k|    ctx->text_blobs = readstat_realloc(ctx->text_blobs, ctx->text_blob_count * sizeof(char *));
  185|  2.61k|    ctx->text_blob_lengths = readstat_realloc(ctx->text_blob_lengths,
  186|  2.61k|            ctx->text_blob_count * sizeof(ctx->text_blob_lengths[0]));
  187|  2.61k|    if (ctx->text_blobs == NULL || ctx->text_blob_lengths == NULL) {
  ------------------
  |  Branch (187:9): [True: 0, False: 2.61k]
  |  Branch (187:36): [True: 0, False: 2.61k]
  ------------------
  188|      0|        retval = READSTAT_ERROR_MALLOC;
  189|      0|        goto cleanup;
  190|      0|    }
  191|       |
  192|  2.61k|    if ((blob = readstat_malloc(len-signature_len)) == NULL) {
  ------------------
  |  Branch (192:9): [True: 0, False: 2.61k]
  ------------------
  193|      0|        retval = READSTAT_ERROR_MALLOC;
  194|      0|        goto cleanup;
  195|      0|    }
  196|  2.61k|    memcpy(blob, subheader+signature_len, len-signature_len);
  197|  2.61k|    ctx->text_blob_lengths[ctx->text_blob_count-1] = len-signature_len;
  198|  2.61k|    ctx->text_blobs[ctx->text_blob_count-1] = blob;
  199|       |
  200|  2.67k|cleanup:
  201|  2.67k|    return retval;
  202|  2.61k|}
readstat_sas7bdat_read.c:sas7bdat_parse_column_name_subheader:
  315|  1.21k|static readstat_error_t sas7bdat_parse_column_name_subheader(const char *subheader, size_t len, sas7bdat_ctx_t *ctx) {
  316|  1.21k|    readstat_error_t retval = READSTAT_OK;
  317|  1.21k|    size_t signature_len = ctx->subheader_signature_size;
  318|  1.21k|    int cmax = ctx->u64 ? (len-28)/8 : (len-20)/8;
  ------------------
  |  Branch (318:16): [True: 99, False: 1.11k]
  ------------------
  319|  1.21k|    int i;
  320|  1.21k|    const char *cnp = &subheader[signature_len+8];
  321|  1.21k|    uint16_t remainder = sas_read2(&subheader[signature_len], ctx->bswap);
  322|       |
  323|  1.21k|    if (remainder != sas_subheader_remainder(len, signature_len)) {
  ------------------
  |  Branch (323:9): [True: 55, False: 1.15k]
  ------------------
  324|     55|        retval = READSTAT_ERROR_PARSE;
  325|     55|        goto cleanup;
  326|     55|    }
  327|       |
  328|  1.15k|    ctx->col_names_count += cmax;
  329|       |
  330|  1.15k|    if ((retval = sas7bdat_realloc_col_info(ctx, ctx->col_names_count)) != READSTAT_OK)
  ------------------
  |  Branch (330:9): [True: 14, False: 1.14k]
  ------------------
  331|     14|        goto cleanup;
  332|       |
  333|  28.8k|    for (i=ctx->col_names_count-cmax; i<ctx->col_names_count; i++) {
  ------------------
  |  Branch (333:39): [True: 27.6k, False: 1.14k]
  ------------------
  334|  27.6k|        ctx->col_info[i].name_ref = sas7bdat_parse_text_ref(cnp, ctx);
  335|  27.6k|        cnp += 8;
  336|  27.6k|    }
  337|       |
  338|  1.21k|cleanup:
  339|       |
  340|  1.21k|    return retval;
  341|  1.14k|}
readstat_sas7bdat_read.c:sas7bdat_parse_column_attributes_subheader:
  343|  1.82k|static readstat_error_t sas7bdat_parse_column_attributes_subheader(const char *subheader, size_t len, sas7bdat_ctx_t *ctx) {
  344|  1.82k|    readstat_error_t retval = READSTAT_OK;
  345|  1.82k|    size_t signature_len = ctx->subheader_signature_size;
  346|  1.82k|    int cmax = ctx->u64 ? (len-28)/16 : (len-20)/12;
  ------------------
  |  Branch (346:16): [True: 122, False: 1.70k]
  ------------------
  347|  1.82k|    int i;
  348|  1.82k|    const char *cap = &subheader[signature_len+8];
  349|  1.82k|    uint16_t remainder = sas_read2(&subheader[signature_len], ctx->bswap);
  350|       |
  351|  1.82k|    if (remainder != sas_subheader_remainder(len, signature_len)) {
  ------------------
  |  Branch (351:9): [True: 54, False: 1.76k]
  ------------------
  352|     54|        retval = READSTAT_ERROR_PARSE;
  353|     54|        goto cleanup;
  354|     54|    }
  355|  1.76k|    ctx->col_attrs_count += cmax;
  356|  1.76k|    if ((retval = sas7bdat_realloc_col_info(ctx, ctx->col_attrs_count)) != READSTAT_OK)
  ------------------
  |  Branch (356:9): [True: 11, False: 1.75k]
  ------------------
  357|     11|        goto cleanup;
  358|       |
  359|  9.69k|    for (i=ctx->col_attrs_count-cmax; i<ctx->col_attrs_count; i++) {
  ------------------
  |  Branch (359:39): [True: 7.94k, False: 1.74k]
  ------------------
  360|  7.94k|        if (ctx->u64) {
  ------------------
  |  Branch (360:13): [True: 839, False: 7.10k]
  ------------------
  361|    839|            ctx->col_info[i].offset = sas_read8(&cap[0], ctx->bswap);
  362|  7.10k|        } else {
  363|  7.10k|            ctx->col_info[i].offset = sas_read4(&cap[0], ctx->bswap);
  364|  7.10k|        }
  365|       |
  366|  7.94k|        readstat_off_t off=4;
  367|  7.94k|        if (ctx->u64)
  ------------------
  |  Branch (367:13): [True: 839, False: 7.10k]
  ------------------
  368|    839|            off=8;
  369|       |
  370|  7.94k|        ctx->col_info[i].width = sas_read4(&cap[off], ctx->bswap);
  371|  7.94k|        if (ctx->col_info[i].width > ctx->max_col_width)
  ------------------
  |  Branch (371:13): [True: 868, False: 7.08k]
  ------------------
  372|    868|            ctx->max_col_width = ctx->col_info[i].width;
  373|       |
  374|  7.94k|        if (cap[off+6] == SAS_COLUMN_TYPE_NUM) {
  ------------------
  |  |   90|  7.94k|#define SAS_COLUMN_TYPE_NUM  0x01
  ------------------
  |  Branch (374:13): [True: 4.90k, False: 3.04k]
  ------------------
  375|  4.90k|            ctx->col_info[i].type = READSTAT_TYPE_DOUBLE;
  376|  4.90k|        } else if (cap[off+6] == SAS_COLUMN_TYPE_CHR) {
  ------------------
  |  |   91|  3.04k|#define SAS_COLUMN_TYPE_CHR  0x02
  ------------------
  |  Branch (376:20): [True: 3.02k, False: 15]
  ------------------
  377|  3.02k|            ctx->col_info[i].type = READSTAT_TYPE_STRING;
  378|  3.02k|        } else {
  379|     15|            retval = READSTAT_ERROR_PARSE;
  380|     15|            goto cleanup;
  381|     15|        }
  382|  7.93k|        ctx->col_info[i].index = i;
  383|  7.93k|        cap += off+8;
  384|  7.93k|    }
  385|       |
  386|  1.82k|cleanup:
  387|       |
  388|  1.82k|    return retval;
  389|  1.75k|}
readstat_sas7bdat_read.c:sas7bdat_parse_column_format_subheader:
  391|  3.52k|static readstat_error_t sas7bdat_parse_column_format_subheader(const char *subheader, size_t len, sas7bdat_ctx_t *ctx) {
  392|  3.52k|    readstat_error_t retval = READSTAT_OK;
  393|       |
  394|  3.52k|    if (len < (ctx->u64 ? 58 : 46)) {
  ------------------
  |  Branch (394:9): [True: 2, False: 3.52k]
  |  Branch (394:16): [True: 344, False: 3.18k]
  ------------------
  395|      2|        retval = READSTAT_ERROR_PARSE;
  396|      2|        goto cleanup;
  397|      2|    }
  398|       |
  399|  3.52k|    ctx->col_formats_count++;
  400|  3.52k|    if ((retval = sas7bdat_realloc_col_info(ctx, ctx->col_formats_count)) != READSTAT_OK)
  ------------------
  |  Branch (400:9): [True: 0, False: 3.52k]
  ------------------
  401|      0|        goto cleanup;
  402|       |
  403|  3.52k|    col_info_t *col_info = &ctx->col_info[ctx->col_formats_count-1];
  404|  3.52k|    if (ctx->u64) {
  ------------------
  |  Branch (404:9): [True: 343, False: 3.18k]
  ------------------
  405|    343|        col_info->format_width = sas_read2(&subheader[24], ctx->bswap);
  406|    343|        col_info->format_digits = sas_read2(&subheader[26], ctx->bswap);
  407|    343|        col_info->informat_width = sas_read2(&subheader[28], ctx->bswap);
  408|    343|        col_info->informat_digits = sas_read2(&subheader[30], ctx->bswap);
  409|  3.18k|    } else {
  410|  3.18k|        col_info->format_width = sas_read2(&subheader[12], ctx->bswap);
  411|  3.18k|        col_info->format_digits = sas_read2(&subheader[14], ctx->bswap);
  412|  3.18k|        col_info->informat_width = sas_read2(&subheader[16], ctx->bswap);
  413|  3.18k|        col_info->informat_digits = sas_read2(&subheader[18], ctx->bswap);
  414|  3.18k|    }
  415|  3.52k|    col_info->informat_ref = sas7bdat_parse_text_ref(
  416|  3.52k|            ctx->u64 ? &subheader[40] : &subheader[28], ctx);
  ------------------
  |  Branch (416:13): [True: 343, False: 3.18k]
  ------------------
  417|  3.52k|    col_info->format_ref = sas7bdat_parse_text_ref(
  418|  3.52k|            ctx->u64 ? &subheader[46] : &subheader[34], ctx);
  ------------------
  |  Branch (418:13): [True: 343, False: 3.18k]
  ------------------
  419|  3.52k|    col_info->label_ref = sas7bdat_parse_text_ref(
  420|  3.52k|            ctx->u64 ? &subheader[52] : &subheader[40], ctx);
  ------------------
  |  Branch (420:13): [True: 343, False: 3.18k]
  ------------------
  421|       |
  422|  3.52k|cleanup:
  423|  3.52k|    return retval;
  424|  3.52k|}
readstat_sas7bdat_read.c:sas7bdat_is_moved_row:
  995|     20|static int sas7bdat_is_moved_row(unsigned char compression) {
  996|     20|    return compression == SAS_COMPRESSION_ROW_MOVED
  ------------------
  |  |  131|     40|#define SAS_COMPRESSION_ROW_MOVED          0x06
  ------------------
  |  Branch (996:12): [True: 0, False: 20]
  ------------------
  997|     20|        || compression == SAS_COMPRESSION_NONE_MOVED
  ------------------
  |  |  127|     40|#define SAS_COMPRESSION_NONE_MOVED         0x02
  ------------------
  |  Branch (997:12): [True: 2, False: 18]
  ------------------
  998|     18|        || compression == SAS_COMPRESSION_ROW_UNREFERENCED
  ------------------
  |  |  133|     38|#define SAS_COMPRESSION_ROW_UNREFERENCED   0x0d
  ------------------
  |  Branch (998:12): [True: 0, False: 18]
  ------------------
  999|     18|        || compression == SAS_COMPRESSION_NONE_UNREFERENCED;
  ------------------
  |  |  132|     18|#define SAS_COMPRESSION_NONE_UNREFERENCED  0x09
  ------------------
  |  Branch (999:12): [True: 0, False: 18]
  ------------------
 1000|     20|}
readstat_sas7bdat_read.c:sas7bdat_parse_amd_pages_pass1:
 1362|  2.91k|static readstat_error_t sas7bdat_parse_amd_pages_pass1(int64_t last_examined_page_pass1, sas7bdat_ctx_t *ctx) {
 1363|  2.91k|    readstat_error_t retval = READSTAT_OK;
 1364|  2.91k|    readstat_io_t *io = ctx->io;
 1365|  2.91k|    uint64_t i;
 1366|  2.91k|    uint64_t amd_page_count = 0;
 1367|       |
 1368|       |    /* ...then AMD pages at the end */
 1369|  6.24k|    for (i=ctx->page_count-1; i>last_examined_page_pass1; i--) {
  ------------------
  |  Branch (1369:31): [True: 4.62k, False: 1.62k]
  ------------------
 1370|  4.62k|        if (io->seek(ctx->header_size + i*ctx->page_size, READSTAT_SEEK_SET, io->io_ctx) == -1) {
  ------------------
  |  Branch (1370:13): [True: 220, False: 4.40k]
  ------------------
 1371|    220|            retval = READSTAT_ERROR_SEEK;
 1372|    220|            if (ctx->handle.error) {
  ------------------
  |  Branch (1372:17): [True: 0, False: 220]
  ------------------
 1373|      0|                snprintf(ctx->error_buf, sizeof(ctx->error_buf), "ReadStat: Failed to seek to position %" PRId64 
 1374|      0|                        " (= %" PRId64 " + %" PRId64 "*%" PRId64 ")",
 1375|      0|                        ctx->header_size + i*ctx->page_size, ctx->header_size, i, ctx->page_size);
 1376|      0|                ctx->handle.error(ctx->error_buf, ctx->user_ctx);
 1377|      0|            }
 1378|    220|            goto cleanup;
 1379|    220|        }
 1380|       |
 1381|  4.40k|        readstat_off_t off = 0;
 1382|  4.40k|        if (ctx->u64)
  ------------------
  |  Branch (1382:13): [True: 3.30k, False: 1.10k]
  ------------------
 1383|  3.30k|            off = 16;
 1384|       |
 1385|  4.40k|        size_t head_len = off + 16 + 2;
 1386|  4.40k|        size_t tail_len = ctx->page_size - head_len;
 1387|       |
 1388|  4.40k|        if (io->read(ctx->page, head_len, io->io_ctx) < head_len) {
  ------------------
  |  Branch (1388:13): [True: 9, False: 4.40k]
  ------------------
 1389|      9|            retval = READSTAT_ERROR_READ;
 1390|      9|            goto cleanup;
 1391|      9|        }
 1392|       |
 1393|  4.40k|        uint16_t page_type = sas_read2(&ctx->page[off+16], ctx->bswap);
 1394|       |
 1395|  4.40k|        if ((page_type & SAS_PAGE_TYPE_MASK) == SAS_PAGE_TYPE_DATA) {
  ------------------
  |  |  113|  4.40k|#define SAS_PAGE_TYPE_MASK   0x0F00
  ------------------
                      if ((page_type & SAS_PAGE_TYPE_MASK) == SAS_PAGE_TYPE_DATA) {
  ------------------
  |  |  110|  4.40k|#define SAS_PAGE_TYPE_DATA   0x0100
  ------------------
  |  Branch (1395:13): [True: 1.04k, False: 3.35k]
  ------------------
 1396|       |            /* Usually AMD pages are at the end but sometimes data pages appear after them */
 1397|  1.04k|            if (amd_page_count > 0)
  ------------------
  |  Branch (1397:17): [True: 377, False: 669]
  ------------------
 1398|    377|                break;
 1399|    669|            continue;
 1400|  1.04k|        }
 1401|  3.35k|        if ((page_type & SAS_PAGE_TYPE_COMP))
  ------------------
  |  |  117|  3.35k|#define SAS_PAGE_TYPE_COMP          0x9000
  ------------------
  |  Branch (1401:13): [True: 807, False: 2.54k]
  ------------------
 1402|    807|            continue;
 1403|       |
 1404|  2.54k|        if (io->read(ctx->page + head_len, tail_len, io->io_ctx) < tail_len) {
  ------------------
  |  Branch (1404:13): [True: 18, False: 2.52k]
  ------------------
 1405|     18|            retval = READSTAT_ERROR_READ;
 1406|     18|            goto cleanup;
 1407|     18|        }
 1408|       |
 1409|  2.52k|        if ((retval = sas7bdat_parse_page_pass1(ctx->page, ctx->page_size, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1409:13): [True: 674, False: 1.85k]
  ------------------
 1410|    674|            if (ctx->handle.error && retval != READSTAT_ERROR_USER_ABORT) {
  ------------------
  |  Branch (1410:17): [True: 0, False: 674]
  |  Branch (1410:38): [True: 0, False: 0]
  ------------------
 1411|      0|                int64_t pos = io->seek(0, READSTAT_SEEK_CUR, io->io_ctx);
 1412|      0|                snprintf(ctx->error_buf, sizeof(ctx->error_buf), 
 1413|      0|                        "ReadStat: Error parsing page %" PRId64 ", bytes %" PRId64 "-%" PRId64, 
 1414|      0|                        i, pos - ctx->page_size, pos-1);
 1415|      0|                ctx->handle.error(ctx->error_buf, ctx->user_ctx);
 1416|      0|            }
 1417|    674|            goto cleanup;
 1418|    674|        }
 1419|       |
 1420|  1.85k|        amd_page_count++;
 1421|  1.85k|    }
 1422|       |
 1423|  2.91k|cleanup:
 1424|       |
 1425|  2.91k|    return retval;
 1426|  2.91k|}
readstat_sas7bdat_read.c:sas7bdat_parse_all_pages_pass2:
 1428|  1.99k|static readstat_error_t sas7bdat_parse_all_pages_pass2(sas7bdat_ctx_t *ctx) {
 1429|  1.99k|    readstat_error_t retval = READSTAT_OK;
 1430|  1.99k|    readstat_io_t *io = ctx->io;
 1431|  1.99k|    int64_t i;
 1432|       |
 1433|  3.38k|    for (i=0; i<ctx->page_count; i++) {
  ------------------
  |  Branch (1433:15): [True: 3.07k, False: 303]
  ------------------
 1434|  3.07k|        if ((retval = sas7bdat_update_progress(ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1434:13): [True: 0, False: 3.07k]
  ------------------
 1435|      0|            goto cleanup;
 1436|      0|        }
 1437|  3.07k|        if (io->read(ctx->page, ctx->page_size, io->io_ctx) < ctx->page_size) {
  ------------------
  |  Branch (1437:13): [True: 101, False: 2.97k]
  ------------------
 1438|    101|            retval = READSTAT_ERROR_READ;
 1439|    101|            goto cleanup;
 1440|    101|        }
 1441|       |
 1442|  2.97k|        if ((retval = sas7bdat_parse_page_pass2(ctx->page, ctx->page_size, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1442:13): [True: 1.57k, False: 1.40k]
  ------------------
 1443|  1.57k|            if (ctx->handle.error && retval != READSTAT_ERROR_USER_ABORT) {
  ------------------
  |  Branch (1443:17): [True: 0, False: 1.57k]
  |  Branch (1443:38): [True: 0, False: 0]
  ------------------
 1444|      0|                int64_t pos = io->seek(0, READSTAT_SEEK_CUR, io->io_ctx);
 1445|      0|                snprintf(ctx->error_buf, sizeof(ctx->error_buf), 
 1446|      0|                        "ReadStat: Error parsing page %" PRId64 ", bytes %" PRId64 "-%" PRId64, 
 1447|      0|                        i, pos - ctx->page_size, pos-1);
 1448|      0|                ctx->handle.error(ctx->error_buf, ctx->user_ctx);
 1449|      0|            }
 1450|  1.57k|            goto cleanup;
 1451|  1.57k|        }
 1452|  1.40k|        if (ctx->row_limit > 0 && ctx->parsed_row_count == ctx->row_limit)
  ------------------
  |  Branch (1452:13): [True: 588, False: 814]
  |  Branch (1452:35): [True: 18, False: 570]
  ------------------
 1453|     18|            break;
 1454|  1.40k|    }
 1455|  1.99k|cleanup:
 1456|       |
 1457|  1.99k|    return retval;
 1458|  1.99k|}
readstat_sas7bdat_read.c:sas7bdat_parse_page_pass2:
 1183|  2.97k|static readstat_error_t sas7bdat_parse_page_pass2(const char *page, size_t page_size, sas7bdat_ctx_t *ctx) {
 1184|  2.97k|    uint16_t page_type;
 1185|       |
 1186|  2.97k|    readstat_error_t retval = READSTAT_OK;
 1187|       |
 1188|  2.97k|    page_type = sas_read2(&page[ctx->page_header_size-8], ctx->bswap);
 1189|       |
 1190|  2.97k|    const char *data = NULL;
 1191|       |
 1192|  2.97k|    if ((page_type & SAS_PAGE_TYPE_MASK) == SAS_PAGE_TYPE_DATA) {
  ------------------
  |  |  113|  2.97k|#define SAS_PAGE_TYPE_MASK   0x0F00
  ------------------
                  if ((page_type & SAS_PAGE_TYPE_MASK) == SAS_PAGE_TYPE_DATA) {
  ------------------
  |  |  110|  2.97k|#define SAS_PAGE_TYPE_DATA   0x0100
  ------------------
  |  Branch (1192:9): [True: 336, False: 2.64k]
  ------------------
 1193|    336|        ctx->page_row_count = sas_read2(&page[ctx->page_header_size-6], ctx->bswap);
 1194|    336|        data = &page[ctx->page_header_size];
 1195|  2.64k|    } else if (!(page_type & SAS_PAGE_TYPE_COMP)) {
  ------------------
  |  |  117|  2.64k|#define SAS_PAGE_TYPE_COMP          0x9000
  ------------------
  |  Branch (1195:16): [True: 2.34k, False: 294]
  ------------------
 1196|  2.34k|        uint16_t subheader_count = sas_read2(&page[ctx->page_header_size-4], ctx->bswap);
 1197|       |
 1198|  2.34k|        int i;
 1199|  2.34k|        const char *shp = &page[ctx->page_header_size];
 1200|  2.34k|        int lshp = ctx->subheader_pointer_size;
 1201|       |
 1202|  2.34k|        if (ctx->page_header_size + subheader_count*lshp > page_size) {
  ------------------
  |  Branch (1202:13): [True: 3, False: 2.34k]
  ------------------
 1203|      3|            retval = READSTAT_ERROR_PARSE;
 1204|      3|            goto cleanup;
 1205|      3|        }
 1206|       |
 1207|  37.8k|        for (i=0; i<subheader_count; i++) {
  ------------------
  |  Branch (1207:19): [True: 36.7k, False: 1.19k]
  ------------------
 1208|  36.7k|            subheader_pointer_t shp_info = { 0 };
 1209|  36.7k|            if ((retval = sas7bdat_parse_subheader_pointer(shp, page + page_size - shp, &shp_info, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1209:17): [True: 0, False: 36.7k]
  ------------------
 1210|      0|                goto cleanup;
 1211|      0|            }
 1212|  36.7k|            if (shp_info.len > 0 && shp_info.compression == SAS_COMPRESSION_REFERENCE) {
  ------------------
  |  |  128|  22.6k|#define SAS_COMPRESSION_REFERENCE          0x03
  ------------------
  |  Branch (1212:17): [True: 22.6k, False: 14.0k]
  |  Branch (1212:37): [True: 0, False: 22.6k]
  ------------------
 1213|      0|                uint64_t page_index = shp_info.offset - 1;
 1214|      0|                uint64_t subheader_index = shp_info.len - 1;
 1215|      0|                if ((retval = sas7bdat_parse_moved_row(page_index, subheader_index, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1215:21): [True: 0, False: 0]
  ------------------
 1216|      0|                    goto cleanup;
 1217|      0|                }
 1218|  36.7k|            } else if (shp_info.len > 0 && shp_info.compression != SAS_COMPRESSION_TRUNC) {
  ------------------
  |  |  126|  22.6k|#define SAS_COMPRESSION_TRUNC              0x01
  ------------------
  |  Branch (1218:24): [True: 22.6k, False: 14.0k]
  |  Branch (1218:44): [True: 18.0k, False: 4.56k]
  ------------------
 1219|  18.0k|                if ((retval = sas7bdat_validate_subheader_pointer(&shp_info, page_size, subheader_count, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1219:21): [True: 1, False: 18.0k]
  ------------------
 1220|      1|                    goto cleanup;
 1221|      1|                }
 1222|  18.0k|                if (shp_info.compression == SAS_COMPRESSION_NONE) {
  ------------------
  |  |  125|  18.0k|#define SAS_COMPRESSION_NONE               0x00
  ------------------
  |  Branch (1222:21): [True: 16.1k, False: 1.91k]
  ------------------
 1223|  16.1k|                    sas_subheader_type_t subheader_type = sas7bdat_parse_subheader_type(page + shp_info.offset, ctx);
 1224|  16.1k|                    if (shp_info.is_compressed_data && subheader_type == SAS_SUBHEADER_TYPE_DATA) {
  ------------------
  |  Branch (1224:25): [True: 12.5k, False: 3.60k]
  |  Branch (1224:56): [True: 935, False: 11.6k]
  ------------------
 1225|    935|                        if (shp_info.len != ctx->row_length) {
  ------------------
  |  Branch (1225:29): [True: 423, False: 512]
  ------------------
 1226|    423|                            retval = READSTAT_ERROR_ROW_WIDTH_MISMATCH;
 1227|    423|                            goto cleanup;
 1228|    423|                        }
 1229|    512|                        if ((retval = sas7bdat_submit_columns_if_needed(ctx, 1)) != READSTAT_OK) {
  ------------------
  |  Branch (1229:29): [True: 8, False: 504]
  ------------------
 1230|      8|                            goto cleanup;
 1231|      8|                        }
 1232|    504|                        if ((retval = sas7bdat_parse_single_row(page + shp_info.offset, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1232:29): [True: 8, False: 496]
  ------------------
 1233|      8|                            goto cleanup;
 1234|      8|                        }
 1235|  15.2k|                    } else {
 1236|  15.2k|                        if (subheader_type != SAS_SUBHEADER_TYPE_COLUMN_TEXT) {
  ------------------
  |  Branch (1236:29): [True: 13.4k, False: 1.74k]
  ------------------
 1237|  13.4k|                            if ((retval = sas7bdat_parse_subheader(subheader_type, page + shp_info.offset, shp_info.len, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1237:33): [True: 446, False: 13.0k]
  ------------------
 1238|    446|                                goto cleanup;
 1239|    446|                            }
 1240|  13.4k|                        }
 1241|  15.2k|                    }
 1242|  16.1k|                } else if (shp_info.compression == SAS_COMPRESSION_ROW) {
  ------------------
  |  |  129|  1.91k|#define SAS_COMPRESSION_ROW                0x04
  ------------------
  |  Branch (1242:28): [True: 1.80k, False: 116]
  ------------------
 1243|  1.80k|                    if ((retval = sas7bdat_submit_columns_if_needed(ctx, 1)) != READSTAT_OK) {
  ------------------
  |  Branch (1243:25): [True: 29, False: 1.77k]
  ------------------
 1244|     29|                        goto cleanup;
 1245|     29|                    }
 1246|  1.77k|                    if ((retval = sas7bdat_parse_subheader_compressed(page + shp_info.offset, shp_info.len, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1246:25): [True: 232, False: 1.54k]
  ------------------
 1247|    232|                        goto cleanup;
 1248|    232|                    }
 1249|  1.77k|                } else if (shp_info.compression == SAS_COMPRESSION_DELETED_ROW) {
  ------------------
  |  |  130|    116|#define SAS_COMPRESSION_DELETED_ROW        0x05
  ------------------
  |  Branch (1249:28): [True: 116, False: 0]
  ------------------
 1250|    116|                    if ((retval = sas7bdat_register_deleted_row(ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1250:25): [True: 2, False: 114]
  ------------------
 1251|      2|                        goto cleanup;
 1252|      2|                    }
 1253|    116|                } else if (sas7bdat_is_moved_row(shp_info.compression)) {
  ------------------
  |  Branch (1253:28): [True: 0, False: 0]
  ------------------
 1254|       |                    /* void */
 1255|      0|                } else {
 1256|      0|                    retval = READSTAT_ERROR_UNSUPPORTED_COMPRESSION;
 1257|      0|                    goto cleanup;
 1258|      0|                }
 1259|  18.0k|            }
 1260|       |
 1261|  35.5k|            shp += lshp;
 1262|  35.5k|        }
 1263|       |
 1264|  1.19k|        if ((page_type & SAS_PAGE_TYPE_MASK) == SAS_PAGE_TYPE_MIX) {
  ------------------
  |  |  113|  1.19k|#define SAS_PAGE_TYPE_MASK   0x0F00
  ------------------
                      if ((page_type & SAS_PAGE_TYPE_MASK) == SAS_PAGE_TYPE_MIX) {
  ------------------
  |  |  111|  1.19k|#define SAS_PAGE_TYPE_MIX    0x0200
  ------------------
  |  Branch (1264:13): [True: 728, False: 467]
  ------------------
 1265|       |            /* HACK - this is supposed to obey 8-byte boundaries but
 1266|       |             * some files created by Stat/Transfer don't. So verify that the
 1267|       |             * padding is { 0, 0, 0, 0 } or { ' ', ' ', ' ', ' ' } (or that
 1268|       |             * the file is not from Stat/Transfer) before skipping it */
 1269|    728|            if ((shp-page)%8 == 4 && shp + 4 <= page + page_size &&
  ------------------
  |  Branch (1269:17): [True: 425, False: 303]
  |  Branch (1269:38): [True: 422, False: 3]
  ------------------
 1270|    422|                    (*(uint32_t *)shp == 0x00000000 ||
  ------------------
  |  Branch (1270:22): [True: 100, False: 322]
  ------------------
 1271|    322|                     *(uint32_t *)shp == 0x20202020 ||
  ------------------
  |  Branch (1271:22): [True: 51, False: 271]
  ------------------
 1272|    385|                     ctx->vendor != READSTAT_VENDOR_STAT_TRANSFER)) {
  ------------------
  |  Branch (1272:22): [True: 234, False: 37]
  ------------------
 1273|    385|                data = shp + 4;
 1274|    385|            } else {
 1275|    343|                data = shp;
 1276|    343|            }
 1277|    728|        }
 1278|  1.19k|    }
 1279|  1.82k|    if (data) {
  ------------------
  |  Branch (1279:9): [True: 1.06k, False: 761]
  ------------------
 1280|  1.06k|        if ((retval = sas7bdat_submit_columns_if_needed(ctx, 0)) != READSTAT_OK) {
  ------------------
  |  Branch (1280:13): [True: 121, False: 943]
  ------------------
 1281|    121|            goto cleanup;
 1282|    121|        }
 1283|    943|        if (ctx->handle.value) {
  ------------------
  |  Branch (1283:13): [True: 943, False: 0]
  ------------------
 1284|    943|            const unsigned char *deleted_row_bitmap = NULL;
 1285|    943|            uint32_t deleted_row_bitmap_row_count = 0;
 1286|    943|            if (page_type & SAS_PAGE_TYPE_DELETED_ROWS) {
  ------------------
  |  |  115|    943|#define SAS_PAGE_TYPE_DELETED_ROWS  0x0080
  ------------------
  |  Branch (1286:17): [True: 229, False: 714]
  ------------------
 1287|    229|                if ((retval = sas7bdat_parse_deleted_row_bitmap(page, data, page_size,
  ------------------
  |  Branch (1287:21): [True: 118, False: 111]
  ------------------
 1288|    229|                        &deleted_row_bitmap, &deleted_row_bitmap_row_count, ctx)) != READSTAT_OK) {
 1289|    118|                    goto cleanup;
 1290|    118|                }
 1291|    229|            }
 1292|    825|            retval = sas7bdat_parse_rows(data, page + page_size - data,
 1293|    825|                    deleted_row_bitmap, deleted_row_bitmap_row_count, ctx);
 1294|    825|        }
 1295|    943|    } 
 1296|  2.97k|cleanup:
 1297|       |
 1298|  2.97k|    return retval;
 1299|  1.82k|}
readstat_sas7bdat_read.c:sas7bdat_parse_single_row:
  498|  42.0k|static readstat_error_t sas7bdat_parse_single_row(const char *data, sas7bdat_ctx_t *ctx) {
  499|  42.0k|    if (ctx->parsed_row_count == ctx->row_limit)
  ------------------
  |  Branch (499:9): [True: 379, False: 41.6k]
  ------------------
  500|    379|        return READSTAT_OK;
  501|  41.6k|    if (ctx->row_offset) {
  ------------------
  |  Branch (501:9): [True: 0, False: 41.6k]
  ------------------
  502|      0|        ctx->row_offset--;
  503|      0|        return READSTAT_OK;
  504|      0|    }
  505|       |
  506|  41.6k|    readstat_error_t retval = READSTAT_OK;
  507|  41.6k|    int j;
  508|  41.6k|    if (ctx->handle.value) {
  ------------------
  |  Branch (508:9): [True: 41.6k, False: 0]
  ------------------
  509|  41.6k|        ctx->scratch_buffer_len = 4*ctx->max_col_width+1;
  510|  41.6k|        ctx->scratch_buffer = readstat_realloc(ctx->scratch_buffer, ctx->scratch_buffer_len);
  511|  41.6k|        if (ctx->scratch_buffer == NULL) {
  ------------------
  |  Branch (511:13): [True: 4, False: 41.6k]
  ------------------
  512|      4|            retval = READSTAT_ERROR_MALLOC;
  513|      4|            goto cleanup;
  514|      4|        }
  515|       |
  516|  19.5M|        for (j=0; j<ctx->column_count; j++) {
  ------------------
  |  Branch (516:19): [True: 19.5M, False: 41.5k]
  ------------------
  517|  19.5M|            col_info_t *col_info = &ctx->col_info[j];
  518|  19.5M|            readstat_variable_t *variable = ctx->variables[j];
  519|  19.5M|            if (variable->skip)
  ------------------
  |  Branch (519:17): [True: 0, False: 19.5M]
  ------------------
  520|      0|                continue;
  521|       |
  522|  19.5M|            if (col_info->offset > ctx->row_length || col_info->offset + col_info->width > ctx->row_length) {
  ------------------
  |  Branch (522:17): [True: 94, False: 19.5M]
  |  Branch (522:55): [True: 23, False: 19.5M]
  ------------------
  523|    117|                retval = READSTAT_ERROR_PARSE;
  524|    117|                goto cleanup;
  525|    117|            }
  526|  19.5M|            retval = sas7bdat_handle_data_value(variable, col_info, &data[col_info->offset], ctx);
  527|  19.5M|            if (retval != READSTAT_OK) {
  ------------------
  |  Branch (527:17): [True: 15, False: 19.5M]
  ------------------
  528|     15|                goto cleanup;
  529|     15|            }
  530|  19.5M|        }
  531|  41.6k|    }
  532|  41.5k|    ctx->parsed_row_count++;
  533|       |
  534|  41.6k|cleanup:
  535|  41.6k|    return retval;
  536|  41.5k|}
readstat_sas7bdat_read.c:sas7bdat_handle_data_value:
  435|  19.5M|        col_info_t *col_info, const char *col_data, sas7bdat_ctx_t *ctx) {
  436|  19.5M|    readstat_error_t retval = READSTAT_OK;
  437|  19.5M|    int cb_retval = 0;
  438|  19.5M|    readstat_value_t value;
  439|  19.5M|    memset(&value, 0, sizeof(readstat_value_t));
  440|       |
  441|  19.5M|    value.type = col_info->type;
  442|       |
  443|  19.5M|    if (col_info->type == READSTAT_TYPE_STRING) {
  ------------------
  |  Branch (443:9): [True: 19.3M, False: 134k]
  ------------------
  444|  19.3M|        retval = readstat_convert(ctx->scratch_buffer, ctx->scratch_buffer_len,
  445|  19.3M|                col_data, col_info->width, ctx->converter);
  446|  19.3M|        if (retval != READSTAT_OK) {
  ------------------
  |  Branch (446:13): [True: 13, False: 19.3M]
  ------------------
  447|     13|            if (ctx->handle.error) {
  ------------------
  |  Branch (447:17): [True: 0, False: 13]
  ------------------
  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|     13|            goto cleanup;
  454|     13|        }
  455|       |
  456|  19.3M|        value.v.string_value = ctx->scratch_buffer;
  457|  19.3M|    } else if (col_info->type == READSTAT_TYPE_DOUBLE) {
  ------------------
  |  Branch (457:16): [True: 134k, False: 0]
  ------------------
  458|   134k|        uint64_t  val = 0;
  459|   134k|        double dval = NAN;
  460|   134k|        if (col_info->width < 1 || col_info->width > 8) {
  ------------------
  |  Branch (460:13): [True: 1, False: 134k]
  |  Branch (460:36): [True: 1, False: 134k]
  ------------------
  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|      2|            retval = READSTAT_ERROR_PARSE;
  465|      2|            goto cleanup;
  466|      2|        }
  467|   134k|        if (ctx->little_endian) {
  ------------------
  |  Branch (467:13): [True: 134k, False: 0]
  ------------------
  468|   134k|            int k;
  469|   922k|            for (k=0; k<col_info->width; k++) {
  ------------------
  |  Branch (469:23): [True: 787k, False: 134k]
  ------------------
  470|   787k|                val = (val << 8) | (unsigned char)col_data[col_info->width-1-k];
  471|   787k|            }
  472|   134k|        } 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|   134k|        val <<= (8-col_info->width)*8;
  479|       |
  480|   134k|        memcpy(&dval, &val, 8);
  481|       |
  482|   134k|        if (isnan(dval)) {
  ------------------
  |  Branch (482:13): [True: 8.56k, False: 126k]
  ------------------
  483|  8.56k|            value.v.double_value = NAN;
  484|  8.56k|            sas_assign_tag(&value, ~((val >> 40) & 0xFF));
  485|   126k|        } else {
  486|   126k|            value.v.double_value = dval;
  487|   126k|        }
  488|   134k|    }
  489|  19.5M|    cb_retval = ctx->handle.value(ctx->parsed_row_count, variable, value, ctx->user_ctx);
  490|       |
  491|  19.5M|    if (cb_retval != READSTAT_HANDLER_OK)
  ------------------
  |  Branch (491:9): [True: 0, False: 19.5M]
  ------------------
  492|      0|        retval = READSTAT_ERROR_USER_ABORT;
  493|       |
  494|  19.5M|cleanup:
  495|  19.5M|    return retval;
  496|  19.5M|}
readstat_sas7bdat_read.c:sas7bdat_parse_subheader_compressed:
  689|  1.77k|static readstat_error_t sas7bdat_parse_subheader_compressed(const char *subheader, size_t len, sas7bdat_ctx_t *ctx) {
  690|  1.77k|    if (ctx->rdc_compression)
  ------------------
  |  Branch (690:9): [True: 408, False: 1.36k]
  ------------------
  691|    408|        return sas7bdat_parse_subheader_rdc(subheader, len, ctx);
  692|       |
  693|  1.36k|    return sas7bdat_parse_subheader_rle(subheader, len, ctx);
  694|  1.77k|}
readstat_sas7bdat_read.c:sas7bdat_parse_subheader_rdc:
  575|    408|static readstat_error_t sas7bdat_parse_subheader_rdc(const char *subheader, size_t len, sas7bdat_ctx_t *ctx) {
  576|    408|    readstat_error_t retval = READSTAT_OK;
  577|    408|    const unsigned char *input = (const unsigned char *)subheader;
  578|    408|    char *buffer = malloc(ctx->row_length);
  579|    408|    if (buffer == NULL) return READSTAT_ERROR_MALLOC;
  ------------------
  |  Branch (579:9): [True: 0, False: 408]
  ------------------
  580|    408|    char *output = buffer;
  581|  1.63k|    while (input + 2 <= (const unsigned char *)subheader + len) {
  ------------------
  |  Branch (581:12): [True: 1.26k, False: 367]
  ------------------
  582|  1.26k|        int i;
  583|  1.26k|        unsigned short prefix = (input[0] << 8) + input[1];
  584|  1.26k|        input += 2;
  585|  16.7k|        for (i=0; i<16; i++) {
  ------------------
  |  Branch (585:19): [True: 15.9k, False: 857]
  ------------------
  586|  15.9k|            if ((prefix & (1 << (15 - i))) == 0) {
  ------------------
  |  Branch (586:17): [True: 12.5k, False: 3.34k]
  ------------------
  587|  12.5k|                if (input + 1 > (const unsigned char *)subheader + len) {
  ------------------
  |  Branch (587:21): [True: 365, False: 12.2k]
  ------------------
  588|    365|                    break;
  589|    365|                }
  590|  12.2k|                if (output + 1 > buffer + ctx->row_length) {
  ------------------
  |  Branch (590:21): [True: 4, False: 12.1k]
  ------------------
  591|      4|                    retval = READSTAT_ERROR_ROW_WIDTH_MISMATCH;
  592|      4|                    goto cleanup;
  593|      4|                }
  594|  12.1k|                *output++ = *input++;
  595|  12.1k|                continue;
  596|  12.2k|            }
  597|       |
  598|  3.34k|            if (input + 2 > (const unsigned char *)subheader + len) {
  ------------------
  |  Branch (598:17): [True: 1, False: 3.34k]
  ------------------
  599|      1|                retval = READSTAT_ERROR_PARSE;
  600|      1|                goto cleanup;
  601|      1|            }
  602|       |
  603|  3.34k|            unsigned char marker_byte = *input++;
  604|  3.34k|            unsigned char next_byte = *input++;
  605|  3.34k|            size_t insert_len = 0, copy_len = 0;
  606|  3.34k|            unsigned char insert_byte = 0x00;
  607|  3.34k|            size_t back_offset = 0;
  608|       |
  609|  3.34k|            if (marker_byte <= 0x0F) {
  ------------------
  |  Branch (609:17): [True: 1.54k, False: 1.80k]
  ------------------
  610|  1.54k|                insert_len = 3 + marker_byte;
  611|  1.54k|                insert_byte = next_byte;
  612|  1.80k|            } else if ((marker_byte >> 4) == 1) {
  ------------------
  |  Branch (612:24): [True: 534, False: 1.26k]
  ------------------
  613|    534|                if (input + 1 > (const unsigned char *)subheader + len) {
  ------------------
  |  Branch (613:21): [True: 2, False: 532]
  ------------------
  614|      2|                    retval = READSTAT_ERROR_PARSE;
  615|      2|                    goto cleanup;
  616|      2|                }
  617|    532|                insert_len = 19 + (marker_byte & 0x0F) + next_byte * 16;
  618|    532|                insert_byte = *input++;
  619|  1.26k|            } else if ((marker_byte >> 4) == 2) {
  ------------------
  |  Branch (619:24): [True: 330, False: 938]
  ------------------
  620|    330|                if (input + 1 > (const unsigned char *)subheader + len) {
  ------------------
  |  Branch (620:21): [True: 1, False: 329]
  ------------------
  621|      1|                    retval = READSTAT_ERROR_PARSE;
  622|      1|                    goto cleanup;
  623|      1|                }
  624|    329|                copy_len = 16 + (*input++);
  625|    329|                back_offset = 3 + (marker_byte & 0x0F) + next_byte * 16;
  626|    938|            } else {
  627|    938|                copy_len = (marker_byte >> 4);
  628|    938|                back_offset = 3 + (marker_byte & 0x0F) + next_byte * 16;
  629|    938|            }
  630|       |
  631|  3.34k|            if (insert_len) {
  ------------------
  |  Branch (631:17): [True: 2.07k, False: 1.26k]
  ------------------
  632|  2.07k|                if (output + insert_len > buffer + ctx->row_length) {
  ------------------
  |  Branch (632:21): [True: 2, False: 2.07k]
  ------------------
  633|      2|                    retval = READSTAT_ERROR_ROW_WIDTH_MISMATCH;
  634|      2|                    goto cleanup;
  635|      2|                }
  636|  2.07k|                memset(output, insert_byte, insert_len);
  637|  2.07k|                output += insert_len;
  638|  2.07k|            } else if (copy_len) {
  ------------------
  |  Branch (638:24): [True: 1.26k, False: 0]
  ------------------
  639|  1.26k|                if (output - buffer < back_offset || copy_len > back_offset) {
  ------------------
  |  Branch (639:21): [True: 11, False: 1.25k]
  |  Branch (639:54): [True: 18, False: 1.23k]
  ------------------
  640|     29|                    retval = READSTAT_ERROR_PARSE;
  641|     29|                    goto cleanup;
  642|     29|                }
  643|  1.23k|                if (output + copy_len > buffer + ctx->row_length) {
  ------------------
  |  Branch (643:21): [True: 2, False: 1.23k]
  ------------------
  644|      2|                    retval = READSTAT_ERROR_ROW_WIDTH_MISMATCH;
  645|      2|                    goto cleanup;
  646|      2|                }
  647|  1.23k|                memcpy(output, output - back_offset, copy_len);
  648|  1.23k|                output += copy_len;
  649|  1.23k|            }
  650|  3.34k|        }
  651|  1.26k|    }
  652|       |
  653|    367|    if (output - buffer != ctx->row_length) {
  ------------------
  |  Branch (653:9): [True: 6, False: 361]
  ------------------
  654|      6|        retval = READSTAT_ERROR_ROW_WIDTH_MISMATCH;
  655|      6|        goto cleanup;
  656|      6|    }
  657|    361|    retval = sas7bdat_parse_single_row(buffer, ctx);
  658|    408|cleanup:
  659|    408|    free(buffer);
  660|       |
  661|    408|    return retval;
  662|    361|}
readstat_sas7bdat_read.c:sas7bdat_parse_subheader_rle:
  664|  1.36k|static readstat_error_t sas7bdat_parse_subheader_rle(const char *subheader, size_t len, sas7bdat_ctx_t *ctx) {
  665|  1.36k|    if (ctx->row_limit == ctx->parsed_row_count)
  ------------------
  |  Branch (665:9): [True: 734, False: 630]
  ------------------
  666|    734|        return READSTAT_OK;
  667|       |
  668|    630|    readstat_error_t retval = READSTAT_OK;
  669|    630|    ssize_t bytes_decompressed = 0;
  670|       |
  671|    630|    bytes_decompressed = sas_rle_decompress(ctx->row, ctx->row_length, subheader, len);
  672|       |
  673|    630|    if (bytes_decompressed != ctx->row_length) {
  ------------------
  |  Branch (673:9): [True: 143, False: 487]
  ------------------
  674|    143|        retval = READSTAT_ERROR_ROW_WIDTH_MISMATCH;
  675|    143|        if (ctx->handle.error) {
  ------------------
  |  Branch (675:13): [True: 0, False: 143]
  ------------------
  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|    143|        goto cleanup;
  682|    143|    }
  683|    487|    retval = sas7bdat_parse_single_row(ctx->row, ctx);
  684|       |
  685|    630|cleanup:
  686|    630|    return retval;
  687|    487|}
readstat_sas7bdat_read.c:sas7bdat_register_deleted_row:
  426|    870|static readstat_error_t sas7bdat_register_deleted_row(sas7bdat_ctx_t *ctx) {
  427|    870|    if (ctx->parsed_deleted_row_count >= ctx->deleted_row_count) {
  ------------------
  |  Branch (427:9): [True: 3, False: 867]
  ------------------
  428|      3|        return READSTAT_ERROR_PARSE;
  429|      3|    }
  430|    867|    ctx->parsed_deleted_row_count++;
  431|    867|    return READSTAT_OK;
  432|    870|}
readstat_sas7bdat_read.c:sas7bdat_parse_deleted_row_bitmap:
 1053|    229|        sas7bdat_ctx_t *ctx) {
 1054|    229|    uint64_t page_unused_bytes;
 1055|    229|    if (ctx->u64) {
  ------------------
  |  Branch (1055:9): [True: 113, False: 116]
  ------------------
 1056|    113|        page_unused_bytes = sas_read8(&page[24], ctx->bswap);
 1057|    116|    } else {
 1058|    116|        page_unused_bytes = sas_read4(&page[12], ctx->bswap);
 1059|    116|    }
 1060|    229|    uint32_t row_count = ctx->page_row_count < ctx->total_row_count ? ctx->page_row_count : ctx->total_row_count;
  ------------------
  |  Branch (1060:26): [True: 125, False: 104]
  ------------------
 1061|    229|    uint64_t deleted_row_bitmap_offset = (uint64_t)row_count * ctx->row_length + page_unused_bytes;
 1062|    229|    uint32_t required_bytes = row_count / CHAR_BIT + (row_count % CHAR_BIT == 0 ? 0 : 1);
  ------------------
  |  Branch (1062:55): [True: 153, False: 76]
  ------------------
 1063|       |
 1064|    229|    if ((data - page) + deleted_row_bitmap_offset + required_bytes > page_size) {
  ------------------
  |  Branch (1064:9): [True: 118, False: 111]
  ------------------
 1065|    118|        return READSTAT_ERROR_PARSE;
 1066|    118|    }
 1067|    111|    *deleted_row_bitmap = (const unsigned char *)data + deleted_row_bitmap_offset;
 1068|    111|    *deleted_row_bitmap_row_count = row_count;
 1069|    111|    return READSTAT_OK;
 1070|    229|}
readstat_sas7bdat_read.c:sas7bdat_parse_rows:
  546|    825|        const unsigned char *deleted_bitmap, uint32_t deleted_bitmap_row_count, sas7bdat_ctx_t *ctx) {
  547|    825|    readstat_error_t retval = READSTAT_OK;
  548|    825|    uint32_t i;
  549|    825|    size_t row_offset=0;
  550|  42.2k|    for (i=0; i<ctx->page_row_count && ctx->parsed_row_count < ctx->row_limit; i++) {
  ------------------
  |  Branch (550:15): [True: 41.7k, False: 443]
  |  Branch (550:40): [True: 41.5k, False: 198]
  ------------------
  551|  41.5k|        if (row_offset + ctx->row_length > len) {
  ------------------
  |  Branch (551:13): [True: 95, False: 41.4k]
  ------------------
  552|     95|            retval = READSTAT_ERROR_ROW_WIDTH_MISMATCH;
  553|     95|            goto cleanup;
  554|     95|        }
  555|  41.4k|        if (deleted_bitmap != NULL && i >= deleted_bitmap_row_count) {
  ------------------
  |  Branch (555:13): [True: 2.46k, False: 38.9k]
  |  Branch (555:39): [True: 2, False: 2.46k]
  ------------------
  556|       |            /* The page claims more rows than the deleted-row bitmap covers */
  557|      2|            retval = READSTAT_ERROR_PARSE;
  558|      2|            goto cleanup;
  559|      2|        }
  560|  41.4k|        if (deleted_bitmap != NULL && sas7bdat_read_bitmap(deleted_bitmap, i)) {
  ------------------
  |  Branch (560:13): [True: 2.46k, False: 38.9k]
  |  Branch (560:39): [True: 754, False: 1.71k]
  ------------------
  561|    754|            if ((retval = sas7bdat_register_deleted_row(ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (561:17): [True: 1, False: 753]
  ------------------
  562|      1|                goto cleanup;
  563|      1|            }
  564|  40.7k|        } else if ((retval = sas7bdat_parse_single_row(&data[row_offset], ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (564:20): [True: 86, False: 40.6k]
  ------------------
  565|     86|            goto cleanup;
  566|     86|        }
  567|       |
  568|  41.3k|        row_offset += ctx->row_length;
  569|  41.3k|    }
  570|       |
  571|    825|cleanup:
  572|    825|    return retval;
  573|    825|}
readstat_sas7bdat_read.c:sas7bdat_read_bitmap:
  538|  2.46k|static unsigned char sas7bdat_read_bitmap(const unsigned char *bitmap, int index) {
  539|  2.46k|    unsigned char current_byte = bitmap[index / CHAR_BIT];
  540|  2.46k|    unsigned char mask = 1 << (CHAR_BIT - 1 - index % CHAR_BIT);
  541|       |
  542|  2.46k|    return current_byte & mask;
  543|  2.46k|}
readstat_sas7bdat_read.c:sas7bdat_submit_columns_if_needed:
  876|  3.69k|static readstat_error_t sas7bdat_submit_columns_if_needed(sas7bdat_ctx_t *ctx, int compressed) {
  877|  3.69k|    readstat_error_t retval = READSTAT_OK;
  878|  3.69k|    if (!ctx->did_submit_columns) {
  ------------------
  |  Branch (878:9): [True: 1.12k, False: 2.57k]
  ------------------
  879|  1.12k|        if ((retval = sas7bdat_submit_columns(ctx, compressed)) != READSTAT_OK) {
  ------------------
  |  Branch (879:13): [True: 234, False: 887]
  ------------------
  880|    234|            goto cleanup;
  881|    234|        }
  882|    887|        ctx->did_submit_columns = 1;
  883|    887|    }
  884|  3.69k|cleanup:
  885|  3.69k|    return retval;
  886|  3.69k|}
readstat_sas7bdat_read.c:sas7bdat_submit_columns:
  815|  1.12k|static readstat_error_t sas7bdat_submit_columns(sas7bdat_ctx_t *ctx, int compressed) {
  816|  1.12k|    readstat_error_t retval = READSTAT_OK;
  817|  1.12k|    if (ctx->handle.metadata) {
  ------------------
  |  Branch (817:9): [True: 1.12k, False: 0]
  ------------------
  818|  1.12k|        readstat_metadata_t metadata = {
  819|  1.12k|            .row_count = ctx->row_limit,
  820|  1.12k|            .var_count = ctx->column_count,
  821|  1.12k|            .table_name = ctx->table_name,
  822|  1.12k|            .file_label = ctx->file_label,
  823|  1.12k|            .file_encoding = ctx->input_encoding, /* orig encoding? */
  824|  1.12k|            .creation_time = ctx->ctime,
  825|  1.12k|            .modified_time = ctx->mtime,
  826|  1.12k|            .file_format_version = ctx->version,
  827|  1.12k|            .compression = READSTAT_COMPRESS_NONE,
  828|  1.12k|            .endianness = ctx->little_endian ? READSTAT_ENDIAN_LITTLE : READSTAT_ENDIAN_BIG,
  ------------------
  |  Branch (828:27): [True: 280, False: 841]
  ------------------
  829|  1.12k|            .is64bit = ctx->u64
  830|  1.12k|        };
  831|  1.12k|        if (compressed) {
  ------------------
  |  Branch (831:13): [True: 472, False: 649]
  ------------------
  832|    472|            if (ctx->rdc_compression) {
  ------------------
  |  Branch (832:17): [True: 44, False: 428]
  ------------------
  833|     44|                metadata.compression = READSTAT_COMPRESS_BINARY;
  834|    428|            } else {
  835|    428|                metadata.compression = READSTAT_COMPRESS_ROWS;
  836|    428|            }
  837|    472|        }
  838|  1.12k|        if (ctx->handle.metadata(&metadata, ctx->user_ctx) != READSTAT_HANDLER_OK) {
  ------------------
  |  Branch (838:13): [True: 0, False: 1.12k]
  ------------------
  839|      0|            retval = READSTAT_ERROR_USER_ABORT;
  840|      0|            goto cleanup;
  841|      0|        }
  842|  1.12k|    }
  843|  1.12k|    if (ctx->column_count == 0)
  ------------------
  |  Branch (843:9): [True: 670, False: 451]
  ------------------
  844|    670|        goto cleanup;
  845|       |
  846|    451|    if ((ctx->variables = readstat_calloc(ctx->column_count, sizeof(readstat_variable_t *))) == NULL) {
  ------------------
  |  Branch (846:9): [True: 0, False: 451]
  ------------------
  847|      0|        retval = READSTAT_ERROR_MALLOC;
  848|      0|        goto cleanup;
  849|      0|    }
  850|    451|    int i;
  851|    451|    int index_after_skipping = 0;
  852|  1.90M|    for (i=0; i<ctx->column_count; i++) {
  ------------------
  |  Branch (852:15): [True: 1.90M, False: 217]
  ------------------
  853|  1.90M|        ctx->variables[i] = sas7bdat_init_variable(ctx, i, index_after_skipping, &retval);
  854|  1.90M|        if (ctx->variables[i] == NULL)
  ------------------
  |  Branch (854:13): [True: 234, False: 1.90M]
  ------------------
  855|    234|            break;
  856|       |
  857|  1.90M|        int cb_retval = READSTAT_HANDLER_OK;
  858|  1.90M|        if (ctx->handle.variable) {
  ------------------
  |  Branch (858:13): [True: 1.90M, False: 0]
  ------------------
  859|  1.90M|            cb_retval = ctx->handle.variable(i, ctx->variables[i], ctx->variables[i]->format, ctx->user_ctx);
  860|  1.90M|        }
  861|  1.90M|        if (cb_retval == READSTAT_HANDLER_ABORT) {
  ------------------
  |  Branch (861:13): [True: 0, False: 1.90M]
  ------------------
  862|      0|            retval = READSTAT_ERROR_USER_ABORT;
  863|      0|            goto cleanup;
  864|      0|        }
  865|       |
  866|  1.90M|        if (cb_retval == READSTAT_HANDLER_SKIP_VARIABLE) {
  ------------------
  |  Branch (866:13): [True: 0, False: 1.90M]
  ------------------
  867|      0|            ctx->variables[i]->skip = 1;
  868|  1.90M|        } else {
  869|  1.90M|            index_after_skipping++;
  870|  1.90M|        }
  871|  1.90M|    }
  872|  1.12k|cleanup:
  873|  1.12k|    return retval;
  874|    451|}
readstat_sas7bdat_read.c:sas7bdat_init_variable:
  762|  1.90M|        int index_after_skipping, readstat_error_t *out_retval) {
  763|  1.90M|    readstat_error_t retval = READSTAT_OK;
  764|  1.90M|    readstat_variable_t *variable = readstat_calloc(1, sizeof(readstat_variable_t));
  765|       |
  766|  1.90M|    variable->index = i;
  767|  1.90M|    variable->index_after_skipping = index_after_skipping;
  768|  1.90M|    variable->type = ctx->col_info[i].type;
  769|  1.90M|    variable->storage_width = ctx->col_info[i].width;
  770|       |
  771|  1.90M|    if ((retval = sas7bdat_validate_column(&ctx->col_info[i])) != READSTAT_OK) {
  ------------------
  |  Branch (771:9): [True: 62, False: 1.90M]
  ------------------
  772|     62|        goto cleanup;
  773|     62|    }
  774|  1.90M|    if ((retval = sas7bdat_copy_text_ref(variable->name, sizeof(variable->name), 
  ------------------
  |  Branch (774:9): [True: 47, False: 1.90M]
  ------------------
  775|  1.90M|                    ctx->col_info[i].name_ref, ctx)) != READSTAT_OK) {
  776|     47|        goto cleanup;
  777|     47|    }
  778|  1.90M|    if ((retval = sas7bdat_construct_format(variable->format, sizeof(variable->format),
  ------------------
  |  Branch (778:9): [True: 44, False: 1.90M]
  ------------------
  779|  1.90M|                    ctx->col_info[i].format_ref, ctx->col_info[i].format_width,
  780|  1.90M|                    ctx->col_info[i].format_digits, ctx)) != READSTAT_OK) {
  781|     44|        goto cleanup;
  782|     44|    }
  783|  1.90M|    if ((retval = sas7bdat_construct_format(variable->informat, sizeof(variable->informat),
  ------------------
  |  Branch (783:9): [True: 69, False: 1.90M]
  ------------------
  784|  1.90M|                    ctx->col_info[i].informat_ref, ctx->col_info[i].informat_width,
  785|  1.90M|                    ctx->col_info[i].informat_digits, ctx)) != READSTAT_OK) {
  786|     69|        goto cleanup;
  787|     69|    }
  788|  1.90M|    if ((retval = sas7bdat_copy_text_ref(variable->label, sizeof(variable->label), 
  ------------------
  |  Branch (788:9): [True: 12, False: 1.90M]
  ------------------
  789|  1.90M|                    ctx->col_info[i].label_ref, ctx)) != READSTAT_OK) {
  790|     12|        goto cleanup;
  791|     12|    }
  792|       |
  793|  1.90M|cleanup:
  794|  1.90M|    if (retval != READSTAT_OK) {
  ------------------
  |  Branch (794:9): [True: 234, False: 1.90M]
  ------------------
  795|    234|        if (out_retval)
  ------------------
  |  Branch (795:13): [True: 234, False: 0]
  ------------------
  796|    234|            *out_retval = retval;
  797|       |
  798|    234|        if (retval == READSTAT_ERROR_CONVERT_BAD_STRING) {
  ------------------
  |  Branch (798:13): [True: 9, False: 225]
  ------------------
  799|      9|            if (ctx->handle.error) {
  ------------------
  |  Branch (799:17): [True: 0, False: 9]
  ------------------
  800|      0|                snprintf(ctx->error_buf, sizeof(ctx->error_buf),
  801|      0|                        "ReadStat: Error converting variable #%d info to specified encoding: %s %s (%s)",
  802|      0|                        i, variable->name, variable->format, variable->label);
  803|      0|                ctx->handle.error(ctx->error_buf, ctx->user_ctx);
  804|      0|            }
  805|      9|        }
  806|       |
  807|    234|        free(variable);
  808|       |
  809|    234|        return NULL;
  810|    234|    }
  811|       |
  812|  1.90M|    return variable;
  813|  1.90M|}
readstat_sas7bdat_read.c:sas7bdat_validate_column:
  731|  1.90M|static readstat_error_t sas7bdat_validate_column(col_info_t *col_info) {
  732|  1.90M|    if (col_info->type == READSTAT_TYPE_DOUBLE) {
  ------------------
  |  Branch (732:9): [True: 772, False: 1.90M]
  ------------------
  733|    772|        if (col_info->width > 8 || col_info->width < 3) {
  ------------------
  |  Branch (733:13): [True: 39, False: 733]
  |  Branch (733:36): [True: 2, False: 731]
  ------------------
  734|     41|            return READSTAT_ERROR_PARSE;
  735|     41|        }
  736|    772|    }
  737|  1.90M|    if (col_info->type == READSTAT_TYPE_STRING) {
  ------------------
  |  Branch (737:9): [True: 1.90M, False: 731]
  ------------------
  738|  1.90M|        if (col_info->width > INT16_MAX) {
  ------------------
  |  Branch (738:13): [True: 21, False: 1.90M]
  ------------------
  739|     21|            return READSTAT_ERROR_PARSE;
  740|     21|        }
  741|  1.90M|    }
  742|  1.90M|    return READSTAT_OK;
  743|  1.90M|}
readstat_sas7bdat_read.c:sas7bdat_construct_format:
  746|  3.80M|        sas_text_ref_t text_ref, int width, int digits, sas7bdat_ctx_t *ctx) {
  747|  3.80M|    readstat_error_t retval = sas7bdat_copy_text_ref(dst, dst_len, text_ref, ctx);
  748|  3.80M|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (748:9): [True: 113, False: 3.80M]
  ------------------
  749|    113|        return retval;
  750|       |
  751|  3.80M|    size_t len = strlen(dst);
  752|  3.80M|    if (width) {
  ------------------
  |  Branch (752:9): [True: 333, False: 3.80M]
  ------------------
  753|    333|        len += snprintf(dst + len, dst_len - len, "%d", width);
  754|    333|    }
  755|  3.80M|    if (len && digits) {
  ------------------
  |  Branch (755:9): [True: 368, False: 3.80M]
  |  Branch (755:16): [True: 261, False: 107]
  ------------------
  756|    261|        len += snprintf(dst + len, dst_len - len, ".%d", digits);
  757|    261|    }
  758|  3.80M|    return READSTAT_OK;
  759|  3.80M|}
readstat_sas7bdat_read.c:sas7bdat_update_progress:
  141|  3.18k|static readstat_error_t sas7bdat_update_progress(sas7bdat_ctx_t *ctx) {
  142|  3.18k|    readstat_io_t *io = ctx->io;
  143|  3.18k|    return io->update(ctx->file_size, ctx->handle.progress, ctx->user_ctx, io->io_ctx);
  144|  3.18k|}
readstat_sas7bdat_read.c:sas7bdat_ctx_free:
  104|  3.67k|static void sas7bdat_ctx_free(sas7bdat_ctx_t *ctx) {
  105|  3.67k|    int i;
  106|  3.67k|    if (ctx->text_blobs) {
  ------------------
  |  Branch (106:9): [True: 867, False: 2.80k]
  ------------------
  107|  3.47k|        for (i=0; i<ctx->text_blob_count; i++) {
  ------------------
  |  Branch (107:19): [True: 2.61k, False: 867]
  ------------------
  108|  2.61k|            free(ctx->text_blobs[i]);
  109|  2.61k|        }
  110|    867|        free(ctx->text_blobs);
  111|    867|        free(ctx->text_blob_lengths);
  112|    867|    }
  113|  3.67k|    if (ctx->variables) {
  ------------------
  |  Branch (113:9): [True: 451, False: 3.22k]
  ------------------
  114|  11.5M|        for (i=0; i<ctx->column_count; i++) {
  ------------------
  |  Branch (114:19): [True: 11.5M, False: 451]
  ------------------
  115|  11.5M|            if (ctx->variables[i])
  ------------------
  |  Branch (115:17): [True: 1.90M, False: 9.61M]
  ------------------
  116|  1.90M|                free(ctx->variables[i]);
  117|  11.5M|        }
  118|    451|        free(ctx->variables);
  119|    451|    }
  120|  3.67k|    if (ctx->col_info)
  ------------------
  |  Branch (120:9): [True: 600, False: 3.07k]
  ------------------
  121|    600|        free(ctx->col_info);
  122|       |
  123|  3.67k|    if (ctx->scratch_buffer)
  ------------------
  |  Branch (123:9): [True: 349, False: 3.32k]
  ------------------
  124|    349|        free(ctx->scratch_buffer);
  125|       |
  126|  3.67k|    if (ctx->page)
  ------------------
  |  Branch (126:9): [True: 3.16k, False: 514]
  ------------------
  127|  3.16k|        free(ctx->page);
  128|       |
  129|  3.67k|    if (ctx->moved_page)
  ------------------
  |  Branch (129:9): [True: 0, False: 3.67k]
  ------------------
  130|      0|        free(ctx->moved_page);
  131|       |
  132|  3.67k|    if (ctx->row)
  ------------------
  |  Branch (132:9): [True: 791, False: 2.88k]
  ------------------
  133|    791|        free(ctx->row);
  134|       |
  135|  3.67k|    if (ctx->converter)
  ------------------
  |  Branch (135:9): [True: 2.10k, False: 1.57k]
  ------------------
  136|  2.10k|        iconv_close(ctx->converter);
  137|       |
  138|  3.67k|    free(ctx);
  139|  3.67k|}

sas_rle_decompress:
   47|    630|        const void *input_buf, size_t input_len) {
   48|    630|    unsigned char *buffer = (unsigned char *)output_buf;
   49|    630|    unsigned char *output = buffer;
   50|    630|    size_t output_written = 0;
   51|       |
   52|    630|    const unsigned char *input = (const unsigned char *)input_buf;
   53|       |
   54|  55.7k|    while (input < (const unsigned char *)input_buf + input_len) {
  ------------------
  |  Branch (54:12): [True: 55.2k, False: 507]
  ------------------
   55|  55.2k|        unsigned char control = *input++;
   56|  55.2k|        unsigned char command = (control & 0xF0) >> 4;
   57|  55.2k|        unsigned char length = (control & 0x0F);
   58|  55.2k|        int copy_len = 0;
   59|  55.2k|        int insert_len = 0;
   60|  55.2k|        unsigned char insert_byte = '\0';
   61|  55.2k|        if (input + command_lengths[command] > (const unsigned char *)input_buf + input_len) {
  ------------------
  |  Branch (61:13): [True: 4, False: 55.2k]
  ------------------
   62|      4|            return -1;
   63|      4|        }
   64|  55.2k|        switch (command) {
   65|  5.85k|            case SAS_RLE_COMMAND_COPY64:
  ------------------
  |  |   13|  5.85k|#define SAS_RLE_COMMAND_COPY64          0
  ------------------
  |  Branch (65:13): [True: 5.85k, False: 49.3k]
  ------------------
   66|  5.85k|                copy_len = (*input++) + 64 + length * 256;
   67|  5.85k|                break;
   68|    163|            case SAS_RLE_COMMAND_COPY64_PLUS_4096:
  ------------------
  |  |   14|    163|#define SAS_RLE_COMMAND_COPY64_PLUS_4096 1
  ------------------
  |  Branch (68:13): [True: 163, False: 55.0k]
  ------------------
   69|    163|                copy_len = (*input++) + 64 + length * 256 + 4096;
   70|    163|                break;
   71|    414|            case SAS_RLE_COMMAND_COPY96: copy_len = length + 96; break;
  ------------------
  |  |   15|    414|#define SAS_RLE_COMMAND_COPY96          2
  ------------------
  |  Branch (71:13): [True: 414, False: 54.8k]
  ------------------
   72|    659|            case SAS_RLE_COMMAND_INSERT_BYTE18:
  ------------------
  |  |   16|    659|#define SAS_RLE_COMMAND_INSERT_BYTE18   4
  ------------------
  |  Branch (72:13): [True: 659, False: 54.5k]
  ------------------
   73|    659|                insert_len = (*input++) + 18 + length * 256;
   74|    659|                insert_byte = *input++;
   75|    659|                break;
   76|  1.72k|            case SAS_RLE_COMMAND_INSERT_AT17:
  ------------------
  |  |   17|  1.72k|#define SAS_RLE_COMMAND_INSERT_AT17     5
  ------------------
  |  Branch (76:13): [True: 1.72k, False: 53.5k]
  ------------------
   77|  1.72k|                insert_len = (*input++) + 17 + length * 256;
   78|  1.72k|                insert_byte = '@';
   79|  1.72k|                break;
   80|  1.30k|            case SAS_RLE_COMMAND_INSERT_BLANK17:
  ------------------
  |  |   18|  1.30k|#define SAS_RLE_COMMAND_INSERT_BLANK17  6
  ------------------
  |  Branch (80:13): [True: 1.30k, False: 53.9k]
  ------------------
   81|  1.30k|                insert_len = (*input++) + 17 + length * 256;
   82|  1.30k|                insert_byte = ' ';
   83|  1.30k|                break;
   84|  3.28k|            case SAS_RLE_COMMAND_INSERT_ZERO17:
  ------------------
  |  |   19|  3.28k|#define SAS_RLE_COMMAND_INSERT_ZERO17   7
  ------------------
  |  Branch (84:13): [True: 3.28k, False: 51.9k]
  ------------------
   85|  3.28k|                insert_len = (*input++) + 17 + length * 256;
   86|  3.28k|                insert_byte = '\0';
   87|  3.28k|                break;
   88|  1.69k|            case SAS_RLE_COMMAND_COPY1:  copy_len = length + 1; break;
  ------------------
  |  |   20|  1.69k|#define SAS_RLE_COMMAND_COPY1           8
  ------------------
  |  Branch (88:13): [True: 1.69k, False: 53.5k]
  ------------------
   89|  13.3k|            case SAS_RLE_COMMAND_COPY17: copy_len = length + 17; break;
  ------------------
  |  |   21|  13.3k|#define SAS_RLE_COMMAND_COPY17          9
  ------------------
  |  Branch (89:13): [True: 13.3k, False: 41.8k]
  ------------------
   90|  1.11k|            case SAS_RLE_COMMAND_COPY33: copy_len = length + 33; break;
  ------------------
  |  |   22|  1.11k|#define SAS_RLE_COMMAND_COPY33         10
  ------------------
  |  Branch (90:13): [True: 1.11k, False: 54.1k]
  ------------------
   91|    440|            case SAS_RLE_COMMAND_COPY49: copy_len = length + 49; break;
  ------------------
  |  |   23|    440|#define SAS_RLE_COMMAND_COPY49         11
  ------------------
  |  Branch (91:13): [True: 440, False: 54.8k]
  ------------------
   92|  1.77k|            case SAS_RLE_COMMAND_INSERT_BYTE3:
  ------------------
  |  |   24|  1.77k|#define SAS_RLE_COMMAND_INSERT_BYTE3   12
  ------------------
  |  Branch (92:13): [True: 1.77k, False: 53.4k]
  ------------------
   93|  1.77k|                insert_byte = *input++;
   94|  1.77k|                insert_len = length + 3;
   95|  1.77k|                break;
   96|  1.81k|            case SAS_RLE_COMMAND_INSERT_AT2:
  ------------------
  |  |   25|  1.81k|#define SAS_RLE_COMMAND_INSERT_AT2     13
  ------------------
  |  Branch (96:13): [True: 1.81k, False: 53.4k]
  ------------------
   97|  1.81k|                insert_byte = '@';
   98|  1.81k|                insert_len = length + 2;
   99|  1.81k|                break;
  100|  10.5k|            case SAS_RLE_COMMAND_INSERT_BLANK2:
  ------------------
  |  |   26|  10.5k|#define SAS_RLE_COMMAND_INSERT_BLANK2  14
  ------------------
  |  Branch (100:13): [True: 10.5k, False: 44.6k]
  ------------------
  101|  10.5k|                insert_byte = ' ';
  102|  10.5k|                insert_len = length + 2;
  103|  10.5k|                break;
  104|  7.92k|            case SAS_RLE_COMMAND_INSERT_ZERO2:
  ------------------
  |  |   27|  7.92k|#define SAS_RLE_COMMAND_INSERT_ZERO2   15
  ------------------
  |  Branch (104:13): [True: 7.92k, False: 47.3k]
  ------------------
  105|  7.92k|                insert_byte = '\0';
  106|  7.92k|                insert_len = length + 2;
  107|  7.92k|                break;
  108|  3.15k|            default:
  ------------------
  |  Branch (108:13): [True: 3.15k, False: 52.0k]
  ------------------
  109|       |                /* error out here? */
  110|  3.15k|                break;
  111|  55.2k|        }
  112|  55.2k|        if (copy_len) {
  ------------------
  |  Branch (112:13): [True: 23.0k, False: 32.2k]
  ------------------
  113|  23.0k|            if (output_written + copy_len > output_len) {
  ------------------
  |  Branch (113:17): [True: 17, False: 23.0k]
  ------------------
  114|     17|                return -1;
  115|     17|            }
  116|  23.0k|            if (input + copy_len > (const unsigned char *)input_buf + input_len) {
  ------------------
  |  Branch (116:17): [True: 83, False: 22.9k]
  ------------------
  117|     83|                return -1;
  118|     83|            }
  119|  22.9k|            if (output) {
  ------------------
  |  Branch (119:17): [True: 22.9k, False: 0]
  ------------------
  120|  22.9k|                memcpy(&output[output_written], input, copy_len);
  121|  22.9k|            }
  122|  22.9k|            input += copy_len;
  123|  22.9k|            output_written += copy_len;
  124|  22.9k|        }
  125|  55.1k|        if (insert_len) {
  ------------------
  |  Branch (125:13): [True: 29.0k, False: 26.0k]
  ------------------
  126|  29.0k|            if (output_written + insert_len > output_len) {
  ------------------
  |  Branch (126:17): [True: 19, False: 29.0k]
  ------------------
  127|     19|                return -1;
  128|     19|            }
  129|  29.0k|            if (output) {
  ------------------
  |  Branch (129:17): [True: 29.0k, False: 0]
  ------------------
  130|  29.0k|                memset(&output[output_written], insert_byte, insert_len);
  131|  29.0k|            }
  132|  29.0k|            output_written += insert_len;
  133|  29.0k|        }
  134|  55.1k|    }
  135|       |
  136|    507|    return output_written;
  137|    630|}

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

