; LLVM IR from brpapa/algorithms :: solutions/codeforces/230-B.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"

%"class.std::bitset<1000001>::reference" = type { ptr, i64 }

@isPrime = external dso_local global { [15626 x i64] }, align 8

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5sievev() #0 personality ptr @__gxx_personality_v0 {
  %1 = alloca %"class.std::bitset<1000001>::reference", align 8
  %2 = alloca %"class.std::bitset<1000001>::reference", align 8
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i64, align 8
  %6 = alloca i32, align 4
  %7 = alloca %"class.std::bitset<1000001>::reference", align 8
  %8 = alloca i64, align 8
  %9 = alloca %"class.std::bitset<1000001>::reference", align 8
  %10 = call noundef nonnull align 8 dereferenceable(125008) ptr @_ZNSt6bitsetILm1000001EE3setEv(ptr noundef nonnull align 8 dereferenceable(125008) @isPrime) #3
  call void @llvm.lifetime.start.p0(i64 16, ptr %1) #3
  call void @_ZNSt6bitsetILm1000001EEixEm(ptr dead_on_unwind writable sret(%"class.std::bitset<1000001>::reference") align 8 %1, ptr noundef nonnull align 8 dereferenceable(125008) @isPrime, i64 noundef 1)
  %11 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6bitsetILm1000001EE9referenceaSEb(ptr noundef nonnull align 8 dereferenceable(16) %1, i1 noundef zeroext false) #3
  call void @llvm.lifetime.start.p0(i64 16, ptr %2) #3
  invoke void @_ZNSt6bitsetILm1000001EEixEm(ptr dead_on_unwind writable sret(%"class.std::bitset<1000001>::reference") align 8 %2, ptr noundef nonnull align 8 dereferenceable(125008) @isPrime, i64 noundef 0)
          to label %12 unwind label %18

12:                                               ; preds = %0
  %13 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6bitsetILm1000001EE9referenceaSERKS1_(ptr noundef nonnull align 8 dereferenceable(16) %2, ptr noundef nonnull align 8 dereferenceable(16) %11) #3
  call void @_ZNSt6bitsetILm1000001EE9referenceD2Ev(ptr noundef nonnull align 8 dereferenceable(16) %2) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr %2) #3
  call void @_ZNSt6bitsetILm1000001EE9referenceD2Ev(ptr noundef nonnull align 8 dereferenceable(16) %1) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr %1) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  store i64 2, ptr %5, align 8, !tbaa !5
  br label %14

14:                                               ; preds = %42, %12
  %15 = load i64, ptr %5, align 8, !tbaa !5
  %16 = icmp sle i64 %15, 1000000
  br i1 %16, label %22, label %17

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

18:                                               ; preds = %0
  %19 = landingpad { ptr, i32 }
          cleanup
  %20 = extractvalue { ptr, i32 } %19, 0
  store ptr %20, ptr %3, align 8
  %21 = extractvalue { ptr, i32 } %19, 1
  store i32 %21, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 16, ptr %2) #3
  call void @_ZNSt6bitsetILm1000001EE9referenceD2Ev(ptr noundef nonnull align 8 dereferenceable(16) %1) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr %1) #3
  br label %46

22:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 16, ptr %7) #3
  %23 = load i64, ptr %5, align 8, !tbaa !5
  call void @_ZNSt6bitsetILm1000001EEixEm(ptr dead_on_unwind writable sret(%"class.std::bitset<1000001>::reference") align 8 %7, ptr noundef nonnull align 8 dereferenceable(125008) @isPrime, i64 noundef %23)
  %24 = call noundef zeroext i1 @_ZNKSt6bitsetILm1000001EE9referencecvbEv(ptr noundef nonnull align 8 dereferenceable(16) %7) #3
  call void @_ZNSt6bitsetILm1000001EE9referenceD2Ev(ptr noundef nonnull align 8 dereferenceable(16) %7) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr %7) #3
  br i1 %24, label %25, label %41

25:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %26 = load i64, ptr %5, align 8, !tbaa !5
  %27 = load i64, ptr %5, align 8, !tbaa !5
  %28 = mul nsw i64 %26, %27
  store i64 %28, ptr %8, align 8, !tbaa !5
  br label %29

29:                                               ; preds = %36, %25
  %30 = load i64, ptr %8, align 8, !tbaa !5
  %31 = icmp sle i64 %30, 1000000
  br i1 %31, label %33, label %32

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

33:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 16, ptr %9) #3
  %34 = load i64, ptr %8, align 8, !tbaa !5
  call void @_ZNSt6bitsetILm1000001EEixEm(ptr dead_on_unwind writable sret(%"class.std::bitset<1000001>::reference") align 8 %9, ptr noundef nonnull align 8 dereferenceable(125008) @isPrime, i64 noundef %34)
  %35 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6bitsetILm1000001EE9referenceaSEb(ptr noundef nonnull align 8 dereferenceable(16) %9, i1 noundef zeroext false) #3
  call void @_ZNSt6bitsetILm1000001EE9referenceD2Ev(ptr noundef nonnull align 8 dereferenceable(16) %9) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr %9) #3
  br label %36

36:                                               ; preds = %33
  %37 = load i64, ptr %5, align 8, !tbaa !5
  %38 = load i64, ptr %8, align 8, !tbaa !5
  %39 = add nsw i64 %38, %37
  store i64 %39, ptr %8, align 8, !tbaa !5
  br label %29, !llvm.loop !9

40:                                               ; preds = %32
  br label %41

41:                                               ; preds = %40, %22
  br label %42

42:                                               ; preds = %41
  %43 = load i64, ptr %5, align 8, !tbaa !5
  %44 = add nsw i64 %43, 1
  store i64 %44, ptr %5, align 8, !tbaa !5
  br label %14, !llvm.loop !11

45:                                               ; preds = %17
  ret void

46:                                               ; preds = %18
  %47 = load ptr, ptr %3, align 8
  %48 = load i32, ptr %4, align 4
  %49 = insertvalue { ptr, i32 } poison, ptr %47, 0
  %50 = insertvalue { ptr, i32 } %49, i32 %48, 1
  resume { ptr, i32 } %50
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(125008) ptr @_ZNSt6bitsetILm1000001EE3setEv(ptr noundef nonnull align 8 dereferenceable(125008)) #1 align 2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt6bitsetILm1000001EEixEm(ptr dead_on_unwind noalias writable sret(%"class.std::bitset<1000001>::reference") align 8, ptr noundef nonnull align 8 dereferenceable(125008), i64 noundef) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6bitsetILm1000001EE9referenceaSEb(ptr noundef nonnull align 8 dereferenceable(16), i1 noundef zeroext) #1 align 2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6bitsetILm1000001EE9referenceaSERKS1_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt6bitsetILm1000001EE9referenceD2Ev(ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #1 align 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 nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNKSt6bitsetILm1000001EE9referencecvbEv(ptr noundef nonnull align 8 dereferenceable(16)) #1 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 = { 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 = { 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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


; 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::bitset<1000001>::reference" = type { ptr, i64 }

@isPrime = external dso_local global { [15626 x i64] }, align 8

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z5sievev() local_unnamed_addr #0 personality ptr @__gxx_personality_v0 {
  %1 = alloca %"class.std::bitset<1000001>::reference", align 8
  %2 = alloca %"class.std::bitset<1000001>::reference", align 8
  %3 = alloca %"class.std::bitset<1000001>::reference", align 8
  %4 = alloca %"class.std::bitset<1000001>::reference", align 8
  %5 = tail call noundef nonnull align 8 dereferenceable(125008) ptr @_ZNSt6bitsetILm1000001EE3setEv(ptr noundef nonnull align 8 dereferenceable(125008) @isPrime) #2
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %1) #2
  call void @_ZNSt6bitsetILm1000001EEixEm(ptr dead_on_unwind nonnull writable sret(%"class.std::bitset<1000001>::reference") align 8 %1, ptr noundef nonnull align 8 dereferenceable(125008) @isPrime, i64 noundef 1)
  %6 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6bitsetILm1000001EE9referenceaSEb(ptr noundef nonnull align 8 dereferenceable(16) %1, i1 noundef zeroext false) #2
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %2) #2
  call void @_ZNSt6bitsetILm1000001EEixEm(ptr dead_on_unwind nonnull writable sret(%"class.std::bitset<1000001>::reference") align 8 %2, ptr noundef nonnull align 8 dereferenceable(125008) @isPrime, i64 noundef 0)
  %7 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6bitsetILm1000001EE9referenceaSERKS1_(ptr noundef nonnull align 8 dereferenceable(16) %2, ptr noundef nonnull align 8 dereferenceable(16) %6) #2
  call void @_ZNSt6bitsetILm1000001EE9referenceD2Ev(ptr noundef nonnull align 8 dereferenceable(16) %2) #2
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %2) #2
  call void @_ZNSt6bitsetILm1000001EE9referenceD2Ev(ptr noundef nonnull align 8 dereferenceable(16) %1) #2
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %1) #2
  br label %9

8:                                                ; preds = %.loopexit
  ret void

9:                                                ; preds = %0, %.loopexit
  %.0911 = phi i64 [ 2, %0 ], [ %16, %.loopexit ]
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %3) #2
  call void @_ZNSt6bitsetILm1000001EEixEm(ptr dead_on_unwind nonnull writable sret(%"class.std::bitset<1000001>::reference") align 8 %3, ptr noundef nonnull align 8 dereferenceable(125008) @isPrime, i64 noundef %.0911)
  %10 = call noundef zeroext i1 @_ZNKSt6bitsetILm1000001EE9referencecvbEv(ptr noundef nonnull align 8 dereferenceable(16) %3) #2
  call void @_ZNSt6bitsetILm1000001EE9referenceD2Ev(ptr noundef nonnull align 8 dereferenceable(16) %3) #2
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %3) #2
  %11 = mul nuw nsw i64 %.0911, %.0911
  %12 = icmp ult i64 %11, 1000001
  %or.cond = select i1 %10, i1 %12, i1 false
  br i1 %or.cond, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %9, %.lr.ph
  %.010 = phi i64 [ %14, %.lr.ph ], [ %11, %9 ]
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %4) #2
  call void @_ZNSt6bitsetILm1000001EEixEm(ptr dead_on_unwind nonnull writable sret(%"class.std::bitset<1000001>::reference") align 8 %4, ptr noundef nonnull align 8 dereferenceable(125008) @isPrime, i64 noundef %.010)
  %13 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6bitsetILm1000001EE9referenceaSEb(ptr noundef nonnull align 8 dereferenceable(16) %4, i1 noundef zeroext false) #2
  call void @_ZNSt6bitsetILm1000001EE9referenceD2Ev(ptr noundef nonnull align 8 dereferenceable(16) %4) #2
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %4) #2
  %14 = add nuw nsw i64 %.010, %.0911
  %15 = icmp ult i64 %14, 1000001
  br i1 %15, label %.lr.ph, label %.loopexit, !llvm.loop !5

.loopexit:                                        ; preds = %.lr.ph, %9
  %16 = add nuw nsw i64 %.0911, 1
  %exitcond.not = icmp eq i64 %16, 1000001
  br i1 %exitcond.not, label %8, label %9, !llvm.loop !7
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(125008) ptr @_ZNSt6bitsetILm1000001EE3setEv(ptr noundef nonnull align 8 dereferenceable(125008)) local_unnamed_addr #0 align 2

; 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 nounwind uwtable
declare dso_local void @_ZNSt6bitsetILm1000001EEixEm(ptr dead_on_unwind noalias writable sret(%"class.std::bitset<1000001>::reference") align 8, ptr noundef nonnull align 8 dereferenceable(125008), i64 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6bitsetILm1000001EE9referenceaSEb(ptr noundef nonnull align 8 dereferenceable(16), i1 noundef zeroext) local_unnamed_addr #0 align 2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6bitsetILm1000001EE9referenceaSERKS1_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt6bitsetILm1000001EE9referenceD2Ev(ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #0 align 2

; 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 nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNKSt6bitsetILm1000001EE9referencecvbEv(ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #0 align 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 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = distinct !{!7, !6}


; Effective O3 passes: GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass