; LLVM IR from PetarV-/Algorithms :: Data Structures/Splay Tree.ll (ZN9SplayTree6insertEi)

; 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"

%class.SplayTree = type { ptr }
%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: mustprogress nounwind uwtable
declare dso_local void @_ZN9SplayTree5splayEP8TreeNode(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN9SplayTree6insertEi(ptr noundef nonnull align 8 dereferenceable(8) %0, i32 noundef %1) #2 align 2 personality ptr @__gxx_personality_v0 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %11 = load ptr, ptr %3, align 8
  %12 = getelementptr inbounds %class.SplayTree, ptr %11, i32 0, i32 0
  %13 = load ptr, ptr %12, align 8, !tbaa !11
  %14 = icmp eq ptr %13, null
  br i1 %14, label %15, label %24

15:                                               ; preds = %2
  %16 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 32) #5
  %17 = load i32, ptr %4, align 4, !tbaa !9
  invoke void @_ZN8TreeNodeC2Ei(ptr noundef nonnull align 8 dereferenceable(32) %16, i32 noundef %17)
          to label %18 unwind label %20

18:                                               ; preds = %15
  %19 = getelementptr inbounds %class.SplayTree, ptr %11, i32 0, i32 0
  store ptr %16, ptr %19, align 8, !tbaa !11
  br label %99

20:                                               ; preds = %15
  %21 = landingpad { ptr, i32 }
          cleanup
  %22 = extractvalue { ptr, i32 } %21, 0
  store ptr %22, ptr %5, align 8
  %23 = extractvalue { ptr, i32 } %21, 1
  store i32 %23, ptr %6, align 4
  call void @_ZdlPvm(ptr noundef %16, i64 noundef 32) #6
  br label %101

24:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #7
  %25 = getelementptr inbounds %class.SplayTree, ptr %11, i32 0, i32 0
  %26 = load ptr, ptr %25, align 8, !tbaa !11
  store ptr %26, ptr %7, align 8, !tbaa !5
  br label %27

27:                                               ; preds = %95, %24
  %28 = load ptr, ptr %7, align 8, !tbaa !5
  %29 = icmp ne ptr %28, null
  br i1 %29, label %30, label %96

30:                                               ; preds = %27
  %31 = load i32, ptr %4, align 4, !tbaa !9
  %32 = load ptr, ptr %7, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.TreeNode, ptr %32, i32 0, i32 0
  %34 = load i32, ptr %33, align 8, !tbaa !13
  %35 = icmp slt i32 %31, %34
  br i1 %35, label %36, label %61

36:                                               ; preds = %30
  %37 = load ptr, ptr %7, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.TreeNode, ptr %37, i32 0, i32 2
  %39 = load ptr, ptr %38, align 8, !tbaa !15
  %40 = icmp eq ptr %39, null
  br i1 %40, label %41, label %56

41:                                               ; preds = %36
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #7
  %42 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 32) #5
  %43 = load i32, ptr %4, align 4, !tbaa !9
  invoke void @_ZN8TreeNodeC2Ei(ptr noundef nonnull align 8 dereferenceable(32) %42, i32 noundef %43)
          to label %44 unwind label %52

44:                                               ; preds = %41
  store ptr %42, ptr %8, align 8, !tbaa !5
  %45 = load ptr, ptr %8, align 8, !tbaa !5
  %46 = load ptr, ptr %7, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.TreeNode, ptr %46, i32 0, i32 2
  store ptr %45, ptr %47, align 8, !tbaa !15
  %48 = load ptr, ptr %7, align 8, !tbaa !5
  %49 = load ptr, ptr %8, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.TreeNode, ptr %49, i32 0, i32 1
  store ptr %48, ptr %50, align 8, !tbaa !16
  %51 = load ptr, ptr %8, align 8, !tbaa !5
  call void @_ZN9SplayTree5splayEP8TreeNode(ptr noundef nonnull align 8 dereferenceable(8) %11, ptr noundef %51)
  store i32 1, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #7
  br label %97

52:                                               ; preds = %41
  %53 = landingpad { ptr, i32 }
          cleanup
  %54 = extractvalue { ptr, i32 } %53, 0
  store ptr %54, ptr %5, align 8
  %55 = extractvalue { ptr, i32 } %53, 1
  store i32 %55, ptr %6, align 4
  call void @_ZdlPvm(ptr noundef %42, i64 noundef 32) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #7
  br label %100

56:                                               ; preds = %36
  %57 = load ptr, ptr %7, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.TreeNode, ptr %57, i32 0, i32 2
  %59 = load ptr, ptr %58, align 8, !tbaa !15
  store ptr %59, ptr %7, align 8, !tbaa !5
  br label %60

60:                                               ; preds = %56
  br label %95

61:                                               ; preds = %30
  %62 = load i32, ptr %4, align 4, !tbaa !9
  %63 = load ptr, ptr %7, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.TreeNode, ptr %63, i32 0, i32 0
  %65 = load i32, ptr %64, align 8, !tbaa !13
  %66 = icmp sgt i32 %62, %65
  br i1 %66, label %67, label %92

67:                                               ; preds = %61
  %68 = load ptr, ptr %7, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.TreeNode, ptr %68, i32 0, i32 3
  %70 = load ptr, ptr %69, align 8, !tbaa !17
  %71 = icmp eq ptr %70, null
  br i1 %71, label %72, label %87

72:                                               ; preds = %67
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #7
  %73 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 32) #5
  %74 = load i32, ptr %4, align 4, !tbaa !9
  invoke void @_ZN8TreeNodeC2Ei(ptr noundef nonnull align 8 dereferenceable(32) %73, i32 noundef %74)
          to label %75 unwind label %83

75:                                               ; preds = %72
  store ptr %73, ptr %10, align 8, !tbaa !5
  %76 = load ptr, ptr %10, align 8, !tbaa !5
  %77 = load ptr, ptr %7, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.TreeNode, ptr %77, i32 0, i32 3
  store ptr %76, ptr %78, align 8, !tbaa !17
  %79 = load ptr, ptr %7, align 8, !tbaa !5
  %80 = load ptr, ptr %10, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.TreeNode, ptr %80, i32 0, i32 1
  store ptr %79, ptr %81, align 8, !tbaa !16
  %82 = load ptr, ptr %10, align 8, !tbaa !5
  call void @_ZN9SplayTree5splayEP8TreeNode(ptr noundef nonnull align 8 dereferenceable(8) %11, ptr noundef %82)
  store i32 1, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #7
  br label %97

83:                                               ; preds = %72
  %84 = landingpad { ptr, i32 }
          cleanup
  %85 = extractvalue { ptr, i32 } %84, 0
  store ptr %85, ptr %5, align 8
  %86 = extractvalue { ptr, i32 } %84, 1
  store i32 %86, ptr %6, align 4
  call void @_ZdlPvm(ptr noundef %73, i64 noundef 32) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #7
  br label %100

87:                                               ; preds = %67
  %88 = load ptr, ptr %7, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.TreeNode, ptr %88, i32 0, i32 3
  %90 = load ptr, ptr %89, align 8, !tbaa !17
  store ptr %90, ptr %7, align 8, !tbaa !5
  br label %91

91:                                               ; preds = %87
  br label %94

92:                                               ; preds = %61
  %93 = load ptr, ptr %7, align 8, !tbaa !5
  call void @_ZN9SplayTree5splayEP8TreeNode(ptr noundef nonnull align 8 dereferenceable(8) %11, ptr noundef %93)
  store i32 1, ptr %9, align 4
  br label %97

94:                                               ; preds = %91
  br label %95

95:                                               ; preds = %94, %60
  br label %27, !llvm.loop !18

96:                                               ; preds = %27
  store i32 0, ptr %9, align 4
  br label %97

97:                                               ; preds = %96, %92, %75, %44
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #7
  %98 = load i32, ptr %9, align 4
  switch i32 %98, label %106 [
    i32 0, label %99
    i32 1, label %99
  ]

99:                                               ; preds = %97, %97, %18
  ret void

100:                                              ; preds = %83, %52
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #7
  br label %101

101:                                              ; preds = %100, %20
  %102 = load ptr, ptr %5, align 8
  %103 = load i32, ptr %6, align 4
  %104 = insertvalue { ptr, i32 } poison, ptr %102, 0
  %105 = insertvalue { ptr, i32 } %104, i32 %103, 1
  resume { ptr, i32 } %105

106:                                              ; preds = %97
  unreachable
}

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) #3

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN8TreeNodeC2Ei(ptr noundef nonnull align 8 dereferenceable(32), i32 noundef) unnamed_addr #1 align 2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 = { 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 #3 = { nobuiltin allocsize(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 #4 = { nobuiltin nounwind "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 #5 = { builtin allocsize(0) }
attributes #6 = { builtin nounwind }
attributes #7 = { 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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"_ZTS9SplayTree", !6, i64 0}
!13 = !{!14, !10, i64 0}
!14 = !{!"_ZTS8TreeNode", !10, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!15 = !{!14, !6, i64 16}
!16 = !{!14, !6, i64 8}
!17 = !{!14, !6, i64 24}
!18 = distinct !{!18, !19}
!19 = !{!"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: mustprogress nounwind uwtable
declare dso_local void @_ZN9SplayTree5splayEP8TreeNode(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN9SplayTree6insertEi(ptr noundef nonnull align 8 dereferenceable(8) %0, i32 noundef %1) local_unnamed_addr #1 align 2 personality ptr @__gxx_personality_v0 {
  %3 = load ptr, ptr %0, align 8, !tbaa !5
  %4 = icmp eq ptr %3, null
  br i1 %4, label %5, label %.preheader

5:                                                ; preds = %2
  %6 = tail call noalias noundef nonnull dereferenceable(32) ptr @_Znwm(i64 noundef 32) #3
  tail call void @_ZN8TreeNodeC2Ei(ptr noundef nonnull align 8 dereferenceable(32) %6, i32 noundef %1)
  store ptr %6, ptr %0, align 8, !tbaa !5
  br label %28

.preheader:                                       ; preds = %2, %.preheader.backedge
  %.0 = phi ptr [ %.0.be, %.preheader.backedge ], [ %3, %2 ]
  %7 = load i32, ptr %.0, align 8, !tbaa !10
  %8 = icmp sgt i32 %7, %1
  br i1 %8, label %9, label %17

9:                                                ; preds = %.preheader
  %10 = getelementptr inbounds i8, ptr %.0, i64 16
  %11 = load ptr, ptr %10, align 8, !tbaa !13
  %12 = icmp eq ptr %11, null
  br i1 %12, label %13, label %.preheader.backedge

13:                                               ; preds = %9
  %14 = getelementptr inbounds i8, ptr %.0, i64 16
  %15 = tail call noalias noundef nonnull dereferenceable(32) ptr @_Znwm(i64 noundef 32) #3
  tail call void @_ZN8TreeNodeC2Ei(ptr noundef nonnull align 8 dereferenceable(32) %15, i32 noundef %1)
  store ptr %15, ptr %14, align 8, !tbaa !13
  %16 = getelementptr inbounds i8, ptr %15, i64 8
  store ptr %.0, ptr %16, align 8, !tbaa !14
  tail call void @_ZN9SplayTree5splayEP8TreeNode(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr noundef nonnull %15)
  br label %28

17:                                               ; preds = %.preheader
  %18 = icmp slt i32 %7, %1
  br i1 %18, label %19, label %27

19:                                               ; preds = %17
  %20 = getelementptr inbounds i8, ptr %.0, i64 24
  %21 = load ptr, ptr %20, align 8, !tbaa !15
  %22 = icmp eq ptr %21, null
  br i1 %22, label %23, label %.preheader.backedge

.preheader.backedge:                              ; preds = %19, %9
  %.0.be = phi ptr [ %11, %9 ], [ %21, %19 ]
  br label %.preheader, !llvm.loop !16

23:                                               ; preds = %19
  %24 = getelementptr inbounds i8, ptr %.0, i64 24
  %25 = tail call noalias noundef nonnull dereferenceable(32) ptr @_Znwm(i64 noundef 32) #3
  tail call void @_ZN8TreeNodeC2Ei(ptr noundef nonnull align 8 dereferenceable(32) %25, i32 noundef %1)
  store ptr %25, ptr %24, align 8, !tbaa !15
  %26 = getelementptr inbounds i8, ptr %25, i64 8
  store ptr %.0, ptr %26, align 8, !tbaa !14
  tail call void @_ZN9SplayTree5splayEP8TreeNode(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr noundef nonnull %25)
  br label %28

27:                                               ; preds = %17
  tail call void @_ZN9SplayTree5splayEP8TreeNode(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr noundef nonnull %.0)
  br label %28

28:                                               ; preds = %13, %23, %27, %5
  ret void
}

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN8TreeNodeC2Ei(ptr noundef nonnull align 8 dereferenceable(32), i32 noundef) unnamed_addr #0 align 2

declare i32 @__gxx_personality_v0(...)

attributes #0 = { mustprogress 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 = { 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 = { nobuiltin allocsize(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 #3 = { builtin allocsize(0) }

!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 = !{!"_ZTS9SplayTree", !7, i64 0}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!11, !12, i64 0}
!11 = !{!"_ZTS8TreeNode", !12, i64 0, !7, i64 8, !7, i64 16, !7, i64 24}
!12 = !{!"int", !8, i64 0}
!13 = !{!11, !7, i64 16}
!14 = !{!11, !7, i64 8}
!15 = !{!11, !7, i64 24}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass