; LLVM IR from sunkafei/xcpc-algorithm-templates :: 算法/字符串算法/后缀自动机.ll (ZN11Suffix_Tree5buildEPKc)

; 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 [210000 x i32], align 16
@len = external dso_local global [210000 x i32], align 16
@cur = external dso_local global i32, align 4
@root = external dso_local global i32, align 4
@last = external dso_local global i32, align 4
@_ZN11Suffix_Tree3posE = external dso_local global [210000 x i32], align 16
@_ZN11Suffix_Tree2chE = external dso_local global [210000 x [26 x i32]], align 16
@_ZN11Suffix_Tree1sE = external dso_local global [210000 x i8], 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: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #1

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN11Suffix_Tree5buildEPKc(ptr noundef %0) #2 {
  %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
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  %8 = call ptr @strcpy(ptr noundef @_ZN11Suffix_Tree1sE, ptr noundef %7) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  %9 = call i64 @strlen(ptr noundef @_ZN11Suffix_Tree1sE) #5
  %10 = trunc i64 %9 to i32
  store i32 %10, ptr %3, align 4, !tbaa !9
  %11 = load i32, ptr @root, align 4, !tbaa !9
  store i32 %11, ptr @last, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 0, ptr %4, align 4, !tbaa !9
  br label %12

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

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

17:                                               ; preds = %12
  %18 = load i32, ptr %4, align 4, !tbaa !9
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [210000 x i8], ptr @_ZN11Suffix_Tree1sE, i64 0, 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 @_ZN11Suffix_Tree6extendEii(i32 noundef %23, i32 noundef %24)
  br label %25

25:                                               ; preds = %17
  %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 = %16
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 2, ptr %5, align 4, !tbaa !9
  br label %29

29:                                               ; preds = %62, %28
  %30 = load i32, ptr %5, align 4, !tbaa !9
  %31 = load i32, ptr @cur, align 4, !tbaa !9
  %32 = icmp slt i32 %30, %31
  br i1 %32, label %34, label %33

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

34:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %35 = load i32, ptr %5, align 4, !tbaa !9
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [210000 x i32], ptr @_ZN11Suffix_Tree3posE, i64 0, i64 %36
  %38 = load i32, ptr %37, align 4, !tbaa !9
  %39 = load i32, ptr %5, align 4, !tbaa !9
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [210000 x i32], ptr @par, i64 0, i64 %40
  %42 = load i32, ptr %41, align 4, !tbaa !9
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [210000 x i32], ptr @len, i64 0, i64 %43
  %45 = load i32, ptr %44, align 4, !tbaa !9
  %46 = sub nsw i32 %38, %45
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [210000 x i8], ptr @_ZN11Suffix_Tree1sE, i64 0, i64 %47
  %49 = load i8, ptr %48, align 1, !tbaa !11
  %50 = sext i8 %49 to i32
  %51 = sub nsw i32 %50, 97
  store i32 %51, ptr %6, align 4, !tbaa !9
  %52 = load i32, ptr %5, align 4, !tbaa !9
  %53 = load i32, ptr %5, align 4, !tbaa !9
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [210000 x i32], ptr @par, i64 0, i64 %54
  %56 = load i32, ptr %55, align 4, !tbaa !9
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [210000 x [26 x i32]], ptr @_ZN11Suffix_Tree2chE, i64 0, i64 %57
  %59 = load i32, ptr %6, align 4, !tbaa !9
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [26 x i32], ptr %58, i64 0, i64 %60
  store i32 %52, ptr %61, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %62

62:                                               ; preds = %34
  %63 = load i32, ptr %5, align 4, !tbaa !9
  %64 = add nsw i32 %63, 1
  store i32 %64, ptr %5, align 4, !tbaa !9
  br label %29, !llvm.loop !14

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

; Function Attrs: nounwind
declare ptr @strcpy(ptr noundef, ptr noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 "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 [210000 x i32], align 16
@len = external dso_local local_unnamed_addr global [210000 x i32], align 16
@cur = external dso_local local_unnamed_addr global i32, align 4
@root = external dso_local local_unnamed_addr global i32, align 4
@last = external dso_local local_unnamed_addr global i32, align 4
@_ZN11Suffix_Tree3posE = external dso_local local_unnamed_addr global [210000 x i32], align 16
@_ZN11Suffix_Tree2chE = external dso_local local_unnamed_addr global [210000 x [26 x i32]], align 16
@_ZN11Suffix_Tree1sE = external dso_local global [210000 x i8], align 16

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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN11Suffix_Tree5buildEPKc(ptr nocapture noundef readonly %0) local_unnamed_addr #1 {
  %2 = tail call ptr @strcpy(ptr noundef nonnull dereferenceable(1) @_ZN11Suffix_Tree1sE, ptr noundef nonnull dereferenceable(1) %0) #3
  %3 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) @_ZN11Suffix_Tree1sE) #4
  %4 = trunc i64 %3 to i32
  %5 = load i32, ptr @root, align 4, !tbaa !5
  store i32 %5, ptr @last, align 4, !tbaa !5
  %6 = icmp sgt i32 %4, 0
  br i1 %6, label %.lr.ph.preheader, label %.preheader

.lr.ph.preheader:                                 ; preds = %1
  %wide.trip.count = and i64 %3, 2147483647
  br label %.lr.ph

.preheader:                                       ; preds = %.lr.ph, %1
  %7 = load i32, ptr @cur, align 4, !tbaa !5
  %8 = icmp sgt i32 %7, 2
  br i1 %8, label %.lr.ph15.preheader, label %._crit_edge

.lr.ph15.preheader:                               ; preds = %.preheader
  %wide.trip.count20 = zext nneg i32 %7 to i64
  %xtraiter = and i64 %wide.trip.count20, 1
  %9 = icmp eq i32 %7, 3
  br i1 %9, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph15.preheader.new

.lr.ph15.preheader.new:                           ; preds = %.lr.ph15.preheader
  %10 = and i64 %wide.trip.count20, 2147483646
  %11 = add nsw i64 %10, -4
  br label %.lr.ph15

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %12 = getelementptr inbounds [210000 x i8], ptr @_ZN11Suffix_Tree1sE, i64 0, i64 %indvars.iv
  %13 = load i8, ptr %12, align 1, !tbaa !9
  %14 = sext i8 %13 to i32
  %15 = add nsw i32 %14, -97
  %16 = trunc nuw nsw i64 %indvars.iv to i32
  tail call void @_ZN11Suffix_Tree6extendEii(i32 noundef %15, i32 noundef %16)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %.preheader, label %.lr.ph, !llvm.loop !10

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

.lr.ph15.epil:                                    ; preds = %._crit_edge.loopexit.unr-lcssa
  %17 = getelementptr inbounds [210000 x i32], ptr @_ZN11Suffix_Tree3posE, i64 0, i64 %indvars.iv17.unr
  %18 = load i32, ptr %17, align 4, !tbaa !5
  %19 = getelementptr inbounds [210000 x i32], ptr @par, i64 0, i64 %indvars.iv17.unr
  %20 = load i32, ptr %19, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [210000 x i32], ptr @len, i64 0, i64 %21
  %23 = load i32, ptr %22, align 4, !tbaa !5
  %24 = sub nsw i32 %18, %23
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [210000 x i8], ptr @_ZN11Suffix_Tree1sE, i64 0, i64 %25
  %27 = load i8, ptr %26, align 1, !tbaa !9
  %28 = sext i8 %27 to i64
  %29 = add nsw i64 %28, -97
  %30 = getelementptr inbounds [210000 x [26 x i32]], ptr @_ZN11Suffix_Tree2chE, i64 0, i64 %21, i64 %29
  %31 = trunc nuw nsw i64 %indvars.iv17.unr to i32
  store i32 %31, ptr %30, align 4, !tbaa !5
  br label %._crit_edge

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

.lr.ph15:                                         ; preds = %.lr.ph15, %.lr.ph15.preheader.new
  %indvars.iv17 = phi i64 [ 2, %.lr.ph15.preheader.new ], [ %indvars.iv.next18.1, %.lr.ph15 ]
  %niter = phi i64 [ 0, %.lr.ph15.preheader.new ], [ %niter.next.1, %.lr.ph15 ]
  %32 = getelementptr inbounds [210000 x i32], ptr @_ZN11Suffix_Tree3posE, i64 0, i64 %indvars.iv17
  %33 = load i32, ptr %32, align 8, !tbaa !5
  %34 = getelementptr inbounds [210000 x i32], ptr @par, i64 0, i64 %indvars.iv17
  %35 = load i32, ptr %34, align 8, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [210000 x i32], ptr @len, i64 0, i64 %36
  %38 = load i32, ptr %37, align 4, !tbaa !5
  %39 = sub nsw i32 %33, %38
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [210000 x i8], ptr @_ZN11Suffix_Tree1sE, i64 0, i64 %40
  %42 = load i8, ptr %41, align 1, !tbaa !9
  %43 = sext i8 %42 to i64
  %44 = add nsw i64 %43, -97
  %45 = getelementptr inbounds [210000 x [26 x i32]], ptr @_ZN11Suffix_Tree2chE, i64 0, i64 %36, i64 %44
  %46 = trunc nuw nsw i64 %indvars.iv17 to i32
  store i32 %46, ptr %45, align 4, !tbaa !5
  %indvars.iv.next18 = or disjoint i64 %indvars.iv17, 1
  %47 = getelementptr inbounds [210000 x i32], ptr @_ZN11Suffix_Tree3posE, i64 0, i64 %indvars.iv.next18
  %48 = load i32, ptr %47, align 4, !tbaa !5
  %49 = getelementptr inbounds [210000 x i32], ptr @par, i64 0, i64 %indvars.iv.next18
  %50 = load i32, ptr %49, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [210000 x i32], ptr @len, i64 0, i64 %51
  %53 = load i32, ptr %52, align 4, !tbaa !5
  %54 = sub nsw i32 %48, %53
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [210000 x i8], ptr @_ZN11Suffix_Tree1sE, i64 0, i64 %55
  %57 = load i8, ptr %56, align 1, !tbaa !9
  %58 = sext i8 %57 to i64
  %59 = add nsw i64 %58, -97
  %60 = getelementptr inbounds [210000 x [26 x i32]], ptr @_ZN11Suffix_Tree2chE, i64 0, i64 %51, i64 %59
  %61 = trunc nuw nsw i64 %indvars.iv.next18 to i32
  store i32 %61, ptr %60, align 4, !tbaa !5
  %indvars.iv.next18.1 = add nuw nsw i64 %indvars.iv17, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter, %11
  br i1 %niter.ncmp.1, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph15, !llvm.loop !12
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: readwrite)
declare ptr @strcpy(ptr noalias noundef returned writeonly, ptr noalias nocapture noundef readonly) local_unnamed_addr #2

attributes #0 = { 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 #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: readwrite) "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 }
attributes #4 = { 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: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass