; LLVM IR from sunkafei/xcpc-algorithm-templates :: 算法/字符串算法/LCT维护隐式后缀树.ll (Z5splayi)

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

@fa = external dso_local global [210000 x i32], align 16
@stk = external dso_local global [210000 x i32], align 16

; 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: mustprogress uwtable
declare dso_local void @_Z6rotatei(i32 noundef) #1

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5splayi(i32 noundef %0) #1 {
  %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) #3
  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 [210000 x i32], ptr @stk, i64 0, i64 %9
  store i32 %6, ptr %10, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %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 @_Z6isrooti(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) #3
  br label %31

17:                                               ; preds = %12
  %18 = load i32, ptr %4, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [210000 x i32], ptr @fa, 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 [210000 x i32], ptr @stk, 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 [210000 x i32], ptr @fa, 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 [210000 x i32], ptr @stk, i64 0, i64 %38
  %40 = load i32, ptr %39, align 4, !tbaa !5
  call void @_Z8pushdowni(i32 noundef %40)
  br label %32, !llvm.loop !11

41:                                               ; preds = %32
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %42 = load i32, ptr %2, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [210000 x i32], ptr @fa, 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 @_Z6isrooti(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) #3
  br label %75

51:                                               ; preds = %46
  %52 = load i32, ptr %5, align 4, !tbaa !5
  %53 = call noundef zeroext i1 @_Z6isrooti(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 @_Z3soni(i32 noundef %55)
  %57 = zext i1 %56 to i32
  %58 = load i32, ptr %5, align 4, !tbaa !5
  %59 = call noundef zeroext i1 @_Z3soni(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 @_Z6rotatei(i32 noundef %64)
  br label %67

65:                                               ; preds = %54
  %66 = load i32, ptr %5, align 4, !tbaa !5
  call void @_Z6rotatei(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 @_Z6rotatei(i32 noundef %70)
  %71 = load i32, ptr %2, align 4, !tbaa !5
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds [210000 x i32], ptr @fa, 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
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  ret void
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { 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"

@fa = external dso_local local_unnamed_addr global [210000 x i32], align 16
@stk = external dso_local local_unnamed_addr global [210000 x i32], align 16

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

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

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

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

.preheader.preheader:                             ; preds = %.preheader.loopexit, %1
  %indvars.iv27.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 ]
  %.01821 = phi i32 [ %6, %.lr.ph ], [ %0, %1 ]
  %4 = sext i32 %.01821 to i64
  %5 = getelementptr inbounds [210000 x i32], ptr @fa, 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 [210000 x i32], ptr @stk, i64 0, i64 %indvars.iv.next
  store i32 %6, ptr %7, align 4, !tbaa !5
  %8 = tail call noundef zeroext i1 @_Z6isrooti(i32 noundef %6)
  br i1 %8, label %.preheader.loopexit, label %.lr.ph, !llvm.loop !9

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

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

._crit_edge:                                      ; preds = %20, %12
  ret void

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

.sink.split:                                      ; preds = %.lr.ph25
  %17 = tail call noundef zeroext i1 @_Z3soni(i32 noundef %0)
  %18 = tail call noundef zeroext i1 @_Z3soni(i32 noundef %.024)
  %19 = xor i1 %17, %18
  %..024 = select i1 %19, i32 %0, i32 %.024
  tail call void @_Z6rotatei(i32 noundef %..024)
  br label %20

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

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

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"}
!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