// File: /workspace/github_c_makefile_star2_O0/phoboslab[P]pl_mpeg/./pl_mpeg.h
// Function: plm_video_decode_block
void plm_video_decode_block(plm_video_t *self, int block) {

	int n = 0;
	uint8_t *quant_matrix;

	// Decode DC coefficient of intra-coded blocks
	if (self->macroblock_intra) {
		int predictor;
		int dct_size;

		// DC prediction
		int plane_index = block > 3 ? block - 3 : 0;
		predictor = self->dc_predictor[plane_index];
		dct_size = plm_buffer_read_vlc(self->buffer, PLM_VIDEO_DCT_SIZE[plane_index]);

		// Read DC coeff
		if (dct_size > 0) {
			int differential = plm_buffer_read(self->buffer, dct_size);
			if ((differential & (1 << (dct_size - 1))) != 0) {
				self->block_data[0] = predictor + differential;
			}
			else {
				self->block_data[0] = predictor + (-(1 << dct_size) | (differential + 1));
			}
		}
		else {
			self->block_data[0] = predictor;
		}

		// Save predictor value
		self->dc_predictor[plane_index] = self->block_data[0];

		// Dequantize + premultiply
		self->block_data[0] <<= (3 + 5);

		quant_matrix = self->intra_quant_matrix;
		n = 1;
	}
	else {
		quant_matrix = self->non_intra_quant_matrix;
	}

	// Decode AC coefficients (+DC for non-intra)
	int level = 0;
	while (TRUE) {
		int run = 0;
		uint16_t coeff = plm_buffer_read_vlc_uint(self->buffer, PLM_VIDEO_DCT_COEFF);

		if ((coeff == 0x0001) && (n > 0) && (plm_buffer_read(self->buffer, 1) == 0)) {
			// end_of_block
			break;
		}
		if (coeff == 0xffff) {
			// escape
			run = plm_buffer_read(self->buffer, 6);
			level = plm_buffer_read(self->buffer, 8);
			if (level == 0) {
				level = plm_buffer_read(self->buffer, 8);
			}
			else if (level == 128) {
				level = plm_buffer_read(self->buffer, 8) - 256;
			}
			else if (level > 128) {
				level = level - 256;
			}
		}
		else {
			run = coeff >> 8;
			level = coeff & 0xff;
			if (plm_buffer_read(self->buffer, 1)) {
				level = -level;
			}
		}

		n += run;
		if (n < 0 || n >= 64) {
			return; // invalid
		}

		int de_zig_zagged = PLM_VIDEO_ZIG_ZAG[n];
		n++;

		// Dequantize, oddify, clip
		level = (unsigned)level << 1;
		if (!self->macroblock_intra) {
			level += (level < 0 ? -1 : 1);
		}
		level = (level * self->quantizer_scale * quant_matrix[de_zig_zagged]) >> 4;
		if ((level & 1) == 0) {
			level -= level > 0 ? 1 : -1;
		}
		if (level > 2047) {
			level = 2047;
		}
		else if (level < -2048) {
			level = -2048;
		}

		// Save premultiplied coefficient
		self->block_data[de_zig_zagged] = level * PLM_VIDEO_PREMULTIPLIER_MATRIX[de_zig_zagged];
	}

	// Move block to its place
	uint8_t *d;
	int dw;
	int di;

	if (block < 4) {
		d = self->frame_current.y.data;
		dw = self->luma_width;
		di = (self->mb_row * self->luma_width + self->mb_col) << 4;
		if ((block & 1) != 0) {
			di += 8;
		}
		if ((block & 2) != 0) {
			di += self->luma_width << 3;
		}
	}
	else {
		d = (block == 4) ? self->frame_current.cb.data : self->frame_current.cr.data;
		dw = self->chroma_width;
		di = ((self->mb_row * self->luma_width) << 2) + (self->mb_col << 3);
	}

	int *s = self->block_data;
	int si = 0;
	if (self->macroblock_intra) {
		// Overwrite (no prediction)
		if (n == 1) {
			int clamped = plm_clamp((s[0] + 128) >> 8);
			PLM_BLOCK_SET(d, di, dw, si, 8, 8, clamped);
			s[0] = 0;
		}
		else {
			plm_video_idct(s);
			PLM_BLOCK_SET(d, di, dw, si, 8, 8, plm_clamp(s[si]));
			memset(self->block_data, 0, sizeof(self->block_data));
		}
	}
	else {
		// Add data to the predicted macroblock
		if (n == 1) {
			int value = (s[0] + 128) >> 8;
			PLM_BLOCK_SET(d, di, dw, si, 8, 8, plm_clamp(d[di] + value));
			s[0] = 0;
		}
		else {
			plm_video_idct(s);
			PLM_BLOCK_SET(d, di, dw, si, 8, 8, plm_clamp(d[di] + s[si]));
			memset(self->block_data, 0, sizeof(self->block_data));
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl $0x0, -0x10(%rbp)
movq -0x8(%rbp), %rax
cmpl $0x0, 0x8c(%rax)
je 0x6a90
cmpl $0x3, -0xc(%rbp)
jle 0x697e
movl -0xc(%rbp), %eax
subl $0x3, %eax
movl %eax, -0xa0(%rbp)
jmp 0x6988
xorl %eax, %eax
movl %eax, -0xa0(%rbp)
jmp 0x6988
movl -0xa0(%rbp), %eax
movl %eax, -0x24(%rbp)
movq -0x8(%rbp), %rax
movslq -0x24(%rbp), %rcx
movl 0x90(%rax,%rcx,4), %eax
movl %eax, -0x1c(%rbp)
movq -0x8(%rbp), %rax
movq 0xa0(%rax), %rdi
movslq -0x24(%rbp), %rcx
leaq 0xa7c7(%rip), %rax      # 0x11180
movq (%rax,%rcx,8), %rsi
callq 0x5700
cwtl
movl %eax, -0x20(%rbp)
cmpl $0x0, -0x20(%rbp)
jle 0x6a40
movq -0x8(%rbp), %rax
movq 0xa0(%rax), %rdi
movl -0x20(%rbp), %esi
callq 0x5320
movl %eax, -0x28(%rbp)
movl -0x28(%rbp), %eax
movl -0x20(%rbp), %ecx
subl $0x1, %ecx
movl $0x1, %edx
shll %cl, %edx
movl %edx, %ecx
andl %ecx, %eax
cmpl $0x0, %eax
je 0x6a0d
movl -0x1c(%rbp), %ecx
addl -0x28(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x178(%rax)
jmp 0x6a3e
movl -0x1c(%rbp), %eax
movl %eax, -0xa4(%rbp)
movl -0x20(%rbp), %ecx
movl $0x1, %edx
shll %cl, %edx
movl -0xa4(%rbp), %ecx
xorl %eax, %eax
subl %edx, %eax
movl -0x28(%rbp), %edx
addl $0x1, %edx
orl %edx, %eax
addl %eax, %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x178(%rax)
jmp 0x6a4d
movl -0x1c(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x178(%rax)
movq -0x8(%rbp), %rax
movl 0x178(%rax), %edx
movq -0x8(%rbp), %rax
movslq -0x24(%rbp), %rcx
movl %edx, 0x90(%rax,%rcx,4)
movq -0x8(%rbp), %rax
movl 0x178(%rax), %ecx
shll $0x8, %ecx
movl %ecx, 0x178(%rax)
movq -0x8(%rbp), %rax
addq $0x278, %rax            # imm = 0x278
movq %rax, -0x18(%rbp)
movl $0x1, -0x10(%rbp)
jmp 0x6a9e
movq -0x8(%rbp), %rax
addq $0x2b8, %rax            # imm = 0x2B8
movq %rax, -0x18(%rbp)
movl $0x0, -0x2c(%rbp)
movl $0x0, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq 0xa0(%rax), %rdi
leaq 0x6b82(%rip), %rsi      # 0xd640
callq 0x5770
movw %ax, -0x32(%rbp)
movzwl -0x32(%rbp), %eax
cmpl $0x1, %eax
jne 0x6af5
cmpl $0x0, -0x10(%rbp)
jle 0x6af5
movq -0x8(%rbp), %rax
movq 0xa0(%rax), %rdi
movl $0x1, %esi
callq 0x5320
cmpl $0x0, %eax
jne 0x6af5
jmp 0x6cc6
movzwl -0x32(%rbp), %eax
cmpl $0xffff, %eax           # imm = 0xFFFF
jne 0x6b96
movq -0x8(%rbp), %rax
movq 0xa0(%rax), %rdi
movl $0x6, %esi
callq 0x5320
movl %eax, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq 0xa0(%rax), %rdi
movl $0x8, %esi
callq 0x5320
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
jne 0x6b54
movq -0x8(%rbp), %rax
movq 0xa0(%rax), %rdi
movl $0x8, %esi
callq 0x5320
movl %eax, -0x2c(%rbp)
jmp 0x6b94
cmpl $0x80, -0x2c(%rbp)
jne 0x6b7c
movq -0x8(%rbp), %rax
movq 0xa0(%rax), %rdi
movl $0x8, %esi
callq 0x5320
subl $0x100, %eax            # imm = 0x100
movl %eax, -0x2c(%rbp)
jmp 0x6b92
cmpl $0x80, -0x2c(%rbp)
jle 0x6b90
movl -0x2c(%rbp), %eax
subl $0x100, %eax            # imm = 0x100
movl %eax, -0x2c(%rbp)
jmp 0x6b92
jmp 0x6b94
jmp 0x6bd0
movzwl -0x32(%rbp), %eax
sarl $0x8, %eax
movl %eax, -0x30(%rbp)
movzwl -0x32(%rbp), %eax
andl $0xff, %eax
movl %eax, -0x2c(%rbp)
movq -0x8(%rbp), %rax
movq 0xa0(%rax), %rdi
movl $0x1, %esi
callq 0x5320
cmpl $0x0, %eax
je 0x6bce
xorl %eax, %eax
subl -0x2c(%rbp), %eax
movl %eax, -0x2c(%rbp)
jmp 0x6bd0
movl -0x30(%rbp), %eax
addl -0x10(%rbp), %eax
movl %eax, -0x10(%rbp)
cmpl $0x0, -0x10(%rbp)
jl 0x6be5
cmpl $0x40, -0x10(%rbp)
jl 0x6bea
jmp 0x70c9
movslq -0x10(%rbp), %rcx
leaq 0x653b(%rip), %rax      # 0xd130
movzbl (%rax,%rcx), %eax
movl %eax, -0x38(%rbp)
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
movl -0x2c(%rbp), %eax
shll %eax
movl %eax, -0x2c(%rbp)
movq -0x8(%rbp), %rax
cmpl $0x0, 0x8c(%rax)
jne 0x6c33
movl -0x2c(%rbp), %edx
movl $0x1, %eax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmpl $0x0, %edx
cmovll %ecx, %eax
addl -0x2c(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movq -0x8(%rbp), %rcx
imull 0x74(%rcx), %eax
movq -0x18(%rbp), %rcx
movslq -0x38(%rbp), %rdx
movzbl (%rcx,%rdx), %ecx
imull %ecx, %eax
sarl $0x4, %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0x6c79
movl -0x2c(%rbp), %edx
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movl $0x1, %eax
cmpl $0x0, %edx
cmovgl %eax, %ecx
movl -0x2c(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x2c(%rbp)
cmpl $0x7ff, -0x2c(%rbp)     # imm = 0x7FF
jle 0x6c8b
movl $0x7ff, -0x2c(%rbp)     # imm = 0x7FF
jmp 0x6c9d
cmpl $0xfffff800, -0x2c(%rbp) # imm = 0xFFFFF800
jge 0x6c9b
movl $0xfffff800, -0x2c(%rbp) # imm = 0xFFFFF800
jmp 0x6c9d
movl -0x2c(%rbp), %edx
movslq -0x38(%rbp), %rcx
leaq 0x6d15(%rip), %rax      # 0xd9c0
movzbl (%rax,%rcx), %eax
imull %eax, %edx
movq -0x8(%rbp), %rax
movslq -0x38(%rbp), %rcx
movl %edx, 0x178(%rax,%rcx,4)
jmp 0x6aa5
cmpl $0x4, -0xc(%rbp)
jge 0x6d38
movq -0x8(%rbp), %rax
movq 0xc8(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rax
movl 0x30(%rax), %eax
movl %eax, -0x44(%rbp)
movq -0x8(%rbp), %rax
movl 0x80(%rax), %eax
movq -0x8(%rbp), %rcx
imull 0x30(%rcx), %eax
movq -0x8(%rbp), %rcx
addl 0x84(%rcx), %eax
shll $0x4, %eax
movl %eax, -0x48(%rbp)
movl -0xc(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x6d1b
movl -0x48(%rbp), %eax
addl $0x8, %eax
movl %eax, -0x48(%rbp)
movl -0xc(%rbp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x6d36
movq -0x8(%rbp), %rax
movl 0x30(%rax), %eax
shll $0x3, %eax
addl -0x48(%rbp), %eax
movl %eax, -0x48(%rbp)
jmp 0x6da0
cmpl $0x4, -0xc(%rbp)
jne 0x6d52
movq -0x8(%rbp), %rax
movq 0xe8(%rax), %rax
movq %rax, -0xb0(%rbp)
jmp 0x6d64
movq -0x8(%rbp), %rax
movq 0xd8(%rax), %rax
movq %rax, -0xb0(%rbp)
movq -0xb0(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rax
movl 0x38(%rax), %eax
movl %eax, -0x44(%rbp)
movq -0x8(%rbp), %rax
movl 0x80(%rax), %eax
movq -0x8(%rbp), %rcx
imull 0x30(%rcx), %eax
shll $0x2, %eax
movq -0x8(%rbp), %rcx
movl 0x84(%rcx), %ecx
shll $0x3, %ecx
addl %ecx, %eax
movl %eax, -0x48(%rbp)
movq -0x8(%rbp), %rax
addq $0x178, %rax            # imm = 0x178
movq %rax, -0x50(%rbp)
movl $0x0, -0x54(%rbp)
movq -0x8(%rbp), %rax
cmpl $0x0, 0x8c(%rax)
je 0x6f17
cmpl $0x1, -0x10(%rbp)
jne 0x6e6f
movq -0x50(%rbp), %rax
movl (%rax), %edi
addl $0x80, %edi
sarl $0x8, %edi
callq 0x7b20
movzbl %al, %eax
movl %eax, -0x58(%rbp)
movl -0x44(%rbp), %eax
subl $0x8, %eax
movl %eax, -0x5c(%rbp)
movl $0x0, -0x60(%rbp)
movl $0x0, -0x64(%rbp)
cmpl $0x8, -0x64(%rbp)
jge 0x6e5e
movl $0x0, -0x68(%rbp)
cmpl $0x8, -0x68(%rbp)
jge 0x6e41
movl -0x58(%rbp), %eax
movb %al, %dl
movq -0x40(%rbp), %rax
movslq -0x48(%rbp), %rcx
movb %dl, (%rax,%rcx)
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
movl -0x68(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x68(%rbp)
jmp 0x6e0e
movl -0x60(%rbp), %eax
addl -0x54(%rbp), %eax
movl %eax, -0x54(%rbp)
movl -0x5c(%rbp), %eax
addl -0x48(%rbp), %eax
movl %eax, -0x48(%rbp)
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0x6e01
jmp 0x6e60
movq -0x50(%rbp), %rax
movl $0x0, (%rax)
jmp 0x6f12
movq -0x50(%rbp), %rdi
callq 0x7b50
movl -0x44(%rbp), %eax
subl $0x8, %eax
movl %eax, -0x6c(%rbp)
movl $0x0, -0x70(%rbp)
movl $0x0, -0x74(%rbp)
cmpl $0x8, -0x74(%rbp)
jge 0x6ef9
movl $0x0, -0x78(%rbp)
cmpl $0x8, -0x78(%rbp)
jge 0x6edc
movq -0x50(%rbp), %rax
movslq -0x54(%rbp), %rcx
movl (%rax,%rcx,4), %edi
callq 0x7b20
movb %al, %dl
movq -0x40(%rbp), %rax
movslq -0x48(%rbp), %rcx
movb %dl, (%rax,%rcx)
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
movl -0x78(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x78(%rbp)
jmp 0x6e9c
movl -0x70(%rbp), %eax
addl -0x54(%rbp), %eax
movl %eax, -0x54(%rbp)
movl -0x6c(%rbp), %eax
addl -0x48(%rbp), %eax
movl %eax, -0x48(%rbp)
movl -0x74(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x74(%rbp)
jmp 0x6e8f
jmp 0x6efb
movq -0x8(%rbp), %rdi
addq $0x178, %rdi            # imm = 0x178
xorl %esi, %esi
movl $0x100, %edx            # imm = 0x100
callq 0x20e0
jmp 0x70c9
cmpl $0x1, -0x10(%rbp)
jne 0x6fed
movq -0x50(%rbp), %rax
movl (%rax), %eax
addl $0x80, %eax
sarl $0x8, %eax
movl %eax, -0x7c(%rbp)
movl -0x44(%rbp), %eax
subl $0x8, %eax
movl %eax, -0x80(%rbp)
movl $0x0, -0x84(%rbp)
movl $0x0, -0x88(%rbp)
cmpl $0x8, -0x88(%rbp)
jge 0x6fdc
movl $0x0, -0x8c(%rbp)
cmpl $0x8, -0x8c(%rbp)
jge 0x6fb3
movq -0x40(%rbp), %rax
movslq -0x48(%rbp), %rcx
movzbl (%rax,%rcx), %edi
addl -0x7c(%rbp), %edi
callq 0x7b20
movb %al, %dl
movq -0x40(%rbp), %rax
movslq -0x48(%rbp), %rcx
movb %dl, (%rax,%rcx)
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
movl -0x8c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8c(%rbp)
jmp 0x6f66
movl -0x84(%rbp), %eax
addl -0x54(%rbp), %eax
movl %eax, -0x54(%rbp)
movl -0x80(%rbp), %eax
addl -0x48(%rbp), %eax
movl %eax, -0x48(%rbp)
movl -0x88(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x88(%rbp)
jmp 0x6f4f
jmp 0x6fde
movq -0x50(%rbp), %rax
movl $0x0, (%rax)
jmp 0x70c7
movq -0x50(%rbp), %rdi
callq 0x7b50
movl -0x44(%rbp), %eax
subl $0x8, %eax
movl %eax, -0x90(%rbp)
movl $0x0, -0x94(%rbp)
movl $0x0, -0x98(%rbp)
cmpl $0x8, -0x98(%rbp)
jge 0x70ae
movl $0x0, -0x9c(%rbp)
cmpl $0x8, -0x9c(%rbp)
jge 0x7082
movq -0x40(%rbp), %rax
movslq -0x48(%rbp), %rcx
movzbl (%rax,%rcx), %edi
movq -0x50(%rbp), %rax
movslq -0x54(%rbp), %rcx
addl (%rax,%rcx,4), %edi
callq 0x7b20
movb %al, %dl
movq -0x40(%rbp), %rax
movslq -0x48(%rbp), %rcx
movb %dl, (%rax,%rcx)
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
movl -0x9c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x9c(%rbp)
jmp 0x702d
movl -0x94(%rbp), %eax
addl -0x54(%rbp), %eax
movl %eax, -0x54(%rbp)
movl -0x90(%rbp), %eax
addl -0x48(%rbp), %eax
movl %eax, -0x48(%rbp)
movl -0x98(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x98(%rbp)
jmp 0x7016
jmp 0x70b0
movq -0x8(%rbp), %rdi
addq $0x178, %rdi            # imm = 0x178
xorl %esi, %esi
movl $0x100, %edx            # imm = 0x100
callq 0x20e0
jmp 0x70c9
addq $0xb0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)