; LLVM IR from kimwalisch/primesieve :: src/Erat.ll (ZN10primesieve4Erat4initEmmmRNS_10MemoryPoolE)

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN10primesieve4Erat4initEmmmRNS_10MemoryPoolE(ptr noundef nonnull align 8 dereferenceable(280) %0, i64 noundef %1, i64 noundef %2, i64 noundef %3, ptr noundef nonnull align 1 %4) #0 align 2 {
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i64 %1, ptr %7, align 8, !tbaa !9
  store i64 %2, ptr %8, align 8, !tbaa !9
  store i64 %3, ptr %9, align 8, !tbaa !9
  store ptr %4, ptr %10, align 8, !tbaa !5
  %11 = load ptr, ptr %6, align 8
  %12 = load i64, ptr %7, align 8, !tbaa !9
  %13 = load i64, ptr %8, align 8, !tbaa !9
  %14 = icmp ugt i64 %12, %13
  br i1 %14, label %19, label %15

15:                                               ; preds = %5
  %16 = load i64, ptr %7, align 8, !tbaa !9
  %17 = call noundef i64 @_ZNSt14numeric_limitsImE3maxEv() #3
  %18 = icmp uge i64 %16, %17
  br label %19

19:                                               ; preds = %15, %5
  %20 = phi i1 [ true, %5 ], [ %18, %15 ]
  %21 = xor i1 %20, true
  %22 = xor i1 %21, true
  %23 = zext i1 %22 to i64
  %24 = call i64 @llvm.expect.i64(i64 %23, i64 0)
  %25 = icmp ne i64 %24, 0
  br i1 %25, label %26, label %27

26:                                               ; preds = %19
  br label %36

27:                                               ; preds = %19
  %28 = load i64, ptr %7, align 8, !tbaa !9
  %29 = getelementptr inbounds %"class.primesieve::Erat", ptr %11, i32 0, i32 0
  store i64 %28, ptr %29, align 8, !tbaa !11
  %30 = load i64, ptr %8, align 8, !tbaa !9
  %31 = getelementptr inbounds %"class.primesieve::Erat", ptr %11, i32 0, i32 1
  store i64 %30, ptr %31, align 8, !tbaa !21
  %32 = load i64, ptr %9, align 8, !tbaa !9
  %33 = shl i64 %32, 10
  store i64 %33, ptr %9, align 8, !tbaa !9
  %34 = load i64, ptr %9, align 8, !tbaa !9
  %35 = load ptr, ptr %10, align 8, !tbaa !5
  call void @_ZN10primesieve4Erat14initAlgorithmsEmRNS_10MemoryPoolE(ptr noundef nonnull align 8 dereferenceable(280) %11, i64 noundef %34, ptr noundef nonnull align 1 %35)
  br label %36

36:                                               ; preds = %27, %26
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNSt14numeric_limitsImE3maxEv() #1 align 2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(none)
declare i64 @llvm.expect.i64(i64, i64) #2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN10primesieve4Erat14initAlgorithmsEmRNS_10MemoryPoolE(ptr noundef nonnull align 8 dereferenceable(280), i64 noundef, ptr noundef nonnull align 1) #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(none) }
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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"_ZTSN10primesieve4EratE", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !13, i64 32, !10, i64 56, !10, i64 64, !14, i64 72, !17, i64 128, !20, i64 200}
!13 = !{!"_ZTSN10primesieve6VectorIhSaIhEEE", !6, i64 0, !6, i64 8, !6, i64 16}
!14 = !{!"_ZTSN10primesieve9EratSmallE", !15, i64 0, !10, i64 16, !10, i64 24, !16, i64 32}
!15 = !{!"_ZTSN10primesieve5WheelILi30ELi8ELi6EXadsoKNS_9WheelInitEL_ZNS_11wheel30InitEEEEEE", !10, i64 8}
!16 = !{!"_ZTSN10primesieve6VectorINS_12SievingPrimeESaIS1_EEE", !6, i64 0, !6, i64 8, !6, i64 16}
!17 = !{!"_ZTSN10primesieve7EratBigE", !18, i64 0, !10, i64 16, !10, i64 24, !10, i64 32, !6, i64 40, !19, i64 48}
!18 = !{!"_ZTSN10primesieve5WheelILi210ELi48ELi10EXadsoKNS_9WheelInitEL_ZNS_12wheel210InitEEEEEE", !10, i64 8}
!19 = !{!"_ZTSN10primesieve6VectorIPNS_12SievingPrimeESaIS2_EEE", !6, i64 0, !6, i64 8, !6, i64 16}
!20 = !{!"_ZTSN10primesieve10EratMediumE", !15, i64 0, !10, i64 16, !6, i64 24, !19, i64 32, !19, i64 56}
!21 = !{!12, !10, i64 8}


; 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 uwtable
define dso_local void @_ZN10primesieve4Erat4initEmmmRNS_10MemoryPoolE(ptr noundef nonnull align 8 dereferenceable(280) %0, i64 noundef %1, i64 noundef %2, i64 noundef %3, ptr noundef nonnull align 1 %4) local_unnamed_addr #0 align 2 {
  %6 = icmp ugt i64 %1, %2
  br i1 %6, label %.critedge, label %7, !prof !5

7:                                                ; preds = %5
  %8 = tail call noundef i64 @_ZNSt14numeric_limitsImE3maxEv() #2
  %.not = icmp ugt i64 %8, %1
  br i1 %.not, label %9, label %.critedge, !prof !6

9:                                                ; preds = %7
  store i64 %1, ptr %0, align 8, !tbaa !7
  %10 = getelementptr inbounds i8, ptr %0, i64 8
  store i64 %2, ptr %10, align 8, !tbaa !21
  %11 = shl i64 %3, 10
  tail call void @_ZN10primesieve4Erat14initAlgorithmsEmRNS_10MemoryPoolE(ptr noundef nonnull align 8 dereferenceable(280) %0, i64 noundef %11, ptr noundef nonnull align 1 %4)
  br label %.critedge

.critedge:                                        ; preds = %5, %7, %9
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNSt14numeric_limitsImE3maxEv() local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN10primesieve4Erat14initAlgorithmsEmRNS_10MemoryPoolE(ptr noundef nonnull align 8 dereferenceable(280), i64 noundef, ptr noundef nonnull align 1) 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 = { 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 = !{!"branch_weights", !"expected", i32 1, i32 2000}
!6 = !{!"branch_weights", !"expected", i32 2000, i32 1}
!7 = !{!8, !9, i64 0}
!8 = !{!"_ZTSN10primesieve4EratE", !9, i64 0, !9, i64 8, !9, i64 16, !9, i64 24, !12, i64 32, !9, i64 56, !9, i64 64, !14, i64 72, !17, i64 128, !20, i64 200}
!9 = !{!"long", !10, i64 0}
!10 = !{!"omnipotent char", !11, i64 0}
!11 = !{!"Simple C++ TBAA"}
!12 = !{!"_ZTSN10primesieve6VectorIhSaIhEEE", !13, i64 0, !13, i64 8, !13, i64 16}
!13 = !{!"any pointer", !10, i64 0}
!14 = !{!"_ZTSN10primesieve9EratSmallE", !15, i64 0, !9, i64 16, !9, i64 24, !16, i64 32}
!15 = !{!"_ZTSN10primesieve5WheelILi30ELi8ELi6EXadsoKNS_9WheelInitEL_ZNS_11wheel30InitEEEEEE", !9, i64 8}
!16 = !{!"_ZTSN10primesieve6VectorINS_12SievingPrimeESaIS1_EEE", !13, i64 0, !13, i64 8, !13, i64 16}
!17 = !{!"_ZTSN10primesieve7EratBigE", !18, i64 0, !9, i64 16, !9, i64 24, !9, i64 32, !13, i64 40, !19, i64 48}
!18 = !{!"_ZTSN10primesieve5WheelILi210ELi48ELi10EXadsoKNS_9WheelInitEL_ZNS_12wheel210InitEEEEEE", !9, i64 8}
!19 = !{!"_ZTSN10primesieve6VectorIPNS_12SievingPrimeESaIS2_EEE", !13, i64 0, !13, i64 8, !13, i64 16}
!20 = !{!"_ZTSN10primesieve10EratMediumE", !15, i64 0, !9, i64 16, !13, i64 24, !19, i64 32, !19, i64 56}
!21 = !{!8, !9, i64 8}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,LowerExpectIntrinsicPass,SROAPass,SimplifyCFGPass,TailCallElimPass