// File: /workspace/github_c_makefile_star2_O0/tditlu[P]shadetabler/src/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;
  Hash hash;
  LodePNGBitWriter writer;

  LodePNGBitWriter_init(&writer, out);

  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 / 8u + 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) {
    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(&writer, &hash, in, start, end, settings, final);
      else if(settings->btype == 2) error = deflateDynamic(&writer, &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 -0x10(%rbp), %rsi
leaq -0x88(%rbp), %rdi
callq 0x11c50
movq -0x28(%rbp), %rax
cmpl $0x2, (%rax)
jbe 0x52d7
movl $0x3d, -0x4(%rbp)
jmp 0x54b7
movq -0x28(%rbp), %rax
cmpl $0x0, (%rax)
jne 0x52f9
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
callq 0x11c80
movl %eax, -0x4(%rbp)
jmp 0x54b7
movq -0x28(%rbp), %rax
cmpl $0x1, (%rax)
jne 0x530c
movq -0x20(%rbp), %rax
movq %rax, -0x40(%rbp)
jmp 0x5342
movq -0x20(%rbp), %rax
shrq $0x3, %rax
addq $0x8, %rax
movq %rax, -0x40(%rbp)
cmpq $0x10000, -0x40(%rbp)   # imm = 0x10000
jae 0x532e
movq $0x10000, -0x40(%rbp)   # imm = 0x10000
cmpq $0x40000, -0x40(%rbp)   # imm = 0x40000
jbe 0x5340
movq $0x40000, -0x40(%rbp)   # imm = 0x40000
jmp 0x5342
jmp 0x5344
jmp 0x5346
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 0x536d
movq $0x1, -0x48(%rbp)
movq -0x28(%rbp), %rax
movl 0x8(%rax), %esi
leaq -0x78(%rbp), %rdi
callq 0x11e30
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
jne 0x54a8
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rcx
xorl %eax, %eax
cmpq -0x48(%rbp), %rcx
movb %al, -0xa1(%rbp)
je 0x53b3
cmpl $0x0, -0x2c(%rbp)
setne %al
xorb $-0x1, %al
movb %al, -0xa1(%rbp)
movb -0xa1(%rbp), %al
testb $0x1, %al
jne 0x53c2
jmp 0x54a6
movq -0x38(%rbp), %rax
movq -0x48(%rbp), %rcx
subq $0x1, %rcx
cmpq %rcx, %rax
sete %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x8c(%rbp)
movq -0x38(%rbp), %rax
imulq -0x40(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x98(%rbp), %rax
addq -0x40(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0xa0(%rbp), %rax
cmpq -0x20(%rbp), %rax
jbe 0x5419
movq -0x20(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0x28(%rbp), %rax
cmpl $0x1, (%rax)
jne 0x5456
movq -0x18(%rbp), %rdx
movq -0x98(%rbp), %rcx
movq -0xa0(%rbp), %r8
movq -0x28(%rbp), %r9
movl -0x8c(%rbp), %eax
leaq -0x88(%rbp), %rdi
leaq -0x78(%rbp), %rsi
movl %eax, (%rsp)
callq 0x12010
movl %eax, -0x2c(%rbp)
jmp 0x5493
movq -0x28(%rbp), %rax
cmpl $0x2, (%rax)
jne 0x5491
movq -0x18(%rbp), %rdx
movq -0x98(%rbp), %rcx
movq -0xa0(%rbp), %r8
movq -0x28(%rbp), %r9
movl -0x8c(%rbp), %eax
leaq -0x88(%rbp), %rdi
leaq -0x78(%rbp), %rsi
movl %eax, (%rsp)
callq 0x12210
movl %eax, -0x2c(%rbp)
jmp 0x5493
jmp 0x5495
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x5392
jmp 0x54a8
leaq -0x78(%rbp), %rdi
callq 0x12e30
movl -0x2c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xb0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)