; LLVM IR from lzyrapx/Competitive-Programming :: LibreOJ/2002（容斥+dp+矩阵快速幂）.ll (Z8multipow6matrixi)

; 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 { [110 x [110 x i32]] }

@p = external dso_local global i32, align 4
@ans = external dso_local global %struct.matrix, align 4

; Function Attrs: mustprogress uwtable
define dso_local void @_Z8multipow6matrixi(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 @llvm.memset.p0.i64(ptr align 4 @ans, i8 0, i64 48400, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %12

12:                                               ; preds = %24, %3
  %13 = load i32, ptr %5, align 4, !tbaa !5
  %14 = load i32, ptr @p, align 4, !tbaa !5
  %15 = icmp slt i32 %13, %14
  br i1 %15, label %17, label %16

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

17:                                               ; preds = %12
  %18 = load i32, ptr %5, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [110 x [110 x i32]], ptr @ans, i64 0, i64 %19
  %21 = load i32, ptr %5, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [110 x i32], ptr %20, i64 0, i64 %22
  store i32 1, ptr %23, align 4, !tbaa !5
  br label %24

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

27:                                               ; preds = %16
  br label %28

28:                                               ; preds = %36, %27
  %29 = load i32, ptr %4, align 4, !tbaa !5
  %30 = icmp ne i32 %29, 0
  br i1 %30, label %31, label %39

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

35:                                               ; preds = %31
  call void @llvm.lifetime.start.p0(i64 48400, ptr %6) #5
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %7, ptr align 4 @ans, i64 48400, i1 false), !tbaa.struct !11
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %8, ptr align 8 %1, i64 48400, 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 @ans, ptr align 4 %6, i64 48400, i1 false), !tbaa.struct !11
  call void @llvm.lifetime.end.p0(i64 48400, ptr %6) #5
  br label %36

36:                                               ; preds = %35, %31
  %37 = load i32, ptr %4, align 4, !tbaa !5
  %38 = ashr i32 %37, 1
  store i32 %38, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 48400, ptr %9) #5
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %10, ptr align 8 %1, i64 48400, i1 false), !tbaa.struct !11
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %11, ptr align 8 %1, i64 48400, 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 48400, i1 false), !tbaa.struct !11
  call void @llvm.lifetime.end.p0(i64 48400, ptr %9) #5
  br label %28, !llvm.loop !13

39:                                               ; preds = %28
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %0, ptr align 4 @ans, i64 48400, i1 false), !tbaa.struct !11
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

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

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

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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { 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 48400, !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 { [110 x [110 x i32]] }

@p = external dso_local local_unnamed_addr global i32, align 4
@ans = external dso_local local_unnamed_addr global %struct.matrix, align 4

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z8multipow6matrixi(ptr dead_on_unwind noalias nocapture writable writeonly 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 @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(48400) @ans, i8 0, i64 48400, i1 false)
  %7 = load i32, ptr @p, align 4, !tbaa !5
  %8 = icmp sgt i32 %7, 0
  br i1 %8, label %.lr.ph.preheader, label %.preheader

.lr.ph.preheader:                                 ; preds = %3
  %wide.trip.count = zext nneg i32 %7 to i64
  %xtraiter = and i64 %wide.trip.count, 3
  %9 = icmp ult i32 %7, 4
  br i1 %9, label %.preheader.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %wide.trip.count, 2147483644
  br label %.lr.ph

.preheader.loopexit.unr-lcssa:                    ; preds = %.lr.ph, %.lr.ph.preheader
  %indvars.iv.unr = phi i64 [ 0, %.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 ]
  %10 = getelementptr inbounds [110 x [110 x i32]], ptr @ans, i64 0, i64 %indvars.iv.epil, i64 %indvars.iv.epil
  store i32 1, ptr %10, 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
  %.not10 = icmp eq i32 %2, 0
  br i1 %.not10, label %._crit_edge, label %.lr.ph12

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader.new ], [ %indvars.iv.next.3, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.3, %.lr.ph ]
  %11 = getelementptr inbounds [110 x [110 x i32]], ptr @ans, i64 0, i64 %indvars.iv, i64 %indvars.iv
  store i32 1, ptr %11, align 4, !tbaa !5
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %12 = getelementptr inbounds [110 x [110 x i32]], ptr @ans, i64 0, i64 %indvars.iv.next, i64 %indvars.iv.next
  store i32 1, ptr %12, align 4, !tbaa !5
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %13 = getelementptr inbounds [110 x [110 x i32]], ptr @ans, i64 0, i64 %indvars.iv.next.1, i64 %indvars.iv.next.1
  store i32 1, ptr %13, align 4, !tbaa !5
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %14 = getelementptr inbounds [110 x [110 x i32]], ptr @ans, i64 0, i64 %indvars.iv.next.2, i64 %indvars.iv.next.2
  store i32 1, ptr %14, 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, %17
  %.0711 = phi i32 [ %18, %17 ], [ %2, %.preheader ]
  %15 = and i32 %.0711, 1
  %.not8 = icmp eq i32 %15, 0
  br i1 %.not8, label %17, label %16

16:                                               ; preds = %.lr.ph12
  call void @llvm.lifetime.start.p0(i64 48400, ptr nonnull %4) #4
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(48400) %5, ptr noundef nonnull align 4 dereferenceable(48400) @ans, i64 48400, 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(48400) @ans, ptr noundef nonnull align 4 dereferenceable(48400) %4, i64 48400, i1 false), !tbaa.struct !13
  call void @llvm.lifetime.end.p0(i64 48400, ptr nonnull %4) #4
  br label %17

17:                                               ; preds = %16, %.lr.ph12
  %18 = ashr i32 %.0711, 1
  call void @llvm.lifetime.start.p0(i64 48400, 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(48400) %1, ptr noundef nonnull align 4 dereferenceable(48400) %6, i64 48400, i1 false), !tbaa.struct !13
  call void @llvm.lifetime.end.p0(i64 48400, ptr nonnull %6) #4
  %.not = icmp ult i32 %.0711, 2
  br i1 %.not, label %._crit_edge, label %.lr.ph12, !llvm.loop !15

._crit_edge:                                      ; preds = %17, %.preheader
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(48400) %0, ptr noundef nonnull align 4 dereferenceable(48400) @ans, i64 48400, i1 false), !tbaa.struct !13
  ret void
}

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

; 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 nounwind 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 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 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: write) }
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 48400, !14}
!14 = !{!7, !7, i64 0}
!15 = distinct !{!15, !12}


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