// File: /workspace/github_cpp_makefile_star2_O1/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 -0xf8(%rbp), %r13
movq %r13, -0x10(%r13)
movq (%r12), %rsi
movq 0x8(%r12), %rdx
addq %rsi, %rdx
leaq -0x108(%rbp), %rdi
callq 0x6876
leaq -0x108(%rbp), %rcx
movq %rbx, %rdi
movq %r14, %rsi
movl %r15d, %edx
callq 0x124b2
movq -0x108(%rbp), %rdi
cmpq %r13, %rdi
movq -0x40(%rbp), %r14
je 0xb271
callq 0x42f0
leaq -0x50(%rbp), %rax
movq %rax, -0x10(%rax)
leaq 0xaccc(%rip), %rdx      # 0x15f4c
leaq -0x60(%rbp), %rdi
movq %rdx, %rsi
callq 0x6b5c
movl 0x8(%r14), %eax
movq %rax, -0x68(%rbp)
movq %rbx, %rdi
callq 0xdca6
movq %rbx, %rdi
callq 0xdaf2
leaq 0x1236d(%rip), %rcx     # 0x1d618
movslq (%rcx), %rcx
cmpq %rcx, %rax
jae 0xb332
movq 0xa8(%rbx), %rdi
leaq 0xb8(%rbx), %rax
cmpq %rax, %rdi
je 0xb2cb
callq 0x42f0
movq 0x88(%rbx), %rdi
leaq 0x98(%rbx), %rax
cmpq %rax, %rdi
je 0xb2e3
callq 0x42f0
movq 0x68(%rbx), %rdi
testq %rdi, %rdi
je 0xb2f1
callq 0x42f0
leaq 0x50(%rbx), %rdi
callq 0x63aa
movq 0x28(%rbx), %rdi
leaq 0x38(%rbx), %rax
cmpq %rax, %rdi
je 0xb30c
callq 0x42f0
movq %rbx, %rdi
addq $0x8, %rdi
callq 0x6402
movq %rbx, %rdi
callq 0x42f0
movsd 0xadc0(%rip), %xmm0     # 0x160e8
movsd %xmm0, -0x38(%rbp)
jmp 0xb68d
movq %rbx, %rdi
callq 0xdaf2
leaq -0xe8(%rbp), %rdx
movl $0x0, (%rdx)
leaq -0x98(%rbp), %rdi
leaq -0x80(%rbp), %rcx
movq %rax, %rsi
callq 0xd70a
movq %rbx, %rdi
callq 0xdaf2
leaq -0xe8(%rbp), %rdx
movl $0x0, (%rdx)
leaq -0x80(%rbp), %r12
leaq -0x29(%rbp), %rcx
movq %r12, %rdi
movq %rax, %rsi
callq 0xd70a
movq -0x40(%rbp), %r15
cmpq $0x0, 0x8(%r15)
je 0xb3ff
xorl %r13d, %r13d
movq %r13, -0x38(%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 0xdaf2
cmpq %r14, %rax
jbe 0xb3ee
movq %rbx, %rdi
movl %r14d, %esi
movl %r13d, %edx
callq 0xdb12
movq %r12, %rcx
cmpb $0x4e, %al
je 0xb3e2
cmpb %r15b, %al
sete %cl
cmpb $-0x1, %al
sete %al
orb %cl, %al
leaq -0x98(%rbp), %rcx
jne 0xb3e9
movq (%rcx), %rax
incl (%rax,%r14,4)
incq %r14
jmp 0xb3aa
movq -0x38(%rbp), %r13
incq %r13
movq -0x40(%rbp), %r15
cmpq %r13, 0x8(%r15)
ja 0xb390
leaq -0xc8(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x6a34
leaq -0xc8(%rbp), %rsi
movq %rbx, %rdi
callq 0x12630
movq -0xc8(%rbp), %rdi
testq %rdi, %rdi
je 0xb432
callq 0x42f0
leaq 0x121ef(%rip), %rax     # 0x1d628
movl (%rax), %esi
movq %rbx, %rdi
callq 0x1263e
movq %rbx, %rdi
callq 0x12886
leaq -0xb0(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x6a34
leaq -0xb0(%rbp), %rsi
movq %rbx, %rdi
callq 0x12630
movq -0xb0(%rbp), %rdi
testq %rdi, %rdi
je 0xb47b
callq 0x42f0
movq %rbx, %rdi
movl $0x3, %esi
callq 0x1263e
movq %rbx, %rdi
callq 0x12886
movq %rbx, %rdi
callq 0xdaf2
leaq 0x12179(%rip), %rcx     # 0x1d618
movslq (%rcx), %rcx
cmpq %rcx, %rax
jae 0xb508
movq 0xa8(%rbx), %rdi
leaq 0xb8(%rbx), %rax
cmpq %rax, %rdi
je 0xb4bf
callq 0x42f0
movq 0x88(%rbx), %rdi
leaq 0x98(%rbx), %rax
cmpq %rax, %rdi
je 0xb4d7
callq 0x42f0
movq 0x68(%rbx), %rdi
testq %rdi, %rdi
je 0xb4e5
callq 0x42f0
leaq 0x50(%rbx), %rdi
callq 0x63aa
movq 0x28(%rbx), %rdi
leaq 0x38(%rbx), %rax
movsd 0xabea(%rip), %xmm0     # 0x160e8
movsd %xmm0, -0x38(%rbp)
jmp 0xb650
movq %rbx, %rdi
callq 0x1295c
leaq -0xe8(%rbp), %rdi
movq %rbx, %rsi
callq 0x12daa
leaq -0x60(%rbp), %rdi
leaq -0xe8(%rbp), %r14
movq %r14, %rsi
callq 0x43b0
movq (%r14), %rdi
leaq -0xd8(%rbp), %rax
cmpq %rax, %rdi
je 0xb546
callq 0x42f0
movq -0x58(%rbp), %rdx
movslq %edx, %rcx
movq 0x8(%r15), %rax
cmpq %rax, %rcx
jae 0xb57c
leaq 0x120bf(%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 0xb4a7
cmpq %rax, %rcx
cmovbeq %rdx, %rax
movslq %eax, %r14
subq %r14, %rdx
leaq -0x128(%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
leaq -0x128(%rbp), %rsi
leaq -0x148(%rbp), %r14
movq %r14, %rdx
callq 0xb126
movsd %xmm0, -0x38(%rbp)
movq (%r14), %rdi
leaq -0x138(%rbp), %rax
cmpq %rax, %rdi
je 0xb5ec
callq 0x42f0
leaq -0x118(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xb601
callq 0x42f0
movq 0xa8(%rbx), %rdi
leaq 0xb8(%rbx), %rax
cmpq %rax, %rdi
je 0xb619
callq 0x42f0
movq 0x88(%rbx), %rdi
leaq 0x98(%rbx), %rax
cmpq %rax, %rdi
je 0xb631
callq 0x42f0
movq 0x68(%rbx), %rdi
testq %rdi, %rdi
je 0xb63f
callq 0x42f0
leaq 0x50(%rbx), %rdi
callq 0x63aa
movq 0x28(%rbx), %rdi
leaq 0x38(%rbx), %rax
cmpq %rax, %rdi
je 0xb65a
callq 0x42f0
movq %rbx, %rdi
addq $0x8, %rdi
callq 0x6402
movq %rbx, %rdi
callq 0x42f0
movq -0x80(%rbp), %rdi
testq %rdi, %rdi
je 0xb67c
callq 0x42f0
movq -0x98(%rbp), %rdi
testq %rdi, %rdi
je 0xb68d
callq 0x42f0
movq -0x60(%rbp), %rdi
leaq -0x50(%rbp), %rax
cmpq %rax, %rdi
je 0xb69f
callq 0x42f0
movsd -0x38(%rbp), %xmm0
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
leaq -0x118(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
jne 0xb6e8
jmp 0xb729
jmp 0xb726
movq %rax, %r14
movq -0xb0(%rbp), %rdi
jmp 0xb6e3
movq %rax, %r14
movq -0xc8(%rbp), %rdi
testq %rdi, %rdi
je 0xb729
callq 0x42f0
jmp 0xb729
jmp 0xb6f1
movq %rax, %r14
jmp 0xb737
jmp 0xb71d
jmp 0xb71d
movq %rax, %r14
jmp 0xb75a
movq %rax, %r14
movq -0x108(%rbp), %rdi
cmpq %r13, %rdi
je 0xb718
callq 0x42f0
jmp 0xb718
movq %rax, %r14
movq %rbx, %rdi
jmp 0xb755
movq %rax, %r14
jmp 0xb748
jmp 0xb726
jmp 0xb726
movq %rax, %r14
movq -0x80(%rbp), %rdi
testq %rdi, %rdi
je 0xb737
callq 0x42f0
movq -0x98(%rbp), %rdi
testq %rdi, %rdi
je 0xb748
callq 0x42f0
leaq -0x50(%rbp), %rax
movq -0x60(%rbp), %rdi
cmpq %rax, %rdi
je 0xb75a
callq 0x42f0
movq %r14, %rdi
callq 0x4590