// File: /workspace/github_c_makefile_star2_O0/archer1357[P]Offline-Raytracer/jo_jpeg.c
// Function: jo_processDU
static int jo_processDU(FILE *fp,
                        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 i,dataOff,  nrmarker;
  // DCT rows
  for(  dataOff=0; dataOff<64; dataOff+=8) {
    jo_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) {
    jo_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
  int DU[64];
  for(  i=0; i<64; ++i) {
    float v = CDU[i]*fdtbl[i];
    DU[s_jo_ZigZag[i]] = (int)(v < 0 ? ceilf(v - 0.5f) : floorf(v + 0.5f));
  }

  // Encode DC
  int diff = DU[0] - DC;
  if (diff == 0) {
    jo_writeBits(fp, bitBuf, bitCnt, HTDC[0]);
  } else {
    unsigned short bits[2];
    jo_calcBits(diff, bits);
    jo_writeBits(fp, bitBuf, bitCnt, HTDC[bits[1]]);
    jo_writeBits(fp, bitBuf, bitCnt, bits);
  }
  // Encode ACs
  int end0pos = 63;
  for(; (end0pos>0)&&(DU[end0pos]==0); --end0pos) {
  }
  // end0pos = first element in reverse order !=0
  if(end0pos == 0) {
    jo_writeBits(fp, bitBuf, bitCnt, EOB);
    return DU[0];
  }

  for(  i = 1; i <= end0pos; ++i) {
    int startpos = i;
    for (; DU[i]==0 && i<=end0pos; ++i) {
    }
    int nrzeroes = i-startpos;
    if ( nrzeroes >= 16 ) {
      int lng = nrzeroes>>4;
      for (  nrmarker=1; nrmarker <= lng; ++nrmarker)
        jo_writeBits(fp, bitBuf, bitCnt, M16zeroes);
      nrzeroes &= 15;
    }
    unsigned short bits[2];
    jo_calcBits(DU[i], bits);
    jo_writeBits(fp, bitBuf, bitCnt, HTAC[(nrzeroes<<4)+bits[1]]);
    jo_writeBits(fp, bitBuf, bitCnt, bits);
  }
  if(end0pos != 63) {
    jo_writeBits(fp, bitBuf, bitCnt, EOB);
  }
  return DU[0];
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x190, %rsp            # imm = 0x190
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movl %r9d, -0x34(%rbp)
movq 0x18(%rbp), %rax
movw (%rax), %ax
movw %ax, -0x38(%rbp)
movq 0x18(%rbp), %rax
movw 0x2(%rax), %ax
movw %ax, -0x36(%rbp)
movq 0x18(%rbp), %rax
movw 0x3c0(%rax), %ax
movw %ax, -0x3c(%rbp)
movq 0x18(%rbp), %rax
movw 0x3c2(%rax), %ax
movw %ax, -0x3a(%rbp)
movl $0x0, -0x44(%rbp)
cmpl $0x40, -0x44(%rbp)
jge 0x409124
movq -0x28(%rbp), %rdi
movslq -0x44(%rbp), %rax
shlq $0x2, %rax
addq %rax, %rdi
movq -0x28(%rbp), %rsi
movl -0x44(%rbp), %eax
addl $0x1, %eax
cltq
shlq $0x2, %rax
addq %rax, %rsi
movq -0x28(%rbp), %rdx
movl -0x44(%rbp), %eax
addl $0x2, %eax
cltq
shlq $0x2, %rax
addq %rax, %rdx
movq -0x28(%rbp), %rcx
movl -0x44(%rbp), %eax
addl $0x3, %eax
cltq
shlq $0x2, %rax
addq %rax, %rcx
movq -0x28(%rbp), %r8
movl -0x44(%rbp), %eax
addl $0x4, %eax
cltq
shlq $0x2, %rax
addq %rax, %r8
movq -0x28(%rbp), %r9
movl -0x44(%rbp), %eax
addl $0x5, %eax
cltq
shlq $0x2, %rax
addq %rax, %r9
movq -0x28(%rbp), %r10
movl -0x44(%rbp), %eax
addl $0x6, %eax
cltq
shlq $0x2, %rax
addq %rax, %r10
movq -0x28(%rbp), %rax
movl -0x44(%rbp), %r11d
addl $0x7, %r11d
movslq %r11d, %r11
shlq $0x2, %r11
addq %r11, %rax
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x4095b0
movl -0x44(%rbp), %eax
addl $0x8, %eax
movl %eax, -0x44(%rbp)
jmp 0x409067
movl $0x0, -0x44(%rbp)
cmpl $0x8, -0x44(%rbp)
jge 0x4091e8
movq -0x28(%rbp), %rdi
movslq -0x44(%rbp), %rax
shlq $0x2, %rax
addq %rax, %rdi
movq -0x28(%rbp), %rsi
movl -0x44(%rbp), %eax
addl $0x8, %eax
cltq
shlq $0x2, %rax
addq %rax, %rsi
movq -0x28(%rbp), %rdx
movl -0x44(%rbp), %eax
addl $0x10, %eax
cltq
shlq $0x2, %rax
addq %rax, %rdx
movq -0x28(%rbp), %rcx
movl -0x44(%rbp), %eax
addl $0x18, %eax
cltq
shlq $0x2, %rax
addq %rax, %rcx
movq -0x28(%rbp), %r8
movl -0x44(%rbp), %eax
addl $0x20, %eax
cltq
shlq $0x2, %rax
addq %rax, %r8
movq -0x28(%rbp), %r9
movl -0x44(%rbp), %eax
addl $0x28, %eax
cltq
shlq $0x2, %rax
addq %rax, %r9
movq -0x28(%rbp), %r10
movl -0x44(%rbp), %eax
addl $0x30, %eax
cltq
shlq $0x2, %rax
addq %rax, %r10
movq -0x28(%rbp), %rax
movl -0x44(%rbp), %r11d
addl $0x38, %r11d
movslq %r11d, %r11
shlq $0x2, %r11
addq %r11, %rax
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x4095b0
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x40912b
movl $0x0, -0x40(%rbp)
cmpl $0x40, -0x40(%rbp)
jge 0x409297
movq -0x28(%rbp), %rax
movslq -0x40(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
movq -0x30(%rbp), %rax
movslq -0x40(%rbp), %rcx
mulss (%rax,%rcx,4), %xmm0
movss %xmm0, -0x154(%rbp)
xorps %xmm0, %xmm0
ucomiss -0x154(%rbp), %xmm0
jbe 0x40924a
movss -0x154(%rbp), %xmm0
movss 0xda22d(%rip), %xmm1    # 0x4e3464
subss %xmm1, %xmm0
callq 0x401120
movss %xmm0, -0x174(%rbp)
jmp 0x409267
movss 0xda212(%rip), %xmm0    # 0x4e3464
addss -0x154(%rbp), %xmm0
callq 0x401148
movss %xmm0, -0x174(%rbp)
movss -0x174(%rbp), %xmm0
cvttss2si %xmm0, %ecx
movslq -0x40(%rbp), %rdx
leaq 0xdb622(%rip), %rax     # 0x4e48a0
movzbl (%rax,%rdx), %eax
movl %ecx, -0x150(%rbp,%rax,4)
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x4091ef
movl -0x150(%rbp), %eax
subl -0x34(%rbp), %eax
movl %eax, -0x158(%rbp)
cmpl $0x0, -0x158(%rbp)
jne 0x4092c6
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq 0x10(%rbp), %rcx
callq 0x409500
jmp 0x409313
movl -0x158(%rbp), %edi
leaq -0x15c(%rbp), %rsi
callq 0x409820
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq 0x10(%rbp), %rcx
movzwl -0x15a(%rbp), %eax
shlq $0x2, %rax
addq %rax, %rcx
callq 0x409500
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
leaq -0x15c(%rbp), %rcx
callq 0x409500
movl $0x3f, -0x160(%rbp)
xorl %eax, %eax
cmpl $0x0, -0x160(%rbp)
movb %al, -0x175(%rbp)
jle 0x409346
movslq -0x160(%rbp), %rax
cmpl $0x0, -0x150(%rbp,%rax,4)
sete %al
movb %al, -0x175(%rbp)
movb -0x175(%rbp), %al
testb $0x1, %al
jne 0x409352
jmp 0x409365
jmp 0x409354
movl -0x160(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x160(%rbp)
jmp 0x40931d
cmpl $0x0, -0x160(%rbp)
jne 0x409391
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
leaq -0x38(%rbp), %rcx
callq 0x409500
movl -0x150(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x4094ef
movl $0x1, -0x40(%rbp)
movl -0x40(%rbp), %eax
cmpl -0x160(%rbp), %eax
jg 0x4094c8
movl -0x40(%rbp), %eax
movl %eax, -0x164(%rbp)
movslq -0x40(%rbp), %rcx
xorl %eax, %eax
cmpl $0x0, -0x150(%rbp,%rcx,4)
movb %al, -0x176(%rbp)
jne 0x4093d8
movl -0x40(%rbp), %eax
cmpl -0x160(%rbp), %eax
setle %al
movb %al, -0x176(%rbp)
movb -0x176(%rbp), %al
testb $0x1, %al
jne 0x4093e4
jmp 0x4093f1
jmp 0x4093e6
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x4093b0
movl -0x40(%rbp), %eax
subl -0x164(%rbp), %eax
movl %eax, -0x168(%rbp)
cmpl $0x10, -0x168(%rbp)
jl 0x409459
movl -0x168(%rbp), %eax
sarl $0x4, %eax
movl %eax, -0x16c(%rbp)
movl $0x1, -0x48(%rbp)
movl -0x48(%rbp), %eax
cmpl -0x16c(%rbp), %eax
jg 0x40944a
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
leaq -0x3c(%rbp), %rcx
callq 0x409500
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x40941f
movl -0x168(%rbp), %eax
andl $0xf, %eax
movl %eax, -0x168(%rbp)
movslq -0x40(%rbp), %rax
movl -0x150(%rbp,%rax,4), %edi
leaq -0x170(%rbp), %rsi
callq 0x409820
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq 0x18(%rbp), %rcx
movl -0x168(%rbp), %eax
shll $0x4, %eax
movzwl -0x16e(%rbp), %r8d
addl %r8d, %eax
cltq
shlq $0x2, %rax
addq %rax, %rcx
callq 0x409500
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
leaq -0x170(%rbp), %rcx
callq 0x409500
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x409398
cmpl $0x3f, -0x160(%rbp)
je 0x4094e6
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
leaq -0x38(%rbp), %rcx
callq 0x409500
movl -0x150(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x190, %rsp            # imm = 0x190
popq %rbp
retq
nopl (%rax,%rax)