// File: 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
subq $0xb0, %rsp
movq %rdx, -0x70(%rbp)
movq %rdi, -0x80(%rbp)
movb %cl, %al
movq %rdi, %rcx
movq %rcx, -0x78(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
andb $0x1, %al
movb %al, -0x19(%rbp)
movq -0x10(%rbp), %rdi
movq %rdi, -0x68(%rbp)
addq $0xa8, %rdi
leaq 0x6925(%rip), %rsi      # 0x2c1b8
callq 0x4520
movq -0x70(%rbp), %rsi
movq -0x68(%rbp), %rdi
movl $0x0, 0xd0(%rdi)
movl $0x0, 0xd4(%rdi)
movb -0x19(%rbp), %al
andb $0x1, %al
movb %al, 0x84(%rdi)
addq $0x88, %rdi
callq 0x4060
movq -0x70(%rbp), %rsi
leaq -0x40(%rbp), %rdi
movq %rdi, -0x60(%rbp)
callq 0x41b0
movq -0x68(%rbp), %rdi
movq -0x60(%rbp), %rsi
movzbl -0x19(%rbp), %edx
andl $0x1, %edx
callq 0x172f0
jmp 0x258f2
leaq -0x40(%rbp), %rdi
callq 0x4270
movq -0x68(%rbp), %rdi
callq 0x17510
testb $0x1, -0x19(%rbp)
je 0x25946
movq -0x70(%rbp), %rdi
callq 0x45e0
movq %rax, %rcx
movq -0x68(%rbp), %rax
movl %ecx, 0x80(%rax)
movl $0x1, 0xc8(%rax)
jmp 0x2595e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x4270
jmp 0x25ba8
movq -0x68(%rbp), %rax
movl $0xffffffff, 0xc8(%rax) # imm = 0xFFFFFFFF
movl $0xffffffff, 0x80(%rax) # imm = 0xFFFFFFFF
movq -0x68(%rbp), %rdi
callq 0x17330
cmpq $0x0, %rax
jne 0x259e1
movq -0x68(%rbp), %rdi
addq $0x50, %rdi
callq 0x25d30
movq -0x68(%rbp), %rdi
addq $0x68, %rdi
callq 0x154a0
movq -0x68(%rbp), %rdi
callq 0x17f10
leaq -0x4d(%rbp), %rdi
movq %rdi, -0x88(%rbp)
callq 0x46e0
movq -0x80(%rbp), %rdi
movq -0x88(%rbp), %rdx
leaq 0x6806(%rip), %rsi      # 0x2c1b8
callq 0x4530
jmp 0x259b9
leaq -0x4d(%rbp), %rdi
callq 0x4420
jmp 0x25b9b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x4d(%rbp), %rdi
callq 0x4420
jmp 0x25ba8
movq -0x68(%rbp), %rdi
movq %rdi, %rax
addq $0x68, %rax
movq %rax, -0x90(%rbp)
callq 0x17330
movq -0x90(%rbp), %rdi
movq %rax, %rsi
movl $0x0, -0x54(%rbp)
leaq -0x54(%rbp), %rdx
callq 0x25d50
movq -0x68(%rbp), %rdi
callq 0x24d40
movq -0x68(%rbp), %rdi
callq 0x25000
movq -0x68(%rbp), %rdi
callq 0x17330
cmpq $0x0, %rax
je 0x25a6c
movq -0x68(%rbp), %rdi
movslq 0xd0(%rdi), %rax
movq %rax, -0x98(%rbp)
callq 0x17330
movq %rax, %rcx
movq -0x98(%rbp), %rax
xorl %edx, %edx
divq %rcx
movq %rax, %rcx
movq -0x68(%rbp), %rax
addq $0x1, %rcx
movl %ecx, 0xd4(%rax)
jmp 0x25ae0
movq -0x68(%rbp), %rdi
addq $0x50, %rdi
callq 0x25d30
movq -0x68(%rbp), %rdi
addq $0x68, %rdi
callq 0x154a0
movq -0x68(%rbp), %rdi
callq 0x17f10
leaq -0x55(%rbp), %rdi
movq %rdi, -0xa0(%rbp)
callq 0x46e0
movq -0x80(%rbp), %rdi
movq -0xa0(%rbp), %rdx
leaq 0x6707(%rip), %rsi      # 0x2c1b8
callq 0x4530
jmp 0x25ab8
leaq -0x55(%rbp), %rdi
callq 0x4420
jmp 0x25b9b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x55(%rbp), %rdi
callq 0x4420
jmp 0x25ba8
movq -0x68(%rbp), %rdi
callq 0x252d0
testb $0x1, %al
jne 0x25b5b
movq -0x68(%rbp), %rdi
addq $0x50, %rdi
callq 0x25d30
movq -0x68(%rbp), %rdi
addq $0x68, %rdi
callq 0x154a0
movq -0x68(%rbp), %rdi
callq 0x17f10
leaq -0x56(%rbp), %rdi
movq %rdi, -0xa8(%rbp)
callq 0x46e0
movq -0x80(%rbp), %rdi
movq -0xa8(%rbp), %rdx
leaq 0x6686(%rip), %rsi      # 0x2c1b8
callq 0x4530
jmp 0x25b39
leaq -0x56(%rbp), %rdi
callq 0x4420
jmp 0x25b9b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x56(%rbp), %rdi
callq 0x4420
jmp 0x25ba8
movq -0x68(%rbp), %rdi
callq 0x25410
movq -0x68(%rbp), %rdi
addq $0x50, %rdi
callq 0x25d30
movq -0x68(%rbp), %rdi
addq $0x68, %rdi
callq 0x154a0
movq -0x68(%rbp), %rdi
callq 0x17f10
movq -0x68(%rbp), %rsi
movq -0x80(%rbp), %rdi
addq $0xa8, %rsi
callq 0x41b0
movq -0x78(%rbp), %rax
addq $0xb0, %rsp
popq %rbp
retq
movq -0x48(%rbp), %rdi
callq 0x46c0
nopw %cs:(%rax,%rax)