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

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

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

readstat_convert:
    7|  4.55M|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|  4.59M|    while (src_len && (src[src_len-1] == ' ' || src[src_len-1] == '\0')) {
  ------------------
  |  Branch (10:12): [True: 65.0k, False: 4.52M]
  |  Branch (10:24): [True: 3.92k, False: 61.1k]
  |  Branch (10:49): [True: 39.8k, False: 21.3k]
  ------------------
   11|  43.7k|        src_len--;
   12|  43.7k|    }
   13|  4.55M|    if (dst_len == 0) {
  ------------------
  |  Branch (13:9): [True: 0, False: 4.55M]
  ------------------
   14|      0|        return READSTAT_ERROR_CONVERT_LONG_STRING;
   15|  4.55M|    } else if (converter) {
  ------------------
  |  Branch (15:16): [True: 4.21M, False: 331k]
  ------------------
   16|  4.21M|        size_t dst_left = dst_len - 1;
   17|  4.21M|        char *dst_end = dst;
   18|  4.21M|        size_t status = iconv(converter, (readstat_iconv_inbuf_t)&src, &src_len, &dst_end, &dst_left);
   19|  4.21M|        if (status == (size_t)-1) {
  ------------------
  |  Branch (19:13): [True: 3.01k, False: 4.21M]
  ------------------
   20|  3.01k|            if (errno == E2BIG) {
  ------------------
  |  Branch (20:17): [True: 6, False: 3.01k]
  ------------------
   21|      6|                return READSTAT_ERROR_CONVERT_LONG_STRING;
   22|  3.01k|            } else if (errno == EILSEQ) {
  ------------------
  |  Branch (22:24): [True: 28, False: 2.98k]
  ------------------
   23|     28|                return READSTAT_ERROR_CONVERT_BAD_STRING;
   24|  2.98k|            } else if (errno != EINVAL) { /* EINVAL indicates improper truncation; accept it */
  ------------------
  |  Branch (24:24): [True: 0, False: 2.98k]
  ------------------
   25|      0|                return READSTAT_ERROR_CONVERT;
   26|      0|            }
   27|  3.01k|        }
   28|  4.21M|        dst[dst_len - dst_left - 1] = '\0';
   29|  4.21M|    } else if (src_len + 1 > dst_len) {
  ------------------
  |  Branch (29:16): [True: 19, False: 331k]
  ------------------
   30|     19|        return READSTAT_ERROR_CONVERT_LONG_STRING;
   31|   331k|    } else {
   32|   331k|        memcpy(dst, src, src_len);
   33|   331k|        dst[src_len] = '\0';
   34|   331k|    }
   35|  4.55M|    return READSTAT_OK;
   36|  4.55M|}

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

readstat_malloc:
   10|  5.78k|void *readstat_malloc(size_t len) {
   11|  5.78k|    if (len > MAX_MALLOC_SIZE || len == 0) {
  ------------------
  |  |    3|  11.5k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
  |  Branch (11:9): [True: 0, False: 5.78k]
  |  Branch (11:34): [True: 0, False: 5.78k]
  ------------------
   12|      0|        return NULL;
   13|      0|    }
   14|  5.78k|    return malloc(len);
   15|  5.78k|}
