#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*/ getchar();
int /*<<< orphan*/ impBsort(int *, int);
int /*<<< orphan*/ printf(char *, ...);
int rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main() {
  srand(time(NULL));
  int i, myarray[4000], myarray2[4000];
  int n = 4000;
  for (i = 0; i < n; i++) {
    myarray[i] = (rand() % (n * 2)) + 1;
    myarray2[i] = myarray[i];
  }
  printf("N = %d\nArray is:\n", n);
  for (i = 0; i < n; i++) {
    printf("%d ", myarray[i]);
  }
  bubbleSort(myarray, n);
  impBsort(myarray2, n);
  printf("\n\nSorted Array is: \n");
  for (i = 0; i < n; i++) {
    printf("%d ", myarray[i]);
  }
  printf("\n\n[Press Enter to close]");
  getchar();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x7d20,%rsp
movl   $0x0,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1080 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
movl   $0xfa0,-0x7d14(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x7d14(%rbp),%eax
jge    11f7 <main+0x87>
mov    $0x0,%al
call   1090 <rand@plt>
mov    -0x7d14(%rbp),%ecx
shl    $0x1,%ecx
cltd
idiv   %ecx
add    $0x1,%edx
movslq -0x8(%rbp),%rax
mov    %edx,-0x3e90(%rbp,%rax,4)
movslq -0x8(%rbp),%rax
mov    -0x3e90(%rbp,%rax,4),%ecx
movslq -0x8(%rbp),%rax
mov    %ecx,-0x7d10(%rbp,%rax,4)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11a3 <main+0x33>
mov    -0x7d14(%rbp),%esi
lea    0xdfc(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x7d14(%rbp),%eax
jge    1248 <main+0xd8>
movslq -0x8(%rbp),%rax
mov    -0x3e90(%rbp,%rax,4),%esi
lea    0xddf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1212 <main+0xa2>
lea    -0x3e90(%rbp),%rdi
mov    -0x7d14(%rbp),%esi
call   1050 <bubbleSort@plt>
lea    -0x7d10(%rbp),%rdi
mov    -0x7d14(%rbp),%esi
call   1030 <impBsort@plt>
lea    0xda3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x7d14(%rbp),%eax
jge    12b7 <main+0x147>
movslq -0x8(%rbp),%rax
mov    -0x3e90(%rbp,%rax,4),%esi
lea    0xd70(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1281 <main+0x111>
lea    0xd6d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1070 <getchar@plt>
xor    %eax,%eax
add    $0x7d20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x7d08,%rsp
xor    %edi,%edi
call   1090 <time@plt>
mov    %eax,%edi
call   1070 <srand@plt>
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   10a0 <rand@plt>
cltq
imul   $0x10624dd3,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x29,%rcx
add    %edx,%ecx
imul   $0x1f40,%ecx,%ecx
neg    %ecx
add    %ecx,%eax
add    $0x1,%eax
mov    %eax,(%rsp,%rbx,4)
mov    %eax,0x3e80(%rsp,%rbx,4)
add    $0x1,%rbx
cmp    $0xfa0,%rbx
jne    11a0 <main+0x20>
lea    0xe18(%rip),%rdi
mov    $0xfa0,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe17(%rip),%r14
xor    %ebx,%ebx
nopl   (%rax)
mov    (%rsp,%rbx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbx
cmp    $0xfa0,%rbx
jne    1200 <main+0x80>
mov    %rsp,%rdi
mov    $0xfa0,%esi
call   1060 <bubbleSort@plt>
lea    0x3e80(%rsp),%rdi
mov    $0xfa0,%esi
call   1030 <impBsort@plt>
lea    0xdef(%rip),%rdi
call   1040 <puts@plt>
lea    0xdc6(%rip),%r14
xor    %ebx,%ebx
xchg   %ax,%ax
mov    (%rsp,%rbx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbx
cmp    $0xfa0,%rbx
jne    1250 <main+0xd0>
lea    0xda5(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1080 <getchar@plt>
xor    %eax,%eax
add    $0x7d08,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [18 x i8] c"N = %d\0AArray is:\0A\00"
@.str.1 = [4 x i8] c"%d \00"
@.str.2 = [21 x i8] c"\0A\0ASorted Array is: \0A\00"
@.str.3 = [25 x i8] c"\0A\0A[Press Enter to close]\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [4000 x i32]
%4 = alloca [4000 x i32]
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32 @time(i32* null)
%7 = call i32 @srand(i32 %6)
store i32 4000, i32* %5
store i32 0, i32* %2
br label %8
8: ; preds = %28, %0
%9 = load i32, i32* %2
%10 = load i32, i32* %5
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %31
12: ; preds = %8
%13 = call i32 (...) @rand()
%14 = load i32, i32* %5
%15 = mul nsw i32 %14, 2
%16 = srem i32 %13, %15
%17 = add nsw i32 %16, 1
%18 = load i32, i32* %2
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [4000 x i32], [4000 x i32]* %3, i64 0, i64 %19
store i32 %17, i32* %20
%21 = load i32, i32* %2
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [4000 x i32], [4000 x i32]* %3, i64 0, i64 %22
%24 = load i32, i32* %23
%25 = load i32, i32* %2
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [4000 x i32], [4000 x i32]* %4, i64 0, i64 %26
store i32 %24, i32* %27
br label %28
28: ; preds = %12
%29 = load i32, i32* %2
%30 = add nsw i32 %29, 1
store i32 %30, i32* %2
br label %8
31: ; preds = %8
%32 = load i32, i32* %5
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %32)
store i32 0, i32* %2
br label %34
34: ; preds = %44, %31
%35 = load i32, i32* %2
%36 = load i32, i32* %5
%37 = icmp slt i32 %35, %36
br i1 %37, label %38, label %47
38: ; preds = %34
%39 = load i32, i32* %2
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [4000 x i32], [4000 x i32]* %3, i64 0, i64 %40
%42 = load i32, i32* %41
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %42)
br label %44
44: ; preds = %38
%45 = load i32, i32* %2
%46 = add nsw i32 %45, 1
store i32 %46, i32* %2
br label %34
47: ; preds = %34
%48 = getelementptr inbounds [4000 x i32], [4000 x i32]* %3, i64 0, i64 0
%49 = load i32, i32* %5
%50 = call i32 @bubbleSort(i32* %48, i32 %49)
%51 = getelementptr inbounds [4000 x i32], [4000 x i32]* %4, i64 0, i64 0
%52 = load i32, i32* %5
%53 = call i32 @impBsort(i32* %51, i32 %52)
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %2
br label %55
55: ; preds = %65, %47
%56 = load i32, i32* %2
%57 = load i32, i32* %5
%58 = icmp slt i32 %56, %57
br i1 %58, label %59, label %68
59: ; preds = %55
%60 = load i32, i32* %2
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds [4000 x i32], [4000 x i32]* %3, i64 0, i64 %61
%63 = load i32, i32* %62
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %63)
br label %65
65: ; preds = %59
%66 = load i32, i32* %2
%67 = add nsw i32 %66, 1
store i32 %67, i32* %2
br label %55
68: ; preds = %55
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
%70 = call i32 (...) @getchar()
ret i32 0
}

LLVM IR (-O2):
@.str = [18 x i8] c"N = %d\0AArray is:\0A\00"
@.str.1 = [4 x i8] c"%d \00"
@.str.3 = [25 x i8] c"\0A\0A[Press Enter to close]\00"
@str = [20 x i8] c"\0A\0ASorted Array is: \00"
define i32 @main() {
%1 = alloca [4000 x i32]
%2 = alloca [4000 x i32]
%3 = tail call i32 @time(i32* null)
%4 = tail call i32 @srand(i32 %3)
%5 = bitcast [4000 x i32]* %1 to i8*
%6 = bitcast [4000 x i32]* %2 to i8*
br label %7
7: ; preds = %0, %7
%8 = phi i64 [ 0, %0 ], [ %14, %7 ]
%9 = tail call i32 (...) @rand()
%10 = srem i32 %9, 8000
%11 = add nsw i32 %10, 1
%12 = getelementptr inbounds [4000 x i32], [4000 x i32]* %1, i64 0, i64 %8
store i32 %11, i32* %12
%13 = getelementptr inbounds [4000 x i32], [4000 x i32]* %2, i64 0, i64 %8
store i32 %11, i32* %13
%14 = add nuw nsw i64 %8, 1
%15 = icmp eq i64 %14, 4000
br i1 %15, label %16, label %7
16: ; preds = %7
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 4000)
br label %18
18: ; preds = %16, %18
%19 = phi i64 [ 0, %16 ], [ %23, %18 ]
%20 = getelementptr inbounds [4000 x i32], [4000 x i32]* %1, i64 0, i64 %19
%21 = load i32, i32* %20
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %21)
%23 = add nuw nsw i64 %19, 1
%24 = icmp eq i64 %23, 4000
br i1 %24, label %25, label %18
25: ; preds = %18
%26 = getelementptr inbounds [4000 x i32], [4000 x i32]* %1, i64 0, i64 0
%27 = call i32 @bubbleSort(i32* %26, i32 4000)
%28 = getelementptr inbounds [4000 x i32], [4000 x i32]* %2, i64 0, i64 0
%29 = call i32 @impBsort(i32* %28, i32 4000)
%30 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
br label %31
31: ; preds = %25, %31
%32 = phi i64 [ 0, %25 ], [ %36, %31 ]
%33 = getelementptr inbounds [4000 x i32], [4000 x i32]* %1, i64 0, i64 %32
%34 = load i32, i32* %33
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %34)
%36 = add nuw nsw i64 %32, 1
%37 = icmp eq i64 %36, 4000
br i1 %37, label %38, label %31
38: ; preds = %31
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
%40 = call i32 (...) @getchar()
ret i32 0
}