ck_str_hash_lookup:
  146|  2.57k|const void *ck_str_hash_lookup(const char *key, ck_hash_table_t *table) {
  147|  2.57k|    size_t keylen = strlen(key);
  148|  2.57k|    return ck_str_n_hash_lookup(key, keylen, table);
  149|  2.57k|}
ck_str_n_hash_lookup:
  152|  2.57k|{
  153|  2.57k|	if (table->count == 0)
  ------------------
  |  Branch (153:6): [True: 624, False: 1.95k]
  ------------------
  154|    624|		return NULL;
  155|       |    	
  156|  1.95k|	if (keylen == 0)
  ------------------
  |  Branch (156:6): [True: 552, False: 1.40k]
  ------------------
  157|    552|		return NULL;
  158|       |	
  159|  1.40k|    uint64_t hash_key = ck_hash_str(key, keylen);
  160|  1.40k|	hash_key %= table->capacity;
  161|  1.40k|    uint64_t end = hash_key;
  162|  2.08k|    do {
  163|  2.08k|        char *this_key = &table->keys[table->entries[hash_key].key_offset];
  164|  2.08k|        size_t this_keylen = table->entries[hash_key].key_length;
  165|  2.08k|        if (this_keylen == 0)
  ------------------
  |  Branch (165:13): [True: 1.34k, False: 746]
  ------------------
  166|  1.34k|            return NULL;
  167|    746|        if (this_keylen == keylen && memcmp(this_key, key, keylen) == 0) {
  ------------------
  |  Branch (167:13): [True: 224, False: 522]
  |  Branch (167:38): [True: 57, False: 167]
  ------------------
  168|     57|			return table->entries[hash_key].value;
  169|     57|		}
  170|    689|		hash_key++;
  171|    689|		hash_key %= table->capacity;
  172|    689|    } while (hash_key != end);
  ------------------
  |  Branch (172:14): [True: 689, False: 0]
  ------------------
  173|      0|	return NULL;
  174|  1.40k|}
ck_str_hash_insert:
  177|   289k|{
  178|   289k|    size_t keylen = strlen(key);
  179|   289k|    return ck_str_n_hash_insert(key, keylen, value, table);
  180|   289k|}
ck_str_n_hash_insert:
  210|   289k|{    
  211|   289k|	if (table->capacity == 0)
  ------------------
  |  Branch (211:6): [True: 0, False: 289k]
  ------------------
  212|      0|		return 0;
  213|       |    	
  214|   289k|	if (keylen == 0)
  ------------------
  |  Branch (214:6): [True: 0, False: 289k]
  ------------------
  215|      0|		return 0;
  216|       |    
  217|   289k|    if (table->count >= 0.75 * table->capacity) {
  ------------------
  |  Branch (217:9): [True: 0, False: 289k]
  ------------------
  218|      0|        if (ck_hash_table_grow(table) == -1) {
  ------------------
  |  Branch (218:13): [True: 0, False: 0]
  ------------------
  219|      0|            return 0;
  220|      0|        }
  221|      0|    }
  222|       |	
  223|   289k|    uint64_t hash_key = ck_hash_str(key, keylen);
  224|   289k|	hash_key %= table->capacity;
  225|   289k|    uint64_t end = hash_key;
  226|   292k|    do {
  227|   292k|        ck_hash_entry_t *entry = &table->entries[hash_key];
  228|   292k|        char *this_key = &table->keys[entry->key_offset];
  229|   292k|        if (entry->key_length == 0) {
  ------------------
  |  Branch (229:13): [True: 8.19k, False: 283k]
  ------------------
  230|  8.19k|            table->count++;
  231|  8.19k|            while (table->keys_used + keylen > table->keys_capacity) {
  ------------------
  |  Branch (231:20): [True: 0, False: 8.19k]
  ------------------
  232|      0|                table->keys_capacity *= 2;
  233|      0|                table->keys = realloc(table->keys, table->keys_capacity);
  234|      0|            }
  235|  8.19k|            memcpy(table->keys + table->keys_used, key, keylen);
  236|  8.19k|            entry->key_offset = table->keys_used;
  237|  8.19k|            entry->key_length = keylen;
  238|  8.19k|            table->keys_used += keylen;
  239|  8.19k|            entry->value = value;
  240|  8.19k|            return 1;
  241|   283k|        } else if (entry->key_length == keylen &&
  ------------------
  |  Branch (241:20): [True: 282k, False: 1.40k]
  ------------------
  242|   282k|                   memcmp(this_key, key, keylen) == 0) {
  ------------------
  |  Branch (242:20): [True: 281k, False: 741]
  ------------------
  243|   281k|			table->entries[hash_key].value = value;
  244|   281k|			return 1;
  245|   281k|		}
  246|  2.14k|		hash_key++;
  247|  2.14k|		hash_key %= table->capacity;
  248|  2.14k|    } while (hash_key != end);
  ------------------
  |  Branch (248:14): [True: 2.14k, False: 0]
  ------------------
  249|      0|	return 0;
  250|   289k|}
ck_hash_table_init:
  253|  1.62k|{
  254|  1.62k|	ck_hash_table_t *table;
  255|  1.62k|	if ((table = malloc(sizeof(ck_hash_table_t))) == NULL)
  ------------------
  |  Branch (255:6): [True: 0, False: 1.62k]
  ------------------
  256|      0|		return NULL;
  257|       |    
  258|  1.62k|    if ((table->keys = malloc(num_entries * mean_key_length)) == NULL) {
  ------------------
  |  Branch (258:9): [True: 0, False: 1.62k]
  ------------------
  259|      0|        free(table);
  260|      0|        return NULL;
  261|      0|    }
  262|  1.62k|    table->keys_capacity = num_entries * mean_key_length;
  263|       |    
  264|  1.62k|    num_entries *= 2;
  265|       |    
  266|  1.62k|    if ((table->entries = malloc(num_entries * sizeof(ck_hash_entry_t))) == NULL) {
  ------------------
  |  Branch (266:9): [True: 0, False: 1.62k]
  ------------------
  267|      0|        free(table->keys);
  268|      0|        free(table);
  269|      0|        return NULL;
  270|      0|    }
  271|  1.62k|	table->capacity = num_entries;
  272|  1.62k|    ck_hash_table_wipe(table);
  273|  1.62k|	return table;
  274|  1.62k|}
ck_hash_table_free:
  276|  1.62k|void ck_hash_table_free(ck_hash_table_t *table) {
  277|  1.62k|    free(table->entries);
  278|  1.62k|    if (table->keys)
  ------------------
  |  Branch (278:9): [True: 1.62k, False: 0]
  ------------------
  279|  1.62k|        free(table->keys);
  280|  1.62k|    free(table);
  281|  1.62k|}
ck_hash_table_wipe:
  283|  1.62k|void ck_hash_table_wipe(ck_hash_table_t *table) {
  284|  1.62k|    table->keys_used = 0;
  285|  1.62k|    table->count = 0;
  286|  1.62k|    memset(table->entries, 0, table->capacity * sizeof(ck_hash_entry_t));
  287|  1.62k|}
CKHashTable.c:ck_hash_str:
  121|   291k|{
  122|   291k|    uint64_t hash;
  123|   291k|    unsigned char k[16] = { 0 };
  124|   291k|    siphash((unsigned char *)&hash, (const unsigned char *)str, keylen, k);
  125|   291k|    return hash;
  126|   291k|}
CKHashTable.c:siphash:
   57|   291k|{
   58|       |    /* "somepseudorandomlygeneratedbytes" */
   59|   291k|    u64 v0 = 0x736f6d6570736575ULL;
   60|   291k|    u64 v1 = 0x646f72616e646f6dULL;
   61|   291k|    u64 v2 = 0x6c7967656e657261ULL;
   62|   291k|    u64 v3 = 0x7465646279746573ULL;
   63|   291k|    u64 b;
   64|   291k|    u64 k0 = U8TO64_LE( k );
  ------------------
  |  |   37|   291k|#define U8TO64_LE(p) \
  |  |   38|   291k|(((u64)((p)[0])      ) | \
  |  |   39|   291k|((u64)((p)[1]) <<  8) | \
  |  |   40|   291k|((u64)((p)[2]) << 16) | \
  |  |   41|   291k|((u64)((p)[3]) << 24) | \
  |  |   42|   291k|((u64)((p)[4]) << 32) | \
  |  |   43|   291k|((u64)((p)[5]) << 40) | \
  |  |   44|   291k|((u64)((p)[6]) << 48) | \
  |  |   45|   291k|((u64)((p)[7]) << 56))
  ------------------
   65|   291k|    u64 k1 = U8TO64_LE( k + 8 );
  ------------------
  |  |   37|   291k|#define U8TO64_LE(p) \
  |  |   38|   291k|(((u64)((p)[0])      ) | \
  |  |   39|   291k|((u64)((p)[1]) <<  8) | \
  |  |   40|   291k|((u64)((p)[2]) << 16) | \
  |  |   41|   291k|((u64)((p)[3]) << 24) | \
  |  |   42|   291k|((u64)((p)[4]) << 32) | \
  |  |   43|   291k|((u64)((p)[5]) << 40) | \
  |  |   44|   291k|((u64)((p)[6]) << 48) | \
  |  |   45|   291k|((u64)((p)[7]) << 56))
  ------------------
   66|   291k|    u64 m;
   67|   291k|    const u8 *end = in + inlen - ( inlen % sizeof( u64 ) );
   68|   291k|    const int left = inlen & 7;
   69|   291k|    b = ( ( u64 )inlen ) << 56;
   70|   291k|    v3 ^= k1;
   71|   291k|    v2 ^= k0;
   72|   291k|    v1 ^= k1;
   73|   291k|    v0 ^= k0;
   74|       |    
   75|   346k|    for ( ; in != end; in += 8 )
  ------------------
  |  Branch (75:13): [True: 55.6k, False: 291k]
  ------------------
   76|  55.6k|    {
   77|  55.6k|        m = U8TO64_LE( in );
  ------------------
  |  |   37|  55.6k|#define U8TO64_LE(p) \
  |  |   38|  55.6k|(((u64)((p)[0])      ) | \
  |  |   39|  55.6k|((u64)((p)[1]) <<  8) | \
  |  |   40|  55.6k|((u64)((p)[2]) << 16) | \
  |  |   41|  55.6k|((u64)((p)[3]) << 24) | \
  |  |   42|  55.6k|((u64)((p)[4]) << 32) | \
  |  |   43|  55.6k|((u64)((p)[5]) << 40) | \
  |  |   44|  55.6k|((u64)((p)[6]) << 48) | \
  |  |   45|  55.6k|((u64)((p)[7]) << 56))
  ------------------
   78|       |        
   79|  55.6k|        v3 ^= m;
   80|       |        
   81|  55.6k|        SIPROUND;
  ------------------
  |  |   47|  55.6k|#define SIPROUND            \
  |  |   48|  55.6k|do {              \
  |  |   49|  55.6k|v0 += v1; v1=ROTL(v1,13); v1 ^= v0; v0=ROTL(v0,32); \
  |  |  ------------------
  |  |  |  |   27|  55.6k|#define ROTL(x,b) (u64)( ((x) << (b)) | ( (x) >> (64 - (b))) )
  |  |  ------------------
  |  |               v0 += v1; v1=ROTL(v1,13); v1 ^= v0; v0=ROTL(v0,32); \
  |  |  ------------------
  |  |  |  |   27|  55.6k|#define ROTL(x,b) (u64)( ((x) << (b)) | ( (x) >> (64 - (b))) )
  |  |  ------------------
  |  |   50|  55.6k|v2 += v3; v3=ROTL(v3,16); v3 ^= v2;     \
  |  |  ------------------
  |  |  |  |   27|  55.6k|#define ROTL(x,b) (u64)( ((x) << (b)) | ( (x) >> (64 - (b))) )
  |  |  ------------------
  |  |   51|  55.6k|v0 += v3; v3=ROTL(v3,21); v3 ^= v0;     \
  |  |  ------------------
  |  |  |  |   27|  55.6k|#define ROTL(x,b) (u64)( ((x) << (b)) | ( (x) >> (64 - (b))) )
  |  |  ------------------
  |  |   52|  55.6k|v2 += v1; v1=ROTL(v1,17); v1 ^= v2; v2=ROTL(v2,32); \
  |  |  ------------------
  |  |  |  |   27|  55.6k|#define ROTL(x,b) (u64)( ((x) << (b)) | ( (x) >> (64 - (b))) )
  |  |  ------------------
  |  |               v2 += v1; v1=ROTL(v1,17); v1 ^= v2; v2=ROTL(v2,32); \
  |  |  ------------------
  |  |  |  |   27|  55.6k|#define ROTL(x,b) (u64)( ((x) << (b)) | ( (x) >> (64 - (b))) )
  |  |  ------------------
  |  |   53|  55.6k|} while(0)
  |  |  ------------------
  |  |  |  Branch (53:9): [Folded, False: 55.6k]
  |  |  ------------------
  ------------------
   82|       |        
   83|  55.6k|        v0 ^= m;
   84|  55.6k|    }
   85|       |    
   86|   291k|    switch( left )
  ------------------
  |  Branch (86:13): [True: 291k, False: 0]
  ------------------
   87|   291k|    {
   88|  17.3k|        case 7: b |= ( ( u64 )in[ 6] )  << 48;
  ------------------
  |  Branch (88:9): [True: 17.3k, False: 273k]
  ------------------
   89|       |            
   90|  32.6k|        case 6: b |= ( ( u64 )in[ 5] )  << 40;
  ------------------
  |  Branch (90:9): [True: 15.2k, False: 276k]
  ------------------
   91|       |            
   92|  56.4k|        case 5: b |= ( ( u64 )in[ 4] )  << 32;
  ------------------
  |  Branch (92:9): [True: 23.8k, False: 267k]
  ------------------
   93|       |            
   94|  58.3k|        case 4: b |= ( ( u64 )in[ 3] )  << 24;
  ------------------
  |  Branch (94:9): [True: 1.86k, False: 289k]
  ------------------
   95|       |            
   96|  59.8k|        case 3: b |= ( ( u64 )in[ 2] )  << 16;
  ------------------
  |  Branch (96:9): [True: 1.52k, False: 289k]
  ------------------
   97|       |            
   98|   197k|        case 2: b |= ( ( u64 )in[ 1] )  <<  8;
  ------------------
  |  Branch (98:9): [True: 137k, False: 153k]
  ------------------
   99|       |            
  100|   236k|        case 1: b |= ( ( u64 )in[ 0] ); break;
  ------------------
  |  Branch (100:9): [True: 38.7k, False: 252k]
  ------------------
  101|       |            
  102|  55.0k|        case 0: break;
  ------------------
  |  Branch (102:9): [True: 55.0k, False: 236k]
  ------------------
  103|   291k|    }
  104|       |
  105|   291k|    v3 ^= b;
  106|       |    
  107|   291k|    SIPROUND;
  ------------------
  |  |   47|   291k|#define SIPROUND            \
  |  |   48|   291k|do {              \
  |  |   49|   291k|v0 += v1; v1=ROTL(v1,13); v1 ^= v0; v0=ROTL(v0,32); \
  |  |  ------------------
  |  |  |  |   27|   291k|#define ROTL(x,b) (u64)( ((x) << (b)) | ( (x) >> (64 - (b))) )
  |  |  ------------------
  |  |               v0 += v1; v1=ROTL(v1,13); v1 ^= v0; v0=ROTL(v0,32); \
  |  |  ------------------
  |  |  |  |   27|   291k|#define ROTL(x,b) (u64)( ((x) << (b)) | ( (x) >> (64 - (b))) )
  |  |  ------------------
  |  |   50|   291k|v2 += v3; v3=ROTL(v3,16); v3 ^= v2;     \
  |  |  ------------------
  |  |  |  |   27|   291k|#define ROTL(x,b) (u64)( ((x) << (b)) | ( (x) >> (64 - (b))) )
  |  |  ------------------
  |  |   51|   291k|v0 += v3; v3=ROTL(v3,21); v3 ^= v0;     \
  |  |  ------------------
  |  |  |  |   27|   291k|#define ROTL(x,b) (u64)( ((x) << (b)) | ( (x) >> (64 - (b))) )
  |  |  ------------------
  |  |   52|   291k|v2 += v1; v1=ROTL(v1,17); v1 ^= v2; v2=ROTL(v2,32); \
  |  |  ------------------
  |  |  |  |   27|   291k|#define ROTL(x,b) (u64)( ((x) << (b)) | ( (x) >> (64 - (b))) )
  |  |  ------------------
  |  |               v2 += v1; v1=ROTL(v1,17); v1 ^= v2; v2=ROTL(v2,32); \
  |  |  ------------------
  |  |  |  |   27|   291k|#define ROTL(x,b) (u64)( ((x) << (b)) | ( (x) >> (64 - (b))) )
  |  |  ------------------
  |  |   53|   291k|} while(0)
  |  |  ------------------
  |  |  |  Branch (53:9): [Folded, False: 291k]
  |  |  ------------------
  ------------------
  108|       |    
  109|   291k|    v0 ^= b;
  110|   291k|    v2 ^= 0xff;
  111|       |    
  112|   291k|    SIPROUND;
  ------------------
  |  |   47|   291k|#define SIPROUND            \
  |  |   48|   291k|do {              \
  |  |   49|   291k|v0 += v1; v1=ROTL(v1,13); v1 ^= v0; v0=ROTL(v0,32); \
  |  |  ------------------
  |  |  |  |   27|   291k|#define ROTL(x,b) (u64)( ((x) << (b)) | ( (x) >> (64 - (b))) )
  |  |  ------------------
  |  |               v0 += v1; v1=ROTL(v1,13); v1 ^= v0; v0=ROTL(v0,32); \
  |  |  ------------------
  |  |  |  |   27|   291k|#define ROTL(x,b) (u64)( ((x) << (b)) | ( (x) >> (64 - (b))) )
  |  |  ------------------
  |  |   50|   291k|v2 += v3; v3=ROTL(v3,16); v3 ^= v2;     \
  |  |  ------------------
  |  |  |  |   27|   291k|#define ROTL(x,b) (u64)( ((x) << (b)) | ( (x) >> (64 - (b))) )
  |  |  ------------------
  |  |   51|   291k|v0 += v3; v3=ROTL(v3,21); v3 ^= v0;     \
  |  |  ------------------
  |  |  |  |   27|   291k|#define ROTL(x,b) (u64)( ((x) << (b)) | ( (x) >> (64 - (b))) )
  |  |  ------------------
  |  |   52|   291k|v2 += v1; v1=ROTL(v1,17); v1 ^= v2; v2=ROTL(v2,32); \
  |  |  ------------------
  |  |  |  |   27|   291k|#define ROTL(x,b) (u64)( ((x) << (b)) | ( (x) >> (64 - (b))) )
  |  |  ------------------
  |  |               v2 += v1; v1=ROTL(v1,17); v1 ^= v2; v2=ROTL(v2,32); \
  |  |  ------------------
  |  |  |  |   27|   291k|#define ROTL(x,b) (u64)( ((x) << (b)) | ( (x) >> (64 - (b))) )
  |  |  ------------------
  |  |   53|   291k|} while(0)
  |  |  ------------------
  |  |  |  Branch (53:9): [Folded, False: 291k]
  |  |  ------------------
  ------------------
  113|   291k|    SIPROUND;
  ------------------
  |  |   47|   291k|#define SIPROUND            \
  |  |   48|   291k|do {              \
  |  |   49|   291k|v0 += v1; v1=ROTL(v1,13); v1 ^= v0; v0=ROTL(v0,32); \
  |  |  ------------------
  |  |  |  |   27|   291k|#define ROTL(x,b) (u64)( ((x) << (b)) | ( (x) >> (64 - (b))) )
  |  |  ------------------
  |  |               v0 += v1; v1=ROTL(v1,13); v1 ^= v0; v0=ROTL(v0,32); \
  |  |  ------------------
  |  |  |  |   27|   291k|#define ROTL(x,b) (u64)( ((x) << (b)) | ( (x) >> (64 - (b))) )
  |  |  ------------------
  |  |   50|   291k|v2 += v3; v3=ROTL(v3,16); v3 ^= v2;     \
  |  |  ------------------
  |  |  |  |   27|   291k|#define ROTL(x,b) (u64)( ((x) << (b)) | ( (x) >> (64 - (b))) )
  |  |  ------------------
  |  |   51|   291k|v0 += v3; v3=ROTL(v3,21); v3 ^= v0;     \
  |  |  ------------------
  |  |  |  |   27|   291k|#define ROTL(x,b) (u64)( ((x) << (b)) | ( (x) >> (64 - (b))) )
  |  |  ------------------
  |  |   52|   291k|v2 += v1; v1=ROTL(v1,17); v1 ^= v2; v2=ROTL(v2,32); \
  |  |  ------------------
  |  |  |  |   27|   291k|#define ROTL(x,b) (u64)( ((x) << (b)) | ( (x) >> (64 - (b))) )
  |  |  ------------------
  |  |               v2 += v1; v1=ROTL(v1,17); v1 ^= v2; v2=ROTL(v2,32); \
  |  |  ------------------
  |  |  |  |   27|   291k|#define ROTL(x,b) (u64)( ((x) << (b)) | ( (x) >> (64 - (b))) )
  |  |  ------------------
  |  |   53|   291k|} while(0)
  |  |  ------------------
  |  |  |  Branch (53:9): [Folded, False: 291k]
  |  |  ------------------
  ------------------
  114|       |    
  115|   291k|    b = v0 ^ v1 ^ v2  ^ v3;
  116|   291k|    U64TO8_LE( out, b );
  ------------------
  |  |   33|   291k|#define U64TO8_LE(p, v)         \
  |  |  ------------------
  |  |  |  |   29|   291k|#define U32TO8_LE(p, v)         \
  |  |  |  |   30|   291k|(p)[0] = (u8)((v)      ); (p)[1] = (u8)((v) >>  8); \
  |  |  |  |   31|   291k|(p)[2] = (u8)((v) >> 16); (p)[3] = (u8)((v) >> 24);
  |  |  ------------------
  |  |   34|   291k|U32TO8_LE((p),     (u32)((v)      ));   \
  |  |  ------------------
  |  |  |  |   29|   291k|#define U32TO8_LE(p, v)         \
  |  |  |  |   30|   291k|(p)[0] = (u8)((v)      ); (p)[1] = (u8)((v) >>  8); \
  |  |  |  |   31|   291k|(p)[2] = (u8)((v) >> 16); (p)[3] = (u8)((v) >> 24);
  |  |  ------------------
  |  |   35|   291k|U32TO8_LE((p) + 4, (u32)((v) >> 32));
  ------------------
  117|   291k|    return 0;
  118|   291k|}

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

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

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

readstat_convert:
    7|  2.11M|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|  24.1M|    while (src_len && (src[src_len-1] == ' ' || src[src_len-1] == '\0')) {
  ------------------
  |  Branch (10:12): [True: 24.1M, False: 19.5k]
  |  Branch (10:24): [True: 3.06M, False: 21.0M]
  |  Branch (10:49): [True: 18.9M, False: 2.09M]
  ------------------
   11|  22.0M|        src_len--;
   12|  22.0M|    }
   13|  2.11M|    if (dst_len == 0) {
  ------------------
  |  Branch (13:9): [True: 0, False: 2.11M]
  ------------------
   14|      0|        return READSTAT_ERROR_CONVERT_LONG_STRING;
   15|  2.11M|    } else if (converter) {
  ------------------
  |  Branch (15:16): [True: 2.36k, False: 2.10M]
  ------------------
   16|  2.36k|        size_t dst_left = dst_len - 1;
   17|  2.36k|        char *dst_end = dst;
   18|  2.36k|        size_t status = iconv(converter, (readstat_iconv_inbuf_t)&src, &src_len, &dst_end, &dst_left);
   19|  2.36k|        if (status == (size_t)-1) {
  ------------------
  |  Branch (19:13): [True: 932, False: 1.43k]
  ------------------
   20|    932|            if (errno == E2BIG) {
  ------------------
  |  Branch (20:17): [True: 1, False: 931]
  ------------------
   21|      1|                return READSTAT_ERROR_CONVERT_LONG_STRING;
   22|    931|            } else if (errno == EILSEQ) {
  ------------------
  |  Branch (22:24): [True: 532, False: 399]
  ------------------
   23|    532|                return READSTAT_ERROR_CONVERT_BAD_STRING;
   24|    532|            } else if (errno != EINVAL) { /* EINVAL indicates improper truncation; accept it */
  ------------------
  |  Branch (24:24): [True: 0, False: 399]
  ------------------
   25|      0|                return READSTAT_ERROR_CONVERT;
   26|      0|            }
   27|    932|        }
   28|  1.83k|        dst[dst_len - dst_left - 1] = '\0';
   29|  2.10M|    } else if (src_len + 1 > dst_len) {
  ------------------
  |  Branch (29:16): [True: 18, False: 2.10M]
  ------------------
   30|     18|        return READSTAT_ERROR_CONVERT_LONG_STRING;
   31|  2.10M|    } else {
   32|  2.10M|        memcpy(dst, src, src_len);
   33|  2.10M|        dst[src_len] = '\0';
   34|  2.10M|    }
   35|  2.11M|    return READSTAT_OK;
   36|  2.11M|}

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

readstat_malloc:
   10|  47.4k|void *readstat_malloc(size_t len) {
   11|  47.4k|    if (len > MAX_MALLOC_SIZE || len == 0) {
  ------------------
  |  |    3|  94.8k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
  |  Branch (11:9): [True: 214, False: 47.2k]
  |  Branch (11:34): [True: 1.17k, False: 46.0k]
  ------------------
   12|  1.38k|        return NULL;
   13|  1.38k|    }
   14|  46.0k|    return malloc(len);
   15|  47.4k|}
readstat_calloc:
   17|   475k|void *readstat_calloc(size_t count, size_t size) {
   18|   475k|    if (count > MAX_MALLOC_SIZE || size > MAX_MALLOC_SIZE || count * size > MAX_MALLOC_SIZE) {
  ------------------
  |  |    3|   951k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
                  if (count > MAX_MALLOC_SIZE || size > MAX_MALLOC_SIZE || count * size > MAX_MALLOC_SIZE) {
  ------------------
  |  |    3|   951k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
                  if (count > MAX_MALLOC_SIZE || size > MAX_MALLOC_SIZE || count * size > MAX_MALLOC_SIZE) {
  ------------------
  |  |    3|   475k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
  |  Branch (18:9): [True: 23, False: 475k]
  |  Branch (18:36): [True: 0, False: 475k]
  |  Branch (18:62): [True: 23, False: 475k]
  ------------------
   19|     46|        return NULL;
   20|     46|    }
   21|   475k|    if (count == 0 || size == 0) {
  ------------------
  |  Branch (21:9): [True: 14, False: 475k]
  |  Branch (21:23): [True: 0, False: 475k]
  ------------------
   22|     14|        return NULL;
   23|     14|    }
   24|   475k|    return calloc(count, size);
   25|   475k|}
readstat_realloc:
   27|  7.77k|void *readstat_realloc(void *ptr, size_t len) {
   28|  7.77k|    if (len > MAX_MALLOC_SIZE || len == 0) {
  ------------------
  |  |    3|  15.5k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
  |  Branch (28:9): [True: 103, False: 7.67k]
  |  Branch (28:34): [True: 1, False: 7.67k]
  ------------------
   29|    104|        if (ptr)
  ------------------
  |  Branch (29:13): [True: 51, False: 53]
  ------------------
   30|     51|            free(ptr);
   31|    104|        return NULL;
   32|    104|    }
   33|  7.67k|    return realloc(ptr, len);
   34|  7.77k|}

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

sav_ctx_init:
   23|  5.17k|sav_ctx_t *sav_ctx_init(sav_file_header_record_t *header, readstat_io_t *io) {
   24|  5.17k|    sav_ctx_t *ctx = readstat_calloc(1, sizeof(sav_ctx_t));
   25|  5.17k|    if (ctx == NULL) {
  ------------------
  |  Branch (25:9): [True: 0, False: 5.17k]
  ------------------
   26|      0|        return NULL;
   27|      0|    }
   28|       |
   29|  5.17k|    if (memcmp(&header->rec_type, "$FL2", 4) == 0) {
  ------------------
  |  Branch (29:9): [True: 3.06k, False: 2.10k]
  ------------------
   30|  3.06k|        ctx->format_version = 2;
   31|  3.06k|    } else if (memcmp(&header->rec_type, "$FL3", 4) == 0) {
  ------------------
  |  Branch (31:16): [True: 2.09k, False: 19]
  ------------------
   32|  2.09k|        ctx->format_version = 3;
   33|  2.09k|    } else {
   34|     19|        sav_ctx_free(ctx);
   35|     19|        return NULL;
   36|     19|    }
   37|       |    
   38|  5.15k|    ctx->bswap = !(header->layout_code == 2 || header->layout_code == 3);
  ------------------
  |  Branch (38:20): [True: 3.27k, False: 1.88k]
  |  Branch (38:48): [True: 275, False: 1.60k]
  ------------------
   39|  5.15k|    ctx->endianness = (machine_is_little_endian() ^ ctx->bswap) ? READSTAT_ENDIAN_LITTLE : READSTAT_ENDIAN_BIG;
  ------------------
  |  Branch (39:23): [True: 3.55k, False: 1.60k]
  ------------------
   40|       |
   41|  5.15k|    if (header->compression == 1 || byteswap4(header->compression) == 1) {
  ------------------
  |  Branch (41:9): [True: 350, False: 4.80k]
  |  Branch (41:37): [True: 133, False: 4.67k]
  ------------------
   42|    483|        ctx->compression = READSTAT_COMPRESS_ROWS;
   43|  4.67k|    } else if (header->compression == 2 || byteswap4(header->compression) == 2) {
  ------------------
  |  Branch (43:16): [True: 399, False: 4.27k]
  |  Branch (43:44): [True: 79, False: 4.19k]
  ------------------
   44|    478|        ctx->compression = READSTAT_COMPRESS_BINARY;
   45|    478|    }
   46|  5.15k|    ctx->record_count = ctx->bswap ? byteswap4(header->ncases) : header->ncases;
  ------------------
  |  Branch (46:25): [True: 1.60k, False: 3.55k]
  ------------------
   47|  5.15k|    ctx->fweight_index = ctx->bswap ? byteswap4(header->weight_index) : header->weight_index;
  ------------------
  |  Branch (47:26): [True: 1.60k, False: 3.55k]
  ------------------
   48|       |
   49|  5.15k|    ctx->missing_double = SAV_MISSING_DOUBLE;
  ------------------
  |  |   43|  5.15k|#define SAV_MISSING_DOUBLE   0xFFEFFFFFFFFFFFFFUL
  ------------------
   50|  5.15k|    ctx->lowest_double = SAV_LOWEST_DOUBLE;
  ------------------
  |  |   44|  5.15k|#define SAV_LOWEST_DOUBLE    0xFFEFFFFFFFFFFFFEUL
  ------------------
   51|  5.15k|    ctx->highest_double = SAV_HIGHEST_DOUBLE;
  ------------------
  |  |   42|  5.15k|#define SAV_HIGHEST_DOUBLE   0x7FEFFFFFFFFFFFFFUL
  ------------------
   52|       |    
   53|  5.15k|    ctx->bias = ctx->bswap ? byteswap_double(header->bias) : header->bias;
  ------------------
  |  Branch (53:17): [True: 1.60k, False: 3.55k]
  ------------------
   54|       |    
   55|  5.15k|    ctx->varinfo_capacity = SAV_VARINFO_INITIAL_CAPACITY;
  ------------------
  |  |   21|  5.15k|#define SAV_VARINFO_INITIAL_CAPACITY  512
  ------------------
   56|       |    
   57|  5.15k|    if ((ctx->varinfo = readstat_calloc(ctx->varinfo_capacity, sizeof(spss_varinfo_t *))) == NULL) {
  ------------------
  |  Branch (57:9): [True: 0, False: 5.15k]
  ------------------
   58|      0|        sav_ctx_free(ctx);
   59|      0|        return NULL;
   60|      0|    }
   61|       |
   62|  5.15k|    ctx->mr_sets = NULL;
   63|       |
   64|  5.15k|    ctx->io = io;
   65|       |    
   66|  5.15k|    return ctx;
   67|  5.15k|}
sav_ctx_free:
   69|  5.17k|void sav_ctx_free(sav_ctx_t *ctx) {
   70|  5.17k|    if (ctx->varinfo) {
  ------------------
  |  Branch (70:9): [True: 5.15k, False: 19]
  ------------------
   71|  5.15k|        int i;
   72|   467k|        for (i=0; i<ctx->var_index; i++) {
  ------------------
  |  Branch (72:19): [True: 462k, False: 5.15k]
  ------------------
   73|   462k|            spss_varinfo_free(ctx->varinfo[i]);
   74|   462k|        }
   75|  5.15k|        free(ctx->varinfo);
   76|  5.15k|    }
   77|  5.17k|    if (ctx->variables) {
  ------------------
  |  Branch (77:9): [True: 1.62k, False: 3.54k]
  ------------------
   78|  1.62k|        int i;
   79|   289k|        for (i=0; i<ctx->var_count; i++) {
  ------------------
  |  Branch (79:19): [True: 288k, False: 1.62k]
  ------------------
   80|   288k|            if (ctx->variables[i])
  ------------------
  |  Branch (80:17): [True: 286k, False: 2.04k]
  ------------------
   81|   286k|                free(ctx->variables[i]);
   82|   288k|        }
   83|  1.62k|        free(ctx->variables);
   84|  1.62k|    }
   85|  5.17k|    if (ctx->raw_string)
  ------------------
  |  Branch (85:9): [True: 1.56k, False: 3.60k]
  ------------------
   86|  1.56k|        free(ctx->raw_string);
   87|  5.17k|    if (ctx->utf8_string)
  ------------------
  |  Branch (87:9): [True: 1.56k, False: 3.61k]
  ------------------
   88|  1.56k|        free(ctx->utf8_string);
   89|  5.17k|    if (ctx->converter)
  ------------------
  |  Branch (89:9): [True: 118, False: 5.05k]
  ------------------
   90|    118|        iconv_close(ctx->converter);
   91|  5.17k|    if (ctx->variable_display_values) {
  ------------------
  |  Branch (91:9): [True: 235, False: 4.93k]
  ------------------
   92|    235|        free(ctx->variable_display_values);
   93|    235|    }
   94|  5.17k|    if (ctx->mr_sets) {
  ------------------
  |  Branch (94:9): [True: 214, False: 4.96k]
  ------------------
   95|    781|        for (size_t i = 0; i < ctx->multiple_response_sets_length; i++) {
  ------------------
  |  Branch (95:28): [True: 567, False: 214]
  ------------------
   96|    567|            if (ctx->mr_sets[i].name) {
  ------------------
  |  Branch (96:17): [True: 567, False: 0]
  ------------------
   97|    567|                free(ctx->mr_sets[i].name);
   98|    567|            }
   99|    567|            if (ctx->mr_sets[i].label) {
  ------------------
  |  Branch (99:17): [True: 567, False: 0]
  ------------------
  100|    567|                free(ctx->mr_sets[i].label);
  101|    567|            }
  102|    567|            if (ctx->mr_sets[i].subvariables) {
  ------------------
  |  Branch (102:17): [True: 407, False: 160]
  ------------------
  103|  4.09k|                for (size_t j = 0; j < ctx->mr_sets[i].num_subvars; j++) {
  ------------------
  |  Branch (103:36): [True: 3.68k, False: 407]
  ------------------
  104|  3.68k|                    if (ctx->mr_sets[i].subvariables[j]) {
  ------------------
  |  Branch (104:25): [True: 3.68k, False: 0]
  ------------------
  105|  3.68k|                        free(ctx->mr_sets[i].subvariables[j]);
  106|  3.68k|                    }
  107|  3.68k|                }
  108|    407|                free(ctx->mr_sets[i].subvariables);
  109|    407|            }
  110|    567|        }
  111|    214|        free(ctx->mr_sets);
  112|    214|    }
  113|  5.17k|    free(ctx);
  114|  5.17k|}

sav_decompress_row:
   77|  2.27M|void sav_decompress_row(struct sav_row_stream_s *state) {
   78|  2.27M|    double fp_value;
   79|  2.27M|    uint64_t missing_value = state->bswap ? byteswap8(state->missing_value) : state->missing_value;
  ------------------
  |  Branch (79:30): [True: 142k, False: 2.13M]
  ------------------
   80|  2.27M|    int i = 8 - state->i;
   81|  2.63M|    while (1) {
  ------------------
  |  Branch (81:12): [True: 2.63M, Folded]
  ------------------
   82|  2.63M|        if (i == 8) {
  ------------------
  |  Branch (82:13): [True: 643k, False: 1.99M]
  ------------------
   83|   643k|            if (state->avail_in < 8) {
  ------------------
  |  Branch (83:17): [True: 237, False: 643k]
  ------------------
   84|    237|                state->status = SAV_ROW_STREAM_NEED_DATA;
   85|    237|                goto done;
   86|    237|            }
   87|       |
   88|   643k|            memcpy(state->chunk, state->next_in, 8);
   89|   643k|            state->next_in += 8;
   90|   643k|            state->avail_in -= 8;
   91|   643k|            i = 0;
   92|   643k|        }
   93|       |
   94|  5.50M|        while (i<8) {
  ------------------
  |  Branch (94:16): [True: 5.14M, False: 362k]
  ------------------
   95|  5.14M|            switch (state->chunk[i]) {
   96|  2.55M|                case 0:
  ------------------
  |  Branch (96:17): [True: 2.55M, False: 2.59M]
  ------------------
   97|  2.55M|                    break;
   98|     50|                case 252:
  ------------------
  |  Branch (98:17): [True: 50, False: 5.14M]
  ------------------
   99|     50|                    state->status = SAV_ROW_STREAM_FINISHED_ALL;
  100|     50|                    goto done;
  101|   112k|                case 253:
  ------------------
  |  Branch (101:17): [True: 112k, False: 5.03M]
  ------------------
  102|   112k|                    if (state->avail_in < 8) {
  ------------------
  |  Branch (102:25): [True: 54, False: 112k]
  ------------------
  103|     54|                        state->status = SAV_ROW_STREAM_NEED_DATA;
  104|     54|                        goto done;
  105|     54|                    }
  106|   112k|                    memcpy(state->next_out, state->next_in, 8);
  107|   112k|                    state->next_out += 8;
  108|   112k|                    state->avail_out -= 8;
  109|   112k|                    state->next_in += 8;
  110|   112k|                    state->avail_in -= 8;
  111|   112k|                    break;
  112|  1.73k|                case 254:
  ------------------
  |  Branch (112:17): [True: 1.73k, False: 5.14M]
  ------------------
  113|  1.73k|                    memset(state->next_out, ' ', 8);
  114|  1.73k|                    state->next_out += 8;
  115|  1.73k|                    state->avail_out -= 8;
  116|  1.73k|                    break;
  117|  73.4k|                case 255:
  ------------------
  |  Branch (117:17): [True: 73.4k, False: 5.07M]
  ------------------
  118|  73.4k|                    memcpy(state->next_out, &missing_value, sizeof(uint64_t));
  119|  73.4k|                    state->next_out += 8;
  120|  73.4k|                    state->avail_out -= 8;
  121|  73.4k|                    break;
  122|  2.40M|                default:
  ------------------
  |  Branch (122:17): [True: 2.40M, False: 2.73M]
  ------------------
  123|  2.40M|                    fp_value = state->chunk[i] - state->bias;
  124|  2.40M|                    fp_value = state->bswap ? byteswap_double(fp_value) : fp_value;
  ------------------
  |  Branch (124:32): [True: 133k, False: 2.27M]
  ------------------
  125|  2.40M|                    memcpy(state->next_out, &fp_value, sizeof(double));
  126|  2.40M|                    state->next_out += 8;
  127|  2.40M|                    state->avail_out -= 8;
  128|  2.40M|                    break;
  129|  5.14M|            }
  130|  5.14M|            i++;
  131|  5.14M|            if (state->avail_out < 8) {
  ------------------
  |  Branch (131:17): [True: 2.27M, False: 2.87M]
  ------------------
  132|  2.27M|                state->status = SAV_ROW_STREAM_FINISHED_ROW;
  133|  2.27M|                goto done;
  134|  2.27M|            }
  135|  5.14M|        }
  136|  2.63M|    }
  137|  2.27M|done:
  138|  2.27M|    state->i = 8 - i;
  139|  2.27M|}

sav_parse_long_variable_names_record:
  284|  2.93k|readstat_error_t sav_parse_long_variable_names_record(void *data, int count, sav_ctx_t *ctx) {
  285|  2.93k|    unsigned char *c_data = (unsigned char *)data;
  286|  2.93k|    int var_count = count_vars(ctx);
  287|  2.93k|    readstat_error_t retval = READSTAT_OK;
  288|       |
  289|  2.93k|    char temp_key[8+1];
  290|  2.93k|    char temp_val[64+1];
  291|  2.93k|    unsigned char *str_start = NULL;
  292|  2.93k|    size_t str_len = 0;
  293|       |    
  294|  2.93k|    char error_buf[8192];
  295|  2.93k|    unsigned char *p = c_data;
  296|  2.93k|    unsigned char *pe = c_data + count;
  297|       |
  298|  2.93k|    varlookup_t *table = build_lookup_table(var_count, ctx);
  299|       |
  300|  2.93k|    unsigned char *eof = pe;
  301|       |
  302|  2.93k|    int cs;
  303|       |
  304|       |    
  305|  2.93k|#line 306 "src/spss/readstat_sav_parse.c"
  306|  2.93k|	{
  307|  2.93k|	cs = sav_long_variable_parse_start;
  308|  2.93k|	}
  309|       |
  310|  2.93k|#line 311 "src/spss/readstat_sav_parse.c"
  311|  2.93k|	{
  312|  2.93k|	int _klen;
  313|  2.93k|	unsigned int _trans;
  314|  2.93k|	const char *_acts;
  315|  2.93k|	unsigned int _nacts;
  316|  2.93k|	const unsigned char *_keys;
  317|       |
  318|  2.93k|	if ( p == pe )
  ------------------
  |  Branch (318:7): [True: 0, False: 2.93k]
  ------------------
  319|      0|		goto _test_eof;
  320|  2.93k|	if ( cs == 0 )
  ------------------
  |  Branch (320:7): [True: 0, False: 2.93k]
  ------------------
  321|      0|		goto _out;
  322|  39.5k|_resume:
  323|  39.5k|	_keys = _sav_long_variable_parse_trans_keys + _sav_long_variable_parse_key_offsets[cs];
  324|  39.5k|	_trans = _sav_long_variable_parse_index_offsets[cs];
  325|       |
  326|  39.5k|	_klen = _sav_long_variable_parse_single_lengths[cs];
  327|  39.5k|	if ( _klen > 0 ) {
  ------------------
  |  Branch (327:7): [True: 39.5k, False: 0]
  ------------------
  328|  39.5k|		const unsigned char *_lower = _keys;
  329|  39.5k|		const unsigned char *_mid;
  330|  39.5k|		const unsigned char *_upper = _keys + _klen - 1;
  331|  93.0k|		while (1) {
  ------------------
  |  Branch (331:10): [True: 93.0k, Folded]
  ------------------
  332|  93.0k|			if ( _upper < _lower )
  ------------------
  |  Branch (332:9): [True: 30.2k, False: 62.7k]
  ------------------
  333|  30.2k|				break;
  334|       |
  335|  62.7k|			_mid = _lower + ((_upper-_lower) >> 1);
  336|  62.7k|			if ( (*p) < *_mid )
  ------------------
  |  Branch (336:9): [True: 33.6k, False: 29.1k]
  ------------------
  337|  33.6k|				_upper = _mid - 1;
  338|  29.1k|			else if ( (*p) > *_mid )
  ------------------
  |  Branch (338:14): [True: 19.8k, False: 9.26k]
  ------------------
  339|  19.8k|				_lower = _mid + 1;
  340|  9.26k|			else {
  341|  9.26k|				_trans += (unsigned int)(_mid - _keys);
  342|  9.26k|				goto _match;
  343|  9.26k|			}
  344|  62.7k|		}
  345|  30.2k|		_keys += _klen;
  346|  30.2k|		_trans += _klen;
  347|  30.2k|	}
  348|       |
  349|  30.2k|	_klen = _sav_long_variable_parse_range_lengths[cs];
  350|  30.2k|	if ( _klen > 0 ) {
  ------------------
  |  Branch (350:7): [True: 30.2k, False: 4]
  ------------------
  351|  30.2k|		const unsigned char *_lower = _keys;
  352|  30.2k|		const unsigned char *_mid;
  353|  30.2k|		const unsigned char *_upper = _keys + (_klen<<1) - 2;
  354|  79.7k|		while (1) {
  ------------------
  |  Branch (354:10): [True: 79.7k, Folded]
  ------------------
  355|  79.7k|			if ( _upper < _lower )
  ------------------
  |  Branch (355:9): [True: 30.1k, False: 49.6k]
  ------------------
  356|  30.1k|				break;
  357|       |
  358|  49.6k|			_mid = _lower + (((_upper-_lower) >> 1) & ~1);
  359|  49.6k|			if ( (*p) < _mid[0] )
  ------------------
  |  Branch (359:9): [True: 10.7k, False: 38.8k]
  ------------------
  360|  10.7k|				_upper = _mid - 2;
  361|  38.8k|			else if ( (*p) > _mid[1] )
  ------------------
  |  Branch (361:14): [True: 38.7k, False: 145]
  ------------------
  362|  38.7k|				_lower = _mid + 2;
  363|    145|			else {
  364|    145|				_trans += (unsigned int)((_mid - _keys)>>1);
  365|    145|				goto _match;
  366|    145|			}
  367|  49.6k|		}
  368|  30.1k|		_trans += _klen;
  369|  30.1k|	}
  370|       |
  371|  39.5k|_match:
  372|  39.5k|	_trans = _sav_long_variable_parse_indicies[_trans];
  373|  39.5k|	cs = _sav_long_variable_parse_trans_targs[_trans];
  374|       |
  375|  39.5k|	if ( _sav_long_variable_parse_trans_actions[_trans] == 0 )
  ------------------
  |  Branch (375:7): [True: 18.4k, False: 21.0k]
  ------------------
  376|  18.4k|		goto _again;
  377|       |
  378|  21.0k|	_acts = _sav_long_variable_parse_actions + _sav_long_variable_parse_trans_actions[_trans];
  379|  21.0k|	_nacts = (unsigned int) *_acts++;
  380|  54.7k|	while ( _nacts-- > 0 )
  ------------------
  |  Branch (380:10): [True: 33.7k, False: 21.0k]
  ------------------
  381|  33.7k|	{
  382|  33.7k|		switch ( *_acts++ )
  ------------------
  |  Branch (382:12): [True: 33.7k, False: 0]
  ------------------
  383|  33.7k|		{
  384|  5.89k|	case 0:
  ------------------
  |  Branch (384:2): [True: 5.89k, False: 27.8k]
  ------------------
  385|  5.89k|#line 13 "src/spss/readstat_sav_parse.rl"
  386|  5.89k|	{
  387|  5.89k|        memcpy(temp_key, str_start, str_len);
  388|  5.89k|        temp_key[str_len] = '\0';
  389|  5.89k|    }
  390|  5.89k|	break;
  391|  5.93k|	case 1:
  ------------------
  |  Branch (391:2): [True: 5.93k, False: 27.7k]
  ------------------
  392|  5.93k|#line 20 "src/spss/readstat_sav_parse.rl"
  393|  5.93k|	{ str_start = p; }
  394|  5.93k|	break;
  395|  5.89k|	case 2:
  ------------------
  |  Branch (395:2): [True: 5.89k, False: 27.8k]
  ------------------
  396|  5.89k|#line 20 "src/spss/readstat_sav_parse.rl"
  397|  5.89k|	{ str_len = p - str_start; }
  398|  5.89k|	break;
  399|  3.37k|	case 3:
  ------------------
  |  Branch (399:2): [True: 3.37k, False: 30.3k]
  ------------------
  400|  3.37k|#line 102 "src/spss/readstat_sav_parse.rl"
  401|  3.37k|	{
  402|  3.37k|            varlookup_t *found = bsearch(temp_key, table, var_count, sizeof(varlookup_t), &compare_key_varlookup);
  403|  3.37k|            if (!found) {
  ------------------
  |  Branch (403:17): [True: 1.72k, False: 1.64k]
  ------------------
  404|  1.72k|                snprintf(error_buf, sizeof(error_buf), "Failed to find %s", temp_key);
  405|  1.72k|                if (ctx->handle.error)
  ------------------
  |  Branch (405:21): [True: 0, False: 1.72k]
  ------------------
  406|      0|                    ctx->handle.error(error_buf, ctx->user_ctx);
  407|  1.72k|            } else {
  408|       |                // Handle the edge case where a ghost variable name (from a multi-segment
  409|       |                // variable) is identical to a real variable name. Normally we handle this
  410|       |                // by incrementing the loop variable by n_segments, but n_segments hasn't
  411|       |                // been set when this record is processed. So just set the longname to every
  412|       |                // matching variable, ghost or real.
  413|  1.64k|                varlookup_t *iter_match = found;
  414|  3.75k|                while (iter_match >= table && strcmp(iter_match->name, temp_key) == 0) {
  ------------------
  |  Branch (414:24): [True: 3.06k, False: 696]
  |  Branch (414:47): [True: 2.11k, False: 948]
  ------------------
  415|  2.11k|                    spss_varinfo_t *info = ctx->varinfo[iter_match->index];
  416|  2.11k|                    snprintf(info->longname, sizeof(info->longname), "%*s", (int)str_len, temp_val);
  417|  2.11k|                    iter_match--;
  418|  2.11k|                }
  419|  1.64k|                iter_match = found + 1;
  420|  2.45k|                while (iter_match - table < var_count && strcmp(iter_match->name, temp_key) == 0) {
  ------------------
  |  Branch (420:24): [True: 1.43k, False: 1.01k]
  |  Branch (420:58): [True: 806, False: 633]
  ------------------
  421|    806|                    spss_varinfo_t *info = ctx->varinfo[iter_match->index];
  422|    806|                    snprintf(info->longname, sizeof(info->longname), "%*s", (int)str_len, temp_val);
  423|    806|                    iter_match++;
  424|    806|                }
  425|  1.64k|            }
  426|  3.37k|        }
  427|  3.37k|	break;
  428|  3.37k|	case 4:
  ------------------
  |  Branch (428:2): [True: 3.37k, False: 30.3k]
  ------------------
  429|  3.37k|#line 129 "src/spss/readstat_sav_parse.rl"
  430|  3.37k|	{
  431|  3.37k|            memcpy(temp_val, str_start, str_len);
  432|  3.37k|            temp_val[str_len] = '\0';
  433|  3.37k|        }
  434|  3.37k|	break;
  435|  5.87k|	case 5:
  ------------------
  |  Branch (435:2): [True: 5.87k, False: 27.8k]
  ------------------
  436|  5.87k|#line 134 "src/spss/readstat_sav_parse.rl"
  437|  5.87k|	{ str_start = p; }
  438|  5.87k|	break;
  439|  3.37k|	case 6:
  ------------------
  |  Branch (439:2): [True: 3.37k, False: 30.3k]
  ------------------
  440|  3.37k|#line 134 "src/spss/readstat_sav_parse.rl"
  441|  3.37k|	{ str_len = p - str_start; }
  442|  3.37k|	break;
  443|  33.7k|#line 444 "src/spss/readstat_sav_parse.c"
  444|  33.7k|		}
  445|  33.7k|	}
  446|       |
  447|  39.5k|_again:
  448|  39.5k|	if ( cs == 0 )
  ------------------
  |  Branch (448:7): [True: 154, False: 39.3k]
  ------------------
  449|    154|		goto _out;
  450|  39.3k|	if ( ++p != pe )
  ------------------
  |  Branch (450:7): [True: 36.5k, False: 2.78k]
  ------------------
  451|  36.5k|		goto _resume;
  452|  2.78k|	_test_eof: {}
  453|  2.78k|	if ( p == eof )
  ------------------
  |  Branch (453:7): [True: 2.78k, False: 0]
  ------------------
  454|  2.78k|	{
  455|  2.78k|	const char *__acts = _sav_long_variable_parse_actions + _sav_long_variable_parse_eof_actions[cs];
  456|  2.78k|	unsigned int __nacts = (unsigned int) *__acts++;
  457|  10.2k|	while ( __nacts-- > 0 ) {
  ------------------
  |  Branch (457:10): [True: 7.48k, False: 2.78k]
  ------------------
  458|  7.48k|		switch ( *__acts++ ) {
  ------------------
  |  Branch (458:12): [True: 7.48k, False: 0]
  ------------------
  459|  2.49k|	case 3:
  ------------------
  |  Branch (459:2): [True: 2.49k, False: 4.98k]
  ------------------
  460|  2.49k|#line 102 "src/spss/readstat_sav_parse.rl"
  461|  2.49k|	{
  462|  2.49k|            varlookup_t *found = bsearch(temp_key, table, var_count, sizeof(varlookup_t), &compare_key_varlookup);
  463|  2.49k|            if (!found) {
  ------------------
  |  Branch (463:17): [True: 1.48k, False: 1.01k]
  ------------------
  464|  1.48k|                snprintf(error_buf, sizeof(error_buf), "Failed to find %s", temp_key);
  465|  1.48k|                if (ctx->handle.error)
  ------------------
  |  Branch (465:21): [True: 0, False: 1.48k]
  ------------------
  466|      0|                    ctx->handle.error(error_buf, ctx->user_ctx);
  467|  1.48k|            } else {
  468|       |                // Handle the edge case where a ghost variable name (from a multi-segment
  469|       |                // variable) is identical to a real variable name. Normally we handle this
  470|       |                // by incrementing the loop variable by n_segments, but n_segments hasn't
  471|       |                // been set when this record is processed. So just set the longname to every
  472|       |                // matching variable, ghost or real.
  473|  1.01k|                varlookup_t *iter_match = found;
  474|  2.63k|                while (iter_match >= table && strcmp(iter_match->name, temp_key) == 0) {
  ------------------
  |  Branch (474:24): [True: 2.31k, False: 318]
  |  Branch (474:47): [True: 1.62k, False: 692]
  ------------------
  475|  1.62k|                    spss_varinfo_t *info = ctx->varinfo[iter_match->index];
  476|  1.62k|                    snprintf(info->longname, sizeof(info->longname), "%*s", (int)str_len, temp_val);
  477|  1.62k|                    iter_match--;
  478|  1.62k|                }
  479|  1.01k|                iter_match = found + 1;
  480|  2.50k|                while (iter_match - table < var_count && strcmp(iter_match->name, temp_key) == 0) {
  ------------------
  |  Branch (480:24): [True: 1.88k, False: 615]
  |  Branch (480:58): [True: 1.49k, False: 395]
  ------------------
  481|  1.49k|                    spss_varinfo_t *info = ctx->varinfo[iter_match->index];
  482|  1.49k|                    snprintf(info->longname, sizeof(info->longname), "%*s", (int)str_len, temp_val);
  483|  1.49k|                    iter_match++;
  484|  1.49k|                }
  485|  1.01k|            }
  486|  2.49k|        }
  487|  2.49k|	break;
  488|  2.49k|	case 4:
  ------------------
  |  Branch (488:2): [True: 2.49k, False: 4.98k]
  ------------------
  489|  2.49k|#line 129 "src/spss/readstat_sav_parse.rl"
  490|  2.49k|	{
  491|  2.49k|            memcpy(temp_val, str_start, str_len);
  492|  2.49k|            temp_val[str_len] = '\0';
  493|  2.49k|        }
  494|  2.49k|	break;
  495|  2.49k|	case 6:
  ------------------
  |  Branch (495:2): [True: 2.49k, False: 4.98k]
  ------------------
  496|  2.49k|#line 134 "src/spss/readstat_sav_parse.rl"
  497|  2.49k|	{ str_len = p - str_start; }
  498|  2.49k|	break;
  499|  7.48k|#line 500 "src/spss/readstat_sav_parse.c"
  500|  7.48k|		}
  501|  7.48k|	}
  502|  2.78k|	}
  503|       |
  504|  2.93k|	_out: {}
  505|  2.93k|	}
  506|       |
  507|      0|#line 142 "src/spss/readstat_sav_parse.rl"
  508|       |
  509|       |
  510|  2.93k|    if (cs < 11|| p != pe) {
  ------------------
  |  Branch (510:9): [True: 185, False: 2.75k]
  |  Branch (510:19): [True: 0, False: 2.75k]
  ------------------
  511|    185|        if (ctx->handle.error) {
  ------------------
  |  Branch (511:13): [True: 0, False: 185]
  ------------------
  512|      0|            snprintf(error_buf, sizeof(error_buf), "Error parsing string \"%.*s\" around byte #%ld/%d, character %c", 
  513|      0|                    count, (char *)data, (long)(p - c_data), count, *p);
  514|      0|            ctx->handle.error(error_buf, ctx->user_ctx);
  515|      0|        }
  516|    185|        retval = READSTAT_ERROR_PARSE;
  517|    185|    }
  518|       |    
  519|       |
  520|  2.93k|    if (table)
  ------------------
  |  Branch (520:9): [True: 2.40k, False: 533]
  ------------------
  521|  2.40k|        free(table);
  522|       |
  523|       |    /* suppress warning */
  524|  2.93k|    (void)sav_long_variable_parse_en_main;
  525|       |
  526|  2.93k|    return retval;
  527|  2.78k|}
sav_parse_very_long_string_record:
  612|  3.81k|readstat_error_t sav_parse_very_long_string_record(void *data, int count, sav_ctx_t *ctx) {
  613|  3.81k|    unsigned char *c_data = (unsigned char *)data;
  614|  3.81k|    int var_count = count_vars(ctx);
  615|  3.81k|    readstat_error_t retval = READSTAT_OK;
  616|       |
  617|  3.81k|    char temp_key[8*4+1];
  618|  3.81k|    unsigned int temp_val = 0;
  619|  3.81k|    unsigned char *str_start = NULL;
  620|  3.81k|    size_t str_len = 0;
  621|       |
  622|  3.81k|    size_t error_buf_len = 1024 + count;
  623|  3.81k|    char *error_buf = NULL;
  624|  3.81k|    unsigned char *p = c_data;
  625|  3.81k|    unsigned char *pe = c_data + count;
  626|  3.81k|    unsigned char *eof = pe;
  627|       |
  628|  3.81k|    varlookup_t *table = NULL;
  629|  3.81k|    int cs;
  630|       |
  631|  3.81k|    error_buf = readstat_malloc(error_buf_len);
  632|  3.81k|    table = build_lookup_table(var_count, ctx);
  633|       |    
  634|       |    
  635|  3.81k|#line 636 "src/spss/readstat_sav_parse.c"
  636|  3.81k|	{
  637|  3.81k|	cs = sav_very_long_string_parse_start;
  638|  3.81k|	}
  639|       |
  640|  3.81k|#line 641 "src/spss/readstat_sav_parse.c"
  641|  3.81k|	{
  642|  3.81k|	int _klen;
  643|  3.81k|	unsigned int _trans;
  644|  3.81k|	const char *_acts;
  645|  3.81k|	unsigned int _nacts;
  646|  3.81k|	const unsigned char *_keys;
  647|       |
  648|  3.81k|	if ( p == pe )
  ------------------
  |  Branch (648:7): [True: 0, False: 3.81k]
  ------------------
  649|      0|		goto _test_eof;
  650|  3.81k|	if ( cs == 0 )
  ------------------
  |  Branch (650:7): [True: 0, False: 3.81k]
  ------------------
  651|      0|		goto _out;
  652|  35.0k|_resume:
  653|  35.0k|	_keys = _sav_very_long_string_parse_trans_keys + _sav_very_long_string_parse_key_offsets[cs];
  654|  35.0k|	_trans = _sav_very_long_string_parse_index_offsets[cs];
  655|       |
  656|  35.0k|	_klen = _sav_very_long_string_parse_single_lengths[cs];
  657|  35.0k|	if ( _klen > 0 ) {
  ------------------
  |  Branch (657:7): [True: 29.4k, False: 5.63k]
  ------------------
  658|  29.4k|		const unsigned char *_lower = _keys;
  659|  29.4k|		const unsigned char *_mid;
  660|  29.4k|		const unsigned char *_upper = _keys + _klen - 1;
  661|  66.0k|		while (1) {
  ------------------
  |  Branch (661:10): [True: 66.0k, Folded]
  ------------------
  662|  66.0k|			if ( _upper < _lower )
  ------------------
  |  Branch (662:9): [True: 18.9k, False: 47.1k]
  ------------------
  663|  18.9k|				break;
  664|       |
  665|  47.1k|			_mid = _lower + ((_upper-_lower) >> 1);
  666|  47.1k|			if ( (*p) < *_mid )
  ------------------
  |  Branch (666:9): [True: 12.9k, False: 34.1k]
  ------------------
  667|  12.9k|				_upper = _mid - 1;
  668|  34.1k|			else if ( (*p) > *_mid )
  ------------------
  |  Branch (668:14): [True: 23.6k, False: 10.4k]
  ------------------
  669|  23.6k|				_lower = _mid + 1;
  670|  10.4k|			else {
  671|  10.4k|				_trans += (unsigned int)(_mid - _keys);
  672|  10.4k|				goto _match;
  673|  10.4k|			}
  674|  47.1k|		}
  675|  18.9k|		_keys += _klen;
  676|  18.9k|		_trans += _klen;
  677|  18.9k|	}
  678|       |
  679|  24.5k|	_klen = _sav_very_long_string_parse_range_lengths[cs];
  680|  24.5k|	if ( _klen > 0 ) {
  ------------------
  |  Branch (680:7): [True: 24.5k, False: 58]
  ------------------
  681|  24.5k|		const unsigned char *_lower = _keys;
  682|  24.5k|		const unsigned char *_mid;
  683|  24.5k|		const unsigned char *_upper = _keys + (_klen<<1) - 2;
  684|  54.9k|		while (1) {
  ------------------
  |  Branch (684:10): [True: 54.9k, Folded]
  ------------------
  685|  54.9k|			if ( _upper < _lower )
  ------------------
  |  Branch (685:9): [True: 12.8k, False: 42.0k]
  ------------------
  686|  12.8k|				break;
  687|       |
  688|  42.0k|			_mid = _lower + (((_upper-_lower) >> 1) & ~1);
  689|  42.0k|			if ( (*p) < _mid[0] )
  ------------------
  |  Branch (689:9): [True: 8.77k, False: 33.3k]
  ------------------
  690|  8.77k|				_upper = _mid - 2;
  691|  33.3k|			else if ( (*p) > _mid[1] )
  ------------------
  |  Branch (691:14): [True: 21.6k, False: 11.6k]
  ------------------
  692|  21.6k|				_lower = _mid + 2;
  693|  11.6k|			else {
  694|  11.6k|				_trans += (unsigned int)((_mid - _keys)>>1);
  695|  11.6k|				goto _match;
  696|  11.6k|			}
  697|  42.0k|		}
  698|  12.8k|		_trans += _klen;
  699|  12.8k|	}
  700|       |
  701|  35.0k|_match:
  702|  35.0k|	_trans = _sav_very_long_string_parse_indicies[_trans];
  703|  35.0k|	cs = _sav_very_long_string_parse_trans_targs[_trans];
  704|       |
  705|  35.0k|	if ( _sav_very_long_string_parse_trans_actions[_trans] == 0 )
  ------------------
  |  Branch (705:7): [True: 9.12k, False: 25.9k]
  ------------------
  706|  9.12k|		goto _again;
  707|       |
  708|  25.9k|	_acts = _sav_very_long_string_parse_actions + _sav_very_long_string_parse_trans_actions[_trans];
  709|  25.9k|	_nacts = (unsigned int) *_acts++;
  710|  62.9k|	while ( _nacts-- > 0 )
  ------------------
  |  Branch (710:10): [True: 37.2k, False: 25.7k]
  ------------------
  711|  37.2k|	{
  712|  37.2k|		switch ( *_acts++ )
  ------------------
  |  Branch (712:12): [True: 37.2k, False: 0]
  ------------------
  713|  37.2k|		{
  714|  5.64k|	case 0:
  ------------------
  |  Branch (714:2): [True: 5.64k, False: 31.5k]
  ------------------
  715|  5.64k|#line 13 "src/spss/readstat_sav_parse.rl"
  716|  5.64k|	{
  717|  5.64k|        memcpy(temp_key, str_start, str_len);
  718|  5.64k|        temp_key[str_len] = '\0';
  719|  5.64k|    }
  720|  5.64k|	break;
  721|  5.70k|	case 1:
  ------------------
  |  Branch (721:2): [True: 5.70k, False: 31.5k]
  ------------------
  722|  5.70k|#line 20 "src/spss/readstat_sav_parse.rl"
  723|  5.70k|	{ str_start = p; }
  724|  5.70k|	break;
  725|  5.64k|	case 2:
  ------------------
  |  Branch (725:2): [True: 5.64k, False: 31.5k]
  ------------------
  726|  5.64k|#line 20 "src/spss/readstat_sav_parse.rl"
  727|  5.64k|	{ str_len = p - str_start; }
  728|  5.64k|	break;
  729|  2.97k|	case 3:
  ------------------
  |  Branch (729:2): [True: 2.97k, False: 34.2k]
  ------------------
  730|  2.97k|#line 193 "src/spss/readstat_sav_parse.rl"
  731|  2.97k|	{
  732|  2.97k|            varlookup_t *found = bsearch(temp_key, table, var_count, sizeof(varlookup_t), &compare_key_varlookup);
  733|  2.97k|            if (found) {
  ------------------
  |  Branch (733:17): [True: 1.59k, False: 1.37k]
  ------------------
  734|       |                // See logic above; we need to apply this to all matching variables since ghost variable
  735|       |                // names may conflict with real variable names.
  736|  1.59k|                varlookup_t *first_match = found, *last_match = found;
  737|  1.59k|                varlookup_t *iter_match = found - 1;
  738|  7.79k|                while (iter_match >= table && strcmp(iter_match->name, temp_key) == 0) {
  ------------------
  |  Branch (738:24): [True: 7.24k, False: 546]
  |  Branch (738:47): [True: 6.19k, False: 1.05k]
  ------------------
  739|  6.19k|                    first_match = iter_match;
  740|  6.19k|                    iter_match--;
  741|  6.19k|                }
  742|  1.59k|                iter_match = found + 1;
  743|  6.61k|                while (iter_match - table < var_count && strcmp(iter_match->name, temp_key) == 0) {
  ------------------
  |  Branch (743:24): [True: 5.80k, False: 811]
  |  Branch (743:58): [True: 5.02k, False: 786]
  ------------------
  744|  5.02k|                    last_match = iter_match;
  745|  5.02k|                    iter_match++;
  746|  5.02k|                }
  747|  14.4k|                for (iter_match=first_match; iter_match<=last_match; iter_match++) {
  ------------------
  |  Branch (747:46): [True: 12.8k, False: 1.59k]
  ------------------
  748|  12.8k|                    ctx->varinfo[iter_match->index]->string_length = temp_val;
  749|  12.8k|                    ctx->varinfo[iter_match->index]->write_format.width = temp_val;
  750|  12.8k|                    ctx->varinfo[iter_match->index]->print_format.width = temp_val;
  751|  12.8k|                }
  752|  1.59k|            }
  753|  2.97k|        }
  754|  2.97k|	break;
  755|  11.6k|	case 4:
  ------------------
  |  Branch (755:2): [True: 11.6k, False: 25.5k]
  ------------------
  756|  11.6k|#line 217 "src/spss/readstat_sav_parse.rl"
  757|  11.6k|	{
  758|  11.6k|            if ((*p) != '\0') {
  ------------------
  |  Branch (758:17): [True: 11.6k, False: 0]
  ------------------
  759|  11.6k|                unsigned char digit = (*p) - '0';
  760|  11.6k|                if (temp_val <= (UINT_MAX - digit) / 10) {
  ------------------
  |  Branch (760:21): [True: 11.4k, False: 223]
  ------------------
  761|  11.4k|                    temp_val = 10 * temp_val + digit;
  762|  11.4k|                } else {
  763|    223|                    {p++; goto _out; }
  764|    223|                }
  765|  11.6k|            }
  766|  11.6k|        }
  767|  11.4k|	break;
  768|  11.4k|	case 5:
  ------------------
  |  Branch (768:2): [True: 5.63k, False: 31.5k]
  ------------------
  769|  5.63k|#line 228 "src/spss/readstat_sav_parse.rl"
  770|  5.63k|	{ temp_val = 0; }
  771|  5.63k|	break;
  772|  37.2k|#line 773 "src/spss/readstat_sav_parse.c"
  773|  37.2k|		}
  774|  37.2k|	}
  775|       |
  776|  34.8k|_again:
  777|  34.8k|	if ( cs == 0 )
  ------------------
  |  Branch (777:7): [True: 133, False: 34.7k]
  ------------------
  778|    133|		goto _out;
  779|  34.7k|	if ( ++p != pe )
  ------------------
  |  Branch (779:7): [True: 31.2k, False: 3.46k]
  ------------------
  780|  31.2k|		goto _resume;
  781|  3.46k|	_test_eof: {}
  782|  3.46k|	if ( p == eof )
  ------------------
  |  Branch (782:7): [True: 3.46k, False: 0]
  ------------------
  783|  3.46k|	{
  784|  3.46k|	const char *__acts = _sav_very_long_string_parse_actions + _sav_very_long_string_parse_eof_actions[cs];
  785|  3.46k|	unsigned int __nacts = (unsigned int) *__acts++;
  786|  5.89k|	while ( __nacts-- > 0 ) {
  ------------------
  |  Branch (786:10): [True: 2.43k, False: 3.46k]
  ------------------
  787|  2.43k|		switch ( *__acts++ ) {
  ------------------
  |  Branch (787:12): [True: 2.43k, False: 0]
  ------------------
  788|  2.43k|	case 3:
  ------------------
  |  Branch (788:2): [True: 2.43k, False: 0]
  ------------------
  789|  2.43k|#line 193 "src/spss/readstat_sav_parse.rl"
  790|  2.43k|	{
  791|  2.43k|            varlookup_t *found = bsearch(temp_key, table, var_count, sizeof(varlookup_t), &compare_key_varlookup);
  792|  2.43k|            if (found) {
  ------------------
  |  Branch (792:17): [True: 1.21k, False: 1.21k]
  ------------------
  793|       |                // See logic above; we need to apply this to all matching variables since ghost variable
  794|       |                // names may conflict with real variable names.
  795|  1.21k|                varlookup_t *first_match = found, *last_match = found;
  796|  1.21k|                varlookup_t *iter_match = found - 1;
  797|  3.89k|                while (iter_match >= table && strcmp(iter_match->name, temp_key) == 0) {
  ------------------
  |  Branch (797:24): [True: 3.43k, False: 459]
  |  Branch (797:47): [True: 2.68k, False: 752]
  ------------------
  798|  2.68k|                    first_match = iter_match;
  799|  2.68k|                    iter_match--;
  800|  2.68k|                }
  801|  1.21k|                iter_match = found + 1;
  802|  3.12k|                while (iter_match - table < var_count && strcmp(iter_match->name, temp_key) == 0) {
  ------------------
  |  Branch (802:24): [True: 2.58k, False: 546]
  |  Branch (802:58): [True: 1.91k, False: 665]
  ------------------
  803|  1.91k|                    last_match = iter_match;
  804|  1.91k|                    iter_match++;
  805|  1.91k|                }
  806|  7.01k|                for (iter_match=first_match; iter_match<=last_match; iter_match++) {
  ------------------
  |  Branch (806:46): [True: 5.80k, False: 1.21k]
  ------------------
  807|  5.80k|                    ctx->varinfo[iter_match->index]->string_length = temp_val;
  808|  5.80k|                    ctx->varinfo[iter_match->index]->write_format.width = temp_val;
  809|  5.80k|                    ctx->varinfo[iter_match->index]->print_format.width = temp_val;
  810|  5.80k|                }
  811|  1.21k|            }
  812|  2.43k|        }
  813|  2.43k|	break;
  814|  2.43k|#line 815 "src/spss/readstat_sav_parse.c"
  815|  2.43k|		}
  816|  2.43k|	}
  817|  3.46k|	}
  818|       |
  819|  3.81k|	_out: {}
  820|  3.81k|	}
  821|       |
  822|      0|#line 236 "src/spss/readstat_sav_parse.rl"
  823|       |
  824|       |    
  825|  3.81k|    if (cs < 11 || p != pe) {
  ------------------
  |  Branch (825:9): [True: 174, False: 3.64k]
  |  Branch (825:20): [True: 2, False: 3.64k]
  ------------------
  826|    176|        if (ctx->handle.error) {
  ------------------
  |  Branch (826:13): [True: 0, False: 176]
  ------------------
  827|      0|            snprintf(error_buf, error_buf_len, "Parsed %ld of %ld bytes. Remaining bytes: %.*s",
  828|      0|                    (long)(p - c_data), (long)(pe - c_data), (int)(pe - p), p);
  829|      0|            ctx->handle.error(error_buf, ctx->user_ctx);
  830|      0|        }
  831|    176|        retval = READSTAT_ERROR_PARSE;
  832|    176|    }
  833|       |    
  834|  3.81k|    if (table)
  ------------------
  |  Branch (834:9): [True: 3.18k, False: 636]
  ------------------
  835|  3.18k|        free(table);
  836|  3.81k|    if (error_buf)
  ------------------
  |  Branch (836:9): [True: 3.81k, False: 0]
  ------------------
  837|  3.81k|        free(error_buf);
  838|       |
  839|       |    /* suppress warning */
  840|  3.81k|    (void)sav_very_long_string_parse_en_main;
  841|       |
  842|  3.81k|    return retval;
  843|  3.46k|}
readstat_sav_parse.c:count_vars:
   33|  6.75k|static int count_vars(sav_ctx_t *ctx) {
   34|  6.75k|    int i;
   35|  6.75k|    spss_varinfo_t *last_info = NULL;
   36|  6.75k|    int var_count = 0;
   37|   596k|    for (i=0; i<ctx->var_index; i++) {
  ------------------
  |  Branch (37:15): [True: 589k, False: 6.75k]
  ------------------
   38|   589k|        spss_varinfo_t *info = ctx->varinfo[i];
   39|   589k|        if (last_info == NULL || strcmp(info->name, last_info->name) != 0) {
  ------------------
  |  Branch (39:13): [True: 5.58k, False: 583k]
  |  Branch (39:34): [True: 511k, False: 72.1k]
  ------------------
   40|   517k|            var_count++;
   41|   517k|        }
   42|   589k|        last_info = info;
   43|   589k|    }
   44|  6.75k|    return var_count;
   45|  6.75k|}
readstat_sav_parse.c:build_lookup_table:
   47|  6.75k|static varlookup_t *build_lookup_table(int var_count, sav_ctx_t *ctx) {
   48|  6.75k|    varlookup_t *table = readstat_malloc(var_count * sizeof(varlookup_t));
   49|  6.75k|    int offset = 0;
   50|  6.75k|    int i;
   51|  6.75k|    spss_varinfo_t *last_info = NULL;
   52|   596k|    for (i=0; i<ctx->var_index; i++) {
  ------------------
  |  Branch (52:15): [True: 589k, False: 6.75k]
  ------------------
   53|   589k|        spss_varinfo_t *info = ctx->varinfo[i];
   54|       |
   55|   589k|        if (last_info == NULL || strcmp(info->name, last_info->name) != 0) {
  ------------------
  |  Branch (55:13): [True: 5.58k, False: 583k]
  |  Branch (55:34): [True: 511k, False: 72.1k]
  ------------------
   56|   517k|            varlookup_t *entry = &table[offset++];
   57|       |
   58|   517k|            memcpy(entry->name, info->name, sizeof(info->name));
   59|   517k|            entry->index = info->index;
   60|   517k|        }
   61|   589k|        last_info = info;
   62|   589k|    }
   63|  6.75k|    qsort(table, var_count, sizeof(varlookup_t), &compare_varlookups);
   64|  6.75k|    return table;
   65|  6.75k|}
readstat_sav_parse.c:compare_varlookups:
   27|  4.40M|static int compare_varlookups(const void *elem1, const void *elem2) {
   28|  4.40M|    const varlookup_t *v1 = (const varlookup_t *)elem1;
   29|  4.40M|    const varlookup_t *v2 = (const varlookup_t *)elem2;
   30|  4.40M|    return strcasecmp(v1->name, v2->name);
   31|  4.40M|}
readstat_sav_parse.c:compare_key_varlookup:
   21|  21.7k|static int compare_key_varlookup(const void *elem1, const void *elem2) {
   22|  21.7k|    const char *key = (const char *)elem1;
   23|  21.7k|    const varlookup_t *v = (const varlookup_t *)elem2;
   24|  21.7k|    return strcasecmp(key, v->name);
   25|  21.7k|}

extract_mr_data:
   76|    668|readstat_error_t extract_mr_data(const char *line, mr_set_t *result, sav_ctx_t *ctx) {
   77|    668|    readstat_error_t retval = READSTAT_OK;
   78|       |
   79|       |    // Variables needed for Ragel operation
   80|    668|    int cs = 0;
   81|    668|    char *p = (char *)line;
   82|    668|    char *start = p;
   83|    668|    char *pe = p + strlen(p) + 1;
   84|       |
   85|       |    // Variables needed for passing Ragel intermediate results
   86|    668|    char mr_type = '\0';
   87|    668|    int mr_counted_value = -1;
   88|    668|    int mr_subvar_count = 0;
   89|    668|    char **mr_subvariables = NULL;
   90|    668|    char *mr_name = NULL;
   91|    668|    char *mr_label = NULL;
   92|       |
   93|       |    // Execute Ragel finite state machine (FSM)
   94|       |    
   95|    668|#line 89 "src/spss/readstat_sav_parse_mr_name.c"
   96|    668|	{
   97|    668|	cs = mr_extractor_start;
   98|    668|	}
   99|       |
  100|    668|#line 142 "src/spss/readstat_sav_parse_mr_name.rl"
  101|       |    
  102|    668|#line 92 "src/spss/readstat_sav_parse_mr_name.c"
  103|    668|	{
  104|    668|	int _klen;
  105|    668|	unsigned int _trans;
  106|    668|	const char *_acts;
  107|    668|	unsigned int _nacts;
  108|    668|	const char *_keys;
  109|       |
  110|    668|	if ( p == pe )
  ------------------
  |  Branch (110:7): [True: 0, False: 668]
  ------------------
  111|      0|		goto _test_eof;
  112|    668|	if ( cs == 0 )
  ------------------
  |  Branch (112:7): [True: 0, False: 668]
  ------------------
  113|      0|		goto _out;
  114|  25.6k|_resume:
  115|  25.6k|	_keys = _mr_extractor_trans_keys + _mr_extractor_key_offsets[cs];
  116|  25.6k|	_trans = _mr_extractor_index_offsets[cs];
  117|       |
  118|  25.6k|	_klen = _mr_extractor_single_lengths[cs];
  119|  25.6k|	if ( _klen > 0 ) {
  ------------------
  |  Branch (119:7): [True: 24.3k, False: 1.24k]
  ------------------
  120|  24.3k|		const char *_lower = _keys;
  121|  24.3k|		const char *_mid;
  122|  24.3k|		const char *_upper = _keys + _klen - 1;
  123|  65.8k|		while (1) {
  ------------------
  |  Branch (123:10): [True: 65.8k, Folded]
  ------------------
  124|  65.8k|			if ( _upper < _lower )
  ------------------
  |  Branch (124:9): [True: 20.8k, False: 45.0k]
  ------------------
  125|  20.8k|				break;
  126|       |
  127|  45.0k|			_mid = _lower + ((_upper-_lower) >> 1);
  128|  45.0k|			if ( (*p) < *_mid )
  ------------------
  |  Branch (128:9): [True: 11.0k, False: 33.9k]
  ------------------
  129|  11.0k|				_upper = _mid - 1;
  130|  33.9k|			else if ( (*p) > *_mid )
  ------------------
  |  Branch (130:14): [True: 30.4k, False: 3.58k]
  ------------------
  131|  30.4k|				_lower = _mid + 1;
  132|  3.58k|			else {
  133|  3.58k|				_trans += (unsigned int)(_mid - _keys);
  134|  3.58k|				goto _match;
  135|  3.58k|			}
  136|  45.0k|		}
  137|  20.8k|		_keys += _klen;
  138|  20.8k|		_trans += _klen;
  139|  20.8k|	}
  140|       |
  141|  22.0k|	_klen = _mr_extractor_range_lengths[cs];
  142|  22.0k|	if ( _klen > 0 ) {
  ------------------
  |  Branch (142:7): [True: 18.5k, False: 3.46k]
  ------------------
  143|  18.5k|		const char *_lower = _keys;
  144|  18.5k|		const char *_mid;
  145|  18.5k|		const char *_upper = _keys + (_klen<<1) - 2;
  146|  32.2k|		while (1) {
  ------------------
  |  Branch (146:10): [True: 32.2k, Folded]
  ------------------
  147|  32.2k|			if ( _upper < _lower )
  ------------------
  |  Branch (147:9): [True: 13.6k, False: 18.5k]
  ------------------
  148|  13.6k|				break;
  149|       |
  150|  18.5k|			_mid = _lower + (((_upper-_lower) >> 1) & ~1);
  151|  18.5k|			if ( (*p) < _mid[0] )
  ------------------
  |  Branch (151:9): [True: 2.78k, False: 15.8k]
  ------------------
  152|  2.78k|				_upper = _mid - 2;
  153|  15.8k|			else if ( (*p) > _mid[1] )
  ------------------
  |  Branch (153:14): [True: 10.8k, False: 4.94k]
  ------------------
  154|  10.8k|				_lower = _mid + 2;
  155|  4.94k|			else {
  156|  4.94k|				_trans += (unsigned int)((_mid - _keys)>>1);
  157|  4.94k|				goto _match;
  158|  4.94k|			}
  159|  18.5k|		}
  160|  13.6k|		_trans += _klen;
  161|  13.6k|	}
  162|       |
  163|  25.6k|_match:
  164|  25.6k|	_trans = _mr_extractor_indicies[_trans];
  165|  25.6k|	cs = _mr_extractor_trans_targs[_trans];
  166|       |
  167|  25.6k|	if ( _mr_extractor_trans_actions[_trans] == 0 )
  ------------------
  |  Branch (167:7): [True: 18.3k, False: 7.30k]
  ------------------
  168|  18.3k|		goto _again;
  169|       |
  170|  7.30k|	_acts = _mr_extractor_actions + _mr_extractor_trans_actions[_trans];
  171|  7.30k|	_nacts = (unsigned int) *_acts++;
  172|  14.5k|	while ( _nacts-- > 0 )
  ------------------
  |  Branch (172:10): [True: 7.30k, False: 7.27k]
  ------------------
  173|  7.30k|	{
  174|  7.30k|		switch ( *_acts++ )
  ------------------
  |  Branch (174:12): [True: 7.30k, False: 0]
  ------------------
  175|  7.30k|		{
  176|    638|	case 0:
  ------------------
  |  Branch (176:2): [True: 638, False: 6.66k]
  ------------------
  177|    638|#line 13 "src/spss/readstat_sav_parse_mr_name.rl"
  178|    638|	{
  179|    638|        size_t src_len = p - start;
  180|    638|        size_t dst_len = 4 * src_len + 1;  // UTF-8 expansion: up to 4 bytes per char
  181|    638|        mr_name = (char *)readstat_malloc(dst_len);
  182|    638|        if (mr_name == NULL) {
  ------------------
  |  Branch (182:13): [True: 0, False: 638]
  ------------------
  183|      0|            retval = READSTAT_ERROR_MALLOC;
  184|      0|            goto cleanup;
  185|      0|        }
  186|    638|        retval = readstat_convert(mr_name, dst_len, start, src_len, ctx->converter);
  187|    638|        if (retval != READSTAT_OK) {
  ------------------
  |  Branch (187:13): [True: 1, False: 637]
  ------------------
  188|      1|            goto cleanup;
  189|      1|        }
  190|    638|    }
  191|    637|	break;
  192|    637|	case 1:
  ------------------
  |  Branch (192:2): [True: 629, False: 6.67k]
  ------------------
  193|    629|#line 27 "src/spss/readstat_sav_parse_mr_name.rl"
  194|    629|	{
  195|    629|        mr_type = *p;
  196|    629|        start = p + 1;
  197|    629|    }
  198|    629|	break;
  199|    626|	case 2:
  ------------------
  |  Branch (199:2): [True: 626, False: 6.67k]
  ------------------
  200|    626|#line 32 "src/spss/readstat_sav_parse_mr_name.rl"
  201|    626|	{
  202|    626|        int n_cv_digs = p - start;
  203|    626|        char *n_dig_str = (char *)readstat_malloc(n_cv_digs + 1);
  204|    626|        if (n_dig_str == NULL) {
  ------------------
  |  Branch (204:13): [True: 0, False: 626]
  ------------------
  205|      0|            retval = READSTAT_ERROR_MALLOC;
  206|      0|            goto cleanup;
  207|      0|        }
  208|    626|        memcpy(n_dig_str, start, n_cv_digs);
  209|    626|        n_dig_str[n_cv_digs] = '\0';
  210|    626|        int n_digs = strtol(n_dig_str, NULL, 10);
  211|    626|        free(n_dig_str);
  212|    626|        if (n_digs != 0) {
  ------------------
  |  Branch (212:13): [True: 62, False: 564]
  ------------------
  213|     62|            char *cv = (char *)readstat_malloc(n_digs + 1);
  214|     62|            if (cv == NULL) {
  ------------------
  |  Branch (214:17): [True: 18, False: 44]
  ------------------
  215|     18|                retval = READSTAT_ERROR_MALLOC;
  216|     18|                goto cleanup;
  217|     18|            }
  218|     44|            memcpy(cv, p + 1, n_digs);
  219|     44|            cv[n_digs] = '\0';
  220|     44|            mr_counted_value = strtol(cv, NULL, 10);
  221|     44|            free(cv);
  222|     44|            p = p + 1 + n_digs;
  223|     44|            start = p + 1;
  224|     44|        }
  225|    564|        else {
  226|    564|            mr_counted_value = -1;
  227|    564|        }
  228|    626|    }
  229|    608|	break;
  230|    608|	case 3:
  ------------------
  |  Branch (230:2): [True: 595, False: 6.70k]
  ------------------
  231|    595|#line 61 "src/spss/readstat_sav_parse_mr_name.rl"
  232|    595|	{
  233|    595|        char *lbl_len_str = (char *)readstat_malloc(p - start + 1);
  234|    595|        if (lbl_len_str == NULL) {
  ------------------
  |  Branch (234:13): [True: 0, False: 595]
  ------------------
  235|      0|            retval = READSTAT_ERROR_MALLOC;
  236|      0|            goto cleanup;
  237|      0|        }
  238|    595|        memcpy(lbl_len_str, start, p - start);
  239|    595|        lbl_len_str[p - start] = '\0';
  240|    595|        int len = strtol(lbl_len_str, NULL, 10);
  241|    595|        free(lbl_len_str);
  242|    595|        size_t dst_len = 4 * len + 1;  // UTF-8 expansion: up to 4 bytes per char
  243|    595|        mr_label = (char *)readstat_malloc(dst_len);
  244|    595|        if (mr_label == NULL) {
  ------------------
  |  Branch (244:13): [True: 7, False: 588]
  ------------------
  245|      7|            retval = READSTAT_ERROR_MALLOC;
  246|      7|            goto cleanup;
  247|      7|        }
  248|    588|        retval = readstat_convert(mr_label, dst_len, p + 1, len, ctx->converter);
  249|    588|        if (retval != READSTAT_OK) {
  ------------------
  |  Branch (249:13): [True: 1, False: 587]
  ------------------
  250|      1|            goto cleanup;
  251|      1|        }
  252|    587|        p = p + 1 + len;
  253|    587|        start = p + 1;
  254|    587|    }
  255|      0|	break;
  256|  4.81k|	case 4:
  ------------------
  |  Branch (256:2): [True: 4.81k, False: 2.48k]
  ------------------
  257|  4.81k|#line 85 "src/spss/readstat_sav_parse_mr_name.rl"
  258|  4.81k|	{
  259|  4.81k|        size_t src_len = p - start;
  260|  4.81k|        size_t dst_len = 4 * src_len + 1;  // UTF-8 expansion: up to 4 bytes per char
  261|  4.81k|        char *subvar = (char *)readstat_malloc(dst_len);
  262|  4.81k|        if (subvar == NULL) {
  ------------------
  |  Branch (262:13): [True: 0, False: 4.81k]
  ------------------
  263|      0|            retval = READSTAT_ERROR_MALLOC;
  264|      0|            goto cleanup;
  265|      0|        }
  266|  4.81k|        retval = readstat_convert(subvar, dst_len, start, src_len, ctx->converter);
  267|  4.81k|        if (retval != READSTAT_OK) {
  ------------------
  |  Branch (267:13): [True: 1, False: 4.81k]
  ------------------
  268|      1|            free(subvar);
  269|      1|            goto cleanup;
  270|      1|        }
  271|  4.81k|        start = p + 1;
  272|  4.81k|        char **new_subvariables = readstat_realloc(mr_subvariables, sizeof(char *) * (mr_subvar_count + 1));
  273|  4.81k|        if (new_subvariables == NULL) {
  ------------------
  |  Branch (273:13): [True: 0, False: 4.81k]
  ------------------
  274|      0|            free(subvar);
  275|      0|            retval = READSTAT_ERROR_MALLOC;
  276|      0|            goto cleanup;
  277|      0|        }
  278|  4.81k|        mr_subvariables = new_subvariables;
  279|  4.81k|        mr_subvariables[mr_subvar_count++] = subvar;
  280|  4.81k|    }
  281|      0|	break;
  282|  7.30k|#line 266 "src/spss/readstat_sav_parse_mr_name.c"
  283|  7.30k|		}
  284|  7.30k|	}
  285|       |
  286|  25.6k|_again:
  287|  25.6k|	if ( cs == 0 )
  ------------------
  |  Branch (287:7): [True: 44, False: 25.5k]
  ------------------
  288|     44|		goto _out;
  289|  25.5k|	if ( ++p != pe )
  ------------------
  |  Branch (289:7): [True: 24.9k, False: 596]
  ------------------
  290|  24.9k|		goto _resume;
  291|    596|	_test_eof: {}
  292|    640|	_out: {}
  293|    640|	}
  294|       |
  295|      0|#line 143 "src/spss/readstat_sav_parse_mr_name.rl"
  296|       |
  297|       |    // Check if FSM finished successfully
  298|    640|    if (cs < 8 || p != pe) {
  ------------------
  |  Branch (298:9): [True: 73, False: 567]
  |  Branch (298:19): [True: 0, False: 567]
  ------------------
  299|     73|        retval = READSTAT_ERROR_BAD_MR_STRING;
  300|     73|        goto cleanup;
  301|     73|    }
  302|       |
  303|    567|    (void)mr_extractor_en_main;
  304|       |
  305|       |    // Assign parsed values to output parameter
  306|    567|    result->name = mr_name;
  307|    567|    result->label = mr_label;
  308|    567|    result->type = mr_type;
  309|    567|    result->counted_value = mr_counted_value;
  310|    567|    result->subvariables = mr_subvariables;
  311|    567|    result->num_subvars = mr_subvar_count;
  312|    567|    if (result->type == 'D') {
  ------------------
  |  Branch (312:9): [True: 387, False: 180]
  ------------------
  313|    387|        result->is_dichotomy = 1;
  314|    387|    }
  315|       |
  316|    668|cleanup:
  317|    668|    if (retval != READSTAT_OK) {
  ------------------
  |  Branch (317:9): [True: 101, False: 567]
  ------------------
  318|    101|        if (mr_subvariables != NULL) {
  ------------------
  |  Branch (318:13): [True: 19, False: 82]
  ------------------
  319|  1.14k|            for (int i = 0; i < mr_subvar_count; i++) {
  ------------------
  |  Branch (319:29): [True: 1.12k, False: 19]
  ------------------
  320|  1.12k|                if (mr_subvariables[i] != NULL) free(mr_subvariables[i]);
  ------------------
  |  Branch (320:21): [True: 1.12k, False: 0]
  ------------------
  321|  1.12k|            }
  322|     19|            free(mr_subvariables);
  323|     19|        }
  324|    101|        if (mr_name != NULL) free(mr_name);
  ------------------
  |  Branch (324:13): [True: 71, False: 30]
  ------------------
  325|    101|        if (mr_label != NULL) free(mr_label);
  ------------------
  |  Branch (325:13): [True: 21, False: 80]
  ------------------
  326|    101|    }
  327|    668|    return retval;
  328|    567|}
parse_mr_line:
  331|    668|readstat_error_t parse_mr_line(const char *line, mr_set_t *result, sav_ctx_t *ctx) {
  332|    668|    *result = (mr_set_t){0};
  333|    668|    return extract_mr_data(line, result, ctx);
  334|    668|}
parse_mr_string:
  383|    227|readstat_error_t parse_mr_string(const char *line, mr_set_t **mr_sets, size_t *n_mr_lines, sav_ctx_t *ctx) {
  384|    227|    readstat_error_t retval = READSTAT_OK;
  385|    227|    int cs = 0;
  386|    227|    char *p = (char *)line;
  387|    227|    char *start = p;
  388|    227|    char *pe = p + strlen(p) + 1;
  389|    227|    *mr_sets = NULL;
  390|    227|    *n_mr_lines = 0;
  391|       |
  392|       |    
  393|    227|#line 369 "src/spss/readstat_sav_parse_mr_name.c"
  394|    227|	{
  395|    227|	cs = mr_parser_start;
  396|    227|	}
  397|       |
  398|    227|#line 228 "src/spss/readstat_sav_parse_mr_name.rl"
  399|       |    
  400|    227|#line 372 "src/spss/readstat_sav_parse_mr_name.c"
  401|    227|	{
  402|    227|	int _klen;
  403|    227|	unsigned int _trans;
  404|    227|	const char *_acts;
  405|    227|	unsigned int _nacts;
  406|    227|	const char *_keys;
  407|       |
  408|    227|	if ( p == pe )
  ------------------
  |  Branch (408:7): [True: 0, False: 227]
  ------------------
  409|      0|		goto _test_eof;
  410|    227|	if ( cs == 0 )
  ------------------
  |  Branch (410:7): [True: 0, False: 227]
  ------------------
  411|      0|		goto _out;
  412|  29.4k|_resume:
  413|  29.4k|	_keys = _mr_parser_trans_keys + _mr_parser_key_offsets[cs];
  414|  29.4k|	_trans = _mr_parser_index_offsets[cs];
  415|       |
  416|  29.4k|	_klen = _mr_parser_single_lengths[cs];
  417|  29.4k|	if ( _klen > 0 ) {
  ------------------
  |  Branch (417:7): [True: 29.4k, False: 0]
  ------------------
  418|  29.4k|		const char *_lower = _keys;
  419|  29.4k|		const char *_mid;
  420|  29.4k|		const char *_upper = _keys + _klen - 1;
  421|  58.4k|		while (1) {
  ------------------
  |  Branch (421:10): [True: 58.4k, Folded]
  ------------------
  422|  58.4k|			if ( _upper < _lower )
  ------------------
  |  Branch (422:9): [True: 28.4k, False: 29.9k]
  ------------------
  423|  28.4k|				break;
  424|       |
  425|  29.9k|			_mid = _lower + ((_upper-_lower) >> 1);
  426|  29.9k|			if ( (*p) < *_mid )
  ------------------
  |  Branch (426:9): [True: 4.42k, False: 25.5k]
  ------------------
  427|  4.42k|				_upper = _mid - 1;
  428|  25.5k|			else if ( (*p) > *_mid )
  ------------------
  |  Branch (428:14): [True: 24.5k, False: 989]
  ------------------
  429|  24.5k|				_lower = _mid + 1;
  430|    989|			else {
  431|    989|				_trans += (unsigned int)(_mid - _keys);
  432|    989|				goto _match;
  433|    989|			}
  434|  29.9k|		}
  435|  28.4k|		_keys += _klen;
  436|  28.4k|		_trans += _klen;
  437|  28.4k|	}
  438|       |
  439|  28.4k|	_klen = _mr_parser_range_lengths[cs];
  440|  28.4k|	if ( _klen > 0 ) {
  ------------------
  |  Branch (440:7): [True: 0, False: 28.4k]
  ------------------
  441|      0|		const char *_lower = _keys;
  442|      0|		const char *_mid;
  443|      0|		const char *_upper = _keys + (_klen<<1) - 2;
  444|      0|		while (1) {
  ------------------
  |  Branch (444:10): [True: 0, Folded]
  ------------------
  445|      0|			if ( _upper < _lower )
  ------------------
  |  Branch (445:9): [True: 0, False: 0]
  ------------------
  446|      0|				break;
  447|       |
  448|      0|			_mid = _lower + (((_upper-_lower) >> 1) & ~1);
  449|      0|			if ( (*p) < _mid[0] )
  ------------------
  |  Branch (449:9): [True: 0, False: 0]
  ------------------
  450|      0|				_upper = _mid - 2;
  451|      0|			else if ( (*p) > _mid[1] )
  ------------------
  |  Branch (451:14): [True: 0, False: 0]
  ------------------
  452|      0|				_lower = _mid + 2;
  453|      0|			else {
  454|      0|				_trans += (unsigned int)((_mid - _keys)>>1);
  455|      0|				goto _match;
  456|      0|			}
  457|      0|		}
  458|      0|		_trans += _klen;
  459|      0|	}
  460|       |
  461|  29.4k|_match:
  462|  29.4k|	_trans = _mr_parser_indicies[_trans];
  463|  29.4k|	cs = _mr_parser_trans_targs[_trans];
  464|       |
  465|  29.4k|	if ( _mr_parser_trans_actions[_trans] == 0 )
  ------------------
  |  Branch (465:7): [True: 28.7k, False: 671]
  ------------------
  466|  28.7k|		goto _again;
  467|       |
  468|    671|	_acts = _mr_parser_actions + _mr_parser_trans_actions[_trans];
  469|    671|	_nacts = (unsigned int) *_acts++;
  470|  1.23k|	while ( _nacts-- > 0 )
  ------------------
  |  Branch (470:10): [True: 671, False: 567]
  ------------------
  471|    671|	{
  472|    671|		switch ( *_acts++ )
  ------------------
  |  Branch (472:12): [True: 671, False: 0]
  ------------------
  473|    671|		{
  474|    671|	case 0:
  ------------------
  |  Branch (474:2): [True: 671, False: 0]
  ------------------
  475|    671|#line 186 "src/spss/readstat_sav_parse_mr_name.rl"
  476|    671|	{
  477|    671|        char *mln = (char *)readstat_malloc(p - start);
  478|    671|        if (mln == NULL) {
  ------------------
  |  Branch (478:13): [True: 3, False: 668]
  ------------------
  479|      3|            retval = READSTAT_ERROR_MALLOC;
  480|      3|            goto cleanup;
  481|      3|        }
  482|    668|        memcpy(mln, start + 1, p - start);
  483|    668|        mln[p - start - 1] = '\0';
  484|    668|        mr_set_t *new_mr_sets = readstat_realloc(*mr_sets, ((*n_mr_lines) + 1) * sizeof(mr_set_t));
  485|    668|        if (new_mr_sets == NULL) {
  ------------------
  |  Branch (485:13): [True: 0, False: 668]
  ------------------
  486|      0|            free(mln);
  487|      0|            retval = READSTAT_ERROR_MALLOC;
  488|      0|            goto cleanup;
  489|      0|        }
  490|    668|        *mr_sets = new_mr_sets;
  491|    668|        retval = parse_mr_line(mln, &(*mr_sets)[*n_mr_lines], ctx);
  492|    668|        free(mln);
  493|    668|        if (retval != READSTAT_OK) {
  ------------------
  |  Branch (493:13): [True: 101, False: 567]
  ------------------
  494|    101|            goto cleanup;
  495|    101|        }
  496|    567|        (*n_mr_lines)++;
  497|    567|        start = p + 1;
  498|    567|    }
  499|      0|	break;
  500|    671|#line 470 "src/spss/readstat_sav_parse_mr_name.c"
  501|    671|		}
  502|    671|	}
  503|       |
  504|  29.3k|_again:
  505|  29.3k|	if ( cs == 0 )
  ------------------
  |  Branch (505:7): [True: 0, False: 29.3k]
  ------------------
  506|      0|		goto _out;
  507|  29.3k|	if ( ++p != pe )
  ------------------
  |  Branch (507:7): [True: 29.2k, False: 123]
  ------------------
  508|  29.2k|		goto _resume;
  509|    123|	_test_eof: {}
  510|    123|	_out: {}
  511|    123|	}
  512|       |
  513|      0|#line 229 "src/spss/readstat_sav_parse_mr_name.rl"
  514|       |
  515|    123|    if (cs < 4 || p != pe) {
  ------------------
  |  Branch (515:9): [True: 32, False: 91]
  |  Branch (515:19): [True: 0, False: 91]
  ------------------
  516|     32|        retval = READSTAT_ERROR_BAD_MR_STRING;
  517|     32|        goto cleanup;
  518|     32|    }
  519|       |
  520|     91|    (void)mr_parser_en_main;
  521|       |
  522|    227|cleanup:
  523|    227|    return retval;
  524|     91|}

sav_parse_time:
   73|  5.15k|readstat_error_handler error_cb, void *user_ctx) {
   74|  5.15k|	readstat_error_t retval = READSTAT_OK;
   75|  5.15k|	char error_buf[8192];
   76|  5.15k|	const char *p = data;
   77|  5.15k|	const char *pe = p + len;
   78|  5.15k|	const char *eof = pe;
   79|  5.15k|	int cs;
   80|  5.15k|	int temp_val = 0;
   81|       |	
   82|  5.15k|#line 83 "src/spss/readstat_sav_parse_timestamp.c"
   83|  5.15k|	{
   84|  5.15k|		cs = (int)sav_time_parse_start;
   85|  5.15k|	}
   86|       |	
   87|  5.15k|#line 88 "src/spss/readstat_sav_parse_timestamp.c"
   88|  5.15k|	{
   89|  5.15k|		int _klen;
   90|  5.15k|		unsigned int _trans = 0;
   91|  5.15k|		const char * _keys;
   92|  5.15k|		const signed char * _acts;
   93|  5.15k|		unsigned int _nacts;
   94|  12.4k|		_resume: {}
   95|  12.4k|		if ( p == pe && p != eof )
  ------------------
  |  Branch (95:8): [True: 693, False: 11.7k]
  |  Branch (95:19): [True: 0, False: 693]
  ------------------
   96|      0|			goto _out;
   97|  12.4k|		if ( p == eof ) {
  ------------------
  |  Branch (97:8): [True: 693, False: 11.7k]
  ------------------
   98|    693|			if ( _sav_time_parse_eof_trans[cs] > 0 ) {
  ------------------
  |  Branch (98:9): [True: 693, False: 0]
  ------------------
   99|    693|				_trans = (unsigned int)_sav_time_parse_eof_trans[cs] - 1;
  100|    693|			}
  101|    693|		}
  102|  11.7k|		else {
  103|  11.7k|			_keys = ( _sav_time_parse_trans_keys + (_sav_time_parse_key_offsets[cs]));
  104|  11.7k|			_trans = (unsigned int)_sav_time_parse_index_offsets[cs];
  105|       |			
  106|  11.7k|			_klen = (int)_sav_time_parse_single_lengths[cs];
  107|  11.7k|			if ( _klen > 0 ) {
  ------------------
  |  Branch (107:9): [True: 8.73k, False: 3.04k]
  ------------------
  108|  8.73k|				const char *_lower = _keys;
  109|  8.73k|				const char *_upper = _keys + _klen - 1;
  110|  8.73k|				const char *_mid;
  111|  15.4k|				while ( 1 ) {
  ------------------
  |  Branch (111:13): [True: 15.4k, Folded]
  ------------------
  112|  15.4k|					if ( _upper < _lower ) {
  ------------------
  |  Branch (112:11): [True: 6.74k, False: 8.73k]
  ------------------
  113|  6.74k|						_keys += _klen;
  114|  6.74k|						_trans += (unsigned int)_klen;
  115|  6.74k|						break;
  116|  6.74k|					}
  117|       |					
  118|  8.73k|					_mid = _lower + ((_upper-_lower) >> 1);
  119|  8.73k|					if ( ( (*( p))) < (*( _mid)) )
  ------------------
  |  Branch (119:11): [True: 3.14k, False: 5.58k]
  ------------------
  120|  3.14k|						_upper = _mid - 1;
  121|  5.58k|					else if ( ( (*( p))) > (*( _mid)) )
  ------------------
  |  Branch (121:16): [True: 3.59k, False: 1.98k]
  ------------------
  122|  3.59k|						_lower = _mid + 1;
  123|  1.98k|					else {
  124|  1.98k|						_trans += (unsigned int)(_mid - _keys);
  125|  1.98k|						goto _match;
  126|  1.98k|					}
  127|  8.73k|				}
  128|  8.73k|			}
  129|       |			
  130|  9.79k|			_klen = (int)_sav_time_parse_range_lengths[cs];
  131|  9.79k|			if ( _klen > 0 ) {
  ------------------
  |  Branch (131:9): [True: 9.59k, False: 197]
  ------------------
  132|  9.59k|				const char *_lower = _keys;
  133|  9.59k|				const char *_upper = _keys + (_klen<<1) - 2;
  134|  9.59k|				const char *_mid;
  135|  13.8k|				while ( 1 ) {
  ------------------
  |  Branch (135:13): [True: 13.8k, Folded]
  ------------------
  136|  13.8k|					if ( _upper < _lower ) {
  ------------------
  |  Branch (136:11): [True: 4.26k, False: 9.59k]
  ------------------
  137|  4.26k|						_trans += (unsigned int)_klen;
  138|  4.26k|						break;
  139|  4.26k|					}
  140|       |					
  141|  9.59k|					_mid = _lower + (((_upper-_lower) >> 1) & ~1);
  142|  9.59k|					if ( ( (*( p))) < (*( _mid)) )
  ------------------
  |  Branch (142:11): [True: 3.65k, False: 5.94k]
  ------------------
  143|  3.65k|						_upper = _mid - 2;
  144|  5.94k|					else if ( ( (*( p))) > (*( _mid + 1)) )
  ------------------
  |  Branch (144:16): [True: 612, False: 5.32k]
  ------------------
  145|    612|						_lower = _mid + 2;
  146|  5.32k|					else {
  147|  5.32k|						_trans += (unsigned int)((_mid - _keys)>>1);
  148|  5.32k|						break;
  149|  5.32k|					}
  150|  9.59k|				}
  151|  9.59k|			}
  152|       |			
  153|  11.7k|			_match: {}
  154|  11.7k|		}
  155|  12.4k|		cs = (int)_sav_time_parse_cond_targs[_trans];
  156|       |		
  157|  12.4k|		if ( _sav_time_parse_cond_actions[_trans] != 0 ) {
  ------------------
  |  Branch (157:8): [True: 7.71k, False: 4.75k]
  ------------------
  158|       |			
  159|  7.71k|			_acts = ( _sav_time_parse_actions + (_sav_time_parse_cond_actions[_trans]));
  160|  7.71k|			_nacts = (unsigned int)(*( _acts));
  161|  7.71k|			_acts += 1;
  162|  15.4k|			while ( _nacts > 0 ) {
  ------------------
  |  Branch (162:12): [True: 7.76k, False: 7.71k]
  ------------------
  163|  7.76k|				switch ( (*( _acts)) )
  ------------------
  |  Branch (163:14): [True: 7.76k, False: 0]
  ------------------
  164|  7.76k|				{
  165|  2.57k|					case 0:  {
  ------------------
  |  Branch (165:6): [True: 2.57k, False: 5.18k]
  ------------------
  166|  2.57k|						{
  167|  2.57k|#line 24 "src/spss/readstat_sav_parse_timestamp.rl"
  168|       |							
  169|  2.57k|							temp_val = 10 * temp_val + ((( (*( p)))) - '0');
  170|  2.57k|						}
  171|       |						
  172|  2.57k|#line 173 "src/spss/readstat_sav_parse_timestamp.c"
  173|       |						
  174|  2.57k|						break; 
  175|      0|					}
  176|     54|					case 1:  {
  ------------------
  |  Branch (176:6): [True: 54, False: 7.71k]
  ------------------
  177|     54|						{
  178|     54|#line 28 "src/spss/readstat_sav_parse_timestamp.rl"
  179|     54|							temp_val = 0; }
  180|       |						
  181|     54|#line 182 "src/spss/readstat_sav_parse_timestamp.c"
  182|       |						
  183|     54|						break; 
  184|      0|					}
  185|  2.74k|					case 2:  {
  ------------------
  |  Branch (185:6): [True: 2.74k, False: 5.01k]
  ------------------
  186|  2.74k|						{
  187|  2.74k|#line 28 "src/spss/readstat_sav_parse_timestamp.rl"
  188|  2.74k|							temp_val = (( (*( p)))) - '0'; }
  189|       |						
  190|  2.74k|#line 191 "src/spss/readstat_sav_parse_timestamp.c"
  191|       |						
  192|  2.74k|						break; 
  193|      0|					}
  194|    919|					case 3:  {
  ------------------
  |  Branch (194:6): [True: 919, False: 6.84k]
  ------------------
  195|    919|						{
  196|    919|#line 30 "src/spss/readstat_sav_parse_timestamp.rl"
  197|    919|							timestamp->tm_hour = temp_val; }
  198|       |						
  199|    919|#line 200 "src/spss/readstat_sav_parse_timestamp.c"
  200|       |						
  201|    919|						break; 
  202|      0|					}
  203|    770|					case 4:  {
  ------------------
  |  Branch (203:6): [True: 770, False: 6.99k]
  ------------------
  204|    770|						{
  205|    770|#line 32 "src/spss/readstat_sav_parse_timestamp.rl"
  206|    770|							timestamp->tm_min = temp_val; }
  207|       |						
  208|    770|#line 209 "src/spss/readstat_sav_parse_timestamp.c"
  209|       |						
  210|    770|						break; 
  211|      0|					}
  212|    693|					case 5:  {
  ------------------
  |  Branch (212:6): [True: 693, False: 7.07k]
  ------------------
  213|    693|						{
  214|    693|#line 34 "src/spss/readstat_sav_parse_timestamp.rl"
  215|    693|							timestamp->tm_sec = temp_val; }
  216|       |						
  217|    693|#line 218 "src/spss/readstat_sav_parse_timestamp.c"
  218|       |						
  219|    693|						break; 
  220|      0|					}
  221|  7.76k|				}
  222|  7.76k|				_nacts -= 1;
  223|  7.76k|				_acts += 1;
  224|  7.76k|			}
  225|       |			
  226|  7.71k|		}
  227|       |		
  228|  12.4k|		if ( p == eof ) {
  ------------------
  |  Branch (228:8): [True: 693, False: 11.7k]
  ------------------
  229|    693|			if ( cs >= 12 )
  ------------------
  |  Branch (229:9): [True: 693, False: 0]
  ------------------
  230|    693|				goto _out;
  231|    693|		}
  232|  11.7k|		else {
  233|  11.7k|			if ( cs != 0 ) {
  ------------------
  |  Branch (233:9): [True: 7.31k, False: 4.46k]
  ------------------
  234|  7.31k|				p += 1;
  235|  7.31k|				goto _resume;
  236|  7.31k|			}
  237|  11.7k|		}
  238|  5.15k|		_out: {}
  239|  5.15k|	}
  240|       |	
  241|      0|#line 40 "src/spss/readstat_sav_parse_timestamp.rl"
  242|       |	
  243|       |	
  244|  5.15k|	if (cs < 
  ------------------
  |  Branch (244:6): [True: 4.46k, False: 693]
  ------------------
  245|  5.15k|#line 246 "src/spss/readstat_sav_parse_timestamp.c"
  246|  5.15k|	12
  247|    693|#line 42 "src/spss/readstat_sav_parse_timestamp.rl"
  248|  4.46k|	|| p != pe) {
  ------------------
  |  Branch (248:5): [True: 0, False: 693]
  ------------------
  249|  4.46k|		if (error_cb) {
  ------------------
  |  Branch (249:7): [True: 0, False: 4.46k]
  ------------------
  250|      0|			snprintf(error_buf, sizeof(error_buf),
  251|      0|			"Invalid time string (length=%d): %.*s", (int)len, (int)len, data);
  252|      0|			error_cb(error_buf, user_ctx);
  253|      0|		}
  254|  4.46k|		retval = READSTAT_ERROR_BAD_TIMESTAMP_STRING;
  255|  4.46k|	}
  256|       |	
  257|  5.15k|	(void)sav_time_parse_en_main;
  258|       |	
  259|  5.15k|	return retval;
  260|  12.4k|}
sav_parse_date:
  398|    693|readstat_error_handler error_cb, void *user_ctx) {
  399|    693|	readstat_error_t retval = READSTAT_OK;
  400|    693|	char error_buf[8192];
  401|    693|	const char *p = data;
  402|    693|	const char *pe = p + len;
  403|    693|	const char *eof = pe;
  404|    693|	int cs;
  405|    693|	int temp_val = 0;
  406|       |	
  407|    693|#line 408 "src/spss/readstat_sav_parse_timestamp.c"
  408|    693|	{
  409|    693|		cs = (int)sav_date_parse_start;
  410|    693|	}
  411|       |	
  412|    693|#line 413 "src/spss/readstat_sav_parse_timestamp.c"
  413|    693|	{
  414|    693|		int _klen;
  415|    693|		unsigned int _trans = 0;
  416|    693|		const char * _keys;
  417|    693|		const signed char * _acts;
  418|    693|		unsigned int _nacts;
  419|  5.14k|		_resume: {}
  420|  5.14k|		if ( p == pe && p != eof )
  ------------------
  |  Branch (420:8): [True: 437, False: 4.70k]
  |  Branch (420:19): [True: 0, False: 437]
  ------------------
  421|      0|			goto _out;
  422|  5.14k|		if ( p == eof ) {
  ------------------
  |  Branch (422:8): [True: 437, False: 4.70k]
  ------------------
  423|    437|			if ( _sav_date_parse_eof_trans[cs] > 0 ) {
  ------------------
  |  Branch (423:9): [True: 437, False: 0]
  ------------------
  424|    437|				_trans = (unsigned int)_sav_date_parse_eof_trans[cs] - 1;
  425|    437|			}
  426|    437|		}
  427|  4.70k|		else {
  428|  4.70k|			_keys = ( _sav_date_parse_trans_keys + (_sav_date_parse_key_offsets[cs]));
  429|  4.70k|			_trans = (unsigned int)_sav_date_parse_index_offsets[cs];
  430|       |			
  431|  4.70k|			_klen = (int)_sav_date_parse_single_lengths[cs];
  432|  4.70k|			if ( _klen > 0 ) {
  ------------------
  |  Branch (432:9): [True: 4.70k, False: 0]
  ------------------
  433|  4.70k|				const char *_lower = _keys;
  434|  4.70k|				const char *_upper = _keys + _klen - 1;
  435|  4.70k|				const char *_mid;
  436|  7.97k|				while ( 1 ) {
  ------------------
  |  Branch (436:13): [True: 7.97k, Folded]
  ------------------
  437|  7.97k|					if ( _upper < _lower ) {
  ------------------
  |  Branch (437:11): [True: 2.20k, False: 5.77k]
  ------------------
  438|  2.20k|						_keys += _klen;
  439|  2.20k|						_trans += (unsigned int)_klen;
  440|  2.20k|						break;
  441|  2.20k|					}
  442|       |					
  443|  5.77k|					_mid = _lower + ((_upper-_lower) >> 1);
  444|  5.77k|					if ( ( (*( p))) < (*( _mid)) )
  ------------------
  |  Branch (444:11): [True: 244, False: 5.53k]
  ------------------
  445|    244|						_upper = _mid - 1;
  446|  5.53k|					else if ( ( (*( p))) > (*( _mid)) )
  ------------------
  |  Branch (446:16): [True: 3.03k, False: 2.50k]
  ------------------
  447|  3.03k|						_lower = _mid + 1;
  448|  2.50k|					else {
  449|  2.50k|						_trans += (unsigned int)(_mid - _keys);
  450|  2.50k|						goto _match;
  451|  2.50k|					}
  452|  5.77k|				}
  453|  4.70k|			}
  454|       |			
  455|  2.20k|			_klen = (int)_sav_date_parse_range_lengths[cs];
  456|  2.20k|			if ( _klen > 0 ) {
  ------------------
  |  Branch (456:9): [True: 2.12k, False: 74]
  ------------------
  457|  2.12k|				const char *_lower = _keys;
  458|  2.12k|				const char *_upper = _keys + (_klen<<1) - 2;
  459|  2.12k|				const char *_mid;
  460|  2.31k|				while ( 1 ) {
  ------------------
  |  Branch (460:13): [True: 2.31k, Folded]
  ------------------
  461|  2.31k|					if ( _upper < _lower ) {
  ------------------
  |  Branch (461:11): [True: 182, False: 2.12k]
  ------------------
  462|    182|						_trans += (unsigned int)_klen;
  463|    182|						break;
  464|    182|					}
  465|       |					
  466|  2.12k|					_mid = _lower + (((_upper-_lower) >> 1) & ~1);
  467|  2.12k|					if ( ( (*( p))) < (*( _mid)) )
  ------------------
  |  Branch (467:11): [True: 121, False: 2.00k]
  ------------------
  468|    121|						_upper = _mid - 2;
  469|  2.00k|					else if ( ( (*( p))) > (*( _mid + 1)) )
  ------------------
  |  Branch (469:16): [True: 61, False: 1.94k]
  ------------------
  470|     61|						_lower = _mid + 2;
  471|  1.94k|					else {
  472|  1.94k|						_trans += (unsigned int)((_mid - _keys)>>1);
  473|  1.94k|						break;
  474|  1.94k|					}
  475|  2.12k|				}
  476|  2.12k|			}
  477|       |			
  478|  4.70k|			_match: {}
  479|  4.70k|		}
  480|  5.14k|		cs = (int)_sav_date_parse_cond_targs[_trans];
  481|       |		
  482|  5.14k|		if ( _sav_date_parse_cond_actions[_trans] != 0 ) {
  ------------------
  |  Branch (482:8): [True: 3.42k, False: 1.72k]
  ------------------
  483|       |			
  484|  3.42k|			_acts = ( _sav_date_parse_actions + (_sav_date_parse_cond_actions[_trans]));
  485|  3.42k|			_nacts = (unsigned int)(*( _acts));
  486|  3.42k|			_acts += 1;
  487|  7.88k|			while ( _nacts > 0 ) {
  ------------------
  |  Branch (487:12): [True: 4.45k, False: 3.42k]
  ------------------
  488|  4.45k|				switch ( (*( _acts)) )
  ------------------
  |  Branch (488:14): [True: 4.45k, False: 0]
  ------------------
  489|  4.45k|				{
  490|  2.00k|					case 0:  {
  ------------------
  |  Branch (490:6): [True: 2.00k, False: 2.45k]
  ------------------
  491|  2.00k|						{
  492|  2.00k|#line 71 "src/spss/readstat_sav_parse_timestamp.rl"
  493|       |							
  494|  2.00k|							char digit = ((( (*( p)))) - '0');
  495|  2.00k|							if (digit >= 0 && digit <= 9) {
  ------------------
  |  Branch (495:12): [True: 1.94k, False: 61]
  |  Branch (495:26): [True: 1.94k, False: 0]
  ------------------
  496|  1.94k|								temp_val = 10 * temp_val + digit;
  497|  1.94k|							}
  498|  2.00k|						}
  499|       |						
  500|  2.00k|#line 501 "src/spss/readstat_sav_parse_timestamp.c"
  501|       |						
  502|  2.00k|						break; 
  503|      0|					}
  504|    437|					case 1:  {
  ------------------
  |  Branch (504:6): [True: 437, False: 4.02k]
  ------------------
  505|    437|						{
  506|    437|#line 78 "src/spss/readstat_sav_parse_timestamp.rl"
  507|       |							
  508|    437|							if (temp_val < 70) {
  ------------------
  |  Branch (508:12): [True: 358, False: 79]
  ------------------
  509|    358|								timestamp->tm_year = 100 + temp_val;
  510|    358|							} else {
  511|     79|								timestamp->tm_year = temp_val;
  512|     79|							}
  513|    437|						}
  514|       |						
  515|    437|#line 516 "src/spss/readstat_sav_parse_timestamp.c"
  516|       |						
  517|    437|						break; 
  518|      0|					}
  519|  1.03k|					case 2:  {
  ------------------
  |  Branch (519:6): [True: 1.03k, False: 3.42k]
  ------------------
  520|  1.03k|						{
  521|  1.03k|#line 87 "src/spss/readstat_sav_parse_timestamp.rl"
  522|  1.03k|							temp_val = 0; }
  523|       |						
  524|  1.03k|#line 525 "src/spss/readstat_sav_parse_timestamp.c"
  525|       |						
  526|  1.03k|						break; 
  527|      0|					}
  528|    517|					case 3:  {
  ------------------
  |  Branch (528:6): [True: 517, False: 3.94k]
  ------------------
  529|    517|						{
  530|    517|#line 89 "src/spss/readstat_sav_parse_timestamp.rl"
  531|    517|							timestamp->tm_mday = temp_val; }
  532|       |						
  533|    517|#line 534 "src/spss/readstat_sav_parse_timestamp.c"
  534|       |						
  535|    517|						break; 
  536|      0|					}
  537|    226|					case 4:  {
  ------------------
  |  Branch (537:6): [True: 226, False: 4.23k]
  ------------------
  538|    226|						{
  539|    226|#line 94 "src/spss/readstat_sav_parse_timestamp.rl"
  540|    226|							timestamp->tm_mon = 0; }
  541|       |						
  542|    226|#line 543 "src/spss/readstat_sav_parse_timestamp.c"
  543|       |						
  544|    226|						break; 
  545|      0|					}
  546|     12|					case 5:  {
  ------------------
  |  Branch (546:6): [True: 12, False: 4.44k]
  ------------------
  547|     12|						{
  548|     12|#line 95 "src/spss/readstat_sav_parse_timestamp.rl"
  549|     12|							timestamp->tm_mon = 1; }
  550|       |						
  551|     12|#line 552 "src/spss/readstat_sav_parse_timestamp.c"
  552|       |						
  553|     12|						break; 
  554|      0|					}
  555|     28|					case 6:  {
  ------------------
  |  Branch (555:6): [True: 28, False: 4.43k]
  ------------------
  556|     28|						{
  557|     28|#line 96 "src/spss/readstat_sav_parse_timestamp.rl"
  558|     28|							timestamp->tm_mon = 2; }
  559|       |						
  560|     28|#line 561 "src/spss/readstat_sav_parse_timestamp.c"
  561|       |						
  562|     28|						break; 
  563|      0|					}
  564|      5|					case 7:  {
  ------------------
  |  Branch (564:6): [True: 5, False: 4.45k]
  ------------------
  565|      5|						{
  566|      5|#line 97 "src/spss/readstat_sav_parse_timestamp.rl"
  567|      5|							timestamp->tm_mon = 3; }
  568|       |						
  569|      5|#line 570 "src/spss/readstat_sav_parse_timestamp.c"
  570|       |						
  571|      5|						break; 
  572|      0|					}
  573|      3|					case 8:  {
  ------------------
  |  Branch (573:6): [True: 3, False: 4.45k]
  ------------------
  574|      3|						{
  575|      3|#line 98 "src/spss/readstat_sav_parse_timestamp.rl"
  576|      3|							timestamp->tm_mon = 4; }
  577|       |						
  578|      3|#line 579 "src/spss/readstat_sav_parse_timestamp.c"
  579|       |						
  580|      3|						break; 
  581|      0|					}
  582|    138|					case 9:  {
  ------------------
  |  Branch (582:6): [True: 138, False: 4.32k]
  ------------------
  583|    138|						{
  584|    138|#line 99 "src/spss/readstat_sav_parse_timestamp.rl"
  585|    138|							timestamp->tm_mon = 5; }
  586|       |						
  587|    138|#line 588 "src/spss/readstat_sav_parse_timestamp.c"
  588|       |						
  589|    138|						break; 
  590|      0|					}
  591|      4|					case 10:  {
  ------------------
  |  Branch (591:6): [True: 4, False: 4.45k]
  ------------------
  592|      4|						{
  593|      4|#line 100 "src/spss/readstat_sav_parse_timestamp.rl"
  594|      4|							timestamp->tm_mon = 6; }
  595|       |						
  596|      4|#line 597 "src/spss/readstat_sav_parse_timestamp.c"
  597|       |						
  598|      4|						break; 
  599|      0|					}
  600|      1|					case 11:  {
  ------------------
  |  Branch (600:6): [True: 1, False: 4.45k]
  ------------------
  601|      1|						{
  602|      1|#line 101 "src/spss/readstat_sav_parse_timestamp.rl"
  603|      1|							timestamp->tm_mon = 7; }
  604|       |						
  605|      1|#line 606 "src/spss/readstat_sav_parse_timestamp.c"
  606|       |						
  607|      1|						break; 
  608|      0|					}
  609|      6|					case 12:  {
  ------------------
  |  Branch (609:6): [True: 6, False: 4.45k]
  ------------------
  610|      6|						{
  611|      6|#line 102 "src/spss/readstat_sav_parse_timestamp.rl"
  612|      6|							timestamp->tm_mon = 8; }
  613|       |						
  614|      6|#line 615 "src/spss/readstat_sav_parse_timestamp.c"
  615|       |						
  616|      6|						break; 
  617|      0|					}
  618|      2|					case 13:  {
  ------------------
  |  Branch (618:6): [True: 2, False: 4.45k]
  ------------------
  619|      2|						{
  620|      2|#line 103 "src/spss/readstat_sav_parse_timestamp.rl"
  621|      2|							timestamp->tm_mon = 9; }
  622|       |						
  623|      2|#line 624 "src/spss/readstat_sav_parse_timestamp.c"
  624|       |						
  625|      2|						break; 
  626|      0|					}
  627|      2|					case 14:  {
  ------------------
  |  Branch (627:6): [True: 2, False: 4.45k]
  ------------------
  628|      2|						{
  629|      2|#line 104 "src/spss/readstat_sav_parse_timestamp.rl"
  630|      2|							timestamp->tm_mon = 10; }
  631|       |						
  632|      2|#line 633 "src/spss/readstat_sav_parse_timestamp.c"
  633|       |						
  634|      2|						break; 
  635|      0|					}
  636|     33|					case 15:  {
  ------------------
  |  Branch (636:6): [True: 33, False: 4.42k]
  ------------------
  637|     33|						{
  638|     33|#line 105 "src/spss/readstat_sav_parse_timestamp.rl"
  639|     33|							timestamp->tm_mon = 11; }
  640|       |						
  641|     33|#line 642 "src/spss/readstat_sav_parse_timestamp.c"
  642|       |						
  643|     33|						break; 
  644|      0|					}
  645|  4.45k|				}
  646|  4.45k|				_nacts -= 1;
  647|  4.45k|				_acts += 1;
  648|  4.45k|			}
  649|       |			
  650|  3.42k|		}
  651|       |		
  652|  5.14k|		if ( p == eof ) {
  ------------------
  |  Branch (652:8): [True: 437, False: 4.70k]
  ------------------
  653|    437|			if ( cs >= 47 )
  ------------------
  |  Branch (653:9): [True: 437, False: 0]
  ------------------
  654|    437|				goto _out;
  655|    437|		}
  656|  4.70k|		else {
  657|  4.70k|			if ( cs != 0 ) {
  ------------------
  |  Branch (657:9): [True: 4.44k, False: 256]
  ------------------
  658|  4.44k|				p += 1;
  659|  4.44k|				goto _resume;
  660|  4.44k|			}
  661|  4.70k|		}
  662|    693|		_out: {}
  663|    693|	}
  664|       |	
  665|      0|#line 112 "src/spss/readstat_sav_parse_timestamp.rl"
  666|       |	
  667|       |	
  668|    693|	if (cs < 
  ------------------
  |  Branch (668:6): [True: 256, False: 437]
  ------------------
  669|    693|#line 670 "src/spss/readstat_sav_parse_timestamp.c"
  670|    693|	47
  671|    437|#line 114 "src/spss/readstat_sav_parse_timestamp.rl"
  672|    437|	|| p != pe) {
  ------------------
  |  Branch (672:5): [True: 0, False: 437]
  ------------------
  673|    256|		if (error_cb) {
  ------------------
  |  Branch (673:7): [True: 0, False: 256]
  ------------------
  674|      0|			snprintf(error_buf, sizeof(error_buf),
  675|      0|			"Invalid date string (length=%d): %.*s", (int)len, (int)len, data);
  676|      0|			error_cb(error_buf, user_ctx);
  677|      0|		}
  678|    256|		retval = READSTAT_ERROR_BAD_TIMESTAMP_STRING;
  679|    256|	}
  680|       |	
  681|    693|	(void)sav_date_parse_en_main;
  682|       |	
  683|    693|	return retval;
  684|  5.14k|}

sav_parse_timestamp:
 1587|  5.15k|readstat_error_t sav_parse_timestamp(sav_ctx_t *ctx, sav_file_header_record_t *header) {
 1588|  5.15k|    readstat_error_t retval = READSTAT_OK;
 1589|  5.15k|    struct tm timestamp = { .tm_isdst = -1 };
 1590|       |
 1591|  5.15k|    if ((retval = sav_parse_time(header->creation_time, sizeof(header->creation_time),
  ------------------
  |  Branch (1591:9): [True: 4.46k, False: 693]
  ------------------
 1592|  5.15k|                    &timestamp, ctx->handle.error, ctx->user_ctx)) 
 1593|  5.15k|            != READSTAT_OK)
 1594|  4.46k|        goto cleanup;
 1595|       |
 1596|    693|    if ((retval = sav_parse_date(header->creation_date, sizeof(header->creation_date),
  ------------------
  |  Branch (1596:9): [True: 256, False: 437]
  ------------------
 1597|    693|                    &timestamp, ctx->handle.error, ctx->user_ctx)) 
 1598|    693|            != READSTAT_OK)
 1599|    256|        goto cleanup;
 1600|       |
 1601|    437|    ctx->timestamp = mktime(&timestamp);
 1602|       |
 1603|  5.15k|cleanup:
 1604|  5.15k|    return retval;
 1605|    437|}
readstat_parse_sav:
 1607|  5.18k|readstat_error_t readstat_parse_sav(readstat_parser_t *parser, const char *path, void *user_ctx) {
 1608|  5.18k|    readstat_error_t retval = READSTAT_OK;
 1609|  5.18k|    readstat_io_t *io = parser->io;
 1610|  5.18k|    sav_file_header_record_t header;
 1611|  5.18k|    sav_ctx_t *ctx = NULL;
 1612|  5.18k|    size_t file_size = 0;
 1613|       |    
 1614|  5.18k|    if (io->open(path, io->io_ctx) == -1) {
  ------------------
  |  Branch (1614:9): [True: 0, False: 5.18k]
  ------------------
 1615|      0|        return READSTAT_ERROR_OPEN;
 1616|      0|    }
 1617|       |
 1618|  5.18k|    file_size = io->seek(0, READSTAT_SEEK_END, io->io_ctx);
 1619|  5.18k|    if (file_size == -1) {
  ------------------
  |  Branch (1619:9): [True: 0, False: 5.18k]
  ------------------
 1620|      0|        retval = READSTAT_ERROR_SEEK;
 1621|      0|        goto cleanup;
 1622|      0|    }
 1623|       |
 1624|  5.18k|    if (io->seek(0, READSTAT_SEEK_SET, io->io_ctx) == -1) {
  ------------------
  |  Branch (1624:9): [True: 0, False: 5.18k]
  ------------------
 1625|      0|        retval = READSTAT_ERROR_SEEK;
 1626|      0|        goto cleanup;
 1627|      0|    }
 1628|       |
 1629|  5.18k|    if (io->read(&header, sizeof(sav_file_header_record_t), io->io_ctx) < sizeof(sav_file_header_record_t)) {
  ------------------
  |  Branch (1629:9): [True: 11, False: 5.17k]
  ------------------
 1630|     11|        retval = READSTAT_ERROR_READ;
 1631|     11|        goto cleanup;
 1632|     11|    }
 1633|       |
 1634|  5.17k|    ctx = sav_ctx_init(&header, io);
 1635|  5.17k|    if (ctx == NULL) {
  ------------------
  |  Branch (1635:9): [True: 19, False: 5.15k]
  ------------------
 1636|     19|        retval = READSTAT_ERROR_PARSE;
 1637|     19|        goto cleanup;
 1638|     19|    }
 1639|       |
 1640|  5.15k|    ctx->handle = parser->handlers;
 1641|  5.15k|    ctx->input_encoding = parser->input_encoding;
 1642|  5.15k|    ctx->output_encoding = parser->output_encoding;
 1643|  5.15k|    ctx->user_ctx = user_ctx;
 1644|  5.15k|    ctx->file_size = file_size;
 1645|  5.15k|    if (parser->row_offset > 0)
  ------------------
  |  Branch (1645:9): [True: 0, False: 5.15k]
  ------------------
 1646|      0|        ctx->row_offset = parser->row_offset;
 1647|  5.15k|    if (ctx->record_count >= 0) {
  ------------------
  |  Branch (1647:9): [True: 3.84k, False: 1.31k]
  ------------------
 1648|  3.84k|        int record_count_after_skipping = ctx->record_count - ctx->row_offset;
 1649|  3.84k|        if (record_count_after_skipping < 0) {
  ------------------
  |  Branch (1649:13): [True: 0, False: 3.84k]
  ------------------
 1650|      0|            record_count_after_skipping = 0;
 1651|      0|            ctx->row_offset = ctx->record_count;
 1652|      0|        }
 1653|  3.84k|        ctx->row_limit = record_count_after_skipping;
 1654|  3.84k|        if (parser->row_limit > 0 && parser->row_limit < record_count_after_skipping) 
  ------------------
  |  Branch (1654:13): [True: 0, False: 3.84k]
  |  Branch (1654:38): [True: 0, False: 0]
  ------------------
 1655|      0|            ctx->row_limit = parser->row_limit;
 1656|  3.84k|    } else if (parser->row_limit > 0) {
  ------------------
  |  Branch (1656:16): [True: 0, False: 1.31k]
  ------------------
 1657|      0|        ctx->row_limit = parser->row_limit;
 1658|      0|    }
 1659|       |    
 1660|       |    /* ignore errors */
 1661|  5.15k|    sav_parse_timestamp(ctx, &header);
 1662|       |
 1663|  5.15k|    if ((retval = sav_parse_records_pass1(ctx)) != READSTAT_OK)
  ------------------
  |  Branch (1663:9): [True: 1.01k, False: 4.14k]
  ------------------
 1664|  1.01k|        goto cleanup;
 1665|       |    
 1666|  4.14k|    if (io->seek(sizeof(sav_file_header_record_t), READSTAT_SEEK_SET, io->io_ctx) == -1) {
  ------------------
  |  Branch (1666:9): [True: 0, False: 4.14k]
  ------------------
 1667|      0|        retval = READSTAT_ERROR_SEEK;
 1668|      0|        goto cleanup;
 1669|      0|    }
 1670|       |
 1671|  4.14k|    if ((retval = sav_update_progress(ctx)) != READSTAT_OK)
  ------------------
  |  Branch (1671:9): [True: 0, False: 4.14k]
  ------------------
 1672|      0|        goto cleanup;
 1673|       |
 1674|  4.14k|    if ((retval = sav_parse_records_pass2(ctx)) != READSTAT_OK)
  ------------------
  |  Branch (1674:9): [True: 2.46k, False: 1.67k]
  ------------------
 1675|  2.46k|        goto cleanup;
 1676|       | 
 1677|  1.67k|    if ((retval = sav_set_n_segments_and_var_count(ctx)) != READSTAT_OK)
  ------------------
  |  Branch (1677:9): [True: 33, False: 1.64k]
  ------------------
 1678|     33|        goto cleanup;
 1679|       |
 1680|  1.64k|    if (ctx->var_count == 0) {
  ------------------
  |  Branch (1680:9): [True: 14, False: 1.62k]
  ------------------
 1681|     14|        retval = READSTAT_ERROR_PARSE;
 1682|     14|        goto cleanup;
 1683|     14|    }
 1684|       |
 1685|  1.62k|    if (ctx->handle.metadata) {
  ------------------
  |  Branch (1685:9): [True: 1.62k, False: 0]
  ------------------
 1686|  1.62k|        readstat_metadata_t metadata = {
 1687|  1.62k|            .row_count = ctx->record_count < 0 ? -1 : ctx->row_limit,
  ------------------
  |  Branch (1687:26): [True: 388, False: 1.24k]
  ------------------
 1688|  1.62k|            .var_count = ctx->var_count,
 1689|  1.62k|            .file_encoding = ctx->input_encoding,
 1690|  1.62k|            .file_format_version = ctx->format_version,
 1691|  1.62k|            .creation_time = ctx->timestamp,
 1692|  1.62k|            .modified_time = ctx->timestamp,
 1693|  1.62k|            .compression = ctx->compression,
 1694|  1.62k|            .endianness = ctx->endianness
 1695|  1.62k|        };
 1696|  1.62k|        if ((retval = readstat_convert(ctx->file_label, sizeof(ctx->file_label),
  ------------------
  |  Branch (1696:13): [True: 5, False: 1.62k]
  ------------------
 1697|  1.62k|                        header.file_label, sizeof(header.file_label), ctx->converter)) != READSTAT_OK)
 1698|      5|            goto cleanup;
 1699|       |
 1700|  1.62k|        metadata.file_label = ctx->file_label;
 1701|       |
 1702|       |        // Replace short MR names with long names
 1703|  1.62k|        ck_hash_table_t *var_dict = ck_hash_table_init(ctx->var_index, 8);
 1704|   294k|        for (size_t i = 0; i < ctx->var_index; i++) {
  ------------------
  |  Branch (1704:28): [True: 293k, False: 1.62k]
  ------------------
 1705|   293k|            spss_varinfo_t *current_varinfo = ctx->varinfo[i];
 1706|   293k|            if (current_varinfo != NULL && current_varinfo->name[0] != '\0') {
  ------------------
  |  Branch (1706:17): [True: 293k, False: 0]
  |  Branch (1706:44): [True: 289k, False: 3.24k]
  ------------------
 1707|   289k|                ck_str_hash_insert(current_varinfo->name, current_varinfo, var_dict);
 1708|   289k|            }
 1709|   293k|        }
 1710|  1.82k|        for (size_t i = 0; i < ctx->multiple_response_sets_length; i++) {
  ------------------
  |  Branch (1710:28): [True: 200, False: 1.62k]
  ------------------
 1711|    200|            mr_set_t mr = ctx->mr_sets[i];
 1712|  2.77k|            for (size_t j = 0; j < mr.num_subvars; j++) {
  ------------------
  |  Branch (1712:32): [True: 2.57k, False: 200]
  ------------------
 1713|  2.57k|                char* sv_name_upper = readstat_malloc(strlen(mr.subvariables[j]) + 1);
 1714|  2.57k|                if (sv_name_upper == NULL) {
  ------------------
  |  Branch (1714:21): [True: 0, False: 2.57k]
  ------------------
 1715|      0|                    retval = READSTAT_ERROR_MALLOC;
 1716|      0|                    goto cleanup;
 1717|      0|                }
 1718|  2.57k|                sv_name_upper[strlen(mr.subvariables[j])] = '\0';
 1719|  12.9k|                for (int c = 0; mr.subvariables[j][c] != '\0'; c++) {
  ------------------
  |  Branch (1719:33): [True: 10.3k, False: 2.57k]
  ------------------
 1720|  10.3k|                    sv_name_upper[c] = toupper((unsigned char) mr.subvariables[j][c]);
  ------------------
  |  Branch (1720:40): [True: 0, False: 0]
  |  Branch (1720:40): [True: 0, False: 0]
  |  Branch (1720:40): [Folded, False: 10.3k]
  ------------------
 1721|  10.3k|                }
 1722|  2.57k|                spss_varinfo_t *info = (spss_varinfo_t *)ck_str_hash_lookup(sv_name_upper, var_dict);
 1723|  2.57k|                if (info) {
  ------------------
  |  Branch (1723:21): [True: 57, False: 2.51k]
  ------------------
 1724|     57|                    free(mr.subvariables[j]);
 1725|       |                    // mr.subvariables[j] = NULL;
 1726|     57|                    if ((mr.subvariables[j] = readstat_malloc(strlen(info->longname) + 1)) == NULL) {
  ------------------
  |  Branch (1726:25): [True: 0, False: 57]
  ------------------
 1727|      0|                        retval = READSTAT_ERROR_MALLOC;
 1728|      0|                        goto cleanup;
 1729|      0|                    }
 1730|       |                    // mr.subvariables[j][strlen(info->longname)] = '\0';
 1731|     57|                    strcpy(mr.subvariables[j], info->longname);
 1732|       |                    // mr.subvariables[j] = info->longname;
 1733|     57|                }
 1734|  2.57k|                free(sv_name_upper);
 1735|       |                // sv_name_upper = NULL;
 1736|  2.57k|            }
 1737|    200|        }
 1738|  1.62k|        if (var_dict)
  ------------------
  |  Branch (1738:13): [True: 1.62k, False: 0]
  ------------------
 1739|  1.62k|            ck_hash_table_free(var_dict);
 1740|       |
 1741|  1.62k|        metadata.multiple_response_sets_length = ctx->multiple_response_sets_length;
 1742|  1.62k|        metadata.mr_sets = ctx->mr_sets;
 1743|       |
 1744|  1.62k|        if (ctx->handle.metadata(&metadata, ctx->user_ctx) != READSTAT_HANDLER_OK) {
  ------------------
  |  Branch (1744:13): [True: 0, False: 1.62k]
  ------------------
 1745|      0|            retval = READSTAT_ERROR_USER_ABORT;
 1746|      0|            goto cleanup;
 1747|      0|        }
 1748|  1.62k|    }
 1749|       |
 1750|  1.62k|    if ((retval = sav_parse_variable_display_parameter_record(ctx)) != READSTAT_OK)
  ------------------
  |  Branch (1750:9): [True: 32, False: 1.59k]
  ------------------
 1751|     32|        goto cleanup;
 1752|       |
 1753|  1.59k|    if ((retval = sav_handle_variables(ctx)) != READSTAT_OK)
  ------------------
  |  Branch (1753:9): [True: 0, False: 1.59k]
  ------------------
 1754|      0|        goto cleanup;
 1755|       |
 1756|       |
 1757|  1.59k|    if ((retval = sav_handle_fweight(ctx)) != READSTAT_OK)
  ------------------
  |  Branch (1757:9): [True: 0, False: 1.59k]
  ------------------
 1758|      0|        goto cleanup;
 1759|       |
 1760|  1.59k|    if (ctx->handle.value) {
  ------------------
  |  Branch (1760:9): [True: 1.59k, False: 0]
  ------------------
 1761|  1.59k|        retval = sav_read_data(ctx);
 1762|  1.59k|    }
 1763|       |    
 1764|  5.18k|cleanup:
 1765|  5.18k|    io->close(io->io_ctx);
 1766|  5.18k|    if (ctx)
  ------------------
  |  Branch (1766:9): [True: 5.15k, False: 30]
  ------------------
 1767|  5.15k|        sav_ctx_free(ctx);
 1768|       |    
 1769|  5.18k|    return retval;
 1770|  1.59k|}
readstat_sav_read.c:sav_parse_records_pass1:
 1304|  5.15k|static readstat_error_t sav_parse_records_pass1(sav_ctx_t *ctx) {
 1305|  5.15k|    char data_buf[4096];
 1306|  5.15k|    readstat_error_t retval = READSTAT_OK;
 1307|  5.15k|    readstat_io_t *io = ctx->io;
 1308|   491k|    while (1) {
  ------------------
  |  Branch (1308:12): [True: 491k, Folded]
  ------------------
 1309|   491k|        uint32_t rec_type;
 1310|   491k|        uint32_t extra_info[3];
 1311|   491k|        size_t data_len = 0;
 1312|   491k|        int i;
 1313|   491k|        int done = 0;
 1314|   491k|        if (io->read(&rec_type, sizeof(uint32_t), io->io_ctx) < sizeof(uint32_t)) {
  ------------------
  |  Branch (1314:13): [True: 216, False: 491k]
  ------------------
 1315|    216|            retval = READSTAT_ERROR_READ;
 1316|    216|            goto cleanup;
 1317|    216|        }
 1318|       |        
 1319|   491k|        if (ctx->bswap) {
  ------------------
  |  Branch (1319:13): [True: 13.8k, False: 477k]
  ------------------
 1320|  13.8k|            rec_type = byteswap4(rec_type);
 1321|  13.8k|        }
 1322|       |        
 1323|   491k|        switch (rec_type) {
 1324|   467k|            case SAV_RECORD_TYPE_VARIABLE:
  ------------------
  |  |  115|   467k|#define SAV_RECORD_TYPE_VARIABLE                2
  ------------------
  |  Branch (1324:13): [True: 467k, False: 23.7k]
  ------------------
 1325|   467k|                retval = sav_skip_variable_record(ctx);
 1326|   467k|                if (retval != READSTAT_OK)
  ------------------
  |  Branch (1326:21): [True: 88, False: 467k]
  ------------------
 1327|     88|                    goto cleanup;
 1328|   467k|                break;
 1329|   467k|            case SAV_RECORD_TYPE_VALUE_LABEL:
  ------------------
  |  |  116|  5.67k|#define SAV_RECORD_TYPE_VALUE_LABEL             3
  ------------------
  |  Branch (1329:13): [True: 5.67k, False: 485k]
  ------------------
 1330|  5.67k|                retval = sav_skip_value_label_record(ctx);
 1331|  5.67k|                if (retval != READSTAT_OK)
  ------------------
  |  Branch (1331:21): [True: 161, False: 5.51k]
  ------------------
 1332|    161|                    goto cleanup;
 1333|  5.51k|                break;
 1334|  5.51k|            case SAV_RECORD_TYPE_DOCUMENT:
  ------------------
  |  |  118|  1.23k|#define SAV_RECORD_TYPE_DOCUMENT                6
  ------------------
  |  Branch (1334:13): [True: 1.23k, False: 489k]
  ------------------
 1335|  1.23k|                retval = sav_skip_document_record(ctx);
 1336|  1.23k|                if (retval != READSTAT_OK)
  ------------------
  |  Branch (1336:21): [True: 30, False: 1.20k]
  ------------------
 1337|     30|                    goto cleanup;
 1338|  1.20k|                break;
 1339|  4.14k|            case SAV_RECORD_TYPE_DICT_TERMINATION:
  ------------------
  |  |  120|  4.14k|#define SAV_RECORD_TYPE_DICT_TERMINATION        999
  ------------------
  |  Branch (1339:13): [True: 4.14k, False: 486k]
  ------------------
 1340|  4.14k|                done = 1;
 1341|  4.14k|                break;
 1342|  12.6k|            case SAV_RECORD_TYPE_HAS_DATA:
  ------------------
  |  |  119|  12.6k|#define SAV_RECORD_TYPE_HAS_DATA                7
  ------------------
  |  Branch (1342:13): [True: 12.6k, False: 478k]
  ------------------
 1343|  12.6k|                if (io->read(extra_info, sizeof(extra_info), io->io_ctx) < sizeof(extra_info)) {
  ------------------
  |  Branch (1343:21): [True: 6, False: 12.6k]
  ------------------
 1344|      6|                    retval = READSTAT_ERROR_READ;
 1345|      6|                    goto cleanup;
 1346|      6|                }
 1347|  12.6k|                if (ctx->bswap) {
  ------------------
  |  Branch (1347:21): [True: 3.51k, False: 9.13k]
  ------------------
 1348|  14.0k|                    for (i=0; i<3; i++)
  ------------------
  |  Branch (1348:31): [True: 10.5k, False: 3.51k]
  ------------------
 1349|  10.5k|                        extra_info[i] = byteswap4(extra_info[i]);
 1350|  3.51k|                }
 1351|  12.6k|                uint32_t subtype = extra_info[0];
 1352|  12.6k|                size_t size = extra_info[1];
 1353|  12.6k|                size_t count = extra_info[2];
 1354|  12.6k|                data_len = size * count;
 1355|  12.6k|                if (subtype == SAV_RECORD_SUBTYPE_INTEGER_INFO) {
  ------------------
  |  |  122|  12.6k|#define SAV_RECORD_SUBTYPE_INTEGER_INFO       3
  ------------------
  |  Branch (1355:21): [True: 639, False: 12.0k]
  ------------------
 1356|    639|                    if (data_len > sizeof(data_buf)) {
  ------------------
  |  Branch (1356:25): [True: 57, False: 582]
  ------------------
 1357|     57|                        retval = READSTAT_ERROR_PARSE;
 1358|     57|                        goto cleanup;
 1359|     57|                    }
 1360|    582|                    if (io->read(data_buf, data_len, io->io_ctx) < data_len) {
  ------------------
  |  Branch (1360:25): [True: 13, False: 569]
  ------------------
 1361|     13|                        retval = READSTAT_ERROR_PARSE;
 1362|     13|                        goto cleanup;
 1363|     13|                    }
 1364|    569|                    retval = sav_parse_machine_integer_info_record(data_buf, data_len, ctx);
 1365|    569|                    if (retval != READSTAT_OK)
  ------------------
  |  Branch (1365:25): [True: 25, False: 544]
  ------------------
 1366|     25|                        goto cleanup;
 1367|  12.0k|                } else if (subtype == SAV_RECORD_SUBTYPE_MULTIPLE_RESPONSE_SETS) {
  ------------------
  |  |  124|  12.0k|#define SAV_RECORD_SUBTYPE_MULTIPLE_RESPONSE_SETS 7
  ------------------
  |  Branch (1367:28): [True: 319, False: 11.6k]
  ------------------
 1368|    319|                    if (ctx->mr_sets != NULL) {
  ------------------
  |  Branch (1368:25): [True: 1, False: 318]
  ------------------
 1369|      1|                        retval = READSTAT_ERROR_BAD_MR_STRING;
 1370|      1|                        goto cleanup;
 1371|      1|                    }
 1372|    318|                    retval = sav_read_multiple_response_sets(data_len, ctx);
 1373|    318|                    if (retval != READSTAT_OK)
  ------------------
  |  Branch (1373:25): [True: 227, False: 91]
  ------------------
 1374|    227|                        goto cleanup;
 1375|  11.6k|                } else {
 1376|  11.6k|                    if (io->seek(data_len, READSTAT_SEEK_CUR, io->io_ctx) == -1) {
  ------------------
  |  Branch (1376:25): [True: 104, False: 11.5k]
  ------------------
 1377|    104|                        retval = READSTAT_ERROR_SEEK;
 1378|    104|                        goto cleanup;
 1379|    104|                    }
 1380|  11.6k|                }
 1381|  12.2k|                break;
 1382|  12.2k|            default:
  ------------------
  |  Branch (1382:13): [True: 87, False: 490k]
  ------------------
 1383|     87|                retval = READSTAT_ERROR_PARSE;
 1384|     87|                goto cleanup;
 1385|      0|                break;
 1386|   491k|        }
 1387|   490k|        if (done)
  ------------------
  |  Branch (1387:13): [True: 4.14k, False: 486k]
  ------------------
 1388|  4.14k|            break;
 1389|   490k|    }
 1390|  5.15k|cleanup:
 1391|  5.15k|    return retval;
 1392|  5.15k|}
readstat_sav_read.c:sav_skip_variable_record:
  196|   467k|static readstat_error_t sav_skip_variable_record(sav_ctx_t *ctx) {
  197|   467k|    sav_variable_record_t variable;
  198|   467k|    readstat_error_t retval = READSTAT_OK;
  199|   467k|    readstat_io_t *io = ctx->io;
  200|   467k|    if (io->read(&variable, sizeof(sav_variable_record_t), io->io_ctx) < sizeof(sav_variable_record_t)) {
  ------------------
  |  Branch (200:9): [True: 8, False: 467k]
  ------------------
  201|      8|        retval = READSTAT_ERROR_READ;
  202|      8|        goto cleanup;
  203|      8|    }
  204|   467k|    if (variable.has_var_label) {
  ------------------
  |  Branch (204:9): [True: 2.54k, False: 464k]
  ------------------
  205|  2.54k|        uint32_t label_len;
  206|  2.54k|        if (io->read(&label_len, sizeof(uint32_t), io->io_ctx) < sizeof(uint32_t)) {
  ------------------
  |  Branch (206:13): [True: 36, False: 2.50k]
  ------------------
  207|     36|            retval = READSTAT_ERROR_READ;
  208|     36|            goto cleanup;
  209|     36|        }
  210|  2.50k|        label_len = ctx->bswap ? byteswap4(label_len) : label_len;
  ------------------
  |  Branch (210:21): [True: 735, False: 1.76k]
  ------------------
  211|  2.50k|        uint32_t label_capacity = (label_len + 3) / 4 * 4;
  212|  2.50k|        if (io->seek(label_capacity, READSTAT_SEEK_CUR, io->io_ctx) == -1) {
  ------------------
  |  Branch (212:13): [True: 7, False: 2.49k]
  ------------------
  213|      7|            retval = READSTAT_ERROR_SEEK;
  214|      7|            goto cleanup;
  215|      7|        }
  216|  2.50k|    }
  217|   467k|    if (variable.n_missing_values) {
  ------------------
  |  Branch (217:9): [True: 6.54k, False: 460k]
  ------------------
  218|  6.54k|        int n_missing_values = ctx->bswap ? byteswap4(variable.n_missing_values) : variable.n_missing_values;
  ------------------
  |  Branch (218:32): [True: 1.80k, False: 4.74k]
  ------------------
  219|  6.54k|        if (io->seek(abs(n_missing_values) * sizeof(double), READSTAT_SEEK_CUR, io->io_ctx) == -1) {
  ------------------
  |  Branch (219:13): [True: 37, False: 6.50k]
  ------------------
  220|     37|            retval = READSTAT_ERROR_SEEK;
  221|     37|            goto cleanup;
  222|     37|        }
  223|  6.54k|    }
  224|   467k|cleanup:
  225|   467k|    return retval;
  226|   467k|}
readstat_sav_read.c:sav_skip_value_label_record:
  431|  5.67k|static readstat_error_t sav_skip_value_label_record(sav_ctx_t *ctx) {
  432|  5.67k|    uint32_t label_count;
  433|  5.67k|    uint32_t rec_type;
  434|  5.67k|    uint32_t var_count;
  435|  5.67k|    readstat_error_t retval = READSTAT_OK;
  436|  5.67k|    readstat_io_t *io = ctx->io;
  437|  5.67k|    if (io->read(&label_count, sizeof(uint32_t), io->io_ctx) < sizeof(uint32_t)) {
  ------------------
  |  Branch (437:9): [True: 4, False: 5.66k]
  ------------------
  438|      4|        retval = READSTAT_ERROR_READ;
  439|      4|        goto cleanup;
  440|      4|    }
  441|  5.66k|    if (ctx->bswap)
  ------------------
  |  Branch (441:9): [True: 2.57k, False: 3.09k]
  ------------------
  442|  2.57k|        label_count = byteswap4(label_count);
  443|  5.66k|    int i;
  444|   130k|    for (i=0; i<label_count; i++) {
  ------------------
  |  Branch (444:15): [True: 125k, False: 5.57k]
  ------------------
  445|   125k|        unsigned char unpadded_len = 0;
  446|   125k|        size_t padded_len = 0;
  447|   125k|        if (io->seek(8, READSTAT_SEEK_CUR, io->io_ctx) == -1) {
  ------------------
  |  Branch (447:13): [True: 61, False: 125k]
  ------------------
  448|     61|            retval = READSTAT_ERROR_SEEK;
  449|     61|            goto cleanup;
  450|     61|        }
  451|   125k|        if (io->read(&unpadded_len, 1, io->io_ctx) < 1) {
  ------------------
  |  Branch (451:13): [True: 11, False: 125k]
  ------------------
  452|     11|            retval = READSTAT_ERROR_READ;
  453|     11|            goto cleanup;
  454|     11|        }
  455|   125k|        padded_len = (unpadded_len + 8) / 8 * 8 - 1;
  456|   125k|        if (io->seek(padded_len, READSTAT_SEEK_CUR, io->io_ctx) == -1) {
  ------------------
  |  Branch (456:13): [True: 17, False: 125k]
  ------------------
  457|     17|            retval = READSTAT_ERROR_SEEK;
  458|     17|            goto cleanup;
  459|     17|        }
  460|   125k|    }
  461|       |
  462|  5.57k|    if (io->read(&rec_type, sizeof(uint32_t), io->io_ctx) < sizeof(uint32_t)) {
  ------------------
  |  Branch (462:9): [True: 11, False: 5.56k]
  ------------------
  463|     11|        retval = READSTAT_ERROR_READ;
  464|     11|        goto cleanup;
  465|     11|    }
  466|  5.56k|    if (ctx->bswap)
  ------------------
  |  Branch (466:9): [True: 2.52k, False: 3.04k]
  ------------------
  467|  2.52k|        rec_type = byteswap4(rec_type);
  468|       |    
  469|  5.56k|    if (rec_type != 4) {
  ------------------
  |  Branch (469:9): [True: 46, False: 5.52k]
  ------------------
  470|     46|        retval = READSTAT_ERROR_PARSE;
  471|     46|        goto cleanup;
  472|     46|    }
  473|  5.52k|    if (io->read(&var_count, sizeof(uint32_t), io->io_ctx) < sizeof(uint32_t)) {
  ------------------
  |  Branch (473:9): [True: 8, False: 5.51k]
  ------------------
  474|      8|        retval = READSTAT_ERROR_READ;
  475|      8|        goto cleanup;
  476|      8|    }
  477|  5.51k|    if (ctx->bswap)
  ------------------
  |  Branch (477:9): [True: 2.49k, False: 3.02k]
  ------------------
  478|  2.49k|        var_count = byteswap4(var_count);
  479|       |    
  480|  5.51k|    if (io->seek(var_count * sizeof(uint32_t), READSTAT_SEEK_CUR, io->io_ctx) == -1) {
  ------------------
  |  Branch (480:9): [True: 3, False: 5.51k]
  ------------------
  481|      3|        retval = READSTAT_ERROR_SEEK;
  482|      3|        goto cleanup;
  483|      3|    }
  484|       |
  485|  5.67k|cleanup:
  486|  5.67k|    return retval;
  487|  5.51k|}
readstat_sav_read.c:sav_skip_document_record:
  643|  1.23k|static readstat_error_t sav_skip_document_record(sav_ctx_t *ctx) {
  644|  1.23k|    uint32_t n_lines;
  645|  1.23k|    readstat_error_t retval = READSTAT_OK;
  646|  1.23k|    readstat_io_t *io = ctx->io;
  647|  1.23k|    if (io->read(&n_lines, sizeof(uint32_t), io->io_ctx) < sizeof(uint32_t)) {
  ------------------
  |  Branch (647:9): [True: 4, False: 1.23k]
  ------------------
  648|      4|        retval = READSTAT_ERROR_READ;
  649|      4|        goto cleanup;
  650|      4|    }
  651|  1.23k|    if (ctx->bswap)
  ------------------
  |  Branch (651:9): [True: 452, False: 781]
  ------------------
  652|    452|        n_lines = byteswap4(n_lines);
  653|  1.23k|    if (io->seek(n_lines * SPSS_DOC_LINE_SIZE, READSTAT_SEEK_CUR, io->io_ctx) == -1) {
  ------------------
  |  |   40|  1.23k|#define SPSS_DOC_LINE_SIZE  80
  ------------------
  |  Branch (653:9): [True: 26, False: 1.20k]
  ------------------
  654|     26|        retval = READSTAT_ERROR_SEEK;
  655|     26|        goto cleanup;
  656|     26|    }
  657|       |    
  658|  1.23k|cleanup:
  659|  1.23k|    return retval;
  660|  1.23k|}
readstat_sav_read.c:sav_parse_machine_integer_info_record:
  946|    569|static readstat_error_t sav_parse_machine_integer_info_record(const void *data, size_t data_len, sav_ctx_t *ctx) {
  947|    569|    if (data_len != 32)
  ------------------
  |  Branch (947:9): [True: 7, False: 562]
  ------------------
  948|      7|        return READSTAT_ERROR_PARSE;
  949|       |
  950|    562|    const char *src_charset = NULL;
  951|    562|    const char *dst_charset = ctx->output_encoding;
  952|    562|    sav_machine_integer_info_record_t record;
  953|    562|    memcpy(&record, data, data_len);
  954|    562|    if (ctx->bswap) {
  ------------------
  |  Branch (954:9): [True: 109, False: 453]
  ------------------
  955|    109|        record.character_code = byteswap4(record.character_code);
  956|    109|    }
  957|    562|    if (ctx->input_encoding) {
  ------------------
  |  Branch (957:9): [True: 426, False: 136]
  ------------------
  958|    426|        src_charset = ctx->input_encoding;
  959|    426|    } else {
  960|    136|        int i;
  961|  8.81k|        for (i=0; i<sizeof(_charset_table)/sizeof(_charset_table[0]); i++) {
  ------------------
  |  Branch (961:19): [True: 8.79k, False: 17]
  ------------------
  962|  8.79k|            if (record.character_code  == _charset_table[i].code) {
  ------------------
  |  Branch (962:17): [True: 119, False: 8.67k]
  ------------------
  963|    119|                src_charset = _charset_table[i].name;
  964|    119|                break;
  965|    119|            }
  966|  8.79k|        }
  967|    136|        if (src_charset == NULL) {
  ------------------
  |  Branch (967:13): [True: 17, False: 119]
  ------------------
  968|     17|            if (ctx->handle.error) {
  ------------------
  |  Branch (968:17): [True: 0, False: 17]
  ------------------
  969|      0|                char error_buf[1024];
  970|      0|                snprintf(error_buf, sizeof(error_buf), "Unsupported character set: %d\n", record.character_code);
  971|      0|                ctx->handle.error(error_buf, ctx->user_ctx);
  972|      0|            }
  973|     17|            return READSTAT_ERROR_UNSUPPORTED_CHARSET;
  974|     17|        }
  975|    119|        ctx->input_encoding = src_charset;
  976|    119|    }
  977|    545|    if (src_charset && dst_charset) {
  ------------------
  |  Branch (977:9): [True: 545, False: 0]
  |  Branch (977:24): [True: 545, False: 0]
  ------------------
  978|       |        // You might be tempted to skip the charset conversion when src_charset
  979|       |        // and dst_charset are the same. However, some versions of SPSS insert
  980|       |        // illegally truncated strings (e.g. the last character is three bytes
  981|       |        // but the field only has room for two bytes). So to prevent the client
  982|       |        // from receiving an invalid byte sequence, we ram everything through
  983|       |        // our iconv machinery.
  984|    545|        iconv_t converter = iconv_open(dst_charset, src_charset);
  985|    545|        if (converter == (iconv_t)-1) {
  ------------------
  |  Branch (985:13): [True: 1, False: 544]
  ------------------
  986|      1|            return READSTAT_ERROR_UNSUPPORTED_CHARSET;
  987|      1|        }
  988|    544|        if (ctx->converter) {
  ------------------
  |  Branch (988:13): [True: 426, False: 118]
  ------------------
  989|    426|            iconv_close(ctx->converter);
  990|    426|        }
  991|    544|        ctx->converter = converter;
  992|    544|    }
  993|    544|    return READSTAT_OK;
  994|    545|}
readstat_sav_read.c:sav_read_multiple_response_sets:
  152|    318|static readstat_error_t sav_read_multiple_response_sets(size_t data_len, sav_ctx_t *ctx) {
  153|    318|    readstat_error_t retval = READSTAT_OK;
  154|       |
  155|    318|    char *mr_string = readstat_malloc(data_len + 1);
  156|    318|    if (mr_string == NULL) {
  ------------------
  |  Branch (156:9): [True: 40, False: 278]
  ------------------
  157|     40|        retval = READSTAT_ERROR_MALLOC;
  158|     40|        goto cleanup;
  159|     40|    }
  160|    278|    mr_string[data_len] = '\0';
  161|    278|    if (ctx->io->read(mr_string, data_len, ctx->io->io_ctx) < data_len) {
  ------------------
  |  Branch (161:9): [True: 40, False: 238]
  ------------------
  162|     40|        retval = READSTAT_ERROR_PARSE;
  163|     40|        goto cleanup;
  164|     40|    }
  165|    238|    if (mr_string[0] != '$') {
  ------------------
  |  Branch (165:9): [True: 11, False: 227]
  ------------------
  166|     11|        retval = READSTAT_ERROR_BAD_MR_STRING;
  167|     11|        goto cleanup;
  168|     11|    }
  169|       |
  170|    227|    retval = parse_mr_string(mr_string, &ctx->mr_sets, &ctx->multiple_response_sets_length, ctx);
  171|       |
  172|    318|cleanup:
  173|    318|    free(mr_string);
  174|    318|    return retval;
  175|    227|}
readstat_sav_read.c:sav_update_progress:
  191|  7.08k|static readstat_error_t sav_update_progress(sav_ctx_t *ctx) {
  192|  7.08k|    readstat_io_t *io = ctx->io;
  193|  7.08k|    return io->update(ctx->file_size, ctx->handle.progress, ctx->user_ctx, io->io_ctx);
  194|  7.08k|}
readstat_sav_read.c:sav_parse_records_pass2:
 1394|  4.14k|static readstat_error_t sav_parse_records_pass2(sav_ctx_t *ctx) {
 1395|  4.14k|    void *data_buf = NULL;
 1396|  4.14k|    size_t data_buf_capacity = 4096;
 1397|  4.14k|    readstat_error_t retval = READSTAT_OK;
 1398|  4.14k|    readstat_io_t *io = ctx->io;
 1399|       |
 1400|  4.14k|    if ((data_buf = readstat_malloc(data_buf_capacity)) == NULL) {
  ------------------
  |  Branch (1400:9): [True: 0, False: 4.14k]
  ------------------
 1401|      0|        retval = READSTAT_ERROR_MALLOC;
 1402|      0|        goto cleanup;
 1403|      0|    }
 1404|       |
 1405|   490k|    while (1) {
  ------------------
  |  Branch (1405:12): [True: 490k, Folded]
  ------------------
 1406|   490k|        uint32_t rec_type;
 1407|   490k|        uint32_t extra_info[3];
 1408|   490k|        size_t data_len = 0;
 1409|   490k|        int i;
 1410|   490k|        int done = 0;
 1411|   490k|        if (io->read(&rec_type, sizeof(uint32_t), io->io_ctx) < sizeof(uint32_t)) {
  ------------------
  |  Branch (1411:13): [True: 19, False: 490k]
  ------------------
 1412|     19|            retval = READSTAT_ERROR_READ;
 1413|     19|            goto cleanup;
 1414|     19|        }
 1415|       |        
 1416|   490k|        if (ctx->bswap) {
  ------------------
  |  Branch (1416:13): [True: 11.7k, False: 478k]
  ------------------
 1417|  11.7k|            rec_type = byteswap4(rec_type);
 1418|  11.7k|        }
 1419|       |        
 1420|   490k|        switch (rec_type) {
 1421|   470k|            case SAV_RECORD_TYPE_VARIABLE:
  ------------------
  |  |  115|   470k|#define SAV_RECORD_TYPE_VARIABLE                2
  ------------------
  |  Branch (1421:13): [True: 470k, False: 19.9k]
  ------------------
 1422|   470k|                if ((retval = sav_read_variable_record(ctx)) != READSTAT_OK)
  ------------------
  |  Branch (1422:21): [True: 164, False: 470k]
  ------------------
 1423|    164|                    goto cleanup;
 1424|   470k|                break;
 1425|   470k|            case SAV_RECORD_TYPE_VALUE_LABEL:
  ------------------
  |  |  116|  4.45k|#define SAV_RECORD_TYPE_VALUE_LABEL             3
  ------------------
  |  Branch (1425:13): [True: 4.45k, False: 485k]
  ------------------
 1426|  4.45k|                if ((retval = sav_read_value_label_record(ctx)) != READSTAT_OK)
  ------------------
  |  Branch (1426:21): [True: 185, False: 4.27k]
  ------------------
 1427|    185|                    goto cleanup;
 1428|  4.27k|                break;
 1429|  4.27k|            case SAV_RECORD_TYPE_DOCUMENT:
  ------------------
  |  |  118|  1.03k|#define SAV_RECORD_TYPE_DOCUMENT                6
  ------------------
  |  Branch (1429:13): [True: 1.03k, False: 489k]
  ------------------
 1430|  1.03k|                if ((retval = sav_read_document_record(ctx)) != READSTAT_OK)
  ------------------
  |  Branch (1430:21): [True: 61, False: 970]
  ------------------
 1431|     61|                    goto cleanup;
 1432|    970|                break;
 1433|  2.74k|            case SAV_RECORD_TYPE_DICT_TERMINATION:
  ------------------
  |  |  120|  2.74k|#define SAV_RECORD_TYPE_DICT_TERMINATION        999
  ------------------
  |  Branch (1433:13): [True: 2.74k, False: 487k]
  ------------------
 1434|  2.74k|                if ((retval = sav_read_dictionary_termination_record(ctx)) != READSTAT_OK)
  ------------------
  |  Branch (1434:21): [True: 1.06k, False: 1.67k]
  ------------------
 1435|  1.06k|                    goto cleanup;
 1436|  1.67k|                done = 1;
 1437|  1.67k|                break;
 1438|  11.6k|            case SAV_RECORD_TYPE_HAS_DATA:
  ------------------
  |  |  119|  11.6k|#define SAV_RECORD_TYPE_HAS_DATA                7
  ------------------
  |  Branch (1438:13): [True: 11.6k, False: 478k]
  ------------------
 1439|  11.6k|                if (io->read(extra_info, sizeof(extra_info), io->io_ctx) < sizeof(extra_info)) {
  ------------------
  |  Branch (1439:21): [True: 5, False: 11.6k]
  ------------------
 1440|      5|                    retval = READSTAT_ERROR_READ;
 1441|      5|                    goto cleanup;
 1442|      5|                }
 1443|  11.6k|                if (ctx->bswap) {
  ------------------
  |  Branch (1443:21): [True: 3.23k, False: 8.41k]
  ------------------
 1444|  12.9k|                    for (i=0; i<3; i++)
  ------------------
  |  Branch (1444:31): [True: 9.69k, False: 3.23k]
  ------------------
 1445|  9.69k|                        extra_info[i] = byteswap4(extra_info[i]);
 1446|  3.23k|                }
 1447|  11.6k|                uint32_t subtype = extra_info[0];
 1448|  11.6k|                size_t size = extra_info[1];
 1449|  11.6k|                size_t count = extra_info[2];
 1450|  11.6k|                data_len = size * count;
 1451|  11.6k|                if (data_buf_capacity < data_len) {
  ------------------
  |  Branch (1451:21): [True: 113, False: 11.5k]
  ------------------
 1452|    113|                    if ((data_buf = readstat_realloc(data_buf, data_buf_capacity = data_len)) == NULL) {
  ------------------
  |  Branch (1452:25): [True: 45, False: 68]
  ------------------
 1453|     45|                        retval = READSTAT_ERROR_MALLOC;
 1454|     45|                        goto cleanup;
 1455|     45|                    }
 1456|    113|                }
 1457|  11.6k|                if (data_len == 0 || io->read(data_buf, data_len, io->io_ctx) < data_len) {
  ------------------
  |  Branch (1457:21): [True: 12, False: 11.5k]
  |  Branch (1457:38): [True: 39, False: 11.5k]
  ------------------
 1458|     51|                    retval = READSTAT_ERROR_PARSE;
 1459|     51|                    goto cleanup;
 1460|     51|                }
 1461|       |                
 1462|  11.5k|                switch (subtype) {
 1463|    369|                    case SAV_RECORD_SUBTYPE_INTEGER_INFO:
  ------------------
  |  |  122|    369|#define SAV_RECORD_SUBTYPE_INTEGER_INFO       3
  ------------------
  |  Branch (1463:21): [True: 369, False: 11.1k]
  ------------------
 1464|       |                        /* parsed in pass 1 */
 1465|    369|                        break;
 1466|    719|                    case SAV_RECORD_SUBTYPE_FP_INFO:
  ------------------
  |  |  123|    719|#define SAV_RECORD_SUBTYPE_FP_INFO            4
  ------------------
  |  Branch (1466:21): [True: 719, False: 10.8k]
  ------------------
 1467|    719|                        retval = sav_parse_machine_floating_point_record(data_buf, size, count, ctx);
 1468|    719|                        if (retval != READSTAT_OK)
  ------------------
  |  Branch (1468:29): [True: 16, False: 703]
  ------------------
 1469|     16|                            goto cleanup;
 1470|    703|                        break;
 1471|    703|                    case SAV_RECORD_SUBTYPE_VAR_DISPLAY:
  ------------------
  |  |  126|    508|#define SAV_RECORD_SUBTYPE_VAR_DISPLAY       11
  ------------------
  |  Branch (1471:21): [True: 508, False: 11.0k]
  ------------------
 1472|    508|                        retval = sav_store_variable_display_parameter_record(data_buf, size, count, ctx);
 1473|    508|                        if (retval != READSTAT_OK)
  ------------------
  |  Branch (1473:29): [True: 16, False: 492]
  ------------------
 1474|     16|                            goto cleanup;
 1475|    492|                        break;
 1476|  2.93k|                    case SAV_RECORD_SUBTYPE_LONG_VAR_NAME:
  ------------------
  |  |  127|  2.93k|#define SAV_RECORD_SUBTYPE_LONG_VAR_NAME     13
  ------------------
  |  Branch (1476:21): [True: 2.93k, False: 8.61k]
  ------------------
 1477|  2.93k|                        retval = sav_parse_long_variable_names_record(data_buf, count, ctx);
 1478|  2.93k|                        if (retval != READSTAT_OK)
  ------------------
  |  Branch (1478:29): [True: 185, False: 2.75k]
  ------------------
 1479|    185|                            goto cleanup;
 1480|  2.75k|                        break;
 1481|  3.81k|                    case SAV_RECORD_SUBTYPE_VERY_LONG_STR:
  ------------------
  |  |  128|  3.81k|#define SAV_RECORD_SUBTYPE_VERY_LONG_STR     14
  ------------------
  |  Branch (1481:21): [True: 3.81k, False: 7.73k]
  ------------------
 1482|  3.81k|                        retval = sav_parse_very_long_string_record(data_buf, count, ctx);
 1483|  3.81k|                        if (retval != READSTAT_OK)
  ------------------
  |  Branch (1483:29): [True: 176, False: 3.64k]
  ------------------
 1484|    176|                            goto cleanup;
 1485|  3.64k|                        break;
 1486|  3.64k|                    case SAV_RECORD_SUBTYPE_LONG_STRING_VALUE_LABELS:
  ------------------
  |  |  133|    654|#define SAV_RECORD_SUBTYPE_LONG_STRING_VALUE_LABELS   21
  ------------------
  |  Branch (1486:21): [True: 654, False: 10.8k]
  ------------------
 1487|    654|                        retval = sav_parse_long_string_value_labels_record(data_buf, size, count, ctx);
 1488|    654|                        if (retval != READSTAT_OK)
  ------------------
  |  Branch (1488:29): [True: 242, False: 412]
  ------------------
 1489|    242|                            goto cleanup;
 1490|    412|                        break;
 1491|    431|                    case SAV_RECORD_SUBTYPE_LONG_STRING_MISSING_VALUES:
  ------------------
  |  |  134|    431|#define SAV_RECORD_SUBTYPE_LONG_STRING_MISSING_VALUES 22
  ------------------
  |  Branch (1491:21): [True: 431, False: 11.1k]
  ------------------
 1492|    431|                        retval = sav_parse_long_string_missing_values_record(data_buf, size, count, ctx);
 1493|    431|                        if (retval != READSTAT_OK)
  ------------------
  |  Branch (1493:29): [True: 160, False: 271]
  ------------------
 1494|    160|                            goto cleanup;
 1495|    271|                        break;
 1496|  2.11k|                    default: /* misc. info */
  ------------------
  |  Branch (1496:21): [True: 2.11k, False: 9.43k]
  ------------------
 1497|  2.11k|                        break;
 1498|  11.5k|                }
 1499|  10.7k|                break;
 1500|  10.7k|            default:
  ------------------
  |  Branch (1500:13): [True: 72, False: 490k]
  ------------------
 1501|     72|                retval = READSTAT_ERROR_PARSE;
 1502|     72|                goto cleanup;
 1503|      0|                break;
 1504|   490k|        }
 1505|   487k|        if (done)
  ------------------
  |  Branch (1505:13): [True: 1.67k, False: 486k]
  ------------------
 1506|  1.67k|            break;
 1507|   487k|    }
 1508|  4.14k|cleanup:
 1509|  4.14k|    if (data_buf)
  ------------------
  |  Branch (1509:9): [True: 4.09k, False: 45]
  ------------------
 1510|  4.09k|        free(data_buf);
 1511|  4.14k|    return retval;
 1512|  4.14k|}
readstat_sav_read.c:sav_read_variable_record:
  343|   470k|static readstat_error_t sav_read_variable_record(sav_ctx_t *ctx) {
  344|   470k|    readstat_io_t *io = ctx->io;
  345|   470k|    sav_variable_record_t variable = { 0 };
  346|   470k|    spss_varinfo_t *info = NULL;
  347|   470k|    readstat_error_t retval = READSTAT_OK;
  348|   470k|    if (ctx->var_index == ctx->varinfo_capacity) {
  ------------------
  |  Branch (348:9): [True: 217, False: 470k]
  ------------------
  349|    217|        if ((ctx->varinfo = readstat_realloc(ctx->varinfo, (ctx->varinfo_capacity *= 2) * sizeof(spss_varinfo_t *))) == NULL) {
  ------------------
  |  Branch (349:13): [True: 0, False: 217]
  ------------------
  350|      0|            retval = READSTAT_ERROR_MALLOC;
  351|      0|            goto cleanup;
  352|      0|        }
  353|    217|    }
  354|   470k|    if (io->read(&variable, sizeof(sav_variable_record_t), io->io_ctx) < sizeof(sav_variable_record_t)) {
  ------------------
  |  Branch (354:9): [True: 10, False: 470k]
  ------------------
  355|     10|        retval = READSTAT_ERROR_READ;
  356|     10|        goto cleanup;
  357|     10|    }
  358|   470k|    variable.print = ctx->bswap ? byteswap4(variable.print) : variable.print;
  ------------------
  |  Branch (358:22): [True: 5.59k, False: 464k]
  ------------------
  359|   470k|    variable.write = ctx->bswap ? byteswap4(variable.write) : variable.write;
  ------------------
  |  Branch (359:22): [True: 5.59k, False: 464k]
  ------------------
  360|       |
  361|   470k|    int32_t type = ctx->bswap ? byteswap4(variable.type) : variable.type;
  ------------------
  |  Branch (361:20): [True: 5.59k, False: 464k]
  ------------------
  362|   470k|    if (type < 0) {
  ------------------
  |  Branch (362:9): [True: 7.52k, False: 462k]
  ------------------
  363|  7.52k|        if (ctx->var_index == 0) {
  ------------------
  |  Branch (363:13): [True: 27, False: 7.49k]
  ------------------
  364|     27|            return READSTAT_ERROR_PARSE;
  365|     27|        }
  366|  7.49k|        ctx->var_offset++;
  367|  7.49k|        ctx->varinfo[ctx->var_index-1]->width++;
  368|  7.49k|        return retval;
  369|  7.52k|    }
  370|       |
  371|   462k|    if ((info = readstat_calloc(1, sizeof(spss_varinfo_t))) == NULL) {
  ------------------
  |  Branch (371:9): [True: 0, False: 462k]
  ------------------
  372|      0|        retval = READSTAT_ERROR_MALLOC;
  373|      0|        goto cleanup;
  374|      0|    }
  375|   462k|    info->width = 1;
  376|   462k|    info->n_segments = 1;
  377|   462k|    info->index = ctx->var_index;
  378|   462k|    info->offset = ctx->var_offset;
  379|   462k|    info->labels_index = -1;
  380|       |
  381|   462k|    retval = readstat_convert(info->name, sizeof(info->name),
  382|   462k|            variable.name, sizeof(variable.name), NULL);
  383|   462k|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (383:9): [True: 0, False: 462k]
  ------------------
  384|      0|        goto cleanup;
  385|       |
  386|   462k|    retval = readstat_convert(info->longname, sizeof(info->longname), 
  387|   462k|            variable.name, sizeof(variable.name), NULL);
  388|   462k|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (388:9): [True: 0, False: 462k]
  ------------------
  389|      0|        goto cleanup;
  390|       |
  391|   462k|    info->print_format.decimal_places = (variable.print & 0x000000FF);
  392|   462k|    info->print_format.width = (variable.print & 0x0000FF00) >> 8;
  393|   462k|    info->print_format.type = (variable.print  & 0x00FF0000) >> 16;
  394|       |
  395|   462k|    info->write_format.decimal_places = (variable.write & 0x000000FF);
  396|   462k|    info->write_format.width = (variable.write & 0x0000FF00) >> 8;
  397|   462k|    info->write_format.type = (variable.write  & 0x00FF0000) >> 16;
  398|       |
  399|   462k|    if (type > 0 || info->print_format.type == SPSS_FORMAT_TYPE_A || info->write_format.type == SPSS_FORMAT_TYPE_A) {
  ------------------
  |  |    2|   788k|#define SPSS_FORMAT_TYPE_A        1
  ------------------
                  if (type > 0 || info->print_format.type == SPSS_FORMAT_TYPE_A || info->write_format.type == SPSS_FORMAT_TYPE_A) {
  ------------------
  |  |    2|   192k|#define SPSS_FORMAT_TYPE_A        1
  ------------------
  |  Branch (399:9): [True: 137k, False: 325k]
  |  Branch (399:21): [True: 132k, False: 192k]
  |  Branch (399:70): [True: 111k, False: 81.7k]
  ------------------
  400|   381k|        info->type = READSTAT_TYPE_STRING;
  401|   381k|    } else {
  402|  81.7k|        info->type = READSTAT_TYPE_DOUBLE;
  403|  81.7k|    }
  404|       |    
  405|   462k|    if (variable.has_var_label) {
  ------------------
  |  Branch (405:9): [True: 1.95k, False: 460k]
  ------------------
  406|  1.95k|        if ((retval = sav_read_variable_label(info, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (406:13): [True: 48, False: 1.91k]
  ------------------
  407|     48|            goto cleanup;
  408|     48|        }
  409|  1.95k|    }
  410|       |    
  411|   462k|    if (variable.n_missing_values) {
  ------------------
  |  Branch (411:9): [True: 5.23k, False: 457k]
  ------------------
  412|  5.23k|        info->n_missing_values = ctx->bswap ? byteswap4(variable.n_missing_values) : variable.n_missing_values;
  ------------------
  |  Branch (412:34): [True: 1.38k, False: 3.85k]
  ------------------
  413|  5.23k|        if ((retval = sav_read_variable_missing_values(info, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (413:13): [True: 79, False: 5.15k]
  ------------------
  414|     79|            goto cleanup;
  415|     79|        }
  416|  5.23k|    }
  417|       |    
  418|   462k|    ctx->varinfo[ctx->var_index] = info;
  419|       |
  420|   462k|    ctx->var_index++;
  421|   462k|    ctx->var_offset++;
  422|       |    
  423|   462k|cleanup:
  424|   462k|    if (retval != READSTAT_OK) {
  ------------------
  |  Branch (424:9): [True: 137, False: 462k]
  ------------------
  425|    137|        spss_varinfo_free(info);
  426|    137|    }
  427|       |
  428|   462k|    return retval;
  429|   462k|}
readstat_sav_read.c:sav_read_variable_label:
  228|  1.95k|static readstat_error_t sav_read_variable_label(spss_varinfo_t *info, sav_ctx_t *ctx) {
  229|  1.95k|    readstat_io_t *io = ctx->io;
  230|  1.95k|    readstat_error_t retval = READSTAT_OK;
  231|  1.95k|    uint32_t label_len, label_capacity;
  232|  1.95k|    size_t out_label_len;
  233|  1.95k|    char *label_buf = NULL;
  234|  1.95k|    if (io->read(&label_len, sizeof(uint32_t), io->io_ctx) < sizeof(uint32_t)) {
  ------------------
  |  Branch (234:9): [True: 5, False: 1.95k]
  ------------------
  235|      5|        retval = READSTAT_ERROR_READ;
  236|      5|        goto cleanup;
  237|      5|    }
  238|  1.95k|    label_len = ctx->bswap ? byteswap4(label_len) : label_len;
  ------------------
  |  Branch (238:17): [True: 546, False: 1.40k]
  ------------------
  239|       |
  240|  1.95k|    if (label_len == 0)
  ------------------
  |  Branch (240:9): [True: 797, False: 1.15k]
  ------------------
  241|    797|        goto cleanup;
  242|       |
  243|  1.15k|    label_capacity = (label_len + 3) / 4 * 4;
  244|  1.15k|    if ((label_buf = readstat_malloc(label_capacity)) == NULL) {
  ------------------
  |  Branch (244:9): [True: 30, False: 1.12k]
  ------------------
  245|     30|        retval = READSTAT_ERROR_MALLOC;
  246|     30|        goto cleanup;
  247|     30|    }
  248|       |
  249|  1.12k|    out_label_len = (size_t)label_len*4+1;
  250|  1.12k|    if ((info->label = readstat_malloc(out_label_len)) == NULL) {
  ------------------
  |  Branch (250:9): [True: 8, False: 1.11k]
  ------------------
  251|      8|        retval = READSTAT_ERROR_MALLOC;
  252|      8|        goto cleanup;
  253|      8|    }
  254|       |
  255|  1.11k|    if (io->read(label_buf, label_capacity, io->io_ctx) < label_capacity) {
  ------------------
  |  Branch (255:9): [True: 5, False: 1.11k]
  ------------------
  256|      5|        retval = READSTAT_ERROR_READ;
  257|      5|        goto cleanup;
  258|      5|    }
  259|       |
  260|  1.11k|    retval = readstat_convert(info->label, out_label_len, label_buf, label_len, ctx->converter);
  261|  1.11k|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (261:9): [True: 0, False: 1.11k]
  ------------------
  262|      0|        goto cleanup;
  263|       |
  264|  1.95k|cleanup:
  265|  1.95k|    if (label_buf)
  ------------------
  |  Branch (265:9): [True: 1.12k, False: 832]
  ------------------
  266|  1.12k|        free(label_buf);
  267|       |
  268|  1.95k|    if (retval != READSTAT_OK) {
  ------------------
  |  Branch (268:9): [True: 48, False: 1.91k]
  ------------------
  269|     48|        if (info->label) {
  ------------------
  |  Branch (269:13): [True: 5, False: 43]
  ------------------
  270|      5|            free(info->label);
  271|      5|            info->label = NULL;
  272|      5|        }
  273|     48|    }
  274|       |
  275|  1.95k|    return retval;
  276|  1.11k|}
readstat_sav_read.c:sav_read_variable_missing_values:
  327|  5.23k|static readstat_error_t sav_read_variable_missing_values(spss_varinfo_t *info, sav_ctx_t *ctx) {
  328|  5.23k|    if (info->n_missing_values > 3 || info->n_missing_values < -3) {
  ------------------
  |  Branch (328:9): [True: 14, False: 5.22k]
  |  Branch (328:39): [True: 51, False: 5.17k]
  ------------------
  329|     65|        return READSTAT_ERROR_PARSE;
  330|     65|    }
  331|  5.17k|    if (info->n_missing_values < 0) {
  ------------------
  |  Branch (331:9): [True: 2.94k, False: 2.22k]
  ------------------
  332|  2.94k|        info->missing_range = 1;
  333|  2.94k|        info->n_missing_values = abs(info->n_missing_values);
  334|  2.94k|    } else {
  335|  2.22k|        info->missing_range = 0;
  336|  2.22k|    }
  337|  5.17k|    if (info->type == READSTAT_TYPE_DOUBLE) {
  ------------------
  |  Branch (337:9): [True: 2.72k, False: 2.44k]
  ------------------
  338|  2.72k|        return sav_read_variable_missing_double_values(info, ctx);
  339|  2.72k|    }
  340|  2.44k|    return sav_read_variable_missing_string_values(info, ctx);
  341|  5.17k|}
readstat_sav_read.c:sav_read_variable_missing_double_values:
  278|  2.72k|static readstat_error_t sav_read_variable_missing_double_values(spss_varinfo_t *info, sav_ctx_t *ctx) {
  279|  2.72k|    readstat_io_t *io = ctx->io;
  280|  2.72k|    int i;
  281|  2.72k|    readstat_error_t retval = READSTAT_OK;
  282|  2.72k|    if (io->read(info->missing_double_values, info->n_missing_values * sizeof(double), io->io_ctx)
  ------------------
  |  Branch (282:9): [True: 8, False: 2.71k]
  ------------------
  283|  2.72k|            < info->n_missing_values * sizeof(double)) {
  284|      8|        retval = READSTAT_ERROR_READ;
  285|      8|        goto cleanup;
  286|      8|    }
  287|  8.65k|    for (i=0; i<info->n_missing_values; i++) {
  ------------------
  |  Branch (287:15): [True: 5.93k, False: 2.71k]
  ------------------
  288|  5.93k|        if (ctx->bswap) {
  ------------------
  |  Branch (288:13): [True: 1.70k, False: 4.23k]
  ------------------
  289|  1.70k|            info->missing_double_values[i] = byteswap_double(info->missing_double_values[i]);
  290|  1.70k|        }
  291|       |
  292|  5.93k|        uint64_t long_value = 0;
  293|  5.93k|        memcpy(&long_value, &info->missing_double_values[i], 8);
  294|       |
  295|  5.93k|        if (long_value == ctx->missing_double)
  ------------------
  |  Branch (295:13): [True: 397, False: 5.53k]
  ------------------
  296|    397|            info->missing_double_values[i] = NAN;
  297|  5.93k|        if (long_value == ctx->lowest_double)
  ------------------
  |  Branch (297:13): [True: 332, False: 5.60k]
  ------------------
  298|    332|            info->missing_double_values[i] = -HUGE_VAL;
  299|  5.93k|        if (long_value == ctx->highest_double)
  ------------------
  |  Branch (299:13): [True: 386, False: 5.55k]
  ------------------
  300|    386|            info->missing_double_values[i] = HUGE_VAL;
  301|  5.93k|    }
  302|       |
  303|  2.72k|cleanup:
  304|  2.72k|    return retval;
  305|  2.71k|}
readstat_sav_read.c:sav_read_variable_missing_string_values:
  307|  2.44k|static readstat_error_t sav_read_variable_missing_string_values(spss_varinfo_t *info, sav_ctx_t *ctx) {
  308|  2.44k|    readstat_io_t *io = ctx->io;
  309|  2.44k|    int i;
  310|  2.44k|    readstat_error_t retval = READSTAT_OK;
  311|  7.12k|    for (i=0; i<info->n_missing_values; i++) {
  ------------------
  |  Branch (311:15): [True: 4.68k, False: 2.44k]
  ------------------
  312|  4.68k|        char missing_value[8];
  313|  4.68k|        if (io->read(missing_value, sizeof(missing_value), io->io_ctx) < sizeof(missing_value)) {
  ------------------
  |  Branch (313:13): [True: 5, False: 4.67k]
  ------------------
  314|      5|            retval = READSTAT_ERROR_READ;
  315|      5|            goto cleanup;
  316|      5|        }
  317|  4.67k|        retval = readstat_convert(info->missing_string_values[i], sizeof(info->missing_string_values[0]),
  318|  4.67k|                missing_value, sizeof(missing_value), ctx->converter);
  319|  4.67k|        if (retval != READSTAT_OK)
  ------------------
  |  Branch (319:13): [True: 1, False: 4.67k]
  ------------------
  320|      1|            goto cleanup;
  321|  4.67k|    }
  322|       |
  323|  2.44k|cleanup:
  324|  2.44k|    return retval;
  325|  2.44k|}
readstat_sav_read.c:sav_read_value_label_record:
  508|  4.45k|static readstat_error_t sav_read_value_label_record(sav_ctx_t *ctx) {
  509|  4.45k|    uint32_t label_count;
  510|  4.45k|    readstat_error_t retval = READSTAT_OK;
  511|  4.45k|    readstat_io_t *io = ctx->io;
  512|  4.45k|    uint32_t *vars = NULL;
  513|  4.45k|    uint32_t var_count;
  514|  4.45k|    int32_t rec_type;
  515|  4.45k|    readstat_type_t value_type = READSTAT_TYPE_STRING;
  516|  4.45k|    char label_buf[256];
  517|  4.45k|    value_label_t *value_labels = NULL;
  518|       |
  519|  4.45k|    if (io->read(&label_count, sizeof(uint32_t), io->io_ctx) < sizeof(uint32_t)) {
  ------------------
  |  Branch (519:9): [True: 6, False: 4.45k]
  ------------------
  520|      6|        retval = READSTAT_ERROR_READ;
  521|      6|        goto cleanup;
  522|      6|    }
  523|  4.45k|    if (ctx->bswap)
  ------------------
  |  Branch (523:9): [True: 1.73k, False: 2.71k]
  ------------------
  524|  1.73k|        label_count = byteswap4(label_count);
  525|       |    
  526|  4.45k|    if (label_count && (value_labels = readstat_calloc(label_count, sizeof(value_label_t))) == NULL) {
  ------------------
  |  Branch (526:9): [True: 798, False: 3.65k]
  |  Branch (526:24): [True: 46, False: 752]
  ------------------
  527|     46|        retval = READSTAT_ERROR_MALLOC;
  528|     46|        goto cleanup;
  529|     46|    }
  530|       |    
  531|  4.40k|    int i;
  532|  17.8k|    for (i=0; i<label_count; i++) {
  ------------------
  |  Branch (532:15): [True: 13.4k, False: 4.37k]
  ------------------
  533|  13.4k|        value_label_t *vlabel = &value_labels[i];
  534|  13.4k|        unsigned char unpadded_label_len = 0;
  535|  13.4k|        size_t padded_label_len = 0, utf8_label_len = 0;
  536|       |
  537|  13.4k|        if (io->read(vlabel->raw_value, 8, io->io_ctx) < 8) {
  ------------------
  |  Branch (537:13): [True: 19, False: 13.4k]
  ------------------
  538|     19|            retval = READSTAT_ERROR_READ;
  539|     19|            goto cleanup;
  540|     19|        }
  541|  13.4k|        if (io->read(&unpadded_label_len, 1, io->io_ctx) < 1) {
  ------------------
  |  Branch (541:13): [True: 3, False: 13.4k]
  ------------------
  542|      3|            retval = READSTAT_ERROR_READ;
  543|      3|            goto cleanup;
  544|      3|        }
  545|       |
  546|  13.4k|        padded_label_len = (unpadded_label_len + 8) / 8 * 8 - 1;
  547|  13.4k|        if (io->read(label_buf, padded_label_len, io->io_ctx) < padded_label_len) {
  ------------------
  |  Branch (547:13): [True: 11, False: 13.4k]
  ------------------
  548|     11|            retval = READSTAT_ERROR_READ;
  549|     11|            goto cleanup;
  550|     11|        }
  551|       |
  552|  13.4k|        utf8_label_len = padded_label_len*4+1;
  553|  13.4k|        if ((vlabel->label = readstat_malloc(utf8_label_len)) == NULL) {
  ------------------
  |  Branch (553:13): [True: 0, False: 13.4k]
  ------------------
  554|      0|            retval = READSTAT_ERROR_MALLOC;
  555|      0|            goto cleanup;
  556|      0|        }
  557|       |
  558|  13.4k|        retval = readstat_convert(vlabel->label, utf8_label_len, label_buf, padded_label_len, ctx->converter);
  559|  13.4k|        if (retval != READSTAT_OK)
  ------------------
  |  Branch (559:13): [True: 1, False: 13.4k]
  ------------------
  560|      1|            goto cleanup;
  561|  13.4k|    }
  562|       |
  563|  4.37k|    if (io->read(&rec_type, sizeof(int32_t), io->io_ctx) < sizeof(int32_t)) {
  ------------------
  |  Branch (563:9): [True: 4, False: 4.36k]
  ------------------
  564|      4|        retval = READSTAT_ERROR_READ;
  565|      4|        goto cleanup;
  566|      4|    }
  567|  4.36k|    if (ctx->bswap)
  ------------------
  |  Branch (567:9): [True: 1.71k, False: 2.64k]
  ------------------
  568|  1.71k|        rec_type = byteswap4(rec_type);
  569|       |    
  570|  4.36k|    if (rec_type != 4) {
  ------------------
  |  Branch (570:9): [True: 44, False: 4.32k]
  ------------------
  571|     44|        retval = READSTAT_ERROR_PARSE;
  572|     44|        goto cleanup;
  573|     44|    }
  574|  4.32k|    if (io->read(&var_count, sizeof(uint32_t), io->io_ctx) < sizeof(uint32_t)) {
  ------------------
  |  Branch (574:9): [True: 2, False: 4.32k]
  ------------------
  575|      2|        retval = READSTAT_ERROR_READ;
  576|      2|        goto cleanup;
  577|      2|    }
  578|  4.32k|    if (ctx->bswap)
  ------------------
  |  Branch (578:9): [True: 1.69k, False: 2.62k]
  ------------------
  579|  1.69k|        var_count = byteswap4(var_count);
  580|       |    
  581|  4.32k|    if (var_count && (vars = readstat_malloc(var_count * sizeof(uint32_t))) == NULL) {
  ------------------
  |  Branch (581:9): [True: 1.24k, False: 3.07k]
  |  Branch (581:22): [True: 38, False: 1.20k]
  ------------------
  582|     38|        retval = READSTAT_ERROR_MALLOC;
  583|     38|        goto cleanup;
  584|     38|    }
  585|  4.28k|    if (io->read(vars, var_count * sizeof(uint32_t), io->io_ctx) < var_count * sizeof(uint32_t)) {
  ------------------
  |  Branch (585:9): [True: 9, False: 4.27k]
  ------------------
  586|      9|        retval = READSTAT_ERROR_READ;
  587|      9|        goto cleanup;
  588|      9|    }
  589|   171k|    for (i=0; i<var_count; i++) {
  ------------------
  |  Branch (589:15): [True: 167k, False: 4.27k]
  ------------------
  590|   167k|        uint32_t var_offset = vars[i];
  591|   167k|        if (ctx->bswap)
  ------------------
  |  Branch (591:13): [True: 78.6k, False: 88.8k]
  ------------------
  592|  78.6k|            var_offset = byteswap4(var_offset);
  593|       |
  594|   167k|        var_offset--; // Why subtract 1????
  595|   167k|        spss_varinfo_t **var = bsearch(&var_offset, ctx->varinfo, ctx->var_index, sizeof(spss_varinfo_t *),
  596|   167k|                &spss_varinfo_compare);
  597|   167k|        if (var) {
  ------------------
  |  Branch (597:13): [True: 6.98k, False: 160k]
  ------------------
  598|  6.98k|            (*var)->labels_index = ctx->value_labels_count;
  599|  6.98k|            value_type = (*var)->type;
  600|  6.98k|        }
  601|   167k|    }
  602|       |
  603|  17.6k|    for (i=0; i<label_count; i++) {
  ------------------
  |  Branch (603:15): [True: 13.3k, False: 4.27k]
  ------------------
  604|  13.3k|        value_label_t *vlabel = &value_labels[i];
  605|  13.3k|        double val_d = 0.0;
  606|  13.3k|        vlabel->final_value.type = value_type;
  607|  13.3k|        if (value_type == READSTAT_TYPE_DOUBLE) {
  ------------------
  |  Branch (607:13): [True: 2.20k, False: 11.1k]
  ------------------
  608|  2.20k|            memcpy(&val_d, vlabel->raw_value, 8);
  609|  2.20k|            if (ctx->bswap)
  ------------------
  |  Branch (609:17): [True: 1.33k, False: 869]
  ------------------
  610|  1.33k|                val_d = byteswap_double(val_d);
  611|       |
  612|  2.20k|            vlabel->final_value.v.double_value = val_d;
  613|  2.20k|            sav_tag_missing_double(&vlabel->final_value, ctx);
  614|  11.1k|        } else {
  615|  11.1k|            retval = readstat_convert(vlabel->utf8_string_value, sizeof(vlabel->utf8_string_value),
  616|  11.1k|                    vlabel->raw_value, 8, ctx->converter);
  617|  11.1k|            if (retval != READSTAT_OK)
  ------------------
  |  Branch (617:17): [True: 2, False: 11.1k]
  ------------------
  618|      2|                break;
  619|       |
  620|  11.1k|            vlabel->final_value.v.string_value = vlabel->utf8_string_value;
  621|  11.1k|        }
  622|  13.3k|    }
  623|       |
  624|  4.27k|    if (ctx->handle.value_label) {
  ------------------
  |  Branch (624:9): [True: 4.27k, False: 0]
  ------------------
  625|  4.27k|        sav_submit_value_labels(value_labels, label_count, value_type, ctx);
  626|  4.27k|    }
  627|  4.27k|    ctx->value_labels_count++;
  628|  4.45k|cleanup:
  629|  4.45k|    if (vars)
  ------------------
  |  Branch (629:9): [True: 1.20k, False: 3.24k]
  ------------------
  630|  1.20k|        free(vars);
  631|  4.45k|    if (value_labels) {
  ------------------
  |  Branch (631:9): [True: 752, False: 3.70k]
  ------------------
  632|  3.09M|        for (i=0; i<label_count; i++) {
  ------------------
  |  Branch (632:19): [True: 3.09M, False: 752]
  ------------------
  633|  3.09M|            value_label_t *vlabel = &value_labels[i];
  634|  3.09M|            if (vlabel->label)
  ------------------
  |  Branch (634:17): [True: 13.4k, False: 3.08M]
  ------------------
  635|  13.4k|                free(vlabel->label);
  636|  3.09M|        }
  637|    752|        free(value_labels);
  638|    752|    }
  639|       |    
  640|  4.45k|    return retval;
  641|  4.27k|}
readstat_sav_read.c:sav_tag_missing_double:
  177|  1.44M|static void sav_tag_missing_double(readstat_value_t *value, sav_ctx_t *ctx) {
  178|  1.44M|    double fp_value = value->v.double_value;
  179|  1.44M|    uint64_t long_value = 0;
  180|  1.44M|    memcpy(&long_value, &fp_value, 8);
  181|  1.44M|    if (long_value == ctx->missing_double)
  ------------------
  |  Branch (181:9): [True: 35.2k, False: 1.41M]
  ------------------
  182|  35.2k|        value->is_system_missing = 1;
  183|  1.44M|    if (long_value == ctx->lowest_double)
  ------------------
  |  Branch (183:9): [True: 819, False: 1.44M]
  ------------------
  184|    819|        value->is_system_missing = 1;
  185|  1.44M|    if (long_value == ctx->highest_double)
  ------------------
  |  Branch (185:9): [True: 631, False: 1.44M]
  ------------------
  186|    631|        value->is_system_missing = 1;
  187|  1.44M|    if (isnan(fp_value))
  ------------------
  |  Branch (187:9): [True: 905, False: 1.44M]
  ------------------
  188|    905|        value->is_system_missing = 1;
  189|  1.44M|}
readstat_sav_read.c:sav_submit_value_labels:
  490|  4.27k|        readstat_type_t value_type, sav_ctx_t *ctx) {
  491|  4.27k|    char label_name_buf[256];
  492|  4.27k|    readstat_error_t retval = READSTAT_OK;
  493|  4.27k|    int32_t i;
  494|       |
  495|  4.27k|    snprintf(label_name_buf, sizeof(label_name_buf), SAV_LABEL_NAME_PREFIX "%d", ctx->value_labels_count);
  ------------------
  |  |  117|  4.27k|#define SAV_LABEL_NAME_PREFIX         "labels"
  ------------------
  496|       |
  497|  17.6k|    for (i=0; i<label_count; i++) {
  ------------------
  |  Branch (497:15): [True: 13.3k, False: 4.27k]
  ------------------
  498|  13.3k|        value_label_t *vlabel = &value_labels[i];
  499|  13.3k|        if (ctx->handle.value_label(label_name_buf, vlabel->final_value, vlabel->label, ctx->user_ctx) != READSTAT_HANDLER_OK) {
  ------------------
  |  Branch (499:13): [True: 0, False: 13.3k]
  ------------------
  500|      0|            retval = READSTAT_ERROR_USER_ABORT;
  501|      0|            goto cleanup;
  502|      0|        }
  503|  13.3k|    }
  504|  4.27k|cleanup:
  505|  4.27k|    return retval;
  506|  4.27k|}
readstat_sav_read.c:sav_read_document_record:
  662|  1.03k|static readstat_error_t sav_read_document_record(sav_ctx_t *ctx) {
  663|  1.03k|    if (!ctx->handle.note)
  ------------------
  |  Branch (663:9): [True: 0, False: 1.03k]
  ------------------
  664|      0|        return sav_skip_document_record(ctx);
  665|       |
  666|  1.03k|    uint32_t n_lines;
  667|  1.03k|    readstat_error_t retval = READSTAT_OK;
  668|  1.03k|    readstat_io_t *io = ctx->io;
  669|  1.03k|    if (io->read(&n_lines, sizeof(uint32_t), io->io_ctx) < sizeof(uint32_t)) {
  ------------------
  |  Branch (669:9): [True: 1, False: 1.03k]
  ------------------
  670|      1|        retval = READSTAT_ERROR_READ;
  671|      1|        goto cleanup;
  672|      1|    }
  673|  1.03k|    if (ctx->bswap)
  ------------------
  |  Branch (673:9): [True: 335, False: 695]
  ------------------
  674|    335|        n_lines = byteswap4(n_lines);
  675|       |
  676|  1.03k|    char raw_buffer[SPSS_DOC_LINE_SIZE];
  677|  1.03k|    char utf8_buffer[4*SPSS_DOC_LINE_SIZE+1];
  678|  1.03k|    int i;
  679|  1.42k|    for (i=0; i<n_lines; i++) {
  ------------------
  |  Branch (679:15): [True: 451, False: 970]
  ------------------
  680|    451|        if (io->read(raw_buffer, SPSS_DOC_LINE_SIZE, io->io_ctx) < SPSS_DOC_LINE_SIZE) {
  ------------------
  |  |   40|    451|#define SPSS_DOC_LINE_SIZE  80
  ------------------
                      if (io->read(raw_buffer, SPSS_DOC_LINE_SIZE, io->io_ctx) < SPSS_DOC_LINE_SIZE) {
  ------------------
  |  |   40|    451|#define SPSS_DOC_LINE_SIZE  80
  ------------------
  |  Branch (680:13): [True: 59, False: 392]
  ------------------
  681|     59|            retval = READSTAT_ERROR_READ;
  682|     59|            goto cleanup;
  683|     59|        }
  684|       |
  685|    392|        retval = readstat_convert(utf8_buffer, sizeof(utf8_buffer),
  686|    392|                raw_buffer, sizeof(raw_buffer), ctx->converter);
  687|    392|        if (retval != READSTAT_OK)
  ------------------
  |  Branch (687:13): [True: 1, False: 391]
  ------------------
  688|      1|            goto cleanup;
  689|       |
  690|    391|        if (ctx->handle.note(i, utf8_buffer, ctx->user_ctx) != READSTAT_HANDLER_OK) {
  ------------------
  |  Branch (690:13): [True: 0, False: 391]
  ------------------
  691|      0|            retval = READSTAT_ERROR_USER_ABORT;
  692|      0|            goto cleanup;
  693|      0|        }
  694|    391|    }
  695|       |
  696|  1.03k|cleanup:
  697|  1.03k|    return retval;
  698|  1.03k|}
readstat_sav_read.c:sav_read_dictionary_termination_record:
  700|  2.74k|static readstat_error_t sav_read_dictionary_termination_record(sav_ctx_t *ctx) {
  701|  2.74k|    int32_t filler;
  702|  2.74k|    readstat_error_t retval = READSTAT_OK;
  703|  2.74k|    readstat_io_t *io = ctx->io;
  704|  2.74k|    if (io->read(&filler, sizeof(int32_t), io->io_ctx) < sizeof(int32_t)) {
  ------------------
  |  Branch (704:9): [True: 1.06k, False: 1.67k]
  ------------------
  705|  1.06k|        retval = READSTAT_ERROR_READ;
  706|  1.06k|    }
  707|  2.74k|    return retval;
  708|  2.74k|}
readstat_sav_read.c:sav_parse_machine_floating_point_record:
  996|    719|static readstat_error_t sav_parse_machine_floating_point_record(const void *data, size_t size, size_t count, sav_ctx_t *ctx) {
  997|    719|    if (size != 8 || count != 3)
  ------------------
  |  Branch (997:9): [True: 2, False: 717]
  |  Branch (997:22): [True: 14, False: 703]
  ------------------
  998|     16|        return READSTAT_ERROR_PARSE;
  999|       |
 1000|    703|    sav_machine_floating_point_info_record_t fp_info;
 1001|    703|    memcpy(&fp_info, data, sizeof(sav_machine_floating_point_info_record_t));
 1002|       |
 1003|    703|    ctx->missing_double = ctx->bswap ? byteswap8(fp_info.sysmis) : fp_info.sysmis;
  ------------------
  |  Branch (1003:27): [True: 260, False: 443]
  ------------------
 1004|    703|    ctx->highest_double = ctx->bswap ? byteswap8(fp_info.highest) : fp_info.highest;
  ------------------
  |  Branch (1004:27): [True: 260, False: 443]
  ------------------
 1005|    703|    ctx->lowest_double = ctx->bswap ? byteswap8(fp_info.lowest) : fp_info.lowest;
  ------------------
  |  Branch (1005:26): [True: 260, False: 443]
  ------------------
 1006|       |
 1007|    703|    return READSTAT_OK;
 1008|    719|}
readstat_sav_read.c:sav_store_variable_display_parameter_record:
 1012|    508|static readstat_error_t sav_store_variable_display_parameter_record(const void *data, size_t size, size_t count, sav_ctx_t *ctx) {
 1013|    508|    if (size != 4)
  ------------------
  |  Branch (1013:9): [True: 16, False: 492]
  ------------------
 1014|     16|        return READSTAT_ERROR_PARSE;
 1015|       |
 1016|    492|    const uint32_t *data_ptr = data;
 1017|    492|    int i;
 1018|       |
 1019|    492|    ctx->variable_display_values = readstat_realloc(ctx->variable_display_values, count * sizeof(uint32_t));
 1020|    492|    if (count > 0 && ctx->variable_display_values == NULL)
  ------------------
  |  Branch (1020:9): [True: 492, False: 0]
  |  Branch (1020:22): [True: 0, False: 492]
  ------------------
 1021|      0|        return READSTAT_ERROR_MALLOC;
 1022|       |
 1023|    492|    ctx->variable_display_values_count = count;
 1024|   256k|    for (i=0; i<count; i++) {
  ------------------
  |  Branch (1024:15): [True: 255k, False: 492]
  ------------------
 1025|   255k|        ctx->variable_display_values[i] = ctx->bswap ? byteswap4(data_ptr[i]) : data_ptr[i];
  ------------------
  |  Branch (1025:43): [True: 132k, False: 122k]
  ------------------
 1026|   255k|    }
 1027|    492|    return READSTAT_OK;
 1028|    492|}
readstat_sav_read.c:sav_parse_long_string_value_labels_record:
 1090|    654|static readstat_error_t sav_parse_long_string_value_labels_record(const void *data, size_t size, size_t count, sav_ctx_t *ctx) {
 1091|    654|    if (!ctx->handle.value_label)
  ------------------
  |  Branch (1091:9): [True: 0, False: 654]
  ------------------
 1092|      0|        return READSTAT_OK;
 1093|    654|    if (size != 1)
  ------------------
  |  Branch (1093:9): [True: 4, False: 650]
  ------------------
 1094|      4|        return READSTAT_ERROR_PARSE;
 1095|       |
 1096|    650|    readstat_error_t retval = READSTAT_OK;
 1097|    650|    uint32_t label_count = 0;
 1098|    650|    uint32_t i = 0;
 1099|    650|    const char *data_ptr = data;
 1100|    650|    const char *data_end = data_ptr + count;
 1101|    650|    char var_name_buf[256+1]; // unconverted
 1102|    650|    char label_name_buf[256];
 1103|    650|    char *value_buffer = NULL;
 1104|    650|    char *label_buffer = NULL;
 1105|       |    
 1106|  1.79k|    while (data_ptr < data_end) {
  ------------------
  |  Branch (1106:12): [True: 1.37k, False: 412]
  ------------------
 1107|  1.37k|        memset(label_name_buf, '\0', sizeof(label_name_buf));
 1108|       |
 1109|  1.37k|        retval = sav_read_pascal_string(var_name_buf, sizeof(var_name_buf),
 1110|  1.37k|                &data_ptr, data_end - data_ptr, ctx);
 1111|  1.37k|        if (retval != READSTAT_OK)
  ------------------
  |  Branch (1111:13): [True: 73, False: 1.30k]
  ------------------
 1112|     73|            goto cleanup;
 1113|       |
 1114|  4.42k|        for (i=0; i<ctx->var_index;) {
  ------------------
  |  Branch (1114:19): [True: 4.35k, False: 76]
  ------------------
 1115|  4.35k|            spss_varinfo_t *info = ctx->varinfo[i];
 1116|  4.35k|            if (strcmp(var_name_buf, info->longname) == 0) {
  ------------------
  |  Branch (1116:17): [True: 1.22k, False: 3.12k]
  ------------------
 1117|  1.22k|                info->labels_index = ctx->value_labels_count++;
 1118|  1.22k|                snprintf(label_name_buf, sizeof(label_name_buf),
 1119|  1.22k|                        SAV_LABEL_NAME_PREFIX "%d", info->labels_index);
  ------------------
  |  |  117|  1.22k|#define SAV_LABEL_NAME_PREFIX         "labels"
  ------------------
 1120|  1.22k|                break;
 1121|  1.22k|            }
 1122|  3.12k|            i += info->n_segments;
 1123|  3.12k|        }
 1124|       |
 1125|  1.30k|        if (label_name_buf[0] == '\0') {
  ------------------
  |  Branch (1125:13): [True: 76, False: 1.22k]
  ------------------
 1126|     76|            retval = READSTAT_ERROR_PARSE;
 1127|     76|            goto cleanup;
 1128|     76|        }
 1129|       |
 1130|  1.22k|        data_ptr += sizeof(uint32_t);
 1131|       |
 1132|  1.22k|        if (data_ptr + sizeof(uint32_t) > data_end) {
  ------------------
  |  Branch (1132:13): [True: 15, False: 1.21k]
  ------------------
 1133|     15|            retval = READSTAT_ERROR_PARSE;
 1134|     15|            goto cleanup;
 1135|     15|        }
 1136|       |
 1137|  1.21k|        memcpy(&label_count, data_ptr, sizeof(uint32_t));
 1138|  1.21k|        if (ctx->bswap)
  ------------------
  |  Branch (1138:13): [True: 452, False: 762]
  ------------------
 1139|    452|            label_count = byteswap4(label_count);
 1140|       |
 1141|  1.21k|        data_ptr += sizeof(uint32_t);
 1142|       |
 1143|  1.80k|        for (i=0; i<label_count; i++) {
  ------------------
  |  Branch (1143:19): [True: 666, False: 1.14k]
  ------------------
 1144|    666|            uint32_t value_len = 0, label_len = 0;
 1145|    666|            uint32_t value_buffer_len = 0, label_buffer_len = 0;
 1146|       |
 1147|    666|            if (data_ptr + sizeof(uint32_t) > data_end) {
  ------------------
  |  Branch (1147:17): [True: 24, False: 642]
  ------------------
 1148|     24|                retval = READSTAT_ERROR_PARSE;
 1149|     24|                goto cleanup;
 1150|     24|            }
 1151|       |
 1152|    642|            memcpy(&value_len, data_ptr, sizeof(uint32_t));
 1153|    642|            if (ctx->bswap)
  ------------------
  |  Branch (1153:17): [True: 321, False: 321]
  ------------------
 1154|    321|                value_len = byteswap4(value_len);
 1155|       |
 1156|    642|            data_ptr += sizeof(uint32_t);
 1157|       |
 1158|    642|            value_buffer_len = value_len*4+1;
 1159|    642|            value_buffer = readstat_realloc(value_buffer, value_buffer_len);
 1160|    642|            if (value_buffer == NULL) {
  ------------------
  |  Branch (1160:17): [True: 19, False: 623]
  ------------------
 1161|     19|                retval = READSTAT_ERROR_MALLOC;
 1162|     19|                goto cleanup;
 1163|     19|            }
 1164|       |
 1165|    623|            if (data_ptr + value_len > data_end) {
  ------------------
  |  Branch (1165:17): [True: 11, False: 612]
  ------------------
 1166|     11|                retval = READSTAT_ERROR_PARSE;
 1167|     11|                goto cleanup;
 1168|     11|            }
 1169|       |
 1170|    612|            retval = readstat_convert(value_buffer, value_buffer_len, data_ptr, value_len, ctx->converter);
 1171|    612|            if (retval != READSTAT_OK)
  ------------------
  |  Branch (1171:17): [True: 1, False: 611]
  ------------------
 1172|      1|                goto cleanup;
 1173|       |
 1174|    611|            data_ptr += value_len;
 1175|       |
 1176|    611|            if (data_ptr + sizeof(uint32_t) > data_end) {
  ------------------
  |  Branch (1176:17): [True: 4, False: 607]
  ------------------
 1177|      4|                retval = READSTAT_ERROR_PARSE;
 1178|      4|                goto cleanup;
 1179|      4|            }
 1180|       |
 1181|    607|            memcpy(&label_len, data_ptr, sizeof(uint32_t));
 1182|    607|            if (ctx->bswap)
  ------------------
  |  Branch (1182:17): [True: 306, False: 301]
  ------------------
 1183|    306|                label_len = byteswap4(label_len);
 1184|       |
 1185|    607|            data_ptr += sizeof(uint32_t);
 1186|       |
 1187|    607|            label_buffer_len = label_len*4+1;
 1188|    607|            label_buffer = readstat_realloc(label_buffer, label_buffer_len);
 1189|    607|            if (label_buffer == NULL) {
  ------------------
  |  Branch (1189:17): [True: 4, False: 603]
  ------------------
 1190|      4|                retval = READSTAT_ERROR_MALLOC;
 1191|      4|                goto cleanup;
 1192|      4|            }
 1193|       |
 1194|    603|            if (data_ptr + label_len > data_end) {
  ------------------
  |  Branch (1194:17): [True: 10, False: 593]
  ------------------
 1195|     10|                retval = READSTAT_ERROR_PARSE;
 1196|     10|                goto cleanup;
 1197|     10|            }
 1198|       |
 1199|    593|            retval = readstat_convert(label_buffer, label_buffer_len, data_ptr, label_len, ctx->converter);
 1200|    593|            if (retval != READSTAT_OK)
  ------------------
  |  Branch (1200:17): [True: 1, False: 592]
  ------------------
 1201|      1|                goto cleanup;
 1202|       |
 1203|    592|            data_ptr += label_len;
 1204|       |
 1205|    592|            readstat_value_t value = { .type = READSTAT_TYPE_STRING };
 1206|    592|            value.v.string_value = value_buffer;
 1207|       |
 1208|    592|            if (ctx->handle.value_label(label_name_buf, value, label_buffer, ctx->user_ctx) != READSTAT_HANDLER_OK) {
  ------------------
  |  Branch (1208:17): [True: 0, False: 592]
  ------------------
 1209|      0|                retval = READSTAT_ERROR_USER_ABORT;
 1210|      0|                goto cleanup;
 1211|      0|            }
 1212|    592|        }
 1213|  1.21k|    }
 1214|       |
 1215|    412|    if (data_ptr != data_end) {
  ------------------
  |  Branch (1215:9): [True: 0, False: 412]
  ------------------
 1216|      0|        retval = READSTAT_ERROR_PARSE;
 1217|      0|    }
 1218|       |
 1219|    650|cleanup:
 1220|    650|    if (value_buffer)
  ------------------
  |  Branch (1220:9): [True: 257, False: 393]
  ------------------
 1221|    257|        free(value_buffer);
 1222|    650|    if (label_buffer)
  ------------------
  |  Branch (1222:9): [True: 245, False: 405]
  ------------------
 1223|    245|        free(label_buffer);
 1224|    650|    return retval;
 1225|    412|}
readstat_sav_read.c:sav_read_pascal_string:
 1056|  2.24k|        const char **inout_data_ptr, size_t data_ptr_len, sav_ctx_t *ctx) {
 1057|  2.24k|    const char *data_ptr = *inout_data_ptr;
 1058|  2.24k|    const char *data_end = data_ptr + data_ptr_len;
 1059|  2.24k|    readstat_error_t retval = READSTAT_OK;
 1060|  2.24k|    uint32_t var_name_len = 0;
 1061|       |
 1062|  2.24k|    if (data_ptr + sizeof(uint32_t) > data_end) {
  ------------------
  |  Branch (1062:9): [True: 21, False: 2.22k]
  ------------------
 1063|     21|        retval = READSTAT_ERROR_PARSE;
 1064|     21|        goto cleanup;
 1065|     21|    }
 1066|       |
 1067|  2.22k|    memcpy(&var_name_len, data_ptr, sizeof(uint32_t));
 1068|  2.22k|    if (ctx->bswap)
  ------------------
  |  Branch (1068:9): [True: 853, False: 1.36k]
  ------------------
 1069|    853|        var_name_len = byteswap4(var_name_len);
 1070|       |
 1071|  2.22k|    data_ptr += sizeof(uint32_t);
 1072|       |
 1073|  2.22k|    if (data_ptr + var_name_len > data_end) {
  ------------------
  |  Branch (1073:9): [True: 95, False: 2.12k]
  ------------------
 1074|     95|        retval = READSTAT_ERROR_PARSE;
 1075|     95|        goto cleanup;
 1076|     95|    }
 1077|       |
 1078|  2.12k|    retval = readstat_convert(buf, buf_len, data_ptr, var_name_len, NULL);
 1079|  2.12k|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (1079:9): [True: 11, False: 2.11k]
  ------------------
 1080|     11|        goto cleanup;
 1081|       |
 1082|  2.11k|    data_ptr += var_name_len;
 1083|       |
 1084|  2.24k|cleanup:
 1085|  2.24k|    *inout_data_ptr = data_ptr;
 1086|       |
 1087|  2.24k|    return retval;
 1088|  2.11k|}
readstat_sav_read.c:sav_parse_long_string_missing_values_record:
 1227|    431|static readstat_error_t sav_parse_long_string_missing_values_record(const void *data, size_t size, size_t count, sav_ctx_t *ctx) {
 1228|    431|    if (size != 1)
  ------------------
  |  Branch (1228:9): [True: 2, False: 429]
  ------------------
 1229|      2|        return READSTAT_ERROR_PARSE;
 1230|       |
 1231|    429|    readstat_error_t retval = READSTAT_OK;
 1232|    429|    uint32_t i = 0, j = 0;
 1233|    429|    const char *data_ptr = data;
 1234|    429|    const char *data_end = data_ptr + count;
 1235|    429|    char var_name_buf[256+1];
 1236|       |
 1237|  1.13k|    while (data_ptr < data_end) {
  ------------------
  |  Branch (1237:12): [True: 865, False: 271]
  ------------------
 1238|    865|        retval = sav_read_pascal_string(var_name_buf, sizeof(var_name_buf),
 1239|    865|                &data_ptr, data_end - data_ptr, ctx);
 1240|    865|        if (retval != READSTAT_OK)
  ------------------
  |  Branch (1240:13): [True: 54, False: 811]
  ------------------
 1241|     54|            goto cleanup;
 1242|       |
 1243|    811|        if (data_ptr == data_end) {
  ------------------
  |  Branch (1243:13): [True: 5, False: 806]
  ------------------
 1244|      5|            retval = READSTAT_ERROR_PARSE;
 1245|      5|            goto cleanup;
 1246|      5|        }
 1247|       |
 1248|    806|        char n_missing_values = *data_ptr++;
 1249|    806|        if (n_missing_values < 1 || n_missing_values > 3) {
  ------------------
  |  Branch (1249:13): [True: 13, False: 793]
  |  Branch (1249:37): [True: 8, False: 785]
  ------------------
 1250|     21|            retval = READSTAT_ERROR_PARSE;
 1251|     21|            goto cleanup;
 1252|     21|        }
 1253|       |
 1254|   115k|        for (i=0; i<ctx->var_index;) {
  ------------------
  |  Branch (1254:19): [True: 115k, False: 51]
  ------------------
 1255|   115k|            spss_varinfo_t *info = ctx->varinfo[i];
 1256|   115k|            if (strcmp(var_name_buf, info->longname) == 0) {
  ------------------
  |  Branch (1256:17): [True: 734, False: 114k]
  ------------------
 1257|    734|                info->n_missing_values = n_missing_values;
 1258|       |
 1259|    734|                uint32_t var_name_len = 0;
 1260|       |
 1261|    734|                if (data_ptr + sizeof(uint32_t) > data_end) {
  ------------------
  |  Branch (1261:21): [True: 9, False: 725]
  ------------------
 1262|      9|                    retval = READSTAT_ERROR_PARSE;
 1263|      9|                    goto cleanup;
 1264|      9|                }
 1265|       |
 1266|    725|                memcpy(&var_name_len, data_ptr, sizeof(uint32_t));
 1267|    725|                if (ctx->bswap)
  ------------------
  |  Branch (1267:21): [True: 323, False: 402]
  ------------------
 1268|    323|                    var_name_len = byteswap4(var_name_len);
 1269|       |
 1270|    725|                data_ptr += sizeof(uint32_t);
 1271|       |
 1272|  2.65k|                for (j=0; j<n_missing_values; j++) {
  ------------------
  |  Branch (1272:27): [True: 1.94k, False: 707]
  ------------------
 1273|  1.94k|                    if (data_ptr + var_name_len > data_end) {
  ------------------
  |  Branch (1273:25): [True: 9, False: 1.93k]
  ------------------
 1274|      9|                        retval = READSTAT_ERROR_PARSE;
 1275|      9|                        goto cleanup;
 1276|      9|                    }
 1277|       |
 1278|  1.93k|                    retval = readstat_convert(info->missing_string_values[j],
 1279|  1.93k|                            sizeof(info->missing_string_values[0]),
 1280|  1.93k|                            data_ptr, var_name_len, ctx->converter);
 1281|  1.93k|                    if (retval != READSTAT_OK)
  ------------------
  |  Branch (1281:25): [True: 9, False: 1.92k]
  ------------------
 1282|      9|                        goto cleanup;
 1283|       |
 1284|  1.92k|                    data_ptr += var_name_len;
 1285|  1.92k|                }
 1286|    707|                break;
 1287|    725|            }
 1288|   114k|            i += info->n_segments;
 1289|   114k|        }
 1290|    758|        if (i == ctx->var_index) {
  ------------------
  |  Branch (1290:13): [True: 51, False: 707]
  ------------------
 1291|     51|            retval = READSTAT_ERROR_PARSE;
 1292|     51|            goto cleanup;
 1293|     51|        }
 1294|    758|    }
 1295|       |
 1296|    271|    if (data_ptr != data_end) {
  ------------------
  |  Branch (1296:9): [True: 0, False: 271]
  ------------------
 1297|      0|        retval = READSTAT_ERROR_PARSE;
 1298|      0|    }
 1299|       |
 1300|    429|cleanup:
 1301|    429|    return retval;
 1302|    271|}
readstat_sav_read.c:sav_set_n_segments_and_var_count:
 1514|  1.67k|static readstat_error_t sav_set_n_segments_and_var_count(sav_ctx_t *ctx) {
 1515|  1.67k|    int i;
 1516|  1.67k|    ctx->var_count = 0;
 1517|   289k|    for (i=0; i<ctx->var_index;) {
  ------------------
  |  Branch (1517:15): [True: 288k, False: 1.64k]
  ------------------
 1518|   288k|        spss_varinfo_t *info = ctx->varinfo[i];
 1519|   288k|        if (info->string_length > VERY_LONG_STRING_MAX_LENGTH)
  ------------------
  |  |   30|   288k|#define VERY_LONG_STRING_MAX_LENGTH INT_MAX
  ------------------
  |  Branch (1519:13): [True: 33, False: 288k]
  ------------------
 1520|     33|            return READSTAT_ERROR_PARSE;
 1521|   288k|        if (info->string_length) {
  ------------------
  |  Branch (1521:13): [True: 852, False: 287k]
  ------------------
 1522|    852|            info->n_segments = (info->string_length + 251) / 252;
 1523|    852|        }
 1524|   288k|        info->index = ctx->var_count++;
 1525|   288k|        i += info->n_segments;
 1526|   288k|    }
 1527|  1.64k|    ctx->variables = readstat_calloc(ctx->var_count, sizeof(readstat_variable_t *));
 1528|  1.64k|    return READSTAT_OK;
 1529|  1.67k|}
readstat_sav_read.c:sav_parse_variable_display_parameter_record:
 1030|  1.62k|static readstat_error_t sav_parse_variable_display_parameter_record(sav_ctx_t *ctx) {
 1031|  1.62k|    if (!ctx->variable_display_values)
  ------------------
  |  Branch (1031:9): [True: 1.42k, False: 195]
  ------------------
 1032|  1.42k|        return READSTAT_OK;
 1033|       |
 1034|    195|    int i;
 1035|    195|    long count = ctx->variable_display_values_count;
 1036|    195|    if (count != 2 * ctx->var_index && count != 3 * ctx->var_index) {
  ------------------
  |  Branch (1036:9): [True: 127, False: 68]
  |  Branch (1036:40): [True: 32, False: 95]
  ------------------
 1037|     32|        return READSTAT_ERROR_PARSE;
 1038|     32|    }
 1039|    163|    int has_display_width = ctx->var_index > 0 && (count / ctx->var_index == 3);
  ------------------
  |  Branch (1039:29): [True: 163, False: 0]
  |  Branch (1039:51): [True: 95, False: 68]
  ------------------
 1040|    163|    int offset = 0;
 1041|  7.22k|    for (i=0; i<ctx->var_index;) {
  ------------------
  |  Branch (1041:15): [True: 7.06k, False: 163]
  ------------------
 1042|  7.06k|        spss_varinfo_t *info = ctx->varinfo[i];
 1043|  7.06k|        offset = (2 + has_display_width)*i;
 1044|  7.06k|        info->measure = spss_measure_to_readstat_measure(ctx->variable_display_values[offset++]);
 1045|  7.06k|        if (has_display_width) {
  ------------------
  |  Branch (1045:13): [True: 3.36k, False: 3.69k]
  ------------------
 1046|  3.36k|            info->display_width = ctx->variable_display_values[offset++];
 1047|  3.36k|        }
 1048|  7.06k|        info->alignment = spss_alignment_to_readstat_alignment(ctx->variable_display_values[offset++]);
 1049|       |
 1050|  7.06k|        i += info->n_segments;
 1051|  7.06k|    }
 1052|    163|    return READSTAT_OK;
 1053|    195|}
readstat_sav_read.c:sav_handle_variables:
 1531|  1.59k|static readstat_error_t sav_handle_variables(sav_ctx_t *ctx) {
 1532|  1.59k|    int i;
 1533|  1.59k|    int index_after_skipping = 0;
 1534|  1.59k|    readstat_error_t retval = READSTAT_OK;
 1535|       |
 1536|  1.59k|    if (!ctx->handle.variable)
  ------------------
  |  Branch (1536:9): [True: 0, False: 1.59k]
  ------------------
 1537|      0|        return retval;
 1538|       |
 1539|   287k|    for (i=0; i<ctx->var_index;) {
  ------------------
  |  Branch (1539:15): [True: 286k, False: 1.59k]
  ------------------
 1540|   286k|        char label_name_buf[256];
 1541|   286k|        spss_varinfo_t *info = ctx->varinfo[i];
 1542|   286k|        ctx->variables[info->index] = spss_init_variable_for_info(info, index_after_skipping, ctx->converter);
 1543|       |
 1544|   286k|        snprintf(label_name_buf, sizeof(label_name_buf), SAV_LABEL_NAME_PREFIX "%d", info->labels_index);
  ------------------
  |  |  117|   286k|#define SAV_LABEL_NAME_PREFIX         "labels"
  ------------------
 1545|       |
 1546|   286k|        int cb_retval = ctx->handle.variable(info->index, ctx->variables[info->index],
 1547|   286k|                info->labels_index == -1 ? NULL : label_name_buf,
  ------------------
  |  Branch (1547:17): [True: 286k, False: 140]
  ------------------
 1548|   286k|                ctx->user_ctx);
 1549|       |
 1550|   286k|        if (cb_retval == READSTAT_HANDLER_ABORT) {
  ------------------
  |  Branch (1550:13): [True: 0, False: 286k]
  ------------------
 1551|      0|            retval = READSTAT_ERROR_USER_ABORT;
 1552|      0|            goto cleanup;
 1553|      0|        }
 1554|       |
 1555|   286k|        if (cb_retval == READSTAT_HANDLER_SKIP_VARIABLE) {
  ------------------
  |  Branch (1555:13): [True: 0, False: 286k]
  ------------------
 1556|      0|            ctx->variables[info->index]->skip = 1;
 1557|   286k|        } else {
 1558|   286k|            index_after_skipping++;
 1559|   286k|        }
 1560|       |
 1561|   286k|        i += info->n_segments;
 1562|   286k|    }
 1563|  1.59k|cleanup:
 1564|  1.59k|    return retval;
 1565|  1.59k|}
readstat_sav_read.c:sav_handle_fweight:
 1567|  1.59k|static readstat_error_t sav_handle_fweight(sav_ctx_t *ctx) {
 1568|  1.59k|    readstat_error_t retval = READSTAT_OK;
 1569|  1.59k|    int i;
 1570|  1.59k|    if (ctx->handle.fweight && ctx->fweight_index >= 0) {
  ------------------
  |  Branch (1570:9): [True: 1.59k, False: 0]
  |  Branch (1570:32): [True: 1.16k, False: 425]
  ------------------
 1571|   279k|        for (i=0; i<ctx->var_index;) {
  ------------------
  |  Branch (1571:19): [True: 278k, False: 1.14k]
  ------------------
 1572|   278k|            spss_varinfo_t *info = ctx->varinfo[i];
 1573|   278k|            if (info->offset == ctx->fweight_index - 1) {
  ------------------
  |  Branch (1573:17): [True: 22, False: 278k]
  ------------------
 1574|     22|                if (ctx->handle.fweight(ctx->variables[info->index], ctx->user_ctx) != READSTAT_HANDLER_OK) {
  ------------------
  |  Branch (1574:21): [True: 0, False: 22]
  ------------------
 1575|      0|                    retval = READSTAT_ERROR_USER_ABORT;
 1576|      0|                    goto cleanup;
 1577|      0|                }
 1578|     22|                break;
 1579|     22|            }
 1580|   278k|            i += info->n_segments;
 1581|   278k|        }
 1582|  1.16k|    }
 1583|  1.59k|cleanup:
 1584|  1.59k|    return retval;
 1585|  1.59k|}
readstat_sav_read.c:sav_read_data:
  795|  1.59k|static readstat_error_t sav_read_data(sav_ctx_t *ctx) {
  796|  1.59k|    readstat_error_t retval = READSTAT_OK;
  797|  1.59k|    size_t longest_string = 256;
  798|  1.59k|    int i;
  799|       |
  800|   287k|    for (i=0; i<ctx->var_index;) {
  ------------------
  |  Branch (800:15): [True: 286k, False: 1.59k]
  ------------------
  801|   286k|        spss_varinfo_t *info = ctx->varinfo[i];
  802|   286k|        if (info->string_length > longest_string) {
  ------------------
  |  Branch (802:13): [True: 147, False: 286k]
  ------------------
  803|    147|            longest_string = info->string_length;
  804|    147|        }
  805|   286k|        i += info->n_segments;
  806|   286k|    }
  807|       |
  808|  1.59k|    ctx->raw_string_len = longest_string + sizeof(SAV_EIGHT_SPACES)-2;
  ------------------
  |  |  143|  1.59k|#define SAV_EIGHT_SPACES              "        "
  ------------------
  809|  1.59k|    ctx->raw_string = readstat_malloc(ctx->raw_string_len);
  810|       |
  811|  1.59k|    ctx->utf8_string_len = 4*longest_string+1 + sizeof(SAV_EIGHT_SPACES)-2;
  ------------------
  |  |  143|  1.59k|#define SAV_EIGHT_SPACES              "        "
  ------------------
  812|  1.59k|    ctx->utf8_string = readstat_malloc(ctx->utf8_string_len);
  813|       |
  814|  1.59k|    if (ctx->raw_string == NULL || ctx->utf8_string == NULL) {
  ------------------
  |  Branch (814:9): [True: 24, False: 1.56k]
  |  Branch (814:36): [True: 4, False: 1.56k]
  ------------------
  815|     28|        retval = READSTAT_ERROR_MALLOC;
  816|     28|        goto done;
  817|     28|    }
  818|       |
  819|  1.56k|    if (ctx->compression == READSTAT_COMPRESS_ROWS) {
  ------------------
  |  Branch (819:9): [True: 322, False: 1.24k]
  ------------------
  820|    322|        retval = sav_read_compressed_data(ctx, &sav_process_row);
  821|  1.24k|    } else if (ctx->compression == READSTAT_COMPRESS_BINARY) {
  ------------------
  |  Branch (821:16): [True: 371, False: 870]
  ------------------
  822|    371|#if HAVE_ZLIB
  823|    371|        retval = zsav_read_compressed_data(ctx, &sav_process_row);
  824|       |#else
  825|       |        retval = READSTAT_ERROR_UNSUPPORTED_COMPRESSION;
  826|       |#endif
  827|    870|    } else {
  828|    870|        retval = sav_read_uncompressed_data(ctx, &sav_process_row);
  829|    870|    }
  830|  1.56k|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (830:9): [True: 343, False: 1.22k]
  ------------------
  831|    343|        goto done;
  832|       |
  833|  1.22k|    if (ctx->record_count >= 0 && ctx->current_row != ctx->row_limit) {
  ------------------
  |  Branch (833:9): [True: 939, False: 281]
  |  Branch (833:35): [True: 855, False: 84]
  ------------------
  834|    855|        retval = READSTAT_ERROR_ROW_COUNT_MISMATCH;
  835|    855|    }
  836|       |
  837|  1.59k|done:
  838|  1.59k|    return retval;
  839|  1.22k|}
readstat_sav_read.c:sav_read_compressed_data:
  879|    322|        readstat_error_t (*row_handler)(unsigned char *, size_t, sav_ctx_t *)) {
  880|    322|    readstat_error_t retval = READSTAT_OK;
  881|    322|    readstat_io_t *io = ctx->io;
  882|    322|    readstat_off_t data_offset = 0;
  883|    322|    unsigned char buffer[DATA_BUFFER_SIZE];
  884|    322|    int buffer_used = 0;
  885|       |
  886|    322|    size_t uncompressed_row_len = ctx->var_offset * 8;
  887|    322|    readstat_off_t uncompressed_offset = 0;
  888|    322|    unsigned char *uncompressed_row = NULL;
  889|       |
  890|    322|    struct sav_row_stream_s state = { 
  891|    322|        .missing_value = ctx->missing_double,
  892|    322|        .bias = ctx->bias,
  893|    322|        .bswap = ctx->bswap };
  894|       |
  895|    322|    if (uncompressed_row_len && (uncompressed_row = readstat_malloc(uncompressed_row_len)) == NULL) {
  ------------------
  |  Branch (895:9): [True: 322, False: 0]
  |  Branch (895:33): [True: 0, False: 322]
  ------------------
  896|      0|        retval = READSTAT_ERROR_MALLOC;
  897|      0|        goto done;
  898|      0|    }
  899|       |
  900|    613|    while (1) {
  ------------------
  |  Branch (900:12): [True: 613, Folded]
  ------------------
  901|    613|        retval = sav_update_progress(ctx);
  902|    613|        if (retval != READSTAT_OK)
  ------------------
  |  Branch (902:13): [True: 0, False: 613]
  ------------------
  903|      0|            goto done;
  904|       |
  905|    613|        buffer_used = io->read(buffer, sizeof(buffer), io->io_ctx);
  906|    613|        if (buffer_used == -1 || buffer_used == 0 || (buffer_used % 8) != 0)
  ------------------
  |  Branch (906:13): [True: 0, False: 613]
  |  Branch (906:34): [True: 239, False: 374]
  |  Branch (906:54): [True: 59, False: 315]
  ------------------
  907|    298|            goto done;
  908|       |
  909|    315|        state.status = SAV_ROW_STREAM_HAVE_DATA;
  910|    315|        data_offset = 0;
  911|       |
  912|  2.27M|        while (state.status != SAV_ROW_STREAM_NEED_DATA) {
  ------------------
  |  Branch (912:16): [True: 2.27M, False: 291]
  ------------------
  913|  2.27M|            state.next_in = &buffer[data_offset];
  914|  2.27M|            state.avail_in = buffer_used - data_offset;
  915|       |
  916|  2.27M|            state.next_out = &uncompressed_row[uncompressed_offset];
  917|  2.27M|            state.avail_out = uncompressed_row_len - uncompressed_offset;
  918|       |
  919|  2.27M|            sav_decompress_row(&state);
  920|       |
  921|  2.27M|            uncompressed_offset = uncompressed_row_len - state.avail_out;
  922|  2.27M|            data_offset = buffer_used - state.avail_in;
  923|       |
  924|  2.27M|            if (state.status == SAV_ROW_STREAM_FINISHED_ROW) {
  ------------------
  |  Branch (924:17): [True: 2.27M, False: 302]
  ------------------
  925|  2.27M|                retval = row_handler(uncompressed_row, uncompressed_row_len, ctx);
  926|  2.27M|                if (retval != READSTAT_OK)
  ------------------
  |  Branch (926:21): [True: 9, False: 2.27M]
  ------------------
  927|      9|                    goto done;
  928|       |
  929|  2.27M|                uncompressed_offset = 0;
  930|  2.27M|            }
  931|       |
  932|  2.27M|            if (state.status == SAV_ROW_STREAM_FINISHED_ALL)
  ------------------
  |  Branch (932:17): [True: 11, False: 2.27M]
  ------------------
  933|     11|                goto done;
  934|  2.27M|            if (ctx->row_limit > 0 && ctx->current_row == ctx->row_limit)
  ------------------
  |  Branch (934:17): [True: 221k, False: 2.05M]
  |  Branch (934:39): [True: 4, False: 221k]
  ------------------
  935|      4|                goto done;
  936|  2.27M|        }
  937|    315|    }
  938|       |
  939|    322|done:
  940|    322|    if (uncompressed_row)
  ------------------
  |  Branch (940:9): [True: 322, False: 0]
  ------------------
  941|    322|        free(uncompressed_row);
  942|       |
  943|    322|    return retval;
  944|    322|}
readstat_sav_read.c:sav_process_row:
  710|  2.27M|static readstat_error_t sav_process_row(unsigned char *buffer, size_t buffer_len, sav_ctx_t *ctx) {
  711|  2.27M|    if (ctx->row_offset) {
  ------------------
  |  Branch (711:9): [True: 0, False: 2.27M]
  ------------------
  712|      0|        ctx->row_offset--;
  713|      0|        return READSTAT_OK;
  714|      0|    }
  715|       |
  716|  2.27M|    readstat_error_t retval = READSTAT_OK;
  717|  2.27M|    double fp_value;
  718|  2.27M|    int offset = 0;
  719|  2.27M|    readstat_off_t data_offset = 0;
  720|  2.27M|    size_t raw_str_used = 0;
  721|  2.27M|    int segment_offset = 0;
  722|  2.27M|    int var_index = 0, col = 0;
  723|  2.27M|    int raw_str_is_utf8 = ctx->input_encoding && !strcmp(ctx->input_encoding, "UTF-8");
  ------------------
  |  Branch (723:27): [True: 842, False: 2.27M]
  |  Branch (723:50): [True: 793, False: 49]
  ------------------
  724|       |
  725|  4.58M|    while (data_offset < buffer_len && col < ctx->var_index && var_index < ctx->var_index) {
  ------------------
  |  Branch (725:12): [True: 2.62M, False: 1.95M]
  |  Branch (725:40): [True: 2.30M, False: 317k]
  |  Branch (725:64): [True: 2.30M, False: 48]
  ------------------
  726|  2.30M|        spss_varinfo_t *col_info = ctx->varinfo[col];
  727|  2.30M|        spss_varinfo_t *var_info = ctx->varinfo[var_index];
  728|  2.30M|        readstat_value_t value = { .type = var_info->type };
  729|  2.30M|        if (offset > 31) {
  ------------------
  |  Branch (729:13): [True: 1, False: 2.30M]
  ------------------
  730|      1|            retval = READSTAT_ERROR_PARSE;
  731|      1|            goto done;
  732|      1|        }
  733|  2.30M|        if (var_info->type == READSTAT_TYPE_STRING) {
  ------------------
  |  Branch (733:13): [True: 858k, False: 1.44M]
  ------------------
  734|       |            // If we're in the last column of a segment, only read 7 bytes
  735|       |            // (Segments contain 255 bytes but have room for 256)
  736|   858k|            size_t read_len = 8 - (offset == 31);
  737|   858k|            if (raw_str_used + read_len <= ctx->raw_string_len) {
  ------------------
  |  Branch (737:17): [True: 858k, False: 231]
  ------------------
  738|   858k|                if (raw_str_is_utf8) {
  ------------------
  |  Branch (738:21): [True: 1.14k, False: 857k]
  ------------------
  739|       |                    /* Skip null bytes, see https://github.com/tidyverse/haven/issues/560  */
  740|  1.14k|                    char c;
  741|  10.2k|                    for (int i=0; i<read_len; i++)
  ------------------
  |  Branch (741:35): [True: 9.14k, False: 1.14k]
  ------------------
  742|  9.14k|                        if ((c = buffer[data_offset+i]))
  ------------------
  |  Branch (742:29): [True: 5.27k, False: 3.86k]
  ------------------
  743|  5.27k|                            ctx->raw_string[raw_str_used++] = c;
  744|   857k|                } else {
  745|   857k|                    memcpy(ctx->raw_string + raw_str_used, &buffer[data_offset], read_len);
  746|   857k|                    raw_str_used += read_len;
  747|   857k|                }
  748|   858k|            }
  749|   858k|            if (++offset == col_info->width) {
  ------------------
  |  Branch (749:17): [True: 856k, False: 2.48k]
  ------------------
  750|   856k|                offset = 0;
  751|   856k|                col++;
  752|   856k|                segment_offset++;
  753|   856k|            }
  754|   858k|            if (segment_offset == var_info->n_segments) {
  ------------------
  |  Branch (754:17): [True: 855k, False: 3.15k]
  ------------------
  755|   855k|                if (!ctx->variables[var_info->index]->skip) {
  ------------------
  |  Branch (755:21): [True: 855k, False: 0]
  ------------------
  756|   855k|                    retval = readstat_convert(ctx->utf8_string, ctx->utf8_string_len, 
  757|   855k|                            ctx->raw_string, raw_str_used, ctx->converter);
  758|   855k|                    if (retval != READSTAT_OK)
  ------------------
  |  Branch (758:25): [True: 20, False: 855k]
  ------------------
  759|     20|                        goto done;
  760|   855k|                    value.v.string_value = ctx->utf8_string;
  761|   855k|                    if (ctx->handle.value(ctx->current_row, ctx->variables[var_info->index],
  ------------------
  |  Branch (761:25): [True: 0, False: 855k]
  ------------------
  762|   855k|                                value, ctx->user_ctx) != READSTAT_HANDLER_OK) {
  763|      0|                        retval = READSTAT_ERROR_USER_ABORT;
  764|      0|                        goto done;
  765|      0|                    }
  766|   855k|                }
  767|   855k|                raw_str_used = 0;
  768|   855k|                segment_offset = 0;
  769|   855k|                var_index += var_info->n_segments;
  770|   855k|            }
  771|  1.44M|        } else if (var_info->type == READSTAT_TYPE_DOUBLE) {
  ------------------
  |  Branch (771:20): [True: 1.44M, False: 0]
  ------------------
  772|  1.44M|            if (!ctx->variables[var_info->index]->skip) {
  ------------------
  |  Branch (772:17): [True: 1.44M, False: 0]
  ------------------
  773|  1.44M|                memcpy(&fp_value, &buffer[data_offset], 8);
  774|  1.44M|                if (ctx->bswap) {
  ------------------
  |  Branch (774:21): [True: 3.02k, False: 1.44M]
  ------------------
  775|  3.02k|                    fp_value = byteswap_double(fp_value);
  776|  3.02k|                }
  777|  1.44M|                value.v.double_value = fp_value;
  778|  1.44M|                sav_tag_missing_double(&value, ctx);
  779|  1.44M|                if (ctx->handle.value(ctx->current_row, ctx->variables[var_info->index],
  ------------------
  |  Branch (779:21): [True: 0, False: 1.44M]
  ------------------
  780|  1.44M|                            value, ctx->user_ctx) != READSTAT_HANDLER_OK) {
  781|      0|                    retval = READSTAT_ERROR_USER_ABORT;
  782|      0|                    goto done;
  783|      0|                }
  784|  1.44M|            }
  785|  1.44M|            var_index += var_info->n_segments;
  786|  1.44M|            col++;
  787|  1.44M|        }
  788|  2.30M|        data_offset += 8;
  789|  2.30M|    }
  790|  2.27M|    ctx->current_row++;
  791|  2.27M|done:
  792|  2.27M|    return retval;
  793|  2.27M|}
readstat_sav_read.c:sav_read_uncompressed_data:
  842|    870|        readstat_error_t (*row_handler)(unsigned char *, size_t, sav_ctx_t *)) {
  843|    870|    readstat_error_t retval = READSTAT_OK;
  844|    870|    readstat_io_t *io = ctx->io;
  845|    870|    unsigned char *buffer = NULL;
  846|    870|    size_t bytes_read = 0;
  847|    870|    size_t buffer_len = ctx->var_offset * 8;
  848|       |
  849|    870|    buffer = readstat_malloc(buffer_len);
  850|       |
  851|    870|    if (ctx->row_offset) {
  ------------------
  |  Branch (851:9): [True: 0, False: 870]
  ------------------
  852|      0|        if (io->seek(buffer_len * ctx->row_offset, READSTAT_SEEK_CUR, io->io_ctx) == -1) {
  ------------------
  |  Branch (852:13): [True: 0, False: 0]
  ------------------
  853|      0|            retval = READSTAT_ERROR_SEEK;
  854|      0|            goto done;
  855|      0|        }
  856|      0|        ctx->row_offset = 0;
  857|      0|    }
  858|       |
  859|  2.58k|    while (ctx->row_limit == -1 || ctx->current_row < ctx->row_limit) {
  ------------------
  |  Branch (859:12): [True: 0, False: 2.58k]
  |  Branch (859:36): [True: 2.32k, False: 260]
  ------------------
  860|  2.32k|        retval = sav_update_progress(ctx);
  861|  2.32k|        if (retval != READSTAT_OK)
  ------------------
  |  Branch (861:13): [True: 0, False: 2.32k]
  ------------------
  862|      0|            goto done;
  863|       |
  864|  2.32k|        if ((bytes_read = io->read(buffer, buffer_len, io->io_ctx)) != buffer_len)
  ------------------
  |  Branch (864:13): [True: 600, False: 1.72k]
  ------------------
  865|    600|            goto done;
  866|       |
  867|  1.72k|        retval = row_handler(buffer, buffer_len, ctx);
  868|  1.72k|        if (retval != READSTAT_OK)
  ------------------
  |  Branch (868:13): [True: 10, False: 1.71k]
  ------------------
  869|     10|            goto done;
  870|  1.72k|    }
  871|    870|done:
  872|    870|    if (buffer)
  ------------------
  |  Branch (872:9): [True: 870, False: 0]
  ------------------
  873|    870|        free(buffer);
  874|       |
  875|    870|    return retval;
  876|    870|}

spss_format:
   51|   286k|int spss_format(char *buffer, size_t len, spss_format_t *format) {
   52|   286k|    if (format->type < 0 
  ------------------
  |  Branch (52:9): [True: 0, False: 286k]
  ------------------
   53|   286k|            || format->type >= sizeof(spss_type_strings)/sizeof(spss_type_strings[0])
  ------------------
  |  Branch (53:16): [True: 6.53k, False: 279k]
  ------------------
   54|   279k|            || spss_type_strings[format->type][0] == '\0') {
  ------------------
  |  Branch (54:16): [True: 29.5k, False: 250k]
  ------------------
   55|  36.1k|        return 0;
   56|  36.1k|    }
   57|   250k|    char *string = spss_type_strings[format->type];
   58|       |
   59|   250k|    if (format->decimal_places || format->type == SPSS_FORMAT_TYPE_F) {
  ------------------
  |  |    6|   168k|#define SPSS_FORMAT_TYPE_F        5
  ------------------
  |  Branch (59:9): [True: 81.2k, False: 168k]
  |  Branch (59:35): [True: 522, False: 168k]
  ------------------
   60|  81.7k|        snprintf(buffer, len, "%s%d.%d", string, format->width, format->decimal_places);
   61|   168k|    } else if (format->width) {
  ------------------
  |  Branch (61:16): [True: 103k, False: 64.9k]
  ------------------
   62|   103k|        snprintf(buffer, len, "%s%d", string, format->width);
   63|   103k|    } else {
   64|  64.9k|        snprintf(buffer, len, "%s", string);
   65|  64.9k|    }
   66|       |
   67|   250k|    return 1;
   68|   286k|}
spss_varinfo_compare:
   70|   337k|int spss_varinfo_compare(const void *elem1, const void *elem2) {
   71|   337k|    int offset = *(int *)elem1;
   72|   337k|    const spss_varinfo_t *v = *(const spss_varinfo_t **)elem2;
   73|   337k|    if (offset < v->offset)
  ------------------
  |  Branch (73:9): [True: 159k, False: 177k]
  ------------------
   74|   159k|        return -1;
   75|   177k|    return (offset > v->offset);
   76|   337k|}
spss_varinfo_free:
   78|   462k|void spss_varinfo_free(spss_varinfo_t *info) {
   79|   462k|    if (info) {
  ------------------
  |  Branch (79:9): [True: 462k, False: 10]
  ------------------
   80|   462k|        if (info->label)
  ------------------
  |  Branch (80:13): [True: 1.11k, False: 461k]
  ------------------
   81|  1.11k|            free(info->label);
   82|   462k|        free(info);
   83|   462k|    }
   84|   462k|}
spss_missingness_for_info:
  127|   286k|readstat_missingness_t spss_missingness_for_info(spss_varinfo_t *info) {
  128|   286k|    readstat_missingness_t missingness;
  129|   286k|    memset(&missingness, '\0', sizeof(readstat_missingness_t));
  130|       |
  131|   286k|    if (info->missing_range) {
  ------------------
  |  Branch (131:9): [True: 1.69k, False: 284k]
  ------------------
  132|  1.69k|        missingness.missing_ranges_count++;
  133|  1.69k|        missingness.missing_ranges[0] = spss_boxed_missing_value(info, 0);
  134|  1.69k|        missingness.missing_ranges[1] = spss_boxed_missing_value(info, 1);
  135|       |
  136|  1.69k|        if (info->n_missing_values == 3) {
  ------------------
  |  Branch (136:13): [True: 752, False: 939]
  ------------------
  137|    752|            missingness.missing_ranges_count++;
  138|    752|            missingness.missing_ranges[2] = missingness.missing_ranges[3] = spss_boxed_missing_value(info, 2);
  139|    752|        }
  140|   284k|    } else if (info->n_missing_values > 0) {
  ------------------
  |  Branch (140:16): [True: 1.77k, False: 282k]
  ------------------
  141|  1.77k|        missingness.missing_ranges_count = info->n_missing_values;
  142|  1.77k|        int i=0;
  143|  5.50k|        for (i=0; i<info->n_missing_values; i++) {
  ------------------
  |  Branch (143:19): [True: 3.73k, False: 1.77k]
  ------------------
  144|  3.73k|            missingness.missing_ranges[2*i] = missingness.missing_ranges[2*i+1] = spss_boxed_missing_value(info, i);
  145|  3.73k|        }
  146|  1.77k|    }
  147|   286k|    return missingness;
  148|   286k|}
spss_init_variable_for_info:
  151|   286k|        iconv_t converter) {
  152|   286k|    readstat_variable_t *variable = calloc(1, sizeof(readstat_variable_t));
  153|       |
  154|   286k|    variable->index = info->index;
  155|   286k|    variable->index_after_skipping = index_after_skipping;
  156|   286k|    variable->type = info->type;
  157|   286k|    if (info->string_length) {
  ------------------
  |  Branch (157:9): [True: 852, False: 285k]
  ------------------
  158|    852|        variable->storage_width = info->string_length;
  159|   285k|    } else {
  160|   285k|        variable->storage_width = 8 * info->width;
  161|   285k|    }
  162|       |
  163|   286k|    if (info->longname[0]) {
  ------------------
  |  Branch (163:9): [True: 283k, False: 3.09k]
  ------------------
  164|   283k|        readstat_convert(variable->name, sizeof(variable->name),
  165|   283k|                info->longname, sizeof(info->longname), converter);
  166|   283k|    } else {
  167|  3.09k|        readstat_convert(variable->name, sizeof(variable->name),
  168|  3.09k|                info->name, sizeof(info->name), converter);
  169|  3.09k|    }
  170|   286k|    if (info->label) {
  ------------------
  |  Branch (170:9): [True: 871, False: 285k]
  ------------------
  171|    871|        snprintf(variable->label, sizeof(variable->label), "%s", info->label);
  172|    871|    }
  173|       |
  174|   286k|    spss_format(variable->format, sizeof(variable->format), &info->print_format);
  175|       |
  176|   286k|    variable->missingness = spss_missingness_for_info(info);
  177|   286k|    variable->measure = info->measure;
  178|   286k|    if (info->display_width) {
  ------------------
  |  Branch (178:9): [True: 2.68k, False: 283k]
  ------------------
  179|  2.68k|        variable->display_width = info->display_width;
  180|   283k|    } else {
  181|   283k|        variable->display_width = info->print_format.width;
  182|   283k|    }
  183|       |
  184|   286k|    return variable;
  185|   286k|}
spss_measure_to_readstat_measure:
  199|  7.06k|readstat_measure_t spss_measure_to_readstat_measure(uint32_t sav_measure) {
  200|  7.06k|    if (sav_measure == SAV_MEASURE_NOMINAL)
  ------------------
  |  |   47|  7.06k|#define SAV_MEASURE_NOMINAL     1
  ------------------
  |  Branch (200:9): [True: 228, False: 6.83k]
  ------------------
  201|    228|        return READSTAT_MEASURE_NOMINAL;
  202|  6.83k|    if (sav_measure == SAV_MEASURE_ORDINAL)
  ------------------
  |  |   48|  6.83k|#define SAV_MEASURE_ORDINAL     2
  ------------------
  |  Branch (202:9): [True: 576, False: 6.26k]
  ------------------
  203|    576|        return READSTAT_MEASURE_ORDINAL;
  204|  6.26k|    if (sav_measure == SAV_MEASURE_SCALE)
  ------------------
  |  |   49|  6.26k|#define SAV_MEASURE_SCALE       3
  ------------------
  |  Branch (204:9): [True: 107, False: 6.15k]
  ------------------
  205|    107|        return READSTAT_MEASURE_SCALE;
  206|  6.15k|    return READSTAT_MEASURE_UNKNOWN;
  207|  6.26k|}
spss_alignment_to_readstat_alignment:
  221|  7.06k|readstat_alignment_t spss_alignment_to_readstat_alignment(uint32_t sav_alignment) {
  222|  7.06k|    if (sav_alignment == SAV_ALIGNMENT_LEFT)
  ------------------
  |  |   51|  7.06k|#define SAV_ALIGNMENT_LEFT      0
  ------------------
  |  Branch (222:9): [True: 1.84k, False: 5.21k]
  ------------------
  223|  1.84k|        return READSTAT_ALIGNMENT_LEFT;
  224|  5.21k|    if (sav_alignment == SAV_ALIGNMENT_CENTER)
  ------------------
  |  |   53|  5.21k|#define SAV_ALIGNMENT_CENTER    2
  ------------------
  |  Branch (224:9): [True: 472, False: 4.74k]
  ------------------
  225|    472|        return READSTAT_ALIGNMENT_CENTER;
  226|  4.74k|    if (sav_alignment == SAV_ALIGNMENT_RIGHT)
  ------------------
  |  |   52|  4.74k|#define SAV_ALIGNMENT_RIGHT     1
  ------------------
  |  Branch (226:9): [True: 174, False: 4.57k]
  ------------------
  227|    174|        return READSTAT_ALIGNMENT_RIGHT;
  228|  4.57k|    return READSTAT_ALIGNMENT_UNKNOWN;
  229|  4.74k|}
readstat_spss.c:spss_boxed_missing_value:
  120|  7.86k|static readstat_value_t spss_boxed_missing_value(spss_varinfo_t *info, int i) {
  121|  7.86k|    if (info->type == READSTAT_TYPE_DOUBLE) {
  ------------------
  |  Branch (121:9): [True: 4.93k, False: 2.93k]
  ------------------
  122|  4.93k|        return spss_boxed_double_value(info->missing_double_values[i]);
  123|  4.93k|    }
  124|  2.93k|    return spss_boxed_string_value(info->missing_string_values[i]);
  125|  7.86k|}
readstat_spss.c:spss_boxed_double_value:
  103|  4.93k|static readstat_value_t spss_boxed_double_value(double fp_value) {
  104|  4.93k|    readstat_value_t value = {
  105|  4.93k|        .type = READSTAT_TYPE_DOUBLE,
  106|  4.93k|        .v = { .double_value = fp_value },
  107|       |        .is_system_missing = isnan(fp_value)
  108|  4.93k|    };
  109|  4.93k|    return value;
  110|  4.93k|}
readstat_spss.c:spss_boxed_string_value:
  112|  2.93k|static readstat_value_t spss_boxed_string_value(const char *string) {
  113|  2.93k|    readstat_value_t value = {
  114|  2.93k|        .type = READSTAT_TYPE_STRING,
  115|  2.93k|        .v = { .string_value = string }
  116|  2.93k|    };
  117|  2.93k|    return value;
  118|  2.93k|}

zsav_read_compressed_data:
   32|    371|        readstat_error_t (*row_handler)(unsigned char *, size_t, sav_ctx_t *)) {
   33|    371|    readstat_error_t retval = READSTAT_OK;
   34|    371|    readstat_io_t *io = ctx->io;
   35|    371|    readstat_off_t data_offset = 0;
   36|       |
   37|    371|    size_t uncompressed_row_len = ctx->var_offset * 8;
   38|    371|    readstat_off_t uncompressed_offset = 0;
   39|    371|    unsigned char *uncompressed_row = NULL;
   40|       |
   41|    371|    uLongf uncompressed_block_len = 0;
   42|    371|    unsigned char *compressed_block = NULL, *uncompressed_block = NULL;
   43|       |
   44|    371|    struct sav_row_stream_s state = { 
   45|    371|        .missing_value = ctx->missing_double,
   46|    371|        .bias = ctx->bias,
   47|    371|        .bswap = ctx->bswap };
   48|       |
   49|    371|    struct zheader zheader;
   50|    371|    struct ztrailer ztrailer;
   51|    371|    struct ztrailer_entry *ztrailer_entries = NULL;
   52|       |
   53|    371|    int n_blocks = 0;
   54|    371|    int block_i = 0;
   55|    371|    int i;
   56|       |
   57|    371|    if (io->read(&zheader, sizeof(struct zheader), io->io_ctx) < sizeof(struct zheader)) {
  ------------------
  |  Branch (57:9): [True: 33, False: 338]
  ------------------
   58|     33|        retval = READSTAT_ERROR_READ;
   59|     33|        goto cleanup;
   60|     33|    }
   61|       |
   62|    338|    zheader.zheader_ofs = ctx->bswap ? byteswap8(zheader.zheader_ofs) : zheader.zheader_ofs;
  ------------------
  |  Branch (62:27): [True: 201, False: 137]
  ------------------
   63|    338|    zheader.ztrailer_ofs = ctx->bswap ? byteswap8(zheader.ztrailer_ofs) : zheader.ztrailer_ofs;
  ------------------
  |  Branch (63:28): [True: 201, False: 137]
  ------------------
   64|    338|    zheader.ztrailer_len = ctx->bswap ? byteswap8(zheader.ztrailer_len) : zheader.ztrailer_len;
  ------------------
  |  Branch (64:28): [True: 201, False: 137]
  ------------------
   65|       |
   66|    338|    if (zheader.zheader_ofs != io->seek(0, READSTAT_SEEK_CUR, io->io_ctx) - sizeof(struct zheader)) {
  ------------------
  |  Branch (66:9): [True: 66, False: 272]
  ------------------
   67|     66|        retval = READSTAT_ERROR_PARSE;
   68|     66|        goto cleanup;
   69|     66|    }
   70|       |
   71|    272|    n_blocks = (zheader.ztrailer_len - 24) / 24;
   72|       |
   73|    272|    if (io->seek(zheader.ztrailer_ofs, READSTAT_SEEK_SET, io->io_ctx) == -1) {
  ------------------
  |  Branch (73:9): [True: 17, False: 255]
  ------------------
   74|     17|        retval = READSTAT_ERROR_SEEK;
   75|     17|        goto cleanup;
   76|     17|    }
   77|       |
   78|    255|    if (io->read(&ztrailer, sizeof(struct ztrailer), io->io_ctx) < sizeof(struct ztrailer)) {
  ------------------
  |  Branch (78:9): [True: 13, False: 242]
  ------------------
   79|     13|        retval = READSTAT_ERROR_READ;
   80|     13|        goto cleanup;
   81|     13|    }
   82|       |
   83|    242|    ztrailer.bias = ctx->bswap ? byteswap8(ztrailer.bias) : ztrailer.bias;
  ------------------
  |  Branch (83:21): [True: 131, False: 111]
  ------------------
   84|    242|    ztrailer.zero = ctx->bswap ? byteswap8(ztrailer.zero) : ztrailer.zero;
  ------------------
  |  Branch (84:21): [True: 131, False: 111]
  ------------------
   85|    242|    ztrailer.block_size = ctx->bswap ? byteswap4(ztrailer.block_size) : ztrailer.block_size;
  ------------------
  |  Branch (85:27): [True: 131, False: 111]
  ------------------
   86|    242|    ztrailer.n_blocks = ctx->bswap ? byteswap4(ztrailer.n_blocks) : ztrailer.n_blocks;
  ------------------
  |  Branch (86:25): [True: 131, False: 111]
  ------------------
   87|       |
   88|    242|    if (n_blocks != ztrailer.n_blocks) {
  ------------------
  |  Branch (88:9): [True: 29, False: 213]
  ------------------
   89|     29|        retval = READSTAT_ERROR_PARSE;
   90|     29|        goto cleanup;
   91|     29|    }
   92|       |
   93|    213|    if (n_blocks && (ztrailer_entries = readstat_malloc(n_blocks * sizeof(struct ztrailer_entry))) == NULL) {
  ------------------
  |  Branch (93:9): [True: 210, False: 3]
  |  Branch (93:21): [True: 23, False: 187]
  ------------------
   94|     23|        retval = READSTAT_ERROR_MALLOC;
   95|     23|        goto cleanup;
   96|     23|    }
   97|       |
   98|    190|    if (io->read(ztrailer_entries, n_blocks * sizeof(struct ztrailer_entry), io->io_ctx) < 
  ------------------
  |  Branch (98:9): [True: 16, False: 174]
  ------------------
   99|    190|            n_blocks * sizeof(struct ztrailer_entry)) {
  100|     16|        retval = READSTAT_ERROR_READ;
  101|     16|        goto cleanup;
  102|     16|    }
  103|       |
  104|  10.3k|    for (i=0; i<n_blocks; i++) {
  ------------------
  |  Branch (104:15): [True: 10.1k, False: 174]
  ------------------
  105|  10.1k|        struct ztrailer_entry *entry = &ztrailer_entries[i];
  106|       |
  107|  10.1k|        entry->uncompressed_ofs = ctx->bswap ? byteswap8(entry->uncompressed_ofs) : entry->uncompressed_ofs;
  ------------------
  |  Branch (107:35): [True: 8.65k, False: 1.48k]
  ------------------
  108|  10.1k|        entry->compressed_ofs = ctx->bswap ? byteswap8(entry->compressed_ofs) : entry->compressed_ofs;
  ------------------
  |  Branch (108:33): [True: 8.65k, False: 1.48k]
  ------------------
  109|  10.1k|        entry->uncompressed_size = ctx->bswap ? byteswap4(entry->uncompressed_size) : entry->uncompressed_size;
  ------------------
  |  Branch (109:36): [True: 8.65k, False: 1.48k]
  ------------------
  110|  10.1k|        entry->compressed_size = ctx->bswap ? byteswap4(entry->compressed_size) : entry->compressed_size;
  ------------------
  |  Branch (110:34): [True: 8.65k, False: 1.48k]
  ------------------
  111|  10.1k|    }
  112|       |
  113|    174|    if (uncompressed_row_len && (uncompressed_row = readstat_malloc(uncompressed_row_len)) == NULL) {
  ------------------
  |  Branch (113:9): [True: 174, False: 0]
  |  Branch (113:33): [True: 0, False: 174]
  ------------------
  114|      0|        retval = READSTAT_ERROR_MALLOC;
  115|      0|        goto cleanup;
  116|      0|    }
  117|       |
  118|    174|    while (1) {
  ------------------
  |  Branch (118:12): [True: 174, Folded]
  ------------------
  119|    174|        if (block_i == n_blocks)
  ------------------
  |  Branch (119:13): [True: 3, False: 171]
  ------------------
  120|      3|            goto cleanup;
  121|       |
  122|    171|        struct ztrailer_entry *entry = &ztrailer_entries[block_i];
  123|    171|        if (io->seek(entry->compressed_ofs, READSTAT_SEEK_SET, io->io_ctx) == -1) {
  ------------------
  |  Branch (123:13): [True: 25, False: 146]
  ------------------
  124|     25|            retval = READSTAT_ERROR_SEEK;
  125|     25|            goto cleanup;
  126|     25|        }
  127|    146|        if ((compressed_block = readstat_realloc(compressed_block, entry->compressed_size)) == NULL) {
  ------------------
  |  Branch (127:13): [True: 30, False: 116]
  ------------------
  128|     30|            retval = READSTAT_ERROR_MALLOC;
  129|     30|            goto cleanup;
  130|     30|        }
  131|    116|        if (io->read(compressed_block, entry->compressed_size, io->io_ctx) != entry->compressed_size) {
  ------------------
  |  Branch (131:13): [True: 39, False: 77]
  ------------------
  132|     39|            retval = READSTAT_ERROR_READ;
  133|     39|            goto cleanup;
  134|     39|        }
  135|       |
  136|     77|        uncompressed_block_len = entry->uncompressed_size;
  137|     77|        if ((uncompressed_block = readstat_realloc(uncompressed_block, uncompressed_block_len)) == NULL) {
  ------------------
  |  Branch (137:13): [True: 6, False: 71]
  ------------------
  138|      6|            retval = READSTAT_ERROR_MALLOC;
  139|      6|            goto cleanup;
  140|      6|        }
  141|     71|        int status = uncompress(uncompressed_block, &uncompressed_block_len,
  142|     71|                compressed_block, entry->compressed_size);
  143|     71|        if (status != Z_OK || uncompressed_block_len != entry->uncompressed_size) {
  ------------------
  |  Branch (143:13): [True: 4, False: 67]
  |  Branch (143:31): [True: 21, False: 46]
  ------------------
  144|     25|            retval = READSTAT_ERROR_PARSE;
  145|     25|            goto cleanup;
  146|     25|        }
  147|       |
  148|     46|        block_i++;
  149|     46|        state.status = SAV_ROW_STREAM_HAVE_DATA;
  150|     46|        data_offset = 0;
  151|       |
  152|    260|        while (state.status != SAV_ROW_STREAM_NEED_DATA) {
  ------------------
  |  Branch (152:16): [True: 260, False: 0]
  ------------------
  153|    260|            state.next_in = &uncompressed_block[data_offset];
  154|    260|            state.avail_in = uncompressed_block_len - data_offset;
  155|       |
  156|    260|            state.next_out = &uncompressed_row[uncompressed_offset];
  157|    260|            state.avail_out = uncompressed_row_len - uncompressed_offset;
  158|       |
  159|    260|            sav_decompress_row(&state);
  160|       |
  161|    260|            uncompressed_offset = uncompressed_row_len - state.avail_out;
  162|    260|            data_offset = uncompressed_block_len - state.avail_in;
  163|       |
  164|    260|            if (state.status == SAV_ROW_STREAM_FINISHED_ROW) {
  ------------------
  |  Branch (164:17): [True: 221, False: 39]
  ------------------
  165|    221|                retval = row_handler(uncompressed_row, uncompressed_row_len, ctx);
  166|    221|                if (retval != READSTAT_OK)
  ------------------
  |  Branch (166:21): [True: 2, False: 219]
  ------------------
  167|      2|                    goto cleanup;
  168|       |
  169|    219|                uncompressed_offset = 0;
  170|    219|            }
  171|       |
  172|    258|            if (state.status == SAV_ROW_STREAM_FINISHED_ALL)
  ------------------
  |  Branch (172:17): [True: 39, False: 219]
  ------------------
  173|     39|                goto cleanup;
  174|    219|            if (ctx->row_limit > 0 && ctx->current_row == ctx->row_limit)
  ------------------
  |  Branch (174:17): [True: 134, False: 85]
  |  Branch (174:39): [True: 5, False: 129]
  ------------------
  175|      5|                goto cleanup;
  176|    219|        }
  177|     46|    }
  178|       |
  179|    371|cleanup:
  180|    371|    if (uncompressed_row)
  ------------------
  |  Branch (180:9): [True: 174, False: 197]
  ------------------
  181|    174|        free(uncompressed_row);
  182|    371|    if (ztrailer_entries)
  ------------------
  |  Branch (182:9): [True: 187, False: 184]
  ------------------
  183|    187|        free(ztrailer_entries);
  184|    371|    if (compressed_block)
  ------------------
  |  Branch (184:9): [True: 116, False: 255]
  ------------------
  185|    116|        free(compressed_block);
  186|    371|    if (uncompressed_block)
  ------------------
  |  Branch (186:9): [True: 71, False: 300]
  ------------------
  187|     71|        free(uncompressed_block);
  188|       |
  189|    371|    return retval;
  190|    174|}

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

