#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*/ Add(int, int);
int /*<<< orphan*/ CopyBack(int *);
int /*<<< orphan*/ Init();
void radix_sort(int a[], int len) {
  int i, j;
  int left;
  int base = 1;
  bool more = true;
  int key;
  do {
    Init();
    more = false;
    for (i = 0; i < len; i++) {
      left = a[i] / base;
      key = left % 10;
      if (left || more)
        more = true;
      Add(a[i], key);
    }
    CopyBack(a);
    base = base * 10;
  } while (more);
}


x86 assembly (clang, -O0):
<radix_sort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x1,-0x1c(%rbp)
movl   $0x1,-0x20(%rbp)
mov    $0x0,%al
call   1040 <Init@plt>
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11ca <radix_sort+0x9a>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
cltd
idivl  -0x1c(%rbp)
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0x24(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    11a2 <radix_sort+0x72>
cmpl   $0x0,-0x20(%rbp)
je     11a9 <radix_sort+0x79>
movl   $0x1,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
mov    -0x24(%rbp),%esi
call   1050 <Add@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1162 <radix_sort+0x32>
mov    -0x8(%rbp),%rdi
call   1030 <CopyBack@plt>
imul   $0xa,-0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x20(%rbp)
jne    114d <radix_sort+0x1d>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<radix_sort>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r13
mov    %esi,0x4(%rsp)
mov    %esi,%r12d
mov    $0x1,%r15d
mov    $0x1,%ebp
xor    %eax,%eax
call   1040 <Init@plt>
cmpl   $0x0,0x4(%rsp)
jle    11ce <radix_sort+0x9e>
xor    %r14d,%r14d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x0(%r13,%r14,4),%edi
mov    %edi,%eax
cltd
idiv   %ebp
cltq
imul   $0x66666667,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rcx
add    %edx,%ecx
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%ecx
mov    %eax,%esi
sub    %ecx,%esi
or     %ebx,%eax
cmovne %r15d,%ebx
call   1050 <Add@plt>
add    $0x1,%r14
cmp    %r14,%r12
jne    1170 <radix_sort+0x40>
mov    %r13,%rdi
call   1030 <CopyBack@plt>
add    %ebp,%ebp
lea    0x0(%rbp,%rbp,4),%ebp
test   %ebx,%ebx
jne    1150 <radix_sort+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r13,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <CopyBack@plt>

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

LLVM IR (-O2):
define void @radix_sort(i32* %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
%4 = zext i32 %1 to i64
br label %5
5: ; preds = %24, %2
%6 = phi i32 [ 1, %2 ], [ %26, %24 ]
%7 = tail call i32 (...) @Init()
br i1 %3, label %10, label %8
8: ; preds = %5
%9 = tail call i32 @CopyBack(i32* %0)
br label %28
10: ; preds = %5, %10
%11 = phi i64 [ %22, %10 ], [ 0, %5 ]
%12 = phi i32 [ %20, %10 ], [ 0, %5 ]
%13 = getelementptr inbounds i32, i32* %0, i64 %11
%14 = load i32, i32* %13
%15 = sdiv i32 %14, %6
%16 = srem i32 %15, 10
%17 = icmp ne i32 %15, 0
%18 = icmp ne i32 %12, 0
%19 = select i1 %17, i1 true, i1 %18
%20 = select i1 %19, i32 1, i32 %12
%21 = tail call i32 @Add(i32 %14, i32 %16)
%22 = add nuw nsw i64 %11, 1
%23 = icmp eq i64 %22, %4
br i1 %23, label %24, label %10
24: ; preds = %10
%25 = tail call i32 @CopyBack(i32* %0)
%26 = mul nsw i32 %6, 10
%27 = icmp eq i32 %20, 0
br i1 %27, label %28, label %5
28: ; preds = %24, %8
ret void
}