#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*/ printArray(int *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ swap(int *, int *);
void bubbleSort(int arr[], int n) {
  int i, j;
  for (i = 0; i < n - 1; i++) {
    for (j = 0; j < n - 1 - i; j++) {
      printf("(%d, %d)\t", j, j + 1);
      if (arr[j] > arr[j + 1])
        swap(&arr[j], &arr[j + 1]);
      printArray(arr, n);
    }
    printf("\n");
  }
}


x86 assembly (clang, -O0):
<bubbleSort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    1207 <bubbleSort+0xd7>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
sub    -0x10(%rbp),%ecx
cmp    %ecx,%eax
jge    11eb <bubbleSort+0xbb>
mov    -0x14(%rbp),%esi
mov    -0x14(%rbp),%edx
add    $0x1,%edx
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    -0x8(%rbp),%rcx
mov    -0x14(%rbp),%edx
add    $0x1,%edx
movslq %edx,%rdx
cmp    (%rcx,%rdx,4),%eax
jle    11d1 <bubbleSort+0xa1>
mov    -0x8(%rbp),%rdi
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
mov    -0x14(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x2,%rax
add    %rax,%rsi
call   1050 <swap@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1040 <printArray@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    115e <bubbleSort+0x2e>
lea    0xe18(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1146 <bubbleSort+0x16>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bubbleSort>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
cmp    $0x2,%esi
jl     11f1 <bubbleSort+0xb1>
mov    %esi,%r14d
mov    %rdi,%r12
lea    -0x1(%r14),%eax
lea    0x4(%rdi),%rcx
mov    %rcx,0x10(%rsp)
mov    %eax,%ebp
xor    %r15d,%r15d
mov    %eax,0xc(%rsp)
jmp    119a <bubbleSort+0x5a>
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x1,%r15d
add    $0xffffffff,%ebp
mov    0xc(%rsp),%eax
cmp    %eax,%r15d
je     11f1 <bubbleSort+0xb1>
mov    %ebp,%ebp
cmp    %r15d,%eax
jle    1180 <bubbleSort+0x40>
mov    0x10(%rsp),%rbx
xor    %r13d,%r13d
jmp    11c4 <bubbleSort+0x84>
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %r14d,%esi
call   1050 <printArray@plt>
add    $0x4,%rbx
cmp    %r13,%rbp
je     1180 <bubbleSort+0x40>
mov    %r13,%rsi
add    $0x1,%r13
lea    0xe2e(%rip),%rdi
mov    %r13d,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    -0x4(%rbx),%eax
cmp    (%rbx),%eax
jle    11b0 <bubbleSort+0x70>
lea    -0x4(%rbx),%rdi
mov    %rbx,%rsi
call   1060 <swap@plt>
jmp    11b0 <bubbleSort+0x70>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"(%d, %d)\09\00"
@.str.1 = [2 x i8] c"\0A\00"
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 0, i32* %5
br label %7
7: ; preds = %57, %2
%8 = load i32, i32* %5
%9 = load i32, i32* %4
%10 = sub nsw i32 %9, 1
%11 = icmp slt i32 %8, %10
br i1 %11, label %12, label %60
12: ; preds = %7
store i32 0, i32* %6
br label %13
13: ; preds = %52, %12
%14 = load i32, i32* %6
%15 = load i32, i32* %4
%16 = sub nsw i32 %15, 1
%17 = load i32, i32* %5
%18 = sub nsw i32 %16, %17
%19 = icmp slt i32 %14, %18
br i1 %19, label %20, label %55
20: ; preds = %13
%21 = load i32, i32* %6
%22 = load i32, i32* %6
%23 = add nsw i32 %22, 1
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %21, i32 %23)
%25 = load i32*, i32** %3
%26 = load i32, i32* %6
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i32, i32* %25, i64 %27
%29 = load i32, i32* %28
%30 = load i32*, i32** %3
%31 = load i32, i32* %6
%32 = add nsw i32 %31, 1
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i32, i32* %30, i64 %33
%35 = load i32, i32* %34
%36 = icmp sgt i32 %29, %35
br i1 %36, label %37, label %48
37: ; preds = %20
%38 = load i32*, i32** %3
%39 = load i32, i32* %6
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i32, i32* %38, i64 %40
%42 = load i32*, i32** %3
%43 = load i32, i32* %6
%44 = add nsw i32 %43, 1
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i32, i32* %42, i64 %45
%47 = call i32 @swap(i32* %41, i32* %46)
br label %48
48: ; preds = %37, %20
%49 = load i32*, i32** %3
%50 = load i32, i32* %4
%51 = call i32 @printArray(i32* %49, i32 %50)
br label %52
52: ; preds = %48
%53 = load i32, i32* %6
%54 = add nsw i32 %53, 1
store i32 %54, i32* %6
br label %13
55: ; preds = %13
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %57
57: ; preds = %55
%58 = load i32, i32* %5
%59 = add nsw i32 %58, 1
store i32 %59, i32* %5
br label %7
60: ; preds = %7
ret void
}

LLVM IR (-O2):
@.str = [10 x i8] c"(%d, %d)\09\00"
define void @bubbleSort(i32* %0, i32 %1) {
%3 = add i32 %1, -1
%4 = icmp sgt i32 %1, 1
br i1 %4, label %5, label %32
5: ; preds = %2, %27
%6 = phi i32 [ %30, %27 ], [ %3, %2 ]
%7 = phi i32 [ %29, %27 ], [ 0, %2 ]
%8 = icmp sgt i32 %3, %7
br i1 %8, label %9, label %27
9: ; preds = %5
%10 = zext i32 %6 to i64
br label %11
11: ; preds = %9, %24
%12 = phi i64 [ 0, %9 ], [ %13, %24 ]
%13 = add nuw nsw i64 %12, 1
%14 = trunc i64 %13 to i32
%15 = trunc i64 %12 to i32
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %15, i32 %14)
%17 = getelementptr inbounds i32, i32* %0, i64 %12
%18 = load i32, i32* %17
%19 = getelementptr inbounds i32, i32* %0, i64 %13
%20 = load i32, i32* %19
%21 = icmp sgt i32 %18, %20
br i1 %21, label %22, label %24
22: ; preds = %11
%23 = tail call i32 @swap(i32* %17, i32* %19)
br label %24
24: ; preds = %22, %11
%25 = tail call i32 @printArray(i32* %0, i32 %1)
%26 = icmp eq i64 %13, %10
br i1 %26, label %27, label %11
27: ; preds = %24, %5
%28 = tail call i32 @putchar(i32 10)
%29 = add nuw nsw i32 %7, 1
%30 = add i32 %6, -1
%31 = icmp eq i32 %29, %3
br i1 %31, label %32, label %5
32: ; preds = %27, %2
ret void
}