// File: /workspace/github_c_makefile_star2_O2/richarddurbin[P]hash10x/moshmap.c
// Function: queryProcess
void queryProcess (Reference *ref, FILE *f)
{
  char *seq, *seqName ;
  int len ;
  Array seeds = 0 ;

  dna2indexConv['N'] = dna2indexConv['n'] = 0 ; /* to get 2-bit encoding */
  while (readSequence (f, dna2indexConv, &seq, &seqName, 0, &len))
    { SeqhashRCiterator *mi = moshRCiterator (ref->ms->hasher, seq, len) ;
      U64 hash ; int pos ;
      seeds = arrayReCreate (seeds, 1024, Seed) ;
      int missed = 0, copy[4] ; copy[1] = copy[2] = copy[3] = 0 ;
      while (moshRCnext (mi, &hash, &pos, 0))
	{ U32 index = moshsetIndexFind (ref->ms, hash, FALSE) ;
	  Seed *s = arrayp(seeds,arrayMax(seeds),Seed) ;
	  s->index = index ; s->pos = pos ;
	  if (index) ++copy[msCopy(ref->ms,index)] ;
	  else ++missed ;
	}
      seqhashRCiteratorDestroy (mi) ;
      fprintf (outFile, "Q\t%s\t%d\t%d miss, %d copy1, %d copy2, %d multi, %.2f hit\n",
	       seqName, len, missed, copy[1], copy[2], copy[3],
	       (arrayMax(seeds)-missed)/(double)(arrayMax(seeds))) ;

      int i ;
      U32 loc0 = 0, locN, i0, iN ;
      int n1 = 0, n2 = 0 ;
      for (i = 0 ; i < arrayMax(seeds) ; ++i)
	{ Seed *s = arrp (seeds, i, Seed) ;
	  if (s->index && !msIsCopyM(ref->ms,s->index)) /* ignore multi-hits for now */
	    { U32 loc = ref->rev[ref->loc[s->index]] ;
	      BOOL is1 = msIsCopy1(ref->ms,s->index) ;
	      if (isVerbose)
		{ if (is1)
		    printf ("  %6d\t%s %d\n", s->pos,
			    dictName(ref->dict,ref->id[loc]), ref->offset[loc]) ;
		  else
		    { U32 loc2 = ref->rev[ref->loc[s->index]+1] ;
		      printf ("  %6d\t%s %d\t%s %d\n", s->pos,
			      dictName(ref->dict,ref->id[loc]), ref->offset[loc],
			      dictName(ref->dict,ref->id[loc2]), ref->offset[loc2]) ;
		    }
		}
	      BOOL endBlock = FALSE ;
	      if (!loc0 || ref->id[loc] != ref->id[loc0]) endBlock = TRUE ;
	      else if (loc0 < locN)
		{ if (loc < locN) endBlock = TRUE ;
		  int d = locN - loc0 - iN + i0 ; if (d > 50 || d < -50) endBlock = TRUE ;
		}
	      else if (loc0 > locN)
		{ if (loc > locN) endBlock = TRUE ;
		  int d = loc0 - locN - iN + i0 ; if (d > 50 || d < -50) endBlock = TRUE ;
		}
	      if (endBlock && loc0 && !is1) /* try the second loc */
		{ loc = ref->rev[ref->loc[s->index]+1] ;
		  endBlock = FALSE ;
		  if (ref->id[loc] != ref->id[loc0]) endBlock = TRUE ;
		   else if (loc0 < locN)
		     { if (loc < locN) endBlock = TRUE ;
		       int d = locN - loc0 - iN + i0 ; if (d > 50 || d < -50) endBlock = TRUE ;
		     }
		   else if (loc0 > locN)
		     { if (loc > locN) endBlock = TRUE ;
		       int d = loc0 - locN - iN + i0 ; if (d > 50 || d < -50) endBlock = TRUE ;
		     }
		}
	      if (endBlock)
		{ if (n1 > 2)
		    fprintf (outFile, "M\t%s\t%d\t%d\t%d\t%s\t%d\t%d\t%d %d\t%.2f\t%.2f\n",
			     seqName, arrp(seeds,i0,Seed)->pos, arrp(seeds,iN,Seed)->pos, len,
			     dictName(ref->dict,ref->id[loc0]),
			     ref->offset[loc0], ref->offset[locN],
			     n1, n2, (n1+n2) / (double)((locN>loc0) ? (locN-loc0) : (loc0-locN)),
			     n1 / (double)copy[1]) ;
		  n1 = 0 ; n2 = 0 ; loc0 = loc ; i0 = i ;
		}
	      if (is1) ++n1 ; else ++n2 ; locN = loc ; iN = i ;
	    }
	}
      if (n2 > 2)
	fprintf (outFile, "M\t%s\t%d\t%d\t%d\t%s\t%d\t%d\t%d %d\t%.2f\t%.2f\n",
		 seqName, arrp(seeds,i0,Seed)->pos, arrp(seeds,iN,Seed)->pos, len,
		 dictName(ref->dict,ref->id[loc0]),
		 ref->offset[loc0], ref->offset[locN],
		 n1, n2, (n1+n2) / (double)((locN>loc0) ? (locN-loc0) : (loc0-locN)),
		 n1 / (double)copy[1]) ;

      free (seq) ; free (seqName) ;
    }

  arrayDestroy (seeds) ;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
leaq 0x8a2b(%rip), %rax      # 0xa730
andl $0x0, 0x1b8(%rax)
movq %rsi, 0xc0(%rsp)
andl $0x0, 0x138(%rax)
movq %rdi, %rbx
leaq 0xb0(%rsp), %r15
leaq 0x6c(%rsp), %r13
movq %rax, 0x28(%rsp)
movq %rax, 0x8(%rsp)
movq %rax, 0x20(%rsp)
xorl %ebp, %ebp
movq %rdi, 0x30(%rsp)
movq 0xc0(%rsp), %rdi
leaq 0x89e0(%rip), %rsi      # 0xa730
leaq 0xb8(%rsp), %rdx
leaq 0x70(%rsp), %rcx
xorl %r8d, %r8d
leaq 0x1c(%rsp), %r9
callq 0x2b58
testl %eax, %eax
je 0x23a8
movq (%rbx), %rax
movq (%rax), %rdi
movq 0xb8(%rsp), %rsi
movl 0x1c(%rsp), %edx
callq 0x3efd
movq %rbp, %rdi
movq %rax, %rbp
movl $0x400, %esi            # imm = 0x400
pushq $0x8
popq %rdx
callq 0x5457
movq %rax, 0x60(%rsp)
andl $0x0, 0x9c(%rsp)
andq $0x0, 0x94(%rsp)
xorl %r14d, %r14d
movq %rbp, %rdi
movq %r15, %rsi
movq %r13, %rdx
xorl %ecx, %ecx
callq 0x4025
testb %al, %al
je 0x1e19
movq (%rbx), %rdi
movq 0xb0(%rsp), %rsi
xorl %edx, %edx
callq 0x428f
movl %eax, %r12d
movq 0x60(%rsp), %rdi
movl 0x18(%rdi), %esi
callq 0x5674
movl %r12d, (%rax)
movl 0x6c(%rsp), %ecx
movl %ecx, 0x4(%rax)
testl %r12d, %r12d
je 0x1e14
movq (%rbx), %rax
movq 0x38(%rax), %rax
movl %r12d, %ecx
movzbl (%rax,%rcx), %eax
andl $0x3, %eax
incl 0x90(%rsp,%rax,4)
jmp 0x1db5
incl %r14d
jmp 0x1db5
movq %rbp, %rdi
callq 0x17e3
movq 0x9520(%rip), %rdi      # 0xb348
movq 0x70(%rsp), %rdx
movl 0x1c(%rsp), %ecx
movl 0x94(%rsp), %ebp
movl 0x98(%rsp), %r10d
movl 0x9c(%rsp), %r11d
movq 0x60(%rsp), %rbx
movl 0x18(%rbx), %eax
cvtsi2sd %eax, %xmm1
subl %r14d, %eax
cvtsi2sd %eax, %xmm0
divsd %xmm1, %xmm0
leaq 0x44c3(%rip), %rsi      # 0x6329
movl %r14d, %r8d
movl %ebp, %r9d
movb $0x1, %al
pushq %r11
pushq %r10
callq 0x1120
addq $0x10, %rsp
cvtsi2sd %ebp, %xmm0
movsd %xmm0, 0xa8(%rsp)
movq %rbx, %rbp
xorl %r10d, %r10d
movq $0x0, 0x50(%rsp)
xorl %r11d, %r11d
xorl %r12d, %r12d
movq 0x28(%rsp), %r8
movq 0x20(%rsp), %r9
movl %r11d, %r13d
movl %r9d, %edi
cvtsi2sd %r10d, %xmm0
cmpl 0x18(%rbp), %r12d
jge 0x2271
movq 0x8(%rbp), %r15
movslq 0x14(%rbp), %rax
movslq %r12d, %rbx
imulq %rax, %rbx
movl (%r15,%rbx), %ecx
testq %rcx, %rcx
je 0x2269
movq 0x30(%rsp), %rdx
movq (%rdx), %rax
movq 0x38(%rax), %rax
movb (%rax,%rcx), %sil
andb $0x3, %sil
cmpb $0x3, %sil
je 0x2269
movq %rdi, 0x78(%rsp)
movq 0x30(%rdx), %rax
movq 0x38(%rdx), %rdx
movl (%rdx,%rcx,4), %ecx
movl (%rax,%rcx,4), %edi
cmpb $0x0, 0x9430(%rip)      # 0xb340
movsd %xmm0, 0x80(%rsp)
movb %sil, 0x10(%rsp)
je 0x2035
movq %rdi, %r14
movq %r11, 0x40(%rsp)
movq %r10, 0x48(%rsp)
movq %r9, 0x20(%rsp)
movq %r8, 0x28(%rsp)
cmpb $0x1, %sil
jne 0x1f85
movl 0x4(%r15,%rbx), %eax
movl %eax, 0x3c(%rsp)
movq 0x30(%rsp), %rbp
movq 0x20(%rbp), %rax
movq 0x40(%rbp), %rdi
movl (%rax,%r14,4), %esi
callq 0x53cd
movq 0x18(%rbp), %rcx
movl (%rcx,%r14,4), %ecx
leaq 0x43f3(%rip), %rdi      # 0x6362
movl 0x3c(%rsp), %esi
movq %rax, %rdx
xorl %eax, %eax
callq 0x10b0
movq %r14, %rdi
jmp 0x2017
incl %ecx
movl (%rax,%rcx,4), %eax
movq %rax, 0xc8(%rsp)
movl 0x4(%r15,%rbx), %eax
movl %eax, 0x3c(%rsp)
movq 0x30(%rsp), %rbp
movq 0x20(%rbp), %rax
movq 0x40(%rbp), %rdi
movl (%rax,%r14,4), %esi
movq %r14, 0x58(%rsp)
callq 0x53cd
movq %rax, 0xd0(%rsp)
movq 0x18(%rbp), %rax
movq 0x20(%rbp), %rcx
movl (%rax,%r14,4), %eax
movl %eax, 0x8c(%rsp)
movq 0x40(%rbp), %rdi
movq 0xc8(%rsp), %r14
movl (%rcx,%r14,4), %esi
callq 0x53cd
movq 0x18(%rbp), %rcx
movl (%rcx,%r14,4), %r9d
leaq 0x437a(%rip), %rdi      # 0x636f
movl 0x3c(%rsp), %esi
movq 0xd0(%rsp), %rdx
movl 0x8c(%rsp), %ecx
movq %rax, %r8
xorl %eax, %eax
callq 0x10b0
movq 0x58(%rsp), %rdi
movq 0x60(%rsp), %rbp
movq 0x28(%rsp), %r8
movq 0x20(%rsp), %r9
movq 0x48(%rsp), %r10
movq 0x40(%rsp), %r11
movb 0x10(%rsp), %sil
testl %r11d, %r11d
je 0x2131
movq 0x30(%rsp), %rax
movq 0x20(%rax), %rax
movl (%rax,%r13,4), %ecx
movb $0x1, %dl
cmpl %ecx, (%rax,%rdi,4)
jne 0x20aa
cmpl %r11d, %r9d
jbe 0x2077
cmpl %r9d, %edi
setb %r14b
movq 0x8(%rsp), %rdx
addl %r9d, %edx
movq %rdi, %rsi
subl %r8d, %edx
subl %r11d, %edx
movq %rsi, %rdi
addl $-0x33, %edx
jmp 0x209c
jae 0x2241
cmpl %r9d, %edi
seta %r14b
movq %rdi, %rsi
movq 0x8(%rsp), %rdi
subl %r8d, %edi
subl %r9d, %edi
leal (%rdi,%r11), %edx
addl $-0x33, %edx
movq %rsi, %rdi
cmpl $-0x65, %edx
setb %dl
orb %r14b, %dl
movb 0x10(%rsp), %sil
cmpb $0x1, %sil
je 0x2129
testb %dl, %dl
je 0x2129
movq 0x30(%rsp), %rsi
movq 0x30(%rsi), %rdx
movq 0x38(%rsi), %rsi
movl (%r15,%rbx), %edi
movl (%rsi,%rdi,4), %esi
incl %esi
movl (%rdx,%rsi,4), %edi
cmpl %ecx, (%rax,%rdi,4)
jne 0x20fa
cmpl %r11d, %r9d
jbe 0x2101
cmpl %r9d, %edi
setb %dl
movq 0x8(%rsp), %rax
addl %r9d, %eax
subl %r8d, %eax
subl %r11d, %eax
addl $-0x33, %eax
cmpl $-0x65, %eax
movb 0x10(%rsp), %sil
jae 0x2129
jmp 0x2131
movb 0x10(%rsp), %sil
jmp 0x2131
movb 0x10(%rsp), %sil
jae 0x2241
cmpl %r9d, %edi
seta %dl
movq 0x8(%rsp), %rcx
subl %r8d, %ecx
subl %r9d, %ecx
leal (%rcx,%r11), %eax
addl $-0x33, %eax
cmpl $-0x65, %eax
jb 0x2131
testb %dl, %dl
je 0x2241
xorl %edx, %edx
cmpl $0x3, %r10d
jl 0x2232
movl %r11d, %eax
subl %r9d, %eax
negl %eax
subl %r9d, %r11d
movq 0x91f9(%rip), %rcx      # 0xb348
movq %rcx, 0x20(%rsp)
movq 0x70(%rsp), %rcx
movq %rcx, 0x28(%rsp)
movq 0x8(%rbp), %rcx
movl 0x14(%rbp), %edx
cmovbl %eax, %r11d
movq 0x8(%rsp), %rax
imull %edx, %eax
movl 0x4(%rcx,%rax), %eax
movl %eax, 0x8(%rsp)
imull %edx, %r8d
movl 0x4(%rcx,%r8), %eax
movl %eax, 0x48(%rsp)
movl 0x1c(%rsp), %eax
movl %eax, 0x40(%rsp)
movq 0x30(%rsp), %r15
movq 0x20(%r15), %rax
movq %rdi, 0x58(%rsp)
movq 0x40(%r15), %rdi
movl (%rax,%r13,4), %esi
movq %r10, %r14
movq %r11, %rbx
callq 0x53cd
movq %rax, %r10
movq 0x18(%r15), %rax
movl (%rax,%r13,4), %r11d
movq 0x78(%rsp), %rcx
movl (%rax,%rcx,4), %r13d
movq 0x50(%rsp), %r15
leal (%r15,%r14), %eax
cvtsi2sd %eax, %xmm0
cvtsi2sd %rbx, %xmm1
divsd %xmm1, %xmm0
movsd 0x80(%rsp), %xmm1
divsd 0xa8(%rsp), %xmm1
subq $0x8, %rsp
movq 0x28(%rsp), %rdi
leaq 0x4187(%rip), %rsi      # 0x6382
movq 0x30(%rsp), %rdx
movl 0x10(%rsp), %ecx
movl 0x50(%rsp), %r8d
movl 0x48(%rsp), %r9d
movb $0x2, %al
pushq %r15
pushq %r14
pushq %r13
pushq %r11
pushq %r10
callq 0x1120
xorl %edx, %edx
movq 0x88(%rsp), %rdi
movb 0x40(%rsp), %sil
addq $0x30, %rsp
xorl %ecx, %ecx
movl %r12d, %eax
movq %rax, 0x8(%rsp)
movl %edi, %r11d
jmp 0x2249
movl %r10d, %edx
movq 0x50(%rsp), %rcx
xorl %eax, %eax
xorl %r10d, %r10d
cmpb $0x1, %sil
setne %al
sete %r10b
addl %edx, %r10d
addl %eax, %ecx
movq %rcx, 0x50(%rsp)
movl %r12d, %r8d
movl %edi, %r9d
incl %r12d
jmp 0x1ea7
movq %r9, 0x20(%rsp)
movq %r8, 0x28(%rsp)
movq 0x50(%rsp), %r8
cmpl $0x3, %r8d
jl 0x237a
movl %r11d, %eax
movq 0x20(%rsp), %rcx
subl %ecx, %eax
negl %eax
subl %ecx, %r11d
movq 0x90a8(%rip), %rcx      # 0xb348
movq %rcx, 0x78(%rsp)
movq 0x70(%rsp), %rcx
movq %rcx, 0x10(%rsp)
movq 0x8(%rbp), %rcx
movl 0x14(%rbp), %edx
cmovbl %eax, %r11d
movl %edx, %eax
imull 0x8(%rsp), %eax
movl 0x4(%rcx,%rax), %eax
movl %eax, 0x58(%rsp)
imull 0x28(%rsp), %edx
movl 0x4(%rcx,%rdx), %eax
movl %eax, 0x48(%rsp)
movl 0x1c(%rsp), %eax
movl %eax, 0x40(%rsp)
movq 0x30(%rsp), %rbx
movq 0x20(%rbx), %rax
movq %rdi, %r14
movq 0x40(%rbx), %rdi
movl (%rax,%r13,4), %esi
movq %r8, %r15
movq %r10, %r12
movq %r11, %rbp
movsd %xmm0, 0x80(%rsp)
callq 0x53cd
movq %rax, %r10
movq 0x18(%rbx), %rax
movl (%rax,%r13,4), %r11d
movl (%rax,%r14,4), %ebx
leal (%r15,%r12), %eax
cvtsi2sd %eax, %xmm0
cvtsi2sd %rbp, %xmm1
divsd %xmm1, %xmm0
movsd 0x80(%rsp), %xmm1
divsd 0xa8(%rsp), %xmm1
subq $0x8, %rsp
movq 0x80(%rsp), %rdi
leaq 0x4034(%rip), %rsi      # 0x6382
movq 0x18(%rsp), %rdx
movl 0x60(%rsp), %ecx
movl 0x50(%rsp), %r8d
movl 0x48(%rsp), %r9d
movq 0x68(%rsp), %rbp
movb $0x2, %al
pushq %r15
pushq %r12
pushq %rbx
pushq %r11
pushq %r10
callq 0x1120
addq $0x30, %rsp
movq 0xb8(%rsp), %rdi
callq 0x1040
movq 0x70(%rsp), %rdi
callq 0x1040
movq 0x30(%rsp), %rbx
leaq 0xb0(%rsp), %r15
leaq 0x6c(%rsp), %r13
jmp 0x1d41
movq %rbp, %rdi
callq 0x551c
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq