#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*/ bubbleSortAscending(int *, int);
int /*<<< orphan*/ bubbleSortDescending(int *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ putchar(char);
int main(int argc, char *argv[]) {
  int testArray[] = {2, 6, 5, 3, 7, 8, 1, 4};
  if (argc == 1)
    bubbleSortAscending(testArray, 8);
  else if (argc == 2) {
    if (argv[1][0] == '-') {
      if (argv[1][1] == 'a')
        bubbleSortAscending(testArray, 8);
      else if (argv[1][1] == 'd')
        bubbleSortDescending(testArray, 8);
      else {
        printf("Usage: sortArray [ -d | -a ]\n");
        exit(1);
      }
    } else {
      printf("Usage: sortArray [ -d | -a ]\n");
      exit(1);
    }
  } else {
    printf("Usage: sortArray [ -d | -a ]\n");
    exit(1);
  }
  int i;
  for (i = 0; i < 8; i++)
    printf("%d ", testArray[i]);
  putchar('\n');
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xe93(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xe90(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xe8d(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xe8a(%rip),%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    11af <main+0x5f>
lea    -0x30(%rbp),%rdi
mov    $0x8,%esi
call   1040 <bubbleSortAscending@plt>
jmp    1279 <main+0x129>
cmpl   $0x2,-0x8(%rbp)
jne    125c <main+0x10c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    123f <main+0xef>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl 0x1(%rax),%eax
cmp    $0x61,%eax
jne    11f5 <main+0xa5>
lea    -0x30(%rbp),%rdi
mov    $0x8,%esi
call   1040 <bubbleSortAscending@plt>
jmp    123a <main+0xea>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl 0x1(%rax),%eax
cmp    $0x64,%eax
jne    121d <main+0xcd>
lea    -0x30(%rbp),%rdi
mov    $0x8,%esi
call   1070 <bubbleSortDescending@plt>
jmp    1235 <main+0xe5>
lea    0xdfc(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
jmp    123a <main+0xea>
jmp    1257 <main+0x107>
lea    0xdda(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
jmp    1274 <main+0x124>
lea    0xdbd(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
jmp    1279 <main+0x129>
movl   $0x0,-0x34(%rbp)
cmpl   $0x8,-0x34(%rbp)
jge    12ae <main+0x15e>
movslq -0x34(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%esi
lea    0xda5(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1280 <main+0x130>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
movaps 0xea4(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xe88(%rip),%xmm0
movaps %xmm0,(%rsp)
cmp    $0x2,%edi
je     118b <main+0x2b>
cmp    $0x1,%edi
je     11a7 <main+0x47>
jmp    124b <main+0xeb>
mov    0x8(%rsi),%rax
cmpb   $0x2d,(%rax)
jne    124b <main+0xeb>
mov    0x1(%rax),%al
cmp    $0x64,%al
je     11b6 <main+0x56>
cmp    $0x61,%al
jne    124b <main+0xeb>
mov    %rsp,%rdi
mov    $0x8,%esi
call   1050 <bubbleSortAscending@plt>
jmp    11c3 <main+0x63>
mov    %rsp,%rdi
mov    $0x8,%esi
call   1080 <bubbleSortDescending@plt>
mov    (%rsp),%esi
lea    0xe53(%rip),%rbx
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x4(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x8(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x10(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x14(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x18(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x1c(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret
lea    0xdd2(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@__const.main.testArray = [8 x i32] [i32 2, i32 6, i32 5, i32 3, i32 7, i32 8, i32 1, i32 4]
@.str = [30 x i8] c"Usage: sortArray [ -d | -a ]\0A\00"
@.str.1 = [4 x i8] c"%d \00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [8 x i32]
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = bitcast [8 x i32]* %6 to i8*
%9 = load i32, i32* %4
%10 = icmp eq i32 %9, 1
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = getelementptr inbounds [8 x i32], [8 x i32]* %6, i64 0, i64 0
%13 = call i32 @bubbleSortAscending(i32* %12, i32 8)
br label %60
14: ; preds = %2
%15 = load i32, i32* %4
%16 = icmp eq i32 %15, 2
br i1 %16, label %17, label %56
17: ; preds = %14
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = getelementptr inbounds i8, i8* %20, i64 0
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 45
br i1 %24, label %25, label %52
25: ; preds = %17
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = getelementptr inbounds i8, i8* %28, i64 1
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp eq i32 %31, 97
br i1 %32, label %33, label %36
33: ; preds = %25
%34 = getelementptr inbounds [8 x i32], [8 x i32]* %6, i64 0, i64 0
%35 = call i32 @bubbleSortAscending(i32* %34, i32 8)
br label %51
36: ; preds = %25
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 1
%39 = load i8*, i8** %38
%40 = getelementptr inbounds i8, i8* %39, i64 1
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = icmp eq i32 %42, 100
br i1 %43, label %44, label %47
44: ; preds = %36
%45 = getelementptr inbounds [8 x i32], [8 x i32]* %6, i64 0, i64 0
%46 = call i32 @bubbleSortDescending(i32* %45, i32 8)
br label %50
47: ; preds = %36
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%49 = call i32 @exit(i32 1)
unreachable
50: ; preds = %44
br label %51
51: ; preds = %50, %33
br label %55
52: ; preds = %17
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%54 = call i32 @exit(i32 1)
unreachable
55: ; preds = %51
br label %59
56: ; preds = %14
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%58 = call i32 @exit(i32 1)
unreachable
59: ; preds = %55
br label %60
60: ; preds = %59, %11
store i32 0, i32* %7
br label %61
61: ; preds = %70, %60
%62 = load i32, i32* %7
%63 = icmp slt i32 %62, 8
br i1 %63, label %64, label %73
64: ; preds = %61
%65 = load i32, i32* %7
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds [8 x i32], [8 x i32]* %6, i64 0, i64 %66
%68 = load i32, i32* %67
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %68)
br label %70
70: ; preds = %64
%71 = load i32, i32* %7
%72 = add nsw i32 %71, 1
store i32 %72, i32* %7
br label %61
73: ; preds = %61
%74 = call i32 @putchar(i8 signext 10)
ret i32 0
}

LLVM IR (-O2):
@__const.main.testArray = [8 x i32] [i32 2, i32 6, i32 5, i32 3, i32 7, i32 8, i32 1, i32 4]
@.str.1 = [4 x i8] c"%d \00"
@str.3 = [29 x i8] c"Usage: sortArray [ -d | -a ]\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [8 x i32]
%4 = bitcast [8 x i32]* %3 to i8*
switch i32 %0, label %28 [
i32 1, label %5
i32 2, label %8
]
5: ; preds = %2
%6 = getelementptr inbounds [8 x i32], [8 x i32]* %3, i64 0, i64 0
%7 = call i32 @bubbleSortAscending(i32* %6, i32 8)
br label %31
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 45
br i1 %12, label %13, label %25
13: ; preds = %8
%14 = getelementptr inbounds i8, i8* %10, i64 1
%15 = load i8, i8* %14
switch i8 %15, label %22 [
i8 97, label %16
i8 100, label %19
]
16: ; preds = %13
%17 = getelementptr inbounds [8 x i32], [8 x i32]* %3, i64 0, i64 0
%18 = call i32 @bubbleSortAscending(i32* %17, i32 8)
br label %31
19: ; preds = %13
%20 = getelementptr inbounds [8 x i32], [8 x i32]* %3, i64 0, i64 0
%21 = call i32 @bubbleSortDescending(i32* %20, i32 8)
br label %31
22: ; preds = %13
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.3, i64 0, i64 0))
%24 = tail call i32 @exit(i32 1)
unreachable
25: ; preds = %8
%26 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.3, i64 0, i64 0))
%27 = tail call i32 @exit(i32 1)
unreachable
28: ; preds = %2
%29 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.3, i64 0, i64 0))
%30 = tail call i32 @exit(i32 1)
unreachable
31: ; preds = %16, %19, %5
%32 = getelementptr inbounds [8 x i32], [8 x i32]* %3, i64 0, i64 0
%33 = load i32, i32* %32
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %33)
%35 = getelementptr inbounds [8 x i32], [8 x i32]* %3, i64 0, i64 1
%36 = load i32, i32* %35
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %36)
%38 = getelementptr inbounds [8 x i32], [8 x i32]* %3, i64 0, i64 2
%39 = load i32, i32* %38
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %39)
%41 = getelementptr inbounds [8 x i32], [8 x i32]* %3, i64 0, i64 3
%42 = load i32, i32* %41
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %42)
%44 = getelementptr inbounds [8 x i32], [8 x i32]* %3, i64 0, i64 4
%45 = load i32, i32* %44
%46 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %45)
%47 = getelementptr inbounds [8 x i32], [8 x i32]* %3, i64 0, i64 5
%48 = load i32, i32* %47
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %48)
%50 = getelementptr inbounds [8 x i32], [8 x i32]* %3, i64 0, i64 6
%51 = load i32, i32* %50
%52 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %51)
%53 = getelementptr inbounds [8 x i32], [8 x i32]* %3, i64 0, i64 7
%54 = load i32, i32* %53
%55 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %54)
%56 = call i32 @putchar(i8 signext 10)
ret i32 0
}