; 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: 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 hidden noundef nonnull align 8 dereferenceable(1776) ptr @_ZN12_GLOBAL__N_111getIterDataEP19primesieve_iterator(ptr noundef) #1

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN10primesieve12IteratorData12deletePrimesEv(ptr noundef nonnull align 8 dereferenceable(1776)) #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
define dso_local void @primesieve_skipto(ptr noundef %0, i64 noundef %1, i64 noundef %2) #2 personality ptr @__gxx_personality_v0 {
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = 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
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.primesieve_iterator, ptr %10, i32 0, i32 0
  store i64 0, ptr %11, align 8, !tbaa !11
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.primesieve_iterator, ptr %12, i32 0, i32 1
  store i64 0, ptr %13, align 8, !tbaa !14
  %14 = load i64, ptr %5, align 8, !tbaa !9
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.primesieve_iterator, ptr %15, i32 0, i32 2
  store i64 %14, ptr %16, align 8, !tbaa !15
  %17 = load i64, ptr %6, align 8, !tbaa !9
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.primesieve_iterator, ptr %18, i32 0, i32 3
  store i64 %17, ptr %19, align 8, !tbaa !16
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.primesieve_iterator, ptr %20, i32 0, i32 4
  store ptr null, ptr %21, align 8, !tbaa !17
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.primesieve_iterator, ptr %22, i32 0, i32 5
  %24 = load ptr, ptr %23, align 8, !tbaa !18
  %25 = icmp ne ptr %24, null
  br i1 %25, label %38, label %26

26:                                               ; preds = %3
  %27 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 1776) #5
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.primesieve_iterator, ptr %28, i32 0, i32 2
  %30 = load i64, ptr %29, align 8, !tbaa !15
  invoke void @_ZN10primesieve12IteratorDataC2Em(ptr noundef nonnull align 8 dereferenceable(1776) %27, i64 noundef %30)
          to label %31 unwind label %34

31:                                               ; preds = %26
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.primesieve_iterator, ptr %32, i32 0, i32 5
  store ptr %27, ptr %33, align 8, !tbaa !18
  br label %38

34:                                               ; preds = %26
  %35 = landingpad { ptr, i32 }
          cleanup
  %36 = extractvalue { ptr, i32 } %35, 0
  store ptr %36, ptr %7, align 8
  %37 = extractvalue { ptr, i32 } %35, 1
  store i32 %37, ptr %8, align 4
  call void @_ZdlPvm(ptr noundef %27, i64 noundef 1776) #6
  br label %50

38:                                               ; preds = %31, %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #7
  %39 = load ptr, ptr %4, align 8, !tbaa !5
  %40 = call noundef nonnull align 8 dereferenceable(1776) ptr @_ZN12_GLOBAL__N_111getIterDataEP19primesieve_iterator(ptr noundef %39)
  store ptr %40, ptr %9, align 8, !tbaa !5
  %41 = load i64, ptr %5, align 8, !tbaa !9
  %42 = load ptr, ptr %9, align 8, !tbaa !5
  %43 = getelementptr inbounds %"struct.primesieve::IteratorData", ptr %42, i32 0, i32 0
  store i64 %41, ptr %43, align 8, !tbaa !19
  %44 = load ptr, ptr %9, align 8, !tbaa !5
  %45 = getelementptr inbounds %"struct.primesieve::IteratorData", ptr %44, i32 0, i32 1
  store i64 0, ptr %45, align 8, !tbaa !23
  %46 = load ptr, ptr %9, align 8, !tbaa !5
  %47 = getelementptr inbounds %"struct.primesieve::IteratorData", ptr %46, i32 0, i32 2
  store i8 0, ptr %47, align 8, !tbaa !24
  %48 = load ptr, ptr %9, align 8, !tbaa !5
  call void @_ZN10primesieve12IteratorData20deletePrimeGeneratorEv(ptr noundef nonnull align 8 dereferenceable(1776) %48)
  %49 = load ptr, ptr %9, align 8, !tbaa !5
  call void @_ZN10primesieve12IteratorData12deletePrimesEv(ptr noundef nonnull align 8 dereferenceable(1776) %49)
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #7
  ret void

50:                                               ; preds = %34
  %51 = load ptr, ptr %7, align 8
  %52 = load i32, ptr %8, align 4
  %53 = insertvalue { ptr, i32 } poison, ptr %51, 0
  %54 = insertvalue { ptr, i32 } %53, i32 %52, 1
  resume { ptr, i32 } %54
}

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) #3

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN10primesieve12IteratorDataC2Em(ptr noundef nonnull align 8 dereferenceable(1776), i64 noundef) unnamed_addr #1 align 2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) #4

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 = { nobuiltin allocsize(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 = { nobuiltin nounwind "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 = { builtin allocsize(0) }
attributes #6 = { builtin nounwind }
attributes #7 = { 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
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: mustprogress uwtable
define dso_local void @primesieve_skipto(ptr noundef %0, i64 noundef %1, i64 noundef %2) local_unnamed_addr #1 personality ptr @__gxx_personality_v0 {
  %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 %9, label %11

9:                                                ; preds = %3
  %10 = tail call noalias noundef nonnull dereferenceable(1776) ptr @_Znwm(i64 noundef 1776) #4
  tail call void @_ZN10primesieve12IteratorDataC2Em(ptr noundef nonnull align 8 dereferenceable(1776) %10, i64 noundef %1)
  store ptr %10, ptr %7, align 8, !tbaa !14
  br label %11

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

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN10primesieve12IteratorDataC2Em(ptr noundef nonnull align 8 dereferenceable(1776), i64 noundef) unnamed_addr #0 align 2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

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 = { nobuiltin allocsize(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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { builtin allocsize(0) }

!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,SROAPass,SimplifyCFGPass,TailCallElimPass