// File: /workspace/github_cpp_makefile_star2_O2/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 $0x148, %rsp            # imm = 0x148
movl %r9d, %r13d
movq %r8, %rbp
movq %rcx, %r12
movq %rdx, %r15
movq %rsi, 0x18(%rsp)
movq %rdi, 0x10(%rsp)
movq 0x188(%rsp), %rcx
movl (%rcx), %eax
movl %eax, 0x2c(%rsp)
movl 0x3c0(%rcx), %eax
movl %eax, 0x28(%rsp)
leaq 0x1c(%r12), %rbx
xorl %r14d, %r14d
cmpq $0x40, %r14
jae 0x2d355
leaq -0x1c(%rbx), %rdi
leaq -0x18(%rbx), %rsi
leaq -0x14(%rbx), %rdx
leaq -0x10(%rbx), %rcx
leaq -0xc(%rbx), %r8
leaq -0x8(%rbx), %r9
leaq -0x4(%rbx), %rax
pushq %rbx
pushq %rax
callq 0x2d627
popq %rax
popq %rcx
addq $0x8, %r14
addq $0x20, %rbx
jmp 0x2d320
xorl %ebx, %ebx
cmpq $0x20, %rbx
je 0x2d3a5
leaq (%r12,%rbx), %rdi
leaq (%r12,%rbx), %rsi
addq $0x20, %rsi
leaq 0x40(%r12,%rbx), %rdx
leaq 0x60(%r12,%rbx), %rcx
leaq 0x80(%r12,%rbx), %r8
leaq 0xa0(%r12,%rbx), %r9
leaq 0xc0(%r12,%rbx), %rax
leaq 0xe0(%r12,%rbx), %r10
pushq %r10
pushq %rax
callq 0x2d627
addq $0x10, %rsp
addq $0x4, %rbx
jmp 0x2d357
xorl %eax, %eax
xorps %xmm0, %xmm0
leaq 0x6217(%rip), %rcx      # 0x335c8
leaq 0x6198(%rip), %rdx      # 0x33550
cmpq $0x40, %rax
je 0x2d3e9
movss (%r12,%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, 0x40(%rsp,%rdi,4)
incq %rax
jmp 0x2d3b8
movl 0x40(%rsp), %ebx
movl %ebx, %edi
subl %r13d, %edi
jne 0x2d40b
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
movq %r15, %rdx
movq 0x180(%rsp), %rcx
jmp 0x2d452
movl %ebx, %ebp
leaq 0xc(%rsp), %r12
movq %r12, %rsi
callq 0x2d750
movzwl 0x2(%r12), %eax
movq 0x180(%rsp), %rcx
leaq (%rcx,%rax,4), %rcx
movq 0x10(%rsp), %r14
movq %r14, %rdi
movq 0x18(%rsp), %rbx
movq %rbx, %rsi
movq %r15, %rdx
callq 0x2d58c
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
movq %r12, %rcx
movl %ebp, %ebx
callq 0x2d58c
xorl %ecx, %ecx
pushq $0x3f
popq %r13
testl %r13d, %r13d
je 0x2d561
movl %r13d, %eax
cmpl $0x0, 0x40(%rsp,%rax,4)
jne 0x2d477
incl %ecx
decq %r13
jmp 0x2d45d
movl %ecx, 0x20(%rsp)
movl %ebx, 0x24(%rsp)
pushq $0x1
popq %rax
leaq 0x28(%rsp), %r12
movq %r15, 0x30(%rsp)
cmpl %r13d, %eax
jg 0x2d556
movq %rax, 0x38(%rsp)
cltq
xorl %ecx, %ecx
pushq $-0x1
popq %rdx
movl %edx, %ebx
movl %ecx, %r14d
movl 0x40(%rsp,%rax,4), %ebp
incl %ebx
cmpq %r13, %rax
jg 0x2d4bc
incq %rax
leal 0x1(%r14), %ecx
testl %ebp, %ebp
je 0x2d4a3
movl %ebx, %r15d
cmpl $0x10, %ebx
jl 0x2d4f1
shrl $0x4, %r14d
movq 0x30(%rsp), %r15
subl $0x1, %r14d
jb 0x2d4ea
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
movq %r15, %rdx
movq %r12, %rcx
callq 0x2d58c
jmp 0x2d4cd
movl %ebx, %r15d
andl $0xf, %r15d
movl %ebp, %edi
leaq 0xc(%rsp), %rsi
callq 0x2d750
shll $0x4, %r15d
movzwl 0xe(%rsp), %eax
movslq %r15d, %rcx
addq %rax, %rcx
movq 0x188(%rsp), %rax
leaq (%rax,%rcx,4), %rcx
movq 0x10(%rsp), %rbp
movq %rbp, %rdi
movq 0x18(%rsp), %r14
movq %r14, %rsi
movq 0x30(%rsp), %r15
movq %r15, %rdx
callq 0x2d58c
movq %rbp, %rdi
movq %r14, %rsi
movq %r15, %rdx
leaq 0xc(%rsp), %rcx
callq 0x2d58c
movq 0x38(%rsp), %rax
addl %ebx, %eax
incl %eax
jmp 0x2d48c
cmpl $0x0, 0x20(%rsp)
movl 0x24(%rsp), %ebx
je 0x2d578
leaq 0x2c(%rsp), %rcx
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
movq %r15, %rdx
callq 0x2d58c
movl %ebx, %eax
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq