// File: /workspace/github_cpp_makefile_star2_O2/tomfunkhouser[P]gaps/pkgs/jpeg/jmemmgr.c
// Function: realize_virt_arrays
METHODDEF(void)
realize_virt_arrays (j_common_ptr cinfo)
/* Allocate the in-memory buffers for any unrealized virtual arrays */
{
  my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  long space_per_minheight, maximum_space, avail_mem;
  long minheights, max_minheights;
  jvirt_sarray_ptr sptr;
  jvirt_barray_ptr bptr;

  /* Compute the minimum space needed (maxaccess rows in each buffer)
   * and the maximum space needed (full image height in each buffer).
   * These may be of use to the system-dependent jpeg_mem_available routine.
   */
  space_per_minheight = 0;
  maximum_space = 0;
  for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
    if (sptr->mem_buffer == NULL) { /* if not realized yet */
      space_per_minheight += (long) sptr->maxaccess *
			     (long) sptr->samplesperrow * SIZEOF(JSAMPLE);
      maximum_space += (long) sptr->rows_in_array *
		       (long) sptr->samplesperrow * SIZEOF(JSAMPLE);
    }
  }
  for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
    if (bptr->mem_buffer == NULL) { /* if not realized yet */
      space_per_minheight += (long) bptr->maxaccess *
			     (long) bptr->blocksperrow * SIZEOF(JBLOCK);
      maximum_space += (long) bptr->rows_in_array *
		       (long) bptr->blocksperrow * SIZEOF(JBLOCK);
    }
  }

  if (space_per_minheight <= 0)
    return;			/* no unrealized arrays, no work */

  /* Determine amount of memory to actually use; this is system-dependent. */
  avail_mem = jpeg_mem_available(cinfo, space_per_minheight, maximum_space,
				 mem->total_space_allocated);

  /* If the maximum space needed is available, make all the buffers full
   * height; otherwise parcel it out with the same number of minheights
   * in each buffer.
   */
  if (avail_mem >= maximum_space)
    max_minheights = 1000000000L;
  else {
    max_minheights = avail_mem / space_per_minheight;
    /* If there doesn't seem to be enough space, try to get the minimum
     * anyway.  This allows a "stub" implementation of jpeg_mem_available().
     */
    if (max_minheights <= 0)
      max_minheights = 1;
  }

  /* Allocate the in-memory buffers and initialize backing store as needed. */

  for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
    if (sptr->mem_buffer == NULL) { /* if not realized yet */
      minheights = ((long) sptr->rows_in_array - 1L) / sptr->maxaccess + 1L;
      if (minheights <= max_minheights) {
	/* This buffer fits in memory */
	sptr->rows_in_mem = sptr->rows_in_array;
      } else {
	/* It doesn't fit in memory, create backing store. */
	sptr->rows_in_mem = (JDIMENSION) (max_minheights * sptr->maxaccess);
	jpeg_open_backing_store(cinfo, & sptr->b_s_info,
				(long) sptr->rows_in_array *
				(long) sptr->samplesperrow *
				(long) SIZEOF(JSAMPLE));
	sptr->b_s_open = TRUE;
      }
      sptr->mem_buffer = alloc_sarray(cinfo, JPOOL_IMAGE,
				      sptr->samplesperrow, sptr->rows_in_mem);
      sptr->rowsperchunk = mem->last_rowsperchunk;
      sptr->cur_start_row = 0;
      sptr->first_undef_row = 0;
      sptr->dirty = FALSE;
    }
  }

  for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
    if (bptr->mem_buffer == NULL) { /* if not realized yet */
      minheights = ((long) bptr->rows_in_array - 1L) / bptr->maxaccess + 1L;
      if (minheights <= max_minheights) {
	/* This buffer fits in memory */
	bptr->rows_in_mem = bptr->rows_in_array;
      } else {
	/* It doesn't fit in memory, create backing store. */
	bptr->rows_in_mem = (JDIMENSION) (max_minheights * bptr->maxaccess);
	jpeg_open_backing_store(cinfo, & bptr->b_s_info,
				(long) bptr->rows_in_array *
				(long) bptr->blocksperrow *
				(long) SIZEOF(JBLOCK));
	bptr->b_s_open = TRUE;
      }
      bptr->mem_buffer = alloc_barray(cinfo, JPOOL_IMAGE,
				      bptr->blocksperrow, bptr->rows_in_mem);
      bptr->rowsperchunk = mem->last_rowsperchunk;
      bptr->cur_start_row = 0;
      bptr->first_undef_row = 0;
      bptr->dirty = FALSE;
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0x8(%rdi), %rax
movq %rax, (%rsp)
leaq 0x88(%rax), %rbp
xorl %r15d, %r15d
xorl %r14d, %r14d
movq %rbp, %rax
movq (%rax), %rax
testq %rax, %rax
je 0x79a06
cmpq $0x0, (%rax)
jne 0x79a00
movl 0x10(%rax), %ecx
movl 0x8(%rax), %edx
movl 0xc(%rax), %esi
imulq %rsi, %rcx
addq %rcx, %r14
imulq %rsi, %rdx
addq %rdx, %r15
addq $0x30, %rax
jmp 0x799db
movq (%rsp), %rax
leaq 0x90(%rax), %r13
movq %r13, %rax
movq (%rax), %rax
testq %rax, %rax
je 0x79a47
cmpq $0x0, (%rax)
jne 0x79a41
movl 0x10(%rax), %ecx
movl 0x8(%rax), %edx
movl 0xc(%rax), %esi
imulq %rsi, %rcx
shlq $0x7, %rcx
addq %rcx, %r14
imulq %rsi, %rdx
shlq $0x7, %rdx
addq %rdx, %r15
addq $0x30, %rax
jmp 0x79a14
testq %r14, %r14
jle 0x79b96
movq (%rsp), %rax
movq 0x98(%rax), %rcx
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x7a130
movl $0x3b9aca00, %r12d      # imm = 0x3B9ACA00
cmpq %r15, %rax
jge 0x79a85
cqto
idivq %r14
cmpq $0x2, %rax
pushq $0x1
popq %r12
cmovgeq %rax, %r12
pushq $0x1
popq %r14
movq (%rbp), %rbp
testq %rbp, %rbp
je 0x79b04
cmpq $0x0, (%rbp)
jne 0x79afe
movl 0x8(%rbp), %ecx
movl 0x10(%rbp), %esi
leaq -0x1(%rcx), %rax
cqto
idivq %rsi
cmpq %r12, %rax
jge 0x79ab2
movl %ecx, 0x14(%rbp)
jmp 0x79ad6
imull %r12d, %esi
movl %esi, 0x14(%rbp)
leaq 0x38(%rbp), %rsi
movl 0xc(%rbp), %edx
imulq %rcx, %rdx
movq %rbx, %rdi
callq 0x7a134
movl $0x1, 0x2c(%rbp)
movl 0x14(%rbp), %ecx
movl 0xc(%rbp), %edx
movq %rbx, %rdi
movl %r14d, %esi
callq 0x79726
movq %rax, (%rbp)
movq (%rsp), %rax
movl 0xa0(%rax), %eax
movl %eax, 0x18(%rbp)
andq $0x0, 0x1c(%rbp)
andl $0x0, 0x28(%rbp)
addq $0x30, %rbp
jmp 0x79a89
pushq $0x1
popq %rbp
movq (%r13), %r13
testq %r13, %r13
je 0x79b96
cmpq $0x0, (%r13)
jne 0x79b8d
movl 0x8(%r13), %ecx
movl 0x10(%r13), %esi
leaq -0x1(%rcx), %rax
cqto
idivq %rsi
cmpq %r12, %rax
jge 0x79b37
movl %ecx, 0x14(%r13)
jmp 0x79b63
imull %r12d, %esi
movl %esi, 0x14(%r13)
leaq 0x38(%r13), %rsi
movl 0xc(%r13), %edx
imulq %rcx, %rdx
shlq $0x7, %rdx
movq %rbx, %rdi
callq 0x7a134
movl $0x1, 0x2c(%r13)
movl 0x14(%r13), %ecx
movl 0xc(%r13), %edx
movq %rbx, %rdi
movl %ebp, %esi
callq 0x797e3
movq %rax, (%r13)
movq (%rsp), %rax
movl 0xa0(%rax), %eax
movl %eax, 0x18(%r13)
andq $0x0, 0x1c(%r13)
andl $0x0, 0x28(%r13)
addq $0x30, %r13
jmp 0x79b07
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq