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

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

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

readstat_convert:
    7|  4.20M|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.25M|    while (src_len && (src[src_len-1] == ' ' || src[src_len-1] == '\0')) {
  ------------------
  |  Branch (10:12): [True: 68.9k, False: 4.18M]
  |  Branch (10:24): [True: 3.81k, False: 65.1k]
  |  Branch (10:49): [True: 43.2k, False: 21.8k]
  ------------------
   11|  47.0k|        src_len--;
   12|  47.0k|    }
   13|  4.20M|    if (dst_len == 0) {
  ------------------
  |  Branch (13:9): [True: 0, False: 4.20M]
  ------------------
   14|      0|        return READSTAT_ERROR_CONVERT_LONG_STRING;
   15|  4.20M|    } else if (converter) {
  ------------------
  |  Branch (15:16): [True: 1.11M, False: 3.08M]
  ------------------
   16|  1.11M|        size_t dst_left = dst_len - 1;
   17|  1.11M|        char *dst_end = dst;
   18|  1.11M|        size_t status = iconv(converter, (readstat_iconv_inbuf_t)&src, &src_len, &dst_end, &dst_left);
   19|  1.11M|        if (status == (size_t)-1) {
  ------------------
  |  Branch (19:13): [True: 1.79k, False: 1.11M]
  ------------------
   20|  1.79k|            if (errno == E2BIG) {
  ------------------
  |  Branch (20:17): [True: 5, False: 1.79k]
  ------------------
   21|      5|                return READSTAT_ERROR_CONVERT_LONG_STRING;
   22|  1.79k|            } else if (errno == EILSEQ) {
  ------------------
  |  Branch (22:24): [True: 31, False: 1.76k]
  ------------------
   23|     31|                return READSTAT_ERROR_CONVERT_BAD_STRING;
   24|  1.76k|            } else if (errno != EINVAL) { /* EINVAL indicates improper truncation; accept it */
  ------------------
  |  Branch (24:24): [True: 0, False: 1.76k]
  ------------------
   25|      0|                return READSTAT_ERROR_CONVERT;
   26|      0|            }
   27|  1.79k|        }
   28|  1.11M|        dst[dst_len - dst_left - 1] = '\0';
   29|  3.08M|    } else if (src_len + 1 > dst_len) {
  ------------------
  |  Branch (29:16): [True: 19, False: 3.08M]
  ------------------
   30|     19|        return READSTAT_ERROR_CONVERT_LONG_STRING;
   31|  3.08M|    } else {
   32|  3.08M|        memcpy(dst, src, src_len);
   33|  3.08M|        dst[src_len] = '\0';
   34|  3.08M|    }
   35|  4.20M|    return READSTAT_OK;
   36|  4.20M|}

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

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

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

sas_read8:
  139|  50.4k|uint64_t sas_read8(const char *data, int bswap) {
  140|  50.4k|    uint64_t tmp;
  141|  50.4k|    memcpy(&tmp, data, 8);
  142|  50.4k|    return bswap ? byteswap8(tmp) : tmp;
  ------------------
  |  Branch (142:12): [True: 45.0k, False: 5.38k]
  ------------------
  143|  50.4k|}
sas_read4:
  145|   223k|uint32_t sas_read4(const char *data, int bswap) {
  146|   223k|    uint32_t tmp;
  147|   223k|    memcpy(&tmp, data, 4);
  148|   223k|    return bswap ? byteswap4(tmp) : tmp;
  ------------------
  |  Branch (148:12): [True: 168k, False: 55.7k]
  ------------------
  149|   223k|}
sas_read2:
  151|   219k|uint16_t sas_read2(const char *data, int bswap) {
  152|   219k|    uint16_t tmp;
  153|   219k|    memcpy(&tmp, data, 2);
  154|   219k|    return bswap ? byteswap2(tmp) : tmp;
  ------------------
  |  Branch (154:12): [True: 81.0k, False: 138k]
  ------------------
  155|   219k|}
sas_subheader_remainder:
  157|  6.12k|size_t sas_subheader_remainder(size_t len, size_t signature_len) {
  158|  6.12k|    return len - (4+2*signature_len);
  159|  6.12k|}
sas_read_header:
  162|  3.51k|        readstat_error_handler error_handler, void *user_ctx) {
  163|  3.51k|    sas_header_start_t  header_start;
  164|  3.51k|    sas_header_end_t    header_end;
  165|  3.51k|    int retval = READSTAT_OK;
  166|  3.51k|    char error_buf[1024];
  167|  3.51k|    time_t epoch = sas_epoch();
  168|       |
  169|  3.51k|    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.49k]
  ------------------
  170|     20|        retval = READSTAT_ERROR_READ;
  171|     20|        goto cleanup;
  172|     20|    }
  173|  3.49k|    if (memcmp(header_start.magic, sas7bdat_magic_number, sizeof(sas7bdat_magic_number)) != 0 &&
  ------------------
  |  Branch (173:9): [True: 1.63k, False: 1.85k]
  ------------------
  174|  1.63k|            memcmp(header_start.magic, sas7bcat_magic_number, sizeof(sas7bcat_magic_number)) != 0) {
  ------------------
  |  Branch (174:13): [True: 126, False: 1.51k]
  ------------------
  175|    126|        retval = READSTAT_ERROR_PARSE;
  176|    126|        goto cleanup;
  177|    126|    }
  178|  3.36k|    if (header_start.a1 == SAS_ALIGNMENT_OFFSET_4) {
  ------------------
  |  |   87|  3.36k|#define SAS_ALIGNMENT_OFFSET_4  0x33
  ------------------
  |  Branch (178:9): [True: 8, False: 3.36k]
  ------------------
  179|      8|        hinfo->pad1 = 4;
  180|      8|    }
  181|  3.36k|    if (header_start.a2 == SAS_ALIGNMENT_OFFSET_4) {
  ------------------
  |  |   87|  3.36k|#define SAS_ALIGNMENT_OFFSET_4  0x33
  ------------------
  |  Branch (181:9): [True: 1.56k, False: 1.80k]
  ------------------
  182|  1.56k|        hinfo->u64 = 1;
  183|  1.56k|    }
  184|  3.36k|    int bswap = 0;
  185|  3.36k|    if (header_start.endian == SAS_ENDIAN_BIG) {
  ------------------
  |  |   80|  3.36k|#define SAS_ENDIAN_BIG       0x00
  ------------------
  |  Branch (185:9): [True: 2.62k, False: 748]
  ------------------
  186|  2.62k|        bswap = machine_is_little_endian();
  187|  2.62k|        hinfo->little_endian = 0;
  188|  2.62k|    } else if (header_start.endian == SAS_ENDIAN_LITTLE) {
  ------------------
  |  |   81|    748|#define SAS_ENDIAN_LITTLE    0x01
  ------------------
  |  Branch (188:16): [True: 735, False: 13]
  ------------------
  189|    735|        bswap = !machine_is_little_endian();
  190|    735|        hinfo->little_endian = 1;
  191|    735|    } else {
  192|     13|        retval = READSTAT_ERROR_PARSE;
  193|     13|        goto cleanup;
  194|     13|    }
  195|  3.35k|    int i;
  196|  20.9k|    for (i=0; i<sizeof(_charset_table)/sizeof(_charset_table[0]); i++) {
  ------------------
  |  Branch (196:15): [True: 20.9k, False: 5]
  ------------------
  197|  20.9k|        if (header_start.encoding == _charset_table[i].code) {
  ------------------
  |  Branch (197:13): [True: 3.35k, False: 17.5k]
  ------------------
  198|  3.35k|            hinfo->encoding = _charset_table[i].name;
  199|  3.35k|            break;
  200|  3.35k|        }
  201|  20.9k|    }
  202|  3.35k|    if (hinfo->encoding == NULL) {
  ------------------
  |  Branch (202:9): [True: 5, False: 3.35k]
  ------------------
  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.35k|    memcpy(hinfo->table_name, header_start.table_name, sizeof(header_start.table_name));
  211|  3.35k|    if (io->seek(hinfo->pad1, READSTAT_SEEK_CUR, io->io_ctx) == -1) {
  ------------------
  |  Branch (211:9): [True: 6, False: 3.34k]
  ------------------
  212|      6|        retval = READSTAT_ERROR_SEEK;
  213|      6|        goto cleanup;
  214|      6|    }
  215|       |
  216|  3.34k|    double creation_time, modification_time, creation_time_diff, modification_time_diff;
  217|       |
  218|  3.34k|    if (io->read(&creation_time, sizeof(double), io->io_ctx) < sizeof(double)) {
  ------------------
  |  Branch (218:9): [True: 11, False: 3.33k]
  ------------------
  219|     11|        retval = READSTAT_ERROR_READ;
  220|     11|        goto cleanup;
  221|     11|    }
  222|  3.33k|    if (bswap)
  ------------------
  |  Branch (222:9): [True: 2.60k, False: 728]
  ------------------
  223|  2.60k|        creation_time = byteswap_double(creation_time);
  224|       |
  225|  3.33k|    if (io->read(&modification_time, sizeof(double), io->io_ctx) < sizeof(double)) {
  ------------------
  |  Branch (225:9): [True: 6, False: 3.32k]
  ------------------
  226|      6|        retval = READSTAT_ERROR_READ;
  227|      6|        goto cleanup;
  228|      6|    }
  229|  3.32k|    if (bswap)
  ------------------
  |  Branch (229:9): [True: 2.60k, False: 725]
  ------------------
  230|  2.60k|        modification_time = byteswap_double(modification_time);
  231|       |
  232|  3.32k|    if (io->read(&creation_time_diff, sizeof(double), io->io_ctx) < sizeof(double)) {
  ------------------
  |  Branch (232:9): [True: 6, False: 3.32k]
  ------------------
  233|      6|        retval = READSTAT_ERROR_READ;
  234|      6|        goto cleanup;
  235|      6|    }
  236|  3.32k|    if (bswap)
  ------------------
  |  Branch (236:9): [True: 2.59k, False: 723]
  ------------------
  237|  2.59k|        creation_time_diff = byteswap_double(creation_time_diff);
  238|       |    
  239|  3.32k|    if (io->read(&modification_time_diff, sizeof(double), io->io_ctx) < sizeof(double)) {
  ------------------
  |  Branch (239:9): [True: 6, False: 3.31k]
  ------------------
  240|      6|        retval = READSTAT_ERROR_READ;
  241|      6|        goto cleanup;
  242|      6|    }
  243|  3.31k|    if (bswap)
  ------------------
  |  Branch (243:9): [True: 2.59k, False: 720]
  ------------------
  244|  2.59k|        modification_time_diff = byteswap_double(modification_time_diff);
  245|       |    
  246|  3.31k|    hinfo->creation_time = sas_convert_time(creation_time, creation_time_diff, epoch);
  247|  3.31k|    hinfo->modification_time = sas_convert_time(modification_time, modification_time_diff, epoch);
  248|       |
  249|  3.31k|    uint32_t header_size, page_size;
  250|       |
  251|  3.31k|    if (io->read(&header_size, sizeof(uint32_t), io->io_ctx) < sizeof(uint32_t)) {
  ------------------
  |  Branch (251:9): [True: 7, False: 3.30k]
  ------------------
  252|      7|        retval = READSTAT_ERROR_READ;
  253|      7|        goto cleanup;
  254|      7|    }
  255|  3.30k|    if (io->read(&page_size, sizeof(uint32_t), io->io_ctx) < sizeof(uint32_t)) {
  ------------------
  |  Branch (255:9): [True: 3, False: 3.30k]
  ------------------
  256|      3|        retval = READSTAT_ERROR_READ;
  257|      3|        goto cleanup;
  258|      3|    }
  259|       |
  260|  3.30k|    hinfo->header_size = bswap ? byteswap4(header_size) : header_size;
  ------------------
  |  Branch (260:26): [True: 2.58k, False: 717]
  ------------------
  261|  3.30k|    hinfo->page_size = bswap ? byteswap4(page_size) : page_size;
  ------------------
  |  Branch (261:24): [True: 2.58k, False: 717]
  ------------------
  262|       |
  263|  3.30k|    if (hinfo->header_size < 1024 || hinfo->page_size < 1024) {
  ------------------
  |  Branch (263:9): [True: 11, False: 3.29k]
  |  Branch (263:38): [True: 11, False: 3.28k]
  ------------------
  264|     22|        retval = READSTAT_ERROR_PARSE;
  265|     22|        goto cleanup;
  266|     22|    }
  267|  3.28k|    if (hinfo->header_size > (1<<24) || hinfo->page_size > (1<<24)) {
  ------------------
  |  Branch (267:9): [True: 21, False: 3.26k]
  |  Branch (267:41): [True: 24, False: 3.23k]
  ------------------
  268|     45|        retval = READSTAT_ERROR_PARSE;
  269|     45|        goto cleanup;
  270|     45|    }
  271|       |
  272|  3.23k|    if (hinfo->u64) {
  ------------------
  |  Branch (272:9): [True: 1.51k, False: 1.72k]
  ------------------
  273|  1.51k|        hinfo->page_header_size = SAS_PAGE_HEADER_SIZE_64BIT;
  ------------------
  |  |  121|  1.51k|#define SAS_PAGE_HEADER_SIZE_64BIT  40
  ------------------
  274|  1.51k|        hinfo->subheader_pointer_size = SAS_SUBHEADER_POINTER_SIZE_64BIT;
  ------------------
  |  |  118|  1.51k|#define SAS_SUBHEADER_POINTER_SIZE_64BIT    24
  ------------------
  275|  1.72k|    } else {
  276|  1.72k|        hinfo->page_header_size = SAS_PAGE_HEADER_SIZE_32BIT;
  ------------------
  |  |  120|  1.72k|#define SAS_PAGE_HEADER_SIZE_32BIT  24
  ------------------
  277|  1.72k|        hinfo->subheader_pointer_size = SAS_SUBHEADER_POINTER_SIZE_32BIT;
  ------------------
  |  |  117|  1.72k|#define SAS_SUBHEADER_POINTER_SIZE_32BIT    12
  ------------------
  278|  1.72k|    }
  279|       |
  280|  3.23k|    if (hinfo->u64) {
  ------------------
  |  Branch (280:9): [True: 1.51k, False: 1.72k]
  ------------------
  281|  1.51k|        uint64_t page_count;
  282|  1.51k|        if (io->read(&page_count, sizeof(uint64_t), io->io_ctx) < sizeof(uint64_t)) {
  ------------------
  |  Branch (282:13): [True: 20, False: 1.49k]
  ------------------
  283|     20|            retval = READSTAT_ERROR_READ;
  284|     20|            goto cleanup;
  285|     20|        }
  286|  1.49k|        hinfo->page_count = bswap ? byteswap8(page_count) : page_count;
  ------------------
  |  Branch (286:29): [True: 1.39k, False: 100]
  ------------------
  287|  1.72k|    } else {
  288|  1.72k|        uint32_t page_count;
  289|  1.72k|        if (io->read(&page_count, sizeof(uint32_t), io->io_ctx) < sizeof(uint32_t)) {
  ------------------
  |  Branch (289:13): [True: 18, False: 1.70k]
  ------------------
  290|     18|            retval = READSTAT_ERROR_READ;
  291|     18|            goto cleanup;
  292|     18|        }
  293|  1.70k|        hinfo->page_count = bswap ? byteswap4(page_count) : page_count;
  ------------------
  |  Branch (293:29): [True: 1.10k, False: 603]
  ------------------
  294|  1.70k|    }
  295|  3.20k|    if (hinfo->page_count > (1<<24)) {
  ------------------
  |  Branch (295:9): [True: 16, False: 3.18k]
  ------------------
  296|     16|        retval = READSTAT_ERROR_PARSE;
  297|     16|        goto cleanup;
  298|     16|    }
  299|       |    
  300|  3.18k|    if (io->seek(8, READSTAT_SEEK_CUR, io->io_ctx) == -1) {
  ------------------
  |  Branch (300:9): [True: 72, False: 3.11k]
  ------------------
  301|     72|        retval = READSTAT_ERROR_SEEK;
  302|     72|        if (error_handler) {
  ------------------
  |  Branch (302:13): [True: 0, False: 72]
  ------------------
  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|     72|        goto cleanup;
  307|     72|    }
  308|  3.11k|    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.09k]
  ------------------
  309|     17|        retval = READSTAT_ERROR_READ;
  310|     17|        goto cleanup;
  311|     17|    }
  312|  3.09k|    char major, revision_tag;
  313|  3.09k|    int minor, revision;
  314|  3.09k|    if (sscanf(header_end.release, "%c.%04d%c%1d", &major, &minor, &revision_tag, &revision) != 4) {
  ------------------
  |  Branch (314:9): [True: 3, False: 3.09k]
  ------------------
  315|      3|        retval = READSTAT_ERROR_PARSE;
  316|      3|        goto cleanup;
  317|      3|    }
  318|       |
  319|  3.09k|    if (major >= '1' && major <= '9') {
  ------------------
  |  Branch (319:9): [True: 3.07k, False: 14]
  |  Branch (319:25): [True: 3.06k, False: 12]
  ------------------
  320|  3.06k|        hinfo->major_version = major - '0';
  321|  3.06k|    } else if (major == 'V') {
  ------------------
  |  Branch (321:16): [True: 4, False: 22]
  ------------------
  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|      4|        hinfo->major_version = 9;
  325|     22|    } else {
  326|     22|        retval = READSTAT_ERROR_PARSE;
  327|     22|        goto cleanup;
  328|     22|    }
  329|       |    // revision_tag is usually M, but J has been observed in the wild (not created with SAS?)
  330|  3.07k|    if (revision_tag != 'M' && revision_tag != 'J') {
  ------------------
  |  Branch (330:9): [True: 22, False: 3.04k]
  |  Branch (330:32): [True: 15, False: 7]
  ------------------
  331|     15|        retval = READSTAT_ERROR_PARSE;
  332|     15|        goto cleanup;
  333|     15|    }
  334|  3.05k|    hinfo->minor_version = minor;
  335|  3.05k|    hinfo->revision = revision;
  336|       |
  337|  3.05k|    if ((major == '8' || major == '9') && minor == 0 && revision == 0) {
  ------------------
  |  Branch (337:10): [True: 279, False: 2.77k]
  |  Branch (337:26): [True: 153, False: 2.62k]
  |  Branch (337:43): [True: 80, False: 352]
  |  Branch (337:57): [True: 59, False: 21]
  ------------------
  338|       |        /* A bit of a hack, but most SAS installations are running a minor update */
  339|     59|        hinfo->vendor = READSTAT_VENDOR_STAT_TRANSFER;
  340|  2.99k|    } else {
  341|  2.99k|        hinfo->vendor = READSTAT_VENDOR_SAS;
  342|  2.99k|    }
  343|  3.05k|    if (io->seek(hinfo->header_size, READSTAT_SEEK_SET, io->io_ctx) == -1) {
  ------------------
  |  Branch (343:9): [True: 50, False: 3.00k]
  ------------------
  344|     50|        retval = READSTAT_ERROR_SEEK;
  345|     50|        if (error_handler) {
  ------------------
  |  Branch (345:13): [True: 0, False: 50]
  ------------------
  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|     50|        goto cleanup;
  351|     50|    }
  352|       |
  353|  3.51k|cleanup:
  354|  3.51k|    return retval;
  355|  3.05k|}
