// File: /workspace/github_c_makefile_star2_O3/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 0x10(%rsp), %rdi
movb $0x0, 0x4(%rdi)
movl $0x64636261, (%rdi)     # imm = 0x64636261
movl $0x4, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x10a0
cmpq $0x1, %rax
jne 0x2644
leaq 0x18(%rsp), %rdi
movl $0x4, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x10a0
cmpq $0x1, %rax
jne 0x2644
leaq 0xe(%rsp), %rdi
movl $0x2, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x10a0
cmpq $0x1, %rax
jne 0x2644
leaq 0xc(%rsp), %rdi
movl $0x2, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x10a0
cmpq $0x1, %rax
je 0x2652
leaq 0x7c41(%rip), %rdi      # 0xa28c
xorl %eax, %eax
callq 0x95f8
movl $0x48583031, %eax       # imm = 0x48583031
xorl 0x10(%rsp), %eax
movzbl 0x14(%rsp), %ecx
orl %eax, %ecx
je 0x2672
leaq 0x7c2d(%rip), %rdi      # 0xa298
xorl %eax, %eax
callq 0x95f8
movl 0x18(%rsp), %ebp
movl 0xcadc(%rip), %edx      # 0xf158
cmpl %edx, %ebp
jbe 0x2690
leaq 0x7c25(%rip), %rdi      # 0xa2ac
movl %ebp, %esi
xorl %eax, %eax
callq 0x95f8
movzwl 0xe(%rsp), %esi
movzwl 0xcac0(%rip), %edx      # 0xf15c
cmpw %dx, %si
je 0x26af
leaq 0x7c32(%rip), %rdi      # 0xa2da
xorl %eax, %eax
callq 0x95f8
movzwl 0xc(%rsp), %esi
movzwl 0xcaa3(%rip), %edx      # 0xf15e
cmpw %dx, %si
je 0x26ce
leaq 0x7c4b(%rip), %rdi      # 0xa312
xorl %eax, %eax
callq 0x95f8
leaq 0x1c(%rsp), %rdi
movl $0x4, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x10a0
cmpq $0x1, %rax
je 0x26f9
leaq 0x7c59(%rip), %rdi      # 0xa34b
xorl %eax, %eax
callq 0x95f8
movl 0x1c(%rsp), %esi
cmpl 0xca4d(%rip), %esi      # 0xf150
je 0x2713
leaq 0x7c4b(%rip), %rdi      # 0xa357
xorl %eax, %eax
callq 0x95f8
movq 0xdc7e(%rip), %rdi      # 0x10398
movq 0xdc7f(%rip), %rdx      # 0x103a0
movl $0x4, %esi
movq %rbx, %rcx
callq 0x10a0
cmpq 0xdc6b(%rip), %rax      # 0x103a0
je 0x2745
leaq 0x7c48(%rip), %rdi      # 0xa386
xorl %eax, %eax
callq 0x95f8
cmpl $0x2, %ebp
je 0x27ab
cmpl $0x1, %ebp
jne 0x280b
movq %rbx, %rdi
callq 0x9263
movq %rax, %r14
testq %rax, %rax
jne 0x2771
leaq 0x7c28(%rip), %rdi      # 0xa392
xorl %eax, %eax
callq 0x95f8
movl 0x18(%r14), %edi
movl %edi, 0xdc2d(%rip)      # 0x103a8
shlq $0x3, %rdi
callq 0x96c0
movq %rax, 0xdc25(%rip)      # 0x103b0
movq 0x8(%r14), %rsi
movl 0xdc13(%rip), %edx      # 0x103a8
shlq $0x3, %rdx
movq %rax, %rdi
callq 0x1170
movq %r14, %rdi
callq 0x8fd6
jmp 0x280b
leaq 0xdbf6(%rip), %rdi      # 0x103a8
movl $0x4, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x10a0
cmpq $0x1, %rax
je 0x27d8
leaq 0x7be0(%rip), %rdi      # 0xa3b1
xorl %eax, %eax
callq 0x95f8
movq 0xdbd1(%rip), %rdi      # 0x103b0
movl 0xdbc3(%rip), %edx      # 0x103a8
movl $0x8, %esi
movq %rbx, %rcx
callq 0x10a0
movl 0xdbb0(%rip), %ecx      # 0x103a8
cmpq %rcx, %rax
je 0x280b
leaq 0x7bc7(%rip), %rdi      # 0xa3cb
xorl %eax, %eax
callq 0x95f8
movq %rbx, %rdi
callq 0x9263
movq %rax, 0xdb66(%rip)      # 0x10380
testq %rax, %rax
jne 0x282d
leaq 0x7bbe(%rip), %rdi      # 0xa3e4
xorl %eax, %eax
callq 0x95f8
movq %rbx, %rdi
callq 0x9263
movq %rax, %rdi
movq %rax, 0xdb49(%rip)      # 0x10388
testq %rax, %rax
jne 0x2859
leaq 0x7bb8(%rip), %rdi      # 0xa403
xorl %eax, %eax
callq 0x95f8
movq 0xdb2f(%rip), %rdi      # 0x10388
movq %rbx, 0x20(%rsp)
cmpl $0x2, 0x18(%rdi)
jl 0x28d3
movl $0x1, %ebp
xorl %r15d, %r15d
xorl %r14d, %r14d
movl %ebp, %esi
callq 0x9131
movq %rax, %r13
movl (%rax), %ebx
movl 0x4(%rax), %r12d
leaq (,%r12,8), %rdi
callq 0x96c0
movq %rax, 0x10(%r13)
movl 0x4(%r13), %edx
movl $0x8, %esi
movq %rax, %rdi
movq 0x20(%rsp), %rcx
callq 0x10a0
movl 0x4(%r13), %ecx
cmpq %rcx, %rax
je 0x28bd
leaq 0x7b70(%rip), %rdi      # 0xa426
xorl %eax, %eax
callq 0x95f8
addq %rbx, %r14
addq %r12, %r15
incl %ebp
movq 0xdabc(%rip), %rdi      # 0x10388
cmpl 0x18(%rdi), %ebp
jl 0x286f
jmp 0x28d9
xorl %r14d, %r14d
xorl %r15d, %r15d
movq 0x20(%rsp), %rdi
callq 0x10b0
movq 0xdaa6(%rip), %rdi      # 0x10390
movq 0xda97(%rip), %rax      # 0x10388
movl 0x18(%rax), %r8d
leaq 0x7b36(%rip), %rsi      # 0xa432
movq %r15, %rdx
movq %r14, %rcx
xorl %eax, %eax
callq 0x1150
movq 0xda80(%rip), %rax      # 0x10390
movq 0xc6b1(%rip), %rcx      # 0xefc8
cmpq (%rcx), %rax
je 0x2948
movq 0xda65(%rip), %rax      # 0x10388
movl 0x18(%rax), %ecx
leaq 0x7b05(%rip), %rdi      # 0xa432
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