#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*/ cmp_fun(int, int);
int /*<<< orphan*/ swap(int *, int *);
int bubble_sort(int *list, int len) {
  if (NULL == list || len < 0) {
    return -1;
  }
  int i = 0;
  for (i = 0; i < len; i++) {
    int j = len - 1;
    for (j = len - 1; j > i; j--) {
      if (!cmp_fun(list[j], list[i])) {
        swap(&list[j], &list[i]);
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<bubble_sort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
xor    %eax,%eax
cmp    -0x10(%rbp),%rax
je     1145 <bubble_sort+0x25>
cmpl   $0x0,-0x14(%rbp)
jge    1151 <bubble_sort+0x31>
movl   $0xffffffff,-0x4(%rbp)
jmp    11fd <bubble_sort+0xdd>
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11f6 <bubble_sort+0xd6>
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jle    11e3 <bubble_sort+0xc3>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
call   1030 <cmp_fun@plt>
cmp    $0x0,%eax
jne    11d0 <bubble_sort+0xb0>
mov    -0x10(%rbp),%rdi
movslq -0x1c(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
movslq -0x18(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
call   1040 <swap@plt>
jmp    11d5 <bubble_sort+0xb5>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    117d <bubble_sort+0x5d>
jmp    11e8 <bubble_sort+0xc8>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    115f <bubble_sort+0x3f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
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    $0xffffffff,%eax
mov    %rdi,(%rsp)
test   %rdi,%rdi
je     11db <bubble_sort+0xbb>
mov    %esi,%r15d
test   %esi,%esi
js     11db <bubble_sort+0xbb>
je     11d9 <bubble_sort+0xb9>
mov    %r15d,%r13d
add    $0xffffffff,%r15d
lea    -0x1(%r13),%rax
mov    %rax,0x10(%rsp)
mov    (%rsp),%rax
lea    (%rax,%r13,4),%rax
add    $0xfffffffffffffffc,%rax
mov    %rax,0x8(%rsp)
xor    %ebp,%ebp
jmp    1189 <bubble_sort+0x69>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%rbp
cmp    %r13,%rbp
je     11d9 <bubble_sort+0xb9>
cmp    %r15,%rbp
jae    1180 <bubble_sort+0x60>
mov    (%rsp),%rax
lea    (%rax,%rbp,4),%r12
mov    0x8(%rsp),%rbx
mov    0x10(%rsp),%r14
jmp    11bd <bubble_sort+0x9d>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0xffffffffffffffff,%r14
add    $0xfffffffffffffffc,%rbx
cmp    %rbp,%r14
jle    1180 <bubble_sort+0x60>
mov    (%rbx),%edi
mov    (%r12),%esi
call   1030 <cmp_fun@plt>
test   %eax,%eax
jne    11b0 <bubble_sort+0x90>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1040 <swap@plt>
jmp    11b0 <bubble_sort+0x90>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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