// File: /workspace/github_cpp_makefile_star2_O1/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 0x67c68
callq *%rax
jmp 0x67c6d
callq 0x662b9
movl %eax, %ebp
xorl %r13d, %r13d
movq %r13, (%r14)
movq %r13, (%rbx)
testl %eax, %eax
jne 0x67c9f
movq 0x8(%rsp), %rdi
addq $0x6, %rdi
movq %rdi, (%rbx)
callq 0x3a5a0
movq %rax, (%r14)
testq %rax, %rax
movl $0x53, %eax
cmovel %eax, %r13d
movl %r13d, %ebp
testl %ebp, %ebp
jne 0x67d73
testl %r15d, %r15d
je 0x67d32
movl $0x1, %ecx
xorl %eax, %eax
movl $0x15b0, %edx           # imm = 0x15B0
movl $0x15b0, %esi           # imm = 0x15B0
movl $0x80078071, %edi       # imm = 0x80078071
cmpl %edx, %r15d
movl $0x15b0, %r8d           # imm = 0x15B0
cmovbl %r15d, %r8d
movl %r15d, %r9d
cmpq %rsi, %r9
cmovaeq %rsi, %r9
xorl %r10d, %r10d
movzbl (%r12,%r10), %r11d
addl %r11d, %ecx
addl %ecx, %eax
incq %r10
cmpl %r10d, %r9d
jne 0x67ce0
leal -0x1(%r8), %r9d
movl %ecx, %r10d
imulq %rdi, %r10
shrq $0x2f, %r10
imull $0xfff1, %r10d, %r10d   # imm = 0xFFF1
subl %r10d, %ecx
movl %eax, %r10d
imulq %rdi, %r10
shrq $0x2f, %r10
imull $0xfff1, %r10d, %r10d   # imm = 0xFFF1
subl %r10d, %eax
addq %r9, %r12
incq %r12
subl %r8d, %r15d
jne 0x67cc6
shll $0x10, %eax
orl %ecx, %eax
jmp 0x67d37
movl $0x1, %eax
movq (%r14), %rcx
movb $0x78, (%rcx)
movq (%r14), %rcx
movb $0x1, 0x1(%rcx)
cmpq $0x0, 0x8(%rsp)
je 0x67d67
xorl %ecx, %ecx
movq 0x10(%rsp), %rdx
movb (%rdx,%rcx), %dl
movq (%r14), %rsi
movb %dl, 0x2(%rsi,%rcx)
incq %rcx
cmpq 0x8(%rsp), %rcx
jne 0x67d4e
movq (%r14), %rcx
movq (%rbx), %rdx
bswapl %eax
movl %eax, -0x4(%rcx,%rdx)
movq 0x10(%rsp), %rdi
callq 0x3a530
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq