; LLVM IR from tangjz/acm-icpc :: codeforces/complete (1091D)

; 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"

@n = external dso_local global i32, align 4
@fct = external dso_local global i32, align 4
@prd = external dso_local global i32, align 4
@ans = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = 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
  store i32 0, ptr %1, align 4
  %4 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  store i32 1, ptr @fct, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %5

5:                                                ; preds = %18, %0
  %6 = load i32, ptr %2, align 4, !tbaa !5
  %7 = load i32, ptr @n, align 4, !tbaa !5
  %8 = icmp sle i32 %6, %7
  br i1 %8, label %10, label %9

9:                                                ; preds = %5
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  br label %21

10:                                               ; preds = %5
  %11 = load i32, ptr @fct, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = load i32, ptr %2, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = mul nsw i64 %12, %14
  %16 = srem i64 %15, 998244353
  %17 = trunc i64 %16 to i32
  store i32 %17, ptr @fct, align 4, !tbaa !5
  br label %18

18:                                               ; preds = %10
  %19 = load i32, ptr %2, align 4, !tbaa !5
  %20 = add nsw i32 %19, 1
  store i32 %20, ptr %2, align 4, !tbaa !5
  br label %5, !llvm.loop !9

21:                                               ; preds = %9
  %22 = load i32, ptr @fct, align 4, !tbaa !5
  store i32 %22, ptr @ans, align 4, !tbaa !5
  store i32 1, ptr @prd, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 1, ptr %3, align 4, !tbaa !5
  br label %23

23:                                               ; preds = %59, %21
  %24 = load i32, ptr %3, align 4, !tbaa !5
  %25 = load i32, ptr @n, align 4, !tbaa !5
  %26 = icmp sle i32 %24, %25
  br i1 %26, label %28, label %27

27:                                               ; preds = %23
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  br label %62

28:                                               ; preds = %23
  %29 = load i32, ptr @prd, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = load i32, ptr @n, align 4, !tbaa !5
  %32 = load i32, ptr %3, align 4, !tbaa !5
  %33 = sub nsw i32 %31, %32
  %34 = add nsw i32 %33, 1
  %35 = sext i32 %34 to i64
  %36 = mul nsw i64 %30, %35
  %37 = srem i64 %36, 998244353
  %38 = trunc i64 %37 to i32
  store i32 %38, ptr @prd, align 4, !tbaa !5
  %39 = load i32, ptr @fct, align 4, !tbaa !5
  %40 = load i32, ptr @ans, align 4, !tbaa !5
  %41 = add nsw i32 %40, %39
  store i32 %41, ptr @ans, align 4, !tbaa !5
  %42 = icmp sge i32 %41, 998244353
  br i1 %42, label %43, label %47

43:                                               ; preds = %28
  %44 = load i32, ptr @ans, align 4, !tbaa !5
  %45 = sub nsw i32 %44, 998244353
  store i32 %45, ptr @ans, align 4, !tbaa !5
  %46 = icmp ne i32 %45, 0
  br label %47

47:                                               ; preds = %43, %28
  %48 = phi i1 [ false, %28 ], [ %46, %43 ]
  %49 = load i32, ptr @prd, align 4, !tbaa !5
  %50 = load i32, ptr @ans, align 4, !tbaa !5
  %51 = sub nsw i32 %50, %49
  store i32 %51, ptr @ans, align 4, !tbaa !5
  %52 = icmp slt i32 %51, 0
  br i1 %52, label %53, label %57

53:                                               ; preds = %47
  %54 = load i32, ptr @ans, align 4, !tbaa !5
  %55 = add nsw i32 %54, 998244353
  store i32 %55, ptr @ans, align 4, !tbaa !5
  %56 = icmp ne i32 %55, 0
  br label %57

57:                                               ; preds = %53, %47
  %58 = phi i1 [ false, %47 ], [ %56, %53 ]
  br label %59

59:                                               ; preds = %57
  %60 = load i32, ptr %3, align 4, !tbaa !5
  %61 = add nsw i32 %60, 1
  store i32 %61, ptr %3, align 4, !tbaa !5
  br label %23, !llvm.loop !11

62:                                               ; preds = %27
  %63 = load i32, ptr @ans, align 4, !tbaa !5
  %64 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %63)
  ret i32 0
}

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

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 = { 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}


; 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"

@n = external dso_local global i32, align 4
@fct = external dso_local local_unnamed_addr global i32, align 4
@prd = external dso_local local_unnamed_addr global i32, align 4
@ans = external dso_local local_unnamed_addr global i32, align 4
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress nofree norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  store i32 1, ptr @fct, align 4, !tbaa !5
  %2 = load i32, ptr @n, align 4, !tbaa !5
  %.not12 = icmp slt i32 %2, 1
  br i1 %.not12, label %.thread, label %.lr.ph.preheader

.thread:                                          ; preds = %0
  store i32 1, ptr @ans, align 4, !tbaa !5
  store i32 1, ptr @prd, align 4, !tbaa !5
  br label %19

.lr.ph.preheader:                                 ; preds = %0
  %3 = zext nneg i32 %2 to i64
  %xtraiter = and i64 %3, 3
  %4 = icmp ult i32 %2, 4
  br i1 %4, label %.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %3, 2147483644
  br label %.lr.ph

.unr-lcssa:                                       ; preds = %.lr.ph, %.lr.ph.preheader
  %.lcssa33.ph = phi i64 [ poison, %.lr.ph.preheader ], [ %18, %.lr.ph ]
  %indvars.iv.unr = phi i64 [ 1, %.lr.ph.preheader ], [ %indvars.iv.next.3, %.lr.ph ]
  %.unr = phi i64 [ 1, %.lr.ph.preheader ], [ %18, %.lr.ph ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.epilog-lcssa, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %.unr-lcssa, %.lr.ph.epil
  %indvars.iv.epil = phi i64 [ %indvars.iv.next.epil, %.lr.ph.epil ], [ %indvars.iv.unr, %.unr-lcssa ]
  %5 = phi i64 [ %7, %.lr.ph.epil ], [ %.unr, %.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.lr.ph.epil ], [ 0, %.unr-lcssa ]
  %6 = mul nsw i64 %5, %indvars.iv.epil
  %7 = srem i64 %6, 998244353
  %indvars.iv.next.epil = add nuw nsw i64 %indvars.iv.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %.epilog-lcssa, label %.lr.ph.epil, !llvm.loop !9

.epilog-lcssa:                                    ; preds = %.lr.ph.epil, %.unr-lcssa
  %.lcssa33 = phi i64 [ %.lcssa33.ph, %.unr-lcssa ], [ %7, %.lr.ph.epil ]
  %8 = trunc nsw i64 %.lcssa33 to i32
  store i32 %8, ptr @fct, align 4, !tbaa !5
  store i32 %8, ptr @ans, align 4, !tbaa !5
  store i32 1, ptr @prd, align 4, !tbaa !5
  br i1 %.not12, label %19, label %.lr.ph20

.lr.ph20:                                         ; preds = %.epilog-lcssa
  %9 = add nuw i32 %2, 1
  %wide.trip.count28 = zext i32 %9 to i64
  br label %22

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %indvars.iv = phi i64 [ 1, %.lr.ph.preheader.new ], [ %indvars.iv.next.3, %.lr.ph ]
  %10 = phi i64 [ 1, %.lr.ph.preheader.new ], [ %18, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.3, %.lr.ph ]
  %11 = mul nsw i64 %10, %indvars.iv
  %12 = srem i64 %11, 998244353
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %13 = mul nsw i64 %12, %indvars.iv.next
  %14 = srem i64 %13, 998244353
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %15 = mul nsw i64 %14, %indvars.iv.next.1
  %16 = srem i64 %15, 998244353
  %indvars.iv.next.2 = add nuw nsw i64 %indvars.iv, 3
  %17 = mul nsw i64 %16, %indvars.iv.next.2
  %18 = srem i64 %17, 998244353
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %.unr-lcssa, label %.lr.ph, !llvm.loop !11

._crit_edge21:                                    ; preds = %22
  store i32 %29, ptr @prd, align 4, !tbaa !5
  store i32 %storemerge11, ptr @ans, align 4, !tbaa !5
  br label %19

19:                                               ; preds = %.thread, %._crit_edge21, %.epilog-lcssa
  %20 = phi i32 [ %storemerge11, %._crit_edge21 ], [ %8, %.epilog-lcssa ], [ 1, %.thread ]
  %21 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %20)
  ret i32 0

22:                                               ; preds = %.lr.ph20, %22
  %indvars.iv25 = phi i64 [ 1, %.lr.ph20 ], [ %indvars.iv.next26, %22 ]
  %23 = phi i64 [ 1, %.lr.ph20 ], [ %28, %22 ]
  %storemerge111517 = phi i32 [ %8, %.lr.ph20 ], [ %storemerge11, %22 ]
  %24 = trunc nuw nsw i64 %indvars.iv25 to i32
  %25 = sub i32 %9, %24
  %26 = sext i32 %25 to i64
  %27 = mul nsw i64 %23, %26
  %28 = srem i64 %27, 998244353
  %29 = trunc nsw i64 %28 to i32
  %30 = add nsw i32 %storemerge111517, %8
  %31 = icmp sgt i32 %30, 998244352
  %32 = add nsw i32 %30, -998244353
  %spec.select = select i1 %31, i32 %32, i32 %30
  %33 = sub nsw i32 %spec.select, %29
  %34 = icmp slt i32 %33, 0
  %35 = add nsw i32 %33, 998244353
  %storemerge11 = select i1 %34, i32 %35, i32 %33
  %indvars.iv.next26 = add nuw nsw i64 %indvars.iv25, 1
  %exitcond29.not = icmp eq i64 %indvars.iv.next26, %wide.trip.count28
  br i1 %exitcond29.not, label %._crit_edge21, label %22, !llvm.loop !13
}

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

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

attributes #0 = { mustprogress nofree 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" }

!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.unroll.disable"}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


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