; LLVM IR from lzyrapx/Competitive-Programming :: LibreOJ/2002（容斥+dp+矩阵快速幂）.ll (Z5sievev)

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

@m = external dso_local global i32, align 4
@isprime = external dso_local global [20000010 x i8], align 16
@prime = external dso_local global [2000010 x i32], align 16

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z5sievev() #1 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  store i8 1, ptr @isprime, align 16, !tbaa !5
  store i8 1, ptr getelementptr inbounds ([20000010 x i8], ptr @isprime, i64 0, i64 1), align 1, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #2
  store i32 2, ptr %1, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #2
  store i32 0, ptr %2, align 4, !tbaa !9
  br label %5

5:                                                ; preds = %64, %0
  %6 = load i32, ptr %1, align 4, !tbaa !9
  %7 = load i32, ptr @m, align 4, !tbaa !9
  %8 = icmp sle i32 %6, %7
  br i1 %8, label %10, label %9

9:                                                ; preds = %5
  store i32 2, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #2
  br label %67

10:                                               ; preds = %5
  %11 = load i32, ptr %1, align 4, !tbaa !9
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [20000010 x i8], ptr @isprime, i64 0, i64 %12
  %14 = load i8, ptr %13, align 1, !tbaa !5, !range !11, !noundef !12
  %15 = trunc i8 %14 to i1
  %16 = zext i1 %15 to i32
  %17 = icmp eq i32 %16, 0
  br i1 %17, label %18, label %24

18:                                               ; preds = %10
  %19 = load i32, ptr %1, align 4, !tbaa !9
  %20 = load i32, ptr %2, align 4, !tbaa !9
  %21 = add nsw i32 %20, 1
  store i32 %21, ptr %2, align 4, !tbaa !9
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [2000010 x i32], ptr @prime, i64 0, i64 %22
  store i32 %19, ptr %23, align 4, !tbaa !9
  br label %24

24:                                               ; preds = %18, %10
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  store i32 1, ptr %4, align 4, !tbaa !9
  br label %25

25:                                               ; preds = %59, %24
  %26 = load i32, ptr %4, align 4, !tbaa !9
  %27 = load i32, ptr %2, align 4, !tbaa !9
  %28 = icmp sle i32 %26, %27
  br i1 %28, label %29, label %38

29:                                               ; preds = %25
  %30 = load i32, ptr %1, align 4, !tbaa !9
  %31 = load i32, ptr %4, align 4, !tbaa !9
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [2000010 x i32], ptr @prime, i64 0, i64 %32
  %34 = load i32, ptr %33, align 4, !tbaa !9
  %35 = mul nsw i32 %30, %34
  %36 = load i32, ptr @m, align 4, !tbaa !9
  %37 = icmp sle i32 %35, %36
  br label %38

38:                                               ; preds = %29, %25
  %39 = phi i1 [ false, %25 ], [ %37, %29 ]
  br i1 %39, label %41, label %40

40:                                               ; preds = %38
  store i32 5, ptr %3, align 4
  br label %62

41:                                               ; preds = %38
  %42 = load i32, ptr %1, align 4, !tbaa !9
  %43 = load i32, ptr %4, align 4, !tbaa !9
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [2000010 x i32], ptr @prime, i64 0, i64 %44
  %46 = load i32, ptr %45, align 4, !tbaa !9
  %47 = mul nsw i32 %42, %46
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [20000010 x i8], ptr @isprime, i64 0, i64 %48
  store i8 1, ptr %49, align 1, !tbaa !5
  %50 = load i32, ptr %1, align 4, !tbaa !9
  %51 = load i32, ptr %4, align 4, !tbaa !9
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [2000010 x i32], ptr @prime, i64 0, i64 %52
  %54 = load i32, ptr %53, align 4, !tbaa !9
  %55 = srem i32 %50, %54
  %56 = icmp eq i32 %55, 0
  br i1 %56, label %57, label %58

57:                                               ; preds = %41
  store i32 5, ptr %3, align 4
  br label %62

58:                                               ; preds = %41
  br label %59

59:                                               ; preds = %58
  %60 = load i32, ptr %4, align 4, !tbaa !9
  %61 = add nsw i32 %60, 1
  store i32 %61, ptr %4, align 4, !tbaa !9
  br label %25, !llvm.loop !13

62:                                               ; preds = %57, %40
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  br label %63

63:                                               ; preds = %62
  br label %64

64:                                               ; preds = %63
  %65 = load i32, ptr %1, align 4, !tbaa !9
  %66 = add nsw i32 %65, 1
  store i32 %66, ptr %1, align 4, !tbaa !9
  br label %5, !llvm.loop !15

67:                                               ; preds = %9
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = !{!"bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !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"

@m = external dso_local local_unnamed_addr global i32, align 4
@isprime = external dso_local local_unnamed_addr global [20000010 x i8], align 16
@prime = external dso_local local_unnamed_addr global [2000010 x i32], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z5sievev() local_unnamed_addr #0 {
  store i8 1, ptr @isprime, align 16, !tbaa !5
  store i8 1, ptr getelementptr inbounds (i8, ptr @isprime, i64 1), align 1, !tbaa !5
  %1 = load i32, ptr @m, align 4, !tbaa !9
  %.not23 = icmp slt i32 %1, 2
  br i1 %.not23, label %._crit_edge, label %.lr.ph26.preheader

.lr.ph26.preheader:                               ; preds = %0
  %2 = add nuw i32 %1, 1
  %wide.trip.count = zext i32 %2 to i64
  br label %.lr.ph26

._crit_edge:                                      ; preds = %.critedge, %0
  ret void

.lr.ph26:                                         ; preds = %.lr.ph26.preheader, %.critedge
  %indvars.iv28 = phi i64 [ 2, %.lr.ph26.preheader ], [ %indvars.iv.next29, %.critedge ]
  %.01425 = phi i32 [ 0, %.lr.ph26.preheader ], [ %.1, %.critedge ]
  %3 = getelementptr inbounds [20000010 x i8], ptr @isprime, i64 0, i64 %indvars.iv28
  %4 = load i8, ptr %3, align 1, !tbaa !5, !range !11, !noundef !12
  %5 = icmp eq i8 %4, 0
  br i1 %5, label %6, label %11

6:                                                ; preds = %.lr.ph26
  %7 = add nsw i32 %.01425, 1
  %8 = sext i32 %7 to i64
  %9 = getelementptr inbounds [2000010 x i32], ptr @prime, i64 0, i64 %8
  %10 = trunc nuw nsw i64 %indvars.iv28 to i32
  store i32 %10, ptr %9, align 4, !tbaa !9
  br label %11

11:                                               ; preds = %6, %.lr.ph26
  %.1 = phi i32 [ %7, %6 ], [ %.01425, %.lr.ph26 ]
  %.not1719 = icmp slt i32 %.1, 1
  br i1 %.not1719, label %.critedge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %11
  %12 = zext nneg i32 %.1 to i64
  %13 = trunc nuw nsw i64 %indvars.iv28 to i32
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %17
  %indvars.iv = phi i64 [ 1, %.lr.ph.preheader ], [ %indvars.iv.next, %17 ]
  %14 = getelementptr inbounds [2000010 x i32], ptr @prime, i64 0, i64 %indvars.iv
  %15 = load i32, ptr %14, align 4, !tbaa !9
  %16 = mul nsw i32 %15, %13
  %.not18 = icmp sgt i32 %16, %1
  br i1 %.not18, label %.critedge, label %17

17:                                               ; preds = %.lr.ph
  %18 = sext i32 %16 to i64
  %19 = getelementptr inbounds [20000010 x i8], ptr @isprime, i64 0, i64 %18
  store i8 1, ptr %19, align 1, !tbaa !5
  %20 = srem i32 %13, %15
  %21 = icmp eq i32 %20, 0
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %.not17 = icmp uge i64 %indvars.iv, %12
  %or.cond = or i1 %21, %.not17
  br i1 %or.cond, label %.critedge, label %.lr.ph, !llvm.loop !13

.critedge:                                        ; preds = %.lr.ph, %17, %11
  %indvars.iv.next29 = add nuw nsw i64 %indvars.iv28, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next29, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph26, !llvm.loop !15
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) 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 = !{!"bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


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