// File: /workspace/github_cpp_makefile_star2_O3/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 $0x138, %rsp            # imm = 0x138
movl %r9d, %r12d
movl %r8d, %ebx
movq %rcx, -0x48(%rbp)
movq %rdx, %r15
movq %rsi, -0x50(%rbp)
movq %rdi, %r14
movl 0x10(%rbp), %r13d
callq 0x95c4
movq %r14, %rdi
movl %r12d, %esi
callq 0x9636
movq %r14, -0x40(%rbp)
movq %r14, %rdi
movl %r13d, %esi
callq 0x9640
leaq 0x1289c(%rip), %rax     # 0x1d61c
cmpl %ebx, (%rax)
jge 0xb184
movslq %ebx, %rbx
decq %rbx
movq 0x8(%r15), %rdx
subq %rbx, %rdx
movl %ebx, %eax
shrl $0x1f, %eax
addl %ebx, %eax
sarl %eax
movslq %eax, %r12
leaq -0x98(%rbp), %rdi
movq %r15, %rsi
movq %r12, %rcx
callq 0x4330
leaq -0x158(%rbp), %rdi
movq -0x48(%rbp), %rsi
xorl %edx, %edx
movq %r12, %rcx
callq 0x4330
movq -0x90(%rbp), %rax
movq -0x158(%rbp), %rdi
movsd 0xb302(%rip), %xmm2     # 0x160e0
testq %rax, %rax
je 0xae51
movq -0x98(%rbp), %rcx
movq %rax, %xmm1
punpckldq 0xb2f9(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0xb301(%rip), %xmm1     # 0x16100
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
leaq 0x1283e(%rip), %rdx     # 0x1d650
movsd (%rdx), %xmm1
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 %xmm2, %xmm2
cvtsi2sd %esi, %xmm2
divsd %xmm0, %xmm2
ucomisd %xmm1, %xmm2
ja 0xae49
incq %rdx
cmpq %rdx, %rax
jne 0xae1a
jmp 0xae51
movsd 0xb28f(%rip), %xmm2     # 0x160e0
movsd %xmm2, -0x30(%rbp)
leaq -0x148(%rbp), %rax
cmpq %rax, %rdi
je 0xae67
callq 0x42f0
movq -0x98(%rbp), %rdi
leaq -0x88(%rbp), %rax
cmpq %rax, %rdi
je 0xae7f
callq 0x42f0
movq 0x8(%r15), %rdx
movq %rbx, %r13
subq %r12, %r13
subq %r13, %rdx
leaq -0x78(%rbp), %rdi
movq %r15, %rsi
movq $-0x1, %rcx
callq 0x4330
leaq -0x138(%rbp), %rdi
movq -0x48(%rbp), %rsi
movq %r12, %rdx
movq %r13, %rcx
callq 0x4330
movq -0x70(%rbp), %rax
movq -0x138(%rbp), %rdi
movsd 0xb218(%rip), %xmm3     # 0x160e0
testq %rax, %rax
movsd -0x30(%rbp), %xmm2
je 0xaf3d
movq -0x78(%rbp), %rcx
movq %rax, %xmm1
punpckldq 0xb20d(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0xb215(%rip), %xmm1     # 0x16100
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
leaq 0x12752(%rip), %rdx     # 0x1d650
movsd (%rdx), %xmm1
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 %xmm0, %xmm3
ucomisd %xmm1, %xmm3
ja 0xaf35
incq %rdx
cmpq %rdx, %rax
jne 0xaf06
jmp 0xaf3d
movsd 0xb1a3(%rip), %xmm3     # 0x160e0
leaq -0x128(%rbp), %rax
cmpq %rax, %rdi
movsd %xmm3, -0x38(%rbp)
je 0xaf5d
callq 0x42f0
movsd -0x38(%rbp), %xmm3
movsd -0x30(%rbp), %xmm2
movq -0x78(%rbp), %rdi
leaq -0x68(%rbp), %rax
cmpq %rax, %rdi
je 0xaf79
callq 0x42f0
movsd -0x38(%rbp), %xmm3
movsd -0x30(%rbp), %xmm2
addsd %xmm3, %xmm2
mulsd 0xb163(%rip), %xmm2     # 0x160e8
movsd %xmm2, -0x58(%rbp)
movq -0x40(%rbp), %rdi
callq 0x964a
movsd -0x58(%rbp), %xmm1
ucomisd %xmm1, %xmm0
movapd %xmm1, %xmm0
jbe 0xafd0
movq -0x40(%rbp), %r14
movq %r14, %rdi
callq 0x9602
movq %r14, %rdi
movl %ebx, %esi
callq 0x960c
leaq 0x1265d(%rip), %rax     # 0x1d61c
movslq (%rax), %rax
cmpq %rax, %rbx
jg 0xad8b
jmp 0xb184
leaq 0x12679(%rip), %rax     # 0x1d650
movsd (%rax), %xmm0
movsd -0x38(%rbp), %xmm1
ucomisd %xmm1, %xmm0
jae 0xb0b6
ucomisd -0x30(%rbp), %xmm0
jb 0xafb8
movq 0x8(%r15), %rdx
subq %r13, %rdx
leaq -0xb8(%rbp), %rdi
movq %r15, %rsi
movq $-0x1, %rcx
callq 0x4330
leaq -0xd8(%rbp), %r14
movq %r14, %rdi
movq -0x48(%rbp), %rsi
movq %r12, %rdx
movq %r13, %rcx
callq 0x4330
movq -0x50(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
movq %r14, %rdx
callq 0xb2aa
movsd %xmm0, -0x38(%rbp)
movq -0xd8(%rbp), %rdi
leaq -0xc8(%rbp), %rax
cmpq %rax, %rdi
je 0xb057
callq 0x42f0
movq -0xb8(%rbp), %rdi
leaq -0xa8(%rbp), %rax
cmpq %rax, %rdi
je 0xb06f
callq 0x42f0
leaq 0x125da(%rip), %rax     # 0x1d650
movsd (%rax), %xmm0
movsd -0x38(%rbp), %xmm1
ucomisd %xmm1, %xmm0
jb 0xafb8
movapd %xmm1, %xmm0
movsd -0x30(%rbp), %xmm1
addsd %xmm0, %xmm1
mulsd 0xb04a(%rip), %xmm1     # 0x160e8
movsd %xmm1, -0x30(%rbp)
movq -0x40(%rbp), %rdi
callq 0x964a
movsd -0x30(%rbp), %xmm1
jmp 0xb171
leaq -0x118(%rbp), %r14
movq %r14, %rdi
movq -0x48(%rbp), %rsi
movq %r12, %rdx
movq %r13, %rcx
callq 0x4330
movq 0x8(%r15), %rdx
subq %rbx, %rdx
leaq -0xf8(%rbp), %r13
movq %r13, %rdi
movq %r15, %rsi
movq %r12, %rcx
callq 0x4330
movq -0x50(%rbp), %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0xb2aa
movsd %xmm0, -0x30(%rbp)
movq -0xf8(%rbp), %rdi
leaq -0xe8(%rbp), %rax
cmpq %rax, %rdi
je 0xb117
callq 0x42f0
movq -0x118(%rbp), %rdi
leaq -0x108(%rbp), %rax
cmpq %rax, %rdi
je 0xb12f
callq 0x42f0
leaq 0x1251a(%rip), %rax     # 0x1d650
movsd (%rax), %xmm0
movsd -0x30(%rbp), %xmm1
ucomisd %xmm1, %xmm0
movapd %xmm1, %xmm0
movsd -0x38(%rbp), %xmm1
jb 0xafb8
addsd %xmm0, %xmm1
mulsd 0xaf8a(%rip), %xmm1     # 0x160e8
movsd %xmm1, -0x38(%rbp)
movq -0x40(%rbp), %rdi
callq 0x964a
movsd -0x38(%rbp), %xmm1
ucomisd %xmm1, %xmm0
movapd %xmm1, %xmm0
ja 0xafa2
jmp 0xafb8
movq -0x40(%rbp), %rax
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq -0xd8(%rbp), %rdi
leaq -0xc8(%rbp), %rax
cmpq %rax, %rdi
je 0xb1ba
callq 0x42f0
jmp 0xb1ba
movq %rax, %rbx
movq -0xb8(%rbp), %rdi
leaq -0xa8(%rbp), %rax
jmp 0xb218
movq %rax, %rbx
movq -0xf8(%rbp), %rdi
leaq -0xe8(%rbp), %rax
cmpq %rax, %rdi
je 0xb1ea
callq 0x42f0
jmp 0xb1ea
movq %rax, %rbx
movq -0x118(%rbp), %rdi
leaq -0x108(%rbp), %rax
jmp 0xb218
movq %rax, %rbx
movq -0x98(%rbp), %rdi
leaq -0x88(%rbp), %rax
jmp 0xb218
movq %rax, %rbx
movq -0x78(%rbp), %rdi
leaq -0x68(%rbp), %rax
cmpq %rax, %rdi
je 0xb222
callq 0x42f0
movq %rbx, %rdi
callq 0x4590