; LLVM IR from sunkafei/xcpc-algorithm-templates :: 算法/字符串算法/序列自动机.ll (Z6extendi)

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

@cur = external dso_local global i32, align 4
@par = external dso_local global [110000 x i32], align 16
@last = external dso_local global [26 x i32], align 16
@ch = external dso_local global [110000 x [26 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 nounwind uwtable
define dso_local void @_Z6extendi(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
  %6 = load i32, ptr %2, align 4, !tbaa !5
  %7 = sext i32 %6 to i64
  %8 = getelementptr inbounds [26 x i32], ptr @last, i64 0, i64 %7
  %9 = load i32, ptr %8, align 4, !tbaa !5
  %10 = load i32, ptr @cur, align 4, !tbaa !5
  %11 = add nsw i32 %10, 1
  store i32 %11, ptr @cur, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [110000 x i32], ptr @par, i64 0, i64 %12
  store i32 %9, ptr %13, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %14

14:                                               ; preds = %53, %1
  %15 = load i32, ptr %3, align 4, !tbaa !5
  %16 = icmp slt i32 %15, 26
  br i1 %16, label %18, label %17

17:                                               ; preds = %14
  store i32 2, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  br label %56

18:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  %19 = load i32, ptr %3, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [26 x i32], ptr @last, i64 0, i64 %20
  %22 = load i32, ptr %21, align 4, !tbaa !5
  store i32 %22, ptr %5, align 4, !tbaa !5
  br label %23

23:                                               ; preds = %47, %18
  %24 = load i32, ptr %5, align 4, !tbaa !5
  %25 = icmp ne i32 %24, 0
  br i1 %25, label %26, label %36

26:                                               ; preds = %23
  %27 = load i32, ptr %5, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [110000 x [26 x i32]], ptr @ch, i64 0, i64 %28
  %30 = load i32, ptr %2, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [26 x i32], ptr %29, i64 0, i64 %31
  %33 = load i32, ptr %32, align 4, !tbaa !5
  %34 = icmp ne i32 %33, 0
  %35 = xor i1 %34, true
  br label %36

36:                                               ; preds = %26, %23
  %37 = phi i1 [ false, %23 ], [ %35, %26 ]
  br i1 %37, label %39, label %38

38:                                               ; preds = %36
  store i32 5, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  br label %52

39:                                               ; preds = %36
  %40 = load i32, ptr @cur, align 4, !tbaa !5
  %41 = load i32, ptr %5, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [110000 x [26 x i32]], ptr @ch, i64 0, i64 %42
  %44 = load i32, ptr %2, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [26 x i32], ptr %43, i64 0, i64 %45
  store i32 %40, ptr %46, align 4, !tbaa !5
  br label %47

47:                                               ; preds = %39
  %48 = load i32, ptr %5, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [110000 x i32], ptr @par, i64 0, i64 %49
  %51 = load i32, ptr %50, align 4, !tbaa !5
  store i32 %51, ptr %5, align 4, !tbaa !5
  br label %23, !llvm.loop !9

52:                                               ; preds = %38
  br label %53

53:                                               ; preds = %52
  %54 = load i32, ptr %3, align 4, !tbaa !5
  %55 = add nsw i32 %54, 1
  store i32 %55, ptr %3, align 4, !tbaa !5
  br label %14, !llvm.loop !11

56:                                               ; preds = %17
  %57 = load i32, ptr @cur, align 4, !tbaa !5
  %58 = load i32, ptr %2, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [26 x i32], ptr @last, i64 0, i64 %59
  store i32 %57, ptr %60, align 4, !tbaa !5
  ret void
}

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

@cur = external dso_local local_unnamed_addr global i32, align 4
@par = external dso_local local_unnamed_addr global [110000 x i32], align 16
@last = external dso_local local_unnamed_addr global [26 x i32], align 16
@ch = external dso_local local_unnamed_addr global [110000 x [26 x i32]], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z6extendi(i32 noundef %0) local_unnamed_addr #0 {
  %2 = sext i32 %0 to i64
  %3 = getelementptr inbounds [26 x i32], ptr @last, i64 0, i64 %2
  %4 = load i32, ptr %3, align 4, !tbaa !5
  %5 = load i32, ptr @cur, align 4, !tbaa !5
  %6 = add nsw i32 %5, 1
  store i32 %6, ptr @cur, align 4, !tbaa !5
  %7 = sext i32 %6 to i64
  %8 = getelementptr inbounds [110000 x i32], ptr @par, i64 0, i64 %7
  store i32 %4, ptr %8, align 4, !tbaa !5
  br label %10

9:                                                ; preds = %.critedge
  store i32 %6, ptr %3, align 4, !tbaa !5
  ret void

10:                                               ; preds = %1, %.critedge
  %indvars.iv = phi i64 [ 0, %1 ], [ %indvars.iv.next, %.critedge ]
  %11 = getelementptr inbounds [26 x i32], ptr @last, i64 0, i64 %indvars.iv
  %.013 = load i32, ptr %11, align 4, !tbaa !5
  %.not14 = icmp eq i32 %.013, 0
  br i1 %.not14, label %.critedge, label %.lr.ph

.lr.ph:                                           ; preds = %10, %15
  %.015 = phi i32 [ %.0, %15 ], [ %.013, %10 ]
  %12 = sext i32 %.015 to i64
  %13 = getelementptr inbounds [110000 x [26 x i32]], ptr @ch, i64 0, i64 %12, i64 %2
  %14 = load i32, ptr %13, align 4, !tbaa !5
  %.not12 = icmp eq i32 %14, 0
  br i1 %.not12, label %15, label %.critedge

.critedge:                                        ; preds = %.lr.ph, %15, %10
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 26
  br i1 %exitcond.not, label %9, label %10, !llvm.loop !9

15:                                               ; preds = %.lr.ph
  store i32 %6, ptr %13, align 4, !tbaa !5
  %16 = getelementptr inbounds [110000 x i32], ptr @par, i64 0, i64 %12
  %.0 = load i32, ptr %16, align 4, !tbaa !5
  %.not = icmp eq i32 %.0, 0
  br i1 %.not, label %.critedge, label %.lr.ph, !llvm.loop !11
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) 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}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass