// File: /workspace/github_cpp_makefile_star2_O3/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), %r8
movq 0x30(%rdi), %rsi
movq %r8, %rax
subq %rsi, %rax
addq %rcx, %rax
testq %rax, %rax
jle 0x50b9
cmpq %rdx, %rax
cmovbq %rax, %rdx
movq %rdx, %rax
lock
xaddq %rax, 0x30(%rdi)
movq 0x20(%rdi), %rcx
subq %rax, %r8
addq %rcx, %r8
testq %r8, %r8
jle 0x50b4
cmpq %r8, %rdx
cmovbq %rdx, %r8
jbe 0x4f05
subq %r8, %rdx
lock
addq %rdx, 0x38(%rdi)
movq %r8, %r14
lock
xaddq %r14, 0x28(%rdi)
movq 0x60(%rdi), %r10
movq 0x8(%r10), %rcx
movq 0x18(%r10), %rax
movq (%rax,%rcx,8), %rdx
movq (%rdx), %rdx
cmpq $0x1, %rdx
je 0x5108
movq %r14, %rsi
andq $-0x20, %rsi
movq %rsi, %r9
subq %rdx, %r9
shrq $0x5, %r9
addq %rcx, %r9
movq (%r10), %r11
decq %r11
andq %r9, %r11
movq (%rax,%r11,8), %rax
movq (%rax), %rcx
cmpq %rsi, %rcx
jne 0x50e9
movq 0x8(%rax), %rax
testq %rax, %rax
je 0x50e9
movq %r8, (%rsp)
leaq (%r14,%r8), %rsi
movabsq $-0x8000000000000000, %r8 # imm = 0x8000000000000000
movq %rdi, 0x18(%rsp)
movq %r10, 0x10(%rsp)
movq %rsi, 0x8(%rsp)
movq %r14, %rbx
andq $-0x20, %rbx
addq $0x20, %rbx
movq %rsi, %rax
subq %rbx, %rax
cmpq %r8, %rax
cmovaq %rsi, %rbx
movq 0x18(%r10), %rax
movq (%rax,%r11,8), %rcx
movq 0x8(%rcx), %rbp
movq %rbx, %rdx
subq %r14, %rdx
je 0x502e
movq %rdx, 0x20(%rsp)
movq %rcx, 0x28(%rsp)
movq %r11, 0x30(%rsp)
movl %r14d, %r13d
andl $0x1f, %r13d
shll $0x5, %r13d
movq %rbp, %r12
addq %r13, %r12
movq (%r15), %rdi
leaq 0x20(%rdi), %rax
movq %rax, (%r15)
movq %r12, %rsi
callq 0x5130
movq 0x10(%rbp,%r13), %rax
testq %rax, %rax
je 0x4ffb
movq %r12, %rdi
movq %r12, %rsi
movl $0x3, %edx
callq *%rax
incq %r14
cmpq %r14, %rbx
jne 0x4fc1
movq %rbx, %r14
movq 0x18(%rsp), %rdi
movq 0x10(%rsp), %r10
movq 0x30(%rsp), %r11
movq 0x8(%rsp), %rsi
movabsq $-0x8000000000000000, %r8 # imm = 0x8000000000000000
movq 0x28(%rsp), %rcx
movq 0x20(%rsp), %rdx
movq %rdx, %rax
lock
xaddq %rax, 0x408(%rbp)
addq %rdx, %rax
cmpq $0x21, %rax
jae 0x50ca
cmpq $0x20, %rax
jne 0x5099
movq $0x0, 0x8(%rcx)
movq 0x50(%rdi), %rcx
movl $0x80000000, %eax       # imm = 0x80000000
lock
xaddl %eax, 0x430(%rbp)
testl %eax, %eax
jne 0x5099
movq 0x28(%rcx), %rax
movq %rax, 0x438(%rbp)
movl $0x1, 0x430(%rbp)
lock
cmpxchgq %rbp, 0x28(%rcx)
je 0x5099
movl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
lock
xaddl %edx, 0x430(%rbp)
cmpl $0x1, %edx
je 0x506e
incq %r11
movq (%r10), %rax
decq %rax
andq %rax, %r11
cmpq %rsi, %r14
jne 0x4f86
movq (%rsp), %rax
jmp 0x50bb
lock
addq %rdx, 0x38(%rdi)
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x25c8(%rip), %rdi      # 0x7699
leaq 0x2006(%rip), %rsi      # 0x70de
leaq 0x25d8(%rip), %rcx      # 0x76b7
movl $0x64a, %edx            # imm = 0x64A
callq 0x3150
leaq 0x250e(%rip), %rdi      # 0x75fe
leaq 0x1fe7(%rip), %rsi      # 0x70de
leaq 0x241e(%rip), %rcx      # 0x751c
movl $0xb81, %edx            # imm = 0xB81
callq 0x3150
leaq 0x23ee(%rip), %rdi      # 0x74fd
leaq 0x1fc8(%rip), %rsi      # 0x70de
leaq 0x23ff(%rip), %rcx      # 0x751c
movl $0xb7c, %edx            # imm = 0xB7C
callq 0x3150
movq %rax, %rdi
callq 0x3ae9
nop