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

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

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

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

readstat_convert:
   39|  1.19M|readstat_error_t readstat_convert(char *dst, size_t dst_len, const char *src, size_t src_len, iconv_t converter) {
   40|  1.19M|    return readstat_convert_impl(dst, dst_len, src, src_len, converter, 1);
   41|  1.19M|}
readstat_convert.c:readstat_convert_impl:
    8|  1.19M|        iconv_t converter, int trim_spaces) {
    9|       |    /* strip off spaces from the input because the programs use ASCII space
   10|       |     * padding even with non-ASCII encoding. */
   11|  6.45M|    while (src_len && ((trim_spaces && src[src_len-1] == ' ') || src[src_len-1] == '\0')) {
  ------------------
  |  Branch (11:12): [True: 6.37M, False: 85.6k]
  |  Branch (11:25): [True: 6.37M, False: 0]
  |  Branch (11:40): [True: 2.64M, False: 3.72M]
  |  Branch (11:66): [True: 2.61M, False: 1.10M]
  ------------------
   12|  5.26M|        src_len--;
   13|  5.26M|    }
   14|  1.19M|    if (dst_len == 0) {
  ------------------
  |  Branch (14:9): [True: 0, False: 1.19M]
  ------------------
   15|      0|        return READSTAT_ERROR_CONVERT_LONG_STRING;
   16|  1.19M|    } else if (converter) {
  ------------------
  |  Branch (16:16): [True: 8.65k, False: 1.18M]
  ------------------
   17|  8.65k|        size_t dst_left = dst_len - 1;
   18|  8.65k|        char *dst_end = dst;
   19|  8.65k|        size_t status = iconv(converter, (readstat_iconv_inbuf_t)&src, &src_len, &dst_end, &dst_left);
   20|  8.65k|        if (status == (size_t)-1) {
  ------------------
  |  Branch (20:13): [True: 2.33k, False: 6.32k]
  ------------------
   21|  2.33k|            if (errno == E2BIG) {
  ------------------
  |  Branch (21:17): [True: 194, False: 2.13k]
  ------------------
   22|    194|                return READSTAT_ERROR_CONVERT_LONG_STRING;
   23|  2.13k|            } else if (errno == EILSEQ) {
  ------------------
  |  Branch (23:24): [True: 1.47k, False: 658]
  ------------------
   24|  1.47k|                return READSTAT_ERROR_CONVERT_BAD_STRING;
   25|  1.47k|            } else if (errno != EINVAL) { /* EINVAL indicates improper truncation; accept it */
  ------------------
  |  Branch (25:24): [True: 0, False: 658]
  ------------------
   26|      0|                return READSTAT_ERROR_CONVERT;
   27|      0|            }
   28|  2.33k|        }
   29|  6.98k|        dst[dst_len - dst_left - 1] = '\0';
   30|  1.18M|    } else if (src_len + 1 > dst_len) {
  ------------------
  |  Branch (30:16): [True: 20, False: 1.18M]
  ------------------
   31|     20|        return READSTAT_ERROR_CONVERT_LONG_STRING;
   32|  1.18M|    } else {
   33|  1.18M|        memcpy(dst, src, src_len);
   34|  1.18M|        dst[src_len] = '\0';
   35|  1.18M|    }
   36|  1.19M|    return READSTAT_OK;
   37|  1.19M|}

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

readstat_malloc:
   10|   318k|void *readstat_malloc(size_t len) {
   11|   318k|    if (len > MAX_MALLOC_SIZE || len == 0) {
  ------------------
  |  |    3|   636k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
  |  Branch (11:9): [True: 551, False: 317k]
  |  Branch (11:34): [True: 1.00k, False: 316k]
  ------------------
   12|  1.56k|        return NULL;
   13|  1.56k|    }
   14|   316k|    return malloc(len);
   15|   318k|}
readstat_calloc:
   17|   456k|void *readstat_calloc(size_t count, size_t size) {
   18|   456k|    if (count > MAX_MALLOC_SIZE || size > MAX_MALLOC_SIZE || count * size > MAX_MALLOC_SIZE) {
  ------------------
  |  |    3|   913k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
                  if (count > MAX_MALLOC_SIZE || size > MAX_MALLOC_SIZE || count * size > MAX_MALLOC_SIZE) {
  ------------------
  |  |    3|   913k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
                  if (count > MAX_MALLOC_SIZE || size > MAX_MALLOC_SIZE || count * size > MAX_MALLOC_SIZE) {
  ------------------
  |  |    3|   456k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
  |  Branch (18:9): [True: 0, False: 456k]
  |  Branch (18:36): [True: 0, False: 456k]
  |  Branch (18:62): [True: 0, False: 456k]
  ------------------
   19|      0|        return NULL;
   20|      0|    }
   21|   456k|    if (count == 0 || size == 0) {
  ------------------
  |  Branch (21:9): [True: 52, False: 456k]
  |  Branch (21:23): [True: 0, False: 456k]
  ------------------
   22|     52|        return NULL;
   23|     52|    }
   24|   456k|    return calloc(count, size);
   25|   456k|}
readstat_realloc:
   27|  7.68k|void *readstat_realloc(void *ptr, size_t len) {
   28|  7.68k|    if (len > MAX_MALLOC_SIZE || len == 0) {
  ------------------
  |  |    3|  15.3k|#define MAX_MALLOC_SIZE 0x1000000
  ------------------
  |  Branch (28:9): [True: 65, False: 7.61k]
  |  Branch (28:34): [True: 1, False: 7.61k]
  ------------------
   29|     66|        if (ptr)
  ------------------
  |  Branch (29:13): [True: 14, False: 52]
  ------------------
   30|     14|            free(ptr);
   31|     66|        return NULL;
   32|     66|    }
   33|  7.61k|    return realloc(ptr, len);
   34|  7.68k|}

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

sav_ctx_init:
   23|  6.65k|sav_ctx_t *sav_ctx_init(sav_file_header_record_t *header, readstat_io_t *io) {
   24|  6.65k|    sav_ctx_t *ctx = readstat_calloc(1, sizeof(sav_ctx_t));
   25|  6.65k|    if (ctx == NULL) {
  ------------------
  |  Branch (25:9): [True: 0, False: 6.65k]
  ------------------
   26|      0|        return NULL;
   27|      0|    }
   28|       |
   29|  6.65k|    if (memcmp(&header->rec_type, "$FL2", 4) == 0) {
  ------------------
  |  Branch (29:9): [True: 4.08k, False: 2.57k]
  ------------------
   30|  4.08k|        ctx->format_version = 2;
   31|  4.08k|    } else if (memcmp(&header->rec_type, "$FL3", 4) == 0) {
  ------------------
  |  Branch (31:16): [True: 2.54k, False: 32]
  ------------------
   32|  2.54k|        ctx->format_version = 3;
   33|  2.54k|    } else {
   34|     32|        sav_ctx_free(ctx);
   35|     32|        return NULL;
   36|     32|    }
   37|       |    
   38|  6.62k|    ctx->bswap = !(header->layout_code == 2 || header->layout_code == 3);
  ------------------
  |  Branch (38:20): [True: 4.44k, False: 2.18k]
  |  Branch (38:48): [True: 317, False: 1.86k]
  ------------------
   39|  6.62k|    ctx->endianness = (machine_is_little_endian() ^ ctx->bswap) ? READSTAT_ENDIAN_LITTLE : READSTAT_ENDIAN_BIG;
  ------------------
  |  Branch (39:23): [True: 4.75k, False: 1.86k]
  ------------------
   40|       |
   41|  6.62k|    if (header->compression == 1 || byteswap4(header->compression) == 1) {
  ------------------
  |  Branch (41:9): [True: 722, False: 5.90k]
  |  Branch (41:37): [True: 219, False: 5.68k]
  ------------------
   42|    941|        ctx->compression = READSTAT_COMPRESS_ROWS;
   43|  5.68k|    } else if (header->compression == 2 || byteswap4(header->compression) == 2) {
  ------------------
  |  Branch (43:16): [True: 336, False: 5.34k]
  |  Branch (43:44): [True: 244, False: 5.10k]
  ------------------
   44|    580|        ctx->compression = READSTAT_COMPRESS_BINARY;
   45|    580|    }
   46|  6.62k|    ctx->record_count = ctx->bswap ? byteswap4(header->ncases) : header->ncases;
  ------------------
  |  Branch (46:25): [True: 1.86k, False: 4.75k]
  ------------------
   47|  6.62k|    if (ctx->record_count < 0 || ctx->record_count > INT32_MAX / 2) {
  ------------------
  |  Branch (47:9): [True: 1.51k, False: 5.11k]
  |  Branch (47:34): [True: 586, False: 4.52k]
  ------------------
   48|       |        /* -1 means unknown; PSPP also treats implausibly large counts as unknown */
   49|  2.09k|        ctx->record_count = -1;
   50|  2.09k|    }
   51|  6.62k|    ctx->row_limit = -1;
   52|  6.62k|    ctx->fweight_index = ctx->bswap ? byteswap4(header->weight_index) : header->weight_index;
  ------------------
  |  Branch (52:26): [True: 1.86k, False: 4.75k]
  ------------------
   53|       |
   54|  6.62k|    ctx->missing_double = SAV_MISSING_DOUBLE;
  ------------------
  |  |   43|  6.62k|#define SAV_MISSING_DOUBLE   0xFFEFFFFFFFFFFFFFUL
  ------------------
   55|  6.62k|    ctx->lowest_double = SAV_LOWEST_DOUBLE;
  ------------------
  |  |   44|  6.62k|#define SAV_LOWEST_DOUBLE    0xFFEFFFFFFFFFFFFEUL
  ------------------
   56|  6.62k|    ctx->highest_double = SAV_HIGHEST_DOUBLE;
  ------------------
  |  |   42|  6.62k|#define SAV_HIGHEST_DOUBLE   0x7FEFFFFFFFFFFFFFUL
  ------------------
   57|       |    
   58|  6.62k|    ctx->bias = ctx->bswap ? byteswap_double(header->bias) : header->bias;
  ------------------
  |  Branch (58:17): [True: 1.86k, False: 4.75k]
  ------------------
   59|       |    
   60|  6.62k|    ctx->varinfo_capacity = SAV_VARINFO_INITIAL_CAPACITY;
  ------------------
  |  |   21|  6.62k|#define SAV_VARINFO_INITIAL_CAPACITY  512
  ------------------
   61|       |    
   62|  6.62k|    if ((ctx->varinfo = readstat_calloc(ctx->varinfo_capacity, sizeof(spss_varinfo_t *))) == NULL) {
  ------------------
  |  Branch (62:9): [True: 0, False: 6.62k]
  ------------------
   63|      0|        sav_ctx_free(ctx);
   64|      0|        return NULL;
   65|      0|    }
   66|       |
   67|  6.62k|    ctx->mr_sets = NULL;
   68|       |
   69|  6.62k|    ctx->io = io;
   70|       |    
   71|  6.62k|    return ctx;
   72|  6.62k|}
sav_ctx_free:
   74|  6.65k|void sav_ctx_free(sav_ctx_t *ctx) {
   75|  6.65k|    if (ctx->varinfo) {
  ------------------
  |  Branch (75:9): [True: 6.62k, False: 32]
  ------------------
   76|  6.62k|        int i;
   77|   447k|        for (i=0; i<ctx->var_index; i++) {
  ------------------
  |  Branch (77:19): [True: 440k, False: 6.62k]
  ------------------
   78|   440k|            spss_varinfo_free(ctx->varinfo[i]);
   79|   440k|        }
   80|  6.62k|        free(ctx->varinfo);
   81|  6.62k|    }
   82|  6.65k|    if (ctx->variables) {
  ------------------
  |  Branch (82:9): [True: 1.89k, False: 4.76k]
  ------------------
   83|  1.89k|        int i;
   84|  30.0k|        for (i=0; i<ctx->var_count; i++) {
  ------------------
  |  Branch (84:19): [True: 28.2k, False: 1.89k]
  ------------------
   85|  28.2k|            if (ctx->variables[i])
  ------------------
  |  Branch (85:17): [True: 28.0k, False: 195]
  ------------------
   86|  28.0k|                free(ctx->variables[i]);
   87|  28.2k|        }
   88|  1.89k|        free(ctx->variables);
   89|  1.89k|    }
   90|  6.65k|    if (ctx->raw_string)
  ------------------
  |  Branch (90:9): [True: 1.65k, False: 5.00k]
  ------------------
   91|  1.65k|        free(ctx->raw_string);
   92|  6.65k|    if (ctx->utf8_string)
  ------------------
  |  Branch (92:9): [True: 1.60k, False: 5.04k]
  ------------------
   93|  1.60k|        free(ctx->utf8_string);
   94|  6.65k|    if (ctx->converter)
  ------------------
  |  Branch (94:9): [True: 221, False: 6.43k]
  ------------------
   95|    221|        iconv_close(ctx->converter);
   96|  6.65k|    if (ctx->variable_display_values) {
  ------------------
  |  Branch (96:9): [True: 241, False: 6.41k]
  ------------------
   97|    241|        free(ctx->variable_display_values);
   98|    241|    }
   99|  6.65k|    if (ctx->mr_sets) {
  ------------------
  |  Branch (99:9): [True: 889, False: 5.76k]
  ------------------
  100|  22.1k|        for (size_t i = 0; i < ctx->multiple_response_sets_length; i++) {
  ------------------
  |  Branch (100:28): [True: 21.2k, False: 889]
  ------------------
  101|  21.2k|            if (ctx->mr_sets[i].name) {
  ------------------
  |  Branch (101:17): [True: 21.2k, False: 0]
  ------------------
  102|  21.2k|                free(ctx->mr_sets[i].name);
  103|  21.2k|            }
  104|  21.2k|            if (ctx->mr_sets[i].label) {
  ------------------
  |  Branch (104:17): [True: 21.2k, False: 0]
  ------------------
  105|  21.2k|                free(ctx->mr_sets[i].label);
  106|  21.2k|            }
  107|  21.2k|            if (ctx->mr_sets[i].counted_string) {
  ------------------
  |  Branch (107:17): [True: 631, False: 20.6k]
  ------------------
  108|    631|                free(ctx->mr_sets[i].counted_string);
  109|    631|            }
  110|  21.2k|            if (ctx->mr_sets[i].subvariables) {
  ------------------
  |  Branch (110:17): [True: 18.4k, False: 2.84k]
  ------------------
  111|  72.2k|                for (size_t j = 0; j < ctx->mr_sets[i].num_subvars; j++) {
  ------------------
  |  Branch (111:36): [True: 53.8k, False: 18.4k]
  ------------------
  112|  53.8k|                    if (ctx->mr_sets[i].subvariables[j]) {
  ------------------
  |  Branch (112:25): [True: 53.8k, False: 0]
  ------------------
  113|  53.8k|                        free(ctx->mr_sets[i].subvariables[j]);
  114|  53.8k|                    }
  115|  53.8k|                }
  116|  18.4k|                free(ctx->mr_sets[i].subvariables);
  117|  18.4k|            }
  118|  21.2k|        }
  119|    889|        free(ctx->mr_sets);
  120|    889|    }
  121|  6.65k|    free(ctx);
  122|  6.65k|}

sav_decompress_row:
   77|  2.69M|void sav_decompress_row(struct sav_row_stream_s *state) {
   78|  2.69M|    double fp_value;
   79|  2.69M|    uint64_t missing_value = state->bswap ? byteswap8(state->missing_value) : state->missing_value;
  ------------------
  |  Branch (79:30): [True: 398k, False: 2.29M]
  ------------------
   80|  2.69M|    int i = 8 - state->i;
   81|  3.12M|    while (1) {
  ------------------
  |  Branch (81:12): [True: 3.12M, Folded]
  ------------------
   82|  3.12M|        if (i == 8) {
  ------------------
  |  Branch (82:13): [True: 760k, False: 2.36M]
  ------------------
   83|   760k|            if (state->avail_in < 8) {
  ------------------
  |  Branch (83:17): [True: 537, False: 759k]
  ------------------
   84|    537|                state->status = SAV_ROW_STREAM_NEED_DATA;
   85|    537|                goto done;
   86|    537|            }
   87|       |
   88|   759k|            memcpy(state->chunk, state->next_in, 8);
   89|   759k|            state->next_in += 8;
   90|   759k|            state->avail_in -= 8;
   91|   759k|            i = 0;
   92|   759k|        }
   93|       |
   94|  6.50M|        while (i<8) {
  ------------------
  |  Branch (94:16): [True: 6.07M, False: 425k]
  ------------------
   95|  6.07M|            switch (state->chunk[i]) {
   96|  2.76M|                case 0:
  ------------------
  |  Branch (96:17): [True: 2.76M, False: 3.31M]
  ------------------
   97|  2.76M|                    break;
   98|     64|                case 252:
  ------------------
  |  Branch (98:17): [True: 64, False: 6.07M]
  ------------------
   99|     64|                    state->status = SAV_ROW_STREAM_FINISHED_ALL;
  100|     64|                    goto done;
  101|   540k|                case 253:
  ------------------
  |  Branch (101:17): [True: 540k, False: 5.53M]
  ------------------
  102|   540k|                    if (state->avail_in < 8) {
  ------------------
  |  Branch (102:25): [True: 104, False: 540k]
  ------------------
  103|    104|                        state->status = SAV_ROW_STREAM_NEED_DATA;
  104|    104|                        goto done;
  105|    104|                    }
  106|   540k|                    memcpy(state->next_out, state->next_in, 8);
  107|   540k|                    state->next_out += 8;
  108|   540k|                    state->avail_out -= 8;
  109|   540k|                    state->next_in += 8;
  110|   540k|                    state->avail_in -= 8;
  111|   540k|                    break;
  112|  6.82k|                case 254:
  ------------------
  |  Branch (112:17): [True: 6.82k, False: 6.07M]
  ------------------
  113|  6.82k|                    memset(state->next_out, ' ', 8);
  114|  6.82k|                    state->next_out += 8;
  115|  6.82k|                    state->avail_out -= 8;
  116|  6.82k|                    break;
  117|  93.6k|                case 255:
  ------------------
  |  Branch (117:17): [True: 93.6k, False: 5.98M]
  ------------------
  118|  93.6k|                    memcpy(state->next_out, &missing_value, sizeof(uint64_t));
  119|  93.6k|                    state->next_out += 8;
  120|  93.6k|                    state->avail_out -= 8;
  121|  93.6k|                    break;
  122|  2.67M|                default:
  ------------------
  |  Branch (122:17): [True: 2.67M, False: 3.40M]
  ------------------
  123|  2.67M|                    fp_value = state->chunk[i] - state->bias;
  124|  2.67M|                    fp_value = state->bswap ? byteswap_double(fp_value) : fp_value;
  ------------------
  |  Branch (124:32): [True: 679k, False: 1.99M]
  ------------------
  125|  2.67M|                    memcpy(state->next_out, &fp_value, sizeof(double));
  126|  2.67M|                    state->next_out += 8;
  127|  2.67M|                    state->avail_out -= 8;
  128|  2.67M|                    break;
  129|  6.07M|            }
  130|  6.07M|            i++;
  131|  6.07M|            if (state->avail_out < 8) {
  ------------------
  |  Branch (131:17): [True: 2.69M, False: 3.38M]
  ------------------
  132|  2.69M|                state->status = SAV_ROW_STREAM_FINISHED_ROW;
  133|  2.69M|                goto done;
  134|  2.69M|            }
  135|  6.07M|        }
  136|  3.12M|    }
  137|  2.69M|done:
  138|  2.69M|    state->i = 8 - i;
  139|  2.69M|}

sav_parse_long_variable_names_record:
  159|  1.18k|readstat_error_t sav_parse_long_variable_names_record(void *data, int count, sav_ctx_t *ctx) {
  160|  1.18k|	unsigned char *c_data = (unsigned char *)data;
  161|  1.18k|	int var_count = count_vars(ctx);
  162|  1.18k|	readstat_error_t retval = READSTAT_OK;
  163|       |	
  164|  1.18k|	char temp_key[8+1];
  165|  1.18k|	char temp_val[64+1];
  166|  1.18k|	unsigned char *str_start = NULL;
  167|  1.18k|	size_t str_len = 0;
  168|       |	
  169|  1.18k|	char error_buf[8192];
  170|  1.18k|	unsigned char *p = c_data;
  171|  1.18k|	unsigned char *pe = c_data + count;
  172|       |	
  173|  1.18k|	varlookup_t *table = build_lookup_table(var_count, ctx);
  174|       |	
  175|  1.18k|	unsigned char *eof = pe;
  176|       |	
  177|  1.18k|	int cs;
  178|       |	
  179|       |	
  180|  1.18k|#line 181 "src/spss/readstat_sav_parse.c"
  181|  1.18k|	{
  182|  1.18k|		cs = (int)sav_long_variable_parse_start;
  183|  1.18k|	}
  184|       |	
  185|  1.18k|#line 186 "src/spss/readstat_sav_parse.c"
  186|  1.18k|	{
  187|  1.18k|		int _klen;
  188|  1.18k|		unsigned int _trans = 0;
  189|  1.18k|		const unsigned char * _keys;
  190|  1.18k|		const signed char * _acts;
  191|  1.18k|		unsigned int _nacts;
  192|  13.2k|		_resume: {}
  193|  13.2k|		if ( p == pe && p != eof )
  ------------------
  |  Branch (193:8): [True: 1.15k, False: 12.0k]
  |  Branch (193:19): [True: 0, False: 1.15k]
  ------------------
  194|      0|			goto _out;
  195|  13.2k|		if ( p == eof ) {
  ------------------
  |  Branch (195:8): [True: 1.15k, False: 12.0k]
  ------------------
  196|  1.15k|			if ( _sav_long_variable_parse_eof_trans[cs] > 0 ) {
  ------------------
  |  Branch (196:9): [True: 1.15k, False: 0]
  ------------------
  197|  1.15k|				_trans = (unsigned int)_sav_long_variable_parse_eof_trans[cs] - 1;
  198|  1.15k|			}
  199|  1.15k|		}
  200|  12.0k|		else {
  201|  12.0k|			_keys = ( _sav_long_variable_parse_trans_keys + (_sav_long_variable_parse_key_offsets[cs]));
  202|  12.0k|			_trans = (unsigned int)_sav_long_variable_parse_index_offsets[cs];
  203|       |			
  204|  12.0k|			_klen = (int)_sav_long_variable_parse_single_lengths[cs];
  205|  12.0k|			if ( _klen > 0 ) {
  ------------------
  |  Branch (205:9): [True: 12.0k, False: 0]
  ------------------
  206|  12.0k|				const unsigned char *_lower = _keys;
  207|  12.0k|				const unsigned char *_upper = _keys + _klen - 1;
  208|  12.0k|				const unsigned char *_mid;
  209|  27.1k|				while ( 1 ) {
  ------------------
  |  Branch (209:13): [True: 27.1k, Folded]
  ------------------
  210|  27.1k|					if ( _upper < _lower ) {
  ------------------
  |  Branch (210:11): [True: 8.39k, False: 18.7k]
  ------------------
  211|  8.39k|						_keys += _klen;
  212|  8.39k|						_trans += (unsigned int)_klen;
  213|  8.39k|						break;
  214|  8.39k|					}
  215|       |					
  216|  18.7k|					_mid = _lower + ((_upper-_lower) >> 1);
  217|  18.7k|					if ( ( (*( p))) < (*( _mid)) )
  ------------------
  |  Branch (217:11): [True: 8.47k, False: 10.3k]
  ------------------
  218|  8.47k|						_upper = _mid - 1;
  219|  10.3k|					else if ( ( (*( p))) > (*( _mid)) )
  ------------------
  |  Branch (219:16): [True: 6.63k, False: 3.66k]
  ------------------
  220|  6.63k|						_lower = _mid + 1;
  221|  3.66k|					else {
  222|  3.66k|						_trans += (unsigned int)(_mid - _keys);
  223|  3.66k|						goto _match;
  224|  3.66k|					}
  225|  18.7k|				}
  226|  12.0k|			}
  227|       |			
  228|  8.39k|			_klen = (int)_sav_long_variable_parse_range_lengths[cs];
  229|  8.39k|			if ( _klen > 0 ) {
  ------------------
  |  Branch (229:9): [True: 8.39k, False: 7]
  ------------------
  230|  8.39k|				const unsigned char *_lower = _keys;
  231|  8.39k|				const unsigned char *_upper = _keys + (_klen<<1) - 2;
  232|  8.39k|				const unsigned char *_mid;
  233|  21.7k|				while ( 1 ) {
  ------------------
  |  Branch (233:13): [True: 21.7k, Folded]
  ------------------
  234|  21.7k|					if ( _upper < _lower ) {
  ------------------
  |  Branch (234:11): [True: 8.36k, False: 13.3k]
  ------------------
  235|  8.36k|						_trans += (unsigned int)_klen;
  236|  8.36k|						break;
  237|  8.36k|					}
  238|       |					
  239|  13.3k|					_mid = _lower + (((_upper-_lower) >> 1) & ~1);
  240|  13.3k|					if ( ( (*( p))) < (*( _mid)) )
  ------------------
  |  Branch (240:11): [True: 2.86k, False: 10.5k]
  ------------------
  241|  2.86k|						_upper = _mid - 2;
  242|  10.5k|					else if ( ( (*( p))) > (*( _mid + 1)) )
  ------------------
  |  Branch (242:16): [True: 10.5k, False: 26]
  ------------------
  243|  10.5k|						_lower = _mid + 2;
  244|     26|					else {
  245|     26|						_trans += (unsigned int)((_mid - _keys)>>1);
  246|     26|						break;
  247|     26|					}
  248|  13.3k|				}
  249|  8.39k|			}
  250|       |			
  251|  12.0k|			_match: {}
  252|  12.0k|		}
  253|  13.2k|		cs = (int)_sav_long_variable_parse_cond_targs[_trans];
  254|       |		
  255|  13.2k|		if ( _sav_long_variable_parse_cond_actions[_trans] != 0 ) {
  ------------------
  |  Branch (255:8): [True: 9.04k, False: 4.16k]
  ------------------
  256|       |			
  257|  9.04k|			_acts = ( _sav_long_variable_parse_actions + (_sav_long_variable_parse_cond_actions[_trans]));
  258|  9.04k|			_nacts = (unsigned int)(*( _acts));
  259|  9.04k|			_acts += 1;
  260|  24.7k|			while ( _nacts > 0 ) {
  ------------------
  |  Branch (260:12): [True: 15.7k, False: 9.04k]
  ------------------
  261|  15.7k|				switch ( (*( _acts)) )
  ------------------
  |  Branch (261:14): [True: 15.7k, False: 0]
  ------------------
  262|  15.7k|				{
  263|  2.24k|					case 0:  {
  ------------------
  |  Branch (263:6): [True: 2.24k, False: 13.4k]
  ------------------
  264|  2.24k|						{
  265|  2.24k|#line 13 "src/spss/readstat_sav_parse.rl"
  266|       |							
  267|  2.24k|							memcpy(temp_key, str_start, str_len);
  268|  2.24k|							temp_key[str_len] = '\0';
  269|  2.24k|						}
  270|       |						
  271|  2.24k|#line 272 "src/spss/readstat_sav_parse.c"
  272|       |						
  273|  2.24k|						break; 
  274|      0|					}
  275|  2.36k|					case 1:  {
  ------------------
  |  Branch (275:6): [True: 2.36k, False: 13.3k]
  ------------------
  276|  2.36k|						{
  277|  2.36k|#line 20 "src/spss/readstat_sav_parse.rl"
  278|  2.36k|							str_start = p; }
  279|       |						
  280|  2.36k|#line 281 "src/spss/readstat_sav_parse.c"
  281|       |						
  282|  2.36k|						break; 
  283|      0|					}
  284|  2.24k|					case 2:  {
  ------------------
  |  Branch (284:6): [True: 2.24k, False: 13.4k]
  ------------------
  285|  2.24k|						{
  286|  2.24k|#line 20 "src/spss/readstat_sav_parse.rl"
  287|  2.24k|							str_len = p - str_start; }
  288|       |						
  289|  2.24k|#line 290 "src/spss/readstat_sav_parse.c"
  290|       |						
  291|  2.24k|						break; 
  292|      0|					}
  293|  2.22k|					case 3:  {
  ------------------
  |  Branch (293:6): [True: 2.22k, False: 13.5k]
  ------------------
  294|  2.22k|						{
  295|  2.22k|#line 102 "src/spss/readstat_sav_parse.rl"
  296|       |							
  297|  2.22k|							varlookup_t *found = bsearch(temp_key, table, var_count, sizeof(varlookup_t), &compare_key_varlookup);
  298|  2.22k|							if (!found) {
  ------------------
  |  Branch (298:12): [True: 1.64k, False: 576]
  ------------------
  299|  1.64k|								snprintf(error_buf, sizeof(error_buf), "Failed to find %s", temp_key);
  300|  1.64k|								if (ctx->handle.error)
  ------------------
  |  Branch (300:13): [True: 0, False: 1.64k]
  ------------------
  301|      0|								ctx->handle.error(error_buf, ctx->user_ctx);
  302|  1.64k|							} else {
  303|       |								// Handle the edge case where a ghost variable name (from a multi-segment
  304|       |								// variable) is identical to a real variable name. Normally we handle this
  305|       |								// by incrementing the loop variable by n_segments, but n_segments hasn't
  306|       |								// been set when this record is processed. So just set the longname to every
  307|       |								// matching variable, ghost or real.
  308|    576|								varlookup_t *iter_match = found;
  309|  1.52k|								while (iter_match >= table && strcmp(iter_match->name, temp_key) == 0) {
  ------------------
  |  Branch (309:16): [True: 1.17k, False: 350]
  |  Branch (309:39): [True: 953, False: 226]
  ------------------
  310|    953|									spss_varinfo_t *info = ctx->varinfo[iter_match->index];
  311|    953|									snprintf(info->longname, sizeof(info->longname), "%*s", (int)str_len, temp_val);
  312|    953|									iter_match--;
  313|    953|								}
  314|    576|								iter_match = found + 1;
  315|  1.18k|								while (iter_match - table < var_count && strcmp(iter_match->name, temp_key) == 0) {
  ------------------
  |  Branch (315:16): [True: 787, False: 396]
  |  Branch (315:50): [True: 607, False: 180]
  ------------------
  316|    607|									spss_varinfo_t *info = ctx->varinfo[iter_match->index];
  317|    607|									snprintf(info->longname, sizeof(info->longname), "%*s", (int)str_len, temp_val);
  318|    607|									iter_match++;
  319|    607|								}
  320|    576|							}
  321|  2.22k|						}
  322|       |						
  323|  2.22k|#line 324 "src/spss/readstat_sav_parse.c"
  324|       |						
  325|  2.22k|						break; 
  326|      0|					}
  327|  2.22k|					case 4:  {
  ------------------
  |  Branch (327:6): [True: 2.22k, False: 13.5k]
  ------------------
  328|  2.22k|						{
  329|  2.22k|#line 129 "src/spss/readstat_sav_parse.rl"
  330|       |							
  331|  2.22k|							if (str_len > sizeof(temp_val) - 1)
  ------------------
  |  Branch (331:12): [True: 0, False: 2.22k]
  ------------------
  332|      0|							str_len = sizeof(temp_val) - 1;
  333|  2.22k|							memcpy(temp_val, str_start, str_len);
  334|  2.22k|							temp_val[str_len] = '\0';
  335|  2.22k|						}
  336|       |						
  337|  2.22k|#line 338 "src/spss/readstat_sav_parse.c"
  338|       |						
  339|  2.22k|						break; 
  340|      0|					}
  341|  2.22k|					case 5:  {
  ------------------
  |  Branch (341:6): [True: 2.22k, False: 13.5k]
  ------------------
  342|  2.22k|						{
  343|  2.22k|#line 136 "src/spss/readstat_sav_parse.rl"
  344|  2.22k|							str_start = p; }
  345|       |						
  346|  2.22k|#line 347 "src/spss/readstat_sav_parse.c"
  347|       |						
  348|  2.22k|						break; 
  349|      0|					}
  350|  2.22k|					case 6:  {
  ------------------
  |  Branch (350:6): [True: 2.22k, False: 13.5k]
  ------------------
  351|  2.22k|						{
  352|  2.22k|#line 136 "src/spss/readstat_sav_parse.rl"
  353|  2.22k|							str_len = p - str_start; if (str_len > 64) str_len = 64; }
  ------------------
  |  Branch (353:37): [True: 12, False: 2.20k]
  ------------------
  354|       |						
  355|  2.22k|#line 356 "src/spss/readstat_sav_parse.c"
  356|       |						
  357|  2.22k|						break; 
  358|      0|					}
  359|  15.7k|				}
  360|  15.7k|				_nacts -= 1;
  361|  15.7k|				_acts += 1;
  362|  15.7k|			}
  363|       |			
  364|  9.04k|		}
  365|       |		
  366|  13.2k|		if ( p == eof ) {
  ------------------
  |  Branch (366:8): [True: 1.15k, False: 12.0k]
  ------------------
  367|  1.15k|			if ( cs >= 11 )
  ------------------
  |  Branch (367:9): [True: 1.02k, False: 131]
  ------------------
  368|  1.02k|				goto _out;
  369|  1.15k|		}
  370|  12.0k|		else {
  371|  12.0k|			if ( cs != 0 ) {
  ------------------
  |  Branch (371:9): [True: 12.0k, False: 36]
  ------------------
  372|  12.0k|				p += 1;
  373|  12.0k|				goto _resume;
  374|  12.0k|			}
  375|  12.0k|		}
  376|  1.18k|		_out: {}
  377|  1.18k|	}
  378|       |	
  379|      0|#line 144 "src/spss/readstat_sav_parse.rl"
  380|       |	
  381|       |	
  382|  1.18k|	if (cs < 
  ------------------
  |  Branch (382:6): [True: 167, False: 1.02k]
  ------------------
  383|  1.18k|#line 384 "src/spss/readstat_sav_parse.c"
  384|  1.18k|	11
  385|  1.02k|#line 146 "src/spss/readstat_sav_parse.rl"
  386|  1.02k|	|| p != pe) {
  ------------------
  |  Branch (386:5): [True: 0, False: 1.02k]
  ------------------
  387|    167|		if (ctx->handle.error) {
  ------------------
  |  Branch (387:7): [True: 0, False: 167]
  ------------------
  388|      0|			snprintf(error_buf, sizeof(error_buf), "Error parsing string \"%.*s\" around byte #%ld/%d, character %c", 
  389|      0|			count, (char *)data, (long)(p - c_data), count, p < pe ? *p : '?');
  ------------------
  |  Branch (389:52): [True: 0, False: 0]
  ------------------
  390|      0|			ctx->handle.error(error_buf, ctx->user_ctx);
  391|      0|		}
  392|    167|		retval = READSTAT_ERROR_PARSE;
  393|    167|	}
  394|       |	
  395|       |	
  396|  1.18k|	if (table)
  ------------------
  |  Branch (396:6): [True: 775, False: 414]
  ------------------
  397|    775|		free(table);
  398|       |	
  399|       |	/* suppress warning */
  400|  1.18k|	(void)sav_long_variable_parse_en_main;
  401|       |	
  402|  1.18k|	return retval;
  403|  13.2k|}
sav_parse_very_long_string_record:
  498|  1.82k|readstat_error_t sav_parse_very_long_string_record(void *data, int count, sav_ctx_t *ctx) {
  499|  1.82k|	unsigned char *c_data = (unsigned char *)data;
  500|  1.82k|	int var_count = count_vars(ctx);
  501|  1.82k|	readstat_error_t retval = READSTAT_OK;
  502|       |	
  503|  1.82k|	char temp_key[8*4+1];
  504|  1.82k|	unsigned int temp_val = 0;
  505|  1.82k|	unsigned char *str_start = NULL;
  506|  1.82k|	size_t str_len = 0;
  507|       |	
  508|  1.82k|	size_t error_buf_len = 1024 + count;
  509|  1.82k|	char *error_buf = NULL;
  510|  1.82k|	unsigned char *p = c_data;
  511|  1.82k|	unsigned char *pe = c_data + count;
  512|  1.82k|	unsigned char *eof = pe;
  513|       |	
  514|  1.82k|	varlookup_t *table = NULL;
  515|  1.82k|	int cs;
  516|       |	
  517|  1.82k|	error_buf = readstat_malloc(error_buf_len);
  518|  1.82k|	table = build_lookup_table(var_count, ctx);
  519|       |	
  520|       |	
  521|  1.82k|#line 522 "src/spss/readstat_sav_parse.c"
  522|  1.82k|	{
  523|  1.82k|		cs = (int)sav_very_long_string_parse_start;
  524|  1.82k|	}
  525|       |	
  526|  1.82k|#line 527 "src/spss/readstat_sav_parse.c"
  527|  1.82k|	{
  528|  1.82k|		int _klen;
  529|  1.82k|		unsigned int _trans = 0;
  530|  1.82k|		const unsigned char * _keys;
  531|  1.82k|		const signed char * _acts;
  532|  1.82k|		unsigned int _nacts;
  533|  20.7k|		_resume: {}
  534|  20.7k|		if ( p == pe && p != eof )
  ------------------
  |  Branch (534:8): [True: 1.52k, False: 19.2k]
  |  Branch (534:19): [True: 0, False: 1.52k]
  ------------------
  535|      0|			goto _out;
  536|  20.7k|		if ( p == eof ) {
  ------------------
  |  Branch (536:8): [True: 1.52k, False: 19.2k]
  ------------------
  537|  1.52k|			if ( _sav_very_long_string_parse_eof_trans[cs] > 0 ) {
  ------------------
  |  Branch (537:9): [True: 1.52k, False: 0]
  ------------------
  538|  1.52k|				_trans = (unsigned int)_sav_very_long_string_parse_eof_trans[cs] - 1;
  539|  1.52k|			}
  540|  1.52k|		}
  541|  19.2k|		else {
  542|  19.2k|			_keys = ( _sav_very_long_string_parse_trans_keys + (_sav_very_long_string_parse_key_offsets[cs]));
  543|  19.2k|			_trans = (unsigned int)_sav_very_long_string_parse_index_offsets[cs];
  544|       |			
  545|  19.2k|			_klen = (int)_sav_very_long_string_parse_single_lengths[cs];
  546|  19.2k|			if ( _klen > 0 ) {
  ------------------
  |  Branch (546:9): [True: 16.4k, False: 2.82k]
  ------------------
  547|  16.4k|				const unsigned char *_lower = _keys;
  548|  16.4k|				const unsigned char *_upper = _keys + _klen - 1;
  549|  16.4k|				const unsigned char *_mid;
  550|  39.8k|				while ( 1 ) {
  ------------------
  |  Branch (550:13): [True: 39.8k, Folded]
  ------------------
  551|  39.8k|					if ( _upper < _lower ) {
  ------------------
  |  Branch (551:11): [True: 11.9k, False: 27.8k]
  ------------------
  552|  11.9k|						_keys += _klen;
  553|  11.9k|						_trans += (unsigned int)_klen;
  554|  11.9k|						break;
  555|  11.9k|					}
  556|       |					
  557|  27.8k|					_mid = _lower + ((_upper-_lower) >> 1);
  558|  27.8k|					if ( ( (*( p))) < (*( _mid)) )
  ------------------
  |  Branch (558:11): [True: 6.71k, False: 21.1k]
  ------------------
  559|  6.71k|						_upper = _mid - 1;
  560|  21.1k|					else if ( ( (*( p))) > (*( _mid)) )
  ------------------
  |  Branch (560:16): [True: 16.7k, False: 4.43k]
  ------------------
  561|  16.7k|						_lower = _mid + 1;
  562|  4.43k|					else {
  563|  4.43k|						_trans += (unsigned int)(_mid - _keys);
  564|  4.43k|						goto _match;
  565|  4.43k|					}
  566|  27.8k|				}
  567|  16.4k|			}
  568|       |			
  569|  14.8k|			_klen = (int)_sav_very_long_string_parse_range_lengths[cs];
  570|  14.8k|			if ( _klen > 0 ) {
  ------------------
  |  Branch (570:9): [True: 14.8k, False: 9]
  ------------------
  571|  14.8k|				const unsigned char *_lower = _keys;
  572|  14.8k|				const unsigned char *_upper = _keys + (_klen<<1) - 2;
  573|  14.8k|				const unsigned char *_mid;
  574|  30.7k|				while ( 1 ) {
  ------------------
  |  Branch (574:13): [True: 30.7k, Folded]
  ------------------
  575|  30.7k|					if ( _upper < _lower ) {
  ------------------
  |  Branch (575:11): [True: 6.60k, False: 24.1k]
  ------------------
  576|  6.60k|						_trans += (unsigned int)_klen;
  577|  6.60k|						break;
  578|  6.60k|					}
  579|       |					
  580|  24.1k|					_mid = _lower + (((_upper-_lower) >> 1) & ~1);
  581|  24.1k|					if ( ( (*( p))) < (*( _mid)) )
  ------------------
  |  Branch (581:11): [True: 4.81k, False: 19.3k]
  ------------------
  582|  4.81k|						_upper = _mid - 2;
  583|  19.3k|					else if ( ( (*( p))) > (*( _mid + 1)) )
  ------------------
  |  Branch (583:16): [True: 11.1k, False: 8.20k]
  ------------------
  584|  11.1k|						_lower = _mid + 2;
  585|  8.20k|					else {
  586|  8.20k|						_trans += (unsigned int)((_mid - _keys)>>1);
  587|  8.20k|						break;
  588|  8.20k|					}
  589|  24.1k|				}
  590|  14.8k|			}
  591|       |			
  592|  19.2k|			_match: {}
  593|  19.2k|		}
  594|  20.7k|		cs = (int)_sav_very_long_string_parse_cond_targs[_trans];
  595|       |		
  596|  20.7k|		if ( _sav_very_long_string_parse_cond_actions[_trans] != 0 ) {
  ------------------
  |  Branch (596:8): [True: 16.5k, False: 4.25k]
  ------------------
  597|       |			
  598|  16.5k|			_acts = ( _sav_very_long_string_parse_actions + (_sav_very_long_string_parse_cond_actions[_trans]));
  599|  16.5k|			_nacts = (unsigned int)(*( _acts));
  600|  16.5k|			_acts += 1;
  601|  38.4k|			while ( _nacts > 0 ) {
  ------------------
  |  Branch (601:12): [True: 22.1k, False: 16.2k]
  ------------------
  602|  22.1k|				switch ( (*( _acts)) )
  ------------------
  |  Branch (602:14): [True: 22.1k, False: 0]
  ------------------
  603|  22.1k|				{
  604|  2.82k|					case 0:  {
  ------------------
  |  Branch (604:6): [True: 2.82k, False: 19.3k]
  ------------------
  605|  2.82k|						{
  606|  2.82k|#line 13 "src/spss/readstat_sav_parse.rl"
  607|       |							
  608|  2.82k|							memcpy(temp_key, str_start, str_len);
  609|  2.82k|							temp_key[str_len] = '\0';
  610|  2.82k|						}
  611|       |						
  612|  2.82k|#line 613 "src/spss/readstat_sav_parse.c"
  613|       |						
  614|  2.82k|						break; 
  615|      0|					}
  616|  2.95k|					case 1:  {
  ------------------
  |  Branch (616:6): [True: 2.95k, False: 19.2k]
  ------------------
  617|  2.95k|						{
  618|  2.95k|#line 20 "src/spss/readstat_sav_parse.rl"
  619|  2.95k|							str_start = p; }
  620|       |						
  621|  2.95k|#line 622 "src/spss/readstat_sav_parse.c"
  622|       |						
  623|  2.95k|						break; 
  624|      0|					}
  625|  2.82k|					case 2:  {
  ------------------
  |  Branch (625:6): [True: 2.82k, False: 19.3k]
  ------------------
  626|  2.82k|						{
  627|  2.82k|#line 20 "src/spss/readstat_sav_parse.rl"
  628|  2.82k|							str_len = p - str_start; }
  629|       |						
  630|  2.82k|#line 631 "src/spss/readstat_sav_parse.c"
  631|       |						
  632|  2.82k|						break; 
  633|      0|					}
  634|  2.56k|					case 3:  {
  ------------------
  |  Branch (634:6): [True: 2.56k, False: 19.6k]
  ------------------
  635|  2.56k|						{
  636|  2.56k|#line 195 "src/spss/readstat_sav_parse.rl"
  637|       |							
  638|  2.56k|							varlookup_t *found = bsearch(temp_key, table, var_count, sizeof(varlookup_t), &compare_key_varlookup);
  639|  2.56k|							if (found) {
  ------------------
  |  Branch (639:12): [True: 949, False: 1.61k]
  ------------------
  640|       |								// See logic above; we need to apply this to all matching variables since ghost variable
  641|       |								// names may conflict with real variable names.
  642|    949|								varlookup_t *first_match = found, *last_match = found;
  643|    949|								varlookup_t *iter_match = found - 1;
  644|  2.95k|								while (iter_match >= table && strcmp(iter_match->name, temp_key) == 0) {
  ------------------
  |  Branch (644:16): [True: 2.47k, False: 478]
  |  Branch (644:39): [True: 2.00k, False: 471]
  ------------------
  645|  2.00k|									first_match = iter_match;
  646|  2.00k|									iter_match--;
  647|  2.00k|								}
  648|    949|								iter_match = found + 1;
  649|  4.90k|								while (iter_match - table < var_count && strcmp(iter_match->name, temp_key) == 0) {
  ------------------
  |  Branch (649:16): [True: 4.38k, False: 520]
  |  Branch (649:50): [True: 3.95k, False: 429]
  ------------------
  650|  3.95k|									last_match = iter_match;
  651|  3.95k|									iter_match++;
  652|  3.95k|								}
  653|  7.85k|								for (iter_match=first_match; iter_match<=last_match; iter_match++) {
  ------------------
  |  Branch (653:38): [True: 6.90k, False: 949]
  ------------------
  654|  6.90k|									ctx->varinfo[iter_match->index]->string_length = temp_val;
  655|  6.90k|									ctx->varinfo[iter_match->index]->write_format.width = temp_val;
  656|  6.90k|									ctx->varinfo[iter_match->index]->print_format.width = temp_val;
  657|  6.90k|								}
  658|    949|							}
  659|  2.56k|						}
  660|       |						
  661|  2.56k|#line 662 "src/spss/readstat_sav_parse.c"
  662|       |						
  663|  2.56k|						break; 
  664|      0|					}
  665|  8.17k|					case 4:  {
  ------------------
  |  Branch (665:6): [True: 8.17k, False: 13.9k]
  ------------------
  666|  8.17k|						{
  667|  8.17k|#line 219 "src/spss/readstat_sav_parse.rl"
  668|       |							
  669|  8.17k|							if ((( (*( p)))) != '\0') {
  ------------------
  |  Branch (669:12): [True: 8.17k, False: 0]
  ------------------
  670|  8.17k|								unsigned char digit = (( (*( p)))) - '0';
  671|  8.17k|								if (temp_val <= (UINT_MAX - digit) / 10) {
  ------------------
  |  Branch (671:13): [True: 7.92k, False: 251]
  ------------------
  672|  7.92k|									temp_val = 10 * temp_val + digit;
  673|  7.92k|								} else {
  674|    251|									{p += 1; goto _out; }
  675|    251|								}
  676|  8.17k|							}
  677|  8.17k|						}
  678|       |						
  679|  7.92k|#line 680 "src/spss/readstat_sav_parse.c"
  680|       |						
  681|  7.92k|						break; 
  682|  8.17k|					}
  683|  7.92k|					case 5:  {
  ------------------
  |  Branch (683:6): [True: 2.81k, False: 19.3k]
  ------------------
  684|  2.81k|						{
  685|  2.81k|#line 230 "src/spss/readstat_sav_parse.rl"
  686|  2.81k|							temp_val = 0; }
  687|       |						
  688|  2.81k|#line 689 "src/spss/readstat_sav_parse.c"
  689|       |						
  690|  2.81k|						break; 
  691|  8.17k|					}
  692|  22.1k|				}
  693|  21.9k|				_nacts -= 1;
  694|  21.9k|				_acts += 1;
  695|  21.9k|			}
  696|       |			
  697|  16.5k|		}
  698|       |		
  699|  20.5k|		if ( p == eof ) {
  ------------------
  |  Branch (699:8): [True: 1.52k, False: 18.9k]
  ------------------
  700|  1.52k|			if ( cs >= 11 )
  ------------------
  |  Branch (700:9): [True: 1.41k, False: 111]
  ------------------
  701|  1.41k|				goto _out;
  702|  1.52k|		}
  703|  18.9k|		else {
  704|  18.9k|			if ( cs != 0 ) {
  ------------------
  |  Branch (704:9): [True: 18.9k, False: 47]
  ------------------
  705|  18.9k|				p += 1;
  706|  18.9k|				goto _resume;
  707|  18.9k|			}
  708|  18.9k|		}
  709|  1.82k|		_out: {}
  710|  1.82k|	}
  711|       |	
  712|      0|#line 238 "src/spss/readstat_sav_parse.rl"
  713|       |	
  714|       |	
  715|  1.82k|	if (cs < 
  ------------------
  |  Branch (715:6): [True: 158, False: 1.66k]
  ------------------
  716|  1.82k|#line 717 "src/spss/readstat_sav_parse.c"
  717|  1.82k|	11
  718|  1.66k|#line 240 "src/spss/readstat_sav_parse.rl"
  719|  1.66k|	|| p != pe) {
  ------------------
  |  Branch (719:5): [True: 2, False: 1.66k]
  ------------------
  720|    160|		if (ctx->handle.error) {
  ------------------
  |  Branch (720:7): [True: 0, False: 160]
  ------------------
  721|      0|			snprintf(error_buf, error_buf_len, "Parsed %ld of %ld bytes. Remaining bytes: %.*s",
  722|      0|			(long)(p - c_data), (long)(pe - c_data), (int)(pe - p), p);
  723|      0|			ctx->handle.error(error_buf, ctx->user_ctx);
  724|      0|		}
  725|    160|		retval = READSTAT_ERROR_PARSE;
  726|    160|	}
  727|       |	
  728|  1.82k|	if (table)
  ------------------
  |  Branch (728:6): [True: 1.23k, False: 595]
  ------------------
  729|  1.23k|		free(table);
  730|  1.82k|	if (error_buf)
  ------------------
  |  Branch (730:6): [True: 1.82k, False: 0]
  ------------------
  731|  1.82k|		free(error_buf);
  732|       |	
  733|       |	/* suppress warning */
  734|  1.82k|	(void)sav_very_long_string_parse_en_main;
  735|       |	
  736|  1.82k|	return retval;
  737|  20.5k|}
readstat_sav_parse.c:count_vars:
   32|  3.01k|static int count_vars(sav_ctx_t *ctx) {
   33|  3.01k|	int i;
   34|  3.01k|	spss_varinfo_t *last_info = NULL;
   35|  3.01k|	int var_count = 0;
   36|  1.05M|	for (i=0; i<ctx->var_index; i++) {
  ------------------
  |  Branch (36:12): [True: 1.05M, False: 3.01k]
  ------------------
   37|  1.05M|		spss_varinfo_t *info = ctx->varinfo[i];
   38|  1.05M|		if (last_info == NULL || strcmp(info->name, last_info->name) != 0) {
  ------------------
  |  Branch (38:7): [True: 2.00k, False: 1.05M]
  |  Branch (38:28): [True: 995k, False: 54.9k]
  ------------------
   39|   997k|			var_count++;
   40|   997k|		}
   41|  1.05M|		last_info = info;
   42|  1.05M|	}
   43|  3.01k|	return var_count;
   44|  3.01k|}
readstat_sav_parse.c:build_lookup_table:
   46|  3.01k|static varlookup_t *build_lookup_table(int var_count, sav_ctx_t *ctx) {
   47|  3.01k|	varlookup_t *table = readstat_malloc(var_count * sizeof(varlookup_t));
   48|  3.01k|	int offset = 0;
   49|  3.01k|	int i;
   50|  3.01k|	spss_varinfo_t *last_info = NULL;
   51|  1.05M|	for (i=0; i<ctx->var_index; i++) {
  ------------------
  |  Branch (51:12): [True: 1.05M, False: 3.01k]
  ------------------
   52|  1.05M|		spss_varinfo_t *info = ctx->varinfo[i];
   53|       |		
   54|  1.05M|		if (last_info == NULL || strcmp(info->name, last_info->name) != 0) {
  ------------------
  |  Branch (54:7): [True: 2.00k, False: 1.05M]
  |  Branch (54:28): [True: 995k, False: 54.9k]
  ------------------
   55|   997k|			varlookup_t *entry = &table[offset++];
   56|       |			
   57|   997k|			memcpy(entry->name, info->name, sizeof(info->name));
   58|   997k|			entry->index = info->index;
   59|   997k|		}
   60|  1.05M|		last_info = info;
   61|  1.05M|	}
   62|  3.01k|	qsort(table, var_count, sizeof(varlookup_t), &compare_varlookups);
   63|  3.01k|	return table;
   64|  3.01k|}
readstat_sav_parse.c:compare_varlookups:
   26|  10.2M|static int compare_varlookups(const void *elem1, const void *elem2) {
   27|  10.2M|	const varlookup_t *v1 = (const varlookup_t *)elem1;
   28|  10.2M|	const varlookup_t *v2 = (const varlookup_t *)elem2;
   29|  10.2M|	return strcasecmp(v1->name, v2->name);
   30|  10.2M|}
readstat_sav_parse.c:compare_key_varlookup:
   20|  9.30k|static int compare_key_varlookup(const void *elem1, const void *elem2) {
   21|  9.30k|	const char *key = (const char *)elem1;
   22|  9.30k|	const varlookup_t *v = (const varlookup_t *)elem2;
   23|  9.30k|	return strcasecmp(key, v->name);
   24|  9.30k|}

parse_mr_string:
  212|  28.6k|readstat_error_t parse_mr_string(const char *data, size_t data_len, mr_set_t **mr_sets, size_t *n_mr_lines, sav_ctx_t *ctx) {
  213|  28.6k|    readstat_error_t retval = READSTAT_OK;
  214|  28.6k|    const char *p = data;
  215|  28.6k|    const char *end = data + data_len;
  216|  28.6k|    size_t line_len = 0;
  217|  28.6k|    size_t line_count = 0;
  218|       |
  219|       |    /* Count the sets and grow *mr_sets once. Copy rather than call
  220|       |     * readstat_realloc, which frees the old block when it refuses a size and
  221|       |     * would leave *mr_sets, with the sets of an earlier record, dangling. */
  222|   393k|    while (p < end) {
  ------------------
  |  Branch (222:12): [True: 365k, False: 28.6k]
  ------------------
  223|   365k|        mr_next_line(&p, end, &line_len);
  224|   365k|        if (line_len)
  ------------------
  |  Branch (224:13): [True: 149k, False: 216k]
  ------------------
  225|   149k|            line_count++;
  226|   365k|    }
  227|  28.6k|    if (line_count == 0)
  ------------------
  |  Branch (227:9): [True: 88, False: 28.6k]
  ------------------
  228|     88|        return READSTAT_OK;
  229|       |
  230|  28.6k|    mr_set_t *new_mr_sets = readstat_malloc((*n_mr_lines + line_count) * sizeof(mr_set_t));
  231|  28.6k|    if (new_mr_sets == NULL)
  ------------------
  |  Branch (231:9): [True: 0, False: 28.6k]
  ------------------
  232|      0|        return READSTAT_ERROR_MALLOC;
  233|  28.6k|    if (*n_mr_lines)
  ------------------
  |  Branch (233:9): [True: 16.6k, False: 11.9k]
  ------------------
  234|  16.6k|        memcpy(new_mr_sets, *mr_sets, *n_mr_lines * sizeof(mr_set_t));
  235|  28.6k|    free(*mr_sets);
  236|  28.6k|    *mr_sets = new_mr_sets;
  237|       |
  238|  28.6k|    p = data;
  239|  65.9k|    while (p < end) {
  ------------------
  |  Branch (239:12): [True: 62.0k, False: 3.98k]
  ------------------
  240|  62.0k|        const char *line = mr_next_line(&p, end, &line_len);
  241|  62.0k|        if (line_len == 0)
  ------------------
  |  Branch (241:13): [True: 16.1k, False: 45.8k]
  ------------------
  242|  16.1k|            continue; /* the spec allows any number of line feeds between sets */
  243|       |
  244|  45.8k|        retval = parse_mr_line(line, line_len, &(*mr_sets)[*n_mr_lines], ctx);
  245|  45.8k|        if (retval != READSTAT_OK)
  ------------------
  |  Branch (245:13): [True: 24.6k, False: 21.2k]
  ------------------
  246|  24.6k|            goto cleanup;
  247|       |
  248|  21.2k|        (*n_mr_lines)++;
  249|  21.2k|    }
  250|       |
  251|  28.6k|cleanup:
  252|  28.6k|    return retval;
  253|  28.6k|}
readstat_sav_parse_mr_name.c:mr_next_line:
  198|   427k|static const char *mr_next_line(const char **pp, const char *end, size_t *line_len) {
  199|   427k|    const char *p = *pp;
  200|   427k|    const char *line = p;
  201|  2.64M|    while (p < end && *p != '\n' && *p != '\0')
  ------------------
  |  Branch (201:12): [True: 2.61M, False: 32.8k]
  |  Branch (201:23): [True: 2.61M, False: 4.66k]
  |  Branch (201:37): [True: 2.22M, False: 389k]
  ------------------
  202|  2.22M|        p++;
  203|   427k|    *line_len = p - line;
  204|   427k|    if (p < end)
  ------------------
  |  Branch (204:9): [True: 394k, False: 32.8k]
  ------------------
  205|   394k|        p++; /* consume the line feed */
  206|   427k|    if (*line_len && line[*line_len-1] == '\r')
  ------------------
  |  Branch (206:9): [True: 195k, False: 231k]
  |  Branch (206:22): [True: 1.94k, False: 193k]
  ------------------
  207|  1.94k|        (*line_len)--;
  208|   427k|    *pp = p;
  209|   427k|    return line;
  210|   427k|}
readstat_sav_parse_mr_name.c:parse_mr_line:
   77|  45.8k|static readstat_error_t parse_mr_line(const char *line, size_t line_len, mr_set_t *result, sav_ctx_t *ctx) {
   78|  45.8k|    readstat_error_t retval = READSTAT_OK;
   79|  45.8k|    const char *p = line;
   80|  45.8k|    const char *end = line + line_len;
   81|  45.8k|    const char *str = NULL;
   82|  45.8k|    size_t str_len = 0;
   83|       |
   84|  45.8k|    memset(result, 0, sizeof(mr_set_t));
   85|       |
   86|       |    /* Name: begins with '$', runs up to '=' */
   87|  45.8k|    if (p == end || *p != '$') {
  ------------------
  |  Branch (87:9): [True: 0, False: 45.8k]
  |  Branch (87:21): [True: 4.90k, False: 40.9k]
  ------------------
   88|  4.90k|        retval = READSTAT_ERROR_BAD_MR_STRING;
   89|  4.90k|        goto cleanup;
   90|  4.90k|    }
   91|  40.9k|    str = p;
   92|   102k|    while (p < end && *p != '=' && *p != ' ')
  ------------------
  |  Branch (92:12): [True: 101k, False: 599]
  |  Branch (92:23): [True: 62.4k, False: 39.4k]
  |  Branch (92:36): [True: 61.5k, False: 957]
  ------------------
   93|  61.5k|        p++;
   94|  40.9k|    if (p == end || *p != '=' || p == str) {
  ------------------
  |  Branch (94:9): [True: 599, False: 40.3k]
  |  Branch (94:21): [True: 957, False: 39.4k]
  |  Branch (94:34): [True: 0, False: 39.4k]
  ------------------
   95|  1.55k|        retval = READSTAT_ERROR_BAD_MR_STRING;
   96|  1.55k|        goto cleanup;
   97|  1.55k|    }
   98|  39.4k|    if ((retval = mr_convert(&result->name, str, p - str, ctx)) != READSTAT_OK)
  ------------------
  |  Branch (98:9): [True: 278, False: 39.1k]
  ------------------
   99|    278|        goto cleanup;
  100|  39.1k|    p++;
  101|       |
  102|       |    /* Type */
  103|  39.1k|    if (p == end || (*p != 'C' && *p != 'D' && *p != 'E')) {
  ------------------
  |  Branch (103:9): [True: 914, False: 38.2k]
  |  Branch (103:22): [True: 12.7k, False: 25.4k]
  |  Branch (103:35): [True: 7.21k, False: 5.57k]
  |  Branch (103:48): [True: 1.81k, False: 5.40k]
  ------------------
  104|  2.72k|        retval = READSTAT_ERROR_BAD_MR_STRING;
  105|  2.72k|        goto cleanup;
  106|  2.72k|    }
  107|  36.4k|    result->type = *p++;
  108|  36.4k|    result->counted_value = -1;
  109|       |
  110|  36.4k|    if (result->type == 'E') {
  ------------------
  |  Branch (110:9): [True: 5.40k, False: 31.0k]
  ------------------
  111|       |        /* " 1 " or " 11 ": 11 means LABELSOURCE=VARLABEL */
  112|  5.40k|        long flag = 0;
  113|  5.40k|        if (p == end || *p != ' ') {
  ------------------
  |  Branch (113:13): [True: 255, False: 5.15k]
  |  Branch (113:25): [True: 459, False: 4.69k]
  ------------------
  114|    714|            retval = READSTAT_ERROR_BAD_MR_STRING;
  115|    714|            goto cleanup;
  116|    714|        }
  117|  4.69k|        p++;
  118|  4.69k|        if (p == end || *p < '0' || *p > '9') {
  ------------------
  |  Branch (118:13): [True: 358, False: 4.33k]
  |  Branch (118:25): [True: 233, False: 4.10k]
  |  Branch (118:37): [True: 1.41k, False: 2.68k]
  ------------------
  119|  2.00k|            retval = READSTAT_ERROR_BAD_MR_STRING;
  120|  2.00k|            goto cleanup;
  121|  2.00k|        }
  122|  9.63k|        while (p < end && *p >= '0' && *p <= '9' && flag < 1000)
  ------------------
  |  Branch (122:16): [True: 9.42k, False: 212]
  |  Branch (122:27): [True: 7.20k, False: 2.22k]
  |  Branch (122:40): [True: 6.96k, False: 236]
  |  Branch (122:53): [True: 6.95k, False: 14]
  ------------------
  123|  6.95k|            flag = flag * 10 + (*p++ - '0');
  124|  2.68k|        if (p == end || *p != ' ') {
  ------------------
  |  Branch (124:13): [True: 212, False: 2.47k]
  |  Branch (124:25): [True: 647, False: 1.82k]
  ------------------
  125|    859|            retval = READSTAT_ERROR_BAD_MR_STRING;
  126|    859|            goto cleanup;
  127|    859|        }
  128|  1.82k|        p++;
  129|  1.82k|        result->label_from_var_label = (flag == 11);
  130|  1.82k|    }
  131|       |
  132|  32.8k|    if (result->type == 'D' || result->type == 'E') {
  ------------------
  |  Branch (132:9): [True: 5.57k, False: 27.2k]
  |  Branch (132:32): [True: 1.82k, False: 25.4k]
  ------------------
  133|  7.39k|        result->is_dichotomy = 1;
  134|  7.39k|        if ((retval = mr_read_counted_string(&p, end, &str, &str_len)) != READSTAT_OK)
  ------------------
  |  Branch (134:13): [True: 3.63k, False: 3.76k]
  ------------------
  135|  3.63k|            goto cleanup;
  136|  3.76k|        if ((retval = mr_convert(&result->counted_string, str, str_len, ctx)) != READSTAT_OK)
  ------------------
  |  Branch (136:13): [True: 206, False: 3.55k]
  ------------------
  137|    206|            goto cleanup;
  138|       |        /* readstat_convert trims trailing spaces; older SPSS pads to 8 bytes */
  139|  3.55k|        if (result->counted_string[0] >= '0' && result->counted_string[0] <= '9') {
  ------------------
  |  Branch (139:13): [True: 1.71k, False: 1.83k]
  |  Branch (139:49): [True: 365, False: 1.35k]
  ------------------
  140|    365|            result->counted_value = (int)strtol(result->counted_string, NULL, 10);
  141|    365|        }
  142|  3.55k|        if (p == end || *p != ' ') {
  ------------------
  |  Branch (142:13): [True: 255, False: 3.29k]
  |  Branch (142:25): [True: 533, False: 2.76k]
  ------------------
  143|    788|            retval = READSTAT_ERROR_BAD_MR_STRING;
  144|    788|            goto cleanup;
  145|    788|        }
  146|  2.76k|        p++;
  147|  25.4k|    } else {
  148|  25.4k|        if (p == end || *p != ' ') {
  ------------------
  |  Branch (148:13): [True: 254, False: 25.1k]
  |  Branch (148:25): [True: 1.22k, False: 23.9k]
  ------------------
  149|  1.48k|            retval = READSTAT_ERROR_BAD_MR_STRING;
  150|  1.48k|            goto cleanup;
  151|  1.48k|        }
  152|  23.9k|        p++;
  153|  23.9k|    }
  154|       |
  155|       |    /* Label */
  156|  26.7k|    if ((retval = mr_read_counted_string(&p, end, &str, &str_len)) != READSTAT_OK)
  ------------------
  |  Branch (156:9): [True: 4.67k, False: 22.0k]
  ------------------
  157|  4.67k|        goto cleanup;
  158|  22.0k|    if ((retval = mr_convert(&result->label, str, str_len, ctx)) != READSTAT_OK)
  ------------------
  |  Branch (158:9): [True: 230, False: 21.8k]
  ------------------
  159|    230|        goto cleanup;
  160|       |
  161|       |    /* Variables: space-separated; some files have zero or one variable.
  162|       |     * Count them first and allocate the array once: readstat_realloc frees
  163|       |     * the old block when it refuses a size, so growing it one variable at a
  164|       |     * time would leave result->subvariables dangling. */
  165|  21.8k|    size_t subvar_count = 0;
  166|   468k|    for (str = p; str < end; str++) {
  ------------------
  |  Branch (166:19): [True: 446k, False: 21.8k]
  ------------------
  167|   446k|        if (*str != ' ' && (str == p || str[-1] == ' '))
  ------------------
  |  Branch (167:13): [True: 377k, False: 68.8k]
  |  Branch (167:29): [True: 10.2k, False: 367k]
  |  Branch (167:41): [True: 45.6k, False: 321k]
  ------------------
  168|  55.8k|            subvar_count++;
  169|   446k|    }
  170|  21.8k|    if (subvar_count &&
  ------------------
  |  Branch (170:9): [True: 18.9k, False: 2.84k]
  ------------------
  171|  18.9k|            (result->subvariables = readstat_malloc(subvar_count * sizeof(char *))) == NULL) {
  ------------------
  |  Branch (171:13): [True: 0, False: 18.9k]
  ------------------
  172|      0|        retval = READSTAT_ERROR_MALLOC;
  173|      0|        goto cleanup;
  174|      0|    }
  175|   145k|    while (p < end) {
  ------------------
  |  Branch (175:12): [True: 123k, False: 21.2k]
  ------------------
  176|   123k|        if (*p == ' ') {
  ------------------
  |  Branch (176:13): [True: 68.3k, False: 55.4k]
  ------------------
  177|  68.3k|            p++;
  178|  68.3k|            continue;
  179|  68.3k|        }
  180|  55.4k|        str = p;
  181|   431k|        while (p < end && *p != ' ')
  ------------------
  |  Branch (181:16): [True: 414k, False: 16.6k]
  |  Branch (181:27): [True: 376k, False: 38.8k]
  ------------------
  182|   376k|            p++;
  183|  55.4k|        char *subvar = NULL;
  184|  55.4k|        if ((retval = mr_convert(&subvar, str, p - str, ctx)) != READSTAT_OK)
  ------------------
  |  Branch (184:13): [True: 558, False: 54.9k]
  ------------------
  185|    558|            goto cleanup;
  186|  54.9k|        result->subvariables[result->num_subvars++] = subvar;
  187|  54.9k|    }
  188|       |
  189|  45.8k|cleanup:
  190|  45.8k|    if (retval != READSTAT_OK) {
  ------------------
  |  Branch (190:9): [True: 24.6k, False: 21.2k]
  ------------------
  191|  24.6k|        mr_set_free_contents(result);
  192|  24.6k|    }
  193|  45.8k|    return retval;
  194|  21.8k|}
readstat_sav_parse_mr_name.c:mr_convert:
   38|   120k|static readstat_error_t mr_convert(char **out, const char *src, size_t src_len, sav_ctx_t *ctx) {
   39|   120k|    size_t dst_len = 4 * src_len + 1; /* UTF-8 expansion: up to 4 bytes per char */
   40|   120k|    char *dst = readstat_malloc(dst_len);
   41|   120k|    if (dst == NULL)
  ------------------
  |  Branch (41:9): [True: 0, False: 120k]
  ------------------
   42|      0|        return READSTAT_ERROR_MALLOC;
   43|   120k|    readstat_error_t retval = readstat_convert(dst, dst_len, src, src_len, ctx->converter);
   44|   120k|    if (retval != READSTAT_OK) {
  ------------------
  |  Branch (44:9): [True: 1.27k, False: 119k]
  ------------------
   45|  1.27k|        free(dst);
   46|  1.27k|        return retval;
   47|  1.27k|    }
   48|   119k|    *out = dst;
   49|   119k|    return READSTAT_OK;
   50|   120k|}
readstat_sav_parse_mr_name.c:mr_read_counted_string:
   55|  34.1k|        const char **str, size_t *str_len) {
   56|  34.1k|    const char *p = *pp;
   57|  34.1k|    size_t n = 0;
   58|  34.1k|    if (p == end || *p < '0' || *p > '9')
  ------------------
  |  Branch (58:9): [True: 497, False: 33.6k]
  |  Branch (58:21): [True: 1.23k, False: 32.3k]
  |  Branch (58:33): [True: 699, False: 31.6k]
  ------------------
   59|  2.43k|        return READSTAT_ERROR_BAD_MR_STRING;
   60|  67.6k|    while (p < end && *p >= '0' && *p <= '9') {
  ------------------
  |  Branch (60:12): [True: 66.5k, False: 1.15k]
  |  Branch (60:23): [True: 38.9k, False: 27.5k]
  |  Branch (60:36): [True: 36.5k, False: 2.42k]
  ------------------
   61|  36.5k|        if (n > (size_t)(end - p))
  ------------------
  |  Branch (61:13): [True: 536, False: 35.9k]
  ------------------
   62|    536|            return READSTAT_ERROR_BAD_MR_STRING;
   63|  35.9k|        n = n * 10 + (*p - '0');
   64|  35.9k|        p++;
   65|  35.9k|    }
   66|  31.1k|    if (p == end || *p != ' ')
  ------------------
  |  Branch (66:9): [True: 1.15k, False: 30.0k]
  |  Branch (66:21): [True: 3.59k, False: 26.4k]
  ------------------
   67|  4.75k|        return READSTAT_ERROR_BAD_MR_STRING;
   68|  26.4k|    p++;
   69|  26.4k|    if (n > (size_t)(end - p))
  ------------------
  |  Branch (69:9): [True: 598, False: 25.8k]
  ------------------
   70|    598|        return READSTAT_ERROR_BAD_MR_STRING;
   71|  25.8k|    *str = p;
   72|  25.8k|    *str_len = n;
   73|  25.8k|    *pp = p + n;
   74|  25.8k|    return READSTAT_OK;
   75|  26.4k|}
readstat_sav_parse_mr_name.c:mr_set_free_contents:
   20|  24.6k|static void mr_set_free_contents(mr_set_t *mr) {
   21|  24.6k|    if (mr->name)
  ------------------
  |  Branch (21:9): [True: 17.8k, False: 6.73k]
  ------------------
   22|  17.8k|        free(mr->name);
   23|  24.6k|    if (mr->label)
  ------------------
  |  Branch (23:9): [True: 558, False: 24.0k]
  ------------------
   24|    558|        free(mr->label);
   25|  24.6k|    if (mr->counted_string)
  ------------------
  |  Branch (25:9): [True: 2.92k, False: 21.7k]
  ------------------
   26|  2.92k|        free(mr->counted_string);
   27|  24.6k|    if (mr->subvariables) {
  ------------------
  |  Branch (27:9): [True: 558, False: 24.0k]
  ------------------
   28|    558|        int i;
   29|  1.63k|        for (i=0; i<mr->num_subvars; i++) {
  ------------------
  |  Branch (29:19): [True: 1.08k, False: 558]
  ------------------
   30|  1.08k|            if (mr->subvariables[i])
  ------------------
  |  Branch (30:17): [True: 1.08k, False: 0]
  ------------------
   31|  1.08k|                free(mr->subvariables[i]);
   32|  1.08k|        }
   33|    558|        free(mr->subvariables);
   34|    558|    }
   35|  24.6k|    memset(mr, 0, sizeof(mr_set_t));
   36|  24.6k|}

sav_parse_time:
   73|  6.62k|readstat_error_handler error_cb, void *user_ctx) {
   74|  6.62k|	readstat_error_t retval = READSTAT_OK;
   75|  6.62k|	char error_buf[8192];
   76|  6.62k|	const char *p = data;
   77|  6.62k|	const char *pe = p + len;
   78|  6.62k|	const char *eof = pe;
   79|  6.62k|	int cs;
   80|  6.62k|	int temp_val = 0;
   81|       |	
   82|  6.62k|#line 83 "src/spss/readstat_sav_parse_timestamp.c"
   83|  6.62k|	{
   84|  6.62k|		cs = (int)sav_time_parse_start;
   85|  6.62k|	}
   86|       |	
   87|  6.62k|#line 88 "src/spss/readstat_sav_parse_timestamp.c"
   88|  6.62k|	{
   89|  6.62k|		int _klen;
   90|  6.62k|		unsigned int _trans = 0;
   91|  6.62k|		const char * _keys;
   92|  6.62k|		const signed char * _acts;
   93|  6.62k|		unsigned int _nacts;
   94|  11.4k|		_resume: {}
   95|  11.4k|		if ( p == pe && p != eof )
  ------------------
  |  Branch (95:8): [True: 391, False: 11.1k]
  |  Branch (95:19): [True: 0, False: 391]
  ------------------
   96|      0|			goto _out;
   97|  11.4k|		if ( p == eof ) {
  ------------------
  |  Branch (97:8): [True: 391, False: 11.1k]
  ------------------
   98|    391|			if ( _sav_time_parse_eof_trans[cs] > 0 ) {
  ------------------
  |  Branch (98:9): [True: 391, False: 0]
  ------------------
   99|    391|				_trans = (unsigned int)_sav_time_parse_eof_trans[cs] - 1;
  100|    391|			}
  101|    391|		}
  102|  11.1k|		else {
  103|  11.1k|			_keys = ( _sav_time_parse_trans_keys + (_sav_time_parse_key_offsets[cs]));
  104|  11.1k|			_trans = (unsigned int)_sav_time_parse_index_offsets[cs];
  105|       |			
  106|  11.1k|			_klen = (int)_sav_time_parse_single_lengths[cs];
  107|  11.1k|			if ( _klen > 0 ) {
  ------------------
  |  Branch (107:9): [True: 8.94k, False: 2.16k]
  ------------------
  108|  8.94k|				const char *_lower = _keys;
  109|  8.94k|				const char *_upper = _keys + _klen - 1;
  110|  8.94k|				const char *_mid;
  111|  16.5k|				while ( 1 ) {
  ------------------
  |  Branch (111:13): [True: 16.5k, Folded]
  ------------------
  112|  16.5k|					if ( _upper < _lower ) {
  ------------------
  |  Branch (112:11): [True: 7.57k, False: 8.94k]
  ------------------
  113|  7.57k|						_keys += _klen;
  114|  7.57k|						_trans += (unsigned int)_klen;
  115|  7.57k|						break;
  116|  7.57k|					}
  117|       |					
  118|  8.94k|					_mid = _lower + ((_upper-_lower) >> 1);
  119|  8.94k|					if ( ( (*( p))) < (*( _mid)) )
  ------------------
  |  Branch (119:11): [True: 4.59k, False: 4.34k]
  ------------------
  120|  4.59k|						_upper = _mid - 1;
  121|  4.34k|					else if ( ( (*( p))) > (*( _mid)) )
  ------------------
  |  Branch (121:16): [True: 2.97k, False: 1.36k]
  ------------------
  122|  2.97k|						_lower = _mid + 1;
  123|  1.36k|					else {
  124|  1.36k|						_trans += (unsigned int)(_mid - _keys);
  125|  1.36k|						goto _match;
  126|  1.36k|					}
  127|  8.94k|				}
  128|  8.94k|			}
  129|       |			
  130|  9.73k|			_klen = (int)_sav_time_parse_range_lengths[cs];
  131|  9.73k|			if ( _klen > 0 ) {
  ------------------
  |  Branch (131:9): [True: 9.56k, False: 169]
  ------------------
  132|  9.56k|				const char *_lower = _keys;
  133|  9.56k|				const char *_upper = _keys + (_klen<<1) - 2;
  134|  9.56k|				const char *_mid;
  135|  15.6k|				while ( 1 ) {
  ------------------
  |  Branch (135:13): [True: 15.6k, Folded]
  ------------------
  136|  15.6k|					if ( _upper < _lower ) {
  ------------------
  |  Branch (136:11): [True: 6.06k, False: 9.56k]
  ------------------
  137|  6.06k|						_trans += (unsigned int)_klen;
  138|  6.06k|						break;
  139|  6.06k|					}
  140|       |					
  141|  9.56k|					_mid = _lower + (((_upper-_lower) >> 1) & ~1);
  142|  9.56k|					if ( ( (*( p))) < (*( _mid)) )
  ------------------
  |  Branch (142:11): [True: 5.13k, False: 4.42k]
  ------------------
  143|  5.13k|						_upper = _mid - 2;
  144|  4.42k|					else if ( ( (*( p))) > (*( _mid + 1)) )
  ------------------
  |  Branch (144:16): [True: 927, False: 3.50k]
  ------------------
  145|    927|						_lower = _mid + 2;
  146|  3.50k|					else {
  147|  3.50k|						_trans += (unsigned int)((_mid - _keys)>>1);
  148|  3.50k|						break;
  149|  3.50k|					}
  150|  9.56k|				}
  151|  9.56k|			}
  152|       |			
  153|  11.1k|			_match: {}
  154|  11.1k|		}
  155|  11.4k|		cs = (int)_sav_time_parse_cond_targs[_trans];
  156|       |		
  157|  11.4k|		if ( _sav_time_parse_cond_actions[_trans] != 0 ) {
  ------------------
  |  Branch (157:8): [True: 4.96k, False: 6.52k]
  ------------------
  158|       |			
  159|  4.96k|			_acts = ( _sav_time_parse_actions + (_sav_time_parse_cond_actions[_trans]));
  160|  4.96k|			_nacts = (unsigned int)(*( _acts));
  161|  4.96k|			_acts += 1;
  162|  10.0k|			while ( _nacts > 0 ) {
  ------------------
  |  Branch (162:12): [True: 5.03k, False: 4.96k]
  ------------------
  163|  5.03k|				switch ( (*( _acts)) )
  ------------------
  |  Branch (163:14): [True: 5.03k, False: 0]
  ------------------
  164|  5.03k|				{
  165|  1.63k|					case 0:  {
  ------------------
  |  Branch (165:6): [True: 1.63k, False: 3.40k]
  ------------------
  166|  1.63k|						{
  167|  1.63k|#line 24 "src/spss/readstat_sav_parse_timestamp.rl"
  168|       |							
  169|  1.63k|							temp_val = 10 * temp_val + ((( (*( p)))) - '0');
  170|  1.63k|						}
  171|       |						
  172|  1.63k|#line 173 "src/spss/readstat_sav_parse_timestamp.c"
  173|       |						
  174|  1.63k|						break; 
  175|      0|					}
  176|     69|					case 1:  {
  ------------------
  |  Branch (176:6): [True: 69, False: 4.96k]
  ------------------
  177|     69|						{
  178|     69|#line 28 "src/spss/readstat_sav_parse_timestamp.rl"
  179|     69|							temp_val = 0; }
  180|       |						
  181|     69|#line 182 "src/spss/readstat_sav_parse_timestamp.c"
  182|       |						
  183|     69|						break; 
  184|      0|					}
  185|  1.86k|					case 2:  {
  ------------------
  |  Branch (185:6): [True: 1.86k, False: 3.16k]
  ------------------
  186|  1.86k|						{
  187|  1.86k|#line 28 "src/spss/readstat_sav_parse_timestamp.rl"
  188|  1.86k|							temp_val = (( (*( p)))) - '0'; }
  189|       |						
  190|  1.86k|#line 191 "src/spss/readstat_sav_parse_timestamp.c"
  191|       |						
  192|  1.86k|						break; 
  193|      0|					}
  194|    640|					case 3:  {
  ------------------
  |  Branch (194:6): [True: 640, False: 4.39k]
  ------------------
  195|    640|						{
  196|    640|#line 30 "src/spss/readstat_sav_parse_timestamp.rl"
  197|    640|							timestamp->tm_hour = temp_val; }
  198|       |						
  199|    640|#line 200 "src/spss/readstat_sav_parse_timestamp.c"
  200|       |						
  201|    640|						break; 
  202|      0|					}
  203|    433|					case 4:  {
  ------------------
  |  Branch (203:6): [True: 433, False: 4.60k]
  ------------------
  204|    433|						{
  205|    433|#line 32 "src/spss/readstat_sav_parse_timestamp.rl"
  206|    433|							timestamp->tm_min = temp_val; }
  207|       |						
  208|    433|#line 209 "src/spss/readstat_sav_parse_timestamp.c"
  209|       |						
  210|    433|						break; 
  211|      0|					}
  212|    391|					case 5:  {
  ------------------
  |  Branch (212:6): [True: 391, False: 4.64k]
  ------------------
  213|    391|						{
  214|    391|#line 34 "src/spss/readstat_sav_parse_timestamp.rl"
  215|    391|							timestamp->tm_sec = temp_val; }
  216|       |						
  217|    391|#line 218 "src/spss/readstat_sav_parse_timestamp.c"
  218|       |						
  219|    391|						break; 
  220|      0|					}
  221|  5.03k|				}
  222|  5.03k|				_nacts -= 1;
  223|  5.03k|				_acts += 1;
  224|  5.03k|			}
  225|       |			
  226|  4.96k|		}
  227|       |		
  228|  11.4k|		if ( p == eof ) {
  ------------------
  |  Branch (228:8): [True: 391, False: 11.1k]
  ------------------
  229|    391|			if ( cs >= 12 )
  ------------------
  |  Branch (229:9): [True: 391, False: 0]
  ------------------
  230|    391|				goto _out;
  231|    391|		}
  232|  11.1k|		else {
  233|  11.1k|			if ( cs != 0 ) {
  ------------------
  |  Branch (233:9): [True: 4.86k, False: 6.23k]
  ------------------
  234|  4.86k|				p += 1;
  235|  4.86k|				goto _resume;
  236|  4.86k|			}
  237|  11.1k|		}
  238|  6.62k|		_out: {}
  239|  6.62k|	}
  240|       |	
  241|      0|#line 40 "src/spss/readstat_sav_parse_timestamp.rl"
  242|       |	
  243|       |	
  244|  6.62k|	if (cs < 
  ------------------
  |  Branch (244:6): [True: 6.23k, False: 391]
  ------------------
  245|  6.62k|#line 246 "src/spss/readstat_sav_parse_timestamp.c"
  246|  6.62k|	12
  247|    391|#line 42 "src/spss/readstat_sav_parse_timestamp.rl"
  248|  6.23k|	|| p != pe) {
  ------------------
  |  Branch (248:5): [True: 0, False: 391]
  ------------------
  249|  6.23k|		if (error_cb) {
  ------------------
  |  Branch (249:7): [True: 0, False: 6.23k]
  ------------------
  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|  6.23k|		retval = READSTAT_ERROR_BAD_TIMESTAMP_STRING;
  255|  6.23k|	}
  256|       |	
  257|  6.62k|	(void)sav_time_parse_en_main;
  258|       |	
  259|  6.62k|	return retval;
  260|  11.4k|}
sav_parse_date:
  398|    391|readstat_error_handler error_cb, void *user_ctx) {
  399|    391|	readstat_error_t retval = READSTAT_OK;
  400|    391|	char error_buf[8192];
  401|    391|	const char *p = data;
  402|    391|	const char *pe = p + len;
  403|    391|	const char *eof = pe;
  404|    391|	int cs;
  405|    391|	int temp_val = 0;
  406|       |	
  407|    391|#line 408 "src/spss/readstat_sav_parse_timestamp.c"
  408|    391|	{
  409|    391|		cs = (int)sav_date_parse_start;
  410|    391|	}
  411|       |	
  412|    391|#line 413 "src/spss/readstat_sav_parse_timestamp.c"
  413|    391|	{
  414|    391|		int _klen;
  415|    391|		unsigned int _trans = 0;
  416|    391|		const char * _keys;
  417|    391|		const signed char * _acts;
  418|    391|		unsigned int _nacts;
  419|  3.00k|		_resume: {}
  420|  3.00k|		if ( p == pe && p != eof )
  ------------------
  |  Branch (420:8): [True: 244, False: 2.76k]
  |  Branch (420:19): [True: 0, False: 244]
  ------------------
  421|      0|			goto _out;
  422|  3.00k|		if ( p == eof ) {
  ------------------
  |  Branch (422:8): [True: 244, False: 2.76k]
  ------------------
  423|    244|			if ( _sav_date_parse_eof_trans[cs] > 0 ) {
  ------------------
  |  Branch (423:9): [True: 244, False: 0]
  ------------------
  424|    244|				_trans = (unsigned int)_sav_date_parse_eof_trans[cs] - 1;
  425|    244|			}
  426|    244|		}
  427|  2.76k|		else {
  428|  2.76k|			_keys = ( _sav_date_parse_trans_keys + (_sav_date_parse_key_offsets[cs]));
  429|  2.76k|			_trans = (unsigned int)_sav_date_parse_index_offsets[cs];
  430|       |			
  431|  2.76k|			_klen = (int)_sav_date_parse_single_lengths[cs];
  432|  2.76k|			if ( _klen > 0 ) {
  ------------------
  |  Branch (432:9): [True: 2.76k, False: 0]
  ------------------
  433|  2.76k|				const char *_lower = _keys;
  434|  2.76k|				const char *_upper = _keys + _klen - 1;
  435|  2.76k|				const char *_mid;
  436|  4.71k|				while ( 1 ) {
  ------------------
  |  Branch (436:13): [True: 4.71k, Folded]
  ------------------
  437|  4.71k|					if ( _upper < _lower ) {
  ------------------
  |  Branch (437:11): [True: 1.22k, False: 3.48k]
  ------------------
  438|  1.22k|						_keys += _klen;
  439|  1.22k|						_trans += (unsigned int)_klen;
  440|  1.22k|						break;
  441|  1.22k|					}
  442|       |					
  443|  3.48k|					_mid = _lower + ((_upper-_lower) >> 1);
  444|  3.48k|					if ( ( (*( p))) < (*( _mid)) )
  ------------------
  |  Branch (444:11): [True: 172, False: 3.31k]
  ------------------
  445|    172|						_upper = _mid - 1;
  446|  3.31k|					else if ( ( (*( p))) > (*( _mid)) )
  ------------------
  |  Branch (446:16): [True: 1.77k, False: 1.53k]
  ------------------
  447|  1.77k|						_lower = _mid + 1;
  448|  1.53k|					else {
  449|  1.53k|						_trans += (unsigned int)(_mid - _keys);
  450|  1.53k|						goto _match;
  451|  1.53k|					}
  452|  3.48k|				}
  453|  2.76k|			}
  454|       |			
  455|  1.22k|			_klen = (int)_sav_date_parse_range_lengths[cs];
  456|  1.22k|			if ( _klen > 0 ) {
  ------------------
  |  Branch (456:9): [True: 1.17k, False: 51]
  ------------------
  457|  1.17k|				const char *_lower = _keys;
  458|  1.17k|				const char *_upper = _keys + (_klen<<1) - 2;
  459|  1.17k|				const char *_mid;
  460|  1.27k|				while ( 1 ) {
  ------------------
  |  Branch (460:13): [True: 1.27k, Folded]
  ------------------
  461|  1.27k|					if ( _upper < _lower ) {
  ------------------
  |  Branch (461:11): [True: 96, False: 1.17k]
  ------------------
  462|     96|						_trans += (unsigned int)_klen;
  463|     96|						break;
  464|     96|					}
  465|       |					
  466|  1.17k|					_mid = _lower + (((_upper-_lower) >> 1) & ~1);
  467|  1.17k|					if ( ( (*( p))) < (*( _mid)) )
  ------------------
  |  Branch (467:11): [True: 64, False: 1.11k]
  ------------------
  468|     64|						_upper = _mid - 2;
  469|  1.11k|					else if ( ( (*( p))) > (*( _mid + 1)) )
  ------------------
  |  Branch (469:16): [True: 32, False: 1.08k]
  ------------------
  470|     32|						_lower = _mid + 2;
  471|  1.08k|					else {
  472|  1.08k|						_trans += (unsigned int)((_mid - _keys)>>1);
  473|  1.08k|						break;
  474|  1.08k|					}
  475|  1.17k|				}
  476|  1.17k|			}
  477|       |			
  478|  2.76k|			_match: {}
  479|  2.76k|		}
  480|  3.00k|		cs = (int)_sav_date_parse_cond_targs[_trans];
  481|       |		
  482|  3.00k|		if ( _sav_date_parse_cond_actions[_trans] != 0 ) {
  ------------------
  |  Branch (482:8): [True: 1.98k, False: 1.02k]
  ------------------
  483|       |			
  484|  1.98k|			_acts = ( _sav_date_parse_actions + (_sav_date_parse_cond_actions[_trans]));
  485|  1.98k|			_nacts = (unsigned int)(*( _acts));
  486|  1.98k|			_acts += 1;
  487|  4.55k|			while ( _nacts > 0 ) {
  ------------------
  |  Branch (487:12): [True: 2.57k, False: 1.98k]
  ------------------
  488|  2.57k|				switch ( (*( _acts)) )
  ------------------
  |  Branch (488:14): [True: 2.57k, False: 0]
  ------------------
  489|  2.57k|				{
  490|  1.15k|					case 0:  {
  ------------------
  |  Branch (490:6): [True: 1.15k, False: 1.41k]
  ------------------
  491|  1.15k|						{
  492|  1.15k|#line 71 "src/spss/readstat_sav_parse_timestamp.rl"
  493|       |							
  494|  1.15k|							char digit = ((( (*( p)))) - '0');
  495|  1.15k|							if (digit >= 0 && digit <= 9) {
  ------------------
  |  Branch (495:12): [True: 1.08k, False: 74]
  |  Branch (495:26): [True: 1.08k, False: 0]
  ------------------
  496|  1.08k|								temp_val = 10 * temp_val + digit;
  497|  1.08k|							}
  498|  1.15k|						}
  499|       |						
  500|  1.15k|#line 501 "src/spss/readstat_sav_parse_timestamp.c"
  501|       |						
  502|  1.15k|						break; 
  503|      0|					}
  504|    244|					case 1:  {
  ------------------
  |  Branch (504:6): [True: 244, False: 2.33k]
  ------------------
  505|    244|						{
  506|    244|#line 78 "src/spss/readstat_sav_parse_timestamp.rl"
  507|       |							
  508|    244|							if (temp_val < 70) {
  ------------------
  |  Branch (508:12): [True: 217, False: 27]
  ------------------
  509|    217|								timestamp->tm_year = 100 + temp_val;
  510|    217|							} else {
  511|     27|								timestamp->tm_year = temp_val;
  512|     27|							}
  513|    244|						}
  514|       |						
  515|    244|#line 516 "src/spss/readstat_sav_parse_timestamp.c"
  516|       |						
  517|    244|						break; 
  518|      0|					}
  519|    591|					case 2:  {
  ------------------
  |  Branch (519:6): [True: 591, False: 1.98k]
  ------------------
  520|    591|						{
  521|    591|#line 87 "src/spss/readstat_sav_parse_timestamp.rl"
  522|    591|							temp_val = 0; }
  523|       |						
  524|    591|#line 525 "src/spss/readstat_sav_parse_timestamp.c"
  525|       |						
  526|    591|						break; 
  527|      0|					}
  528|    313|					case 3:  {
  ------------------
  |  Branch (528:6): [True: 313, False: 2.26k]
  ------------------
  529|    313|						{
  530|    313|#line 89 "src/spss/readstat_sav_parse_timestamp.rl"
  531|    313|							timestamp->tm_mday = temp_val; }
  532|       |						
  533|    313|#line 534 "src/spss/readstat_sav_parse_timestamp.c"
  534|       |						
  535|    313|						break; 
  536|      0|					}
  537|    101|					case 4:  {
  ------------------
  |  Branch (537:6): [True: 101, False: 2.47k]
  ------------------
  538|    101|						{
  539|    101|#line 94 "src/spss/readstat_sav_parse_timestamp.rl"
  540|    101|							timestamp->tm_mon = 0; }
  541|       |						
  542|    101|#line 543 "src/spss/readstat_sav_parse_timestamp.c"
  543|       |						
  544|    101|						break; 
  545|      0|					}
  546|      3|					case 5:  {
  ------------------
  |  Branch (546:6): [True: 3, False: 2.57k]
  ------------------
  547|      3|						{
  548|      3|#line 95 "src/spss/readstat_sav_parse_timestamp.rl"
  549|      3|							timestamp->tm_mon = 1; }
  550|       |						
  551|      3|#line 552 "src/spss/readstat_sav_parse_timestamp.c"
  552|       |						
  553|      3|						break; 
  554|      0|					}
  555|     14|					case 6:  {
  ------------------
  |  Branch (555:6): [True: 14, False: 2.56k]
  ------------------
  556|     14|						{
  557|     14|#line 96 "src/spss/readstat_sav_parse_timestamp.rl"
  558|     14|							timestamp->tm_mon = 2; }
  559|       |						
  560|     14|#line 561 "src/spss/readstat_sav_parse_timestamp.c"
  561|       |						
  562|     14|						break; 
  563|      0|					}
  564|      9|					case 7:  {
  ------------------
  |  Branch (564:6): [True: 9, False: 2.56k]
  ------------------
  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|      1|					case 8:  {
  ------------------
  |  Branch (573:6): [True: 1, False: 2.57k]
  ------------------
  574|      1|						{
  575|      1|#line 98 "src/spss/readstat_sav_parse_timestamp.rl"
  576|      1|							timestamp->tm_mon = 4; }
  577|       |						
  578|      1|#line 579 "src/spss/readstat_sav_parse_timestamp.c"
  579|       |						
  580|      1|						break; 
  581|      0|					}
  582|    100|					case 9:  {
  ------------------
  |  Branch (582:6): [True: 100, False: 2.47k]
  ------------------
  583|    100|						{
  584|    100|#line 99 "src/spss/readstat_sav_parse_timestamp.rl"
  585|    100|							timestamp->tm_mon = 5; }
  586|       |						
  587|    100|#line 588 "src/spss/readstat_sav_parse_timestamp.c"
  588|       |						
  589|    100|						break; 
  590|      0|					}
  591|      5|					case 10:  {
  ------------------
  |  Branch (591:6): [True: 5, False: 2.56k]
  ------------------
  592|      5|						{
  593|      5|#line 100 "src/spss/readstat_sav_parse_timestamp.rl"
  594|      5|							timestamp->tm_mon = 6; }
  595|       |						
  596|      5|#line 597 "src/spss/readstat_sav_parse_timestamp.c"
  597|       |						
  598|      5|						break; 
  599|      0|					}
  600|      1|					case 11:  {
  ------------------
  |  Branch (600:6): [True: 1, False: 2.57k]
  ------------------
  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|      9|					case 12:  {
  ------------------
  |  Branch (609:6): [True: 9, False: 2.56k]
  ------------------
  610|      9|						{
  611|      9|#line 102 "src/spss/readstat_sav_parse_timestamp.rl"
  612|      9|							timestamp->tm_mon = 8; }
  613|       |						
  614|      9|#line 615 "src/spss/readstat_sav_parse_timestamp.c"
  615|       |						
  616|      9|						break; 
  617|      0|					}
  618|      3|					case 13:  {
  ------------------
  |  Branch (618:6): [True: 3, False: 2.57k]
  ------------------
  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|      1|					case 14:  {
  ------------------
  |  Branch (627:6): [True: 1, False: 2.57k]
  ------------------
  628|      1|						{
  629|      1|#line 104 "src/spss/readstat_sav_parse_timestamp.rl"
  630|      1|							timestamp->tm_mon = 10; }
  631|       |						
  632|      1|#line 633 "src/spss/readstat_sav_parse_timestamp.c"
  633|       |						
  634|      1|						break; 
  635|      0|					}
  636|     23|					case 15:  {
  ------------------
  |  Branch (636:6): [True: 23, False: 2.55k]
  ------------------
  637|     23|						{
  638|     23|#line 105 "src/spss/readstat_sav_parse_timestamp.rl"
  639|     23|							timestamp->tm_mon = 11; }
  640|       |						
  641|     23|#line 642 "src/spss/readstat_sav_parse_timestamp.c"
  642|       |						
  643|     23|						break; 
  644|      0|					}
  645|  2.57k|				}
  646|  2.57k|				_nacts -= 1;
  647|  2.57k|				_acts += 1;
  648|  2.57k|			}
  649|       |			
  650|  1.98k|		}
  651|       |		
  652|  3.00k|		if ( p == eof ) {
  ------------------
  |  Branch (652:8): [True: 244, False: 2.76k]
  ------------------
  653|    244|			if ( cs >= 47 )
  ------------------
  |  Branch (653:9): [True: 244, False: 0]
  ------------------
  654|    244|				goto _out;
  655|    244|		}
  656|  2.76k|		else {
  657|  2.76k|			if ( cs != 0 ) {
  ------------------
  |  Branch (657:9): [True: 2.61k, False: 147]
  ------------------
  658|  2.61k|				p += 1;
  659|  2.61k|				goto _resume;
  660|  2.61k|			}
  661|  2.76k|		}
  662|    391|		_out: {}
  663|    391|	}
  664|       |	
  665|      0|#line 112 "src/spss/readstat_sav_parse_timestamp.rl"
  666|       |	
  667|       |	
  668|    391|	if (cs < 
  ------------------
  |  Branch (668:6): [True: 147, False: 244]
  ------------------
  669|    391|#line 670 "src/spss/readstat_sav_parse_timestamp.c"
  670|    391|	47
  671|    244|#line 114 "src/spss/readstat_sav_parse_timestamp.rl"
  672|    244|	|| p != pe) {
  ------------------
  |  Branch (672:5): [True: 0, False: 244]
  ------------------
  673|    147|		if (error_cb) {
  ------------------
  |  Branch (673:7): [True: 0, False: 147]
  ------------------
  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|    147|		retval = READSTAT_ERROR_BAD_TIMESTAMP_STRING;
  679|    147|	}
  680|       |	
  681|    391|	(void)sav_date_parse_en_main;
  682|       |	
  683|    391|	return retval;
  684|  3.00k|}

sav_update_progress:
  185|  8.03k|readstat_error_t sav_update_progress(sav_ctx_t *ctx) {
  186|  8.03k|    readstat_io_t *io = ctx->io;
  187|  8.03k|    return io->update(ctx->file_size, ctx->handle.progress, ctx->user_ctx, io->io_ctx);
  188|  8.03k|}
sav_parse_timestamp:
 1727|  6.62k|readstat_error_t sav_parse_timestamp(sav_ctx_t *ctx, sav_file_header_record_t *header) {
 1728|  6.62k|    readstat_error_t retval = READSTAT_OK;
 1729|  6.62k|    struct tm timestamp = { .tm_isdst = -1 };
 1730|       |
 1731|  6.62k|    if ((retval = sav_parse_time(header->creation_time, sizeof(header->creation_time),
  ------------------
  |  Branch (1731:9): [True: 6.23k, False: 391]
  ------------------
 1732|  6.62k|                    &timestamp, ctx->handle.error, ctx->user_ctx)) 
 1733|  6.62k|            != READSTAT_OK)
 1734|  6.23k|        goto cleanup;
 1735|       |
 1736|    391|    if ((retval = sav_parse_date(header->creation_date, sizeof(header->creation_date),
  ------------------
  |  Branch (1736:9): [True: 147, False: 244]
  ------------------
 1737|    391|                    &timestamp, ctx->handle.error, ctx->user_ctx)) 
 1738|    391|            != READSTAT_OK)
 1739|    147|        goto cleanup;
 1740|       |
 1741|    244|    ctx->timestamp = mktime(&timestamp);
 1742|       |
 1743|  6.62k|cleanup:
 1744|  6.62k|    return retval;
 1745|    244|}
readstat_parse_sav:
 1747|  6.67k|readstat_error_t readstat_parse_sav(readstat_parser_t *parser, const char *path, void *user_ctx) {
 1748|  6.67k|    readstat_error_t retval = READSTAT_OK;
 1749|  6.67k|    readstat_io_t *io = parser->io;
 1750|  6.67k|    sav_file_header_record_t header;
 1751|  6.67k|    sav_ctx_t *ctx = NULL;
 1752|  6.67k|    size_t file_size = 0;
 1753|       |    
 1754|  6.67k|    if (io->open(path, io->io_ctx) == -1) {
  ------------------
  |  Branch (1754:9): [True: 0, False: 6.67k]
  ------------------
 1755|      0|        return READSTAT_ERROR_OPEN;
 1756|      0|    }
 1757|       |
 1758|  6.67k|    file_size = io->seek(0, READSTAT_SEEK_END, io->io_ctx);
 1759|  6.67k|    if (file_size == -1) {
  ------------------
  |  Branch (1759:9): [True: 0, False: 6.67k]
  ------------------
 1760|      0|        retval = READSTAT_ERROR_SEEK;
 1761|      0|        goto cleanup;
 1762|      0|    }
 1763|       |
 1764|  6.67k|    if (io->seek(0, READSTAT_SEEK_SET, io->io_ctx) == -1) {
  ------------------
  |  Branch (1764:9): [True: 0, False: 6.67k]
  ------------------
 1765|      0|        retval = READSTAT_ERROR_SEEK;
 1766|      0|        goto cleanup;
 1767|      0|    }
 1768|       |
 1769|  6.67k|    if (io->read(&header, sizeof(sav_file_header_record_t), io->io_ctx) < sizeof(sav_file_header_record_t)) {
  ------------------
  |  Branch (1769:9): [True: 18, False: 6.65k]
  ------------------
 1770|     18|        retval = READSTAT_ERROR_READ;
 1771|     18|        goto cleanup;
 1772|     18|    }
 1773|       |
 1774|  6.65k|    ctx = sav_ctx_init(&header, io);
 1775|  6.65k|    if (ctx == NULL) {
  ------------------
  |  Branch (1775:9): [True: 32, False: 6.62k]
  ------------------
 1776|     32|        retval = READSTAT_ERROR_PARSE;
 1777|     32|        goto cleanup;
 1778|     32|    }
 1779|       |
 1780|  6.62k|    ctx->handle = parser->handlers;
 1781|  6.62k|    ctx->input_encoding = parser->input_encoding;
 1782|  6.62k|    ctx->output_encoding = parser->output_encoding;
 1783|  6.62k|    ctx->user_ctx = user_ctx;
 1784|  6.62k|    ctx->file_size = file_size;
 1785|  6.62k|    if (parser->row_offset > 0)
  ------------------
  |  Branch (1785:9): [True: 0, False: 6.62k]
  ------------------
 1786|      0|        ctx->row_offset = parser->row_offset;
 1787|  6.62k|    if (ctx->record_count >= 0) {
  ------------------
  |  Branch (1787:9): [True: 4.52k, False: 2.09k]
  ------------------
 1788|  4.52k|        int record_count_after_skipping = ctx->record_count - ctx->row_offset;
 1789|  4.52k|        if (record_count_after_skipping < 0) {
  ------------------
  |  Branch (1789:13): [True: 0, False: 4.52k]
  ------------------
 1790|      0|            record_count_after_skipping = 0;
 1791|      0|            ctx->row_offset = ctx->record_count;
 1792|      0|        }
 1793|  4.52k|        ctx->row_limit = record_count_after_skipping;
 1794|  4.52k|        if (parser->row_limit > 0 && parser->row_limit < record_count_after_skipping) 
  ------------------
  |  Branch (1794:13): [True: 0, False: 4.52k]
  |  Branch (1794:38): [True: 0, False: 0]
  ------------------
 1795|      0|            ctx->row_limit = parser->row_limit;
 1796|  4.52k|    } else if (parser->row_limit > 0) {
  ------------------
  |  Branch (1796:16): [True: 0, False: 2.09k]
  ------------------
 1797|      0|        ctx->row_limit = parser->row_limit;
 1798|      0|    }
 1799|       |    
 1800|       |    /* ignore errors */
 1801|  6.62k|    sav_parse_timestamp(ctx, &header);
 1802|       |
 1803|  6.62k|    if ((retval = sav_parse_records_pass1(ctx)) != READSTAT_OK)
  ------------------
  |  Branch (1803:9): [True: 1.12k, False: 5.50k]
  ------------------
 1804|  1.12k|        goto cleanup;
 1805|       |
 1806|  5.50k|    if ((retval = sav_setup_converter(ctx)) != READSTAT_OK)
  ------------------
  |  Branch (1806:9): [True: 42, False: 5.46k]
  ------------------
 1807|     42|        goto cleanup;
 1808|       |    
 1809|  5.46k|    if (io->seek(sizeof(sav_file_header_record_t), READSTAT_SEEK_SET, io->io_ctx) == -1) {
  ------------------
  |  Branch (1809:9): [True: 0, False: 5.46k]
  ------------------
 1810|      0|        retval = READSTAT_ERROR_SEEK;
 1811|      0|        goto cleanup;
 1812|      0|    }
 1813|       |
 1814|  5.46k|    if ((retval = sav_update_progress(ctx)) != READSTAT_OK)
  ------------------
  |  Branch (1814:9): [True: 0, False: 5.46k]
  ------------------
 1815|      0|        goto cleanup;
 1816|       |
 1817|  5.46k|    if ((retval = sav_parse_records_pass2(ctx)) != READSTAT_OK)
  ------------------
  |  Branch (1817:9): [True: 3.48k, False: 1.97k]
  ------------------
 1818|  3.48k|        goto cleanup;
 1819|       | 
 1820|  1.97k|    if ((retval = sav_set_n_segments_and_var_count(ctx)) != READSTAT_OK)
  ------------------
  |  Branch (1820:9): [True: 31, False: 1.94k]
  ------------------
 1821|     31|        goto cleanup;
 1822|       |
 1823|  1.94k|    if (ctx->var_count == 0) {
  ------------------
  |  Branch (1823:9): [True: 52, False: 1.89k]
  ------------------
 1824|     52|        retval = READSTAT_ERROR_PARSE;
 1825|     52|        goto cleanup;
 1826|     52|    }
 1827|       |
 1828|  1.89k|    if (ctx->handle.metadata) {
  ------------------
  |  Branch (1828:9): [True: 1.89k, False: 0]
  ------------------
 1829|  1.89k|        readstat_metadata_t metadata = {
 1830|  1.89k|            .row_count = ctx->record_count < 0 ? -1 : ctx->row_limit,
  ------------------
  |  Branch (1830:26): [True: 516, False: 1.37k]
  ------------------
 1831|  1.89k|            .var_count = ctx->var_count,
 1832|  1.89k|            .file_encoding = ctx->input_encoding,
 1833|  1.89k|            .file_format_version = ctx->format_version,
 1834|  1.89k|            .creation_time = ctx->timestamp,
 1835|  1.89k|            .modified_time = ctx->timestamp,
 1836|  1.89k|            .compression = ctx->compression,
 1837|  1.89k|            .endianness = ctx->endianness
 1838|  1.89k|        };
 1839|  1.89k|        if ((retval = readstat_convert(ctx->file_label, sizeof(ctx->file_label),
  ------------------
  |  Branch (1839:13): [True: 9, False: 1.88k]
  ------------------
 1840|  1.89k|                        header.file_label, sizeof(header.file_label), ctx->converter)) != READSTAT_OK)
 1841|      9|            goto cleanup;
 1842|       |
 1843|  1.88k|        metadata.file_label = ctx->file_label;
 1844|       |
 1845|       |        // Replace short MR names with long names
 1846|  1.88k|        ck_hash_table_t *var_dict = ck_hash_table_init(ctx->var_index, 8);
 1847|   321k|        for (size_t i = 0; i < ctx->var_index; i++) {
  ------------------
  |  Branch (1847:28): [True: 319k, False: 1.88k]
  ------------------
 1848|   319k|            spss_varinfo_t *current_varinfo = ctx->varinfo[i];
 1849|   319k|            if (current_varinfo != NULL && current_varinfo->name[0] != '\0') {
  ------------------
  |  Branch (1849:17): [True: 319k, False: 0]
  |  Branch (1849:44): [True: 314k, False: 4.83k]
  ------------------
 1850|   314k|                ck_str_hash_insert(current_varinfo->name, current_varinfo, var_dict);
 1851|   314k|            }
 1852|   319k|        }
 1853|  21.6k|        for (size_t i = 0; i < ctx->multiple_response_sets_length; i++) {
  ------------------
  |  Branch (1853:28): [True: 19.7k, False: 1.88k]
  ------------------
 1854|  19.7k|            mr_set_t mr = ctx->mr_sets[i];
 1855|  70.2k|            for (size_t j = 0; j < mr.num_subvars; j++) {
  ------------------
  |  Branch (1855:32): [True: 50.5k, False: 19.7k]
  ------------------
 1856|  50.5k|                char* sv_name_upper = readstat_malloc(strlen(mr.subvariables[j]) + 1);
 1857|  50.5k|                if (sv_name_upper == NULL) {
  ------------------
  |  Branch (1857:21): [True: 0, False: 50.5k]
  ------------------
 1858|      0|                    retval = READSTAT_ERROR_MALLOC;
 1859|      0|                    goto cleanup;
 1860|      0|                }
 1861|  50.5k|                sv_name_upper[strlen(mr.subvariables[j])] = '\0';
 1862|   422k|                for (int c = 0; mr.subvariables[j][c] != '\0'; c++) {
  ------------------
  |  Branch (1862:33): [True: 371k, False: 50.5k]
  ------------------
 1863|   371k|                    sv_name_upper[c] = toupper((unsigned char) mr.subvariables[j][c]);
  ------------------
  |  Branch (1863:40): [True: 0, False: 0]
  |  Branch (1863:40): [True: 0, False: 0]
  |  Branch (1863:40): [Folded, False: 371k]
  ------------------
 1864|   371k|                }
 1865|  50.5k|                spss_varinfo_t *info = (spss_varinfo_t *)ck_str_hash_lookup(sv_name_upper, var_dict);
 1866|  50.5k|                if (info) {
  ------------------
  |  Branch (1866:21): [True: 268, False: 50.2k]
  ------------------
 1867|    268|                    free(mr.subvariables[j]);
 1868|       |                    // mr.subvariables[j] = NULL;
 1869|    268|                    if ((mr.subvariables[j] = readstat_malloc(strlen(info->longname) + 1)) == NULL) {
  ------------------
  |  Branch (1869:25): [True: 0, False: 268]
  ------------------
 1870|      0|                        retval = READSTAT_ERROR_MALLOC;
 1871|      0|                        goto cleanup;
 1872|      0|                    }
 1873|       |                    // mr.subvariables[j][strlen(info->longname)] = '\0';
 1874|    268|                    strcpy(mr.subvariables[j], info->longname);
 1875|       |                    // mr.subvariables[j] = info->longname;
 1876|    268|                }
 1877|  50.5k|                free(sv_name_upper);
 1878|       |                // sv_name_upper = NULL;
 1879|  50.5k|            }
 1880|  19.7k|        }
 1881|  1.88k|        if (var_dict)
  ------------------
  |  Branch (1881:13): [True: 1.88k, False: 0]
  ------------------
 1882|  1.88k|            ck_hash_table_free(var_dict);
 1883|       |
 1884|  1.88k|        metadata.multiple_response_sets_length = ctx->multiple_response_sets_length;
 1885|  1.88k|        metadata.mr_sets = ctx->mr_sets;
 1886|       |
 1887|  1.88k|        if (ctx->handle.metadata(&metadata, ctx->user_ctx) != READSTAT_HANDLER_OK) {
  ------------------
  |  |   22|  1.88k|#define READSTAT_HANDLER_OK             0
  ------------------
  |  Branch (1887:13): [True: 0, False: 1.88k]
  ------------------
 1888|      0|            retval = READSTAT_ERROR_USER_ABORT;
 1889|      0|            goto cleanup;
 1890|      0|        }
 1891|  1.88k|    }
 1892|       |
 1893|  1.88k|    if ((retval = sav_parse_variable_display_parameter_record(ctx)) != READSTAT_OK)
  ------------------
  |  Branch (1893:9): [True: 0, False: 1.88k]
  ------------------
 1894|      0|        goto cleanup;
 1895|       |
 1896|  1.88k|    if ((retval = sav_handle_variables(ctx)) != READSTAT_OK)
  ------------------
  |  Branch (1896:9): [True: 0, False: 1.88k]
  ------------------
 1897|      0|        goto cleanup;
 1898|       |
 1899|       |
 1900|  1.88k|    if ((retval = sav_handle_fweight(ctx)) != READSTAT_OK)
  ------------------
  |  Branch (1900:9): [True: 0, False: 1.88k]
  ------------------
 1901|      0|        goto cleanup;
 1902|       |
 1903|  1.88k|    if (ctx->handle.value) {
  ------------------
  |  Branch (1903:9): [True: 1.88k, False: 0]
  ------------------
 1904|  1.88k|        retval = sav_read_data(ctx);
 1905|  1.88k|    }
 1906|       |    
 1907|  6.67k|cleanup:
 1908|  6.67k|    io->close(io->io_ctx);
 1909|  6.67k|    if (ctx)
  ------------------
  |  Branch (1909:9): [True: 6.62k, False: 50]
  ------------------
 1910|  6.62k|        sav_ctx_free(ctx);
 1911|       |    
 1912|  6.67k|    return retval;
 1913|  1.88k|}
readstat_sav_read.c:sav_parse_records_pass1:
 1423|  6.62k|static readstat_error_t sav_parse_records_pass1(sav_ctx_t *ctx) {
 1424|  6.62k|    char data_buf[4096];
 1425|  6.62k|    readstat_error_t retval = READSTAT_OK;
 1426|  6.62k|    readstat_io_t *io = ctx->io;
 1427|   595k|    while (1) {
  ------------------
  |  Branch (1427:12): [True: 595k, Folded]
  ------------------
 1428|   595k|        uint32_t rec_type;
 1429|   595k|        uint32_t extra_info[3];
 1430|   595k|        size_t data_len = 0;
 1431|   595k|        int i;
 1432|   595k|        int done = 0;
 1433|   595k|        if (io->read(&rec_type, sizeof(uint32_t), io->io_ctx) < sizeof(uint32_t)) {
  ------------------
  |  Branch (1433:13): [True: 456, False: 594k]
  ------------------
 1434|    456|            retval = READSTAT_ERROR_READ;
 1435|    456|            goto cleanup;
 1436|    456|        }
 1437|       |        
 1438|   594k|        if (ctx->bswap) {
  ------------------
  |  Branch (1438:13): [True: 29.5k, False: 565k]
  ------------------
 1439|  29.5k|            rec_type = byteswap4(rec_type);
 1440|  29.5k|        }
 1441|       |        
 1442|   594k|        switch (rec_type) {
 1443|   462k|            case SAV_RECORD_TYPE_VARIABLE:
  ------------------
  |  |  117|   462k|#define SAV_RECORD_TYPE_VARIABLE                2
  ------------------
  |  Branch (1443:13): [True: 462k, False: 132k]
  ------------------
 1444|   462k|                retval = sav_skip_variable_record(ctx);
 1445|   462k|                if (retval != READSTAT_OK)
  ------------------
  |  Branch (1445:21): [True: 155, False: 461k]
  ------------------
 1446|    155|                    goto cleanup;
 1447|   461k|                break;
 1448|   461k|            case SAV_RECORD_TYPE_VALUE_LABEL:
  ------------------
  |  |  118|  82.5k|#define SAV_RECORD_TYPE_VALUE_LABEL             3
  ------------------
  |  Branch (1448:13): [True: 82.5k, False: 512k]
  ------------------
 1449|  82.5k|                retval = sav_skip_value_label_record(ctx);
 1450|  82.5k|                if (retval != READSTAT_OK)
  ------------------
  |  Branch (1450:21): [True: 184, False: 82.3k]
  ------------------
 1451|    184|                    goto cleanup;
 1452|  82.3k|                break;
 1453|  82.3k|            case SAV_RECORD_TYPE_DOCUMENT:
  ------------------
  |  |  120|  1.93k|#define SAV_RECORD_TYPE_DOCUMENT                6
  ------------------
  |  Branch (1453:13): [True: 1.93k, False: 593k]
  ------------------
 1454|  1.93k|                retval = sav_skip_document_record(ctx);
 1455|  1.93k|                if (retval != READSTAT_OK)
  ------------------
  |  Branch (1455:21): [True: 55, False: 1.88k]
  ------------------
 1456|     55|                    goto cleanup;
 1457|  1.88k|                break;
 1458|  5.50k|            case SAV_RECORD_TYPE_DICT_TERMINATION:
  ------------------
  |  |  122|  5.50k|#define SAV_RECORD_TYPE_DICT_TERMINATION        999
  ------------------
  |  Branch (1458:13): [True: 5.50k, False: 589k]
  ------------------
 1459|  5.50k|                done = 1;
 1460|  5.50k|                break;
 1461|  42.8k|            case SAV_RECORD_TYPE_HAS_DATA:
  ------------------
  |  |  121|  42.8k|#define SAV_RECORD_TYPE_HAS_DATA                7
  ------------------
  |  Branch (1461:13): [True: 42.8k, False: 552k]
  ------------------
 1462|  42.8k|                if (io->read(extra_info, sizeof(extra_info), io->io_ctx) < sizeof(extra_info)) {
  ------------------
  |  Branch (1462:21): [True: 5, False: 42.8k]
  ------------------
 1463|      5|                    retval = READSTAT_ERROR_READ;
 1464|      5|                    goto cleanup;
 1465|      5|                }
 1466|  42.8k|                if (ctx->bswap) {
  ------------------
  |  Branch (1466:21): [True: 4.44k, False: 38.4k]
  ------------------
 1467|  17.7k|                    for (i=0; i<3; i++)
  ------------------
  |  Branch (1467:31): [True: 13.3k, False: 4.44k]
  ------------------
 1468|  13.3k|                        extra_info[i] = byteswap4(extra_info[i]);
 1469|  4.44k|                }
 1470|  42.8k|                uint32_t subtype = extra_info[0];
 1471|  42.8k|                size_t size = extra_info[1];
 1472|  42.8k|                size_t count = extra_info[2];
 1473|  42.8k|                if (size && count > SIZE_MAX / size) {
  ------------------
  |  Branch (1473:21): [True: 42.3k, False: 496]
  |  Branch (1473:29): [True: 0, False: 42.3k]
  ------------------
 1474|      0|                    retval = READSTAT_ERROR_PARSE;
 1475|      0|                    goto cleanup;
 1476|      0|                }
 1477|  42.8k|                data_len = size * count;
 1478|  42.8k|                if (subtype == SAV_RECORD_SUBTYPE_INTEGER_INFO ||
  ------------------
  |  |  124|  85.7k|#define SAV_RECORD_SUBTYPE_INTEGER_INFO       3
  ------------------
  |  Branch (1478:21): [True: 1.18k, False: 41.6k]
  ------------------
 1479|  41.6k|                        subtype == SAV_RECORD_SUBTYPE_FP_INFO ||
  ------------------
  |  |  125|  84.5k|#define SAV_RECORD_SUBTYPE_FP_INFO            4
  ------------------
  |  Branch (1479:25): [True: 1.91k, False: 39.7k]
  ------------------
 1480|  39.7k|                        subtype == SAV_RECORD_SUBTYPE_CHAR_ENCODING) {
  ------------------
  |  |  135|  39.7k|#define SAV_RECORD_SUBTYPE_CHAR_ENCODING     20
  ------------------
  |  Branch (1480:25): [True: 958, False: 38.7k]
  ------------------
 1481|  4.06k|                    if (data_len > sizeof(data_buf)) {
  ------------------
  |  Branch (1481:25): [True: 61, False: 4.00k]
  ------------------
 1482|     61|                        retval = READSTAT_ERROR_PARSE;
 1483|     61|                        goto cleanup;
 1484|     61|                    }
 1485|  4.00k|                    if (data_len && io->read(data_buf, data_len, io->io_ctx) < data_len) {
  ------------------
  |  Branch (1485:25): [True: 2.46k, False: 1.53k]
  |  Branch (1485:37): [True: 17, False: 2.45k]
  ------------------
 1486|     17|                        retval = READSTAT_ERROR_PARSE;
 1487|     17|                        goto cleanup;
 1488|     17|                    }
 1489|  3.98k|                    if (subtype == SAV_RECORD_SUBTYPE_INTEGER_INFO) {
  ------------------
  |  |  124|  3.98k|#define SAV_RECORD_SUBTYPE_INTEGER_INFO       3
  ------------------
  |  Branch (1489:25): [True: 1.16k, False: 2.82k]
  ------------------
 1490|  1.16k|                        retval = sav_parse_machine_integer_info_record(data_buf, data_len, ctx);
 1491|  2.82k|                    } else if (subtype == SAV_RECORD_SUBTYPE_FP_INFO) {
  ------------------
  |  |  125|  2.82k|#define SAV_RECORD_SUBTYPE_FP_INFO            4
  ------------------
  |  Branch (1491:32): [True: 1.88k, False: 937]
  ------------------
 1492|       |                        /* Parsed here so the file's SYSMIS/LOWEST/HIGHEST are
 1493|       |                         * known before the variable records' missing values */
 1494|  1.88k|                        retval = sav_parse_machine_floating_point_record(data_buf, size, count, ctx);
 1495|  1.88k|                    } else {
 1496|    937|                        retval = sav_parse_character_encoding_record(data_buf, data_len, ctx);
 1497|    937|                    }
 1498|  3.98k|                    if (retval != READSTAT_OK)
  ------------------
  |  Branch (1498:25): [True: 0, False: 3.98k]
  ------------------
 1499|      0|                        goto cleanup;
 1500|  38.7k|                } else {
 1501|  38.7k|                    if (io->seek(data_len, READSTAT_SEEK_CUR, io->io_ctx) == -1) {
  ------------------
  |  Branch (1501:25): [True: 102, False: 38.6k]
  ------------------
 1502|    102|                        retval = READSTAT_ERROR_SEEK;
 1503|    102|                        goto cleanup;
 1504|    102|                    }
 1505|  38.7k|                }
 1506|  42.6k|                break;
 1507|  42.6k|            default:
  ------------------
  |  Branch (1507:13): [True: 85, False: 594k]
  ------------------
 1508|     85|                retval = READSTAT_ERROR_PARSE;
 1509|     85|                goto cleanup;
 1510|      0|                break;
 1511|   594k|        }
 1512|   594k|        if (done)
  ------------------
  |  Branch (1512:13): [True: 5.50k, False: 588k]
  ------------------
 1513|  5.50k|            break;
 1514|   594k|    }
 1515|  6.62k|cleanup:
 1516|  6.62k|    return retval;
 1517|  6.62k|}
readstat_sav_read.c:sav_skip_variable_record:
  190|   462k|static readstat_error_t sav_skip_variable_record(sav_ctx_t *ctx) {
  191|   462k|    sav_variable_record_t variable;
  192|   462k|    readstat_error_t retval = READSTAT_OK;
  193|   462k|    readstat_io_t *io = ctx->io;
  194|   462k|    if (io->read(&variable, sizeof(sav_variable_record_t), io->io_ctx) < sizeof(sav_variable_record_t)) {
  ------------------
  |  Branch (194:9): [True: 8, False: 462k]
  ------------------
  195|      8|        retval = READSTAT_ERROR_READ;
  196|      8|        goto cleanup;
  197|      8|    }
  198|   462k|    if (variable.has_var_label) {
  ------------------
  |  Branch (198:9): [True: 29.2k, False: 432k]
  ------------------
  199|  29.2k|        uint32_t label_len;
  200|  29.2k|        if (io->read(&label_len, sizeof(uint32_t), io->io_ctx) < sizeof(uint32_t)) {
  ------------------
  |  Branch (200:13): [True: 47, False: 29.1k]
  ------------------
  201|     47|            retval = READSTAT_ERROR_READ;
  202|     47|            goto cleanup;
  203|     47|        }
  204|  29.1k|        label_len = ctx->bswap ? byteswap4(label_len) : label_len;
  ------------------
  |  Branch (204:21): [True: 885, False: 28.3k]
  ------------------
  205|  29.1k|        readstat_off_t label_capacity = ((readstat_off_t)label_len + 3) / 4 * 4;
  206|  29.1k|        if (io->seek(label_capacity, READSTAT_SEEK_CUR, io->io_ctx) == -1) {
  ------------------
  |  Branch (206:13): [True: 6, False: 29.1k]
  ------------------
  207|      6|            retval = READSTAT_ERROR_SEEK;
  208|      6|            goto cleanup;
  209|      6|        }
  210|  29.1k|    }
  211|   461k|    if (variable.n_missing_values) {
  ------------------
  |  Branch (211:9): [True: 31.1k, False: 430k]
  ------------------
  212|  31.1k|        int n_missing_values = ctx->bswap ? byteswap4(variable.n_missing_values) : variable.n_missing_values;
  ------------------
  |  Branch (212:32): [True: 2.69k, False: 28.4k]
  ------------------
  213|  31.1k|        if (n_missing_values > 3 || n_missing_values < -3) {
  ------------------
  |  Branch (213:13): [True: 21, False: 31.0k]
  |  Branch (213:37): [True: 56, False: 31.0k]
  ------------------
  214|     77|            retval = READSTAT_ERROR_PARSE;
  215|     77|            goto cleanup;
  216|     77|        }
  217|  31.0k|        if (io->seek(abs(n_missing_values) * sizeof(double), READSTAT_SEEK_CUR, io->io_ctx) == -1) {
  ------------------
  |  Branch (217:13): [True: 17, False: 31.0k]
  ------------------
  218|     17|            retval = READSTAT_ERROR_SEEK;
  219|     17|            goto cleanup;
  220|     17|        }
  221|  31.0k|    }
  222|   462k|cleanup:
  223|   462k|    return retval;
  224|   461k|}
readstat_sav_read.c:sav_skip_value_label_record:
  470|  82.5k|static readstat_error_t sav_skip_value_label_record(sav_ctx_t *ctx) {
  471|  82.5k|    uint32_t label_count;
  472|  82.5k|    uint32_t rec_type;
  473|  82.5k|    uint32_t var_count;
  474|  82.5k|    readstat_error_t retval = READSTAT_OK;
  475|  82.5k|    readstat_io_t *io = ctx->io;
  476|  82.5k|    if (io->read(&label_count, sizeof(uint32_t), io->io_ctx) < sizeof(uint32_t)) {
  ------------------
  |  Branch (476:9): [True: 3, False: 82.5k]
  ------------------
  477|      3|        retval = READSTAT_ERROR_READ;
  478|      3|        goto cleanup;
  479|      3|    }
  480|  82.5k|    if (ctx->bswap)
  ------------------
  |  Branch (480:9): [True: 4.01k, False: 78.4k]
  ------------------
  481|  4.01k|        label_count = byteswap4(label_count);
  482|  82.5k|    int i;
  483|   286k|    for (i=0; i<label_count; i++) {
  ------------------
  |  Branch (483:15): [True: 203k, False: 82.4k]
  ------------------
  484|   203k|        unsigned char unpadded_len = 0;
  485|   203k|        size_t padded_len = 0;
  486|   203k|        if (io->seek(8, READSTAT_SEEK_CUR, io->io_ctx) == -1) {
  ------------------
  |  Branch (486:13): [True: 75, False: 203k]
  ------------------
  487|     75|            retval = READSTAT_ERROR_SEEK;
  488|     75|            goto cleanup;
  489|     75|        }
  490|   203k|        if (io->read(&unpadded_len, 1, io->io_ctx) < 1) {
  ------------------
  |  Branch (490:13): [True: 20, False: 203k]
  ------------------
  491|     20|            retval = READSTAT_ERROR_READ;
  492|     20|            goto cleanup;
  493|     20|        }
  494|   203k|        padded_len = (unpadded_len + 8) / 8 * 8 - 1;
  495|   203k|        if (io->seek(padded_len, READSTAT_SEEK_CUR, io->io_ctx) == -1) {
  ------------------
  |  Branch (495:13): [True: 2, False: 203k]
  ------------------
  496|      2|            retval = READSTAT_ERROR_SEEK;
  497|      2|            goto cleanup;
  498|      2|        }
  499|   203k|    }
  500|       |
  501|  82.4k|    if (io->read(&rec_type, sizeof(uint32_t), io->io_ctx) < sizeof(uint32_t)) {
  ------------------
  |  Branch (501:9): [True: 20, False: 82.3k]
  ------------------
  502|     20|        retval = READSTAT_ERROR_READ;
  503|     20|        goto cleanup;
  504|     20|    }
  505|  82.3k|    if (ctx->bswap)
  ------------------
  |  Branch (505:9): [True: 3.95k, False: 78.4k]
  ------------------
  506|  3.95k|        rec_type = byteswap4(rec_type);
  507|       |    
  508|  82.3k|    if (rec_type != 4) {
  ------------------
  |  Branch (508:9): [True: 49, False: 82.3k]
  ------------------
  509|     49|        retval = READSTAT_ERROR_PARSE;
  510|     49|        goto cleanup;
  511|     49|    }
  512|  82.3k|    if (io->read(&var_count, sizeof(uint32_t), io->io_ctx) < sizeof(uint32_t)) {
  ------------------
  |  Branch (512:9): [True: 9, False: 82.3k]
  ------------------
  513|      9|        retval = READSTAT_ERROR_READ;
  514|      9|        goto cleanup;
  515|      9|    }
  516|  82.3k|    if (ctx->bswap)
  ------------------
  |  Branch (516:9): [True: 3.93k, False: 78.4k]
  ------------------
  517|  3.93k|        var_count = byteswap4(var_count);
  518|       |    
  519|  82.3k|    if (io->seek(var_count * sizeof(uint32_t), READSTAT_SEEK_CUR, io->io_ctx) == -1) {
  ------------------
  |  Branch (519:9): [True: 6, False: 82.3k]
  ------------------
  520|      6|        retval = READSTAT_ERROR_SEEK;
  521|      6|        goto cleanup;
  522|      6|    }
  523|       |
  524|  82.5k|cleanup:
  525|  82.5k|    return retval;
  526|  82.3k|}
readstat_sav_read.c:sav_skip_document_record:
  682|  1.93k|static readstat_error_t sav_skip_document_record(sav_ctx_t *ctx) {
  683|  1.93k|    uint32_t n_lines;
  684|  1.93k|    readstat_error_t retval = READSTAT_OK;
  685|  1.93k|    readstat_io_t *io = ctx->io;
  686|  1.93k|    if (io->read(&n_lines, sizeof(uint32_t), io->io_ctx) < sizeof(uint32_t)) {
  ------------------
  |  Branch (686:9): [True: 3, False: 1.93k]
  ------------------
  687|      3|        retval = READSTAT_ERROR_READ;
  688|      3|        goto cleanup;
  689|      3|    }
  690|  1.93k|    if (ctx->bswap)
  ------------------
  |  Branch (690:9): [True: 885, False: 1.04k]
  ------------------
  691|    885|        n_lines = byteswap4(n_lines);
  692|  1.93k|    if (io->seek((readstat_off_t)n_lines * SPSS_DOC_LINE_SIZE, READSTAT_SEEK_CUR, io->io_ctx) == -1) {
  ------------------
  |  |   40|  1.93k|#define SPSS_DOC_LINE_SIZE  80
  ------------------
  |  Branch (692:9): [True: 52, False: 1.88k]
  ------------------
  693|     52|        retval = READSTAT_ERROR_SEEK;
  694|     52|        goto cleanup;
  695|     52|    }
  696|       |    
  697|  1.93k|cleanup:
  698|  1.93k|    return retval;
  699|  1.93k|}
readstat_sav_read.c:sav_parse_machine_integer_info_record:
 1009|  1.16k|static readstat_error_t sav_parse_machine_integer_info_record(const void *data, size_t data_len, sav_ctx_t *ctx) {
 1010|  1.16k|    if (data_len != 32)
  ------------------
  |  Branch (1010:9): [True: 325, False: 840]
  ------------------
 1011|    325|        return READSTAT_OK; /* malformed; ignore the record like PSPP does */
 1012|       |
 1013|    840|    sav_machine_integer_info_record_t record;
 1014|    840|    memcpy(&record, data, data_len);
 1015|    840|    ctx->charset_code = ctx->bswap ? byteswap4(record.character_code) : record.character_code;
  ------------------
  |  Branch (1015:25): [True: 260, False: 580]
  ------------------
 1016|    840|    return READSTAT_OK;
 1017|  1.16k|}
readstat_sav_read.c:sav_parse_machine_floating_point_record:
 1096|  1.88k|static readstat_error_t sav_parse_machine_floating_point_record(const void *data, size_t size, size_t count, sav_ctx_t *ctx) {
 1097|  1.88k|    if (size != 8 || count != 3)
  ------------------
  |  Branch (1097:9): [True: 871, False: 1.01k]
  |  Branch (1097:22): [True: 296, False: 718]
  ------------------
 1098|  1.16k|        return READSTAT_OK; /* malformed; ignore the record like PSPP does */
 1099|       |
 1100|    718|    sav_machine_floating_point_info_record_t fp_info;
 1101|    718|    memcpy(&fp_info, data, sizeof(sav_machine_floating_point_info_record_t));
 1102|       |
 1103|    718|    ctx->missing_double = ctx->bswap ? byteswap8(fp_info.sysmis) : fp_info.sysmis;
  ------------------
  |  Branch (1103:27): [True: 213, False: 505]
  ------------------
 1104|    718|    ctx->highest_double = ctx->bswap ? byteswap8(fp_info.highest) : fp_info.highest;
  ------------------
  |  Branch (1104:27): [True: 213, False: 505]
  ------------------
 1105|    718|    ctx->lowest_double = ctx->bswap ? byteswap8(fp_info.lowest) : fp_info.lowest;
  ------------------
  |  Branch (1105:26): [True: 213, False: 505]
  ------------------
 1106|       |
 1107|    718|    return READSTAT_OK;
 1108|  1.88k|}
readstat_sav_read.c:sav_parse_character_encoding_record:
 1021|    937|static readstat_error_t sav_parse_character_encoding_record(const void *data, size_t data_len, sav_ctx_t *ctx) {
 1022|    937|    if (data_len == 0 || data_len >= sizeof(ctx->charset_name))
  ------------------
  |  Branch (1022:9): [True: 209, False: 728]
  |  Branch (1022:26): [True: 208, False: 520]
  ------------------
 1023|    417|        return READSTAT_OK;
 1024|    520|    readstat_convert(ctx->charset_name, sizeof(ctx->charset_name), data, data_len, NULL);
 1025|    520|    return READSTAT_OK;
 1026|    937|}
readstat_sav_read.c:sav_setup_converter:
 1047|  5.50k|static readstat_error_t sav_setup_converter(sav_ctx_t *ctx) {
 1048|  5.50k|    const char *dst_charset = ctx->output_encoding;
 1049|  5.50k|    const char *code_charset = sav_charset_name_for_code(ctx->charset_code);
 1050|  5.50k|    const char *src_charset = NULL;
 1051|  5.50k|    iconv_t converter = (iconv_t)-1;
 1052|       |
 1053|  5.50k|    if (ctx->input_encoding) {
  ------------------
  |  Branch (1053:9): [True: 0, False: 5.50k]
  ------------------
 1054|      0|        src_charset = ctx->input_encoding;
 1055|      0|        converter = sav_open_converter(src_charset, dst_charset);
 1056|  5.50k|    } else if (ctx->charset_name[0]) {
  ------------------
  |  Branch (1056:16): [True: 147, False: 5.35k]
  ------------------
 1057|    147|        src_charset = ctx->charset_name;
 1058|    147|        converter = sav_open_converter(src_charset, dst_charset);
 1059|    147|        if (converter == (iconv_t)-1 && code_charset) {
  ------------------
  |  Branch (1059:13): [True: 6, False: 141]
  |  Branch (1059:41): [True: 1, False: 5]
  ------------------
 1060|      1|            src_charset = code_charset;
 1061|      1|            converter = sav_open_converter(src_charset, dst_charset);
 1062|      1|        }
 1063|  5.35k|    } else if (code_charset) {
  ------------------
  |  Branch (1063:16): [True: 79, False: 5.28k]
  ------------------
 1064|     79|        src_charset = code_charset;
 1065|     79|        converter = sav_open_converter(src_charset, dst_charset);
 1066|  5.28k|    } else if (ctx->charset_code) {
  ------------------
  |  Branch (1066:16): [True: 37, False: 5.24k]
  ------------------
 1067|     37|        char error_buf[1024];
 1068|     37|        snprintf(error_buf, sizeof(error_buf), "Unsupported character set: %d\n", ctx->charset_code);
 1069|     37|        sav_report_error(ctx, error_buf);
 1070|     37|        return READSTAT_ERROR_UNSUPPORTED_CHARSET;
 1071|     37|    }
 1072|       |
 1073|  5.46k|    if (src_charset && dst_charset && converter == (iconv_t)-1) {
  ------------------
  |  Branch (1073:9): [True: 226, False: 5.24k]
  |  Branch (1073:24): [True: 226, False: 0]
  |  Branch (1073:39): [True: 5, False: 221]
  ------------------
 1074|      5|        char error_buf[1024];
 1075|      5|        snprintf(error_buf, sizeof(error_buf), "Unsupported character set: %s\n", src_charset);
 1076|      5|        sav_report_error(ctx, error_buf);
 1077|      5|        return READSTAT_ERROR_UNSUPPORTED_CHARSET;
 1078|      5|    }
 1079|       |
 1080|  5.46k|    ctx->input_encoding = src_charset;
 1081|  5.46k|    if (converter != (iconv_t)-1) {
  ------------------
  |  Branch (1081:9): [True: 221, False: 5.24k]
  ------------------
 1082|       |        // You might be tempted to skip the charset conversion when src_charset
 1083|       |        // and dst_charset are the same. However, some versions of SPSS insert
 1084|       |        // illegally truncated strings (e.g. the last character is three bytes
 1085|       |        // but the field only has room for two bytes). So to prevent the client
 1086|       |        // from receiving an invalid byte sequence, we ram everything through
 1087|       |        // our iconv machinery.
 1088|    221|        if (ctx->converter) {
  ------------------
  |  Branch (1088:13): [True: 0, False: 221]
  ------------------
 1089|      0|            iconv_close(ctx->converter);
 1090|      0|        }
 1091|    221|        ctx->converter = converter;
 1092|    221|    }
 1093|  5.46k|    return READSTAT_OK;
 1094|  5.46k|}
readstat_sav_read.c:sav_charset_name_for_code:
 1028|  5.50k|static const char *sav_charset_name_for_code(int code) {
 1029|  5.50k|    int i;
 1030|   437k|    for (i=0; i<sizeof(_charset_table)/sizeof(_charset_table[0]); i++) {
  ------------------
  |  Branch (1030:15): [True: 432k, False: 5.42k]
  ------------------
 1031|   432k|        if (code == _charset_table[i].code) {
  ------------------
  |  Branch (1031:13): [True: 80, False: 432k]
  ------------------
 1032|     80|            return _charset_table[i].name;
 1033|     80|        }
 1034|   432k|    }
 1035|  5.42k|    return NULL;
 1036|  5.50k|}
readstat_sav_read.c:sav_open_converter:
 1038|    227|static iconv_t sav_open_converter(const char *src_charset, const char *dst_charset) {
 1039|    227|    if (src_charset == NULL || dst_charset == NULL)
  ------------------
  |  Branch (1039:9): [True: 0, False: 227]
  |  Branch (1039:32): [True: 0, False: 227]
  ------------------
 1040|      0|        return (iconv_t)-1;
 1041|    227|    return iconv_open(dst_charset, src_charset);
 1042|    227|}
readstat_sav_read.c:sav_report_error:
  152|  28.8k|static void sav_report_error(sav_ctx_t *ctx, const char *message) {
  153|  28.8k|    if (ctx->handle.error) {
  ------------------
  |  Branch (153:9): [True: 0, False: 28.8k]
  ------------------
  154|      0|        ctx->handle.error(message, ctx->user_ctx);
  155|      0|    }
  156|  28.8k|}
readstat_sav_read.c:sav_parse_records_pass2:
 1519|  5.46k|static readstat_error_t sav_parse_records_pass2(sav_ctx_t *ctx) {
 1520|  5.46k|    void *data_buf = NULL;
 1521|  5.46k|    size_t data_buf_capacity = 4096;
 1522|  5.46k|    readstat_error_t retval = READSTAT_OK;
 1523|  5.46k|    readstat_io_t *io = ctx->io;
 1524|       |
 1525|  5.46k|    if ((data_buf = readstat_malloc(data_buf_capacity)) == NULL) {
  ------------------
  |  Branch (1525:9): [True: 0, False: 5.46k]
  ------------------
 1526|      0|        retval = READSTAT_ERROR_MALLOC;
 1527|      0|        goto cleanup;
 1528|      0|    }
 1529|       |
 1530|   537k|    while (1) {
  ------------------
  |  Branch (1530:12): [True: 537k, Folded]
  ------------------
 1531|   537k|        uint32_t rec_type;
 1532|   537k|        uint32_t extra_info[3];
 1533|   537k|        size_t data_len = 0;
 1534|   537k|        int i;
 1535|   537k|        int done = 0;
 1536|   537k|        if (io->read(&rec_type, sizeof(uint32_t), io->io_ctx) < sizeof(uint32_t)) {
  ------------------
  |  Branch (1536:13): [True: 0, False: 537k]
  ------------------
 1537|      0|            retval = READSTAT_ERROR_READ;
 1538|      0|            goto cleanup;
 1539|      0|        }
 1540|       |        
 1541|   537k|        if (ctx->bswap) {
  ------------------
  |  Branch (1541:13): [True: 24.9k, False: 512k]
  ------------------
 1542|  24.9k|            rec_type = byteswap4(rec_type);
 1543|  24.9k|        }
 1544|       |        
 1545|   537k|        switch (rec_type) {
 1546|   445k|            case SAV_RECORD_TYPE_VARIABLE:
  ------------------
  |  |  117|   445k|#define SAV_RECORD_TYPE_VARIABLE                2
  ------------------
  |  Branch (1546:13): [True: 445k, False: 91.6k]
  ------------------
 1547|   445k|                if ((retval = sav_read_variable_record(ctx)) != READSTAT_OK)
  ------------------
  |  Branch (1547:21): [True: 40, False: 445k]
  ------------------
 1548|     40|                    goto cleanup;
 1549|   445k|                break;
 1550|   445k|            case SAV_RECORD_TYPE_VALUE_LABEL:
  ------------------
  |  |  118|  49.4k|#define SAV_RECORD_TYPE_VALUE_LABEL             3
  ------------------
  |  Branch (1550:13): [True: 49.4k, False: 488k]
  ------------------
 1551|  49.4k|                if ((retval = sav_read_value_label_record(ctx)) != READSTAT_OK)
  ------------------
  |  Branch (1551:21): [True: 10, False: 49.4k]
  ------------------
 1552|     10|                    goto cleanup;
 1553|  49.4k|                break;
 1554|  49.4k|            case SAV_RECORD_TYPE_DOCUMENT:
  ------------------
  |  |  120|  1.22k|#define SAV_RECORD_TYPE_DOCUMENT                6
  ------------------
  |  Branch (1554:13): [True: 1.22k, False: 536k]
  ------------------
 1555|  1.22k|                if ((retval = sav_read_document_record(ctx)) != READSTAT_OK)
  ------------------
  |  Branch (1555:21): [True: 1, False: 1.22k]
  ------------------
 1556|      1|                    goto cleanup;
 1557|  1.22k|                break;
 1558|  4.43k|            case SAV_RECORD_TYPE_DICT_TERMINATION:
  ------------------
  |  |  122|  4.43k|#define SAV_RECORD_TYPE_DICT_TERMINATION        999
  ------------------
  |  Branch (1558:13): [True: 4.43k, False: 533k]
  ------------------
 1559|  4.43k|                if ((retval = sav_read_dictionary_termination_record(ctx)) != READSTAT_OK)
  ------------------
  |  Branch (1559:21): [True: 2.45k, False: 1.97k]
  ------------------
 1560|  2.45k|                    goto cleanup;
 1561|  1.97k|                done = 1;
 1562|  1.97k|                break;
 1563|  36.5k|            case SAV_RECORD_TYPE_HAS_DATA:
  ------------------
  |  |  121|  36.5k|#define SAV_RECORD_TYPE_HAS_DATA                7
  ------------------
  |  Branch (1563:13): [True: 36.5k, False: 500k]
  ------------------
 1564|  36.5k|                if (io->read(extra_info, sizeof(extra_info), io->io_ctx) < sizeof(extra_info)) {
  ------------------
  |  Branch (1564:21): [True: 0, False: 36.5k]
  ------------------
 1565|      0|                    retval = READSTAT_ERROR_READ;
 1566|      0|                    goto cleanup;
 1567|      0|                }
 1568|  36.5k|                if (ctx->bswap) {
  ------------------
  |  Branch (1568:21): [True: 2.47k, False: 34.1k]
  ------------------
 1569|  9.91k|                    for (i=0; i<3; i++)
  ------------------
  |  Branch (1569:31): [True: 7.43k, False: 2.47k]
  ------------------
 1570|  7.43k|                        extra_info[i] = byteswap4(extra_info[i]);
 1571|  2.47k|                }
 1572|  36.5k|                uint32_t subtype = extra_info[0];
 1573|  36.5k|                size_t size = extra_info[1];
 1574|  36.5k|                size_t count = extra_info[2];
 1575|  36.5k|                if (size && count > SIZE_MAX / size) {
  ------------------
  |  Branch (1575:21): [True: 36.4k, False: 168]
  |  Branch (1575:29): [True: 0, False: 36.4k]
  ------------------
 1576|      0|                    retval = READSTAT_ERROR_PARSE;
 1577|      0|                    goto cleanup;
 1578|      0|                }
 1579|  36.5k|                data_len = size * count;
 1580|  36.5k|                if (data_buf_capacity < data_len) {
  ------------------
  |  Branch (1580:21): [True: 62, False: 36.5k]
  ------------------
 1581|     62|                    if ((data_buf = readstat_realloc(data_buf, data_buf_capacity = data_len)) == NULL) {
  ------------------
  |  Branch (1581:25): [True: 0, False: 62]
  ------------------
 1582|      0|                        retval = READSTAT_ERROR_MALLOC;
 1583|      0|                        goto cleanup;
 1584|      0|                    }
 1585|     62|                }
 1586|  36.5k|                if (data_len == 0)
  ------------------
  |  Branch (1586:21): [True: 741, False: 35.8k]
  ------------------
 1587|    741|                    break; /* nothing to parse */
 1588|  35.8k|                if (io->read(data_buf, data_len, io->io_ctx) < data_len) {
  ------------------
  |  Branch (1588:21): [True: 0, False: 35.8k]
  ------------------
 1589|      0|                    retval = READSTAT_ERROR_PARSE;
 1590|      0|                    goto cleanup;
 1591|      0|                }
 1592|       |                
 1593|  35.8k|                switch (subtype) {
 1594|    106|                    case SAV_RECORD_SUBTYPE_INTEGER_INFO:
  ------------------
  |  |  124|    106|#define SAV_RECORD_SUBTYPE_INTEGER_INFO       3
  ------------------
  |  Branch (1594:21): [True: 106, False: 35.7k]
  ------------------
 1595|    164|                    case SAV_RECORD_SUBTYPE_FP_INFO:
  ------------------
  |  |  125|    164|#define SAV_RECORD_SUBTYPE_FP_INFO            4
  ------------------
  |  Branch (1595:21): [True: 58, False: 35.7k]
  ------------------
 1596|    301|                    case SAV_RECORD_SUBTYPE_CHAR_ENCODING:
  ------------------
  |  |  135|    301|#define SAV_RECORD_SUBTYPE_CHAR_ENCODING     20
  ------------------
  |  Branch (1596:21): [True: 137, False: 35.7k]
  ------------------
 1597|       |                        /* parsed in pass 1 */
 1598|    301|                        break;
 1599|  26.3k|                    case SAV_RECORD_SUBTYPE_MULTIPLE_RESPONSE_SETS:
  ------------------
  |  |  126|  26.3k|#define SAV_RECORD_SUBTYPE_MULTIPLE_RESPONSE_SETS 7
  ------------------
  |  Branch (1599:21): [True: 26.3k, False: 9.54k]
  ------------------
 1600|  28.6k|                    case SAV_RECORD_SUBTYPE_MULTIPLE_RESPONSE_SETS_V14:
  ------------------
  |  |  127|  28.6k|#define SAV_RECORD_SUBTYPE_MULTIPLE_RESPONSE_SETS_V14 19
  ------------------
  |  Branch (1600:21): [True: 2.39k, False: 33.4k]
  ------------------
 1601|  28.6k|                        retval = sav_read_multiple_response_sets(data_buf, data_len, ctx);
 1602|  28.6k|                        if (retval != READSTAT_OK)
  ------------------
  |  Branch (1602:29): [True: 0, False: 28.6k]
  ------------------
 1603|      0|                            goto cleanup;
 1604|  28.6k|                        break;
 1605|  28.6k|                    case SAV_RECORD_SUBTYPE_VAR_DISPLAY:
  ------------------
  |  |  129|    688|#define SAV_RECORD_SUBTYPE_VAR_DISPLAY       11
  ------------------
  |  Branch (1605:21): [True: 688, False: 35.1k]
  ------------------
 1606|    688|                        retval = sav_store_variable_display_parameter_record(data_buf, size, count, ctx);
 1607|    688|                        if (retval != READSTAT_OK)
  ------------------
  |  Branch (1607:29): [True: 0, False: 688]
  ------------------
 1608|      0|                            goto cleanup;
 1609|    688|                        break;
 1610|  1.18k|                    case SAV_RECORD_SUBTYPE_LONG_VAR_NAME:
  ------------------
  |  |  130|  1.18k|#define SAV_RECORD_SUBTYPE_LONG_VAR_NAME     13
  ------------------
  |  Branch (1610:21): [True: 1.18k, False: 34.6k]
  ------------------
 1611|  1.18k|                        retval = sav_parse_long_variable_names_record(data_buf, count, ctx);
 1612|  1.18k|                        if (retval != READSTAT_OK)
  ------------------
  |  Branch (1612:29): [True: 167, False: 1.02k]
  ------------------
 1613|    167|                            goto cleanup;
 1614|  1.02k|                        break;
 1615|  1.82k|                    case SAV_RECORD_SUBTYPE_VERY_LONG_STR:
  ------------------
  |  |  131|  1.82k|#define SAV_RECORD_SUBTYPE_VERY_LONG_STR     14
  ------------------
  |  Branch (1615:21): [True: 1.82k, False: 34.0k]
  ------------------
 1616|  1.82k|                        retval = sav_parse_very_long_string_record(data_buf, count, ctx);
 1617|  1.82k|                        if (retval != READSTAT_OK)
  ------------------
  |  Branch (1617:29): [True: 160, False: 1.66k]
  ------------------
 1618|    160|                            goto cleanup;
 1619|  1.66k|                        break;
 1620|  1.66k|                    case SAV_RECORD_SUBTYPE_LONG_STRING_VALUE_LABELS:
  ------------------
  |  |  136|    867|#define SAV_RECORD_SUBTYPE_LONG_STRING_VALUE_LABELS   21
  ------------------
  |  Branch (1620:21): [True: 867, False: 34.9k]
  ------------------
 1621|    867|                        retval = sav_parse_long_string_value_labels_record(data_buf, size, count, ctx);
 1622|    867|                        if (retval != READSTAT_OK)
  ------------------
  |  Branch (1622:29): [True: 331, False: 536]
  ------------------
 1623|    331|                            goto cleanup;
 1624|    536|                        break;
 1625|    943|                    case SAV_RECORD_SUBTYPE_LONG_STRING_MISSING_VALUES:
  ------------------
  |  |  137|    943|#define SAV_RECORD_SUBTYPE_LONG_STRING_MISSING_VALUES 22
  ------------------
  |  Branch (1625:21): [True: 943, False: 34.9k]
  ------------------
 1626|    943|                        retval = sav_parse_long_string_missing_values_record(data_buf, size, count, ctx);
 1627|    943|                        if (retval != READSTAT_OK)
  ------------------
  |  Branch (1627:29): [True: 320, False: 623]
  ------------------
 1628|    320|                            goto cleanup;
 1629|    623|                        break;
 1630|  1.33k|                    default: /* misc. info */
  ------------------
  |  Branch (1630:21): [True: 1.33k, False: 34.5k]
  ------------------
 1631|  1.33k|                        break;
 1632|  35.8k|                }
 1633|  34.8k|                break;
 1634|  34.8k|            default:
  ------------------
  |  Branch (1634:13): [True: 0, False: 537k]
  ------------------
 1635|      0|                retval = READSTAT_ERROR_PARSE;
 1636|      0|                goto cleanup;
 1637|      0|                break;
 1638|   537k|        }
 1639|   534k|        if (done)
  ------------------
  |  Branch (1639:13): [True: 1.97k, False: 532k]
  ------------------
 1640|  1.97k|            break;
 1641|   534k|    }
 1642|  5.46k|cleanup:
 1643|  5.46k|    if (data_buf)
  ------------------
  |  Branch (1643:9): [True: 5.46k, False: 0]
  ------------------
 1644|  5.46k|        free(data_buf);
 1645|  5.46k|    return retval;
 1646|  5.46k|}
readstat_sav_read.c:sav_read_variable_record:
  364|   445k|static readstat_error_t sav_read_variable_record(sav_ctx_t *ctx) {
  365|   445k|    readstat_io_t *io = ctx->io;
  366|   445k|    sav_variable_record_t variable = { 0 };
  367|   445k|    spss_varinfo_t *info = NULL;
  368|   445k|    readstat_error_t retval = READSTAT_OK;
  369|   445k|    if (ctx->var_index == ctx->varinfo_capacity) {
  ------------------
  |  Branch (369:9): [True: 259, False: 445k]
  ------------------
  370|    259|        if ((ctx->varinfo = readstat_realloc(ctx->varinfo, (ctx->varinfo_capacity *= 2) * sizeof(spss_varinfo_t *))) == NULL) {
  ------------------
  |  Branch (370:13): [True: 0, False: 259]
  ------------------
  371|      0|            retval = READSTAT_ERROR_MALLOC;
  372|      0|            goto cleanup;
  373|      0|        }
  374|    259|    }
  375|   445k|    if (io->read(&variable, sizeof(sav_variable_record_t), io->io_ctx) < sizeof(sav_variable_record_t)) {
  ------------------
  |  Branch (375:9): [True: 0, False: 445k]
  ------------------
  376|      0|        retval = READSTAT_ERROR_READ;
  377|      0|        goto cleanup;
  378|      0|    }
  379|   445k|    variable.print = ctx->bswap ? byteswap4(variable.print) : variable.print;
  ------------------
  |  Branch (379:22): [True: 18.3k, False: 427k]
  ------------------
  380|   445k|    variable.write = ctx->bswap ? byteswap4(variable.write) : variable.write;
  ------------------
  |  Branch (380:22): [True: 18.3k, False: 427k]
  ------------------
  381|       |
  382|   445k|    int32_t type = ctx->bswap ? byteswap4(variable.type) : variable.type;
  ------------------
  |  Branch (382:20): [True: 18.3k, False: 427k]
  ------------------
  383|   445k|    if (type < 0) {
  ------------------
  |  Branch (383:9): [True: 5.04k, False: 440k]
  ------------------
  384|  5.04k|        if (ctx->var_index == 0 || ctx->varinfo[ctx->var_index-1]->type != READSTAT_TYPE_STRING) {
  ------------------
  |  Branch (384:13): [True: 31, False: 5.01k]
  |  Branch (384:36): [True: 1, False: 5.00k]
  ------------------
  385|     32|            return READSTAT_ERROR_PARSE;
  386|     32|        }
  387|       |        /* Some files put a label or missing values on continuation records;
  388|       |         * the spec says to parse them like any other variable record. */
  389|  5.00k|        if (variable.has_var_label) {
  ------------------
  |  Branch (389:13): [True: 911, False: 4.09k]
  ------------------
  390|    911|            spss_varinfo_t dummy = { .label = NULL };
  391|    911|            if ((retval = sav_read_variable_label(&dummy, ctx)) != READSTAT_OK)
  ------------------
  |  Branch (391:17): [True: 1, False: 910]
  ------------------
  392|      1|                return retval;
  393|    910|            if (dummy.label)
  ------------------
  |  Branch (393:17): [True: 329, False: 581]
  ------------------
  394|    329|                free(dummy.label);
  395|    910|        }
  396|  5.00k|        if (variable.n_missing_values) {
  ------------------
  |  Branch (396:13): [True: 815, False: 4.19k]
  ------------------
  397|    815|            spss_varinfo_t dummy = { .type = READSTAT_TYPE_DOUBLE };
  398|    815|            dummy.n_missing_values = ctx->bswap ? byteswap4(variable.n_missing_values) : variable.n_missing_values;
  ------------------
  |  Branch (398:38): [True: 207, False: 608]
  ------------------
  399|    815|            if ((retval = sav_read_variable_missing_values(&dummy, ctx)) != READSTAT_OK)
  ------------------
  |  Branch (399:17): [True: 3, False: 812]
  ------------------
  400|      3|                return retval;
  401|    815|        }
  402|  5.00k|        ctx->var_offset++;
  403|  5.00k|        ctx->varinfo[ctx->var_index-1]->width++;
  404|  5.00k|        return retval;
  405|  5.00k|    }
  406|       |
  407|   440k|    sav_synthesize_missing_continuations(ctx);
  408|       |
  409|   440k|    if ((info = readstat_calloc(1, sizeof(spss_varinfo_t))) == NULL) {
  ------------------
  |  Branch (409:9): [True: 0, False: 440k]
  ------------------
  410|      0|        retval = READSTAT_ERROR_MALLOC;
  411|      0|        goto cleanup;
  412|      0|    }
  413|   440k|    info->width = 1;
  414|   440k|    info->n_segments = 1;
  415|   440k|    info->index = ctx->var_index;
  416|   440k|    info->offset = ctx->var_offset;
  417|   440k|    info->labels_index = -1;
  418|       |
  419|   440k|    retval = readstat_convert(info->name, sizeof(info->name),
  420|   440k|            variable.name, sizeof(variable.name), NULL);
  421|   440k|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (421:9): [True: 0, False: 440k]
  ------------------
  422|      0|        goto cleanup;
  423|       |
  424|   440k|    retval = readstat_convert(info->longname, sizeof(info->longname), 
  425|   440k|            variable.name, sizeof(variable.name), NULL);
  426|   440k|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (426:9): [True: 0, False: 440k]
  ------------------
  427|      0|        goto cleanup;
  428|       |
  429|   440k|    info->print_format.decimal_places = (variable.print & 0x000000FF);
  430|   440k|    info->print_format.width = (variable.print & 0x0000FF00) >> 8;
  431|   440k|    info->print_format.type = (variable.print  & 0x00FF0000) >> 16;
  432|       |
  433|   440k|    info->write_format.decimal_places = (variable.write & 0x000000FF);
  434|   440k|    info->write_format.width = (variable.write & 0x0000FF00) >> 8;
  435|   440k|    info->write_format.type = (variable.write  & 0x00FF0000) >> 16;
  436|       |
  437|   440k|    if (type > 0 || info->print_format.type == SPSS_FORMAT_TYPE_A || info->write_format.type == SPSS_FORMAT_TYPE_A) {
  ------------------
  |  |    2|   749k|#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|   189k|#define SPSS_FORMAT_TYPE_A        1
  ------------------
  |  Branch (437:9): [True: 131k, False: 309k]
  |  Branch (437:21): [True: 119k, False: 189k]
  |  Branch (437:70): [True: 102k, False: 87.3k]
  ------------------
  438|   353k|        info->type = READSTAT_TYPE_STRING;
  439|   353k|        info->string_length = type; /* may be raised by the very long string record */
  440|   353k|    } else {
  441|  87.3k|        info->type = READSTAT_TYPE_DOUBLE;
  442|  87.3k|    }
  443|       |    
  444|   440k|    if (variable.has_var_label) {
  ------------------
  |  Branch (444:9): [True: 17.2k, False: 423k]
  ------------------
  445|  17.2k|        if ((retval = sav_read_variable_label(info, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (445:13): [True: 1, False: 17.2k]
  ------------------
  446|      1|            goto cleanup;
  447|      1|        }
  448|  17.2k|    }
  449|       |    
  450|   440k|    if (variable.n_missing_values) {
  ------------------
  |  Branch (450:9): [True: 19.0k, False: 421k]
  ------------------
  451|  19.0k|        info->n_missing_values = ctx->bswap ? byteswap4(variable.n_missing_values) : variable.n_missing_values;
  ------------------
  |  Branch (451:34): [True: 2.18k, False: 16.9k]
  ------------------
  452|  19.0k|        if ((retval = sav_read_variable_missing_values(info, ctx)) != READSTAT_OK) {
  ------------------
  |  Branch (452:13): [True: 3, False: 19.0k]
  ------------------
  453|      3|            goto cleanup;
  454|      3|        }
  455|  19.0k|    }
  456|       |    
  457|   440k|    ctx->varinfo[ctx->var_index] = info;
  458|       |
  459|   440k|    ctx->var_index++;
  460|   440k|    ctx->var_offset++;
  461|       |    
  462|   440k|cleanup:
  463|   440k|    if (retval != READSTAT_OK) {
  ------------------
  |  Branch (463:9): [True: 4, False: 440k]
  ------------------
  464|      4|        spss_varinfo_free(info);
  465|      4|    }
  466|       |
  467|   440k|    return retval;
  468|   440k|}
readstat_sav_read.c:sav_read_variable_label:
  226|  18.1k|static readstat_error_t sav_read_variable_label(spss_varinfo_t *info, sav_ctx_t *ctx) {
  227|  18.1k|    readstat_io_t *io = ctx->io;
  228|  18.1k|    readstat_error_t retval = READSTAT_OK;
  229|  18.1k|    uint32_t label_len;
  230|  18.1k|    size_t label_capacity;
  231|  18.1k|    size_t out_label_len;
  232|  18.1k|    char *label_buf = NULL;
  233|  18.1k|    if (io->read(&label_len, sizeof(uint32_t), io->io_ctx) < sizeof(uint32_t)) {
  ------------------
  |  Branch (233:9): [True: 0, False: 18.1k]
  ------------------
  234|      0|        retval = READSTAT_ERROR_READ;
  235|      0|        goto cleanup;
  236|      0|    }
  237|  18.1k|    label_len = ctx->bswap ? byteswap4(label_len) : label_len;
  ------------------
  |  Branch (237:17): [True: 770, False: 17.3k]
  ------------------
  238|       |
  239|  18.1k|    if (label_len == 0)
  ------------------
  |  Branch (239:9): [True: 11.0k, False: 7.05k]
  ------------------
  240|  11.0k|        goto cleanup;
  241|       |
  242|  7.05k|    label_capacity = ((size_t)label_len + 3) / 4 * 4;
  243|  7.05k|    if ((label_buf = readstat_malloc(label_capacity)) == NULL) {
  ------------------
  |  Branch (243:9): [True: 0, False: 7.05k]
  ------------------
  244|      0|        retval = READSTAT_ERROR_MALLOC;
  245|      0|        goto cleanup;
  246|      0|    }
  247|       |
  248|  7.05k|    out_label_len = (size_t)label_len*4+1;
  249|  7.05k|    if ((info->label = readstat_malloc(out_label_len)) == NULL) {
  ------------------
  |  Branch (249:9): [True: 0, False: 7.05k]
  ------------------
  250|      0|        retval = READSTAT_ERROR_MALLOC;
  251|      0|        goto cleanup;
  252|      0|    }
  253|       |
  254|  7.05k|    if (io->read(label_buf, label_capacity, io->io_ctx) < label_capacity) {
  ------------------
  |  Branch (254:9): [True: 0, False: 7.05k]
  ------------------
  255|      0|        retval = READSTAT_ERROR_READ;
  256|      0|        goto cleanup;
  257|      0|    }
  258|       |
  259|  7.05k|    retval = readstat_convert(info->label, out_label_len, label_buf, label_len, ctx->converter);
  260|  7.05k|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (260:9): [True: 2, False: 7.05k]
  ------------------
  261|      2|        goto cleanup;
  262|       |
  263|  18.1k|cleanup:
  264|  18.1k|    if (label_buf)
  ------------------
  |  Branch (264:9): [True: 7.05k, False: 11.0k]
  ------------------
  265|  7.05k|        free(label_buf);
  266|       |
  267|  18.1k|    if (retval != READSTAT_OK) {
  ------------------
  |  Branch (267:9): [True: 2, False: 18.1k]
  ------------------
  268|      2|        if (info->label) {
  ------------------
  |  Branch (268:13): [True: 2, False: 0]
  ------------------
  269|      2|            free(info->label);
  270|      2|            info->label = NULL;
  271|      2|        }
  272|      2|    }
  273|       |
  274|  18.1k|    return retval;
  275|  7.05k|}
readstat_sav_read.c:sav_read_variable_missing_values:
  332|  19.9k|static readstat_error_t sav_read_variable_missing_values(spss_varinfo_t *info, sav_ctx_t *ctx) {
  333|  19.9k|    if (info->n_missing_values > 3 || info->n_missing_values < -3 || info->n_missing_values == -1) {
  ------------------
  |  Branch (333:9): [True: 0, False: 19.9k]
  |  Branch (333:39): [True: 0, False: 19.9k]
  |  Branch (333:70): [True: 5, False: 19.9k]
  ------------------
  334|      5|        return READSTAT_ERROR_PARSE;
  335|      5|    }
  336|  19.9k|    if (info->n_missing_values < 0) {
  ------------------
  |  Branch (336:9): [True: 7.35k, False: 12.5k]
  ------------------
  337|  7.35k|        info->missing_range = 1;
  338|  7.35k|        info->n_missing_values = abs(info->n_missing_values);
  339|  12.5k|    } else {
  340|  12.5k|        info->missing_range = 0;
  341|  12.5k|    }
  342|  19.9k|    if (info->type == READSTAT_TYPE_DOUBLE) {
  ------------------
  |  Branch (342:9): [True: 17.2k, False: 2.64k]
  ------------------
  343|  17.2k|        return sav_read_variable_missing_double_values(info, ctx);
  344|  17.2k|    }
  345|  2.64k|    return sav_read_variable_missing_string_values(info, ctx);
  346|  19.9k|}
readstat_sav_read.c:sav_read_variable_missing_double_values:
  277|  17.2k|static readstat_error_t sav_read_variable_missing_double_values(spss_varinfo_t *info, sav_ctx_t *ctx) {
  278|  17.2k|    readstat_io_t *io = ctx->io;
  279|  17.2k|    int i;
  280|  17.2k|    readstat_error_t retval = READSTAT_OK;
  281|  17.2k|    if (io->read(info->missing_double_values, info->n_missing_values * sizeof(double), io->io_ctx)
  ------------------
  |  Branch (281:9): [True: 0, False: 17.2k]
  ------------------
  282|  17.2k|            < info->n_missing_values * sizeof(double)) {
  283|      0|        retval = READSTAT_ERROR_READ;
  284|      0|        goto cleanup;
  285|      0|    }
  286|  66.6k|    for (i=0; i<info->n_missing_values; i++) {
  ------------------
  |  Branch (286:15): [True: 49.3k, False: 17.2k]
  ------------------
  287|  49.3k|        if (ctx->bswap) {
  ------------------
  |  Branch (287:13): [True: 3.60k, False: 45.7k]
  ------------------
  288|  3.60k|            info->missing_double_values[i] = byteswap_double(info->missing_double_values[i]);
  289|  3.60k|        }
  290|       |
  291|  49.3k|        uint64_t long_value = 0;
  292|  49.3k|        memcpy(&long_value, &info->missing_double_values[i], 8);
  293|       |
  294|  49.3k|        if (info->missing_range && i == 0 && long_value == ctx->missing_double) {
  ------------------
  |  Branch (294:13): [True: 19.7k, False: 29.6k]
  |  Branch (294:36): [True: 7.01k, False: 12.7k]
  |  Branch (294:46): [True: 724, False: 6.28k]
  ------------------
  295|       |            /* SPSS 21 and later write LOWEST with the same bit pattern as
  296|       |             * SYSMIS, which is unambiguous here because SYSMIS cannot be a
  297|       |             * range endpoint. */
  298|    724|            info->missing_double_values[i] = -HUGE_VAL;
  299|  48.6k|        } else if (long_value == ctx->missing_double) {
  ------------------
  |  Branch (299:20): [True: 544, False: 48.1k]
  ------------------
  300|    544|            info->missing_double_values[i] = NAN;
  301|  48.1k|        } else if (long_value == ctx->lowest_double) {
  ------------------
  |  Branch (301:20): [True: 7.04k, False: 41.0k]
  ------------------
  302|  7.04k|            info->missing_double_values[i] = -HUGE_VAL;
  303|  41.0k|        } else if (long_value == ctx->highest_double) {
  ------------------
  |  Branch (303:20): [True: 195, False: 40.8k]
  ------------------
  304|    195|            info->missing_double_values[i] = HUGE_VAL;
  305|    195|        }
  306|  49.3k|    }
  307|       |
  308|  17.2k|cleanup:
  309|  17.2k|    return retval;
  310|  17.2k|}
readstat_sav_read.c:sav_read_variable_missing_string_values:
  312|  2.64k|static readstat_error_t sav_read_variable_missing_string_values(spss_varinfo_t *info, sav_ctx_t *ctx) {
  313|  2.64k|    readstat_io_t *io = ctx->io;
  314|  2.64k|    int i;
  315|  2.64k|    readstat_error_t retval = READSTAT_OK;
  316|  9.15k|    for (i=0; i<info->n_missing_values; i++) {
  ------------------
  |  Branch (316:15): [True: 6.51k, False: 2.64k]
  ------------------
  317|  6.51k|        char missing_value[8];
  318|  6.51k|        if (io->read(missing_value, sizeof(missing_value), io->io_ctx) < sizeof(missing_value)) {
  ------------------
  |  Branch (318:13): [True: 0, False: 6.51k]
  ------------------
  319|      0|            retval = READSTAT_ERROR_READ;
  320|      0|            goto cleanup;
  321|      0|        }
  322|  6.51k|        retval = readstat_convert(info->missing_string_values[i], sizeof(info->missing_string_values[0]),
  323|  6.51k|                missing_value, sizeof(missing_value), ctx->converter);
  324|  6.51k|        if (retval != READSTAT_OK)
  ------------------
  |  Branch (324:13): [True: 1, False: 6.51k]
  ------------------
  325|      1|            goto cleanup;
  326|  6.51k|    }
  327|       |
  328|  2.64k|cleanup:
  329|  2.64k|    return retval;
  330|  2.64k|}
readstat_sav_read.c:sav_synthesize_missing_continuations:
  352|   445k|static void sav_synthesize_missing_continuations(sav_ctx_t *ctx) {
  353|   445k|    if (ctx->var_index == 0)
  ------------------
  |  Branch (353:9): [True: 4.89k, False: 440k]
  ------------------
  354|  4.89k|        return;
  355|   440k|    spss_varinfo_t *info = ctx->varinfo[ctx->var_index-1];
  356|   440k|    if (info->type == READSTAT_TYPE_STRING && info->width == 1 &&
  ------------------
  |  Branch (356:9): [True: 353k, False: 87.3k]
  |  Branch (356:47): [True: 349k, False: 3.74k]
  ------------------
  357|   349k|            info->string_length > 8 && info->string_length <= 255) {
  ------------------
  |  Branch (357:13): [True: 116k, False: 232k]
  |  Branch (357:40): [True: 46.3k, False: 70.5k]
  ------------------
  358|  46.3k|        int needed = (info->string_length + 7) / 8;
  359|  46.3k|        ctx->var_offset += needed - 1;
  360|  46.3k|        info->width = needed;
  361|  46.3k|    }
  362|   440k|}
readstat_sav_read.c:sav_read_value_label_record:
  547|  49.4k|static readstat_error_t sav_read_value_label_record(sav_ctx_t *ctx) {
  548|  49.4k|    uint32_t label_count;
  549|  49.4k|    readstat_error_t retval = READSTAT_OK;
  550|  49.4k|    readstat_io_t *io = ctx->io;
  551|  49.4k|    uint32_t *vars = NULL;
  552|  49.4k|    uint32_t var_count;
  553|  49.4k|    int32_t rec_type;
  554|  49.4k|    readstat_type_t value_type = READSTAT_TYPE_STRING;
  555|  49.4k|    char label_buf[256];
  556|  49.4k|    value_label_t *value_labels = NULL;
  557|       |
  558|  49.4k|    if (io->read(&label_count, sizeof(uint32_t), io->io_ctx) < sizeof(uint32_t)) {
  ------------------
  |  Branch (558:9): [True: 0, False: 49.4k]
  ------------------
  559|      0|        retval = READSTAT_ERROR_READ;
  560|      0|        goto cleanup;
  561|      0|    }
  562|  49.4k|    if (ctx->bswap)
  ------------------
  |  Branch (562:9): [True: 2.60k, False: 46.8k]
  ------------------
  563|  2.60k|        label_count = byteswap4(label_count);
  564|       |    
  565|  49.4k|    if (label_count && (value_labels = readstat_calloc(label_count, sizeof(value_label_t))) == NULL) {
  ------------------
  |  Branch (565:9): [True: 885, False: 48.5k]
  |  Branch (565:24): [True: 0, False: 885]
  ------------------
  566|      0|        retval = READSTAT_ERROR_MALLOC;
  567|      0|        goto cleanup;
  568|      0|    }
  569|       |    
  570|  49.4k|    int i;
  571|  98.1k|    for (i=0; i<label_count; i++) {
  ------------------
  |  Branch (571:15): [True: 48.7k, False: 49.4k]
  ------------------
  572|  48.7k|        value_label_t *vlabel = &value_labels[i];
  573|  48.7k|        unsigned char unpadded_label_len = 0;
  574|  48.7k|        size_t padded_label_len = 0, utf8_label_len = 0;
  575|       |
  576|  48.7k|        if (io->read(vlabel->raw_value, 8, io->io_ctx) < 8) {
  ------------------
  |  Branch (576:13): [True: 0, False: 48.7k]
  ------------------
  577|      0|            retval = READSTAT_ERROR_READ;
  578|      0|            goto cleanup;
  579|      0|        }
  580|  48.7k|        if (io->read(&unpadded_label_len, 1, io->io_ctx) < 1) {
  ------------------
  |  Branch (580:13): [True: 0, False: 48.7k]
  ------------------
  581|      0|            retval = READSTAT_ERROR_READ;
  582|      0|            goto cleanup;
  583|      0|        }
  584|       |
  585|  48.7k|        padded_label_len = (unpadded_label_len + 8) / 8 * 8 - 1;
  586|  48.7k|        if (io->read(label_buf, padded_label_len, io->io_ctx) < padded_label_len) {
  ------------------
  |  Branch (586:13): [True: 0, False: 48.7k]
  ------------------
  587|      0|            retval = READSTAT_ERROR_READ;
  588|      0|            goto cleanup;
  589|      0|        }
  590|       |
  591|  48.7k|        utf8_label_len = padded_label_len*4+1;
  592|  48.7k|        if ((vlabel->label = readstat_malloc(utf8_label_len)) == NULL) {
  ------------------
  |  Branch (592:13): [True: 0, False: 48.7k]
  ------------------
  593|      0|            retval = READSTAT_ERROR_MALLOC;
  594|      0|            goto cleanup;
  595|      0|        }
  596|       |
  597|  48.7k|        retval = readstat_convert(vlabel->label, utf8_label_len, label_buf, unpadded_label_len, ctx->converter);
  598|  48.7k|        if (retval != READSTAT_OK)
  ------------------
  |  Branch (598:13): [True: 9, False: 48.7k]
  ------------------
  599|      9|            goto cleanup;
  600|  48.7k|    }
  601|       |
  602|  49.4k|    if (io->read(&rec_type, sizeof(int32_t), io->io_ctx) < sizeof(int32_t)) {
  ------------------
  |  Branch (602:9): [True: 0, False: 49.4k]
  ------------------
  603|      0|        retval = READSTAT_ERROR_READ;
  604|      0|        goto cleanup;
  605|      0|    }
  606|  49.4k|    if (ctx->bswap)
  ------------------
  |  Branch (606:9): [True: 2.60k, False: 46.8k]
  ------------------
  607|  2.60k|        rec_type = byteswap4(rec_type);
  608|       |    
  609|  49.4k|    if (rec_type != 4) {
  ------------------
  |  Branch (609:9): [True: 0, False: 49.4k]
  ------------------
  610|      0|        retval = READSTAT_ERROR_PARSE;
  611|      0|        goto cleanup;
  612|      0|    }
  613|  49.4k|    if (io->read(&var_count, sizeof(uint32_t), io->io_ctx) < sizeof(uint32_t)) {
  ------------------
  |  Branch (613:9): [True: 0, False: 49.4k]
  ------------------
  614|      0|        retval = READSTAT_ERROR_READ;
  615|      0|        goto cleanup;
  616|      0|    }
  617|  49.4k|    if (ctx->bswap)
  ------------------
  |  Branch (617:9): [True: 2.60k, False: 46.8k]
  ------------------
  618|  2.60k|        var_count = byteswap4(var_count);
  619|       |    
  620|  49.4k|    if (var_count && (vars = readstat_malloc(var_count * sizeof(uint32_t))) == NULL) {
  ------------------
  |  Branch (620:9): [True: 20.8k, False: 28.6k]
  |  Branch (620:22): [True: 0, False: 20.8k]
  ------------------
  621|      0|        retval = READSTAT_ERROR_MALLOC;
  622|      0|        goto cleanup;
  623|      0|    }
  624|  49.4k|    if (io->read(vars, var_count * sizeof(uint32_t), io->io_ctx) < var_count * sizeof(uint32_t)) {
  ------------------
  |  Branch (624:9): [True: 0, False: 49.4k]
  ------------------
  625|      0|        retval = READSTAT_ERROR_READ;
  626|      0|        goto cleanup;
  627|      0|    }
  628|   170k|    for (i=0; i<var_count; i++) {
  ------------------
  |  Branch (628:15): [True: 120k, False: 49.4k]
  ------------------
  629|   120k|        uint32_t var_offset = vars[i];
  630|   120k|        if (ctx->bswap)
  ------------------
  |  Branch (630:13): [True: 4.07k, False: 116k]
  ------------------
  631|  4.07k|            var_offset = byteswap4(var_offset);
  632|       |
  633|   120k|        var_offset--; // Why subtract 1????
  634|   120k|        spss_varinfo_t **var = bsearch(&var_offset, ctx->varinfo, ctx->var_index, sizeof(spss_varinfo_t *),
  635|   120k|                &spss_varinfo_compare);
  636|   120k|        if (var) {
  ------------------
  |  Branch (636:13): [True: 25.1k, False: 95.7k]
  ------------------
  637|  25.1k|            (*var)->labels_index = ctx->value_labels_count;
  638|  25.1k|            value_type = (*var)->type;
  639|  25.1k|        }
  640|   120k|    }
  641|       |
  642|  98.1k|    for (i=0; i<label_count; i++) {
  ------------------
  |  Branch (642:15): [True: 48.7k, False: 49.4k]
  ------------------
  643|  48.7k|        value_label_t *vlabel = &value_labels[i];
  644|  48.7k|        double val_d = 0.0;
  645|  48.7k|        vlabel->final_value.type = value_type;
  646|  48.7k|        if (value_type == READSTAT_TYPE_DOUBLE) {
  ------------------
  |  Branch (646:13): [True: 13.7k, False: 34.9k]
  ------------------
  647|  13.7k|            memcpy(&val_d, vlabel->raw_value, 8);
  648|  13.7k|            if (ctx->bswap)
  ------------------
  |  Branch (648:17): [True: 537, False: 13.2k]
  ------------------
  649|    537|                val_d = byteswap_double(val_d);
  650|       |
  651|  13.7k|            vlabel->final_value.v.double_value = val_d;
  652|  13.7k|            sav_tag_missing_double(&vlabel->final_value, ctx);
  653|  34.9k|        } else {
  654|  34.9k|            retval = readstat_convert(vlabel->utf8_string_value, sizeof(vlabel->utf8_string_value),
  655|  34.9k|                    vlabel->raw_value, 8, ctx->converter);
  656|  34.9k|            if (retval != READSTAT_OK)
  ------------------
  |  Branch (656:17): [True: 1, False: 34.9k]
  ------------------
  657|      1|                break;
  658|       |
  659|  34.9k|            vlabel->final_value.v.string_value = vlabel->utf8_string_value;
  660|  34.9k|        }
  661|  48.7k|    }
  662|       |
  663|  49.4k|    if (ctx->handle.value_label) {
  ------------------
  |  Branch (663:9): [True: 49.4k, False: 0]
  ------------------
  664|  49.4k|        sav_submit_value_labels(value_labels, label_count, value_type, ctx);
  665|  49.4k|    }
  666|  49.4k|    ctx->value_labels_count++;
  667|  49.4k|cleanup:
  668|  49.4k|    if (vars)
  ------------------
  |  Branch (668:9): [True: 20.8k, False: 28.6k]
  ------------------
  669|  20.8k|        free(vars);
  670|  49.4k|    if (value_labels) {
  ------------------
  |  Branch (670:9): [True: 885, False: 48.5k]
  ------------------
  671|  49.8k|        for (i=0; i<label_count; i++) {
  ------------------
  |  Branch (671:19): [True: 48.9k, False: 885]
  ------------------
  672|  48.9k|            value_label_t *vlabel = &value_labels[i];
  673|  48.9k|            if (vlabel->label)
  ------------------
  |  Branch (673:17): [True: 48.7k, False: 200]
  ------------------
  674|  48.7k|                free(vlabel->label);
  675|  48.9k|        }
  676|    885|        free(value_labels);
  677|    885|    }
  678|       |    
  679|  49.4k|    return retval;
  680|  49.4k|}
readstat_sav_read.c:sav_tag_missing_double:
  171|  1.83M|static void sav_tag_missing_double(readstat_value_t *value, sav_ctx_t *ctx) {
  172|  1.83M|    double fp_value = value->v.double_value;
  173|  1.83M|    uint64_t long_value = 0;
  174|  1.83M|    memcpy(&long_value, &fp_value, 8);
  175|  1.83M|    if (long_value == ctx->missing_double)
  ------------------
  |  Branch (175:9): [True: 20.0k, False: 1.81M]
  ------------------
  176|  20.0k|        value->is_system_missing = 1;
  177|  1.83M|    if (long_value == ctx->lowest_double)
  ------------------
  |  Branch (177:9): [True: 488, False: 1.83M]
  ------------------
  178|    488|        value->is_system_missing = 1;
  179|  1.83M|    if (long_value == ctx->highest_double)
  ------------------
  |  Branch (179:9): [True: 516, False: 1.83M]
  ------------------
  180|    516|        value->is_system_missing = 1;
  181|  1.83M|    if (isnan(fp_value))
  ------------------
  |  Branch (181:9): [True: 836, False: 1.83M]
  ------------------
  182|    836|        value->is_system_missing = 1;
  183|  1.83M|}
readstat_sav_read.c:sav_submit_value_labels:
  529|  49.4k|        readstat_type_t value_type, sav_ctx_t *ctx) {
  530|  49.4k|    char label_name_buf[256];
  531|  49.4k|    readstat_error_t retval = READSTAT_OK;
  532|  49.4k|    int32_t i;
  533|       |
  534|  49.4k|    snprintf(label_name_buf, sizeof(label_name_buf), SAV_LABEL_NAME_PREFIX "%d", ctx->value_labels_count);
  ------------------
  |  |  117|  49.4k|#define SAV_LABEL_NAME_PREFIX         "labels"
  ------------------
  535|       |
  536|  98.1k|    for (i=0; i<label_count; i++) {
  ------------------
  |  Branch (536:15): [True: 48.7k, False: 49.4k]
  ------------------
  537|  48.7k|        value_label_t *vlabel = &value_labels[i];
  538|  48.7k|        if (ctx->handle.value_label(label_name_buf, vlabel->final_value, vlabel->label, ctx->user_ctx) != READSTAT_HANDLER_OK) {
  ------------------
  |  |   22|  48.7k|#define READSTAT_HANDLER_OK             0
  ------------------
  |  Branch (538:13): [True: 0, False: 48.7k]
  ------------------
  539|      0|            retval = READSTAT_ERROR_USER_ABORT;
  540|      0|            goto cleanup;
  541|      0|        }
  542|  48.7k|    }
  543|  49.4k|cleanup:
  544|  49.4k|    return retval;
  545|  49.4k|}
readstat_sav_read.c:sav_read_document_record:
  701|  1.22k|static readstat_error_t sav_read_document_record(sav_ctx_t *ctx) {
  702|  1.22k|    if (!ctx->handle.note)
  ------------------
  |  Branch (702:9): [True: 0, False: 1.22k]
  ------------------
  703|      0|        return sav_skip_document_record(ctx);
  704|       |
  705|  1.22k|    uint32_t n_lines;
  706|  1.22k|    readstat_error_t retval = READSTAT_OK;
  707|  1.22k|    readstat_io_t *io = ctx->io;
  708|  1.22k|    if (io->read(&n_lines, sizeof(uint32_t), io->io_ctx) < sizeof(uint32_t)) {
  ------------------
  |  Branch (708:9): [True: 0, False: 1.22k]
  ------------------
  709|      0|        retval = READSTAT_ERROR_READ;
  710|      0|        goto cleanup;
  711|      0|    }
  712|  1.22k|    if (ctx->bswap)
  ------------------
  |  Branch (712:9): [True: 521, False: 700]
  ------------------
  713|    521|        n_lines = byteswap4(n_lines);
  714|       |
  715|  1.22k|    char raw_buffer[SPSS_DOC_LINE_SIZE];
  716|  1.22k|    char utf8_buffer[4*SPSS_DOC_LINE_SIZE+1];
  717|  1.22k|    int i;
  718|  2.30k|    for (i=0; i<n_lines; i++) {
  ------------------
  |  Branch (718:15): [True: 1.08k, False: 1.22k]
  ------------------
  719|  1.08k|        if (io->read(raw_buffer, SPSS_DOC_LINE_SIZE, io->io_ctx) < SPSS_DOC_LINE_SIZE) {
  ------------------
  |  |   40|  1.08k|#define SPSS_DOC_LINE_SIZE  80
  ------------------
                      if (io->read(raw_buffer, SPSS_DOC_LINE_SIZE, io->io_ctx) < SPSS_DOC_LINE_SIZE) {
  ------------------
  |  |   40|  1.08k|#define SPSS_DOC_LINE_SIZE  80
  ------------------
  |  Branch (719:13): [True: 0, False: 1.08k]
  ------------------
  720|      0|            retval = READSTAT_ERROR_READ;
  721|      0|            goto cleanup;
  722|      0|        }
  723|       |
  724|  1.08k|        retval = readstat_convert(utf8_buffer, sizeof(utf8_buffer),
  725|  1.08k|                raw_buffer, sizeof(raw_buffer), ctx->converter);
  726|  1.08k|        if (retval != READSTAT_OK)
  ------------------
  |  Branch (726:13): [True: 1, False: 1.07k]
  ------------------
  727|      1|            goto cleanup;
  728|       |
  729|  1.07k|        if (ctx->handle.note(i, utf8_buffer, ctx->user_ctx) != READSTAT_HANDLER_OK) {
  ------------------
  |  |   22|  1.07k|#define READSTAT_HANDLER_OK             0
  ------------------
  |  Branch (729:13): [True: 0, False: 1.07k]
  ------------------
  730|      0|            retval = READSTAT_ERROR_USER_ABORT;
  731|      0|            goto cleanup;
  732|      0|        }
  733|  1.07k|    }
  734|       |
  735|  1.22k|cleanup:
  736|  1.22k|    return retval;
  737|  1.22k|}
readstat_sav_read.c:sav_read_dictionary_termination_record:
  739|  4.43k|static readstat_error_t sav_read_dictionary_termination_record(sav_ctx_t *ctx) {
  740|  4.43k|    int32_t filler;
  741|  4.43k|    readstat_error_t retval = READSTAT_OK;
  742|  4.43k|    readstat_io_t *io = ctx->io;
  743|  4.43k|    sav_synthesize_missing_continuations(ctx);
  744|  4.43k|    if (io->read(&filler, sizeof(int32_t), io->io_ctx) < sizeof(int32_t)) {
  ------------------
  |  Branch (744:9): [True: 2.45k, False: 1.97k]
  ------------------
  745|  2.45k|        retval = READSTAT_ERROR_READ;
  746|  2.45k|    }
  747|  4.43k|    return retval;
  748|  4.43k|}
readstat_sav_read.c:sav_read_multiple_response_sets:
  160|  28.6k|static readstat_error_t sav_read_multiple_response_sets(const void *data, size_t data_len, sav_ctx_t *ctx) {
  161|  28.6k|    readstat_error_t retval = parse_mr_string(data, data_len,
  162|  28.6k|            &ctx->mr_sets, &ctx->multiple_response_sets_length, ctx);
  163|  28.6k|    if (retval == READSTAT_ERROR_MALLOC || retval == READSTAT_ERROR_USER_ABORT)
  ------------------
  |  Branch (163:9): [True: 0, False: 28.6k]
  |  Branch (163:44): [True: 0, False: 28.6k]
  ------------------
  164|      0|        return retval;
  165|  28.6k|    if (retval != READSTAT_OK) {
  ------------------
  |  Branch (165:9): [True: 24.6k, False: 4.07k]
  ------------------
  166|  24.6k|        sav_report_error(ctx, "Ignoring malformed multiple response set record");
  167|  24.6k|    }
  168|  28.6k|    return READSTAT_OK;
  169|  28.6k|}
readstat_sav_read.c:sav_store_variable_display_parameter_record:
 1112|    688|static readstat_error_t sav_store_variable_display_parameter_record(const void *data, size_t size, size_t count, sav_ctx_t *ctx) {
 1113|    688|    if (size != 4)
  ------------------
  |  Branch (1113:9): [True: 205, False: 483]
  ------------------
 1114|    205|        return READSTAT_OK; /* malformed; ignore the record like PSPP does */
 1115|       |
 1116|    483|    const uint32_t *data_ptr = data;
 1117|    483|    int i;
 1118|       |
 1119|    483|    ctx->variable_display_values = readstat_realloc(ctx->variable_display_values, count * sizeof(uint32_t));
 1120|    483|    if (count > 0 && ctx->variable_display_values == NULL)
  ------------------
  |  Branch (1120:9): [True: 483, False: 0]
  |  Branch (1120:22): [True: 0, False: 483]
  ------------------
 1121|      0|        return READSTAT_ERROR_MALLOC;
 1122|       |
 1123|    483|    ctx->variable_display_values_count = count;
 1124|  93.7k|    for (i=0; i<count; i++) {
  ------------------
  |  Branch (1124:15): [True: 93.2k, False: 483]
  ------------------
 1125|  93.2k|        ctx->variable_display_values[i] = ctx->bswap ? byteswap4(data_ptr[i]) : data_ptr[i];
  ------------------
  |  Branch (1125:43): [True: 1.83k, False: 91.4k]
  ------------------
 1126|  93.2k|    }
 1127|    483|    return READSTAT_OK;
 1128|    483|}
readstat_sav_read.c:sav_parse_long_string_value_labels_record:
 1191|    867|static readstat_error_t sav_parse_long_string_value_labels_record(const void *data, size_t size, size_t count, sav_ctx_t *ctx) {
 1192|    867|    if (!ctx->handle.value_label)
  ------------------
  |  Branch (1192:9): [True: 0, False: 867]
  ------------------
 1193|      0|        return READSTAT_OK;
 1194|    867|    if (size != 1)
  ------------------
  |  Branch (1194:9): [True: 4, False: 863]
  ------------------
 1195|      4|        return READSTAT_ERROR_PARSE;
 1196|       |
 1197|    863|    readstat_error_t retval = READSTAT_OK;
 1198|    863|    uint32_t label_count = 0;
 1199|    863|    uint32_t i = 0;
 1200|    863|    const char *data_ptr = data;
 1201|    863|    const char *data_end = data_ptr + count;
 1202|    863|    char var_name_buf[256+1]; // unconverted
 1203|    863|    char label_name_buf[256];
 1204|    863|    char *value_buffer = NULL;
 1205|    863|    char *label_buffer = NULL;
 1206|       |    
 1207|  3.91k|    while (data_ptr < data_end) {
  ------------------
  |  Branch (1207:12): [True: 3.38k, False: 536]
  ------------------
 1208|  3.38k|        memset(label_name_buf, '\0', sizeof(label_name_buf));
 1209|       |
 1210|  3.38k|        retval = sav_read_pascal_string(var_name_buf, sizeof(var_name_buf),
 1211|  3.38k|                &data_ptr, data_end - data_ptr, ctx);
 1212|  3.38k|        if (retval != READSTAT_OK)
  ------------------
  |  Branch (1212:13): [True: 84, False: 3.29k]
  ------------------
 1213|     84|            goto cleanup;
 1214|       |
 1215|  2.75M|        for (i=0; i<ctx->var_index;) {
  ------------------
  |  Branch (1215:19): [True: 2.75M, False: 2.87k]
  ------------------
 1216|  2.75M|            spss_varinfo_t *info = ctx->varinfo[i];
 1217|  2.75M|            if (strcmp(var_name_buf, info->longname) == 0) {
  ------------------
  |  Branch (1217:17): [True: 426, False: 2.75M]
  ------------------
 1218|    426|                info->labels_index = ctx->value_labels_count++;
 1219|    426|                snprintf(label_name_buf, sizeof(label_name_buf),
 1220|    426|                        SAV_LABEL_NAME_PREFIX "%d", info->labels_index);
  ------------------
  |  |  117|    426|#define SAV_LABEL_NAME_PREFIX         "labels"
  ------------------
 1221|    426|                break;
 1222|    426|            }
 1223|  2.75M|            i += info->n_segments;
 1224|  2.75M|        }
 1225|       |
 1226|  3.29k|        if (label_name_buf[0] == '\0') {
  ------------------
  |  Branch (1226:13): [True: 2.87k, False: 426]
  ------------------
 1227|  2.87k|            sav_report_error(ctx, "Ignoring long string value labels for unknown variable");
 1228|  2.87k|        }
 1229|       |
 1230|  3.29k|        data_ptr += sizeof(uint32_t);
 1231|       |
 1232|  3.29k|        if (data_ptr + sizeof(uint32_t) > data_end) {
  ------------------
  |  Branch (1232:13): [True: 111, False: 3.18k]
  ------------------
 1233|    111|            retval = READSTAT_ERROR_PARSE;
 1234|    111|            goto cleanup;
 1235|    111|        }
 1236|       |
 1237|  3.18k|        memcpy(&label_count, data_ptr, sizeof(uint32_t));
 1238|  3.18k|        if (ctx->bswap)
  ------------------
  |  Branch (1238:13): [True: 707, False: 2.48k]
  ------------------
 1239|    707|            label_count = byteswap4(label_count);
 1240|       |
 1241|  3.18k|        data_ptr += sizeof(uint32_t);
 1242|       |
 1243|  6.49k|        for (i=0; i<label_count; i++) {
  ------------------
  |  Branch (1243:19): [True: 3.43k, False: 3.05k]
  ------------------
 1244|  3.43k|            uint32_t value_len = 0, label_len = 0;
 1245|  3.43k|            size_t value_buffer_len = 0, label_buffer_len = 0;
 1246|       |
 1247|  3.43k|            if (data_ptr + sizeof(uint32_t) > data_end) {
  ------------------
  |  Branch (1247:17): [True: 61, False: 3.37k]
  ------------------
 1248|     61|                retval = READSTAT_ERROR_PARSE;
 1249|     61|                goto cleanup;
 1250|     61|            }
 1251|       |
 1252|  3.37k|            memcpy(&value_len, data_ptr, sizeof(uint32_t));
 1253|  3.37k|            if (ctx->bswap)
  ------------------
  |  Branch (1253:17): [True: 542, False: 2.83k]
  ------------------
 1254|    542|                value_len = byteswap4(value_len);
 1255|       |
 1256|  3.37k|            data_ptr += sizeof(uint32_t);
 1257|       |
 1258|  3.37k|            value_buffer_len = (size_t)value_len*4+1;
 1259|  3.37k|            value_buffer = readstat_realloc(value_buffer, value_buffer_len);
 1260|  3.37k|            if (value_buffer == NULL) {
  ------------------
  |  Branch (1260:17): [True: 28, False: 3.34k]
  ------------------
 1261|     28|                retval = READSTAT_ERROR_MALLOC;
 1262|     28|                goto cleanup;
 1263|     28|            }
 1264|       |
 1265|  3.34k|            if (data_ptr + value_len > data_end) {
  ------------------
  |  Branch (1265:17): [True: 26, False: 3.32k]
  ------------------
 1266|     26|                retval = READSTAT_ERROR_PARSE;
 1267|     26|                goto cleanup;
 1268|     26|            }
 1269|       |
 1270|  3.32k|            retval = readstat_convert(value_buffer, value_buffer_len, data_ptr, value_len, ctx->converter);
 1271|  3.32k|            if (retval != READSTAT_OK)
  ------------------
  |  Branch (1271:17): [True: 1, False: 3.32k]
  ------------------
 1272|      1|                goto cleanup;
 1273|       |
 1274|  3.32k|            data_ptr += value_len;
 1275|       |
 1276|  3.32k|            if (data_ptr + sizeof(uint32_t) > data_end) {
  ------------------
  |  Branch (1276:17): [True: 6, False: 3.31k]
  ------------------
 1277|      6|                retval = READSTAT_ERROR_PARSE;
 1278|      6|                goto cleanup;
 1279|      6|            }
 1280|       |
 1281|  3.31k|            memcpy(&label_len, data_ptr, sizeof(uint32_t));
 1282|  3.31k|            if (ctx->bswap)
  ------------------
  |  Branch (1282:17): [True: 525, False: 2.79k]
  ------------------
 1283|    525|                label_len = byteswap4(label_len);
 1284|       |
 1285|  3.31k|            data_ptr += sizeof(uint32_t);
 1286|       |
 1287|  3.31k|            label_buffer_len = (size_t)label_len*4+1;
 1288|  3.31k|            label_buffer = readstat_realloc(label_buffer, label_buffer_len);
 1289|  3.31k|            if (label_buffer == NULL) {
  ------------------
  |  Branch (1289:17): [True: 3, False: 3.31k]
  ------------------
 1290|      3|                retval = READSTAT_ERROR_MALLOC;
 1291|      3|                goto cleanup;
 1292|      3|            }
 1293|       |
 1294|  3.31k|            if (data_ptr + label_len > data_end) {
  ------------------
  |  Branch (1294:17): [True: 6, False: 3.30k]
  ------------------
 1295|      6|                retval = READSTAT_ERROR_PARSE;
 1296|      6|                goto cleanup;
 1297|      6|            }
 1298|       |
 1299|  3.30k|            retval = readstat_convert(label_buffer, label_buffer_len, data_ptr, label_len, ctx->converter);
 1300|  3.30k|            if (retval != READSTAT_OK)
  ------------------
  |  Branch (1300:17): [True: 1, False: 3.30k]
  ------------------
 1301|      1|                goto cleanup;
 1302|       |
 1303|  3.30k|            data_ptr += label_len;
 1304|       |
 1305|  3.30k|            readstat_value_t value = { .type = READSTAT_TYPE_STRING };
 1306|  3.30k|            value.v.string_value = value_buffer;
 1307|       |
 1308|  3.30k|            if (label_name_buf[0] == '\0')
  ------------------
  |  Branch (1308:17): [True: 2.97k, False: 330]
  ------------------
 1309|  2.97k|                continue;
 1310|       |
 1311|    330|            if (ctx->handle.value_label(label_name_buf, value, label_buffer, ctx->user_ctx) != READSTAT_HANDLER_OK) {
  ------------------
  |  |   22|    330|#define READSTAT_HANDLER_OK             0
  ------------------
  |  Branch (1311:17): [True: 0, False: 330]
  ------------------
 1312|      0|                retval = READSTAT_ERROR_USER_ABORT;
 1313|      0|                goto cleanup;
 1314|      0|            }
 1315|    330|        }
 1316|  3.18k|    }
 1317|       |
 1318|    536|    if (data_ptr != data_end) {
  ------------------
  |  Branch (1318:9): [True: 0, False: 536]
  ------------------
 1319|      0|        retval = READSTAT_ERROR_PARSE;
 1320|      0|    }
 1321|       |
 1322|    863|cleanup:
 1323|    863|    if (value_buffer)
  ------------------
  |  Branch (1323:9): [True: 382, False: 481]
  ------------------
 1324|    382|        free(value_buffer);
 1325|    863|    if (label_buffer)
  ------------------
  |  Branch (1325:9): [True: 366, False: 497]
  ------------------
 1326|    366|        free(label_buffer);
 1327|    863|    return retval;
 1328|    536|}
readstat_sav_read.c:sav_read_pascal_string:
 1157|  5.10k|        const char **inout_data_ptr, size_t data_ptr_len, sav_ctx_t *ctx) {
 1158|  5.10k|    const char *data_ptr = *inout_data_ptr;
 1159|  5.10k|    const char *data_end = data_ptr + data_ptr_len;
 1160|  5.10k|    readstat_error_t retval = READSTAT_OK;
 1161|  5.10k|    uint32_t var_name_len = 0;
 1162|       |
 1163|  5.10k|    if (data_ptr + sizeof(uint32_t) > data_end) {
  ------------------
  |  Branch (1163:9): [True: 26, False: 5.08k]
  ------------------
 1164|     26|        retval = READSTAT_ERROR_PARSE;
 1165|     26|        goto cleanup;
 1166|     26|    }
 1167|       |
 1168|  5.08k|    memcpy(&var_name_len, data_ptr, sizeof(uint32_t));
 1169|  5.08k|    if (ctx->bswap)
  ------------------
  |  Branch (1169:9): [True: 1.95k, False: 3.12k]
  ------------------
 1170|  1.95k|        var_name_len = byteswap4(var_name_len);
 1171|       |
 1172|  5.08k|    data_ptr += sizeof(uint32_t);
 1173|       |
 1174|  5.08k|    if (data_ptr + var_name_len > data_end) {
  ------------------
  |  Branch (1174:9): [True: 123, False: 4.95k]
  ------------------
 1175|    123|        retval = READSTAT_ERROR_PARSE;
 1176|    123|        goto cleanup;
 1177|    123|    }
 1178|       |
 1179|  4.95k|    retval = readstat_convert(buf, buf_len, data_ptr, var_name_len, NULL);
 1180|  4.95k|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (1180:9): [True: 11, False: 4.94k]
  ------------------
 1181|     11|        goto cleanup;
 1182|       |
 1183|  4.94k|    data_ptr += var_name_len;
 1184|       |
 1185|  5.10k|cleanup:
 1186|  5.10k|    *inout_data_ptr = data_ptr;
 1187|       |
 1188|  5.10k|    return retval;
 1189|  4.94k|}
readstat_sav_read.c:sav_parse_long_string_missing_values_record:
 1330|    943|static readstat_error_t sav_parse_long_string_missing_values_record(const void *data, size_t size, size_t count, sav_ctx_t *ctx) {
 1331|    943|    if (size != 1)
  ------------------
  |  Branch (1331:9): [True: 8, False: 935]
  ------------------
 1332|      8|        return READSTAT_ERROR_PARSE;
 1333|       |
 1334|    935|    readstat_error_t retval = READSTAT_OK;
 1335|    935|    uint32_t i = 0, j = 0;
 1336|    935|    const char *data_ptr = data;
 1337|    935|    const char *data_end = data_ptr + count;
 1338|    935|    char var_name_buf[256+1];
 1339|       |
 1340|  2.34k|    while (data_ptr < data_end) {
  ------------------
  |  Branch (1340:12): [True: 1.72k, False: 623]
  ------------------
 1341|  1.72k|        retval = sav_read_pascal_string(var_name_buf, sizeof(var_name_buf),
 1342|  1.72k|                &data_ptr, data_end - data_ptr, ctx);
 1343|  1.72k|        if (retval != READSTAT_OK)
  ------------------
  |  Branch (1343:13): [True: 76, False: 1.64k]
  ------------------
 1344|     76|            goto cleanup;
 1345|       |
 1346|  1.64k|        if (data_ptr == data_end) {
  ------------------
  |  Branch (1346:13): [True: 9, False: 1.63k]
  ------------------
 1347|      9|            retval = READSTAT_ERROR_PARSE;
 1348|      9|            goto cleanup;
 1349|      9|        }
 1350|       |
 1351|  1.63k|        char n_missing_values = *data_ptr++;
 1352|  1.63k|        if (n_missing_values < 1 || n_missing_values > 3) {
  ------------------
  |  Branch (1352:13): [True: 9, False: 1.63k]
  |  Branch (1352:37): [True: 6, False: 1.62k]
  ------------------
 1353|     15|            retval = READSTAT_ERROR_PARSE;
 1354|     15|            goto cleanup;
 1355|     15|        }
 1356|       |
 1357|  1.62k|        spss_varinfo_t *info = NULL;
 1358|  3.07k|        for (i=0; i<ctx->var_index;) {
  ------------------
  |  Branch (1358:19): [True: 1.97k, False: 1.09k]
  ------------------
 1359|  1.97k|            if (strcmp(var_name_buf, ctx->varinfo[i]->longname) == 0) {
  ------------------
  |  Branch (1359:17): [True: 531, False: 1.44k]
  ------------------
 1360|    531|                info = ctx->varinfo[i];
 1361|    531|                break;
 1362|    531|            }
 1363|  1.44k|            i += ctx->varinfo[i]->n_segments;
 1364|  1.44k|        }
 1365|  1.62k|        if (info == NULL || info->type != READSTAT_TYPE_STRING) {
  ------------------
  |  Branch (1365:13): [True: 1.09k, False: 531]
  |  Branch (1365:29): [True: 198, False: 333]
  ------------------
 1366|  1.29k|            sav_report_error(ctx, "Ignoring long string missing values for unknown or numeric variable");
 1367|  1.29k|            info = NULL;
 1368|  1.29k|        }
 1369|       |
 1370|  1.62k|        uint32_t value_len = 0;
 1371|       |
 1372|  1.62k|        if (data_ptr + sizeof(uint32_t) > data_end) {
  ------------------
  |  Branch (1372:13): [True: 99, False: 1.52k]
  ------------------
 1373|     99|            retval = READSTAT_ERROR_PARSE;
 1374|     99|            goto cleanup;
 1375|     99|        }
 1376|       |
 1377|  1.52k|        memcpy(&value_len, data_ptr, sizeof(uint32_t));
 1378|  1.52k|        if (ctx->bswap)
  ------------------
  |  Branch (1378:13): [True: 1.06k, False: 458]
  ------------------
 1379|  1.06k|            value_len = byteswap4(value_len);
 1380|       |
 1381|  1.52k|        data_ptr += sizeof(uint32_t);
 1382|       |
 1383|  5.19k|        for (j=0; j<n_missing_values; j++) {
  ------------------
  |  Branch (1383:19): [True: 3.78k, False: 1.41k]
  ------------------
 1384|       |            /* Old versions of PSPP repeated the value length (always 8)
 1385|       |             * before each value; tolerate that as PSPP itself does. */
 1386|  3.78k|            if (value_len == 8 && data_ptr + sizeof(uint32_t) <= data_end) {
  ------------------
  |  Branch (1386:17): [True: 295, False: 3.48k]
  |  Branch (1386:35): [True: 292, False: 3]
  ------------------
 1387|    292|                uint32_t repeated_len = 0;
 1388|    292|                memcpy(&repeated_len, data_ptr, sizeof(uint32_t));
 1389|    292|                if (ctx->bswap)
  ------------------
  |  Branch (1389:21): [True: 201, False: 91]
  ------------------
 1390|    201|                    repeated_len = byteswap4(repeated_len);
 1391|    292|                if (repeated_len == 8)
  ------------------
  |  Branch (1391:21): [True: 54, False: 238]
  ------------------
 1392|     54|                    data_ptr += sizeof(uint32_t);
 1393|    292|            }
 1394|  3.78k|            if (data_ptr + value_len > data_end) {
  ------------------
  |  Branch (1394:17): [True: 103, False: 3.67k]
  ------------------
 1395|    103|                retval = READSTAT_ERROR_PARSE;
 1396|    103|                goto cleanup;
 1397|    103|            }
 1398|       |
 1399|  3.67k|            if (info) {
  ------------------
  |  Branch (1399:17): [True: 859, False: 2.81k]
  ------------------
 1400|    859|                retval = readstat_convert(info->missing_string_values[j],
 1401|    859|                        sizeof(info->missing_string_values[0]),
 1402|    859|                        data_ptr, value_len, ctx->converter);
 1403|    859|                if (retval != READSTAT_OK)
  ------------------
  |  Branch (1403:21): [True: 10, False: 849]
  ------------------
 1404|     10|                    goto cleanup;
 1405|    859|            }
 1406|       |
 1407|  3.66k|            data_ptr += value_len;
 1408|  3.66k|        }
 1409|  1.41k|        if (info) {
  ------------------
  |  Branch (1409:13): [True: 311, False: 1.10k]
  ------------------
 1410|    311|            info->n_missing_values = n_missing_values;
 1411|    311|            info->missing_range = 0;
 1412|    311|        }
 1413|  1.41k|    }
 1414|       |
 1415|    623|    if (data_ptr != data_end) {
  ------------------
  |  Branch (1415:9): [True: 0, False: 623]
  ------------------
 1416|      0|        retval = READSTAT_ERROR_PARSE;
 1417|      0|    }
 1418|       |
 1419|    935|cleanup:
 1420|    935|    return retval;
 1421|    623|}
readstat_sav_read.c:sav_set_n_segments_and_var_count:
 1648|  1.97k|static readstat_error_t sav_set_n_segments_and_var_count(sav_ctx_t *ctx) {
 1649|  1.97k|    int i;
 1650|  1.97k|    ctx->var_count = 0;
 1651|  30.1k|    for (i=0; i<ctx->var_index;) {
  ------------------
  |  Branch (1651:15): [True: 28.2k, False: 1.94k]
  ------------------
 1652|  28.2k|        spss_varinfo_t *info = ctx->varinfo[i];
 1653|  28.2k|        if (info->string_length > VERY_LONG_STRING_MAX_LENGTH)
  ------------------
  |  |   30|  28.2k|#define VERY_LONG_STRING_MAX_LENGTH INT_MAX
  ------------------
  |  Branch (1653:13): [True: 31, False: 28.2k]
  ------------------
 1654|     31|            return READSTAT_ERROR_PARSE;
 1655|  28.2k|        if (info->string_length > 255) {
  ------------------
  |  Branch (1655:13): [True: 3.72k, False: 24.4k]
  ------------------
 1656|  3.72k|            info->n_segments = (info->string_length + 251) / 252;
 1657|  3.72k|        }
 1658|  28.2k|        info->index = ctx->var_count++;
 1659|  28.2k|        i += info->n_segments;
 1660|  28.2k|    }
 1661|  1.94k|    ctx->variables = readstat_calloc(ctx->var_count, sizeof(readstat_variable_t *));
 1662|  1.94k|    return READSTAT_OK;
 1663|  1.97k|}
readstat_sav_read.c:sav_parse_variable_display_parameter_record:
 1130|  1.88k|static readstat_error_t sav_parse_variable_display_parameter_record(sav_ctx_t *ctx) {
 1131|  1.88k|    if (!ctx->variable_display_values)
  ------------------
  |  Branch (1131:9): [True: 1.68k, False: 197]
  ------------------
 1132|  1.68k|        return READSTAT_OK;
 1133|       |
 1134|    197|    int i;
 1135|    197|    long count = ctx->variable_display_values_count;
 1136|    197|    if (count != 2 * ctx->var_index && count != 3 * ctx->var_index) {
  ------------------
  |  Branch (1136:9): [True: 87, False: 110]
  |  Branch (1136:40): [True: 43, False: 44]
  ------------------
 1137|     43|        sav_report_error(ctx, "Ignoring variable display record with unexpected length");
 1138|     43|        return READSTAT_OK;
 1139|     43|    }
 1140|    154|    int has_display_width = ctx->var_index > 0 && (count / ctx->var_index == 3);
  ------------------
  |  Branch (1140:29): [True: 154, False: 0]
  |  Branch (1140:51): [True: 44, False: 110]
  ------------------
 1141|    154|    int offset = 0;
 1142|    956|    for (i=0; i<ctx->var_index;) {
  ------------------
  |  Branch (1142:15): [True: 802, False: 154]
  ------------------
 1143|    802|        spss_varinfo_t *info = ctx->varinfo[i];
 1144|    802|        offset = (2 + has_display_width)*i;
 1145|    802|        info->measure = spss_measure_to_readstat_measure(ctx->variable_display_values[offset++]);
 1146|    802|        if (has_display_width) {
  ------------------
  |  Branch (1146:13): [True: 184, False: 618]
  ------------------
 1147|    184|            info->display_width = ctx->variable_display_values[offset++];
 1148|    184|        }
 1149|    802|        info->alignment = spss_alignment_to_readstat_alignment(ctx->variable_display_values[offset++]);
 1150|       |
 1151|    802|        i += info->n_segments;
 1152|    802|    }
 1153|    154|    return READSTAT_OK;
 1154|    197|}
readstat_sav_read.c:sav_handle_variables:
 1665|  1.88k|static readstat_error_t sav_handle_variables(sav_ctx_t *ctx) {
 1666|  1.88k|    int i;
 1667|  1.88k|    int index_after_skipping = 0;
 1668|  1.88k|    readstat_error_t retval = READSTAT_OK;
 1669|       |
 1670|  29.8k|    for (i=0; i<ctx->var_index;) {
  ------------------
  |  Branch (1670:15): [True: 28.0k, False: 1.88k]
  ------------------
 1671|  28.0k|        char label_name_buf[256];
 1672|  28.0k|        spss_varinfo_t *info = ctx->varinfo[i];
 1673|  28.0k|        ctx->variables[info->index] = spss_init_variable_for_info(info, index_after_skipping, ctx->converter);
 1674|  28.0k|        if (ctx->variables[info->index] == NULL) {
  ------------------
  |  Branch (1674:13): [True: 0, False: 28.0k]
  ------------------
 1675|      0|            retval = READSTAT_ERROR_MALLOC;
 1676|      0|            goto cleanup;
 1677|      0|        }
 1678|       |
 1679|  28.0k|        snprintf(label_name_buf, sizeof(label_name_buf), SAV_LABEL_NAME_PREFIX "%d", info->labels_index);
  ------------------
  |  |  117|  28.0k|#define SAV_LABEL_NAME_PREFIX         "labels"
  ------------------
 1680|       |
 1681|  28.0k|        int cb_retval = READSTAT_HANDLER_OK;
  ------------------
  |  |   22|  28.0k|#define READSTAT_HANDLER_OK             0
  ------------------
 1682|  28.0k|        if (ctx->handle.variable) {
  ------------------
  |  Branch (1682:13): [True: 28.0k, False: 0]
  ------------------
 1683|  28.0k|            cb_retval = ctx->handle.variable(info->index, ctx->variables[info->index],
 1684|  28.0k|                    info->labels_index == -1 ? NULL : label_name_buf,
  ------------------
  |  Branch (1684:21): [True: 27.8k, False: 204]
  ------------------
 1685|  28.0k|                    ctx->user_ctx);
 1686|  28.0k|        }
 1687|       |
 1688|  28.0k|        if (cb_retval == READSTAT_HANDLER_ABORT) {
  ------------------
  |  |   23|  28.0k|#define READSTAT_HANDLER_ABORT          1
  ------------------
  |  Branch (1688:13): [True: 0, False: 28.0k]
  ------------------
 1689|      0|            retval = READSTAT_ERROR_USER_ABORT;
 1690|      0|            goto cleanup;
 1691|      0|        }
 1692|       |
 1693|  28.0k|        if (cb_retval == READSTAT_HANDLER_SKIP_VARIABLE) {
  ------------------
  |  |   24|  28.0k|#define READSTAT_HANDLER_SKIP_VARIABLE  2
  ------------------
  |  Branch (1693:13): [True: 0, False: 28.0k]
  ------------------
 1694|      0|            ctx->variables[info->index]->skip = 1;
 1695|  28.0k|        } else {
 1696|  28.0k|            index_after_skipping++;
 1697|  28.0k|        }
 1698|       |
 1699|  28.0k|        i += info->n_segments;
 1700|  28.0k|    }
 1701|  1.88k|cleanup:
 1702|  1.88k|    return retval;
 1703|  1.88k|}
readstat_sav_read.c:sav_handle_fweight:
 1705|  1.88k|static readstat_error_t sav_handle_fweight(sav_ctx_t *ctx) {
 1706|  1.88k|    readstat_error_t retval = READSTAT_OK;
 1707|  1.88k|    int i;
 1708|  1.88k|    if (ctx->handle.fweight && ctx->fweight_index >= 0) {
  ------------------
  |  Branch (1708:9): [True: 1.88k, False: 0]
  |  Branch (1708:32): [True: 1.34k, False: 538]
  ------------------
 1709|  27.5k|        for (i=0; i<ctx->var_index;) {
  ------------------
  |  Branch (1709:19): [True: 26.2k, False: 1.32k]
  ------------------
 1710|  26.2k|            spss_varinfo_t *info = ctx->varinfo[i];
 1711|  26.2k|            if (info->offset == ctx->fweight_index - 1) {
  ------------------
  |  Branch (1711:17): [True: 22, False: 26.1k]
  ------------------
 1712|     22|                if (info->type != READSTAT_TYPE_DOUBLE)
  ------------------
  |  Branch (1712:21): [True: 11, False: 11]
  ------------------
 1713|     11|                    break; /* PSPP ignores a weight that names a string variable */
 1714|     11|                if (ctx->handle.fweight(ctx->variables[info->index], ctx->user_ctx) != READSTAT_HANDLER_OK) {
  ------------------
  |  |   22|     11|#define READSTAT_HANDLER_OK             0
  ------------------
  |  Branch (1714:21): [True: 0, False: 11]
  ------------------
 1715|      0|                    retval = READSTAT_ERROR_USER_ABORT;
 1716|      0|                    goto cleanup;
 1717|      0|                }
 1718|     11|                break;
 1719|     11|            }
 1720|  26.1k|            i += info->n_segments;
 1721|  26.1k|        }
 1722|  1.34k|    }
 1723|  1.88k|cleanup:
 1724|  1.88k|    return retval;
 1725|  1.88k|}
readstat_sav_read.c:sav_read_data:
  840|  1.88k|static readstat_error_t sav_read_data(sav_ctx_t *ctx) {
  841|  1.88k|    readstat_error_t retval = READSTAT_OK;
  842|  1.88k|    size_t longest_string = 256;
  843|  1.88k|    int i;
  844|       |
  845|  29.8k|    for (i=0; i<ctx->var_index;) {
  ------------------
  |  Branch (845:15): [True: 28.0k, False: 1.88k]
  ------------------
  846|  28.0k|        spss_varinfo_t *info = ctx->varinfo[i];
  847|  28.0k|        if (info->string_length > longest_string) {
  ------------------
  |  Branch (847:13): [True: 1.07k, False: 26.9k]
  ------------------
  848|  1.07k|            longest_string = info->string_length;
  849|  1.07k|        }
  850|  28.0k|        i += info->n_segments;
  851|  28.0k|    }
  852|       |
  853|  1.88k|    ctx->raw_string_len = longest_string + sizeof(SAV_EIGHT_SPACES)-2;
  ------------------
  |  |  146|  1.88k|#define SAV_EIGHT_SPACES              "        "
  ------------------
  854|  1.88k|    ctx->raw_string = readstat_malloc(ctx->raw_string_len);
  855|       |
  856|  1.88k|    ctx->utf8_string_len = 4*longest_string+1 + sizeof(SAV_EIGHT_SPACES)-2;
  ------------------
  |  |  146|  1.88k|#define SAV_EIGHT_SPACES              "        "
  ------------------
  857|  1.88k|    ctx->utf8_string = readstat_malloc(ctx->utf8_string_len);
  858|       |
  859|  1.88k|    if (ctx->raw_string == NULL || ctx->utf8_string == NULL) {
  ------------------
  |  Branch (859:9): [True: 229, False: 1.65k]
  |  Branch (859:36): [True: 46, False: 1.60k]
  ------------------
  860|    275|        retval = READSTAT_ERROR_MALLOC;
  861|    275|        goto done;
  862|    275|    }
  863|       |
  864|  1.60k|    if (ctx->compression == READSTAT_COMPRESS_ROWS) {
  ------------------
  |  Branch (864:9): [True: 607, False: 1.00k]
  ------------------
  865|    607|        retval = sav_read_compressed_data(ctx, &sav_process_row);
  866|  1.00k|    } else if (ctx->compression == READSTAT_COMPRESS_BINARY) {
  ------------------
  |  Branch (866:16): [True: 432, False: 570]
  ------------------
  867|    432|#if HAVE_ZLIB
  868|    432|        retval = zsav_read_compressed_data(ctx, &sav_process_row);
  869|       |#else
  870|       |        retval = READSTAT_ERROR_UNSUPPORTED_COMPRESSION;
  871|       |#endif
  872|    570|    } else {
  873|    570|        retval = sav_read_uncompressed_data(ctx, &sav_process_row);
  874|    570|    }
  875|  1.60k|    if (retval != READSTAT_OK)
  ------------------
  |  Branch (875:9): [True: 570, False: 1.03k]
  ------------------
  876|    570|        goto done;
  877|       |
  878|  1.03k|    if (ctx->record_count >= 0 && ctx->current_row != ctx->row_limit) {
  ------------------
  |  Branch (878:9): [True: 754, False: 285]
  |  Branch (878:35): [True: 670, False: 84]
  ------------------
  879|    670|        retval = READSTAT_ERROR_ROW_COUNT_MISMATCH;
  880|    670|    }
  881|       |
  882|  1.88k|done:
  883|  1.88k|    return retval;
  884|  1.03k|}
readstat_sav_read.c:sav_read_compressed_data:
  927|    607|        readstat_error_t (*row_handler)(unsigned char *, size_t, sav_ctx_t *)) {
  928|    607|    readstat_error_t retval = READSTAT_OK;
  929|    607|    readstat_io_t *io = ctx->io;
  930|    607|    readstat_off_t data_offset = 0;
  931|    607|    unsigned char buffer[DATA_BUFFER_SIZE];
  932|    607|    int buffer_used = 0;
  933|    607|    int trailing_bytes = 0;
  934|       |
  935|    607|    size_t uncompressed_row_len = ctx->var_offset * 8;
  936|    607|    readstat_off_t uncompressed_offset = 0;
  937|    607|    unsigned char *uncompressed_row = NULL;
  938|       |
  939|    607|    struct sav_row_stream_s state = { 
  940|    607|        .missing_value = ctx->missing_double,
  941|    607|        .bias = ctx->bias,
  942|    607|        .bswap = ctx->bswap };
  943|       |
  944|    607|    if (uncompressed_row_len && (uncompressed_row = readstat_malloc(uncompressed_row_len)) == NULL) {
  ------------------
  |  Branch (944:9): [True: 607, False: 0]
  |  Branch (944:33): [True: 0, False: 607]
  ------------------
  945|      0|        retval = READSTAT_ERROR_MALLOC;
  946|      0|        goto done;
  947|      0|    }
  948|       |
  949|  1.10k|    while (1) {
  ------------------
  |  Branch (949:12): [True: 1.10k, Folded]
  ------------------
  950|  1.10k|        retval = sav_update_progress(ctx);
  951|  1.10k|        if (retval != READSTAT_OK)
  ------------------
  |  Branch (951:13): [True: 0, False: 1.10k]
  ------------------
  952|      0|            goto done;
  953|       |
  954|  1.10k|        buffer_used = io->read(buffer, sizeof(buffer), io->io_ctx);
  955|  1.10k|        if (buffer_used == -1 || buffer_used == 0) {
  ------------------
  |  Branch (955:13): [True: 0, False: 1.10k]
  |  Branch (955:34): [True: 420, False: 682]
  ------------------
  956|    420|            if (uncompressed_offset != 0 && (ctx->row_limit < 0 || ctx->current_row < ctx->row_limit)) {
  ------------------
  |  Branch (956:17): [True: 106, False: 314]
  |  Branch (956:46): [True: 10, False: 96]
  |  Branch (956:68): [True: 85, False: 11]
  ------------------
  957|       |                /* File ends in the middle of a row */
  958|     95|                retval = READSTAT_ERROR_PARSE;
  959|     95|            }
  960|    420|            goto done;
  961|    420|        }
  962|       |        /* Decode every complete opcode block; a trailing fragment ends the data */
  963|    682|        trailing_bytes = buffer_used % 8;
  964|    682|        buffer_used -= trailing_bytes;
  965|       |
  966|    682|        state.status = SAV_ROW_STREAM_HAVE_DATA;
  967|    682|        data_offset = 0;
  968|       |
  969|  2.69M|        while (state.status != SAV_ROW_STREAM_NEED_DATA) {
  ------------------
  |  Branch (969:16): [True: 2.69M, False: 641]
  ------------------
  970|  2.69M|            state.next_in = &buffer[data_offset];
  971|  2.69M|            state.avail_in = buffer_used - data_offset;
  972|       |
  973|  2.69M|            state.next_out = &uncompressed_row[uncompressed_offset];
  974|  2.69M|            state.avail_out = uncompressed_row_len - uncompressed_offset;
  975|       |
  976|  2.69M|            sav_decompress_row(&state);
  977|       |
  978|  2.69M|            uncompressed_offset = uncompressed_row_len - state.avail_out;
  979|  2.69M|            data_offset = buffer_used - state.avail_in;
  980|       |
  981|  2.69M|            if (state.status == SAV_ROW_STREAM_FINISHED_ROW) {
  ------------------
  |  Branch (981:17): [True: 2.69M, False: 660]
  ------------------
  982|  2.69M|                retval = row_handler(uncompressed_row, uncompressed_row_len, ctx);
  983|  2.69M|                if (retval != READSTAT_OK)
  ------------------
  |  Branch (983:21): [True: 20, False: 2.69M]
  ------------------
  984|     20|                    goto done;
  985|       |
  986|  2.69M|                uncompressed_offset = 0;
  987|  2.69M|            }
  988|       |
  989|  2.69M|            if (state.status == SAV_ROW_STREAM_FINISHED_ALL)
  ------------------
  |  Branch (989:17): [True: 19, False: 2.69M]
  ------------------
  990|     19|                goto done;
  991|  2.69M|            if (ctx->row_limit > 0 && ctx->current_row == ctx->row_limit)
  ------------------
  |  Branch (991:17): [True: 798k, False: 1.89M]
  |  Branch (991:39): [True: 2, False: 798k]
  ------------------
  992|      2|                goto done;
  993|  2.69M|        }
  994|    641|        if (trailing_bytes) {
  ------------------
  |  Branch (994:13): [True: 146, False: 495]
  ------------------
  995|    146|            if (uncompressed_offset != 0 && (ctx->row_limit < 0 || ctx->current_row < ctx->row_limit)) {
  ------------------
  |  Branch (995:17): [True: 80, False: 66]
  |  Branch (995:46): [True: 6, False: 74]
  |  Branch (995:68): [True: 61, False: 13]
  ------------------
  996|     67|                retval = READSTAT_ERROR_PARSE;
  997|     67|            }
  998|    146|            goto done;
  999|    146|        }
 1000|    641|    }
 1001|       |
 1002|    607|done:
 1003|    607|    if (uncompressed_row)
  ------------------
  |  Branch (1003:9): [True: 607, False: 0]
  ------------------
 1004|    607|        free(uncompressed_row);
 1005|       |
 1006|    607|    return retval;
 1007|    607|}
readstat_sav_read.c:sav_process_row:
  750|  2.69M|static readstat_error_t sav_process_row(unsigned char *buffer, size_t buffer_len, sav_ctx_t *ctx) {
  751|  2.69M|    if (ctx->row_offset) {
  ------------------
  |  Branch (751:9): [True: 0, False: 2.69M]
  ------------------
  752|      0|        ctx->row_offset--;
  753|      0|        return READSTAT_OK;
  754|      0|    }
  755|       |
  756|  2.69M|    readstat_error_t retval = READSTAT_OK;
  757|  2.69M|    double fp_value;
  758|  2.69M|    int offset = 0;
  759|  2.69M|    readstat_off_t data_offset = 0;
  760|  2.69M|    size_t raw_str_used = 0;
  761|  2.69M|    int segment_offset = 0;
  762|  2.69M|    int var_index = 0, col = 0;
  763|  2.69M|    int raw_str_is_utf8 = ctx->input_encoding && !strcmp(ctx->input_encoding, "UTF-8");
  ------------------
  |  Branch (763:27): [True: 557, False: 2.69M]
  |  Branch (763:50): [True: 301, False: 256]
  ------------------
  764|       |
  765|  5.87M|    while (data_offset < buffer_len && col < ctx->var_index && var_index < ctx->var_index) {
  ------------------
  |  Branch (765:12): [True: 3.17M, False: 2.69M]
  |  Branch (765:40): [True: 3.17M, False: 194]
  |  Branch (765:64): [True: 3.17M, False: 43]
  ------------------
  766|  3.17M|        spss_varinfo_t *col_info = ctx->varinfo[col];
  767|  3.17M|        spss_varinfo_t *var_info = ctx->varinfo[var_index];
  768|  3.17M|        readstat_value_t value = { .type = var_info->type };
  769|  3.17M|        if (offset > 31) {
  ------------------
  |  Branch (769:13): [True: 1, False: 3.17M]
  ------------------
  770|      1|            retval = READSTAT_ERROR_PARSE;
  771|      1|            goto done;
  772|      1|        }
  773|  3.17M|        if (var_info->type == READSTAT_TYPE_STRING) {
  ------------------
  |  Branch (773:13): [True: 1.35M, False: 1.82M]
  ------------------
  774|       |            // If we're in the last column of a segment, only read 7 bytes
  775|       |            // (Segments contain 255 bytes but have room for 256)
  776|  1.35M|            size_t read_len = 8 - (offset == 31);
  777|       |            /* Data in padding and in the unused space of very long string
  778|       |             * segments is ignored, per the spec */
  779|  1.35M|            if (raw_str_used + read_len > var_info->string_length) {
  ------------------
  |  Branch (779:17): [True: 31.7k, False: 1.32M]
  ------------------
  780|  31.7k|                read_len = var_info->string_length > raw_str_used ? var_info->string_length - raw_str_used : 0;
  ------------------
  |  Branch (780:28): [True: 31.1k, False: 551]
  ------------------
  781|  31.7k|            }
  782|  1.35M|            if (read_len && raw_str_used + read_len <= ctx->raw_string_len) {
  ------------------
  |  Branch (782:17): [True: 1.35M, False: 551]
  |  Branch (782:29): [True: 1.35M, False: 0]
  ------------------
  783|  1.35M|                if (raw_str_is_utf8) {
  ------------------
  |  Branch (783:21): [True: 329, False: 1.35M]
  ------------------
  784|       |                    /* Skip null bytes, see https://github.com/tidyverse/haven/issues/560  */
  785|    329|                    char c;
  786|  1.87k|                    for (int i=0; i<read_len; i++)
  ------------------
  |  Branch (786:35): [True: 1.55k, False: 329]
  ------------------
  787|  1.55k|                        if ((c = buffer[data_offset+i]))
  ------------------
  |  Branch (787:29): [True: 793, False: 757]
  ------------------
  788|    793|                            ctx->raw_string[raw_str_used++] = c;
  789|  1.35M|                } else {
  790|  1.35M|                    memcpy(ctx->raw_string + raw_str_used, &buffer[data_offset], read_len);
  791|  1.35M|                    raw_str_used += read_len;
  792|  1.35M|                }
  793|  1.35M|            }
  794|  1.35M|            if (++offset == col_info->width) {
  ------------------
  |  Branch (794:17): [True: 896k, False: 456k]
  ------------------
  795|   896k|                offset = 0;
  796|   896k|                col++;
  797|   896k|                segment_offset++;
  798|   896k|            }
  799|  1.35M|            if (segment_offset == var_info->n_segments) {
  ------------------
  |  Branch (799:17): [True: 50.0k, False: 1.30M]
  ------------------
  800|  50.0k|                if (!ctx->variables[var_info->index]->skip) {
  ------------------
  |  Branch (800:21): [True: 50.0k, False: 0]
  ------------------
  801|  50.0k|                    retval = readstat_convert(ctx->utf8_string, ctx->utf8_string_len, 
  802|  50.0k|                            ctx->raw_string, raw_str_used, ctx->converter);
  803|  50.0k|                    if (retval != READSTAT_OK)
  ------------------
  |  Branch (803:25): [True: 29, False: 50.0k]
  ------------------
  804|     29|                        goto done;
  805|  50.0k|                    value.v.string_value = ctx->utf8_string;
  806|  50.0k|                    if (ctx->handle.value(ctx->current_row, ctx->variables[var_info->index],
  ------------------
  |  Branch (806:25): [True: 0, False: 50.0k]
  ------------------
  807|  50.0k|                                value, ctx->user_ctx) != READSTAT_HANDLER_OK) {
  ------------------
  |  |   22|  50.0k|#define READSTAT_HANDLER_OK             0
  ------------------
  808|      0|                        retval = READSTAT_ERROR_USER_ABORT;
  809|      0|                        goto done;
  810|      0|                    }
  811|  50.0k|                }
  812|  50.0k|                raw_str_used = 0;
  813|  50.0k|                segment_offset = 0;
  814|  50.0k|                var_index += var_info->n_segments;
  815|  50.0k|            }
  816|  1.82M|        } else if (var_info->type == READSTAT_TYPE_DOUBLE) {
  ------------------
  |  Branch (816:20): [True: 1.82M, False: 0]
  ------------------
  817|  1.82M|            if (!ctx->variables[var_info->index]->skip) {
  ------------------
  |  Branch (817:17): [True: 1.82M, False: 0]
  ------------------
  818|  1.82M|                memcpy(&fp_value, &buffer[data_offset], 8);
  819|  1.82M|                if (ctx->bswap) {
  ------------------
  |  Branch (819:21): [True: 131k, False: 1.69M]
  ------------------
  820|   131k|                    fp_value = byteswap_double(fp_value);
  821|   131k|                }
  822|  1.82M|                value.v.double_value = fp_value;
  823|  1.82M|                sav_tag_missing_double(&value, ctx);
  824|  1.82M|                if (ctx->handle.value(ctx->current_row, ctx->variables[var_info->index],
  ------------------
  |  Branch (824:21): [True: 0, False: 1.82M]
  ------------------
  825|  1.82M|                            value, ctx->user_ctx) != READSTAT_HANDLER_OK) {
  ------------------
  |  |   22|  1.82M|#define READSTAT_HANDLER_OK             0
  ------------------
  826|      0|                    retval = READSTAT_ERROR_USER_ABORT;
  827|      0|                    goto done;
  828|      0|                }
  829|  1.82M|            }
  830|  1.82M|            var_index += var_info->n_segments;
  831|  1.82M|            col++;
  832|  1.82M|        }
  833|  3.17M|        data_offset += 8;
  834|  3.17M|    }
  835|  2.69M|    ctx->current_row++;
  836|  2.69M|done:
  837|  2.69M|    return retval;
  838|  2.69M|}
readstat_sav_read.c:sav_read_uncompressed_data:
  887|    570|        readstat_error_t (*row_handler)(unsigned char *, size_t, sav_ctx_t *)) {
  888|    570|    readstat_error_t retval = READSTAT_OK;
  889|    570|    readstat_io_t *io = ctx->io;
  890|    570|    unsigned char *buffer = NULL;
  891|    570|    size_t bytes_read = 0;
  892|    570|    size_t buffer_len = ctx->var_offset * 8;
  893|       |
  894|    570|    if ((buffer = readstat_malloc(buffer_len)) == NULL) {
  ------------------
  |  Branch (894:9): [True: 0, False: 570]
  ------------------
  895|      0|        retval = READSTAT_ERROR_MALLOC;
  896|      0|        goto done;
  897|      0|    }
  898|       |
  899|    570|    if (ctx->row_offset) {
  ------------------
  |  Branch (899:9): [True: 0, False: 570]
  ------------------
  900|      0|        if (io->seek(buffer_len * ctx->row_offset, READSTAT_SEEK_CUR, io->io_ctx) == -1) {
  ------------------
  |  Branch (900:13): [True: 0, False: 0]
  ------------------
  901|      0|            retval = READSTAT_ERROR_SEEK;
  902|      0|            goto done;
  903|      0|        }
  904|      0|        ctx->row_offset = 0;
  905|      0|    }
  906|       |
  907|  1.45k|    while (ctx->row_limit == -1 || ctx->current_row < ctx->row_limit) {
  ------------------
  |  Branch (907:12): [True: 562, False: 895]
  |  Branch (907:36): [True: 845, False: 50]
  ------------------
  908|  1.40k|        retval = sav_update_progress(ctx);
  909|  1.40k|        if (retval != READSTAT_OK)
  ------------------
  |  Branch (909:13): [True: 0, False: 1.40k]
  ------------------
  910|      0|            goto done;
  911|       |
  912|  1.40k|        if ((bytes_read = io->read(buffer, buffer_len, io->io_ctx)) != buffer_len)
  ------------------
  |  Branch (912:13): [True: 512, False: 895]
  ------------------
  913|    512|            goto done;
  914|       |
  915|    895|        retval = row_handler(buffer, buffer_len, ctx);
  916|    895|        if (retval != READSTAT_OK)
  ------------------
  |  Branch (916:13): [True: 8, False: 887]
  ------------------
  917|      8|            goto done;
  918|    895|    }
  919|    570|done:
  920|    570|    if (buffer)
  ------------------
  |  Branch (920:9): [True: 570, False: 0]
  ------------------
  921|    570|        free(buffer);
  922|       |
  923|    570|    return retval;
  924|    570|}

spss_format:
   51|  28.0k|int spss_format(char *buffer, size_t len, spss_format_t *format) {
   52|  28.0k|    if (format->type < 0 
  ------------------
  |  Branch (52:9): [True: 0, False: 28.0k]
  ------------------
   53|  28.0k|            || format->type >= sizeof(spss_type_strings)/sizeof(spss_type_strings[0])
  ------------------
  |  Branch (53:16): [True: 8.97k, False: 19.0k]
  ------------------
   54|  19.0k|            || spss_type_strings[format->type][0] == '\0') {
  ------------------
  |  Branch (54:16): [True: 9.11k, False: 9.91k]
  ------------------
   55|  18.0k|        return 0;
   56|  18.0k|    }
   57|  9.91k|    char *string = spss_type_strings[format->type];
   58|       |
   59|  9.91k|    if (format->decimal_places || format->type == SPSS_FORMAT_TYPE_F) {
  ------------------
  |  |    6|  6.51k|#define SPSS_FORMAT_TYPE_F        5
  ------------------
  |  Branch (59:9): [True: 3.40k, False: 6.51k]
  |  Branch (59:35): [True: 386, False: 6.12k]
  ------------------
   60|  3.78k|        snprintf(buffer, len, "%s%d.%d", string, format->width, format->decimal_places);
   61|  6.12k|    } else if (format->width) {
  ------------------
  |  Branch (61:16): [True: 3.81k, False: 2.31k]
  ------------------
   62|  3.81k|        snprintf(buffer, len, "%s%d", string, format->width);
   63|  3.81k|    } else {
   64|  2.31k|        snprintf(buffer, len, "%s", string);
   65|  2.31k|    }
   66|       |
   67|  9.91k|    return 1;
   68|  28.0k|}
spss_varinfo_compare:
   70|  1.08M|int spss_varinfo_compare(const void *elem1, const void *elem2) {
   71|  1.08M|    int offset = *(int *)elem1;
   72|  1.08M|    const spss_varinfo_t *v = *(const spss_varinfo_t **)elem2;
   73|  1.08M|    if (offset < v->offset)
  ------------------
  |  Branch (73:9): [True: 690k, False: 393k]
  ------------------
   74|   690k|        return -1;
   75|   393k|    return (offset > v->offset);
   76|  1.08M|}
spss_varinfo_free:
   78|   440k|void spss_varinfo_free(spss_varinfo_t *info) {
   79|   440k|    if (info) {
  ------------------
  |  Branch (79:9): [True: 440k, False: 0]
  ------------------
   80|   440k|        if (info->label)
  ------------------
  |  Branch (80:13): [True: 6.72k, False: 434k]
  ------------------
   81|  6.72k|            free(info->label);
   82|   440k|        free(info);
   83|   440k|    }
   84|   440k|}
spss_missingness_for_info:
  127|  28.0k|readstat_missingness_t spss_missingness_for_info(spss_varinfo_t *info) {
  128|  28.0k|    readstat_missingness_t missingness;
  129|  28.0k|    memset(&missingness, '\0', sizeof(readstat_missingness_t));
  130|       |
  131|  28.0k|    if (info->missing_range) {
  ------------------
  |  Branch (131:9): [True: 6.31k, False: 21.6k]
  ------------------
  132|  6.31k|        missingness.missing_ranges_count++;
  133|  6.31k|        missingness.missing_ranges[0] = spss_boxed_missing_value(info, 0);
  134|  6.31k|        missingness.missing_ranges[1] = spss_boxed_missing_value(info, 1);
  135|       |
  136|  6.31k|        if (info->n_missing_values == 3) {
  ------------------
  |  Branch (136:13): [True: 5.29k, False: 1.02k]
  ------------------
  137|  5.29k|            missingness.missing_ranges_count++;
  138|  5.29k|            missingness.missing_ranges[2] = missingness.missing_ranges[3] = spss_boxed_missing_value(info, 2);
  139|  5.29k|        }
  140|  21.6k|    } else if (info->n_missing_values > 0) {
  ------------------
  |  Branch (140:16): [True: 8.13k, False: 13.5k]
  ------------------
  141|  8.13k|        missingness.missing_ranges_count = info->n_missing_values;
  142|  8.13k|        int i=0;
  143|  31.7k|        for (i=0; i<info->n_missing_values; i++) {
  ------------------
  |  Branch (143:19): [True: 23.6k, False: 8.13k]
  ------------------
  144|  23.6k|            missingness.missing_ranges[2*i] = missingness.missing_ranges[2*i+1] = spss_boxed_missing_value(info, i);
  145|  23.6k|        }
  146|  8.13k|    }
  147|  28.0k|    return missingness;
  148|  28.0k|}
spss_init_variable_for_info:
  151|  28.0k|        iconv_t converter) {
  152|  28.0k|    readstat_variable_t *variable = calloc(1, sizeof(readstat_variable_t));
  153|       |
  154|  28.0k|    variable->index = info->index;
  155|  28.0k|    variable->index_after_skipping = index_after_skipping;
  156|  28.0k|    variable->type = info->type;
  157|  28.0k|    if (info->string_length) {
  ------------------
  |  Branch (157:9): [True: 8.12k, False: 19.8k]
  ------------------
  158|  8.12k|        variable->storage_width = info->string_length;
  159|  19.8k|    } else {
  160|  19.8k|        variable->storage_width = 8 * info->width;
  161|  19.8k|    }
  162|       |
  163|  28.0k|    if (info->longname[0]) {
  ------------------
  |  Branch (163:9): [True: 25.7k, False: 2.28k]
  ------------------
  164|  25.7k|        readstat_convert(variable->name, sizeof(variable->name),
  165|  25.7k|                info->longname, sizeof(info->longname), converter);
  166|  25.7k|    } else {
  167|  2.28k|        readstat_convert(variable->name, sizeof(variable->name),
  168|  2.28k|                info->name, sizeof(info->name), converter);
  169|  2.28k|    }
  170|  28.0k|    if (info->label) {
  ------------------
  |  Branch (170:9): [True: 5.19k, False: 22.8k]
  ------------------
  171|  5.19k|        snprintf(variable->label, sizeof(variable->label), "%s", info->label);
  172|  5.19k|    }
  173|       |
  174|  28.0k|    spss_format(variable->format, sizeof(variable->format), &info->print_format);
  175|       |
  176|  28.0k|    variable->missingness = spss_missingness_for_info(info);
  177|  28.0k|    variable->measure = info->measure;
  178|  28.0k|    variable->alignment = info->alignment;
  179|  28.0k|    if (info->display_width) {
  ------------------
  |  Branch (179:9): [True: 153, False: 27.8k]
  ------------------
  180|    153|        variable->display_width = info->display_width;
  181|  27.8k|    } else {
  182|  27.8k|        variable->display_width = info->print_format.width;
  183|  27.8k|    }
  184|       |
  185|  28.0k|    return variable;
  186|  28.0k|}
spss_measure_to_readstat_measure:
  200|    802|readstat_measure_t spss_measure_to_readstat_measure(uint32_t sav_measure) {
  201|    802|    if (sav_measure == SAV_MEASURE_NOMINAL)
  ------------------
  |  |   47|    802|#define SAV_MEASURE_NOMINAL     1
  ------------------
  |  Branch (201:9): [True: 44, False: 758]
  ------------------
  202|     44|        return READSTAT_MEASURE_NOMINAL;
  203|    758|    if (sav_measure == SAV_MEASURE_ORDINAL)
  ------------------
  |  |   48|    758|#define SAV_MEASURE_ORDINAL     2
  ------------------
  |  Branch (203:9): [True: 41, False: 717]
  ------------------
  204|     41|        return READSTAT_MEASURE_ORDINAL;
  205|    717|    if (sav_measure == SAV_MEASURE_SCALE)
  ------------------
  |  |   49|    717|#define SAV_MEASURE_SCALE       3
  ------------------
  |  Branch (205:9): [True: 73, False: 644]
  ------------------
  206|     73|        return READSTAT_MEASURE_SCALE;
  207|    644|    return READSTAT_MEASURE_UNKNOWN;
  208|    717|}
spss_alignment_to_readstat_alignment:
  222|    802|readstat_alignment_t spss_alignment_to_readstat_alignment(uint32_t sav_alignment) {
  223|    802|    if (sav_alignment == SAV_ALIGNMENT_LEFT)
  ------------------
  |  |   51|    802|#define SAV_ALIGNMENT_LEFT      0
  ------------------
  |  Branch (223:9): [True: 244, False: 558]
  ------------------
  224|    244|        return READSTAT_ALIGNMENT_LEFT;
  225|    558|    if (sav_alignment == SAV_ALIGNMENT_CENTER)
  ------------------
  |  |   53|    558|#define SAV_ALIGNMENT_CENTER    2
  ------------------
  |  Branch (225:9): [True: 38, False: 520]
  ------------------
  226|     38|        return READSTAT_ALIGNMENT_CENTER;
  227|    520|    if (sav_alignment == SAV_ALIGNMENT_RIGHT)
  ------------------
  |  |   52|    520|#define SAV_ALIGNMENT_RIGHT     1
  ------------------
  |  Branch (227:9): [True: 51, False: 469]
  ------------------
  228|     51|        return READSTAT_ALIGNMENT_RIGHT;
  229|    469|    return READSTAT_ALIGNMENT_UNKNOWN;
  230|    520|}
readstat_spss.c:spss_boxed_missing_value:
  120|  41.5k|static readstat_value_t spss_boxed_missing_value(spss_varinfo_t *info, int i) {
  121|  41.5k|    if (info->type == READSTAT_TYPE_DOUBLE) {
  ------------------
  |  Branch (121:9): [True: 36.4k, False: 5.08k]
  ------------------
  122|  36.4k|        return spss_boxed_double_value(info->missing_double_values[i]);
  123|  36.4k|    }
  124|  5.08k|    return spss_boxed_string_value(info->missing_string_values[i]);
  125|  41.5k|}
readstat_spss.c:spss_boxed_double_value:
  103|  36.4k|static readstat_value_t spss_boxed_double_value(double fp_value) {
  104|  36.4k|    readstat_value_t value = {
  105|  36.4k|        .type = READSTAT_TYPE_DOUBLE,
  106|  36.4k|        .v = { .double_value = fp_value },
  107|       |        .is_system_missing = isnan(fp_value)
  108|  36.4k|    };
  109|  36.4k|    return value;
  110|  36.4k|}
readstat_spss.c:spss_boxed_string_value:
  112|  5.08k|static readstat_value_t spss_boxed_string_value(const char *string) {
  113|  5.08k|    readstat_value_t value = {
  114|  5.08k|        .type = READSTAT_TYPE_STRING,
  115|  5.08k|        .v = { .string_value = string }
  116|  5.08k|    };
  117|  5.08k|    return value;
  118|  5.08k|}

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

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

