; LLVM IR from tangjz/acm-icpc :: codeforces/complete (755G)

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

@w = external dso_local global [65537 x i32], align 16
@inv2 = external dso_local global [17 x i32], align 16
@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@len = external dso_local global i32, align 4
@G = external dso_local global %struct.Matrix, align 4
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [3 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 i32, align 4
  store i32 0, ptr %1, align 4
  store i32 1, ptr @w, align 16, !tbaa !5
  %6 = call noundef i32 @_Z7mod_powii(i32 noundef 3, i32 noundef 15232)
  store i32 %6, ptr getelementptr inbounds ([65537 x i32], ptr @w, i64 0, i64 1), align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #6
  store i32 2, ptr %2, align 4, !tbaa !5
  br label %7

7:                                                ; preds = %26, %0
  %8 = load i32, ptr %2, align 4, !tbaa !5
  %9 = icmp slt i32 %8, 65536
  br i1 %9, label %11, label %10

10:                                               ; preds = %7
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #6
  br label %29

11:                                               ; preds = %7
  %12 = load i32, ptr %2, align 4, !tbaa !5
  %13 = sub nsw i32 %12, 1
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [65537 x i32], ptr @w, i64 0, i64 %14
  %16 = load i32, ptr %15, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = load i32, ptr getelementptr inbounds ([65537 x i32], ptr @w, i64 0, i64 1), align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = mul nsw i64 %17, %19
  %21 = srem i64 %20, 998244353
  %22 = trunc i64 %21 to i32
  %23 = load i32, ptr %2, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [65537 x i32], ptr @w, i64 0, i64 %24
  store i32 %22, ptr %25, align 4, !tbaa !5
  br label %26

26:                                               ; preds = %11
  %27 = load i32, ptr %2, align 4, !tbaa !5
  %28 = add nsw i32 %27, 1
  store i32 %28, ptr %2, align 4, !tbaa !5
  br label %7, !llvm.loop !9

29:                                               ; preds = %10
  store i32 1, ptr @inv2, align 16, !tbaa !5
  store i32 499122177, ptr getelementptr inbounds ([17 x i32], ptr @inv2, i64 0, i64 1), align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #6
  store i32 2, ptr %3, align 4, !tbaa !5
  br label %30

30:                                               ; preds = %49, %29
  %31 = load i32, ptr %3, align 4, !tbaa !5
  %32 = icmp sle i32 %31, 16
  br i1 %32, label %34, label %33

33:                                               ; preds = %30
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #6
  br label %52

34:                                               ; preds = %30
  %35 = load i32, ptr %3, align 4, !tbaa !5
  %36 = sub nsw i32 %35, 1
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [17 x i32], ptr @inv2, i64 0, i64 %37
  %39 = load i32, ptr %38, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = load i32, ptr getelementptr inbounds ([17 x i32], ptr @inv2, i64 0, i64 1), align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = mul nsw i64 %40, %42
  %44 = srem i64 %43, 998244353
  %45 = trunc i64 %44 to i32
  %46 = load i32, ptr %3, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [17 x i32], ptr @inv2, i64 0, i64 %47
  store i32 %45, ptr %48, align 4, !tbaa !5
  br label %49

49:                                               ; preds = %34
  %50 = load i32, ptr %3, align 4, !tbaa !5
  %51 = add nsw i32 %50, 1
  store i32 %51, ptr %3, align 4, !tbaa !5
  br label %30, !llvm.loop !11

52:                                               ; preds = %33
  %53 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @m)
  %54 = load i32, ptr @n, align 4, !tbaa !5
  %55 = add nsw i32 %54, 1
  store i32 %55, ptr @n, align 4, !tbaa !5
  %56 = load i32, ptr @m, align 4, !tbaa !5
  %57 = add nsw i32 %56, 1
  store i32 %57, ptr @m, align 4, !tbaa !5
  store i32 1, ptr @len, align 4, !tbaa !5
  br label %58

58:                                               ; preds = %64, %52
  %59 = load i32, ptr @len, align 4, !tbaa !5
  %60 = load i32, ptr @m, align 4, !tbaa !5
  %61 = shl i32 %60, 1
  %62 = icmp slt i32 %59, %61
  br i1 %62, label %63, label %67

63:                                               ; preds = %58
  br label %64

64:                                               ; preds = %63
  %65 = load i32, ptr @len, align 4, !tbaa !5
  %66 = shl i32 %65, 1
  store i32 %66, ptr @len, align 4, !tbaa !5
  br label %58, !llvm.loop !12

67:                                               ; preds = %58
  store i32 1, ptr getelementptr inbounds (%struct.Matrix, ptr @G, i32 0, i32 1), align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 262152, ptr %4) #6
  %68 = load i32, ptr @n, align 4, !tbaa !5
  call void @_ZN6Matrix3powEi(ptr dead_on_unwind writable sret(%struct.Matrix) align 4 %4, ptr noundef nonnull align 4 dereferenceable(262152) @G, i32 noundef %68)
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 @G, ptr align 4 %4, i64 262152, i1 false), !tbaa.struct !13
  call void @llvm.lifetime.end.p0(i64 262152, ptr %4) #6
  %69 = load i32, ptr @m, align 4, !tbaa !5
  %70 = add nsw i32 %69, -1
  store i32 %70, ptr @m, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #6
  store i32 1, ptr %5, align 4, !tbaa !5
  br label %71

71:                                               ; preds = %89, %67
  %72 = load i32, ptr %5, align 4, !tbaa !5
  %73 = load i32, ptr @m, align 4, !tbaa !5
  %74 = icmp sle i32 %72, %73
  br i1 %74, label %76, label %75

75:                                               ; preds = %71
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #6
  br label %92

76:                                               ; preds = %71
  %77 = load i32, ptr %5, align 4, !tbaa !5
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds [32769 x i32], ptr getelementptr inbounds (%struct.Matrix, ptr @G, i32 0, i32 1), i64 0, i64 %78
  %80 = load i32, ptr %79, align 4, !tbaa !5
  %81 = load i32, ptr %5, align 4, !tbaa !5
  %82 = load i32, ptr @m, align 4, !tbaa !5
  %83 = icmp eq i32 %81, %82
  %84 = zext i1 %83 to i64
  %85 = getelementptr inbounds [3 x i8], ptr @.str.2, i64 0, i64 %84
  %86 = load i8, ptr %85, align 1, !tbaa !14
  %87 = sext i8 %86 to i32
  %88 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %80, i32 noundef %87)
  br label %89

89:                                               ; preds = %76
  %90 = load i32, ptr %5, align 4, !tbaa !5
  %91 = add nsw i32 %90, 1
  store i32 %91, ptr %5, align 4, !tbaa !5
  br label %71, !llvm.loop !15

92:                                               ; preds = %75
  ret i32 0
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z7mod_powii(i32 noundef, i32 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 @__isoc99_scanf(ptr noundef, ...) #3

; 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(262152), i32 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 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 = { inlinehint 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 = { "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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}
!13 = !{i64 0, i64 131076, !14, i64 131076, i64 131076, !14}
!14 = !{!7, !7, i64 0}
!15 = distinct !{!15, !10}


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

@w = external dso_local local_unnamed_addr global [65537 x i32], align 16
@inv2 = external dso_local local_unnamed_addr global [17 x i32], align 16
@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@len = external dso_local local_unnamed_addr global i32, align 4
@G = external dso_local global %struct.Matrix, align 4
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca %struct.Matrix, align 4
  store i32 1, ptr @w, align 16, !tbaa !5
  %2 = tail call noundef i32 @_Z7mod_powii(i32 noundef 3, i32 noundef 15232)
  store i32 %2, ptr getelementptr inbounds (i8, ptr @w, i64 4), align 4, !tbaa !5
  br label %10

3:                                                ; preds = %10
  store <4 x i32> <i32 1, i32 499122177, i32 748683265, i32 873463809>, ptr @inv2, align 16, !tbaa !5
  store <4 x i32> <i32 935854081, i32 967049217, i32 982646785, i32 990445569>, ptr getelementptr inbounds (i8, ptr @inv2, i64 16), align 16, !tbaa !5
  store <4 x i32> <i32 994344961, i32 996294657, i32 997269505, i32 997756929>, ptr getelementptr inbounds (i8, ptr @inv2, i64 32), align 16, !tbaa !5
  store <4 x i32> <i32 998000641, i32 998122497, i32 998183425, i32 998213889>, ptr getelementptr inbounds (i8, ptr @inv2, i64 48), align 16, !tbaa !5
  store i32 998229121, ptr getelementptr inbounds (i8, ptr @inv2, i64 64), align 16, !tbaa !5
  %4 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @m)
  %5 = load i32, ptr @n, align 4, !tbaa !5
  %6 = add nsw i32 %5, 1
  store i32 %6, ptr @n, align 4, !tbaa !5
  %7 = load i32, ptr @m, align 4, !tbaa !5
  %8 = add nsw i32 %7, 1
  store i32 %8, ptr @m, align 4, !tbaa !5
  %9 = shl i32 %8, 1
  br label %25

10:                                               ; preds = %10, %0
  %11 = phi i32 [ %2, %0 ], [ %23, %10 ]
  %indvars.iv = phi i64 [ 2, %0 ], [ %indvars.iv.next.1, %10 ]
  %12 = sext i32 %11 to i64
  %13 = load i32, ptr getelementptr inbounds (i8, ptr @w, i64 4), align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = mul nsw i64 %14, %12
  %16 = srem i64 %15, 998244353
  %17 = trunc nsw i64 %16 to i32
  %18 = getelementptr inbounds [65537 x i32], ptr @w, i64 0, i64 %indvars.iv
  store i32 %17, ptr %18, align 8, !tbaa !5
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %19 = load i32, ptr getelementptr inbounds (i8, ptr @w, i64 4), align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = mul nsw i64 %16, %20
  %22 = srem i64 %21, 998244353
  %23 = trunc nsw i64 %22 to i32
  %24 = getelementptr inbounds [65537 x i32], ptr @w, i64 0, i64 %indvars.iv.next
  store i32 %23, ptr %24, align 4, !tbaa !5
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %exitcond.not.1 = icmp eq i64 %indvars.iv.next.1, 65536
  br i1 %exitcond.not.1, label %3, label %10, !llvm.loop !9

25:                                               ; preds = %25, %3
  %storemerge = phi i32 [ 1, %3 ], [ %27, %25 ]
  %26 = icmp slt i32 %storemerge, %9
  %27 = shl i32 %storemerge, 1
  br i1 %26, label %25, label %28, !llvm.loop !11

28:                                               ; preds = %25
  store i32 %storemerge, ptr @len, align 4, !tbaa !5
  store i32 1, ptr getelementptr inbounds (i8, ptr @G, i64 131076), align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 262152, ptr nonnull %1) #6
  call void @_ZN6Matrix3powEi(ptr dead_on_unwind nonnull writable sret(%struct.Matrix) align 4 %1, ptr noundef nonnull align 4 dereferenceable(262152) @G, i32 noundef %6)
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(262152) @G, ptr noundef nonnull align 4 dereferenceable(262152) %1, i64 262152, i1 false), !tbaa.struct !12
  call void @llvm.lifetime.end.p0(i64 262152, ptr nonnull %1) #6
  %29 = load i32, ptr @m, align 4, !tbaa !5
  %30 = add nsw i32 %29, -1
  store i32 %30, ptr @m, align 4, !tbaa !5
  %.not18 = icmp slt i32 %29, 2
  br i1 %.not18, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %28
  ret i32 0

.lr.ph:                                           ; preds = %28, %.lr.ph
  %indvars.iv25 = phi i64 [ %indvars.iv.next26, %.lr.ph ], [ 1, %28 ]
  %31 = phi i32 [ %41, %.lr.ph ], [ %30, %28 ]
  %32 = getelementptr inbounds [32769 x i32], ptr getelementptr inbounds (i8, ptr @G, i64 131076), i64 0, i64 %indvars.iv25
  %33 = load i32, ptr %32, align 4, !tbaa !5
  %34 = zext i32 %31 to i64
  %35 = icmp eq i64 %indvars.iv25, %34
  %36 = zext i1 %35 to i64
  %37 = getelementptr inbounds [3 x i8], ptr @.str.2, i64 0, i64 %36
  %38 = load i8, ptr %37, align 1, !tbaa !13
  %39 = sext i8 %38 to i32
  %40 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %33, i32 noundef %39)
  %indvars.iv.next26 = add nuw nsw i64 %indvars.iv25, 1
  %41 = load i32, ptr @m, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %.not.not = icmp slt i64 %indvars.iv25, %42
  br i1 %.not.not, label %.lr.ph, label %._crit_edge, !llvm.loop !14
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z7mod_powii(i32 noundef, i32 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: nofree nounwind
declare noundef i32 @__isoc99_scanf(ptr nocapture noundef readonly, ...) local_unnamed_addr #3

; 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(262152), i32 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 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 = { inlinehint 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 = { 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 = distinct !{!11, !10}
!12 = !{i64 0, i64 131076, !13, i64 131076, i64 131076, !13}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !10}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass