; LLVM IR from maksimandrianov/cdcontainers :: src (avl-tree)

; 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.cdc_avl_tree = type { ptr, i64, ptr }
%struct.cdc_data_info = type { ptr, ptr, ptr, ptr, ptr, i64, i64 }
%struct.cdc_avl_tree_node = type { ptr, ptr, ptr, ptr, ptr, i8 }
%struct.cdc_avl_tree_iter = type { ptr, ptr, ptr }

@.str = external hidden unnamed_addr constant [10 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [77 x i8], align 1
@__PRETTY_FUNCTION__.cdc_avl_tree_insert_or_assign1 = external hidden unnamed_addr constant [103 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
declare hidden ptr @cdc_tree_predecessor(ptr noundef) #2

; Function Attrs: nounwind uwtable
declare hidden ptr @find_hint(ptr noundef, ptr noundef, ptr noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @cdc_eq(ptr noundef, ptr noundef, ptr noundef) #3

; Function Attrs: nounwind uwtable
declare hidden ptr @make_new_node(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
declare hidden ptr @insert_unique(ptr noundef, ptr noundef, ptr noundef) #2

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

18:                                               ; preds = %5
  br label %20

19:                                               ; preds = %5
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 448, ptr noundef @__PRETTY_FUNCTION__.cdc_avl_tree_insert_or_assign1) #4
  unreachable

20:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  %21 = load ptr, ptr %7, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.cdc_avl_tree, ptr %21, i32 0, i32 0
  %23 = load ptr, ptr %22, align 8, !tbaa !9
  %24 = load ptr, ptr %8, align 8, !tbaa !5
  %25 = load ptr, ptr %7, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.cdc_avl_tree, ptr %25, i32 0, i32 2
  %27 = load ptr, ptr %26, align 8, !tbaa !12
  %28 = getelementptr inbounds %struct.cdc_data_info, ptr %27, i32 0, i32 1
  %29 = load ptr, ptr %28, align 8, !tbaa !13
  %30 = call ptr @find_hint(ptr noundef %23, ptr noundef %24, ptr noundef %29)
  store ptr %30, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %13) #5
  %31 = load ptr, ptr %12, align 8, !tbaa !5
  %32 = icmp ne ptr %31, null
  br i1 %32, label %33, label %45

33:                                               ; preds = %20
  %34 = load ptr, ptr %7, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.cdc_avl_tree, ptr %34, i32 0, i32 2
  %36 = load ptr, ptr %35, align 8, !tbaa !12
  %37 = getelementptr inbounds %struct.cdc_data_info, ptr %36, i32 0, i32 1
  %38 = load ptr, ptr %37, align 8, !tbaa !13
  %39 = load ptr, ptr %12, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.cdc_avl_tree_node, ptr %39, i32 0, i32 3
  %41 = load ptr, ptr %40, align 8, !tbaa !15
  %42 = load ptr, ptr %8, align 8, !tbaa !5
  %43 = call i32 @cdc_eq(ptr noundef %38, ptr noundef %41, ptr noundef %42)
  %44 = icmp ne i32 %43, 0
  br label %45

45:                                               ; preds = %33, %20
  %46 = phi i1 [ false, %20 ], [ %44, %33 ]
  %47 = zext i1 %46 to i8
  store i8 %47, ptr %13, align 1, !tbaa !17
  %48 = load i8, ptr %13, align 1, !tbaa !17, !range !19, !noundef !20
  %49 = trunc i8 %48 to i1
  br i1 %49, label %65, label %50

50:                                               ; preds = %45
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #5
  %51 = load ptr, ptr %8, align 8, !tbaa !5
  %52 = load ptr, ptr %9, align 8, !tbaa !5
  %53 = call ptr @make_new_node(ptr noundef %51, ptr noundef %52)
  store ptr %53, ptr %14, align 8, !tbaa !5
  %54 = load ptr, ptr %14, align 8, !tbaa !5
  %55 = icmp ne ptr %54, null
  br i1 %55, label %57, label %56

56:                                               ; preds = %50
  store i32 1, ptr %6, align 4
  store i32 1, ptr %15, align 4
  br label %62

57:                                               ; preds = %50
  %58 = load ptr, ptr %7, align 8, !tbaa !5
  %59 = load ptr, ptr %14, align 8, !tbaa !5
  %60 = load ptr, ptr %12, align 8, !tbaa !5
  %61 = call ptr @insert_unique(ptr noundef %58, ptr noundef %59, ptr noundef %60)
  store ptr %61, ptr %12, align 8, !tbaa !5
  store i32 0, ptr %15, align 4
  br label %62

62:                                               ; preds = %57, %56
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #5
  %63 = load i32, ptr %15, align 4
  switch i32 %63, label %93 [
    i32 0, label %64
  ]

64:                                               ; preds = %62
  br label %69

65:                                               ; preds = %45
  %66 = load ptr, ptr %9, align 8, !tbaa !5
  %67 = load ptr, ptr %12, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.cdc_avl_tree_node, ptr %67, i32 0, i32 4
  store ptr %66, ptr %68, align 8, !tbaa !21
  br label %69

69:                                               ; preds = %65, %64
  %70 = load ptr, ptr %10, align 8, !tbaa !5
  %71 = icmp ne ptr %70, null
  br i1 %71, label %72, label %83

72:                                               ; preds = %69
  %73 = load ptr, ptr %7, align 8, !tbaa !5
  %74 = load ptr, ptr %10, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.cdc_avl_tree_iter, ptr %74, i32 0, i32 0
  store ptr %73, ptr %75, align 8, !tbaa !22
  %76 = load ptr, ptr %12, align 8, !tbaa !5
  %77 = load ptr, ptr %10, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.cdc_avl_tree_iter, ptr %77, i32 0, i32 2
  store ptr %76, ptr %78, align 8, !tbaa !24
  %79 = load ptr, ptr %12, align 8, !tbaa !5
  %80 = call ptr @cdc_tree_predecessor(ptr noundef %79)
  %81 = load ptr, ptr %10, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.cdc_avl_tree_iter, ptr %81, i32 0, i32 1
  store ptr %80, ptr %82, align 8, !tbaa !25
  br label %83

83:                                               ; preds = %72, %69
  %84 = load ptr, ptr %11, align 8, !tbaa !5
  %85 = icmp ne ptr %84, null
  br i1 %85, label %86, label %92

86:                                               ; preds = %83
  %87 = load i8, ptr %13, align 1, !tbaa !17, !range !19, !noundef !20
  %88 = trunc i8 %87 to i1
  %89 = xor i1 %88, true
  %90 = load ptr, ptr %11, align 8, !tbaa !5
  %91 = zext i1 %89 to i8
  store i8 %91, ptr %90, align 1, !tbaa !17
  br label %92

92:                                               ; preds = %86, %83
  store i32 0, ptr %6, align 4
  store i32 1, ptr %15, align 4
  br label %93

93:                                               ; preds = %92, %62
  call void @llvm.lifetime.end.p0(i64 1, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  %94 = load i32, ptr %6, align 4
  ret i32 %94
}

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 = { 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 #4 = { noreturn nounwind }
attributes #5 = { 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 = !{!"cdc_avl_tree", !6, i64 0, !11, i64 8, !6, i64 16}
!11 = !{!"long", !7, i64 0}
!12 = !{!10, !6, i64 16}
!13 = !{!14, !6, i64 8}
!14 = !{!"cdc_data_info", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !11, i64 40, !11, i64 48}
!15 = !{!16, !6, i64 24}
!16 = !{!"cdc_avl_tree_node", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !7, i64 40}
!17 = !{!18, !18, i64 0}
!18 = !{!"_Bool", !7, i64 0}
!19 = !{i8 0, i8 2}
!20 = !{}
!21 = !{!16, !6, i64 32}
!22 = !{!23, !6, i64 0}
!23 = !{!"cdc_avl_tree_iter", !6, i64 0, !6, i64 8, !6, i64 16}
!24 = !{!23, !6, i64 16}
!25 = !{!23, !6, i64 8}


; 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"

@.str = external hidden unnamed_addr constant [10 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [77 x i8], align 1
@__PRETTY_FUNCTION__.cdc_avl_tree_insert_or_assign1 = external hidden unnamed_addr constant [103 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: nounwind uwtable
declare hidden ptr @cdc_tree_predecessor(ptr noundef) local_unnamed_addr #1

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @cdc_eq(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

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

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @cdc_avl_tree_insert_or_assign1(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef writeonly %3, ptr noundef writeonly %4) local_unnamed_addr #1 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %6, label %7

6:                                                ; preds = %5
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 448, ptr noundef nonnull @__PRETTY_FUNCTION__.cdc_avl_tree_insert_or_assign1) #3
  unreachable

7:                                                ; preds = %5
  %8 = load ptr, ptr %0, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %0, i64 16
  %10 = load ptr, ptr %9, align 8, !tbaa !11
  %11 = getelementptr inbounds i8, ptr %10, i64 8
  %12 = load ptr, ptr %11, align 8, !tbaa !12
  %13 = tail call ptr @find_hint(ptr noundef %8, ptr noundef %1, ptr noundef %12)
  %.not36 = icmp eq ptr %13, null
  br i1 %.not36, label %.thread, label %14

14:                                               ; preds = %7
  %15 = load ptr, ptr %9, align 8, !tbaa !11
  %16 = getelementptr inbounds i8, ptr %15, i64 8
  %17 = load ptr, ptr %16, align 8, !tbaa !12
  %18 = getelementptr inbounds i8, ptr %13, i64 24
  %19 = load ptr, ptr %18, align 8, !tbaa !14
  %20 = tail call i32 @cdc_eq(ptr noundef %17, ptr noundef %19, ptr noundef %1)
  %.not42 = icmp eq i32 %20, 0
  br i1 %.not42, label %.thread, label %24

.thread:                                          ; preds = %7, %14
  %21 = tail call ptr @make_new_node(ptr noundef %1, ptr noundef %2)
  %.not37.not = icmp eq ptr %21, null
  br i1 %.not37.not, label %.thread40, label %22

22:                                               ; preds = %.thread
  %23 = tail call ptr @insert_unique(ptr noundef nonnull %0, ptr noundef nonnull %21, ptr noundef %13)
  br label %26

24:                                               ; preds = %14
  %25 = getelementptr inbounds i8, ptr %13, i64 32
  store ptr %2, ptr %25, align 8, !tbaa !16
  br label %26

26:                                               ; preds = %22, %24
  %27 = phi i8 [ 0, %24 ], [ 1, %22 ]
  %.130 = phi ptr [ %13, %24 ], [ %23, %22 ]
  %.not38 = icmp eq ptr %3, null
  br i1 %.not38, label %32, label %28

28:                                               ; preds = %26
  store ptr %0, ptr %3, align 8, !tbaa !17
  %29 = getelementptr inbounds i8, ptr %3, i64 16
  store ptr %.130, ptr %29, align 8, !tbaa !19
  %30 = tail call ptr @cdc_tree_predecessor(ptr noundef %.130)
  %31 = getelementptr inbounds i8, ptr %3, i64 8
  store ptr %30, ptr %31, align 8, !tbaa !20
  br label %32

32:                                               ; preds = %28, %26
  %.not39 = icmp eq ptr %4, null
  br i1 %.not39, label %.thread40, label %33

33:                                               ; preds = %32
  store i8 %27, ptr %4, align 1, !tbaa !21
  br label %.thread40

.thread40:                                        ; preds = %.thread, %32, %33
  %.1 = phi i32 [ 0, %33 ], [ 0, %32 ], [ 1, %.thread ]
  ret i32 %.1
}

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 = { 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 = { 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 #3 = { noreturn 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 0}
!6 = !{!"cdc_avl_tree", !7, i64 0, !10, i64 8, !7, i64 16}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!6, !7, i64 16}
!12 = !{!13, !7, i64 8}
!13 = !{!"cdc_data_info", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !10, i64 40, !10, i64 48}
!14 = !{!15, !7, i64 24}
!15 = !{!"cdc_avl_tree_node", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !8, i64 40}
!16 = !{!15, !7, i64 32}
!17 = !{!18, !7, i64 0}
!18 = !{!"cdc_avl_tree_iter", !7, i64 0, !7, i64 8, !7, i64 16}
!19 = !{!18, !7, i64 16}
!20 = !{!18, !7, i64 8}
!21 = !{!22, !22, i64 0}
!22 = !{!"_Bool", !8, i64 0}


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