// File: /workspace/github_cpp_makefile_star2_O3/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
movl %ecx, 0x14(%rsp)
testl %edx, %edx
je 0xe89c
movq %rsi, %r14
movq %rdi, %r12
movl 0x14(%rsp), %eax
movl %eax, %ecx
xorb $0x1, %cl
movb %cl, 0x13(%rsp)
leaq 0x1c0(%rdi), %rcx
movq %rcx, 0x78(%rsp)
leaq 0xd0(%rsp), %rdi
leaq 0x88(%rdi), %rcx
movq %rcx, 0x70(%rsp)
leaq 0x2a8(%r12), %rcx
movq %rcx, 0x98(%rsp)
leaq 0x2e0(%r12), %rcx
movq %rcx, 0xb8(%rsp)
movzbl %al, %eax
leaq 0x1bdd0(%rip), %rcx     # 0x2a07e
leaq 0x129d4(%rip), %rsi     # 0x20c89
movq %rax, 0xb0(%rsp)
testb %al, %al
cmoveq %rsi, %rcx
movq %rcx, 0xa0(%rsp)
movl %edx, %eax
movq %rax, 0xc8(%rsp)
xorl %ebx, %ebx
movq %r14, 0xa8(%rsp)
movq %r12, 0x38(%rsp)
movzbl (%r14,%rbx), %ecx
movl %ecx, %r15d
andl $0x7f, %r15d
je 0xe88b
leal -0x1(%rcx), %eax
andl $0x40, %eax
shrl $0x6, %eax
testb %cl, %cl
setns %bpl
testl %eax, %eax
cmovnel %ecx, %r15d
movzbl %r15b, %r13d
leaq 0x18786(%rip), %rsi     # 0x26a9c
testb %r15b, %r15b
jg 0xe32f
leal 0x3f(%r15), %ecx
leaq 0x17226(%rip), %rsi     # 0x2554c
cmpb $0x1a, %cl
ja 0xe599
leal -0x5d(%r15), %ecx
cmpb $0x5, %cl
ja 0xe357
movzbl %cl, %ecx
movl $0x27, %edx
btl %ecx, %edx
jae 0xe357
leaq 0x1baf0(%rip), %rdx     # 0x29e3c
movl (%rdx,%rcx,4), %ecx
orl %ecx, 0x2dc(%r12)
movb 0x2d6(%r12), %dl
andb 0x13(%rsp), %dl
movb %dl, 0x12(%rsp)
cmpb $0x1, %dl
leaq 0x80(%rsp), %r14
jne 0xe382
movb 0x2c1(%r12), %cl
movl %ecx, 0x64(%rsp)
jmp 0xe38a
movl $0x0, 0x64(%rsp)
orb %al, %bpl
imulq $0x54, %r13, %rax
addq %rax, %rsi
movq %r14, %rdi
movq %rsi, %r12
leaq 0x12563(%rip), %rsi     # 0x20904
movl %r13d, %edx
xorl %eax, %eax
callq 0x3070
movb %bpl, 0x11(%rsp)
testb %bpl, %bpl
movq %r14, %r8
leaq 0x1c0b4(%rip), %r14     # 0x2a471
leaq 0x128c5(%rip), %rax     # 0x20c89
cmovneq %rax, %r14
cmpb $0x0, 0x14(%rsp)
movq %r12, 0x68(%rsp)
je 0xe406
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 0x38(%rsp), %rdi
leaq 0x17093(%rip), %rsi     # 0x25497
jmp 0xe41c
movl $0x1, (%rsp)
movq 0x38(%rsp), %rdi
leaq 0x1707e(%rip), %rsi     # 0x25497
movq %r12, %rdx
movq %r8, %rcx
movq %r14, %r8
xorl %r9d, %r9d
callq 0x3e8c
cmpb $0x0, 0x64(%rsp)
movq %r13, 0xc0(%rsp)
je 0xe481
movq 0x38(%rsp), %rax
movq 0x1c0(%rax), %rsi
cmpq 0x1c8(%rax), %rsi
je 0xe5d3
movq 0x38(%rsp), %rdi
movq 0x68(%rsp), %rdx
callq 0x3d40
movl $0x1, %edi
testb %al, %al
je 0xe5c2
leaq 0x1bb1f(%rip), %rsi     # 0x29f94
xorl %eax, %eax
callq 0x37cc
jmp 0xe5d3
cmpb $0x0, 0x12(%rsp)
movq 0x38(%rsp), %r12
leaq 0xd0(%rsp), %r13
je 0xe6fe
leaq 0x28(%rsp), %rax
movq %rax, 0x18(%rsp)
leaq 0x80(%rsp), %rbp
movq %rbp, %rdi
callq 0x3110
leaq (%rsp,%rax), %rdx
addq $0x80, %rdx
leaq 0x18(%rsp), %rdi
movq %rbp, %rsi
callq 0x8d58
leaq 0x50(%rsp), %rax
movq %rax, 0x40(%rsp)
leaq 0x6(%r14), %rdx
cmpb $0x0, 0x11(%rsp)
cmovneq %r14, %rdx
leaq 0x40(%rsp), %rbp
movq %rbp, %rdi
movq %r14, %rsi
callq 0x8d58
movq %r13, %rdi
movq 0x68(%rsp), %rsi
leaq 0x18(%rsp), %rdx
movq %rbp, %rcx
callq 0xdb20
movq 0x78(%rsp), %rdi
movq %r13, %rsi
callq 0x15ede
movq 0x148(%rsp), %rdi
cmpq 0x70(%rsp), %rdi
je 0xe533
movq 0x158(%rsp), %rsi
incq %rsi
callq 0x3260
movq 0x128(%rsp), %rdi
leaq 0x138(%rsp), %rax
cmpq %rax, %rdi
je 0xe558
movq 0x138(%rsp), %rsi
incq %rsi
callq 0x3260
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
je 0xe574
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x3260
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0xe6ec
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x3260
jmp 0xe6ec
leaq 0x1baa1(%rip), %rdi     # 0x2a041
movl %r13d, %esi
xorl %eax, %eax
callq 0x3030
xorl %edi, %edi
leaq 0x1baa5(%rip), %rsi     # 0x2a058
movl %r13d, %edx
xorl %eax, %eax
callq 0x37cc
jmp 0xe827
leaq 0x1ba1e(%rip), %rsi     # 0x29fe7
movl %r13d, %edx
xorl %eax, %eax
callq 0x37cc
movq 0x78(%rsp), %rax
movq (%rax), %rbp
leaq 0x28(%rsp), %rax
movq %rax, 0x18(%rsp)
leaq 0x80(%rsp), %r13
movq %r13, %rdi
callq 0x3110
leaq (%rsp,%rax), %rdx
addq $0x80, %rdx
leaq 0x18(%rsp), %rdi
movq %r13, %rsi
callq 0x8d58
leaq 0x50(%rsp), %rax
movq %rax, 0x40(%rsp)
leaq 0x6(%r14), %rdx
cmpb $0x0, 0x11(%rsp)
cmovneq %r14, %rdx
leaq 0x40(%rsp), %r13
movq %r13, %rdi
movq %r14, %rsi
callq 0x8d58
leaq 0xd0(%rsp), %r14
movq %r14, %rdi
movq 0x68(%rsp), %rsi
leaq 0x18(%rsp), %rdx
movq %r13, %rcx
callq 0xdb20
movq 0x78(%rsp), %rdi
movq %rbp, %rsi
movq %r14, %rdx
callq 0x15c78
movq %r14, %r13
movq 0x148(%rsp), %rdi
cmpq 0x70(%rsp), %rdi
je 0xe683
movq 0x158(%rsp), %rsi
incq %rsi
callq 0x3260
movq 0x128(%rsp), %rdi
leaq 0x138(%rsp), %rax
cmpq %rax, %rdi
je 0xe6a8
movq 0x138(%rsp), %rsi
incq %rsi
callq 0x3260
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
je 0xe6c4
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x3260
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0xe6e0
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x3260
cmpb $0x0, 0x12(%rsp)
movq 0x38(%rsp), %r12
je 0xe6fe
xorl %eax, %eax
movb %al, 0x2d6(%r12)
movb %al, 0x2c1(%r12)
cmpb $0x0, 0x11(%rsp)
movq 0xa8(%rsp), %r14
jne 0xe809
leaq 0x28(%rsp), %rax
movq %rax, 0x18(%rsp)
leaq 0x80(%rsp), %rbp
movq %rbp, %rdi
callq 0x3110
leaq (%rsp,%rax), %rdx
addq $0x80, %rdx
leaq 0x18(%rsp), %rdi
movq %rbp, %rsi
callq 0x8d58
leaq 0x50(%rsp), %rax
movq %rax, 0x40(%rsp)
leaq 0x40(%rsp), %rbp
movq %rbp, %rdi
leaq 0x1bd15(%rip), %rsi     # 0x2a471
leaq 0x1bd14(%rip), %rdx     # 0x2a477
callq 0x8d58
movq %r13, %rdi
movq 0x68(%rsp), %rsi
leaq 0x18(%rsp), %rdx
movq %rbp, %rcx
callq 0xdb20
movq 0x98(%rsp), %rdi
movq %r13, %rsi
callq 0x15ede
movq 0x148(%rsp), %rdi
cmpq 0x70(%rsp), %rdi
je 0xe7ac
movq 0x158(%rsp), %rsi
incq %rsi
callq 0x3260
movq 0x128(%rsp), %rdi
leaq 0x138(%rsp), %rax
cmpq %rax, %rdi
je 0xe7d1
movq 0x138(%rsp), %rsi
incq %rsi
callq 0x3260
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
je 0xe7ed
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x3260
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0xe809
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x3260
cmpb $0x1, %r15b
setne %al
orb 0x14(%rsp), %al
movq 0xc0(%rsp), %r13
jne 0xe827
movb $0x1, 0x2c0(%r12)
movq 0xb8(%rsp), %rax
leaq (%rax,%r13,4), %rax
movq 0xb0(%rsp), %rdx
movzwl (%rax,%rdx,2), %ecx
incl %ecx
movw %cx, (%rax,%rdx,2)
cmpw $0x2, %cx
jne 0xe866
xorl %edi, %edi
leaq 0x1b815(%rip), %rsi     # 0x2a069
movq 0xa0(%rsp), %rdx
movl %r13d, %ecx
xorl %eax, %eax
callq 0x37cc
cmpb $0x0, 0x14(%rsp)
je 0xe88b
cmpb $0x1, 0x6e0(%r12,%r13)
jne 0xe88b
xorl %edi, %edi
leaq 0x1b80a(%rip), %rsi     # 0x2a08b
movl %r13d, %edx
xorl %eax, %eax
callq 0x37cc
incq %rbx
cmpq %rbx, 0xc8(%rsp)
jne 0xe2e4
addq $0x168, %rsp            # imm = 0x168
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xe8be
jmp 0xe8d0
jmp 0xe8f1
jmp 0xe912
jmp 0xe8be
jmp 0xe8d0
jmp 0xe8f1
jmp 0xe912
movq %rax, %rbx
leaq 0xd0(%rsp), %rdi
callq 0xdbdc
jmp 0xe8d3
movq %rax, %rbx
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
je 0xe8f4
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x3260
jmp 0xe8f4
movq %rax, %rbx
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0xe915
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x3260
jmp 0xe915
movq %rax, %rbx
movq %rbx, %rdi
callq 0x3400
nop