// File: rpavlik[P]edid-decode/parse-cta-block.cpp
// Function: cta_hf_scdb(unsigned char const*, unsigned int)
static void cta_hf_scdb(const unsigned char *x, unsigned length)
{
	unsigned rate = x[1] * 5;

	printf("    Version: %u\n", x[0]);
	if (rate) {
		printf("    Maximum TMDS Character Rate: %u MHz\n", rate);
		if (rate <= 340 || rate > 600)
			fail("Max TMDS rate is > 0 and <= 340 or > 600.\n");
	}
	if (x[2] & 0x80)
		printf("    SCDC Present\n");
	if (x[2] & 0x40)
		printf("    SCDC Read Request Capable\n");
	if (x[2] & 0x10)
		printf("    Supports Color Content Bits Per Component Indication\n");
	if (x[2] & 0x08)
		printf("    Supports scrambling for <= 340 Mcsc\n");
	if (x[2] & 0x04)
		printf("    Supports 3D Independent View signaling\n");
	if (x[2] & 0x02)
		printf("    Supports 3D Dual View signaling\n");
	if (x[2] & 0x01)
		printf("    Supports 3D OSD Disparity signaling\n");
	if (x[3] & 0xf0) {
		unsigned max_frl_rate = x[3] >> 4;

		printf("    Max Fixed Rate Link: ");
		if (max_frl_rate < ARRAY_SIZE(max_frl_rates)) {
			printf("%s\n", max_frl_rates[max_frl_rate]);
		} else {
			printf("Unknown (0x%02x)\n", max_frl_rate);
			fail("Unknown Max Fixed Rate Link (0x%02x).\n", max_frl_rate);
		}
		if (max_frl_rate == 1 && rate < 300)
			fail("Max Fixed Rate Link is 1, but Max TMDS rate < 300.\n");
		else if (max_frl_rate >= 2 && rate < 600)
			fail("Max Fixed Rate Link is >= 2, but Max TMDS rate < 600.\n");
	}
	if (x[3] & 0x08)
		printf("    Supports UHD VIC\n");
	if (x[3] & 0x04)
		printf("    Supports 16-bits/component Deep Color 4:2:0 Pixel Encoding\n");
	if (x[3] & 0x02)
		printf("    Supports 12-bits/component Deep Color 4:2:0 Pixel Encoding\n");
	if (x[3] & 0x01)
		printf("    Supports 10-bits/component Deep Color 4:2:0 Pixel Encoding\n");

	if (length <= 4)
		return;

	if (x[4] & 0x20)
		printf("    Supports Mdelta\n");
	if (x[4] & 0x10)
		printf("    Supports media rates below VRRmin (CinemaVRR)\n");
	if (x[4] & 0x08)
		printf("    Supports negative Mvrr values\n");
	if (x[4] & 0x04)
		printf("    Supports Fast Vactive\n");
	if (x[4] & 0x02)
		printf("    Supports Auto Low-Latency Mode\n");
	if (x[4] & 0x01)
		printf("    Supports a FAPA in blanking after first active video line\n");

	if (length <= 5)
		return;

	printf("    VRRmin: %d Hz\n", x[5] & 0x3f);
	printf("    VRRmax: %d Hz\n", (x[5] & 0xc0) << 2 | x[6]);

	if (length <= 7)
		return;

	if (x[7] & 0x80)
		printf("    Supports VESA DSC 1.2a compression\n");
	if (x[7] & 0x40)
		printf("    Supports Compressed Video Transport for 4:2:0 Pixel Encoding\n");
	if (x[7] & 0x08)
		printf("    Supports Compressed Video Transport at any valid 1/16th bit bpp\n");
	if (x[7] & 0x04)
		printf("    Supports 16 bpc Compressed Video Transport\n");
	if (x[7] & 0x02)
		printf("    Supports 12 bpc Compressed Video Transport\n");
	if (x[7] & 0x01)
		printf("    Supports 10 bpc Compressed Video Transport\n");
	if (x[8] & 0xf) {
		unsigned max_slices = x[8] & 0xf;

		printf("    DSC Max Slices: ");
		if (max_slices < ARRAY_SIZE(dsc_max_slices)) {
			printf("%s\n", dsc_max_slices[max_slices]);
		} else {
			printf("Unknown (0x%02x)\n", max_slices);
			fail("Unknown DSC Max Slices (0x%02x).\n", max_slices);
		}
	}
	if (x[8] & 0xf0) {
		unsigned max_frl_rate = x[8] >> 4;

		printf("    DSC Max Fixed Rate Link: ");
		if (max_frl_rate < ARRAY_SIZE(max_frl_rates)) {
			printf("%s\n", max_frl_rates[max_frl_rate]);
		} else {
			printf("Unknown (0x%02x)\n", max_frl_rate);
			fail("Unknown DSC Max Fixed Rate Link (0x%02x).\n", max_frl_rate);
		}
	}
	if (x[9] & 0x3f)
		printf("    Maximum number of bytes in a line of chunks: %u\n",
		       1024 * (1 + (x[9] & 0x3f)));
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq -0x8(%rbp), %rax
movzbl 0x1(%rax), %eax
imull $0x5, %eax, %eax
movl %eax, -0x10(%rbp)
movq -0x8(%rbp), %rax
movzbl (%rax), %esi
leaq 0x208d6(%rip), %rdi     # 0x3c5b1
movb $0x0, %al
callq 0x4050
cmpl $0x0, -0x10(%rbp)
je 0x1bd1d
movl -0x10(%rbp), %esi
leaq 0x20d19(%rip), %rdi     # 0x3ca0b
movb $0x0, %al
callq 0x4050
cmpl $0x154, -0x10(%rbp)     # imm = 0x154
jbe 0x1bd0b
cmpl $0x258, -0x10(%rbp)     # imm = 0x258
jbe 0x1bd1b
xorl %edi, %edi
leaq 0x20d20(%rip), %rsi     # 0x3ca34
movb $0x0, %al
callq 0x47d0
jmp 0x1bd1d
movq -0x8(%rbp), %rax
movzbl 0x2(%rax), %eax
andl $0x80, %eax
cmpl $0x0, %eax
je 0x1bd3d
leaq 0x20d29(%rip), %rdi     # 0x3ca5f
movb $0x0, %al
callq 0x4050
movq -0x8(%rbp), %rax
movzbl 0x2(%rax), %eax
andl $0x40, %eax
cmpl $0x0, %eax
je 0x1bd5b
leaq 0x20d1d(%rip), %rdi     # 0x3ca71
movb $0x0, %al
callq 0x4050
movq -0x8(%rbp), %rax
movzbl 0x2(%rax), %eax
andl $0x10, %eax
cmpl $0x0, %eax
je 0x1bd79
leaq 0x20d1e(%rip), %rdi     # 0x3ca90
movb $0x0, %al
callq 0x4050
movq -0x8(%rbp), %rax
movzbl 0x2(%rax), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0x1bd97
leaq 0x20d3a(%rip), %rdi     # 0x3caca
movb $0x0, %al
callq 0x4050
movq -0x8(%rbp), %rax
movzbl 0x2(%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x1bdb5
leaq 0x20d45(%rip), %rdi     # 0x3caf3
movb $0x0, %al
callq 0x4050
movq -0x8(%rbp), %rax
movzbl 0x2(%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x1bdd3
leaq 0x20d53(%rip), %rdi     # 0x3cb1f
movb $0x0, %al
callq 0x4050
movq -0x8(%rbp), %rax
movzbl 0x2(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x1bdf1
leaq 0x20d5a(%rip), %rdi     # 0x3cb44
movb $0x0, %al
callq 0x4050
movq -0x8(%rbp), %rax
movzbl 0x3(%rax), %eax
andl $0xf0, %eax
cmpl $0x0, %eax
je 0x1beb4
movq -0x8(%rbp), %rax
movzbl 0x3(%rax), %eax
sarl $0x4, %eax
movl %eax, -0x14(%rbp)
leaq 0x20d51(%rip), %rdi     # 0x3cb6d
movb $0x0, %al
callq 0x4050
movl -0x14(%rbp), %eax
cmpq $0x7, %rax
jae 0x1be4c
movl -0x14(%rbp), %eax
movl %eax, %ecx
leaq 0x2fa58(%rip), %rax     # 0x4b890
movq (%rax,%rcx,8), %rsi
leaq 0x1e0d8(%rip), %rdi     # 0x39f1b
movb $0x0, %al
callq 0x4050
jmp 0x1be70
movl -0x14(%rbp), %esi
leaq 0x183e2(%rip), %rdi     # 0x34238
movb $0x0, %al
callq 0x4050
movl -0x14(%rbp), %edx
xorl %edi, %edi
leaq 0x20d1e(%rip), %rsi     # 0x3cb87
movb $0x0, %al
callq 0x47d0
cmpl $0x1, -0x14(%rbp)
jne 0x1be91
cmpl $0x12c, -0x10(%rbp)     # imm = 0x12C
jae 0x1be91
xorl %edi, %edi
leaq 0x20d26(%rip), %rsi     # 0x3cbae
movb $0x0, %al
callq 0x47d0
jmp 0x1beb2
cmpl $0x2, -0x14(%rbp)
jb 0x1beb0
cmpl $0x258, -0x10(%rbp)     # imm = 0x258
jae 0x1beb0
xorl %edi, %edi
leaq 0x20d39(%rip), %rsi     # 0x3cbe2
movb $0x0, %al
callq 0x47d0
jmp 0x1beb2
jmp 0x1beb4
movq -0x8(%rbp), %rax
movzbl 0x3(%rax), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0x1bed2
leaq 0x20d4e(%rip), %rdi     # 0x3cc19
movb $0x0, %al
callq 0x4050
movq -0x8(%rbp), %rax
movzbl 0x3(%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x1bef0
leaq 0x20d46(%rip), %rdi     # 0x3cc2f
movb $0x0, %al
callq 0x4050
movq -0x8(%rbp), %rax
movzbl 0x3(%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x1bf0e
leaq 0x20d68(%rip), %rdi     # 0x3cc6f
movb $0x0, %al
callq 0x4050
movq -0x8(%rbp), %rax
movzbl 0x3(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x1bf2c
leaq 0x20d8a(%rip), %rdi     # 0x3ccaf
movb $0x0, %al
callq 0x4050
cmpl $0x4, -0xc(%rbp)
ja 0x1bf37
jmp 0x1c220
movq -0x8(%rbp), %rax
movzbl 0x4(%rax), %eax
andl $0x20, %eax
cmpl $0x0, %eax
je 0x1bf55
leaq 0x20da1(%rip), %rdi     # 0x3ccef
movb $0x0, %al
callq 0x4050
movq -0x8(%rbp), %rax
movzbl 0x4(%rax), %eax
andl $0x10, %eax
cmpl $0x0, %eax
je 0x1bf73
leaq 0x20d98(%rip), %rdi     # 0x3cd04
movb $0x0, %al
callq 0x4050
movq -0x8(%rbp), %rax
movzbl 0x4(%rax), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0x1bf91
leaq 0x20dad(%rip), %rdi     # 0x3cd37
movb $0x0, %al
callq 0x4050
movq -0x8(%rbp), %rax
movzbl 0x4(%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x1bfaf
leaq 0x20db2(%rip), %rdi     # 0x3cd5a
movb $0x0, %al
callq 0x4050
movq -0x8(%rbp), %rax
movzbl 0x4(%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x1bfcd
leaq 0x20daf(%rip), %rdi     # 0x3cd75
movb $0x0, %al
callq 0x4050
movq -0x8(%rbp), %rax
movzbl 0x4(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x1bfeb
leaq 0x20db5(%rip), %rdi     # 0x3cd99
movb $0x0, %al
callq 0x4050
cmpl $0x5, -0xc(%rbp)
ja 0x1bff6
jmp 0x1c220
movq -0x8(%rbp), %rax
movzbl 0x5(%rax), %esi
andl $0x3f, %esi
leaq 0x20dd0(%rip), %rdi     # 0x3cdd8
movb $0x0, %al
callq 0x4050
movq -0x8(%rbp), %rax
movzbl 0x5(%rax), %esi
andl $0xc0, %esi
shll $0x2, %esi
movq -0x8(%rbp), %rax
movzbl 0x6(%rax), %eax
orl %eax, %esi
leaq 0x20dba(%rip), %rdi     # 0x3cdeb
movb $0x0, %al
callq 0x4050
cmpl $0x7, -0xc(%rbp)
ja 0x1c043
jmp 0x1c220
movq -0x8(%rbp), %rax
movzbl 0x7(%rax), %eax
andl $0x80, %eax
cmpl $0x0, %eax
je 0x1c063
leaq 0x20da2(%rip), %rdi     # 0x3cdfe
movb $0x0, %al
callq 0x4050
movq -0x8(%rbp), %rax
movzbl 0x7(%rax), %eax
andl $0x40, %eax
cmpl $0x0, %eax
je 0x1c081
leaq 0x20dac(%rip), %rdi     # 0x3ce26
movb $0x0, %al
callq 0x4050
movq -0x8(%rbp), %rax
movzbl 0x7(%rax), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0x1c09f
leaq 0x20dd0(%rip), %rdi     # 0x3ce68
movb $0x0, %al
callq 0x4050
movq -0x8(%rbp), %rax
movzbl 0x7(%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x1c0bd
leaq 0x20df7(%rip), %rdi     # 0x3cead
movb $0x0, %al
callq 0x4050
movq -0x8(%rbp), %rax
movzbl 0x7(%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x1c0db
leaq 0x20e09(%rip), %rdi     # 0x3cedd
movb $0x0, %al
callq 0x4050
movq -0x8(%rbp), %rax
movzbl 0x7(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x1c0f9
leaq 0x20e1b(%rip), %rdi     # 0x3cf0d
movb $0x0, %al
callq 0x4050
movq -0x8(%rbp), %rax
movzbl 0x8(%rax), %eax
andl $0xf, %eax
cmpl $0x0, %eax
je 0x1c174
movq -0x8(%rbp), %rax
movzbl 0x8(%rax), %eax
andl $0xf, %eax
movl %eax, -0x18(%rbp)
leaq 0x20e1f(%rip), %rdi     # 0x3cf3d
movb $0x0, %al
callq 0x4050
movl -0x18(%rbp), %eax
cmpq $0x8, %rax
jae 0x1c14e
movl -0x18(%rbp), %eax
movl %eax, %ecx
leaq 0x2f796(%rip), %rax     # 0x4b8d0
movq (%rax,%rcx,8), %rsi
leaq 0x1ddd6(%rip), %rdi     # 0x39f1b
movb $0x0, %al
callq 0x4050
jmp 0x1c172
movl -0x18(%rbp), %esi
leaq 0x180e0(%rip), %rdi     # 0x34238
movb $0x0, %al
callq 0x4050
movl -0x18(%rbp), %edx
xorl %edi, %edi
leaq 0x20de7(%rip), %rsi     # 0x3cf52
movb $0x0, %al
callq 0x47d0
jmp 0x1c174
movq -0x8(%rbp), %rax
movzbl 0x8(%rax), %eax
andl $0xf0, %eax
cmpl $0x0, %eax
je 0x1c1f1
movq -0x8(%rbp), %rax
movzbl 0x8(%rax), %eax
sarl $0x4, %eax
movl %eax, -0x1c(%rbp)
leaq 0x20dd9(%rip), %rdi     # 0x3cf74
movb $0x0, %al
callq 0x4050
movl -0x1c(%rbp), %eax
cmpq $0x7, %rax
jae 0x1c1cb
movl -0x1c(%rbp), %eax
movl %eax, %ecx
leaq 0x2f6d9(%rip), %rax     # 0x4b890
movq (%rax,%rcx,8), %rsi
leaq 0x1dd59(%rip), %rdi     # 0x39f1b
movb $0x0, %al
callq 0x4050
jmp 0x1c1ef
movl -0x1c(%rbp), %esi
leaq 0x18063(%rip), %rdi     # 0x34238
movb $0x0, %al
callq 0x4050
movl -0x1c(%rbp), %edx
xorl %edi, %edi
leaq 0x20daa(%rip), %rsi     # 0x3cf92
movb $0x0, %al
callq 0x47d0
jmp 0x1c1f1
movq -0x8(%rbp), %rax
movzbl 0x9(%rax), %eax
andl $0x3f, %eax
cmpl $0x0, %eax
je 0x1c220
movq -0x8(%rbp), %rax
movzbl 0x9(%rax), %esi
andl $0x3f, %esi
addl $0x1, %esi
shll $0xa, %esi
leaq 0x20da4(%rip), %rdi     # 0x3cfbd
movb $0x0, %al
callq 0x4050
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)