// File: lvandeve[P]lodepng/lodepng.cpp
// Function: addChunk_sBIT(ucvector*, LodePNGInfo const*)
static unsigned addChunk_sBIT(ucvector* out, const LodePNGInfo* info) {
  unsigned bitdepth = (info->color.colortype == LCT_PALETTE) ? 8 : info->color.bitdepth;
  unsigned char* chunk = 0;
  if(info->color.colortype == LCT_GREY) {
    if(info->sbit_r == 0 || info->sbit_r > bitdepth) return 115;
    CERROR_TRY_RETURN(lodepng_chunk_init(&chunk, out, 1, "sBIT"));
    chunk[8] = info->sbit_r;
  } else if(info->color.colortype == LCT_RGB || info->color.colortype == LCT_PALETTE) {
    if(info->sbit_r == 0 || info->sbit_g == 0 || info->sbit_b == 0) return 115;
    if(info->sbit_r > bitdepth || info->sbit_g > bitdepth || info->sbit_b > bitdepth) return 115;
    CERROR_TRY_RETURN(lodepng_chunk_init(&chunk, out, 3, "sBIT"));
    chunk[8] = info->sbit_r;
    chunk[9] = info->sbit_g;
    chunk[10] = info->sbit_b;
  } else if(info->color.colortype == LCT_GREY_ALPHA) {
    if(info->sbit_r == 0 || info->sbit_a == 0) return 115;
    if(info->sbit_r > bitdepth || info->sbit_a > bitdepth) return 115;
    CERROR_TRY_RETURN(lodepng_chunk_init(&chunk, out, 2, "sBIT"));
    chunk[8] = info->sbit_r;
    chunk[9] = info->sbit_a;
  } else if(info->color.colortype == LCT_RGBA) {
    if(info->sbit_r == 0 || info->sbit_g == 0 || info->sbit_b == 0 || info->sbit_a == 0 ||
       info->sbit_r > bitdepth || info->sbit_g > bitdepth ||
       info->sbit_b > bitdepth || info->sbit_a > bitdepth) {
      return 115;
    }
    CERROR_TRY_RETURN(lodepng_chunk_init(&chunk, out, 4, "sBIT"));
    chunk[8] = info->sbit_r;
    chunk[9] = info->sbit_g;
    chunk[10] = info->sbit_b;
    chunk[11] = info->sbit_a;
  }
  if(chunk) lodepng_chunk_generate_crc(chunk);
  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x3, 0x10(%rax)
jne 0xfc44
movl $0x8, %eax
movl %eax, -0x3c(%rbp)
jmp 0xfc4e
movq -0x18(%rbp), %rax
movl 0x14(%rax), %eax
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movl %eax, -0x1c(%rbp)
movq $0x0, -0x28(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x0, 0x10(%rax)
jne 0xfcd3
movq -0x18(%rbp), %rax
cmpl $0x0, 0x164(%rax)
je 0xfc82
movq -0x18(%rbp), %rax
movl 0x164(%rax), %eax
cmpl -0x1c(%rbp), %eax
jbe 0xfc8e
movl $0x73, -0x4(%rbp)
jmp 0xff95
movq -0x10(%rbp), %rsi
leaq -0x28(%rbp), %rdi
movl $0x1, %edx
leaq 0xa190e(%rip), %rcx     # 0xb15b0
callq 0x167a0
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
je 0xfcbb
movl -0x2c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0xff95
movq -0x18(%rbp), %rax
movl 0x164(%rax), %eax
movb %al, %cl
movq -0x28(%rbp), %rax
movb %cl, 0x8(%rax)
jmp 0xff7e
movq -0x18(%rbp), %rax
cmpl $0x2, 0x10(%rax)
je 0xfceb
movq -0x18(%rbp), %rax
cmpl $0x3, 0x10(%rax)
jne 0xfdc2
movq -0x18(%rbp), %rax
cmpl $0x0, 0x164(%rax)
je 0xfd12
movq -0x18(%rbp), %rax
cmpl $0x0, 0x168(%rax)
je 0xfd12
movq -0x18(%rbp), %rax
cmpl $0x0, 0x16c(%rax)
jne 0xfd1e
movl $0x73, -0x4(%rbp)
jmp 0xff95
movq -0x18(%rbp), %rax
movl 0x164(%rax), %eax
cmpl -0x1c(%rbp), %eax
ja 0xfd4b
movq -0x18(%rbp), %rax
movl 0x168(%rax), %eax
cmpl -0x1c(%rbp), %eax
ja 0xfd4b
movq -0x18(%rbp), %rax
movl 0x16c(%rax), %eax
cmpl -0x1c(%rbp), %eax
jbe 0xfd57
movl $0x73, -0x4(%rbp)
jmp 0xff95
movq -0x10(%rbp), %rsi
leaq -0x28(%rbp), %rdi
movl $0x3, %edx
leaq 0xa1845(%rip), %rcx     # 0xb15b0
callq 0x167a0
movl %eax, -0x30(%rbp)
cmpl $0x0, -0x30(%rbp)
je 0xfd84
movl -0x30(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0xff95
movq -0x18(%rbp), %rax
movl 0x164(%rax), %eax
movb %al, %cl
movq -0x28(%rbp), %rax
movb %cl, 0x8(%rax)
movq -0x18(%rbp), %rax
movl 0x168(%rax), %eax
movb %al, %cl
movq -0x28(%rbp), %rax
movb %cl, 0x9(%rax)
movq -0x18(%rbp), %rax
movl 0x16c(%rax), %eax
movb %al, %cl
movq -0x28(%rbp), %rax
movb %cl, 0xa(%rax)
jmp 0xff7c
movq -0x18(%rbp), %rax
cmpl $0x4, 0x10(%rax)
jne 0xfe78
movq -0x18(%rbp), %rax
cmpl $0x0, 0x164(%rax)
je 0xfdea
movq -0x18(%rbp), %rax
cmpl $0x0, 0x170(%rax)
jne 0xfdf6
movl $0x73, -0x4(%rbp)
jmp 0xff95
movq -0x18(%rbp), %rax
movl 0x164(%rax), %eax
cmpl -0x1c(%rbp), %eax
ja 0xfe14
movq -0x18(%rbp), %rax
movl 0x170(%rax), %eax
cmpl -0x1c(%rbp), %eax
jbe 0xfe20
movl $0x73, -0x4(%rbp)
jmp 0xff95
movq -0x10(%rbp), %rsi
leaq -0x28(%rbp), %rdi
movl $0x2, %edx
leaq 0xa177c(%rip), %rcx     # 0xb15b0
callq 0x167a0
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
je 0xfe4d
movl -0x34(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0xff95
movq -0x18(%rbp), %rax
movl 0x164(%rax), %eax
movb %al, %cl
movq -0x28(%rbp), %rax
movb %cl, 0x8(%rax)
movq -0x18(%rbp), %rax
movl 0x170(%rax), %eax
movb %al, %cl
movq -0x28(%rbp), %rax
movb %cl, 0x9(%rax)
jmp 0xff7a
movq -0x18(%rbp), %rax
cmpl $0x6, 0x10(%rax)
jne 0xff78
movq -0x18(%rbp), %rax
cmpl $0x0, 0x164(%rax)
je 0xfef6
movq -0x18(%rbp), %rax
cmpl $0x0, 0x168(%rax)
je 0xfef6
movq -0x18(%rbp), %rax
cmpl $0x0, 0x16c(%rax)
je 0xfef6
movq -0x18(%rbp), %rax
cmpl $0x0, 0x170(%rax)
je 0xfef6
movq -0x18(%rbp), %rax
movl 0x164(%rax), %eax
cmpl -0x1c(%rbp), %eax
ja 0xfef6
movq -0x18(%rbp), %rax
movl 0x168(%rax), %eax
cmpl -0x1c(%rbp), %eax
ja 0xfef6
movq -0x18(%rbp), %rax
movl 0x16c(%rax), %eax
cmpl -0x1c(%rbp), %eax
ja 0xfef6
movq -0x18(%rbp), %rax
movl 0x170(%rax), %eax
cmpl -0x1c(%rbp), %eax
jbe 0xff02
movl $0x73, -0x4(%rbp)
jmp 0xff95
movq -0x10(%rbp), %rsi
leaq -0x28(%rbp), %rdi
movl $0x4, %edx
leaq 0xa169a(%rip), %rcx     # 0xb15b0
callq 0x167a0
movl %eax, -0x38(%rbp)
cmpl $0x0, -0x38(%rbp)
je 0xff2c
movl -0x38(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0xff95
movq -0x18(%rbp), %rax
movl 0x164(%rax), %eax
movb %al, %cl
movq -0x28(%rbp), %rax
movb %cl, 0x8(%rax)
movq -0x18(%rbp), %rax
movl 0x168(%rax), %eax
movb %al, %cl
movq -0x28(%rbp), %rax
movb %cl, 0x9(%rax)
movq -0x18(%rbp), %rax
movl 0x16c(%rax), %eax
movb %al, %cl
movq -0x28(%rbp), %rax
movb %cl, 0xa(%rax)
movq -0x18(%rbp), %rax
movl 0x170(%rax), %eax
movb %al, %cl
movq -0x28(%rbp), %rax
movb %cl, 0xb(%rax)
jmp 0xff7a
jmp 0xff7c
jmp 0xff7e
cmpq $0x0, -0x28(%rbp)
je 0xff8e
movq -0x28(%rbp), %rdi
callq 0x5020
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nop