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

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

machine_is_little_endian:
   11|   609k|int machine_is_little_endian(void) {
   12|   609k|    int test_byte_order = 1;
   13|   609k|    return ((char *)&test_byte_order)[0];
   14|   609k|}
byteswap2:
   40|   976k|uint16_t byteswap2(uint16_t num) {
   41|   976k|    return ((num & 0xFF00) >> 8) | ((num & 0x00FF) << 8);
   42|   976k|}
byteswap4:
   44|  97.2k|uint32_t byteswap4(uint32_t num) {
   45|  97.2k|    num = ((num & 0xFFFF0000) >> 16) | ((num & 0x0000FFFF) << 16);
   46|  97.2k|    return ((num & 0xFF00FF00) >> 8) | ((num & 0x00FF00FF) << 8);
   47|  97.2k|}

readstat_convert:
   39|   822k|readstat_error_t readstat_convert(char *dst, size_t dst_len, const char *src, size_t src_len, iconv_t converter) {
   40|   822k|    return readstat_convert_impl(dst, dst_len, src, src_len, converter, 1);
   41|   822k|}
readstat_convert.c:readstat_convert_impl:
    8|   822k|        iconv_t converter, int trim_spaces) {
    9|       |    /* strip off spaces from the input because the programs use ASCII space
   10|       |     * padding even with non-ASCII encoding. */
   11|  8.17M|    while (src_len && ((trim_spaces && src[src_len-1] == ' ') || src[src_len-1] == '\0')) {
  ------------------
  |  Branch (11:12): [True: 7.51M, False: 664k]
  |  Branch (11:25): [True: 7.51M, False: 0]
  |  Branch (11:40): [True: 4.18M, False: 3.33M]
  |  Branch (11:66): [True: 3.17M, False: 157k]
  ------------------
   12|  7.35M|        src_len--;
   13|  7.35M|    }
   14|   822k|    if (dst_len == 0) {
  ------------------
  |  Branch (14:9): [True: 0, False: 822k]
  ------------------
   15|      0|        return READSTAT_ERROR_CONVERT_LONG_STRING;
   16|   822k|    } else if (converter) {
  ------------------
  |  Branch (16:16): [True: 0, False: 822k]
  ------------------
   17|      0|        size_t dst_left = dst_len - 1;
   18|      0|        char *dst_end = dst;
   19|      0|        size_t status = iconv(converter, (readstat_iconv_inbuf_t)&src, &src_len, &dst_end, &dst_left);
   20|      0|        if (status == (size_t)-1) {
  ------------------
  |  Branch (20:13): [True: 0, False: 0]
  ------------------
   21|      0|            if (errno == E2BIG) {
  ------------------
  |  Branch (21:17): [True: 0, False: 0]
  ------------------
   22|      0|                return READSTAT_ERROR_CONVERT_LONG_STRING;
   23|      0|            } else if (errno == EILSEQ) {
  ------------------
  |  Branch (23:24): [True: 0, False: 0]
  ------------------
   24|      0|                return READSTAT_ERROR_CONVERT_BAD_STRING;
   25|      0|            } else if (errno != EINVAL) { /* EINVAL indicates improper truncation; accept it */
  ------------------
  |  Branch (25:24): [True: 0, False: 0]
  ------------------
   26|      0|                return READSTAT_ERROR_CONVERT;
   27|      0|            }
   28|      0|        }
   29|      0|        dst[dst_len - dst_left - 1] = '\0';
   30|   822k|    } else if (src_len + 1 > dst_len) {
  ------------------
  |  Branch (30:16): [True: 21, False: 822k]
  ------------------
   31|     21|        return READSTAT_ERROR_CONVERT_LONG_STRING;
   32|   822k|    } else {
   33|   822k|        memcpy(dst, src, src_len);
   34|   822k|        dst[src_len] = '\0';
   35|   822k|    }
   36|   822k|    return READSTAT_OK;
   37|   822k|}

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

readstat_malloc:
   10|  1.37k|void *readstat_malloc(size_t len) {
   11|  1.37k|    if (len > MAX_MALLOC_SIZE || len == 0) {
  ------------------
  |  |    3|  2.74k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
  |  Branch (11:9): [True: 14, False: 1.35k]
  |  Branch (11:34): [True: 0, False: 1.35k]
  ------------------
   12|     14|        return NULL;
   13|     14|    }
   14|  1.35k|    return malloc(len);
   15|  1.37k|}
readstat_calloc:
   17|  1.31k|void *readstat_calloc(size_t count, size_t size) {
   18|  1.31k|    if (count > MAX_MALLOC_SIZE || size > MAX_MALLOC_SIZE || count * size > MAX_MALLOC_SIZE) {
  ------------------
  |  |    3|  2.62k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
                  if (count > MAX_MALLOC_SIZE || size > MAX_MALLOC_SIZE || count * size > MAX_MALLOC_SIZE) {
  ------------------
  |  |    3|  2.60k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
                  if (count > MAX_MALLOC_SIZE || size > MAX_MALLOC_SIZE || count * size > MAX_MALLOC_SIZE) {
  ------------------
  |  |    3|  1.29k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
  |  Branch (18:9): [True: 14, False: 1.29k]
  |  Branch (18:36): [True: 0, False: 1.29k]
  |  Branch (18:62): [True: 0, False: 1.29k]
  ------------------
   19|     14|        return NULL;
   20|     14|    }
   21|  1.29k|    if (count == 0 || size == 0) {
  ------------------
  |  Branch (21:9): [True: 2, False: 1.29k]
  |  Branch (21:23): [True: 0, False: 1.29k]
  ------------------
   22|      2|        return NULL;
   23|      2|    }
   24|  1.29k|    return calloc(count, size);
   25|  1.29k|}
readstat_realloc:
   27|   427k|void *readstat_realloc(void *ptr, size_t len) {
   28|   427k|    if (len > MAX_MALLOC_SIZE || len == 0) {
  ------------------
  |  |    3|   855k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
  |  Branch (28:9): [True: 0, False: 427k]
  |  Branch (28:34): [True: 0, False: 427k]
  ------------------
   29|      0|        if (ptr)
  ------------------
  |  Branch (29:13): [True: 0, False: 0]
  ------------------
   30|      0|            free(ptr);
   31|      0|        return NULL;
   32|      0|    }
   33|   427k|    return realloc(ptr, len);
   34|   427k|}

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

memreverse:
   22|   511k|void memreverse(void *intp_void, int l) {
   23|   511k|    if (!machine_is_little_endian())
  ------------------
  |  Branch (23:9): [True: 0, False: 511k]
  ------------------
   24|      0|        return;
   25|       |
   26|   511k|    int i,j;
   27|   511k|    char save;
   28|   511k|    char *intp = (char *)intp_void;
   29|       |
   30|   511k|    j = l/2;
   31|  1.53M|    for (i=0;i<j;i++) {
  ------------------
  |  Branch (31:14): [True: 1.02M, False: 511k]
  ------------------
   32|  1.02M|        save = intp[i];
   33|  1.02M|        intp[i] = intp[l-i-1];
   34|  1.02M|        intp[l-i-1] = save;
   35|  1.02M|    }
   36|   511k|}
cnxptiee:
   39|   139k|{
   40|   139k|    unsigned char *from = (unsigned char *)from_bytes;
   41|   139k|    unsigned char *to = (unsigned char *)to_bytes;
   42|   139k|    unsigned char temp[8];
   43|   139k|    int i;
   44|       |
   45|   139k|    if (fromtype == CN_TYPE_NATIVE) {
  ------------------
  |  |    1|   139k|#define CN_TYPE_NATIVE 0
  ------------------
  |  Branch (45:9): [True: 0, False: 139k]
  ------------------
   46|      0|        fromtype = FLOATREP;
  ------------------
  |  |   18|      0|#define FLOATREP get_native()
  ------------------
   47|      0|    }
   48|   139k|    switch(fromtype) {
   49|      0|        case CN_TYPE_IEEEL :
  ------------------
  |  |    4|      0|#define CN_TYPE_IEEEL 3
  ------------------
  |  Branch (49:9): [True: 0, False: 139k]
  ------------------
   50|      0|            if (totype == CN_TYPE_IEEEL)
  ------------------
  |  |    4|      0|#define CN_TYPE_IEEEL 3
  ------------------
  |  Branch (50:17): [True: 0, False: 0]
  ------------------
   51|      0|                break;
   52|      0|            for (i=7;i>=0;i--) {
  ------------------
  |  Branch (52:22): [True: 0, False: 0]
  ------------------
   53|      0|                temp[7-i] = from[i];
   54|      0|            }
   55|      0|            from = temp;
   56|      0|            fromtype = CN_TYPE_IEEEB;
  ------------------
  |  |    3|      0|#define CN_TYPE_IEEEB 2
  ------------------
   57|       |            /* Break intentionally omitted. */
   58|      0|        case CN_TYPE_IEEEB :
  ------------------
  |  |    3|      0|#define CN_TYPE_IEEEB 2
  ------------------
  |  Branch (58:9): [True: 0, False: 139k]
  ------------------
   59|       |            /* Break intentionally omitted. */
   60|   139k|        case CN_TYPE_XPORT :
  ------------------
  |  |    2|   139k|#define CN_TYPE_XPORT 1
  ------------------
  |  Branch (60:9): [True: 139k, False: 0]
  ------------------
   61|   139k|            break;
   62|      0|        default:
  ------------------
  |  Branch (62:9): [True: 0, False: 139k]
  ------------------
   63|      0|            return(-1);
   64|   139k|    }
   65|   139k|    if (totype == CN_TYPE_NATIVE) {
  ------------------
  |  |    1|   139k|#define CN_TYPE_NATIVE 0
  ------------------
  |  Branch (65:9): [True: 139k, False: 0]
  ------------------
   66|   139k|        totype = FLOATREP;
  ------------------
  |  |   18|   139k|#define FLOATREP get_native()
  ------------------
   67|   139k|    }
   68|   139k|    switch(totype) {
   69|      0|        case CN_TYPE_XPORT :
  ------------------
  |  |    2|      0|#define CN_TYPE_XPORT 1
  ------------------
  |  Branch (69:9): [True: 0, False: 139k]
  ------------------
   70|      0|        case CN_TYPE_IEEEB :
  ------------------
  |  |    3|      0|#define CN_TYPE_IEEEB 2
  ------------------
  |  Branch (70:9): [True: 0, False: 139k]
  ------------------
   71|   139k|        case CN_TYPE_IEEEL :
  ------------------
  |  |    4|   139k|#define CN_TYPE_IEEEL 3
  ------------------
  |  Branch (71:9): [True: 139k, False: 0]
  ------------------
   72|   139k|            break;
   73|      0|        default:
  ------------------
  |  Branch (73:9): [True: 0, False: 139k]
  ------------------
   74|      0|            return(-2);
   75|   139k|    }
   76|   139k|    if (fromtype == totype) {
  ------------------
  |  Branch (76:9): [True: 0, False: 139k]
  ------------------
   77|      0|        memcpy(to,from,8);
   78|      0|        return(0);
   79|      0|    }
   80|   139k|    switch(fromtype) {
  ------------------
  |  Branch (80:12): [True: 139k, False: 0]
  ------------------
   81|      0|        case CN_TYPE_IEEEB :
  ------------------
  |  |    3|      0|#define CN_TYPE_IEEEB 2
  ------------------
  |  Branch (81:9): [True: 0, False: 139k]
  ------------------
   82|      0|            if (totype == CN_TYPE_XPORT)
  ------------------
  |  |    2|      0|#define CN_TYPE_XPORT 1
  ------------------
  |  Branch (82:17): [True: 0, False: 0]
  ------------------
   83|      0|                ieee2xpt(from,to);
   84|      0|            else memcpy(to,from,8);
   85|      0|            break;
   86|   139k|        case CN_TYPE_XPORT :
  ------------------
  |  |    2|   139k|#define CN_TYPE_XPORT 1
  ------------------
  |  Branch (86:9): [True: 139k, False: 0]
  ------------------
   87|   139k|            xpt2ieee(from,to);
   88|   139k|            break;
   89|   139k|    }
   90|   139k|    if (totype == CN_TYPE_IEEEL) {
  ------------------
  |  |    4|   139k|#define CN_TYPE_IEEEL 3
  ------------------
  |  Branch (90:9): [True: 139k, False: 0]
  ------------------
   91|   139k|        memcpy(temp,to,8);
   92|  1.25M|        for (i=7;i>=0;i--) {
  ------------------
  |  Branch (92:18): [True: 1.11M, False: 139k]
  ------------------
   93|  1.11M|            to[7-i] = temp[i];
   94|  1.11M|        }
   95|   139k|    }
   96|   139k|    return(0);
   97|   139k|}
get_native:
   99|   139k|int get_native(void) {
  100|   139k|    static unsigned char float_reps[][8] = {
  101|   139k|        {0x41,0x10,0x00,0x00,0x00,0x00,0x00,0x00},
  102|   139k|        {0x3f,0xf0,0x00,0x00,0x00,0x00,0x00,0x00},
  103|   139k|        {0x00,0x00,0x00,0x00,0x00,0x00,0xf0,0x3f}
  104|   139k|    };
  105|       |
  106|   139k|    static double one = 1.00;
  107|       |
  108|   139k|    int i,j;
  109|   139k|    j = sizeof(float_reps)/8;
  110|   418k|    for (i=0;i<j;i++)  {
  ------------------
  |  Branch (110:14): [True: 418k, False: 0]
  ------------------
  111|   418k|        if (memcmp(&one,float_reps+i,8) == 0)
  ------------------
  |  Branch (111:13): [True: 139k, False: 279k]
  ------------------
  112|   139k|            return(i+1);
  113|   418k|    }
  114|      0|    return(-1);
  115|   139k|}
ieee.c:xpt2ieee:
  117|   139k|void xpt2ieee(unsigned char *xport, unsigned char *ieee) {
  118|   139k|    char temp[8];
  119|   139k|    register int shift;
  120|   139k|    register int nib;
  121|   139k|    uint32_t ieee1,ieee2;
  122|   139k|    uint32_t xport1 = 0;
  123|   139k|    uint32_t xport2 = 0;
  124|       |
  125|   139k|    memcpy(temp,xport,8);
  126|   139k|    memset(ieee,0,8);
  127|       |
  128|   139k|    if (*temp && memcmp(temp+1,ieee,7) == 0) {
  ------------------
  |  Branch (128:9): [True: 113k, False: 26.3k]
  |  Branch (128:18): [True: 587, False: 112k]
  ------------------
  129|    587|        ieee[0] = ieee[1] = 0xff;
  130|    587|        ieee[2] = ~(*temp);
  131|    587|        return;
  132|    587|    }
  133|       |
  134|   139k|    memcpy(&xport1,temp,sizeof(uint32_t));
  135|   139k|    memreverse(&xport1,sizeof(uint32_t));
  136|   139k|    memcpy(&xport2,temp+4,sizeof(uint32_t));
  137|   139k|    memreverse(&xport2,sizeof(uint32_t));
  138|       |
  139|       |    /***************************************************************/
  140|       |    /* Translate IBM format floating point numbers into IEEE */
  141|       |    /* format floating point numbers. */
  142|       |    /* */
  143|       |    /* IEEE format: */
  144|       |    /* */
  145|       |    /* 6 5 0 */
  146|       |    /* 3 1 0 */
  147|       |    /* */
  148|       |    /* SEEEEEEEEEEEMMMM ............ MMMM */
  149|       |    /* */
  150|       |    /* Sign bit, 11 bits exponent, 52 bit fraction. Exponent is */
  151|       |    /* excess 1023. The fraction is multiplied by a power of 2 of */
  152|       |
  153|       |    /* the actual exponent. Normalized floating point numbers are */
  154|       |    /* represented with the binary point immediately to the left */
  155|       |    /* of the fraction with an implied "1" to the left of the */
  156|       |    /* binary point. */
  157|       |    /* */
  158|       |    /* IBM format: */
  159|       |    /* */
  160|       |    /* 6 5 0 */
  161|       |    /* 3 1 0 */
  162|       |    /* */
  163|       |    /* SEEEEEEEMMMM ......... MMMM */
  164|       |    /* */
  165|       |    /* Sign bit, 7 bit exponent, 56 bit fraction. Exponent is */
  166|       |    /* excess 64. The fraction is multiplied bya power of 16 of */
  167|       |    /* the actual exponent. Normalized floating point numbers are */
  168|       |    /* represented with the radix point immediately to the left of*/
  169|       |    /* the high order hex fraction digit. */
  170|       |    /* */
  171|       |    /* How do you translate from IBM format to IEEE? */
  172|       |    /* */
  173|       |    /* Translating back to ieee format from ibm is easier than */
  174|       |    /* going the other way. You lose at most, 3 bits of fraction, */
  175|       |    /* but nothing can be done about that. The only tricky parts */
  176|       |    /* are setting up the correct binary exponent from the ibm */
  177|       |    /* hex exponent, and removing the implicit "1" bit of the ieee*/
  178|       |    /* fraction (see vzctdbl). We must shift down the high order */
  179|       |    /* nibble of the ibm fraction until it is 1. This is the */
  180|       |    /* implicit 1. The bit is then cleared and the exponent */
  181|       |    /* adjusted by the number of positions shifted. A more */
  182|       |    /* thorough discussion is in vzctdbl.c. */
  183|       |
  184|   139k|    if ((xport1 & 0x7fffffff) == 0x7fffffff && xport2 == 0xffffffff) {
  ------------------
  |  Branch (184:9): [True: 1.95k, False: 137k]
  |  Branch (184:48): [True: 1.04k, False: 911]
  ------------------
  185|  1.04k|        ieee1 = (xport1 & 0x80000000) | 0x7ff00000;
  186|  1.04k|        ieee2 = 0;
  187|  1.04k|        goto doret;
  188|  1.04k|    }
  189|       |
  190|       |    /* Get the first half of the ibm number without the exponent */
  191|       |    /* into the ieee number */
  192|   138k|    ieee1 = xport1 & 0x00ffffff;
  193|       |
  194|       |    /* get the second half of the ibm number into the second half */
  195|       |    /* of the ieee number . If both halves were 0. then just */
  196|       |    /* return since the ieee number is zero. */
  197|   138k|    if ((!(ieee2 = xport2)) && !xport1)
  ------------------
  |  Branch (197:9): [True: 27.1k, False: 110k]
  |  Branch (197:32): [True: 22.5k, False: 4.59k]
  ------------------
  198|  22.5k|        return;
  199|       |
  200|       |    /* The fraction bit to the left of the binary point in the */
  201|       |    /* ieee format was set and the number was shifted 0, 1, 2, or */
  202|       |    /* 3 places. This will tell us how to adjust the ibm exponent */
  203|       |    /* to be a power of 2 ieee exponent and how to shift the */
  204|       |    /* fraction bits to restore the correct magnitude. */
  205|       |
  206|   115k|    if ((nib = (int)xport1) & 0x00800000) {
  ------------------
  |  Branch (206:9): [True: 50.5k, False: 64.8k]
  ------------------
  207|  50.5k|        shift = 3;
  208|  64.8k|    } else if (nib & 0x00400000) {
  ------------------
  |  Branch (208:16): [True: 8.01k, False: 56.8k]
  ------------------
  209|  8.01k|        shift = 2;
  210|  56.8k|    } else if (nib & 0x00200000) {
  ------------------
  |  Branch (210:16): [True: 52.3k, False: 4.45k]
  ------------------
  211|  52.3k|        shift = 1;
  212|  52.3k|    } else {
  213|  4.45k|        shift = 0;
  214|  4.45k|    }
  215|       |
  216|   115k|    if (shift) {
  ------------------
  |  Branch (216:9): [True: 110k, False: 4.45k]
  ------------------
  217|       |        /* shift the ieee number down the correct number of places */
  218|       |        /* then set the second half of the ieee number to be the */
  219|       |        /* second half of the ibm number shifted appropriately, */
  220|       |        /* ored with the bits from the first half that would have */
  221|       |        /* been shifted in if we could shift a double. All we are */
  222|       |        /* worried about are the low order 3 bits of the first */
  223|       |        /* half since we're only shifting by 1, 2, or 3. */
  224|   110k|        ieee1 >>= shift;
  225|   110k|        ieee2 = (xport2 >> shift) |
  226|   110k|            ((xport1 & 0x00000007) << (29 + (3 - shift)));
  227|   110k|    }
  228|       |
  229|       |    /* clear the 1 bit to the left of the binary point */
  230|   115k|    ieee1 &= 0xffefffff;
  231|       |
  232|       |    /* set the exponent of the ieee number to be the actual */
  233|       |    /* exponent plus the shift count + 1023. Or this into the */
  234|       |    /* first half of the ieee number. The ibm exponent is excess */
  235|       |    /* 64 but is adjusted by 65 since during conversion to ibm */
  236|       |    /* format the exponent is incremented by 1 and the fraction */
  237|       |    /* bits left 4 positions to the right of the radix point. */
  238|   115k|    ieee1 |=
  239|   115k|        (((((int32_t)(*temp & 0x7f) - 65) * 4) + shift + 1023) << 20) |
  240|   115k|        (xport1 & 0x80000000);
  241|       |
  242|   116k|doret:
  243|   116k|    memreverse(&ieee1,sizeof(uint32_t));
  244|   116k|    memcpy(ieee,&ieee1,sizeof(uint32_t));
  245|   116k|    memreverse(&ieee2,sizeof(uint32_t));
  246|   116k|    memcpy(ieee+4,&ieee2,sizeof(uint32_t));
  247|   116k|    return;
  248|   115k|}

sas_validate_tag:
  599|  23.6k|readstat_error_t sas_validate_tag(char tag) {
  600|  23.6k|    if (tag == '_' || (tag >= 'A' && tag <= 'Z'))
  ------------------
  |  Branch (600:9): [True: 202, False: 23.4k]
  |  Branch (600:24): [True: 516, False: 22.8k]
  |  Branch (600:38): [True: 233, False: 283]
  ------------------
  601|    435|        return READSTAT_OK;
  602|       |
  603|  23.1k|    return READSTAT_ERROR_TAGGED_VALUE_IS_OUT_OF_RANGE;
  604|  23.6k|}

xport_namestr_bswap:
   10|  97.2k|void xport_namestr_bswap(xport_namestr_t *namestr) {
   11|  97.2k|    if (!machine_is_little_endian())
  ------------------
  |  Branch (11:9): [True: 0, False: 97.2k]
  ------------------
   12|      0|        return;
   13|       |
   14|  97.2k|    namestr->ntype = byteswap2(namestr->ntype);
   15|  97.2k|    namestr->nhfun = byteswap2(namestr->nhfun);
   16|  97.2k|    namestr->nlng = byteswap2(namestr->nlng);
   17|  97.2k|    namestr->nvar0 = byteswap2(namestr->nvar0);
   18|       |
   19|  97.2k|    namestr->nfl = byteswap2(namestr->nfl);
   20|  97.2k|    namestr->nfd = byteswap2(namestr->nfd);
   21|  97.2k|    namestr->nfj = byteswap2(namestr->nfj);
   22|       |
   23|  97.2k|    namestr->nifl = byteswap2(namestr->nifl);
   24|  97.2k|    namestr->nifd = byteswap2(namestr->nifd);
   25|  97.2k|    namestr->npos = byteswap4(namestr->npos);
   26|       |
   27|  97.2k|    namestr->labeln  = byteswap2(namestr->labeln);
   28|  97.2k|}

readstat_parse_xport:
  759|  1.86k|readstat_error_t readstat_parse_xport(readstat_parser_t *parser, const char *path, void *user_ctx) {
  760|  1.86k|    readstat_error_t retval = READSTAT_OK;
  761|  1.86k|    readstat_io_t *io = parser->io;
  762|       |
  763|  1.86k|    xport_ctx_t *ctx = xport_ctx_init();
  764|  1.86k|    ctx->handle = parser->handlers;
  765|  1.86k|    ctx->input_encoding = parser->input_encoding;
  766|  1.86k|    ctx->output_encoding = parser->output_encoding;
  767|  1.86k|    ctx->user_ctx = user_ctx;
  768|  1.86k|    ctx->io = io;
  769|  1.86k|    ctx->row_limit = parser->row_limit;
  770|  1.86k|    if (parser->row_offset > 0)
  ------------------
  |  Branch (770:9): [True: 0, False: 1.86k]
  ------------------
  771|      0|        ctx->row_offset = parser->row_offset;
  772|       |
  773|  1.86k|    if (io->open(path, io->io_ctx) == -1) {
  ------------------
  |  Branch (773:9): [True: 0, False: 1.86k]
  ------------------
  774|      0|        retval = READSTAT_ERROR_OPEN;
  775|      0|        goto cleanup;
  776|      0|    }
  777|       |
  778|  1.86k|    if ((ctx->file_size = io->seek(0, READSTAT_SEEK_END, io->io_ctx)) == -1) {
  ------------------
  |  Branch (778:9): [True: 0, False: 1.86k]
  ------------------
  779|      0|        retval = READSTAT_ERROR_SEEK;
  780|      0|        goto cleanup;
  781|      0|    }
  782|       |
  783|  1.86k|    if (io->seek(0, READSTAT_SEEK_SET, io->io_ctx) == -1) {
  ------------------
  |  Branch (783:9): [True: 0, False: 1.86k]
  ------------------
  784|      0|        retval = READSTAT_ERROR_SEEK;
  785|      0|        goto cleanup;
  786|      0|    }
  787|       |
  788|  1.86k|    if (ctx->input_encoding && ctx->output_encoding && strcmp(ctx->input_encoding, ctx->output_encoding) != 0) {
  ------------------
  |  Branch (788:9): [True: 0, False: 1.86k]
  |  Branch (788:32): [True: 0, False: 0]
  |  Branch (788:56): [True: 0, False: 0]
  ------------------
  789|      0|        iconv_t converter = iconv_open(ctx->output_encoding, ctx->input_encoding);
  790|      0|        if (converter == (iconv_t)-1) {
  ------------------
  |  Branch (790:13): [True: 0, False: 0]
  ------------------
  791|      0|            retval = READSTAT_ERROR_UNSUPPORTED_CHARSET;
  792|      0|            goto cleanup;
  793|      0|        }
  794|      0|        ctx->converter = converter;
  795|      0|    }
  796|       |
  797|  1.86k|    retval = xport_read_library_record(ctx);
  798|  1.86k|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (798:9): [True: 213, False: 1.65k]
  ------------------
  799|    213|        goto cleanup;
  800|       |
  801|  1.65k|    retval = xport_skip_record(ctx);
  802|  1.65k|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (802:9): [True: 10, False: 1.64k]
  ------------------
  803|     10|        goto cleanup;
  804|       |
  805|  1.64k|    retval = xport_read_timestamp_record(ctx);
  806|  1.64k|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (806:9): [True: 12, False: 1.63k]
  ------------------
  807|     12|        goto cleanup;
  808|       |
  809|  1.63k|    retval = xport_expect_header_record(ctx, "MEMBER", "MEMBV8");
  810|  1.63k|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (810:9): [True: 134, False: 1.50k]
  ------------------
  811|    134|        goto cleanup;
  812|       |
  813|  1.50k|    retval = xport_expect_header_record(ctx, "DSCRPTR", "DSCPTV8");
  814|  1.50k|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (814:9): [True: 20, False: 1.48k]
  ------------------
  815|     20|        goto cleanup;
  816|       |
  817|  1.48k|    retval = xport_read_table_name_record(ctx);
  818|  1.48k|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (818:9): [True: 12, False: 1.46k]
  ------------------
  819|     12|        goto cleanup;
  820|       |
  821|  1.46k|    retval = xport_read_file_label_record(ctx);
  822|  1.46k|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (822:9): [True: 30, False: 1.43k]
  ------------------
  823|     30|        goto cleanup;
  824|       |
  825|  1.43k|    retval = xport_read_namestr_header_record(ctx);
  826|  1.43k|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (826:9): [True: 143, False: 1.29k]
  ------------------
  827|    143|        goto cleanup;
  828|       |
  829|  1.29k|    retval = xport_read_variables(ctx);
  830|  1.29k|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (830:9): [True: 594, False: 701]
  ------------------
  831|    594|        goto cleanup;
  832|       |
  833|    701|    if (ctx->row_length) {
  ------------------
  |  Branch (833:9): [True: 686, False: 15]
  ------------------
  834|    686|        retval = xport_read_data(ctx);
  835|    686|        if (retval != READSTAT_OK)
  ------------------
  |  Branch (835:13): [True: 7, False: 679]
  ------------------
  836|      7|            goto cleanup;
  837|    686|    }
  838|       |
  839|  1.86k|cleanup:
  840|  1.86k|    io->close(io->io_ctx);
  841|  1.86k|    xport_ctx_free(ctx);
  842|       |
  843|  1.86k|    return retval;
  844|    701|}
readstat_xport_read.c:xport_ctx_init:
   48|  1.86k|static xport_ctx_t *xport_ctx_init(void) {
   49|  1.86k|    xport_ctx_t *ctx = calloc(1, sizeof(xport_ctx_t));
   50|  1.86k|    return ctx;
   51|  1.86k|}
readstat_xport_read.c:xport_read_library_record:
  198|  1.86k|static readstat_error_t xport_read_library_record(xport_ctx_t *ctx) {
  199|  1.86k|    xport_header_record_t xrecord;
  200|  1.86k|    readstat_error_t retval = xport_read_header_record(ctx, &xrecord);
  201|  1.86k|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (201:9): [True: 26, False: 1.84k]
  ------------------
  202|     26|        goto cleanup;
  203|       |
  204|  1.84k|    if (strcmp(xrecord.name, "LIBRARY") == 0) {
  ------------------
  |  Branch (204:9): [True: 295, False: 1.54k]
  ------------------
  205|    295|        ctx->version = 5;
  206|  1.54k|    } else if (strcmp(xrecord.name, "LIBV8") == 0) {
  ------------------
  |  Branch (206:16): [True: 1.36k, False: 187]
  ------------------
  207|  1.36k|        ctx->version = 8;
  208|  1.36k|    } else {
  209|    187|        retval = READSTAT_ERROR_UNSUPPORTED_FILE_FORMAT_VERSION;
  210|    187|        goto cleanup;
  211|    187|    }
  212|       |
  213|  1.86k|cleanup:
  214|  1.86k|    return retval;
  215|  1.84k|}
readstat_xport_read.c:xport_read_header_record:
  106|  7.78k|static readstat_error_t xport_read_header_record(xport_ctx_t *ctx, xport_header_record_t *xrecord) {
  107|  7.78k|    char line[LINE_LEN+1];
  108|  7.78k|    readstat_error_t retval = READSTAT_OK;
  109|       |
  110|  7.78k|    retval = xport_read_record(ctx, line);
  111|  7.78k|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (111:9): [True: 125, False: 7.66k]
  ------------------
  112|    125|        return retval;
  113|       |
  114|  7.66k|    memset(xrecord, 0, sizeof(xport_header_record_t));
  115|  7.66k|    int matches = sscanf(line,
  116|  7.66k|            "HEADER RECORD*******%8s HEADER RECORD!!!!!!!"
  117|  7.66k|            "%05d%05d%05d" "%05d%05d%05d", xrecord->name,
  118|  7.66k|            &xrecord->num1, &xrecord->num2, &xrecord->num3,
  119|  7.66k|            &xrecord->num4, &xrecord->num5, &xrecord->num6);
  120|       |
  121|  7.66k|    if (matches < 2) {
  ------------------
  |  Branch (121:9): [True: 16, False: 7.64k]
  ------------------
  122|     16|        return READSTAT_ERROR_PARSE;
  123|     16|    }
  124|       |
  125|       |    /* V8 files store the observation count as a 15-character field
  126|       |     * immediately after the 48-character header prefix. Older writers
  127|       |     * may leave it blank or zero, in which case it stays unknown. */
  128|  7.64k|    if (strcmp(xrecord->name, "OBSV8") == 0) {
  ------------------
  |  Branch (128:9): [True: 202, False: 7.44k]
  ------------------
  129|    202|        char obs_count[16];
  130|    202|        memcpy(obs_count, &line[48], 15);
  131|    202|        obs_count[15] = '\0';
  132|       |
  133|    202|        char *end = NULL;
  134|    202|        long count = strtol(obs_count, &end, 10);
  135|    202|        if (end != obs_count && count > 0) {
  ------------------
  |  Branch (135:13): [True: 199, False: 3]
  |  Branch (135:33): [True: 141, False: 58]
  ------------------
  136|    141|            ctx->obs_count = count;
  137|    141|        }
  138|    202|    }
  139|       |
  140|  7.64k|    return READSTAT_OK;
  141|  7.66k|}
readstat_xport_read.c:xport_read_record:
   96|  12.3k|static readstat_error_t xport_read_record(xport_ctx_t *ctx, char *record) {
   97|  12.3k|    ssize_t bytes_read = read_bytes(ctx, record, LINE_LEN);
  ------------------
  |  |   16|  12.3k|#define LINE_LEN        80
  ------------------
   98|  12.3k|    if (bytes_read < LINE_LEN)
  ------------------
  |  |   16|  12.3k|#define LINE_LEN        80
  ------------------
  |  Branch (98:9): [True: 179, False: 12.2k]
  ------------------
   99|    179|        return READSTAT_ERROR_READ;
  100|       |
  101|  12.2k|    record[LINE_LEN] = '\0';
  ------------------
  |  |   16|  12.2k|#define LINE_LEN        80
  ------------------
  102|       |
  103|  12.2k|    return READSTAT_OK;
  104|  12.3k|}
readstat_xport_read.c:read_bytes:
   69|   729k|static ssize_t read_bytes(xport_ctx_t *ctx, void *dst, size_t dst_len) {
   70|   729k|    readstat_io_t *io = (readstat_io_t *)ctx->io;
   71|   729k|    return io->read(dst, dst_len, io->io_ctx);
   72|   729k|}
readstat_xport_read.c:xport_skip_record:
   74|  1.65k|static readstat_error_t xport_skip_record(xport_ctx_t *ctx) {
   75|  1.65k|    readstat_io_t *io = (readstat_io_t *)ctx->io;
   76|  1.65k|    if (io->seek(LINE_LEN, READSTAT_SEEK_CUR, io->io_ctx) == -1)
  ------------------
  |  |   16|  1.65k|#define LINE_LEN        80
  ------------------
  |  Branch (76:9): [True: 10, False: 1.64k]
  ------------------
   77|     10|        return READSTAT_ERROR_SEEK;
   78|       |
   79|  1.64k|    return READSTAT_OK;
   80|  1.65k|}
readstat_xport_read.c:xport_read_timestamp_record:
  217|  1.64k|static readstat_error_t xport_read_timestamp_record(xport_ctx_t *ctx) {
  218|  1.64k|    char line[LINE_LEN+1];
  219|  1.64k|    readstat_error_t retval = READSTAT_OK;
  220|  1.64k|    struct tm ts = { .tm_isdst = -1 };
  221|  1.64k|    char month[4];
  222|  1.64k|    int i;
  223|       |
  224|  1.64k|    retval = xport_read_record(ctx, line);
  225|  1.64k|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (225:9): [True: 12, False: 1.63k]
  ------------------
  226|     12|        goto cleanup;
  227|       |
  228|  1.63k|    sscanf(line,
  229|  1.63k|            "%02d%3s%02d:%02d:%02d:%02d",
  230|  1.63k|            &ts.tm_mday, month, &ts.tm_year, &ts.tm_hour, &ts.tm_min, &ts.tm_sec);
  231|       |
  232|  16.4k|    for (i=0; i<sizeof(_xport_months)/sizeof(_xport_months[0]); i++) {
  ------------------
  |  Branch (232:15): [True: 15.3k, False: 1.09k]
  ------------------
  233|  15.3k|        if (strcmp(month, _xport_months[i]) == 0) {
  ------------------
  |  Branch (233:13): [True: 541, False: 14.7k]
  ------------------
  234|    541|            ts.tm_mon = i;
  235|    541|            break;
  236|    541|        }
  237|  15.3k|    }
  238|       |
  239|  1.63k|    if (ts.tm_year < 60) {
  ------------------
  |  Branch (239:9): [True: 1.62k, False: 12]
  ------------------
  240|  1.62k|        ts.tm_year += 100;
  241|  1.62k|    }
  242|       |
  243|  1.63k|    ctx->timestamp = mktime(&ts);
  244|       |
  245|  1.64k|cleanup:
  246|  1.64k|    return retval;
  247|  1.63k|}
readstat_xport_read.c:xport_expect_header_record:
  144|  3.39k|        const char *v5_name, const char *v8_name) {
  145|  3.39k|    readstat_error_t retval = READSTAT_OK;
  146|  3.39k|    xport_header_record_t xrecord;
  147|       |
  148|  3.39k|    retval = xport_read_header_record(ctx, &xrecord);
  149|  3.39k|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (149:9): [True: 98, False: 3.29k]
  ------------------
  150|     98|        goto cleanup;
  151|       |
  152|  3.29k|    if (ctx->version == 5 && strcmp(xrecord.name, v5_name) != 0) {
  ------------------
  |  Branch (152:9): [True: 608, False: 2.69k]
  |  Branch (152:30): [True: 88, False: 520]
  ------------------
  153|     88|        retval = READSTAT_ERROR_PARSE;
  154|     88|        goto cleanup;
  155|  3.21k|    } else if (ctx->version == 8 && strcmp(xrecord.name, v8_name) != 0) {
  ------------------
  |  Branch (155:16): [True: 2.69k, False: 520]
  |  Branch (155:37): [True: 150, False: 2.54k]
  ------------------
  156|    150|        retval = READSTAT_ERROR_PARSE;
  157|    150|        goto cleanup;
  158|    150|    }
  159|       |
  160|  3.39k|cleanup:
  161|  3.39k|    return retval;
  162|  3.29k|}
readstat_xport_read.c:xport_read_table_name_record:
  164|  1.48k|static readstat_error_t xport_read_table_name_record(xport_ctx_t *ctx) {
  165|  1.48k|    char line[LINE_LEN+1];
  166|  1.48k|    readstat_error_t retval = READSTAT_OK;
  167|       |
  168|  1.48k|    retval = xport_read_record(ctx, line);
  169|  1.48k|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (169:9): [True: 12, False: 1.46k]
  ------------------
  170|     12|        goto cleanup;
  171|       |
  172|  1.46k|    retval = readstat_convert(ctx->table_name, sizeof(ctx->table_name), &line[8],
  173|  1.46k|            ctx->version == 5 ? 8 : 32, ctx->converter);
  ------------------
  |  Branch (173:13): [True: 213, False: 1.25k]
  ------------------
  174|  1.46k|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (174:9): [True: 0, False: 1.46k]
  ------------------
  175|      0|        goto cleanup;
  176|       |
  177|  1.48k|cleanup:
  178|  1.48k|    return retval;
  179|  1.46k|}
readstat_xport_read.c:xport_read_file_label_record:
  181|  1.46k|static readstat_error_t xport_read_file_label_record(xport_ctx_t *ctx) {
  182|  1.46k|    char line[LINE_LEN+1];
  183|  1.46k|    readstat_error_t retval = READSTAT_OK;
  184|       |
  185|  1.46k|    retval = xport_read_record(ctx, line);
  186|  1.46k|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (186:9): [True: 30, False: 1.43k]
  ------------------
  187|     30|        goto cleanup;
  188|       |
  189|  1.43k|    retval = readstat_convert(ctx->file_label, sizeof(ctx->file_label), &line[32],
  190|  1.43k|            40, ctx->converter);
  191|  1.43k|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (191:9): [True: 0, False: 1.43k]
  ------------------
  192|      0|        goto cleanup;
  193|       |
  194|  1.46k|cleanup:
  195|  1.46k|    return retval;
  196|  1.43k|}
readstat_xport_read.c:xport_read_namestr_header_record:
  249|  1.43k|static readstat_error_t xport_read_namestr_header_record(xport_ctx_t *ctx) {
  250|  1.43k|    xport_header_record_t xrecord;
  251|  1.43k|    readstat_error_t retval = READSTAT_OK;
  252|       |
  253|  1.43k|    retval = xport_read_header_record(ctx, &xrecord);
  254|  1.43k|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (254:9): [True: 3, False: 1.43k]
  ------------------
  255|      3|        goto cleanup;
  256|       |
  257|  1.43k|    if (ctx->version == 5 && strcmp(xrecord.name, "NAMESTR") != 0) {
  ------------------
  |  Branch (257:9): [True: 209, False: 1.22k]
  |  Branch (257:30): [True: 62, False: 147]
  ------------------
  258|     62|        retval = READSTAT_ERROR_PARSE;
  259|     62|        goto cleanup;
  260|  1.37k|    } else if (ctx->version == 8 && strcmp(xrecord.name, "NAMSTV8") != 0) {
  ------------------
  |  Branch (260:16): [True: 1.22k, False: 147]
  |  Branch (260:37): [True: 62, False: 1.16k]
  ------------------
  261|     62|        retval = READSTAT_ERROR_PARSE;
  262|     62|        goto cleanup;
  263|     62|    }
  264|       |
  265|  1.31k|    ctx->var_count = xrecord.num2;
  266|  1.31k|    ctx->variables = readstat_calloc(ctx->var_count, sizeof(readstat_variable_t *));
  267|  1.31k|    if (ctx->variables == NULL) {
  ------------------
  |  Branch (267:9): [True: 16, False: 1.29k]
  ------------------
  268|     16|        retval = READSTAT_ERROR_MALLOC;
  269|     16|        goto cleanup;
  270|     16|    }
  271|       |
  272|  1.29k|    if (ctx->handle.metadata) {
  ------------------
  |  Branch (272:9): [True: 1.29k, False: 0]
  ------------------
  273|  1.29k|        readstat_metadata_t metadata = {
  274|  1.29k|            .row_count = -1,
  275|  1.29k|            .var_count = ctx->var_count,
  276|  1.29k|            .file_label = ctx->file_label,
  277|  1.29k|            .table_name = ctx->table_name,
  278|  1.29k|            .creation_time = ctx->timestamp,
  279|  1.29k|            .modified_time = ctx->timestamp,
  280|  1.29k|            .file_format_version = ctx->version
  281|  1.29k|        };
  282|  1.29k|        if (ctx->handle.metadata(&metadata, ctx->user_ctx) != READSTAT_HANDLER_OK) {
  ------------------
  |  |   22|  1.29k|#define READSTAT_HANDLER_OK             0
  ------------------
  |  Branch (282:13): [True: 0, False: 1.29k]
  ------------------
  283|      0|            retval = READSTAT_ERROR_USER_ABORT;
  284|      0|            goto cleanup;
  285|      0|        }
  286|  1.29k|    }
  287|       |
  288|  1.43k|cleanup:
  289|  1.43k|    return retval;
  290|  1.29k|}
readstat_xport_read.c:xport_read_variables:
  492|  1.29k|static readstat_error_t xport_read_variables(xport_ctx_t *ctx) {
  493|  1.29k|    int i;
  494|  1.29k|    readstat_error_t retval = READSTAT_OK;
  495|  98.5k|    for (i=0; i<ctx->var_count; i++) {
  ------------------
  |  Branch (495:15): [True: 97.3k, False: 1.22k]
  ------------------
  496|  97.3k|        xport_namestr_t namestr;
  497|  97.3k|        ssize_t bytes_read = read_bytes(ctx, &namestr, sizeof(xport_namestr_t));
  498|  97.3k|        if (bytes_read < sizeof(xport_namestr_t)) {
  ------------------
  |  Branch (498:13): [True: 68, False: 97.2k]
  ------------------
  499|     68|            retval = READSTAT_ERROR_READ;
  500|     68|            goto cleanup;
  501|     68|        }
  502|  97.2k|        xport_namestr_bswap(&namestr);
  503|       |
  504|  97.2k|        readstat_variable_t *variable = calloc(1, sizeof(readstat_variable_t));
  505|       |
  506|  97.2k|        variable->index = i;
  507|  97.2k|        variable->type = namestr.ntype == SAS_COLUMN_TYPE_CHR ? READSTAT_TYPE_STRING : READSTAT_TYPE_DOUBLE;
  ------------------
  |  |   91|  97.2k|#define SAS_COLUMN_TYPE_CHR  0x02
  ------------------
  |  Branch (507:26): [True: 151, False: 97.1k]
  ------------------
  508|  97.2k|        variable->storage_width = namestr.nlng;
  509|  97.2k|        variable->display_width = namestr.nfl;
  510|  97.2k|        variable->decimals = namestr.nfd;
  511|  97.2k|        variable->alignment = namestr.nfj ? READSTAT_ALIGNMENT_RIGHT : READSTAT_ALIGNMENT_LEFT;
  ------------------
  |  Branch (511:31): [True: 58.7k, False: 38.5k]
  ------------------
  512|       |
  513|  97.2k|        if (ctx->version == 5) {
  ------------------
  |  Branch (513:13): [True: 4.44k, False: 92.8k]
  ------------------
  514|  4.44k|            retval = readstat_convert(variable->name, sizeof(variable->name),
  515|  4.44k|                    namestr.nname, sizeof(namestr.nname), ctx->converter);
  516|  92.8k|        } else {
  517|  92.8k|            retval = readstat_convert(variable->name, sizeof(variable->name),
  518|  92.8k|                    namestr.longname, sizeof(namestr.longname), ctx->converter);
  519|  92.8k|        }
  520|  97.2k|        if (retval != READSTAT_OK)
  ------------------
  |  Branch (520:13): [True: 0, False: 97.2k]
  ------------------
  521|      0|            goto cleanup;
  522|       |
  523|  97.2k|        retval = readstat_convert(variable->label, sizeof(variable->label),
  524|  97.2k|                namestr.nlabel, sizeof(namestr.nlabel), ctx->converter);
  525|  97.2k|        if (retval != READSTAT_OK)
  ------------------
  |  Branch (525:13): [True: 0, False: 97.2k]
  ------------------
  526|      0|            goto cleanup;
  527|       |
  528|  97.2k|        retval = xport_construct_format(variable->format, sizeof(variable->format),
  529|  97.2k|                namestr.nform, sizeof(namestr.nform),
  530|  97.2k|                namestr.nfl, namestr.nfd);
  531|  97.2k|        if (retval != READSTAT_OK)
  ------------------
  |  Branch (531:13): [True: 0, False: 97.2k]
  ------------------
  532|      0|            goto cleanup;
  533|       |
  534|  97.2k|        retval = xport_construct_format(variable->informat, sizeof(variable->informat),
  535|  97.2k|                namestr.niform, sizeof(namestr.niform),
  536|  97.2k|                namestr.nifl, namestr.nifd);
  537|  97.2k|        if (retval != READSTAT_OK)
  ------------------
  |  Branch (537:13): [True: 0, False: 97.2k]
  ------------------
  538|      0|            goto cleanup;
  539|       |
  540|  97.2k|        ctx->variables[i] = variable;
  541|  97.2k|    }
  542|       |
  543|  1.22k|    retval = xport_skip_rest_of_record(ctx);
  544|  1.22k|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (544:9): [True: 30, False: 1.19k]
  ------------------
  545|     30|        goto cleanup;
  546|       |
  547|  1.19k|    if (ctx->version == 5) {
  ------------------
  |  Branch (547:9): [True: 112, False: 1.08k]
  ------------------
  548|    112|        retval = xport_read_obs_header_record(ctx);
  549|    112|        if (retval != READSTAT_OK)
  ------------------
  |  Branch (549:13): [True: 34, False: 78]
  ------------------
  550|     34|            goto cleanup;
  551|  1.08k|    } else {
  552|  1.08k|        xport_header_record_t xrecord;
  553|  1.08k|        retval = xport_read_header_record(ctx, &xrecord);
  554|  1.08k|        if (retval != READSTAT_OK)
  ------------------
  |  Branch (554:13): [True: 14, False: 1.07k]
  ------------------
  555|     14|            goto cleanup;
  556|       |
  557|  1.07k|        if (strcmp(xrecord.name, "OBSV8") == 0) {
  ------------------
  |  Branch (557:13): [True: 118, False: 953]
  ------------------
  558|       |            /* void */
  559|    953|        } else if (strcmp(xrecord.name, "LABELV8") == 0) {
  ------------------
  |  Branch (559:20): [True: 198, False: 755]
  ------------------
  560|    198|            retval = xport_read_labels_v8(ctx, xrecord.num1);
  561|    755|        } else if (strcmp(xrecord.name, "LABELV9") == 0) {
  ------------------
  |  Branch (561:20): [True: 252, False: 503]
  ------------------
  562|    252|            retval = xport_read_labels_v9(ctx, xrecord.num1);
  563|    252|        }
  564|  1.07k|        if (retval != READSTAT_OK)
  ------------------
  |  Branch (564:13): [True: 448, False: 623]
  ------------------
  565|    448|            goto cleanup;
  566|  1.07k|    }
  567|       |
  568|    701|    ctx->row_length = 0;
  569|       |
  570|    701|    int index_after_skipping = 0;
  571|       |
  572|  20.0k|    for (i=0; i<ctx->var_count; i++) {
  ------------------
  |  Branch (572:15): [True: 19.3k, False: 701]
  ------------------
  573|  19.3k|        readstat_variable_t *variable = ctx->variables[i];
  574|  19.3k|        variable->index_after_skipping = index_after_skipping;
  575|       |
  576|  19.3k|        int cb_retval = READSTAT_HANDLER_OK;
  ------------------
  |  |   22|  19.3k|#define READSTAT_HANDLER_OK             0
  ------------------
  577|  19.3k|        if (ctx->handle.variable) {
  ------------------
  |  Branch (577:13): [True: 19.3k, False: 0]
  ------------------
  578|  19.3k|            cb_retval = ctx->handle.variable(i, variable, variable->format, ctx->user_ctx);
  579|  19.3k|        }
  580|  19.3k|        if (cb_retval == READSTAT_HANDLER_ABORT) {
  ------------------
  |  |   23|  19.3k|#define READSTAT_HANDLER_ABORT          1
  ------------------
  |  Branch (580:13): [True: 0, False: 19.3k]
  ------------------
  581|      0|            retval = READSTAT_ERROR_USER_ABORT;
  582|      0|            goto cleanup;
  583|      0|        }
  584|  19.3k|        if (cb_retval == READSTAT_HANDLER_SKIP_VARIABLE) {
  ------------------
  |  |   24|  19.3k|#define READSTAT_HANDLER_SKIP_VARIABLE  2
  ------------------
  |  Branch (584:13): [True: 0, False: 19.3k]
  ------------------
  585|      0|            variable->skip = 1;
  586|  19.3k|        } else {
  587|  19.3k|            index_after_skipping++;
  588|  19.3k|        }
  589|       |
  590|  19.3k|        ctx->row_length += variable->storage_width;
  591|  19.3k|    }
  592|       |
  593|  1.29k|cleanup:
  594|  1.29k|    return retval;
  595|    701|}
readstat_xport_read.c:xport_construct_format:
  297|   194k|        const char *src, size_t src_len, int width, int decimals) {
  298|   194k|    char *format = malloc(4 * src_len + 1);
  299|   194k|    if (format == NULL) return READSTAT_ERROR_MALLOC;
  ------------------
  |  Branch (299:9): [True: 0, False: 194k]
  ------------------
  300|   194k|    readstat_error_t retval = readstat_convert(format, 4 * src_len + 1, src, src_len, NULL);
  301|       |
  302|   194k|    if (retval != READSTAT_OK) {
  ------------------
  |  Branch (302:9): [True: 0, False: 194k]
  ------------------
  303|      0|        free(format);
  304|      0|        return retval;
  305|      0|    }
  306|       |
  307|   194k|    char *pos = dst;
  308|   194k|    *dst = '\0';
  309|   194k|    if (format[0]) {
  ------------------
  |  Branch (309:9): [True: 68.4k, False: 126k]
  ------------------
  310|  68.4k|        pos += snprintf(dst, dst_len, "%s", format);
  311|  68.4k|    }
  312|   194k|    if (width) {
  ------------------
  |  Branch (312:9): [True: 117k, False: 77.3k]
  ------------------
  313|   117k|        pos += snprintf(pos, dst_len-(pos-dst), "%d", width);
  314|   117k|    }
  315|   194k|    if (decimals) {
  ------------------
  |  Branch (315:9): [True: 116k, False: 77.8k]
  ------------------
  316|   116k|        pos += snprintf(pos, dst_len-(pos-dst), ".%d", decimals);
  317|   116k|    } else if (width) {
  ------------------
  |  Branch (317:16): [True: 2.50k, False: 75.3k]
  ------------------
  318|  2.50k|        pos += snprintf(pos, dst_len-(pos-dst), ".");
  319|  2.50k|    }
  320|       |
  321|   194k|    free(format);
  322|   194k|    return retval;
  323|   194k|}
readstat_xport_read.c:xport_skip_rest_of_record:
   82|  1.42k|static readstat_error_t xport_skip_rest_of_record(xport_ctx_t *ctx) {
   83|  1.42k|    readstat_io_t *io = (readstat_io_t *)ctx->io;
   84|  1.42k|    off_t pos = io->seek(0, READSTAT_SEEK_CUR, io->io_ctx);
   85|  1.42k|    if (pos == -1)
  ------------------
  |  Branch (85:9): [True: 0, False: 1.42k]
  ------------------
   86|      0|        return READSTAT_ERROR_SEEK;
   87|       |
   88|  1.42k|    if (pos % LINE_LEN) {
  ------------------
  |  |   16|  1.42k|#define LINE_LEN        80
  ------------------
  |  Branch (88:9): [True: 1.26k, False: 157]
  ------------------
   89|  1.26k|        if (io->seek(LINE_LEN - (pos % LINE_LEN), READSTAT_SEEK_CUR, io->io_ctx) == -1)
  ------------------
  |  |   16|  1.26k|#define LINE_LEN        80
  ------------------
                      if (io->seek(LINE_LEN - (pos % LINE_LEN), READSTAT_SEEK_CUR, io->io_ctx) == -1)
  ------------------
  |  |   16|  1.26k|#define LINE_LEN        80
  ------------------
  |  Branch (89:13): [True: 74, False: 1.19k]
  ------------------
   90|     74|            return READSTAT_ERROR_SEEK;
   91|  1.26k|    }
   92|       |
   93|  1.34k|    return READSTAT_OK;
   94|  1.42k|}
readstat_xport_read.c:xport_read_obs_header_record:
  292|    262|static readstat_error_t xport_read_obs_header_record(xport_ctx_t *ctx) {
  293|    262|    return xport_expect_header_record(ctx, "OBS", "OBSV8");
  294|    262|}
readstat_xport_read.c:xport_read_labels_v8:
  325|    198|static readstat_error_t xport_read_labels_v8(xport_ctx_t *ctx, int label_count) {
  326|    198|    readstat_error_t retval = READSTAT_OK;
  327|    198|    uint16_t labeldef[3];
  328|    198|    char *name = NULL;
  329|    198|    char *label = NULL;
  330|    198|    int i;
  331|    705|    for (i=0; i<label_count; i++) {
  ------------------
  |  Branch (331:15): [True: 612, False: 93]
  ------------------
  332|    612|        int index, name_len, label_len;
  333|    612|        if (read_bytes(ctx, labeldef, sizeof(labeldef)) != sizeof(labeldef)) {
  ------------------
  |  Branch (333:13): [True: 28, False: 584]
  ------------------
  334|     28|            retval = READSTAT_ERROR_READ;
  335|     28|            goto cleanup;
  336|     28|        }
  337|       |
  338|    584|        if (machine_is_little_endian()) {
  ------------------
  |  Branch (338:13): [True: 584, False: 0]
  ------------------
  339|    584|            index = byteswap2(labeldef[0]);
  340|    584|            name_len = byteswap2(labeldef[1]);
  341|    584|            label_len = byteswap2(labeldef[2]);
  342|    584|        } else {
  343|      0|            index = labeldef[0];
  344|      0|            name_len = labeldef[1];
  345|      0|            label_len = labeldef[2];
  346|      0|        }
  347|       |
  348|    584|        if (index > ctx->var_count || index == 0) {
  ------------------
  |  Branch (348:13): [True: 18, False: 566]
  |  Branch (348:39): [True: 12, False: 554]
  ------------------
  349|     30|            retval = READSTAT_ERROR_PARSE;
  350|     30|            goto cleanup;
  351|     30|        }
  352|       |
  353|    554|        char *tmp_name = realloc(name, name_len + 1);
  354|    554|        if (tmp_name == NULL) { retval = READSTAT_ERROR_MALLOC; goto cleanup; }
  ------------------
  |  Branch (354:13): [True: 0, False: 554]
  ------------------
  355|    554|        name = tmp_name;
  356|       |
  357|    554|        char *tmp_label = realloc(label, label_len + 1);
  358|    554|        if (tmp_label == NULL) { retval = READSTAT_ERROR_MALLOC; goto cleanup; }
  ------------------
  |  Branch (358:13): [True: 0, False: 554]
  ------------------
  359|    554|        label = tmp_label;
  360|       |
  361|    554|        readstat_variable_t *variable = ctx->variables[index-1];
  362|       |
  363|    554|        if (read_bytes(ctx, name, name_len) != name_len ||
  ------------------
  |  Branch (363:13): [True: 26, False: 528]
  ------------------
  364|    528|                read_bytes(ctx, label, label_len) != label_len) {
  ------------------
  |  Branch (364:17): [True: 18, False: 510]
  ------------------
  365|     44|            retval = READSTAT_ERROR_READ;
  366|     44|            goto cleanup;
  367|     44|        }
  368|       |
  369|    510|        retval = readstat_convert(variable->name, sizeof(variable->name),
  370|    510|                name, name_len, ctx->converter);
  371|    510|        if (retval != READSTAT_OK)
  ------------------
  |  Branch (371:13): [True: 2, False: 508]
  ------------------
  372|      2|            goto cleanup;
  373|       |
  374|    508|        retval = readstat_convert(variable->label, sizeof(variable->label),
  375|    508|                label, label_len, ctx->converter);
  376|    508|        if (retval != READSTAT_OK)
  ------------------
  |  Branch (376:13): [True: 1, False: 507]
  ------------------
  377|      1|            goto cleanup;
  378|    508|    }
  379|       |
  380|     93|    retval = xport_skip_rest_of_record(ctx);
  381|     93|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (381:9): [True: 19, False: 74]
  ------------------
  382|     19|        goto cleanup;
  383|       |
  384|     74|    retval = xport_read_obs_header_record(ctx);
  385|     74|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (385:9): [True: 73, False: 1]
  ------------------
  386|     73|        goto cleanup;
  387|       |
  388|    198|cleanup:
  389|    198|    free(name);
  390|    198|    free(label);
  391|    198|    return retval;
  392|     74|}
readstat_xport_read.c:xport_read_labels_v9:
  394|    252|static readstat_error_t xport_read_labels_v9(xport_ctx_t *ctx, int label_count) {
  395|    252|    readstat_error_t retval = READSTAT_OK;
  396|    252|    uint16_t labeldef[5];
  397|    252|    int i;
  398|    252|    char *name = NULL;
  399|    252|    char *label = NULL;
  400|    252|    char *format = NULL;
  401|    252|    char *informat = NULL;
  402|       |
  403|    562|    for (i=0; i<label_count; i++) {
  ------------------
  |  Branch (403:15): [True: 461, False: 101]
  ------------------
  404|    461|        int index, name_len, label_len, format_len, informat_len;
  405|    461|        if (read_bytes(ctx, labeldef, sizeof(labeldef)) != sizeof(labeldef)) {
  ------------------
  |  Branch (405:13): [True: 30, False: 431]
  ------------------
  406|     30|            retval = READSTAT_ERROR_READ;
  407|     30|            goto cleanup;
  408|     30|        }
  409|       |
  410|    431|        if (machine_is_little_endian()) {
  ------------------
  |  Branch (410:13): [True: 431, False: 0]
  ------------------
  411|    431|            index = byteswap2(labeldef[0]);
  412|    431|            name_len = byteswap2(labeldef[1]);
  413|    431|            label_len = byteswap2(labeldef[2]);
  414|    431|            format_len = byteswap2(labeldef[3]);
  415|    431|            informat_len = byteswap2(labeldef[4]);
  416|    431|        } else {
  417|      0|            index = labeldef[0];
  418|      0|            name_len = labeldef[1];
  419|      0|            label_len = labeldef[2];
  420|      0|            format_len = labeldef[3];
  421|      0|            informat_len = labeldef[4];
  422|      0|        }
  423|       |
  424|    431|        if (index > ctx->var_count || index == 0) {
  ------------------
  |  Branch (424:13): [True: 16, False: 415]
  |  Branch (424:39): [True: 11, False: 404]
  ------------------
  425|     27|            retval = READSTAT_ERROR_PARSE;
  426|     27|            goto cleanup;
  427|     27|        }
  428|       |
  429|    404|        char *tmp_name = realloc(name, name_len + 1);
  430|    404|        if (tmp_name == NULL) { retval = READSTAT_ERROR_MALLOC; goto cleanup; }
  ------------------
  |  Branch (430:13): [True: 0, False: 404]
  ------------------
  431|    404|        name = tmp_name;
  432|       |
  433|    404|        char *tmp_label = realloc(label, label_len + 1);
  434|    404|        if (tmp_label == NULL) { retval = READSTAT_ERROR_MALLOC; goto cleanup; }
  ------------------
  |  Branch (434:13): [True: 0, False: 404]
  ------------------
  435|    404|        label = tmp_label;
  436|       |
  437|    404|        char *tmp_format = realloc(format, format_len + 1);
  438|    404|        if (tmp_format == NULL) { retval = READSTAT_ERROR_MALLOC; goto cleanup; }
  ------------------
  |  Branch (438:13): [True: 0, False: 404]
  ------------------
  439|    404|        format = tmp_format;
  440|       |
  441|    404|        char *tmp_informat = realloc(informat, informat_len + 1);
  442|    404|        if (tmp_informat == NULL) { retval = READSTAT_ERROR_MALLOC; goto cleanup; }
  ------------------
  |  Branch (442:13): [True: 0, False: 404]
  ------------------
  443|    404|        informat = tmp_informat;
  444|       |
  445|    404|        readstat_variable_t *variable = ctx->variables[index-1];
  446|       |
  447|    404|        if (read_bytes(ctx, name, name_len) != name_len ||
  ------------------
  |  Branch (447:13): [True: 25, False: 379]
  ------------------
  448|    379|                read_bytes(ctx, label, label_len) != label_len ||
  ------------------
  |  Branch (448:17): [True: 17, False: 362]
  ------------------
  449|    362|                read_bytes(ctx, format, format_len) != format_len ||
  ------------------
  |  Branch (449:17): [True: 16, False: 346]
  ------------------
  450|    346|                read_bytes(ctx, informat, informat_len) != informat_len) {
  ------------------
  |  Branch (450:17): [True: 18, False: 328]
  ------------------
  451|     76|            retval = READSTAT_ERROR_READ;
  452|     76|            goto cleanup;
  453|     76|        }
  454|       |
  455|    328|        retval = readstat_convert(variable->name, sizeof(variable->name),
  456|    328|                name, name_len, ctx->converter);
  457|    328|        if (retval != READSTAT_OK)
  ------------------
  |  Branch (457:13): [True: 1, False: 327]
  ------------------
  458|      1|            goto cleanup;
  459|       |
  460|    327|        retval = readstat_convert(variable->label, sizeof(variable->label),
  461|    327|                label, label_len, ctx->converter);
  462|    327|        if (retval != READSTAT_OK)
  ------------------
  |  Branch (462:13): [True: 1, False: 326]
  ------------------
  463|      1|            goto cleanup;
  464|       |
  465|    326|        retval = readstat_convert(variable->format, sizeof(variable->format),
  466|    326|                format, format_len, ctx->converter);
  467|    326|        if (retval != READSTAT_OK)
  ------------------
  |  Branch (467:13): [True: 13, False: 313]
  ------------------
  468|     13|            goto cleanup;
  469|       |
  470|    313|        retval = readstat_convert(variable->informat, sizeof(variable->informat),
  471|    313|                informat, informat_len, ctx->converter);
  472|    313|        if (retval != READSTAT_OK)
  ------------------
  |  Branch (472:13): [True: 3, False: 310]
  ------------------
  473|      3|            goto cleanup;
  474|    313|    }
  475|       |
  476|    101|    retval = xport_skip_rest_of_record(ctx);
  477|    101|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (477:9): [True: 25, False: 76]
  ------------------
  478|     25|        goto cleanup;
  479|       |
  480|     76|    retval = xport_read_obs_header_record(ctx);
  481|     76|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (481:9): [True: 75, False: 1]
  ------------------
  482|     75|        goto cleanup;
  483|       |
  484|    252|cleanup:
  485|    252|    free(name);
  486|    252|    free(format);
  487|    252|    free(informat);
  488|    252|    free(label);
  489|    252|    return retval;
  490|     76|}
readstat_xport_read.c:xport_read_data:
  663|    686|static readstat_error_t xport_read_data(xport_ctx_t *ctx) {
  664|    686|    if (!ctx->row_length)
  ------------------
  |  Branch (664:9): [True: 0, False: 686]
  ------------------
  665|      0|        return READSTAT_OK;
  666|       |
  667|    686|    if (!ctx->handle.value)
  ------------------
  |  Branch (667:9): [True: 0, False: 686]
  ------------------
  668|      0|        return READSTAT_OK;
  669|       |
  670|    686|    readstat_error_t retval = READSTAT_OK;
  671|    686|    char *row = readstat_malloc(ctx->row_length);
  672|    686|    char *blank_row = readstat_malloc(ctx->row_length);
  673|    686|    int num_blank_rows = 0;
  674|    686|    long rows_read = 0;
  675|       |
  676|    686|    if (row == NULL || blank_row == NULL) {
  ------------------
  |  Branch (676:9): [True: 7, False: 679]
  |  Branch (676:24): [True: 0, False: 679]
  ------------------
  677|      7|        retval = READSTAT_ERROR_MALLOC;
  678|      7|        goto cleanup;
  679|      7|    }
  680|       |
  681|    679|    memset(blank_row, ' ', ctx->row_length);
  682|   616k|    while (1) {
  ------------------
  |  Branch (682:12): [True: 616k, Folded]
  ------------------
  683|   616k|        if (ctx->obs_count > 0 && rows_read == ctx->obs_count)
  ------------------
  |  Branch (683:13): [True: 10.0k, False: 606k]
  |  Branch (683:35): [True: 3, False: 10.0k]
  ------------------
  684|      3|            break;
  685|       |
  686|   616k|        ssize_t bytes_read = read_bytes(ctx, row, ctx->row_length);
  687|   616k|        if (bytes_read == -1) {
  ------------------
  |  Branch (687:13): [True: 0, False: 616k]
  ------------------
  688|      0|            retval = READSTAT_ERROR_READ;
  689|      0|            goto cleanup;
  690|   616k|        } else if (bytes_read < ctx->row_length) {
  ------------------
  |  Branch (690:20): [True: 676, False: 615k]
  ------------------
  691|    676|            break;
  692|    676|        }
  693|   615k|        rows_read++;
  694|       |
  695|   615k|        off_t pos = 0;
  696|       |
  697|       |        /* When the row count is known, blank rows are real data rather
  698|       |         * than potential end-of-file padding */
  699|   615k|        int row_is_blank = ctx->obs_count <= 0;
  700|       |
  701|  2.02M|        for (pos=0; pos<ctx->row_length; pos++) {
  ------------------
  |  Branch (701:21): [True: 1.51M, False: 509k]
  ------------------
  702|  1.51M|            if (row[pos] != ' ') {
  ------------------
  |  Branch (702:17): [True: 106k, False: 1.40M]
  ------------------
  703|   106k|                row_is_blank = 0;
  704|   106k|                break;
  705|   106k|            }
  706|  1.51M|        }
  707|       |
  708|   615k|        if (row_is_blank) {
  ------------------
  |  Branch (708:13): [True: 503k, False: 112k]
  ------------------
  709|   503k|            num_blank_rows++;
  710|   503k|            continue;
  711|   503k|        }
  712|       |
  713|   603k|        while (num_blank_rows) {
  ------------------
  |  Branch (713:16): [True: 491k, False: 112k]
  ------------------
  714|   491k|            retval = xport_process_row(ctx, blank_row, ctx->row_length);
  715|   491k|            if (retval != READSTAT_OK)
  ------------------
  |  Branch (715:17): [True: 0, False: 491k]
  ------------------
  716|      0|                goto cleanup;
  717|       |
  718|   491k|            if (ctx->row_limit > 0 && ctx->parsed_row_count == ctx->row_limit)
  ------------------
  |  Branch (718:17): [True: 0, False: 491k]
  |  Branch (718:39): [True: 0, False: 0]
  ------------------
  719|      0|                goto cleanup;
  720|       |
  721|   491k|            num_blank_rows--;
  722|   491k|        }
  723|       |
  724|   112k|        retval = xport_process_row(ctx, row, ctx->row_length);
  725|   112k|        if (retval != READSTAT_OK)
  ------------------
  |  Branch (725:13): [True: 0, False: 112k]
  ------------------
  726|      0|            goto cleanup;
  727|       |
  728|   112k|        retval = xport_update_progress(ctx);
  729|   112k|        if (retval != READSTAT_OK)
  ------------------
  |  Branch (729:13): [True: 0, False: 112k]
  ------------------
  730|      0|            goto cleanup;
  731|       |
  732|   112k|        if (ctx->row_limit > 0 && ctx->parsed_row_count == ctx->row_limit)
  ------------------
  |  Branch (732:13): [True: 0, False: 112k]
  |  Branch (732:35): [True: 0, False: 0]
  ------------------
  733|      0|            break;
  734|   112k|    }
  735|       |
  736|       |    /* Padding never fills a whole line, so blank rows at least a line
  737|       |     * wide are data rather than end-of-file padding */
  738|    679|    if (ctx->row_length >= LINE_LEN) {
  ------------------
  |  |   16|    679|#define LINE_LEN        80
  ------------------
  |  Branch (738:9): [True: 204, False: 475]
  ------------------
  739|  8.76k|        while (num_blank_rows) {
  ------------------
  |  Branch (739:16): [True: 8.56k, False: 204]
  ------------------
  740|  8.56k|            if (ctx->row_limit > 0 && ctx->parsed_row_count == ctx->row_limit)
  ------------------
  |  Branch (740:17): [True: 0, False: 8.56k]
  |  Branch (740:39): [True: 0, False: 0]
  ------------------
  741|      0|                break;
  742|       |
  743|  8.56k|            retval = xport_process_row(ctx, blank_row, ctx->row_length);
  744|  8.56k|            if (retval != READSTAT_OK)
  ------------------
  |  Branch (744:17): [True: 0, False: 8.56k]
  ------------------
  745|      0|                goto cleanup;
  746|       |
  747|  8.56k|            num_blank_rows--;
  748|  8.56k|        }
  749|    204|    }
  750|       |
  751|    686|cleanup:
  752|    686|    if (row)
  ------------------
  |  Branch (752:9): [True: 679, False: 7]
  ------------------
  753|    679|        free(row);
  754|    686|    if (blank_row)
  ------------------
  |  Branch (754:9): [True: 679, False: 7]
  ------------------
  755|    679|        free(blank_row);
  756|    686|    return retval;
  757|    679|}
readstat_xport_read.c:xport_process_row:
  597|   612k|static readstat_error_t xport_process_row(xport_ctx_t *ctx, const char *row, size_t row_length) {
  598|   612k|    readstat_error_t retval = READSTAT_OK;
  599|   612k|    int i;
  600|   612k|    off_t pos = 0;
  601|   612k|    char *string = NULL;
  602|  1.22M|    for (i=0; i<ctx->var_count; i++) {
  ------------------
  |  Branch (602:15): [True: 612k, False: 612k]
  ------------------
  603|   612k|        readstat_variable_t *variable = ctx->variables[i];
  604|   612k|        readstat_value_t value = { .type = variable->type };
  605|       |
  606|   612k|        if (variable->type == READSTAT_TYPE_STRING) {
  ------------------
  |  Branch (606:13): [True: 427k, False: 184k]
  ------------------
  607|   427k|            string = readstat_realloc(string, 4*variable->storage_width+1);
  608|   427k|            if (string == NULL) {
  ------------------
  |  Branch (608:17): [True: 0, False: 427k]
  ------------------
  609|      0|                retval = READSTAT_ERROR_MALLOC;
  610|      0|                goto cleanup;
  611|      0|            }
  612|   427k|            retval = readstat_convert(string, 4*variable->storage_width+1,
  613|   427k|                    &row[pos], variable->storage_width, ctx->converter);
  614|   427k|            if (retval != READSTAT_OK)
  ------------------
  |  Branch (614:17): [True: 0, False: 427k]
  ------------------
  615|      0|                goto cleanup;
  616|       |
  617|   427k|            value.v.string_value = string;
  618|   427k|        } else {
  619|   184k|            double dval = NAN;
  620|   184k|            if (variable->storage_width <= XPORT_MAX_DOUBLE_SIZE &&
  ------------------
  |  |   45|   369k|#define XPORT_MAX_DOUBLE_SIZE   8
  ------------------
  |  Branch (620:17): [True: 184k, False: 224]
  ------------------
  621|   184k|                    variable->storage_width >= XPORT_MIN_DOUBLE_SIZE) {
  ------------------
  |  |   44|   184k|#define XPORT_MIN_DOUBLE_SIZE   3
  ------------------
  |  Branch (621:21): [True: 140k, False: 44.1k]
  ------------------
  622|   140k|                char full_value[8] = { 0 };
  623|   140k|                if (memcmp(&full_value[1], &row[pos+1], variable->storage_width - 1) == 0 &&
  ------------------
  |  Branch (623:21): [True: 23.8k, False: 116k]
  ------------------
  624|  23.8k|                        (row[pos] == '.' || sas_validate_tag(row[pos]) == READSTAT_OK)) {
  ------------------
  |  Branch (624:26): [True: 201, False: 23.6k]
  |  Branch (624:45): [True: 435, False: 23.1k]
  ------------------
  625|    636|                    if (row[pos] == '.') {
  ------------------
  |  Branch (625:25): [True: 201, False: 435]
  ------------------
  626|    201|                        value.is_system_missing = 1;
  627|    435|                    } else {
  628|    435|                        value.tag = row[pos];
  629|    435|                        value.is_tagged_missing = 1;
  630|    435|                    }
  631|   139k|                } else {
  632|   139k|                    memcpy(full_value, &row[pos], variable->storage_width);
  633|   139k|                    int rc = cnxptiee(full_value, CN_TYPE_XPORT, &dval, CN_TYPE_NATIVE);
  ------------------
  |  |    2|   139k|#define CN_TYPE_XPORT 1
  ------------------
                                  int rc = cnxptiee(full_value, CN_TYPE_XPORT, &dval, CN_TYPE_NATIVE);
  ------------------
  |  |    1|   139k|#define CN_TYPE_NATIVE 0
  ------------------
  634|   139k|                    if (rc != 0) {
  ------------------
  |  Branch (634:25): [True: 0, False: 139k]
  ------------------
  635|      0|                        retval = READSTAT_ERROR_CONVERT;
  636|      0|                        goto cleanup;
  637|      0|                    }
  638|   139k|                }
  639|   140k|            }
  640|       |
  641|   184k|            value.v.double_value = dval;
  642|   184k|        }
  643|   612k|        pos += variable->storage_width;
  644|       |
  645|   612k|        if (ctx->handle.value && !ctx->variables[i]->skip && !ctx->row_offset) {
  ------------------
  |  Branch (645:13): [True: 612k, False: 0]
  |  Branch (645:34): [True: 612k, False: 0]
  |  Branch (645:62): [True: 612k, False: 0]
  ------------------
  646|   612k|            if (ctx->handle.value(ctx->parsed_row_count, variable, value, ctx->user_ctx) != READSTAT_HANDLER_OK) {
  ------------------
  |  |   22|   612k|#define READSTAT_HANDLER_OK             0
  ------------------
  |  Branch (646:17): [True: 0, False: 612k]
  ------------------
  647|      0|                retval = READSTAT_ERROR_USER_ABORT;
  648|      0|                goto cleanup;
  649|      0|            }
  650|   612k|        }
  651|   612k|    }
  652|   612k|    if (ctx->row_offset) {
  ------------------
  |  Branch (652:9): [True: 0, False: 612k]
  ------------------
  653|      0|        ctx->row_offset--;
  654|   612k|    } else {
  655|   612k|        ctx->parsed_row_count++;
  656|   612k|    }
  657|       |
  658|   612k|cleanup:
  659|   612k|    free(string);
  660|   612k|    return retval;
  661|   612k|}
readstat_xport_read.c:xport_update_progress:
   43|   112k|static readstat_error_t xport_update_progress(xport_ctx_t *ctx) {
   44|   112k|    readstat_io_t *io = ctx->io;
   45|   112k|    return io->update(ctx->file_size, ctx->handle.progress, ctx->user_ctx, io->io_ctx);
   46|   112k|}
readstat_xport_read.c:xport_ctx_free:
   53|  1.86k|static void xport_ctx_free(xport_ctx_t *ctx) {
   54|  1.86k|    if (ctx->variables) {
  ------------------
  |  Branch (54:9): [True: 1.29k, False: 574]
  ------------------
   55|  1.29k|        int i;
   56|  1.29M|        for (i=0; i<ctx->var_count; i++) {
  ------------------
  |  Branch (56:19): [True: 1.29M, False: 1.29k]
  ------------------
   57|  1.29M|            if (ctx->variables[i])
  ------------------
  |  Branch (57:17): [True: 97.2k, False: 1.19M]
  ------------------
   58|  97.2k|                free(ctx->variables[i]);
   59|  1.29M|        }
   60|  1.29k|        free(ctx->variables);
   61|  1.29k|    }
   62|  1.86k|    if (ctx->converter) {
  ------------------
  |  Branch (62:9): [True: 0, False: 1.86k]
  ------------------
   63|      0|        iconv_close(ctx->converter);
   64|      0|    }
   65|       |
   66|  1.86k|    free(ctx);
   67|  1.86k|}

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

