; LLVM IR from xuxping/codelife :: algorthms/tests (test_BinarySeachTree)

; 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, ptr }

; 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: nounwind uwtable
define dso_local void @TreeInsert(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %8, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %9, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.TreeNode, ptr %10, i32 0, i32 0
  %12 = load i32, ptr %11, align 8, !tbaa !9
  store i32 %12, ptr %7, align 4, !tbaa !12
  br label %13

13:                                               ; preds = %31, %2
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = icmp ne ptr %14, null
  br i1 %15, label %16, label %32

16:                                               ; preds = %13
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %17, ptr %6, align 8, !tbaa !5
  %18 = load i32, ptr %7, align 4, !tbaa !12
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.TreeNode, ptr %19, i32 0, i32 0
  %21 = load i32, ptr %20, align 8, !tbaa !9
  %22 = icmp sgt i32 %18, %21
  br i1 %22, label %23, label %27

23:                                               ; preds = %16
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.TreeNode, ptr %24, i32 0, i32 3
  %26 = load ptr, ptr %25, align 8, !tbaa !13
  store ptr %26, ptr %5, align 8, !tbaa !5
  br label %31

27:                                               ; preds = %16
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.TreeNode, ptr %28, i32 0, i32 2
  %30 = load ptr, ptr %29, align 8, !tbaa !14
  store ptr %30, ptr %5, align 8, !tbaa !5
  br label %31

31:                                               ; preds = %27, %23
  br label %13, !llvm.loop !15

32:                                               ; preds = %13
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.TreeNode, ptr %34, i32 0, i32 1
  store ptr %33, ptr %35, align 8, !tbaa !17
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = icmp eq ptr %36, null
  br i1 %37, label %38, label %40

38:                                               ; preds = %32
  %39 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %39, ptr %3, align 8, !tbaa !5
  br label %55

40:                                               ; preds = %32
  %41 = load i32, ptr %7, align 4, !tbaa !12
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.TreeNode, ptr %42, i32 0, i32 0
  %44 = load i32, ptr %43, align 8, !tbaa !9
  %45 = icmp sgt i32 %41, %44
  br i1 %45, label %46, label %50

46:                                               ; preds = %40
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = load ptr, ptr %6, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.TreeNode, ptr %48, i32 0, i32 3
  store ptr %47, ptr %49, align 8, !tbaa !13
  br label %54

50:                                               ; preds = %40
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = load ptr, ptr %6, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.TreeNode, ptr %52, i32 0, i32 2
  store ptr %51, ptr %53, align 8, !tbaa !14
  br label %54

54:                                               ; preds = %50, %46
  br label %55

55:                                               ; preds = %54, %38
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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, !6, i64 24}
!11 = !{!"int", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!10, !6, i64 24}
!14 = !{!10, !6, i64 16}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!10, !6, i64 8}


; 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(readwrite, inaccessiblemem: none) uwtable
define dso_local void @TreeInsert(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = load i32, ptr %1, align 8, !tbaa !5
  %.not19 = icmp eq ptr %0, null
  br i1 %.not19, label %._crit_edge.thread, label %.lr.ph

._crit_edge.thread:                               ; preds = %2
  %4 = getelementptr inbounds i8, ptr %1, i64 8
  store ptr null, ptr %4, align 8, !tbaa !11
  br label %15

.lr.ph:                                           ; preds = %2, %.lr.ph
  %.01820 = phi ptr [ %.1, %.lr.ph ], [ %0, %2 ]
  %5 = load i32, ptr %.01820, align 8, !tbaa !5
  %6 = icmp sgt i32 %3, %5
  %.1.in.v = select i1 %6, i64 24, i64 16
  %.1.in = getelementptr inbounds i8, ptr %.01820, i64 %.1.in.v
  %.1 = load ptr, ptr %.1.in, align 8, !tbaa !12
  %.not = icmp eq ptr %.1, null
  br i1 %.not, label %7, label %.lr.ph, !llvm.loop !13

7:                                                ; preds = %.lr.ph
  %8 = getelementptr inbounds i8, ptr %1, i64 8
  store ptr %.01820, ptr %8, align 8, !tbaa !11
  %9 = load i32, ptr %.01820, align 8, !tbaa !5
  %10 = icmp sgt i32 %3, %9
  br i1 %10, label %11, label %13

11:                                               ; preds = %7
  %12 = getelementptr inbounds i8, ptr %.01820, i64 24
  store ptr %1, ptr %12, align 8, !tbaa !15
  br label %15

13:                                               ; preds = %7
  %14 = getelementptr inbounds i8, ptr %.01820, i64 16
  store ptr %1, ptr %14, align 8, !tbaa !16
  br label %15

15:                                               ; preds = %._crit_edge.thread, %11, %13
  ret void
}

attributes #0 = { nofree norecurse nosync nounwind memory(readwrite, 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 = !{!"TreeNode", !7, i64 0, !10, i64 8, !10, i64 16, !10, i64 24}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !10, i64 8}
!12 = !{!10, !10, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!6, !10, i64 24}
!16 = !{!6, !10, i64 16}


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