// File: tomfunkhouser[P]gaps/pkgs/png/png.c
// Function: png_check_cHRM_fixed
int /* PRIVATE */
png_check_cHRM_fixed(png_structp png_ptr,
   png_fixed_point white_x, png_fixed_point white_y, png_fixed_point red_x,
   png_fixed_point red_y, png_fixed_point green_x, png_fixed_point green_y,
   png_fixed_point blue_x, png_fixed_point blue_y)
{
   int ret = 1;
   unsigned long xy_hi,xy_lo,yx_hi,yx_lo;

   png_debug(1, "in function png_check_cHRM_fixed");

   if (png_ptr == NULL)
      return 0;

   if (white_x < 0 || white_y <= 0 ||
         red_x < 0 ||   red_y <  0 ||
       green_x < 0 || green_y <  0 ||
        blue_x < 0 ||  blue_y <  0)
   {
      png_warning(png_ptr,
        "Ignoring attempt to set negative chromaticity value");
      ret = 0;
   }
   if (white_x > (png_fixed_point) PNG_UINT_31_MAX ||
       white_y > (png_fixed_point) PNG_UINT_31_MAX ||
         red_x > (png_fixed_point) PNG_UINT_31_MAX ||
         red_y > (png_fixed_point) PNG_UINT_31_MAX ||
       green_x > (png_fixed_point) PNG_UINT_31_MAX ||
       green_y > (png_fixed_point) PNG_UINT_31_MAX ||
        blue_x > (png_fixed_point) PNG_UINT_31_MAX ||
        blue_y > (png_fixed_point) PNG_UINT_31_MAX )
   {
      png_warning(png_ptr,
        "Ignoring attempt to set chromaticity value exceeding 21474.83");
      ret = 0;
   }
   if (white_x > 100000L - white_y)
   {
      png_warning(png_ptr, "Invalid cHRM white point");
      ret = 0;
   }
   if (red_x > 100000L - red_y)
   {
      png_warning(png_ptr, "Invalid cHRM red point");
      ret = 0;
   }
   if (green_x > 100000L - green_y)
   {
      png_warning(png_ptr, "Invalid cHRM green point");
      ret = 0;
   }
   if (blue_x > 100000L - blue_y)
   {
      png_warning(png_ptr, "Invalid cHRM blue point");
      ret = 0;
   }

   png_64bit_product(green_x - red_x, blue_y - red_y, &xy_hi, &xy_lo);
   png_64bit_product(green_y - red_y, blue_x - red_x, &yx_hi, &yx_lo);

   if (xy_hi == yx_hi && xy_lo == yx_lo)
   {
      png_warning(png_ptr,
         "Ignoring attempt to set cHRM RGB triangle with zero area");
      ret = 0;
   }

   return ret;
}

// Assembly:
subq $0x48, %rsp
movl 0x60(%rsp), %eax
movl 0x58(%rsp), %eax
movl 0x50(%rsp), %eax
movq %rdi, 0x38(%rsp)
movl %esi, 0x34(%rsp)
movl %edx, 0x30(%rsp)
movl %ecx, 0x2c(%rsp)
movl %r8d, 0x28(%rsp)
movl %r9d, 0x24(%rsp)
movl $0x1, 0x20(%rsp)
cmpq $0x0, 0x38(%rsp)
jne 0xfc658
movl $0x0, 0x44(%rsp)
jmp 0xfc852
cmpl $0x0, 0x34(%rsp)
jl 0xfc690
cmpl $0x0, 0x30(%rsp)
jle 0xfc690
cmpl $0x0, 0x2c(%rsp)
jl 0xfc690
cmpl $0x0, 0x28(%rsp)
jl 0xfc690
cmpl $0x0, 0x24(%rsp)
jl 0xfc690
cmpl $0x0, 0x50(%rsp)
jl 0xfc690
cmpl $0x0, 0x58(%rsp)
jl 0xfc690
cmpl $0x0, 0x60(%rsp)
jge 0xfc6a9
movq 0x38(%rsp), %rdi
leaq 0x3c378(%rip), %rsi     # 0x138a14
callq 0x113940
movl $0x0, 0x20(%rsp)
cmpl $0x7fffffff, 0x34(%rsp) # imm = 0x7FFFFFFF
jg 0xfc6f9
cmpl $0x7fffffff, 0x30(%rsp) # imm = 0x7FFFFFFF
jg 0xfc6f9
cmpl $0x7fffffff, 0x2c(%rsp) # imm = 0x7FFFFFFF
jg 0xfc6f9
cmpl $0x7fffffff, 0x28(%rsp) # imm = 0x7FFFFFFF
jg 0xfc6f9
cmpl $0x7fffffff, 0x24(%rsp) # imm = 0x7FFFFFFF
jg 0xfc6f9
cmpl $0x7fffffff, 0x50(%rsp) # imm = 0x7FFFFFFF
jg 0xfc6f9
cmpl $0x7fffffff, 0x58(%rsp) # imm = 0x7FFFFFFF
jg 0xfc6f9
cmpl $0x7fffffff, 0x60(%rsp) # imm = 0x7FFFFFFF
jle 0xfc712
movq 0x38(%rsp), %rdi
leaq 0x3c343(%rip), %rsi     # 0x138a48
callq 0x113940
movl $0x0, 0x20(%rsp)
movslq 0x34(%rsp), %rax
movslq 0x30(%rsp), %rdx
movl $0x186a0, %ecx          # imm = 0x186A0
subq %rdx, %rcx
cmpq %rcx, %rax
jle 0xfc742
movq 0x38(%rsp), %rdi
leaq 0x3c351(%rip), %rsi     # 0x138a86
callq 0x113940
movl $0x0, 0x20(%rsp)
movslq 0x2c(%rsp), %rax
movslq 0x28(%rsp), %rdx
movl $0x186a0, %ecx          # imm = 0x186A0
subq %rdx, %rcx
cmpq %rcx, %rax
jle 0xfc772
movq 0x38(%rsp), %rdi
leaq 0x3c33a(%rip), %rsi     # 0x138a9f
callq 0x113940
movl $0x0, 0x20(%rsp)
movslq 0x24(%rsp), %rax
movslq 0x50(%rsp), %rdx
movl $0x186a0, %ecx          # imm = 0x186A0
subq %rdx, %rcx
cmpq %rcx, %rax
jle 0xfc7a2
movq 0x38(%rsp), %rdi
leaq 0x3c321(%rip), %rsi     # 0x138ab6
callq 0x113940
movl $0x0, 0x20(%rsp)
movslq 0x58(%rsp), %rax
movslq 0x60(%rsp), %rdx
movl $0x186a0, %ecx          # imm = 0x186A0
subq %rdx, %rcx
cmpq %rcx, %rax
jle 0xfc7d2
movq 0x38(%rsp), %rdi
leaq 0x3c30a(%rip), %rsi     # 0x138acf
callq 0x113940
movl $0x0, 0x20(%rsp)
movl 0x24(%rsp), %eax
subl 0x2c(%rsp), %eax
movslq %eax, %rdi
movl 0x60(%rsp), %eax
subl 0x28(%rsp), %eax
movslq %eax, %rsi
leaq 0x18(%rsp), %rdx
leaq 0x10(%rsp), %rcx
callq 0xfc500
movl 0x50(%rsp), %eax
subl 0x28(%rsp), %eax
movslq %eax, %rdi
movl 0x58(%rsp), %eax
subl 0x2c(%rsp), %eax
movslq %eax, %rsi
leaq 0x8(%rsp), %rdx
movq %rsp, %rcx
callq 0xfc500
movq 0x18(%rsp), %rax
cmpq 0x8(%rsp), %rax
jne 0xfc84a
movq 0x10(%rsp), %rax
cmpq (%rsp), %rax
jne 0xfc84a
movq 0x38(%rsp), %rdi
leaq 0x3c2aa(%rip), %rsi     # 0x138ae7
callq 0x113940
movl $0x0, 0x20(%rsp)
movl 0x20(%rsp), %eax
movl %eax, 0x44(%rsp)
movl 0x44(%rsp), %eax
addq $0x48, %rsp
retq
nopl (%rax,%rax)