; LLVM IR from tangjz/acm-icpc :: hdu/6414.ll (Z8poly_dif4PolyRS_)

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

%struct.Poly = type { i32, [2001 x i32] }

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z9poly_normR4Poly(ptr noundef nonnull align 4 dereferenceable(8008)) #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
define dso_local void @_Z8poly_dif4PolyRS_(ptr noundef byval(%struct.Poly) align 8 %0, ptr noundef nonnull align 4 dereferenceable(8008) %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  store ptr %1, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds %struct.Poly, ptr %0, i32 0, i32 0
  %6 = load i32, ptr %5, align 8, !tbaa !9
  %7 = icmp ne i32 %6, 0
  br i1 %7, label %11, label %8

8:                                                ; preds = %2
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.Poly, ptr %9, i32 0, i32 0
  store i32 -1, ptr %10, align 4, !tbaa !9
  br label %48

11:                                               ; preds = %2
  %12 = getelementptr inbounds %struct.Poly, ptr %0, i32 0, i32 0
  %13 = load i32, ptr %12, align 8, !tbaa !9
  %14 = sub nsw i32 %13, 1
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.Poly, ptr %15, i32 0, i32 0
  store i32 %14, ptr %16, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  store i32 0, ptr %4, align 4, !tbaa !12
  br label %17

17:                                               ; preds = %43, %11
  %18 = load i32, ptr %4, align 4, !tbaa !12
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.Poly, ptr %19, i32 0, i32 0
  %21 = load i32, ptr %20, align 4, !tbaa !9
  %22 = icmp sle i32 %18, %21
  br i1 %22, label %24, label %23

23:                                               ; preds = %17
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  br label %46

24:                                               ; preds = %17
  %25 = load i32, ptr %4, align 4, !tbaa !12
  %26 = sext i32 %25 to i64
  %27 = add nsw i64 %26, 1
  %28 = getelementptr inbounds %struct.Poly, ptr %0, i32 0, i32 1
  %29 = load i32, ptr %4, align 4, !tbaa !12
  %30 = add nsw i32 %29, 1
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [2001 x i32], ptr %28, i64 0, i64 %31
  %33 = load i32, ptr %32, align 4, !tbaa !12
  %34 = sext i32 %33 to i64
  %35 = mul nsw i64 %27, %34
  %36 = srem i64 %35, 998244353
  %37 = trunc i64 %36 to i32
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.Poly, ptr %38, i32 0, i32 1
  %40 = load i32, ptr %4, align 4, !tbaa !12
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [2001 x i32], ptr %39, i64 0, i64 %41
  store i32 %37, ptr %42, align 4, !tbaa !12
  br label %43

43:                                               ; preds = %24
  %44 = load i32, ptr %4, align 4, !tbaa !12
  %45 = add nsw i32 %44, 1
  store i32 %45, ptr %4, align 4, !tbaa !12
  br label %17, !llvm.loop !13

46:                                               ; preds = %23
  %47 = load ptr, ptr %3, align 8, !tbaa !5
  call void @_Z9poly_normR4Poly(ptr noundef nonnull align 4 dereferenceable(8008) %47)
  br label %48

48:                                               ; preds = %46, %8
  ret void
}

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"_ZTS4Poly", !11, i64 0, !7, i64 4}
!11 = !{!"int", !7, i64 0}
!12 = !{!11, !11, 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"

%struct.Poly = type { i32, [2001 x i32] }

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z9poly_normR4Poly(ptr noundef nonnull align 4 dereferenceable(8008)) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_Z8poly_dif4PolyRS_(ptr nocapture noundef readonly byval(%struct.Poly) align 8 %0, ptr noundef nonnull align 4 dereferenceable(8008) %1) local_unnamed_addr #0 {
  %3 = load i32, ptr %0, align 8, !tbaa !5
  %.not = icmp eq i32 %3, 0
  br i1 %.not, label %4, label %5

4:                                                ; preds = %2
  store i32 -1, ptr %1, align 4, !tbaa !5
  br label %35

5:                                                ; preds = %2
  %6 = add nsw i32 %3, -1
  store i32 %6, ptr %1, align 4, !tbaa !5
  %.not10.not11 = icmp sgt i32 %3, 0
  br i1 %.not10.not11, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %5
  %7 = getelementptr inbounds i8, ptr %0, i64 4
  %8 = getelementptr inbounds i8, ptr %1, i64 4
  %wide.trip.count = zext nneg i32 %3 to i64
  %xtraiter = and i64 %wide.trip.count, 1
  %9 = icmp eq i32 %3, 1
  br i1 %9, 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 %18

._crit_edge.loopexit.unr-lcssa:                   ; preds = %18, %.lr.ph
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph ], [ %27, %18 ]
  %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
  %10 = add nuw nsw i64 %indvars.iv.unr, 1
  %11 = getelementptr inbounds [2001 x i32], ptr %7, i64 0, i64 %10
  %12 = load i32, ptr %11, align 4, !tbaa !10
  %13 = sext i32 %12 to i64
  %14 = mul nsw i64 %10, %13
  %15 = srem i64 %14, 998244353
  %16 = trunc nsw i64 %15 to i32
  %17 = getelementptr inbounds [2001 x i32], ptr %8, i64 0, i64 %indvars.iv.unr
  store i32 %16, ptr %17, align 4, !tbaa !10
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit.epilog-lcssa, %._crit_edge.loopexit.unr-lcssa, %5
  tail call void @_Z9poly_normR4Poly(ptr noundef nonnull align 4 dereferenceable(8008) %1)
  br label %35

18:                                               ; preds = %18, %.lr.ph.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.new ], [ %27, %18 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.1, %18 ]
  %19 = or disjoint i64 %indvars.iv, 1
  %20 = getelementptr inbounds [2001 x i32], ptr %7, i64 0, i64 %19
  %21 = load i32, ptr %20, align 8, !tbaa !10
  %22 = sext i32 %21 to i64
  %23 = mul nsw i64 %19, %22
  %24 = srem i64 %23, 998244353
  %25 = trunc nsw i64 %24 to i32
  %26 = getelementptr inbounds [2001 x i32], ptr %8, i64 0, i64 %indvars.iv
  store i32 %25, ptr %26, align 4, !tbaa !10
  %27 = add nuw nsw i64 %indvars.iv, 2
  %28 = getelementptr inbounds [2001 x i32], ptr %7, i64 0, i64 %27
  %29 = load i32, ptr %28, align 4, !tbaa !10
  %30 = sext i32 %29 to i64
  %31 = mul nsw i64 %27, %30
  %32 = srem i64 %31, 998244353
  %33 = trunc nsw i64 %32 to i32
  %34 = getelementptr inbounds [2001 x i32], ptr %8, i64 0, i64 %19
  store i32 %33, ptr %34, align 4, !tbaa !10
  %niter.next.1 = add nuw 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 %18, !llvm.loop !11

35:                                               ; preds = %._crit_edge, %4
  ret void
}

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

!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, !7, i64 0}
!6 = !{!"_ZTS4Poly", !7, i64 0, !8, i64 4}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!7, !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,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass