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

; 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]] }

@sz = external dso_local global i32, align 4

; Function Attrs: mustprogress uwtable
declare dso_local void @_Zml6matrixS_(ptr dead_on_unwind noalias writable sret(%struct.matrix) align 4, ptr noundef byval(%struct.matrix) align 8, ptr noundef byval(%struct.matrix) align 8) #0

; 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

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

12:                                               ; preds = %26, %3
  %13 = load i32, ptr %5, align 4, !tbaa !5
  %14 = load i32, ptr @sz, align 4, !tbaa !5
  %15 = add nsw i32 %14, 1
  %16 = icmp sle i32 %13, %15
  br i1 %16, label %18, label %17

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

18:                                               ; preds = %12
  %19 = getelementptr inbounds %struct.matrix, ptr %0, i32 0, i32 0
  %20 = load i32, ptr %5, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [26 x [26 x i32]], ptr %19, i64 0, i64 %21
  %23 = load i32, ptr %5, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [26 x i32], ptr %22, i64 0, i64 %24
  store i32 1, ptr %25, align 4, !tbaa !5
  br label %26

26:                                               ; preds = %18
  %27 = load i32, ptr %5, align 4, !tbaa !5
  %28 = add nsw i32 %27, 1
  store i32 %28, ptr %5, align 4, !tbaa !5
  br label %12, !llvm.loop !9

29:                                               ; preds = %17
  br label %30

30:                                               ; preds = %38, %29
  %31 = load i32, ptr %4, align 4, !tbaa !5
  %32 = icmp sgt i32 %31, 0
  br i1 %32, label %33, label %41

33:                                               ; preds = %30
  %34 = load i32, ptr %4, align 4, !tbaa !5
  %35 = and i32 %34, 1
  %36 = icmp ne i32 %35, 0
  br i1 %36, label %37, label %38

37:                                               ; preds = %33
  call void @llvm.lifetime.start.p0(i64 2704, ptr %6) #4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %7, ptr align 4 %0, i64 2704, i1 false), !tbaa.struct !11
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %8, ptr align 8 %1, i64 2704, i1 false), !tbaa.struct !11
  call void @_Zml6matrixS_(ptr dead_on_unwind writable sret(%struct.matrix) align 4 %6, ptr noundef byval(%struct.matrix) align 8 %7, ptr noundef byval(%struct.matrix) align 8 %8)
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %0, ptr align 4 %6, i64 2704, i1 false), !tbaa.struct !11
  call void @llvm.lifetime.end.p0(i64 2704, ptr %6) #4
  br label %38

38:                                               ; preds = %37, %33
  %39 = load i32, ptr %4, align 4, !tbaa !5
  %40 = ashr i32 %39, 1
  store i32 %40, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 2704, ptr %9) #4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %10, ptr align 8 %1, i64 2704, i1 false), !tbaa.struct !11
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %11, ptr align 8 %1, i64 2704, i1 false), !tbaa.struct !11
  call void @_Zml6matrixS_(ptr dead_on_unwind writable sret(%struct.matrix) align 4 %9, ptr noundef byval(%struct.matrix) align 8 %10, ptr noundef byval(%struct.matrix) align 8 %11)
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %1, ptr align 4 %9, i64 2704, i1 false), !tbaa.struct !11
  call void @llvm.lifetime.end.p0(i64 2704, ptr %9) #4
  br label %30, !llvm.loop !13

41:                                               ; preds = %30
  ret void
}

; 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) #3

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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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 = !{i64 0, i64 2704, !12}
!12 = !{!7, !7, i64 0}
!13 = distinct !{!13, !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]] }

@sz = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress uwtable
declare dso_local void @_Zml6matrixS_(ptr dead_on_unwind noalias writable sret(%struct.matrix) align 4, ptr noundef byval(%struct.matrix) align 8, ptr noundef byval(%struct.matrix) align 8) local_unnamed_addr #0

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #2

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #2

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

.lr.ph.preheader:                                 ; preds = %3
  %8 = add nuw i32 %7, 1
  %9 = zext i32 %8 to i64
  %xtraiter = and i64 %9, 3
  %10 = icmp ult i32 %7, 3
  br i1 %10, label %.preheader.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %9, 4294967292
  br label %.lr.ph

.preheader.loopexit.unr-lcssa:                    ; preds = %.lr.ph, %.lr.ph.preheader
  %indvars.iv.unr = phi i64 [ 1, %.lr.ph.preheader ], [ %indvars.iv.next.3, %.lr.ph ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.preheader, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %.preheader.loopexit.unr-lcssa, %.lr.ph.epil
  %indvars.iv.epil = phi i64 [ %indvars.iv.next.epil, %.lr.ph.epil ], [ %indvars.iv.unr, %.preheader.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.lr.ph.epil ], [ 0, %.preheader.loopexit.unr-lcssa ]
  %11 = getelementptr inbounds [26 x [26 x i32]], ptr %0, i64 0, i64 %indvars.iv.epil, i64 %indvars.iv.epil
  store i32 1, ptr %11, align 4, !tbaa !5
  %indvars.iv.next.epil = add nuw nsw i64 %indvars.iv.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %.preheader, label %.lr.ph.epil, !llvm.loop !9

.preheader:                                       ; preds = %.preheader.loopexit.unr-lcssa, %.lr.ph.epil, %3
  %12 = icmp sgt i32 %2, 0
  br i1 %12, label %.lr.ph12, label %._crit_edge

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %indvars.iv = phi i64 [ 1, %.lr.ph.preheader.new ], [ %indvars.iv.next.3, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.3, %.lr.ph ]
  %13 = getelementptr inbounds [26 x [26 x i32]], ptr %0, i64 0, i64 %indvars.iv, i64 %indvars.iv
  store i32 1, ptr %13, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %14 = getelementptr inbounds [26 x [26 x i32]], ptr %0, i64 0, i64 %indvars.iv.next, i64 %indvars.iv.next
  store i32 1, ptr %14, align 4, !tbaa !5
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %15 = getelementptr inbounds [26 x [26 x i32]], ptr %0, i64 0, i64 %indvars.iv.next.1, i64 %indvars.iv.next.1
  store i32 1, ptr %15, align 4, !tbaa !5
  %indvars.iv.next.2 = add nuw nsw i64 %indvars.iv, 3
  %16 = getelementptr inbounds [26 x [26 x i32]], ptr %0, i64 0, i64 %indvars.iv.next.2, i64 %indvars.iv.next.2
  store i32 1, ptr %16, align 4, !tbaa !5
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %.preheader.loopexit.unr-lcssa, label %.lr.ph, !llvm.loop !11

.lr.ph12:                                         ; preds = %.preheader, %19
  %.0711 = phi i32 [ %20, %19 ], [ %2, %.preheader ]
  %17 = and i32 %.0711, 1
  %.not8 = icmp eq i32 %17, 0
  br i1 %.not8, label %19, label %18

18:                                               ; preds = %.lr.ph12
  call void @llvm.lifetime.start.p0(i64 2704, ptr nonnull %4) #4
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(2704) %5, ptr noundef nonnull align 4 dereferenceable(2704) %0, i64 2704, i1 false), !tbaa.struct !13
  call void @_Zml6matrixS_(ptr dead_on_unwind nonnull writable sret(%struct.matrix) align 4 %4, ptr noundef nonnull byval(%struct.matrix) align 8 %5, ptr noundef nonnull byval(%struct.matrix) align 8 %1)
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(2704) %0, ptr noundef nonnull align 4 dereferenceable(2704) %4, i64 2704, i1 false), !tbaa.struct !13
  call void @llvm.lifetime.end.p0(i64 2704, ptr nonnull %4) #4
  br label %19

19:                                               ; preds = %18, %.lr.ph12
  %20 = lshr i32 %.0711, 1
  call void @llvm.lifetime.start.p0(i64 2704, ptr nonnull %6) #4
  call void @_Zml6matrixS_(ptr dead_on_unwind nonnull writable sret(%struct.matrix) align 4 %6, ptr noundef nonnull byval(%struct.matrix) align 8 %1, ptr noundef nonnull byval(%struct.matrix) align 8 %1)
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(2704) %1, ptr noundef nonnull align 4 dereferenceable(2704) %6, i64 2704, i1 false), !tbaa.struct !13
  call void @llvm.lifetime.end.p0(i64 2704, ptr nonnull %6) #4
  %.not13 = icmp ult i32 %.0711, 2
  br i1 %.not13, label %._crit_edge, label %.lr.ph12, !llvm.loop !15

._crit_edge:                                      ; preds = %19, %.preheader
  ret void
}

; 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) #3

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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.unroll.disable"}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{i64 0, i64 2704, !14}
!14 = !{!7, !7, i64 0}
!15 = distinct !{!15, !12}


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