// File: drummyfish[P]flowchart/src/lodepng.cpp
// Function: inflateNoCompression(ucvector*, unsigned char const*, unsigned long*, unsigned long*, unsigned long)
static unsigned inflateNoCompression(ucvector* out, const unsigned char* in, size_t* bp, size_t* pos, size_t inlength)
{
  /*go to first boundary of byte*/
  size_t p;
  unsigned LEN, NLEN, n, error = 0;
  while(((*bp) & 0x7) != 0) (*bp)++;
  p = (*bp) / 8; /*byte position*/

  /*read LEN (2 bytes) and NLEN (2 bytes)*/
  if(p >= inlength - 4) return 52; /*error, bit pointer will jump past memory*/
  LEN = in[p] + 256 * in[p + 1]; p += 2;
  NLEN = in[p] + 256 * in[p + 1]; p += 2;

  /*check if 16-bit NLEN is really the one's complement of LEN*/
  if(LEN + NLEN != 65535) return 21; /*error: NLEN is not one's complement of LEN*/

  if((*pos) + LEN >= out->size)
  {
    if(!ucvector_resize(out, (*pos) + LEN)) return 83; /*alloc fail*/
  }

  /*read the literal data: LEN bytes are now stored in the out buffer*/
  if(p + LEN > inlength) return 23; /*error: reading outside of in buffer*/
  for(n = 0; n < LEN; n++) out->data[(*pos)++] = in[p++];

  (*bp) = p * 8;

  return error;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movl $0x0, -0x48(%rbp)
movq -0x20(%rbp), %rax
movq (%rax), %rax
andq $0x7, %rax
cmpq $0x0, %rax
je 0xd1e4
movq -0x20(%rbp), %rax
movq (%rax), %rcx
addq $0x1, %rcx
movq %rcx, (%rax)
jmp 0xd1c3
movq -0x20(%rbp), %rax
movq (%rax), %rax
shrq $0x3, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq -0x30(%rbp), %rcx
subq $0x4, %rcx
cmpq %rcx, %rax
jb 0xd210
movl $0x34, -0x4(%rbp)
jmp 0xd339
movq -0x18(%rbp), %rax
movq -0x38(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movq -0x18(%rbp), %rcx
movq -0x38(%rbp), %rdx
movzbl 0x1(%rcx,%rdx), %ecx
shll $0x8, %ecx
addl %ecx, %eax
movl %eax, -0x3c(%rbp)
movq -0x38(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x38(%rbp)
movq -0x18(%rbp), %rax
movq -0x38(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movq -0x18(%rbp), %rcx
movq -0x38(%rbp), %rdx
movzbl 0x1(%rcx,%rdx), %ecx
shll $0x8, %ecx
addl %ecx, %eax
movl %eax, -0x40(%rbp)
movq -0x38(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x38(%rbp)
movl -0x3c(%rbp), %eax
addl -0x40(%rbp), %eax
cmpl $0xffff, %eax           # imm = 0xFFFF
je 0xd283
movl $0x15, -0x4(%rbp)
jmp 0xd339
movq -0x28(%rbp), %rax
movq (%rax), %rax
movl -0x3c(%rbp), %ecx
addq %rcx, %rax
movq -0x10(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jb 0xd2c0
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rax
movq (%rax), %rsi
movl -0x3c(%rbp), %eax
addq %rax, %rsi
callq 0xd730
cmpl $0x0, %eax
jne 0xd2be
movl $0x53, -0x4(%rbp)
jmp 0xd339
jmp 0xd2c0
movq -0x38(%rbp), %rax
movl -0x3c(%rbp), %ecx
addq %rcx, %rax
cmpq -0x30(%rbp), %rax
jbe 0xd2d9
movl $0x17, -0x4(%rbp)
jmp 0xd339
movl $0x0, -0x44(%rbp)
movl -0x44(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jae 0xd324
movq -0x18(%rbp), %rax
movq -0x38(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x38(%rbp)
movb (%rax,%rcx), %dl
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq -0x28(%rbp), %rsi
movq (%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, (%rsi)
movb %dl, (%rax,%rcx)
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0xd2e0
movq -0x38(%rbp), %rcx
shlq $0x3, %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movl -0x48(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)