#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*/ getchar();
int /*<<< orphan*/ improved_bubblesort(int *, int);
int /*<<< orphan*/ printf(char *);
int rand();
main() {
  printf("============================");
  printf("\nImproved Bubble Sort Results\n");
  printf("============================");
  int i, j;
  int array1[800];
  int array2[1600];
  int array3[2400];
  int array4[3200];
  int array5[4000];
  for (i = 0; i < 800; i++) {
    array1[i] = rand() % (2 * 800);
  }
  for (i = 0; i < 1600; i++) {
    array2[i] = rand() % (2 * 1600);
  }
  for (i = 0; i < 2400; i++) {
    array3[i] = rand() % (2 * 2400);
  }
  for (i = 0; i < 3200; i++) {
    array4[i] = rand() % (2 * 3200);
  }
  for (i = 0; i < 4000; i++) {
    array5[i] = rand() % (2 * 4000);
  }
  for (j = 1; j < 6; j++) {
    switch (j) {
    case 1: {
      improved_bubblesort(array1, 800);
      break;
    }
    case 2: {
      improved_bubblesort(array2, 1600);
      break;
    }
    case 3: {
      improved_bubblesort(array3, 2400);
      break;
    }
    case 4: {
      improved_bubblesort(array4, 3200);
      break;
    }
    case 5: {
      improved_bubblesort(array5, 4000);
      break;
    }
    }
  }
  getchar();
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xbba0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xebb(%rip),%rdi
call   1030 <printf@plt>
lea    0xecc(%rip),%rdi
call   1030 <printf@plt>
lea    0xea3(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0x320,-0x8(%rbp)
jge    11b2 <main+0x72>
mov    $0x0,%al
call   1060 <rand@plt>
mov    $0x640,%ecx
cltd
idiv   %ecx
movslq -0x8(%rbp),%rax
mov    %edx,-0xc90(%rbp,%rax,4)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    117d <main+0x3d>
movl   $0x0,-0x8(%rbp)
cmpl   $0x640,-0x8(%rbp)
jge    11ee <main+0xae>
mov    $0x0,%al
call   1060 <rand@plt>
mov    $0xc80,%ecx
cltd
idiv   %ecx
movslq -0x8(%rbp),%rax
mov    %edx,-0x2590(%rbp,%rax,4)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11b9 <main+0x79>
movl   $0x0,-0x8(%rbp)
cmpl   $0x960,-0x8(%rbp)
jge    122a <main+0xea>
mov    $0x0,%al
call   1060 <rand@plt>
mov    $0x12c0,%ecx
cltd
idiv   %ecx
movslq -0x8(%rbp),%rax
mov    %edx,-0x4b10(%rbp,%rax,4)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11f5 <main+0xb5>
movl   $0x0,-0x8(%rbp)
cmpl   $0xc80,-0x8(%rbp)
jge    1266 <main+0x126>
mov    $0x0,%al
call   1060 <rand@plt>
mov    $0x1900,%ecx
cltd
idiv   %ecx
movslq -0x8(%rbp),%rax
mov    %edx,-0x7d10(%rbp,%rax,4)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1231 <main+0xf1>
movl   $0x0,-0x8(%rbp)
cmpl   $0xfa0,-0x8(%rbp)
jge    12a2 <main+0x162>
mov    $0x0,%al
call   1060 <rand@plt>
mov    $0x1f40,%ecx
cltd
idiv   %ecx
movslq -0x8(%rbp),%rax
mov    %edx,-0xbb90(%rbp,%rax,4)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    126d <main+0x12d>
movl   $0x1,-0xc(%rbp)
cmpl   $0x6,-0xc(%rbp)
jge    135e <main+0x21e>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0xbb98(%rbp)
sub    $0x4,%eax
ja     134b <main+0x20b>
mov    -0xbb98(%rbp),%rax
lea    0xd27(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    -0xc90(%rbp),%rdi
mov    $0x320,%esi
call   1050 <improved_bubblesort@plt>
jmp    134b <main+0x20b>
lea    -0x2590(%rbp),%rdi
mov    $0x640,%esi
call   1050 <improved_bubblesort@plt>
jmp    134b <main+0x20b>
lea    -0x4b10(%rbp),%rdi
mov    $0x960,%esi
call   1050 <improved_bubblesort@plt>
jmp    134b <main+0x20b>
lea    -0x7d10(%rbp),%rdi
mov    $0xc80,%esi
call   1050 <improved_bubblesort@plt>
jmp    134b <main+0x20b>
lea    -0xbb90(%rbp),%rdi
mov    $0xfa0,%esi
call   1050 <improved_bubblesort@plt>
jmp    1350 <main+0x210>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    12a9 <main+0x169>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    -0x4(%rbp),%eax
add    $0xbba0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0xbb80,%rsp
lea    0xea1(%rip),%rbx
mov    %rbx,%rdi
call   1040 <printf@plt>
lea    0xeaf(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1040 <printf@plt>
xor    %ebx,%ebx
nopl   (%rax)
xor    %eax,%eax
call   1070 <rand@plt>
cltq
imul   $0x51eb851f,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x29,%rcx
add    %edx,%ecx
imul   $0x640,%ecx,%ecx
sub    %ecx,%eax
mov    %eax,(%rsp,%rbx,4)
add    $0x1,%rbx
cmp    $0x320,%rbx
jne    1180 <main+0x30>
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1070 <rand@plt>
cltq
imul   $0x51eb851f,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x2a,%rcx
add    %edx,%ecx
imul   $0xc80,%ecx,%ecx
sub    %ecx,%eax
mov    %eax,0xc80(%rsp,%rbx,4)
add    $0x1,%rbx
cmp    $0x640,%rbx
jne    11c0 <main+0x70>
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1070 <rand@plt>
cltq
imul   $0x1b4e81b5,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x29,%rcx
add    %edx,%ecx
imul   $0x12c0,%ecx,%ecx
sub    %ecx,%eax
mov    %eax,0x2580(%rsp,%rbx,4)
add    $0x1,%rbx
cmp    $0x960,%rbx
jne    1200 <main+0xb0>
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1070 <rand@plt>
cltq
imul   $0x51eb851f,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x2b,%rcx
add    %edx,%ecx
imul   $0x1900,%ecx,%ecx
sub    %ecx,%eax
mov    %eax,0x4b00(%rsp,%rbx,4)
add    $0x1,%rbx
cmp    $0xc80,%rbx
jne    1240 <main+0xf0>
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1070 <rand@plt>
cltq
imul   $0x10624dd3,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x29,%rcx
add    %edx,%ecx
imul   $0x1f40,%ecx,%ecx
sub    %ecx,%eax
mov    %eax,0x7d00(%rsp,%rbx,4)
add    $0x1,%rbx
cmp    $0xfa0,%rbx
jne    1280 <main+0x130>
mov    %rsp,%rdi
mov    $0x320,%esi
call   1060 <improved_bubblesort@plt>
lea    0xc80(%rsp),%rdi
mov    $0x640,%esi
call   1060 <improved_bubblesort@plt>
lea    0x2580(%rsp),%rdi
mov    $0x960,%esi
call   1060 <improved_bubblesort@plt>
lea    0x4b00(%rsp),%rdi
mov    $0xc80,%esi
call   1060 <improved_bubblesort@plt>
lea    0x7d00(%rsp),%rdi
mov    $0xfa0,%esi
call   1060 <improved_bubblesort@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
xor    %eax,%eax
add    $0xbb80,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [29 x i8] c"============================\00"
@.str.1 = [31 x i8] c"\0AImproved Bubble Sort Results\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [800 x i32]
%5 = alloca [1600 x i32]
%6 = alloca [2400 x i32]
%7 = alloca [3200 x i32]
%8 = alloca [4000 x i32]
store i32 0, i32* %1
%9 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %2
br label %12
12: ; preds = %21, %0
%13 = load i32, i32* %2
%14 = icmp slt i32 %13, 800
br i1 %14, label %15, label %24
15: ; preds = %12
%16 = call i32 (...) @rand()
%17 = srem i32 %16, 1600
%18 = load i32, i32* %2
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [800 x i32], [800 x i32]* %4, i64 0, i64 %19
store i32 %17, i32* %20
br label %21
21: ; preds = %15
%22 = load i32, i32* %2
%23 = add nsw i32 %22, 1
store i32 %23, i32* %2
br label %12
24: ; preds = %12
store i32 0, i32* %2
br label %25
25: ; preds = %34, %24
%26 = load i32, i32* %2
%27 = icmp slt i32 %26, 1600
br i1 %27, label %28, label %37
28: ; preds = %25
%29 = call i32 (...) @rand()
%30 = srem i32 %29, 3200
%31 = load i32, i32* %2
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [1600 x i32], [1600 x i32]* %5, i64 0, i64 %32
store i32 %30, i32* %33
br label %34
34: ; preds = %28
%35 = load i32, i32* %2
%36 = add nsw i32 %35, 1
store i32 %36, i32* %2
br label %25
37: ; preds = %25
store i32 0, i32* %2
br label %38
38: ; preds = %47, %37
%39 = load i32, i32* %2
%40 = icmp slt i32 %39, 2400
br i1 %40, label %41, label %50
41: ; preds = %38
%42 = call i32 (...) @rand()
%43 = srem i32 %42, 4800
%44 = load i32, i32* %2
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [2400 x i32], [2400 x i32]* %6, i64 0, i64 %45
store i32 %43, i32* %46
br label %47
47: ; preds = %41
%48 = load i32, i32* %2
%49 = add nsw i32 %48, 1
store i32 %49, i32* %2
br label %38
50: ; preds = %38
store i32 0, i32* %2
br label %51
51: ; preds = %60, %50
%52 = load i32, i32* %2
%53 = icmp slt i32 %52, 3200
br i1 %53, label %54, label %63
54: ; preds = %51
%55 = call i32 (...) @rand()
%56 = srem i32 %55, 6400
%57 = load i32, i32* %2
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds [3200 x i32], [3200 x i32]* %7, i64 0, i64 %58
store i32 %56, i32* %59
br label %60
60: ; preds = %54
%61 = load i32, i32* %2
%62 = add nsw i32 %61, 1
store i32 %62, i32* %2
br label %51
63: ; preds = %51
store i32 0, i32* %2
br label %64
64: ; preds = %73, %63
%65 = load i32, i32* %2
%66 = icmp slt i32 %65, 4000
br i1 %66, label %67, label %76
67: ; preds = %64
%68 = call i32 (...) @rand()
%69 = srem i32 %68, 8000
%70 = load i32, i32* %2
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds [4000 x i32], [4000 x i32]* %8, i64 0, i64 %71
store i32 %69, i32* %72
br label %73
73: ; preds = %67
%74 = load i32, i32* %2
%75 = add nsw i32 %74, 1
store i32 %75, i32* %2
br label %64
76: ; preds = %64
store i32 1, i32* %3
br label %77
77: ; preds = %98, %76
%78 = load i32, i32* %3
%79 = icmp slt i32 %78, 6
br i1 %79, label %80, label %101
80: ; preds = %77
%81 = load i32, i32* %3
switch i32 %81, label %97 [
i32 1, label %82
i32 2, label %85
i32 3, label %88
i32 4, label %91
i32 5, label %94
]
82: ; preds = %80
%83 = getelementptr inbounds [800 x i32], [800 x i32]* %4, i64 0, i64 0
%84 = call i32 @improved_bubblesort(i32* %83, i32 800)
br label %97
85: ; preds = %80
%86 = getelementptr inbounds [1600 x i32], [1600 x i32]* %5, i64 0, i64 0
%87 = call i32 @improved_bubblesort(i32* %86, i32 1600)
br label %97
88: ; preds = %80
%89 = getelementptr inbounds [2400 x i32], [2400 x i32]* %6, i64 0, i64 0
%90 = call i32 @improved_bubblesort(i32* %89, i32 2400)
br label %97
91: ; preds = %80
%92 = getelementptr inbounds [3200 x i32], [3200 x i32]* %7, i64 0, i64 0
%93 = call i32 @improved_bubblesort(i32* %92, i32 3200)
br label %97
94: ; preds = %80
%95 = getelementptr inbounds [4000 x i32], [4000 x i32]* %8, i64 0, i64 0
%96 = call i32 @improved_bubblesort(i32* %95, i32 4000)
br label %97
97: ; preds = %80, %94, %91, %88, %85, %82
br label %98
98: ; preds = %97
%99 = load i32, i32* %3
%100 = add nsw i32 %99, 1
store i32 %100, i32* %3
br label %77
101: ; preds = %77
%102 = call i32 (...) @getchar()
%103 = load i32, i32* %1
ret i32 %103
}

LLVM IR (-O2):
@.str = [29 x i8] c"============================\00"
@str = [30 x i8] c"\0AImproved Bubble Sort Results\00"
define i32 @main() {
%1 = alloca [800 x i32]
%2 = alloca [1600 x i32]
%3 = alloca [2400 x i32]
%4 = alloca [3200 x i32]
%5 = alloca [4000 x i32]
%6 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str, i64 0, i64 0))
%8 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%9 = bitcast [800 x i32]* %1 to i8*
%10 = bitcast [1600 x i32]* %2 to i8*
%11 = bitcast [2400 x i32]* %3 to i8*
%12 = bitcast [3200 x i32]* %4 to i8*
%13 = bitcast [4000 x i32]* %5 to i8*
br label %14
14: ; preds = %0, %14
%15 = phi i64 [ 0, %0 ], [ %19, %14 ]
%16 = tail call i32 (...) @rand()
%17 = srem i32 %16, 1600
%18 = getelementptr inbounds [800 x i32], [800 x i32]* %1, i64 0, i64 %15
store i32 %17, i32* %18
%19 = add nuw nsw i64 %15, 1
%20 = icmp eq i64 %19, 800
br i1 %20, label %21, label %14
21: ; preds = %14, %21
%22 = phi i64 [ %26, %21 ], [ 0, %14 ]
%23 = tail call i32 (...) @rand()
%24 = srem i32 %23, 3200
%25 = getelementptr inbounds [1600 x i32], [1600 x i32]* %2, i64 0, i64 %22
store i32 %24, i32* %25
%26 = add nuw nsw i64 %22, 1
%27 = icmp eq i64 %26, 1600
br i1 %27, label %28, label %21
28: ; preds = %21, %28
%29 = phi i64 [ %33, %28 ], [ 0, %21 ]
%30 = tail call i32 (...) @rand()
%31 = srem i32 %30, 4800
%32 = getelementptr inbounds [2400 x i32], [2400 x i32]* %3, i64 0, i64 %29
store i32 %31, i32* %32
%33 = add nuw nsw i64 %29, 1
%34 = icmp eq i64 %33, 2400
br i1 %34, label %35, label %28
35: ; preds = %28, %35
%36 = phi i64 [ %40, %35 ], [ 0, %28 ]
%37 = tail call i32 (...) @rand()
%38 = srem i32 %37, 6400
%39 = getelementptr inbounds [3200 x i32], [3200 x i32]* %4, i64 0, i64 %36
store i32 %38, i32* %39
%40 = add nuw nsw i64 %36, 1
%41 = icmp eq i64 %40, 3200
br i1 %41, label %42, label %35
42: ; preds = %35, %42
%43 = phi i64 [ %47, %42 ], [ 0, %35 ]
%44 = tail call i32 (...) @rand()
%45 = srem i32 %44, 8000
%46 = getelementptr inbounds [4000 x i32], [4000 x i32]* %5, i64 0, i64 %43
store i32 %45, i32* %46
%47 = add nuw nsw i64 %43, 1
%48 = icmp eq i64 %47, 4000
br i1 %48, label %49, label %42
49: ; preds = %42
%50 = getelementptr inbounds [4000 x i32], [4000 x i32]* %5, i64 0, i64 0
%51 = getelementptr inbounds [3200 x i32], [3200 x i32]* %4, i64 0, i64 0
%52 = getelementptr inbounds [2400 x i32], [2400 x i32]* %3, i64 0, i64 0
%53 = getelementptr inbounds [1600 x i32], [1600 x i32]* %2, i64 0, i64 0
%54 = getelementptr inbounds [800 x i32], [800 x i32]* %1, i64 0, i64 0
%55 = call i32 @improved_bubblesort(i32* %54, i32 800)
%56 = call i32 @improved_bubblesort(i32* %53, i32 1600)
%57 = call i32 @improved_bubblesort(i32* %52, i32 2400)
%58 = call i32 @improved_bubblesort(i32* %51, i32 3200)
%59 = call i32 @improved_bubblesort(i32* %50, i32 4000)
%60 = call i32 (...) @getchar()
ret i32 0
}