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

; 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
@p = external dso_local global i32, align 4
@n = external dso_local global i64, align 8
@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 [7 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [4 x i8], align 1

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_Z7mod_powxxx(i64 noundef, i64 noundef, i64 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 norecurse uwtable
define dso_local noundef i32 @main() #3 {
  %1 = alloca i32, align 4
  %2 = alloca %struct.Matrix, align 4
  %3 = alloca %struct.Matrix, align 4
  %4 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %5 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @t)
  br label %6

6:                                                ; preds = %55, %14, %0
  %7 = load i32, ptr @t, align 4, !tbaa !5
  %8 = add nsw i32 %7, -1
  store i32 %8, ptr @t, align 4, !tbaa !5
  %9 = icmp ne i32 %7, 0
  br i1 %9, label %10, label %69

10:                                               ; preds = %6
  %11 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef @n, ptr noundef @p)
  %12 = load i32, ptr @p, align 4, !tbaa !5
  %13 = icmp sle i32 %12, 3
  br i1 %13, label %14, label %16

14:                                               ; preds = %10
  %15 = call i32 @puts(ptr noundef @.str.2)
  br label %6, !llvm.loop !9

16:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 24, ptr %2) #6
  %17 = getelementptr inbounds %struct.Matrix, ptr %2, i32 0, i32 0
  store i32 2, ptr %17, align 4, !tbaa !11
  %18 = getelementptr inbounds %struct.Matrix, ptr %2, i32 0, i32 1
  store i32 2, ptr %18, align 4, !tbaa !13
  %19 = getelementptr inbounds %struct.Matrix, ptr %2, i32 0, i32 2
  store i32 0, ptr %19, align 4, !tbaa !5
  %20 = getelementptr inbounds i32, ptr %19, i64 1
  %21 = load i32, ptr @p, align 4, !tbaa !5
  %22 = sub nsw i32 %21, 1
  store i32 %22, ptr %20, align 4, !tbaa !5
  %23 = getelementptr inbounds [2 x i32], ptr %19, i64 1
  store i32 1, ptr %23, align 4, !tbaa !5
  %24 = getelementptr inbounds i32, ptr %23, i64 1
  %25 = load i32, ptr @p, align 4, !tbaa !5
  %26 = srem i32 11, %25
  store i32 %26, ptr %24, align 4, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 @A, ptr align 4 %2, i64 24, i1 false), !tbaa.struct !14
  call void @llvm.lifetime.end.p0(i64 24, ptr %2) #6
  %27 = load i64, ptr @n, align 8, !tbaa !16
  %28 = sub nsw i64 %27, 1
  %29 = load i32, ptr @p, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = load i32, ptr @p, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = mul nsw i64 %30, %32
  %34 = sub nsw i64 %33, 1
  %35 = call noundef i64 @_Z7mod_powxxx(i64 noundef 2, i64 noundef %28, i64 noundef %34)
  store i64 %35, ptr @n, align 8, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 24, ptr %3) #6
  %36 = load i64, ptr @n, align 8, !tbaa !16
  call void @_ZN6Matrix3powEx(ptr dead_on_unwind writable sret(%struct.Matrix) align 4 %3, ptr noundef nonnull align 4 dereferenceable(24) @A, i64 noundef %36)
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 @B, ptr align 4 %3, i64 24, i1 false), !tbaa.struct !14
  call void @llvm.lifetime.end.p0(i64 24, ptr %3) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #6
  %37 = load i32, ptr getelementptr inbounds (%struct.Matrix, ptr @B, i32 0, i32 2), align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = mul nsw i64 2, %38
  %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 !5
  %41 = sext i32 %40 to i64
  %42 = mul nsw i64 11, %41
  %43 = add nsw i64 %39, %42
  %44 = sub nsw i64 %43, 5
  %45 = load i32, ptr @p, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = srem i64 %44, %46
  %48 = trunc i64 %47 to i32
  store i32 %48, ptr %4, align 4, !tbaa !5
  %49 = load i32, ptr %4, align 4, !tbaa !5
  %50 = icmp slt i32 %49, 0
  br i1 %50, label %51, label %55

51:                                               ; preds = %16
  %52 = load i32, ptr @p, align 4, !tbaa !5
  %53 = load i32, ptr %4, align 4, !tbaa !5
  %54 = add nsw i32 %53, %52
  store i32 %54, ptr %4, align 4, !tbaa !5
  br label %55

55:                                               ; preds = %51, %16
  %56 = load i32, ptr %4, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = load i32, ptr @p, align 4, !tbaa !5
  %59 = srem i32 6, %58
  %60 = call noundef i32 @_Z3invi(i32 noundef %59)
  %61 = sext i32 %60 to i64
  %62 = mul nsw i64 %57, %61
  %63 = load i32, ptr @p, align 4, !tbaa !5
  %64 = sext i32 %63 to i64
  %65 = srem i64 %62, %64
  %66 = trunc i64 %65 to i32
  store i32 %66, ptr %4, align 4, !tbaa !5
  %67 = load i32, ptr %4, align 4, !tbaa !5
  %68 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i32 noundef %67)
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #6
  br label %6, !llvm.loop !9

69:                                               ; preds = %6
  ret i32 0
}

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

declare i32 @puts(ptr noundef) #4

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

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


; 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
@p = external dso_local global i32, align 4
@n = external dso_local global i64, align 8
@A = external dso_local global %struct.Matrix, align 4
@B = external dso_local local_unnamed_addr global %struct.Matrix, align 4
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [4 x i8], align 1

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_Z7mod_powxxx(i64 noundef, i64 noundef, i64 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 norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #3 {
  %1 = alloca %struct.Matrix, align 4
  %2 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @t)
  %3 = load i32, ptr @t, align 4, !tbaa !5
  %4 = add nsw i32 %3, -1
  store i32 %4, ptr @t, align 4, !tbaa !5
  %.not6 = icmp eq i32 %3, 0
  br i1 %.not6, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %0, %.backedge
  %5 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @n, ptr noundef nonnull @p)
  %6 = load i32, ptr @p, align 4, !tbaa !5
  %7 = icmp slt i32 %6, 4
  br i1 %7, label %8, label %12

8:                                                ; preds = %.lr.ph
  %9 = call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.2)
  br label %.backedge

.backedge:                                        ; preds = %8, %12
  %10 = load i32, ptr @t, align 4, !tbaa !5
  %11 = add nsw i32 %10, -1
  store i32 %11, ptr @t, align 4, !tbaa !5
  %.not = icmp eq i32 %10, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !9

12:                                               ; preds = %.lr.ph
  %13 = add nsw i32 %6, -1
  %14 = urem i32 11, %6
  store i32 2, ptr @A, align 4, !tbaa !5
  store i32 2, ptr getelementptr inbounds (i8, ptr @A, i64 4), align 4, !tbaa !5
  store i32 0, ptr getelementptr inbounds (i8, ptr @A, i64 8), align 4
  store i32 %13, ptr getelementptr inbounds (i8, ptr @A, i64 12), align 4
  store i32 1, ptr getelementptr inbounds (i8, ptr @A, i64 16), align 4
  store i32 %14, ptr getelementptr inbounds (i8, ptr @A, i64 20), align 4, !tbaa !11
  %15 = load i64, ptr @n, align 8, !tbaa !12
  %16 = add nsw i64 %15, -1
  %17 = zext nneg i32 %6 to i64
  %18 = mul nuw nsw i64 %17, %17
  %19 = add nsw i64 %18, -1
  %20 = call noundef i64 @_Z7mod_powxxx(i64 noundef 2, i64 noundef %16, i64 noundef %19)
  store i64 %20, ptr @n, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %1) #6
  call void @_ZN6Matrix3powEx(ptr dead_on_unwind nonnull writable sret(%struct.Matrix) align 4 %1, ptr noundef nonnull align 4 dereferenceable(24) @A, i64 noundef %20)
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(24) @B, ptr noundef nonnull align 4 dereferenceable(24) %1, i64 24, i1 false), !tbaa.struct !14
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %1) #6
  %21 = load i32, ptr getelementptr inbounds (i8, ptr @B, i64 8), align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = shl nsw i64 %22, 1
  %24 = load i32, ptr getelementptr inbounds (i8, ptr @B, i64 16), align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = mul nsw i64 %25, 11
  %27 = add nsw i64 %23, -5
  %28 = add nsw i64 %27, %26
  %29 = load i32, ptr @p, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = srem i64 %28, %30
  %32 = trunc nsw i64 %31 to i32
  %33 = icmp slt i64 %31, 0
  %34 = select i1 %33, i32 %29, i32 0
  %spec.select = add nsw i32 %34, %32
  %35 = sext i32 %spec.select to i64
  %36 = srem i32 6, %29
  %37 = call noundef i32 @_Z3invi(i32 noundef %36)
  %38 = sext i32 %37 to i64
  %39 = mul nsw i64 %35, %38
  %40 = load i32, ptr @p, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = srem i64 %39, %41
  %43 = trunc nsw i64 %42 to i32
  %44 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i32 noundef %43)
  br label %.backedge

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

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

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

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

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


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass