// File: /workspace/github_cpp_makefile_star2_O2/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 0x79e7b
movq (%rbx), %rax
movl $0xe, 0x28(%rax)
movl %ebp, 0x2c(%rax)
movq (%rbx), %rax
movq %rbx, %rdi
callq *(%rax)
jmp 0x79eec
cmpl $0x1, %ebp
jne 0x79eec
leaq 0x88(%r15), %r14
movq (%r14), %r14
testq %r14, %r14
je 0x79eac
cmpl $0x0, 0x2c(%r14)
je 0x79ea6
andl $0x0, 0x2c(%r14)
leaq 0x38(%r14), %rsi
movq %rbx, %rdi
callq *0x48(%r14)
addq $0x30, %r14
jmp 0x79e87
andq $0x0, 0x88(%r15)
leaq 0x90(%r15), %r14
movq %r14, %r12
movq (%r12), %r12
testq %r12, %r12
je 0x79ee8
cmpl $0x0, 0x2c(%r12)
je 0x79ee2
andl $0x0, 0x2c(%r12)
leaq 0x38(%r12), %rsi
movq %rbx, %rdi
callq *0x48(%r12)
addq $0x30, %r12
jmp 0x79ebe
andq $0x0, (%r14)
movslq %ebp, %r12
movq 0x78(%r15,%r12,8), %rsi
andq $0x0, 0x78(%r15,%r12,8)
testq %rsi, %rsi
je 0x79f29
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 0x7a128
subq %r14, 0x98(%r15)
movq %r13, %rsi
jmp 0x79efa
movq 0x68(%r15,%r12,8), %rsi
andq $0x0, 0x68(%r15,%r12,8)
testq %rsi, %rsi
je 0x79f63
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 0x7a118
subq %r14, 0x98(%r15)
movq %r12, %rsi
jmp 0x79f34
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq