#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 insertion_sort(double array[], int n) {
  int i, j;
  for (i = 1; i < n; i++) {
    for (j = i; j > 0; j--) {
      if (array[j] < array[j - 1])
        swap(array, j, j - 1);
      else
        break;
    }
  }
}


x86 assembly (clang, -O0):
<insertion_sort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11ad <insertion_sort+0x9d>
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    119a <insertion_sort+0x8a>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
ucomisd %xmm1,%xmm0
jbe    1182 <insertion_sort+0x72>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x14(%rbp),%edx
sub    $0x1,%edx
call   1030 <swap@plt>
jmp    1187 <insertion_sort+0x77>
jmp    119a <insertion_sort+0x8a>
jmp    118c <insertion_sort+0x7c>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    1138 <insertion_sort+0x28>
jmp    119f <insertion_sort+0x8f>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1126 <insertion_sort+0x16>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<insertion_sort>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
cmp    $0x2,%esi
jl     116d <insertion_sort+0x5d>
mov    %rdi,%r14
mov    %esi,%r12d
mov    $0x1,%r13d
jmp    1139 <insertion_sort+0x29>
nopl   0x0(%rax)
add    $0x1,%r13
cmp    %r12,%r13
je     116d <insertion_sort+0x5d>
mov    %r13,%rbx
nopl   0x0(%rax)
lea    -0x1(%rbx),%eax
movsd  (%r14,%rax,8),%xmm0
ucomisd (%r14,%rbx,8),%xmm0
jbe    1130 <insertion_sort+0x20>
lea    -0x1(%rbx),%r15
mov    %r14,%rdi
mov    %ebx,%esi
mov    %r15d,%edx
call   1030 <swap@plt>
cmp    $0x1,%rbx
mov    %r15,%rbx
jg     1140 <insertion_sort+0x30>
jmp    1130 <insertion_sort+0x20>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

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