// File: 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
movq %rsp, %rbp
subq $0x250, %rsp            # imm = 0x250
movq %rdi, -0x118(%rbp)
movq %rsi, -0x120(%rbp)
movq %rdx, -0x128(%rbp)
movq -0x118(%rbp), %rax
movq %rax, -0x1b0(%rbp)
addq $0x20, %rax
movq %rax, -0xb0(%rbp)
movl $0x0, -0xb4(%rbp)
movq -0xb0(%rbp), %rax
movq %rax, -0x1a8(%rbp)
movl -0xb4(%rbp), %edi
movl $0xffff, %esi           # imm = 0xFFFF
callq 0x58d0
movl %eax, -0xb8(%rbp)
movl -0xb4(%rbp), %eax
movl %eax, -0x19c(%rbp)
decl %eax
subl $0x2, %eax
jb 0x9ecc
jmp 0x9eac
movl -0x19c(%rbp), %eax
subl $0x5, %eax
je 0x9edf
jmp 0x9eb9
movq -0x1a8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0xc0(%rbp)
jmp 0x9ef0
movq -0x1a8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0xc0(%rbp)
jmp 0x9ef0
movq -0x1a8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0xc0(%rbp)
movq -0x1b0(%rbp), %rax
movq -0xc0(%rbp), %rcx
movq %rcx, -0x130(%rbp)
addq $0x38, %rax
movq %rax, -0xc8(%rbp)
movl $0x0, -0xcc(%rbp)
movq -0xc8(%rbp), %rax
movq %rax, -0x1c0(%rbp)
movl -0xcc(%rbp), %edi
movl $0xffff, %esi           # imm = 0xFFFF
callq 0x58d0
movl %eax, -0xd0(%rbp)
movl -0xcc(%rbp), %eax
movl %eax, -0x1b4(%rbp)
decl %eax
subl $0x2, %eax
jb 0x9f73
jmp 0x9f53
movl -0x1b4(%rbp), %eax
subl $0x5, %eax
je 0x9f86
jmp 0x9f60
movq -0x1c0(%rbp), %rax
movq (%rax), %rax
movq %rax, -0xd8(%rbp)
jmp 0x9f97
movq -0x1c0(%rbp), %rax
movq (%rax), %rax
movq %rax, -0xd8(%rbp)
jmp 0x9f97
movq -0x1c0(%rbp), %rax
movq (%rax), %rax
movq %rax, -0xd8(%rbp)
movq -0x1b0(%rbp), %rax
movq -0xd8(%rbp), %rcx
movq %rcx, -0x138(%rbp)
movq -0x130(%rbp), %rcx
movq %rcx, -0x1d8(%rbp)
addq $0x30, %rax
movq %rax, -0xe0(%rbp)
movl $0x0, -0xe4(%rbp)
movq -0xe0(%rbp), %rax
movq %rax, -0x1d0(%rbp)
movl -0xe4(%rbp), %edi
movl $0xffff, %esi           # imm = 0xFFFF
callq 0x58d0
movl %eax, -0xe8(%rbp)
movl -0xe4(%rbp), %eax
movl %eax, -0x1c4(%rbp)
decl %eax
subl $0x2, %eax
jb 0xa028
jmp 0xa008
movl -0x1c4(%rbp), %eax
subl $0x5, %eax
je 0xa03b
jmp 0xa015
movq -0x1d0(%rbp), %rax
movq (%rax), %rax
movq %rax, -0xf0(%rbp)
jmp 0xa04c
movq -0x1d0(%rbp), %rax
movq (%rax), %rax
movq %rax, -0xf0(%rbp)
jmp 0xa04c
movq -0x1d0(%rbp), %rax
movq (%rax), %rax
movq %rax, -0xf0(%rbp)
movq -0x1d8(%rbp), %rax
movq -0xf0(%rbp), %rcx
subq -0x138(%rbp), %rcx
subq %rcx, %rax
movq %rax, -0x140(%rbp)
movq -0x140(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edi
callq 0x3800
testb $0x1, %al
jne 0xa084
jmp 0xa794
movq -0x140(%rbp), %rax
cmpq -0x128(%rbp), %rax
jae 0xa0a4
movq -0x140(%rbp), %rax
movq %rax, -0x1e0(%rbp)
jmp 0xa0b2
movq -0x128(%rbp), %rax
movq %rax, -0x1e0(%rbp)
movq -0x1e0(%rbp), %rax
movq %rax, -0x140(%rbp)
movl $0x2, -0xa4(%rbp)
movl -0xa4(%rbp), %eax
decl %eax
movl %eax, %ecx
movq %rcx, -0x1e8(%rbp)
subl $0x4, %eax
ja 0xa100
movq -0x1e8(%rbp), %rax
leaq 0xe012(%rip), %rcx      # 0x18100
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
jmp 0xa100
jmp 0xa100
jmp 0xa100
mfence
movq -0x1b0(%rbp), %rcx
addq $0x30, %rcx
movq -0x140(%rbp), %rax
movq %rcx, -0x8(%rbp)
movq %rax, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x1f8(%rbp)
movl -0x14(%rbp), %eax
movq -0x10(%rbp), %rcx
movq %rcx, -0x20(%rbp)
decl %eax
movl %eax, %ecx
movq %rcx, -0x1f0(%rbp)
subl $0x4, %eax
ja 0xa15e
movq -0x1f0(%rbp), %rax
leaq 0xdfbf(%rip), %rcx      # 0x18114
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x1f8(%rbp), %rcx
movq -0x20(%rbp), %rax
lock
xaddq %rax, (%rcx)
movq %rax, -0x28(%rbp)
jmp 0xa1ca
movq -0x1f8(%rbp), %rcx
movq -0x20(%rbp), %rax
lock
xaddq %rax, (%rcx)
movq %rax, -0x28(%rbp)
jmp 0xa1ca
movq -0x1f8(%rbp), %rcx
movq -0x20(%rbp), %rax
lock
xaddq %rax, (%rcx)
movq %rax, -0x28(%rbp)
jmp 0xa1ca
movq -0x1f8(%rbp), %rcx
movq -0x20(%rbp), %rax
lock
xaddq %rax, (%rcx)
movq %rax, -0x28(%rbp)
jmp 0xa1ca
movq -0x1f8(%rbp), %rcx
movq -0x20(%rbp), %rax
lock
xaddq %rax, (%rcx)
movq %rax, -0x28(%rbp)
movq -0x1b0(%rbp), %rax
movq -0x28(%rbp), %rcx
movq %rcx, -0x148(%rbp)
addq $0x20, %rax
movq %rax, -0xf8(%rbp)
movl $0x2, -0xfc(%rbp)
movq -0xf8(%rbp), %rax
movq %rax, -0x208(%rbp)
movl -0xfc(%rbp), %edi
movl $0xffff, %esi           # imm = 0xFFFF
callq 0x58d0
movl %eax, -0x100(%rbp)
movl -0xfc(%rbp), %eax
movl %eax, -0x1fc(%rbp)
decl %eax
subl $0x2, %eax
jb 0xa24a
jmp 0xa22a
movl -0x1fc(%rbp), %eax
subl $0x5, %eax
je 0xa25d
jmp 0xa237
movq -0x208(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x108(%rbp)
jmp 0xa26e
movq -0x208(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x108(%rbp)
jmp 0xa26e
movq -0x208(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x108(%rbp)
movq -0x108(%rbp), %rax
movq %rax, -0x130(%rbp)
movq -0x130(%rbp), %rax
movq -0x148(%rbp), %rcx
subq -0x138(%rbp), %rcx
subq %rcx, %rax
movq %rax, -0x150(%rbp)
movq -0x150(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edi
callq 0x3800
testb $0x1, %al
jne 0xa2b4
jmp 0xa69b
movq -0x140(%rbp), %rax
cmpq -0x150(%rbp), %rax
jae 0xa2d4
movq -0x140(%rbp), %rax
movq %rax, -0x210(%rbp)
jmp 0xa2e2
movq -0x150(%rbp), %rax
movq %rax, -0x210(%rbp)
movq -0x210(%rbp), %rax
movq %rax, -0x150(%rbp)
movq -0x150(%rbp), %rax
cmpq -0x140(%rbp), %rax
jae 0xa3d8
movq -0x1b0(%rbp), %rcx
addq $0x38, %rcx
movq -0x140(%rbp), %rax
movq -0x150(%rbp), %rdx
subq %rdx, %rax
movq %rcx, -0x30(%rbp)
movq %rax, -0x38(%rbp)
movl $0x3, -0x3c(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x220(%rbp)
movl -0x3c(%rbp), %eax
movq -0x38(%rbp), %rcx
movq %rcx, -0x48(%rbp)
decl %eax
movl %eax, %ecx
movq %rcx, -0x218(%rbp)
subl $0x4, %eax
ja 0xa36c
movq -0x218(%rbp), %rax
leaq 0xddd9(%rip), %rcx      # 0x1813c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x220(%rbp), %rcx
movq -0x48(%rbp), %rax
lock
xaddq %rax, (%rcx)
movq %rax, -0x50(%rbp)
jmp 0xa3d8
movq -0x220(%rbp), %rcx
movq -0x48(%rbp), %rax
lock
xaddq %rax, (%rcx)
movq %rax, -0x50(%rbp)
jmp 0xa3d8
movq -0x220(%rbp), %rcx
movq -0x48(%rbp), %rax
lock
xaddq %rax, (%rcx)
movq %rax, -0x50(%rbp)
jmp 0xa3d8
movq -0x220(%rbp), %rcx
movq -0x48(%rbp), %rax
lock
xaddq %rax, (%rcx)
movq %rax, -0x50(%rbp)
jmp 0xa3d8
movq -0x220(%rbp), %rcx
movq -0x48(%rbp), %rax
lock
xaddq %rax, (%rcx)
movq %rax, -0x50(%rbp)
movq -0x1b0(%rbp), %rcx
addq $0x28, %rcx
movq -0x150(%rbp), %rax
movq %rcx, -0x58(%rbp)
movq %rax, -0x60(%rbp)
movl $0x4, -0x64(%rbp)
movq -0x58(%rbp), %rax
movq %rax, -0x230(%rbp)
movl -0x64(%rbp), %eax
movq -0x60(%rbp), %rcx
movq %rcx, -0x70(%rbp)
decl %eax
movl %eax, %ecx
movq %rcx, -0x228(%rbp)
subl $0x4, %eax
ja 0xa436
movq -0x228(%rbp), %rax
leaq 0xdd23(%rip), %rcx      # 0x18150
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x230(%rbp), %rcx
movq -0x70(%rbp), %rax
lock
xaddq %rax, (%rcx)
movq %rax, -0x78(%rbp)
jmp 0xa4a2
movq -0x230(%rbp), %rcx
movq -0x70(%rbp), %rax
lock
xaddq %rax, (%rcx)
movq %rax, -0x78(%rbp)
jmp 0xa4a2
movq -0x230(%rbp), %rcx
movq -0x70(%rbp), %rax
lock
xaddq %rax, (%rcx)
movq %rax, -0x78(%rbp)
jmp 0xa4a2
movq -0x230(%rbp), %rcx
movq -0x70(%rbp), %rax
lock
xaddq %rax, (%rcx)
movq %rax, -0x78(%rbp)
jmp 0xa4a2
movq -0x230(%rbp), %rcx
movq -0x70(%rbp), %rax
lock
xaddq %rax, (%rcx)
movq %rax, -0x78(%rbp)
movq -0x1b0(%rbp), %rdi
movq -0x78(%rbp), %rax
movq %rax, -0x158(%rbp)
movq -0x158(%rbp), %rax
movq %rax, -0x160(%rbp)
movq -0x160(%rbp), %rsi
leaq -0x168(%rbp), %rdx
callq 0xacd0
movq %rax, -0x170(%rbp)
movq -0x160(%rbp), %rax
movq %rax, -0x178(%rbp)
movq -0x160(%rbp), %rax
andq $-0x20, %rax
addq $0x20, %rax
movq %rax, -0x180(%rbp)
movq -0x158(%rbp), %rdi
addq -0x150(%rbp), %rdi
movq -0x180(%rbp), %rsi
callq 0x3800
testb $0x1, %al
jne 0xa520
jmp 0xa537
movq -0x158(%rbp), %rax
addq -0x150(%rbp), %rax
movq %rax, -0x238(%rbp)
jmp 0xa545
movq -0x180(%rbp), %rax
movq %rax, -0x238(%rbp)
movq -0x238(%rbp), %rax
movq %rax, -0x180(%rbp)
movq -0x168(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x170(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x188(%rbp)
movq -0x188(%rbp), %rdi
addq $0x8, %rdi
xorl %esi, %esi
callq 0x6210
movq %rax, -0x190(%rbp)
movq -0x160(%rbp), %rax
cmpq -0x180(%rbp), %rax
je 0xa5f3
movq -0x190(%rbp), %rdi
movq -0x160(%rbp), %rsi
callq 0xa830
movq %rax, -0x198(%rbp)
movq -0x198(%rbp), %rsi
movq -0x120(%rbp), %rax
movq (%rax), %rdi
movq %rdi, %rcx
addq $0x20, %rcx
movq %rcx, (%rax)
callq 0xa860
movq -0x198(%rbp), %rdi
callq 0x6fc0
movq -0x160(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x160(%rbp)
jmp 0xa589
movq -0x190(%rbp), %rdi
movq -0x178(%rbp), %rsi
movq -0x180(%rbp), %rdx
subq -0x178(%rbp), %rdx
callq 0xaf80
testb $0x1, %al
jne 0xa61a
jmp 0xa647
movq -0x188(%rbp), %rdi
addq $0x8, %rdi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0xb0a0
movq -0x1b0(%rbp), %rax
movq 0x50(%rax), %rdi
movq -0x190(%rbp), %rsi
callq 0xb130
movq -0x170(%rbp), %rax
addq $0x1, %rax
movq -0x168(%rbp), %rcx
movq (%rcx), %rcx
subq $0x1, %rcx
andq %rcx, %rax
movq %rax, -0x170(%rbp)
movq -0x160(%rbp), %rax
movq -0x158(%rbp), %rcx
addq -0x150(%rbp), %rcx
cmpq %rcx, %rax
jne 0xa4dc
movq -0x150(%rbp), %rax
movq %rax, -0x110(%rbp)
jmp 0xa79f
movq -0x1b0(%rbp), %rcx
addq $0x38, %rcx
movq -0x140(%rbp), %rax
movq %rcx, -0x80(%rbp)
movq %rax, -0x88(%rbp)
movl $0x3, -0x8c(%rbp)
movq -0x80(%rbp), %rax
movq %rax, -0x248(%rbp)
movl -0x8c(%rbp), %eax
movq -0x88(%rbp), %rcx
movq %rcx, -0x98(%rbp)
decl %eax
movl %eax, %ecx
movq %rcx, -0x240(%rbp)
subl $0x4, %eax
ja 0xa708
movq -0x240(%rbp), %rax
leaq 0xda29(%rip), %rcx      # 0x18128
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x248(%rbp), %rcx
movq -0x98(%rbp), %rax
lock
xaddq %rax, (%rcx)
movq %rax, -0xa0(%rbp)
jmp 0xa792
movq -0x248(%rbp), %rcx
movq -0x98(%rbp), %rax
lock
xaddq %rax, (%rcx)
movq %rax, -0xa0(%rbp)
jmp 0xa792
movq -0x248(%rbp), %rcx
movq -0x98(%rbp), %rax
lock
xaddq %rax, (%rcx)
movq %rax, -0xa0(%rbp)
jmp 0xa792
movq -0x248(%rbp), %rcx
movq -0x98(%rbp), %rax
lock
xaddq %rax, (%rcx)
movq %rax, -0xa0(%rbp)
jmp 0xa792
movq -0x248(%rbp), %rcx
movq -0x98(%rbp), %rax
lock
xaddq %rax, (%rcx)
movq %rax, -0xa0(%rbp)
jmp 0xa794
movq $0x0, -0x110(%rbp)
movq -0x110(%rbp), %rax
addq $0x250, %rsp            # imm = 0x250
popq %rbp
retq
nop