// File: /workspace/github_cpp_makefile_star2_O2/ekg[P]tsvtools/tsvsplit.cpp
// Function: main
int main(int argc, char** argv) {

    if (argc == 1) {
        cerr << "usage: " << argv[0] << " [-v] FIELD1 FIELD2 FIELD3 ..." << endl
             << "splits out the fields from the input tab-separated value stream"
             << "specifying '-v' inverts the split, excluding the listed fields" << endl;
        exit(1);
    }

    int i = 1;
    bool invert = false;
    if (string(argv[i]) == "-v") {
        invert = true;
        i = 2;
    }

    vector<string> fieldnames;
    for (; i < argc; ++i) {
        fieldnames.push_back(argv[i]);
    }

    string header;
    getline(cin, header);
    if (header.empty()) {
        cerr << "could not get header line" << endl;
        exit(1);
    }

    vector<string> header_fields;
    split(header, '\t', header_fields);

    // if we are inverting the selection, invert the list of fieldnames
    if (invert) {
        map<string, bool> fieldnamesToRemove;
        for (vector<string>::iterator f = fieldnames.begin(); f != fieldnames.end(); ++f) {
            fieldnamesToRemove[*f] = true;
        }
        fieldnames.clear();
        for (vector<string>::iterator h = header_fields.begin(); h != header_fields.end(); ++h) {
            if (fieldnamesToRemove.find(*h) == fieldnamesToRemove.end()) {
                fieldnames.push_back(*h);
            }
        }
    }

    vector<int> columns;

    for (vector<string>::iterator f = fieldnames.begin(); f != fieldnames.end(); ++f) {
        const string& fieldname = *f;
        int i = 0;
        for (vector<string>::iterator h = header_fields.begin(); h != header_fields.end(); ++h) {
            const string& headername = *h;
            if (headername == fieldname) {
                columns.push_back(i);
                break;
            }
            ++i;
        }
    }

    cout << join(fieldnames, "\t") << endl;

    string line;
    getline(cin, line);
    while (!line.empty()) {
        vector<string> fields = split(line, '\t');
        for (vector<int>::iterator c = columns.begin(); c != columns.end(); ++c) {
            cout << (c == columns.begin() ? "" : "\t") << fields[*c];
        }
        cout << endl;
        getline(cin, line);
    }

    return 0;

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
movq %rsi, %r14
cmpl $0x1, %edi
je 0x26ee
movl %edi, %ebp
movq 0x8(%r14), %rsi
leaq 0x10(%rsp), %r15
leaq 0xa0(%rsp), %r12
movq %r15, %rdi
movq %r12, %rdx
callq 0x280a
leaq 0x1cac(%rip), %rsi      # 0x40aa
movq %r15, %rdi
callq 0x27fc
movl %eax, %ebx
movq %r15, %rdi
callq 0x20c0
xorps %xmm0, %xmm0
leaq 0x40(%rsp), %r13
andq $0x0, 0x10(%r13)
movaps %xmm0, (%r13)
movb %bl, 0xf(%rsp)
movzbl %bl, %ebx
incq %rbx
movslq %ebp, %rbp
cmpq %rbp, %rbx
jge 0x245b
movq (%r14,%rbx,8), %rsi
movq %r15, %rdi
movq %r12, %rdx
callq 0x280a
movq %r13, %rdi
movq %r15, %rsi
callq 0x2b48
movq %r15, %rdi
callq 0x20c0
incq %rbx
jmp 0x242f
leaq 0xb0(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq 0x4b62(%rip), %rdi      # 0x6fd8
leaq 0xa0(%rsp), %rsi
callq 0x2050
cmpq $0x0, 0xa8(%rsp)
je 0x2751
xorps %xmm0, %xmm0
leaq 0x60(%rsp), %rdx
movaps %xmm0, (%rdx)
andq $0x0, 0x10(%rdx)
leaq 0xa0(%rsp), %rdi
pushq $0x9
popq %rsi
callq 0x33c0
cmpb $0x0, 0xf(%rsp)
je 0x254b
leaq 0x18(%rsp), %r12
andl $0x0, (%r12)
andq $0x0, 0x8(%r12)
movq %r12, 0x10(%r12)
movq %r12, 0x18(%r12)
andq $0x0, 0x20(%r12)
movq 0x40(%rsp), %rbx
leaq 0x10(%rsp), %r14
cmpq 0x48(%rsp), %rbx
je 0x2502
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2846
movb $0x1, (%rax)
addq $0x20, %rbx
jmp 0x24e7
leaq 0x40(%rsp), %rbx
movq %rbx, %rdi
callq 0x28ac
movq 0x60(%rsp), %r14
leaq 0x10(%rsp), %r15
cmpq 0x68(%rsp), %r14
je 0x2541
movq %r15, %rdi
movq %r14, %rsi
callq 0x3104
cmpq %r12, %rax
jne 0x253b
movq %rbx, %rdi
movq %r14, %rsi
callq 0x28b4
addq $0x20, %r14
jmp 0x2519
leaq 0x10(%rsp), %rdi
callq 0x29f4
leaq 0x80(%rsp), %rbx
andq $0x0, 0x10(%rbx)
xorps %xmm0, %xmm0
movaps %xmm0, (%rbx)
movq 0x40(%rsp), %r14
leaq 0x10(%rsp), %r15
cmpq 0x48(%rsp), %r14
je 0x25aa
andl $0x0, 0x10(%rsp)
movq 0x60(%rsp), %r12
cmpq 0x68(%rsp), %r12
je 0x25a4
movq %r12, %rdi
movq %r14, %rsi
callq 0x28e0
testb %al, %al
jne 0x2599
incl 0x10(%rsp)
addq $0x20, %r12
jmp 0x2579
movq %rbx, %rdi
movq %r15, %rsi
callq 0x290a
addq $0x20, %r14
jmp 0x2568
leaq 0x1b16(%rip), %rbx      # 0x40c7
leaq 0x10(%rsp), %rdi
leaq 0x40(%rsp), %rsi
movq %rbx, %rdx
callq 0x2928
movq 0x49fe(%rip), %rdi      # 0x6fc8
leaq 0x10(%rsp), %rsi
callq 0x2160
movq %rax, %rdi
callq 0x20d0
leaq 0x10(%rsp), %rdi
callq 0x20c0
leaq 0x20(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq 0x49da(%rip), %rdi      # 0x6fd8
leaq 0x10(%rsp), %rsi
callq 0x2050
leaq 0xc0(%rsp), %r14
leaq 0x10(%rsp), %r15
movq 0x49ac(%rip), %r12      # 0x6fc8
leaq 0x1aa5(%rip), %rbp      # 0x40c8
cmpq $0x0, 0x18(%rsp)
je 0x26a2
movq %r14, %rdi
movq %r15, %rsi
pushq $0x9
popq %rdx
callq 0x3465
movq 0x80(%rsp), %r13
cmpq 0x88(%rsp), %r13
je 0x2681
movq %rbp, %rsi
cmpq 0x80(%rsp), %r13
je 0x265b
movq %rbx, %rsi
movq %r12, %rdi
callq 0x2180
movslq (%r13), %rsi
shlq $0x5, %rsi
addq 0xc0(%rsp), %rsi
movq %rax, %rdi
callq 0x2160
addq $0x4, %r13
jmp 0x2641
movq %r12, %rdi
callq 0x20d0
movq 0x4948(%rip), %rdi      # 0x6fd8
movq %r15, %rsi
callq 0x2050
movq %r14, %rdi
callq 0x29c8
jmp 0x2623
leaq 0x10(%rsp), %rdi
callq 0x20c0
leaq 0x80(%rsp), %rdi
callq 0x324a
leaq 0x60(%rsp), %rdi
callq 0x29c8
leaq 0xa0(%rsp), %rdi
callq 0x20c0
leaq 0x40(%rsp), %rdi
callq 0x29c8
xorl %eax, %eax
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x48fb(%rip), %rdi      # 0x6ff0
leaq 0x1908(%rip), %rsi      # 0x4004
callq 0x2180
movq (%r14), %rsi
movq %rax, %rdi
callq 0x2180
leaq 0x18f9(%rip), %rsi      # 0x400c
movq %rax, %rdi
callq 0x2180
movq %rax, %rdi
callq 0x20d0
leaq 0x1901(%rip), %rsi      # 0x402b
movq %rax, %rdi
callq 0x2180
leaq 0x1932(%rip), %rsi      # 0x406b
movq %rax, %rdi
callq 0x2180
movq %rax, %rdi
callq 0x20d0
pushq $0x1
popq %rdi
callq 0x21c0
movq 0x4898(%rip), %rdi      # 0x6ff0
leaq 0x194e(%rip), %rsi      # 0x40ad
callq 0x2180
movq %rax, %rdi
callq 0x20d0
jmp 0x2749
jmp 0x2796
jmp 0x2780
movq %rax, %rbx
jmp 0x27d3
movq %rax, %rbx
jmp 0x27dd
jmp 0x2796
jmp 0x2787
movq %rax, %rbx
jmp 0x27c6
jmp 0x2787
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x29f4
jmp 0x27d3
movq %rax, %rbx
jmp 0x27bc
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
jmp 0x27e5
movq %rax, %rbx
jmp 0x27ea
jmp 0x27ac
movq %rax, %rbx
leaq 0xc0(%rsp), %rdi
callq 0x29c8
leaq 0x10(%rsp), %rdi
callq 0x20c0
leaq 0x80(%rsp), %rdi
callq 0x324a
leaq 0x60(%rsp), %rdi
callq 0x29c8
leaq 0xa0(%rsp), %rdi
callq 0x20c0
leaq 0x40(%rsp), %rdi
callq 0x29c8
movq %rbx, %rdi
callq 0x2260