// File: /workspace/github_cpp_makefile_star2_O2/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 $0x318, %rsp            # imm = 0x318
movq %rdi, %rbx
leaq 0x28(%rdi), %rax
movq %rax, -0x40(%rbp)
pushq $0x1
popq %rcx
pushq $0x20
popq %r15
xorl %r13d, %r13d
leaq -0x1c8(%rbp), %r12
movq 0x10(%rbx), %rdi
movq 0x18(%rbx), %rax
subq %rdi, %rax
sarq $0x5, %rax
cmpq %r13, %rax
jbe 0xa9e2
movq %rcx, -0x58(%rbp)
movq %r13, -0x50(%rbp)
shlq $0x5, %r13
addq %r13, %rdi
callq 0x81ca
movl %eax, -0x30(%rbp)
movq 0x10(%rbx), %rdi
movq %r13, -0x38(%rbp)
addq %r13, %rdi
callq 0x81d4
movl %eax, -0x2c(%rbp)
movq (%rbx), %rsi
movl -0x30(%rbp), %edx
leaq -0x168(%rbp), %r14
movq %r14, %rdi
callq 0x107a4
leaq -0xb8(%rbp), %rdi
movq %r14, %rsi
callq 0x5534
movq %r14, %rdi
callq 0x5328
movq (%rbx), %rsi
movl -0x2c(%rbp), %edx
movq %r14, %rdi
callq 0x107a4
movq %r15, -0x48(%rbp)
leaq -0x98(%rbp), %rdi
movq %r14, %rsi
callq 0x5534
movq %r14, %rdi
callq 0x5328
leaq -0x78(%rbp), %rdi
leaq 0x89fa(%rip), %r15      # 0x12f4c
movq %r15, %rsi
movq %r14, %rdx
callq 0x4120
leaq -0x118(%rbp), %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x4120
leaq -0xf8(%rbp), %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x4120
leaq -0xd8(%rbp), %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x4120
movq 0x10(%rbx), %rdi
addq -0x38(%rbp), %rdi
callq 0x81de
testl %eax, %eax
jne 0xa5f7
leaq -0x2a8(%rbp), %r15
movq %r15, %rdi
leaq -0xb8(%rbp), %rsi
callq 0x4410
movq %r14, %rdi
movq %r15, %rsi
callq 0x802c
leaq -0xb8(%rbp), %rdi
movq %r14, %rsi
callq 0x4390
movq %r14, %rdi
callq 0x4160
movq %r15, %rdi
callq 0x4160
leaq -0xf8(%rbp), %rdi
leaq 0x8b9c(%rip), %rsi      # 0x1318e
callq 0x4600
movq 0x10(%rbx), %rdi
addq -0x38(%rbp), %rdi
callq 0x81e8
cmpl $0x1, %eax
jne 0xa65c
leaq -0x288(%rbp), %r15
movq %r15, %rdi
leaq -0x98(%rbp), %rsi
callq 0x4410
movq %r14, %rdi
movq %r15, %rsi
callq 0x802c
leaq -0x98(%rbp), %rdi
movq %r14, %rsi
callq 0x4390
movq %r14, %rdi
callq 0x4160
movq %r15, %rdi
callq 0x4160
leaq -0xd8(%rbp), %rdi
leaq 0x8b37(%rip), %rsi      # 0x1318e
callq 0x4600
movq 0x10(%rbx), %rax
movq -0x38(%rbp), %rcx
movups (%rax,%rcx), %xmm0
movups 0x10(%rax,%rcx), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movq %rbx, %rdi
callq 0x8c78
movq (%rbx), %rsi
movl -0x30(%rbp), %edx
movq %r14, %rdi
callq 0x107a4
leaq -0x208(%rbp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x5550
leaq -0x228(%rbp), %rdi
movq %r15, %rsi
leaq -0xf8(%rbp), %rdx
callq 0x5a47
movq (%rbx), %rsi
movl -0x2c(%rbp), %edx
leaq -0x2f8(%rbp), %r14
movq %r14, %rdi
callq 0x107a4
movq %r12, %rdi
movq %r14, %rsi
callq 0x5550
leaq -0x228(%rbp), %r14
movq %r12, %rsi
leaq -0x1e8(%rbp), %r15
movq %r15, %rdi
leaq -0xd8(%rbp), %rdx
callq 0x5a47
leaq -0x318(%rbp), %r13
movq %r13, %rdi
movq %r14, %rdx
movq %r15, %rcx
callq 0x8b7c
leaq -0x78(%rbp), %r15
movq %r15, %rdi
movq %r13, %rsi
callq 0x4390
movq %r13, %rdi
callq 0x4160
leaq -0x1e8(%rbp), %rdi
callq 0x4160
movq %r12, %rdi
callq 0x4160
leaq -0x2f8(%rbp), %r12
movq %r12, %rdi
callq 0x5328
movq %r14, %rdi
callq 0x4160
leaq -0x208(%rbp), %rdi
callq 0x4160
leaq -0x168(%rbp), %r14
movq %r14, %rdi
callq 0x5328
movq %r12, %rdi
leaq 0x8a21(%rip), %rsi      # 0x13191
movq %r15, %rdx
callq 0xae38
movq %r14, %rdi
movq %r12, %rsi
leaq 0x8a9e(%rip), %rdx      # 0x13223
callq 0x5a70
leaq -0x78(%rbp), %rdi
movq %r14, %rsi
callq 0x4390
movq %r14, %rdi
callq 0x4160
movq %r12, %rdi
callq 0x4160
movq -0x40(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0xaf4e
movq -0x40(%rbp), %rdi
leaq -0x2c(%rbp), %rsi
callq 0xaf4e
leaq -0x268(%rbp), %r15
movq %r15, %rdi
leaq -0xb8(%rbp), %rsi
callq 0x4410
leaq -0x1a8(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x4410
movq -0x38(%rbp), %rdi
addq 0x10(%rbx), %rdi
callq 0x81c0
leaq -0x1a8(%rbp), %r13
movq %r14, %rdi
movq %r15, %rdx
movq %r13, %rcx
movl %eax, %r8d
callq 0x9a2a
movq %r15, %r12
leaq -0x118(%rbp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x4390
movq %r14, %rdi
callq 0x4160
movq %r13, %rdi
callq 0x4160
movq %r12, %rdi
callq 0x4160
leaq -0x188(%rbp), %rdi
movq %r15, %rsi
callq 0x4410
leaq -0x248(%rbp), %r15
movq %r15, %rdi
leaq -0x78(%rbp), %rsi
callq 0x4410
movl -0x30(%rbp), %ecx
movl -0x2c(%rbp), %r8d
movq %rbx, %rdi
leaq -0x188(%rbp), %r14
movq %r14, %rsi
movq %r15, %rdx
callq 0x8f5c
movq %r15, %rdi
callq 0x4160
movq %r14, %rdi
callq 0x4160
movq (%rbx), %rdi
callq 0x107dc
movl %eax, %r13d
decl %r13d
incq -0x50(%rbp)
movq -0x48(%rbp), %r12
movq -0x58(%rbp), %r15
movq 0x10(%rbx), %rdi
movq 0x18(%rbx), %rax
subq %rdi, %rax
sarq $0x5, %rax
cmpq %r15, %rax
jbe 0xa985
movl -0x30(%rbp), %r14d
addq %r12, %rdi
callq 0x81ca
cmpl %eax, %r14d
jne 0xa8ef
movq 0x10(%rbx), %rdi
addq %r12, %rdi
xorl %r14d, %r14d
movl %r13d, %esi
callq 0x8182
movq 0x10(%rbx), %rdi
addq %r12, %rdi
movl %r14d, %esi
callq 0x81a2
jmp 0xa925
movl -0x30(%rbp), %r14d
movq 0x10(%rbx), %rdi
addq %r12, %rdi
callq 0x81d4
cmpl %eax, %r14d
jne 0xa931
movq 0x10(%rbx), %rdi
addq %r12, %rdi
xorl %r14d, %r14d
movl %r13d, %esi
callq 0x818c
movq 0x10(%rbx), %rdi
addq %r12, %rdi
movl %r14d, %esi
callq 0x81ac
incq %r15
addq $0x20, %r12
jmp 0xa8a3
movl -0x2c(%rbp), %r14d
movq 0x10(%rbx), %rdi
addq %r12, %rdi
callq 0x81ca
cmpl %eax, %r14d
jne 0xa95b
movq 0x10(%rbx), %rdi
addq %r12, %rdi
movl %r13d, %esi
callq 0x8182
pushq $0x1
popq %r14
jmp 0xa8de
movl -0x2c(%rbp), %r14d
movq 0x10(%rbx), %rdi
addq %r12, %rdi
callq 0x81d4
cmpl %eax, %r14d
jne 0xa925
movq 0x10(%rbx), %rdi
addq %r12, %rdi
movl %r13d, %esi
callq 0x818c
pushq $0x1
popq %r14
jmp 0xa916
leaq -0xd8(%rbp), %rdi
callq 0x4160
leaq -0xf8(%rbp), %rdi
callq 0x4160
leaq -0x118(%rbp), %rdi
callq 0x4160
leaq -0x78(%rbp), %rdi
callq 0x4160
leaq -0x98(%rbp), %rdi
callq 0x4160
leaq -0xb8(%rbp), %rdi
callq 0x4160
movq -0x58(%rbp), %rcx
incq %rcx
movq -0x48(%rbp), %r15
addq $0x20, %r15
movq -0x50(%rbp), %r13
jmp 0xa4a9
addq $0x318, %rsp            # imm = 0x318
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq -0x2a8(%rbp), %rdi
jmp 0xab2d
jmp 0xab36
jmp 0xab36
movq %rax, %rbx
leaq -0x288(%rbp), %rdi
jmp 0xab2d
movq %rax, %rbx
jmp 0xaa50
jmp 0xab36
movq %rax, %rbx
leaq -0x1e8(%rbp), %rdi
callq 0x4160
jmp 0xaa44
jmp 0xab36
movq %rax, %rbx
jmp 0xaa78
movq %rax, %rbx
leaq -0x1c8(%rbp), %rdi
callq 0x4160
leaq -0x2f8(%rbp), %rdi
callq 0x5328
jmp 0xaae7
movq %rax, %rbx
jmp 0xab26
movq %rax, %rbx
leaq -0x248(%rbp), %rdi
callq 0x4160
leaq -0x188(%rbp), %rdi
jmp 0xab2d
movq %rax, %rbx
leaq -0x2f8(%rbp), %rdi
jmp 0xab2d
jmp 0xab36
movq %rax, %rbx
jmp 0xab72
movq %rax, %rbx
jmp 0xab51
movq %rax, %rbx
leaq -0x168(%rbp), %rdi
callq 0x5328
jmp 0xab72
movq %rax, %rbx
jmp 0xab04
movq %rax, %rbx
leaq -0x168(%rbp), %rdi
callq 0x5328
jmp 0xab7e
jmp 0xab36
movq %rax, %rbx
jmp 0xab45
movq %rax, %rbx
jmp 0xab66
movq %rax, %rbx
leaq -0x228(%rbp), %rdi
callq 0x4160
jmp 0xaaf8
movq %rax, %rbx
leaq -0x208(%rbp), %rdi
callq 0x4160
leaq -0x168(%rbp), %rdi
callq 0x5328
jmp 0xab39
movq %rax, %rbx
jmp 0xab5d
movq %rax, %rbx
leaq -0x1a8(%rbp), %rdi
callq 0x4160
leaq -0x268(%rbp), %rdi
callq 0x4160
jmp 0xab39
jmp 0xab36
movq %rax, %rbx
leaq -0xd8(%rbp), %rdi
callq 0x4160
leaq -0xf8(%rbp), %rdi
callq 0x4160
leaq -0x118(%rbp), %rdi
callq 0x4160
leaq -0x78(%rbp), %rdi
callq 0x4160
leaq -0x98(%rbp), %rdi
callq 0x4160
leaq -0xb8(%rbp), %rdi
callq 0x4160
movq %rbx, %rdi
callq 0x4590