; LLVM IR from glaretechnologies/substrata :: 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 { i64 }
%"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 0
  %12 = call noundef i64 @_ZNSt13__atomic_baseImEaSEm(ptr noundef nonnull align 8 dereferenceable(8) %11, i64 noundef 0) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  store i64 0, ptr %5, align 8, !tbaa !9
  br label %13

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

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

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

27:                                               ; preds = %19
  %28 = load i64, ptr %5, align 8, !tbaa !9
  %29 = add i64 %28, 1
  store i64 %29, ptr %5, align 8, !tbaa !9
  br label %13, !llvm.loop !11

30:                                               ; preds = %18
  %31 = getelementptr inbounds %"class.vraudio::LocklessTaskQueue", ptr %6, i32 0, i32 2
  %32 = load i64, ptr %4, align 8, !tbaa !9
  %33 = sub i64 %32, 1
  %34 = call noundef nonnull align 8 dereferenceable(40) ptr @_ZNSt6vectorIN7vraudio17LocklessTaskQueue4NodeESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %31, i64 noundef %33) #3
  %35 = getelementptr inbounds %"struct.vraudio::LocklessTaskQueue::Node", ptr %34, i32 0, i32 1
  %36 = call noundef i64 @_ZNSt13__atomic_baseImEaSEm(ptr noundef nonnull align 8 dereferenceable(8) %35, i64 noundef 4294967295) #3
  %37 = getelementptr inbounds %"class.vraudio::LocklessTaskQueue", ptr %6, i32 0, i32 1
  %38 = call noundef i64 @_ZNSt13__atomic_baseImEaSEm(ptr noundef nonnull align 8 dereferenceable(8) %37, i64 noundef 4294967295) #3
  ret void
}

; 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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNSt13__atomic_baseImEaSEm(ptr noundef nonnull align 8 dereferenceable(8), i64 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

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 i64 @_ZNSt13__atomic_baseImEaSEm(ptr noundef nonnull align 8 dereferenceable(8) %0, i64 noundef 0) #2
  %6 = add i64 %1, -1
  %.not = icmp eq i64 %6, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

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

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

; 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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNSt13__atomic_baseImEaSEm(ptr noundef nonnull align 8 dereferenceable(8), i64 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

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