#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*/ swapValue(int *, int, int);
void bubbleSort(int arr[], int arrLength) {
  int indexOfLastUnsortedElement = arrLength;
  int swapped = 0;
  while (swapped == 0) {
    swapped = 1;
    for (int i = 0; i < indexOfLastUnsortedElement - 1; i++) {
      if (arr[i] > arr[i + 1]) {
        swapValue(arr, i, i + 1);
        swapped = 0;
      }
    }
    indexOfLastUnsortedElement--;
  }
}


x86 assembly (clang, -O0):
<bubbleSort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    11b0 <bubbleSort+0xa0>
movl   $0x1,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    -0x10(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11a2 <bubbleSort+0x92>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    -0x8(%rbp),%rcx
mov    -0x18(%rbp),%edx
add    $0x1,%edx
movslq %edx,%rdx
cmp    (%rcx,%rdx,4),%eax
jle    118f <bubbleSort+0x7f>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    -0x18(%rbp),%edx
add    $0x1,%edx
call   1030 <swapValue@plt>
movl   $0x0,-0x14(%rbp)
jmp    1194 <bubbleSort+0x84>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1144 <bubbleSort+0x34>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    112c <bubbleSort+0x1c>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bubbleSort>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%r12
lea    -0x1(%r14),%r15d
jmp    1138 <bubbleSort+0x28>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0xffffffff,%r15d
test   %eax,%eax
jne    1176 <bubbleSort+0x66>
cmp    $0x2,%r14d
jl     1176 <bubbleSort+0x66>
mov    %r15d,%r15d
add    $0xffffffff,%r14d
mov    $0x1,%eax
xor    %esi,%esi
jmp    1158 <bubbleSort+0x48>
xchg   %ax,%ax
mov    %rbx,%rsi
cmp    %rbx,%r15
je     1130 <bubbleSort+0x20>
mov    (%r12,%rsi,4),%ecx
lea    0x1(%rsi),%rbx
cmp    0x4(%r12,%rsi,4),%ecx
jle    1150 <bubbleSort+0x40>
lea    0x1(%rsi),%edx
mov    %r12,%rdi
call   1030 <swapValue@plt>
xor    %eax,%eax
jmp    1150 <bubbleSort+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @bubbleSort(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
%8 = load i32, i32* %4
store i32 %8, i32* %5
store i32 0, i32* %6
br label %9
9: ; preds = %41, %2
%10 = load i32, i32* %6
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %44
12: ; preds = %9
store i32 1, i32* %6
store i32 0, i32* %7
br label %13
13: ; preds = %38, %12
%14 = load i32, i32* %7
%15 = load i32, i32* %5
%16 = sub nsw i32 %15, 1
%17 = icmp slt i32 %14, %16
br i1 %17, label %18, label %41
18: ; preds = %13
%19 = load i32*, i32** %3
%20 = load i32, i32* %7
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i32, i32* %19, i64 %21
%23 = load i32, i32* %22
%24 = load i32*, i32** %3
%25 = load i32, i32* %7
%26 = add nsw i32 %25, 1
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i32, i32* %24, i64 %27
%29 = load i32, i32* %28
%30 = icmp sgt i32 %23, %29
br i1 %30, label %31, label %37
31: ; preds = %18
%32 = load i32*, i32** %3
%33 = load i32, i32* %7
%34 = load i32, i32* %7
%35 = add nsw i32 %34, 1
%36 = call i32 @swapValue(i32* %32, i32 %33, i32 %35)
store i32 0, i32* %6
br label %37
37: ; preds = %31, %18
br label %38
38: ; preds = %37
%39 = load i32, i32* %7
%40 = add nsw i32 %39, 1
store i32 %40, i32* %7
br label %13
41: ; preds = %13
%42 = load i32, i32* %5
%43 = add nsw i32 %42, -1
store i32 %43, i32* %5
br label %9
44: ; preds = %9
ret void
}

LLVM IR (-O2):
define void @bubbleSort(i32* %0, i32 %1) {
br label %5
3: ; preds = %26
%4 = icmp eq i32 %27, 0
br i1 %4, label %5, label %29
5: ; preds = %2, %3
%6 = phi i32 [ %1, %2 ], [ %8, %3 ]
%7 = phi i32 [ %1, %2 ], [ %9, %3 ]
%8 = add i32 %6, -1
%9 = add nsw i32 %7, -1
%10 = icmp sgt i32 %7, 1
br i1 %10, label %11, label %29
11: ; preds = %5
%12 = zext i32 %8 to i64
br label %13
13: ; preds = %11, %26
%14 = phi i64 [ 0, %11 ], [ %18, %26 ]
%15 = phi i32 [ 1, %11 ], [ %27, %26 ]
%16 = getelementptr inbounds i32, i32* %0, i64 %14
%17 = load i32, i32* %16
%18 = add nuw nsw i64 %14, 1
%19 = getelementptr inbounds i32, i32* %0, i64 %18
%20 = load i32, i32* %19
%21 = icmp sgt i32 %17, %20
br i1 %21, label %22, label %26
22: ; preds = %13
%23 = trunc i64 %18 to i32
%24 = trunc i64 %14 to i32
%25 = tail call i32 @swapValue(i32* %0, i32 %24, i32 %23)
br label %26
26: ; preds = %13, %22
%27 = phi i32 [ 0, %22 ], [ %15, %13 ]
%28 = icmp eq i64 %18, %12
br i1 %28, label %3, label %13
29: ; preds = %5, %3
ret void
}