#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(int work[], const int size, int (*compare)(int x, int y)) {
  int pass;
  int count;
  for (pass = 1; pass < size; pass++) {
    for (count = 0; count < size - 1; count++) {
      if ((*compare)(work[count], work[count + 1])) {
        swap(&work[count], &work[count + 1]);
      }
    }
  }
}


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

x86 assembly (clang, -O2):
<bubble>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x2,%esi
jl     1184 <bubble+0x74>
mov    %rdx,%r12
mov    %esi,%r14d
mov    %rdi,%r15
lea    -0x1(%r14),%eax
mov    %rax,(%rsp)
add    $0x4,%r15
mov    $0x1,%ebp
jmp    1148 <bubble+0x38>
nopl   0x0(%rax)
add    $0x1,%ebp
cmp    %r14d,%ebp
je     1184 <bubble+0x74>
mov    (%rsp),%r13
mov    %r15,%rbx
jmp    116a <bubble+0x5a>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x4,%rbx
add    $0xffffffffffffffff,%r13
je     1140 <bubble+0x30>
mov    -0x4(%rbx),%edi
mov    (%rbx),%esi
call   *%r12
test   %eax,%eax
je     1160 <bubble+0x50>
lea    -0x4(%rbx),%rdi
mov    %rbx,%rsi
call   1030 <swap@plt>
jmp    1160 <bubble+0x50>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @bubble(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 1, 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* %8
%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* %8
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i32, i32* %35, i64 %37
%39 = load i32*, i32** %4
%40 = load i32, i32* %8
%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(i32* %0, i32 %1, i32 (i32, i32)* nocapture %2) {
%4 = icmp sgt i32 %1, 1
br i1 %4, label %5, label %26
5: ; preds = %3
%6 = add nsw i32 %1, -1
%7 = zext i32 %6 to i64
br label %8
8: ; preds = %23, %5
%9 = phi i32 [ 1, %5 ], [ %24, %23 ]
br label %10
10: ; preds = %8, %21
%11 = phi i64 [ 0, %8 ], [ %14, %21 ]
%12 = getelementptr inbounds i32, i32* %0, i64 %11
%13 = load i32, i32* %12
%14 = add nuw nsw i64 %11, 1
%15 = getelementptr inbounds i32, i32* %0, i64 %14
%16 = load i32, i32* %15
%17 = tail call i32 %2(i32 %13, i32 %16)
%18 = icmp eq i32 %17, 0
br i1 %18, label %21, label %19
19: ; preds = %10
%20 = tail call i32 @swap(i32* %12, i32* %15)
br label %21
21: ; preds = %10, %19
%22 = icmp eq i64 %14, %7
br i1 %22, label %23, label %10
23: ; preds = %21
%24 = add nuw nsw i32 %9, 1
%25 = icmp eq i32 %24, %1
br i1 %25, label %26, label %8
26: ; preds = %23, %3
ret void
}