; LLVM IR from tangjz/acm-icpc :: 51nod/1514.ll (Z8poly_inviPxS_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"

@eps = external dso_local global [262145 x i64], align 16
@inv_eps = external dso_local global [262145 x i64], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_Z7mod_powxx(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 nounwind uwtable
declare dso_local void @_Z3NTTiPxS_(i32 noundef, ptr noundef, ptr noundef) #0

; Function Attrs: mustprogress uwtable
define dso_local void @_Z8poly_inviPxS_S_(i32 noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #2 {
  %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
  %11 = alloca i64, align 8
  %12 = 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
  %13 = load i32, ptr %5, align 4, !tbaa !5
  %14 = icmp eq i32 %13, 1
  br i1 %14, label %15, label %22

15:                                               ; preds = %4
  %16 = load ptr, ptr %6, align 8, !tbaa !9
  %17 = getelementptr inbounds i64, ptr %16, i64 0
  %18 = load i64, ptr %17, align 8, !tbaa !11
  %19 = call noundef i64 @_Z7mod_powxx(i64 noundef %18, i64 noundef 998244351)
  %20 = load ptr, ptr %7, align 8, !tbaa !9
  %21 = getelementptr inbounds i64, ptr %20, i64 0
  store i64 %19, ptr %21, align 8, !tbaa !11
  br label %140

22:                                               ; preds = %4
  %23 = load i32, ptr %5, align 4, !tbaa !5
  %24 = add nsw i32 %23, 1
  %25 = ashr i32 %24, 1
  %26 = load ptr, ptr %6, align 8, !tbaa !9
  %27 = load ptr, ptr %7, align 8, !tbaa !9
  %28 = load ptr, ptr %8, align 8, !tbaa !9
  call void @_Z8poly_inviPxS_S_(i32 noundef %25, ptr noundef %26, ptr noundef %27, ptr noundef %28)
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  store i32 1, ptr %9, align 4, !tbaa !5
  br label %29

29:                                               ; preds = %34, %22
  %30 = load i32, ptr %9, align 4, !tbaa !5
  %31 = load i32, ptr %5, align 4, !tbaa !5
  %32 = shl i32 %31, 1
  %33 = icmp slt i32 %30, %32
  br i1 %33, label %34, label %37

34:                                               ; preds = %29
  %35 = load i32, ptr %9, align 4, !tbaa !5
  %36 = shl i32 %35, 1
  store i32 %36, ptr %9, align 4, !tbaa !5
  br label %29, !llvm.loop !13

37:                                               ; preds = %29
  %38 = load ptr, ptr %8, align 8, !tbaa !9
  %39 = load ptr, ptr %6, align 8, !tbaa !9
  %40 = load i32, ptr %5, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = mul i64 %41, 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %38, ptr align 8 %39, i64 %42, i1 false)
  %43 = load ptr, ptr %8, align 8, !tbaa !9
  %44 = load i32, ptr %5, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds i64, ptr %43, i64 %45
  %47 = load i32, ptr %9, align 4, !tbaa !5
  %48 = load i32, ptr %5, align 4, !tbaa !5
  %49 = sub nsw i32 %47, %48
  %50 = sext i32 %49 to i64
  %51 = mul i64 %50, 8
  call void @llvm.memset.p0.i64(ptr align 8 %46, i8 0, i64 %51, i1 false)
  %52 = load i32, ptr %9, align 4, !tbaa !5
  %53 = load ptr, ptr %8, align 8, !tbaa !9
  call void @_Z3NTTiPxS_(i32 noundef %52, ptr noundef %53, ptr noundef @eps)
  %54 = load i32, ptr %9, align 4, !tbaa !5
  %55 = load ptr, ptr %7, align 8, !tbaa !9
  call void @_Z3NTTiPxS_(i32 noundef %54, ptr noundef %55, ptr noundef @eps)
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  store i32 0, ptr %10, align 4, !tbaa !5
  br label %56

56:                                               ; preds = %100, %37
  %57 = load i32, ptr %10, align 4, !tbaa !5
  %58 = load i32, ptr %9, align 4, !tbaa !5
  %59 = icmp slt i32 %57, %58
  br i1 %59, label %61, label %60

60:                                               ; preds = %56
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  br label %103

61:                                               ; preds = %56
  %62 = load ptr, ptr %8, align 8, !tbaa !9
  %63 = load i32, ptr %10, align 4, !tbaa !5
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds i64, ptr %62, i64 %64
  %66 = load i64, ptr %65, align 8, !tbaa !11
  %67 = load ptr, ptr %7, align 8, !tbaa !9
  %68 = load i32, ptr %10, align 4, !tbaa !5
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds i64, ptr %67, i64 %69
  %71 = load i64, ptr %70, align 8, !tbaa !11
  %72 = mul nsw i64 %66, %71
  %73 = srem i64 %72, 998244353
  %74 = sub nsw i64 2, %73
  %75 = load ptr, ptr %7, align 8, !tbaa !9
  %76 = load i32, ptr %10, align 4, !tbaa !5
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds i64, ptr %75, i64 %77
  %79 = load i64, ptr %78, align 8, !tbaa !11
  %80 = mul nsw i64 %74, %79
  %81 = srem i64 %80, 998244353
  %82 = load ptr, ptr %7, align 8, !tbaa !9
  %83 = load i32, ptr %10, align 4, !tbaa !5
  %84 = sext i32 %83 to i64
  %85 = getelementptr inbounds i64, ptr %82, i64 %84
  store i64 %81, ptr %85, align 8, !tbaa !11
  %86 = load ptr, ptr %7, align 8, !tbaa !9
  %87 = load i32, ptr %10, align 4, !tbaa !5
  %88 = sext i32 %87 to i64
  %89 = getelementptr inbounds i64, ptr %86, i64 %88
  %90 = load i64, ptr %89, align 8, !tbaa !11
  %91 = icmp slt i64 %90, 0
  br i1 %91, label %92, label %99

92:                                               ; preds = %61
  %93 = load ptr, ptr %7, align 8, !tbaa !9
  %94 = load i32, ptr %10, align 4, !tbaa !5
  %95 = sext i32 %94 to i64
  %96 = getelementptr inbounds i64, ptr %93, i64 %95
  %97 = load i64, ptr %96, align 8, !tbaa !11
  %98 = add nsw i64 %97, 998244353
  store i64 %98, ptr %96, align 8, !tbaa !11
  br label %99

99:                                               ; preds = %92, %61
  br label %100

100:                                              ; preds = %99
  %101 = load i32, ptr %10, align 4, !tbaa !5
  %102 = add nsw i32 %101, 1
  store i32 %102, ptr %10, align 4, !tbaa !5
  br label %56, !llvm.loop !15

103:                                              ; preds = %60
  %104 = load i32, ptr %9, align 4, !tbaa !5
  %105 = load ptr, ptr %7, align 8, !tbaa !9
  call void @_Z3NTTiPxS_(i32 noundef %104, ptr noundef %105, ptr noundef @inv_eps)
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  %106 = load i32, ptr %9, align 4, !tbaa !5
  %107 = sext i32 %106 to i64
  %108 = call noundef i64 @_Z7mod_powxx(i64 noundef %107, i64 noundef 998244351)
  store i64 %108, ptr %11, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #5
  store i32 0, ptr %12, align 4, !tbaa !5
  br label %109

109:                                              ; preds = %127, %103
  %110 = load i32, ptr %12, align 4, !tbaa !5
  %111 = load i32, ptr %9, align 4, !tbaa !5
  %112 = icmp slt i32 %110, %111
  br i1 %112, label %114, label %113

113:                                              ; preds = %109
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #5
  br label %130

114:                                              ; preds = %109
  %115 = load ptr, ptr %7, align 8, !tbaa !9
  %116 = load i32, ptr %12, align 4, !tbaa !5
  %117 = sext i32 %116 to i64
  %118 = getelementptr inbounds i64, ptr %115, i64 %117
  %119 = load i64, ptr %118, align 8, !tbaa !11
  %120 = load i64, ptr %11, align 8, !tbaa !11
  %121 = mul nsw i64 %119, %120
  %122 = srem i64 %121, 998244353
  %123 = load ptr, ptr %7, align 8, !tbaa !9
  %124 = load i32, ptr %12, align 4, !tbaa !5
  %125 = sext i32 %124 to i64
  %126 = getelementptr inbounds i64, ptr %123, i64 %125
  store i64 %122, ptr %126, align 8, !tbaa !11
  br label %127

127:                                              ; preds = %114
  %128 = load i32, ptr %12, align 4, !tbaa !5
  %129 = add nsw i32 %128, 1
  store i32 %129, ptr %12, align 4, !tbaa !5
  br label %109, !llvm.loop !16

130:                                              ; preds = %113
  %131 = load ptr, ptr %7, align 8, !tbaa !9
  %132 = load i32, ptr %5, align 4, !tbaa !5
  %133 = sext i32 %132 to i64
  %134 = getelementptr inbounds i64, ptr %131, i64 %133
  %135 = load i32, ptr %9, align 4, !tbaa !5
  %136 = load i32, ptr %5, align 4, !tbaa !5
  %137 = sub nsw i32 %135, %136
  %138 = sext i32 %137 to i64
  %139 = mul i64 %138, 8
  call void @llvm.memset.p0.i64(ptr align 8 %134, i8 0, i64 %139, i1 false)
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  br label %140

140:                                              ; preds = %130, %15
  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) #3

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

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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { 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 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !14}


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

@eps = external dso_local global [262145 x i64], align 16
@inv_eps = external dso_local global [262145 x i64], align 16

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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z8poly_inviPxS_S_(i32 noundef %0, ptr nocapture noundef readonly %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #0 {
  %5 = icmp eq i32 %0, 1
  br i1 %5, label %6, label %9

6:                                                ; preds = %4
  %7 = load i64, ptr %1, align 8, !tbaa !5
  %8 = tail call noundef i64 @_Z7mod_powxx(i64 noundef %7, i64 noundef 998244351)
  store i64 %8, ptr %2, align 8, !tbaa !5
  br label %51

9:                                                ; preds = %4
  %10 = add nsw i32 %0, 1
  %11 = ashr i32 %10, 1
  tail call void @_Z8poly_inviPxS_S_(i32 noundef %11, ptr noundef %1, ptr noundef %2, ptr noundef %3)
  %12 = shl i32 %0, 1
  br label %13

13:                                               ; preds = %13, %9
  %.050 = phi i32 [ 1, %9 ], [ %15, %13 ]
  %14 = icmp slt i32 %.050, %12
  %15 = shl i32 %.050, 1
  br i1 %14, label %13, label %16, !llvm.loop !9

16:                                               ; preds = %13
  %17 = sext i32 %0 to i64
  %18 = shl nsw i64 %17, 3
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 8 %3, ptr align 8 %1, i64 %18, i1 false)
  %19 = getelementptr inbounds i64, ptr %3, i64 %17
  %20 = sub nsw i32 %.050, %0
  %21 = sext i32 %20 to i64
  %22 = shl nsw i64 %21, 3
  tail call void @llvm.memset.p0.i64(ptr align 8 %19, i8 0, i64 %22, i1 false)
  tail call void @_Z3NTTiPxS_(i32 noundef %.050, ptr noundef %3, ptr noundef nonnull @eps)
  tail call void @_Z3NTTiPxS_(i32 noundef %.050, ptr noundef %2, ptr noundef nonnull @eps)
  %23 = icmp sgt i32 %.050, 0
  br i1 %23, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %16
  %wide.trip.count = zext nneg i32 %.050 to i64
  br label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %16
  tail call void @_Z3NTTiPxS_(i32 noundef %.050, ptr noundef %2, ptr noundef nonnull @inv_eps)
  %24 = sext i32 %.050 to i64
  %25 = tail call noundef i64 @_Z7mod_powxx(i64 noundef %24, i64 noundef 998244351)
  br i1 %23, label %.lr.ph57.preheader, label %._crit_edge58

.lr.ph57.preheader:                               ; preds = %._crit_edge
  %wide.trip.count63 = zext nneg i32 %.050 to i64
  %xtraiter = and i64 %wide.trip.count63, 1
  %26 = icmp eq i32 %.050, 1
  br i1 %26, label %._crit_edge58.loopexit.unr-lcssa, label %.lr.ph57.preheader.new

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

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %27 = getelementptr inbounds i64, ptr %3, i64 %indvars.iv
  %28 = load i64, ptr %27, align 8, !tbaa !5
  %29 = getelementptr inbounds i64, ptr %2, i64 %indvars.iv
  %30 = load i64, ptr %29, align 8, !tbaa !5
  %31 = mul nsw i64 %30, %28
  %32 = srem i64 %31, 998244353
  %33 = sub nsw i64 2, %32
  %34 = mul nsw i64 %33, %30
  %35 = srem i64 %34, 998244353
  %36 = icmp slt i64 %35, 0
  %37 = add nsw i64 %35, 998244353
  %spec.select = select i1 %36, i64 %37, i64 %35
  store i64 %spec.select, ptr %29, align 8, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !11

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

.lr.ph57.epil:                                    ; preds = %._crit_edge58.loopexit.unr-lcssa
  %38 = getelementptr inbounds i64, ptr %2, i64 %indvars.iv60.unr
  %39 = load i64, ptr %38, align 8, !tbaa !5
  %40 = mul nsw i64 %39, %25
  %41 = srem i64 %40, 998244353
  store i64 %41, ptr %38, align 8, !tbaa !5
  br label %._crit_edge58

._crit_edge58:                                    ; preds = %.lr.ph57.epil, %._crit_edge58.loopexit.unr-lcssa, %._crit_edge
  %42 = getelementptr inbounds i64, ptr %2, i64 %17
  tail call void @llvm.memset.p0.i64(ptr align 8 %42, i8 0, i64 %22, i1 false)
  br label %51

.lr.ph57:                                         ; preds = %.lr.ph57, %.lr.ph57.preheader.new
  %indvars.iv60 = phi i64 [ 0, %.lr.ph57.preheader.new ], [ %indvars.iv.next61.1, %.lr.ph57 ]
  %niter = phi i64 [ 0, %.lr.ph57.preheader.new ], [ %niter.next.1, %.lr.ph57 ]
  %43 = getelementptr inbounds i64, ptr %2, i64 %indvars.iv60
  %44 = load i64, ptr %43, align 8, !tbaa !5
  %45 = mul nsw i64 %44, %25
  %46 = srem i64 %45, 998244353
  store i64 %46, ptr %43, align 8, !tbaa !5
  %indvars.iv.next61 = or disjoint i64 %indvars.iv60, 1
  %47 = getelementptr inbounds i64, ptr %2, i64 %indvars.iv.next61
  %48 = load i64, ptr %47, align 8, !tbaa !5
  %49 = mul nsw i64 %48, %25
  %50 = srem i64 %49, 998244353
  store i64 %50, ptr %47, align 8, !tbaa !5
  %indvars.iv.next61.1 = add nuw nsw i64 %indvars.iv60, 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_edge58.loopexit.unr-lcssa, label %.lr.ph57, !llvm.loop !12

51:                                               ; preds = %._crit_edge58, %6
  ret void
}

; 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 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 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 = !{!6, !6, i64 0}
!6 = !{!"long long", !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}


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