// File: /workspace/github_cpp_makefile_star2_O3/kevintownsend[P]bwt/example.cpp
// Function: main
int main(int argc, char* argv[]){
    vector<char> original;
    if(argc == 3){
        if(string(argv[1]) == "-f"){
            original.clear();
            ifstream file(argv[2]);
            while(!file.eof()){
                char c = file.get();
                if(c == '\n') break;
                original.push_back(c);
            }
            file.close();
        }else{
            cerr << "usage: " << argv[0] << " gataca" << endl;
            return 1;
        }
    }else if(argc == 2){
        original.insert(original.begin(),argv[1], argv[1] + strlen(argv[1]));
    }else if(argc == 1){
        char c;
        while((c = getchar()) != -1)
            original.push_back(c);
    }else{
        cerr << "usage: " << argv[0] << " gataca" << endl;
        return 1;
    }
    size_t key;
    std::tie(original, key) = bwt::bwt(original.begin(), original.end());
    if(original.size() <= 1000){
        for(auto it = original.begin(); it != original.end(); it++){
            if(it == (original.begin() + key))
                cout << "$";
            cout << *it;
        }
        cout << endl;
    }
    bool success;
    std::tie(original, success) = bwt::iBwt(original.begin(), original.end(), key);
    if(original.size() <= 1000){
        for(auto it = original.begin(); it != original.end(); it++){
            cout << *it;
        }
        cout << endl;
    }
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x238, %rsp            # imm = 0x238
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
cmpl $0x1, %edi
je 0x23ec
movq %rsi, %rbx
cmpl $0x2, %edi
je 0x23c8
cmpl $0x3, %edi
jne 0x2439
movq 0x8(%rbx), %rsi
leaq 0x30(%rsp), %rdi
leaq 0xf(%rsp), %rdx
callq 0x20a0
leaq 0x1c82(%rip), %rsi      # 0x4004
leaq 0x30(%rsp), %r14
movq %r14, %rdi
callq 0x2080
movl %eax, %ebp
movq (%r14), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x23a3
callq 0x2120
testl %ebp, %ebp
je 0x24e3
movq 0x3c3e(%rip), %rdi      # 0x5ff0
leaq 0x1c4e(%rip), %rsi      # 0x4007
movl $0x7, %edx
callq 0x2160
jmp 0x2451
movq 0x8(%rbx), %rbx
movq %rbx, %rdi
callq 0x20c0
leaq (%rax,%rbx), %rcx
leaq 0x10(%rsp), %rdi
xorl %esi, %esi
movq %rbx, %rdx
callq 0x2d48
jmp 0x257a
callq 0x2180
movb %al, 0x30(%rsp)
cmpb $-0x1, %al
je 0x257a
leaq 0x10(%rsp), %rbx
leaq 0x30(%rsp), %r14
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x241c
movb %al, (%rsi)
incq 0x18(%rsp)
jmp 0x2427
movq %rbx, %rdi
movq %r14, %rdx
callq 0x2c5a
callq 0x2180
movb %al, 0x30(%rsp)
cmpb $-0x1, %al
jne 0x2407
jmp 0x257a
movq 0x3bb0(%rip), %rdi      # 0x5ff0
leaq 0x1bc0(%rip), %rsi      # 0x4007
movl $0x7, %edx
callq 0x2160
movq (%rbx), %rbx
testq %rbx, %rbx
je 0x2475
movq %rbx, %rdi
callq 0x20c0
movq 0x3b88(%rip), %rdi      # 0x5ff0
movq %rbx, %rsi
movq %rax, %rdx
callq 0x2160
jmp 0x2493
movq 0x3b74(%rip), %rax      # 0x5ff0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
leaq (%rax,%rcx), %rdi
movl 0x20(%rax,%rcx), %esi
orl $0x1, %esi
callq 0x21d0
movq 0x3b56(%rip), %rbx      # 0x5ff0
leaq 0x1b6e(%rip), %rsi      # 0x400f
movl $0x7, %edx
movq %rbx, %rdi
callq 0x2160
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2130
movsbl %al, %esi
movq 0x3b24(%rip), %rdi      # 0x5ff0
callq 0x2030
movl $0x1, %ebp
movq %rax, %rdi
callq 0x20f0
jmp 0x2758
movq 0x10(%rsp), %rax
cmpq %rax, 0x18(%rsp)
je 0x24f4
movq %rax, 0x18(%rsp)
movq 0x10(%rbx), %rsi
leaq 0x30(%rsp), %rdi
movl $0x8, %edx
callq 0x21f0
movq 0x30(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x2, 0x50(%rsp,%rax)
jne 0x2566
leaq 0x30(%rsp), %rbx
leaq 0x10(%rsp), %r14
leaq 0xf(%rsp), %r15
movq %rbx, %rdi
callq 0x2170
movb %al, 0xf(%rsp)
cmpb $0xa, %al
je 0x2566
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x254b
movb %al, (%rsi)
incq 0x18(%rsp)
jmp 0x2556
movq %r14, %rdi
movq %r15, %rdx
callq 0x2c5a
movq 0x30(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x2, 0x50(%rsp,%rax)
je 0x2526
leaq 0x30(%rsp), %rdi
callq 0x2050
leaq 0x30(%rsp), %rdi
callq 0x2060
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
leaq 0x30(%rsp), %rdi
callq 0x27bd
movq 0x10(%rsp), %rdi
movaps 0x30(%rsp), %xmm0
movaps %xmm0, 0x10(%rsp)
movq 0x40(%rsp), %rax
movq %rax, 0x20(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
movq $0x0, 0x40(%rsp)
testq %rdi, %rdi
je 0x25d8
callq 0x2120
movq 0x30(%rsp), %rdi
movq 0x48(%rsp), %rbx
testq %rdi, %rdi
je 0x25dd
callq 0x2120
jmp 0x25dd
movq 0x48(%rsp), %rbx
movq 0x10(%rsp), %r14
movq 0x18(%rsp), %rdx
movq %rdx, %rax
subq %r14, %rax
cmpq $0x3e8, %rax            # imm = 0x3E8
ja 0x2688
cmpq %rdx, %r14
je 0x264f
movq 0x39cb(%rip), %r15      # 0x5fd0
leaq 0x1a0b(%rip), %r12      # 0x4017
leaq 0x30(%rsp), %r13
movq 0x10(%rsp), %rax
addq %rbx, %rax
cmpq %rax, %r14
jne 0x262e
movl $0x1, %edx
movq %r15, %rdi
movq %r12, %rsi
callq 0x2160
movb (%r14), %al
movb %al, 0x30(%rsp)
movl $0x1, %edx
movq %r15, %rdi
movq %r13, %rsi
callq 0x2160
incq %r14
cmpq 0x18(%rsp), %r14
jne 0x2611
movq 0x397a(%rip), %rdi      # 0x5fd0
movq (%rdi), %rax
addq -0x18(%rax), %rdi
movl $0xa, %esi
callq 0x2130
movsbl %al, %esi
movq 0x395f(%rip), %rdi      # 0x5fd0
callq 0x2030
movq %rax, %rdi
callq 0x20f0
movq 0x10(%rsp), %r14
movq 0x18(%rsp), %rdx
leaq 0x30(%rsp), %rdi
movq %r14, %rsi
movq %rbx, %rcx
callq 0x2a30
movq 0x10(%rsp), %rdi
movaps 0x30(%rsp), %xmm0
movaps %xmm0, 0x10(%rsp)
movq 0x40(%rsp), %rax
movq %rax, 0x20(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
movq $0x0, 0x40(%rsp)
testq %rdi, %rdi
je 0x26db
callq 0x2120
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x26db
callq 0x2120
movq 0x10(%rsp), %rbx
movq 0x18(%rsp), %rax
movq %rax, %rcx
subq %rbx, %rcx
xorl %ebp, %ebp
cmpq $0x3e8, %rcx            # imm = 0x3E8
ja 0x275d
cmpq %rax, %rbx
je 0x2727
movq 0x38ce(%rip), %r14      # 0x5fd0
leaq 0x30(%rsp), %r15
movb (%rbx), %al
movb %al, 0x30(%rsp)
movl $0x1, %edx
movq %r14, %rdi
movq %r15, %rsi
callq 0x2160
incq %rbx
cmpq 0x18(%rsp), %rbx
jne 0x2707
movq 0x38a2(%rip), %rdi      # 0x5fd0
movq (%rdi), %rax
addq -0x18(%rax), %rdi
movl $0xa, %esi
callq 0x2130
movsbl %al, %esi
movq 0x3887(%rip), %rdi      # 0x5fd0
callq 0x2030
xorl %ebp, %ebp
movq %rax, %rdi
callq 0x20f0
movq 0x10(%rsp), %rbx
testq %rbx, %rbx
je 0x276a
movq %rbx, %rdi
callq 0x2120
movl %ebp, %eax
addq $0x238, %rsp            # imm = 0x238
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x278e
jmp 0x27a3
jmp 0x27a3
jmp 0x27a3
jmp 0x27a3
jmp 0x27a3
jmp 0x27a3
jmp 0x27a3
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x2060
jmp 0x27a6
jmp 0x27a3
jmp 0x27a3
jmp 0x27a3
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x27b5
callq 0x2120
movq %rbx, %rdi
callq 0x21e0