// File: rpavlik[P]edid-decode/parse-cta-block.cpp
// Function: edid_state::cta_svd(unsigned char const*, unsigned int, bool)
void edid_state::cta_svd(const unsigned char *x, unsigned n, bool for_ycbcr420)
{
	unsigned i;

	for (i = 0; i < n; i++)  {
		const struct timings *t = NULL;
		unsigned char svd = x[i];
		unsigned char native;
		unsigned char vic;

		if ((svd & 0x7f) == 0)
			continue;

		if ((svd - 1) & 0x40) {
			vic = svd;
			native = 0;
		} else {
			vic = svd & 0x7f;
			native = svd & 0x80;
		}

		t = find_vic_id(vic);
		if (t) {
			switch (vic) {
			case 95:
				cta.supported_hdmi_vic_vsb_codes |= 1 << 0;
				break;
			case 94:
				cta.supported_hdmi_vic_vsb_codes |= 1 << 1;
				break;
			case 93:
				cta.supported_hdmi_vic_vsb_codes |= 1 << 2;
				break;
			case 98:
				cta.supported_hdmi_vic_vsb_codes |= 1 << 3;
				break;
			}
			bool first_svd = cta.first_svd && !for_ycbcr420;
			bool override_pref = first_svd && cta.first_svd_might_be_preferred;

			char type[16];
			sprintf(type, "VIC %3u", vic);
			const char *flags = native ? "native" : "";

			if (for_ycbcr420) {
				struct timings tmp = *t;
				tmp.ycbcr420 = true;
				print_timings("    ", &tmp, type, flags);
			} else {
				print_timings("    ", t, type, flags);
			}
			if (override_pref) {
				if (!cta.preferred_timings.empty()) {
					if (match_timings(cta.preferred_timings[0].t, *t))
						warn("For improved preferred timing interoperability, set 'Native detailed modes' to 1.\n");
					else
						warn("VIC %u is the preferred timing, overriding the first detailed timings. Is this intended?\n", vic);
				}
				cta.preferred_timings.insert(cta.preferred_timings.begin(),
							     timings_ext(*t, type, flags));
			} else if (first_svd) {
				cta.preferred_timings.push_back(timings_ext(*t, type, flags));
			}
			if (first_svd) {
				cta.first_svd = false;
				cta.first_svd_might_be_preferred = false;
			}
			if (native)
				cta.native_timings.push_back(timings_ext(*t, type, flags));
		} else {
			printf("    Unknown (VIC %3u)\n", vic);
			fail("Unknown VIC %u.\n", vic);
		}

		if (vic == 1 && !for_ycbcr420)
			cta.has_vic_1 = 1;
		if (++cta.vics[vic][for_ycbcr420] == 2)
			fail("Duplicate %sVIC %u.\n", for_ycbcr420 ? "YCbCr 4:2:0 " : "", vic);
		if (for_ycbcr420 && cta.preparsed_has_vic[0][vic])
			fail("YCbCr 4:2:0-only VIC %u is also a regular VIC.\n", vic);
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x420, %rsp            # imm = 0x420
movb %cl, %al
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
andb $0x1, %al
movb %al, -0x15(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x388(%rbp)
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x14(%rbp), %eax
jae 0x1611f
movq $0x0, -0x28(%rbp)
movq -0x10(%rbp), %rax
movl -0x1c(%rbp), %ecx
movb (%rax,%rcx), %al
movb %al, -0x29(%rbp)
movzbl -0x29(%rbp), %eax
andl $0x7f, %eax
cmpl $0x0, %eax
jne 0x158c1
jmp 0x16111
movzbl -0x29(%rbp), %eax
subl $0x1, %eax
andl $0x40, %eax
cmpl $0x0, %eax
je 0x158dc
movb -0x29(%rbp), %al
movb %al, -0x2b(%rbp)
movb $0x0, -0x2a(%rbp)
jmp 0x158f2
movzbl -0x29(%rbp), %eax
andl $0x7f, %eax
movb %al, -0x2b(%rbp)
movzbl -0x29(%rbp), %eax
andl $0x80, %eax
movb %al, -0x2a(%rbp)
movzbl -0x2b(%rbp), %edi
callq 0x154d0
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x16033
movzbl -0x2b(%rbp), %eax
addl $-0x5d, %eax
movl %eax, %ecx
movq %rcx, -0x390(%rbp)
subl $0x5, %eax
ja 0x15994
movq -0x390(%rbp), %rax
leaq 0x200a3(%rip), %rcx     # 0x359d0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x388(%rbp), %rax
movl 0x2dc(%rax), %ecx
orl $0x1, %ecx
movl %ecx, 0x2dc(%rax)
jmp 0x15994
movq -0x388(%rbp), %rax
movl 0x2dc(%rax), %ecx
orl $0x2, %ecx
movl %ecx, 0x2dc(%rax)
jmp 0x15994
movq -0x388(%rbp), %rax
movl 0x2dc(%rax), %ecx
orl $0x4, %ecx
movl %ecx, 0x2dc(%rax)
jmp 0x15994
movq -0x388(%rbp), %rax
movl 0x2dc(%rax), %ecx
orl $0x8, %ecx
movl %ecx, 0x2dc(%rax)
movq -0x388(%rbp), %rcx
xorl %eax, %eax
testb $0x1, 0x2d6(%rcx)
movb %al, -0x391(%rbp)
je 0x159b7
movb -0x15(%rbp), %al
xorb $-0x1, %al
movb %al, -0x391(%rbp)
movb -0x391(%rbp), %al
andb $0x1, %al
movb %al, -0x2c(%rbp)
xorl %eax, %eax
testb $0x1, -0x2c(%rbp)
movb %al, -0x392(%rbp)
je 0x159e3
movq -0x388(%rbp), %rax
movb 0x2c1(%rax), %al
movb %al, -0x392(%rbp)
movb -0x392(%rbp), %al
andb $0x1, %al
movb %al, -0x2d(%rbp)
leaq -0x40(%rbp), %rdi
movzbl -0x2b(%rbp), %edx
leaq 0x1a0e1(%rip), %rsi     # 0x2fade
movb $0x0, %al
callq 0x40a0
movb -0x2a(%rbp), %dl
leaq 0x1a4ab(%rip), %rax     # 0x2feb9
leaq 0x2420a(%rip), %rcx     # 0x39c1f
cmpb $0x0, %dl
cmovneq %rcx, %rax
movq %rax, -0x48(%rbp)
testb $0x1, -0x15(%rbp)
je 0x15a6d
movq -0x28(%rbp), %rsi
leaq -0x9c(%rbp), %rdi
movl $0x54, %edx
callq 0x42a0
movq -0x388(%rbp), %rdi
movb $0x1, -0x4c(%rbp)
leaq -0x40(%rbp), %rcx
movq -0x48(%rbp), %r8
leaq 0x1ed8a(%rip), %rsi     # 0x347df
leaq -0x9c(%rbp), %rdx
xorl %r9d, %r9d
movl $0x1, (%rsp)
callq 0x50c0
jmp 0x15a96
movq -0x388(%rbp), %rdi
movq -0x28(%rbp), %rdx
leaq -0x40(%rbp), %rcx
movq -0x48(%rbp), %r8
leaq 0x1ed58(%rip), %rsi     # 0x347df
xorl %r9d, %r9d
movl $0x1, (%rsp)
callq 0x50c0
testb $0x1, -0x2d(%rbp)
je 0x15ce6
movq -0x388(%rbp), %rdi
addq $0x180, %rdi            # imm = 0x180
addq $0x40, %rdi
callq 0xb930
testb $0x1, %al
jne 0x15b1d
movq -0x388(%rbp), %rdi
addq $0x180, %rdi            # imm = 0x180
addq $0x40, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x1fef0
movq -0x388(%rbp), %rdi
movq %rax, %rsi
movq -0x28(%rbp), %rdx
callq 0x4db0
testb $0x1, %al
jne 0x15aef
jmp 0x15b04
movl $0x1, %edi
leaq 0x238cd(%rip), %rsi     # 0x393c8
movb $0x0, %al
callq 0x47d0
jmp 0x15b1b
movzbl -0x2b(%rbp), %edx
movl $0x1, %edi
leaq 0x23907(%rip), %rsi     # 0x3941b
movb $0x0, %al
callq 0x47d0
jmp 0x15b1d
movq -0x388(%rbp), %rdi
addq $0x1c0, %rdi            # imm = 0x1C0
movq %rdi, -0x3b0(%rbp)
callq 0xb9a0
movq %rax, -0xb0(%rbp)
leaq -0xa8(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x1ff50
movq -0x28(%rbp), %rax
movq %rax, -0x3a8(%rbp)
leaq -0x169(%rbp), %rdi
movq %rdi, -0x3a0(%rbp)
callq 0x4560
movq -0x3a0(%rbp), %rdx
leaq -0x168(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0xb510
jmp 0x15b88
movq -0x48(%rbp), %rax
movq %rax, -0x3c0(%rbp)
leaq -0x1a1(%rbp), %rdi
movq %rdi, -0x3b8(%rbp)
callq 0x4560
movq -0x3c0(%rbp), %rsi
movq -0x3b8(%rbp), %rdx
leaq -0x1a0(%rbp), %rdi
callq 0xb510
jmp 0x15bc2
movq -0x3a8(%rbp), %rsi
leaq -0x148(%rbp), %rdi
leaq -0x168(%rbp), %rdx
leaq -0x1a0(%rbp), %rcx
callq 0x148f0
jmp 0x15be5
movq -0x3b0(%rbp), %rdi
movq -0xa8(%rbp), %rsi
leaq -0x148(%rbp), %rdx
callq 0x1ff10
movq %rax, -0x3c8(%rbp)
jmp 0x15c08
movq -0x3c8(%rbp), %rax
movq %rax, -0x1b0(%rbp)
leaq -0x148(%rbp), %rdi
callq 0xc3d0
leaq -0x1a0(%rbp), %rdi
callq 0x41f0
leaq -0x1a1(%rbp), %rdi
callq 0x4370
leaq -0x168(%rbp), %rdi
callq 0x41f0
leaq -0x169(%rbp), %rdi
callq 0x4370
jmp 0x15e7f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x178(%rbp)
movl %eax, -0x17c(%rbp)
jmp 0x15cd5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x178(%rbp)
movl %eax, -0x17c(%rbp)
jmp 0x15cbd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x178(%rbp)
movl %eax, -0x17c(%rbp)
jmp 0x15cb1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x178(%rbp)
movl %eax, -0x17c(%rbp)
leaq -0x148(%rbp), %rdi
callq 0xc3d0
leaq -0x1a0(%rbp), %rdi
callq 0x41f0
leaq -0x1a1(%rbp), %rdi
callq 0x4370
leaq -0x168(%rbp), %rdi
callq 0x41f0
leaq -0x169(%rbp), %rdi
callq 0x4370
jmp 0x16128
testb $0x1, -0x2c(%rbp)
je 0x15e7d
movq -0x388(%rbp), %rax
addq $0x1c0, %rax            # imm = 0x1C0
movq %rax, -0x3e0(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x3d8(%rbp)
leaq -0x269(%rbp), %rdi
movq %rdi, -0x3d0(%rbp)
callq 0x4560
movq -0x3d0(%rbp), %rdx
leaq -0x268(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0xb510
jmp 0x15d3b
movq -0x48(%rbp), %rax
movq %rax, -0x3f0(%rbp)
leaq -0x291(%rbp), %rdi
movq %rdi, -0x3e8(%rbp)
callq 0x4560
movq -0x3f0(%rbp), %rsi
movq -0x3e8(%rbp), %rdx
leaq -0x290(%rbp), %rdi
callq 0xb510
jmp 0x15d75
movq -0x3d8(%rbp), %rsi
leaq -0x248(%rbp), %rdi
leaq -0x268(%rbp), %rdx
leaq -0x290(%rbp), %rcx
callq 0x148f0
jmp 0x15d98
movq -0x3e0(%rbp), %rdi
leaq -0x248(%rbp), %rsi
callq 0x1ff90
jmp 0x15dad
leaq -0x248(%rbp), %rdi
callq 0xc3d0
leaq -0x290(%rbp), %rdi
callq 0x41f0
leaq -0x291(%rbp), %rdi
callq 0x4370
leaq -0x268(%rbp), %rdi
callq 0x41f0
leaq -0x269(%rbp), %rdi
callq 0x4370
jmp 0x15e7d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x178(%rbp)
movl %eax, -0x17c(%rbp)
jmp 0x15e6c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x178(%rbp)
movl %eax, -0x17c(%rbp)
jmp 0x15e54
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x178(%rbp)
movl %eax, -0x17c(%rbp)
jmp 0x15e48
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x178(%rbp)
movl %eax, -0x17c(%rbp)
leaq -0x248(%rbp), %rdi
callq 0xc3d0
leaq -0x290(%rbp), %rdi
callq 0x41f0
leaq -0x291(%rbp), %rdi
callq 0x4370
leaq -0x268(%rbp), %rdi
callq 0x41f0
leaq -0x269(%rbp), %rdi
callq 0x4370
jmp 0x16128
jmp 0x15e7f
testb $0x1, -0x2c(%rbp)
je 0x15e9a
movq -0x388(%rbp), %rax
movb $0x0, 0x2d6(%rax)
movb $0x0, 0x2c1(%rax)
cmpb $0x0, -0x2a(%rbp)
je 0x16031
movq -0x388(%rbp), %rax
addq $0x2a8, %rax            # imm = 0x2A8
movq %rax, -0x408(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x400(%rbp)
leaq -0x351(%rbp), %rdi
movq %rdi, -0x3f8(%rbp)
callq 0x4560
movq -0x3f8(%rbp), %rdx
leaq -0x350(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0xb510
jmp 0x15eef
movq -0x48(%rbp), %rax
movq %rax, -0x418(%rbp)
leaq -0x379(%rbp), %rdi
movq %rdi, -0x410(%rbp)
callq 0x4560
movq -0x418(%rbp), %rsi
movq -0x410(%rbp), %rdx
leaq -0x378(%rbp), %rdi
callq 0xb510
jmp 0x15f29
movq -0x400(%rbp), %rsi
leaq -0x330(%rbp), %rdi
leaq -0x350(%rbp), %rdx
leaq -0x378(%rbp), %rcx
callq 0x148f0
jmp 0x15f4c
movq -0x408(%rbp), %rdi
leaq -0x330(%rbp), %rsi
callq 0x1ff90
jmp 0x15f61
leaq -0x330(%rbp), %rdi
callq 0xc3d0
leaq -0x378(%rbp), %rdi
callq 0x41f0
leaq -0x379(%rbp), %rdi
callq 0x4370
leaq -0x350(%rbp), %rdi
callq 0x41f0
leaq -0x351(%rbp), %rdi
callq 0x4370
jmp 0x16031
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x178(%rbp)
movl %eax, -0x17c(%rbp)
jmp 0x16020
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x178(%rbp)
movl %eax, -0x17c(%rbp)
jmp 0x16008
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x178(%rbp)
movl %eax, -0x17c(%rbp)
jmp 0x15ffc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x178(%rbp)
movl %eax, -0x17c(%rbp)
leaq -0x330(%rbp), %rdi
callq 0xc3d0
leaq -0x378(%rbp), %rdi
callq 0x41f0
leaq -0x379(%rbp), %rdi
callq 0x4370
leaq -0x350(%rbp), %rdi
callq 0x41f0
leaq -0x351(%rbp), %rdi
callq 0x4370
jmp 0x16128
jmp 0x16059
movzbl -0x2b(%rbp), %esi
leaq 0x23437(%rip), %rdi     # 0x39475
movb $0x0, %al
callq 0x4050
movzbl -0x2b(%rbp), %edx
xorl %edi, %edi
leaq 0x2343a(%rip), %rsi     # 0x3948c
movb $0x0, %al
callq 0x47d0
movzbl -0x2b(%rbp), %eax
cmpl $0x1, %eax
jne 0x16076
testb $0x1, -0x15(%rbp)
jne 0x16076
movq -0x388(%rbp), %rax
movb $0x1, 0x2c0(%rax)
movq -0x388(%rbp), %rcx
addq $0x180, %rcx            # imm = 0x180
addq $0x160, %rcx            # imm = 0x160
movzbl -0x2b(%rbp), %eax
shlq $0x2, %rax
addq %rax, %rcx
movb -0x15(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, %edx
movw (%rcx,%rdx,2), %ax
addw $0x1, %ax
movw %ax, (%rcx,%rdx,2)
movzwl %ax, %eax
cmpl $0x2, %eax
jne 0x160e0
movb -0x15(%rbp), %cl
leaq 0x19dfb(%rip), %rdx     # 0x2feb9
leaq 0x233ed(%rip), %rax     # 0x394b2
testb $0x1, %cl
cmovneq %rax, %rdx
movzbl -0x2b(%rbp), %ecx
xorl %edi, %edi
leaq 0x233c4(%rip), %rsi     # 0x3949d
movb $0x0, %al
callq 0x47d0
testb $0x1, -0x15(%rbp)
je 0x1610f
movq -0x388(%rbp), %rax
movzbl -0x2b(%rbp), %ecx
testb $0x1, 0x6e0(%rax,%rcx)
je 0x1610f
movzbl -0x2b(%rbp), %edx
xorl %edi, %edi
leaq 0x233b7(%rip), %rsi     # 0x394bf
movb $0x0, %al
callq 0x47d0
jmp 0x16111
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x1588f
addq $0x420, %rsp            # imm = 0x420
popq %rbp
retq
movq -0x178(%rbp), %rdi
callq 0x4550
nopw %cs:(%rax,%rax)