// File: /workspace/github_c_makefile_star2_O0/AlxHnr[P]nano-backup/third-party/CRegion/mempool.c
// Function: CR_DestroyObject
void CR_DestroyObject(void *ptr)
{
  Header *header = (Header *)ptr - 1;
  ASAN_UNPOISON_MEMORY_REGION(header, sizeof(Header));
  CR_Mempool *mp = header->mp;

  if(header->destructor_state == DS_already_called)
  {
    CR_ExitFailure("passed the same object to CR_DestroyObject() twice");
  }
  const bool destructor_enabled = (header->destructor_state == DS_enabled);
  header->destructor_state = DS_already_called;

  /* Call destructor on object. */
  if(destructor_enabled && mp->explicit_destructor != NULL)
  {
    ASAN_POISON_MEMORY_REGION(header, sizeof(Header));
    mp->explicit_destructor(ptr);
    ASAN_UNPOISON_MEMORY_REGION(header, sizeof(Header));
  }

  /* Detach header from allocated chunk list. */
  if(header->prev != NULL)
  {
    ASAN_UNPOISON_MEMORY_REGION(header->prev, sizeof(Header));
    header->prev->next = header->next;
    ASAN_POISON_MEMORY_REGION(header->prev, sizeof(Header));
  }
  if(header->next != NULL)
  {
    ASAN_UNPOISON_MEMORY_REGION(header->next, sizeof(Header));
    header->next->prev = header->prev;
    ASAN_POISON_MEMORY_REGION(header->next, sizeof(Header));
  }
  if(header == mp->allocated_chunks)
  {
    mp->allocated_chunks = mp->allocated_chunks->next;
  }

#ifdef CREGION_ALWAYS_FRESH_MALLOC
  free(header);
#else
  /* Prepend header to released chunk list. */
  header->prev = NULL;
  header->next = mp->released_chunks;
  mp->released_chunks = header;

  if(header->next != NULL)
  {
    ASAN_UNPOISON_MEMORY_REGION(header->next, sizeof(Header));
    header->next->prev = header;
    ASAN_POISON_MEMORY_REGION(header->next, sizeof(Header));
  }
  ASAN_POISON_MEMORY_REGION(mp->released_chunks, mp->chunk_size);
#endif
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $-0x20, %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x2, (%rax)
jne 0x22e4b
leaq 0x22fa(%rip), %rdi      # 0x2513e
movb $0x0, %al
callq 0x4680
movq -0x10(%rbp), %rax
cmpl $0x1, (%rax)
sete %al
andb $0x1, %al
movb %al, -0x19(%rbp)
movq -0x10(%rbp), %rax
movl $0x2, (%rax)
testb $0x1, -0x19(%rbp)
je 0x22e83
movq -0x18(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x22e83
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x8(%rbp), %rdi
callq *%rax
movq -0x10(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x22ea2
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rcx
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq %rcx, 0x18(%rax)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x18(%rax)
je 0x22ec1
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rcx
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq %rcx, 0x10(%rax)
movq -0x10(%rbp), %rax
movq -0x18(%rbp), %rcx
cmpq 0x20(%rcx), %rax
jne 0x22ee3
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movq 0x18(%rax), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x10(%rbp), %rax
movq $0x0, 0x10(%rax)
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x10(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x18(%rax)
je 0x22f26
movq -0x10(%rbp), %rcx
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq %rcx, 0x10(%rax)
addq $0x20, %rsp
popq %rbp
retq
nopl (%rax)