// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/jpeg/jmemmgr.c
// Function: free_pool
METHODDEF(void)
free_pool (j_common_ptr cinfo, int pool_id)
{
  my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  small_pool_ptr shdr_ptr;
  large_pool_ptr lhdr_ptr;
  size_t space_freed;

  if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
    ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id);	/* safety check */

#ifdef MEM_STATS
  if (cinfo->err->trace_level > 1)
    print_mem_stats(cinfo, pool_id); /* print pool's memory usage statistics */
#endif

  /* If freeing IMAGE pool, close any virtual arrays first */
  if (pool_id == JPOOL_IMAGE) {
    jvirt_sarray_ptr sptr;
    jvirt_barray_ptr bptr;

    for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
      if (sptr->b_s_open) {	/* there may be no backing store */
	sptr->b_s_open = FALSE;	/* prevent recursive close if error */
	(*sptr->b_s_info.close_backing_store) (cinfo, & sptr->b_s_info);
      }
    }
    mem->virt_sarray_list = NULL;
    for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
      if (bptr->b_s_open) {	/* there may be no backing store */
	bptr->b_s_open = FALSE;	/* prevent recursive close if error */
	(*bptr->b_s_info.close_backing_store) (cinfo, & bptr->b_s_info);
      }
    }
    mem->virt_barray_list = NULL;
  }

  /* Release large objects */
  lhdr_ptr = mem->large_list[pool_id];
  mem->large_list[pool_id] = NULL;

  while (lhdr_ptr != NULL) {
    large_pool_ptr next_lhdr_ptr = lhdr_ptr->hdr.next;
    space_freed = lhdr_ptr->hdr.bytes_used +
		  lhdr_ptr->hdr.bytes_left +
		  SIZEOF(large_pool_hdr);
    jpeg_free_large(cinfo, (void FAR *) lhdr_ptr, space_freed);
    mem->total_space_allocated -= space_freed;
    lhdr_ptr = next_lhdr_ptr;
  }

  /* Release small objects */
  shdr_ptr = mem->small_list[pool_id];
  mem->small_list[pool_id] = NULL;

  while (shdr_ptr != NULL) {
    small_pool_ptr next_shdr_ptr = shdr_ptr->hdr.next;
    space_freed = shdr_ptr->hdr.bytes_used +
		  shdr_ptr->hdr.bytes_left +
		  SIZEOF(small_pool_hdr);
    jpeg_free_small(cinfo, (void *) shdr_ptr, space_freed);
    mem->total_space_allocated -= space_freed;
    shdr_ptr = next_shdr_ptr;
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %esi, %ebp
movq %rdi, %rbx
movq 0x8(%rdi), %r15
cmpl $0x2, %esi
jb 0x869e3
movq (%rbx), %rax
movl $0xe, 0x28(%rax)
movl %ebp, 0x2c(%rax)
movq (%rbx), %rax
movq %rbx, %rdi
callq *(%rax)
jmp 0x86a56
cmpl $0x1, %ebp
jne 0x86a56
movq 0x88(%r15), %r14
testq %r14, %r14
je 0x86a14
cmpl $0x0, 0x2c(%r14)
je 0x86a0e
movl $0x0, 0x2c(%r14)
leaq 0x38(%r14), %rsi
movq %rbx, %rdi
callq *0x48(%r14)
movq 0x30(%r14), %r14
jmp 0x869ef
movq $0x0, 0x88(%r15)
movq 0x90(%r15), %r14
testq %r14, %r14
je 0x86a4b
cmpl $0x0, 0x2c(%r14)
je 0x86a45
movl $0x0, 0x2c(%r14)
leaq 0x38(%r14), %rsi
movq %rbx, %rdi
callq *0x48(%r14)
movq 0x30(%r14), %r14
jmp 0x86a26
movq $0x0, 0x90(%r15)
movslq %ebp, %r12
movq 0x78(%r15,%r12,8), %rsi
movq $0x0, 0x78(%r15,%r12,8)
testq %rsi, %rsi
je 0x86a99
movq (%rsi), %r13
movq 0x8(%rsi), %rax
movq 0x10(%rsi), %rcx
leaq (%rax,%rcx), %r14
addq $0x18, %r14
movq %rbx, %rdi
movq %r14, %rdx
callq 0x86cc0
subq %r14, 0x98(%r15)
movq %r13, %rsi
testq %r13, %r13
jne 0x86a6c
movq 0x68(%r15,%r12,8), %rsi
movq $0x0, 0x68(%r15,%r12,8)
testq %rsi, %rsi
je 0x86ad9
movq (%rsi), %r12
movq 0x8(%rsi), %rax
movq 0x10(%rsi), %rcx
leaq (%rax,%rcx), %r14
addq $0x18, %r14
movq %rbx, %rdi
movq %r14, %rdx
callq 0x86cb0
subq %r14, 0x98(%r15)
movq %r12, %rsi
testq %r12, %r12
jne 0x86aac
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq