// File: srajangarg[P]raytracer/src/core/stb_image.hpp
// 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(pixel_count * pal_img_n);
   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), %eax
imull -0x20(%rbp), %eax
movl %eax, %eax
movl %eax, %edi
callq 0x27f20
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x31da8
leaq 0x1624a(%rip), %rdi     # 0x47fe5
callq 0x275b0
movl %eax, -0x4(%rbp)
jmp 0x31ee7
movq -0x30(%rbp), %rax
movq %rax, -0x38(%rbp)
cmpl $0x3, -0x20(%rbp)
jne 0x31e31
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x28(%rbp), %eax
jae 0x31e2c
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 0x31dbd
jmp 0x31ec7
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x28(%rbp), %eax
jae 0x31ec5
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 0x31e38
jmp 0x31ec7
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x54c0
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