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

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

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

readstat_convert:
    7|   243k|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.44M|    while (src_len && (src[src_len-1] == ' ' || src[src_len-1] == '\0')) {
  ------------------
  |  Branch (10:12): [True: 4.31M, False: 128k]
  |  Branch (10:24): [True: 2.01M, False: 2.30M]
  |  Branch (10:49): [True: 2.18M, False: 115k]
  ------------------
   11|  4.19M|        src_len--;
   12|  4.19M|    }
   13|   243k|    if (dst_len == 0) {
  ------------------
  |  Branch (13:9): [True: 0, False: 243k]
  ------------------
   14|      0|        return READSTAT_ERROR_CONVERT_LONG_STRING;
   15|   243k|    } else if (converter) {
  ------------------
  |  Branch (15:16): [True: 0, False: 243k]
  ------------------
   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|   243k|    } else if (src_len + 1 > dst_len) {
  ------------------
  |  Branch (29:16): [True: 21, False: 243k]
  ------------------
   30|     21|        return READSTAT_ERROR_CONVERT_LONG_STRING;
   31|   243k|    } else {
   32|   243k|        memcpy(dst, src, src_len);
   33|   243k|        dst[src_len] = '\0';
   34|   243k|    }
   35|   243k|    return READSTAT_OK;
   36|   243k|}

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

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

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

memreverse:
   22|  10.0k|void memreverse(void *intp_void, int l) {
   23|  10.0k|    if (!machine_is_little_endian())
  ------------------
  |  Branch (23:9): [True: 0, False: 10.0k]
  ------------------
   24|      0|        return;
   25|       |
   26|  10.0k|    int i,j;
   27|  10.0k|    char save;
   28|  10.0k|    char *intp = (char *)intp_void;
   29|       |
   30|  10.0k|    j = l/2;
   31|  30.2k|    for (i=0;i<j;i++) {
  ------------------
  |  Branch (31:14): [True: 20.1k, False: 10.0k]
  ------------------
   32|  20.1k|        save = intp[i];
   33|  20.1k|        intp[i] = intp[l-i-1];
   34|  20.1k|        intp[l-i-1] = save;
   35|  20.1k|    }
   36|  10.0k|}
