; LLVM IR from tangjz/acm-icpc :: 51nod (1248)

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

@A = external dso_local global %struct.Matrix, align 4
@B = 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 [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca %struct.Matrix, align 4
  %4 = alloca i64, align 8
  %5 = alloca %struct.Matrix, align 4
  %6 = alloca %struct.Matrix, align 4
  %7 = alloca %struct.Matrix, align 4
  %8 = alloca %struct.Matrix, align 4
  %9 = alloca %struct.Matrix, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #7
  %10 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %2)
  call void @llvm.lifetime.start.p0(i64 24, ptr %3) #7
  %11 = getelementptr inbounds %struct.Matrix, ptr %3, i32 0, i32 0
  store i32 1, ptr %11, align 4, !tbaa !5
  %12 = getelementptr inbounds %struct.Matrix, ptr %3, i32 0, i32 1
  store i32 2, ptr %12, align 4, !tbaa !10
  %13 = getelementptr inbounds %struct.Matrix, ptr %3, i32 0, i32 2
  store i32 1, ptr %13, align 4, !tbaa !11
  %14 = getelementptr inbounds i32, ptr %13, i64 1
  store i32 3, ptr %14, align 4, !tbaa !11
  %15 = getelementptr inbounds [2 x i32], ptr %13, i64 1
  %16 = getelementptr inbounds [2 x i32], ptr %13, i64 2
  br label %17

17:                                               ; preds = %17, %0
  %18 = phi ptr [ %15, %0 ], [ %19, %17 ]
  call void @llvm.memset.p0.i64(ptr align 4 %18, i8 0, i64 8, i1 false)
  %19 = getelementptr inbounds [2 x i32], ptr %18, i64 1
  %20 = icmp eq ptr %19, %16
  br i1 %20, label %21, label %17

21:                                               ; preds = %17
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 @A, ptr align 4 %3, i64 24, i1 false), !tbaa.struct !12
  call void @llvm.lifetime.end.p0(i64 24, ptr %3) #7
  br label %22

22:                                               ; preds = %26, %21
  %23 = load i32, ptr %2, align 4, !tbaa !11
  %24 = add nsw i32 %23, -1
  store i32 %24, ptr %2, align 4, !tbaa !11
  %25 = icmp ne i32 %23, 0
  br i1 %25, label %26, label %45

26:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #7
  %27 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %4)
  call void @llvm.lifetime.start.p0(i64 24, ptr %5) #7
  call void @llvm.lifetime.start.p0(i64 24, ptr %6) #7
  %28 = getelementptr inbounds %struct.Matrix, ptr %6, i32 0, i32 0
  store i32 2, ptr %28, align 4, !tbaa !5
  %29 = getelementptr inbounds %struct.Matrix, ptr %6, i32 0, i32 1
  store i32 2, ptr %29, align 4, !tbaa !10
  %30 = getelementptr inbounds %struct.Matrix, ptr %6, i32 0, i32 2
  store i32 0, ptr %30, align 4, !tbaa !11
  %31 = getelementptr inbounds i32, ptr %30, i64 1
  store i32 1000000006, ptr %31, align 4, !tbaa !11
  %32 = getelementptr inbounds [2 x i32], ptr %30, i64 1
  store i32 1, ptr %32, align 4, !tbaa !11
  %33 = getelementptr inbounds i32, ptr %32, i64 1
  store i32 6, ptr %33, align 4, !tbaa !11
  %34 = load i64, ptr %4, align 8, !tbaa !14
  call void @_ZNK6Matrix3powEx(ptr dead_on_unwind writable sret(%struct.Matrix) align 4 %5, ptr noundef nonnull align 4 dereferenceable(24) %6, i64 noundef %34)
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 @B, ptr align 4 %5, i64 24, i1 false), !tbaa.struct !12
  call void @llvm.lifetime.end.p0(i64 24, ptr %6) #7
  call void @llvm.lifetime.end.p0(i64 24, ptr %5) #7
  call void @llvm.lifetime.start.p0(i64 24, ptr %7) #7
  call void @llvm.lifetime.start.p0(i64 24, ptr %8) #7
  %35 = getelementptr inbounds %struct.Matrix, ptr %8, i32 0, i32 0
  store i32 2, ptr %35, align 4, !tbaa !5
  %36 = getelementptr inbounds %struct.Matrix, ptr %8, i32 0, i32 1
  store i32 2, ptr %36, align 4, !tbaa !10
  %37 = getelementptr inbounds %struct.Matrix, ptr %8, i32 0, i32 2
  %38 = load i32, ptr getelementptr inbounds ([2 x i32], ptr getelementptr inbounds ([2 x [2 x i32]], ptr getelementptr inbounds (%struct.Matrix, ptr @B, i32 0, i32 2), i64 0, i64 1), i64 0, i64 1), align 4, !tbaa !11
  store i32 %38, ptr %37, align 4, !tbaa !11
  %39 = getelementptr inbounds i32, ptr %37, i64 1
  %40 = load i32, ptr getelementptr inbounds ([2 x [2 x i32]], ptr getelementptr inbounds (%struct.Matrix, ptr @B, i32 0, i32 2), i64 0, i64 1), align 4, !tbaa !11
  store i32 %40, ptr %39, align 4, !tbaa !11
  %41 = getelementptr inbounds [2 x i32], ptr %37, i64 1
  %42 = load i32, ptr getelementptr inbounds ([2 x i32], ptr getelementptr inbounds (%struct.Matrix, ptr @B, i32 0, i32 2), i64 0, i64 1), align 4, !tbaa !11
  store i32 %42, ptr %41, align 4, !tbaa !11
  %43 = getelementptr inbounds i32, ptr %41, i64 1
  %44 = load i32, ptr getelementptr inbounds (%struct.Matrix, ptr @B, i32 0, i32 2), align 4, !tbaa !11
  store i32 %44, ptr %43, align 4, !tbaa !11
  call void @_ZNK6MatrixplERKS_(ptr dead_on_unwind writable sret(%struct.Matrix) align 4 %7, ptr noundef nonnull align 4 dereferenceable(24) @B, ptr noundef nonnull align 4 dereferenceable(24) %8)
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 @B, ptr align 4 %7, i64 24, i1 false), !tbaa.struct !12
  call void @llvm.lifetime.end.p0(i64 24, ptr %8) #7
  call void @llvm.lifetime.end.p0(i64 24, ptr %7) #7
  call void @llvm.lifetime.start.p0(i64 24, ptr %9) #7
  call void @_ZNK6MatrixmlERKS_(ptr dead_on_unwind writable sret(%struct.Matrix) align 4 %9, ptr noundef nonnull align 4 dereferenceable(24) @A, ptr noundef nonnull align 4 dereferenceable(24) @B)
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 @A, ptr align 4 %9, i64 24, i1 false), !tbaa.struct !12
  call void @llvm.lifetime.end.p0(i64 24, ptr %9) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #7
  br label %22, !llvm.loop !16

45:                                               ; preds = %22
  %46 = load i32, ptr getelementptr inbounds (%struct.Matrix, ptr @A, i32 0, i32 2), align 4, !tbaa !11
  %47 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %46)
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #7
  ret i32 0
}

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

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #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

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

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

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

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

declare i32 @printf(ptr noundef, ...) #2

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 #3 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { 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 #6 = { 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 #7 = { 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 0}
!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 4}
!11 = !{!7, !7, i64 0}
!12 = !{i64 0, i64 4, !11, i64 4, i64 4, !11, i64 8, i64 16, !13}
!13 = !{!8, !8, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"long long", !8, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


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

@A = external dso_local global %struct.Matrix, align 4
@B = 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 [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca i32, align 4
  %2 = alloca i64, align 8
  %3 = alloca %struct.Matrix, align 4
  %4 = alloca %struct.Matrix, align 16
  %5 = alloca %struct.Matrix, align 4
  %6 = alloca %struct.Matrix, align 4
  %7 = alloca %struct.Matrix, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #6
  %8 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  store <4 x i32> <i32 1, i32 2, i32 1, i32 3>, ptr @A, align 4
  store i64 0, ptr getelementptr inbounds (i8, ptr @A, i64 16), align 4, !tbaa !5
  %9 = load i32, ptr %1, align 4, !tbaa !8
  %10 = add nsw i32 %9, -1
  store i32 %10, ptr %1, align 4, !tbaa !8
  %.not3 = icmp eq i32 %9, 0
  br i1 %.not3, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %0
  %11 = getelementptr inbounds i8, ptr %4, i64 16
  %12 = getelementptr inbounds i8, ptr %4, i64 20
  %13 = getelementptr inbounds i8, ptr %6, i64 4
  %14 = getelementptr inbounds i8, ptr %6, i64 8
  br label %15

15:                                               ; preds = %.lr.ph, %15
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #6
  %16 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %2)
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %3) #6
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %4) #6
  store <4 x i32> <i32 2, i32 2, i32 0, i32 1000000006>, ptr %4, align 16, !tbaa !8
  store i32 1, ptr %11, align 16, !tbaa !8
  store i32 6, ptr %12, align 4, !tbaa !8
  %17 = load i64, ptr %2, align 8, !tbaa !10
  call void @_ZNK6Matrix3powEx(ptr dead_on_unwind nonnull writable sret(%struct.Matrix) align 4 %3, ptr noundef nonnull align 4 dereferenceable(24) %4, i64 noundef %17)
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(24) @B, ptr noundef nonnull align 4 dereferenceable(24) %3, i64 24, i1 false), !tbaa.struct !12
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %4) #6
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %3) #6
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %5) #6
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %6) #6
  store i32 2, ptr %6, align 4, !tbaa !13
  store i32 2, ptr %13, align 4, !tbaa !15
  %18 = load <4 x i32>, ptr getelementptr inbounds (i8, ptr @B, i64 8), align 4, !tbaa !8
  %19 = shufflevector <4 x i32> %18, <4 x i32> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
  store <4 x i32> %19, ptr %14, align 4, !tbaa !8
  call void @_ZNK6MatrixplERKS_(ptr dead_on_unwind nonnull writable sret(%struct.Matrix) align 4 %5, ptr noundef nonnull align 4 dereferenceable(24) @B, ptr noundef nonnull align 4 dereferenceable(24) %6)
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(24) @B, ptr noundef nonnull align 4 dereferenceable(24) %5, i64 24, i1 false), !tbaa.struct !12
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %6) #6
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %5) #6
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %7) #6
  call void @_ZNK6MatrixmlERKS_(ptr dead_on_unwind nonnull writable sret(%struct.Matrix) align 4 %7, ptr noundef nonnull align 4 dereferenceable(24) @A, ptr noundef nonnull align 4 dereferenceable(24) @B)
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(24) @A, ptr noundef nonnull align 4 dereferenceable(24) %7, i64 24, i1 false), !tbaa.struct !12
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %7) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #6
  %20 = load i32, ptr %1, align 4, !tbaa !8
  %21 = add nsw i32 %20, -1
  store i32 %21, ptr %1, align 4, !tbaa !8
  %.not = icmp eq i32 %20, 0
  br i1 %.not, label %._crit_edge.loopexit, label %15, !llvm.loop !16

._crit_edge.loopexit:                             ; preds = %15
  %.pre = load i32, ptr getelementptr inbounds (i8, ptr @A, i64 8), align 4, !tbaa !8
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %0
  %22 = phi i32 [ %.pre, %._crit_edge.loopexit ], [ 1, %0 ]
  %23 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %22)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #6
  ret i32 0
}

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

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

; 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

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

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

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

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

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

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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 #5 = { 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 #6 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"int", !6, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"long long", !6, i64 0}
!12 = !{i64 0, i64 4, !8, i64 4, i64 4, !8, i64 8, i64 16, !5}
!13 = !{!14, !9, i64 0}
!14 = !{!"_ZTS6Matrix", !9, i64 0, !9, i64 4, !6, i64 8}
!15 = !{!14, !9, i64 4}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopRotatePass,LoopSimplifyPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass