; LLVM IR from ahampriyanshu/algo-ds-101 :: Algorithms/Tree/Validate_BST/Validate_BST.ll (Z5isBSTP4node)

; 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.node = type <{ ptr, ptr, i32, i32, i32, [4 x i8] }>

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z5isBSTP4node(ptr noundef %0) #1 {
  %2 = alloca i1, align 1
  %3 = alloca ptr, align 8
  %4 = alloca i8, align 1
  %5 = alloca i32, align 4
  %6 = alloca i8, align 1
  store ptr %0, ptr %3, align 8, !tbaa !5
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = icmp eq ptr %7, null
  br i1 %8, label %9, label %10

9:                                                ; preds = %1
  br label %10

10:                                               ; preds = %9, %1
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.node, ptr %11, i32 0, i32 0
  %13 = load ptr, ptr %12, align 8, !tbaa !9
  %14 = icmp eq ptr %13, null
  br i1 %14, label %15, label %21

15:                                               ; preds = %10
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.node, ptr %16, i32 0, i32 1
  %18 = load ptr, ptr %17, align 8, !tbaa !12
  %19 = icmp eq ptr %18, null
  br i1 %19, label %20, label %21

20:                                               ; preds = %15
  store i1 true, ptr %2, align 1
  br label %79

21:                                               ; preds = %15, %10
  call void @llvm.lifetime.start.p0(i64 1, ptr %4) #2
  store i8 1, ptr %4, align 1, !tbaa !13
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.node, ptr %22, i32 0, i32 0
  %24 = load ptr, ptr %23, align 8, !tbaa !9
  %25 = icmp ne ptr %24, null
  br i1 %25, label %26, label %45

26:                                               ; preds = %21
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.node, ptr %27, i32 0, i32 2
  %29 = load i32, ptr %28, align 8, !tbaa !15
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.node, ptr %30, i32 0, i32 0
  %32 = load ptr, ptr %31, align 8, !tbaa !9
  %33 = getelementptr inbounds %struct.node, ptr %32, i32 0, i32 3
  %34 = load i32, ptr %33, align 4, !tbaa !16
  %35 = icmp slt i32 %29, %34
  br i1 %35, label %36, label %39

36:                                               ; preds = %26
  store i8 0, ptr %4, align 1, !tbaa !13
  %37 = load i8, ptr %4, align 1, !tbaa !13, !range !17, !noundef !18
  %38 = trunc i8 %37 to i1
  store i1 %38, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %78

39:                                               ; preds = %26
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.node, ptr %40, i32 0, i32 0
  %42 = load ptr, ptr %41, align 8, !tbaa !9
  %43 = call noundef zeroext i1 @_Z5isBSTP4node(ptr noundef %42)
  %44 = zext i1 %43 to i8
  store i8 %44, ptr %4, align 1, !tbaa !13
  br label %45

45:                                               ; preds = %39, %21
  call void @llvm.lifetime.start.p0(i64 1, ptr %6) #2
  store i8 1, ptr %6, align 1, !tbaa !13
  %46 = load ptr, ptr %3, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.node, ptr %46, i32 0, i32 1
  %48 = load ptr, ptr %47, align 8, !tbaa !12
  %49 = icmp ne ptr %48, null
  br i1 %49, label %50, label %69

50:                                               ; preds = %45
  %51 = load ptr, ptr %3, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.node, ptr %51, i32 0, i32 2
  %53 = load i32, ptr %52, align 8, !tbaa !15
  %54 = load ptr, ptr %3, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.node, ptr %54, i32 0, i32 1
  %56 = load ptr, ptr %55, align 8, !tbaa !12
  %57 = getelementptr inbounds %struct.node, ptr %56, i32 0, i32 4
  %58 = load i32, ptr %57, align 8, !tbaa !19
  %59 = icmp sgt i32 %53, %58
  br i1 %59, label %60, label %63

60:                                               ; preds = %50
  store i8 0, ptr %6, align 1, !tbaa !13
  %61 = load i8, ptr %6, align 1, !tbaa !13, !range !17, !noundef !18
  %62 = trunc i8 %61 to i1
  store i1 %62, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %77

63:                                               ; preds = %50
  %64 = load ptr, ptr %3, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.node, ptr %64, i32 0, i32 1
  %66 = load ptr, ptr %65, align 8, !tbaa !12
  %67 = call noundef zeroext i1 @_Z5isBSTP4node(ptr noundef %66)
  %68 = zext i1 %67 to i8
  store i8 %68, ptr %6, align 1, !tbaa !13
  br label %69

69:                                               ; preds = %63, %45
  %70 = load i8, ptr %4, align 1, !tbaa !13, !range !17, !noundef !18
  %71 = trunc i8 %70 to i1
  br i1 %71, label %72, label %75

72:                                               ; preds = %69
  %73 = load i8, ptr %6, align 1, !tbaa !13, !range !17, !noundef !18
  %74 = trunc i8 %73 to i1
  br label %75

75:                                               ; preds = %72, %69
  %76 = phi i1 [ false, %69 ], [ %74, %72 ]
  store i1 %76, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %77

77:                                               ; preds = %75, %60
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #2
  br label %78

78:                                               ; preds = %77, %36
  call void @llvm.lifetime.end.p0(i64 1, ptr %4) #2
  br label %79

79:                                               ; preds = %78, %20
  %80 = load i1, ptr %2, align 1
  ret i1 %80
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 #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++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"_ZTS4node", !6, i64 0, !6, i64 8, !11, i64 16, !11, i64 20, !11, i64 24}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !6, i64 8}
!13 = !{!14, !14, i64 0}
!14 = !{!"bool", !7, i64 0}
!15 = !{!10, !11, i64 16}
!16 = !{!10, !11, i64 20}
!17 = !{i8 0, i8 2}
!18 = !{}
!19 = !{!10, !11, i64 24}


; 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: mustprogress nofree nosync nounwind willreturn memory(read, inaccessiblemem: none) uwtable
define dso_local noundef zeroext i1 @_Z5isBSTP4node(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = load ptr, ptr %0, align 8, !tbaa !5
  %3 = icmp eq ptr %2, null
  br i1 %3, label %4, label %8

4:                                                ; preds = %1
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = load ptr, ptr %5, align 8, !tbaa !11
  %7 = icmp eq ptr %6, null
  br i1 %7, label %25, label %.thread.thread

8:                                                ; preds = %1
  %9 = getelementptr inbounds i8, ptr %0, i64 16
  %10 = load i32, ptr %9, align 8, !tbaa !12
  %11 = getelementptr inbounds i8, ptr %2, i64 20
  %12 = load i32, ptr %11, align 4, !tbaa !13
  %13 = icmp slt i32 %10, %12
  br i1 %13, label %25, label %.thread

.thread:                                          ; preds = %8
  %14 = tail call noundef zeroext i1 @_Z5isBSTP4node(ptr noundef nonnull %2)
  %.phi.trans.insert = getelementptr inbounds i8, ptr %0, i64 8
  %.pre = load ptr, ptr %.phi.trans.insert, align 8, !tbaa !11
  %.not19 = icmp eq ptr %.pre, null
  br i1 %.not19, label %23, label %.thread.thread

.thread.thread:                                   ; preds = %4, %.thread
  %.01522 = phi i1 [ %14, %.thread ], [ true, %4 ]
  %15 = phi ptr [ %.pre, %.thread ], [ %6, %4 ]
  %16 = getelementptr inbounds i8, ptr %0, i64 16
  %17 = load i32, ptr %16, align 8, !tbaa !12
  %18 = getelementptr inbounds i8, ptr %15, i64 24
  %19 = load i32, ptr %18, align 8, !tbaa !14
  %20 = icmp sgt i32 %17, %19
  br i1 %20, label %25, label %21

21:                                               ; preds = %.thread.thread
  %22 = tail call noundef zeroext i1 @_Z5isBSTP4node(ptr noundef nonnull %15)
  br label %23

23:                                               ; preds = %21, %.thread
  %.01523 = phi i1 [ %.01522, %21 ], [ %14, %.thread ]
  %.0 = phi i1 [ %22, %21 ], [ true, %.thread ]
  %24 = and i1 %.01523, %.0
  br label %25

25:                                               ; preds = %8, %.thread.thread, %23, %4
  %.2 = phi i1 [ true, %4 ], [ false, %8 ], [ %24, %23 ], [ false, %.thread.thread ]
  ret i1 %.2
}

attributes #0 = { mustprogress nofree nosync nounwind willreturn 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" }

!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, !7, i64 0}
!6 = !{!"_ZTS4node", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 20, !10, i64 24}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !7, i64 8}
!12 = !{!6, !10, i64 16}
!13 = !{!6, !10, i64 20}
!14 = !{!6, !10, i64 24}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass