; LLVM IR from lzyrapx/Competitive-Programming :: BZOJ/BZOJ 4555（多项式求逆）.ll (Z7polyInvPiS_i)

; 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
@c = external dso_local global [262145 x i32], align 16
@tmp = external dso_local global [262145 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 uwtable
declare dso_local void @_Z7polyMulPiiS_iS_(ptr noundef, i32 noundef, ptr noundef, i32 noundef, ptr noundef) #2

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

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

22:                                               ; preds = %3
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = load i32, ptr %6, align 4, !tbaa !9
  %26 = add nsw i32 %25, 1
  %27 = ashr i32 %26, 1
  call void @_Z7polyInvPiS_i(ptr noundef %23, ptr noundef %24, i32 noundef %27)
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = load i32, ptr %6, align 4, !tbaa !9
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds i32, ptr %29, i64 %31
  %33 = call noundef ptr @_ZSt4copyIPiS0_ET0_T_S2_S1_(ptr noundef %28, ptr noundef %32, ptr noundef @tmp)
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %34 = load i32, ptr %6, align 4, !tbaa !9
  %35 = add nsw i32 %34, 1
  %36 = ashr i32 %35, 1
  %37 = load i32, ptr %6, align 4, !tbaa !9
  %38 = add nsw i32 %36, %37
  %39 = sub nsw i32 %38, 1
  store i32 %39, ptr %7, align 4, !tbaa !9
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = load i32, ptr %6, align 4, !tbaa !9
  %42 = add nsw i32 %41, 1
  %43 = ashr i32 %42, 1
  %44 = load i32, ptr %6, align 4, !tbaa !9
  call void @_Z7polyMulPiiS_iS_(ptr noundef %40, i32 noundef %43, ptr noundef @tmp, i32 noundef %44, ptr noundef @c)
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %45

45:                                               ; preds = %65, %22
  %46 = load i32, ptr %8, align 4, !tbaa !9
  %47 = load i32, ptr %7, align 4, !tbaa !9
  %48 = icmp slt i32 %46, %47
  br i1 %48, label %50, label %49

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

50:                                               ; preds = %45
  %51 = load i32, ptr %8, align 4, !tbaa !9
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [262145 x i32], ptr @c, i64 0, i64 %52
  %54 = load i32, ptr %53, align 4, !tbaa !9
  %55 = sub nsw i32 0, %54
  %56 = sext i32 %55 to i64
  %57 = load i64, ptr @mod, align 8, !tbaa !11
  %58 = add nsw i64 %56, %57
  %59 = load i64, ptr @mod, align 8, !tbaa !11
  %60 = srem i64 %58, %59
  %61 = trunc i64 %60 to i32
  %62 = load i32, ptr %8, align 4, !tbaa !9
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds [262145 x i32], ptr @c, i64 0, i64 %63
  store i32 %61, ptr %64, align 4, !tbaa !9
  br label %65

65:                                               ; preds = %50
  %66 = load i32, ptr %8, align 4, !tbaa !9
  %67 = add nsw i32 %66, 1
  store i32 %67, ptr %8, align 4, !tbaa !9
  br label %45, !llvm.loop !13

68:                                               ; preds = %49
  %69 = load i64, ptr @mod, align 8, !tbaa !11
  %70 = load i32, ptr @c, align 16, !tbaa !9
  %71 = add nsw i32 %70, 2
  store i32 %71, ptr @c, align 16, !tbaa !9
  %72 = load i32, ptr @c, align 16, !tbaa !9
  %73 = sext i32 %72 to i64
  %74 = srem i64 %73, %69
  %75 = trunc i64 %74 to i32
  store i32 %75, ptr @c, align 16, !tbaa !9
  %76 = load ptr, ptr %5, align 8, !tbaa !5
  %77 = load i32, ptr %6, align 4, !tbaa !9
  %78 = add nsw i32 %77, 1
  %79 = ashr i32 %78, 1
  %80 = load i32, ptr %6, align 4, !tbaa !9
  call void @_Z7polyMulPiiS_iS_(ptr noundef %76, i32 noundef %79, ptr noundef @c, i32 noundef %80, ptr noundef @tmp)
  %81 = load i32, ptr %6, align 4, !tbaa !9
  %82 = sext i32 %81 to i64
  %83 = getelementptr inbounds i32, ptr @tmp, i64 %82
  %84 = load ptr, ptr %5, align 8, !tbaa !5
  %85 = call noundef ptr @_ZSt4copyIPiS0_ET0_T_S2_S1_(ptr noundef @tmp, ptr noundef %83, ptr noundef %84)
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %86

86:                                               ; preds = %68, %11
  ret void
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_ZSt4copyIPiS0_ET0_T_S2_S1_(ptr noundef, 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 = !{!"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
@c = external dso_local global [262145 x i32], align 16
@tmp = external dso_local global [262145 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 uwtable
declare dso_local void @_Z7polyMulPiiS_iS_(ptr noundef, i32 noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z7polyInvPiS_i(ptr noundef %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #1 {
  %4 = icmp eq i32 %2, 1
  br i1 %4, label %5, label %12

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

12:                                               ; preds = %3
  %13 = add nsw i32 %2, 1
  %14 = ashr i32 %13, 1
  tail call void @_Z7polyInvPiS_i(ptr noundef %0, ptr noundef %1, i32 noundef %14)
  %15 = sext i32 %2 to i64
  %16 = getelementptr inbounds i32, ptr %0, i64 %15
  %17 = tail call noundef ptr @_ZSt4copyIPiS0_ET0_T_S2_S1_(ptr noundef %0, ptr noundef %16, ptr noundef nonnull @tmp)
  %18 = add i32 %2, -1
  %19 = add i32 %18, %14
  tail call void @_Z7polyMulPiiS_iS_(ptr noundef %1, i32 noundef %14, ptr noundef nonnull @tmp, i32 noundef %2, ptr noundef nonnull @c)
  %20 = icmp sgt i32 %19, 0
  %.pre = load i64, ptr @mod, align 8, !tbaa !9
  br i1 %20, label %.lr.ph, label %._crit_edge

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

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

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

._crit_edge.loopexit.epilog-lcssa:                ; preds = %._crit_edge.loopexit.unr-lcssa
  %22 = getelementptr inbounds [262145 x i32], ptr @c, i64 0, i64 %indvars.iv.unr
  %23 = load i32, ptr %22, align 4, !tbaa !5
  %24 = sub nsw i32 0, %23
  %25 = sext i32 %24 to i64
  %26 = add nsw i64 %.pre, %25
  %27 = srem i64 %26, %.pre
  %28 = trunc i64 %27 to i32
  store i32 %28, ptr %22, align 4, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit.epilog-lcssa, %._crit_edge.loopexit.unr-lcssa, %12
  %29 = load i32, ptr @c, align 16, !tbaa !5
  %30 = add nsw i32 %29, 2
  %31 = sext i32 %30 to i64
  %32 = srem i64 %31, %.pre
  %33 = trunc nsw i64 %32 to i32
  store i32 %33, ptr @c, align 16, !tbaa !5
  tail call void @_Z7polyMulPiiS_iS_(ptr noundef %1, i32 noundef %14, ptr noundef nonnull @c, i32 noundef %2, ptr noundef nonnull @tmp)
  %34 = getelementptr inbounds i32, ptr @tmp, i64 %15
  %35 = tail call noundef ptr @_ZSt4copyIPiS0_ET0_T_S2_S1_(ptr noundef nonnull @tmp, ptr noundef nonnull %34, ptr noundef %1)
  br label %51

36:                                               ; preds = %36, %.lr.ph.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.new ], [ %indvars.iv.next.1, %36 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.1, %36 ]
  %37 = getelementptr inbounds [262145 x i32], ptr @c, i64 0, i64 %indvars.iv
  %38 = load i32, ptr %37, align 8, !tbaa !5
  %39 = sub nsw i32 0, %38
  %40 = sext i32 %39 to i64
  %41 = add nsw i64 %.pre, %40
  %42 = srem i64 %41, %.pre
  %43 = trunc i64 %42 to i32
  store i32 %43, ptr %37, align 8, !tbaa !5
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %44 = getelementptr inbounds [262145 x i32], ptr @c, i64 0, i64 %indvars.iv.next
  %45 = load i32, ptr %44, align 4, !tbaa !5
  %46 = sub nsw i32 0, %45
  %47 = sext i32 %46 to i64
  %48 = add nsw i64 %.pre, %47
  %49 = srem i64 %48, %.pre
  %50 = trunc i64 %49 to i32
  store i32 %50, ptr %44, align 4, !tbaa !5
  %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 %36, !llvm.loop !11

51:                                               ; preds = %._crit_edge, %5
  ret void
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_ZSt4copyIPiS0_ET0_T_S2_S1_(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #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 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" }

!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,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass