// File: srajangarg[P]raytracer/src/core/stb_image.hpp
// Function: stbi__create_png_image(stbi__png*, unsigned char*, unsigned int, int, int, int, int)
static int stbi__create_png_image(stbi__png *a, stbi_uc *image_data, stbi__uint32 image_data_len, int out_n, int depth, int color, int interlaced)
{
   stbi_uc *final;
   int p;
   if (!interlaced)
      return stbi__create_png_image_raw(a, image_data, image_data_len, out_n, a->s->img_x, a->s->img_y, depth, color);

   // de-interlacing
   final = (stbi_uc *) stbi__malloc(a->s->img_x * a->s->img_y * out_n);
   for (p=0; p < 7; ++p) {
      int xorig[] = { 0,4,0,2,0,1,0 };
      int yorig[] = { 0,0,4,0,2,0,1 };
      int xspc[]  = { 8,8,4,4,2,2,1 };
      int yspc[]  = { 8,8,8,4,4,2,2 };
      int i,j,x,y;
      // pass1_x[4] = 0, pass1_x[5] = 1, pass1_x[12] = 1
      x = (a->s->img_x - xorig[p] + xspc[p]-1) / xspc[p];
      y = (a->s->img_y - yorig[p] + yspc[p]-1) / yspc[p];
      if (x && y) {
         stbi__uint32 img_len = ((((a->s->img_n * x * depth) + 7) >> 3) + 1) * y;
         if (!stbi__create_png_image_raw(a, image_data, image_data_len, out_n, x, y, depth, color)) {
            STBI_FREE(final);
            return 0;
         }
         for (j=0; j < y; ++j) {
            for (i=0; i < x; ++i) {
               int out_y = j*yspc[p]+yorig[p];
               int out_x = i*xspc[p]+xorig[p];
               memcpy(final + out_y*a->s->img_x*out_n + out_x*out_n,
                      a->out + (j*x+i)*out_n, out_n);
            }
         }
         STBI_FREE(a->out);
         image_data += img_len;
         image_data_len -= img_len;
      }
   }
   a->out = final;

   return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xe0, %rsp
movl 0x10(%rbp), %eax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movl %ecx, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
movl %r9d, -0x28(%rbp)
cmpl $0x0, 0x10(%rbp)
jne 0x316e9
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
movl -0x20(%rbp), %ecx
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl (%rax), %r8d
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl 0x4(%rax), %r9d
movl -0x24(%rbp), %r10d
movl -0x28(%rbp), %eax
movl %r10d, (%rsp)
movl %eax, 0x8(%rsp)
callq 0x31ef0
movl %eax, -0x4(%rbp)
jmp 0x31a19
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl (%rax), %eax
movq -0x10(%rbp), %rcx
movq (%rcx), %rcx
imull 0x4(%rcx), %eax
imull -0x20(%rbp), %eax
movl %eax, %eax
movl %eax, %edi
callq 0x27f20
movq %rax, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
cmpl $0x7, -0x34(%rbp)
jge 0x31a06
movq 0x1674a(%rip), %rax     # 0x47e70
movq %rax, -0x50(%rbp)
movq 0x16747(%rip), %rax     # 0x47e78
movq %rax, -0x48(%rbp)
movq 0x16744(%rip), %rax     # 0x47e80
movq %rax, -0x40(%rbp)
movl 0x16742(%rip), %eax     # 0x47e88
movl %eax, -0x38(%rbp)
movq 0x16740(%rip), %rax     # 0x47e90
movq %rax, -0x70(%rbp)
movq 0x1673d(%rip), %rax     # 0x47e98
movq %rax, -0x68(%rbp)
movq 0x1673a(%rip), %rax     # 0x47ea0
movq %rax, -0x60(%rbp)
movl 0x16738(%rip), %eax     # 0x47ea8
movl %eax, -0x58(%rbp)
movq 0x16736(%rip), %rax     # 0x47eb0
movq %rax, -0x90(%rbp)
movq 0x16730(%rip), %rax     # 0x47eb8
movq %rax, -0x88(%rbp)
movq 0x1672a(%rip), %rax     # 0x47ec0
movq %rax, -0x80(%rbp)
movl 0x16728(%rip), %eax     # 0x47ec8
movl %eax, -0x78(%rbp)
movq 0x16726(%rip), %rax     # 0x47ed0
movq %rax, -0xb0(%rbp)
movq 0x16720(%rip), %rax     # 0x47ed8
movq %rax, -0xa8(%rbp)
movq 0x1671a(%rip), %rax     # 0x47ee0
movq %rax, -0xa0(%rbp)
movl 0x16715(%rip), %eax     # 0x47ee8
movl %eax, -0x98(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl (%rax), %eax
movslq -0x34(%rbp), %rcx
subl -0x50(%rbp,%rcx,4), %eax
movslq -0x34(%rbp), %rcx
addl -0x90(%rbp,%rcx,4), %eax
subl $0x1, %eax
movslq -0x34(%rbp), %rcx
xorl %edx, %edx
divl -0x90(%rbp,%rcx,4)
movl %eax, -0xbc(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl 0x4(%rax), %eax
movslq -0x34(%rbp), %rcx
subl -0x70(%rbp,%rcx,4), %eax
movslq -0x34(%rbp), %rcx
addl -0xb0(%rbp,%rcx,4), %eax
subl $0x1, %eax
movslq -0x34(%rbp), %rcx
xorl %edx, %edx
divl -0xb0(%rbp,%rcx,4)
movl %eax, -0xc0(%rbp)
cmpl $0x0, -0xbc(%rbp)
je 0x319f6
cmpl $0x0, -0xc0(%rbp)
je 0x319f6
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl 0x8(%rax), %eax
imull -0xbc(%rbp), %eax
imull -0x24(%rbp), %eax
addl $0x7, %eax
sarl $0x3, %eax
addl $0x1, %eax
imull -0xc0(%rbp), %eax
movl %eax, -0xc4(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
movl -0x20(%rbp), %ecx
movl -0xbc(%rbp), %r8d
movl -0xc0(%rbp), %r9d
movl -0x24(%rbp), %r10d
movl -0x28(%rbp), %eax
movl %r10d, (%rsp)
movl %eax, 0x8(%rsp)
callq 0x31ef0
cmpl $0x0, %eax
jne 0x318cd
movq -0x30(%rbp), %rdi
callq 0x54c0
movl $0x0, -0x4(%rbp)
jmp 0x31a19
movl $0x0, -0xb8(%rbp)
movl -0xb8(%rbp), %eax
cmpl -0xc0(%rbp), %eax
jge 0x319c8
movl $0x0, -0xb4(%rbp)
movl -0xb4(%rbp), %eax
cmpl -0xbc(%rbp), %eax
jge 0x319b2
movl -0xb8(%rbp), %eax
movslq -0x34(%rbp), %rcx
imull -0xb0(%rbp,%rcx,4), %eax
movslq -0x34(%rbp), %rcx
addl -0x70(%rbp,%rcx,4), %eax
movl %eax, -0xc8(%rbp)
movl -0xb4(%rbp), %eax
movslq -0x34(%rbp), %rcx
imull -0x90(%rbp,%rcx,4), %eax
movslq -0x34(%rbp), %rcx
addl -0x50(%rbp,%rcx,4), %eax
movl %eax, -0xcc(%rbp)
movq -0x30(%rbp), %rdi
movl -0xc8(%rbp), %eax
movq -0x10(%rbp), %rcx
movq (%rcx), %rcx
imull (%rcx), %eax
imull -0x20(%rbp), %eax
movl %eax, %eax
addq %rax, %rdi
movl -0xcc(%rbp), %eax
imull -0x20(%rbp), %eax
cltq
addq %rax, %rdi
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rsi
movl -0xb8(%rbp), %eax
imull -0xbc(%rbp), %eax
addl -0xb4(%rbp), %eax
imull -0x20(%rbp), %eax
cltq
addq %rax, %rsi
movslq -0x20(%rbp), %rdx
callq 0x5370
movl -0xb4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xb4(%rbp)
jmp 0x318f3
jmp 0x319b4
movl -0xb8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xb8(%rbp)
jmp 0x318d7
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x54c0
movl -0xc4(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, %ecx
addq %rcx, %rax
movq %rax, -0x18(%rbp)
movl -0xc4(%rbp), %ecx
movl -0x1c(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x1c(%rbp)
jmp 0x319f8
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x31715
movq -0x30(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x18(%rax)
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xe0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)