// File: /workspace/github_cpp_makefile_star2_O3/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 %eax, %eax
movq %rax, 0x10(%rsp)
movq %rax, 0x8(%rsp)
movq %rdi, 0x18(%rsp)
movq (%rdi), %rdi
movq %rsi, 0x20(%rsp)
movq (%rsi), %r14
movq %r14, %rbp
movq $-0x1, %rbx
incq %r14
movq %r8, (%rsp)
jne 0x54a8
movq %rdi, %rax
jmp 0x54c0
leaq (%r14,%r14), %rbx
movq %rbx, %rsi
movq %rdi, %r15
callq 0x2320
testq %rax, %rax
je 0x55e3
movb $0x78, -0x1(%rax,%r14)
addq $0x2, %rbp
movq %rbp, %r15
movq %rax, %rdi
movq %rbx, %rbp
cmpq %r15, %rbp
jae 0x54ff
leaq (%r15,%r15), %rbx
movq %rbx, %rsi
movq %rbp, 0x28(%rsp)
movq %rdi, %rbp
callq 0x2320
movq %rbp, %rcx
movq 0x28(%rsp), %rbp
testq %rax, %rax
movq (%rsp), %r8
jne 0x5509
jmp 0x5518
movq %rbp, %rbx
movq %rdi, %rax
movq (%rsp), %r8
movb $0x1, -0x1(%rax,%r15)
movq %rax, %rcx
movq %r15, %r14
movq %rbx, %rbp
movq %rcx, %rbx
movq 0x18(%r8), %rax
leaq 0x10(%rsp), %rdi
leaq 0x8(%rsp), %rsi
movq %r13, %rdx
movq %r12, %rcx
testq %rax, %rax
je 0x5538
callq *%rax
jmp 0x553d
callq 0x3a20
testl %eax, %eax
movq %rbx, %rdi
je 0x5553
movq 0x18(%rsp), %rdx
movq 0x20(%rsp), %rcx
jmp 0x56bd
movl %eax, 0x34(%rsp)
testl %r12d, %r12d
je 0x55f1
movl $0x1, %eax
xorl %r15d, %r15d
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, %r15d
incq %r9
cmpl %r9d, %r8d
jne 0x5591
movl %r11d, %r8d
addq %r8, %r13
movl %eax, %r8d
imulq %rsi, %r8
shrq $0x2f, %r8
imull $0xfff1, %r8d, %r8d     # imm = 0xFFF1
subl %r8d, %eax
movl %r15d, %r8d
imulq %rsi, %r8
shrq $0x2f, %r8
imull $0xfff1, %r8d, %r8d     # imm = 0xFFF1
subl %r8d, %r15d
subl %r11d, %r12d
jne 0x5577
shll $0x10, %r15d
orl %eax, %r15d
jmp 0x55f7
movq %r15, %rdi
movq %r14, %r15
movq %rbp, %r14
jmp 0x54d3
movl $0x1, %r15d
cmpq $0x0, 0x8(%rsp)
je 0x5665
xorl %r12d, %r12d
movq 0x10(%rsp), %rax
movb (%rax,%r12), %cl
leaq 0x1(%r14), %r13
cmpq %r13, %rbp
jae 0x5647
leaq (,%r13,2), %rbx
movq %rbx, %rsi
movq %rbp, 0x28(%rsp)
movq %r14, (%rsp)
movq %rdi, %r14
movl %ecx, %ebp
callq 0x2320
movl %ebp, %ecx
movq %r14, %rdi
movq (%rsp), %r14
movq 0x28(%rsp), %rbp
testq %rax, %rax
jne 0x564d
jmp 0x565b
movq %rbp, %rbx
movq %rdi, %rax
movb %cl, -0x1(%rax,%r13)
movq %rax, %rdi
movq %r13, %r14
movq %rbx, %rbp
incq %r12
cmpq 0x8(%rsp), %r12
jb 0x5602
movq %rdi, %r12
movq 0x10(%rsp), %rdi
callq 0x2220
leaq 0x4(%r14), %rbx
cmpq %rbx, %rbp
jae 0x56a1
leaq (%rbx,%rbx), %rsi
movq %r12, %rdi
callq 0x2320
movq %r12, %rdi
testq %rax, %rax
cmoveq %r14, %rbx
cmovneq %rax, %rdi
movq 0x20(%rsp), %rcx
movq 0x18(%rsp), %rdx
jmp 0x56ae
movq 0x20(%rsp), %rcx
movq 0x18(%rsp), %rdx
movq %r12, %rdi
bswapl %r15d
movl %r15d, -0x4(%rdi,%rbx)
movq %rbx, %r14
movl 0x34(%rsp), %eax
movq %rdi, (%rdx)
movq %r14, (%rcx)
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq