// File: /workspace/github_cpp_makefile_star2_O3/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 0x43b68
movl $0x208, %edi            # imm = 0x208
callq 0x8470
movq %rax, %r14
movq 0xbfc5a(%rip), %rsi     # 0x102fd0
movq %rax, %rdi
movl $0x8, %edx
callq 0x8860
movl $0x208, %edi            # imm = 0x208
callq 0x8470
movq %rax, %rbx
movq 0xbfc59(%rip), %rsi     # 0x102ff0
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, 0xbfc56(%rip)     # 0x103018
je 0x433d7
leaq 0xbfc45(%rip), %rsi     # 0x103010
leaq 0x48(%rsp), %rdi
callq 0x8270
jmp 0x43414
leaq 0xbfbf2(%rip), %rsi     # 0x102fd0
leaq 0x20(%rsp), %rdi
callq 0x4d82f
leaq 0x48(%rsp), %rdi
leaq 0x20(%rsp), %r15
movq %r15, %rsi
callq 0x8540
movq (%r15), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x43414
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, 0xbfc00(%rip)     # 0x103030
je 0x434b1
movq 0xbebaf(%rip), %r15     # 0x101fe8
leaq 0x8b4c4(%rip), %rsi     # 0xce904
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 0xbeb7d(%rip), %rdi     # 0x101fe8
callq 0x8040
movq %rax, %rdi
callq 0x8300
cmpb $0x1, 0xbfbb2(%rip)     # 0x103031
jne 0x434e1
leaq 0x10(%rsp), %r12
movq %r12, -0x10(%r12)
movq 0x48(%rsp), %rsi
movq 0x50(%rsp), %rdx
addq %rsi, %rdx
movq %rsp, %rdi
callq 0x2ba06
leaq 0x8b467(%rip), %rsi     # 0xce90e
movq %rsp, %rdi
callq 0x88c0
jmp 0x4350f
leaq 0x10(%rsp), %r12
movq %r12, -0x10(%r12)
movq 0x48(%rsp), %rsi
movq 0x50(%rsp), %rdx
addq %rsi, %rdx
movq %rsp, %rdi
callq 0x2ba06
leaq 0x8b417(%rip), %rsi     # 0xce8ee
movq %rsp, %rdi
callq 0x88c0
jmp 0x4350f
leaq 0x10(%rsp), %r12
movq %r12, -0x10(%r12)
movq 0x48(%rsp), %rsi
movq 0x50(%rsp), %rdx
addq %rsi, %rdx
movq %rsp, %rdi
callq 0x2ba06
leaq 0x8b423(%rip), %rsi     # 0xce92a
movq %rsp, %rdi
callq 0x88c0
leaq 0x20(%rsp), %rdi
movq %rsp, %r15
movq %r15, %rsi
callq 0x8540
movq (%r15), %rdi
cmpq %r12, %rdi
je 0x43534
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x8480
movq 0xbeaad(%rip), %r15     # 0x101fe8
leaq 0x8b400(%rip), %rsi     # 0xce942
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 0xbea7b(%rip), %rdi     # 0x101fe8
callq 0x8040
movq %rax, %rdi
callq 0x8300
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rdx
movq 0xbea5d(%rip), %rdi     # 0x101fe8
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 0x4370d
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
movq %r12, %rdi
callq 0x8180
jmp 0x436ca
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 0x4375b
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
movq %r15, %rdi
callq 0x8180
jmp 0x43718
movq 0x70(%rsp), %rax
cmpq 0xb0(%rsp), %rax
jne 0x439bc
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, 0xbf88c(%rip)     # 0x103030
je 0x43821
testq %rax, %rax
je 0x438ae
xorl %r15d, %r15d
leaq 0x88(%rsp), %rbx
movl $0x4e, %r12d
movq 0x68(%rsp), %rax
movzbl (%rax,%r15), %ecx
cmpl $0x2d, %ecx
je 0x437f1
cmpl $0x4e, %ecx
je 0x437e4
movq 0xa8(%rsp), %rax
movb (%rax,%r15), %al
cmpb %al, %cl
jne 0x43800
movl %ecx, %eax
movsbl %al, %esi
movq %rbx, %rdi
callq 0x83d0
incq %r15
cmpq 0x70(%rsp), %r15
jne 0x437c0
jmp 0x438ae
movzbl %al, %edx
cmpl $0x2a, %edx
je 0x4381d
cmpl $0x2d, %edx
jne 0x437e6
movzbl %cl, %eax
cmpb $0x0, 0xbf81a(%rip)     # 0x103031
cmovnel %r12d, %eax
jmp 0x437e6
movb $0x4e, %al
jmp 0x437e6
testq %rax, %rax
je 0x43866
xorl %r15d, %r15d
leaq 0x88(%rsp), %rbx
movq 0x68(%rsp), %rax
movzbl (%rax,%r15), %eax
cmpl $0x2d, %eax
je 0x4385c
cmpl $0x4e, %eax
je 0x43851
movq 0xa8(%rsp), %rax
movb (%rax,%r15), %al
movsbl %al, %esi
movq %rbx, %rdi
callq 0x83d0
incq %r15
cmpq 0x70(%rsp), %r15
jne 0x43831
leaq 0xf8(%rsp), %rbx
movq %rbx, -0x10(%rbx)
movq 0x88(%rsp), %rsi
movq 0x90(%rsp), %rdx
addq %rsi, %rdx
leaq 0xe8(%rsp), %rdi
callq 0x2ba06
leaq 0x40(%rsp), %rdi
leaq 0xe8(%rsp), %rsi
callq 0x502ab
movq 0xe8(%rsp), %rdi
jmp 0x438f4
leaq 0xd8(%rsp), %rbx
movq %rbx, -0x10(%rbx)
movq 0x88(%rsp), %rsi
movq 0x90(%rsp), %rdx
addq %rsi, %rdx
leaq 0xc8(%rsp), %rdi
callq 0x2ba06
leaq 0x40(%rsp), %rdi
leaq 0xc8(%rsp), %rsi
callq 0x502ab
movq 0xc8(%rsp), %rdi
cmpq %rbx, %rdi
je 0x43904
movq (%rbx), %rsi
incq %rsi
callq 0x8480
movq 0x88(%rsp), %rdi
cmpq %r14, %rdi
je 0x43921
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x8480
movq 0xa8(%rsp), %rdi
cmpq %r13, %rdi
je 0x4393e
movq 0xb8(%rsp), %rsi
incq %rsi
callq 0x8480
movq 0x68(%rsp), %rdi
cmpq %rbp, %rdi
leaq 0x58(%rsp), %rbx
je 0x4395a
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x8480
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
leaq 0x30(%rsp), %r14
je 0x4397a
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x8480
movq 0x20(%rsp), %rdi
cmpq %r14, %rdi
je 0x43991
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x8480
movq 0x48(%rsp), %rdi
cmpq %rbx, %rdi
je 0x439a8
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 0x8af94(%rip), %rdi     # 0xce957
leaq 0x8afbd(%rip), %rsi     # 0xce987
leaq 0x8afd1(%rip), %rcx     # 0xce9a2
movl $0x59, %edx
callq 0x82c0
jmp 0x43a2f
jmp 0x43a2f
jmp 0x43acf
jmp 0x43acf
jmp 0x43a49
movq %rax, %r15
movq 0xc8(%rsp), %rdi
cmpq %rbx, %rdi
je 0x43aa1
movq 0xd8(%rsp), %rsi
jmp 0x43a25
movq %rax, %r15
movq 0xe8(%rsp), %rdi
cmpq %rbx, %rdi
je 0x43aa1
movq 0xf8(%rsp), %rsi
incq %rsi
callq 0x8480
jmp 0x43aa1
movq %rax, %r15
movq (%rsp), %rdi
cmpq %r12, %rdi
jne 0x43b25
jmp 0x43b32
jmp 0x43acf
movq %rax, %r15
jmp 0x43b49
jmp 0x43ad6
movq %rax, %r15
leaq 0x58(%rsp), %r13
leaq 0x10(%rsp), %rbx
jmp 0x43b00
movq %rax, %r15
movl $0x200, %esi            # imm = 0x200
movq %r12, %rdi
jmp 0x43b2d
jmp 0x43acf
movq %rax, %r15
movl $0x208, %esi            # imm = 0x208
movq %rbx, %rdi
jmp 0x43b5b
movq %rax, %r15
movl $0x208, %esi            # imm = 0x208
movq %r14, %rdi
jmp 0x43b5b
jmp 0x43a9e
jmp 0x43a9e
movq %rax, %r15
movq 0x88(%rsp), %rdi
cmpq %r14, %rdi
je 0x43ad9
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x8480
jmp 0x43ad9
movq %rax, %r15
leaq 0x30(%rsp), %rbp
leaq 0x10(%rsp), %rbx
jmp 0x43b1c
movq %rax, %r15
jmp 0x43b32
jmp 0x43ad6
movq %rax, %r15
leaq 0x10(%rsp), %rbx
movq 0xa8(%rsp), %rdi
cmpq %r13, %rdi
je 0x43afb
movq 0xb8(%rsp), %rsi
incq %rsi
callq 0x8480
leaq 0x58(%rsp), %r13
movq 0x68(%rsp), %rdi
cmpq %rbp, %rdi
je 0x43b17
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x8480
leaq 0x30(%rsp), %rbp
movq (%rsp), %rdi
cmpq %rbx, %rdi
je 0x43b32
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x8480
movq 0x20(%rsp), %rdi
cmpq %rbp, %rdi
je 0x43b49
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x8480
movq 0x48(%rsp), %rdi
cmpq %r13, %rdi
je 0x43b60
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x8480
movq %r15, %rdi
callq 0x8840