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

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

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

readstat_convert:
    7|   238k|readstat_error_t readstat_convert(char *dst, size_t dst_len, const char *src, size_t src_len, iconv_t converter) {
    8|       |    /* strip off spaces from the input because the programs use ASCII space
    9|       |     * padding even with non-ASCII encoding. */
   10|  4.43M|    while (src_len && (src[src_len-1] == ' ' || src[src_len-1] == '\0')) {
  ------------------
  |  Branch (10:12): [True: 4.30M, False: 127k]
  |  Branch (10:24): [True: 2.04M, False: 2.25M]
  |  Branch (10:49): [True: 2.14M, False: 110k]
  ------------------
   11|  4.19M|        src_len--;
   12|  4.19M|    }
   13|   238k|    if (dst_len == 0) {
  ------------------
  |  Branch (13:9): [True: 0, False: 238k]
  ------------------
   14|      0|        return READSTAT_ERROR_CONVERT_LONG_STRING;
   15|   238k|    } else if (converter) {
  ------------------
  |  Branch (15:16): [True: 0, False: 238k]
  ------------------
   16|      0|        size_t dst_left = dst_len - 1;
   17|      0|        char *dst_end = dst;
   18|      0|        size_t status = iconv(converter, (readstat_iconv_inbuf_t)&src, &src_len, &dst_end, &dst_left);
   19|      0|        if (status == (size_t)-1) {
  ------------------
  |  Branch (19:13): [True: 0, False: 0]
  ------------------
   20|      0|            if (errno == E2BIG) {
  ------------------
  |  Branch (20:17): [True: 0, False: 0]
  ------------------
   21|      0|                return READSTAT_ERROR_CONVERT_LONG_STRING;
   22|      0|            } else if (errno == EILSEQ) {
  ------------------
  |  Branch (22:24): [True: 0, False: 0]
  ------------------
   23|      0|                return READSTAT_ERROR_CONVERT_BAD_STRING;
   24|      0|            } else if (errno != EINVAL) { /* EINVAL indicates improper truncation; accept it */
  ------------------
  |  Branch (24:24): [True: 0, False: 0]
  ------------------
   25|      0|                return READSTAT_ERROR_CONVERT;
   26|      0|            }
   27|      0|        }
   28|      0|        dst[dst_len - dst_left - 1] = '\0';
   29|   238k|    } else if (src_len + 1 > dst_len) {
  ------------------
  |  Branch (29:16): [True: 21, False: 238k]
  ------------------
   30|     21|        return READSTAT_ERROR_CONVERT_LONG_STRING;
   31|   238k|    } else {
   32|   238k|        memcpy(dst, src, src_len);
   33|   238k|        dst[src_len] = '\0';
   34|   238k|    }
   35|   238k|    return READSTAT_OK;
   36|   238k|}

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

readstat_malloc:
   10|  1.22k|void *readstat_malloc(size_t len) {
   11|  1.22k|    if (len > MAX_MALLOC_SIZE || len == 0) {
  ------------------
  |  |    3|  2.44k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
  |  Branch (11:9): [True: 12, False: 1.21k]
  |  Branch (11:34): [True: 0, False: 1.21k]
  ------------------
   12|     12|        return NULL;
   13|     12|    }
   14|  1.21k|    return malloc(len);
   15|  1.22k|}
readstat_calloc:
   17|  1.11k|void *readstat_calloc(size_t count, size_t size) {
   18|  1.11k|    if (count > MAX_MALLOC_SIZE || size > MAX_MALLOC_SIZE || count * size > MAX_MALLOC_SIZE) {
  ------------------
  |  |    3|  2.22k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
                  if (count > MAX_MALLOC_SIZE || size > MAX_MALLOC_SIZE || count * size > MAX_MALLOC_SIZE) {
  ------------------
  |  |    3|  2.21k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
                  if (count > MAX_MALLOC_SIZE || size > MAX_MALLOC_SIZE || count * size > MAX_MALLOC_SIZE) {
  ------------------
  |  |    3|  1.09k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
  |  Branch (18:9): [True: 14, False: 1.09k]
  |  Branch (18:36): [True: 0, False: 1.09k]
  |  Branch (18:62): [True: 0, False: 1.09k]
  ------------------
   19|     14|        return NULL;
   20|     14|    }
   21|  1.09k|    if (count == 0 || size == 0) {
  ------------------
  |  Branch (21:9): [True: 1, False: 1.09k]
  |  Branch (21:23): [True: 0, False: 1.09k]
  ------------------
   22|      1|        return NULL;
   23|      1|    }
   24|  1.09k|    return calloc(count, size);
   25|  1.09k|}
readstat_realloc:
   27|  1.12k|void *readstat_realloc(void *ptr, size_t len) {
   28|  1.12k|    if (len > MAX_MALLOC_SIZE || len == 0) {
  ------------------
  |  |    3|  2.25k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
  |  Branch (28:9): [True: 0, False: 1.12k]
  |  Branch (28:34): [True: 0, False: 1.12k]
  ------------------
   29|      0|        if (ptr)
  ------------------
  |  Branch (29:13): [True: 0, False: 0]
  ------------------
   30|      0|            free(ptr);
   31|      0|        return NULL;
   32|      0|    }
   33|  1.12k|    return realloc(ptr, len);
   34|  1.12k|}

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

memreverse:
   22|  90.5k|void memreverse(void *intp_void, int l) {
   23|  90.5k|    if (!machine_is_little_endian())
  ------------------
  |  Branch (23:9): [True: 0, False: 90.5k]
  ------------------
   24|      0|        return;
   25|       |
   26|  90.5k|    int i,j;
   27|  90.5k|    char save;
   28|  90.5k|    char *intp = (char *)intp_void;
   29|       |
   30|  90.5k|    j = l/2;
   31|   271k|    for (i=0;i<j;i++) {
  ------------------
  |  Branch (31:14): [True: 181k, False: 90.5k]
  ------------------
   32|   181k|        save = intp[i];
   33|   181k|        intp[i] = intp[l-i-1];
   34|   181k|        intp[l-i-1] = save;
   35|   181k|    }
   36|  90.5k|}
cnxptiee:
   39|  39.6k|{
   40|  39.6k|    unsigned char *from = (unsigned char *)from_bytes;
   41|  39.6k|    unsigned char *to = (unsigned char *)to_bytes;
   42|  39.6k|    unsigned char temp[8];
   43|  39.6k|    int i;
   44|       |
   45|  39.6k|    if (fromtype == CN_TYPE_NATIVE) {
  ------------------
  |  |    1|  39.6k|#define CN_TYPE_NATIVE 0
  ------------------
  |  Branch (45:9): [True: 0, False: 39.6k]
  ------------------
   46|      0|        fromtype = FLOATREP;
  ------------------
  |  |   18|      0|#define FLOATREP get_native()
  ------------------
   47|      0|    }
   48|  39.6k|    switch(fromtype) {
   49|      0|        case CN_TYPE_IEEEL :
  ------------------
  |  |    4|      0|#define CN_TYPE_IEEEL 3
  ------------------
  |  Branch (49:9): [True: 0, False: 39.6k]
  ------------------
   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: 39.6k]
  ------------------
   59|       |            /* Break intentionally omitted. */
   60|  39.6k|        case CN_TYPE_XPORT :
  ------------------
  |  |    2|  39.6k|#define CN_TYPE_XPORT 1
  ------------------
  |  Branch (60:9): [True: 39.6k, False: 0]
  ------------------
   61|  39.6k|            break;
   62|      0|        default:
  ------------------
  |  Branch (62:9): [True: 0, False: 39.6k]
  ------------------
   63|      0|            return(-1);
   64|  39.6k|    }
   65|  39.6k|    if (totype == CN_TYPE_NATIVE) {
  ------------------
  |  |    1|  39.6k|#define CN_TYPE_NATIVE 0
  ------------------
  |  Branch (65:9): [True: 39.6k, False: 0]
  ------------------
   66|  39.6k|        totype = FLOATREP;
  ------------------
  |  |   18|  39.6k|#define FLOATREP get_native()
  ------------------
   67|  39.6k|    }
   68|  39.6k|    switch(totype) {
   69|      0|        case CN_TYPE_XPORT :
  ------------------
  |  |    2|      0|#define CN_TYPE_XPORT 1
  ------------------
  |  Branch (69:9): [True: 0, False: 39.6k]
  ------------------
   70|      0|        case CN_TYPE_IEEEB :
  ------------------
  |  |    3|      0|#define CN_TYPE_IEEEB 2
  ------------------
  |  Branch (70:9): [True: 0, False: 39.6k]
  ------------------
   71|  39.6k|        case CN_TYPE_IEEEL :
  ------------------
  |  |    4|  39.6k|#define CN_TYPE_IEEEL 3
  ------------------
  |  Branch (71:9): [True: 39.6k, False: 0]
  ------------------
   72|  39.6k|            break;
   73|      0|        default:
  ------------------
  |  Branch (73:9): [True: 0, False: 39.6k]
  ------------------
   74|      0|            return(-2);
   75|  39.6k|    }
   76|  39.6k|    if (fromtype == totype) {
  ------------------
  |  Branch (76:9): [True: 0, False: 39.6k]
  ------------------
   77|      0|        memcpy(to,from,8);
   78|      0|        return(0);
   79|      0|    }
   80|  39.6k|    switch(fromtype) {
  ------------------
  |  Branch (80:12): [True: 39.6k, False: 0]
  ------------------
   81|      0|        case CN_TYPE_IEEEB :
  ------------------
  |  |    3|      0|#define CN_TYPE_IEEEB 2
  ------------------
  |  Branch (81:9): [True: 0, False: 39.6k]
  ------------------
   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|  39.6k|        case CN_TYPE_XPORT :
  ------------------
  |  |    2|  39.6k|#define CN_TYPE_XPORT 1
  ------------------
  |  Branch (86:9): [True: 39.6k, False: 0]
  ------------------
   87|  39.6k|            xpt2ieee(from,to);
   88|  39.6k|            break;
   89|  39.6k|    }
   90|  39.6k|    if (totype == CN_TYPE_IEEEL) {
  ------------------
  |  |    4|  39.6k|#define CN_TYPE_IEEEL 3
  ------------------
  |  Branch (90:9): [True: 39.6k, False: 0]
  ------------------
   91|  39.6k|        memcpy(temp,to,8);
   92|   357k|        for (i=7;i>=0;i--) {
  ------------------
  |  Branch (92:18): [True: 317k, False: 39.6k]
  ------------------
   93|   317k|            to[7-i] = temp[i];
   94|   317k|        }
   95|  39.6k|    }
   96|  39.6k|    return(0);
   97|  39.6k|}
get_native:
   99|  39.6k|int get_native(void) {
  100|  39.6k|    static unsigned char float_reps[][8] = {
  101|  39.6k|        {0x41,0x10,0x00,0x00,0x00,0x00,0x00,0x00},
  102|  39.6k|        {0x3f,0xf0,0x00,0x00,0x00,0x00,0x00,0x00},
  103|  39.6k|        {0x00,0x00,0x00,0x00,0x00,0x00,0xf0,0x3f}
  104|  39.6k|    };
  105|       |
  106|  39.6k|    static double one = 1.00;
  107|       |
  108|  39.6k|    int i,j;
  109|  39.6k|    j = sizeof(float_reps)/8;
  110|   119k|    for (i=0;i<j;i++)  {
  ------------------
  |  Branch (110:14): [True: 119k, False: 0]
  ------------------
  111|   119k|        if (memcmp(&one,float_reps+i,8) == 0)
  ------------------
  |  Branch (111:13): [True: 39.6k, False: 79.3k]
  ------------------
  112|  39.6k|            return(i+1);
  113|   119k|    }
  114|      0|    return(-1);
  115|  39.6k|}
ieee.c:xpt2ieee:
  117|  39.6k|void xpt2ieee(unsigned char *xport, unsigned char *ieee) {
  118|  39.6k|    char temp[8];
  119|  39.6k|    register int shift;
  120|  39.6k|    register int nib;
  121|  39.6k|    uint32_t ieee1,ieee2;
  122|  39.6k|    uint32_t xport1 = 0;
  123|  39.6k|    uint32_t xport2 = 0;
  124|       |
  125|  39.6k|    memcpy(temp,xport,8);
  126|  39.6k|    memset(ieee,0,8);
  127|       |
  128|  39.6k|    if (*temp && memcmp(temp+1,ieee,7) == 0) {
  ------------------
  |  Branch (128:9): [True: 5.84k, False: 33.8k]
  |  Branch (128:18): [True: 231, False: 5.61k]
  ------------------
  129|    231|        ieee[0] = ieee[1] = 0xff;
  130|    231|        ieee[2] = ~(*temp);
  131|    231|        return;
  132|    231|    }
  133|       |
  134|  39.4k|    memcpy(&xport1,temp,sizeof(uint32_t));
  135|  39.4k|    memreverse(&xport1,sizeof(uint32_t));
  136|  39.4k|    memcpy(&xport2,temp+4,sizeof(uint32_t));
  137|  39.4k|    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|  39.4k|    if ((xport1 & 0x7fffffff) == 0x7fffffff && xport2 == 0xffffffff) {
  ------------------
  |  Branch (184:9): [True: 606, False: 38.8k]
  |  Branch (184:48): [True: 194, False: 412]
  ------------------
  185|    194|        ieee1 = (xport1 & 0x80000000) | 0x7ff00000;
  186|    194|        ieee2 = 0;
  187|    194|        goto doret;
  188|    194|    }
  189|       |
  190|       |    /* Get the first half of the ibm number without the exponent */
  191|       |    /* into the ieee number */
  192|  39.2k|    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|  39.2k|    if ((!(ieee2 = xport2)) && !xport1)
  ------------------
  |  Branch (197:9): [True: 35.1k, False: 4.11k]
  |  Branch (197:32): [True: 33.6k, False: 1.51k]
  ------------------
  198|  33.6k|        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|  5.62k|    if ((nib = (int)xport1) & 0x00800000) {
  ------------------
  |  Branch (206:9): [True: 2.80k, False: 2.82k]
  ------------------
  207|  2.80k|        shift = 3;
  208|  2.82k|    } else if (nib & 0x00400000) {
  ------------------
  |  Branch (208:16): [True: 726, False: 2.09k]
  ------------------
  209|    726|        shift = 2;
  210|  2.09k|    } else if (nib & 0x00200000) {
  ------------------
  |  Branch (210:16): [True: 1.62k, False: 470]
  ------------------
  211|  1.62k|        shift = 1;
  212|  1.62k|    } else {
  213|    470|        shift = 0;
  214|    470|    }
  215|       |
  216|  5.62k|    if (shift) {
  ------------------
  |  Branch (216:9): [True: 5.15k, False: 470]
  ------------------
  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|  5.15k|        ieee1 >>= shift;
  225|  5.15k|        ieee2 = (xport2 >> shift) |
  226|  5.15k|            ((xport1 & 0x00000007) << (29 + (3 - shift)));
  227|  5.15k|    }
  228|       |
  229|       |    /* clear the 1 bit to the left of the binary point */
  230|  5.62k|    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|  5.62k|    ieee1 |=
  239|  5.62k|        (((((int32_t)(*temp & 0x7f) - 65) * 4) + shift + 1023) << 20) |
  240|  5.62k|        (xport1 & 0x80000000);
  241|       |
  242|  5.82k|doret:
  243|  5.82k|    memreverse(&ieee1,sizeof(uint32_t));
  244|  5.82k|    memcpy(ieee,&ieee1,sizeof(uint32_t));
  245|  5.82k|    memreverse(&ieee2,sizeof(uint32_t));
  246|  5.82k|    memcpy(ieee+4,&ieee2,sizeof(uint32_t));
  247|  5.82k|    return;
  248|  5.62k|}

sas_validate_tag:
  507|  34.2k|readstat_error_t sas_validate_tag(char tag) {
  508|  34.2k|    if (tag == '_' || (tag >= 'A' && tag <= 'Z'))
  ------------------
  |  Branch (508:9): [True: 197, False: 34.0k]
  |  Branch (508:24): [True: 408, False: 33.6k]
  |  Branch (508:38): [True: 203, False: 205]
  ------------------
  509|    400|        return READSTAT_OK;
  510|       |
  511|  33.8k|    return READSTAT_ERROR_TAGGED_VALUE_IS_OUT_OF_RANGE;
  512|  34.2k|}

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

readstat_parse_xport:
  692|  1.59k|readstat_error_t readstat_parse_xport(readstat_parser_t *parser, const char *path, void *user_ctx) {
  693|  1.59k|    readstat_error_t retval = READSTAT_OK;
  694|  1.59k|    readstat_io_t *io = parser->io;
  695|       |
  696|  1.59k|    xport_ctx_t *ctx = xport_ctx_init();
  697|  1.59k|    ctx->handle = parser->handlers;
  698|  1.59k|    ctx->input_encoding = parser->input_encoding;
  699|  1.59k|    ctx->output_encoding = parser->output_encoding;
  700|  1.59k|    ctx->user_ctx = user_ctx;
  701|  1.59k|    ctx->io = io;
  702|  1.59k|    ctx->row_limit = parser->row_limit;
  703|  1.59k|    if (parser->row_offset > 0)
  ------------------
  |  Branch (703:9): [True: 0, False: 1.59k]
  ------------------
  704|      0|        ctx->row_offset = parser->row_offset;
  705|       |
  706|  1.59k|    if (io->open(path, io->io_ctx) == -1) {
  ------------------
  |  Branch (706:9): [True: 0, False: 1.59k]
  ------------------
  707|      0|        retval = READSTAT_ERROR_OPEN;
  708|      0|        goto cleanup;
  709|      0|    }
  710|       |
  711|  1.59k|    if ((ctx->file_size = io->seek(0, READSTAT_SEEK_END, io->io_ctx)) == -1) {
  ------------------
  |  Branch (711:9): [True: 0, False: 1.59k]
  ------------------
  712|      0|        retval = READSTAT_ERROR_SEEK;
  713|      0|        goto cleanup;
  714|      0|    }
  715|       |
  716|  1.59k|    if (io->seek(0, READSTAT_SEEK_SET, io->io_ctx) == -1) {
  ------------------
  |  Branch (716:9): [True: 0, False: 1.59k]
  ------------------
  717|      0|        retval = READSTAT_ERROR_SEEK;
  718|      0|        goto cleanup;
  719|      0|    }
  720|       |
  721|  1.59k|    if (ctx->input_encoding && ctx->output_encoding && strcmp(ctx->input_encoding, ctx->output_encoding) != 0) {
  ------------------
  |  Branch (721:9): [True: 0, False: 1.59k]
  |  Branch (721:32): [True: 0, False: 0]
  |  Branch (721:56): [True: 0, False: 0]
  ------------------
  722|      0|        iconv_t converter = iconv_open(ctx->output_encoding, ctx->input_encoding);
  723|      0|        if (converter == (iconv_t)-1) {
  ------------------
  |  Branch (723:13): [True: 0, False: 0]
  ------------------
  724|      0|            retval = READSTAT_ERROR_UNSUPPORTED_CHARSET;
  725|      0|            goto cleanup;
  726|      0|        }
  727|      0|        ctx->converter = converter;
  728|      0|    }
  729|       |
  730|  1.59k|    retval = xport_read_library_record(ctx);
  731|  1.59k|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (731:9): [True: 101, False: 1.49k]
  ------------------
  732|    101|        goto cleanup;
  733|       |
  734|  1.49k|    retval = xport_skip_record(ctx);
  735|  1.49k|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (735:9): [True: 10, False: 1.48k]
  ------------------
  736|     10|        goto cleanup;
  737|       |
  738|  1.48k|    retval = xport_read_timestamp_record(ctx);
  739|  1.48k|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (739:9): [True: 12, False: 1.47k]
  ------------------
  740|     12|        goto cleanup;
  741|       |
  742|  1.47k|    retval = xport_expect_header_record(ctx, "MEMBER", "MEMBV8");
  743|  1.47k|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (743:9): [True: 154, False: 1.31k]
  ------------------
  744|    154|        goto cleanup;
  745|       |
  746|  1.31k|    retval = xport_expect_header_record(ctx, "DSCRPTR", "DSCPTV8");
  747|  1.31k|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (747:9): [True: 20, False: 1.29k]
  ------------------
  748|     20|        goto cleanup;
  749|       |
  750|  1.29k|    retval = xport_read_table_name_record(ctx);
  751|  1.29k|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (751:9): [True: 13, False: 1.28k]
  ------------------
  752|     13|        goto cleanup;
  753|       |
  754|  1.28k|    retval = xport_read_file_label_record(ctx);
  755|  1.28k|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (755:9): [True: 33, False: 1.25k]
  ------------------
  756|     33|        goto cleanup;
  757|       |
  758|  1.25k|    retval = xport_read_namestr_header_record(ctx);
  759|  1.25k|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (759:9): [True: 155, False: 1.09k]
  ------------------
  760|    155|        goto cleanup;
  761|       |
  762|  1.09k|    retval = xport_read_variables(ctx);
  763|  1.09k|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (763:9): [True: 478, False: 620]
  ------------------
  764|    478|        goto cleanup;
  765|       |
  766|    620|    if (ctx->row_length) {
  ------------------
  |  Branch (766:9): [True: 611, False: 9]
  ------------------
  767|    611|        retval = xport_read_data(ctx);
  768|    611|        if (retval != READSTAT_OK)
  ------------------
  |  Branch (768:13): [True: 6, False: 605]
  ------------------
  769|      6|            goto cleanup;
  770|    611|    }
  771|       |
  772|  1.59k|cleanup:
  773|  1.59k|    io->close(io->io_ctx);
  774|  1.59k|    xport_ctx_free(ctx);
  775|       |
  776|  1.59k|    return retval;
  777|    620|}
readstat_xport_read.c:xport_ctx_init:
   48|  1.59k|static xport_ctx_t *xport_ctx_init(void) {
   49|  1.59k|    xport_ctx_t *ctx = calloc(1, sizeof(xport_ctx_t));
   50|  1.59k|    return ctx;
   51|  1.59k|}
readstat_xport_read.c:xport_read_library_record:
  183|  1.59k|static readstat_error_t xport_read_library_record(xport_ctx_t *ctx) {
  184|  1.59k|    xport_header_record_t xrecord;
  185|  1.59k|    readstat_error_t retval = xport_read_header_record(ctx, &xrecord);
  186|  1.59k|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (186:9): [True: 23, False: 1.57k]
  ------------------
  187|     23|        goto cleanup;
  188|       |
  189|  1.57k|    if (strcmp(xrecord.name, "LIBRARY") == 0) {
  ------------------
  |  Branch (189:9): [True: 262, False: 1.31k]
  ------------------
  190|    262|        ctx->version = 5;
  191|  1.31k|    } else if (strcmp(xrecord.name, "LIBV8") == 0) {
  ------------------
  |  Branch (191:16): [True: 1.23k, False: 78]
  ------------------
  192|  1.23k|        ctx->version = 8;
  193|  1.23k|    } else {
  194|     78|        retval = READSTAT_ERROR_UNSUPPORTED_FILE_FORMAT_VERSION;
  195|     78|        goto cleanup;
  196|     78|    }
  197|       |
  198|  1.59k|cleanup:
  199|  1.59k|    return retval;
  200|  1.57k|}
readstat_xport_read.c:xport_read_header_record:
  106|  6.68k|static readstat_error_t xport_read_header_record(xport_ctx_t *ctx, xport_header_record_t *xrecord) {
  107|  6.68k|    char line[LINE_LEN+1];
  108|  6.68k|    readstat_error_t retval = READSTAT_OK;
  109|       |
  110|  6.68k|    retval = xport_read_record(ctx, line);
  111|  6.68k|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (111:9): [True: 157, False: 6.53k]
  ------------------
  112|    157|        return retval;
  113|       |
  114|  6.53k|    memset(xrecord, 0, sizeof(xport_header_record_t));
  115|  6.53k|    int matches = sscanf(line,
  116|  6.53k|            "HEADER RECORD*******%8s HEADER RECORD!!!!!!!"
  117|  6.53k|            "%05d%05d%05d" "%05d%05d%05d", xrecord->name,
  118|  6.53k|            &xrecord->num1, &xrecord->num2, &xrecord->num3,
  119|  6.53k|            &xrecord->num4, &xrecord->num5, &xrecord->num6);
  120|       |
  121|  6.53k|    if (matches < 2) {
  ------------------
  |  Branch (121:9): [True: 16, False: 6.51k]
  ------------------
  122|     16|        return READSTAT_ERROR_PARSE;
  123|     16|    }
  124|       |
  125|  6.51k|    return READSTAT_OK;
  126|  6.53k|}
readstat_xport_read.c:xport_read_record:
   96|  10.7k|static readstat_error_t xport_read_record(xport_ctx_t *ctx, char *record) {
   97|  10.7k|    ssize_t bytes_read = read_bytes(ctx, record, LINE_LEN);
  ------------------
  |  |   16|  10.7k|#define LINE_LEN        80
  ------------------
   98|  10.7k|    if (bytes_read < LINE_LEN)
  ------------------
  |  |   16|  10.7k|#define LINE_LEN        80
  ------------------
  |  Branch (98:9): [True: 215, False: 10.5k]
  ------------------
   99|    215|        return READSTAT_ERROR_READ;
  100|       |
  101|  10.5k|    record[LINE_LEN] = '\0';
  ------------------
  |  |   16|  10.5k|#define LINE_LEN        80
  ------------------
  102|       |
  103|  10.5k|    return READSTAT_OK;
  104|  10.7k|}
readstat_xport_read.c:read_bytes:
   69|  1.05M|static ssize_t read_bytes(xport_ctx_t *ctx, void *dst, size_t dst_len) {
   70|  1.05M|    readstat_io_t *io = (readstat_io_t *)ctx->io;
   71|  1.05M|    return io->read(dst, dst_len, io->io_ctx);
   72|  1.05M|}
readstat_xport_read.c:xport_skip_record:
   74|  1.49k|static readstat_error_t xport_skip_record(xport_ctx_t *ctx) {
   75|  1.49k|    readstat_io_t *io = (readstat_io_t *)ctx->io;
   76|  1.49k|    if (io->seek(LINE_LEN, READSTAT_SEEK_CUR, io->io_ctx) == -1)
  ------------------
  |  |   16|  1.49k|#define LINE_LEN        80
  ------------------
  |  Branch (76:9): [True: 10, False: 1.48k]
  ------------------
   77|     10|        return READSTAT_ERROR_SEEK;
   78|       |
   79|  1.48k|    return READSTAT_OK;
   80|  1.49k|}
readstat_xport_read.c:xport_read_timestamp_record:
  202|  1.48k|static readstat_error_t xport_read_timestamp_record(xport_ctx_t *ctx) {
  203|  1.48k|    char line[LINE_LEN+1];
  204|  1.48k|    readstat_error_t retval = READSTAT_OK;
  205|  1.48k|    struct tm ts = { .tm_isdst = -1 };
  206|  1.48k|    char month[4];
  207|  1.48k|    int i;
  208|       |
  209|  1.48k|    retval = xport_read_record(ctx, line);
  210|  1.48k|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (210:9): [True: 12, False: 1.47k]
  ------------------
  211|     12|        goto cleanup;
  212|       |
  213|  1.47k|    sscanf(line,
  214|  1.47k|            "%02d%3s%02d:%02d:%02d:%02d",
  215|  1.47k|            &ts.tm_mday, month, &ts.tm_year, &ts.tm_hour, &ts.tm_min, &ts.tm_sec);
  216|       |
  217|  14.3k|    for (i=0; i<sizeof(_xport_months)/sizeof(_xport_months[0]); i++) {
  ------------------
  |  Branch (217:15): [True: 13.3k, False: 976]
  ------------------
  218|  13.3k|        if (strcmp(month, _xport_months[i]) == 0) {
  ------------------
  |  Branch (218:13): [True: 497, False: 12.8k]
  ------------------
  219|    497|            ts.tm_mon = i;
  220|    497|            break;
  221|    497|        }
  222|  13.3k|    }
  223|       |
  224|  1.47k|    if (ts.tm_year < 60) {
  ------------------
  |  Branch (224:9): [True: 1.45k, False: 18]
  ------------------
  225|  1.45k|        ts.tm_year += 100;
  226|  1.45k|    }
  227|       |
  228|  1.47k|    ctx->timestamp = mktime(&ts);
  229|       |
  230|  1.48k|cleanup:
  231|  1.48k|    return retval;
  232|  1.47k|}
readstat_xport_read.c:xport_expect_header_record:
  129|  2.91k|        const char *v5_name, const char *v8_name) {
  130|  2.91k|    readstat_error_t retval = READSTAT_OK;
  131|  2.91k|    xport_header_record_t xrecord;
  132|       |
  133|  2.91k|    retval = xport_read_header_record(ctx, &xrecord);
  134|  2.91k|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (134:9): [True: 118, False: 2.79k]
  ------------------
  135|    118|        goto cleanup;
  136|       |
  137|  2.79k|    if (ctx->version == 5 && strcmp(xrecord.name, v5_name) != 0) {
  ------------------
  |  Branch (137:9): [True: 465, False: 2.32k]
  |  Branch (137:30): [True: 64, False: 401]
  ------------------
  138|     64|        retval = READSTAT_ERROR_PARSE;
  139|     64|        goto cleanup;
  140|  2.72k|    } else if (ctx->version == 8 && strcmp(xrecord.name, v8_name) != 0) {
  ------------------
  |  Branch (140:16): [True: 2.32k, False: 401]
  |  Branch (140:37): [True: 63, False: 2.26k]
  ------------------
  141|     63|        retval = READSTAT_ERROR_PARSE;
  142|     63|        goto cleanup;
  143|     63|    }
  144|       |
  145|  2.91k|cleanup:
  146|  2.91k|    return retval;
  147|  2.79k|}
readstat_xport_read.c:xport_read_table_name_record:
  149|  1.29k|static readstat_error_t xport_read_table_name_record(xport_ctx_t *ctx) {
  150|  1.29k|    char line[LINE_LEN+1];
  151|  1.29k|    readstat_error_t retval = READSTAT_OK;
  152|       |
  153|  1.29k|    retval = xport_read_record(ctx, line);
  154|  1.29k|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (154:9): [True: 13, False: 1.28k]
  ------------------
  155|     13|        goto cleanup;
  156|       |
  157|  1.28k|    retval = readstat_convert(ctx->table_name, sizeof(ctx->table_name), &line[8],
  158|  1.28k|            ctx->version == 5 ? 8 : 32, ctx->converter);
  ------------------
  |  Branch (158:13): [True: 168, False: 1.11k]
  ------------------
  159|  1.28k|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (159:9): [True: 0, False: 1.28k]
  ------------------
  160|      0|        goto cleanup;
  161|       |
  162|  1.29k|cleanup:
  163|  1.29k|    return retval;
  164|  1.28k|}
readstat_xport_read.c:xport_read_file_label_record:
  166|  1.28k|static readstat_error_t xport_read_file_label_record(xport_ctx_t *ctx) {
  167|  1.28k|    char line[LINE_LEN+1];
  168|  1.28k|    readstat_error_t retval = READSTAT_OK;
  169|       |
  170|  1.28k|    retval = xport_read_record(ctx, line);
  171|  1.28k|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (171:9): [True: 33, False: 1.25k]
  ------------------
  172|     33|        goto cleanup;
  173|       |
  174|  1.25k|    retval = readstat_convert(ctx->file_label, sizeof(ctx->file_label), &line[32],
  175|  1.25k|            40, ctx->converter);
  176|  1.25k|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (176:9): [True: 0, False: 1.25k]
  ------------------
  177|      0|        goto cleanup;
  178|       |
  179|  1.28k|cleanup:
  180|  1.28k|    return retval;
  181|  1.25k|}
readstat_xport_read.c:xport_read_namestr_header_record:
  234|  1.25k|static readstat_error_t xport_read_namestr_header_record(xport_ctx_t *ctx) {
  235|  1.25k|    xport_header_record_t xrecord;
  236|  1.25k|    readstat_error_t retval = READSTAT_OK;
  237|       |
  238|  1.25k|    retval = xport_read_header_record(ctx, &xrecord);
  239|  1.25k|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (239:9): [True: 16, False: 1.23k]
  ------------------
  240|     16|        goto cleanup;
  241|       |
  242|  1.23k|    if (ctx->version == 5 && strcmp(xrecord.name, "NAMESTR") != 0) {
  ------------------
  |  Branch (242:9): [True: 156, False: 1.08k]
  |  Branch (242:30): [True: 61, False: 95]
  ------------------
  243|     61|        retval = READSTAT_ERROR_PARSE;
  244|     61|        goto cleanup;
  245|  1.17k|    } else if (ctx->version == 8 && strcmp(xrecord.name, "NAMSTV8") != 0) {
  ------------------
  |  Branch (245:16): [True: 1.08k, False: 95]
  |  Branch (245:37): [True: 63, False: 1.01k]
  ------------------
  246|     63|        retval = READSTAT_ERROR_PARSE;
  247|     63|        goto cleanup;
  248|     63|    }
  249|       |
  250|  1.11k|    ctx->var_count = xrecord.num2;
  251|  1.11k|    ctx->variables = readstat_calloc(ctx->var_count, sizeof(readstat_variable_t *));
  252|  1.11k|    if (ctx->variables == NULL) {
  ------------------
  |  Branch (252:9): [True: 15, False: 1.09k]
  ------------------
  253|     15|        retval = READSTAT_ERROR_MALLOC;
  254|     15|        goto cleanup;
  255|     15|    }
  256|       |
  257|  1.09k|    if (ctx->handle.metadata) {
  ------------------
  |  Branch (257:9): [True: 1.09k, False: 0]
  ------------------
  258|  1.09k|        readstat_metadata_t metadata = {
  259|  1.09k|            .row_count = -1,
  260|  1.09k|            .var_count = ctx->var_count,
  261|  1.09k|            .file_label = ctx->file_label,
  262|  1.09k|            .table_name = ctx->table_name,
  263|  1.09k|            .creation_time = ctx->timestamp,
  264|  1.09k|            .modified_time = ctx->timestamp,
  265|  1.09k|            .file_format_version = ctx->version
  266|  1.09k|        };
  267|  1.09k|        if (ctx->handle.metadata(&metadata, ctx->user_ctx) != READSTAT_HANDLER_OK) {
  ------------------
  |  Branch (267:13): [True: 0, False: 1.09k]
  ------------------
  268|      0|            retval = READSTAT_ERROR_USER_ABORT;
  269|      0|            goto cleanup;
  270|      0|        }
  271|  1.09k|    }
  272|       |
  273|  1.25k|cleanup:
  274|  1.25k|    return retval;
  275|  1.09k|}
readstat_xport_read.c:xport_read_variables:
  453|  1.09k|static readstat_error_t xport_read_variables(xport_ctx_t *ctx) {
  454|  1.09k|    int i;
  455|  1.09k|    readstat_error_t retval = READSTAT_OK;
  456|  78.5k|    for (i=0; i<ctx->var_count; i++) {
  ------------------
  |  Branch (456:15): [True: 77.5k, False: 1.01k]
  ------------------
  457|  77.5k|        xport_namestr_t namestr;
  458|  77.5k|        ssize_t bytes_read = read_bytes(ctx, &namestr, sizeof(xport_namestr_t));
  459|  77.5k|        if (bytes_read < sizeof(xport_namestr_t)) {
  ------------------
  |  Branch (459:13): [True: 81, False: 77.4k]
  ------------------
  460|     81|            retval = READSTAT_ERROR_READ;
  461|     81|            goto cleanup;
  462|     81|        }
  463|  77.4k|        xport_namestr_bswap(&namestr);
  464|       |
  465|  77.4k|        readstat_variable_t *variable = calloc(1, sizeof(readstat_variable_t));
  466|       |
  467|  77.4k|        variable->index = i;
  468|  77.4k|        variable->type = namestr.ntype == SAS_COLUMN_TYPE_CHR ? READSTAT_TYPE_STRING : READSTAT_TYPE_DOUBLE;
  ------------------
  |  |   90|  77.4k|#define SAS_COLUMN_TYPE_CHR  0x02
  ------------------
  |  Branch (468:26): [True: 74, False: 77.4k]
  ------------------
  469|  77.4k|        variable->storage_width = namestr.nlng;
  470|  77.4k|        variable->display_width = namestr.nfl;
  471|  77.4k|        variable->decimals = namestr.nfd;
  472|  77.4k|        variable->alignment = namestr.nfj ? READSTAT_ALIGNMENT_RIGHT : READSTAT_ALIGNMENT_LEFT;
  ------------------
  |  Branch (472:31): [True: 48.6k, False: 28.8k]
  ------------------
  473|       |
  474|  77.4k|        if (ctx->version == 5) {
  ------------------
  |  Branch (474:13): [True: 4.46k, False: 73.0k]
  ------------------
  475|  4.46k|            retval = readstat_convert(variable->name, sizeof(variable->name),
  476|  4.46k|                    namestr.nname, sizeof(namestr.nname), ctx->converter);
  477|  73.0k|        } else {
  478|  73.0k|            retval = readstat_convert(variable->name, sizeof(variable->name),
  479|  73.0k|                    namestr.longname, sizeof(namestr.longname), ctx->converter);
  480|  73.0k|        }
  481|  77.4k|        if (retval != READSTAT_OK)
  ------------------
  |  Branch (481:13): [True: 0, False: 77.4k]
  ------------------
  482|      0|            goto cleanup;
  483|       |
  484|  77.4k|        retval = readstat_convert(variable->label, sizeof(variable->label),
  485|  77.4k|                namestr.nlabel, sizeof(namestr.nlabel), ctx->converter);
  486|  77.4k|        if (retval != READSTAT_OK)
  ------------------
  |  Branch (486:13): [True: 0, False: 77.4k]
  ------------------
  487|      0|            goto cleanup;
  488|       |
  489|  77.4k|        retval = xport_construct_format(variable->format, sizeof(variable->format),
  490|  77.4k|                namestr.nform, sizeof(namestr.nform),
  491|  77.4k|                variable->display_width, variable->decimals);
  492|  77.4k|        if (retval != READSTAT_OK)
  ------------------
  |  Branch (492:13): [True: 0, False: 77.4k]
  ------------------
  493|      0|            goto cleanup;
  494|       |
  495|  77.4k|        ctx->variables[i] = variable;
  496|  77.4k|    }
  497|       |
  498|  1.01k|    retval = xport_skip_rest_of_record(ctx);
  499|  1.01k|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (499:9): [True: 34, False: 983]
  ------------------
  500|     34|        goto cleanup;
  501|       |
  502|    983|    if (ctx->version == 5) {
  ------------------
  |  Branch (502:9): [True: 54, False: 929]
  ------------------
  503|     54|        retval = xport_read_obs_header_record(ctx);
  504|     54|        if (retval != READSTAT_OK)
  ------------------
  |  Branch (504:13): [True: 7, False: 47]
  ------------------
  505|      7|            goto cleanup;
  506|    929|    } else {
  507|    929|        xport_header_record_t xrecord;
  508|    929|        retval = xport_read_header_record(ctx, &xrecord);
  509|    929|        if (retval != READSTAT_OK)
  ------------------
  |  Branch (509:13): [True: 16, False: 913]
  ------------------
  510|     16|            goto cleanup;
  511|       |
  512|    913|        if (strcmp(xrecord.name, "OBSV8") == 0) {
  ------------------
  |  Branch (512:13): [True: 13, False: 900]
  ------------------
  513|       |            /* void */
  514|    900|        } else if (strcmp(xrecord.name, "LABELV8") == 0) {
  ------------------
  |  Branch (514:20): [True: 153, False: 747]
  ------------------
  515|    153|            retval = xport_read_labels_v8(ctx, xrecord.num1);
  516|    747|        } else if (strcmp(xrecord.name, "LABELV9") == 0) {
  ------------------
  |  Branch (516:20): [True: 188, False: 559]
  ------------------
  517|    188|            retval = xport_read_labels_v9(ctx, xrecord.num1);
  518|    188|        }
  519|    913|        if (retval != READSTAT_OK)
  ------------------
  |  Branch (519:13): [True: 340, False: 573]
  ------------------
  520|    340|            goto cleanup;
  521|    913|    }
  522|       |
  523|    620|    ctx->row_length = 0;
  524|       |
  525|    620|    int index_after_skipping = 0;
  526|       |
  527|  19.6k|    for (i=0; i<ctx->var_count; i++) {
  ------------------
  |  Branch (527:15): [True: 19.0k, False: 620]
  ------------------
  528|  19.0k|        readstat_variable_t *variable = ctx->variables[i];
  529|  19.0k|        variable->index_after_skipping = index_after_skipping;
  530|       |
  531|  19.0k|        int cb_retval = READSTAT_HANDLER_OK;
  532|  19.0k|        if (ctx->handle.variable) {
  ------------------
  |  Branch (532:13): [True: 19.0k, False: 0]
  ------------------
  533|  19.0k|            cb_retval = ctx->handle.variable(i, variable, variable->format, ctx->user_ctx);
  534|  19.0k|        }
  535|  19.0k|        if (cb_retval == READSTAT_HANDLER_ABORT) {
  ------------------
  |  Branch (535:13): [True: 0, False: 19.0k]
  ------------------
  536|      0|            retval = READSTAT_ERROR_USER_ABORT;
  537|      0|            goto cleanup;
  538|      0|        }
  539|  19.0k|        if (cb_retval == READSTAT_HANDLER_SKIP_VARIABLE) {
  ------------------
  |  Branch (539:13): [True: 0, False: 19.0k]
  ------------------
  540|      0|            variable->skip = 1;
  541|  19.0k|        } else {
  542|  19.0k|            index_after_skipping++;
  543|  19.0k|        }
  544|       |
  545|  19.0k|        ctx->row_length += variable->storage_width;
  546|  19.0k|    }
  547|       |
  548|  1.09k|cleanup:
  549|  1.09k|    return retval;
  550|    620|}
readstat_xport_read.c:xport_construct_format:
  282|  77.4k|        const char *src, size_t src_len, int width, int decimals) {
  283|  77.4k|    char *format = malloc(4 * src_len + 1);
  284|  77.4k|    if (format == NULL) return READSTAT_ERROR_MALLOC;
  ------------------
  |  Branch (284:9): [True: 0, False: 77.4k]
  ------------------
  285|  77.4k|    readstat_error_t retval = readstat_convert(format, 4 * src_len + 1, src, src_len, NULL);
  286|       |
  287|  77.4k|    if (retval != READSTAT_OK) {
  ------------------
  |  Branch (287:9): [True: 0, False: 77.4k]
  ------------------
  288|      0|        free(format);
  289|      0|        return retval;
  290|      0|    }
  291|       |
  292|  77.4k|    char *pos = dst;
  293|  77.4k|    *dst = '\0';
  294|  77.4k|    if (format[0]) {
  ------------------
  |  Branch (294:9): [True: 31.9k, False: 45.5k]
  ------------------
  295|  31.9k|        pos += snprintf(dst, dst_len, "%s", format);
  296|  31.9k|    }
  297|  77.4k|    if (width) {
  ------------------
  |  Branch (297:9): [True: 48.7k, False: 28.7k]
  ------------------
  298|  48.7k|        pos += snprintf(pos, dst_len-(pos-dst), "%d", width);
  299|  48.7k|    }
  300|  77.4k|    if (decimals) {
  ------------------
  |  Branch (300:9): [True: 48.4k, False: 28.9k]
  ------------------
  301|  48.4k|        pos += snprintf(pos, dst_len-(pos-dst), ".%d", decimals);
  302|  48.4k|    }
  303|       |
  304|  77.4k|    free(format);
  305|  77.4k|    return retval;
  306|  77.4k|}
readstat_xport_read.c:xport_skip_rest_of_record:
   82|  1.12k|static readstat_error_t xport_skip_rest_of_record(xport_ctx_t *ctx) {
   83|  1.12k|    readstat_io_t *io = (readstat_io_t *)ctx->io;
   84|  1.12k|    off_t pos = io->seek(0, READSTAT_SEEK_CUR, io->io_ctx);
   85|  1.12k|    if (pos == -1)
  ------------------
  |  Branch (85:9): [True: 0, False: 1.12k]
  ------------------
   86|      0|        return READSTAT_ERROR_SEEK;
   87|       |
   88|  1.12k|    if (pos % LINE_LEN) {
  ------------------
  |  |   16|  1.12k|#define LINE_LEN        80
  ------------------
  |  Branch (88:9): [True: 1.06k, False: 66]
  ------------------
   89|  1.06k|        if (io->seek(LINE_LEN - (pos % LINE_LEN), READSTAT_SEEK_CUR, io->io_ctx) == -1)
  ------------------
  |  |   16|  1.06k|#define LINE_LEN        80
  ------------------
                      if (io->seek(LINE_LEN - (pos % LINE_LEN), READSTAT_SEEK_CUR, io->io_ctx) == -1)
  ------------------
  |  |   16|  1.06k|#define LINE_LEN        80
  ------------------
  |  Branch (89:13): [True: 79, False: 982]
  ------------------
   90|     79|            return READSTAT_ERROR_SEEK;
   91|  1.06k|    }
   92|       |
   93|  1.04k|    return READSTAT_OK;
   94|  1.12k|}
readstat_xport_read.c:xport_read_obs_header_record:
  277|    119|static readstat_error_t xport_read_obs_header_record(xport_ctx_t *ctx) {
  278|    119|    return xport_expect_header_record(ctx, "OBS", "OBSV8");
  279|    119|}
readstat_xport_read.c:xport_read_labels_v8:
  308|    153|static readstat_error_t xport_read_labels_v8(xport_ctx_t *ctx, int label_count) {
  309|    153|    readstat_error_t retval = READSTAT_OK;
  310|    153|    uint16_t labeldef[3];
  311|    153|    char *name = NULL;
  312|    153|    char *label = NULL;
  313|    153|    int i;
  314|    730|    for (i=0; i<label_count; i++) {
  ------------------
  |  Branch (314:15): [True: 677, False: 53]
  ------------------
  315|    677|        int index, name_len, label_len;
  316|    677|        if (read_bytes(ctx, labeldef, sizeof(labeldef)) != sizeof(labeldef)) {
  ------------------
  |  Branch (316:13): [True: 21, False: 656]
  ------------------
  317|     21|            retval = READSTAT_ERROR_READ;
  318|     21|            goto cleanup;
  319|     21|        }
  320|       |
  321|    656|        if (machine_is_little_endian()) {
  ------------------
  |  Branch (321:13): [True: 656, False: 0]
  ------------------
  322|    656|            index = byteswap2(labeldef[0]);
  323|    656|            name_len = byteswap2(labeldef[1]);
  324|    656|            label_len = byteswap2(labeldef[2]);
  325|    656|        } else {
  326|      0|            index = labeldef[0];
  327|      0|            name_len = labeldef[1];
  328|      0|            label_len = labeldef[2];
  329|      0|        }
  330|       |
  331|    656|        if (index > ctx->var_count || index == 0) {
  ------------------
  |  Branch (331:13): [True: 18, False: 638]
  |  Branch (331:39): [True: 12, False: 626]
  ------------------
  332|     30|            retval = READSTAT_ERROR_PARSE;
  333|     30|            goto cleanup;
  334|     30|        }
  335|       |
  336|    626|        name = realloc(name, name_len + 1);
  337|    626|        label = realloc(label, label_len + 1);
  338|    626|        readstat_variable_t *variable = ctx->variables[index-1];
  339|       |
  340|    626|        if (read_bytes(ctx, name, name_len) != name_len ||
  ------------------
  |  Branch (340:13): [True: 25, False: 601]
  ------------------
  341|    601|                read_bytes(ctx, label, label_len) != label_len) {
  ------------------
  |  Branch (341:17): [True: 20, False: 581]
  ------------------
  342|     45|            retval = READSTAT_ERROR_READ;
  343|     45|            goto cleanup;
  344|     45|        }
  345|       |
  346|    581|        retval = readstat_convert(variable->name, sizeof(variable->name),
  347|    581|                name, name_len, ctx->converter);
  348|    581|        if (retval != READSTAT_OK)
  ------------------
  |  Branch (348:13): [True: 2, False: 579]
  ------------------
  349|      2|            goto cleanup;
  350|       |
  351|    579|        retval = readstat_convert(variable->label, sizeof(variable->label),
  352|    579|                label, label_len, ctx->converter);
  353|    579|        if (retval != READSTAT_OK)
  ------------------
  |  Branch (353:13): [True: 2, False: 577]
  ------------------
  354|      2|            goto cleanup;
  355|    579|    }
  356|       |
  357|     53|    retval = xport_skip_rest_of_record(ctx);
  358|     53|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (358:9): [True: 21, False: 32]
  ------------------
  359|     21|        goto cleanup;
  360|       |
  361|     32|    retval = xport_read_obs_header_record(ctx);
  362|     32|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (362:9): [True: 32, False: 0]
  ------------------
  363|     32|        goto cleanup;
  364|       |
  365|    153|cleanup:
  366|    153|    free(name);
  367|    153|    free(label);
  368|    153|    return retval;
  369|     32|}
readstat_xport_read.c:xport_read_labels_v9:
  371|    188|static readstat_error_t xport_read_labels_v9(xport_ctx_t *ctx, int label_count) {
  372|    188|    readstat_error_t retval = READSTAT_OK;
  373|    188|    uint16_t labeldef[5];
  374|    188|    int i;
  375|    188|    char *name = NULL;
  376|    188|    char *label = NULL;
  377|    188|    char *format = NULL;
  378|    188|    char *informat = NULL;
  379|       |
  380|    484|    for (i=0; i<label_count; i++) {
  ------------------
  |  Branch (380:15): [True: 427, False: 57]
  ------------------
  381|    427|        int index, name_len, label_len, format_len, informat_len;
  382|    427|        if (read_bytes(ctx, labeldef, sizeof(labeldef)) != sizeof(labeldef)) {
  ------------------
  |  Branch (382:13): [True: 28, False: 399]
  ------------------
  383|     28|            retval = READSTAT_ERROR_READ;
  384|     28|            goto cleanup;
  385|     28|        }
  386|       |
  387|    399|        if (machine_is_little_endian()) {
  ------------------
  |  Branch (387:13): [True: 399, False: 0]
  ------------------
  388|    399|            index = byteswap2(labeldef[0]);
  389|    399|            name_len = byteswap2(labeldef[1]);
  390|    399|            label_len = byteswap2(labeldef[2]);
  391|    399|            format_len = byteswap2(labeldef[3]);
  392|    399|            informat_len = byteswap2(labeldef[4]);
  393|    399|        } else {
  394|      0|            index = labeldef[0];
  395|      0|            name_len = labeldef[1];
  396|      0|            label_len = labeldef[2];
  397|      0|            format_len = labeldef[3];
  398|      0|            informat_len = labeldef[4];
  399|      0|        }
  400|       |
  401|    399|        if (index > ctx->var_count || index == 0) {
  ------------------
  |  Branch (401:13): [True: 16, False: 383]
  |  Branch (401:39): [True: 3, False: 380]
  ------------------
  402|     19|            retval = READSTAT_ERROR_PARSE;
  403|     19|            goto cleanup;
  404|     19|        }
  405|       |
  406|    380|        name = realloc(name, name_len + 1);
  407|    380|        label = realloc(label, label_len + 1);
  408|    380|        format = realloc(format, format_len + 1);
  409|    380|        informat = realloc(informat, informat_len + 1);
  410|       |
  411|    380|        readstat_variable_t *variable = ctx->variables[index-1];
  412|       |
  413|    380|        if (read_bytes(ctx, name, name_len) != name_len ||
  ------------------
  |  Branch (413:13): [True: 18, False: 362]
  ------------------
  414|    362|                read_bytes(ctx, label, label_len) != label_len ||
  ------------------
  |  Branch (414:17): [True: 16, False: 346]
  ------------------
  415|    346|                read_bytes(ctx, format, format_len) != format_len ||
  ------------------
  |  Branch (415:17): [True: 16, False: 330]
  ------------------
  416|    330|                read_bytes(ctx, informat, informat_len) != informat_len) {
  ------------------
  |  Branch (416:17): [True: 17, False: 313]
  ------------------
  417|     67|            retval = READSTAT_ERROR_READ;
  418|     67|            goto cleanup;
  419|     67|        }
  420|       |
  421|    313|        retval = readstat_convert(variable->name, sizeof(variable->name),
  422|    313|                name, name_len, ctx->converter);
  423|    313|        if (retval != READSTAT_OK)
  ------------------
  |  Branch (423:13): [True: 1, False: 312]
  ------------------
  424|      1|            goto cleanup;
  425|       |
  426|    312|        retval = readstat_convert(variable->label, sizeof(variable->label),
  427|    312|                label, label_len, ctx->converter);
  428|    312|        if (retval != READSTAT_OK)
  ------------------
  |  Branch (428:13): [True: 1, False: 311]
  ------------------
  429|      1|            goto cleanup;
  430|       |
  431|    311|        retval = readstat_convert(variable->format, sizeof(variable->format),
  432|    311|                format, format_len, ctx->converter);
  433|    311|        if (retval != READSTAT_OK)
  ------------------
  |  Branch (433:13): [True: 15, False: 296]
  ------------------
  434|     15|            goto cleanup;
  435|    311|    }
  436|       |
  437|     57|    retval = xport_skip_rest_of_record(ctx);
  438|     57|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (438:9): [True: 24, False: 33]
  ------------------
  439|     24|        goto cleanup;
  440|       |
  441|     33|    retval = xport_read_obs_header_record(ctx);
  442|     33|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (442:9): [True: 32, False: 1]
  ------------------
  443|     32|        goto cleanup;
  444|       |
  445|    188|cleanup:
  446|    188|    free(name);
  447|    188|    free(format);
  448|    188|    free(informat);
  449|    188|    free(label);
  450|    188|    return retval;
  451|     33|}
readstat_xport_read.c:xport_read_data:
  618|    611|static readstat_error_t xport_read_data(xport_ctx_t *ctx) {
  619|    611|    if (!ctx->row_length)
  ------------------
  |  Branch (619:9): [True: 0, False: 611]
  ------------------
  620|      0|        return READSTAT_OK;
  621|       |
  622|    611|    if (!ctx->handle.value)
  ------------------
  |  Branch (622:9): [True: 0, False: 611]
  ------------------
  623|      0|        return READSTAT_OK;
  624|       |
  625|    611|    readstat_error_t retval = READSTAT_OK;
  626|    611|    char *row = readstat_malloc(ctx->row_length);
  627|    611|    char *blank_row = readstat_malloc(ctx->row_length);
  628|    611|    int num_blank_rows = 0;
  629|       |
  630|    611|    if (row == NULL || blank_row == NULL) {
  ------------------
  |  Branch (630:9): [True: 6, False: 605]
  |  Branch (630:24): [True: 0, False: 605]
  ------------------
  631|      6|        retval = READSTAT_ERROR_MALLOC;
  632|      6|        goto cleanup;
  633|      6|    }
  634|       |
  635|    605|    memset(blank_row, ' ', ctx->row_length);
  636|   961k|    while (1) {
  ------------------
  |  Branch (636:12): [True: 961k, Folded]
  ------------------
  637|   961k|        ssize_t bytes_read = read_bytes(ctx, row, ctx->row_length);
  638|   961k|        if (bytes_read == -1) {
  ------------------
  |  Branch (638:13): [True: 0, False: 961k]
  ------------------
  639|      0|            retval = READSTAT_ERROR_READ;
  640|      0|            goto cleanup;
  641|   961k|        } else if (bytes_read < ctx->row_length) {
  ------------------
  |  Branch (641:20): [True: 605, False: 960k]
  ------------------
  642|    605|            break;
  643|    605|        }
  644|       |
  645|   960k|        off_t pos = 0;
  646|       |
  647|   960k|        int row_is_blank = 1;
  648|       |
  649|  1.88M|        for (pos=0; pos<ctx->row_length; pos++) {
  ------------------
  |  Branch (649:21): [True: 966k, False: 919k]
  ------------------
  650|   966k|            if (row[pos] != ' ') {
  ------------------
  |  Branch (650:17): [True: 41.5k, False: 925k]
  ------------------
  651|  41.5k|                row_is_blank = 0;
  652|  41.5k|                break;
  653|  41.5k|            }
  654|   966k|        }
  655|       |
  656|   960k|        if (row_is_blank) {
  ------------------
  |  Branch (656:13): [True: 919k, False: 41.5k]
  ------------------
  657|   919k|            num_blank_rows++;
  658|   919k|            continue;
  659|   919k|        }
  660|       |
  661|   960k|        while (num_blank_rows) {
  ------------------
  |  Branch (661:16): [True: 919k, False: 41.5k]
  ------------------
  662|   919k|            retval = xport_process_row(ctx, blank_row, ctx->row_length);
  663|   919k|            if (retval != READSTAT_OK)
  ------------------
  |  Branch (663:17): [True: 0, False: 919k]
  ------------------
  664|      0|                goto cleanup;
  665|       |
  666|   919k|            if (ctx->row_limit > 0 && ctx->parsed_row_count == ctx->row_limit)
  ------------------
  |  Branch (666:17): [True: 0, False: 919k]
  |  Branch (666:39): [True: 0, False: 0]
  ------------------
  667|      0|                goto cleanup;
  668|       |
  669|   919k|            num_blank_rows--;
  670|   919k|        }
  671|       |
  672|  41.5k|        retval = xport_process_row(ctx, row, ctx->row_length);
  673|  41.5k|        if (retval != READSTAT_OK)
  ------------------
  |  Branch (673:13): [True: 0, False: 41.5k]
  ------------------
  674|      0|            goto cleanup;
  675|       |
  676|  41.5k|        retval = xport_update_progress(ctx);
  677|  41.5k|        if (retval != READSTAT_OK)
  ------------------
  |  Branch (677:13): [True: 0, False: 41.5k]
  ------------------
  678|      0|            goto cleanup;
  679|       |
  680|  41.5k|        if (ctx->row_limit > 0 && ctx->parsed_row_count == ctx->row_limit)
  ------------------
  |  Branch (680:13): [True: 0, False: 41.5k]
  |  Branch (680:35): [True: 0, False: 0]
  ------------------
  681|      0|            break;
  682|  41.5k|    }
  683|       |
  684|    611|cleanup:
  685|    611|    if (row)
  ------------------
  |  Branch (685:9): [True: 605, False: 6]
  ------------------
  686|    605|        free(row);
  687|    611|    if (blank_row)
  ------------------
  |  Branch (687:9): [True: 605, False: 6]
  ------------------
  688|    605|        free(blank_row);
  689|    611|    return retval;
  690|    605|}
