#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*/ printData(int *, int);
int /*<<< orphan*/ printf(char *, int, int);
void bubbleSort(int data[], int size) {
  int i, j;
  int haveSwap;
  printf("%2c, %2c: ", 'i', 'j');
  printData(data, size);
  for (i = size - 1; i > 0; i--) {
    haveSwap = 0;
    for (j = 1; j <= i; j++) {
      if (data[j] < data[j - 1]) {
        {
          int _temp = *(&data[j]);
          *(&data[j]) = *(&data[j - 1]);
          *(&data[j - 1]) = _temp;
        };
        printf("      : %2d<=>%2d\n", j - 1, j);
        haveSwap = 1;
      }
    }
    printf("%2d, %2d: ", i, j);
    printData(data, size);
    if (haveSwap == 0) {
      break;
    }
  }
}


x86 assembly (clang, -O0):
<bubbleSort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    0xeca(%rip),%rdi
mov    $0x69,%esi
mov    $0x6a,%edx
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1040 <printData@plt>
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jle    124a <bubbleSort+0x12a>
movl   $0x0,-0x18(%rbp)
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jg     120a <bubbleSort+0xea>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    -0x8(%rbp),%rcx
mov    -0x14(%rbp),%edx
sub    $0x1,%edx
movslq %edx,%rdx
cmp    (%rcx,%rdx,4),%eax
jge    11f7 <bubbleSort+0xd7>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x1c(%rbp),%edx
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x14(%rbp),%esi
sub    $0x1,%esi
mov    -0x14(%rbp),%edx
lea    0xe20(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x18(%rbp)
jmp    11fc <bubbleSort+0xdc>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1172 <bubbleSort+0x52>
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%edx
lea    0xe07(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1040 <printData@plt>
cmpl   $0x0,-0x18(%rbp)
jne    1237 <bubbleSort+0x117>
jmp    124a <bubbleSort+0x12a>
jmp    123c <bubbleSort+0x11c>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    115a <bubbleSort+0x3a>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bubbleSort>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
lea    0xec9(%rip),%rdi
mov    $0x69,%esi
mov    $0x6a,%edx
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1040 <printData@plt>
lea    0xeb4(%rip),%r12
mov    %ebp,(%rsp)
jmp    1189 <bubbleSort+0x69>
nopl   0x0(%rax)
lea    0xeb7(%rip),%rdi
mov    0x4(%rsp),%r14d
mov    %r14d,%esi
mov    %ebp,%edx
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    (%rsp),%esi
call   1040 <printData@plt>
mov    %r14d,%ebp
test   %r13d,%r13d
je     11e1 <bubbleSort+0xc1>
cmp    $0x2,%ebp
jl     11e1 <bubbleSort+0xc1>
mov    %ebp,%r14d
add    $0xffffffffffffffff,%r14
lea    -0x1(%rbp),%eax
mov    %eax,0x4(%rsp)
xor    %esi,%esi
xor    %r13d,%r13d
jmp    11b8 <bubbleSort+0x98>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r15,%rsi
cmp    %r15,%r14
je     1160 <bubbleSort+0x40>
lea    0x1(%rsi),%r15
mov    (%rbx,%rsi,4),%ecx
mov    0x4(%rbx,%rsi,4),%eax
cmp    %ecx,%eax
jge    11b0 <bubbleSort+0x90>
mov    %ecx,0x4(%rbx,%rsi,4)
mov    %eax,(%rbx,%rsi,4)
mov    %r12,%rdi
mov    %r15d,%edx
call   1030 <printf@plt>
mov    $0x1,%r13d
jmp    11b0 <bubbleSort+0x90>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"%2c, %2c: \00"
@.str.1 = [19 x i8] c" : %2d<=>%2d\0A\00"
@.str.2 = [11 x i8] c"%2d, %2d: \00"
define void @bubbleSort(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
%9 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 105, i32 106)
%10 = load i32*, i32** %3
%11 = load i32, i32* %4
%12 = call i32 @printData(i32* %10, i32 %11)
%13 = load i32, i32* %4
%14 = sub nsw i32 %13, 1
store i32 %14, i32* %5
br label %15
15: ; preds = %77, %2
%16 = load i32, i32* %5
%17 = icmp sgt i32 %16, 0
br i1 %17, label %18, label %80
18: ; preds = %15
store i32 0, i32* %7
store i32 1, i32* %6
br label %19
19: ; preds = %63, %18
%20 = load i32, i32* %6
%21 = load i32, i32* %5
%22 = icmp sle i32 %20, %21
br i1 %22, label %23, label %66
23: ; preds = %19
%24 = load i32*, i32** %3
%25 = load i32, i32* %6
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i32, i32* %24, i64 %26
%28 = load i32, i32* %27
%29 = load i32*, i32** %3
%30 = load i32, i32* %6
%31 = sub nsw i32 %30, 1
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i32, i32* %29, i64 %32
%34 = load i32, i32* %33
%35 = icmp slt i32 %28, %34
br i1 %35, label %36, label %62
36: ; preds = %23
%37 = load i32*, i32** %3
%38 = load i32, i32* %6
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i32, i32* %37, i64 %39
%41 = load i32, i32* %40
store i32 %41, i32* %8
%42 = load i32*, i32** %3
%43 = load i32, i32* %6
%44 = sub nsw i32 %43, 1
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i32, i32* %42, i64 %45
%47 = load i32, i32* %46
%48 = load i32*, i32** %3
%49 = load i32, i32* %6
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i32, i32* %48, i64 %50
store i32 %47, i32* %51
%52 = load i32, i32* %8
%53 = load i32*, i32** %3
%54 = load i32, i32* %6
%55 = sub nsw i32 %54, 1
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i32, i32* %53, i64 %56
store i32 %52, i32* %57
%58 = load i32, i32* %6
%59 = sub nsw i32 %58, 1
%60 = load i32, i32* %6
%61 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %59, i32 %60)
store i32 1, i32* %7
br label %62
62: ; preds = %36, %23
br label %63
63: ; preds = %62
%64 = load i32, i32* %6
%65 = add nsw i32 %64, 1
store i32 %65, i32* %6
br label %19
66: ; preds = %19
%67 = load i32, i32* %5
%68 = load i32, i32* %6
%69 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %67, i32 %68)
%70 = load i32*, i32** %3
%71 = load i32, i32* %4
%72 = call i32 @printData(i32* %70, i32 %71)
%73 = load i32, i32* %7
%74 = icmp eq i32 %73, 0
br i1 %74, label %75, label %76
75: ; preds = %66
br label %80
76: ; preds = %66
br label %77
77: ; preds = %76
%78 = load i32, i32* %5
%79 = add nsw i32 %78, -1
store i32 %79, i32* %5
br label %15
80: ; preds = %75, %15
ret void
}

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