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

; 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::SievingPrimes" = type { %"class.primesieve::Erat", i64, i64, i64, i64, i64, %"class.primesieve::Array", %"class.primesieve::Vector.3" }
%"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::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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; 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) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN10primesieve13SievingPrimes12sieveSegmentEv(ptr noundef nonnull align 8 dereferenceable(1368) %0) #2 align 2 {
  %2 = alloca i1, align 1
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %6 = load ptr, ptr %3, align 8
  %7 = call noundef zeroext i1 @_ZNK10primesieve4Erat14hasNextSegmentEv(ptr noundef nonnull align 8 dereferenceable(280) %6)
  br i1 %7, label %8, label %38

8:                                                ; preds = %1
  %9 = getelementptr inbounds %"class.primesieve::SievingPrimes", ptr %6, i32 0, i32 5
  store i64 0, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  %10 = getelementptr inbounds %"class.primesieve::Erat", ptr %6, i32 0, i32 3
  %11 = load i64, ptr %10, align 8, !tbaa !23
  store i64 %11, ptr %4, align 8, !tbaa !24
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  %12 = getelementptr inbounds %"class.primesieve::SievingPrimes", ptr %6, i32 0, i32 4
  store ptr %12, ptr %5, align 8, !tbaa !5
  br label %13

13:                                               ; preds = %33, %8
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = load i64, ptr %14, align 8, !tbaa !24
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = load i64, ptr %16, align 8, !tbaa !24
  %18 = mul i64 %15, %17
  %19 = load i64, ptr %4, align 8, !tbaa !24
  %20 = icmp ule i64 %18, %19
  br i1 %20, label %22, label %21

21:                                               ; preds = %13
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  br label %37

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

29:                                               ; preds = %22
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = load i64, ptr %30, align 8, !tbaa !24
  call void @_ZN10primesieve4Erat15addSievingPrimeEm(ptr noundef nonnull align 8 dereferenceable(280) %6, i64 noundef %31)
  br label %32

32:                                               ; preds = %29, %22
  br label %33

33:                                               ; preds = %32
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = load i64, ptr %34, align 8, !tbaa !24
  %36 = add i64 %35, 2
  store i64 %36, ptr %34, align 8, !tbaa !24
  br label %13, !llvm.loop !29

37:                                               ; preds = %21
  call void @_ZN10primesieve4Erat12sieveSegmentEv(ptr noundef nonnull align 8 dereferenceable(280) %6)
  store i1 true, ptr %2, align 1
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  br label %43

38:                                               ; preds = %1
  %39 = getelementptr inbounds %"class.primesieve::SievingPrimes", ptr %6, i32 0, i32 1
  store i64 0, ptr %39, align 8, !tbaa !31
  %40 = getelementptr inbounds %"class.primesieve::SievingPrimes", ptr %6, i32 0, i32 2
  store i64 1, ptr %40, align 8, !tbaa !32
  %41 = getelementptr inbounds %"class.primesieve::SievingPrimes", ptr %6, i32 0, i32 6
  %42 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZN10primesieve5ArrayImLm128EEixEm(ptr noundef nonnull align 8 dereferenceable(1024) %41, i64 noundef 0) #5
  store i64 -1, ptr %42, align 8, !tbaa !24
  store i1 false, ptr %2, align 1
  br label %43

43:                                               ; preds = %38, %37
  %44 = load i1, ptr %2, align 1
  ret i1 %44
}

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

declare noundef zeroext i1 @_ZNK10primesieve4Erat14hasNextSegmentEv(ptr noundef nonnull align 8 dereferenceable(280)) #3

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN10primesieve4Erat15addSievingPrimeEm(ptr noundef nonnull align 8 dereferenceable(280), i64 noundef) #4 align 2

declare void @_ZN10primesieve4Erat12sieveSegmentEv(ptr noundef nonnull align 8 dereferenceable(280)) #3

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


; 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 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 #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN10primesieve13SievingPrimes12sieveSegmentEv(ptr noundef nonnull align 8 dereferenceable(1368) %0) local_unnamed_addr #1 align 2 {
  %2 = tail call noundef zeroext i1 @_ZNK10primesieve4Erat14hasNextSegmentEv(ptr noundef nonnull align 8 dereferenceable(280) %0)
  br i1 %2, label %3, label %22

3:                                                ; preds = %1
  %4 = getelementptr inbounds i8, ptr %0, i64 312
  store i64 0, ptr %4, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 24
  %6 = load i64, ptr %5, align 8, !tbaa !22
  %7 = getelementptr inbounds i8, ptr %0, i64 304
  %8 = load i64, ptr %7, align 8, !tbaa !23
  %9 = mul i64 %8, %8
  %.not7 = icmp ugt i64 %9, %6
  br i1 %.not7, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %3
  %10 = getelementptr inbounds i8, ptr %0, i64 1344
  br label %11

._crit_edge:                                      ; preds = %18, %3
  tail call void @_ZN10primesieve4Erat12sieveSegmentEv(ptr noundef nonnull align 8 dereferenceable(280) %0)
  br label %27

11:                                               ; preds = %.lr.ph, %18
  %12 = phi i64 [ %8, %.lr.ph ], [ %20, %18 ]
  %13 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZN10primesieve6VectorIbSaIbEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %10, i64 noundef %12) #4
  %14 = load i8, ptr %13, align 1, !tbaa !24, !range !26, !noundef !27
  %15 = trunc nuw i8 %14 to i1
  br i1 %15, label %16, label %18

16:                                               ; preds = %11
  %17 = load i64, ptr %7, align 8, !tbaa !23
  tail call void @_ZN10primesieve4Erat15addSievingPrimeEm(ptr noundef nonnull align 8 dereferenceable(280) %0, i64 noundef %17)
  br label %18

18:                                               ; preds = %11, %16
  %19 = load i64, ptr %7, align 8, !tbaa !23
  %20 = add i64 %19, 2
  store i64 %20, ptr %7, align 8, !tbaa !23
  %21 = mul i64 %20, %20
  %.not = icmp ugt i64 %21, %6
  br i1 %.not, label %._crit_edge, label %11, !llvm.loop !28

22:                                               ; preds = %1
  %23 = getelementptr inbounds i8, ptr %0, i64 280
  store i64 0, ptr %23, align 8, !tbaa !30
  %24 = getelementptr inbounds i8, ptr %0, i64 288
  store i64 1, ptr %24, align 8, !tbaa !31
  %25 = getelementptr inbounds i8, ptr %0, i64 320
  %26 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZN10primesieve5ArrayImLm128EEixEm(ptr noundef nonnull align 8 dereferenceable(1024) %25, i64 noundef 0) #4
  store i64 -1, ptr %26, align 8, !tbaa !23
  br label %27

27:                                               ; preds = %22, %._crit_edge
  ret i1 %2
}

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

declare noundef zeroext i1 @_ZNK10primesieve4Erat14hasNextSegmentEv(ptr noundef nonnull align 8 dereferenceable(280)) local_unnamed_addr #2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN10primesieve4Erat15addSievingPrimeEm(ptr noundef nonnull align 8 dereferenceable(280), i64 noundef) local_unnamed_addr #3 align 2

declare void @_ZN10primesieve4Erat12sieveSegmentEv(ptr noundef nonnull align 8 dereferenceable(280)) local_unnamed_addr #2

attributes #0 = { 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 #1 = { 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 = { "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 = { 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, !8, i64 312}
!6 = !{!"_ZTSN10primesieve13SievingPrimesE", !7, i64 0, !8, i64 280, !8, i64 288, !8, i64 296, !8, i64 304, !8, i64 312, !20, i64 320, !21, i64 1344}
!7 = !{!"_ZTSN10primesieve4EratE", !8, i64 0, !8, i64 8, !8, i64 16, !8, i64 24, !11, i64 32, !8, i64 56, !8, i64 64, !13, i64 72, !16, i64 128, !19, i64 200}
!8 = !{!"long", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"_ZTSN10primesieve6VectorIhSaIhEEE", !12, i64 0, !12, i64 8, !12, i64 16}
!12 = !{!"any pointer", !9, i64 0}
!13 = !{!"_ZTSN10primesieve9EratSmallE", !14, i64 0, !8, i64 16, !8, i64 24, !15, i64 32}
!14 = !{!"_ZTSN10primesieve5WheelILi30ELi8ELi6EXadsoKNS_9WheelInitEL_ZNS_11wheel30InitEEEEEE", !8, i64 8}
!15 = !{!"_ZTSN10primesieve6VectorINS_12SievingPrimeESaIS1_EEE", !12, i64 0, !12, i64 8, !12, i64 16}
!16 = !{!"_ZTSN10primesieve7EratBigE", !17, i64 0, !8, i64 16, !8, i64 24, !8, i64 32, !12, i64 40, !18, i64 48}
!17 = !{!"_ZTSN10primesieve5WheelILi210ELi48ELi10EXadsoKNS_9WheelInitEL_ZNS_12wheel210InitEEEEEE", !8, i64 8}
!18 = !{!"_ZTSN10primesieve6VectorIPNS_12SievingPrimeESaIS2_EEE", !12, i64 0, !12, i64 8, !12, i64 16}
!19 = !{!"_ZTSN10primesieve10EratMediumE", !14, i64 0, !8, i64 16, !12, i64 24, !18, i64 32, !18, i64 56}
!20 = !{!"_ZTSN10primesieve5ArrayImLm128EEE", !9, i64 0}
!21 = !{!"_ZTSN10primesieve6VectorIbSaIbEEE", !12, i64 0, !12, i64 8, !12, i64 16}
!22 = !{!7, !8, i64 24}
!23 = !{!8, !8, i64 0}
!24 = !{!25, !25, i64 0}
!25 = !{!"bool", !9, i64 0}
!26 = !{i8 0, i8 2}
!27 = !{}
!28 = distinct !{!28, !29}
!29 = !{!"llvm.loop.mustprogress"}
!30 = !{!6, !8, i64 280}
!31 = !{!6, !8, i64 288}


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