fuzzer_parser_init:
   33|  3.60k|readstat_parser_t *fuzzer_parser_init(const uint8_t *Data, size_t Size) {
   34|  3.60k|    readstat_parser_t *parser = readstat_parser_init();
   35|  3.60k|    readstat_set_open_handler(parser, rt_open_handler);
   36|  3.60k|    readstat_set_close_handler(parser, rt_close_handler);
   37|  3.60k|    readstat_set_seek_handler(parser, rt_seek_handler);
   38|  3.60k|    readstat_set_read_handler(parser, rt_read_handler);
   39|  3.60k|    readstat_set_update_handler(parser, rt_update_handler);
   40|       |
   41|  3.60k|    readstat_set_metadata_handler(parser, &handle_metadata);
   42|  3.60k|    readstat_set_note_handler(parser, &handle_note);
   43|  3.60k|    readstat_set_variable_handler(parser, &handle_variable);
   44|  3.60k|    readstat_set_fweight_handler(parser, &handle_fweight);
   45|  3.60k|    readstat_set_value_handler(parser, &handle_value);
   46|  3.60k|    readstat_set_value_label_handler(parser, &handle_value_label);
   47|       |
   48|  3.60k|    return parser;
   49|  3.60k|}
fuzz_format.c:handle_metadata:
    8|  1.37k|static int handle_metadata(readstat_metadata_t *metadata, void *ctx) {
    9|  1.37k|    return READSTAT_HANDLER_OK;
   10|  1.37k|}
fuzz_format.c:handle_variable:
   21|  3.78M|                           const char *val_labels, void *ctx) {
   22|  3.78M|    return READSTAT_HANDLER_OK;
   23|  3.78M|}
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.60k|int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
   11|  3.60k|    rt_buffer_t buffer = { .bytes = (char *)Data, .size = Size, .used = Size };
   12|  3.60k|    rt_buffer_ctx_t buffer_ctx = { .buffer = &buffer };
   13|       |
   14|  3.60k|    readstat_parser_t *parser = fuzzer_parser_init(Data, Size);
   15|  3.60k|    readstat_set_io_ctx(parser, &buffer_ctx);
   16|       |
   17|  3.60k|    readstat_parse_sas7bdat(parser, NULL, NULL);
   18|  3.60k|    readstat_parser_free(parser);
   19|  3.60k|    return 0;
   20|  3.60k|}

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

readstat_convert:
    7|  4.54M|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: 67.8k, False: 4.52M]
  |  Branch (10:24): [True: 3.95k, False: 63.8k]
  |  Branch (10:49): [True: 41.3k, False: 22.4k]
  ------------------
   11|  45.3k|        src_len--;
   12|  45.3k|    }
   13|  4.54M|    if (dst_len == 0) {
  ------------------
  |  Branch (13:9): [True: 0, False: 4.54M]
  ------------------
   14|      0|        return READSTAT_ERROR_CONVERT_LONG_STRING;
   15|  4.54M|    } else if (converter) {
  ------------------
  |  Branch (15:16): [True: 3.28M, False: 1.25M]
  ------------------
   16|  3.28M|        size_t dst_left = dst_len - 1;
   17|  3.28M|        char *dst_end = dst;
   18|  3.28M|        size_t status = iconv(converter, (readstat_iconv_inbuf_t)&src, &src_len, &dst_end, &dst_left);
   19|  3.28M|        if (status == (size_t)-1) {
  ------------------
  |  Branch (19:13): [True: 2.28k, False: 3.28M]
  ------------------
   20|  2.28k|            if (errno == E2BIG) {
  ------------------
  |  Branch (20:17): [True: 6, False: 2.28k]
  ------------------
   21|      6|                return READSTAT_ERROR_CONVERT_LONG_STRING;
   22|  2.28k|            } else if (errno == EILSEQ) {
  ------------------
  |  Branch (22:24): [True: 31, False: 2.24k]
  ------------------
   23|     31|                return READSTAT_ERROR_CONVERT_BAD_STRING;
   24|  2.24k|            } else if (errno != EINVAL) { /* EINVAL indicates improper truncation; accept it */
  ------------------
  |  Branch (24:24): [True: 0, False: 2.24k]
  ------------------
   25|      0|                return READSTAT_ERROR_CONVERT;
   26|      0|            }
   27|  2.28k|        }
   28|  3.28M|        dst[dst_len - dst_left - 1] = '\0';
   29|  3.28M|    } else if (src_len + 1 > dst_len) {
  ------------------
  |  Branch (29:16): [True: 19, False: 1.25M]
  ------------------
   30|     19|        return READSTAT_ERROR_CONVERT_LONG_STRING;
   31|  1.25M|    } else {
   32|  1.25M|        memcpy(dst, src, src_len);
   33|  1.25M|        dst[src_len] = '\0';
   34|  1.25M|    }
   35|  4.54M|    return READSTAT_OK;
   36|  4.54M|}

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

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

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

sas_read8:
  139|  47.7k|uint64_t sas_read8(const char *data, int bswap) {
  140|  47.7k|    uint64_t tmp;
  141|  47.7k|    memcpy(&tmp, data, 8);
  142|  47.7k|    return bswap ? byteswap8(tmp) : tmp;
  ------------------
  |  Branch (142:12): [True: 42.2k, False: 5.53k]
  ------------------
  143|  47.7k|}
sas_read4:
  145|   229k|uint32_t sas_read4(const char *data, int bswap) {
  146|   229k|    uint32_t tmp;
  147|   229k|    memcpy(&tmp, data, 4);
  148|   229k|    return bswap ? byteswap4(tmp) : tmp;
  ------------------
  |  Branch (148:12): [True: 172k, False: 57.1k]
  ------------------
  149|   229k|}
sas_read2:
  151|   214k|uint16_t sas_read2(const char *data, int bswap) {
  152|   214k|    uint16_t tmp;
  153|   214k|    memcpy(&tmp, data, 2);
  154|   214k|    return bswap ? byteswap2(tmp) : tmp;
  ------------------
  |  Branch (154:12): [True: 81.7k, False: 132k]
  ------------------
  155|   214k|}
sas_subheader_remainder:
  157|  6.55k|size_t sas_subheader_remainder(size_t len, size_t signature_len) {
  158|  6.55k|    return len - (4+2*signature_len);
  159|  6.55k|}
sas_read_header:
  162|  3.60k|        readstat_error_handler error_handler, void *user_ctx) {
  163|  3.60k|    sas_header_start_t  header_start;
  164|  3.60k|    sas_header_end_t    header_end;
  165|  3.60k|    int retval = READSTAT_OK;
  166|  3.60k|    char error_buf[1024];
  167|  3.60k|    time_t epoch = sas_epoch();
  168|       |
  169|  3.60k|    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.58k]
  ------------------
  170|     20|        retval = READSTAT_ERROR_READ;
  171|     20|        goto cleanup;
  172|     20|    }
  173|  3.58k|    if (memcmp(header_start.magic, sas7bdat_magic_number, sizeof(sas7bdat_magic_number)) != 0 &&
  ------------------
  |  Branch (173:9): [True: 1.64k, False: 1.93k]
  ------------------
  174|  1.64k|            memcmp(header_start.magic, sas7bcat_magic_number, sizeof(sas7bcat_magic_number)) != 0) {
  ------------------
  |  Branch (174:13): [True: 126, False: 1.52k]
  ------------------
  175|    126|        retval = READSTAT_ERROR_PARSE;
  176|    126|        goto cleanup;
  177|    126|    }
  178|  3.45k|    if (header_start.a1 == SAS_ALIGNMENT_OFFSET_4) {
  ------------------
  |  |   87|  3.45k|#define SAS_ALIGNMENT_OFFSET_4  0x33
  ------------------
  |  Branch (178:9): [True: 8, False: 3.44k]
  ------------------
  179|      8|        hinfo->pad1 = 4;
  180|      8|    }
  181|  3.45k|    if (header_start.a2 == SAS_ALIGNMENT_OFFSET_4) {
  ------------------
  |  |   87|  3.45k|#define SAS_ALIGNMENT_OFFSET_4  0x33
  ------------------
  |  Branch (181:9): [True: 1.60k, False: 1.85k]
  ------------------
  182|  1.60k|        hinfo->u64 = 1;
  183|  1.60k|    }
  184|  3.45k|    int bswap = 0;
  185|  3.45k|    if (header_start.endian == SAS_ENDIAN_BIG) {
  ------------------
  |  |   80|  3.45k|#define SAS_ENDIAN_BIG       0x00
  ------------------
  |  Branch (185:9): [True: 2.74k, False: 714]
  ------------------
  186|  2.74k|        bswap = machine_is_little_endian();
  187|  2.74k|        hinfo->little_endian = 0;
  188|  2.74k|    } else if (header_start.endian == SAS_ENDIAN_LITTLE) {
  ------------------
  |  |   81|    714|#define SAS_ENDIAN_LITTLE    0x01
  ------------------
  |  Branch (188:16): [True: 701, False: 13]
  ------------------
  189|    701|        bswap = !machine_is_little_endian();
  190|    701|        hinfo->little_endian = 1;
  191|    701|    } else {
  192|     13|        retval = READSTAT_ERROR_PARSE;
  193|     13|        goto cleanup;
  194|     13|    }
  195|  3.44k|    int i;
  196|  23.6k|    for (i=0; i<sizeof(_charset_table)/sizeof(_charset_table[0]); i++) {
  ------------------
  |  Branch (196:15): [True: 23.6k, False: 5]
  ------------------
  197|  23.6k|        if (header_start.encoding == _charset_table[i].code) {
  ------------------
  |  Branch (197:13): [True: 3.43k, False: 20.2k]
  ------------------
  198|  3.43k|            hinfo->encoding = _charset_table[i].name;
  199|  3.43k|            break;
  200|  3.43k|        }
  201|  23.6k|    }
  202|  3.44k|    if (hinfo->encoding == NULL) {
  ------------------
  |  Branch (202:9): [True: 5, False: 3.43k]
  ------------------
  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.43k|    memcpy(hinfo->table_name, header_start.table_name, sizeof(header_start.table_name));
  211|  3.43k|    if (io->seek(hinfo->pad1, READSTAT_SEEK_CUR, io->io_ctx) == -1) {
  ------------------
  |  Branch (211:9): [True: 5, False: 3.43k]
  ------------------
  212|      5|        retval = READSTAT_ERROR_SEEK;
  213|      5|        goto cleanup;
  214|      5|    }
  215|       |
  216|  3.43k|    double creation_time, modification_time, creation_time_diff, modification_time_diff;
  217|       |
  218|  3.43k|    if (io->read(&creation_time, sizeof(double), io->io_ctx) < sizeof(double)) {
  ------------------
  |  Branch (218:9): [True: 9, False: 3.42k]
  ------------------
  219|      9|        retval = READSTAT_ERROR_READ;
  220|      9|        goto cleanup;
  221|      9|    }
  222|  3.42k|    if (bswap)
  ------------------
  |  Branch (222:9): [True: 2.72k, False: 699]
  ------------------
  223|  2.72k|        creation_time = byteswap_double(creation_time);
  224|       |
  225|  3.42k|    if (io->read(&modification_time, sizeof(double), io->io_ctx) < sizeof(double)) {
  ------------------
  |  Branch (225:9): [True: 6, False: 3.41k]
  ------------------
  226|      6|        retval = READSTAT_ERROR_READ;
  227|      6|        goto cleanup;
  228|      6|    }
  229|  3.41k|    if (bswap)
  ------------------
  |  Branch (229:9): [True: 2.72k, False: 697]
  ------------------
  230|  2.72k|        modification_time = byteswap_double(modification_time);
  231|       |
  232|  3.41k|    if (io->read(&creation_time_diff, sizeof(double), io->io_ctx) < sizeof(double)) {
  ------------------
  |  Branch (232:9): [True: 6, False: 3.41k]
  ------------------
  233|      6|        retval = READSTAT_ERROR_READ;
  234|      6|        goto cleanup;
  235|      6|    }
  236|  3.41k|    if (bswap)
  ------------------
  |  Branch (236:9): [True: 2.71k, False: 695]
  ------------------
  237|  2.71k|        creation_time_diff = byteswap_double(creation_time_diff);
  238|       |    
  239|  3.41k|    if (io->read(&modification_time_diff, sizeof(double), io->io_ctx) < sizeof(double)) {
  ------------------
  |  Branch (239:9): [True: 6, False: 3.40k]
  ------------------
  240|      6|        retval = READSTAT_ERROR_READ;
  241|      6|        goto cleanup;
  242|      6|    }
  243|  3.40k|    if (bswap)
  ------------------
  |  Branch (243:9): [True: 2.71k, False: 694]
  ------------------
  244|  2.71k|        modification_time_diff = byteswap_double(modification_time_diff);
  245|       |    
  246|  3.40k|    hinfo->creation_time = sas_convert_time(creation_time, creation_time_diff, epoch);
  247|  3.40k|    hinfo->modification_time = sas_convert_time(modification_time, modification_time_diff, epoch);
  248|       |
  249|  3.40k|    uint32_t header_size, page_size;
  250|       |
  251|  3.40k|    if (io->read(&header_size, sizeof(uint32_t), io->io_ctx) < sizeof(uint32_t)) {
  ------------------
  |  Branch (251:9): [True: 9, False: 3.39k]
  ------------------
  252|      9|        retval = READSTAT_ERROR_READ;
  253|      9|        goto cleanup;
  254|      9|    }
  255|  3.39k|    if (io->read(&page_size, sizeof(uint32_t), io->io_ctx) < sizeof(uint32_t)) {
  ------------------
  |  Branch (255:9): [True: 3, False: 3.39k]
  ------------------
  256|      3|        retval = READSTAT_ERROR_READ;
  257|      3|        goto cleanup;
  258|      3|    }
  259|       |
  260|  3.39k|    hinfo->header_size = bswap ? byteswap4(header_size) : header_size;
  ------------------
  |  Branch (260:26): [True: 2.70k, False: 692]
  ------------------
  261|  3.39k|    hinfo->page_size = bswap ? byteswap4(page_size) : page_size;
  ------------------
  |  Branch (261:24): [True: 2.70k, False: 692]
  ------------------
  262|       |
  263|  3.39k|    if (hinfo->header_size < 1024 || hinfo->page_size < 1024) {
  ------------------
  |  Branch (263:9): [True: 12, False: 3.38k]
  |  Branch (263:38): [True: 11, False: 3.37k]
  ------------------
  264|     23|        retval = READSTAT_ERROR_PARSE;
  265|     23|        goto cleanup;
  266|     23|    }
  267|  3.37k|    if (hinfo->header_size > (1<<24) || hinfo->page_size > (1<<24)) {
  ------------------
  |  Branch (267:9): [True: 23, False: 3.34k]
  |  Branch (267:41): [True: 30, False: 3.31k]
  ------------------
  268|     53|        retval = READSTAT_ERROR_PARSE;
  269|     53|        goto cleanup;
  270|     53|    }
  271|       |
  272|  3.31k|    if (hinfo->u64) {
  ------------------
  |  Branch (272:9): [True: 1.55k, False: 1.76k]
  ------------------
  273|  1.55k|        hinfo->page_header_size = SAS_PAGE_HEADER_SIZE_64BIT;
  ------------------
  |  |  121|  1.55k|#define SAS_PAGE_HEADER_SIZE_64BIT  40
  ------------------
  274|  1.55k|        hinfo->subheader_pointer_size = SAS_SUBHEADER_POINTER_SIZE_64BIT;
  ------------------
  |  |  118|  1.55k|#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.31k|    if (hinfo->u64) {
  ------------------
  |  Branch (280:9): [True: 1.55k, False: 1.76k]
  ------------------
  281|  1.55k|        uint64_t page_count;
  282|  1.55k|        if (io->read(&page_count, sizeof(uint64_t), io->io_ctx) < sizeof(uint64_t)) {
  ------------------
  |  Branch (282:13): [True: 19, False: 1.53k]
  ------------------
  283|     19|            retval = READSTAT_ERROR_READ;
  284|     19|            goto cleanup;
  285|     19|        }
  286|  1.53k|        hinfo->page_count = bswap ? byteswap8(page_count) : page_count;
  ------------------
  |  Branch (286:29): [True: 1.43k, False: 98]
  ------------------
  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: 15, False: 1.75k]
  ------------------
  290|     15|            retval = READSTAT_ERROR_READ;
  291|     15|            goto cleanup;
  292|     15|        }
  293|  1.75k|        hinfo->page_count = bswap ? byteswap4(page_count) : page_count;
  ------------------
  |  Branch (293:29): [True: 1.16k, False: 582]
  ------------------
  294|  1.75k|    }
  295|  3.28k|    if (hinfo->page_count > (1<<24)) {
  ------------------
  |  Branch (295:9): [True: 19, False: 3.26k]
  ------------------
  296|     19|        retval = READSTAT_ERROR_PARSE;
  297|     19|        goto cleanup;
  298|     19|    }
  299|       |    
  300|  3.26k|    if (io->seek(8, READSTAT_SEEK_CUR, io->io_ctx) == -1) {
  ------------------
  |  Branch (300:9): [True: 74, False: 3.19k]
  ------------------
  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.19k|    if (io->read(&header_end, sizeof(sas_header_end_t), io->io_ctx) < sizeof(sas_header_end_t)) {
  ------------------
  |  Branch (308:9): [True: 17, False: 3.17k]
  ------------------
  309|     17|        retval = READSTAT_ERROR_READ;
  310|     17|        goto cleanup;
  311|     17|    }
  312|  3.17k|    char major, revision_tag;
  313|  3.17k|    int minor, revision;
  314|  3.17k|    if (sscanf(header_end.release, "%c.%04d%c%1d", &major, &minor, &revision_tag, &revision) != 4) {
  ------------------
  |  Branch (314:9): [True: 4, False: 3.16k]
  ------------------
  315|      4|        retval = READSTAT_ERROR_PARSE;
  316|      4|        goto cleanup;
  317|      4|    }
  318|       |
  319|  3.16k|    if (major >= '1' && major <= '9') {
  ------------------
  |  Branch (319:9): [True: 3.15k, False: 12]
  |  Branch (319:25): [True: 3.14k, False: 11]
  ------------------
  320|  3.14k|        hinfo->major_version = major - '0';
  321|  3.14k|    } else if (major == 'V') {
  ------------------
  |  Branch (321:16): [True: 3, False: 20]
  ------------------
  322|       |        // It appears that SAS Visual Forecaster reports the major version as "V"
  323|       |        // Treat it as version 9 for all intents and purposes
  324|      3|        hinfo->major_version = 9;
  325|     20|    } else {
  326|     20|        retval = READSTAT_ERROR_PARSE;
  327|     20|        goto cleanup;
  328|     20|    }
  329|       |    // revision_tag is usually M, but J has been observed in the wild (not created with SAS?)
  330|  3.14k|    if (revision_tag != 'M' && revision_tag != 'J') {
  ------------------
  |  Branch (330:9): [True: 26, False: 3.12k]
  |  Branch (330:32): [True: 15, False: 11]
  ------------------
  331|     15|        retval = READSTAT_ERROR_PARSE;
  332|     15|        goto cleanup;
  333|     15|    }
  334|  3.13k|    hinfo->minor_version = minor;
  335|  3.13k|    hinfo->revision = revision;
  336|       |
  337|  3.13k|    if ((major == '8' || major == '9') && minor == 0 && revision == 0) {
  ------------------
  |  Branch (337:10): [True: 287, False: 2.84k]
  |  Branch (337:26): [True: 151, False: 2.69k]
  |  Branch (337:43): [True: 83, False: 355]
  |  Branch (337:57): [True: 66, False: 17]
  ------------------
  338|       |        /* A bit of a hack, but most SAS installations are running a minor update */
  339|     66|        hinfo->vendor = READSTAT_VENDOR_STAT_TRANSFER;
  340|  3.06k|    } else {
  341|  3.06k|        hinfo->vendor = READSTAT_VENDOR_SAS;
  342|  3.06k|    }
  343|  3.13k|    if (io->seek(hinfo->header_size, READSTAT_SEEK_SET, io->io_ctx) == -1) {
  ------------------
  |  Branch (343:9): [True: 52, False: 3.08k]
  ------------------
  344|     52|        retval = READSTAT_ERROR_SEEK;
  345|     52|        if (error_handler) {
  ------------------
  |  Branch (345:13): [True: 0, False: 52]
  ------------------
  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|     52|        goto cleanup;
  351|     52|    }
  352|       |
  353|  3.60k|cleanup:
  354|  3.60k|    return retval;
  355|  3.13k|}
sas_validate_tag:
  507|  8.11k|readstat_error_t sas_validate_tag(char tag) {
  508|  8.11k|    if (tag == '_' || (tag >= 'A' && tag <= 'Z'))
  ------------------
  |  Branch (508:9): [True: 4.39k, False: 3.71k]
  |  Branch (508:24): [True: 1.23k, False: 2.48k]
  |  Branch (508:38): [True: 918, False: 318]
  ------------------
  509|  5.31k|        return READSTAT_OK;
  510|       |
  511|  2.80k|    return READSTAT_ERROR_TAGGED_VALUE_IS_OUT_OF_RANGE;
  512|  8.11k|}
sas_assign_tag:
  514|  8.11k|void sas_assign_tag(readstat_value_t *value, uint8_t tag) {
  515|       |    /* We accommodate two tag schemes. In the first, the tag is an ASCII code
  516|       |     * given by uint8_t tag above. System missing is represented by an ASCII
  517|       |     * period. In the second scheme, (tag-2) is an offset from 'A', except when
  518|       |     * tag == 0, in which case it represents an underscore, or tag == 1, in
  519|       |     * which case it represents system-missing.
  520|       |     */
  521|  8.11k|    if (tag == 0) {
  ------------------
  |  Branch (521:9): [True: 4.39k, False: 3.71k]
  ------------------
  522|  4.39k|        tag = '_';
  523|  4.39k|    } else if (tag >= 2 && tag < 28) {
  ------------------
  |  Branch (523:16): [True: 3.23k, False: 486]
  |  Branch (523:28): [True: 842, False: 2.39k]
  ------------------
  524|    842|        tag = 'A' + (tag - 2);
  525|    842|    }
  526|  8.11k|    if (sas_validate_tag(tag) == READSTAT_OK) {
  ------------------
  |  Branch (526:9): [True: 5.31k, False: 2.80k]
  ------------------
  527|  5.31k|        value->tag = tag;
  528|  5.31k|        value->is_tagged_missing = 1;
  529|  5.31k|    } else {
  530|  2.80k|        value->tag = 0;
  531|  2.80k|        value->is_system_missing = 1;
  532|  2.80k|    }
  533|  8.11k|}
readstat_sas.c:sas_epoch:
  123|  3.60k|static time_t sas_epoch(void) {
  124|  3.60k|    return - 3653 * 86400; // seconds between 01-01-1960 and 01-01-1970
  125|  3.60k|}
readstat_sas.c:sas_convert_time:
  127|  6.81k|static time_t sas_convert_time(double time, double time_diff, time_t epoch) {
  128|  6.81k|    time -= time_diff;
  129|  6.81k|    time += epoch;
  130|  6.81k|    if (isnan(time))
  ------------------
  |  Branch (130:9): [True: 812, False: 5.99k]
  ------------------
  131|    812|        return 0;
  132|  5.99k|    if (time > (double)LONG_MAX)
  ------------------
  |  Branch (132:9): [True: 1.69k, False: 4.29k]
  ------------------
  133|  1.69k|        return LONG_MAX;
  134|  4.29k|    if (time < (double)LONG_MIN)
  ------------------
  |  Branch (134:9): [True: 1.16k, False: 3.13k]
  ------------------
  135|  1.16k|        return LONG_MIN;
  136|  3.13k|    return time;
  137|  4.29k|}

readstat_parse_sas7bdat:
 1206|  3.60k|readstat_error_t readstat_parse_sas7bdat(readstat_parser_t *parser, const char *path, void *user_ctx) {
 1207|  3.60k|    int64_t last_examined_page_pass1 = 0;
 1208|  3.60k|    readstat_error_t retval = READSTAT_OK;
 1209|  3.60k|    readstat_io_t *io = parser->io;
 1210|       |
 1211|  3.60k|    sas7bdat_ctx_t  *ctx = calloc(1, sizeof(sas7bdat_ctx_t));
 1212|  3.60k|    sas_header_info_t  *hinfo = calloc(1, sizeof(sas_header_info_t));
 1213|       |
 1214|  3.60k|    ctx->handle = parser->handlers;
 1215|  3.60k|    ctx->input_encoding = parser->input_encoding;
 1216|  3.60k|    ctx->output_encoding = parser->output_encoding;
 1217|  3.60k|    ctx->user_ctx = user_ctx;
 1218|  3.60k|    ctx->io = parser->io;
 1219|  3.60k|    ctx->row_limit = parser->row_limit;
 1220|  3.60k|    if (parser->row_offset > 0)
  ------------------
  |  Branch (1220:9): [True: 0, False: 3.60k]
  ------------------
 1221|      0|        ctx->row_offset = parser->row_offset;
 1222|       |
 1223|  3.60k|    if (io->open(path, io->io_ctx) == -1) {
  ------------------
  |  Branch (1223:9): [True: 0, False: 3.60k]
  ------------------
 1224|      0|        retval = READSTAT_ERROR_OPEN;
 1225|      0|        goto cleanup;
 1226|      0|    }
 1227|       |
 1228|  3.60k|    if ((ctx->file_size = io->seek(0, READSTAT_SEEK_END, io->io_ctx)) == -1) {
  ------------------
  |  Branch (1228:9): [True: 0, False: 3.60k]
  ------------------
 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.60k|    if (io->seek(0, READSTAT_SEEK_SET, io->io_ctx) == -1) {
  ------------------
  |  Branch (1237:9): [True: 0, False: 3.60k]
  ------------------
 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.60k|    if ((retval = sas_read_header(io, hinfo, ctx->handle.error, user_ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1246:9): [True: 519, False: 3.08k]
  ------------------
 1247|    519|        goto cleanup;
 1248|    519|    }
 1249|       |
 1250|  3.08k|    ctx->u64 = hinfo->u64;
 1251|  3.08k|    ctx->little_endian = hinfo->little_endian;
 1252|  3.08k|    ctx->vendor = hinfo->vendor;
 1253|  3.08k|    ctx->bswap = machine_is_little_endian() ^ hinfo->little_endian;
 1254|  3.08k|    ctx->header_size = hinfo->header_size;
 1255|  3.08k|    ctx->page_count = hinfo->page_count;
 1256|  3.08k|    ctx->page_size = hinfo->page_size;
 1257|  3.08k|    ctx->page_header_size = hinfo->page_header_size;
 1258|  3.08k|    ctx->subheader_pointer_size = hinfo->subheader_pointer_size;
 1259|  3.08k|    ctx->subheader_signature_size = ctx->u64 ? 8 : 4;
  ------------------
  |  Branch (1259:37): [True: 1.47k, False: 1.60k]
  ------------------
 1260|  3.08k|    ctx->ctime = hinfo->creation_time;
 1261|  3.08k|    ctx->mtime = hinfo->modification_time;
 1262|  3.08k|    ctx->version = hinfo->major_version;
 1263|  3.08k|    if (ctx->input_encoding == NULL) {
  ------------------
  |  Branch (1263:9): [True: 3.08k, False: 0]
  ------------------
 1264|  3.08k|        ctx->input_encoding = hinfo->encoding;
 1265|  3.08k|    }
 1266|  3.08k|    if ((ctx->page = readstat_malloc(ctx->page_size)) == NULL) {
  ------------------
  |  Branch (1266:9): [True: 0, False: 3.08k]
  ------------------
 1267|      0|        retval = READSTAT_ERROR_MALLOC;
 1268|      0|        goto cleanup;
 1269|      0|    }
 1270|       |
 1271|  3.08k|    if (ctx->input_encoding && ctx->output_encoding && strcmp(ctx->input_encoding, ctx->output_encoding) != 0) {
  ------------------
  |  Branch (1271:9): [True: 3.08k, False: 0]
  |  Branch (1271:32): [True: 3.08k, False: 0]
  |  Branch (1271:56): [True: 2.19k, False: 890]
  ------------------
 1272|  2.19k|        iconv_t converter = iconv_open(ctx->output_encoding, ctx->input_encoding);
 1273|  2.19k|        if (converter == (iconv_t)-1) {
  ------------------
  |  Branch (1273:13): [True: 1, False: 2.19k]
  ------------------
 1274|      1|            retval = READSTAT_ERROR_UNSUPPORTED_CHARSET;
 1275|      1|            goto cleanup;
 1276|      1|        }
 1277|  2.19k|        ctx->converter = converter;
 1278|  2.19k|    }
 1279|       |
 1280|  3.08k|    if ((retval = readstat_convert(ctx->table_name, sizeof(ctx->table_name),
  ------------------
  |  Branch (1280:9): [True: 4, False: 3.07k]
  ------------------
 1281|  3.08k|                hinfo->table_name, sizeof(hinfo->table_name), ctx->converter)) != READSTAT_OK) {
 1282|      4|        goto cleanup;
 1283|      4|    }
 1284|       |
 1285|  3.07k|    if ((retval = sas7bdat_parse_meta_pages_pass1(ctx, &last_examined_page_pass1)) != READSTAT_OK) {
  ------------------
  |  Branch (1285:9): [True: 219, False: 2.85k]
  ------------------
 1286|    219|        goto cleanup;
 1287|    219|    }
 1288|       |
 1289|  2.85k|    if ((retval = sas7bdat_parse_amd_pages_pass1(last_examined_page_pass1, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1289:9): [True: 961, False: 1.89k]
  ------------------
 1290|    961|        goto cleanup;
 1291|    961|    }
 1292|       |
 1293|  1.89k|    if (io->seek(ctx->header_size, READSTAT_SEEK_SET, io->io_ctx) == -1) {
  ------------------
  |  Branch (1293:9): [True: 0, False: 1.89k]
  ------------------
 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.89k|    if ((retval = sas7bdat_parse_all_pages_pass2(ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1303:9): [True: 1.54k, False: 349]
  ------------------
 1304|  1.54k|        goto cleanup;
 1305|  1.54k|    }
 1306|       |    
 1307|    349|    if ((retval = sas7bdat_submit_columns_if_needed(ctx, 0)) != READSTAT_OK) {
  ------------------
  |  Branch (1307:9): [True: 74, False: 275]
  ------------------
 1308|     74|        goto cleanup;
 1309|     74|    }
 1310|       |
 1311|    275|    if (ctx->handle.value && ctx->parsed_row_count != ctx->row_limit) {
  ------------------
  |  Branch (1311:9): [True: 275, False: 0]
  |  Branch (1311:30): [True: 102, False: 173]
  ------------------
 1312|    102|        retval = READSTAT_ERROR_ROW_COUNT_MISMATCH;
 1313|    102|        if (ctx->handle.error) {
  ------------------
  |  Branch (1313:13): [True: 0, False: 102]
  ------------------
 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|    102|        goto cleanup;
 1319|    102|    }
 1320|       |
 1321|    173|    if ((retval = sas7bdat_update_progress(ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1321:9): [True: 0, False: 173]
  ------------------
 1322|      0|        goto cleanup;
 1323|      0|    }
 1324|       |
 1325|  3.60k|cleanup:
 1326|  3.60k|    io->close(io->io_ctx);
 1327|       |
 1328|  3.60k|    if (retval == READSTAT_ERROR_OPEN ||
  ------------------
  |  Branch (1328:9): [True: 0, False: 3.60k]
  ------------------
 1329|  3.60k|            retval == READSTAT_ERROR_READ ||
  ------------------
  |  Branch (1329:13): [True: 408, False: 3.19k]
  ------------------
 1330|  3.19k|            retval == READSTAT_ERROR_SEEK) {
  ------------------
  |  Branch (1330:13): [True: 352, False: 2.84k]
  ------------------
 1331|    760|        if (ctx->handle.error) {
  ------------------
  |  Branch (1331:13): [True: 0, False: 760]
  ------------------
 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|    760|    }
 1337|       |
 1338|  3.60k|    if (ctx)
  ------------------
  |  Branch (1338:9): [True: 3.60k, False: 0]
  ------------------
 1339|  3.60k|        sas7bdat_ctx_free(ctx);
 1340|  3.60k|    if (hinfo)
  ------------------
  |  Branch (1340:9): [True: 3.60k, False: 0]
  ------------------
 1341|  3.60k|        free(hinfo);
 1342|       |
 1343|  3.60k|    return retval;
 1344|    173|}
readstat_sas7bdat_read.c:sas7bdat_parse_meta_pages_pass1:
 1047|  3.07k|static readstat_error_t sas7bdat_parse_meta_pages_pass1(sas7bdat_ctx_t *ctx, int64_t *outLastExaminedPage) {
 1048|  3.07k|    readstat_error_t retval = READSTAT_OK;
 1049|  3.07k|    readstat_io_t *io = ctx->io;
 1050|  3.07k|    int64_t i;
 1051|       |
 1052|       |    /* look for META and MIX pages at beginning... */
 1053|  7.97k|    for (i=0; i<ctx->page_count; i++) {
  ------------------
  |  Branch (1053:15): [True: 5.69k, False: 2.28k]
  ------------------
 1054|  5.69k|        if (io->seek(ctx->header_size + i*ctx->page_size, READSTAT_SEEK_SET, io->io_ctx) == -1) {
  ------------------
  |  Branch (1054:13): [True: 9, False: 5.68k]
  ------------------
 1055|      9|            retval = READSTAT_ERROR_SEEK;
 1056|      9|            if (ctx->handle.error) {
  ------------------
  |  Branch (1056:17): [True: 0, False: 9]
  ------------------
 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|      9|            goto cleanup;
 1063|      9|        }
 1064|       |
 1065|  5.68k|        readstat_off_t off = 0;
 1066|  5.68k|        if (ctx->u64)
  ------------------
  |  Branch (1066:13): [True: 3.72k, False: 1.96k]
  ------------------
 1067|  3.72k|            off = 16;
 1068|       |
 1069|  5.68k|        size_t head_len = off + 16 + 2;
 1070|  5.68k|        size_t tail_len = ctx->page_size - head_len;
 1071|       |
 1072|  5.68k|        if (io->read(ctx->page, head_len, io->io_ctx) < head_len) {
  ------------------
  |  Branch (1072:13): [True: 136, False: 5.54k]
  ------------------
 1073|    136|            retval = READSTAT_ERROR_READ;
 1074|    136|            goto cleanup;
 1075|    136|        }
 1076|       |
 1077|  5.54k|        uint16_t page_type = sas_read2(&ctx->page[off+16], ctx->bswap);
 1078|       |
 1079|  5.54k|        if ((page_type & SAS_PAGE_TYPE_MASK) == SAS_PAGE_TYPE_DATA)
  ------------------
  |  |  112|  5.54k|#define SAS_PAGE_TYPE_MASK   0x0F00
  ------------------
                      if ((page_type & SAS_PAGE_TYPE_MASK) == SAS_PAGE_TYPE_DATA)
  ------------------
  |  |  109|  5.54k|#define SAS_PAGE_TYPE_DATA   0x0100
  ------------------
  |  Branch (1079:13): [True: 576, False: 4.96k]
  ------------------
 1080|    576|            break;
 1081|  4.96k|        if ((page_type & SAS_PAGE_TYPE_COMP))
  ------------------
  |  |  115|  4.96k|#define SAS_PAGE_TYPE_COMP   0x9000
  ------------------
  |  Branch (1081:13): [True: 1.14k, False: 3.82k]
  ------------------
 1082|  1.14k|            continue;
 1083|       |
 1084|  3.82k|        if (io->read(ctx->page + head_len, tail_len, io->io_ctx) < tail_len) {
  ------------------
  |  Branch (1084:13): [True: 29, False: 3.79k]
  ------------------
 1085|     29|            retval = READSTAT_ERROR_READ;
 1086|     29|            goto cleanup;
 1087|     29|        }
 1088|       |
 1089|  3.79k|        if ((retval = sas7bdat_parse_page_pass1(ctx->page, ctx->page_size, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1089:13): [True: 45, False: 3.75k]
  ------------------
 1090|     45|            if (ctx->handle.error && retval != READSTAT_ERROR_USER_ABORT) {
  ------------------
  |  Branch (1090:17): [True: 0, False: 45]
  |  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|     45|            goto cleanup;
 1098|     45|        }
 1099|  3.79k|    }
 1100|       |
 1101|  3.07k|cleanup:
 1102|  3.07k|    if (outLastExaminedPage)
  ------------------
  |  Branch (1102:9): [True: 3.07k, False: 0]
  ------------------
 1103|  3.07k|        *outLastExaminedPage = i;
 1104|       |
 1105|  3.07k|    return retval;
 1106|  3.07k|}
readstat_sas7bdat_read.c:sas7bdat_parse_page_pass1:
  903|  6.63k|static readstat_error_t sas7bdat_parse_page_pass1(const char *page, size_t page_size, sas7bdat_ctx_t *ctx) {
  904|  6.63k|    readstat_error_t retval = READSTAT_OK;
  905|       |
  906|  6.63k|    uint16_t subheader_count = sas_read2(&page[ctx->page_header_size-4], ctx->bswap);
  907|       |
  908|  6.63k|    int i;
  909|  6.63k|    const char *shp = &page[ctx->page_header_size];
  910|  6.63k|    int lshp = ctx->subheader_pointer_size;
  911|       |
  912|  6.63k|    if (ctx->page_header_size + subheader_count*lshp > page_size) {
  ------------------
  |  Branch (912:9): [True: 39, False: 6.59k]
  ------------------
  913|     39|        retval = READSTAT_ERROR_PARSE;
  914|     39|        goto cleanup;
  915|     39|    }
  916|       |
  917|  67.9k|    for (i=0; i<subheader_count; i++) {
  ------------------
  |  Branch (917:15): [True: 62.1k, False: 5.86k]
  ------------------
  918|  62.1k|        subheader_pointer_t shp_info = { 0 };
  919|  62.1k|        if ((retval = sas7bdat_parse_subheader_pointer(shp, page + page_size - shp, &shp_info, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (919:13): [True: 0, False: 62.1k]
  ------------------
  920|      0|            goto cleanup;
  921|      0|        }
  922|  62.1k|        if (shp_info.len > 0 && shp_info.compression != SAS_COMPRESSION_TRUNC) {
  ------------------
  |  |  124|  40.1k|#define SAS_COMPRESSION_TRUNC  0x01
  ------------------
  |  Branch (922:13): [True: 40.1k, False: 21.9k]
  |  Branch (922:33): [True: 34.4k, False: 5.74k]
  ------------------
  923|  34.4k|            if ((retval = sas7bdat_validate_subheader_pointer(&shp_info, page_size, subheader_count, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (923:17): [True: 650, False: 33.7k]
  ------------------
  924|    650|                goto cleanup;
  925|    650|            }
  926|  33.7k|            if (shp_info.compression == SAS_COMPRESSION_NONE) {
  ------------------
  |  |  123|  33.7k|#define SAS_COMPRESSION_NONE   0x00
  ------------------
  |  Branch (926:17): [True: 30.9k, False: 2.79k]
  ------------------
  927|  30.9k|                sas_subheader_type_t subheader_type = sas7bdat_parse_subheader_type(page + shp_info.offset, ctx);
  928|  30.9k|                if (subheader_type == SAS_SUBHEADER_TYPE_COLUMN_TEXT) {
  ------------------
  |  Branch (928:21): [True: 2.90k, False: 28.0k]
  ------------------
  929|  2.90k|                    if ((retval = sas7bdat_parse_subheader(subheader_type, page + shp_info.offset, shp_info.len, ctx))
  ------------------
  |  Branch (929:25): [True: 59, False: 2.84k]
  ------------------
  930|  2.90k|                            != READSTAT_OK) {
  931|     59|                        goto cleanup;
  932|     59|                    }
  933|  2.90k|                }
  934|  30.9k|            } else if (shp_info.compression == SAS_COMPRESSION_ROW) {
  ------------------
  |  |  125|  2.79k|#define SAS_COMPRESSION_ROW    0x04
  ------------------
  |  Branch (934:24): [True: 2.77k, False: 22]
  ------------------
  935|       |                /* void */
  936|  2.77k|            } else {
  937|     22|                retval = READSTAT_ERROR_UNSUPPORTED_COMPRESSION;
  938|     22|                goto cleanup;
  939|     22|            }
  940|  33.7k|        }
  941|       |
  942|  61.3k|        shp += lshp;
  943|  61.3k|    }
  944|       |
  945|  6.63k|cleanup:
  946|       |
  947|  6.63k|    return retval;
  948|  6.59k|}
readstat_sas7bdat_read.c:sas7bdat_parse_subheader_pointer:
  857|  99.4k|        subheader_pointer_t *info, sas7bdat_ctx_t *ctx) {
  858|  99.4k|    readstat_error_t retval = READSTAT_OK;
  859|  99.4k|    if (ctx->u64) {
  ------------------
  |  Branch (859:9): [True: 16.9k, False: 82.4k]
  ------------------
  860|  16.9k|        if (shp_size <= 17) {
  ------------------
  |  Branch (860:13): [True: 0, False: 16.9k]
  ------------------
  861|      0|            retval = READSTAT_ERROR_PARSE;
  862|      0|            goto cleanup;
  863|      0|        }
  864|  16.9k|        info->offset = sas_read8(&shp[0], ctx->bswap);
  865|  16.9k|        info->len = sas_read8(&shp[8], ctx->bswap);
  866|  16.9k|        info->compression = shp[16];
  867|  16.9k|        info->is_compressed_data = shp[17];
  868|  82.4k|    } else {
  869|  82.4k|        if (shp_size <= 9) {
  ------------------
  |  Branch (869:13): [True: 0, False: 82.4k]
  ------------------
  870|      0|            retval = READSTAT_ERROR_PARSE;
  871|      0|            goto cleanup;
  872|      0|        }
  873|  82.4k|        info->offset = sas_read4(&shp[0], ctx->bswap);
  874|  82.4k|        info->len = sas_read4(&shp[4], ctx->bswap);
  875|  82.4k|        info->compression = shp[8];
  876|  82.4k|        info->is_compressed_data = shp[9];
  877|  82.4k|    }
  878|  99.4k|cleanup:
  879|  99.4k|    return retval;
  880|  99.4k|}
readstat_sas7bdat_read.c:sas7bdat_validate_subheader_pointer:
  883|  53.7k|        uint16_t subheader_count, sas7bdat_ctx_t *ctx) {
  884|  53.7k|    if (shp_info->offset > page_size)
  ------------------
  |  Branch (884:9): [True: 503, False: 53.2k]
  ------------------
  885|    503|        return READSTAT_ERROR_PARSE;
  886|  53.2k|    if (shp_info->len > page_size)
  ------------------
  |  Branch (886:9): [True: 294, False: 52.9k]
  ------------------
  887|    294|        return READSTAT_ERROR_PARSE;
  888|  52.9k|    if (shp_info->offset + shp_info->len > page_size)
  ------------------
  |  Branch (888:9): [True: 45, False: 52.9k]
  ------------------
  889|     45|        return READSTAT_ERROR_PARSE;
  890|  52.9k|    if (shp_info->offset < ctx->page_header_size + subheader_count*ctx->subheader_pointer_size)
  ------------------
  |  Branch (890:9): [True: 13, False: 52.9k]
  ------------------
  891|     13|        return READSTAT_ERROR_PARSE;
  892|  52.9k|    if (shp_info->compression == SAS_COMPRESSION_NONE) {
  ------------------
  |  |  123|  52.9k|#define SAS_COMPRESSION_NONE   0x00
  ------------------
  |  Branch (892:9): [True: 48.7k, False: 4.14k]
  ------------------
  893|  48.7k|        if (shp_info->len < ctx->subheader_signature_size)
  ------------------
  |  Branch (893:13): [True: 7, False: 48.7k]
  ------------------
  894|      7|            return READSTAT_ERROR_PARSE;
  895|  48.7k|        if (shp_info->offset + ctx->subheader_signature_size > page_size)
  ------------------
  |  Branch (895:13): [True: 0, False: 48.7k]
  ------------------
  896|      0|            return READSTAT_ERROR_PARSE;
  897|  48.7k|    }
  898|       |    
  899|  52.9k|    return READSTAT_OK;
  900|  52.9k|}
readstat_sas7bdat_read.c:sas7bdat_parse_subheader_type:
  837|  48.7k|static sas_subheader_type_t sas7bdat_parse_subheader_type(const char* subheader, sas7bdat_ctx_t* ctx) {
  838|  48.7k|    if (!ctx->u64) {
  ------------------
  |  Branch (838:9): [True: 39.0k, False: 9.71k]
  ------------------
  839|  39.0k|        uint32_t signature_32 = sas_read4(subheader, ctx->bswap);
  840|  39.0k|        return sas7bdat_parse_subheader_type_32(signature_32);
  841|  39.0k|    }
  842|       |
  843|  9.71k|    uint64_t signature = sas_read8(subheader, ctx->bswap);
  844|  9.71k|    if (signature == SAS_SUBHEADER_SIGNATURE_ROW_SIZE) {
  ------------------
  |  |   92|  9.71k|#define SAS_SUBHEADER_SIGNATURE_ROW_SIZE       0xF7F7F7F7
  ------------------
  |  Branch (844:9): [True: 1.82k, False: 7.88k]
  ------------------
  845|  1.82k|        return SAS_SUBHEADER_TYPE_ROW_SIZE;
  846|  7.88k|    } else if (signature == SAS_SUBHEADER_SIGNATURE_COLUMN_SIZE) {
  ------------------
  |  |   93|  7.88k|#define SAS_SUBHEADER_SIGNATURE_COLUMN_SIZE    0xF6F6F6F6
  ------------------
  |  Branch (846:16): [True: 468, False: 7.41k]
  ------------------
  847|    468|        return SAS_SUBHEADER_TYPE_COLUMN_SIZE;
  848|  7.41k|    } else if ((signature & SAS_SUBHEADER_SIGNATURE_64BIT_MASK) != SAS_SUBHEADER_SIGNATURE_64BIT_MASK) {
  ------------------
  |  |  105|  7.41k|#define SAS_SUBHEADER_SIGNATURE_64BIT_MASK     0xFFFFFFFF00000000
  ------------------
                  } else if ((signature & SAS_SUBHEADER_SIGNATURE_64BIT_MASK) != SAS_SUBHEADER_SIGNATURE_64BIT_MASK) {
  ------------------
  |  |  105|  7.41k|#define SAS_SUBHEADER_SIGNATURE_64BIT_MASK     0xFFFFFFFF00000000
  ------------------
  |  Branch (848:16): [True: 1.54k, False: 5.86k]
  ------------------
  849|  1.54k|        return SAS_SUBHEADER_TYPE_DATA;
  850|  1.54k|    }
  851|       |
  852|  5.86k|    uint32_t lower_bytes = (uint32_t)(signature & SAS_SUBHEADER_SIGNATURE_32BIT_MASK);
  ------------------
  |  |  106|  5.86k|#define SAS_SUBHEADER_SIGNATURE_32BIT_MASK     0x00000000FFFFFFFF
  ------------------
  853|  5.86k|    return sas7bdat_parse_subheader_type_32(lower_bytes);
  854|  9.71k|}
readstat_sas7bdat_read.c:sas7bdat_parse_subheader_type_32:
  811|  44.9k|static sas_subheader_type_t sas7bdat_parse_subheader_type_32(uint32_t signature) {
  812|  44.9k|    switch (signature) {
  813|  7.76k|        case SAS_SUBHEADER_SIGNATURE_ROW_SIZE:
  ------------------
  |  |   92|  7.76k|#define SAS_SUBHEADER_SIGNATURE_ROW_SIZE       0xF7F7F7F7
  ------------------
  |  Branch (813:9): [True: 7.76k, False: 37.1k]
  ------------------
  814|  7.76k|            return SAS_SUBHEADER_TYPE_ROW_SIZE;
  815|  3.96k|        case SAS_SUBHEADER_SIGNATURE_COLUMN_SIZE:
  ------------------
  |  |   93|  3.96k|#define SAS_SUBHEADER_SIGNATURE_COLUMN_SIZE    0xF6F6F6F6
  ------------------
  |  Branch (815:9): [True: 3.96k, False: 40.9k]
  ------------------
  816|  3.96k|            return SAS_SUBHEADER_TYPE_COLUMN_SIZE;
  817|  3.11k|        case SAS_SUBHEADER_SIGNATURE_COUNTS:
  ------------------
  |  |   94|  3.11k|#define SAS_SUBHEADER_SIGNATURE_COUNTS         0xFFFFFC00
  ------------------
  |  Branch (817:9): [True: 3.11k, False: 41.8k]
  ------------------
  818|  3.11k|            return SAS_SUBHEADER_TYPE_COUNTS;
  819|  8.71k|        case SAS_SUBHEADER_SIGNATURE_COLUMN_FORMAT:
  ------------------
  |  |   95|  8.71k|#define SAS_SUBHEADER_SIGNATURE_COLUMN_FORMAT  0xFFFFFBFE
  ------------------
  |  Branch (819:9): [True: 8.71k, False: 36.2k]
  ------------------
  820|  8.71k|            return SAS_SUBHEADER_TYPE_COLUMN_FORMAT;
  821|  5.57k|        case SAS_SUBHEADER_SIGNATURE_COLUMN_ATTRS:
  ------------------
  |  |  100|  5.57k|#define SAS_SUBHEADER_SIGNATURE_COLUMN_ATTRS   0xFFFFFFFC
  ------------------
  |  Branch (821:9): [True: 5.57k, False: 39.3k]
  ------------------
  822|  5.57k|            return SAS_SUBHEADER_TYPE_COLUMN_ATTRS;
  823|  4.51k|        case SAS_SUBHEADER_SIGNATURE_COLUMN_TEXT:
  ------------------
  |  |  101|  4.51k|#define SAS_SUBHEADER_SIGNATURE_COLUMN_TEXT    0xFFFFFFFD
  ------------------
  |  Branch (823:9): [True: 4.51k, False: 40.4k]
  ------------------
  824|  4.51k|            return SAS_SUBHEADER_TYPE_COLUMN_TEXT;
  825|  1.74k|        case SAS_SUBHEADER_SIGNATURE_COLUMN_LIST:
  ------------------
  |  |  102|  1.74k|#define SAS_SUBHEADER_SIGNATURE_COLUMN_LIST    0xFFFFFFFE
  ------------------
  |  Branch (825:9): [True: 1.74k, False: 43.1k]
  ------------------
  826|  1.74k|            return SAS_SUBHEADER_TYPE_COLUMN_LIST;
  827|  4.02k|        case SAS_SUBHEADER_SIGNATURE_COLUMN_NAME:
  ------------------
  |  |  103|  4.02k|#define SAS_SUBHEADER_SIGNATURE_COLUMN_NAME    0xFFFFFFFF
  ------------------
  |  Branch (827:9): [True: 4.02k, False: 40.8k]
  ------------------
  828|  4.02k|            return SAS_SUBHEADER_TYPE_COLUMN_NAME;
  829|  5.50k|        default:
  ------------------
  |  Branch (829:9): [True: 5.50k, False: 39.4k]
  ------------------
  830|  5.50k|            if ((signature & SAS_SUBHEADER_SIGNATURE_COLUMN_MASK) == SAS_SUBHEADER_SIGNATURE_COLUMN_MASK) {
  ------------------
  |  |   97|  5.50k|#define SAS_SUBHEADER_SIGNATURE_COLUMN_MASK    0xFFFFFFF8
  ------------------
                          if ((signature & SAS_SUBHEADER_SIGNATURE_COLUMN_MASK) == SAS_SUBHEADER_SIGNATURE_COLUMN_MASK) {
  ------------------
  |  |   97|  5.50k|#define SAS_SUBHEADER_SIGNATURE_COLUMN_MASK    0xFFFFFFF8
  ------------------
  |  Branch (830:17): [True: 1.86k, False: 3.64k]
  ------------------
  831|  1.86k|                return SAS_SUBHEADER_TYPE_UNKNOWN;
  832|  1.86k|            }
  833|  3.64k|            return SAS_SUBHEADER_TYPE_DATA;
  834|  44.9k|    }
  835|  44.9k|}
readstat_sas7bdat_read.c:sas7bdat_parse_subheader:
  633|  18.3k|        size_t len, sas7bdat_ctx_t *ctx) {
  634|  18.3k|    readstat_error_t retval = READSTAT_OK;
  635|       |
  636|  18.3k|    if (len < 2 + ctx->subheader_signature_size) {
  ------------------
  |  Branch (636:9): [True: 7, False: 18.3k]
  ------------------
  637|      7|        retval = READSTAT_ERROR_PARSE;
  638|      7|        goto cleanup;
  639|      7|    }
  640|  18.3k|    if (subheader_type == SAS_SUBHEADER_TYPE_ROW_SIZE) {
  ------------------
  |  Branch (640:9): [True: 3.75k, False: 14.5k]
  ------------------
  641|  3.75k|        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.65k, False: 12.9k]
  ------------------
  643|  1.65k|        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.19k, False: 11.7k]
  ------------------
  645|       |        /* void */
  646|  11.7k|    } else if (subheader_type == SAS_SUBHEADER_TYPE_COLUMN_TEXT) {
  ------------------
  |  Branch (646:16): [True: 2.90k, False: 8.82k]
  ------------------
  647|  2.90k|        retval = sas7bdat_parse_column_text_subheader(subheader, len, ctx);
  648|  8.82k|    } else if (subheader_type == SAS_SUBHEADER_TYPE_COLUMN_NAME) {
  ------------------
  |  Branch (648:16): [True: 1.46k, False: 7.36k]
  ------------------
  649|  1.46k|        retval = sas7bdat_parse_column_name_subheader(subheader, len, ctx);
  650|  7.36k|    } else if (subheader_type == SAS_SUBHEADER_TYPE_COLUMN_ATTRS) {
  ------------------
  |  Branch (650:16): [True: 2.19k, False: 5.17k]
  ------------------
  651|  2.19k|        retval = sas7bdat_parse_column_attributes_subheader(subheader, len, ctx);
  652|  5.17k|    } else if (subheader_type == SAS_SUBHEADER_TYPE_COLUMN_FORMAT) {
  ------------------
  |  Branch (652:16): [True: 3.71k, False: 1.45k]
  ------------------
  653|  3.71k|        retval = sas7bdat_parse_column_format_subheader(subheader, len, ctx);
  654|  3.71k|    } else if (subheader_type == SAS_SUBHEADER_TYPE_COLUMN_LIST) {
  ------------------
  |  Branch (654:16): [True: 692, False: 767]
  ------------------
  655|       |        /* void */
  656|    767|    } else if (subheader_type == SAS_SUBHEADER_TYPE_UNKNOWN) {
  ------------------
  |  Branch (656:16): [True: 729, False: 38]
  ------------------
  657|       |        /* void */
  658|    729|    } else {
  659|     38|        retval = READSTAT_ERROR_PARSE;
  660|     38|    }
  661|       |
  662|  18.3k|cleanup:
  663|       |
  664|  18.3k|    return retval;
  665|  18.3k|}
readstat_sas7bdat_read.c:sas7bdat_parse_row_size_subheader:
  232|  3.75k|static readstat_error_t sas7bdat_parse_row_size_subheader(const char *subheader, size_t len, sas7bdat_ctx_t *ctx) {
  233|  3.75k|    readstat_error_t retval = READSTAT_OK;
  234|  3.75k|    uint64_t total_row_count;
  235|  3.75k|    uint64_t row_length, page_row_count;
  236|       |
  237|  3.75k|    if (len < (ctx->u64 ? 250: 190)) {
  ------------------
  |  Branch (237:9): [True: 10, False: 3.74k]
  |  Branch (237:16): [True: 975, False: 2.77k]
  ------------------
  238|     10|        retval = READSTAT_ERROR_PARSE;
  239|     10|        goto cleanup;
  240|     10|    }
  241|       |
  242|  3.74k|    if (ctx->u64) {
  ------------------
  |  Branch (242:9): [True: 975, False: 2.76k]
  ------------------
  243|    975|        row_length = sas_read8(&subheader[40], ctx->bswap);
  244|    975|        total_row_count = sas_read8(&subheader[48], ctx->bswap);
  245|    975|        page_row_count = sas_read8(&subheader[120], ctx->bswap);
  246|  2.76k|    } else {
  247|  2.76k|        row_length = sas_read4(&subheader[20], ctx->bswap);
  248|  2.76k|        total_row_count = sas_read4(&subheader[24], ctx->bswap);
  249|  2.76k|        page_row_count = sas_read4(&subheader[60], ctx->bswap);
  250|  2.76k|    }
  251|       |
  252|  3.74k|    sas_text_ref_t file_label_ref = sas7bdat_parse_text_ref(&subheader[len-130], ctx);
  253|  3.74k|    if (file_label_ref.length) {
  ------------------
  |  Branch (253:9): [True: 695, False: 3.04k]
  ------------------
  254|    695|        if ((retval = sas7bdat_copy_text_ref(ctx->file_label, sizeof(ctx->file_label),
  ------------------
  |  Branch (254:13): [True: 52, False: 643]
  ------------------
  255|    695|                        file_label_ref, ctx)) != READSTAT_OK) {
  256|     52|            goto cleanup;
  257|     52|        }
  258|    695|    }
  259|       |
  260|  3.69k|    sas_text_ref_t compression_ref = sas7bdat_parse_text_ref(&subheader[len-118], ctx);
  261|  3.69k|    if (compression_ref.length) {
  ------------------
  |  Branch (261:9): [True: 1.26k, False: 2.42k]
  ------------------
  262|  1.26k|        char compression[9];
  263|  1.26k|        if ((retval = sas7bdat_copy_text_ref(compression, sizeof(compression),
  ------------------
  |  Branch (263:13): [True: 44, False: 1.21k]
  ------------------
  264|  1.26k|                        compression_ref, ctx)) != READSTAT_OK) {
  265|     44|            goto cleanup;
  266|     44|        }
  267|  1.21k|        ctx->rdc_compression = (memcmp(compression, SAS_COMPRESSION_SIGNATURE_RDC, 8) == 0);
  ------------------
  |  |  128|  1.21k|#define SAS_COMPRESSION_SIGNATURE_RDC  "SASYZCR2"
  ------------------
  268|  1.21k|    }
  269|       |
  270|  3.64k|    ctx->row_length = row_length;
  271|  3.64k|    ctx->row = readstat_realloc(ctx->row, ctx->row_length);
  272|  3.64k|    if (ctx->row == NULL) {
  ------------------
  |  Branch (272:9): [True: 9, False: 3.63k]
  ------------------
  273|      9|        retval = READSTAT_ERROR_MALLOC;
  274|      9|        goto cleanup;
  275|      9|    }
  276|       |
  277|  3.63k|    ctx->page_row_count = page_row_count;
  278|  3.63k|    uint64_t total_row_count_after_skipping = total_row_count;
  279|  3.63k|    if (total_row_count > ctx->row_offset) {
  ------------------
  |  Branch (279:9): [True: 3.26k, False: 370]
  ------------------
  280|  3.26k|        total_row_count_after_skipping -= ctx->row_offset;
  281|  3.26k|    } else {
  282|    370|        total_row_count_after_skipping = 0;
  283|    370|        ctx->row_offset = total_row_count;
  284|    370|    }
  285|  3.63k|    if (ctx->row_limit == 0 || total_row_count_after_skipping < ctx->row_limit)
  ------------------
  |  Branch (285:9): [True: 1.42k, False: 2.21k]
  |  Branch (285:32): [True: 191, False: 2.02k]
  ------------------
  286|  1.61k|        ctx->row_limit = total_row_count_after_skipping;
  287|       |
  288|  3.75k|cleanup:
  289|  3.75k|    return retval;
  290|  3.63k|}
readstat_sas7bdat_read.c:sas7bdat_parse_text_ref:
  133|  58.6k|static sas_text_ref_t sas7bdat_parse_text_ref(const char *data, sas7bdat_ctx_t *ctx) {
  134|  58.6k|    sas_text_ref_t  ref;
  135|       |
  136|  58.6k|    ref.index = sas_read2(&data[0], ctx->bswap);
  137|  58.6k|    ref.offset = sas_read2(&data[2], ctx->bswap);
  138|  58.6k|    ref.length = sas_read2(&data[4], ctx->bswap);
  139|       |
  140|  58.6k|    return ref;
  141|  58.6k|}
readstat_sas7bdat_read.c:sas7bdat_copy_text_ref:
  143|  11.3M|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.3M|    if (text_ref.index >= ctx->text_blob_count)
  ------------------
  |  Branch (144:9): [True: 149, False: 11.3M]
  ------------------
  145|    149|        return READSTAT_ERROR_PARSE;
  146|       |    
  147|  11.3M|    if (text_ref.length == 0) {
  ------------------
  |  Branch (147:9): [True: 11.3M, False: 3.74k]
  ------------------
  148|  11.3M|        out_buffer[0] = '\0';
  149|  11.3M|        return READSTAT_OK;
  150|  11.3M|    }
  151|       |
  152|  3.74k|    char *blob = ctx->text_blobs[text_ref.index];
  153|       |
  154|  3.74k|    if (text_ref.offset + text_ref.length > ctx->text_blob_lengths[text_ref.index])
  ------------------
  |  Branch (154:9): [True: 87, False: 3.66k]
  ------------------
  155|     87|        return READSTAT_ERROR_PARSE;
  156|       |
  157|  3.66k|    return readstat_convert(out_buffer, out_buffer_len, &blob[text_ref.offset], text_ref.length,
  158|  3.66k|            ctx->converter);
  159|  3.74k|}
readstat_sas7bdat_read.c:sas7bdat_parse_column_size_subheader:
  204|  1.65k|static readstat_error_t sas7bdat_parse_column_size_subheader(const char *subheader, size_t len, sas7bdat_ctx_t *ctx) {
  205|  1.65k|    uint64_t col_count;
  206|  1.65k|    readstat_error_t retval = READSTAT_OK;
  207|       |
  208|  1.65k|    if (ctx->column_count || ctx->did_submit_columns) {
  ------------------
  |  Branch (208:9): [True: 21, False: 1.63k]
  |  Branch (208:30): [True: 4, False: 1.63k]
  ------------------
  209|     25|        retval = READSTAT_ERROR_PARSE;
  210|     25|        goto cleanup;
  211|     25|    }
  212|       |
  213|  1.63k|    if (len < (ctx->u64 ? 16 : 8)) {
  ------------------
  |  Branch (213:9): [True: 3, False: 1.62k]
  |  Branch (213:16): [True: 441, False: 1.19k]
  ------------------
  214|      3|        retval = READSTAT_ERROR_PARSE;
  215|      3|        goto cleanup;
  216|      3|    }
  217|       |
  218|  1.62k|    if (ctx->u64) {
  ------------------
  |  Branch (218:9): [True: 441, False: 1.18k]
  ------------------
  219|    441|        col_count = sas_read8(&subheader[8], ctx->bswap);
  220|  1.18k|    } else {
  221|  1.18k|        col_count = sas_read4(&subheader[4], ctx->bswap);
  222|  1.18k|    }
  223|       |
  224|  1.62k|    ctx->column_count = col_count;
  225|       |
  226|  1.62k|    retval = sas7bdat_realloc_col_info(ctx, ctx->column_count);
  227|       |
  228|  1.65k|cleanup:
  229|  1.65k|    return retval;
  230|  1.62k|}
readstat_sas7bdat_read.c:sas7bdat_realloc_col_info:
  191|  8.87k|static readstat_error_t sas7bdat_realloc_col_info(sas7bdat_ctx_t *ctx, size_t count) {
  192|  8.87k|    if (ctx->col_info_count < count) {
  ------------------
  |  Branch (192:9): [True: 3.57k, False: 5.30k]
  ------------------
  193|  3.57k|        size_t old_count = ctx->col_info_count;
  194|  3.57k|        ctx->col_info_count = count;
  195|  3.57k|        ctx->col_info = readstat_realloc(ctx->col_info, ctx->col_info_count * sizeof(col_info_t));
  196|  3.57k|        if (ctx->col_info == NULL) {
  ------------------
  |  Branch (196:13): [True: 85, False: 3.48k]
  ------------------
  197|     85|            return READSTAT_ERROR_MALLOC;
  198|     85|        }
  199|  3.48k|        memset(ctx->col_info + old_count, 0, (count - old_count) * sizeof(col_info_t));
  200|  3.48k|    }
  201|  8.79k|    return READSTAT_OK;
  202|  8.87k|}
readstat_sas7bdat_read.c:sas7bdat_parse_column_text_subheader:
  161|  2.90k|static readstat_error_t sas7bdat_parse_column_text_subheader(const char *subheader, size_t len, sas7bdat_ctx_t *ctx) {
  162|  2.90k|    readstat_error_t retval = READSTAT_OK;
  163|  2.90k|    size_t signature_len = ctx->subheader_signature_size;
  164|  2.90k|    uint16_t remainder = sas_read2(&subheader[signature_len], ctx->bswap);
  165|  2.90k|    char *blob = NULL;
  166|  2.90k|    if (remainder != sas_subheader_remainder(len, signature_len)) {
  ------------------
  |  Branch (166:9): [True: 58, False: 2.84k]
  ------------------
  167|     58|        retval = READSTAT_ERROR_PARSE;
  168|     58|        goto cleanup;
  169|     58|    }
  170|  2.84k|    ctx->text_blob_count++;
  171|  2.84k|    ctx->text_blobs = readstat_realloc(ctx->text_blobs, ctx->text_blob_count * sizeof(char *));
  172|  2.84k|    ctx->text_blob_lengths = readstat_realloc(ctx->text_blob_lengths,
  173|  2.84k|            ctx->text_blob_count * sizeof(ctx->text_blob_lengths[0]));
  174|  2.84k|    if (ctx->text_blobs == NULL || ctx->text_blob_lengths == NULL) {
  ------------------
  |  Branch (174:9): [True: 0, False: 2.84k]
  |  Branch (174:36): [True: 0, False: 2.84k]
  ------------------
  175|      0|        retval = READSTAT_ERROR_MALLOC;
  176|      0|        goto cleanup;
  177|      0|    }
  178|       |
  179|  2.84k|    if ((blob = readstat_malloc(len-signature_len)) == NULL) {
  ------------------
  |  Branch (179:9): [True: 0, False: 2.84k]
  ------------------
  180|      0|        retval = READSTAT_ERROR_MALLOC;
  181|      0|        goto cleanup;
  182|      0|    }
  183|  2.84k|    memcpy(blob, subheader+signature_len, len-signature_len);
  184|  2.84k|    ctx->text_blob_lengths[ctx->text_blob_count-1] = len-signature_len;
  185|  2.84k|    ctx->text_blobs[ctx->text_blob_count-1] = blob;
  186|       |
  187|  2.90k|cleanup:
  188|  2.90k|    return retval;
  189|  2.84k|}
readstat_sas7bdat_read.c:sas7bdat_parse_column_name_subheader:
  292|  1.46k|static readstat_error_t sas7bdat_parse_column_name_subheader(const char *subheader, size_t len, sas7bdat_ctx_t *ctx) {
  293|  1.46k|    readstat_error_t retval = READSTAT_OK;
  294|  1.46k|    size_t signature_len = ctx->subheader_signature_size;
  295|  1.46k|    int cmax = ctx->u64 ? (len-28)/8 : (len-20)/8;
  ------------------
  |  Branch (295:16): [True: 337, False: 1.12k]
  ------------------
  296|  1.46k|    int i;
  297|  1.46k|    const char *cnp = &subheader[signature_len+8];
  298|  1.46k|    uint16_t remainder = sas_read2(&subheader[signature_len], ctx->bswap);
  299|       |
  300|  1.46k|    if (remainder != sas_subheader_remainder(len, signature_len)) {
  ------------------
  |  Branch (300:9): [True: 69, False: 1.39k]
  ------------------
  301|     69|        retval = READSTAT_ERROR_PARSE;
  302|     69|        goto cleanup;
  303|     69|    }
  304|       |
  305|  1.39k|    ctx->col_names_count += cmax;
  306|       |
  307|  1.39k|    if ((retval = sas7bdat_realloc_col_info(ctx, ctx->col_names_count)) != READSTAT_OK)
  ------------------
  |  Branch (307:9): [True: 17, False: 1.37k]
  ------------------
  308|     17|        goto cleanup;
  309|       |
  310|  45.1k|    for (i=ctx->col_names_count-cmax; i<ctx->col_names_count; i++) {
  ------------------
  |  Branch (310:39): [True: 43.7k, False: 1.37k]
  ------------------
  311|  43.7k|        ctx->col_info[i].name_ref = sas7bdat_parse_text_ref(cnp, ctx);
  312|  43.7k|        cnp += 8;
  313|  43.7k|    }
  314|       |
  315|  1.46k|cleanup:
  316|       |
  317|  1.46k|    return retval;
  318|  1.37k|}
readstat_sas7bdat_read.c:sas7bdat_parse_column_attributes_subheader:
  320|  2.19k|static readstat_error_t sas7bdat_parse_column_attributes_subheader(const char *subheader, size_t len, sas7bdat_ctx_t *ctx) {
  321|  2.19k|    readstat_error_t retval = READSTAT_OK;
  322|  2.19k|    size_t signature_len = ctx->subheader_signature_size;
  323|  2.19k|    int cmax = ctx->u64 ? (len-28)/16 : (len-20)/12;
  ------------------
  |  Branch (323:16): [True: 292, False: 1.90k]
  ------------------
  324|  2.19k|    int i;
  325|  2.19k|    const char *cap = &subheader[signature_len+8];
  326|  2.19k|    uint16_t remainder = sas_read2(&subheader[signature_len], ctx->bswap);
  327|       |
  328|  2.19k|    if (remainder != sas_subheader_remainder(len, signature_len)) {
  ------------------
  |  Branch (328:9): [True: 51, False: 2.14k]
  ------------------
  329|     51|        retval = READSTAT_ERROR_PARSE;
  330|     51|        goto cleanup;
  331|     51|    }
  332|  2.14k|    ctx->col_attrs_count += cmax;
  333|  2.14k|    if ((retval = sas7bdat_realloc_col_info(ctx, ctx->col_attrs_count)) != READSTAT_OK)
  ------------------
  |  Branch (333:9): [True: 10, False: 2.13k]
  ------------------
  334|     10|        goto cleanup;
  335|       |
  336|  10.4k|    for (i=ctx->col_attrs_count-cmax; i<ctx->col_attrs_count; i++) {
  ------------------
  |  Branch (336:39): [True: 8.34k, False: 2.11k]
  ------------------
  337|  8.34k|        if (ctx->u64) {
  ------------------
  |  Branch (337:13): [True: 732, False: 7.61k]
  ------------------
  338|    732|            ctx->col_info[i].offset = sas_read8(&cap[0], ctx->bswap);
  339|  7.61k|        } else {
  340|  7.61k|            ctx->col_info[i].offset = sas_read4(&cap[0], ctx->bswap);
  341|  7.61k|        }
  342|       |
  343|  8.34k|        readstat_off_t off=4;
  344|  8.34k|        if (ctx->u64)
  ------------------
  |  Branch (344:13): [True: 732, False: 7.61k]
  ------------------
  345|    732|            off=8;
  346|       |
  347|  8.34k|        ctx->col_info[i].width = sas_read4(&cap[off], ctx->bswap);
  348|  8.34k|        if (ctx->col_info[i].width > ctx->max_col_width)
  ------------------
  |  Branch (348:13): [True: 874, False: 7.47k]
  ------------------
  349|    874|            ctx->max_col_width = ctx->col_info[i].width;
  350|       |
  351|  8.34k|        if (cap[off+6] == SAS_COLUMN_TYPE_NUM) {
  ------------------
  |  |   89|  8.34k|#define SAS_COLUMN_TYPE_NUM  0x01
  ------------------
  |  Branch (351:13): [True: 4.93k, False: 3.40k]
  ------------------
  352|  4.93k|            ctx->col_info[i].type = READSTAT_TYPE_DOUBLE;
  353|  4.93k|        } else if (cap[off+6] == SAS_COLUMN_TYPE_CHR) {
  ------------------
  |  |   90|  3.40k|#define SAS_COLUMN_TYPE_CHR  0x02
  ------------------
  |  Branch (353:20): [True: 3.39k, False: 16]
  ------------------
  354|  3.39k|            ctx->col_info[i].type = READSTAT_TYPE_STRING;
  355|  3.39k|        } else {
  356|     16|            retval = READSTAT_ERROR_PARSE;
  357|     16|            goto cleanup;
  358|     16|        }
  359|  8.32k|        ctx->col_info[i].index = i;
  360|  8.32k|        cap += off+8;
  361|  8.32k|    }
  362|       |
  363|  2.19k|cleanup:
  364|       |
  365|  2.19k|    return retval;
  366|  2.13k|}
readstat_sas7bdat_read.c:sas7bdat_parse_column_format_subheader:
  368|  3.71k|static readstat_error_t sas7bdat_parse_column_format_subheader(const char *subheader, size_t len, sas7bdat_ctx_t *ctx) {
  369|  3.71k|    readstat_error_t retval = READSTAT_OK;
  370|       |
  371|  3.71k|    if (len < (ctx->u64 ? 58 : 46)) {
  ------------------
  |  Branch (371:9): [True: 3, False: 3.70k]
  |  Branch (371:16): [True: 355, False: 3.35k]
  ------------------
  372|      3|        retval = READSTAT_ERROR_PARSE;
  373|      3|        goto cleanup;
  374|      3|    }
  375|       |
  376|  3.70k|    ctx->col_formats_count++;
  377|  3.70k|    if ((retval = sas7bdat_realloc_col_info(ctx, ctx->col_formats_count)) != READSTAT_OK)
  ------------------
  |  Branch (377:9): [True: 0, False: 3.70k]
  ------------------
  378|      0|        goto cleanup;
  379|       |
  380|  3.70k|    if (ctx->u64) {
  ------------------
  |  Branch (380:9): [True: 354, False: 3.35k]
  ------------------
  381|    354|        ctx->col_info[ctx->col_formats_count-1].format_width = sas_read2(&subheader[24], ctx->bswap);
  382|    354|        ctx->col_info[ctx->col_formats_count-1].format_digits = sas_read2(&subheader[26], ctx->bswap);
  383|  3.35k|    } else {
  384|  3.35k|        ctx->col_info[ctx->col_formats_count-1].format_width = sas_read2(&subheader[12], ctx->bswap);
  385|  3.35k|        ctx->col_info[ctx->col_formats_count-1].format_digits = sas_read2(&subheader[14], ctx->bswap);
  386|  3.35k|    }
  387|  3.70k|    ctx->col_info[ctx->col_formats_count-1].format_ref = sas7bdat_parse_text_ref(
  388|  3.70k|            ctx->u64 ? &subheader[46] : &subheader[34], ctx);
  ------------------
  |  Branch (388:13): [True: 354, False: 3.35k]
  ------------------
  389|  3.70k|    ctx->col_info[ctx->col_formats_count-1].label_ref = sas7bdat_parse_text_ref(
  390|  3.70k|            ctx->u64 ? &subheader[52] : &subheader[40], ctx);
  ------------------
  |  Branch (390:13): [True: 354, False: 3.35k]
  ------------------
  391|       |
  392|  3.71k|cleanup:
  393|  3.71k|    return retval;
  394|  3.70k|}
readstat_sas7bdat_read.c:sas7bdat_parse_amd_pages_pass1:
 1108|  2.85k|static readstat_error_t sas7bdat_parse_amd_pages_pass1(int64_t last_examined_page_pass1, sas7bdat_ctx_t *ctx) {
 1109|  2.85k|    readstat_error_t retval = READSTAT_OK;
 1110|  2.85k|    readstat_io_t *io = ctx->io;
 1111|  2.85k|    uint64_t i;
 1112|  2.85k|    uint64_t amd_page_count = 0;
 1113|       |
 1114|       |    /* ...then AMD pages at the end */
 1115|  6.65k|    for (i=ctx->page_count-1; i>last_examined_page_pass1; i--) {
  ------------------
  |  Branch (1115:31): [True: 5.13k, False: 1.52k]
  ------------------
 1116|  5.13k|        if (io->seek(ctx->header_size + i*ctx->page_size, READSTAT_SEEK_SET, io->io_ctx) == -1) {
  ------------------
  |  Branch (1116:13): [True: 212, False: 4.91k]
  ------------------
 1117|    212|            retval = READSTAT_ERROR_SEEK;
 1118|    212|            if (ctx->handle.error) {
  ------------------
  |  Branch (1118:17): [True: 0, False: 212]
  ------------------
 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|    212|            goto cleanup;
 1125|    212|        }
 1126|       |
 1127|  4.91k|        readstat_off_t off = 0;
 1128|  4.91k|        if (ctx->u64)
  ------------------
  |  Branch (1128:13): [True: 3.98k, False: 938]
  ------------------
 1129|  3.98k|            off = 16;
 1130|       |
 1131|  4.91k|        size_t head_len = off + 16 + 2;
 1132|  4.91k|        size_t tail_len = ctx->page_size - head_len;
 1133|       |
 1134|  4.91k|        if (io->read(ctx->page, head_len, io->io_ctx) < head_len) {
  ------------------
  |  Branch (1134:13): [True: 7, False: 4.91k]
  ------------------
 1135|      7|            retval = READSTAT_ERROR_READ;
 1136|      7|            goto cleanup;
 1137|      7|        }
 1138|       |
 1139|  4.91k|        uint16_t page_type = sas_read2(&ctx->page[off+16], ctx->bswap);
 1140|       |
 1141|  4.91k|        if ((page_type & SAS_PAGE_TYPE_MASK) == SAS_PAGE_TYPE_DATA) {
  ------------------
  |  |  112|  4.91k|#define SAS_PAGE_TYPE_MASK   0x0F00
  ------------------
                      if ((page_type & SAS_PAGE_TYPE_MASK) == SAS_PAGE_TYPE_DATA) {
  ------------------
  |  |  109|  4.91k|#define SAS_PAGE_TYPE_DATA   0x0100
  ------------------
  |  Branch (1141:13): [True: 1.17k, False: 3.73k]
  ------------------
 1142|       |            /* Usually AMD pages are at the end but sometimes data pages appear after them */
 1143|  1.17k|            if (amd_page_count > 0)
  ------------------
  |  Branch (1143:17): [True: 373, False: 803]
  ------------------
 1144|    373|                break;
 1145|    803|            continue;
 1146|  1.17k|        }
 1147|  3.73k|        if ((page_type & SAS_PAGE_TYPE_COMP))
  ------------------
  |  |  115|  3.73k|#define SAS_PAGE_TYPE_COMP   0x9000
  ------------------
  |  Branch (1147:13): [True: 883, False: 2.85k]
  ------------------
 1148|    883|            continue;
 1149|       |
 1150|  2.85k|        if (io->read(ctx->page + head_len, tail_len, io->io_ctx) < tail_len) {
  ------------------
  |  Branch (1150:13): [True: 17, False: 2.83k]
  ------------------
 1151|     17|            retval = READSTAT_ERROR_READ;
 1152|     17|            goto cleanup;
 1153|     17|        }
 1154|       |
 1155|  2.83k|        if ((retval = sas7bdat_parse_page_pass1(ctx->page, ctx->page_size, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1155:13): [True: 725, False: 2.11k]
  ------------------
 1156|    725|            if (ctx->handle.error && retval != READSTAT_ERROR_USER_ABORT) {
  ------------------
  |  Branch (1156:17): [True: 0, False: 725]
  |  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|    725|            goto cleanup;
 1164|    725|        }
 1165|       |
 1166|  2.11k|        amd_page_count++;
 1167|  2.11k|    }
 1168|       |
 1169|  2.85k|cleanup:
 1170|       |
 1171|  2.85k|    return retval;
 1172|  2.85k|}
readstat_sas7bdat_read.c:sas7bdat_parse_all_pages_pass2:
 1174|  1.89k|static readstat_error_t sas7bdat_parse_all_pages_pass2(sas7bdat_ctx_t *ctx) {
 1175|  1.89k|    readstat_error_t retval = READSTAT_OK;
 1176|  1.89k|    readstat_io_t *io = ctx->io;
 1177|  1.89k|    int64_t i;
 1178|       |
 1179|  4.22k|    for (i=0; i<ctx->page_count; i++) {
  ------------------
  |  Branch (1179:15): [True: 4.11k, False: 112]
  ------------------
 1180|  4.11k|        if ((retval = sas7bdat_update_progress(ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1180:13): [True: 0, False: 4.11k]
  ------------------
 1181|      0|            goto cleanup;
 1182|      0|        }
 1183|  4.11k|        if (io->read(ctx->page, ctx->page_size, io->io_ctx) < ctx->page_size) {
  ------------------
  |  Branch (1183:13): [True: 109, False: 4.00k]
  ------------------
 1184|    109|            retval = READSTAT_ERROR_READ;
 1185|    109|            goto cleanup;
 1186|    109|        }
 1187|       |
 1188|  4.00k|        if ((retval = sas7bdat_parse_page_pass2(ctx->page, ctx->page_size, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1188:13): [True: 1.43k, False: 2.56k]
  ------------------
 1189|  1.43k|            if (ctx->handle.error && retval != READSTAT_ERROR_USER_ABORT) {
  ------------------
  |  Branch (1189:17): [True: 0, False: 1.43k]
  |  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.43k|            goto cleanup;
 1197|  1.43k|        }
 1198|  2.56k|        if (ctx->parsed_row_count == ctx->row_limit)
  ------------------
  |  Branch (1198:13): [True: 237, False: 2.32k]
  ------------------
 1199|    237|            break;
 1200|  2.56k|    }
 1201|  1.89k|cleanup:
 1202|       |
 1203|  1.89k|    return retval;
 1204|  1.89k|}
readstat_sas7bdat_read.c:sas7bdat_parse_page_pass2:
  950|  4.00k|static readstat_error_t sas7bdat_parse_page_pass2(const char *page, size_t page_size, sas7bdat_ctx_t *ctx) {
  951|  4.00k|    uint16_t page_type;
  952|       |
  953|  4.00k|    readstat_error_t retval = READSTAT_OK;
  954|       |
  955|  4.00k|    page_type = sas_read2(&page[ctx->page_header_size-8], ctx->bswap);
  956|       |
  957|  4.00k|    const char *data = NULL;
  958|       |
  959|  4.00k|    if ((page_type & SAS_PAGE_TYPE_MASK) == SAS_PAGE_TYPE_DATA) {
  ------------------
  |  |  112|  4.00k|#define SAS_PAGE_TYPE_MASK   0x0F00
  ------------------
                  if ((page_type & SAS_PAGE_TYPE_MASK) == SAS_PAGE_TYPE_DATA) {
  ------------------
  |  |  109|  4.00k|#define SAS_PAGE_TYPE_DATA   0x0100
  ------------------
  |  Branch (959:9): [True: 632, False: 3.37k]
  ------------------
  960|    632|        ctx->page_row_count = sas_read2(&page[ctx->page_header_size-6], ctx->bswap);
  961|    632|        data = &page[ctx->page_header_size];
  962|  3.37k|    } else if (!(page_type & SAS_PAGE_TYPE_COMP)) {
  ------------------
  |  |  115|  3.37k|#define SAS_PAGE_TYPE_COMP   0x9000
  ------------------
  |  Branch (962:16): [True: 3.04k, False: 322]
  ------------------
  963|  3.04k|        uint16_t subheader_count = sas_read2(&page[ctx->page_header_size-4], ctx->bswap);
  964|       |
  965|  3.04k|        int i;
  966|  3.04k|        const char *shp = &page[ctx->page_header_size];
  967|  3.04k|        int lshp = ctx->subheader_pointer_size;
  968|       |
  969|  3.04k|        if (ctx->page_header_size + subheader_count*lshp > page_size) {
  ------------------
  |  Branch (969:13): [True: 15, False: 3.03k]
  ------------------
  970|     15|            retval = READSTAT_ERROR_PARSE;
  971|     15|            goto cleanup;
  972|     15|        }
  973|       |
  974|  39.2k|        for (i=0; i<subheader_count; i++) {
  ------------------
  |  Branch (974:19): [True: 37.3k, False: 1.93k]
  ------------------
  975|  37.3k|            subheader_pointer_t shp_info = { 0 };
  976|  37.3k|            if ((retval = sas7bdat_parse_subheader_pointer(shp, page + page_size - shp, &shp_info, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (976:17): [True: 0, False: 37.3k]
  ------------------
  977|      0|                goto cleanup;
  978|      0|            }
  979|  37.3k|            if (shp_info.len > 0 && shp_info.compression != SAS_COMPRESSION_TRUNC) {
  ------------------
  |  |  124|  23.0k|#define SAS_COMPRESSION_TRUNC  0x01
  ------------------
  |  Branch (979:17): [True: 23.0k, False: 14.3k]
  |  Branch (979:37): [True: 19.3k, False: 3.71k]
  ------------------
  980|  19.3k|                if ((retval = sas7bdat_validate_subheader_pointer(&shp_info, page_size, subheader_count, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (980:21): [True: 212, False: 19.1k]
  ------------------
  981|    212|                    goto cleanup;
  982|    212|                }
  983|  19.1k|                if (shp_info.compression == SAS_COMPRESSION_NONE) {
  ------------------
  |  |  123|  19.1k|#define SAS_COMPRESSION_NONE   0x00
  ------------------
  |  Branch (983:21): [True: 17.7k, False: 1.34k]
  ------------------
  984|  17.7k|                    sas_subheader_type_t subheader_type = sas7bdat_parse_subheader_type(page + shp_info.offset, ctx);
  985|  17.7k|                    if (shp_info.is_compressed_data && subheader_type == SAS_SUBHEADER_TYPE_DATA) {
  ------------------
  |  Branch (985:25): [True: 13.2k, False: 4.50k]
  |  Branch (985:56): [True: 715, False: 12.5k]
  ------------------
  986|    715|                        if (shp_info.len != ctx->row_length) {
  ------------------
  |  Branch (986:29): [True: 142, False: 573]
  ------------------
  987|    142|                            retval = READSTAT_ERROR_ROW_WIDTH_MISMATCH;
  988|    142|                            goto cleanup;
  989|    142|                        }
  990|    573|                        if ((retval = sas7bdat_submit_columns_if_needed(ctx, 1)) != READSTAT_OK) {
  ------------------
  |  Branch (990:29): [True: 14, False: 559]
  ------------------
  991|     14|                            goto cleanup;
  992|     14|                        }
  993|    559|                        if ((retval = sas7bdat_parse_single_row(page + shp_info.offset, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (993:29): [True: 10, False: 549]
  ------------------
  994|     10|                            goto cleanup;
  995|     10|                        }
  996|  17.0k|                    } else {
  997|  17.0k|                        if (subheader_type != SAS_SUBHEADER_TYPE_COLUMN_TEXT) {
  ------------------
  |  Branch (997:29): [True: 15.4k, False: 1.61k]
  ------------------
  998|  15.4k|                            if ((retval = sas7bdat_parse_subheader(subheader_type, page + shp_info.offset, shp_info.len, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (998:33): [True: 411, False: 15.0k]
  ------------------
  999|    411|                                goto cleanup;
 1000|    411|                            }
 1001|  15.4k|                        }
 1002|  17.0k|                    }
 1003|  17.7k|                } else if (shp_info.compression == SAS_COMPRESSION_ROW) {
  ------------------
  |  |  125|  1.34k|#define SAS_COMPRESSION_ROW    0x04
  ------------------
  |  Branch (1003:28): [True: 1.33k, False: 10]
  ------------------
 1004|  1.33k|                    if ((retval = sas7bdat_submit_columns_if_needed(ctx, 1)) != READSTAT_OK) {
  ------------------
  |  Branch (1004:25): [True: 43, False: 1.29k]
  ------------------
 1005|     43|                        goto cleanup;
 1006|     43|                    }
 1007|  1.29k|                    if ((retval = sas7bdat_parse_subheader_compressed(page + shp_info.offset, shp_info.len, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (1007:25): [True: 255, False: 1.04k]
  ------------------
 1008|    255|                        goto cleanup;
 1009|    255|                    }
 1010|  1.29k|                } else {
 1011|     10|                    retval = READSTAT_ERROR_UNSUPPORTED_COMPRESSION;
 1012|     10|                    goto cleanup;
 1013|     10|                }
 1014|  19.1k|            }
 1015|       |
 1016|  36.2k|            shp += lshp;
 1017|  36.2k|        }
 1018|       |
 1019|  1.93k|        if ((page_type & SAS_PAGE_TYPE_MASK) == SAS_PAGE_TYPE_MIX) {
  ------------------
  |  |  112|  1.93k|#define SAS_PAGE_TYPE_MASK   0x0F00
  ------------------
                      if ((page_type & SAS_PAGE_TYPE_MASK) == SAS_PAGE_TYPE_MIX) {
  ------------------
  |  |  110|  1.93k|#define SAS_PAGE_TYPE_MIX    0x0200
  ------------------
  |  Branch (1019:13): [True: 1.08k, False: 853]
  ------------------
 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.08k|            if ((shp-page)%8 == 4 && shp + 4 <= page + page_size &&
  ------------------
  |  Branch (1024:17): [True: 306, False: 777]
  |  Branch (1024:38): [True: 303, False: 3]
  ------------------
 1025|    303|                    (*(uint32_t *)shp == 0x00000000 ||
  ------------------
  |  Branch (1025:22): [True: 51, False: 252]
  ------------------
 1026|    252|                     *(uint32_t *)shp == 0x20202020 ||
  ------------------
  |  Branch (1026:22): [True: 30, False: 222]
  ------------------
 1027|    269|                     ctx->vendor != READSTAT_VENDOR_STAT_TRANSFER)) {
  ------------------
  |  Branch (1027:22): [True: 188, False: 34]
  ------------------
 1028|    269|                data = shp + 4;
 1029|    814|            } else {
 1030|    814|                data = shp;
 1031|    814|            }
 1032|  1.08k|        }
 1033|  1.93k|    }
 1034|  2.89k|    if (data) {
  ------------------
  |  Branch (1034:9): [True: 1.71k, False: 1.17k]
  ------------------
 1035|  1.71k|        if ((retval = sas7bdat_submit_columns_if_needed(ctx, 0)) != READSTAT_OK) {
  ------------------
  |  Branch (1035:13): [True: 129, False: 1.58k]
  ------------------
 1036|    129|            goto cleanup;
 1037|    129|        }
 1038|  1.58k|        if (ctx->handle.value) {
  ------------------
  |  Branch (1038:13): [True: 1.58k, False: 0]
  ------------------
 1039|  1.58k|            retval = sas7bdat_parse_rows(data, page + page_size - data, ctx);
 1040|  1.58k|        }
 1041|  1.58k|    } 
 1042|  4.00k|cleanup:
 1043|       |
 1044|  4.00k|    return retval;
 1045|  2.89k|}
readstat_sas7bdat_read.c:sas7bdat_parse_single_row:
  453|   197k|static readstat_error_t sas7bdat_parse_single_row(const char *data, sas7bdat_ctx_t *ctx) {
  454|   197k|    if (ctx->parsed_row_count == ctx->row_limit)
  ------------------
  |  Branch (454:9): [True: 405, False: 197k]
  ------------------
  455|    405|        return READSTAT_OK;
  456|   197k|    if (ctx->row_offset) {
  ------------------
  |  Branch (456:9): [True: 0, False: 197k]
  ------------------
  457|      0|        ctx->row_offset--;
  458|      0|        return READSTAT_OK;
  459|      0|    }
  460|       |
  461|   197k|    readstat_error_t retval = READSTAT_OK;
  462|   197k|    int j;
  463|   197k|    if (ctx->handle.value) {
  ------------------
  |  Branch (463:9): [True: 197k, False: 0]
  ------------------
  464|   197k|        ctx->scratch_buffer_len = 4*ctx->max_col_width+1;
  465|   197k|        ctx->scratch_buffer = readstat_realloc(ctx->scratch_buffer, ctx->scratch_buffer_len);
  466|   197k|        if (ctx->scratch_buffer == NULL) {
  ------------------
  |  Branch (466:13): [True: 3, False: 197k]
  ------------------
  467|      3|            retval = READSTAT_ERROR_MALLOC;
  468|      3|            goto cleanup;
  469|      3|        }
  470|       |
  471|  4.85M|        for (j=0; j<ctx->column_count; j++) {
  ------------------
  |  Branch (471:19): [True: 4.65M, False: 197k]
  ------------------
  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: 16, False: 4.65M]
  ------------------
  478|    104|                retval = READSTAT_ERROR_PARSE;
  479|    104|                goto cleanup;
  480|    104|            }
  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: 18, False: 4.65M]
  ------------------
  483|     18|                goto cleanup;
  484|     18|            }
  485|  4.65M|        }
  486|   197k|    }
  487|   197k|    ctx->parsed_row_count++;
  488|       |
  489|   197k|cleanup:
  490|   197k|    return retval;
  491|   197k|}
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: 117k]
  ------------------
  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: 18, False: 4.54M]
  ------------------
  409|     18|            if (ctx->handle.error) {
  ------------------
  |  Branch (409:17): [True: 0, False: 18]
  ------------------
  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|     18|            goto cleanup;
  416|     18|        }
  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: 117k, False: 0]
  ------------------
  420|   117k|        uint64_t  val = 0;
  421|   117k|        double dval = NAN;
  422|   117k|        if (ctx->little_endian) {
  ------------------
  |  Branch (422:13): [True: 117k, False: 0]
  ------------------
  423|   117k|            int k;
  424|   709k|            for (k=0; k<col_info->width; k++) {
  ------------------
  |  Branch (424:23): [True: 591k, False: 117k]
  ------------------
  425|   591k|                val = (val << 8) | (unsigned char)col_data[col_info->width-1-k];
  426|   591k|            }
  427|   117k|        } 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|   117k|        val <<= (8-col_info->width)*8;
  434|       |
  435|   117k|        memcpy(&dval, &val, 8);
  436|       |
  437|   117k|        if (isnan(dval)) {
  ------------------
  |  Branch (437:13): [True: 8.11k, False: 109k]
  ------------------
  438|  8.11k|            value.v.double_value = NAN;
  439|  8.11k|            sas_assign_tag(&value, ~((val >> 40) & 0xFF));
  440|   109k|        } else {
  441|   109k|            value.v.double_value = dval;
  442|   109k|        }
  443|   117k|    }
  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.29k|static readstat_error_t sas7bdat_parse_subheader_compressed(const char *subheader, size_t len, sas7bdat_ctx_t *ctx) {
  626|  1.29k|    if (ctx->rdc_compression)
  ------------------
  |  Branch (626:9): [True: 334, False: 962]
  ------------------
  627|    334|        return sas7bdat_parse_subheader_rdc(subheader, len, ctx);
  628|       |
  629|    962|    return sas7bdat_parse_subheader_rle(subheader, len, ctx);
  630|  1.29k|}
readstat_sas7bdat_read.c:sas7bdat_parse_subheader_rdc:
  512|    334|static readstat_error_t sas7bdat_parse_subheader_rdc(const char *subheader, size_t len, sas7bdat_ctx_t *ctx) {
  513|    334|    readstat_error_t retval = READSTAT_OK;
  514|    334|    const unsigned char *input = (const unsigned char *)subheader;
  515|    334|    char *buffer = malloc(ctx->row_length);
  516|    334|    char *output = buffer;
  517|  1.88k|    while (input + 2 <= (const unsigned char *)subheader + len) {
  ------------------
  |  Branch (517:12): [True: 1.59k, False: 295]
  ------------------
  518|  1.59k|        int i;
  519|  1.59k|        unsigned short prefix = (input[0] << 8) + input[1];
  520|  1.59k|        input += 2;
  521|  23.5k|        for (i=0; i<16; i++) {
  ------------------
  |  Branch (521:19): [True: 22.2k, False: 1.27k]
  ------------------
  522|  22.2k|            if ((prefix & (1 << (15 - i))) == 0) {
  ------------------
  |  Branch (522:17): [True: 15.2k, False: 6.96k]
  ------------------
  523|  15.2k|                if (input + 1 > (const unsigned char *)subheader + len) {
  ------------------
  |  Branch (523:21): [True: 284, False: 14.9k]
  ------------------
  524|    284|                    break;
  525|    284|                }
  526|  14.9k|                if (output + 1 > buffer + ctx->row_length) {
  ------------------
  |  Branch (526:21): [True: 2, False: 14.9k]
  ------------------
  527|      2|                    retval = READSTAT_ERROR_ROW_WIDTH_MISMATCH;
  528|      2|                    goto cleanup;
  529|      2|                }
  530|  14.9k|                *output++ = *input++;
  531|  14.9k|                continue;
  532|  14.9k|            }
  533|       |
  534|  6.96k|            if (input + 2 > (const unsigned char *)subheader + len) {
  ------------------
  |  Branch (534:17): [True: 3, False: 6.96k]
  ------------------
  535|      3|                retval = READSTAT_ERROR_PARSE;
  536|      3|                goto cleanup;
  537|      3|            }
  538|       |
  539|  6.96k|            unsigned char marker_byte = *input++;
  540|  6.96k|            unsigned char next_byte = *input++;
  541|  6.96k|            size_t insert_len = 0, copy_len = 0;
  542|  6.96k|            unsigned char insert_byte = 0x00;
  543|  6.96k|            size_t back_offset = 0;
  544|       |
  545|  6.96k|            if (marker_byte <= 0x0F) {
  ------------------
  |  Branch (545:17): [True: 2.39k, False: 4.56k]
  ------------------
  546|  2.39k|                insert_len = 3 + marker_byte;
  547|  2.39k|                insert_byte = next_byte;
  548|  4.56k|            } else if ((marker_byte >> 4) == 1) {
  ------------------
  |  Branch (548:24): [True: 1.28k, False: 3.28k]
  ------------------
  549|  1.28k|                if (input + 1 > (const unsigned char *)subheader + len) {
  ------------------
  |  Branch (549:21): [True: 2, False: 1.28k]
  ------------------
  550|      2|                    retval = READSTAT_ERROR_PARSE;
  551|      2|                    goto cleanup;
  552|      2|                }
  553|  1.28k|                insert_len = 19 + (marker_byte & 0x0F) + next_byte * 16;
  554|  1.28k|                insert_byte = *input++;
  555|  3.28k|            } else if ((marker_byte >> 4) == 2) {
  ------------------
  |  Branch (555:24): [True: 528, False: 2.75k]
  ------------------
  556|    528|                if (input + 1 > (const unsigned char *)subheader + len) {
  ------------------
  |  Branch (556:21): [True: 1, False: 527]
  ------------------
  557|      1|                    retval = READSTAT_ERROR_PARSE;
  558|      1|                    goto cleanup;
  559|      1|                }
  560|    527|                copy_len = 16 + (*input++);
  561|    527|                back_offset = 3 + (marker_byte & 0x0F) + next_byte * 16;
  562|  2.75k|            } else {
  563|  2.75k|                copy_len = (marker_byte >> 4);
  564|  2.75k|                back_offset = 3 + (marker_byte & 0x0F) + next_byte * 16;
  565|  2.75k|            }
  566|       |
  567|  6.96k|            if (insert_len) {
  ------------------
  |  Branch (567:17): [True: 3.67k, False: 3.28k]
  ------------------
  568|  3.67k|                if (output + insert_len > buffer + ctx->row_length) {
  ------------------
  |  Branch (568:21): [True: 1, False: 3.67k]
  ------------------
  569|      1|                    retval = READSTAT_ERROR_ROW_WIDTH_MISMATCH;
  570|      1|                    goto cleanup;
  571|      1|                }
  572|  3.67k|                memset(output, insert_byte, insert_len);
  573|  3.67k|                output += insert_len;
  574|  3.67k|            } else if (copy_len) {
  ------------------
  |  Branch (574:24): [True: 3.28k, False: 0]
  ------------------
  575|  3.28k|                if (output - buffer < back_offset || copy_len > back_offset) {
  ------------------
  |  Branch (575:21): [True: 12, False: 3.27k]
  |  Branch (575:54): [True: 17, False: 3.25k]
  ------------------
  576|     29|                    retval = READSTAT_ERROR_PARSE;
  577|     29|                    goto cleanup;
  578|     29|                }
  579|  3.25k|                if (output + copy_len > buffer + ctx->row_length) {
  ------------------
  |  Branch (579:21): [True: 1, False: 3.25k]
  ------------------
  580|      1|                    retval = READSTAT_ERROR_ROW_WIDTH_MISMATCH;
  581|      1|                    goto cleanup;
  582|      1|                }
  583|  3.25k|                memcpy(output, output - back_offset, copy_len);
  584|  3.25k|                output += copy_len;
  585|  3.25k|            }
  586|  6.96k|        }
  587|  1.59k|    }
  588|       |
  589|    295|    if (output - buffer != ctx->row_length) {
  ------------------
  |  Branch (589:9): [True: 27, False: 268]
  ------------------
  590|     27|        retval = READSTAT_ERROR_ROW_WIDTH_MISMATCH;
  591|     27|        goto cleanup;
  592|     27|    }
  593|    268|    retval = sas7bdat_parse_single_row(buffer, ctx);
  594|    334|cleanup:
  595|    334|    free(buffer);
  596|       |
  597|    334|    return retval;
  598|    268|}
readstat_sas7bdat_read.c:sas7bdat_parse_subheader_rle:
  600|    962|static readstat_error_t sas7bdat_parse_subheader_rle(const char *subheader, size_t len, sas7bdat_ctx_t *ctx) {
  601|    962|    if (ctx->row_limit == ctx->parsed_row_count)
  ------------------
  |  Branch (601:9): [True: 503, False: 459]
  ------------------
  602|    503|        return READSTAT_OK;
  603|       |
  604|    459|    readstat_error_t retval = READSTAT_OK;
  605|    459|    ssize_t bytes_decompressed = 0;
  606|       |
  607|    459|    bytes_decompressed = sas_rle_decompress(ctx->row, ctx->row_length, subheader, len);
  608|       |
  609|    459|    if (bytes_decompressed != ctx->row_length) {
  ------------------
  |  Branch (609:9): [True: 149, False: 310]
  ------------------
  610|    149|        retval = READSTAT_ERROR_ROW_WIDTH_MISMATCH;
  611|    149|        if (ctx->handle.error) {
  ------------------
  |  Branch (611:13): [True: 0, False: 149]
  ------------------
  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|    149|        goto cleanup;
  618|    149|    }
  619|    310|    retval = sas7bdat_parse_single_row(ctx->row, ctx);
  620|       |
  621|    459|cleanup:
  622|    459|    return retval;
  623|    310|}
readstat_sas7bdat_read.c:sas7bdat_parse_rows:
  493|  1.58k|static readstat_error_t sas7bdat_parse_rows(const char *data, size_t len, sas7bdat_ctx_t *ctx) {
  494|  1.58k|    readstat_error_t retval = READSTAT_OK;
  495|  1.58k|    int i;
  496|  1.58k|    size_t row_offset=0;
  497|   198k|    for (i=0; i<ctx->page_row_count && ctx->parsed_row_count < ctx->row_limit; i++) {
  ------------------
  |  Branch (497:15): [True: 196k, False: 1.35k]
  |  Branch (497:40): [True: 196k, False: 30]
  ------------------
  498|   196k|        if (row_offset + ctx->row_length > len) {
  ------------------
  |  Branch (498:13): [True: 123, False: 196k]
  ------------------
  499|    123|            retval = READSTAT_ERROR_ROW_WIDTH_MISMATCH;
  500|    123|            goto cleanup;
  501|    123|        }
  502|   196k|        if ((retval = sas7bdat_parse_single_row(&data[row_offset], ctx)) != READSTAT_OK)
  ------------------
  |  Branch (502:13): [True: 75, False: 196k]
  ------------------
  503|     75|            goto cleanup;
  504|       |
  505|   196k|        row_offset += ctx->row_length;
  506|   196k|    }
  507|       |
  508|  1.58k|cleanup:
  509|  1.58k|    return retval;
  510|  1.58k|}
readstat_sas7bdat_read.c:sas7bdat_submit_columns_if_needed:
  799|  3.97k|static readstat_error_t sas7bdat_submit_columns_if_needed(sas7bdat_ctx_t *ctx, int compressed) {
  800|  3.97k|    readstat_error_t retval = READSTAT_OK;
  801|  3.97k|    if (!ctx->did_submit_columns) {
  ------------------
  |  Branch (801:9): [True: 1.37k, False: 2.59k]
  ------------------
  802|  1.37k|        if ((retval = sas7bdat_submit_columns(ctx, compressed)) != READSTAT_OK) {
  ------------------
  |  Branch (802:13): [True: 260, False: 1.11k]
  ------------------
  803|    260|            goto cleanup;
  804|    260|        }
  805|  1.11k|        ctx->did_submit_columns = 1;
  806|  1.11k|    }
  807|  3.97k|cleanup:
  808|  3.97k|    return retval;
  809|  3.97k|}
readstat_sas7bdat_read.c:sas7bdat_submit_columns:
  738|  1.37k|static readstat_error_t sas7bdat_submit_columns(sas7bdat_ctx_t *ctx, int compressed) {
  739|  1.37k|    readstat_error_t retval = READSTAT_OK;
  740|  1.37k|    if (ctx->handle.metadata) {
  ------------------
  |  Branch (740:9): [True: 1.37k, False: 0]
  ------------------
  741|  1.37k|        readstat_metadata_t metadata = {
  742|  1.37k|            .row_count = ctx->row_limit,
  743|  1.37k|            .var_count = ctx->column_count,
  744|  1.37k|            .table_name = ctx->table_name,
  745|  1.37k|            .file_label = ctx->file_label,
  746|  1.37k|            .file_encoding = ctx->input_encoding, /* orig encoding? */
  747|  1.37k|            .creation_time = ctx->ctime,
  748|  1.37k|            .modified_time = ctx->mtime,
  749|  1.37k|            .file_format_version = ctx->version,
  750|  1.37k|            .compression = READSTAT_COMPRESS_NONE,
  751|  1.37k|            .endianness = ctx->little_endian ? READSTAT_ENDIAN_LITTLE : READSTAT_ENDIAN_BIG,
  ------------------
  |  Branch (751:27): [True: 260, False: 1.11k]
  ------------------
  752|  1.37k|            .is64bit = ctx->u64
  753|  1.37k|        };
  754|  1.37k|        if (compressed) {
  ------------------
  |  Branch (754:13): [True: 572, False: 806]
  ------------------
  755|    572|            if (ctx->rdc_compression) {
  ------------------
  |  Branch (755:17): [True: 64, False: 508]
  ------------------
  756|     64|                metadata.compression = READSTAT_COMPRESS_BINARY;
  757|    508|            } else {
  758|    508|                metadata.compression = READSTAT_COMPRESS_ROWS;
  759|    508|            }
  760|    572|        }
  761|  1.37k|        if (ctx->handle.metadata(&metadata, ctx->user_ctx) != READSTAT_HANDLER_OK) {
  ------------------
  |  Branch (761:13): [True: 0, False: 1.37k]
  ------------------
  762|      0|            retval = READSTAT_ERROR_USER_ABORT;
  763|      0|            goto cleanup;
  764|      0|        }
  765|  1.37k|    }
  766|  1.37k|    if (ctx->column_count == 0)
  ------------------
  |  Branch (766:9): [True: 883, False: 495]
  ------------------
  767|    883|        goto cleanup;
  768|       |
  769|    495|    if ((ctx->variables = readstat_calloc(ctx->column_count, sizeof(readstat_variable_t *))) == NULL) {
  ------------------
  |  Branch (769:9): [True: 0, False: 495]
  ------------------
  770|      0|        retval = READSTAT_ERROR_MALLOC;
  771|      0|        goto cleanup;
  772|      0|    }
  773|    495|    int i;
  774|    495|    int index_after_skipping = 0;
  775|  3.78M|    for (i=0; i<ctx->column_count; i++) {
  ------------------
  |  Branch (775:15): [True: 3.78M, False: 235]
  ------------------
  776|  3.78M|        ctx->variables[i] = sas7bdat_init_variable(ctx, i, index_after_skipping, &retval);
  777|  3.78M|        if (ctx->variables[i] == NULL)
  ------------------
  |  Branch (777:13): [True: 260, False: 3.78M]
  ------------------
  778|    260|            break;
  779|       |
  780|  3.78M|        int cb_retval = READSTAT_HANDLER_OK;
  781|  3.78M|        if (ctx->handle.variable) {
  ------------------
  |  Branch (781:13): [True: 3.78M, False: 0]
  ------------------
  782|  3.78M|            cb_retval = ctx->handle.variable(i, ctx->variables[i], ctx->variables[i]->format, ctx->user_ctx);
  783|  3.78M|        }
  784|  3.78M|        if (cb_retval == READSTAT_HANDLER_ABORT) {
  ------------------
  |  Branch (784:13): [True: 0, False: 3.78M]
  ------------------
  785|      0|            retval = READSTAT_ERROR_USER_ABORT;
  786|      0|            goto cleanup;
  787|      0|        }
  788|       |
  789|  3.78M|        if (cb_retval == READSTAT_HANDLER_SKIP_VARIABLE) {
  ------------------
  |  Branch (789:13): [True: 0, False: 3.78M]
  ------------------
  790|      0|            ctx->variables[i]->skip = 1;
  791|  3.78M|        } else {
  792|  3.78M|            index_after_skipping++;
  793|  3.78M|        }
  794|  3.78M|    }
  795|  1.37k|cleanup:
  796|  1.37k|    return retval;
  797|    495|}
readstat_sas7bdat_read.c:sas7bdat_init_variable:
  682|  3.78M|        int index_after_skipping, readstat_error_t *out_retval) {
  683|  3.78M|    readstat_error_t retval = READSTAT_OK;
  684|  3.78M|    readstat_variable_t *variable = readstat_calloc(1, sizeof(readstat_variable_t));
  685|       |
  686|  3.78M|    variable->index = i;
  687|  3.78M|    variable->index_after_skipping = index_after_skipping;
  688|  3.78M|    variable->type = ctx->col_info[i].type;
  689|  3.78M|    variable->storage_width = ctx->col_info[i].width;
  690|       |
  691|  3.78M|    if ((retval = sas7bdat_validate_column(&ctx->col_info[i])) != READSTAT_OK) {
  ------------------
  |  Branch (691:9): [True: 86, False: 3.78M]
  ------------------
  692|     86|        goto cleanup;
  693|     86|    }
  694|  3.78M|    if ((retval = sas7bdat_copy_text_ref(variable->name, sizeof(variable->name), 
  ------------------
  |  Branch (694:9): [True: 59, False: 3.78M]
  ------------------
  695|  3.78M|                    ctx->col_info[i].name_ref, ctx)) != READSTAT_OK) {
  696|     59|        goto cleanup;
  697|     59|    }
  698|  3.78M|    if ((retval = sas7bdat_copy_text_ref(variable->format, sizeof(variable->format),
  ------------------
  |  Branch (698:9): [True: 54, False: 3.78M]
  ------------------
  699|  3.78M|                    ctx->col_info[i].format_ref, ctx)) != READSTAT_OK) {
  700|     54|        goto cleanup;
  701|     54|    }
  702|  3.78M|    size_t len = strlen(variable->format);
  703|  3.78M|    if (ctx->col_info[i].format_width) {
  ------------------
  |  Branch (703:9): [True: 610, False: 3.78M]
  ------------------
  704|    610|        len += snprintf(variable->format + len, sizeof(variable->format) - len,
  705|    610|                "%d", ctx->col_info[i].format_width);
  706|    610|    }
  707|  3.78M|    if (len && ctx->col_info[i].format_digits) {
  ------------------
  |  Branch (707:9): [True: 665, False: 3.78M]
  |  Branch (707:16): [True: 524, False: 141]
  ------------------
  708|    524|        len += snprintf(variable->format + len, sizeof(variable->format) - len,
  709|    524|                ".%d", ctx->col_info[i].format_digits);
  710|    524|    }
  711|  3.78M|    if ((retval = sas7bdat_copy_text_ref(variable->label, sizeof(variable->label), 
  ------------------
  |  Branch (711:9): [True: 61, False: 3.78M]
  ------------------
  712|  3.78M|                    ctx->col_info[i].label_ref, ctx)) != READSTAT_OK) {
  713|     61|        goto cleanup;
  714|     61|    }
  715|       |
  716|  3.78M|cleanup:
  717|  3.78M|    if (retval != READSTAT_OK) {
  ------------------
  |  Branch (717:9): [True: 260, False: 3.78M]
  ------------------
  718|    260|        if (out_retval)
  ------------------
  |  Branch (718:13): [True: 260, False: 0]
  ------------------
  719|    260|            *out_retval = retval;
  720|       |
  721|    260|        if (retval == READSTAT_ERROR_CONVERT_BAD_STRING) {
  ------------------
  |  Branch (721:13): [True: 9, False: 251]
  ------------------
  722|      9|            if (ctx->handle.error) {
  ------------------
  |  Branch (722:17): [True: 0, False: 9]
  ------------------
  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|      9|        }
  729|       |
  730|    260|        free(variable);
  731|       |
  732|    260|        return NULL;
  733|    260|    }
  734|       |
  735|  3.78M|    return variable;
  736|  3.78M|}
readstat_sas7bdat_read.c:sas7bdat_validate_column:
  667|  3.78M|static readstat_error_t sas7bdat_validate_column(col_info_t *col_info) {
  668|  3.78M|    if (col_info->type == READSTAT_TYPE_DOUBLE) {
  ------------------
  |  Branch (668:9): [True: 898, False: 3.78M]
  ------------------
  669|    898|        if (col_info->width > 8 || col_info->width < 3) {
  ------------------
  |  Branch (669:13): [True: 45, False: 853]
  |  Branch (669:36): [True: 2, False: 851]
  ------------------
  670|     47|            return READSTAT_ERROR_PARSE;
  671|     47|        }
  672|    898|    }
  673|  3.78M|    if (col_info->type == READSTAT_TYPE_STRING) {
  ------------------
  |  Branch (673:9): [True: 3.78M, False: 851]
  ------------------
  674|  3.78M|        if (col_info->width > INT16_MAX) {
  ------------------
  |  Branch (674:13): [True: 39, False: 3.78M]
  ------------------
  675|     39|            return READSTAT_ERROR_PARSE;
  676|     39|        }
  677|  3.78M|    }
  678|  3.78M|    return READSTAT_OK;
  679|  3.78M|}
readstat_sas7bdat_read.c:sas7bdat_update_progress:
  128|  4.28k|static readstat_error_t sas7bdat_update_progress(sas7bdat_ctx_t *ctx) {
  129|  4.28k|    readstat_io_t *io = ctx->io;
  130|  4.28k|    return io->update(ctx->file_size, ctx->handle.progress, ctx->user_ctx, io->io_ctx);
  131|  4.28k|}
readstat_sas7bdat_read.c:sas7bdat_ctx_free:
   94|  3.60k|static void sas7bdat_ctx_free(sas7bdat_ctx_t *ctx) {
   95|  3.60k|    int i;
   96|  3.60k|    if (ctx->text_blobs) {
  ------------------
  |  Branch (96:9): [True: 882, False: 2.71k]
  ------------------
   97|  3.72k|        for (i=0; i<ctx->text_blob_count; i++) {
  ------------------
  |  Branch (97:19): [True: 2.84k, False: 882]
  ------------------
   98|  2.84k|            free(ctx->text_blobs[i]);
   99|  2.84k|        }
  100|    882|        free(ctx->text_blobs);
  101|    882|        free(ctx->text_blob_lengths);
  102|    882|    }
  103|  3.60k|    if (ctx->variables) {
  ------------------
  |  Branch (103:9): [True: 495, False: 3.10k]
  ------------------
  104|  18.6M|        for (i=0; i<ctx->column_count; i++) {
  ------------------
  |  Branch (104:19): [True: 18.6M, False: 495]
  ------------------
  105|  18.6M|            if (ctx->variables[i])
  ------------------
  |  Branch (105:17): [True: 3.78M, False: 14.8M]
  ------------------
  106|  3.78M|                free(ctx->variables[i]);
  107|  18.6M|        }
  108|    495|        free(ctx->variables);
  109|    495|    }
  110|  3.60k|    if (ctx->col_info)
  ------------------
  |  Branch (110:9): [True: 649, False: 2.95k]
  ------------------
  111|    649|        free(ctx->col_info);
  112|       |
  113|  3.60k|    if (ctx->scratch_buffer)
  ------------------
  |  Branch (113:9): [True: 563, False: 3.03k]
  ------------------
  114|    563|        free(ctx->scratch_buffer);
  115|       |
  116|  3.60k|    if (ctx->page)
  ------------------
  |  Branch (116:9): [True: 3.08k, False: 519]
  ------------------
  117|  3.08k|        free(ctx->page);
  118|       |
  119|  3.60k|    if (ctx->row)
  ------------------
  |  Branch (119:9): [True: 1.02k, False: 2.57k]
  ------------------
  120|  1.02k|        free(ctx->row);
  121|       |
  122|  3.60k|    if (ctx->converter)
  ------------------
  |  Branch (122:9): [True: 2.19k, False: 1.41k]
  ------------------
  123|  2.19k|        iconv_close(ctx->converter);
  124|       |
  125|  3.60k|    free(ctx);
  126|  3.60k|}

sas_rle_decompress:
   47|    459|        const void *input_buf, size_t input_len) {
   48|    459|    unsigned char *buffer = (unsigned char *)output_buf;
   49|    459|    unsigned char *output = buffer;
   50|    459|    size_t output_written = 0;
   51|       |
   52|    459|    const unsigned char *input = (const unsigned char *)input_buf;
   53|       |
   54|  57.5k|    while (input < (const unsigned char *)input_buf + input_len) {
  ------------------
  |  Branch (54:12): [True: 57.2k, False: 336]
  ------------------
   55|  57.2k|        unsigned char control = *input++;
   56|  57.2k|        unsigned char command = (control & 0xF0) >> 4;
   57|  57.2k|        unsigned char length = (control & 0x0F);
   58|  57.2k|        int copy_len = 0;
   59|  57.2k|        int insert_len = 0;
   60|  57.2k|        unsigned char insert_byte = '\0';
   61|  57.2k|        if (input + command_lengths[command] > (const unsigned char *)input_buf + input_len) {
  ------------------
  |  Branch (61:13): [True: 4, False: 57.2k]
  ------------------
   62|      4|            return -1;
   63|      4|        }
   64|  57.2k|        switch (command) {
   65|  3.45k|            case SAS_RLE_COMMAND_COPY64:
  ------------------
  |  |   13|  3.45k|#define SAS_RLE_COMMAND_COPY64          0
  ------------------
  |  Branch (65:13): [True: 3.45k, False: 53.7k]
  ------------------
   66|  3.45k|                copy_len = (*input++) + 64 + length * 256;
   67|  3.45k|                break;
   68|    124|            case SAS_RLE_COMMAND_COPY64_PLUS_4096:
  ------------------
  |  |   14|    124|#define SAS_RLE_COMMAND_COPY64_PLUS_4096 1
  ------------------
  |  Branch (68:13): [True: 124, False: 57.1k]
  ------------------
   69|    124|                copy_len = (*input++) + 64 + length * 256 + 4096;
   70|    124|                break;
   71|    749|            case SAS_RLE_COMMAND_COPY96: copy_len = length + 96; break;
  ------------------
  |  |   15|    749|#define SAS_RLE_COMMAND_COPY96          2
  ------------------
  |  Branch (71:13): [True: 749, False: 56.4k]
  ------------------
   72|    750|            case SAS_RLE_COMMAND_INSERT_BYTE18:
  ------------------
  |  |   16|    750|#define SAS_RLE_COMMAND_INSERT_BYTE18   4
  ------------------
  |  Branch (72:13): [True: 750, False: 56.4k]
  ------------------
   73|    750|                insert_len = (*input++) + 18 + length * 256;
   74|    750|                insert_byte = *input++;
   75|    750|                break;
   76|  1.01k|            case SAS_RLE_COMMAND_INSERT_AT17:
  ------------------
  |  |   17|  1.01k|#define SAS_RLE_COMMAND_INSERT_AT17     5
  ------------------
  |  Branch (76:13): [True: 1.01k, False: 56.2k]
  ------------------
   77|  1.01k|                insert_len = (*input++) + 17 + length * 256;
   78|  1.01k|                insert_byte = '@';
   79|  1.01k|                break;
   80|    987|            case SAS_RLE_COMMAND_INSERT_BLANK17:
  ------------------
  |  |   18|    987|#define SAS_RLE_COMMAND_INSERT_BLANK17  6
  ------------------
  |  Branch (80:13): [True: 987, False: 56.2k]
  ------------------
   81|    987|                insert_len = (*input++) + 17 + length * 256;
   82|    987|                insert_byte = ' ';
   83|    987|                break;
   84|  1.45k|            case SAS_RLE_COMMAND_INSERT_ZERO17:
  ------------------
  |  |   19|  1.45k|#define SAS_RLE_COMMAND_INSERT_ZERO17   7
  ------------------
  |  Branch (84:13): [True: 1.45k, False: 55.7k]
  ------------------
   85|  1.45k|                insert_len = (*input++) + 17 + length * 256;
   86|  1.45k|                insert_byte = '\0';
   87|  1.45k|                break;
   88|  1.03k|            case SAS_RLE_COMMAND_COPY1:  copy_len = length + 1; break;
  ------------------
  |  |   20|  1.03k|#define SAS_RLE_COMMAND_COPY1           8
  ------------------
  |  Branch (88:13): [True: 1.03k, False: 56.1k]
  ------------------
   89|  9.58k|            case SAS_RLE_COMMAND_COPY17: copy_len = length + 17; break;
  ------------------
  |  |   21|  9.58k|#define SAS_RLE_COMMAND_COPY17          9
  ------------------
  |  Branch (89:13): [True: 9.58k, False: 47.6k]
  ------------------
   90|    583|            case SAS_RLE_COMMAND_COPY33: copy_len = length + 33; break;
  ------------------
  |  |   22|    583|#define SAS_RLE_COMMAND_COPY33         10
  ------------------
  |  Branch (90:13): [True: 583, False: 56.6k]
  ------------------
   91|    399|            case SAS_RLE_COMMAND_COPY49: copy_len = length + 49; break;
  ------------------
  |  |   23|    399|#define SAS_RLE_COMMAND_COPY49         11
  ------------------
  |  Branch (91:13): [True: 399, False: 56.8k]
  ------------------
   92|    964|            case SAS_RLE_COMMAND_INSERT_BYTE3:
  ------------------
  |  |   24|    964|#define SAS_RLE_COMMAND_INSERT_BYTE3   12
  ------------------
  |  Branch (92:13): [True: 964, False: 56.2k]
  ------------------
   93|    964|                insert_byte = *input++;
   94|    964|                insert_len = length + 3;
   95|    964|                break;
   96|    625|            case SAS_RLE_COMMAND_INSERT_AT2:
  ------------------
  |  |   25|    625|#define SAS_RLE_COMMAND_INSERT_AT2     13
  ------------------
  |  Branch (96:13): [True: 625, False: 56.5k]
  ------------------
   97|    625|                insert_byte = '@';
   98|    625|                insert_len = length + 2;
   99|    625|                break;
  100|  28.1k|            case SAS_RLE_COMMAND_INSERT_BLANK2:
  ------------------
  |  |   26|  28.1k|#define SAS_RLE_COMMAND_INSERT_BLANK2  14
  ------------------
  |  Branch (100:13): [True: 28.1k, False: 29.0k]
  ------------------
  101|  28.1k|                insert_byte = ' ';
  102|  28.1k|                insert_len = length + 2;
  103|  28.1k|                break;
  104|  5.00k|            case SAS_RLE_COMMAND_INSERT_ZERO2:
  ------------------
  |  |   27|  5.00k|#define SAS_RLE_COMMAND_INSERT_ZERO2   15
  ------------------
  |  Branch (104:13): [True: 5.00k, False: 52.2k]
  ------------------
  105|  5.00k|                insert_byte = '\0';
  106|  5.00k|                insert_len = length + 2;
  107|  5.00k|                break;
  108|  2.33k|            default:
  ------------------
  |  Branch (108:13): [True: 2.33k, False: 54.8k]
  ------------------
  109|       |                /* error out here? */
  110|  2.33k|                break;
  111|  57.2k|        }
  112|  57.2k|        if (copy_len) {
  ------------------
  |  Branch (112:13): [True: 15.9k, False: 41.2k]
  ------------------
  113|  15.9k|            if (output_written + copy_len > output_len) {
  ------------------
  |  Branch (113:17): [True: 19, False: 15.9k]
  ------------------
  114|     19|                return -1;
  115|     19|            }
  116|  15.9k|            if (input + copy_len > (const unsigned char *)input_buf + input_len) {
  ------------------
  |  Branch (116:17): [True: 84, False: 15.8k]
  ------------------
  117|     84|                return -1;
  118|     84|            }
  119|  15.8k|            if (output) {
  ------------------
  |  Branch (119:17): [True: 15.8k, False: 0]
  ------------------
  120|  15.8k|                memcpy(&output[output_written], input, copy_len);
  121|  15.8k|            }
  122|  15.8k|            input += copy_len;
  123|  15.8k|            output_written += copy_len;
  124|  15.8k|        }
  125|  57.1k|        if (insert_len) {
  ------------------
  |  Branch (125:13): [True: 38.9k, False: 18.1k]
  ------------------
  126|  38.9k|            if (output_written + insert_len > output_len) {
  ------------------
  |  Branch (126:17): [True: 16, False: 38.9k]
  ------------------
  127|     16|                return -1;
  128|     16|            }
  129|  38.9k|            if (output) {
  ------------------
  |  Branch (129:17): [True: 38.9k, False: 0]
  ------------------
  130|  38.9k|                memset(&output[output_written], insert_byte, insert_len);
  131|  38.9k|            }
  132|  38.9k|            output_written += insert_len;
  133|  38.9k|        }
  134|  57.1k|    }
  135|       |
  136|    336|    return output_written;
  137|    459|}

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

