// File: /workspace/github_cpp_makefile_star2_O3/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 0x9b2db
leaq 0x17daa(%rip), %rsi     # 0xb2fc7
movq %rbx, %rdi
callq 0x920b4
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 0x9b2fd
leaq 0xa(%rsp), %rsi
movq %rbx, %rdi
callq 0x99b23
movq %rbx, %rdi
xorl %esi, %esi
callq 0x99b4f
testl %eax, %eax
jne 0x9b3a9
movb 0x24e(%rbx), %cl
cmpb $0x3, %cl
jne 0x9b344
movzbl 0xa(%rsp), %eax
movb %al, 0x260(%rbx)
testq %r14, %r14
je 0x9b397
movzwl 0x20(%r14), %ecx
testw %cx, %cx
je 0x9b397
cmpw %ax, %cx
jbe 0x9b3b2
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 0x9b38e
testb $0x4, %cl
jne 0x9b306
movb 0x24e(%rbx), %al
cmpb $0x3, %al
setne %dl
andl $0x2, %ecx
shrl %ecx
orb %dl, %cl
jne 0x9b327
leaq 0x17cfd(%rip), %rsi     # 0xb2ff8
jmp 0x9b30d
leaq 0x17d22(%rip), %rsi     # 0xb3026
jmp 0x9b30d
leaq 0x17cd3(%rip), %rsi     # 0xb2fe0
movq %rbx, %rdi
callq 0x9214d
movq %rbx, %rdi
movl %ebp, %esi
addq $0x10, %rsp
popq %rbx
popq %r14
popq %rbp
jmp 0x99b4f
testq %r14, %r14
je 0x9b22b
testb $0x20, 0x8(%r14)
je 0x9b22b
leaq 0x17ccf(%rip), %rsi     # 0xb3011
jmp 0x9b30d
movzwl 0xa(%rsp), %eax
rolw $0x8, %ax
testb $0x2, %cl
jne 0x9b36e
movw %ax, 0x268(%rbx)
movw %ax, 0x266(%rbx)
movw %ax, 0x264(%rbx)
movl $0x262, %ecx            # imm = 0x262
jmp 0x9b393
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 0x879b4
addq $0x10, %rsp
popq %rbx
popq %r14
popq %rbp
retq
leaq 0x17c89(%rip), %rsi     # 0xb3042
movq %rbx, %rdi
callq 0x9214d
jmp 0x9b3a9