// File: mhe[P]raytracerframework_cpp/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 / 65536 + 1;
  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 % 256));
    ucvector_push_back(out, (unsigned char)(LEN / 256));
    ucvector_push_back(out, (unsigned char)(NLEN % 256));
    ucvector_push_back(out, (unsigned char)(NLEN / 256));

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

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x18(%rbp), %rax
shrq $0x10, %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movq $0x0, -0x20(%rbp)
movq -0x20(%rbp), %rax
cmpq -0x30(%rbp), %rax
jae 0x2471f
movq -0x20(%rbp), %rax
movq -0x30(%rbp), %rcx
subq $0x1, %rcx
cmpq %rcx, %rax
sete %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
movl -0x38(%rbp), %eax
movl -0x3c(%rbp), %ecx
andl $0x1, %ecx
shll %ecx
addl %ecx, %eax
movl -0x3c(%rbp), %ecx
andl $0x2, %ecx
shll %ecx
addl %ecx, %eax
movb %al, -0x45(%rbp)
movq -0x8(%rbp), %rdi
movzbl -0x45(%rbp), %esi
callq 0x25570
movl $0xffff, -0x40(%rbp)    # imm = 0xFFFF
movq -0x18(%rbp), %rax
movl -0x34(%rbp), %ecx
subq %rcx, %rax
cmpq $0xffff, %rax           # imm = 0xFFFF
jae 0x2465c
movq -0x18(%rbp), %rax
subl -0x34(%rbp), %eax
movl %eax, -0x40(%rbp)
movl $0xffff, %eax           # imm = 0xFFFF
subl -0x40(%rbp), %eax
movl %eax, -0x44(%rbp)
movq -0x8(%rbp), %rdi
movl -0x40(%rbp), %eax
andl $0xff, %eax
movzbl %al, %esi
callq 0x25570
movq -0x8(%rbp), %rdi
movl -0x40(%rbp), %eax
shrl $0x8, %eax
movzbl %al, %esi
callq 0x25570
movq -0x8(%rbp), %rdi
movl -0x44(%rbp), %eax
andl $0xff, %eax
movzbl %al, %esi
callq 0x25570
movq -0x8(%rbp), %rdi
movl -0x44(%rbp), %eax
shrl $0x8, %eax
movzbl %al, %esi
callq 0x25570
movq $0x0, -0x28(%rbp)
xorl %eax, %eax
cmpq $0xffff, -0x28(%rbp)    # imm = 0xFFFF
movb %al, -0x46(%rbp)
jae 0x246d7
movl -0x34(%rbp), %eax
cmpq -0x18(%rbp), %rax
setb %al
movb %al, -0x46(%rbp)
movb -0x46(%rbp), %al
testb $0x1, %al
jne 0x246e0
jmp 0x2470c
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movl -0x34(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x34(%rbp)
movl %ecx, %ecx
movzbl (%rax,%rcx), %esi
callq 0x25570
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x246bb
jmp 0x2470e
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x245e3
xorl %eax, %eax
addq $0x50, %rsp
popq %rbp
retq
nopw (%rax,%rax)