// File: lvandeve[P]lodepng/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, numdeflateblocks = (datasize + 65534u) / 65535u;
  size_t datapos = 0;
  for(i = 0; i != numdeflateblocks; ++i) {
    unsigned BFINAL, BTYPE, LEN, NLEN;
    unsigned char firstbyte;
    size_t pos = out->size;

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

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

    if(!ucvector_resize(out, out->size + LEN + 5)) return 83; /*alloc fail*/

    firstbyte = (unsigned char)(BFINAL + ((BTYPE & 1u) << 1u) + ((BTYPE & 2u) << 1u));
    out->data[pos + 0] = firstbyte;
    out->data[pos + 1] = (unsigned char)(LEN & 255);
    out->data[pos + 2] = (unsigned char)(LEN >> 8u);
    out->data[pos + 3] = (unsigned char)(NLEN & 255);
    out->data[pos + 4] = (unsigned char)(NLEN >> 8u);
    lodepng_memcpy(out->data + pos + 5, data + datapos, LEN);
    datapos += LEN;
  }

  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x20(%rbp), %rax
addq $0xfffe, %rax           # imm = 0xFFFE
movl $0xffff, %ecx           # imm = 0xFFFF
xorl %edx, %edx
divq %rcx
movq %rax, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movq $0x0, -0x28(%rbp)
movq -0x28(%rbp), %rax
cmpq -0x30(%rbp), %rax
je 0x1446a
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x58(%rbp)
movq -0x28(%rbp), %rax
movq -0x30(%rbp), %rcx
subq $0x1, %rcx
cmpq %rcx, %rax
sete %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x3c(%rbp)
movl $0x0, -0x40(%rbp)
movl $0xffff, -0x44(%rbp)    # imm = 0xFFFF
movq -0x20(%rbp), %rax
subq -0x38(%rbp), %rax
cmpq $0xffff, %rax           # imm = 0xFFFF
jae 0x1436b
movq -0x20(%rbp), %rax
movq -0x38(%rbp), %rcx
subl %ecx, %eax
movl %eax, -0x44(%rbp)
movl $0xffff, %eax           # imm = 0xFFFF
subl -0x44(%rbp), %eax
movl %eax, -0x48(%rbp)
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
movl -0x44(%rbp), %eax
addq %rax, %rsi
addq $0x5, %rsi
callq 0x12cb0
cmpl $0x0, %eax
jne 0x143a2
movl $0x53, -0x4(%rbp)
jmp 0x14471
movl -0x3c(%rbp), %eax
movl -0x40(%rbp), %ecx
andl $0x1, %ecx
shll %ecx
addl %ecx, %eax
movl -0x40(%rbp), %ecx
andl $0x2, %ecx
shll %ecx
addl %ecx, %eax
movb %al, -0x49(%rbp)
movb -0x49(%rbp), %dl
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq -0x58(%rbp), %rcx
movb %dl, (%rax,%rcx)
movl -0x44(%rbp), %eax
andl $0xff, %eax
movb %al, %dl
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq -0x58(%rbp), %rcx
movb %dl, 0x1(%rax,%rcx)
movl -0x44(%rbp), %eax
shrl $0x8, %eax
movb %al, %dl
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq -0x58(%rbp), %rcx
movb %dl, 0x2(%rax,%rcx)
movl -0x48(%rbp), %eax
andl $0xff, %eax
movb %al, %dl
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq -0x58(%rbp), %rcx
movb %dl, 0x3(%rax,%rcx)
movl -0x48(%rbp), %eax
shrl $0x8, %eax
movb %al, %dl
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq -0x58(%rbp), %rcx
movb %dl, 0x4(%rax,%rcx)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
addq -0x58(%rbp), %rdi
addq $0x5, %rdi
movq -0x18(%rbp), %rsi
addq -0x38(%rbp), %rsi
movl -0x44(%rbp), %eax
movl %eax, %edx
callq 0x5820
movl -0x44(%rbp), %eax
addq -0x38(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x1430c
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopw (%rax,%rax)