// File: /workspace/github_cpp_makefile_star2_O2/tomfunkhouser[P]gaps/pkgs/jpeg/jmemmgr.c
// Function: access_virt_sarray
METHODDEF(JSAMPARRAY)
access_virt_sarray (j_common_ptr cinfo, jvirt_sarray_ptr ptr,
		    JDIMENSION start_row, JDIMENSION num_rows,
		    jboolean writable)
/* Access the part of a virtual sample array starting at start_row */
/* and extending for num_rows rows.  writable is true if  */
/* caller intends to modify the accessed area. */
{
  JDIMENSION end_row = start_row + num_rows;
  JDIMENSION undef_row;

  /* debugging check */
  if (end_row > ptr->rows_in_array || num_rows > ptr->maxaccess ||
      ptr->mem_buffer == NULL)
    ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);

  /* Make the desired part of the virtual array accessible */
  if (start_row < ptr->cur_start_row ||
      end_row > ptr->cur_start_row+ptr->rows_in_mem) {
    if (! ptr->b_s_open)
      ERREXIT(cinfo, JERR_VIRTUAL_BUG);
    /* Flush old buffer contents if necessary */
    if (ptr->dirty) {
      do_sarray_io(cinfo, ptr, TRUE);
      ptr->dirty = FALSE;
    }
    /* Decide what part of virtual array to access.
     * Algorithm: if target address > current window, assume forward scan,
     * load starting at target address.  If target address < current window,
     * assume backward scan, load so that target area is top of window.
     * Note that when switching from forward write to forward read, will have
     * start_row = 0, so the limiting case applies and we load from 0 anyway.
     */
    if (start_row > ptr->cur_start_row) {
      ptr->cur_start_row = start_row;
    } else {
      /* use long arithmetic here to avoid overflow & unsigned problems */
      long ltemp;

      ltemp = (long) end_row - (long) ptr->rows_in_mem;
      if (ltemp < 0)
	ltemp = 0;		/* don't fall off front end of file */
      ptr->cur_start_row = (JDIMENSION) ltemp;
    }
    /* Read in the selected part of the array.
     * During the initial write pass, we will do no actual read
     * because the selected part is all undefined.
     */
    do_sarray_io(cinfo, ptr, FALSE);
  }
  /* Ensure the accessed part of the array is defined; prezero if needed.
   * To improve locality of access, we only prezero the part of the array
   * that the caller is about to access, not the entire in-memory array.
   */
  if (ptr->first_undef_row < end_row) {
    if (ptr->first_undef_row < start_row) {
      if (writable)		/* writer skipped over a section of array */
	ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
      undef_row = start_row;	/* but reader is allowed to read ahead */
    } else {
      undef_row = ptr->first_undef_row;
    }
    if (writable)
      ptr->first_undef_row = end_row;
    if (ptr->pre_zero) {
      size_t bytesperrow = (size_t) ptr->samplesperrow * SIZEOF(JSAMPLE);
      undef_row -= ptr->cur_start_row; /* make indexes relative to buffer */
      end_row -= ptr->cur_start_row;
      while (undef_row < end_row) {
	jzero_far((void FAR *) ptr->mem_buffer[undef_row], bytesperrow);
	undef_row++;
      }
    } else {
      if (! writable)		/* reader looking at undefined data */
	ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
    }
  }
  /* Flag the buffer dirty if caller will write in it */
  if (writable)
    ptr->dirty = TRUE;
  /* Return address of proper part of the buffer */
  return ptr->mem_buffer + (start_row - ptr->cur_start_row);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %r8d, %ebp
movl %edx, %ebx
movq %rsi, %r14
movq %rdi, %r15
leal (%rcx,%rbx), %r12d
cmpl 0x8(%rsi), %r12d
ja 0x79bd1
cmpl %ecx, 0x10(%r14)
jb 0x79bd1
cmpq $0x0, (%r14)
jne 0x79be0
movq (%r15), %rax
movl $0x16, 0x28(%rax)
movq %r15, %rdi
callq *(%rax)
movl 0x1c(%r14), %eax
cmpl %ebx, %eax
ja 0x79bf1
addl 0x14(%r14), %eax
cmpl %eax, %r12d
jbe 0x79c4d
cmpl $0x0, 0x2c(%r14)
jne 0x79c07
movq (%r15), %rax
movl $0x45, 0x28(%rax)
movq %r15, %rdi
callq *(%rax)
cmpl $0x0, 0x28(%r14)
je 0x79c21
pushq $0x1
popq %rdx
movq %r15, %rdi
movq %r14, %rsi
callq 0x79fb1
andl $0x0, 0x28(%r14)
movl %ebx, %eax
cmpl %ebx, 0x1c(%r14)
jb 0x79c3c
movl %r12d, %ecx
movl 0x14(%r14), %eax
subq %rax, %rcx
xorl %eax, %eax
testq %rcx, %rcx
cmovgq %rcx, %rax
movl %eax, 0x1c(%r14)
movq %r15, %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x79fb1
movl 0x20(%r14), %r13d
cmpl %r12d, %r13d
jae 0x79cb5
cmpl %ebx, %r13d
jae 0x79c73
testl %ebp, %ebp
je 0x79c84
movq (%r15), %rax
movl $0x16, 0x28(%rax)
movq %r15, %rdi
callq *(%rax)
movl %ebx, %r13d
jmp 0x79c77
testl %ebp, %ebp
je 0x79cde
movl %r12d, 0x20(%r14)
cmpl $0x0, 0x24(%r14)
jne 0x79c8e
jmp 0x79cb9
cmpl $0x0, 0x24(%r14)
movl %ebx, %r13d
je 0x79ce5
movl 0xc(%r14), %r15d
movl 0x1c(%r14), %eax
subl %eax, %r13d
subl %eax, %r12d
cmpq %r12, %r13
jae 0x79cb5
movq (%r14), %rax
movq (%rax,%r13,8), %rdi
movq %r15, %rsi
callq 0x791cd
incq %r13
jmp 0x79c9c
testl %ebp, %ebp
je 0x79cc1
movl $0x1, 0x28(%r14)
subl 0x1c(%r14), %ebx
shlq $0x3, %rbx
addq (%r14), %rbx
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x0, 0x24(%r14)
jne 0x79c8e
movq (%r15), %rax
movl $0x16, 0x28(%rax)
movq %r15, %rdi
callq *(%rax)
jmp 0x79cc1