// File: /workspace/github_c_makefile_star2_O3/aap[P]pdp11/lodepng.c
// Function: addChunk_sBIT
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 %rbx
subq $0x10, %rsp
movq %rsi, %rbx
movq %rdi, %rsi
movl 0x10(%rbx), %edx
cmpl $0x3, %edx
jne 0x101f1
movq $0x0, 0x8(%rsp)
movl $0x8, %ecx
movl 0x108(%rbx), %edx
movl $0x73, %eax
testl %edx, %edx
je 0x10355
movl 0x10c(%rbx), %edi
testl %edi, %edi
je 0x10355
movl 0x110(%rbx), %r8d
testl %r8d, %r8d
je 0x10355
cmpl %ecx, %edx
seta %dl
cmpl %ecx, %edi
seta %dil
orb %dl, %dil
cmpl %ecx, %r8d
seta %cl
orb %dil, %cl
jne 0x10355
leaq 0x7f24(%rip), %rcx      # 0x180d9
leaq 0x8(%rsp), %rdi
movl $0x3, %edx
callq 0x11d0e
testl %eax, %eax
jne 0x10355
movb 0x108(%rbx), %al
movq 0x8(%rsp), %rdi
movb %al, 0x8(%rdi)
movb 0x10c(%rbx), %al
movb %al, 0x9(%rdi)
movb 0x110(%rbx), %al
movb %al, 0xa(%rdi)
jmp 0x1034e
movl 0x14(%rbx), %ecx
movq $0x0, 0x8(%rsp)
xorl %eax, %eax
cmpl $0x6, %edx
ja 0x10355
movl %edx, %edx
leaq 0x58cf(%rip), %rdi      # 0x15ae0
movslq (%rdi,%rdx,4), %rdx
addq %rdi, %rdx
jmpq *%rdx
movl 0x108(%rbx), %edx
decl %edx
movl $0x73, %eax
cmpl %ecx, %edx
jae 0x10355
leaq 0x7ea3(%rip), %rcx      # 0x180d9
leaq 0x8(%rsp), %rdi
movl $0x1, %edx
callq 0x11d0e
testl %eax, %eax
jne 0x10355
movb 0x108(%rbx), %al
movq 0x8(%rsp), %rdi
movb %al, 0x8(%rdi)
jmp 0x1034e
movl 0x108(%rbx), %edx
movl $0x73, %eax
testl %edx, %edx
je 0x10355
movl 0x114(%rbx), %edi
testl %edi, %edi
je 0x10355
cmpl %ecx, %edx
seta %dl
cmpl %ecx, %edi
seta %cl
orb %dl, %cl
jne 0x10355
leaq 0x7e3f(%rip), %rcx      # 0x180d9
leaq 0x8(%rsp), %rdi
movl $0x2, %edx
callq 0x11d0e
testl %eax, %eax
jne 0x10355
movb 0x108(%rbx), %al
movq 0x8(%rsp), %rdi
movb %al, 0x8(%rdi)
movb 0x114(%rbx), %al
movb %al, 0x9(%rdi)
jmp 0x1034e
movl 0x108(%rbx), %edx
movl $0x73, %eax
testl %edx, %edx
je 0x10355
movl 0x10c(%rbx), %edi
testl %edi, %edi
je 0x10355
movl 0x110(%rbx), %r8d
testl %r8d, %r8d
je 0x10355
cmpl %ecx, %edx
ja 0x10355
cmpl %ecx, %edi
ja 0x10355
cmpl %ecx, %r8d
ja 0x10355
movl 0x114(%rbx), %edx
decl %edx
cmpl %ecx, %edx
jae 0x10355
leaq 0x7dc7(%rip), %rcx      # 0x180d9
leaq 0x8(%rsp), %rdi
movl $0x4, %edx
callq 0x11d0e
testl %eax, %eax
jne 0x10355
movb 0x108(%rbx), %al
movq 0x8(%rsp), %rdi
movb %al, 0x8(%rdi)
movb 0x10c(%rbx), %al
movb %al, 0x9(%rdi)
movb 0x110(%rbx), %al
movb %al, 0xa(%rdi)
movb 0x114(%rbx), %al
movb %al, 0xb(%rdi)
callq 0x9981
xorl %eax, %eax
addq $0x10, %rsp
popq %rbx
retq