#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 *c, int n) {
  int i, j;
  for (i = 0; i < n; i++) {
    for (j = i + 1; j < n; j++) {
      if (c[i] > c[j]) {
        swap(&c[i], &c[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
cmp    -0xc(%rbp),%eax
jge    11ac <bubble_sort+0x9c>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1199 <bubble_sort+0x89>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    -0x8(%rbp),%rcx
movslq -0x14(%rbp),%rdx
cmp    (%rcx,%rdx,4),%eax
jle    1186 <bubble_sort+0x76>
mov    -0x8(%rbp),%rdi
movslq -0x10(%rbp),%rax
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    118b <bubble_sort+0x7b>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    113b <bubble_sort+0x2b>
jmp    119e <bubble_sort+0x8e>
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
sub    $0x18,%rsp
mov    %rdi,0x8(%rsp)
test   %esi,%esi
jle    11b1 <bubble_sort+0xa1>
mov    %esi,%ecx
mov    0x8(%rsp),%rax
lea    0x4(%rax),%r13
mov    $0x1,%ebp
xor    %r14d,%r14d
mov    %rcx,0x10(%rsp)
jmp    1162 <bubble_sort+0x52>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%rbp
add    $0x4,%r13
mov    0x10(%rsp),%rcx
cmp    %rcx,%r14
je     11b1 <bubble_sort+0xa1>
mov    %r14,%rax
add    $0x1,%r14
cmp    %rcx,%r14
jae    1150 <bubble_sort+0x40>
mov    0x8(%rsp),%rcx
lea    (%rcx,%rax,4),%r15
mov    0x10(%rsp),%r12
mov    %r13,%rbx
jmp    119d <bubble_sort+0x8d>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x4,%rbx
add    $0xffffffffffffffff,%r12
cmp    %r12,%rbp
je     1150 <bubble_sort+0x40>
mov    (%r15),%eax
cmp    (%rbx),%eax
jle    1190 <bubble_sort+0x80>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1030 <swap@plt>
jmp    1190 <bubble_sort+0x80>
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) {
%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 = %45, %2
%8 = load i32, i32* %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %8, %9
br i1 %10, label %11, label %48
11: ; preds = %7
%12 = load i32, i32* %5
%13 = add nsw i32 %12, 1
store i32 %13, i32* %6
br label %14
14: ; preds = %41, %11
%15 = load i32, i32* %6
%16 = load i32, i32* %4
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %44
18: ; preds = %14
%19 = load i32*, i32** %3
%20 = load i32, i32* %5
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i32, i32* %19, i64 %21
%23 = load i32, i32* %22
%24 = load i32*, i32** %3
%25 = load i32, i32* %6
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i32, i32* %24, i64 %26
%28 = load i32, i32* %27
%29 = icmp sgt i32 %23, %28
br i1 %29, label %30, label %40
30: ; preds = %18
%31 = load i32*, i32** %3
%32 = load i32, i32* %5
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i32, i32* %31, i64 %33
%35 = load i32*, i32** %3
%36 = load i32, i32* %6
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i32, i32* %35, i64 %37
%39 = call i32 @swap(i32* %34, i32* %38)
br label %40
40: ; preds = %30, %18
br label %41
41: ; preds = %40
%42 = load i32, i32* %6
%43 = add nsw i32 %42, 1
store i32 %43, i32* %6
br label %14
44: ; preds = %14
br label %45
45: ; preds = %44
%46 = load i32, i32* %5
%47 = add nsw i32 %46, 1
store i32 %47, i32* %5
br label %7
48: ; preds = %7
ret void
}

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