; LLVM IR from brpapa/algorithms :: solutions/uva/10539.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<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 }
%"class.std::bitset<1000101>::reference" = type { ptr, i64 }

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5sievev() #0 personality ptr @__gxx_personality_v0 {
  %1 = alloca %"class.std::bitset<1000101>::reference", align 8
  %2 = alloca %"class.std::bitset<1000101>::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<1000101>::reference", align 8
  %8 = alloca i64, align 8
  %9 = alloca %"class.std::bitset<1000101>::reference", align 8
  call void @_ZNSt6vectorIxSaIxEE5clearEv(ptr noundef nonnull align 8 dereferenceable(24) @primes) #3
  %10 = call noundef nonnull align 8 dereferenceable(125016) ptr @_ZNSt6bitsetILm1000101EE3setEv(ptr noundef nonnull align 8 dereferenceable(125016) @is) #3
  call void @llvm.lifetime.start.p0(i64 16, ptr %1) #3
  call void @_ZNSt6bitsetILm1000101EEixEm(ptr dead_on_unwind writable sret(%"class.std::bitset<1000101>::reference") align 8 %1, ptr noundef nonnull align 8 dereferenceable(125016) @is, i64 noundef 1)
  %11 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6bitsetILm1000101EE9referenceaSEb(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 @_ZNSt6bitsetILm1000101EEixEm(ptr dead_on_unwind writable sret(%"class.std::bitset<1000101>::reference") align 8 %2, ptr noundef nonnull align 8 dereferenceable(125016) @is, i64 noundef 0)
          to label %12 unwind label %18

12:                                               ; preds = %0
  %13 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6bitsetILm1000101EE9referenceaSERKS1_(ptr noundef nonnull align 8 dereferenceable(16) %2, ptr noundef nonnull align 8 dereferenceable(16) %11) #3
  call void @_ZNSt6bitsetILm1000101EE9referenceD2Ev(ptr noundef nonnull align 8 dereferenceable(16) %2) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr %2) #3
  call void @_ZNSt6bitsetILm1000101EE9referenceD2Ev(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, 1000100
  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 @_ZNSt6bitsetILm1000101EE9referenceD2Ev(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 @_ZNSt6bitsetILm1000101EEixEm(ptr dead_on_unwind writable sret(%"class.std::bitset<1000101>::reference") align 8 %7, ptr noundef nonnull align 8 dereferenceable(125016) @is, i64 noundef %23)
  %24 = call noundef zeroext i1 @_ZNKSt6bitsetILm1000101EE9referencecvbEv(ptr noundef nonnull align 8 dereferenceable(16) %7) #3
  call void @_ZNSt6bitsetILm1000101EE9referenceD2Ev(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 @_ZNSt6vectorIxSaIxEE9push_backERKx(ptr noundef nonnull align 8 dereferenceable(24) @primes, ptr noundef nonnull align 8 dereferenceable(8) %5)
  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, 1000100
  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 @_ZNSt6bitsetILm1000101EEixEm(ptr dead_on_unwind writable sret(%"class.std::bitset<1000101>::reference") align 8 %9, ptr noundef nonnull align 8 dereferenceable(125016) @is, i64 noundef %34)
  %35 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6bitsetILm1000101EE9referenceaSEb(ptr noundef nonnull align 8 dereferenceable(16) %9, i1 noundef zeroext false) #3
  call void @_ZNSt6bitsetILm1000101EE9referenceD2Ev(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 void @_ZNSt6vectorIxSaIxEE5clearEv(ptr noundef nonnull align 8 dereferenceable(24)) #1 align 2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6bitsetILm1000101EE9referenceaSEb(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 @_ZNSt6bitsetILm1000101EE9referenceaSERKS1_(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 @_ZNSt6bitsetILm1000101EE9referenceD2Ev(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 @_ZNKSt6bitsetILm1000101EE9referencecvbEv(ptr noundef nonnull align 8 dereferenceable(16)) #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNSt6vectorIxSaIxEE9push_backERKx(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 8 dereferenceable(8)) #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 = 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<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 }
%"class.std::bitset<1000101>::reference" = type { ptr, i64 }

@primes = external dso_local global %"class.std::vector", align 8
@is = external dso_local global { [15627 x i64] }, 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<1000101>::reference", align 8
  %2 = alloca %"class.std::bitset<1000101>::reference", align 8
  %3 = alloca i64, align 8
  %4 = alloca %"class.std::bitset<1000101>::reference", align 8
  %5 = alloca %"class.std::bitset<1000101>::reference", align 8
  tail call void @_ZNSt6vectorIxSaIxEE5clearEv(ptr noundef nonnull align 8 dereferenceable(24) @primes) #3
  %6 = tail call noundef nonnull align 8 dereferenceable(125016) ptr @_ZNSt6bitsetILm1000101EE3setEv(ptr noundef nonnull align 8 dereferenceable(125016) @is) #3
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %1) #3
  call void @_ZNSt6bitsetILm1000101EEixEm(ptr dead_on_unwind nonnull writable sret(%"class.std::bitset<1000101>::reference") align 8 %1, ptr noundef nonnull align 8 dereferenceable(125016) @is, i64 noundef 1)
  %7 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6bitsetILm1000101EE9referenceaSEb(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 @_ZNSt6bitsetILm1000101EEixEm(ptr dead_on_unwind nonnull writable sret(%"class.std::bitset<1000101>::reference") align 8 %2, ptr noundef nonnull align 8 dereferenceable(125016) @is, i64 noundef 0)
  %8 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6bitsetILm1000101EE9referenceaSERKS1_(ptr noundef nonnull align 8 dereferenceable(16) %2, ptr noundef nonnull align 8 dereferenceable(16) %7) #3
  call void @_ZNSt6bitsetILm1000101EE9referenceD2Ev(ptr noundef nonnull align 8 dereferenceable(16) %2) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %2) #3
  call void @_ZNSt6bitsetILm1000101EE9referenceD2Ev(ptr noundef nonnull align 8 dereferenceable(16) %1) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %1) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #3
  store i64 2, ptr %3, align 8, !tbaa !5
  br label %10

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

10:                                               ; preds = %0, %.loopexit
  %storemerge4 = phi i64 [ 2, %0 ], [ %21, %.loopexit ]
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %4) #3
  call void @_ZNSt6bitsetILm1000101EEixEm(ptr dead_on_unwind nonnull writable sret(%"class.std::bitset<1000101>::reference") align 8 %4, ptr noundef nonnull align 8 dereferenceable(125016) @is, i64 noundef %storemerge4)
  %11 = call noundef zeroext i1 @_ZNKSt6bitsetILm1000101EE9referencecvbEv(ptr noundef nonnull align 8 dereferenceable(16) %4) #3
  call void @_ZNSt6bitsetILm1000101EE9referenceD2Ev(ptr noundef nonnull align 8 dereferenceable(16) %4) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %4) #3
  br i1 %11, label %12, label %..loopexit_crit_edge

..loopexit_crit_edge:                             ; preds = %10
  %.pre = load i64, ptr %3, align 8, !tbaa !5
  br label %.loopexit

12:                                               ; preds = %10
  call void @_ZNSt6vectorIxSaIxEE9push_backERKx(ptr noundef nonnull align 8 dereferenceable(24) @primes, ptr noundef nonnull align 8 dereferenceable(8) %3)
  %13 = load i64, ptr %3, align 8, !tbaa !5
  %14 = mul nsw i64 %13, %13
  %15 = icmp ult i64 %14, 1000101
  br i1 %15, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %12, %.lr.ph
  %.03 = phi i64 [ %18, %.lr.ph ], [ %14, %12 ]
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %5) #3
  call void @_ZNSt6bitsetILm1000101EEixEm(ptr dead_on_unwind nonnull writable sret(%"class.std::bitset<1000101>::reference") align 8 %5, ptr noundef nonnull align 8 dereferenceable(125016) @is, i64 noundef %.03)
  %16 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6bitsetILm1000101EE9referenceaSEb(ptr noundef nonnull align 8 dereferenceable(16) %5, i1 noundef zeroext false) #3
  call void @_ZNSt6bitsetILm1000101EE9referenceD2Ev(ptr noundef nonnull align 8 dereferenceable(16) %5) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %5) #3
  %17 = load i64, ptr %3, align 8, !tbaa !5
  %18 = add nsw i64 %17, %.03
  %19 = icmp slt i64 %18, 1000101
  br i1 %19, label %.lr.ph, label %.loopexit, !llvm.loop !9

.loopexit:                                        ; preds = %.lr.ph, %..loopexit_crit_edge, %12
  %20 = phi i64 [ %.pre, %..loopexit_crit_edge ], [ %13, %12 ], [ %17, %.lr.ph ]
  %21 = add nsw i64 %20, 1
  store i64 %21, ptr %3, align 8, !tbaa !5
  %22 = icmp slt i64 %20, 1000100
  br i1 %22, label %10, label %9, !llvm.loop !11
}

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6bitsetILm1000101EE9referenceaSEb(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 @_ZNSt6bitsetILm1000101EE9referenceaSERKS1_(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 @_ZNSt6bitsetILm1000101EE9referenceD2Ev(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 @_ZNKSt6bitsetILm1000101EE9referencecvbEv(ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #1 align 2

; 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 #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 = !{!"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}


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