#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 heap {
  int dummy;
};

/* Variables and functions */
size_t P(size_t);
scalar_t__ leq(struct heap *, size_t, size_t);
int /*<<< orphan*/ swap(struct heap *, size_t, size_t);
void sift_up(struct heap *h, size_t i) {
  for (; i && leq(h, i, P(i)); i = P(i)) {
    swap(h, i, P(i));
  }
}


x86 assembly (clang, -O0):
<sift_up>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x10(%rbp)
mov    %al,-0x11(%rbp)
je     1183 <sift_up+0x53>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <P@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    %rax,%rdx
call   1040 <leq@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    1193 <sift_up+0x63>
jmp    11ce <sift_up+0x9e>
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <P@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    %rax,%rdx
call   1050 <swap@plt>
mov    -0x10(%rbp),%rdi
call   1030 <P@plt>
mov    %rax,-0x10(%rbp)
jmp    1140 <sift_up+0x10>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sift_up>:
push   %r14
push   %rbx
push   %rax
test   %rsi,%rsi
je     1181 <sift_up+0x51>
mov    %rsi,%rbx
mov    %rdi,%r14
nop
mov    %rbx,%rdi
call   1030 <P@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1040 <leq@plt>
test   %rax,%rax
je     1181 <sift_up+0x51>
mov    %rbx,%rdi
call   1030 <P@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1050 <swap@plt>
mov    %rbx,%rdi
call   1030 <P@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1140 <sift_up+0x10>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.heap = type { i32 }
define void @sift_up(%struct.heap* %0, i64 %1) {
%3 = alloca %struct.heap*
%4 = alloca i64
store %struct.heap* %0, %struct.heap** %3
store i64 %1, i64* %4
br label %5
5: ; preds = %23, %2
%6 = load i64, i64* %4
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %15
8: ; preds = %5
%9 = load %struct.heap*, %struct.heap** %3
%10 = load i64, i64* %4
%11 = load i64, i64* %4
%12 = call i64 @P(i64 %11)
%13 = call i64 @leq(%struct.heap* %9, i64 %10, i64 %12)
%14 = icmp ne i64 %13, 0
br label %15
15: ; preds = %8, %5
%16 = phi i1 [ false, %5 ], [ %14, %8 ]
br i1 %16, label %17, label %26
17: ; preds = %15
%18 = load %struct.heap*, %struct.heap** %3
%19 = load i64, i64* %4
%20 = load i64, i64* %4
%21 = call i64 @P(i64 %20)
%22 = call i32 @swap(%struct.heap* %18, i64 %19, i64 %21)
br label %23
23: ; preds = %17
%24 = load i64, i64* %4
%25 = call i64 @P(i64 %24)
store i64 %25, i64* %4
br label %5
26: ; preds = %15
ret void
}

LLVM IR (-O2):
%struct.heap = type { i32 }
define void @sift_up(%struct.heap* %0, i64 %1) {
%3 = icmp eq i64 %1, 0
br i1 %3, label %14, label %4
4: ; preds = %2, %9
%5 = phi i64 [ %12, %9 ], [ %1, %2 ]
%6 = tail call i64 @P(i64 %5)
%7 = tail call i64 @leq(%struct.heap* %0, i64 %5, i64 %6)
%8 = icmp eq i64 %7, 0
br i1 %8, label %14, label %9
9: ; preds = %4
%10 = tail call i64 @P(i64 %5)
%11 = tail call i32 @swap(%struct.heap* %0, i64 %5, i64 %10)
%12 = tail call i64 @P(i64 %5)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %4
14: ; preds = %4, %9, %2
ret void
}