// File: lvandeve[P]lodepng/lodepng.cpp
// Function: addChunk_tRNS(ucvector*, LodePNGColorMode const*)
static unsigned addChunk_tRNS(ucvector* out, const LodePNGColorMode* info) {
  unsigned char* chunk = 0;

  if(info->colortype == LCT_PALETTE) {
    size_t i, amount = info->palettesize;
    /*the tail of palette values that all have 255 as alpha, does not have to be encoded*/
    for(i = info->palettesize; i != 0; --i) {
      if(info->palette[4 * (i - 1) + 3] != 255) break;
      --amount;
    }
    if(amount) {
      CERROR_TRY_RETURN(lodepng_chunk_init(&chunk, out, amount, "tRNS"));
      /*add the alpha channel values from the palette*/
      for(i = 0; i != amount; ++i) chunk[8 + i] = info->palette[4 * i + 3];
    }
  } else if(info->colortype == LCT_GREY) {
    if(info->key_defined) {
      CERROR_TRY_RETURN(lodepng_chunk_init(&chunk, out, 2, "tRNS"));
      chunk[8] = (unsigned char)(info->key_r >> 8);
      chunk[9] = (unsigned char)(info->key_r & 255);
    }
  } else if(info->colortype == LCT_RGB) {
    if(info->key_defined) {
      CERROR_TRY_RETURN(lodepng_chunk_init(&chunk, out, 6, "tRNS"));
      chunk[8] = (unsigned char)(info->key_r >> 8);
      chunk[9] = (unsigned char)(info->key_r & 255);
      chunk[10] = (unsigned char)(info->key_g >> 8);
      chunk[11] = (unsigned char)(info->key_g & 255);
      chunk[12] = (unsigned char)(info->key_b >> 8);
      chunk[13] = (unsigned char)(info->key_b & 255);
    }
  }

  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 $0x0, -0x20(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x3, (%rax)
jne 0x1020d
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x10190
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x28(%rbp), %rcx
subq $0x1, %rcx
shlq $0x2, %rcx
movzbl 0x3(%rax,%rcx), %eax
cmpl $0xff, %eax
je 0x10176
jmp 0x10190
movq -0x30(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x1014d
cmpq $0x0, -0x30(%rbp)
je 0x10208
movq -0x10(%rbp), %rsi
movq -0x30(%rbp), %rdx
leaq -0x20(%rbp), %rdi
leaq 0xa13bb(%rip), %rcx     # 0xb1565
callq 0x167a0
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
je 0x101c3
movl -0x34(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x10357
movq $0x0, -0x28(%rbp)
movq -0x28(%rbp), %rax
cmpq -0x30(%rbp), %rax
je 0x10206
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x28(%rbp), %rcx
shlq $0x2, %rcx
movb 0x3(%rax,%rcx), %dl
movq -0x20(%rbp), %rax
movq -0x28(%rbp), %rcx
addq $0x8, %rcx
movb %dl, (%rax,%rcx)
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x101cb
jmp 0x10208
jmp 0x10340
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
jne 0x1027a
movq -0x18(%rbp), %rax
cmpl $0x0, 0x18(%rax)
je 0x10275
movq -0x10(%rbp), %rsi
leaq -0x20(%rbp), %rdi
movl $0x2, %edx
leaq 0xa1331(%rip), %rcx     # 0xb1565
callq 0x167a0
movl %eax, -0x38(%rbp)
cmpl $0x0, -0x38(%rbp)
je 0x1024d
movl -0x38(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x10357
movq -0x18(%rbp), %rax
movl 0x1c(%rax), %eax
shrl $0x8, %eax
movb %al, %cl
movq -0x20(%rbp), %rax
movb %cl, 0x8(%rax)
movq -0x18(%rbp), %rax
movl 0x1c(%rax), %eax
andl $0xff, %eax
movb %al, %cl
movq -0x20(%rbp), %rax
movb %cl, 0x9(%rax)
jmp 0x1033e
movq -0x18(%rbp), %rax
cmpl $0x2, (%rax)
jne 0x1033c
movq -0x18(%rbp), %rax
cmpl $0x0, 0x18(%rax)
je 0x1033a
movq -0x10(%rbp), %rsi
leaq -0x20(%rbp), %rdi
movl $0x6, %edx
leaq 0xa12bc(%rip), %rcx     # 0xb1565
callq 0x167a0
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x3c(%rbp)
je 0x102c2
movl -0x3c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x10357
movq -0x18(%rbp), %rax
movl 0x1c(%rax), %eax
shrl $0x8, %eax
movb %al, %cl
movq -0x20(%rbp), %rax
movb %cl, 0x8(%rax)
movq -0x18(%rbp), %rax
movl 0x1c(%rax), %eax
andl $0xff, %eax
movb %al, %cl
movq -0x20(%rbp), %rax
movb %cl, 0x9(%rax)
movq -0x18(%rbp), %rax
movl 0x20(%rax), %eax
shrl $0x8, %eax
movb %al, %cl
movq -0x20(%rbp), %rax
movb %cl, 0xa(%rax)
movq -0x18(%rbp), %rax
movl 0x20(%rax), %eax
andl $0xff, %eax
movb %al, %cl
movq -0x20(%rbp), %rax
movb %cl, 0xb(%rax)
movq -0x18(%rbp), %rax
movl 0x24(%rax), %eax
shrl $0x8, %eax
movb %al, %cl
movq -0x20(%rbp), %rax
movb %cl, 0xc(%rax)
movq -0x18(%rbp), %rax
movl 0x24(%rax), %eax
andl $0xff, %eax
movb %al, %cl
movq -0x20(%rbp), %rax
movb %cl, 0xd(%rax)
jmp 0x1033c
jmp 0x1033e
jmp 0x10340
cmpq $0x0, -0x20(%rbp)
je 0x10350
movq -0x20(%rbp), %rdi
callq 0x5020
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq