#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 *, ...);
void printBubbleSort(int len, int array[], int pos) {
  printArray(len, array);
  int i = 0;
  while (i < len) {
    if (i == pos) {
      printf(" |%s|  ", array[i] > array[i + 1] ? "swap" : "    ");
    } else if (i + 1 != pos) {
      printf("    ");
    }
    i++;
  }
  printf("\n\n");
}


x86 assembly (clang, -O0):
<printBubbleSort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1040 <printArray@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11cf <printBubbleSort+0xaf>
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jne    119f <printBubbleSort+0x7f>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%ecx
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%edx
add    $0x1,%edx
movslq %edx,%rdx
mov    (%rax,%rdx,4),%edx
lea    0xe8e(%rip),%rsi
lea    0xe82(%rip),%rax
cmp    %edx,%ecx
cmovg  %rax,%rsi
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11c1 <printBubbleSort+0xa1>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
cmp    -0x14(%rbp),%eax
je     11bc <printBubbleSort+0x9c>
lea    0xe58(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11c1 <printBubbleSort+0xa1>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1145 <printBubbleSort+0x25>
lea    0xe3c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printBubbleSort>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %rsi,%r12
mov    %edi,%r15d
call   1050 <printArray@plt>
test   %r15d,%r15d
jle    11b5 <printBubbleSort+0x85>
mov    %r14d,%ebp
mov    %r15d,%ebx
lea    0xeb2(%rip),%r14
lea    0xe9e(%rip),%r15
xor    %r13d,%r13d
jmp    1183 <printBubbleSort+0x53>
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%r13
cmp    %rbx,%r13
je     11b5 <printBubbleSort+0x85>
cmp    %rbp,%r13
jne    11a0 <printBubbleSort+0x70>
mov    (%r12,%rbp,4),%eax
lea    0xe75(%rip),%rsi
cmp    0x4(%r12,%rbp,4),%eax
jg     1170 <printBubbleSort+0x40>
mov    %r14,%rsi
jmp    1170 <printBubbleSort+0x40>
nop
add    $0x1,%r13
cmp    %rbp,%r13
je     117e <printBubbleSort+0x4e>
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    117e <printBubbleSort+0x4e>
lea    0xe56(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <puts@plt>

LLVM IR (-O0):
@.str = [8 x i8] c" |%s| \00"
@.str.1 = [5 x i8] c"swap\00"
@.str.2 = [5 x i8] c" \00"
@.str.3 = [3 x i8] c"\0A\0A\00"
define void @printBubbleSort(i32 %0, i32* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store i32* %1, i32** %5
store i32 %2, i32* %6
%8 = load i32, i32* %4
%9 = load i32*, i32** %5
%10 = call i32 @printArray(i32 %8, i32* %9)
store i32 0, i32* %7
br label %11
11: ; preds = %43, %3
%12 = load i32, i32* %7
%13 = load i32, i32* %4
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %46
15: ; preds = %11
%16 = load i32, i32* %7
%17 = load i32, i32* %6
%18 = icmp eq i32 %16, %17
br i1 %18, label %19, label %35
19: ; preds = %15
%20 = load i32*, i32** %5
%21 = load i32, i32* %7
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i32, i32* %20, i64 %22
%24 = load i32, i32* %23
%25 = load i32*, i32** %5
%26 = load i32, i32* %7
%27 = add nsw i32 %26, 1
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i32, i32* %25, i64 %28
%30 = load i32, i32* %29
%31 = icmp sgt i32 %24, %30
%32 = zext i1 %31 to i64
%33 = select i1 %31, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0)
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %33)
br label %43
35: ; preds = %15
%36 = load i32, i32* %7
%37 = add nsw i32 %36, 1
%38 = load i32, i32* %6
%39 = icmp ne i32 %37, %38
br i1 %39, label %40, label %42
40: ; preds = %35
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %42
42: ; preds = %40, %35
br label %43
43: ; preds = %42, %19
%44 = load i32, i32* %7
%45 = add nsw i32 %44, 1
store i32 %45, i32* %7
br label %11
46: ; preds = %11
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
ret void
}

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