; LLVM IR from lzyrapx/Competitive-Programming :: Retired_code/String/BZOJ 1009 （AC自动机+矩阵乘法优化dp）.ll (Zml6matrixS_)

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

%struct.matrix = type { [26 x [26 x i32]] }

@mod = external dso_local global i32, align 4
@sz = external dso_local global i32, align 4

; Function Attrs: mustprogress uwtable
define dso_local void @_Zml6matrixS_(ptr dead_on_unwind noalias writable sret(%struct.matrix) align 4 %0, ptr noundef byval(%struct.matrix) align 8 %1, ptr noundef byval(%struct.matrix) align 8 %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  call void @_ZN6matrix4initEv(ptr noundef nonnull align 4 dereferenceable(2704) %0)
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 1, ptr %4, align 4, !tbaa !5
  br label %8

8:                                                ; preds = %73, %3
  %9 = load i32, ptr %4, align 4, !tbaa !5
  %10 = load i32, ptr @sz, align 4, !tbaa !5
  %11 = add nsw i32 %10, 1
  %12 = icmp sle i32 %9, %11
  br i1 %12, label %14, label %13

13:                                               ; preds = %8
  store i32 2, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %76

14:                                               ; preds = %8
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 1, ptr %6, align 4, !tbaa !5
  br label %15

15:                                               ; preds = %69, %14
  %16 = load i32, ptr %6, align 4, !tbaa !5
  %17 = load i32, ptr @sz, align 4, !tbaa !5
  %18 = add nsw i32 %17, 1
  %19 = icmp sle i32 %16, %18
  br i1 %19, label %21, label %20

20:                                               ; preds = %15
  store i32 5, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %72

21:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 1, ptr %7, align 4, !tbaa !5
  br label %22

22:                                               ; preds = %65, %21
  %23 = load i32, ptr %7, align 4, !tbaa !5
  %24 = load i32, ptr @sz, align 4, !tbaa !5
  %25 = add nsw i32 %24, 1
  %26 = icmp sle i32 %23, %25
  br i1 %26, label %28, label %27

27:                                               ; preds = %22
  store i32 8, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %68

28:                                               ; preds = %22
  %29 = getelementptr inbounds %struct.matrix, ptr %1, i32 0, i32 0
  %30 = load i32, ptr %4, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [26 x [26 x i32]], ptr %29, i64 0, i64 %31
  %33 = load i32, ptr %7, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [26 x i32], ptr %32, i64 0, i64 %34
  %36 = load i32, ptr %35, align 4, !tbaa !5
  %37 = getelementptr inbounds %struct.matrix, ptr %2, i32 0, i32 0
  %38 = load i32, ptr %7, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [26 x [26 x i32]], ptr %37, i64 0, i64 %39
  %41 = load i32, ptr %6, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [26 x i32], ptr %40, i64 0, i64 %42
  %44 = load i32, ptr %43, align 4, !tbaa !5
  %45 = mul nsw i32 %36, %44
  %46 = getelementptr inbounds %struct.matrix, ptr %0, i32 0, i32 0
  %47 = load i32, ptr %4, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [26 x [26 x i32]], ptr %46, i64 0, i64 %48
  %50 = load i32, ptr %6, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [26 x i32], ptr %49, i64 0, i64 %51
  %53 = load i32, ptr %52, align 4, !tbaa !5
  %54 = add nsw i32 %53, %45
  store i32 %54, ptr %52, align 4, !tbaa !5
  %55 = load i32, ptr @mod, align 4, !tbaa !5
  %56 = getelementptr inbounds %struct.matrix, ptr %0, i32 0, i32 0
  %57 = load i32, ptr %4, align 4, !tbaa !5
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [26 x [26 x i32]], ptr %56, i64 0, i64 %58
  %60 = load i32, ptr %6, 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
  %64 = srem i32 %63, %55
  store i32 %64, ptr %62, align 4, !tbaa !5
  br label %65

65:                                               ; preds = %28
  %66 = load i32, ptr %7, align 4, !tbaa !5
  %67 = add nsw i32 %66, 1
  store i32 %67, ptr %7, align 4, !tbaa !5
  br label %22, !llvm.loop !9

68:                                               ; preds = %27
  br label %69

69:                                               ; preds = %68
  %70 = load i32, ptr %6, align 4, !tbaa !5
  %71 = add nsw i32 %70, 1
  store i32 %71, ptr %6, align 4, !tbaa !5
  br label %15, !llvm.loop !11

72:                                               ; preds = %20
  br label %73

73:                                               ; preds = %72
  %74 = load i32, ptr %4, align 4, !tbaa !5
  %75 = add nsw i32 %74, 1
  store i32 %75, ptr %4, align 4, !tbaa !5
  br label %8, !llvm.loop !12

76:                                               ; preds = %13
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN6matrix4initEv(ptr noundef nonnull align 4 dereferenceable(2704)) #1 align 2

; 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

attributes #0 = { 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 #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 }

!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}
!12 = distinct !{!12, !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"

%struct.matrix = type { [26 x [26 x i32]] }

@mod = external dso_local local_unnamed_addr global i32, align 4
@sz = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Zml6matrixS_(ptr dead_on_unwind noalias nonnull writable sret(%struct.matrix) align 4 %0, ptr nocapture noundef readonly byval(%struct.matrix) align 8 %1, ptr nocapture noundef readonly byval(%struct.matrix) align 8 %2) local_unnamed_addr #0 {
  tail call void @_ZN6matrix4initEv(ptr noundef nonnull align 4 dereferenceable(2704) %0)
  %4 = load i32, ptr @sz, align 4, !tbaa !5
  %.not24 = icmp slt i32 %4, 0
  br i1 %.not24, label %._crit_edge26, label %.preheader18.lr.ph

.preheader18.lr.ph:                               ; preds = %3
  %5 = load i32, ptr @mod, align 4
  %6 = add nuw i32 %4, 2
  %wide.trip.count36 = zext i32 %6 to i64
  %7 = add nsw i64 %wide.trip.count36, -1
  %xtraiter = and i64 %7, 1
  %8 = icmp eq i32 %4, 0
  %unroll_iter = and i64 %7, -2
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br label %.preheader18

.preheader18:                                     ; preds = %.preheader18.lr.ph, %._crit_edge23.split
  %indvars.iv33 = phi i64 [ 1, %.preheader18.lr.ph ], [ %indvars.iv.next34, %._crit_edge23.split ]
  br label %.preheader

._crit_edge26:                                    ; preds = %._crit_edge23.split, %3
  ret void

.preheader:                                       ; preds = %.preheader18, %._crit_edge
  %indvars.iv28 = phi i64 [ 1, %.preheader18 ], [ %indvars.iv.next29, %._crit_edge ]
  %9 = getelementptr inbounds [26 x [26 x i32]], ptr %0, i64 0, i64 %indvars.iv33, i64 %indvars.iv28
  %.promoted = load i32, ptr %9, align 4, !tbaa !5
  br i1 %8, label %._crit_edge.unr-lcssa, label %.preheader.new

._crit_edge23.split:                              ; preds = %._crit_edge
  %indvars.iv.next34 = add nuw nsw i64 %indvars.iv33, 1
  %exitcond37 = icmp eq i64 %indvars.iv.next34, %wide.trip.count36
  br i1 %exitcond37, label %._crit_edge26, label %.preheader18, !llvm.loop !9

._crit_edge.unr-lcssa:                            ; preds = %.preheader.new, %.preheader
  %.lcssa.ph = phi i32 [ poison, %.preheader ], [ %31, %.preheader.new ]
  %indvars.iv.unr = phi i64 [ 1, %.preheader ], [ %indvars.iv.next.1, %.preheader.new ]
  %.unr = phi i32 [ %.promoted, %.preheader ], [ %31, %.preheader.new ]
  br i1 %lcmp.mod.not, label %._crit_edge, label %._crit_edge.epilog-lcssa

._crit_edge.epilog-lcssa:                         ; preds = %._crit_edge.unr-lcssa
  %10 = getelementptr inbounds [26 x [26 x i32]], ptr %1, i64 0, i64 %indvars.iv33, i64 %indvars.iv.unr
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %12 = getelementptr inbounds [26 x [26 x i32]], ptr %2, i64 0, i64 %indvars.iv.unr, i64 %indvars.iv28
  %13 = load i32, ptr %12, align 4, !tbaa !5
  %14 = mul nsw i32 %13, %11
  %15 = add nsw i32 %.unr, %14
  %16 = srem i32 %15, %5
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.unr-lcssa, %._crit_edge.epilog-lcssa
  %.lcssa = phi i32 [ %.lcssa.ph, %._crit_edge.unr-lcssa ], [ %16, %._crit_edge.epilog-lcssa ]
  store i32 %.lcssa, ptr %9, align 4, !tbaa !5
  %indvars.iv.next29 = add nuw nsw i64 %indvars.iv28, 1
  %exitcond32 = icmp eq i64 %indvars.iv.next29, %wide.trip.count36
  br i1 %exitcond32, label %._crit_edge23.split, label %.preheader, !llvm.loop !11

.preheader.new:                                   ; preds = %.preheader, %.preheader.new
  %indvars.iv = phi i64 [ %indvars.iv.next.1, %.preheader.new ], [ 1, %.preheader ]
  %17 = phi i32 [ %31, %.preheader.new ], [ %.promoted, %.preheader ]
  %niter = phi i64 [ %niter.next.1, %.preheader.new ], [ 0, %.preheader ]
  %18 = getelementptr inbounds [26 x [26 x i32]], ptr %1, i64 0, i64 %indvars.iv33, i64 %indvars.iv
  %19 = load i32, ptr %18, align 4, !tbaa !5
  %20 = getelementptr inbounds [26 x [26 x i32]], ptr %2, i64 0, i64 %indvars.iv, i64 %indvars.iv28
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = mul nsw i32 %21, %19
  %23 = add nsw i32 %17, %22
  %24 = srem i32 %23, %5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %25 = getelementptr inbounds [26 x [26 x i32]], ptr %1, i64 0, i64 %indvars.iv33, i64 %indvars.iv.next
  %26 = load i32, ptr %25, align 4, !tbaa !5
  %27 = getelementptr inbounds [26 x [26 x i32]], ptr %2, i64 0, i64 %indvars.iv.next, i64 %indvars.iv28
  %28 = load i32, ptr %27, align 4, !tbaa !5
  %29 = mul nsw i32 %28, %26
  %30 = add nsw i32 %24, %29
  %31 = srem i32 %30, %5
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.unr-lcssa, label %.preheader.new, !llvm.loop !12
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN6matrix4initEv(ptr noundef nonnull align 4 dereferenceable(2704)) local_unnamed_addr #0 align 2

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

!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}
!12 = distinct !{!12, !10}


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