// File: /workspace/github_cpp_makefile_star2_O3/alan0201tw[P]RayTracer/include/stb_image_write.h
// Function: stbiw__jpg_processDU(stbi__write_context*, int*, int*, float*, float*, int, unsigned short const (*) [2], unsigned short const (*) [2])
static int stbiw__jpg_processDU(stbi__write_context *s, int *bitBuf, int *bitCnt, float *CDU, float *fdtbl, int DC, const unsigned short HTDC[256][2], const unsigned short HTAC[256][2]) {
   const unsigned short EOB[2] = { HTAC[0x00][0], HTAC[0x00][1] };
   const unsigned short M16zeroes[2] = { HTAC[0xF0][0], HTAC[0xF0][1] };
   int dataOff, i, diff, end0pos;
   int DU[64];

   // DCT rows
   for(dataOff=0; dataOff<64; dataOff+=8) {
      stbiw__jpg_DCT(&CDU[dataOff], &CDU[dataOff+1], &CDU[dataOff+2], &CDU[dataOff+3], &CDU[dataOff+4], &CDU[dataOff+5], &CDU[dataOff+6], &CDU[dataOff+7]);
   }
   // DCT columns
   for(dataOff=0; dataOff<8; ++dataOff) {
      stbiw__jpg_DCT(&CDU[dataOff], &CDU[dataOff+8], &CDU[dataOff+16], &CDU[dataOff+24], &CDU[dataOff+32], &CDU[dataOff+40], &CDU[dataOff+48], &CDU[dataOff+56]);
   }
   // Quantize/descale/zigzag the coefficients
   for(i=0; i<64; ++i) {
      float v = CDU[i]*fdtbl[i];
      // DU[stbiw__jpg_ZigZag[i]] = (int)(v < 0 ? ceilf(v - 0.5f) : floorf(v + 0.5f));
      // ceilf() and floorf() are C99, not C89, but I /think/ they're not needed here anyway?
      DU[stbiw__jpg_ZigZag[i]] = (int)(v < 0 ? v - 0.5f : v + 0.5f);
   }

   // Encode DC
   diff = DU[0] - DC;
   if (diff == 0) {
      stbiw__jpg_writeBits(s, bitBuf, bitCnt, HTDC[0]);
   } else {
      unsigned short bits[2];
      stbiw__jpg_calcBits(diff, bits);
      stbiw__jpg_writeBits(s, bitBuf, bitCnt, HTDC[bits[1]]);
      stbiw__jpg_writeBits(s, bitBuf, bitCnt, bits);
   }
   // Encode ACs
   end0pos = 63;
   for(; (end0pos>0)&&(DU[end0pos]==0); --end0pos) {
   }
   // end0pos = first element in reverse order !=0
   if(end0pos == 0) {
      stbiw__jpg_writeBits(s, bitBuf, bitCnt, EOB);
      return DU[0];
   }
   for(i = 1; i <= end0pos; ++i) {
      int startpos = i;
      int nrzeroes;
      unsigned short bits[2];
      for (; DU[i]==0 && i<=end0pos; ++i) {
      }
      nrzeroes = i-startpos;
      if ( nrzeroes >= 16 ) {
         int lng = nrzeroes>>4;
         int nrmarker;
         for (nrmarker=1; nrmarker <= lng; ++nrmarker)
            stbiw__jpg_writeBits(s, bitBuf, bitCnt, M16zeroes);
         nrzeroes &= 15;
      }
      stbiw__jpg_calcBits(DU[i], bits);
      stbiw__jpg_writeBits(s, bitBuf, bitCnt, HTAC[(nrzeroes<<4)+bits[1]]);
      stbiw__jpg_writeBits(s, bitBuf, bitCnt, bits);
   }
   if(end0pos != 63) {
      stbiw__jpg_writeBits(s, bitBuf, bitCnt, EOB);
   }
   return DU[0];
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x158, %rsp            # imm = 0x158
movl %r9d, (%rsp)
movq %r8, %rbp
movq %rcx, %r13
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, 0x8(%rsp)
movq 0x198(%rsp), %rcx
movzwl (%rcx), %eax
movl %eax, 0x20(%rsp)
movzwl 0x2(%rcx), %eax
movl %eax, 0x1c(%rsp)
movzwl 0x3c0(%rcx), %eax
movl %eax, 0x28(%rsp)
movzwl 0x3c2(%rcx), %eax
movl %eax, 0x24(%rsp)
movq $-0x8, %rbx
movq %r13, %r12
leaq 0x4(%r12), %rsi
leaq 0x8(%r12), %rdx
leaq 0xc(%r12), %rcx
leaq 0x10(%r12), %r8
leaq 0x14(%r12), %r9
leaq 0x18(%r12), %rax
leaq 0x1c(%r12), %r10
movq %r12, %rdi
pushq %r10
pushq %rax
callq 0x39333
addq $0x10, %rsp
addq $0x8, %rbx
addq $0x20, %r12
cmpq $0x38, %rbx
jb 0x38f6d
xorl %ebx, %ebx
leaq (%rbx,%r13), %rdi
leaq (%rbx,%r13), %rsi
addq $0x20, %rsi
leaq 0x40(%r13,%rbx), %rdx
leaq 0x60(%r13,%rbx), %rcx
leaq 0x80(%r13,%rbx), %r8
leaq 0xa0(%r13,%rbx), %r9
leaq 0xc0(%r13,%rbx), %rax
leaq 0xe0(%r13,%rbx), %r10
pushq %r10
pushq %rax
callq 0x39333
addq $0x10, %rsp
addq $0x4, %rbx
cmpq $0x20, %rbx
jne 0x38faf
xorl %eax, %eax
xorps %xmm0, %xmm0
leaq 0x66b9(%rip), %rcx      # 0x3f6c0
leaq 0x6642(%rip), %rdx      # 0x3f650
movss (%r13,%rax,4), %xmm1
mulss (%rbp,%rax,4), %xmm1
xorl %esi, %esi
ucomiss %xmm1, %xmm0
seta %sil
addss (%rcx,%rsi,4), %xmm1
cvttss2si %xmm1, %esi
movzbl (%rax,%rdx), %edi
movl %esi, 0x50(%rsp,%rdi,4)
incq %rax
cmpq $0x40, %rax
jne 0x3900e
movl 0x50(%rsp), %ebp
movl %ebp, %eax
subl (%rsp), %eax
movq 0x8(%rsp), %rbx
jne 0x39069
movq 0x190(%rsp), %rax
movzwl 0x2(%rax), %r8d
movzwl (%rax), %ecx
movq %rbx, %rdi
movq %r15, %rsi
movq %r14, %rdx
jmp 0x390d2
movl %eax, %ecx
negl %ecx
cmovsl %eax, %ecx
bsrl %ecx, %edx
xorl $-0x20, %edx
addl $0x21, %edx
cmpl $0x2, %ecx
movq 0x190(%rsp), %rsi
movl $0x1, %r12d
cmovael %edx, %r12d
movl %eax, %edx
sarl $0x1f, %edx
addl %eax, %edx
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
movl %r12d, %ecx
shll %cl, %r13d
notl %r13d
andl %edx, %r13d
movzbl %r12b, %eax
movzwl 0x2(%rsi,%rax,4), %r8d
movzwl (%rsi,%rax,4), %ecx
movq %rbx, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x39282
movq %rbx, %rdi
movq %r15, %rsi
movq %r14, %rdx
movl %r13d, %ecx
movl %r12d, %r8d
callq 0x39282
movl $0x40, %eax
leal -0x1(%rax), %ecx
cmpl $0x0, 0x50(%rsp,%rcx,4)
jne 0x390f2
movl %ecx, %eax
cmpl $0x1, %ecx
ja 0x390dc
jmp 0x39257
testl %ecx, %ecx
jle 0x39257
movq %rax, 0x38(%rsp)
movl %ebp, 0x18(%rsp)
movq %r15, 0x10(%rsp)
movq %r14, (%rsp)
movl %ecx, %edx
movl $0x1, %eax
movq %rcx, 0x48(%rsp)
movq %rdx, 0x40(%rsp)
movq %rax, 0x30(%rsp)
cltq
xorl %ecx, %ecx
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
movl %ecx, %r12d
movl 0x50(%rsp,%rax,4), %r13d
incl %r15d
cmpq %rdx, %rax
jg 0x39149
incq %rax
leal 0x1(%r12), %ecx
testl %r13d, %r13d
je 0x3912c
movl %r15d, %eax
cmpl $0x10, %r15d
jl 0x3918e
shrl $0x4, %r12d
cmpl $0x1, %r12d
adcl $0x0, %r12d
movq 0x8(%rsp), %rbx
movl 0x28(%rsp), %r14d
movl 0x24(%rsp), %ebp
movq %rbx, %rdi
movq 0x10(%rsp), %rsi
movq (%rsp), %rdx
movl %r14d, %ecx
movl %ebp, %r8d
callq 0x39282
decl %r12d
jne 0x3916c
movl %r15d, %eax
andl $0xf, %eax
movl %r13d, %ecx
negl %ecx
cmovsl %r13d, %ecx
bsrl %ecx, %r12d
xorl $-0x20, %r12d
addl $0x21, %r12d
cmpl $0x2, %ecx
movl $0x1, %ecx
cmovbl %ecx, %r12d
movl %r13d, %edx
sarl $0x1f, %edx
addl %r13d, %edx
movzbl %r12b, %ecx
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
shll %cl, %r13d
movq 0x30(%rsp), %rsi
addl %r15d, %esi
movl %esi, 0x2c(%rsp)
notl %r13d
andl %edx, %r13d
shll $0x4, %eax
addl %ecx, %eax
cltq
movq 0x198(%rsp), %rcx
movzwl 0x2(%rcx,%rax,4), %r8d
movzwl (%rcx,%rax,4), %ecx
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
movq 0x10(%rsp), %rbp
movq %rbp, %rsi
movq (%rsp), %r14
movq %r14, %rdx
callq 0x39282
movq %rbx, %rdi
movq %rbp, %rsi
movq %r14, %rdx
movl %r13d, %ecx
movl %r12d, %r8d
callq 0x39282
movq 0x30(%rsp), %rax
addl %r15d, %eax
incl %eax
movq 0x48(%rsp), %rcx
cmpl 0x2c(%rsp), %ecx
movq 0x40(%rsp), %rdx
jg 0x3911d
cmpl $0x40, 0x38(%rsp)
movq (%rsp), %r14
movq 0x10(%rsp), %r15
movq 0x8(%rsp), %rbx
movl 0x18(%rsp), %ebp
je 0x3926e
movq %rbx, %rdi
movq %r15, %rsi
movq %r14, %rdx
movl 0x20(%rsp), %ecx
movl 0x1c(%rsp), %r8d
callq 0x39282
movl %ebp, %eax
addq $0x158, %rsp            # imm = 0x158
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq