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

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

@A = external dso_local global %struct.Matrix, align 4
@B = external dso_local global %struct.Matrix, align 4
@n = external dso_local global i64, align 8
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 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 i32, align 4
  %4 = alloca %struct.Matrix, align 4
  %5 = alloca %struct.Matrix, align 4
  store i32 0, ptr %1, align 4
  %6 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  %7 = load i64, ptr @n, align 8, !tbaa !5
  %8 = icmp sle i64 %7, 4
  br i1 %8, label %9, label %11

9:                                                ; preds = %0
  %10 = call i32 @puts(ptr noundef @.str.1)
  store i32 0, ptr %1, align 4
  br label %52

11:                                               ; preds = %0
  %12 = load i64, ptr @n, align 8, !tbaa !5
  %13 = sub nsw i64 %12, 4
  %14 = mul nsw i64 %13, 10
  store i64 %14, ptr @n, align 8, !tbaa !5
  store i32 1, ptr @A, align 4, !tbaa !9
  store i32 34, ptr getelementptr inbounds (%struct.Matrix, ptr @B, i32 0, i32 1), align 4, !tbaa !12
  store i32 34, ptr @B, align 4, !tbaa !9
  store i32 34, ptr getelementptr inbounds (%struct.Matrix, ptr @A, i32 0, i32 1), align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 0, ptr %2, align 4, !tbaa !13
  br label %15

15:                                               ; preds = %24, %11
  %16 = load i32, ptr %2, align 4, !tbaa !13
  %17 = load i32, ptr getelementptr inbounds (%struct.Matrix, ptr @A, i32 0, i32 1), align 4, !tbaa !12
  %18 = icmp slt i32 %16, %17
  br i1 %18, label %20, label %19

19:                                               ; preds = %15
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  br label %27

20:                                               ; preds = %15
  %21 = load i32, ptr %2, align 4, !tbaa !13
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [35 x i32], ptr getelementptr inbounds (%struct.Matrix, ptr @A, i32 0, i32 2), i64 0, i64 %22
  store i32 1, ptr %23, align 4, !tbaa !13
  br label %24

24:                                               ; preds = %20
  %25 = load i32, ptr %2, align 4, !tbaa !13
  %26 = add nsw i32 %25, 1
  store i32 %26, ptr %2, align 4, !tbaa !13
  br label %15, !llvm.loop !14

27:                                               ; preds = %19
  store i32 1, ptr getelementptr inbounds ([35 x [35 x i32]], ptr getelementptr inbounds (%struct.Matrix, ptr @B, i32 0, i32 2), i64 0, i64 33), align 4, !tbaa !13
  store i32 1, ptr getelementptr inbounds ([35 x [35 x i32]], ptr getelementptr inbounds (%struct.Matrix, ptr @B, i32 0, i32 2), i64 0, i64 9), align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 1, ptr %3, align 4, !tbaa !13
  br label %28

28:                                               ; preds = %41, %27
  %29 = load i32, ptr %3, align 4, !tbaa !13
  %30 = load i32, ptr @B, align 4, !tbaa !9
  %31 = icmp slt i32 %29, %30
  br i1 %31, label %33, label %32

32:                                               ; preds = %28
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  br label %44

33:                                               ; preds = %28
  %34 = load i32, ptr %3, align 4, !tbaa !13
  %35 = sub nsw i32 %34, 1
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [35 x [35 x i32]], ptr getelementptr inbounds (%struct.Matrix, ptr @B, i32 0, i32 2), i64 0, i64 %36
  %38 = load i32, ptr %3, align 4, !tbaa !13
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [35 x i32], ptr %37, i64 0, i64 %39
  store i32 1, ptr %40, align 4, !tbaa !13
  br label %41

41:                                               ; preds = %33
  %42 = load i32, ptr %3, align 4, !tbaa !13
  %43 = add nsw i32 %42, 1
  store i32 %43, ptr %3, align 4, !tbaa !13
  br label %28, !llvm.loop !16

44:                                               ; preds = %32
  call void @llvm.lifetime.start.p0(i64 4908, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 4908, ptr %5) #4
  %45 = load i64, ptr @n, align 8, !tbaa !5
  %46 = trunc i64 %45 to i32
  call void @_ZN6Matrix3powEi(ptr dead_on_unwind writable sret(%struct.Matrix) align 4 %5, ptr noundef nonnull align 4 dereferenceable(4908) @B, i32 noundef %46)
  call void @_ZNK6MatrixmlERKS_(ptr dead_on_unwind writable sret(%struct.Matrix) align 4 %4, ptr noundef nonnull align 4 dereferenceable(4908) @A, ptr noundef nonnull align 4 dereferenceable(4908) %5)
  %47 = getelementptr inbounds %struct.Matrix, ptr %4, i32 0, i32 2
  %48 = getelementptr inbounds [35 x [35 x i32]], ptr %47, i64 0, i64 0
  %49 = getelementptr inbounds [35 x i32], ptr %48, i64 0, i64 0
  %50 = load i32, ptr %49, align 4, !tbaa !13
  %51 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %50)
  call void @llvm.lifetime.end.p0(i64 4908, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4908, ptr %4) #4
  store i32 0, ptr %1, align 4
  br label %52

52:                                               ; preds = %44, %9
  %53 = load i32, ptr %1, align 4
  ret i32 %53
}

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

declare i32 @puts(ptr 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

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

; 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(4908), ptr noundef nonnull align 4 dereferenceable(4908)) #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN6Matrix3powEi(ptr dead_on_unwind noalias writable sret(%struct.Matrix) align 4, ptr noundef nonnull align 4 dereferenceable(4908), i32 noundef) #3 align 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 = { "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 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 = { 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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"_ZTS6Matrix", !11, i64 0, !11, i64 4, !7, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 4}
!13 = !{!11, !11, 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, [35 x [35 x i32]] }

@A = external dso_local global %struct.Matrix, align 4
@B = external dso_local global %struct.Matrix, align 4
@n = external dso_local global i64, align 8
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca %struct.Matrix, align 4
  %2 = alloca %struct.Matrix, align 4
  %3 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  %4 = load i64, ptr @n, align 8, !tbaa !5
  %5 = icmp slt i64 %4, 5
  br i1 %5, label %6, label %8

6:                                                ; preds = %0
  %7 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.1)
  br label %15

8:                                                ; preds = %0
  %9 = mul i64 %4, 10
  %10 = add i64 %9, -40
  store i64 %10, ptr @n, align 8, !tbaa !5
  store i32 34, ptr getelementptr inbounds (i8, ptr @B, i64 4), align 4, !tbaa !9
  store i32 34, ptr @B, align 4, !tbaa !12
  store <4 x i32> <i32 1, i32 34, i32 1, i32 1>, ptr @A, align 4, !tbaa !13
  store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, ptr getelementptr inbounds (i8, ptr @A, i64 16), align 4, !tbaa !13
  store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, ptr getelementptr inbounds (i8, ptr @A, i64 32), align 4, !tbaa !13
  store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, ptr getelementptr inbounds (i8, ptr @A, i64 48), align 4, !tbaa !13
  store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, ptr getelementptr inbounds (i8, ptr @A, i64 64), align 4, !tbaa !13
  store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, ptr getelementptr inbounds (i8, ptr @A, i64 80), align 4, !tbaa !13
  store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, ptr getelementptr inbounds (i8, ptr @A, i64 96), align 4, !tbaa !13
  store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, ptr getelementptr inbounds (i8, ptr @A, i64 112), align 4, !tbaa !13
  store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, ptr getelementptr inbounds (i8, ptr @A, i64 128), align 4, !tbaa !13
  store i32 1, ptr getelementptr inbounds (i8, ptr @B, i64 4628), align 4, !tbaa !13
  store i32 1, ptr getelementptr inbounds (i8, ptr @B, i64 1268), align 4, !tbaa !13
  store i32 1, ptr getelementptr inbounds (i8, ptr @B, i64 12), align 4, !tbaa !13
  store i32 1, ptr getelementptr inbounds (i8, ptr @B, i64 156), align 4, !tbaa !13
  store i32 1, ptr getelementptr inbounds (i8, ptr @B, i64 300), align 4, !tbaa !13
  store i32 1, ptr getelementptr inbounds (i8, ptr @B, i64 444), align 4, !tbaa !13
  store i32 1, ptr getelementptr inbounds (i8, ptr @B, i64 588), align 4, !tbaa !13
  store i32 1, ptr getelementptr inbounds (i8, ptr @B, i64 732), align 4, !tbaa !13
  store i32 1, ptr getelementptr inbounds (i8, ptr @B, i64 876), align 4, !tbaa !13
  store i32 1, ptr getelementptr inbounds (i8, ptr @B, i64 1020), align 4, !tbaa !13
  store i32 1, ptr getelementptr inbounds (i8, ptr @B, i64 1164), align 4, !tbaa !13
  store i32 1, ptr getelementptr inbounds (i8, ptr @B, i64 1308), align 4, !tbaa !13
  store i32 1, ptr getelementptr inbounds (i8, ptr @B, i64 1452), align 4, !tbaa !13
  store i32 1, ptr getelementptr inbounds (i8, ptr @B, i64 1596), align 4, !tbaa !13
  store i32 1, ptr getelementptr inbounds (i8, ptr @B, i64 1740), align 4, !tbaa !13
  store i32 1, ptr getelementptr inbounds (i8, ptr @B, i64 1884), align 4, !tbaa !13
  store i32 1, ptr getelementptr inbounds (i8, ptr @B, i64 2028), align 4, !tbaa !13
  store i32 1, ptr getelementptr inbounds (i8, ptr @B, i64 2172), align 4, !tbaa !13
  store i32 1, ptr getelementptr inbounds (i8, ptr @B, i64 2316), align 4, !tbaa !13
  store i32 1, ptr getelementptr inbounds (i8, ptr @B, i64 2460), align 4, !tbaa !13
  store i32 1, ptr getelementptr inbounds (i8, ptr @B, i64 2604), align 4, !tbaa !13
  store i32 1, ptr getelementptr inbounds (i8, ptr @B, i64 2748), align 4, !tbaa !13
  store i32 1, ptr getelementptr inbounds (i8, ptr @B, i64 2892), align 4, !tbaa !13
  store i32 1, ptr getelementptr inbounds (i8, ptr @B, i64 3036), align 4, !tbaa !13
  store i32 1, ptr getelementptr inbounds (i8, ptr @B, i64 3180), align 4, !tbaa !13
  store i32 1, ptr getelementptr inbounds (i8, ptr @B, i64 3324), align 4, !tbaa !13
  store i32 1, ptr getelementptr inbounds (i8, ptr @B, i64 3468), align 4, !tbaa !13
  store i32 1, ptr getelementptr inbounds (i8, ptr @B, i64 3612), align 4, !tbaa !13
  store i32 1, ptr getelementptr inbounds (i8, ptr @B, i64 3756), align 4, !tbaa !13
  store i32 1, ptr getelementptr inbounds (i8, ptr @B, i64 3900), align 4, !tbaa !13
  store i32 1, ptr getelementptr inbounds (i8, ptr @B, i64 4044), align 4, !tbaa !13
  store i32 1, ptr getelementptr inbounds (i8, ptr @B, i64 4188), align 4, !tbaa !13
  store i32 1, ptr getelementptr inbounds (i8, ptr @B, i64 4332), align 4, !tbaa !13
  store i32 1, ptr getelementptr inbounds (i8, ptr @B, i64 4476), align 4, !tbaa !13
  store i32 1, ptr getelementptr inbounds (i8, ptr @B, i64 4620), align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4908, ptr nonnull %1) #4
  call void @llvm.lifetime.start.p0(i64 4908, ptr nonnull %2) #4
  %11 = trunc i64 %10 to i32
  call void @_ZN6Matrix3powEi(ptr dead_on_unwind nonnull writable sret(%struct.Matrix) align 4 %2, ptr noundef nonnull align 4 dereferenceable(4908) @B, i32 noundef %11)
  call void @_ZNK6MatrixmlERKS_(ptr dead_on_unwind nonnull writable sret(%struct.Matrix) align 4 %1, ptr noundef nonnull align 4 dereferenceable(4908) @A, ptr noundef nonnull align 4 dereferenceable(4908) %2)
  %12 = getelementptr inbounds i8, ptr %1, i64 8
  %13 = load i32, ptr %12, align 4, !tbaa !13
  %14 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %13)
  call void @llvm.lifetime.end.p0(i64 4908, ptr nonnull %2) #4
  call void @llvm.lifetime.end.p0(i64 4908, ptr nonnull %1) #4
  br label %15

15:                                               ; preds = %8, %6
  ret i32 0
}

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

; Function Attrs: nofree nounwind
declare noundef i32 @puts(ptr nocapture noundef readonly) 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: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

; 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(4908), ptr noundef nonnull align 4 dereferenceable(4908)) local_unnamed_addr #3 align 2

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

attributes #0 = { mustprogress norecurse 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 = { 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 #2 = { mustprogress 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 = { 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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !11, i64 4}
!10 = !{!"_ZTS6Matrix", !11, i64 0, !11, i64 4, !7, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 0}
!13 = !{!11, !11, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass