// File: tomfunkhouser[P]gaps/pkgs/png/pngwutil.c
// Function: png_write_tRNS
void /* PRIVATE */
png_write_tRNS(png_structp png_ptr, png_bytep trans_alpha, png_color_16p tran,
   int num_trans, int color_type)
{
   PNG_tRNS;
   png_byte buf[6];

   png_debug(1, "in png_write_tRNS");

   if (color_type == PNG_COLOR_TYPE_PALETTE)
   {
      if (num_trans <= 0 || num_trans > (int)png_ptr->num_palette)
      {
         png_warning(png_ptr, "Invalid number of transparent colors specified");
         return;
      }
      /* Write the chunk out as it is */
      png_write_chunk(png_ptr, (png_bytep)png_tRNS, trans_alpha,
        (png_size_t)num_trans);
   }
   else if (color_type == PNG_COLOR_TYPE_GRAY)
   {
      /* One 16 bit value */
      if (tran->gray >= (1 << png_ptr->bit_depth))
      {
         png_warning(png_ptr,
           "Ignoring attempt to write tRNS chunk out-of-range for bit_depth");
         return;
      }
      png_save_uint_16(buf, tran->gray);
      png_write_chunk(png_ptr, (png_bytep)png_tRNS, buf, (png_size_t)2);
   }
   else if (color_type == PNG_COLOR_TYPE_RGB)
   {
      /* Three 16 bit values */
      png_save_uint_16(buf, tran->red);
      png_save_uint_16(buf + 2, tran->green);
      png_save_uint_16(buf + 4, tran->blue);
      if (png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4]))
      {
         png_warning(png_ptr,
           "Ignoring attempt to write 16-bit tRNS chunk when bit_depth is 8");
         return;
      }
      png_write_chunk(png_ptr, (png_bytep)png_tRNS, buf, (png_size_t)6);
   }
   else
   {
      png_warning(png_ptr, "Can't write tRNS with an alpha channel");
   }
}

// Assembly:
subq $0x38, %rsp
movq %rdi, 0x30(%rsp)
movq %rsi, 0x28(%rsp)
movq %rdx, 0x20(%rsp)
movl %ecx, 0x1c(%rsp)
movl %r8d, 0x18(%rsp)
movl 0x1278f(%rip), %eax     # 0x13f891
movl %eax, 0x13(%rsp)
movb 0x12789(%rip), %al      # 0x13f895
movb %al, 0x17(%rsp)
cmpl $0x3, 0x18(%rsp)
jne 0x12d166
cmpl $0x0, 0x1c(%rsp)
jle 0x12d132
movl 0x1c(%rsp), %eax
movq 0x30(%rsp), %rcx
movzwl 0x240(%rcx), %ecx
cmpl %ecx, %eax
jle 0x12d148
movq 0x30(%rsp), %rdi
leaq 0x13756(%rip), %rsi     # 0x140894
callq 0x113940
jmp 0x12d28e
movq 0x30(%rsp), %rdi
leaq 0x13(%rsp), %rsi
movq 0x28(%rsp), %rdx
movslq 0x1c(%rsp), %rcx
callq 0x12b040
jmp 0x12d28e
cmpl $0x0, 0x18(%rsp)
jne 0x12d1d6
movq 0x20(%rsp), %rax
movzwl 0x8(%rax), %eax
movq 0x30(%rsp), %rcx
movzbl 0x24f(%rcx), %ecx
movl $0x1, %edx
shll %cl, %edx
movl %edx, %ecx
cmpl %ecx, %eax
jl 0x12d1a5
movq 0x30(%rsp), %rdi
leaq 0x13728(%rip), %rsi     # 0x1408c3
callq 0x113940
jmp 0x12d28e
leaq 0xd(%rsp), %rdi
movq 0x20(%rsp), %rax
movzwl 0x8(%rax), %esi
callq 0x12af70
movq 0x30(%rsp), %rdi
leaq 0x13(%rsp), %rsi
leaq 0xd(%rsp), %rdx
movl $0x2, %ecx
callq 0x12b040
jmp 0x12d28c
cmpl $0x2, 0x18(%rsp)
jne 0x12d279
leaq 0xd(%rsp), %rdi
movq 0x20(%rsp), %rax
movzwl 0x2(%rax), %esi
callq 0x12af70
leaq 0xd(%rsp), %rdi
addq $0x2, %rdi
movq 0x20(%rsp), %rax
movzwl 0x4(%rax), %esi
callq 0x12af70
leaq 0xd(%rsp), %rdi
addq $0x4, %rdi
movq 0x20(%rsp), %rax
movzwl 0x6(%rax), %esi
callq 0x12af70
movq 0x30(%rsp), %rax
movzbl 0x24f(%rax), %eax
cmpl $0x8, %eax
jne 0x12d25e
movzbl 0xd(%rsp), %eax
movzbl 0xf(%rsp), %ecx
orl %ecx, %eax
movzbl 0x11(%rsp), %ecx
orl %ecx, %eax
cmpl $0x0, %eax
je 0x12d25e
movq 0x30(%rsp), %rdi
leaq 0x136ac(%rip), %rsi     # 0x140903
callq 0x113940
jmp 0x12d28e
movq 0x30(%rsp), %rdi
leaq 0x13(%rsp), %rsi
leaq 0xd(%rsp), %rdx
movl $0x6, %ecx
callq 0x12b040
jmp 0x12d28a
movq 0x30(%rsp), %rdi
leaq 0x136be(%rip), %rsi     # 0x140943
callq 0x113940
jmp 0x12d28c
jmp 0x12d28e
addq $0x38, %rsp
retq
nopw %cs:(%rax,%rax)