// File: tomfunkhouser[P]gaps/pkgs/png/pngrtran.c
// Function: png_do_read_intrapixel
void /* PRIVATE */
png_do_read_intrapixel(png_row_infop row_info, png_bytep row)
{
   png_debug(1, "in png_do_read_intrapixel");

   if (
       (row_info->color_type & PNG_COLOR_MASK_COLOR))
   {
      int bytes_per_pixel;
      png_uint_32 row_width = row_info->width;
      if (row_info->bit_depth == 8)
      {
         png_bytep rp;
         png_uint_32 i;

         if (row_info->color_type == PNG_COLOR_TYPE_RGB)
            bytes_per_pixel = 3;

         else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
            bytes_per_pixel = 4;

         else
            return;

         for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
         {
            *(rp) = (png_byte)((256 + *rp + *(rp+1))&0xff);
            *(rp+2) = (png_byte)((256 + *(rp+2) + *(rp+1))&0xff);
         }
      }
      else if (row_info->bit_depth == 16)
      {
         png_bytep rp;
         png_uint_32 i;

         if (row_info->color_type == PNG_COLOR_TYPE_RGB)
            bytes_per_pixel = 6;

         else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
            bytes_per_pixel = 8;

         else
            return;

         for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
         {
            png_uint_32 s0   = (*(rp    ) << 8) | *(rp + 1);
            png_uint_32 s1   = (*(rp + 2) << 8) | *(rp + 3);
            png_uint_32 s2   = (*(rp + 4) << 8) | *(rp + 5);
            png_uint_32 red  = (png_uint_32)((s0 + s1 + 65536L) & 0xffffL);
            png_uint_32 blue = (png_uint_32)((s2 + s1 + 65536L) & 0xffffL);
            *(rp  ) = (png_byte)((red >> 8) & 0xff);
            *(rp+1) = (png_byte)(red & 0xff);
            *(rp+4) = (png_byte)((blue >> 8) & 0xff);
            *(rp+5) = (png_byte)(blue & 0xff);
         }
      }
   }
}

// Assembly:
movq %rdi, -0x8(%rsp)
movq %rsi, -0x10(%rsp)
movq -0x8(%rsp), %rax
movzbl 0x10(%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x111f0b
movq -0x8(%rsp), %rax
movl (%rax), %eax
movl %eax, -0x18(%rsp)
movq -0x8(%rsp), %rax
movzbl 0x11(%rax), %eax
cmpl $0x8, %eax
jne 0x111da3
movq -0x8(%rsp), %rax
movzbl 0x10(%rax), %eax
cmpl $0x2, %eax
jne 0x111cf4
movl $0x3, -0x14(%rsp)
jmp 0x111d13
movq -0x8(%rsp), %rax
movzbl 0x10(%rax), %eax
cmpl $0x6, %eax
jne 0x111d0c
movl $0x4, -0x14(%rsp)
jmp 0x111d11
jmp 0x111f0b
jmp 0x111d13
movl $0x0, -0x24(%rsp)
movq -0x10(%rsp), %rax
movq %rax, -0x20(%rsp)
movl -0x24(%rsp), %eax
cmpl -0x18(%rsp), %eax
jae 0x111d9e
movq -0x20(%rsp), %rax
movzbl (%rax), %eax
addl $0x100, %eax            # imm = 0x100
movq -0x20(%rsp), %rcx
movzbl 0x1(%rcx), %ecx
addl %ecx, %eax
andl $0xff, %eax
movb %al, %cl
movq -0x20(%rsp), %rax
movb %cl, (%rax)
movq -0x20(%rsp), %rax
movzbl 0x2(%rax), %eax
addl $0x100, %eax            # imm = 0x100
movq -0x20(%rsp), %rcx
movzbl 0x1(%rcx), %ecx
addl %ecx, %eax
andl $0xff, %eax
movb %al, %cl
movq -0x20(%rsp), %rax
movb %cl, 0x2(%rax)
movl -0x24(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rsp)
movl -0x14(%rsp), %ecx
movq -0x20(%rsp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x20(%rsp)
jmp 0x111d25
jmp 0x111f09
movq -0x8(%rsp), %rax
movzbl 0x11(%rax), %eax
cmpl $0x10, %eax
jne 0x111f07
movq -0x8(%rsp), %rax
movzbl 0x10(%rax), %eax
cmpl $0x2, %eax
jne 0x111dcd
movl $0x6, -0x14(%rsp)
jmp 0x111dec
movq -0x8(%rsp), %rax
movzbl 0x10(%rax), %eax
cmpl $0x6, %eax
jne 0x111de5
movl $0x8, -0x14(%rsp)
jmp 0x111dea
jmp 0x111f0b
jmp 0x111dec
movl $0x0, -0x34(%rsp)
movq -0x10(%rsp), %rax
movq %rax, -0x30(%rsp)
movl -0x34(%rsp), %eax
cmpl -0x18(%rsp), %eax
jae 0x111f05
movq -0x30(%rsp), %rax
movzbl (%rax), %eax
shll $0x8, %eax
movq -0x30(%rsp), %rcx
movzbl 0x1(%rcx), %ecx
orl %ecx, %eax
movl %eax, -0x38(%rsp)
movq -0x30(%rsp), %rax
movzbl 0x2(%rax), %eax
shll $0x8, %eax
movq -0x30(%rsp), %rcx
movzbl 0x3(%rcx), %ecx
orl %ecx, %eax
movl %eax, -0x3c(%rsp)
movq -0x30(%rsp), %rax
movzbl 0x4(%rax), %eax
shll $0x8, %eax
movq -0x30(%rsp), %rcx
movzbl 0x5(%rcx), %ecx
orl %ecx, %eax
movl %eax, -0x40(%rsp)
movl -0x38(%rsp), %eax
addl -0x3c(%rsp), %eax
movl %eax, %eax
addq $0x10000, %rax          # imm = 0x10000
andq $0xffff, %rax           # imm = 0xFFFF
movl %eax, -0x44(%rsp)
movl -0x40(%rsp), %eax
addl -0x3c(%rsp), %eax
movl %eax, %eax
addq $0x10000, %rax          # imm = 0x10000
andq $0xffff, %rax           # imm = 0xFFFF
movl %eax, -0x48(%rsp)
movl -0x44(%rsp), %eax
shrl $0x8, %eax
andl $0xff, %eax
movb %al, %cl
movq -0x30(%rsp), %rax
movb %cl, (%rax)
movl -0x44(%rsp), %eax
andl $0xff, %eax
movb %al, %cl
movq -0x30(%rsp), %rax
movb %cl, 0x1(%rax)
movl -0x48(%rsp), %eax
shrl $0x8, %eax
andl $0xff, %eax
movb %al, %cl
movq -0x30(%rsp), %rax
movb %cl, 0x4(%rax)
movl -0x48(%rsp), %eax
andl $0xff, %eax
movb %al, %cl
movq -0x30(%rsp), %rax
movb %cl, 0x5(%rax)
movl -0x34(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rsp)
movl -0x14(%rsp), %ecx
movq -0x30(%rsp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rsp)
jmp 0x111dfe
jmp 0x111f07
jmp 0x111f09
jmp 0x111f0b
retq
nopl (%rax)