; LLVM IR from tangjz/acm-icpc :: lydsy/3657.ll (Z4calciii)

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

@A = external dso_local global %struct.Matrix, align 4
@B = external dso_local global %struct.Matrix, align 4
@C = external dso_local global %struct.Matrix, align 4
@constinit = external hidden constant [3 x [3 x i32]], align 4

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z4calciii(i32 noundef %0, i32 noundef %1, i32 noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca %struct.Matrix, align 4
  %8 = alloca %struct.Matrix, align 4
  %9 = alloca %struct.Matrix, align 4
  %10 = alloca %struct.Matrix, align 4
  %11 = alloca %struct.Matrix, align 4
  %12 = alloca %struct.Matrix, align 4
  %13 = alloca %struct.Matrix, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 44, ptr %7) #5
  %14 = getelementptr inbounds %struct.Matrix, ptr %7, i32 0, i32 0
  store i32 2, ptr %14, align 4, !tbaa !9
  %15 = getelementptr inbounds %struct.Matrix, ptr %7, i32 0, i32 1
  store i32 2, ptr %15, align 4, !tbaa !11
  %16 = getelementptr inbounds %struct.Matrix, ptr %7, i32 0, i32 2
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %16, ptr align 4 @constinit, i64 36, i1 false), !tbaa.struct !12
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 @A, ptr align 4 %7, i64 44, i1 false), !tbaa.struct !14
  call void @llvm.lifetime.end.p0(i64 44, ptr %7) #5
  call void @llvm.lifetime.start.p0(i64 44, ptr %8) #5
  %17 = load i32, ptr %5, align 4, !tbaa !5
  call void @_ZN6Matrix3powEi(ptr dead_on_unwind writable sret(%struct.Matrix) align 4 %8, ptr noundef nonnull align 4 dereferenceable(44) @A, i32 noundef %17)
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 @B, ptr align 4 %8, i64 44, i1 false), !tbaa.struct !14
  call void @llvm.lifetime.end.p0(i64 44, ptr %8) #5
  call void @llvm.lifetime.start.p0(i64 44, ptr %9) #5
  %18 = load i32, ptr %4, align 4, !tbaa !5
  call void @_ZN6Matrix3powEi(ptr dead_on_unwind writable sret(%struct.Matrix) align 4 %9, ptr noundef nonnull align 4 dereferenceable(44) @A, i32 noundef %18)
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 @A, ptr align 4 %9, i64 44, i1 false), !tbaa.struct !14
  call void @llvm.lifetime.end.p0(i64 44, ptr %9) #5
  call void @llvm.lifetime.start.p0(i64 44, ptr %10) #5
  %19 = getelementptr inbounds %struct.Matrix, ptr %10, i32 0, i32 0
  store i32 1, ptr %19, align 4, !tbaa !9
  %20 = getelementptr inbounds %struct.Matrix, ptr %10, i32 0, i32 1
  store i32 3, ptr %20, align 4, !tbaa !11
  %21 = getelementptr inbounds %struct.Matrix, ptr %10, i32 0, i32 2
  call void @llvm.memset.p0.i64(ptr align 4 %21, i8 0, i64 36, i1 false)
  %22 = load i32, ptr getelementptr inbounds (%struct.Matrix, ptr @A, i32 0, i32 2), align 4, !tbaa !5
  store i32 %22, ptr %21, align 4, !tbaa !5
  %23 = getelementptr inbounds i32, ptr %21, i64 1
  %24 = load i32, ptr getelementptr inbounds ([3 x i32], ptr getelementptr inbounds (%struct.Matrix, ptr @A, i32 0, i32 2), i64 0, i64 1), align 4, !tbaa !5
  store i32 %24, ptr %23, align 4, !tbaa !5
  %25 = getelementptr inbounds i32, ptr %21, i64 2
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 @C, ptr align 4 %10, i64 44, i1 false), !tbaa.struct !14
  call void @llvm.lifetime.end.p0(i64 44, ptr %10) #5
  store i32 3, ptr getelementptr inbounds (%struct.Matrix, ptr @B, i32 0, i32 1), align 4, !tbaa !11
  store i32 3, ptr @B, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 44, ptr %11) #5
  %26 = getelementptr inbounds %struct.Matrix, ptr %11, i32 0, i32 0
  store i32 3, ptr %26, align 4, !tbaa !9
  %27 = getelementptr inbounds %struct.Matrix, ptr %11, i32 0, i32 1
  store i32 3, ptr %27, align 4, !tbaa !11
  %28 = getelementptr inbounds %struct.Matrix, ptr %11, i32 0, i32 2
  %29 = load i32, ptr getelementptr inbounds (%struct.Matrix, ptr @B, i32 0, i32 2), align 4, !tbaa !5
  store i32 %29, ptr %28, align 4, !tbaa !5
  %30 = getelementptr inbounds i32, ptr %28, i64 1
  %31 = load i32, ptr getelementptr inbounds ([3 x i32], ptr getelementptr inbounds (%struct.Matrix, ptr @B, i32 0, i32 2), i64 0, i64 1), align 4, !tbaa !5
  store i32 %31, ptr %30, align 4, !tbaa !5
  %32 = getelementptr inbounds i32, ptr %28, i64 2
  store i32 0, ptr %32, align 4, !tbaa !5
  %33 = getelementptr inbounds [3 x i32], ptr %28, i64 1
  %34 = load i32, ptr getelementptr inbounds ([3 x [3 x i32]], ptr getelementptr inbounds (%struct.Matrix, ptr @B, i32 0, i32 2), i64 0, i64 1), align 4, !tbaa !5
  store i32 %34, ptr %33, align 4, !tbaa !5
  %35 = getelementptr inbounds i32, ptr %33, i64 1
  %36 = load i32, ptr getelementptr inbounds ([3 x i32], ptr getelementptr inbounds ([3 x [3 x i32]], ptr getelementptr inbounds (%struct.Matrix, ptr @B, i32 0, i32 2), i64 0, i64 1), i64 0, i64 1), align 4, !tbaa !5
  store i32 %36, ptr %35, align 4, !tbaa !5
  %37 = getelementptr inbounds i32, ptr %33, i64 2
  store i32 1, ptr %37, align 4, !tbaa !5
  %38 = getelementptr inbounds [3 x i32], ptr %28, i64 2
  store i32 0, ptr %38, align 4, !tbaa !5
  %39 = getelementptr inbounds i32, ptr %38, i64 1
  store i32 0, ptr %39, align 4, !tbaa !5
  %40 = getelementptr inbounds i32, ptr %38, i64 2
  store i32 1, ptr %40, align 4, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 @B, ptr align 4 %11, i64 44, i1 false), !tbaa.struct !14
  call void @llvm.lifetime.end.p0(i64 44, ptr %11) #5
  call void @llvm.lifetime.start.p0(i64 44, ptr %12) #5
  call void @llvm.lifetime.start.p0(i64 44, ptr %13) #5
  %41 = load i32, ptr %6, align 4, !tbaa !5
  call void @_ZN6Matrix3powEi(ptr dead_on_unwind writable sret(%struct.Matrix) align 4 %13, ptr noundef nonnull align 4 dereferenceable(44) @B, i32 noundef %41)
  call void @_ZNK6MatrixmlERKS_(ptr dead_on_unwind writable sret(%struct.Matrix) align 4 %12, ptr noundef nonnull align 4 dereferenceable(44) @C, ptr noundef nonnull align 4 dereferenceable(44) %13)
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 @C, ptr align 4 %12, i64 44, i1 false), !tbaa.struct !14
  call void @llvm.lifetime.end.p0(i64 44, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 44, ptr %12) #5
  %42 = load i32, ptr getelementptr inbounds ([3 x i32], ptr getelementptr inbounds (%struct.Matrix, ptr @C, i32 0, i32 2), i64 0, i64 2), align 4, !tbaa !5
  ret i32 %42
}

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

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

; 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 @_ZN6Matrix3powEi(ptr dead_on_unwind noalias writable sret(%struct.Matrix) align 4, ptr noundef nonnull align 4 dereferenceable(44), i32 noundef) #0 align 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: 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(44), ptr noundef nonnull align 4 dereferenceable(44)) #4 align 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { 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 #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 = !{!10, !6, i64 0}
!10 = !{!"_ZTS6Matrix", !6, i64 0, !6, i64 4, !7, i64 8}
!11 = !{!10, !6, i64 4}
!12 = !{i64 0, i64 36, !13}
!13 = !{!7, !7, i64 0}
!14 = !{i64 0, i64 4, !5, i64 4, i64 4, !5, i64 8, i64 36, !13}


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

@A = external dso_local global %struct.Matrix, align 4
@B = external dso_local global %struct.Matrix, align 4
@C = external dso_local global %struct.Matrix, align 4
@constinit = external hidden local_unnamed_addr constant [3 x [3 x i32]], align 4

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z4calciii(i32 noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = alloca %struct.Matrix, align 4
  %5 = alloca %struct.Matrix, align 4
  %6 = alloca %struct.Matrix, align 4
  %7 = alloca %struct.Matrix, align 4
  store i32 2, ptr @A, align 4, !tbaa !5
  store i32 2, ptr getelementptr inbounds (i8, ptr @A, i64 4), align 4, !tbaa !5
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(36) getelementptr inbounds (i8, ptr @A, i64 8), ptr noundef nonnull align 4 dereferenceable(36) @constinit, i64 36, i1 false), !tbaa.struct !9
  call void @llvm.lifetime.start.p0(i64 44, ptr nonnull %4) #5
  call void @_ZN6Matrix3powEi(ptr dead_on_unwind nonnull writable sret(%struct.Matrix) align 4 %4, ptr noundef nonnull align 4 dereferenceable(44) @A, i32 noundef %1)
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(44) @B, ptr noundef nonnull align 4 dereferenceable(44) %4, i64 44, i1 false), !tbaa.struct !11
  call void @llvm.lifetime.end.p0(i64 44, ptr nonnull %4) #5
  call void @llvm.lifetime.start.p0(i64 44, ptr nonnull %5) #5
  call void @_ZN6Matrix3powEi(ptr dead_on_unwind nonnull writable sret(%struct.Matrix) align 4 %5, ptr noundef nonnull align 4 dereferenceable(44) @A, i32 noundef %0)
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(44) @A, ptr noundef nonnull align 4 dereferenceable(44) %5, i64 44, i1 false), !tbaa.struct !11
  call void @llvm.lifetime.end.p0(i64 44, ptr nonnull %5) #5
  store i32 1, ptr @C, align 4, !tbaa !5
  store i32 3, ptr getelementptr inbounds (i8, ptr @C, i64 4), align 4, !tbaa !5
  %8 = load <2 x i32>, ptr getelementptr inbounds (i8, ptr @A, i64 8), align 4, !tbaa !5
  store <2 x i32> %8, ptr getelementptr inbounds (i8, ptr @C, i64 8), align 4
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(28) getelementptr inbounds (i8, ptr @C, i64 16), i8 0, i64 28, i1 false)
  store i32 3, ptr @B, align 4, !tbaa !5
  store i32 3, ptr getelementptr inbounds (i8, ptr @B, i64 4), align 4, !tbaa !5
  store i32 0, ptr getelementptr inbounds (i8, ptr @B, i64 16), align 4
  store <4 x i32> <i32 1, i32 0, i32 0, i32 1>, ptr getelementptr inbounds (i8, ptr @B, i64 28), align 4
  call void @llvm.lifetime.start.p0(i64 44, ptr nonnull %6) #5
  call void @llvm.lifetime.start.p0(i64 44, ptr nonnull %7) #5
  call void @_ZN6Matrix3powEi(ptr dead_on_unwind nonnull writable sret(%struct.Matrix) align 4 %7, ptr noundef nonnull align 4 dereferenceable(44) @B, i32 noundef %2)
  call void @_ZNK6MatrixmlERKS_(ptr dead_on_unwind nonnull writable sret(%struct.Matrix) align 4 %6, ptr noundef nonnull align 4 dereferenceable(44) @C, ptr noundef nonnull align 4 dereferenceable(44) %7)
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(44) @C, ptr noundef nonnull align 4 dereferenceable(44) %6, i64 44, i1 false), !tbaa.struct !11
  call void @llvm.lifetime.end.p0(i64 44, ptr nonnull %7) #5
  call void @llvm.lifetime.end.p0(i64 44, ptr nonnull %6) #5
  %9 = load i32, ptr getelementptr inbounds (i8, ptr @C, i64 16), align 4, !tbaa !5
  ret i32 %9
}

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

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

; 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 @_ZN6Matrix3powEi(ptr dead_on_unwind noalias writable sret(%struct.Matrix) align 4, ptr noundef nonnull align 4 dereferenceable(44), i32 noundef) local_unnamed_addr #0 align 2

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

; 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(44), ptr noundef nonnull align 4 dereferenceable(44)) local_unnamed_addr #4 align 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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { 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 #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 = !{i64 0, i64 36, !10}
!10 = !{!7, !7, i64 0}
!11 = !{i64 0, i64 4, !5, i64 4, i64 4, !5, i64 8, i64 36, !10}


; Effective O3 passes: CorrelatedValuePropagationPass,DSEPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,MemCpyOptPass,SLPVectorizerPass,SROAPass,TailCallElimPass