// File: /workspace/github_cpp_makefile_star2_O1/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), %eax
testb $0x1, %al
jne 0x9bc96
leaq 0x1739b(%rip), %rsi     # 0xb2f73
movq %rbx, %rdi
callq 0x92dd0
movb 0x24e(%rbx), %al
movl %eax, %ecx
andb $0x2, %cl
shrb %cl
cmpb $0x3, %al
movzbl %cl, %eax
leaq 0x2(,%rax,4), %rax
movl $0x1, %edx
cmovneq %rax, %rdx
movl %ebp, %eax
cmpq %rax, %rdx
jne 0x9bcb0
leaq 0xa(%rsp), %rsi
movq %rbx, %rdi
callq 0x9a4db
movq %rbx, %rdi
xorl %esi, %esi
callq 0x9a507
testl %eax, %eax
jne 0x9bd5c
movb 0x24e(%rbx), %cl
cmpb $0x3, %cl
jne 0x9bcf7
movzbl 0xa(%rsp), %eax
movb %al, 0x260(%rbx)
testq %r14, %r14
je 0x9bd4a
movzwl 0x20(%r14), %ecx
testw %cx, %cx
je 0x9bd4a
cmpw %ax, %cx
jbe 0x9bd65
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 0x9bd41
testb $0x4, %al
jne 0x9bcb9
testb $0x2, %al
jne 0x9bcda
cmpb $0x3, 0x24e(%rbx)
jne 0x9bcda
leaq 0x172f6(%rip), %rsi     # 0xb2fa4
jmp 0x9bcc0
leaq 0x1731b(%rip), %rsi     # 0xb2fd2
jmp 0x9bcc0
leaq 0x172cc(%rip), %rsi     # 0xb2f8c
movq %rbx, %rdi
callq 0x92e6e
movq %rbx, %rdi
movl %ebp, %esi
addq $0x10, %rsp
popq %rbx
popq %r14
popq %rbp
jmp 0x9a507
testq %r14, %r14
je 0x9bbe0
testb $0x20, 0x8(%r14)
je 0x9bbe0
leaq 0x172c8(%rip), %rsi     # 0xb2fbd
jmp 0x9bcc0
movzwl 0xa(%rsp), %eax
rolw $0x8, %ax
testb $0x2, %cl
jne 0x9bd21
movw %ax, 0x268(%rbx)
movw %ax, 0x266(%rbx)
movw %ax, 0x264(%rbx)
movl $0x262, %ecx            # imm = 0x262
jmp 0x9bd46
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 0x887a4
addq $0x10, %rsp
popq %rbx
popq %r14
popq %rbp
retq
leaq 0x17282(%rip), %rsi     # 0xb2fee
movq %rbx, %rdi
callq 0x92e6e
jmp 0x9bd5c