#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 *a, int n) {
  int i;
  int j;
  for (i = 0; i < n - 1; i++) {
    for (j = 0; j < n - 1 - i; j++) {
      if (a[j] > a[j + 1])
        __swap(&a[j + 1], &a[j]);
    }
  }
}


x86 assembly (clang, -O0):
<bubble_sort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11c0 <bubble_sort+0xb0>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
sub    -0x10(%rbp),%ecx
cmp    %ecx,%eax
jge    11ad <bubble_sort+0x9d>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    -0x8(%rbp),%rcx
mov    -0x14(%rbp),%edx
add    $0x1,%edx
movslq %edx,%rdx
cmp    (%rcx,%rdx,4),%eax
jle    119a <bubble_sort+0x8a>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
call   1030 <__swap@plt>
jmp    119f <bubble_sort+0x8f>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    113e <bubble_sort+0x2e>
jmp    11b2 <bubble_sort+0xa2>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1126 <bubble_sort+0x16>
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
cmp    $0x2,%esi
jl     117f <bubble_sort+0x6f>
mov    %esi,%r15d
mov    %rdi,%r14
add    $0xffffffff,%r15d
add    $0x4,%r14
xor    %r12d,%r12d
mov    %r15d,%r13d
jmp    114d <bubble_sort+0x3d>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%r12d
add    $0xffffffff,%r13d
cmp    %r15d,%r12d
je     117f <bubble_sort+0x6f>
mov    %r13d,%r13d
cmp    %r12d,%r15d
jle    1140 <bubble_sort+0x30>
mov    %r13,%rbp
mov    %r14,%rbx
jmp    116a <bubble_sort+0x5a>
nopl   (%rax)
add    $0x4,%rbx
add    $0xffffffffffffffff,%rbp
je     1140 <bubble_sort+0x30>
mov    -0x4(%rbx),%eax
cmp    (%rbx),%eax
jle    1160 <bubble_sort+0x50>
lea    -0x4(%rbx),%rsi
mov    %rbx,%rdi
call   1030 <__swap@plt>
jmp    1160 <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
store i32 0, i32* %5
br label %7
7: ; preds = %49, %2
%8 = load i32, i32* %5
%9 = load i32, i32* %4
%10 = sub nsw i32 %9, 1
%11 = icmp slt i32 %8, %10
br i1 %11, label %12, label %52
12: ; preds = %7
store i32 0, i32* %6
br label %13
13: ; preds = %45, %12
%14 = load i32, i32* %6
%15 = load i32, i32* %4
%16 = sub nsw i32 %15, 1
%17 = load i32, i32* %5
%18 = sub nsw i32 %16, %17
%19 = icmp slt i32 %14, %18
br i1 %19, label %20, label %48
20: ; preds = %13
%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* %6
%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 = icmp sgt i32 %25, %31
br i1 %32, label %33, label %44
33: ; preds = %20
%34 = load i32*, i32** %3
%35 = load i32, i32* %6
%36 = add nsw i32 %35, 1
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i32, i32* %34, i64 %37
%39 = load i32*, i32** %3
%40 = load i32, i32* %6
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i32, i32* %39, i64 %41
%43 = call i32 @__swap(i32* %38, i32* %42)
br label %44
44: ; preds = %33, %20
br label %45
45: ; preds = %44
%46 = load i32, i32* %6
%47 = add nsw i32 %46, 1
store i32 %47, i32* %6
br label %13
48: ; preds = %13
br label %49
49: ; preds = %48
%50 = load i32, i32* %5
%51 = add nsw i32 %50, 1
store i32 %51, i32* %5
br label %7
52: ; preds = %7
ret void
}

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