// File: phillip-h[P]fractal-gen/lodepng.cpp
// Function: deflateNoCompression(ucvector*, unsigned char const*, unsigned long)
static unsigned deflateNoCompression(ucvector* out, const unsigned char* data, size_t datasize)
{
  /*non compressed deflate block data: 1 bit BFINAL,2 bits BTYPE,(5 bits): it jumps to start of next byte,
  2 bytes LEN, 2 bytes NLEN, LEN bytes literal DATA*/

  size_t i, j, numdeflateblocks = (datasize + 65534) / 65535;
  unsigned datapos = 0;
  for(i = 0; i != numdeflateblocks; ++i)
  {
    unsigned BFINAL, BTYPE, LEN, NLEN;
    unsigned char firstbyte;

    BFINAL = (i == numdeflateblocks - 1);
    BTYPE = 0;

    firstbyte = (unsigned char)(BFINAL + ((BTYPE & 1) << 1) + ((BTYPE & 2) << 1));
    ucvector_push_back(out, firstbyte);

    LEN = 65535;
    if(datasize - datapos < 65535) LEN = (unsigned)datasize - datapos;
    NLEN = 65535 - LEN;

    ucvector_push_back(out, (unsigned char)(LEN & 255));
    ucvector_push_back(out, (unsigned char)(LEN >> 8));
    ucvector_push_back(out, (unsigned char)(NLEN & 255));
    ucvector_push_back(out, (unsigned char)(NLEN >> 8));

    /*Decompressed data*/
    for(j = 0; j < 65535 && datapos < datasize; ++j)
    {
      ucvector_push_back(out, data[datapos++]);
    }
  }

  return 0;
}

// Assembly:
subq $0x48, %rsp
movq %rdi, 0x40(%rsp)
movq %rsi, 0x38(%rsp)
movq %rdx, 0x30(%rsp)
movq 0x30(%rsp), %rax
addq $0xfffe, %rax           # imm = 0xFFFE
movl $0xffff, %ecx           # imm = 0xFFFF
xorl %edx, %edx
divq %rcx
movq %rax, 0x18(%rsp)
movl $0x0, 0x14(%rsp)
movq $0x0, 0x28(%rsp)
movq 0x28(%rsp), %rax
cmpq 0x18(%rsp), %rax
je 0x13785
movq 0x28(%rsp), %rax
movq 0x18(%rsp), %rcx
subq $0x1, %rcx
cmpq %rcx, %rax
sete %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, 0x10(%rsp)
movl $0x0, 0xc(%rsp)
movl 0x10(%rsp), %eax
movl 0xc(%rsp), %ecx
andl $0x1, %ecx
shll %ecx
addl %ecx, %eax
movl 0xc(%rsp), %ecx
andl $0x2, %ecx
shll %ecx
addl %ecx, %eax
movb %al, 0x3(%rsp)
movq 0x40(%rsp), %rdi
movzbl 0x3(%rsp), %esi
callq 0x81d0
movl $0xffff, 0x8(%rsp)      # imm = 0xFFFF
movq 0x30(%rsp), %rax
movl 0x14(%rsp), %ecx
subq %rcx, %rax
cmpq $0xffff, %rax           # imm = 0xFFFF
jae 0x136a9
movq 0x30(%rsp), %rax
subl 0x14(%rsp), %eax
movl %eax, 0x8(%rsp)
movl $0xffff, %eax           # imm = 0xFFFF
subl 0x8(%rsp), %eax
movl %eax, 0x4(%rsp)
movq 0x40(%rsp), %rdi
movl 0x8(%rsp), %eax
andl $0xff, %eax
movzbl %al, %esi
callq 0x81d0
movq 0x40(%rsp), %rdi
movl 0x8(%rsp), %eax
shrl $0x8, %eax
movzbl %al, %esi
callq 0x81d0
movq 0x40(%rsp), %rdi
movl 0x4(%rsp), %eax
andl $0xff, %eax
movzbl %al, %esi
callq 0x81d0
movq 0x40(%rsp), %rdi
movl 0x4(%rsp), %eax
shrl $0x8, %eax
movzbl %al, %esi
callq 0x81d0
movq $0x0, 0x20(%rsp)
xorl %eax, %eax
cmpq $0xffff, 0x20(%rsp)     # imm = 0xFFFF
movb %al, 0x2(%rsp)
jae 0x13734
movl 0x14(%rsp), %eax
cmpq 0x30(%rsp), %rax
setb %al
movb %al, 0x2(%rsp)
movb 0x2(%rsp), %al
testb $0x1, %al
jne 0x1373e
jmp 0x13770
movq 0x40(%rsp), %rdi
movq 0x38(%rsp), %rax
movl 0x14(%rsp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, 0x14(%rsp)
movl %ecx, %ecx
movzbl (%rax,%rcx), %esi
callq 0x81d0
movq 0x20(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x20(%rsp)
jmp 0x13713
jmp 0x13772
movq 0x28(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x28(%rsp)
jmp 0x1361e
xorl %eax, %eax
addq $0x48, %rsp
retq
nopl (%rax)