// File: /workspace/github_cpp_makefile_star2_O3/afinit[P]afin/fusion.cpp
// Function: Fusion::check_fusion_support(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
double Fusion::check_fusion_support( string contig, string contig_ref ){
  Extension *exten = new Extension( reads, contig_ref.length(), contig ); 
  
  string support_string( "" );
  double score = 0;
  const int pos = contig_ref.length() - 1;
  const int start = -1;
  
  exten->matches.start_match();

  // return if matches found is less than min_cov
  if( exten->matches.get_matchlist_size() < min_cov ){
    delete exten;
    return 1.0;
  }

  // create missed bp's vector to keep track of how many bp's each read contains that are below the max at that position
  vector<int> mismatch( exten->matches.get_matchlist_size(), 0 );
  vector<int> ambiguous_bp( exten->matches.get_matchlist_size(), 0 );
  int mismatch_tot = 0;
  int mismatch_avg = 0;
  int cmp_len = 0;

  // count mismatch's in each read match
  for( int i=0; i<contig_ref.length(); i++ ){
    int next_char_ref = contig_ref[pos-i];
    for( int j=0; j<exten->matches.get_matchlist_size(); j++ ){
      int next_char = exten->matches.get_pos( j, start-i );
      if( next_char == 'N' ){
        ambiguous_bp[j]++;
      }
      // check if next_char matches or exists in the current read
      else if( next_char != next_char_ref && next_char != -1 ){
        mismatch[j]++;
      }
    }
  }

  // remove reads with more than the max_missed
  exten->set_missed_bp( mismatch );
  exten->set_missed_avg( max_missed );
  exten->error_removal();

  // remove reads with more than 3 N's
  exten->set_missed_bp( ambiguous_bp );
  exten->set_missed_avg( 3 );
  exten->error_removal();
  
  // if matchlist is smaller than min_cov, bail, return 1.0 (the least supportive return value)
  if( exten->matches.get_matchlist_size() < min_cov ){
    delete exten;
    return 1.0;
  }

  // get string built from remaining matches.
  exten->build_string();
  support_string = exten->get_extension();
  cmp_len = support_string.length();

  // use the smaller of contig_ref.length() and min_overlap/2 as min_length to compare support_string with matching contig
  if( cmp_len < contig_ref.length() && cmp_len < (min_overlap/2 + min_overlap%2) ){
    delete exten;
    return 1.0;
  }

  // get smallest of string lengths
  if( cmp_len > contig_ref.length() ){
    cmp_len = contig_ref.length();
  }

  score = mismatch_score( support_string.substr( support_string.length() - cmp_len), contig_ref.substr( contig_ref.length() - cmp_len ) );
  
  delete exten;
  return score;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x128, %rsp            # imm = 0x128
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %r14
movl $0xd8, %edi
callq 0x4310
movq %rax, %rbx
movq 0x8(%r14), %r14
movq %r15, -0x40(%rbp)
movq 0x8(%r15), %r15
leaq -0x118(%rbp), %r13
movq %r13, -0x10(%r13)
movq (%r12), %rsi
movq 0x8(%r12), %rdx
addq %rsi, %rdx
leaq -0x128(%rbp), %rdi
callq 0x68f6
leaq -0x128(%rbp), %rcx
movq %rbx, %rdi
movq %r14, %rsi
movl %r15d, %edx
callq 0x1264a
movq -0x128(%rbp), %rdi
cmpq %r13, %rdi
movq -0x40(%rbp), %r14
je 0xb32d
callq 0x42f0
leaq -0x50(%rbp), %rax
movq %rax, -0x10(%rax)
leaq 0xac10(%rip), %rdx      # 0x15f4c
leaq -0x60(%rbp), %rdi
movq %rdx, %rsi
callq 0x6be0
movl 0x8(%r14), %eax
movq %rax, -0x68(%rbp)
movq %rbx, %rdi
callq 0xddc6
movq %rbx, %rdi
callq 0xdc12
leaq 0x122b1(%rip), %rcx     # 0x1d618
movslq (%rcx), %rcx
cmpq %rcx, %rax
jae 0xb3e9
movq 0xa8(%rbx), %rdi
leaq 0xb8(%rbx), %rax
cmpq %rax, %rdi
je 0xb387
callq 0x42f0
movq 0x88(%rbx), %rdi
leaq 0x98(%rbx), %rax
cmpq %rax, %rdi
je 0xb39f
callq 0x42f0
movq 0x68(%rbx), %rdi
testq %rdi, %rdi
je 0xb3ad
callq 0x42f0
leaq 0x50(%rbx), %rdi
callq 0x6412
movq 0x28(%rbx), %rdi
leaq 0x38(%rbx), %rax
cmpq %rax, %rdi
je 0xb3c8
callq 0x42f0
movq %rbx, %rdi
addq $0x8, %rdi
callq 0x6474
movq %rbx, %rdi
callq 0x42f0
movsd 0xacfc(%rip), %xmm0     # 0x160e0
jmp 0xb7b5
movq %rbx, %rdi
callq 0xdc12
leaq -0x108(%rbp), %rdx
movl $0x0, (%rdx)
leaq -0x98(%rbp), %rdi
leaq -0x80(%rbp), %rcx
movq %rax, %rsi
callq 0xd82a
movq %rbx, %rdi
callq 0xdc12
leaq -0x108(%rbp), %rdx
movl $0x0, (%rdx)
leaq -0x80(%rbp), %r12
leaq -0x31(%rbp), %rcx
movq %r12, %rdi
movq %rax, %rsi
callq 0xd82a
movq -0x40(%rbp), %r15
cmpq $0x0, 0x8(%r15)
je 0xb4b6
xorl %r13d, %r13d
movq %r13, -0x30(%rbp)
notl %r13d
movq -0x68(%rbp), %rax
addl %r13d, %eax
cltq
movq (%r15), %rcx
movb (%rcx,%rax), %r15b
xorl %r14d, %r14d
movq %rbx, %rdi
callq 0xdc12
cmpq %r14, %rax
jbe 0xb4a5
movq %rbx, %rdi
movl %r14d, %esi
movl %r13d, %edx
callq 0xdc32
movq %r12, %rcx
cmpb $0x4e, %al
je 0xb499
cmpb %r15b, %al
sete %cl
cmpb $-0x1, %al
sete %al
orb %cl, %al
leaq -0x98(%rbp), %rcx
jne 0xb4a0
movq (%rcx), %rax
incl (%rax,%r14,4)
incq %r14
jmp 0xb461
movq -0x30(%rbp), %r13
incq %r13
movq -0x40(%rbp), %r15
cmpq %r13, 0x8(%r15)
ja 0xb447
leaq -0xc8(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x6ab8
leaq -0xc8(%rbp), %rsi
movq %rbx, %rdi
callq 0x127c8
movq -0xc8(%rbp), %rdi
testq %rdi, %rdi
je 0xb4e9
callq 0x42f0
leaq 0x12138(%rip), %rax     # 0x1d628
movl (%rax), %esi
movq %rbx, %rdi
callq 0x127d6
movq %rbx, %rdi
callq 0x12a0e
leaq -0xb0(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x6ab8
leaq -0xb0(%rbp), %rsi
movq %rbx, %rdi
callq 0x127c8
movq -0xb0(%rbp), %rdi
testq %rdi, %rdi
je 0xb532
callq 0x42f0
movq %rbx, %rdi
movl $0x3, %esi
callq 0x127d6
movq %rbx, %rdi
callq 0x12a0e
movq %rbx, %rdi
callq 0xdc12
leaq 0x120c2(%rip), %rcx     # 0x1d618
movslq (%rcx), %rcx
cmpq %rcx, %rax
jae 0xb5bf
movq 0xa8(%rbx), %rdi
leaq 0xb8(%rbx), %rax
cmpq %rax, %rdi
je 0xb576
callq 0x42f0
movq 0x88(%rbx), %rdi
leaq 0x98(%rbx), %rax
cmpq %rax, %rdi
je 0xb58e
callq 0x42f0
movq 0x68(%rbx), %rdi
testq %rdi, %rdi
je 0xb59c
callq 0x42f0
leaq 0x50(%rbx), %rdi
callq 0x6412
movq 0x28(%rbx), %rdi
leaq 0x38(%rbx), %rax
movsd 0xab2b(%rip), %xmm0     # 0x160e0
movsd %xmm0, -0x30(%rbp)
jmp 0xb773
movq %rbx, %rdi
callq 0x12aee
leaq -0x108(%rbp), %rdi
movq %rbx, %rsi
callq 0x12f1c
leaq -0x60(%rbp), %rdi
leaq -0x108(%rbp), %r14
movq %r14, %rsi
callq 0x43b0
movq (%r14), %rdi
leaq -0xf8(%rbp), %rax
cmpq %rax, %rdi
je 0xb5fd
callq 0x42f0
movq -0x58(%rbp), %rdx
movslq %edx, %rcx
movq 0x8(%r15), %rax
cmpq %rax, %rcx
jae 0xb633
leaq 0x12008(%rip), %rsi     # 0x1d61c
movl (%rsi), %esi
movl %esi, %edi
shrl $0x1f, %edi
addl %esi, %edi
movl %edi, %r8d
andl $-0x2, %r8d
subl %r8d, %esi
sarl %edi
addl %esi, %edi
cmpl %edx, %edi
jg 0xb55e
cmpq %rax, %rcx
cmovbeq %rdx, %rax
movslq %eax, %r14
subq %r14, %rdx
leaq -0xe8(%rbp), %rdi
leaq -0x60(%rbp), %rsi
movq $-0x1, %rcx
callq 0x4330
movq 0x8(%r15), %rdx
subq %r14, %rdx
leaq -0x148(%rbp), %rdi
movq %r15, %rsi
movq $-0x1, %rcx
callq 0x4330
movq -0xe0(%rbp), %rax
movsd 0xaa5d(%rip), %xmm0     # 0x160e0
movq -0x148(%rbp), %rdi
testq %rax, %rax
je 0xb6f5
movq %rax, %xmm2
punpckldq 0xaa54(%rip), %xmm2 # xmm2 = xmm2[0],mem[0],xmm2[1],mem[1]
subpd 0xaa5c(%rip), %xmm2     # 0x16100
movq -0xe8(%rbp), %rcx
movapd %xmm2, %xmm1
unpckhpd %xmm2, %xmm1            # xmm1 = xmm1[1],xmm2[1]
addsd %xmm2, %xmm1
leaq 0x11f92(%rip), %rdx     # 0x1d650
movsd (%rdx), %xmm2
xorl %edx, %edx
xorl %esi, %esi
movl %esi, %r8d
movb (%rcx,%rdx), %r9b
xorl %esi, %esi
cmpb (%rdi,%rdx), %r9b
setne %sil
addl %r8d, %esi
xorps %xmm3, %xmm3
cvtsi2sd %esi, %xmm3
divsd %xmm1, %xmm3
ucomisd %xmm2, %xmm3
ja 0xb6f5
incq %rdx
cmpq %rdx, %rax
jne 0xb6c6
jmp 0xb6f9
movapd %xmm0, %xmm3
movsd %xmm3, -0x30(%rbp)
leaq -0x138(%rbp), %rax
cmpq %rax, %rdi
je 0xb70f
callq 0x42f0
leaq -0xd8(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xb724
callq 0x42f0
movq 0xa8(%rbx), %rdi
leaq 0xb8(%rbx), %rax
cmpq %rax, %rdi
je 0xb73c
callq 0x42f0
movq 0x88(%rbx), %rdi
leaq 0x98(%rbx), %rax
cmpq %rax, %rdi
je 0xb754
callq 0x42f0
movq 0x68(%rbx), %rdi
testq %rdi, %rdi
je 0xb762
callq 0x42f0
leaq 0x50(%rbx), %rdi
callq 0x6412
movq 0x28(%rbx), %rdi
leaq 0x38(%rbx), %rax
cmpq %rax, %rdi
je 0xb77d
callq 0x42f0
movq %rbx, %rdi
addq $0x8, %rdi
callq 0x6474
movq %rbx, %rdi
callq 0x42f0
movq -0x80(%rbp), %rdi
testq %rdi, %rdi
je 0xb79f
callq 0x42f0
movq -0x98(%rbp), %rdi
testq %rdi, %rdi
je 0xb7b0
callq 0x42f0
movsd -0x30(%rbp), %xmm0
movq -0x60(%rbp), %rdi
leaq -0x50(%rbp), %rax
cmpq %rax, %rdi
je 0xb7d1
movsd %xmm0, -0x30(%rbp)
callq 0x42f0
movsd -0x30(%rbp), %xmm0
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
leaq -0xd8(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
jne 0xb815
jmp 0xb856
jmp 0xb853
movq %rax, %r14
movq -0xb0(%rbp), %rdi
jmp 0xb810
movq %rax, %r14
movq -0xc8(%rbp), %rdi
testq %rdi, %rdi
je 0xb856
callq 0x42f0
jmp 0xb856
jmp 0xb81e
movq %rax, %r14
jmp 0xb864
jmp 0xb84a
jmp 0xb84a
movq %rax, %r14
jmp 0xb887
movq %rax, %r14
movq -0x128(%rbp), %rdi
cmpq %r13, %rdi
je 0xb845
callq 0x42f0
jmp 0xb845
movq %rax, %r14
movq %rbx, %rdi
jmp 0xb882
movq %rax, %r14
jmp 0xb875
jmp 0xb853
jmp 0xb853
movq %rax, %r14
movq -0x80(%rbp), %rdi
testq %rdi, %rdi
je 0xb864
callq 0x42f0
movq -0x98(%rbp), %rdi
testq %rdi, %rdi
je 0xb875
callq 0x42f0
leaq -0x50(%rbp), %rax
movq -0x60(%rbp), %rdi
cmpq %rax, %rdi
je 0xb887
callq 0x42f0
movq %r14, %rdi
callq 0x4590
nop