#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 atoi(char *);
int /*<<< orphan*/ key_index_count(int *, int);
int *malloc(int);
int /*<<< orphan*/ print_list(int *, int);
int /*<<< orphan*/ printf(char *, int, int);
int rand();
int main(int argc, char *argv[]) {
  int i;
  int N = atoi(argv[1]);
  int *a = malloc(N * sizeof(int));
  printf("sorting %d random numbers from 0 to %d:\n", N, 100);
  for (i = 0; i < N; i++)
    a[i] = rand() % (100 - 1);
  print_list(a, N);
  key_index_count(a, N);
  print_list(a, N);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x18(%rbp)
movslq -0x18(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%esi
lea    0xe5d(%rip),%rdi
mov    $0x64,%edx
call   1040 <printf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11e8 <main+0x88>
mov    $0x0,%al
call   1080 <rand@plt>
mov    $0x63,%ecx
cltd
idiv   %ecx
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11b4 <main+0x54>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1030 <print_list@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1050 <key_index_count@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1030 <print_list@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    0x8(%rsi),%rdi
call   1070 <atoi@plt>
mov    %eax,%r14d
lea    0x0(,%r14,4),%edi
call   1060 <malloc@plt>
mov    %rax,%r15
lea    0xe75(%rip),%rdi
mov    %r14d,%esi
mov    $0x64,%edx
call   1040 <printf@plt>
test   %r14d,%r14d
jle    11e2 <main+0x82>
mov    %r14d,%r12d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %eax,%eax
call   1080 <rand@plt>
cltq
imul   $0xffffffffa57eb503,%rax,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
sar    $0x6,%ecx
add    %edx,%ecx
imul   $0x63,%ecx,%ecx
sub    %ecx,%eax
mov    %eax,(%r15,%rbx,4)
add    $0x1,%rbx
cmp    %rbx,%r12
jne    11b0 <main+0x50>
mov    %r15,%rdi
mov    %r14d,%esi
call   1030 <print_list@plt>
mov    %r15,%rdi
mov    %r14d,%esi
call   1050 <key_index_count@plt>
mov    %r15,%rdi
mov    %r14d,%esi
call   1030 <print_list@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [41 x i8] c"sorting %d random numbers from 0 to %d:\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i8**, i8*** %5
%10 = getelementptr inbounds i8*, i8** %9, i64 1
%11 = load i8*, i8** %10
%12 = call i32 @atoi(i8* %11)
store i32 %12, i32* %7
%13 = load i32, i32* %7
%14 = sext i32 %13 to i64
%15 = mul i64 %14, 4
%16 = trunc i64 %15 to i32
%17 = call i32* @malloc(i32 %16)
store i32* %17, i32** %8
%18 = load i32, i32* %7
%19 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %18, i32 100)
store i32 0, i32* %6
br label %20
20: ; preds = %31, %2
%21 = load i32, i32* %6
%22 = load i32, i32* %7
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %34
24: ; preds = %20
%25 = call i32 (...) @rand()
%26 = srem i32 %25, 99
%27 = load i32*, i32** %8
%28 = load i32, i32* %6
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i32, i32* %27, i64 %29
store i32 %26, i32* %30
br label %31
31: ; preds = %24
%32 = load i32, i32* %6
%33 = add nsw i32 %32, 1
store i32 %33, i32* %6
br label %20
34: ; preds = %20
%35 = load i32*, i32** %8
%36 = load i32, i32* %7
%37 = call i32 @print_list(i32* %35, i32 %36)
%38 = load i32*, i32** %8
%39 = load i32, i32* %7
%40 = call i32 @key_index_count(i32* %38, i32 %39)
%41 = load i32*, i32** %8
%42 = load i32, i32* %7
%43 = call i32 @print_list(i32* %41, i32 %42)
ret i32 0
}

LLVM IR (-O2):
@.str = [41 x i8] c"sorting %d random numbers from 0 to %d:\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 1
%4 = load i8*, i8** %3
%5 = tail call i32 @atoi(i8* %4)
%6 = shl i32 %5, 2
%7 = tail call i32* @malloc(i32 %6)
%8 = tail call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %5, i32 100)
%9 = icmp sgt i32 %5, 0
br i1 %9, label %10, label %19
10: ; preds = %2
%11 = zext i32 %5 to i64
br label %12
12: ; preds = %10, %12
%13 = phi i64 [ 0, %10 ], [ %17, %12 ]
%14 = tail call i32 (...) @rand()
%15 = srem i32 %14, 99
%16 = getelementptr inbounds i32, i32* %7, i64 %13
store i32 %15, i32* %16
%17 = add nuw nsw i64 %13, 1
%18 = icmp eq i64 %17, %11
br i1 %18, label %19, label %12
19: ; preds = %12, %2
%20 = tail call i32 @print_list(i32* %7, i32 %5)
%21 = tail call i32 @key_index_count(i32* %7, i32 %5)
%22 = tail call i32 @print_list(i32* %7, i32 %5)
ret i32 0
}