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

/* Variables and functions */
int EXIT_SUCCESS;
int /*<<< orphan*/ counting_sort(int, int, int *);
int /*<<< orphan*/ printf(char *, int);
int main(int argc, char **argv) {
  int v[] = {10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
  int n = sizeof(v) / sizeof(v[0]);
  int k = 0;
  for (int i = 0; i < n; i++) {
    if (v[i] > k)
      k = v[i];
  }
  counting_sort(n, k, v);
  for (int i = 0; i < n; i++) {
    printf("%d ", v[i]);
  }
  return EXIT_SUCCESS;
}


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    0xeaf(%rip),%rsi
mov    $0x28,%edx
call   1050 <memcpy@plt>
movl   $0xa,-0x44(%rbp)
movl   $0x0,-0x48(%rbp)
movl   $0x0,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
cmp    -0x44(%rbp),%eax
jge    11ab <main+0x7b>
movslq -0x4c(%rbp),%rax
mov    -0x40(%rbp,%rax,4),%eax
cmp    -0x48(%rbp),%eax
jle    1198 <main+0x68>
movslq -0x4c(%rbp),%rax
mov    -0x40(%rbp,%rax,4),%eax
mov    %eax,-0x48(%rbp)
jmp    119d <main+0x6d>
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
jmp    1170 <main+0x40>
mov    -0x44(%rbp),%edi
mov    -0x48(%rbp),%esi
lea    -0x40(%rbp),%rdx
call   1040 <counting_sort@plt>
movl   $0x0,-0x50(%rbp)
mov    -0x50(%rbp),%eax
cmp    -0x44(%rbp),%eax
jge    11ef <main+0xbf>
movslq -0x50(%rbp),%rax
mov    -0x40(%rbp,%rax,4),%esi
lea    0xe4c(%rip),%rdi
call   1030 <printf@plt>
mov    -0x50(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x50(%rbp)
jmp    11c1 <main+0x91>
mov    0x2dea(%rip),%rax
mov    (%rax),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x30,%rsp
mov    0xef4(%rip),%rax
mov    %rax,0x20(%rsp)
movaps 0xed8(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xebc(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%rdx
mov    $0xa,%edi
mov    $0xa,%esi
call   1040 <counting_sort@plt>
mov    (%rsp),%esi
lea    0xec4(%rip),%rbx
mov    %rbx,%rdi
call   1030 <printf@plt>
mov    0x4(%rsp),%esi
mov    %rbx,%rdi
call   1030 <printf@plt>
mov    0x8(%rsp),%esi
mov    %rbx,%rdi
call   1030 <printf@plt>
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
call   1030 <printf@plt>
mov    0x10(%rsp),%esi
mov    %rbx,%rdi
call   1030 <printf@plt>
mov    0x14(%rsp),%esi
mov    %rbx,%rdi
call   1030 <printf@plt>
mov    0x18(%rsp),%esi
mov    %rbx,%rdi
call   1030 <printf@plt>
mov    0x1c(%rsp),%esi
mov    %rbx,%rdi
call   1030 <printf@plt>
mov    0x20(%rsp),%esi
mov    %rbx,%rdi
call   1030 <printf@plt>
mov    0x24(%rsp),%esi
mov    %rbx,%rdi
call   1030 <printf@plt>
mov    0x2e01(%rip),%rax
mov    (%rax),%eax
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.main.v = [10 x i32] [i32 10, i32 9, i32 8, i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1]
@.str = [4 x i8] c"%d \00"
@EXIT_SUCCESS = global i32 0
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
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = bitcast [10 x i32]* %6 to i8*
store i32 10, i32* %7
store i32 0, i32* %8
store i32 0, i32* %9
br label %12
12: ; preds = %29, %2
%13 = load i32, i32* %9
%14 = load i32, i32* %7
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %32
16: ; preds = %12
%17 = load i32, i32* %9
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [10 x i32], [10 x i32]* %6, i64 0, i64 %18
%20 = load i32, i32* %19
%21 = load i32, i32* %8
%22 = icmp sgt i32 %20, %21
br i1 %22, label %23, label %28
23: ; preds = %16
%24 = load i32, i32* %9
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [10 x i32], [10 x i32]* %6, i64 0, i64 %25
%27 = load i32, i32* %26
store i32 %27, i32* %8
br label %28
28: ; preds = %23, %16
br label %29
29: ; preds = %28
%30 = load i32, i32* %9
%31 = add nsw i32 %30, 1
store i32 %31, i32* %9
br label %12
32: ; preds = %12
%33 = load i32, i32* %7
%34 = load i32, i32* %8
%35 = getelementptr inbounds [10 x i32], [10 x i32]* %6, i64 0, i64 0
%36 = call i32 @counting_sort(i32 %33, i32 %34, i32* %35)
store i32 0, i32* %10
br label %37
37: ; preds = %47, %32
%38 = load i32, i32* %10
%39 = load i32, i32* %7
%40 = icmp slt i32 %38, %39
br i1 %40, label %41, label %50
41: ; preds = %37
%42 = load i32, i32* %10
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [10 x i32], [10 x i32]* %6, i64 0, i64 %43
%45 = load i32, i32* %44
%46 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %45)
br label %47
47: ; preds = %41
%48 = load i32, i32* %10
%49 = add nsw i32 %48, 1
store i32 %49, i32* %10
br label %37
50: ; preds = %37
%51 = load i32, i32* @EXIT_SUCCESS
ret i32 %51
}

LLVM IR (-O2):
@__const.main.v = [10 x i32] [i32 10, i32 9, i32 8, i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1]
@.str = [4 x i8] c"%d \00"
@EXIT_SUCCESS = global i32 0
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 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 1
%7 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 2
%8 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 3
%9 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 4
%10 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 5
%11 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 6
%12 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 7
%13 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 8
%14 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 9
%15 = call i32 @counting_sort(i32 10, i32 10, i32* %5)
%16 = load i32, i32* %5
%17 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %16)
%18 = load i32, i32* %6
%19 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %18)
%20 = load i32, i32* %7
%21 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %20)
%22 = load i32, i32* %8
%23 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %22)
%24 = load i32, i32* %9
%25 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %24)
%26 = load i32, i32* %10
%27 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %26)
%28 = load i32, i32* %11
%29 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %28)
%30 = load i32, i32* %12
%31 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %30)
%32 = load i32, i32* %13
%33 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %32)
%34 = load i32, i32* %14
%35 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %34)
%36 = load i32, i32* @EXIT_SUCCESS
ret i32 %36
}