// File: /workspace/github_cpp_makefile_star2_O1/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 0x336d(%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 0x6876
movq %r14, %rdi
movq %r13, %rsi
movl %r12d, %edx
callq 0xdae0
movq -0x58(%rbp), %rdi
cmpq %rbx, %rdi
je 0x12c44
callq 0x42f0
movq %r14, %rdi
callq 0xdca6
testb %r12b, %r12b
movq -0x30(%rbp), %rbx
je 0x12c6d
movl 0x8(%r15), %eax
movl %eax, 0x80(%r14)
movl $0x1, 0xc8(%r14)
jmp 0x12c80
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, 0xc8(%r14)
movl %eax, 0x80(%r14)
movq %r14, %rdi
callq 0xdaf2
testq %rax, %rax
je 0x12d47
leaq 0x68(%r14), %r15
movq %r14, %rdi
callq 0xdaf2
leaq -0x34(%rbp), %rdx
movl $0x0, (%rdx)
movq %r15, %rdi
movq %rax, %rsi
callq 0x12ec8
movq %r14, %rdi
callq 0x1264a
movq %r14, %rdi
callq 0x127a4
movq %r14, %rdi
callq 0xdaf2
testq %rax, %rax
je 0x12d47
movslq 0xd0(%r14), %r15
movq %r14, %rdi
callq 0xdaf2
movq %rax, %rcx
movq %r15, %rax
xorl %edx, %edx
divq %rcx
incl %eax
movl %eax, 0xd4(%r14)
movq %r14, %rdi
callq 0x12886
testb %al, %al
je 0x12d47
movq %r14, %rdi
callq 0x1295c
leaq 0x50(%r14), %rdi
callq 0x12e86
movq 0x68(%r14), %rax
cmpq %rax, 0x70(%r14)
je 0x12d1d
movq %rax, 0x70(%r14)
movq %r14, %rdi
callq 0xe404
leaq 0x10(%rbx), %rax
movq %rax, (%rbx)
movq 0xa8(%r14), %rsi
movq 0xb0(%r14), %rdx
addq %rsi, %rdx
movq %rbx, %rdi
callq 0x6876
jmp 0x12d7f
leaq 0x50(%r14), %rdi
callq 0x12e86
movq 0x68(%r14), %rax
cmpq %rax, 0x70(%r14)
je 0x12d5e
movq %rax, 0x70(%r14)
movq %r14, %rdi
callq 0xe404
leaq 0x10(%rbx), %rax
movq %rax, (%rbx)
leaq 0x31d8(%rip), %rdx      # 0x15f4c
movq %rbx, %rdi
movq %rdx, %rsi
callq 0x6b5c
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 0x12da2
callq 0x42f0
movq %r14, %rdi
callq 0x4590