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

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

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

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

readstat_convert:
    7|  2.15M|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|  22.6M|    while (src_len && (src[src_len-1] == ' ' || src[src_len-1] == '\0')) {
  ------------------
  |  Branch (10:12): [True: 22.5M, False: 22.7k]
  |  Branch (10:24): [True: 2.58M, False: 19.9M]
  |  Branch (10:49): [True: 17.8M, False: 2.12M]
  ------------------
   11|  20.4M|        src_len--;
   12|  20.4M|    }
   13|  2.15M|    if (dst_len == 0) {
  ------------------
  |  Branch (13:9): [True: 0, False: 2.15M]
  ------------------
   14|      0|        return READSTAT_ERROR_CONVERT_LONG_STRING;
   15|  2.15M|    } else if (converter) {
  ------------------
  |  Branch (15:16): [True: 1.73k, False: 2.14M]
  ------------------
   16|  1.73k|        size_t dst_left = dst_len - 1;
   17|  1.73k|        char *dst_end = dst;
   18|  1.73k|        size_t status = iconv(converter, (readstat_iconv_inbuf_t)&src, &src_len, &dst_end, &dst_left);
   19|  1.73k|        if (status == (size_t)-1) {
  ------------------
  |  Branch (19:13): [True: 860, False: 875]
  ------------------
   20|    860|            if (errno == E2BIG) {
  ------------------
  |  Branch (20:17): [True: 1, False: 859]
  ------------------
   21|      1|                return READSTAT_ERROR_CONVERT_LONG_STRING;
   22|    859|            } else if (errno == EILSEQ) {
  ------------------
  |  Branch (22:24): [True: 468, False: 391]
  ------------------
   23|    468|                return READSTAT_ERROR_CONVERT_BAD_STRING;
   24|    468|            } else if (errno != EINVAL) { /* EINVAL indicates improper truncation; accept it */
  ------------------
  |  Branch (24:24): [True: 0, False: 391]
  ------------------
   25|      0|                return READSTAT_ERROR_CONVERT;
   26|      0|            }
   27|    860|        }
   28|  1.26k|        dst[dst_len - dst_left - 1] = '\0';
   29|  2.14M|    } else if (src_len + 1 > dst_len) {
  ------------------
  |  Branch (29:16): [True: 22, False: 2.14M]
  ------------------
   30|     22|        return READSTAT_ERROR_CONVERT_LONG_STRING;
   31|  2.14M|    } else {
   32|  2.14M|        memcpy(dst, src, src_len);
   33|  2.14M|        dst[src_len] = '\0';
   34|  2.14M|    }
   35|  2.14M|    return READSTAT_OK;
   36|  2.15M|}

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

readstat_malloc:
   10|  48.3k|void *readstat_malloc(size_t len) {
   11|  48.3k|    if (len > MAX_MALLOC_SIZE || len == 0) {
  ------------------
  |  |    3|  96.7k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
  |  Branch (11:9): [True: 241, False: 48.1k]
  |  Branch (11:34): [True: 1.16k, False: 46.9k]
  ------------------
   12|  1.40k|        return NULL;
   13|  1.40k|    }
   14|  46.9k|    return malloc(len);
   15|  48.3k|}
