// File: /workspace/github_c_makefile_star2_O2/ggerganov[P]font-rasterizer/./stb_image_write.h
// Function: stbiw__jpg_processDU
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
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x138, %rsp            # imm = 0x138
movl %r9d, -0x58(%rbp)
movq %r8, %r12
movq %rcx, %r13
movq %rdx, -0x50(%rbp)
movq %rsi, -0x40(%rbp)
movq %rdi, -0x38(%rbp)
movq 0x18(%rbp), %rcx
movq 0x10(%rbp), %r15
movzwl (%rcx), %eax
movw %ax, -0x48(%rbp)
movzwl 0x2(%rcx), %eax
movw %ax, -0x46(%rbp)
movzwl 0x3c0(%rcx), %eax
movw %ax, -0x44(%rbp)
movzwl 0x3c2(%rcx), %eax
movw %ax, -0x42(%rbp)
leaq 0x1c(%r13), %rbx
xorl %r14d, %r14d
cmpq $0x40, %r14
jae 0x9915
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 0x9bc3
popq %rax
popq %rcx
addq $0x8, %r14
addq $0x20, %rbx
jmp 0x98e0
xorl %ebx, %ebx
cmpq $0x20, %rbx
je 0x9968
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 (%rbx,%r13), %r10
addq $0xe0, %r10
pushq %r10
pushq %rax
callq 0x9bc3
addq $0x10, %rsp
addq $0x4, %rbx
jmp 0x9917
xorl %eax, %eax
xorps %xmm0, %xmm0
leaq 0x4204(%rip), %rcx      # 0xdb78
leaq 0x40a5(%rip), %rdx      # 0xda20
cmpq $0x40, %rax
je 0x99b0
movss (%r13,%rax,4), %xmm1
mulss (%r12,%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, -0x160(%rbp,%rdi,4)
incq %rax
jmp 0x997b
movl -0x160(%rbp), %edi
movl %edi, -0x5c(%rbp)
subl -0x58(%rbp), %edi
jne 0x99d2
movq -0x38(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq %r15, %rcx
movq -0x50(%rbp), %r13
movq %r13, %rdx
jmp 0x9a0e
leaq -0x2c(%rbp), %r12
movq %r12, %rsi
callq 0x9cef
movzwl 0x2(%r12), %eax
leaq (%r15,%rax,4), %rcx
movq -0x38(%rbp), %r14
movq %r14, %rdi
movq -0x40(%rbp), %rbx
movq %rbx, %rsi
movq -0x50(%rbp), %r13
movq %r13, %rdx
callq 0x9b2e
movq %r14, %rdi
movq %rbx, %rsi
movq %r13, %rdx
movq %r12, %rcx
callq 0x9b2e
xorl %ecx, %ecx
pushq $0x3f
popq %rbx
testl %ebx, %ebx
je 0x9b05
movl %ebx, %eax
cmpl $0x0, -0x160(%rbp,%rax,4)
jne 0x9a33
incl %ecx
decq %rbx
jmp 0x9a18
pushq $0x1
popq %rax
movl %ecx, -0x60(%rbp)
cmpl %ebx, %eax
jg 0x9b01
movq %rax, -0x58(%rbp)
cltq
xorl %ecx, %ecx
pushq $-0x1
popq %rdx
movl %edx, %r14d
movl %ecx, %r15d
movl -0x160(%rbp,%rax,4), %r12d
incl %r14d
cmpq %rbx, %rax
jg 0x9a6e
incq %rax
leal 0x1(%r15), %ecx
testl %r12d, %r12d
je 0x9a4f
movl %r14d, %r13d
cmpl $0x10, %r14d
jl 0x9aa2
shrl $0x4, %r15d
movq -0x50(%rbp), %r13
subl $0x1, %r15d
jb 0x9a9b
movq -0x38(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq %r13, %rdx
leaq -0x44(%rbp), %rcx
callq 0x9b2e
jmp 0x9a7f
movl %r14d, %r13d
andl $0xf, %r13d
movl %r12d, %edi
leaq -0x2c(%rbp), %rsi
callq 0x9cef
shll $0x4, %r13d
movzwl -0x2a(%rbp), %eax
movslq %r13d, %rcx
addq %rax, %rcx
movq 0x18(%rbp), %rax
leaq (%rax,%rcx,4), %rcx
movq -0x38(%rbp), %r15
movq %r15, %rdi
movq -0x40(%rbp), %r12
movq %r12, %rsi
movq -0x50(%rbp), %r13
movq %r13, %rdx
callq 0x9b2e
movq %r15, %rdi
movq %r12, %rsi
movq %r13, %rdx
leaq -0x2c(%rbp), %rcx
callq 0x9b2e
movq -0x58(%rbp), %rax
addl %r14d, %eax
incl %eax
movl -0x60(%rbp), %ecx
jmp 0x9a39
testl %ecx, %ecx
je 0x9b19
leaq -0x48(%rbp), %rcx
movq -0x38(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq %r13, %rdx
callq 0x9b2e
movl -0x5c(%rbp), %eax
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq