; LLVM IR from lzyrapx/Competitive-Programming :: HDUOJ/5901（Lehmer素数计数）.ll (Z4initv)

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

%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl" = type { %"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" = type { ptr, ptr, ptr }

@isp = external dso_local global [10000000 x i8], align 16
@pcnt = external dso_local global [10000000 x i32], align 16
@primes = external dso_local global %"class.std::vector", align 8

; Function Attrs: mustprogress uwtable
define dso_local void @_Z4initv() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #2
  store i32 2, ptr %1, align 4, !tbaa !5
  br label %6

6:                                                ; preds = %15, %0
  %7 = load i32, ptr %1, align 4, !tbaa !5
  %8 = sext i32 %7 to i64
  %9 = icmp slt i64 %8, 10000000
  br i1 %9, label %11, label %10

10:                                               ; preds = %6
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #2
  br label %18

11:                                               ; preds = %6
  %12 = load i32, ptr %1, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [10000000 x i8], ptr @isp, i64 0, i64 %13
  store i8 1, ptr %14, align 1, !tbaa !9
  br label %15

15:                                               ; preds = %11
  %16 = load i32, ptr %1, align 4, !tbaa !5
  %17 = add nsw i32 %16, 1
  store i32 %17, ptr %1, align 4, !tbaa !5
  br label %6, !llvm.loop !11

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

19:                                               ; preds = %48, %18
  %20 = load i32, ptr %2, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = icmp slt i64 %21, 10000000
  br i1 %22, label %24, label %23

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

24:                                               ; preds = %19
  %25 = load i32, ptr %2, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [10000000 x i8], ptr @isp, i64 0, i64 %26
  %28 = load i8, ptr %27, align 1, !tbaa !9, !range !13, !noundef !14
  %29 = trunc i8 %28 to i1
  br i1 %29, label %31, label %30

30:                                               ; preds = %24
  br label %48

31:                                               ; preds = %24
  call void @_ZNSt6vectorIiSaIiEE9push_backERKi(ptr noundef nonnull align 8 dereferenceable(24) @primes, ptr noundef nonnull align 4 dereferenceable(4) %2)
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  %32 = load i32, ptr %2, align 4, !tbaa !5
  %33 = mul nsw i32 2, %32
  store i32 %33, ptr %4, align 4, !tbaa !5
  br label %34

34:                                               ; preds = %43, %31
  %35 = load i32, ptr %4, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = icmp slt i64 %36, 10000000
  br i1 %37, label %39, label %38

38:                                               ; preds = %34
  store i32 8, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  br label %47

39:                                               ; preds = %34
  %40 = load i32, ptr %4, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [10000000 x i8], ptr @isp, i64 0, i64 %41
  store i8 0, ptr %42, align 1, !tbaa !9
  br label %43

43:                                               ; preds = %39
  %44 = load i32, ptr %2, align 4, !tbaa !5
  %45 = load i32, ptr %4, align 4, !tbaa !5
  %46 = add nsw i32 %45, %44
  store i32 %46, ptr %4, align 4, !tbaa !5
  br label %34, !llvm.loop !15

47:                                               ; preds = %38
  br label %48

48:                                               ; preds = %47, %30
  %49 = load i32, ptr %2, align 4, !tbaa !5
  %50 = add nsw i32 %49, 1
  store i32 %50, ptr %2, align 4, !tbaa !5
  br label %19, !llvm.loop !16

51:                                               ; preds = %23
  store i32 0, ptr @pcnt, align 16, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  store i32 1, ptr %5, align 4, !tbaa !5
  br label %52

52:                                               ; preds = %73, %51
  %53 = load i32, ptr %5, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = icmp slt i64 %54, 10000000
  br i1 %55, label %57, label %56

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

57:                                               ; preds = %52
  %58 = load i32, ptr %5, align 4, !tbaa !5
  %59 = sub nsw i32 %58, 1
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [10000000 x i32], ptr @pcnt, i64 0, i64 %60
  %62 = load i32, ptr %61, align 4, !tbaa !5
  %63 = load i32, ptr %5, align 4, !tbaa !5
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [10000000 x i8], ptr @isp, i64 0, i64 %64
  %66 = load i8, ptr %65, align 1, !tbaa !9, !range !13, !noundef !14
  %67 = trunc i8 %66 to i1
  %68 = zext i1 %67 to i32
  %69 = add nsw i32 %62, %68
  %70 = load i32, ptr %5, align 4, !tbaa !5
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds [10000000 x i32], ptr @pcnt, i64 0, i64 %71
  store i32 %69, ptr %72, align 4, !tbaa !5
  br label %73

73:                                               ; preds = %57
  %74 = load i32, ptr %5, align 4, !tbaa !5
  %75 = add nsw i32 %74, 1
  store i32 %75, ptr %5, align 4, !tbaa !5
  br label %52, !llvm.loop !17

76:                                               ; preds = %56
  ret void
}

; 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 @_ZNSt6vectorIiSaIiEE9push_backERKi(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 4 dereferenceable(4)) #0 align 2

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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = distinct !{!15, !12}
!16 = distinct !{!16, !12}
!17 = distinct !{!17, !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"

%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl" = type { %"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" = type { ptr, ptr, ptr }

@isp = external dso_local local_unnamed_addr global [10000000 x i8], align 16
@pcnt = external dso_local local_unnamed_addr global [10000000 x i32], align 16
@primes = external dso_local global %"class.std::vector", align 8

; Function Attrs: mustprogress uwtable
define dso_local void @_Z4initv() local_unnamed_addr #0 {
  %1 = alloca i32, align 4
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 2 dereferenceable(9999998) getelementptr inbounds (i8, ptr @isp, i64 2), i8 1, i64 9999998, i1 false), !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #4
  store i32 2, ptr %1, align 4, !tbaa !9
  br label %3

2:                                                ; preds = %.loopexit
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #4
  store i32 0, ptr @pcnt, align 16, !tbaa !9
  br label %32

3:                                                ; preds = %0, %.loopexit
  %storemerge19 = phi i32 [ 2, %0 ], [ %29, %.loopexit ]
  %4 = sext i32 %storemerge19 to i64
  %5 = getelementptr inbounds [10000000 x i8], ptr @isp, i64 0, i64 %4
  %6 = load i8, ptr %5, align 1, !tbaa !5, !range !11, !noundef !12
  %7 = trunc nuw i8 %6 to i1
  br i1 %7, label %8, label %.loopexit

8:                                                ; preds = %3
  call void @_ZNSt6vectorIiSaIiEE9push_backERKi(ptr noundef nonnull align 8 dereferenceable(24) @primes, ptr noundef nonnull align 4 dereferenceable(4) %1)
  %9 = load i32, ptr %1, align 4, !tbaa !9
  %10 = icmp slt i32 %9, 5000000
  br i1 %10, label %iter.check, label %.loopexit

iter.check:                                       ; preds = %8
  %11 = shl i32 %9, 1
  %12 = sext i32 %11 to i64
  %13 = sext i32 %9 to i64
  %14 = add nsw i64 %13, %12
  %smax = call i64 @llvm.smax.i64(i64 %14, i64 10000000)
  %15 = icmp slt i64 %14, 10000000
  %umin.neg = sext i1 %15 to i64
  %16 = select i1 %15, i64 2, i64 1
  %17 = add i64 %smax, %umin.neg
  %18 = sub i64 %17, %14
  %umax = call i64 @llvm.umax.i64(i64 %13, i64 1)
  %19 = udiv i64 %18, %umax
  %20 = add i64 %16, %19
  %min.iters.check = icmp ugt i64 %20, 7
  %ident.check.not = icmp eq i32 %9, 1
  %or.cond = and i1 %min.iters.check, %ident.check.not
  br i1 %or.cond, label %vector.main.loop.iter.check, label %.lr.ph.preheader

vector.main.loop.iter.check:                      ; preds = %iter.check
  %min.iters.check26 = icmp ult i64 %20, 32
  br i1 %min.iters.check26, label %vec.epilog.ph, label %vector.ph

vector.ph:                                        ; preds = %vector.main.loop.iter.check
  %n.vec = and i64 %20, -32
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %offset.idx = or disjoint i64 %index, 2
  %21 = getelementptr inbounds [10000000 x i8], ptr @isp, i64 0, i64 %offset.idx
  %22 = getelementptr inbounds i8, ptr %21, i64 16
  store <16 x i8> zeroinitializer, ptr %21, align 2, !tbaa !5
  store <16 x i8> zeroinitializer, ptr %22, align 2, !tbaa !5
  %index.next = add nuw i64 %index, 32
  %23 = icmp eq i64 %index.next, %n.vec
  br i1 %23, label %middle.block, label %vector.body, !llvm.loop !13

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %20, %n.vec
  br i1 %cmp.n, label %.loopexit, label %vec.epilog.iter.check

vec.epilog.iter.check:                            ; preds = %middle.block
  %ind.end29 = or disjoint i64 %n.vec, 2
  %n.vec.remaining = and i64 %20, 24
  %min.epilog.iters.check = icmp eq i64 %n.vec.remaining, 0
  br i1 %min.epilog.iters.check, label %.lr.ph.preheader, label %vec.epilog.ph

vec.epilog.ph:                                    ; preds = %vector.main.loop.iter.check, %vec.epilog.iter.check
  %vec.epilog.resume.val = phi i64 [ %n.vec, %vec.epilog.iter.check ], [ 0, %vector.main.loop.iter.check ]
  %n.vec28 = and i64 %20, -8
  %ind.end = or disjoint i64 %n.vec28, 2
  br label %vec.epilog.vector.body

vec.epilog.vector.body:                           ; preds = %vec.epilog.vector.body, %vec.epilog.ph
  %index30 = phi i64 [ %vec.epilog.resume.val, %vec.epilog.ph ], [ %index.next32, %vec.epilog.vector.body ]
  %offset.idx31 = or disjoint i64 %index30, 2
  %24 = getelementptr inbounds [10000000 x i8], ptr @isp, i64 0, i64 %offset.idx31
  store <8 x i8> zeroinitializer, ptr %24, align 2, !tbaa !5
  %index.next32 = add nuw i64 %index30, 8
  %25 = icmp eq i64 %index.next32, %n.vec28
  br i1 %25, label %vec.epilog.middle.block, label %vec.epilog.vector.body, !llvm.loop !17

vec.epilog.middle.block:                          ; preds = %vec.epilog.vector.body
  %cmp.n33 = icmp eq i64 %20, %n.vec28
  br i1 %cmp.n33, label %.loopexit, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %vec.epilog.middle.block, %iter.check, %vec.epilog.iter.check
  %indvars.iv.ph = phi i64 [ %12, %iter.check ], [ %ind.end29, %vec.epilog.iter.check ], [ %ind.end, %vec.epilog.middle.block ]
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ %indvars.iv.ph, %.lr.ph.preheader ]
  %26 = getelementptr inbounds [10000000 x i8], ptr @isp, i64 0, i64 %indvars.iv
  store i8 0, ptr %26, align 1, !tbaa !5
  %indvars.iv.next = add nsw i64 %indvars.iv, %13
  %27 = icmp slt i64 %indvars.iv.next, 10000000
  br i1 %27, label %.lr.ph, label %.loopexit, !llvm.loop !18

.loopexit:                                        ; preds = %.lr.ph, %middle.block, %vec.epilog.middle.block, %8, %3
  %28 = phi i32 [ %9, %8 ], [ %storemerge19, %3 ], [ %9, %vec.epilog.middle.block ], [ %9, %middle.block ], [ %9, %.lr.ph ]
  %29 = add nsw i32 %28, 1
  store i32 %29, ptr %1, align 4, !tbaa !9
  %30 = icmp slt i32 %28, 9999999
  br i1 %30, label %3, label %2, !llvm.loop !19

31:                                               ; preds = %32
  ret void

32:                                               ; preds = %32, %2
  %33 = phi i32 [ 0, %2 ], [ %47, %32 ]
  %indvars.iv23 = phi i64 [ 1, %2 ], [ %indvars.iv.next24.2, %32 ]
  %34 = getelementptr inbounds [10000000 x i8], ptr @isp, i64 0, i64 %indvars.iv23
  %35 = load i8, ptr %34, align 1, !tbaa !5, !range !11, !noundef !12
  %36 = zext nneg i8 %35 to i32
  %37 = add nuw nsw i32 %33, %36
  %38 = getelementptr inbounds [10000000 x i32], ptr @pcnt, i64 0, i64 %indvars.iv23
  store i32 %37, ptr %38, align 4, !tbaa !9
  %indvars.iv.next24 = add nuw nsw i64 %indvars.iv23, 1
  %39 = getelementptr inbounds [10000000 x i8], ptr @isp, i64 0, i64 %indvars.iv.next24
  %40 = load i8, ptr %39, align 1, !tbaa !5, !range !11, !noundef !12
  %41 = zext nneg i8 %40 to i32
  %42 = add nuw nsw i32 %37, %41
  %43 = getelementptr inbounds [10000000 x i32], ptr @pcnt, i64 0, i64 %indvars.iv.next24
  store i32 %42, ptr %43, align 4, !tbaa !9
  %indvars.iv.next24.1 = add nuw nsw i64 %indvars.iv23, 2
  %44 = getelementptr inbounds [10000000 x i8], ptr @isp, i64 0, i64 %indvars.iv.next24.1
  %45 = load i8, ptr %44, align 1, !tbaa !5, !range !11, !noundef !12
  %46 = zext nneg i8 %45 to i32
  %47 = add nuw nsw i32 %42, %46
  %48 = getelementptr inbounds [10000000 x i32], ptr @pcnt, i64 0, i64 %indvars.iv.next24.1
  store i32 %47, ptr %48, align 4, !tbaa !9
  %indvars.iv.next24.2 = add nuw nsw i64 %indvars.iv23, 3
  %exitcond.not.2 = icmp eq i64 %indvars.iv.next24.2, 10000000
  br i1 %exitcond.not.2, label %31, label %32, !llvm.loop !20
}

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

; Function Attrs: mustprogress 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 @_ZNSt6vectorIiSaIiEE9push_backERKi(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #0 align 2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.smax.i64(i64, i64) #3

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.umax.i64(i64, i64) #3

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!"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, !15, !16}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!"llvm.loop.isvectorized", i32 1}
!16 = !{!"llvm.loop.unroll.runtime.disable"}
!17 = distinct !{!17, !14, !15, !16}
!18 = distinct !{!18, !14, !15}
!19 = distinct !{!19, !14}
!20 = distinct !{!20, !14}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalDCEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopIdiomRecognizePass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass