// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x168, %rsp            # imm = 0x168
movq %rsi, 0xc8(%rsp)
movq %rdi, 0x18(%rsp)
testl %edx, %edx
je 0xea0b
movl %ecx, %ebp
movl %ebp, %eax
xorb $0x1, %al
movb %al, 0x17(%rsp)
movq 0x18(%rsp), %rax
leaq 0x1c0(%rax), %rcx
movq %rcx, 0x70(%rsp)
leaq 0xd0(%rsp), %rdi
leaq 0x88(%rdi), %rcx
movq %rcx, 0x68(%rsp)
leaq 0x2a8(%rax), %rcx
movq %rcx, 0xa0(%rsp)
addq $0x2e0, %rax            # imm = 0x2E0
movq %rax, 0xc0(%rsp)
movzbl %bpl, %eax
leaq 0x1bbe5(%rip), %rcx     # 0x2a056
leaq 0x12801(%rip), %rsi     # 0x20c79
movq %rax, 0xb8(%rsp)
testb %al, %al
cmoveq %rsi, %rcx
movq %rcx, 0xa8(%rsp)
movl %edx, %r14d
xorl %ebx, %ebx
movl %ebp, 0x64(%rsp)
movq %r14, 0xb0(%rsp)
movq 0xc8(%rsp), %rax
movzbl (%rax,%rbx), %ecx
movl %ecx, %r15d
andl $0x7f, %r15d
je 0xe9ff
leal -0x1(%rcx), %eax
andl $0x40, %eax
shrl $0x6, %eax
testb %cl, %cl
setns %dil
testl %eax, %eax
cmovnel %ecx, %r15d
movzbl %r15b, %r8d
testb %r15b, %r15b
jle 0xe4eb
imulq $0x54, %r8, %rcx
leaq 0x185ef(%rip), %rdx     # 0x26ad0
leaq (%rcx,%rdx), %r12
addq $-0x54, %r12
jmp 0xe50f
leal 0x3f(%r15), %ecx
cmpb $0x1a, %cl
ja 0xe50c
imulq $0x54, %r8, %rcx
leaq 0x1af81(%rip), %rdx     # 0x29480
leaq (%rcx,%rdx), %r12
addq $-0x3f54, %r12          # imm = 0xC0AC
jmp 0xe50f
xorl %r12d, %r12d
testq %r12, %r12
movq %r8, 0x98(%rsp)
je 0xe549
leal -0x5d(%r8), %ecx
cmpl $0x5, %ecx
movq 0x18(%rsp), %rdx
leaq 0x80(%rsp), %r13
ja 0xe58e
leaq 0x182c7(%rip), %rsi     # 0x26800
movslq (%rsi,%rcx,4), %rcx
addq %rsi, %rcx
jmpq *%rcx
movl $0x4, %ecx
jmp 0xe588
leaq 0x1bac9(%rip), %rdi     # 0x2a019
movl %r8d, %esi
xorl %eax, %eax
movq %r8, %r12
callq 0x3030
xorl %edi, %edi
leaq 0x1baca(%rip), %rsi     # 0x2a030
movl %r12d, %edx
xorl %eax, %eax
callq 0x37ec
jmp 0xe977
movl $0x1, %ecx
jmp 0xe588
movl $0x2, %ecx
jmp 0xe588
movl $0x8, %ecx
orl %ecx, 0x2dc(%rdx)
movb 0x2d6(%rdx), %cl
andb 0x17(%rsp), %cl
movb %cl, 0x16(%rsp)
cmpb $0x1, %cl
jne 0xe5aa
movb 0x2c1(%rdx), %r14b
jmp 0xe5ad
xorl %r14d, %r14d
movl %edi, %ebp
orb %al, %bpl
movq %r13, %rdi
leaq 0x12338(%rip), %rsi     # 0x208f4
movl %r8d, %edx
xorl %eax, %eax
callq 0x3070
movb %bpl, 0x15(%rsp)
testb %bpl, %bpl
leaq 0x1be74(%rip), %rbp     # 0x2a449
leaq 0x1269d(%rip), %rax     # 0x20c79
cmovneq %rax, %rbp
cmpb $0x0, 0x64(%rsp)
movq %rbp, 0x78(%rsp)
je 0xe61e
movl $0x15, %ecx
leaq 0xd0(%rsp), %rdx
movq %rdx, %rdi
movq %r12, %rsi
rep  movsl (%rsi), %es:(%rdi)
movb $0x1, 0x120(%rsp)
movl $0x1, (%rsp)
movq 0x18(%rsp), %rdi
leaq 0x16e2b(%rip), %rsi     # 0x25447
jmp 0xe634
movl $0x1, (%rsp)
movq 0x18(%rsp), %rdi
leaq 0x16e16(%rip), %rsi     # 0x25447
movq %r12, %rdx
movq %r13, %rcx
movq %rbp, %r8
xorl %r9d, %r9d
callq 0x3ebe
testb %r14b, %r14b
je 0xe68d
movq 0x18(%rsp), %rax
movq 0x1c0(%rax), %rsi
cmpq 0x1c8(%rax), %rsi
je 0xe739
movq 0x18(%rsp), %rdi
movq %r12, %rdx
callq 0x3d6a
movl $0x1, %edi
testb %al, %al
je 0xe723
leaq 0x1b8eb(%rip), %rsi     # 0x29f6c
xorl %eax, %eax
callq 0x37ec
jmp 0xe739
cmpb $0x0, 0x16(%rsp)
leaq 0xd0(%rsp), %r14
je 0xe863
movq %r12, %rbp
leaq 0x30(%rsp), %rax
movq %rax, 0x20(%rsp)
leaq 0x80(%rsp), %r13
movq %r13, %rdi
callq 0x3110
leaq (%rsp,%rax), %rdx
addq $0x80, %rdx
leaq 0x20(%rsp), %rdi
movq %r13, %rsi
callq 0x8f6e
leaq 0x50(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0x78(%rsp), %rsi
leaq 0x6(%rsi), %rdx
cmpb $0x0, 0x15(%rsp)
cmovneq %rsi, %rdx
leaq 0x40(%rsp), %r12
movq %r12, %rdi
callq 0x8f6e
movq %r14, %rdi
movq %rbp, %rsi
leaq 0x20(%rsp), %rdx
movq %r12, %rcx
callq 0xdce2
movq 0x70(%rsp), %rdi
movq %r14, %rsi
callq 0x16042
jmp 0xe7ca
leaq 0x1b895(%rip), %rsi     # 0x29fbf
movq 0x98(%rsp), %rdx
xorl %eax, %eax
callq 0x37ec
movq %r12, %rbp
movq 0x70(%rsp), %rax
movq (%rax), %r13
leaq 0x30(%rsp), %rax
movq %rax, 0x20(%rsp)
leaq 0x80(%rsp), %r14
movq %r14, %rdi
callq 0x3110
leaq (%rsp,%rax), %rdx
addq $0x80, %rdx
leaq 0x20(%rsp), %rdi
movq %r14, %rsi
callq 0x8f6e
leaq 0x50(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0x78(%rsp), %rsi
leaq 0x6(%rsi), %rdx
cmpb $0x0, 0x15(%rsp)
cmovneq %rsi, %rdx
leaq 0x40(%rsp), %r12
movq %r12, %rdi
callq 0x8f6e
leaq 0xd0(%rsp), %r14
movq %r14, %rdi
movq %rbp, %rsi
leaq 0x20(%rsp), %rdx
movq %r12, %rcx
callq 0xdce2
movq 0x70(%rsp), %rdi
movq %r13, %rsi
movq %r14, %rdx
callq 0x15ddc
movq 0x148(%rsp), %rdi
cmpq 0x68(%rsp), %rdi
movq %rbp, %r12
je 0xe7ec
movq 0x158(%rsp), %rsi
incq %rsi
callq 0x3260
movq 0x128(%rsp), %rdi
leaq 0x138(%rsp), %rax
cmpq %rax, %rdi
je 0xe811
movq 0x138(%rsp), %rsi
incq %rsi
callq 0x3260
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
je 0xe82d
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x3260
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0xe849
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x3260
cmpb $0x0, 0x16(%rsp)
je 0xe863
movq 0x18(%rsp), %rax
xorl %ecx, %ecx
movb %cl, 0x2d6(%rax)
movb %cl, 0x2c1(%rax)
cmpb $0x0, 0x15(%rsp)
jne 0xe96b
movq %r12, %rbp
leaq 0x30(%rsp), %rax
movq %rax, 0x20(%rsp)
leaq 0x80(%rsp), %r13
movq %r13, %rdi
callq 0x3110
leaq (%rsp,%rax), %rdx
addq $0x80, %rdx
leaq 0x20(%rsp), %rdi
movq %r13, %rsi
callq 0x8f6e
leaq 0x50(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0x78(%rsp), %rsi
leaq 0x6(%rsi), %rdx
cmpb $0x0, 0x15(%rsp)
cmovneq %rsi, %rdx
leaq 0x40(%rsp), %r12
movq %r12, %rdi
callq 0x8f6e
movq %r14, %rdi
movq %rbp, %rsi
leaq 0x20(%rsp), %rdx
movq %r12, %rcx
callq 0xdce2
movq 0xa0(%rsp), %rdi
movq %r14, %rsi
callq 0x16042
movq 0x148(%rsp), %rdi
cmpq 0x68(%rsp), %rdi
je 0xe90e
movq 0x158(%rsp), %rsi
incq %rsi
callq 0x3260
movq 0x128(%rsp), %rdi
leaq 0x138(%rsp), %rax
cmpq %rax, %rdi
je 0xe933
movq 0x138(%rsp), %rsi
incq %rsi
callq 0x3260
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
je 0xe94f
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x3260
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0xe96b
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x3260
movl 0x64(%rsp), %ebp
movq 0xb0(%rsp), %r14
cmpb $0x1, %r15b
setne %al
orb %bpl, %al
jne 0xe98f
movq 0x18(%rsp), %rax
movb $0x1, 0x2c0(%rax)
movq 0xc0(%rsp), %rax
movq 0x98(%rsp), %rcx
leaq (%rax,%rcx,4), %rax
movq 0xb8(%rsp), %rdx
movzwl (%rax,%rdx,2), %esi
incl %esi
movw %si, (%rax,%rdx,2)
cmpw $0x2, %si
jne 0xe9d9
xorl %edi, %edi
leaq 0x1b67d(%rip), %rsi     # 0x2a041
movq 0xa8(%rsp), %rdx
xorl %eax, %eax
movq %rcx, %r15
callq 0x37ec
movq %r15, %rcx
testb %bpl, %bpl
je 0xe9ff
movq 0x18(%rsp), %rax
cmpb $0x1, 0x6e0(%rax,%rcx)
jne 0xe9ff
xorl %edi, %edi
leaq 0x1b66d(%rip), %rsi     # 0x2a063
movl %ecx, %edx
xorl %eax, %eax
callq 0x37ec
incq %rbx
cmpq %rbx, %r14
jne 0xe49f
addq $0x168, %rsp            # imm = 0x168
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xea37
jmp 0xea49
jmp 0xea2d
jmp 0xea32
jmp 0xea2d
jmp 0xea32
jmp 0xea37
jmp 0xea49
movq %rax, %rbx
jmp 0xea68
movq %rax, %rbx
jmp 0xea84
movq %rax, %rbx
leaq 0xd0(%rsp), %rdi
callq 0xdd9e
jmp 0xea4c
movq %rax, %rbx
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
je 0xea68
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x3260
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0xea84
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x3260
movq %rbx, %rdi
callq 0x3400