// File: /workspace/github_cpp_makefile_star2_O1/afinit[P]afin/fusion.cpp
// Function: Fusion::process_fusions()
void Fusion::process_fusions(){
  for( int i=0; i<match_list.size(); i++ ){
    // fuse contigs
    int index_i = match_list[i].get_index_i();
    int index_j = match_list[i].get_index_j();
    string contig_i = contigs->get_contig(index_i).get_sequence();
    string contig_j = contigs->get_contig(index_j).get_sequence();
    string fused_id("");
    string fused("");
    string rev_i("");
    string rev_j("");

    // find the reverse compliment of the contigs where necessary
    if( match_list[i].get_end_i() == 0 ){
      contig_i = revcomp( contig_i );
      rev_i = "_r";
    }
    
    if( match_list[i].get_end_j() == 1 ){
      contig_j = revcomp( contig_j );
      rev_j = "_r";
    }

    contig_fusion_log( match_list[i] );
    fused_id = get_fused_id( contigs->get_contig(index_i).get_contig_id()+rev_i, contigs->get_contig(index_j).get_contig_id()+rev_j );
    fused_id = "fused(" + fused_id + ")";
 
    // push each index onto the remove vector
    contig_remove_list.push_back( index_i );
    contig_remove_list.push_back( index_j );

    // create fused contig
    fused = build_fusion_string( contig_i, contig_j, match_list[i].get_length() );
            
    // commit fusion here
    commit_fusion( fused, fused_id, index_i, index_j );
    int new_index = contigs->get_list_size()-1;

    // check for additional appearances of the current contigs in match_list
    for( int j=i+1; j<match_list.size(); j++ ){
      // change reference index and end variables where necessary
      if( index_i == match_list[j].get_index_i() ){
        match_list[j].set_index_i( new_index );
        match_list[j].set_end_i( 0 );
      }
      else if( index_i == match_list[j].get_index_j() ){
        match_list[j].set_index_j( new_index );
        match_list[j].set_end_j( 0 );
      }
      else if( index_j == match_list[j].get_index_i() ){
        match_list[j].set_index_i( new_index );
        match_list[j].set_end_i( 1 );
      }
      else if( index_j == match_list[j].get_index_j() ){
        match_list[j].set_index_j( new_index );
        match_list[j].set_end_j( 1 );
      }
    }
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x308, %rsp            # imm = 0x308
movq %rdi, %rbx
movq 0x10(%rdi), %rdi
cmpq %rdi, 0x18(%rbx)
je 0xcdec
leaq 0x28(%rbx), %rax
movq %rax, -0x78(%rbp)
movl $0x1, %eax
movq %rax, -0x88(%rbp)
movl $0x20, %eax
movq %rax, -0x80(%rbp)
xorl %r14d, %r14d
movq %r14, %r13
shlq $0x5, %r13
addq %r13, %rdi
callq 0x95f2
movl %eax, -0x30(%rbp)
movq 0x10(%rbx), %rdi
addq %r13, %rdi
callq 0x95fc
movl %eax, -0x2c(%rbp)
movq (%rbx), %rsi
movl -0x30(%rbp), %edx
leaq -0x198(%rbp), %r15
movq %r15, %rdi
callq 0x13c48
leaq -0x148(%rbp), %rdi
movq %r15, %rsi
callq 0x5c7a
movq %r15, %rdi
callq 0x59a6
movq (%rbx), %rsi
movl -0x2c(%rbp), %edx
movq %r15, %rdi
callq 0x13c48
leaq -0x128(%rbp), %rdi
movq %r15, %rsi
callq 0x5c7a
movq %r15, %rdi
callq 0x59a6
leaq -0x40(%rbp), %rax
movq %rax, -0x50(%rbp)
leaq -0x50(%rbp), %rdi
leaq 0x9964(%rip), %r15      # 0x15f4c
movq %r15, %rsi
movq %r15, %rdx
callq 0x6b5c
leaq -0x60(%rbp), %rax
movq %rax, -0x70(%rbp)
leaq -0x70(%rbp), %rdi
movq %r15, %rsi
movq %r15, %rdx
callq 0x6b5c
leaq -0xb8(%rbp), %rax
movq %rax, -0xc8(%rbp)
leaq -0xc8(%rbp), %rdi
movq %r15, %rsi
movq %r15, %rdx
callq 0x6b5c
leaq -0x98(%rbp), %rax
movq %rax, -0xa8(%rbp)
leaq -0xa8(%rbp), %rdi
movq %r15, %rsi
movq %r15, %rdx
callq 0x6b5c
movq 0x10(%rbx), %rdi
addq %r13, %rdi
callq 0x9606
testl %eax, %eax
jne 0xc6ff
leaq -0x250(%rbp), %rax
movq %rax, -0x260(%rbp)
movq -0x148(%rbp), %rsi
movq -0x140(%rbp), %rdx
addq %rsi, %rdx
leaq -0x260(%rbp), %r12
movq %r12, %rdi
callq 0x6876
leaq -0x198(%rbp), %r15
movq %r15, %rdi
movq %r12, %rsi
callq 0x946c
leaq -0x148(%rbp), %rdi
movq %r15, %rsi
callq 0x43b0
movq -0x198(%rbp), %rdi
leaq -0x188(%rbp), %rax
cmpq %rax, %rdi
je 0xc6c5
callq 0x42f0
movq -0x260(%rbp), %rdi
leaq -0x250(%rbp), %rax
cmpq %rax, %rdi
je 0xc6dd
callq 0x42f0
movq -0xc0(%rbp), %rdx
movl $0x2, %r8d
leaq -0xc8(%rbp), %rdi
xorl %esi, %esi
leaq 0x9a94(%rip), %rcx      # 0x1618e
callq 0x44f0
movq 0x10(%rbx), %rdi
addq %r13, %rdi
callq 0x9610
cmpl $0x1, %eax
jne 0xc7b5
leaq -0x230(%rbp), %rax
movq %rax, -0x240(%rbp)
movq -0x128(%rbp), %rsi
movq -0x120(%rbp), %rdx
addq %rsi, %rdx
leaq -0x240(%rbp), %r12
movq %r12, %rdi
callq 0x6876
leaq -0x198(%rbp), %r15
movq %r15, %rdi
movq %r12, %rsi
callq 0x946c
leaq -0x128(%rbp), %rdi
movq %r15, %rsi
callq 0x43b0
movq -0x198(%rbp), %rdi
leaq -0x188(%rbp), %rax
cmpq %rax, %rdi
je 0xc77b
callq 0x42f0
movq -0x240(%rbp), %rdi
leaq -0x230(%rbp), %rax
cmpq %rax, %rdi
je 0xc793
callq 0x42f0
movq -0xa0(%rbp), %rdx
movl $0x2, %r8d
leaq -0xa8(%rbp), %rdi
xorl %esi, %esi
leaq 0x99de(%rip), %rcx      # 0x1618e
callq 0x44f0
movq 0x10(%rbx), %rax
movups (%rax,%r13), %xmm0
movups 0x10(%rax,%r13), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movq %rbx, %rdi
callq 0xa338
movq (%rbx), %rsi
movl -0x30(%rbp), %edx
leaq -0x198(%rbp), %r15
movq %r15, %rdi
callq 0x13c48
leaq -0x2a0(%rbp), %r12
movq %r12, %rdi
movq %r15, %rsi
callq 0x5ca8
movq -0xc8(%rbp), %rsi
movq -0xc0(%rbp), %rdx
movq %r12, %rdi
callq 0x40f0
leaq -0xf8(%rbp), %rsi
movq %rsi, -0x108(%rbp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
leaq -0x2f0(%rbp), %r15
je 0xc849
movq %rdx, -0x108(%rbp)
movq (%rcx), %rdx
movq %rdx, -0xf8(%rbp)
jmp 0xc84f
movups (%rcx), %xmm0
movups %xmm0, (%rsi)
movq 0x8(%rax), %rdx
movq %rdx, -0x100(%rbp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq (%rbx), %rsi
movl -0x2c(%rbp), %edx
movq %r15, %rdi
callq 0x13c48
leaq -0x280(%rbp), %r12
movq %r12, %rdi
movq %r15, %rsi
callq 0x5ca8
movq -0xa8(%rbp), %rsi
movq -0xa0(%rbp), %rdx
movq %r12, %rdi
callq 0x40f0
leaq -0xd8(%rbp), %rsi
movq %rsi, -0xe8(%rbp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
leaq -0x310(%rbp), %r15
je 0xc8d6
movq %rdx, -0xe8(%rbp)
movq (%rcx), %rdx
movq %rdx, -0xd8(%rbp)
jmp 0xc8dc
movups (%rcx), %xmm0
movups %xmm0, (%rsi)
movq 0x8(%rax), %rdx
movq %rdx, -0xe0(%rbp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq %r15, %rdi
leaq -0x108(%rbp), %rdx
leaq -0xe8(%rbp), %rcx
callq 0xa1b8
leaq -0x50(%rbp), %rdi
movq %r15, %rsi
callq 0x43b0
movq -0x310(%rbp), %rdi
leaq -0x300(%rbp), %rax
cmpq %rax, %rdi
je 0xc930
callq 0x42f0
movq -0xe8(%rbp), %rdi
leaq -0xd8(%rbp), %rax
cmpq %rax, %rdi
je 0xc948
callq 0x42f0
movq -0x280(%rbp), %rdi
leaq -0x270(%rbp), %rax
cmpq %rax, %rdi
je 0xc960
callq 0x42f0
leaq -0x2f0(%rbp), %rdi
callq 0x59a6
movq -0x108(%rbp), %rdi
leaq -0xf8(%rbp), %rax
cmpq %rax, %rdi
je 0xc984
callq 0x42f0
movq -0x2a0(%rbp), %rdi
leaq -0x290(%rbp), %rax
cmpq %rax, %rdi
je 0xc99c
callq 0x42f0
leaq -0x198(%rbp), %rdi
callq 0x59a6
leaq -0x2f0(%rbp), %r12
movq %r12, %rdi
leaq 0x97d8(%rip), %rsi      # 0x16191
leaq -0x50(%rbp), %rdx
callq 0xd67f
movq %r14, %r15
movq %r12, %rdi
leaq 0x9854(%rip), %rsi      # 0x16223
callq 0x45f0
leaq -0x188(%rbp), %r14
movq %r14, -0x198(%rbp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0xca04
movq %rdx, -0x198(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x188(%rbp)
jmp 0xca0b
movups (%rcx), %xmm0
movups %xmm0, (%r14)
movq 0x8(%rax), %rdx
movq %rdx, -0x190(%rbp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq -0x50(%rbp), %rdi
leaq -0x198(%rbp), %rsi
callq 0x43b0
movq -0x198(%rbp), %rdi
cmpq %r14, %rdi
je 0xca46
callq 0x42f0
movq -0x2f0(%rbp), %rdi
leaq -0x2e0(%rbp), %rax
cmpq %rax, %rdi
movq %r15, %r14
je 0xca61
callq 0x42f0
movq 0x30(%rbx), %rsi
cmpq 0x38(%rbx), %rsi
je 0xca7a
movl -0x30(%rbp), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x30(%rbx)
jmp 0xca87
movq -0x78(%rbp), %rdi
leaq -0x30(%rbp), %rdx
callq 0xd8fa
movq 0x30(%rbx), %rsi
cmpq 0x38(%rbx), %rsi
je 0xcaa0
movl -0x2c(%rbp), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x30(%rbx)
jmp 0xcaad
movq -0x78(%rbp), %rdi
leaq -0x2c(%rbp), %rdx
callq 0xd8fa
leaq -0x1f0(%rbp), %rax
movq %rax, -0x200(%rbp)
movq -0x148(%rbp), %rsi
movq -0x140(%rbp), %rdx
addq %rsi, %rdx
leaq -0x200(%rbp), %rdi
callq 0x6876
leaq -0x1d0(%rbp), %rax
movq %rax, -0x1e0(%rbp)
movq -0x128(%rbp), %rsi
movq -0x120(%rbp), %rdx
addq %rsi, %rdx
leaq -0x1e0(%rbp), %rdi
callq 0x6876
addq 0x10(%rbx), %r13
movq %r13, %rdi
callq 0x95e8
leaq -0x198(%rbp), %r15
movq %r15, %rdi
leaq -0x200(%rbp), %rdx
leaq -0x1e0(%rbp), %rcx
movl %eax, %r8d
callq 0xb762
leaq -0x70(%rbp), %rdi
movq %r15, %rsi
callq 0x43b0
movq -0x198(%rbp), %rdi
leaq -0x188(%rbp), %rax
cmpq %rax, %rdi
je 0xcb53
callq 0x42f0
movq -0x1e0(%rbp), %rdi
leaq -0x1d0(%rbp), %rax
cmpq %rax, %rdi
je 0xcb6b
callq 0x42f0
movq -0x200(%rbp), %rdi
leaq -0x1f0(%rbp), %rax
cmpq %rax, %rdi
je 0xcb83
callq 0x42f0
leaq -0x1b0(%rbp), %rax
movq %rax, -0x1c0(%rbp)
movq -0x70(%rbp), %rsi
movq -0x68(%rbp), %rdx
addq %rsi, %rdx
leaq -0x1c0(%rbp), %rdi
callq 0x6876
leaq -0x210(%rbp), %rax
movq %rax, -0x220(%rbp)
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rdx
addq %rsi, %rdx
leaq -0x220(%rbp), %r15
movq %r15, %rdi
callq 0x6876
movl -0x30(%rbp), %ecx
movl -0x2c(%rbp), %r8d
movq %rbx, %rdi
leaq -0x1c0(%rbp), %rsi
movq %r15, %rdx
callq 0xa890
movq -0x220(%rbp), %rdi
leaq -0x210(%rbp), %rax
cmpq %rax, %rdi
je 0xcc01
callq 0x42f0
movq -0x1c0(%rbp), %rdi
leaq -0x1b0(%rbp), %rax
cmpq %rax, %rdi
je 0xcc19
callq 0x42f0
movq (%rbx), %rdi
callq 0x13c88
movl %eax, %r13d
incq %r14
movq 0x10(%rbx), %rdi
movq 0x18(%rbx), %rax
subq %rdi, %rax
sarq $0x5, %rax
movq %r14, -0x1a0(%rbp)
cmpq %r14, %rax
jbe 0xcd3d
decl %r13d
movq -0x80(%rbp), %r12
movq -0x88(%rbp), %r15
movl -0x30(%rbp), %r14d
addq %r12, %rdi
callq 0x95f2
cmpl %eax, %r14d
jne 0xcc88
movq 0x10(%rbx), %rdi
addq %r12, %rdi
xorl %r14d, %r14d
movl %r13d, %esi
callq 0x95aa
movq 0x10(%rbx), %rdi
addq %r12, %rdi
movl %r14d, %esi
callq 0x95ca
jmp 0xccbe
movl -0x30(%rbp), %r14d
movq 0x10(%rbx), %rdi
addq %r12, %rdi
callq 0x95fc
cmpl %eax, %r14d
jne 0xccdf
movq 0x10(%rbx), %rdi
addq %r12, %rdi
xorl %r14d, %r14d
movl %r13d, %esi
callq 0x95b4
movq 0x10(%rbx), %rdi
addq %r12, %rdi
movl %r14d, %esi
callq 0x95d4
incq %r15
movq 0x10(%rbx), %rdi
movq 0x18(%rbx), %rax
subq %rdi, %rax
sarq $0x5, %rax
addq $0x20, %r12
cmpq %r15, %rax
ja 0xcc54
jmp 0xcd3d
movl -0x2c(%rbp), %r14d
movq 0x10(%rbx), %rdi
addq %r12, %rdi
callq 0x95f2
cmpl %eax, %r14d
jne 0xcd0e
movq 0x10(%rbx), %rdi
addq %r12, %rdi
movl $0x1, %r14d
movl %r13d, %esi
callq 0x95aa
jmp 0xcc77
movl -0x2c(%rbp), %r14d
movq 0x10(%rbx), %rdi
addq %r12, %rdi
callq 0x95fc
cmpl %eax, %r14d
jne 0xccbe
movq 0x10(%rbx), %rdi
addq %r12, %rdi
movl $0x1, %r14d
movl %r13d, %esi
callq 0x95b4
jmp 0xccaf
movq -0xa8(%rbp), %rdi
leaq -0x98(%rbp), %rax
cmpq %rax, %rdi
je 0xcd55
callq 0x42f0
movq -0xc8(%rbp), %rdi
leaq -0xb8(%rbp), %r12
cmpq %r12, %rdi
leaq -0x40(%rbp), %r14
leaq -0x60(%rbp), %r15
je 0xcd75
callq 0x42f0
movq -0x70(%rbp), %rdi
cmpq %r15, %rdi
je 0xcd83
callq 0x42f0
movq -0x50(%rbp), %rdi
cmpq %r14, %rdi
movq -0x1a0(%rbp), %r14
je 0xcd98
callq 0x42f0
movq -0x128(%rbp), %rdi
leaq -0x118(%rbp), %rax
cmpq %rax, %rdi
je 0xcdb0
callq 0x42f0
movq -0x148(%rbp), %rdi
leaq -0x138(%rbp), %rax
cmpq %rax, %rdi
je 0xcdc8
callq 0x42f0
movq 0x10(%rbx), %rdi
movq 0x18(%rbx), %rax
subq %rdi, %rax
sarq $0x5, %rax
incq -0x88(%rbp)
addq $0x20, -0x80(%rbp)
cmpq %r14, %rax
ja 0xc563
addq $0x308, %rsp            # imm = 0x308
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq -0x260(%rbp), %rdi
leaq -0x250(%rbp), %rax
jmp 0xcfc7
jmp 0xcfd5
jmp 0xcfd5
movq %rax, %rbx
movq -0x240(%rbp), %rdi
leaq -0x230(%rbp), %rax
jmp 0xcfc7
movq %rax, %rbx
jmp 0xce54
movq %rax, %rbx
movq -0x220(%rbp), %rdi
leaq -0x210(%rbp), %rax
cmpq %rax, %rdi
je 0xce54
callq 0x42f0
movq -0x1c0(%rbp), %rdi
leaq -0x1b0(%rbp), %rax
jmp 0xcfc7
jmp 0xcfd5
movq %rax, %rbx
jmp 0xcea9
movq %rax, %rbx
jmp 0xce91
movq %rax, %rbx
movq -0xe8(%rbp), %rdi
leaq -0xd8(%rbp), %rax
cmpq %rax, %rdi
je 0xce91
callq 0x42f0
movq -0x280(%rbp), %rdi
leaq -0x270(%rbp), %rax
cmpq %rax, %rdi
je 0xcea9
callq 0x42f0
leaq -0x2f0(%rbp), %rdi
callq 0x59a6
jmp 0xcf58
jmp 0xcfd5
movq %rax, %rbx
movq -0x2f0(%rbp), %rdi
leaq -0x2e0(%rbp), %rax
jmp 0xcfc7
jmp 0xcfd5
movq %rax, %rbx
jmp 0xcfb9
movq %rax, %rbx
leaq -0x198(%rbp), %rdi
callq 0x59a6
jmp 0xd05c
movq %rax, %rbx
jmp 0xd044
movq %rax, %rbx
leaq -0x198(%rbp), %rdi
callq 0x59a6
jmp 0xd044
movq %rax, %rbx
jmp 0xd02c
movq %rax, %rbx
leaq -0x40(%rbp), %r14
jmp 0xd01e
movq %rax, %rbx
leaq -0x40(%rbp), %r14
leaq -0x60(%rbp), %r15
jmp 0xd010
movq %rax, %rbx
leaq -0x40(%rbp), %r14
leaq -0x60(%rbp), %r15
jmp 0xcff8
jmp 0xcfd5
movq %rax, %rbx
jmp 0xcf88
movq %rax, %rbx
jmp 0xcf70
movq %rax, %rbx
movq -0x108(%rbp), %rdi
leaq -0xf8(%rbp), %rax
cmpq %rax, %rdi
je 0xcf70
callq 0x42f0
movq -0x2a0(%rbp), %rdi
leaq -0x290(%rbp), %rax
cmpq %rax, %rdi
je 0xcf88
callq 0x42f0
leaq -0x40(%rbp), %r14
leaq -0x60(%rbp), %r15
leaq -0x198(%rbp), %rdi
callq 0x59a6
jmp 0xcfe0
movq %rax, %rbx
movq -0x1e0(%rbp), %rdi
leaq -0x1d0(%rbp), %rax
cmpq %rax, %rdi
je 0xcfb9
callq 0x42f0
movq -0x200(%rbp), %rdi
leaq -0x1f0(%rbp), %rax
cmpq %rax, %rdi
je 0xcfd8
callq 0x42f0
jmp 0xcfd8
jmp 0xcfd5
movq %rax, %rbx
leaq -0x40(%rbp), %r14
leaq -0x60(%rbp), %r15
movq -0xa8(%rbp), %rdi
leaq -0x98(%rbp), %rax
cmpq %rax, %rdi
je 0xcff8
callq 0x42f0
movq -0xc8(%rbp), %rdi
leaq -0xb8(%rbp), %rax
cmpq %rax, %rdi
je 0xd010
callq 0x42f0
movq -0x70(%rbp), %rdi
cmpq %r15, %rdi
je 0xd01e
callq 0x42f0
movq -0x50(%rbp), %rdi
cmpq %r14, %rdi
je 0xd02c
callq 0x42f0
movq -0x128(%rbp), %rdi
leaq -0x118(%rbp), %rax
cmpq %rax, %rdi
je 0xd044
callq 0x42f0
movq -0x148(%rbp), %rdi
leaq -0x138(%rbp), %rax
cmpq %rax, %rdi
je 0xd05c
callq 0x42f0
movq %rbx, %rdi
callq 0x4590