; LLVM IR from tangjz/acm-icpc :: hdu (5667)

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

@n = external dso_local global i64, align 8
@t = external dso_local global i32, align 4
@a = external dso_local global i32, align 4
@b = external dso_local global i32, align 4
@c = external dso_local global i32, align 4
@p = external dso_local global i32, align 4
@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 [13 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 nounwind uwtable
declare dso_local noundef i32 @_Z7mod_powii(i32 noundef, i32 noundef) #0

; 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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #2 {
  %1 = alloca i32, align 4
  %2 = alloca %struct.Matrix, align 4
  store i32 0, ptr %1, align 4
  %3 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @t)
  br label %4

4:                                                ; preds = %19, %17, %0
  %5 = load i32, ptr @t, align 4, !tbaa !5
  %6 = add nsw i32 %5, -1
  store i32 %6, ptr @t, align 4, !tbaa !5
  %7 = icmp ne i32 %5, 0
  br i1 %7, label %8, label %43

8:                                                ; preds = %4
  %9 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef @n, ptr noundef @a, ptr noundef @b, ptr noundef @c, ptr noundef @p)
  %10 = load i32, ptr @a, align 4, !tbaa !5
  %11 = load i32, ptr @p, align 4, !tbaa !5
  %12 = srem i32 %10, %11
  %13 = icmp eq i32 %12, 0
  br i1 %13, label %14, label %19

14:                                               ; preds = %8
  %15 = load i64, ptr @n, align 8, !tbaa !9
  %16 = icmp sgt i64 %15, 1
  br i1 %16, label %17, label %19

17:                                               ; preds = %14
  %18 = call i32 @puts(ptr noundef @.str.2)
  br label %4, !llvm.loop !11

19:                                               ; preds = %14, %8
  store i32 3, ptr getelementptr inbounds (%struct.Matrix, ptr @A, i32 0, i32 1), align 4, !tbaa !13
  store i32 3, ptr @A, align 4, !tbaa !15
  store i32 0, ptr getelementptr inbounds (%struct.Matrix, ptr @A, i32 0, i32 2), align 4, !tbaa !5
  %20 = load i32, ptr @p, align 4, !tbaa !5
  %21 = sub nsw i32 %20, 1
  %22 = srem i32 1, %21
  store i32 %22, 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 0, ptr getelementptr inbounds ([3 x i32], ptr getelementptr inbounds (%struct.Matrix, ptr @A, i32 0, i32 2), i64 0, i64 2), align 4, !tbaa !5
  %23 = load i32, ptr @p, align 4, !tbaa !5
  %24 = sub nsw i32 %23, 1
  %25 = srem i32 1, %24
  store i32 %25, ptr getelementptr inbounds ([3 x [3 x i32]], ptr getelementptr inbounds (%struct.Matrix, ptr @A, i32 0, i32 2), i64 0, i64 1), align 4, !tbaa !5
  %26 = load i32, ptr @c, align 4, !tbaa !5
  %27 = load i32, ptr @p, align 4, !tbaa !5
  %28 = sub nsw i32 %27, 1
  %29 = srem i32 %26, %28
  store i32 %29, ptr getelementptr inbounds ([3 x i32], ptr getelementptr inbounds ([3 x [3 x i32]], ptr getelementptr inbounds (%struct.Matrix, ptr @A, i32 0, i32 2), i64 0, i64 1), i64 0, i64 1), align 4, !tbaa !5
  store i32 0, ptr getelementptr inbounds ([3 x i32], ptr getelementptr inbounds ([3 x [3 x i32]], ptr getelementptr inbounds (%struct.Matrix, ptr @A, i32 0, i32 2), i64 0, i64 1), i64 0, i64 2), align 4, !tbaa !5
  store i32 0, ptr getelementptr inbounds ([3 x [3 x i32]], ptr getelementptr inbounds (%struct.Matrix, ptr @A, i32 0, i32 2), i64 0, i64 2), align 4, !tbaa !5
  %30 = load i32, ptr @b, align 4, !tbaa !5
  %31 = load i32, ptr @p, align 4, !tbaa !5
  %32 = sub nsw i32 %31, 1
  %33 = srem i32 %30, %32
  store i32 %33, ptr getelementptr inbounds ([3 x i32], ptr getelementptr inbounds ([3 x [3 x i32]], ptr getelementptr inbounds (%struct.Matrix, ptr @A, i32 0, i32 2), i64 0, i64 2), i64 0, i64 1), align 4, !tbaa !5
  %34 = load i32, ptr @p, align 4, !tbaa !5
  %35 = sub nsw i32 %34, 1
  %36 = srem i32 1, %35
  store i32 %36, ptr getelementptr inbounds ([3 x i32], ptr getelementptr inbounds ([3 x [3 x i32]], ptr getelementptr inbounds (%struct.Matrix, ptr @A, i32 0, i32 2), i64 0, i64 2), i64 0, i64 2), align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 44, ptr %2) #6
  %37 = load i64, ptr @n, align 8, !tbaa !9
  %38 = sub nsw i64 %37, 1
  call void @_ZN6Matrix3powEx(ptr dead_on_unwind writable sret(%struct.Matrix) align 4 %2, ptr noundef nonnull align 4 dereferenceable(44) @A, i64 noundef %38)
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 @A, ptr align 4 %2, i64 44, i1 false), !tbaa.struct !16
  call void @llvm.lifetime.end.p0(i64 44, ptr %2) #6
  %39 = load i32, ptr @a, align 4, !tbaa !5
  %40 = load i32, ptr getelementptr inbounds ([3 x i32], ptr getelementptr inbounds ([3 x [3 x i32]], ptr getelementptr inbounds (%struct.Matrix, ptr @A, i32 0, i32 2), i64 0, i64 2), i64 0, i64 1), align 4, !tbaa !5
  %41 = call noundef i32 @_Z7mod_powii(i32 noundef %39, i32 noundef %40)
  %42 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i32 noundef %41)
  br label %4, !llvm.loop !11

43:                                               ; preds = %4
  ret i32 0
}

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

declare i32 @puts(ptr noundef) #3

; 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(44), i64 noundef) #4 align 2

; 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

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

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

@n = external dso_local global i64, align 8
@t = external dso_local global i32, align 4
@a = external dso_local global i32, align 4
@b = external dso_local global i32, align 4
@c = external dso_local global i32, align 4
@p = external dso_local global i32, align 4
@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 [13 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 nounwind uwtable
declare dso_local noundef i32 @_Z7mod_powii(i32 noundef, i32 noundef) local_unnamed_addr #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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #2 {
  %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
  %.not2 = icmp eq i32 %3, 0
  br i1 %.not2, 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 @a, ptr noundef nonnull @b, ptr noundef nonnull @c, ptr noundef nonnull @p)
  %6 = load i32, ptr @a, align 4, !tbaa !5
  %7 = load i32, ptr @p, align 4, !tbaa !5
  %8 = srem i32 %6, %7
  %9 = icmp eq i32 %8, 0
  %10 = load i64, ptr @n, align 8
  %11 = icmp sgt i64 %10, 1
  %or.cond = select i1 %9, i1 %11, i1 false
  br i1 %or.cond, label %12, label %16

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

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

16:                                               ; preds = %.lr.ph
  store i32 3, ptr getelementptr inbounds (i8, ptr @A, i64 4), align 4, !tbaa !11
  store i32 3, ptr @A, align 4, !tbaa !13
  store i32 0, ptr getelementptr inbounds (i8, ptr @A, i64 8), align 4, !tbaa !5
  %17 = add nsw i32 %7, -1
  %18 = srem i32 1, %17
  store i32 %18, ptr getelementptr inbounds (i8, ptr @A, i64 12), align 4, !tbaa !5
  store i32 0, ptr getelementptr inbounds (i8, ptr @A, i64 16), align 4, !tbaa !5
  store i32 %18, ptr getelementptr inbounds (i8, ptr @A, i64 20), align 4, !tbaa !5
  %19 = load i32, ptr @c, align 4, !tbaa !5
  %20 = srem i32 %19, %17
  store i32 %20, ptr getelementptr inbounds (i8, ptr @A, i64 24), align 4, !tbaa !5
  store i32 0, ptr getelementptr inbounds (i8, ptr @A, i64 28), align 4, !tbaa !5
  store i32 0, ptr getelementptr inbounds (i8, ptr @A, i64 32), align 4, !tbaa !5
  %21 = load i32, ptr @b, align 4, !tbaa !5
  %22 = srem i32 %21, %17
  store i32 %22, ptr getelementptr inbounds (i8, ptr @A, i64 36), align 4, !tbaa !5
  store i32 %18, ptr getelementptr inbounds (i8, ptr @A, i64 40), align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 44, ptr nonnull %1) #6
  %23 = add nsw i64 %10, -1
  call void @_ZN6Matrix3powEx(ptr dead_on_unwind nonnull writable sret(%struct.Matrix) align 4 %1, ptr noundef nonnull align 4 dereferenceable(44) @A, i64 noundef %23)
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(44) @A, ptr noundef nonnull align 4 dereferenceable(44) %1, i64 44, i1 false), !tbaa.struct !14
  call void @llvm.lifetime.end.p0(i64 44, ptr nonnull %1) #6
  %24 = load i32, ptr @a, align 4, !tbaa !5
  %25 = load i32, ptr getelementptr inbounds (i8, ptr @A, i64 36), align 4, !tbaa !5
  %26 = call noundef i32 @_Z7mod_powii(i32 noundef %24, i32 noundef %25)
  %27 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i32 noundef %26)
  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 #3

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

; 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(44), i64 noundef) local_unnamed_addr #4 align 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) #5

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

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { 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 #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 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 4}
!12 = !{!"_ZTS6Matrix", !6, i64 0, !6, i64 4, !7, i64 8}
!13 = !{!12, !6, i64 0}
!14 = !{i64 0, i64 4, !5, i64 4, i64 4, !5, i64 8, i64 36, !15}
!15 = !{!7, !7, i64 0}


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