; LLVM IR from brpapa/algorithms :: solutions/spoj/PRIME1.ll (Z5sievei)

; 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 }
%"class.std::bitset<35001>::reference" = type { ptr, i64 }

@primes = external dso_local global %"class.std::vector", align 8
@is = external dso_local global { [547 x i64] }, align 8

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5sievei(i32 noundef %0) #0 personality ptr @__gxx_personality_v0 {
  %2 = alloca i32, align 4
  %3 = alloca %"class.std::bitset<35001>::reference", align 8
  %4 = alloca %"class.std::bitset<35001>::reference", align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca %"class.std::bitset<35001>::reference", align 8
  %10 = alloca i32, align 4
  %11 = alloca %"class.std::bitset<35001>::reference", align 8
  store i32 %0, ptr %2, align 4, !tbaa !5
  %12 = call noundef nonnull align 8 dereferenceable(4376) ptr @_ZNSt6bitsetILm35001EE3setEv(ptr noundef nonnull align 8 dereferenceable(4376) @is) #3
  call void @llvm.lifetime.start.p0(i64 16, ptr %3) #3
  call void @_ZNSt6bitsetILm35001EEixEm(ptr dead_on_unwind writable sret(%"class.std::bitset<35001>::reference") align 8 %3, ptr noundef nonnull align 8 dereferenceable(4376) @is, i64 noundef 1)
  %13 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6bitsetILm35001EE9referenceaSEb(ptr noundef nonnull align 8 dereferenceable(16) %3, i1 noundef zeroext false) #3
  call void @llvm.lifetime.start.p0(i64 16, ptr %4) #3
  invoke void @_ZNSt6bitsetILm35001EEixEm(ptr dead_on_unwind writable sret(%"class.std::bitset<35001>::reference") align 8 %4, ptr noundef nonnull align 8 dereferenceable(4376) @is, i64 noundef 0)
          to label %14 unwind label %21

14:                                               ; preds = %1
  %15 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6bitsetILm35001EE9referenceaSERKS1_(ptr noundef nonnull align 8 dereferenceable(16) %4, ptr noundef nonnull align 8 dereferenceable(16) %13) #3
  call void @_ZNSt6bitsetILm35001EE9referenceD2Ev(ptr noundef nonnull align 8 dereferenceable(16) %4) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr %4) #3
  call void @_ZNSt6bitsetILm35001EE9referenceD2Ev(ptr noundef nonnull align 8 dereferenceable(16) %3) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 2, ptr %7, align 4, !tbaa !5
  br label %16

16:                                               ; preds = %48, %14
  %17 = load i32, ptr %7, align 4, !tbaa !5
  %18 = load i32, ptr %2, align 4, !tbaa !5
  %19 = icmp slt i32 %17, %18
  br i1 %19, label %25, label %20

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

21:                                               ; preds = %1
  %22 = landingpad { ptr, i32 }
          cleanup
  %23 = extractvalue { ptr, i32 } %22, 0
  store ptr %23, ptr %5, align 8
  %24 = extractvalue { ptr, i32 } %22, 1
  store i32 %24, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 16, ptr %4) #3
  call void @_ZNSt6bitsetILm35001EE9referenceD2Ev(ptr noundef nonnull align 8 dereferenceable(16) %3) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr %3) #3
  br label %52

25:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 16, ptr %9) #3
  %26 = load i32, ptr %7, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  call void @_ZNSt6bitsetILm35001EEixEm(ptr dead_on_unwind writable sret(%"class.std::bitset<35001>::reference") align 8 %9, ptr noundef nonnull align 8 dereferenceable(4376) @is, i64 noundef %27)
  %28 = call noundef zeroext i1 @_ZNKSt6bitsetILm35001EE9referencecvbEv(ptr noundef nonnull align 8 dereferenceable(16) %9) #3
  call void @_ZNSt6bitsetILm35001EE9referenceD2Ev(ptr noundef nonnull align 8 dereferenceable(16) %9) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr %9) #3
  br i1 %28, label %29, label %47

29:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %30 = load i32, ptr %7, align 4, !tbaa !5
  %31 = load i32, ptr %7, align 4, !tbaa !5
  %32 = mul nsw i32 %30, %31
  store i32 %32, ptr %10, align 4, !tbaa !5
  br label %33

33:                                               ; preds = %42, %29
  %34 = load i32, ptr %10, align 4, !tbaa !5
  %35 = load i32, ptr %2, align 4, !tbaa !5
  %36 = icmp slt i32 %34, %35
  br i1 %36, label %38, label %37

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

38:                                               ; preds = %33
  call void @llvm.lifetime.start.p0(i64 16, ptr %11) #3
  %39 = load i32, ptr %10, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  call void @_ZNSt6bitsetILm35001EEixEm(ptr dead_on_unwind writable sret(%"class.std::bitset<35001>::reference") align 8 %11, ptr noundef nonnull align 8 dereferenceable(4376) @is, i64 noundef %40)
  %41 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6bitsetILm35001EE9referenceaSEb(ptr noundef nonnull align 8 dereferenceable(16) %11, i1 noundef zeroext false) #3
  call void @_ZNSt6bitsetILm35001EE9referenceD2Ev(ptr noundef nonnull align 8 dereferenceable(16) %11) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr %11) #3
  br label %42

42:                                               ; preds = %38
  %43 = load i32, ptr %7, align 4, !tbaa !5
  %44 = load i32, ptr %10, align 4, !tbaa !5
  %45 = add nsw i32 %44, %43
  store i32 %45, ptr %10, align 4, !tbaa !5
  br label %33, !llvm.loop !9

46:                                               ; preds = %37
  call void @_ZNSt6vectorIiSaIiEE9push_backERKi(ptr noundef nonnull align 8 dereferenceable(24) @primes, ptr noundef nonnull align 4 dereferenceable(4) %7)
  br label %47

47:                                               ; preds = %46, %25
  br label %48

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

51:                                               ; preds = %20
  ret void

52:                                               ; preds = %21
  %53 = load ptr, ptr %5, align 8
  %54 = load i32, ptr %6, align 4
  %55 = insertvalue { ptr, i32 } poison, ptr %53, 0
  %56 = insertvalue { ptr, i32 } %55, i32 %54, 1
  resume { ptr, i32 } %56
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(4376) ptr @_ZNSt6bitsetILm35001EE3setEv(ptr noundef nonnull align 8 dereferenceable(4376)) #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 @_ZNSt6bitsetILm35001EEixEm(ptr dead_on_unwind noalias writable sret(%"class.std::bitset<35001>::reference") align 8, ptr noundef nonnull align 8 dereferenceable(4376), i64 noundef) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6bitsetILm35001EE9referenceaSEb(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 @_ZNSt6bitsetILm35001EE9referenceaSERKS1_(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 @_ZNSt6bitsetILm35001EE9referenceD2Ev(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 @_ZNKSt6bitsetILm35001EE9referencecvbEv(ptr noundef nonnull align 8 dereferenceable(16)) #1 align 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 = { 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 = !{!"int", !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::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 }
%"class.std::bitset<35001>::reference" = type { ptr, i64 }

@primes = external dso_local global %"class.std::vector", align 8
@is = external dso_local global { [547 x i64] }, align 8

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5sievei(i32 noundef %0) local_unnamed_addr #0 personality ptr @__gxx_personality_v0 {
  %2 = alloca %"class.std::bitset<35001>::reference", align 8
  %3 = alloca %"class.std::bitset<35001>::reference", align 8
  %4 = alloca i32, align 4
  %5 = alloca %"class.std::bitset<35001>::reference", align 8
  %6 = alloca %"class.std::bitset<35001>::reference", align 8
  %7 = tail call noundef nonnull align 8 dereferenceable(4376) ptr @_ZNSt6bitsetILm35001EE3setEv(ptr noundef nonnull align 8 dereferenceable(4376) @is) #3
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %2) #3
  call void @_ZNSt6bitsetILm35001EEixEm(ptr dead_on_unwind nonnull writable sret(%"class.std::bitset<35001>::reference") align 8 %2, ptr noundef nonnull align 8 dereferenceable(4376) @is, i64 noundef 1)
  %8 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6bitsetILm35001EE9referenceaSEb(ptr noundef nonnull align 8 dereferenceable(16) %2, i1 noundef zeroext false) #3
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %3) #3
  call void @_ZNSt6bitsetILm35001EEixEm(ptr dead_on_unwind nonnull writable sret(%"class.std::bitset<35001>::reference") align 8 %3, ptr noundef nonnull align 8 dereferenceable(4376) @is, i64 noundef 0)
  %9 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6bitsetILm35001EE9referenceaSERKS1_(ptr noundef nonnull align 8 dereferenceable(16) %3, ptr noundef nonnull align 8 dereferenceable(16) %8) #3
  call void @_ZNSt6bitsetILm35001EE9referenceD2Ev(ptr noundef nonnull align 8 dereferenceable(16) %3) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %3) #3
  call void @_ZNSt6bitsetILm35001EE9referenceD2Ev(ptr noundef nonnull align 8 dereferenceable(16) %2) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %2) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #3
  store i32 2, ptr %4, align 4, !tbaa !5
  %10 = icmp sgt i32 %0, 2
  br i1 %10, label %.lr.ph9, label %._crit_edge10

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

.lr.ph9:                                          ; preds = %1, %22
  %storemerge7 = phi i32 [ %24, %22 ], [ 2, %1 ]
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %5) #3
  %11 = sext i32 %storemerge7 to i64
  call void @_ZNSt6bitsetILm35001EEixEm(ptr dead_on_unwind nonnull writable sret(%"class.std::bitset<35001>::reference") align 8 %5, ptr noundef nonnull align 8 dereferenceable(4376) @is, i64 noundef %11)
  %12 = call noundef zeroext i1 @_ZNKSt6bitsetILm35001EE9referencecvbEv(ptr noundef nonnull align 8 dereferenceable(16) %5) #3
  call void @_ZNSt6bitsetILm35001EE9referenceD2Ev(ptr noundef nonnull align 8 dereferenceable(16) %5) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %5) #3
  br i1 %12, label %13, label %22

13:                                               ; preds = %.lr.ph9
  %14 = load i32, ptr %4, align 4, !tbaa !5
  %15 = mul nsw i32 %14, %14
  %16 = icmp slt i32 %15, %0
  br i1 %16, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %13
  call void @_ZNSt6vectorIiSaIiEE9push_backERKi(ptr noundef nonnull align 8 dereferenceable(24) @primes, ptr noundef nonnull align 4 dereferenceable(4) %4)
  br label %22

.lr.ph:                                           ; preds = %13, %.lr.ph
  %.06 = phi i32 [ %20, %.lr.ph ], [ %15, %13 ]
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %6) #3
  %17 = sext i32 %.06 to i64
  call void @_ZNSt6bitsetILm35001EEixEm(ptr dead_on_unwind nonnull writable sret(%"class.std::bitset<35001>::reference") align 8 %6, ptr noundef nonnull align 8 dereferenceable(4376) @is, i64 noundef %17)
  %18 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6bitsetILm35001EE9referenceaSEb(ptr noundef nonnull align 8 dereferenceable(16) %6, i1 noundef zeroext false) #3
  call void @_ZNSt6bitsetILm35001EE9referenceD2Ev(ptr noundef nonnull align 8 dereferenceable(16) %6) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %6) #3
  %19 = load i32, ptr %4, align 4, !tbaa !5
  %20 = add nsw i32 %19, %.06
  %21 = icmp slt i32 %20, %0
  br i1 %21, label %.lr.ph, label %._crit_edge, !llvm.loop !9

22:                                               ; preds = %.lr.ph9, %._crit_edge
  %23 = load i32, ptr %4, align 4, !tbaa !5
  %24 = add nsw i32 %23, 1
  store i32 %24, ptr %4, align 4, !tbaa !5
  %25 = icmp slt i32 %24, %0
  br i1 %25, label %.lr.ph9, label %._crit_edge10, !llvm.loop !11
}

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

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

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

declare i32 @__gxx_personality_v0(...)

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt6bitsetILm35001EE9referenceD2Ev(ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #1 align 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 nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNKSt6bitsetILm35001EE9referencecvbEv(ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #1 align 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

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 = { mustprogress 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 = !{!"int", !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}


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