readstat_xport_read.c:xport_process_row:
  552|   960k|static readstat_error_t xport_process_row(xport_ctx_t *ctx, const char *row, size_t row_length) {
  553|   960k|    readstat_error_t retval = READSTAT_OK;
  554|   960k|    int i;
  555|   960k|    off_t pos = 0;
  556|   960k|    char *string = NULL;
  557|  1.92M|    for (i=0; i<ctx->var_count; i++) {
  ------------------
  |  Branch (557:15): [True: 961k, False: 960k]
  ------------------
  558|   961k|        readstat_variable_t *variable = ctx->variables[i];
  559|   961k|        readstat_value_t value = { .type = variable->type };
  560|       |
  561|   961k|        if (variable->type == READSTAT_TYPE_STRING) {
  ------------------
  |  Branch (561:13): [True: 1.12k, False: 959k]
  ------------------
  562|  1.12k|            string = readstat_realloc(string, 4*variable->storage_width+1);
  563|  1.12k|            if (string == NULL) {
  ------------------
  |  Branch (563:17): [True: 0, False: 1.12k]
  ------------------
  564|      0|                retval = READSTAT_ERROR_MALLOC;
  565|      0|                goto cleanup;
  566|      0|            }
  567|  1.12k|            retval = readstat_convert(string, 4*variable->storage_width+1,
  568|  1.12k|                    &row[pos], variable->storage_width, ctx->converter);
  569|  1.12k|            if (retval != READSTAT_OK)
  ------------------
  |  Branch (569:17): [True: 0, False: 1.12k]
  ------------------
  570|      0|                goto cleanup;
  571|       |
  572|  1.12k|            value.v.string_value = string;
  573|   959k|        } else {
  574|   959k|            double dval = NAN;
  575|   959k|            if (variable->storage_width <= XPORT_MAX_DOUBLE_SIZE &&
  ------------------
  |  |   45|  1.91M|#define XPORT_MAX_DOUBLE_SIZE   8
  ------------------
  |  Branch (575:17): [True: 959k, False: 224]
  ------------------
  576|   959k|                    variable->storage_width >= XPORT_MIN_DOUBLE_SIZE) {
  ------------------
  |  |   44|   959k|#define XPORT_MIN_DOUBLE_SIZE   3
  ------------------
  |  Branch (576:21): [True: 40.2k, False: 919k]
  ------------------
  577|  40.2k|                char full_value[8] = { 0 };
  578|  40.2k|                if (memcmp(&full_value[1], &row[pos+1], variable->storage_width - 1) == 0 &&
  ------------------
  |  Branch (578:21): [True: 34.4k, False: 5.82k]
  ------------------
  579|  34.4k|                        (row[pos] == '.' || sas_validate_tag(row[pos]) == READSTAT_OK)) {
  ------------------
  |  Branch (579:26): [True: 194, False: 34.2k]
  |  Branch (579:45): [True: 400, False: 33.8k]
  ------------------
  580|    594|                    if (row[pos] == '.') {
  ------------------
  |  Branch (580:25): [True: 194, False: 400]
  ------------------
  581|    194|                        value.is_system_missing = 1;
  582|    400|                    } else {
  583|    400|                        value.tag = row[pos];
  584|    400|                        value.is_tagged_missing = 1;
  585|    400|                    }
  586|  39.6k|                } else {
  587|  39.6k|                    memcpy(full_value, &row[pos], variable->storage_width);
  588|  39.6k|                    int rc = cnxptiee(full_value, CN_TYPE_XPORT, &dval, CN_TYPE_NATIVE);
  ------------------
  |  |    2|  39.6k|#define CN_TYPE_XPORT 1
  ------------------
                                  int rc = cnxptiee(full_value, CN_TYPE_XPORT, &dval, CN_TYPE_NATIVE);
  ------------------
  |  |    1|  39.6k|#define CN_TYPE_NATIVE 0
  ------------------
  589|  39.6k|                    if (rc != 0) {
  ------------------
  |  Branch (589:25): [True: 0, False: 39.6k]
  ------------------
  590|      0|                        retval = READSTAT_ERROR_CONVERT;
  591|      0|                        goto cleanup;
  592|      0|                    }
  593|  39.6k|                }
  594|  40.2k|            }
  595|       |
  596|   959k|            value.v.double_value = dval;
  597|   959k|        }
  598|   961k|        pos += variable->storage_width;
  599|       |
  600|   961k|        if (ctx->handle.value && !ctx->variables[i]->skip && !ctx->row_offset) {
  ------------------
  |  Branch (600:13): [True: 961k, False: 0]
  |  Branch (600:34): [True: 961k, False: 0]
  |  Branch (600:62): [True: 961k, False: 0]
  ------------------
  601|   961k|            if (ctx->handle.value(ctx->parsed_row_count, variable, value, ctx->user_ctx) != READSTAT_HANDLER_OK) {
  ------------------
  |  Branch (601:17): [True: 0, False: 961k]
  ------------------
  602|      0|                retval = READSTAT_ERROR_USER_ABORT;
  603|      0|                goto cleanup;
  604|      0|            }
  605|   961k|        }
  606|   961k|    }
  607|   960k|    if (ctx->row_offset) {
  ------------------
  |  Branch (607:9): [True: 0, False: 960k]
  ------------------
  608|      0|        ctx->row_offset--;
  609|   960k|    } else {
  610|   960k|        ctx->parsed_row_count++;
  611|   960k|    }
  612|       |
  613|   960k|cleanup:
  614|   960k|    free(string);
  615|   960k|    return retval;
  616|   960k|}
readstat_xport_read.c:xport_update_progress:
   43|  41.5k|static readstat_error_t xport_update_progress(xport_ctx_t *ctx) {
   44|  41.5k|    readstat_io_t *io = ctx->io;
   45|  41.5k|    return io->update(ctx->file_size, ctx->handle.progress, ctx->user_ctx, io->io_ctx);
   46|  41.5k|}
readstat_xport_read.c:xport_ctx_free:
   53|  1.59k|static void xport_ctx_free(xport_ctx_t *ctx) {
   54|  1.59k|    if (ctx->variables) {
  ------------------
  |  Branch (54:9): [True: 1.09k, False: 498]
  ------------------
   55|  1.09k|        int i;
   56|  1.45M|        for (i=0; i<ctx->var_count; i++) {
  ------------------
  |  Branch (56:19): [True: 1.45M, False: 1.09k]
  ------------------
   57|  1.45M|            if (ctx->variables[i])
  ------------------
  |  Branch (57:17): [True: 77.4k, False: 1.37M]
  ------------------
   58|  77.4k|                free(ctx->variables[i]);
   59|  1.45M|        }
   60|  1.09k|        free(ctx->variables);
   61|  1.09k|    }
   62|  1.59k|    if (ctx->converter) {
  ------------------
  |  Branch (62:9): [True: 0, False: 1.59k]
  ------------------
   63|      0|        iconv_close(ctx->converter);
   64|      0|    }
   65|       |
   66|  1.59k|    free(ctx);
   67|  1.59k|}

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

