// File: /workspace/github_cpp_makefile_star2_O3/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 $0xc8, %rsp
movq %rsi, %rbx
cmpl $0x1, %edi
je 0x28ca
movl %edi, %r14d
movq 0x8(%rbx), %rsi
movq %rsp, %r15
leaq 0x70(%rsp), %rdx
movq %r15, %rdi
callq 0x2a2c
leaq 0x1c83(%rip), %rsi      # 0x40aa
movq %r15, %rdi
callq 0x2070
movl %eax, %ebp
movq (%r15), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x244b
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x21a0
xorl %eax, %eax
movl %ebp, 0x6c(%rsp)
cmpl $0x1, %ebp
adcl $0x1, %eax
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
movq $0x0, 0x40(%rsp)
cmpl %r14d, %eax
jge 0x24bd
movl %eax, %r13d
movl %r14d, %ebp
movq %rsp, %r14
leaq 0x70(%rsp), %r15
leaq 0x30(%rsp), %r12
movq (%rbx,%r13,8), %rsi
movq %r14, %rdi
movq %r15, %rdx
callq 0x2a2c
movq %r12, %rdi
movq %r14, %rsi
callq 0x2d78
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x24b5
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x21a0
incq %r13
cmpq %r13, %rbp
jne 0x2480
leaq 0x80(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq 0x3afd(%rip), %rdi      # 0x5fd8
movq (%rdi), %rax
addq -0x18(%rax), %rdi
movl $0xa, %esi
callq 0x2170
movsbl %al, %edx
movq 0x3ae2(%rip), %rdi      # 0x5fd8
leaq 0x70(%rsp), %rsi
callq 0x2280
cmpq $0x0, 0x78(%rsp)
je 0x292f
xorps %xmm0, %xmm0
leaq 0x90(%rsp), %rdx
movaps %xmm0, (%rdx)
movq $0x0, 0x10(%rdx)
leaq 0x70(%rsp), %rdi
movl $0x9, %esi
callq 0x3700
movl 0x6c(%rsp), %eax
testl %eax, %eax
jne 0x260a
leaq 0x8(%rsp), %r13
movl $0x0, (%r13)
xorl %eax, %eax
movq %rax, 0x8(%r13)
movq %r13, 0x10(%r13)
movq %r13, 0x18(%r13)
movq %rax, 0x20(%r13)
movq 0x30(%rsp), %r14
cmpq 0x38(%rsp), %r14
je 0x25bf
movq %rsp, %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x2a6a
movb $0x1, (%rax)
addq $0x20, %r14
cmpq 0x38(%rsp), %r14
jne 0x256b
movq 0x30(%rsp), %rbx
cmpq %rbx, %r14
je 0x25bf
addq $-0x20, %r14
leaq 0x10(%rbx), %r15
movq -0x10(%r15), %rdi
cmpq %rdi, %r15
je 0x25aa
movq (%r15), %rsi
incq %rsi
callq 0x21a0
leaq 0x20(%r15), %rax
addq $-0x10, %r15
cmpq %r15, %r14
movq %rax, %r15
jne 0x2596
movq %rbx, 0x38(%rsp)
movq 0x90(%rsp), %r14
cmpq 0x98(%rsp), %r14
je 0x2602
movq %rsp, %r15
leaq 0x30(%rsp), %r12
movq %r15, %rdi
movq %r14, %rsi
callq 0x33d0
cmpq %r13, %rax
jne 0x25f4
movq %r12, %rdi
movq %r14, %rsi
callq 0x2ae6
addq $0x20, %r14
cmpq 0x98(%rsp), %r14
jne 0x25d9
movq %rsp, %rdi
callq 0x2c6a
xorps %xmm0, %xmm0
movaps %xmm0, 0x50(%rsp)
movq $0x0, 0x60(%rsp)
movq 0x30(%rsp), %r13
movq 0x38(%rsp), %rbp
cmpq %rbp, %r13
je 0x26b6
movl $0x0, (%rsp)
movq 0x90(%rsp), %r15
movq 0x98(%rsp), %rbx
cmpq %rbx, %r15
je 0x26ad
movq 0x8(%r13), %r12
xorl %r14d, %r14d
cmpq %r12, 0x8(%r15)
jne 0x266f
testq %r12, %r12
je 0x2681
movq (%r13), %rsi
movq (%r15), %rdi
movq %r12, %rdx
callq 0x21b0
testl %eax, %eax
je 0x2681
incl %r14d
movl %r14d, (%rsp)
addq $0x20, %r15
cmpq %rbx, %r15
jne 0x2651
jmp 0x26ad
movq 0x58(%rsp), %rsi
cmpq 0x60(%rsp), %rsi
je 0x269b
movl %r14d, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x58(%rsp)
jmp 0x26ad
leaq 0x50(%rsp), %rdi
movq %rsp, %rdx
callq 0x35c2
movq 0x38(%rsp), %rbp
addq $0x20, %r13
jmp 0x2625
leaq 0x1a0a(%rip), %r14      # 0x40c7
movq %rsp, %rdi
leaq 0x30(%rsp), %rsi
movq %r14, %rdx
callq 0x2b23
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
movq 0x38eb(%rip), %r15      # 0x5fc8
movq %r15, %rdi
callq 0x21d0
movq 0x38ec(%rip), %rbx      # 0x5fd8
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x2170
movsbl %al, %esi
movq %r12, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20e0
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x2731
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x21a0
leaq 0x10(%rsp), %rax
movq %rax, (%rsp)
movq $0x0, 0x8(%rsp)
movb $0x0, 0x10(%rsp)
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2170
movsbl %al, %edx
movq 0x3872(%rip), %rbx      # 0x5fd8
movq %rsp, %rsi
movq %rbx, %rdi
callq 0x2280
cmpq $0x0, 0x8(%rsp)
je 0x284b
leaq 0xb0(%rsp), %r12
leaq 0x193c(%rip), %rbp      # 0x40c8
movq %r12, %r13
movq %r12, %rdi
movq %rsp, %rsi
movl $0x9, %edx
callq 0x37fa
movq 0x50(%rsp), %r12
cmpq 0x58(%rsp), %r12
je 0x27eb
xorl %edx, %edx
cmpq 0x50(%rsp), %r12
setne %dl
movq %rbp, %rsi
cmovneq %r14, %rsi
movq %r15, %rdi
callq 0x21d0
movslq (%r12), %rax
movq 0xb0(%rsp), %rcx
shlq $0x5, %rax
movq (%rcx,%rax), %rsi
movq 0x8(%rcx,%rax), %rdx
movq %r15, %rdi
callq 0x21d0
addq $0x4, %r12
jmp 0x27a4
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x2170
movsbl %al, %esi
movq %r15, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20e0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2170
movsbl %al, %edx
movq %rbx, %rdi
movq %rsp, %rsi
callq 0x2280
movq %r13, %r12
movq %r13, %rdi
callq 0x2c00
cmpq $0x0, 0x8(%rsp)
jne 0x278c
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x2866
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x21a0
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x287d
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x21a0
leaq 0x90(%rsp), %rdi
callq 0x2c00
movq 0x70(%rsp), %rdi
leaq 0x80(%rsp), %rax
cmpq %rax, %rdi
je 0x28ac
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x21a0
leaq 0x30(%rsp), %rdi
callq 0x2c00
xorl %eax, %eax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x371f(%rip), %rdi      # 0x5ff0
leaq 0x172c(%rip), %rsi      # 0x4004
callq 0x2180
movq (%rbx), %rsi
movq %rax, %rdi
callq 0x2180
leaq 0x171d(%rip), %rsi      # 0x400c
movq %rax, %rdi
callq 0x2180
movq %rax, %rdi
callq 0x20c0
leaq 0x1725(%rip), %rsi      # 0x402b
movq %rax, %rdi
callq 0x2180
leaq 0x1756(%rip), %rsi      # 0x406b
movq %rax, %rdi
callq 0x2180
movq %rax, %rdi
callq 0x20c0
movl $0x1, %edi
callq 0x21e0
movq 0x36ba(%rip), %rdi      # 0x5ff0
leaq 0x1770(%rip), %rsi      # 0x40ad
movl $0x19, %edx
callq 0x21d0
movq 0x36a2(%rip), %rdi      # 0x5ff0
callq 0x20c0
jmp 0x2925
jmp 0x2961
movq %rax, %rbx
jmp 0x29ea
jmp 0x29a1
movq %rax, %rbx
jmp 0x29d3
movq %rax, %rbx
jmp 0x29f7
jmp 0x2974
jmp 0x29a1
jmp 0x2974
movq %rax, %rbx
movq %rsp, %rdi
callq 0x2c6a
jmp 0x29ea
movq %rax, %rbx
jmp 0x2a19
movq %rax, %rbx
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x2a19
movq 0x10(%rsp), %rsi
jmp 0x2a11
movq %rax, %rbx
jmp 0x29b8
jmp 0x29a8
movq %rax, %rbx
leaq 0xb0(%rsp), %rdi
callq 0x2c00
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x29d3
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x21a0
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x29ea
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x21a0
leaq 0x90(%rsp), %rdi
callq 0x2c00
movq 0x70(%rsp), %rdi
leaq 0x80(%rsp), %rax
cmpq %rax, %rdi
je 0x2a19
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x21a0
leaq 0x30(%rsp), %rdi
callq 0x2c00
movq %rbx, %rdi
callq 0x2260
nop