// File: /workspace/github_cpp_makefile_star2_O1/phillip-h[P]fractal-gen/lodepng.cpp
// Function: lodepng_zlib_compress(unsigned char**, unsigned long*, unsigned char const*, unsigned long, LodePNGCompressSettings const*)
unsigned lodepng_zlib_compress(unsigned char** out, size_t* outsize, const unsigned char* in,
                               size_t insize, const LodePNGCompressSettings* settings)
{
  /*initially, *out must be NULL and outsize 0, if you just give some random *out
  that's pointing to a non allocated buffer, this'll crash*/
  ucvector outv;
  size_t i;
  unsigned error;
  unsigned char* deflatedata = 0;
  size_t deflatesize = 0;

  /*zlib data: 1 byte CMF (CM+CINFO), 1 byte FLG, deflate data, 4 byte ADLER32 checksum of the Decompressed data*/
  unsigned CMF = 120; /*0b01111000: CM 8, CINFO 7. With CINFO 7, any window size up to 32768 can be used.*/
  unsigned FLEVEL = 0;
  unsigned FDICT = 0;
  unsigned CMFFLG = 256 * CMF + FDICT * 32 + FLEVEL * 64;
  unsigned FCHECK = 31 - CMFFLG % 31;
  CMFFLG += FCHECK;

  /*ucvector-controlled version of the output buffer, for dynamic array*/
  ucvector_init_buffer(&outv, *out, *outsize);

  ucvector_push_back(&outv, (unsigned char)(CMFFLG >> 8));
  ucvector_push_back(&outv, (unsigned char)(CMFFLG & 255));

  error = deflate(&deflatedata, &deflatesize, in, insize, settings);

  if(!error)
  {
    unsigned ADLER32 = adler32(in, (unsigned)insize);
    for(i = 0; i != deflatesize; ++i) ucvector_push_back(&outv, deflatedata[i]);
    lodepng_free(deflatedata);
    lodepng_add32bitInt(&outv, ADLER32);
  }

  *out = outv.data;
  *outsize = outv.size;

  return error;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %r8, %r13
movq %rcx, %r15
movq %rdx, %r12
movq %rsi, %r14
xorl %eax, %eax
movq %rax, 0x30(%rsp)
movq %rax, 0x28(%rsp)
movq %rdi, 0x48(%rsp)
movq (%rdi), %rdi
movq (%rsi), %rax
movq %rdi, 0x10(%rsp)
movq %rax, 0x18(%rsp)
movq %rax, 0x20(%rsp)
movq %rax, %rbx
incq %rbx
je 0x7004
addq %rax, %rax
leaq (%rbx,%rbx,2), %rbp
shrq %rbp
cmpq %rbx, %rax
cmovbq %rbx, %rbp
movq %rbp, %rsi
callq 0x2260
testq %rax, %rax
je 0x7013
movq %rbp, 0x20(%rsp)
movq %rax, 0x10(%rsp)
movq %rbx, 0x18(%rsp)
movq 0x10(%rsp), %rax
movb $0x78, -0x1(%rax,%rbx)
movq 0x18(%rsp), %rbx
movq 0x20(%rsp), %rax
incq %rbx
cmpq %rbx, %rax
jae 0x7052
addq %rax, %rax
leaq (%rbx,%rbx,2), %rbp
shrq %rbp
cmpq %rbx, %rax
cmovbq %rbx, %rbp
movq 0x10(%rsp), %rdi
movq %rbp, %rsi
callq 0x2260
testq %rax, %rax
je 0x7061
movq %rbp, 0x20(%rsp)
movq %rax, 0x10(%rsp)
movq %rbx, 0x18(%rsp)
movq 0x10(%rsp), %rax
movb $0x1, -0x1(%rax,%rbx)
movq 0x20(%r13), %rax
leaq 0x30(%rsp), %rdi
leaq 0x28(%rsp), %rsi
movq %r12, %rdx
movq %r15, %rcx
movq %r13, %r8
testq %rax, %rax
je 0x7081
callq *%rax
jmp 0x7086
callq 0x572e
testl %eax, %eax
jne 0x71dd
testl %r15d, %r15d
je 0x711c
movl $0x1, %r11d
xorl %r13d, %r13d
movl $0x15ae, %ecx           # imm = 0x15AE
movl $0x15ae, %edx           # imm = 0x15AE
movl $0x80078071, %esi       # imm = 0x80078071
cmpl %ecx, %r15d
movl $0x15ae, %edi           # imm = 0x15AE
cmovbl %r15d, %edi
movl %r15d, %r8d
cmpq %rdx, %r8
cmovaeq %rdx, %r8
xorl %r9d, %r9d
movzbl (%r12,%r9), %r10d
addl %r10d, %r11d
addl %r11d, %r13d
incq %r9
cmpl %r9d, %r8d
jne 0x70c8
leal -0x1(%rdi), %r8d
movl %r11d, %r9d
imulq %rsi, %r9
shrq $0x2f, %r9
imull $0xfff1, %r9d, %r9d     # imm = 0xFFF1
subl %r9d, %r11d
movl %r13d, %r9d
imulq %rsi, %r9
shrq $0x2f, %r9
imull $0xfff1, %r9d, %r9d     # imm = 0xFFF1
subl %r9d, %r13d
subl %edi, %r15d
leaq 0x1(%r12,%r8), %r12
jne 0x70af
shll $0x10, %r13d
orl %r11d, %r13d
jmp 0x7122
movl $0x1, %r13d
movq %r14, 0x40(%rsp)
movq 0x10(%rsp), %rbx
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %r15
cmpq $0x0, 0x28(%rsp)
movl %eax, 0x3c(%rsp)
je 0x71ac
xorl %ebp, %ebp
movq 0x30(%rsp), %rax
movb (%rax,%rbp), %dil
leaq 0x1(%rsi), %r14
cmpq %r14, %r15
jae 0x718e
leaq (%r15,%r15), %rax
leaq (%r14,%r14,2), %r12
shrq %r12
cmpq %r14, %rax
cmovbq %r14, %r12
movb %dil, 0xf(%rsp)
movq %rbx, %rdi
movq %rsi, 0x50(%rsp)
movq %r12, %rsi
callq 0x2260
movb 0xf(%rsp), %dil
movq 0x50(%rsp), %rsi
testq %rax, %rax
jne 0x7194
jmp 0x71a2
movq %rbx, %rax
movq %r15, %r12
movb %dil, -0x1(%rax,%r14)
movq %rax, %rbx
movq %r12, %r15
movq %r14, %rsi
incq %rbp
cmpq 0x28(%rsp), %rbp
jne 0x7144
leaq 0x10(%rsp), %r12
movq %rsi, 0x8(%r12)
movq %r15, 0x10(%r12)
movq %rbx, (%r12)
movq 0x30(%rsp), %rdi
callq 0x21b0
movq %r12, %rdi
movl %r13d, %esi
callq 0x7201
movq 0x40(%rsp), %r14
movl 0x3c(%rsp), %eax
movq 0x10(%rsp), %rdx
movq 0x48(%rsp), %rcx
movq %rdx, (%rcx)
movq 0x18(%rsp), %rcx
movq %rcx, (%r14)
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq