// File: /workspace/github_cpp_makefile_star2_O1/rpavlik[P]edid-decode/parse-cta-block.cpp
// Function: edid_state::preparse_cta_block(unsigned char const*)
void edid_state::preparse_cta_block(const unsigned char *x)
{
	unsigned version = x[1];
	unsigned offset = x[2];

	if (offset >= 4) {
		const unsigned char *detailed;

		for (detailed = x + offset; detailed + 17 < x + 127; detailed += 18) {
			if (memchk(detailed, 18))
				break;
			if (detailed[0] || detailed[1])
				cta.preparsed_total_dtds++;
		}
	}

	if (version < 3)
		return;

	for (unsigned i = 4; i < offset; i += (x[i] & 0x1f) + 1) {
		bool for_ycbcr420 = false;
		unsigned oui;

		switch ((x[i] & 0xe0) >> 5) {
		case 0x03:
			oui = (x[i + 3] << 16) + (x[i + 2] << 8) + x[i + 1];
			if (oui == 0x000c03) {
				cta.has_hdmi = true;
				cta.preparsed_phys_addr = (x[i + 4] << 8) | x[i + 5];
			}
			break;
		case 0x07:
			if (x[i + 1] == 0x0d)
				cta.has_vfpdb = true;
			if (x[i + 1] == 0x13 && (x[i + 2] & 0x40)) {
				cta.preparsed_speaker_count = 1 + (x[i + 2] & 0x1f);
				cta.preparsed_sld = x[i + 2] & 0x20;
			}
			if (x[i + 1] == 0x14)
				cta_preparse_sldb(x + i + 2, (x[i] & 0x1f) - 1);
			if (x[i + 1] == 0x22)
				cta.preparsed_total_vtdbs++;
			if (x[i + 1] == 0x23)
				cta.preparsed_has_t8vtdb = true;
			if (x[i + 1] == 0x32)
				cta.preparsed_total_vtdbs +=
					((x[i] & 0x1f) - 2) / (6 + ((x[i + 2] & 0x70) >> 4));
			if (x[i + 1] != 0x0e)
				continue;
			for_ycbcr420 = true;
			/* fall-through */
		case 0x02:
			for (unsigned j = 1 + for_ycbcr420; j <= (x[i] & 0x1f); j++) {
				unsigned char vic = x[i + j];

				if ((vic & 0x7f) <= 64)
					vic &= 0x7f;
				cta.preparsed_svds[for_ycbcr420].push_back(vic);
				cta.preparsed_has_vic[for_ycbcr420][vic] = true;
			}
			break;
		}
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rsi, %rbx
movq %rdi, 0x10(%rsp)
movb 0x1(%rsi), %bpl
movzbl 0x2(%rsi), %eax
movq %rax, 0x18(%rsp)
addl $-0x4, %eax
cmpb $0x69, %al
ja 0x14c92
movq 0x18(%rsp), %r14
leaq (%rbx,%r14), %r15
movq %r15, %rdi
movl $0x12, %esi
xorl %edx, %edx
callq 0x5b92
testb %al, %al
jne 0x14c92
cmpb $0x0, (%r15)
jne 0x14c7a
cmpb $0x0, 0x1(%rbx,%r14)
je 0x14c85
movq 0x10(%rsp), %rax
incl 0x180(%rax)
leaq 0x12(%r14), %rax
cmpq $0x5c, %r14
movq %rax, %r14
jb 0x14c55
cmpb $0x3, %bpl
setb %al
cmpb $0x5, 0x18(%rsp)
setb %cl
orb %al, %cl
jne 0x14ec8
movq 0x10(%rsp), %rax
leaq 0x8e0(%rax), %rcx
movq %rcx, 0x30(%rsp)
addq $0x6e0, %rax            # imm = 0x6E0
movq %rax, 0x28(%rsp)
leaq 0x2(%rbx), %rax
movq %rax, 0x20(%rsp)
movl $0x4, %eax
movl %eax, %ebp
leaq (%rbx,%rbp), %r13
movzbl (%rbx,%rbp), %eax
shrl $0x5, %eax
cmpl $0x2, %eax
je 0x14dc0
cmpl $0x7, %eax
je 0x14d3c
cmpl $0x3, %eax
jne 0x14eb2
movzbl 0x3(%r13), %eax
shll $0x10, %eax
movzbl 0x2(%r13), %ecx
shll $0x8, %ecx
orl %eax, %ecx
movzbl 0x1(%r13), %eax
orl %ecx, %eax
cmpl $0xc03, %eax            # imm = 0xC03
jne 0x14eb2
movq 0x10(%rsp), %rcx
movb $0x1, 0x2c3(%rcx)
movzwl 0x4(%r13), %eax
rolw $0x8, %ax
movw %ax, 0x2d0(%rcx)
jmp 0x14eb2
cmpb $0xd, 0x1(%r13)
jne 0x14d4f
movq 0x10(%rsp), %rax
movb $0x1, 0x2c5(%rax)
cmpb $0x13, 0x1(%r13)
jne 0x14d7e
movzbl 0x2(%r13), %eax
testb $0x40, %al
je 0x14d7e
andl $0x1f, %eax
incl %eax
movq 0x10(%rsp), %rcx
movl %eax, 0x2c8(%rcx)
movb 0x2(%r13), %al
shrb $0x5, %al
andb $0x1, %al
movb %al, 0x2cd(%rcx)
cmpb $0x14, 0x1(%r13)
jne 0x14dd0
movzbl (%r13), %eax
andl $0x1f, %eax
decl %eax
movq 0x10(%rsp), %rcx
movb $0x1, 0x2ce(%rcx)
cmpl $0x2, %eax
jb 0x14dd0
movq 0x20(%rsp), %rcx
addq %rbp, %rcx
cmpl $0x5, %eax
jb 0x14db2
testb $0x40, (%rcx)
jne 0x14dc4
addl $-0x2, %eax
addq $0x2, %rcx
cmpl $0x1, %eax
ja 0x14da8
jmp 0x14dd0
xorl %eax, %eax
jmp 0x14e30
movq 0x10(%rsp), %rax
movb $0x1, 0x2cc(%rax)
cmpb $0x22, 0x1(%r13)
jne 0x14de2
movq 0x10(%rsp), %rax
incl 0x1a0(%rax)
cmpb $0x23, 0x1(%r13)
jne 0x14df5
movq 0x10(%rsp), %rax
movb $0x1, 0x1d8(%rax)
cmpb $0x32, 0x1(%r13)
jne 0x14e23
movzbl (%r13), %eax
andl $0x1f, %eax
addl $-0x2, %eax
movzbl 0x2(%r13), %ecx
shrl $0x4, %ecx
andl $0x7, %ecx
addl $0x6, %ecx
cltd
idivl %ecx
movq 0x10(%rsp), %rcx
addl %eax, 0x1a0(%rcx)
movb $0x1, %al
cmpb $0xe, 0x1(%r13)
jne 0x14eb2
movzbl %al, %r15d
leal 0x1(%r15), %eax
movzbl (%r13), %ecx
andl $0x1f, %ecx
cmpl %ecx, %eax
ja 0x14eb2
leaq (%r15,%r15,2), %rcx
movq 0x30(%rsp), %rdx
leaq (%rdx,%rcx,8), %r12
movl %eax, %r14d
decq %r14
shll $0x8, %r15d
addq 0x28(%rsp), %r15
movzbl 0x1(%r13,%r14), %ecx
movl %ecx, %eax
andb $0x7f, %al
cmpb $0x41, %al
movzbl %al, %eax
cmovael %ecx, %eax
movb %al, 0xf(%rsp)
movq 0x8(%r12), %rsi
cmpq 0x10(%r12), %rsi
je 0x14e8b
movb %al, (%rsi)
incq 0x8(%r12)
jmp 0x14e98
movq %r12, %rdi
leaq 0xf(%rsp), %rdx
callq 0x1607a
movzbl 0xf(%rsp), %eax
movb $0x1, (%rax,%r15)
movzbl (%r13), %eax
andl $0x1f, %eax
incq %r14
cmpq %rax, %r14
jb 0x14e60
movzbl (%r13), %eax
andl $0x1f, %eax
addl %ebp, %eax
incl %eax
cmpl 0x18(%rsp), %eax
jb 0x14cd3
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop