#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*/ fprintf(int /*<<< orphan*/, char *, int, int);
size_t left(int);
size_t right(int);
int /*<<< orphan*/ stderr;
void heapSanity(int *a, int i, int n) {
  if (left(i) < n)
    if (a[i] >= a[left(i)])
      heapSanity(a, left(i), n);
    else {
      int l = left(i);
      fprintf(stderr, "ERROR!! heap not sane %d %d\n", a[i], a[left(i)]);
    }
  if (right(i) < n)
    if (a[i] >= a[right(i)])
      heapSanity(a, right(i), n);
    else {
      int r = right(i);
      fprintf(stderr, "ERROR!! heap not sane %d %d\n", a[i], a[right(i)]);
    }
}


x86 assembly (clang, -O0):
<heapSanity>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0xc(%rbp),%edi
call   1030 <left@plt>
movslq -0x10(%rbp),%rcx
cmp    %rcx,%rax
jae    1211 <heapSanity+0xd1>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0xc(%rbp),%edi
call   1030 <left@plt>
mov    -0x28(%rbp),%rcx
mov    %rax,%rdx
mov    -0x1c(%rbp),%eax
cmp    (%rcx,%rdx,4),%eax
jl     11bb <heapSanity+0x7b>
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0xc(%rbp),%edi
call   1030 <left@plt>
mov    -0x30(%rbp),%rdi
mov    %eax,%esi
mov    -0x10(%rbp),%edx
call   1060 <heapSanity@plt>
jmp    120c <heapSanity+0xcc>
mov    -0xc(%rbp),%edi
call   1030 <left@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e13(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0xc(%rbp),%edi
call   1030 <left@plt>
mov    -0x40(%rbp),%edi
mov    -0x3c(%rbp),%edx
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
mov    (%rax,%rcx,4),%ecx
lea    0xdf9(%rip),%rsi
call   1050 <fprintf@plt>
jmp    1211 <heapSanity+0xd1>
mov    -0xc(%rbp),%edi
call   1040 <right@plt>
movslq -0x10(%rbp),%rcx
cmp    %rcx,%rax
jae    12d0 <heapSanity+0x190>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x44(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0xc(%rbp),%edi
call   1040 <right@plt>
mov    -0x50(%rbp),%rcx
mov    %rax,%rdx
mov    -0x44(%rbp),%eax
cmp    (%rcx,%rdx,4),%eax
jl     127a <heapSanity+0x13a>
mov    -0x8(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0xc(%rbp),%edi
call   1040 <right@plt>
mov    -0x58(%rbp),%rdi
mov    %eax,%esi
mov    -0x10(%rbp),%edx
call   1060 <heapSanity@plt>
jmp    12cb <heapSanity+0x18b>
mov    -0xc(%rbp),%edi
call   1040 <right@plt>
mov    %eax,-0x18(%rbp)
mov    0x2d54(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x68(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x64(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0xc(%rbp),%edi
call   1040 <right@plt>
mov    -0x68(%rbp),%edi
mov    -0x64(%rbp),%edx
mov    %rax,%rcx
mov    -0x60(%rbp),%rax
mov    (%rax,%rcx,4),%ecx
lea    0xd3a(%rip),%rsi
call   1050 <fprintf@plt>
jmp    12d0 <heapSanity+0x190>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<heapSanity>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %rdi,%r14
mov    %edx,0x4(%rsp)
movslq %edx,%r15
nopw   0x0(%rax,%rax,1)
mov    %ebx,%edi
call   1030 <left@plt>
movslq %ebx,%r12
cmp    %r15,%rax
jae    11d1 <heapSanity+0x91>
mov    %r15,%rbp
mov    (%r14,%r12,4),%r15d
mov    %r12d,%edi
call   1030 <left@plt>
mov    (%r14,%rax,4),%r13d
mov    %r12d,%edi
call   1030 <left@plt>
cmp    %r13d,%r15d
jge    11c0 <heapSanity+0x80>
mov    0x2e4a(%rip),%rax
mov    (%rax),%r13d
mov    (%r14,%r12,4),%r15d
mov    %r12d,%edi
call   1030 <left@plt>
mov    (%r14,%rax,4),%ecx
mov    %r13d,%edi
lea    0xe4d(%rip),%rsi
mov    %r15d,%edx
call   1050 <fprintf@plt>
jmp    11ce <heapSanity+0x8e>
nopl   (%rax)
mov    %r14,%rdi
mov    %eax,%esi
mov    0x4(%rsp),%edx
call   1060 <heapSanity@plt>
mov    %rbp,%r15
mov    %ebx,%edi
call   1040 <right@plt>
cmp    %r15,%rax
jae    11fd <heapSanity+0xbd>
mov    (%r14,%r12,4),%ebp
mov    %ebx,%edi
call   1040 <right@plt>
cmp    (%r14,%rax,4),%ebp
jl     120c <heapSanity+0xcc>
mov    %ebx,%edi
call   1040 <right@plt>
mov    %rax,%rbx
jmp    1160 <heapSanity+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %ebx,%edi
call   1040 <right@plt>
mov    0x2dc6(%rip),%rax
mov    (%rax),%r15d
mov    (%r14,%r12,4),%ebp
mov    %ebx,%edi
call   1040 <right@plt>
mov    (%r14,%rax,4),%ecx
lea    0xdcd(%rip),%rsi
mov    %r15d,%edi
mov    %ebp,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <fprintf@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [29 x i8] c"ERROR!! heap not sane %d %d\0A\00"
define void @heapSanity(i32* %0, i32 %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%9 = load i32, i32* %5
%10 = call i64 @left(i32 %9)
%11 = load i32, i32* %6
%12 = sext i32 %11 to i64
%13 = icmp ult i64 %10, %12
br i1 %13, label %14, label %49
14: ; preds = %3
%15 = load i32*, i32** %4
%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** %4
%21 = load i32, i32* %5
%22 = call i64 @left(i32 %21)
%23 = getelementptr inbounds i32, i32* %20, i64 %22
%24 = load i32, i32* %23
%25 = icmp sge i32 %19, %24
br i1 %25, label %26, label %32
26: ; preds = %14
%27 = load i32*, i32** %4
%28 = load i32, i32* %5
%29 = call i64 @left(i32 %28)
%30 = trunc i64 %29 to i32
%31 = load i32, i32* %6
br label %48
32: ; preds = %14
%33 = load i32, i32* %5
%34 = call i64 @left(i32 %33)
%35 = trunc i64 %34 to i32
store i32 %35, i32* %7
%36 = load i32, i32* @stderr
%37 = load i32*, i32** %4
%38 = load i32, i32* %5
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i32, i32* %37, i64 %39
%41 = load i32, i32* %40
%42 = load i32*, i32** %4
%43 = load i32, i32* %5
%44 = call i64 @left(i32 %43)
%45 = getelementptr inbounds i32, i32* %42, i64 %44
%46 = load i32, i32* %45
%47 = call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %41, i32 %46)
br label %48
48: ; preds = %32, %26
br label %49
49: ; preds = %48, %3
%50 = load i32, i32* %5
%51 = call i64 @right(i32 %50)
%52 = load i32, i32* %6
%53 = sext i32 %52 to i64
%54 = icmp ult i64 %51, %53
br i1 %54, label %55, label %90
55: ; preds = %49
%56 = load i32*, i32** %4
%57 = load i32, i32* %5
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i32, i32* %56, i64 %58
%60 = load i32, i32* %59
%61 = load i32*, i32** %4
%62 = load i32, i32* %5
%63 = call i64 @right(i32 %62)
%64 = getelementptr inbounds i32, i32* %61, i64 %63
%65 = load i32, i32* %64
%66 = icmp sge i32 %60, %65
br i1 %66, label %67, label %73
67: ; preds = %55
%68 = load i32*, i32** %4
%69 = load i32, i32* %5
%70 = call i64 @right(i32 %69)
%71 = trunc i64 %70 to i32
%72 = load i32, i32* %6
br label %89
73: ; preds = %55
%74 = load i32, i32* %5
%75 = call i64 @right(i32 %74)
%76 = trunc i64 %75 to i32
store i32 %76, i32* %8
%77 = load i32, i32* @stderr
%78 = load i32*, i32** %4
%79 = load i32, i32* %5
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds i32, i32* %78, i64 %80
%82 = load i32, i32* %81
%83 = load i32*, i32** %4
%84 = load i32, i32* %5
%85 = call i64 @right(i32 %84)
%86 = getelementptr inbounds i32, i32* %83, i64 %85
%87 = load i32, i32* %86
%88 = call i32 @fprintf(i32 %77, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %82, i32 %87)
br label %89
89: ; preds = %73, %67
br label %90
90: ; preds = %89, %49
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [29 x i8] c"ERROR!! heap not sane %d %d\0A\00"
define void @heapSanity(i32* %0, i32 %1, i32 %2) {
%4 = sext i32 %2 to i64
br label %5
5: ; preds = %38, %3
%6 = phi i32 [ %1, %3 ], [ %40, %38 ]
%7 = tail call i64 @left(i32 %6)
%8 = icmp ult i64 %7, %4
br i1 %8, label %9, label %27
9: ; preds = %5
%10 = sext i32 %6 to i64
%11 = getelementptr inbounds i32, i32* %0, i64 %10
%12 = load i32, i32* %11
%13 = tail call i64 @left(i32 %6)
%14 = getelementptr inbounds i32, i32* %0, i64 %13
%15 = load i32, i32* %14
%16 = icmp slt i32 %12, %15
%17 = tail call i64 @left(i32 %6)
br i1 %16, label %20, label %18
18: ; preds = %9
%19 = trunc i64 %17 to i32
tail call void @heapSanity(i32* %0, i32 %19, i32 %2)
br label %27
20: ; preds = %9
%21 = load i32, i32* @stderr
%22 = load i32, i32* %11
%23 = tail call i64 @left(i32 %6)
%24 = getelementptr inbounds i32, i32* %0, i64 %23
%25 = load i32, i32* %24
%26 = tail call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %22, i32 %25)
br label %27
27: ; preds = %18, %20, %5
%28 = tail call i64 @right(i32 %6)
%29 = icmp ult i64 %28, %4
br i1 %29, label %30, label %50
30: ; preds = %27
%31 = sext i32 %6 to i64
%32 = getelementptr inbounds i32, i32* %0, i64 %31
%33 = load i32, i32* %32
%34 = tail call i64 @right(i32 %6)
%35 = getelementptr inbounds i32, i32* %0, i64 %34
%36 = load i32, i32* %35
%37 = icmp slt i32 %33, %36
br i1 %37, label %41, label %38
38: ; preds = %30
%39 = tail call i64 @right(i32 %6)
%40 = trunc i64 %39 to i32
br label %5
41: ; preds = %30
%42 = getelementptr inbounds i32, i32* %0, i64 %31
%43 = tail call i64 @right(i32 %6)
%44 = load i32, i32* @stderr
%45 = load i32, i32* %42
%46 = tail call i64 @right(i32 %6)
%47 = getelementptr inbounds i32, i32* %0, i64 %46
%48 = load i32, i32* %47
%49 = tail call i32 @fprintf(i32 %44, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %45, i32 %48)
br label %50
50: ; preds = %27, %41
ret void
}