; LLVM IR from AnneLivia/Competitive-Programming :: Data Structures/Tree/Binary Search Tree/bst.ll (Z12delete_valuePP4Nodei)

; 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: 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 noundef ptr @_Z14remove_currentP4Node(ptr noundef) #1

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

11:                                               ; preds = %2
  store i32 0, ptr %3, align 4
  br label %69

12:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = load ptr, ptr %13, align 8, !tbaa !5
  store ptr %14, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  store ptr null, ptr %7, align 8, !tbaa !5
  br label %15

15:                                               ; preds = %66, %12
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = icmp ne ptr %16, null
  br i1 %17, label %18, label %67

18:                                               ; preds = %15
  %19 = load i32, ptr %5, align 4, !tbaa !9
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.Node, ptr %20, i32 0, i32 0
  %22 = load i32, ptr %21, align 8, !tbaa !11
  %23 = icmp eq i32 %19, %22
  br i1 %23, label %24, label %51

24:                                               ; preds = %18
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = load ptr, ptr %26, align 8, !tbaa !5
  %28 = icmp eq ptr %25, %27
  br i1 %28, label %29, label %33

29:                                               ; preds = %24
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = call noundef ptr @_Z14remove_currentP4Node(ptr noundef %30)
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %31, ptr %32, align 8, !tbaa !5
  br label %50

33:                                               ; preds = %24
  %34 = load ptr, ptr %7, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.Node, ptr %34, i32 0, i32 2
  %36 = load ptr, ptr %35, align 8, !tbaa !13
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = icmp eq ptr %36, %37
  br i1 %38, label %39, label %44

39:                                               ; preds = %33
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = call noundef ptr @_Z14remove_currentP4Node(ptr noundef %40)
  %42 = load ptr, ptr %7, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.Node, ptr %42, i32 0, i32 2
  store ptr %41, ptr %43, align 8, !tbaa !13
  br label %49

44:                                               ; preds = %33
  %45 = load ptr, ptr %6, align 8, !tbaa !5
  %46 = call noundef ptr @_Z14remove_currentP4Node(ptr noundef %45)
  %47 = load ptr, ptr %7, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.Node, ptr %47, i32 0, i32 1
  store ptr %46, ptr %48, align 8, !tbaa !14
  br label %49

49:                                               ; preds = %44, %39
  br label %50

50:                                               ; preds = %49, %29
  store i32 1, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %68

51:                                               ; preds = %18
  %52 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %52, ptr %7, align 8, !tbaa !5
  %53 = load i32, ptr %5, align 4, !tbaa !9
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.Node, ptr %54, i32 0, i32 0
  %56 = load i32, ptr %55, align 8, !tbaa !11
  %57 = icmp sgt i32 %53, %56
  br i1 %57, label %58, label %62

58:                                               ; preds = %51
  %59 = load ptr, ptr %6, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.Node, ptr %59, i32 0, i32 2
  %61 = load ptr, ptr %60, align 8, !tbaa !13
  store ptr %61, ptr %6, align 8, !tbaa !5
  br label %66

62:                                               ; preds = %51
  %63 = load ptr, ptr %6, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.Node, ptr %63, i32 0, i32 1
  %65 = load ptr, ptr %64, align 8, !tbaa !14
  store ptr %65, ptr %6, align 8, !tbaa !5
  br label %66

66:                                               ; preds = %62, %58
  br label %15, !llvm.loop !15

67:                                               ; preds = %15
  store i32 0, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %68

68:                                               ; preds = %67, %50
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  br label %69

69:                                               ; preds = %68, %11
  %70 = load i32, ptr %3, align 4
  ret i32 %70
}

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 = { 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 16}
!14 = !{!12, !6, i64 8}
!15 = distinct !{!15, !16}
!16 = !{!"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 noundef ptr @_Z14remove_currentP4Node(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef range(i32 0, 2) i32 @_Z12delete_valuePP4Nodei(ptr noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = icmp eq ptr %0, null
  br i1 %3, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %2
  %.02028 = load ptr, ptr %0, align 8, !tbaa !5
  %.not29 = icmp eq ptr %.02028, null
  br i1 %.not29, label %.loopexit, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %.preheader
  %4 = load i32, ptr %.02028, align 8, !tbaa !9
  %5 = icmp eq i32 %4, %1
  br i1 %5, label %.lr.ph._crit_edge, label %.lr.ph39

.lr.ph:                                           ; preds = %.lr.ph39
  %6 = load i32, ptr %.020, align 8, !tbaa !9
  %7 = icmp eq i32 %6, %1
  br i1 %7, label %.lr.ph._crit_edge, label %.lr.ph39, !llvm.loop !12

.lr.ph._crit_edge:                                ; preds = %.lr.ph, %.lr.ph.preheader
  %.02031.lcssa = phi ptr [ %.02028, %.lr.ph.preheader ], [ %.020, %.lr.ph ]
  %.030.lcssa = phi ptr [ null, %.lr.ph.preheader ], [ %.0203138, %.lr.ph ]
  %8 = icmp eq ptr %.02031.lcssa, %.02028
  br i1 %8, label %9, label %11

9:                                                ; preds = %.lr.ph._crit_edge
  %10 = tail call noundef ptr @_Z14remove_currentP4Node(ptr noundef nonnull %.02031.lcssa)
  store ptr %10, ptr %0, align 8, !tbaa !5
  br label %.loopexit

11:                                               ; preds = %.lr.ph._crit_edge
  %12 = getelementptr inbounds i8, ptr %.030.lcssa, i64 16
  %13 = load ptr, ptr %12, align 8, !tbaa !14
  %14 = icmp eq ptr %13, %.02031.lcssa
  %15 = tail call noundef ptr @_Z14remove_currentP4Node(ptr noundef nonnull %.02031.lcssa)
  br i1 %14, label %16, label %17

16:                                               ; preds = %11
  store ptr %15, ptr %12, align 8, !tbaa !14
  br label %.loopexit

17:                                               ; preds = %11
  %18 = getelementptr inbounds i8, ptr %.030.lcssa, i64 8
  store ptr %15, ptr %18, align 8, !tbaa !15
  br label %.loopexit

.lr.ph39:                                         ; preds = %.lr.ph.preheader, %.lr.ph
  %19 = phi i32 [ %6, %.lr.ph ], [ %4, %.lr.ph.preheader ]
  %.0203138 = phi ptr [ %.020, %.lr.ph ], [ %.02028, %.lr.ph.preheader ]
  %20 = icmp slt i32 %19, %1
  %.1.in.v = select i1 %20, i64 16, i64 8
  %.1.in = getelementptr inbounds i8, ptr %.0203138, i64 %.1.in.v
  %.020 = load ptr, ptr %.1.in, align 8, !tbaa !5
  %.not = icmp eq ptr %.020, null
  br i1 %.not, label %.loopexit, label %.lr.ph, !llvm.loop !12

.loopexit:                                        ; preds = %.lr.ph39, %.preheader, %16, %17, %9, %2
  %.122 = phi i32 [ 0, %2 ], [ 1, %16 ], [ 1, %17 ], [ 1, %9 ], [ 0, %.preheader ], [ 0, %.lr.ph39 ]
  ret i32 %.122
}

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

!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, !11, i64 0}
!10 = !{!"_ZTS4Node", !11, i64 0, !6, i64 8, !6, i64 16}
!11 = !{!"int", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!10, !6, i64 16}
!15 = !{!10, !6, i64 8}


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