#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 */

/* Variables and functions */
int /*<<< orphan*/ counting_sort(int *, int *, int, int, int);
void radix_sort(int a[], int *b, int size, int max) {
  for (int unit = 1; (max / unit) > 0; unit *= 10) {
    if (unit == 1) {
      counting_sort(a, b, size, max, unit);
    } else {
      int temp[size];
      for (int i = 0; i < size; i++)
        temp[i] = b[i];
      counting_sort(temp, b, size, max, unit);
    }
  }
}


x86 assembly (clang, -O0):
<radix_sort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
cltd
idivl  -0x1c(%rbp)
cmp    $0x0,%eax
jle    11f0 <radix_sort+0xe0>
cmpl   $0x1,-0x1c(%rbp)
jne    1163 <radix_sort+0x53>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
call   1030 <counting_sort@plt>
jmp    11df <radix_sort+0xcf>
mov    -0x14(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11c1 <radix_sort+0xb1>
mov    -0x40(%rbp),%rax
mov    -0x10(%rbp),%rcx
movslq -0x34(%rbp),%rdx
mov    (%rcx,%rdx,4),%edx
movslq -0x34(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1191 <radix_sort+0x81>
mov    -0x40(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
call   1030 <counting_sort@plt>
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
jmp    11e4 <radix_sort+0xd4>
imul   $0xa,-0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    112d <radix_sort+0x1d>
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<radix_sort>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %edx,-0x2c(%rbp)
mov    %rdi,-0x48(%rbp)
test   %ecx,%ecx
jle    11dc <radix_sort+0xbc>
mov    %ecx,%r14d
mov    %rsi,%rbx
mov    -0x2c(%rbp),%eax
mov    $0x1,%r13d
lea    0xf(,%rax,4),%rcx
shl    $0x2,%rax
mov    %rax,-0x38(%rbp)
and    $0xfffffffffffffff0,%rcx
mov    %rcx,-0x40(%rbp)
jmp    119b <radix_sort+0x7b>
nopl   0x0(%rax)
mov    -0x48(%rbp),%rdi
mov    %rbx,%rsi
mov    -0x2c(%rbp),%edx
mov    %r14d,%ecx
mov    $0x1,%r8d
call   1030 <counting_sort@plt>
add    %r13d,%r13d
lea    0x0(%r13,%r13,4),%r13d
mov    %r14d,%eax
cltd
idiv   %r13d
test   %eax,%eax
jle    11dc <radix_sort+0xbc>
cmp    $0x1,%r13d
je     1170 <radix_sort+0x50>
mov    %rsp,%r15
mov    %rsp,%r12
sub    -0x40(%rbp),%r12
mov    %r12,%rsp
cmpl   $0x0,-0x2c(%rbp)
jle    11c3 <radix_sort+0xa3>
mov    %r12,%rdi
mov    %rbx,%rsi
mov    -0x38(%rbp),%rdx
call   1040 <memcpy@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
mov    -0x2c(%rbp),%edx
mov    %r14d,%ecx
mov    %r13d,%r8d
call   1030 <counting_sort@plt>
mov    %r15,%rsp
jmp    1188 <radix_sort+0x68>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @radix_sort(i32* %0, i32* %1, i32 %2, i32 %3) {
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i32
store i32* %0, i32** %5
store i32* %1, i32** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
store i32 1, i32* %9
br label %13
13: ; preds = %57, %4
%14 = load i32, i32* %8
%15 = load i32, i32* %9
%16 = sdiv i32 %14, %15
%17 = icmp sgt i32 %16, 0
br i1 %17, label %18, label %60
18: ; preds = %13
%19 = load i32, i32* %9
%20 = icmp eq i32 %19, 1
br i1 %20, label %21, label %28
21: ; preds = %18
%22 = load i32*, i32** %5
%23 = load i32*, i32** %6
%24 = load i32, i32* %7
%25 = load i32, i32* %8
%26 = load i32, i32* %9
%27 = call i32 @counting_sort(i32* %22, i32* %23, i32 %24, i32 %25, i32 %26)
br label %56
28: ; preds = %18
%29 = load i32, i32* %7
%30 = zext i32 %29 to i64
%31 = call i8* @llvm.stacksave()
store i8* %31, i8** %10
%32 = alloca i32, i64 %30
store i64 %30, i64* %11
store i32 0, i32* %12
br label %33
33: ; preds = %46, %28
%34 = load i32, i32* %12
%35 = load i32, i32* %7
%36 = icmp slt i32 %34, %35
br i1 %36, label %37, label %49
37: ; preds = %33
%38 = load i32*, i32** %6
%39 = load i32, i32* %12
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i32, i32* %38, i64 %40
%42 = load i32, i32* %41
%43 = load i32, i32* %12
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i32, i32* %32, i64 %44
store i32 %42, i32* %45
br label %46
46: ; preds = %37
%47 = load i32, i32* %12
%48 = add nsw i32 %47, 1
store i32 %48, i32* %12
br label %33
49: ; preds = %33
%50 = load i32*, i32** %6
%51 = load i32, i32* %7
%52 = load i32, i32* %8
%53 = load i32, i32* %9
%54 = call i32 @counting_sort(i32* %32, i32* %50, i32 %51, i32 %52, i32 %53)
%55 = load i8*, i8** %10
br label %56
56: ; preds = %49, %21
br label %57
57: ; preds = %56
%58 = load i32, i32* %9
%59 = mul nsw i32 %58, 10
store i32 %59, i32* %9
br label %13
60: ; preds = %13
ret void
}

LLVM IR (-O2):
define void @radix_sort(i32* %0, i32* %1, i32 %2, i32 %3) {
%5 = bitcast i32* %1 to i8*
%6 = icmp sgt i32 %3, 0
br i1 %6, label %7, label %11
7: ; preds = %4
%8 = zext i32 %2 to i64
%9 = icmp sgt i32 %2, 0
%10 = shl nuw nsw i64 %8, 2
br label %12
11: ; preds = %24, %4
ret void
12: ; preds = %7, %24
%13 = phi i32 [ 1, %7 ], [ %25, %24 ]
%14 = icmp eq i32 %13, 1
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = call i32 @counting_sort(i32* %0, i32* %1, i32 %2, i32 %3, i32 1)
br label %24
17: ; preds = %12
%18 = call i8* @llvm.stacksave()
%19 = alloca i32, i64 %8
br i1 %9, label %20, label %22
20: ; preds = %17
%21 = bitcast i32* %19 to i8*
br label %22
22: ; preds = %20, %17
%23 = call i32 @counting_sort(i32* %19, i32* %1, i32 %2, i32 %3, i32 %13)
br label %24
24: ; preds = %15, %22
%25 = mul nsw i32 %13, 10
%26 = sdiv i32 %3, %25
%27 = icmp sgt i32 %26, 0
br i1 %27, label %12, label %11
}