// File: /workspace/github_c_makefile_star2_O0/richarddurbin[P]hash10x/hash10x.c
// Function: readFQB
void readFQB (FILE *f, int N, int chunkSize)
{
  int nReads = 0 ;	/* this group for statistics accumulation */
  U64 nHashes = 0 ;
  
  printf ("  reading and processing sorted fqb file with chunkSize %d", chunkSize) ;
  if (N) printf (", first %d records", N) ;
  printf ("\n") ;
  
  U32 *uBuf = new (chunkSize*30, U32) ; /* read and process readPairs in chunks */
  U32 *uStart = uBuf ;			/* beginning of records for current block */
  U32 barcode = 0 ;
  ClusterBlock *b = arrayp(clusterBlocks, 1, ClusterBlock) ; /* start at 1 */
  b->nRead = 0 ;
  while (!N || nReads < N)
    { if (b->nRead) { memmove (uBuf, uStart, 120*b->nRead) ; uStart = uBuf ; }

      U32 *u = &uBuf[30*b->nRead] ;
      int thisChunk = chunkSize - b->nRead ; if (thisChunk <= 0) die ("chunkSize too small") ;
      if (N && (nReads + thisChunk > N)) { thisChunk = N - nReads ; }
      int nRec = fread (u, 120, thisChunk, f) ;
      if (!nRec) { if (feof (f)) break ; else die ("file read problem") ; } /* loop exit here */
      
      int i ;
      if (!barcode) barcode = u[0] ; /* needed to start barcode matching */
      for (i = 0 ; i < nRec ; ++i)
	if (u[30*i] == barcode) ++b->nRead ;
	else
	  { processBlock (uStart, b) ;
	    nHashes += b->nHash ;
	    b = arrayp(clusterBlocks, arrayMax(clusterBlocks), ClusterBlock) ; b->nRead = 1 ;
	    barcode = u[30*i] ; uStart = &u[30*i] ;
	  }

      nReads += nRec ;
    }
  fclose (f) ;

  fprintf (outFile, "  read %d read pair records for %d barcodes, mean %.2f read pairs per barcode\n",
	  nReads, arrayMax(clusterBlocks)-1, nReads/(double)(arrayMax(clusterBlocks)-1)) ;
  fprintf (outFile, "  created %ld hashes, mean %.2f hashes per read pair, %.2f per barcode\n",
	  (long)nHashes, nHashes/(double)nReads, nHashes/(double)(arrayMax(clusterBlocks)-1)) ;
  if (outFile != stdin)
    { printf ("  read %d read pair records for %d barcodes, mean %.2f read pairs per barcode\n",
	  nReads, arrayMax(clusterBlocks)-1, nReads/(double)(arrayMax(clusterBlocks)-1)) ;
      printf ("  created %ld hashes, mean %.2f hashes per read pair, %.2f per barcode\n",
	  (long)nHashes, nHashes/(double)nReads, nHashes/(double)(arrayMax(clusterBlocks)-1)) ;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
movq $0x0, -0x20(%rbp)
movl -0x10(%rbp), %esi
leaq 0xc555(%rip), %rdi      # 0xe050
movb $0x0, %al
callq 0x10d0
cmpl $0x0, -0xc(%rbp)
je 0x1b19
movl -0xc(%rbp), %esi
leaq 0xc579(%rip), %rdi      # 0xe08b
movb $0x0, %al
callq 0x10d0
leaq 0xd04d(%rip), %rdi      # 0xeb6d
movb $0x0, %al
callq 0x10d0
imull $0x1e, -0x10(%rbp), %eax
movslq %eax, %rdi
shlq $0x2, %rdi
callq 0xd1a0
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movq 0x12877(%rip), %rdi     # 0x143c8
movl $0x1, %esi
callq 0xc640
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movl $0x0, (%rax)
movb $0x1, %al
cmpl $0x0, -0xc(%rbp)
movb %al, -0x55(%rbp)
je 0x1b80
movl -0x14(%rbp), %eax
cmpl -0xc(%rbp), %eax
setl %al
movb %al, -0x55(%rbp)
movb -0x55(%rbp), %al
testb $0x1, %al
jne 0x1b8c
jmp 0x1d10
movq -0x40(%rbp), %rax
cmpl $0x0, (%rax)
je 0x1bb5
movq -0x28(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x40(%rbp), %rax
imull $0x78, (%rax), %eax
movl %eax, %eax
movl %eax, %edx
callq 0x11d0
movq -0x28(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rax
movq -0x40(%rbp), %rcx
imull $0x1e, (%rcx), %ecx
movl %ecx, %ecx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movl -0x10(%rbp), %eax
movq -0x40(%rbp), %rcx
subl (%rcx), %eax
movl %eax, -0x4c(%rbp)
cmpl $0x0, -0x4c(%rbp)
jg 0x1bed
leaq 0xc4b8(%rip), %rdi      # 0xe09e
movb $0x0, %al
callq 0xd0c0
cmpl $0x0, -0xc(%rbp)
je 0x1c07
movl -0x14(%rbp), %eax
addl -0x4c(%rbp), %eax
cmpl -0xc(%rbp), %eax
jle 0x1c07
movl -0xc(%rbp), %eax
subl -0x14(%rbp), %eax
movl %eax, -0x4c(%rbp)
movq -0x48(%rbp), %rdi
movslq -0x4c(%rbp), %rdx
movq -0x8(%rbp), %rcx
movl $0x78, %esi
callq 0x10a0
movl %eax, -0x50(%rbp)
cmpl $0x0, -0x50(%rbp)
jne 0x1c49
movq -0x8(%rbp), %rdi
callq 0x1160
cmpl $0x0, %eax
je 0x1c39
jmp 0x1d10
leaq 0xc472(%rip), %rdi      # 0xe0b2
movb $0x0, %al
callq 0xd0c0
jmp 0x1c49
cmpl $0x0, -0x34(%rbp)
jne 0x1c58
movq -0x48(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x34(%rbp)
movl $0x0, -0x54(%rbp)
movl -0x54(%rbp), %eax
cmpl -0x50(%rbp), %eax
jge 0x1d02
movq -0x48(%rbp), %rax
imull $0x1e, -0x54(%rbp), %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
cmpl -0x34(%rbp), %eax
jne 0x1c8b
movq -0x40(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
jmp 0x1cf2
movq -0x30(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x1740
movq -0x40(%rbp), %rax
movl 0x4(%rax), %eax
addq -0x20(%rbp), %rax
movq %rax, -0x20(%rbp)
movq 0x1271a(%rip), %rdi     # 0x143c8
movq 0x12713(%rip), %rax     # 0x143c8
movl 0x18(%rax), %esi
callq 0xc640
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movl $0x1, (%rax)
movq -0x48(%rbp), %rax
imull $0x1e, -0x54(%rbp), %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x34(%rbp)
movq -0x48(%rbp), %rax
imull $0x1e, -0x54(%rbp), %ecx
movslq %ecx, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
jmp 0x1cf4
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x1c5f
movl -0x50(%rbp), %eax
addl -0x14(%rbp), %eax
movl %eax, -0x14(%rbp)
jmp 0x1b69
movq -0x8(%rbp), %rdi
callq 0x10b0
movq 0x126b0(%rip), %rdi     # 0x143d0
movl -0x14(%rbp), %edx
movq 0x1269e(%rip), %rax     # 0x143c8
movl 0x18(%rax), %ecx
decl %ecx
cvtsi2sd %edx, %xmm0
cvtsi2sd %ecx, %xmm1
divsd %xmm1, %xmm0
leaq 0xc382(%rip), %rsi      # 0xe0c4
movb $0x1, %al
callq 0x1150
movq 0x12680(%rip), %rdi     # 0x143d0
movq -0x20(%rbp), %rdx
movq %rdx, %xmm1
movaps 0xc2b0(%rip), %xmm0     # 0xe010
punpckldq %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
movapd 0xc2b4(%rip), %xmm0     # 0xe020
subpd %xmm0, %xmm1
movaps %xmm1, %xmm0
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm0, %xmm1
cvtsi2sdl -0x14(%rbp), %xmm2
movaps %xmm1, %xmm0
divsd %xmm2, %xmm0
movq 0x1263a(%rip), %rax     # 0x143c8
movl 0x18(%rax), %eax
subl $0x1, %eax
cvtsi2sd %eax, %xmm2
divsd %xmm2, %xmm1
leaq 0xc370(%rip), %rsi      # 0xe113
movb $0x2, %al
callq 0x1150
movq 0x1261f(%rip), %rax     # 0x143d0
movq 0x11220(%rip), %rcx     # 0x12fd8
cmpq (%rcx), %rax
je 0x1e44
movl -0x14(%rbp), %esi
movq 0x125fd(%rip), %rax     # 0x143c8
movl 0x18(%rax), %edx
decl %edx
cvtsi2sd %esi, %xmm0
cvtsi2sd %edx, %xmm1
divsd %xmm1, %xmm0
leaq 0xc2e1(%rip), %rdi      # 0xe0c4
movb $0x1, %al
callq 0x10d0
movq -0x20(%rbp), %rsi
movq %rsi, %xmm1
movaps 0xc216(%rip), %xmm0     # 0xe010
punpckldq %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
movapd 0xc21a(%rip), %xmm0     # 0xe020
subpd %xmm0, %xmm1
movaps %xmm1, %xmm0
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm0, %xmm1
cvtsi2sdl -0x14(%rbp), %xmm2
movaps %xmm1, %xmm0
divsd %xmm2, %xmm0
movq 0x125a0(%rip), %rax     # 0x143c8
movl 0x18(%rax), %eax
subl $0x1, %eax
cvtsi2sd %eax, %xmm2
divsd %xmm2, %xmm1
leaq 0xc2d6(%rip), %rdi      # 0xe113
movb $0x2, %al
callq 0x10d0
addq $0x60, %rsp
popq %rbp
retq
nopw (%rax,%rax)