// File: /workspace/github_cpp_makefile_star2_O1/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), %rax
movq %rax, -0x10(%rax)
leaq 0x18581(%rip), %rsi     # 0x2ee09
leaq 0x18581(%rip), %rdx     # 0x2ee10
movq %rsp, %rdi
callq 0x8f6e
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 0x16e70
leaq 0x17d56(%rip), %rcx     # 0x2e630
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x18527(%rip), %rsi     # 0x2ee11
movq %rsp, %rdi
callq 0x3420
leaq 0x2c(%rsp), %rax
movl $0x1, %edx
leaq 0x28(%rsp), %rsi
movl $0x1, %ecx
jmp 0x169ef
leaq 0xe31d(%rip), %rsi      # 0x24c2f
movq %rsp, %rdi
callq 0x3420
leaq 0x28(%rsp), %rax
movl $0x9, %ecx
jmp 0x169c5
leaq 0xe2fa(%rip), %rsi      # 0x24c2a
movq %rsp, %rdi
callq 0x3420
leaq 0x28(%rsp), %rax
movl $0x3, %ecx
movl $0x4, %edx
jmp 0x169ea
leaq 0xe2ee(%rip), %rsi      # 0x24c41
movq %rsp, %rdi
callq 0x3420
leaq 0x28(%rsp), %rax
movl $0x9, %ecx
movl $0xf, %edx
jmp 0x169ea
leaq 0x184a8(%rip), %rsi     # 0x2ee1b
movq %rsp, %rdi
callq 0x3420
leaq 0x28(%rsp), %rax
movl $0x87, %ecx
movl $0x100, %edx            # imm = 0x100
jmp 0x169ea
leaq 0xe2a9(%rip), %rsi      # 0x24c3c
movq %rsp, %rdi
callq 0x3420
leaq 0x28(%rsp), %rax
movl $0x4, %ecx
movl $0x5, %edx
jmp 0x169ea
leaq 0xe282(%rip), %rsi      # 0x24c35
movq %rsp, %rdi
callq 0x3420
leaq 0x28(%rsp), %rax
movl $0xa, %ecx
movl $0x10, %edx
jmp 0x169ea
leaq 0x18442(%rip), %rsi     # 0x2ee15
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 0x17c4b(%rip), %rcx     # 0x2e650
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x18426(%rip), %rsi     # 0x2ee3b
jmp 0x16a48
leaq 0x18438(%rip), %rsi     # 0x2ee56
jmp 0x16a48
leaq 0x13b58(%rip), %rsi     # 0x2a57f
movq %rsp, %rdi
callq 0x3420
leaq 0x18443(%rip), %rsi     # 0x2ee79
xorl %edi, %edi
xorl %eax, %eax
callq 0x37ec
jmp 0x16a50
leaq 0x18402(%rip), %rsi     # 0x2ee4a
movq %rsp, %rdi
callq 0x3420
cmpl $0x2, %r15d
jb 0x16a6c
cmpb $0x0, 0x3(%r14)
jns 0x16a6c
leaq 0x1842c(%rip), %rsi     # 0x2ee90
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
addl %esi, %ecx
incl %ecx
movl %ecx, 0x3c(%rsp)
movzwl 0xa(%r14), %esi
leal 0x1(%rsi), %edi
movl %edi, 0x40(%rsp)
subl %ecx, %eax
subl %esi, %eax
movl %eax, 0x44(%rsp)
testb %dl, %dl
jns 0x16ab3
movb $0x1, 0x48(%rsp)
movzwl 0xc(%r14), %eax
incl %eax
movl %eax, 0x24(%rsp)
movzwl 0xe(%r14), %eax
movzbl 0x10(%r14), %ecx
movzbl 0x11(%r14), %esi
movl %esi, %edx
andl $0x7f, %edx
shll $0x8, %edx
addl %edx, %ecx
incl %ecx
movl %ecx, 0x4c(%rsp)
movzwl 0x12(%r14), %edi
leal 0x1(%rdi), %edx
movl %edx, 0x50(%rsp)
subl %ecx, %eax
subl %edi, %eax
movl %eax, 0x54(%rsp)
testb %sil, %sil
jns 0x16afb
movb $0x1, 0x58(%rsp)
movb 0x3(%r14), %sil
testb $0x10, %sil
je 0x16b23
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 0x16bfe
leaq 0x1835f(%rip), %rsi     # 0x2ee9e
movq %rsp, %rdi
callq 0x3420
leaq 0x98(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x9753(%rip), %rsi      # 0x202ad
leaq 0x974f(%rip), %rdx      # 0x202b0
leaq 0x88(%rsp), %rdi
callq 0x8f6e
leaq 0xe0(%rsp), %rdi
leaq 0x20(%rsp), %rsi
leaq 0x88(%rsp), %rdx
movq %rsp, %rcx
callq 0xdce2
leaq 0x928(%rbx), %rdi
leaq 0xe0(%rsp), %rsi
callq 0x16042
leaq 0x168(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x16bc0
movq 0x168(%rsp), %rsi
incq %rsi
callq 0x3260
leaq 0x148(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x16be1
movq 0x148(%rsp), %rsi
incq %rsi
callq 0x3260
movq 0x88(%rsp), %rdi
cmpq %r15, %rdi
je 0x16bfe
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x3260
movq (%rsp), %r8
subq $0x8, %rsp
leaq 0xe83a(%rip), %rsi      # 0x25447
leaq 0x9699(%rip), %rcx      # 0x202ad
leaq 0x28(%rsp), %rdx
movq %rbx, %rdi
movl $0x1, %r9d
pushq $0x1
callq 0x3ebe
addq $0x10, %rsp
testb %bpl, %bpl
je 0x16e43
leaq 0x98(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x9664(%rip), %rsi      # 0x202ad
leaq 0x9660(%rip), %rdx      # 0x202b0
leaq 0x88(%rsp), %rdi
callq 0x8f6e
leaq 0xe0(%rsp), %rdi
leaq 0x20(%rsp), %rsi
leaq 0x88(%rsp), %rdx
movq %rsp, %rcx
callq 0xdce2
movq 0x88(%rsp), %rdi
cmpq %r15, %rdi
je 0x16c97
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x3260
leaq 0x1a8(%rbx), %rdi
leaq 0xe0(%rsp), %rsi
callq 0xdd72
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 0x16cfa
cmpb $0x1f, 0x3(%r14)
ja 0x16cfa
leaq 0x181be(%rip), %rsi     # 0x2eeaa
xorl %edi, %edi
xorl %eax, %eax
callq 0x37ec
jmp 0x16e01
leaq 0x20(%rsp), %r14
addl 0x1c(%r14), %eax
addl 0x20(%r14), %eax
addl 0x24(%r14), %eax
addl 0x2c(%r14), %ecx
addl 0x30(%r14), %ecx
movl %edx, %edx
addl 0x34(%r14), %ecx
imull %eax, %ecx
imulq $0x3e8, %rdx, %rax      # imm = 0x3E8
xorl %edx, %edx
divq %rcx
movl %eax, %eax
movq %rax, 0x78(%rsp)
cvtsi2sd %rax, %xmm0
movsd %xmm0, 0x80(%rsp)
xorl %r12d, %r12d
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 0x1f728
addq $0x10, %rsp
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x3d6a
movl %eax, %r13d
testb %al, %al
je 0x16d9e
xorl %edi, %edi
leaq 0x1814b(%rip), %rsi     # 0x2eedd
xorl %eax, %eax
callq 0x37ec
testb %r13b, %r13b
jne 0x16e01
incl %ebp
cmpl $0x4, %ebp
jne 0x16d4a
movl 0x20(%rsp), %edx
movl 0x24(%rsp), %ecx
xorps %xmm0, %xmm0
cvtsi2sdq 0x78(%rsp), %xmm0
leaq 0x88(%rsp), %rdi
movq %rbx, %rsi
movl $0x3, %r8d
xorl %r9d, %r9d
pushq $0x1
pushq $0x0
callq 0x1f728
addq $0x10, %rsp
leaq 0x20(%rsp), %rsi
leaq 0x88(%rsp), %rdx
movq %rbx, %rdi
callq 0x3d6a
testb %al, %al
je 0x16e01
leaq 0x180e5(%rip), %rsi     # 0x2eedd
xorl %edi, %edi
xorl %eax, %eax
callq 0x37ec
leaq 0x168(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x16e22
movq 0x168(%rsp), %rsi
incq %rsi
callq 0x3260
leaq 0x148(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x16e43
movq 0x148(%rsp), %rsi
incq %rsi
callq 0x3260
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x16e5e
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 0xf787(%rip), %rsi      # 0x265fe
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 0x169f3
leaq 0x17f7e(%rip), %rsi     # 0x2ee23
xorl %edi, %edi
xorl %eax, %eax
callq 0x37ec
jmp 0x169f3
jmp 0x16ec9
jmp 0x16ef1
movq %rax, %rbx
leaq 0xe0(%rsp), %rdi
callq 0xdd9e
jmp 0x16ecc
movq %rax, %rbx
movq 0x88(%rsp), %rdi
cmpq %r15, %rdi
je 0x16f06
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x3260
jmp 0x16f06
jmp 0x16ef1
jmp 0x16ef6
jmp 0x16ef6
movq %rax, %rbx
jmp 0x16f06
movq %rax, %rbx
leaq 0xe0(%rsp), %rdi
callq 0xdd9e
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x16f21
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x3260
movq %rbx, %rdi
callq 0x3400
nop