; LLVM IR from tangjz/acm-icpc :: lydsy (3328)

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

@t = external dso_local global i32, align 4
@len = external dso_local global i32, align 4
@mod = external dso_local global i32, align 4
@ans = external dso_local global i32, align 4
@n = external dso_local global i64, align 8
@A = external dso_local global %struct.Matrix, align 4
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z7mod_invi(i32 noundef) #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z7mod_powii(i32 noundef, i32 noundef) #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 noundef i32 @_Z6originv() #1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #3 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca %struct.Matrix, align 4
  %6 = alloca %struct.Matrix, align 4
  %7 = alloca %struct.Matrix, align 4
  store i32 0, ptr %1, align 4
  store i32 2, ptr getelementptr inbounds (%struct.Matrix, ptr @A, i32 0, i32 1), align 4, !tbaa !5
  store i32 2, ptr @A, align 4, !tbaa !10
  store i32 1, ptr getelementptr inbounds ([2 x i32], ptr getelementptr inbounds ([2 x [2 x i32]], ptr getelementptr inbounds (%struct.Matrix, ptr @A, i32 0, i32 2), i64 0, i64 1), i64 0, i64 1), align 4, !tbaa !11
  store i32 1, ptr getelementptr inbounds ([2 x [2 x i32]], ptr getelementptr inbounds (%struct.Matrix, ptr @A, i32 0, i32 2), i64 0, i64 1), align 4, !tbaa !11
  store i32 1, ptr getelementptr inbounds ([2 x i32], ptr getelementptr inbounds (%struct.Matrix, ptr @A, i32 0, i32 2), i64 0, i64 1), align 4, !tbaa !11
  %8 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @t)
  br label %9

9:                                                ; preds = %53, %0
  %10 = load i32, ptr @t, align 4, !tbaa !11
  %11 = add nsw i32 %10, -1
  store i32 %11, ptr @t, align 4, !tbaa !11
  %12 = icmp ne i32 %10, 0
  br i1 %12, label %13, label %66

13:                                               ; preds = %9
  store i32 0, ptr @ans, align 4, !tbaa !11
  %14 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef @n, ptr noundef @len, ptr noundef @mod)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  store i32 0, ptr %2, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  %15 = call noundef i32 @_Z6originv()
  %16 = load i32, ptr @mod, align 4, !tbaa !11
  %17 = sub nsw i32 %16, 1
  %18 = load i32, ptr @len, align 4, !tbaa !11
  %19 = sdiv i32 %17, %18
  %20 = call noundef i32 @_Z7mod_powii(i32 noundef %15, i32 noundef %19)
  store i32 %20, ptr %3, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  store i32 1, ptr %4, align 4, !tbaa !11
  br label %21

21:                                               ; preds = %41, %13
  %22 = load i32, ptr %2, align 4, !tbaa !11
  %23 = load i32, ptr @len, align 4, !tbaa !11
  %24 = icmp slt i32 %22, %23
  br i1 %24, label %26, label %25

25:                                               ; preds = %21
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  br label %53

26:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 24, ptr %5) #5
  call void @llvm.lifetime.start.p0(i64 24, ptr %6) #5
  call void @llvm.lifetime.start.p0(i64 24, ptr %7) #5
  call void @_ZNK6MatrixmlERKi(ptr dead_on_unwind writable sret(%struct.Matrix) align 4 %7, ptr noundef nonnull align 4 dereferenceable(24) @A, ptr noundef nonnull align 4 dereferenceable(4) %4)
  call void @_ZN6Matrix3incEv(ptr dead_on_unwind writable sret(%struct.Matrix) align 4 %6, ptr noundef nonnull align 4 dereferenceable(24) %7)
  %27 = load i64, ptr @n, align 8, !tbaa !12
  call void @_ZN6Matrix3powEx(ptr dead_on_unwind writable sret(%struct.Matrix) align 4 %5, ptr noundef nonnull align 4 dereferenceable(24) %6, i64 noundef %27)
  %28 = getelementptr inbounds %struct.Matrix, ptr %5, i32 0, i32 2
  %29 = getelementptr inbounds [2 x [2 x i32]], ptr %28, i64 0, i64 1
  %30 = getelementptr inbounds [2 x i32], ptr %29, i64 0, i64 1
  %31 = load i32, ptr %30, align 4, !tbaa !11
  %32 = load i32, ptr @ans, align 4, !tbaa !11
  %33 = add nsw i32 %32, %31
  store i32 %33, ptr @ans, align 4, !tbaa !11
  %34 = load i32, ptr @mod, align 4, !tbaa !11
  %35 = icmp sge i32 %33, %34
  call void @llvm.lifetime.end.p0(i64 24, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 24, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 24, ptr %5) #5
  br i1 %35, label %36, label %40

36:                                               ; preds = %26
  %37 = load i32, ptr @mod, align 4, !tbaa !11
  %38 = load i32, ptr @ans, align 4, !tbaa !11
  %39 = sub nsw i32 %38, %37
  store i32 %39, ptr @ans, align 4, !tbaa !11
  br label %40

40:                                               ; preds = %36, %26
  br label %41

41:                                               ; preds = %40
  %42 = load i32, ptr %2, align 4, !tbaa !11
  %43 = add nsw i32 %42, 1
  store i32 %43, ptr %2, align 4, !tbaa !11
  %44 = load i32, ptr %4, align 4, !tbaa !11
  %45 = sext i32 %44 to i64
  %46 = load i32, ptr %3, align 4, !tbaa !11
  %47 = sext i32 %46 to i64
  %48 = mul nsw i64 %45, %47
  %49 = load i32, ptr @mod, align 4, !tbaa !11
  %50 = sext i32 %49 to i64
  %51 = srem i64 %48, %50
  %52 = trunc i64 %51 to i32
  store i32 %52, ptr %4, align 4, !tbaa !11
  br label %21, !llvm.loop !14

53:                                               ; preds = %25
  %54 = load i32, ptr @ans, align 4, !tbaa !11
  %55 = sext i32 %54 to i64
  %56 = load i32, ptr @len, align 4, !tbaa !11
  %57 = call noundef i32 @_Z7mod_invi(i32 noundef %56)
  %58 = sext i32 %57 to i64
  %59 = mul nsw i64 %55, %58
  %60 = load i32, ptr @mod, align 4, !tbaa !11
  %61 = sext i32 %60 to i64
  %62 = srem i64 %59, %61
  %63 = trunc i64 %62 to i32
  store i32 %63, ptr @ans, align 4, !tbaa !11
  %64 = load i32, ptr @ans, align 4, !tbaa !11
  %65 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %64)
  br label %9, !llvm.loop !16

66:                                               ; preds = %9
  ret i32 0
}

declare i32 @__isoc99_scanf(ptr noundef, ...) #4

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNK6MatrixmlERKi(ptr dead_on_unwind noalias writable sret(%struct.Matrix) align 4, ptr noundef nonnull align 4 dereferenceable(24), ptr noundef nonnull align 4 dereferenceable(4)) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN6Matrix3incEv(ptr dead_on_unwind noalias writable sret(%struct.Matrix) align 4, ptr noundef nonnull align 4 dereferenceable(24)) #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN6Matrix3powEx(ptr dead_on_unwind noalias writable sret(%struct.Matrix) align 4, ptr noundef nonnull align 4 dereferenceable(24), i64 noundef) #0 align 2

declare i32 @printf(ptr noundef, ...) #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 = { 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 = { mustprogress norecurse 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 = { "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 #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, !7, i64 4}
!6 = !{!"_ZTS6Matrix", !7, i64 0, !7, i64 4, !8, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!6, !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"long long", !8, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}


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

@t = external dso_local global i32, align 4
@len = external dso_local global i32, align 4
@mod = external dso_local global i32, align 4
@ans = external dso_local local_unnamed_addr global i32, align 4
@n = external dso_local global i64, align 8
@A = external dso_local global %struct.Matrix, align 4
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z7mod_powii(i32 noundef, i32 noundef) local_unnamed_addr #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 noundef i32 @_Z6originv() local_unnamed_addr #1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #3 {
  %1 = alloca i32, align 4
  %2 = alloca %struct.Matrix, align 4
  %3 = alloca %struct.Matrix, align 4
  %4 = alloca %struct.Matrix, align 4
  store i32 2, ptr getelementptr inbounds (i8, ptr @A, i64 4), align 4, !tbaa !5
  store i32 2, ptr @A, align 4, !tbaa !10
  store i32 1, ptr getelementptr inbounds (i8, ptr @A, i64 20), align 4, !tbaa !11
  store i32 1, ptr getelementptr inbounds (i8, ptr @A, i64 16), align 4, !tbaa !11
  store i32 1, ptr getelementptr inbounds (i8, ptr @A, i64 12), align 4, !tbaa !11
  %5 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @t)
  %6 = load i32, ptr @t, align 4, !tbaa !11
  %7 = add nsw i32 %6, -1
  store i32 %7, ptr @t, align 4, !tbaa !11
  %.not5 = icmp eq i32 %6, 0
  br i1 %.not5, label %._crit_edge8, label %.lr.ph7

.lr.ph7:                                          ; preds = %0
  %8 = getelementptr inbounds i8, ptr %2, i64 20
  br label %9

9:                                                ; preds = %.lr.ph7, %._crit_edge
  store i32 0, ptr @ans, align 4, !tbaa !11
  %10 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @n, ptr noundef nonnull @len, ptr noundef nonnull @mod)
  %11 = call noundef i32 @_Z6originv()
  %12 = load i32, ptr @mod, align 4, !tbaa !11
  %13 = add nsw i32 %12, -1
  %14 = load i32, ptr @len, align 4, !tbaa !11
  %15 = sdiv i32 %13, %14
  %16 = call noundef i32 @_Z7mod_powii(i32 noundef %11, i32 noundef %15)
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #5
  store i32 1, ptr %1, align 4, !tbaa !11
  %17 = load i32, ptr @len, align 4, !tbaa !11
  %18 = icmp sgt i32 %17, 0
  br i1 %18, label %.lr.ph, label %.._crit_edge_crit_edge

.._crit_edge_crit_edge:                           ; preds = %9
  %.pre = load i32, ptr @ans, align 4, !tbaa !11
  br label %._crit_edge

.lr.ph:                                           ; preds = %9
  %19 = sext i32 %16 to i64
  br label %32

._crit_edge:                                      ; preds = %40, %.._crit_edge_crit_edge
  %20 = phi i32 [ %.pre, %.._crit_edge_crit_edge ], [ %41, %40 ]
  %.lcssa = phi i32 [ %17, %.._crit_edge_crit_edge ], [ %49, %40 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #5
  %21 = sext i32 %20 to i64
  %22 = call noundef i32 @_Z7mod_invi(i32 noundef %.lcssa)
  %23 = sext i32 %22 to i64
  %24 = mul nsw i64 %23, %21
  %25 = load i32, ptr @mod, align 4, !tbaa !11
  %26 = sext i32 %25 to i64
  %27 = srem i64 %24, %26
  %28 = trunc nsw i64 %27 to i32
  store i32 %28, ptr @ans, align 4, !tbaa !11
  %29 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %28)
  %30 = load i32, ptr @t, align 4, !tbaa !11
  %31 = add nsw i32 %30, -1
  store i32 %31, ptr @t, align 4, !tbaa !11
  %.not = icmp eq i32 %30, 0
  br i1 %.not, label %._crit_edge8, label %9, !llvm.loop !12

32:                                               ; preds = %.lr.ph, %40
  %.04 = phi i32 [ 0, %.lr.ph ], [ %42, %40 ]
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %2) #5
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %3) #5
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %4) #5
  call void @_ZNK6MatrixmlERKi(ptr dead_on_unwind nonnull writable sret(%struct.Matrix) align 4 %4, ptr noundef nonnull align 4 dereferenceable(24) @A, ptr noundef nonnull align 4 dereferenceable(4) %1)
  call void @_ZN6Matrix3incEv(ptr dead_on_unwind nonnull writable sret(%struct.Matrix) align 4 %3, ptr noundef nonnull align 4 dereferenceable(24) %4)
  %33 = load i64, ptr @n, align 8, !tbaa !14
  call void @_ZN6Matrix3powEx(ptr dead_on_unwind nonnull writable sret(%struct.Matrix) align 4 %2, ptr noundef nonnull align 4 dereferenceable(24) %3, i64 noundef %33)
  %34 = load i32, ptr %8, align 4, !tbaa !11
  %35 = load i32, ptr @ans, align 4, !tbaa !11
  %36 = add nsw i32 %35, %34
  store i32 %36, ptr @ans, align 4, !tbaa !11
  %37 = load i32, ptr @mod, align 4, !tbaa !11
  %.not3 = icmp slt i32 %36, %37
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %4) #5
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %3) #5
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %2) #5
  br i1 %.not3, label %40, label %38

38:                                               ; preds = %32
  %39 = sub nsw i32 %36, %37
  store i32 %39, ptr @ans, align 4, !tbaa !11
  br label %40

40:                                               ; preds = %32, %38
  %41 = phi i32 [ %36, %32 ], [ %39, %38 ]
  %42 = add nuw nsw i32 %.04, 1
  %43 = load i32, ptr %1, align 4, !tbaa !11
  %44 = sext i32 %43 to i64
  %45 = mul nsw i64 %44, %19
  %46 = sext i32 %37 to i64
  %47 = srem i64 %45, %46
  %48 = trunc nsw i64 %47 to i32
  store i32 %48, ptr %1, align 4, !tbaa !11
  %49 = load i32, ptr @len, align 4, !tbaa !11
  %50 = icmp slt i32 %42, %49
  br i1 %50, label %32, label %._crit_edge, !llvm.loop !16

._crit_edge8:                                     ; preds = %._crit_edge, %0
  ret i32 0
}

; Function Attrs: nofree nounwind
declare noundef i32 @__isoc99_scanf(ptr nocapture noundef readonly, ...) local_unnamed_addr #4

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNK6MatrixmlERKi(ptr dead_on_unwind noalias writable sret(%struct.Matrix) align 4, ptr noundef nonnull align 4 dereferenceable(24), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN6Matrix3incEv(ptr dead_on_unwind noalias writable sret(%struct.Matrix) align 4, ptr noundef nonnull align 4 dereferenceable(24)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN6Matrix3powEx(ptr dead_on_unwind noalias writable sret(%struct.Matrix) align 4, ptr noundef nonnull align 4 dereferenceable(24), i64 noundef) local_unnamed_addr #0 align 2

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #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 = { 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 norecurse 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 = { nofree nounwind "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 #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, !7, i64 4}
!6 = !{!"_ZTS6Matrix", !7, i64 0, !7, i64 4, !8, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!6, !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!15, !15, i64 0}
!15 = !{!"long long", !8, i64 0}
!16 = distinct !{!16, !13}


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