// File: /workspace/github_cpp_makefile_star2_O3/mhe[P]raytracerframework_cpp/lodepng.cpp
// Function: LodeZlib_compress(unsigned char**, unsigned long*, unsigned char const*, unsigned long, LodeZlib_DeflateSettings const*)
unsigned LodeZlib_compress(unsigned char** out, size_t* outsize, const unsigned char* in, size_t insize, const LodeZlib_DeflateSettings* 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 deflatedata, outv;
  size_t i;
  unsigned error;
  
  unsigned ADLER32;
  /*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_init_buffer(&outv, *out, *outsize); /*ucvector-controlled version of the output buffer, for dynamic array*/
  
  ucvector_push_back(&outv, (unsigned char)(CMFFLG / 256));
  ucvector_push_back(&outv, (unsigned char)(CMFFLG % 256));
  
  ucvector_init(&deflatedata);
  error = LodeFlate_deflate(&deflatedata, in, insize, settings);
  
  if(!error)
  {
    ADLER32 = adler32(in, (unsigned)insize);
    for(i = 0; i < deflatedata.size; i++) ucvector_push_back(&outv, deflatedata.data[i]);
    ucvector_cleanup(&deflatedata);
    LodeZlib_add32bitInt(&outv, ADLER32);
  }
  
  *out = outv.data;
  *outsize = outv.size;
  
  return error;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rcx, %r12
movq %rdx, %rbx
movq %rdi, -0x68(%rbp)
movq (%rdi), %r13
movq %rsi, -0x70(%rbp)
movq (%rsi), %r14
movq %r13, -0x50(%rbp)
movq %r14, -0x48(%rbp)
movq %r14, -0x40(%rbp)
leaq 0x1(%r14), %rax
leaq 0x4(,%r14,4), %r15
cmpq %r14, %r15
jbe 0x1bf00
movq %r8, -0x38(%rbp)
movq %rax, -0x30(%rbp)
leaq (,%rax,8), %rsi
movq %r13, %rdi
movq %rsi, -0x58(%rbp)
callq 0x44f0
testq %rax, %rax
je 0x1c017
movq -0x58(%rbp), %rcx
movq %rcx, -0x40(%rbp)
movq %rax, -0x50(%rbp)
movq %rax, %r13
movq -0x38(%rbp), %r8
movq -0x30(%rbp), %rax
jmp 0x1bf03
movq %r14, %rcx
movq %rax, -0x48(%rbp)
movb $0x78, (%r13,%r14)
leaq 0x8(,%r14,4), %r15
addq $0x2, %r14
movq %r14, %rax
movq %rcx, %r14
cmpq %r14, %r15
jbe 0x1bf55
movq %rax, -0x30(%rbp)
leaq (,%rax,8), %r14
movq %r13, %rdi
movq %r14, %rsi
movq %r8, %r15
callq 0x44f0
movq %r15, %r8
testq %rax, %rax
je 0x1bf5f
movq %rax, %r13
movq %r14, -0x40(%rbp)
movq %rax, -0x50(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x48(%rbp)
movb $0x1, -0x1(%r13,%rax)
xorps %xmm0, %xmm0
leaq -0xa0(%rbp), %rdi
movaps %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
movq %rbx, %rsi
movq %r12, %rdx
movq %r8, %rcx
callq 0x1ab91
movl %eax, %r15d
testl %eax, %eax
jne 0x1c0f1
testl %r12d, %r12d
je 0x1c024
movl $0x1, %eax
xorl %r13d, %r13d
movl $0x15ae, %ecx           # imm = 0x15AE
movl $0x15ae, %edx           # imm = 0x15AE
movl $0x80078071, %esi       # imm = 0x80078071
cmpl %ecx, %r12d
movl $0x15ae, %edi           # imm = 0x15AE
cmovbl %r12d, %edi
movl %r12d, %r8d
cmpq %rdx, %r8
cmovaeq %rdx, %r8
xorl %r9d, %r9d
movzbl (%rbx,%r9), %r10d
addl %r10d, %eax
addl %eax, %r13d
incq %r9
cmpl %r9d, %r8d
jne 0x1bfc6
movl %edi, %r8d
addq %r8, %rbx
movl %eax, %r8d
imulq %rsi, %r8
shrq $0x2f, %r8
imull $0xfff1, %r8d, %r8d     # imm = 0xFFF1
subl %r8d, %eax
movl %r13d, %r8d
imulq %rsi, %r8
shrq $0x2f, %r8
imull $0xfff1, %r8d, %r8d     # imm = 0xFFF1
subl %r8d, %r13d
subl %edi, %r12d
jne 0x1bfad
shll $0x10, %r13d
orl %eax, %r13d
jmp 0x1c02a
movq -0x38(%rbp), %r8
movq -0x30(%rbp), %rax
jmp 0x1bf1f
movl $0x1, %r13d
movq -0xa0(%rbp), %rdi
movq -0x98(%rbp), %r8
movq -0x50(%rbp), %rcx
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
testq %r8, %r8
je 0x1c0d2
movl %r15d, -0x5c(%rbp)
xorl %r12d, %r12d
movq %rdi, -0x80(%rbp)
movq %r8, -0x78(%rbp)
movb (%rdi,%r12), %r15b
leaq 0x1(%rsi), %rbx
leaq 0x4(,%rsi,4), %rax
cmpq %rdx, %rax
jbe 0x1c0ab
leaq (,%rbx,8), %r14
movq %rcx, %rdi
movq %rsi, -0x38(%rbp)
movq %r14, %rsi
movq %rcx, -0x58(%rbp)
movq %rdx, -0x30(%rbp)
callq 0x44f0
movq -0x78(%rbp), %r8
movq -0x38(%rbp), %rsi
movq -0x30(%rbp), %rdx
movq -0x58(%rbp), %rcx
movq -0x80(%rbp), %rdi
testq %rax, %rax
jne 0x1c0b1
jmp 0x1c0bf
movq %rcx, %rax
movq %rdx, %r14
movb %r15b, -0x1(%rax,%rbx)
movq %rax, %rcx
movq %r14, %rdx
movq %rbx, %rsi
incq %r12
cmpq %r12, %r8
jne 0x1c05c
movq -0xa0(%rbp), %rdi
movl -0x5c(%rbp), %r15d
leaq -0x50(%rbp), %r14
movq %rsi, 0x8(%r14)
movq %rdx, 0x10(%r14)
movq %rcx, (%r14)
callq 0x4380
movq %r14, %rdi
movl %r13d, %esi
callq 0x1bc6a
movq -0x50(%rbp), %rax
movq -0x68(%rbp), %rcx
movq %rax, (%rcx)
movq -0x48(%rbp), %rax
movq -0x70(%rbp), %rcx
movq %rax, (%rcx)
movl %r15d, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq