#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*/ bubbleSort(int *, int);
int /*<<< orphan*/ memcpy(int *, int *, int);
int rand();
int /*<<< orphan*/ srand(int);
int main() {
  srand(1000);
  int mainObject[5000], backupObject[5000];
  for (int i = 0; i < 5000; i++) {
    mainObject[i] = rand() % 4001;
  }
  memcpy(backupObject, mainObject, sizeof(int) * 5000);
  for (int i = 0; i < 300; i++) {
    bubbleSort(mainObject, 5000);
    memcpy(mainObject, backupObject, sizeof(int) * 5000);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x9c60,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x3e8,%edi
call   1040 <srand@plt>
movl   $0x0,-0x9c54(%rbp)
cmpl   $0x1388,-0x9c54(%rbp)
jge    11a7 <main+0x67>
mov    $0x0,%al
call   1060 <rand@plt>
mov    $0xfa1,%ecx
cltd
idiv   %ecx
movslq -0x9c54(%rbp),%rax
mov    %edx,-0x4e30(%rbp,%rax,4)
mov    -0x9c54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x9c54(%rbp)
jmp    1166 <main+0x26>
lea    -0x9c50(%rbp),%rdi
lea    -0x4e30(%rbp),%rsi
mov    $0x4e20,%edx
call   1050 <memcpy@plt>
movl   $0x0,-0x9c58(%rbp)
cmpl   $0x12c,-0x9c58(%rbp)
jge    1216 <main+0xd6>
lea    -0x4e30(%rbp),%rdi
mov    $0x1388,%esi
call   1030 <bubbleSort@plt>
lea    -0x4e30(%rbp),%rdi
lea    -0x9c50(%rbp),%rsi
mov    $0x4e20,%edx
call   1050 <memcpy@plt>
mov    -0x9c58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x9c58(%rbp)
jmp    11c9 <main+0x89>
xor    %eax,%eax
add    $0x9c60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x9c40,%rsp
mov    $0x3e8,%edi
call   1040 <srand@plt>
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1060 <rand@plt>
cltq
imul   $0x418505d3,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x2a,%rcx
add    %edx,%ecx
imul   $0xfa1,%ecx,%ecx
sub    %ecx,%eax
mov    %eax,(%rsp,%rbx,4)
add    $0x1,%rbx
cmp    $0x1388,%rbx
jne    1160 <main+0x20>
lea    0x4e20(%rsp),%r14
mov    %rsp,%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x4e20,%edx
call   1050 <memcpy@plt>
mov    $0x12c,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
mov    $0x1388,%esi
call   1030 <bubbleSort@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x4e20,%edx
call   1050 <memcpy@plt>
add    $0xffffffff,%ebp
jne    11c0 <main+0x80>
xor    %eax,%eax
add    $0x9c40,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @main() {
%1 = alloca i32
%2 = alloca [5000 x i32]
%3 = alloca [5000 x i32]
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32 @srand(i32 1000)
store i32 0, i32* %4
br label %7
7: ; preds = %16, %0
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 5000
br i1 %9, label %10, label %19
10: ; preds = %7
%11 = call i32 (...) @rand()
%12 = srem i32 %11, 4001
%13 = load i32, i32* %4
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [5000 x i32], [5000 x i32]* %2, i64 0, i64 %14
store i32 %12, i32* %15
br label %16
16: ; preds = %10
%17 = load i32, i32* %4
%18 = add nsw i32 %17, 1
store i32 %18, i32* %4
br label %7
19: ; preds = %7
%20 = getelementptr inbounds [5000 x i32], [5000 x i32]* %3, i64 0, i64 0
%21 = getelementptr inbounds [5000 x i32], [5000 x i32]* %2, i64 0, i64 0
%22 = call i32 @memcpy(i32* %20, i32* %21, i32 20000)
store i32 0, i32* %5
br label %23
23: ; preds = %32, %19
%24 = load i32, i32* %5
%25 = icmp slt i32 %24, 300
br i1 %25, label %26, label %35
26: ; preds = %23
%27 = getelementptr inbounds [5000 x i32], [5000 x i32]* %2, i64 0, i64 0
%28 = call i32 @bubbleSort(i32* %27, i32 5000)
%29 = getelementptr inbounds [5000 x i32], [5000 x i32]* %2, i64 0, i64 0
%30 = getelementptr inbounds [5000 x i32], [5000 x i32]* %3, i64 0, i64 0
%31 = call i32 @memcpy(i32* %29, i32* %30, i32 20000)
br label %32
32: ; preds = %26
%33 = load i32, i32* %5
%34 = add nsw i32 %33, 1
store i32 %34, i32* %5
br label %23
35: ; preds = %23
ret i32 0
}

LLVM IR (-O2):
define i32 @main() {
%1 = alloca [5000 x i32]
%2 = alloca [5000 x i32]
%3 = tail call i32 @srand(i32 1000)
%4 = bitcast [5000 x i32]* %1 to i8*
%5 = bitcast [5000 x i32]* %2 to i8*
br label %10
6: ; preds = %10
%7 = getelementptr inbounds [5000 x i32], [5000 x i32]* %2, i64 0, i64 0
%8 = getelementptr inbounds [5000 x i32], [5000 x i32]* %1, i64 0, i64 0
%9 = call i32 @memcpy(i32* %7, i32* %8, i32 20000)
br label %18
10: ; preds = %0, %10
%11 = phi i64 [ 0, %0 ], [ %15, %10 ]
%12 = tail call i32 (...) @rand()
%13 = srem i32 %12, 4001
%14 = getelementptr inbounds [5000 x i32], [5000 x i32]* %1, i64 0, i64 %11
store i32 %13, i32* %14
%15 = add nuw nsw i64 %11, 1
%16 = icmp eq i64 %15, 5000
br i1 %16, label %6, label %10
17: ; preds = %18
ret i32 0
18: ; preds = %6, %18
%19 = phi i32 [ 0, %6 ], [ %22, %18 ]
%20 = call i32 @bubbleSort(i32* %8, i32 5000)
%21 = call i32 @memcpy(i32* %8, i32* %7, i32 20000)
%22 = add nuw nsw i32 %19, 1
%23 = icmp eq i32 %22, 300
br i1 %23, label %17, label %18
}