// File: tomfunkhouser[P]gaps/pkgs/jpeg/jdmainct.c
// Function: make_funny_pointers
LOCAL(void)
make_funny_pointers (j_decompress_ptr cinfo)
/* Create the funny pointer lists discussed in the comments above.
 * The actual workspace is already allocated (in mainp->buffer),
 * and the space for the pointer lists is allocated too.
 * This routine just fills in the curiously ordered lists.
 * This will be repeated at the beginning of each pass.
 */
{
  my_main_ptr mainp = (my_main_ptr) cinfo->main;
  int ci, i, rgroup;
  int M = cinfo->min_DCT_scaled_size;
  jpeg_component_info *compptr;
  JSAMPARRAY buf, xbuf0, xbuf1;

  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
       ci++, compptr++) {
    rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
      cinfo->min_DCT_scaled_size; /* height of a row group of component */
    xbuf0 = mainp->xbuffer[0][ci];
    xbuf1 = mainp->xbuffer[1][ci];
    /* First copy the workspace pointers as-is */
    buf = mainp->buffer[ci];
    for (i = 0; i < rgroup * (M + 2); i++) {
      xbuf0[i] = xbuf1[i] = buf[i];
    }
    /* In the second list, put the last four row groups in swapped order */
    for (i = 0; i < rgroup * 2; i++) {
      xbuf1[rgroup*(M-2) + i] = buf[rgroup*M + i];
      xbuf1[rgroup*M + i] = buf[rgroup*(M-2) + i];
    }
    /* The wraparound pointers at top and bottom will be filled later
     * (see set_wraparound_pointers, below).  Initially we want the "above"
     * pointers to duplicate the first actual data line.  This only needs
     * to happen in xbuffer[0].
     */
    for (i = 0; i < rgroup; i++) {
      xbuf0[i - rgroup] = xbuf0[0];
    }
  }
}

// Assembly:
movq %rdi, -0x8(%rsp)
movq -0x8(%rsp), %rax
movq 0x228(%rax), %rax
movq %rax, -0x10(%rsp)
movq -0x8(%rsp), %rax
movl 0x1a0(%rax), %eax
movl %eax, -0x20(%rsp)
movl $0x0, -0x14(%rsp)
movq -0x8(%rsp), %rax
movq 0x130(%rax), %rax
movq %rax, -0x28(%rsp)
movl -0x14(%rsp), %eax
movq -0x8(%rsp), %rcx
cmpl 0x38(%rcx), %eax
jge 0xeccc7
movq -0x28(%rsp), %rax
movl 0xc(%rax), %eax
movq -0x28(%rsp), %rcx
imull 0x24(%rcx), %eax
movq -0x8(%rsp), %rcx
cltd
idivl 0x1a0(%rcx)
movl %eax, -0x1c(%rsp)
movq -0x10(%rsp), %rax
movq 0x68(%rax), %rax
movslq -0x14(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x38(%rsp)
movq -0x10(%rsp), %rax
movq 0x70(%rax), %rax
movslq -0x14(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x40(%rsp)
movq -0x10(%rsp), %rax
movslq -0x14(%rsp), %rcx
movq 0x10(%rax,%rcx,8), %rax
movq %rax, -0x30(%rsp)
movl $0x0, -0x18(%rsp)
movl -0x18(%rsp), %eax
movl -0x1c(%rsp), %ecx
movl -0x20(%rsp), %edx
addl $0x2, %edx
imull %edx, %ecx
cmpl %ecx, %eax
jge 0xecbd8
movq -0x30(%rsp), %rax
movslq -0x18(%rsp), %rcx
movq (%rax,%rcx,8), %rdx
movq -0x40(%rsp), %rax
movslq -0x18(%rsp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x38(%rsp), %rax
movslq -0x18(%rsp), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x18(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rsp)
jmp 0xecb8b
movl $0x0, -0x18(%rsp)
movl -0x18(%rsp), %eax
movl -0x1c(%rsp), %ecx
shll %ecx
cmpl %ecx, %eax
jge 0xecc6c
movq -0x30(%rsp), %rax
movl -0x1c(%rsp), %ecx
imull -0x20(%rsp), %ecx
addl -0x18(%rsp), %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdx
movq -0x40(%rsp), %rax
movl -0x1c(%rsp), %ecx
movl -0x20(%rsp), %esi
subl $0x2, %esi
imull %esi, %ecx
addl -0x18(%rsp), %ecx
movslq %ecx, %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x30(%rsp), %rax
movl -0x1c(%rsp), %ecx
movl -0x20(%rsp), %edx
subl $0x2, %edx
imull %edx, %ecx
addl -0x18(%rsp), %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdx
movq -0x40(%rsp), %rax
movl -0x1c(%rsp), %ecx
imull -0x20(%rsp), %ecx
addl -0x18(%rsp), %ecx
movslq %ecx, %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x18(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rsp)
jmp 0xecbe0
movl $0x0, -0x18(%rsp)
movl -0x18(%rsp), %eax
cmpl -0x1c(%rsp), %eax
jge 0xecca7
movq -0x38(%rsp), %rax
movq (%rax), %rdx
movq -0x38(%rsp), %rax
movl -0x18(%rsp), %ecx
subl -0x1c(%rsp), %ecx
movslq %ecx, %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x18(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rsp)
jmp 0xecc74
jmp 0xecca9
movl -0x14(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rsp)
movq -0x28(%rsp), %rax
addq $0x60, %rax
movq %rax, -0x28(%rsp)
jmp 0xecb0e
retq
nopl (%rax,%rax)