; 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 }
%struct.ax_splay = type { ptr, ptr, i32 }

; Function Attrs: nounwind uwtable
declare dso_local void @ax_splay_splay(ptr 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 void @ax_splay_remove(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %6 = load ptr, ptr %4, align 8, !tbaa !5
  %7 = icmp ne ptr %6, null
  br i1 %7, label %9, label %8

8:                                                ; preds = %2
  br label %117

9:                                                ; preds = %2
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  call void @ax_splay_splay(ptr noundef %10, ptr noundef %11)
  %12 = load ptr, ptr %4, 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 !9
  %15 = icmp ne ptr %14, null
  br i1 %15, label %32, label %16

16:                                               ; preds = %9
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.ax_splay_node_st, ptr %17, i32 0, i32 2
  %19 = load ptr, ptr %18, align 8, !tbaa !11
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.ax_splay, ptr %20, i32 0, i32 0
  store ptr %19, ptr %21, align 8, !tbaa !12
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.ax_splay, ptr %22, i32 0, i32 0
  %24 = load ptr, ptr %23, align 8, !tbaa !12
  %25 = icmp ne ptr %24, null
  br i1 %25, label %26, label %31

26:                                               ; preds = %16
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.ax_splay, ptr %27, i32 0, i32 0
  %29 = load ptr, ptr %28, align 8, !tbaa !12
  %30 = getelementptr inbounds %struct.ax_splay_node_st, ptr %29, i32 0, i32 0
  store ptr null, ptr %30, align 8, !tbaa !15
  br label %31

31:                                               ; preds = %26, %16
  br label %105

32:                                               ; preds = %9
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.ax_splay_node_st, ptr %33, i32 0, i32 2
  %35 = load ptr, ptr %34, align 8, !tbaa !11
  %36 = icmp ne ptr %35, null
  br i1 %36, label %47, label %37

37:                                               ; preds = %32
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.ax_splay_node_st, ptr %38, i32 0, i32 1
  %40 = load ptr, ptr %39, align 8, !tbaa !9
  %41 = load ptr, ptr %3, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.ax_splay, ptr %41, i32 0, i32 0
  store ptr %40, ptr %42, align 8, !tbaa !12
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.ax_splay, ptr %43, i32 0, i32 0
  %45 = load ptr, ptr %44, align 8, !tbaa !12
  %46 = getelementptr inbounds %struct.ax_splay_node_st, ptr %45, i32 0, i32 0
  store ptr null, ptr %46, align 8, !tbaa !15
  br label %104

47:                                               ; preds = %32
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.ax_splay_node_st, ptr %48, i32 0, i32 2
  %50 = load ptr, ptr %49, align 8, !tbaa !11
  %51 = call ptr @leftmost(ptr noundef %50)
  store ptr %51, ptr %5, align 8, !tbaa !5
  %52 = load ptr, ptr %5, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.ax_splay_node_st, ptr %52, i32 0, i32 0
  %54 = load ptr, ptr %53, align 8, !tbaa !15
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  %56 = icmp ne ptr %54, %55
  br i1 %56, label %57, label %88

57:                                               ; preds = %47
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.ax_splay_node_st, ptr %58, i32 0, i32 2
  %60 = load ptr, ptr %59, align 8, !tbaa !11
  %61 = load ptr, ptr %5, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.ax_splay_node_st, ptr %61, i32 0, i32 0
  %63 = load ptr, ptr %62, align 8, !tbaa !15
  %64 = getelementptr inbounds %struct.ax_splay_node_st, ptr %63, i32 0, i32 1
  store ptr %60, ptr %64, align 8, !tbaa !9
  %65 = load ptr, ptr %5, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.ax_splay_node_st, ptr %65, i32 0, i32 2
  %67 = load ptr, ptr %66, align 8, !tbaa !11
  %68 = icmp ne ptr %67, null
  br i1 %68, label %69, label %77

69:                                               ; preds = %57
  %70 = load ptr, ptr %5, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.ax_splay_node_st, ptr %70, i32 0, i32 0
  %72 = load ptr, ptr %71, align 8, !tbaa !15
  %73 = load ptr, ptr %5, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.ax_splay_node_st, ptr %73, i32 0, i32 2
  %75 = load ptr, ptr %74, align 8, !tbaa !11
  %76 = getelementptr inbounds %struct.ax_splay_node_st, ptr %75, i32 0, i32 0
  store ptr %72, ptr %76, align 8, !tbaa !15
  br label %77

77:                                               ; preds = %69, %57
  %78 = load ptr, ptr %4, 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 !11
  %81 = load ptr, ptr %5, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.ax_splay_node_st, ptr %81, i32 0, i32 2
  store ptr %80, ptr %82, align 8, !tbaa !11
  %83 = load ptr, ptr %5, align 8, !tbaa !5
  %84 = load ptr, ptr %5, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.ax_splay_node_st, ptr %84, i32 0, i32 2
  %86 = load ptr, ptr %85, align 8, !tbaa !11
  %87 = getelementptr inbounds %struct.ax_splay_node_st, ptr %86, i32 0, i32 0
  store ptr %83, ptr %87, align 8, !tbaa !15
  br label %88

88:                                               ; preds = %77, %47
  %89 = load ptr, ptr %5, align 8, !tbaa !5
  %90 = load ptr, ptr %3, align 8, !tbaa !5
  %91 = getelementptr inbounds %struct.ax_splay, ptr %90, i32 0, i32 0
  store ptr %89, ptr %91, align 8, !tbaa !12
  %92 = load ptr, ptr %5, align 8, !tbaa !5
  %93 = getelementptr inbounds %struct.ax_splay_node_st, ptr %92, i32 0, i32 0
  store ptr null, ptr %93, align 8, !tbaa !15
  %94 = load ptr, ptr %4, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.ax_splay_node_st, ptr %94, i32 0, i32 1
  %96 = load ptr, ptr %95, align 8, !tbaa !9
  %97 = load ptr, ptr %5, align 8, !tbaa !5
  %98 = getelementptr inbounds %struct.ax_splay_node_st, ptr %97, i32 0, i32 1
  store ptr %96, ptr %98, align 8, !tbaa !9
  %99 = load ptr, ptr %5, align 8, !tbaa !5
  %100 = load ptr, ptr %5, align 8, !tbaa !5
  %101 = getelementptr inbounds %struct.ax_splay_node_st, ptr %100, i32 0, i32 1
  %102 = load ptr, ptr %101, align 8, !tbaa !9
  %103 = getelementptr inbounds %struct.ax_splay_node_st, ptr %102, i32 0, i32 0
  store ptr %99, ptr %103, align 8, !tbaa !15
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  br label %104

104:                                              ; preds = %88, %37
  br label %105

105:                                              ; preds = %104, %31
  %106 = load ptr, ptr %4, align 8, !tbaa !5
  %107 = getelementptr inbounds %struct.ax_splay_node_st, ptr %106, i32 0, i32 0
  store ptr null, ptr %107, align 8, !tbaa !15
  %108 = load ptr, ptr %4, align 8, !tbaa !5
  %109 = getelementptr inbounds %struct.ax_splay_node_st, ptr %108, i32 0, i32 2
  store ptr null, ptr %109, align 8, !tbaa !11
  %110 = load ptr, ptr %4, align 8, !tbaa !5
  %111 = getelementptr inbounds %struct.ax_splay_node_st, ptr %110, i32 0, i32 1
  store ptr null, ptr %111, align 8, !tbaa !9
  %112 = load ptr, ptr %3, align 8, !tbaa !5
  %113 = getelementptr inbounds %struct.ax_splay, ptr %112, i32 0, i32 2
  %114 = load i32, ptr %113, align 8, !tbaa !16
  %115 = add nsw i32 %114, -1
  store i32 %115, ptr %113, align 8, !tbaa !16
  %116 = load ptr, ptr %3, align 8, !tbaa !5
  call void @check_sanity(ptr noundef %116)
  br label %117

117:                                              ; preds = %105, %8
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden ptr @leftmost(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare hidden void @check_sanity(ptr noundef) #0

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 8}
!10 = !{!"ax_splay_node_st", !6, i64 0, !6, i64 8, !6, i64 16}
!11 = !{!10, !6, i64 16}
!12 = !{!13, !6, i64 0}
!13 = !{!"ax_splay", !6, i64 0, !6, i64 8, !14, i64 16}
!14 = !{!"int", !7, i64 0}
!15 = !{!10, !6, i64 0}
!16 = !{!13, !14, 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"

; Function Attrs: nounwind uwtable
declare dso_local void @ax_splay_splay(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @ax_splay_remove(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %.not = icmp eq ptr %1, null
  br i1 %.not, label %29, label %3

3:                                                ; preds = %2
  tail call void @ax_splay_splay(ptr noundef %0, ptr noundef nonnull %1)
  %4 = getelementptr inbounds i8, ptr %1, i64 8
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %.not41 = icmp eq ptr %5, null
  %6 = getelementptr inbounds i8, ptr %1, i64 16
  %7 = load ptr, ptr %6, align 8, !tbaa !10
  br i1 %.not41, label %8, label %10

8:                                                ; preds = %3
  store ptr %7, ptr %0, align 8, !tbaa !11
  %.not42 = icmp eq ptr %7, null
  br i1 %.not42, label %25, label %9

9:                                                ; preds = %8
  store ptr null, ptr %7, align 8, !tbaa !14
  br label %25

10:                                               ; preds = %3
  %.not43 = icmp eq ptr %7, null
  br i1 %.not43, label %11, label %12

11:                                               ; preds = %10
  store ptr %5, ptr %0, align 8, !tbaa !11
  store ptr null, ptr %5, align 8, !tbaa !14
  br label %25

12:                                               ; preds = %10
  %13 = tail call ptr @leftmost(ptr noundef nonnull %7)
  %14 = load ptr, ptr %13, align 8, !tbaa !14
  %.not44 = icmp eq ptr %14, %1
  br i1 %.not44, label %22, label %15

15:                                               ; preds = %12
  %16 = getelementptr inbounds i8, ptr %13, i64 16
  %17 = load ptr, ptr %16, align 8, !tbaa !10
  %18 = getelementptr inbounds i8, ptr %14, i64 8
  store ptr %17, ptr %18, align 8, !tbaa !5
  %.not45 = icmp eq ptr %17, null
  br i1 %.not45, label %20, label %19

19:                                               ; preds = %15
  store ptr %14, ptr %17, align 8, !tbaa !14
  br label %20

20:                                               ; preds = %19, %15
  %21 = load ptr, ptr %6, align 8, !tbaa !10
  store ptr %21, ptr %16, align 8, !tbaa !10
  store ptr %13, ptr %21, align 8, !tbaa !14
  br label %22

22:                                               ; preds = %20, %12
  store ptr %13, ptr %0, align 8, !tbaa !11
  store ptr null, ptr %13, align 8, !tbaa !14
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = getelementptr inbounds i8, ptr %13, i64 8
  store ptr %23, ptr %24, align 8, !tbaa !5
  store ptr %13, ptr %23, align 8, !tbaa !14
  br label %25

25:                                               ; preds = %11, %22, %8, %9
  %26 = getelementptr inbounds i8, ptr %0, i64 16
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %1, i8 0, i64 24, i1 false)
  %27 = load i32, ptr %26, align 8, !tbaa !15
  %28 = add nsw i32 %27, -1
  store i32 %28, ptr %26, align 8, !tbaa !15
  tail call void @check_sanity(ptr noundef nonnull %0)
  br label %29

29:                                               ; preds = %2, %25
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden ptr @leftmost(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden void @check_sanity(ptr noundef) local_unnamed_addr #0

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #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 = { nocallback nofree nounwind willreturn memory(argmem: write) }

!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 16}
!11 = !{!12, !7, i64 0}
!12 = !{!"ax_splay", !7, i64 0, !7, i64 8, !13, i64 16}
!13 = !{!"int", !8, i64 0}
!14 = !{!6, !7, i64 0}
!15 = !{!12, !13, i64 16}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,MemCpyOptPass,SROAPass,SimplifyCFGPass,TailCallElimPass