; LLVM IR from kimwalisch/primesieve :: src (iterator-c)

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

%struct.primesieve_iterator = type { i64, i64, i64, i64, ptr, ptr, i32 }
%"struct.primesieve::IteratorData" = type { i64, i64, i8, ptr, %"class.primesieve::Vector", [1720 x i8] }
%"class.primesieve::Vector" = type { ptr, ptr, ptr }

; Function Attrs: mustprogress uwtable
define dso_local void @primesieve_jump_to(ptr noundef %0, i64 noundef %1, i64 noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  store i64 %2, ptr %6, align 8, !tbaa !9
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.primesieve_iterator, ptr %8, i32 0, i32 0
  store i64 0, ptr %9, align 8, !tbaa !11
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.primesieve_iterator, ptr %10, i32 0, i32 1
  store i64 0, ptr %11, align 8, !tbaa !14
  %12 = load i64, ptr %5, align 8, !tbaa !9
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.primesieve_iterator, ptr %13, i32 0, i32 2
  store i64 %12, ptr %14, align 8, !tbaa !15
  %15 = load i64, ptr %6, align 8, !tbaa !9
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.primesieve_iterator, ptr %16, i32 0, i32 3
  store i64 %15, ptr %17, align 8, !tbaa !16
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.primesieve_iterator, ptr %18, i32 0, i32 4
  store ptr null, ptr %19, align 8, !tbaa !17
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.primesieve_iterator, ptr %20, i32 0, i32 5
  %22 = load ptr, ptr %21, align 8, !tbaa !18
  %23 = icmp ne ptr %22, null
  br i1 %23, label %24, label %36

24:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = call noundef nonnull align 8 dereferenceable(1776) ptr @_ZN12_GLOBAL__N_111getIterDataEP19primesieve_iterator(ptr noundef %25)
  store ptr %26, ptr %7, align 8, !tbaa !5
  %27 = load i64, ptr %5, align 8, !tbaa !9
  %28 = load ptr, ptr %7, align 8, !tbaa !5
  %29 = getelementptr inbounds %"struct.primesieve::IteratorData", ptr %28, i32 0, i32 0
  store i64 %27, ptr %29, align 8, !tbaa !19
  %30 = load ptr, ptr %7, align 8, !tbaa !5
  %31 = getelementptr inbounds %"struct.primesieve::IteratorData", ptr %30, i32 0, i32 1
  store i64 0, ptr %31, align 8, !tbaa !23
  %32 = load ptr, ptr %7, align 8, !tbaa !5
  %33 = getelementptr inbounds %"struct.primesieve::IteratorData", ptr %32, i32 0, i32 2
  store i8 1, ptr %33, align 8, !tbaa !24
  %34 = load ptr, ptr %7, align 8, !tbaa !5
  call void @_ZN10primesieve12IteratorData20deletePrimeGeneratorEv(ptr noundef nonnull align 8 dereferenceable(1776) %34)
  %35 = load ptr, ptr %7, align 8, !tbaa !5
  call void @_ZN10primesieve12IteratorData12deletePrimesEv(ptr noundef nonnull align 8 dereferenceable(1776) %35)
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  br label %36

36:                                               ; preds = %24, %3
  ret void
}

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

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

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

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

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

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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 = !{!"_ZTS19primesieve_iterator", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !6, i64 32, !6, i64 40, !13, i64 48}
!13 = !{!"int", !7, i64 0}
!14 = !{!12, !10, i64 8}
!15 = !{!12, !10, i64 16}
!16 = !{!12, !10, i64 24}
!17 = !{!12, !6, i64 32}
!18 = !{!12, !6, i64 40}
!19 = !{!20, !10, i64 0}
!20 = !{!"_ZTSN10primesieve12IteratorDataE", !10, i64 0, !10, i64 8, !21, i64 16, !6, i64 24, !22, i64 32, !7, i64 56}
!21 = !{!"bool", !7, i64 0}
!22 = !{!"_ZTSN10primesieve6VectorImSaImEEE", !6, i64 0, !6, i64 8, !6, i64 16}
!23 = !{!20, !10, i64 8}
!24 = !{!20, !21, i64 16}


; 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
define dso_local void @primesieve_jump_to(ptr noundef %0, i64 noundef %1, i64 noundef %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 16
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %0, i8 0, i64 16, i1 false)
  store i64 %1, ptr %4, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 24
  store i64 %2, ptr %5, align 8, !tbaa !12
  %6 = getelementptr inbounds i8, ptr %0, i64 32
  store ptr null, ptr %6, align 8, !tbaa !13
  %7 = getelementptr inbounds i8, ptr %0, i64 40
  %8 = load ptr, ptr %7, align 8, !tbaa !14
  %.not = icmp eq ptr %8, null
  br i1 %.not, label %13, label %9

9:                                                ; preds = %3
  %10 = tail call noundef nonnull align 8 dereferenceable(1776) ptr @_ZN12_GLOBAL__N_111getIterDataEP19primesieve_iterator(ptr noundef nonnull %0)
  store i64 %1, ptr %10, align 8, !tbaa !15
  %11 = getelementptr inbounds i8, ptr %10, i64 8
  store i64 0, ptr %11, align 8, !tbaa !19
  %12 = getelementptr inbounds i8, ptr %10, i64 16
  store i8 1, ptr %12, align 8, !tbaa !20
  tail call void @_ZN10primesieve12IteratorData20deletePrimeGeneratorEv(ptr noundef nonnull align 8 dereferenceable(1776) %10)
  tail call void @_ZN10primesieve12IteratorData12deletePrimesEv(ptr noundef nonnull align 8 dereferenceable(1776) %10)
  br label %13

13:                                               ; preds = %9, %3
  ret void
}

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN10primesieve12IteratorData12deletePrimesEv(ptr noundef nonnull align 8 dereferenceable(1776)) 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) #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 = { nocallback nofree nounwind willreturn memory(argmem: write) }

!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 16}
!6 = !{!"_ZTS19primesieve_iterator", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !10, i64 32, !10, i64 40, !11, i64 48}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!6, !7, i64 24}
!13 = !{!6, !10, i64 32}
!14 = !{!6, !10, i64 40}
!15 = !{!16, !7, i64 0}
!16 = !{!"_ZTSN10primesieve12IteratorDataE", !7, i64 0, !7, i64 8, !17, i64 16, !10, i64 24, !18, i64 32, !8, i64 56}
!17 = !{!"bool", !8, i64 0}
!18 = !{!"_ZTSN10primesieve6VectorImSaImEEE", !10, i64 0, !10, i64 8, !10, i64 16}
!19 = !{!16, !7, i64 8}
!20 = !{!16, !17, i64 16}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,MemCpyOptPass,PostOrderFunctionAttrsPass,SROAPass,TailCallElimPass