#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(int *, int, int);
void siftup(int *head, int cur_node) {
  int parent = 0;
  int i = cur_node;
  while (1) {
    if (i == 1) {
      break;
    }
    parent = i / 2;
    if (head[parent] <= head[i]) {
      break;
    }
    swap(head, parent, i);
    i = parent;
  }
}


x86 assembly (clang, -O0):
<siftup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x1,-0x14(%rbp)
jne    113b <siftup+0x2b>
jmp    1184 <siftup+0x74>
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    -0x8(%rbp),%rcx
movslq -0x14(%rbp),%rdx
cmp    (%rcx,%rdx,4),%eax
jg     116a <siftup+0x5a>
jmp    1184 <siftup+0x74>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1030 <swap@plt>
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    112c <siftup+0x1c>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<siftup>:
push   %rbp
push   %r14
push   %rbx
cmp    $0x1,%esi
je     114d <siftup+0x3d>
mov    %esi,%ebx
mov    %rdi,%r14
mov    %esi,%ebp
shr    $0x1f,%ebp
add    %ebx,%ebp
sar    %ebp
movslq %ebp,%rax
mov    (%r14,%rax,4),%eax
movslq %ebx,%rcx
cmp    (%r14,%rcx,4),%eax
jle    114d <siftup+0x3d>
mov    %r14,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
call   1030 <swap@plt>
and    $0xfffffffe,%ebx
cmp    $0x2,%ebx
mov    %ebp,%ebx
jne    1120 <siftup+0x10>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @siftup(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
store i32 0, i32* %5
%7 = load i32, i32* %4
store i32 %7, i32* %6
br label %8
8: ; preds = %2, %27
%9 = load i32, i32* %6
%10 = icmp eq i32 %9, 1
br i1 %10, label %11, label %12
11: ; preds = %8
br label %33
12: ; preds = %8
%13 = load i32, i32* %6
%14 = sdiv i32 %13, 2
store i32 %14, i32* %5
%15 = load i32*, i32** %3
%16 = load i32, i32* %5
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i32, i32* %15, i64 %17
%19 = load i32, i32* %18
%20 = load i32*, i32** %3
%21 = load i32, i32* %6
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i32, i32* %20, i64 %22
%24 = load i32, i32* %23
%25 = icmp sle i32 %19, %24
br i1 %25, label %26, label %27
26: ; preds = %12
br label %33
27: ; preds = %12
%28 = load i32*, i32** %3
%29 = load i32, i32* %5
%30 = load i32, i32* %6
%31 = call i32 @swap(i32* %28, i32 %29, i32 %30)
%32 = load i32, i32* %5
store i32 %32, i32* %6
br label %8
33: ; preds = %26, %11
ret void
}

LLVM IR (-O2):
define void @siftup(i32* %0, i32 %1) {
%3 = icmp eq i32 %1, 1
br i1 %3, label %18, label %4
4: ; preds = %2, %14
%5 = phi i32 [ %6, %14 ], [ %1, %2 ]
%6 = sdiv i32 %5, 2
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds i32, i32* %0, i64 %7
%9 = load i32, i32* %8
%10 = sext i32 %5 to i64
%11 = getelementptr inbounds i32, i32* %0, i64 %10
%12 = load i32, i32* %11
%13 = icmp sgt i32 %9, %12
br i1 %13, label %14, label %18
14: ; preds = %4
%15 = tail call i32 @swap(i32* %0, i32 %6, i32 %5)
%16 = and i32 %5, -2
%17 = icmp eq i32 %16, 2
br i1 %17, label %18, label %4
18: ; preds = %14, %4, %2
ret void
}