// File: /workspace/github_cpp_makefile_star2_O3/rpavlik[P]edid-decode/parse-displayid-block.cpp
// Function: edid_state::parse_displayid_type_1_7_timing(unsigned char const*, bool, unsigned int, bool)
void edid_state::parse_displayid_type_1_7_timing(const unsigned char *x,
						 bool type7, unsigned block_rev, bool is_cta)
{
	struct timings t = {};
	unsigned hbl, vbl;
	std::string s("aspect ");

	dispid.has_type_1_7 = true;
	t.pixclk_khz = (type7 ? 1 : 10) * (1 + (x[0] + (x[1] << 8) + (x[2] << 16)));
	switch (x[3] & 0xf) {
	case 0:
		s += "1:1";
		t.hratio = t.vratio = 1;
		break;
	case 1:
		s += "5:4";
		t.hratio = 5;
		t.vratio = 4;
		break;
	case 2:
		s += "4:3";
		t.hratio = 4;
		t.vratio = 3;
		break;
	case 3:
		s += "15:9";
		t.hratio = 15;
		t.vratio = 9;
		break;
	case 4:
		s += "16:9";
		t.hratio = 16;
		t.vratio = 9;
		break;
	case 5:
		s += "16:10";
		t.hratio = 16;
		t.vratio = 10;
		break;
	case 6:
		s += "64:27";
		t.hratio = 64;
		t.vratio = 27;
		break;
	case 7:
		s += "256:135";
		t.hratio = 256;
		t.vratio = 135;
		break;
	default:
		s += "undefined";
		if ((x[3] & 0xf) > (dispid.version <= 0x12 ? 7 : 8))
			fail("Unknown aspect 0x%02x.\n", x[3] & 0xf);
		break;
	}
	switch ((x[3] >> 5) & 0x3) {
	case 0:
		s += ", no 3D stereo";
		break;
	case 1:
		s += ", 3D stereo";
		break;
	case 2:
		s += ", 3D stereo depends on user action";
		break;
	case 3:
		s += ", reserved";
		fail("Reserved stereo 0x03.\n");
		break;
	}
	if (block_rev >= 2 && (x[3] & 0x80))
		s += ", YCbCr 4:2:0";

	t.hact = 1 + (x[4] | (x[5] << 8));
	hbl = 1 + (x[6] | (x[7] << 8));
	t.hfp = 1 + (x[8] | ((x[9] & 0x7f) << 8));
	t.hsync = 1 + (x[10] | (x[11] << 8));
	t.hbp = hbl - t.hfp - t.hsync;
	if ((x[9] >> 7) & 0x1)
		t.pos_pol_hsync = true;
	t.vact = 1 + (x[12] | (x[13] << 8));
	vbl = 1 + (x[14] | (x[15] << 8));
	t.vfp = 1 + (x[16] | ((x[17] & 0x7f) << 8));
	t.vsync = 1 + (x[18] | (x[19] << 8));
	t.vbp = vbl - t.vfp - t.vsync;
	if ((x[17] >> 7) & 0x1)
		t.pos_pol_vsync = true;

	if (x[3] & 0x10) {
		t.interlaced = true;
		t.vfp /= 2;
		t.vsync /= 2;
		t.vbp /= 2;
	}
	if (block_rev < 2 && (x[3] & 0x80)) {
		s += ", preferred";
		dispid.preferred_timings.push_back(timings_ext(t, "DTD", s));
	}

	print_timings("    ", &t, "DTD", s.c_str(), true);
	if (is_cta) {
		timings_ext te(t, "DTD", s);
		cta.vec_vtdbs.push_back(te);

		// Only use a T7VTDB if is cannot be expressed by a
		// DTD or a T10VTDB.
		if (t.hact <= 4095 && t.vact <= 4095 &&
		    t.pixclk_khz <= 655360 && !(x[3] & 0xe0)) {
			fail("This T7VTDB can be represented as an 18-byte DTD.\n");
			return;
		}
		unsigned htot = t.hact + t.hfp + t.hsync + t.hbp;
		unsigned vtot = t.vact + t.vfp + t.vsync + t.vbp;
		unsigned refresh = (t.pixclk_khz * 1000ULL) / (htot * vtot);

		for (unsigned rb = RB_NONE; rb <= RB_CVT_V3; rb++) {
			timings cvt_t = calc_cvt_mode(t.hact, t.vact, refresh, rb);
			if (match_timings(t, cvt_t)) {
				fail("This T7VTDB can be represented as a T10VTDB.\n");
				return;
			}
		}
		timings cvt_t = calc_cvt_mode(t.hact, t.vact, refresh, RB_CVT_V3,
					      false, false, true);
		if (match_timings(t, cvt_t))
			fail("This T7VTDB can be represented as a T10VTDB.\n");
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x178, %rsp            # imm = 0x178
movl %r8d, %ebp
movl %ecx, %r15d
movl %edx, %r12d
movq %rsi, %r14
movq %rdi, %rbx
xorpd %xmm0, %xmm0
movapd %xmm0, 0x60(%rsp)
movapd %xmm0, 0x50(%rsp)
movapd %xmm0, 0x40(%rsp)
movapd %xmm0, 0x30(%rsp)
movapd %xmm0, 0x20(%rsp)
movl $0x0, 0x70(%rsp)
leaq 0x10(%rsp), %r13
movq %r13, -0x10(%r13)
leaq 0x18725(%rip), %rsi     # 0x2ee49
leaq 0x18725(%rip), %rdx     # 0x2ee50
movq %rsp, %rdi
callq 0x8d58
movb $0x1, 0x920(%rbx)
xorb $0x1, %r12b
movzbl %r12b, %eax
leal (%rax,%rax,8), %eax
incl %eax
movzwl (%r14), %ecx
movzbl 0x2(%r14), %edx
shll $0x10, %edx
addl %edx, %ecx
incl %ecx
imull %eax, %ecx
movl %ecx, 0x30(%rsp)
movzbl 0x3(%r14), %eax
andl $0xf, %eax
cmpl $0x7, %eax
ja 0x16d0a
leaq 0x17ee2(%rip), %rcx     # 0x2e658
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x186cb(%rip), %rsi     # 0x2ee51
movq %rsp, %rdi
callq 0x3420
leaq 0x2c(%rsp), %rax
movl $0x1, %edx
leaq 0x28(%rsp), %rsi
movl $0x1, %ecx
jmp 0x1688b
leaq 0xe4d1(%rip), %rsi      # 0x24c7f
movq %rsp, %rdi
callq 0x3420
leaq 0x28(%rsp), %rax
movl $0x9, %ecx
jmp 0x16861
leaq 0xe4ae(%rip), %rsi      # 0x24c7a
movq %rsp, %rdi
callq 0x3420
leaq 0x28(%rsp), %rax
movl $0x3, %ecx
movl $0x4, %edx
jmp 0x16886
leaq 0xe4a2(%rip), %rsi      # 0x24c91
movq %rsp, %rdi
callq 0x3420
leaq 0x28(%rsp), %rax
movl $0x9, %ecx
movl $0xf, %edx
jmp 0x16886
leaq 0x1864c(%rip), %rsi     # 0x2ee5b
movq %rsp, %rdi
callq 0x3420
leaq 0x28(%rsp), %rax
movl $0x87, %ecx
movl $0x100, %edx            # imm = 0x100
jmp 0x16886
leaq 0xe45d(%rip), %rsi      # 0x24c8c
movq %rsp, %rdi
callq 0x3420
leaq 0x28(%rsp), %rax
movl $0x4, %ecx
movl $0x5, %edx
jmp 0x16886
leaq 0xe436(%rip), %rsi      # 0x24c85
movq %rsp, %rdi
callq 0x3420
leaq 0x28(%rsp), %rax
movl $0xa, %ecx
movl $0x10, %edx
jmp 0x16886
leaq 0x185e6(%rip), %rsi     # 0x2ee55
movq %rsp, %rdi
callq 0x3420
leaq 0x28(%rsp), %rax
movl $0x1b, %ecx
movl $0x40, %edx
leaq 0x2c(%rsp), %rsi
movl %edx, (%rax)
movl %ecx, (%rsi)
movzbl 0x3(%r14), %eax
shrl $0x5, %eax
andl $0x3, %eax
leaq 0x17dd7(%rip), %rcx     # 0x2e678
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x185ca(%rip), %rsi     # 0x2ee7b
jmp 0x168e4
leaq 0x185dc(%rip), %rsi     # 0x2ee96
jmp 0x168e4
leaq 0x13ce4(%rip), %rsi     # 0x2a5a7
movq %rsp, %rdi
callq 0x3420
leaq 0x185e7(%rip), %rsi     # 0x2eeb9
xorl %edi, %edi
xorl %eax, %eax
callq 0x37cc
jmp 0x168ec
leaq 0x185a6(%rip), %rsi     # 0x2ee8a
movq %rsp, %rdi
callq 0x3420
cmpl $0x2, %r15d
jb 0x16908
cmpb $0x0, 0x3(%r14)
jns 0x16908
leaq 0x185d0(%rip), %rsi     # 0x2eed0
movq %rsp, %rdi
callq 0x3420
movzwl 0x4(%r14), %eax
incl %eax
movl %eax, 0x20(%rsp)
movzwl 0x6(%r14), %eax
movzbl 0x8(%r14), %ecx
movzbl 0x9(%r14), %edx
movl %edx, %esi
andl $0x7f, %esi
shll $0x8, %esi
leal (%rcx,%rsi), %edi
incl %edi
orl %esi, %ecx
movl %edi, 0x3c(%rsp)
movzwl 0xa(%r14), %esi
leal 0x1(%rsi), %edi
movl %edi, 0x40(%rsp)
addl %esi, %ecx
incl %ecx
subl %ecx, %eax
movl %eax, 0x44(%rsp)
testb %dl, %dl
jns 0x16954
movb $0x1, 0x48(%rsp)
movzwl 0xc(%r14), %eax
incl %eax
movl %eax, 0x24(%rsp)
movzwl 0xe(%r14), %eax
movzbl 0x10(%r14), %edx
movzbl 0x11(%r14), %esi
movl %esi, %edi
andl $0x7f, %edi
shll $0x8, %edi
leal (%rdx,%rdi), %ecx
incl %ecx
movl %edx, %r8d
orl %edi, %r8d
movl %ecx, 0x4c(%rsp)
movzwl 0x12(%r14), %edi
leal 0x1(%rdi), %edx
movl %edx, 0x50(%rsp)
addl %r8d, %edi
incl %edi
subl %edi, %eax
movl %eax, 0x54(%rsp)
testb %sil, %sil
jns 0x169a6
movb $0x1, 0x58(%rsp)
movb 0x3(%r14), %sil
testb $0x10, %sil
je 0x169ce
movb $0x1, 0x38(%rsp)
shrl %ecx
movl %ecx, 0x4c(%rsp)
shrl %edx
movl %edx, 0x50(%rsp)
movl %eax, %ecx
shrl $0x1f, %ecx
addl %eax, %ecx
sarl %ecx
movl %ecx, 0x54(%rsp)
cmpl $0x2, %r15d
setae %al
testb %sil, %sil
setns %cl
orb %al, %cl
jne 0x16aa9
leaq 0x184f4(%rip), %rsi     # 0x2eede
movq %rsp, %rdi
callq 0x3420
leaq 0x98(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x98b8(%rip), %rsi      # 0x202bd
leaq 0x98b4(%rip), %rdx      # 0x202c0
leaq 0x88(%rsp), %rdi
callq 0x8d58
leaq 0xe0(%rsp), %rdi
leaq 0x20(%rsp), %rsi
leaq 0x88(%rsp), %rdx
movq %rsp, %rcx
callq 0xdb20
leaq 0x928(%rbx), %rdi
leaq 0xe0(%rsp), %rsi
callq 0x15ede
leaq 0x168(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x16a6b
movq 0x168(%rsp), %rsi
incq %rsi
callq 0x3260
leaq 0x148(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x16a8c
movq 0x148(%rsp), %rsi
incq %rsi
callq 0x3260
movq 0x88(%rsp), %rdi
cmpq %r15, %rdi
je 0x16aa9
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x3260
movq (%rsp), %r8
subq $0x8, %rsp
leaq 0xe9df(%rip), %rsi      # 0x25497
leaq 0x97fe(%rip), %rcx      # 0x202bd
leaq 0x28(%rsp), %rdx
movq %rbx, %rdi
movl $0x1, %r9d
pushq $0x1
callq 0x3e8c
addq $0x10, %rsp
testb %bpl, %bpl
je 0x16ce2
leaq 0x98(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x97c9(%rip), %rsi      # 0x202bd
leaq 0x97c5(%rip), %rdx      # 0x202c0
leaq 0x88(%rsp), %rdi
callq 0x8d58
leaq 0xe0(%rsp), %rdi
leaq 0x20(%rsp), %rsi
leaq 0x88(%rsp), %rdx
movq %rsp, %rcx
callq 0xdb20
movq 0x88(%rsp), %rdi
cmpq %r15, %rdi
je 0x16b42
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x3260
leaq 0x1a8(%rbx), %rdi
leaq 0xe0(%rsp), %rsi
callq 0xdbb0
movl 0x20(%rsp), %eax
movl 0x24(%rsp), %ecx
movl $0x1000, %edx           # imm = 0x1000
cmpl %edx, %eax
setb %sil
cmpl %edx, %ecx
setb %dil
andb %sil, %dil
movl 0x30(%rsp), %edx
cmpl $0xa0001, %edx          # imm = 0xA0001
setb %sil
andb %dil, %sil
cmpb $0x1, %sil
jne 0x16ba5
cmpb $0x1f, 0x3(%r14)
ja 0x16ba5
leaq 0x18353(%rip), %rsi     # 0x2eeea
xorl %edi, %edi
xorl %eax, %eax
callq 0x37cc
jmp 0x16ca0
movl %edx, %edx
leaq 0x20(%rsp), %r14
addl 0x1c(%r14), %eax
addl 0x20(%r14), %eax
addl 0x24(%r14), %eax
addl 0x2c(%r14), %ecx
addl 0x30(%r14), %ecx
addl 0x34(%r14), %ecx
imull %eax, %ecx
imulq $0x3e8, %rdx, %rax      # imm = 0x3E8
xorl %r12d, %r12d
xorl %edx, %edx
divq %rcx
movl %eax, %eax
cvtsi2sd %rax, %xmm0
movsd %xmm0, 0x80(%rsp)
leaq 0x88(%rsp), %r15
xorl %ebp, %ebp
movl 0x20(%rsp), %edx
movl 0x24(%rsp), %ecx
movq %r15, %rdi
movq %rbx, %rsi
movsd 0x80(%rsp), %xmm0
movl %ebp, %r8d
xorl %r9d, %r9d
pushq %r12
pushq %r12
callq 0x1f362
addq $0x10, %rsp
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x3d40
testb %al, %al
jne 0x16c90
incl %ebp
cmpl $0x4, %ebp
jne 0x16bf0
movl 0x20(%rsp), %edx
movl 0x24(%rsp), %ecx
leaq 0x88(%rsp), %rdi
movq %rbx, %rsi
movsd 0x80(%rsp), %xmm0
movl $0x3, %r8d
xorl %r9d, %r9d
pushq $0x1
pushq $0x0
callq 0x1f362
addq $0x10, %rsp
leaq 0x20(%rsp), %rsi
leaq 0x88(%rsp), %rdx
movq %rbx, %rdi
callq 0x3d40
testb %al, %al
je 0x16ca0
leaq 0x18298(%rip), %rsi     # 0x2ef1d
xorl %edi, %edi
xorl %eax, %eax
callq 0x37cc
jmp 0x16ca0
leaq 0x18286(%rip), %rsi     # 0x2ef1d
xorl %edi, %edi
xorl %eax, %eax
callq 0x37cc
leaq 0x168(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x16cc1
movq 0x168(%rsp), %rsi
incq %rsi
callq 0x3260
leaq 0x148(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x16ce2
movq 0x148(%rsp), %rsi
incq %rsi
callq 0x3260
movq (%rsp), %rdi
cmpq %r13, %rdi
je 0x16cf8
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x3260
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xf93d(%rip), %rsi      # 0x2664e
movq %rsp, %rdi
callq 0x3420
movzbl 0x3(%r14), %edx
andl $0xf, %edx
cmpb $0x13, 0x910(%rbx)
movl $0x8, %eax
sbbl $0x0, %eax
cmpl %edx, %eax
jae 0x1688f
leaq 0x18124(%rip), %rsi     # 0x2ee63
xorl %edi, %edi
xorl %eax, %eax
callq 0x37cc
jmp 0x1688f
jmp 0x16d92
jmp 0x16d92
jmp 0x16d67
jmp 0x16d8d
movq %rax, %rbx
leaq 0xe0(%rsp), %rdi
callq 0xdbdc
jmp 0x16d6a
movq %rax, %rbx
movq 0x88(%rsp), %rdi
cmpq %r15, %rdi
je 0x16da2
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x3260
jmp 0x16da2
jmp 0x16d8d
jmp 0x16d92
movq %rax, %rbx
jmp 0x16da2
movq %rax, %rbx
leaq 0xe0(%rsp), %rdi
callq 0xdbdc
movq (%rsp), %rdi
cmpq %r13, %rdi
je 0x16db8
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x3260
movq %rbx, %rdi
callq 0x3400