#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 /*<<< orphan*/ printf(char *, ...);
int rand();
int main(void) {
  int testdata[100];
  int rtndata[100];
  size_t idx;
  printf("The test data is:\n");
  for (idx = 0; idx < 100; idx++) {
    testdata[idx] = rand() % 100;
    printf("%zu\t,%d,\n", idx, testdata[idx]);
  }
  counting_sort(testdata, rtndata, 100);
  for (idx = 0; idx < 100; idx++) {
    printf("%zu\t,%d,\n", idx, rtndata[idx]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x340,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeb7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movq   $0x0,-0x338(%rbp)
cmpq   $0x64,-0x338(%rbp)
64
jae    11c0 <main+0x90>
mov    $0x0,%al
call   1050 <rand@plt>
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    -0x338(%rbp),%rax
mov    %edx,-0x1a0(%rbp,%rax,4)
mov    -0x338(%rbp),%rsi
mov    -0x338(%rbp),%rax
mov    -0x1a0(%rbp,%rax,4),%edx
lea    0xe71(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x338(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x338(%rbp)
jmp    115b <main+0x2b>
lea    -0x1a0(%rbp),%rdi
lea    -0x330(%rbp),%rsi
mov    $0x64,%edx
call   1040 <counting_sort@plt>
movq   $0x0,-0x338(%rbp)
cmpq   $0x64,-0x338(%rbp)
64
jae    122b <main+0xfb>
mov    -0x338(%rbp),%rsi
mov    -0x338(%rbp),%rax
mov    -0x330(%rbp,%rax,4),%edx
lea    0xe06(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x338(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x338(%rbp)
jmp    11e3 <main+0xb3>
xor    %eax,%eax
add    $0x340,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x328,%rsp
lea    0xeb9(%rip),%rdi
call   1030 <puts@plt>
lea    0xea3(%rip),%r14
xor    %ebx,%ebx
nop
xor    %eax,%eax
call   1060 <rand@plt>
movslq %eax,%rdx
imul   $0x51eb851f,%rdx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x25,%rax
add    %ecx,%eax
imul   $0x64,%eax,%eax
sub    %eax,%edx
mov    %edx,0x190(%rsp,%rbx,4)
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    $0x64,%rbx
jne    1160 <main+0x20>
lea    0x190(%rsp),%rdi
mov    %rsp,%rsi
mov    $0x64,%edx
call   1050 <counting_sort@plt>
lea    0xe43(%rip),%r14
xor    %ebx,%ebx
nop
mov    (%rsp,%rbx,4),%edx
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    $0x64,%rbx
jne    11c0 <main+0x80>
xor    %eax,%eax
add    $0x328,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [19 x i8] c"The test data is:\0A\00"
@.str.1 = [10 x i8] c"%zu\09,%d,\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [100 x i32]
%3 = alloca [100 x i32]
%4 = alloca i64
store i32 0, i32* %1
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
store i64 0, i64* %4
br label %6
6: ; preds = %19, %0
%7 = load i64, i64* %4
%8 = icmp ult i64 %7, 100
br i1 %8, label %9, label %22
9: ; preds = %6
%10 = call i32 (...) @rand()
%11 = srem i32 %10, 100
%12 = load i64, i64* %4
%13 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 %12
store i32 %11, i32* %13
%14 = load i64, i64* %4
%15 = load i64, i64* %4
%16 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 %15
%17 = load i32, i32* %16
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i64 %14, i32 %17)
br label %19
19: ; preds = %9
%20 = load i64, i64* %4
%21 = add i64 %20, 1
store i64 %21, i64* %4
br label %6
22: ; preds = %6
%23 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 0
%24 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 0
%25 = call i32 @counting_sort(i32* %23, i32* %24, i32 100)
store i64 0, i64* %4
br label %26
26: ; preds = %35, %22
%27 = load i64, i64* %4
%28 = icmp ult i64 %27, 100
br i1 %28, label %29, label %38
29: ; preds = %26
%30 = load i64, i64* %4
%31 = load i64, i64* %4
%32 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 %31
%33 = load i32, i32* %32
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i64 %30, i32 %33)
br label %35
35: ; preds = %29
%36 = load i64, i64* %4
%37 = add i64 %36, 1
store i64 %37, i64* %4
br label %26
38: ; preds = %26
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [10 x i8] c"%zu\09,%d,\0A\00"
@str = [18 x i8] c"The test data is:\00"
define i32 @main() {
%1 = alloca [100 x i32]
%2 = alloca [100 x i32]
%3 = bitcast [100 x i32]* %1 to i8*
%4 = bitcast [100 x i32]* %2 to i8*
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
br label %6
6: ; preds = %0, %6
%7 = phi i64 [ 0, %0 ], [ %12, %6 ]
%8 = tail call i32 (...) @rand()
%9 = srem i32 %8, 100
%10 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 %7
store i32 %9, i32* %10
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i64 %7, i32 %9)
%12 = add nuw nsw i64 %7, 1
%13 = icmp eq i64 %12, 100
br i1 %13, label %14, label %6
14: ; preds = %6
%15 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 0
%16 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 0
%17 = call i32 @counting_sort(i32* %15, i32* %16, i32 100)
br label %18
18: ; preds = %14, %18
%19 = phi i64 [ 0, %14 ], [ %23, %18 ]
%20 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 %19
%21 = load i32, i32* %20
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i64 %19, i32 %21)
%23 = add nuw nsw i64 %19, 1
%24 = icmp eq i64 %23, 100
br i1 %24, label %25, label %18
25: ; preds = %18
ret i32 0
}