#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 */
struct bheap_t {
  int dummy;
};

/* Variables and functions */
int bh_primax(struct bheap_t *, int, int);
int /*<<< orphan*/ bh_swap(struct bheap_t *, int, int);
int /*<<< orphan*/ bh_valid(struct bheap_t *, int);
void bh_siftup(struct bheap_t *bh, int node) {
  int parent;
  while (parent = ((node) >> 1), bh_valid(bh, parent)) {
    if (bh_primax(bh, node, parent) == node) {
      bh_swap(bh, parent, node);
      node = parent;
    } else
      break;
  }
}


x86 assembly (clang, -O0):
<bh_siftup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
call   1050 <bh_valid@plt>
cmp    $0x0,%eax
je     1199 <bh_siftup+0x69>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1030 <bh_primax@plt>
cmp    -0xc(%rbp),%eax
jne    118f <bh_siftup+0x5f>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1040 <bh_swap@plt>
mov    -0x10(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    1194 <bh_siftup+0x64>
jmp    1199 <bh_siftup+0x69>
jmp    113f <bh_siftup+0xf>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bh_siftup>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %rdi,%r14
mov    %esi,%ebp
sar    %ebp
mov    %ebp,%esi
call   1050 <bh_valid@plt>
test   %eax,%eax
je     1186 <bh_siftup+0x56>
nopl   0x0(%rax)
mov    %ebp,%ebx
mov    %r14,%rdi
mov    %r15d,%esi
mov    %ebp,%edx
call   1030 <bh_primax@plt>
cmp    %r15d,%eax
jne    1186 <bh_siftup+0x56>
mov    %r14,%rdi
mov    %ebx,%esi
mov    %r15d,%edx
call   1040 <bh_swap@plt>
mov    %ebx,%ebp
sar    %ebp
mov    %r14,%rdi
mov    %ebp,%esi
call   1050 <bh_valid@plt>
mov    %ebx,%r15d
test   %eax,%eax
jne    1150 <bh_siftup+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.bheap_t = type { i32 }
define void @bh_siftup(%struct.bheap_t* %0, i32 %1) {
%3 = alloca %struct.bheap_t*
%4 = alloca i32
%5 = alloca i32
store %struct.bheap_t* %0, %struct.bheap_t** %3
store i32 %1, i32* %4
br label %6
6: ; preds = %27, %2
%7 = load i32, i32* %4
%8 = ashr i32 %7, 1
store i32 %8, i32* %5
%9 = load %struct.bheap_t*, %struct.bheap_t** %3
%10 = load i32, i32* %5
%11 = call i32 @bh_valid(%struct.bheap_t* %9, i32 %10)
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %28
13: ; preds = %6
%14 = load %struct.bheap_t*, %struct.bheap_t** %3
%15 = load i32, i32* %4
%16 = load i32, i32* %5
%17 = call i32 @bh_primax(%struct.bheap_t* %14, i32 %15, i32 %16)
%18 = load i32, i32* %4
%19 = icmp eq i32 %17, %18
br i1 %19, label %20, label %26
20: ; preds = %13
%21 = load %struct.bheap_t*, %struct.bheap_t** %3
%22 = load i32, i32* %5
%23 = load i32, i32* %4
%24 = call i32 @bh_swap(%struct.bheap_t* %21, i32 %22, i32 %23)
%25 = load i32, i32* %5
store i32 %25, i32* %4
br label %27
26: ; preds = %13
br label %28
27: ; preds = %20
br label %6
28: ; preds = %26, %6
ret void
}

LLVM IR (-O2):
%struct.bheap_t = type { i32 }
define void @bh_siftup(%struct.bheap_t* %0, i32 %1) {
%3 = ashr i32 %1, 1
%4 = tail call i32 @bh_valid(%struct.bheap_t* %0, i32 %3)
%5 = icmp eq i32 %4, 0
br i1 %5, label %16, label %6
6: ; preds = %2, %11
%7 = phi i32 [ %13, %11 ], [ %3, %2 ]
%8 = phi i32 [ %7, %11 ], [ %1, %2 ]
%9 = tail call i32 @bh_primax(%struct.bheap_t* %0, i32 %8, i32 %7)
%10 = icmp eq i32 %9, %8
br i1 %10, label %11, label %16
11: ; preds = %6
%12 = tail call i32 @bh_swap(%struct.bheap_t* %0, i32 %7, i32 %8)
%13 = ashr i32 %7, 1
%14 = tail call i32 @bh_valid(%struct.bheap_t* %0, i32 %13)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %6
16: ; preds = %11, %6, %2
ret void
}