sas_validate_tag:
  507|  8.65k|readstat_error_t sas_validate_tag(char tag) {
  508|  8.65k|    if (tag == '_' || (tag >= 'A' && tag <= 'Z'))
  ------------------
  |  Branch (508:9): [True: 4.26k, False: 4.39k]
  |  Branch (508:24): [True: 1.52k, False: 2.86k]
  |  Branch (508:38): [True: 950, False: 577]
  ------------------
  509|  5.21k|        return READSTAT_OK;
  510|       |
  511|  3.44k|    return READSTAT_ERROR_TAGGED_VALUE_IS_OUT_OF_RANGE;
  512|  8.65k|}
sas_assign_tag:
  514|  8.65k|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.65k|    if (tag == 0) {
  ------------------
  |  Branch (521:9): [True: 4.26k, False: 4.39k]
  ------------------
  522|  4.26k|        tag = '_';
  523|  4.39k|    } else if (tag >= 2 && tag < 28) {
  ------------------
  |  Branch (523:16): [True: 3.86k, False: 530]
  |  Branch (523:28): [True: 879, False: 2.98k]
  ------------------
  524|    879|        tag = 'A' + (tag - 2);
  525|    879|    }
  526|  8.65k|    if (sas_validate_tag(tag) == READSTAT_OK) {
  ------------------
  |  Branch (526:9): [True: 5.21k, False: 3.44k]
  ------------------
  527|  5.21k|        value->tag = tag;
  528|  5.21k|        value->is_tagged_missing = 1;
  529|  5.21k|    } else {
  530|  3.44k|        value->tag = 0;
  531|  3.44k|        value->is_system_missing = 1;
  532|  3.44k|    }
  533|  8.65k|}
readstat_sas.c:sas_epoch:
  123|  3.51k|static time_t sas_epoch(void) {
  124|  3.51k|    return - 3653 * 86400; // seconds between 01-01-1960 and 01-01-1970
  125|  3.51k|}
readstat_sas.c:sas_convert_time:
  127|  6.63k|static time_t sas_convert_time(double time, double time_diff, time_t epoch) {
  128|  6.63k|    time -= time_diff;
  129|  6.63k|    time += epoch;
  130|  6.63k|    if (isnan(time))
  ------------------
  |  Branch (130:9): [True: 778, False: 5.85k]
  ------------------
  131|    778|        return 0;
  132|  5.85k|    if (time > (double)LONG_MAX)
  ------------------
  |  Branch (132:9): [True: 1.57k, False: 4.27k]
  ------------------
  133|  1.57k|        return LONG_MAX;
  134|  4.27k|    if (time < (double)LONG_MIN)
  ------------------
  |  Branch (134:9): [True: 1.12k, False: 3.15k]
  ------------------
  135|  1.12k|        return LONG_MIN;
  136|  3.15k|    return time;
  137|  4.27k|}

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

sas_rle_decompress:
   47|    479|        const void *input_buf, size_t input_len) {
   48|    479|    unsigned char *buffer = (unsigned char *)output_buf;
   49|    479|    unsigned char *output = buffer;
   50|    479|    size_t output_written = 0;
   51|       |
   52|    479|    const unsigned char *input = (const unsigned char *)input_buf;
   53|       |
   54|  36.5k|    while (input < (const unsigned char *)input_buf + input_len) {
  ------------------
  |  Branch (54:12): [True: 36.2k, False: 359]
  ------------------
   55|  36.2k|        unsigned char control = *input++;
   56|  36.2k|        unsigned char command = (control & 0xF0) >> 4;
   57|  36.2k|        unsigned char length = (control & 0x0F);
   58|  36.2k|        int copy_len = 0;
   59|  36.2k|        int insert_len = 0;
   60|  36.2k|        unsigned char insert_byte = '\0';
   61|  36.2k|        if (input + command_lengths[command] > (const unsigned char *)input_buf + input_len) {
  ------------------
  |  Branch (61:13): [True: 5, False: 36.2k]
  ------------------
   62|      5|            return -1;
   63|      5|        }
   64|  36.2k|        switch (command) {
   65|  3.00k|            case SAS_RLE_COMMAND_COPY64:
  ------------------
  |  |   13|  3.00k|#define SAS_RLE_COMMAND_COPY64          0
  ------------------
  |  Branch (65:13): [True: 3.00k, False: 33.2k]
  ------------------
   66|  3.00k|                copy_len = (*input++) + 64 + length * 256;
   67|  3.00k|                break;
   68|    121|            case SAS_RLE_COMMAND_COPY64_PLUS_4096:
  ------------------
  |  |   14|    121|#define SAS_RLE_COMMAND_COPY64_PLUS_4096 1
  ------------------
  |  Branch (68:13): [True: 121, False: 36.0k]
  ------------------
   69|    121|                copy_len = (*input++) + 64 + length * 256 + 4096;
   70|    121|                break;
   71|    515|            case SAS_RLE_COMMAND_COPY96: copy_len = length + 96; break;
  ------------------
  |  |   15|    515|#define SAS_RLE_COMMAND_COPY96          2
  ------------------
  |  Branch (71:13): [True: 515, False: 35.7k]
  ------------------
   72|    731|            case SAS_RLE_COMMAND_INSERT_BYTE18:
  ------------------
  |  |   16|    731|#define SAS_RLE_COMMAND_INSERT_BYTE18   4
  ------------------
  |  Branch (72:13): [True: 731, False: 35.4k]
  ------------------
   73|    731|                insert_len = (*input++) + 18 + length * 256;
   74|    731|                insert_byte = *input++;
   75|    731|                break;
   76|    900|            case SAS_RLE_COMMAND_INSERT_AT17:
  ------------------
  |  |   17|    900|#define SAS_RLE_COMMAND_INSERT_AT17     5
  ------------------
  |  Branch (76:13): [True: 900, False: 35.3k]
  ------------------
   77|    900|                insert_len = (*input++) + 17 + length * 256;
   78|    900|                insert_byte = '@';
   79|    900|                break;
   80|    741|            case SAS_RLE_COMMAND_INSERT_BLANK17:
  ------------------
  |  |   18|    741|#define SAS_RLE_COMMAND_INSERT_BLANK17  6
  ------------------
  |  Branch (80:13): [True: 741, False: 35.4k]
  ------------------
   81|    741|                insert_len = (*input++) + 17 + length * 256;
   82|    741|                insert_byte = ' ';
   83|    741|                break;
   84|  2.16k|            case SAS_RLE_COMMAND_INSERT_ZERO17:
  ------------------
  |  |   19|  2.16k|#define SAS_RLE_COMMAND_INSERT_ZERO17   7
  ------------------
  |  Branch (84:13): [True: 2.16k, False: 34.0k]
  ------------------
   85|  2.16k|                insert_len = (*input++) + 17 + length * 256;
   86|  2.16k|                insert_byte = '\0';
   87|  2.16k|                break;
   88|    986|            case SAS_RLE_COMMAND_COPY1:  copy_len = length + 1; break;
  ------------------
  |  |   20|    986|#define SAS_RLE_COMMAND_COPY1           8
  ------------------
  |  Branch (88:13): [True: 986, False: 35.2k]
  ------------------
   89|  9.51k|            case SAS_RLE_COMMAND_COPY17: copy_len = length + 17; break;
  ------------------
  |  |   21|  9.51k|#define SAS_RLE_COMMAND_COPY17          9
  ------------------
  |  Branch (89:13): [True: 9.51k, False: 26.6k]
  ------------------
   90|    541|            case SAS_RLE_COMMAND_COPY33: copy_len = length + 33; break;
  ------------------
  |  |   22|    541|#define SAS_RLE_COMMAND_COPY33         10
  ------------------
  |  Branch (90:13): [True: 541, False: 35.6k]
  ------------------
   91|    350|            case SAS_RLE_COMMAND_COPY49: copy_len = length + 49; break;
  ------------------
  |  |   23|    350|#define SAS_RLE_COMMAND_COPY49         11
  ------------------
  |  Branch (91:13): [True: 350, False: 35.8k]
  ------------------
   92|  1.02k|            case SAS_RLE_COMMAND_INSERT_BYTE3:
  ------------------
  |  |   24|  1.02k|#define SAS_RLE_COMMAND_INSERT_BYTE3   12
  ------------------
  |  Branch (92:13): [True: 1.02k, False: 35.1k]
  ------------------
   93|  1.02k|                insert_byte = *input++;
   94|  1.02k|                insert_len = length + 3;
   95|  1.02k|                break;
   96|    727|            case SAS_RLE_COMMAND_INSERT_AT2:
  ------------------
  |  |   25|    727|#define SAS_RLE_COMMAND_INSERT_AT2     13
  ------------------
  |  Branch (96:13): [True: 727, False: 35.4k]
  ------------------
   97|    727|                insert_byte = '@';
   98|    727|                insert_len = length + 2;
   99|    727|                break;
  100|  7.11k|            case SAS_RLE_COMMAND_INSERT_BLANK2:
  ------------------
  |  |   26|  7.11k|#define SAS_RLE_COMMAND_INSERT_BLANK2  14
  ------------------
  |  Branch (100:13): [True: 7.11k, False: 29.1k]
  ------------------
  101|  7.11k|                insert_byte = ' ';
  102|  7.11k|                insert_len = length + 2;
  103|  7.11k|                break;
  104|  5.25k|            case SAS_RLE_COMMAND_INSERT_ZERO2:
  ------------------
  |  |   27|  5.25k|#define SAS_RLE_COMMAND_INSERT_ZERO2   15
  ------------------
  |  Branch (104:13): [True: 5.25k, False: 30.9k]
  ------------------
  105|  5.25k|                insert_byte = '\0';
  106|  5.25k|                insert_len = length + 2;
  107|  5.25k|                break;
  108|  2.52k|            default:
  ------------------
  |  Branch (108:13): [True: 2.52k, False: 33.6k]
  ------------------
  109|       |                /* error out here? */
  110|  2.52k|                break;
  111|  36.2k|        }
  112|  36.2k|        if (copy_len) {
  ------------------
  |  Branch (112:13): [True: 15.0k, False: 21.1k]
  ------------------
  113|  15.0k|            if (output_written + copy_len > output_len) {
  ------------------
  |  Branch (113:17): [True: 28, False: 15.0k]
  ------------------
  114|     28|                return -1;
  115|     28|            }
  116|  15.0k|            if (input + copy_len > (const unsigned char *)input_buf + input_len) {
  ------------------
  |  Branch (116:17): [True: 75, False: 14.9k]
  ------------------
  117|     75|                return -1;
  118|     75|            }
  119|  14.9k|            if (output) {
  ------------------
  |  Branch (119:17): [True: 14.9k, False: 0]
  ------------------
  120|  14.9k|                memcpy(&output[output_written], input, copy_len);
  121|  14.9k|            }
  122|  14.9k|            input += copy_len;
  123|  14.9k|            output_written += copy_len;
  124|  14.9k|        }
  125|  36.1k|        if (insert_len) {
  ------------------
  |  Branch (125:13): [True: 18.6k, False: 17.4k]
  ------------------
  126|  18.6k|            if (output_written + insert_len > output_len) {
  ------------------
  |  Branch (126:17): [True: 12, False: 18.6k]
  ------------------
  127|     12|                return -1;
  128|     12|            }
  129|  18.6k|            if (output) {
  ------------------
  |  Branch (129:17): [True: 18.6k, False: 0]
  ------------------
  130|  18.6k|                memset(&output[output_written], insert_byte, insert_len);
  131|  18.6k|            }
  132|  18.6k|            output_written += insert_len;
  133|  18.6k|        }
  134|  36.1k|    }
  135|       |
  136|    359|    return output_written;
  137|    479|}

rt_open_handler:
    8|  3.51k|int rt_open_handler(const char *path, void *io_ctx) {
    9|  3.51k|    return 0;
   10|  3.51k|}
rt_close_handler:
   12|  3.51k|int rt_close_handler(void *io_ctx) {
   13|  3.51k|    return 0;
   14|  3.51k|}
rt_seek_handler:
   17|  28.8k|        readstat_io_flags_t whence, void *io_ctx) {
   18|  28.8k|    rt_buffer_ctx_t *buffer_ctx = (rt_buffer_ctx_t *)io_ctx;
   19|  28.8k|    readstat_off_t newpos = -1;
   20|  28.8k|    if (whence == READSTAT_SEEK_SET) {
  ------------------
  |  Branch (20:9): [True: 18.8k, False: 10.0k]
  ------------------
   21|  18.8k|        newpos = offset;
   22|  18.8k|    } else if (whence == READSTAT_SEEK_CUR) {
  ------------------
  |  Branch (22:16): [True: 6.53k, False: 3.51k]
  ------------------
   23|  6.53k|        newpos = buffer_ctx->pos + offset;
   24|  6.53k|    } else if (whence == READSTAT_SEEK_END) {
  ------------------
  |  Branch (24:16): [True: 3.51k, False: 0]
  ------------------
   25|  3.51k|        newpos = buffer_ctx->buffer->used + offset;
   26|  3.51k|    }
   27|       |
   28|  28.8k|    if (newpos < 0)
  ------------------
  |  Branch (28:9): [True: 125, False: 28.7k]
  ------------------
   29|    125|        return -1;
   30|       |
   31|  28.7k|    if (newpos > buffer_ctx->buffer->used)
  ------------------
  |  Branch (31:9): [True: 232, False: 28.5k]
  ------------------
   32|    232|        return -1;
   33|       |
   34|  28.5k|    buffer_ctx->pos = newpos;
   35|  28.5k|    return newpos;
   36|  28.7k|}
rt_read_handler:
   38|  50.5k|ssize_t rt_read_handler(void *buf, size_t nbytes, void *io_ctx) {
   39|  50.5k|    rt_buffer_ctx_t *buffer_ctx = (rt_buffer_ctx_t *)io_ctx;
   40|  50.5k|    ssize_t bytes_copied = 0;
   41|  50.5k|    ssize_t bytes_left = buffer_ctx->buffer->used - buffer_ctx->pos;
   42|  50.5k|    if (nbytes <= bytes_left) {
  ------------------
  |  Branch (42:9): [True: 50.1k, False: 418]
  ------------------
   43|  50.1k|        memcpy(buf, buffer_ctx->buffer->bytes + buffer_ctx->pos, nbytes);
   44|  50.1k|        bytes_copied = nbytes;
   45|  50.1k|    } else if (bytes_left > 0) {
  ------------------
  |  Branch (45:16): [True: 210, False: 208]
  ------------------
   46|    210|        memcpy(buf, buffer_ctx->buffer->bytes + buffer_ctx->pos, bytes_left);
   47|    210|        bytes_copied = bytes_left;
   48|    210|    }
   49|  50.5k|    buffer_ctx->pos += bytes_copied;
   50|  50.5k|    return bytes_copied;
   51|  50.5k|}
rt_update_handler:
   54|  4.34k|        void *user_ctx, void *io_ctx) {
   55|  4.34k|    if (!progress_handler)
  ------------------
  |  Branch (55:9): [True: 4.34k, False: 0]
  ------------------
   56|  4.34k|        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|}

