; LLVM IR from tangjz/acm-icpc :: codeforces/gym/102028G.ll (Z8poly_muliPiS_S_)

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

@f = external dso_local global [524289 x i32], align 16
@g = external dso_local global [524289 x i32], align 16

; 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 uwtable
declare dso_local void @_Z3NTTiPii(i32 noundef, ptr noundef, i32 noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z8poly_muliPiS_S_(i32 noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #1 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store i32 %0, ptr %5, align 4, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !9
  store ptr %3, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  store i32 1, ptr %9, align 4, !tbaa !5
  br label %11

11:                                               ; preds = %18, %4
  %12 = load i32, ptr %9, align 4, !tbaa !5
  %13 = load i32, ptr %5, align 4, !tbaa !5
  %14 = sub nsw i32 %13, 1
  %15 = shl i32 %14, 1
  %16 = icmp sle i32 %12, %15
  br i1 %16, label %17, label %21

17:                                               ; preds = %11
  br label %18

18:                                               ; preds = %17
  %19 = load i32, ptr %9, align 4, !tbaa !5
  %20 = shl i32 %19, 1
  store i32 %20, ptr %9, align 4, !tbaa !5
  br label %11, !llvm.loop !11

21:                                               ; preds = %11
  %22 = load ptr, ptr %6, align 8, !tbaa !9
  %23 = load i32, ptr %5, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = mul i64 %24, 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 @f, ptr align 4 %22, i64 %25, i1 false)
  %26 = load i32, ptr %5, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds i32, ptr @f, i64 %27
  %29 = load i32, ptr %9, align 4, !tbaa !5
  %30 = load i32, ptr %5, align 4, !tbaa !5
  %31 = sub nsw i32 %29, %30
  %32 = sext i32 %31 to i64
  %33 = mul i64 %32, 4
  call void @llvm.memset.p0.i64(ptr align 4 %28, i8 0, i64 %33, i1 false)
  %34 = load ptr, ptr %7, align 8, !tbaa !9
  %35 = load i32, ptr %5, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = mul i64 %36, 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 @g, ptr align 4 %34, i64 %37, i1 false)
  %38 = load i32, ptr %5, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds i32, ptr @g, i64 %39
  %41 = load i32, ptr %9, align 4, !tbaa !5
  %42 = load i32, ptr %5, align 4, !tbaa !5
  %43 = sub nsw i32 %41, %42
  %44 = sext i32 %43 to i64
  %45 = mul i64 %44, 4
  call void @llvm.memset.p0.i64(ptr align 4 %40, i8 0, i64 %45, i1 false)
  %46 = load i32, ptr %9, align 4, !tbaa !5
  call void @_Z3NTTiPii(i32 noundef %46, ptr noundef @f, i32 noundef 1)
  %47 = load i32, ptr %9, align 4, !tbaa !5
  call void @_Z3NTTiPii(i32 noundef %47, ptr noundef @g, i32 noundef 1)
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  store i32 0, ptr %10, align 4, !tbaa !5
  br label %48

48:                                               ; preds = %70, %21
  %49 = load i32, ptr %10, align 4, !tbaa !5
  %50 = load i32, ptr %9, align 4, !tbaa !5
  %51 = icmp slt i32 %49, %50
  br i1 %51, label %53, label %52

52:                                               ; preds = %48
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  br label %73

53:                                               ; preds = %48
  %54 = load i32, ptr %10, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [524289 x i32], ptr @f, i64 0, i64 %55
  %57 = load i32, ptr %56, align 4, !tbaa !5
  %58 = sext i32 %57 to i64
  %59 = load i32, ptr %10, align 4, !tbaa !5
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [524289 x i32], ptr @g, i64 0, i64 %60
  %62 = load i32, ptr %61, align 4, !tbaa !5
  %63 = sext i32 %62 to i64
  %64 = mul nsw i64 %58, %63
  %65 = srem i64 %64, 998244353
  %66 = trunc i64 %65 to i32
  %67 = load i32, ptr %10, align 4, !tbaa !5
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds [524289 x i32], ptr @f, i64 0, i64 %68
  store i32 %66, ptr %69, align 4, !tbaa !5
  br label %70

70:                                               ; preds = %53
  %71 = load i32, ptr %10, align 4, !tbaa !5
  %72 = add nsw i32 %71, 1
  store i32 %72, ptr %10, align 4, !tbaa !5
  br label %48, !llvm.loop !13

73:                                               ; preds = %52
  %74 = load i32, ptr %9, align 4, !tbaa !5
  call void @_Z3NTTiPii(i32 noundef %74, ptr noundef @f, i32 noundef -1)
  %75 = load ptr, ptr %8, align 8, !tbaa !9
  %76 = load i32, ptr %5, align 4, !tbaa !5
  %77 = sext i32 %76 to i64
  %78 = mul i64 %77, 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %75, ptr align 16 @f, i64 %78, i1 false)
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  ret void
}

; 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) #2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 = !{!"any pointer", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !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"

@f = external dso_local global [524289 x i32], align 16
@g = external dso_local global [524289 x i32], align 16

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z3NTTiPii(i32 noundef, ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_Z8poly_muliPiS_S_(i32 noundef %0, ptr nocapture noundef readonly %1, ptr nocapture noundef readonly %2, ptr nocapture noundef writeonly %3) local_unnamed_addr #0 {
  %5 = shl i32 %0, 1
  %6 = add i32 %5, -2
  br label %7

7:                                                ; preds = %7, %4
  %.023 = phi i32 [ 1, %4 ], [ %8, %7 ]
  %.not = icmp sgt i32 %.023, %6
  %8 = shl i32 %.023, 1
  br i1 %.not, label %9, label %7, !llvm.loop !5

9:                                                ; preds = %7
  %10 = sext i32 %0 to i64
  %11 = shl nsw i64 %10, 2
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 16 @f, ptr align 4 %1, i64 %11, i1 false)
  %12 = getelementptr inbounds i32, ptr @f, i64 %10
  %13 = sub nsw i32 %.023, %0
  %14 = sext i32 %13 to i64
  %15 = shl nsw i64 %14, 2
  tail call void @llvm.memset.p0.i64(ptr nonnull align 4 %12, i8 0, i64 %15, i1 false)
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 16 @g, ptr align 4 %2, i64 %11, i1 false)
  %16 = getelementptr inbounds i32, ptr @g, i64 %10
  tail call void @llvm.memset.p0.i64(ptr nonnull align 4 %16, i8 0, i64 %15, i1 false)
  tail call void @_Z3NTTiPii(i32 noundef %.023, ptr noundef nonnull @f, i32 noundef 1)
  tail call void @_Z3NTTiPii(i32 noundef %.023, ptr noundef nonnull @g, i32 noundef 1)
  %17 = icmp sgt i32 %.023, 0
  br i1 %17, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %9
  %wide.trip.count = zext nneg i32 %.023 to i64
  %xtraiter = and i64 %wide.trip.count, 1
  %18 = icmp eq i32 %.023, 1
  br i1 %18, 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
  %19 = getelementptr inbounds [524289 x i32], ptr @f, i64 0, i64 %indvars.iv.unr
  %20 = load i32, ptr %19, align 4, !tbaa !7
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [524289 x i32], ptr @g, i64 0, i64 %indvars.iv.unr
  %23 = load i32, ptr %22, align 4, !tbaa !7
  %24 = sext i32 %23 to i64
  %25 = mul nsw i64 %24, %21
  %26 = srem i64 %25, 998244353
  %27 = trunc nsw i64 %26 to i32
  store i32 %27, ptr %19, align 4, !tbaa !7
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph.epil, %._crit_edge.loopexit.unr-lcssa, %9
  tail call void @_Z3NTTiPii(i32 noundef %.023, ptr noundef nonnull @f, i32 noundef -1)
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 4 %3, ptr nonnull align 16 @f, i64 %11, i1 false)
  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 ]
  %28 = getelementptr inbounds [524289 x i32], ptr @f, i64 0, i64 %indvars.iv
  %29 = load i32, ptr %28, align 8, !tbaa !7
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [524289 x i32], ptr @g, i64 0, i64 %indvars.iv
  %32 = load i32, ptr %31, align 8, !tbaa !7
  %33 = sext i32 %32 to i64
  %34 = mul nsw i64 %33, %30
  %35 = srem i64 %34, 998244353
  %36 = trunc nsw i64 %35 to i32
  store i32 %36, ptr %28, align 8, !tbaa !7
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %37 = getelementptr inbounds [524289 x i32], ptr @f, i64 0, i64 %indvars.iv.next
  %38 = load i32, ptr %37, align 4, !tbaa !7
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [524289 x i32], ptr @g, i64 0, i64 %indvars.iv.next
  %41 = load i32, ptr %40, align 4, !tbaa !7
  %42 = sext i32 %41 to i64
  %43 = mul nsw i64 %42, %39
  %44 = srem i64 %43, 998244353
  %45 = trunc nsw i64 %44 to i32
  store i32 %45, ptr %37, align 4, !tbaa !7
  %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 !11
}

; 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) #1

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }

!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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !8, i64 0}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = distinct !{!11, !6}


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