; LLVM IR from priyankchheda/algorithms :: _other_languages/cpp/BinarySearchTree/BST/BST.ll (ZN3BST10deleteNodeEP4Nodei)

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN3BST11findMinNodeEP4Node(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) #1 align 2

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZN3BST10deleteNodeEP4Nodei(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr noundef %1, i32 noundef %2) #3 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  %11 = load ptr, ptr %5, align 8
  %12 = load ptr, ptr %6, align 8, !tbaa !5
  %13 = icmp eq ptr %12, null
  br i1 %13, label %14, label %16

14:                                               ; preds = %3
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %15, ptr %4, align 8
  br label %113

16:                                               ; preds = %3
  %17 = load i32, ptr %7, align 4, !tbaa !9
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.Node, ptr %18, i32 0, i32 0
  %20 = load i32, ptr %19, align 8, !tbaa !11
  %21 = icmp slt i32 %17, %20
  br i1 %21, label %22, label %30

22:                                               ; preds = %16
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.Node, ptr %23, i32 0, i32 1
  %25 = load ptr, ptr %24, align 8, !tbaa !13
  %26 = load i32, ptr %7, align 4, !tbaa !9
  %27 = call noundef ptr @_ZN3BST10deleteNodeEP4Nodei(ptr noundef nonnull align 8 dereferenceable(8) %11, ptr noundef %25, i32 noundef %26)
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.Node, ptr %28, i32 0, i32 1
  store ptr %27, ptr %29, align 8, !tbaa !13
  br label %110

30:                                               ; preds = %16
  %31 = load i32, ptr %7, align 4, !tbaa !9
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.Node, ptr %32, i32 0, i32 0
  %34 = load i32, ptr %33, align 8, !tbaa !11
  %35 = icmp sgt i32 %31, %34
  br i1 %35, label %36, label %44

36:                                               ; preds = %30
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.Node, ptr %37, i32 0, i32 2
  %39 = load ptr, ptr %38, align 8, !tbaa !14
  %40 = load i32, ptr %7, align 4, !tbaa !9
  %41 = call noundef ptr @_ZN3BST10deleteNodeEP4Nodei(ptr noundef nonnull align 8 dereferenceable(8) %11, ptr noundef %39, i32 noundef %40)
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.Node, ptr %42, i32 0, i32 2
  store ptr %41, ptr %43, align 8, !tbaa !14
  br label %109

44:                                               ; preds = %30
  %45 = load ptr, ptr %6, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.Node, ptr %45, i32 0, i32 1
  %47 = load ptr, ptr %46, align 8, !tbaa !13
  %48 = icmp eq ptr %47, null
  br i1 %48, label %49, label %59

49:                                               ; preds = %44
  %50 = load ptr, ptr %6, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.Node, ptr %50, i32 0, i32 2
  %52 = load ptr, ptr %51, align 8, !tbaa !14
  %53 = icmp eq ptr %52, null
  br i1 %53, label %54, label %59

54:                                               ; preds = %49
  %55 = load ptr, ptr %6, align 8, !tbaa !5
  %56 = icmp eq ptr %55, null
  br i1 %56, label %58, label %57

57:                                               ; preds = %54
  call void @_ZdlPvm(ptr noundef %55, i64 noundef 24) #4
  br label %58

58:                                               ; preds = %57, %54
  store ptr null, ptr %6, align 8, !tbaa !5
  br label %108

59:                                               ; preds = %49, %44
  %60 = load ptr, ptr %6, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.Node, ptr %60, i32 0, i32 1
  %62 = load ptr, ptr %61, align 8, !tbaa !13
  %63 = icmp eq ptr %62, null
  br i1 %63, label %64, label %73

64:                                               ; preds = %59
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %65 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %65, ptr %8, align 8, !tbaa !5
  %66 = load ptr, ptr %6, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.Node, ptr %66, i32 0, i32 2
  %68 = load ptr, ptr %67, align 8, !tbaa !14
  store ptr %68, ptr %6, align 8, !tbaa !5
  %69 = load ptr, ptr %8, align 8, !tbaa !5
  %70 = icmp eq ptr %69, null
  br i1 %70, label %72, label %71

71:                                               ; preds = %64
  call void @_ZdlPvm(ptr noundef %69, i64 noundef 24) #4
  br label %72

72:                                               ; preds = %71, %64
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  br label %107

73:                                               ; preds = %59
  %74 = load ptr, ptr %6, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.Node, ptr %74, i32 0, i32 2
  %76 = load ptr, ptr %75, align 8, !tbaa !14
  %77 = icmp eq ptr %76, null
  br i1 %77, label %78, label %87

78:                                               ; preds = %73
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %79 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %79, ptr %9, align 8, !tbaa !5
  %80 = load ptr, ptr %6, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.Node, ptr %80, i32 0, i32 1
  %82 = load ptr, ptr %81, align 8, !tbaa !13
  store ptr %82, ptr %6, align 8, !tbaa !5
  %83 = load ptr, ptr %9, align 8, !tbaa !5
  %84 = icmp eq ptr %83, null
  br i1 %84, label %86, label %85

85:                                               ; preds = %78
  call void @_ZdlPvm(ptr noundef %83, i64 noundef 24) #4
  br label %86

86:                                               ; preds = %85, %78
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  br label %106

87:                                               ; preds = %73
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %88 = load ptr, ptr %6, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.Node, ptr %88, i32 0, i32 2
  %90 = load ptr, ptr %89, align 8, !tbaa !14
  %91 = call noundef ptr @_ZN3BST11findMinNodeEP4Node(ptr noundef nonnull align 8 dereferenceable(8) %11, ptr noundef %90)
  store ptr %91, ptr %10, align 8, !tbaa !5
  %92 = load ptr, ptr %10, align 8, !tbaa !5
  %93 = getelementptr inbounds %struct.Node, ptr %92, i32 0, i32 0
  %94 = load i32, ptr %93, align 8, !tbaa !11
  %95 = load ptr, ptr %6, align 8, !tbaa !5
  %96 = getelementptr inbounds %struct.Node, ptr %95, i32 0, i32 0
  store i32 %94, ptr %96, align 8, !tbaa !11
  %97 = load ptr, ptr %6, align 8, !tbaa !5
  %98 = getelementptr inbounds %struct.Node, ptr %97, i32 0, i32 2
  %99 = load ptr, ptr %98, align 8, !tbaa !14
  %100 = load ptr, ptr %10, align 8, !tbaa !5
  %101 = getelementptr inbounds %struct.Node, ptr %100, i32 0, i32 0
  %102 = load i32, ptr %101, align 8, !tbaa !11
  %103 = call noundef ptr @_ZN3BST10deleteNodeEP4Nodei(ptr noundef nonnull align 8 dereferenceable(8) %11, ptr noundef %99, i32 noundef %102)
  %104 = load ptr, ptr %6, align 8, !tbaa !5
  %105 = getelementptr inbounds %struct.Node, ptr %104, i32 0, i32 2
  store ptr %103, ptr %105, align 8, !tbaa !14
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  br label %106

106:                                              ; preds = %87, %86
  br label %107

107:                                              ; preds = %106, %72
  br label %108

108:                                              ; preds = %107, %58
  br label %109

109:                                              ; preds = %108, %36
  br label %110

110:                                              ; preds = %109, %22
  br label %111

111:                                              ; preds = %110
  %112 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %112, ptr %4, align 8
  br label %113

113:                                              ; preds = %111, %14
  %114 = load ptr, ptr %4, align 8
  ret ptr %114
}

attributes #0 = { 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 #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { builtin nounwind }
attributes #5 = { 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 0}
!12 = !{!"_ZTS4Node", !10, i64 0, !6, i64 8, !6, i64 16}
!13 = !{!12, !6, i64 8}
!14 = !{!12, !6, i64 16}


; 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: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN3BST11findMinNodeEP4Node(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef ptr @_ZN3BST10deleteNodeEP4Nodei(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #1 align 2 {
  %4 = icmp eq ptr %1, null
  br i1 %4, label %common.ret38, label %5

5:                                                ; preds = %3
  %6 = load i32, ptr %1, align 8, !tbaa !5
  %7 = icmp sgt i32 %6, %2
  br i1 %7, label %8, label %12

common.ret38:                                     ; preds = %27, %3, %24, %28, %14, %8
  %common.ret38.op = phi ptr [ %1, %8 ], [ %1, %14 ], [ %1, %28 ], [ null, %3 ], [ %20, %27 ], [ %23, %24 ]
  ret ptr %common.ret38.op

8:                                                ; preds = %5
  %9 = getelementptr inbounds i8, ptr %1, i64 8
  %10 = load ptr, ptr %9, align 8, !tbaa !11
  %11 = tail call noundef ptr @_ZN3BST10deleteNodeEP4Nodei(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr noundef %10, i32 noundef %2)
  store ptr %11, ptr %9, align 8, !tbaa !11
  br label %common.ret38

12:                                               ; preds = %5
  %13 = icmp slt i32 %6, %2
  br i1 %13, label %14, label %18

14:                                               ; preds = %12
  %15 = getelementptr inbounds i8, ptr %1, i64 16
  %16 = load ptr, ptr %15, align 8, !tbaa !12
  %17 = tail call noundef ptr @_ZN3BST10deleteNodeEP4Nodei(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr noundef %16, i32 noundef %2)
  store ptr %17, ptr %15, align 8, !tbaa !12
  br label %common.ret38

18:                                               ; preds = %12
  %19 = getelementptr inbounds i8, ptr %1, i64 8
  %20 = load ptr, ptr %19, align 8, !tbaa !11
  %21 = icmp eq ptr %20, null
  %22 = getelementptr inbounds i8, ptr %1, i64 16
  %23 = load ptr, ptr %22, align 8, !tbaa !12
  br i1 %21, label %24, label %25

24:                                               ; preds = %18
  tail call void @_ZdlPvm(ptr noundef nonnull %1, i64 noundef 24) #2
  br label %common.ret38

25:                                               ; preds = %18
  %26 = icmp eq ptr %23, null
  br i1 %26, label %27, label %28

27:                                               ; preds = %25
  tail call void @_ZdlPvm(ptr noundef nonnull %1, i64 noundef 24) #2
  br label %common.ret38

28:                                               ; preds = %25
  %29 = tail call noundef ptr @_ZN3BST11findMinNodeEP4Node(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr noundef nonnull %23)
  %30 = load i32, ptr %29, align 8, !tbaa !5
  store i32 %30, ptr %1, align 8, !tbaa !5
  %31 = load ptr, ptr %22, align 8, !tbaa !12
  %32 = tail call noundef ptr @_ZN3BST10deleteNodeEP4Nodei(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr noundef %31, i32 noundef %30)
  store ptr %32, ptr %22, align 8, !tbaa !12
  br label %common.ret38
}

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


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