; LLVM IR from ahampriyanshu/algo-ds-101 :: Data-Structures/Tree/23-Tree/23Tree.ll (Z10deleteNodei)

; 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 { [3 x i32], ptr, ptr, ptr, ptr, ptr, i32 }

@root = external dso_local global ptr, align 8

; 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 ptr @_Z6searchP8TreeNodei(ptr noundef, i32 noundef) #1

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

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

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

; Function Attrs: nounwind
declare void @free(ptr noundef) #3

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_Z6getMinP8TreeNode(ptr noundef) #1

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z10deleteNodei(i32 noundef %0) #1 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  store i32 %0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  %5 = load ptr, ptr @root, align 8, !tbaa !9
  %6 = load i32, ptr %2, align 4, !tbaa !5
  %7 = call noundef ptr @_Z6searchP8TreeNodei(ptr noundef %5, i32 noundef %6)
  store ptr %7, ptr %3, align 8, !tbaa !9
  %8 = load ptr, ptr %3, align 8, !tbaa !9
  %9 = call noundef zeroext i1 @_Z6isLeafP8TreeNode(ptr noundef %8)
  br i1 %9, label %10, label %48

10:                                               ; preds = %1
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = load ptr, ptr %3, align 8, !tbaa !9
  %13 = getelementptr inbounds %struct.TreeNode, ptr %12, i32 0, i32 0
  %14 = getelementptr inbounds [3 x i32], ptr %13, i64 0, i64 0
  %15 = load i32, ptr %14, align 8, !tbaa !5
  %16 = icmp eq i32 %11, %15
  br i1 %16, label %17, label %28

17:                                               ; preds = %10
  %18 = load ptr, ptr %3, align 8, !tbaa !9
  %19 = getelementptr inbounds %struct.TreeNode, ptr %18, i32 0, i32 0
  %20 = getelementptr inbounds [3 x i32], ptr %19, i64 0, i64 1
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = load ptr, ptr %3, align 8, !tbaa !9
  %23 = getelementptr inbounds %struct.TreeNode, ptr %22, i32 0, i32 0
  %24 = getelementptr inbounds [3 x i32], ptr %23, i64 0, i64 0
  store i32 %21, ptr %24, align 8, !tbaa !5
  %25 = load ptr, ptr %3, align 8, !tbaa !9
  %26 = getelementptr inbounds %struct.TreeNode, ptr %25, i32 0, i32 0
  %27 = getelementptr inbounds [3 x i32], ptr %26, i64 0, i64 1
  store i32 2147483647, ptr %27, align 4, !tbaa !5
  br label %32

28:                                               ; preds = %10
  %29 = load ptr, ptr %3, align 8, !tbaa !9
  %30 = getelementptr inbounds %struct.TreeNode, ptr %29, i32 0, i32 0
  %31 = getelementptr inbounds [3 x i32], ptr %30, i64 0, i64 1
  store i32 2147483647, ptr %31, align 4, !tbaa !5
  br label %32

32:                                               ; preds = %28, %17
  %33 = load ptr, ptr %3, align 8, !tbaa !9
  %34 = getelementptr inbounds %struct.TreeNode, ptr %33, i32 0, i32 6
  %35 = load i32, ptr %34, align 8, !tbaa !11
  %36 = add nsw i32 %35, -1
  store i32 %36, ptr %34, align 8, !tbaa !11
  %37 = load ptr, ptr %3, align 8, !tbaa !9
  %38 = call noundef zeroext i1 @_Z11isUnderflowP8TreeNode(ptr noundef %37)
  br i1 %38, label %39, label %47

39:                                               ; preds = %32
  %40 = load ptr, ptr %3, align 8, !tbaa !9
  %41 = call noundef zeroext i1 @_Z6isRootP8TreeNode(ptr noundef %40)
  br i1 %41, label %42, label %44

42:                                               ; preds = %39
  %43 = load ptr, ptr @root, align 8, !tbaa !9
  call void @free(ptr noundef %43) #4
  store ptr null, ptr @root, align 8, !tbaa !9
  br label %46

44:                                               ; preds = %39
  %45 = load ptr, ptr %3, align 8, !tbaa !9
  call void @_Z12fixUnderflowP8TreeNode(ptr noundef %45)
  br label %46

46:                                               ; preds = %44, %42
  br label %47

47:                                               ; preds = %46, %32
  br label %108

48:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  store ptr null, ptr %4, align 8, !tbaa !9
  %49 = load i32, ptr %2, align 4, !tbaa !5
  %50 = load ptr, ptr %3, align 8, !tbaa !9
  %51 = getelementptr inbounds %struct.TreeNode, ptr %50, i32 0, i32 0
  %52 = getelementptr inbounds [3 x i32], ptr %51, i64 0, i64 0
  %53 = load i32, ptr %52, align 8, !tbaa !5
  %54 = icmp eq i32 %49, %53
  br i1 %54, label %55, label %60

55:                                               ; preds = %48
  %56 = load ptr, ptr %3, align 8, !tbaa !9
  %57 = getelementptr inbounds %struct.TreeNode, ptr %56, i32 0, i32 2
  %58 = load ptr, ptr %57, align 8, !tbaa !13
  %59 = call noundef ptr @_Z6getMinP8TreeNode(ptr noundef %58)
  store ptr %59, ptr %4, align 8, !tbaa !9
  br label %65

60:                                               ; preds = %48
  %61 = load ptr, ptr %3, align 8, !tbaa !9
  %62 = getelementptr inbounds %struct.TreeNode, ptr %61, i32 0, i32 3
  %63 = load ptr, ptr %62, align 8, !tbaa !14
  %64 = call noundef ptr @_Z6getMinP8TreeNode(ptr noundef %63)
  store ptr %64, ptr %4, align 8, !tbaa !9
  br label %65

65:                                               ; preds = %60, %55
  %66 = load i32, ptr %2, align 4, !tbaa !5
  %67 = load ptr, ptr %3, align 8, !tbaa !9
  %68 = getelementptr inbounds %struct.TreeNode, ptr %67, i32 0, i32 0
  %69 = getelementptr inbounds [3 x i32], ptr %68, i64 0, i64 0
  %70 = load i32, ptr %69, align 8, !tbaa !5
  %71 = icmp eq i32 %66, %70
  br i1 %71, label %72, label %80

72:                                               ; preds = %65
  %73 = load ptr, ptr %4, align 8, !tbaa !9
  %74 = getelementptr inbounds %struct.TreeNode, ptr %73, i32 0, i32 0
  %75 = getelementptr inbounds [3 x i32], ptr %74, i64 0, i64 0
  %76 = load i32, ptr %75, align 8, !tbaa !5
  %77 = load ptr, ptr %3, align 8, !tbaa !9
  %78 = getelementptr inbounds %struct.TreeNode, ptr %77, i32 0, i32 0
  %79 = getelementptr inbounds [3 x i32], ptr %78, i64 0, i64 0
  store i32 %76, ptr %79, align 8, !tbaa !5
  br label %88

80:                                               ; preds = %65
  %81 = load ptr, ptr %4, align 8, !tbaa !9
  %82 = getelementptr inbounds %struct.TreeNode, ptr %81, i32 0, i32 0
  %83 = getelementptr inbounds [3 x i32], ptr %82, i64 0, i64 0
  %84 = load i32, ptr %83, align 8, !tbaa !5
  %85 = load ptr, ptr %3, align 8, !tbaa !9
  %86 = getelementptr inbounds %struct.TreeNode, ptr %85, i32 0, i32 0
  %87 = getelementptr inbounds [3 x i32], ptr %86, i64 0, i64 1
  store i32 %84, ptr %87, align 4, !tbaa !5
  br label %88

88:                                               ; preds = %80, %72
  %89 = load ptr, ptr %4, align 8, !tbaa !9
  %90 = getelementptr inbounds %struct.TreeNode, ptr %89, i32 0, i32 0
  %91 = getelementptr inbounds [3 x i32], ptr %90, i64 0, i64 1
  %92 = load i32, ptr %91, align 4, !tbaa !5
  %93 = load ptr, ptr %4, align 8, !tbaa !9
  %94 = getelementptr inbounds %struct.TreeNode, ptr %93, i32 0, i32 0
  %95 = getelementptr inbounds [3 x i32], ptr %94, i64 0, i64 0
  store i32 %92, ptr %95, align 8, !tbaa !5
  %96 = load ptr, ptr %4, align 8, !tbaa !9
  %97 = getelementptr inbounds %struct.TreeNode, ptr %96, i32 0, i32 0
  %98 = getelementptr inbounds [3 x i32], ptr %97, i64 0, i64 1
  store i32 2147483647, ptr %98, align 4, !tbaa !5
  %99 = load ptr, ptr %4, align 8, !tbaa !9
  %100 = getelementptr inbounds %struct.TreeNode, ptr %99, i32 0, i32 6
  %101 = load i32, ptr %100, align 8, !tbaa !11
  %102 = add nsw i32 %101, -1
  store i32 %102, ptr %100, align 8, !tbaa !11
  %103 = load ptr, ptr %4, align 8, !tbaa !9
  %104 = call noundef zeroext i1 @_Z11isUnderflowP8TreeNode(ptr noundef %103)
  br i1 %104, label %105, label %107

105:                                              ; preds = %88
  %106 = load ptr, ptr %4, align 8, !tbaa !9
  call void @_Z12fixUnderflowP8TreeNode(ptr noundef %106)
  br label %107

107:                                              ; preds = %105, %88
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  br label %108

108:                                              ; preds = %107, %47
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  ret void
}

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 = { 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 }

!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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !6, i64 56}
!12 = !{!"_ZTS8TreeNode", !7, i64 0, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !6, i64 56}
!13 = !{!12, !10, i64 24}
!14 = !{!12, !10, i64 32}


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

@root = external dso_local local_unnamed_addr global ptr, align 8

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_Z6searchP8TreeNodei(ptr noundef, i32 noundef) local_unnamed_addr #0

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

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

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

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_Z6getMinP8TreeNode(ptr noundef) local_unnamed_addr #0

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z10deleteNodei(i32 noundef %0) local_unnamed_addr #0 {
  %2 = load ptr, ptr @root, align 8, !tbaa !5
  %3 = tail call noundef ptr @_Z6searchP8TreeNodei(ptr noundef %2, i32 noundef %0)
  %4 = tail call noundef zeroext i1 @_Z6isLeafP8TreeNode(ptr noundef %3)
  %5 = load i32, ptr %3, align 8, !tbaa !9
  %6 = icmp eq i32 %5, %0
  br i1 %4, label %7, label %21

7:                                                ; preds = %1
  %8 = getelementptr inbounds i8, ptr %3, i64 4
  br i1 %6, label %9, label %11

9:                                                ; preds = %7
  %10 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %10, ptr %3, align 8, !tbaa !9
  br label %11

11:                                               ; preds = %7, %9
  store i32 2147483647, ptr %8, align 4, !tbaa !9
  %12 = getelementptr inbounds i8, ptr %3, i64 56
  %13 = load i32, ptr %12, align 8, !tbaa !11
  %14 = add nsw i32 %13, -1
  store i32 %14, ptr %12, align 8, !tbaa !11
  %15 = tail call noundef zeroext i1 @_Z11isUnderflowP8TreeNode(ptr noundef nonnull %3)
  br i1 %15, label %16, label %39

16:                                               ; preds = %11
  %17 = tail call noundef zeroext i1 @_Z6isRootP8TreeNode(ptr noundef nonnull %3)
  br i1 %17, label %18, label %20

18:                                               ; preds = %16
  %19 = load ptr, ptr @root, align 8, !tbaa !5
  tail call void @free(ptr noundef %19) #3
  store ptr null, ptr @root, align 8, !tbaa !5
  br label %39

20:                                               ; preds = %16
  tail call void @_Z12fixUnderflowP8TreeNode(ptr noundef nonnull %3)
  br label %39

21:                                               ; preds = %1
  %. = select i1 %6, i64 24, i64 32
  %22 = getelementptr inbounds i8, ptr %3, i64 %.
  %23 = load ptr, ptr %22, align 8, !tbaa !5
  %24 = tail call noundef ptr @_Z6getMinP8TreeNode(ptr noundef %23)
  %25 = load i32, ptr %3, align 8, !tbaa !9
  %26 = icmp eq i32 %25, %0
  %27 = load i32, ptr %24, align 8, !tbaa !9
  br i1 %26, label %28, label %29

28:                                               ; preds = %21
  store i32 %27, ptr %3, align 8, !tbaa !9
  br label %31

29:                                               ; preds = %21
  %30 = getelementptr inbounds i8, ptr %3, i64 4
  store i32 %27, ptr %30, align 4, !tbaa !9
  br label %31

31:                                               ; preds = %29, %28
  %32 = getelementptr inbounds i8, ptr %24, i64 4
  %33 = load i32, ptr %32, align 4, !tbaa !9
  store i32 %33, ptr %24, align 8, !tbaa !9
  store i32 2147483647, ptr %32, align 4, !tbaa !9
  %34 = getelementptr inbounds i8, ptr %24, i64 56
  %35 = load i32, ptr %34, align 8, !tbaa !11
  %36 = add nsw i32 %35, -1
  store i32 %36, ptr %34, align 8, !tbaa !11
  %37 = tail call noundef zeroext i1 @_Z11isUnderflowP8TreeNode(ptr noundef nonnull %24)
  br i1 %37, label %38, label %39

38:                                               ; preds = %31
  tail call void @_Z12fixUnderflowP8TreeNode(ptr noundef nonnull %24)
  br label %39

39:                                               ; preds = %31, %38, %11, %20, %18
  ret void
}

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 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { 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 56}
!12 = !{!"_ZTS8TreeNode", !7, i64 0, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !10, i64 56}


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