// File: /workspace/github_c_makefile_star2_O2/richarddurbin[P]hash10x/hash10x.c
// Function: readHashFile
void readHashFile (FILE *f)
{
  int B ; U32 version ; U16 clusterHashSize, clusterBlockSize ;
  char name[5] = "abcd" ;
  if ((fread (name, 4, 1, f) != 1) || (fread (&version, 4, 1, f) != 1) ||
      (fread (&clusterHashSize, 2, 1, f) != 1) || (fread (&clusterBlockSize, 2, 1, f) != 1))
    die ("read fail 0") ;
  if (strcmp (name, "10XH")) die ("not a 10X hash file") ;
  if (version > HASHFILE_VERSION)
    die ("hash file version mismatch: file %d > code %d", version, HASHFILE_VERSION) ;
  if (clusterHashSize != CLUSTERHASH_SIZE)
    die ("ClusterHash structure size mismatch: file %d != code %d", clusterHashSize, CLUSTERHASH_SIZE) ;
  if (clusterBlockSize != CLUSTERBLOCK_SIZE)
    die ("ClusterBlock structure size mismatch: file %d != code %d", clusterBlockSize, CLUSTERBLOCK_SIZE) ;
  if (fread (&B, 4, 1, f) != 1) die ("read fail 1") ;
  if (B != hashTableBits) die ("incompatible hash table size: rerun with -B %d", B) ;
  if (fread (hashIndex, sizeof(U32), hashTableSize, f) != hashTableSize) die ("read fail 2") ;
  if (version == 1)
    { Array a ;
      if (!(a = arrayRead (f))) die ("failed to read hashValue array") ;
      hashNumber = arrayMax(a) ; hashValue = new(hashNumber, U64) ;
      memcpy (hashValue, arrp(a,0,U64), hashNumber*sizeof(U64)) ;
      arrayDestroy (a) ;
    }
  else if (version == 2)
    { if (fread (&hashNumber, sizeof(U32), 1, f) != 1) die ("failed to read hashNumber") ;
      if (fread (hashValue, sizeof(U64), hashNumber, f) != hashNumber) die ("failed to read hashValue") ;
    }

  if (!(hashDepth = arrayRead (f))) die ("failed to read hashDepth array") ;
  if (!(clusterBlocks = arrayRead (f))) die ("failed to read clusterBlocks array") ;
  int i ;
  U64 nReads = 0, nHashes = 0 ;
  for (i = 1 ; i < arrayMax(clusterBlocks) ; ++i)
    { ClusterBlock *b = arrayp(clusterBlocks, i, ClusterBlock) ;
      nReads += b->nRead ; nHashes += b->nHash ;
      b->clusHash = new(b->nHash, ClusterHash) ;
      if (fread (b->clusHash, sizeof(ClusterHash), b->nHash, f) != b->nHash) die ("read fail 3") ;
    }
  fclose (f) ;

  fprintf (outFile, "  read %ld hashes for %ld reads in %d barcode blocks\n",
	  (long)nHashes, (long)nReads, arrayMax(clusterBlocks)) ;
  if (outFile != stdout)
    printf ("  read %ld hashes for %ld reads in %d barcode blocks\n",
	    (long)nHashes, (long)nReads, arrayMax(clusterBlocks)) ;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
leaq 0x18(%rsp), %rdi
movb $0x0, 0x4(%rdi)
movl $0x64636261, (%rdi)     # imm = 0x64636261
pushq $0x4
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rcx
callq 0x10a0
cmpq $0x1, %rax
jne 0x1ceb
leaq 0x10(%rsp), %rdi
pushq $0x4
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rcx
callq 0x10a0
cmpq $0x1, %rax
jne 0x1ceb
leaq 0xe(%rsp), %rdi
pushq $0x2
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rcx
callq 0x10a0
cmpq $0x1, %rax
jne 0x1ceb
leaq 0xc(%rsp), %rdi
pushq $0x2
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rcx
callq 0x10a0
cmpq $0x1, %rax
je 0x1cf9
leaq 0x755a(%rip), %rdi      # 0x924c
xorl %eax, %eax
callq 0x8a3c
leaq 0x746b(%rip), %rsi      # 0x916b
leaq 0x18(%rsp), %rdi
pushq $0x5
popq %rdx
callq 0x11c0
testl %eax, %eax
je 0x1d1f
leaq 0x7540(%rip), %rdi      # 0x9258
xorl %eax, %eax
callq 0x8a3c
movl 0x10(%rsp), %ebp
movl 0xd43f(%rip), %edx      # 0xf168
cmpl %edx, %ebp
jbe 0x1d3d
leaq 0x7538(%rip), %rdi      # 0x926c
movl %ebp, %esi
xorl %eax, %eax
callq 0x8a3c
movzwl 0xe(%rsp), %esi
movzwl 0xd423(%rip), %edx      # 0xf16c
cmpw %dx, %si
je 0x1d5c
leaq 0x7545(%rip), %rdi      # 0x929a
xorl %eax, %eax
callq 0x8a3c
movzwl 0xc(%rsp), %esi
movzwl 0xd406(%rip), %edx      # 0xf16e
cmpw %dx, %si
je 0x1d7b
leaq 0x755e(%rip), %rdi      # 0x92d2
xorl %eax, %eax
callq 0x8a3c
leaq 0x14(%rsp), %rdi
pushq $0x4
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rcx
callq 0x10a0
cmpq $0x1, %rax
je 0x1da2
leaq 0x7570(%rip), %rdi      # 0x930b
xorl %eax, %eax
callq 0x8a3c
movl 0x14(%rsp), %esi
cmpl 0xd3b4(%rip), %esi      # 0xf160
je 0x1dbc
leaq 0x7562(%rip), %rdi      # 0x9317
xorl %eax, %eax
callq 0x8a3c
movq 0xe5e5(%rip), %rdi      # 0x103a8
movq 0xe5e6(%rip), %rdx      # 0x103b0
pushq $0x4
popq %rsi
movq %rbx, %rcx
callq 0x10a0
cmpq 0xe5d4(%rip), %rax      # 0x103b0
je 0x1dec
leaq 0x7561(%rip), %rdi      # 0x9346
xorl %eax, %eax
callq 0x8a3c
cmpl $0x2, %ebp
je 0x1e52
cmpl $0x1, %ebp
jne 0x1eac
movq %rbx, %rdi
callq 0x868e
movq %rax, %r14
testq %rax, %rax
jne 0x1e18
leaq 0x7541(%rip), %rdi      # 0x9352
xorl %eax, %eax
callq 0x8a3c
movl 0x18(%r14), %edi
movl %edi, 0xe596(%rip)      # 0x103b8
shlq $0x3, %rdi
callq 0x8afc
movq %rax, 0xe58e(%rip)      # 0x103c0
movq 0x8(%r14), %rsi
movl 0xe57c(%rip), %edx      # 0x103b8
shlq $0x3, %rdx
movq %rax, %rdi
callq 0x1170
movq %r14, %rdi
callq 0x8408
jmp 0x1eac
leaq 0xe55f(%rip), %rdi      # 0x103b8
pushq $0x4
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rcx
callq 0x10a0
cmpq $0x1, %rax
je 0x1e7b
leaq 0x74fd(%rip), %rdi      # 0x9371
xorl %eax, %eax
callq 0x8a3c
movq 0xe53e(%rip), %rdi      # 0x103c0
movl 0xe530(%rip), %edx      # 0x103b8
pushq $0x8
popq %rsi
movq %rbx, %rcx
callq 0x10a0
movl 0xe51f(%rip), %ecx      # 0x103b8
cmpq %rcx, %rax
je 0x1eac
leaq 0x74e6(%rip), %rdi      # 0x938b
xorl %eax, %eax
callq 0x8a3c
movq %rbx, %rdi
callq 0x868e
movq %rax, 0xe4d5(%rip)      # 0x10390
testq %rax, %rax
jne 0x1ece
leaq 0x74dd(%rip), %rdi      # 0x93a4
xorl %eax, %eax
callq 0x8a3c
movq %rbx, 0x20(%rsp)
movq %rbx, %rdi
callq 0x868e
movq %rax, 0xe4b6(%rip)      # 0x10398
testq %rax, %rax
jne 0x1ef5
leaq 0x74d5(%rip), %rdi      # 0x93c3
xorl %eax, %eax
callq 0x8a3c
pushq $0x1
popq %rbp
xorl %r14d, %r14d
xorl %r15d, %r15d
movq 0xe493(%rip), %rdi      # 0x10398
cmpl 0x18(%rdi), %ebp
jge 0x1f5f
movl %ebp, %esi
callq 0x8560
movq %rax, %rbx
movl (%rax), %r12d
movl 0x4(%rax), %r13d
leaq (,%r13,8), %rdi
callq 0x8afc
movq %rax, 0x10(%rbx)
movl 0x4(%rbx), %edx
movq %rax, %rdi
pushq $0x8
popq %rsi
movq 0x20(%rsp), %rcx
callq 0x10a0
movl 0x4(%rbx), %ecx
cmpq %rcx, %rax
je 0x1f55
leaq 0x7498(%rip), %rdi      # 0x93e6
xorl %eax, %eax
callq 0x8a3c
addq %r12, %r14
addq %r13, %r15
incl %ebp
jmp 0x1efe
movq 0x20(%rsp), %rdi
callq 0x10b0
movq 0xe430(%rip), %rdi      # 0x103a0
movq 0xe421(%rip), %rax      # 0x10398
movl 0x18(%rax), %r8d
leaq 0x7470(%rip), %rsi      # 0x93f2
movq %r15, %rdx
movq %r14, %rcx
xorl %eax, %eax
callq 0x1150
movq 0xe40a(%rip), %rax      # 0x103a0
movq 0xd02b(%rip), %rcx      # 0xefc8
cmpq (%rcx), %rax
je 0x1fce
movq 0xe3ef(%rip), %rax      # 0x10398
movl 0x18(%rax), %ecx
leaq 0x743f(%rip), %rdi      # 0x93f2
movq %r15, %rsi
movq %r14, %rdx
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x10d0
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq