#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*/ Rprintf(char *, int, int);
int /*<<< orphan*/ swap(int, int, double *, int *, int *, int);
void uptoleave(int outvirt, int k, double *window, int *outlist, int *nrlist,
               int print_level) {
  int childl, childr;
  if (print_level >= 2)
    Rprintf("\n uptoleave(%d, %d)\n   ", outvirt, k);
  for (;;) {
    childl = outvirt * 2;
    childr = childl + 1;
    if (window[childl + k] > window[childr + k])
      childl = childr;
    if (window[outvirt + k] <= window[childl + k])
      break;
    swap(outvirt + k, childl + k, window, outlist, nrlist, print_level);
    outvirt = childl;
  }
}


x86 assembly (clang, -O0):
<uptoleave>:
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)
cmpl   $0x2,-0x24(%rbp)
jl     115a <uptoleave+0x3a>
mov    -0x4(%rbp),%esi
mov    -0x8(%rbp),%edx
lea    0xeab(%rip),%rdi
call   1030 <Rprintf@plt>
jmp    115f <uptoleave+0x3f>
mov    -0x4(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%ecx
add    -0x8(%rbp),%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
mov    -0x2c(%rbp),%ecx
add    -0x8(%rbp),%ecx
movslq %ecx,%rcx
ucomisd (%rax,%rcx,8),%xmm0
jbe    11a1 <uptoleave+0x81>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x4(%rbp),%ecx
add    -0x8(%rbp),%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%ecx
add    -0x8(%rbp),%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
ucomisd %xmm1,%xmm0
jb     11d4 <uptoleave+0xb4>
jmp    1200 <uptoleave+0xe0>
mov    -0x4(%rbp),%edi
add    -0x8(%rbp),%edi
mov    -0x28(%rbp),%esi
add    -0x8(%rbp),%esi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%r8
mov    -0x24(%rbp),%r9d
call   1040 <swap@plt>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    115f <uptoleave+0x3f>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<uptoleave>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9d,%r12d
mov    %r8,(%rsp)
mov    %rcx,%r15
mov    %rdx,%rbx
mov    %esi,%r13d
mov    %edi,%ebp
cmp    $0x2,%r9d
jl     1177 <uptoleave+0x57>
lea    0xeb6(%rip),%rdi
mov    %ebp,%esi
mov    %r13d,%edx
call   1030 <Rprintf@plt>
jmp    1177 <uptoleave+0x57>
cs nopw 0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %r15,%rcx
mov    (%rsp),%r8
mov    %r12d,%r9d
call   1040 <swap@plt>
mov    %r14d,%ebp
lea    0x0(%r13,%rbp,2),%eax
cltq
movsd  (%rbx,%rax,8),%xmm0
lea    0x1(%r13,%rbp,2),%eax
cltq
ucomisd (%rbx,%rax,8),%xmm0
ja     11a0 <uptoleave+0x80>
lea    0x0(%rbp,%rbp,1),%r14d
jmp    11a5 <uptoleave+0x85>
nopl   0x0(%rax,%rax,1)
lea    0x1(%rbp,%rbp,1),%r14d
add    %r13d,%ebp
movslq %ebp,%rax
lea    (%r14,%r13,1),%esi
movslq %esi,%rcx
movsd  (%rbx,%rcx,8),%xmm0
ucomisd (%rbx,%rax,8),%xmm0
jb     1160 <uptoleave+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [24 x i8] c"\0A uptoleave(%d, %d)\0A \00"
define void @uptoleave(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* %12
%16 = icmp sge i32 %15, 2
br i1 %16, label %17, label %21
17: ; preds = %6
%18 = load i32, i32* %7
%19 = load i32, i32* %8
%20 = call i32 @Rprintf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %18, i32 %19)
br label %21
21: ; preds = %17, %6
br label %22
22: ; preds = %61, %21
%23 = load i32, i32* %7
%24 = mul nsw i32 %23, 2
store i32 %24, i32* %13
%25 = load i32, i32* %13
%26 = add nsw i32 %25, 1
store i32 %26, i32* %14
%27 = load double*, double** %9
%28 = load i32, i32* %13
%29 = load i32, i32* %8
%30 = add nsw i32 %28, %29
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds double, double* %27, i64 %31
%33 = load double, double* %32
%34 = load double*, double** %9
%35 = load i32, i32* %14
%36 = load i32, i32* %8
%37 = add nsw i32 %35, %36
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds double, double* %34, i64 %38
%40 = load double, double* %39
%41 = fcmp ogt double %33, %40
br i1 %41, label %42, label %44
42: ; preds = %22
%43 = load i32, i32* %14
store i32 %43, i32* %13
br label %44
44: ; preds = %42, %22
%45 = load double*, double** %9
%46 = load i32, i32* %7
%47 = load i32, i32* %8
%48 = add nsw i32 %46, %47
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds double, double* %45, i64 %49
%51 = load double, double* %50
%52 = load double*, double** %9
%53 = load i32, i32* %13
%54 = load i32, i32* %8
%55 = add nsw i32 %53, %54
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds double, double* %52, i64 %56
%58 = load double, double* %57
%59 = fcmp ole double %51, %58
br i1 %59, label %60, label %61
60: ; preds = %44
br label %74
61: ; preds = %44
%62 = load i32, i32* %7
%63 = load i32, i32* %8
%64 = add nsw i32 %62, %63
%65 = load i32, i32* %13
%66 = load i32, i32* %8
%67 = add nsw i32 %65, %66
%68 = load double*, double** %9
%69 = load i32*, i32** %10
%70 = load i32*, i32** %11
%71 = load i32, i32* %12
%72 = call i32 @swap(i32 %64, i32 %67, double* %68, i32* %69, i32* %70, i32 %71)
%73 = load i32, i32* %13
store i32 %73, i32* %7
br label %22
74: ; preds = %60
ret void
}

LLVM IR (-O2):
@.str = [24 x i8] c"\0A uptoleave(%d, %d)\0A \00"
define void @uptoleave(i32 %0, i32 %1, double* %2, i32* %3, i32* %4, i32 %5) {
%7 = icmp sgt i32 %5, 1
br i1 %7, label %8, label %10
8: ; preds = %6
%9 = tail call i32 @Rprintf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %0, i32 %1)
br label %10
10: ; preds = %8, %6
br label %11
11: ; preds = %10, %34
%12 = phi i32 [ %24, %34 ], [ %0, %10 ]
%13 = shl nsw i32 %12, 1
%14 = or i32 %13, 1
%15 = add nsw i32 %13, %1
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds double, double* %2, i64 %16
%18 = load double, double* %17
%19 = add nsw i32 %14, %1
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds double, double* %2, i64 %20
%22 = load double, double* %21
%23 = fcmp ogt double %18, %22
%24 = select i1 %23, i32 %14, i32 %13
%25 = add nsw i32 %12, %1
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds double, double* %2, i64 %26
%28 = load double, double* %27
%29 = add nsw i32 %24, %1
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds double, double* %2, i64 %30
%32 = load double, double* %31
%33 = fcmp ugt double %28, %32
br i1 %33, label %34, label %36
34: ; preds = %11
%35 = tail call i32 @swap(i32 %25, i32 %29, double* %2, i32* %3, i32* %4, i32 %5)
br label %11
36: ; preds = %11
ret void
}