; LLVM IR from lzyrapx/Competitive-Programming :: HDUOJ/5829(NTT).ll (Z5solvev)

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

@inv = external dso_local global [400010 x i64], align 16
@fac = external dso_local global [400010 x i64], align 16
@a = external dso_local global [400010 x i64], align 16
@b = external dso_local global [400010 x i64], align 16
@A = external dso_local global [400010 x i64], align 16
@n = external dso_local global i32, align 4

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_Z3Powxx(i64 noundef, i64 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 uwtable
define dso_local void @_Z5solvev() #2 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #4
  store i32 0, ptr %1, align 4, !tbaa !5
  br label %4

4:                                                ; preds = %24, %0
  %5 = load i32, ptr %1, align 4, !tbaa !5
  %6 = load i32, ptr @n, align 4, !tbaa !5
  %7 = icmp slt i32 %5, %6
  br i1 %7, label %9, label %8

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

9:                                                ; preds = %4
  %10 = load i32, ptr %1, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [400010 x i64], ptr @inv, i64 0, i64 %11
  %13 = load i64, ptr %12, align 8, !tbaa !9
  %14 = load i32, ptr @n, align 4, !tbaa !5
  %15 = load i32, ptr %1, align 4, !tbaa !5
  %16 = sub nsw i32 %14, %15
  %17 = sext i32 %16 to i64
  %18 = call noundef i64 @_Z3Powxx(i64 noundef 2, i64 noundef %17)
  %19 = mul nsw i64 %13, %18
  %20 = srem i64 %19, 998244353
  %21 = load i32, ptr %1, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [400010 x i64], ptr @a, i64 0, i64 %22
  store i64 %20, ptr %23, align 8, !tbaa !9
  br label %24

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

27:                                               ; preds = %8
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %28

28:                                               ; preds = %48, %27
  %29 = load i32, ptr %2, align 4, !tbaa !5
  %30 = load i32, ptr @n, align 4, !tbaa !5
  %31 = icmp sle i32 %29, %30
  br i1 %31, label %33, label %32

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

33:                                               ; preds = %28
  %34 = load i32, ptr %2, align 4, !tbaa !5
  %35 = sub nsw i32 %34, 1
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [400010 x i64], ptr @fac, i64 0, i64 %36
  %38 = load i64, ptr %37, align 8, !tbaa !9
  %39 = load i32, ptr %2, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [400010 x i64], ptr @A, i64 0, i64 %40
  %42 = load i64, ptr %41, align 8, !tbaa !9
  %43 = mul nsw i64 %38, %42
  %44 = srem i64 %43, 998244353
  %45 = load i32, ptr %2, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [400010 x i64], ptr @b, i64 0, i64 %46
  store i64 %44, ptr %47, align 8, !tbaa !9
  br label %48

48:                                               ; preds = %33
  %49 = load i32, ptr %2, align 4, !tbaa !5
  %50 = add nsw i32 %49, 1
  store i32 %50, ptr %2, align 4, !tbaa !5
  br label %28, !llvm.loop !13

51:                                               ; preds = %32
  %52 = load i32, ptr @n, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds i64, ptr getelementptr inbounds (i64, ptr @b, i64 1), i64 %53
  call void @_ZSt7reverseIPxEvT_S1_(ptr noundef getelementptr inbounds (i64, ptr @b, i64 1), ptr noundef %54)
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %55

55:                                               ; preds = %69, %51
  %56 = load i32, ptr %3, align 4, !tbaa !5
  %57 = load i32, ptr @n, align 4, !tbaa !5
  %58 = icmp slt i32 %56, %57
  br i1 %58, label %60, label %59

59:                                               ; preds = %55
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  br label %72

60:                                               ; preds = %55
  %61 = load i32, ptr %3, align 4, !tbaa !5
  %62 = add nsw i32 %61, 1
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds [400010 x i64], ptr @b, i64 0, i64 %63
  %65 = load i64, ptr %64, align 8, !tbaa !9
  %66 = load i32, ptr %3, align 4, !tbaa !5
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [400010 x i64], ptr @b, i64 0, i64 %67
  store i64 %65, ptr %68, align 8, !tbaa !9
  br label %69

69:                                               ; preds = %60
  %70 = load i32, ptr %3, align 4, !tbaa !5
  %71 = add nsw i32 %70, 1
  store i32 %71, ptr %3, align 4, !tbaa !5
  br label %55, !llvm.loop !14

72:                                               ; preds = %59
  %73 = load i32, ptr @n, align 4, !tbaa !5
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds [400010 x i64], ptr @b, i64 0, i64 %74
  store i64 0, ptr %75, align 8, !tbaa !9
  ret void
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt7reverseIPxEvT_S1_(ptr noundef, 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 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 = { inlinehint 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 #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 = !{!"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 = distinct !{!13, !12}
!14 = distinct !{!14, !12}


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

@inv = external dso_local local_unnamed_addr global [400010 x i64], align 16
@fac = external dso_local local_unnamed_addr global [400010 x i64], align 16
@a = external dso_local local_unnamed_addr global [400010 x i64], align 16
@b = external dso_local global [400010 x i64], align 16
@A = external dso_local local_unnamed_addr global [400010 x i64], align 16
@n = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_Z3Powxx(i64 noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5solvev() local_unnamed_addr #1 {
  %1 = load i32, ptr @n, align 4, !tbaa !5
  %2 = icmp sgt i32 %1, 0
  br i1 %2, label %.lr.ph, label %._crit_edge

.preheader:                                       ; preds = %.lr.ph
  %.not21 = icmp slt i32 %15, 1
  br i1 %.not21, label %._crit_edge, label %.lr.ph23.preheader

.lr.ph23.preheader:                               ; preds = %.preheader
  %3 = zext nneg i32 %15 to i64
  %xtraiter = and i64 %3, 1
  %4 = icmp eq i32 %15, 1
  br i1 %4, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph23.preheader.new

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

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %0 ]
  %5 = phi i32 [ %15, %.lr.ph ], [ %1, %0 ]
  %6 = getelementptr inbounds [400010 x i64], ptr @inv, i64 0, i64 %indvars.iv
  %7 = load i64, ptr %6, align 8, !tbaa !9
  %8 = trunc nuw nsw i64 %indvars.iv to i32
  %9 = sub nsw i32 %5, %8
  %10 = sext i32 %9 to i64
  %11 = tail call noundef i64 @_Z3Powxx(i64 noundef 2, i64 noundef %10)
  %12 = mul nsw i64 %11, %7
  %13 = srem i64 %12, 998244353
  %14 = getelementptr inbounds [400010 x i64], ptr @a, i64 0, i64 %indvars.iv
  store i64 %13, ptr %14, align 8, !tbaa !9
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %15 = load i32, ptr @n, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = icmp slt i64 %indvars.iv.next, %16
  br i1 %17, label %.lr.ph, label %.preheader, !llvm.loop !11

._crit_edge.loopexit.unr-lcssa:                   ; preds = %.lr.ph23, %.lr.ph23.preheader
  %indvars.iv30.unr = phi i64 [ 1, %.lr.ph23.preheader ], [ %indvars.iv.next31.1, %.lr.ph23 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.lr.ph23.epil

.lr.ph23.epil:                                    ; preds = %._crit_edge.loopexit.unr-lcssa
  %18 = add nsw i64 %indvars.iv30.unr, -1
  %19 = getelementptr inbounds [400010 x i64], ptr @fac, i64 0, i64 %18
  %20 = load i64, ptr %19, align 8, !tbaa !9
  %21 = getelementptr inbounds [400010 x i64], ptr @A, i64 0, i64 %indvars.iv30.unr
  %22 = load i64, ptr %21, align 8, !tbaa !9
  %23 = mul nsw i64 %22, %20
  %24 = srem i64 %23, 998244353
  %25 = getelementptr inbounds [400010 x i64], ptr @b, i64 0, i64 %indvars.iv30.unr
  store i64 %24, ptr %25, align 8, !tbaa !9
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph23.epil, %._crit_edge.loopexit.unr-lcssa, %0, %.preheader
  %.lcssa1938 = phi i32 [ %15, %.preheader ], [ %1, %0 ], [ %15, %._crit_edge.loopexit.unr-lcssa ], [ %15, %.lr.ph23.epil ]
  %26 = sext i32 %.lcssa1938 to i64
  %27 = getelementptr inbounds i64, ptr getelementptr inbounds (i8, ptr @b, i64 8), i64 %26
  tail call void @_ZSt7reverseIPxEvT_S1_(ptr noundef nonnull getelementptr inbounds (i8, ptr @b, i64 8), ptr noundef nonnull %27)
  %28 = load i32, ptr @n, align 4, !tbaa !5
  %29 = icmp sgt i32 %28, 0
  br i1 %29, label %.lr.ph26.preheader, label %._crit_edge27

.lr.ph26.preheader:                               ; preds = %._crit_edge
  %30 = zext nneg i32 %28 to i64
  %31 = shl nuw nsw i64 %30, 3
  tail call void @llvm.memmove.p0.p0.i64(ptr nonnull align 16 @b, ptr nonnull align 8 getelementptr inbounds (i8, ptr @b, i64 8), i64 %31, i1 false), !tbaa !9
  br label %._crit_edge27

.lr.ph23:                                         ; preds = %.lr.ph23, %.lr.ph23.preheader.new
  %indvars.iv30 = phi i64 [ 1, %.lr.ph23.preheader.new ], [ %indvars.iv.next31.1, %.lr.ph23 ]
  %niter = phi i64 [ 0, %.lr.ph23.preheader.new ], [ %niter.next.1, %.lr.ph23 ]
  %32 = add nsw i64 %indvars.iv30, -1
  %33 = getelementptr inbounds [400010 x i64], ptr @fac, i64 0, i64 %32
  %34 = load i64, ptr %33, align 8, !tbaa !9
  %35 = getelementptr inbounds [400010 x i64], ptr @A, i64 0, i64 %indvars.iv30
  %36 = load i64, ptr %35, align 8, !tbaa !9
  %37 = mul nsw i64 %36, %34
  %38 = srem i64 %37, 998244353
  %39 = getelementptr inbounds [400010 x i64], ptr @b, i64 0, i64 %indvars.iv30
  store i64 %38, ptr %39, align 8, !tbaa !9
  %indvars.iv.next31 = add nuw nsw i64 %indvars.iv30, 1
  %40 = getelementptr inbounds [400010 x i64], ptr @fac, i64 0, i64 %indvars.iv30
  %41 = load i64, ptr %40, align 8, !tbaa !9
  %42 = getelementptr inbounds [400010 x i64], ptr @A, i64 0, i64 %indvars.iv.next31
  %43 = load i64, ptr %42, align 8, !tbaa !9
  %44 = mul nsw i64 %43, %41
  %45 = srem i64 %44, 998244353
  %46 = getelementptr inbounds [400010 x i64], ptr @b, i64 0, i64 %indvars.iv.next31
  store i64 %45, ptr %46, align 8, !tbaa !9
  %indvars.iv.next31.1 = add nuw nsw i64 %indvars.iv30, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph23, !llvm.loop !13

._crit_edge27:                                    ; preds = %.lr.ph26.preheader, %._crit_edge
  %47 = sext i32 %28 to i64
  %48 = getelementptr inbounds [400010 x i64], ptr @b, i64 0, i64 %47
  store i64 0, ptr %48, align 8, !tbaa !9
  ret void
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt7reverseIPxEvT_S1_(ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memmove.p0.p0.i64(ptr nocapture writeonly, ptr nocapture readonly, i64, i1 immarg) #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 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 = { inlinehint 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 #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }

!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 = distinct !{!13, !12}


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