// File: /workspace/github_cpp_makefile_star2_O1/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 %r13
pushq %r12
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
callq 0x46aa8
movl $0x208, %edi            # imm = 0x208
callq 0x8470
movq %rax, %r14
movq 0xc5d12(%rip), %rsi     # 0x10bfc8
movq %rax, %rdi
movl $0x8, %edx
callq 0x8860
movl $0x208, %edi            # imm = 0x208
callq 0x8470
movq %rax, %rbx
movq 0xc5d11(%rip), %rsi     # 0x10bfe8
movq %rax, %rdi
movl $0x8, %edx
callq 0x8860
leaq 0x58(%rsp), %r13
movq %r13, -0x10(%r13)
movq $0x0, -0x8(%r13)
movb $0x0, (%r13)
cmpq $0x0, 0xc5d0e(%rip)     # 0x10c010
je 0x46317
leaq 0xc5cfd(%rip), %rsi     # 0x10c008
leaq 0x48(%rsp), %rdi
callq 0x8270
jmp 0x46354
leaq 0xc5caa(%rip), %rsi     # 0x10bfc8
leaq 0x20(%rsp), %rdi
callq 0x50803
leaq 0x48(%rsp), %rdi
leaq 0x20(%rsp), %r15
movq %r15, %rsi
callq 0x8540
movq (%r15), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x46354
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x8480
leaq 0x30(%rsp), %rbp
movq %rbp, -0x10(%rbp)
movq $0x0, -0x8(%rbp)
movb $0x0, (%rbp)
cmpb $0x0, 0xc5cb8(%rip)     # 0x10c028
je 0x463f1
movq 0xc4c6f(%rip), %r15     # 0x10afe8
leaq 0x8e85c(%rip), %rsi     # 0xd4bdc
movl $0x9, %edx
movq %r15, %rdi
callq 0x84e0
movq (%r15), %rax
addq -0x18(%rax), %r15
movq %r15, %rdi
movl $0xa, %esi
callq 0x8450
movsbl %al, %esi
movq 0xc4c3d(%rip), %rdi     # 0x10afe8
callq 0x8040
movq %rax, %rdi
callq 0x8300
cmpb $0x1, 0xc5c6a(%rip)     # 0x10c029
jne 0x46421
leaq 0x10(%rsp), %r12
movq %r12, -0x10(%r12)
movq 0x48(%rsp), %rsi
movq 0x50(%rsp), %rdx
addq %rsi, %rdx
movq %rsp, %rdi
callq 0x2e45c
leaq 0x8e7ff(%rip), %rsi     # 0xd4be6
movq %rsp, %rdi
callq 0x88c0
jmp 0x4644f
leaq 0x10(%rsp), %r12
movq %r12, -0x10(%r12)
movq 0x48(%rsp), %rsi
movq 0x50(%rsp), %rdx
addq %rsi, %rdx
movq %rsp, %rdi
callq 0x2e45c
leaq 0x8e7af(%rip), %rsi     # 0xd4bc6
movq %rsp, %rdi
callq 0x88c0
jmp 0x4644f
leaq 0x10(%rsp), %r12
movq %r12, -0x10(%r12)
movq 0x48(%rsp), %rsi
movq 0x50(%rsp), %rdx
addq %rsi, %rdx
movq %rsp, %rdi
callq 0x2e45c
leaq 0x8e7bb(%rip), %rsi     # 0xd4c02
movq %rsp, %rdi
callq 0x88c0
leaq 0x20(%rsp), %rdi
movq %rsp, %r15
movq %r15, %rsi
callq 0x8540
movq (%r15), %rdi
cmpq %r12, %rdi
je 0x46474
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x8480
movq 0xc4b6d(%rip), %r15     # 0x10afe8
leaq 0x8e798(%rip), %rsi     # 0xd4c1a
movl $0x14, %edx
movq %r15, %rdi
callq 0x84e0
movq (%r15), %rax
addq -0x18(%rax), %r15
movq %r15, %rdi
movl $0xa, %esi
callq 0x8450
movsbl %al, %esi
movq 0xc4b3b(%rip), %rdi     # 0x10afe8
callq 0x8040
movq %rax, %rdi
callq 0x8300
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rdx
movq 0xc4b1d(%rip), %rdi     # 0x10afe8
callq 0x84e0
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x8450
movsbl %al, %esi
movq %r15, %rdi
callq 0x8040
movq %rax, %rdi
callq 0x8300
movl $0x200, %edi            # imm = 0x200
callq 0x8470
movq %rax, %r12
movq 0x20(%rsp), %rsi
movq %rax, %rdi
movl $0x10, %edx
callq 0x84c0
movq %r12, 0x40(%rsp)
leaq 0x10(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x8450
movsbl %al, %edx
movq %rsp, %rsi
movq %rbx, %rdi
callq 0x8870
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x8450
movsbl %al, %edx
movq %rsp, %rsi
movq %r14, %rdi
callq 0x8870
movq 0x40(%rsp), %rdi
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
callq 0x84e0
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x8450
movsbl %al, %esi
movq %r15, %rdi
callq 0x8040
movq %rax, %rdi
callq 0x8300
leaq 0x78(%rsp), %rbp
movq %rbp, -0x10(%rbp)
movq $0x0, -0x8(%rbp)
movb $0x0, (%rbp)
leaq 0x68(%rsp), %rdi
movl $0x2faf080, %esi        # imm = 0x2FAF080
callq 0x86f0
leaq 0xb8(%rsp), %r13
movq %r13, -0x10(%r13)
movq $0x0, -0x8(%r13)
movb $0x0, (%r13)
leaq 0xa8(%rsp), %rdi
movl $0x2faf080, %esi        # imm = 0x2FAF080
callq 0x86f0
movq %rsp, %r15
leaq 0x68(%rsp), %r12
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x8450
movsbl %al, %edx
movq %r14, %rdi
movq %r15, %rsi
callq 0x8870
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x4664d
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
movq %r12, %rdi
callq 0x8180
jmp 0x4660a
movq %rsp, %r14
leaq 0xa8(%rsp), %r15
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x8450
movsbl %al, %edx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x8870
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x4669b
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
movq %r15, %rdi
callq 0x8180
jmp 0x46658
movq 0x70(%rsp), %rax
cmpq 0xb0(%rsp), %rax
jne 0x468fc
leaq 0x98(%rsp), %r14
movq %r14, -0x10(%r14)
movq $0x0, -0x8(%r14)
movb $0x0, (%r14)
leaq 0x88(%rsp), %rdi
movl $0x2faf080, %esi        # imm = 0x2FAF080
callq 0x86f0
movq 0x70(%rsp), %rax
cmpb $0x0, 0xc5944(%rip)     # 0x10c028
je 0x46761
testq %rax, %rax
je 0x467ee
xorl %r15d, %r15d
leaq 0x88(%rsp), %rbx
movl $0x4e, %r12d
movq 0x68(%rsp), %rax
movzbl (%rax,%r15), %ecx
cmpl $0x2d, %ecx
je 0x46731
cmpl $0x4e, %ecx
je 0x46724
movq 0xa8(%rsp), %rax
movb (%rax,%r15), %al
cmpb %al, %cl
jne 0x46740
movl %ecx, %eax
movsbl %al, %esi
movq %rbx, %rdi
callq 0x83d0
incq %r15
cmpq 0x70(%rsp), %r15
jne 0x46700
jmp 0x467ee
movzbl %al, %edx
cmpl $0x2a, %edx
je 0x4675d
cmpl $0x2d, %edx
jne 0x46726
movzbl %cl, %eax
cmpb $0x0, 0xc58d2(%rip)     # 0x10c029
cmovnel %r12d, %eax
jmp 0x46726
movb $0x4e, %al
jmp 0x46726
testq %rax, %rax
je 0x467a6
xorl %r15d, %r15d
leaq 0x88(%rsp), %rbx
movq 0x68(%rsp), %rax
movzbl (%rax,%r15), %eax
cmpl $0x2d, %eax
je 0x4679c
cmpl $0x4e, %eax
je 0x46791
movq 0xa8(%rsp), %rax
movb (%rax,%r15), %al
movsbl %al, %esi
movq %rbx, %rdi
callq 0x83d0
incq %r15
cmpq 0x70(%rsp), %r15
jne 0x46771
leaq 0xf8(%rsp), %rbx
movq %rbx, -0x10(%rbx)
movq 0x88(%rsp), %rsi
movq 0x90(%rsp), %rdx
addq %rsi, %rdx
leaq 0xe8(%rsp), %rdi
callq 0x2e45c
leaq 0x40(%rsp), %rdi
leaq 0xe8(%rsp), %rsi
callq 0x53420
movq 0xe8(%rsp), %rdi
jmp 0x46834
leaq 0xd8(%rsp), %rbx
movq %rbx, -0x10(%rbx)
movq 0x88(%rsp), %rsi
movq 0x90(%rsp), %rdx
addq %rsi, %rdx
leaq 0xc8(%rsp), %rdi
callq 0x2e45c
leaq 0x40(%rsp), %rdi
leaq 0xc8(%rsp), %rsi
callq 0x53420
movq 0xc8(%rsp), %rdi
cmpq %rbx, %rdi
je 0x46844
movq (%rbx), %rsi
incq %rsi
callq 0x8480
movq 0x88(%rsp), %rdi
cmpq %r14, %rdi
je 0x46861
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x8480
movq 0xa8(%rsp), %rdi
cmpq %r13, %rdi
je 0x4687e
movq 0xb8(%rsp), %rsi
incq %rsi
callq 0x8480
movq 0x68(%rsp), %rdi
cmpq %rbp, %rdi
leaq 0x58(%rsp), %rbx
je 0x4689a
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x8480
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
leaq 0x30(%rsp), %r14
je 0x468ba
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x8480
movq 0x20(%rsp), %rdi
cmpq %r14, %rdi
je 0x468d1
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x8480
movq 0x48(%rsp), %rdi
cmpq %rbx, %rdi
je 0x468e8
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x8480
xorl %eax, %eax
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x8e32c(%rip), %rdi     # 0xd4c2f
leaq 0x8e355(%rip), %rsi     # 0xd4c5f
leaq 0x8e369(%rip), %rcx     # 0xd4c7a
movl $0x59, %edx
callq 0x82c0
jmp 0x4696f
jmp 0x4696f
jmp 0x46a0f
jmp 0x46a0f
jmp 0x46989
movq %rax, %r15
movq 0xc8(%rsp), %rdi
cmpq %rbx, %rdi
je 0x469e1
movq 0xd8(%rsp), %rsi
jmp 0x46965
movq %rax, %r15
movq 0xe8(%rsp), %rdi
cmpq %rbx, %rdi
je 0x469e1
movq 0xf8(%rsp), %rsi
incq %rsi
callq 0x8480
jmp 0x469e1
movq %rax, %r15
movq (%rsp), %rdi
cmpq %r12, %rdi
jne 0x46a65
jmp 0x46a72
jmp 0x46a0f
movq %rax, %r15
jmp 0x46a89
jmp 0x46a16
movq %rax, %r15
leaq 0x58(%rsp), %r13
leaq 0x10(%rsp), %rbx
jmp 0x46a40
movq %rax, %r15
movl $0x200, %esi            # imm = 0x200
movq %r12, %rdi
jmp 0x46a6d
jmp 0x46a0f
movq %rax, %r15
movl $0x208, %esi            # imm = 0x208
movq %rbx, %rdi
jmp 0x46a9b
movq %rax, %r15
movl $0x208, %esi            # imm = 0x208
movq %r14, %rdi
jmp 0x46a9b
jmp 0x469de
jmp 0x469de
movq %rax, %r15
movq 0x88(%rsp), %rdi
cmpq %r14, %rdi
je 0x46a19
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x8480
jmp 0x46a19
movq %rax, %r15
leaq 0x30(%rsp), %rbp
leaq 0x10(%rsp), %rbx
jmp 0x46a5c
movq %rax, %r15
jmp 0x46a72
jmp 0x46a16
movq %rax, %r15
leaq 0x10(%rsp), %rbx
movq 0xa8(%rsp), %rdi
cmpq %r13, %rdi
je 0x46a3b
movq 0xb8(%rsp), %rsi
incq %rsi
callq 0x8480
leaq 0x58(%rsp), %r13
movq 0x68(%rsp), %rdi
cmpq %rbp, %rdi
je 0x46a57
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x8480
leaq 0x30(%rsp), %rbp
movq (%rsp), %rdi
cmpq %rbx, %rdi
je 0x46a72
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x8480
movq 0x20(%rsp), %rdi
cmpq %rbp, %rdi
je 0x46a89
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x8480
movq 0x48(%rsp), %rdi
cmpq %r13, %rdi
je 0x46aa0
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x8480
movq %r15, %rdi
callq 0x8840