// File: /workspace/github_c_makefile_star2_O1/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 $0xb8, %rsp
movq %rsi, %rax
movq %rdi, %r13
leaq 0x908f(%rip), %rsi      # 0xb730
xorl %r15d, %r15d
movl %r15d, 0x1b8(%rsi)
movl %r15d, 0x138(%rsi)
leaq 0x70(%rsp), %rdx
leaq 0x60(%rsp), %rcx
leaq 0xc(%rsp), %r9
movq %rax, 0xa8(%rsp)
movq %rax, %rdi
xorl %r8d, %r8d
callq 0x2df4
testl %eax, %eax
je 0x2d43
leaq 0xa0(%rsp), %r14
xorl %r15d, %r15d
movq %rax, 0x18(%rsp)
movq %rax, 0x10(%rsp)
movq %rax, 0x20(%rsp)
movq %r13, 0x38(%rsp)
movq (%r13), %rax
movq (%rax), %rdi
movq 0x70(%rsp), %rsi
movl 0xc(%rsp), %edx
callq 0x437a
movq %rax, %rbx
movq %r15, %rdi
movl $0x400, %esi            # imm = 0x400
movl $0x8, %edx
callq 0x5a38
movq %rax, %r15
movl $0x0, 0x8c(%rsp)
movq $0x0, 0x84(%rsp)
movq %rbx, %rdi
movq %r14, %rsi
leaq 0x6c(%rsp), %rdx
xorl %ecx, %ecx
callq 0x450c
movl $0x0, %ebp
testb %al, %al
je 0x27c0
xorl %ebp, %ebp
movq (%r13), %rdi
movq 0xa0(%rsp), %rsi
xorl %edx, %edx
callq 0x47f3
movl %eax, %r12d
movl 0x18(%r15), %esi
movq %r15, %rdi
callq 0x5c6f
movl %r12d, (%rax)
movl 0x6c(%rsp), %ecx
movl %ecx, 0x4(%rax)
testl %r12d, %r12d
je 0x27a8
movq (%r13), %rax
movq 0x38(%rax), %rax
movl %r12d, %ecx
movzbl (%rax,%rcx), %eax
andl $0x3, %eax
incl 0x80(%rsp,%rax,4)
jmp 0x27aa
incl %ebp
movq %rbx, %rdi
movq %r14, %rsi
leaq 0x6c(%rsp), %rdx
xorl %ecx, %ecx
callq 0x450c
testb %al, %al
jne 0x275c
movq %rbx, %rdi
callq 0x2149
movq 0x9b71(%rip), %rdi      # 0xc340
movq 0x60(%rsp), %rdx
movl 0xc(%rsp), %ecx
movl 0x84(%rsp), %ebx
movl 0x88(%rsp), %r10d
movl 0x8c(%rsp), %r11d
movl 0x18(%r15), %eax
cvtsi2sd %eax, %xmm1
subl %ebp, %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
divsd %xmm1, %xmm0
leaq 0x4b1e(%rip), %rsi      # 0x7329
movl %ebp, %r8d
movl %ebx, %r9d
movb $0x1, %al
pushq %r11
pushq %r10
callq 0x1120
addq $0x10, %rsp
cmpl $0x0, 0x18(%r15)
xorps %xmm0, %xmm0
cvtsi2sd %ebx, %xmm0
movsd %xmm0, 0x98(%rsp)
movq %r15, 0x58(%rsp)
jle 0x2bea
xorl %r13d, %r13d
xorl %r12d, %r12d
xorl %r10d, %r10d
movq 0x18(%rsp), %rbx
movq $0x0, 0x30(%rsp)
xorl %r9d, %r9d
movq 0x20(%rsp), %rdi
movq 0x8(%r15), %r14
movslq 0x14(%r15), %rax
movslq %r12d, %r15
imulq %rax, %r15
movl (%r14,%r15), %ecx
testq %rcx, %rcx
je 0x2891
movq 0x38(%rsp), %rdx
movq (%rdx), %rax
movq 0x38(%rax), %rax
movb (%rax,%rcx), %r11b
andb $0x3, %r11b
cmpb $0x3, %r11b
jne 0x289d
movl %ebx, %ebp
movq 0x58(%rsp), %r15
jmp 0x2bd3
movq 0x30(%rdx), %rax
movq 0x38(%rdx), %rdx
movl (%rdx,%rcx,4), %ecx
movl (%rax,%rcx,4), %ebp
cmpb $0x0, 0x9a86(%rip)      # 0xc338
je 0x29ba
movq %r10, 0x50(%rsp)
movq %r9, 0x40(%rsp)
movq %rdi, 0x20(%rsp)
movq %rbp, %rdx
movb %r11b, 0x48(%rsp)
cmpb $0x1, %r11b
movq %rbp, 0x18(%rsp)
jne 0x291e
movl 0x4(%r14,%r15), %eax
movl %eax, 0x28(%rsp)
movq 0x38(%rsp), %rbp
movq 0x20(%rbp), %rax
movq 0x40(%rbp), %rdi
movl (%rax,%rdx,4), %esi
callq 0x59a7
movq 0x18(%rbp), %rcx
movq 0x18(%rsp), %rbp
movl (%rcx,%rbp,4), %ecx
leaq 0x4a57(%rip), %rdi      # 0x7362
movl 0x28(%rsp), %esi
movq %rax, %rdx
xorl %eax, %eax
callq 0x10b0
jmp 0x29a6
incl %ecx
movl (%rax,%rcx,4), %eax
movq %rax, 0x28(%rsp)
movl 0x4(%r14,%r15), %eax
movl %eax, 0x7c(%rsp)
movq 0x38(%rsp), %rbp
movq 0x20(%rbp), %rax
movq 0x40(%rbp), %rdi
movl (%rax,%rdx,4), %esi
callq 0x59a7
movq %rax, 0xb0(%rsp)
movq 0x18(%rbp), %rax
movq 0x20(%rbp), %rcx
movq 0x18(%rsp), %rdx
movl (%rax,%rdx,4), %eax
movl %eax, 0x78(%rsp)
movq 0x40(%rbp), %rdi
movq 0x28(%rsp), %rax
movl (%rcx,%rax,4), %esi
callq 0x59a7
movq 0x18(%rbp), %rcx
movq 0x18(%rsp), %rbp
movq 0x28(%rsp), %rdx
movl (%rcx,%rdx,4), %r9d
leaq 0x49e3(%rip), %rdi      # 0x736f
movl 0x7c(%rsp), %esi
movq 0xb0(%rsp), %rdx
movl 0x78(%rsp), %ecx
movq %rax, %r8
xorl %eax, %eax
callq 0x10b0
movq 0x20(%rsp), %rdi
movq 0x40(%rsp), %r9
movq 0x50(%rsp), %r10
movb 0x48(%rsp), %r11b
movb $0x1, %al
movl %r10d, %r8d
testl %r10d, %r10d
je 0x2a14
movq 0x38(%rsp), %rcx
movq 0x20(%rcx), %rcx
movl (%rcx,%rbp,4), %edx
cmpl (%rcx,%r8,4), %edx
jne 0x2a14
cmpl %r10d, %ebx
jbe 0x29f1
cmpl %ebx, %ebp
setb %cl
movq 0x10(%rsp), %rax
subl %edi, %eax
addl %ebx, %eax
addl %r13d, %eax
addl $-0x33, %eax
jmp 0x2a08
jae 0x2a12
cmpl %ebx, %ebp
seta %cl
movq 0x10(%rsp), %rdx
subl %edi, %edx
subl %ebx, %edx
leal (%rdx,%r10), %eax
addl $-0x33, %eax
cmpl $-0x65, %eax
setb %al
orb %cl, %al
jmp 0x2a14
xorl %eax, %eax
cmpb $0x1, %r11b
je 0x2a89
testl %r10d, %r10d
je 0x2a89
testb %al, %al
je 0x2a89
movq 0x38(%rsp), %rdx
movq 0x20(%rdx), %rcx
movq 0x30(%rdx), %rax
movq 0x38(%rdx), %rdx
movl (%r14,%r15), %esi
movl (%rdx,%rsi,4), %edx
incl %edx
movl (%rax,%rdx,4), %ebp
movl (%rcx,%rbp,4), %edx
movb $0x1, %al
cmpl (%rcx,%r8,4), %edx
jne 0x2a89
cmpl %r10d, %ebx
jbe 0x2a66
cmpl %ebx, %ebp
setb %cl
movq 0x10(%rsp), %rax
subl %edi, %eax
addl %ebx, %eax
addl %r13d, %eax
addl $-0x33, %eax
jmp 0x2a7d
jae 0x2a87
cmpl %ebx, %ebp
seta %cl
movq 0x10(%rsp), %rdx
subl %edi, %edx
subl %ebx, %edx
leal (%rdx,%r10), %eax
addl $-0x33, %eax
cmpl $-0x65, %eax
setb %al
orb %cl, %al
jmp 0x2a89
xorl %eax, %eax
testb %al, %al
je 0x2ba9
xorl %ecx, %ecx
cmpl $0x3, %r9d
movq 0x58(%rsp), %r15
jl 0x2b93
movl %r10d, %eax
subl %ebx, %eax
negl %eax
subl %ebx, %r10d
movq 0x988d(%rip), %rcx      # 0xc340
movq %rcx, 0x20(%rsp)
movq 0x60(%rsp), %rcx
movq %rcx, 0x18(%rsp)
movq 0x8(%r15), %rcx
movl 0x14(%r15), %edx
cmovbl %eax, %r10d
movq %r10, 0x50(%rsp)
movq 0x10(%rsp), %rax
imull %edx, %eax
movl 0x4(%rcx,%rax), %eax
movl %eax, 0x10(%rsp)
imull %edx, %edi
movl 0x4(%rcx,%rdi), %eax
movl %eax, 0x40(%rsp)
movl 0xc(%rsp), %eax
movl %eax, 0x28(%rsp)
movq 0x38(%rsp), %r15
movq 0x20(%r15), %rax
movq 0x40(%r15), %rdi
movq %r8, %r14
movl (%rax,%r8,4), %esi
movq %r9, %r13
movb %r11b, 0x48(%rsp)
callq 0x59a7
movq %rax, %r10
movq 0x18(%r15), %rax
movq 0x58(%rsp), %r15
movl (%rax,%r14,4), %r11d
movl %ebx, %ecx
movl (%rax,%rcx,4), %ebx
movq 0x30(%rsp), %r14
leal (%r14,%r13), %eax
cvtsi2sd %eax, %xmm0
cvtsi2sdq 0x50(%rsp), %xmm1
divsd %xmm1, %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %r13d, %xmm1
divsd 0x98(%rsp), %xmm1
subq $0x8, %rsp
movq 0x28(%rsp), %rdi
leaq 0x481d(%rip), %rsi      # 0x7382
movq 0x20(%rsp), %rdx
movl 0x18(%rsp), %ecx
movl 0x48(%rsp), %r8d
movl 0x30(%rsp), %r9d
movb $0x2, %al
pushq %r14
pushq %r13
pushq %rbx
pushq %r11
pushq %r10
callq 0x1120
xorl %ecx, %ecx
movb 0x78(%rsp), %r11b
addq $0x30, %rsp
movq $0x0, 0x30(%rsp)
movl %r12d, %eax
movq %rax, 0x10(%rsp)
movl %ebp, %r10d
jmp 0x2bb1
movl %r9d, %ecx
movq 0x58(%rsp), %r15
xorl %eax, %eax
xorl %r9d, %r9d
cmpb $0x1, %r11b
setne %al
sete %r9b
addl %ecx, %r9d
movq 0x30(%rsp), %rcx
addl %eax, %ecx
movq %rcx, 0x30(%rsp)
movl %r12d, %edi
incl %r12d
movl %r10d, %r13d
negl %r13d
movl %ebp, %ebx
cmpl 0x18(%r15), %r12d
jl 0x285f
jmp 0x2c03
xorl %r9d, %r9d
movq $0x0, 0x30(%rsp)
xorl %r10d, %r10d
movq 0x18(%rsp), %rbp
movq 0x20(%rsp), %rdi
movq %rdi, 0x20(%rsp)
cmpl $0x3, 0x30(%rsp)
movq 0x38(%rsp), %r13
movq %rbp, 0x18(%rsp)
jl 0x2cf9
movl %r10d, %eax
subl %ebp, %eax
negl %eax
movl %r10d, %r14d
subl %ebp, %r14d
movq 0x970f(%rip), %rcx      # 0xc340
movq %rcx, 0x48(%rsp)
movq 0x60(%rsp), %rcx
movq %rcx, 0x50(%rsp)
movq 0x8(%r15), %rcx
movl 0x14(%r15), %edx
cmovbl %eax, %r14d
movl %edx, %eax
imull 0x10(%rsp), %eax
movl 0x4(%rcx,%rax), %eax
movl %eax, 0x40(%rsp)
imull 0x20(%rsp), %edx
movl 0x4(%rcx,%rdx), %ebp
movl 0xc(%rsp), %eax
movl %eax, 0x28(%rsp)
movq 0x20(%r13), %rax
movq 0x40(%r13), %rdi
movl %r10d, %r15d
movl (%rax,%r15,4), %esi
movq 0x30(%rsp), %r12
movq %r9, %rbx
callq 0x59a7
movq %rax, %r10
movq 0x18(%r13), %rax
movl (%rax,%r15,4), %r11d
movl 0x18(%rsp), %ecx
movl (%rax,%rcx,4), %r15d
leal (%r12,%rbx), %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
cvtsi2sd %r14, %xmm1
divsd %xmm1, %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %ebx, %xmm1
divsd 0x98(%rsp), %xmm1
subq $0x8, %rsp
movq 0x50(%rsp), %rdi
leaq 0x46b3(%rip), %rsi      # 0x7382
movq 0x58(%rsp), %rdx
movl 0x48(%rsp), %ecx
movl %ebp, %r8d
movl 0x30(%rsp), %r9d
movb $0x2, %al
pushq %r12
pushq %rbx
pushq %r15
movq 0x78(%rsp), %r15
pushq %r11
pushq %r10
callq 0x1120
addq $0x30, %rsp
movq 0x70(%rsp), %rdi
callq 0x1040
movq 0x60(%rsp), %rdi
callq 0x1040
movq 0xa8(%rsp), %rdi
leaq 0x8a14(%rip), %rsi      # 0xb730
leaq 0x70(%rsp), %rdx
leaq 0x60(%rsp), %rcx
xorl %r8d, %r8d
leaq 0xc(%rsp), %r9
callq 0x2df4
testl %eax, %eax
leaq 0xa0(%rsp), %r14
jne 0x26fb
movq %r15, %rdi
callq 0x5b0d
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq