; 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 ptr @rBTreeDeleteRWtoFr(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
  %7 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  %8 = load ptr, ptr %6, align 8, !tbaa !5
  %9 = icmp eq ptr %8, null
  br i1 %9, label %10, label %11

10:                                               ; preds = %3
  store ptr null, ptr %4, align 8
  br label %95

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

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

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

31:                                               ; preds = %26
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = call ptr @deleteNodeLeafCaseWtoFr(ptr noundef %32, ptr noundef %33)
  store ptr %34, ptr %4, align 8
  br label %95

35:                                               ; preds = %26, %21
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.RBNode, ptr %36, i32 0, i32 3
  %38 = load ptr, ptr %37, align 8, !tbaa !14
  %39 = icmp eq ptr %38, null
  br i1 %39, label %40, label %44

40:                                               ; preds = %35
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = call ptr @deleteRightNullNodeWtoFr(ptr noundef %41, ptr noundef %42)
  store ptr %43, ptr %4, align 8
  br label %95

44:                                               ; preds = %35
  %45 = load ptr, ptr %6, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.RBNode, ptr %45, i32 0, i32 2
  %47 = load ptr, ptr %46, align 8, !tbaa !15
  %48 = icmp eq ptr %47, null
  br i1 %48, label %49, label %53

49:                                               ; preds = %44
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  %52 = call ptr @deleteLeftNullNodeWtoFr(ptr noundef %50, ptr noundef %51)
  store ptr %52, ptr %4, align 8
  br label %95

53:                                               ; preds = %44
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  %55 = load ptr, ptr %6, align 8, !tbaa !5
  %56 = call ptr @deleteRightNoneNullNodeWtoFr(ptr noundef %54, ptr noundef %55)
  store ptr %56, ptr %4, align 8
  br label %95

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

67:                                               ; preds = %57
  %68 = load ptr, ptr %5, align 8, !tbaa !5
  %69 = load ptr, ptr %6, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.RBNode, ptr %69, i32 0, i32 2
  %71 = load ptr, ptr %70, align 8, !tbaa !15
  %72 = load ptr, ptr %7, align 8, !tbaa !5
  %73 = call ptr @rBTreeDeleteRWtoFr(ptr noundef %68, ptr noundef %71, ptr noundef %72)
  store ptr %73, ptr %4, align 8
  br label %95

74:                                               ; preds = %57
  %75 = load ptr, ptr %5, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.RBTree, ptr %75, i32 0, i32 3
  %77 = load ptr, ptr %76, align 8, !tbaa !9
  %78 = load ptr, ptr %7, align 8, !tbaa !5
  %79 = load ptr, ptr %6, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.RBNode, ptr %79, i32 0, i32 0
  %81 = load ptr, ptr %80, align 8, !tbaa !12
  %82 = call i32 %77(ptr noundef %78, ptr noundef %81)
  %83 = icmp sgt i32 %82, 0
  br i1 %83, label %84, label %91

84:                                               ; preds = %74
  %85 = load ptr, ptr %5, align 8, !tbaa !5
  %86 = load ptr, ptr %6, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.RBNode, ptr %86, i32 0, i32 3
  %88 = load ptr, ptr %87, align 8, !tbaa !14
  %89 = load ptr, ptr %7, align 8, !tbaa !5
  %90 = call ptr @rBTreeDeleteRWtoFr(ptr noundef %85, ptr noundef %88, ptr noundef %89)
  store ptr %90, ptr %4, align 8
  br label %95

91:                                               ; preds = %74
  br label %92

92:                                               ; preds = %91
  br label %93

93:                                               ; preds = %92
  br label %94

94:                                               ; preds = %93
  store ptr null, ptr %4, align 8
  br label %95

95:                                               ; preds = %94, %84, %67, %53, %49, %40, %31, %10
  %96 = load ptr, ptr %4, align 8
  ret ptr %96
}

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

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

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @deleteRightNoneNullNodeWtoFr(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 ptr @rBTreeDeleteRWtoFr(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
  %.tr3033 = phi ptr [ %1, %.lr.ph ], [ %.tr30.be, %tailrecurse.backedge ]
  %7 = load ptr, ptr %5, align 8, !tbaa !5
  %8 = load ptr, ptr %.tr3033, 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 %28

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

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

19:                                               ; preds = %18
  %20 = tail call ptr @deleteNodeLeafCaseWtoFr(ptr noundef nonnull %0, ptr noundef nonnull %.tr3033)
  br label %.loopexit

21:                                               ; preds = %18
  %22 = tail call ptr @deleteRightNullNodeWtoFr(ptr noundef nonnull %0, ptr noundef nonnull %.tr3033)
  br label %.loopexit

23:                                               ; preds = %11
  br i1 %17, label %24, label %26

24:                                               ; preds = %23
  %25 = tail call ptr @deleteLeftNullNodeWtoFr(ptr noundef nonnull %0, ptr noundef nonnull %.tr3033)
  br label %.loopexit

26:                                               ; preds = %23
  %27 = tail call ptr @deleteRightNoneNullNodeWtoFr(ptr noundef nonnull %0, ptr noundef nonnull %.tr3033)
  br label %.loopexit

28:                                               ; preds = %6
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = load ptr, ptr %.tr3033, align 8, !tbaa !11
  %31 = tail call i32 %29(ptr noundef %2, ptr noundef %30) #1
  %32 = icmp slt i32 %31, 0
  br i1 %32, label %tailrecurse.backedge, label %35

tailrecurse.backedge:                             ; preds = %28, %35
  %.sink = phi i64 [ 24, %35 ], [ 16, %28 ]
  %33 = getelementptr inbounds i8, ptr %.tr3033, i64 %.sink
  %.tr30.be = load ptr, ptr %33, align 8, !tbaa !15
  %34 = icmp eq ptr %.tr30.be, null
  br i1 %34, label %.loopexit, label %6

35:                                               ; preds = %28
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = load ptr, ptr %.tr3033, align 8, !tbaa !11
  %38 = tail call i32 %36(ptr noundef %2, ptr noundef %37) #1
  %39 = icmp sgt i32 %38, 0
  br i1 %39, label %tailrecurse.backedge, label %.loopexit

.loopexit:                                        ; preds = %tailrecurse.backedge, %35, %3, %26, %24, %21, %19
  %.0 = phi ptr [ %20, %19 ], [ %22, %21 ], [ %25, %24 ], [ %27, %26 ], [ null, %3 ], [ null, %35 ], [ null, %tailrecurse.backedge ]
  ret ptr %.0
}

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

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

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @deleteRightNoneNullNodeWtoFr(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