// File: phillip-h[P]fractal-gen/lodepng.cpp
// Function: addChunk_tRNS(ucvector*, LodePNGColorMode const*)
static unsigned addChunk_tRNS(ucvector* out, const LodePNGColorMode* info)
{
  unsigned error = 0;
  size_t i;
  ucvector tRNS;
  ucvector_init(&tRNS);
  if(info->colortype == LCT_PALETTE)
  {
    size_t 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) --amount;
      else break;
    }
    /*add only alpha channel*/
    for(i = 0; i != amount; ++i) ucvector_push_back(&tRNS, info->palette[4 * i + 3]);
  }
  else if(info->colortype == LCT_GREY)
  {
    if(info->key_defined)
    {
      ucvector_push_back(&tRNS, (unsigned char)(info->key_r >> 8));
      ucvector_push_back(&tRNS, (unsigned char)(info->key_r & 255));
    }
  }
  else if(info->colortype == LCT_RGB)
  {
    if(info->key_defined)
    {
      ucvector_push_back(&tRNS, (unsigned char)(info->key_r >> 8));
      ucvector_push_back(&tRNS, (unsigned char)(info->key_r & 255));
      ucvector_push_back(&tRNS, (unsigned char)(info->key_g >> 8));
      ucvector_push_back(&tRNS, (unsigned char)(info->key_g & 255));
      ucvector_push_back(&tRNS, (unsigned char)(info->key_b >> 8));
      ucvector_push_back(&tRNS, (unsigned char)(info->key_b & 255));
    }
  }

  error = addChunk(out, "tRNS", tRNS.data, tRNS.size);
  ucvector_cleanup(&tRNS);

  return error;
}

// Assembly:
subq $0x48, %rsp
movq %rdi, 0x40(%rsp)
movq %rsi, 0x38(%rsp)
movl $0x0, 0x34(%rsp)
leaq 0x10(%rsp), %rdi
callq 0xf580
movq 0x38(%rsp), %rax
cmpl $0x3, (%rax)
jne 0xfa93
movq 0x38(%rsp), %rax
movq 0x10(%rax), %rax
movq %rax, 0x8(%rsp)
movq 0x38(%rsp), %rax
movq 0x10(%rax), %rax
movq %rax, 0x28(%rsp)
cmpq $0x0, 0x28(%rsp)
je 0xfa48
movq 0x38(%rsp), %rax
movq 0x8(%rax), %rax
movq 0x28(%rsp), %rcx
subq $0x1, %rcx
shlq $0x2, %rcx
movzbl 0x3(%rax,%rcx), %eax
cmpl $0xff, %eax
jne 0xfa34
movq 0x8(%rsp), %rax
addq $-0x1, %rax
movq %rax, 0x8(%rsp)
jmp 0xfa36
jmp 0xfa48
jmp 0xfa38
movq 0x28(%rsp), %rax
addq $-0x1, %rax
movq %rax, 0x28(%rsp)
jmp 0xf9fa
movq $0x0, 0x28(%rsp)
movq 0x28(%rsp), %rax
cmpq 0x8(%rsp), %rax
je 0xfa8e
movq 0x38(%rsp), %rax
movq 0x8(%rax), %rax
movq 0x28(%rsp), %rcx
shlq $0x2, %rcx
leaq 0x10(%rsp), %rdi
movzbl 0x3(%rax,%rcx), %esi
callq 0x81d0
movq 0x28(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x28(%rsp)
jmp 0xfa51
jmp 0xfb98
movq 0x38(%rsp), %rax
cmpl $0x0, (%rax)
jne 0xfadf
movq 0x38(%rsp), %rax
cmpl $0x0, 0x18(%rax)
je 0xfada
movq 0x38(%rsp), %rax
movl 0x1c(%rax), %eax
shrl $0x8, %eax
leaq 0x10(%rsp), %rdi
movzbl %al, %esi
callq 0x81d0
movq 0x38(%rsp), %rax
movl 0x1c(%rax), %eax
andl $0xff, %eax
leaq 0x10(%rsp), %rdi
movzbl %al, %esi
callq 0x81d0
jmp 0xfb96
movq 0x38(%rsp), %rax
cmpl $0x2, (%rax)
jne 0xfb94
movq 0x38(%rsp), %rax
cmpl $0x0, 0x18(%rax)
je 0xfb92
movq 0x38(%rsp), %rax
movl 0x1c(%rax), %eax
shrl $0x8, %eax
leaq 0x10(%rsp), %rdi
movzbl %al, %esi
callq 0x81d0
movq 0x38(%rsp), %rax
movl 0x1c(%rax), %eax
andl $0xff, %eax
leaq 0x10(%rsp), %rdi
movzbl %al, %esi
callq 0x81d0
movq 0x38(%rsp), %rax
movl 0x20(%rax), %eax
shrl $0x8, %eax
leaq 0x10(%rsp), %rdi
movzbl %al, %esi
callq 0x81d0
movq 0x38(%rsp), %rax
movl 0x20(%rax), %eax
andl $0xff, %eax
leaq 0x10(%rsp), %rdi
movzbl %al, %esi
callq 0x81d0
movq 0x38(%rsp), %rax
movl 0x24(%rax), %eax
shrl $0x8, %eax
leaq 0x10(%rsp), %rdi
movzbl %al, %esi
callq 0x81d0
movq 0x38(%rsp), %rax
movl 0x24(%rax), %eax
andl $0xff, %eax
leaq 0x10(%rsp), %rdi
movzbl %al, %esi
callq 0x81d0
jmp 0xfb94
jmp 0xfb96
jmp 0xfb98
movq 0x40(%rsp), %rdi
movq 0x10(%rsp), %rdx
movq 0x18(%rsp), %rcx
leaq 0xdbc4(%rip), %rsi      # 0x1d772
callq 0x19c40
movl %eax, 0x34(%rsp)
leaq 0x10(%rsp), %rdi
callq 0x17170
movl 0x34(%rsp), %eax
addq $0x48, %rsp
retq
nopw (%rax,%rax)