// File: /workspace/github_c_makefile_star2_O1/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 0x265d
leaq 0x18(%rsp), %rdi
movl $0x4, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x10a0
cmpq $0x1, %rax
jne 0x265d
leaq 0xe(%rsp), %rdi
movl $0x2, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x10a0
cmpq $0x1, %rax
jne 0x265d
leaq 0xc(%rsp), %rdi
movl $0x2, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x10a0
cmpq $0x1, %rax
je 0x266b
leaq 0x7be8(%rip), %rdi      # 0xa24c
xorl %eax, %eax
callq 0x9408
movl $0x48583031, %eax       # imm = 0x48583031
xorl 0x10(%rsp), %eax
movzbl 0x14(%rsp), %ecx
orl %eax, %ecx
je 0x268b
leaq 0x7bd4(%rip), %rdi      # 0xa258
xorl %eax, %eax
callq 0x9408
movl 0x18(%rsp), %ebp
movl 0xcac3(%rip), %edx      # 0xf158
cmpl %edx, %ebp
jbe 0x26a9
leaq 0x7bcc(%rip), %rdi      # 0xa26c
movl %ebp, %esi
xorl %eax, %eax
callq 0x9408
movzwl 0xe(%rsp), %esi
movzwl 0xcaa7(%rip), %edx      # 0xf15c
cmpw %dx, %si
je 0x26c8
leaq 0x7bd9(%rip), %rdi      # 0xa29a
xorl %eax, %eax
callq 0x9408
movzwl 0xc(%rsp), %esi
movzwl 0xca8a(%rip), %edx      # 0xf15e
cmpw %dx, %si
je 0x26e7
leaq 0x7bf2(%rip), %rdi      # 0xa2d2
xorl %eax, %eax
callq 0x9408
leaq 0x1c(%rsp), %rdi
movl $0x4, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x10a0
cmpq $0x1, %rax
je 0x2712
leaq 0x7c00(%rip), %rdi      # 0xa30b
xorl %eax, %eax
callq 0x9408
movl 0x1c(%rsp), %esi
cmpl 0xca34(%rip), %esi      # 0xf150
je 0x272c
leaq 0x7bf2(%rip), %rdi      # 0xa317
xorl %eax, %eax
callq 0x9408
movq 0xdc65(%rip), %rdi      # 0x10398
movq 0xdc66(%rip), %rdx      # 0x103a0
movl $0x4, %esi
movq %rbx, %rcx
callq 0x10a0
cmpq 0xdc52(%rip), %rax      # 0x103a0
je 0x275e
leaq 0x7bef(%rip), %rdi      # 0xa346
xorl %eax, %eax
callq 0x9408
cmpl $0x2, %ebp
je 0x27c4
cmpl $0x1, %ebp
jne 0x2824
movq %rbx, %rdi
callq 0x905d
movq %rax, %r14
testq %rax, %rax
jne 0x278a
leaq 0x7bcf(%rip), %rdi      # 0xa352
xorl %eax, %eax
callq 0x9408
movl 0x18(%r14), %edi
movl %edi, 0xdc14(%rip)      # 0x103a8
shlq $0x3, %rdi
callq 0x94d0
movq %rax, 0xdc0c(%rip)      # 0x103b0
movq 0x8(%r14), %rsi
movl 0xdbfa(%rip), %edx      # 0x103a8
shlq $0x3, %rdx
movq %rax, %rdi
callq 0x1170
movq %r14, %rdi
callq 0x8dc9
jmp 0x2824
leaq 0xdbdd(%rip), %rdi      # 0x103a8
movl $0x4, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x10a0
cmpq $0x1, %rax
je 0x27f1
leaq 0x7b87(%rip), %rdi      # 0xa371
xorl %eax, %eax
callq 0x9408
movq 0xdbb8(%rip), %rdi      # 0x103b0
movl 0xdbaa(%rip), %edx      # 0x103a8
movl $0x8, %esi
movq %rbx, %rcx
callq 0x10a0
movl 0xdb97(%rip), %ecx      # 0x103a8
cmpq %rcx, %rax
je 0x2824
leaq 0x7b6e(%rip), %rdi      # 0xa38b
xorl %eax, %eax
callq 0x9408
movq %rbx, %rdi
callq 0x905d
movq %rax, 0xdb4d(%rip)      # 0x10380
testq %rax, %rax
jne 0x2846
leaq 0x7b65(%rip), %rdi      # 0xa3a4
xorl %eax, %eax
callq 0x9408
movq %rbx, %rdi
callq 0x905d
movq %rax, 0xdb33(%rip)      # 0x10388
testq %rax, %rax
jne 0x2868
leaq 0x7b62(%rip), %rdi      # 0xa3c3
xorl %eax, %eax
callq 0x9408
movq %rbx, 0x20(%rsp)
movq 0xdb14(%rip), %rdi      # 0x10388
cmpl $0x2, 0x18(%rdi)
jl 0x28e9
movl $0x1, %ebp
xorl %r15d, %r15d
xorl %r14d, %r14d
movl %ebp, %esi
callq 0x8f2b
movq %rax, %r13
movl (%rax), %ebx
movl 0x4(%rax), %r12d
leaq (,%r12,8), %rdi
callq 0x94d0
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 0x28d3
leaq 0x7b1a(%rip), %rdi      # 0xa3e6
xorl %eax, %eax
callq 0x9408
addq %rbx, %r14
addq %r12, %r15
incl %ebp
movq 0xdaa6(%rip), %rdi      # 0x10388
cmpl 0x18(%rdi), %ebp
jl 0x2885
jmp 0x28ef
xorl %r14d, %r14d
xorl %r15d, %r15d
movq 0x20(%rsp), %rdi
callq 0x10b0
movq 0xda90(%rip), %rdi      # 0x10390
movq 0xda81(%rip), %rax      # 0x10388
movl 0x18(%rax), %r8d
leaq 0x7ae0(%rip), %rsi      # 0xa3f2
movq %r15, %rdx
movq %r14, %rcx
xorl %eax, %eax
callq 0x1150
movq 0xda6a(%rip), %rax      # 0x10390
movq 0xc69b(%rip), %rcx      # 0xefc8
cmpq (%rcx), %rax
je 0x295e
movq 0xda4f(%rip), %rax      # 0x10388
movl 0x18(%rax), %ecx
leaq 0x7aaf(%rip), %rdi      # 0xa3f2
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