#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 */
scalar_t__ compare_double(double, double);
void insertion_sort_double(double array[], int count) {
  int i = 0, j = 0, tmp = 0;
  for (i = 1; i < count; i++) {
    j = i;
    do {
      if (compare_double(array[j], array[j - 1]) < 0) {
        tmp = array[j];
        array[j] = array[j - 1];
        array[j - 1] = tmp;
      }
      j--;
    } while ((j > 0) && (array[j] < array[j - 1]));
  }
}


x86 assembly (clang, -O0):
<insertion_sort_double>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x1,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1220 <insertion_sort_double+0x110>
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm1
call   1030 <compare_double@plt>
cmp    $0x0,%rax
jge    11c1 <insertion_sort_double+0xb1>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
cvttsd2si (%rax,%rcx,8),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
cvtsi2sdl -0x18(%rbp),%xmm0
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x14(%rbp)
mov    %al,-0x19(%rbp)
jle    1202 <insertion_sort_double+0xf2>
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
seta   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    114d <insertion_sort_double+0x3d>
jmp    1212 <insertion_sort_double+0x102>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    113b <insertion_sort_double+0x2b>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<insertion_sort_double>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x2,%esi
jl     11bb <insertion_sort_double+0xab>
mov    %rdi,%r13
mov    %esi,%r14d
mov    $0x1,%r15d
mov    $0xffffffff,%r12d
jmp    114d <insertion_sort_double+0x3d>
nopl   0x0(%rax,%rax,1)
add    $0x1,%r15
add    $0x1,%r12
cmp    %r14,%r15
je     11bb <insertion_sort_double+0xab>
movsd  0x0(%r13,%r15,8),%xmm0
mov    %r12,%rbx
mov    %r15,%rbp
nopw   0x0(%rax,%rax,1)
movsd  -0x8(%r13,%rbp,8),%xmm1
call   1030 <compare_double@plt>
test   %rax,%rax
jns    1195 <insertion_sort_double+0x85>
movsd  -0x8(%r13,%rbp,8),%xmm0
movsd  0x0(%r13,%rbp,8),%xmm1
cvttpd2dq %xmm1,%xmm1
movsd  %xmm0,0x0(%r13,%rbp,8)
cvtdq2pd %xmm1,%xmm0
movlpd %xmm0,-0x8(%r13,%rbp,8)
cmp    $0x2,%rbp
jl     1140 <insertion_sort_double+0x30>
movsd  -0x8(%r13,%rbp,8),%xmm0
mov    %ebx,%eax
movsd  0x0(%r13,%rax,8),%xmm1
add    $0xffffffffffffffff,%rbx
add    $0xffffffffffffffff,%rbp
ucomisd %xmm0,%xmm1
ja     1160 <insertion_sort_double+0x50>
jmp    1140 <insertion_sort_double+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @insertion_sort_double(double* %0, i32 %1) {
%3 = alloca double*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store double* %0, double** %3
store i32 %1, i32* %4
store i32 0, i32* %5
store i32 0, i32* %6
store i32 0, i32* %7
store i32 1, i32* %5
br label %8
8: ; preds = %74, %2
%9 = load i32, i32* %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %77
12: ; preds = %8
%13 = load i32, i32* %5
store i32 %13, i32* %6
br label %14
14: ; preds = %71, %12
%15 = load double*, double** %3
%16 = load i32, i32* %6
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds double, double* %15, i64 %17
%19 = load double, double* %18
%20 = load double*, double** %3
%21 = load i32, i32* %6
%22 = sub nsw i32 %21, 1
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds double, double* %20, i64 %23
%25 = load double, double* %24
%26 = call i64 @compare_double(double %19, double %25)
%27 = icmp slt i64 %26, 0
br i1 %27, label %28, label %52
28: ; preds = %14
%29 = load double*, double** %3
%30 = load i32, i32* %6
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds double, double* %29, i64 %31
%33 = load double, double* %32
%34 = fptosi double %33 to i32
store i32 %34, i32* %7
%35 = load double*, double** %3
%36 = load i32, i32* %6
%37 = sub nsw i32 %36, 1
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds double, double* %35, i64 %38
%40 = load double, double* %39
%41 = load double*, double** %3
%42 = load i32, i32* %6
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds double, double* %41, i64 %43
store double %40, double* %44
%45 = load i32, i32* %7
%46 = sitofp i32 %45 to double
%47 = load double*, double** %3
%48 = load i32, i32* %6
%49 = sub nsw i32 %48, 1
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds double, double* %47, i64 %50
store double %46, double* %51
br label %52
52: ; preds = %28, %14
%53 = load i32, i32* %6
%54 = add nsw i32 %53, -1
store i32 %54, i32* %6
br label %55
55: ; preds = %52
%56 = load i32, i32* %6
%57 = icmp sgt i32 %56, 0
br i1 %57, label %58, label %71
58: ; preds = %55
%59 = load double*, double** %3
%60 = load i32, i32* %6
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds double, double* %59, i64 %61
%63 = load double, double* %62
%64 = load double*, double** %3
%65 = load i32, i32* %6
%66 = sub nsw i32 %65, 1
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds double, double* %64, i64 %67
%69 = load double, double* %68
%70 = fcmp olt double %63, %69
br label %71
71: ; preds = %58, %55
%72 = phi i1 [ false, %55 ], [ %70, %58 ]
br i1 %72, label %14, label %73
73: ; preds = %71
br label %74
74: ; preds = %73
%75 = load i32, i32* %5
%76 = add nsw i32 %75, 1
store i32 %76, i32* %5
br label %8
77: ; preds = %8
ret void
}

LLVM IR (-O2):
define void @insertion_sort_double(double* nocapture %0, i32 %1) {
%3 = icmp sgt i32 %1, 1
br i1 %3, label %4, label %36
4: ; preds = %2
%5 = zext i32 %1 to i64
br label %6
6: ; preds = %4, %33
%7 = phi i64 [ 1, %4 ], [ %34, %33 ]
%8 = getelementptr inbounds double, double* %0, i64 %7
%9 = load double, double* %8
br label %10
10: ; preds = %6, %26
%11 = phi double [ %9, %6 ], [ %27, %26 ]
%12 = phi i64 [ %7, %6 ], [ %14, %26 ]
%13 = getelementptr inbounds double, double* %0, i64 %12
%14 = add nsw i64 %12, -1
%15 = getelementptr inbounds double, double* %0, i64 %14
%16 = load double, double* %15
%17 = tail call i64 @compare_double(double %11, double %16)
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %24
19: ; preds = %10
%20 = load double, double* %13
%21 = fptosi double %20 to i32
%22 = load double, double* %15
store double %22, double* %13
%23 = sitofp i32 %21 to double
store double %23, double* %15
br label %24
24: ; preds = %19, %10
%25 = icmp sgt i64 %12, 1
br i1 %25, label %26, label %33
26: ; preds = %24
%27 = load double, double* %15
%28 = add nuw i64 %12, 4294967294
%29 = and i64 %28, 4294967295
%30 = getelementptr inbounds double, double* %0, i64 %29
%31 = load double, double* %30
%32 = fcmp olt double %27, %31
br i1 %32, label %10, label %33
33: ; preds = %24, %26
%34 = add nuw nsw i64 %7, 1
%35 = icmp eq i64 %34, %5
br i1 %35, label %36, label %6
36: ; preds = %33, %2
ret void
}