; LLVM IR from kazunetakahashi/atcoder :: 201510_201609/0131/tenka1_2012_qualC_A.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 }

@isprime = external dso_local global [10000010 x i8], align 16
@prime_num = external dso_local global %"class.std::vector", align 8

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

5:                                                ; preds = %33, %0
  %6 = load i32, ptr %2, align 4, !tbaa !9
  %7 = icmp slt i32 %6, 10000010
  br i1 %7, label %9, label %8

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

9:                                                ; preds = %5
  %10 = load i32, ptr %2, align 4, !tbaa !9
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [10000010 x i8], ptr @isprime, i64 0, i64 %11
  %13 = load i8, ptr %12, align 1, !tbaa !5, !range !11, !noundef !12
  %14 = trunc i8 %13 to i1
  br i1 %14, label %15, label %32

15:                                               ; preds = %9
  call void @_ZNSt6vectorIiSaIiEE9push_backERKi(ptr noundef nonnull align 8 dereferenceable(24) @prime_num, ptr noundef nonnull align 4 dereferenceable(4) %2)
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 2, ptr %4, align 4, !tbaa !9
  br label %16

16:                                               ; preds = %28, %15
  %17 = load i32, ptr %2, align 4, !tbaa !9
  %18 = load i32, ptr %4, align 4, !tbaa !9
  %19 = mul nsw i32 %17, %18
  %20 = icmp slt i32 %19, 10000010
  br i1 %20, label %22, label %21

21:                                               ; preds = %16
  store i32 5, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %31

22:                                               ; preds = %16
  %23 = load i32, ptr %2, align 4, !tbaa !9
  %24 = load i32, ptr %4, align 4, !tbaa !9
  %25 = mul nsw i32 %23, %24
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [10000010 x i8], ptr @isprime, i64 0, i64 %26
  store i8 0, ptr %27, align 1, !tbaa !5
  br label %28

28:                                               ; preds = %22
  %29 = load i32, ptr %4, align 4, !tbaa !9
  %30 = add nsw i32 %29, 1
  store i32 %30, ptr %4, align 4, !tbaa !9
  br label %16, !llvm.loop !13

31:                                               ; preds = %21
  br label %32

32:                                               ; preds = %31, %9
  br label %33

33:                                               ; preds = %32
  %34 = load i32, ptr %2, align 4, !tbaa !9
  %35 = add nsw i32 %34, 1
  store i32 %35, ptr %2, align 4, !tbaa !9
  br label %5, !llvm.loop !15

36:                                               ; preds = %8
  ret void
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4fillIPbbEvT_S1_RKT0_(ptr noundef, ptr noundef, ptr noundef nonnull align 1 dereferenceable(1)) #1

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

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

; 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 = { 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 #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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"

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

@isprime = external dso_local global [10000010 x i8], align 16
@prime_num = external dso_local global %"class.std::vector", align 8

; Function Attrs: mustprogress uwtable
define dso_local void @_Z4initv() local_unnamed_addr #0 {
  %1 = alloca i8, align 1
  %2 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %1) #4
  store i8 1, ptr %1, align 1, !tbaa !5
  call void @_ZSt4fillIPbbEvT_S1_RKT0_(ptr noundef nonnull @isprime, ptr noundef nonnull getelementptr inbounds (i8, ptr @isprime, i64 10000010), ptr noundef nonnull align 1 dereferenceable(1) %1)
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %1) #4
  store i8 0, ptr getelementptr inbounds (i8, ptr @isprime, i64 1), align 1, !tbaa !5
  store i8 0, ptr @isprime, align 16, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #4
  store i32 2, ptr %2, align 4, !tbaa !9
  br label %4

3:                                                ; preds = %.loopexit
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #4
  ret void

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

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

iter.check:                                       ; preds = %9
  %12 = shl nsw i32 %10, 1
  %13 = sext i32 %10 to i64
  %14 = mul nsw i64 %13, 3
  %smax8 = call i64 @llvm.smax.i64(i64 %14, i64 10000010)
  %15 = icmp slt i32 %10, 3333337
  %umin9.neg = sext i1 %15 to i64
  %16 = select i1 %15, i64 2, i64 1
  %17 = add i64 %smax8, %umin9.neg
  %18 = sub i64 %17, %14
  %umax10 = call i64 @llvm.umax.i64(i64 %13, i64 1)
  %19 = udiv i64 %18, %umax10
  %20 = add i64 %16, %19
  %min.iters.check = icmp ult i64 %20, 8
  br i1 %min.iters.check, label %.lr.ph.preheader, label %vector.scevcheck

vector.scevcheck:                                 ; preds = %iter.check
  %ident.check = icmp ne i32 %10, 1
  %21 = mul nsw i64 %13, 3
  %smax = call i64 @llvm.smax.i64(i64 %21, i64 10000010)
  %22 = icmp slt i32 %10, 3333337
  %umin = zext i1 %22 to i64
  %23 = add nsw i64 %21, %umin
  %24 = sub i64 %smax, %23
  %umax = call i64 @llvm.umax.i64(i64 %13, i64 1)
  %25 = udiv i64 %24, %umax
  %26 = add i64 %25, %umin
  %27 = trunc i64 %26 to i32
  %28 = icmp ugt i32 %27, 2147483645
  %29 = icmp ugt i64 %26, 4294967295
  %30 = or i1 %28, %29
  %31 = or i1 %ident.check, %30
  br i1 %31, label %.lr.ph.preheader, label %vector.main.loop.iter.check

vector.main.loop.iter.check:                      ; preds = %vector.scevcheck
  %min.iters.check11 = icmp ult i64 %20, 32
  br i1 %min.iters.check11, 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 = shl i64 %index, 32
  %sext = ashr exact i64 %offset.idx, 32
  %32 = or disjoint i64 %sext, 2
  %33 = getelementptr inbounds [10000010 x i8], ptr @isprime, i64 0, i64 %32
  %34 = getelementptr inbounds i8, ptr %33, i64 16
  store <16 x i8> zeroinitializer, ptr %33, align 2, !tbaa !5
  store <16 x i8> zeroinitializer, ptr %34, align 2, !tbaa !5
  %index.next = add nuw i64 %index, 32
  %35 = icmp eq i64 %index.next, %n.vec
  br i1 %35, 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
  %.cast17 = trunc i64 %n.vec to i32
  %36 = or disjoint i32 %.cast17, 2
  %ind.end18 = mul nuw i32 %10, %36
  %ind.end14 = 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.vec13 = and i64 %20, -8
  %ind.end = or disjoint i64 %n.vec13, 2
  %.cast15 = trunc i64 %n.vec13 to i32
  %37 = or disjoint i32 %.cast15, 2
  %ind.end16 = mul nuw i32 %10, %37
  br label %vec.epilog.vector.body

vec.epilog.vector.body:                           ; preds = %vec.epilog.vector.body, %vec.epilog.ph
  %index20 = phi i64 [ %vec.epilog.resume.val, %vec.epilog.ph ], [ %index.next23, %vec.epilog.vector.body ]
  %offset.idx22 = shl i64 %index20, 32
  %sext25 = ashr exact i64 %offset.idx22, 32
  %38 = or disjoint i64 %sext25, 2
  %39 = getelementptr inbounds [10000010 x i8], ptr @isprime, i64 0, i64 %38
  store <8 x i8> zeroinitializer, ptr %39, align 1, !tbaa !5
  %index.next23 = add nuw i64 %index20, 8
  %40 = icmp eq i64 %index.next23, %n.vec13
  br i1 %40, label %vec.epilog.middle.block, label %vec.epilog.vector.body, !llvm.loop !17

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

.lr.ph.preheader:                                 ; preds = %vec.epilog.middle.block, %vector.scevcheck, %iter.check, %vec.epilog.iter.check
  %indvars.iv.ph = phi i64 [ 2, %iter.check ], [ 2, %vector.scevcheck ], [ %ind.end14, %vec.epilog.iter.check ], [ %ind.end, %vec.epilog.middle.block ]
  %.ph = phi i32 [ %12, %iter.check ], [ %12, %vector.scevcheck ], [ %ind.end18, %vec.epilog.iter.check ], [ %ind.end16, %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 ]
  %41 = phi i32 [ %46, %.lr.ph ], [ %.ph, %.lr.ph.preheader ]
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [10000010 x i8], ptr @isprime, i64 0, i64 %42
  store i8 0, ptr %43, align 1, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %44 = mul nsw i64 %indvars.iv.next, %13
  %45 = icmp slt i64 %44, 10000010
  %46 = trunc nsw i64 %44 to i32
  br i1 %45, label %.lr.ph, label %.loopexit, !llvm.loop !18

.loopexit:                                        ; preds = %.lr.ph, %middle.block, %vec.epilog.middle.block, %9, %4
  %47 = phi i32 [ %10, %9 ], [ %storemerge6, %4 ], [ %10, %vec.epilog.middle.block ], [ %10, %middle.block ], [ %10, %.lr.ph ]
  %48 = add nsw i32 %47, 1
  store i32 %48, ptr %2, align 4, !tbaa !9
  %49 = icmp slt i32 %47, 10000009
  br i1 %49, label %4, label %3, !llvm.loop !19
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4fillIPbbEvT_S1_RKT0_(ptr noundef, ptr noundef, ptr noundef nonnull align 1 dereferenceable(1)) local_unnamed_addr #1

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

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

; 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 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 = { 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 #2 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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}


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