; LLVM IR from MostafaTwfiq/C-DataStructures-And-Algorithms :: DataStructure/Trees/Sources (RedBlackTree)

; 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.RBTree = type { ptr, i32, ptr, ptr }
%struct.RBNode = type { ptr, i32, ptr, ptr, ptr }

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

9:                                                ; preds = %3
  br label %90

10:                                               ; preds = %3
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.RBTree, ptr %11, i32 0, i32 3
  %13 = load ptr, ptr %12, align 8, !tbaa !9
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.RBNode, ptr %15, i32 0, i32 0
  %17 = load ptr, ptr %16, align 8, !tbaa !12
  %18 = call i32 %13(ptr noundef %14, ptr noundef %17)
  %19 = icmp eq i32 %18, 0
  br i1 %19, label %20, label %55

20:                                               ; preds = %10
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.RBNode, ptr %21, i32 0, i32 3
  %23 = load ptr, ptr %22, align 8, !tbaa !14
  %24 = icmp eq ptr %23, null
  br i1 %24, label %25, label %33

25:                                               ; preds = %20
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.RBNode, ptr %26, i32 0, i32 2
  %28 = load ptr, ptr %27, align 8, !tbaa !15
  %29 = icmp eq ptr %28, null
  br i1 %29, label %30, label %33

30:                                               ; preds = %25
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  call void @deleteNodeLeafCase(ptr noundef %31, ptr noundef %32)
  br label %54

33:                                               ; preds = %25, %20
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.RBNode, ptr %34, i32 0, i32 3
  %36 = load ptr, ptr %35, align 8, !tbaa !14
  %37 = icmp eq ptr %36, null
  br i1 %37, label %38, label %41

38:                                               ; preds = %33
  %39 = load ptr, ptr %4, align 8, !tbaa !5
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  call void @deleteRightNullNode(ptr noundef %39, ptr noundef %40)
  br label %53

41:                                               ; preds = %33
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.RBNode, ptr %42, i32 0, i32 2
  %44 = load ptr, ptr %43, align 8, !tbaa !15
  %45 = icmp eq ptr %44, null
  br i1 %45, label %46, label %49

46:                                               ; preds = %41
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  call void @deleteLeftNullNode(ptr noundef %47, ptr noundef %48)
  br label %52

49:                                               ; preds = %41
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = load ptr, ptr %5, align 8, !tbaa !5
  call void @deleteRightNoneNullNode(ptr noundef %50, ptr noundef %51)
  br label %52

52:                                               ; preds = %49, %46
  br label %53

53:                                               ; preds = %52, %38
  br label %54

54:                                               ; preds = %53, %30
  br label %89

55:                                               ; preds = %10
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.RBTree, ptr %56, i32 0, i32 3
  %58 = load ptr, ptr %57, align 8, !tbaa !9
  %59 = load ptr, ptr %6, align 8, !tbaa !5
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.RBNode, ptr %60, i32 0, i32 0
  %62 = load ptr, ptr %61, align 8, !tbaa !12
  %63 = call i32 %58(ptr noundef %59, ptr noundef %62)
  %64 = icmp slt i32 %63, 0
  br i1 %64, label %65, label %71

65:                                               ; preds = %55
  %66 = load ptr, ptr %4, align 8, !tbaa !5
  %67 = load ptr, ptr %5, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.RBNode, ptr %67, i32 0, i32 2
  %69 = load ptr, ptr %68, align 8, !tbaa !15
  %70 = load ptr, ptr %6, align 8, !tbaa !5
  call void @rBTreeDeleteR(ptr noundef %66, ptr noundef %69, ptr noundef %70)
  br label %88

71:                                               ; preds = %55
  %72 = load ptr, ptr %4, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.RBTree, ptr %72, i32 0, i32 3
  %74 = load ptr, ptr %73, align 8, !tbaa !9
  %75 = load ptr, ptr %6, align 8, !tbaa !5
  %76 = load ptr, ptr %5, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.RBNode, ptr %76, i32 0, i32 0
  %78 = load ptr, ptr %77, align 8, !tbaa !12
  %79 = call i32 %74(ptr noundef %75, ptr noundef %78)
  %80 = icmp sgt i32 %79, 0
  br i1 %80, label %81, label %87

81:                                               ; preds = %71
  %82 = load ptr, ptr %4, align 8, !tbaa !5
  %83 = load ptr, ptr %5, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.RBNode, ptr %83, i32 0, i32 3
  %85 = load ptr, ptr %84, align 8, !tbaa !14
  %86 = load ptr, ptr %6, align 8, !tbaa !5
  call void @rBTreeDeleteR(ptr noundef %82, ptr noundef %85, ptr noundef %86)
  br label %87

87:                                               ; preds = %81, %71
  br label %88

88:                                               ; preds = %87, %65
  br label %89

89:                                               ; preds = %88, %54
  br label %90

90:                                               ; preds = %89, %9
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local void @deleteNodeLeafCase(ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local void @deleteRightNullNode(ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local void @deleteLeftNullNode(ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local void @deleteRightNoneNullNode(ptr noundef, ptr noundef) #0

attributes #0 = { 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/C++ TBAA"}
!9 = !{!10, !6, i64 24}
!10 = !{!"RBTree", !6, i64 0, !11, i64 8, !6, i64 16, !6, i64 24}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !6, i64 0}
!13 = !{!"RBNode", !6, i64 0, !11, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!14 = !{!13, !6, i64 24}
!15 = !{!13, !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: nounwind uwtable
define dso_local void @rBTreeDeleteR(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = icmp eq ptr %1, null
  br i1 %4, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %3
  %5 = getelementptr inbounds i8, ptr %0, i64 24
  br label %6

6:                                                ; preds = %.lr.ph, %tailrecurse.backedge
  %.tr2831 = phi ptr [ %1, %.lr.ph ], [ %.tr28.be, %tailrecurse.backedge ]
  %7 = load ptr, ptr %5, align 8, !tbaa !5
  %8 = load ptr, ptr %.tr2831, align 8, !tbaa !11
  %9 = tail call i32 %7(ptr noundef %2, ptr noundef %8) #1
  %10 = icmp eq i32 %9, 0
  br i1 %10, label %11, label %24

11:                                               ; preds = %6
  %12 = getelementptr inbounds i8, ptr %.tr2831, i64 24
  %13 = load ptr, ptr %12, align 8, !tbaa !13
  %14 = icmp eq ptr %13, null
  %15 = getelementptr inbounds i8, ptr %.tr2831, i64 16
  %16 = load ptr, ptr %15, align 8, !tbaa !14
  %17 = icmp eq ptr %16, null
  br i1 %14, label %18, label %21

18:                                               ; preds = %11
  br i1 %17, label %19, label %20

19:                                               ; preds = %18
  tail call void @deleteNodeLeafCase(ptr noundef nonnull %0, ptr noundef nonnull %.tr2831)
  br label %.loopexit

20:                                               ; preds = %18
  tail call void @deleteRightNullNode(ptr noundef nonnull %0, ptr noundef nonnull %.tr2831)
  br label %.loopexit

21:                                               ; preds = %11
  br i1 %17, label %22, label %23

22:                                               ; preds = %21
  tail call void @deleteLeftNullNode(ptr noundef nonnull %0, ptr noundef nonnull %.tr2831)
  br label %.loopexit

23:                                               ; preds = %21
  tail call void @deleteRightNoneNullNode(ptr noundef nonnull %0, ptr noundef nonnull %.tr2831)
  br label %.loopexit

24:                                               ; preds = %6
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = load ptr, ptr %.tr2831, align 8, !tbaa !11
  %27 = tail call i32 %25(ptr noundef %2, ptr noundef %26) #1
  %28 = icmp slt i32 %27, 0
  br i1 %28, label %tailrecurse.backedge, label %31

tailrecurse.backedge:                             ; preds = %24, %31
  %.sink = phi i64 [ 24, %31 ], [ 16, %24 ]
  %29 = getelementptr inbounds i8, ptr %.tr2831, i64 %.sink
  %.tr28.be = load ptr, ptr %29, align 8, !tbaa !15
  %30 = icmp eq ptr %.tr28.be, null
  br i1 %30, label %.loopexit, label %6

31:                                               ; preds = %24
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = load ptr, ptr %.tr2831, align 8, !tbaa !11
  %34 = tail call i32 %32(ptr noundef %2, ptr noundef %33) #1
  %35 = icmp sgt i32 %34, 0
  br i1 %35, label %tailrecurse.backedge, label %.loopexit

.loopexit:                                        ; preds = %tailrecurse.backedge, %31, %3, %20, %23, %22, %19
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local void @deleteNodeLeafCase(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @deleteRightNullNode(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @deleteLeftNullNode(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @deleteRightNoneNullNode(ptr noundef, ptr noundef) local_unnamed_addr #0

attributes #0 = { 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 = { 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 24}
!6 = !{!"RBTree", !7, i64 0, !10, i64 8, !7, i64 16, !7, i64 24}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!12, !7, i64 0}
!12 = !{!"RBNode", !7, i64 0, !10, i64 8, !7, i64 16, !7, i64 24, !7, i64 32}
!13 = !{!12, !7, i64 24}
!14 = !{!12, !7, i64 16}
!15 = !{!7, !7, i64 0}


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