; LLVM IR from sunkafei/xcpc-algorithm-templates :: 算法/字符串算法/基于后缀自动机构建后缀树.ll (Z5buildPKc)

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

@par = external dso_local global [2010000 x i32], align 16
@len = external dso_local global [2010000 x i32], align 16
@cur = external dso_local global i32, align 4
@ch = external dso_local global [2010000 x [26 x i32]], align 16
@pos = external dso_local global [2010000 x i32], align 16

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #0

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

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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z5buildPKc(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  %8 = call i64 @strlen(ptr noundef %7) #5
  %9 = trunc i64 %8 to i32
  store i32 %9, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  %10 = load i32, ptr %3, align 4, !tbaa !9
  %11 = sub nsw i32 %10, 1
  store i32 %11, ptr %4, align 4, !tbaa !9
  br label %12

12:                                               ; preds = %25, %1
  %13 = load i32, ptr %4, align 4, !tbaa !9
  %14 = icmp sge i32 %13, 0
  br i1 %14, label %16, label %15

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

16:                                               ; preds = %12
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  %18 = load i32, ptr %4, align 4, !tbaa !9
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds i8, ptr %17, i64 %19
  %21 = load i8, ptr %20, align 1, !tbaa !11
  %22 = sext i8 %21 to i32
  %23 = sub nsw i32 %22, 97
  %24 = load i32, ptr %4, align 4, !tbaa !9
  call void @_Z6extendii(i32 noundef %23, i32 noundef %24)
  br label %25

25:                                               ; preds = %16
  %26 = load i32, ptr %4, align 4, !tbaa !9
  %27 = add nsw i32 %26, -1
  store i32 %27, ptr %4, align 4, !tbaa !9
  br label %12, !llvm.loop !12

28:                                               ; preds = %15
  %29 = load i32, ptr @cur, align 4, !tbaa !9
  %30 = add nsw i32 %29, 10
  %31 = sext i32 %30 to i64
  %32 = mul i64 104, %31
  call void @llvm.memset.p0.i64(ptr align 16 @ch, i8 0, i64 %32, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 2, ptr %5, align 4, !tbaa !9
  br label %33

33:                                               ; preds = %67, %28
  %34 = load i32, ptr %5, align 4, !tbaa !9
  %35 = load i32, ptr @cur, align 4, !tbaa !9
  %36 = icmp slt i32 %34, %35
  br i1 %36, label %38, label %37

37:                                               ; preds = %33
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %70

38:                                               ; preds = %33
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %39 = load ptr, ptr %2, align 8, !tbaa !5
  %40 = load i32, ptr %5, align 4, !tbaa !9
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [2010000 x i32], ptr @pos, i64 0, i64 %41
  %43 = load i32, ptr %42, align 4, !tbaa !9
  %44 = load i32, ptr %5, align 4, !tbaa !9
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [2010000 x i32], ptr @par, i64 0, i64 %45
  %47 = load i32, ptr %46, align 4, !tbaa !9
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [2010000 x i32], ptr @len, i64 0, i64 %48
  %50 = load i32, ptr %49, align 4, !tbaa !9
  %51 = add nsw i32 %43, %50
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds i8, ptr %39, i64 %52
  %54 = load i8, ptr %53, align 1, !tbaa !11
  %55 = sext i8 %54 to i32
  %56 = sub nsw i32 %55, 97
  store i32 %56, ptr %6, align 4, !tbaa !9
  %57 = load i32, ptr %5, align 4, !tbaa !9
  %58 = load i32, ptr %5, align 4, !tbaa !9
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [2010000 x i32], ptr @par, i64 0, i64 %59
  %61 = load i32, ptr %60, align 4, !tbaa !9
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [2010000 x [26 x i32]], ptr @ch, i64 0, i64 %62
  %64 = load i32, ptr %6, align 4, !tbaa !9
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds [26 x i32], ptr %63, i64 0, i64 %65
  store i32 %57, ptr %66, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %67

67:                                               ; preds = %38
  %68 = load i32, ptr %5, align 4, !tbaa !9
  %69 = add nsw i32 %68, 1
  store i32 %69, ptr %5, align 4, !tbaa !9
  br label %33, !llvm.loop !14

70:                                               ; preds = %37
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  ret void
}

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #3

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

!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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}


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

@par = external dso_local local_unnamed_addr global [2010000 x i32], align 16
@len = external dso_local local_unnamed_addr global [2010000 x i32], align 16
@cur = external dso_local local_unnamed_addr global i32, align 4
@ch = external dso_local local_unnamed_addr global [2010000 x [26 x i32]], align 16
@pos = external dso_local local_unnamed_addr global [2010000 x i32], align 16

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #0

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z5buildPKc(ptr nocapture noundef readonly %0) local_unnamed_addr #1 {
  %2 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %0) #3
  %3 = trunc i64 %2 to i32
  %4 = icmp sgt i32 %3, 0
  br i1 %4, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %1
  %5 = and i64 %2, 2147483647
  br label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %1
  %6 = load i32, ptr @cur, align 4, !tbaa !5
  %7 = add nsw i32 %6, 10
  %8 = sext i32 %7 to i64
  %9 = mul nsw i64 %8, 104
  tail call void @llvm.memset.p0.i64(ptr nonnull align 16 @ch, i8 0, i64 %9, i1 false)
  %10 = icmp sgt i32 %6, 2
  br i1 %10, label %.lr.ph18.preheader, label %._crit_edge19

