// File: Lut99[P]RayTracer/src/lib/LodePNG.cpp
// Function: inflateNoCompression(ucvector*, unsigned long*, LodePNGBitReader*, LodePNGDecompressSettings const*)
static unsigned inflateNoCompression(ucvector* out, size_t* pos,
                                     LodePNGBitReader* reader, const LodePNGDecompressSettings* settings) {
  size_t bytepos;
  size_t size = reader->size;
  unsigned LEN, NLEN, error = 0;

  /*go to first boundary of byte*/
  bytepos = (reader->bp + 7u) >> 3u;

  /*read LEN (2 bytes) and NLEN (2 bytes)*/
  if(bytepos + 4 >= size) return 52; /*error, bit pointer will jump past memory*/
  LEN = (unsigned)reader->data[bytepos] + ((unsigned)reader->data[bytepos + 1] << 8u); bytepos += 2;
  NLEN = (unsigned)reader->data[bytepos] + ((unsigned)reader->data[bytepos + 1] << 8u); bytepos += 2;

  /*check if 16-bit NLEN is really the one's complement of LEN*/
  if(!settings->ignore_nlen && LEN + NLEN != 65535) {
    return 21; /*error: NLEN is not one's complement of LEN*/
  }

  if(!ucvector_resize(out, (*pos) + LEN)) return 83; /*alloc fail*/

  /*read the literal data: LEN bytes are now stored in the out buffer*/
  if(bytepos + LEN > size) return 23; /*error: reading outside of in buffer*/

  lodepng_memcpy(out->data + *pos, reader->data + bytepos, LEN);
  *pos += LEN;
  bytepos += LEN;

  reader->bp = bytepos << 3u;

  return error;
}

// Assembly:
subq $0x48, %rsp
movq %rdi, 0x38(%rsp)
movq %rsi, 0x30(%rsp)
movq %rdx, 0x28(%rsp)
movq %rcx, 0x20(%rsp)
movq 0x28(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x10(%rsp)
movl $0x0, 0x4(%rsp)
movq 0x28(%rsp), %rax
movq 0x18(%rax), %rax
addq $0x7, %rax
shrq $0x3, %rax
movq %rax, 0x18(%rsp)
movq 0x18(%rsp), %rax
addq $0x4, %rax
cmpq 0x10(%rsp), %rax
jb 0x14b8e1
movl $0x34, 0x44(%rsp)
jmp 0x14ba22
movq 0x28(%rsp), %rax
movq (%rax), %rax
movq 0x18(%rsp), %rcx
movzbl (%rax,%rcx), %eax
movq 0x28(%rsp), %rcx
movq (%rcx), %rcx
movq 0x18(%rsp), %rdx
movzbl 0x1(%rcx,%rdx), %ecx
shll $0x8, %ecx
addl %ecx, %eax
movl %eax, 0xc(%rsp)
movq 0x18(%rsp), %rax
addq $0x2, %rax
movq %rax, 0x18(%rsp)
movq 0x28(%rsp), %rax
movq (%rax), %rax
movq 0x18(%rsp), %rcx
movzbl (%rax,%rcx), %eax
movq 0x28(%rsp), %rcx
movq (%rcx), %rcx
movq 0x18(%rsp), %rdx
movzbl 0x1(%rcx,%rdx), %ecx
shll $0x8, %ecx
addl %ecx, %eax
movl %eax, 0x8(%rsp)
movq 0x18(%rsp), %rax
addq $0x2, %rax
movq %rax, 0x18(%rsp)
movq 0x20(%rsp), %rax
cmpl $0x0, 0x4(%rax)
jne 0x14b97c
movl 0xc(%rsp), %eax
addl 0x8(%rsp), %eax
cmpl $0xffff, %eax           # imm = 0xFFFF
je 0x14b97c
movl $0x15, 0x44(%rsp)
jmp 0x14ba22
movq 0x38(%rsp), %rdi
movq 0x30(%rsp), %rax
movq (%rax), %rsi
movl 0xc(%rsp), %eax
addq %rax, %rsi
callq 0x14be50
cmpl $0x0, %eax
jne 0x14b9a4
movl $0x53, 0x44(%rsp)
jmp 0x14ba22
movq 0x18(%rsp), %rax
movl 0xc(%rsp), %ecx
addq %rcx, %rax
cmpq 0x10(%rsp), %rax
jbe 0x14b9c1
movl $0x17, 0x44(%rsp)
jmp 0x14ba22
movq 0x38(%rsp), %rax
movq (%rax), %rdi
movq 0x30(%rsp), %rax
addq (%rax), %rdi
movq 0x28(%rsp), %rax
movq (%rax), %rsi
addq 0x18(%rsp), %rsi
movl 0xc(%rsp), %eax
movl %eax, %edx
callq 0x14b830
movl 0xc(%rsp), %eax
movl %eax, %ecx
movq 0x30(%rsp), %rax
addq (%rax), %rcx
movq %rcx, (%rax)
movl 0xc(%rsp), %eax
addq 0x18(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x18(%rsp), %rcx
shlq $0x3, %rcx
movq 0x28(%rsp), %rax
movq %rcx, 0x18(%rax)
movl 0x4(%rsp), %eax
movl %eax, 0x44(%rsp)
movl 0x44(%rsp), %eax
addq $0x48, %rsp
retq
nopl (%rax,%rax)