// File: /workspace/github_cpp_makefile_star2_O2/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 %r12
pushq %rbx
subq $0x250, %rsp            # imm = 0x250
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
andq $0x0, 0x20(%rsp)
cmpl $0x1, %edi
je 0x2461
movq %rsi, %rbx
cmpl $0x2, %edi
je 0x2440
cmpl $0x3, %edi
jne 0x2403
movq 0x8(%rbx), %rsi
leaq 0x48(%rsp), %rdi
leaq 0x38(%rsp), %rdx
callq 0x2090
leaq 0x1c83(%rip), %rsi      # 0x4004
leaq 0x48(%rsp), %r14
movq %r14, %rdi
callq 0x261e
movl %eax, %ebp
movq %r14, %rdi
callq 0x20c0
testb %bpl, %bpl
je 0x2403
movq 0x10(%rsp), %rax
cmpq %rax, 0x18(%rsp)
je 0x23ae
movq %rax, 0x18(%rsp)
movq 0x10(%rbx), %rsi
leaq 0x48(%rsp), %rdi
pushq $0x8
popq %rdx
callq 0x21f0
leaq 0x48(%rsp), %rbx
leaq 0x10(%rsp), %r14
leaq 0x38(%rsp), %r15
movq 0x48(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x2, 0x68(%rsp,%rax)
jne 0x2485
movq %rbx, %rdi
callq 0x2180
movb %al, 0x38(%rsp)
cmpb $0xa, %al
je 0x2485
movq %r14, %rdi
movq %r15, %rsi
callq 0x262c
jmp 0x23ce
movq 0x3be6(%rip), %rdi      # 0x5ff0
leaq 0x1bf6(%rip), %rsi      # 0x4007
callq 0x2140
movq (%rbx), %rsi
movq %rax, %rdi
callq 0x2140
leaq 0x1be7(%rip), %rsi      # 0x400f
movq %rax, %rdi
callq 0x2140
movq %rax, %rdi
callq 0x20d0
pushq $0x1
popq %rbx
jmp 0x25c8
movq 0x8(%rbx), %rbx
movq %rbx, %rdi
callq 0x20b0
leaq (%rax,%rbx), %rcx
leaq 0x10(%rsp), %rdi
xorl %esi, %esi
movq %rbx, %rdx
callq 0x2646
jmp 0x2499
leaq 0x10(%rsp), %rbx
leaq 0x48(%rsp), %r14
callq 0x2190
movb %al, 0x48(%rsp)
cmpb $-0x1, %al
je 0x2499
movq %rbx, %rdi
movq %r14, %rsi
callq 0x262c
jmp 0x246b
leaq 0x48(%rsp), %rdi
callq 0x2040
leaq 0x48(%rsp), %rdi
callq 0x2050
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
leaq 0x48(%rsp), %rdi
callq 0x2666
leaq 0x30(%rsp), %rax
leaq 0x38(%rsp), %rdi
movq %rax, (%rdi)
leaq 0x10(%rsp), %r12
movq %r12, 0x8(%rdi)
leaq 0x48(%rsp), %rbx
movq %rbx, %rsi
callq 0x286a
movq %rbx, %rdi
callq 0x2a86
movq (%r12), %rbx
movq 0x8(%r12), %rdx
movq %rdx, %rax
subq %rbx, %rax
cmpq $0x3e8, %rax            # imm = 0x3E8
ja 0x2547
movq 0x3ada(%rip), %r14      # 0x5fd0
leaq 0x1b1a(%rip), %r15      # 0x4017
cmpq %rdx, %rbx
je 0x2531
movq 0x10(%rsp), %rax
addq 0x30(%rsp), %rax
cmpq %rax, %rbx
jne 0x251c
movq %r14, %rdi
movq %r15, %rsi
callq 0x2140
movsbl (%rbx), %esi
movq %r14, %rdi
callq 0x2170
incq %rbx
movq 0x18(%rsp), %rdx
jmp 0x24fd
movq 0x3a98(%rip), %rdi      # 0x5fd0
callq 0x20d0
movq 0x10(%rsp), %rbx
movq 0x18(%rsp), %rdx
movq 0x30(%rsp), %rcx
leaq 0x48(%rsp), %rdi
movq %rbx, %rsi
callq 0x2892
leaq 0xf(%rsp), %rax
leaq 0x38(%rsp), %rdi
movq %rax, (%rdi)
movq %r12, 0x8(%rdi)
leaq 0x48(%rsp), %rbx
movq %rbx, %rsi
callq 0x2a54
movq %rbx, %rdi
callq 0x2a86
movq 0x10(%rsp), %r14
movq 0x18(%rsp), %rax
movq %rax, %rcx
subq %r14, %rcx
cmpq $0x3e8, %rcx            # imm = 0x3E8
ja 0x25c6
movq 0x3a31(%rip), %rbx      # 0x5fd0
cmpq %rax, %r14
je 0x25ba
movsbl (%r14), %esi
movq %rbx, %rdi
callq 0x2170
incq %r14
movq 0x18(%rsp), %rax
jmp 0x259f
movq 0x3a0f(%rip), %rdi      # 0x5fd0
callq 0x20d0
xorl %ebx, %ebx
leaq 0x10(%rsp), %rdi
callq 0x2a86
movl %ebx, %eax
addq $0x250, %rsp            # imm = 0x250
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
jmp 0x25f6
jmp 0x2609
jmp 0x2609
jmp 0x2609
jmp 0x2609
jmp 0x2609
jmp 0x2609
jmp 0x2609
jmp 0x2609
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x2050
jmp 0x260c
jmp 0x2609
jmp 0x2609
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x2a86
movq %rbx, %rdi
callq 0x21e0