// File: /workspace/github_c_makefile_star2_O3/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 $0x158, %rsp            # imm = 0x158
movl %r9d, -0x40(%rbp)
movq %r8, %rbx
movq %rcx, %r13
movq %rdx, %r15
movq %rsi, -0x48(%rbp)
movq %rdi, -0x38(%rbp)
movq 0x18(%rbp), %rcx
movzwl (%rcx), %eax
movl %eax, -0x50(%rbp)
movzwl 0x2(%rcx), %eax
movl %eax, -0x4c(%rbp)
movzwl 0x3c0(%rcx), %eax
movl %eax, -0x58(%rbp)
movzwl 0x3c2(%rcx), %eax
movl %eax, -0x54(%rbp)
movq $-0x8, %r14
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 0xa5e5
addq $0x10, %rsp
addq $0x8, %r14
addq $0x20, %r12
cmpq $0x38, %r14
jb 0xa223
xorl %r14d, %r14d
leaq (%r14,%r13), %rdi
leaq (%r14,%r13), %rsi
addq $0x20, %rsi
leaq 0x40(%r13,%r14), %rdx
leaq 0x60(%r13,%r14), %rcx
leaq 0x80(%r13,%r14), %r8
leaq 0xa0(%r13,%r14), %r9
leaq 0xc0(%r13,%r14), %rax
leaq (%r14,%r13), %r10
addq $0xe0, %r10
pushq %r10
pushq %rax
callq 0xa5e5
addq $0x10, %rsp
addq $0x4, %r14
cmpq $0x20, %r14
jne 0xa266
xorl %eax, %eax
xorps %xmm0, %xmm0
leaq 0x48bf(%rip), %rcx      # 0xeb80
leaq 0x4758(%rip), %rdx      # 0xea20
movss (%r13,%rax,4), %xmm1
mulss (%rbx,%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, -0x180(%rbp,%rdi,4)
incq %rax
cmpq $0x40, %rax
jne 0xa2c8
movl -0x180(%rbp), %r12d
movl %r12d, %eax
subl -0x40(%rbp), %eax
movq -0x48(%rbp), %r14
jne 0xa328
movq 0x10(%rbp), %rax
movzwl 0x2(%rax), %r8d
movzwl (%rax), %ecx
movq -0x38(%rbp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
jmp 0xa399
movl %eax, %ecx
negl %ecx
cmovsl %eax, %ecx
bsrl %ecx, %edx
xorl $-0x20, %edx
addl $0x21, %edx
cmpl $0x2, %ecx
movl %r12d, -0x2c(%rbp)
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
movq 0x10(%rbp), %rcx
movzwl 0x2(%rcx,%rax,4), %r8d
movzwl (%rcx,%rax,4), %ecx
movq -0x38(%rbp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0xa52d
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
movl %r13d, %ecx
movl %r12d, %r8d
movl -0x2c(%rbp), %r12d
callq 0xa52d
movl $0x40, %eax
leal -0x1(%rax), %ecx
cmpl $0x0, -0x180(%rbp,%rcx,4)
jne 0xa3bc
movl %ecx, %eax
cmpl $0x1, %ecx
ja 0xa3a3
jmp 0xa503
testl %ecx, %ecx
jle 0xa503
movq %rax, -0x70(%rbp)
movl %r12d, -0x2c(%rbp)
movq %r15, -0x40(%rbp)
movl %ecx, %edx
movl $0x1, %eax
movq %rcx, -0x80(%rbp)
movq %rdx, -0x78(%rbp)
movq %rax, -0x68(%rbp)
cltq
xorl %ecx, %ecx
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
movl %ecx, %r12d
movl -0x180(%rbp,%rax,4), %r13d
incl %r15d
cmpq %rdx, %rax
jg 0xa40d
incq %rax
leal 0x1(%r12), %ecx
testl %r13d, %r13d
je 0xa3ed
movl %r15d, %eax
cmpl $0x10, %r15d
jl 0xa44b
shrl $0x4, %r12d
cmpl $0x1, %r12d
adcl $0x0, %r12d
movl -0x58(%rbp), %r14d
movl -0x54(%rbp), %ebx
movq -0x38(%rbp), %rdi
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
movl %r14d, %ecx
movl %ebx, %r8d
callq 0xa52d
decl %r12d
jne 0xa429
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 -0x68(%rbp), %rsi
addl %r15d, %esi
movl %esi, -0x5c(%rbp)
notl %r13d
andl %edx, %r13d
shll $0x4, %eax
addl %ecx, %eax
cltq
movq 0x18(%rbp), %rcx
movzwl 0x2(%rcx,%rax,4), %r8d
movzwl (%rcx,%rax,4), %ecx
movq -0x38(%rbp), %rdi
movq -0x48(%rbp), %r14
movq %r14, %rsi
movq -0x40(%rbp), %rbx
movq %rbx, %rdx
callq 0xa52d
movq -0x38(%rbp), %rdi
movq %r14, %rsi
movq %rbx, %rdx
movl %r13d, %ecx
movl %r12d, %r8d
callq 0xa52d
movq -0x68(%rbp), %rax
addl %r15d, %eax
incl %eax
movq -0x80(%rbp), %rcx
cmpl -0x5c(%rbp), %ecx
movq -0x78(%rbp), %rdx
jg 0xa3df
cmpl $0x40, -0x70(%rbp)
movq -0x40(%rbp), %r15
movq -0x48(%rbp), %r14
movq -0x38(%rbp), %rbx
movl -0x2c(%rbp), %r12d
je 0xa518
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
movl -0x50(%rbp), %ecx
movl -0x4c(%rbp), %r8d
callq 0xa52d
movl %r12d, %eax
addq $0x158, %rsp            # imm = 0x158
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq