#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*/ countingSort(int *, int, int);
int /*<<< orphan*/ printArray(int *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int A[100], n, i, s, maxElement = -1;
  printf("Enter Number of Elements: ");
  scanf("%d", &n);
  printf("Enter %d Elements(>=0):\n", n);
  for (i = 0; i < n; i++) {
    scanf("%d", &A[i]);
    maxElement = (maxElement > A[i]) ? maxElement : A[i];
  }
  countingSort(A, n, maxElement);
  printArray(A, n);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1c0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xffffffff,-0x1b0(%rbp)
ff ff ff
lea    0xe9d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeaa(%rip),%rdi
lea    -0x1a4(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x1a4(%rbp),%esi
lea    0xe94(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x1a8(%rbp)
mov    -0x1a8(%rbp),%eax
cmp    -0x1a4(%rbp),%eax
jge    122d <main+0xed>
movslq -0x1a8(%rbp),%rax
lea    -0x1a0(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe52(%rip),%rdi
call   1040 <scanf@plt>
mov    -0x1b0(%rbp),%eax
movslq -0x1a8(%rbp),%rcx
cmp    -0x1a0(%rbp,%rcx,4),%eax
jle    11f9 <main+0xb9>
mov    -0x1b0(%rbp),%eax
mov    %eax,-0x1b4(%rbp)
jmp    120d <main+0xcd>
movslq -0x1a8(%rbp),%rax
mov    -0x1a0(%rbp,%rax,4),%eax
mov    %eax,-0x1b4(%rbp)
mov    -0x1b4(%rbp),%eax
mov    %eax,-0x1b0(%rbp)
mov    -0x1a8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1a8(%rbp)
jmp    119b <main+0x5b>
lea    -0x1a0(%rbp),%rdi
mov    -0x1a4(%rbp),%esi
mov    -0x1b0(%rbp),%edx
call   1050 <countingSort@plt>
lea    -0x1a0(%rbp),%rdi
mov    -0x1a4(%rbp),%esi
call   1060 <printArray@plt>
xor    %eax,%eax
add    $0x1c0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x1a8,%rsp
lea    0xeac(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xeb9(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1040 <scanf@plt>
mov    0xc(%rsp),%esi
lea    0xea7(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0xc(%rsp),%esi
mov    $0xffffffff,%edx
test   %esi,%esi
jle    11c6 <main+0x86>
lea    0x10(%rsp),%rbx
xor    %r15d,%r15d
lea    0xe81(%rip),%r14
nopw   0x0(%rax,%rax,1)
mov    %edx,%ebp
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <scanf@plt>
mov    (%rbx),%edx
cmp    %edx,%ebp
cmovg  %ebp,%edx
add    $0x1,%r15
movslq 0xc(%rsp),%rsi
add    $0x4,%rbx
cmp    %rsi,%r15
jl     11a0 <main+0x60>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1050 <countingSort@plt>
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
call   1060 <printArray@plt>
xor    %eax,%eax
add    $0x1a8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [27 x i8] c"Enter Number of Elements: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [25 x i8] c"Enter %d Elements(>=0):\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [100 x i32]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
store i32 -1, i32* %6
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%9 = load i32, i32* %3
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 %9)
store i32 0, i32* %4
br label %11
11: ; preds = %35, %0
%12 = load i32, i32* %4
%13 = load i32, i32* %3
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %38
15: ; preds = %11
%16 = load i32, i32* %4
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 %17
%19 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %18)
%20 = load i32, i32* %6
%21 = load i32, i32* %4
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 %22
%24 = load i32, i32* %23
%25 = icmp sgt i32 %20, %24
br i1 %25, label %26, label %28
26: ; preds = %15
%27 = load i32, i32* %6
br label %33
28: ; preds = %15
%29 = load i32, i32* %4
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 %30
%32 = load i32, i32* %31
br label %33
33: ; preds = %28, %26
%34 = phi i32 [ %27, %26 ], [ %32, %28 ]
store i32 %34, i32* %6
br label %35
35: ; preds = %33
%36 = load i32, i32* %4
%37 = add nsw i32 %36, 1
store i32 %37, i32* %4
br label %11
38: ; preds = %11
%39 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 0
%40 = load i32, i32* %3
%41 = load i32, i32* %6
%42 = call i32 @countingSort(i32* %39, i32 %40, i32 %41)
%43 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 0
%44 = load i32, i32* %3
%45 = call i32 @printArray(i32* %43, i32 %44)
ret i32 0
}

LLVM IR (-O2):
@.str = [27 x i8] c"Enter Number of Elements: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [25 x i8] c"Enter %d Elements(>=0):\0A\00"
define i32 @main() {
%1 = alloca [100 x i32]
%2 = alloca i32
%3 = bitcast [100 x i32]* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%7 = load i32, i32* %2
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 %7)
%9 = load i32, i32* %2
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %23
11: ; preds = %0, %11
%12 = phi i64 [ %19, %11 ], [ 0, %0 ]
%13 = phi i32 [ %18, %11 ], [ -1, %0 ]
%14 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 %12
%15 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %14)
%16 = load i32, i32* %14
%17 = icmp sgt i32 %13, %16
%18 = select i1 %17, i32 %13, i32 %16
%19 = add nuw nsw i64 %12, 1
%20 = load i32, i32* %2
%21 = sext i32 %20 to i64
%22 = icmp slt i64 %19, %21
br i1 %22, label %11, label %23
23: ; preds = %11, %0
%24 = phi i32 [ -1, %0 ], [ %18, %11 ]
%25 = phi i32 [ %9, %0 ], [ %20, %11 ]
%26 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 0
%27 = call i32 @countingSort(i32* %26, i32 %25, i32 %24)
%28 = load i32, i32* %2
%29 = call i32 @printArray(i32* %26, i32 %28)
ret i32 0
}