#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(double *, int, int);
void bubble_sort(double array[], int n) {
  int i, j;
  for (i = n - 1; i > 0; i--) {
    for (j = 0; j < i; j++) {
      if (array[j] > array[j + 1]) {
        swap(array, 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    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jle    119f <bubble_sort+0x8f>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    118c <bubble_sort+0x7c>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
ucomisd (%rax,%rcx,8),%xmm0
jbe    1179 <bubble_sort+0x69>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1030 <swap@plt>
jmp    117e <bubble_sort+0x6e>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1139 <bubble_sort+0x29>
jmp    1191 <bubble_sort+0x81>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    1128 <bubble_sort+0x18>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bubble_sort>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
cmp    $0x2,%esi
jl     1179 <bubble_sort+0x69>
mov    %esi,%r14d
mov    %rdi,%r13
lea    -0x1(%r14),%r15d
jmp    113a <bubble_sort+0x2a>
nopw   0x0(%rax,%rax,1)
add    $0xffffffffffffffff,%r15
cmp    $0x3,%r12d
jl     1179 <bubble_sort+0x69>
mov    %r14d,%r12d
lea    -0x1(%r12),%r14d
xor    %edx,%edx
jmp    1158 <bubble_sort+0x48>
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdx
cmp    %rbx,%r15
je     1130 <bubble_sort+0x20>
movsd  0x0(%r13,%rdx,8),%xmm0
lea    0x1(%rdx),%rbx
ucomisd 0x8(%r13,%rdx,8),%xmm0
jbe    1150 <bubble_sort+0x40>
mov    %r13,%rdi
mov    %r14d,%esi
call   1030 <swap@plt>
jmp    1150 <bubble_sort+0x40>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @bubble_sort(double* %0, i32 %1) {
%3 = alloca double*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store double* %0, double** %3
store i32 %1, i32* %4
%7 = load i32, i32* %4
%8 = sub nsw i32 %7, 1
store i32 %8, i32* %5
br label %9
9: ; preds = %40, %2
%10 = load i32, i32* %5
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %43
12: ; preds = %9
store i32 0, i32* %6
br label %13
13: ; preds = %36, %12
%14 = load i32, i32* %6
%15 = load i32, i32* %5
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %39
17: ; preds = %13
%18 = load double*, double** %3
%19 = load i32, i32* %6
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds double, double* %18, i64 %20
%22 = load double, double* %21
%23 = load double*, double** %3
%24 = load i32, i32* %6
%25 = add nsw i32 %24, 1
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds double, double* %23, i64 %26
%28 = load double, double* %27
%29 = fcmp ogt double %22, %28
br i1 %29, label %30, label %35
30: ; preds = %17
%31 = load double*, double** %3
%32 = load i32, i32* %5
%33 = load i32, i32* %6
%34 = call i32 @swap(double* %31, i32 %32, i32 %33)
br label %35
35: ; preds = %30, %17
br label %36
36: ; preds = %35
%37 = load i32, i32* %6
%38 = add nsw i32 %37, 1
store i32 %38, i32* %6
br label %13
39: ; preds = %13
br label %40
40: ; preds = %39
%41 = load i32, i32* %5
%42 = add nsw i32 %41, -1
store i32 %42, i32* %5
br label %9
43: ; preds = %9
ret void
}

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