// File: tomfunkhouser[P]gaps/pkgs/jpeg/jmemmgr.c
// Function: alloc_barray
METHODDEF(JBLOCKARRAY)
alloc_barray (j_common_ptr cinfo, int pool_id,
	      JDIMENSION blocksperrow, JDIMENSION numrows)
/* Allocate a 2-D coefficient-block array */
{
  my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  JBLOCKARRAY result;
  JBLOCKROW workspace;
  JDIMENSION rowsperchunk, currow, i;
  long ltemp;

  /* Calculate max # of rows allowed in one allocation chunk */
  ltemp = (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)) /
	  ((long) blocksperrow * SIZEOF(JBLOCK));
  if (ltemp <= 0)
    ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
  if (ltemp < (long) numrows)
    rowsperchunk = (JDIMENSION) ltemp;
  else
    rowsperchunk = numrows;
  mem->last_rowsperchunk = rowsperchunk;

  /* Get space for row pointers (small object) */
  result = (JBLOCKARRAY) alloc_small(cinfo, pool_id,
				     (size_t) (numrows * SIZEOF(JBLOCKROW)));

  /* Get the rows themselves (large objects) */
  currow = 0;
  while (currow < numrows) {
    rowsperchunk = MIN(rowsperchunk, numrows - currow);
    workspace = (JBLOCKROW) alloc_large(cinfo, pool_id,
	(size_t) ((size_t) rowsperchunk * (size_t) blocksperrow
		  * SIZEOF(JBLOCK)));
    for (i = rowsperchunk; i > 0; i--) {
      result[currow++] = workspace;
      workspace += blocksperrow;
    }
  }

  return result;
}

// Assembly:
subq $0x58, %rsp
movq %rdi, 0x50(%rsp)
movl %esi, 0x4c(%rsp)
movl %edx, 0x48(%rsp)
movl %ecx, 0x44(%rsp)
movq 0x50(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x38(%rsp)
movl 0x48(%rsp), %eax
movl %eax, %ecx
shlq $0x7, %rcx
movl $0x3b9ac9e8, %eax       # imm = 0x3B9AC9E8
xorl %edx, %edx
divq %rcx
movq %rax, 0x10(%rsp)
cmpq $0x0, 0x10(%rsp)
jg 0xfa0c5
movq 0x50(%rsp), %rax
movq (%rax), %rax
movl $0x46, 0x28(%rax)
movq 0x50(%rsp), %rax
movq (%rax), %rax
movq (%rax), %rax
movq 0x50(%rsp), %rdi
callq *%rax
movq 0x10(%rsp), %rax
movl 0x44(%rsp), %ecx
cmpq %rcx, %rax
jge 0xfa0de
movq 0x10(%rsp), %rax
movl %eax, 0x24(%rsp)
jmp 0xfa0e6
movl 0x44(%rsp), %eax
movl %eax, 0x24(%rsp)
movl 0x24(%rsp), %ecx
movq 0x38(%rsp), %rax
movl %ecx, 0xa0(%rax)
movq 0x50(%rsp), %rdi
movl 0x4c(%rsp), %esi
movl 0x44(%rsp), %eax
movl %eax, %edx
shlq $0x3, %rdx
callq 0xf9b10
movq %rax, 0x30(%rsp)
movl $0x0, 0x20(%rsp)
movl 0x20(%rsp), %eax
cmpl 0x44(%rsp), %eax
jae 0xfa1d0
movl 0x24(%rsp), %eax
movl 0x44(%rsp), %ecx
subl 0x20(%rsp), %ecx
cmpl %ecx, %eax
jae 0xfa142
movl 0x24(%rsp), %eax
movl %eax, 0xc(%rsp)
jmp 0xfa14e
movl 0x44(%rsp), %eax
subl 0x20(%rsp), %eax
movl %eax, 0xc(%rsp)
movl 0xc(%rsp), %eax
movl %eax, 0x24(%rsp)
movq 0x50(%rsp), %rdi
movl 0x4c(%rsp), %esi
movl 0x24(%rsp), %eax
movl %eax, %edx
movl 0x48(%rsp), %eax
imulq %rax, %rdx
shlq $0x7, %rdx
callq 0xf9d90
movq %rax, 0x28(%rsp)
movl 0x24(%rsp), %eax
movl %eax, 0x1c(%rsp)
cmpl $0x0, 0x1c(%rsp)
jbe 0xfa1cb
movq 0x28(%rsp), %rdx
movq 0x30(%rsp), %rax
movl 0x20(%rsp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, 0x20(%rsp)
movl %ecx, %ecx
movq %rdx, (%rax,%rcx,8)
movl 0x48(%rsp), %ecx
movq 0x28(%rsp), %rax
movl %ecx, %ecx
shlq $0x7, %rcx
addq %rcx, %rax
movq %rax, 0x28(%rsp)
movl 0x1c(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x1c(%rsp)
jmp 0xfa183
jmp 0xfa11a
movq 0x30(%rsp), %rax
addq $0x58, %rsp
retq
nopw (%rax,%rax)