#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 balance(int *, int);
int /*<<< orphan*/ printf(char *);
int verify_AVL(int *tree, int tree_size) {
  int i;
  for (i = 0; i < tree_size * 2 + 5; i++) {
    if (tree[i] != -1) {
      int balance_node = balance(tree, i);
      if (balance_node < -1 || balance_node > 1) {
        printf("F\n");
        return 0;
      }
    }
  }
  printf("T\n");
  return 1;
}


x86 assembly (clang, -O0):
<verify_AVL>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    -0x14(%rbp),%ecx
shl    $0x1,%ecx
add    $0x5,%ecx
cmp    %ecx,%eax
jge    11af <verify_AVL+0x8f>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
cmpl   $0xffffffff,(%rax,%rcx,4)
je     119c <verify_AVL+0x7c>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1030 <balance@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jl     117f <verify_AVL+0x5f>
cmpl   $0x1,-0x1c(%rbp)
jle    1197 <verify_AVL+0x77>
lea    0xe7a(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11c2 <verify_AVL+0xa2>
jmp    119c <verify_AVL+0x7c>
jmp    11a1 <verify_AVL+0x81>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1136 <verify_AVL+0x16>
lea    0xe4d(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<verify_AVL>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x1,%r14d
lea    0xec8(%rip),%r12
cmp    $0xfffffffe,%esi
jl     1186 <verify_AVL+0x66>
mov    %rdi,%rbx
lea    (%rsi,%rsi,1),%r13d
add    $0x4,%r13d
xor    %ebp,%ebp
test   %r13d,%r13d
cmovle %ebp,%r13d
or     $0x1,%r13d
lea    0xea6(%rip),%r15
jmp    1169 <verify_AVL+0x49>
xchg   %ax,%ax
add    $0x1,%rbp
cmp    %rbp,%r13
je     1186 <verify_AVL+0x66>
cmpl   $0xffffffff,(%rbx,%rbp,4)
je     1160 <verify_AVL+0x40>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1040 <balance@plt>
add    $0xfffffffe,%eax
cmp    $0xfffffffd,%eax
jae    1160 <verify_AVL+0x40>
xor    %r14d,%r14d
jmp    1189 <verify_AVL+0x69>
mov    %r12,%r15
mov    %r15,%rdi
call   1030 <puts@plt>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"F\0A\00"
@.str.1 = [3 x i8] c"T\0A\00"
define i32 @verify_AVL(i32* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32 0, i32* %6
br label %8
8: ; preds = %34, %2
%9 = load i32, i32* %6
%10 = load i32, i32* %5
%11 = mul nsw i32 %10, 2
%12 = add nsw i32 %11, 5
%13 = icmp slt i32 %9, %12
br i1 %13, label %14, label %37
14: ; preds = %8
%15 = load i32*, i32** %4
%16 = load i32, i32* %6
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i32, i32* %15, i64 %17
%19 = load i32, i32* %18
%20 = icmp ne i32 %19, -1
br i1 %20, label %21, label %33
21: ; preds = %14
%22 = load i32*, i32** %4
%23 = load i32, i32* %6
%24 = call i32 @balance(i32* %22, i32 %23)
store i32 %24, i32* %7
%25 = load i32, i32* %7
%26 = icmp slt i32 %25, -1
br i1 %26, label %30, label %27
27: ; preds = %21
%28 = load i32, i32* %7
%29 = icmp sgt i32 %28, 1
br i1 %29, label %30, label %32
30: ; preds = %27, %21
%31 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %39
32: ; preds = %27
br label %33
33: ; preds = %32, %14
br label %34
34: ; preds = %33
%35 = load i32, i32* %6
%36 = add nsw i32 %35, 1
store i32 %36, i32* %6
br label %8
37: ; preds = %8
%38 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %39
39: ; preds = %37, %30
%40 = load i32, i32* %3
ret i32 %40
}

LLVM IR (-O2):
@str = [2 x i8] c"T\00"
@str.2 = [2 x i8] c"F\00"
define i32 @verify_AVL(i32* %0, i32 %1) {
%3 = icmp sgt i32 %1, -3
br i1 %3, label %4, label %23
4: ; preds = %2
%5 = shl i32 %1, 1
%6 = add i32 %5, 4
%7 = call i32 @llvm.smax.i32(i32 %6, i32 0)
%8 = or i32 %7, 1
%9 = zext i32 %8 to i64
br label %10
10: ; preds = %4, %20
%11 = phi i64 [ 0, %4 ], [ %21, %20 ]
%12 = getelementptr inbounds i32, i32* %0, i64 %11
%13 = load i32, i32* %12
%14 = icmp eq i32 %13, -1
br i1 %14, label %20, label %15
15: ; preds = %10
%16 = trunc i64 %11 to i32
%17 = tail call i32 @balance(i32* %0, i32 %16)
%18 = add i32 %17, -2
%19 = icmp ult i32 %18, -3
br i1 %19, label %23, label %20
20: ; preds = %15, %10
%21 = add nuw nsw i64 %11, 1
%22 = icmp eq i64 %21, %9
br i1 %22, label %23, label %10
23: ; preds = %20, %15, %2
%24 = phi i8* [ getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0), %2 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @str.2, i64 0, i64 0), %15 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0), %20 ]
%25 = phi i32 [ 1, %2 ], [ 0, %15 ], [ 1, %20 ]
%26 = tail call i32 @puts(i8* dereferenceable(1) %24)
ret i32 %25
}