#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int ulong;

/* Variables and functions */
int /*<<< orphan*/ assert(int /*<<< orphan*/);
int /*<<< orphan*/ free(int *);
scalar_t__ malloc(int);
int /*<<< orphan*/ radix(int, int, int *, int *);
void radix_sort(ulong *source, ulong N) {
  ulong *temp = (ulong *)malloc(N * sizeof(ulong));
  assert(temp != NULL);
  radix(3, N, source, temp);
  radix(2, N, temp, source);
  radix(1, N, source, temp);
  radix(0, N, temp, source);
  free(temp);
}


x86 assembly (clang, -O0):
<radix_sort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0xc(%rbp),%esi
mov    -0x8(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    $0x3,%edi
call   1050 <radix@plt>
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rdx
mov    -0x8(%rbp),%rcx
mov    $0x2,%edi
call   1050 <radix@plt>
mov    -0xc(%rbp),%esi
mov    -0x8(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    $0x1,%edi
call   1050 <radix@plt>
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rdx
mov    -0x8(%rbp),%rcx
xor    %edi,%edi
call   1050 <radix@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<radix_sort>:
push   %r15
push   %r14
push   %rbx
mov    %esi,%r15d
mov    %rdi,%r14
lea    0x0(,%r15,4),%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1040 <assert@plt>
mov    $0x3,%edi
mov    %r15d,%esi
mov    %r14,%rdx
mov    %rbx,%rcx
call   1050 <radix@plt>
mov    $0x2,%edi
mov    %r15d,%esi
mov    %rbx,%rdx
mov    %r14,%rcx
call   1050 <radix@plt>
mov    $0x1,%edi
mov    %r15d,%esi
mov    %r14,%rdx
mov    %rbx,%rcx
call   1050 <radix@plt>
xor    %edi,%edi
mov    %r15d,%esi
mov    %rbx,%rdx
mov    %r14,%rcx
call   1050 <radix@plt>
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <free@plt>

LLVM IR (-O0):
define void @radix_sort(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32*
store i32* %0, i32** %3
store i32 %1, i32* %4
%6 = load i32, i32* %4
%7 = sext i32 %6 to i64
%8 = mul i64 %7, 4
%9 = trunc i64 %8 to i32
%10 = call i64 @malloc(i32 %9)
%11 = inttoptr i64 %10 to i32*
store i32* %11, i32** %5
%12 = load i32*, i32** %5
%13 = icmp ne i32* %12, null
%14 = zext i1 %13 to i32
%15 = call i32 @assert(i32 %14)
%16 = load i32, i32* %4
%17 = load i32*, i32** %3
%18 = load i32*, i32** %5
%19 = call i32 @radix(i32 3, i32 %16, i32* %17, i32* %18)
%20 = load i32, i32* %4
%21 = load i32*, i32** %5
%22 = load i32*, i32** %3
%23 = call i32 @radix(i32 2, i32 %20, i32* %21, i32* %22)
%24 = load i32, i32* %4
%25 = load i32*, i32** %3
%26 = load i32*, i32** %5
%27 = call i32 @radix(i32 1, i32 %24, i32* %25, i32* %26)
%28 = load i32, i32* %4
%29 = load i32*, i32** %5
%30 = load i32*, i32** %3
%31 = call i32 @radix(i32 0, i32 %28, i32* %29, i32* %30)
%32 = load i32*, i32** %5
%33 = call i32 @free(i32* %32)
ret void
}

LLVM IR (-O2):
define void @radix_sort(i32* %0, i32 %1) {
%3 = shl i32 %1, 2
%4 = tail call i64 @malloc(i32 %3)
%5 = inttoptr i64 %4 to i32*
%6 = icmp ne i64 %4, 0
%7 = zext i1 %6 to i32
%8 = tail call i32 @assert(i32 %7)
%9 = tail call i32 @radix(i32 3, i32 %1, i32* %0, i32* %5)
%10 = tail call i32 @radix(i32 2, i32 %1, i32* %5, i32* %0)
%11 = tail call i32 @radix(i32 1, i32 %1, i32* %0, i32* %5)
%12 = tail call i32 @radix(i32 0, i32 %1, i32* %5, i32* %0)
%13 = tail call i32 @free(i32* %5)
ret void
}