// File: /workspace/github_cpp_makefile_star2_O1/afinit[P]afin/fusion.cpp
// Function: Fusion::overlap_check(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, int, int, int)
Mismatch Fusion::overlap_check( string contig_a, string contig_b, int overlap, int end_i, int end_j ){
  Mismatch mim;
  mim.set_end_i( end_i );
  mim.set_end_j( end_j );
  double score_f = 1.0;
  double score_r = 1.0;
  double score = 1.0;

  for( int i=overlap-1; i>=min_overlap; i-- ){
    score_f = mismatch_score( contig_a.substr( contig_a.length() - i, i/2 ), contig_b.substr( 0, i/2 ) );
    score_r = mismatch_score( contig_a.substr( contig_a.length() - (i-i/2) ), contig_b.substr( i/2, i-i/2 ) );
    score = (score_f + score_r)/2;

    // check if this overlap is the best so far
    if( score < mim.get_score() ){
      mim.set_score( score );
      mim.set_length( i );
    }
    // if the score for the end of contig_a is better than the threshold, check the end of contig_b to see if there could be support in the reads for that end going in a different direction
    else if( score_r <= mismatch_threshold ){
      score_f = check_fusion_support( contig_b.substr(i/2, i-i/2), contig_a.substr( contig_a.length() - i, i/2 ) );
      // make sure the support score is at least as good as the threshold
      if( score_f <= mismatch_threshold ){
        score = (score_f + score_r)/2;
        if( score < mim.get_score() ){
          mim.set_score( score );
          mim.set_length( i );
        }
      }
    }
    // if the score for the end of contig_b is better than the threshold, check the end of contig_a to see if there could be support in the reads for that end going in a different direction
    else if( score_f <= mismatch_threshold ){
      score_r = check_fusion_support( contig_a.substr( contig_a.length() - (i-i/2) ), contig_b.substr( i/2, i-i/2 ) );
      // make sure the support score is at least as good as the threshold
      if( score_r <= mismatch_threshold ){
        score = (score_r + score_f)/2;
        if( score < mim.get_score() ){
          mim.set_score( score );
          mim.set_length( i );
        }
      }
    }
  }
  return mim;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x148, %rsp            # imm = 0x148
movl %r9d, %r12d
movl %r8d, %ebx
movq %rcx, -0x58(%rbp)
movq %rdx, -0x50(%rbp)
movq %rsi, -0x60(%rbp)
movq %rdi, %r14
movl 0x10(%rbp), %r13d
callq 0x9558
movq %r14, %rdi
movl %r12d, %esi
callq 0x95ca
movq %r14, -0x40(%rbp)
movq %r14, %rdi
movl %r13d, %esi
callq 0x95d4
leaq 0x12903(%rip), %rax     # 0x1d61c
cmpl %ebx, (%rax)
jge 0xb07c
movslq %ebx, %rdx
leal -0x1(%rdx), %ecx
movl $0x1, %r15d
subq %rdx, %r15
leaq -0x90(%rbp), %r12
movq %r15, %rax
movq %rdx, %r15
movq -0x50(%rbp), %rsi
movq 0x8(%rsi), %rdx
movq %rax, %r13
addq %rax, %rdx
movl %ecx, %eax
shrl $0x1f, %eax
movl %ecx, -0x44(%rbp)
addl %ecx, %eax
sarl %eax
movslq %eax, %rbx
movq %r12, %rdi
movq %rbx, %rcx
callq 0x4330
leaq -0x170(%rbp), %r14
movq %r14, %rdi
movq -0x58(%rbp), %rsi
xorl %edx, %edx
movq %rbx, %rcx
callq 0x4330
movq %r12, %rsi
movq %r14, %rdx
callq 0xb126
movsd %xmm0, -0x38(%rbp)
movq -0x170(%rbp), %rdi
leaq -0x160(%rbp), %rax
cmpq %rax, %rdi
je 0xada5
callq 0x42f0
movq -0x90(%rbp), %rdi
leaq -0x80(%rbp), %rax
cmpq %rax, %rdi
je 0xadba
callq 0x42f0
movq %rbx, %r12
notq %r12
movq %r15, -0x70(%rbp)
addq %r15, %r12
movq -0x50(%rbp), %rsi
movq 0x8(%rsi), %rdx
addq %rbx, %rdx
movq %r13, %r15
addq %r13, %rdx
leaq -0x130(%rbp), %r13
movq %r13, %rdi
movq $-0x1, %rcx
callq 0x4330
leaq -0x150(%rbp), %r14
movq %r14, %rdi
movq -0x58(%rbp), %rsi
movq %rbx, %rdx
movq %r12, %rcx
callq 0x4330
movq %r13, %rsi
movq %r14, %rdx
callq 0xb126
movq -0x150(%rbp), %rdi
leaq -0x140(%rbp), %rax
cmpq %rax, %rdi
movsd %xmm0, -0x30(%rbp)
je 0xae34
callq 0x42f0
movsd -0x30(%rbp), %xmm0
movq -0x130(%rbp), %rdi
leaq -0x120(%rbp), %rax
cmpq %rax, %rdi
je 0xae51
callq 0x42f0
movsd -0x30(%rbp), %xmm0
movsd -0x38(%rbp), %xmm1
addsd %xmm0, %xmm1
mulsd 0xb27e(%rip), %xmm1     # 0x160e0
movsd %xmm1, -0x68(%rbp)
movq -0x40(%rbp), %rdi
callq 0x95de
movsd -0x68(%rbp), %xmm1
ucomisd %xmm1, %xmm0
movapd %xmm1, %xmm0
jbe 0xaec4
movq -0x40(%rbp), %rbx
movq %rbx, %rdi
callq 0x9596
movq %rbx, %rdi
movl -0x44(%rbp), %esi
callq 0x95a0
movq -0x70(%rbp), %rdx
decq %rdx
leaq 0x12778(%rip), %rax     # 0x1d61c
movslq (%rax), %rax
movl -0x44(%rbp), %ecx
decl %ecx
incq %r15
cmpq %rax, %rdx
leaq -0x90(%rbp), %r12
jg 0xad37
jmp 0xb07c
leaq 0x12785(%rip), %rax     # 0x1d650
movsd (%rax), %xmm0
movsd -0x30(%rbp), %xmm1
ucomisd %xmm1, %xmm0
jae 0xafad
ucomisd -0x38(%rbp), %xmm0
jb 0xae96
movq -0x50(%rbp), %rsi
movq 0x8(%rsi), %rdx
addq %rbx, %rdx
addq %r15, %rdx
leaq -0xd0(%rbp), %r14
movq %r14, %rdi
movq $-0x1, %rcx
callq 0x4330
leaq -0xb0(%rbp), %r13
movq %r13, %rdi
movq -0x58(%rbp), %rsi
movq %rbx, %rdx
movq %r12, %rcx
callq 0x4330
movq -0x60(%rbp), %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0xb1ee
movsd %xmm0, -0x30(%rbp)
movq -0xb0(%rbp), %rdi
leaq -0xa0(%rbp), %rax
cmpq %rax, %rdi
je 0xaf4e
callq 0x42f0
movq -0xd0(%rbp), %rdi
leaq -0xc0(%rbp), %rax
cmpq %rax, %rdi
je 0xaf66
callq 0x42f0
leaq 0x126e3(%rip), %rax     # 0x1d650
movsd (%rax), %xmm0
movsd -0x30(%rbp), %xmm1
ucomisd %xmm1, %xmm0
jb 0xae96
movapd %xmm1, %xmm0
movsd -0x38(%rbp), %xmm1
addsd %xmm0, %xmm1
mulsd 0xb14b(%rip), %xmm1     # 0x160e0
movsd %xmm1, -0x38(%rbp)
movq -0x40(%rbp), %rdi
callq 0x95de
movsd -0x38(%rbp), %xmm1
jmp 0xb069
leaq -0x110(%rbp), %r14
movq %r14, %rdi
movq -0x58(%rbp), %rsi
movq %rbx, %rdx
movq %r12, %rcx
callq 0x4330
movq -0x50(%rbp), %rsi
movq 0x8(%rsi), %rdx
addq %r15, %rdx
leaq -0xf0(%rbp), %r12
movq %r12, %rdi
movq %rbx, %rcx
callq 0x4330
movq -0x60(%rbp), %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0xb1ee
movsd %xmm0, -0x38(%rbp)
movq -0xf0(%rbp), %rdi
leaq -0xe0(%rbp), %rax
cmpq %rax, %rdi
je 0xb00f
callq 0x42f0
movq -0x110(%rbp), %rdi
leaq -0x100(%rbp), %rax
cmpq %rax, %rdi
je 0xb027
callq 0x42f0
leaq 0x12622(%rip), %rax     # 0x1d650
movsd (%rax), %xmm0
movsd -0x38(%rbp), %xmm1
ucomisd %xmm1, %xmm0
movapd %xmm1, %xmm0
movsd -0x30(%rbp), %xmm1
jb 0xae96
addsd %xmm0, %xmm1
mulsd 0xb08a(%rip), %xmm1     # 0x160e0
movsd %xmm1, -0x30(%rbp)
movq -0x40(%rbp), %rdi
callq 0x95de
movsd -0x30(%rbp), %xmm1
ucomisd %xmm1, %xmm0
movapd %xmm1, %xmm0
ja 0xae7f
jmp 0xae96
movq -0x40(%rbp), %rax
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq -0xb0(%rbp), %rdi
leaq -0xa0(%rbp), %rax
cmpq %rax, %rdi
je 0xb0b2
callq 0x42f0
jmp 0xb0b2
movq %rax, %rbx
movq -0xd0(%rbp), %rdi
leaq -0xc0(%rbp), %rax
jmp 0xb113
movq %rax, %rbx
movq -0xf0(%rbp), %rdi
leaq -0xe0(%rbp), %rax
cmpq %rax, %rdi
je 0xb0e2
callq 0x42f0
jmp 0xb0e2
movq %rax, %rbx
movq -0x110(%rbp), %rdi
leaq -0x100(%rbp), %rax
jmp 0xb113
movq %rax, %rbx
movq -0x90(%rbp), %rdi
leaq -0x80(%rbp), %rax
jmp 0xb113
movq %rax, %rbx
movq -0x130(%rbp), %rdi
leaq -0x120(%rbp), %rax
cmpq %rax, %rdi
je 0xb11d
callq 0x42f0
movq %rbx, %rdi
callq 0x4590
nop