; LLVM IR from ritikbanger/Hacktoberfest2022-DSA :: 28. Codechef Problems/Dish-Owner.ll (Z19SieveOfEratosthenesv)

; 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<long long, std::allocator<long long>>::_Vector_impl" }
%"struct.std::_Vector_base<long long, std::allocator<long long>>::_Vector_impl" = type { %"struct.std::_Vector_base<long long, std::allocator<long long>>::_Vector_impl_data" }
%"struct.std::_Vector_base<long long, std::allocator<long long>>::_Vector_impl_data" = type { ptr, ptr, ptr }

@primes = external dso_local global %"class.std::vector", align 8
@prefp = external dso_local global %"class.std::vector", align 8

; 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 uwtable
declare dso_local void @_ZNSt6vectorIxSaIxEE9push_backERKx(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 8 dereferenceable(8)) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_Z19SieveOfEratosthenesv() #1 {
  %1 = alloca [50005 x i8], align 16
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  %4 = alloca i32, align 4
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 50005, ptr %1) #4
  call void @_ZNSt6vectorIxSaIxEE5clearEv(ptr noundef nonnull align 8 dereferenceable(24) @primes) #4
  call void @_ZNSt6vectorIxSaIxEE5clearEv(ptr noundef nonnull align 8 dereferenceable(24) @prefp) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #4
  store i64 0, ptr %2, align 8, !tbaa !5
  call void @_ZNSt6vectorIxSaIxEE6assignEmRKx(ptr noundef nonnull align 8 dereferenceable(24) @prefp, i64 noundef 50005, ptr noundef nonnull align 8 dereferenceable(8) %2)
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #4
  %7 = getelementptr inbounds [50005 x i8], ptr %1, i64 0, i64 0
  call void @llvm.memset.p0.i64(ptr align 16 %7, i8 1, i64 50005, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  store i64 2, ptr %3, align 8, !tbaa !5
  br label %8

8:                                                ; preds = %38, %0
  %9 = load i64, ptr %3, align 8, !tbaa !5
  %10 = load i64, ptr %3, align 8, !tbaa !5
  %11 = mul nsw i64 %9, %10
  %12 = icmp slt i64 %11, 50005
  br i1 %12, label %14, label %13

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

14:                                               ; preds = %8
  %15 = load i64, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds [50005 x i8], ptr %1, i64 0, i64 %15
  %17 = load i8, ptr %16, align 1, !tbaa !9, !range !11, !noundef !12
  %18 = trunc i8 %17 to i1
  %19 = zext i1 %18 to i32
  %20 = icmp eq i32 %19, 1
  br i1 %20, label %21, label %37

21:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %22 = load i64, ptr %3, align 8, !tbaa !5
  %23 = load i64, ptr %3, align 8, !tbaa !5
  %24 = mul nsw i64 %22, %23
  store i64 %24, ptr %5, align 8, !tbaa !5
  br label %25

25:                                               ; preds = %32, %21
  %26 = load i64, ptr %5, align 8, !tbaa !5
  %27 = icmp slt i64 %26, 50005
  br i1 %27, label %29, label %28

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

29:                                               ; preds = %25
  %30 = load i64, ptr %5, align 8, !tbaa !5
  %31 = getelementptr inbounds [50005 x i8], ptr %1, i64 0, i64 %30
  store i8 0, ptr %31, align 1, !tbaa !9
  br label %32

32:                                               ; preds = %29
  %33 = load i64, ptr %3, align 8, !tbaa !5
  %34 = load i64, ptr %5, align 8, !tbaa !5
  %35 = add nsw i64 %34, %33
  store i64 %35, ptr %5, align 8, !tbaa !5
  br label %25, !llvm.loop !13

36:                                               ; preds = %28
  br label %37

37:                                               ; preds = %36, %14
  br label %38

38:                                               ; preds = %37
  %39 = load i64, ptr %3, align 8, !tbaa !5
  %40 = add nsw i64 %39, 1
  store i64 %40, ptr %3, align 8, !tbaa !5
  br label %8, !llvm.loop !15

41:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  store i64 2, ptr %6, align 8, !tbaa !5
  br label %42

42:                                               ; preds = %63, %41
  %43 = load i64, ptr %6, align 8, !tbaa !5
  %44 = icmp slt i64 %43, 50005
  br i1 %44, label %46, label %45

45:                                               ; preds = %42
  store i32 8, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %66

46:                                               ; preds = %42
  %47 = load i64, ptr %6, align 8, !tbaa !5
  %48 = getelementptr inbounds [50005 x i8], ptr %1, i64 0, i64 %47
  %49 = load i8, ptr %48, align 1, !tbaa !9, !range !11, !noundef !12
  %50 = trunc i8 %49 to i1
  br i1 %50, label %51, label %54

51:                                               ; preds = %46
  call void @_ZNSt6vectorIxSaIxEE9push_backERKx(ptr noundef nonnull align 8 dereferenceable(24) @primes, ptr noundef nonnull align 8 dereferenceable(8) %6)
  %52 = load i64, ptr %6, align 8, !tbaa !5
  %53 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @prefp, i64 noundef %52) #4
  store i64 1, ptr %53, align 8, !tbaa !5
  br label %54

54:                                               ; preds = %51, %46
  %55 = load i64, ptr %6, align 8, !tbaa !5
  %56 = sub nsw i64 %55, 1
  %57 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @prefp, i64 noundef %56) #4
  %58 = load i64, ptr %57, align 8, !tbaa !5
  %59 = load i64, ptr %6, align 8, !tbaa !5
  %60 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @prefp, i64 noundef %59) #4
  %61 = load i64, ptr %60, align 8, !tbaa !5
  %62 = add nsw i64 %61, %58
  store i64 %62, ptr %60, align 8, !tbaa !5
  br label %63

63:                                               ; preds = %54
  %64 = load i64, ptr %6, align 8, !tbaa !5
  %65 = add nsw i64 %64, 1
  store i64 %65, ptr %6, align 8, !tbaa !5
  br label %42, !llvm.loop !16

66:                                               ; preds = %45
  call void @llvm.lifetime.end.p0(i64 50005, ptr %1) #4
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt6vectorIxSaIxEE5clearEv(ptr noundef nonnull align 8 dereferenceable(24)) #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNSt6vectorIxSaIxEE6assignEmRKx(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef, ptr noundef nonnull align 8 dereferenceable(8)) #1 align 2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #2 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 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 #3 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !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<long long, std::allocator<long long>>::_Vector_impl" }
%"struct.std::_Vector_base<long long, std::allocator<long long>>::_Vector_impl" = type { %"struct.std::_Vector_base<long long, std::allocator<long long>>::_Vector_impl_data" }
%"struct.std::_Vector_base<long long, std::allocator<long long>>::_Vector_impl_data" = type { ptr, ptr, ptr }

@primes = external dso_local global %"class.std::vector", align 8
@prefp = external dso_local global %"class.std::vector", align 8

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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNSt6vectorIxSaIxEE9push_backERKx(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_Z19SieveOfEratosthenesv() local_unnamed_addr #1 {
  %1 = alloca [50005 x i8], align 16
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 50005, ptr nonnull %1) #4
  tail call void @_ZNSt6vectorIxSaIxEE5clearEv(ptr noundef nonnull align 8 dereferenceable(24) @primes) #4
  tail call void @_ZNSt6vectorIxSaIxEE5clearEv(ptr noundef nonnull align 8 dereferenceable(24) @prefp) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #4
  store i64 0, ptr %2, align 8, !tbaa !5
  call void @_ZNSt6vectorIxSaIxEE6assignEmRKx(ptr noundef nonnull align 8 dereferenceable(24) @prefp, i64 noundef 50005, ptr noundef nonnull align 8 dereferenceable(8) %2)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #4
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(50005) %1, i8 1, i64 50005, i1 false)
  br label %5

4:                                                ; preds = %.loopexit.1
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #4
  store i64 2, ptr %3, align 8, !tbaa !5
  br label %26

5:                                                ; preds = %.loopexit.1, %0
  %6 = phi i64 [ 4, %0 ], [ %24, %.loopexit.1 ]
  %.01014 = phi i64 [ 2, %0 ], [ %23, %.loopexit.1 ]
  %7 = getelementptr inbounds [50005 x i8], ptr %1, i64 0, i64 %.01014
  %8 = load i8, ptr %7, align 2, !tbaa !9, !range !11, !noundef !12
  %9 = trunc nuw i8 %8 to i1
  %10 = icmp ult i64 %6, 50005
  %or.cond = and i1 %10, %9
  br i1 %or.cond, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %5, %.lr.ph
  %.013 = phi i64 [ %12, %.lr.ph ], [ %6, %5 ]
  %11 = getelementptr inbounds [50005 x i8], ptr %1, i64 0, i64 %.013
  store i8 0, ptr %11, align 1, !tbaa !9
  %12 = add nuw nsw i64 %.013, %.01014
  %13 = icmp ult i64 %12, 50005
  br i1 %13, label %.lr.ph, label %.loopexit, !llvm.loop !13

.loopexit:                                        ; preds = %.lr.ph, %5
  %14 = or disjoint i64 %.01014, 1
  %15 = mul nuw nsw i64 %14, %14
  %16 = getelementptr inbounds [50005 x i8], ptr %1, i64 0, i64 %14
  %17 = load i8, ptr %16, align 1, !tbaa !9, !range !11, !noundef !12
  %18 = trunc nuw i8 %17 to i1
  %19 = icmp ult i64 %15, 50005
  %or.cond.1 = and i1 %19, %18
  br i1 %or.cond.1, label %.lr.ph.1, label %.loopexit.1

.lr.ph.1:                                         ; preds = %.loopexit, %.lr.ph.1
  %.013.1 = phi i64 [ %21, %.lr.ph.1 ], [ %15, %.loopexit ]
  %20 = getelementptr inbounds [50005 x i8], ptr %1, i64 0, i64 %.013.1
  store i8 0, ptr %20, align 1, !tbaa !9
  %21 = add nuw nsw i64 %.013.1, %14
  %22 = icmp ult i64 %21, 50005
  br i1 %22, label %.lr.ph.1, label %.loopexit.1, !llvm.loop !13

.loopexit.1:                                      ; preds = %.lr.ph.1, %.loopexit
  %23 = add nuw nsw i64 %.01014, 2
  %24 = mul nuw nsw i64 %23, %23
  %exitcond.not.1 = icmp eq i64 %23, 224
  br i1 %exitcond.not.1, label %4, label %5, !llvm.loop !15

25:                                               ; preds = %33
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #4
  call void @llvm.lifetime.end.p0(i64 50005, ptr nonnull %1) #4
  ret void

26:                                               ; preds = %4, %33
  %storemerge15 = phi i64 [ 2, %4 ], [ %43, %33 ]
  %27 = getelementptr inbounds [50005 x i8], ptr %1, i64 0, i64 %storemerge15
  %28 = load i8, ptr %27, align 1, !tbaa !9, !range !11, !noundef !12
  %29 = trunc nuw i8 %28 to i1
  br i1 %29, label %30, label %33

30:                                               ; preds = %26
  call void @_ZNSt6vectorIxSaIxEE9push_backERKx(ptr noundef nonnull align 8 dereferenceable(24) @primes, ptr noundef nonnull align 8 dereferenceable(8) %3)
  %31 = load i64, ptr %3, align 8, !tbaa !5
  %32 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @prefp, i64 noundef %31) #4
  store i64 1, ptr %32, align 8, !tbaa !5
  %.pre = load i64, ptr %3, align 8, !tbaa !5
  br label %33

33:                                               ; preds = %30, %26
  %34 = phi i64 [ %.pre, %30 ], [ %storemerge15, %26 ]
  %35 = add nsw i64 %34, -1
  %36 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @prefp, i64 noundef %35) #4
  %37 = load i64, ptr %36, align 8, !tbaa !5
  %38 = load i64, ptr %3, align 8, !tbaa !5
  %39 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @prefp, i64 noundef %38) #4
  %40 = load i64, ptr %39, align 8, !tbaa !5
  %41 = add nsw i64 %40, %37
  store i64 %41, ptr %39, align 8, !tbaa !5
  %42 = load i64, ptr %3, align 8, !tbaa !5
  %43 = add nsw i64 %42, 1
  store i64 %43, ptr %3, align 8, !tbaa !5
  %44 = icmp slt i64 %42, 50004
  br i1 %44, label %26, label %25, !llvm.loop !16
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt6vectorIxSaIxEE5clearEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNSt6vectorIxSaIxEE6assignEmRKx(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef, ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #1 align 2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #2 align 2

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


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