// File: /workspace/github_cpp_makefile_star2_O2/tomfunkhouser[P]gaps/pkgs/png/pngrutil.c
// Function: png_handle_bKGD
void /* PRIVATE */
png_handle_bKGD(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
{
   png_size_t truelen;
   png_byte buf[6];

   png_debug(1, "in png_handle_bKGD");

   if (!(png_ptr->mode & PNG_HAVE_IHDR))
      png_error(png_ptr, "Missing IHDR before bKGD");
   else if (png_ptr->mode & PNG_HAVE_IDAT)
   {
      png_warning(png_ptr, "Invalid bKGD after IDAT");
      png_crc_finish(png_ptr, length);
      return;
   }
   else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
            !(png_ptr->mode & PNG_HAVE_PLTE))
   {
      png_warning(png_ptr, "Missing PLTE before bKGD");
      png_crc_finish(png_ptr, length);
      return;
   }
   else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD))
   {
      png_warning(png_ptr, "Duplicate bKGD chunk");
      png_crc_finish(png_ptr, length);
      return;
   }

   if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
      truelen = 1;
   else if (png_ptr->color_type & PNG_COLOR_MASK_COLOR)
      truelen = 6;
   else
      truelen = 2;

   if (length != truelen)
   {
      png_warning(png_ptr, "Incorrect bKGD chunk length");
      png_crc_finish(png_ptr, length);
      return;
   }

   png_crc_read(png_ptr, buf, truelen);
   if (png_crc_finish(png_ptr, 0))
      return;

   /* We convert the index value into RGB components so that we can allow
    * arbitrary RGB values for background when we have transparency, and
    * so it is easy to determine the RGB values of the background color
    * from the info_ptr struct. */
   if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
   {
      png_ptr->background.index = buf[0];
      if (info_ptr && info_ptr->num_palette)
      {
          if (buf[0] >= info_ptr->num_palette)
          {
             png_warning(png_ptr, "Incorrect bKGD chunk index value");
             return;
          }
          png_ptr->background.red =
             (png_uint_16)png_ptr->palette[buf[0]].red;
          png_ptr->background.green =
             (png_uint_16)png_ptr->palette[buf[0]].green;
          png_ptr->background.blue =
             (png_uint_16)png_ptr->palette[buf[0]].blue;
      }
   }
   else if (!(png_ptr->color_type & PNG_COLOR_MASK_COLOR)) /* GRAY */
   {
      png_ptr->background.red =
      png_ptr->background.green =
      png_ptr->background.blue =
      png_ptr->background.gray = png_get_uint_16(buf);
   }
   else
   {
      png_ptr->background.red = png_get_uint_16(buf);
      png_ptr->background.green = png_get_uint_16(buf + 2);
      png_ptr->background.blue = png_get_uint_16(buf + 4);
   }

   png_set_bKGD(png_ptr, info_ptr, &(png_ptr->background));
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
subq $0x10, %rsp
movl %edx, %ebp
movq %rsi, %r14
movq %rdi, %rbx
movl 0x11c(%rdi), %ecx
testb $0x1, %cl
jne 0x8cdcc
leaq 0x16f67(%rip), %rsi     # 0xa3c77
movq %rbx, %rdi
callq 0x849c0
movb 0x24e(%rbx), %al
movl %eax, %ecx
andb $0x2, %cl
shrb %cl
cmpb $0x3, %al
movzbl %cl, %eax
leaq 0x2(,%rax,4), %rax
pushq $0x1
popq %rdx
cmovneq %rax, %rdx
movl %ebp, %eax
cmpq %rax, %rdx
jne 0x8cdee
leaq 0xa(%rsp), %rsi
movq %rbx, %rdi
callq 0x8b6d7
movq %rbx, %rdi
xorl %esi, %esi
callq 0x8b703
testl %eax, %eax
jne 0x8ce9a
movb 0x24e(%rbx), %cl
cmpb $0x3, %cl
jne 0x8ce35
movzbl 0xa(%rsp), %eax
movb %al, 0x260(%rbx)
testq %r14, %r14
je 0x8ce88
movzwl 0x20(%r14), %ecx
testw %cx, %cx
je 0x8ce88
cmpw %ax, %cx
jbe 0x8cea3
movq 0x238(%rbx), %rcx
movzwl %ax, %eax
leaq (%rax,%rax,2), %rax
movzbl (%rcx,%rax), %edx
movw %dx, 0x262(%rbx)
movzbl 0x1(%rcx,%rax), %edx
movw %dx, 0x264(%rbx)
movzbl 0x2(%rcx,%rax), %eax
jmp 0x8ce7f
testb $0x4, %cl
jne 0x8cdf7
movb 0x24e(%rbx), %al
cmpb $0x3, %al
setne %dl
andl $0x2, %ecx
shrl %ecx
orb %dl, %cl
jne 0x8ce18
leaq 0x16ebc(%rip), %rsi     # 0xa3ca8
jmp 0x8cdfe
leaq 0x16ee1(%rip), %rsi     # 0xa3cd6
jmp 0x8cdfe
leaq 0x16e92(%rip), %rsi     # 0xa3c90
movq %rbx, %rdi
callq 0x84a53
movq %rbx, %rdi
movl %ebp, %esi
addq $0x10, %rsp
popq %rbx
popq %r14
popq %rbp
jmp 0x8b703
testq %r14, %r14
je 0x8cd1e
testb $0x20, 0x8(%r14)
je 0x8cd1e
leaq 0x16e8e(%rip), %rsi     # 0xa3cc1
jmp 0x8cdfe
movzwl 0xa(%rsp), %eax
rolw $0x8, %ax
testb $0x2, %cl
jne 0x8ce5f
movw %ax, 0x268(%rbx)
movw %ax, 0x266(%rbx)
movw %ax, 0x264(%rbx)
movl $0x262, %ecx            # imm = 0x262
jmp 0x8ce84
movw %ax, 0x262(%rbx)
movzwl 0xc(%rsp), %eax
rolw $0x8, %ax
movw %ax, 0x264(%rbx)
movzwl 0xe(%rsp), %eax
rolw $0x8, %ax
movl $0x266, %ecx            # imm = 0x266
movw %ax, (%rbx,%rcx)
leaq 0x260(%rbx), %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x7ad18
addq $0x10, %rsp
popq %rbx
popq %r14
popq %rbp
retq
leaq 0x16e48(%rip), %rsi     # 0xa3cf2
movq %rbx, %rdi
callq 0x84a53
jmp 0x8ce9a