// File: /workspace/github_c_makefile_star2_O3/albinoloverats[P]hide/src/jpeg-load.c
// Function: DecodeSingleBlock
static void DecodeSingleBlock(stComponent *comp, uint8_t *outputBuf, int stride)
{
	int16_t *inptr = comp->m_DCT;
	double *quantptr = comp->m_qTable;

	// Create a temp 8x8, i.e. 64 array for the data
	int data[64] = { 0x0 };

	// Copy our data into the temp array
	for (int i = 0; i < 64; i++)
		data[i] = inptr[i];


	static uint64_t offset = 0;
	static uint8_t bit = 1;
	static bool aloc = false;

	for (int i = 0; i < 64 && !(aloc && offset >= message->size + sizeof message->size); i++)
		if (data[i] > 1)
		{
			switch (action)
			{
				case JPEG_LOAD_FIND:
				{
					uint8_t *ptr = (aloc ? message->data : (uint8_t *)&message->size) + offset;
					if (data[i] & 0x01)
						*ptr |= (0xFF & bit);
					bit <<= 1;
					if (!bit)
					{
						bit = 1;
						offset++;
					}
					if (offset >= sizeof message->size && !aloc)
					{
						message->size = fill_size ? : ntohll(message->size);
						message->data = calloc(message->size + sizeof message->size, sizeof (uint8_t));
						aloc = true;
					}
					break;
				}
				case JPEG_LOAD_READ:
					message->size++;
					break;
			}
		}


	// De-Quantize
	DequantizeBlock(data, quantptr);

	// De-Zig-Zag
	int block[64] = { 0x0 };
	DeZigZag(block, data);

	// Create an 8x8 array
	int arrayBlock[8][8] = { { 0x0 } };
	TransformArray(arrayBlock, block);

	// Inverse DCT
	int val[8][8] = { { 0x0 } };
	PerformIDCT(val, arrayBlock);

	// Level Shift each element (i.e. add 128), and copy to our output
	uint8_t *outptr = outputBuf;
	for (int y = 0; y < 8; y++)
	{
		for (int x = 0; x < 8; x++)
		{
			val[x][y] += 128;
			outptr[x] = byte_limit(val[x][y], 0);
		}
		outptr += stride;
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x448, %rsp            # imm = 0x448
movl %edx, 0xc(%rsp)
movq %rsi, 0x10(%rsp)
movq %rdi, %r14
movq 0x8(%rdi), %r15
leaq 0x40(%rsp), %rdi
xorl %ebx, %ebx
movl $0x100, %edx            # imm = 0x100
xorl %esi, %esi
callq 0x1090
movq 0x20(%r14,%rbx,2), %xmm0
punpcklwd %xmm0, %xmm0    # xmm0 = xmm0[0,0,1,1,2,2,3,3]
psrad $0x10, %xmm0
movdqa %xmm0, 0x40(%rsp,%rbx,4)
addq $0x4, %rbx
cmpq $0x40, %rbx
jne 0x27db
movb 0x492f(%rip), %al       # 0x7130
movq 0x4920(%rip), %r14      # 0x7128
movb 0x48a1(%rip), %r13b     # 0x70b0
movl 0x48fa(%rip), %r12d     # 0x7110
movq 0x48fb(%rip), %rcx      # 0x7118
movq %rcx, (%rsp)
xorl %ebp, %ebp
testb $0x1, %al
je 0x283e
movq 0x48da(%rip), %rcx      # 0x7108
movq (%rcx), %rcx
addq $0x8, %rcx
cmpq %rcx, %r14
jae 0x2900
movl 0x40(%rsp,%rbp,4), %ecx
cmpl $0x2, %ecx
jl 0x28f3
testl %r12d, %r12d
je 0x28e9
cmpl $0x1, %r12d
jne 0x28f3
testb $0x1, %cl
je 0x2882
movq 0x489e(%rip), %rcx      # 0x7108
addq $0x8, %rcx
testb $0x1, %al
leaq 0x4891(%rip), %rdx      # 0x7108
cmoveq %rdx, %rcx
movq (%rcx), %rcx
orb %r13b, (%rcx,%r14)
addb %r13b, %r13b
movb %r13b, 0x4824(%rip)     # 0x70b0
jne 0x28a2
movb $0x1, 0x481b(%rip)      # 0x70b0
incq %r14
movq %r14, 0x4889(%rip)      # 0x7128
movb $0x1, %r13b
cmpq $0x8, %r14
setb %cl
orb %al, %cl
testb $0x1, %cl
jne 0x28f3
movq 0x4851(%rip), %rbx      # 0x7108
movq (%rsp), %rax
movq %rax, %rdi
testq %rax, %rax
jne 0x28c9
movq (%rbx), %rdi
bswapq %rdi
movq %rdi, (%rbx)
addq $0x8, %rdi
movl $0x1, %esi
callq 0x10c0
movq %rax, 0x8(%rbx)
movb $0x1, 0x484b(%rip)      # 0x7130
movb $0x1, %al
jmp 0x28f3
movq 0x4818(%rip), %rcx      # 0x7108
incq (%rcx)
incq %rbp
cmpq $0x40, %rbp
jne 0x2823
xorl %eax, %eax
cvtdq2pd 0x40(%rsp,%rax,4), %xmm0
movupd (%r15,%rax,8), %xmm1
mulpd %xmm0, %xmm1
cvttpd2dq %xmm1, %xmm0
movlpd %xmm0, 0x40(%rsp,%rax,4)
addq $0x2, %rax
cmpq $0x40, %rax
jne 0x2902
leaq 0x240(%rsp), %rdi
xorl %ebx, %ebx
movl $0x100, %edx            # imm = 0x100
xorl %esi, %esi
callq 0x1090
leaq 0x273d(%rip), %rax      # 0x5080
movslq (%rbx,%rax), %rcx
movl 0x40(%rsp,%rcx,4), %ecx
movl %ecx, 0x240(%rsp,%rbx)
addq $0x4, %rbx
cmpq $0x100, %rbx            # imm = 0x100
jne 0x2943
leaq 0x340(%rsp), %r14
xorl %ebx, %ebx
movl $0x100, %edx            # imm = 0x100
movq %r14, %rdi
xorl %esi, %esi
callq 0x1090
xorl %eax, %eax
cltq
xorl %ecx, %ecx
movl 0x240(%rsp,%rax,4), %edx
movl %edx, (%r14,%rcx,8)
incq %rax
addq $0x4, %rcx
cmpq $0x20, %rcx
jne 0x297e
incq %rbx
addq $0x4, %r14
cmpq $0x8, %rbx
jne 0x297a
leaq 0x140(%rsp), %rdi
xorl %ebx, %ebx
movl $0x100, %edx            # imm = 0x100
xorl %esi, %esi
callq 0x1090
leaq 0x27c0(%rip), %r13      # 0x5180
leal 0x1(,%rbx,2), %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
mulsd 0x2682(%rip), %xmm0     # 0x5058
movsd %xmm0, 0x28(%rsp)
xorl %ebp, %ebp
movq %rbx, 0x18(%rsp)
leal 0x1(,%rbp,2), %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
mulsd 0x265f(%rip), %xmm0     # 0x5058
movsd %xmm0, 0x20(%rsp)
xorpd %xmm0, %xmm0
movsd %xmm0, (%rsp)
leaq 0x340(%rsp), %r12
xorl %ebx, %ebx
xorl %r14d, %r14d
testq %rbx, %rbx
sete %r14b
xorps %xmm0, %xmm0
cvtsi2sd %ebx, %xmm0
mulsd 0x20(%rsp), %xmm0
callq 0x10a0
movsd %xmm0, 0x38(%rsp)
movsd (%r13,%r14,8), %xmm0
movsd %xmm0, 0x30(%rsp)
xorl %r14d, %r14d
movsd (%rsp), %xmm0
movsd %xmm0, (%rsp)
xorl %r15d, %r15d
testq %r14, %r14
sete %r15b
xorps %xmm0, %xmm0
cvtsi2sd %r14d, %xmm0
mulsd 0x28(%rsp), %xmm0
callq 0x10a0
movsd (%r13,%r15,8), %xmm1
mulsd 0x30(%rsp), %xmm1
xorps %xmm2, %xmm2
cvtsi2sdl (%r12,%r14,4), %xmm2
mulsd %xmm1, %xmm2
mulsd 0x38(%rsp), %xmm2
mulsd %xmm0, %xmm2
movsd (%rsp), %xmm0
addsd %xmm2, %xmm0
incq %r14
cmpq $0x8, %r14
jne 0x2a49
movsd %xmm0, (%rsp)
incq %rbx
addq $0x20, %r12
cmpq $0x8, %rbx
jne 0x2a12
cvttsd2si (%rsp), %eax
sarl $0x2, %eax
movq %rbp, %rcx
shlq $0x5, %rcx
addq %rsp, %rcx
addq $0x140, %rcx            # imm = 0x140
movq 0x18(%rsp), %rbx
movl %eax, (%rcx,%rbx,4)
incq %rbp
cmpq $0x8, %rbp
jne 0x29e3
incq %rbx
cmpq $0x8, %rbx
jne 0x29c0
movslq 0xc(%rsp), %rax
xorl %ecx, %ecx
movl $0xff, %edx
xorl %esi, %esi
movq 0x10(%rsp), %r11
leaq 0x140(%rsp), %rbx
movq %rbx, %rdi
xorl %r8d, %r8d
movl (%rdi), %r9d
leal 0x80(%r9), %r10d
cmpl $0x7f, %r9d
cmovgl %edx, %r10d
subl $-0x80, %r9d
movl %r9d, (%rdi)
cmovll %ecx, %r10d
movb %r10b, (%r11,%r8)
incq %r8
addq $0x20, %rdi
cmpq $0x8, %r8
jne 0x2b13
addq %rax, %r11
incq %rsi
addq $0x4, %rbx
cmpq $0x8, %rsi
jne 0x2b0d
addq $0x448, %rsp            # imm = 0x448
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop