; LLVM IR from pavlosdais/Abstract-Data-Types :: modules/RedBlackTree (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.tnode = type { ptr, i32, ptr, ptr, ptr }
%struct.Set = type { ptr, i64, ptr, ptr }

@NULLNode = external dso_local global %struct.tnode, align 8
@.str.1 = external hidden unnamed_addr constant [100 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [13 x i8], align 1
@__PRETTY_FUNCTION__.rbt_insert = external hidden unnamed_addr constant [46 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [17 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #0

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

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

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @rbt_insert(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca i1, align 1
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = icmp ne ptr %13, null
  br i1 %14, label %15, label %16

15:                                               ; preds = %2
  br label %17

16:                                               ; preds = %2
  call void @__assert_fail(ptr noundef @.str.2, ptr noundef @.str.1, i32 noundef 111, ptr noundef @__PRETTY_FUNCTION__.rbt_insert) #5
  unreachable

17:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #6
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.Set, ptr %18, i32 0, i32 0
  store ptr %19, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #6
  %20 = call ptr @CreateNode()
  store ptr %20, ptr %7, align 8, !tbaa !5
  %21 = load ptr, ptr %7, align 8, !tbaa !5
  %22 = icmp ne ptr %21, null
  br i1 %22, label %23, label %24

23:                                               ; preds = %17
  br label %25

24:                                               ; preds = %17
  call void @__assert_fail(ptr noundef @.str.4, ptr noundef @.str.1, i32 noundef 116, ptr noundef @__PRETTY_FUNCTION__.rbt_insert) #5
  unreachable

25:                                               ; preds = %23
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = load ptr, ptr %7, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.tnode, ptr %27, i32 0, i32 0
  store ptr %26, ptr %28, align 8, !tbaa !9
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = load ptr, ptr %29, align 8, !tbaa !5
  %31 = icmp eq ptr %30, null
  br i1 %31, label %32, label %41

32:                                               ; preds = %25
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.Set, ptr %33, i32 0, i32 1
  store i64 1, ptr %34, align 8, !tbaa !12
  %35 = load ptr, ptr %7, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.tnode, ptr %35, i32 0, i32 1
  store i32 1, ptr %36, align 8, !tbaa !15
  %37 = load ptr, ptr %7, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.tnode, ptr %37, i32 0, i32 4
  store ptr null, ptr %38, align 8, !tbaa !16
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %39, ptr %40, align 8, !tbaa !5
  store i1 true, ptr %3, align 1
  store i32 1, ptr %8, align 4
  br label %117

41:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #6
  store ptr null, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #6
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = load ptr, ptr %42, align 8, !tbaa !5
  store ptr %43, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #6
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.Set, ptr %44, i32 0, i32 2
  %46 = load ptr, ptr %45, align 8, !tbaa !17
  %47 = load ptr, ptr %10, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.tnode, ptr %47, i32 0, i32 0
  %49 = load ptr, ptr %48, align 8, !tbaa !9
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = call i32 %46(ptr noundef %49, ptr noundef %50)
  store i32 %51, ptr %12, align 4, !tbaa !18
  br label %52

52:                                               ; preds = %95, %41
  br label %53

53:                                               ; preds = %52
  %54 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %54, ptr %9, align 8, !tbaa !5
  %55 = load i32, ptr %12, align 4, !tbaa !18
  store i32 %55, ptr %11, align 4, !tbaa !18
  %56 = load i32, ptr %12, align 4, !tbaa !18
  %57 = icmp eq i32 %56, 0
  br i1 %57, label %58, label %70

58:                                               ; preds = %53
  %59 = load ptr, ptr %7, align 8, !tbaa !5
  call void @free(ptr noundef %59) #6
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.Set, ptr %60, i32 0, i32 3
  %62 = load ptr, ptr %61, align 8, !tbaa !19
  %63 = icmp ne ptr %62, null
  br i1 %63, label %64, label %69

64:                                               ; preds = %58
  %65 = load ptr, ptr %4, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.Set, ptr %65, i32 0, i32 3
  %67 = load ptr, ptr %66, align 8, !tbaa !19
  %68 = load ptr, ptr %5, align 8, !tbaa !5
  call void %67(ptr noundef %68)
  br label %69

69:                                               ; preds = %64, %58
  store i1 false, ptr %3, align 1
  store i32 1, ptr %8, align 4
  br label %116

70:                                               ; preds = %53
  %71 = load i32, ptr %12, align 4, !tbaa !18
  %72 = icmp slt i32 %71, 0
  br i1 %72, label %73, label %77

73:                                               ; preds = %70
  %74 = load ptr, ptr %10, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.tnode, ptr %74, i32 0, i32 3
  %76 = load ptr, ptr %75, align 8, !tbaa !20
  store ptr %76, ptr %10, align 8, !tbaa !5
  br label %81

77:                                               ; preds = %70
  %78 = load ptr, ptr %10, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.tnode, ptr %78, i32 0, i32 2
  %80 = load ptr, ptr %79, align 8, !tbaa !21
  store ptr %80, ptr %10, align 8, !tbaa !5
  br label %81

81:                                               ; preds = %77, %73
  br label %82

82:                                               ; preds = %81
  %83 = load ptr, ptr %10, align 8, !tbaa !5
  %84 = icmp ne ptr %83, @NULLNode
  br i1 %84, label %85, label %94

85:                                               ; preds = %82
  %86 = load ptr, ptr %4, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.Set, ptr %86, i32 0, i32 2
  %88 = load ptr, ptr %87, align 8, !tbaa !17
  %89 = load ptr, ptr %10, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.tnode, ptr %89, i32 0, i32 0
  %91 = load ptr, ptr %90, align 8, !tbaa !9
  %92 = load ptr, ptr %5, align 8, !tbaa !5
  %93 = call i32 %88(ptr noundef %91, ptr noundef %92)
  store i32 %93, ptr %12, align 4, !tbaa !18
  br label %95

94:                                               ; preds = %82
  br label %96

95:                                               ; preds = %85
  br label %52

96:                                               ; preds = %94
  %97 = load ptr, ptr %9, align 8, !tbaa !5
  %98 = load ptr, ptr %7, align 8, !tbaa !5
  %99 = getelementptr inbounds %struct.tnode, ptr %98, i32 0, i32 4
  store ptr %97, ptr %99, align 8, !tbaa !16
  %100 = load i32, ptr %11, align 4, !tbaa !18
  %101 = icmp slt i32 %100, 0
  br i1 %101, label %102, label %106

102:                                              ; preds = %96
  %103 = load ptr, ptr %7, align 8, !tbaa !5
  %104 = load ptr, ptr %9, align 8, !tbaa !5
  %105 = getelementptr inbounds %struct.tnode, ptr %104, i32 0, i32 3
  store ptr %103, ptr %105, align 8, !tbaa !20
  br label %110

106:                                              ; preds = %96
  %107 = load ptr, ptr %7, align 8, !tbaa !5
  %108 = load ptr, ptr %9, align 8, !tbaa !5
  %109 = getelementptr inbounds %struct.tnode, ptr %108, i32 0, i32 2
  store ptr %107, ptr %109, align 8, !tbaa !21
  br label %110

110:                                              ; preds = %106, %102
  %111 = load ptr, ptr %6, align 8, !tbaa !5
  call void @fix_insert(ptr noundef %111, ptr noundef %7)
  %112 = load ptr, ptr %4, align 8, !tbaa !5
  %113 = getelementptr inbounds %struct.Set, ptr %112, i32 0, i32 1
  %114 = load i64, ptr %113, align 8, !tbaa !12
  %115 = add i64 %114, 1
  store i64 %115, ptr %113, align 8, !tbaa !12
  store i1 true, ptr %3, align 1
  store i32 1, ptr %8, align 4
  br label %116

116:                                              ; preds = %110, %69
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #6
  br label %117

117:                                              ; preds = %116, %32
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #6
  %118 = load i1, ptr %3, align 1
  ret i1 %118
}

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @fix_insert(ptr noundef, ptr noundef) #4

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @CreateNode() #4

attributes #0 = { noreturn 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 = { 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 = { inlinehint 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 #5 = { noreturn nounwind }
attributes #6 = { 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, !6, i64 0}
!10 = !{!"tnode", !6, i64 0, !11, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !14, i64 8}
!13 = !{!"Set", !6, i64 0, !14, i64 8, !6, i64 16, !6, i64 24}
!14 = !{!"long", !7, i64 0}
!15 = !{!10, !11, i64 8}
!16 = !{!10, !6, i64 32}
!17 = !{!13, !6, i64 16}
!18 = !{!11, !11, i64 0}
!19 = !{!13, !6, i64 24}
!20 = !{!10, !6, i64 24}
!21 = !{!10, !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"

%struct.tnode = type { ptr, i32, ptr, ptr, ptr }

@NULLNode = external dso_local global %struct.tnode, align 8
@.str.1 = external hidden unnamed_addr constant [100 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [13 x i8], align 1
@__PRETTY_FUNCTION__.rbt_insert = external hidden unnamed_addr constant [46 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [17 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

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

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

; Function Attrs: nounwind uwtable
define dso_local noundef zeroext i1 @rbt_insert(ptr noundef %0, ptr noundef %1) local_unnamed_addr #2 {
  %3 = alloca ptr, align 8
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %4, label %5

4:                                                ; preds = %2
  tail call void @__assert_fail(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.1, i32 noundef 111, ptr noundef nonnull @__PRETTY_FUNCTION__.rbt_insert) #5
  unreachable

5:                                                ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #6
  %6 = tail call ptr @CreateNode()
  store ptr %6, ptr %3, align 8, !tbaa !5
  %.not36 = icmp eq ptr %6, null
  br i1 %.not36, label %7, label %8

7:                                                ; preds = %5
  tail call void @__assert_fail(ptr noundef nonnull @.str.4, ptr noundef nonnull @.str.1, i32 noundef 116, ptr noundef nonnull @__PRETTY_FUNCTION__.rbt_insert) #5
  unreachable

8:                                                ; preds = %5
  store ptr %1, ptr %6, align 8, !tbaa !9
  %9 = load ptr, ptr %0, align 8, !tbaa !5
  %10 = icmp eq ptr %9, null
  br i1 %10, label %11, label %15

11:                                               ; preds = %8
  %12 = getelementptr inbounds i8, ptr %0, i64 8
  store i64 1, ptr %12, align 8, !tbaa !12
  %13 = getelementptr inbounds i8, ptr %6, i64 8
  store i32 1, ptr %13, align 8, !tbaa !15
  %14 = getelementptr inbounds i8, ptr %6, i64 32
  store ptr null, ptr %14, align 8, !tbaa !16
  store ptr %6, ptr %0, align 8, !tbaa !5
  br label %35

15:                                               ; preds = %8
  %16 = getelementptr inbounds i8, ptr %0, i64 16
  %17 = load ptr, ptr %16, align 8, !tbaa !17
  %18 = load ptr, ptr %9, align 8, !tbaa !9
  %19 = tail call i32 %17(ptr noundef %18, ptr noundef %1) #6
  %.not3943 = icmp eq i32 %19, 0
  br i1 %.not3943, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %26, %15
  tail call void @free(ptr noundef %6) #6
  %20 = getelementptr inbounds i8, ptr %0, i64 24
  %21 = load ptr, ptr %20, align 8, !tbaa !18
  %.not38 = icmp eq ptr %21, null
  br i1 %.not38, label %35, label %22

22:                                               ; preds = %._crit_edge
  tail call void %21(ptr noundef %1) #6
  br label %35

.lr.ph:                                           ; preds = %15, %26
  %.045 = phi i32 [ %29, %26 ], [ %19, %15 ]
  %.03044 = phi ptr [ %.131, %26 ], [ %9, %15 ]
  %23 = icmp slt i32 %.045, 0
  %24 = getelementptr inbounds i8, ptr %.03044, i64 24
  %25 = getelementptr inbounds i8, ptr %.03044, i64 16
  %.131.in = select i1 %23, ptr %24, ptr %25
  %.131 = load ptr, ptr %.131.in, align 8, !tbaa !5
  %.not37 = icmp eq ptr %.131, @NULLNode
  br i1 %.not37, label %30, label %26

26:                                               ; preds = %.lr.ph
  %27 = load ptr, ptr %16, align 8, !tbaa !17
  %28 = load ptr, ptr %.131, align 8, !tbaa !9
  %29 = tail call i32 %27(ptr noundef %28, ptr noundef %1) #6
  %.not39 = icmp eq i32 %29, 0
  br i1 %.not39, label %._crit_edge, label %.lr.ph

30:                                               ; preds = %.lr.ph
  %31 = getelementptr inbounds i8, ptr %6, i64 32
  store ptr %.03044, ptr %31, align 8, !tbaa !16
  %. = select i1 %23, ptr %24, ptr %25
  store ptr %6, ptr %., align 8, !tbaa !5
  call void @fix_insert(ptr noundef nonnull %0, ptr noundef nonnull %3)
  %32 = getelementptr inbounds i8, ptr %0, i64 8
  %33 = load i64, ptr %32, align 8, !tbaa !12
  %34 = add i64 %33, 1
  store i64 %34, ptr %32, align 8, !tbaa !12
  br label %35

35:                                               ; preds = %30, %22, %._crit_edge, %11
  %.1 = phi i1 [ true, %11 ], [ false, %._crit_edge ], [ false, %22 ], [ true, %30 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #6
  ret i1 %.1
}

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @fix_insert(ptr noundef, ptr noundef) local_unnamed_addr #4

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @CreateNode() local_unnamed_addr #4

attributes #0 = { noreturn 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 #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 = { 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 #4 = { inlinehint 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 #5 = { noreturn nounwind }
attributes #6 = { 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, !6, i64 0}
!10 = !{!"tnode", !6, i64 0, !11, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !14, i64 8}
!13 = !{!"Set", !6, i64 0, !14, i64 8, !6, i64 16, !6, i64 24}
!14 = !{!"long", !7, i64 0}
!15 = !{!10, !11, i64 8}
!16 = !{!10, !6, i64 32}
!17 = !{!13, !6, i64 16}
!18 = !{!13, !6, i64 24}


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