; LLVM IR from HarshCasper/NeoAlgo :: C-Plus-Plus/ds/BinarySearchTree.ll (Z6DeleteP4Nodei)

; 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, i32, 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 uwtable
declare dso_local noundef i32 @_Z6HeightP4Node(ptr noundef) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_Z17InOrderpredecssorP4Node(ptr noundef) #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_Z16InOrderSuccessorP4Node(ptr noundef) #2

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_Z6DeleteP4Nodei(ptr noundef %0, i32 noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = icmp eq ptr %8, null
  br i1 %9, label %10, label %11

10:                                               ; preds = %2
  store ptr null, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %106

11:                                               ; preds = %2
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.Node, ptr %12, i32 0, i32 0
  %14 = load ptr, ptr %13, align 8, !tbaa !11
  %15 = icmp eq ptr %14, null
  br i1 %15, label %16, label %26

16:                                               ; preds = %11
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.Node, ptr %17, i32 0, i32 2
  %19 = load ptr, ptr %18, align 8, !tbaa !13
  %20 = icmp eq ptr %19, null
  br i1 %20, label %21, label %26

21:                                               ; preds = %16
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = icmp eq ptr %22, null
  br i1 %23, label %25, label %24

24:                                               ; preds = %21
  call void @_ZdlPvm(ptr noundef %22, i64 noundef 24) #5
  br label %25

25:                                               ; preds = %24, %21
  store ptr null, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %106

26:                                               ; preds = %16, %11
  %27 = load i32, ptr %5, align 4, !tbaa !9
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.Node, ptr %28, i32 0, i32 1
  %30 = load i32, ptr %29, align 8, !tbaa !14
  %31 = icmp slt i32 %27, %30
  br i1 %31, label %32, label %40

32:                                               ; preds = %26
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.Node, ptr %33, i32 0, i32 0
  %35 = load ptr, ptr %34, align 8, !tbaa !11
  %36 = load i32, ptr %5, align 4, !tbaa !9
  %37 = call noundef ptr @_Z6DeleteP4Nodei(ptr noundef %35, i32 noundef %36)
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.Node, ptr %38, i32 0, i32 0
  store ptr %37, ptr %39, align 8, !tbaa !11
  br label %104

40:                                               ; preds = %26
  %41 = load i32, ptr %5, align 4, !tbaa !9
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.Node, ptr %42, i32 0, i32 1
  %44 = load i32, ptr %43, align 8, !tbaa !14
  %45 = icmp sgt i32 %41, %44
  br i1 %45, label %46, label %54

46:                                               ; preds = %40
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.Node, ptr %47, i32 0, i32 2
  %49 = load ptr, ptr %48, align 8, !tbaa !13
  %50 = load i32, ptr %5, align 4, !tbaa !9
  %51 = call noundef ptr @_Z6DeleteP4Nodei(ptr noundef %49, i32 noundef %50)
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.Node, ptr %52, i32 0, i32 2
  store ptr %51, ptr %53, align 8, !tbaa !13
  br label %103

54:                                               ; preds = %40
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.Node, ptr %55, i32 0, i32 0
  %57 = load ptr, ptr %56, align 8, !tbaa !11
  %58 = call noundef i32 @_Z6HeightP4Node(ptr noundef %57)
  %59 = load ptr, ptr %4, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.Node, ptr %59, i32 0, i32 2
  %61 = load ptr, ptr %60, align 8, !tbaa !13
  %62 = call noundef i32 @_Z6HeightP4Node(ptr noundef %61)
  %63 = icmp sgt i32 %58, %62
  br i1 %63, label %64, label %83

64:                                               ; preds = %54
  %65 = load ptr, ptr %4, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.Node, ptr %65, i32 0, i32 0
  %67 = load ptr, ptr %66, align 8, !tbaa !11
  %68 = call noundef ptr @_Z17InOrderpredecssorP4Node(ptr noundef %67)
  store ptr %68, ptr %6, align 8, !tbaa !5
  %69 = load ptr, ptr %6, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.Node, ptr %69, i32 0, i32 1
  %71 = load i32, ptr %70, align 8, !tbaa !14
  %72 = load ptr, ptr %4, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.Node, ptr %72, i32 0, i32 1
  store i32 %71, ptr %73, align 8, !tbaa !14
  %74 = load ptr, ptr %4, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.Node, ptr %74, i32 0, i32 0
  %76 = load ptr, ptr %75, align 8, !tbaa !11
  %77 = load ptr, ptr %6, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.Node, ptr %77, i32 0, i32 1
  %79 = load i32, ptr %78, align 8, !tbaa !14
  %80 = call noundef ptr @_Z6DeleteP4Nodei(ptr noundef %76, i32 noundef %79)
  %81 = load ptr, ptr %4, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.Node, ptr %81, i32 0, i32 0
  store ptr %80, ptr %82, align 8, !tbaa !11
  br label %102

83:                                               ; preds = %54
  %84 = load ptr, ptr %4, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.Node, ptr %84, i32 0, i32 2
  %86 = load ptr, ptr %85, align 8, !tbaa !13
  %87 = call noundef ptr @_Z16InOrderSuccessorP4Node(ptr noundef %86)
  store ptr %87, ptr %6, align 8, !tbaa !5
  %88 = load ptr, ptr %6, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.Node, ptr %88, i32 0, i32 1
  %90 = load i32, ptr %89, align 8, !tbaa !14
  %91 = load ptr, ptr %4, align 8, !tbaa !5
  %92 = getelementptr inbounds %struct.Node, ptr %91, i32 0, i32 1
  store i32 %90, ptr %92, align 8, !tbaa !14
  %93 = load ptr, ptr %4, align 8, !tbaa !5
  %94 = getelementptr inbounds %struct.Node, ptr %93, i32 0, i32 2
  %95 = load ptr, ptr %94, align 8, !tbaa !13
  %96 = load ptr, ptr %6, align 8, !tbaa !5
  %97 = getelementptr inbounds %struct.Node, ptr %96, i32 0, i32 1
  %98 = load i32, ptr %97, align 8, !tbaa !14
  %99 = call noundef ptr @_Z6DeleteP4Nodei(ptr noundef %95, i32 noundef %98)
  %100 = load ptr, ptr %4, align 8, !tbaa !5
  %101 = getelementptr inbounds %struct.Node, ptr %100, i32 0, i32 2
  store ptr %99, ptr %101, align 8, !tbaa !13
  br label %102

102:                                              ; preds = %83, %64
  br label %103

103:                                              ; preds = %102, %46
  br label %104

104:                                              ; preds = %103, %32
  %105 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %105, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %106

106:                                              ; preds = %104, %25, %10
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  %107 = load ptr, ptr %3, align 8
  ret ptr %107
}

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

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 = { 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 = { nounwind }
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, !6, i64 0}
!12 = !{!"_ZTS4Node", !6, i64 0, !10, i64 8, !6, i64 16}
!13 = !{!12, !6, i64 16}
!14 = !{!12, !10, 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
declare dso_local noundef i32 @_Z6HeightP4Node(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_Z17InOrderpredecssorP4Node(ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_Z16InOrderSuccessorP4Node(ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_Z6DeleteP4Nodei(ptr noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = icmp eq ptr %0, null
  br i1 %3, label %common.ret32, label %4

4:                                                ; preds = %2
  %5 = load ptr, ptr %0, align 8, !tbaa !5
  %6 = icmp eq ptr %5, null
  br i1 %6, label %7, label %12

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

11:                                               ; preds = %7
  tail call void @_ZdlPvm(ptr noundef nonnull %0, i64 noundef 24) #3
  br label %common.ret32

12:                                               ; preds = %7, %4
  %13 = getelementptr inbounds i8, ptr %0, i64 8
  %14 = load i32, ptr %13, align 8, !tbaa !12
  %15 = icmp sgt i32 %14, %1
  br i1 %15, label %16, label %18

common.ret32:                                     ; preds = %2, %11, %37, %30, %20, %16
  %common.ret32.op = phi ptr [ %0, %16 ], [ %0, %20 ], [ %0, %30 ], [ %0, %37 ], [ null, %11 ], [ null, %2 ]
  ret ptr %common.ret32.op

16:                                               ; preds = %12
  %17 = tail call noundef ptr @_Z6DeleteP4Nodei(ptr noundef %5, i32 noundef %1)
  store ptr %17, ptr %0, align 8, !tbaa !5
  br label %common.ret32

18:                                               ; preds = %12
  %19 = icmp slt i32 %14, %1
  br i1 %19, label %20, label %24

20:                                               ; preds = %18
  %21 = getelementptr inbounds i8, ptr %0, i64 16
  %22 = load ptr, ptr %21, align 8, !tbaa !11
  %23 = tail call noundef ptr @_Z6DeleteP4Nodei(ptr noundef %22, i32 noundef %1)
  store ptr %23, ptr %21, align 8, !tbaa !11
  br label %common.ret32

24:                                               ; preds = %18
  %25 = tail call noundef i32 @_Z6HeightP4Node(ptr noundef %5)
  %26 = getelementptr inbounds i8, ptr %0, i64 16
  %27 = load ptr, ptr %26, align 8, !tbaa !11
  %28 = tail call noundef i32 @_Z6HeightP4Node(ptr noundef %27)
  %29 = icmp sgt i32 %25, %28
  br i1 %29, label %30, label %37

30:                                               ; preds = %24
  %31 = load ptr, ptr %0, align 8, !tbaa !5
  %32 = tail call noundef ptr @_Z17InOrderpredecssorP4Node(ptr noundef %31)
  %33 = getelementptr inbounds i8, ptr %32, i64 8
  %34 = load i32, ptr %33, align 8, !tbaa !12
  store i32 %34, ptr %13, align 8, !tbaa !12
  %35 = load ptr, ptr %0, align 8, !tbaa !5
  %36 = tail call noundef ptr @_Z6DeleteP4Nodei(ptr noundef %35, i32 noundef %34)
  store ptr %36, ptr %0, align 8, !tbaa !5
  br label %common.ret32

37:                                               ; preds = %24
  %38 = load ptr, ptr %26, align 8, !tbaa !11
  %39 = tail call noundef ptr @_Z16InOrderSuccessorP4Node(ptr noundef %38)
  %40 = getelementptr inbounds i8, ptr %39, i64 8
  %41 = load i32, ptr %40, align 8, !tbaa !12
  store i32 %41, ptr %13, align 8, !tbaa !12
  %42 = load ptr, ptr %26, align 8, !tbaa !11
  %43 = tail call noundef ptr @_Z6DeleteP4Nodei(ptr noundef %42, i32 noundef %41)
  store ptr %43, ptr %26, align 8, !tbaa !11
  br label %common.ret32
}

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

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 = { 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 = { 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 #3 = { 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, !7, 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 16}
!12 = !{!6, !10, i64 8}


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