; LLVM IR from priyankchheda/algorithms :: _other_languages/cpp/Maths/sieve_of_eratosthenes.ll (Z21sieve_of_eratosthenesi)

; 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::basic_ostream" = type { ptr, %"class.std::basic_ios" }
%"class.std::basic_ios" = type { %"class.std::ios_base", ptr, i8, i8, ptr, ptr, ptr, ptr }
%"class.std::ios_base" = type { ptr, i64, i64, i32, i32, i32, ptr, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, ptr, %"class.std::locale" }
%"struct.std::ios_base::_Words" = type { ptr, i64 }
%"class.std::locale" = type { ptr }
%"class.std::bitset" = type { %"struct.std::_Base_bitset" }
%"struct.std::_Base_bitset" = type { i64 }
%"class.std::bitset<31>::reference" = type { ptr, i64 }

@_ZSt4cout = external global %"class.std::basic_ostream", align 8
@.str = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z21sieve_of_eratosthenesi(i32 noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca %"class.std::bitset", align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca %"class.std::bitset<31>::reference", align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca %"class.std::bitset<31>::reference", align 8
  store i32 %0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #5
  call void @_ZNSt6bitsetILm31EEC2Ev(ptr noundef nonnull align 8 dereferenceable(8) %3) #5
  %10 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6bitsetILm31EE3setEv(ptr noundef nonnull align 8 dereferenceable(8) %3) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  store i32 2, ptr %4, align 4, !tbaa !5
  br label %11

11:                                               ; preds = %41, %1
  %12 = load i32, ptr %4, align 4, !tbaa !5
  %13 = load i32, ptr %4, align 4, !tbaa !5
  %14 = mul nsw i32 %12, %13
  %15 = load i32, ptr %2, align 4, !tbaa !5
  %16 = icmp sle i32 %14, %15
  br i1 %16, label %18, label %17

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

18:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 16, ptr %6) #5
  %19 = load i32, ptr %4, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  call void @_ZNSt6bitsetILm31EEixEm(ptr dead_on_unwind writable sret(%"class.std::bitset<31>::reference") align 8 %6, ptr noundef nonnull align 8 dereferenceable(8) %3, i64 noundef %20)
  %21 = call noundef zeroext i1 @_ZNKSt6bitsetILm31EE9referencecvbEv(ptr noundef nonnull align 8 dereferenceable(16) %6) #5
  call void @_ZNSt6bitsetILm31EE9referenceD2Ev(ptr noundef nonnull align 8 dereferenceable(16) %6) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr %6) #5
  br i1 %21, label %22, label %40

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

26:                                               ; preds = %35, %22
  %27 = load i32, ptr %7, align 4, !tbaa !5
  %28 = load i32, ptr %2, align 4, !tbaa !5
  %29 = icmp sle i32 %27, %28
  br i1 %29, label %31, label %30

30:                                               ; preds = %26
  store i32 5, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  br label %39

31:                                               ; preds = %26
  %32 = load i32, ptr %7, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6bitsetILm31EE5resetEm(ptr noundef nonnull align 8 dereferenceable(8) %3, i64 noundef %33)
  br label %35

35:                                               ; preds = %31
  %36 = load i32, ptr %4, align 4, !tbaa !5
  %37 = load i32, ptr %7, align 4, !tbaa !5
  %38 = add nsw i32 %37, %36
  store i32 %38, ptr %7, align 4, !tbaa !5
  br label %26, !llvm.loop !9

39:                                               ; preds = %30
  br label %40

40:                                               ; preds = %39, %18
  br label %41

41:                                               ; preds = %40
  %42 = load i32, ptr %4, align 4, !tbaa !5
  %43 = add nsw i32 %42, 1
  store i32 %43, ptr %4, align 4, !tbaa !5
  br label %11, !llvm.loop !11

44:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  store i32 2, ptr %8, align 4, !tbaa !5
  br label %45

45:                                               ; preds = %59, %44
  %46 = load i32, ptr %8, align 4, !tbaa !5
  %47 = load i32, ptr %2, align 4, !tbaa !5
  %48 = icmp sle i32 %46, %47
  br i1 %48, label %50, label %49

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

50:                                               ; preds = %45
  call void @llvm.lifetime.start.p0(i64 16, ptr %9) #5
  %51 = load i32, ptr %8, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  call void @_ZNSt6bitsetILm31EEixEm(ptr dead_on_unwind writable sret(%"class.std::bitset<31>::reference") align 8 %9, ptr noundef nonnull align 8 dereferenceable(8) %3, i64 noundef %52)
  %53 = call noundef zeroext i1 @_ZNKSt6bitsetILm31EE9referencecvbEv(ptr noundef nonnull align 8 dereferenceable(16) %9) #5
  call void @_ZNSt6bitsetILm31EE9referenceD2Ev(ptr noundef nonnull align 8 dereferenceable(16) %9) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr %9) #5
  br i1 %53, label %54, label %58

54:                                               ; preds = %50
  %55 = load i32, ptr %8, align 4, !tbaa !5
  %56 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i32 noundef %55)
  %57 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) %56, ptr noundef @.str)
  br label %58

58:                                               ; preds = %54, %50
  br label %59

59:                                               ; preds = %58
  %60 = load i32, ptr %8, align 4, !tbaa !5
  %61 = add nsw i32 %60, 1
  store i32 %61, ptr %8, align 4, !tbaa !5
  br label %45, !llvm.loop !12

62:                                               ; preds = %49
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #5
  ret void
}

; Function Attrs: 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 @_ZNSt6bitsetILm31EEC2Ev(ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #2 align 2

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

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

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

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

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

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

; Function Attrs: inlinehint mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) #3

declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8), i32 noundef) #4

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { inlinehint 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 #4 = { "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 #5 = { 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}
!12 = distinct !{!12, !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::basic_ostream" = type { ptr, %"class.std::basic_ios" }
%"class.std::basic_ios" = type { %"class.std::ios_base", ptr, i8, i8, ptr, ptr, ptr, ptr }
%"class.std::ios_base" = type { ptr, i64, i64, i32, i32, i32, ptr, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, ptr, %"class.std::locale" }
%"struct.std::ios_base::_Words" = type { ptr, i64 }
%"class.std::locale" = type { ptr }
%"class.std::bitset" = type { %"struct.std::_Base_bitset" }
%"struct.std::_Base_bitset" = type { i64 }
%"class.std::bitset<31>::reference" = type { ptr, i64 }

@_ZSt4cout = external global %"class.std::basic_ostream", align 8
@.str = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z21sieve_of_eratosthenesi(i32 noundef %0) local_unnamed_addr #0 {
  %2 = alloca %"class.std::bitset", align 8
  %3 = alloca %"class.std::bitset<31>::reference", align 8
  %4 = alloca %"class.std::bitset<31>::reference", align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #5
  call void @_ZNSt6bitsetILm31EEC2Ev(ptr noundef nonnull align 8 dereferenceable(8) %2) #5
  %5 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6bitsetILm31EE3setEv(ptr noundef nonnull align 8 dereferenceable(8) %2) #5
  %.not26 = icmp slt i32 %0, 4
  br i1 %.not26, label %.preheader, label %.lr.ph28

.preheader:                                       ; preds = %.loopexit, %1
  %.not2129 = icmp slt i32 %0, 2
  br i1 %.not2129, label %._crit_edge, label %.lr.ph31.preheader

.lr.ph31.preheader:                               ; preds = %.preheader
  %6 = add nuw nsw i32 %0, 1
  %wide.trip.count = zext nneg i32 %6 to i64
  br label %.lr.ph31

.lr.ph28:                                         ; preds = %1, %.loopexit
  %indvars.iv = phi i64 [ %indvars.iv.next, %.loopexit ], [ 2, %1 ]
  %7 = phi i32 [ %13, %.loopexit ], [ 4, %1 ]
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %3) #5
  call void @_ZNSt6bitsetILm31EEixEm(ptr dead_on_unwind nonnull writable sret(%"class.std::bitset<31>::reference") align 8 %3, ptr noundef nonnull align 8 dereferenceable(8) %2, i64 noundef %indvars.iv)
  %8 = call noundef zeroext i1 @_ZNKSt6bitsetILm31EE9referencecvbEv(ptr noundef nonnull align 8 dereferenceable(16) %3) #5
  call void @_ZNSt6bitsetILm31EE9referenceD2Ev(ptr noundef nonnull align 8 dereferenceable(16) %3) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %3) #5
  %.not2224 = icmp sle i32 %7, %0
  %or.cond.not = and i1 %.not2224, %8
  br i1 %or.cond.not, label %.lr.ph.preheader, label %.loopexit

.lr.ph.preheader:                                 ; preds = %.lr.ph28
  %9 = zext nneg i32 %7 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv33 = phi i64 [ %9, %.lr.ph.preheader ], [ %indvars.iv.next34, %.lr.ph ]
  %10 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6bitsetILm31EE5resetEm(ptr noundef nonnull align 8 dereferenceable(8) %2, i64 noundef %indvars.iv33)
  %indvars.iv.next34 = add nuw nsw i64 %indvars.iv33, %indvars.iv
  %11 = trunc nuw i64 %indvars.iv.next34 to i32
  %.not22 = icmp sgt i32 %11, %0
  br i1 %.not22, label %.loopexit, label %.lr.ph, !llvm.loop !5

.loopexit:                                        ; preds = %.lr.ph, %.lr.ph28
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %12 = mul nuw nsw i64 %indvars.iv.next, %indvars.iv.next
  %13 = trunc nuw i64 %12 to i32
  %.not = icmp sgt i32 %13, %0
  br i1 %.not, label %.preheader, label %.lr.ph28, !llvm.loop !7

._crit_edge:                                      ; preds = %19, %.preheader
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #5
  ret void

.lr.ph31:                                         ; preds = %.lr.ph31.preheader, %19
  %indvars.iv37 = phi i64 [ 2, %.lr.ph31.preheader ], [ %indvars.iv.next38, %19 ]
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %4) #5
  call void @_ZNSt6bitsetILm31EEixEm(ptr dead_on_unwind nonnull writable sret(%"class.std::bitset<31>::reference") align 8 %4, ptr noundef nonnull align 8 dereferenceable(8) %2, i64 noundef %indvars.iv37)
  %14 = call noundef zeroext i1 @_ZNKSt6bitsetILm31EE9referencecvbEv(ptr noundef nonnull align 8 dereferenceable(16) %4) #5
  call void @_ZNSt6bitsetILm31EE9referenceD2Ev(ptr noundef nonnull align 8 dereferenceable(16) %4) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %4) #5
  br i1 %14, label %15, label %19

15:                                               ; preds = %.lr.ph31
  %16 = trunc nuw nsw i64 %indvars.iv37 to i32
  %17 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i32 noundef %16)
  %18 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) %17, ptr noundef nonnull @.str)
  br label %19

19:                                               ; preds = %.lr.ph31, %15
  %indvars.iv.next38 = add nuw nsw i64 %indvars.iv37, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next38, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph31, !llvm.loop !8
}

; 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 @_ZNSt6bitsetILm31EEC2Ev(ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #2 align 2

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

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt6bitsetILm31EE9referenceD2Ev(ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #2 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 uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6bitsetILm31EE5resetEm(ptr noundef nonnull align 8 dereferenceable(8), i64 noundef) local_unnamed_addr #0 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) local_unnamed_addr #3

declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8), i32 noundef) local_unnamed_addr #4

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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { inlinehint 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 #4 = { "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 #5 = { 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}
!8 = distinct !{!8, !6}


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