// File: /workspace/github_cpp_makefile_star2_O2/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 $0x158, %rsp            # imm = 0x158
movl %ecx, %r13d
movq %rsi, 0xb0(%rsp)
movl %r13d, %eax
xorb $0x1, %al
movb %al, 0x16(%rsp)
leaq 0x1c0(%rdi), %rax
movq %rax, 0x38(%rsp)
leaq 0x2a8(%rdi), %rax
movq %rax, 0x90(%rsp)
movq %rdi, 0x18(%rsp)
leaq 0x2e0(%rdi), %rax
movq %rax, 0xa8(%rsp)
movl %ecx, %eax
movq %rax, 0xa0(%rsp)
leaq 0x17eaf(%rip), %rax     # 0x2407e
leaq 0xeab3(%rip), %rcx      # 0x1ac89
testl %r13d, %r13d
cmoveq %rcx, %rax
movq %rax, 0x98(%rsp)
movl %edx, %eax
movq %rax, 0xb8(%rsp)
xorl %ebx, %ebx
movl %r13d, 0x24(%rsp)
cmpq %rbx, 0xb8(%rsp)
je 0xc5db
movq 0xb0(%rsp), %rax
movzbl (%rax,%rbx), %eax
movl %eax, %r12d
andl $0x7f, %r12d
je 0xc5d3
leal -0x1(%rax), %ebp
andl $0x40, %ebp
shrl $0x6, %ebp
testb %al, %al
setns %r14b
testl %ebp, %ebp
cmovnel %eax, %r12d
movl %r12d, %edi
callq 0xbf2b
movq %rax, 0x28(%rsp)
testq %rax, %rax
je 0xc28b
leal -0x5d(%r12), %eax
cmpb $0x5, %al
movq 0x18(%rsp), %rcx
ja 0xc26d
movzbl %al, %eax
pushq $0x27
popq %rdx
btl %eax, %edx
jae 0xc26d
leaq 0x17bd8(%rip), %rdx     # 0x23e3c
movl (%rdx,%rax,4), %eax
orl %eax, 0x2dc(%rcx)
movb 0x2d6(%rcx), %r13b
andb 0x16(%rsp), %r13b
cmpb $0x1, %r13b
jne 0xc2b4
movb 0x2c1(%rcx), %al
movl %eax, 0x34(%rsp)
jmp 0xc2bc
leaq 0x17daf(%rip), %rdi     # 0x24041
movl %r12d, %esi
xorl %eax, %eax
callq 0x3030
xorl %edi, %edi
leaq 0x17db3(%rip), %rsi     # 0x24058
movl %r12d, %edx
xorl %eax, %eax
callq 0x362c
jmp 0xc551
movl $0x0, 0x34(%rsp)
orb %bpl, %r14b
leaq 0x80(%rsp), %r15
movq %r15, %rdi
leaq 0xe633(%rip), %rsi      # 0x1a904
movl %r12d, %edx
xorl %eax, %eax
callq 0x3070
movb %r14b, 0x17(%rsp)
testb %r14b, %r14b
leaq 0x18187(%rip), %rbp     # 0x24471
leaq 0xe998(%rip), %rax      # 0x1ac89
cmovneq %rax, %rbp
cmpb $0x0, 0x24(%rsp)
je 0xc32e
pushq $0x15
popq %rcx
leaq 0xc0(%rsp), %rdx
movq %rdx, %rdi
movq 0x28(%rsp), %rsi
rep  movsl (%rsi), %es:(%rdi)
movb $0x1, 0x110(%rsp)
movl $0x1, (%rsp)
movq 0x18(%rsp), %rdi
leaq 0x1316b(%rip), %rsi     # 0x1f497
jmp 0xc346
movl $0x1, (%rsp)
movq 0x18(%rsp), %rdi
leaq 0x13156(%rip), %rsi     # 0x1f497
movq 0x28(%rsp), %rdx
movq %r15, %rcx
movq %rbp, %r8
xorl %r9d, %r9d
callq 0x3af0
cmpb $0x0, 0x34(%rsp)
je 0xc3a1
movq 0x18(%rsp), %rax
movq 0x1c0(%rax), %rsi
cmpq 0x1c8(%rax), %rsi
je 0xc437
movq 0x18(%rsp), %rdi
movq 0x28(%rsp), %rdx
callq 0x39a6
pushq $0x1
popq %rdi
testb %al, %al
je 0xc426
leaq 0x17bff(%rip), %rsi     # 0x23f94
xorl %eax, %eax
callq 0x362c
jmp 0xc437
testb %r13b, %r13b
movl 0x24(%rsp), %r13d
je 0xc4d1
leaq 0x40(%rsp), %rdi
leaq 0x80(%rsp), %rsi
leaq 0x15(%rsp), %rdx
callq 0x75c4
leaq 0x60(%rsp), %r14
movq %r14, %rdi
movq %rbp, %rsi
leaq 0x14(%rsp), %rdx
callq 0x75c4
leaq 0xc0(%rsp), %r15
movq %r15, %rdi
movq 0x28(%rsp), %rsi
leaq 0x40(%rsp), %rdx
movq %r14, %rcx
callq 0xbb34
movq 0x38(%rsp), %rdi
movq %r15, %rsi
callq 0x120e8
movq %r15, %rdi
callq 0x78cc
leaq 0x60(%rsp), %rdi
callq 0x3130
leaq 0x40(%rsp), %rdi
callq 0x3130
jmp 0xc4be
leaq 0x17bba(%rip), %rsi     # 0x23fe7
movl %r12d, %edx
xorl %eax, %eax
callq 0x362c
movq 0x38(%rsp), %rax
movq (%rax), %r14
leaq 0x40(%rsp), %rdi
leaq 0x80(%rsp), %rsi
leaq 0x15(%rsp), %rdx
callq 0x75c4
leaq 0x60(%rsp), %r15
movq %r15, %rdi
movq %rbp, %rsi
leaq 0x14(%rsp), %rdx
callq 0x75c4
leaq 0xc0(%rsp), %rbp
movq %rbp, %rdi
movq 0x28(%rsp), %rsi
leaq 0x40(%rsp), %rdx
movq %r15, %rcx
callq 0xbb34
movq 0x38(%rsp), %rdi
movq %r14, %rsi
movq %rbp, %rdx
callq 0x11f14
movq %rbp, %rdi
callq 0x78cc
leaq 0x60(%rsp), %rdi
callq 0x3130
leaq 0x40(%rsp), %rdi
callq 0x3130
testb %r13b, %r13b
movl 0x24(%rsp), %r13d
je 0xc4d1
movq 0x18(%rsp), %rax
xorl %ecx, %ecx
movb %cl, 0x2d6(%rax)
movb %cl, 0x2c1(%rax)
cmpb $0x0, 0x17(%rsp)
leaq 0x80(%rsp), %rsi
jne 0xc551
leaq 0x40(%rsp), %rdi
leaq 0x15(%rsp), %rdx
callq 0x75c4
leaq 0x60(%rsp), %r14
movq %r14, %rdi
leaq 0x17f73(%rip), %rsi     # 0x24471
leaq 0x14(%rsp), %rdx
callq 0x75c4
leaq 0xc0(%rsp), %r15
movq %r15, %rdi
movq 0x28(%rsp), %rsi
leaq 0x40(%rsp), %rdx
movq %r14, %rcx
callq 0xbb34
movq 0x90(%rsp), %rdi
movq %r15, %rsi
callq 0x120e8
movq %r15, %rdi
callq 0x78cc
leaq 0x60(%rsp), %rdi
callq 0x3130
leaq 0x40(%rsp), %rdi
callq 0x3130
cmpl $0x1, %r12d
setne %al
orb %r13b, %al
jne 0xc569
movq 0x18(%rsp), %rax
movb $0x1, 0x2c0(%rax)
movl %r12d, %r14d
movq 0xa8(%rsp), %rax
leaq (%rax,%r14,4), %rax
movq 0xa0(%rsp), %rdx
movzwl (%rax,%rdx,2), %ecx
incl %ecx
movw %cx, (%rax,%rdx,2)
cmpw $0x2, %cx
jne 0xc5ab
xorl %edi, %edi
leaq 0x17ad0(%rip), %rsi     # 0x24069
movq 0x98(%rsp), %rdx
movl %r12d, %ecx
xorl %eax, %eax
callq 0x362c
testb %r13b, %r13b
je 0xc5d3
movq 0x18(%rsp), %rax
cmpb $0x1, 0x6e0(%rax,%r14)
jne 0xc5d3
xorl %edi, %edi
leaq 0x17ac2(%rip), %rsi     # 0x2408b
movl %r12d, %edx
xorl %eax, %eax
callq 0x362c
incq %rbx
jmp 0xc1f6
addq $0x158, %rsp            # imm = 0x158
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xc607
jmp 0xc619
jmp 0xc5fd
jmp 0xc602
jmp 0xc5fd
jmp 0xc602
jmp 0xc607
jmp 0xc619
movq %rax, %rbx
jmp 0xc626
movq %rax, %rbx
jmp 0xc630
movq %rax, %rbx
leaq 0xc0(%rsp), %rdi
callq 0x78cc
jmp 0xc61c
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0x3130
leaq 0x40(%rsp), %rdi
callq 0x3130
movq %rbx, %rdi
callq 0x3430