; LLVM IR from begeekmyfriend/leetcode :: 0098_validate_binary_search_tree (valid_bst)

; Unoptimized IR (clang -disable-llvm-passes):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

%struct.TreeNode = type { i32, ptr, ptr }

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @isValidBST(ptr noundef %0) #0 {
  %2 = alloca i1, align 1
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i8, align 1
  %7 = alloca [1000 x ptr], align 16
  %8 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  store i32 0, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  store i32 -2147483648, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %6) #2
  store i8 1, ptr %6, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8000, ptr %7) #2
  br label %9

9:                                                ; preds = %51, %1
  %10 = load i32, ptr %4, align 4, !tbaa !9
  %11 = icmp sgt i32 %10, 0
  br i1 %11, label %15, label %12

12:                                               ; preds = %9
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = icmp ne ptr %13, null
  br label %15

15:                                               ; preds = %12, %9
  %16 = phi i1 [ true, %9 ], [ %14, %12 ]
  br i1 %16, label %17, label %52

17:                                               ; preds = %15
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = icmp ne ptr %18, null
  br i1 %19, label %20, label %29

20:                                               ; preds = %17
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = load i32, ptr %4, align 4, !tbaa !9
  %23 = add nsw i32 %22, 1
  store i32 %23, ptr %4, align 4, !tbaa !9
  %24 = sext i32 %22 to i64
  %25 = getelementptr inbounds [1000 x ptr], ptr %7, i64 0, i64 %24
  store ptr %21, ptr %25, align 8, !tbaa !5
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.TreeNode, ptr %26, i32 0, i32 1
  %28 = load ptr, ptr %27, align 8, !tbaa !13
  store ptr %28, ptr %3, align 8, !tbaa !5
  br label %51

29:                                               ; preds = %17
  %30 = load i32, ptr %4, align 4, !tbaa !9
  %31 = add nsw i32 %30, -1
  store i32 %31, ptr %4, align 4, !tbaa !9
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [1000 x ptr], ptr %7, i64 0, i64 %32
  %34 = load ptr, ptr %33, align 8, !tbaa !5
  store ptr %34, ptr %3, align 8, !tbaa !5
  %35 = load i8, ptr %6, align 1, !tbaa !11, !range !15, !noundef !16
  %36 = trunc i8 %35 to i1
  br i1 %36, label %44, label %37

37:                                               ; preds = %29
  %38 = load i32, ptr %5, align 4, !tbaa !9
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.TreeNode, ptr %39, i32 0, i32 0
  %41 = load i32, ptr %40, align 8, !tbaa !17
  %42 = icmp sge i32 %38, %41
  br i1 %42, label %43, label %44

43:                                               ; preds = %37
  store i1 false, ptr %2, align 1
  store i32 1, ptr %8, align 4
  br label %53

44:                                               ; preds = %37, %29
  store i8 0, ptr %6, align 1, !tbaa !11
  %45 = load ptr, ptr %3, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.TreeNode, ptr %45, i32 0, i32 0
  %47 = load i32, ptr %46, align 8, !tbaa !17
  store i32 %47, ptr %5, align 4, !tbaa !9
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.TreeNode, ptr %48, i32 0, i32 2
  %50 = load ptr, ptr %49, align 8, !tbaa !18
  store ptr %50, ptr %3, align 8, !tbaa !5
  br label %51

51:                                               ; preds = %44, %20
  br label %9, !llvm.loop !19

52:                                               ; preds = %15
  store i1 true, ptr %2, align 1
  store i32 1, ptr %8, align 4
  br label %53

53:                                               ; preds = %52, %43
  call void @llvm.lifetime.end.p0(i64 8000, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  %54 = load i1, ptr %2, align 1
  ret i1 %54
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

attributes #0 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"_Bool", !7, i64 0}
!13 = !{!14, !6, i64 8}
!14 = !{!"TreeNode", !10, i64 0, !6, i64 8, !6, i64 16}
!15 = !{i8 0, i8 2}
!16 = !{}
!17 = !{!14, !10, i64 0}
!18 = !{!14, !6, i64 16}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}


; Optimized IR (opt -passes='default<O3>'):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

; Function Attrs: nofree norecurse nosync nounwind memory(read, inaccessiblemem: none) uwtable
define dso_local noundef zeroext i1 @isValidBST(ptr noundef %0) local_unnamed_addr #0 {
  %2 = alloca [1000 x ptr], align 16
  call void @llvm.lifetime.start.p0(i64 8000, ptr nonnull %2) #2
  %3 = icmp eq ptr %0, null
  br i1 %3, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1, %17
  %4 = phi i1 [ %19, %17 ], [ false, %1 ]
  %.025 = phi i1 [ %.1, %17 ], [ true, %1 ]
  %.01224 = phi i32 [ %.113, %17 ], [ -2147483648, %1 ]
  %.01423 = phi i32 [ %.115, %17 ], [ 0, %1 ]
  %.01622 = phi ptr [ %.117, %17 ], [ %0, %1 ]
  br i1 %4, label %10, label %5

5:                                                ; preds = %.lr.ph
  %6 = add nsw i32 %.01423, 1
  %7 = sext i32 %.01423 to i64
  %8 = getelementptr inbounds [1000 x ptr], ptr %2, i64 0, i64 %7
  store ptr %.01622, ptr %8, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %.01622, i64 8
  br label %17

10:                                               ; preds = %.lr.ph
  %11 = add nsw i32 %.01423, -1
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [1000 x ptr], ptr %2, i64 0, i64 %12
  %14 = load ptr, ptr %13, align 8, !tbaa !5
  %.pre = load i32, ptr %14, align 8, !tbaa !9
  %.not = icmp slt i32 %.01224, %.pre
  %or.cond = select i1 %.025, i1 true, i1 %.not
  br i1 %or.cond, label %15, label %._crit_edge

15:                                               ; preds = %10
  %16 = getelementptr inbounds i8, ptr %14, i64 16
  br label %17

17:                                               ; preds = %15, %5
  %.117.in = phi ptr [ %9, %5 ], [ %16, %15 ]
  %.115 = phi i32 [ %6, %5 ], [ %11, %15 ]
  %.113 = phi i32 [ %.01224, %5 ], [ %.pre, %15 ]
  %.1 = phi i1 [ %.025, %5 ], [ false, %15 ]
  %.117 = load ptr, ptr %.117.in, align 8, !tbaa !5
  %18 = icmp slt i32 %.115, 1
  %19 = icmp eq ptr %.117, null
  %.not21 = select i1 %18, i1 %19, i1 false
  br i1 %.not21, label %._crit_edge, label %.lr.ph, !llvm.loop !12

._crit_edge:                                      ; preds = %17, %10, %1
  %.not21.lcssa = phi i1 [ true, %1 ], [ true, %17 ], [ false, %10 ]
  call void @llvm.lifetime.end.p0(i64 8000, ptr nonnull %2) #2
  ret i1 %.not21.lcssa
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

attributes #0 = { nofree norecurse nosync nounwind memory(read, inaccessiblemem: none) uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"TreeNode", !11, i64 0, !6, i64 8, !6, i64 16}
!11 = !{!"int", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: AggressiveInstCombinePass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass