; LLVM IR from sunkafei/xcpc-algorithm-templates :: 算法/数据结构/SplayTree.ll (ZN10splay_tree5splayEii)

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

@_ZN10splay_tree2chE = external dso_local global [110000 x [2 x i32]], align 16
@_ZN10splay_tree2szE = external dso_local global [110000 x i32], align 16

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN10splay_tree6ascendEi(i32 noundef) #0

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN10splay_tree8pushdownEi(i32 noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN10splay_tree5splayEii(i32 noundef %0, i32 noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  br label %5

5:                                                ; preds = %52, %2
  %6 = load i32, ptr %3, align 4, !tbaa !5
  call void @_ZN10splay_tree8pushdownEi(i32 noundef %6)
  %7 = load i32, ptr %4, align 4, !tbaa !5
  %8 = load i32, ptr %3, align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds [110000 x [2 x i32]], ptr @_ZN10splay_tree2chE, i64 0, i64 %9
  %11 = getelementptr inbounds [2 x i32], ptr %10, i64 0, i64 0
  %12 = load i32, ptr %11, align 8, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [110000 x i32], ptr @_ZN10splay_tree2szE, i64 0, i64 %13
  %15 = load i32, ptr %14, align 4, !tbaa !5
  %16 = add nsw i32 %15, 1
  %17 = icmp ne i32 %7, %16
  br i1 %17, label %18, label %53

18:                                               ; preds = %5
  %19 = load i32, ptr %4, align 4, !tbaa !5
  %20 = load i32, ptr %3, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [110000 x [2 x i32]], ptr @_ZN10splay_tree2chE, i64 0, i64 %21
  %23 = getelementptr inbounds [2 x i32], ptr %22, i64 0, i64 0
  %24 = load i32, ptr %23, align 8, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [110000 x i32], ptr @_ZN10splay_tree2szE, i64 0, i64 %25
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %28 = icmp sle i32 %19, %27
  br i1 %28, label %29, label %35

29:                                               ; preds = %18
  %30 = load i32, ptr %3, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [110000 x [2 x i32]], ptr @_ZN10splay_tree2chE, i64 0, i64 %31
  %33 = getelementptr inbounds [2 x i32], ptr %32, i64 0, i64 0
  %34 = load i32, ptr %33, align 8, !tbaa !5
  store i32 %34, ptr %3, align 4, !tbaa !5
  br label %52

35:                                               ; preds = %18
  %36 = load i32, ptr %3, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [110000 x [2 x i32]], ptr @_ZN10splay_tree2chE, i64 0, i64 %37
  %39 = getelementptr inbounds [2 x i32], ptr %38, i64 0, i64 0
  %40 = load i32, ptr %39, align 8, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [110000 x i32], ptr @_ZN10splay_tree2szE, i64 0, i64 %41
  %43 = load i32, ptr %42, align 4, !tbaa !5
  %44 = add nsw i32 %43, 1
  %45 = load i32, ptr %4, align 4, !tbaa !5
  %46 = sub nsw i32 %45, %44
  store i32 %46, ptr %4, align 4, !tbaa !5
  %47 = load i32, ptr %3, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [110000 x [2 x i32]], ptr @_ZN10splay_tree2chE, i64 0, i64 %48
  %50 = getelementptr inbounds [2 x i32], ptr %49, i64 0, i64 1
  %51 = load i32, ptr %50, align 4, !tbaa !5
  store i32 %51, ptr %3, align 4, !tbaa !5
  br label %52

52:                                               ; preds = %35, %29
  br label %5, !llvm.loop !9

53:                                               ; preds = %5
  %54 = load i32, ptr %3, align 4, !tbaa !5
  %55 = icmp ne i32 %54, 0
  br i1 %55, label %56, label %58

56:                                               ; preds = %53
  %57 = load i32, ptr %3, align 4, !tbaa !5
  call void @_ZN10splay_tree6ascendEi(i32 noundef %57)
  br label %58

58:                                               ; preds = %56, %53
  %59 = load i32, ptr %3, align 4, !tbaa !5
  ret i32 %59
}

attributes #0 = { mustprogress 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 = { inlinehint mustprogress 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" }

!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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"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"

@_ZN10splay_tree2chE = external dso_local local_unnamed_addr global [110000 x [2 x i32]], align 16
@_ZN10splay_tree2szE = external dso_local local_unnamed_addr global [110000 x i32], align 16

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN10splay_tree6ascendEi(i32 noundef) local_unnamed_addr #0

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN10splay_tree8pushdownEi(i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN10splay_tree5splayEii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  tail call void @_ZN10splay_tree8pushdownEi(i32 noundef %0)
  %3 = sext i32 %0 to i64
  %4 = getelementptr inbounds [110000 x [2 x i32]], ptr @_ZN10splay_tree2chE, i64 0, i64 %3
  %5 = load i32, ptr %4, align 8, !tbaa !5
  %6 = sext i32 %5 to i64
  %7 = getelementptr inbounds [110000 x i32], ptr @_ZN10splay_tree2szE, i64 0, i64 %6
  %8 = load i32, ptr %7, align 4, !tbaa !5
  %9 = add nsw i32 %8, 1
  %.not17 = icmp eq i32 %9, %1
  br i1 %.not17, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2, %18
  %10 = phi i32 [ %25, %18 ], [ %9, %2 ]
  %11 = phi i32 [ %24, %18 ], [ %8, %2 ]
  %12 = phi i32 [ %21, %18 ], [ %5, %2 ]
  %13 = phi i64 [ %19, %18 ], [ %3, %2 ]
  %.018 = phi i32 [ %.1, %18 ], [ %1, %2 ]
  %.not16 = icmp sgt i32 %.018, %11
  br i1 %.not16, label %14, label %18

14:                                               ; preds = %.lr.ph
  %15 = sub nsw i32 %.018, %10
  %16 = getelementptr inbounds [110000 x [2 x i32]], ptr @_ZN10splay_tree2chE, i64 0, i64 %13, i64 1
  %17 = load i32, ptr %16, align 4, !tbaa !5
  br label %18

18:                                               ; preds = %.lr.ph, %14
  %.113 = phi i32 [ %17, %14 ], [ %12, %.lr.ph ]
  %.1 = phi i32 [ %15, %14 ], [ %.018, %.lr.ph ]
  tail call void @_ZN10splay_tree8pushdownEi(i32 noundef %.113)
  %19 = sext i32 %.113 to i64
  %20 = getelementptr inbounds [110000 x [2 x i32]], ptr @_ZN10splay_tree2chE, i64 0, i64 %19
  %21 = load i32, ptr %20, align 8, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [110000 x i32], ptr @_ZN10splay_tree2szE, i64 0, i64 %22
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %25 = add nsw i32 %24, 1
  %.not = icmp eq i32 %.1, %25
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !9

._crit_edge:                                      ; preds = %18, %2
  %.012.lcssa = phi i32 [ %0, %2 ], [ %.113, %18 ]
  %.not15 = icmp eq i32 %.012.lcssa, 0
  br i1 %.not15, label %27, label %26

26:                                               ; preds = %._crit_edge
  tail call void @_ZN10splay_tree6ascendEi(i32 noundef %.012.lcssa)
  br label %27

27:                                               ; preds = %26, %._crit_edge
  ret i32 %.012.lcssa
}

attributes #0 = { mustprogress 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 = { inlinehint mustprogress 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" }

!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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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