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

; 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
@go = external dso_local global [210000 x [26 x i32]], align 16
@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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z8newstateii(i32 noundef, 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: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #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 nounwind uwtable
define dso_local void @_ZN11Suffix_Tree6extendEii(i32 noundef %0, i32 noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %9 = load i32, ptr @last, align 4, !tbaa !5
  store i32 %9, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %10 = load i32, ptr %5, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [210000 x i32], ptr @len, i64 0, i64 %11
  %13 = load i32, ptr %12, align 4, !tbaa !5
  %14 = add nsw i32 %13, 1
  %15 = load i32, ptr %4, align 4, !tbaa !5
  %16 = call noundef i32 @_Z8newstateii(i32 noundef %14, i32 noundef %15)
  store i32 %16, ptr %6, align 4, !tbaa !5
  %17 = load i32, ptr %4, align 4, !tbaa !5
  %18 = load i32, ptr %6, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [210000 x i32], ptr @_ZN11Suffix_Tree3posE, i64 0, i64 %19
  store i32 %17, ptr %20, align 4, !tbaa !5
  br label %21

21:                                               ; preds = %36, %2
  %22 = load i32, ptr %5, align 4, !tbaa !5
  %23 = icmp ne i32 %22, 0
  br i1 %23, label %24, label %34

24:                                               ; preds = %21
  %25 = load i32, ptr %5, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [210000 x [26 x i32]], ptr @go, i64 0, i64 %26
  %28 = load i32, ptr %3, 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 = icmp ne i32 %31, 0
  %33 = xor i1 %32, true
  br label %34

34:                                               ; preds = %24, %21
  %35 = phi i1 [ false, %21 ], [ %33, %24 ]
  br i1 %35, label %36, label %48

36:                                               ; preds = %34
  %37 = load i32, ptr %6, align 4, !tbaa !5
  %38 = load i32, ptr %5, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [210000 x [26 x i32]], ptr @go, i64 0, i64 %39
  %41 = load i32, ptr %3, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [26 x i32], ptr %40, i64 0, i64 %42
  store i32 %37, ptr %43, align 4, !tbaa !5
  %44 = load i32, ptr %5, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [210000 x i32], ptr @par, i64 0, i64 %45
  %47 = load i32, ptr %46, align 4, !tbaa !5
  store i32 %47, ptr %5, align 4, !tbaa !5
  br label %21, !llvm.loop !9

48:                                               ; preds = %34
  %49 = load i32, ptr %5, align 4, !tbaa !5
  %50 = icmp ne i32 %49, 0
  br i1 %50, label %56, label %51

51:                                               ; preds = %48
  %52 = load i32, ptr @root, align 4, !tbaa !5
  %53 = load i32, ptr %6, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [210000 x i32], ptr @par, i64 0, i64 %54
  store i32 %52, ptr %55, align 4, !tbaa !5
  br label %144

56:                                               ; preds = %48
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %57 = load i32, ptr %5, align 4, !tbaa !5
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [210000 x [26 x i32]], ptr @go, i64 0, i64 %58
  %60 = load i32, ptr %3, align 4, !tbaa !5
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [26 x i32], ptr %59, i64 0, i64 %61
  %63 = load i32, ptr %62, align 4, !tbaa !5
  store i32 %63, ptr %7, align 4, !tbaa !5
  %64 = load i32, ptr %5, align 4, !tbaa !5
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds [210000 x i32], ptr @len, i64 0, i64 %65
  %67 = load i32, ptr %66, align 4, !tbaa !5
  %68 = add nsw i32 %67, 1
  %69 = load i32, ptr %7, align 4, !tbaa !5
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [210000 x i32], ptr @len, i64 0, i64 %70
  %72 = load i32, ptr %71, align 4, !tbaa !5
  %73 = icmp eq i32 %68, %72
  br i1 %73, label %74, label %79

74:                                               ; preds = %56
  %75 = load i32, ptr %7, align 4, !tbaa !5
  %76 = load i32, ptr %6, align 4, !tbaa !5
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds [210000 x i32], ptr @par, i64 0, i64 %77
  store i32 %75, ptr %78, align 4, !tbaa !5
  br label %143

79:                                               ; preds = %56
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %80 = load i32, ptr %5, align 4, !tbaa !5
  %81 = sext i32 %80 to i64
  %82 = getelementptr inbounds [210000 x i32], ptr @len, i64 0, i64 %81
  %83 = load i32, ptr %82, align 4, !tbaa !5
  %84 = add nsw i32 %83, 1
  %85 = call noundef i32 @_Z8newstateii(i32 noundef %84, i32 noundef -1)
  store i32 %85, ptr %8, align 4, !tbaa !5
  %86 = load i32, ptr %8, align 4, !tbaa !5
  %87 = sext i32 %86 to i64
  %88 = getelementptr inbounds [210000 x [26 x i32]], ptr @go, i64 0, i64 %87
  %89 = getelementptr inbounds [26 x i32], ptr %88, i64 0, i64 0
  %90 = load i32, ptr %7, align 4, !tbaa !5
  %91 = sext i32 %90 to i64
  %92 = getelementptr inbounds [210000 x [26 x i32]], ptr @go, i64 0, i64 %91
  %93 = getelementptr inbounds [26 x i32], ptr %92, i64 0, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %89, ptr align 8 %93, i64 104, i1 false)
  %94 = load i32, ptr %7, align 4, !tbaa !5
  %95 = sext i32 %94 to i64
  %96 = getelementptr inbounds [210000 x i32], ptr @_ZN11Suffix_Tree3posE, i64 0, i64 %95
  %97 = load i32, ptr %96, align 4, !tbaa !5
  %98 = load i32, ptr %8, align 4, !tbaa !5
  %99 = sext i32 %98 to i64
  %100 = getelementptr inbounds [210000 x i32], ptr @_ZN11Suffix_Tree3posE, i64 0, i64 %99
  store i32 %97, ptr %100, align 4, !tbaa !5
  %101 = load i32, ptr %7, align 4, !tbaa !5
  %102 = sext i32 %101 to i64
  %103 = getelementptr inbounds [210000 x i32], ptr @par, i64 0, i64 %102
  %104 = load i32, ptr %103, align 4, !tbaa !5
  %105 = load i32, ptr %8, align 4, !tbaa !5
  %106 = sext i32 %105 to i64
  %107 = getelementptr inbounds [210000 x i32], ptr @par, i64 0, i64 %106
  store i32 %104, ptr %107, align 4, !tbaa !5
  %108 = load i32, ptr %8, align 4, !tbaa !5
  %109 = load i32, ptr %7, align 4, !tbaa !5
  %110 = sext i32 %109 to i64
  %111 = getelementptr inbounds [210000 x i32], ptr @par, i64 0, i64 %110
  store i32 %108, ptr %111, align 4, !tbaa !5
  %112 = load i32, ptr %6, align 4, !tbaa !5
  %113 = sext i32 %112 to i64
  %114 = getelementptr inbounds [210000 x i32], ptr @par, i64 0, i64 %113
  store i32 %108, ptr %114, align 4, !tbaa !5
  br label %115

115:                                              ; preds = %130, %79
  %116 = load i32, ptr %5, align 4, !tbaa !5
  %117 = icmp ne i32 %116, 0
  br i1 %117, label %118, label %128

118:                                              ; preds = %115
  %119 = load i32, ptr %5, align 4, !tbaa !5
  %120 = sext i32 %119 to i64
  %121 = getelementptr inbounds [210000 x [26 x i32]], ptr @go, i64 0, i64 %120
  %122 = load i32, ptr %3, align 4, !tbaa !5
  %123 = sext i32 %122 to i64
  %124 = getelementptr inbounds [26 x i32], ptr %121, i64 0, i64 %123
  %125 = load i32, ptr %124, align 4, !tbaa !5
  %126 = load i32, ptr %7, align 4, !tbaa !5
  %127 = icmp eq i32 %125, %126
  br label %128

128:                                              ; preds = %118, %115
  %129 = phi i1 [ false, %115 ], [ %127, %118 ]
  br i1 %129, label %130, label %142

130:                                              ; preds = %128
  %131 = load i32, ptr %8, align 4, !tbaa !5
  %132 = load i32, ptr %5, align 4, !tbaa !5
  %133 = sext i32 %132 to i64
  %134 = getelementptr inbounds [210000 x [26 x i32]], ptr @go, i64 0, i64 %133
  %135 = load i32, ptr %3, align 4, !tbaa !5
  %136 = sext i32 %135 to i64
  %137 = getelementptr inbounds [26 x i32], ptr %134, i64 0, i64 %136
  store i32 %131, ptr %137, align 4, !tbaa !5
  %138 = load i32, ptr %5, align 4, !tbaa !5
  %139 = sext i32 %138 to i64
  %140 = getelementptr inbounds [210000 x i32], ptr @par, i64 0, i64 %139
  %141 = load i32, ptr %140, align 4, !tbaa !5
  store i32 %141, ptr %5, align 4, !tbaa !5
  br label %115, !llvm.loop !11

142:                                              ; preds = %128
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %143

143:                                              ; preds = %142, %74
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %144

144:                                              ; preds = %143, %51
  %145 = load i32, ptr %6, align 4, !tbaa !5
  store i32 %145, ptr @last, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  ret void
}

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


