// File: /workspace/github_cpp_makefile_star2_O1/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 %r8, %r15
movq %rcx, %r13
movq %rdx, %rbx
movq %rdi, -0x78(%rbp)
movq (%rdi), %rdi
movq %rsi, -0x80(%rbp)
movq (%rsi), %rax
movq %rdi, -0x48(%rbp)
movq %rax, -0x40(%rbp)
movq %rax, -0x38(%rbp)
leaq 0x1(%rax), %r14
leaq 0x4(,%rax,4), %rcx
cmpq %rax, %rcx
jbe 0x1cf7f
leaq (,%r14,8), %r12
movq %r12, %rsi
callq 0x5500
testq %rax, %rax
je 0x1cf8d
movq %r12, -0x38(%rbp)
movq %rax, -0x48(%rbp)
movq %r14, -0x40(%rbp)
movq -0x48(%rbp), %rax
movb $0x78, -0x1(%rax,%r14)
movq -0x40(%rbp), %r14
leaq 0x4(,%r14,4), %rax
incq %r14
cmpq -0x38(%rbp), %rax
jbe 0x1cfc3
leaq (,%r14,8), %r12
movq -0x48(%rbp), %rdi
movq %r12, %rsi
callq 0x5500
testq %rax, %rax
je 0x1cfd1
movq %r12, -0x38(%rbp)
movq %rax, -0x48(%rbp)
movq %r14, -0x40(%rbp)
movq -0x48(%rbp), %rax
movb $0x1, -0x1(%rax,%r14)
xorps %xmm0, %xmm0
leaq -0x70(%rbp), %rdi
movaps %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
movq %rbx, %rsi
movq %r13, %rdx
movq %r15, %rcx
callq 0x1bb84
testl %eax, %eax
jne 0x1d171
testl %r13d, %r13d
je 0x1d088
movl $0x1, %r11d
xorl %r12d, %r12d
movl $0x15ae, %ecx           # imm = 0x15AE
movl $0x15ae, %edx           # imm = 0x15AE
movl $0x80078071, %esi       # imm = 0x80078071
cmpl %ecx, %r13d
movl $0x15ae, %edi           # imm = 0x15AE
cmovbl %r13d, %edi
movl %r13d, %r8d
cmpq %rdx, %r8
cmovaeq %rdx, %r8
xorl %r9d, %r9d
movzbl (%rbx,%r9), %r10d
addl %r10d, %r11d
addl %r11d, %r12d
incq %r9
cmpl %r9d, %r8d
jne 0x1d033
leal -0x1(%rdi), %r8d
movl %r11d, %r9d
imulq %rsi, %r9
shrq $0x2f, %r9
imull $0xfff1, %r9d, %r9d     # imm = 0xFFF1
subl %r9d, %r11d
movl %r12d, %r9d
imulq %rsi, %r9
shrq $0x2f, %r9
imull $0xfff1, %r9d, %r9d     # imm = 0xFFF1
subl %r9d, %r12d
addq %r8, %rbx
incq %rbx
subl %edi, %r13d
jne 0x1d01a
shll $0x10, %r12d
orl %r11d, %r12d
jmp 0x1d08e
movl $0x1, %r12d
movq -0x68(%rbp), %rsi
movq -0x48(%rbp), %r14
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rdx
testq %rsi, %rsi
movl %eax, -0x4c(%rbp)
je 0x1d13b
movq -0x70(%rbp), %r8
xorl %ebx, %ebx
movq %rsi, -0x90(%rbp)
movq %r8, -0x88(%rbp)
movb (%r8,%rbx), %r9b
leaq 0x1(%rdi), %r15
leaq 0x4(,%rdi,4), %rax
cmpq %rdx, %rax
jbe 0x1d11f
leaq (,%r15,8), %r13
movq %rdi, -0x98(%rbp)
movq %r14, %rdi
movq %r13, %rsi
movq %rdx, -0xa0(%rbp)
movb %r9b, -0x29(%rbp)
callq 0x5500
movb -0x29(%rbp), %r9b
movq -0x88(%rbp), %r8
movq -0x98(%rbp), %rdi
movq -0x90(%rbp), %rsi
movq -0xa0(%rbp), %rdx
testq %rax, %rax
jne 0x1d125
jmp 0x1d133
movq %r14, %rax
movq %rdx, %r13
movb %r9b, -0x1(%rax,%r15)
movq %rax, %r14
movq %r13, %rdx
movq %r15, %rdi
incq %rbx
cmpq %rbx, %rsi
jne 0x1d0be
leaq -0x48(%rbp), %r13
movq %rdi, 0x8(%r13)
movq %rdx, 0x10(%r13)
movq %r14, (%r13)
xorps %xmm0, %xmm0
movups %xmm0, -0x68(%rbp)
movq -0x70(%rbp), %rdi
callq 0x5390
movq $0x0, -0x70(%rbp)
movq %r13, %rdi
movl %r12d, %esi
callq 0x1ccfd
movl -0x4c(%rbp), %eax
movq -0x48(%rbp), %rdx
movq -0x78(%rbp), %rcx
movq %rdx, (%rcx)
movq -0x40(%rbp), %rdx
movq -0x80(%rbp), %rcx
movq %rdx, (%rcx)
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq