// File: /workspace/github_cpp_makefile_star2_O3/afinit[P]afin/extension.cpp
// Function: Extension::get_extension(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, bool)
string Extension::get_extension( string contig, bool back ){
  // contains multiplier for position calculation
  exten_seq = "";
  missed_bp_tot = 0;
  missed_bp_avg = 0;
  this->back = back;
  this->contig = contig;

  // reset parameters of Match object
  matches.set_seq( contig, back );
  matches.start_match();
  
  // get matches
  if( back ){
    start = contig.length();
    pos_mult = 1;
  }
  else{
    pos_mult = -1;
    start = -1;
  }

  // return if no matches are found
  if( matches.get_matchlist_size() == 0 ){
    // reset lists
    ATCG.clear();
    missed_bp.clear();
    matches.clearlist();
    return "";
  }

  // create missed bp's vector to keep track of how many bp's each read contains that are below the max at that position
  missed_bp.resize( matches.get_matchlist_size(), 0 );
 
  /////////////////////////////////////
  // STEP 1: First Pass Over Matches //
  // loop through bp's for initial pass to tally up missed nucleotides
  bp_count();
  
  ///////////////////////////////////////////
  // STEP 2: Mark Errant Reads For Removal //
  // loop through bp's to determine which reads, if any, should be eliminated from the matchlist
  // if nucleotide of read is < max for that position, count it against the read, otherwise don't count it
  missed_count();

  if( matches.get_matchlist_size() != 0 ){
    // calculate avg missed_bp's
    missed_bp_avg = missed_bp_tot / matches.get_matchlist_size() + 1;
  }
  else{
    // reset lists
    ATCG.clear();
    missed_bp.clear();
    matches.clearlist();
    return "";
  }

  /////////////////////////////////
  // STEP 3: Remove Errant Reads //
  // loop through missed_bp list to eliminate any matches that have a missed level greater than the avg 
  if ( !error_removal() ){
    // reset lists
    ATCG.clear();
    missed_bp.clear();
    matches.clearlist();
    return "";
  }

  //////////////////////////////
  // STEP 4: Build Extension //
  build_string();

  // reset lists
  ATCG.clear();
  missed_bp.clear();
  matches.clearlist();
  return exten_seq;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %ecx, %r12d
movq %rdx, %r15
movq %rsi, %r14
movq %rdi, -0x30(%rbp)
leaq 0xa8(%rsi), %rdi
movq 0xb0(%rsi), %rdx
leaq 0x31f1(%rip), %rcx      # 0x15f4c
xorl %esi, %esi
xorl %r8d, %r8d
callq 0x44f0
movq $0x0, 0xd0(%r14)
movb %r12b, 0x84(%r14)
leaq 0x88(%r14), %rdi
movq %r15, %rsi
callq 0x41c0
leaq -0x48(%rbp), %rbx
movq %rbx, -0x10(%rbx)
movq (%r15), %rsi
movq 0x8(%r15), %rdx
addq %rsi, %rdx
leaq -0x58(%rbp), %r13
movq %r13, %rdi
callq 0x68f6
movq %r14, %rdi
movq %r13, %rsi
movl %r12d, %edx
callq 0xdc00
movq -0x58(%rbp), %rdi
cmpq %rbx, %rdi
je 0x12dc0
callq 0x42f0
movq %r14, %rdi
callq 0xddc6
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
testb %r12b, %r12b
movq -0x30(%rbp), %rbx
je 0x12de4
movl 0x8(%r15), %eax
movl $0x1, %ecx
movl %eax, 0x80(%r14)
movl %ecx, 0xc8(%r14)
movq %r14, %rdi
callq 0xdc12
testq %rax, %rax
je 0x12eb9
leaq 0x68(%r14), %r15
movq %r14, %rdi
callq 0xdc12
leaq -0x34(%rbp), %rdx
movl $0x0, (%rdx)
movq %r15, %rdi
movq %rax, %rsi
callq 0x1303a
movq %r14, %rdi
callq 0x127e2
movq %r14, %rdi
callq 0x1292c
movq %r14, %rdi
callq 0xdc12
testq %rax, %rax
je 0x12eb9
movslq 0xd0(%r14), %r15
movq %r14, %rdi
callq 0xdc12
movq %rax, %rcx
movq %r15, %rax
xorl %edx, %edx
divq %rcx
incl %eax
movl %eax, 0xd4(%r14)
movq %r14, %rdi
callq 0x12a0e
testb %al, %al
je 0x12eb9
movq %r14, %rdi
callq 0x12aee
leaq 0x50(%r14), %rdi
callq 0x12ff8
movq 0x68(%r14), %rax
cmpq %rax, 0x70(%r14)
je 0x12e8f
movq %rax, 0x70(%r14)
movq %r14, %rdi
callq 0xe564
leaq 0x10(%rbx), %rax
movq %rax, (%rbx)
movq 0xa8(%r14), %rsi
movq 0xb0(%r14), %rdx
addq %rsi, %rdx
movq %rbx, %rdi
callq 0x68f6
jmp 0x12ef1
leaq 0x50(%r14), %rdi
callq 0x12ff8
movq 0x68(%r14), %rax
cmpq %rax, 0x70(%r14)
je 0x12ed0
movq %rax, 0x70(%r14)
movq %r14, %rdi
callq 0xe564
leaq 0x10(%rbx), %rax
movq %rax, (%rbx)
leaq 0x3066(%rip), %rdx      # 0x15f4c
movq %rbx, %rdi
movq %rdx, %rsi
callq 0x6be0
movq %rbx, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
movq -0x58(%rbp), %rdi
cmpq %rbx, %rdi
je 0x12f14
callq 0x42f0
movq %r14, %rdi
callq 0x4590