; LLVM IR from lzyrapx/Competitive-Programming :: BZOJ/BZOJ 3456（多项式求逆+NTT）.ll (Z7ployInvPiS_ii)

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

@mod = external dso_local global i64, align 8
@d = external dso_local global [1000000 x i32], align 16

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z7ployInvPiS_ii(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3) #2 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  store i32 %3, ptr %8, align 4, !tbaa !9
  %10 = load i32, ptr %7, align 4, !tbaa !9
  %11 = icmp eq i32 %10, 1
  br i1 %11, label %12, label %23

12:                                               ; preds = %4
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = getelementptr inbounds i32, ptr %13, i64 0
  %15 = load i32, ptr %14, align 4, !tbaa !9
  %16 = sext i32 %15 to i64
  %17 = load i64, ptr @mod, align 8, !tbaa !11
  %18 = sub nsw i64 %17, 2
  %19 = call noundef i64 @_Z6qpowerxx(i64 noundef %16, i64 noundef %18)
  %20 = trunc i64 %19 to i32
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = getelementptr inbounds i32, ptr %21, i64 0
  store i32 %20, ptr %22, align 4, !tbaa !9
  br label %107

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

49:                                               ; preds = %91, %23
  %50 = load i32, ptr %9, align 4, !tbaa !9
  %51 = load i32, ptr %7, align 4, !tbaa !9
  %52 = shl i32 %51, 1
  %53 = icmp slt i32 %50, %52
  br i1 %53, label %55, label %54

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

55:                                               ; preds = %49
  %56 = load ptr, ptr %6, align 8, !tbaa !5
  %57 = load i32, ptr %9, align 4, !tbaa !9
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds i32, ptr %56, i64 %58
  %60 = load i32, ptr %59, align 4, !tbaa !9
  %61 = sext i32 %60 to i64
  %62 = mul nsw i64 1, %61
  %63 = load i32, ptr %9, align 4, !tbaa !9
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [1000000 x i32], ptr @d, i64 0, i64 %64
  %66 = load i32, ptr %65, align 4, !tbaa !9
  %67 = sext i32 %66 to i64
  %68 = mul nsw i64 1, %67
  %69 = load ptr, ptr %6, align 8, !tbaa !5
  %70 = load i32, ptr %9, align 4, !tbaa !9
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds i32, ptr %69, i64 %71
  %73 = load i32, ptr %72, align 4, !tbaa !9
  %74 = sext i32 %73 to i64
  %75 = mul nsw i64 %68, %74
  %76 = load i64, ptr @mod, align 8, !tbaa !11
  %77 = srem i64 %75, %76
  %78 = sub nsw i64 2, %77
  %79 = load i64, ptr @mod, align 8, !tbaa !11
  %80 = add nsw i64 %78, %79
  %81 = load i64, ptr @mod, align 8, !tbaa !11
  %82 = srem i64 %80, %81
  %83 = mul nsw i64 %62, %82
  %84 = load i64, ptr @mod, align 8, !tbaa !11
  %85 = srem i64 %83, %84
  %86 = trunc i64 %85 to i32
  %87 = load ptr, ptr %6, align 8, !tbaa !5
  %88 = load i32, ptr %9, align 4, !tbaa !9
  %89 = sext i32 %88 to i64
  %90 = getelementptr inbounds i32, ptr %87, i64 %89
  store i32 %86, ptr %90, align 4, !tbaa !9
  br label %91

91:                                               ; preds = %55
  %92 = load i32, ptr %9, align 4, !tbaa !9
  %93 = add nsw i32 %92, 1
  store i32 %93, ptr %9, align 4, !tbaa !9
  br label %49, !llvm.loop !13

