// File: 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
subq $0x1b0, %rsp            # imm = 0x1B0
movq %rcx, -0x178(%rbp)
movq %rdx, -0x170(%rbp)
movq %rdi, -0x158(%rbp)
movq %rdi, %rax
movq %rax, -0x168(%rbp)
movl 0x10(%rbp), %eax
movq %rsi, -0x8(%rbp)
movq %rdx, -0x10(%rbp)
movq %rcx, -0x18(%rbp)
movl %r8d, -0x1c(%rbp)
movl %r9d, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x160(%rbp)
callq 0xfe80
movq -0x158(%rbp), %rdi
movl -0x20(%rbp), %esi
callq 0xffb0
movq -0x158(%rbp), %rdi
movl 0x10(%rbp), %esi
callq 0xffd0
movsd 0x1a209(%rip), %xmm0    # 0x2c150
movsd %xmm0, -0x28(%rbp)
movsd 0x1a1fc(%rip), %xmm0    # 0x2c150
movsd %xmm0, -0x30(%rbp)
movsd 0x1a1ef(%rip), %xmm0    # 0x2c150
movsd %xmm0, -0x38(%rbp)
movl -0x1c(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
leaq 0x2c753(%rip), %rcx     # 0x3e6cc
cmpl (%rcx), %eax
jl 0x124e3
movq -0x170(%rbp), %rdi
callq 0x45e0
movq -0x170(%rbp), %rsi
movq %rax, %rdx
movslq -0x3c(%rbp), %rcx
movl %ecx, %eax
subq %rcx, %rdx
movl %eax, %ecx
shrl $0x1f, %ecx
addl %ecx, %eax
sarl %eax
movslq %eax, %rcx
leaq -0x60(%rbp), %rdi
callq 0x43e0
movq -0x178(%rbp), %rsi
movl -0x3c(%rbp), %eax
movl %eax, %ecx
shrl $0x1f, %ecx
addl %ecx, %eax
sarl %eax
movslq %eax, %rcx
xorl %eax, %eax
movl %eax, %edx
leaq -0x80(%rbp), %rdi
callq 0x43e0
jmp 0x11fda
movq -0x160(%rbp), %rdi
leaq -0x60(%rbp), %rsi
leaq -0x80(%rbp), %rdx
callq 0x12500
movsd %xmm0, -0x180(%rbp)
jmp 0x11ff8
movsd -0x180(%rbp), %xmm0
movsd %xmm0, -0x28(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x4270
leaq -0x60(%rbp), %rdi
callq 0x4270
movq -0x170(%rbp), %rdi
callq 0x45e0
movq -0x170(%rbp), %rsi
movq %rax, %rdx
movl -0x3c(%rbp), %eax
movl %eax, %edi
shrl $0x1f, %edi
movl %eax, %ecx
addl %edi, %ecx
sarl %ecx
subl %ecx, %eax
cltq
subq %rax, %rdx
leaq -0xb0(%rbp), %rdi
movq $-0x1, %rcx
callq 0x43e0
movq -0x178(%rbp), %rsi
movl -0x3c(%rbp), %eax
movl %eax, %edx
shrl $0x1f, %edx
movl %eax, %ecx
addl %edx, %ecx
sarl %ecx
movslq %ecx, %rdx
subl %ecx, %eax
movslq %eax, %rcx
leaq -0xd0(%rbp), %rdi
callq 0x43e0
jmp 0x12080
movq -0x160(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
leaq -0xd0(%rbp), %rdx
callq 0x12500
movsd %xmm0, -0x188(%rbp)
jmp 0x120a4
movsd -0x188(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
leaq -0xd0(%rbp), %rdi
callq 0x4270
leaq -0xb0(%rbp), %rdi
callq 0x4270
movq -0x158(%rbp), %rdi
movsd -0x28(%rbp), %xmm0
addsd -0x30(%rbp), %xmm0
movsd 0x1a26e(%rip), %xmm1    # 0x2c350
divsd %xmm1, %xmm0
movsd %xmm0, -0x38(%rbp)
movsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x190(%rbp)
callq 0xfff0
movsd -0x190(%rbp), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x121b4
movq -0x158(%rbp), %rdi
movsd -0x38(%rbp), %xmm0
callq 0xff10
movq -0x158(%rbp), %rdi
movl -0x3c(%rbp), %esi
callq 0xff30
jmp 0x124d3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0x12163
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x4270
leaq -0x60(%rbp), %rdi
callq 0x4270
jmp 0x124f3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0x121a3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
leaq -0xd0(%rbp), %rdi
callq 0x4270
leaq -0xb0(%rbp), %rdi
callq 0x4270
jmp 0x124f3
movsd -0x30(%rbp), %xmm1
leaq 0x2c540(%rip), %rax     # 0x3e700
movsd (%rax), %xmm0
ucomisd %xmm1, %xmm0
jb 0x12341
movq -0x178(%rbp), %rsi
movl -0x3c(%rbp), %eax
movl %eax, %edx
shrl $0x1f, %edx
movl %eax, %ecx
addl %edx, %ecx
sarl %ecx
movslq %ecx, %rdx
subl %ecx, %eax
movslq %eax, %rcx
leaq -0xf0(%rbp), %rdi
callq 0x43e0
movq -0x170(%rbp), %rdi
callq 0x45e0
movq -0x170(%rbp), %rsi
movq %rax, %rdx
movslq -0x3c(%rbp), %rcx
movl %ecx, %eax
subq %rcx, %rdx
movl %eax, %ecx
shrl $0x1f, %ecx
addl %ecx, %eax
sarl %eax
movslq %eax, %rcx
leaq -0x110(%rbp), %rdi
callq 0x43e0
jmp 0x12230
movq -0x160(%rbp), %rdi
leaq -0xf0(%rbp), %rsi
leaq -0x110(%rbp), %rdx
callq 0x12680
movsd %xmm0, -0x198(%rbp)
jmp 0x12254
movsd -0x198(%rbp), %xmm0
movsd %xmm0, -0x28(%rbp)
leaq -0x110(%rbp), %rdi
callq 0x4270
leaq -0xf0(%rbp), %rdi
callq 0x4270
movsd -0x28(%rbp), %xmm1
leaq 0x2c47b(%rip), %rax     # 0x3e700
movsd (%rax), %xmm0
ucomisd %xmm1, %xmm0
jb 0x1233c
movq -0x158(%rbp), %rdi
movsd -0x28(%rbp), %xmm0
addsd -0x30(%rbp), %xmm0
movsd 0x1a0a4(%rip), %xmm1    # 0x2c350
divsd %xmm1, %xmm0
movsd %xmm0, -0x38(%rbp)
movsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x1a0(%rbp)
callq 0xfff0
movsd -0x1a0(%rbp), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x1233a
movq -0x158(%rbp), %rdi
movsd -0x38(%rbp), %xmm0
callq 0xff10
movq -0x158(%rbp), %rdi
movl -0x3c(%rbp), %esi
callq 0xff30
jmp 0x1233a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0x12329
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
leaq -0x110(%rbp), %rdi
callq 0x4270
leaq -0xf0(%rbp), %rdi
callq 0x4270
jmp 0x124f3
jmp 0x1233c
jmp 0x124d1
movsd -0x28(%rbp), %xmm1
leaq 0x2c3b3(%rip), %rax     # 0x3e700
movsd (%rax), %xmm0
ucomisd %xmm1, %xmm0
jb 0x124cf
movq -0x170(%rbp), %rdi
callq 0x45e0
movq -0x170(%rbp), %rsi
movq %rax, %rdx
movl -0x3c(%rbp), %eax
movl %eax, %edi
shrl $0x1f, %edi
movl %eax, %ecx
addl %edi, %ecx
sarl %ecx
subl %ecx, %eax
cltq
subq %rax, %rdx
leaq -0x130(%rbp), %rdi
movq $-0x1, %rcx
callq 0x43e0
movq -0x178(%rbp), %rsi
movl -0x3c(%rbp), %eax
movl %eax, %edx
shrl $0x1f, %edx
movl %eax, %ecx
addl %edx, %ecx
sarl %ecx
movslq %ecx, %rdx
subl %ecx, %eax
movslq %eax, %rcx
leaq -0x150(%rbp), %rdi
callq 0x43e0
jmp 0x123c4
movq -0x160(%rbp), %rdi
leaq -0x130(%rbp), %rsi
leaq -0x150(%rbp), %rdx
callq 0x12680
movsd %xmm0, -0x1a8(%rbp)
jmp 0x123e8
movsd -0x1a8(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
leaq -0x150(%rbp), %rdi
callq 0x4270
leaq -0x130(%rbp), %rdi
callq 0x4270
movsd -0x30(%rbp), %xmm1
leaq 0x2c2e7(%rip), %rax     # 0x3e700
movsd (%rax), %xmm0
ucomisd %xmm1, %xmm0
jb 0x124cd
movq -0x158(%rbp), %rdi
movsd -0x30(%rbp), %xmm0
addsd -0x28(%rbp), %xmm0
movsd 0x19f10(%rip), %xmm1    # 0x2c350
divsd %xmm1, %xmm0
movsd %xmm0, -0x38(%rbp)
movsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x1b0(%rbp)
callq 0xfff0
movsd -0x1b0(%rbp), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x124cb
movq -0x158(%rbp), %rdi
movsd -0x38(%rbp), %xmm0
callq 0xff10
movq -0x158(%rbp), %rdi
movl -0x3c(%rbp), %esi
callq 0xff30
jmp 0x124cb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0x124bd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
leaq -0x150(%rbp), %rdi
callq 0x4270
leaq -0x130(%rbp), %rdi
callq 0x4270
jmp 0x124f3
jmp 0x124cd
jmp 0x124cf
jmp 0x124d1
jmp 0x124d3
jmp 0x124d5
movl -0x3c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x11f6f
movq -0x168(%rbp), %rax
addq $0x1b0, %rsp            # imm = 0x1B0
popq %rbp
retq
movq -0x88(%rbp), %rdi
callq 0x46c0
nop