; LLVM IR from sunkafei/xcpc-algorithm-templates :: 算法/数据结构/link-cut-tree.ll (ZN3lct5splayEi)

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

@_ZN3lct2faE = external dso_local global [110000 x i32], align 16
@_ZN3lct3stkE = external dso_local global [110000 x i32], align 16

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3lct6rotateEi(i32 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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN3lct3sonEi(i32 noundef) #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN3lct6isrootEi(i32 noundef) #2

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN3lct5splayEi(i32 noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 0, ptr %3, align 4, !tbaa !5
  %6 = load i32, ptr %2, align 4, !tbaa !5
  %7 = load i32, ptr %3, align 4, !tbaa !5
  %8 = add nsw i32 %7, 1
  store i32 %8, ptr %3, align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds [110000 x i32], ptr @_ZN3lct3stkE, i64 0, i64 %9
  store i32 %6, ptr %10, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  %11 = load i32, ptr %2, align 4, !tbaa !5
  store i32 %11, ptr %4, align 4, !tbaa !5
  br label %12

12:                                               ; preds = %26, %1
  %13 = load i32, ptr %4, align 4, !tbaa !5
  %14 = call noundef zeroext i1 @_ZN3lct6isrootEi(i32 noundef %13)
  %15 = xor i1 %14, true
  br i1 %15, label %17, label %16

16:                                               ; preds = %12
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  br label %31

17:                                               ; preds = %12
  %18 = load i32, ptr %4, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [110000 x i32], ptr @_ZN3lct2faE, i64 0, i64 %19
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = load i32, ptr %3, align 4, !tbaa !5
  %23 = add nsw i32 %22, 1
  store i32 %23, ptr %3, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [110000 x i32], ptr @_ZN3lct3stkE, i64 0, i64 %24
  store i32 %21, ptr %25, align 4, !tbaa !5
  br label %26

26:                                               ; preds = %17
  %27 = load i32, ptr %4, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [110000 x i32], ptr @_ZN3lct2faE, i64 0, i64 %28
  %30 = load i32, ptr %29, align 4, !tbaa !5
  store i32 %30, ptr %4, align 4, !tbaa !5
  br label %12, !llvm.loop !9

31:                                               ; preds = %16
  br label %32

32:                                               ; preds = %35, %31
  %33 = load i32, ptr %3, align 4, !tbaa !5
  %34 = icmp ne i32 %33, 0
  br i1 %34, label %35, label %41

35:                                               ; preds = %32
  %36 = load i32, ptr %3, align 4, !tbaa !5
  %37 = add nsw i32 %36, -1
  store i32 %37, ptr %3, align 4, !tbaa !5
  %38 = sext i32 %36 to i64
  %39 = getelementptr inbounds [110000 x i32], ptr @_ZN3lct3stkE, i64 0, i64 %38
  %40 = load i32, ptr %39, align 4, !tbaa !5
  call void @_ZN3lct8pushdownEi(i32 noundef %40)
  br label %32, !llvm.loop !11

41:                                               ; preds = %32
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %42 = load i32, ptr %2, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [110000 x i32], ptr @_ZN3lct2faE, i64 0, i64 %43
  %45 = load i32, ptr %44, align 4, !tbaa !5
  store i32 %45, ptr %5, align 4, !tbaa !5
  br label %46

46:                                               ; preds = %69, %41
  %47 = load i32, ptr %2, align 4, !tbaa !5
  %48 = call noundef zeroext i1 @_ZN3lct6isrootEi(i32 noundef %47)
  %49 = xor i1 %48, true
  br i1 %49, label %51, label %50

50:                                               ; preds = %46
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %75

51:                                               ; preds = %46
  %52 = load i32, ptr %5, align 4, !tbaa !5
  %53 = call noundef zeroext i1 @_ZN3lct6isrootEi(i32 noundef %52)
  br i1 %53, label %68, label %54

54:                                               ; preds = %51
  %55 = load i32, ptr %2, align 4, !tbaa !5
  %56 = call noundef zeroext i1 @_ZN3lct3sonEi(i32 noundef %55)
  %57 = zext i1 %56 to i32
  %58 = load i32, ptr %5, align 4, !tbaa !5
  %59 = call noundef zeroext i1 @_ZN3lct3sonEi(i32 noundef %58)
  %60 = zext i1 %59 to i32
  %61 = xor i32 %57, %60
  %62 = icmp ne i32 %61, 0
  br i1 %62, label %63, label %65

63:                                               ; preds = %54
  %64 = load i32, ptr %2, align 4, !tbaa !5
  call void @_ZN3lct6rotateEi(i32 noundef %64)
  br label %67

65:                                               ; preds = %54
  %66 = load i32, ptr %5, align 4, !tbaa !5
  call void @_ZN3lct6rotateEi(i32 noundef %66)
  br label %67

67:                                               ; preds = %65, %63
  br label %68

68:                                               ; preds = %67, %51
  br label %69

69:                                               ; preds = %68
  %70 = load i32, ptr %2, align 4, !tbaa !5
  call void @_ZN3lct6rotateEi(i32 noundef %70)
  %71 = load i32, ptr %2, align 4, !tbaa !5
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds [110000 x i32], ptr @_ZN3lct2faE, i64 0, i64 %72
  %74 = load i32, ptr %73, align 4, !tbaa !5
  store i32 %74, ptr %5, align 4, !tbaa !5
  br label %46, !llvm.loop !12

75:                                               ; preds = %50
  %76 = load i32, ptr %2, align 4, !tbaa !5
  call void @_ZN3lct6pushupEi(i32 noundef %76)
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  ret void
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN3lct8pushdownEi(i32 noundef) #3

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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" }
attributes #3 = { inlinehint 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 #4 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}


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

@_ZN3lct2faE = external dso_local local_unnamed_addr global [110000 x i32], align 16
@_ZN3lct3stkE = external dso_local local_unnamed_addr global [110000 x i32], align 16

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN3lct3sonEi(i32 noundef) local_unnamed_addr #1

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN3lct6isrootEi(i32 noundef) local_unnamed_addr #1

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN3lct5splayEi(i32 noundef %0) local_unnamed_addr #0 {
  store i32 %0, ptr getelementptr inbounds (i8, ptr @_ZN3lct3stkE, i64 4), align 4, !tbaa !5
  %2 = tail call noundef zeroext i1 @_ZN3lct6isrootEi(i32 noundef %0)
  br i1 %2, label %.preheader.preheader, label %.lr.ph

.preheader.preheader:                             ; preds = %.preheader.loopexit, %1
  %indvars.iv28.ph = phi i64 [ %3, %.preheader.loopexit ], [ 1, %1 ]
  br label %.preheader

.preheader.loopexit:                              ; preds = %.lr.ph
  %3 = and i64 %indvars.iv.next, 4294967295
  br label %.preheader.preheader

.lr.ph:                                           ; preds = %1, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 1, %1 ]
  %.01922 = phi i32 [ %6, %.lr.ph ], [ %0, %1 ]
  %4 = sext i32 %.01922 to i64
  %5 = getelementptr inbounds [110000 x i32], ptr @_ZN3lct2faE, i64 0, i64 %4
  %6 = load i32, ptr %5, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %7 = getelementptr inbounds [110000 x i32], ptr @_ZN3lct3stkE, i64 0, i64 %indvars.iv.next
  store i32 %6, ptr %7, align 4, !tbaa !5
  %8 = tail call noundef zeroext i1 @_ZN3lct6isrootEi(i32 noundef %6)
  br i1 %8, label %.preheader.loopexit, label %.lr.ph, !llvm.loop !9

.preheader:                                       ; preds = %.preheader.preheader, %.preheader
  %indvars.iv28 = phi i64 [ %indvars.iv.next29, %.preheader ], [ %indvars.iv28.ph, %.preheader.preheader ]
  %indvars.iv.next29 = add nsw i64 %indvars.iv28, -1
  %9 = getelementptr inbounds [110000 x i32], ptr @_ZN3lct3stkE, i64 0, i64 %indvars.iv28
  %10 = load i32, ptr %9, align 4, !tbaa !5
  tail call void @_ZN3lct8pushdownEi(i32 noundef %10)
  %11 = icmp eq i64 %indvars.iv.next29, 0
  br i1 %11, label %12, label %.preheader, !llvm.loop !11

12:                                               ; preds = %.preheader
  %13 = sext i32 %0 to i64
  %14 = getelementptr inbounds [110000 x i32], ptr @_ZN3lct2faE, i64 0, i64 %13
  %.024 = load i32, ptr %14, align 4, !tbaa !5
  %15 = tail call noundef zeroext i1 @_ZN3lct6isrootEi(i32 noundef %0)
  br i1 %15, label %._crit_edge, label %.lr.ph26

._crit_edge:                                      ; preds = %20, %12
  tail call void @_ZN3lct6pushupEi(i32 noundef %0)
  ret void

.lr.ph26:                                         ; preds = %12, %20
  %.025 = phi i32 [ %.0, %20 ], [ %.024, %12 ]
  %16 = tail call noundef zeroext i1 @_ZN3lct6isrootEi(i32 noundef %.025)
  br i1 %16, label %20, label %.sink.split

.sink.split:                                      ; preds = %.lr.ph26
  %17 = tail call noundef zeroext i1 @_ZN3lct3sonEi(i32 noundef %0)
  %18 = tail call noundef zeroext i1 @_ZN3lct3sonEi(i32 noundef %.025)
  %19 = xor i1 %17, %18
  %..025 = select i1 %19, i32 %0, i32 %.025
  tail call void @_ZN3lct6rotateEi(i32 noundef %..025)
  br label %20

20:                                               ; preds = %.sink.split, %.lr.ph26
  tail call void @_ZN3lct6rotateEi(i32 noundef %0)
  %.0 = load i32, ptr %14, align 4, !tbaa !5
  %21 = tail call noundef zeroext i1 @_ZN3lct6isrootEi(i32 noundef %0)
  br i1 %21, label %._crit_edge, label %.lr.ph26, !llvm.loop !12
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN3lct8pushdownEi(i32 noundef) local_unnamed_addr #2

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

!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"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}


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