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

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

@_ZN28Generalized_Suffix_Automaton2goE = external dso_local global [210000 x [26 x i32]], align 16
@_ZN28Generalized_Suffix_Automaton5timesE = external dso_local global [210000 x i32], align 16
@_ZN28Generalized_Suffix_Automaton1nE = external dso_local global i32, align 4
@_ZN28Generalized_Suffix_Automaton2dpE = external dso_local global [210000 x i64], 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
define dso_local void @_ZN28Generalized_Suffix_Automaton6outputEix(i32 noundef %0, i64 noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca i64, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !9
  %7 = load i64, ptr %4, align 8, !tbaa !9
  %8 = icmp eq i64 %7, 0
  br i1 %8, label %9, label %10

9:                                                ; preds = %2
  br label %86

10:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %11

11:                                               ; preds = %81, %10
  %12 = load i32, ptr %5, align 4, !tbaa !5
  %13 = icmp slt i32 %12, 26
  br i1 %13, label %15, label %14

14:                                               ; preds = %11
  store i32 2, ptr %6, align 4
  br label %84

15:                                               ; preds = %11
  %16 = load i32, ptr %3, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [210000 x [26 x i32]], ptr @_ZN28Generalized_Suffix_Automaton2goE, i64 0, i64 %17
  %19 = load i32, ptr %5, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [26 x i32], ptr %18, i64 0, i64 %20
  %22 = load i32, ptr %21, align 4, !tbaa !5
  %23 = icmp ne i32 %22, 0
  br i1 %23, label %24, label %80

24:                                               ; preds = %15
  %25 = load i32, ptr %3, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [210000 x [26 x i32]], ptr @_ZN28Generalized_Suffix_Automaton2goE, i64 0, i64 %26
  %28 = load i32, ptr %5, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [26 x i32], ptr %27, i64 0, i64 %29
  %31 = load i32, ptr %30, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [210000 x i32], ptr @_ZN28Generalized_Suffix_Automaton5timesE, i64 0, i64 %32
  %34 = load i32, ptr %33, align 4, !tbaa !5
  %35 = load i32, ptr @_ZN28Generalized_Suffix_Automaton1nE, align 4, !tbaa !5
  %36 = icmp eq i32 %34, %35
  br i1 %36, label %37, label %80

37:                                               ; preds = %24
  %38 = load i64, ptr %4, align 8, !tbaa !9
  %39 = load i32, ptr %3, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [210000 x [26 x i32]], ptr @_ZN28Generalized_Suffix_Automaton2goE, i64 0, i64 %40
  %42 = load i32, ptr %5, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [26 x i32], ptr %41, i64 0, i64 %43
  %45 = load i32, ptr %44, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [210000 x i64], ptr @_ZN28Generalized_Suffix_Automaton2dpE, i64 0, i64 %46
  %48 = load i64, ptr %47, align 8, !tbaa !9
  %49 = sub nsw i64 %38, %48
  %50 = sub nsw i64 %49, 1
  %51 = icmp sgt i64 %50, 0
  br i1 %51, label %52, label %66

52:                                               ; preds = %37
  %53 = load i32, ptr %3, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [210000 x [26 x i32]], ptr @_ZN28Generalized_Suffix_Automaton2goE, i64 0, i64 %54
  %56 = load i32, ptr %5, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [26 x i32], ptr %55, i64 0, i64 %57
  %59 = load i32, ptr %58, align 4, !tbaa !5
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [210000 x i64], ptr @_ZN28Generalized_Suffix_Automaton2dpE, i64 0, i64 %60
  %62 = load i64, ptr %61, align 8, !tbaa !9
  %63 = add nsw i64 %62, 1
  %64 = load i64, ptr %4, align 8, !tbaa !9
  %65 = sub nsw i64 %64, %63
  store i64 %65, ptr %4, align 8, !tbaa !9
  br label %79

66:                                               ; preds = %37
  %67 = load i32, ptr %5, align 4, !tbaa !5
  %68 = add nsw i32 97, %67
  %69 = call i32 @putchar(i32 noundef %68)
  %70 = load i32, ptr %3, align 4, !tbaa !5
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds [210000 x [26 x i32]], ptr @_ZN28Generalized_Suffix_Automaton2goE, i64 0, i64 %71
  %73 = load i32, ptr %5, align 4, !tbaa !5
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds [26 x i32], ptr %72, i64 0, i64 %74
  %76 = load i32, ptr %75, align 4, !tbaa !5
  %77 = load i64, ptr %4, align 8, !tbaa !9
  %78 = sub nsw i64 %77, 1
  call void @_ZN28Generalized_Suffix_Automaton6outputEix(i32 noundef %76, i64 noundef %78)
  store i32 1, ptr %6, align 4
  br label %84

79:                                               ; preds = %52
  br label %80

80:                                               ; preds = %79, %24, %15
  br label %81

81:                                               ; preds = %80
  %82 = load i32, ptr %5, align 4, !tbaa !5
  %83 = add nsw i32 %82, 1
  store i32 %83, ptr %5, align 4, !tbaa !5
  br label %11, !llvm.loop !11

84:                                               ; preds = %66, %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  %85 = load i32, ptr %6, align 4
  switch i32 %85, label %87 [
    i32 2, label %86
    i32 1, label %86
  ]

86:                                               ; preds = %84, %84, %9
  ret void

87:                                               ; preds = %84
  unreachable
}

; Function Attrs: inlinehint mustprogress uwtable
declare i32 @putchar(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 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 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"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"

@_ZN28Generalized_Suffix_Automaton2goE = external dso_local local_unnamed_addr global [210000 x [26 x i32]], align 16
@_ZN28Generalized_Suffix_Automaton5timesE = external dso_local local_unnamed_addr global [210000 x i32], align 16
@_ZN28Generalized_Suffix_Automaton1nE = external dso_local local_unnamed_addr global i32, align 4
@_ZN28Generalized_Suffix_Automaton2dpE = external dso_local local_unnamed_addr global [210000 x i64], align 16

; Function Attrs: mustprogress nofree nounwind uwtable
define dso_local void @_ZN28Generalized_Suffix_Automaton6outputEix(i32 noundef %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = icmp eq i64 %1, 0
  br i1 %3, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %2, %tailrecurse
  %.tr2027 = phi i64 [ %25, %tailrecurse ], [ %1, %2 ]
  %.tr26 = phi i32 [ %24, %tailrecurse ], [ %0, %2 ]
  %4 = sext i32 %.tr26 to i64
  %5 = load i32, ptr @_ZN28Generalized_Suffix_Automaton1nE, align 4
  br label %6

6:                                                ; preds = %.preheader, %27
  %indvars.iv = phi i64 [ 0, %.preheader ], [ %indvars.iv.next, %27 ]
  %.01724 = phi i64 [ %.tr2027, %.preheader ], [ %.1, %27 ]
  %7 = getelementptr inbounds [210000 x [26 x i32]], ptr @_ZN28Generalized_Suffix_Automaton2goE, i64 0, i64 %4, i64 %indvars.iv
  %8 = load i32, ptr %7, align 4, !tbaa !5
  %.not = icmp eq i32 %8, 0
  br i1 %.not, label %27, label %9

9:                                                ; preds = %6
  %10 = sext i32 %8 to i64
  %11 = getelementptr inbounds [210000 x i32], ptr @_ZN28Generalized_Suffix_Automaton5timesE, i64 0, i64 %10
  %12 = load i32, ptr %11, align 4, !tbaa !5
  %13 = icmp eq i32 %12, %5
  br i1 %13, label %14, label %27

14:                                               ; preds = %9
  %15 = getelementptr inbounds [210000 x i64], ptr @_ZN28Generalized_Suffix_Automaton2dpE, i64 0, i64 %10
  %16 = load i64, ptr %15, align 8, !tbaa !9
  %17 = sub i64 %16, %.01724
  %18 = icmp slt i64 %17, -1
  br i1 %18, label %19, label %tailrecurse

19:                                               ; preds = %14
  %.neg = xor i64 %16, -1
  %20 = add i64 %.01724, %.neg
  br label %27

tailrecurse:                                      ; preds = %14
  %21 = trunc nuw nsw i64 %indvars.iv to i32
  %22 = add nuw nsw i32 %21, 97
  %23 = tail call i32 @putchar(i32 noundef %22)
  %24 = load i32, ptr %7, align 4, !tbaa !5
  %25 = add nsw i64 %.01724, -1
  %26 = icmp eq i64 %25, 0
  br i1 %26, label %.loopexit, label %.preheader

27:                                               ; preds = %6, %9, %19
  %.1 = phi i64 [ %20, %19 ], [ %.01724, %9 ], [ %.01724, %6 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 26
  br i1 %exitcond.not, label %.loopexit, label %6, !llvm.loop !11

.loopexit:                                        ; preds = %tailrecurse, %27, %2
  ret void
}

; Function Attrs: inlinehint mustprogress nofree nounwind uwtable
declare noundef i32 @putchar(i32 noundef) local_unnamed_addr #1

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


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