// File: 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
movq %rsp, %rbp
subq $0x300, %rsp            # imm = 0x300
movl %edi, -0x4(%rbp)
movq %rsi, -0x10(%rbp)
movl -0x4(%rbp), %edi
movq -0x10(%rbp), %rsi
callq 0x67510
movl $0x208, %edi            # imm = 0x208
callq 0xa5d0
movq %rax, -0x1d0(%rbp)
movq %rax, -0x1d8(%rbp)
leaq 0x133a43(%rip), %rdi    # 0x19a4b0
callq 0xa220
movq -0x1d0(%rbp), %rdi
movq %rax, %rsi
movl $0x8, %edx
callq 0xab90
jmp 0x66a88
movq -0x1d8(%rbp), %rax
movq %rax, -0x18(%rbp)
movl $0x208, %edi            # imm = 0x208
callq 0xa5d0
movq %rax, -0x1e0(%rbp)
movq %rax, -0x1e8(%rbp)
leaq 0x133a1e(%rip), %rdi    # 0x19a4d0
callq 0xa220
movq -0x1e0(%rbp), %rdi
movq %rax, %rsi
movl $0x8, %edx
callq 0xab90
jmp 0x66acd
movq -0x1e8(%rbp), %rax
movq %rax, -0x30(%rbp)
leaq -0x50(%rbp), %rdi
callq 0xa820
leaq 0x133a08(%rip), %rdi    # 0x19a4f0
callq 0xaa70
testb $0x1, %al
jne 0x66af3
jmp 0x66b72
leaq 0x1339b6(%rip), %rsi    # 0x19a4b0
leaq -0x70(%rbp), %rdi
callq 0x7be70
jmp 0x66b05
leaq -0x50(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0xa710
leaq -0x70(%rbp), %rdi
callq 0xac88
jmp 0x66b86
movq -0x1d8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
movl $0x208, %esi            # imm = 0x208
callq 0xa5e0
jmp 0x674f9
movq -0x1e8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
movl $0x208, %esi            # imm = 0x208
callq 0xa5e0
jmp 0x674f9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x674f0
leaq 0x133977(%rip), %rsi    # 0x19a4f0
leaq -0x50(%rbp), %rdi
callq 0xa060
jmp 0x66b84
jmp 0x66b86
leaq -0x90(%rbp), %rdi
callq 0xa820
testb $0x1, 0x133977(%rip)    # 0x19a510
jne 0x66be9
leaq 0xd225e(%rip), %rdx     # 0x138e00
leaq -0xb0(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x3da80
jmp 0x66bb4
leaq -0x90(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0xa710
leaq -0xb0(%rbp), %rdi
callq 0xac88
jmp 0x66c97
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x674e4
movq 0x132400(%rip), %rdi    # 0x198ff0
leaq 0xd221f(%rip), %rsi     # 0x138e16
callq 0xa5c0
movq %rax, -0x1f0(%rbp)
jmp 0x66c05
movq -0x1f0(%rbp), %rdi
movq 0x132375(%rip), %rsi    # 0x198f88
callq 0xa610
jmp 0x66c1a
testb $0x1, 0x1338f0(%rip)    # 0x19a511
je 0x66c5d
leaq 0xd21f6(%rip), %rdx     # 0x138e20
leaq -0xd0(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x3da80
jmp 0x66c3c
leaq -0x90(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0xa710
leaq -0xd0(%rbp), %rdi
callq 0xac88
jmp 0x66c95
leaq 0xd21d8(%rip), %rdx     # 0x138e3c
leaq -0xf0(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x3da80
jmp 0x66c76
leaq -0x90(%rbp), %rdi
leaq -0xf0(%rbp), %rsi
callq 0xa710
leaq -0xf0(%rbp), %rdi
callq 0xac88
jmp 0x66c97
movq 0x132352(%rip), %rdi    # 0x198ff0
leaq 0xd21af(%rip), %rsi     # 0x138e54
callq 0xa5c0
movq %rax, -0x1f8(%rbp)
jmp 0x66cb3
movq -0x1f8(%rbp), %rdi
movq 0x1322c7(%rip), %rsi    # 0x198f88
callq 0xa610
jmp 0x66cc8
movq 0x132321(%rip), %rdi    # 0x198ff0
leaq -0x90(%rbp), %rsi
callq 0xa520
movq %rax, -0x200(%rbp)
jmp 0x66ce4
movq -0x200(%rbp), %rdi
movq 0x132296(%rip), %rsi    # 0x198f88
callq 0xa610
jmp 0x66cf9
movl $0x200, %edi            # imm = 0x200
callq 0xa5d0
movq %rax, -0x208(%rbp)
jmp 0x66d0c
leaq -0x90(%rbp), %rdi
callq 0xa220
movq -0x208(%rbp), %rdi
movq %rax, %rsi
movl $0x10, %edx
callq 0xa650
jmp 0x66d2e
movq -0x208(%rbp), %rax
movq %rax, -0xf8(%rbp)
leaq -0x118(%rbp), %rdi
movq %rdi, -0x210(%rbp)
callq 0xa820
movq -0x210(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0xa0d0
jmp 0x66d61
movq -0x18(%rbp), %rdi
leaq -0x118(%rbp), %rsi
callq 0xa0d0
jmp 0x66d73
movq -0xf8(%rbp), %rdi
leaq -0x118(%rbp), %rsi
callq 0xa520
movq %rax, -0x218(%rbp)
jmp 0x66d8f
movq -0x218(%rbp), %rdi
movq 0x1321eb(%rip), %rsi    # 0x198f88
callq 0xa610
jmp 0x66da4
leaq -0x138(%rbp), %rdi
movq %rdi, -0x220(%rbp)
callq 0xa820
movq -0x220(%rbp), %rdi
movl $0x2faf080, %esi        # imm = 0x2FAF080
callq 0xa980
jmp 0x66dca
leaq -0x158(%rbp), %rdi
movq %rdi, -0x228(%rbp)
callq 0xa820
movq -0x228(%rbp), %rdi
movl $0x2faf080, %esi        # imm = 0x2FAF080
callq 0xa980
jmp 0x66df0
jmp 0x66df2
movq -0x18(%rbp), %rdi
leaq -0x118(%rbp), %rsi
callq 0xa0d0
movq %rax, -0x230(%rbp)
jmp 0x66e0b
movq -0x230(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0xa740
movb %al, -0x231(%rbp)
jmp 0x66e29
movb -0x231(%rbp), %al
testb $0x1, %al
jne 0x66e35
jmp 0x66ea1
leaq -0x138(%rbp), %rdi
leaq -0x118(%rbp), %rsi
callq 0xac20
jmp 0x66e4a
jmp 0x66df2
movq -0x208(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
movl $0x200, %esi            # imm = 0x200
callq 0xa5e0
jmp 0x674e4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x674d8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x674cc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x674c0
jmp 0x66ea3
movq -0x30(%rbp), %rdi
leaq -0x118(%rbp), %rsi
callq 0xa0d0
movq %rax, -0x240(%rbp)
jmp 0x66ebc
movq -0x240(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0xa740
movb %al, -0x241(%rbp)
jmp 0x66eda
movb -0x241(%rbp), %al
testb $0x1, %al
jne 0x66ee6
jmp 0x66efd
leaq -0x158(%rbp), %rdi
leaq -0x118(%rbp), %rsi
callq 0xac20
jmp 0x66efb
jmp 0x66ea3
leaq -0x138(%rbp), %rdi
callq 0xa930
movq %rax, -0x250(%rbp)
leaq -0x158(%rbp), %rdi
callq 0xa930
movq %rax, %rcx
movq -0x250(%rbp), %rax
cmpq %rcx, %rax
jne 0x66f2d
jmp 0x66f4c
leaq 0xd1f35(%rip), %rdi     # 0x138e69
leaq 0xd1f5e(%rip), %rsi     # 0x138e99
movl $0x59, %edx
leaq 0xd1f6d(%rip), %rcx     # 0x138eb4
callq 0xa390
leaq -0x178(%rbp), %rdi
movq %rdi, -0x258(%rbp)
callq 0xa820
movq -0x258(%rbp), %rdi
movl $0x2faf080, %esi        # imm = 0x2FAF080
callq 0xa980
jmp 0x66f72
testb $0x1, 0x133597(%rip)    # 0x19a510
jne 0x67199
movq $0x0, -0x180(%rbp)
movq -0x180(%rbp), %rax
movq %rax, -0x260(%rbp)
leaq -0x138(%rbp), %rdi
callq 0xa930
movq %rax, %rcx
movq -0x260(%rbp), %rax
cmpq %rcx, %rax
je 0x67141
movq -0x180(%rbp), %rsi
leaq -0x138(%rbp), %rdi
callq 0xac60
movq %rax, -0x268(%rbp)
jmp 0x66fd3
movq -0x268(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
jne 0x66ff8
jmp 0x6712a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x674b4
movq -0x180(%rbp), %rsi
leaq -0x138(%rbp), %rdi
callq 0xac60
movq %rax, -0x270(%rbp)
jmp 0x67014
movq -0x270(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x4e, %eax
jne 0x6705c
movq -0x180(%rbp), %rsi
leaq -0x138(%rbp), %rdi
callq 0xac60
movq %rax, -0x278(%rbp)
jmp 0x6703f
movq -0x278(%rbp), %rax
movsbl (%rax), %esi
leaq -0x178(%rbp), %rdi
callq 0xa380
jmp 0x67057
jmp 0x67126
movq -0x180(%rbp), %rsi
leaq -0x138(%rbp), %rdi
callq 0xac60
movq %rax, -0x280(%rbp)
jmp 0x67078
movq -0x280(%rbp), %rax
movsbl (%rax), %eax
movl %eax, -0x28c(%rbp)
movq -0x180(%rbp), %rsi
leaq -0x158(%rbp), %rdi
callq 0xac60
movq %rax, -0x288(%rbp)
jmp 0x670a4
movl -0x28c(%rbp), %eax
movq -0x288(%rbp), %rcx
movsbl (%rcx), %ecx
cmpl %ecx, %eax
jne 0x670ee
movq -0x180(%rbp), %rsi
leaq -0x138(%rbp), %rdi
callq 0xac60
movq %rax, -0x298(%rbp)
jmp 0x670d4
movq -0x298(%rbp), %rax
movsbl (%rax), %esi
leaq -0x178(%rbp), %rdi
callq 0xa380
jmp 0x670ec
jmp 0x67124
movq -0x180(%rbp), %rsi
leaq -0x158(%rbp), %rdi
callq 0xac60
movq %rax, -0x2a0(%rbp)
jmp 0x6710a
movq -0x2a0(%rbp), %rax
movsbl (%rax), %esi
leaq -0x178(%rbp), %rdi
callq 0xa380
jmp 0x67122
jmp 0x67124
jmp 0x67126
jmp 0x67128
jmp 0x6712a
movq -0x180(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x180(%rbp)
jmp 0x66f8a
leaq -0x1a0(%rbp), %rdi
leaq -0x178(%rbp), %rsi
callq 0xa250
jmp 0x67156
leaq -0xf8(%rbp), %rdi
leaq -0x1a0(%rbp), %rsi
callq 0x81170
jmp 0x6716b
leaq -0x1a0(%rbp), %rdi
callq 0xac88
jmp 0x67464
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0x1a0(%rbp), %rdi
callq 0xac88
jmp 0x674b4
movq $0x0, -0x1a8(%rbp)
movq -0x1a8(%rbp), %rax
movq %rax, -0x2a8(%rbp)
leaq -0x138(%rbp), %rdi
callq 0xa930
movq %rax, %rcx
movq -0x2a8(%rbp), %rax
cmpq %rcx, %rax
je 0x67412
movq -0x1a8(%rbp), %rsi
leaq -0x138(%rbp), %rdi
callq 0xac60
movq %rax, -0x2b0(%rbp)
jmp 0x671ed
movq -0x2b0(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
jne 0x67201
jmp 0x673fb
movq -0x1a8(%rbp), %rsi
leaq -0x138(%rbp), %rdi
callq 0xac60
movq %rax, -0x2b8(%rbp)
jmp 0x6721d
movq -0x2b8(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x4e, %eax
jne 0x67265
movq -0x1a8(%rbp), %rsi
leaq -0x138(%rbp), %rdi
callq 0xac60
movq %rax, -0x2c0(%rbp)
jmp 0x67248
movq -0x2c0(%rbp), %rax
movsbl (%rax), %esi
leaq -0x178(%rbp), %rdi
callq 0xa380
jmp 0x67260
jmp 0x673f7
movq -0x1a8(%rbp), %rsi
leaq -0x138(%rbp), %rdi
callq 0xac60
movq %rax, -0x2c8(%rbp)
jmp 0x67281
movq -0x2c8(%rbp), %rax
movsbl (%rax), %eax
movl %eax, -0x2d4(%rbp)
movq -0x1a8(%rbp), %rsi
leaq -0x158(%rbp), %rdi
callq 0xac60
movq %rax, -0x2d0(%rbp)
jmp 0x672ad
movl -0x2d4(%rbp), %eax
movq -0x2d0(%rbp), %rcx
movsbl (%rcx), %ecx
cmpl %ecx, %eax
jne 0x672fa
movq -0x1a8(%rbp), %rsi
leaq -0x138(%rbp), %rdi
callq 0xac60
movq %rax, -0x2e0(%rbp)
jmp 0x672dd
movq -0x2e0(%rbp), %rax
movsbl (%rax), %esi
leaq -0x178(%rbp), %rdi
callq 0xa380
jmp 0x672f5
jmp 0x673f5
movq -0x1a8(%rbp), %rsi
leaq -0x158(%rbp), %rdi
callq 0xac60
movq %rax, -0x2e8(%rbp)
jmp 0x67316
movq -0x2e8(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
jne 0x6737b
testb $0x1, 0x1331e5(%rip)    # 0x19a511
je 0x67343
leaq -0x178(%rbp), %rdi
movl $0x4e, %esi
callq 0xa380
jmp 0x67341
jmp 0x67379
movq -0x1a8(%rbp), %rsi
leaq -0x138(%rbp), %rdi
callq 0xac60
movq %rax, -0x2f0(%rbp)
jmp 0x6735f
movq -0x2f0(%rbp), %rax
movsbl (%rax), %esi
leaq -0x178(%rbp), %rdi
callq 0xa380
jmp 0x67377
jmp 0x67379
jmp 0x673f3
movq -0x1a8(%rbp), %rsi
leaq -0x158(%rbp), %rdi
callq 0xac60
movq %rax, -0x2f8(%rbp)
jmp 0x67397
movq -0x2f8(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2a, %eax
jne 0x673bb
leaq -0x178(%rbp), %rdi
movl $0x4e, %esi
callq 0xa380
jmp 0x673b9
jmp 0x673f1
movq -0x1a8(%rbp), %rsi
leaq -0x158(%rbp), %rdi
callq 0xac60
movq %rax, -0x300(%rbp)
jmp 0x673d7
movq -0x300(%rbp), %rax
movsbl (%rax), %esi
leaq -0x178(%rbp), %rdi
callq 0xa380
jmp 0x673ef
jmp 0x673f1
jmp 0x673f3
jmp 0x673f5
jmp 0x673f7
jmp 0x673f9
jmp 0x673fb
movq -0x1a8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x1a8(%rbp)
jmp 0x671a4
leaq -0x1c8(%rbp), %rdi
leaq -0x178(%rbp), %rsi
callq 0xa250
jmp 0x67427
leaq -0xf8(%rbp), %rdi
leaq -0x1c8(%rbp), %rsi
callq 0x81170
jmp 0x6743c
leaq -0x1c8(%rbp), %rdi
callq 0xac88
jmp 0x67464
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0x1c8(%rbp), %rdi
callq 0xac88
jmp 0x674b4
leaq -0x178(%rbp), %rdi
callq 0xac88
leaq -0x158(%rbp), %rdi
callq 0xac88
leaq -0x138(%rbp), %rdi
callq 0xac88
leaq -0x118(%rbp), %rdi
callq 0xac88
leaq -0x90(%rbp), %rdi
callq 0xac88
leaq -0x50(%rbp), %rdi
callq 0xac88
xorl %eax, %eax
addq $0x300, %rsp            # imm = 0x300
popq %rbp
retq
leaq -0x178(%rbp), %rdi
callq 0xac88
leaq -0x158(%rbp), %rdi
callq 0xac88
leaq -0x138(%rbp), %rdi
callq 0xac88
leaq -0x118(%rbp), %rdi
callq 0xac88
leaq -0x90(%rbp), %rdi
callq 0xac88
leaq -0x50(%rbp), %rdi
callq 0xac88
movq -0x20(%rbp), %rdi
callq 0xab50
nopw %cs:(%rax,%rax)