readstat_calloc:
   17|   407k|void *readstat_calloc(size_t count, size_t size) {
   18|   407k|    if (count > MAX_MALLOC_SIZE || size > MAX_MALLOC_SIZE || count * size > MAX_MALLOC_SIZE) {
  ------------------
  |  |    3|   814k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
                  if (count > MAX_MALLOC_SIZE || size > MAX_MALLOC_SIZE || count * size > MAX_MALLOC_SIZE) {
  ------------------
  |  |    3|   814k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
                  if (count > MAX_MALLOC_SIZE || size > MAX_MALLOC_SIZE || count * size > MAX_MALLOC_SIZE) {
  ------------------
  |  |    3|   407k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
  |  Branch (18:9): [True: 27, False: 407k]
  |  Branch (18:36): [True: 0, False: 407k]
  |  Branch (18:62): [True: 33, False: 407k]
  ------------------
   19|     60|        return NULL;
   20|     60|    }
   21|   407k|    if (count == 0 || size == 0) {
  ------------------
  |  Branch (21:9): [True: 27, False: 407k]
  |  Branch (21:23): [True: 0, False: 407k]
  ------------------
   22|     27|        return NULL;
   23|     27|    }
   24|   407k|    return calloc(count, size);
   25|   407k|}
readstat_realloc:
   27|  8.16k|void *readstat_realloc(void *ptr, size_t len) {
   28|  8.16k|    if (len > MAX_MALLOC_SIZE || len == 0) {
  ------------------
  |  |    3|  16.3k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
  |  Branch (28:9): [True: 113, False: 8.04k]
  |  Branch (28:34): [True: 1, False: 8.04k]
  ------------------
   29|    114|        if (ptr)
  ------------------
  |  Branch (29:13): [True: 62, False: 52]
  ------------------
   30|     62|            free(ptr);
   31|    114|        return NULL;
   32|    114|    }
   33|  8.04k|    return realloc(ptr, len);
   34|  8.16k|}

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

sav_ctx_init:
   23|  5.90k|sav_ctx_t *sav_ctx_init(sav_file_header_record_t *header, readstat_io_t *io) {
   24|  5.90k|    sav_ctx_t *ctx = readstat_calloc(1, sizeof(sav_ctx_t));
   25|  5.90k|    if (ctx == NULL) {
  ------------------
  |  Branch (25:9): [True: 0, False: 5.90k]
  ------------------
   26|      0|        return NULL;
   27|      0|    }
   28|       |
   29|  5.90k|    if (memcmp(&header->rec_type, "$FL2", 4) == 0) {
  ------------------
  |  Branch (29:9): [True: 3.48k, False: 2.42k]
  ------------------
   30|  3.48k|        ctx->format_version = 2;
   31|  3.48k|    } else if (memcmp(&header->rec_type, "$FL3", 4) == 0) {
  ------------------
  |  Branch (31:16): [True: 2.39k, False: 31]
  ------------------
   32|  2.39k|        ctx->format_version = 3;
   33|  2.39k|    } else {
   34|     31|        sav_ctx_free(ctx);
   35|     31|        return NULL;
   36|     31|    }
   37|       |    
   38|  5.87k|    ctx->bswap = !(header->layout_code == 2 || header->layout_code == 3);
  ------------------
  |  Branch (38:20): [True: 3.81k, False: 2.05k]
  |  Branch (38:48): [True: 268, False: 1.79k]
  ------------------
   39|  5.87k|    ctx->endianness = (machine_is_little_endian() ^ ctx->bswap) ? READSTAT_ENDIAN_LITTLE : READSTAT_ENDIAN_BIG;
  ------------------
  |  Branch (39:23): [True: 4.08k, False: 1.79k]
  ------------------
   40|       |
   41|  5.87k|    if (header->compression == 1 || byteswap4(header->compression) == 1) {
  ------------------
  |  Branch (41:9): [True: 404, False: 5.46k]
  |  Branch (41:37): [True: 144, False: 5.32k]
  ------------------
   42|    548|        ctx->compression = READSTAT_COMPRESS_ROWS;
   43|  5.32k|    } else if (header->compression == 2 || byteswap4(header->compression) == 2) {
  ------------------
  |  Branch (43:16): [True: 470, False: 4.85k]
  |  Branch (43:44): [True: 105, False: 4.74k]
  ------------------
   44|    575|        ctx->compression = READSTAT_COMPRESS_BINARY;
   45|    575|    }
   46|  5.87k|    ctx->record_count = ctx->bswap ? byteswap4(header->ncases) : header->ncases;
  ------------------
  |  Branch (46:25): [True: 1.79k, False: 4.08k]
  ------------------
   47|  5.87k|    ctx->fweight_index = ctx->bswap ? byteswap4(header->weight_index) : header->weight_index;
  ------------------
  |  Branch (47:26): [True: 1.79k, False: 4.08k]
  ------------------
   48|       |
   49|  5.87k|    ctx->missing_double = SAV_MISSING_DOUBLE;
  ------------------
  |  |   43|  5.87k|#define SAV_MISSING_DOUBLE   0xFFEFFFFFFFFFFFFFUL
  ------------------
   50|  5.87k|    ctx->lowest_double = SAV_LOWEST_DOUBLE;
  ------------------
  |  |   44|  5.87k|#define SAV_LOWEST_DOUBLE    0xFFEFFFFFFFFFFFFEUL
  ------------------
   51|  5.87k|    ctx->highest_double = SAV_HIGHEST_DOUBLE;
  ------------------
  |  |   42|  5.87k|#define SAV_HIGHEST_DOUBLE   0x7FEFFFFFFFFFFFFFUL
  ------------------
   52|       |    
   53|  5.87k|    ctx->bias = ctx->bswap ? byteswap_double(header->bias) : header->bias;
  ------------------
  |  Branch (53:17): [True: 1.79k, False: 4.08k]
  ------------------
   54|       |    
   55|  5.87k|    ctx->varinfo_capacity = SAV_VARINFO_INITIAL_CAPACITY;
  ------------------
  |  |   21|  5.87k|#define SAV_VARINFO_INITIAL_CAPACITY  512
  ------------------
   56|       |    
   57|  5.87k|    if ((ctx->varinfo = readstat_calloc(ctx->varinfo_capacity, sizeof(spss_varinfo_t *))) == NULL) {
  ------------------
  |  Branch (57:9): [True: 0, False: 5.87k]
  ------------------
   58|      0|        sav_ctx_free(ctx);
   59|      0|        return NULL;
   60|      0|    }
   61|       |
   62|  5.87k|    ctx->mr_sets = NULL;
   63|       |
   64|  5.87k|    ctx->io = io;
   65|       |    
   66|  5.87k|    return ctx;
   67|  5.87k|}
sav_ctx_free:
   69|  5.90k|void sav_ctx_free(sav_ctx_t *ctx) {
   70|  5.90k|    if (ctx->varinfo) {
  ------------------
  |  Branch (70:9): [True: 5.87k, False: 31]
  ------------------
   71|  5.87k|        int i;
   72|   398k|        for (i=0; i<ctx->var_index; i++) {
  ------------------
  |  Branch (72:19): [True: 392k, False: 5.87k]
  ------------------
   73|   392k|            spss_varinfo_free(ctx->varinfo[i]);
   74|   392k|        }
   75|  5.87k|        free(ctx->varinfo);
   76|  5.87k|    }
   77|  5.90k|    if (ctx->variables) {
  ------------------
  |  Branch (77:9): [True: 1.90k, False: 3.99k]
  ------------------
   78|  1.90k|        int i;
   79|   258k|        for (i=0; i<ctx->var_count; i++) {
  ------------------
  |  Branch (79:19): [True: 256k, False: 1.90k]
  ------------------
   80|   256k|            if (ctx->variables[i])
  ------------------
  |  Branch (80:17): [True: 254k, False: 2.38k]
  ------------------
   81|   254k|                free(ctx->variables[i]);
   82|   256k|        }
   83|  1.90k|        free(ctx->variables);
   84|  1.90k|    }
   85|  5.90k|    if (ctx->raw_string)
  ------------------
  |  Branch (85:9): [True: 1.84k, False: 4.06k]
  ------------------
   86|  1.84k|        free(ctx->raw_string);
   87|  5.90k|    if (ctx->utf8_string)
  ------------------
  |  Branch (87:9): [True: 1.83k, False: 4.06k]
  ------------------
   88|  1.83k|        free(ctx->utf8_string);
   89|  5.90k|    if (ctx->converter)
  ------------------
  |  Branch (89:9): [True: 100, False: 5.80k]
  ------------------
   90|    100|        iconv_close(ctx->converter);
   91|  5.90k|    if (ctx->variable_display_values) {
  ------------------
  |  Branch (91:9): [True: 234, False: 5.66k]
  ------------------
   92|    234|        free(ctx->variable_display_values);
   93|    234|    }
   94|  5.90k|    if (ctx->mr_sets) {
  ------------------
  |  Branch (94:9): [True: 226, False: 5.67k]
  ------------------
   95|    813|        for (size_t i = 0; i < ctx->multiple_response_sets_length; i++) {
  ------------------
  |  Branch (95:28): [True: 587, False: 226]
  ------------------
   96|    587|            if (ctx->mr_sets[i].name) {
  ------------------
  |  Branch (96:17): [True: 587, False: 0]
  ------------------
   97|    587|                free(ctx->mr_sets[i].name);
   98|    587|            }
   99|    587|            if (ctx->mr_sets[i].label) {
  ------------------
  |  Branch (99:17): [True: 587, False: 0]
  ------------------
  100|    587|                free(ctx->mr_sets[i].label);
  101|    587|            }
  102|    587|            if (ctx->mr_sets[i].subvariables) {
  ------------------
  |  Branch (102:17): [True: 433, False: 154]
  ------------------
  103|  4.43k|                for (size_t j = 0; j < ctx->mr_sets[i].num_subvars; j++) {
  ------------------
  |  Branch (103:36): [True: 3.99k, False: 433]
  ------------------
  104|  3.99k|                    if (ctx->mr_sets[i].subvariables[j]) {
  ------------------
  |  Branch (104:25): [True: 3.99k, False: 0]
  ------------------
  105|  3.99k|                        free(ctx->mr_sets[i].subvariables[j]);
  106|  3.99k|                    }
  107|  3.99k|                }
  108|    433|                free(ctx->mr_sets[i].subvariables);
  109|    433|            }
  110|    587|        }
  111|    226|        free(ctx->mr_sets);
  112|    226|    }
  113|  5.90k|    free(ctx);
  114|  5.90k|}

sav_decompress_row:
   77|  2.18M|void sav_decompress_row(struct sav_row_stream_s *state) {
   78|  2.18M|    double fp_value;
   79|  2.18M|    uint64_t missing_value = state->bswap ? byteswap8(state->missing_value) : state->missing_value;
  ------------------
  |  Branch (79:30): [True: 338k, False: 1.84M]
  ------------------
   80|  2.18M|    int i = 8 - state->i;
   81|  2.54M|    while (1) {
  ------------------
  |  Branch (81:12): [True: 2.54M, Folded]
  ------------------
   82|  2.54M|        if (i == 8) {
  ------------------
  |  Branch (82:13): [True: 626k, False: 1.91M]
  ------------------
   83|   626k|            if (state->avail_in < 8) {
  ------------------
  |  Branch (83:17): [True: 262, False: 626k]
  ------------------
   84|    262|                state->status = SAV_ROW_STREAM_NEED_DATA;
   85|    262|                goto done;
   86|    262|            }
   87|       |
   88|   626k|            memcpy(state->chunk, state->next_in, 8);
   89|   626k|            state->next_in += 8;
   90|   626k|            state->avail_in -= 8;
   91|   626k|            i = 0;
   92|   626k|        }
   93|       |
   94|  5.36M|        while (i<8) {
  ------------------
  |  Branch (94:16): [True: 5.00M, False: 357k]
  ------------------
   95|  5.00M|            switch (state->chunk[i]) {
   96|  2.51M|                case 0:
  ------------------
  |  Branch (96:17): [True: 2.51M, False: 2.49M]
  ------------------
   97|  2.51M|                    break;
   98|     54|                case 252:
  ------------------
  |  Branch (98:17): [True: 54, False: 5.00M]
  ------------------
   99|     54|                    state->status = SAV_ROW_STREAM_FINISHED_ALL;
  100|     54|                    goto done;
  101|   113k|                case 253:
  ------------------
  |  Branch (101:17): [True: 113k, False: 4.89M]
  ------------------
  102|   113k|                    if (state->avail_in < 8) {
  ------------------
  |  Branch (102:25): [True: 56, False: 113k]
  ------------------
  103|     56|                        state->status = SAV_ROW_STREAM_NEED_DATA;
  104|     56|                        goto done;
  105|     56|                    }
  106|   113k|                    memcpy(state->next_out, state->next_in, 8);
  107|   113k|                    state->next_out += 8;
  108|   113k|                    state->avail_out -= 8;
  109|   113k|                    state->next_in += 8;
  110|   113k|                    state->avail_in -= 8;
  111|   113k|                    break;
  112|  1.73k|                case 254:
  ------------------
  |  Branch (112:17): [True: 1.73k, False: 5.00M]
  ------------------
  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|  83.8k|                case 255:
  ------------------
  |  Branch (117:17): [True: 83.8k, False: 4.92M]
  ------------------
  118|  83.8k|                    memcpy(state->next_out, &missing_value, sizeof(uint64_t));
  119|  83.8k|                    state->next_out += 8;
  120|  83.8k|                    state->avail_out -= 8;
  121|  83.8k|                    break;
  122|  2.29M|                default:
  ------------------
  |  Branch (122:17): [True: 2.29M, False: 2.71M]
  ------------------
  123|  2.29M|                    fp_value = state->chunk[i] - state->bias;
  124|  2.29M|                    fp_value = state->bswap ? byteswap_double(fp_value) : fp_value;
  ------------------
  |  Branch (124:32): [True: 313k, False: 1.98M]
  ------------------
  125|  2.29M|                    memcpy(state->next_out, &fp_value, sizeof(double));
  126|  2.29M|                    state->next_out += 8;
  127|  2.29M|                    state->avail_out -= 8;
  128|  2.29M|                    break;
  129|  5.00M|            }
  130|  5.00M|            i++;
  131|  5.00M|            if (state->avail_out < 8) {
  ------------------
  |  Branch (131:17): [True: 2.18M, False: 2.82M]
  ------------------
  132|  2.18M|                state->status = SAV_ROW_STREAM_FINISHED_ROW;
  133|  2.18M|                goto done;
  134|  2.18M|            }
  135|  5.00M|        }
  136|  2.54M|    }
  137|  2.18M|done:
  138|  2.18M|    state->i = 8 - i;
  139|  2.18M|}

sav_parse_long_variable_names_record:
  284|  2.82k|readstat_error_t sav_parse_long_variable_names_record(void *data, int count, sav_ctx_t *ctx) {
  285|  2.82k|    unsigned char *c_data = (unsigned char *)data;
  286|  2.82k|    int var_count = count_vars(ctx);
  287|  2.82k|    readstat_error_t retval = READSTAT_OK;
  288|       |
  289|  2.82k|    char temp_key[8+1];
  290|  2.82k|    char temp_val[64+1];
  291|  2.82k|    unsigned char *str_start = NULL;
  292|  2.82k|    size_t str_len = 0;
  293|       |    
  294|  2.82k|    char error_buf[8192];
  295|  2.82k|    unsigned char *p = c_data;
  296|  2.82k|    unsigned char *pe = c_data + count;
  297|       |
  298|  2.82k|    varlookup_t *table = build_lookup_table(var_count, ctx);
  299|       |
  300|  2.82k|    unsigned char *eof = pe;
  301|       |
  302|  2.82k|    int cs;
  303|       |
  304|       |    
  305|  2.82k|#line 306 "src/spss/readstat_sav_parse.c"
  306|  2.82k|	{
  307|  2.82k|	cs = sav_long_variable_parse_start;
  308|  2.82k|	}
  309|       |
  310|  2.82k|#line 311 "src/spss/readstat_sav_parse.c"
  311|  2.82k|	{
  312|  2.82k|	int _klen;
  313|  2.82k|	unsigned int _trans;
  314|  2.82k|	const char *_acts;
  315|  2.82k|	unsigned int _nacts;
  316|  2.82k|	const unsigned char *_keys;
  317|       |
  318|  2.82k|	if ( p == pe )
  ------------------
  |  Branch (318:7): [True: 0, False: 2.82k]
  ------------------
  319|      0|		goto _test_eof;
  320|  2.82k|	if ( cs == 0 )
  ------------------
  |  Branch (320:7): [True: 0, False: 2.82k]
  ------------------
  321|      0|		goto _out;
  322|  27.1k|_resume:
  323|  27.1k|	_keys = _sav_long_variable_parse_trans_keys + _sav_long_variable_parse_key_offsets[cs];
  324|  27.1k|	_trans = _sav_long_variable_parse_index_offsets[cs];
  325|       |
  326|  27.1k|	_klen = _sav_long_variable_parse_single_lengths[cs];
  327|  27.1k|	if ( _klen > 0 ) {
  ------------------
  |  Branch (327:7): [True: 27.1k, False: 0]
  ------------------
  328|  27.1k|		const unsigned char *_lower = _keys;
  329|  27.1k|		const unsigned char *_mid;
  330|  27.1k|		const unsigned char *_upper = _keys + _klen - 1;
  331|  62.0k|		while (1) {
  ------------------
  |  Branch (331:10): [True: 62.0k, Folded]
  ------------------
  332|  62.0k|			if ( _upper < _lower )
  ------------------
  |  Branch (332:9): [True: 20.1k, False: 41.9k]
  ------------------
  333|  20.1k|				break;
  334|       |
  335|  41.9k|			_mid = _lower + ((_upper-_lower) >> 1);
  336|  41.9k|			if ( (*p) < *_mid )
  ------------------
  |  Branch (336:9): [True: 22.5k, False: 19.4k]
  ------------------
  337|  22.5k|				_upper = _mid - 1;
  338|  19.4k|			else if ( (*p) > *_mid )
  ------------------
  |  Branch (338:14): [True: 12.4k, False: 6.94k]
  ------------------
  339|  12.4k|				_lower = _mid + 1;
  340|  6.94k|			else {
  341|  6.94k|				_trans += (unsigned int)(_mid - _keys);
  342|  6.94k|				goto _match;
  343|  6.94k|			}
  344|  41.9k|		}
  345|  20.1k|		_keys += _klen;
  346|  20.1k|		_trans += _klen;
  347|  20.1k|	}
  348|       |
  349|  20.1k|	_klen = _sav_long_variable_parse_range_lengths[cs];
  350|  20.1k|	if ( _klen > 0 ) {
  ------------------
  |  Branch (350:7): [True: 20.1k, False: 3]
  ------------------
  351|  20.1k|		const unsigned char *_lower = _keys;
  352|  20.1k|		const unsigned char *_mid;
  353|  20.1k|		const unsigned char *_upper = _keys + (_klen<<1) - 2;
  354|  53.3k|		while (1) {
  ------------------
  |  Branch (354:10): [True: 53.3k, Folded]
  ------------------
  355|  53.3k|			if ( _upper < _lower )
  ------------------
  |  Branch (355:9): [True: 19.9k, False: 33.3k]
  ------------------
  356|  19.9k|				break;
  357|       |
  358|  33.3k|			_mid = _lower + (((_upper-_lower) >> 1) & ~1);
  359|  33.3k|			if ( (*p) < _mid[0] )
  ------------------
  |  Branch (359:9): [True: 7.03k, False: 26.3k]
  ------------------
  360|  7.03k|				_upper = _mid - 2;
  361|  26.3k|			else if ( (*p) > _mid[1] )
  ------------------
  |  Branch (361:14): [True: 26.1k, False: 177]
  ------------------
  362|  26.1k|				_lower = _mid + 2;
  363|    177|			else {
  364|    177|				_trans += (unsigned int)((_mid - _keys)>>1);
  365|    177|				goto _match;
  366|    177|			}
  367|  33.3k|		}
  368|  19.9k|		_trans += _klen;
  369|  19.9k|	}
  370|       |
  371|  27.1k|_match:
  372|  27.1k|	_trans = _sav_long_variable_parse_indicies[_trans];
  373|  27.1k|	cs = _sav_long_variable_parse_trans_targs[_trans];
  374|       |
  375|  27.1k|	if ( _sav_long_variable_parse_trans_actions[_trans] == 0 )
  ------------------
  |  Branch (375:7): [True: 10.8k, False: 16.2k]
  ------------------
  376|  10.8k|		goto _again;
  377|       |
  378|  16.2k|	_acts = _sav_long_variable_parse_actions + _sav_long_variable_parse_trans_actions[_trans];
  379|  16.2k|	_nacts = (unsigned int) *_acts++;
  380|  41.8k|	while ( _nacts-- > 0 )
  ------------------
  |  Branch (380:10): [True: 25.5k, False: 16.2k]
  ------------------
  381|  25.5k|	{
  382|  25.5k|		switch ( *_acts++ )
  ------------------
  |  Branch (382:12): [True: 25.5k, False: 0]
  ------------------
  383|  25.5k|		{
  384|  4.65k|	case 0:
  ------------------
  |  Branch (384:2): [True: 4.65k, False: 20.8k]
  ------------------
  385|  4.65k|#line 13 "src/spss/readstat_sav_parse.rl"
  386|  4.65k|	{
  387|  4.65k|        memcpy(temp_key, str_start, str_len);
  388|  4.65k|        temp_key[str_len] = '\0';
  389|  4.65k|    }
  390|  4.65k|	break;
  391|  4.70k|	case 1:
  ------------------
  |  Branch (391:2): [True: 4.70k, False: 20.8k]
  ------------------
  392|  4.70k|#line 20 "src/spss/readstat_sav_parse.rl"
  393|  4.70k|	{ str_start = p; }
  394|  4.70k|	break;
  395|  4.65k|	case 2:
  ------------------
  |  Branch (395:2): [True: 4.65k, False: 20.8k]
  ------------------
  396|  4.65k|#line 20 "src/spss/readstat_sav_parse.rl"
  397|  4.65k|	{ str_len = p - str_start; }
  398|  4.65k|	break;
  399|  2.28k|	case 3:
  ------------------
  |  Branch (399:2): [True: 2.28k, False: 23.2k]
  ------------------
  400|  2.28k|#line 102 "src/spss/readstat_sav_parse.rl"
  401|  2.28k|	{
  402|  2.28k|            varlookup_t *found = bsearch(temp_key, table, var_count, sizeof(varlookup_t), &compare_key_varlookup);
  403|  2.28k|            if (!found) {
  ------------------
  |  Branch (403:17): [True: 1.47k, False: 815]
  ------------------
  404|  1.47k|                snprintf(error_buf, sizeof(error_buf), "Failed to find %s", temp_key);
  405|  1.47k|                if (ctx->handle.error)
  ------------------
  |  Branch (405:21): [True: 0, False: 1.47k]
  ------------------
  406|      0|                    ctx->handle.error(error_buf, ctx->user_ctx);
  407|  1.47k|            } 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|    815|                varlookup_t *iter_match = found;
  414|  2.05k|                while (iter_match >= table && strcmp(iter_match->name, temp_key) == 0) {
  ------------------
  |  Branch (414:24): [True: 1.77k, False: 280]
  |  Branch (414:47): [True: 1.23k, False: 535]
  ------------------
  415|  1.23k|                    spss_varinfo_t *info = ctx->varinfo[iter_match->index];
  416|  1.23k|                    snprintf(info->longname, sizeof(info->longname), "%*s", (int)str_len, temp_val);
  417|  1.23k|                    iter_match--;
  418|  1.23k|                }
  419|    815|                iter_match = found + 1;
  420|  1.25k|                while (iter_match - table < var_count && strcmp(iter_match->name, temp_key) == 0) {
  ------------------
  |  Branch (420:24): [True: 899, False: 355]
  |  Branch (420:58): [True: 439, False: 460]
  ------------------
  421|    439|                    spss_varinfo_t *info = ctx->varinfo[iter_match->index];
  422|    439|                    snprintf(info->longname, sizeof(info->longname), "%*s", (int)str_len, temp_val);
  423|    439|                    iter_match++;
  424|    439|                }
  425|    815|            }
  426|  2.28k|        }
  427|  2.28k|	break;
  428|  2.28k|	case 4:
  ------------------
  |  Branch (428:2): [True: 2.28k, False: 23.2k]
  ------------------
  429|  2.28k|#line 129 "src/spss/readstat_sav_parse.rl"
  430|  2.28k|	{
  431|  2.28k|            memcpy(temp_val, str_start, str_len);
  432|  2.28k|            temp_val[str_len] = '\0';
  433|  2.28k|        }
  434|  2.28k|	break;
  435|  4.63k|	case 5:
  ------------------
  |  Branch (435:2): [True: 4.63k, False: 20.8k]
  ------------------
  436|  4.63k|#line 134 "src/spss/readstat_sav_parse.rl"
  437|  4.63k|	{ str_start = p; }
  438|  4.63k|	break;
  439|  2.28k|	case 6:
  ------------------
  |  Branch (439:2): [True: 2.28k, False: 23.2k]
  ------------------
  440|  2.28k|#line 134 "src/spss/readstat_sav_parse.rl"
  441|  2.28k|	{ str_len = p - str_start; }
  442|  2.28k|	break;
  443|  25.5k|#line 444 "src/spss/readstat_sav_parse.c"
  444|  25.5k|		}
  445|  25.5k|	}
  446|       |
  447|  27.1k|_again:
  448|  27.1k|	if ( cs == 0 )
  ------------------
  |  Branch (448:7): [True: 183, False: 26.9k]
  ------------------
  449|    183|		goto _out;
  450|  26.9k|	if ( ++p != pe )
  ------------------
  |  Branch (450:7): [True: 24.2k, False: 2.64k]
  ------------------
  451|  24.2k|		goto _resume;
  452|  2.64k|	_test_eof: {}
  453|  2.64k|	if ( p == eof )
  ------------------
  |  Branch (453:7): [True: 2.64k, False: 0]
  ------------------
  454|  2.64k|	{
  455|  2.64k|	const char *__acts = _sav_long_variable_parse_actions + _sav_long_variable_parse_eof_actions[cs];
  456|  2.64k|	unsigned int __nacts = (unsigned int) *__acts++;
  457|  9.67k|	while ( __nacts-- > 0 ) {
  ------------------
  |  Branch (457:10): [True: 7.03k, False: 2.64k]
  ------------------
  458|  7.03k|		switch ( *__acts++ ) {
  ------------------
  |  Branch (458:12): [True: 7.03k, False: 0]
  ------------------
  459|  2.34k|	case 3:
  ------------------
  |  Branch (459:2): [True: 2.34k, False: 4.69k]
  ------------------
  460|  2.34k|#line 102 "src/spss/readstat_sav_parse.rl"
  461|  2.34k|	{
  462|  2.34k|            varlookup_t *found = bsearch(temp_key, table, var_count, sizeof(varlookup_t), &compare_key_varlookup);
  463|  2.34k|            if (!found) {
  ------------------
  |  Branch (463:17): [True: 1.34k, False: 1.00k]
  ------------------
  464|  1.34k|                snprintf(error_buf, sizeof(error_buf), "Failed to find %s", temp_key);
  465|  1.34k|                if (ctx->handle.error)
  ------------------
  |  Branch (465:21): [True: 0, False: 1.34k]
  ------------------
  466|      0|                    ctx->handle.error(error_buf, ctx->user_ctx);
  467|  1.34k|            } 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.00k|                varlookup_t *iter_match = found;
  474|  2.72k|                while (iter_match >= table && strcmp(iter_match->name, temp_key) == 0) {
  ------------------
  |  Branch (474:24): [True: 2.42k, False: 293]
  |  Branch (474:47): [True: 1.72k, False: 709]
  ------------------
  475|  1.72k|                    spss_varinfo_t *info = ctx->varinfo[iter_match->index];
  476|  1.72k|                    snprintf(info->longname, sizeof(info->longname), "%*s", (int)str_len, temp_val);
  477|  1.72k|                    iter_match--;
  478|  1.72k|                }
  479|  1.00k|                iter_match = found + 1;
  480|  2.43k|                while (iter_match - table < var_count && strcmp(iter_match->name, temp_key) == 0) {
  ------------------
  |  Branch (480:24): [True: 2.00k, False: 429]
  |  Branch (480:58): [True: 1.42k, False: 573]
  ------------------
  481|  1.42k|                    spss_varinfo_t *info = ctx->varinfo[iter_match->index];
  482|  1.42k|                    snprintf(info->longname, sizeof(info->longname), "%*s", (int)str_len, temp_val);
  483|  1.42k|                    iter_match++;
  484|  1.42k|                }
  485|  1.00k|            }
  486|  2.34k|        }
  487|  2.34k|	break;
  488|  2.34k|	case 4:
  ------------------
  |  Branch (488:2): [True: 2.34k, False: 4.69k]
  ------------------
  489|  2.34k|#line 129 "src/spss/readstat_sav_parse.rl"
  490|  2.34k|	{
  491|  2.34k|            memcpy(temp_val, str_start, str_len);
  492|  2.34k|            temp_val[str_len] = '\0';
  493|  2.34k|        }
  494|  2.34k|	break;
  495|  2.34k|	case 6:
  ------------------
  |  Branch (495:2): [True: 2.34k, False: 4.69k]
  ------------------
  496|  2.34k|#line 134 "src/spss/readstat_sav_parse.rl"
  497|  2.34k|	{ str_len = p - str_start; }
  498|  2.34k|	break;
  499|  7.03k|#line 500 "src/spss/readstat_sav_parse.c"
  500|  7.03k|		}
  501|  7.03k|	}
  502|  2.64k|	}
  503|       |
  504|  2.82k|	_out: {}
  505|  2.82k|	}
  506|       |
  507|      0|#line 142 "src/spss/readstat_sav_parse.rl"
  508|       |
  509|       |
  510|  2.82k|    if (cs < 11|| p != pe) {
  ------------------
  |  Branch (510:9): [True: 220, False: 2.60k]
  |  Branch (510:19): [True: 0, False: 2.60k]
  ------------------
  511|    220|        if (ctx->handle.error) {
  ------------------
  |  Branch (511:13): [True: 0, False: 220]
  ------------------
  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|    220|        retval = READSTAT_ERROR_PARSE;
  517|    220|    }
  518|       |    
  519|       |
  520|  2.82k|    if (table)
  ------------------
  |  Branch (520:9): [True: 2.30k, False: 516]
  ------------------
  521|  2.30k|        free(table);
  522|       |
  523|       |    /* suppress warning */
  524|  2.82k|    (void)sav_long_variable_parse_en_main;
  525|       |
  526|  2.82k|    return retval;
  527|  2.64k|}
sav_parse_very_long_string_record:
  612|  3.57k|readstat_error_t sav_parse_very_long_string_record(void *data, int count, sav_ctx_t *ctx) {
  613|  3.57k|    unsigned char *c_data = (unsigned char *)data;
  614|  3.57k|    int var_count = count_vars(ctx);
  615|  3.57k|    readstat_error_t retval = READSTAT_OK;
  616|       |
  617|  3.57k|    char temp_key[8*4+1];
  618|  3.57k|    unsigned int temp_val = 0;
  619|  3.57k|    unsigned char *str_start = NULL;
  620|  3.57k|    size_t str_len = 0;
  621|       |
  622|  3.57k|    size_t error_buf_len = 1024 + count;
  623|  3.57k|    char *error_buf = NULL;
  624|  3.57k|    unsigned char *p = c_data;
  625|  3.57k|    unsigned char *pe = c_data + count;
  626|  3.57k|    unsigned char *eof = pe;
  627|       |
  628|  3.57k|    varlookup_t *table = NULL;
  629|  3.57k|    int cs;
  630|       |
  631|  3.57k|    error_buf = readstat_malloc(error_buf_len);
  632|  3.57k|    table = build_lookup_table(var_count, ctx);
  633|       |    
  634|       |    
  635|  3.57k|#line 636 "src/spss/readstat_sav_parse.c"
  636|  3.57k|	{
  637|  3.57k|	cs = sav_very_long_string_parse_start;
  638|  3.57k|	}
  639|       |
  640|  3.57k|#line 641 "src/spss/readstat_sav_parse.c"
  641|  3.57k|	{
  642|  3.57k|	int _klen;
  643|  3.57k|	unsigned int _trans;
  644|  3.57k|	const char *_acts;
  645|  3.57k|	unsigned int _nacts;
  646|  3.57k|	const unsigned char *_keys;
  647|       |
  648|  3.57k|	if ( p == pe )
  ------------------
  |  Branch (648:7): [True: 0, False: 3.57k]
  ------------------
  649|      0|		goto _test_eof;
  650|  3.57k|	if ( cs == 0 )
  ------------------
  |  Branch (650:7): [True: 0, False: 3.57k]
  ------------------
  651|      0|		goto _out;
  652|  30.5k|_resume:
  653|  30.5k|	_keys = _sav_very_long_string_parse_trans_keys + _sav_very_long_string_parse_key_offsets[cs];
  654|  30.5k|	_trans = _sav_very_long_string_parse_index_offsets[cs];
  655|       |
  656|  30.5k|	_klen = _sav_very_long_string_parse_single_lengths[cs];
  657|  30.5k|	if ( _klen > 0 ) {
  ------------------
  |  Branch (657:7): [True: 25.6k, False: 4.87k]
  ------------------
  658|  25.6k|		const unsigned char *_lower = _keys;
  659|  25.6k|		const unsigned char *_mid;
  660|  25.6k|		const unsigned char *_upper = _keys + _klen - 1;
  661|  57.4k|		while (1) {
  ------------------
  |  Branch (661:10): [True: 57.4k, Folded]
  ------------------
  662|  57.4k|			if ( _upper < _lower )
  ------------------
  |  Branch (662:9): [True: 16.5k, False: 40.9k]
  ------------------
  663|  16.5k|				break;
  664|       |
  665|  40.9k|			_mid = _lower + ((_upper-_lower) >> 1);
  666|  40.9k|			if ( (*p) < *_mid )
  ------------------
  |  Branch (666:9): [True: 11.1k, False: 29.7k]
  ------------------
  667|  11.1k|				_upper = _mid - 1;
  668|  29.7k|			else if ( (*p) > *_mid )
  ------------------
  |  Branch (668:14): [True: 20.6k, False: 9.15k]
  ------------------
  669|  20.6k|				_lower = _mid + 1;
  670|  9.15k|			else {
  671|  9.15k|				_trans += (unsigned int)(_mid - _keys);
  672|  9.15k|				goto _match;
  673|  9.15k|			}
  674|  40.9k|		}
  675|  16.5k|		_keys += _klen;
  676|  16.5k|		_trans += _klen;
  677|  16.5k|	}
  678|       |
  679|  21.3k|	_klen = _sav_very_long_string_parse_range_lengths[cs];
  680|  21.3k|	if ( _klen > 0 ) {
  ------------------
  |  Branch (680:7): [True: 21.3k, False: 53]
  ------------------
  681|  21.3k|		const unsigned char *_lower = _keys;
  682|  21.3k|		const unsigned char *_mid;
  683|  21.3k|		const unsigned char *_upper = _keys + (_klen<<1) - 2;
  684|  47.1k|		while (1) {
  ------------------
  |  Branch (684:10): [True: 47.1k, Folded]
  ------------------
  685|  47.1k|			if ( _upper < _lower )
  ------------------
  |  Branch (685:9): [True: 10.9k, False: 36.2k]
  ------------------
  686|  10.9k|				break;
  687|       |
  688|  36.2k|			_mid = _lower + (((_upper-_lower) >> 1) & ~1);
  689|  36.2k|			if ( (*p) < _mid[0] )
  ------------------
  |  Branch (689:9): [True: 7.78k, False: 28.4k]
  ------------------
  690|  7.78k|				_upper = _mid - 2;
  691|  28.4k|			else if ( (*p) > _mid[1] )
  ------------------
  |  Branch (691:14): [True: 18.0k, False: 10.3k]
  ------------------
  692|  18.0k|				_lower = _mid + 2;
  693|  10.3k|			else {
  694|  10.3k|				_trans += (unsigned int)((_mid - _keys)>>1);
  695|  10.3k|				goto _match;
  696|  10.3k|			}
  697|  36.2k|		}
  698|  10.9k|		_trans += _klen;
  699|  10.9k|	}
  700|       |
  701|  30.5k|_match:
  702|  30.5k|	_trans = _sav_very_long_string_parse_indicies[_trans];
  703|  30.5k|	cs = _sav_very_long_string_parse_trans_targs[_trans];
  704|       |
  705|  30.5k|	if ( _sav_very_long_string_parse_trans_actions[_trans] == 0 )
  ------------------
  |  Branch (705:7): [True: 8.05k, False: 22.4k]
  ------------------
  706|  8.05k|		goto _again;
  707|       |
  708|  22.4k|	_acts = _sav_very_long_string_parse_actions + _sav_very_long_string_parse_trans_actions[_trans];
  709|  22.4k|	_nacts = (unsigned int) *_acts++;
  710|  54.4k|	while ( _nacts-- > 0 )
  ------------------
  |  Branch (710:10): [True: 32.2k, False: 22.2k]
  ------------------
  711|  32.2k|	{
  712|  32.2k|		switch ( *_acts++ )
  ------------------
  |  Branch (712:12): [True: 32.2k, False: 0]
  ------------------
  713|  32.2k|		{
  714|  4.87k|	case 0:
  ------------------
  |  Branch (714:2): [True: 4.87k, False: 27.3k]
  ------------------
  715|  4.87k|#line 13 "src/spss/readstat_sav_parse.rl"
  716|  4.87k|	{
  717|  4.87k|        memcpy(temp_key, str_start, str_len);
  718|  4.87k|        temp_key[str_len] = '\0';
  719|  4.87k|    }
  720|  4.87k|	break;
  721|  4.96k|	case 1:
  ------------------
  |  Branch (721:2): [True: 4.96k, False: 27.2k]
  ------------------
  722|  4.96k|#line 20 "src/spss/readstat_sav_parse.rl"
  723|  4.96k|	{ str_start = p; }
  724|  4.96k|	break;
  725|  4.87k|	case 2:
  ------------------
  |  Branch (725:2): [True: 4.87k, False: 27.3k]
  ------------------
  726|  4.87k|#line 20 "src/spss/readstat_sav_parse.rl"
  727|  4.87k|	{ str_len = p - str_start; }
  728|  4.87k|	break;
  729|  2.37k|	case 3:
  ------------------
  |  Branch (729:2): [True: 2.37k, False: 29.8k]
  ------------------
  730|  2.37k|#line 193 "src/spss/readstat_sav_parse.rl"
  731|  2.37k|	{
  732|  2.37k|            varlookup_t *found = bsearch(temp_key, table, var_count, sizeof(varlookup_t), &compare_key_varlookup);
  733|  2.37k|            if (found) {
  ------------------
  |  Branch (733:17): [True: 1.15k, False: 1.21k]
  ------------------
  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.15k|                varlookup_t *first_match = found, *last_match = found;
  737|  1.15k|                varlookup_t *iter_match = found - 1;
  738|  8.42k|                while (iter_match >= table && strcmp(iter_match->name, temp_key) == 0) {
  ------------------
  |  Branch (738:24): [True: 8.10k, False: 319]
  |  Branch (738:47): [True: 7.27k, False: 837]
  ------------------
  739|  7.27k|                    first_match = iter_match;
  740|  7.27k|                    iter_match--;
  741|  7.27k|                }
  742|  1.15k|                iter_match = found + 1;
  743|  6.89k|                while (iter_match - table < var_count && strcmp(iter_match->name, temp_key) == 0) {
  ------------------
  |  Branch (743:24): [True: 6.48k, False: 417]
  |  Branch (743:58): [True: 5.74k, False: 739]
  ------------------
  744|  5.74k|                    last_match = iter_match;
  745|  5.74k|                    iter_match++;
  746|  5.74k|                }
  747|  15.3k|                for (iter_match=first_match; iter_match<=last_match; iter_match++) {
  ------------------
  |  Branch (747:46): [True: 14.1k, False: 1.15k]
  ------------------
  748|  14.1k|                    ctx->varinfo[iter_match->index]->string_length = temp_val;
  749|  14.1k|                    ctx->varinfo[iter_match->index]->write_format.width = temp_val;
  750|  14.1k|                    ctx->varinfo[iter_match->index]->print_format.width = temp_val;
  751|  14.1k|                }
  752|  1.15k|            }
  753|  2.37k|        }
  754|  2.37k|	break;
  755|  10.2k|	case 4:
  ------------------
  |  Branch (755:2): [True: 10.2k, False: 21.9k]
  ------------------
  756|  10.2k|#line 217 "src/spss/readstat_sav_parse.rl"
  757|  10.2k|	{
  758|  10.2k|            if ((*p) != '\0') {
  ------------------
  |  Branch (758:17): [True: 10.2k, False: 0]
  ------------------
  759|  10.2k|                unsigned char digit = (*p) - '0';
  760|  10.2k|                if (temp_val <= (UINT_MAX - digit) / 10) {
  ------------------
  |  Branch (760:21): [True: 10.0k, False: 222]
  ------------------
  761|  10.0k|                    temp_val = 10 * temp_val + digit;
  762|  10.0k|                } else {
  763|    222|                    {p++; goto _out; }
  764|    222|                }
  765|  10.2k|            }
  766|  10.2k|        }
  767|  10.0k|	break;
  768|  10.0k|	case 5:
  ------------------
  |  Branch (768:2): [True: 4.86k, False: 27.3k]
  ------------------
  769|  4.86k|#line 228 "src/spss/readstat_sav_parse.rl"
  770|  4.86k|	{ temp_val = 0; }
  771|  4.86k|	break;
  772|  32.2k|#line 773 "src/spss/readstat_sav_parse.c"
  773|  32.2k|		}
  774|  32.2k|	}
  775|       |
  776|  30.3k|_again:
  777|  30.3k|	if ( cs == 0 )
  ------------------
  |  Branch (777:7): [True: 159, False: 30.1k]
  ------------------
  778|    159|		goto _out;
  779|  30.1k|	if ( ++p != pe )
  ------------------
  |  Branch (779:7): [True: 26.9k, False: 3.19k]
  ------------------
  780|  26.9k|		goto _resume;
  781|  3.19k|	_test_eof: {}
  782|  3.19k|	if ( p == eof )
  ------------------
  |  Branch (782:7): [True: 3.19k, False: 0]
  ------------------
  783|  3.19k|	{
  784|  3.19k|	const char *__acts = _sav_very_long_string_parse_actions + _sav_very_long_string_parse_eof_actions[cs];
  785|  3.19k|	unsigned int __nacts = (unsigned int) *__acts++;
  786|  5.45k|	while ( __nacts-- > 0 ) {
  ------------------
  |  Branch (786:10): [True: 2.26k, False: 3.19k]
  ------------------
  787|  2.26k|		switch ( *__acts++ ) {
  ------------------
  |  Branch (787:12): [True: 2.26k, False: 0]
  ------------------
  788|  2.26k|	case 3:
  ------------------
  |  Branch (788:2): [True: 2.26k, False: 0]
  ------------------
  789|  2.26k|#line 193 "src/spss/readstat_sav_parse.rl"
  790|  2.26k|	{
  791|  2.26k|            varlookup_t *found = bsearch(temp_key, table, var_count, sizeof(varlookup_t), &compare_key_varlookup);
  792|  2.26k|            if (found) {
  ------------------
  |  Branch (792:17): [True: 1.17k, False: 1.08k]
  ------------------
  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.17k|                varlookup_t *first_match = found, *last_match = found;
  796|  1.17k|                varlookup_t *iter_match = found - 1;
  797|  3.60k|                while (iter_match >= table && strcmp(iter_match->name, temp_key) == 0) {
  ------------------
  |  Branch (797:24): [True: 3.13k, False: 468]
  |  Branch (797:47): [True: 2.42k, False: 710]
  ------------------
  798|  2.42k|                    first_match = iter_match;
  799|  2.42k|                    iter_match--;
  800|  2.42k|                }
  801|  1.17k|                iter_match = found + 1;
  802|  2.96k|                while (iter_match - table < var_count && strcmp(iter_match->name, temp_key) == 0) {
  ------------------
  |  Branch (802:24): [True: 2.49k, False: 466]
  |  Branch (802:58): [True: 1.78k, False: 712]
  ------------------
  803|  1.78k|                    last_match = iter_match;
  804|  1.78k|                    iter_match++;
  805|  1.78k|                }
  806|  6.57k|                for (iter_match=first_match; iter_match<=last_match; iter_match++) {
  ------------------
  |  Branch (806:46): [True: 5.39k, False: 1.17k]
  ------------------
  807|  5.39k|                    ctx->varinfo[iter_match->index]->string_length = temp_val;
  808|  5.39k|                    ctx->varinfo[iter_match->index]->write_format.width = temp_val;
  809|  5.39k|                    ctx->varinfo[iter_match->index]->print_format.width = temp_val;
  810|  5.39k|                }
  811|  1.17k|            }
  812|  2.26k|        }
  813|  2.26k|	break;
  814|  2.26k|#line 815 "src/spss/readstat_sav_parse.c"
  815|  2.26k|		}
  816|  2.26k|	}
  817|  3.19k|	}
  818|       |
  819|  3.57k|	_out: {}
  820|  3.57k|	}
  821|       |
  822|      0|#line 236 "src/spss/readstat_sav_parse.rl"
  823|       |
  824|       |    
  825|  3.57k|    if (cs < 11 || p != pe) {
  ------------------
  |  Branch (825:9): [True: 223, False: 3.35k]
  |  Branch (825:20): [True: 1, False: 3.35k]
  ------------------
  826|    224|        if (ctx->handle.error) {
  ------------------
  |  Branch (826:13): [True: 0, False: 224]
  ------------------
  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|    224|        retval = READSTAT_ERROR_PARSE;
  832|    224|    }
  833|       |    
  834|  3.57k|    if (table)
  ------------------
  |  Branch (834:9): [True: 2.93k, False: 644]
  ------------------
  835|  2.93k|        free(table);
  836|  3.57k|    if (error_buf)
  ------------------
  |  Branch (836:9): [True: 3.57k, False: 0]
  ------------------
  837|  3.57k|        free(error_buf);
  838|       |
  839|       |    /* suppress warning */
  840|  3.57k|    (void)sav_very_long_string_parse_en_main;
  841|       |
  842|  3.57k|    return retval;
  843|  3.19k|}
readstat_sav_parse.c:count_vars:
   33|  6.39k|static int count_vars(sav_ctx_t *ctx) {
   34|  6.39k|    int i;
   35|  6.39k|    spss_varinfo_t *last_info = NULL;
   36|  6.39k|    int var_count = 0;
   37|   552k|    for (i=0; i<ctx->var_index; i++) {
  ------------------
  |  Branch (37:15): [True: 545k, False: 6.39k]
  ------------------
   38|   545k|        spss_varinfo_t *info = ctx->varinfo[i];
   39|   545k|        if (last_info == NULL || strcmp(info->name, last_info->name) != 0) {
  ------------------
  |  Branch (39:13): [True: 5.23k, False: 540k]
  |  Branch (39:34): [True: 494k, False: 45.6k]
  ------------------
   40|   500k|            var_count++;
   41|   500k|        }
   42|   545k|        last_info = info;
   43|   545k|    }
   44|  6.39k|    return var_count;
   45|  6.39k|}
readstat_sav_parse.c:build_lookup_table:
   47|  6.39k|static varlookup_t *build_lookup_table(int var_count, sav_ctx_t *ctx) {
   48|  6.39k|    varlookup_t *table = readstat_malloc(var_count * sizeof(varlookup_t));
   49|  6.39k|    int offset = 0;
   50|  6.39k|    int i;
   51|  6.39k|    spss_varinfo_t *last_info = NULL;
   52|   552k|    for (i=0; i<ctx->var_index; i++) {
  ------------------
  |  Branch (52:15): [True: 545k, False: 6.39k]
  ------------------
   53|   545k|        spss_varinfo_t *info = ctx->varinfo[i];
   54|       |
   55|   545k|        if (last_info == NULL || strcmp(info->name, last_info->name) != 0) {
  ------------------
  |  Branch (55:13): [True: 5.23k, False: 540k]
  |  Branch (55:34): [True: 494k, False: 45.6k]
  ------------------
   56|   500k|            varlookup_t *entry = &table[offset++];
   57|       |
   58|   500k|            memcpy(entry->name, info->name, sizeof(info->name));
   59|   500k|            entry->index = info->index;
   60|   500k|        }
   61|   545k|        last_info = info;
   62|   545k|    }
   63|  6.39k|    qsort(table, var_count, sizeof(varlookup_t), &compare_varlookups);
   64|  6.39k|    return table;
   65|  6.39k|}
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|  15.9k|static int compare_key_varlookup(const void *elem1, const void *elem2) {
   22|  15.9k|    const char *key = (const char *)elem1;
   23|  15.9k|    const varlookup_t *v = (const varlookup_t *)elem2;
   24|  15.9k|    return strcasecmp(key, v->name);
   25|  15.9k|}

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

sav_parse_time:
   73|  5.87k|readstat_error_handler error_cb, void *user_ctx) {
   74|  5.87k|	readstat_error_t retval = READSTAT_OK;
   75|  5.87k|	char error_buf[8192];
   76|  5.87k|	const char *p = data;
   77|  5.87k|	const char *pe = p + len;
   78|  5.87k|	const char *eof = pe;
   79|  5.87k|	int cs;
   80|  5.87k|	int temp_val = 0;
   81|       |	
   82|  5.87k|#line 83 "src/spss/readstat_sav_parse_timestamp.c"
   83|  5.87k|	{
   84|  5.87k|		cs = (int)sav_time_parse_start;
   85|  5.87k|	}
   86|       |	
   87|  5.87k|#line 88 "src/spss/readstat_sav_parse_timestamp.c"
   88|  5.87k|	{
   89|  5.87k|		int _klen;
   90|  5.87k|		unsigned int _trans = 0;
   91|  5.87k|		const char * _keys;
   92|  5.87k|		const signed char * _acts;
   93|  5.87k|		unsigned int _nacts;
   94|  13.7k|		_resume: {}
   95|  13.7k|		if ( p == pe && p != eof )
  ------------------
  |  Branch (95:8): [True: 721, False: 13.0k]
  |  Branch (95:19): [True: 0, False: 721]
  ------------------
   96|      0|			goto _out;
   97|  13.7k|		if ( p == eof ) {
  ------------------
  |  Branch (97:8): [True: 721, False: 13.0k]
  ------------------
   98|    721|			if ( _sav_time_parse_eof_trans[cs] > 0 ) {
  ------------------
  |  Branch (98:9): [True: 721, False: 0]
  ------------------
   99|    721|				_trans = (unsigned int)_sav_time_parse_eof_trans[cs] - 1;
  100|    721|			}
  101|    721|		}
  102|  13.0k|		else {
  103|  13.0k|			_keys = ( _sav_time_parse_trans_keys + (_sav_time_parse_key_offsets[cs]));
  104|  13.0k|			_trans = (unsigned int)_sav_time_parse_index_offsets[cs];
  105|       |			
  106|  13.0k|			_klen = (int)_sav_time_parse_single_lengths[cs];
  107|  13.0k|			if ( _klen > 0 ) {
  ------------------
  |  Branch (107:9): [True: 9.72k, False: 3.34k]
  ------------------
  108|  9.72k|				const char *_lower = _keys;
  109|  9.72k|				const char *_upper = _keys + _klen - 1;
  110|  9.72k|				const char *_mid;
  111|  17.3k|				while ( 1 ) {
  ------------------
  |  Branch (111:13): [True: 17.3k, Folded]
  ------------------
  112|  17.3k|					if ( _upper < _lower ) {
  ------------------
  |  Branch (112:11): [True: 7.58k, False: 9.72k]
  ------------------
  113|  7.58k|						_keys += _klen;
  114|  7.58k|						_trans += (unsigned int)_klen;
  115|  7.58k|						break;
  116|  7.58k|					}
  117|       |					
  118|  9.72k|					_mid = _lower + ((_upper-_lower) >> 1);
  119|  9.72k|					if ( ( (*( p))) < (*( _mid)) )
  ------------------
  |  Branch (119:11): [True: 3.60k, False: 6.12k]
  ------------------
  120|  3.60k|						_upper = _mid - 1;
  121|  6.12k|					else if ( ( (*( p))) > (*( _mid)) )
  ------------------
  |  Branch (121:16): [True: 3.98k, False: 2.13k]
  ------------------
  122|  3.98k|						_lower = _mid + 1;
  123|  2.13k|					else {
  124|  2.13k|						_trans += (unsigned int)(_mid - _keys);
  125|  2.13k|						goto _match;
  126|  2.13k|					}
  127|  9.72k|				}
  128|  9.72k|			}
  129|       |			
  130|  10.9k|			_klen = (int)_sav_time_parse_range_lengths[cs];
  131|  10.9k|			if ( _klen > 0 ) {
  ------------------
  |  Branch (131:9): [True: 10.6k, False: 270]
  ------------------
  132|  10.6k|				const char *_lower = _keys;
  133|  10.6k|				const char *_upper = _keys + (_klen<<1) - 2;
  134|  10.6k|				const char *_mid;
  135|  15.5k|				while ( 1 ) {
  ------------------
  |  Branch (135:13): [True: 15.5k, Folded]
  ------------------
  136|  15.5k|					if ( _upper < _lower ) {
  ------------------
  |  Branch (136:11): [True: 4.88k, False: 10.6k]
  ------------------
  137|  4.88k|						_trans += (unsigned int)_klen;
  138|  4.88k|						break;
  139|  4.88k|					}
  140|       |					
  141|  10.6k|					_mid = _lower + (((_upper-_lower) >> 1) & ~1);
  142|  10.6k|					if ( ( (*( p))) < (*( _mid)) )
  ------------------
  |  Branch (142:11): [True: 4.15k, False: 6.50k]
  ------------------
  143|  4.15k|						_upper = _mid - 2;
  144|  6.50k|					else if ( ( (*( p))) > (*( _mid + 1)) )
  ------------------
  |  Branch (144:16): [True: 722, False: 5.78k]
  ------------------
  145|    722|						_lower = _mid + 2;
  146|  5.78k|					else {
  147|  5.78k|						_trans += (unsigned int)((_mid - _keys)>>1);
  148|  5.78k|						break;
  149|  5.78k|					}
  150|  10.6k|				}
  151|  10.6k|			}
  152|       |			
  153|  13.0k|			_match: {}
  154|  13.0k|		}
  155|  13.7k|		cs = (int)_sav_time_parse_cond_targs[_trans];
  156|       |		
  157|  13.7k|		if ( _sav_time_parse_cond_actions[_trans] != 0 ) {
  ------------------
  |  Branch (157:8): [True: 8.29k, False: 5.49k]
  ------------------
  158|       |			
  159|  8.29k|			_acts = ( _sav_time_parse_actions + (_sav_time_parse_cond_actions[_trans]));
  160|  8.29k|			_nacts = (unsigned int)(*( _acts));
  161|  8.29k|			_acts += 1;
  162|  16.6k|			while ( _nacts > 0 ) {
  ------------------
  |  Branch (162:12): [True: 8.34k, False: 8.29k]
  ------------------
  163|  8.34k|				switch ( (*( _acts)) )
  ------------------
  |  Branch (163:14): [True: 8.34k, False: 0]
  ------------------
  164|  8.34k|				{
  165|  2.78k|					case 0:  {
  ------------------
  |  Branch (165:6): [True: 2.78k, False: 5.56k]
  ------------------
  166|  2.78k|						{
  167|  2.78k|#line 24 "src/spss/readstat_sav_parse_timestamp.rl"
  168|       |							
  169|  2.78k|							temp_val = 10 * temp_val + ((( (*( p)))) - '0');
  170|  2.78k|						}
  171|       |						
  172|  2.78k|#line 173 "src/spss/readstat_sav_parse_timestamp.c"
  173|       |						
  174|  2.78k|						break; 
  175|      0|					}
  176|     49|					case 1:  {
  ------------------
  |  Branch (176:6): [True: 49, False: 8.29k]
  ------------------
  177|     49|						{
  178|     49|#line 28 "src/spss/readstat_sav_parse_timestamp.rl"
  179|     49|							temp_val = 0; }
  180|       |						
  181|     49|#line 182 "src/spss/readstat_sav_parse_timestamp.c"
  182|       |						
  183|     49|						break; 
  184|      0|					}
  185|  3.00k|					case 2:  {
  ------------------
  |  Branch (185:6): [True: 3.00k, False: 5.34k]
  ------------------
  186|  3.00k|						{
  187|  3.00k|#line 28 "src/spss/readstat_sav_parse_timestamp.rl"
  188|  3.00k|							temp_val = (( (*( p)))) - '0'; }
  189|       |						
  190|  3.00k|#line 191 "src/spss/readstat_sav_parse_timestamp.c"
  191|       |						
  192|  3.00k|						break; 
  193|      0|					}
  194|    992|					case 3:  {
  ------------------
  |  Branch (194:6): [True: 992, False: 7.35k]
  ------------------
  195|    992|						{
  196|    992|#line 30 "src/spss/readstat_sav_parse_timestamp.rl"
  197|    992|							timestamp->tm_hour = temp_val; }
  198|       |						
  199|    992|#line 200 "src/spss/readstat_sav_parse_timestamp.c"
  200|       |						
  201|    992|						break; 
  202|      0|					}
  203|    799|					case 4:  {
  ------------------
  |  Branch (203:6): [True: 799, False: 7.54k]
  ------------------
  204|    799|						{
  205|    799|#line 32 "src/spss/readstat_sav_parse_timestamp.rl"
  206|    799|							timestamp->tm_min = temp_val; }
  207|       |						
  208|    799|#line 209 "src/spss/readstat_sav_parse_timestamp.c"
  209|       |						
  210|    799|						break; 
  211|      0|					}
  212|    721|					case 5:  {
  ------------------
  |  Branch (212:6): [True: 721, False: 7.62k]
  ------------------
  213|    721|						{
  214|    721|#line 34 "src/spss/readstat_sav_parse_timestamp.rl"
  215|    721|							timestamp->tm_sec = temp_val; }
  216|       |						
  217|    721|#line 218 "src/spss/readstat_sav_parse_timestamp.c"
  218|       |						
  219|    721|						break; 
  220|      0|					}
  221|  8.34k|				}
  222|  8.34k|				_nacts -= 1;
  223|  8.34k|				_acts += 1;
  224|  8.34k|			}
  225|       |			
  226|  8.29k|		}
  227|       |		
  228|  13.7k|		if ( p == eof ) {
  ------------------
  |  Branch (228:8): [True: 721, False: 13.0k]
  ------------------
  229|    721|			if ( cs >= 12 )
  ------------------
  |  Branch (229:9): [True: 721, False: 0]
  ------------------
  230|    721|				goto _out;
  231|    721|		}
  232|  13.0k|		else {
  233|  13.0k|			if ( cs != 0 ) {
  ------------------
  |  Branch (233:9): [True: 7.91k, False: 5.15k]
  ------------------
  234|  7.91k|				p += 1;
  235|  7.91k|				goto _resume;
  236|  7.91k|			}
  237|  13.0k|		}
  238|  5.87k|		_out: {}
  239|  5.87k|	}
  240|       |	
  241|      0|#line 40 "src/spss/readstat_sav_parse_timestamp.rl"
  242|       |	
  243|       |	
  244|  5.87k|	if (cs < 
  ------------------
  |  Branch (244:6): [True: 5.15k, False: 721]
  ------------------
  245|  5.87k|#line 246 "src/spss/readstat_sav_parse_timestamp.c"
  246|  5.87k|	12
  247|    721|#line 42 "src/spss/readstat_sav_parse_timestamp.rl"
  248|  5.15k|	|| p != pe) {
  ------------------
  |  Branch (248:5): [True: 0, False: 721]
  ------------------
  249|  5.15k|		if (error_cb) {
  ------------------
  |  Branch (249:7): [True: 0, False: 5.15k]
  ------------------
  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|  5.15k|		retval = READSTAT_ERROR_BAD_TIMESTAMP_STRING;
  255|  5.15k|	}
  256|       |	
  257|  5.87k|	(void)sav_time_parse_en_main;
  258|       |	
  259|  5.87k|	return retval;
  260|  13.7k|}
sav_parse_date:
  398|    721|readstat_error_handler error_cb, void *user_ctx) {
  399|    721|	readstat_error_t retval = READSTAT_OK;
  400|    721|	char error_buf[8192];
  401|    721|	const char *p = data;
  402|    721|	const char *pe = p + len;
  403|    721|	const char *eof = pe;
  404|    721|	int cs;
  405|    721|	int temp_val = 0;
  406|       |	
  407|    721|#line 408 "src/spss/readstat_sav_parse_timestamp.c"
  408|    721|	{
  409|    721|		cs = (int)sav_date_parse_start;
  410|    721|	}
  411|       |	
  412|    721|#line 413 "src/spss/readstat_sav_parse_timestamp.c"
  413|    721|	{
  414|    721|		int _klen;
  415|    721|		unsigned int _trans = 0;
  416|    721|		const char * _keys;
  417|    721|		const signed char * _acts;
  418|    721|		unsigned int _nacts;
  419|  5.23k|		_resume: {}
  420|  5.23k|		if ( p == pe && p != eof )
  ------------------
  |  Branch (420:8): [True: 442, False: 4.78k]
  |  Branch (420:19): [True: 0, False: 442]
  ------------------
  421|      0|			goto _out;
  422|  5.23k|		if ( p == eof ) {
  ------------------
  |  Branch (422:8): [True: 442, False: 4.78k]
  ------------------
  423|    442|			if ( _sav_date_parse_eof_trans[cs] > 0 ) {
  ------------------
  |  Branch (423:9): [True: 442, False: 0]
  ------------------
  424|    442|				_trans = (unsigned int)_sav_date_parse_eof_trans[cs] - 1;
  425|    442|			}
  426|    442|		}
  427|  4.78k|		else {
  428|  4.78k|			_keys = ( _sav_date_parse_trans_keys + (_sav_date_parse_key_offsets[cs]));
  429|  4.78k|			_trans = (unsigned int)_sav_date_parse_index_offsets[cs];
  430|       |			
  431|  4.78k|			_klen = (int)_sav_date_parse_single_lengths[cs];
  432|  4.78k|			if ( _klen > 0 ) {
  ------------------
  |  Branch (432:9): [True: 4.78k, False: 0]
  ------------------
  433|  4.78k|				const char *_lower = _keys;
  434|  4.78k|				const char *_upper = _keys + _klen - 1;
  435|  4.78k|				const char *_mid;
  436|  8.10k|				while ( 1 ) {
  ------------------
  |  Branch (436:13): [True: 8.10k, Folded]
  ------------------
  437|  8.10k|					if ( _upper < _lower ) {
  ------------------
  |  Branch (437:11): [True: 2.26k, False: 5.83k]
  ------------------
  438|  2.26k|						_keys += _klen;
  439|  2.26k|						_trans += (unsigned int)_klen;
  440|  2.26k|						break;
  441|  2.26k|					}
  442|       |					
  443|  5.83k|					_mid = _lower + ((_upper-_lower) >> 1);
  444|  5.83k|					if ( ( (*( p))) < (*( _mid)) )
  ------------------
  |  Branch (444:11): [True: 312, False: 5.52k]
  ------------------
  445|    312|						_upper = _mid - 1;
  446|  5.52k|					else if ( ( (*( p))) > (*( _mid)) )
  ------------------
  |  Branch (446:16): [True: 3.00k, False: 2.52k]
  ------------------
  447|  3.00k|						_lower = _mid + 1;
  448|  2.52k|					else {
  449|  2.52k|						_trans += (unsigned int)(_mid - _keys);
  450|  2.52k|						goto _match;
  451|  2.52k|					}
  452|  5.83k|				}
  453|  4.78k|			}
  454|       |			
  455|  2.26k|			_klen = (int)_sav_date_parse_range_lengths[cs];
  456|  2.26k|			if ( _klen > 0 ) {
  ------------------
  |  Branch (456:9): [True: 2.18k, False: 78]
  ------------------
  457|  2.18k|				const char *_lower = _keys;
  458|  2.18k|				const char *_upper = _keys + (_klen<<1) - 2;
  459|  2.18k|				const char *_mid;
  460|  2.38k|				while ( 1 ) {
  ------------------
  |  Branch (460:13): [True: 2.38k, Folded]
  ------------------
  461|  2.38k|					if ( _upper < _lower ) {
  ------------------
  |  Branch (461:11): [True: 201, False: 2.18k]
  ------------------
  462|    201|						_trans += (unsigned int)_klen;
  463|    201|						break;
  464|    201|					}
  465|       |					
  466|  2.18k|					_mid = _lower + (((_upper-_lower) >> 1) & ~1);
  467|  2.18k|					if ( ( (*( p))) < (*( _mid)) )
  ------------------
  |  Branch (467:11): [True: 138, False: 2.04k]
  ------------------
  468|    138|						_upper = _mid - 2;
  469|  2.04k|					else if ( ( (*( p))) > (*( _mid + 1)) )
  ------------------
  |  Branch (469:16): [True: 63, False: 1.98k]
  ------------------
  470|     63|						_lower = _mid + 2;
  471|  1.98k|					else {
  472|  1.98k|						_trans += (unsigned int)((_mid - _keys)>>1);
  473|  1.98k|						break;
  474|  1.98k|					}
  475|  2.18k|				}
  476|  2.18k|			}
  477|       |			
  478|  4.78k|			_match: {}
  479|  4.78k|		}
  480|  5.23k|		cs = (int)_sav_date_parse_cond_targs[_trans];
  481|       |		
  482|  5.23k|		if ( _sav_date_parse_cond_actions[_trans] != 0 ) {
  ------------------
  |  Branch (482:8): [True: 3.48k, False: 1.74k]
  ------------------
  483|       |			
  484|  3.48k|			_acts = ( _sav_date_parse_actions + (_sav_date_parse_cond_actions[_trans]));
  485|  3.48k|			_nacts = (unsigned int)(*( _acts));
  486|  3.48k|			_acts += 1;
  487|  8.03k|			while ( _nacts > 0 ) {
  ------------------
  |  Branch (487:12): [True: 4.54k, False: 3.48k]
  ------------------
  488|  4.54k|				switch ( (*( _acts)) )
  ------------------
  |  Branch (488:14): [True: 4.54k, False: 0]
  ------------------
  489|  4.54k|				{
  490|  2.05k|					case 0:  {
  ------------------
  |  Branch (490:6): [True: 2.05k, False: 2.49k]
  ------------------
  491|  2.05k|						{
  492|  2.05k|#line 71 "src/spss/readstat_sav_parse_timestamp.rl"
  493|       |							
  494|  2.05k|							char digit = ((( (*( p)))) - '0');
  495|  2.05k|							if (digit >= 0 && digit <= 9) {
  ------------------
  |  Branch (495:12): [True: 1.98k, False: 64]
  |  Branch (495:26): [True: 1.98k, False: 0]
  ------------------
  496|  1.98k|								temp_val = 10 * temp_val + digit;
  497|  1.98k|							}
  498|  2.05k|						}
  499|       |						
  500|  2.05k|#line 501 "src/spss/readstat_sav_parse_timestamp.c"
  501|       |						
  502|  2.05k|						break; 
  503|      0|					}
  504|    442|					case 1:  {
  ------------------
  |  Branch (504:6): [True: 442, False: 4.10k]
  ------------------
  505|    442|						{
  506|    442|#line 78 "src/spss/readstat_sav_parse_timestamp.rl"
  507|       |							
  508|    442|							if (temp_val < 70) {
  ------------------
  |  Branch (508:12): [True: 369, False: 73]
  ------------------
  509|    369|								timestamp->tm_year = 100 + temp_val;
  510|    369|							} else {
  511|     73|								timestamp->tm_year = temp_val;
  512|     73|							}
  513|    442|						}
  514|       |						
  515|    442|#line 516 "src/spss/readstat_sav_parse_timestamp.c"
  516|       |						
  517|    442|						break; 
  518|      0|					}
  519|  1.06k|					case 2:  {
  ------------------
  |  Branch (519:6): [True: 1.06k, False: 3.48k]
  ------------------
  520|  1.06k|						{
  521|  1.06k|#line 87 "src/spss/readstat_sav_parse_timestamp.rl"
  522|  1.06k|							temp_val = 0; }
  523|       |						
  524|  1.06k|#line 525 "src/spss/readstat_sav_parse_timestamp.c"
  525|       |						
  526|  1.06k|						break; 
  527|      0|					}
  528|    527|					case 3:  {
  ------------------
  |  Branch (528:6): [True: 527, False: 4.02k]
  ------------------
  529|    527|						{
  530|    527|#line 89 "src/spss/readstat_sav_parse_timestamp.rl"
  531|    527|							timestamp->tm_mday = temp_val; }
  532|       |						
  533|    527|#line 534 "src/spss/readstat_sav_parse_timestamp.c"
  534|       |						
  535|    527|						break; 
  536|      0|					}
  537|    234|					case 4:  {
  ------------------
  |  Branch (537:6): [True: 234, False: 4.31k]
  ------------------
  538|    234|						{
  539|    234|#line 94 "src/spss/readstat_sav_parse_timestamp.rl"
  540|    234|							timestamp->tm_mon = 0; }
  541|       |						
  542|    234|#line 543 "src/spss/readstat_sav_parse_timestamp.c"
  543|       |						
  544|    234|						break; 
  545|      0|					}
  546|      5|					case 5:  {
  ------------------
  |  Branch (546:6): [True: 5, False: 4.54k]
  ------------------
  547|      5|						{
  548|      5|#line 95 "src/spss/readstat_sav_parse_timestamp.rl"
  549|      5|							timestamp->tm_mon = 1; }
  550|       |						
  551|      5|#line 552 "src/spss/readstat_sav_parse_timestamp.c"
  552|       |						
  553|      5|						break; 
  554|      0|					}
  555|     41|					case 6:  {
  ------------------
  |  Branch (555:6): [True: 41, False: 4.50k]
  ------------------
  556|     41|						{
  557|     41|#line 96 "src/spss/readstat_sav_parse_timestamp.rl"
  558|     41|							timestamp->tm_mon = 2; }
  559|       |						
  560|     41|#line 561 "src/spss/readstat_sav_parse_timestamp.c"
  561|       |						
  562|     41|						break; 
  563|      0|					}
  564|      4|					case 7:  {
  ------------------
  |  Branch (564:6): [True: 4, False: 4.54k]
  ------------------
  565|      4|						{
  566|      4|#line 97 "src/spss/readstat_sav_parse_timestamp.rl"
  567|      4|							timestamp->tm_mon = 3; }
  568|       |						
  569|      4|#line 570 "src/spss/readstat_sav_parse_timestamp.c"
  570|       |						
  571|      4|						break; 
  572|      0|					}
  573|      3|					case 8:  {
  ------------------
  |  Branch (573:6): [True: 3, False: 4.54k]
  ------------------
  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|    127|					case 9:  {
  ------------------
  |  Branch (582:6): [True: 127, False: 4.42k]
  ------------------
  583|    127|						{
  584|    127|#line 99 "src/spss/readstat_sav_parse_timestamp.rl"
  585|    127|							timestamp->tm_mon = 5; }
  586|       |						
  587|    127|#line 588 "src/spss/readstat_sav_parse_timestamp.c"
  588|       |						
  589|    127|						break; 
  590|      0|					}
  591|      6|					case 10:  {
  ------------------
  |  Branch (591:6): [True: 6, False: 4.54k]
  ------------------
  592|      6|						{
  593|      6|#line 100 "src/spss/readstat_sav_parse_timestamp.rl"
  594|      6|							timestamp->tm_mon = 6; }
  595|       |						
  596|      6|#line 597 "src/spss/readstat_sav_parse_timestamp.c"
  597|       |						
  598|      6|						break; 
  599|      0|					}
  600|      1|					case 11:  {
  ------------------
  |  Branch (600:6): [True: 1, False: 4.54k]
  ------------------
  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.54k]
  ------------------
  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|      3|					case 13:  {
  ------------------
  |  Branch (618:6): [True: 3, False: 4.54k]
  ------------------
  619|      3|						{
  620|      3|#line 103 "src/spss/readstat_sav_parse_timestamp.rl"
  621|      3|							timestamp->tm_mon = 9; }
  622|       |						
  623|      3|#line 624 "src/spss/readstat_sav_parse_timestamp.c"
  624|       |						
  625|      3|						break; 
  626|      0|					}
  627|      2|					case 14:  {
  ------------------
  |  Branch (627:6): [True: 2, False: 4.54k]
  ------------------
  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|     36|					case 15:  {
  ------------------
  |  Branch (636:6): [True: 36, False: 4.51k]
  ------------------
  637|     36|						{
  638|     36|#line 105 "src/spss/readstat_sav_parse_timestamp.rl"
  639|     36|							timestamp->tm_mon = 11; }
  640|       |						
  641|     36|#line 642 "src/spss/readstat_sav_parse_timestamp.c"
  642|       |						
  643|     36|						break; 
  644|      0|					}
  645|  4.54k|				}
  646|  4.54k|				_nacts -= 1;
  647|  4.54k|				_acts += 1;
  648|  4.54k|			}
  649|       |			
  650|  3.48k|		}
  651|       |		
  652|  5.23k|		if ( p == eof ) {
  ------------------
  |  Branch (652:8): [True: 442, False: 4.78k]
  ------------------
  653|    442|			if ( cs >= 47 )
  ------------------
  |  Branch (653:9): [True: 442, False: 0]
  ------------------
  654|    442|				goto _out;
  655|    442|		}
  656|  4.78k|		else {
  657|  4.78k|			if ( cs != 0 ) {
  ------------------
  |  Branch (657:9): [True: 4.51k, False: 279]
  ------------------
  658|  4.51k|				p += 1;
  659|  4.51k|				goto _resume;
  660|  4.51k|			}
  661|  4.78k|		}
  662|    721|		_out: {}
  663|    721|	}
  664|       |	
  665|      0|#line 112 "src/spss/readstat_sav_parse_timestamp.rl"
  666|       |	
  667|       |	
  668|    721|	if (cs < 
  ------------------
  |  Branch (668:6): [True: 279, False: 442]
  ------------------
  669|    721|#line 670 "src/spss/readstat_sav_parse_timestamp.c"
  670|    721|	47
  671|    442|#line 114 "src/spss/readstat_sav_parse_timestamp.rl"
  672|    442|	|| p != pe) {
  ------------------
  |  Branch (672:5): [True: 0, False: 442]
  ------------------
  673|    279|		if (error_cb) {
  ------------------
  |  Branch (673:7): [True: 0, False: 279]
  ------------------
  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|    279|		retval = READSTAT_ERROR_BAD_TIMESTAMP_STRING;
  679|    279|	}
  680|       |	
  681|    721|	(void)sav_date_parse_en_main;
  682|       |	
  683|    721|	return retval;
  684|  5.23k|}

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

spss_format:
   51|   254k|int spss_format(char *buffer, size_t len, spss_format_t *format) {
   52|   254k|    if (format->type < 0 
  ------------------
  |  Branch (52:9): [True: 0, False: 254k]
  ------------------
   53|   254k|            || format->type >= sizeof(spss_type_strings)/sizeof(spss_type_strings[0])
  ------------------
  |  Branch (53:16): [True: 6.67k, False: 247k]
  ------------------
   54|   247k|            || spss_type_strings[format->type][0] == '\0') {
  ------------------
  |  Branch (54:16): [True: 26.3k, False: 221k]
  ------------------
   55|  32.9k|        return 0;
   56|  32.9k|    }
   57|   221k|    char *string = spss_type_strings[format->type];
   58|       |
   59|   221k|    if (format->decimal_places || format->type == SPSS_FORMAT_TYPE_F) {
  ------------------
  |  |    6|   149k|#define SPSS_FORMAT_TYPE_F        5
  ------------------
  |  Branch (59:9): [True: 72.0k, False: 149k]
  |  Branch (59:35): [True: 627, False: 148k]
  ------------------
   60|  72.6k|        snprintf(buffer, len, "%s%d.%d", string, format->width, format->decimal_places);
   61|   148k|    } else if (format->width) {
  ------------------
  |  Branch (61:16): [True: 91.5k, False: 57.2k]
  ------------------
   62|  91.5k|        snprintf(buffer, len, "%s%d", string, format->width);
   63|  91.5k|    } else {
   64|  57.2k|        snprintf(buffer, len, "%s", string);
   65|  57.2k|    }
   66|       |
   67|   221k|    return 1;
   68|   254k|}
spss_varinfo_compare:
   70|   309k|int spss_varinfo_compare(const void *elem1, const void *elem2) {
   71|   309k|    int offset = *(int *)elem1;
   72|   309k|    const spss_varinfo_t *v = *(const spss_varinfo_t **)elem2;
   73|   309k|    if (offset < v->offset)
  ------------------
  |  Branch (73:9): [True: 156k, False: 153k]
  ------------------
   74|   156k|        return -1;
   75|   153k|    return (offset > v->offset);
   76|   309k|}
spss_varinfo_free:
   78|   392k|void spss_varinfo_free(spss_varinfo_t *info) {
   79|   392k|    if (info) {
  ------------------
  |  Branch (79:9): [True: 392k, False: 11]
  ------------------
   80|   392k|        if (info->label)
  ------------------
  |  Branch (80:13): [True: 1.03k, False: 391k]
  ------------------
   81|  1.03k|            free(info->label);
   82|   392k|        free(info);
   83|   392k|    }
   84|   392k|}
spss_missingness_for_info:
  127|   254k|readstat_missingness_t spss_missingness_for_info(spss_varinfo_t *info) {
  128|   254k|    readstat_missingness_t missingness;
  129|   254k|    memset(&missingness, '\0', sizeof(readstat_missingness_t));
  130|       |
  131|   254k|    if (info->missing_range) {
  ------------------
  |  Branch (131:9): [True: 2.38k, False: 252k]
  ------------------
  132|  2.38k|        missingness.missing_ranges_count++;
  133|  2.38k|        missingness.missing_ranges[0] = spss_boxed_missing_value(info, 0);
  134|  2.38k|        missingness.missing_ranges[1] = spss_boxed_missing_value(info, 1);
  135|       |
  136|  2.38k|        if (info->n_missing_values == 3) {
  ------------------
  |  Branch (136:13): [True: 764, False: 1.62k]
  ------------------
  137|    764|            missingness.missing_ranges_count++;
  138|    764|            missingness.missing_ranges[2] = missingness.missing_ranges[3] = spss_boxed_missing_value(info, 2);
  139|    764|        }
  140|   252k|    } else if (info->n_missing_values > 0) {
  ------------------
  |  Branch (140:16): [True: 1.68k, False: 250k]
  ------------------
  141|  1.68k|        missingness.missing_ranges_count = info->n_missing_values;
  142|  1.68k|        int i=0;
  143|  5.40k|        for (i=0; i<info->n_missing_values; i++) {
  ------------------
  |  Branch (143:19): [True: 3.72k, False: 1.68k]
  ------------------
  144|  3.72k|            missingness.missing_ranges[2*i] = missingness.missing_ranges[2*i+1] = spss_boxed_missing_value(info, i);
  145|  3.72k|        }
  146|  1.68k|    }
  147|   254k|    return missingness;
  148|   254k|}
spss_init_variable_for_info:
  151|   254k|        iconv_t converter) {
  152|   254k|    readstat_variable_t *variable = calloc(1, sizeof(readstat_variable_t));
  153|       |
  154|   254k|    variable->index = info->index;
  155|   254k|    variable->index_after_skipping = index_after_skipping;
  156|   254k|    variable->type = info->type;
  157|   254k|    if (info->string_length) {
  ------------------
  |  Branch (157:9): [True: 968, False: 253k]
  ------------------
  158|    968|        variable->storage_width = info->string_length;
  159|   253k|    } else {
  160|   253k|        variable->storage_width = 8 * info->width;
  161|   253k|    }
  162|       |
  163|   254k|    if (info->longname[0]) {
  ------------------
  |  Branch (163:9): [True: 251k, False: 3.11k]
  ------------------
  164|   251k|        readstat_convert(variable->name, sizeof(variable->name),
  165|   251k|                info->longname, sizeof(info->longname), converter);
  166|   251k|    } else {
  167|  3.11k|        readstat_convert(variable->name, sizeof(variable->name),
  168|  3.11k|                info->name, sizeof(info->name), converter);
  169|  3.11k|    }
  170|   254k|    if (info->label) {
  ------------------
  |  Branch (170:9): [True: 722, False: 253k]
  ------------------
  171|    722|        snprintf(variable->label, sizeof(variable->label), "%s", info->label);
  172|    722|    }
  173|       |
  174|   254k|    spss_format(variable->format, sizeof(variable->format), &info->print_format);
  175|       |
  176|   254k|    variable->missingness = spss_missingness_for_info(info);
  177|   254k|    variable->measure = info->measure;
  178|   254k|    if (info->display_width) {
  ------------------
  |  Branch (178:9): [True: 1.60k, False: 252k]
  ------------------
  179|  1.60k|        variable->display_width = info->display_width;
  180|   252k|    } else {
  181|   252k|        variable->display_width = info->print_format.width;
  182|   252k|    }
  183|       |
  184|   254k|    return variable;
  185|   254k|}
spss_measure_to_readstat_measure:
  199|  4.70k|readstat_measure_t spss_measure_to_readstat_measure(uint32_t sav_measure) {
  200|  4.70k|    if (sav_measure == SAV_MEASURE_NOMINAL)
  ------------------
  |  |   47|  4.70k|#define SAV_MEASURE_NOMINAL     1
  ------------------
  |  Branch (200:9): [True: 155, False: 4.55k]
  ------------------
  201|    155|        return READSTAT_MEASURE_NOMINAL;
  202|  4.55k|    if (sav_measure == SAV_MEASURE_ORDINAL)
  ------------------
  |  |   48|  4.55k|#define SAV_MEASURE_ORDINAL     2
  ------------------
  |  Branch (202:9): [True: 398, False: 4.15k]
  ------------------
  203|    398|        return READSTAT_MEASURE_ORDINAL;
  204|  4.15k|    if (sav_measure == SAV_MEASURE_SCALE)
  ------------------
  |  |   49|  4.15k|#define SAV_MEASURE_SCALE       3
  ------------------
  |  Branch (204:9): [True: 91, False: 4.06k]
  ------------------
  205|     91|        return READSTAT_MEASURE_SCALE;
  206|  4.06k|    return READSTAT_MEASURE_UNKNOWN;
  207|  4.15k|}
spss_alignment_to_readstat_alignment:
  221|  4.70k|readstat_alignment_t spss_alignment_to_readstat_alignment(uint32_t sav_alignment) {
  222|  4.70k|    if (sav_alignment == SAV_ALIGNMENT_LEFT)
  ------------------
  |  |   51|  4.70k|#define SAV_ALIGNMENT_LEFT      0
  ------------------
  |  Branch (222:9): [True: 1.30k, False: 3.40k]
  ------------------
  223|  1.30k|        return READSTAT_ALIGNMENT_LEFT;
  224|  3.40k|    if (sav_alignment == SAV_ALIGNMENT_CENTER)
  ------------------
  |  |   53|  3.40k|#define SAV_ALIGNMENT_CENTER    2
  ------------------
  |  Branch (224:9): [True: 364, False: 3.03k]
  ------------------
  225|    364|        return READSTAT_ALIGNMENT_CENTER;
  226|  3.03k|    if (sav_alignment == SAV_ALIGNMENT_RIGHT)
  ------------------
  |  |   52|  3.03k|#define SAV_ALIGNMENT_RIGHT     1
  ------------------
  |  Branch (226:9): [True: 119, False: 2.91k]
  ------------------
  227|    119|        return READSTAT_ALIGNMENT_RIGHT;
  228|  2.91k|    return READSTAT_ALIGNMENT_UNKNOWN;
  229|  3.03k|}
readstat_spss.c:spss_boxed_missing_value:
  120|  9.25k|static readstat_value_t spss_boxed_missing_value(spss_varinfo_t *info, int i) {
  121|  9.25k|    if (info->type == READSTAT_TYPE_DOUBLE) {
  ------------------
  |  Branch (121:9): [True: 5.49k, False: 3.76k]
  ------------------
  122|  5.49k|        return spss_boxed_double_value(info->missing_double_values[i]);
  123|  5.49k|    }
  124|  3.76k|    return spss_boxed_string_value(info->missing_string_values[i]);
  125|  9.25k|}
readstat_spss.c:spss_boxed_double_value:
  103|  5.49k|static readstat_value_t spss_boxed_double_value(double fp_value) {
  104|  5.49k|    readstat_value_t value = {
  105|  5.49k|        .type = READSTAT_TYPE_DOUBLE,
  106|  5.49k|        .v = { .double_value = fp_value },
  107|       |        .is_system_missing = isnan(fp_value)
  108|  5.49k|    };
  109|  5.49k|    return value;
  110|  5.49k|}
readstat_spss.c:spss_boxed_string_value:
  112|  3.76k|static readstat_value_t spss_boxed_string_value(const char *string) {
  113|  3.76k|    readstat_value_t value = {
  114|  3.76k|        .type = READSTAT_TYPE_STRING,
  115|  3.76k|        .v = { .string_value = string }
  116|  3.76k|    };
  117|  3.76k|    return value;
  118|  3.76k|}

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

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

