; LLVM IR from kimwalisch/primesieve :: src/SievingPrimes.ll (ZN10primesieve13SievingPrimes9tinySieveEv)

; 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.primesieve::Erat" = type { i64, i64, i64, i64, %"class.primesieve::Vector", i64, i64, %"class.primesieve::EratSmall", %"class.primesieve::EratBig", %"class.primesieve::EratMedium" }
%"class.primesieve::Vector" = type { ptr, ptr, ptr }
%"class.primesieve::EratSmall" = type { %"class.primesieve::Wheel", i64, i64, %"class.primesieve::Vector.0" }
%"class.primesieve::Wheel" = type { ptr, i64 }
%"class.primesieve::Vector.0" = type { ptr, ptr, ptr }
%"class.primesieve::EratBig" = type { %"class.primesieve::Wheel.1", i64, i64, i64, ptr, %"class.primesieve::Vector.2" }
%"class.primesieve::Wheel.1" = type { ptr, i64 }
%"class.primesieve::Vector.2" = type { ptr, ptr, ptr }
%"class.primesieve::EratMedium" = type { %"class.primesieve::Wheel", i64, ptr, %"class.primesieve::Vector.2", %"class.primesieve::Vector.2" }
%"class.primesieve::SievingPrimes" = type { %"class.primesieve::Erat", i64, i64, i64, i64, i64, %"class.primesieve::Array", %"class.primesieve::Vector.3" }
%"class.primesieve::Array" = type { [128 x i64] }
%"class.primesieve::Vector.3" = type { ptr, ptr, ptr }

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

; Function Attrs: inlinehint mustprogress uwtable
declare hidden noundef i64 @_ZN12_GLOBAL__N_15isqrtImEET_S1_(i64 noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN10primesieve13SievingPrimes9tinySieveEv(ptr noundef nonnull align 8 dereferenceable(1368) %0) #2 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = alloca i8, align 1
  %5 = alloca i64, align 8
  %6 = alloca i32, align 4
  %7 = alloca i64, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %8 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  %9 = getelementptr inbounds %"class.primesieve::Erat", ptr %8, i32 0, i32 1
  %10 = load i64, ptr %9, align 8, !tbaa !9
  %11 = call noundef i64 @_ZN12_GLOBAL__N_15isqrtImEET_S1_(i64 noundef %10)
  store i64 %11, ptr %3, align 8, !tbaa !20
  %12 = getelementptr inbounds %"class.primesieve::SievingPrimes", ptr %8, i32 0, i32 7
  %13 = load i64, ptr %3, align 8, !tbaa !20
  %14 = add i64 %13, 1
  call void @_ZN10primesieve6VectorIbSaIbEE6resizeEm(ptr noundef nonnull align 8 dereferenceable(24) %12, i64 noundef %14)
  %15 = getelementptr inbounds %"class.primesieve::SievingPrimes", ptr %8, i32 0, i32 7
  %16 = call noundef ptr @_ZN10primesieve6VectorIbSaIbEE5beginEv(ptr noundef nonnull align 8 dereferenceable(24) %15) #4
  %17 = getelementptr inbounds %"class.primesieve::SievingPrimes", ptr %8, i32 0, i32 7
  %18 = call noundef ptr @_ZN10primesieve6VectorIbSaIbEE3endEv(ptr noundef nonnull align 8 dereferenceable(24) %17) #4
  call void @llvm.lifetime.start.p0(i64 1, ptr %4) #4
  store i8 1, ptr %4, align 1, !tbaa !21
  call void @_ZSt4fillIPbbEvT_S1_RKT0_(ptr noundef %16, ptr noundef %18, ptr noundef nonnull align 1 dereferenceable(1) %4)
  call void @llvm.lifetime.end.p0(i64 1, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  store i64 3, ptr %5, align 8, !tbaa !20
  br label %19

19:                                               ; preds = %52, %1
  %20 = load i64, ptr %5, align 8, !tbaa !20
  %21 = load i64, ptr %5, align 8, !tbaa !20
  %22 = mul i64 %20, %21
  %23 = load i64, ptr %3, align 8, !tbaa !20
  %24 = icmp ule i64 %22, %23
  br i1 %24, label %26, label %25

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

26:                                               ; preds = %19
  %27 = getelementptr inbounds %"class.primesieve::SievingPrimes", ptr %8, i32 0, i32 7
  %28 = load i64, ptr %5, align 8, !tbaa !20
  %29 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZN10primesieve6VectorIbSaIbEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %27, i64 noundef %28) #4
  %30 = load i8, ptr %29, align 1, !tbaa !21, !range !23, !noundef !24
  %31 = trunc i8 %30 to i1
  br i1 %31, label %32, label %51

32:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %33 = load i64, ptr %5, align 8, !tbaa !20
  %34 = load i64, ptr %5, align 8, !tbaa !20
  %35 = mul i64 %33, %34
  store i64 %35, ptr %7, align 8, !tbaa !20
  br label %36

36:                                               ; preds = %45, %32
  %37 = load i64, ptr %7, align 8, !tbaa !20
  %38 = load i64, ptr %3, align 8, !tbaa !20
  %39 = icmp ule i64 %37, %38
  br i1 %39, label %41, label %40

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

41:                                               ; preds = %36
  %42 = getelementptr inbounds %"class.primesieve::SievingPrimes", ptr %8, i32 0, i32 7
  %43 = load i64, ptr %7, align 8, !tbaa !20
  %44 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZN10primesieve6VectorIbSaIbEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %42, i64 noundef %43) #4
  store i8 0, ptr %44, align 1, !tbaa !21
  br label %45

45:                                               ; preds = %41
  %46 = load i64, ptr %5, align 8, !tbaa !20
  %47 = mul i64 %46, 2
  %48 = load i64, ptr %7, align 8, !tbaa !20
  %49 = add i64 %48, %47
  store i64 %49, ptr %7, align 8, !tbaa !20
  br label %36, !llvm.loop !25

50:                                               ; preds = %40
  br label %51

51:                                               ; preds = %50, %26
  br label %52

52:                                               ; preds = %51
  %53 = load i64, ptr %5, align 8, !tbaa !20
  %54 = add i64 %53, 2
  store i64 %54, ptr %5, align 8, !tbaa !20
  br label %19, !llvm.loop !27

55:                                               ; preds = %25
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  ret void
}

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

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4fillIPbbEvT_S1_RKT0_(ptr noundef, ptr noundef, ptr noundef nonnull align 1 dereferenceable(1)) #1

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 1 dereferenceable(1) ptr @_ZN10primesieve6VectorIbSaIbEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #3 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 #3 = { 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 #4 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !11, i64 8}
!10 = !{!"_ZTSN10primesieve4EratE", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !12, i64 32, !11, i64 56, !11, i64 64, !13, i64 72, !16, i64 128, !19, i64 200}
!11 = !{!"long", !7, i64 0}
!12 = !{!"_ZTSN10primesieve6VectorIhSaIhEEE", !6, i64 0, !6, i64 8, !6, i64 16}
!13 = !{!"_ZTSN10primesieve9EratSmallE", !14, i64 0, !11, i64 16, !11, i64 24, !15, i64 32}
!14 = !{!"_ZTSN10primesieve5WheelILi30ELi8ELi6EXadsoKNS_9WheelInitEL_ZNS_11wheel30InitEEEEEE", !11, i64 8}
!15 = !{!"_ZTSN10primesieve6VectorINS_12SievingPrimeESaIS1_EEE", !6, i64 0, !6, i64 8, !6, i64 16}
!16 = !{!"_ZTSN10primesieve7EratBigE", !17, i64 0, !11, i64 16, !11, i64 24, !11, i64 32, !6, i64 40, !18, i64 48}
!17 = !{!"_ZTSN10primesieve5WheelILi210ELi48ELi10EXadsoKNS_9WheelInitEL_ZNS_12wheel210InitEEEEEE", !11, i64 8}
!18 = !{!"_ZTSN10primesieve6VectorIPNS_12SievingPrimeESaIS2_EEE", !6, i64 0, !6, i64 8, !6, i64 16}
!19 = !{!"_ZTSN10primesieve10EratMediumE", !14, i64 0, !11, i64 16, !6, i64 24, !18, i64 32, !18, i64 56}
!20 = !{!11, !11, i64 0}
!21 = !{!22, !22, i64 0}
!22 = !{!"bool", !7, i64 0}
!23 = !{i8 0, i8 2}
!24 = !{}
!25 = distinct !{!25, !26}
!26 = !{!"llvm.loop.mustprogress"}
!27 = distinct !{!27, !26}


; 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"

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

; Function Attrs: inlinehint mustprogress uwtable
declare hidden noundef i64 @_ZN12_GLOBAL__N_15isqrtImEET_S1_(i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN10primesieve13SievingPrimes9tinySieveEv(ptr noundef nonnull align 8 dereferenceable(1368) %0) local_unnamed_addr #2 align 2 {
  %2 = alloca i8, align 1
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  %4 = load i64, ptr %3, align 8, !tbaa !5
  %5 = tail call noundef i64 @_ZN12_GLOBAL__N_15isqrtImEET_S1_(i64 noundef %4)
  %6 = getelementptr inbounds i8, ptr %0, i64 1344
  %7 = add i64 %5, 1
  tail call void @_ZN10primesieve6VectorIbSaIbEE6resizeEm(ptr noundef nonnull align 8 dereferenceable(24) %6, i64 noundef %7)
  %8 = tail call noundef ptr @_ZN10primesieve6VectorIbSaIbEE5beginEv(ptr noundef nonnull align 8 dereferenceable(24) %6) #4
  %9 = tail call noundef ptr @_ZN10primesieve6VectorIbSaIbEE3endEv(ptr noundef nonnull align 8 dereferenceable(24) %6) #4
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %2) #4
  store i8 1, ptr %2, align 1, !tbaa !19
  call void @_ZSt4fillIPbbEvT_S1_RKT0_(ptr noundef %8, ptr noundef %9, ptr noundef nonnull align 1 dereferenceable(1) %2)
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %2) #4
  %.not19 = icmp ult i64 %5, 9
  br i1 %.not19, label %._crit_edge, label %.lr.ph22

._crit_edge:                                      ; preds = %.loopexit, %1
  ret void

.lr.ph22:                                         ; preds = %1, %.loopexit
  %10 = phi i64 [ %19, %.loopexit ], [ 9, %1 ]
  %.01320 = phi i64 [ %18, %.loopexit ], [ 3, %1 ]
  %11 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZN10primesieve6VectorIbSaIbEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %6, i64 noundef %.01320) #4
  %12 = load i8, ptr %11, align 1, !tbaa !19, !range !21, !noundef !22
  %13 = trunc nuw i8 %12 to i1
  %.not1617 = icmp ule i64 %10, %5
  %or.cond.not = and i1 %.not1617, %13
  br i1 %or.cond.not, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %.lr.ph22
  %14 = shl i64 %.01320, 1
  br label %15

15:                                               ; preds = %.lr.ph, %15
  %.018 = phi i64 [ %10, %.lr.ph ], [ %17, %15 ]
  %16 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZN10primesieve6VectorIbSaIbEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %6, i64 noundef %.018) #4
  store i8 0, ptr %16, align 1, !tbaa !19
  %17 = add i64 %.018, %14
  %.not16 = icmp ugt i64 %17, %5
  br i1 %.not16, label %.loopexit, label %15, !llvm.loop !23

.loopexit:                                        ; preds = %15, %.lr.ph22
  %18 = add i64 %.01320, 2
  %19 = mul i64 %18, %18
  %.not = icmp ugt i64 %19, %5
  br i1 %.not, label %._crit_edge, label %.lr.ph22, !llvm.loop !25
}

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN10primesieve6VectorIbSaIbEE6resizeEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #2 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4fillIPbbEvT_S1_RKT0_(ptr noundef, ptr noundef, ptr noundef nonnull align 1 dereferenceable(1)) local_unnamed_addr #1

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 1 dereferenceable(1) ptr @_ZN10primesieve6VectorIbSaIbEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #3 align 2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 #3 = { 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 #4 = { 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, !7, i64 8}
!6 = !{!"_ZTSN10primesieve4EratE", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !10, i64 32, !7, i64 56, !7, i64 64, !12, i64 72, !15, i64 128, !18, i64 200}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTSN10primesieve6VectorIhSaIhEEE", !11, i64 0, !11, i64 8, !11, i64 16}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!"_ZTSN10primesieve9EratSmallE", !13, i64 0, !7, i64 16, !7, i64 24, !14, i64 32}
!13 = !{!"_ZTSN10primesieve5WheelILi30ELi8ELi6EXadsoKNS_9WheelInitEL_ZNS_11wheel30InitEEEEEE", !7, i64 8}
!14 = !{!"_ZTSN10primesieve6VectorINS_12SievingPrimeESaIS1_EEE", !11, i64 0, !11, i64 8, !11, i64 16}
!15 = !{!"_ZTSN10primesieve7EratBigE", !16, i64 0, !7, i64 16, !7, i64 24, !7, i64 32, !11, i64 40, !17, i64 48}
!16 = !{!"_ZTSN10primesieve5WheelILi210ELi48ELi10EXadsoKNS_9WheelInitEL_ZNS_12wheel210InitEEEEEE", !7, i64 8}
!17 = !{!"_ZTSN10primesieve6VectorIPNS_12SievingPrimeESaIS2_EEE", !11, i64 0, !11, i64 8, !11, i64 16}
!18 = !{!"_ZTSN10primesieve10EratMediumE", !13, i64 0, !7, i64 16, !11, i64 24, !17, i64 32, !17, i64 56}
!19 = !{!20, !20, i64 0}
!20 = !{!"bool", !8, i64 0}
!21 = !{i8 0, i8 2}
!22 = !{}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}
!25 = distinct !{!25, !24}


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