// File: /workspace/github_c_makefile_star2_O0/Joy-Division[P]tools-mgs/lodepng/lodepng.c
// Function: lodepng_deflatev
static unsigned lodepng_deflatev(ucvector* out, const unsigned char* in, size_t insize,
                                 const LodePNGCompressSettings* settings)
{
  unsigned error = 0;
  size_t i, blocksize, numdeflateblocks;
  size_t bp = 0; /*the bit pointer*/
  Hash hash;

  if(settings->btype > 2) return 61;
  else if(settings->btype == 0) return deflateNoCompression(out, in, insize);
  else if(settings->btype == 1) blocksize = insize;
  else /*if(settings->btype == 2)*/
  {
    /*on PNGs, deflate blocks of 65-262k seem to give most dense encoding*/
    blocksize = insize / 8 + 8;
    if(blocksize < 65536) blocksize = 65536;
    if(blocksize > 262144) blocksize = 262144;
  }

  numdeflateblocks = (insize + blocksize - 1) / blocksize;
  if(numdeflateblocks == 0) numdeflateblocks = 1;

  error = hash_init(&hash, settings->windowsize);
  if(error) return error;

  for(i = 0; i != numdeflateblocks && !error; ++i)
  {
    unsigned final = (i == numdeflateblocks - 1);
    size_t start = i * blocksize;
    size_t end = start + blocksize;
    if(end > insize) end = insize;

    if(settings->btype == 1) error = deflateFixed(out, &bp, &hash, in, start, end, settings, final);
    else if(settings->btype == 2) error = deflateDynamic(out, &bp, &hash, in, start, end, settings, final);
  }

  hash_cleanup(&hash);

  return error;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
movq $0x0, -0x50(%rbp)
movq -0x28(%rbp), %rax
cmpl $0x2, (%rax)
jbe 0x210f
movl $0x3d, -0x4(%rbp)
jmp 0x2300
movq -0x28(%rbp), %rax
cmpl $0x0, (%rax)
jne 0x2131
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
callq 0xbb70
movl %eax, -0x4(%rbp)
jmp 0x2300
movq -0x28(%rbp), %rax
cmpl $0x1, (%rax)
jne 0x2144
movq -0x20(%rbp), %rax
movq %rax, -0x40(%rbp)
jmp 0x217a
movq -0x20(%rbp), %rax
shrq $0x3, %rax
addq $0x8, %rax
movq %rax, -0x40(%rbp)
cmpq $0x10000, -0x40(%rbp)   # imm = 0x10000
jae 0x2166
movq $0x10000, -0x40(%rbp)   # imm = 0x10000
cmpq $0x40000, -0x40(%rbp)   # imm = 0x40000
jbe 0x2178
movq $0x40000, -0x40(%rbp)   # imm = 0x40000
jmp 0x217a
jmp 0x217c
jmp 0x217e
movq -0x20(%rbp), %rax
addq -0x40(%rbp), %rax
subq $0x1, %rax
xorl %ecx, %ecx
movl %ecx, %edx
divq -0x40(%rbp)
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
jne 0x21a5
movq $0x1, -0x48(%rbp)
movq -0x28(%rbp), %rax
movl 0x8(%rax), %esi
leaq -0x80(%rbp), %rdi
callq 0xbcf0
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
je 0x21c9
movl -0x2c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x2300
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rcx
xorl %eax, %eax
cmpq -0x48(%rbp), %rcx
movb %al, -0x99(%rbp)
je 0x21f2
cmpl $0x0, -0x2c(%rbp)
setne %al
xorb $-0x1, %al
movb %al, -0x99(%rbp)
movb -0x99(%rbp), %al
testb $0x1, %al
jne 0x2201
jmp 0x22f1
movq -0x38(%rbp), %rax
movq -0x48(%rbp), %rcx
subq $0x1, %rcx
cmpq %rcx, %rax
sete %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x84(%rbp)
movq -0x38(%rbp), %rax
imulq -0x40(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rax
addq -0x40(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x98(%rbp), %rax
cmpq -0x20(%rbp), %rax
jbe 0x2258
movq -0x20(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x28(%rbp), %rax
cmpl $0x1, (%rax)
jne 0x229b
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rcx
movq -0x90(%rbp), %r8
movq -0x98(%rbp), %r9
movq -0x28(%rbp), %r10
movl -0x84(%rbp), %eax
leaq -0x50(%rbp), %rsi
leaq -0x80(%rbp), %rdx
movq %r10, (%rsp)
movl %eax, 0x8(%rsp)
callq 0xbed0
movl %eax, -0x2c(%rbp)
jmp 0x22de
movq -0x28(%rbp), %rax
cmpl $0x2, (%rax)
jne 0x22dc
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rcx
movq -0x90(%rbp), %r8
movq -0x98(%rbp), %r9
movq -0x28(%rbp), %r10
movl -0x84(%rbp), %eax
leaq -0x50(%rbp), %rsi
leaq -0x80(%rbp), %rdx
movq %r10, (%rsp)
movl %eax, 0x8(%rsp)
callq 0xc1d0
movl %eax, -0x2c(%rbp)
jmp 0x22de
jmp 0x22e0
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x21d1
leaq -0x80(%rbp), %rdi
callq 0xcef0
movl -0x2c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xb0, %rsp
popq %rbp
retq
nopl (%rax)