; LLVM IR from mahanzavari/ARBAB :: src (rbtree)

; 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.RBTreeNode = type { i32, ptr, ptr, ptr, ptr, i8 }

; 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: nounwind uwtable
declare dso_local ptr @rbt_search(ptr noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @rbt_find_min(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @rbt_transplant(ptr noundef, ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local ptr @rbt_delete(ptr noundef %0, i32 noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i8, align 1
  %10 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = load ptr, ptr %11, align 8, !tbaa !5
  %13 = load i32, ptr %5, align 4, !tbaa !9
  %14 = call ptr @rbt_search(ptr noundef %12, i32 noundef %13)
  store ptr %14, ptr %6, align 8, !tbaa !5
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = icmp eq ptr %15, null
  br i1 %16, label %17, label %20

17:                                               ; preds = %2
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = load ptr, ptr %18, align 8, !tbaa !5
  store ptr %19, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %134

20:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %21, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %9) #3
  %22 = load ptr, ptr %8, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.RBTreeNode, ptr %22, i32 0, i32 5
  %24 = load i8, ptr %23, align 8, !tbaa !11
  store i8 %24, ptr %9, align 1, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.RBTreeNode, ptr %25, i32 0, i32 3
  %27 = load ptr, ptr %26, align 8, !tbaa !14
  %28 = icmp eq ptr %27, null
  br i1 %28, label %29, label %40

29:                                               ; preds = %20
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.RBTreeNode, ptr %30, i32 0, i32 4
  %32 = load ptr, ptr %31, align 8, !tbaa !15
  store ptr %32, ptr %10, align 8, !tbaa !5
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.RBTreeNode, ptr %35, i32 0, i32 4
  %37 = load ptr, ptr %36, align 8, !tbaa !15
  %38 = call ptr @rbt_transplant(ptr noundef %33, ptr noundef %34, ptr noundef %37)
  %39 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %38, ptr %39, align 8, !tbaa !5
  br label %120

40:                                               ; preds = %20
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.RBTreeNode, ptr %41, i32 0, i32 4
  %43 = load ptr, ptr %42, align 8, !tbaa !15
  %44 = icmp eq ptr %43, null
  br i1 %44, label %45, label %56

45:                                               ; preds = %40
  %46 = load ptr, ptr %6, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.RBTreeNode, ptr %46, i32 0, i32 3
  %48 = load ptr, ptr %47, align 8, !tbaa !14
  store ptr %48, ptr %10, align 8, !tbaa !5
  %49 = load ptr, ptr %4, align 8, !tbaa !5
  %50 = load ptr, ptr %6, align 8, !tbaa !5
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.RBTreeNode, ptr %51, i32 0, i32 3
  %53 = load ptr, ptr %52, align 8, !tbaa !14
  %54 = call ptr @rbt_transplant(ptr noundef %49, ptr noundef %50, ptr noundef %53)
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %54, ptr %55, align 8, !tbaa !5
  br label %119

56:                                               ; preds = %40
  %57 = load ptr, ptr %6, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.RBTreeNode, ptr %57, i32 0, i32 4
  %59 = load ptr, ptr %58, align 8, !tbaa !15
  %60 = call ptr @rbt_find_min(ptr noundef %59)
  store ptr %60, ptr %8, align 8, !tbaa !5
  %61 = load ptr, ptr %8, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.RBTreeNode, ptr %61, i32 0, i32 5
  %63 = load i8, ptr %62, align 8, !tbaa !11
  store i8 %63, ptr %9, align 1, !tbaa !13
  %64 = load ptr, ptr %8, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.RBTreeNode, ptr %64, i32 0, i32 4
  %66 = load ptr, ptr %65, align 8, !tbaa !15
  store ptr %66, ptr %10, align 8, !tbaa !5
  %67 = load ptr, ptr %8, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.RBTreeNode, ptr %67, i32 0, i32 2
  %69 = load ptr, ptr %68, align 8, !tbaa !16
  %70 = load ptr, ptr %6, align 8, !tbaa !5
  %71 = icmp eq ptr %69, %70
  br i1 %71, label %72, label %80

72:                                               ; preds = %56
  %73 = load ptr, ptr %10, align 8, !tbaa !5
  %74 = icmp ne ptr %73, null
  br i1 %74, label %75, label %79

75:                                               ; preds = %72
  %76 = load ptr, ptr %8, align 8, !tbaa !5
  %77 = load ptr, ptr %10, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.RBTreeNode, ptr %77, i32 0, i32 2
  store ptr %76, ptr %78, align 8, !tbaa !16
  br label %79

79:                                               ; preds = %75, %72
  br label %98

80:                                               ; preds = %56
  %81 = load ptr, ptr %4, align 8, !tbaa !5
  %82 = load ptr, ptr %8, align 8, !tbaa !5
  %83 = load ptr, ptr %8, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.RBTreeNode, ptr %83, i32 0, i32 4
  %85 = load ptr, ptr %84, align 8, !tbaa !15
  %86 = call ptr @rbt_transplant(ptr noundef %81, ptr noundef %82, ptr noundef %85)
  %87 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %86, ptr %87, align 8, !tbaa !5
  %88 = load ptr, ptr %6, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.RBTreeNode, ptr %88, i32 0, i32 4
  %90 = load ptr, ptr %89, align 8, !tbaa !15
  %91 = load ptr, ptr %8, align 8, !tbaa !5
  %92 = getelementptr inbounds %struct.RBTreeNode, ptr %91, i32 0, i32 4
  store ptr %90, ptr %92, align 8, !tbaa !15
  %93 = load ptr, ptr %8, align 8, !tbaa !5
  %94 = load ptr, ptr %8, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.RBTreeNode, ptr %94, i32 0, i32 4
  %96 = load ptr, ptr %95, align 8, !tbaa !15
  %97 = getelementptr inbounds %struct.RBTreeNode, ptr %96, i32 0, i32 2
  store ptr %93, ptr %97, align 8, !tbaa !16
  br label %98

98:                                               ; preds = %80, %79
  %99 = load ptr, ptr %4, align 8, !tbaa !5
  %100 = load ptr, ptr %6, align 8, !tbaa !5
  %101 = load ptr, ptr %8, align 8, !tbaa !5
  %102 = call ptr @rbt_transplant(ptr noundef %99, ptr noundef %100, ptr noundef %101)
  %103 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %102, ptr %103, align 8, !tbaa !5
  %104 = load ptr, ptr %6, align 8, !tbaa !5
  %105 = getelementptr inbounds %struct.RBTreeNode, ptr %104, i32 0, i32 3
  %106 = load ptr, ptr %105, align 8, !tbaa !14
  %107 = load ptr, ptr %8, align 8, !tbaa !5
  %108 = getelementptr inbounds %struct.RBTreeNode, ptr %107, i32 0, i32 3
  store ptr %106, ptr %108, align 8, !tbaa !14
  %109 = load ptr, ptr %8, align 8, !tbaa !5
  %110 = load ptr, ptr %8, align 8, !tbaa !5
  %111 = getelementptr inbounds %struct.RBTreeNode, ptr %110, i32 0, i32 3
  %112 = load ptr, ptr %111, align 8, !tbaa !14
  %113 = getelementptr inbounds %struct.RBTreeNode, ptr %112, i32 0, i32 2
  store ptr %109, ptr %113, align 8, !tbaa !16
  %114 = load ptr, ptr %6, align 8, !tbaa !5
  %115 = getelementptr inbounds %struct.RBTreeNode, ptr %114, i32 0, i32 5
  %116 = load i8, ptr %115, align 8, !tbaa !11
  %117 = load ptr, ptr %8, align 8, !tbaa !5
  %118 = getelementptr inbounds %struct.RBTreeNode, ptr %117, i32 0, i32 5
  store i8 %116, ptr %118, align 8, !tbaa !11
  br label %119

119:                                              ; preds = %98, %45
  br label %120

120:                                              ; preds = %119, %29
  %121 = load ptr, ptr %6, align 8, !tbaa !5
  call void @free(ptr noundef %121) #3
  %122 = load i8, ptr %9, align 1, !tbaa !13
  %123 = sext i8 %122 to i32
  %124 = icmp eq i32 %123, 66
  br i1 %124, label %125, label %131

125:                                              ; preds = %120
  %126 = load ptr, ptr %10, align 8, !tbaa !5
  %127 = icmp ne ptr %126, null
  br i1 %127, label %128, label %131

128:                                              ; preds = %125
  %129 = load ptr, ptr %4, align 8, !tbaa !5
  %130 = load ptr, ptr %10, align 8, !tbaa !5
  call void @rbt_delete_fixup(ptr noundef %129, ptr noundef %130)
  br label %131

131:                                              ; preds = %128, %125, %120
  %132 = load ptr, ptr %4, align 8, !tbaa !5
  %133 = load ptr, ptr %132, align 8, !tbaa !5
  store ptr %133, ptr %3, align 8
  store i32 1, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %134

134:                                              ; preds = %131, %17
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %135 = load ptr, ptr %3, align 8
  ret ptr %135
}

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

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 "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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !7, i64 40}
!12 = !{!"RBTreeNode", !10, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !7, i64 40}
!13 = !{!7, !7, i64 0}
!14 = !{!12, !6, i64 24}
!15 = !{!12, !6, i64 32}
!16 = !{!12, !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
declare dso_local ptr @rbt_search(ptr noundef, i32 noundef) local_unnamed_addr #0

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

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

; Function Attrs: nounwind uwtable
define dso_local ptr @rbt_delete(ptr noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = load ptr, ptr %0, align 8, !tbaa !5
  %4 = tail call ptr @rbt_search(ptr noundef %3, i32 noundef %1)
  %5 = icmp eq ptr %4, null
  br i1 %5, label %44, label %6

6:                                                ; preds = %2
  %7 = getelementptr inbounds i8, ptr %4, i64 40
  %8 = load i8, ptr %7, align 8, !tbaa !9
  %9 = getelementptr inbounds i8, ptr %4, i64 24
  %10 = load ptr, ptr %9, align 8, !tbaa !12
  %11 = icmp eq ptr %10, null
  %12 = getelementptr inbounds i8, ptr %4, i64 32
  %13 = load ptr, ptr %12, align 8, !tbaa !13
  br i1 %11, label %14, label %16

14:                                               ; preds = %6
  %15 = tail call ptr @rbt_transplant(ptr noundef nonnull %0, ptr noundef nonnull %4, ptr noundef %13)
  store ptr %15, ptr %0, align 8, !tbaa !5
  br label %40

16:                                               ; preds = %6
  %17 = icmp eq ptr %13, null
  br i1 %17, label %18, label %20

18:                                               ; preds = %16
  %19 = tail call ptr @rbt_transplant(ptr noundef nonnull %0, ptr noundef nonnull %4, ptr noundef nonnull %10)
  store ptr %19, ptr %0, align 8, !tbaa !5
  br label %40

20:                                               ; preds = %16
  %21 = tail call ptr @rbt_find_min(ptr noundef nonnull %13)
  %22 = getelementptr inbounds i8, ptr %21, i64 40
  %23 = load i8, ptr %22, align 8, !tbaa !9
  %24 = getelementptr inbounds i8, ptr %21, i64 32
  %25 = load ptr, ptr %24, align 8, !tbaa !13
  %26 = getelementptr inbounds i8, ptr %21, i64 16
  %27 = load ptr, ptr %26, align 8, !tbaa !14
  %28 = icmp eq ptr %27, %4
  br i1 %28, label %29, label %30

29:                                               ; preds = %20
  %.not = icmp eq ptr %25, null
  br i1 %.not, label %34, label %.sink.split

30:                                               ; preds = %20
  %31 = tail call ptr @rbt_transplant(ptr noundef nonnull %0, ptr noundef nonnull %21, ptr noundef %25)
  store ptr %31, ptr %0, align 8, !tbaa !5
  %32 = load ptr, ptr %12, align 8, !tbaa !13
  store ptr %32, ptr %24, align 8, !tbaa !13
  br label %.sink.split

.sink.split:                                      ; preds = %29, %30
  %.sink57 = phi ptr [ %32, %30 ], [ %25, %29 ]
  %33 = getelementptr inbounds i8, ptr %.sink57, i64 16
  store ptr %21, ptr %33, align 8, !tbaa !14
  br label %34

34:                                               ; preds = %.sink.split, %29
  %35 = tail call ptr @rbt_transplant(ptr noundef nonnull %0, ptr noundef nonnull %4, ptr noundef nonnull %21)
  store ptr %35, ptr %0, align 8, !tbaa !5
  %36 = load ptr, ptr %9, align 8, !tbaa !12
  %37 = getelementptr inbounds i8, ptr %21, i64 24
  store ptr %36, ptr %37, align 8, !tbaa !12
  %38 = getelementptr inbounds i8, ptr %36, i64 16
  store ptr %21, ptr %38, align 8, !tbaa !14
  %39 = load i8, ptr %7, align 8, !tbaa !9
  store i8 %39, ptr %22, align 8, !tbaa !9
  br label %40

40:                                               ; preds = %18, %34, %14
  %.051 = phi i8 [ %8, %14 ], [ %8, %18 ], [ %23, %34 ]
  %.0 = phi ptr [ %13, %14 ], [ %10, %18 ], [ %25, %34 ]
  tail call void @free(ptr noundef nonnull %4) #2
  %41 = icmp eq i8 %.051, 66
  %42 = icmp ne ptr %.0, null
  %or.cond = select i1 %41, i1 %42, i1 false
  br i1 %or.cond, label %43, label %44

43:                                               ; preds = %40
  tail call void @rbt_delete_fixup(ptr noundef nonnull %0, ptr noundef nonnull %.0)
  br label %44

44:                                               ; preds = %40, %43, %2
  %.052 = load ptr, ptr %0, align 8, !tbaa !5
  ret ptr %.052
}

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

; Function Attrs: nounwind uwtable
declare dso_local void @rbt_delete_fixup(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 = { 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 #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/C++ TBAA"}
!9 = !{!10, !7, i64 40}
!10 = !{!"RBTreeNode", !11, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !7, i64 40}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !6, i64 24}
!13 = !{!10, !6, i64 32}
!14 = !{!10, !6, i64 16}


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