#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 /*<<< orphan*/ a;

/* Variables and functions */
int /*<<< orphan*/ bucketSort(int *, int, int);
int getMaxNumInArray(int *, int);
int /*<<< orphan*/ printAfterSort(int *, int);
int /*<<< orphan*/ printBeforeSort(int *, int);
int /*<<< orphan*/ printf(char *, int);
int main(int argc, char **argv) {
  int a[] = {300, 25, 22, 43, 66, 8, 2, 6, 99, 1000};
  int size = sizeof(a) / sizeof(a[0]);
  int ex = 1;
  int maxNum = getMaxNumInArray(a, size);
  printBeforeSort(a, size);
  while ((maxNum / ex) != 0) {
    printf("%d\n", (maxNum / ex));
    bucketSort(a, size, ex);
    ex = ex * 10;
  }
  printAfterSort(a, size);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x40(%rbp),%rdi
lea    0xe7f(%rip),%rsi
mov    $0x28,%edx
call   1040 <memcpy@plt>
movl   $0xa,-0x44(%rbp)
movl   $0x1,-0x48(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0x44(%rbp),%esi
call   1070 <getMaxNumInArray@plt>
mov    %eax,-0x4c(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0x44(%rbp),%esi
call   1080 <printBeforeSort@plt>
mov    -0x4c(%rbp),%eax
cltd
idivl  -0x48(%rbp)
cmp    $0x0,%eax
je     11f4 <main+0x94>
mov    -0x4c(%rbp),%eax
cltd
idivl  -0x48(%rbp)
mov    %eax,%esi
lea    0xe54(%rip),%rdi
call   1030 <printf@plt>
lea    -0x40(%rbp),%rdi
mov    -0x44(%rbp),%esi
mov    -0x48(%rbp),%edx
call   1060 <bucketSort@plt>
imul   $0xa,-0x48(%rbp),%eax
mov    %eax,-0x48(%rbp)
jmp    11b4 <main+0x54>
lea    -0x40(%rbp),%rdi
mov    -0x44(%rbp),%esi
call   1050 <printAfterSort@plt>
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    0xebf(%rip),%rax
mov    %rax,0x20(%rsp)
movaps 0xea3(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xe87(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0xa,%esi
call   1060 <getMaxNumInArray@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
mov    $0xa,%esi
call   1070 <printBeforeSort@plt>
test   %ebp,%ebp
je     11e7 <main+0x97>
mov    $0x1,%ebx
lea    0xe7c(%rip),%r14
mov    %rsp,%r15
mov    %ebp,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    %r15,%rdi
mov    $0xa,%esi
mov    %ebx,%edx
call   1050 <bucketSort@plt>
add    %ebx,%ebx
lea    (%rbx,%rbx,4),%ebx
mov    %ebp,%eax
cltd
idiv   %ebx
test   %eax,%eax
jne    11c0 <main+0x70>
mov    %rsp,%rdi
mov    $0xa,%esi
call   1040 <printAfterSort@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.a = [10 x i32] [i32 300, i32 25, i32 22, i32 43, i32 66, i32 8, i32 2, i32 6, i32 99, i32 1000]
@.str = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [10 x i32]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = bitcast [10 x i32]* %6 to i8*
store i32 10, i32* %7
store i32 1, i32* %8
%11 = getelementptr inbounds [10 x i32], [10 x i32]* %6, i64 0, i64 0
%12 = load i32, i32* %7
%13 = call i32 @getMaxNumInArray(i32* %11, i32 %12)
store i32 %13, i32* %9
%14 = getelementptr inbounds [10 x i32], [10 x i32]* %6, i64 0, i64 0
%15 = load i32, i32* %7
%16 = call i32 @printBeforeSort(i32* %14, i32 %15)
br label %17
17: ; preds = %22, %2
%18 = load i32, i32* %9
%19 = load i32, i32* %8
%20 = sdiv i32 %18, %19
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %33
22: ; preds = %17
%23 = load i32, i32* %9
%24 = load i32, i32* %8
%25 = sdiv i32 %23, %24
%26 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %25)
%27 = getelementptr inbounds [10 x i32], [10 x i32]* %6, i64 0, i64 0
%28 = load i32, i32* %7
%29 = load i32, i32* %8
%30 = call i32 @bucketSort(i32* %27, i32 %28, i32 %29)
%31 = load i32, i32* %8
%32 = mul nsw i32 %31, 10
store i32 %32, i32* %8
br label %17
33: ; preds = %17
%34 = getelementptr inbounds [10 x i32], [10 x i32]* %6, i64 0, i64 0
%35 = load i32, i32* %7
%36 = call i32 @printAfterSort(i32* %34, i32 %35)
%37 = load i32, i32* %3
ret i32 %37
}

LLVM IR (-O2):
@__const.main.a = [10 x i32] [i32 300, i32 25, i32 22, i32 43, i32 66, i32 8, i32 2, i32 6, i32 99, i32 1000]
@.str = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [10 x i32]
%4 = bitcast [10 x i32]* %3 to i8*
%5 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 0
%6 = call i32 @getMaxNumInArray(i32* %5, i32 10)
%7 = call i32 @printBeforeSort(i32* %5, i32 10)
%8 = icmp eq i32 %6, 0
br i1 %8, label %17, label %9
9: ; preds = %2, %9
%10 = phi i32 [ %15, %9 ], [ %6, %2 ]
%11 = phi i32 [ %14, %9 ], [ 1, %2 ]
%12 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %10)
%13 = call i32 @bucketSort(i32* %5, i32 10, i32 %11)
%14 = mul nsw i32 %11, 10
%15 = sdiv i32 %6, %14
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %9
17: ; preds = %9, %2
%18 = call i32 @printAfterSort(i32* %5, i32 10)
ret i32 0
}