.lr.ph18.preheader:                               ; preds = %._crit_edge
  %wide.trip.count = zext nneg i32 %6 to i64
  %xtraiter = and i64 %wide.trip.count, 1
  %11 = icmp eq i32 %6, 3
  br i1 %11, label %._crit_edge19.loopexit.unr-lcssa, label %.lr.ph18.preheader.new

.lr.ph18.preheader.new:                           ; preds = %.lr.ph18.preheader
  %12 = and i64 %wide.trip.count, 2147483646
  %13 = add nsw i64 %12, -4
  br label %.lr.ph18

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ %5, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  %14 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv.next
  %15 = load i8, ptr %14, align 1, !tbaa !9
  %16 = sext i8 %15 to i32
  %17 = add nsw i32 %16, -97
  %18 = trunc nuw nsw i64 %indvars.iv.next to i32
  tail call void @_Z6extendii(i32 noundef %17, i32 noundef %18)
  %19 = icmp ugt i64 %indvars.iv, 1
  br i1 %19, label %.lr.ph, label %._crit_edge, !llvm.loop !10

._crit_edge19.loopexit.unr-lcssa:                 ; preds = %.lr.ph18, %.lr.ph18.preheader
  %indvars.iv21.unr = phi i64 [ 2, %.lr.ph18.preheader ], [ %indvars.iv.next22.1, %.lr.ph18 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge19, label %.lr.ph18.epil

.lr.ph18.epil:                                    ; preds = %._crit_edge19.loopexit.unr-lcssa
  %20 = getelementptr inbounds [2010000 x i32], ptr @pos, i64 0, i64 %indvars.iv21.unr
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = getelementptr inbounds [2010000 x i32], ptr @par, i64 0, i64 %indvars.iv21.unr
  %23 = load i32, ptr %22, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [2010000 x i32], ptr @len, i64 0, i64 %24
  %26 = load i32, ptr %25, align 4, !tbaa !5
  %27 = add nsw i32 %26, %21
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds i8, ptr %0, i64 %28
  %30 = load i8, ptr %29, align 1, !tbaa !9
  %31 = sext i8 %30 to i64
  %32 = add nsw i64 %31, -97
  %33 = getelementptr inbounds [2010000 x [26 x i32]], ptr @ch, i64 0, i64 %24, i64 %32
  %34 = trunc nuw nsw i64 %indvars.iv21.unr to i32
  store i32 %34, ptr %33, align 4, !tbaa !5
  br label %._crit_edge19

._crit_edge19:                                    ; preds = %.lr.ph18.epil, %._crit_edge19.loopexit.unr-lcssa, %._crit_edge
  ret void

.lr.ph18:                                         ; preds = %.lr.ph18, %.lr.ph18.preheader.new
  %indvars.iv21 = phi i64 [ 2, %.lr.ph18.preheader.new ], [ %indvars.iv.next22.1, %.lr.ph18 ]
  %niter = phi i64 [ 0, %.lr.ph18.preheader.new ], [ %niter.next.1, %.lr.ph18 ]
  %35 = getelementptr inbounds [2010000 x i32], ptr @pos, i64 0, i64 %indvars.iv21
  %36 = load i32, ptr %35, align 8, !tbaa !5
  %37 = getelementptr inbounds [2010000 x i32], ptr @par, i64 0, i64 %indvars.iv21
  %38 = load i32, ptr %37, align 8, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [2010000 x i32], ptr @len, i64 0, i64 %39
  %41 = load i32, ptr %40, align 4, !tbaa !5
  %42 = add nsw i32 %41, %36
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds i8, ptr %0, i64 %43
  %45 = load i8, ptr %44, align 1, !tbaa !9
  %46 = sext i8 %45 to i64
  %47 = add nsw i64 %46, -97
  %48 = getelementptr inbounds [2010000 x [26 x i32]], ptr @ch, i64 0, i64 %39, i64 %47
  %49 = trunc nuw nsw i64 %indvars.iv21 to i32
  store i32 %49, ptr %48, align 4, !tbaa !5
  %indvars.iv.next22 = or disjoint i64 %indvars.iv21, 1
  %50 = getelementptr inbounds [2010000 x i32], ptr @pos, i64 0, i64 %indvars.iv.next22
  %51 = load i32, ptr %50, align 4, !tbaa !5
  %52 = getelementptr inbounds [2010000 x i32], ptr @par, i64 0, i64 %indvars.iv.next22
  %53 = load i32, ptr %52, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [2010000 x i32], ptr @len, i64 0, i64 %54
  %56 = load i32, ptr %55, align 4, !tbaa !5
  %57 = add nsw i32 %56, %51
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds i8, ptr %0, i64 %58
  %60 = load i8, ptr %59, align 1, !tbaa !9
  %61 = sext i8 %60 to i64
  %62 = add nsw i64 %61, -97
  %63 = getelementptr inbounds [2010000 x [26 x i32]], ptr @ch, i64 0, i64 %54, i64 %62
  %64 = trunc nuw nsw i64 %indvars.iv.next22 to i32
  store i32 %64, ptr %63, align 4, !tbaa !5
  %indvars.iv.next22.1 = add nuw nsw i64 %indvars.iv21, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter, %13
  br i1 %niter.ncmp.1, label %._crit_edge19.loopexit.unr-lcssa, label %.lr.ph18, !llvm.loop !12
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #2

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

!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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass