#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*/ bubble_sort(int *, int /*<<< orphan*/, 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;
  print_list(a, N);
  bubble_sort(a, 0, N - 1);
  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   1060 <atoi@plt>
mov    %eax,-0x18(%rbp)
movslq -0x18(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <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   1070 <rand@plt>
mov    $0x64,%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),%edx
sub    $0x1,%edx
xor    %esi,%esi
call   1080 <bubble_sort@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   1060 <atoi@plt>
mov    %eax,%r14d
lea    0x0(,%r14,4),%edi
call   1050 <malloc@plt>
mov    %rax,%r15
lea    0xe75(%rip),%rdi
mov    %r14d,%esi
mov    $0x64,%edx
call   1040 <printf@plt>
test   %r14d,%r14d
jle    11df <main+0x7f>
mov    %r14d,%r12d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %eax,%eax
call   1070 <rand@plt>
cltq
imul   $0x51eb851f,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x25,%rcx
add    %edx,%ecx
imul   $0x64,%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    %r14d,%edx
add    $0xffffffff,%edx
mov    %r15,%rdi
xor    %esi,%esi
call   1080 <bubble_sort@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, 100
%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 = sub nsw i32 %39, 1
%41 = call i32 @bubble_sort(i32* %38, i32 0, i32 %40)
%42 = load i32*, i32** %8
%43 = load i32, i32* %7
%44 = call i32 @print_list(i32* %42, i32 %43)
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, 100
%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 = add nsw i32 %5, -1
%22 = tail call i32 @bubble_sort(i32* %7, i32 0, i32 %21)
%23 = tail call i32 @print_list(i32* %7, i32 %5)
ret i32 0
}