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

; 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::Array.3" = type { [37 x i8] }
%"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" }

@_ZN12_GLOBAL__N_111unsetLargerE = external hidden constant %"class.primesieve::Array.3", align 1

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

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

; 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 @_ZN10primesieve6VectorIhSaIhEE6resizeEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #2 align 2

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN10primesieve4Erat8preSieveEv(ptr noundef nonnull align 8 dereferenceable(280)) #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN10primesieve4Erat8crossOffEv(ptr noundef nonnull align 8 dereferenceable(280)) #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN10primesieve4Erat16sieveLastSegmentEv(ptr noundef nonnull align 8 dereferenceable(280) %0) #2 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, 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) #3
  %8 = getelementptr inbounds %"class.primesieve::Erat", ptr %7, i32 0, i32 1
  %9 = load i64, ptr %8, align 8, !tbaa !9
  %10 = call noundef i64 @_ZN10primesieve4Erat13byteRemainderEm(i64 noundef %9)
  store i64 %10, ptr %3, align 8, !tbaa !20
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %11 = getelementptr inbounds %"class.primesieve::Erat", ptr %7, i32 0, i32 1
  %12 = load i64, ptr %11, align 8, !tbaa !9
  %13 = load i64, ptr %3, align 8, !tbaa !20
  %14 = sub i64 %12, %13
  %15 = getelementptr inbounds %"class.primesieve::Erat", ptr %7, i32 0, i32 2
  %16 = load i64, ptr %15, align 8, !tbaa !21
  %17 = sub i64 %14, %16
  store i64 %17, ptr %4, align 8, !tbaa !20
  %18 = getelementptr inbounds %"class.primesieve::Erat", ptr %7, i32 0, i32 4
  %19 = load i64, ptr %4, align 8, !tbaa !20
  %20 = udiv i64 %19, 30
  %21 = add i64 %20, 1
  call void @_ZN10primesieve6VectorIhSaIhEE6resizeEm(ptr noundef nonnull align 8 dereferenceable(24) %18, i64 noundef %21)
  call void @_ZN10primesieve4Erat8preSieveEv(ptr noundef nonnull align 8 dereferenceable(280) %7)
  call void @_ZN10primesieve4Erat8crossOffEv(ptr noundef nonnull align 8 dereferenceable(280) %7)
  %22 = load i64, ptr %3, align 8, !tbaa !20
  %23 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNK10primesieve5ArrayIhLm37EEixEm(ptr noundef nonnull align 1 dereferenceable(37) @_ZN12_GLOBAL__N_111unsetLargerE, i64 noundef %22) #3
  %24 = load i8, ptr %23, align 1, !tbaa !22
  %25 = zext i8 %24 to i32
  %26 = getelementptr inbounds %"class.primesieve::Erat", ptr %7, i32 0, i32 4
  %27 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZN10primesieve6VectorIhSaIhEE4backEv(ptr noundef nonnull align 8 dereferenceable(24) %26) #3
  %28 = load i8, ptr %27, align 1, !tbaa !22
  %29 = zext i8 %28 to i32
  %30 = and i32 %29, %25
  %31 = trunc i32 %30 to i8
  store i8 %31, ptr %27, align 1, !tbaa !22
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %32 = getelementptr inbounds %"class.primesieve::Erat", ptr %7, i32 0, i32 4
  %33 = call noundef ptr @_ZN10primesieve6VectorIhSaIhEE4dataEv(ptr noundef nonnull align 8 dereferenceable(24) %32) #3
  store ptr %33, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %34 = getelementptr inbounds %"class.primesieve::Erat", ptr %7, i32 0, i32 4
  %35 = call noundef i64 @_ZNK10primesieve6VectorIhSaIhEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %34) #3
  store i64 %35, ptr %6, align 8, !tbaa !20
  br label %36

36:                                               ; preds = %44, %1
  %37 = load i64, ptr %6, align 8, !tbaa !20
  %38 = urem i64 %37, 8
  %39 = icmp ne i64 %38, 0
  br i1 %39, label %40, label %47

40:                                               ; preds = %36
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = load i64, ptr %6, align 8, !tbaa !20
  %43 = getelementptr inbounds i8, ptr %41, i64 %42
  store i8 0, ptr %43, align 1, !tbaa !22
  br label %44

44:                                               ; preds = %40
  %45 = load i64, ptr %6, align 8, !tbaa !20
  %46 = add i64 %45, 1
  store i64 %46, ptr %6, align 8, !tbaa !20
  br label %36, !llvm.loop !23

47:                                               ; preds = %36
  %48 = getelementptr inbounds %"class.primesieve::Erat", ptr %7, i32 0, i32 1
  %49 = load i64, ptr %48, align 8, !tbaa !9
  %50 = getelementptr inbounds %"class.primesieve::Erat", ptr %7, i32 0, i32 2
  store i64 %49, ptr %50, align 8, !tbaa !21
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret void
}

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN10primesieve6VectorIhSaIhEE4dataEv(ptr noundef nonnull align 8 dereferenceable(24)) #1 align 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 = { 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, !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 = !{!10, !11, i64 16}
!22 = !{!7, !7, i64 0}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}


; 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.primesieve::Array.3" = type { [37 x i8] }

@_ZN12_GLOBAL__N_111unsetLargerE = external hidden constant %"class.primesieve::Array.3", align 1

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

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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN10primesieve4Erat8preSieveEv(ptr noundef nonnull align 8 dereferenceable(280)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN10primesieve4Erat8crossOffEv(ptr noundef nonnull align 8 dereferenceable(280)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN10primesieve4Erat16sieveLastSegmentEv(ptr noundef nonnull align 8 dereferenceable(280) %0) local_unnamed_addr #1 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 8
  %3 = load i64, ptr %2, align 8, !tbaa !5
  %4 = tail call noundef i64 @_ZN10primesieve4Erat13byteRemainderEm(i64 noundef %3)
  %5 = load i64, ptr %2, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 16
  %7 = load i64, ptr %6, align 8, !tbaa !19
  %8 = add i64 %4, %7
  %9 = sub i64 %5, %8
  %10 = getelementptr inbounds i8, ptr %0, i64 32
  %11 = udiv i64 %9, 30
  %12 = add nuw nsw i64 %11, 1
  tail call void @_ZN10primesieve6VectorIhSaIhEE6resizeEm(ptr noundef nonnull align 8 dereferenceable(24) %10, i64 noundef %12)
  tail call void @_ZN10primesieve4Erat8preSieveEv(ptr noundef nonnull align 8 dereferenceable(280) %0)
  tail call void @_ZN10primesieve4Erat8crossOffEv(ptr noundef nonnull align 8 dereferenceable(280) %0)
  %13 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNK10primesieve5ArrayIhLm37EEixEm(ptr noundef nonnull align 1 dereferenceable(37) @_ZN12_GLOBAL__N_111unsetLargerE, i64 noundef %4) #3
  %14 = load i8, ptr %13, align 1, !tbaa !20
  %15 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZN10primesieve6VectorIhSaIhEE4backEv(ptr noundef nonnull align 8 dereferenceable(24) %10) #3
  %16 = load i8, ptr %15, align 1, !tbaa !20
  %17 = and i8 %16, %14
  store i8 %17, ptr %15, align 1, !tbaa !20
  %18 = tail call noundef ptr @_ZN10primesieve6VectorIhSaIhEE4dataEv(ptr noundef nonnull align 8 dereferenceable(24) %10) #3
  %19 = tail call noundef i64 @_ZNK10primesieve6VectorIhSaIhEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %10) #3
  %20 = and i64 %19, 7
  %.not9 = icmp eq i64 %20, 0
  br i1 %.not9, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %1
  %scevgep = getelementptr i8, ptr %18, i64 %19
  %21 = and i64 %19, 7
  %22 = sub nuw nsw i64 8, %21
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 1 dereferenceable(1) %scevgep, i8 0, i64 %22, i1 false), !tbaa !20
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph.preheader, %1
  %23 = load i64, ptr %2, align 8, !tbaa !5
  store i64 %23, ptr %6, align 8, !tbaa !19
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 1 dereferenceable(1) ptr @_ZNK10primesieve5ArrayIhLm37EEixEm(ptr noundef nonnull align 1 dereferenceable(37), i64 noundef) local_unnamed_addr #0 align 2

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

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 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 = !{!6, !7, i64 16}
!20 = !{!8, !8, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopIdiomRecognizePass,LoopRotatePass,LoopSimplifyPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass