// File: Lut99[P]RayTracer/src/lib/LodePNG.cpp
// Function: readChunk_bKGD(LodePNGInfo*, unsigned char const*, unsigned long)
static unsigned readChunk_bKGD(LodePNGInfo* info, const unsigned char* data, size_t chunkLength) {
  if(info->color.colortype == LCT_PALETTE) {
    /*error: this chunk must be 1 byte for indexed color image*/
    if(chunkLength != 1) return 43;

    /*error: invalid palette index, or maybe this chunk appeared before PLTE*/
    if(data[0] >= info->color.palettesize) return 103;

    info->background_defined = 1;
    info->background_r = info->background_g = info->background_b = data[0];
  } else if(info->color.colortype == LCT_GREY || info->color.colortype == LCT_GREY_ALPHA) {
    /*error: this chunk must be 2 bytes for grayscale image*/
    if(chunkLength != 2) return 44;

    /*the values are truncated to bitdepth in the PNG file*/
    info->background_defined = 1;
    info->background_r = info->background_g = info->background_b = 256u * data[0] + data[1];
  } else if(info->color.colortype == LCT_RGB || info->color.colortype == LCT_RGBA) {
    /*error: this chunk must be 6 bytes for grayscale image*/
    if(chunkLength != 6) return 45;

    /*the values are truncated to bitdepth in the PNG file*/
    info->background_defined = 1;
    info->background_r = 256u * data[0] + data[1];
    info->background_g = 256u * data[2] + data[3];
    info->background_b = 256u * data[4] + data[5];
  }

  return 0; /* OK */
}

// Assembly:
movq %rdi, -0x10(%rsp)
movq %rsi, -0x18(%rsp)
movq %rdx, -0x20(%rsp)
movq -0x10(%rsp), %rax
cmpl $0x3, 0x10(%rax)
jne 0x1450d0
cmpq $0x1, -0x20(%rsp)
je 0x14507f
movl $0x2b, -0x4(%rsp)
jmp 0x1451d6
movq -0x18(%rsp), %rax
movzbl (%rax), %eax
movq -0x10(%rsp), %rcx
cmpq 0x20(%rcx), %rax
jb 0x14509f
movl $0x67, -0x4(%rsp)
jmp 0x1451d6
movq -0x10(%rsp), %rax
movl $0x1, 0x38(%rax)
movq -0x18(%rsp), %rax
movzbl (%rax), %ecx
movq -0x10(%rsp), %rax
movl %ecx, 0x44(%rax)
movq -0x10(%rsp), %rax
movl %ecx, 0x40(%rax)
movq -0x10(%rsp), %rax
movl %ecx, 0x3c(%rax)
jmp 0x1451ce
movq -0x10(%rsp), %rax
cmpl $0x0, 0x10(%rax)
je 0x1450e6
movq -0x10(%rsp), %rax
cmpl $0x4, 0x10(%rax)
jne 0x14513a
cmpq $0x2, -0x20(%rsp)
je 0x1450fb
movl $0x2c, -0x4(%rsp)
jmp 0x1451d6
movq -0x10(%rsp), %rax
movl $0x1, 0x38(%rax)
movq -0x18(%rsp), %rax
movzbl (%rax), %ecx
shll $0x8, %ecx
movq -0x18(%rsp), %rax
movzbl 0x1(%rax), %eax
addl %eax, %ecx
movq -0x10(%rsp), %rax
movl %ecx, 0x44(%rax)
movq -0x10(%rsp), %rax
movl %ecx, 0x40(%rax)
movq -0x10(%rsp), %rax
movl %ecx, 0x3c(%rax)
jmp 0x1451cc
movq -0x10(%rsp), %rax
cmpl $0x2, 0x10(%rax)
je 0x145150
movq -0x10(%rsp), %rax
cmpl $0x6, 0x10(%rax)
jne 0x1451ca
cmpq $0x6, -0x20(%rsp)
je 0x145162
movl $0x2d, -0x4(%rsp)
jmp 0x1451d6
movq -0x10(%rsp), %rax
movl $0x1, 0x38(%rax)
movq -0x18(%rsp), %rax
movzbl (%rax), %ecx
shll $0x8, %ecx
movq -0x18(%rsp), %rax
movzbl 0x1(%rax), %eax
addl %eax, %ecx
movq -0x10(%rsp), %rax
movl %ecx, 0x3c(%rax)
movq -0x18(%rsp), %rax
movzbl 0x2(%rax), %ecx
shll $0x8, %ecx
movq -0x18(%rsp), %rax
movzbl 0x3(%rax), %eax
addl %eax, %ecx
movq -0x10(%rsp), %rax
movl %ecx, 0x40(%rax)
movq -0x18(%rsp), %rax
movzbl 0x4(%rax), %ecx
shll $0x8, %ecx
movq -0x18(%rsp), %rax
movzbl 0x5(%rax), %eax
addl %eax, %ecx
movq -0x10(%rsp), %rax
movl %ecx, 0x44(%rax)
jmp 0x1451cc
jmp 0x1451ce
movl $0x0, -0x4(%rsp)
movl -0x4(%rsp), %eax
retq
nopl (%rax,%rax)