; 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
@go = external dso_local local_unnamed_addr global [210000 x [26 x i32]], align 16
@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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z8newstateii(i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN11Suffix_Tree6extendEii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = load i32, ptr @last, align 4, !tbaa !5
  %4 = sext i32 %3 to i64
  %5 = getelementptr inbounds [210000 x i32], ptr @len, i64 0, i64 %4
  %6 = load i32, ptr %5, align 4, !tbaa !5
  %7 = add nsw i32 %6, 1
  %8 = tail call noundef i32 @_Z8newstateii(i32 noundef %7, i32 noundef %1)
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds [210000 x i32], ptr @_ZN11Suffix_Tree3posE, i64 0, i64 %9
  store i32 %1, ptr %10, align 4, !tbaa !5
  %.not47 = icmp eq i32 %3, 0
  br i1 %.not47, label %.critedge43, label %.lr.ph

.lr.ph:                                           ; preds = %2
  %11 = sext i32 %0 to i64
  br label %12

12:                                               ; preds = %.lr.ph, %16
  %.048 = phi i32 [ %3, %.lr.ph ], [ %18, %16 ]
  %13 = sext i32 %.048 to i64
  %14 = getelementptr inbounds [210000 x [26 x i32]], ptr @go, i64 0, i64 %13, i64 %11
  %15 = load i32, ptr %14, align 4, !tbaa !5
  %.not41 = icmp eq i32 %15, 0
  br i1 %.not41, label %16, label %.critedge

16:                                               ; preds = %12
  store i32 %8, ptr %14, align 4, !tbaa !5
  %17 = getelementptr inbounds [210000 x i32], ptr @par, i64 0, i64 %13
  %18 = load i32, ptr %17, align 4, !tbaa !5
  %.not = icmp eq i32 %18, 0
  br i1 %.not, label %.critedge43, label %12, !llvm.loop !9

.critedge43:                                      ; preds = %16, %2
  %19 = load i32, ptr @root, align 4, !tbaa !5
  br label %.critedge2.sink.split

.critedge:                                        ; preds = %12
  %20 = getelementptr inbounds [210000 x i32], ptr @len, i64 0, i64 %13
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = add nsw i32 %21, 1
  %23 = sext i32 %15 to i64
  %24 = getelementptr inbounds [210000 x i32], ptr @len, i64 0, i64 %23
  %25 = load i32, ptr %24, align 4, !tbaa !5
  %26 = icmp eq i32 %22, %25
  br i1 %26, label %.critedge2.sink.split, label %27

27:                                               ; preds = %.critedge
  %28 = tail call noundef i32 @_Z8newstateii(i32 noundef %22, i32 noundef -1)
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [210000 x [26 x i32]], ptr @go, i64 0, i64 %29
  %31 = getelementptr inbounds [210000 x [26 x i32]], ptr @go, i64 0, i64 %23
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(104) %30, ptr noundef nonnull align 8 dereferenceable(104) %31, i64 104, i1 false)
  %32 = getelementptr inbounds [210000 x i32], ptr @_ZN11Suffix_Tree3posE, i64 0, i64 %23
  %33 = load i32, ptr %32, align 4, !tbaa !5
  %34 = getelementptr inbounds [210000 x i32], ptr @_ZN11Suffix_Tree3posE, i64 0, i64 %29
  store i32 %33, ptr %34, align 4, !tbaa !5
  %35 = getelementptr inbounds [210000 x i32], ptr @par, i64 0, i64 %23
  %36 = load i32, ptr %35, align 4, !tbaa !5
  %37 = getelementptr inbounds [210000 x i32], ptr @par, i64 0, i64 %29
  store i32 %36, ptr %37, align 4, !tbaa !5
  store i32 %28, ptr %35, align 4, !tbaa !5
  %38 = getelementptr inbounds [210000 x i32], ptr @par, i64 0, i64 %9
  store i32 %28, ptr %38, align 4, !tbaa !5
  br label %39

39:                                               ; preds = %27, %44
  %.149 = phi i32 [ %.048, %27 ], [ %46, %44 ]
  %40 = sext i32 %.149 to i64
  %41 = getelementptr inbounds [210000 x [26 x i32]], ptr @go, i64 0, i64 %40, i64 %11
  %42 = load i32, ptr %41, align 4, !tbaa !5
  %43 = icmp eq i32 %42, %15
  br i1 %43, label %44, label %.critedge2

44:                                               ; preds = %39
  store i32 %28, ptr %41, align 4, !tbaa !5
  %45 = getelementptr inbounds [210000 x i32], ptr @par, i64 0, i64 %40
  %46 = load i32, ptr %45, align 4, !tbaa !5
  %.not42 = icmp eq i32 %46, 0
  br i1 %.not42, label %.critedge2, label %39, !llvm.loop !11

.critedge2.sink.split:                            ; preds = %.critedge, %.critedge43
  %.lcssa.sink = phi i32 [ %19, %.critedge43 ], [ %15, %.critedge ]
  %47 = getelementptr inbounds [210000 x i32], ptr @par, i64 0, i64 %9
  store i32 %.lcssa.sink, ptr %47, align 4, !tbaa !5
  br label %.critedge2

.critedge2:                                       ; preds = %44, %39, %.critedge2.sink.split
  store i32 %8, ptr @last, align 4, !tbaa !5
  ret void
}

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

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


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