// File: /workspace/github_cpp_makefile_star2_O2/tomfunkhouser[P]gaps/pkgs/png/pngrtran.c
// Function: png_do_rgb_to_gray
int /* PRIVATE */
png_do_rgb_to_gray(png_structp png_ptr, png_row_infop row_info, png_bytep row)

{
   png_uint_32 i;

   png_uint_32 row_width = row_info->width;
   int rgb_error = 0;

   png_debug(1, "in png_do_rgb_to_gray");

   if (
      (row_info->color_type & PNG_COLOR_MASK_COLOR))
   {
      png_uint_32 rc = png_ptr->rgb_to_gray_red_coeff;
      png_uint_32 gc = png_ptr->rgb_to_gray_green_coeff;
      png_uint_32 bc = png_ptr->rgb_to_gray_blue_coeff;

      if (row_info->color_type == PNG_COLOR_TYPE_RGB)
      {
         if (row_info->bit_depth == 8)
         {
#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
            if (png_ptr->gamma_from_1 != NULL && png_ptr->gamma_to_1 != NULL)
            {
               png_bytep sp = row;
               png_bytep dp = row;

               for (i = 0; i < row_width; i++)
               {
                  png_byte red   = png_ptr->gamma_to_1[*(sp++)];
                  png_byte green = png_ptr->gamma_to_1[*(sp++)];
                  png_byte blue  = png_ptr->gamma_to_1[*(sp++)];
                  if (red != green || red != blue)
                  {
                     rgb_error |= 1;
                     *(dp++) = png_ptr->gamma_from_1[
                       (rc*red + gc*green + bc*blue)>>15];
                  }
                  else
                     *(dp++) = *(sp - 1);
               }
            }
            else
#endif
            {
               png_bytep sp = row;
               png_bytep dp = row;
               for (i = 0; i < row_width; i++)
               {
                  png_byte red   = *(sp++);
                  png_byte green = *(sp++);
                  png_byte blue  = *(sp++);
                  if (red != green || red != blue)
                  {
                     rgb_error |= 1;
                     *(dp++) = (png_byte)((rc*red + gc*green + bc*blue)>>15);
                  }
                  else
                     *(dp++) = *(sp - 1);
               }
            }
         }

         else /* RGB bit_depth == 16 */
         {
#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
            if (png_ptr->gamma_16_to_1 != NULL &&
                png_ptr->gamma_16_from_1 != NULL)
            {
               png_bytep sp = row;
               png_bytep dp = row;
               for (i = 0; i < row_width; i++)
               {
                  png_uint_16 red, green, blue, w;

                  red   = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
                  green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
                  blue  = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;

                  if (red == green && red == blue)
                     w = red;
                  else
                  {
                     png_uint_16 red_1   = png_ptr->gamma_16_to_1[(red&0xff) >>
                                  png_ptr->gamma_shift][red>>8];
                     png_uint_16 green_1 =
                         png_ptr->gamma_16_to_1[(green&0xff) >>
                                  png_ptr->gamma_shift][green>>8];
                     png_uint_16 blue_1  = png_ptr->gamma_16_to_1[(blue&0xff) >>
                                  png_ptr->gamma_shift][blue>>8];
                     png_uint_16 gray16  = (png_uint_16)((rc*red_1 + gc*green_1
                                  + bc*blue_1)>>15);
                     w = png_ptr->gamma_16_from_1[(gray16&0xff) >>
                         png_ptr->gamma_shift][gray16 >> 8];
                     rgb_error |= 1;
                  }

                  *(dp++) = (png_byte)((w>>8) & 0xff);
                  *(dp++) = (png_byte)(w & 0xff);
               }
            }
            else
#endif
            {
               png_bytep sp = row;
               png_bytep dp = row;
               for (i = 0; i < row_width; i++)
               {
                  png_uint_16 red, green, blue, gray16;

                  red   = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
                  green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
                  blue  = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;

                  if (red != green || red != blue)
                     rgb_error |= 1;
                  gray16  = (png_uint_16)((rc*red + gc*green + bc*blue)>>15);
                  *(dp++) = (png_byte)((gray16>>8) & 0xff);
                  *(dp++) = (png_byte)(gray16 & 0xff);
               }
            }
         }
      }
      if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
      {
         if (row_info->bit_depth == 8)
         {
#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
            if (png_ptr->gamma_from_1 != NULL && png_ptr->gamma_to_1 != NULL)
            {
               png_bytep sp = row;
               png_bytep dp = row;
               for (i = 0; i < row_width; i++)
               {
                  png_byte red   = png_ptr->gamma_to_1[*(sp++)];
                  png_byte green = png_ptr->gamma_to_1[*(sp++)];
                  png_byte blue  = png_ptr->gamma_to_1[*(sp++)];
                  if (red != green || red != blue)
                     rgb_error |= 1;
                  *(dp++) =  png_ptr->gamma_from_1
                             [(rc*red + gc*green + bc*blue)>>15];
                  *(dp++) = *(sp++);  /* alpha */
               }
            }
            else
#endif
            {
               png_bytep sp = row;
               png_bytep dp = row;
               for (i = 0; i < row_width; i++)
               {
                  png_byte red   = *(sp++);
                  png_byte green = *(sp++);
                  png_byte blue  = *(sp++);
                  if (red != green || red != blue)
                     rgb_error |= 1;
                  *(dp++) =  (png_byte)((rc*red + gc*green + bc*blue)>>15);
                  *(dp++) = *(sp++);  /* alpha */
               }
            }
         }
         else /* RGBA bit_depth == 16 */
         {
#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
            if (png_ptr->gamma_16_to_1 != NULL &&
                png_ptr->gamma_16_from_1 != NULL)
            {
               png_bytep sp = row;
               png_bytep dp = row;
               for (i = 0; i < row_width; i++)
               {
                  png_uint_16 red, green, blue, w;

                  red   = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
                  green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
                  blue  = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;

                  if (red == green && red == blue)
                     w = red;
                  else
                  {
                     png_uint_16 red_1   = png_ptr->gamma_16_to_1[(red&0xff) >>
                         png_ptr->gamma_shift][red>>8];
                     png_uint_16 green_1 =
                         png_ptr->gamma_16_to_1[(green&0xff) >>
                         png_ptr->gamma_shift][green>>8];
                     png_uint_16 blue_1  = png_ptr->gamma_16_to_1[(blue&0xff) >>
                         png_ptr->gamma_shift][blue>>8];
                     png_uint_16 gray16  = (png_uint_16)((rc * red_1
                         + gc * green_1 + bc * blue_1)>>15);
                     w = png_ptr->gamma_16_from_1[(gray16&0xff) >>
                         png_ptr->gamma_shift][gray16 >> 8];
                     rgb_error |= 1;
                  }

                  *(dp++) = (png_byte)((w>>8) & 0xff);
                  *(dp++) = (png_byte)(w & 0xff);
                  *(dp++) = *(sp++);  /* alpha */
                  *(dp++) = *(sp++);
               }
            }
            else
#endif
            {
               png_bytep sp = row;
               png_bytep dp = row;
               for (i = 0; i < row_width; i++)
               {
                  png_uint_16 red, green, blue, gray16;
                  red   = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2;
                  green = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2;
                  blue  = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2;
                  if (red != green || red != blue)
                     rgb_error |= 1;
                  gray16  = (png_uint_16)((rc*red + gc*green + bc*blue)>>15);
                  *(dp++) = (png_byte)((gray16>>8) & 0xff);
                  *(dp++) = (png_byte)(gray16 & 0xff);
                  *(dp++) = *(sp++);  /* alpha */
                  *(dp++) = *(sp++);
               }
            }
         }
      }
   row_info->channels -= (png_byte)2;
      row_info->color_type &= ~PNG_COLOR_MASK_COLOR;
      row_info->pixel_depth = (png_byte)(row_info->channels *
         row_info->bit_depth);
      row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_width);
   }
   return rgb_error;
}

// Assembly:
movb 0x10(%rsi), %r11b
xorl %ecx, %ecx
testb $0x2, %r11b
je 0x8260a
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movl (%rsi), %r8d
movzwl 0x402(%rdi), %eax
movl %eax, -0xc(%rsp)
movzwl 0x404(%rdi), %r9d
movzwl 0x406(%rdi), %r10d
xorl %ecx, %ecx
cmpb $0x2, %r11b
jne 0x82332
cmpb $0x8, 0x11(%rsi)
jne 0x82149
cmpq $0x0, 0x2a0(%rdi)
je 0x82251
cmpq $0x0, 0x2a8(%rdi)
je 0x82251
xorl %r11d, %r11d
movl $0x1, %ebx
xorl %r14d, %r14d
xorl %ecx, %ecx
cmpl %r14d, %r8d
je 0x82332
movq 0x2a8(%rdi), %r13
movzbl (%rdx,%r11), %r15d
movb (%r13,%r15), %r15b
movzbl 0x1(%rdx,%r11), %r12d
movzbl (%r13,%r12), %ebp
movzbl 0x2(%rdx,%r11), %r12d
movb (%r13,%r12), %r13b
cmpb %bpl, %r15b
jne 0x82111
cmpb %r13b, %r15b
je 0x8213c
movzbl %r15b, %ecx
movzbl %r13b, %r15d
movq 0x2a0(%rdi), %r12
imull -0xc(%rsp), %ecx
imull %r9d, %ebp
addl %ecx, %ebp
imull %r10d, %r15d
addl %ebp, %r15d
shrl $0xf, %r15d
movb (%r12,%r15), %r12b
movl %ebx, %ecx
movb %r12b, (%rdx,%r14)
incq %r14
addq $0x3, %r11
jmp 0x820d6
movq %rsi, -0x8(%rsp)
cmpq $0x0, 0x2c0(%rdi)
je 0x822b3
cmpq $0x0, 0x2b8(%rdi)
je 0x822b3
xorl %r11d, %r11d
xorl %r15d, %r15d
xorl %ecx, %ecx
cmpl %r15d, %r8d
je 0x8232d
movzwl (%rdx,%r11), %r14d
movzwl 0x4(%rdx,%r11), %ebx
rolw $0x8, %r14w
movzwl %r14w, %ebp
movzbl 0x2(%rdx,%r11), %r12d
movl %r12d, %eax
shll $0x8, %eax
movzbl 0x3(%rdx,%r11), %r13d
orl %r13d, %eax
rolw $0x8, %bx
cmpl %ebp, %eax
jne 0x821b6
cmpw %bx, %r14w
je 0x8223b
movzwl %bx, %eax
movq 0x2c0(%rdi), %rbx
movl %ebp, %r14d
movl $0xff, %esi
andl %esi, %r14d
movb 0x288(%rdi), %cl
shrl %cl, %r14d
movq (%rbx,%r14,8), %r14
shrl $0x8, %ebp
movzwl (%r14,%rbp,2), %ebp
shrl %cl, %r13d
movq (%rbx,%r13,8), %r14
movzwl (%r14,%r12,2), %r14d
movl %eax, %r12d
andl %esi, %r12d
shrl %cl, %r12d
movq (%rbx,%r12,8), %rbx
shrl $0x8, %eax
movzwl (%rbx,%rax,2), %eax
imull -0xc(%rsp), %ebp
imull %r9d, %r14d
addl %ebp, %r14d
imull %r10d, %eax
addl %r14d, %eax
movl %eax, %ebx
shrl $0xf, %ebx
movq 0x2b8(%rdi), %r14
andl %esi, %ebx
shrl %cl, %ebx
movq (%r14,%rbx,8), %rcx
shrl $0x16, %eax
movl $0x1fe, %esi            # imm = 0x1FE
andl %esi, %eax
movzwl (%rcx,%rax), %r14d
movl $0x1, %ecx
rolw $0x8, %r14w
movw %r14w, (%rdx,%r15,2)
incq %r15
addq $0x6, %r11
jmp 0x82172
xorl %r11d, %r11d
movl $0x1, %eax
xorl %r14d, %r14d
xorl %ecx, %ecx
cmpl %r14d, %r8d
je 0x82332
movb (%rdx,%r11), %bpl
movb 0x2(%rdx,%r11), %r12b
movzbl 0x1(%rdx,%r11), %r15d
movl %r15d, %r13d
xorb %bpl, %r13b
movl %ebp, %ebx
xorb %r12b, %bl
orb %r13b, %bl
je 0x822a6
movzbl %bpl, %ecx
movzbl %r12b, %ebp
imull -0xc(%rsp), %ecx
imull %r9d, %r15d
addl %ecx, %r15d
imull %r10d, %ebp
addl %r15d, %ebp
shrl $0xf, %ebp
movl %eax, %ecx
movb %bpl, (%rdx,%r14)
incq %r14
addq $0x3, %r11
jmp 0x8225e
xorl %r11d, %r11d
movl $0x1, %ebx
xorl %r14d, %r14d
xorl %ecx, %ecx
cmpl %r14d, %r8d
je 0x8232d
movzwl (%rdx,%r11), %eax
rolw $0x8, %ax
movzwl 0x2(%rdx,%r11), %ebp
movzwl %ax, %eax
rolw $0x8, %bp
movzwl %bp, %ebp
movzwl 0x4(%rdx,%r11), %r15d
rolw $0x8, %r15w
movzwl %r15w, %r15d
movl %eax, %r12d
xorl %ebp, %r12d
movl %eax, %r13d
xorl %r15d, %r13d
orl %r12d, %r13d
cmovnel %ebx, %ecx
imull -0xc(%rsp), %eax
imull %r9d, %ebp
addl %eax, %ebp
imull %r10d, %r15d
addl %ebp, %r15d
movl %r15d, %eax
shrl $0xf, %eax
shrl $0x17, %r15d
movb %r15b, (%rdx,%r14,2)
movb %al, 0x1(%rdx,%r14,2)
incq %r14
addq $0x6, %r11
jmp 0x822c0
movq -0x8(%rsp), %rsi
cmpb $0x6, 0x10(%rsi)
jne 0x825c8
cmpb $0x8, 0x11(%rsi)
jne 0x823e0
cmpq $0x0, 0x2a0(%rdi)
je 0x824f5
cmpq $0x0, 0x2a8(%rdi)
je 0x824f5
xorl %r11d, %r11d
movl $0x1, %ebx
cmpl %r11d, %r8d
je 0x825c8
movq 0x2a8(%rdi), %rax
movzbl (%rdx,%r11,4), %r14d
movzbl (%rax,%r14), %ebp
movzbl 0x1(%rdx,%r11,4), %r14d
movzbl (%rax,%r14), %r14d
movzbl 0x2(%rdx,%r11,4), %r15d
movzbl (%rax,%r15), %eax
movl %ebp, %r15d
xorl %r14d, %r15d
movl %ebp, %r12d
xorl %eax, %r12d
orl %r15d, %r12d
cmovnel %ebx, %ecx
movq 0x2a0(%rdi), %r15
imull -0xc(%rsp), %ebp
imull %r9d, %r14d
addl %ebp, %r14d
imull %r10d, %eax
addl %r14d, %eax
shrl $0xf, %eax
movb (%r15,%rax), %al
movb %al, (%rdx,%r11,2)
movb 0x3(%rdx,%r11,4), %al
movb %al, 0x1(%rdx,%r11,2)
incq %r11
jmp 0x8236a
cmpq $0x0, 0x2c0(%rdi)
je 0x8254f
cmpq $0x0, 0x2b8(%rdi)
je 0x8254f
xorl %ebx, %ebx
movl $0xff, %ebp
cmpl %ebx, %r8d
je 0x825c8
movzwl (%rdx,%rbx,8), %r11d
movzwl 0x4(%rdx,%rbx,8), %r14d
rolw $0x8, %r11w
movzwl %r11w, %r13d
movzbl 0x2(%rdx,%rbx,8), %r15d
movl %r15d, %eax
shll $0x8, %eax
movzbl 0x3(%rdx,%rbx,8), %r12d
orl %r12d, %eax
rolw $0x8, %r14w
cmpl %r13d, %eax
jne 0x82449
cmpw %r14w, %r11w
je 0x824d3
movzwl %r14w, %eax
movq 0x2c0(%rdi), %r11
movl %r13d, %r14d
andl %ebp, %r14d
movb 0x288(%rdi), %cl
shrl %cl, %r14d
movq (%r11,%r14,8), %r14
shrl $0x8, %r13d
movzwl (%r14,%r13,2), %r14d
shrl %cl, %r12d
movq (%r11,%r12,8), %r12
movzwl (%r12,%r15,2), %r15d
movl %eax, %r12d
andl %ebp, %r12d
shrl %cl, %r12d
movq (%r11,%r12,8), %r11
shrl $0x8, %eax
movzwl (%r11,%rax,2), %eax
imull -0xc(%rsp), %r14d
imull %r9d, %r15d
addl %r14d, %r15d
imull %r10d, %eax
addl %r15d, %eax
movl %eax, %r11d
shrl $0xf, %r11d
movq 0x2b8(%rdi), %r14
andl %ebp, %r11d
shrl %cl, %r11d
movq (%r14,%r11,8), %rcx
shrl $0x16, %eax
movl $0x1fe, %r11d           # imm = 0x1FE
andl %r11d, %eax
movzwl (%rcx,%rax), %r11d
movl $0x1, %ecx
rolw $0x8, %r11w
movw %r11w, (%rdx,%rbx,4)
movb 0x6(%rdx,%rbx,8), %al
movb %al, 0x2(%rdx,%rbx,4)
movb 0x7(%rdx,%rbx,8), %al
movb %al, 0x3(%rdx,%rbx,4)
incq %rbx
jmp 0x82403
xorl %edi, %edi
movl $0x1, %r11d
cmpl %edi, %r8d
je 0x825c8
movb (%rdx,%rdi,4), %al
movb 0x2(%rdx,%rdi,4), %bl
movzbl 0x1(%rdx,%rdi,4), %ebp
movzbl %al, %eax
movl %eax, %r14d
xorb %bpl, %r14b
movl %eax, %r15d
xorb %bl, %r15b
orb %r14b, %r15b
cmovnel %r11d, %ecx
imull -0xc(%rsp), %eax
imull %r9d, %ebp
addl %eax, %ebp
movzbl %bl, %eax
imull %r10d, %eax
addl %ebp, %eax
shrl $0xf, %eax
movb %al, (%rdx,%rdi,2)
movb 0x3(%rdx,%rdi,4), %al
movb %al, 0x1(%rdx,%rdi,2)
incq %rdi
jmp 0x824fd
xorl %edi, %edi
movl $0x1, %r11d
cmpl %edi, %r8d
je 0x825c8
movzwl (%rdx,%rdi,8), %eax
rolw $0x8, %ax
movzwl 0x2(%rdx,%rdi,8), %ebx
movzwl %ax, %eax
rolw $0x8, %bx
movzwl %bx, %ebx
movzwl 0x4(%rdx,%rdi,8), %ebp
rolw $0x8, %bp
movzwl %bp, %ebp
movl %eax, %r14d
xorl %ebx, %r14d
movl %eax, %r15d
xorl %ebp, %r15d
orl %r14d, %r15d
cmovnel %r11d, %ecx
imull -0xc(%rsp), %eax
imull %r9d, %ebx
addl %eax, %ebx
imull %r10d, %ebp
addl %ebx, %ebp
movl %ebp, %eax
shrl $0xf, %eax
shrl $0x17, %ebp
movb %bpl, (%rdx,%rdi,4)
movb %al, 0x1(%rdx,%rdi,4)
movb 0x6(%rdx,%rdi,8), %al
movb %al, 0x2(%rdx,%rdi,4)
movb 0x7(%rdx,%rdi,8), %al
movb %al, 0x3(%rdx,%rdi,4)
incq %rdi
jmp 0x82557
movb 0x11(%rsi), %al
movb 0x12(%rsi), %dl
addb $-0x2, %dl
movb %dl, 0x12(%rsi)
andb $-0x3, 0x10(%rsi)
mulb %dl
movb %al, 0x13(%rsi)
cmpb $0x8, %al
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jb 0x825f7
shrb $0x3, %al
movzbl %al, %eax
imulq %r8, %rax
jmp 0x82606
movzbl %al, %eax
imulq %r8, %rax
addq $0x7, %rax
shrq $0x3, %rax
movq %rax, 0x8(%rsi)
movl %ecx, %eax
retq