#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 bubble_sort(int *arr, int num, int (*compare_func)(int num0, int num1)) {
  int i, j;
  for (i = 0; i < num; i++)
    for (j = 10 - 1; j > i; j--)
      if (compare_func(arr[j], arr[i]))
        swap(&arr[i], &arr[j]);
}


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    11b7 <bubble_sort+0xa7>
movl   $0x9,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jle    11a4 <bubble_sort+0x94>
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%rcx
movslq -0x20(%rbp),%rdx
mov    (%rcx,%rdx,4),%edi
mov    -0x8(%rbp),%rcx
movslq -0x1c(%rbp),%rdx
mov    (%rcx,%rdx,4),%esi
call   *%rax
cmp    $0x0,%eax
je     1191 <bubble_sort+0x81>
mov    -0x8(%rbp),%rdi
movslq -0x1c(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
movslq -0x20(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
call   1030 <swap@plt>
jmp    1196 <bubble_sort+0x86>
mov    -0x20(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x20(%rbp)
jmp    113d <bubble_sort+0x2d>
jmp    11a9 <bubble_sort+0x99>
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
mov    %rdi,0x8(%rsp)
test   %esi,%esi
jle    1197 <bubble_sort+0x87>
mov    %rdx,%r15
mov    %esi,%r13d
mov    0x8(%rsp),%rax
add    $0x24,%rax
mov    %rax,0x10(%rsp)
xor    %r14d,%r14d
jmp    1149 <bubble_sort+0x39>
add    $0x1,%r14
cmp    %r13,%r14
je     1197 <bubble_sort+0x87>
cmp    $0x8,%r14
ja     1140 <bubble_sort+0x30>
mov    0x8(%rsp),%rax
lea    (%rax,%r14,4),%r12
mov    $0x9,%ebp
mov    0x10(%rsp),%rbx
jmp    117d <bubble_sort+0x6d>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0xffffffffffffffff,%rbp
add    $0xfffffffffffffffc,%rbx
cmp    %r14,%rbp
jbe    1140 <bubble_sort+0x30>
mov    (%rbx),%edi
mov    (%r12),%esi
call   *%r15
test   %eax,%eax
je     1170 <bubble_sort+0x60>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1030 <swap@plt>
jmp    1170 <bubble_sort+0x60>
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 = %47, %3
%10 = load i32, i32* %7
%11 = load i32, i32* %5
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %50
13: ; preds = %9
store i32 9, i32* %8
br label %14
14: ; preds = %43, %13
%15 = load i32, i32* %8
%16 = load i32, i32* %7
%17 = icmp sgt i32 %15, %16
br i1 %17, label %18, label %46
18: ; preds = %14
%19 = load i32 (i32, i32)*, i32 (i32, i32)** %6
%20 = load i32*, i32** %4
%21 = load i32, i32* %8
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i32, i32* %20, i64 %22
%24 = load i32, i32* %23
%25 = load i32*, i32** %4
%26 = load i32, i32* %7
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i32, i32* %25, i64 %27
%29 = load i32, i32* %28
%30 = call i32 %19(i32 %24, i32 %29)
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %42
32: ; preds = %18
%33 = load i32*, i32** %4
%34 = load i32, i32* %7
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i32, i32* %33, i64 %35
%37 = load i32*, i32** %4
%38 = load i32, i32* %8
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i32, i32* %37, i64 %39
%41 = call i32 @swap(i32* %36, i32* %40)
br label %42
42: ; preds = %32, %18
br label %43
43: ; preds = %42
%44 = load i32, i32* %8
%45 = add nsw i32 %44, -1
store i32 %45, i32* %8
br label %14
46: ; preds = %14
br label %47
47: ; preds = %46
%48 = load i32, i32* %7
%49 = add nsw i32 %48, 1
store i32 %49, i32* %7
br label %9
50: ; 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 %27
5: ; preds = %3
%6 = zext i32 %1 to i64
br label %7
7: ; preds = %5, %24
%8 = phi i64 [ 0, %5 ], [ %25, %24 ]
%9 = icmp ult i64 %8, 9
br i1 %9, label %10, label %24
10: ; preds = %7
%11 = getelementptr inbounds i32, i32* %0, i64 %8
br label %12
12: ; preds = %10, %21
%13 = phi i64 [ 9, %10 ], [ %22, %21 ]
%14 = getelementptr inbounds i32, i32* %0, i64 %13
%15 = load i32, i32* %14
%16 = load i32, i32* %11
%17 = tail call i32 %2(i32 %15, i32 %16)
%18 = icmp eq i32 %17, 0
br i1 %18, label %21, label %19
19: ; preds = %12
%20 = tail call i32 @swap(i32* %11, i32* %14)
br label %21
21: ; preds = %12, %19
%22 = add nsw i64 %13, -1
%23 = icmp ugt i64 %22, %8
br i1 %23, label %12, label %24
24: ; preds = %21, %7
%25 = add nuw nsw i64 %8, 1
%26 = icmp eq i64 %25, %6
br i1 %26, label %27, label %7
27: ; preds = %24, %3
ret void
}