#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*/ siftup(int, int, double *, int *, int *, int);
int /*<<< orphan*/ swap(int, int, double *, int *, int *, int);
void R_heapsort(int low, int up, double *window, int *outlist, int *nrlist,
                int print_level) {
  int l, u;
  l = (up / 2) + 1;
  u = up;
  while (l > low) {
    l--;
    siftup(l, u, window, outlist, nrlist, print_level);
  }
  while (u > low) {
    swap(l, u, window, outlist, nrlist, print_level);
    u--;
    siftup(l, u, window, outlist, nrlist, print_level);
  }
}


x86 assembly (clang, -O0):
<R_heapsort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    %r9d,-0x24(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x4(%rbp),%eax
jle    118a <R_heapsort+0x6a>
mov    -0x28(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%edi
mov    -0x2c(%rbp),%esi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%r8
mov    -0x24(%rbp),%r9d
call   1030 <siftup@plt>
jmp    1155 <R_heapsort+0x35>
jmp    118f <R_heapsort+0x6f>
mov    -0x2c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jle    11df <R_heapsort+0xbf>
mov    -0x28(%rbp),%edi
mov    -0x2c(%rbp),%esi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%r8
mov    -0x24(%rbp),%r9d
call   1040 <swap@plt>
mov    -0x2c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%edi
mov    -0x2c(%rbp),%esi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%r8
mov    -0x24(%rbp),%r9d
call   1030 <siftup@plt>
jmp    118f <R_heapsort+0x6f>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<R_heapsort>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9d,%r14d
mov    %r8,%r15
mov    %rcx,%r12
mov    %rdx,%rbx
mov    %esi,%ebp
mov    %esi,%r13d
shr    $0x1f,%r13d
add    %esi,%r13d
sar    %r13d
cmp    %edi,%r13d
mov    %edi,0x4(%rsp)
jge    1160 <R_heapsort+0x40>
add    $0x1,%r13d
cmp    %edi,%ebp
jg     1190 <R_heapsort+0x70>
jmp    11c5 <R_heapsort+0xa5>
nopl   0x0(%rax)
mov    %r13d,%edi
mov    %ebp,%esi
mov    %rbx,%rdx
mov    %r12,%rcx
mov    %r15,%r8
mov    %r14d,%r9d
call   1030 <siftup@plt>
mov    0x4(%rsp),%edi
lea    -0x1(%r13),%eax
cmp    %edi,%r13d
mov    %eax,%r13d
jg     1160 <R_heapsort+0x40>
mov    %edi,%r13d
cmp    %edi,%ebp
jle    11c5 <R_heapsort+0xa5>
nopl   (%rax)
mov    %r13d,%edi
mov    %ebp,%esi
mov    %rbx,%rdx
mov    %r12,%rcx
mov    %r15,%r8
mov    %r14d,%r9d
call   1040 <swap@plt>
add    $0xffffffff,%ebp
mov    %r13d,%edi
mov    %ebp,%esi
mov    %rbx,%rdx
mov    %r12,%rcx
mov    %r15,%r8
mov    %r14d,%r9d
call   1030 <siftup@plt>
cmp    0x4(%rsp),%ebp
jg     1190 <R_heapsort+0x70>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @R_heapsort(i32 %0, i32 %1, double* %2, i32* %3, i32* %4, i32 %5) {
%7 = sdiv i32 %1, 2
%8 = add nsw i32 %7, 1
%9 = icmp slt i32 %7, %0
br i1 %9, label %10, label %13
10: ; preds = %13, %6
%11 = phi i32 [ %8, %6 ], [ %0, %13 ]
%12 = icmp sgt i32 %1, %0
br i1 %12, label %18, label %24
13: ; preds = %6, %13
%14 = phi i32 [ %15, %13 ], [ %8, %6 ]
%15 = add nsw i32 %14, -1
%16 = tail call i32 @siftup(i32 %15, i32 %1, double* %2, i32* %3, i32* %4, i32 %5)
%17 = icmp sgt i32 %15, %0
br i1 %17, label %13, label %10
18: ; preds = %10, %18
%19 = phi i32 [ %21, %18 ], [ %1, %10 ]
%20 = tail call i32 @swap(i32 %11, i32 %19, double* %2, i32* %3, i32* %4, i32 %5)
%21 = add nsw i32 %19, -1
%22 = tail call i32 @siftup(i32 %11, i32 %21, double* %2, i32* %3, i32* %4, i32 %5)
%23 = icmp sgt i32 %21, %0
br i1 %23, label %18, label %24
24: ; preds = %18, %10
ret void
}