; LLVM IR from TheAlgorithms/C-Plus-Plus :: data_structures/tree_234.ll (ZN15data_structures8tree_2347Tree23410DeleteNodeEPNS0_4NodeE)

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN15data_structures8tree_2347Tree23410DeleteNodeEPNS0_4NodeE(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr noundef %1) #0 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i8, align 1
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %6 = load ptr, ptr %3, align 8
  %7 = load ptr, ptr %4, align 8, !tbaa !5
  %8 = icmp ne ptr %7, null
  br i1 %8, label %10, label %9

9:                                                ; preds = %2
  br label %30

10:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 1, ptr %5) #4
  store i8 0, ptr %5, align 1, !tbaa !9
  br label %11

11:                                               ; preds = %23, %10
  %12 = load i8, ptr %5, align 1, !tbaa !9
  %13 = sext i8 %12 to i32
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = call noundef signext i8 @_ZN15data_structures8tree_2344Node8GetCountEv(ptr noundef nonnull align 8 dereferenceable(57) %14)
  %16 = sext i8 %15 to i32
  %17 = icmp sle i32 %13, %16
  br i1 %17, label %19, label %18

18:                                               ; preds = %11
  call void @llvm.lifetime.end.p0(i64 1, ptr %5) #4
  br label %26

19:                                               ; preds = %11
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = load i8, ptr %5, align 1, !tbaa !9
  %22 = call noundef ptr @_ZN15data_structures8tree_2344Node8GetChildEa(ptr noundef nonnull align 8 dereferenceable(57) %20, i8 noundef signext %21)
  call void @_ZN15data_structures8tree_2347Tree23410DeleteNodeEPNS0_4NodeE(ptr noundef nonnull align 8 dereferenceable(8) %6, ptr noundef %22)
  br label %23

23:                                               ; preds = %19
  %24 = load i8, ptr %5, align 1, !tbaa !9
  %25 = add i8 %24, 1
  store i8 %25, ptr %5, align 1, !tbaa !9
  br label %11, !llvm.loop !10

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

29:                                               ; preds = %26
  call void @_ZdlPvm(ptr noundef %27, i64 noundef 64) #5
  br label %30

30:                                               ; preds = %29, %26, %9
  ret void
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef signext i8 @_ZN15data_structures8tree_2344Node8GetCountEv(ptr noundef nonnull align 8 dereferenceable(57)) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN15data_structures8tree_2344Node8GetChildEa(ptr noundef nonnull align 8 dereferenceable(57), i8 noundef signext) #2 align 2

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

; 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"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
define dso_local void @_ZN15data_structures8tree_2347Tree23410DeleteNodeEPNS0_4NodeE(ptr nocapture noundef nonnull readnone align 8 dereferenceable(8) %0, ptr noundef %1) local_unnamed_addr #0 align 2 {
  %.not = icmp eq ptr %1, null
  br i1 %.not, label %7, label %.preheader

.preheader:                                       ; preds = %2
  %3 = tail call noundef signext i8 @_ZN15data_structures8tree_2344Node8GetCountEv(ptr noundef nonnull align 8 dereferenceable(57) %1)
  %.not89 = icmp slt i8 %3, 0
  br i1 %.not89, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %.010 = phi i8 [ %5, %.lr.ph ], [ 0, %.preheader ]
  %4 = tail call noundef ptr @_ZN15data_structures8tree_2344Node8GetChildEa(ptr noundef nonnull align 8 dereferenceable(57) %1, i8 noundef signext %.010)
  tail call void @_ZN15data_structures8tree_2347Tree23410DeleteNodeEPNS0_4NodeE(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr noundef %4)
  %5 = add i8 %.010, 1
  %6 = tail call noundef signext i8 @_ZN15data_structures8tree_2344Node8GetCountEv(ptr noundef nonnull align 8 dereferenceable(57) %1)
  %.not8 = icmp sgt i8 %5, %6
  br i1 %.not8, label %._crit_edge, label %.lr.ph, !llvm.loop !5

._crit_edge:                                      ; preds = %.lr.ph, %.preheader
  tail call void @_ZdlPvm(ptr noundef %1, i64 noundef 64) #2
  br label %7

7:                                                ; preds = %2, %._crit_edge
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef signext i8 @_ZN15data_structures8tree_2344Node8GetCountEv(ptr noundef nonnull align 8 dereferenceable(57)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN15data_structures8tree_2344Node8GetChildEa(ptr noundef nonnull align 8 dereferenceable(57), i8 noundef signext) local_unnamed_addr #0 align 2

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

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" }
attributes #1 = { 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 #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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


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