; LLVM IR from lzyrapx/Competitive-Programming :: LibreOJ (6165（线性筛）)

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

@n = external dso_local global i32, align 4
@prime = external dso_local global [6000005 x i64], align 16
@cnt = external dso_local global i64, align 8
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z5Sievei(i32 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 norecurse uwtable
define dso_local noundef i32 @main() #2 {
  %1 = alloca i32, align 4
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %6 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  %7 = load i32, ptr @n, align 4, !tbaa !5
  call void @_Z5Sievei(i32 noundef %7)
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  store i64 1, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 1, ptr %5, align 4, !tbaa !5
  br label %8

8:                                                ; preds = %36, %0
  %9 = load i32, ptr %5, align 4, !tbaa !5
  %10 = sext i32 %9 to i64
  %11 = load i64, ptr @cnt, align 8, !tbaa !9
  %12 = icmp sle i64 %10, %11
  br i1 %12, label %14, label %13

13:                                               ; preds = %8
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %39

14:                                               ; preds = %8
  %15 = load i32, ptr %5, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [6000005 x i64], ptr @prime, i64 0, i64 %16
  %18 = load i64, ptr %17, align 8, !tbaa !9
  store i64 %18, ptr %2, align 8, !tbaa !9
  br label %19

19:                                               ; preds = %29, %14
  %20 = load i64, ptr %2, align 8, !tbaa !9
  %21 = load i32, ptr %5, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [6000005 x i64], ptr @prime, i64 0, i64 %22
  %24 = load i64, ptr %23, align 8, !tbaa !9
  %25 = mul nsw i64 %20, %24
  store i64 %25, ptr %3, align 8, !tbaa !9
  %26 = load i32, ptr @n, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = icmp sle i64 %25, %27
  br i1 %28, label %29, label %31

29:                                               ; preds = %19
  %30 = load i64, ptr %3, align 8, !tbaa !9
  store i64 %30, ptr %2, align 8, !tbaa !9
  br label %19, !llvm.loop !11

31:                                               ; preds = %19
  %32 = load i64, ptr %4, align 8, !tbaa !9
  %33 = load i64, ptr %2, align 8, !tbaa !9
  %34 = mul nsw i64 %32, %33
  %35 = srem i64 %34, 100000007
  store i64 %35, ptr %4, align 8, !tbaa !9
  br label %36

36:                                               ; preds = %31
  %37 = load i32, ptr %5, align 4, !tbaa !5
  %38 = add nsw i32 %37, 1
  store i32 %38, ptr %5, align 4, !tbaa !5
  br label %8, !llvm.loop !13

39:                                               ; preds = %13
  %40 = load i64, ptr %4, align 8, !tbaa !9
  %41 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i64 noundef %40)
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #4
  ret i32 0
}

declare i32 @__isoc99_scanf(ptr noundef, ...) #3

declare i32 @printf(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 norecurse 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 = { "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 = !{!"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"}
!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"

@n = external dso_local global i32, align 4
@prime = external dso_local local_unnamed_addr global [6000005 x i64], align 16
@cnt = external dso_local local_unnamed_addr global i64, align 8
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1

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

; Function Attrs: mustprogress norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  %2 = load i32, ptr @n, align 4, !tbaa !5
  tail call void @_Z5Sievei(i32 noundef %2)
  %3 = load i64, ptr @cnt, align 8, !tbaa !9
  %.not14 = icmp slt i64 %3, 1
  br i1 %.not14, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %0
  %4 = load i32, ptr @n, align 4, !tbaa !5
  %5 = sext i32 %4 to i64
  %xtraiter = and i64 %3, 1
  %6 = icmp eq i64 %3, 1
  br i1 %6, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.lr.ph
  %unroll_iter = and i64 %3, 9223372036854775806
  br label %14

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

.epil.preheader:                                  ; preds = %._crit_edge.loopexit.unr-lcssa
  %7 = getelementptr inbounds [6000005 x i64], ptr @prime, i64 0, i64 %indvars.iv.unr
  %8 = load i64, ptr %7, align 8, !tbaa !9
  br label %9

9:                                                ; preds = %9, %.epil.preheader
  %.010.epil = phi i64 [ %8, %.epil.preheader ], [ %10, %9 ]
  %10 = mul nsw i64 %.010.epil, %8
  %.not13.epil = icmp sgt i64 %10, %5
  br i1 %.not13.epil, label %._crit_edge.loopexit.epilog-lcssa, label %9, !llvm.loop !11

._crit_edge.loopexit.epilog-lcssa:                ; preds = %9
  %11 = mul nsw i64 %.010.epil, %.0915.unr
  %12 = srem i64 %11, 100000007
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit.epilog-lcssa, %._crit_edge.loopexit.unr-lcssa, %0
  %.09.lcssa = phi i64 [ 1, %0 ], [ %.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %12, %._crit_edge.loopexit.epilog-lcssa ]
  %13 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i64 noundef %.09.lcssa)
  ret i32 0

14:                                               ; preds = %26, %.lr.ph.new
  %indvars.iv = phi i64 [ 1, %.lr.ph.new ], [ %indvars.iv.next.1, %26 ]
  %.0915 = phi i64 [ 1, %.lr.ph.new ], [ %28, %26 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.1, %26 ]
  %15 = getelementptr inbounds [6000005 x i64], ptr @prime, i64 0, i64 %indvars.iv
  %16 = load i64, ptr %15, align 8, !tbaa !9
  br label %17

17:                                               ; preds = %17, %14
  %.010 = phi i64 [ %16, %14 ], [ %18, %17 ]
  %18 = mul nsw i64 %.010, %16
  %.not13 = icmp sgt i64 %18, %5
  br i1 %.not13, label %19, label %17, !llvm.loop !11

19:                                               ; preds = %17
  %20 = mul nsw i64 %.010, %.0915
  %21 = srem i64 %20, 100000007
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %22 = getelementptr inbounds [6000005 x i64], ptr @prime, i64 0, i64 %indvars.iv.next
  %23 = load i64, ptr %22, align 8, !tbaa !9
  br label %24

24:                                               ; preds = %24, %19
  %.010.1 = phi i64 [ %23, %19 ], [ %25, %24 ]
  %25 = mul nsw i64 %.010.1, %23
  %.not13.1 = icmp sgt i64 %25, %5
  br i1 %.not13.1, label %26, label %24, !llvm.loop !11

26:                                               ; preds = %24
  %27 = mul nsw i64 %.010.1, %21
  %28 = srem i64 %27, 100000007
  %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 %14, !llvm.loop !13
}

; Function Attrs: nofree nounwind
declare noundef i32 @__isoc99_scanf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) 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 norecurse 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 #2 = { nofree nounwind "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"}
!13 = distinct !{!13, !12}


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