#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 *, double *);
void bubble_sort(double *array, size_t size) {
  for (size_t i = 0; i < size; ++i) {
    for (size_t j = 0; j < size - i - 1; ++j) {
      if (array[j] > array[j + 1]) {
        swap(array + j, array + j + 1);
      }
    }
  }
}


x86 assembly (clang, -O0):
<bubble_sort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    11cb <bubble_sort+0xbb>
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    -0x18(%rbp),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
jae    11b5 <bubble_sort+0xa5>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
ucomisd 0x8(%rax,%rcx,8),%xmm0
jbe    119f <bubble_sort+0x8f>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
mov    -0x20(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rsi
add    $0x8,%rsi
call   1030 <swap@plt>
jmp    11a4 <bubble_sort+0x94>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    113e <bubble_sort+0x2e>
jmp    11ba <bubble_sort+0xaa>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1128 <bubble_sort+0x18>
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
test   %rsi,%rsi
je     117b <bubble_sort+0x6b>
mov    %rdi,%rbx
lea    0x8(%rdi),%r15
xor    %r12d,%r12d
mov    %rsi,(%rsp)
jmp    113d <bubble_sort+0x2d>
add    $0x1,%r12
mov    (%rsp),%rsi
cmp    %rsi,%r12
je     117b <bubble_sort+0x6b>
mov    %r12,%r13
not    %r13
add    %rsi,%r13
je     1130 <bubble_sort+0x20>
xor    %ebp,%ebp
xor    %r14d,%r14d
jmp    1159 <bubble_sort+0x49>
nop
add    $0x8,%rbp
cmp    %r13,%r14
jae    1130 <bubble_sort+0x20>
movsd  (%rbx,%r14,8),%xmm0
ucomisd 0x8(%rbx,%r14,8),%xmm0
lea    0x1(%r14),%r14
jbe    1150 <bubble_sort+0x40>
lea    (%rbx,%rbp,1),%rdi
lea    (%r15,%rbp,1),%rsi
call   1030 <swap@plt>
jmp    1150 <bubble_sort+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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