#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 max(int *, int);
int /*<<< orphan*/ print(int *, int);
int /*<<< orphan*/ radix_sort(int *, int, int);
int main(void) {
  int arr[] = {3,   24,   78,  98, 6,  12, 45,   868,  211,  2215,    10,  459,
               678, 1357, 36,  9,  30, 25, 1,    49,   82,   492,     83,  153,
               767, 64,   916, 81, 4,  97, 1234, 6789, 8008, 7654321, 9876};
  int length = 35;
  int m = max(arr, length);
  for (int radix = 1; m / radix > 0; radix *= 10) {
    radix_sort(arr, length, radix);
    print(arr, length);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x90(%rbp),%rdi
lea    0xea0(%rip),%rsi
mov    $0x8c,%edx
call   1060 <memcpy@plt>
movl   $0x23,-0x94(%rbp)
lea    -0x90(%rbp),%rdi
mov    -0x94(%rbp),%esi
call   1030 <max@plt>
mov    %eax,-0x98(%rbp)
movl   $0x1,-0x9c(%rbp)
mov    -0x98(%rbp),%eax
cltd
idivl  -0x9c(%rbp)
cmp    $0x0,%eax
jle    11e8 <main+0xa8>
lea    -0x90(%rbp),%rdi
mov    -0x94(%rbp),%esi
mov    -0x9c(%rbp),%edx
call   1040 <radix_sort@plt>
lea    -0x90(%rbp),%rdi
mov    -0x94(%rbp),%esi
call   1050 <print@plt>
imul   $0xa,-0x9c(%rbp),%eax
mov    %eax,-0x9c(%rbp)
jmp    1196 <main+0x56>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x90,%rsp
lea    0xeae(%rip),%rsi
mov    %rsp,%rbx
mov    $0x8c,%edx
mov    %rbx,%rdi
call   1060 <memcpy@plt>
mov    %rbx,%rdi
mov    $0x23,%esi
call   1030 <max@plt>
test   %eax,%eax
jle    11ab <main+0x6b>
mov    %eax,%r14d
mov    $0x1,%ebx
mov    %rsp,%rbp
xchg   %ax,%ax
mov    %rbp,%rdi
mov    $0x23,%esi
mov    %ebx,%edx
call   1040 <radix_sort@plt>
mov    %rbp,%rdi
mov    $0x23,%esi
call   1050 <print@plt>
add    %ebx,%ebx
lea    (%rbx,%rbx,4),%ebx
mov    %r14d,%eax
cltd
idiv   %ebx
test   %eax,%eax
jg     1180 <main+0x40>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.arr = [35 x i32] [i32 3, i32 24, i32 78, i32 98, i32 6, i32 12, i32 45, i32 868, i32 211, i32 2215, i32 10, i32 459, i32 678, i32 1357, i32 36, i32 9, i32 30, i32 25, i32 1, i32 49, i32 82, i32 492, i32 83, i32 153, i32 767, i32 64, i32 916, i32 81, i32 4, i32 97, i32 1234, i32 6789, i32 8008, i32 7654321, i32 9876]
define i32 @main() {
%1 = alloca i32
%2 = alloca [35 x i32]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = bitcast [35 x i32]* %2 to i8*
store i32 35, i32* %3
%7 = getelementptr inbounds [35 x i32], [35 x i32]* %2, i64 0, i64 0
%8 = load i32, i32* %3
%9 = call i32 @max(i32* %7, i32 %8)
store i32 %9, i32* %4
store i32 1, i32* %5
br label %10
10: ; preds = %23, %0
%11 = load i32, i32* %4
%12 = load i32, i32* %5
%13 = sdiv i32 %11, %12
%14 = icmp sgt i32 %13, 0
br i1 %14, label %15, label %26
15: ; preds = %10
%16 = getelementptr inbounds [35 x i32], [35 x i32]* %2, i64 0, i64 0
%17 = load i32, i32* %3
%18 = load i32, i32* %5
%19 = call i32 @radix_sort(i32* %16, i32 %17, i32 %18)
%20 = getelementptr inbounds [35 x i32], [35 x i32]* %2, i64 0, i64 0
%21 = load i32, i32* %3
%22 = call i32 @print(i32* %20, i32 %21)
br label %23
23: ; preds = %15
%24 = load i32, i32* %5
%25 = mul nsw i32 %24, 10
store i32 %25, i32* %5
br label %10
26: ; preds = %10
ret i32 0
}

LLVM IR (-O2):
@__const.main.arr = [35 x i32] [i32 3, i32 24, i32 78, i32 98, i32 6, i32 12, i32 45, i32 868, i32 211, i32 2215, i32 10, i32 459, i32 678, i32 1357, i32 36, i32 9, i32 30, i32 25, i32 1, i32 49, i32 82, i32 492, i32 83, i32 153, i32 767, i32 64, i32 916, i32 81, i32 4, i32 97, i32 1234, i32 6789, i32 8008, i32 7654321, i32 9876]
define i32 @main() {
%1 = alloca [35 x i32]
%2 = bitcast [35 x i32]* %1 to i8*
%3 = getelementptr inbounds [35 x i32], [35 x i32]* %1, i64 0, i64 0
%4 = call i32 @max(i32* %3, i32 35)
%5 = icmp sgt i32 %4, 0
br i1 %5, label %7, label %6
6: ; preds = %7, %0
ret i32 0
7: ; preds = %0, %7
%8 = phi i32 [ %11, %7 ], [ 1, %0 ]
%9 = call i32 @radix_sort(i32* %3, i32 35, i32 %8)
%10 = call i32 @print(i32* %3, i32 35)
%11 = mul nsw i32 %8, 10
%12 = sdiv i32 %4, %11
%13 = icmp sgt i32 %12, 0
br i1 %13, label %7, label %6
}