// File: /workspace/github_c_makefile_star2_O2/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, %r12
movq %rdi, %r14
movq 0x8(%rdi), %r15
leaq 0x40(%rsp), %rdi
xorl %ebx, %ebx
movl $0x100, %edx            # imm = 0x100
xorl %esi, %esi
callq 0x1090
cmpq $0x40, %rbx
je 0x2477
movswl 0x20(%r14,%rbx,2), %eax
movl %eax, 0x40(%rsp,%rbx,4)
incq %rbx
jmp 0x2462
movq %r12, 0x10(%rsp)
movb 0x3cae(%rip), %al       # 0x6130
movq 0x3c9f(%rip), %r12      # 0x6128
movb 0x3c28(%rip), %bpl      # 0x60b8
movl 0x3c79(%rip), %r13d     # 0x6110
movq 0x3c7a(%rip), %rcx      # 0x6118
movq %rcx, (%rsp)
xorl %r14d, %r14d
cmpq $0x40, %r14
je 0x2586
testb $0x1, %al
je 0x24ca
movq 0x3c4e(%rip), %rcx      # 0x6108
movq (%rcx), %rcx
addq $0x8, %rcx
cmpq %rcx, %r12
jae 0x2586
movl 0x40(%rsp,%r14,4), %ecx
cmpl $0x2, %ecx
jl 0x257e
testl %r13d, %r13d
je 0x2574
cmpl $0x1, %r13d
jne 0x257e
testb $0x1, %cl
je 0x250f
movq 0x3c11(%rip), %rcx      # 0x6108
addq $0x8, %rcx
testb $0x1, %al
leaq 0x3c04(%rip), %rdx      # 0x6108
cmoveq %rdx, %rcx
movq (%rcx), %rcx
orb %bpl, (%rcx,%r12)
addb %bpl, %bpl
movb %bpl, 0x3b9f(%rip)      # 0x60b8
jne 0x252f
movb $0x1, 0x3b96(%rip)      # 0x60b8
incq %r12
movq %r12, 0x3bfc(%rip)      # 0x6128
movb $0x1, %bpl
cmpq $0x8, %r12
setb %cl
orb %al, %cl
testb $0x1, %cl
jne 0x257e
movq 0x3bc4(%rip), %rbx      # 0x6108
movq (%rsp), %rax
movq %rax, %rdi
testq %rax, %rax
jne 0x2556
movq (%rbx), %rdi
bswapq %rdi
movq %rdi, (%rbx)
addq $0x8, %rdi
pushq $0x1
popq %rsi
callq 0x10c0
movq %rax, 0x8(%rbx)
movb $0x1, 0x3bc0(%rip)      # 0x6130
movb $0x1, %al
jmp 0x257e
movq 0x3b8d(%rip), %rcx      # 0x6108
incq (%rcx)
incq %r14
jmp 0x24a5
xorl %eax, %eax
cmpq $0x40, %rax
je 0x25a7
cvtsi2sdl 0x40(%rsp,%rax,4), %xmm0
mulsd (%r15,%rax,8), %xmm0
cvttsd2si %xmm0, %ecx
movl %ecx, 0x40(%rsp,%rax,4)
incq %rax
jmp 0x2588
leaq 0x240(%rsp), %rdi
xorl %ebx, %ebx
movl $0x100, %edx            # imm = 0x100
xorl %esi, %esi
callq 0x1090
leaq 0x1abc(%rip), %rax      # 0x4080
cmpq $0x100, %rbx            # imm = 0x100
je 0x25e2
movslq (%rbx,%rax), %rcx
movl 0x40(%rsp,%rcx,4), %ecx
movl %ecx, 0x240(%rsp,%rbx)
addq $0x4, %rbx
jmp 0x25c4
leaq 0x340(%rsp), %r14
xorl %ebx, %ebx
movl $0x100, %edx            # imm = 0x100
movq %r14, %rdi
xorl %esi, %esi
callq 0x1090
xorl %eax, %eax
cmpq $0x8, %rbx
je 0x2637
cltq
leaq (%rsp,%rax,4), %rcx
addq $0x240, %rcx            # imm = 0x240
negq %rax
xorl %edx, %edx
cmpq $0x20, %rdx
je 0x262b
movl (%rcx,%rdx), %esi
movl %esi, (%r14,%rdx,8)
addq $0x4, %rdx
decq %rax
jmp 0x2615
incq %rbx
addq $0x4, %r14
negq %rax
jmp 0x25fd
leaq 0x140(%rsp), %rdi
xorl %ebx, %ebx
movl $0x100, %edx            # imm = 0x100
xorl %esi, %esi
callq 0x1090
leaq 0x1b2c(%rip), %r13      # 0x4180
cmpq $0x8, %rbx
je 0x277e
leal 0x1(,%rbx,2), %eax
cvtsi2sd %eax, %xmm0
mulsd 0x19e7(%rip), %xmm0     # 0x4058
movsd %xmm0, 0x28(%rsp)
xorl %ebp, %ebp
movq %rbx, 0x18(%rsp)
cmpq $0x8, %rbp
je 0x2776
leal 0x1(,%rbp,2), %eax
cvtsi2sd %eax, %xmm0
mulsd 0x19bd(%rip), %xmm0     # 0x4058
movsd %xmm0, 0x20(%rsp)
xorpd %xmm0, %xmm0
movsd %xmm0, (%rsp)
leaq 0x340(%rsp), %r12
xorl %ebx, %ebx
cmpq $0x8, %rbx
je 0x274d
xorl %r14d, %r14d
testq %rbx, %rbx
sete %r14b
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
cmpq $0x8, %r14
je 0x2741
xorl %r15d, %r15d
testq %r14, %r14
sete %r15b
cvtsi2sd %r14d, %xmm0
mulsd 0x28(%rsp), %xmm0
callq 0x10a0
movsd (%r13,%r15,8), %xmm1
mulsd 0x30(%rsp), %xmm1
cvtsi2sdl (%r12,%r14,4), %xmm2
mulsd %xmm1, %xmm2
mulsd 0x38(%rsp), %xmm2
mulsd %xmm0, %xmm2
movsd (%rsp), %xmm0
addsd %xmm2, %xmm0
movsd %xmm0, (%rsp)
incq %r14
jmp 0x26ed
incq %rbx
addq $0x20, %r12
jmp 0x26b4
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
jmp 0x267e
incq %rbx
jmp 0x2654
movslq 0xc(%rsp), %rax
xorl %ecx, %ecx
movl $0xff, %edx
xorl %esi, %esi
movq 0x10(%rsp), %r11
leaq 0x140(%rsp), %rbx
cmpq $0x8, %rsi
je 0x27e1
movq %rbx, %rdi
xorl %r8d, %r8d
cmpq $0x8, %r8
je 0x27d5
movl (%rdi), %r9d
leal 0x80(%r9), %r10d
cmpl $0x7f, %r9d
cmovgl %edx, %r10d
subl $-0x80, %r9d
cmovll %ecx, %r10d
movl %r9d, (%rdi)
movb %r10b, (%r11,%r8)
incq %r8
addq $0x20, %rdi
jmp 0x27a5
addq %rax, %r11
incq %rsi
addq $0x4, %rbx
jmp 0x2799
addq $0x448, %rsp            # imm = 0x448
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq