// File: tomfunkhouser[P]gaps/pkgs/png/pngrtran.c
// Function: png_set_rgb_to_gray_fixed
void PNGAPI
png_set_rgb_to_gray_fixed(png_structp png_ptr, int error_action,
   png_fixed_point red, png_fixed_point green)
{
   png_debug(1, "in png_set_rgb_to_gray");

   if (png_ptr == NULL)
      return;

   switch(error_action)
   {
      case 1: png_ptr->transformations |= PNG_RGB_TO_GRAY;
              break;

      case 2: png_ptr->transformations |= PNG_RGB_TO_GRAY_WARN;
              break;

      case 3: png_ptr->transformations |= PNG_RGB_TO_GRAY_ERR;
   }
   if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
#ifdef PNG_READ_EXPAND_SUPPORTED
      png_ptr->transformations |= PNG_EXPAND;
#else
   {
      png_warning(png_ptr,
        "Cannot do RGB_TO_GRAY without EXPAND_SUPPORTED");
      png_ptr->transformations &= ~PNG_RGB_TO_GRAY;
   }
#endif
   {
      png_uint_16 red_int, green_int;
      if (red < 0 || green < 0)
      {
         red_int   =  6968; /* .212671 * 32768 + .5 */
         green_int = 23434; /* .715160 * 32768 + .5 */
      }
      else if (red + green < 100000L)
      {
         red_int = (png_uint_16)(((png_uint_32)red*32768L)/100000L);
         green_int = (png_uint_16)(((png_uint_32)green*32768L)/100000L);
      }
      else
      {
         png_warning(png_ptr, "ignoring out of range rgb_to_gray coefficients");
         red_int   =  6968;
         green_int = 23434;
      }
      png_ptr->rgb_to_gray_red_coeff   = red_int;
      png_ptr->rgb_to_gray_green_coeff = green_int;
      png_ptr->rgb_to_gray_blue_coeff  =
         (png_uint_16)(32768 - red_int - green_int);
   }
}

// Assembly:
subq $0x28, %rsp
movq %rdi, 0x20(%rsp)
movl %esi, 0x1c(%rsp)
movl %edx, 0x18(%rsp)
movl %ecx, 0x14(%rsp)
cmpq $0x0, 0x20(%rsp)
jne 0x107982
jmp 0x107ae0
movl 0x1c(%rsp), %eax
movl %eax, 0xc(%rsp)
subl $0x1, %eax
je 0x1079a7
jmp 0x107991
movl 0xc(%rsp), %eax
subl $0x2, %eax
je 0x1079c1
jmp 0x10799c
movl 0xc(%rsp), %eax
subl $0x3, %eax
je 0x1079db
jmp 0x1079f3
movq 0x20(%rsp), %rax
movl 0x124(%rax), %ecx
orq $0x600000, %rcx         # imm = 0x600000
movl %ecx, 0x124(%rax)
jmp 0x1079f3
movq 0x20(%rsp), %rax
movl 0x124(%rax), %ecx
orq $0x400000, %rcx         # imm = 0x400000
movl %ecx, 0x124(%rax)
jmp 0x1079f3
movq 0x20(%rsp), %rax
movl 0x124(%rax), %ecx
orq $0x200000, %rcx         # imm = 0x200000
movl %ecx, 0x124(%rax)
movq 0x20(%rsp), %rax
movzbl 0x24e(%rax), %eax
cmpl $0x3, %eax
jne 0x107a1b
movq 0x20(%rsp), %rax
movl 0x124(%rax), %ecx
orl $0x1000, %ecx           # imm = 0x1000
movl %ecx, 0x124(%rax)
cmpl $0x0, 0x18(%rsp)
jl 0x107a29
cmpl $0x0, 0x14(%rsp)
jge 0x107a39
movw $0x1b38, 0x12(%rsp)     # imm = 0x1B38
movw $0x5b8a, 0x10(%rsp)     # imm = 0x5B8A
jmp 0x107a9c
movl 0x18(%rsp), %eax
addl 0x14(%rsp), %eax
cltq
cmpq $0x186a0, %rax          # imm = 0x186A0
jge 0x107a7b
movl 0x18(%rsp), %eax
shlq $0xf, %rax
movl $0x186a0, %ecx          # imm = 0x186A0
cqto
idivq %rcx
movw %ax, 0x12(%rsp)
movl 0x14(%rsp), %eax
shlq $0xf, %rax
movl $0x186a0, %ecx          # imm = 0x186A0
cqto
idivq %rcx
movw %ax, 0x10(%rsp)
jmp 0x107a9a
movq 0x20(%rsp), %rdi
leaq 0x31d3b(%rip), %rsi     # 0x1397c2
callq 0x113940
movw $0x1b38, 0x12(%rsp)     # imm = 0x1B38
movw $0x5b8a, 0x10(%rsp)     # imm = 0x5B8A
jmp 0x107a9c
movw 0x12(%rsp), %cx
movq 0x20(%rsp), %rax
movw %cx, 0x402(%rax)
movw 0x10(%rsp), %cx
movq 0x20(%rsp), %rax
movw %cx, 0x404(%rax)
movzwl 0x12(%rsp), %ecx
movl $0x8000, %eax           # imm = 0x8000
subl %ecx, %eax
movzwl 0x10(%rsp), %ecx
subl %ecx, %eax
movw %ax, %cx
movq 0x20(%rsp), %rax
movw %cx, 0x406(%rax)
addq $0x28, %rsp
retq
nopw %cs:(%rax,%rax)