// File: /workspace/github_cpp_makefile_star2_O2/millanek[P]evo/process_vcf_get_aa_seq.cpp
// Function: getAaSeqMain(int, char**)
int getAaSeqMain(int argc, char** argv) {
    parseAaSeqOptions(argc, argv);
    
    std::ifstream* refFastaFile = new std::ifstream(opt::refFastaFile.c_str());
    std::ifstream* ancWithGapsFile = new std::ifstream(opt::ancWithGapsFile.c_str());
    
    string refFastaFileRoot;
    if (opt::out.empty()) {
        refFastaFileRoot = stripExtension(opt::refFastaFile);
    } else {
        refFastaFileRoot = opt::out;
    }
    
    string outAncestralFN;
    if (!opt::bAncFromMaf) { outAncestralFN = refFastaFileRoot + ".ancestralSequence.fa"; }
    else { std::cerr << "Using maf" << std::endl;
        if (opt::deletionAsN) outAncestralFN = refFastaFileRoot + ".PNsequence.deletionsAsN.fa";
        else outAncestralFN = refFastaFileRoot + ".PNsequence.NoIndels.fa";
    }
    std::cerr << "Output should be in:" << std::endl;
    std::cerr << outAncestralFN << std::endl;
    std::ofstream* outAncestralFile = new std::ofstream(outAncestralFN.c_str());
    
    string line;
    getline(*ancWithGapsFile, line); getline(*refFastaFile, line);
    *outAncestralFile << line << std::endl;
    
    // Read in everything
    string refFastaSeq; refFastaSeq.reserve(50000000);
    string ancWithGapsSeq; ancWithGapsSeq.reserve(50000000);
    while (getline(*refFastaFile, line)) { refFastaSeq.append(line); }
    while (getline(*ancWithGapsFile, line)) { ancWithGapsSeq.append(line); }
    
    
    // Now generate the final ancestral sequence
    assert(refFastaSeq.length() == ancWithGapsSeq.length());
    string outAncestralSeq; outAncestralSeq.reserve(50000000);
    
    if (!opt::bAncFromMaf) {
        for (string::size_type i = 0; i != refFastaSeq.length(); i++) {
            if (refFastaSeq[i] == '-') { continue; }
            else if (refFastaSeq[i] == 'N') { outAncestralSeq += refFastaSeq[i]; }
            else if (refFastaSeq[i] == ancWithGapsSeq[i]) { outAncestralSeq += refFastaSeq[i]; }
            else { outAncestralSeq += ancWithGapsSeq[i]; }
        }
        print80bpPerLineFile(outAncestralFile, outAncestralSeq);
    } else {
        for (string::size_type i = 0; i != refFastaSeq.length(); i++) {
            if (refFastaSeq[i] == '-') { continue; }
            else if (refFastaSeq[i] == 'N') { outAncestralSeq += refFastaSeq[i]; }
            else if (refFastaSeq[i] == ancWithGapsSeq[i]) { outAncestralSeq += refFastaSeq[i]; }
            else if (ancWithGapsSeq[i] == '-') {
                if (opt::deletionAsN) outAncestralSeq += 'N';
                else outAncestralSeq += refFastaSeq[i];
            } else if (ancWithGapsSeq[i] == '*') { outAncestralSeq += 'N'; }
            else { outAncestralSeq += ancWithGapsSeq[i]; }
        }
        print80bpPerLineFile(outAncestralFile, outAncestralSeq);
    }
    
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x110, %rsp            # imm = 0x110
callq 0x385f8
movl $0x208, %edi            # imm = 0x208
callq 0x8490
movq %rax, %r14
movq 0xa5ef0(%rip), %rsi     # 0xde000
pushq $0x8
popq %rdx
movq %rax, %rdi
callq 0x8890
movl $0x208, %edi            # imm = 0x208
callq 0x8490
movq %rax, %rbx
movq 0xa5ef1(%rip), %rsi     # 0xde020
pushq $0x8
popq %rdx
movq %rax, %rdi
callq 0x8890
leaq 0xc0(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
cmpq $0x0, 0xa5ef2(%rip)     # 0xde048
je 0x3816e
leaq 0xa5ee1(%rip), %rsi     # 0xde040
leaq 0xb0(%rsp), %rdi
callq 0x82a0
jmp 0x3819c
leaq 0xa5e8b(%rip), %rsi     # 0xde000
leaq 0x50(%rsp), %rdi
callq 0x404d7
leaq 0xb0(%rsp), %rdi
leaq 0x50(%rsp), %r15
movq %r15, %rsi
callq 0x8550
movq %r15, %rdi
callq 0x8978
leaq 0x60(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
cmpb $0x0, 0xa5eac(%rip)     # 0xde060
je 0x381f5
movq 0xa4e2b(%rip), %rdi     # 0xdcfe8
leaq 0x64bb8(%rip), %rsi     # 0x9cd7c
callq 0x8480
movq %rax, %rdi
callq 0x8230
cmpb $0x1, 0xa5e89(%rip)     # 0xde061
jne 0x38210
leaq 0x64ba5(%rip), %rdx     # 0x9cd86
leaq 0x10(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
callq 0x28806
jmp 0x38229
leaq 0x64b6a(%rip), %rdx     # 0x9cd66
leaq 0x10(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
callq 0x28806
jmp 0x38229
leaq 0x64b8b(%rip), %rdx     # 0x9cda2
leaq 0x10(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
callq 0x28806
leaq 0x50(%rsp), %rdi
leaq 0x10(%rsp), %r15
movq %r15, %rsi
callq 0x8550
movq %r15, %rdi
callq 0x8978
movq 0xa4d9e(%rip), %rdi     # 0xdcfe8
leaq 0x64b69(%rip), %rsi     # 0x9cdba
callq 0x8480
movq %rax, %rdi
callq 0x8230
movq 0xa4d83(%rip), %rdi     # 0xdcfe8
leaq 0x50(%rsp), %rsi
callq 0x8430
movq %rax, %rdi
callq 0x8230
movl $0x200, %edi            # imm = 0x200
callq 0x8490
movq %rax, %r12
movq 0x50(%rsp), %rsi
pushq $0x10
popq %rdx
movq %rax, %rdi
callq 0x84e0
movq %r12, 0x8(%rsp)
leaq 0x20(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x10(%rsp), %rsi
movq %rbx, %rdi
callq 0x80a0
leaq 0x10(%rsp), %rsi
movq %r14, %rdi
callq 0x80a0
movq 0x8(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x8430
movq %rax, %rdi
callq 0x8230
leaq 0x40(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x30(%rsp), %rdi
movl $0x2faf080, %esi        # imm = 0x2FAF080
callq 0x8700
leaq 0xa0(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x90(%rsp), %rdi
movl $0x2faf080, %esi        # imm = 0x2FAF080
callq 0x8700
leaq 0x10(%rsp), %r15
leaq 0x30(%rsp), %r12
movq %r14, %rdi
movq %r15, %rsi
callq 0x80a0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x38351
movq %r12, %rdi
movq %r15, %rsi
callq 0x8920
jmp 0x3832b
leaq 0x10(%rsp), %r14
leaq 0x90(%rsp), %r15
movq %rbx, %rdi
movq %r14, %rsi
callq 0x80a0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x38384
movq %r15, %rdi
movq %r14, %rsi
callq 0x8920
jmp 0x3835e
movq 0x38(%rsp), %rax
cmpq 0x98(%rsp), %rax
jne 0x38510
leaq 0x80(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x70(%rsp), %rdi
movl $0x2faf080, %esi        # imm = 0x2FAF080
callq 0x8700
cmpb $0x0, 0xa5c9f(%rip)     # 0xde060
je 0x3842f
xorl %r14d, %r14d
leaq 0x70(%rsp), %rbx
pushq $0x4e
popq %rbp
cmpq 0x38(%rsp), %r14
je 0x3846e
movq 0x30(%rsp), %rax
movzbl (%rax,%r14), %ecx
cmpl $0x2d, %ecx
je 0x3840a
cmpl $0x4e, %ecx
je 0x383fd
movq 0x90(%rsp), %rax
movb (%rax,%r14), %al
cmpb %al, %cl
jne 0x3840f
movl %ecx, %eax
movsbl %al, %esi
movq %rbx, %rdi
callq 0x8400
incq %r14
jmp 0x383ce
movzbl %al, %edx
cmpl $0x2a, %edx
je 0x3842b
cmpl $0x2d, %edx
jne 0x383ff
movzbl %cl, %eax
cmpb $0x0, 0xa5c3b(%rip)     # 0xde061
cmovnel %ebp, %eax
jmp 0x383ff
movb $0x4e, %al
jmp 0x383ff
xorl %r14d, %r14d
leaq 0x70(%rsp), %rbx
cmpq 0x38(%rsp), %r14
je 0x38492
movq 0x30(%rsp), %rax
movzbl (%rax,%r14), %eax
cmpl $0x2d, %eax
je 0x38469
cmpl $0x4e, %eax
je 0x3845e
movq 0x90(%rsp), %rax
movb (%rax,%r14), %al
movsbl %al, %esi
movq %rbx, %rdi
callq 0x8400
incq %r14
jmp 0x38437
leaq 0xd0(%rsp), %rbx
leaq 0x70(%rsp), %rsi
movq %rbx, %rdi
callq 0x8600
leaq 0x8(%rsp), %rdi
movq %rbx, %rsi
callq 0x42730
jmp 0x384b4
leaq 0xf0(%rsp), %rbx
leaq 0x70(%rsp), %rsi
movq %rbx, %rdi
callq 0x8600
leaq 0x8(%rsp), %rdi
movq %rbx, %rsi
callq 0x42730
movq %rbx, %rdi
callq 0x8978
leaq 0x70(%rsp), %rdi
callq 0x8978
leaq 0x90(%rsp), %rdi
callq 0x8978
leaq 0x30(%rsp), %rdi
callq 0x8978
leaq 0x10(%rsp), %rdi
callq 0x8978
leaq 0x50(%rsp), %rdi
callq 0x8978
leaq 0xb0(%rsp), %rdi
callq 0x8978
xorl %eax, %eax
addq $0x110, %rsp            # imm = 0x110
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0x648b8(%rip), %rdi     # 0x9cdcf
leaq 0x648e1(%rip), %rsi     # 0x9cdff
leaq 0x648f5(%rip), %rcx     # 0x9ce1a
pushq $0x59
popq %rdx
callq 0x82f0
jmp 0x3859d
jmp 0x3859d
jmp 0x38554
movq %rax, %r15
leaq 0xf0(%rsp), %rdi
jmp 0x3854b
movq %rax, %r15
leaq 0xd0(%rsp), %rdi
callq 0x8978
jmp 0x385a7
jmp 0x3859d
movq %rax, %r15
jmp 0x385e3
jmp 0x385b5
movq %rax, %r15
jmp 0x385c5
movq %rax, %r15
movl $0x200, %esi            # imm = 0x200
movq %r12, %rdi
callq 0x84a0
jmp 0x385d9
jmp 0x3859d
movq %rax, %r15
movl $0x208, %esi            # imm = 0x208
movq %rbx, %rdi
jmp 0x3858f
movq %rax, %r15
movl $0x208, %esi            # imm = 0x208
movq %r14, %rdi
callq 0x84a0
jmp 0x385f0
jmp 0x385a4
movq %rax, %r15
jmp 0x385cf
movq %rax, %r15
jmp 0x385d9
jmp 0x385a4
movq %rax, %r15
leaq 0x70(%rsp), %rdi
callq 0x8978
jmp 0x385b8
jmp 0x385b5
movq %rax, %r15
leaq 0x90(%rsp), %rdi
callq 0x8978
leaq 0x30(%rsp), %rdi
callq 0x8978
leaq 0x10(%rsp), %rdi
callq 0x8978
leaq 0x50(%rsp), %rdi
callq 0x8978
leaq 0xb0(%rsp), %rdi
callq 0x8978
movq %r15, %rdi
callq 0x8870