// File: /workspace/github_cpp_makefile_star2_O1/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 0x23f3
movq %rsi, %rbx
cmpl $0x2, %edi
je 0x23c8
cmpl $0x3, %edi
jne 0x2440
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 0x24ea
movq 0x3c3e(%rip), %rdi      # 0x5ff0
leaq 0x1c4e(%rip), %rsi      # 0x4007
movl $0x7, %edx
callq 0x2160
jmp 0x2458
leaq 0x10(%rsp), %r14
movq (%r14), %r15
movq 0x8(%rbx), %rbx
movq %rbx, %rdi
callq 0x20c0
leaq (%rax,%rbx), %rcx
movq %r14, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x2d22
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 0x2423
movb %al, (%rsi)
incq 0x18(%rsp)
jmp 0x242e
movq %rbx, %rdi
movq %r14, %rdx
callq 0x2c34
callq 0x2180
movb %al, 0x30(%rsp)
cmpb $-0x1, %al
jne 0x240e
jmp 0x257a
movq 0x3ba9(%rip), %rdi      # 0x5ff0
leaq 0x1bb9(%rip), %rsi      # 0x4007
movl $0x7, %edx
callq 0x2160
movq (%rbx), %rbx
testq %rbx, %rbx
je 0x247c
movq %rbx, %rdi
callq 0x20c0
movq 0x3b81(%rip), %rdi      # 0x5ff0
movq %rbx, %rsi
movq %rax, %rdx
callq 0x2160
jmp 0x249a
movq 0x3b6d(%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 0x3b4f(%rip), %rbx      # 0x5ff0
leaq 0x1b67(%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 0x3b1d(%rip), %rdi      # 0x5ff0
callq 0x2030
movl $0x1, %ebx
movq %rax, %rdi
callq 0x20f0
jmp 0x276a
movq 0x10(%rsp), %rax
cmpq %rax, 0x18(%rsp)
je 0x24fb
movq %rax, 0x18(%rsp)
movq 0x10(%rbx), %rsi
leaq 0x30(%rsp), %rdi
movl $0x8, %edx
callq 0x21f0
leaq 0x30(%rsp), %rbx
leaq 0x10(%rsp), %r14
leaq 0xf(%rsp), %r15
movq 0x30(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x2, 0x50(%rsp,%rax)
jne 0x2566
movq %rbx, %rdi
callq 0x2170
movb %al, 0xf(%rsp)
movzbl %al, %ebp
cmpl $0xa, %ebp
je 0x2566
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x2556
movb %al, (%rsi)
incq 0x18(%rsp)
jmp 0x2561
movq %r14, %rdi
movq %r15, %rdx
callq 0x2c34
cmpl $0xa, %ebp
jne 0x251d
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 0x27cc
movq 0x10(%rsp), %rdi
movaps 0x30(%rsp), %xmm0
movq 0x40(%rsp), %rax
movq %rdi, 0x30(%rsp)
movups 0x18(%rsp), %xmm1
movaps %xmm0, 0x10(%rsp)
movq %rax, 0x20(%rsp)
movups %xmm1, 0x38(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
movq $0x0, 0x40(%rsp)
testq %rdi, %rdi
je 0x25d1
callq 0x2120
movq 0x30(%rsp), %rdi
movq 0x48(%rsp), %rbx
testq %rdi, %rdi
je 0x25e5
callq 0x2120
movq 0x10(%rsp), %r13
movq 0x18(%rsp), %rax
subq %r13, %rax
cmpq $0x3e8, %rax            # imm = 0x3E8
ja 0x2686
cmpq 0x18(%rsp), %r13
je 0x2657
movq 0x39c4(%rip), %r14      # 0x5fd0
leaq 0x1a04(%rip), %r15      # 0x4017
leaq 0x30(%rsp), %r12
movq 0x10(%rsp), %rax
addq %rbx, %rax
cmpq %rax, %r13
jne 0x2635
movl $0x1, %edx
movq %r14, %rdi
movq %r15, %rsi
callq 0x2160
movb (%r13), %al
movb %al, 0x30(%rsp)
movl $0x1, %edx
movq %r14, %rdi
movq %r12, %rsi
callq 0x2160
incq %r13
cmpq 0x18(%rsp), %r13
jne 0x2618
movq 0x3972(%rip), %rdi      # 0x5fd0
movq (%rdi), %rax
addq -0x18(%rax), %rdi
movl $0xa, %esi
callq 0x2130
movsbl %al, %esi
movq 0x3957(%rip), %rdi      # 0x5fd0
callq 0x2030
movq %rax, %rdi
callq 0x20f0
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
leaq 0x30(%rsp), %rdi
movq %rbx, %rcx
callq 0x2a29
movq 0x10(%rsp), %rdi
movaps 0x30(%rsp), %xmm0
movq 0x40(%rsp), %rax
movq %rdi, 0x30(%rsp)
movups 0x18(%rsp), %xmm1
movaps %xmm0, 0x10(%rsp)
movq %rax, 0x20(%rsp)
movups %xmm1, 0x38(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
movq $0x0, 0x40(%rsp)
testq %rdi, %rdi
je 0x26e0
callq 0x2120
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x26ef
callq 0x2120
movq 0x10(%rsp), %r12
movq 0x18(%rsp), %rax
subq %r12, %rax
xorl %ebx, %ebx
cmpq $0x3e8, %rax            # imm = 0x3E8
ja 0x276a
cmpq 0x18(%rsp), %r12
je 0x273b
movq 0x38bc(%rip), %r14      # 0x5fd0
leaq 0x30(%rsp), %r15
movb (%r12), %al
movb %al, 0x30(%rsp)
movl $0x1, %edx
movq %r14, %rdi
movq %r15, %rsi
callq 0x2160
incq %r12
cmpq 0x18(%rsp), %r12
jne 0x2719
movq 0x388e(%rip), %rdi      # 0x5fd0
movq (%rdi), %rax
addq -0x18(%rax), %rdi
movl $0xa, %esi
callq 0x2130
movsbl %al, %esi
movq 0x3873(%rip), %rdi      # 0x5fd0
callq 0x2030
movq %rax, %rdi
callq 0x20f0
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x2779
callq 0x2120
movl %ebx, %eax
addq $0x238, %rsp            # imm = 0x238
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x279d
jmp 0x27b2
jmp 0x27b2
jmp 0x27b2
jmp 0x27b2
jmp 0x27b2
jmp 0x27b2
jmp 0x27b2
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x2060
jmp 0x27b5
jmp 0x27b2
jmp 0x27b2
jmp 0x27b2
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x27c4
callq 0x2120
movq %rbx, %rdi
callq 0x21e0