; LLVM IR from Algo-Phantoms/Algo-Tree :: Code/C++/check_prime.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::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<1000000>::reference" = type { ptr, i64 }

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5sievev() #0 personality ptr @__gxx_personality_v0 {
  %1 = alloca %"class.std::bitset<1000000>::reference", align 8
  %2 = alloca %"class.std::bitset<1000000>::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<1000000>::reference", align 8
  %8 = alloca i32, align 4
  %9 = alloca i64, align 8
  %10 = alloca %"class.std::bitset<1000000>::reference", align 8
  %11 = call noundef nonnull align 8 dereferenceable(125000) ptr @_ZNSt6bitsetILm1000000EE3setEv(ptr noundef nonnull align 8 dereferenceable(125000) @b) #3
  call void @llvm.lifetime.start.p0(i64 16, ptr %1) #3
  call void @_ZNSt6bitsetILm1000000EEixEm(ptr dead_on_unwind writable sret(%"class.std::bitset<1000000>::reference") align 8 %1, ptr noundef nonnull align 8 dereferenceable(125000) @b, i64 noundef 1)
  %12 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6bitsetILm1000000EE9referenceaSEb(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 @_ZNSt6bitsetILm1000000EEixEm(ptr dead_on_unwind writable sret(%"class.std::bitset<1000000>::reference") align 8 %2, ptr noundef nonnull align 8 dereferenceable(125000) @b, i64 noundef 0)
          to label %13 unwind label %19

13:                                               ; preds = %0
  %14 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6bitsetILm1000000EE9referenceaSERKS1_(ptr noundef nonnull align 8 dereferenceable(16) %2, ptr noundef nonnull align 8 dereferenceable(16) %12) #3
  call void @_ZNSt6bitsetILm1000000EE9referenceD2Ev(ptr noundef nonnull align 8 dereferenceable(16) %2) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr %2) #3
  call void @_ZNSt6bitsetILm1000000EE9referenceD2Ev(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 %15

15:                                               ; preds = %45, %13
  %16 = load i64, ptr %5, align 8, !tbaa !5
  %17 = icmp sle i64 %16, 1000000
  br i1 %17, label %23, label %18

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

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

23:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 16, ptr %7) #3
  %24 = load i64, ptr %5, align 8, !tbaa !5
  call void @_ZNSt6bitsetILm1000000EEixEm(ptr dead_on_unwind writable sret(%"class.std::bitset<1000000>::reference") align 8 %7, ptr noundef nonnull align 8 dereferenceable(125000) @b, i64 noundef %24)
  %25 = call noundef zeroext i1 @_ZNKSt6bitsetILm1000000EE9referencecvbEv(ptr noundef nonnull align 8 dereferenceable(16) %7) #3
  call void @_ZNSt6bitsetILm1000000EE9referenceD2Ev(ptr noundef nonnull align 8 dereferenceable(16) %7) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr %7) #3
  br i1 %25, label %26, label %44

26:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %27 = load i64, ptr %5, align 8, !tbaa !5
  %28 = trunc i64 %27 to i32
  store i32 %28, ptr %8, align 4, !tbaa !9
  call void @_ZNSt6vectorIiSaIiEE9push_backEOi(ptr noundef nonnull align 8 dereferenceable(24) @primes, ptr noundef nonnull align 4 dereferenceable(4) %8)
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %29 = load i64, ptr %5, align 8, !tbaa !5
  %30 = load i64, ptr %5, align 8, !tbaa !5
  %31 = mul nsw i64 %29, %30
  store i64 %31, ptr %9, align 8, !tbaa !5
  br label %32

32:                                               ; preds = %39, %26
  %33 = load i64, ptr %9, align 8, !tbaa !5
  %34 = icmp sle i64 %33, 1000000
  br i1 %34, label %36, label %35

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

36:                                               ; preds = %32
  call void @llvm.lifetime.start.p0(i64 16, ptr %10) #3
  %37 = load i64, ptr %9, align 8, !tbaa !5
  call void @_ZNSt6bitsetILm1000000EEixEm(ptr dead_on_unwind writable sret(%"class.std::bitset<1000000>::reference") align 8 %10, ptr noundef nonnull align 8 dereferenceable(125000) @b, i64 noundef %37)
  %38 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6bitsetILm1000000EE9referenceaSEb(ptr noundef nonnull align 8 dereferenceable(16) %10, i1 noundef zeroext false) #3
  call void @_ZNSt6bitsetILm1000000EE9referenceD2Ev(ptr noundef nonnull align 8 dereferenceable(16) %10) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr %10) #3
  br label %39

39:                                               ; preds = %36
  %40 = load i64, ptr %9, align 8, !tbaa !5
  %41 = load i64, ptr %5, align 8, !tbaa !5
  %42 = add nsw i64 %40, %41
  store i64 %42, ptr %9, align 8, !tbaa !5
  br label %32, !llvm.loop !11

43:                                               ; preds = %35
  br label %44

44:                                               ; preds = %43, %23
  br label %45

45:                                               ; preds = %44
  %46 = load i64, ptr %5, align 8, !tbaa !5
  %47 = add nsw i64 %46, 1
  store i64 %47, ptr %5, align 8, !tbaa !5
  br label %15, !llvm.loop !13

48:                                               ; preds = %18
  ret void

49:                                               ; preds = %19
  %50 = load ptr, ptr %3, align 8
  %51 = load i32, ptr %4, align 4
  %52 = insertvalue { ptr, i32 } poison, ptr %50, 0
  %53 = insertvalue { ptr, i32 } %52, i32 %51, 1
  resume { ptr, i32 } %53
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6bitsetILm1000000EE9referenceaSEb(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 @_ZNSt6bitsetILm1000000EE9referenceaSERKS1_(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 @_ZNSt6bitsetILm1000000EE9referenceD2Ev(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 @_ZNKSt6bitsetILm1000000EE9referencecvbEv(ptr noundef nonnull align 8 dereferenceable(16)) #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNSt6vectorIiSaIiEE9push_backEOi(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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !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 }
%"class.std::bitset<1000000>::reference" = type { ptr, i64 }

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5sievev() local_unnamed_addr #0 personality ptr @__gxx_personality_v0 {
  %1 = alloca %"class.std::bitset<1000000>::reference", align 8
  %2 = alloca %"class.std::bitset<1000000>::reference", align 8
  %3 = alloca %"class.std::bitset<1000000>::reference", align 8
  %4 = alloca i32, align 4
  %5 = alloca %"class.std::bitset<1000000>::reference", align 8
  %6 = tail call noundef nonnull align 8 dereferenceable(125000) ptr @_ZNSt6bitsetILm1000000EE3setEv(ptr noundef nonnull align 8 dereferenceable(125000) @b) #3
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %1) #3
  call void @_ZNSt6bitsetILm1000000EEixEm(ptr dead_on_unwind nonnull writable sret(%"class.std::bitset<1000000>::reference") align 8 %1, ptr noundef nonnull align 8 dereferenceable(125000) @b, i64 noundef 1)
  %7 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6bitsetILm1000000EE9referenceaSEb(ptr noundef nonnull align 8 dereferenceable(16) %1, i1 noundef zeroext false) #3
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %2) #3
  call void @_ZNSt6bitsetILm1000000EEixEm(ptr dead_on_unwind nonnull writable sret(%"class.std::bitset<1000000>::reference") align 8 %2, ptr noundef nonnull align 8 dereferenceable(125000) @b, i64 noundef 0)
  %8 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6bitsetILm1000000EE9referenceaSERKS1_(ptr noundef nonnull align 8 dereferenceable(16) %2, ptr noundef nonnull align 8 dereferenceable(16) %7) #3
  call void @_ZNSt6bitsetILm1000000EE9referenceD2Ev(ptr noundef nonnull align 8 dereferenceable(16) %2) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %2) #3
  call void @_ZNSt6bitsetILm1000000EE9referenceD2Ev(ptr noundef nonnull align 8 dereferenceable(16) %1) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %1) #3
  br label %10

9:                                                ; preds = %.loopexit
  ret void

10:                                               ; preds = %0, %.loopexit
  %.01012 = phi i64 [ 2, %0 ], [ %19, %.loopexit ]
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %3) #3
  call void @_ZNSt6bitsetILm1000000EEixEm(ptr dead_on_unwind nonnull writable sret(%"class.std::bitset<1000000>::reference") align 8 %3, ptr noundef nonnull align 8 dereferenceable(125000) @b, i64 noundef %.01012)
  %11 = call noundef zeroext i1 @_ZNKSt6bitsetILm1000000EE9referencecvbEv(ptr noundef nonnull align 8 dereferenceable(16) %3) #3
  call void @_ZNSt6bitsetILm1000000EE9referenceD2Ev(ptr noundef nonnull align 8 dereferenceable(16) %3) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %3) #3
  br i1 %11, label %12, label %.loopexit

12:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #3
  %13 = trunc nuw i64 %.01012 to i32
  store i32 %13, ptr %4, align 4, !tbaa !5
  call void @_ZNSt6vectorIiSaIiEE9push_backEOi(ptr noundef nonnull align 8 dereferenceable(24) @primes, ptr noundef nonnull align 4 dereferenceable(4) %4)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #3
  %14 = mul nuw nsw i64 %.01012, %.01012
  %15 = icmp ult i64 %14, 1000001
  br i1 %15, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %12, %.lr.ph
  %.011 = phi i64 [ %17, %.lr.ph ], [ %14, %12 ]
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %5) #3
  call void @_ZNSt6bitsetILm1000000EEixEm(ptr dead_on_unwind nonnull writable sret(%"class.std::bitset<1000000>::reference") align 8 %5, ptr noundef nonnull align 8 dereferenceable(125000) @b, i64 noundef %.011)
  %16 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6bitsetILm1000000EE9referenceaSEb(ptr noundef nonnull align 8 dereferenceable(16) %5, i1 noundef zeroext false) #3
  call void @_ZNSt6bitsetILm1000000EE9referenceD2Ev(ptr noundef nonnull align 8 dereferenceable(16) %5) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %5) #3
  %17 = add nuw nsw i64 %.011, %.01012
  %18 = icmp ult i64 %17, 1000001
  br i1 %18, label %.lr.ph, label %.loopexit, !llvm.loop !9

.loopexit:                                        ; preds = %.lr.ph, %12, %10
  %19 = add nuw nsw i64 %.01012, 1
  %exitcond.not = icmp eq i64 %19, 1000001
  br i1 %exitcond.not, label %9, label %10, !llvm.loop !11
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6bitsetILm1000000EE9referenceaSEb(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 @_ZNSt6bitsetILm1000000EE9referenceaSERKS1_(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 @_ZNSt6bitsetILm1000000EE9referenceD2Ev(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 @_ZNKSt6bitsetILm1000000EE9referencecvbEv(ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNSt6vectorIiSaIiEE9push_backEOi(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: GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass