; 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.NullLogger = type { i8 }
%"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: mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZN10NullLogger9GetStreamEv(ptr noundef nonnull align 1 dereferenceable(1)) #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 noundef i64 @_ZN7vraudio17LocklessTaskQueue15PopNodeFromListEPSt6atomicImE(ptr noundef nonnull align 8 dereferenceable(64) %0, ptr noundef %1) #1 align 2 {
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca %class.NullLogger, align 1
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %10 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 1, ptr %6) #5
  %11 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZN10NullLogger9GetStreamEv(ptr noundef nonnull align 1 dereferenceable(1) %6)
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  br label %12

12:                                               ; preds = %26, %2
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = call noundef i64 @_ZNKSt13__atomic_baseImE4loadESt12memory_order(ptr noundef nonnull align 8 dereferenceable(8) %13, i32 noundef 5) #5
  store i64 %14, ptr %7, align 8, !tbaa !9
  %15 = load i64, ptr %7, align 8, !tbaa !9
  %16 = call noundef i64 @_ZN7vraudio17LocklessTaskQueue8GetIndexEm(ptr noundef nonnull align 8 dereferenceable(64) %10, i64 noundef %15)
  %17 = icmp eq i64 %16, 4294967295
  br i1 %17, label %18, label %19

18:                                               ; preds = %12
  store i64 4294967295, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %34

19:                                               ; preds = %12
  %20 = getelementptr inbounds %"class.vraudio::LocklessTaskQueue", ptr %10, i32 0, i32 2
  %21 = load i64, ptr %7, align 8, !tbaa !9
  %22 = call noundef i64 @_ZN7vraudio17LocklessTaskQueue8GetIndexEm(ptr noundef nonnull align 8 dereferenceable(64) %10, i64 noundef %21)
  %23 = call noundef nonnull align 8 dereferenceable(40) ptr @_ZNSt6vectorIN7vraudio17LocklessTaskQueue4NodeESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %20, i64 noundef %22) #5
  %24 = getelementptr inbounds %"struct.vraudio::LocklessTaskQueue::Node", ptr %23, i32 0, i32 1
  %25 = call noundef i64 @_ZNKSt13__atomic_baseImEcvmEv(ptr noundef nonnull align 8 dereferenceable(8) %24) #5
  store i64 %25, ptr %8, align 8, !tbaa !9
  br label %26

26:                                               ; preds = %19
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = load i64, ptr %8, align 8, !tbaa !9
  %29 = call noundef zeroext i1 @_ZSt30atomic_compare_exchange_strongImEbPSt6atomicIT_EPNSt15__type_identityIS1_E4typeES6_(ptr noundef %27, ptr noundef %7, i64 noundef %28) #5
  %30 = xor i1 %29, true
  br i1 %30, label %12, label %31, !llvm.loop !11

31:                                               ; preds = %26
  %32 = load i64, ptr %7, align 8, !tbaa !9
  %33 = call noundef i64 @_ZN7vraudio17LocklessTaskQueue11IncreaseTagEm(ptr noundef nonnull align 8 dereferenceable(64) %10, i64 noundef %32)
  store i64 %33, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %34

34:                                               ; preds = %31, %18
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  %35 = load i64, ptr %3, align 8
  ret i64 %35
}

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

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

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

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt13__atomic_baseImE4loadESt12memory_order(ptr noundef nonnull align 8 dereferenceable(8), i32 noundef) #3 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZSt30atomic_compare_exchange_strongImEbPSt6atomicIT_EPNSt15__type_identityIS1_E4typeES6_(ptr noundef, ptr noundef, i64 noundef) #4

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 = { alwaysinline 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 #4 = { inlinehint 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 #5 = { 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"

%class.NullLogger = type { i8 }

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

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

; Function Attrs: mustprogress 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 noundef i64 @_ZN7vraudio17LocklessTaskQueue15PopNodeFromListEPSt6atomicImE(ptr noundef nonnull align 8 dereferenceable(64) %0, ptr noundef %1) local_unnamed_addr #1 align 2 {
  %3 = alloca %class.NullLogger, align 1
  %4 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %3) #5
  %5 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZN10NullLogger9GetStreamEv(ptr noundef nonnull align 1 dereferenceable(1) %3)
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %3) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #5
  %6 = getelementptr inbounds i8, ptr %0, i64 16
  br label %7

7:                                                ; preds = %11, %2
  %8 = call noundef i64 @_ZNKSt13__atomic_baseImE4loadESt12memory_order(ptr noundef nonnull align 8 dereferenceable(8) %1, i32 noundef 5) #5
  store i64 %8, ptr %4, align 8, !tbaa !5
  %9 = call noundef i64 @_ZN7vraudio17LocklessTaskQueue8GetIndexEm(ptr noundef nonnull align 8 dereferenceable(64) %0, i64 noundef %8)
  %10 = icmp eq i64 %9, 4294967295
  br i1 %10, label %.loopexit, label %11

11:                                               ; preds = %7
  %12 = load i64, ptr %4, align 8, !tbaa !5
  %13 = call noundef i64 @_ZN7vraudio17LocklessTaskQueue8GetIndexEm(ptr noundef nonnull align 8 dereferenceable(64) %0, i64 noundef %12)
  %14 = call noundef nonnull align 8 dereferenceable(40) ptr @_ZNSt6vectorIN7vraudio17LocklessTaskQueue4NodeESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %6, i64 noundef %13) #5
  %15 = getelementptr inbounds i8, ptr %14, i64 32
  %16 = call noundef i64 @_ZNKSt13__atomic_baseImEcvmEv(ptr noundef nonnull align 8 dereferenceable(8) %15) #5
  %17 = call noundef zeroext i1 @_ZSt30atomic_compare_exchange_strongImEbPSt6atomicIT_EPNSt15__type_identityIS1_E4typeES6_(ptr noundef nonnull %1, ptr noundef nonnull %4, i64 noundef %16) #5
  br i1 %17, label %18, label %7, !llvm.loop !9

18:                                               ; preds = %11
  %19 = load i64, ptr %4, align 8, !tbaa !5
  %20 = call noundef i64 @_ZN7vraudio17LocklessTaskQueue11IncreaseTagEm(ptr noundef nonnull align 8 dereferenceable(64) %0, i64 noundef %19)
  br label %.loopexit

.loopexit:                                        ; preds = %7, %18
  %.0 = phi i64 [ %20, %18 ], [ 4294967295, %7 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #5
  ret i64 %.0
}

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

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

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

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt13__atomic_baseImE4loadESt12memory_order(ptr noundef nonnull align 8 dereferenceable(8), i32 noundef) local_unnamed_addr #3 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZSt30atomic_compare_exchange_strongImEbPSt6atomicIT_EPNSt15__type_identityIS1_E4typeES6_(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #4

attributes #0 = { mustprogress 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 = { alwaysinline 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 #4 = { inlinehint 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 #5 = { 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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass