; LLVM IR from kimwalisch/primesieve :: src/PrimeSieveClass.ll (ZN10primesieve10PrimeSieve18processSmallPrimesEv)

; 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.primesieve::Array.0" = type { [8 x %"struct.(anonymous namespace)::SmallPrime"] }
%"struct.(anonymous namespace)::SmallPrime" = type { i64, i64, i32, ptr }
%"class.primesieve::PrimeSieve" = type { ptr, i64, i64, double, double, %"class.primesieve::Array", i64, i64, i32, i32, ptr }
%"class.primesieve::Array" = type { [6 x i64] }

@_ZSt4cout = external global %"class.std::basic_ostream", align 8
@_ZN12_GLOBAL__N_111smallPrimesE = external hidden constant %"class.primesieve::Array.0", align 8

; 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 zeroext i1 @_ZNK10primesieve10PrimeSieve7isCountEi(ptr noundef nonnull align 8 dereferenceable(120), i32 noundef) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK10primesieve10PrimeSieve7isPrintEi(ptr noundef nonnull align 8 dereferenceable(120), i32 noundef) #1 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_c(ptr noundef nonnull align 8 dereferenceable(8), i8 noundef signext) #2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN10primesieve10PrimeSieve18processSmallPrimesEv(ptr noundef nonnull align 8 dereferenceable(120) %0) #3 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %7 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  store ptr @_ZN12_GLOBAL__N_111smallPrimesE, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %8 = call noundef ptr @_ZNK10primesieve5ArrayIN12_GLOBAL__N_110SmallPrimeELm8EE5beginEv(ptr noundef nonnull align 8 dereferenceable(256) @_ZN12_GLOBAL__N_111smallPrimesE) #4
  store ptr %8, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %9 = call noundef ptr @_ZNK10primesieve5ArrayIN12_GLOBAL__N_110SmallPrimeELm8EE3endEv(ptr noundef nonnull align 8 dereferenceable(256) @_ZN12_GLOBAL__N_111smallPrimesE) #4
  store ptr %9, ptr %5, align 8, !tbaa !5
  br label %10

10:                                               ; preds = %57, %1
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = icmp ne ptr %11, %12
  br i1 %13, label %15, label %14

14:                                               ; preds = %10
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  br label %60

15:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %16, ptr %6, align 8, !tbaa !5
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = getelementptr inbounds %"struct.(anonymous namespace)::SmallPrime", ptr %17, i32 0, i32 0
  %19 = load i64, ptr %18, align 8, !tbaa !9
  %20 = getelementptr inbounds %"class.primesieve::PrimeSieve", ptr %7, i32 0, i32 1
  %21 = load i64, ptr %20, align 8, !tbaa !13
  %22 = icmp uge i64 %19, %21
  br i1 %22, label %23, label %56

23:                                               ; preds = %15
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = getelementptr inbounds %"struct.(anonymous namespace)::SmallPrime", ptr %24, i32 0, i32 1
  %26 = load i64, ptr %25, align 8, !tbaa !17
  %27 = getelementptr inbounds %"class.primesieve::PrimeSieve", ptr %7, i32 0, i32 2
  %28 = load i64, ptr %27, align 8, !tbaa !18
  %29 = icmp ule i64 %26, %28
  br i1 %29, label %30, label %56

30:                                               ; preds = %23
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = getelementptr inbounds %"struct.(anonymous namespace)::SmallPrime", ptr %31, i32 0, i32 2
  %33 = load i32, ptr %32, align 8, !tbaa !19
  %34 = call noundef zeroext i1 @_ZNK10primesieve10PrimeSieve7isCountEi(ptr noundef nonnull align 8 dereferenceable(120) %7, i32 noundef %33)
  br i1 %34, label %35, label %44

35:                                               ; preds = %30
  %36 = getelementptr inbounds %"class.primesieve::PrimeSieve", ptr %7, i32 0, i32 5
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = getelementptr inbounds %"struct.(anonymous namespace)::SmallPrime", ptr %37, i32 0, i32 2
  %39 = load i32, ptr %38, align 8, !tbaa !19
  %40 = sext i32 %39 to i64
  %41 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZN10primesieve5ArrayImLm6EEixEm(ptr noundef nonnull align 8 dereferenceable(48) %36, i64 noundef %40) #4
  %42 = load i64, ptr %41, align 8, !tbaa !20
  %43 = add i64 %42, 1
  store i64 %43, ptr %41, align 8, !tbaa !20
  br label %44

44:                                               ; preds = %35, %30
  %45 = load ptr, ptr %6, align 8, !tbaa !5
  %46 = getelementptr inbounds %"struct.(anonymous namespace)::SmallPrime", ptr %45, i32 0, i32 2
  %47 = load i32, ptr %46, align 8, !tbaa !19
  %48 = call noundef zeroext i1 @_ZNK10primesieve10PrimeSieve7isPrintEi(ptr noundef nonnull align 8 dereferenceable(120) %7, i32 noundef %47)
  br i1 %48, label %49, label %55

49:                                               ; preds = %44
  %50 = load ptr, ptr %6, align 8, !tbaa !5
  %51 = getelementptr inbounds %"struct.(anonymous namespace)::SmallPrime", ptr %50, i32 0, i32 3
  %52 = load ptr, ptr %51, align 8, !tbaa !21
  %53 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, ptr noundef %52)
  %54 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_c(ptr noundef nonnull align 8 dereferenceable(8) %53, i8 noundef signext 10)
  br label %55

55:                                               ; preds = %49, %44
  br label %56

56:                                               ; preds = %55, %23, %15
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %57

57:                                               ; preds = %56
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  %59 = getelementptr inbounds %"struct.(anonymous namespace)::SmallPrime", ptr %58, i32 1
  store ptr %59, ptr %4, align 8, !tbaa !5
  br label %10

60:                                               ; preds = %14
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef ptr @_ZNK10primesieve5ArrayIN12_GLOBAL__N_110SmallPrimeELm8EE5beginEv(ptr noundef nonnull align 8 dereferenceable(256)) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef ptr @_ZNK10primesieve5ArrayIN12_GLOBAL__N_110SmallPrimeELm8EE3endEv(ptr noundef nonnull align 8 dereferenceable(256)) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZN10primesieve5ArrayImLm6EEixEm(ptr noundef nonnull align 8 dereferenceable(48), i64 noundef) #1 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) #2

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 = { 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 #3 = { 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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"_ZTSN12_GLOBAL__N_110SmallPrimeE", !11, i64 0, !11, i64 8, !12, i64 16, !6, i64 24}
!11 = !{!"long", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !11, i64 8}
!14 = !{!"_ZTSN10primesieve10PrimeSieveE", !11, i64 8, !11, i64 16, !15, i64 24, !15, i64 32, !16, i64 40, !11, i64 88, !11, i64 96, !12, i64 104, !12, i64 108, !6, i64 112}
!15 = !{!"double", !7, i64 0}
!16 = !{!"_ZTSN10primesieve5ArrayImLm6EEE", !7, i64 0}
!17 = !{!10, !11, i64 8}
!18 = !{!14, !11, i64 16}
!19 = !{!10, !12, i64 16}
!20 = !{!11, !11, i64 0}
!21 = !{!10, !6, i64 24}


; 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.primesieve::Array.0" = type { [8 x %"struct.(anonymous namespace)::SmallPrime"] }
%"struct.(anonymous namespace)::SmallPrime" = type { i64, i64, i32, ptr }

@_ZSt4cout = external global %"class.std::basic_ostream", align 8
@_ZN12_GLOBAL__N_111smallPrimesE = external hidden constant %"class.primesieve::Array.0", align 8

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK10primesieve10PrimeSieve7isCountEi(ptr noundef nonnull align 8 dereferenceable(120), i32 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK10primesieve10PrimeSieve7isPrintEi(ptr noundef nonnull align 8 dereferenceable(120), i32 noundef) local_unnamed_addr #0 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_c(ptr noundef nonnull align 8 dereferenceable(8), i8 noundef signext) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN10primesieve10PrimeSieve18processSmallPrimesEv(ptr noundef nonnull align 8 dereferenceable(120) %0) local_unnamed_addr #2 align 2 {
  %2 = tail call noundef ptr @_ZNK10primesieve5ArrayIN12_GLOBAL__N_110SmallPrimeELm8EE5beginEv(ptr noundef nonnull align 8 dereferenceable(256) @_ZN12_GLOBAL__N_111smallPrimesE) #3
  %3 = tail call noundef ptr @_ZNK10primesieve5ArrayIN12_GLOBAL__N_110SmallPrimeELm8EE3endEv(ptr noundef nonnull align 8 dereferenceable(256) @_ZN12_GLOBAL__N_111smallPrimesE) #3
  %.not13 = icmp eq ptr %2, %3
  br i1 %.not13, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = getelementptr inbounds i8, ptr %0, i64 16
  %6 = getelementptr inbounds i8, ptr %0, i64 40
  br label %7

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

7:                                                ; preds = %.lr.ph, %32
  %.014 = phi ptr [ %2, %.lr.ph ], [ %33, %32 ]
  %8 = load i64, ptr %.014, align 8, !tbaa !5
  %9 = load i64, ptr %4, align 8, !tbaa !12
  %.not11 = icmp ult i64 %8, %9
  br i1 %.not11, label %32, label %10

10:                                               ; preds = %7
  %11 = getelementptr inbounds i8, ptr %.014, i64 8
  %12 = load i64, ptr %11, align 8, !tbaa !16
  %13 = load i64, ptr %5, align 8, !tbaa !17
  %.not12 = icmp ugt i64 %12, %13
  br i1 %.not12, label %32, label %14

14:                                               ; preds = %10
  %15 = getelementptr inbounds i8, ptr %.014, i64 16
  %16 = load i32, ptr %15, align 8, !tbaa !18
  %17 = tail call noundef zeroext i1 @_ZNK10primesieve10PrimeSieve7isCountEi(ptr noundef nonnull align 8 dereferenceable(120) %0, i32 noundef %16)
  br i1 %17, label %18, label %24

18:                                               ; preds = %14
  %19 = load i32, ptr %15, align 8, !tbaa !18
  %20 = sext i32 %19 to i64
  %21 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZN10primesieve5ArrayImLm6EEixEm(ptr noundef nonnull align 8 dereferenceable(48) %6, i64 noundef %20) #3
  %22 = load i64, ptr %21, align 8, !tbaa !19
  %23 = add i64 %22, 1
  store i64 %23, ptr %21, align 8, !tbaa !19
  br label %24

24:                                               ; preds = %18, %14
  %25 = load i32, ptr %15, align 8, !tbaa !18
  %26 = tail call noundef zeroext i1 @_ZNK10primesieve10PrimeSieve7isPrintEi(ptr noundef nonnull align 8 dereferenceable(120) %0, i32 noundef %25)
  br i1 %26, label %27, label %32

27:                                               ; preds = %24
  %28 = getelementptr inbounds i8, ptr %.014, i64 24
  %29 = load ptr, ptr %28, align 8, !tbaa !20
  %30 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, ptr noundef %29)
  %31 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_c(ptr noundef nonnull align 8 dereferenceable(8) %30, i8 noundef signext 10)
  br label %32

32:                                               ; preds = %24, %27, %10, %7
  %33 = getelementptr inbounds i8, ptr %.014, i64 32
  %.not = icmp eq ptr %33, %3
  br i1 %.not, label %._crit_edge, label %7
}

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef ptr @_ZNK10primesieve5ArrayIN12_GLOBAL__N_110SmallPrimeELm8EE5beginEv(ptr noundef nonnull align 8 dereferenceable(256)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef ptr @_ZNK10primesieve5ArrayIN12_GLOBAL__N_110SmallPrimeELm8EE3endEv(ptr noundef nonnull align 8 dereferenceable(256)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZN10primesieve5ArrayImLm6EEixEm(ptr noundef nonnull align 8 dereferenceable(48), 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 #1

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 = { 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 = { 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 0}
!6 = !{!"_ZTSN12_GLOBAL__N_110SmallPrimeE", !7, i64 0, !7, i64 8, !10, i64 16, !11, i64 24}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!13, !7, i64 8}
!13 = !{!"_ZTSN10primesieve10PrimeSieveE", !7, i64 8, !7, i64 16, !14, i64 24, !14, i64 32, !15, i64 40, !7, i64 88, !7, i64 96, !10, i64 104, !10, i64 108, !11, i64 112}
!14 = !{!"double", !8, i64 0}
!15 = !{!"_ZTSN10primesieve5ArrayImLm6EEE", !8, i64 0}
!16 = !{!6, !7, i64 8}
!17 = !{!13, !7, i64 16}
!18 = !{!6, !10, i64 16}
!19 = !{!7, !7, i64 0}
!20 = !{!6, !11, i64 24}


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