; LLVM IR from recp/ds :: src (rb)

; 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.RBTree = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i64 }
%struct.RBNode = type { ptr, ptr, [2 x 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
define dso_local i32 @rb_parent(ptr noundef %0, ptr noundef %1, ptr noundef %2) #1 {
  %4 = alloca ptr, align 8
  %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 %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  store i32 1, ptr %9, align 4, !tbaa !9
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.RBTree, ptr %11, i32 0, i32 1
  %13 = load ptr, ptr %12, align 8, !tbaa !11
  %14 = getelementptr inbounds %struct.RBNode, ptr %13, i32 0, i32 2
  %15 = load i32, ptr %9, align 4, !tbaa !9
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [2 x ptr], ptr %14, i64 0, i64 %16
  %18 = load ptr, ptr %17, align 8, !tbaa !5
  store ptr %18, ptr %7, align 8, !tbaa !5
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.RBTree, ptr %19, i32 0, i32 1
  %21 = load ptr, ptr %20, align 8, !tbaa !11
  store ptr %21, ptr %8, align 8, !tbaa !5
  store i32 -1, ptr %10, align 4, !tbaa !9
  br label %22

22:                                               ; preds = %40, %3
  %23 = load ptr, ptr %7, align 8, !tbaa !5
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.RBTree, ptr %24, i32 0, i32 2
  %26 = load ptr, ptr %25, align 8, !tbaa !14
  %27 = icmp ne ptr %23, %26
  br i1 %27, label %28, label %51

28:                                               ; preds = %22
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.RBTree, ptr %29, i32 0, i32 4
  %31 = load ptr, ptr %30, align 8, !tbaa !15
  %32 = load ptr, ptr %7, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.RBNode, ptr %32, i32 0, i32 0
  %34 = load ptr, ptr %33, align 8, !tbaa !16
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = call i32 %31(ptr noundef %34, ptr noundef %35)
  store i32 %36, ptr %10, align 4, !tbaa !9
  %37 = load i32, ptr %10, align 4, !tbaa !9
  %38 = icmp eq i32 %37, 0
  br i1 %38, label %39, label %40

39:                                               ; preds = %28
  br label %51

40:                                               ; preds = %28
  %41 = load i32, ptr %10, align 4, !tbaa !9
  %42 = icmp slt i32 %41, 0
  %43 = zext i1 %42 to i32
  store i32 %43, ptr %9, align 4, !tbaa !9
  %44 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %44, ptr %8, align 8, !tbaa !5
  %45 = load ptr, ptr %7, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.RBNode, ptr %45, i32 0, i32 2
  %47 = load i32, ptr %9, align 4, !tbaa !9
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [2 x ptr], ptr %46, i64 0, i64 %48
  %50 = load ptr, ptr %49, align 8, !tbaa !5
  store ptr %50, ptr %7, align 8, !tbaa !5
  br label %22, !llvm.loop !18

51:                                               ; preds = %39, %22
  %52 = load i32, ptr %10, align 4, !tbaa !9
  %53 = icmp ne i32 %52, 0
  br i1 %53, label %54, label %56

54:                                               ; preds = %51
  %55 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr null, ptr %55, align 8, !tbaa !5
  br label %59

56:                                               ; preds = %51
  %57 = load ptr, ptr %8, align 8, !tbaa !5
  %58 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %57, ptr %58, align 8, !tbaa !5
  br label %59

59:                                               ; preds = %56, %54
  %60 = load i32, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  ret i32 %60
}

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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 8}
!12 = !{!"RBTree", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !13, i64 64}
!13 = !{!"long", !7, i64 0}
!14 = !{!12, !6, i64 16}
!15 = !{!12, !6, i64 32}
!16 = !{!17, !6, i64 0}
!17 = !{!"RBNode", !6, i64 0, !6, i64 8, !7, i64 16, !7, i64 32}
!18 = distinct !{!18, !19}
!19 = !{!"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 range(i32 0, 2) i32 @rb_parent(ptr nocapture noundef readonly %0, ptr noundef %1, ptr nocapture noundef writeonly %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %5, i64 24
  %7 = getelementptr inbounds i8, ptr %0, i64 32
  %8 = getelementptr inbounds i8, ptr %0, i64 16
  %.01923 = load ptr, ptr %6, align 8, !tbaa !11
  %9 = load ptr, ptr %8, align 8, !tbaa !12
  %.not.not24 = icmp eq ptr %.01923, %9
  br i1 %.not.not24, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %3
  %10 = load ptr, ptr %7, align 8, !tbaa !13
  %11 = load ptr, ptr %.01923, align 8, !tbaa !14
  %12 = tail call i32 %10(ptr noundef %11, ptr noundef %1) #1
  %13 = icmp eq i32 %12, 0
  br i1 %13, label %._crit_edge, label %.lr.ph33

.lr.ph:                                           ; preds = %.lr.ph33
  %14 = load ptr, ptr %7, align 8, !tbaa !13
  %15 = load ptr, ptr %.019, align 8, !tbaa !14
  %16 = tail call i32 %14(ptr noundef %15, ptr noundef %1) #1
  %17 = icmp eq i32 %16, 0
  br i1 %17, label %._crit_edge, label %.lr.ph33, !llvm.loop !16

.lr.ph33:                                         ; preds = %.lr.ph.preheader, %.lr.ph
  %18 = phi i32 [ %16, %.lr.ph ], [ %12, %.lr.ph.preheader ]
  %.0192732 = phi ptr [ %.019, %.lr.ph ], [ %.01923, %.lr.ph.preheader ]
  %.lobit = lshr i32 %18, 31
  %19 = getelementptr inbounds i8, ptr %.0192732, i64 16
  %20 = zext nneg i32 %.lobit to i64
  %21 = getelementptr inbounds [2 x ptr], ptr %19, i64 0, i64 %20
  %.019 = load ptr, ptr %21, align 8, !tbaa !11
  %22 = load ptr, ptr %8, align 8, !tbaa !12
  %.not.not = icmp eq ptr %.019, %22
  br i1 %.not.not, label %._crit_edge, label %.lr.ph, !llvm.loop !16

._crit_edge:                                      ; preds = %.lr.ph, %.lr.ph33, %.lr.ph.preheader, %3
  %.017.lcssa = phi i32 [ 1, %3 ], [ 1, %.lr.ph.preheader ], [ %.lobit, %.lr.ph33 ], [ %.lobit, %.lr.ph ]
  %..018 = phi ptr [ null, %3 ], [ %5, %.lr.ph.preheader ], [ null, %.lr.ph33 ], [ %.0192732, %.lr.ph ]
  store ptr %..018, ptr %2, align 8, !tbaa !11
  ret i32 %.017.lcssa
}

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


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