// File: /workspace/github_cpp_makefile_star2_O2/srajangarg[P]raytracer/src/core/stb_image_write.hpp
// Function: stbi_zlib_compress(unsigned char*, int, int*, int)
unsigned char * stbi_zlib_compress(unsigned char *data, int data_len, int *out_len, int quality)
{
   static unsigned short lengthc[] = { 3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258, 259 };
   static unsigned char  lengtheb[]= { 0,0,0,0,0,0,0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4,  4,  5,  5,  5,  5,  0 };
   static unsigned short distc[]   = { 1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577, 32768 };
   static unsigned char  disteb[]  = { 0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13 };
   unsigned int bitbuf=0;
   int i,j, bitcount=0;
   unsigned char *out = NULL;
   unsigned char **hash_table[stbiw__ZHASH]; // 64KB on the stack!
   if (quality < 5) quality = 5;

   stbiw__sbpush(out, 0x78);   // DEFLATE 32K window
   stbiw__sbpush(out, 0x5e);   // FLEVEL = 1
   stbiw__zlib_add(1,1);  // BFINAL = 1
   stbiw__zlib_add(1,2);  // BTYPE = 1 -- fixed huffman

   for (i=0; i < stbiw__ZHASH; ++i)
      hash_table[i] = NULL;

   i=0;
   while (i < data_len-3) {
      // hash next 3 bytes of data to be compressed
      int h = stbiw__zhash(data+i)&(stbiw__ZHASH-1), best=3;
      unsigned char *bestloc = 0;
      unsigned char **hlist = hash_table[h];
      int n = stbiw__sbcount(hlist);
      for (j=0; j < n; ++j) {
         if (hlist[j]-data > i-32768) { // if entry lies within window
            int d = stbiw__zlib_countm(hlist[j], data+i, data_len-i);
            if (d >= best) best=d,bestloc=hlist[j];
         }
      }
      // when hash table entry is too long, delete half the entries
      if (hash_table[h] && stbiw__sbn(hash_table[h]) == 2*quality) {
         STBIW_MEMMOVE(hash_table[h], hash_table[h]+quality, sizeof(hash_table[h][0])*quality);
         stbiw__sbn(hash_table[h]) = quality;
      }
      stbiw__sbpush(hash_table[h],data+i);

      if (bestloc) {
         // "lazy matching" - check match at *next* byte, and if it's better, do cur byte as literal
         h = stbiw__zhash(data+i+1)&(stbiw__ZHASH-1);
         hlist = hash_table[h];
         n = stbiw__sbcount(hlist);
         for (j=0; j < n; ++j) {
            if (hlist[j]-data > i-32767) {
               int e = stbiw__zlib_countm(hlist[j], data+i+1, data_len-i-1);
               if (e > best) { // if next match is better, bail on current match
                  bestloc = NULL;
                  break;
               }
            }
         }
      }

      if (bestloc) {
         int d = (int) (data+i - bestloc); // distance back
         STBIW_ASSERT(d <= 32767 && best <= 258);
         for (j=0; best > lengthc[j+1]-1; ++j);
         stbiw__zlib_huff(j+257);
         if (lengtheb[j]) stbiw__zlib_add(best - lengthc[j], lengtheb[j]);
         for (j=0; d > distc[j+1]-1; ++j);
         stbiw__zlib_add(stbiw__zlib_bitrev(j,5),5);
         if (disteb[j]) stbiw__zlib_add(d - distc[j], disteb[j]);
         i += best;
      } else {
         stbiw__zlib_huffb(data[i]);
         ++i;
      }
   }
   // write out final bytes
   for (;i < data_len; ++i)
      stbiw__zlib_huffb(data[i]);
   stbiw__zlib_huff(256); // end of block
   // pad with 0 bits to byte boundary
   while (bitcount)
      stbiw__zlib_add(0,1);

   for (i=0; i < stbiw__ZHASH; ++i)
      (void) stbiw__sbfree(hash_table[i]);

   {
      // compute adler32 on input
      unsigned int s1=1, s2=0;
      int blocklen = (int) (data_len % 5552);
      j=0;
      while (j < data_len) {
         for (i=0; i < blocklen; ++i) s1 += data[j+i], s2 += s1;
         s1 %= 65521, s2 %= 65521;
         j += blocklen;
         blocklen = 5552;
      }
      stbiw__sbpush(out, STBIW_UCHAR(s2 >> 8));
      stbiw__sbpush(out, STBIW_UCHAR(s2));
      stbiw__sbpush(out, STBIW_UCHAR(s1 >> 8));
      stbiw__sbpush(out, STBIW_UCHAR(s1));
   }
   *out_len = stbiw__sbn(out);
   // make returned pointer freeable
   STBIW_MEMMOVE(stbiw__sbraw(out), out, *out_len);
   return (unsigned char *) stbiw__sbraw(out);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x20088, %rsp          # imm = 0x20088
movq %rdx, 0x60(%rsp)
movq %rsi, 0x30(%rsp)
movq %rdi, 0x38(%rsp)
leaq 0x18(%rsp), %rbx
andq $0x0, (%rbx)
cmpl $0x6, %ecx
pushq $0x5
popq %rax
cmovgel %ecx, %eax
movq %rax, 0x58(%rsp)
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0x1bf36
movq (%rbx), %rdi
movslq -0x4(%rdi), %rax
leal 0x1(%rax), %ecx
movl %ecx, -0x4(%rdi)
movb $0x78, (%rdi,%rax)
movl -0x4(%rdi), %eax
leal 0x1(%rax), %ecx
cmpl -0x8(%rdi), %ecx
jl 0x1b8ab
leaq 0x18(%rsp), %rbx
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0x1bf36
movq (%rbx), %rdi
movl -0x4(%rdi), %eax
leal 0x1(%rax), %ecx
movl %ecx, -0x4(%rdi)
cltq
movb $0x5e, (%rdi,%rax)
leaq 0x10(%rsp), %rbx
pushq $0x1
popq %rbp
movl %ebp, (%rbx)
leaq 0xc(%rsp), %r14
movl %ebp, (%r14)
movq %rbx, %rsi
movq %r14, %rdx
callq 0x1bfae
movl (%r14), %ecx
movl %ebp, %edx
shll %cl, %edx
orl %edx, (%rbx)
addl $0x2, %ecx
movl %ecx, (%r14)
movq %rax, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x1bfae
movq %rax, %rdi
movq %rax, 0x18(%rsp)
xorl %eax, %eax
cmpq $0x4000, %rax           # imm = 0x4000
je 0x1b90e
andq $0x0, 0x80(%rsp,%rax,8)
incq %rax
jmp 0x1b8f8
movq 0x30(%rsp), %rax
addl $-0x3, %eax
movl %eax, 0x54(%rsp)
movq 0x58(%rsp), %rax
leal (%rax,%rax), %ecx
movl %ecx, 0x50(%rsp)
movl %eax, %eax
movq %rax, 0x70(%rsp)
leaq (,%rax,8), %rax
movq %rax, 0x68(%rsp)
xorl %r15d, %r15d
cmpl 0x54(%rsp), %r15d
jge 0x1bce4
movq %rdi, 0x48(%rsp)
movslq %r15d, %rdi
addq 0x38(%rsp), %rdi
movq %rdi, 0x20(%rsp)
callq 0x1c017
andl $0x3fff, %eax           # imm = 0x3FFF
movq 0x80(%rsp,%rax,8), %rbx
testq %rbx, %rbx
je 0x1b977
movslq -0x4(%rbx), %r12
jmp 0x1b97a
xorl %r12d, %r12d
leaq (%rsp,%rax,8), %rax
addq $0x80, %rax
movq %rax, 0x78(%rsp)
leal -0x8000(%r15), %eax
movq 0x30(%rsp), %rcx
movl %ecx, %r14d
movq %r15, 0x28(%rsp)
subl %r15d, %r14d
testq %r12, %r12
movl $0x0, %ecx
cmovleq %rcx, %r12
movslq %eax, %r15
xorl %r13d, %r13d
pushq $0x3
popq %rax
movl %eax, 0x14(%rsp)
movq $0x0, 0x40(%rsp)
movq 0x20(%rsp), %rdx
cmpq %r13, %r12
je 0x1ba12
movq (%rbx,%r13,8), %rbp
movq %rbp, %rax
subq 0x38(%rsp), %rax
cmpq %r15, %rax
jle 0x1ba0d
movq %rbp, %rdi
movq 0x20(%rsp), %rsi
movl %r14d, %edx
callq 0x1c050
movq 0x20(%rsp), %rdx
movl 0x14(%rsp), %ecx
cmpl %ecx, %eax
cmovgl %eax, %ecx
movl %ecx, 0x14(%rsp)
movq 0x40(%rsp), %rax
cmovgeq %rbp, %rax
movq %rax, 0x40(%rsp)
incq %r13
jmp 0x1b9c7
testq %rbx, %rbx
je 0x1ba4b
movl -0x4(%rbx), %eax
cmpl 0x50(%rsp), %eax
jne 0x1ba43
movq 0x70(%rsp), %rax
leaq (%rbx,%rax,8), %rsi
movq %rbx, %rdi
movq 0x68(%rsp), %rdx
callq 0x4510
movq 0x20(%rsp), %rdx
movq 0x58(%rsp), %rax
movl %eax, -0x4(%rbx)
leal 0x1(%rax), %ecx
cmpl -0x8(%rbx), %ecx
jl 0x1ba69
movq 0x78(%rsp), %rbx
movq %rbx, %rdi
pushq $0x8
popq %rsi
callq 0x1bf36
movq 0x20(%rsp), %rdx
movq (%rbx), %rbx
movl -0x4(%rbx), %eax
leal 0x1(%rax), %ecx
movl %ecx, -0x4(%rbx)
cltq
movq %rdx, (%rbx,%rax,8)
cmpq $0x0, 0x40(%rsp)
je 0x1bb00
leaq 0x1(%rdx), %rbx
movq %rbx, %rdi
callq 0x1c017
andl $0x3fff, %eax           # imm = 0x3FFF
movq 0x80(%rsp,%rax,8), %r12
testq %r12, %r12
je 0x1baa3
movl -0x4(%r12), %ebp
jmp 0x1baa5
xorl %ebp, %ebp
movq 0x28(%rsp), %rax
movl %eax, %r14d
notl %r14d
addl 0x30(%rsp), %r14d
addl $0xffff8001, %eax       # imm = 0xFFFF8001
movslq %eax, %r15
testl %ebp, %ebp
movl $0x0, %eax
cmovlel %eax, %ebp
xorl %r13d, %r13d
movq 0x20(%rsp), %rdx
cmpq %r13, %rbp
je 0x1bb2d
movq (%r12,%r13,8), %rdi
movq %rdi, %rax
subq 0x38(%rsp), %rax
cmpq %r15, %rax
jle 0x1bafb
movq %rbx, %rsi
movl %r14d, %edx
callq 0x1c050
movq 0x20(%rsp), %rdx
cmpl 0x14(%rsp), %eax
jg 0x1bb00
incq %r13
jmp 0x1bacf
movzbl (%rdx), %edi
movl 0xc(%rsp), %ebx
movl 0x10(%rsp), %ebp
cmpl $0x8f, %edi
ja 0x1bb91
addl $0x30, %edi
pushq $0x8
popq %rsi
callq 0x1c070
movl %ebx, %ecx
shll %cl, %eax
orl %eax, %ebp
movl %ebp, 0x10(%rsp)
addl $0x8, %ebx
jmp 0x1bbac
subl 0x40(%rsp), %edx
cmpl $0x7fff, %edx           # imm = 0x7FFF
movl 0x14(%rsp), %ecx
jg 0x1bf17
cmpl $0x102, %ecx            # imm = 0x102
jg 0x1bf17
xorl %edi, %edi
leaq 0x10(%rsp), %r15
leaq 0xc(%rsp), %r12
leaq 0x6ee0(%rip), %r13      # 0x22a40
movzwl 0x2(%r13,%rdi,2), %eax
incq %rdi
cmpl %eax, %ecx
jge 0x1bb60
movq %rdx, %rbp
leaq -0x1(%rdi), %r14
cmpq $0x16, %r14
ja 0x1bbcc
pushq $0x7
popq %rsi
callq 0x1c070
movl 0xc(%rsp), %ecx
shll %cl, %eax
orl %eax, 0x10(%rsp)
addl $0x7, %ecx
jmp 0x1bbe7
orl $0x100, %edi            # imm = 0x100
pushq $0x9
popq %rsi
callq 0x1c070
movl %ebx, %ecx
shll %cl, %eax
orl %eax, %ebp
movl %ebp, 0x10(%rsp)
addl $0x9, %ebx
movl %ebx, 0xc(%rsp)
pushq $0x1
popq %rbx
movq 0x48(%rsp), %rdi
leaq 0x10(%rsp), %r15
leaq 0xc(%rsp), %r12
movq 0x28(%rsp), %r13
jmp 0x1bccb
addl $0xa8, %edi
pushq $0x8
popq %rsi
callq 0x1c070
movl 0xc(%rsp), %ecx
shll %cl, %eax
orl %eax, 0x10(%rsp)
addl $0x8, %ecx
movl %ecx, 0xc(%rsp)
movq 0x48(%rsp), %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x1bfae
movq %rax, %rbx
movl %r14d, %eax
leaq -0x1c(%rax), %rcx
cmpq $-0x14, %rcx
jb 0x1bc43
movzwl (%r13,%rax,2), %ecx
movl 0x14(%rsp), %edx
subl %ecx, %edx
movl 0xc(%rsp), %ecx
shll %cl, %edx
orl %edx, 0x10(%rsp)
leaq 0x6e58(%rip), %rdx      # 0x22a80
movzbl (%rax,%rdx), %eax
addl %ecx, %eax
movl %eax, 0xc(%rsp)
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x1bfae
movq %rax, %rbx
leaq 0x6e56(%rip), %rcx      # 0x22aa0
movq 0x28(%rsp), %r13
movq %rbp, %rdx
pushq $-0x1
popq %r14
movzwl 0x4(%rcx,%r14,2), %eax
incq %r14
cmpl %edx, %eax
jle 0x1bc56
movl %r14d, %edi
pushq $0x5
popq %rsi
callq 0x1c070
movl 0xc(%rsp), %ecx
shll %cl, %eax
orl %eax, 0x10(%rsp)
addl $0x5, %ecx
movl %ecx, 0xc(%rsp)
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x1bfae
movq %rax, %rdi
cmpq $0x4, %r14
jae 0x1bc9c
movl 0x14(%rsp), %ebx
jmp 0x1bcd9
movl %r14d, %eax
leaq 0x6dfa(%rip), %rcx      # 0x22aa0
movzwl (%rcx,%rax,2), %ecx
subl %ecx, %ebp
movl 0xc(%rsp), %ecx
shll %cl, %ebp
orl %ebp, 0x10(%rsp)
leaq 0x6e23(%rip), %rdx      # 0x22ae0
movzbl (%rax,%rdx), %eax
addl %ecx, %eax
movl %eax, 0xc(%rsp)
movl 0x14(%rsp), %ebx
movq %r15, %rsi
movq %r12, %rdx
callq 0x1bfae
movq %rax, %rdi
addl %r13d, %ebx
movl %ebx, %r15d
jmp 0x1b93d
movslq %r15d, %r15
movq %rdi, 0x18(%rsp)
movslq 0x30(%rsp), %r13
cmpq %r13, %r15
jge 0x1bd5a
movq %rdi, %rbx
movq 0x38(%rsp), %rax
movzbl (%rax,%r15), %edi
movl 0xc(%rsp), %r14d
movl 0x10(%rsp), %ebp
cmpl $0x8f, %edi
ja 0x1bd1b
addl $0x30, %edi
pushq $0x8
jmp 0x1bd23
orl $0x100, %edi            # imm = 0x100
pushq $0x9
popq %r12
movl %r12d, %esi
callq 0x1c070
movl %r14d, %ecx
shll %cl, %eax
orl %eax, %ebp
movl %ebp, 0x10(%rsp)
addl %r14d, %r12d
movl %r12d, 0xc(%rsp)
movq %rbx, %rdi
leaq 0x10(%rsp), %rsi
leaq 0xc(%rsp), %rdx
callq 0x1bfae
movq %rax, %rdi
incq %r15
jmp 0x1bcf1
movq %rdi, 0x18(%rsp)
pushq $0x7
popq %rsi
movq %rdi, %rbx
xorl %edi, %edi
callq 0x1c070
movq %rbx, %rdi
leaq 0xc(%rsp), %rbx
movl (%rbx), %ecx
shll %cl, %eax
leaq 0x10(%rsp), %r14
orl %eax, (%r14)
addl $0x7, %ecx
movl %ecx, 0xc(%rsp)
movq %r14, %rsi
movq %rbx, %rdx
callq 0x1bfae
movq %rax, %rdi
movl 0xc(%rsp), %eax
leal 0x1(%rax), %ecx
testl %eax, %eax
jne 0x1bd83
movq %rdi, %r14
movq %rdi, 0x18(%rsp)
xorl %ebx, %ebx
cmpq $0x4000, %rbx           # imm = 0x4000
je 0x1bdce
movq 0x80(%rsp,%rbx,8), %rdi
testq %rdi, %rdi
je 0x1bdc9
addq $-0x8, %rdi
callq 0x43a0
incq %rbx
jmp 0x1bdaa
movl $0x15b0, %ecx           # imm = 0x15B0
movq 0x30(%rsp), %rax
cltd
idivl %ecx
movl %edx, %ecx
pushq $0x1
popq %rbp
xorl %esi, %esi
movl $0xfff1, %edi           # imm = 0xFFF1
xorl %ebx, %ebx
cmpl 0x30(%rsp), %esi
jge 0x1be38
movslq %esi, %rax
testl %ecx, %ecx
movl $0x0, %edx
cmovgl %ecx, %edx
addq 0x38(%rsp), %rax
xorl %r8d, %r8d
cmpq %r8, %rdx
je 0x1be1f
movzbl (%rax,%r8), %r9d
movl %ebp, %r10d
addl %r9d, %r10d
movl %r10d, %ebp
addl %r10d, %ebx
incq %r8
jmp 0x1be04
movl %ebp, %eax
xorl %edx, %edx
divl %edi
movl %edx, %ebp
movl %ebx, %eax
xorl %edx, %edx
divl %edi
addl %ecx, %esi
movl $0x15b0, %ecx           # imm = 0x15B0
movl %edx, %ebx
jmp 0x1bde9
testq %r14, %r14
je 0x1be4d
movq %r14, %rdx
movl -0x4(%r14), %eax
leal 0x1(%rax), %ecx
cmpl -0x8(%r14), %ecx
jl 0x1be66
leaq 0x18(%rsp), %r14
pushq $0x1
popq %rsi
movq %r14, %rdi
callq 0x1bf36
movq (%r14), %rdx
movl -0x4(%rdx), %eax
leal 0x1(%rax), %ecx
movl %ecx, -0x4(%rdx)
cltq
movb %bh, (%rdx,%rax)
movl -0x4(%rdx), %eax
incl %eax
cmpl -0x8(%rdx), %eax
jl 0x1be85
leaq 0x18(%rsp), %rdi
pushq $0x1
popq %rsi
callq 0x1bf36
movq 0x18(%rsp), %rsi
movslq -0x4(%rsi), %rax
leal 0x1(%rax), %ecx
movl %ecx, -0x4(%rsi)
movb %bl, (%rsi,%rax)
movl -0x4(%rsi), %eax
leal 0x1(%rax), %ecx
cmpl -0x8(%rsi), %ecx
jl 0x1bebb
leaq 0x18(%rsp), %rbx
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0x1bf36
movq (%rbx), %rsi
movl -0x4(%rsi), %eax
leal 0x1(%rax), %ecx
movl %ecx, -0x4(%rsi)
cltq
movl %ebp, %ecx
movb %ch, (%rsi,%rax)
movl -0x4(%rsi), %eax
leal 0x1(%rax), %ecx
cmpl -0x8(%rsi), %ecx
jl 0x1bee9
leaq 0x18(%rsp), %rbx
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0x1bf36
movq (%rbx), %rsi
movl -0x4(%rsi), %eax
leal 0x1(%rax), %ecx
movl %ecx, -0x4(%rsi)
cltq
movb %bpl, (%rsi,%rax)
movslq -0x4(%rsi), %rdx
movq 0x60(%rsp), %rax
movl %edx, (%rax)
leaq -0x8(%rsi), %rdi
addq $0x20088, %rsp          # imm = 0x20088
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x4510
leaq 0x710e(%rip), %rdi      # 0x2302c
leaq 0x704d(%rip), %rsi      # 0x22f72
leaq 0x711a(%rip), %rcx      # 0x23046
movl $0x314, %edx            # imm = 0x314
callq 0x4210