94:                                               ; preds = %54
  %95 = load ptr, ptr %6, align 8, !tbaa !5
  %96 = load i32, ptr %7, align 4, !tbaa !9
  %97 = shl i32 %96, 1
  %98 = load i32, ptr %8, align 4, !tbaa !9
  %99 = add nsw i32 %98, 1
  call void @_Z3NTTPiiii(ptr noundef %95, i32 noundef -1, i32 noundef %97, i32 noundef %99)
  %100 = load ptr, ptr %6, align 8, !tbaa !5
  %101 = load i32, ptr %7, align 4, !tbaa !9
  %102 = sext i32 %101 to i64
  %103 = getelementptr inbounds i32, ptr %100, i64 %102
  %104 = load i32, ptr %7, align 4, !tbaa !9
  %105 = sext i32 %104 to i64
  %106 = mul i64 %105, 4
  call void @llvm.memset.p0.i64(ptr align 4 %103, i8 0, i64 %106, i1 false)
  br label %107

107:                                              ; preds = %94, %12
  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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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

@mod = external dso_local local_unnamed_addr global i64, align 8
@d = external dso_local global [1000000 x i32], align 16

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

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

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

6:                                                ; preds = %4
  %7 = load i32, ptr %0, align 4, !tbaa !5
  %8 = sext i32 %7 to i64
  %9 = load i64, ptr @mod, align 8, !tbaa !9
  %10 = add nsw i64 %9, -2
  %11 = tail call noundef i64 @_Z6qpowerxx(i64 noundef %8, i64 noundef %10)
  %12 = trunc i64 %11 to i32
  store i32 %12, ptr %1, align 4, !tbaa !5
  br label %38

13:                                               ; preds = %4
  %14 = ashr i32 %2, 1
  %15 = add nsw i32 %3, -1
  tail call void @_Z7ployInvPiS_ii(ptr noundef %0, ptr noundef %1, i32 noundef %14, i32 noundef %15)
  %16 = sext i32 %2 to i64
  %17 = shl nsw i64 %16, 2
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 16 @d, ptr align 4 %0, i64 %17, i1 false)
  %18 = getelementptr inbounds i32, ptr @d, i64 %16
  tail call void @llvm.memset.p0.i64(ptr nonnull align 4 %18, i8 0, i64 %17, i1 false)
  %19 = shl i32 %2, 1
  %20 = add nsw i32 %3, 1
  tail call void @_Z3NTTPiiii(ptr noundef nonnull @d, i32 noundef 1, i32 noundef %19, i32 noundef %20)
  tail call void @_Z3NTTPiiii(ptr noundef %1, i32 noundef 1, i32 noundef %19, i32 noundef %20)
  %21 = icmp sgt i32 %19, 0
  br i1 %21, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %13
  %22 = load i64, ptr @mod, align 8, !tbaa !9
  %reass.sub = add i64 %22, 2
  %wide.trip.count = zext nneg i32 %19 to i64
  br label %24

._crit_edge:                                      ; preds = %24, %13
  tail call void @_Z3NTTPiiii(ptr noundef %1, i32 noundef -1, i32 noundef %19, i32 noundef %20)
  %23 = getelementptr inbounds i32, ptr %1, i64 %16
  tail call void @llvm.memset.p0.i64(ptr align 4 %23, i8 0, i64 %17, i1 false)
  br label %38

24:                                               ; preds = %.lr.ph, %24
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %24 ]
  %25 = getelementptr inbounds i32, ptr %1, i64 %indvars.iv
  %26 = load i32, ptr %25, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [1000000 x i32], ptr @d, i64 0, i64 %indvars.iv
  %29 = load i32, ptr %28, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = mul nsw i64 %30, %27
  %32 = srem i64 %31, %22
  %33 = sub i64 %reass.sub, %32
  %34 = srem i64 %33, %22
  %35 = mul nsw i64 %34, %27
  %36 = srem i64 %35, %22
  %37 = trunc i64 %36 to i32
  store i32 %37, ptr %25, align 4, !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 %24, !llvm.loop !11

38:                                               ; preds = %._crit_edge, %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 = !{!"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"}


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