#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 */
void *get_node(void *, size_t, size_t);
int /*<<< orphan*/ memswap(void *, void *, size_t);
size_t sink_to(size_t, void *, void *, size_t, size_t,
               int (*)(void const *, void const *));
void init_bheap(void *heap, size_t nmemb, size_t size,
                int (*compar)(void const *, void const *)) {
  size_t i, j, k;
  void *src, *p;
  k = nmemb / 2;
  while (k-- > 0) {
    i = k;
    src = get_node(heap, i, size);
    while (j = sink_to(i, src, heap, nmemb, size, compar), j != i) {
      p = get_node(heap, j, size);
      memswap(src, p, size);
      i = j;
      src = p;
    }
  }
}


x86 assembly (clang, -O0):
<init_bheap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
shr    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x38(%rbp)
cmp    $0x0,%rax
jbe    11f9 <init_bheap+0xc9>
mov    -0x38(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1050 <get_node@plt>
mov    %rax,-0x40(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%r8
mov    -0x20(%rbp),%r9
call   1040 <sink_to@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x28(%rbp),%rax
je     11f4 <init_bheap+0xc4>
mov    -0x8(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1050 <get_node@plt>
mov    %rax,-0x48(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <memswap@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x48(%rbp),%rax
mov    %rax,-0x40(%rbp)
jmp    118a <init_bheap+0x5a>
jmp    1154 <init_bheap+0x24>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_bheap>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
cmp    $0x2,%rsi
jae    1153 <init_bheap+0x23>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rcx,%r15
mov    %rdx,%rbx
mov    %rsi,%r13
mov    %rdi,%r12
mov    %rsi,%rbp
shr    %rbp
mov    %rsi,(%rsp)
mov    %rcx,0x8(%rsp)
jmp    117e <init_bheap+0x4e>
mov    0x10(%rsp),%rbp
test   %rbp,%rbp
mov    (%rsp),%r13
je     1144 <init_bheap+0x14>
add    $0xffffffffffffffff,%rbp
mov    %r12,%rdi
mov    %rbp,%rsi
mov    %rbx,%rdx
call   1050 <get_node@plt>
mov    %rbp,%r15
mov    %rax,%r14
mov    %rbp,%rdi
mov    %rax,%rsi
mov    %r12,%rdx
mov    %r13,%rcx
mov    %rbx,%r8
mov    0x8(%rsp),%r13
mov    %r13,%r9
call   1040 <sink_to@plt>
mov    %rbp,0x10(%rsp)
cmp    %rbp,%rax
je     1170 <init_bheap+0x40>
mov    %rax,%rbp
mov    %r13,%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r12,%rdi
mov    %rbp,%rsi
mov    %rbx,%rdx
call   1050 <get_node@plt>
mov    %rax,%r13
mov    %r14,%rdi
mov    %rax,%rsi
mov    %rbx,%rdx
call   1030 <memswap@plt>
mov    %rbp,%rdi
mov    %r13,%rsi
mov    %r12,%rdx
mov    (%rsp),%rcx
mov    %rbx,%r8
mov    %r15,%r9
call   1040 <sink_to@plt>
mov    %r13,%r14
cmp    %rbp,%rax
mov    %rax,%rbp
jne    11d0 <init_bheap+0xa0>
jmp    1170 <init_bheap+0x40>

LLVM IR (-O0):
define void @init_bheap(i8* %0, i64 %1, i64 %2, i32 (i8*, i8*)* %3) {
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i32 (i8*, i8*)*
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
%12 = alloca i8*
%13 = alloca i8*
store i8* %0, i8** %5
store i64 %1, i64* %6
store i64 %2, i64* %7
store i32 (i8*, i8*)* %3, i32 (i8*, i8*)** %8
%14 = load i64, i64* %6
%15 = udiv i64 %14, 2
store i64 %15, i64* %11
br label %16
16: ; preds = %48, %4
%17 = load i64, i64* %11
%18 = add i64 %17, -1
store i64 %18, i64* %11
%19 = icmp ugt i64 %17, 0
br i1 %19, label %20, label %49
20: ; preds = %16
%21 = load i64, i64* %11
store i64 %21, i64* %9
%22 = load i8*, i8** %5
%23 = load i64, i64* %9
%24 = load i64, i64* %7
%25 = call i8* @get_node(i8* %22, i64 %23, i64 %24)
store i8* %25, i8** %12
br label %26
26: ; preds = %37, %20
%27 = load i64, i64* %9
%28 = load i8*, i8** %12
%29 = load i8*, i8** %5
%30 = load i64, i64* %6
%31 = load i64, i64* %7
%32 = load i32 (i8*, i8*)*, i32 (i8*, i8*)** %8
%33 = call i64 @sink_to(i64 %27, i8* %28, i8* %29, i64 %30, i64 %31, i32 (i8*, i8*)* %32)
store i64 %33, i64* %10
%34 = load i64, i64* %10
%35 = load i64, i64* %9
%36 = icmp ne i64 %34, %35
br i1 %36, label %37, label %48
37: ; preds = %26
%38 = load i8*, i8** %5
%39 = load i64, i64* %10
%40 = load i64, i64* %7
%41 = call i8* @get_node(i8* %38, i64 %39, i64 %40)
store i8* %41, i8** %13
%42 = load i8*, i8** %12
%43 = load i8*, i8** %13
%44 = load i64, i64* %7
%45 = call i32 @memswap(i8* %42, i8* %43, i64 %44)
%46 = load i64, i64* %10
store i64 %46, i64* %9
%47 = load i8*, i8** %13
store i8* %47, i8** %12
br label %26
48: ; preds = %26
br label %16
49: ; preds = %16
ret void
}

LLVM IR (-O2):
define void @init_bheap(i8* %0, i64 %1, i64 %2, i32 (i8*, i8*)* %3) {
%5 = icmp ult i64 %1, 2
br i1 %5, label %23, label %6
6: ; preds = %4
%7 = lshr i64 %1, 1
br label %10
8: ; preds = %16, %10
%9 = icmp eq i64 %12, 0
br i1 %9, label %23, label %10
10: ; preds = %6, %8
%11 = phi i64 [ %12, %8 ], [ %7, %6 ]
%12 = add nsw i64 %11, -1
%13 = tail call i8* @get_node(i8* %0, i64 %12, i64 %2)
%14 = tail call i64 @sink_to(i64 %12, i8* %13, i8* %0, i64 %1, i64 %2, i32 (i8*, i8*)* %3)
%15 = icmp eq i64 %14, %12
br i1 %15, label %8, label %16
16: ; preds = %10, %16
%17 = phi i64 [ %21, %16 ], [ %14, %10 ]
%18 = phi i8* [ %19, %16 ], [ %13, %10 ]
%19 = tail call i8* @get_node(i8* %0, i64 %17, i64 %2)
%20 = tail call i32 @memswap(i8* %18, i8* %19, i64 %2)
%21 = tail call i64 @sink_to(i64 %17, i8* %19, i8* %0, i64 %1, i64 %2, i32 (i8*, i8*)* %3)
%22 = icmp eq i64 %21, %17
br i1 %22, label %8, label %16
23: ; preds = %8, %4
ret void
}