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

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

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

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

readstat_convert:
    7|  2.20M|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.9M|    while (src_len && (src[src_len-1] == ' ' || src[src_len-1] == '\0')) {
  ------------------
  |  Branch (10:12): [True: 22.9M, False: 20.1k]
  |  Branch (10:24): [True: 2.85M, False: 20.0M]
  |  Branch (10:49): [True: 17.9M, False: 2.18M]
  ------------------
   11|  20.7M|        src_len--;
   12|  20.7M|    }
   13|  2.20M|    if (dst_len == 0) {
  ------------------
  |  Branch (13:9): [True: 0, False: 2.20M]
  ------------------
   14|      0|        return READSTAT_ERROR_CONVERT_LONG_STRING;
   15|  2.20M|    } else if (converter) {
  ------------------
  |  Branch (15:16): [True: 2.57k, False: 2.20M]
  ------------------
   16|  2.57k|        size_t dst_left = dst_len - 1;
   17|  2.57k|        char *dst_end = dst;
   18|  2.57k|        size_t status = iconv(converter, (readstat_iconv_inbuf_t)&src, &src_len, &dst_end, &dst_left);
   19|  2.57k|        if (status == (size_t)-1) {
  ------------------
  |  Branch (19:13): [True: 1.10k, False: 1.47k]
  ------------------
   20|  1.10k|            if (errno == E2BIG) {
  ------------------
  |  Branch (20:17): [True: 1, False: 1.10k]
  ------------------
   21|      1|                return READSTAT_ERROR_CONVERT_LONG_STRING;
   22|  1.10k|            } else if (errno == EILSEQ) {
  ------------------
  |  Branch (22:24): [True: 684, False: 417]
  ------------------
   23|    684|                return READSTAT_ERROR_CONVERT_BAD_STRING;
   24|    684|            } else if (errno != EINVAL) { /* EINVAL indicates improper truncation; accept it */
  ------------------
  |  Branch (24:24): [True: 0, False: 417]
  ------------------
   25|      0|                return READSTAT_ERROR_CONVERT;
   26|      0|            }
   27|  1.10k|        }
   28|  1.89k|        dst[dst_len - dst_left - 1] = '\0';
   29|  2.20M|    } else if (src_len + 1 > dst_len) {
  ------------------
  |  Branch (29:16): [True: 17, False: 2.20M]
  ------------------
   30|     17|        return READSTAT_ERROR_CONVERT_LONG_STRING;
   31|  2.20M|    } else {
   32|  2.20M|        memcpy(dst, src, src_len);
   33|  2.20M|        dst[src_len] = '\0';
   34|  2.20M|    }
   35|  2.20M|    return READSTAT_OK;
   36|  2.20M|}

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

readstat_malloc:
   10|  47.5k|void *readstat_malloc(size_t len) {
   11|  47.5k|    if (len > MAX_MALLOC_SIZE || len == 0) {
  ------------------
  |  |    3|  95.0k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
  |  Branch (11:9): [True: 229, False: 47.3k]
  |  Branch (11:34): [True: 1.16k, False: 46.1k]
  ------------------
   12|  1.39k|        return NULL;
   13|  1.39k|    }
   14|  46.1k|    return malloc(len);
   15|  47.5k|}
readstat_calloc:
   17|   446k|void *readstat_calloc(size_t count, size_t size) {
   18|   446k|    if (count > MAX_MALLOC_SIZE || size > MAX_MALLOC_SIZE || count * size > MAX_MALLOC_SIZE) {
  ------------------
  |  |    3|   892k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
                  if (count > MAX_MALLOC_SIZE || size > MAX_MALLOC_SIZE || count * size > MAX_MALLOC_SIZE) {
  ------------------
  |  |    3|   892k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
                  if (count > MAX_MALLOC_SIZE || size > MAX_MALLOC_SIZE || count * size > MAX_MALLOC_SIZE) {
  ------------------
  |  |    3|   446k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
  |  Branch (18:9): [True: 23, False: 446k]
  |  Branch (18:36): [True: 0, False: 446k]
  |  Branch (18:62): [True: 23, False: 446k]
  ------------------
   19|     46|        return NULL;
   20|     46|    }
   21|   446k|    if (count == 0 || size == 0) {
  ------------------
  |  Branch (21:9): [True: 18, False: 446k]
  |  Branch (21:23): [True: 0, False: 446k]
  ------------------
   22|     18|        return NULL;
   23|     18|    }
   24|   446k|    return calloc(count, size);
   25|   446k|}
readstat_realloc:
   27|  7.94k|void *readstat_realloc(void *ptr, size_t len) {
   28|  7.94k|    if (len > MAX_MALLOC_SIZE || len == 0) {
  ------------------
  |  |    3|  15.8k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
  |  Branch (28:9): [True: 113, False: 7.83k]
  |  Branch (28:34): [True: 1, False: 7.83k]
  ------------------
   29|    114|        if (ptr)
  ------------------
  |  Branch (29:13): [True: 59, False: 55]
  ------------------
   30|     59|            free(ptr);
   31|    114|        return NULL;
   32|    114|    }
   33|  7.83k|    return realloc(ptr, len);
   34|  7.94k|}

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

sav_ctx_init:
   23|  5.34k|sav_ctx_t *sav_ctx_init(sav_file_header_record_t *header, readstat_io_t *io) {
   24|  5.34k|    sav_ctx_t *ctx = readstat_calloc(1, sizeof(sav_ctx_t));
   25|  5.34k|    if (ctx == NULL) {
  ------------------
  |  Branch (25:9): [True: 0, False: 5.34k]
  ------------------
   26|      0|        return NULL;
   27|      0|    }
   28|       |
   29|  5.34k|    if (memcmp(&header->rec_type, "$FL2", 4) == 0) {
  ------------------
  |  Branch (29:9): [True: 3.15k, False: 2.19k]
  ------------------
   30|  3.15k|        ctx->format_version = 2;
   31|  3.15k|    } else if (memcmp(&header->rec_type, "$FL3", 4) == 0) {
  ------------------
  |  Branch (31:16): [True: 2.16k, False: 30]
  ------------------
   32|  2.16k|        ctx->format_version = 3;
   33|  2.16k|    } else {
   34|     30|        sav_ctx_free(ctx);
   35|     30|        return NULL;
   36|     30|    }
   37|       |    
   38|  5.31k|    ctx->bswap = !(header->layout_code == 2 || header->layout_code == 3);
  ------------------
  |  Branch (38:20): [True: 3.47k, False: 1.83k]
  |  Branch (38:48): [True: 239, False: 1.59k]
  ------------------
   39|  5.31k|    ctx->endianness = (machine_is_little_endian() ^ ctx->bswap) ? READSTAT_ENDIAN_LITTLE : READSTAT_ENDIAN_BIG;
  ------------------
  |  Branch (39:23): [True: 3.71k, False: 1.59k]
  ------------------
   40|       |
   41|  5.31k|    if (header->compression == 1 || byteswap4(header->compression) == 1) {
  ------------------
  |  Branch (41:9): [True: 364, False: 4.94k]
  |  Branch (41:37): [True: 151, False: 4.79k]
  ------------------
   42|    515|        ctx->compression = READSTAT_COMPRESS_ROWS;
   43|  4.79k|    } else if (header->compression == 2 || byteswap4(header->compression) == 2) {
  ------------------
  |  Branch (43:16): [True: 455, False: 4.34k]
  |  Branch (43:44): [True: 89, False: 4.25k]
  ------------------
   44|    544|        ctx->compression = READSTAT_COMPRESS_BINARY;
   45|    544|    }
   46|  5.31k|    ctx->record_count = ctx->bswap ? byteswap4(header->ncases) : header->ncases;
  ------------------
  |  Branch (46:25): [True: 1.59k, False: 3.71k]
  ------------------
   47|  5.31k|    ctx->fweight_index = ctx->bswap ? byteswap4(header->weight_index) : header->weight_index;
  ------------------
  |  Branch (47:26): [True: 1.59k, False: 3.71k]
  ------------------
   48|       |
   49|  5.31k|    ctx->missing_double = SAV_MISSING_DOUBLE;
  ------------------
  |  |   43|  5.31k|#define SAV_MISSING_DOUBLE   0xFFEFFFFFFFFFFFFFUL
  ------------------
   50|  5.31k|    ctx->lowest_double = SAV_LOWEST_DOUBLE;
  ------------------
  |  |   44|  5.31k|#define SAV_LOWEST_DOUBLE    0xFFEFFFFFFFFFFFFEUL
  ------------------
   51|  5.31k|    ctx->highest_double = SAV_HIGHEST_DOUBLE;
  ------------------
  |  |   42|  5.31k|#define SAV_HIGHEST_DOUBLE   0x7FEFFFFFFFFFFFFFUL
  ------------------
   52|       |    
   53|  5.31k|    ctx->bias = ctx->bswap ? byteswap_double(header->bias) : header->bias;
  ------------------
  |  Branch (53:17): [True: 1.59k, False: 3.71k]
  ------------------
   54|       |    
   55|  5.31k|    ctx->varinfo_capacity = SAV_VARINFO_INITIAL_CAPACITY;
  ------------------
  |  |   21|  5.31k|#define SAV_VARINFO_INITIAL_CAPACITY  512
  ------------------
   56|       |    
   57|  5.31k|    if ((ctx->varinfo = readstat_calloc(ctx->varinfo_capacity, sizeof(spss_varinfo_t *))) == NULL) {
  ------------------
  |  Branch (57:9): [True: 0, False: 5.31k]
  ------------------
   58|      0|        sav_ctx_free(ctx);
   59|      0|        return NULL;
   60|      0|    }
   61|       |
   62|  5.31k|    ctx->mr_sets = NULL;
   63|       |
   64|  5.31k|    ctx->io = io;
   65|       |    
   66|  5.31k|    return ctx;
   67|  5.31k|}
sav_ctx_free:
   69|  5.34k|void sav_ctx_free(sav_ctx_t *ctx) {
   70|  5.34k|    if (ctx->varinfo) {
  ------------------
  |  Branch (70:9): [True: 5.31k, False: 30]
  ------------------
   71|  5.31k|        int i;
   72|   438k|        for (i=0; i<ctx->var_index; i++) {
  ------------------
  |  Branch (72:19): [True: 433k, False: 5.31k]
  ------------------
   73|   433k|            spss_varinfo_free(ctx->varinfo[i]);
   74|   433k|        }
   75|  5.31k|        free(ctx->varinfo);
   76|  5.31k|    }
   77|  5.34k|    if (ctx->variables) {
  ------------------
  |  Branch (77:9): [True: 1.73k, False: 3.60k]
  ------------------
   78|  1.73k|        int i;
   79|   261k|        for (i=0; i<ctx->var_count; i++) {
  ------------------
  |  Branch (79:19): [True: 259k, False: 1.73k]
  ------------------
   80|   259k|            if (ctx->variables[i])
  ------------------
  |  Branch (80:17): [True: 255k, False: 4.00k]
  ------------------
   81|   255k|                free(ctx->variables[i]);
   82|   259k|        }
   83|  1.73k|        free(ctx->variables);
   84|  1.73k|    }
   85|  5.34k|    if (ctx->raw_string)
  ------------------
  |  Branch (85:9): [True: 1.67k, False: 3.67k]
  ------------------
   86|  1.67k|        free(ctx->raw_string);
   87|  5.34k|    if (ctx->utf8_string)
  ------------------
  |  Branch (87:9): [True: 1.66k, False: 3.67k]
  ------------------
   88|  1.66k|        free(ctx->utf8_string);
   89|  5.34k|    if (ctx->converter)
  ------------------
  |  Branch (89:9): [True: 126, False: 5.21k]
  ------------------
   90|    126|        iconv_close(ctx->converter);
   91|  5.34k|    if (ctx->variable_display_values) {
  ------------------
  |  Branch (91:9): [True: 259, False: 5.08k]
  ------------------
   92|    259|        free(ctx->variable_display_values);
   93|    259|    }
   94|  5.34k|    if (ctx->mr_sets) {
  ------------------
  |  Branch (94:9): [True: 212, False: 5.12k]
  ------------------
   95|    685|        for (size_t i = 0; i < ctx->multiple_response_sets_length; i++) {
  ------------------
  |  Branch (95:28): [True: 473, False: 212]
  ------------------
   96|    473|            if (ctx->mr_sets[i].name) {
  ------------------
  |  Branch (96:17): [True: 473, False: 0]
  ------------------
   97|    473|                free(ctx->mr_sets[i].name);
   98|    473|            }
   99|    473|            if (ctx->mr_sets[i].label) {
  ------------------
  |  Branch (99:17): [True: 473, False: 0]
  ------------------
  100|    473|                free(ctx->mr_sets[i].label);
  101|    473|            }
  102|    473|            if (ctx->mr_sets[i].subvariables) {
  ------------------
  |  Branch (102:17): [True: 385, False: 88]
  ------------------
  103|  4.22k|                for (size_t j = 0; j < ctx->mr_sets[i].num_subvars; j++) {
  ------------------
  |  Branch (103:36): [True: 3.84k, False: 385]
  ------------------
  104|  3.84k|                    if (ctx->mr_sets[i].subvariables[j]) {
  ------------------
  |  Branch (104:25): [True: 3.84k, False: 0]
  ------------------
  105|  3.84k|                        free(ctx->mr_sets[i].subvariables[j]);
  106|  3.84k|                    }
  107|  3.84k|                }
  108|    385|                free(ctx->mr_sets[i].subvariables);
  109|    385|            }
  110|    473|        }
  111|    212|        free(ctx->mr_sets);
  112|    212|    }
  113|  5.34k|    free(ctx);
  114|  5.34k|}

sav_decompress_row:
   77|  2.24M|void sav_decompress_row(struct sav_row_stream_s *state) {
   78|  2.24M|    double fp_value;
   79|  2.24M|    uint64_t missing_value = state->bswap ? byteswap8(state->missing_value) : state->missing_value;
  ------------------
  |  Branch (79:30): [True: 321k, False: 1.92M]
  ------------------
   80|  2.24M|    int i = 8 - state->i;
   81|  2.60M|    while (1) {
  ------------------
  |  Branch (81:12): [True: 2.60M, Folded]
  ------------------
   82|  2.60M|        if (i == 8) {
  ------------------
  |  Branch (82:13): [True: 635k, False: 1.96M]
  ------------------
   83|   635k|            if (state->avail_in < 8) {
  ------------------
  |  Branch (83:17): [True: 255, False: 635k]
  ------------------
   84|    255|                state->status = SAV_ROW_STREAM_NEED_DATA;
   85|    255|                goto done;
   86|    255|            }
   87|       |
   88|   635k|            memcpy(state->chunk, state->next_in, 8);
   89|   635k|            state->next_in += 8;
   90|   635k|            state->avail_in -= 8;
   91|   635k|            i = 0;
   92|   635k|        }
   93|       |
   94|  5.44M|        while (i<8) {
  ------------------
  |  Branch (94:16): [True: 5.08M, False: 357k]
  ------------------
   95|  5.08M|            switch (state->chunk[i]) {
   96|  2.54M|                case 0:
  ------------------
  |  Branch (96:17): [True: 2.54M, False: 2.53M]
  ------------------
   97|  2.54M|                    break;
   98|     56|                case 252:
  ------------------
  |  Branch (98:17): [True: 56, False: 5.08M]
  ------------------
   99|     56|                    state->status = SAV_ROW_STREAM_FINISHED_ALL;
  100|     56|                    goto done;
  101|   117k|                case 253:
  ------------------
  |  Branch (101:17): [True: 117k, False: 4.96M]
  ------------------
  102|   117k|                    if (state->avail_in < 8) {
  ------------------
  |  Branch (102:25): [True: 50, False: 117k]
  ------------------
  103|     50|                        state->status = SAV_ROW_STREAM_NEED_DATA;
  104|     50|                        goto done;
  105|     50|                    }
  106|   117k|                    memcpy(state->next_out, state->next_in, 8);
  107|   117k|                    state->next_out += 8;
  108|   117k|                    state->avail_out -= 8;
  109|   117k|                    state->next_in += 8;
  110|   117k|                    state->avail_in -= 8;
  111|   117k|                    break;
  112|  1.93k|                case 254:
  ------------------
  |  Branch (112:17): [True: 1.93k, False: 5.08M]
  ------------------
  113|  1.93k|                    memset(state->next_out, ' ', 8);
  114|  1.93k|                    state->next_out += 8;
  115|  1.93k|                    state->avail_out -= 8;
  116|  1.93k|                    break;
  117|  83.3k|                case 255:
  ------------------
  |  Branch (117:17): [True: 83.3k, False: 5.00M]
  ------------------
  118|  83.3k|                    memcpy(state->next_out, &missing_value, sizeof(uint64_t));
  119|  83.3k|                    state->next_out += 8;
  120|  83.3k|                    state->avail_out -= 8;
  121|  83.3k|                    break;
  122|  2.33M|                default:
  ------------------
  |  Branch (122:17): [True: 2.33M, False: 2.75M]
  ------------------
  123|  2.33M|                    fp_value = state->chunk[i] - state->bias;
  124|  2.33M|                    fp_value = state->bswap ? byteswap_double(fp_value) : fp_value;
  ------------------
  |  Branch (124:32): [True: 299k, False: 2.03M]
  ------------------
  125|  2.33M|                    memcpy(state->next_out, &fp_value, sizeof(double));
  126|  2.33M|                    state->next_out += 8;
  127|  2.33M|                    state->avail_out -= 8;
  128|  2.33M|                    break;
  129|  5.08M|            }
  130|  5.08M|            i++;
  131|  5.08M|            if (state->avail_out < 8) {
  ------------------
  |  Branch (131:17): [True: 2.24M, False: 2.83M]
  ------------------
  132|  2.24M|                state->status = SAV_ROW_STREAM_FINISHED_ROW;
  133|  2.24M|                goto done;
  134|  2.24M|            }
  135|  5.08M|        }
  136|  2.60M|    }
  137|  2.24M|done:
  138|  2.24M|    state->i = 8 - i;
  139|  2.24M|}

sav_parse_long_variable_names_record:
  284|  2.87k|readstat_error_t sav_parse_long_variable_names_record(void *data, int count, sav_ctx_t *ctx) {
  285|  2.87k|    unsigned char *c_data = (unsigned char *)data;
  286|  2.87k|    int var_count = count_vars(ctx);
  287|  2.87k|    readstat_error_t retval = READSTAT_OK;
  288|       |
  289|  2.87k|    char temp_key[8+1];
  290|  2.87k|    char temp_val[64+1];
  291|  2.87k|    unsigned char *str_start = NULL;
  292|  2.87k|    size_t str_len = 0;
  293|       |    
  294|  2.87k|    char error_buf[8192];
  295|  2.87k|    unsigned char *p = c_data;
  296|  2.87k|    unsigned char *pe = c_data + count;
  297|       |
  298|  2.87k|    varlookup_t *table = build_lookup_table(var_count, ctx);
  299|       |
  300|  2.87k|    unsigned char *eof = pe;
  301|       |
  302|  2.87k|    int cs;
  303|       |
  304|       |    
  305|  2.87k|#line 306 "src/spss/readstat_sav_parse.c"
  306|  2.87k|	{
  307|  2.87k|	cs = sav_long_variable_parse_start;
  308|  2.87k|	}
  309|       |
  310|  2.87k|#line 311 "src/spss/readstat_sav_parse.c"
  311|  2.87k|	{
  312|  2.87k|	int _klen;
  313|  2.87k|	unsigned int _trans;
  314|  2.87k|	const char *_acts;
  315|  2.87k|	unsigned int _nacts;
  316|  2.87k|	const unsigned char *_keys;
  317|       |
  318|  2.87k|	if ( p == pe )
  ------------------
  |  Branch (318:7): [True: 0, False: 2.87k]
  ------------------
  319|      0|		goto _test_eof;
  320|  2.87k|	if ( cs == 0 )
  ------------------
  |  Branch (320:7): [True: 0, False: 2.87k]
  ------------------
  321|      0|		goto _out;
  322|  38.2k|_resume:
  323|  38.2k|	_keys = _sav_long_variable_parse_trans_keys + _sav_long_variable_parse_key_offsets[cs];
  324|  38.2k|	_trans = _sav_long_variable_parse_index_offsets[cs];
  325|       |
  326|  38.2k|	_klen = _sav_long_variable_parse_single_lengths[cs];
  327|  38.2k|	if ( _klen > 0 ) {
  ------------------
  |  Branch (327:7): [True: 38.2k, False: 0]
  ------------------
  328|  38.2k|		const unsigned char *_lower = _keys;
  329|  38.2k|		const unsigned char *_mid;
  330|  38.2k|		const unsigned char *_upper = _keys + _klen - 1;
  331|  89.6k|		while (1) {
  ------------------
  |  Branch (331:10): [True: 89.6k, Folded]
  ------------------
  332|  89.6k|			if ( _upper < _lower )
  ------------------
  |  Branch (332:9): [True: 29.1k, False: 60.4k]
  ------------------
  333|  29.1k|				break;
  334|       |
  335|  60.4k|			_mid = _lower + ((_upper-_lower) >> 1);
  336|  60.4k|			if ( (*p) < *_mid )
  ------------------
  |  Branch (336:9): [True: 32.4k, False: 27.9k]
  ------------------
  337|  32.4k|				_upper = _mid - 1;
  338|  27.9k|			else if ( (*p) > *_mid )
  ------------------
  |  Branch (338:14): [True: 18.9k, False: 9.02k]
  ------------------
  339|  18.9k|				_lower = _mid + 1;
  340|  9.02k|			else {
  341|  9.02k|				_trans += (unsigned int)(_mid - _keys);
  342|  9.02k|				goto _match;
  343|  9.02k|			}
  344|  60.4k|		}
  345|  29.1k|		_keys += _klen;
  346|  29.1k|		_trans += _klen;
  347|  29.1k|	}
  348|       |
  349|  29.1k|	_klen = _sav_long_variable_parse_range_lengths[cs];
  350|  29.1k|	if ( _klen > 0 ) {
  ------------------
  |  Branch (350:7): [True: 29.1k, False: 4]
  ------------------
  351|  29.1k|		const unsigned char *_lower = _keys;
  352|  29.1k|		const unsigned char *_mid;
  353|  29.1k|		const unsigned char *_upper = _keys + (_klen<<1) - 2;
  354|  77.2k|		while (1) {
  ------------------
  |  Branch (354:10): [True: 77.2k, Folded]
  ------------------
  355|  77.2k|			if ( _upper < _lower )
  ------------------
  |  Branch (355:9): [True: 29.0k, False: 48.1k]
  ------------------
  356|  29.0k|				break;
  357|       |
  358|  48.1k|			_mid = _lower + (((_upper-_lower) >> 1) & ~1);
  359|  48.1k|			if ( (*p) < _mid[0] )
  ------------------
  |  Branch (359:9): [True: 10.6k, False: 37.4k]
  ------------------
  360|  10.6k|				_upper = _mid - 2;
  361|  37.4k|			else if ( (*p) > _mid[1] )
  ------------------
  |  Branch (361:14): [True: 37.3k, False: 145]
  ------------------
  362|  37.3k|				_lower = _mid + 2;
  363|    145|			else {
  364|    145|				_trans += (unsigned int)((_mid - _keys)>>1);
  365|    145|				goto _match;
  366|    145|			}
  367|  48.1k|		}
  368|  29.0k|		_trans += _klen;
  369|  29.0k|	}
  370|       |
  371|  38.2k|_match:
  372|  38.2k|	_trans = _sav_long_variable_parse_indicies[_trans];
  373|  38.2k|	cs = _sav_long_variable_parse_trans_targs[_trans];
  374|       |
  375|  38.2k|	if ( _sav_long_variable_parse_trans_actions[_trans] == 0 )
  ------------------
  |  Branch (375:7): [True: 17.6k, False: 20.5k]
  ------------------
  376|  17.6k|		goto _again;
  377|       |
  378|  20.5k|	_acts = _sav_long_variable_parse_actions + _sav_long_variable_parse_trans_actions[_trans];
  379|  20.5k|	_nacts = (unsigned int) *_acts++;
  380|  53.3k|	while ( _nacts-- > 0 )
  ------------------
  |  Branch (380:10): [True: 32.8k, False: 20.5k]
  ------------------
  381|  32.8k|	{
  382|  32.8k|		switch ( *_acts++ )
  ------------------
  |  Branch (382:12): [True: 32.8k, False: 0]
  ------------------
  383|  32.8k|		{
  384|  5.75k|	case 0:
  ------------------
  |  Branch (384:2): [True: 5.75k, False: 27.0k]
  ------------------
  385|  5.75k|#line 13 "src/spss/readstat_sav_parse.rl"
  386|  5.75k|	{
  387|  5.75k|        memcpy(temp_key, str_start, str_len);
  388|  5.75k|        temp_key[str_len] = '\0';
  389|  5.75k|    }
  390|  5.75k|	break;
  391|  5.79k|	case 1:
  ------------------
  |  Branch (391:2): [True: 5.79k, False: 27.0k]
  ------------------
  392|  5.79k|#line 20 "src/spss/readstat_sav_parse.rl"
  393|  5.79k|	{ str_start = p; }
  394|  5.79k|	break;
  395|  5.75k|	case 2:
  ------------------
  |  Branch (395:2): [True: 5.75k, False: 27.0k]
  ------------------
  396|  5.75k|#line 20 "src/spss/readstat_sav_parse.rl"
  397|  5.75k|	{ str_len = p - str_start; }
  398|  5.75k|	break;
  399|  3.26k|	case 3:
  ------------------
  |  Branch (399:2): [True: 3.26k, False: 29.5k]
  ------------------
  400|  3.26k|#line 102 "src/spss/readstat_sav_parse.rl"
  401|  3.26k|	{
  402|  3.26k|            varlookup_t *found = bsearch(temp_key, table, var_count, sizeof(varlookup_t), &compare_key_varlookup);
  403|  3.26k|            if (!found) {
  ------------------
  |  Branch (403:17): [True: 1.64k, False: 1.61k]
  ------------------
  404|  1.64k|                snprintf(error_buf, sizeof(error_buf), "Failed to find %s", temp_key);
  405|  1.64k|                if (ctx->handle.error)
  ------------------
  |  Branch (405:21): [True: 0, False: 1.64k]
  ------------------
  406|      0|                    ctx->handle.error(error_buf, ctx->user_ctx);
  407|  1.64k|            } else {
  408|       |                // Handle the edge case where a ghost variable name (from a multi-segment
  409|       |                // variable) is identical to a real variable name. Normally we handle this
  410|       |                // by incrementing the loop variable by n_segments, but n_segments hasn't
  411|       |                // been set when this record is processed. So just set the longname to every
  412|       |                // matching variable, ghost or real.
  413|  1.61k|                varlookup_t *iter_match = found;
  414|  3.74k|                while (iter_match >= table && strcmp(iter_match->name, temp_key) == 0) {
  ------------------
  |  Branch (414:24): [True: 3.05k, False: 694]
  |  Branch (414:47): [True: 2.13k, False: 922]
  ------------------
  415|  2.13k|                    spss_varinfo_t *info = ctx->varinfo[iter_match->index];
  416|  2.13k|                    snprintf(info->longname, sizeof(info->longname), "%*s", (int)str_len, temp_val);
  417|  2.13k|                    iter_match--;
  418|  2.13k|                }
  419|  1.61k|                iter_match = found + 1;
  420|  2.41k|                while (iter_match - table < var_count && strcmp(iter_match->name, temp_key) == 0) {
  ------------------
  |  Branch (420:24): [True: 1.40k, False: 1.00k]
  |  Branch (420:58): [True: 801, False: 608]
  ------------------
  421|    801|                    spss_varinfo_t *info = ctx->varinfo[iter_match->index];
  422|    801|                    snprintf(info->longname, sizeof(info->longname), "%*s", (int)str_len, temp_val);
  423|    801|                    iter_match++;
  424|    801|                }
  425|  1.61k|            }
  426|  3.26k|        }
  427|  3.26k|	break;
  428|  3.26k|	case 4:
  ------------------
  |  Branch (428:2): [True: 3.26k, False: 29.5k]
  ------------------
  429|  3.26k|#line 129 "src/spss/readstat_sav_parse.rl"
  430|  3.26k|	{
  431|  3.26k|            memcpy(temp_val, str_start, str_len);
  432|  3.26k|            temp_val[str_len] = '\0';
  433|  3.26k|        }
  434|  3.26k|	break;
  435|  5.73k|	case 5:
  ------------------
  |  Branch (435:2): [True: 5.73k, False: 27.0k]
  ------------------
  436|  5.73k|#line 134 "src/spss/readstat_sav_parse.rl"
  437|  5.73k|	{ str_start = p; }
  438|  5.73k|	break;
  439|  3.26k|	case 6:
  ------------------
  |  Branch (439:2): [True: 3.26k, False: 29.5k]
  ------------------
  440|  3.26k|#line 134 "src/spss/readstat_sav_parse.rl"
  441|  3.26k|	{ str_len = p - str_start; }
  442|  3.26k|	break;
  443|  32.8k|#line 444 "src/spss/readstat_sav_parse.c"
  444|  32.8k|		}
  445|  32.8k|	}
  446|       |
  447|  38.2k|_again:
  448|  38.2k|	if ( cs == 0 )
  ------------------
  |  Branch (448:7): [True: 155, False: 38.0k]
  ------------------
  449|    155|		goto _out;
  450|  38.0k|	if ( ++p != pe )
  ------------------
  |  Branch (450:7): [True: 35.3k, False: 2.71k]
  ------------------
  451|  35.3k|		goto _resume;
  452|  2.71k|	_test_eof: {}
  453|  2.71k|	if ( p == eof )
  ------------------
  |  Branch (453:7): [True: 2.71k, False: 0]
  ------------------
  454|  2.71k|	{
  455|  2.71k|	const char *__acts = _sav_long_variable_parse_actions + _sav_long_variable_parse_eof_actions[cs];
  456|  2.71k|	unsigned int __nacts = (unsigned int) *__acts++;
  457|  10.1k|	while ( __nacts-- > 0 ) {
  ------------------
  |  Branch (457:10): [True: 7.38k, False: 2.71k]
  ------------------
  458|  7.38k|		switch ( *__acts++ ) {
  ------------------
  |  Branch (458:12): [True: 7.38k, False: 0]
  ------------------
  459|  2.46k|	case 3:
  ------------------
  |  Branch (459:2): [True: 2.46k, False: 4.92k]
  ------------------
  460|  2.46k|#line 102 "src/spss/readstat_sav_parse.rl"
  461|  2.46k|	{
  462|  2.46k|            varlookup_t *found = bsearch(temp_key, table, var_count, sizeof(varlookup_t), &compare_key_varlookup);
  463|  2.46k|            if (!found) {
  ------------------
  |  Branch (463:17): [True: 1.44k, False: 1.01k]
  ------------------
  464|  1.44k|                snprintf(error_buf, sizeof(error_buf), "Failed to find %s", temp_key);
  465|  1.44k|                if (ctx->handle.error)
  ------------------
  |  Branch (465:21): [True: 0, False: 1.44k]
  ------------------
  466|      0|                    ctx->handle.error(error_buf, ctx->user_ctx);
  467|  1.44k|            } else {
  468|       |                // Handle the edge case where a ghost variable name (from a multi-segment
  469|       |                // variable) is identical to a real variable name. Normally we handle this
  470|       |                // by incrementing the loop variable by n_segments, but n_segments hasn't
  471|       |                // been set when this record is processed. So just set the longname to every
  472|       |                // matching variable, ghost or real.
  473|  1.01k|                varlookup_t *iter_match = found;
  474|  2.57k|                while (iter_match >= table && strcmp(iter_match->name, temp_key) == 0) {
  ------------------
  |  Branch (474:24): [True: 2.26k, False: 316]
  |  Branch (474:47): [True: 1.56k, False: 698]
  ------------------
  475|  1.56k|                    spss_varinfo_t *info = ctx->varinfo[iter_match->index];
  476|  1.56k|                    snprintf(info->longname, sizeof(info->longname), "%*s", (int)str_len, temp_val);
  477|  1.56k|                    iter_match--;
  478|  1.56k|                }
  479|  1.01k|                iter_match = found + 1;
  480|  1.96k|                while (iter_match - table < var_count && strcmp(iter_match->name, temp_key) == 0) {
  ------------------
  |  Branch (480:24): [True: 1.41k, False: 548]
  |  Branch (480:58): [True: 953, False: 466]
  ------------------
  481|    953|                    spss_varinfo_t *info = ctx->varinfo[iter_match->index];
  482|    953|                    snprintf(info->longname, sizeof(info->longname), "%*s", (int)str_len, temp_val);
  483|    953|                    iter_match++;
  484|    953|                }
  485|  1.01k|            }
  486|  2.46k|        }
  487|  2.46k|	break;
  488|  2.46k|	case 4:
  ------------------
  |  Branch (488:2): [True: 2.46k, False: 4.92k]
  ------------------
  489|  2.46k|#line 129 "src/spss/readstat_sav_parse.rl"
  490|  2.46k|	{
  491|  2.46k|            memcpy(temp_val, str_start, str_len);
  492|  2.46k|            temp_val[str_len] = '\0';
  493|  2.46k|        }
  494|  2.46k|	break;
  495|  2.46k|	case 6:
  ------------------
  |  Branch (495:2): [True: 2.46k, False: 4.92k]
  ------------------
  496|  2.46k|#line 134 "src/spss/readstat_sav_parse.rl"
  497|  2.46k|	{ str_len = p - str_start; }
  498|  2.46k|	break;
  499|  7.38k|#line 500 "src/spss/readstat_sav_parse.c"
  500|  7.38k|		}
  501|  7.38k|	}
  502|  2.71k|	}
  503|       |
  504|  2.87k|	_out: {}
  505|  2.87k|	}
  506|       |
  507|      0|#line 142 "src/spss/readstat_sav_parse.rl"
  508|       |
  509|       |
  510|  2.87k|    if (cs < 11|| p != pe) {
  ------------------
  |  Branch (510:9): [True: 187, False: 2.68k]
  |  Branch (510:19): [True: 0, False: 2.68k]
  ------------------
  511|    187|        if (ctx->handle.error) {
  ------------------
  |  Branch (511:13): [True: 0, False: 187]
  ------------------
  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|    187|        retval = READSTAT_ERROR_PARSE;
  517|    187|    }
  518|       |    
  519|       |
  520|  2.87k|    if (table)
  ------------------
  |  Branch (520:9): [True: 2.36k, False: 511]
  ------------------
  521|  2.36k|        free(table);
  522|       |
  523|       |    /* suppress warning */
  524|  2.87k|    (void)sav_long_variable_parse_en_main;
  525|       |
  526|  2.87k|    return retval;
  527|  2.71k|}
sav_parse_very_long_string_record:
  612|  3.95k|readstat_error_t sav_parse_very_long_string_record(void *data, int count, sav_ctx_t *ctx) {
  613|  3.95k|    unsigned char *c_data = (unsigned char *)data;
  614|  3.95k|    int var_count = count_vars(ctx);
  615|  3.95k|    readstat_error_t retval = READSTAT_OK;
  616|       |
  617|  3.95k|    char temp_key[8*4+1];
  618|  3.95k|    unsigned int temp_val = 0;
  619|  3.95k|    unsigned char *str_start = NULL;
  620|  3.95k|    size_t str_len = 0;
  621|       |
  622|  3.95k|    size_t error_buf_len = 1024 + count;
  623|  3.95k|    char *error_buf = NULL;
  624|  3.95k|    unsigned char *p = c_data;
  625|  3.95k|    unsigned char *pe = c_data + count;
  626|  3.95k|    unsigned char *eof = pe;
  627|       |
  628|  3.95k|    varlookup_t *table = NULL;
  629|  3.95k|    int cs;
  630|       |
  631|  3.95k|    error_buf = readstat_malloc(error_buf_len);
  632|  3.95k|    table = build_lookup_table(var_count, ctx);
  633|       |    
  634|       |    
  635|  3.95k|#line 636 "src/spss/readstat_sav_parse.c"
  636|  3.95k|	{
  637|  3.95k|	cs = sav_very_long_string_parse_start;
  638|  3.95k|	}
  639|       |
  640|  3.95k|#line 641 "src/spss/readstat_sav_parse.c"
  641|  3.95k|	{
  642|  3.95k|	int _klen;
  643|  3.95k|	unsigned int _trans;
  644|  3.95k|	const char *_acts;
  645|  3.95k|	unsigned int _nacts;
  646|  3.95k|	const unsigned char *_keys;
  647|       |
  648|  3.95k|	if ( p == pe )
  ------------------
  |  Branch (648:7): [True: 0, False: 3.95k]
  ------------------
  649|      0|		goto _test_eof;
  650|  3.95k|	if ( cs == 0 )
  ------------------
  |  Branch (650:7): [True: 0, False: 3.95k]
  ------------------
  651|      0|		goto _out;
  652|  37.2k|_resume:
  653|  37.2k|	_keys = _sav_very_long_string_parse_trans_keys + _sav_very_long_string_parse_key_offsets[cs];
  654|  37.2k|	_trans = _sav_very_long_string_parse_index_offsets[cs];
  655|       |
  656|  37.2k|	_klen = _sav_very_long_string_parse_single_lengths[cs];
  657|  37.2k|	if ( _klen > 0 ) {
  ------------------
  |  Branch (657:7): [True: 31.3k, False: 5.85k]
  ------------------
  658|  31.3k|		const unsigned char *_lower = _keys;
  659|  31.3k|		const unsigned char *_mid;
  660|  31.3k|		const unsigned char *_upper = _keys + _klen - 1;
  661|  72.1k|		while (1) {
  ------------------
  |  Branch (661:10): [True: 72.1k, Folded]
  ------------------
  662|  72.1k|			if ( _upper < _lower )
  ------------------
  |  Branch (662:9): [True: 21.0k, False: 51.1k]
  ------------------
  663|  21.0k|				break;
  664|       |
  665|  51.1k|			_mid = _lower + ((_upper-_lower) >> 1);
  666|  51.1k|			if ( (*p) < *_mid )
  ------------------
  |  Branch (666:9): [True: 14.5k, False: 36.5k]
  ------------------
  667|  14.5k|				_upper = _mid - 1;
  668|  36.5k|			else if ( (*p) > *_mid )
  ------------------
  |  Branch (668:14): [True: 26.3k, False: 10.2k]
  ------------------
  669|  26.3k|				_lower = _mid + 1;
  670|  10.2k|			else {
  671|  10.2k|				_trans += (unsigned int)(_mid - _keys);
  672|  10.2k|				goto _match;
  673|  10.2k|			}
  674|  51.1k|		}
  675|  21.0k|		_keys += _klen;
  676|  21.0k|		_trans += _klen;
  677|  21.0k|	}
  678|       |
  679|  26.9k|	_klen = _sav_very_long_string_parse_range_lengths[cs];
  680|  26.9k|	if ( _klen > 0 ) {
  ------------------
  |  Branch (680:7): [True: 26.8k, False: 70]
  ------------------
  681|  26.8k|		const unsigned char *_lower = _keys;
  682|  26.8k|		const unsigned char *_mid;
  683|  26.8k|		const unsigned char *_upper = _keys + (_klen<<1) - 2;
  684|  60.9k|		while (1) {
  ------------------
  |  Branch (684:10): [True: 60.9k, Folded]
  ------------------
  685|  60.9k|			if ( _upper < _lower )
  ------------------
  |  Branch (685:9): [True: 14.3k, False: 46.6k]
  ------------------
  686|  14.3k|				break;
  687|       |
  688|  46.6k|			_mid = _lower + (((_upper-_lower) >> 1) & ~1);
  689|  46.6k|			if ( (*p) < _mid[0] )
  ------------------
  |  Branch (689:9): [True: 10.1k, False: 36.5k]
  ------------------
  690|  10.1k|				_upper = _mid - 2;
  691|  36.5k|			else if ( (*p) > _mid[1] )
  ------------------
  |  Branch (691:14): [True: 24.0k, False: 12.4k]
  ------------------
  692|  24.0k|				_lower = _mid + 2;
  693|  12.4k|			else {
  694|  12.4k|				_trans += (unsigned int)((_mid - _keys)>>1);
  695|  12.4k|				goto _match;
  696|  12.4k|			}
  697|  46.6k|		}
  698|  14.3k|		_trans += _klen;
  699|  14.3k|	}
  700|       |
  701|  37.2k|_match:
  702|  37.2k|	_trans = _sav_very_long_string_parse_indicies[_trans];
  703|  37.2k|	cs = _sav_very_long_string_parse_trans_targs[_trans];
  704|       |
  705|  37.2k|	if ( _sav_very_long_string_parse_trans_actions[_trans] == 0 )
  ------------------
  |  Branch (705:7): [True: 10.0k, False: 27.1k]
  ------------------
  706|  10.0k|		goto _again;
  707|       |
  708|  27.1k|	_acts = _sav_very_long_string_parse_actions + _sav_very_long_string_parse_trans_actions[_trans];
  709|  27.1k|	_nacts = (unsigned int) *_acts++;
  710|  65.8k|	while ( _nacts-- > 0 )
  ------------------
  |  Branch (710:10): [True: 38.8k, False: 26.9k]
  ------------------
  711|  38.8k|	{
  712|  38.8k|		switch ( *_acts++ )
  ------------------
  |  Branch (712:12): [True: 38.8k, False: 0]
  ------------------
  713|  38.8k|		{
  714|  5.86k|	case 0:
  ------------------
  |  Branch (714:2): [True: 5.86k, False: 33.0k]
  ------------------
  715|  5.86k|#line 13 "src/spss/readstat_sav_parse.rl"
  716|  5.86k|	{
  717|  5.86k|        memcpy(temp_key, str_start, str_len);
  718|  5.86k|        temp_key[str_len] = '\0';
  719|  5.86k|    }
  720|  5.86k|	break;
  721|  5.92k|	case 1:
  ------------------
  |  Branch (721:2): [True: 5.92k, False: 32.9k]
  ------------------
  722|  5.92k|#line 20 "src/spss/readstat_sav_parse.rl"
  723|  5.92k|	{ str_start = p; }
  724|  5.92k|	break;
  725|  5.86k|	case 2:
  ------------------
  |  Branch (725:2): [True: 5.86k, False: 33.0k]
  ------------------
  726|  5.86k|#line 20 "src/spss/readstat_sav_parse.rl"
  727|  5.86k|	{ str_len = p - str_start; }
  728|  5.86k|	break;
  729|  2.97k|	case 3:
  ------------------
  |  Branch (729:2): [True: 2.97k, False: 35.9k]
  ------------------
  730|  2.97k|#line 193 "src/spss/readstat_sav_parse.rl"
  731|  2.97k|	{
  732|  2.97k|            varlookup_t *found = bsearch(temp_key, table, var_count, sizeof(varlookup_t), &compare_key_varlookup);
  733|  2.97k|            if (found) {
  ------------------
  |  Branch (733:17): [True: 1.49k, False: 1.47k]
  ------------------
  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.49k|                varlookup_t *first_match = found, *last_match = found;
  737|  1.49k|                varlookup_t *iter_match = found - 1;
  738|  5.05k|                while (iter_match >= table && strcmp(iter_match->name, temp_key) == 0) {
  ------------------
  |  Branch (738:24): [True: 4.46k, False: 589]
  |  Branch (738:47): [True: 3.55k, False: 909]
  ------------------
  739|  3.55k|                    first_match = iter_match;
  740|  3.55k|                    iter_match--;
  741|  3.55k|                }
  742|  1.49k|                iter_match = found + 1;
  743|  5.25k|                while (iter_match - table < var_count && strcmp(iter_match->name, temp_key) == 0) {
  ------------------
  |  Branch (743:24): [True: 4.45k, False: 807]
  |  Branch (743:58): [True: 3.76k, False: 691]
  ------------------
  744|  3.76k|                    last_match = iter_match;
  745|  3.76k|                    iter_match++;
  746|  3.76k|                }
  747|  10.3k|                for (iter_match=first_match; iter_match<=last_match; iter_match++) {
  ------------------
  |  Branch (747:46): [True: 8.81k, False: 1.49k]
  ------------------
  748|  8.81k|                    ctx->varinfo[iter_match->index]->string_length = temp_val;
  749|  8.81k|                    ctx->varinfo[iter_match->index]->write_format.width = temp_val;
  750|  8.81k|                    ctx->varinfo[iter_match->index]->print_format.width = temp_val;
  751|  8.81k|                }
  752|  1.49k|            }
  753|  2.97k|        }
  754|  2.97k|	break;
  755|  12.4k|	case 4:
  ------------------
  |  Branch (755:2): [True: 12.4k, False: 26.4k]
  ------------------
  756|  12.4k|#line 217 "src/spss/readstat_sav_parse.rl"
  757|  12.4k|	{
  758|  12.4k|            if ((*p) != '\0') {
  ------------------
  |  Branch (758:17): [True: 12.4k, False: 0]
  ------------------
  759|  12.4k|                unsigned char digit = (*p) - '0';
  760|  12.4k|                if (temp_val <= (UINT_MAX - digit) / 10) {
  ------------------
  |  Branch (760:21): [True: 12.1k, False: 221]
  ------------------
  761|  12.1k|                    temp_val = 10 * temp_val + digit;
  762|  12.1k|                } else {
  763|    221|                    {p++; goto _out; }
  764|    221|                }
  765|  12.4k|            }
  766|  12.4k|        }
  767|  12.1k|	break;
  768|  12.1k|	case 5:
  ------------------
  |  Branch (768:2): [True: 5.85k, False: 33.0k]
  ------------------
  769|  5.85k|#line 228 "src/spss/readstat_sav_parse.rl"
  770|  5.85k|	{ temp_val = 0; }
  771|  5.85k|	break;
  772|  38.8k|#line 773 "src/spss/readstat_sav_parse.c"
  773|  38.8k|		}
  774|  38.8k|	}
  775|       |
  776|  36.9k|_again:
  777|  36.9k|	if ( cs == 0 )
  ------------------
  |  Branch (777:7): [True: 174, False: 36.8k]
  ------------------
  778|    174|		goto _out;
  779|  36.8k|	if ( ++p != pe )
  ------------------
  |  Branch (779:7): [True: 33.2k, False: 3.56k]
  ------------------
  780|  33.2k|		goto _resume;
  781|  3.56k|	_test_eof: {}
  782|  3.56k|	if ( p == eof )
  ------------------
  |  Branch (782:7): [True: 3.56k, False: 0]
  ------------------
  783|  3.56k|	{
  784|  3.56k|	const char *__acts = _sav_very_long_string_parse_actions + _sav_very_long_string_parse_eof_actions[cs];
  785|  3.56k|	unsigned int __nacts = (unsigned int) *__acts++;
  786|  6.21k|	while ( __nacts-- > 0 ) {
  ------------------
  |  Branch (786:10): [True: 2.65k, False: 3.56k]
  ------------------
  787|  2.65k|		switch ( *__acts++ ) {
  ------------------
  |  Branch (787:12): [True: 2.65k, False: 0]
  ------------------
  788|  2.65k|	case 3:
  ------------------
  |  Branch (788:2): [True: 2.65k, False: 0]
  ------------------
  789|  2.65k|#line 193 "src/spss/readstat_sav_parse.rl"
  790|  2.65k|	{
  791|  2.65k|            varlookup_t *found = bsearch(temp_key, table, var_count, sizeof(varlookup_t), &compare_key_varlookup);
  792|  2.65k|            if (found) {
  ------------------
  |  Branch (792:17): [True: 1.29k, False: 1.35k]
  ------------------
  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.29k|                varlookup_t *first_match = found, *last_match = found;
  796|  1.29k|                varlookup_t *iter_match = found - 1;
  797|  4.28k|                while (iter_match >= table && strcmp(iter_match->name, temp_key) == 0) {
  ------------------
  |  Branch (797:24): [True: 3.82k, False: 464]
  |  Branch (797:47): [True: 2.99k, False: 829]
  ------------------
  798|  2.99k|                    first_match = iter_match;
  799|  2.99k|                    iter_match--;
  800|  2.99k|                }
  801|  1.29k|                iter_match = found + 1;
  802|  3.54k|                while (iter_match - table < var_count && strcmp(iter_match->name, temp_key) == 0) {
  ------------------
  |  Branch (802:24): [True: 2.99k, False: 552]
  |  Branch (802:58): [True: 2.25k, False: 741]
  ------------------
  803|  2.25k|                    last_match = iter_match;
  804|  2.25k|                    iter_match++;
  805|  2.25k|                }
  806|  7.83k|                for (iter_match=first_match; iter_match<=last_match; iter_match++) {
  ------------------
  |  Branch (806:46): [True: 6.53k, False: 1.29k]
  ------------------
  807|  6.53k|                    ctx->varinfo[iter_match->index]->string_length = temp_val;
  808|  6.53k|                    ctx->varinfo[iter_match->index]->write_format.width = temp_val;
  809|  6.53k|                    ctx->varinfo[iter_match->index]->print_format.width = temp_val;
  810|  6.53k|                }
  811|  1.29k|            }
  812|  2.65k|        }
  813|  2.65k|	break;
  814|  2.65k|#line 815 "src/spss/readstat_sav_parse.c"
  815|  2.65k|		}
  816|  2.65k|	}
  817|  3.56k|	}
  818|       |
  819|  3.95k|	_out: {}
  820|  3.95k|	}
  821|       |
  822|      0|#line 236 "src/spss/readstat_sav_parse.rl"
  823|       |
  824|       |    
  825|  3.95k|    if (cs < 11 || p != pe) {
  ------------------
  |  Branch (825:9): [True: 219, False: 3.73k]
  |  Branch (825:20): [True: 1, False: 3.73k]
  ------------------
  826|    220|        if (ctx->handle.error) {
  ------------------
  |  Branch (826:13): [True: 0, False: 220]
  ------------------
  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|    220|        retval = READSTAT_ERROR_PARSE;
  832|    220|    }
  833|       |    
  834|  3.95k|    if (table)
  ------------------
  |  Branch (834:9): [True: 3.31k, False: 642]
  ------------------
  835|  3.31k|        free(table);
  836|  3.95k|    if (error_buf)
  ------------------
  |  Branch (836:9): [True: 3.95k, False: 0]
  ------------------
  837|  3.95k|        free(error_buf);
  838|       |
  839|       |    /* suppress warning */
  840|  3.95k|    (void)sav_very_long_string_parse_en_main;
  841|       |
  842|  3.95k|    return retval;
  843|  3.56k|}
readstat_sav_parse.c:count_vars:
   33|  6.82k|static int count_vars(sav_ctx_t *ctx) {
   34|  6.82k|    int i;
   35|  6.82k|    spss_varinfo_t *last_info = NULL;
   36|  6.82k|    int var_count = 0;
   37|   686k|    for (i=0; i<ctx->var_index; i++) {
  ------------------
  |  Branch (37:15): [True: 679k, False: 6.82k]
  ------------------
   38|   679k|        spss_varinfo_t *info = ctx->varinfo[i];
   39|   679k|        if (last_info == NULL || strcmp(info->name, last_info->name) != 0) {
  ------------------
  |  Branch (39:13): [True: 5.67k, False: 673k]
  |  Branch (39:34): [True: 590k, False: 82.7k]
  ------------------
   40|   596k|            var_count++;
   41|   596k|        }
   42|   679k|        last_info = info;
   43|   679k|    }
   44|  6.82k|    return var_count;
   45|  6.82k|}
readstat_sav_parse.c:build_lookup_table:
   47|  6.82k|static varlookup_t *build_lookup_table(int var_count, sav_ctx_t *ctx) {
   48|  6.82k|    varlookup_t *table = readstat_malloc(var_count * sizeof(varlookup_t));
   49|  6.82k|    int offset = 0;
   50|  6.82k|    int i;
   51|  6.82k|    spss_varinfo_t *last_info = NULL;
   52|   686k|    for (i=0; i<ctx->var_index; i++) {
  ------------------
  |  Branch (52:15): [True: 679k, False: 6.82k]
  ------------------
   53|   679k|        spss_varinfo_t *info = ctx->varinfo[i];
   54|       |
   55|   679k|        if (last_info == NULL || strcmp(info->name, last_info->name) != 0) {
  ------------------
  |  Branch (55:13): [True: 5.67k, False: 673k]
  |  Branch (55:34): [True: 590k, False: 82.7k]
  ------------------
   56|   596k|            varlookup_t *entry = &table[offset++];
   57|       |
   58|   596k|            memcpy(entry->name, info->name, sizeof(info->name));
   59|   596k|            entry->index = info->index;
   60|   596k|        }
   61|   679k|        last_info = info;
   62|   679k|    }
   63|  6.82k|    qsort(table, var_count, sizeof(varlookup_t), &compare_varlookups);
   64|  6.82k|    return table;
   65|  6.82k|}
readstat_sav_parse.c:compare_varlookups:
   27|  5.00M|static int compare_varlookups(const void *elem1, const void *elem2) {
   28|  5.00M|    const varlookup_t *v1 = (const varlookup_t *)elem1;
   29|  5.00M|    const varlookup_t *v2 = (const varlookup_t *)elem2;
   30|  5.00M|    return strcasecmp(v1->name, v2->name);
   31|  5.00M|}
readstat_sav_parse.c:compare_key_varlookup:
   21|  23.0k|static int compare_key_varlookup(const void *elem1, const void *elem2) {
   22|  23.0k|    const char *key = (const char *)elem1;
   23|  23.0k|    const varlookup_t *v = (const varlookup_t *)elem2;
   24|  23.0k|    return strcasecmp(key, v->name);
   25|  23.0k|}

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

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

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

spss_format:
   51|   255k|int spss_format(char *buffer, size_t len, spss_format_t *format) {
   52|   255k|    if (format->type < 0 
  ------------------
  |  Branch (52:9): [True: 0, False: 255k]
  ------------------
   53|   255k|            || format->type >= sizeof(spss_type_strings)/sizeof(spss_type_strings[0])
  ------------------
  |  Branch (53:16): [True: 5.93k, False: 249k]
  ------------------
   54|   249k|            || spss_type_strings[format->type][0] == '\0') {
  ------------------
  |  Branch (54:16): [True: 26.5k, False: 223k]
  ------------------
   55|  32.5k|        return 0;
   56|  32.5k|    }
   57|   223k|    char *string = spss_type_strings[format->type];
   58|       |
   59|   223k|    if (format->decimal_places || format->type == SPSS_FORMAT_TYPE_F) {
  ------------------
  |  |    6|   150k|#define SPSS_FORMAT_TYPE_F        5
  ------------------
  |  Branch (59:9): [True: 72.7k, False: 150k]
  |  Branch (59:35): [True: 517, False: 149k]
  ------------------
   60|  73.2k|        snprintf(buffer, len, "%s%d.%d", string, format->width, format->decimal_places);
   61|   149k|    } else if (format->width) {
  ------------------
  |  Branch (61:16): [True: 91.9k, False: 57.9k]
  ------------------
   62|  91.9k|        snprintf(buffer, len, "%s%d", string, format->width);
   63|  91.9k|    } else {
   64|  57.9k|        snprintf(buffer, len, "%s", string);
   65|  57.9k|    }
   66|       |
   67|   223k|    return 1;
   68|   255k|}
spss_varinfo_compare:
   70|   328k|int spss_varinfo_compare(const void *elem1, const void *elem2) {
   71|   328k|    int offset = *(int *)elem1;
   72|   328k|    const spss_varinfo_t *v = *(const spss_varinfo_t **)elem2;
   73|   328k|    if (offset < v->offset)
  ------------------
  |  Branch (73:9): [True: 154k, False: 173k]
  ------------------
   74|   154k|        return -1;
   75|   173k|    return (offset > v->offset);
   76|   328k|}
spss_varinfo_free:
   78|   433k|void spss_varinfo_free(spss_varinfo_t *info) {
   79|   433k|    if (info) {
  ------------------
  |  Branch (79:9): [True: 433k, False: 12]
  ------------------
   80|   433k|        if (info->label)
  ------------------
  |  Branch (80:13): [True: 1.01k, False: 432k]
  ------------------
   81|  1.01k|            free(info->label);
   82|   433k|        free(info);
   83|   433k|    }
   84|   433k|}
spss_missingness_for_info:
  127|   255k|readstat_missingness_t spss_missingness_for_info(spss_varinfo_t *info) {
  128|   255k|    readstat_missingness_t missingness;
  129|   255k|    memset(&missingness, '\0', sizeof(readstat_missingness_t));
  130|       |
  131|   255k|    if (info->missing_range) {
  ------------------
  |  Branch (131:9): [True: 1.98k, False: 253k]
  ------------------
  132|  1.98k|        missingness.missing_ranges_count++;
  133|  1.98k|        missingness.missing_ranges[0] = spss_boxed_missing_value(info, 0);
  134|  1.98k|        missingness.missing_ranges[1] = spss_boxed_missing_value(info, 1);
  135|       |
  136|  1.98k|        if (info->n_missing_values == 3) {
  ------------------
  |  Branch (136:13): [True: 766, False: 1.22k]
  ------------------
  137|    766|            missingness.missing_ranges_count++;
  138|    766|            missingness.missing_ranges[2] = missingness.missing_ranges[3] = spss_boxed_missing_value(info, 2);
  139|    766|        }
  140|   253k|    } else if (info->n_missing_values > 0) {
  ------------------
  |  Branch (140:16): [True: 1.78k, False: 251k]
  ------------------
  141|  1.78k|        missingness.missing_ranges_count = info->n_missing_values;
  142|  1.78k|        int i=0;
  143|  5.49k|        for (i=0; i<info->n_missing_values; i++) {
  ------------------
  |  Branch (143:19): [True: 3.71k, False: 1.78k]
  ------------------
  144|  3.71k|            missingness.missing_ranges[2*i] = missingness.missing_ranges[2*i+1] = spss_boxed_missing_value(info, i);
  145|  3.71k|        }
  146|  1.78k|    }
  147|   255k|    return missingness;
  148|   255k|}
spss_init_variable_for_info:
  151|   255k|        iconv_t converter) {
  152|   255k|    readstat_variable_t *variable = calloc(1, sizeof(readstat_variable_t));
  153|       |
  154|   255k|    variable->index = info->index;
  155|   255k|    variable->index_after_skipping = index_after_skipping;
  156|   255k|    variable->type = info->type;
  157|   255k|    if (info->string_length) {
  ------------------
  |  Branch (157:9): [True: 1.03k, False: 254k]
  ------------------
  158|  1.03k|        variable->storage_width = info->string_length;
  159|   254k|    } else {
  160|   254k|        variable->storage_width = 8 * info->width;
  161|   254k|    }
  162|       |
  163|   255k|    if (info->longname[0]) {
  ------------------
  |  Branch (163:9): [True: 252k, False: 3.23k]
  ------------------
  164|   252k|        readstat_convert(variable->name, sizeof(variable->name),
  165|   252k|                info->longname, sizeof(info->longname), converter);
  166|   252k|    } else {
  167|  3.23k|        readstat_convert(variable->name, sizeof(variable->name),
  168|  3.23k|                info->name, sizeof(info->name), converter);
  169|  3.23k|    }
  170|   255k|    if (info->label) {
  ------------------
  |  Branch (170:9): [True: 732, False: 254k]
  ------------------
  171|    732|        snprintf(variable->label, sizeof(variable->label), "%s", info->label);
  172|    732|    }
  173|       |
  174|   255k|    spss_format(variable->format, sizeof(variable->format), &info->print_format);
  175|       |
  176|   255k|    variable->missingness = spss_missingness_for_info(info);
  177|   255k|    variable->measure = info->measure;
  178|   255k|    if (info->display_width) {
  ------------------
  |  Branch (178:9): [True: 2.59k, False: 253k]
  ------------------
  179|  2.59k|        variable->display_width = info->display_width;
  180|   253k|    } else {
  181|   253k|        variable->display_width = info->print_format.width;
  182|   253k|    }
  183|       |
  184|   255k|    return variable;
  185|   255k|}
spss_measure_to_readstat_measure:
  199|  6.09k|readstat_measure_t spss_measure_to_readstat_measure(uint32_t sav_measure) {
  200|  6.09k|    if (sav_measure == SAV_MEASURE_NOMINAL)
  ------------------
  |  |   47|  6.09k|#define SAV_MEASURE_NOMINAL     1
  ------------------
  |  Branch (200:9): [True: 163, False: 5.93k]
  ------------------
  201|    163|        return READSTAT_MEASURE_NOMINAL;
  202|  5.93k|    if (sav_measure == SAV_MEASURE_ORDINAL)
  ------------------
  |  |   48|  5.93k|#define SAV_MEASURE_ORDINAL     2
  ------------------
  |  Branch (202:9): [True: 315, False: 5.61k]
  ------------------
  203|    315|        return READSTAT_MEASURE_ORDINAL;
  204|  5.61k|    if (sav_measure == SAV_MEASURE_SCALE)
  ------------------
  |  |   49|  5.61k|#define SAV_MEASURE_SCALE       3
  ------------------
  |  Branch (204:9): [True: 98, False: 5.52k]
  ------------------
  205|     98|        return READSTAT_MEASURE_SCALE;
  206|  5.52k|    return READSTAT_MEASURE_UNKNOWN;
  207|  5.61k|}
spss_alignment_to_readstat_alignment:
  221|  6.09k|readstat_alignment_t spss_alignment_to_readstat_alignment(uint32_t sav_alignment) {
  222|  6.09k|    if (sav_alignment == SAV_ALIGNMENT_LEFT)
  ------------------
  |  |   51|  6.09k|#define SAV_ALIGNMENT_LEFT      0
  ------------------
  |  Branch (222:9): [True: 1.61k, False: 4.48k]
  ------------------
  223|  1.61k|        return READSTAT_ALIGNMENT_LEFT;
  224|  4.48k|    if (sav_alignment == SAV_ALIGNMENT_CENTER)
  ------------------
  |  |   53|  4.48k|#define SAV_ALIGNMENT_CENTER    2
  ------------------
  |  Branch (224:9): [True: 375, False: 4.10k]
  ------------------
  225|    375|        return READSTAT_ALIGNMENT_CENTER;
  226|  4.10k|    if (sav_alignment == SAV_ALIGNMENT_RIGHT)
  ------------------
  |  |   52|  4.10k|#define SAV_ALIGNMENT_RIGHT     1
  ------------------
  |  Branch (226:9): [True: 122, False: 3.98k]
  ------------------
  227|    122|        return READSTAT_ALIGNMENT_RIGHT;
  228|  3.98k|    return READSTAT_ALIGNMENT_UNKNOWN;
  229|  4.10k|}
readstat_spss.c:spss_boxed_missing_value:
  120|  8.45k|static readstat_value_t spss_boxed_missing_value(spss_varinfo_t *info, int i) {
  121|  8.45k|    if (info->type == READSTAT_TYPE_DOUBLE) {
  ------------------
  |  Branch (121:9): [True: 4.83k, False: 3.61k]
  ------------------
  122|  4.83k|        return spss_boxed_double_value(info->missing_double_values[i]);
  123|  4.83k|    }
  124|  3.61k|    return spss_boxed_string_value(info->missing_string_values[i]);
  125|  8.45k|}
readstat_spss.c:spss_boxed_double_value:
  103|  4.83k|static readstat_value_t spss_boxed_double_value(double fp_value) {
  104|  4.83k|    readstat_value_t value = {
  105|  4.83k|        .type = READSTAT_TYPE_DOUBLE,
  106|  4.83k|        .v = { .double_value = fp_value },
  107|       |        .is_system_missing = isnan(fp_value)
  108|  4.83k|    };
  109|  4.83k|    return value;
  110|  4.83k|}
readstat_spss.c:spss_boxed_string_value:
  112|  3.61k|static readstat_value_t spss_boxed_string_value(const char *string) {
  113|  3.61k|    readstat_value_t value = {
  114|  3.61k|        .type = READSTAT_TYPE_STRING,
  115|  3.61k|        .v = { .string_value = string }
  116|  3.61k|    };
  117|  3.61k|    return value;
  118|  3.61k|}

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

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

