#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*/ assert(int);
int /*<<< orphan*/ max_heapify(int *, size_t, size_t);
void build_max_heap(int arr[], size_t arr_sz) {
  assert(arr_sz > 0);
  size_t i = (arr_sz - 1) / 2;
  while (i > 0) {
    max_heapify(arr, arr_sz, i);
    i--;
  }
  max_heapify(arr, arr_sz, i);
}


x86 assembly (clang, -O0):
<build_max_heap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
seta   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x10(%rbp),%rax
sub    $0x1,%rax
shr    $0x1,%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jbe    117f <build_max_heap+0x5f>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <max_heapify@plt>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    1152 <build_max_heap+0x32>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <max_heapify@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<build_max_heap>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
xor    %edi,%edi
mov    %rsi,%rbx
add    $0xffffffffffffffff,%rbx
setb   %dil
call   1030 <assert@plt>
cmp    $0x2,%rbx
jb     1164 <build_max_heap+0x44>
shr    %rbx
cs nopw 0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1040 <max_heapify@plt>
add    $0xffffffffffffffff,%rbx
jne    1150 <build_max_heap+0x30>
mov    %r14,%rdi
mov    %r15,%rsi
xor    %edx,%edx
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <max_heapify@plt>

LLVM IR (-O0):
define void @build_max_heap(i32* %0, i64 %1) {
%3 = alloca i32*
%4 = alloca i64
%5 = alloca i64
store i32* %0, i32** %3
store i64 %1, i64* %4
%6 = load i64, i64* %4
%7 = icmp ugt i64 %6, 0
%8 = zext i1 %7 to i32
%9 = call i32 @assert(i32 %8)
%10 = load i64, i64* %4
%11 = sub i64 %10, 1
%12 = udiv i64 %11, 2
store i64 %12, i64* %5
br label %13
13: ; preds = %16, %2
%14 = load i64, i64* %5
%15 = icmp ugt i64 %14, 0
br i1 %15, label %16, label %23
16: ; preds = %13
%17 = load i32*, i32** %3
%18 = load i64, i64* %4
%19 = load i64, i64* %5
%20 = call i32 @max_heapify(i32* %17, i64 %18, i64 %19)
%21 = load i64, i64* %5
%22 = add i64 %21, -1
store i64 %22, i64* %5
br label %13
23: ; preds = %13
%24 = load i32*, i32** %3
%25 = load i64, i64* %4
%26 = load i64, i64* %5
%27 = call i32 @max_heapify(i32* %24, i64 %25, i64 %26)
ret void
}

LLVM IR (-O2):
define void @build_max_heap(i32* %0, i64 %1) {
%3 = icmp ne i64 %1, 0
%4 = zext i1 %3 to i32
%5 = tail call i32 @assert(i32 %4)
%6 = add i64 %1, -1
%7 = icmp ult i64 %6, 2
br i1 %7, label %15, label %8
8: ; preds = %2
%9 = lshr i64 %6, 1
br label %10
10: ; preds = %8, %10
%11 = phi i64 [ %13, %10 ], [ %9, %8 ]
%12 = tail call i32 @max_heapify(i32* %0, i64 %1, i64 %11)
%13 = add i64 %11, -1
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %10
15: ; preds = %10, %2
%16 = tail call i32 @max_heapify(i32* %0, i64 %1, i64 0)
ret void
}