// File: rpavlik[P]edid-decode/parse-cta-block.cpp
// Function: edid_state::cta_y420cmdb(unsigned char const*, unsigned int)
void edid_state::cta_y420cmdb(const unsigned char *x, unsigned length)
{
	unsigned max_idx = 0;
	unsigned i;

	if (!length) {
		printf("    All VDB SVDs\n");
		return;
	}

	if (memchk(x, length)) {
		printf("    Empty Capability Map\n");
		fail("Empty Capability Map.\n");
		return;
	}

	for (i = 0; i < length; i++) {
		unsigned char v = x[i];
		unsigned j;

		for (j = 0; j < 8; j++) {
			if (!(v & (1 << j)))
				continue;

			print_vic_index("    ", i * 8 + j, "", true);
			max_idx = i * 8 + j;
			if (max_idx < cta.preparsed_svds[0].size()) {
				unsigned vic = cta.preparsed_svds[0][max_idx];
				if (cta.preparsed_has_vic[1][vic])
					fail("VIC %u is also a YCbCr 4:2:0-only VIC.\n", vic);
			}
		}
	}
	if (max_idx >= cta.preparsed_svds[0].size())
		fail("Max index %u > %u (#SVDs).\n",
		     max_idx + 1, cta.preparsed_svds[0].size());
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x30(%rbp)
movl $0x0, -0x18(%rbp)
cmpl $0x0, -0x14(%rbp)
jne 0x1630b
leaq 0x23229(%rip), %rdi     # 0x39528
movb $0x0, %al
callq 0x4050
jmp 0x164b6
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
xorl %edx, %edx
callq 0x7810
testb $0x1, %al
jne 0x1631f
jmp 0x16342
leaq 0x23214(%rip), %rdi     # 0x3953a
movb $0x0, %al
callq 0x4050
xorl %edi, %edi
leaq 0x2321e(%rip), %rsi     # 0x39554
movb $0x0, %al
callq 0x47d0
jmp 0x164b6
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x14(%rbp), %eax
jae 0x16456
movq -0x10(%rbp), %rax
movl -0x1c(%rbp), %ecx
movb (%rax,%rcx), %al
movb %al, -0x1d(%rbp)
movl $0x0, -0x24(%rbp)
cmpl $0x8, -0x24(%rbp)
jae 0x16446
movzbl -0x1d(%rbp), %eax
movl -0x24(%rbp), %ecx
movl $0x1, %edx
shll %cl, %edx
movl %edx, %ecx
andl %ecx, %eax
cmpl $0x0, %eax
jne 0x1638f
jmp 0x16438
movq -0x30(%rbp), %rdi
movl -0x1c(%rbp), %edx
shll $0x3, %edx
addl -0x24(%rbp), %edx
leaq 0x1e43c(%rip), %rsi     # 0x347df
leaq 0x19b0f(%rip), %rcx     # 0x2feb9
movl $0x1, %r8d
callq 0x16140
movq -0x30(%rbp), %rdi
movl -0x1c(%rbp), %eax
shll $0x3, %eax
addl -0x24(%rbp), %eax
movl %eax, -0x18(%rbp)
movl -0x18(%rbp), %eax
movq %rax, -0x38(%rbp)
addq $0x180, %rdi            # imm = 0x180
addq $0x760, %rdi            # imm = 0x760
callq 0x1ffc0
movq %rax, %rcx
movq -0x38(%rbp), %rax
cmpq %rcx, %rax
jae 0x16436
movq -0x30(%rbp), %rdi
addq $0x180, %rdi            # imm = 0x180
addq $0x760, %rdi            # imm = 0x760
movl -0x18(%rbp), %eax
movl %eax, %esi
callq 0x1ffe0
movq %rax, %rcx
movq -0x30(%rbp), %rax
movzbl (%rcx), %ecx
movl %ecx, -0x28(%rbp)
movl -0x28(%rbp), %ecx
testb $0x1, 0x7e0(%rax,%rcx)
je 0x16434
movl -0x28(%rbp), %edx
xorl %edi, %edi
leaq 0x2313e(%rip), %rsi     # 0x3956b
movb $0x0, %al
callq 0x47d0
jmp 0x16436
jmp 0x16438
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x16369
jmp 0x16448
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x16349
movq -0x30(%rbp), %rdi
movl -0x18(%rbp), %eax
movq %rax, -0x40(%rbp)
addq $0x180, %rdi            # imm = 0x180
addq $0x760, %rdi            # imm = 0x760
callq 0x1ffc0
movq %rax, %rcx
movq -0x40(%rbp), %rax
cmpq %rcx, %rax
jb 0x164b6
movq -0x30(%rbp), %rdi
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
addq $0x180, %rdi            # imm = 0x180
addq $0x760, %rdi            # imm = 0x760
callq 0x1ffc0
movl -0x44(%rbp), %edx
movq %rax, %rcx
xorl %edi, %edi
leaq 0x230e4(%rip), %rsi     # 0x39593
movb $0x0, %al
callq 0x47d0
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)