; LLVM IR from yudi-matsuzake/libgenerics :: src (red_black_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.redblacktree_t = type { i64, i64, ptr, ptr, i64, ptr }
%struct.redblacknode_t = type { ptr, ptr, ptr, i32, ptr }

; 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
define dso_local i32 @rbtree_find_node(ptr noundef %0, ptr noundef %1, ptr noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  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
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = icmp ne ptr %11, null
  br i1 %12, label %14, label %13

13:                                               ; preds = %3
  store i32 1, ptr %4, align 4
  br label %57

14:                                               ; preds = %3
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = icmp ne ptr %15, null
  br i1 %16, label %18, label %17

17:                                               ; preds = %14
  store i32 11, ptr %4, align 4
  br label %57

18:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.redblacktree_t, ptr %19, i32 0, i32 5
  %21 = load ptr, ptr %20, align 8, !tbaa !9
  store ptr %21, ptr %8, align 8, !tbaa !5
  %22 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr null, ptr %22, align 8, !tbaa !5
  br label %23

23:                                               ; preds = %54, %18
  %24 = load ptr, ptr %8, align 8, !tbaa !5
  %25 = icmp ne ptr %24, null
  br i1 %25, label %26, label %55

26:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.redblacktree_t, ptr %27, i32 0, i32 2
  %29 = load ptr, ptr %28, align 8, !tbaa !12
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = load ptr, ptr %8, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.redblacknode_t, ptr %31, i32 0, i32 4
  %33 = load ptr, ptr %32, align 8, !tbaa !13
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.redblacktree_t, ptr %34, i32 0, i32 3
  %36 = load ptr, ptr %35, align 8, !tbaa !16
  %37 = call i32 %29(ptr noundef %30, ptr noundef %33, ptr noundef %36)
  store i32 %37, ptr %9, align 4, !tbaa !17
  %38 = load i32, ptr %9, align 4, !tbaa !17
  switch i32 %38, label %50 [
    i32 -1, label %39
    i32 1, label %43
    i32 0, label %47
  ]

39:                                               ; preds = %26
  %40 = load ptr, ptr %8, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.redblacknode_t, ptr %40, i32 0, i32 0
  %42 = load ptr, ptr %41, align 8, !tbaa !18
  store ptr %42, ptr %8, align 8, !tbaa !5
  br label %51

43:                                               ; preds = %26
  %44 = load ptr, ptr %8, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.redblacknode_t, ptr %44, i32 0, i32 1
  %46 = load ptr, ptr %45, align 8, !tbaa !19
  store ptr %46, ptr %8, align 8, !tbaa !5
  br label %51

47:                                               ; preds = %26
  %48 = load ptr, ptr %8, align 8, !tbaa !5
  %49 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %48, ptr %49, align 8, !tbaa !5
  store i32 0, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %52

50:                                               ; preds = %26
  store i32 15, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %52

51:                                               ; preds = %43, %39
  store i32 0, ptr %10, align 4
  br label %52

52:                                               ; preds = %51, %50, %47
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  %53 = load i32, ptr %10, align 4
  switch i32 %53, label %56 [
    i32 0, label %54
  ]

54:                                               ; preds = %52
  br label %23, !llvm.loop !20

55:                                               ; preds = %23
  store i32 13, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %56

56:                                               ; preds = %55, %52
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  br label %57

57:                                               ; preds = %56, %17, %13
  %58 = load i32, ptr %4, align 4
  ret i32 %58
}

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, !6, i64 40}
!10 = !{!"redblacktree_t", !11, i64 0, !11, i64 8, !6, i64 16, !6, i64 24, !11, i64 32, !6, i64 40}
!11 = !{!"long", !7, i64 0}
!12 = !{!10, !6, i64 16}
!13 = !{!14, !6, i64 32}
!14 = !{!"redblacknode_t", !6, i64 0, !6, i64 8, !6, i64 16, !15, i64 24, !6, i64 32}
!15 = !{!"int", !7, i64 0}
!16 = !{!10, !6, i64 24}
!17 = !{!15, !15, i64 0}
!18 = !{!14, !6, i64 0}
!19 = !{!14, !6, i64 8}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}


; 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 noundef i32 @rbtree_find_node(ptr noundef readonly %0, ptr noundef %1, ptr nocapture noundef writeonly %2) local_unnamed_addr #0 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %.thread, label %4

4:                                                ; preds = %3
  %.not21 = icmp eq ptr %1, null
  br i1 %.not21, label %.thread, label %5

5:                                                ; preds = %4
  %6 = getelementptr inbounds i8, ptr %0, i64 40
  %7 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr null, ptr %2, align 8, !tbaa !11
  %.not2227 = icmp eq ptr %7, null
  br i1 %.not2227, label %.thread, label %.lr.ph

.lr.ph:                                           ; preds = %5
  %8 = getelementptr inbounds i8, ptr %0, i64 16
  %9 = getelementptr inbounds i8, ptr %0, i64 24
  br label %10

10:                                               ; preds = %.lr.ph, %19
  %.01628 = phi ptr [ %7, %.lr.ph ], [ %.117, %19 ]
  %11 = load ptr, ptr %8, align 8, !tbaa !12
  %12 = getelementptr inbounds i8, ptr %.01628, i64 32
  %13 = load ptr, ptr %12, align 8, !tbaa !13
  %14 = load ptr, ptr %9, align 8, !tbaa !16
  %15 = tail call i32 %11(ptr noundef nonnull %1, ptr noundef %13, ptr noundef %14) #1
  switch i32 %15, label %.thread [
    i32 -1, label %19
    i32 1, label %16
    i32 0, label %18
  ]

16:                                               ; preds = %10
  %17 = getelementptr inbounds i8, ptr %.01628, i64 8
  br label %19

18:                                               ; preds = %10
  store ptr %.01628, ptr %2, align 8, !tbaa !11
  br label %.thread

19:                                               ; preds = %16, %10
  %.117.in = phi ptr [ %17, %16 ], [ %.01628, %10 ]
  %.117 = load ptr, ptr %.117.in, align 8, !tbaa !11
  %.not22 = icmp eq ptr %.117, null
  br i1 %.not22, label %.thread, label %10, !llvm.loop !17

.thread:                                          ; preds = %19, %10, %5, %18, %4, %3
  %.3 = phi i32 [ 1, %3 ], [ 11, %4 ], [ 0, %18 ], [ 13, %5 ], [ 13, %19 ], [ 15, %10 ]
  ret i32 %.3
}

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, !10, i64 40}
!6 = !{!"redblacktree_t", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 24, !7, i64 32, !10, i64 40}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!10, !10, i64 0}
!12 = !{!6, !10, i64 16}
!13 = !{!14, !10, i64 32}
!14 = !{!"redblacknode_t", !10, i64 0, !10, i64 8, !10, i64 16, !15, i64 24, !10, i64 32}
!15 = !{!"int", !8, i64 0}
!16 = !{!6, !10, i64 24}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


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