// File: /workspace/github_cpp_makefile_star2_O1/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 0x28e0
movl %edi, %r14d
movq 0x8(%rbx), %rsi
movq %rsp, %r15
leaq 0x90(%rsp), %rdx
movq %r15, %rdi
callq 0x2a46
leaq 0x1c80(%rip), %rsi      # 0x40aa
movq %r15, %rdi
callq 0x2070
movl %eax, %ebp
movq (%r15), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x244e
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 0x24c3
movl %eax, %r13d
movl %r14d, %ebp
movq %rsp, %r14
leaq 0x90(%rsp), %r15
leaq 0x30(%rsp), %r12
movq (%rbx,%r13,8), %rsi
movq %r14, %rdi
movq %r15, %rdx
callq 0x2a46
movq %r12, %rdi
movq %r14, %rsi
callq 0x2d88
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x24bb
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x21a0
incq %r13
cmpq %r13, %rbp
jne 0x2486
leaq 0xa0(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq 0x3af7(%rip), %rdi      # 0x5fd8
movq (%rdi), %rax
addq -0x18(%rax), %rdi
movl $0xa, %esi
callq 0x2170
movsbl %al, %edx
movq 0x3adc(%rip), %rbx      # 0x5fd8
leaq 0x90(%rsp), %rsi
movq %rbx, %rdi
callq 0x2280
cmpq $0x0, 0x98(%rsp)
je 0x2945
xorps %xmm0, %xmm0
leaq 0x70(%rsp), %rdx
movaps %xmm0, (%rdx)
movq $0x0, 0x10(%rdx)
leaq 0x90(%rsp), %rdi
movl $0x9, %esi
callq 0x3738
movl 0x6c(%rsp), %eax
testl %eax, %eax
jne 0x2612
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
movq 0x38(%rsp), %r12
cmpq %r12, %r14
je 0x2599
movq %rsp, %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x2a84
movb $0x1, (%rax)
addq $0x20, %r14
movq 0x38(%rsp), %r12
cmpq %r12, %r14
jne 0x257d
movq 0x30(%rsp), %r14
cmpq %r14, %r12
je 0x25d0
leaq 0x10(%r14), %r15
movq -0x10(%r15), %rdi
cmpq %rdi, %r15
je 0x25bb
movq (%r15), %rsi
incq %rsi
callq 0x21a0
leaq 0x20(%r15), %rax
addq $0x10, %r15
cmpq %r12, %r15
movq %rax, %r15
jne 0x25a7
movq %r14, 0x38(%rsp)
movq 0x70(%rsp), %r14
cmpq 0x78(%rsp), %r14
je 0x260a
movq %rsp, %r15
leaq 0x30(%rsp), %r12
movq %r15, %rdi
movq %r14, %rsi
callq 0x33d2
cmpq %r13, %rax
jne 0x25ff
movq %r12, %rdi
movq %r14, %rsi
callq 0x2b00
addq $0x20, %r14
cmpq 0x78(%rsp), %r14
jne 0x25e4
movq %rsp, %rdi
callq 0x2c80
xorps %xmm0, %xmm0
movaps %xmm0, 0x50(%rsp)
movq $0x0, 0x60(%rsp)
movq 0x30(%rsp), %r12
cmpq 0x38(%rsp), %r12
je 0x26d3
leaq 0x50(%rsp), %r14
movq %rsp, %r15
movl $0x0, (%rsp)
movq 0x70(%rsp), %r13
cmpq 0x78(%rsp), %r13
je 0x26c4
addq $0x20, %r13
movq -0x18(%r13), %rdx
cmpq 0x8(%r12), %rdx
jne 0x2677
testq %rdx, %rdx
je 0x267b
movq (%r12), %rsi
movq -0x20(%r13), %rdi
callq 0x21b0
testl %eax, %eax
sete %bpl
jmp 0x267e
xorl %ebp, %ebp
jmp 0x267e
movb $0x1, %bpl
testb %bpl, %bpl
je 0x269f
movq 0x58(%rsp), %rsi
cmpq 0x60(%rsp), %rsi
je 0x26a4
movl (%rsp), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x58(%rsp)
jmp 0x26af
incl (%rsp)
jmp 0x26af
movq %r14, %rdi
movq %r15, %rdx
callq 0x35fc
cmpq 0x78(%rsp), %r13
sete %al
orb %al, %bpl
addq $0x20, %r13
cmpb $0x1, %bpl
jne 0x2652
addq $0x20, %r12
cmpq 0x38(%rsp), %r12
jne 0x263b
leaq 0x19ed(%rip), %r14      # 0x40c7
movq %rsp, %rdi
leaq 0x30(%rsp), %rsi
movq %r14, %rdx
callq 0x2b3d
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
movq 0x38ce(%rip), %r15      # 0x5fc8
movq %r15, %rdi
callq 0x21d0
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 0x2747
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 0x385c(%rip), %rbx      # 0x5fd8
movq %rsp, %rsi
movq %rbx, %rdi
callq 0x2280
cmpq $0x0, 0x8(%rsp)
je 0x2861
leaq 0xb0(%rsp), %r12
leaq 0x1926(%rip), %rbp      # 0x40c8
movq %r12, %r13
movq %r12, %rdi
movq %rsp, %rsi
movl $0x9, %edx
callq 0x3832
movq 0x50(%rsp), %r12
cmpq 0x58(%rsp), %r12
je 0x2801
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 0x27ba
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 0x2c1a
cmpq $0x0, 0x8(%rsp)
jne 0x27a2
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x287c
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x21a0
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x2893
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x21a0
leaq 0x70(%rsp), %rdi
callq 0x2c1a
movq 0x90(%rsp), %rdi
leaq 0xa0(%rsp), %rax
cmpq %rax, %rdi
je 0x28c2
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x21a0
leaq 0x30(%rsp), %rdi
callq 0x2c1a
xorl %eax, %eax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x3709(%rip), %rdi      # 0x5ff0
leaq 0x1716(%rip), %rsi      # 0x4004
callq 0x2180
movq (%rbx), %rsi
movq %rax, %rdi
callq 0x2180
leaq 0x1707(%rip), %rsi      # 0x400c
movq %rax, %rdi
callq 0x2180
movq %rax, %rdi
callq 0x20c0
leaq 0x170f(%rip), %rsi      # 0x402b
movq %rax, %rdi
callq 0x2180
leaq 0x1740(%rip), %rsi      # 0x406b
movq %rax, %rdi
callq 0x2180
movq %rax, %rdi
callq 0x20c0
movl $0x1, %edi
callq 0x21e0
movq 0x36a4(%rip), %rdi      # 0x5ff0
leaq 0x175a(%rip), %rsi      # 0x40ad
movl $0x19, %edx
callq 0x21d0
movq 0x368c(%rip), %rdi      # 0x5ff0
callq 0x20c0
jmp 0x293b
jmp 0x29bb
movq %rax, %rbx
jmp 0x2a04
jmp 0x29b6
movq %rax, %rbx
jmp 0x2a0e
jmp 0x2985
jmp 0x29b6
jmp 0x2985
movq %rax, %rbx
movq %rsp, %rdi
callq 0x2c80
jmp 0x2a04
movq %rax, %rbx
jmp 0x2a33
movq %rax, %rbx
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x2a33
movq 0x10(%rsp), %rsi
jmp 0x2a2b
movq %rax, %rbx
jmp 0x29d2
movq %rax, %rbx
jmp 0x29ed
jmp 0x29c2
movq %rax, %rbx
leaq 0xb0(%rsp), %rdi
callq 0x2c1a
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x29ed
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x21a0
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x2a04
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x21a0
leaq 0x70(%rsp), %rdi
callq 0x2c1a
movq 0x90(%rsp), %rdi
leaq 0xa0(%rsp), %rax
cmpq %rax, %rdi
je 0x2a33
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x21a0
leaq 0x30(%rsp), %rdi
callq 0x2c1a
movq %rbx, %rdi
callq 0x2260
nop