; LLVM IR from vertver/Fresponze-old :: modules/resonance-audio/resonance_audio/utils (lockless_task_queue)

; 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.vraudio::LocklessTaskQueue" = type { %"struct.std::atomic", %"struct.std::atomic", %"class.std::vector", %"class.std::vector.0" }
%"struct.std::atomic" = type { %"struct.std::__atomic_base" }
%"struct.std::__atomic_base" = type { ptr }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<vraudio::LocklessTaskQueue::Node, std::allocator<vraudio::LocklessTaskQueue::Node>>::_Vector_impl" }
%"struct.std::_Vector_base<vraudio::LocklessTaskQueue::Node, std::allocator<vraudio::LocklessTaskQueue::Node>>::_Vector_impl" = type { %"struct.std::_Vector_base<vraudio::LocklessTaskQueue::Node, std::allocator<vraudio::LocklessTaskQueue::Node>>::_Vector_impl_data" }
%"struct.std::_Vector_base<vraudio::LocklessTaskQueue::Node, std::allocator<vraudio::LocklessTaskQueue::Node>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"class.std::vector.0" = type { %"struct.std::_Vector_base.1" }
%"struct.std::_Vector_base.1" = type { %"struct.std::_Vector_base<std::function<void ()>, std::allocator<std::function<void ()>>>::_Vector_impl" }
%"struct.std::_Vector_base<std::function<void ()>, std::allocator<std::function<void ()>>>::_Vector_impl" = type { %"struct.std::_Vector_base<std::function<void ()>, std::allocator<std::function<void ()>>>::_Vector_impl_data" }
%"struct.std::_Vector_base<std::function<void ()>, std::allocator<std::function<void ()>>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"struct.vraudio::LocklessTaskQueue::Node" = type { %"class.std::function", %"struct.std::atomic" }
%"class.std::function" = type { %"class.std::_Function_base", ptr }
%"class.std::_Function_base" = type { %"union.std::_Any_data", ptr }
%"union.std::_Any_data" = type { %"union.std::_Nocopy_types" }
%"union.std::_Nocopy_types" = type { { i64, i64 } }

; 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 uwtable
define dso_local void @_ZN7vraudio17LocklessTaskQueue4InitEm(ptr noundef nonnull align 8 dereferenceable(64) %0, i64 noundef %1) #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !9
  %6 = load ptr, ptr %3, align 8
  %7 = getelementptr inbounds %"class.vraudio::LocklessTaskQueue", ptr %6, i32 0, i32 2
  %8 = load i64, ptr %4, align 8, !tbaa !9
  call void @_ZNSt6vectorIN7vraudio17LocklessTaskQueue4NodeESaIS2_EE6resizeEm(ptr noundef nonnull align 8 dereferenceable(24) %7, i64 noundef %8)
  %9 = getelementptr inbounds %"class.vraudio::LocklessTaskQueue", ptr %6, i32 0, i32 3
  %10 = load i64, ptr %4, align 8, !tbaa !9
  call void @_ZNSt6vectorISt8functionIFvvEESaIS2_EE7reserveEm(ptr noundef nonnull align 8 dereferenceable(24) %9, i64 noundef %10)
  %11 = getelementptr inbounds %"class.vraudio::LocklessTaskQueue", ptr %6, i32 0, i32 2
  %12 = call noundef nonnull align 8 dereferenceable(40) ptr @_ZNSt6vectorIN7vraudio17LocklessTaskQueue4NodeESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %11, i64 noundef 0) #3
  %13 = getelementptr inbounds %"class.vraudio::LocklessTaskQueue", ptr %6, i32 0, i32 0
  %14 = call noundef ptr @_ZNSt6atomicIPN7vraudio17LocklessTaskQueue4NodeEEaSES3_(ptr noundef nonnull align 8 dereferenceable(8) %13, ptr noundef %12) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  store i64 0, ptr %5, align 8, !tbaa !9
  br label %15

15:                                               ; preds = %31, %2
  %16 = load i64, ptr %5, align 8, !tbaa !9
  %17 = load i64, ptr %4, align 8, !tbaa !9
  %18 = sub i64 %17, 1
  %19 = icmp ult i64 %16, %18
  br i1 %19, label %21, label %20

20:                                               ; preds = %15
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  br label %34

21:                                               ; preds = %15
  %22 = getelementptr inbounds %"class.vraudio::LocklessTaskQueue", ptr %6, i32 0, i32 2
  %23 = load i64, ptr %5, align 8, !tbaa !9
  %24 = add i64 %23, 1
  %25 = call noundef nonnull align 8 dereferenceable(40) ptr @_ZNSt6vectorIN7vraudio17LocklessTaskQueue4NodeESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %22, i64 noundef %24) #3
  %26 = getelementptr inbounds %"class.vraudio::LocklessTaskQueue", ptr %6, i32 0, i32 2
  %27 = load i64, ptr %5, align 8, !tbaa !9
  %28 = call noundef nonnull align 8 dereferenceable(40) ptr @_ZNSt6vectorIN7vraudio17LocklessTaskQueue4NodeESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %26, i64 noundef %27) #3
  %29 = getelementptr inbounds %"struct.vraudio::LocklessTaskQueue::Node", ptr %28, i32 0, i32 1
  %30 = call noundef ptr @_ZNSt6atomicIPN7vraudio17LocklessTaskQueue4NodeEEaSES3_(ptr noundef nonnull align 8 dereferenceable(8) %29, ptr noundef %25) #3
  br label %31

31:                                               ; preds = %21
  %32 = load i64, ptr %5, align 8, !tbaa !9
  %33 = add i64 %32, 1
  store i64 %33, ptr %5, align 8, !tbaa !9
  br label %15, !llvm.loop !11

34:                                               ; preds = %20
  %35 = getelementptr inbounds %"class.vraudio::LocklessTaskQueue", ptr %6, i32 0, i32 2
  %36 = load i64, ptr %4, align 8, !tbaa !9
  %37 = sub i64 %36, 1
  %38 = call noundef nonnull align 8 dereferenceable(40) ptr @_ZNSt6vectorIN7vraudio17LocklessTaskQueue4NodeESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %35, i64 noundef %37) #3
  %39 = getelementptr inbounds %"struct.vraudio::LocklessTaskQueue::Node", ptr %38, i32 0, i32 1
  %40 = call noundef ptr @_ZNSt6atomicIPN7vraudio17LocklessTaskQueue4NodeEEaSES3_(ptr noundef nonnull align 8 dereferenceable(8) %39, ptr noundef null) #3
  %41 = getelementptr inbounds %"class.vraudio::LocklessTaskQueue", ptr %6, i32 0, i32 1
  %42 = call noundef ptr @_ZNSt6atomicIPN7vraudio17LocklessTaskQueue4NodeEEaSES3_(ptr noundef nonnull align 8 dereferenceable(8) %41, ptr noundef null) #3
  ret void
}

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

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

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

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = distinct !{!11, !12}
!12 = !{!"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"

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7vraudio17LocklessTaskQueue4InitEm(ptr noundef nonnull align 8 dereferenceable(64) %0, i64 noundef %1) local_unnamed_addr #0 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 16
  tail call void @_ZNSt6vectorIN7vraudio17LocklessTaskQueue4NodeESaIS2_EE6resizeEm(ptr noundef nonnull align 8 dereferenceable(24) %3, i64 noundef %1)
  %4 = getelementptr inbounds i8, ptr %0, i64 40
  tail call void @_ZNSt6vectorISt8functionIFvvEESaIS2_EE7reserveEm(ptr noundef nonnull align 8 dereferenceable(24) %4, i64 noundef %1)
  %5 = tail call noundef nonnull align 8 dereferenceable(40) ptr @_ZNSt6vectorIN7vraudio17LocklessTaskQueue4NodeESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %3, i64 noundef 0) #2
  %6 = tail call noundef ptr @_ZNSt6atomicIPN7vraudio17LocklessTaskQueue4NodeEEaSES3_(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr noundef nonnull %5) #2
  %7 = add i64 %1, -1
  %.not = icmp eq i64 %7, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %2
  %8 = tail call noundef nonnull align 8 dereferenceable(40) ptr @_ZNSt6vectorIN7vraudio17LocklessTaskQueue4NodeESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %3, i64 noundef %7) #2
  %9 = getelementptr inbounds i8, ptr %8, i64 32
  %10 = tail call noundef ptr @_ZNSt6atomicIPN7vraudio17LocklessTaskQueue4NodeEEaSES3_(ptr noundef nonnull align 8 dereferenceable(8) %9, ptr noundef null) #2
  %11 = getelementptr inbounds i8, ptr %0, i64 8
  %12 = tail call noundef ptr @_ZNSt6atomicIPN7vraudio17LocklessTaskQueue4NodeEEaSES3_(ptr noundef nonnull align 8 dereferenceable(8) %11, ptr noundef null) #2
  ret void

.lr.ph:                                           ; preds = %2, %.lr.ph
  %.09 = phi i64 [ %13, %.lr.ph ], [ 0, %2 ]
  %13 = add nuw i64 %.09, 1
  %14 = tail call noundef nonnull align 8 dereferenceable(40) ptr @_ZNSt6vectorIN7vraudio17LocklessTaskQueue4NodeESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %3, i64 noundef %13) #2
  %15 = tail call noundef nonnull align 8 dereferenceable(40) ptr @_ZNSt6vectorIN7vraudio17LocklessTaskQueue4NodeESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %3, i64 noundef %.09) #2
  %16 = getelementptr inbounds i8, ptr %15, i64 32
  %17 = tail call noundef ptr @_ZNSt6atomicIPN7vraudio17LocklessTaskQueue4NodeEEaSES3_(ptr noundef nonnull align 8 dereferenceable(8) %16, ptr noundef nonnull %14) #2
  %exitcond.not = icmp eq i64 %13, %7
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !5
}

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

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(40) ptr @_ZNSt6vectorIN7vraudio17LocklessTaskQueue4NodeESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #1 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


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