cnxptiee:
   39|  3.03k|{
   40|  3.03k|    unsigned char *from = (unsigned char *)from_bytes;
   41|  3.03k|    unsigned char *to = (unsigned char *)to_bytes;
   42|  3.03k|    unsigned char temp[8];
   43|  3.03k|    int i;
   44|       |
   45|  3.03k|    if (fromtype == CN_TYPE_NATIVE) {
  ------------------
  |  |    1|  3.03k|#define CN_TYPE_NATIVE 0
  ------------------
  |  Branch (45:9): [True: 0, False: 3.03k]
  ------------------
   46|      0|        fromtype = FLOATREP;
  ------------------
  |  |   18|      0|#define FLOATREP get_native()
  ------------------
   47|      0|    }
   48|  3.03k|    switch(fromtype) {
   49|      0|        case CN_TYPE_IEEEL :
  ------------------
  |  |    4|      0|#define CN_TYPE_IEEEL 3
  ------------------
  |  Branch (49:9): [True: 0, False: 3.03k]
  ------------------
   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: 3.03k]
  ------------------
   59|       |            /* Break intentionally omitted. */
   60|  3.03k|        case CN_TYPE_XPORT :
  ------------------
  |  |    2|  3.03k|#define CN_TYPE_XPORT 1
  ------------------
  |  Branch (60:9): [True: 3.03k, False: 0]
  ------------------
   61|  3.03k|            break;
   62|      0|        default:
  ------------------
  |  Branch (62:9): [True: 0, False: 3.03k]
  ------------------
   63|      0|            return(-1);
   64|  3.03k|    }
   65|  3.03k|    if (totype == CN_TYPE_NATIVE) {
  ------------------
  |  |    1|  3.03k|#define CN_TYPE_NATIVE 0
  ------------------
  |  Branch (65:9): [True: 3.03k, False: 0]
  ------------------
   66|  3.03k|        totype = FLOATREP;
  ------------------
  |  |   18|  3.03k|#define FLOATREP get_native()
  ------------------
   67|  3.03k|    }
   68|  3.03k|    switch(totype) {
   69|      0|        case CN_TYPE_XPORT :
  ------------------
  |  |    2|      0|#define CN_TYPE_XPORT 1
  ------------------
  |  Branch (69:9): [True: 0, False: 3.03k]
  ------------------
   70|      0|        case CN_TYPE_IEEEB :
  ------------------
  |  |    3|      0|#define CN_TYPE_IEEEB 2
  ------------------
  |  Branch (70:9): [True: 0, False: 3.03k]
  ------------------
   71|  3.03k|        case CN_TYPE_IEEEL :
  ------------------
  |  |    4|  3.03k|#define CN_TYPE_IEEEL 3
  ------------------
  |  Branch (71:9): [True: 3.03k, False: 0]
  ------------------
   72|  3.03k|            break;
   73|      0|        default:
  ------------------
  |  Branch (73:9): [True: 0, False: 3.03k]
  ------------------
   74|      0|            return(-2);
   75|  3.03k|    }
   76|  3.03k|    if (fromtype == totype) {
  ------------------
  |  Branch (76:9): [True: 0, False: 3.03k]
  ------------------
   77|      0|        memcpy(to,from,8);
   78|      0|        return(0);
   79|      0|    }
   80|  3.03k|    switch(fromtype) {
  ------------------
  |  Branch (80:12): [True: 3.03k, False: 0]
  ------------------
   81|      0|        case CN_TYPE_IEEEB :
  ------------------
  |  |    3|      0|#define CN_TYPE_IEEEB 2
  ------------------
  |  Branch (81:9): [True: 0, False: 3.03k]
  ------------------
   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|  3.03k|        case CN_TYPE_XPORT :
  ------------------
  |  |    2|  3.03k|#define CN_TYPE_XPORT 1
  ------------------
  |  Branch (86:9): [True: 3.03k, False: 0]
  ------------------
   87|  3.03k|            xpt2ieee(from,to);
   88|  3.03k|            break;
   89|  3.03k|    }
   90|  3.03k|    if (totype == CN_TYPE_IEEEL) {
  ------------------
  |  |    4|  3.03k|#define CN_TYPE_IEEEL 3
  ------------------
  |  Branch (90:9): [True: 3.03k, False: 0]
  ------------------
   91|  3.03k|        memcpy(temp,to,8);
   92|  27.2k|        for (i=7;i>=0;i--) {
  ------------------
  |  Branch (92:18): [True: 24.2k, False: 3.03k]
  ------------------
   93|  24.2k|            to[7-i] = temp[i];
   94|  24.2k|        }
   95|  3.03k|    }
   96|  3.03k|    return(0);
   97|  3.03k|}
get_native:
   99|  3.03k|int get_native(void) {
  100|  3.03k|    static unsigned char float_reps[][8] = {
  101|  3.03k|        {0x41,0x10,0x00,0x00,0x00,0x00,0x00,0x00},
  102|  3.03k|        {0x3f,0xf0,0x00,0x00,0x00,0x00,0x00,0x00},
  103|  3.03k|        {0x00,0x00,0x00,0x00,0x00,0x00,0xf0,0x3f}
  104|  3.03k|    };
  105|       |
  106|  3.03k|    static double one = 1.00;
  107|       |
  108|  3.03k|    int i,j;
  109|  3.03k|    j = sizeof(float_reps)/8;
  110|  9.09k|    for (i=0;i<j;i++)  {
  ------------------
  |  Branch (110:14): [True: 9.09k, False: 0]
  ------------------
  111|  9.09k|        if (memcmp(&one,float_reps+i,8) == 0)
  ------------------
  |  Branch (111:13): [True: 3.03k, False: 6.06k]
  ------------------
  112|  3.03k|            return(i+1);
  113|  9.09k|    }
  114|      0|    return(-1);
  115|  3.03k|}
ieee.c:xpt2ieee:
  117|  3.03k|void xpt2ieee(unsigned char *xport, unsigned char *ieee) {
  118|  3.03k|    char temp[8];
  119|  3.03k|    register int shift;
  120|  3.03k|    register int nib;
  121|  3.03k|    uint32_t ieee1,ieee2;
  122|  3.03k|    uint32_t xport1 = 0;
  123|  3.03k|    uint32_t xport2 = 0;
  124|       |
  125|  3.03k|    memcpy(temp,xport,8);
  126|  3.03k|    memset(ieee,0,8);
  127|       |
  128|  3.03k|    if (*temp && memcmp(temp+1,ieee,7) == 0) {
  ------------------
  |  Branch (128:9): [True: 2.61k, False: 414]
  |  Branch (128:18): [True: 368, False: 2.25k]
  ------------------
  129|    368|        ieee[0] = ieee[1] = 0xff;
  130|    368|        ieee[2] = ~(*temp);
  131|    368|        return;
  132|    368|    }
  133|       |
  134|  2.66k|    memcpy(&xport1,temp,sizeof(uint32_t));
  135|  2.66k|    memreverse(&xport1,sizeof(uint32_t));
  136|  2.66k|    memcpy(&xport2,temp+4,sizeof(uint32_t));
  137|  2.66k|    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|  2.66k|    if ((xport1 & 0x7fffffff) == 0x7fffffff && xport2 == 0xffffffff) {
  ------------------
  |  Branch (184:9): [True: 527, False: 2.13k]
  |  Branch (184:48): [True: 194, False: 333]
  ------------------
  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|  2.47k|    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|  2.47k|    if ((!(ieee2 = xport2)) && !xport1)
  ------------------
  |  Branch (197:9): [True: 1.79k, False: 674]
  |  Branch (197:32): [True: 292, False: 1.50k]
  ------------------
  198|    292|        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|  2.17k|    if ((nib = (int)xport1) & 0x00800000) {
  ------------------
  |  Branch (206:9): [True: 684, False: 1.49k]
  ------------------
  207|    684|        shift = 3;
  208|  1.49k|    } else if (nib & 0x00400000) {
  ------------------
  |  Branch (208:16): [True: 467, False: 1.02k]
  ------------------
  209|    467|        shift = 2;
  210|  1.02k|    } else if (nib & 0x00200000) {
  ------------------
  |  Branch (210:16): [True: 686, False: 341]
  ------------------
  211|    686|        shift = 1;
  212|    686|    } else {
  213|    341|        shift = 0;
  214|    341|    }
  215|       |
  216|  2.17k|    if (shift) {
  ------------------
  |  Branch (216:9): [True: 1.83k, False: 341]
  ------------------
  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|  1.83k|        ieee1 >>= shift;
  225|  1.83k|        ieee2 = (xport2 >> shift) |
  226|  1.83k|            ((xport1 & 0x00000007) << (29 + (3 - shift)));
  227|  1.83k|    }
  228|       |
  229|       |    /* clear the 1 bit to the left of the binary point */
  230|  2.17k|    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|  2.17k|    ieee1 |=
  239|  2.17k|        (((((int32_t)(*temp & 0x7f) - 65) * 4) + shift + 1023) << 20) |
  240|  2.17k|        (xport1 & 0x80000000);
  241|       |
  242|  2.37k|doret:
  243|  2.37k|    memreverse(&ieee1,sizeof(uint32_t));
  244|  2.37k|    memcpy(ieee,&ieee1,sizeof(uint32_t));
  245|  2.37k|    memreverse(&ieee2,sizeof(uint32_t));
  246|  2.37k|    memcpy(ieee+4,&ieee2,sizeof(uint32_t));
  247|  2.37k|    return;
  248|  2.17k|}

sas_validate_tag:
  507|  1.05k|readstat_error_t sas_validate_tag(char tag) {
  508|  1.05k|    if (tag == '_' || (tag >= 'A' && tag <= 'Z'))
  ------------------
  |  Branch (508:9): [True: 197, False: 860]
  |  Branch (508:24): [True: 541, False: 319]
  |  Branch (508:38): [True: 200, False: 341]
  ------------------
  509|    397|        return READSTAT_OK;
  510|       |
  511|    660|    return READSTAT_ERROR_TAGGED_VALUE_IS_OUT_OF_RANGE;
  512|  1.05k|}

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

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

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

