// File: /workspace/github_cpp_makefile_star2_O2/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, %r13d
movq %rdx, %r12
movq %rsi, %r14
movq %rdi, -0x38(%rbp)
leaq 0xa8(%rsi), %r15
leaq 0x34ce(%rip), %rsi      # 0x12f4c
movq %r15, %rdi
callq 0x4600
andq $0x0, 0xd0(%r14)
movb %r13b, 0x84(%r14)
leaq 0x88(%r14), %rdi
movq %r12, %rsi
callq 0x41d0
leaq -0x58(%rbp), %rbx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x4410
movq %r14, %rdi
movq %rbx, %rsi
movl %r13d, %edx
callq 0xb3ca
leaq -0x58(%rbp), %rdi
callq 0x4160
movq %r14, %rdi
callq 0xb520
testb %r13b, %r13b
je 0xfae1
movl 0x8(%r12), %eax
pushq $0x1
popq %rcx
jmp 0xfae6
pushq $-0x1
popq %rax
movl %eax, %ecx
movl %eax, 0x80(%r14)
movl %ecx, 0xc8(%r14)
movq %r14, %rdi
callq 0xb3dc
testq %rax, %rax
je 0xfba7
leaq 0x68(%r14), %rbx
movq %r14, %rdi
callq 0xb3dc
leaq -0x2c(%rbp), %rdx
andl $0x0, (%rdx)
movq %rbx, %rdi
movq %rax, %rsi
callq 0xfca4
movq %r14, %rdi
callq 0xf5c4
movq %r14, %rdi
callq 0xf6fc
movq %r14, %rdi
callq 0xb3dc
testq %rax, %rax
je 0xfba7
movslq 0xd0(%r14), %rbx
movq %r14, %rdi
callq 0xb3dc
movq %rax, %rcx
movq %rbx, %rax
xorl %edx, %edx
divq %rcx
incl %eax
movl %eax, 0xd4(%r14)
movq %r14, %rdi
callq 0xf7c0
testb %al, %al
je 0xfba7
movq %r14, %rdi
callq 0xf87a
leaq 0x50(%r14), %rdi
callq 0xfc96
movq 0x68(%r14), %rax
cmpq %rax, 0x70(%r14)
je 0xfb8e
movq %rax, 0x70(%r14)
movq %r14, %rdi
callq 0xbab8
movq -0x38(%rbp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x4410
jmp 0xfbdd
leaq 0x50(%r14), %rdi
callq 0xfc96
movq 0x68(%r14), %rax
cmpq %rax, 0x70(%r14)
je 0xfbbe
movq %rax, 0x70(%r14)
movq %r14, %rdi
callq 0xbab8
leaq 0x337f(%rip), %rsi      # 0x12f4c
leaq -0x2c(%rbp), %rdx
movq -0x38(%rbp), %rbx
movq %rbx, %rdi
callq 0x4120
movq %rbx, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq -0x58(%rbp), %rdi
callq 0x4160
movq %rbx, %rdi
callq 0x4590
nop