// File: /workspace/github_cpp_makefile_star2_O2/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 $0x158, %rsp            # imm = 0x158
movl %r9d, %ebx
movl %r8d, %r15d
movq %rcx, -0x50(%rbp)
movq %rdx, -0x58(%rbp)
movq %rsi, -0x68(%rbp)
movq %rdi, %r13
movl 0x10(%rbp), %r12d
callq 0x8134
movq %r13, %rdi
movl %ebx, %esi
callq 0x81a2
movq %r13, -0x40(%rbp)
movq %r13, %rdi
movl %r12d, %esi
callq 0x81ac
movslq %r15d, %r14
pushq $0x1
popq %rdx
subq %r14, %rdx
leal -0x1(%r14), %eax
leaq -0xf8(%rbp), %r13
leaq -0xd8(%rbp), %r15
leaq 0x12359(%rip), %rcx     # 0x1b62c
movslq (%rcx), %rcx
cmpq %rcx, %r14
jle 0x9583
movq %r14, -0x70(%rbp)
movq %r13, %rbx
movq -0x58(%rbp), %r13
movq 0x8(%r13), %rcx
addq %rdx, %rcx
movl %eax, -0x44(%rbp)
movq %rdx, %r14
cltd
pushq $0x2
popq %rsi
idivl %esi
movslq %eax, %r12
movq %rbx, %rdi
movq %r13, %rsi
movq %rcx, %rdx
movq %r12, %rcx
callq 0x4330
movq %r15, %rdi
movq -0x50(%rbp), %rsi
xorl %edx, %edx
movq %r12, %rcx
callq 0x4330
movq %rbx, %rsi
movq %r15, %rdx
callq 0x95d6
movsd %xmm0, -0x30(%rbp)
movq %r15, %rdi
callq 0x4160
movq %rbx, %rdi
callq 0x4160
movq %r12, %rbx
notq %rbx
addq -0x70(%rbp), %rbx
movq 0x8(%r13), %rdx
addq %r12, %rdx
movq %r14, -0x60(%rbp)
addq %r14, %rdx
leaq -0x178(%rbp), %r14
movq %r14, %rdi
movq %r13, %rsi
pushq $-0x1
popq %rcx
callq 0x4330
leaq -0x158(%rbp), %r15
movq %r15, %rdi
movq -0x50(%rbp), %rsi
movq %r12, %rdx
movq %rbx, %rcx
callq 0x4330
movq %r14, %rsi
movq %r15, %rdx
callq 0x95d6
movsd %xmm0, -0x38(%rbp)
movq %r15, %rdi
callq 0x4160
movq %r14, %rdi
callq 0x4160
movsd -0x30(%rbp), %xmm0
addsd -0x38(%rbp), %xmm0
mulsd 0x9d26(%rip), %xmm0     # 0x130e0
movsd %xmm0, -0x78(%rbp)
movq -0x40(%rbp), %rdi
callq 0x81b6
movsd -0x78(%rbp), %xmm1
ucomisd %xmm1, %xmm0
movapd %xmm1, %xmm0
leaq -0xf8(%rbp), %r13
jbe 0x940d
movq -0x40(%rbp), %rbx
movq %rbx, %rdi
callq 0x816e
movq %rbx, %rdi
movl -0x44(%rbp), %esi
callq 0x8178
movq -0x60(%rbp), %rdx
incq %rdx
movl -0x44(%rbp), %eax
decl %eax
movq -0x70(%rbp), %r14
decq %r14
jmp 0x92c5
leaq 0x1224c(%rip), %rax     # 0x1b660
movsd (%rax), %xmm0
movsd -0x38(%rbp), %xmm1
ucomisd %xmm1, %xmm0
jae 0x94d3
ucomisd -0x30(%rbp), %xmm0
jb 0x93f5
movq -0x58(%rbp), %rsi
movq 0x8(%rsi), %rdx
addq %r12, %rdx
addq -0x60(%rbp), %rdx
leaq -0x118(%rbp), %r14
movq %r14, %rdi
pushq $-0x1
popq %rcx
callq 0x4330
leaq -0x98(%rbp), %r15
movq %r15, %rdi
movq -0x50(%rbp), %rsi
movq %r12, %rdx
movq %rbx, %rcx
callq 0x4330
movq -0x68(%rbp), %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x9656
movsd %xmm0, -0x38(%rbp)
movq %r15, %rdi
callq 0x4160
movq %r14, %rdi
callq 0x4160
leaq 0x121cd(%rip), %rax     # 0x1b660
movsd (%rax), %xmm0
movsd -0x38(%rbp), %xmm1
ucomisd %xmm1, %xmm0
jb 0x93f5
movapd %xmm1, %xmm0
movsd -0x30(%rbp), %xmm1
addsd %xmm0, %xmm1
mulsd 0x9c25(%rip), %xmm1     # 0x130e0
movsd %xmm1, -0x30(%rbp)
movq -0x40(%rbp), %rdi
callq 0x81b6
movsd -0x30(%rbp), %xmm1
jmp 0x9570
leaq -0x138(%rbp), %r14
movq %r14, %rdi
movq -0x50(%rbp), %rsi
movq %r12, %rdx
movq %rbx, %rcx
callq 0x4330
movq -0x58(%rbp), %rsi
movq 0x8(%rsi), %rdx
addq -0x60(%rbp), %rdx
leaq -0xb8(%rbp), %rbx
movq %rbx, %rdi
movq %r12, %rcx
callq 0x4330
movq -0x68(%rbp), %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x9656
movsd %xmm0, -0x30(%rbp)
movq %rbx, %rdi
callq 0x4160
movq %r14, %rdi
callq 0x4160
leaq 0x1212b(%rip), %rax     # 0x1b660
movsd (%rax), %xmm0
movsd -0x30(%rbp), %xmm1
ucomisd %xmm1, %xmm0
movapd %xmm1, %xmm0
movsd -0x38(%rbp), %xmm1
jb 0x93f5
addsd %xmm0, %xmm1
mulsd 0x9b83(%rip), %xmm1     # 0x130e0
movsd %xmm1, -0x38(%rbp)
movq -0x40(%rbp), %rdi
callq 0x81b6
movsd -0x38(%rbp), %xmm1
ucomisd %xmm1, %xmm0
movapd %xmm1, %xmm0
ja 0x93de
jmp 0x93f5
movq -0x40(%rbp), %rax
addq $0x158, %rsp            # imm = 0x158
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq -0x98(%rbp), %rdi
jmp 0x95b1
jmp 0x95ba
movq %rax, %rbx
leaq -0xb8(%rbp), %rdi
callq 0x4160
jmp 0x95bd
jmp 0x95ba
movq %rax, %rbx
movq %r14, %rdi
jmp 0x95c8
movq %rbx, %rdi
movq %rax, %rbx
callq 0x4160
movq %rbx, %rdi
callq 0x4590
nop