// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x4b0, %rsp            # imm = 0x4B0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq -0x8(%rbp), %rax
addq $0x20, %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x28(%rbp)
leaq -0x130(%rbp), %rdi
xorl %esi, %esi
movl $0x100, %edx            # imm = 0x100
callq 0x1090
movl $0x0, -0x134(%rbp)
cmpl $0x40, -0x134(%rbp)
jge 0x3342
movq -0x20(%rbp), %rax
movslq -0x134(%rbp), %rcx
movswl (%rax,%rcx,2), %ecx
movslq -0x134(%rbp), %rax
movl %ecx, -0x130(%rbp,%rax,4)
movl -0x134(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x134(%rbp)
jmp 0x330b
movl $0x0, -0x138(%rbp)
xorl %eax, %eax
cmpl $0x40, -0x138(%rbp)
movb %al, -0x489(%rbp)
jge 0x339d
xorl %eax, %eax
testb $0x1, 0x61ca(%rip)      # 0x9530
movb %al, -0x48a(%rbp)
je 0x338f
movq 0x61b3(%rip), %rax      # 0x9528
movq 0x618c(%rip), %rcx      # 0x9508
movq (%rcx), %rcx
addq $0x8, %rcx
cmpq %rcx, %rax
setae %al
movb %al, -0x48a(%rbp)
movb -0x48a(%rbp), %al
xorb $-0x1, %al
movb %al, -0x489(%rbp)
movb -0x489(%rbp), %al
testb $0x1, %al
jne 0x33ac
jmp 0x3608
movslq -0x138(%rbp), %rax
cmpl $0x1, -0x130(%rbp,%rax,4)
jle 0x35f2
movl 0x6149(%rip), %eax      # 0x9510
movl %eax, -0x490(%rbp)
testl %eax, %eax
je 0x35df
jmp 0x33d7
movl -0x490(%rbp), %eax
subl $0x1, %eax
jne 0x35f0
jmp 0x33e8
testb $0x1, 0x6141(%rip)      # 0x9530
je 0x3405
movq 0x6110(%rip), %rax      # 0x9508
movq 0x8(%rax), %rax
movq %rax, -0x498(%rbp)
jmp 0x3413
movq 0x60fc(%rip), %rax      # 0x9508
movq %rax, -0x498(%rbp)
movq -0x498(%rbp), %rax
addq 0x6107(%rip), %rax      # 0x9528
movq %rax, -0x140(%rbp)
movslq -0x138(%rbp), %rax
movl -0x130(%rbp,%rax,4), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x3459
movzbl 0x5c7b(%rip), %edx      # 0x90c0
andl $0xff, %edx
movq -0x140(%rbp), %rax
movzbl (%rax), %ecx
orl %edx, %ecx
movb %cl, (%rax)
movzbl 0x5c60(%rip), %eax      # 0x90c0
shll %eax
movb %al, 0x5c58(%rip)       # 0x90c0
cmpb $0x0, 0x5c51(%rip)      # 0x90c0
jne 0x348a
movb $0x1, 0x5c48(%rip)      # 0x90c0
movq 0x60a9(%rip), %rax      # 0x9528
addq $0x1, %rax
movq %rax, 0x609e(%rip)      # 0x9528
cmpq $0x8, 0x6096(%rip)      # 0x9528
jb 0x35dd
testb $0x1, 0x6091(%rip)      # 0x9530
jne 0x35dd
movq 0x606c(%rip), %rax      # 0x9518
movq %rax, -0x4a0(%rbp)
cmpq $0x0, %rax
je 0x34cc
movq -0x4a0(%rbp), %rax
movq %rax, -0x4a8(%rbp)
jmp 0x359f
movq 0x6035(%rip), %rcx      # 0x9508
movabsq $-0x100000000000000, %rax # imm = 0xFF00000000000000
andq (%rcx), %rax
shrq $0x38, %rax
movq 0x601d(%rip), %rdx      # 0x9508
movabsq $0xff000000000000, %rcx # imm = 0xFF000000000000
andq (%rdx), %rcx
shrq $0x28, %rcx
orq %rcx, %rax
movq 0x6002(%rip), %rdx      # 0x9508
movabsq $0xff0000000000, %rcx   # imm = 0xFF0000000000
andq (%rdx), %rcx
shrq $0x18, %rcx
orq %rcx, %rax
movq 0x5fe7(%rip), %rdx      # 0x9508
movabsq $0xff00000000, %rcx     # imm = 0xFF00000000
andq (%rdx), %rcx
shrq $0x8, %rcx
orq %rcx, %rax
movq 0x5fcc(%rip), %rdx      # 0x9508
movabsq $0xff000000, %rcx       # imm = 0xFF000000
andq (%rdx), %rcx
shlq $0x8, %rcx
orq %rcx, %rax
movq 0x5fb1(%rip), %rcx      # 0x9508
movq (%rcx), %rcx
andq $0xff0000, %rcx         # imm = 0xFF0000
shlq $0x18, %rcx
orq %rcx, %rax
movq 0x5f99(%rip), %rcx      # 0x9508
movq (%rcx), %rcx
andq $0xff00, %rcx           # imm = 0xFF00
shlq $0x28, %rcx
orq %rcx, %rax
movq 0x5f81(%rip), %rcx      # 0x9508
movq (%rcx), %rcx
andq $0xff, %rcx
shlq $0x38, %rcx
orq %rcx, %rax
movq %rax, -0x4a8(%rbp)
movq -0x4a8(%rbp), %rcx
movq 0x5f5b(%rip), %rax      # 0x9508
movq %rcx, (%rax)
movq 0x5f51(%rip), %rax      # 0x9508
movq (%rax), %rdi
addq $0x8, %rdi
movl $0x1, %esi
callq 0x10d0
movq %rax, %rcx
movq 0x5f36(%rip), %rax      # 0x9508
movq %rcx, 0x8(%rax)
movb $0x1, 0x5f53(%rip)      # 0x9530
jmp 0x35f0
movq 0x5f22(%rip), %rax      # 0x9508
movq (%rax), %rcx
addq $0x1, %rcx
movq %rcx, (%rax)
jmp 0x35f2
jmp 0x35f4
movl -0x138(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x138(%rbp)
jmp 0x334c
movl $0x0, -0x144(%rbp)
cmpl $0x40, -0x144(%rbp)
jge 0x365e
movslq -0x144(%rbp), %rax
cvtsi2sdl -0x130(%rbp,%rax,4), %xmm0
movq -0x28(%rbp), %rax
movslq -0x144(%rbp), %rcx
mulsd (%rax,%rcx,8), %xmm0
cvttsd2si %xmm0, %ecx
movslq -0x144(%rbp), %rax
movl %ecx, -0x130(%rbp,%rax,4)
movl -0x144(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x144(%rbp)
jmp 0x3612
leaq -0x250(%rbp), %rdi
xorl %esi, %esi
movl $0x100, %edx            # imm = 0x100
callq 0x1090
movl $0x0, -0x254(%rbp)
cmpl $0x40, -0x254(%rbp)
jge 0x36bc
movslq -0x254(%rbp), %rcx
leaq 0x5a3e(%rip), %rax      # 0x90d0
movslq (%rax,%rcx,4), %rax
movl -0x130(%rbp,%rax,4), %ecx
movslq -0x254(%rbp), %rax
movl %ecx, -0x250(%rbp,%rax,4)
movl -0x254(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x254(%rbp)
jmp 0x367b
leaq -0x360(%rbp), %rdi
xorl %esi, %esi
movl $0x100, %edx            # imm = 0x100
callq 0x1090
movl $0x0, -0x364(%rbp)
movl $0x0, -0x368(%rbp)
cmpl $0x8, -0x364(%rbp)
jge 0x375f
movl $0x0, -0x36c(%rbp)
cmpl $0x8, -0x36c(%rbp)
jge 0x374c
movslq -0x368(%rbp), %rax
movl -0x250(%rbp,%rax,4), %edx
movslq -0x36c(%rbp), %rcx
leaq -0x360(%rbp), %rax
shlq $0x5, %rcx
addq %rcx, %rax
movslq -0x364(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x36c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x36c(%rbp)
movl -0x368(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x368(%rbp)
jmp 0x36f6
jmp 0x374e
movl -0x364(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x364(%rbp)
jmp 0x36e3
leaq -0x470(%rbp), %rdi
xorl %esi, %esi
movl $0x100, %edx            # imm = 0x100
callq 0x1090
movl $0x0, -0x474(%rbp)
cmpl $0x8, -0x474(%rbp)
jge 0x37f5
movl $0x0, -0x478(%rbp)
cmpl $0x8, -0x478(%rbp)
jge 0x37e2
movl -0x478(%rbp), %edi
movl -0x474(%rbp), %esi
leaq -0x360(%rbp), %rdx
callq 0x3b50
movl %eax, %edx
movslq -0x478(%rbp), %rcx
leaq -0x470(%rbp), %rax
shlq $0x5, %rcx
addq %rcx, %rax
movslq -0x474(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x478(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x478(%rbp)
jmp 0x378f
jmp 0x37e4
movl -0x474(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x474(%rbp)
jmp 0x377c
movq -0x10(%rbp), %rax
movq %rax, -0x480(%rbp)
movl $0x0, -0x484(%rbp)
cmpl $0x8, -0x484(%rbp)
jge 0x393d
movl $0x0, -0x488(%rbp)
cmpl $0x8, -0x488(%rbp)
jge 0x3912
movslq -0x488(%rbp), %rcx
leaq -0x470(%rbp), %rax
shlq $0x5, %rcx
addq %rcx, %rax
movslq -0x484(%rbp), %rcx
movl (%rax,%rcx,4), %edx
addl $0x80, %edx
movl %edx, (%rax,%rcx,4)
movslq -0x488(%rbp), %rcx
leaq -0x470(%rbp), %rax
shlq $0x5, %rcx
addq %rcx, %rax
movslq -0x484(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
jge 0x3882
xorl %eax, %eax
movl %eax, -0x4ac(%rbp)
jmp 0x38e5
movslq -0x488(%rbp), %rcx
leaq -0x470(%rbp), %rax
shlq $0x5, %rcx
addq %rcx, %rax
movslq -0x484(%rbp), %rcx
cmpl $0xff, (%rax,%rcx,4)
jle 0x38b4
movl $0xff, %eax
movl %eax, -0x4b0(%rbp)
jmp 0x38d9
movslq -0x488(%rbp), %rcx
leaq -0x470(%rbp), %rax
shlq $0x5, %rcx
addq %rcx, %rax
movslq -0x484(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x4b0(%rbp)
movl -0x4b0(%rbp), %eax
movl %eax, -0x4ac(%rbp)
movl -0x4ac(%rbp), %eax
movb %al, %dl
movq -0x480(%rbp), %rax
movslq -0x488(%rbp), %rcx
movb %dl, (%rax,%rcx)
movl -0x488(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x488(%rbp)
jmp 0x3821
movl -0x14(%rbp), %ecx
movq -0x480(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x480(%rbp)
movl -0x484(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x484(%rbp)
jmp 0x380a
addq $0x4b0, %rsp            # imm = 0x4B0
popq %rbp
retq
nopw %cs:(%rax,%rax)