#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 stub1(int, int);
int /*<<< orphan*/ swap(int *, int *);
void bubble_sort(int arr[], int size, int (*compare)(int, int)) {
  int i, j;
  for (i = 0; i < size; i++)
    for (j = 0; j < size - 1; j++)
      if ((*compare)(arr[i], arr[j + 1]))
        swap(&arr[i], &arr[i + 1]);
}


x86 assembly (clang, -O0):
<bubble_sort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11c5 <bubble_sort+0xb5>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11b2 <bubble_sort+0xa2>
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%rcx
movslq -0x1c(%rbp),%rdx
mov    (%rcx,%rdx,4),%edi
mov    -0x8(%rbp),%rcx
mov    -0x20(%rbp),%edx
add    $0x1,%edx
movslq %edx,%rdx
mov    (%rcx,%rdx,4),%esi
call   *%rax
cmp    $0x0,%eax
je     119f <bubble_sort+0x8f>
mov    -0x8(%rbp),%rdi
movslq -0x1c(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x2,%rax
add    %rax,%rsi
call   1030 <swap@plt>
jmp    11a4 <bubble_sort+0x94>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    113d <bubble_sort+0x2d>
jmp    11b7 <bubble_sort+0xa7>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    112a <bubble_sort+0x1a>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bubble_sort>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
test   %esi,%esi
jle    11b4 <bubble_sort+0xa4>
mov    %rdx,%r15
mov    %rdi,%r12
lea    -0x1(%rsi),%ebp
mov    %esi,%eax
xor    %ecx,%ecx
mov    %rsi,0x8(%rsp)
mov    %rax,(%rsp)
jmp    1153 <bubble_sort+0x43>
xchg   %ax,%ax
mov    0x8(%rsp),%rsi
mov    (%rsp),%rax
mov    0x10(%rsp),%rcx
cmp    %rax,%rcx
je     11b4 <bubble_sort+0xa4>
cmp    $0x1,%esi
jne    1170 <bubble_sort+0x60>
add    $0x1,%rcx
cmp    %rax,%rcx
jne    1153 <bubble_sort+0x43>
jmp    11b4 <bubble_sort+0xa4>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    (%r12,%rcx,4),%rbx
lea    (%r12,%rcx,4),%r13
add    $0x4,%r13
add    $0x1,%rcx
mov    %rcx,0x10(%rsp)
xor    %r14d,%r14d
jmp    1195 <bubble_sort+0x85>
nopw   0x0(%rax,%rax,1)
cmp    %r14,%rbp
je     1140 <bubble_sort+0x30>
mov    (%rbx),%edi
mov    0x4(%r12,%r14,4),%esi
add    $0x1,%r14
call   *%r15
test   %eax,%eax
je     1190 <bubble_sort+0x80>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1030 <swap@plt>
jmp    1190 <bubble_sort+0x80>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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