; LLVM IR from li-xilin/axe :: src/core (splay)

; 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.ax_splay_node_st = type { ptr, ptr, ptr }

@.str = external hidden unnamed_addr constant [21 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [63 x i8], align 1
@__PRETTY_FUNCTION__.check_node_sanity = external hidden unnamed_addr constant [73 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [22 x i8], align 1

; 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 @check_node_sanity(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #1 {
  %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 ptr, align 8
  %11 = alloca ptr, align 8
  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
  store ptr %3, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store i32 1, ptr %9, align 4, !tbaa !9
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.ax_splay_node_st, ptr %12, i32 0, i32 1
  %14 = load ptr, ptr %13, align 8, !tbaa !11
  %15 = icmp ne ptr %14, null
  br i1 %15, label %16, label %49

16:                                               ; preds = %4
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.ax_splay_node_st, ptr %17, i32 0, i32 1
  %19 = load ptr, ptr %18, align 8, !tbaa !11
  %20 = getelementptr inbounds %struct.ax_splay_node_st, ptr %19, i32 0, i32 0
  %21 = load ptr, ptr %20, align 8, !tbaa !13
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = icmp eq ptr %21, %22
  br i1 %23, label %24, label %25

24:                                               ; preds = %16
  br label %26

25:                                               ; preds = %16
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 239, ptr noundef @__PRETTY_FUNCTION__.check_node_sanity) #4
  unreachable

26:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = icmp ne ptr %27, null
  br i1 %28, label %29, label %35

29:                                               ; preds = %26
  %30 = load ptr, ptr %8, align 8, !tbaa !5
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = call i32 %30(ptr noundef %31, ptr noundef %32)
  %34 = icmp slt i32 %33, 0
  br i1 %34, label %35, label %37

35:                                               ; preds = %29, %26
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %36, ptr %10, align 8, !tbaa !5
  br label %39

37:                                               ; preds = %29
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %38, ptr %10, align 8, !tbaa !5
  br label %39

39:                                               ; preds = %37, %35
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.ax_splay_node_st, ptr %40, i32 0, i32 1
  %42 = load ptr, ptr %41, align 8, !tbaa !11
  %43 = load ptr, ptr %10, align 8, !tbaa !5
  %44 = load ptr, ptr %7, align 8, !tbaa !5
  %45 = load ptr, ptr %8, align 8, !tbaa !5
  %46 = call i32 @check_node_sanity(ptr noundef %42, ptr noundef %43, ptr noundef %44, ptr noundef %45)
  %47 = load i32, ptr %9, align 4, !tbaa !9
  %48 = add nsw i32 %47, %46
  store i32 %48, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  br label %49

49:                                               ; preds = %39, %4
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.ax_splay_node_st, ptr %50, i32 0, i32 2
  %52 = load ptr, ptr %51, align 8, !tbaa !14
  %53 = icmp ne ptr %52, null
  br i1 %53, label %54, label %87

54:                                               ; preds = %49
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.ax_splay_node_st, ptr %55, i32 0, i32 2
  %57 = load ptr, ptr %56, align 8, !tbaa !14
  %58 = getelementptr inbounds %struct.ax_splay_node_st, ptr %57, i32 0, i32 0
  %59 = load ptr, ptr %58, align 8, !tbaa !13
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  %61 = icmp eq ptr %59, %60
  br i1 %61, label %62, label %63

62:                                               ; preds = %54
  br label %64

63:                                               ; preds = %54
  call void @__assert_fail(ptr noundef @.str.2, ptr noundef @.str.1, i32 noundef 248, ptr noundef @__PRETTY_FUNCTION__.check_node_sanity) #4
  unreachable

64:                                               ; preds = %62
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %65 = load ptr, ptr %7, align 8, !tbaa !5
  %66 = icmp ne ptr %65, null
  br i1 %66, label %67, label %73

67:                                               ; preds = %64
  %68 = load ptr, ptr %8, align 8, !tbaa !5
  %69 = load ptr, ptr %5, align 8, !tbaa !5
  %70 = load ptr, ptr %7, align 8, !tbaa !5
  %71 = call i32 %68(ptr noundef %69, ptr noundef %70)
  %72 = icmp sgt i32 %71, 0
  br i1 %72, label %73, label %75

73:                                               ; preds = %67, %64
  %74 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %74, ptr %11, align 8, !tbaa !5
  br label %77

75:                                               ; preds = %67
  %76 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %76, ptr %11, align 8, !tbaa !5
  br label %77

77:                                               ; preds = %75, %73
  %78 = load ptr, ptr %5, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.ax_splay_node_st, ptr %78, i32 0, i32 2
  %80 = load ptr, ptr %79, align 8, !tbaa !14
  %81 = load ptr, ptr %6, align 8, !tbaa !5
  %82 = load ptr, ptr %11, align 8, !tbaa !5
  %83 = load ptr, ptr %8, align 8, !tbaa !5
  %84 = call i32 @check_node_sanity(ptr noundef %80, ptr noundef %81, ptr noundef %82, ptr noundef %83)
  %85 = load i32, ptr %9, align 4, !tbaa !9
  %86 = add nsw i32 %85, %84
  store i32 %86, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  br label %87

87:                                               ; preds = %77, %49
  %88 = load i32, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  ret i32 %88
}

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

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 = { 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 #3 = { nounwind }
attributes #4 = { 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, !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 = !{!"ax_splay_node_st", !6, i64 0, !6, i64 8, !6, i64 16}
!13 = !{!12, !6, i64 0}
!14 = !{!12, !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"

@.str = external hidden unnamed_addr constant [21 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [63 x i8], align 1
@__PRETTY_FUNCTION__.check_node_sanity = external hidden unnamed_addr constant [73 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [22 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @check_node_sanity(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #0 {
  %.not36 = icmp eq ptr %1, null
  br i1 %.not36, label %tailrecurse.us, label %tailrecurse

tailrecurse.us:                                   ; preds = %4, %23
  %accumulator.tr.us = phi i32 [ %25, %23 ], [ 0, %4 ]
  %.tr.us = phi ptr [ %24, %23 ], [ %0, %4 ]
  %.tr41.us = phi ptr [ %.0.us, %23 ], [ %2, %4 ]
  %5 = getelementptr inbounds i8, ptr %.tr.us, i64 8
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %.not.us = icmp eq ptr %6, null
  br i1 %.not.us, label %13, label %7

7:                                                ; preds = %tailrecurse.us
  %8 = load ptr, ptr %6, align 8, !tbaa !10
  %9 = icmp eq ptr %8, %.tr.us
  br i1 %9, label %10, label %.split47.us

10:                                               ; preds = %7
  %11 = tail call i32 @check_node_sanity(ptr noundef nonnull %6, ptr noundef nonnull %.tr.us, ptr noundef %.tr41.us, ptr noundef %3)
  %12 = add nsw i32 %11, 1
  br label %13

13:                                               ; preds = %10, %tailrecurse.us
  %.029.us = phi i32 [ %12, %10 ], [ 1, %tailrecurse.us ]
  %14 = getelementptr inbounds i8, ptr %.tr.us, i64 16
  %15 = load ptr, ptr %14, align 8, !tbaa !11
  %.not37.us = icmp eq ptr %15, null
  br i1 %.not37.us, label %.split49.us, label %16

16:                                               ; preds = %13
  %17 = load ptr, ptr %15, align 8, !tbaa !10
  %18 = icmp eq ptr %17, %.tr.us
  br i1 %18, label %19, label %.split52.us

19:                                               ; preds = %16
  %.not38.us = icmp eq ptr %.tr41.us, null
  br i1 %.not38.us, label %23, label %20

20:                                               ; preds = %19
  %21 = tail call i32 %3(ptr noundef nonnull %.tr.us, ptr noundef nonnull %.tr41.us) #2
  %22 = icmp sgt i32 %21, 0
  %spec.select39.us = select i1 %22, ptr %.tr.us, ptr %.tr41.us
  %.pre62 = load ptr, ptr %14, align 8, !tbaa !11
  br label %23

23:                                               ; preds = %20, %19
  %24 = phi ptr [ %15, %19 ], [ %.pre62, %20 ]
  %.0.us = phi ptr [ %.tr.us, %19 ], [ %spec.select39.us, %20 ]
  %25 = add nsw i32 %.029.us, %accumulator.tr.us
  br label %tailrecurse.us

tailrecurse:                                      ; preds = %4, %47
  %accumulator.tr = phi i32 [ %49, %47 ], [ 0, %4 ]
  %.tr = phi ptr [ %48, %47 ], [ %0, %4 ]
  %.tr41 = phi ptr [ %.0, %47 ], [ %2, %4 ]
  %26 = getelementptr inbounds i8, ptr %.tr, i64 8
  %27 = load ptr, ptr %26, align 8, !tbaa !5
  %.not = icmp eq ptr %27, null
  br i1 %.not, label %37, label %28

28:                                               ; preds = %tailrecurse
  %29 = load ptr, ptr %27, align 8, !tbaa !10
  %30 = icmp eq ptr %29, %.tr
  br i1 %30, label %31, label %.split47.us

.split47.us:                                      ; preds = %28, %7
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 239, ptr noundef nonnull @__PRETTY_FUNCTION__.check_node_sanity) #3
  unreachable

31:                                               ; preds = %28
  %32 = tail call i32 %3(ptr noundef nonnull %.tr, ptr noundef nonnull %1) #2
  %33 = icmp slt i32 %32, 0
  %spec.select = select i1 %33, ptr %.tr, ptr %1
  %34 = load ptr, ptr %26, align 8, !tbaa !5
  %35 = tail call i32 @check_node_sanity(ptr noundef %34, ptr noundef nonnull %spec.select, ptr noundef %.tr41, ptr noundef %3)
  %36 = add nsw i32 %35, 1
  br label %37

37:                                               ; preds = %31, %tailrecurse
  %.029 = phi i32 [ %36, %31 ], [ 1, %tailrecurse ]
  %38 = getelementptr inbounds i8, ptr %.tr, i64 16
  %39 = load ptr, ptr %38, align 8, !tbaa !11
  %.not37 = icmp eq ptr %39, null
  br i1 %.not37, label %.split49.us, label %40

40:                                               ; preds = %37
  %41 = load ptr, ptr %39, align 8, !tbaa !10
  %42 = icmp eq ptr %41, %.tr
  br i1 %42, label %43, label %.split52.us

.split52.us:                                      ; preds = %40, %16
  tail call void @__assert_fail(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.1, i32 noundef 248, ptr noundef nonnull @__PRETTY_FUNCTION__.check_node_sanity) #3
  unreachable

43:                                               ; preds = %40
  %.not38 = icmp eq ptr %.tr41, null
  br i1 %.not38, label %47, label %44

44:                                               ; preds = %43
  %45 = tail call i32 %3(ptr noundef nonnull %.tr, ptr noundef nonnull %.tr41) #2
  %46 = icmp sgt i32 %45, 0
  %spec.select39 = select i1 %46, ptr %.tr, ptr %.tr41
  %.pre = load ptr, ptr %38, align 8, !tbaa !11
  br label %47

47:                                               ; preds = %44, %43
  %48 = phi ptr [ %39, %43 ], [ %.pre, %44 ]
  %.0 = phi ptr [ %.tr, %43 ], [ %spec.select39, %44 ]
  %49 = add nsw i32 %.029, %accumulator.tr
  br label %tailrecurse

.split49.us:                                      ; preds = %37, %13
  %.us-phi = phi i32 [ %.029.us, %13 ], [ %.029, %37 ]
  %.us-phi50 = phi i32 [ %accumulator.tr.us, %13 ], [ %accumulator.tr, %37 ]
  %accumulator.ret.tr = add nsw i32 %.us-phi, %.us-phi50
  ret i32 %accumulator.ret.tr
}

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

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 = { 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 #2 = { nounwind }
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 8}
!6 = !{!"ax_splay_node_st", !7, i64 0, !7, i64 8, !7, i64 16}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!6, !7, i64 0}
!11 = !{!6, !7, i64 16}


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