// File: 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
subq $0x560, %rsp            # imm = 0x560
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x480(%rbp)
movl $0x0, -0xc(%rbp)
movq -0x480(%rbp), %rdi
movslq -0xc(%rbp), %rax
movq %rax, -0x488(%rbp)
addq $0x10, %rdi
callq 0x15530
movq %rax, %rcx
movq -0x488(%rbp), %rax
cmpq %rcx, %rax
jae 0x14e96
movq -0x480(%rbp), %rdi
addq $0x10, %rdi
movq %rdi, -0x498(%rbp)
movslq -0xc(%rbp), %rsi
callq 0x15550
movq %rax, %rdi
callq 0x10030
movq -0x498(%rbp), %rdi
movl %eax, -0x10(%rbp)
movslq -0xc(%rbp), %rsi
callq 0x15550
movq %rax, %rdi
callq 0x10050
movl %eax, %ecx
movq -0x480(%rbp), %rax
movl %ecx, -0x14(%rbp)
movq (%rax), %rsi
movl -0x10(%rbp), %edx
leaq -0x88(%rbp), %rdi
movq %rdi, -0x490(%rbp)
callq 0x28150
movq -0x490(%rbp), %rsi
leaq -0x38(%rbp), %rdi
callq 0x5e50
jmp 0x142d4
leaq -0x88(%rbp), %rdi
callq 0x5b00
movq -0x480(%rbp), %rax
movq (%rax), %rsi
movl -0x14(%rbp), %edx
leaq -0x108(%rbp), %rdi
callq 0x28150
jmp 0x142fb
leaq -0xb8(%rbp), %rdi
leaq -0x108(%rbp), %rsi
callq 0x5e50
jmp 0x14310
leaq -0x108(%rbp), %rdi
callq 0x5b00
leaq -0x129(%rbp), %rdi
movq %rdi, -0x4a0(%rbp)
callq 0x46e0
movq -0x4a0(%rbp), %rdx
leaq 0x17e7b(%rip), %rsi     # 0x2c1b8
leaq -0x128(%rbp), %rdi
callq 0x4530
jmp 0x1434b
leaq -0x129(%rbp), %rdi
callq 0x4420
leaq -0x151(%rbp), %rdi
movq %rdi, -0x4a8(%rbp)
callq 0x46e0
movq -0x4a8(%rbp), %rdx
leaq 0x17e40(%rip), %rsi     # 0x2c1b8
leaq -0x150(%rbp), %rdi
callq 0x4530
jmp 0x14386
leaq -0x151(%rbp), %rdi
callq 0x4420
leaq -0x179(%rbp), %rdi
movq %rdi, -0x4b0(%rbp)
callq 0x46e0
movq -0x4b0(%rbp), %rdx
leaq 0x17e05(%rip), %rsi     # 0x2c1b8
leaq -0x178(%rbp), %rdi
callq 0x4530
jmp 0x143c1
leaq -0x179(%rbp), %rdi
callq 0x4420
leaq -0x1a1(%rbp), %rdi
movq %rdi, -0x4b8(%rbp)
callq 0x46e0
movq -0x4b8(%rbp), %rdx
leaq 0x17dca(%rip), %rsi     # 0x2c1b8
leaq -0x1a0(%rbp), %rdi
callq 0x4530
jmp 0x143fc
leaq -0x1a1(%rbp), %rdi
callq 0x4420
movq -0x480(%rbp), %rdi
addq $0x10, %rdi
movslq -0xc(%rbp), %rsi
callq 0x15550
movq %rax, %rdi
callq 0x10070
movl %eax, -0x4bc(%rbp)
jmp 0x1442c
movl -0x4bc(%rbp), %eax
cmpl $0x0, %eax
jne 0x145ce
leaq -0x1e8(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x41b0
jmp 0x1444d
leaq -0x1c8(%rbp), %rdi
leaq -0x1e8(%rbp), %rsi
callq 0xfc10
jmp 0x14462
leaq -0x38(%rbp), %rdi
leaq -0x1c8(%rbp), %rsi
movq %rsi, -0x4c8(%rbp)
callq 0x4480
movq -0x4c8(%rbp), %rdi
callq 0x4270
leaq -0x1e8(%rbp), %rdi
callq 0x4270
leaq 0x17f66(%rip), %rsi     # 0x2c3fe
leaq -0x178(%rbp), %rdi
callq 0x4520
jmp 0x144a6
jmp 0x145ce
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
leaq -0x88(%rbp), %rdi
callq 0x5b00
jmp 0x14e9f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
jmp 0x14e8b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
leaq -0x108(%rbp), %rdi
callq 0x5b00
jmp 0x14e8b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
leaq -0x129(%rbp), %rdi
callq 0x4420
jmp 0x14e7f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
leaq -0x151(%rbp), %rdi
callq 0x4420
jmp 0x14e73
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
leaq -0x179(%rbp), %rdi
callq 0x4420
jmp 0x14e67
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
leaq -0x1a1(%rbp), %rdi
callq 0x4420
jmp 0x14e5b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
jmp 0x14e4f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
leaq -0x1e8(%rbp), %rdi
callq 0x4270
jmp 0x14e4f
movq -0x480(%rbp), %rdi
addq $0x10, %rdi
movslq -0xc(%rbp), %rsi
callq 0x15550
movq %rax, %rdi
callq 0x10090
movl %eax, -0x4cc(%rbp)
jmp 0x145f2
movl -0x4cc(%rbp), %eax
cmpl $0x1, %eax
jne 0x14697
leaq -0x228(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
callq 0x41b0
jmp 0x14616
leaq -0x208(%rbp), %rdi
leaq -0x228(%rbp), %rsi
callq 0xfc10
jmp 0x1462b
leaq -0xb8(%rbp), %rdi
leaq -0x208(%rbp), %rsi
movq %rsi, -0x4d8(%rbp)
callq 0x4480
movq -0x4d8(%rbp), %rdi
callq 0x4270
leaq -0x228(%rbp), %rdi
callq 0x4270
leaq 0x17d9a(%rip), %rsi     # 0x2c3fe
leaq -0x1a0(%rbp), %rdi
callq 0x4520
jmp 0x14672
jmp 0x14697
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
leaq -0x228(%rbp), %rdi
callq 0x4270
jmp 0x14e4f
movq -0x480(%rbp), %rdi
addq $0x10, %rdi
movslq -0xc(%rbp), %rsi
callq 0x15550
movq -0x480(%rbp), %rdi
movups (%rax), %xmm0
movups 0x10(%rax), %xmm1
movaps %xmm1, -0x240(%rbp)
movaps %xmm0, -0x250(%rbp)
movaps -0x250(%rbp), %xmm0
movaps -0x240(%rbp), %xmm1
movq %rsp, %rax
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
callq 0x11580
jmp 0x146e6
movq -0x480(%rbp), %rax
movq (%rax), %rsi
movl -0x10(%rbp), %edx
leaq -0x300(%rbp), %rdi
callq 0x28150
jmp 0x14701
leaq -0x2b0(%rbp), %rdi
leaq -0x300(%rbp), %rsi
callq 0x5e80
jmp 0x14716
leaq -0x290(%rbp), %rdi
leaq -0x2b0(%rbp), %rsi
leaq -0x178(%rbp), %rdx
callq 0x6a10
jmp 0x14732
movq -0x480(%rbp), %rax
movq (%rax), %rsi
movl -0x14(%rbp), %edx
leaq -0x390(%rbp), %rdi
callq 0x28150
jmp 0x1474d
leaq -0x340(%rbp), %rdi
leaq -0x390(%rbp), %rsi
callq 0x5e80
jmp 0x14762
leaq -0x320(%rbp), %rdi
leaq -0x340(%rbp), %rsi
leaq -0x1a0(%rbp), %rdx
callq 0x6a10
jmp 0x1477e
movq -0x480(%rbp), %rsi
leaq -0x270(%rbp), %rdi
leaq -0x290(%rbp), %rdx
leaq -0x320(%rbp), %rcx
callq 0x113f0
jmp 0x147a1
leaq -0x128(%rbp), %rdi
movq %rdi, -0x4e0(%rbp)
leaq -0x270(%rbp), %rsi
movq %rsi, -0x4e8(%rbp)
callq 0x4480
movq -0x4e8(%rbp), %rdi
callq 0x4270
leaq -0x320(%rbp), %rdi
callq 0x4270
leaq -0x340(%rbp), %rdi
callq 0x4270
leaq -0x390(%rbp), %rdi
callq 0x5b00
leaq -0x290(%rbp), %rdi
callq 0x4270
leaq -0x2b0(%rbp), %rdi
callq 0x4270
leaq -0x300(%rbp), %rdi
callq 0x5b00
movq -0x4e0(%rbp), %rdx
leaq 0x17bdd(%rip), %rsi     # 0x2c401
leaq -0x3d0(%rbp), %rdi
callq 0x152c0
jmp 0x14832
leaq 0x17c4a(%rip), %rdx     # 0x2c483
leaq -0x3b0(%rbp), %rdi
leaq -0x3d0(%rbp), %rsi
callq 0x6a60
jmp 0x1484e
leaq -0x128(%rbp), %rdi
leaq -0x3b0(%rbp), %rsi
movq %rsi, -0x4f0(%rbp)
callq 0x4480
movq -0x4f0(%rbp), %rdi
callq 0x4270
leaq -0x3d0(%rbp), %rdi
callq 0x4270
movq -0x480(%rbp), %rdi
addq $0x28, %rdi
leaq -0x10(%rbp), %rsi
callq 0x15690
jmp 0x14896
movq -0x480(%rbp), %rdi
addq $0x28, %rdi
leaq -0x14(%rbp), %rsi
callq 0x15690
jmp 0x148ac
leaq -0x410(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x41b0
jmp 0x148be
leaq -0x430(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
callq 0x41b0
jmp 0x148d3
movq -0x480(%rbp), %rdi
addq $0x10, %rdi
movslq -0xc(%rbp), %rsi
callq 0x15550
movq %rax, %rdi
callq 0x10010
movl %eax, -0x4f4(%rbp)
jmp 0x148f7
movl -0x4f4(%rbp), %r8d
movq -0x480(%rbp), %rsi
leaq -0x3f0(%rbp), %rdi
leaq -0x410(%rbp), %rdx
leaq -0x430(%rbp), %rcx
callq 0x12f30
jmp 0x14921
leaq -0x150(%rbp), %rdi
movq %rdi, -0x500(%rbp)
leaq -0x3f0(%rbp), %rsi
movq %rsi, -0x508(%rbp)
callq 0x4480
movq -0x508(%rbp), %rdi
callq 0x4270
leaq -0x430(%rbp), %rdi
callq 0x4270
leaq -0x410(%rbp), %rdi
callq 0x4270
movq -0x500(%rbp), %rsi
leaq -0x450(%rbp), %rdi
callq 0x41b0
jmp 0x1497b
leaq -0x470(%rbp), %rdi
leaq -0x128(%rbp), %rsi
callq 0x41b0
jmp 0x14990
movq -0x480(%rbp), %rdi
movl -0x10(%rbp), %ecx
movl -0x14(%rbp), %r8d
leaq -0x450(%rbp), %rsi
leaq -0x470(%rbp), %rdx
callq 0x11a30
jmp 0x149b3
leaq -0x470(%rbp), %rdi
callq 0x4270
leaq -0x450(%rbp), %rdi
callq 0x4270
movq -0x480(%rbp), %rax
movq (%rax), %rdi
callq 0x281d0
movl %eax, -0x50c(%rbp)
jmp 0x149e2
movl -0x50c(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x474(%rbp)
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x478(%rbp)
movq -0x480(%rbp), %rdi
movslq -0x478(%rbp), %rax
movq %rax, -0x518(%rbp)
addq $0x10, %rdi
callq 0x15530
movq %rax, %rcx
movq -0x518(%rbp), %rax
cmpq %rcx, %rax
jae 0x14dfc
movq -0x480(%rbp), %rdi
movl -0x10(%rbp), %eax
movl %eax, -0x520(%rbp)
addq $0x10, %rdi
movslq -0x478(%rbp), %rsi
callq 0x15550
movq %rax, %rdi
callq 0x10030
movl %eax, -0x51c(%rbp)
jmp 0x14a5e
movl -0x520(%rbp), %eax
movl -0x51c(%rbp), %ecx
cmpl %ecx, %eax
jne 0x14c30
movq -0x480(%rbp), %rdi
addq $0x10, %rdi
movslq -0x478(%rbp), %rsi
callq 0x15550
movq %rax, %rdi
movl -0x474(%rbp), %esi
callq 0xff50
jmp 0x14a99
movq -0x480(%rbp), %rdi
addq $0x10, %rdi
movslq -0x478(%rbp), %rsi
callq 0x15550
movq %rax, %rdi
xorl %esi, %esi
callq 0xffb0
jmp 0x14abc
jmp 0x14de6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
jmp 0x14b76
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
jmp 0x14b6a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
jmp 0x14b5e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
jmp 0x14b52
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
jmp 0x14b46
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
leaq -0x320(%rbp), %rdi
callq 0x4270
leaq -0x340(%rbp), %rdi
callq 0x4270
leaq -0x390(%rbp), %rdi
callq 0x5b00
leaq -0x290(%rbp), %rdi
callq 0x4270
leaq -0x2b0(%rbp), %rdi
callq 0x4270
leaq -0x300(%rbp), %rdi
callq 0x5b00
jmp 0x14e4f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
leaq -0x3d0(%rbp), %rdi
callq 0x4270
jmp 0x14e4f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
jmp 0x14bdc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
leaq -0x430(%rbp), %rdi
callq 0x4270
leaq -0x410(%rbp), %rdi
callq 0x4270
jmp 0x14e4f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
jmp 0x14c1f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
leaq -0x470(%rbp), %rdi
callq 0x4270
leaq -0x450(%rbp), %rdi
callq 0x4270
jmp 0x14e4f
movq -0x480(%rbp), %rdi
movl -0x10(%rbp), %eax
movl %eax, -0x528(%rbp)
addq $0x10, %rdi
movslq -0x478(%rbp), %rsi
callq 0x15550
movq %rax, %rdi
callq 0x10050
movl %eax, -0x524(%rbp)
jmp 0x14c60
movl -0x528(%rbp), %eax
movl -0x524(%rbp), %ecx
cmpl %ecx, %eax
jne 0x14cbf
movq -0x480(%rbp), %rdi
addq $0x10, %rdi
movslq -0x478(%rbp), %rsi
callq 0x15550
movq %rax, %rdi
movl -0x474(%rbp), %esi
callq 0xff70
jmp 0x14c97
movq -0x480(%rbp), %rdi
addq $0x10, %rdi
movslq -0x478(%rbp), %rsi
callq 0x15550
movq %rax, %rdi
xorl %esi, %esi
callq 0xffd0
jmp 0x14cba
jmp 0x14de4
movq -0x480(%rbp), %rdi
movl -0x14(%rbp), %eax
movl %eax, -0x530(%rbp)
addq $0x10, %rdi
movslq -0x478(%rbp), %rsi
callq 0x15550
movq %rax, %rdi
callq 0x10030
movl %eax, -0x52c(%rbp)
jmp 0x14cef
movl -0x530(%rbp), %eax
movl -0x52c(%rbp), %ecx
cmpl %ecx, %eax
jne 0x14d51
movq -0x480(%rbp), %rdi
addq $0x10, %rdi
movslq -0x478(%rbp), %rsi
callq 0x15550
movq %rax, %rdi
movl -0x474(%rbp), %esi
callq 0xff50
jmp 0x14d26
movq -0x480(%rbp), %rdi
addq $0x10, %rdi
movslq -0x478(%rbp), %rsi
callq 0x15550
movq %rax, %rdi
movl $0x1, %esi
callq 0xffb0
jmp 0x14d4c
jmp 0x14de2
movq -0x480(%rbp), %rdi
movl -0x14(%rbp), %eax
movl %eax, -0x538(%rbp)
addq $0x10, %rdi
movslq -0x478(%rbp), %rsi
callq 0x15550
movq %rax, %rdi
callq 0x10050
movl %eax, -0x534(%rbp)
jmp 0x14d81
movl -0x538(%rbp), %eax
movl -0x534(%rbp), %ecx
cmpl %ecx, %eax
jne 0x14de0
movq -0x480(%rbp), %rdi
addq $0x10, %rdi
movslq -0x478(%rbp), %rsi
callq 0x15550
movq %rax, %rdi
movl -0x474(%rbp), %esi
callq 0xff70
jmp 0x14db8
movq -0x480(%rbp), %rdi
addq $0x10, %rdi
movslq -0x478(%rbp), %rsi
callq 0x15550
movq %rax, %rdi
movl $0x1, %esi
callq 0xffd0
jmp 0x14dde
jmp 0x14de0
jmp 0x14de2
jmp 0x14de4
jmp 0x14de6
jmp 0x14de8
movl -0x478(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x478(%rbp)
jmp 0x149fd
leaq -0x1a0(%rbp), %rdi
callq 0x4270
leaq -0x178(%rbp), %rdi
callq 0x4270
leaq -0x150(%rbp), %rdi
callq 0x4270
leaq -0x128(%rbp), %rdi
callq 0x4270
leaq -0xb8(%rbp), %rdi
callq 0x4270
leaq -0x38(%rbp), %rdi
callq 0x4270
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x14231
leaq -0x1a0(%rbp), %rdi
callq 0x4270
leaq -0x178(%rbp), %rdi
callq 0x4270
leaq -0x150(%rbp), %rdi
callq 0x4270
leaq -0x128(%rbp), %rdi
callq 0x4270
leaq -0xb8(%rbp), %rdi
callq 0x4270
leaq -0x38(%rbp), %rdi
callq 0x4270
jmp 0x14e9f
addq $0x560, %rsp            # imm = 0x560
popq %rbp
retq
movq -0x90(%rbp), %rdi
callq 0x46c0
nopl (%rax,%rax)