#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*/ siftDown(double *, int, int);
void sort_double(int count, double ra[]) {
  int start, end;
  for (start = (count - 2) / 2; start >= 0; start--) {
    siftDown(ra, start, count);
  }
  for (end = count - 1; end > 0; end--) {
    do {
      double t = ra[end];
      (ra[end]) = ra[0];
      (ra[0]) = t;
    } while (0);
    siftDown(ra, 0, end);
  }
}


x86 assembly (clang, -O0):
<sort_double>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%eax
sub    $0x2,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     1157 <sort_double+0x47>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x4(%rbp),%edx
call   1030 <siftDown@plt>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    1130 <sort_double+0x20>
mov    -0x4(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jle    11bf <sort_double+0xaf>
jmp    116f <sort_double+0x5f>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
movsd  -0x20(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%edx
xor    %esi,%esi
call   1030 <siftDown@plt>
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    1160 <sort_double+0x50>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sort_double>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %edi,%edi
jle    1191 <sort_double+0x81>
mov    %rsi,%r15
mov    %edi,%r14d
lea    -0x2(%r14),%eax
shr    $0x1f,%eax
lea    (%r14,%rax,1),%ebp
add    $0xfffffffe,%ebp
sar    %ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %ebp,%esi
mov    %r14d,%edx
call   1030 <siftDown@plt>
add    $0xffffffff,%ebp
jb     1140 <sort_double+0x30>
cmp    $0x2,%r14d
jl     1191 <sort_double+0x81>
mov    %r14d,%ebp
nopl   0x0(%rax,%rax,1)
lea    -0x1(%rbp),%rbx
mov    %ebx,%eax
movsd  (%r15,%rax,8),%xmm0
movsd  (%r15),%xmm1
movsd  %xmm1,(%r15,%rax,8)
movsd  %xmm0,(%r15)
mov    %r15,%rdi
xor    %esi,%esi
mov    %ebx,%edx
call   1030 <siftDown@plt>
cmp    $0x2,%rbp
mov    %rbx,%rbp
ja     1160 <sort_double+0x50>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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