readstat_calloc:
   17|  3.75M|void *readstat_calloc(size_t count, size_t size) {
   18|  3.75M|    if (count > MAX_MALLOC_SIZE || size > MAX_MALLOC_SIZE || count * size > MAX_MALLOC_SIZE) {
  ------------------
  |  |    3|  7.50M|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
                  if (count > MAX_MALLOC_SIZE || size > MAX_MALLOC_SIZE || count * size > MAX_MALLOC_SIZE) {
  ------------------
  |  |    3|  7.50M|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
                  if (count > MAX_MALLOC_SIZE || size > MAX_MALLOC_SIZE || count * size > MAX_MALLOC_SIZE) {
  ------------------
  |  |    3|  3.75M|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
  |  Branch (18:9): [True: 0, False: 3.75M]
  |  Branch (18:36): [True: 0, False: 3.75M]
  |  Branch (18:62): [True: 0, False: 3.75M]
  ------------------
   19|      0|        return NULL;
   20|      0|    }
   21|  3.75M|    if (count == 0 || size == 0) {
  ------------------
  |  Branch (21:9): [True: 0, False: 3.75M]
  |  Branch (21:23): [True: 0, False: 3.75M]
  ------------------
   22|      0|        return NULL;
   23|      0|    }
   24|  3.75M|    return calloc(count, size);
   25|  3.75M|}
readstat_realloc:
   27|   172k|void *readstat_realloc(void *ptr, size_t len) {
   28|   172k|    if (len > MAX_MALLOC_SIZE || len == 0) {
  ------------------
  |  |    3|   345k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
  |  Branch (28:9): [True: 97, False: 172k]
  |  Branch (28:34): [True: 1, False: 172k]
  ------------------
   29|     98|        if (ptr)
  ------------------
  |  Branch (29:13): [True: 68, False: 30]
  ------------------
   30|     68|            free(ptr);
   31|     98|        return NULL;
   32|     98|    }
   33|   172k|    return realloc(ptr, len);
   34|   172k|}

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

sas_read8:
  139|  46.1k|uint64_t sas_read8(const char *data, int bswap) {
  140|  46.1k|    uint64_t tmp;
  141|  46.1k|    memcpy(&tmp, data, 8);
  142|  46.1k|    return bswap ? byteswap8(tmp) : tmp;
  ------------------
  |  Branch (142:12): [True: 40.8k, False: 5.29k]
  ------------------
  143|  46.1k|}
sas_read4:
  145|   224k|uint32_t sas_read4(const char *data, int bswap) {
  146|   224k|    uint32_t tmp;
  147|   224k|    memcpy(&tmp, data, 4);
  148|   224k|    return bswap ? byteswap4(tmp) : tmp;
  ------------------
  |  Branch (148:12): [True: 168k, False: 55.8k]
  ------------------
  149|   224k|}
sas_read2:
  151|   216k|uint16_t sas_read2(const char *data, int bswap) {
  152|   216k|    uint16_t tmp;
  153|   216k|    memcpy(&tmp, data, 2);
  154|   216k|    return bswap ? byteswap2(tmp) : tmp;
  ------------------
  |  Branch (154:12): [True: 79.5k, False: 136k]
  ------------------
  155|   216k|}
sas_subheader_remainder:
  157|  6.48k|size_t sas_subheader_remainder(size_t len, size_t signature_len) {
  158|  6.48k|    return len - (4+2*signature_len);
  159|  6.48k|}
sas_read_header:
  162|  3.56k|        readstat_error_handler error_handler, void *user_ctx) {
  163|  3.56k|    sas_header_start_t  header_start;
  164|  3.56k|    sas_header_end_t    header_end;
  165|  3.56k|    int retval = READSTAT_OK;
  166|  3.56k|    char error_buf[1024];
  167|  3.56k|    time_t epoch = sas_epoch();
  168|       |
  169|  3.56k|    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.54k]
  ------------------
  170|     20|        retval = READSTAT_ERROR_READ;
  171|     20|        goto cleanup;
  172|     20|    }
  173|  3.54k|    if (memcmp(header_start.magic, sas7bdat_magic_number, sizeof(sas7bdat_magic_number)) != 0 &&
  ------------------
  |  Branch (173:9): [True: 1.68k, False: 1.86k]
  ------------------
  174|  1.68k|            memcmp(header_start.magic, sas7bcat_magic_number, sizeof(sas7bcat_magic_number)) != 0) {
  ------------------
  |  Branch (174:13): [True: 123, False: 1.56k]
  ------------------
  175|    123|        retval = READSTAT_ERROR_PARSE;
  176|    123|        goto cleanup;
  177|    123|    }
  178|  3.42k|    if (header_start.a1 == SAS_ALIGNMENT_OFFSET_4) {
  ------------------
  |  |   87|  3.42k|#define SAS_ALIGNMENT_OFFSET_4  0x33
  ------------------
  |  Branch (178:9): [True: 8, False: 3.41k]
  ------------------
  179|      8|        hinfo->pad1 = 4;
  180|      8|    }
  181|  3.42k|    if (header_start.a2 == SAS_ALIGNMENT_OFFSET_4) {
  ------------------
  |  |   87|  3.42k|#define SAS_ALIGNMENT_OFFSET_4  0x33
  ------------------
  |  Branch (181:9): [True: 1.55k, False: 1.86k]
  ------------------
  182|  1.55k|        hinfo->u64 = 1;
  183|  1.55k|    }
  184|  3.42k|    int bswap = 0;
  185|  3.42k|    if (header_start.endian == SAS_ENDIAN_BIG) {
  ------------------
  |  |   80|  3.42k|#define SAS_ENDIAN_BIG       0x00
  ------------------
  |  Branch (185:9): [True: 2.70k, False: 717]
  ------------------
  186|  2.70k|        bswap = machine_is_little_endian();
  187|  2.70k|        hinfo->little_endian = 0;
  188|  2.70k|    } else if (header_start.endian == SAS_ENDIAN_LITTLE) {
  ------------------
  |  |   81|    717|#define SAS_ENDIAN_LITTLE    0x01
  ------------------
  |  Branch (188:16): [True: 704, False: 13]
  ------------------
  189|    704|        bswap = !machine_is_little_endian();
  190|    704|        hinfo->little_endian = 1;
  191|    704|    } else {
  192|     13|        retval = READSTAT_ERROR_PARSE;
  193|     13|        goto cleanup;
  194|     13|    }
  195|  3.40k|    int i;
  196|  22.8k|    for (i=0; i<sizeof(_charset_table)/sizeof(_charset_table[0]); i++) {
  ------------------
  |  Branch (196:15): [True: 22.8k, False: 5]
  ------------------
  197|  22.8k|        if (header_start.encoding == _charset_table[i].code) {
  ------------------
  |  Branch (197:13): [True: 3.40k, False: 19.4k]
  ------------------
  198|  3.40k|            hinfo->encoding = _charset_table[i].name;
  199|  3.40k|            break;
  200|  3.40k|        }
  201|  22.8k|    }
  202|  3.40k|    if (hinfo->encoding == NULL) {
  ------------------
  |  Branch (202:9): [True: 5, False: 3.40k]
  ------------------
  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.40k|    memcpy(hinfo->table_name, header_start.table_name, sizeof(header_start.table_name));
  211|  3.40k|    if (io->seek(hinfo->pad1, READSTAT_SEEK_CUR, io->io_ctx) == -1) {
  ------------------
  |  Branch (211:9): [True: 6, False: 3.39k]
  ------------------
  212|      6|        retval = READSTAT_ERROR_SEEK;
  213|      6|        goto cleanup;
  214|      6|    }
  215|       |
  216|  3.39k|    double creation_time, modification_time, creation_time_diff, modification_time_diff;
  217|       |
  218|  3.39k|    if (io->read(&creation_time, sizeof(double), io->io_ctx) < sizeof(double)) {
  ------------------
  |  Branch (218:9): [True: 13, False: 3.38k]
  ------------------
  219|     13|        retval = READSTAT_ERROR_READ;
  220|     13|        goto cleanup;
  221|     13|    }
  222|  3.38k|    if (bswap)
  ------------------
  |  Branch (222:9): [True: 2.68k, False: 703]
  ------------------
  223|  2.68k|        creation_time = byteswap_double(creation_time);
  224|       |
  225|  3.38k|    if (io->read(&modification_time, sizeof(double), io->io_ctx) < sizeof(double)) {
  ------------------
  |  Branch (225:9): [True: 6, False: 3.37k]
  ------------------
  226|      6|        retval = READSTAT_ERROR_READ;
  227|      6|        goto cleanup;
  228|      6|    }
  229|  3.37k|    if (bswap)
  ------------------
  |  Branch (229:9): [True: 2.67k, False: 702]
  ------------------
  230|  2.67k|        modification_time = byteswap_double(modification_time);
  231|       |
  232|  3.37k|    if (io->read(&creation_time_diff, sizeof(double), io->io_ctx) < sizeof(double)) {
  ------------------
  |  Branch (232:9): [True: 6, False: 3.37k]
  ------------------
  233|      6|        retval = READSTAT_ERROR_READ;
  234|      6|        goto cleanup;
  235|      6|    }
  236|  3.37k|    if (bswap)
  ------------------
  |  Branch (236:9): [True: 2.67k, False: 699]
  ------------------
  237|  2.67k|        creation_time_diff = byteswap_double(creation_time_diff);
  238|       |    
  239|  3.37k|    if (io->read(&modification_time_diff, sizeof(double), io->io_ctx) < sizeof(double)) {
  ------------------
  |  Branch (239:9): [True: 6, False: 3.36k]
  ------------------
  240|      6|        retval = READSTAT_ERROR_READ;
  241|      6|        goto cleanup;
  242|      6|    }
  243|  3.36k|    if (bswap)
  ------------------
  |  Branch (243:9): [True: 2.66k, False: 697]
  ------------------
  244|  2.66k|        modification_time_diff = byteswap_double(modification_time_diff);
  245|       |    
  246|  3.36k|    hinfo->creation_time = sas_convert_time(creation_time, creation_time_diff, epoch);
  247|  3.36k|    hinfo->modification_time = sas_convert_time(modification_time, modification_time_diff, epoch);
  248|       |
  249|  3.36k|    uint32_t header_size, page_size;
  250|       |
  251|  3.36k|    if (io->read(&header_size, sizeof(uint32_t), io->io_ctx) < sizeof(uint32_t)) {
  ------------------
  |  Branch (251:9): [True: 8, False: 3.35k]
  ------------------
  252|      8|        retval = READSTAT_ERROR_READ;
  253|      8|        goto cleanup;
  254|      8|    }
  255|  3.35k|    if (io->read(&page_size, sizeof(uint32_t), io->io_ctx) < sizeof(uint32_t)) {
  ------------------
  |  Branch (255:9): [True: 3, False: 3.35k]
  ------------------
  256|      3|        retval = READSTAT_ERROR_READ;
  257|      3|        goto cleanup;
  258|      3|    }
  259|       |
  260|  3.35k|    hinfo->header_size = bswap ? byteswap4(header_size) : header_size;
  ------------------
  |  Branch (260:26): [True: 2.66k, False: 694]
  ------------------
  261|  3.35k|    hinfo->page_size = bswap ? byteswap4(page_size) : page_size;
  ------------------
  |  Branch (261:24): [True: 2.66k, False: 694]
  ------------------
  262|       |
  263|  3.35k|    if (hinfo->header_size < 1024 || hinfo->page_size < 1024) {
  ------------------
  |  Branch (263:9): [True: 12, False: 3.34k]
  |  Branch (263:38): [True: 11, False: 3.33k]
  ------------------
  264|     23|        retval = READSTAT_ERROR_PARSE;
  265|     23|        goto cleanup;
  266|     23|    }
  267|  3.33k|    if (hinfo->header_size > (1<<24) || hinfo->page_size > (1<<24)) {
  ------------------
  |  Branch (267:9): [True: 19, False: 3.31k]
  |  Branch (267:41): [True: 33, False: 3.27k]
  ------------------
  268|     52|        retval = READSTAT_ERROR_PARSE;
  269|     52|        goto cleanup;
  270|     52|    }
  271|       |
  272|  3.27k|    if (hinfo->u64) {
  ------------------
  |  Branch (272:9): [True: 1.51k, False: 1.76k]
  ------------------
  273|  1.51k|        hinfo->page_header_size = SAS_PAGE_HEADER_SIZE_64BIT;
  ------------------
  |  |  121|  1.51k|#define SAS_PAGE_HEADER_SIZE_64BIT  40
  ------------------
  274|  1.51k|        hinfo->subheader_pointer_size = SAS_SUBHEADER_POINTER_SIZE_64BIT;
  ------------------
  |  |  118|  1.51k|#define SAS_SUBHEADER_POINTER_SIZE_64BIT    24
  ------------------
  275|  1.76k|    } else {
  276|  1.76k|        hinfo->page_header_size = SAS_PAGE_HEADER_SIZE_32BIT;
  ------------------
  |  |  120|  1.76k|#define SAS_PAGE_HEADER_SIZE_32BIT  24
  ------------------
  277|  1.76k|        hinfo->subheader_pointer_size = SAS_SUBHEADER_POINTER_SIZE_32BIT;
  ------------------
  |  |  117|  1.76k|#define SAS_SUBHEADER_POINTER_SIZE_32BIT    12
  ------------------
  278|  1.76k|    }
  279|       |
  280|  3.27k|    if (hinfo->u64) {
  ------------------
  |  Branch (280:9): [True: 1.51k, False: 1.76k]
  ------------------
  281|  1.51k|        uint64_t page_count;
  282|  1.51k|        if (io->read(&page_count, sizeof(uint64_t), io->io_ctx) < sizeof(uint64_t)) {
  ------------------
  |  Branch (282:13): [True: 15, False: 1.50k]
  ------------------
  283|     15|            retval = READSTAT_ERROR_READ;
  284|     15|            goto cleanup;
  285|     15|        }
  286|  1.50k|        hinfo->page_count = bswap ? byteswap8(page_count) : page_count;
  ------------------
  |  Branch (286:29): [True: 1.40k, False: 95]
  ------------------
  287|  1.76k|    } else {
  288|  1.76k|        uint32_t page_count;
  289|  1.76k|        if (io->read(&page_count, sizeof(uint32_t), io->io_ctx) < sizeof(uint32_t)) {
  ------------------
  |  Branch (289:13): [True: 19, False: 1.74k]
  ------------------
  290|     19|            retval = READSTAT_ERROR_READ;
  291|     19|            goto cleanup;
  292|     19|        }
  293|  1.74k|        hinfo->page_count = bswap ? byteswap4(page_count) : page_count;
  ------------------
  |  Branch (293:29): [True: 1.16k, False: 581]
  ------------------
  294|  1.74k|    }
  295|  3.24k|    if (hinfo->page_count > (1<<24)) {
  ------------------
  |  Branch (295:9): [True: 18, False: 3.22k]
  ------------------
  296|     18|        retval = READSTAT_ERROR_PARSE;
  297|     18|        goto cleanup;
  298|     18|    }
  299|       |    
  300|  3.22k|    if (io->seek(8, READSTAT_SEEK_CUR, io->io_ctx) == -1) {
  ------------------
  |  Branch (300:9): [True: 74, False: 3.15k]
  ------------------
  301|     74|        retval = READSTAT_ERROR_SEEK;
  302|     74|        if (error_handler) {
  ------------------
  |  Branch (302:13): [True: 0, False: 74]
  ------------------
  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|     74|        goto cleanup;
  307|     74|    }
  308|  3.15k|    if (io->read(&header_end, sizeof(sas_header_end_t), io->io_ctx) < sizeof(sas_header_end_t)) {
  ------------------
  |  Branch (308:9): [True: 18, False: 3.13k]
  ------------------
  309|     18|        retval = READSTAT_ERROR_READ;
  310|     18|        goto cleanup;
  311|     18|    }
  312|  3.13k|    char major, revision_tag;
  313|  3.13k|    int minor, revision;
  314|  3.13k|    if (sscanf(header_end.release, "%c.%04d%c%1d", &major, &minor, &revision_tag, &revision) != 4) {
  ------------------
  |  Branch (314:9): [True: 4, False: 3.13k]
  ------------------
  315|      4|        retval = READSTAT_ERROR_PARSE;
  316|      4|        goto cleanup;
  317|      4|    }
  318|       |
  319|  3.13k|    if (major >= '1' && major <= '9') {
  ------------------
  |  Branch (319:9): [True: 3.12k, False: 11]
  |  Branch (319:25): [True: 3.11k, False: 8]
  ------------------
  320|  3.11k|        hinfo->major_version = major - '0';
  321|  3.11k|    } else if (major == 'V') {
  ------------------
  |  Branch (321:16): [True: 2, False: 17]
  ------------------
  322|       |        // It appears that SAS Visual Forecaster reports the major version as "V"
  323|       |        // Treat it as version 9 for all intents and purposes
  324|      2|        hinfo->major_version = 9;
  325|     17|    } else {
  326|     17|        retval = READSTAT_ERROR_PARSE;
  327|     17|        goto cleanup;
  328|     17|    }
  329|       |    // revision_tag is usually M, but J has been observed in the wild (not created with SAS?)
  330|  3.11k|    if (revision_tag != 'M' && revision_tag != 'J') {
  ------------------
  |  Branch (330:9): [True: 30, False: 3.08k]
  |  Branch (330:32): [True: 17, False: 13]
  ------------------
  331|     17|        retval = READSTAT_ERROR_PARSE;
  332|     17|        goto cleanup;
  333|     17|    }
  334|  3.09k|    hinfo->minor_version = minor;
  335|  3.09k|    hinfo->revision = revision;
  336|       |
  337|  3.09k|    if ((major == '8' || major == '9') && minor == 0 && revision == 0) {
  ------------------
  |  Branch (337:10): [True: 286, False: 2.81k]
  |  Branch (337:26): [True: 152, False: 2.65k]
  |  Branch (337:43): [True: 79, False: 359]
  |  Branch (337:57): [True: 64, False: 15]
  ------------------
  338|       |        /* A bit of a hack, but most SAS installations are running a minor update */
  339|     64|        hinfo->vendor = READSTAT_VENDOR_STAT_TRANSFER;
  340|  3.03k|    } else {
  341|  3.03k|        hinfo->vendor = READSTAT_VENDOR_SAS;
  342|  3.03k|    }
  343|  3.09k|    if (io->seek(hinfo->header_size, READSTAT_SEEK_SET, io->io_ctx) == -1) {
  ------------------
  |  Branch (343:9): [True: 55, False: 3.04k]
  ------------------
  344|     55|        retval = READSTAT_ERROR_SEEK;
  345|     55|        if (error_handler) {
  ------------------
  |  Branch (345:13): [True: 0, False: 55]
  ------------------
  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|     55|        goto cleanup;
  351|     55|    }
  352|       |
  353|  3.56k|cleanup:
  354|  3.56k|    return retval;
  355|  3.09k|}
sas_validate_tag:
  507|  10.4k|readstat_error_t sas_validate_tag(char tag) {
  508|  10.4k|    if (tag == '_' || (tag >= 'A' && tag <= 'Z'))
  ------------------
  |  Branch (508:9): [True: 4.71k, False: 5.76k]
  |  Branch (508:24): [True: 1.66k, False: 4.09k]
  |  Branch (508:38): [True: 1.22k, False: 445]
  ------------------
  509|  5.93k|        return READSTAT_OK;
  510|       |
  511|  4.54k|    return READSTAT_ERROR_TAGGED_VALUE_IS_OUT_OF_RANGE;
  512|  10.4k|}
sas_assign_tag:
  514|  10.4k|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|  10.4k|    if (tag == 0) {
  ------------------
  |  Branch (521:9): [True: 4.71k, False: 5.76k]
  ------------------
  522|  4.71k|        tag = '_';
  523|  5.76k|    } else if (tag >= 2 && tag < 28) {
  ------------------
  |  Branch (523:16): [True: 5.05k, False: 710]
  |  Branch (523:28): [True: 1.12k, False: 3.92k]
  ------------------
  524|  1.12k|        tag = 'A' + (tag - 2);
  525|  1.12k|    }
  526|  10.4k|    if (sas_validate_tag(tag) == READSTAT_OK) {
  ------------------
  |  Branch (526:9): [True: 5.93k, False: 4.54k]
  ------------------
  527|  5.93k|        value->tag = tag;
  528|  5.93k|        value->is_tagged_missing = 1;
  529|  5.93k|    } else {
  530|  4.54k|        value->tag = 0;
  531|  4.54k|        value->is_system_missing = 1;
  532|  4.54k|    }
  533|  10.4k|}
readstat_sas.c:sas_epoch:
  123|  3.56k|static time_t sas_epoch(void) {
  124|  3.56k|    return - 3653 * 86400; // seconds between 01-01-1960 and 01-01-1970
  125|  3.56k|}
readstat_sas.c:sas_convert_time:
  127|  6.73k|static time_t sas_convert_time(double time, double time_diff, time_t epoch) {
  128|  6.73k|    time -= time_diff;
  129|  6.73k|    time += epoch;
  130|  6.73k|    if (isnan(time))
  ------------------
  |  Branch (130:9): [True: 835, False: 5.89k]
  ------------------
  131|    835|        return 0;
  132|  5.89k|    if (time > (double)LONG_MAX)
  ------------------
  |  Branch (132:9): [True: 1.66k, False: 4.22k]
  ------------------
  133|  1.66k|        return LONG_MAX;
  134|  4.22k|    if (time < (double)LONG_MIN)
  ------------------
  |  Branch (134:9): [True: 1.17k, False: 3.05k]
  ------------------
  135|  1.17k|        return LONG_MIN;
  136|  3.05k|    return time;
  137|  4.22k|}

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

sas_rle_decompress:
   47|    484|        const void *input_buf, size_t input_len) {
   48|    484|    unsigned char *buffer = (unsigned char *)output_buf;
   49|    484|    unsigned char *output = buffer;
   50|    484|    size_t output_written = 0;
   51|       |
   52|    484|    const unsigned char *input = (const unsigned char *)input_buf;
   53|       |
   54|  43.8k|    while (input < (const unsigned char *)input_buf + input_len) {
  ------------------
  |  Branch (54:12): [True: 43.5k, False: 364]
  ------------------
   55|  43.5k|        unsigned char control = *input++;
   56|  43.5k|        unsigned char command = (control & 0xF0) >> 4;
   57|  43.5k|        unsigned char length = (control & 0x0F);
   58|  43.5k|        int copy_len = 0;
   59|  43.5k|        int insert_len = 0;
   60|  43.5k|        unsigned char insert_byte = '\0';
   61|  43.5k|        if (input + command_lengths[command] > (const unsigned char *)input_buf + input_len) {
  ------------------
  |  Branch (61:13): [True: 4, False: 43.4k]
  ------------------
   62|      4|            return -1;
   63|      4|        }
   64|  43.4k|        switch (command) {
   65|  3.11k|            case SAS_RLE_COMMAND_COPY64:
  ------------------
  |  |   13|  3.11k|#define SAS_RLE_COMMAND_COPY64          0
  ------------------
  |  Branch (65:13): [True: 3.11k, False: 40.3k]
  ------------------
   66|  3.11k|                copy_len = (*input++) + 64 + length * 256;
   67|  3.11k|                break;
   68|    118|            case SAS_RLE_COMMAND_COPY64_PLUS_4096:
  ------------------
  |  |   14|    118|#define SAS_RLE_COMMAND_COPY64_PLUS_4096 1
  ------------------
  |  Branch (68:13): [True: 118, False: 43.3k]
  ------------------
   69|    118|                copy_len = (*input++) + 64 + length * 256 + 4096;
   70|    118|                break;
   71|    708|            case SAS_RLE_COMMAND_COPY96: copy_len = length + 96; break;
  ------------------
  |  |   15|    708|#define SAS_RLE_COMMAND_COPY96          2
  ------------------
  |  Branch (71:13): [True: 708, False: 42.7k]
  ------------------
   72|    726|            case SAS_RLE_COMMAND_INSERT_BYTE18:
  ------------------
  |  |   16|    726|#define SAS_RLE_COMMAND_INSERT_BYTE18   4
  ------------------
  |  Branch (72:13): [True: 726, False: 42.7k]
  ------------------
   73|    726|                insert_len = (*input++) + 18 + length * 256;
   74|    726|                insert_byte = *input++;
   75|    726|                break;
   76|    766|            case SAS_RLE_COMMAND_INSERT_AT17:
  ------------------
  |  |   17|    766|#define SAS_RLE_COMMAND_INSERT_AT17     5
  ------------------
  |  Branch (76:13): [True: 766, False: 42.7k]
  ------------------
   77|    766|                insert_len = (*input++) + 17 + length * 256;
   78|    766|                insert_byte = '@';
   79|    766|                break;
   80|    774|            case SAS_RLE_COMMAND_INSERT_BLANK17:
  ------------------
  |  |   18|    774|#define SAS_RLE_COMMAND_INSERT_BLANK17  6
  ------------------
  |  Branch (80:13): [True: 774, False: 42.7k]
  ------------------
   81|    774|                insert_len = (*input++) + 17 + length * 256;
   82|    774|                insert_byte = ' ';
   83|    774|                break;
   84|  1.88k|            case SAS_RLE_COMMAND_INSERT_ZERO17:
  ------------------
  |  |   19|  1.88k|#define SAS_RLE_COMMAND_INSERT_ZERO17   7
  ------------------
  |  Branch (84:13): [True: 1.88k, False: 41.6k]
  ------------------
   85|  1.88k|                insert_len = (*input++) + 17 + length * 256;
   86|  1.88k|                insert_byte = '\0';
   87|  1.88k|                break;
   88|    986|            case SAS_RLE_COMMAND_COPY1:  copy_len = length + 1; break;
  ------------------
  |  |   20|    986|#define SAS_RLE_COMMAND_COPY1           8
  ------------------
  |  Branch (88:13): [True: 986, False: 42.5k]
  ------------------
   89|    362|            case SAS_RLE_COMMAND_COPY17: copy_len = length + 17; break;
  ------------------
  |  |   21|    362|#define SAS_RLE_COMMAND_COPY17          9
  ------------------
  |  Branch (89:13): [True: 362, False: 43.1k]
  ------------------
   90|    567|            case SAS_RLE_COMMAND_COPY33: copy_len = length + 33; break;
  ------------------
  |  |   22|    567|#define SAS_RLE_COMMAND_COPY33         10
  ------------------
  |  Branch (90:13): [True: 567, False: 42.9k]
  ------------------
   91|    395|            case SAS_RLE_COMMAND_COPY49: copy_len = length + 49; break;
  ------------------
  |  |   23|    395|#define SAS_RLE_COMMAND_COPY49         11
  ------------------
  |  Branch (91:13): [True: 395, False: 43.1k]
  ------------------
   92|    828|            case SAS_RLE_COMMAND_INSERT_BYTE3:
  ------------------
  |  |   24|    828|#define SAS_RLE_COMMAND_INSERT_BYTE3   12
  ------------------
  |  Branch (92:13): [True: 828, False: 42.6k]
  ------------------
   93|    828|                insert_byte = *input++;
   94|    828|                insert_len = length + 3;
   95|    828|                break;
   96|    731|            case SAS_RLE_COMMAND_INSERT_AT2:
  ------------------
  |  |   25|    731|#define SAS_RLE_COMMAND_INSERT_AT2     13
  ------------------
  |  Branch (96:13): [True: 731, False: 42.7k]
  ------------------
   97|    731|                insert_byte = '@';
   98|    731|                insert_len = length + 2;
   99|    731|                break;
  100|  24.7k|            case SAS_RLE_COMMAND_INSERT_BLANK2:
  ------------------
  |  |   26|  24.7k|#define SAS_RLE_COMMAND_INSERT_BLANK2  14
  ------------------
  |  Branch (100:13): [True: 24.7k, False: 18.7k]
  ------------------
  101|  24.7k|                insert_byte = ' ';
  102|  24.7k|                insert_len = length + 2;
  103|  24.7k|                break;
  104|  4.11k|            case SAS_RLE_COMMAND_INSERT_ZERO2:
  ------------------
  |  |   27|  4.11k|#define SAS_RLE_COMMAND_INSERT_ZERO2   15
  ------------------
  |  Branch (104:13): [True: 4.11k, False: 39.3k]
  ------------------
  105|  4.11k|                insert_byte = '\0';
  106|  4.11k|                insert_len = length + 2;
  107|  4.11k|                break;
  108|  2.63k|            default:
  ------------------
  |  Branch (108:13): [True: 2.63k, False: 40.8k]
  ------------------
  109|       |                /* error out here? */
  110|  2.63k|                break;
  111|  43.4k|        }
  112|  43.4k|        if (copy_len) {
  ------------------
  |  Branch (112:13): [True: 6.24k, False: 37.2k]
  ------------------
  113|  6.24k|            if (output_written + copy_len > output_len) {
  ------------------
  |  Branch (113:17): [True: 22, False: 6.22k]
  ------------------
  114|     22|                return -1;
  115|     22|            }
  116|  6.22k|            if (input + copy_len > (const unsigned char *)input_buf + input_len) {
  ------------------
  |  Branch (116:17): [True: 83, False: 6.14k]
  ------------------
  117|     83|                return -1;
  118|     83|            }
  119|  6.14k|            if (output) {
  ------------------
  |  Branch (119:17): [True: 6.14k, False: 0]
  ------------------
  120|  6.14k|                memcpy(&output[output_written], input, copy_len);
  121|  6.14k|            }
  122|  6.14k|            input += copy_len;
  123|  6.14k|            output_written += copy_len;
  124|  6.14k|        }
  125|  43.3k|        if (insert_len) {
  ------------------
  |  Branch (125:13): [True: 34.6k, False: 8.78k]
  ------------------
  126|  34.6k|            if (output_written + insert_len > output_len) {
  ------------------
  |  Branch (126:17): [True: 11, False: 34.5k]
  ------------------
  127|     11|                return -1;
  128|     11|            }
  129|  34.5k|            if (output) {
  ------------------
  |  Branch (129:17): [True: 34.5k, False: 0]
  ------------------
  130|  34.5k|                memset(&output[output_written], insert_byte, insert_len);
  131|  34.5k|            }
  132|  34.5k|            output_written += insert_len;
  133|  34.5k|        }
  134|  43.3k|    }
  135|       |
  136|    364|    return output_written;
  137|    484|}

rt_open_handler:
    8|  3.56k|int rt_open_handler(const char *path, void *io_ctx) {
    9|  3.56k|    return 0;
   10|  3.56k|}
rt_close_handler:
   12|  3.56k|int rt_close_handler(void *io_ctx) {
   13|  3.56k|    return 0;
   14|  3.56k|}
rt_seek_handler:
   17|  29.6k|        readstat_io_flags_t whence, void *io_ctx) {
   18|  29.6k|    rt_buffer_ctx_t *buffer_ctx = (rt_buffer_ctx_t *)io_ctx;
   19|  29.6k|    readstat_off_t newpos = -1;
   20|  29.6k|    if (whence == READSTAT_SEEK_SET) {
  ------------------
  |  Branch (20:9): [True: 19.4k, False: 10.1k]
  ------------------
   21|  19.4k|        newpos = offset;
   22|  19.4k|    } else if (whence == READSTAT_SEEK_CUR) {
  ------------------
  |  Branch (22:16): [True: 6.62k, False: 3.56k]
  ------------------
   23|  6.62k|        newpos = buffer_ctx->pos + offset;
   24|  6.62k|    } else if (whence == READSTAT_SEEK_END) {
  ------------------
  |  Branch (24:16): [True: 3.56k, False: 0]
  ------------------
   25|  3.56k|        newpos = buffer_ctx->buffer->used + offset;
   26|  3.56k|    }
   27|       |
   28|  29.6k|    if (newpos < 0)
  ------------------
  |  Branch (28:9): [True: 126, False: 29.5k]
  ------------------
   29|    126|        return -1;
   30|       |
   31|  29.5k|    if (newpos > buffer_ctx->buffer->used)
  ------------------
  |  Branch (31:9): [True: 231, False: 29.3k]
  ------------------
   32|    231|        return -1;
   33|       |
   34|  29.3k|    buffer_ctx->pos = newpos;
   35|  29.3k|    return newpos;
   36|  29.5k|}
rt_read_handler:
   38|  51.5k|ssize_t rt_read_handler(void *buf, size_t nbytes, void *io_ctx) {
   39|  51.5k|    rt_buffer_ctx_t *buffer_ctx = (rt_buffer_ctx_t *)io_ctx;
   40|  51.5k|    ssize_t bytes_copied = 0;
   41|  51.5k|    ssize_t bytes_left = buffer_ctx->buffer->used - buffer_ctx->pos;
   42|  51.5k|    if (nbytes <= bytes_left) {
  ------------------
  |  Branch (42:9): [True: 51.1k, False: 428]
  ------------------
   43|  51.1k|        memcpy(buf, buffer_ctx->buffer->bytes + buffer_ctx->pos, nbytes);
   44|  51.1k|        bytes_copied = nbytes;
   45|  51.1k|    } else if (bytes_left > 0) {
  ------------------
  |  Branch (45:16): [True: 222, False: 206]
  ------------------
   46|    222|        memcpy(buf, buffer_ctx->buffer->bytes + buffer_ctx->pos, bytes_left);
   47|    222|        bytes_copied = bytes_left;
   48|    222|    }
   49|  51.5k|    buffer_ctx->pos += bytes_copied;
   50|  51.5k|    return bytes_copied;
   51|  51.5k|}
rt_update_handler:
   54|  4.03k|        void *user_ctx, void *io_ctx) {
   55|  4.03k|    if (!progress_handler)
  ------------------
  |  Branch (55:9): [True: 4.03k, False: 0]
  ------------------
   56|  4.03k|        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|}

