// File: /workspace/github_cpp_makefile_star2_O3/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
xorl %eax, %eax
movq %rax, 0x20(%rsp)
movq %rax, 0x18(%rsp)
movq $-0x1, %rbx
movq %rcx, %r15
movq %rdx, %r12
movq %rdi, 0x48(%rsp)
movq %rsi, 0x50(%rsp)
movq (%rsi), %r14
movq (%rdi), %rbp
movq %r14, %r13
incq %r13
movq %rbp, 0x28(%rsp)
movq %r14, 0x30(%rsp)
movq %r14, 0x38(%rsp)
je 0x7017
leaq (%r13,%r13,2), %rbx
leaq (%r14,%r14), %rax
movq %r8, 0x10(%rsp)
movq %rbp, %rdi
shrq %rbx
cmpq %r13, %rax
cmovbq %r13, %rbx
movq %rbx, %rsi
callq 0x2260
testq %rax, %rax
je 0x7126
movq 0x10(%rsp), %r8
movq %rbx, 0x38(%rsp)
movq %rax, %rbp
movq %rax, 0x28(%rsp)
addq $0x2, %r14
movq %r13, 0x30(%rsp)
movb $0x78, -0x1(%rbp,%r13)
movq %r14, %r13
movq %rbx, %r14
cmpq %r13, %r14
jae 0x7066
leaq (%r13,%r13,2), %rbx
addq %r14, %r14
movq %rbp, %rdi
shrq %rbx
cmpq %r13, %r14
movq %r8, %r14
cmovbq %r13, %rbx
movq %rbx, %rsi
callq 0x2260
movq %r14, %r8
testq %rax, %rax
je 0x7071
movq %rax, %rbp
movq %rbx, 0x38(%rsp)
movq %rax, 0x28(%rsp)
movq %r13, 0x30(%rsp)
movb $0x1, -0x1(%rbp,%r13)
movq 0x20(%r8), %rax
leaq 0x20(%rsp), %rdi
leaq 0x18(%rsp), %rsi
movq %r12, %rdx
movq %r15, %rcx
testq %rax, %rax
je 0x708e
callq *%rax
jmp 0x7093
callq 0x5754
testl %eax, %eax
jne 0x71e4
testl %r15d, %r15d
je 0x7130
movl $0x1, %r11d
movl $0x15ae, %ecx           # imm = 0x15AE
movl $0x15ae, %edx           # imm = 0x15AE
movl $0x80078071, %esi       # imm = 0x80078071
xorl %r13d, %r13d
cmpl %ecx, %r15d
movl $0x15ae, %edi           # imm = 0x15AE
movl %r15d, %r8d
cmovbl %r15d, %edi
cmpq %rdx, %r8
cmovaeq %rdx, %r8
xorl %r9d, %r9d
movzbl (%r12,%r9), %r10d
incq %r9
addl %r10d, %r11d
addl %r11d, %r13d
cmpl %r9d, %r8d
jne 0x70d5
movl %edi, %r8d
addq %r8, %r12
movl %r11d, %r8d
imulq %rsi, %r8
shrq $0x2f, %r8
imull $0xfff1, %r8d, %r8d     # imm = 0xFFF1
subl %r8d, %r11d
movl %r13d, %r8d
imulq %rsi, %r8
shrq $0x2f, %r8
imull $0xfff1, %r8d, %r8d     # imm = 0xFFF1
subl %r8d, %r13d
subl %edi, %r15d
jne 0x70bc
shll $0x10, %r13d
orl %r11d, %r13d
jmp 0x7136
movq 0x10(%rsp), %r8
jmp 0x702c
movl $0x1, %r13d
movq 0x28(%rsp), %r14
movq 0x30(%rsp), %rsi
movq 0x38(%rsp), %r15
cmpq $0x0, 0x18(%rsp)
movl %eax, 0x44(%rsp)
je 0x71bb
xorl %ebp, %ebp
movq 0x20(%rsp), %rax
leaq 0x1(%rsi), %r12
movb (%rax,%rbp), %dil
cmpq %r12, %r15
jae 0x719d
leaq (%r12,%r12,2), %rbx
leaq (%r15,%r15), %rax
movb %dil, 0xf(%rsp)
movq %r14, %rdi
movq %rsi, 0x10(%rsp)
shrq %rbx
cmpq %r12, %rax
cmovbq %r12, %rbx
movq %rbx, %rsi
callq 0x2260
movb 0xf(%rsp), %dil
movq 0x10(%rsp), %rsi
testq %rax, %rax
jne 0x71a3
jmp 0x71b1
movq %r14, %rax
movq %r15, %rbx
movb %dil, -0x1(%rax,%r12)
movq %rax, %r14
movq %rbx, %r15
movq %r12, %rsi
incq %rbp
cmpq 0x18(%rsp), %rbp
jne 0x7153
movq 0x20(%rsp), %rdi
leaq 0x28(%rsp), %rbx
movq %rsi, 0x8(%rbx)
movq %r15, 0x10(%rbx)
movq %r14, (%rbx)
callq 0x21b0
movq %rbx, %rdi
movl %r13d, %esi
callq 0x720d
movl 0x44(%rsp), %eax
movq 0x28(%rsp), %rdx
movq 0x48(%rsp), %rcx
movq %rdx, (%rcx)
movq 0x50(%rsp), %rcx
movq 0x30(%rsp), %rdx
movq %rdx, (%rcx)
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq