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

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

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z3nttPxii(ptr noundef, i32 noundef, i32 noundef) #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z4Convv() #1 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #2
  store i32 1, ptr %1, align 4, !tbaa !5
  br label %3

3:                                                ; preds = %8, %0
  %4 = load i32, ptr %1, align 4, !tbaa !5
  %5 = load i32, ptr @n, align 4, !tbaa !5
  %6 = mul nsw i32 2, %5
  %7 = icmp sle i32 %4, %6
  br i1 %7, label %8, label %11

8:                                                ; preds = %3
  %9 = load i32, ptr %1, align 4, !tbaa !5
  %10 = shl i32 %9, 1
  store i32 %10, ptr %1, align 4, !tbaa !5
  br label %3, !llvm.loop !9

11:                                               ; preds = %3
  %12 = load i32, ptr %1, align 4, !tbaa !5
  call void @_Z3nttPxii(ptr noundef @a, i32 noundef %12, i32 noundef 1)
  %13 = load i32, ptr %1, align 4, !tbaa !5
  call void @_Z3nttPxii(ptr noundef @b, i32 noundef %13, i32 noundef 1)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #2
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %14

14:                                               ; preds = %33, %11
  %15 = load i32, ptr %2, align 4, !tbaa !5
  %16 = load i32, ptr %1, align 4, !tbaa !5
  %17 = icmp slt i32 %15, %16
  br i1 %17, label %19, label %18

18:                                               ; preds = %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #2
  br label %36

19:                                               ; preds = %14
  %20 = load i32, ptr %2, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [400010 x i64], ptr @a, i64 0, i64 %21
  %23 = load i64, ptr %22, align 8, !tbaa !11
  %24 = load i32, ptr %2, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [400010 x i64], ptr @b, i64 0, i64 %25
  %27 = load i64, ptr %26, align 8, !tbaa !11
  %28 = mul nsw i64 %23, %27
  %29 = srem i64 %28, 998244353
  %30 = load i32, ptr %2, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [400010 x i64], ptr @a, i64 0, i64 %31
  store i64 %29, ptr %32, align 8, !tbaa !11
  br label %33

33:                                               ; preds = %19
  %34 = load i32, ptr %2, align 4, !tbaa !5
  %35 = add nsw i32 %34, 1
  store i32 %35, ptr %2, align 4, !tbaa !5
  br label %14, !llvm.loop !13

36:                                               ; preds = %18
  %37 = load i32, ptr %1, align 4, !tbaa !5
  call void @_Z3nttPxii(ptr noundef @a, i32 noundef %37, i32 noundef -1)
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #2
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = distinct !{!13, !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"

@a = external dso_local global [400010 x i64], align 16
@b = external dso_local 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 void @_Z3nttPxii(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z4Convv() local_unnamed_addr #0 {
  %1 = load i32, ptr @n, align 4, !tbaa !5
  %2 = shl nsw i32 %1, 1
  br label %3

3:                                                ; preds = %3, %0
  %.011 = phi i32 [ 1, %0 ], [ %4, %3 ]
  %.not = icmp sgt i32 %.011, %2
  %4 = shl i32 %.011, 1
  br i1 %.not, label %5, label %3, !llvm.loop !9

5:                                                ; preds = %3
  tail call void @_Z3nttPxii(ptr noundef nonnull @a, i32 noundef %.011, i32 noundef 1)
  tail call void @_Z3nttPxii(ptr noundef nonnull @b, i32 noundef %.011, i32 noundef 1)
  %6 = icmp sgt i32 %.011, 0
  br i1 %6, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %5
  %wide.trip.count = zext nneg i32 %.011 to i64
  %xtraiter = and i64 %wide.trip.count, 1
  %7 = icmp eq i32 %.011, 1
  br i1 %7, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %wide.trip.count, 2147483646
  br label %.lr.ph

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

.lr.ph.epil:                                      ; preds = %._crit_edge.loopexit.unr-lcssa
  %8 = getelementptr inbounds [400010 x i64], ptr @a, i64 0, i64 %indvars.iv.unr
  %9 = load i64, ptr %8, align 8, !tbaa !11
  %10 = getelementptr inbounds [400010 x i64], ptr @b, i64 0, i64 %indvars.iv.unr
  %11 = load i64, ptr %10, align 8, !tbaa !11
  %12 = mul nsw i64 %11, %9
  %13 = srem i64 %12, 998244353
  store i64 %13, ptr %8, align 8, !tbaa !11
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph.epil, %._crit_edge.loopexit.unr-lcssa, %5
  tail call void @_Z3nttPxii(ptr noundef nonnull @a, i32 noundef %.011, i32 noundef -1)
  ret void

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader.new ], [ %indvars.iv.next.1, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.1, %.lr.ph ]
  %14 = getelementptr inbounds [400010 x i64], ptr @a, i64 0, i64 %indvars.iv
  %15 = load i64, ptr %14, align 16, !tbaa !11
  %16 = getelementptr inbounds [400010 x i64], ptr @b, i64 0, i64 %indvars.iv
  %17 = load i64, ptr %16, align 16, !tbaa !11
  %18 = mul nsw i64 %17, %15
  %19 = srem i64 %18, 998244353
  store i64 %19, ptr %14, align 16, !tbaa !11
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %20 = getelementptr inbounds [400010 x i64], ptr @a, i64 0, i64 %indvars.iv.next
  %21 = load i64, ptr %20, align 8, !tbaa !11
  %22 = getelementptr inbounds [400010 x i64], ptr @b, i64 0, i64 %indvars.iv.next
  %23 = load i64, ptr %22, align 8, !tbaa !11
  %24 = mul nsw i64 %23, %21
  %25 = srem i64 %24, 998244353
  store i64 %25, ptr %20, align 8, !tbaa !11
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 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.ph, !llvm.loop !13
}

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

!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, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = distinct !{!13, !10}


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