// File: /workspace/github_cpp_makefile_star2_O3/Lut99[P]RayTracer/src/lib/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) {
  size_t i;
  unsigned error;
  unsigned char* deflatedata = 0;
  size_t deflatesize = 0;

  error = deflate(&deflatedata, &deflatesize, in, insize, settings);

  *out = NULL;
  *outsize = 0;
  if(!error) {
    *outsize = deflatesize + 6;
    *out = (unsigned char*)lodepng_malloc(*outsize);
    if(!*out) error = 83; /*alloc fail*/
  }

  if(!error) {
    unsigned ADLER32 = adler32(in, (unsigned)insize);
    /*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;

    (*out)[0] = (unsigned char)(CMFFLG >> 8);
    (*out)[1] = (unsigned char)(CMFFLG & 255);
    for(i = 0; i != deflatesize; ++i) (*out)[i + 2] = deflatedata[i];
    lodepng_set32bitInt(&(*out)[*outsize - 4], ADLER32);
  }

  lodepng_free(deflatedata);
  return error;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rcx, %r15
movq %rdx, %r12
movq %rsi, %rbx
movq %rdi, %r14
xorl %eax, %eax
movq %rax, 0x10(%rsp)
movq %rax, 0x8(%rsp)
movq 0x20(%r8), %rax
leaq 0x10(%rsp), %rdi
leaq 0x8(%rsp), %rsi
testq %rax, %rax
je 0x6766e
callq *%rax
jmp 0x67673
callq 0x65da9
movl %eax, %ebp
xorl %eax, %eax
movq %rax, (%r14)
movq %rax, (%rbx)
testl %ebp, %ebp
jne 0x6776f
movq 0x8(%rsp), %r13
leaq 0x6(%r13), %rdi
movq %rdi, (%rbx)
callq 0x3a5b0
movq %rax, (%r14)
testq %rax, %rax
je 0x67729
testl %r15d, %r15d
je 0x67730
movl $0x1, %edx
xorl %ecx, %ecx
movl $0x15b0, %esi           # imm = 0x15B0
movl $0x15b0, %edi           # imm = 0x15B0
movl $0x80078071, %r8d       # imm = 0x80078071
cmpl %esi, %r15d
movl $0x15b0, %r9d           # imm = 0x15B0
cmovbl %r15d, %r9d
movl %r15d, %r10d
cmpq %rdi, %r10
cmovaeq %rdi, %r10
xorl %r11d, %r11d
movzbl (%r12,%r11), %ebp
addl %ebp, %edx
addl %edx, %ecx
incq %r11
cmpl %r11d, %r10d
jne 0x676dc
movl %r9d, %r10d
addq %r10, %r12
movl %edx, %r10d
imulq %r8, %r10
shrq $0x2f, %r10
imull $0xfff1, %r10d, %r10d   # imm = 0xFFF1
subl %r10d, %edx
movl %ecx, %r10d
imulq %r8, %r10
shrq $0x2f, %r10
imull $0xfff1, %r10d, %r10d   # imm = 0xFFF1
subl %r10d, %ecx
subl %r9d, %r15d
jne 0x676c2
shll $0x10, %ecx
orl %edx, %ecx
jmp 0x67735
movl $0x53, %ebp
jmp 0x6776f
movl $0x1, %ecx
movw $0x178, (%rax)          # imm = 0x178
testq %r13, %r13
je 0x67762
xorl %eax, %eax
movq 0x10(%rsp), %rdx
movb (%rdx,%rax), %dl
movq (%r14), %rsi
movb %dl, 0x2(%rsi,%rax)
incq %rax
cmpq 0x8(%rsp), %rax
jne 0x67741
movq (%r14), %rax
movq (%rbx), %rdx
jmp 0x67767
movl $0x6, %edx
bswapl %ecx
movl %ecx, -0x4(%rax,%rdx)
xorl %ebp, %ebp
movq 0x10(%rsp), %rdi
callq 0x3a540
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq