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.44k|static int handle_metadata(readstat_metadata_t *metadata, void *ctx) {
    9|  1.44k|    return READSTAT_HANDLER_OK;
   10|  1.44k|}
fuzz_format.c:handle_variable:
   21|  3.05M|                           const char *val_labels, void *ctx) {
   22|  3.05M|    return READSTAT_HANDLER_OK;
   23|  3.05M|}
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|  76.1k|uint16_t byteswap2(uint16_t num) {
   41|  76.1k|    return ((num & 0xFF00) >> 8) | ((num & 0x00FF) << 8);
   42|  76.1k|}
byteswap4:
   44|   165k|uint32_t byteswap4(uint32_t num) {
   45|   165k|    num = ((num & 0xFFFF0000) >> 16) | ((num & 0x0000FFFF) << 16);
   46|   165k|    return ((num & 0xFF00FF00) >> 8) | ((num & 0x00FF00FF) << 8);
   47|   165k|}
byteswap8:
   49|  71.2k|uint64_t byteswap8(uint64_t num) {
   50|  71.2k|    num = ((num & 0xFFFFFFFF00000000) >> 32) | ((num & 0x00000000FFFFFFFF) << 32);
   51|  71.2k|    num = ((num & 0xFFFF0000FFFF0000) >> 16) | ((num & 0x0000FFFF0000FFFF) << 16);
   52|  71.2k|    return ((num & 0xFF00FF00FF00FF00) >> 8) | ((num & 0x00FF00FF00FF00FF) << 8);
   53|  71.2k|}
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:
    7|  19.3M|readstat_error_t readstat_convert(char *dst, size_t dst_len, const char *src, size_t src_len, iconv_t converter) {
    8|       |    /* strip off spaces from the input because the programs use ASCII space
    9|       |     * padding even with non-ASCII encoding. */
   10|  19.4M|    while (src_len && (src[src_len-1] == ' ' || src[src_len-1] == '\0')) {
  ------------------
  |  Branch (10:12): [True: 68.4k, False: 19.3M]
  |  Branch (10:24): [True: 5.11k, False: 63.3k]
  |  Branch (10:49): [True: 42.9k, False: 20.4k]
  ------------------
   11|  48.0k|        src_len--;
   12|  48.0k|    }
   13|  19.3M|    if (dst_len == 0) {
  ------------------
  |  Branch (13:9): [True: 0, False: 19.3M]
  ------------------
   14|      0|        return READSTAT_ERROR_CONVERT_LONG_STRING;
   15|  19.3M|    } else if (converter) {
  ------------------
  |  Branch (15:16): [True: 587k, False: 18.8M]
  ------------------
   16|   587k|        size_t dst_left = dst_len - 1;
   17|   587k|        char *dst_end = dst;
   18|   587k|        size_t status = iconv(converter, (readstat_iconv_inbuf_t)&src, &src_len, &dst_end, &dst_left);
   19|   587k|        if (status == (size_t)-1) {
  ------------------
  |  Branch (19:13): [True: 1.77k, False: 585k]
  ------------------
   20|  1.77k|            if (errno == E2BIG) {
  ------------------
  |  Branch (20:17): [True: 4, False: 1.77k]
  ------------------
   21|      4|                return READSTAT_ERROR_CONVERT_LONG_STRING;
   22|  1.77k|            } else if (errno == EILSEQ) {
  ------------------
  |  Branch (22:24): [True: 26, False: 1.74k]
  ------------------
   23|     26|                return READSTAT_ERROR_CONVERT_BAD_STRING;
   24|  1.74k|            } else if (errno != EINVAL) { /* EINVAL indicates improper truncation; accept it */
  ------------------
  |  Branch (24:24): [True: 0, False: 1.74k]
  ------------------
   25|      0|                return READSTAT_ERROR_CONVERT;
   26|      0|            }
   27|  1.77k|        }
   28|   587k|        dst[dst_len - dst_left - 1] = '\0';
   29|  18.8M|    } else if (src_len + 1 > dst_len) {
  ------------------
  |  Branch (29:16): [True: 26, False: 18.8M]
  ------------------
   30|     26|        return READSTAT_ERROR_CONVERT_LONG_STRING;
   31|  18.8M|    } else {
   32|  18.8M|        memcpy(dst, src, src_len);
   33|  18.8M|        dst[src_len] = '\0';
   34|  18.8M|    }
   35|  19.3M|    return READSTAT_OK;
   36|  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|  3.05M|void *readstat_calloc(size_t count, size_t size) {
   18|  3.05M|    if (count > MAX_MALLOC_SIZE || size > MAX_MALLOC_SIZE || count * size > MAX_MALLOC_SIZE) {
  ------------------
  |  |    3|  6.10M|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
                  if (count > MAX_MALLOC_SIZE || size > MAX_MALLOC_SIZE || count * size > MAX_MALLOC_SIZE) {
  ------------------
  |  |    3|  6.10M|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
                  if (count > MAX_MALLOC_SIZE || size > MAX_MALLOC_SIZE || count * size > MAX_MALLOC_SIZE) {
  ------------------
  |  |    3|  3.05M|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
  |  Branch (18:9): [True: 0, False: 3.05M]
  |  Branch (18:36): [True: 0, False: 3.05M]
  |  Branch (18:62): [True: 0, False: 3.05M]
  ------------------
   19|      0|        return NULL;
   20|      0|    }
   21|  3.05M|    if (count == 0 || size == 0) {
  ------------------
  |  Branch (21:9): [True: 0, False: 3.05M]
  |  Branch (21:23): [True: 0, False: 3.05M]
  ------------------
   22|      0|        return NULL;
   23|      0|    }
   24|  3.05M|    return calloc(count, size);
   25|  3.05M|}
readstat_realloc:
   27|   247k|void *readstat_realloc(void *ptr, size_t len) {
   28|   247k|    if (len > MAX_MALLOC_SIZE || len == 0) {
  ------------------
  |  |    3|   495k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
  |  Branch (28:9): [True: 99, False: 247k]
  |  Branch (28:34): [True: 1, False: 247k]
  ------------------
   29|    100|        if (ptr)
  ------------------
  |  Branch (29:13): [True: 51, False: 49]
  ------------------
   30|     51|            free(ptr);
   31|    100|        return NULL;
   32|    100|    }
   33|   247k|    return realloc(ptr, len);
   34|   247k|}

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|}

readstat_variable_set_informat:
  441|    652|void readstat_variable_set_informat(readstat_variable_t *variable, const char *informat) {
  442|    652|    if (informat) {
  ------------------
  |  Branch (442:9): [True: 652, False: 0]
  ------------------
  443|    652|        snprintf(variable->informat, sizeof(variable->informat), "%s", informat);
  444|    652|    } else {
  445|      0|        memset(variable->informat, '\0', sizeof(variable->informat));
  446|      0|    }
  447|    652|}

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

readstat_parse_sas7bdat:
 1282|  3.67k|readstat_error_t readstat_parse_sas7bdat(readstat_parser_t *parser, const char *path, void *user_ctx) {
 1283|  3.67k|    int64_t last_examined_page_pass1 = 0;
 1284|  3.67k|    readstat_error_t retval = READSTAT_OK;
 1285|  3.67k|    readstat_io_t *io = parser->io;
 1286|       |
 1287|  3.67k|    sas7bdat_ctx_t  *ctx = calloc(1, sizeof(sas7bdat_ctx_t));
 1288|  3.67k|    sas_header_info_t  *hinfo = calloc(1, sizeof(sas_header_info_t));
 1289|       |
 1290|  3.67k|    if (ctx == NULL || hinfo == NULL) {
  ------------------
  |  Branch (1290:9): [True: 0, False: 3.67k]
  |  Branch (1290:24): [True: 0, False: 3.67k]
  ------------------
 1291|      0|        retval = READSTAT_ERROR_MALLOC;
 1292|      0|        goto cleanup;
 1293|      0|    }
 1294|       |
 1295|  3.67k|    ctx->handle = parser->handlers;
 1296|  3.67k|    ctx->input_encoding = parser->input_encoding;
 1297|  3.67k|    ctx->output_encoding = parser->output_encoding;
 1298|  3.67k|    ctx->user_ctx = user_ctx;
 1299|  3.67k|    ctx->io = parser->io;
 1300|  3.67k|    ctx->row_limit = parser->row_limit;
 1301|  3.67k|    if (parser->row_offset > 0)
  ------------------
  |  Branch (1301:9): [True: 0, False: 3.67k]
  ------------------
 1302|      0|        ctx->row_offset = parser->row_offset;
 1303|       |
 1304|  3.67k|    if (io->open(path, io->io_ctx) == -1) {
  ------------------
  |  Branch (1304:9): [True: 0, False: 3.67k]
  ------------------
 1305|      0|        retval = READSTAT_ERROR_OPEN;
 1306|      0|        goto cleanup;
 1307|      0|    }
 1308|       |
 1309|  3.67k|    if ((ctx->file_size = io->seek(0, READSTAT_SEEK_END, io->io_ctx)) == -1) {
  ------------------
  |  Branch (1309:9): [True: 0, False: 3.67k]
  ------------------
 1310|      0|        retval = READSTAT_ERROR_SEEK;
 1311|      0|        if (ctx->handle.error) {
  ------------------
  |  Branch (1311:13): [True: 0, False: 0]
  ------------------
 1312|      0|            snprintf(ctx->error_buf, sizeof(ctx->error_buf), "ReadStat: Failed to seek to end of file");
 1313|      0|            ctx->handle.error(ctx->error_buf, ctx->user_ctx);
 1314|      0|        }
 1315|      0|        goto cleanup;
 1316|      0|    }
 1317|       |
 1318|  3.67k|    if (io->seek(0, READSTAT_SEEK_SET, io->io_ctx) == -1) {
  ------------------
  |  Branch (1318:9): [True: 0, False: 3.67k]
  ------------------
 1319|      0|        retval = READSTAT_ERROR_SEEK;
 1320|      0|        if (ctx->handle.error) {
  ------------------
  |  Branch (1320:13): [True: 0, False: 0]
  ------------------
 1321|      0|            snprintf(ctx->error_buf, sizeof(ctx->error_buf), "ReadStat: Failed to seek to beginning of file");
 1322|      0|            ctx->handle.error(ctx->error_buf, ctx->user_ctx);
 1323|      0|        }
 1324|      0|        goto cleanup;
 1325|      0|    }
 1326|       |
 1327|  3.67k|    if ((retval = sas_read_header(io, hinfo, ctx->handle.error, user_ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1327:9): [True: 513, False: 3.16k]
  ------------------
 1328|    513|        goto cleanup;
 1329|    513|    }
 1330|       |
 1331|  3.16k|    ctx->u64 = hinfo->u64;
 1332|  3.16k|    ctx->little_endian = hinfo->little_endian;
 1333|  3.16k|    ctx->vendor = hinfo->vendor;
 1334|  3.16k|    ctx->bswap = machine_is_little_endian() ^ hinfo->little_endian;
 1335|  3.16k|    ctx->header_size = hinfo->header_size;
 1336|  3.16k|    ctx->page_count = hinfo->page_count;
 1337|  3.16k|    ctx->page_size = hinfo->page_size;
 1338|  3.16k|    ctx->page_header_size = hinfo->page_header_size;
 1339|  3.16k|    ctx->subheader_pointer_size = hinfo->subheader_pointer_size;
 1340|  3.16k|    ctx->subheader_signature_size = ctx->u64 ? 8 : 4;
  ------------------
  |  Branch (1340:37): [True: 1.59k, False: 1.56k]
  ------------------
 1341|  3.16k|    ctx->ctime = hinfo->creation_time;
 1342|  3.16k|    ctx->mtime = hinfo->modification_time;
 1343|  3.16k|    ctx->version = hinfo->major_version;
 1344|  3.16k|    if (ctx->input_encoding == NULL) {
  ------------------
  |  Branch (1344:9): [True: 3.16k, False: 0]
  ------------------
 1345|  3.16k|        ctx->input_encoding = hinfo->encoding;
 1346|  3.16k|    }
 1347|  3.16k|    if ((ctx->page = readstat_malloc(ctx->page_size)) == NULL) {
  ------------------
  |  Branch (1347:9): [True: 0, False: 3.16k]
  ------------------
 1348|      0|        retval = READSTAT_ERROR_MALLOC;
 1349|      0|        goto cleanup;
 1350|      0|    }
 1351|       |
 1352|  3.16k|    if (ctx->input_encoding && ctx->output_encoding && strcmp(ctx->input_encoding, ctx->output_encoding) != 0) {
  ------------------
  |  Branch (1352:9): [True: 3.16k, False: 0]
  |  Branch (1352:32): [True: 3.16k, False: 0]
  |  Branch (1352:56): [True: 2.10k, False: 1.05k]
  ------------------
 1353|  2.10k|        iconv_t converter = iconv_open(ctx->output_encoding, ctx->input_encoding);
 1354|  2.10k|        if (converter == (iconv_t)-1) {
  ------------------
  |  Branch (1354:13): [True: 2, False: 2.10k]
  ------------------
 1355|      2|            retval = READSTAT_ERROR_UNSUPPORTED_CHARSET;
 1356|      2|            goto cleanup;
 1357|      2|        }
 1358|  2.10k|        ctx->converter = converter;
 1359|  2.10k|    }
 1360|       |
 1361|  3.16k|    if ((retval = readstat_convert(ctx->table_name, sizeof(ctx->table_name),
  ------------------
  |  Branch (1361:9): [True: 2, False: 3.15k]
  ------------------
 1362|  3.16k|                hinfo->table_name, sizeof(hinfo->table_name), ctx->converter)) != READSTAT_OK) {
 1363|      2|        goto cleanup;
 1364|      2|    }
 1365|       |
 1366|  3.15k|    if ((retval = sas7bdat_parse_meta_pages_pass1(ctx, &last_examined_page_pass1)) != READSTAT_OK) {
  ------------------
  |  Branch (1366:9): [True: 239, False: 2.91k]
  ------------------
 1367|    239|        goto cleanup;
 1368|    239|    }
 1369|       |
 1370|  2.91k|    if ((retval = sas7bdat_parse_amd_pages_pass1(last_examined_page_pass1, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1370:9): [True: 922, False: 1.99k]
  ------------------
 1371|    922|        goto cleanup;
 1372|    922|    }
 1373|       |
 1374|  1.99k|    if (io->seek(ctx->header_size, READSTAT_SEEK_SET, io->io_ctx) == -1) {
  ------------------
  |  Branch (1374:9): [True: 0, False: 1.99k]
  ------------------
 1375|      0|        retval = READSTAT_ERROR_SEEK;
 1376|      0|        if (ctx->handle.error) {
  ------------------
  |  Branch (1376:13): [True: 0, False: 0]
  ------------------
 1377|      0|            snprintf(ctx->error_buf, sizeof(ctx->error_buf), "ReadStat: Failed to seek to position %" PRId64, 
 1378|      0|                    ctx->header_size);
 1379|      0|            ctx->handle.error(ctx->error_buf, ctx->user_ctx);
 1380|      0|        }
 1381|      0|        goto cleanup;
 1382|      0|    }
 1383|       |
 1384|  1.99k|    if ((retval = sas7bdat_parse_all_pages_pass2(ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1384:9): [True: 1.63k, False: 366]
  ------------------
 1385|  1.63k|        goto cleanup;
 1386|  1.63k|    }
 1387|       |    
 1388|    366|    if ((retval = sas7bdat_submit_columns_if_needed(ctx, 0)) != READSTAT_OK) {
  ------------------
  |  Branch (1388:9): [True: 76, False: 290]
  ------------------
 1389|     76|        goto cleanup;
 1390|     76|    }
 1391|       |
 1392|    290|    if (ctx->handle.value && ctx->parsed_row_count != ctx->row_limit) {
  ------------------
  |  Branch (1392:9): [True: 290, False: 0]
  |  Branch (1392:30): [True: 146, False: 144]
  ------------------
 1393|    146|        retval = READSTAT_ERROR_ROW_COUNT_MISMATCH;
 1394|    146|        if (ctx->handle.error) {
  ------------------
  |  Branch (1394:13): [True: 0, False: 146]
  ------------------
 1395|      0|            snprintf(ctx->error_buf, sizeof(ctx->error_buf), "ReadStat: Expected %d rows in file, found %d",
 1396|      0|                    ctx->row_limit, ctx->parsed_row_count);
 1397|      0|            ctx->handle.error(ctx->error_buf, ctx->user_ctx);
 1398|      0|        }
 1399|    146|        goto cleanup;
 1400|    146|    }
 1401|       |
 1402|    144|    if ((retval = sas7bdat_update_progress(ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1402:9): [True: 0, False: 144]
  ------------------
 1403|      0|        goto cleanup;
 1404|      0|    }
 1405|       |
 1406|  3.67k|cleanup:
 1407|  3.67k|    io->close(io->io_ctx);
 1408|       |
 1409|  3.67k|    if (retval == READSTAT_ERROR_OPEN ||
  ------------------
  |  Branch (1409:9): [True: 0, False: 3.67k]
  ------------------
 1410|  3.67k|            retval == READSTAT_ERROR_READ ||
  ------------------
  |  Branch (1410:13): [True: 460, False: 3.21k]
  ------------------
 1411|  3.21k|            retval == READSTAT_ERROR_SEEK) {
  ------------------
  |  Branch (1411:13): [True: 363, False: 2.85k]
  ------------------
 1412|    823|        if (ctx->handle.error) {
  ------------------
  |  Branch (1412:13): [True: 0, False: 823]
  ------------------
 1413|      0|            snprintf(ctx->error_buf, sizeof(ctx->error_buf), "ReadStat: %s (retval = %d): %s (errno = %d)", 
 1414|      0|                    readstat_error_message(retval), retval, strerror(errno), errno);
 1415|      0|            ctx->handle.error(ctx->error_buf, user_ctx);
 1416|      0|        }
 1417|    823|    }
 1418|       |
 1419|  3.67k|    if (ctx)
  ------------------
  |  Branch (1419:9): [True: 3.67k, False: 0]
  ------------------
 1420|  3.67k|        sas7bdat_ctx_free(ctx);
 1421|  3.67k|    if (hinfo)
  ------------------
  |  Branch (1421:9): [True: 3.67k, False: 0]
  ------------------
 1422|  3.67k|        free(hinfo);
 1423|       |
 1424|  3.67k|    return retval;
 1425|    144|}
readstat_sas7bdat_read.c:sas7bdat_parse_meta_pages_pass1:
 1123|  3.15k|static readstat_error_t sas7bdat_parse_meta_pages_pass1(sas7bdat_ctx_t *ctx, int64_t *outLastExaminedPage) {
 1124|  3.15k|    readstat_error_t retval = READSTAT_OK;
 1125|  3.15k|    readstat_io_t *io = ctx->io;
 1126|  3.15k|    int64_t i;
 1127|       |
 1128|       |    /* look for META and MIX pages at beginning... */
 1129|  8.35k|    for (i=0; i<ctx->page_count; i++) {
  ------------------
  |  Branch (1129:15): [True: 6.10k, False: 2.25k]
  ------------------
 1130|  6.10k|        if (io->seek(ctx->header_size + i*ctx->page_size, READSTAT_SEEK_SET, io->io_ctx) == -1) {
  ------------------
  |  Branch (1130:13): [True: 9, False: 6.09k]
  ------------------
 1131|      9|            retval = READSTAT_ERROR_SEEK;
 1132|      9|            if (ctx->handle.error) {
  ------------------
  |  Branch (1132:17): [True: 0, False: 9]
  ------------------
 1133|      0|                snprintf(ctx->error_buf, sizeof(ctx->error_buf), "ReadStat: Failed to seek to position %" PRId64 
 1134|      0|                        " (= %" PRId64 " + %" PRId64 "*%" PRId64 ")",
 1135|      0|                        ctx->header_size + i*ctx->page_size, ctx->header_size, i, ctx->page_size);
 1136|      0|                ctx->handle.error(ctx->error_buf, ctx->user_ctx);
 1137|      0|            }
 1138|      9|            goto cleanup;
 1139|      9|        }
 1140|       |
 1141|  6.09k|        readstat_off_t off = 0;
 1142|  6.09k|        if (ctx->u64)
  ------------------
  |  Branch (1142:13): [True: 3.86k, False: 2.22k]
  ------------------
 1143|  3.86k|            off = 16;
 1144|       |
 1145|  6.09k|        size_t head_len = off + 16 + 2;
 1146|  6.09k|        size_t tail_len = ctx->page_size - head_len;
 1147|       |
 1148|  6.09k|        if (io->read(ctx->page, head_len, io->io_ctx) < head_len) {
  ------------------
  |  Branch (1148:13): [True: 145, False: 5.94k]
  ------------------
 1149|    145|            retval = READSTAT_ERROR_READ;
 1150|    145|            goto cleanup;
 1151|    145|        }
 1152|       |
 1153|  5.94k|        uint16_t page_type = sas_read2(&ctx->page[off+16], ctx->bswap);
 1154|       |
 1155|  5.94k|        if ((page_type & SAS_PAGE_TYPE_MASK) == SAS_PAGE_TYPE_DATA)
  ------------------
  |  |  112|  5.94k|#define SAS_PAGE_TYPE_MASK   0x0F00
  ------------------
                      if ((page_type & SAS_PAGE_TYPE_MASK) == SAS_PAGE_TYPE_DATA)
  ------------------
  |  |  109|  5.94k|#define SAS_PAGE_TYPE_DATA   0x0100
  ------------------
  |  Branch (1155:13): [True: 669, False: 5.27k]
  ------------------
 1156|    669|            break;
 1157|  5.27k|        if ((page_type & SAS_PAGE_TYPE_COMP))
  ------------------
  |  |  116|  5.27k|#define SAS_PAGE_TYPE_COMP          0x9000
  ------------------
  |  Branch (1157:13): [True: 1.46k, False: 3.81k]
  ------------------
 1158|  1.46k|            continue;
 1159|       |
 1160|  3.81k|        if (io->read(ctx->page + head_len, tail_len, io->io_ctx) < tail_len) {
  ------------------
  |  Branch (1160:13): [True: 33, False: 3.78k]
  ------------------
 1161|     33|            retval = READSTAT_ERROR_READ;
 1162|     33|            goto cleanup;
 1163|     33|        }
 1164|       |
 1165|  3.78k|        if ((retval = sas7bdat_parse_page_pass1(ctx->page, ctx->page_size, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1165:13): [True: 52, False: 3.73k]
  ------------------
 1166|     52|            if (ctx->handle.error && retval != READSTAT_ERROR_USER_ABORT) {
  ------------------
  |  Branch (1166:17): [True: 0, False: 52]
  |  Branch (1166:38): [True: 0, False: 0]
  ------------------
 1167|      0|                int64_t pos = io->seek(0, READSTAT_SEEK_CUR, io->io_ctx);
 1168|      0|                snprintf(ctx->error_buf, sizeof(ctx->error_buf), 
 1169|      0|                        "ReadStat: Error parsing page %" PRId64 ", bytes %" PRId64 "-%" PRId64, 
 1170|      0|                        i, pos - ctx->page_size, pos-1);
 1171|      0|                ctx->handle.error(ctx->error_buf, ctx->user_ctx);
 1172|      0|            }
 1173|     52|            goto cleanup;
 1174|     52|        }
 1175|  3.78k|    }
 1176|       |
 1177|  3.15k|cleanup:
 1178|  3.15k|    if (outLastExaminedPage)
  ------------------
  |  Branch (1178:9): [True: 3.15k, False: 0]
  ------------------
 1179|  3.15k|        *outLastExaminedPage = i;
 1180|       |
 1181|  3.15k|    return retval;
 1182|  3.15k|}
readstat_sas7bdat_read.c:sas7bdat_parse_page_pass1:
  949|  6.31k|static readstat_error_t sas7bdat_parse_page_pass1(const char *page, size_t page_size, sas7bdat_ctx_t *ctx) {
  950|  6.31k|    readstat_error_t retval = READSTAT_OK;
  951|       |
  952|  6.31k|    uint16_t subheader_count = sas_read2(&page[ctx->page_header_size-4], ctx->bswap);
  953|       |
  954|  6.31k|    int i;
  955|  6.31k|    const char *shp = &page[ctx->page_header_size];
  956|  6.31k|    int lshp = ctx->subheader_pointer_size;
  957|       |
  958|  6.31k|    if (ctx->page_header_size + subheader_count*lshp > page_size) {
  ------------------
  |  Branch (958:9): [True: 35, False: 6.27k]
  ------------------
  959|     35|        retval = READSTAT_ERROR_PARSE;
  960|     35|        goto cleanup;
  961|     35|    }
  962|       |
  963|  70.2k|    for (i=0; i<subheader_count; i++) {
  ------------------
  |  Branch (963:15): [True: 64.7k, False: 5.58k]
  ------------------
  964|  64.7k|        subheader_pointer_t shp_info = { 0 };
  965|  64.7k|        if ((retval = sas7bdat_parse_subheader_pointer(shp, page + page_size - shp, &shp_info, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (965:13): [True: 0, False: 64.7k]
  ------------------
  966|      0|            goto cleanup;
  967|      0|        }
  968|  64.7k|        if (shp_info.len > 0 && shp_info.compression != SAS_COMPRESSION_TRUNC) {
  ------------------
  |  |  125|  41.9k|#define SAS_COMPRESSION_TRUNC        0x01
  ------------------
  |  Branch (968:13): [True: 41.9k, False: 22.7k]
  |  Branch (968:33): [True: 35.2k, False: 6.75k]
  ------------------
  969|  35.2k|            if ((retval = sas7bdat_validate_subheader_pointer(&shp_info, page_size, subheader_count, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (969:17): [True: 605, False: 34.6k]
  ------------------
  970|    605|                goto cleanup;
  971|    605|            }
  972|  34.6k|            if (shp_info.compression == SAS_COMPRESSION_NONE) {
  ------------------
  |  |  124|  34.6k|#define SAS_COMPRESSION_NONE         0x00
  ------------------
  |  Branch (972:17): [True: 31.0k, False: 3.58k]
  ------------------
  973|  31.0k|                sas_subheader_type_t subheader_type = sas7bdat_parse_subheader_type(page + shp_info.offset, ctx);
  974|  31.0k|                if (subheader_type == SAS_SUBHEADER_TYPE_COLUMN_TEXT) {
  ------------------
  |  Branch (974:21): [True: 2.67k, False: 28.3k]
  ------------------
  975|  2.67k|                    if ((retval = sas7bdat_parse_subheader(subheader_type, page + shp_info.offset, shp_info.len, ctx))
  ------------------
  |  Branch (975:25): [True: 66, False: 2.61k]
  ------------------
  976|  2.67k|                            != READSTAT_OK) {
  977|     66|                        goto cleanup;
  978|     66|                    }
  979|  2.67k|                }
  980|  31.0k|            } else if (shp_info.compression == SAS_COMPRESSION_ROW || shp_info.compression == SAS_COMPRESSION_DELETED_ROW) {
  ------------------
  |  |  126|  7.16k|#define SAS_COMPRESSION_ROW          0x04
  ------------------
                          } else if (shp_info.compression == SAS_COMPRESSION_ROW || shp_info.compression == SAS_COMPRESSION_DELETED_ROW) {
  ------------------
  |  |  127|    388|#define SAS_COMPRESSION_DELETED_ROW  0x05
  ------------------
  |  Branch (980:24): [True: 3.19k, False: 388]
  |  Branch (980:71): [True: 367, False: 21]
  ------------------
  981|       |                /* void */
  982|  3.56k|            } else {
  983|     21|                retval = READSTAT_ERROR_UNSUPPORTED_COMPRESSION;
  984|     21|                goto cleanup;
  985|     21|            }
  986|  34.6k|        }
  987|       |
  988|  64.0k|        shp += lshp;
  989|  64.0k|    }
  990|       |
  991|  6.31k|cleanup:
  992|       |
  993|  6.31k|    return retval;
  994|  6.27k|}
readstat_sas7bdat_read.c:sas7bdat_parse_subheader_pointer:
  903|   104k|        subheader_pointer_t *info, sas7bdat_ctx_t *ctx) {
  904|   104k|    readstat_error_t retval = READSTAT_OK;
  905|   104k|    if (ctx->u64) {
  ------------------
  |  Branch (905:9): [True: 22.0k, False: 82.5k]
  ------------------
  906|  22.0k|        if (shp_size <= 17) {
  ------------------
  |  Branch (906:13): [True: 0, False: 22.0k]
  ------------------
  907|      0|            retval = READSTAT_ERROR_PARSE;
  908|      0|            goto cleanup;
  909|      0|        }
  910|  22.0k|        info->offset = sas_read8(&shp[0], ctx->bswap);
  911|  22.0k|        info->len = sas_read8(&shp[8], ctx->bswap);
  912|  22.0k|        info->compression = shp[16];
  913|  22.0k|        info->is_compressed_data = shp[17];
  914|  82.5k|    } else {
  915|  82.5k|        if (shp_size <= 9) {
  ------------------
  |  Branch (915:13): [True: 0, False: 82.5k]
  ------------------
  916|      0|            retval = READSTAT_ERROR_PARSE;
  917|      0|            goto cleanup;
  918|      0|        }
  919|  82.5k|        info->offset = sas_read4(&shp[0], ctx->bswap);
  920|  82.5k|        info->len = sas_read4(&shp[4], ctx->bswap);
  921|  82.5k|        info->compression = shp[8];
  922|  82.5k|        info->is_compressed_data = shp[9];
  923|  82.5k|    }
  924|   104k|cleanup:
  925|   104k|    return retval;
  926|   104k|}
readstat_sas7bdat_read.c:sas7bdat_validate_subheader_pointer:
  929|  55.8k|        uint16_t subheader_count, sas7bdat_ctx_t *ctx) {
  930|  55.8k|    if (shp_info->offset > page_size)
  ------------------
  |  Branch (930:9): [True: 469, False: 55.4k]
  ------------------
  931|    469|        return READSTAT_ERROR_PARSE;
  932|  55.4k|    if (shp_info->len > page_size)
  ------------------
  |  Branch (932:9): [True: 292, False: 55.1k]
  ------------------
  933|    292|        return READSTAT_ERROR_PARSE;
  934|  55.1k|    if (shp_info->offset + shp_info->len > page_size)
  ------------------
  |  Branch (934:9): [True: 38, False: 55.0k]
  ------------------
  935|     38|        return READSTAT_ERROR_PARSE;
  936|  55.0k|    if (shp_info->offset < ctx->page_header_size + subheader_count*ctx->subheader_pointer_size)
  ------------------
  |  Branch (936:9): [True: 12, False: 55.0k]
  ------------------
  937|     12|        return READSTAT_ERROR_PARSE;
  938|  55.0k|    if (shp_info->compression == SAS_COMPRESSION_NONE) {
  ------------------
  |  |  124|  55.0k|#define SAS_COMPRESSION_NONE         0x00
  ------------------
  |  Branch (938:9): [True: 49.4k, False: 5.65k]
  ------------------
  939|  49.4k|        if (shp_info->len < ctx->subheader_signature_size)
  ------------------
  |  Branch (939:13): [True: 4, False: 49.4k]
  ------------------
  940|      4|            return READSTAT_ERROR_PARSE;
  941|  49.4k|        if (shp_info->offset + ctx->subheader_signature_size > page_size)
  ------------------
  |  Branch (941:13): [True: 0, False: 49.4k]
  ------------------
  942|      0|            return READSTAT_ERROR_PARSE;
  943|  49.4k|    }
  944|       |    
  945|  55.0k|    return READSTAT_OK;
  946|  55.0k|}
readstat_sas7bdat_read.c:sas7bdat_parse_subheader_type:
  883|  49.4k|static sas_subheader_type_t sas7bdat_parse_subheader_type(const char* subheader, sas7bdat_ctx_t* ctx) {
  884|  49.4k|    if (!ctx->u64) {
  ------------------
  |  Branch (884:9): [True: 35.9k, False: 13.4k]
  ------------------
  885|  35.9k|        uint32_t signature_32 = sas_read4(subheader, ctx->bswap);
  886|  35.9k|        return sas7bdat_parse_subheader_type_32(signature_32);
  887|  35.9k|    }
  888|       |
  889|  13.4k|    uint64_t signature = sas_read8(subheader, ctx->bswap);
  890|  13.4k|    if (signature == SAS_SUBHEADER_SIGNATURE_ROW_SIZE) {
  ------------------
  |  |   92|  13.4k|#define SAS_SUBHEADER_SIGNATURE_ROW_SIZE       0xF7F7F7F7
  ------------------
  |  Branch (890:9): [True: 1.62k, False: 11.8k]
  ------------------
  891|  1.62k|        return SAS_SUBHEADER_TYPE_ROW_SIZE;
  892|  11.8k|    } else if (signature == SAS_SUBHEADER_SIGNATURE_COLUMN_SIZE) {
  ------------------
  |  |   93|  11.8k|#define SAS_SUBHEADER_SIGNATURE_COLUMN_SIZE    0xF6F6F6F6
  ------------------
  |  Branch (892:16): [True: 458, False: 11.3k]
  ------------------
  893|    458|        return SAS_SUBHEADER_TYPE_COLUMN_SIZE;
  894|  11.3k|    } else if ((signature & SAS_SUBHEADER_SIGNATURE_64BIT_MASK) != SAS_SUBHEADER_SIGNATURE_64BIT_MASK) {
  ------------------
  |  |  105|  11.3k|#define SAS_SUBHEADER_SIGNATURE_64BIT_MASK     0xFFFFFFFF00000000
  ------------------
                  } else if ((signature & SAS_SUBHEADER_SIGNATURE_64BIT_MASK) != SAS_SUBHEADER_SIGNATURE_64BIT_MASK) {
  ------------------
  |  |  105|  11.3k|#define SAS_SUBHEADER_SIGNATURE_64BIT_MASK     0xFFFFFFFF00000000
  ------------------
  |  Branch (894:16): [True: 1.28k, False: 10.1k]
  ------------------
  895|  1.28k|        return SAS_SUBHEADER_TYPE_DATA;
  896|  1.28k|    }
  897|       |
  898|  10.1k|    uint32_t lower_bytes = (uint32_t)(signature & SAS_SUBHEADER_SIGNATURE_32BIT_MASK);
  ------------------
  |  |  106|  10.1k|#define SAS_SUBHEADER_SIGNATURE_32BIT_MASK     0x00000000FFFFFFFF
  ------------------
  899|  10.1k|    return sas7bdat_parse_subheader_type_32(lower_bytes);
  900|  13.4k|}
readstat_sas7bdat_read.c:sas7bdat_parse_subheader_type_32:
  857|  46.0k|static sas_subheader_type_t sas7bdat_parse_subheader_type_32(uint32_t signature) {
  858|  46.0k|    switch (signature) {
  859|  7.74k|        case SAS_SUBHEADER_SIGNATURE_ROW_SIZE:
  ------------------
  |  |   92|  7.74k|#define SAS_SUBHEADER_SIGNATURE_ROW_SIZE       0xF7F7F7F7
  ------------------
  |  Branch (859:9): [True: 7.74k, False: 38.3k]
  ------------------
  860|  7.74k|            return SAS_SUBHEADER_TYPE_ROW_SIZE;
  861|  3.25k|        case SAS_SUBHEADER_SIGNATURE_COLUMN_SIZE:
  ------------------
  |  |   93|  3.25k|#define SAS_SUBHEADER_SIGNATURE_COLUMN_SIZE    0xF6F6F6F6
  ------------------
  |  Branch (861:9): [True: 3.25k, False: 42.8k]
  ------------------
  862|  3.25k|            return SAS_SUBHEADER_TYPE_COLUMN_SIZE;
  863|  2.82k|        case SAS_SUBHEADER_SIGNATURE_COUNTS:
  ------------------
  |  |   94|  2.82k|#define SAS_SUBHEADER_SIGNATURE_COUNTS         0xFFFFFC00
  ------------------
  |  Branch (863:9): [True: 2.82k, False: 43.2k]
  ------------------
  864|  2.82k|            return SAS_SUBHEADER_TYPE_COUNTS;
  865|  8.19k|        case SAS_SUBHEADER_SIGNATURE_COLUMN_FORMAT:
  ------------------
  |  |   95|  8.19k|#define SAS_SUBHEADER_SIGNATURE_COLUMN_FORMAT  0xFFFFFBFE
  ------------------
  |  Branch (865:9): [True: 8.19k, False: 37.8k]
  ------------------
  866|  8.19k|            return SAS_SUBHEADER_TYPE_COLUMN_FORMAT;
  867|  4.98k|        case SAS_SUBHEADER_SIGNATURE_COLUMN_ATTRS:
  ------------------
  |  |  100|  4.98k|#define SAS_SUBHEADER_SIGNATURE_COLUMN_ATTRS   0xFFFFFFFC
  ------------------
  |  Branch (867:9): [True: 4.98k, False: 41.0k]
  ------------------
  868|  4.98k|            return SAS_SUBHEADER_TYPE_COLUMN_ATTRS;
  869|  4.38k|        case SAS_SUBHEADER_SIGNATURE_COLUMN_TEXT:
  ------------------
  |  |  101|  4.38k|#define SAS_SUBHEADER_SIGNATURE_COLUMN_TEXT    0xFFFFFFFD
  ------------------
  |  Branch (869:9): [True: 4.38k, False: 41.6k]
  ------------------
  870|  4.38k|            return SAS_SUBHEADER_TYPE_COLUMN_TEXT;
  871|  2.33k|        case SAS_SUBHEADER_SIGNATURE_COLUMN_LIST:
  ------------------
  |  |  102|  2.33k|#define SAS_SUBHEADER_SIGNATURE_COLUMN_LIST    0xFFFFFFFE
  ------------------
  |  Branch (871:9): [True: 2.33k, False: 43.7k]
  ------------------
  872|  2.33k|            return SAS_SUBHEADER_TYPE_COLUMN_LIST;
  873|  7.02k|        case SAS_SUBHEADER_SIGNATURE_COLUMN_NAME:
  ------------------
  |  |  103|  7.02k|#define SAS_SUBHEADER_SIGNATURE_COLUMN_NAME    0xFFFFFFFF
  ------------------
  |  Branch (873:9): [True: 7.02k, False: 39.0k]
  ------------------
  874|  7.02k|            return SAS_SUBHEADER_TYPE_COLUMN_NAME;
  875|  5.30k|        default:
  ------------------
  |  Branch (875:9): [True: 5.30k, False: 40.7k]
  ------------------
  876|  5.30k|            if ((signature & SAS_SUBHEADER_SIGNATURE_COLUMN_MASK) == SAS_SUBHEADER_SIGNATURE_COLUMN_MASK) {
  ------------------
  |  |   97|  5.30k|#define SAS_SUBHEADER_SIGNATURE_COLUMN_MASK    0xFFFFFFF8
  ------------------
                          if ((signature & SAS_SUBHEADER_SIGNATURE_COLUMN_MASK) == SAS_SUBHEADER_SIGNATURE_COLUMN_MASK) {
  ------------------
  |  |   97|  5.30k|#define SAS_SUBHEADER_SIGNATURE_COLUMN_MASK    0xFFFFFFF8
  ------------------
  |  Branch (876:17): [True: 1.74k, False: 3.56k]
  ------------------
  877|  1.74k|                return SAS_SUBHEADER_TYPE_UNKNOWN;
  878|  1.74k|            }
  879|  3.56k|            return SAS_SUBHEADER_TYPE_DATA;
  880|  46.0k|    }
  881|  46.0k|}
readstat_sas7bdat_read.c:sas7bdat_parse_subheader:
  676|  18.7k|        size_t len, sas7bdat_ctx_t *ctx) {
  677|  18.7k|    readstat_error_t retval = READSTAT_OK;
  678|       |
  679|  18.7k|    if (len < 2 + ctx->subheader_signature_size) {
  ------------------
  |  Branch (679:9): [True: 4, False: 18.7k]
  ------------------
  680|      4|        retval = READSTAT_ERROR_PARSE;
  681|      4|        goto cleanup;
  682|      4|    }
  683|  18.7k|    if (subheader_type == SAS_SUBHEADER_TYPE_ROW_SIZE) {
  ------------------
  |  Branch (683:9): [True: 3.68k, False: 15.0k]
  ------------------
  684|  3.68k|        retval = sas7bdat_parse_row_size_subheader(subheader, len, ctx);
  685|  15.0k|    } else if (subheader_type == SAS_SUBHEADER_TYPE_COLUMN_SIZE) {
  ------------------
  |  Branch (685:16): [True: 1.29k, False: 13.7k]
  ------------------
  686|  1.29k|        retval = sas7bdat_parse_column_size_subheader(subheader, len, ctx);
  687|  13.7k|    } else if (subheader_type == SAS_SUBHEADER_TYPE_COUNTS) {
  ------------------
  |  Branch (687:16): [True: 1.23k, False: 12.5k]
  ------------------
  688|       |        /* void */
  689|  12.5k|    } else if (subheader_type == SAS_SUBHEADER_TYPE_COLUMN_TEXT) {
  ------------------
  |  Branch (689:16): [True: 2.67k, False: 9.84k]
  ------------------
  690|  2.67k|        retval = sas7bdat_parse_column_text_subheader(subheader, len, ctx);
  691|  9.84k|    } else if (subheader_type == SAS_SUBHEADER_TYPE_COLUMN_NAME) {
  ------------------
  |  Branch (691:16): [True: 2.73k, False: 7.10k]
  ------------------
  692|  2.73k|        retval = sas7bdat_parse_column_name_subheader(subheader, len, ctx);
  693|  7.10k|    } else if (subheader_type == SAS_SUBHEADER_TYPE_COLUMN_ATTRS) {
  ------------------
  |  Branch (693:16): [True: 2.02k, False: 5.08k]
  ------------------
  694|  2.02k|        retval = sas7bdat_parse_column_attributes_subheader(subheader, len, ctx);
  695|  5.08k|    } else if (subheader_type == SAS_SUBHEADER_TYPE_COLUMN_FORMAT) {
  ------------------
  |  Branch (695:16): [True: 3.57k, False: 1.50k]
  ------------------
  696|  3.57k|        retval = sas7bdat_parse_column_format_subheader(subheader, len, ctx);
  697|  3.57k|    } else if (subheader_type == SAS_SUBHEADER_TYPE_COLUMN_LIST) {
  ------------------
  |  Branch (697:16): [True: 698, False: 805]
  ------------------
  698|       |        /* void */
  699|    805|    } else if (subheader_type == SAS_SUBHEADER_TYPE_UNKNOWN) {
  ------------------
  |  Branch (699:16): [True: 764, False: 41]
  ------------------
  700|       |        /* void */
  701|    764|    } else {
  702|     41|        retval = READSTAT_ERROR_PARSE;
  703|     41|    }
  704|       |
  705|  18.7k|cleanup:
  706|       |
  707|  18.7k|    return retval;
  708|  18.7k|}
readstat_sas7bdat_read.c:sas7bdat_parse_row_size_subheader:
  236|  3.68k|static readstat_error_t sas7bdat_parse_row_size_subheader(const char *subheader, size_t len, sas7bdat_ctx_t *ctx) {
  237|  3.68k|    readstat_error_t retval = READSTAT_OK;
  238|  3.68k|    uint64_t total_row_count;
  239|  3.68k|    uint64_t row_length, deleted_row_count, page_row_count;
  240|       |
  241|  3.68k|    if (len < (ctx->u64 ? 250: 190)) {
  ------------------
  |  Branch (241:9): [True: 3, False: 3.68k]
  |  Branch (241:16): [True: 1.17k, False: 2.51k]
  ------------------
  242|      3|        retval = READSTAT_ERROR_PARSE;
  243|      3|        goto cleanup;
  244|      3|    }
  245|       |
  246|  3.68k|    if (ctx->u64) {
  ------------------
  |  Branch (246:9): [True: 1.17k, False: 2.51k]
  ------------------
  247|  1.17k|        row_length = sas_read8(&subheader[40], ctx->bswap);
  248|  1.17k|        total_row_count = sas_read8(&subheader[48], ctx->bswap);
  249|  1.17k|        deleted_row_count = sas_read8(&subheader[56], ctx->bswap);
  250|  1.17k|        page_row_count = sas_read8(&subheader[120], ctx->bswap);
  251|  2.51k|    } else {
  252|  2.51k|        row_length = sas_read4(&subheader[20], ctx->bswap);
  253|  2.51k|        total_row_count = sas_read4(&subheader[24], ctx->bswap);
  254|  2.51k|        deleted_row_count = sas_read4(&subheader[28], ctx->bswap);
  255|  2.51k|        page_row_count = sas_read4(&subheader[60], ctx->bswap);
  256|  2.51k|    }
  257|       |
  258|  3.68k|    if (deleted_row_count > total_row_count) {
  ------------------
  |  Branch (258:9): [True: 51, False: 3.63k]
  ------------------
  259|     51|        retval = READSTAT_ERROR_PARSE;
  260|     51|        goto cleanup;
  261|     51|    }
  262|  3.63k|    ctx->total_row_count = total_row_count;
  263|  3.63k|    ctx->deleted_row_count = deleted_row_count;
  264|       |
  265|  3.63k|    sas_text_ref_t file_label_ref = sas7bdat_parse_text_ref(&subheader[len-130], ctx);
  266|  3.63k|    if (file_label_ref.length) {
  ------------------
  |  Branch (266:9): [True: 1.03k, False: 2.59k]
  ------------------
  267|  1.03k|        if ((retval = sas7bdat_copy_text_ref(ctx->file_label, sizeof(ctx->file_label),
  ------------------
  |  Branch (267:13): [True: 48, False: 989]
  ------------------
  268|  1.03k|                        file_label_ref, ctx)) != READSTAT_OK) {
  269|     48|            goto cleanup;
  270|     48|        }
  271|  1.03k|    }
  272|       |
  273|  3.58k|    sas_text_ref_t compression_ref = sas7bdat_parse_text_ref(&subheader[len-118], ctx);
  274|  3.58k|    if (compression_ref.length) {
  ------------------
  |  Branch (274:9): [True: 1.41k, False: 2.16k]
  ------------------
  275|  1.41k|        char compression[9];
  276|  1.41k|        if ((retval = sas7bdat_copy_text_ref(compression, sizeof(compression),
  ------------------
  |  Branch (276:13): [True: 58, False: 1.35k]
  ------------------
  277|  1.41k|                        compression_ref, ctx)) != READSTAT_OK) {
  278|     58|            goto cleanup;
  279|     58|        }
  280|  1.35k|        ctx->rdc_compression = (memcmp(compression, SAS_COMPRESSION_SIGNATURE_RDC, 8) == 0);
  ------------------
  |  |  130|  1.35k|#define SAS_COMPRESSION_SIGNATURE_RDC  "SASYZCR2"
  ------------------
  281|  1.35k|    }
  282|       |
  283|  3.52k|    ctx->row_length = row_length;
  284|  3.52k|    ctx->row = readstat_realloc(ctx->row, ctx->row_length);
  285|  3.52k|    if (ctx->row == NULL) {
  ------------------
  |  Branch (285:9): [True: 9, False: 3.51k]
  ------------------
  286|      9|        retval = READSTAT_ERROR_MALLOC;
  287|      9|        goto cleanup;
  288|      9|    }
  289|       |
  290|  3.51k|    ctx->page_row_count = page_row_count;
  291|  3.51k|    uint64_t live_row_count = total_row_count - deleted_row_count;
  292|  3.51k|    uint64_t total_row_count_after_skipping = live_row_count;
  293|  3.51k|    if (live_row_count > ctx->row_offset) {
  ------------------
  |  Branch (293:9): [True: 3.20k, False: 313]
  ------------------
  294|  3.20k|        total_row_count_after_skipping -= ctx->row_offset;
  295|  3.20k|    } else {
  296|    313|        total_row_count_after_skipping = 0;
  297|    313|        ctx->row_offset = live_row_count;
  298|    313|    }
  299|  3.51k|    if (ctx->row_limit == 0 || total_row_count_after_skipping < ctx->row_limit)
  ------------------
  |  Branch (299:9): [True: 1.39k, False: 2.12k]
  |  Branch (299:32): [True: 68, False: 2.05k]
  ------------------
  300|  1.46k|        ctx->row_limit = total_row_count_after_skipping;
  301|       |
  302|  3.68k|cleanup:
  303|  3.68k|    return retval;
  304|  3.51k|}
readstat_sas7bdat_read.c:sas7bdat_parse_text_ref:
  137|  42.0k|static sas_text_ref_t sas7bdat_parse_text_ref(const char *data, sas7bdat_ctx_t *ctx) {
  138|  42.0k|    sas_text_ref_t  ref;
  139|       |
  140|  42.0k|    ref.index = sas_read2(&data[0], ctx->bswap);
  141|  42.0k|    ref.offset = sas_read2(&data[2], ctx->bswap);
  142|  42.0k|    ref.length = sas_read2(&data[4], ctx->bswap);
  143|       |
  144|  42.0k|    return ref;
  145|  42.0k|}
readstat_sas7bdat_read.c:sas7bdat_copy_text_ref:
  147|  9.15M|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) {
  148|  9.15M|    if (text_ref.index >= ctx->text_blob_count)
  ------------------
  |  Branch (148:9): [True: 140, False: 9.15M]
  ------------------
  149|    140|        return READSTAT_ERROR_PARSE;
  150|       |    
  151|  9.15M|    if (text_ref.length == 0) {
  ------------------
  |  Branch (151:9): [True: 9.15M, False: 4.44k]
  ------------------
  152|  9.15M|        out_buffer[0] = '\0';
  153|  9.15M|        return READSTAT_OK;
  154|  9.15M|    }
  155|       |
  156|  4.44k|    char *blob = ctx->text_blobs[text_ref.index];
  157|       |
  158|  4.44k|    if (text_ref.offset + text_ref.length > ctx->text_blob_lengths[text_ref.index])
  ------------------
  |  Branch (158:9): [True: 78, False: 4.36k]
  ------------------
  159|     78|        return READSTAT_ERROR_PARSE;
  160|       |
  161|  4.36k|    return readstat_convert(out_buffer, out_buffer_len, &blob[text_ref.offset], text_ref.length,
  162|  4.36k|            ctx->converter);
  163|  4.44k|}
readstat_sas7bdat_read.c:sas7bdat_parse_column_size_subheader:
  208|  1.29k|static readstat_error_t sas7bdat_parse_column_size_subheader(const char *subheader, size_t len, sas7bdat_ctx_t *ctx) {
  209|  1.29k|    uint64_t col_count;
  210|  1.29k|    readstat_error_t retval = READSTAT_OK;
  211|       |
  212|  1.29k|    if (ctx->column_count || ctx->did_submit_columns) {
  ------------------
  |  Branch (212:9): [True: 9, False: 1.28k]
  |  Branch (212:30): [True: 3, False: 1.28k]
  ------------------
  213|     12|        retval = READSTAT_ERROR_PARSE;
  214|     12|        goto cleanup;
  215|     12|    }
  216|       |
  217|  1.28k|    if (len < (ctx->u64 ? 16 : 8)) {
  ------------------
  |  Branch (217:9): [True: 3, False: 1.28k]
  |  Branch (217:16): [True: 269, False: 1.01k]
  ------------------
  218|      3|        retval = READSTAT_ERROR_PARSE;
  219|      3|        goto cleanup;
  220|      3|    }
  221|       |
  222|  1.28k|    if (ctx->u64) {
  ------------------
  |  Branch (222:9): [True: 268, False: 1.01k]
  ------------------
  223|    268|        col_count = sas_read8(&subheader[8], ctx->bswap);
  224|  1.01k|    } else {
  225|  1.01k|        col_count = sas_read4(&subheader[4], ctx->bswap);
  226|  1.01k|    }
  227|       |
  228|  1.28k|    ctx->column_count = col_count;
  229|       |
  230|  1.28k|    retval = sas7bdat_realloc_col_info(ctx, ctx->column_count);
  231|       |
  232|  1.29k|cleanup:
  233|  1.29k|    return retval;
  234|  1.28k|}
readstat_sas7bdat_read.c:sas7bdat_realloc_col_info:
  195|  9.51k|static readstat_error_t sas7bdat_realloc_col_info(sas7bdat_ctx_t *ctx, size_t count) {
  196|  9.51k|    if (ctx->col_info_count < count) {
  ------------------
  |  Branch (196:9): [True: 3.74k, False: 5.76k]
  ------------------
  197|  3.74k|        size_t old_count = ctx->col_info_count;
  198|  3.74k|        ctx->col_info_count = count;
  199|  3.74k|        ctx->col_info = readstat_realloc(ctx->col_info, ctx->col_info_count * sizeof(col_info_t));
  200|  3.74k|        if (ctx->col_info == NULL) {
  ------------------
  |  Branch (200:13): [True: 87, False: 3.65k]
  ------------------
  201|     87|            return READSTAT_ERROR_MALLOC;
  202|     87|        }
  203|  3.65k|        memset(ctx->col_info + old_count, 0, (count - old_count) * sizeof(col_info_t));
  204|  3.65k|    }
  205|  9.42k|    return READSTAT_OK;
  206|  9.51k|}
readstat_sas7bdat_read.c:sas7bdat_parse_column_text_subheader:
  165|  2.67k|static readstat_error_t sas7bdat_parse_column_text_subheader(const char *subheader, size_t len, sas7bdat_ctx_t *ctx) {
  166|  2.67k|    readstat_error_t retval = READSTAT_OK;
  167|  2.67k|    size_t signature_len = ctx->subheader_signature_size;
  168|  2.67k|    uint16_t remainder = sas_read2(&subheader[signature_len], ctx->bswap);
  169|  2.67k|    char *blob = NULL;
  170|  2.67k|    if (remainder != sas_subheader_remainder(len, signature_len)) {
  ------------------
  |  Branch (170:9): [True: 65, False: 2.61k]
  ------------------
  171|     65|        retval = READSTAT_ERROR_PARSE;
  172|     65|        goto cleanup;
  173|     65|    }
  174|  2.61k|    ctx->text_blob_count++;
  175|  2.61k|    ctx->text_blobs = readstat_realloc(ctx->text_blobs, ctx->text_blob_count * sizeof(char *));
  176|  2.61k|    ctx->text_blob_lengths = readstat_realloc(ctx->text_blob_lengths,
  177|  2.61k|            ctx->text_blob_count * sizeof(ctx->text_blob_lengths[0]));
  178|  2.61k|    if (ctx->text_blobs == NULL || ctx->text_blob_lengths == NULL) {
  ------------------
  |  Branch (178:9): [True: 0, False: 2.61k]
  |  Branch (178:36): [True: 0, False: 2.61k]
  ------------------
  179|      0|        retval = READSTAT_ERROR_MALLOC;
  180|      0|        goto cleanup;
  181|      0|    }
  182|       |
  183|  2.61k|    if ((blob = readstat_malloc(len-signature_len)) == NULL) {
  ------------------
  |  Branch (183:9): [True: 0, False: 2.61k]
  ------------------
  184|      0|        retval = READSTAT_ERROR_MALLOC;
  185|      0|        goto cleanup;
  186|      0|    }
  187|  2.61k|    memcpy(blob, subheader+signature_len, len-signature_len);
  188|  2.61k|    ctx->text_blob_lengths[ctx->text_blob_count-1] = len-signature_len;
  189|  2.61k|    ctx->text_blobs[ctx->text_blob_count-1] = blob;
  190|       |
  191|  2.67k|cleanup:
  192|  2.67k|    return retval;
  193|  2.61k|}
readstat_sas7bdat_read.c:sas7bdat_parse_column_name_subheader:
  306|  2.73k|static readstat_error_t sas7bdat_parse_column_name_subheader(const char *subheader, size_t len, sas7bdat_ctx_t *ctx) {
  307|  2.73k|    readstat_error_t retval = READSTAT_OK;
  308|  2.73k|    size_t signature_len = ctx->subheader_signature_size;
  309|  2.73k|    int cmax = ctx->u64 ? (len-28)/8 : (len-20)/8;
  ------------------
  |  Branch (309:16): [True: 1.62k, False: 1.11k]
  ------------------
  310|  2.73k|    int i;
  311|  2.73k|    const char *cnp = &subheader[signature_len+8];
  312|  2.73k|    uint16_t remainder = sas_read2(&subheader[signature_len], ctx->bswap);
  313|       |
  314|  2.73k|    if (remainder != sas_subheader_remainder(len, signature_len)) {
  ------------------
  |  Branch (314:9): [True: 56, False: 2.68k]
  ------------------
  315|     56|        retval = READSTAT_ERROR_PARSE;
  316|     56|        goto cleanup;
  317|     56|    }
  318|       |
  319|  2.68k|    ctx->col_names_count += cmax;
  320|       |
  321|  2.68k|    if ((retval = sas7bdat_realloc_col_info(ctx, ctx->col_names_count)) != READSTAT_OK)
  ------------------
  |  Branch (321:9): [True: 14, False: 2.66k]
  ------------------
  322|     14|        goto cleanup;
  323|       |
  324|  30.3k|    for (i=ctx->col_names_count-cmax; i<ctx->col_names_count; i++) {
  ------------------
  |  Branch (324:39): [True: 27.6k, False: 2.66k]
  ------------------
  325|  27.6k|        ctx->col_info[i].name_ref = sas7bdat_parse_text_ref(cnp, ctx);
  326|  27.6k|        cnp += 8;
  327|  27.6k|    }
  328|       |
  329|  2.73k|cleanup:
  330|       |
  331|  2.73k|    return retval;
  332|  2.66k|}
readstat_sas7bdat_read.c:sas7bdat_parse_column_attributes_subheader:
  334|  2.02k|static readstat_error_t sas7bdat_parse_column_attributes_subheader(const char *subheader, size_t len, sas7bdat_ctx_t *ctx) {
  335|  2.02k|    readstat_error_t retval = READSTAT_OK;
  336|  2.02k|    size_t signature_len = ctx->subheader_signature_size;
  337|  2.02k|    int cmax = ctx->u64 ? (len-28)/16 : (len-20)/12;
  ------------------
  |  Branch (337:16): [True: 320, False: 1.70k]
  ------------------
  338|  2.02k|    int i;
  339|  2.02k|    const char *cap = &subheader[signature_len+8];
  340|  2.02k|    uint16_t remainder = sas_read2(&subheader[signature_len], ctx->bswap);
  341|       |
  342|  2.02k|    if (remainder != sas_subheader_remainder(len, signature_len)) {
  ------------------
  |  Branch (342:9): [True: 54, False: 1.97k]
  ------------------
  343|     54|        retval = READSTAT_ERROR_PARSE;
  344|     54|        goto cleanup;
  345|     54|    }
  346|  1.97k|    ctx->col_attrs_count += cmax;
  347|  1.97k|    if ((retval = sas7bdat_realloc_col_info(ctx, ctx->col_attrs_count)) != READSTAT_OK)
  ------------------
  |  Branch (347:9): [True: 11, False: 1.96k]
  ------------------
  348|     11|        goto cleanup;
  349|       |
  350|  9.93k|    for (i=ctx->col_attrs_count-cmax; i<ctx->col_attrs_count; i++) {
  ------------------
  |  Branch (350:39): [True: 7.98k, False: 1.94k]
  ------------------
  351|  7.98k|        if (ctx->u64) {
  ------------------
  |  Branch (351:13): [True: 839, False: 7.14k]
  ------------------
  352|    839|            ctx->col_info[i].offset = sas_read8(&cap[0], ctx->bswap);
  353|  7.14k|        } else {
  354|  7.14k|            ctx->col_info[i].offset = sas_read4(&cap[0], ctx->bswap);
  355|  7.14k|        }
  356|       |
  357|  7.98k|        readstat_off_t off=4;
  358|  7.98k|        if (ctx->u64)
  ------------------
  |  Branch (358:13): [True: 839, False: 7.14k]
  ------------------
  359|    839|            off=8;
  360|       |
  361|  7.98k|        ctx->col_info[i].width = sas_read4(&cap[off], ctx->bswap);
  362|  7.98k|        if (ctx->col_info[i].width > ctx->max_col_width)
  ------------------
  |  Branch (362:13): [True: 873, False: 7.11k]
  ------------------
  363|    873|            ctx->max_col_width = ctx->col_info[i].width;
  364|       |
  365|  7.98k|        if (cap[off+6] == SAS_COLUMN_TYPE_NUM) {
  ------------------
  |  |   89|  7.98k|#define SAS_COLUMN_TYPE_NUM  0x01
  ------------------
  |  Branch (365:13): [True: 4.92k, False: 3.06k]
  ------------------
  366|  4.92k|            ctx->col_info[i].type = READSTAT_TYPE_DOUBLE;
  367|  4.92k|        } else if (cap[off+6] == SAS_COLUMN_TYPE_CHR) {
  ------------------
  |  |   90|  3.06k|#define SAS_COLUMN_TYPE_CHR  0x02
  ------------------
  |  Branch (367:20): [True: 3.04k, False: 16]
  ------------------
  368|  3.04k|            ctx->col_info[i].type = READSTAT_TYPE_STRING;
  369|  3.04k|        } else {
  370|     16|            retval = READSTAT_ERROR_PARSE;
  371|     16|            goto cleanup;
  372|     16|        }
  373|  7.97k|        ctx->col_info[i].index = i;
  374|  7.97k|        cap += off+8;
  375|  7.97k|    }
  376|       |
  377|  2.02k|cleanup:
  378|       |
  379|  2.02k|    return retval;
  380|  1.96k|}
readstat_sas7bdat_read.c:sas7bdat_parse_column_format_subheader:
  382|  3.57k|static readstat_error_t sas7bdat_parse_column_format_subheader(const char *subheader, size_t len, sas7bdat_ctx_t *ctx) {
  383|  3.57k|    readstat_error_t retval = READSTAT_OK;
  384|       |
  385|  3.57k|    if (len < (ctx->u64 ? 58 : 46)) {
  ------------------
  |  Branch (385:9): [True: 3, False: 3.57k]
  |  Branch (385:16): [True: 344, False: 3.23k]
  ------------------
  386|      3|        retval = READSTAT_ERROR_PARSE;
  387|      3|        goto cleanup;
  388|      3|    }
  389|       |
  390|  3.57k|    ctx->col_formats_count++;
  391|  3.57k|    if ((retval = sas7bdat_realloc_col_info(ctx, ctx->col_formats_count)) != READSTAT_OK)
  ------------------
  |  Branch (391:9): [True: 0, False: 3.57k]
  ------------------
  392|      0|        goto cleanup;
  393|       |
  394|  3.57k|    if (ctx->u64) {
  ------------------
  |  Branch (394:9): [True: 343, False: 3.23k]
  ------------------
  395|    343|        ctx->col_info[ctx->col_formats_count-1].format_width = sas_read2(&subheader[24], ctx->bswap);
  396|    343|        ctx->col_info[ctx->col_formats_count-1].format_digits = sas_read2(&subheader[26], ctx->bswap);
  397|  3.23k|    } else {
  398|  3.23k|        ctx->col_info[ctx->col_formats_count-1].format_width = sas_read2(&subheader[12], ctx->bswap);
  399|  3.23k|        ctx->col_info[ctx->col_formats_count-1].format_digits = sas_read2(&subheader[14], ctx->bswap);
  400|  3.23k|    }
  401|  3.57k|    ctx->col_info[ctx->col_formats_count-1].format_ref = sas7bdat_parse_text_ref(
  402|  3.57k|            ctx->u64 ? &subheader[46] : &subheader[34], ctx);
  ------------------
  |  Branch (402:13): [True: 343, False: 3.23k]
  ------------------
  403|  3.57k|    ctx->col_info[ctx->col_formats_count-1].label_ref = sas7bdat_parse_text_ref(
  404|  3.57k|            ctx->u64 ? &subheader[52] : &subheader[40], ctx);
  ------------------
  |  Branch (404:13): [True: 343, False: 3.23k]
  ------------------
  405|       |
  406|  3.57k|cleanup:
  407|  3.57k|    return retval;
  408|  3.57k|}
readstat_sas7bdat_read.c:sas7bdat_parse_amd_pages_pass1:
 1184|  2.91k|static readstat_error_t sas7bdat_parse_amd_pages_pass1(int64_t last_examined_page_pass1, sas7bdat_ctx_t *ctx) {
 1185|  2.91k|    readstat_error_t retval = READSTAT_OK;
 1186|  2.91k|    readstat_io_t *io = ctx->io;
 1187|  2.91k|    uint64_t i;
 1188|  2.91k|    uint64_t amd_page_count = 0;
 1189|       |
 1190|       |    /* ...then AMD pages at the end */
 1191|  6.25k|    for (i=ctx->page_count-1; i>last_examined_page_pass1; i--) {
  ------------------
  |  Branch (1191:31): [True: 4.63k, False: 1.62k]
  ------------------
 1192|  4.63k|        if (io->seek(ctx->header_size + i*ctx->page_size, READSTAT_SEEK_SET, io->io_ctx) == -1) {
  ------------------
  |  Branch (1192:13): [True: 220, False: 4.41k]
  ------------------
 1193|    220|            retval = READSTAT_ERROR_SEEK;
 1194|    220|            if (ctx->handle.error) {
  ------------------
  |  Branch (1194:17): [True: 0, False: 220]
  ------------------
 1195|      0|                snprintf(ctx->error_buf, sizeof(ctx->error_buf), "ReadStat: Failed to seek to position %" PRId64 
 1196|      0|                        " (= %" PRId64 " + %" PRId64 "*%" PRId64 ")",
 1197|      0|                        ctx->header_size + i*ctx->page_size, ctx->header_size, i, ctx->page_size);
 1198|      0|                ctx->handle.error(ctx->error_buf, ctx->user_ctx);
 1199|      0|            }
 1200|    220|            goto cleanup;
 1201|    220|        }
 1202|       |
 1203|  4.41k|        readstat_off_t off = 0;
 1204|  4.41k|        if (ctx->u64)
  ------------------
  |  Branch (1204:13): [True: 3.30k, False: 1.10k]
  ------------------
 1205|  3.30k|            off = 16;
 1206|       |
 1207|  4.41k|        size_t head_len = off + 16 + 2;
 1208|  4.41k|        size_t tail_len = ctx->page_size - head_len;
 1209|       |
 1210|  4.41k|        if (io->read(ctx->page, head_len, io->io_ctx) < head_len) {
  ------------------
  |  Branch (1210:13): [True: 9, False: 4.40k]
  ------------------
 1211|      9|            retval = READSTAT_ERROR_READ;
 1212|      9|            goto cleanup;
 1213|      9|        }
 1214|       |
 1215|  4.40k|        uint16_t page_type = sas_read2(&ctx->page[off+16], ctx->bswap);
 1216|       |
 1217|  4.40k|        if ((page_type & SAS_PAGE_TYPE_MASK) == SAS_PAGE_TYPE_DATA) {
  ------------------
  |  |  112|  4.40k|#define SAS_PAGE_TYPE_MASK   0x0F00
  ------------------
                      if ((page_type & SAS_PAGE_TYPE_MASK) == SAS_PAGE_TYPE_DATA) {
  ------------------
  |  |  109|  4.40k|#define SAS_PAGE_TYPE_DATA   0x0100
  ------------------
  |  Branch (1217:13): [True: 1.04k, False: 3.35k]
  ------------------
 1218|       |            /* Usually AMD pages are at the end but sometimes data pages appear after them */
 1219|  1.04k|            if (amd_page_count > 0)
  ------------------
  |  Branch (1219:17): [True: 377, False: 669]
  ------------------
 1220|    377|                break;
 1221|    669|            continue;
 1222|  1.04k|        }
 1223|  3.35k|        if ((page_type & SAS_PAGE_TYPE_COMP))
  ------------------
  |  |  116|  3.35k|#define SAS_PAGE_TYPE_COMP          0x9000
  ------------------
  |  Branch (1223:13): [True: 807, False: 2.54k]
  ------------------
 1224|    807|            continue;
 1225|       |
 1226|  2.54k|        if (io->read(ctx->page + head_len, tail_len, io->io_ctx) < tail_len) {
  ------------------
  |  Branch (1226:13): [True: 18, False: 2.53k]
  ------------------
 1227|     18|            retval = READSTAT_ERROR_READ;
 1228|     18|            goto cleanup;
 1229|     18|        }
 1230|       |
 1231|  2.53k|        if ((retval = sas7bdat_parse_page_pass1(ctx->page, ctx->page_size, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1231:13): [True: 675, False: 1.85k]
  ------------------
 1232|    675|            if (ctx->handle.error && retval != READSTAT_ERROR_USER_ABORT) {
  ------------------
  |  Branch (1232:17): [True: 0, False: 675]
  |  Branch (1232:38): [True: 0, False: 0]
  ------------------
 1233|      0|                int64_t pos = io->seek(0, READSTAT_SEEK_CUR, io->io_ctx);
 1234|      0|                snprintf(ctx->error_buf, sizeof(ctx->error_buf), 
 1235|      0|                        "ReadStat: Error parsing page %" PRId64 ", bytes %" PRId64 "-%" PRId64, 
 1236|      0|                        i, pos - ctx->page_size, pos-1);
 1237|      0|                ctx->handle.error(ctx->error_buf, ctx->user_ctx);
 1238|      0|            }
 1239|    675|            goto cleanup;
 1240|    675|        }
 1241|       |
 1242|  1.85k|        amd_page_count++;
 1243|  1.85k|    }
 1244|       |
 1245|  2.91k|cleanup:
 1246|       |
 1247|  2.91k|    return retval;
 1248|  2.91k|}
readstat_sas7bdat_read.c:sas7bdat_parse_all_pages_pass2:
 1250|  1.99k|static readstat_error_t sas7bdat_parse_all_pages_pass2(sas7bdat_ctx_t *ctx) {
 1251|  1.99k|    readstat_error_t retval = READSTAT_OK;
 1252|  1.99k|    readstat_io_t *io = ctx->io;
 1253|  1.99k|    int64_t i;
 1254|       |
 1255|  4.89k|    for (i=0; i<ctx->page_count; i++) {
  ------------------
  |  Branch (1255:15): [True: 4.73k, False: 158]
  ------------------
 1256|  4.73k|        if ((retval = sas7bdat_update_progress(ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1256:13): [True: 0, False: 4.73k]
  ------------------
 1257|      0|            goto cleanup;
 1258|      0|        }
 1259|  4.73k|        if (io->read(ctx->page, ctx->page_size, io->io_ctx) < ctx->page_size) {
  ------------------
  |  Branch (1259:13): [True: 142, False: 4.59k]
  ------------------
 1260|    142|            retval = READSTAT_ERROR_READ;
 1261|    142|            goto cleanup;
 1262|    142|        }
 1263|       |
 1264|  4.59k|        if ((retval = sas7bdat_parse_page_pass2(ctx->page, ctx->page_size, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1264:13): [True: 1.48k, False: 3.10k]
  ------------------
 1265|  1.48k|            if (ctx->handle.error && retval != READSTAT_ERROR_USER_ABORT) {
  ------------------
  |  Branch (1265:17): [True: 0, False: 1.48k]
  |  Branch (1265:38): [True: 0, False: 0]
  ------------------
 1266|      0|                int64_t pos = io->seek(0, READSTAT_SEEK_CUR, io->io_ctx);
 1267|      0|                snprintf(ctx->error_buf, sizeof(ctx->error_buf), 
 1268|      0|                        "ReadStat: Error parsing page %" PRId64 ", bytes %" PRId64 "-%" PRId64, 
 1269|      0|                        i, pos - ctx->page_size, pos-1);
 1270|      0|                ctx->handle.error(ctx->error_buf, ctx->user_ctx);
 1271|      0|            }
 1272|  1.48k|            goto cleanup;
 1273|  1.48k|        }
 1274|  3.10k|        if (ctx->parsed_row_count == ctx->row_limit)
  ------------------
  |  Branch (1274:13): [True: 208, False: 2.89k]
  ------------------
 1275|    208|            break;
 1276|  3.10k|    }
 1277|  1.99k|cleanup:
 1278|       |
 1279|  1.99k|    return retval;
 1280|  1.99k|}
readstat_sas7bdat_read.c:sas7bdat_parse_page_pass2:
 1015|  4.59k|static readstat_error_t sas7bdat_parse_page_pass2(const char *page, size_t page_size, sas7bdat_ctx_t *ctx) {
 1016|  4.59k|    uint16_t page_type;
 1017|       |
 1018|  4.59k|    readstat_error_t retval = READSTAT_OK;
 1019|       |
 1020|  4.59k|    page_type = sas_read2(&page[ctx->page_header_size-8], ctx->bswap);
 1021|       |
 1022|  4.59k|    const char *data = NULL;
 1023|       |
 1024|  4.59k|    if ((page_type & SAS_PAGE_TYPE_MASK) == SAS_PAGE_TYPE_DATA) {
  ------------------
  |  |  112|  4.59k|#define SAS_PAGE_TYPE_MASK   0x0F00
  ------------------
                  if ((page_type & SAS_PAGE_TYPE_MASK) == SAS_PAGE_TYPE_DATA) {
  ------------------
  |  |  109|  4.59k|#define SAS_PAGE_TYPE_DATA   0x0100
  ------------------
  |  Branch (1024:9): [True: 949, False: 3.64k]
  ------------------
 1025|    949|        ctx->page_row_count = sas_read2(&page[ctx->page_header_size-6], ctx->bswap);
 1026|    949|        data = &page[ctx->page_header_size];
 1027|  3.64k|    } else if (!(page_type & SAS_PAGE_TYPE_COMP)) {
  ------------------
  |  |  116|  3.64k|#define SAS_PAGE_TYPE_COMP          0x9000
  ------------------
  |  Branch (1027:16): [True: 3.35k, False: 289]
  ------------------
 1028|  3.35k|        uint16_t subheader_count = sas_read2(&page[ctx->page_header_size-4], ctx->bswap);
 1029|       |
 1030|  3.35k|        int i;
 1031|  3.35k|        const char *shp = &page[ctx->page_header_size];
 1032|  3.35k|        int lshp = ctx->subheader_pointer_size;
 1033|       |
 1034|  3.35k|        if (ctx->page_header_size + subheader_count*lshp > page_size) {
  ------------------
  |  Branch (1034:13): [True: 7, False: 3.34k]
  ------------------
 1035|      7|            retval = READSTAT_ERROR_PARSE;
 1036|      7|            goto cleanup;
 1037|      7|        }
 1038|       |
 1039|  42.2k|        for (i=0; i<subheader_count; i++) {
  ------------------
  |  Branch (1039:19): [True: 39.9k, False: 2.30k]
  ------------------
 1040|  39.9k|            subheader_pointer_t shp_info = { 0 };
 1041|  39.9k|            if ((retval = sas7bdat_parse_subheader_pointer(shp, page + page_size - shp, &shp_info, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1041:17): [True: 0, False: 39.9k]
  ------------------
 1042|      0|                goto cleanup;
 1043|      0|            }
 1044|  39.9k|            if (shp_info.len > 0 && shp_info.compression != SAS_COMPRESSION_TRUNC) {
  ------------------
  |  |  125|  25.2k|#define SAS_COMPRESSION_TRUNC        0x01
  ------------------
  |  Branch (1044:17): [True: 25.2k, False: 14.6k]
  |  Branch (1044:37): [True: 20.6k, False: 4.58k]
  ------------------
 1045|  20.6k|                if ((retval = sas7bdat_validate_subheader_pointer(&shp_info, page_size, subheader_count, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1045:21): [True: 210, False: 20.4k]
  ------------------
 1046|    210|                    goto cleanup;
 1047|    210|                }
 1048|  20.4k|                if (shp_info.compression == SAS_COMPRESSION_NONE) {
  ------------------
  |  |  124|  20.4k|#define SAS_COMPRESSION_NONE         0x00
  ------------------
  |  Branch (1048:21): [True: 18.3k, False: 2.06k]
  ------------------
 1049|  18.3k|                    sas_subheader_type_t subheader_type = sas7bdat_parse_subheader_type(page + shp_info.offset, ctx);
 1050|  18.3k|                    if (shp_info.is_compressed_data && subheader_type == SAS_SUBHEADER_TYPE_DATA) {
  ------------------
  |  Branch (1050:25): [True: 13.4k, False: 4.91k]
  |  Branch (1050:56): [True: 625, False: 12.8k]
  ------------------
 1051|    625|                        if (shp_info.len != ctx->row_length) {
  ------------------
  |  Branch (1051:29): [True: 112, False: 513]
  ------------------
 1052|    112|                            retval = READSTAT_ERROR_ROW_WIDTH_MISMATCH;
 1053|    112|                            goto cleanup;
 1054|    112|                        }
 1055|    513|                        if ((retval = sas7bdat_submit_columns_if_needed(ctx, 1)) != READSTAT_OK) {
  ------------------
  |  Branch (1055:29): [True: 8, False: 505]
  ------------------
 1056|      8|                            goto cleanup;
 1057|      8|                        }
 1058|    505|                        if ((retval = sas7bdat_parse_single_row(page + shp_info.offset, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1058:29): [True: 8, False: 497]
  ------------------
 1059|      8|                            goto cleanup;
 1060|      8|                        }
 1061|  17.7k|                    } else {
 1062|  17.7k|                        if (subheader_type != SAS_SUBHEADER_TYPE_COLUMN_TEXT) {
  ------------------
  |  Branch (1062:29): [True: 16.0k, False: 1.70k]
  ------------------
 1063|  16.0k|                            if ((retval = sas7bdat_parse_subheader(subheader_type, page + shp_info.offset, shp_info.len, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1063:33): [True: 444, False: 15.6k]
  ------------------
 1064|    444|                                goto cleanup;
 1065|    444|                            }
 1066|  16.0k|                        }
 1067|  17.7k|                    }
 1068|  18.3k|                } else if (shp_info.compression == SAS_COMPRESSION_ROW) {
  ------------------
  |  |  126|  2.06k|#define SAS_COMPRESSION_ROW          0x04
  ------------------
  |  Branch (1068:28): [True: 1.80k, False: 258]
  ------------------
 1069|  1.80k|                    if ((retval = sas7bdat_submit_columns_if_needed(ctx, 1)) != READSTAT_OK) {
  ------------------
  |  Branch (1069:25): [True: 21, False: 1.78k]
  ------------------
 1070|     21|                        goto cleanup;
 1071|     21|                    }
 1072|  1.78k|                    if ((retval = sas7bdat_parse_subheader_compressed(page + shp_info.offset, shp_info.len, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1072:25): [True: 233, False: 1.55k]
  ------------------
 1073|    233|                        goto cleanup;
 1074|    233|                    }
 1075|  1.78k|                } else if (shp_info.compression == SAS_COMPRESSION_DELETED_ROW) {
  ------------------
  |  |  127|    258|#define SAS_COMPRESSION_DELETED_ROW  0x05
  ------------------
  |  Branch (1075:28): [True: 251, False: 7]
  ------------------
 1076|    251|                    if ((retval = sas7bdat_register_deleted_row(ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1076:25): [True: 2, False: 249]
  ------------------
 1077|      2|                        goto cleanup;
 1078|      2|                    }
 1079|    251|                } else {
 1080|      7|                    retval = READSTAT_ERROR_UNSUPPORTED_COMPRESSION;
 1081|      7|                    goto cleanup;
 1082|      7|                }
 1083|  20.4k|            }
 1084|       |
 1085|  38.8k|            shp += lshp;
 1086|  38.8k|        }
 1087|       |
 1088|  2.30k|        if ((page_type & SAS_PAGE_TYPE_MASK) == SAS_PAGE_TYPE_MIX) {
  ------------------
  |  |  112|  2.30k|#define SAS_PAGE_TYPE_MASK   0x0F00
  ------------------
                      if ((page_type & SAS_PAGE_TYPE_MASK) == SAS_PAGE_TYPE_MIX) {
  ------------------
  |  |  110|  2.30k|#define SAS_PAGE_TYPE_MIX    0x0200
  ------------------
  |  Branch (1088:13): [True: 1.25k, False: 1.04k]
  ------------------
 1089|       |            /* HACK - this is supposed to obey 8-byte boundaries but
 1090|       |             * some files created by Stat/Transfer don't. So verify that the
 1091|       |             * padding is { 0, 0, 0, 0 } or { ' ', ' ', ' ', ' ' } (or that
 1092|       |             * the file is not from Stat/Transfer) before skipping it */
 1093|  1.25k|            if ((shp-page)%8 == 4 && shp + 4 <= page + page_size &&
  ------------------
  |  Branch (1093:17): [True: 426, False: 829]
  |  Branch (1093:38): [True: 423, False: 3]
  ------------------
 1094|    423|                    (*(uint32_t *)shp == 0x00000000 ||
  ------------------
  |  Branch (1094:22): [True: 100, False: 323]
  ------------------
 1095|    323|                     *(uint32_t *)shp == 0x20202020 ||
  ------------------
  |  Branch (1095:22): [True: 51, False: 272]
  ------------------
 1096|    385|                     ctx->vendor != READSTAT_VENDOR_STAT_TRANSFER)) {
  ------------------
  |  Branch (1096:22): [True: 234, False: 38]
  ------------------
 1097|    385|                data = shp + 4;
 1098|    870|            } else {
 1099|    870|                data = shp;
 1100|    870|            }
 1101|  1.25k|        }
 1102|  2.30k|    }
 1103|  3.54k|    if (data) {
  ------------------
  |  Branch (1103:9): [True: 2.20k, False: 1.33k]
  ------------------
 1104|  2.20k|        if ((retval = sas7bdat_submit_columns_if_needed(ctx, 0)) != READSTAT_OK) {
  ------------------
  |  Branch (1104:13): [True: 121, False: 2.08k]
  ------------------
 1105|    121|            goto cleanup;
 1106|    121|        }
 1107|  2.08k|        if (ctx->handle.value) {
  ------------------
  |  Branch (1107:13): [True: 2.08k, False: 0]
  ------------------
 1108|  2.08k|            const unsigned char *deleted_row_bitmap = NULL;
 1109|  2.08k|            if (page_type & SAS_PAGE_TYPE_DELETED_ROWS) {
  ------------------
  |  |  114|  2.08k|#define SAS_PAGE_TYPE_DELETED_ROWS  0x0080
  ------------------
  |  Branch (1109:17): [True: 485, False: 1.59k]
  ------------------
 1110|    485|                if ((retval = sas7bdat_parse_deleted_row_bitmap(page, data, page_size,
  ------------------
  |  Branch (1110:21): [True: 121, False: 364]
  ------------------
 1111|    485|                        &deleted_row_bitmap, ctx)) != READSTAT_OK) {
 1112|    121|                    goto cleanup;
 1113|    121|                }
 1114|    485|            }
 1115|  1.96k|            retval = sas7bdat_parse_rows(data, page + page_size - data, deleted_row_bitmap, ctx);
 1116|  1.96k|        }
 1117|  2.08k|    } 
 1118|  4.59k|cleanup:
 1119|       |
 1120|  4.59k|    return retval;
 1121|  3.54k|}
readstat_sas7bdat_read.c:sas7bdat_parse_single_row:
  482|   235k|static readstat_error_t sas7bdat_parse_single_row(const char *data, sas7bdat_ctx_t *ctx) {
  483|   235k|    if (ctx->parsed_row_count == ctx->row_limit)
  ------------------
  |  Branch (483:9): [True: 379, False: 235k]
  ------------------
  484|    379|        return READSTAT_OK;
  485|   235k|    if (ctx->row_offset) {
  ------------------
  |  Branch (485:9): [True: 0, False: 235k]
  ------------------
  486|      0|        ctx->row_offset--;
  487|      0|        return READSTAT_OK;
  488|      0|    }
  489|       |
  490|   235k|    readstat_error_t retval = READSTAT_OK;
  491|   235k|    int j;
  492|   235k|    if (ctx->handle.value) {
  ------------------
  |  Branch (492:9): [True: 235k, False: 0]
  ------------------
  493|   235k|        ctx->scratch_buffer_len = 4*ctx->max_col_width+1;
  494|   235k|        ctx->scratch_buffer = readstat_realloc(ctx->scratch_buffer, ctx->scratch_buffer_len);
  495|   235k|        if (ctx->scratch_buffer == NULL) {
  ------------------
  |  Branch (495:13): [True: 4, False: 235k]
  ------------------
  496|      4|            retval = READSTAT_ERROR_MALLOC;
  497|      4|            goto cleanup;
  498|      4|        }
  499|       |
  500|  19.7M|        for (j=0; j<ctx->column_count; j++) {
  ------------------
  |  Branch (500:19): [True: 19.5M, False: 235k]
  ------------------
  501|  19.5M|            col_info_t *col_info = &ctx->col_info[j];
  502|  19.5M|            readstat_variable_t *variable = ctx->variables[j];
  503|  19.5M|            if (variable->skip)
  ------------------
  |  Branch (503:17): [True: 0, False: 19.5M]
  ------------------
  504|      0|                continue;
  505|       |
  506|  19.5M|            if (col_info->offset > ctx->row_length || col_info->offset + col_info->width > ctx->row_length) {
  ------------------
  |  Branch (506:17): [True: 94, False: 19.5M]
  |  Branch (506:55): [True: 23, False: 19.5M]
  ------------------
  507|    117|                retval = READSTAT_ERROR_PARSE;
  508|    117|                goto cleanup;
  509|    117|            }
  510|  19.5M|            retval = sas7bdat_handle_data_value(variable, col_info, &data[col_info->offset], ctx);
  511|  19.5M|            if (retval != READSTAT_OK) {
  ------------------
  |  Branch (511:17): [True: 15, False: 19.5M]
  ------------------
  512|     15|                goto cleanup;
  513|     15|            }
  514|  19.5M|        }
  515|   235k|    }
  516|   235k|    ctx->parsed_row_count++;
  517|       |
  518|   235k|cleanup:
  519|   235k|    return retval;
  520|   235k|}
readstat_sas7bdat_read.c:sas7bdat_handle_data_value:
  419|  19.5M|        col_info_t *col_info, const char *col_data, sas7bdat_ctx_t *ctx) {
  420|  19.5M|    readstat_error_t retval = READSTAT_OK;
  421|  19.5M|    int cb_retval = 0;
  422|  19.5M|    readstat_value_t value;
  423|  19.5M|    memset(&value, 0, sizeof(readstat_value_t));
  424|       |
  425|  19.5M|    value.type = col_info->type;
  426|       |
  427|  19.5M|    if (col_info->type == READSTAT_TYPE_STRING) {
  ------------------
  |  Branch (427:9): [True: 19.3M, False: 134k]
  ------------------
  428|  19.3M|        retval = readstat_convert(ctx->scratch_buffer, ctx->scratch_buffer_len,
  429|  19.3M|                col_data, col_info->width, ctx->converter);
  430|  19.3M|        if (retval != READSTAT_OK) {
  ------------------
  |  Branch (430:13): [True: 13, False: 19.3M]
  ------------------
  431|     13|            if (ctx->handle.error) {
  ------------------
  |  Branch (431:17): [True: 0, False: 13]
  ------------------
  432|      0|                snprintf(ctx->error_buf, sizeof(ctx->error_buf),
  433|      0|                        "ReadStat: Error converting string (row=%u, col=%u) to specified encoding: %.*s",
  434|      0|                        ctx->parsed_row_count+1, col_info->index+1, col_info->width, col_data);
  435|      0|                ctx->handle.error(ctx->error_buf, ctx->user_ctx);
  436|      0|            }
  437|     13|            goto cleanup;
  438|     13|        }
  439|       |
  440|  19.3M|        value.v.string_value = ctx->scratch_buffer;
  441|  19.3M|    } else if (col_info->type == READSTAT_TYPE_DOUBLE) {
  ------------------
  |  Branch (441:16): [True: 134k, False: 0]
  ------------------
  442|   134k|        uint64_t  val = 0;
  443|   134k|        double dval = NAN;
  444|   134k|        if (col_info->width < 1 || col_info->width > 8) {
  ------------------
  |  Branch (444:13): [True: 1, False: 134k]
  |  Branch (444:36): [True: 1, False: 134k]
  ------------------
  445|       |            /* A DOUBLE is 3-8 bytes on disk, but col_info can be mutated by a
  446|       |             * COLUMN_ATTRS subheader after the columns were validated. Guard
  447|       |             * here so a corrupt width can't produce an undefined shift below. */
  448|      2|            retval = READSTAT_ERROR_PARSE;
  449|      2|            goto cleanup;
  450|      2|        }
  451|   134k|        if (ctx->little_endian) {
  ------------------
  |  Branch (451:13): [True: 134k, False: 0]
  ------------------
  452|   134k|            int k;
  453|   922k|            for (k=0; k<col_info->width; k++) {
  ------------------
  |  Branch (453:23): [True: 787k, False: 134k]
  ------------------
  454|   787k|                val = (val << 8) | (unsigned char)col_data[col_info->width-1-k];
  455|   787k|            }
  456|   134k|        } else {
  457|      0|            int k;
  458|      0|            for (k=0; k<col_info->width; k++) {
  ------------------
  |  Branch (458:23): [True: 0, False: 0]
  ------------------
  459|      0|                val = (val << 8) | (unsigned char)col_data[k];
  460|      0|            }
  461|      0|        }
  462|   134k|        val <<= (8-col_info->width)*8;
  463|       |
  464|   134k|        memcpy(&dval, &val, 8);
  465|       |
  466|   134k|        if (isnan(dval)) {
  ------------------
  |  Branch (466:13): [True: 8.56k, False: 126k]
  ------------------
  467|  8.56k|            value.v.double_value = NAN;
  468|  8.56k|            sas_assign_tag(&value, ~((val >> 40) & 0xFF));
  469|   126k|        } else {
  470|   126k|            value.v.double_value = dval;
  471|   126k|        }
  472|   134k|    }
  473|  19.5M|    cb_retval = ctx->handle.value(ctx->parsed_row_count, variable, value, ctx->user_ctx);
  474|       |
  475|  19.5M|    if (cb_retval != READSTAT_HANDLER_OK)
  ------------------
  |  Branch (475:9): [True: 0, False: 19.5M]
  ------------------
  476|      0|        retval = READSTAT_ERROR_USER_ABORT;
  477|       |
  478|  19.5M|cleanup:
  479|  19.5M|    return retval;
  480|  19.5M|}
readstat_sas7bdat_read.c:sas7bdat_parse_subheader_compressed:
  668|  1.78k|static readstat_error_t sas7bdat_parse_subheader_compressed(const char *subheader, size_t len, sas7bdat_ctx_t *ctx) {
  669|  1.78k|    if (ctx->rdc_compression)
  ------------------
  |  Branch (669:9): [True: 408, False: 1.37k]
  ------------------
  670|    408|        return sas7bdat_parse_subheader_rdc(subheader, len, ctx);
  671|       |
  672|  1.37k|    return sas7bdat_parse_subheader_rle(subheader, len, ctx);
  673|  1.78k|}
readstat_sas7bdat_read.c:sas7bdat_parse_subheader_rdc:
  554|    408|static readstat_error_t sas7bdat_parse_subheader_rdc(const char *subheader, size_t len, sas7bdat_ctx_t *ctx) {
  555|    408|    readstat_error_t retval = READSTAT_OK;
  556|    408|    const unsigned char *input = (const unsigned char *)subheader;
  557|    408|    char *buffer = malloc(ctx->row_length);
  558|    408|    if (buffer == NULL) return READSTAT_ERROR_MALLOC;
  ------------------
  |  Branch (558:9): [True: 0, False: 408]
  ------------------
  559|    408|    char *output = buffer;
  560|  1.63k|    while (input + 2 <= (const unsigned char *)subheader + len) {
  ------------------
  |  Branch (560:12): [True: 1.26k, False: 367]
  ------------------
  561|  1.26k|        int i;
  562|  1.26k|        unsigned short prefix = (input[0] << 8) + input[1];
  563|  1.26k|        input += 2;
  564|  16.7k|        for (i=0; i<16; i++) {
  ------------------
  |  Branch (564:19): [True: 15.9k, False: 857]
  ------------------
  565|  15.9k|            if ((prefix & (1 << (15 - i))) == 0) {
  ------------------
  |  Branch (565:17): [True: 12.5k, False: 3.34k]
  ------------------
  566|  12.5k|                if (input + 1 > (const unsigned char *)subheader + len) {
  ------------------
  |  Branch (566:21): [True: 365, False: 12.2k]
  ------------------
  567|    365|                    break;
  568|    365|                }
  569|  12.2k|                if (output + 1 > buffer + ctx->row_length) {
  ------------------
  |  Branch (569:21): [True: 4, False: 12.1k]
  ------------------
  570|      4|                    retval = READSTAT_ERROR_ROW_WIDTH_MISMATCH;
  571|      4|                    goto cleanup;
  572|      4|                }
  573|  12.1k|                *output++ = *input++;
  574|  12.1k|                continue;
  575|  12.2k|            }
  576|       |
  577|  3.34k|            if (input + 2 > (const unsigned char *)subheader + len) {
  ------------------
  |  Branch (577:17): [True: 1, False: 3.34k]
  ------------------
  578|      1|                retval = READSTAT_ERROR_PARSE;
  579|      1|                goto cleanup;
  580|      1|            }
  581|       |
  582|  3.34k|            unsigned char marker_byte = *input++;
  583|  3.34k|            unsigned char next_byte = *input++;
  584|  3.34k|            size_t insert_len = 0, copy_len = 0;
  585|  3.34k|            unsigned char insert_byte = 0x00;
  586|  3.34k|            size_t back_offset = 0;
  587|       |
  588|  3.34k|            if (marker_byte <= 0x0F) {
  ------------------
  |  Branch (588:17): [True: 1.54k, False: 1.80k]
  ------------------
  589|  1.54k|                insert_len = 3 + marker_byte;
  590|  1.54k|                insert_byte = next_byte;
  591|  1.80k|            } else if ((marker_byte >> 4) == 1) {
  ------------------
  |  Branch (591:24): [True: 534, False: 1.26k]
  ------------------
  592|    534|                if (input + 1 > (const unsigned char *)subheader + len) {
  ------------------
  |  Branch (592:21): [True: 2, False: 532]
  ------------------
  593|      2|                    retval = READSTAT_ERROR_PARSE;
  594|      2|                    goto cleanup;
  595|      2|                }
  596|    532|                insert_len = 19 + (marker_byte & 0x0F) + next_byte * 16;
  597|    532|                insert_byte = *input++;
  598|  1.26k|            } else if ((marker_byte >> 4) == 2) {
  ------------------
  |  Branch (598:24): [True: 330, False: 938]
  ------------------
  599|    330|                if (input + 1 > (const unsigned char *)subheader + len) {
  ------------------
  |  Branch (599:21): [True: 1, False: 329]
  ------------------
  600|      1|                    retval = READSTAT_ERROR_PARSE;
  601|      1|                    goto cleanup;
  602|      1|                }
  603|    329|                copy_len = 16 + (*input++);
  604|    329|                back_offset = 3 + (marker_byte & 0x0F) + next_byte * 16;
  605|    938|            } else {
  606|    938|                copy_len = (marker_byte >> 4);
  607|    938|                back_offset = 3 + (marker_byte & 0x0F) + next_byte * 16;
  608|    938|            }
  609|       |
  610|  3.34k|            if (insert_len) {
  ------------------
  |  Branch (610:17): [True: 2.07k, False: 1.26k]
  ------------------
  611|  2.07k|                if (output + insert_len > buffer + ctx->row_length) {
  ------------------
  |  Branch (611:21): [True: 2, False: 2.07k]
  ------------------
  612|      2|                    retval = READSTAT_ERROR_ROW_WIDTH_MISMATCH;
  613|      2|                    goto cleanup;
  614|      2|                }
  615|  2.07k|                memset(output, insert_byte, insert_len);
  616|  2.07k|                output += insert_len;
  617|  2.07k|            } else if (copy_len) {
  ------------------
  |  Branch (617:24): [True: 1.26k, False: 0]
  ------------------
  618|  1.26k|                if (output - buffer < back_offset || copy_len > back_offset) {
  ------------------
  |  Branch (618:21): [True: 11, False: 1.25k]
  |  Branch (618:54): [True: 18, False: 1.23k]
  ------------------
  619|     29|                    retval = READSTAT_ERROR_PARSE;
  620|     29|                    goto cleanup;
  621|     29|                }
  622|  1.23k|                if (output + copy_len > buffer + ctx->row_length) {
  ------------------
  |  Branch (622:21): [True: 2, False: 1.23k]
  ------------------
  623|      2|                    retval = READSTAT_ERROR_ROW_WIDTH_MISMATCH;
  624|      2|                    goto cleanup;
  625|      2|                }
  626|  1.23k|                memcpy(output, output - back_offset, copy_len);
  627|  1.23k|                output += copy_len;
  628|  1.23k|            }
  629|  3.34k|        }
  630|  1.26k|    }
  631|       |
  632|    367|    if (output - buffer != ctx->row_length) {
  ------------------
  |  Branch (632:9): [True: 6, False: 361]
  ------------------
  633|      6|        retval = READSTAT_ERROR_ROW_WIDTH_MISMATCH;
  634|      6|        goto cleanup;
  635|      6|    }
  636|    361|    retval = sas7bdat_parse_single_row(buffer, ctx);
  637|    408|cleanup:
  638|    408|    free(buffer);
  639|       |
  640|    408|    return retval;
  641|    361|}
readstat_sas7bdat_read.c:sas7bdat_parse_subheader_rle:
  643|  1.37k|static readstat_error_t sas7bdat_parse_subheader_rle(const char *subheader, size_t len, sas7bdat_ctx_t *ctx) {
  644|  1.37k|    if (ctx->row_limit == ctx->parsed_row_count)
  ------------------
  |  Branch (644:9): [True: 748, False: 631]
  ------------------
  645|    748|        return READSTAT_OK;
  646|       |
  647|    631|    readstat_error_t retval = READSTAT_OK;
  648|    631|    ssize_t bytes_decompressed = 0;
  649|       |
  650|    631|    bytes_decompressed = sas_rle_decompress(ctx->row, ctx->row_length, subheader, len);
  651|       |
  652|    631|    if (bytes_decompressed != ctx->row_length) {
  ------------------
  |  Branch (652:9): [True: 144, False: 487]
  ------------------
  653|    144|        retval = READSTAT_ERROR_ROW_WIDTH_MISMATCH;
  654|    144|        if (ctx->handle.error) {
  ------------------
  |  Branch (654:13): [True: 0, False: 144]
  ------------------
  655|      0|            snprintf(ctx->error_buf, sizeof(ctx->error_buf), 
  656|      0|                    "ReadStat: Row #%d decompressed to %ld bytes (expected %d bytes)",
  657|      0|                    ctx->parsed_row_count, (long)(bytes_decompressed), ctx->row_length);
  658|      0|            ctx->handle.error(ctx->error_buf, ctx->user_ctx);
  659|      0|        }
  660|    144|        goto cleanup;
  661|    144|    }
  662|    487|    retval = sas7bdat_parse_single_row(ctx->row, ctx);
  663|       |
  664|    631|cleanup:
  665|    631|    return retval;
  666|    487|}
readstat_sas7bdat_read.c:sas7bdat_register_deleted_row:
  410|  18.3k|static readstat_error_t sas7bdat_register_deleted_row(sas7bdat_ctx_t *ctx) {
  411|  18.3k|    if (ctx->parsed_deleted_row_count >= ctx->deleted_row_count) {
  ------------------
  |  Branch (411:9): [True: 3, False: 18.3k]
  ------------------
  412|      3|        return READSTAT_ERROR_PARSE;
  413|      3|    }
  414|  18.3k|    ctx->parsed_deleted_row_count++;
  415|  18.3k|    return READSTAT_OK;
  416|  18.3k|}
readstat_sas7bdat_read.c:sas7bdat_parse_deleted_row_bitmap:
  997|    485|        size_t page_size, const unsigned char **deleted_row_bitmap, sas7bdat_ctx_t *ctx) {
  998|    485|    uint64_t page_unused_bytes;
  999|    485|    if (ctx->u64) {
  ------------------
  |  Branch (999:9): [True: 369, False: 116]
  ------------------
 1000|    369|        page_unused_bytes = sas_read8(&page[24], ctx->bswap);
 1001|    369|    } else {
 1002|    116|        page_unused_bytes = sas_read4(&page[12], ctx->bswap);
 1003|    116|    }
 1004|    485|    uint32_t row_count = ctx->page_row_count < ctx->total_row_count ? ctx->page_row_count : ctx->total_row_count;
  ------------------
  |  Branch (1004:26): [True: 310, False: 175]
  ------------------
 1005|    485|    uint64_t deleted_row_bitmap_offset = (uint64_t)row_count * ctx->row_length + page_unused_bytes;
 1006|    485|    uint32_t required_bytes = row_count / CHAR_BIT + (row_count % CHAR_BIT == 0 ? 0 : 1);
  ------------------
  |  Branch (1006:55): [True: 355, False: 130]
  ------------------
 1007|       |
 1008|    485|    if ((data - page) + deleted_row_bitmap_offset + required_bytes > page_size) {
  ------------------
  |  Branch (1008:9): [True: 121, False: 364]
  ------------------
 1009|    121|        return READSTAT_ERROR_PARSE;
 1010|    121|    }
 1011|    364|    *deleted_row_bitmap = (const unsigned char *)data + deleted_row_bitmap_offset;
 1012|    364|    return READSTAT_OK;
 1013|    485|}
readstat_sas7bdat_read.c:sas7bdat_parse_rows:
  530|  1.96k|        const unsigned char *deleted_bitmap, sas7bdat_ctx_t *ctx) {
  531|  1.96k|    readstat_error_t retval = READSTAT_OK;
  532|  1.96k|    int i;
  533|  1.96k|    size_t row_offset=0;
  534|   254k|    for (i=0; i<ctx->page_row_count && ctx->parsed_row_count < ctx->row_limit; i++) {
  ------------------
  |  Branch (534:15): [True: 252k, False: 1.74k]
  |  Branch (534:40): [True: 252k, False: 24]
  ------------------
  535|   252k|        if (row_offset + ctx->row_length > len) {
  ------------------
  |  Branch (535:13): [True: 108, False: 252k]
  ------------------
  536|    108|            retval = READSTAT_ERROR_ROW_WIDTH_MISMATCH;
  537|    108|            goto cleanup;
  538|    108|        }
  539|   252k|        if (deleted_bitmap != NULL && sas7bdat_read_bitmap(deleted_bitmap, i)) {
  ------------------
  |  Branch (539:13): [True: 70.2k, False: 182k]
  |  Branch (539:39): [True: 18.1k, False: 52.1k]
  ------------------
  540|  18.1k|            if ((retval = sas7bdat_register_deleted_row(ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (540:17): [True: 1, False: 18.1k]
  ------------------
  541|      1|                goto cleanup;
  542|      1|            }
  543|   234k|        } else if ((retval = sas7bdat_parse_single_row(&data[row_offset], ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (543:20): [True: 86, False: 234k]
  ------------------
  544|     86|            goto cleanup;
  545|     86|        }
  546|       |
  547|   252k|        row_offset += ctx->row_length;
  548|   252k|    }
  549|       |
  550|  1.96k|cleanup:
  551|  1.96k|    return retval;
  552|  1.96k|}
readstat_sas7bdat_read.c:sas7bdat_read_bitmap:
  522|  70.2k|static unsigned char sas7bdat_read_bitmap(const unsigned char *bitmap, int index) {
  523|  70.2k|    unsigned char current_byte = bitmap[index / CHAR_BIT];
  524|  70.2k|    unsigned char mask = 1 << (CHAR_BIT - 1 - index % CHAR_BIT);
  525|       |
  526|  70.2k|    return current_byte & mask;
  527|  70.2k|}
readstat_sas7bdat_read.c:sas7bdat_submit_columns_if_needed:
  845|  4.89k|static readstat_error_t sas7bdat_submit_columns_if_needed(sas7bdat_ctx_t *ctx, int compressed) {
  846|  4.89k|    readstat_error_t retval = READSTAT_OK;
  847|  4.89k|    if (!ctx->did_submit_columns) {
  ------------------
  |  Branch (847:9): [True: 1.44k, False: 3.44k]
  ------------------
  848|  1.44k|        if ((retval = sas7bdat_submit_columns(ctx, compressed)) != READSTAT_OK) {
  ------------------
  |  Branch (848:13): [True: 226, False: 1.21k]
  ------------------
  849|    226|            goto cleanup;
  850|    226|        }
  851|  1.21k|        ctx->did_submit_columns = 1;
  852|  1.21k|    }
  853|  4.89k|cleanup:
  854|  4.89k|    return retval;
  855|  4.89k|}
readstat_sas7bdat_read.c:sas7bdat_submit_columns:
  784|  1.44k|static readstat_error_t sas7bdat_submit_columns(sas7bdat_ctx_t *ctx, int compressed) {
  785|  1.44k|    readstat_error_t retval = READSTAT_OK;
  786|  1.44k|    if (ctx->handle.metadata) {
  ------------------
  |  Branch (786:9): [True: 1.44k, False: 0]
  ------------------
  787|  1.44k|        readstat_metadata_t metadata = {
  788|  1.44k|            .row_count = ctx->row_limit,
  789|  1.44k|            .var_count = ctx->column_count,
  790|  1.44k|            .table_name = ctx->table_name,
  791|  1.44k|            .file_label = ctx->file_label,
  792|  1.44k|            .file_encoding = ctx->input_encoding, /* orig encoding? */
  793|  1.44k|            .creation_time = ctx->ctime,
  794|  1.44k|            .modified_time = ctx->mtime,
  795|  1.44k|            .file_format_version = ctx->version,
  796|  1.44k|            .compression = READSTAT_COMPRESS_NONE,
  797|  1.44k|            .endianness = ctx->little_endian ? READSTAT_ENDIAN_LITTLE : READSTAT_ENDIAN_BIG,
  ------------------
  |  Branch (797:27): [True: 285, False: 1.15k]
  ------------------
  798|  1.44k|            .is64bit = ctx->u64
  799|  1.44k|        };
  800|  1.44k|        if (compressed) {
  ------------------
  |  Branch (800:13): [True: 474, False: 970]
  ------------------
  801|    474|            if (ctx->rdc_compression) {
  ------------------
  |  Branch (801:17): [True: 44, False: 430]
  ------------------
  802|     44|                metadata.compression = READSTAT_COMPRESS_BINARY;
  803|    430|            } else {
  804|    430|                metadata.compression = READSTAT_COMPRESS_ROWS;
  805|    430|            }
  806|    474|        }
  807|  1.44k|        if (ctx->handle.metadata(&metadata, ctx->user_ctx) != READSTAT_HANDLER_OK) {
  ------------------
  |  Branch (807:13): [True: 0, False: 1.44k]
  ------------------
  808|      0|            retval = READSTAT_ERROR_USER_ABORT;
  809|      0|            goto cleanup;
  810|      0|        }
  811|  1.44k|    }
  812|  1.44k|    if (ctx->column_count == 0)
  ------------------
  |  Branch (812:9): [True: 979, False: 465]
  ------------------
  813|    979|        goto cleanup;
  814|       |
  815|    465|    if ((ctx->variables = readstat_calloc(ctx->column_count, sizeof(readstat_variable_t *))) == NULL) {
  ------------------
  |  Branch (815:9): [True: 0, False: 465]
  ------------------
  816|      0|        retval = READSTAT_ERROR_MALLOC;
  817|      0|        goto cleanup;
  818|      0|    }
  819|    465|    int i;
  820|    465|    int index_after_skipping = 0;
  821|  3.05M|    for (i=0; i<ctx->column_count; i++) {
  ------------------
  |  Branch (821:15): [True: 3.05M, False: 239]
  ------------------
  822|  3.05M|        ctx->variables[i] = sas7bdat_init_variable(ctx, i, index_after_skipping, &retval);
  823|  3.05M|        if (ctx->variables[i] == NULL)
  ------------------
  |  Branch (823:13): [True: 226, False: 3.05M]
  ------------------
  824|    226|            break;
  825|       |
  826|  3.05M|        int cb_retval = READSTAT_HANDLER_OK;
  827|  3.05M|        if (ctx->handle.variable) {
  ------------------
  |  Branch (827:13): [True: 3.05M, False: 0]
  ------------------
  828|  3.05M|            cb_retval = ctx->handle.variable(i, ctx->variables[i], ctx->variables[i]->format, ctx->user_ctx);
  829|  3.05M|        }
  830|  3.05M|        if (cb_retval == READSTAT_HANDLER_ABORT) {
  ------------------
  |  Branch (830:13): [True: 0, False: 3.05M]
  ------------------
  831|      0|            retval = READSTAT_ERROR_USER_ABORT;
  832|      0|            goto cleanup;
  833|      0|        }
  834|       |
  835|  3.05M|        if (cb_retval == READSTAT_HANDLER_SKIP_VARIABLE) {
  ------------------
  |  Branch (835:13): [True: 0, False: 3.05M]
  ------------------
  836|      0|            ctx->variables[i]->skip = 1;
  837|  3.05M|        } else {
  838|  3.05M|            index_after_skipping++;
  839|  3.05M|        }
  840|  3.05M|    }
  841|  1.44k|cleanup:
  842|  1.44k|    return retval;
  843|    465|}
readstat_sas7bdat_read.c:sas7bdat_init_variable:
  725|  3.05M|        int index_after_skipping, readstat_error_t *out_retval) {
  726|  3.05M|    readstat_error_t retval = READSTAT_OK;
  727|  3.05M|    readstat_variable_t *variable = readstat_calloc(1, sizeof(readstat_variable_t));
  728|       |
  729|  3.05M|    variable->index = i;
  730|  3.05M|    variable->index_after_skipping = index_after_skipping;
  731|  3.05M|    variable->type = ctx->col_info[i].type;
  732|  3.05M|    variable->storage_width = ctx->col_info[i].width;
  733|       |
  734|  3.05M|    if ((retval = sas7bdat_validate_column(&ctx->col_info[i])) != READSTAT_OK) {
  ------------------
  |  Branch (734:9): [True: 73, False: 3.05M]
  ------------------
  735|     73|        goto cleanup;
  736|     73|    }
  737|  3.05M|    if ((retval = sas7bdat_copy_text_ref(variable->name, sizeof(variable->name), 
  ------------------
  |  Branch (737:9): [True: 49, False: 3.05M]
  ------------------
  738|  3.05M|                    ctx->col_info[i].name_ref, ctx)) != READSTAT_OK) {
  739|     49|        goto cleanup;
  740|     49|    }
  741|  3.05M|    if ((retval = sas7bdat_copy_text_ref(variable->format, sizeof(variable->format),
  ------------------
  |  Branch (741:9): [True: 50, False: 3.05M]
  ------------------
  742|  3.05M|                    ctx->col_info[i].format_ref, ctx)) != READSTAT_OK) {
  743|     50|        goto cleanup;
  744|     50|    }
  745|  3.05M|    size_t len = strlen(variable->format);
  746|  3.05M|    if (ctx->col_info[i].format_width) {
  ------------------
  |  Branch (746:9): [True: 617, False: 3.05M]
  ------------------
  747|    617|        len += snprintf(variable->format + len, sizeof(variable->format) - len,
  748|    617|                "%d", ctx->col_info[i].format_width);
  749|    617|    }
  750|  3.05M|    if (len && ctx->col_info[i].format_digits) {
  ------------------
  |  Branch (750:9): [True: 652, False: 3.05M]
  |  Branch (750:16): [True: 445, False: 207]
  ------------------
  751|    445|        len += snprintf(variable->format + len, sizeof(variable->format) - len,
  752|    445|                ".%d", ctx->col_info[i].format_digits);
  753|    445|    }
  754|  3.05M|    if (len) { // TODO where is the informat saved?
  ------------------
  |  Branch (754:9): [True: 652, False: 3.05M]
  ------------------
  755|    652|        readstat_variable_set_informat(variable, variable->format);
  756|    652|    }
  757|  3.05M|    if ((retval = sas7bdat_copy_text_ref(variable->label, sizeof(variable->label), 
  ------------------
  |  Branch (757:9): [True: 54, False: 3.05M]
  ------------------
  758|  3.05M|                    ctx->col_info[i].label_ref, ctx)) != READSTAT_OK) {
  759|     54|        goto cleanup;
  760|     54|    }
  761|       |
  762|  3.05M|cleanup:
  763|  3.05M|    if (retval != READSTAT_OK) {
  ------------------
  |  Branch (763:9): [True: 226, False: 3.05M]
  ------------------
  764|    226|        if (out_retval)
  ------------------
  |  Branch (764:13): [True: 226, False: 0]
  ------------------
  765|    226|            *out_retval = retval;
  766|       |
  767|    226|        if (retval == READSTAT_ERROR_CONVERT_BAD_STRING) {
  ------------------
  |  Branch (767:13): [True: 9, False: 217]
  ------------------
  768|      9|            if (ctx->handle.error) {
  ------------------
  |  Branch (768:17): [True: 0, False: 9]
  ------------------
  769|      0|                snprintf(ctx->error_buf, sizeof(ctx->error_buf),
  770|      0|                        "ReadStat: Error converting variable #%d info to specified encoding: %s %s (%s)",
  771|      0|                        i, variable->name, variable->format, variable->label);
  772|      0|                ctx->handle.error(ctx->error_buf, ctx->user_ctx);
  773|      0|            }
  774|      9|        }
  775|       |
  776|    226|        free(variable);
  777|       |
  778|    226|        return NULL;
  779|    226|    }
  780|       |
  781|  3.05M|    return variable;
  782|  3.05M|}
readstat_sas7bdat_read.c:sas7bdat_validate_column:
  710|  3.05M|static readstat_error_t sas7bdat_validate_column(col_info_t *col_info) {
  711|  3.05M|    if (col_info->type == READSTAT_TYPE_DOUBLE) {
  ------------------
  |  Branch (711:9): [True: 1.12k, False: 3.05M]
  ------------------
  712|  1.12k|        if (col_info->width > 8 || col_info->width < 3) {
  ------------------
  |  Branch (712:13): [True: 45, False: 1.08k]
  |  Branch (712:36): [True: 2, False: 1.08k]
  ------------------
  713|     47|            return READSTAT_ERROR_PARSE;
  714|     47|        }
  715|  1.12k|    }
  716|  3.05M|    if (col_info->type == READSTAT_TYPE_STRING) {
  ------------------
  |  Branch (716:9): [True: 3.05M, False: 1.08k]
  ------------------
  717|  3.05M|        if (col_info->width > INT16_MAX) {
  ------------------
  |  Branch (717:13): [True: 26, False: 3.05M]
  ------------------
  718|     26|            return READSTAT_ERROR_PARSE;
  719|     26|        }
  720|  3.05M|    }
  721|  3.05M|    return READSTAT_OK;
  722|  3.05M|}
readstat_sas7bdat_read.c:sas7bdat_update_progress:
  132|  4.88k|static readstat_error_t sas7bdat_update_progress(sas7bdat_ctx_t *ctx) {
  133|  4.88k|    readstat_io_t *io = ctx->io;
  134|  4.88k|    return io->update(ctx->file_size, ctx->handle.progress, ctx->user_ctx, io->io_ctx);
  135|  4.88k|}
readstat_sas7bdat_read.c:sas7bdat_ctx_free:
   98|  3.67k|static void sas7bdat_ctx_free(sas7bdat_ctx_t *ctx) {
   99|  3.67k|    int i;
  100|  3.67k|    if (ctx->text_blobs) {
  ------------------
  |  Branch (100:9): [True: 867, False: 2.80k]
  ------------------
  101|  3.47k|        for (i=0; i<ctx->text_blob_count; i++) {
  ------------------
  |  Branch (101:19): [True: 2.61k, False: 867]
  ------------------
  102|  2.61k|            free(ctx->text_blobs[i]);
  103|  2.61k|        }
  104|    867|        free(ctx->text_blobs);
  105|    867|        free(ctx->text_blob_lengths);
  106|    867|    }
  107|  3.67k|    if (ctx->variables) {
  ------------------
  |  Branch (107:9): [True: 465, False: 3.21k]
  ------------------
  108|  15.7M|        for (i=0; i<ctx->column_count; i++) {
  ------------------
  |  Branch (108:19): [True: 15.7M, False: 465]
  ------------------
  109|  15.7M|            if (ctx->variables[i])
  ------------------
  |  Branch (109:17): [True: 3.05M, False: 12.6M]
  ------------------
  110|  3.05M|                free(ctx->variables[i]);
  111|  15.7M|        }
  112|    465|        free(ctx->variables);
  113|    465|    }
  114|  3.67k|    if (ctx->col_info)
  ------------------
  |  Branch (114:9): [True: 616, False: 3.05k]
  ------------------
  115|    616|        free(ctx->col_info);
  116|       |
  117|  3.67k|    if (ctx->scratch_buffer)
  ------------------
  |  Branch (117:9): [True: 623, False: 3.05k]
  ------------------
  118|    623|        free(ctx->scratch_buffer);
  119|       |
  120|  3.67k|    if (ctx->page)
  ------------------
  |  Branch (120:9): [True: 3.16k, False: 513]
  ------------------
  121|  3.16k|        free(ctx->page);
  122|       |
  123|  3.67k|    if (ctx->row)
  ------------------
  |  Branch (123:9): [True: 1.10k, False: 2.57k]
  ------------------
  124|  1.10k|        free(ctx->row);
  125|       |
  126|  3.67k|    if (ctx->converter)
  ------------------
  |  Branch (126:9): [True: 2.10k, False: 1.56k]
  ------------------
  127|  2.10k|        iconv_close(ctx->converter);
  128|       |
  129|  3.67k|    free(ctx);
  130|  3.67k|}

sas_rle_decompress:
   47|    631|        const void *input_buf, size_t input_len) {
   48|    631|    unsigned char *buffer = (unsigned char *)output_buf;
   49|    631|    unsigned char *output = buffer;
   50|    631|    size_t output_written = 0;
   51|       |
   52|    631|    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|    164|            case SAS_RLE_COMMAND_COPY64_PLUS_4096:
  ------------------
  |  |   14|    164|#define SAS_RLE_COMMAND_COPY64_PLUS_4096 1
  ------------------
  |  Branch (68:13): [True: 164, False: 55.0k]
  ------------------
   69|    164|                copy_len = (*input++) + 64 + length * 256 + 4096;
   70|    164|                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: 18, False: 23.0k]
  ------------------
  114|     18|                return -1;
  115|     18|            }
  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|    631|}

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: 235, False: 29.7k]
  ------------------
   32|    235|        return -1;
   33|       |
   34|  29.7k|    buffer_ctx->pos = newpos;
   35|  29.7k|    return newpos;
   36|  30.0k|}
rt_read_handler:
   38|  52.8k|ssize_t rt_read_handler(void *buf, size_t nbytes, void *io_ctx) {
   39|  52.8k|    rt_buffer_ctx_t *buffer_ctx = (rt_buffer_ctx_t *)io_ctx;
   40|  52.8k|    ssize_t bytes_copied = 0;
   41|  52.8k|    ssize_t bytes_left = buffer_ctx->buffer->used - buffer_ctx->pos;
   42|  52.8k|    if (nbytes <= bytes_left) {
  ------------------
  |  Branch (42:9): [True: 52.3k, False: 460]
  ------------------
   43|  52.3k|        memcpy(buf, buffer_ctx->buffer->bytes + buffer_ctx->pos, nbytes);
   44|  52.3k|        bytes_copied = nbytes;
   45|  52.3k|    } else if (bytes_left > 0) {
  ------------------
  |  Branch (45:16): [True: 246, False: 214]
  ------------------
   46|    246|        memcpy(buf, buffer_ctx->buffer->bytes + buffer_ctx->pos, bytes_left);
   47|    246|        bytes_copied = bytes_left;
   48|    246|    }
   49|  52.8k|    buffer_ctx->pos += bytes_copied;
   50|  52.8k|    return bytes_copied;
   51|  52.8k|}
rt_update_handler:
   54|  4.88k|        void *user_ctx, void *io_ctx) {
   55|  4.88k|    if (!progress_handler)
  ------------------
  |  Branch (55:9): [True: 4.88k, False: 0]
  ------------------
   56|  4.88k|        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|}

