// File: /workspace/github_cpp_makefile_star2_O1/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, 0x20(%rsp)
movq %r8, %rbp
movq %rcx, %r13
movq %rdx, %r15
movq %rsi, 0x10(%rsp)
movq %rdi, %r14
movq 0x198(%rsp), %rcx
movzwl (%rcx), %eax
movw %ax, 0x1c(%rsp)
movzwl 0x2(%rcx), %eax
movw %ax, 0x1e(%rsp)
movzwl 0x3c0(%rcx), %eax
movw %ax, 0x18(%rsp)
movzwl 0x3c2(%rcx), %eax
movw %ax, 0x1a(%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 0x39600
addq $0x10, %rsp
addq $0x8, %rbx
addq $0x20, %r12
cmpq $0x38, %rbx
jb 0x39273
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 0x39600
addq $0x10, %rsp
addq $0x4, %rbx
cmpq $0x20, %rbx
jne 0x392b5
xorl %eax, %eax
xorps %xmm0, %xmm0
leaq 0x614b(%rip), %rcx      # 0x3f458
leaq 0x60cc(%rip), %rdx      # 0x3f3e0
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 0x39314
movl 0x50(%rsp), %ebx
movl %ebx, %eax
subl 0x20(%rsp), %eax
movq %r14, 0x28(%rsp)
jne 0x3936a
movq %r14, %rdi
movq 0x10(%rsp), %rsi
movq %r15, %rdx
movq 0x190(%rsp), %rcx
jmp 0x393d8
movl %eax, %ecx
negl %ecx
cmovsl %eax, %ecx
bsrl %ecx, %edx
xorl $-0x20, %edx
addl $0x21, %edx
cmpl $0x2, %ecx
movl $0x1, %ecx
cmovael %edx, %ecx
leaq 0xc(%rsp), %r12
movw %cx, 0x2(%r12)
movl %eax, %edx
sarl $0x1f, %edx
addl %eax, %edx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
shll %cl, %eax
notl %eax
andl %edx, %eax
movw %ax, (%r12)
movzbl %cl, %eax
movq 0x190(%rsp), %rcx
leaq (%rcx,%rax,4), %rcx
movq %r14, %r13
movq %r14, %rdi
movq 0x10(%rsp), %r14
movq %r14, %rsi
movq %r15, %rdx
callq 0x39566
movq %r13, %rdi
movq %r14, %rsi
movq %r15, %rdx
movq %r12, %rcx
callq 0x39566
movl $0x40, %eax
leal -0x1(%rax), %r13d
cmpl $0x0, 0x50(%rsp,%r13,4)
jne 0x393f8
decl %eax
cmpl $0x1, %eax
ja 0x393e2
xorl %r13d, %r13d
testl %r13d, %r13d
je 0x3953b
movl %ebx, 0x30(%rsp)
jle 0x39531
movl %r13d, %edx
movl $0x1, %ebp
movq %r15, 0x38(%rsp)
movq %r13, 0x40(%rsp)
movq %rdx, 0x48(%rsp)
movq %rbp, 0x20(%rsp)
movslq %ebp, %rax
xorl %ecx, %ecx
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movl %ecx, %r15d
movl 0x50(%rsp,%rax,4), %r14d
incl %ebx
cmpq %rdx, %rax
jg 0x3944c
incq %rax
leal 0x1(%r15), %ecx
testl %r14d, %r14d
je 0x39431
movl %ebx, %eax
cmpl $0x10, %ebx
jl 0x39490
shrl $0x4, %r15d
cmpl $0x1, %r15d
adcl $0x0, %r15d
movq 0x10(%rsp), %rbp
movq 0x38(%rsp), %r12
leaq 0x18(%rsp), %r13
movq 0x28(%rsp), %rdi
movq %rbp, %rsi
movq %r12, %rdx
movq %r13, %rcx
callq 0x39566
decl %r15d
jne 0x3946e
movl %ebx, %eax
andl $0xf, %eax
movq 0x40(%rsp), %r13
movl %r14d, %ecx
negl %ecx
cmovsl %r14d, %ecx
bsrl %ecx, %edx
xorl $-0x20, %edx
addl $0x21, %edx
cmpl $0x2, %ecx
movl $0x1, %ecx
cmovbl %ecx, %edx
movw %dx, 0xe(%rsp)
movl %r14d, %esi
sarl $0x1f, %esi
addl %r14d, %esi
movzbl %dl, %ecx
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
shll %cl, %edx
movq 0x20(%rsp), %rbp
leal (%rbx,%rbp), %edi
movl %edi, 0x34(%rsp)
notl %edx
andl %esi, %edx
movw %dx, 0xc(%rsp)
shll $0x4, %eax
addl %ecx, %eax
cltq
movq 0x198(%rsp), %rcx
leaq (%rcx,%rax,4), %rcx
movq 0x28(%rsp), %r12
movq %r12, %rdi
movq 0x10(%rsp), %r14
movq %r14, %rsi
movq 0x38(%rsp), %r15
movq %r15, %rdx
callq 0x39566
movq %r12, %rdi
movq %r14, %rsi
movq %r15, %rdx
leaq 0xc(%rsp), %rcx
callq 0x39566
addl %ebx, %ebp
incl %ebp
cmpl 0x34(%rsp), %r13d
movq 0x48(%rsp), %rdx
jg 0x39422
cmpl $0x3f, %r13d
movl 0x30(%rsp), %ebx
je 0x39552
leaq 0x1c(%rsp), %rcx
movq 0x28(%rsp), %rdi
movq 0x10(%rsp), %rsi
movq %r15, %rdx
callq 0x39566
movl %ebx, %eax
addq $0x158, %rsp            # imm = 0x158
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq