; LLVM IR from smv1999/CompetitiveProgrammingQuestionBank :: Data Structures/Trees/binary_search_tree.ll (ZN4Node6insertEi)

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4Node6insertEi(ptr noundef nonnull align 8 dereferenceable(20) %0, i32 noundef %1) #0 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
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %7 = load ptr, ptr %3, align 8
  %8 = load i32, ptr %4, align 4, !tbaa !9
  %9 = getelementptr inbounds %class.Node, ptr %7, i32 0, i32 2
  %10 = load i32, ptr %9, align 8, !tbaa !11
  %11 = icmp sle i32 %8, %10
  br i1 %11, label %12, label %30

12:                                               ; preds = %2
  %13 = getelementptr inbounds %class.Node, ptr %7, i32 0, i32 0
  %14 = load ptr, ptr %13, align 8, !tbaa !13
  %15 = icmp eq ptr %14, null
  br i1 %15, label %16, label %25

16:                                               ; preds = %12
  %17 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 24) #4
  %18 = load i32, ptr %4, align 4, !tbaa !9
  invoke void @_ZN4NodeC2Ei(ptr noundef nonnull align 8 dereferenceable(20) %17, i32 noundef %18)
          to label %19 unwind label %21

19:                                               ; preds = %16
  %20 = getelementptr inbounds %class.Node, ptr %7, i32 0, i32 0
  store ptr %17, ptr %20, align 8, !tbaa !13
  br label %29

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

25:                                               ; preds = %12
  %26 = getelementptr inbounds %class.Node, ptr %7, i32 0, i32 0
  %27 = load ptr, ptr %26, align 8, !tbaa !13
  %28 = load i32, ptr %4, align 4, !tbaa !9
  call void @_ZN4Node6insertEi(ptr noundef nonnull align 8 dereferenceable(20) %27, i32 noundef %28)
  br label %29

29:                                               ; preds = %25, %19
  br label %48

30:                                               ; preds = %2
  %31 = getelementptr inbounds %class.Node, ptr %7, i32 0, i32 1
  %32 = load ptr, ptr %31, align 8, !tbaa !14
  %33 = icmp eq ptr %32, null
  br i1 %33, label %34, label %43

34:                                               ; preds = %30
  %35 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 24) #4
  %36 = load i32, ptr %4, align 4, !tbaa !9
  invoke void @_ZN4NodeC2Ei(ptr noundef nonnull align 8 dereferenceable(20) %35, i32 noundef %36)
          to label %37 unwind label %39

37:                                               ; preds = %34
  %38 = getelementptr inbounds %class.Node, ptr %7, i32 0, i32 1
  store ptr %35, ptr %38, align 8, !tbaa !14
  br label %47

39:                                               ; preds = %34
  %40 = landingpad { ptr, i32 }
          cleanup
  %41 = extractvalue { ptr, i32 } %40, 0
  store ptr %41, ptr %5, align 8
  %42 = extractvalue { ptr, i32 } %40, 1
  store i32 %42, ptr %6, align 4
  call void @_ZdlPvm(ptr noundef %35, i64 noundef 24) #5
  br label %49

43:                                               ; preds = %30
  %44 = getelementptr inbounds %class.Node, ptr %7, i32 0, i32 1
  %45 = load ptr, ptr %44, align 8, !tbaa !14
  %46 = load i32, ptr %4, align 4, !tbaa !9
  call void @_ZN4Node6insertEi(ptr noundef nonnull align 8 dereferenceable(20) %45, i32 noundef %46)
  br label %47

47:                                               ; preds = %43, %37
  br label %48

48:                                               ; preds = %47, %29
  ret void

49:                                               ; preds = %39, %21
  %50 = load ptr, ptr %5, align 8
  %51 = load i32, ptr %6, align 4
  %52 = insertvalue { ptr, i32 } poison, ptr %50, 0
  %53 = insertvalue { ptr, i32 } %52, i32 %51, 1
  resume { ptr, i32 } %53
}

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

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

declare i32 @__gxx_personality_v0(...)

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

attributes #0 = { 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 #1 = { 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 #2 = { 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 #3 = { 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 #4 = { builtin allocsize(0) }
attributes #5 = { builtin 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, !10, i64 16}
!12 = !{!"_ZTS4Node", !6, i64 0, !6, i64 8, !10, i64 16}
!13 = !{!12, !6, i64 0}
!14 = !{!12, !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: mustprogress uwtable
define dso_local void @_ZN4Node6insertEi(ptr nocapture noundef nonnull align 8 dereferenceable(20) %0, i32 noundef %1) local_unnamed_addr #0 align 2 personality ptr @__gxx_personality_v0 {
  br label %tailrecurse

tailrecurse:                                      ; preds = %tailrecurse.backedge, %2
  %.tr = phi ptr [ %0, %2 ], [ %.tr.be, %tailrecurse.backedge ]
  %3 = getelementptr inbounds i8, ptr %.tr, i64 16
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %.not = icmp slt i32 %4, %1
  br i1 %.not, label %8, label %5

5:                                                ; preds = %tailrecurse
  %6 = load ptr, ptr %.tr, align 8, !tbaa !11
  %7 = icmp eq ptr %6, null
  br i1 %7, label %.loopexit, label %tailrecurse.backedge

tailrecurse.backedge:                             ; preds = %5, %8
  %.tr.be = phi ptr [ %6, %5 ], [ %10, %8 ]
  br label %tailrecurse

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

12:                                               ; preds = %8
  %13 = getelementptr inbounds i8, ptr %.tr, i64 8
  br label %.loopexit

.loopexit:                                        ; preds = %5, %12
  %.sink13 = phi ptr [ %13, %12 ], [ %.tr, %5 ]
  %14 = tail call noalias noundef nonnull dereferenceable(24) ptr @_Znwm(i64 noundef 24) #3
  tail call void @_ZN4NodeC2Ei(ptr noundef nonnull align 8 dereferenceable(20) %14, i32 noundef %1)
  store ptr %14, ptr %.sink13, align 8, !tbaa !13
  ret void
}

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

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

declare i32 @__gxx_personality_v0(...)

attributes #0 = { 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 #1 = { 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 #2 = { 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 #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, !10, i64 16}
!6 = !{!"_ZTS4Node", !7, i64 0, !7, i64 8, !10, i64 16}
!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 0}
!12 = !{!6, !7, i64 8}
!13 = !{!7, !7, i64 0}


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