#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*/ bubble_sort(int *, int);
int /*<<< orphan*/ printf(char *, int);
int rand();
void sort_array() {
  printf("Bubble sorting array of %d elements\n", 30000);
  int data[30000], i;
  for (i = 0; i < 30000; ++i) {
    data[i] = rand();
  }
  bubble_sort(data, 30000);
}


x86 assembly (clang, -O0):
<sort_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1d4d0,%rsp
lea    0xebe(%rip),%rdi
mov    $0x7530,%esi
call   1030 <printf@plt>
movl   $0x0,-0x1d4c4(%rbp)
cmpl   $0x7530,-0x1d4c4(%rbp)
jge    1191 <sort_array+0x61>
mov    $0x0,%al
call   1040 <rand@plt>
mov    %eax,%ecx
movslq -0x1d4c4(%rbp),%rax
mov    %ecx,-0x1d4c0(%rbp,%rax,4)
mov    -0x1d4c4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1d4c4(%rbp)
jmp    1156 <sort_array+0x26>
lea    -0x1d4c0(%rbp),%rdi
mov    $0x7530,%esi
call   1050 <bubble_sort@plt>
add    $0x1d4d0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sort_array>:
push   %rbx
sub    $0x1d4c0,%rsp
lea    0xec1(%rip),%rdi
mov    $0x7530,%esi
call   1030 <printf@plt>
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1040 <rand@plt>
mov    %eax,(%rsp,%rbx,4)
add    $0x1,%rbx
cmp    $0x7530,%rbx
jne    1150 <sort_array+0x20>
mov    %rsp,%rdi
mov    $0x7530,%esi
call   1050 <bubble_sort@plt>
add    $0x1d4c0,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [37 x i8] c"Bubble sorting array of %d elements\0A\00"
define void @sort_array() {
%1 = alloca [30000 x i32]
%2 = alloca i32
%3 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 30000)
store i32 0, i32* %2
br label %4
4: ; preds = %12, %0
%5 = load i32, i32* %2
%6 = icmp slt i32 %5, 30000
br i1 %6, label %7, label %15
7: ; preds = %4
%8 = call i32 (...) @rand()
%9 = load i32, i32* %2
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds [30000 x i32], [30000 x i32]* %1, i64 0, i64 %10
store i32 %8, i32* %11
br label %12
12: ; preds = %7
%13 = load i32, i32* %2
%14 = add nsw i32 %13, 1
store i32 %14, i32* %2
br label %4
15: ; preds = %4
%16 = getelementptr inbounds [30000 x i32], [30000 x i32]* %1, i64 0, i64 0
%17 = call i32 @bubble_sort(i32* %16, i32 30000)
ret void
}

LLVM IR (-O2):
@.str = [37 x i8] c"Bubble sorting array of %d elements\0A\00"
define void @sort_array() {
%1 = alloca [30000 x i32]
%2 = tail call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 30000)
%3 = bitcast [30000 x i32]* %1 to i8*
br label %4
4: ; preds = %0, %4
%5 = phi i64 [ 0, %0 ], [ %8, %4 ]
%6 = tail call i32 (...) @rand()
%7 = getelementptr inbounds [30000 x i32], [30000 x i32]* %1, i64 0, i64 %5
store i32 %6, i32* %7
%8 = add nuw nsw i64 %5, 1
%9 = icmp eq i64 %8, 30000
br i1 %9, label %10, label %4
10: ; preds = %4
%11 = getelementptr inbounds [30000 x i32], [30000 x i32]* %1, i64 0, i64 0
%12 = call i32 @bubble_sort(i32* %11, i32 30000)
ret void
}