// File: f18m[P]boost-intrusive-pool/include/boost_intrusive_pool.hpp
// Function: memorypool::boost_intrusive_pool<DummyClass>::impl::allocate_safe_get_recycled_item()
Item* allocate_safe_get_recycled_item()
        {
#if BOOST_INTRUSIVE_POOL_DEBUG_THREAD_ACCESS
            if (m_allowed_thread == 0)
                m_allowed_thread = pthread_self();
            else
                assert(m_allowed_thread == pthread_self());
#endif

            if (m_free_count == 0) {
                assert(m_first_free_item == nullptr);
                size_t enlarge_step = get_effective_enlarge_step();
                if (enlarge_step == 0 || !enlarge(enlarge_step)) {
                    m_memory_exhausted = true;
                    return nullptr; // allocation by enlarge() failed or this is a fixed-size memory pool!
                }
            }

            // get first item from free list
            assert(m_first_free_item != nullptr);
            Item* recycled_item = dynamic_cast<Item*>(m_first_free_item); // downcast (base class -> derived class)
            assert(recycled_item != nullptr); // we always allocate all items of the same type,
                                              // so the dynamic cast cannot fail
            assert(
                recycled_item->_refcounted_item_get_pool().get() == this); // this was set during arena initialization
                                                                           // and must be valid at all times

            // update stats
            m_free_count--;
            m_inuse_count++;

            // update the pointer to the next free item available
            m_first_free_item = m_first_free_item->_refcounted_item_get_next();
            if (m_first_free_item == nullptr && m_enlarge_step > 0) {
                size_t enlarge_step = get_effective_enlarge_step();
                if (enlarge_step == 0) { // enlarge_step can be zero if we reach the max_size
                    m_memory_exhausted = true;
                } else {
                    // this is a memory pool which can be still enlarged:
                    // exit the function leaving the m_first_free_item as a valid pointer to a free item!
                    // this is just to simplify debugging and make more effective the check() function implementation!

                    assert(m_free_count == 0);
                    if (!enlarge(enlarge_step)) {
                        m_memory_exhausted = true;
                        // We tried to fetch memory from the O.S. but we failed. However we succeeded in getting the
                        // last available item. So fallback and provide that last item to the caller.
                    }
                }
            }

            // unlink the item to return
            recycled_item->_refcounted_item_set_next(nullptr);
            return recycled_item;
        }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, 0x80(%rax)
jne 0x69c3
callq 0x20e0
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x80(%rax)
jmp 0x6a06
movq -0x38(%rbp), %rax
movq 0x80(%rax), %rax
movq %rax, -0x40(%rbp)
callq 0x20e0
movq %rax, %rcx
movq -0x40(%rbp), %rax
cmpq %rcx, %rax
jne 0x69e5
jmp 0x6a04
leaq 0x330d(%rip), %rdi      # 0x9cf9
leaq 0x2ce7(%rip), %rsi      # 0x96da
movl $0x253, %edx            # imm = 0x253
leaq 0x351b(%rip), %rcx      # 0x9f1a
callq 0x20a0
jmp 0x6a06
movq -0x38(%rbp), %rax
cmpq $0x0, 0x60(%rax)
jne 0x6a79
movq -0x38(%rbp), %rax
cmpq $0x0, 0x50(%rax)
jne 0x6a1e
jmp 0x6a3d
leaq 0x3565(%rip), %rdi      # 0x9f8a
leaq 0x2cae(%rip), %rsi      # 0x96da
movl $0x257, %edx            # imm = 0x257
leaq 0x34e2(%rip), %rcx      # 0x9f1a
callq 0x20a0
movq -0x38(%rbp), %rdi
callq 0x6c30
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x6a62
movq -0x38(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x5970
testb $0x1, %al
jne 0x6a77
movq -0x38(%rbp), %rax
movb $0x1, 0x58(%rax)
movq $0x0, -0x8(%rbp)
jmp 0x6c17
jmp 0x6a79
movq -0x38(%rbp), %rax
cmpq $0x0, 0x50(%rax)
je 0x6a86
jmp 0x6aa5
leaq 0x351a(%rip), %rdi      # 0x9fa7
leaq 0x2c46(%rip), %rsi      # 0x96da
movl $0x260, %edx            # imm = 0x260
leaq 0x347a(%rip), %rcx      # 0x9f1a
callq 0x20a0
movq -0x38(%rbp), %rax
movq 0x50(%rax), %rax
movq %rax, -0x48(%rbp)
cmpq $0x0, %rax
je 0x6ad8
movq -0x48(%rbp), %rdi
leaq 0x800e(%rip), %rsi      # 0xead0
leaq 0x8017(%rip), %rdx      # 0xeae0
xorl %eax, %eax
movl %eax, %ecx
callq 0x2110
movq %rax, -0x50(%rbp)
jmp 0x6ae0
xorl %eax, %eax
movq %rax, -0x50(%rbp)
jmp 0x6ae0
movq -0x50(%rbp), %rax
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x6af1
jmp 0x6b10
leaq 0x34cc(%rip), %rdi      # 0x9fc4
leaq 0x2bdb(%rip), %rsi      # 0x96da
movl $0x262, %edx            # imm = 0x262
leaq 0x340f(%rip), %rcx      # 0x9f1a
callq 0x20a0
movq -0x20(%rbp), %rsi
leaq -0x28(%rbp), %rdi
callq 0x6320
leaq -0x28(%rbp), %rdi
callq 0x53c0
movq -0x38(%rbp), %rcx
cmpq %rcx, %rax
jne 0x6b31
jmp 0x6b50
leaq 0x34a5(%rip), %rdi      # 0x9fdd
leaq 0x2b9b(%rip), %rsi      # 0x96da
movl $0x265, %edx            # imm = 0x265
leaq 0x33cf(%rip), %rcx      # 0x9f1a
callq 0x20a0
leaq -0x28(%rbp), %rdi
callq 0x4300
movq -0x38(%rbp), %rax
movq 0x60(%rax), %rcx
addq $-0x1, %rcx
movq %rcx, 0x60(%rax)
movq 0x68(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x68(%rax)
movq 0x50(%rax), %rdi
callq 0x6300
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x50(%rax)
cmpq $0x0, 0x50(%rax)
jne 0x6c02
movq -0x38(%rbp), %rax
cmpq $0x0, 0x30(%rax)
jbe 0x6c02
movq -0x38(%rbp), %rdi
callq 0x6c30
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x6bb9
movq -0x38(%rbp), %rax
movb $0x1, 0x58(%rax)
jmp 0x6c00
movq -0x38(%rbp), %rax
cmpq $0x0, 0x60(%rax)
jne 0x6bc6
jmp 0x6be5
leaq 0x3449(%rip), %rdi      # 0xa016
leaq 0x2b06(%rip), %rsi      # 0x96da
movl $0x277, %edx            # imm = 0x277
leaq 0x333a(%rip), %rcx      # 0x9f1a
callq 0x20a0
movq -0x38(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x5970
testb $0x1, %al
jne 0x6bfe
movq -0x38(%rbp), %rax
movb $0x1, 0x58(%rax)
jmp 0x6c00
jmp 0x6c02
movq -0x20(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x6390
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
nopl (%rax,%rax)