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

/* Variables and functions */
scalar_t__ malloc(int);
int /*<<< orphan*/ traverse(struct TreeNode *, int **, int *);
bool isValidBST(struct TreeNode *root) {
  if (!root)
    return true;
  int *arr = (int *)malloc(sizeof(int));
  int size = 0;
  traverse(root, &arr, &size);
  for (int i = 1; i < size; i++)
    if (arr[i] <= arr[i - 1])
      return false;
  return true;
}


x86 assembly (clang, -O0):
<isValidBST>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1143 <isValidBST+0x23>
movl   $0x1,-0x4(%rbp)
jmp    11c3 <isValidBST+0xa3>
mov    $0x4,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
lea    -0x1c(%rbp),%rdx
call   1030 <traverse@plt>
movl   $0x1,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11bc <isValidBST+0x9c>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%edx
sub    $0x1,%edx
movslq %edx,%rdx
cmp    (%rcx,%rdx,4),%eax
jg     11a9 <isValidBST+0x89>
movl   $0x0,-0x4(%rbp)
jmp    11c3 <isValidBST+0xa3>
jmp    11ae <isValidBST+0x8e>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1170 <isValidBST+0x50>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<isValidBST>:
test   %rdi,%rdi
je     11a3 <isValidBST+0x83>
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
mov    $0x4,%edi
call   1040 <malloc@plt>
mov    %rax,0x8(%rsp)
movl   $0x0,0x4(%rsp)
lea    0x8(%rsp),%rsi
lea    0x4(%rsp),%rdx
mov    %rbx,%rdi
call   1030 <traverse@plt>
mov    0x4(%rsp),%ecx
mov    $0x1,%eax
cmp    $0x2,%ecx
jl     119d <isValidBST+0x7d>
mov    0x8(%rsp),%rdx
mov    0x4(%rdx),%ebx
xor    %eax,%eax
cmp    (%rdx),%ebx
jle    119d <isValidBST+0x7d>
mov    $0x2,%eax
nopw   0x0(%rax,%rax,1)
mov    %rax,%rdi
cmp    %rax,%rcx
je     1195 <isValidBST+0x75>
mov    (%rdx,%rdi,4),%esi
lea    0x1(%rdi),%rax
cmp    %ebx,%esi
mov    %esi,%ebx
jg     1180 <isValidBST+0x60>
xor    %eax,%eax
cmp    %rcx,%rdi
setae  %al
add    $0x10,%rsp
pop    %rbx
ret
mov    $0x1,%eax
ret

LLVM IR (-O0):
%struct.TreeNode = type { i32 }
define i32 @isValidBST(%struct.TreeNode* %0) {
%2 = alloca i32
%3 = alloca %struct.TreeNode*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
store %struct.TreeNode* %0, %struct.TreeNode** %3
%7 = load %struct.TreeNode*, %struct.TreeNode** %3
%8 = icmp ne %struct.TreeNode* %7, null
br i1 %8, label %10, label %9
9: ; preds = %1
store i32 1, i32* %2
br label %38
10: ; preds = %1
%11 = call i64 @malloc(i32 4)
%12 = inttoptr i64 %11 to i32*
store i32* %12, i32** %4
store i32 0, i32* %5
%13 = load %struct.TreeNode*, %struct.TreeNode** %3
%14 = call i32 @traverse(%struct.TreeNode* %13, i32** %4, i32* %5)
store i32 1, i32* %6
br label %15
15: ; preds = %34, %10
%16 = load i32, i32* %6
%17 = load i32, i32* %5
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %37
19: ; preds = %15
%20 = load i32*, i32** %4
%21 = load i32, i32* %6
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i32, i32* %20, i64 %22
%24 = load i32, i32* %23
%25 = load i32*, i32** %4
%26 = load i32, i32* %6
%27 = sub nsw i32 %26, 1
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i32, i32* %25, i64 %28
%30 = load i32, i32* %29
%31 = icmp sle i32 %24, %30
br i1 %31, label %32, label %33
32: ; preds = %19
store i32 0, i32* %2
br label %38
33: ; preds = %19
br label %34
34: ; preds = %33
%35 = load i32, i32* %6
%36 = add nsw i32 %35, 1
store i32 %36, i32* %6
br label %15
37: ; preds = %15
store i32 1, i32* %2
br label %38
38: ; preds = %37, %32, %9
%39 = load i32, i32* %2
ret i32 %39
}

LLVM IR (-O2):
%struct.TreeNode = type { i32 }
define i32 @isValidBST(%struct.TreeNode* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = icmp eq %struct.TreeNode* %0, null
br i1 %4, label %35, label %5
5: ; preds = %1
%6 = bitcast i32** %2 to i8*
%7 = tail call i64 @malloc(i32 4)
%8 = inttoptr i64 %7 to i32*
store i32* %8, i32** %2
%9 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%10 = call i32 @traverse(%struct.TreeNode* %0, i32** %2, i32* %3)
%11 = load i32, i32* %3
%12 = icmp sgt i32 %11, 1
br i1 %12, label %13, label %33
13: ; preds = %5
%14 = load i32*, i32** %2
%15 = zext i32 %11 to i64
%16 = zext i32 %11 to i64
%17 = load i32, i32* %14
%18 = getelementptr inbounds i32, i32* %14, i64 1
%19 = load i32, i32* %18
%20 = icmp sgt i32 %19, %17
br i1 %20, label %21, label %33
21: ; preds = %13, %25
%22 = phi i64 [ %29, %25 ], [ 2, %13 ]
%23 = phi i32 [ %27, %25 ], [ %19, %13 ]
%24 = icmp eq i64 %22, %16
br i1 %24, label %30, label %25
25: ; preds = %21
%26 = getelementptr inbounds i32, i32* %14, i64 %22
%27 = load i32, i32* %26
%28 = icmp sgt i32 %27, %23
%29 = add nuw nsw i64 %22, 1
br i1 %28, label %21, label %30
30: ; preds = %21, %25
%31 = icmp uge i64 %22, %15
%32 = zext i1 %31 to i32
br label %33
33: ; preds = %30, %13, %5
%34 = phi i32 [ 1, %5 ], [ 0, %13 ], [ %32, %30 ]
br label %35
35: ; preds = %1, %33
%36 = phi i32 [ %34, %33 ], [ 1, %1 ]
ret i32 %36
}