// File: /workspace/github_cpp_makefile_star2_O1/drummyfish[P]flowchart/src/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;

  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-controlled version of the output buffer, for dynamic array*/
  ucvector_init_buffer(&outv, *out, *outsize);

  ucvector_push_back(&outv, (unsigned char)(CMFFLG / 256));
  ucvector_push_back(&outv, (unsigned char)(CMFFLG % 256));

  error = deflate(&deflatedata, &deflatesize, in, insize, settings);

  if(!error)
  {
    ADLER32 = adler32(in, (unsigned)insize);
    for(i = 0; i < deflatesize; i++) ucvector_push_back(&outv, deflatedata[i]);
    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 $0x38, %rsp
movq %rcx, %r12
movq %rdx, %r13
xorl %ecx, %ecx
movq %rcx, 0x10(%rsp)
movq %rcx, 0x8(%rsp)
movq %rdi, 0x18(%rsp)
movq (%rdi), %rdi
movq %rsi, 0x20(%rsp)
movq (%rsi), %r15
movq %r15, %r14
incq %r14
je 0x5305
movq %r8, %rbp
movq %r15, (%rsp)
leaq (%r14,%r14), %rbx
movq %rbx, %rsi
movq %rdi, %r15
callq 0x2320
testq %rax, %rax
je 0x52f3
xorl %ecx, %ecx
movq %rbx, %r15
movq %rax, %rdi
jmp 0x5302
movb $0x1, %cl
movq (%rsp), %rax
movq %rax, %r14
movq %r15, %rdi
movq %rax, %r15
movq %rbp, %r8
testb %cl, %cl
jne 0x530f
movb $0x78, -0x1(%rdi,%r14)
leaq 0x1(%r14), %rax
cmpq %rax, %r15
jae 0x5344
movq %r8, %rbp
movq %rax, 0x28(%rsp)
leaq (%rax,%rax), %rbx
movq %rbx, %rsi
movq %rdi, (%rsp)
callq 0x2320
testq %rax, %rax
je 0x5348
xorl %ecx, %ecx
movq %rbx, %r15
movq %rax, %rdi
movq 0x28(%rsp), %rax
jmp 0x5351
xorl %ecx, %ecx
jmp 0x5354
movb $0x1, %cl
movq %r14, %rax
movq (%rsp), %rdi
movq %rbp, %r8
testb %cl, %cl
jne 0x535d
movb $0x1, -0x1(%rdi,%rax)
movq %rax, %r14
movq %rdi, %rbx
movq 0x18(%r8), %rax
leaq 0x10(%rsp), %rdi
leaq 0x8(%rsp), %rsi
movq %r13, %rdx
movq %r12, %rcx
testq %rax, %rax
je 0x5380
callq *%rax
jmp 0x5385
callq 0x3a63
movl %eax, 0x34(%rsp)
testl %eax, %eax
movq %rbx, %rdi
je 0x539f
movq 0x20(%rsp), %rax
movq 0x18(%rsp), %rcx
jmp 0x5502
testl %r12d, %r12d
movq %r14, %rbx
je 0x5432
movl $0x1, %eax
xorl %r14d, %r14d
movl $0x15ae, %ecx           # imm = 0x15AE
movl $0x15ae, %edx           # imm = 0x15AE
movl $0x80078071, %esi       # imm = 0x80078071
cmpl %ecx, %r12d
movl $0x15ae, %r11d          # imm = 0x15AE
cmovbl %r12d, %r11d
movl %r12d, %r8d
cmpq %rdx, %r8
cmovaeq %rdx, %r8
xorl %r9d, %r9d
movzbl (%r13,%r9), %r10d
addl %r10d, %eax
addl %eax, %r14d
incq %r9
cmpl %r9d, %r8d
jne 0x53dc
leal -0x1(%r11), %r8d
movl %eax, %r9d
imulq %rsi, %r9
shrq $0x2f, %r9
imull $0xfff1, %r9d, %r9d     # imm = 0xFFF1
subl %r9d, %eax
movl %r14d, %r9d
imulq %rsi, %r9
shrq $0x2f, %r9
imull $0xfff1, %r9d, %r9d     # imm = 0xFFF1
subl %r9d, %r14d
addq %r8, %r13
incq %r13
subl %r11d, %r12d
jne 0x53c2
shll $0x10, %r14d
orl %eax, %r14d
jmp 0x5438
movl $0x1, %r14d
cmpq $0x0, 0x8(%rsp)
je 0x54ab
xorl %r12d, %r12d
movq 0x10(%rsp), %rax
movb (%rax,%r12), %r13b
leaq 0x1(%rbx), %rbp
cmpq %rbp, %r15
jae 0x5483
movq %rbx, 0x28(%rsp)
movq %r15, (%rsp)
leaq (,%rbp,2), %rbx
movq %rbx, %rsi
movq %rdi, %r15
callq 0x2320
testq %rax, %rax
je 0x548a
xorl %ecx, %ecx
movq %rbx, %r15
movq %rbp, %rbx
movq %rax, %rdi
jmp 0x5498
xorl %ecx, %ecx
movq %rbp, %rbx
jmp 0x5498
movb $0x1, %cl
movq %r15, %rdi
movq (%rsp), %r15
movq 0x28(%rsp), %rbx
testb %cl, %cl
jne 0x54a1
movb %r13b, -0x1(%rdi,%rbx)
incq %r12
cmpq 0x8(%rsp), %r12
jb 0x5443
movq %rdi, %r12
movq 0x10(%rsp), %rdi
callq 0x2220
movq %rbx, %r13
addq $0x4, %rbx
cmpq %rbx, %r15
jae 0x54ea
leaq (%rbx,%rbx), %rsi
movq %r12, %rdi
callq 0x2320
movq %r12, %rdi
testq %rax, %rax
cmoveq %r13, %rbx
cmovneq %rax, %rdi
movq 0x20(%rsp), %rax
movq 0x18(%rsp), %rcx
jmp 0x54f7
movq 0x20(%rsp), %rax
movq 0x18(%rsp), %rcx
movq %r12, %rdi
bswapl %r14d
movl %r14d, -0x4(%rdi,%rbx)
movq %rbx, %r14
movq %rdi, (%rcx)
movq %r14, (%rax)
movl 0x34(%rsp), %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq