// File: /workspace/github_cpp_makefile_star2_O3/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 0x8fa88
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movl (%rsi), %r8d
movzwl 0x402(%rdi), %eax
movzwl 0x404(%rdi), %r9d
movzwl 0x406(%rdi), %r10d
xorl %ecx, %ecx
cmpb $0x2, %r11b
movq %rsi, -0x8(%rsp)
jne 0x8f59d
cmpb $0x8, 0x11(%rsi)
jne 0x8f658
cmpq $0x0, 0x2a0(%rdi)
movl %eax, %esi
je 0x8f882
cmpq $0x0, 0x2a8(%rdi)
je 0x8f882
testq %r8, %r8
je 0x8f59f
xorl %r11d, %r11d
xorl %ecx, %ecx
movq %rdx, %rbx
movq 0x2a8(%rdi), %r12
movzbl (%rbx), %r14d
movb (%r12,%r14), %r15b
movzbl 0x1(%rbx), %r14d
movzbl (%r12,%r14), %ebp
movzbl 0x2(%rbx), %r14d
movb (%r12,%r14), %r12b
cmpb %bpl, %r15b
jne 0x8f55f
cmpb %r12b, %r15b
je 0x8f58b
movzbl %r15b, %ecx
movzbl %r12b, %r14d
movq 0x2a0(%rdi), %r15
imull %esi, %ecx
imull %r9d, %ebp
addl %ecx, %ebp
imull %r10d, %r14d
addl %ebp, %r14d
shrl $0xf, %r14d
movb (%r15,%r14), %r14b
movl $0x1, %ecx
movb %r14b, (%rdx,%r11)
incq %r11
addq $0x3, %rbx
cmpl %r11d, %r8d
jne 0x8f533
jmp 0x8f59f
movl %eax, %esi
movq -0x8(%rsp), %rax
cmpb $0x6, 0x10(%rax)
jne 0x8fa41
cmpb $0x8, 0x11(%rax)
jne 0x8f764
cmpq $0x0, 0x2a0(%rdi)
je 0x8f8e6
cmpq $0x0, 0x2a8(%rdi)
je 0x8f8e6
testq %r8, %r8
je 0x8fa41
xorl %r11d, %r11d
movl $0x1, %ebx
movq 0x2a0(%rdi), %r14
movq 0x2a8(%rdi), %rax
movzbl (%rdx,%r11,4), %r15d
movzbl (%rax,%r15), %ebp
movzbl 0x1(%rdx,%r11,4), %r15d
movzbl (%rax,%r15), %r15d
movzbl 0x2(%rdx,%r11,4), %r12d
movzbl (%rax,%r12), %eax
movl %ebp, %r12d
xorl %r15d, %r12d
movl %ebp, %r13d
xorl %eax, %r13d
orl %r12d, %r13d
cmovnel %ebx, %ecx
imull %esi, %ebp
imull %r9d, %r15d
addl %ebp, %r15d
imull %r10d, %eax
addl %r15d, %eax
shrl $0xf, %eax
movb (%r14,%rax), %al
movb %al, (%rdx,%r11,2)
movb 0x3(%rdx,%r11,4), %al
movb %al, 0x1(%rdx,%r11,2)
incq %r11
cmpl %r11d, %r8d
jne 0x8f5e5
jmp 0x8fa41
cmpq $0x0, 0x2c0(%rdi)
movl %eax, %esi
je 0x8f946
cmpq $0x0, 0x2b8(%rdi)
je 0x8f946
testq %r8, %r8
je 0x8f59f
xorl %r11d, %r11d
xorl %ecx, %ecx
movq %rdx, %r14
movzwl (%r14), %ebp
movzwl 0x4(%r14), %ebx
rolw $0x8, %bp
movzwl %bp, %r13d
movzbl 0x2(%r14), %r15d
movl %r15d, %eax
shll $0x8, %eax
movzbl 0x3(%r14), %r12d
orl %r12d, %eax
rolw $0x8, %bx
cmpl %r13d, %eax
jne 0x8f6bd
cmpw %bx, %bp
je 0x8f746
movzwl %bx, %eax
movq 0x2c0(%rdi), %rbx
movl %r13d, %ebp
movl $0xff, %ecx
andl %ecx, %ebp
movb 0x288(%rdi), %cl
shrl %cl, %ebp
movq (%rbx,%rbp,8), %rbp
shrl $0x8, %r13d
movzwl (%rbp,%r13,2), %ebp
shrl %cl, %r12d
movq (%rbx,%r12,8), %r12
movzwl (%r12,%r15,2), %r15d
movl %eax, %r12d
movl $0xff, %r13d
andl %r13d, %r12d
shrl %cl, %r12d
movq (%rbx,%r12,8), %rbx
shrl $0x8, %eax
movzwl (%rbx,%rax,2), %eax
imull %esi, %ebp
imull %r9d, %r15d
addl %ebp, %r15d
imull %r10d, %eax
addl %r15d, %eax
movl %eax, %ebx
shrl $0xf, %ebx
movq 0x2b8(%rdi), %r15
andl %r13d, %ebx
shrl %cl, %ebx
movq (%r15,%rbx,8), %rcx
shrl $0x16, %eax
movl $0x1fe, %ebx            # imm = 0x1FE
andl %ebx, %eax
movzwl (%rcx,%rax), %ebp
movl $0x1, %ecx
rolw $0x8, %bp
movw %bp, (%rdx,%r11,2)
incq %r11
addq $0x6, %r14
cmpl %r11d, %r8d
jne 0x8f687
jmp 0x8f59f
cmpq $0x0, 0x2c0(%rdi)
je 0x8f9c7
cmpq $0x0, 0x2b8(%rdi)
je 0x8f9c7
testq %r8, %r8
je 0x8fa41
xorl %r11d, %r11d
movl $0xff, %ebx
movzwl (%rdx,%r11,8), %r13d
movzwl 0x4(%rdx,%r11,8), %ebp
rolw $0x8, %r13w
movzwl %r13w, %r12d
movzbl 0x2(%rdx,%r11,8), %r14d
movl %r14d, %eax
shll $0x8, %eax
movzbl 0x3(%rdx,%r11,8), %r15d
orl %r15d, %eax
rolw $0x8, %bp
cmpl %r12d, %eax
jne 0x8f7cd
cmpw %bp, %r13w
je 0x8f853
movzwl %bp, %eax
movq 0x2c0(%rdi), %r13
movl %r12d, %ebp
andl %ebx, %ebp
movb 0x288(%rdi), %cl
shrl %cl, %ebp
movq (%r13,%rbp,8), %rbp
shrl $0x8, %r12d
movzwl (%rbp,%r12,2), %ebp
shrl %cl, %r15d
movq (%r13,%r15,8), %r15
movzwl (%r15,%r14,2), %r14d
movl %eax, %r15d
andl %ebx, %r15d
shrl %cl, %r15d
movq (%r13,%r15,8), %r15
shrl $0x8, %eax
movzwl (%r15,%rax,2), %eax
imull %esi, %ebp
imull %r9d, %r14d
addl %ebp, %r14d
imull %r10d, %eax
addl %r14d, %eax
movl %eax, %r14d
shrl $0xf, %r14d
movq 0x2b8(%rdi), %r15
andl %ebx, %r14d
shrl %cl, %r14d
movq (%r15,%r14,8), %rcx
shrl $0x16, %eax
movl $0x1fe, %ebp            # imm = 0x1FE
andl %ebp, %eax
movzwl (%rcx,%rax), %r13d
movl $0x1, %ecx
rolw $0x8, %r13w
movw %r13w, (%rdx,%r11,4)
movb 0x6(%rdx,%r11,8), %al
movb %al, 0x2(%rdx,%r11,4)
movb 0x7(%rdx,%r11,8), %al
movb %al, 0x3(%rdx,%r11,4)
incq %r11
cmpl %r11d, %r8d
jne 0x8f791
jmp 0x8fa41
testq %r8, %r8
je 0x8f59f
xorl %r11d, %r11d
xorl %ecx, %ecx
movq %rdx, %rbx
movb (%rbx), %bpl
movb 0x2(%rbx), %r15b
movzbl 0x1(%rbx), %r14d
movl %r14d, %r12d
xorb %bpl, %r12b
movl %ebp, %r13d
xorb %r15b, %r13b
orb %r12b, %r13b
je 0x8f8d1
movzbl %bpl, %ecx
movzbl %r15b, %ebp
imull %esi, %ecx
imull %r9d, %r14d
addl %ecx, %r14d
imull %r10d, %ebp
addl %r14d, %ebp
shrl $0xf, %ebp
movl $0x1, %ecx
movb %bpl, (%rdx,%r11)
incq %r11
addq $0x3, %rbx
cmpl %r11d, %r8d
jne 0x8f893
jmp 0x8f59f
testq %r8, %r8
je 0x8fa41
xorl %edi, %edi
movl $0x1, %r11d
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 %esi, %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
cmpl %edi, %r8d
jne 0x8f8f7
jmp 0x8fa41
testq %r8, %r8
je 0x8f59f
xorl %r11d, %r11d
movl $0x1, %ebx
xorl %ecx, %ecx
movq %rdx, %r14
movzwl (%r14), %eax
movzwl 0x2(%r14), %ebp
rolw $0x8, %ax
movzwl %ax, %eax
rolw $0x8, %bp
movzwl %bp, %ebp
movzwl 0x4(%r14), %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 %esi, %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,%r11,2)
movb %al, 0x1(%rdx,%r11,2)
incq %r11
addq $0x6, %r14
cmpl %r11d, %r8d
jne 0x8f95c
jmp 0x8f59f
testq %r8, %r8
je 0x8fa41
xorl %edi, %edi
movl $0x1, %r11d
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 %esi, %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
cmpl %edi, %r8d
jne 0x8f9d4
movq -0x8(%rsp), %rsi
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 0x8fa75
shrb $0x3, %al
movzbl %al, %eax
imulq %r8, %rax
jmp 0x8fa84
movzbl %al, %eax
imulq %r8, %rax
addq $0x7, %rax
shrq $0x3, %rax
movq %rax, 0x8(%rsi)
movl %ecx, %eax
retq