#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ bubbleSort(int *, int);
int /*<<< orphan*/ cocktailSort(int *, int);
int /*<<< orphan*/ copyArray(int *, int *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintArray(int /*<<< orphan*/ *, int *, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ randomInitialize(int *, int, int, int);
int /*<<< orphan*/ shellSort_1(int *, int);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdout;
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main() {
  int origin[100];
  int arr[100];
  srand(time(NULL));
  randomInitialize(origin, 100, 1, 999);
  printf("Original Array:\n\n");
  fprintArray(stdout, origin, 100);
  copyArray(arr, origin, 100);
  bubbleSort(arr, 100);
  printf("Bubble Sort with swaps counting:\n\n");
  fprintArray(stdout, arr, 100);
  copyArray(arr, origin, 100);
  cocktailSort(arr, 100);
  printf("Cocktail Sort with swaps counting:\n\n");
  fprintArray(stdout, arr, 100);
  copyArray(arr, origin, 100);
  shellSort_1(arr, 100);
  printf("Shellsort with gap sequence 2^k + 1 (1 appended to sequence)\n\n");
  fprintArray(stdout, arr, 100);
  copyArray(arr, origin, 100);
  shellSort_1(arr, 100);
  printf("Shellsort with gap sequence (3^k - 1)/2\n\n");
  fprintArray(stdout, arr, 100);
  FILE *f = fopen("A1.sortedArray", "w");
  if (f == NULL) {
    fprintf(stderr, "Error opening file!\n");
    exit(1);
  }
  fprintArray(f, arr, 100);
  fclose(f);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x340,%rsp
movl   $0x0,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   10a0 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
lea    -0x1a0(%rbp),%rdi
mov    $0x64,%esi
mov    $0x1,%edx
mov    $0x3e7,%ecx
call   10c0 <randomInitialize@plt>
lea    0xdec(%rip),%rdi
call   1040 <printf@plt>
mov    0x2db8(%rip),%rax
mov    (%rax),%rdi
lea    -0x1a0(%rbp),%rsi
mov    $0x64,%edx
call   1070 <fprintArray@plt>
lea    -0x330(%rbp),%rdi
lea    -0x1a0(%rbp),%rsi
mov    $0x64,%edx
call   10f0 <copyArray@plt>
lea    -0x330(%rbp),%rdi
mov    $0x64,%esi
call   1050 <bubbleSort@plt>
lea    0xdae(%rip),%rdi
call   1040 <printf@plt>
mov    0x2d68(%rip),%rax
mov    (%rax),%rdi
lea    -0x330(%rbp),%rsi
mov    $0x64,%edx
call   1070 <fprintArray@plt>
lea    -0x330(%rbp),%rdi
lea    -0x1a0(%rbp),%rsi
mov    $0x64,%edx
call   10f0 <copyArray@plt>
lea    -0x330(%rbp),%rdi
mov    $0x64,%esi
call   1090 <cocktailSort@plt>
lea    0xd81(%rip),%rdi
call   1040 <printf@plt>
mov    0x2d18(%rip),%rax
mov    (%rax),%rdi
lea    -0x330(%rbp),%rsi
mov    $0x64,%edx
call   1070 <fprintArray@plt>
lea    -0x330(%rbp),%rdi
lea    -0x1a0(%rbp),%rsi
mov    $0x64,%edx
call   10f0 <copyArray@plt>
lea    -0x330(%rbp),%rdi
mov    $0x64,%esi
call   10b0 <shellSort_1@plt>
lea    0xd56(%rip),%rdi
call   1040 <printf@plt>
mov    0x2cc8(%rip),%rax
mov    (%rax),%rdi
lea    -0x330(%rbp),%rsi
mov    $0x64,%edx
call   1070 <fprintArray@plt>
lea    -0x330(%rbp),%rdi
lea    -0x1a0(%rbp),%rsi
mov    $0x64,%edx
call   10f0 <copyArray@plt>
lea    -0x330(%rbp),%rdi
mov    $0x64,%esi
call   10b0 <shellSort_1@plt>
lea    0xd45(%rip),%rdi
call   1040 <printf@plt>
mov    0x2c78(%rip),%rax
mov    (%rax),%rdi
lea    -0x330(%rbp),%rsi
mov    $0x64,%edx
call   1070 <fprintArray@plt>
lea    0xd48(%rip),%rdi
lea    0xd50(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x338(%rbp)
cmpq   $0x0,-0x338(%rbp)
jne    13bb <main+0x1eb>
mov    0x2c3d(%rip),%rax
mov    (%rax),%edi
lea    0xd28(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    -0x338(%rbp),%rdi
lea    -0x330(%rbp),%rsi
mov    $0x64,%edx
call   1070 <fprintArray@plt>
mov    -0x338(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x340,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x320,%rsp
xor    %edi,%edi
call   10a0 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
lea    0x190(%rsp),%r14
mov    %r14,%rdi
mov    $0x64,%esi
mov    $0x1,%edx
mov    $0x3e7,%ecx
call   10c0 <randomInitialize@plt>
lea    0xe16(%rip),%rdi
call   1030 <puts@plt>
mov    0x2dbc(%rip),%r15
mov    (%r15),%rdi
mov    %r14,%rsi
mov    $0x64,%edx
call   1070 <fprintArray@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x64,%edx
call   10f0 <copyArray@plt>
mov    %rbx,%rdi
mov    $0x64,%esi
call   1050 <bubbleSort@plt>
lea    0xde4(%rip),%rdi
call   1030 <puts@plt>
mov    (%r15),%rdi
mov    %rbx,%rsi
mov    $0x64,%edx
call   1070 <fprintArray@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x64,%edx
call   10f0 <copyArray@plt>
mov    %rbx,%rdi
mov    $0x64,%esi
call   1090 <cocktailSort@plt>
lea    0xdcd(%rip),%rdi
call   1030 <puts@plt>
mov    (%r15),%rdi
mov    %rbx,%rsi
mov    $0x64,%edx
call   1070 <fprintArray@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x64,%edx
call   10f0 <copyArray@plt>
mov    %rbx,%rdi
mov    $0x64,%esi
call   10b0 <shellSort_1@plt>
lea    0xdb8(%rip),%rdi
call   1030 <puts@plt>
mov    (%r15),%rdi
mov    %rbx,%rsi
mov    $0x64,%edx
call   1070 <fprintArray@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x64,%edx
call   10f0 <copyArray@plt>
mov    %rbx,%rdi
mov    $0x64,%esi
call   10b0 <shellSort_1@plt>
lea    0xdbd(%rip),%rdi
call   1030 <puts@plt>
mov    (%r15),%rdi
mov    %rbx,%rsi
mov    $0x64,%edx
call   1070 <fprintArray@plt>
lea    0xce6(%rip),%rdi
lea    0xcee(%rip),%rsi
call   10d0 <fopen@plt>
test   %rax,%rax
je     1355 <main+0x185>
mov    %rax,%rbx
mov    %rsp,%rsi
mov    %rax,%rdi
mov    $0x64,%edx
call   1070 <fprintArray@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x320,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2c84(%rip),%rax
mov    (%rax),%edi
lea    0xcac(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
@.str = [18 x i8] c"Original Array:\0A\0A\00"
@stdout = global i32* null
@.str.1 = [35 x i8] c"Bubble Sort with swaps counting:\0A\0A\00"
@.str.2 = [37 x i8] c"Cocktail Sort with swaps counting:\0A\0A\00"
@.str.3 = [63 x i8] c"Shellsort with gap sequence 2^k + 1 (1 appended to sequence)\0A\0A\00"
@.str.4 = [42 x i8] c"Shellsort with gap sequence (3^k - 1)/2\0A\0A\00"
@.str.5 = [15 x i8] c"A1.sortedArray\00"
@.str.6 = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.7 = [21 x i8] c"Error opening file!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [100 x i32]
%3 = alloca [100 x i32]
%4 = alloca i32*
store i32 0, i32* %1
%5 = call i32 @time(i32* null)
%6 = call i32 @srand(i32 %5)
%7 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 0
%8 = call i32 @randomInitialize(i32* %7, i32 100, i32 1, i32 999)
%9 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%10 = load i32*, i32** @stdout
%11 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 0
%12 = call i32 @fprintArray(i32* %10, i32* %11, i32 100)
%13 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 0
%14 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 0
%15 = call i32 @copyArray(i32* %13, i32* %14, i32 100)
%16 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 0
%17 = call i32 @bubbleSort(i32* %16, i32 100)
%18 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
%19 = load i32*, i32** @stdout
%20 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 0
%21 = call i32 @fprintArray(i32* %19, i32* %20, i32 100)
%22 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 0
%23 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 0
%24 = call i32 @copyArray(i32* %22, i32* %23, i32 100)
%25 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 0
%26 = call i32 @cocktailSort(i32* %25, i32 100)
%27 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0))
%28 = load i32*, i32** @stdout
%29 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 0
%30 = call i32 @fprintArray(i32* %28, i32* %29, i32 100)
%31 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 0
%32 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 0
%33 = call i32 @copyArray(i32* %31, i32* %32, i32 100)
%34 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 0
%35 = call i32 @shellSort_1(i32* %34, i32 100)
%36 = call i32 @printf(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.3, i64 0, i64 0))
%37 = load i32*, i32** @stdout
%38 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 0
%39 = call i32 @fprintArray(i32* %37, i32* %38, i32 100)
%40 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 0
%41 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 0
%42 = call i32 @copyArray(i32* %40, i32* %41, i32 100)
%43 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 0
%44 = call i32 @shellSort_1(i32* %43, i32 100)
%45 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0))
%46 = load i32*, i32** @stdout
%47 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 0
%48 = call i32 @fprintArray(i32* %46, i32* %47, i32 100)
%49 = call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i32* %49, i32** %4
%50 = load i32*, i32** %4
%51 = icmp eq i32* %50, null
br i1 %51, label %52, label %56
52: ; preds = %0
%53 = load i32, i32* @stderr
%54 = call i32 @fprintf(i32 %53, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.7, i64 0, i64 0))
%55 = call i32 @exit(i32 1)
unreachable
56: ; preds = %0
%57 = load i32*, i32** %4
%58 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 0
%59 = call i32 @fprintArray(i32* %57, i32* %58, i32 100)
%60 = load i32*, i32** %4
%61 = call i32 @fclose(i32* %60)
ret i32 0
}

LLVM IR (-O2):
@stdout = global i32* null
@.str.5 = [15 x i8] c"A1.sortedArray\00"
@.str.6 = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.7 = [21 x i8] c"Error opening file!\0A\00"
@str = [17 x i8] c"Original Array:\0A\00"
@str.8 = [34 x i8] c"Bubble Sort with swaps counting:\0A\00"
@str.9 = [36 x i8] c"Cocktail Sort with swaps counting:\0A\00"
@str.10 = [62 x i8] c"Shellsort with gap sequence 2^k + 1 (1 appended to sequence)\0A\00"
@str.11 = [41 x i8] c"Shellsort with gap sequence (3^k - 1)/2\0A\00"
define i32 @main() {
%1 = alloca [100 x i32]
%2 = alloca [100 x i32]
%3 = bitcast [100 x i32]* %1 to i8*
%4 = bitcast [100 x i32]* %2 to i8*
%5 = tail call i32 @time(i32* null)
%6 = tail call i32 @srand(i32 %5)
%7 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 0
%8 = call i32 @randomInitialize(i32* %7, i32 100, i32 1, i32 999)
%9 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%10 = load i32*, i32** @stdout
%11 = call i32 @fprintArray(i32* %10, i32* %7, i32 100)
%12 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 0
%13 = call i32 @copyArray(i32* %12, i32* %7, i32 100)
%14 = call i32 @bubbleSort(i32* %12, i32 100)
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str.8, i64 0, i64 0))
%16 = load i32*, i32** @stdout
%17 = call i32 @fprintArray(i32* %16, i32* %12, i32 100)
%18 = call i32 @copyArray(i32* %12, i32* %7, i32 100)
%19 = call i32 @cocktailSort(i32* %12, i32 100)
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str.9, i64 0, i64 0))
%21 = load i32*, i32** @stdout
%22 = call i32 @fprintArray(i32* %21, i32* %12, i32 100)
%23 = call i32 @copyArray(i32* %12, i32* %7, i32 100)
%24 = call i32 @shellSort_1(i32* %12, i32 100)
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([62 x i8], [62 x i8]* @str.10, i64 0, i64 0))
%26 = load i32*, i32** @stdout
%27 = call i32 @fprintArray(i32* %26, i32* %12, i32 100)
%28 = call i32 @copyArray(i32* %12, i32* %7, i32 100)
%29 = call i32 @shellSort_1(i32* %12, i32 100)
%30 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str.11, i64 0, i64 0))
%31 = load i32*, i32** @stdout
%32 = call i32 @fprintArray(i32* %31, i32* %12, i32 100)
%33 = call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%34 = icmp eq i32* %33, null
br i1 %34, label %35, label %39
35: ; preds = %0
%36 = load i32, i32* @stderr
%37 = call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.7, i64 0, i64 0))
%38 = call i32 @exit(i32 1)
unreachable
39: ; preds = %0
%40 = call i32 @fprintArray(i32* %33, i32* %12, i32 100)
%41 = call i32 @fclose(i32* %33)
ret i32 0
}