// File: /workspace/github_cpp_makefile_star2_O2/ncbi[P]amr/alignment.cpp
// Function: Alignment_sp::Alignment::refMutation2refSeq_pos()
size_t Alignment::refMutation2refSeq_pos ()
{
  ASSERT (! refMutation. empty ());
  
  if (   refMutation. pos_real < refStart
      || refMutation. pos_real + refMutation. allele. size () > refEnd
     )
    return no_index;
    
  size_t pos = refStart;
  size_t frameshift_i = no_index;
	size_t i = 0;
	while (i < refSeq. size ())
	{
	  ASSERT (pos <= refMutation. pos_real);
	  if (refSeq [i] != '-')
	  {
      if (pos == refMutation. pos_real)
      {
        if (   refSeq.    substr (i, refMutation. allele. size ()) == refMutation. allele
            && targetSeq. substr (i, refMutation. allele. size ()) == refMutation. allele
            && (pos == 0 || (i > 0 && refSeq [i - 1] == targetSeq [i - 1]))
           )
        {
          if (refMutation. frameshift != no_index) 
          {
            frameshift_i = i;
            i += refMutation. allele. size ();
            pos = refMutation. getStop ();
            break;
          }
          const size_t alignStop = i   + refMutation. allele. size ();
          const size_t refStop   = pos + refMutation. allele. size ();
          ASSERT (alignStop <= refSeq. size ());
          if (refStop == refLen || refSeq [alignStop] == targetSeq [alignStop])
            return i;
        }
        return no_index;
      }
  	  pos++;
    }
    i++;
	}

	while (i < refSeq. size ())
	{
	  ASSERT (frameshift_i != no_index);
	  if (refSeq [i] != '-')
	  {
	  #if 0
	    PRINT (i);
	    PRINT (pos);
	    PRINT (refMutation. getStop ());
	    PRINT (refMutation. frameshift);
	    PRINT (refSeq    [i]);
	    PRINT (targetSeq [i]);	    
	  #endif
	    ASSERT (refMutation. getStop ());
	    if (pos == refMutation. getStop () - 1 + refMutation. frameshift)
	    {
	      if (   refSeq    [i] == '*'
	          && targetSeq [i] == '*'
	         )
	        return frameshift_i;
	      return no_index;
	    } 
  	  pos++;
    }
    i++;
	}

  return no_index;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
movq %rdi, %r14
callq 0xc070
andl $0x0, (%rax)
cmpq $0x0, 0xe8(%r14)
je 0x439aa
movq %rax, %r15
movq 0xb8(%r14), %rax
movq 0xd8(%r14), %rbp
pushq $-0x1
popq %r12
cmpq %rax, %rbp
jb 0x43685
movq 0x128(%r14), %rcx
leaq (%rcx,%rbp), %rdx
cmpq 0xc0(%r14), %rdx
ja 0x43685
leaq 0x120(%r14), %r8
leaq 0x98(%r14), %rsi
movq 0x98(%r14), %rdi
movq 0xa0(%r14), %rdx
xorl %ebx, %ebx
cmpq %rbx, %rdx
je 0x4355d
andl $0x0, (%r15)
cmpq %rbp, %rax
ja 0x4372e
cmpb $0x2d, (%rdi,%rbx)
je 0x43558
cmpq %rbp, %rax
je 0x435bc
incq %rax
incq %rbx
jmp 0x43538
movq 0xd8(%r14), %r8
movq 0x108(%r14), %r9
movq 0x168(%r14), %rdi
pushq $-0x1
popq %rbx
movq %rdx, %rcx
addq %r8, %r9
leaq (%rdi,%r9), %r8
decq %r8
movq (%rsi), %rdi
cmpq %rdx, %rcx
jae 0x43685
andl $0x0, (%r15)
cmpq $-0x1, %rbx
je 0x43802
cmpb $0x2d, (%rdi,%rcx)
je 0x435b7
testq %r9, %r9
je 0x438d6
cmpq %r8, %rax
je 0x4365f
incq %rax
incq %rcx
jmp 0x43585
movq %r8, 0x28(%rsp)
leaq 0x8(%rsp), %r13
movq %r13, %rdi
movq %rsi, 0x50(%rsp)
movq %rbx, %rdx
callq 0xc5f0
movq %r13, %rdi
movq 0x28(%rsp), %rsi
callq 0x2a27e
testb %al, %al
je 0x4367b
leaq 0x30(%r14), %r13
movq 0x128(%r14), %rcx
leaq 0x30(%rsp), %rdi
movq %r13, %rsi
movq %rbx, %rdx
callq 0xc5f0
leaq 0x30(%rsp), %rdi
movq 0x28(%rsp), %rsi
callq 0x2a27e
testb %al, %al
movq 0x50(%rsp), %rax
je 0x43671
testq %rbp, %rbp
je 0x4369d
testq %rbx, %rbx
je 0x43671
movq (%rax), %rax
movb -0x1(%rax,%rbx), %al
movb %al, 0x28(%rsp)
movq (%r13), %rax
movb -0x1(%rax,%rbx), %al
movb %al, 0x7(%rsp)
leaq 0x30(%rsp), %rdi
callq 0xcbe8
leaq 0x8(%rsp), %rdi
callq 0xcbe8
movb 0x7(%rsp), %al
cmpb %al, 0x28(%rsp)
jne 0x43685
jmp 0x436b1
cmpb $0x2a, (%rdi,%rcx)
jne 0x43685
movq 0x30(%r14), %rax
cmpb $0x2a, (%rax,%rcx)
jne 0x43685
jmp 0x43688
leaq 0x30(%rsp), %rdi
callq 0xcbe8
leaq 0x8(%rsp), %rdi
callq 0xcbe8
movq %r12, %rbx
movq %rbx, %rax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x30(%rsp), %rdi
callq 0xcbe8
leaq 0x8(%rsp), %rdi
callq 0xcbe8
movq 0x128(%r14), %rax
movq 0x168(%r14), %rdi
leaq (%rax,%rbx), %rcx
cmpq $-0x1, %rdi
je 0x436ec
movq 0xa0(%r14), %rdx
movq 0xd8(%r14), %r8
movq 0x108(%r14), %r9
leaq (%r9,%r8), %rax
movq 0x50(%rsp), %rsi
jmp 0x43578
andl $0x0, (%r15)
cmpq 0xa0(%r14), %rcx
movq 0x50(%rsp), %rcx
ja 0x43a7e
addq %rax, %rbp
cmpq 0xc8(%r14), %rbp
je 0x43688
movq (%rcx), %rcx
addq %rax, %rcx
movb (%rbx,%rcx), %cl
addq (%r13), %rax
cmpb (%rbx,%rax), %cl
pushq $-0x1
popq %rax
cmovneq %rax, %rbx
jmp 0x43688
callq 0xc6d0
testl %eax, %eax
jne 0x43b52
leaq 0x1e8a6(%rip), %rsi     # 0x61fe8
leaq 0xb8(%rsp), %rdi
leaq 0x6(%rsp), %rdx
callq 0xdbbe
leaq 0x98(%rsp), %rdi
movl $0x379, %esi            # imm = 0x379
callq 0xe2d5
leaq 0xd8(%rsp), %rdi
leaq 0xb8(%rsp), %rsi
leaq 0x98(%rsp), %rdx
callq 0xe26e
leaq 0x1aa47(%rip), %rdx     # 0x5e1d1
leaq 0xf8(%rsp), %rdi
leaq 0xd8(%rsp), %rsi
callq 0xe24f
leaq 0x1f1da(%rip), %rsi     # 0x62980
leaq 0x58(%rsp), %rdi
leaq 0x5(%rsp), %rdx
callq 0xdbbe
leaq 0x1b110(%rip), %rdx     # 0x5e8cc
leaq 0x78(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0xe24f
leaq 0x30(%rsp), %rdi
leaq 0xf8(%rsp), %rsi
leaq 0x78(%rsp), %rdx
callq 0xe26e
leaq 0x1f1e8(%rip), %rdx     # 0x629d1
leaq 0x8(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0xe24f
leaq 0x8(%rsp), %rdi
callq 0x101d0
callq 0xc6d0
testl %eax, %eax
jne 0x43b52
leaq 0x1e7d2(%rip), %rsi     # 0x61fe8
leaq 0xb8(%rsp), %rdi
leaq 0x6(%rsp), %rdx
callq 0xdbbe
leaq 0x98(%rsp), %rdi
movl $0x399, %esi            # imm = 0x399
callq 0xe2d5
leaq 0xd8(%rsp), %rdi
leaq 0xb8(%rsp), %rsi
leaq 0x98(%rsp), %rdx
callq 0xe26e
leaq 0x1a973(%rip), %rdx     # 0x5e1d1
leaq 0xf8(%rsp), %rdi
leaq 0xd8(%rsp), %rsi
callq 0xe24f
leaq 0x1f106(%rip), %rsi     # 0x62980
leaq 0x58(%rsp), %rdi
leaq 0x5(%rsp), %rdx
callq 0xdbbe
leaq 0x1b03c(%rip), %rdx     # 0x5e8cc
leaq 0x78(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0xe24f
leaq 0x30(%rsp), %rdi
leaq 0xf8(%rsp), %rsi
leaq 0x78(%rsp), %rdx
callq 0xe26e
leaq 0x1f14e(%rip), %rdx     # 0x62a0b
leaq 0x8(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0xe24f
leaq 0x8(%rsp), %rdi
callq 0x101d0
callq 0xc6d0
testl %eax, %eax
jne 0x43b52
leaq 0x1e6fe(%rip), %rsi     # 0x61fe8
leaq 0xb8(%rsp), %rdi
leaq 0x6(%rsp), %rdx
callq 0xdbbe
leaq 0x98(%rsp), %rdi
movl $0x3a4, %esi            # imm = 0x3A4
callq 0xe2d5
leaq 0xd8(%rsp), %rdi
leaq 0xb8(%rsp), %rsi
leaq 0x98(%rsp), %rdx
callq 0xe26e
leaq 0x1a89f(%rip), %rdx     # 0x5e1d1
leaq 0xf8(%rsp), %rdi
leaq 0xd8(%rsp), %rsi
callq 0xe24f
leaq 0x1f032(%rip), %rsi     # 0x62980
leaq 0x58(%rsp), %rdi
leaq 0x5(%rsp), %rdx
callq 0xdbbe
leaq 0x1af68(%rip), %rdx     # 0x5e8cc
leaq 0x78(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0xe24f
leaq 0x30(%rsp), %rdi
leaq 0xf8(%rsp), %rsi
leaq 0x78(%rsp), %rdx
callq 0xe26e
leaq 0x1f093(%rip), %rdx     # 0x62a24
leaq 0x8(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0xe24f
leaq 0x8(%rsp), %rdi
callq 0x101d0
callq 0xc6d0
testl %eax, %eax
jne 0x43b52
leaq 0x1e62a(%rip), %rsi     # 0x61fe8
leaq 0xb8(%rsp), %rdi
leaq 0x6(%rsp), %rdx
callq 0xdbbe
leaq 0x98(%rsp), %rdi
movl $0x36d, %esi            # imm = 0x36D
callq 0xe2d5
leaq 0xd8(%rsp), %rdi
leaq 0xb8(%rsp), %rsi
leaq 0x98(%rsp), %rdx
callq 0xe26e
leaq 0x1a7cb(%rip), %rdx     # 0x5e1d1
leaq 0xf8(%rsp), %rdi
leaq 0xd8(%rsp), %rsi
callq 0xe24f
leaq 0x1ef5e(%rip), %rsi     # 0x62980
leaq 0x58(%rsp), %rdi
leaq 0x5(%rsp), %rdx
callq 0xdbbe
leaq 0x1ae94(%rip), %rdx     # 0x5e8cc
leaq 0x78(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0xe24f
leaq 0x30(%rsp), %rdi
leaq 0xf8(%rsp), %rsi
leaq 0x78(%rsp), %rdx
callq 0xe26e
leaq 0x1ef54(%rip), %rdx     # 0x629b9
leaq 0x8(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0xe24f
leaq 0x8(%rsp), %rdi
callq 0x101d0
callq 0xc6d0
testl %eax, %eax
jne 0x43b52
leaq 0x1e556(%rip), %rsi     # 0x61fe8
leaq 0xb8(%rsp), %rdi
leaq 0x6(%rsp), %rdx
callq 0xdbbe
leaq 0x98(%rsp), %rdi
movl $0x38c, %esi            # imm = 0x38C
callq 0xe2d5
leaq 0xd8(%rsp), %rdi
leaq 0xb8(%rsp), %rsi
leaq 0x98(%rsp), %rdx
callq 0xe26e
leaq 0x1a6f7(%rip), %rdx     # 0x5e1d1
leaq 0xf8(%rsp), %rdi
leaq 0xd8(%rsp), %rsi
callq 0xe24f
leaq 0x1ee8a(%rip), %rsi     # 0x62980
leaq 0x58(%rsp), %rdi
leaq 0x5(%rsp), %rdx
callq 0xdbbe
leaq 0x1adc0(%rip), %rdx     # 0x5e8cc
leaq 0x78(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0xe24f
leaq 0x30(%rsp), %rdi
leaq 0xf8(%rsp), %rsi
leaq 0x78(%rsp), %rdx
callq 0xe26e
leaq 0x1eeb5(%rip), %rdx     # 0x629ee
leaq 0x8(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0xe24f
leaq 0x8(%rsp), %rdi
callq 0x101d0
pushq $0x1
popq %rdi
callq 0xc6f0
jmp 0x43b8a
jmp 0x43b99
jmp 0x43bae
jmp 0x43bc3
jmp 0x43be2
jmp 0x43bfa
jmp 0x43c12
jmp 0x43c28
jmp 0x43c3c
jmp 0x43b8a
jmp 0x43b99
jmp 0x43b8a
jmp 0x43b99
jmp 0x43bae
jmp 0x43b8a
jmp 0x43b99
jmp 0x43bae
jmp 0x43bc3
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0xcbe8
jmp 0x43b9c
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0xcbe8
jmp 0x43bb1
jmp 0x43bae
jmp 0x43bc3
jmp 0x43be2
movq %rax, %rbx
leaq 0x78(%rsp), %rdi
callq 0xcbe8
jmp 0x43bc6
jmp 0x43bc3
jmp 0x43be2
jmp 0x43bfa
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
callq 0xcbe8
jmp 0x43be5
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
jmp 0x43c33
jmp 0x43be2
jmp 0x43bfa
jmp 0x43c12
movq %rax, %rbx
leaq 0xf8(%rsp), %rdi
callq 0xcbe8
jmp 0x43bfd
jmp 0x43bfa
jmp 0x43c12
jmp 0x43c28
movq %rax, %rbx
leaq 0xd8(%rsp), %rdi
callq 0xcbe8
jmp 0x43c15
jmp 0x43c12
jmp 0x43c28
jmp 0x43c3c
movq %rax, %rbx
leaq 0x98(%rsp), %rdi
callq 0xcbe8
jmp 0x43c2b
jmp 0x43c28
jmp 0x43c3c
movq %rax, %rbx
leaq 0xb8(%rsp), %rdi
callq 0xcbe8
jmp 0x43c3f
jmp 0x43c3c
movq %rax, %rbx
movq %rbx, %rdi
callq 0xcaa0
nop