// File: 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
subq $0x270, %rsp            # imm = 0x270
movq %rsi, -0x198(%rbp)
movq %rdx, -0x1b8(%rbp)
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x1b0(%rbp)
movl $0xd8, %edi
callq 0x43d0
movq -0x1b8(%rbp), %rdi
movq %rax, %rcx
movq -0x1b0(%rbp), %rax
movq %rcx, -0x1a8(%rbp)
movb $0x1, -0x55(%rbp)
movq 0x8(%rax), %rax
movq %rax, -0x1a0(%rbp)
callq 0x45e0
movq -0x198(%rbp), %rsi
movl %eax, -0x18c(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x41b0
jmp 0x126fe
movl -0x18c(%rbp), %edx
movq -0x1a0(%rbp), %rsi
movq -0x1a8(%rbp), %rdi
leaq -0x48(%rbp), %rcx
callq 0x24b50
jmp 0x1271d
movb $0x0, -0x55(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x4270
movq -0x1a8(%rbp), %rax
movq %rax, -0x28(%rbp)
leaq -0x79(%rbp), %rdi
movq %rdi, -0x1c0(%rbp)
callq 0x46e0
movq -0x1c0(%rbp), %rdx
leaq 0x19a65(%rip), %rsi     # 0x2c1b8
leaq -0x78(%rbp), %rdi
callq 0x4530
jmp 0x1275e
leaq -0x79(%rbp), %rdi
callq 0x4420
movq -0x1b8(%rbp), %rdi
movq $0x0, -0x88(%rbp)
callq 0x45e0
decl %eax
movl %eax, -0x8c(%rbp)
movl $0xffffffff, -0x90(%rbp) # imm = 0xFFFFFFFF
movq -0x28(%rbp), %rdi
callq 0x17510
jmp 0x1279b
movq -0x28(%rbp), %rdi
callq 0x17330
movq %rax, -0x1c8(%rbp)
jmp 0x127ad
movq -0x1c8(%rbp), %rax
leaq 0x2bf0d(%rip), %rcx     # 0x3e6c8
movslq (%rcx), %rcx
cmpq %rcx, %rax
jae 0x12873
movq -0x28(%rbp), %rax
movq %rax, -0x1d0(%rbp)
cmpq $0x0, %rax
je 0x127f0
movq -0x1d0(%rbp), %rdi
callq 0x63d0
movq -0x1d0(%rbp), %rdi
callq 0x43a0
movsd 0x19958(%rip), %xmm0    # 0x2c150
movsd %xmm0, -0x8(%rbp)
movl $0x1, -0x94(%rbp)
jmp 0x12f04
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x1282f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x4270
testb $0x1, -0x55(%rbp)
jne 0x12837
jmp 0x12843
movq -0x1a8(%rbp), %rdi
callq 0x43a0
jmp 0x12f24
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x79(%rbp), %rdi
callq 0x4420
jmp 0x12f24
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x12f1b
movq -0x28(%rbp), %rdi
callq 0x17330
movq %rax, -0x1d8(%rbp)
jmp 0x12885
movl $0x0, -0xb4(%rbp)
leaq -0xb5(%rbp), %rdi
movq %rdi, -0x1e0(%rbp)
callq 0xcd30
movq -0x1d8(%rbp), %rsi
movq -0x1e0(%rbp), %rcx
leaq -0xb0(%rbp), %rdi
leaq -0xb4(%rbp), %rdx
callq 0x15700
jmp 0x128c5
leaq -0xb5(%rbp), %rdi
callq 0x8a20
movq -0x28(%rbp), %rdi
callq 0x17330
movq %rax, -0x1e8(%rbp)
jmp 0x128e3
movl $0x0, -0xd4(%rbp)
leaq -0xd5(%rbp), %rdi
movq %rdi, -0x1f0(%rbp)
callq 0xcd30
movq -0x1e8(%rbp), %rsi
movq -0x1f0(%rbp), %rcx
leaq -0xd0(%rbp), %rdi
leaq -0xd4(%rbp), %rdx
callq 0x15700
jmp 0x12923
leaq -0xd5(%rbp), %rdi
callq 0x8a20
movl $0x0, -0xdc(%rbp)
movl $0x0, -0xe0(%rbp)
movl $0x0, -0xe4(%rbp)
movl $0x0, -0xe8(%rbp)
movq -0x1b8(%rbp), %rdi
movslq -0xe8(%rbp), %rax
movq %rax, -0x1f8(%rbp)
callq 0x45e0
movq %rax, %rcx
movq -0x1f8(%rbp), %rax
cmpq %rcx, %rax
jae 0x12b0c
movq -0x1b8(%rbp), %rdi
movl -0x8c(%rbp), %eax
movl -0xe8(%rbp), %ecx
subl %ecx, %eax
movslq %eax, %rsi
callq 0x4770
movq %rax, -0x200(%rbp)
jmp 0x129aa
movq -0x200(%rbp), %rax
movsbl (%rax), %eax
movl %eax, -0xec(%rbp)
movl $0x0, -0xf0(%rbp)
movslq -0xf0(%rbp), %rax
movq %rax, -0x210(%rbp)
movq -0x28(%rbp), %rdi
callq 0x17330
movq %rax, -0x208(%rbp)
jmp 0x129e4
movq -0x210(%rbp), %rax
movq -0x208(%rbp), %rcx
cmpq %rcx, %rax
jae 0x12af6
movq -0x28(%rbp), %rdi
movl -0xf0(%rbp), %esi
movl -0xe8(%rbp), %edx
notl %edx
callq 0x17350
movb %al, -0x211(%rbp)
jmp 0x12a1a
movb -0x211(%rbp), %al
movsbl %al, %eax
movl %eax, -0xf4(%rbp)
cmpl $0x4e, -0xf4(%rbp)
jne 0x12aad
movslq -0xf0(%rbp), %rsi
leaq -0xd0(%rbp), %rdi
callq 0x153d0
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
jmp 0x12ae0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0xb5(%rbp), %rdi
callq 0x8a20
jmp 0x12f1b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x12ef6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0xd5(%rbp), %rdi
callq 0x8a20
jmp 0x12ef6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x12eea
movl -0xf4(%rbp), %eax
cmpl -0xec(%rbp), %eax
je 0x12ade
cmpl $-0x1, -0xf4(%rbp)
je 0x12ade
movslq -0xf0(%rbp), %rsi
leaq -0xb0(%rbp), %rdi
callq 0x153d0
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
jmp 0x12ae0
jmp 0x12ae2
movl -0xf0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xf0(%rbp)
jmp 0x129c4
jmp 0x12af8
movl -0xe8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xe8(%rbp)
jmp 0x12957
movq -0x28(%rbp), %rax
movq %rax, -0x220(%rbp)
leaq -0x110(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x8870
jmp 0x12b2c
movq -0x220(%rbp), %rdi
leaq -0x110(%rbp), %rsi
callq 0x24cf0
jmp 0x12b41
leaq -0x110(%rbp), %rdi
callq 0x6b60
movq -0x28(%rbp), %rdi
leaq 0x2bb80(%rip), %rax     # 0x3e6d8
movl (%rax), %esi
callq 0x24d20
jmp 0x12b61
movq -0x28(%rbp), %rdi
callq 0x252d0
jmp 0x12b6c
movq -0x28(%rbp), %rax
movq %rax, -0x228(%rbp)
leaq -0x128(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0x8870
jmp 0x12b8c
movq -0x228(%rbp), %rdi
leaq -0x128(%rbp), %rsi
callq 0x24cf0
jmp 0x12ba1
leaq -0x128(%rbp), %rdi
callq 0x6b60
movq -0x28(%rbp), %rdi
movl $0x3, %esi
callq 0x24d20
jmp 0x12bbd
movq -0x28(%rbp), %rdi
callq 0x252d0
jmp 0x12bc8
movq -0x28(%rbp), %rdi
callq 0x17330
movq %rax, -0x230(%rbp)
jmp 0x12bda
movq -0x230(%rbp), %rax
leaq 0x2bae0(%rip), %rcx     # 0x3e6c8
movslq (%rcx), %rcx
cmpq %rcx, %rax
jae 0x12c6f
movq -0x28(%rbp), %rax
movq %rax, -0x238(%rbp)
cmpq $0x0, %rax
je 0x12c19
movq -0x238(%rbp), %rdi
callq 0x63d0
movq -0x238(%rbp), %rdi
callq 0x43a0
movsd 0x1952f(%rip), %xmm0    # 0x2c150
movsd %xmm0, -0x8(%rbp)
movl $0x1, -0x94(%rbp)
jmp 0x12ed0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x110(%rbp), %rdi
callq 0x6b60
jmp 0x12eea
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x128(%rbp), %rdi
callq 0x6b60
jmp 0x12eea
movq -0x28(%rbp), %rdi
callq 0x25410
jmp 0x12c7a
movq -0x28(%rbp), %rsi
leaq -0x148(%rbp), %rdi
callq 0x25bc0
jmp 0x12c8c
leaq -0x78(%rbp), %rdi
leaq -0x148(%rbp), %rsi
callq 0x4480
leaq -0x148(%rbp), %rdi
callq 0x4270
leaq -0x78(%rbp), %rdi
callq 0x45e0
movq -0x1b8(%rbp), %rdi
movl %eax, -0xe4(%rbp)
movslq -0xe4(%rbp), %rax
movq %rax, -0x240(%rbp)
callq 0x45e0
movq %rax, %rcx
movq -0x240(%rbp), %rax
cmpq %rcx, %rax
jae 0x12d65
movl -0xe4(%rbp), %eax
movl %eax, -0x244(%rbp)
leaq 0x2b9d5(%rip), %rax     # 0x3e6cc
movl (%rax), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
leaq 0x2b9c2(%rip), %rax     # 0x3e6cc
movl (%rax), %eax
movl $0x2, %esi
cltd
idivl %esi
movl -0x244(%rbp), %eax
addl %edx, %ecx
cmpl %ecx, %eax
jge 0x12d65
movq -0x28(%rbp), %rax
movq %rax, -0x250(%rbp)
cmpq $0x0, %rax
je 0x12d49
movq -0x250(%rbp), %rdi
callq 0x63d0
movq -0x250(%rbp), %rdi
callq 0x43a0
movsd 0x193ff(%rip), %xmm0    # 0x2c150
movsd %xmm0, -0x8(%rbp)
movl $0x1, -0x94(%rbp)
jmp 0x12ed0
movq -0x1b8(%rbp), %rdi
movslq -0xe4(%rbp), %rax
movq %rax, -0x258(%rbp)
callq 0x45e0
movq %rax, %rcx
movq -0x258(%rbp), %rax
cmpq %rcx, %rax
jbe 0x12da0
movq -0x1b8(%rbp), %rdi
callq 0x45e0
movl %eax, -0xe4(%rbp)
leaq -0x78(%rbp), %rdi
movq %rdi, -0x260(%rbp)
callq 0x45e0
movq -0x260(%rbp), %rsi
movq %rax, %rdx
movslq -0xe4(%rbp), %rax
subq %rax, %rdx
leaq -0x168(%rbp), %rdi
movq $-0x1, %rcx
callq 0x43e0
jmp 0x12dd9
movq -0x1b8(%rbp), %rdi
callq 0x45e0
movq -0x1b8(%rbp), %rsi
movq %rax, %rdx
movslq -0xe4(%rbp), %rax
subq %rax, %rdx
leaq -0x188(%rbp), %rdi
movq $-0x1, %rcx
callq 0x43e0
jmp 0x12e0e
movq -0x1b0(%rbp), %rdi
leaq -0x168(%rbp), %rsi
leaq -0x188(%rbp), %rdx
callq 0x12500
movsd %xmm0, -0x268(%rbp)
jmp 0x12e32
movsd -0x268(%rbp), %xmm0
movsd %xmm0, -0x88(%rbp)
leaq -0x188(%rbp), %rdi
callq 0x4270
leaq -0x168(%rbp), %rdi
callq 0x4270
movq -0x28(%rbp), %rax
movq %rax, -0x270(%rbp)
cmpq $0x0, %rax
je 0x12e83
movq -0x270(%rbp), %rdi
callq 0x63d0
movq -0x270(%rbp), %rdi
callq 0x43a0
movsd -0x88(%rbp), %xmm0
movsd %xmm0, -0x8(%rbp)
movl $0x1, -0x94(%rbp)
jmp 0x12ed0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x12ec2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x188(%rbp), %rdi
callq 0x4270
leaq -0x168(%rbp), %rdi
callq 0x4270
jmp 0x12eea
leaq -0xd0(%rbp), %rdi
callq 0x6b60
leaq -0xb0(%rbp), %rdi
callq 0x6b60
jmp 0x12f04
leaq -0xd0(%rbp), %rdi
callq 0x6b60
leaq -0xb0(%rbp), %rdi
callq 0x6b60
jmp 0x12f1b
leaq -0x78(%rbp), %rdi
callq 0x4270
movsd -0x8(%rbp), %xmm0
addq $0x270, %rsp            # imm = 0x270
popq %rbp
retq
leaq -0x78(%rbp), %rdi
callq 0x4270
movq -0x50(%rbp), %rdi
callq 0x46c0
nopl (%rax)