; LLVM IR from hutusi/rethink-c :: 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 { ptr, ptr, ptr, ptr, ptr, i32 }
%struct._RBTree = type { ptr, ptr, ptr, ptr, i32 }

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

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

15:                                               ; preds = %2
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct._RBTreeNode, ptr %16, i32 0, i32 4
  %18 = load ptr, ptr %17, align 8, !tbaa !14
  %19 = icmp eq ptr %18, null
  br i1 %19, label %20, label %24

20:                                               ; preds = %15
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = call ptr @rb_tree_replace_node(ptr noundef %21, ptr noundef %22, ptr noundef null)
  br label %104

24:                                               ; preds = %15, %2
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct._RBTreeNode, ptr %25, i32 0, i32 3
  %27 = load ptr, ptr %26, align 8, !tbaa !13
  %28 = icmp eq ptr %27, null
  br i1 %28, label %29, label %39

29:                                               ; preds = %24
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct._RBTreeNode, ptr %30, i32 0, i32 4
  %32 = load ptr, ptr %31, align 8, !tbaa !14
  store ptr %32, ptr %5, align 8, !tbaa !5
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct._RBTreeNode, ptr %35, i32 0, i32 4
  %37 = load ptr, ptr %36, align 8, !tbaa !14
  %38 = call ptr @rb_tree_replace_node(ptr noundef %33, ptr noundef %34, ptr noundef %37)
  br label %103

39:                                               ; preds = %24
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct._RBTreeNode, ptr %40, i32 0, i32 4
  %42 = load ptr, ptr %41, align 8, !tbaa !14
  %43 = icmp eq ptr %42, null
  br i1 %43, label %44, label %54

44:                                               ; preds = %39
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct._RBTreeNode, ptr %45, i32 0, i32 3
  %47 = load ptr, ptr %46, align 8, !tbaa !13
  store ptr %47, ptr %5, align 8, !tbaa !5
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  %49 = load ptr, ptr %4, align 8, !tbaa !5
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct._RBTreeNode, ptr %50, i32 0, i32 3
  %52 = load ptr, ptr %51, align 8, !tbaa !13
  %53 = call ptr @rb_tree_replace_node(ptr noundef %48, ptr noundef %49, ptr noundef %52)
  br label %102

54:                                               ; preds = %39
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct._RBTreeNode, ptr %55, i32 0, i32 4
  %57 = load ptr, ptr %56, align 8, !tbaa !14
  %58 = call ptr @rb_tree_leftmost_node(ptr noundef %57)
  store ptr %58, ptr %7, align 8, !tbaa !5
  %59 = load ptr, ptr %7, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct._RBTreeNode, ptr %59, i32 0, i32 5
  %61 = load i32, ptr %60, align 8, !tbaa !9
  store i32 %61, ptr %6, align 4, !tbaa !12
  %62 = load ptr, ptr %7, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct._RBTreeNode, ptr %62, i32 0, i32 4
  %64 = load ptr, ptr %63, align 8, !tbaa !14
  store ptr %64, ptr %5, align 8, !tbaa !5
  %65 = load ptr, ptr %7, align 8, !tbaa !5
  %66 = load ptr, ptr %4, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct._RBTreeNode, ptr %66, i32 0, i32 4
  %68 = load ptr, ptr %67, align 8, !tbaa !14
  %69 = icmp ne ptr %65, %68
  br i1 %69, label %70, label %87

70:                                               ; preds = %54
  %71 = load ptr, ptr %3, align 8, !tbaa !5
  %72 = load ptr, ptr %7, align 8, !tbaa !5
  %73 = load ptr, ptr %7, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct._RBTreeNode, ptr %73, i32 0, i32 4
  %75 = load ptr, ptr %74, align 8, !tbaa !14
  %76 = call ptr @rb_tree_replace_node(ptr noundef %71, ptr noundef %72, ptr noundef %75)
  %77 = load ptr, ptr %4, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct._RBTreeNode, ptr %77, i32 0, i32 4
  %79 = load ptr, ptr %78, align 8, !tbaa !14
  %80 = load ptr, ptr %7, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct._RBTreeNode, ptr %80, i32 0, i32 4
  store ptr %79, ptr %81, align 8, !tbaa !14
  %82 = load ptr, ptr %7, align 8, !tbaa !5
  %83 = load ptr, ptr %4, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct._RBTreeNode, ptr %83, i32 0, i32 4
  %85 = load ptr, ptr %84, align 8, !tbaa !14
  %86 = getelementptr inbounds %struct._RBTreeNode, ptr %85, i32 0, i32 2
  store ptr %82, ptr %86, align 8, !tbaa !15
  br label %87

87:                                               ; preds = %70, %54
  %88 = load ptr, ptr %3, align 8, !tbaa !5
  %89 = load ptr, ptr %4, align 8, !tbaa !5
  %90 = load ptr, ptr %7, align 8, !tbaa !5
  %91 = call ptr @rb_tree_replace_node(ptr noundef %88, ptr noundef %89, ptr noundef %90)
  %92 = load ptr, ptr %4, align 8, !tbaa !5
  %93 = getelementptr inbounds %struct._RBTreeNode, ptr %92, i32 0, i32 3
  %94 = load ptr, ptr %93, align 8, !tbaa !13
  %95 = load ptr, ptr %7, align 8, !tbaa !5
  %96 = getelementptr inbounds %struct._RBTreeNode, ptr %95, i32 0, i32 3
  store ptr %94, ptr %96, align 8, !tbaa !13
  %97 = load ptr, ptr %7, align 8, !tbaa !5
  %98 = load ptr, ptr %4, align 8, !tbaa !5
  %99 = getelementptr inbounds %struct._RBTreeNode, ptr %98, i32 0, i32 3
  %100 = load ptr, ptr %99, align 8, !tbaa !13
  %101 = getelementptr inbounds %struct._RBTreeNode, ptr %100, i32 0, i32 2
  store ptr %97, ptr %101, align 8, !tbaa !15
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  br label %102

102:                                              ; preds = %87, %44
  br label %103

103:                                              ; preds = %102, %29
  br label %104

104:                                              ; preds = %103, %20
  %105 = load i32, ptr %6, align 4, !tbaa !12
  %106 = icmp eq i32 %105, 1
  br i1 %106, label %107, label %110

107:                                              ; preds = %104
  %108 = load ptr, ptr %3, align 8, !tbaa !5
  %109 = load ptr, ptr %5, align 8, !tbaa !5
  call void @rb_tree_delete_fixup(ptr noundef %108, ptr noundef %109)
  br label %110

110:                                              ; preds = %107, %104
  %111 = load ptr, ptr %3, align 8, !tbaa !5
  %112 = getelementptr inbounds %struct._RBTree, ptr %111, i32 0, i32 4
  %113 = load i32, ptr %112, align 8, !tbaa !16
  %114 = add i32 %113, -1
  store i32 %114, ptr %112, align 8, !tbaa !16
  %115 = load ptr, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  ret ptr %115
}

; Function Attrs: nounwind uwtable
declare hidden ptr @rb_tree_replace_node(ptr noundef, ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare hidden void @rb_tree_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 }

!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, !11, i64 40}
!10 = !{!"_RBTreeNode", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !11, i64 40}
!11 = !{!"int", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!10, !6, i64 24}
!14 = !{!10, !6, i64 32}
!15 = !{!10, !6, i64 16}
!16 = !{!17, !11, i64 32}
!17 = !{!"_RBTree", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !11, i64 32}


; 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 @rb_tree_leftmost_node(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @rb_tree_remove_node(ptr noundef %0, ptr noundef returned %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %1, i64 40
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %1, i64 24
  %6 = load ptr, ptr %5, align 8, !tbaa !11
  %7 = icmp eq ptr %6, null
  %8 = getelementptr inbounds i8, ptr %1, i64 32
  %9 = load ptr, ptr %8, align 8, !tbaa !12
  %10 = icmp eq ptr %9, null
  br i1 %7, label %11, label %16

11:                                               ; preds = %2
  br i1 %10, label %12, label %14

12:                                               ; preds = %11
  %13 = tail call ptr @rb_tree_replace_node(ptr noundef %0, ptr noundef nonnull %1, ptr noundef null)
  br label %35

14:                                               ; preds = %11
  %15 = tail call ptr @rb_tree_replace_node(ptr noundef %0, ptr noundef nonnull %1, ptr noundef nonnull %9)
  br label %35

16:                                               ; preds = %2
  br i1 %10, label %17, label %19

17:                                               ; preds = %16
  %18 = tail call ptr @rb_tree_replace_node(ptr noundef %0, ptr noundef nonnull %1, ptr noundef nonnull %6)
  br label %35

19:                                               ; preds = %16
  %20 = tail call ptr @rb_tree_leftmost_node(ptr noundef nonnull %9)
  %21 = getelementptr inbounds i8, ptr %20, i64 40
  %22 = load i32, ptr %21, align 8, !tbaa !5
  %23 = getelementptr inbounds i8, ptr %20, i64 32
  %24 = load ptr, ptr %23, align 8, !tbaa !12
  %25 = load ptr, ptr %8, align 8, !tbaa !12
  %.not = icmp eq ptr %20, %25
  br i1 %.not, label %30, label %26

26:                                               ; preds = %19
  %27 = tail call ptr @rb_tree_replace_node(ptr noundef %0, ptr noundef nonnull %20, ptr noundef %24)
  %28 = load ptr, ptr %8, align 8, !tbaa !12
  store ptr %28, ptr %23, align 8, !tbaa !12
  %29 = getelementptr inbounds i8, ptr %28, i64 16
  store ptr %20, ptr %29, align 8, !tbaa !13
  br label %30

30:                                               ; preds = %26, %19
  %31 = tail call ptr @rb_tree_replace_node(ptr noundef %0, ptr noundef nonnull %1, ptr noundef nonnull %20)
  %32 = load ptr, ptr %5, align 8, !tbaa !11
  %33 = getelementptr inbounds i8, ptr %20, i64 24
  store ptr %32, ptr %33, align 8, !tbaa !11
  %34 = getelementptr inbounds i8, ptr %32, i64 16
  store ptr %20, ptr %34, align 8, !tbaa !13
  br label %35

35:                                               ; preds = %14, %30, %17, %12
  %.038 = phi i32 [ %4, %12 ], [ %4, %14 ], [ %4, %17 ], [ %22, %30 ]
  %.0 = phi ptr [ null, %12 ], [ %9, %14 ], [ %6, %17 ], [ %24, %30 ]
  %36 = icmp eq i32 %.038, 1
  br i1 %36, label %37, label %38

37:                                               ; preds = %35
  tail call void @rb_tree_delete_fixup(ptr noundef %0, ptr noundef %.0)
  br label %38

38:                                               ; preds = %37, %35
  %39 = getelementptr inbounds i8, ptr %0, i64 32
  %40 = load i32, ptr %39, align 8, !tbaa !14
  %41 = add i32 %40, -1
  store i32 %41, ptr %39, align 8, !tbaa !14
  ret ptr %1
}

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

; Function Attrs: nounwind uwtable
declare hidden void @rb_tree_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" }

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


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