// File: /workspace/github_cpp_makefile_star2_O2/HQarroum[P]thread-pool/examples/one-producer-many-consumers/./../../includes/concurrent_queue.hpp
// Function: unsigned long moodycamel::ConcurrentQueue<std::function<void ()>, moodycamel::ConcurrentQueueDefaultTraits>::ImplicitProducer::dequeue_bulk<std::function<void ()>*>(std::function<void ()>*&, unsigned long)
size_t dequeue_bulk(It& itemFirst, size_t max)
		{
			auto tail = this->tailIndex.load(std::memory_order_relaxed);
			auto overcommit = this->dequeueOvercommit.load(std::memory_order_relaxed);
			auto desiredCount = static_cast<size_t>(tail - (this->dequeueOptimisticCount.load(std::memory_order_relaxed) - overcommit));
			if (details::circular_less_than<size_t>(0, desiredCount)) {
				desiredCount = desiredCount < max ? desiredCount : max;
				std::atomic_thread_fence(std::memory_order_acquire);
				
				auto myDequeueCount = this->dequeueOptimisticCount.fetch_add(desiredCount, std::memory_order_relaxed);
				
				tail = this->tailIndex.load(std::memory_order_acquire);
				auto actualCount = static_cast<size_t>(tail - (myDequeueCount - overcommit));
				if (details::circular_less_than<size_t>(0, actualCount)) {
					actualCount = desiredCount < actualCount ? desiredCount : actualCount;
					if (actualCount < desiredCount) {
						this->dequeueOvercommit.fetch_add(desiredCount - actualCount, std::memory_order_release);
					}
					
					// Get the first index. Note that since there's guaranteed to be at least actualCount elements, this
					// will never exceed tail.
					auto firstIndex = this->headIndex.fetch_add(actualCount, std::memory_order_acq_rel);
					
					// Iterate the blocks and dequeue
					auto index = firstIndex;
					BlockIndexHeader* localBlockIndex;
					auto indexIndex = get_block_index_index_for_index(index, localBlockIndex);
					do {
						auto blockStartIndex = index;
						index_t endIndex = (index & ~static_cast<index_t>(BLOCK_SIZE - 1)) + static_cast<index_t>(BLOCK_SIZE);
						endIndex = details::circular_less_than<index_t>(firstIndex + static_cast<index_t>(actualCount), endIndex) ? firstIndex + static_cast<index_t>(actualCount) : endIndex;
						
						auto entry = localBlockIndex->index[indexIndex];
						auto block = entry->value.load(std::memory_order_relaxed);
						if (MOODYCAMEL_NOEXCEPT_ASSIGN(T, T&&, details::deref_noexcept(itemFirst) = std::move((*(*block)[index])))) {
							while (index != endIndex) {
								auto& el = *((*block)[index]);
								*itemFirst++ = std::move(el);
								el.~T();
								++index;
							}
						}
						else {
							MOODYCAMEL_TRY {
								while (index != endIndex) {
									auto& el = *((*block)[index]);
									*itemFirst = std::move(el);
									++itemFirst;
									el.~T();
									++index;
								}
							}
							MOODYCAMEL_CATCH (...) {
								do {
									entry = localBlockIndex->index[indexIndex];
									block = entry->value.load(std::memory_order_relaxed);
									while (index != endIndex) {
										(*block)[index++]->~T();
									}
									
									if (block->ConcurrentQueue::Block::template set_many_empty<implicit_context>(blockStartIndex, static_cast<size_t>(endIndex - blockStartIndex))) {
#ifdef MCDBGQ_NOLOCKFREE_IMPLICITPRODBLOCKINDEX
										debug::DebugLock lock(mutex);
#endif
										entry->value.store(nullptr, std::memory_order_relaxed);
										this->parent->add_block_to_free_list(block);
									}
									indexIndex = (indexIndex + 1) & (localBlockIndex->capacity - 1);
									
									blockStartIndex = index;
									endIndex = (index & ~static_cast<index_t>(BLOCK_SIZE - 1)) + static_cast<index_t>(BLOCK_SIZE);
									endIndex = details::circular_less_than<index_t>(firstIndex + static_cast<index_t>(actualCount), endIndex) ? firstIndex + static_cast<index_t>(actualCount) : endIndex;
								} while (index != firstIndex + actualCount);
								
								MOODYCAMEL_RETHROW;
							}
						}
						if (block->ConcurrentQueue::Block::template set_many_empty<implicit_context>(blockStartIndex, static_cast<size_t>(endIndex - blockStartIndex))) {
							{
#ifdef MCDBGQ_NOLOCKFREE_IMPLICITPRODBLOCKINDEX
								debug::DebugLock lock(mutex);
#endif
								// Note that the set_many_empty above did a release, meaning that anybody who acquires the block
								// we're about to free can use it safely since our writes (and reads!) will have happened-before then.
								entry->value.store(nullptr, std::memory_order_relaxed);
							}
							this->parent->add_block_to_free_list(block);		// releases the above store
						}
						indexIndex = (indexIndex + 1) & (localBlockIndex->capacity - 1);
					} while (index != firstIndex + actualCount);
					
					return actualCount;
				}
				else {
					this->dequeueOvercommit.fetch_add(desiredCount, std::memory_order_release);
				}
			}
			
			return 0;
		}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rsi, %r15
movq 0x20(%rdi), %rcx
movq 0x38(%rdi), %r14
movq 0x30(%rdi), %rsi
movq %r14, %rax
subq %rsi, %rax
addq %rcx, %rax
testq %rax, %rax
jle 0x48d5
cmpq %rdx, %rax
cmovbq %rax, %rdx
movq %rdx, %rax
lock
xaddq %rax, 0x30(%rdi)
movq 0x20(%rdi), %rcx
subq %rax, %r14
addq %rcx, %r14
testq %r14, %r14
jle 0x48d0
cmpq %r14, %rdx
cmovbq %rdx, %r14
jbe 0x47d5
subq %r14, %rdx
lock
addq %rdx, 0x38(%rdi)
movq %r14, %r12
lock
xaddq %r12, 0x28(%rdi)
leaq 0x30(%rsp), %rbx
movq %rdi, 0x10(%rsp)
movq %r12, %rsi
movq %rbx, %rdx
callq 0x49c4
movq %rax, %r13
movq %r14, 0x8(%rsp)
leaq (%r12,%r14), %rdx
movq (%rbx), %rax
movq %rdx, 0x18(%rsp)
movq %r12, %rbx
andq $-0x20, %r12
addq $0x20, %r12
movq %rdx, %rcx
subq %r12, %rcx
movabsq $-0x8000000000000000, %rsi # imm = 0x8000000000000000
cmpq %rsi, %rcx
cmovaq %rdx, %r12
movq 0x18(%rax), %rax
movq (%rax,%r13,8), %rax
movq %rax, 0x20(%rsp)
movq 0x8(%rax), %rbp
movq %rbx, 0x28(%rsp)
cmpq %rbx, %r12
je 0x4871
movl %ebx, %r14d
andl $0x1f, %r14d
shll $0x5, %r14d
addq %rbp, %r14
movq (%r15), %rdi
leaq 0x20(%rdi), %rax
movq %rax, (%r15)
movq %r14, %rsi
callq 0x48e6
movq %r14, %rdi
callq 0x5276
incq %rbx
jmp 0x483f
movq %r12, %rdx
movq 0x28(%rsp), %rsi
subq %rsi, %rdx
movq %rbp, %rdi
callq 0x4a54
testb %al, %al
je 0x48aa
movq 0x20(%rsp), %rax
movq $0x0, 0x8(%rax)
movq 0x10(%rsp), %rax
movq 0x50(%rax), %rdi
addq $0x28, %rdi
movq %rbp, %rsi
callq 0x4a92
incq %r13
movq 0x30(%rsp), %rax
movq (%rax), %rcx
decq %rcx
andq %rcx, %r13
movq 0x18(%rsp), %rdx
cmpq %rdx, %r12
jne 0x4807
movq 0x8(%rsp), %rax
jmp 0x48d7
lock
addq %rdx, 0x38(%rdi)
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq