// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq -0x28(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x2c(%rbp)
movq -0x28(%rbp), %rax
movl 0x3c0(%rax), %eax
movl %eax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
leaq 0x5711f(%rip), %rdx     # 0x5c8d0
callq 0x5ae0
movl $0x0, -0x38(%rbp)
cmpl $0x3f, -0x38(%rbp)
jg 0x57f9
movslq -0x38(%rbp), %rcx
leaq 0x57102(%rip), %rax     # 0x5c8d0
movw (%rax,%rcx,2), %dx
movslq -0x38(%rbp), %rcx
leaq 0x3a53(%rip), %rax      # 0x9230
movzbl (%rax,%rcx), %eax
movl %eax, %ecx
leaq 0x57166(%rip), %rax     # 0x5c950
movw %dx, (%rax,%rcx,2)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x57bd
movq $0x0, -0x40(%rbp)
xorl %eax, %eax
cmpq $0x40, -0x40(%rbp)
movb %al, -0x55(%rbp)
jae 0x582b
movq 0x571bc(%rip), %rax     # 0x5c9d0
movq 0x3d25(%rip), %rcx      # 0x9540
movq (%rcx), %rcx
addq $0x8, %rcx
cmpq %rcx, %rax
setb %al
movb %al, -0x55(%rbp)
movb -0x55(%rbp), %al
testb $0x1, %al
jne 0x5837
jmp 0x5901
movq -0x40(%rbp), %rcx
leaq 0x5710e(%rip), %rax     # 0x5c950
movswl (%rax,%rcx,2), %eax
cmpl $0x1, %eax
jle 0x58ee
movq 0x3cea(%rip), %rax      # 0x9540
movq 0x8(%rax), %rax
movq 0x5716f(%rip), %rcx     # 0x5c9d0
movzbl (%rax,%rcx), %eax
movzbl 0x3c36(%rip), %ecx      # 0x94a2
andl %ecx, %eax
movb %al, -0x41(%rbp)
cmpb $0x0, -0x41(%rbp)
je 0x5899
movq -0x40(%rbp), %rcx
leaq 0x570ce(%rip), %rax     # 0x5c950
movswl (%rax,%rcx,2), %eax
orl $0x1, %eax
movw %ax, %dx
leaq 0x570bd(%rip), %rax     # 0x5c950
movw %dx, (%rax,%rcx,2)
jmp 0x58bb
movq -0x40(%rbp), %rcx
leaq 0x570ac(%rip), %rax     # 0x5c950
movswl (%rax,%rcx,2), %eax
andl $0xfffe, %eax           # imm = 0xFFFE
movw %ax, %dx
leaq 0x57099(%rip), %rax     # 0x5c950
movw %dx, (%rax,%rcx,2)
movzbl 0x3be0(%rip), %eax      # 0x94a2
shll %eax
movb %al, 0x3bd8(%rip)       # 0x94a2
cmpb $0x0, 0x3bd1(%rip)      # 0x94a2
jne 0x58ec
movb $0x1, 0x3bc8(%rip)      # 0x94a2
movq 0x570ef(%rip), %rax     # 0x5c9d0
addq $0x1, %rax
movq %rax, 0x570e4(%rip)     # 0x5c9d0
jmp 0x58ee
jmp 0x58f0
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x5801
movswl 0x57048(%rip), %eax     # 0x5c950
movq -0x18(%rbp), %rcx
movswl (%rcx), %ecx
subl %ecx, %eax
movw %ax, -0x44(%rbp)
movw 0x57034(%rip), %cx      # 0x5c950
movq -0x18(%rbp), %rax
movw %cx, (%rax)
movswl -0x44(%rbp), %eax
cmpl $0x0, %eax
jne 0x5939
movq -0x20(%rbp), %rax
movl (%rax), %edi
callq 0x4a60
jmp 0x5969
movq -0x20(%rbp), %rax
movq 0x146ac(%rip), %rcx     # 0x19ff0
movswq -0x44(%rbp), %rdx
movzbl (%rcx,%rdx), %ecx
movl (%rax,%rcx,4), %edi
callq 0x4a60
movq 0x546a4(%rip), %rax     # 0x5a000
movswq -0x44(%rbp), %rcx
movl (%rax,%rcx,4), %edi
callq 0x4a60
movb $0x3f, -0x31(%rbp)
movzbl -0x31(%rbp), %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x56(%rbp)
jle 0x5995
movzbl -0x31(%rbp), %eax
movl %eax, %ecx
leaq 0x56fc8(%rip), %rax     # 0x5c950
movswl (%rax,%rcx,2), %eax
cmpl $0x0, %eax
sete %al
movb %al, -0x56(%rbp)
movb -0x56(%rbp), %al
testb $0x1, %al
jne 0x599e
jmp 0x59aa
jmp 0x59a0
movb -0x31(%rbp), %al
addb $-0x1, %al
movb %al, -0x31(%rbp)
jmp 0x596d
movzbl -0x31(%rbp), %eax
cmpl $0x0, %eax
jne 0x59c0
movl -0x2c(%rbp), %edi
callq 0x4a60
jmp 0x5ace
movl $0x1, -0x48(%rbp)
movl -0x48(%rbp), %eax
movzbl -0x31(%rbp), %ecx
cmpl %ecx, %eax
jg 0x5abd
movl -0x48(%rbp), %eax
movl %eax, -0x4c(%rbp)
movslq -0x48(%rbp), %rcx
leaq 0x56f69(%rip), %rax     # 0x5c950
movswl (%rax,%rcx,2), %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x57(%rbp)
jne 0x5a04
movl -0x48(%rbp), %eax
movzbl -0x31(%rbp), %ecx
cmpl %ecx, %eax
setle %al
movb %al, -0x57(%rbp)
movb -0x57(%rbp), %al
testb $0x1, %al
jne 0x5a0d
jmp 0x5a1a
jmp 0x5a0f
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x59dc
movl -0x48(%rbp), %eax
subl -0x4c(%rbp), %eax
movl %eax, -0x50(%rbp)
cmpl $0x10, -0x50(%rbp)
jl 0x5a5e
movl $0x1, -0x54(%rbp)
movl -0x54(%rbp), %eax
movl -0x50(%rbp), %ecx
sarl $0x4, %ecx
cmpl %ecx, %eax
jg 0x5a50
movl -0x30(%rbp), %edi
callq 0x4a60
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x5a30
movl -0x50(%rbp), %eax
movl $0x10, %ecx
cltd
idivl %ecx
movl %edx, -0x50(%rbp)
movq -0x28(%rbp), %rax
movl -0x50(%rbp), %ecx
shll $0x4, %ecx
movq 0x14581(%rip), %rdx     # 0x19ff0
movslq -0x48(%rbp), %rdi
leaq 0x56ed6(%rip), %rsi     # 0x5c950
movswq (%rsi,%rdi,2), %rsi
movzbl (%rdx,%rsi), %edx
addl %edx, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %edi
callq 0x4a60
movq 0x54569(%rip), %rax     # 0x5a000
movslq -0x48(%rbp), %rdx
leaq 0x56eae(%rip), %rcx     # 0x5c950
movswq (%rcx,%rdx,2), %rcx
movl (%rax,%rcx,4), %edi
callq 0x4a60
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x59c7
movzbl -0x31(%rbp), %eax
cmpl $0x3f, %eax
je 0x5ace
movl -0x2c(%rbp), %edi
callq 0x4a60
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)