// File: tomfunkhouser[P]gaps/pkgs/jpeg/jmemmgr.c
// Function: do_sarray_io
LOCAL(void)
do_sarray_io (j_common_ptr cinfo, jvirt_sarray_ptr ptr, jboolean writing)
/* Do backing store read or write of a virtual sample array */
{
  long bytesperrow, file_offset, byte_count, rows, thisrow, i;

  bytesperrow = (long) ptr->samplesperrow * SIZEOF(JSAMPLE);
  file_offset = ptr->cur_start_row * bytesperrow;
  /* Loop to read or write each allocation chunk in mem_buffer */
  for (i = 0; i < (long) ptr->rows_in_mem; i += ptr->rowsperchunk) {
    /* One chunk, but check for short chunk at end of buffer */
    rows = MIN((long) ptr->rowsperchunk, (long) ptr->rows_in_mem - i);
    /* Transfer no more than is currently defined */
    thisrow = (long) ptr->cur_start_row + i;
    rows = MIN(rows, (long) ptr->first_undef_row - thisrow);
    /* Transfer no more than fits in file */
    rows = MIN(rows, (long) ptr->rows_in_array - thisrow);
    if (rows <= 0)		/* this chunk might be past end of file! */
      break;
    byte_count = rows * bytesperrow;
    if (writing)
      (*ptr->b_s_info.write_backing_store) (cinfo, & ptr->b_s_info,
					    (void FAR *) ptr->mem_buffer[i],
					    file_offset, byte_count);
    else
      (*ptr->b_s_info.read_backing_store) (cinfo, & ptr->b_s_info,
					   (void FAR *) ptr->mem_buffer[i],
					   file_offset, byte_count);
    file_offset += byte_count;
  }
}

// Assembly:
subq $0x68, %rsp
movq %rdi, 0x60(%rsp)
movq %rsi, 0x58(%rsp)
movl %edx, 0x54(%rsp)
movq 0x58(%rsp), %rax
movl 0xc(%rax), %eax
shlq $0x0, %rax
movq %rax, 0x48(%rsp)
movq 0x58(%rsp), %rax
movl 0x1c(%rax), %eax
imulq 0x48(%rsp), %rax
movq %rax, 0x40(%rsp)
movq $0x0, 0x20(%rsp)
movq 0x20(%rsp), %rax
movq 0x58(%rsp), %rcx
movl 0x14(%rcx), %ecx
cmpq %rcx, %rax
jge 0xfb20e
movq 0x58(%rsp), %rax
movl 0x18(%rax), %eax
movq 0x58(%rsp), %rcx
movl 0x14(%rcx), %ecx
subq 0x20(%rsp), %rcx
cmpq %rcx, %rax
jge 0xfb0ae
movq 0x58(%rsp), %rax
movl 0x18(%rax), %eax
movq %rax, 0x18(%rsp)
jmp 0xfb0c0
movq 0x58(%rsp), %rax
movl 0x14(%rax), %eax
subq 0x20(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x18(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0x58(%rsp), %rax
movl 0x1c(%rax), %eax
addq 0x20(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0x30(%rsp), %rax
movq 0x58(%rsp), %rcx
movl 0x20(%rcx), %ecx
subq 0x28(%rsp), %rcx
cmpq %rcx, %rax
jge 0xfb0ff
movq 0x30(%rsp), %rax
movq %rax, 0x10(%rsp)
jmp 0xfb111
movq 0x58(%rsp), %rax
movl 0x20(%rax), %eax
subq 0x28(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x10(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0x30(%rsp), %rax
movq 0x58(%rsp), %rcx
movl 0x8(%rcx), %ecx
subq 0x28(%rsp), %rcx
cmpq %rcx, %rax
jge 0xfb13e
movq 0x30(%rsp), %rax
movq %rax, 0x8(%rsp)
jmp 0xfb150
movq 0x58(%rsp), %rax
movl 0x8(%rax), %eax
subq 0x28(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x8(%rsp), %rax
movq %rax, 0x30(%rsp)
cmpq $0x0, 0x30(%rsp)
jg 0xfb167
jmp 0xfb20e
movq 0x30(%rsp), %rax
imulq 0x48(%rsp), %rax
movq %rax, 0x38(%rsp)
cmpl $0x0, 0x54(%rsp)
je 0xfb1b4
movq 0x58(%rsp), %rax
movq 0x40(%rax), %rax
movq 0x60(%rsp), %rdi
movq 0x58(%rsp), %rsi
addq $0x38, %rsi
movq 0x58(%rsp), %rcx
movq (%rcx), %rcx
movq 0x20(%rsp), %rdx
movq (%rcx,%rdx,8), %rdx
movq 0x40(%rsp), %rcx
movq 0x38(%rsp), %r8
callq *%rax
jmp 0xfb1e8
movq 0x58(%rsp), %rax
movq 0x38(%rax), %rax
movq 0x60(%rsp), %rdi
movq 0x58(%rsp), %rsi
addq $0x38, %rsi
movq 0x58(%rsp), %rcx
movq (%rcx), %rcx
movq 0x20(%rsp), %rdx
movq (%rcx,%rdx,8), %rdx
movq 0x40(%rsp), %rcx
movq 0x38(%rsp), %r8
callq *%rax
movq 0x38(%rsp), %rax
addq 0x40(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0x58(%rsp), %rax
movl 0x18(%rax), %eax
addq 0x20(%rsp), %rax
movq %rax, 0x20(%rsp)
jmp 0xfb06f
addq $0x68, %rsp
retq
nopw %cs:(%rax,%rax)