fuzzer_parser_init:
   33|  1.80k|readstat_parser_t *fuzzer_parser_init(const uint8_t *Data, size_t Size) {
   34|  1.80k|    readstat_parser_t *parser = readstat_parser_init();
   35|  1.80k|    readstat_set_open_handler(parser, rt_open_handler);
   36|  1.80k|    readstat_set_close_handler(parser, rt_close_handler);
   37|  1.80k|    readstat_set_seek_handler(parser, rt_seek_handler);
   38|  1.80k|    readstat_set_read_handler(parser, rt_read_handler);
   39|  1.80k|    readstat_set_update_handler(parser, rt_update_handler);
   40|       |
   41|  1.80k|    readstat_set_metadata_handler(parser, &handle_metadata);
   42|  1.80k|    readstat_set_note_handler(parser, &handle_note);
   43|  1.80k|    readstat_set_variable_handler(parser, &handle_variable);
   44|  1.80k|    readstat_set_fweight_handler(parser, &handle_fweight);
   45|  1.80k|    readstat_set_value_handler(parser, &handle_value);
   46|  1.80k|    readstat_set_value_label_handler(parser, &handle_value_label);
   47|       |
   48|  1.80k|    return parser;
   49|  1.80k|}
fuzz_format.c:handle_metadata:
    8|  1.24k|static int handle_metadata(readstat_metadata_t *metadata, void *ctx) {
    9|  1.24k|    return READSTAT_HANDLER_OK;
   10|  1.24k|}
fuzz_format.c:handle_value_label:
   29|  29.0k|static int handle_value_label(const char *val_labels, readstat_value_t value, const char *label, void *ctx) {
   30|  29.0k|    return READSTAT_HANDLER_OK;
   31|  29.0k|}

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

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

readstat_convert:
    7|  34.7k|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|   188k|    while (src_len && (src[src_len-1] == ' ' || src[src_len-1] == '\0')) {
  ------------------
  |  Branch (10:12): [True: 158k, False: 29.3k]
  |  Branch (10:24): [True: 1.30k, False: 157k]
  |  Branch (10:49): [True: 152k, False: 5.42k]
  ------------------
   11|   153k|        src_len--;
   12|   153k|    }
   13|  34.7k|    if (dst_len == 0) {
  ------------------
  |  Branch (13:9): [True: 0, False: 34.7k]
  ------------------
   14|      0|        return READSTAT_ERROR_CONVERT_LONG_STRING;
   15|  34.7k|    } else if (converter) {
  ------------------
  |  Branch (15:16): [True: 6.44k, False: 28.3k]
  ------------------
   16|  6.44k|        size_t dst_left = dst_len - 1;
   17|  6.44k|        char *dst_end = dst;
   18|  6.44k|        size_t status = iconv(converter, (readstat_iconv_inbuf_t)&src, &src_len, &dst_end, &dst_left);
   19|  6.44k|        if (status == (size_t)-1) {
  ------------------
  |  Branch (19:13): [True: 418, False: 6.02k]
  ------------------
   20|    418|            if (errno == E2BIG) {
  ------------------
  |  Branch (20:17): [True: 1, False: 417]
  ------------------
   21|      1|                return READSTAT_ERROR_CONVERT_LONG_STRING;
   22|    417|            } else if (errno == EILSEQ) {
  ------------------
  |  Branch (22:24): [True: 43, False: 374]
  ------------------
   23|     43|                return READSTAT_ERROR_CONVERT_BAD_STRING;
   24|    374|            } else if (errno != EINVAL) { /* EINVAL indicates improper truncation; accept it */
  ------------------
  |  Branch (24:24): [True: 0, False: 374]
  ------------------
   25|      0|                return READSTAT_ERROR_CONVERT;
   26|      0|            }
   27|    418|        }
   28|  6.40k|        dst[dst_len - dst_left - 1] = '\0';
   29|  28.3k|    } else if (src_len + 1 > dst_len) {
  ------------------
  |  Branch (29:16): [True: 0, False: 28.3k]
  ------------------
   30|      0|        return READSTAT_ERROR_CONVERT_LONG_STRING;
   31|  28.3k|    } else {
   32|  28.3k|        memcpy(dst, src, src_len);
   33|  28.3k|        dst[src_len] = '\0';
   34|  28.3k|    }
   35|  34.7k|    return READSTAT_OK;
   36|  34.7k|}

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

readstat_malloc:
   10|  1.24k|void *readstat_malloc(size_t len) {
   11|  1.24k|    if (len > MAX_MALLOC_SIZE || len == 0) {
  ------------------
  |  |    3|  2.49k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
  |  Branch (11:9): [True: 0, False: 1.24k]
  |  Branch (11:34): [True: 0, False: 1.24k]
  ------------------
   12|      0|        return NULL;
   13|      0|    }
   14|  1.24k|    return malloc(len);
   15|  1.24k|}
readstat_calloc:
   17|  1.58k|void *readstat_calloc(size_t count, size_t size) {
   18|  1.58k|    if (count > MAX_MALLOC_SIZE || size > MAX_MALLOC_SIZE || count * size > MAX_MALLOC_SIZE) {
  ------------------
  |  |    3|  3.16k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
                  if (count > MAX_MALLOC_SIZE || size > MAX_MALLOC_SIZE || count * size > MAX_MALLOC_SIZE) {
  ------------------
  |  |    3|  3.04k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
                  if (count > MAX_MALLOC_SIZE || size > MAX_MALLOC_SIZE || count * size > MAX_MALLOC_SIZE) {
  ------------------
  |  |    3|  1.45k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
  |  Branch (18:9): [True: 124, False: 1.45k]
  |  Branch (18:36): [True: 0, False: 1.45k]
  |  Branch (18:62): [True: 32, False: 1.42k]
  ------------------
   19|    156|        return NULL;
   20|    156|    }
   21|  1.42k|    if (count == 0 || size == 0) {
  ------------------
  |  Branch (21:9): [True: 8, False: 1.41k]
  |  Branch (21:23): [True: 0, False: 1.41k]
  ------------------
   22|      8|        return NULL;
   23|      8|    }
   24|  1.41k|    return calloc(count, size);
   25|  1.42k|}
readstat_realloc:
   27|  3.70k|void *readstat_realloc(void *ptr, size_t len) {
   28|  3.70k|    if (len > MAX_MALLOC_SIZE || len == 0) {
  ------------------
  |  |    3|  7.41k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
  |  Branch (28:9): [True: 3, False: 3.70k]
  |  Branch (28:34): [True: 0, False: 3.70k]
  ------------------
   29|      3|        if (ptr)
  ------------------
  |  Branch (29:13): [True: 2, False: 1]
  ------------------
   30|      2|            free(ptr);
   31|      3|        return NULL;
   32|      3|    }
   33|  3.70k|    return realloc(ptr, len);
   34|  3.70k|}

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

sas_read8:
  139|  30.3k|uint64_t sas_read8(const char *data, int bswap) {
  140|  30.3k|    uint64_t tmp;
  141|  30.3k|    memcpy(&tmp, data, 8);
  142|  30.3k|    return bswap ? byteswap8(tmp) : tmp;
  ------------------
  |  Branch (142:12): [True: 28.5k, False: 1.81k]
  ------------------
  143|  30.3k|}
sas_read4:
  145|   227k|uint32_t sas_read4(const char *data, int bswap) {
  146|   227k|    uint32_t tmp;
  147|   227k|    memcpy(&tmp, data, 4);
  148|   227k|    return bswap ? byteswap4(tmp) : tmp;
  ------------------
  |  Branch (148:12): [True: 5.62k, False: 221k]
  ------------------
  149|   227k|}
sas_read2:
  151|  9.31M|uint16_t sas_read2(const char *data, int bswap) {
  152|  9.31M|    uint16_t tmp;
  153|  9.31M|    memcpy(&tmp, data, 2);
  154|  9.31M|    return bswap ? byteswap2(tmp) : tmp;
  ------------------
  |  Branch (154:12): [True: 13.4k, False: 9.29M]
  ------------------
  155|  9.31M|}
sas_read_header:
  162|  1.80k|        readstat_error_handler error_handler, void *user_ctx) {
  163|  1.80k|    sas_header_start_t  header_start;
  164|  1.80k|    sas_header_end_t    header_end;
  165|  1.80k|    int retval = READSTAT_OK;
  166|  1.80k|    char error_buf[1024];
  167|  1.80k|    time_t epoch = sas_epoch();
  168|       |
  169|  1.80k|    if (io->read(&header_start, sizeof(sas_header_start_t), io->io_ctx) < sizeof(sas_header_start_t)) {
  ------------------
  |  Branch (169:9): [True: 20, False: 1.78k]
  ------------------
  170|     20|        retval = READSTAT_ERROR_READ;
  171|     20|        goto cleanup;
  172|     20|    }
  173|  1.78k|    if (memcmp(header_start.magic, sas7bdat_magic_number, sizeof(sas7bdat_magic_number)) != 0 &&
  ------------------
  |  Branch (173:9): [True: 999, False: 788]
  ------------------
  174|    999|            memcmp(header_start.magic, sas7bcat_magic_number, sizeof(sas7bcat_magic_number)) != 0) {
  ------------------
  |  Branch (174:13): [True: 130, False: 869]
  ------------------
  175|    130|        retval = READSTAT_ERROR_PARSE;
  176|    130|        goto cleanup;
  177|    130|    }
  178|  1.65k|    if (header_start.a1 == SAS_ALIGNMENT_OFFSET_4) {
  ------------------
  |  |   87|  1.65k|#define SAS_ALIGNMENT_OFFSET_4  0x33
  ------------------
  |  Branch (178:9): [True: 11, False: 1.64k]
  ------------------
  179|     11|        hinfo->pad1 = 4;
  180|     11|    }
  181|  1.65k|    if (header_start.a2 == SAS_ALIGNMENT_OFFSET_4) {
  ------------------
  |  |   87|  1.65k|#define SAS_ALIGNMENT_OFFSET_4  0x33
  ------------------
  |  Branch (181:9): [True: 409, False: 1.24k]
  ------------------
  182|    409|        hinfo->u64 = 1;
  183|    409|    }
  184|  1.65k|    int bswap = 0;
  185|  1.65k|    if (header_start.endian == SAS_ENDIAN_BIG) {
  ------------------
  |  |   80|  1.65k|#define SAS_ENDIAN_BIG       0x00
  ------------------
  |  Branch (185:9): [True: 408, False: 1.24k]
  ------------------
  186|    408|        bswap = machine_is_little_endian();
  187|    408|        hinfo->little_endian = 0;
  188|  1.24k|    } else if (header_start.endian == SAS_ENDIAN_LITTLE) {
  ------------------
  |  |   81|  1.24k|#define SAS_ENDIAN_LITTLE    0x01
  ------------------
  |  Branch (188:16): [True: 1.23k, False: 11]
  ------------------
  189|  1.23k|        bswap = !machine_is_little_endian();
  190|  1.23k|        hinfo->little_endian = 1;
  191|  1.23k|    } else {
  192|     11|        retval = READSTAT_ERROR_PARSE;
  193|     11|        goto cleanup;
  194|     11|    }
  195|  1.64k|    int i;
  196|  17.8k|    for (i=0; i<sizeof(_charset_table)/sizeof(_charset_table[0]); i++) {
  ------------------
  |  Branch (196:15): [True: 17.8k, False: 8]
  ------------------
  197|  17.8k|        if (header_start.encoding == _charset_table[i].code) {
  ------------------
  |  Branch (197:13): [True: 1.63k, False: 16.2k]
  ------------------
  198|  1.63k|            hinfo->encoding = _charset_table[i].name;
  199|  1.63k|            break;
  200|  1.63k|        }
  201|  17.8k|    }
  202|  1.64k|    if (hinfo->encoding == NULL) {
  ------------------
  |  Branch (202:9): [True: 8, False: 1.63k]
  ------------------
  203|      8|        if (error_handler) {
  ------------------
  |  Branch (203:13): [True: 0, False: 8]
  ------------------
  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|      8|        retval = READSTAT_ERROR_UNSUPPORTED_CHARSET;
  208|      8|        goto cleanup;
  209|      8|    }
  210|  1.63k|    memcpy(hinfo->table_name, header_start.table_name, sizeof(header_start.table_name));
  211|  1.63k|    if (io->seek(hinfo->pad1, READSTAT_SEEK_CUR, io->io_ctx) == -1) {
  ------------------
  |  Branch (211:9): [True: 5, False: 1.63k]
  ------------------
  212|      5|        retval = READSTAT_ERROR_SEEK;
  213|      5|        goto cleanup;
  214|      5|    }
  215|       |
  216|  1.63k|    double creation_time, modification_time, creation_time_diff, modification_time_diff;
  217|       |
  218|  1.63k|    if (io->read(&creation_time, sizeof(double), io->io_ctx) < sizeof(double)) {
  ------------------
  |  Branch (218:9): [True: 12, False: 1.62k]
  ------------------
  219|     12|        retval = READSTAT_ERROR_READ;
  220|     12|        goto cleanup;
  221|     12|    }
  222|  1.62k|    if (bswap)
  ------------------
  |  Branch (222:9): [True: 394, False: 1.22k]
  ------------------
  223|    394|        creation_time = byteswap_double(creation_time);
  224|       |
  225|  1.62k|    if (io->read(&modification_time, sizeof(double), io->io_ctx) < sizeof(double)) {
  ------------------
  |  Branch (225:9): [True: 7, False: 1.61k]
  ------------------
  226|      7|        retval = READSTAT_ERROR_READ;
  227|      7|        goto cleanup;
  228|      7|    }
  229|  1.61k|    if (bswap)
  ------------------
  |  Branch (229:9): [True: 390, False: 1.22k]
  ------------------
  230|    390|        modification_time = byteswap_double(modification_time);
  231|       |
  232|  1.61k|    if (io->read(&creation_time_diff, sizeof(double), io->io_ctx) < sizeof(double)) {
  ------------------
  |  Branch (232:9): [True: 6, False: 1.60k]
  ------------------
  233|      6|        retval = READSTAT_ERROR_READ;
  234|      6|        goto cleanup;
  235|      6|    }
  236|  1.60k|    if (bswap)
  ------------------
  |  Branch (236:9): [True: 385, False: 1.22k]
  ------------------
  237|    385|        creation_time_diff = byteswap_double(creation_time_diff);
  238|       |    
  239|  1.60k|    if (io->read(&modification_time_diff, sizeof(double), io->io_ctx) < sizeof(double)) {
  ------------------
  |  Branch (239:9): [True: 7, False: 1.60k]
  ------------------
  240|      7|        retval = READSTAT_ERROR_READ;
  241|      7|        goto cleanup;
  242|      7|    }
  243|  1.60k|    if (bswap)
  ------------------
  |  Branch (243:9): [True: 381, False: 1.22k]
  ------------------
  244|    381|        modification_time_diff = byteswap_double(modification_time_diff);
  245|       |    
  246|  1.60k|    hinfo->creation_time = sas_convert_time(creation_time, creation_time_diff, epoch);
  247|  1.60k|    hinfo->modification_time = sas_convert_time(modification_time, modification_time_diff, epoch);
  248|       |
  249|  1.60k|    uint32_t header_size, page_size;
  250|       |
  251|  1.60k|    if (io->read(&header_size, sizeof(uint32_t), io->io_ctx) < sizeof(uint32_t)) {
  ------------------
  |  Branch (251:9): [True: 9, False: 1.59k]
  ------------------
  252|      9|        retval = READSTAT_ERROR_READ;
  253|      9|        goto cleanup;
  254|      9|    }
  255|  1.59k|    if (io->read(&page_size, sizeof(uint32_t), io->io_ctx) < sizeof(uint32_t)) {
  ------------------
  |  Branch (255:9): [True: 3, False: 1.58k]
  ------------------
  256|      3|        retval = READSTAT_ERROR_READ;
  257|      3|        goto cleanup;
  258|      3|    }
  259|       |
  260|  1.58k|    hinfo->header_size = bswap ? byteswap4(header_size) : header_size;
  ------------------
  |  Branch (260:26): [True: 373, False: 1.21k]
  ------------------
  261|  1.58k|    hinfo->page_size = bswap ? byteswap4(page_size) : page_size;
  ------------------
  |  Branch (261:24): [True: 373, False: 1.21k]
  ------------------
  262|       |
  263|  1.58k|    if (hinfo->header_size < 1024 || hinfo->page_size < 1024) {
  ------------------
  |  Branch (263:9): [True: 12, False: 1.57k]
  |  Branch (263:38): [True: 12, False: 1.56k]
  ------------------
  264|     24|        retval = READSTAT_ERROR_PARSE;
  265|     24|        goto cleanup;
  266|     24|    }
  267|  1.56k|    if (hinfo->header_size > (1<<24) || hinfo->page_size > (1<<24)) {
  ------------------
  |  Branch (267:9): [True: 29, False: 1.53k]
  |  Branch (267:41): [True: 31, False: 1.50k]
  ------------------
  268|     60|        retval = READSTAT_ERROR_PARSE;
  269|     60|        goto cleanup;
  270|     60|    }
  271|       |
  272|  1.50k|    if (hinfo->u64) {
  ------------------
  |  Branch (272:9): [True: 374, False: 1.13k]
  ------------------
  273|    374|        hinfo->page_header_size = SAS_PAGE_HEADER_SIZE_64BIT;
  ------------------
  |  |  121|    374|#define SAS_PAGE_HEADER_SIZE_64BIT  40
  ------------------
  274|    374|        hinfo->subheader_pointer_size = SAS_SUBHEADER_POINTER_SIZE_64BIT;
  ------------------
  |  |  118|    374|#define SAS_SUBHEADER_POINTER_SIZE_64BIT    24
  ------------------
  275|  1.13k|    } else {
  276|  1.13k|        hinfo->page_header_size = SAS_PAGE_HEADER_SIZE_32BIT;
  ------------------
  |  |  120|  1.13k|#define SAS_PAGE_HEADER_SIZE_32BIT  24
  ------------------
  277|  1.13k|        hinfo->subheader_pointer_size = SAS_SUBHEADER_POINTER_SIZE_32BIT;
  ------------------
  |  |  117|  1.13k|#define SAS_SUBHEADER_POINTER_SIZE_32BIT    12
  ------------------
  278|  1.13k|    }
  279|       |
  280|  1.50k|    if (hinfo->u64) {
  ------------------
  |  Branch (280:9): [True: 374, False: 1.13k]
  ------------------
  281|    374|        uint64_t page_count;
  282|    374|        if (io->read(&page_count, sizeof(uint64_t), io->io_ctx) < sizeof(uint64_t)) {
  ------------------
  |  Branch (282:13): [True: 18, False: 356]
  ------------------
  283|     18|            retval = READSTAT_ERROR_READ;
  284|     18|            goto cleanup;
  285|     18|        }
  286|    356|        hinfo->page_count = bswap ? byteswap8(page_count) : page_count;
  ------------------
  |  Branch (286:29): [True: 29, False: 327]
  ------------------
  287|  1.13k|    } else {
  288|  1.13k|        uint32_t page_count;
  289|  1.13k|        if (io->read(&page_count, sizeof(uint32_t), io->io_ctx) < sizeof(uint32_t)) {
  ------------------
  |  Branch (289:13): [True: 26, False: 1.10k]
  ------------------
  290|     26|            retval = READSTAT_ERROR_READ;
  291|     26|            goto cleanup;
  292|     26|        }
  293|  1.10k|        hinfo->page_count = bswap ? byteswap4(page_count) : page_count;
  ------------------
  |  Branch (293:29): [True: 275, False: 830]
  ------------------
  294|  1.10k|    }
  295|  1.46k|    if (hinfo->page_count > (1<<24)) {
  ------------------
  |  Branch (295:9): [True: 13, False: 1.44k]
  ------------------
  296|     13|        retval = READSTAT_ERROR_PARSE;
  297|     13|        goto cleanup;
  298|     13|    }
  299|       |    
  300|  1.44k|    if (io->seek(8, READSTAT_SEEK_CUR, io->io_ctx) == -1) {
  ------------------
  |  Branch (300:9): [True: 84, False: 1.36k]
  ------------------
  301|     84|        retval = READSTAT_ERROR_SEEK;
  302|     84|        if (error_handler) {
  ------------------
  |  Branch (302:13): [True: 0, False: 84]
  ------------------
  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|     84|        goto cleanup;
  307|     84|    }
  308|  1.36k|    if (io->read(&header_end, sizeof(sas_header_end_t), io->io_ctx) < sizeof(sas_header_end_t)) {
  ------------------
  |  Branch (308:9): [True: 17, False: 1.34k]
  ------------------
  309|     17|        retval = READSTAT_ERROR_READ;
  310|     17|        goto cleanup;
  311|     17|    }
  312|  1.34k|    char major, revision_tag;
  313|  1.34k|    int minor, revision;
  314|  1.34k|    if (sscanf(header_end.release, "%c.%04d%c%1d", &major, &minor, &revision_tag, &revision) != 4) {
  ------------------
  |  Branch (314:9): [True: 3, False: 1.34k]
  ------------------
  315|      3|        retval = READSTAT_ERROR_PARSE;
  316|      3|        goto cleanup;
  317|      3|    }
  318|       |
  319|  1.34k|    if (major >= '1' && major <= '9') {
  ------------------
  |  Branch (319:9): [True: 1.33k, False: 11]
  |  Branch (319:25): [True: 1.31k, False: 15]
  ------------------
  320|  1.31k|        hinfo->major_version = major - '0';
  321|  1.31k|    } else if (major == 'V') {
  ------------------
  |  Branch (321:16): [True: 7, False: 19]
  ------------------
  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|      7|        hinfo->major_version = 9;
  325|     19|    } else {
  326|     19|        retval = READSTAT_ERROR_PARSE;
  327|     19|        goto cleanup;
  328|     19|    }
  329|       |    // revision_tag is usually M, but J has been observed in the wild (not created with SAS?)
  330|  1.32k|    if (revision_tag != 'M' && revision_tag != 'J') {
  ------------------
  |  Branch (330:9): [True: 21, False: 1.30k]
  |  Branch (330:32): [True: 14, False: 7]
  ------------------
  331|     14|        retval = READSTAT_ERROR_PARSE;
  332|     14|        goto cleanup;
  333|     14|    }
  334|  1.31k|    hinfo->minor_version = minor;
  335|  1.31k|    hinfo->revision = revision;
  336|       |
  337|  1.31k|    if ((major == '8' || major == '9') && minor == 0 && revision == 0) {
  ------------------
  |  Branch (337:10): [True: 269, False: 1.04k]
  |  Branch (337:26): [True: 169, False: 873]
  |  Branch (337:43): [True: 13, False: 425]
  |  Branch (337:57): [True: 3, False: 10]
  ------------------
  338|       |        /* A bit of a hack, but most SAS installations are running a minor update */
  339|      3|        hinfo->vendor = READSTAT_VENDOR_STAT_TRANSFER;
  340|  1.30k|    } else {
  341|  1.30k|        hinfo->vendor = READSTAT_VENDOR_SAS;
  342|  1.30k|    }
  343|  1.31k|    if (io->seek(hinfo->header_size, READSTAT_SEEK_SET, io->io_ctx) == -1) {
  ------------------
  |  Branch (343:9): [True: 61, False: 1.25k]
  ------------------
  344|     61|        retval = READSTAT_ERROR_SEEK;
  345|     61|        if (error_handler) {
  ------------------
  |  Branch (345:13): [True: 0, False: 61]
  ------------------
  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|     61|        goto cleanup;
  351|     61|    }
  352|       |
  353|  1.80k|cleanup:
  354|  1.80k|    return retval;
  355|  1.31k|}
sas_validate_tag:
  507|  1.73k|readstat_error_t sas_validate_tag(char tag) {
  508|  1.73k|    if (tag == '_' || (tag >= 'A' && tag <= 'Z'))
  ------------------
  |  Branch (508:9): [True: 374, False: 1.35k]
  |  Branch (508:24): [True: 588, False: 770]
  |  Branch (508:38): [True: 341, False: 247]
  ------------------
  509|    715|        return READSTAT_OK;
  510|       |
  511|  1.01k|    return READSTAT_ERROR_TAGGED_VALUE_IS_OUT_OF_RANGE;
  512|  1.73k|}
sas_assign_tag:
  514|  1.73k|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|  1.73k|    if (tag == 0) {
  ------------------
  |  Branch (521:9): [True: 373, False: 1.35k]
  ------------------
  522|    373|        tag = '_';
  523|  1.35k|    } else if (tag >= 2 && tag < 28) {
  ------------------
  |  Branch (523:16): [True: 1.02k, False: 336]
  |  Branch (523:28): [True: 335, False: 688]
  ------------------
  524|    335|        tag = 'A' + (tag - 2);
  525|    335|    }
  526|  1.73k|    if (sas_validate_tag(tag) == READSTAT_OK) {
  ------------------
  |  Branch (526:9): [True: 715, False: 1.01k]
  ------------------
  527|    715|        value->tag = tag;
  528|    715|        value->is_tagged_missing = 1;
  529|  1.01k|    } else {
  530|  1.01k|        value->tag = 0;
  531|  1.01k|        value->is_system_missing = 1;
  532|  1.01k|    }
  533|  1.73k|}
readstat_sas.c:sas_epoch:
  123|  1.80k|static time_t sas_epoch(void) {
  124|  1.80k|    return - 3653 * 86400; // seconds between 01-01-1960 and 01-01-1970
  125|  1.80k|}
readstat_sas.c:sas_convert_time:
  127|  3.20k|static time_t sas_convert_time(double time, double time_diff, time_t epoch) {
  128|  3.20k|    time -= time_diff;
  129|  3.20k|    time += epoch;
  130|  3.20k|    if (isnan(time))
  ------------------
  |  Branch (130:9): [True: 99, False: 3.10k]
  ------------------
  131|     99|        return 0;
  132|  3.10k|    if (time > (double)LONG_MAX)
  ------------------
  |  Branch (132:9): [True: 253, False: 2.85k]
  ------------------
  133|    253|        return LONG_MAX;
  134|  2.85k|    if (time < (double)LONG_MIN)
  ------------------
  |  Branch (134:9): [True: 320, False: 2.53k]
  ------------------
  135|    320|        return LONG_MIN;
  136|  2.53k|    return time;
  137|  2.85k|}

readstat_parse_sas7bcat:
  376|  1.80k|readstat_error_t readstat_parse_sas7bcat(readstat_parser_t *parser, const char *path, void *user_ctx) {
  377|  1.80k|    readstat_error_t retval = READSTAT_OK;
  378|  1.80k|    readstat_io_t *io = parser->io;
  379|  1.80k|    int64_t i;
  380|  1.80k|    char *page = NULL;
  381|  1.80k|    char *buffer = NULL;
  382|       |
  383|  1.80k|    sas7bcat_ctx_t *ctx = calloc(1, sizeof(sas7bcat_ctx_t));
  384|  1.80k|    sas_header_info_t *hinfo = calloc(1, sizeof(sas_header_info_t));
  385|       |
  386|  1.80k|    ctx->block_pointers = malloc((ctx->block_pointers_capacity = 200) * sizeof(uint64_t));
  387|       |
  388|  1.80k|    ctx->value_label_handler = parser->handlers.value_label;
  389|  1.80k|    ctx->metadata_handler = parser->handlers.metadata;
  390|  1.80k|    ctx->input_encoding = parser->input_encoding;
  391|  1.80k|    ctx->output_encoding = parser->output_encoding;
  392|  1.80k|    ctx->user_ctx = user_ctx;
  393|  1.80k|    ctx->io = io;
  394|       |
  395|  1.80k|    if (io->open(path, io->io_ctx) == -1) {
  ------------------
  |  Branch (395:9): [True: 0, False: 1.80k]
  ------------------
  396|      0|        retval = READSTAT_ERROR_OPEN;
  397|      0|        goto cleanup;
  398|      0|    }
  399|       |
  400|  1.80k|    if ((retval = sas_read_header(io, hinfo, parser->handlers.error, user_ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (400:9): [True: 557, False: 1.25k]
  ------------------
  401|    557|        goto cleanup;
  402|    557|    }
  403|       |
  404|  1.25k|    ctx->u64 = hinfo->u64;
  405|  1.25k|    ctx->pad1 = hinfo->pad1;
  406|  1.25k|    ctx->bswap = machine_is_little_endian() ^ hinfo->little_endian;
  407|  1.25k|    ctx->header_size = hinfo->header_size;
  408|  1.25k|    ctx->page_count = hinfo->page_count;
  409|  1.25k|    ctx->page_size = hinfo->page_size;
  410|  1.25k|    if (ctx->input_encoding == NULL) {
  ------------------
  |  Branch (410:9): [True: 1.25k, False: 0]
  ------------------
  411|  1.25k|        ctx->input_encoding = hinfo->encoding;
  412|  1.25k|    }
  413|       |
  414|  1.25k|    ctx->xlsr_size = 212 + ctx->pad1;
  415|  1.25k|    ctx->xlsr_offset = 856 + 2 * ctx->pad1;
  416|  1.25k|    ctx->xlsr_O_offset = 50 + ctx->pad1;
  417|  1.25k|    if (ctx->u64) {
  ------------------
  |  Branch (417:9): [True: 294, False: 956]
  ------------------
  418|    294|        ctx->xlsr_offset += 144;
  419|    294|        ctx->xlsr_size += 72;
  420|    294|        ctx->xlsr_O_offset += 24;
  421|    294|    }
  422|       |
  423|  1.25k|    if (ctx->input_encoding && ctx->output_encoding && strcmp(ctx->input_encoding, ctx->output_encoding) != 0) {
  ------------------
  |  Branch (423:9): [True: 1.25k, False: 0]
  |  Branch (423:32): [True: 1.25k, False: 0]
  |  Branch (423:56): [True: 724, False: 526]
  ------------------
  424|    724|        iconv_t converter = iconv_open(ctx->output_encoding, ctx->input_encoding);
  425|    724|        if (converter == (iconv_t)-1) {
  ------------------
  |  Branch (425:13): [True: 2, False: 722]
  ------------------
  426|      2|            retval = READSTAT_ERROR_UNSUPPORTED_CHARSET;
  427|      2|            goto cleanup;
  428|      2|        }
  429|    722|        ctx->converter = converter;
  430|    722|    }
  431|       |
  432|  1.24k|    if (ctx->metadata_handler) {
  ------------------
  |  Branch (432:9): [True: 1.24k, False: 0]
  ------------------
  433|  1.24k|        char table_name[4*32+1];
  434|  1.24k|        readstat_metadata_t metadata = { 
  435|  1.24k|            .file_encoding = ctx->input_encoding, /* orig encoding? */
  436|  1.24k|            .modified_time = hinfo->modification_time,
  437|  1.24k|            .creation_time = hinfo->creation_time,
  438|  1.24k|            .file_format_version = hinfo->major_version,
  439|  1.24k|            .endianness = hinfo->little_endian ? READSTAT_ENDIAN_LITTLE : READSTAT_ENDIAN_BIG,
  ------------------
  |  Branch (439:27): [True: 1.03k, False: 218]
  ------------------
  440|  1.24k|            .is64bit = ctx->u64
  441|  1.24k|        };
  442|  1.24k|        retval = readstat_convert(table_name, sizeof(table_name),
  443|  1.24k|                hinfo->table_name, sizeof(hinfo->table_name), ctx->converter);
  444|  1.24k|        if (retval != READSTAT_OK)
  ------------------
  |  Branch (444:13): [True: 3, False: 1.24k]
  ------------------
  445|      3|            goto cleanup;
  446|       |
  447|  1.24k|        metadata.table_name = table_name;
  448|       |
  449|  1.24k|        if (ctx->metadata_handler(&metadata, ctx->user_ctx) != READSTAT_HANDLER_OK) {
  ------------------
  |  Branch (449:13): [True: 0, False: 1.24k]
  ------------------
  450|      0|            retval = READSTAT_ERROR_USER_ABORT;
  451|      0|            goto cleanup;
  452|      0|        }
  453|  1.24k|    }
  454|       |
  455|  1.24k|    if ((page = readstat_malloc(ctx->page_size)) == NULL) {
  ------------------
  |  Branch (455:9): [True: 0, False: 1.24k]
  ------------------
  456|      0|        retval = READSTAT_ERROR_MALLOC;
  457|      0|        goto cleanup;
  458|      0|    }
  459|  1.24k|    if (io->seek(ctx->header_size+SAS_CATALOG_FIRST_INDEX_PAGE*ctx->page_size, READSTAT_SEEK_SET, io->io_ctx) == -1) {
  ------------------
  |  |   11|  1.24k|#define SAS_CATALOG_FIRST_INDEX_PAGE 1
  ------------------
  |  Branch (459:9): [True: 69, False: 1.17k]
  ------------------
  460|     69|        retval = READSTAT_ERROR_SEEK;
  461|     69|        goto cleanup;
  462|     69|    }
  463|  1.17k|    if (io->read(page, ctx->page_size, io->io_ctx) < ctx->page_size) {
  ------------------
  |  Branch (463:9): [True: 42, False: 1.13k]
  ------------------
  464|     42|        retval = READSTAT_ERROR_READ;
  465|     42|        goto cleanup;
  466|     42|    }
  467|       |
  468|  1.13k|    retval = sas7bcat_augment_index(&page[ctx->xlsr_offset], ctx->page_size - ctx->xlsr_offset, ctx);
  469|  1.13k|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (469:9): [True: 0, False: 1.13k]
  ------------------
  470|      0|        goto cleanup;
  471|       |
  472|       |    // Pass 1 -- find the XLSR entries
  473|  20.9k|    for (i=SAS_CATALOG_USELESS_PAGES; i<ctx->page_count; i++) {
  ------------------
  |  |   12|  1.13k|#define SAS_CATALOG_USELESS_PAGES    3
  ------------------
  |  Branch (473:39): [True: 19.9k, False: 1.03k]
  ------------------
  474|  19.9k|        if (io->seek(ctx->header_size+i*ctx->page_size, READSTAT_SEEK_SET, io->io_ctx) == -1) {
  ------------------
  |  Branch (474:13): [True: 21, False: 19.8k]
  ------------------
  475|     21|            retval = READSTAT_ERROR_SEEK;
  476|     21|            goto cleanup;
  477|     21|        }
  478|  19.8k|        if (io->read(page, ctx->page_size, io->io_ctx) < ctx->page_size) {
  ------------------
  |  Branch (478:13): [True: 80, False: 19.8k]
  ------------------
  479|     80|            retval = READSTAT_ERROR_READ;
  480|     80|            goto cleanup;
  481|     80|        }
  482|  19.8k|        if (memcmp(&page[16], "XLSR", sizeof("XLSR")-1) == 0) {
  ------------------
  |  Branch (482:13): [True: 7.52k, False: 12.2k]
  ------------------
  483|  7.52k|            retval = sas7bcat_augment_index(&page[16], ctx->page_size - 16, ctx);
  484|  7.52k|            if (retval != READSTAT_OK)
  ------------------
  |  Branch (484:17): [True: 0, False: 7.52k]
  ------------------
  485|      0|                goto cleanup;
  486|  7.52k|        }
  487|  19.8k|    }
  488|       |
  489|  1.03k|    sas7bcat_sort_index(ctx);
  490|  1.03k|    sas7bcat_uniq_index(ctx);
  491|       |
  492|       |    // Pass 2 -- look up the individual block pointers
  493|  13.9k|    for (i=0; i<ctx->block_pointers_used; i++) {
  ------------------
  |  Branch (493:15): [True: 13.5k, False: 482]
  ------------------
  494|  13.5k|        int start_page = ctx->block_pointers[i] >> 32;
  495|  13.5k|        int start_page_pos = (ctx->block_pointers[i]) & 0xFFFF;
  496|       |
  497|  13.5k|        int buffer_len = sas7bcat_block_size(start_page, start_page_pos, ctx, &retval);
  498|  13.5k|        if (buffer_len == -1) {
  ------------------
  |  Branch (498:13): [True: 39, False: 13.4k]
  ------------------
  499|     39|            goto cleanup;
  500|  13.4k|        } else if (buffer_len == 0) {
  ------------------
  |  Branch (500:20): [True: 9.82k, False: 3.64k]
  ------------------
  501|  9.82k|            continue;
  502|  9.82k|        }
  503|  3.64k|        if ((buffer = readstat_realloc(buffer, buffer_len)) == NULL) {
  ------------------
  |  Branch (503:13): [True: 3, False: 3.63k]
  ------------------
  504|      3|            retval = READSTAT_ERROR_MALLOC;
  505|      3|            goto cleanup;
  506|      3|        }
  507|  3.63k|        if ((retval = sas7bcat_read_block(buffer, buffer_len, start_page, start_page_pos, ctx)) != READSTAT_OK)
  ------------------
  |  Branch (507:13): [True: 51, False: 3.58k]
  ------------------
  508|     51|            goto cleanup;
  509|  3.58k|        if ((retval = sas7bcat_parse_block(buffer, buffer_len, ctx)) != READSTAT_OK)
  ------------------
  |  Branch (509:13): [True: 458, False: 3.12k]
  ------------------
  510|    458|            goto cleanup;
  511|  3.58k|    }
  512|       |
  513|  1.80k|cleanup:
  514|  1.80k|    io->close(io->io_ctx);
  515|  1.80k|    if (page)
  ------------------
  |  Branch (515:9): [True: 1.24k, False: 562]
  ------------------
  516|  1.24k|        free(page);
  517|  1.80k|    if (buffer)
  ------------------
  |  Branch (517:9): [True: 746, False: 1.06k]
  ------------------
  518|    746|        free(buffer);
  519|  1.80k|    if (ctx)
  ------------------
  |  Branch (519:9): [True: 1.80k, False: 0]
  ------------------
  520|  1.80k|        sas7bcat_ctx_free(ctx);
  521|  1.80k|    if (hinfo)
  ------------------
  |  Branch (521:9): [True: 1.80k, False: 0]
  ------------------
  522|  1.80k|        free(hinfo);
  523|       |
  524|  1.80k|    return retval;
  525|  1.03k|}
readstat_sas7bcat_read.c:sas7bcat_augment_index:
  208|  8.65k|static readstat_error_t sas7bcat_augment_index(const char *index, size_t len, sas7bcat_ctx_t *ctx) {
  209|  8.65k|    const char *xlsr = index;
  210|  8.65k|    readstat_error_t retval = READSTAT_OK;
  211|  36.4k|    while (xlsr + ctx->xlsr_size <= index + len) {
  ------------------
  |  Branch (211:12): [True: 29.2k, False: 7.21k]
  ------------------
  212|  29.2k|        if (memcmp(xlsr, "XLSR", 4) != 0) // some block pointers seem to have 8 bytes of extra padding
  ------------------
  |  Branch (212:13): [True: 14.0k, False: 15.2k]
  ------------------
  213|  14.0k|            xlsr += 8;
  214|  29.2k|        if (memcmp(xlsr, "XLSR", 4) != 0)
  ------------------
  |  Branch (214:13): [True: 1.44k, False: 27.8k]
  ------------------
  215|  1.44k|            break;
  216|       |
  217|  27.8k|        if (xlsr[ctx->xlsr_O_offset] == 'O') {
  ------------------
  |  Branch (217:13): [True: 25.7k, False: 2.13k]
  ------------------
  218|  25.7k|            uint64_t page = 0, pos = 0;
  219|  25.7k|            if (ctx->u64) {
  ------------------
  |  Branch (219:17): [True: 864, False: 24.8k]
  ------------------
  220|    864|                page = sas_read8(&xlsr[8], ctx->bswap);
  221|    864|                pos = sas_read2(&xlsr[16], ctx->bswap);
  222|  24.8k|            } else {
  223|  24.8k|                page = sas_read4(&xlsr[4], ctx->bswap);
  224|  24.8k|                pos = sas_read2(&xlsr[8], ctx->bswap);
  225|  24.8k|            }
  226|  25.7k|            ctx->block_pointers[ctx->block_pointers_used++] = (page << 32) + pos;
  227|  25.7k|        }
  228|       |
  229|  27.8k|        if (ctx->block_pointers_used == ctx->block_pointers_capacity) {
  ------------------
  |  Branch (229:13): [True: 64, False: 27.7k]
  ------------------
  230|     64|            ctx->block_pointers = readstat_realloc(ctx->block_pointers, (ctx->block_pointers_capacity *= 2) * sizeof(uint64_t));
  231|     64|            if (ctx->block_pointers == NULL) {
  ------------------
  |  Branch (231:17): [True: 0, False: 64]
  ------------------
  232|      0|                retval = READSTAT_ERROR_MALLOC;
  233|      0|                goto cleanup;
  234|      0|            }
  235|     64|        }
  236|       |
  237|  27.8k|        xlsr += ctx->xlsr_size;
  238|  27.8k|    }
  239|  8.65k|cleanup:
  240|  8.65k|    return retval;
  241|  8.65k|}
readstat_sas7bcat_read.c:sas7bcat_sort_index:
  249|  1.03k|static void sas7bcat_sort_index(sas7bcat_ctx_t *ctx) {
  250|  1.03k|    if (ctx->block_pointers_used == 0)
  ------------------
  |  Branch (250:9): [True: 116, False: 917]
  ------------------
  251|    116|        return;
  252|       |
  253|    917|    int i;
  254|  1.31k|    for (i=1; i<ctx->block_pointers_used; i++) {
  ------------------
  |  Branch (254:15): [True: 608, False: 710]
  ------------------
  255|    608|        if (ctx->block_pointers[i] < ctx->block_pointers[i-1]) {
  ------------------
  |  Branch (255:13): [True: 207, False: 401]
  ------------------
  256|    207|            qsort(ctx->block_pointers, ctx->block_pointers_used, sizeof(uint64_t), &compare_block_pointers);
  257|    207|            break;
  258|    207|        }
  259|    608|    }
  260|    917|}
readstat_sas7bcat_read.c:compare_block_pointers:
  243|  99.0k|static int compare_block_pointers(const void *elem1, const void *elem2) {
  244|  99.0k|    uint64_t v1 = *(const uint64_t *)elem1;
  245|  99.0k|    uint64_t v2 = *(const uint64_t *)elem2;
  246|  99.0k|    return v1 - v2;
  247|  99.0k|}
readstat_sas7bcat_read.c:sas7bcat_uniq_index:
  262|  1.03k|static void sas7bcat_uniq_index(sas7bcat_ctx_t *ctx) {
  263|  1.03k|    if (ctx->block_pointers_used == 0)
  ------------------
  |  Branch (263:9): [True: 116, False: 917]
  ------------------
  264|    116|        return;
  265|       |
  266|    917|    int i;
  267|    917|    int out_i = 1;
  268|  17.6k|    for (i=1; i<ctx->block_pointers_used; i++) {
  ------------------
  |  Branch (268:15): [True: 16.6k, False: 917]
  ------------------
  269|  16.6k|        if (ctx->block_pointers[i] != ctx->block_pointers[i-1]) {
  ------------------
  |  Branch (269:13): [True: 12.6k, False: 4.04k]
  ------------------
  270|  12.6k|            if (out_i != i) {
  ------------------
  |  Branch (270:17): [True: 11.0k, False: 1.56k]
  ------------------
  271|  11.0k|                ctx->block_pointers[out_i] = ctx->block_pointers[i];
  272|  11.0k|            }
  273|  12.6k|            out_i++;
  274|  12.6k|        }
  275|  16.6k|    }
  276|    917|    ctx->block_pointers_used = out_i;
  277|    917|}
readstat_sas7bcat_read.c:sas7bcat_block_size:
  279|  13.5k|static int sas7bcat_block_size(int start_page, int start_page_pos, sas7bcat_ctx_t *ctx, readstat_error_t *outError) {
  280|  13.5k|    readstat_error_t retval = READSTAT_OK;
  281|  13.5k|    readstat_io_t *io = ctx->io;
  282|  13.5k|    int next_page = start_page;
  283|  13.5k|    int next_page_pos = start_page_pos;
  284|  13.5k|    int link_count = 0;
  285|       |
  286|  13.5k|    int buffer_len = 0;
  287|  13.5k|    int chain_link_len = 0;
  288|       |
  289|  13.5k|    char chain_link[32];
  290|  13.5k|    int chain_link_header_len = 16;
  291|  13.5k|    if (ctx->u64) {
  ------------------
  |  Branch (291:9): [True: 638, False: 12.8k]
  ------------------
  292|    638|        chain_link_header_len = 32;
  293|    638|    }
  294|       |
  295|       |    // calculate buffer size needed
  296|  59.7k|    while (next_page > 0 && next_page_pos > 0 && next_page <= ctx->page_count && link_count++ < ctx->page_count) {
  ------------------
  |  Branch (296:12): [True: 55.2k, False: 4.43k]
  |  Branch (296:29): [True: 54.2k, False: 998]
  |  Branch (296:50): [True: 46.7k, False: 7.52k]
  |  Branch (296:82): [True: 46.2k, False: 516]
  ------------------
  297|  46.2k|        if (io->seek(ctx->header_size+(next_page-1)*ctx->page_size+next_page_pos, READSTAT_SEEK_SET, io->io_ctx) == -1) {
  ------------------
  |  Branch (297:13): [True: 18, False: 46.2k]
  ------------------
  298|     18|            retval = READSTAT_ERROR_SEEK;
  299|     18|            goto cleanup;
  300|     18|        }
  301|  46.2k|        if (io->read(chain_link, chain_link_header_len, io->io_ctx) < chain_link_header_len) {
  ------------------
  |  Branch (301:13): [True: 21, False: 46.2k]
  ------------------
  302|     21|            retval = READSTAT_ERROR_READ;
  303|     21|            goto cleanup;
  304|     21|        }
  305|       |
  306|  46.2k|        if (ctx->u64) {
  ------------------
  |  Branch (306:13): [True: 1.39k, False: 44.8k]
  ------------------
  307|  1.39k|            next_page = sas_read4(&chain_link[0], ctx->bswap);
  308|  1.39k|            next_page_pos = sas_read2(&chain_link[8], ctx->bswap);
  309|  1.39k|            chain_link_len = sas_read2(&chain_link[10], ctx->bswap);
  310|  44.8k|        } else {
  311|  44.8k|            next_page = sas_read4(&chain_link[0], ctx->bswap);
  312|  44.8k|            next_page_pos = sas_read2(&chain_link[4], ctx->bswap);
  313|  44.8k|            chain_link_len = sas_read2(&chain_link[6], ctx->bswap);
  314|  44.8k|        }
  315|       |
  316|  46.2k|        buffer_len += chain_link_len;
  317|  46.2k|    }
  318|       |
  319|  13.5k|cleanup:
  320|  13.5k|    if (outError)
  ------------------
  |  Branch (320:9): [True: 13.5k, False: 0]
  ------------------
  321|  13.5k|        *outError = retval;
  322|       |
  323|  13.5k|    return retval == READSTAT_OK ? buffer_len : -1;
  ------------------
  |  Branch (323:12): [True: 13.4k, False: 39]
  ------------------
  324|  13.5k|}
readstat_sas7bcat_read.c:sas7bcat_read_block:
  327|  3.63k|        int start_page, int start_page_pos, sas7bcat_ctx_t *ctx) {
  328|  3.63k|    readstat_error_t retval = READSTAT_OK;
  329|  3.63k|    readstat_io_t *io = ctx->io;
  330|  3.63k|    int next_page = start_page;
  331|  3.63k|    int next_page_pos = start_page_pos;
  332|  3.63k|    int link_count = 0;
  333|       |
  334|  3.63k|    int chain_link_len = 0;
  335|  3.63k|    int buffer_offset = 0;
  336|       |
  337|  3.63k|    char chain_link[32];
  338|  3.63k|    int chain_link_header_len = 16;
  339|  3.63k|    if (ctx->u64) {
  ------------------
  |  Branch (339:9): [True: 553, False: 3.08k]
  ------------------
  340|    553|        chain_link_header_len = 32;
  341|    553|    }
  342|       |
  343|  47.0k|    while (next_page > 0 && next_page_pos > 0 && next_page <= ctx->page_count && link_count++ < ctx->page_count) {
  ------------------
  |  Branch (343:12): [True: 45.8k, False: 1.23k]
  |  Branch (343:29): [True: 45.1k, False: 685]
  |  Branch (343:50): [True: 43.9k, False: 1.18k]
  |  Branch (343:82): [True: 43.4k, False: 487]
  ------------------
  344|  43.4k|        if (io->seek(ctx->header_size+(next_page-1)*ctx->page_size+next_page_pos, READSTAT_SEEK_SET, io->io_ctx) == -1) {
  ------------------
  |  Branch (344:13): [True: 0, False: 43.4k]
  ------------------
  345|      0|            retval = READSTAT_ERROR_SEEK;
  346|      0|            goto cleanup;
  347|      0|        }
  348|  43.4k|        if (io->read(chain_link, chain_link_header_len, io->io_ctx) < chain_link_header_len) {
  ------------------
  |  Branch (348:13): [True: 0, False: 43.4k]
  ------------------
  349|      0|            retval = READSTAT_ERROR_READ;
  350|      0|            goto cleanup;
  351|      0|        }
  352|  43.4k|        if (ctx->u64) {
  ------------------
  |  Branch (352:13): [True: 1.38k, False: 42.0k]
  ------------------
  353|  1.38k|            next_page = sas_read4(&chain_link[0], ctx->bswap);
  354|  1.38k|            next_page_pos = sas_read2(&chain_link[8], ctx->bswap);
  355|  1.38k|            chain_link_len = sas_read2(&chain_link[10], ctx->bswap);
  356|  42.0k|        } else {
  357|  42.0k|            next_page = sas_read4(&chain_link[0], ctx->bswap);
  358|  42.0k|            next_page_pos = sas_read2(&chain_link[4], ctx->bswap);
  359|  42.0k|            chain_link_len = sas_read2(&chain_link[6], ctx->bswap);
  360|  42.0k|        }
  361|  43.4k|        if (buffer_offset + chain_link_len > buffer_len) {
  ------------------
  |  Branch (361:13): [True: 0, False: 43.4k]
  ------------------
  362|      0|            retval = READSTAT_ERROR_PARSE;
  363|      0|            goto cleanup;
  364|      0|        }
  365|  43.4k|        if (io->read(buffer + buffer_offset, chain_link_len, io->io_ctx) < chain_link_len) {
  ------------------
  |  Branch (365:13): [True: 51, False: 43.4k]
  ------------------
  366|     51|            retval = READSTAT_ERROR_READ;
  367|     51|            goto cleanup;
  368|     51|        }
  369|  43.4k|        buffer_offset += chain_link_len;
  370|  43.4k|    }
  371|  3.63k|cleanup:
  372|       |
  373|  3.63k|    return retval;
  374|  3.63k|}
readstat_sas7bcat_read.c:sas7bcat_parse_block:
  152|  3.58k|static readstat_error_t sas7bcat_parse_block(const char *data, size_t data_size, sas7bcat_ctx_t *ctx) {
  153|  3.58k|    readstat_error_t retval = READSTAT_OK;
  154|       |
  155|  3.58k|    size_t pad = 0;
  156|  3.58k|    uint64_t label_count_capacity = 0;
  157|  3.58k|    uint64_t label_count_used = 0;
  158|  3.58k|    int payload_offset = 106;
  159|  3.58k|    uint16_t flags = 0;
  160|  3.58k|    char name[4*32+1];
  161|       |
  162|  3.58k|    if (data_size < payload_offset)
  ------------------
  |  Branch (162:9): [True: 785, False: 2.80k]
  ------------------
  163|    785|        goto cleanup;
  164|       |
  165|  2.80k|    flags = sas_read2(&data[2], ctx->bswap);
  166|  2.80k|    pad = (flags & 0x08) ? 4 : 0; // might be 0x10, not sure
  ------------------
  |  Branch (166:11): [True: 1.03k, False: 1.76k]
  ------------------
  167|  2.80k|    if (ctx->u64) {
  ------------------
  |  Branch (167:9): [True: 473, False: 2.32k]
  ------------------
  168|    473|        label_count_capacity = sas_read8(&data[42+pad], ctx->bswap);
  169|    473|        label_count_used = sas_read8(&data[50+pad], ctx->bswap);
  170|       |
  171|    473|        payload_offset += 32;
  172|  2.32k|    } else {
  173|  2.32k|        label_count_capacity = sas_read4(&data[38+pad], ctx->bswap);
  174|  2.32k|        label_count_used = sas_read4(&data[42+pad], ctx->bswap);
  175|  2.32k|    }
  176|       |
  177|  2.80k|    if ((retval = readstat_convert(name, sizeof(name), &data[8], 8, ctx->converter)) != READSTAT_OK)
  ------------------
  |  Branch (177:9): [True: 3, False: 2.79k]
  ------------------
  178|      3|        goto cleanup;
  179|       |
  180|  2.79k|    if (pad) {
  ------------------
  |  Branch (180:9): [True: 1.03k, False: 1.76k]
  ------------------
  181|  1.03k|        pad += 16;
  182|  1.03k|    }
  183|       |
  184|  2.79k|    if (((flags & 0x80) && !ctx->u64) || ((flags & 0x20) && ctx->u64)) { // has long name
  ------------------
  |  Branch (184:10): [True: 1.30k, False: 1.49k]
  |  Branch (184:28): [True: 1.06k, False: 242]
  |  Branch (184:43): [True: 562, False: 1.17k]
  |  Branch (184:61): [True: 252, False: 310]
  ------------------
  185|  1.31k|        if (data_size < payload_offset + pad + 32)
  ------------------
  |  Branch (185:13): [True: 296, False: 1.01k]
  ------------------
  186|    296|            goto cleanup;
  187|       |
  188|  1.01k|        retval = readstat_convert(name, sizeof(name), &data[payload_offset+pad], 32, ctx->converter);
  189|  1.01k|        if (retval != READSTAT_OK)
  ------------------
  |  Branch (189:13): [True: 2, False: 1.01k]
  ------------------
  190|      2|            goto cleanup;
  191|  1.01k|        pad += 32;
  192|  1.01k|    }
  193|       |
  194|  2.50k|    if (data_size < payload_offset + pad)
  ------------------
  |  Branch (194:9): [True: 223, False: 2.27k]
  ------------------
  195|    223|        goto cleanup;
  196|       |
  197|  2.27k|    if (label_count_used == 0)
  ------------------
  |  Branch (197:9): [True: 695, False: 1.58k]
  ------------------
  198|    695|        goto cleanup;
  199|       |
  200|  1.58k|    if ((retval = sas7bcat_parse_value_labels(&data[payload_offset+pad], data_size - payload_offset - pad,
  ------------------
  |  Branch (200:9): [True: 453, False: 1.13k]
  ------------------
  201|  1.58k|                    label_count_used, label_count_capacity, name, ctx)) != READSTAT_OK)
  202|    453|        goto cleanup;
  203|       |
  204|  3.58k|cleanup:
  205|  3.58k|    return retval;
  206|  1.58k|}
readstat_sas7bcat_read.c:sas7bcat_parse_value_labels:
   46|  1.58k|        int label_count_used, int label_count_capacity, const char *name, sas7bcat_ctx_t *ctx) {
   47|  1.58k|    readstat_error_t retval = READSTAT_OK;
   48|  1.58k|    int i;
   49|  1.58k|    const char *lbp1 = value_start;
   50|  1.58k|    uint32_t *value_offset = readstat_calloc(label_count_used, sizeof(uint32_t));
   51|       |    /* Doubles appear to be stored as big-endian, always */
   52|  1.58k|    int bswap_doubles = machine_is_little_endian();
   53|  1.58k|    int is_string = (name[0] == '$');
   54|  1.58k|    char *label = NULL;
   55|       |
   56|  1.58k|    if (value_offset == NULL) {
  ------------------
  |  Branch (56:9): [True: 164, False: 1.41k]
  ------------------
   57|    164|        retval = READSTAT_ERROR_MALLOC;
   58|    164|        goto cleanup;
   59|    164|    }
   60|       |
   61|       |    /* Pass 1 -- find out the offset of the labels */
   62|  4.53M|    for (i=0; i<label_count_capacity; i++) {
  ------------------
  |  Branch (62:15): [True: 4.53M, False: 1.30k]
  ------------------
   63|  4.53M|        if (&lbp1[4] - value_start > value_labels_len || sas_read2(&lbp1[2], ctx->bswap) < 0) {
  ------------------
  |  Branch (63:13): [True: 54, False: 4.53M]
  |  Branch (63:58): [True: 0, False: 4.53M]
  ------------------
   64|     54|            retval = READSTAT_ERROR_PARSE;
   65|     54|            goto cleanup;
   66|     54|        }
   67|  4.53M|        if (i<label_count_used) {
  ------------------
  |  Branch (67:13): [True: 108k, False: 4.42M]
  ------------------
   68|   108k|            if (&lbp1[10+ctx->pad1+4] - value_start > value_labels_len) {
  ------------------
  |  Branch (68:17): [True: 6, False: 108k]
  ------------------
   69|      6|                retval = READSTAT_ERROR_PARSE;
   70|      6|                goto cleanup;
   71|      6|            }
   72|   108k|            uint32_t label_pos = sas_read4(&lbp1[10+ctx->pad1], ctx->bswap);
   73|   108k|            if (label_pos >= label_count_used) {
  ------------------
  |  Branch (73:17): [True: 57, False: 107k]
  ------------------
   74|     57|                retval = READSTAT_ERROR_PARSE;
   75|     57|                goto cleanup;
   76|     57|            }
   77|   107k|            value_offset[label_pos] = lbp1 - value_start;
   78|   107k|        }
   79|  4.53M|        lbp1 += 6 + sas_read2(&lbp1[2], ctx->bswap);
   80|  4.53M|    }
   81|       |
   82|  1.30k|    const char *lbp2 = lbp1;
   83|       |
   84|       |    /* Pass 2 -- parse pairs of values & labels */
   85|  30.3k|    for (i=0; i<label_count_used && i<label_count_capacity; i++) {
  ------------------
  |  Branch (85:15): [True: 30.1k, False: 268]
  |  Branch (85:37): [True: 29.2k, False: 862]
  ------------------
   86|  29.2k|        lbp1 = value_start + value_offset[i];
   87|       |
   88|  29.2k|        if (&lbp1[30] - value_start > value_labels_len ||
  ------------------
  |  Branch (88:13): [True: 9, False: 29.2k]
  ------------------
   89|  29.2k|                &lbp2[10] - value_start > value_labels_len) {
  ------------------
  |  Branch (89:17): [True: 127, False: 29.1k]
  ------------------
   90|    136|            retval = READSTAT_ERROR_PARSE;
   91|    136|            goto cleanup;
   92|    136|        }
   93|  29.1k|        readstat_value_t value = { .type = is_string ? READSTAT_TYPE_STRING : READSTAT_TYPE_DOUBLE };
  ------------------
  |  Branch (93:44): [True: 607, False: 28.5k]
  ------------------
   94|  29.1k|        char string_val[4*16+1];
   95|  29.1k|        if (is_string) {
  ------------------
  |  Branch (95:13): [True: 607, False: 28.5k]
  ------------------
   96|    607|            size_t value_entry_len = 6 + sas_read2(&lbp1[2], ctx->bswap);
   97|    607|            retval = readstat_convert(string_val, sizeof(string_val),
   98|    607|                    &lbp1[value_entry_len-16], 16, ctx->converter);
   99|    607|            if (retval != READSTAT_OK)
  ------------------
  |  Branch (99:17): [True: 1, False: 606]
  ------------------
  100|      1|                goto cleanup;
  101|       |
  102|    606|            value.v.string_value = string_val;
  103|  28.5k|        } else {
  104|  28.5k|            uint64_t val = sas_read8(&lbp1[22], bswap_doubles);
  105|  28.5k|            double dval = NAN;
  106|  28.5k|            if ((val | 0xFF0000000000) == 0xFFFFFFFFFFFF) {
  ------------------
  |  Branch (106:17): [True: 1.73k, False: 26.7k]
  ------------------
  107|  1.73k|                sas_assign_tag(&value, (val >> 40));
  108|  26.7k|            } else {
  109|  26.7k|                memcpy(&dval, &val, 8);
  110|  26.7k|                if (dval > 0.0) {
  ------------------
  |  Branch (110:21): [True: 23.6k, False: 3.09k]
  ------------------
  111|  23.6k|                    val = ~val;
  112|  23.6k|                    memcpy(&dval, &val, 8);
  113|  23.6k|                } else {
  114|  3.09k|                    dval *= -1.0;
  115|  3.09k|                }
  116|  26.7k|            }
  117|       |
  118|  28.5k|            value.v.double_value = dval;
  119|  28.5k|        }
  120|  29.1k|        size_t label_len = sas_read2(&lbp2[8], ctx->bswap);
  121|  29.1k|        if (&lbp2[10] > value_start + value_labels_len) {
  ------------------
  |  Branch (121:13): [True: 0, False: 29.1k]
  ------------------
  122|      0|            retval = READSTAT_ERROR_PARSE;
  123|      0|            goto cleanup;
  124|      0|        }
  125|       |        /* Some labels seem to overflow the reported block length, truncate it */
  126|       |        /* (Observed with formats.sasbcat from GSS2021, produced with 9.0401M6X64_SR12R2 */
  127|  29.1k|        if (label_len > value_start + value_labels_len - &lbp2[10]) {
  ------------------
  |  Branch (127:13): [True: 349, False: 28.7k]
  ------------------
  128|    349|            label_len = value_start + value_labels_len - &lbp2[10];
  129|    349|        }
  130|  29.1k|        if (ctx->value_label_handler) {
  ------------------
  |  Branch (130:13): [True: 29.1k, False: 0]
  ------------------
  131|  29.1k|            label = realloc(label, 4 * label_len + 1);
  132|  29.1k|            retval = readstat_convert(label, 4 * label_len + 1,
  133|  29.1k|                    &lbp2[10], label_len, ctx->converter);
  134|  29.1k|            if (retval != READSTAT_OK)
  ------------------
  |  Branch (134:17): [True: 35, False: 29.0k]
  ------------------
  135|     35|                goto cleanup;
  136|       |
  137|  29.0k|            if (ctx->value_label_handler(name, value, label, ctx->user_ctx) != READSTAT_HANDLER_OK) {
  ------------------
  |  Branch (137:17): [True: 0, False: 29.0k]
  ------------------
  138|      0|                retval = READSTAT_ERROR_USER_ABORT;
  139|      0|                goto cleanup;
  140|      0|            }
  141|  29.0k|        }
  142|       |
  143|  29.0k|        lbp2 += 8 + 2 + label_len + 1;
  144|  29.0k|    }
  145|       |
  146|  1.58k|cleanup:
  147|  1.58k|    free(label);
  148|  1.58k|    free(value_offset);
  149|  1.58k|    return retval;
  150|  1.30k|}
readstat_sas7bcat_read.c:sas7bcat_ctx_free:
   36|  1.80k|static void sas7bcat_ctx_free(sas7bcat_ctx_t *ctx) {
   37|  1.80k|    if (ctx->converter)
  ------------------
  |  Branch (37:9): [True: 722, False: 1.08k]
  ------------------
   38|    722|        iconv_close(ctx->converter);
   39|  1.80k|    if (ctx->block_pointers)
  ------------------
  |  Branch (39:9): [True: 1.80k, False: 0]
  ------------------
   40|  1.80k|        free(ctx->block_pointers);
   41|       |
   42|  1.80k|    free(ctx);
   43|  1.80k|}

rt_open_handler:
    8|  1.80k|int rt_open_handler(const char *path, void *io_ctx) {
    9|  1.80k|    return 0;
   10|  1.80k|}
rt_close_handler:
   12|  1.80k|int rt_close_handler(void *io_ctx) {
   13|  1.80k|    return 0;
   14|  1.80k|}
rt_seek_handler:
   17|   115k|        readstat_io_flags_t whence, void *io_ctx) {
   18|   115k|    rt_buffer_ctx_t *buffer_ctx = (rt_buffer_ctx_t *)io_ctx;
   19|   115k|    readstat_off_t newpos = -1;
   20|   115k|    if (whence == READSTAT_SEEK_SET) {
  ------------------
  |  Branch (20:9): [True: 112k, False: 3.08k]
  ------------------
   21|   112k|        newpos = offset;
   22|   112k|    } else if (whence == READSTAT_SEEK_CUR) {
  ------------------
  |  Branch (22:16): [True: 3.08k, False: 0]
  ------------------
   23|  3.08k|        newpos = buffer_ctx->pos + offset;
   24|  3.08k|    } else if (whence == READSTAT_SEEK_END) {
  ------------------
  |  Branch (24:16): [True: 0, False: 0]
  ------------------
   25|      0|        newpos = buffer_ctx->buffer->used + offset;
   26|      0|    }
   27|       |
   28|   115k|    if (newpos < 0)
  ------------------
  |  Branch (28:9): [True: 0, False: 115k]
  ------------------
   29|      0|        return -1;
   30|       |
   31|   115k|    if (newpos > buffer_ctx->buffer->used)
  ------------------
  |  Branch (31:9): [True: 258, False: 115k]
  ------------------
   32|    258|        return -1;
   33|       |
   34|   115k|    buffer_ctx->pos = newpos;
   35|   115k|    return newpos;
   36|   115k|}
rt_read_handler:
   38|   168k|ssize_t rt_read_handler(void *buf, size_t nbytes, void *io_ctx) {
   39|   168k|    rt_buffer_ctx_t *buffer_ctx = (rt_buffer_ctx_t *)io_ctx;
   40|   168k|    ssize_t bytes_copied = 0;
   41|   168k|    ssize_t bytes_left = buffer_ctx->buffer->used - buffer_ctx->pos;
   42|   168k|    if (nbytes <= bytes_left) {
  ------------------
  |  Branch (42:9): [True: 168k, False: 319]
  ------------------
   43|   168k|        memcpy(buf, buffer_ctx->buffer->bytes + buffer_ctx->pos, nbytes);
   44|   168k|        bytes_copied = nbytes;
   45|   168k|    } else if (bytes_left > 0) {
  ------------------
  |  Branch (45:16): [True: 172, False: 147]
  ------------------
   46|    172|        memcpy(buf, buffer_ctx->buffer->bytes + buffer_ctx->pos, bytes_left);
   47|    172|        bytes_copied = bytes_left;
   48|    172|    }
   49|   168k|    buffer_ctx->pos += bytes_copied;
   50|   168k|    return bytes_copied;
   51|   168k|}

