// File: phillip-h[P]fractal-gen/lodepng.cpp
// Function: Adam7_deinterlace(unsigned char*, unsigned char const*, unsigned int, unsigned int, unsigned int)
static void Adam7_deinterlace(unsigned char* out, const unsigned char* in, unsigned w, unsigned h, unsigned bpp)
{
  unsigned passw[7], passh[7];
  size_t filter_passstart[8], padded_passstart[8], passstart[8];
  unsigned i;

  Adam7_getpassvalues(passw, passh, filter_passstart, padded_passstart, passstart, w, h, bpp);

  if(bpp >= 8)
  {
    for(i = 0; i != 7; ++i)
    {
      unsigned x, y, b;
      size_t bytewidth = bpp / 8;
      for(y = 0; y < passh[i]; ++y)
      for(x = 0; x < passw[i]; ++x)
      {
        size_t pixelinstart = passstart[i] + (y * passw[i] + x) * bytewidth;
        size_t pixeloutstart = ((ADAM7_IY[i] + y * ADAM7_DY[i]) * w + ADAM7_IX[i] + x * ADAM7_DX[i]) * bytewidth;
        for(b = 0; b < bytewidth; ++b)
        {
          out[pixeloutstart + b] = in[pixelinstart + b];
        }
      }
    }
  }
  else /*bpp < 8: Adam7 with pixels < 8 bit is a bit trickier: with bit pointers*/
  {
    for(i = 0; i != 7; ++i)
    {
      unsigned x, y, b;
      unsigned ilinebits = bpp * passw[i];
      unsigned olinebits = bpp * w;
      size_t obp, ibp; /*bit pointers (for out and in buffer)*/
      for(y = 0; y < passh[i]; ++y)
      for(x = 0; x < passw[i]; ++x)
      {
        ibp = (8 * passstart[i]) + (y * ilinebits + x * bpp);
        obp = (ADAM7_IY[i] + y * ADAM7_DY[i]) * olinebits + (ADAM7_IX[i] + x * ADAM7_DX[i]) * bpp;
        for(b = 0; b < bpp; ++b)
        {
          unsigned char bit = readBitFromReversedStream(&ibp, in);
          /*note that this function assumes the out buffer is completely 0, use setBitOfReversedStream otherwise*/
          setBitOfReversedStream0(&obp, out, bit);
        }
      }
    }
  }
}

// Assembly:
subq $0x188, %rsp            # imm = 0x188
movq %rdi, 0x180(%rsp)
movq %rsi, 0x178(%rsp)
movl %edx, 0x174(%rsp)
movl %ecx, 0x170(%rsp)
movl %r8d, 0x16c(%rsp)
leaq 0x150(%rsp), %rdi
leaq 0x130(%rsp), %rsi
leaq 0xf0(%rsp), %rdx
leaq 0xb0(%rsp), %rcx
leaq 0x70(%rsp), %r8
movl 0x174(%rsp), %r9d
movl 0x170(%rsp), %r10d
movl 0x16c(%rsp), %eax
movl %r10d, (%rsp)
movl %eax, 0x8(%rsp)
callq 0x176c0
cmpl $0x8, 0x16c(%rsp)
jb 0x17b3b
movl $0x0, 0x6c(%rsp)
cmpl $0x7, 0x6c(%rsp)
je 0x17b36
movl 0x16c(%rsp), %eax
shrl $0x3, %eax
movl %eax, %eax
movq %rax, 0x58(%rsp)
movl $0x0, 0x64(%rsp)
movl 0x64(%rsp), %eax
movl 0x6c(%rsp), %ecx
cmpl 0x130(%rsp,%rcx,4), %eax
jae 0x17b24
movl $0x0, 0x68(%rsp)
movl 0x68(%rsp), %eax
movl 0x6c(%rsp), %ecx
cmpl 0x150(%rsp,%rcx,4), %eax
jae 0x17b12
movl 0x6c(%rsp), %eax
movq 0x70(%rsp,%rax,8), %rax
movl 0x64(%rsp), %ecx
movl 0x6c(%rsp), %edx
imull 0x150(%rsp,%rdx,4), %ecx
addl 0x68(%rsp), %ecx
movl %ecx, %ecx
imulq 0x58(%rsp), %rcx
addq %rcx, %rax
movq %rax, 0x50(%rsp)
movl 0x6c(%rsp), %eax
movl %eax, %ecx
leaq 0x4dd4(%rip), %rax      # 0x1c830
movl (%rax,%rcx,4), %eax
movl 0x64(%rsp), %ecx
movl 0x6c(%rsp), %edx
movl %edx, %esi
leaq 0x4da0(%rip), %rdx      # 0x1c810
imull (%rdx,%rsi,4), %ecx
addl %ecx, %eax
imull 0x174(%rsp), %eax
movl 0x6c(%rsp), %ecx
movl %ecx, %edx
leaq 0x4d65(%rip), %rcx      # 0x1c7f0
addl (%rcx,%rdx,4), %eax
movl 0x68(%rsp), %ecx
movl 0x6c(%rsp), %edx
movl %edx, %esi
leaq 0x4d31(%rip), %rdx      # 0x1c7d0
imull (%rdx,%rsi,4), %ecx
addl %ecx, %eax
movl %eax, %eax
imulq 0x58(%rsp), %rax
movq %rax, 0x48(%rsp)
movl $0x0, 0x60(%rsp)
movl 0x60(%rsp), %eax
cmpq 0x58(%rsp), %rax
jae 0x17b00
movq 0x178(%rsp), %rax
movq 0x50(%rsp), %rcx
movl 0x60(%rsp), %edx
addq %rdx, %rcx
movb (%rax,%rcx), %dl
movq 0x180(%rsp), %rax
movq 0x48(%rsp), %rcx
movl 0x60(%rsp), %esi
addq %rsi, %rcx
movb %dl, (%rax,%rcx)
movl 0x60(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x60(%rsp)
jmp 0x17aba
jmp 0x17b02
movl 0x68(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x68(%rsp)
jmp 0x17a0d
jmp 0x17b14
movl 0x64(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x64(%rsp)
jmp 0x179f0
jmp 0x17b26
movl 0x6c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x6c(%rsp)
jmp 0x179cc
jmp 0x17ccb
movl $0x0, 0x6c(%rsp)
cmpl $0x7, 0x6c(%rsp)
je 0x17cc9
movl 0x16c(%rsp), %eax
movl 0x6c(%rsp), %ecx
imull 0x150(%rsp,%rcx,4), %eax
movl %eax, 0x38(%rsp)
movl 0x16c(%rsp), %eax
imull 0x174(%rsp), %eax
movl %eax, 0x34(%rsp)
movl $0x0, 0x40(%rsp)
movl 0x40(%rsp), %eax
movl 0x6c(%rsp), %ecx
cmpl 0x130(%rsp,%rcx,4), %eax
jae 0x17cb7
movl $0x0, 0x44(%rsp)
movl 0x44(%rsp), %eax
movl 0x6c(%rsp), %ecx
cmpl 0x150(%rsp,%rcx,4), %eax
jae 0x17ca5
movl 0x6c(%rsp), %eax
movq 0x70(%rsp,%rax,8), %rax
shlq $0x3, %rax
movl 0x40(%rsp), %ecx
imull 0x38(%rsp), %ecx
movl 0x44(%rsp), %edx
imull 0x16c(%rsp), %edx
addl %edx, %ecx
movl %ecx, %ecx
addq %rcx, %rax
movq %rax, 0x20(%rsp)
movl 0x6c(%rsp), %eax
movl %eax, %ecx
leaq 0x4c43(%rip), %rax      # 0x1c830
movl (%rax,%rcx,4), %eax
movl 0x40(%rsp), %ecx
movl 0x6c(%rsp), %edx
movl %edx, %esi
leaq 0x4c0f(%rip), %rdx      # 0x1c810
imull (%rdx,%rsi,4), %ecx
addl %ecx, %eax
imull 0x34(%rsp), %eax
movl 0x6c(%rsp), %ecx
movl %ecx, %edx
leaq 0x4bd7(%rip), %rcx      # 0x1c7f0
movl (%rcx,%rdx,4), %ecx
movl 0x44(%rsp), %edx
movl 0x6c(%rsp), %esi
movl %esi, %edi
leaq 0x4ba3(%rip), %rsi      # 0x1c7d0
imull (%rsi,%rdi,4), %edx
addl %edx, %ecx
imull 0x16c(%rsp), %ecx
addl %ecx, %eax
movl %eax, %eax
movq %rax, 0x28(%rsp)
movl $0x0, 0x3c(%rsp)
movl 0x3c(%rsp), %eax
cmpl 0x16c(%rsp), %eax
jae 0x17c93
movq 0x178(%rsp), %rsi
leaq 0x20(%rsp), %rdi
callq 0x15fe0
movb %al, 0x1f(%rsp)
movq 0x180(%rsp), %rsi
leaq 0x28(%rsp), %rdi
movzbl 0x1f(%rsp), %edx
callq 0x18340
movl 0x3c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x3c(%rsp)
jmp 0x17c4c
jmp 0x17c95
movl 0x44(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x44(%rsp)
jmp 0x17b9d
jmp 0x17ca7
movl 0x40(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x40(%rsp)
jmp 0x17b80
jmp 0x17cb9
movl 0x6c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x6c(%rsp)
jmp 0x17b43
jmp 0x17ccb
addq $0x188, %rsp            # imm = 0x188
retq
nopw %cs:(%rax,%rax)