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


x86 assembly (clang, -O0):
<bubbleSort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x1,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11b6 <bubbleSort+0xa6>
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11b1 <bubbleSort+0xa1>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    -0x8(%rbp),%rcx
mov    -0x10(%rbp),%edx
add    $0x1,%edx
movslq %edx,%rdx
cmp    (%rcx,%rdx,4),%eax
jle    119e <bubbleSort+0x8e>
mov    -0x8(%rbp),%rdi
movslq -0x10(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x2,%rax
add    %rax,%rsi
call   1030 <swap@plt>
movl   $0x1,-0x14(%rbp)
jmp    11a3 <bubbleSort+0x93>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    113e <bubbleSort+0x2e>
jmp    1126 <bubbleSort+0x16>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bubbleSort>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
cmp    $0x2,%esi
jl     116e <bubbleSort+0x5e>
mov    %esi,%r14d
mov    %rdi,%r12
lea    -0x1(%r14),%r15d
xor    %ecx,%ecx
xor    %eax,%eax
nopl   0x0(%rax,%rax,1)
mov    (%r12,%rcx,4),%edx
lea    0x1(%rcx),%rbx
cmp    0x4(%r12,%rcx,4),%edx
jle    1155 <bubbleSort+0x45>
lea    (%r12,%rcx,4),%rdi
lea    (%r12,%rcx,4),%rsi
add    $0x4,%rsi
call   1030 <swap@plt>
mov    $0x1,%eax
mov    %rbx,%rcx
cmp    %r15,%rbx
jne    1130 <bubbleSort+0x20>
cmp    $0x2,%r14d
jl     116e <bubbleSort+0x5e>
xor    %ecx,%ecx
test   %eax,%eax
mov    $0x0,%eax
jne    1130 <bubbleSort+0x20>
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
store i32* %0, i32** %3
store i32 %1, i32* %4
store i32 1, i32* %6
br label %7
7: ; preds = %44, %2
%8 = load i32, i32* %6
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %45
10: ; preds = %7
store i32 0, i32* %6
store i32 0, i32* %5
br label %11
11: ; preds = %41, %10
%12 = load i32, i32* %5
%13 = load i32, i32* %4
%14 = sub nsw i32 %13, 1
%15 = icmp slt i32 %12, %14
br i1 %15, label %16, label %44
16: ; preds = %11
%17 = load i32*, i32** %3
%18 = load i32, i32* %5
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i32, i32* %17, i64 %19
%21 = load i32, i32* %20
%22 = load i32*, i32** %3
%23 = load i32, i32* %5
%24 = add nsw i32 %23, 1
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i32, i32* %22, i64 %25
%27 = load i32, i32* %26
%28 = icmp sgt i32 %21, %27
br i1 %28, label %29, label %40
29: ; preds = %16
%30 = load i32*, i32** %3
%31 = load i32, i32* %5
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i32, i32* %30, i64 %32
%34 = load i32*, i32** %3
%35 = load i32, i32* %5
%36 = add nsw i32 %35, 1
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i32, i32* %34, i64 %37
%39 = call i32 @swap(i32* %33, i32* %38)
store i32 1, i32* %6
br label %40
40: ; preds = %29, %16
br label %41
41: ; preds = %40
%42 = load i32, i32* %5
%43 = add nsw i32 %42, 1
store i32 %43, i32* %5
br label %11
44: ; preds = %11
br label %7
45: ; preds = %7
ret void
}

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