#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 cocktailSortArray(int, int *);
int /*<<< orphan*/ getRandomArray(int, int *);
int /*<<< orphan*/ printArray(int, int *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ puts(char *);
int main() {
  int a[100];
  int count;
  getRandomArray(100, a);
  puts("Array before sort:");
  printArray(100, a);
  count = cocktailSortArray(100, a);
  puts("Array after sort:");
  printArray(100, a);
  printf("Number of comparisons is %d", count);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1b0,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x1a0(%rbp),%rsi
mov    $0x64,%edi
call   1050 <getRandomArray@plt>
lea    0xe86(%rip),%rdi
call   1030 <puts@plt>
lea    -0x1a0(%rbp),%rsi
mov    $0x64,%edi
call   1070 <printArray@plt>
lea    -0x1a0(%rbp),%rsi
mov    $0x64,%edi
call   1060 <cocktailSortArray@plt>
mov    %eax,-0x1a4(%rbp)
lea    0xe65(%rip),%rdi
call   1030 <puts@plt>
lea    -0x1a0(%rbp),%rsi
mov    $0x64,%edi
call   1070 <printArray@plt>
mov    -0x1a4(%rbp),%esi
lea    0xe54(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x1b0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x198,%rsp
mov    %rsp,%rbx
mov    $0x64,%edi
mov    %rbx,%rsi
call   1050 <getRandomArray@plt>
lea    0xe90(%rip),%rdi
call   1030 <puts@plt>
mov    $0x64,%edi
mov    %rbx,%rsi
call   1070 <printArray@plt>
mov    $0x64,%edi
mov    %rbx,%rsi
call   1060 <cocktailSortArray@plt>
mov    %eax,%ebp
lea    0xe7b(%rip),%rdi
call   1030 <puts@plt>
mov    $0x64,%edi
mov    %rbx,%rsi
call   1070 <printArray@plt>
lea    0xe74(%rip),%rdi
mov    %ebp,%esi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x198,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [19 x i8] c"Array before sort:\00"
@.str.1 = [18 x i8] c"Array after sort:\00"
@.str.2 = [28 x i8] c"Number of comparisons is %d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [100 x i32]
%3 = alloca i32
store i32 0, i32* %1
%4 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 0
%5 = call i32 @getRandomArray(i32 100, i32* %4)
%6 = call i32 @puts(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%7 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 0
%8 = call i32 @printArray(i32 100, i32* %7)
%9 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 0
%10 = call i32 @cocktailSortArray(i32 100, i32* %9)
store i32 %10, i32* %3
%11 = call i32 @puts(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%12 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 0
%13 = call i32 @printArray(i32 100, i32* %12)
%14 = load i32, i32* %3
%15 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 %14)
ret i32 0
}

LLVM IR (-O2):
@.str = [19 x i8] c"Array before sort:\00"
@.str.1 = [18 x i8] c"Array after sort:\00"
@.str.2 = [28 x i8] c"Number of comparisons is %d\00"
define i32 @main() {
%1 = alloca [100 x i32]
%2 = bitcast [100 x i32]* %1 to i8*
%3 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 0
%4 = call i32 @getRandomArray(i32 100, i32* %3)
%5 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @printArray(i32 100, i32* %3)
%7 = call i32 @cocktailSortArray(i32 100, i32* %3)
%8 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%9 = call i32 @printArray(i32 100, i32* %3)
%10 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 %7)
ret i32 0
}