// File: /workspace/github_c_makefile_star2_O1/albinoloverats[P]hide/src/jpeg-save.c
// Function: process_DU
static void process_DU(int8_t *ComponentDU, double *fdtbl, int16_t *DC, bitstring *HTDC, bitstring *HTAC)
{
	bitstring EOB = HTAC[0x00];
	bitstring M16zeroes = HTAC[0xF0];
	uint8_t end0pos;

	fdct_and_quantization(ComponentDU, fdtbl, DU_DCT);
	// zigzag reorder
	for (int i = 0; i <= 63; i++)
		DU[zigzag[i]] = DU_DCT[i];


	static uint64_t offset = 0;
	static uint8_t bit = 1;

	for (uint64_t i = 0; i < 64 && offset < message->size + sizeof message->size; i++)
		if (DU[i] > 1)
		{
			uint8_t v = (*(message->data + offset) & bit);
			if (v)
				DU[i] |= 0x0001;
			else
				DU[i] &= 0xFFFE;
			bit <<= 1;
			if (!bit)
			{
				bit = 1;
				offset++;
			}
		}


	int16_t diff = DU[0] - *DC;
	*DC = DU[0];
	// Encode DC
	if (diff == 0)
		writebits(HTDC[0]); // diff might be 0
	else
	{
		writebits(HTDC[category[diff]]);
		writebits(bitcode[diff]);
	}
	// Encode ACs
	for (end0pos = 63; (end0pos > 0) && (DU[end0pos] == 0); end0pos--);
	// end0pos = first element in reverse order !=0
	if (end0pos == 0)
	{
		writebits(EOB);
		return;
	}

	for (int i = 1; i <= end0pos; i++)
	{
		int startpos = i;
		for (; (DU[i] == 0) && (i <= end0pos); i++);
		int nrzeroes = i - startpos;
		if (nrzeroes >= 16)
		{
			for (int nrmarker = 1; nrmarker <= (nrzeroes >> 4); nrmarker++)
				writebits(M16zeroes);
			nrzeroes %= 16;
		}
		writebits(HTAC[(nrzeroes << 4) + category[DU[i]]]);
		writebits(bitcode[DU[i]]);
	}
	if (end0pos != 63)
		writebits(EOB);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x228, %rsp            # imm = 0x228
movl (%r8), %ebp
movq %r8, 0x18(%rsp)
movl 0x3c0(%r8), %r14d
xorl %eax, %eax
movsbl (%rdi,%rax), %r8d
xorps %xmm0, %xmm0
cvtsi2sd %r8d, %xmm0
movsd %xmm0, 0x20(%rsp,%rax,8)
incq %rax
cmpq $0x40, %rax
jne 0x3ba2
xorl %eax, %eax
movsd 0x1628(%rip), %xmm0     # 0x51f0
movsd 0x1628(%rip), %xmm1     # 0x51f8
movsd 0x1628(%rip), %xmm2     # 0x5200
movsd 0x1628(%rip), %xmm3     # 0x5208
movsd 0x58(%rsp,%rax), %xmm6
movsd 0x20(%rsp,%rax), %xmm5
movsd 0x28(%rsp,%rax), %xmm4
movapd %xmm5, %xmm8
addsd %xmm6, %xmm8
subsd %xmm6, %xmm5
movsd 0x50(%rsp,%rax), %xmm6
movapd %xmm4, %xmm9
addsd %xmm6, %xmm9
subsd %xmm6, %xmm4
movsd 0x30(%rsp,%rax), %xmm6
movsd 0x48(%rsp,%rax), %xmm7
movapd %xmm6, %xmm10
addsd %xmm7, %xmm10
subsd %xmm7, %xmm6
movsd 0x38(%rsp,%rax), %xmm7
movsd 0x40(%rsp,%rax), %xmm11
movapd %xmm7, %xmm12
addsd %xmm11, %xmm12
subsd %xmm11, %xmm7
movapd %xmm8, %xmm11
addsd %xmm12, %xmm11
subsd %xmm12, %xmm8
movapd %xmm9, %xmm12
addsd %xmm10, %xmm12
subsd %xmm10, %xmm9
movapd %xmm12, %xmm10
addsd %xmm11, %xmm10
movsd %xmm10, 0x20(%rsp,%rax)
subsd %xmm12, %xmm11
movsd %xmm11, 0x40(%rsp,%rax)
addsd %xmm8, %xmm9
mulsd %xmm0, %xmm9
movapd %xmm8, %xmm10
addsd %xmm9, %xmm10
movsd %xmm10, 0x30(%rsp,%rax)
subsd %xmm9, %xmm8
movsd %xmm8, 0x50(%rsp,%rax)
addsd %xmm6, %xmm7
addsd %xmm4, %xmm6
addsd %xmm5, %xmm4
movapd %xmm7, %xmm8
subsd %xmm4, %xmm8
mulsd %xmm1, %xmm8
mulsd %xmm2, %xmm7
addsd %xmm8, %xmm7
mulsd %xmm3, %xmm4
addsd %xmm8, %xmm4
mulsd %xmm0, %xmm6
movapd %xmm5, %xmm8
addsd %xmm6, %xmm8
subsd %xmm6, %xmm5
movapd %xmm5, %xmm6
addsd %xmm7, %xmm6
movsd %xmm6, 0x48(%rsp,%rax)
subsd %xmm7, %xmm5
movsd %xmm5, 0x38(%rsp,%rax)
movapd %xmm8, %xmm5
addsd %xmm4, %xmm5
movsd %xmm5, 0x28(%rsp,%rax)
subsd %xmm4, %xmm8
movsd %xmm8, 0x58(%rsp,%rax)
addq $0x40, %rax
cmpl $0x200, %eax            # imm = 0x200
jne 0x3be0
xorl %eax, %eax
movsd 0x1e0(%rsp,%rax,8), %xmm6
movsd 0x20(%rsp,%rax,8), %xmm5
movsd 0x60(%rsp,%rax,8), %xmm4
movapd %xmm5, %xmm8
addsd %xmm6, %xmm8
subsd %xmm6, %xmm5
movsd 0x1a0(%rsp,%rax,8), %xmm6
movapd %xmm4, %xmm9
addsd %xmm6, %xmm9
subsd %xmm6, %xmm4
movsd 0xa0(%rsp,%rax,8), %xmm6
movsd 0x160(%rsp,%rax,8), %xmm7
movapd %xmm6, %xmm10
addsd %xmm7, %xmm10
subsd %xmm7, %xmm6
movsd 0xe0(%rsp,%rax,8), %xmm7
movsd 0x120(%rsp,%rax,8), %xmm11
movapd %xmm7, %xmm12
addsd %xmm11, %xmm12
subsd %xmm11, %xmm7
movapd %xmm8, %xmm11
addsd %xmm12, %xmm11
subsd %xmm12, %xmm8
movapd %xmm9, %xmm12
addsd %xmm10, %xmm12
subsd %xmm10, %xmm9
movapd %xmm12, %xmm10
addsd %xmm11, %xmm10
movsd %xmm10, 0x20(%rsp,%rax,8)
subsd %xmm12, %xmm11
movsd %xmm11, 0x120(%rsp,%rax,8)
addsd %xmm8, %xmm9
mulsd %xmm0, %xmm9
movapd %xmm8, %xmm10
addsd %xmm9, %xmm10
movsd %xmm10, 0xa0(%rsp,%rax,8)
subsd %xmm9, %xmm8
movsd %xmm8, 0x1a0(%rsp,%rax,8)
addsd %xmm6, %xmm7
addsd %xmm4, %xmm6
addsd %xmm5, %xmm4
movapd %xmm7, %xmm8
subsd %xmm4, %xmm8
mulsd %xmm1, %xmm8
mulsd %xmm2, %xmm7
addsd %xmm8, %xmm7
mulsd %xmm3, %xmm4
addsd %xmm8, %xmm4
mulsd %xmm0, %xmm6
movapd %xmm5, %xmm8
addsd %xmm6, %xmm8
subsd %xmm6, %xmm5
movapd %xmm5, %xmm6
addsd %xmm7, %xmm6
movsd %xmm6, 0x160(%rsp,%rax,8)
subsd %xmm7, %xmm5
movsd %xmm5, 0xe0(%rsp,%rax,8)
movapd %xmm8, %xmm5
addsd %xmm4, %xmm5
movsd %xmm5, 0x60(%rsp,%rax,8)
subsd %xmm4, %xmm8
movsd %xmm8, 0x1e0(%rsp,%rax,8)
incq %rax
cmpl $0x8, %eax
jne 0x3d2f
xorl %edi, %edi
movsd 0x1369(%rip), %xmm0     # 0x5210
leaq 0x56622(%rip), %rax     # 0x5a4d0
movsd 0x20(%rsp,%rdi,4), %xmm1
mulsd (%rsi,%rdi,4), %xmm1
addsd %xmm0, %xmm1
cvttsd2si %xmm1, %r8d
addl $0xffffc000, %r8d       # imm = 0xFFFFC000
movw %r8w, (%rdi,%rax)
addq $0x2, %rdi
cmpq $0x80, %rdi
jne 0x3eae
xorl %esi, %esi
leaq 0x137c(%rip), %rdi      # 0x5260
leaq 0x56665(%rip), %r15     # 0x5a550
movzwl (%rax), %r8d
movzbl (%rsi,%rdi), %r9d
movw %r8w, (%r15,%r9,2)
incq %rsi
addq $0x2, %rax
cmpq $0x40, %rsi
jne 0x3eeb
movq 0x566c3(%rip), %rax     # 0x5a5d0
movb 0x31b2(%rip), %r9b      # 0x70c6
movq 0x3225(%rip), %rsi      # 0x7140
movq (%rsi), %rdi
addq $0x8, %rdi
xorl %r8d, %r8d
cmpq %rdi, %rax
jae 0x3f7f
movzwl (%r8,%r15), %r10d
cmpw $0x2, %r10w
jl 0x3f72
movq 0x8(%rsi), %r11
testb %r9b, (%r11,%rax)
je 0x3f46
orl $0x1, %r10d
jmp 0x3f4d
andl $0x7ffe, %r10d          # imm = 0x7FFE
movw %r10w, (%r8,%r15)
addb %r9b, %r9b
movb %r9b, 0x316a(%rip)      # 0x70c6
jne 0x3f72
movb $0x1, 0x3161(%rip)      # 0x70c6
incq %rax
movq %rax, 0x56661(%rip)     # 0x5a5d0
movb $0x1, %r9b
addq $0x2, %r8
cmpq $0x80, %r8
jne 0x3f25
movzwl 0x565ca(%rip), %eax     # 0x5a550
movzwl (%rdx), %esi
movw %ax, (%rdx)
cmpw %si, %ax
je 0x3fb8
subl %esi, %eax
movq 0x13c56(%rip), %rdx     # 0x17bf0
movswq %ax, %rbx
movzbl (%rdx,%rbx), %eax
movl (%rcx,%rax,4), %edi
callq 0x3af0
shlq $0x2, %rbx
addq 0x53c4b(%rip), %rbx     # 0x57c00
movq %rbx, %rcx
movl (%rcx), %edi
callq 0x3af0
movb $0x3f, %al
movzbl %al, %r13d
cmpw $0x0, (%r15,%r13,2)
jne 0x3fd6
decb %al
jne 0x3fc1
jmp 0x40b7
movb %al, 0x7(%rsp)
movl %r14d, 0xc(%rsp)
movl %ebp, 0x8(%rsp)
movl $0x1, %ebx
movslq %ebx, %rax
decq %rax
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
xorl %ecx, %ecx
movl %ecx, %r12d
leaq 0x1(%rax), %rbp
incl %r14d
cmpq %r13, %rbp
jg 0x4016
leal 0x1(%r12), %ecx
cmpw $0x0, 0x2(%r15,%rax,2)
movq %rbp, %rax
je 0x3ff6
movl %r14d, %eax
cmpl $0x10, %r14d
jl 0x404b
movq %rbx, 0x10(%rsp)
shrl $0x4, %r12d
cmpl $0x1, %r12d
adcl $0x0, %r12d
movl 0xc(%rsp), %ebx
movl %ebx, %edi
callq 0x3af0
decl %r12d
jne 0x4034
movl %r14d, %eax
andl $0xf, %eax
movq 0x10(%rsp), %rbx
leaq (,%rbp,2), %r12
shll $0x4, %eax
movq 0x13b93(%rip), %rcx     # 0x17bf0
movswq (%r12,%r15), %rdx
movzbl (%rcx,%rdx), %ecx
cltq
addq %rcx, %rax
movq 0x18(%rsp), %rcx
movl (%rcx,%rax,4), %edi
callq 0x3af0
movq 0x53b81(%rip), %rax     # 0x57c00
movswq (%r12,%r15), %rcx
movl (%rax,%rcx,4), %edi
callq 0x3af0
addl %r14d, %ebx
incl %ebx
cmpq %r13, %rbp
jl 0x3fe8
cmpb $0x3f, 0x7(%rsp)
movl 0x8(%rsp), %ebp
jne 0x40b7
addq $0x228, %rsp            # imm = 0x228
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %ebp, %edi
addq $0x228, %rsp            # imm = 0x228
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3af0