// File: alan0201tw[P]RayTracer/include/stb_image.h
// Function: stbi__expand_png_palette(stbi__png*, unsigned char*, int, int)
static int stbi__expand_png_palette(stbi__png *a, stbi_uc *palette, int len, int pal_img_n)
{
   stbi__uint32 i, pixel_count = a->s->img_x * a->s->img_y;
   stbi_uc *p, *temp_out, *orig = a->out;

   p = (stbi_uc *) stbi__malloc_mad2(pixel_count, pal_img_n, 0);
   if (p == NULL) return stbi__err("outofmem", "Out of memory");

   // between here and free(out) below, exitting would leak
   temp_out = p;

   if (pal_img_n == 3) {
      for (i=0; i < pixel_count; ++i) {
         int n = orig[i]*4;
         p[0] = palette[n  ];
         p[1] = palette[n+1];
         p[2] = palette[n+2];
         p += 3;
      }
   } else {
      for (i=0; i < pixel_count; ++i) {
         int n = orig[i]*4;
         p[0] = palette[n  ];
         p[1] = palette[n+1];
         p[2] = palette[n+2];
         p[3] = palette[n+3];
         p += 4;
      }
   }
   STBI_FREE(a->out);
   a->out = temp_out;

   STBI_NOTUSED(len);

   return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movl %ecx, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl (%rax), %eax
movq -0x10(%rbp), %rcx
movq (%rcx), %rcx
imull 0x4(%rcx), %eax
movl %eax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x40(%rbp)
movl -0x28(%rbp), %edi
movl -0x20(%rbp), %esi
xorl %edx, %edx
callq 0x66310
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x6be35
leaq 0x152da(%rip), %rdi     # 0x81102
callq 0x56040
movl %eax, -0x4(%rbp)
jmp 0x6bf74
movq -0x30(%rbp), %rax
movq %rax, -0x38(%rbp)
cmpl $0x3, -0x20(%rbp)
jne 0x6bebe
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x28(%rbp), %eax
jae 0x6beb9
movq -0x40(%rbp), %rax
movl -0x24(%rbp), %ecx
movzbl (%rax,%rcx), %eax
shll $0x2, %eax
movl %eax, -0x44(%rbp)
movq -0x18(%rbp), %rax
movslq -0x44(%rbp), %rcx
movb (%rax,%rcx), %cl
movq -0x30(%rbp), %rax
movb %cl, (%rax)
movq -0x18(%rbp), %rax
movl -0x44(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %cl
movq -0x30(%rbp), %rax
movb %cl, 0x1(%rax)
movq -0x18(%rbp), %rax
movl -0x44(%rbp), %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %cl
movq -0x30(%rbp), %rax
movb %cl, 0x2(%rax)
movq -0x30(%rbp), %rax
addq $0x3, %rax
movq %rax, -0x30(%rbp)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x6be4a
jmp 0x6bf54
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x28(%rbp), %eax
jae 0x6bf52
movq -0x40(%rbp), %rax
movl -0x24(%rbp), %ecx
movzbl (%rax,%rcx), %eax
shll $0x2, %eax
movl %eax, -0x48(%rbp)
movq -0x18(%rbp), %rax
movslq -0x48(%rbp), %rcx
movb (%rax,%rcx), %cl
movq -0x30(%rbp), %rax
movb %cl, (%rax)
movq -0x18(%rbp), %rax
movl -0x48(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %cl
movq -0x30(%rbp), %rax
movb %cl, 0x1(%rax)
movq -0x18(%rbp), %rax
movl -0x48(%rbp), %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %cl
movq -0x30(%rbp), %rax
movb %cl, 0x2(%rax)
movq -0x18(%rbp), %rax
movl -0x48(%rbp), %ecx
addl $0x3, %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %cl
movq -0x30(%rbp), %rax
movb %cl, 0x3(%rax)
movq -0x30(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x30(%rbp)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x6bec5
jmp 0x6bf54
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x75e0
movq -0x38(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x18(%rax)
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)