// File: wichtounet[P]articles/src/linear_sorting/bench.cpp
// Function: radix_sort(std::vector<unsigned long, std::allocator<unsigned long>>&)
void radix_sort(std::vector<std::size_t>& A){
    std::vector<std::size_t> B(SIZE);
    std::vector<std::size_t> cnt(radix);

    for(std::size_t i = 0, shift = 0; i < digits; i++, shift += r){
        for(std::size_t j = 0; j < radix; ++j){
            cnt[j] = 0;
        }

        for(std::size_t j = 0; j < SIZE; ++j){
            ++cnt[(A[j] >> shift) & mask];
        }

        for(std::size_t j = 1; j < radix; ++j){
            cnt[j] += cnt[j - 1];
        }

        for(long j = SIZE - 1; j >= 0; --j){
            B[--cnt[(A[j] >> shift) & mask]] = A[j];
        }

        for(std::size_t j = 0; j < SIZE; ++j){
           A[j] = B[j];
        }
    }
}

// Assembly:
subq $0xb8, %rsp
movq %rdi, 0xb0(%rsp)
leaq 0x97(%rsp), %rdi
movq %rdi, 0x20(%rsp)
callq 0x1fe0
movq 0x20(%rsp), %rdx
leaq 0x98(%rsp), %rdi
movl $0x4c4b40, %esi         # imm = 0x4C4B40
callq 0x1ff0
jmp 0x1a7a
leaq 0x97(%rsp), %rdi
callq 0x2070
leaq 0x67(%rsp), %rdi
movq %rdi, 0x18(%rsp)
callq 0x1fe0
movq 0x18(%rsp), %rdx
leaq 0x68(%rsp), %rdi
movl $0x10000, %esi          # imm = 0x10000
callq 0x1ff0
jmp 0x1aac
leaq 0x67(%rsp), %rdi
callq 0x2070
movq $0x0, 0x58(%rsp)
movq $0x0, 0x50(%rsp)
cmpq $0x2, 0x58(%rsp)
jae 0x1d1a
movq $0x0, 0x48(%rsp)
cmpq $0x10000, 0x48(%rsp)    # imm = 0x10000
jae 0x1b64
movq 0x48(%rsp), %rsi
leaq 0x68(%rsp), %rdi
callq 0x1f20
movq $0x0, (%rax)
movq 0x48(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x48(%rsp)
jmp 0x1add
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x88(%rsp)
movl %eax, 0x84(%rsp)
leaq 0x97(%rsp), %rdi
callq 0x2070
jmp 0x1d39
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x88(%rsp)
movl %eax, 0x84(%rsp)
leaq 0x67(%rsp), %rdi
callq 0x2070
leaq 0x98(%rsp), %rdi
callq 0x2080
jmp 0x1d39
movq $0x0, 0x40(%rsp)
cmpq $0x4c4b40, 0x40(%rsp)   # imm = 0x4C4B40
jae 0x1bc0
movq 0xb0(%rsp), %rdi
movq 0x40(%rsp), %rsi
callq 0x1f20
movq (%rax), %rsi
movq 0x50(%rsp), %rcx
shrq %cl, %rsi
andq $0xffff, %rsi           # imm = 0xFFFF
leaq 0x68(%rsp), %rdi
callq 0x1f20
movq (%rax), %rcx
addq $0x1, %rcx
movq %rcx, (%rax)
movq 0x40(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x40(%rsp)
jmp 0x1b6d
movq $0x1, 0x38(%rsp)
cmpq $0x10000, 0x38(%rsp)    # imm = 0x10000
jae 0x1c19
movq 0x38(%rsp), %rsi
subq $0x1, %rsi
leaq 0x68(%rsp), %rdi
callq 0x1f20
movq (%rax), %rax
movq %rax, 0x10(%rsp)
movq 0x38(%rsp), %rsi
leaq 0x68(%rsp), %rdi
callq 0x1f20
movq 0x10(%rsp), %rcx
addq (%rax), %rcx
movq %rcx, (%rax)
movq 0x38(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x38(%rsp)
jmp 0x1bc9
movq $0x4c4b3f, 0x30(%rsp)   # imm = 0x4C4B3F
cmpq $0x0, 0x30(%rsp)
jl 0x1ca1
movq 0xb0(%rsp), %rdi
movq 0x30(%rsp), %rsi
callq 0x1f20
movq (%rax), %rax
movq %rax, 0x8(%rsp)
movq 0xb0(%rsp), %rdi
movq 0x30(%rsp), %rsi
callq 0x1f20
movq (%rax), %rsi
movq 0x50(%rsp), %rcx
shrq %cl, %rsi
andq $0xffff, %rsi           # imm = 0xFFFF
leaq 0x68(%rsp), %rdi
callq 0x1f20
movq (%rax), %rsi
addq $-0x1, %rsi
movq %rsi, (%rax)
leaq 0x98(%rsp), %rdi
callq 0x1f20
movq 0x8(%rsp), %rcx
movq %rcx, (%rax)
movq 0x30(%rsp), %rax
addq $-0x1, %rax
movq %rax, 0x30(%rsp)
jmp 0x1c22
movq $0x0, 0x28(%rsp)
cmpq $0x4c4b40, 0x28(%rsp)   # imm = 0x4C4B40
jae 0x1cf7
movq 0x28(%rsp), %rsi
leaq 0x98(%rsp), %rdi
callq 0x1f20
movq (%rax), %rax
movq %rax, (%rsp)
movq 0xb0(%rsp), %rdi
movq 0x28(%rsp), %rsi
callq 0x1f20
movq (%rsp), %rcx
movq %rcx, (%rax)
movq 0x28(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x28(%rsp)
jmp 0x1caa
jmp 0x1cf9
movq 0x58(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x58(%rsp)
movq 0x50(%rsp), %rax
addq $0x10, %rax
movq %rax, 0x50(%rsp)
jmp 0x1ac8
leaq 0x68(%rsp), %rdi
callq 0x2080
leaq 0x98(%rsp), %rdi
callq 0x2080
addq $0xb8, %rsp
retq
movq 0x88(%rsp), %rdi
callq 0x1140
nopw %cs:(%rax,%rax)