// File: /workspace/github_cpp_makefile_star2_O1/dgboy2000[P]compress/compress.cpp
// Function: DATCompression::burrows_wheeler_decode(std::vector<int, std::allocator<int>>)
vector<int> DATCompression::burrows_wheeler_decode(vector<int> data) {
    int n = data.size() - 4;
    long int dollar_pos = 256*256*data[n+1] + 256*data[n+2] + data[n+3];
    int bwt_size = n + 1;
    
    pair<int,int> *f = (pair<int,int> *) calloc(bwt_size, sizeof(pair<int,int>));
    int *t = (int *) calloc(bwt_size, sizeof(int));
    vector<int> s;
    s.resize(n);
    
    for (int i=0; i<bwt_size; ++i) f[i] = pair<int,int>(data[i], i);
    f[dollar_pos].first = INT_MIN;
    stable_sort(f, f + bwt_size, pair_comparator);
    
    for (int i=0; i<bwt_size; ++i) t[f[i].second] = i;
    free(f);
    
    int last_t = dollar_pos;
    for (vector<int>::reverse_iterator viter = s.rbegin(); viter != s.rend(); ++viter) {
        last_t = t[last_t];
        *viter = data[last_t];
    }
    free(t);
    
    return s;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, 0x30(%rsp)
movq (%rdx), %rax
movq %rdx, (%rsp)
movq 0x8(%rdx), %r14
subq %rax, %r14
movq %r14, %rbx
shrq $0x2, %rbx
addl $-0x3, %ebx
movslq %ebx, %r12
movslq (%rax,%r12,4), %rcx
movq %rcx, 0x28(%rsp)
shlq $0x1e, %r14
movabsq $-0x200000000, %rcx     # imm = 0xFFFFFFFE00000000
addq %r14, %rcx
sarq $0x1e, %rcx
movslq (%rax,%rcx), %rbp
movabsq $-0x100000000, %rcx     # imm = 0xFFFFFFFF00000000
addq %r14, %rcx
sarq $0x1e, %rcx
movslq (%rax,%rcx), %rax
movq %rax, 0x20(%rsp)
movl $0x8, %esi
movq %r12, %rdi
callq 0x2110
movq %rax, %r13
movl $0x4, %esi
movq %r12, %rdi
callq 0x2110
movq %rax, %r15
xorps %xmm0, %xmm0
movq 0x30(%rsp), %rdi
movups %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
movabsq $-0x400000000, %rsi     # imm = 0xFFFFFFFC00000000
addq %r14, %rsi
sarq $0x20, %rsi
movq %rdi, %r14
callq 0x613a
movq 0x28(%rsp), %rax
shlq $0x10, %rax
shlq $0x8, %rbp
addq %rax, %rbp
addq 0x20(%rsp), %rbp
testl %ebx, %ebx
jle 0x414d
movq (%rsp), %rax
movq (%rax), %rax
xorl %ecx, %ecx
movl (%rax,%rcx,4), %edx
movl %edx, (%r13,%rcx,8)
movl %ecx, 0x4(%r13,%rcx,8)
incq %rcx
cmpq %rcx, %r12
jne 0x4138
movl $0x80000000, (%r13,%rbp,8) # imm = 0x80000000
testl %ebx, %ebx
je 0x41c9
leaq 0x1(%r12), %rax
shrq $0x3f, %rax
addq %r12, %rax
incq %rax
shrq %rax
movslq %eax, %rdx
leaq 0x8(%rsp), %rdi
movq %r13, %rsi
callq 0x6606
leaq (,%r12,8), %rsi
addq %r13, %rsi
movq 0x18(%rsp), %rdx
testq %rdx, %rdx
je 0x41a7
movq 0x10(%rsp), %rcx
leaq 0xef9(%rip), %r8        # 0x5096
movq %r13, %rdi
callq 0x66f9
jmp 0x41b6
leaq 0xee8(%rip), %rdx       # 0x5096
movq %r13, %rdi
callq 0x6676
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdi
shlq $0x3, %rsi
callq 0x21b0
testl %ebx, %ebx
jle 0x41e0
xorl %eax, %eax
movslq 0x4(%r13,%rax,8), %rcx
movl %eax, (%r15,%rcx,4)
incq %rax
cmpq %rax, %r12
jne 0x41cf
movq %r13, %rdi
callq 0x21f0
movq (%r14), %rax
movq 0x8(%r14), %rcx
cmpq %rax, %rcx
je 0x4211
movq (%rsp), %rdx
movq (%rdx), %rdx
movslq %ebp, %rsi
movslq (%r15,%rsi,4), %rbp
movl (%rdx,%rbp,4), %esi
movl %esi, -0x4(%rcx)
addq $-0x4, %rcx
cmpq %rax, %rcx
jne 0x41fb
movq %r15, %rdi
callq 0x21f0
movq %r14, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdi
shlq $0x3, %rsi
callq 0x21b0
jmp 0x4246
movq %rax, %rbx
movq (%r14), %rdi
testq %rdi, %rdi
je 0x425a
movq 0x10(%r14), %rsi
subq %rdi, %rsi
callq 0x21b0
movq %rbx, %rdi
callq 0x22c0