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


x86 assembly (clang, -O0):
<bubble_sort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <assert@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11b1 <bubble_sort+0x91>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    119e <bubble_sort+0x7e>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    -0x8(%rbp),%rcx
movslq -0x10(%rbp),%rdx
cmp    (%rcx,%rdx,4),%eax
jge    118b <bubble_sort+0x6b>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1040 <swap@plt>
jmp    1190 <bubble_sort+0x70>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1154 <bubble_sort+0x34>
jmp    11a3 <bubble_sort+0x83>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    113f <bubble_sort+0x1f>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bubble_sort>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %rdi,%r15
call   1030 <assert@plt>
test   %ebx,%ebx
jle    1192 <bubble_sort+0x72>
mov    %ebx,%r12d
mov    $0x1,%r13d
xor    %ebp,%ebp
jmp    1159 <bubble_sort+0x39>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%r13
cmp    %r12,%rbp
je     1192 <bubble_sort+0x72>
mov    %rbp,%r14
add    $0x1,%rbp
cmp    %r12,%rbp
jae    1150 <bubble_sort+0x30>
mov    %r13,%rbx
jmp    1179 <bubble_sort+0x59>
nopw   0x0(%rax,%rax,1)
add    $0x1,%rbx
cmp    %rbx,%r12
je     1150 <bubble_sort+0x30>
mov    (%r15,%rbx,4),%eax
cmp    (%r15,%r14,4),%eax
jge    1170 <bubble_sort+0x50>
mov    %r15,%rdi
mov    %r14d,%esi
mov    %ebx,%edx
call   1040 <swap@plt>
jmp    1170 <bubble_sort+0x50>
add    $0x8,%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) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
%7 = load i32*, i32** %3
%8 = call i32 @assert(i32* %7)
store i32 0, i32* %5
br label %9
9: ; preds = %42, %2
%10 = load i32, i32* %5
%11 = load i32, i32* %4
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %45
13: ; preds = %9
%14 = load i32, i32* %5
%15 = add nsw i32 %14, 1
store i32 %15, i32* %6
br label %16
16: ; preds = %38, %13
%17 = load i32, i32* %6
%18 = load i32, i32* %4
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %41
20: ; preds = %16
%21 = load i32*, i32** %3
%22 = load i32, i32* %6
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i32, i32* %21, i64 %23
%25 = load i32, i32* %24
%26 = load i32*, i32** %3
%27 = load i32, i32* %5
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i32, i32* %26, i64 %28
%30 = load i32, i32* %29
%31 = icmp slt i32 %25, %30
br i1 %31, label %32, label %37
32: ; preds = %20
%33 = load i32*, i32** %3
%34 = load i32, i32* %5
%35 = load i32, i32* %6
%36 = call i32 @swap(i32* %33, i32 %34, i32 %35)
br label %37
37: ; preds = %32, %20
br label %38
38: ; preds = %37
%39 = load i32, i32* %6
%40 = add nsw i32 %39, 1
store i32 %40, i32* %6
br label %16
41: ; preds = %16
br label %42
42: ; preds = %41
%43 = load i32, i32* %5
%44 = add nsw i32 %43, 1
store i32 %44, i32* %5
br label %9
45: ; preds = %9
ret void
}

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