// File: /workspace/github_cpp_makefile_star2_O2/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 $0x198, %rsp            # imm = 0x198
movl %r8d, 0x4c(%rsp)
movl %ecx, 0x20(%rsp)
movl %edx, %r12d
movq %rsi, %r14
movq %rdi, %rbx
xorpd %xmm0, %xmm0
movapd %xmm0, 0x90(%rsp)
movapd %xmm0, 0x80(%rsp)
movapd %xmm0, 0x70(%rsp)
movapd %xmm0, 0x60(%rsp)
movapd %xmm0, 0x50(%rsp)
andl $0x0, 0xa0(%rsp)
leaq 0x16495(%rip), %rsi     # 0x28e49
leaq 0x28(%rsp), %rdi
leaq 0x100(%rsp), %rdx
callq 0x75c4
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, 0x60(%rsp)
movzbl 0x3(%r14), %eax
andl $0xf, %eax
cmpl $0x7, %eax
ja 0x12ed3
leaq 0x15c57(%rip), %rcx     # 0x28660
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
leaq 0x58(%rsp), %r12
leaq 0x5c(%rsp), %r13
pushq $0x10
popq %rbp
pushq $0x9
popq %r15
jmpq *%rax
leaq 0x16427(%rip), %rsi     # 0x28e51
leaq 0x28(%rsp), %rdi
callq 0x3450
leaq 0x5c(%rsp), %r12
pushq $0x1
popq %rbp
leaq 0x58(%rsp), %r13
movl %ebp, %r15d
jmp 0x12af2
leaq 0xc22f(%rip), %rsi      # 0x1ec7f
leaq 0x28(%rsp), %rdi
callq 0x3450
jmp 0x12af2
leaq 0xc214(%rip), %rsi      # 0x1ec7a
leaq 0x28(%rsp), %rdi
callq 0x3450
pushq $0x4
popq %rbp
pushq $0x3
jmp 0x12ad6
leaq 0xc213(%rip), %rsi      # 0x1ec91
leaq 0x28(%rsp), %rdi
callq 0x3450
pushq $0xf
jmp 0x12af1
leaq 0x163c8(%rip), %rsi     # 0x28e5b
leaq 0x28(%rsp), %rdi
callq 0x3450
movl $0x87, %r15d
movl $0x100, %ebp            # imm = 0x100
jmp 0x12af2
leaq 0xc1db(%rip), %rsi      # 0x1ec8c
leaq 0x28(%rsp), %rdi
callq 0x3450
pushq $0x4
popq %r15
pushq $0x5
jmp 0x12af1
leaq 0xc1bb(%rip), %rsi      # 0x1ec85
leaq 0x28(%rsp), %rdi
callq 0x3450
pushq $0xa
popq %r15
jmp 0x12af2
leaq 0x16374(%rip), %rsi     # 0x28e55
leaq 0x28(%rsp), %rdi
callq 0x3450
pushq $0x1b
popq %r15
pushq $0x40
popq %rbp
movl %ebp, (%r12)
movl %r15d, (%r13)
movzbl 0x3(%r14), %eax
shrl $0x5, %eax
andl $0x3, %eax
leaq 0x15b74(%rip), %rcx     # 0x28680
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x1635f(%rip), %rsi     # 0x28e7b
jmp 0x12b51
leaq 0x16371(%rip), %rsi     # 0x28e96
jmp 0x12b51
leaq 0x11a79(%rip), %rsi     # 0x245a7
leaq 0x28(%rsp), %rdi
callq 0x3450
leaq 0x1637a(%rip), %rsi     # 0x28eb9
xorl %edi, %edi
xorl %eax, %eax
callq 0x362c
jmp 0x12b5b
leaq 0x16339(%rip), %rsi     # 0x28e8a
leaq 0x28(%rsp), %rdi
callq 0x3450
cmpl $0x2, 0x20(%rsp)
jb 0x12b7a
cmpb $0x0, 0x3(%r14)
jns 0x12b7a
leaq 0x16360(%rip), %rsi     # 0x28ed0
leaq 0x28(%rsp), %rdi
callq 0x3450
movzwl 0x4(%r14), %eax
incl %eax
movl %eax, 0x50(%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, 0x6c(%rsp)
movzwl 0xa(%r14), %esi
leal 0x1(%rsi), %edi
movl %edi, 0x70(%rsp)
addl %esi, %ecx
incl %ecx
subl %ecx, %eax
movl %eax, 0x74(%rsp)
testb %dl, %dl
jns 0x12bc6
movb $0x1, 0x78(%rsp)
movzwl 0xc(%r14), %eax
incl %eax
movl %eax, 0x54(%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, 0x7c(%rsp)
movzwl 0x12(%r14), %edi
leal 0x1(%rdi), %edx
movl %edx, 0x80(%rsp)
addl %r8d, %edi
incl %edi
subl %edi, %eax
movl %eax, 0x84(%rsp)
testb %sil, %sil
jns 0x12c21
movb $0x1, 0x88(%rsp)
movb 0x3(%r14), %sil
testb $0x10, %sil
je 0x12c4c
movb $0x1, 0x68(%rsp)
shrl %ecx
movl %ecx, 0x7c(%rsp)
shrl %edx
movl %edx, 0x80(%rsp)
pushq $0x2
popq %rcx
cltd
idivl %ecx
movl %eax, 0x84(%rsp)
cmpl $0x2, 0x20(%rsp)
setae %al
testb %sil, %sil
setns %cl
orb %al, %cl
jne 0x12cd5
leaq 0x16279(%rip), %rsi     # 0x28ede
leaq 0x28(%rsp), %rdi
callq 0x3450
leaq 0x7647(%rip), %rsi      # 0x1a2bd
leaq 0xa8(%rsp), %rdi
leaq 0x1f(%rsp), %rdx
callq 0x75c4
leaq 0x100(%rsp), %rdi
leaq 0x50(%rsp), %rsi
leaq 0xa8(%rsp), %rdx
leaq 0x28(%rsp), %rcx
callq 0xbb34
leaq 0x928(%rbx), %rdi
leaq 0x100(%rsp), %rsi
callq 0x120e8
leaq 0x100(%rsp), %rdi
callq 0x78cc
leaq 0xa8(%rsp), %rdi
callq 0x3130
movq 0x28(%rsp), %r8
movl $0x1, (%rsp)
leaq 0xc7af(%rip), %rsi      # 0x1f497
leaq 0x75ce(%rip), %rcx      # 0x1a2bd
leaq 0x50(%rsp), %rdx
pushq $0x1
popq %r9
movq %rbx, %rdi
callq 0x3af0
cmpb $0x0, 0x4c(%rsp)
je 0x12eb7
leaq 0x75ab(%rip), %rsi      # 0x1a2bd
leaq 0xa8(%rsp), %rdi
leaq 0x1f(%rsp), %rdx
callq 0x75c4
leaq 0x100(%rsp), %rdi
leaq 0x50(%rsp), %rsi
leaq 0xa8(%rsp), %rdx
leaq 0x28(%rsp), %rcx
callq 0xbb34
leaq 0xa8(%rsp), %rdi
callq 0x3130
leaq 0x1a8(%rbx), %rdi
leaq 0x100(%rsp), %rsi
callq 0xbbe4
movl 0x50(%rsp), %eax
movl 0x54(%rsp), %ecx
movl $0x1000, %edx           # imm = 0x1000
cmpl %edx, %eax
setb %sil
cmpl %edx, %ecx
setb %dil
andb %sil, %dil
movl 0x60(%rsp), %edx
cmpl $0xa0001, %edx          # imm = 0xA0001
setb %sil
andb %dil, %sil
cmpb $0x1, %sil
jne 0x12db3
cmpb $0x1f, 0x3(%r14)
ja 0x12db3
leaq 0x16145(%rip), %rsi     # 0x28eea
xorl %edi, %edi
xorl %eax, %eax
callq 0x362c
jmp 0x12eaa
leaq 0x50(%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
movl %edx, %edx
imull %eax, %ecx
imulq $0x3e8, %rdx, %rax      # imm = 0x3E8
xorl %r15d, %r15d
xorl %edx, %edx
divq %rcx
movl %eax, %eax
cvtsi2sd %rax, %xmm0
movsd %xmm0, 0x20(%rsp)
leaq 0xa8(%rsp), %r12
cmpl $0x4, %r15d
je 0x12e3e
movl 0x50(%rsp), %edx
movl 0x54(%rsp), %ecx
andl $0x0, 0x8(%rsp)
andl $0x0, (%rsp)
movq %r12, %rdi
movq %rbx, %rsi
movsd 0x20(%rsp), %xmm0
movl %r15d, %r8d
xorl %r9d, %r9d
callq 0x1984c
movq %rbx, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x39a6
testb %al, %al
jne 0x12e9a
incl %r15d
jmp 0x12df9
movl 0x50(%rsp), %edx
movl 0x54(%rsp), %ecx
movl $0x1, 0x8(%rsp)
andl $0x0, (%rsp)
leaq 0xa8(%rsp), %rdi
pushq $0x3
popq %r8
movq %rbx, %rsi
movsd 0x20(%rsp), %xmm0
xorl %r9d, %r9d
callq 0x1984c
leaq 0x50(%rsp), %rsi
leaq 0xa8(%rsp), %rdx
movq %rbx, %rdi
callq 0x39a6
testb %al, %al
je 0x12eaa
leaq 0x1608e(%rip), %rsi     # 0x28f1d
xorl %edi, %edi
xorl %eax, %eax
callq 0x362c
jmp 0x12eaa
leaq 0x1607c(%rip), %rsi     # 0x28f1d
xorl %edi, %edi
xorl %eax, %eax
callq 0x362c
leaq 0x100(%rsp), %rdi
callq 0x78cc
leaq 0x28(%rsp), %rdi
callq 0x3130
addq $0x198, %rsp            # imm = 0x198
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xd774(%rip), %rsi      # 0x2064e
leaq 0x28(%rsp), %rdi
callq 0x3450
movzbl 0x3(%r14), %edx
andl $0xf, %edx
cmpb $0x13, 0x910(%rbx)
pushq $0x8
popq %rax
sbbl $0x0, %eax
cmpl %edx, %eax
jae 0x12afa
leaq 0x15f5b(%rip), %rsi     # 0x28e63
xorl %edi, %edi
xorl %eax, %eax
callq 0x362c
jmp 0x12afa
jmp 0x12f4b
jmp 0x12f4b
jmp 0x12f30
jmp 0x12f46
movq %rax, %rbx
leaq 0x100(%rsp), %rdi
callq 0x78cc
jmp 0x12f33
movq %rax, %rbx
leaq 0xa8(%rsp), %rdi
callq 0x3130
jmp 0x12f5b
jmp 0x12f46
jmp 0x12f4b
movq %rax, %rbx
jmp 0x12f5b
movq %rax, %rbx
leaq 0x100(%rsp), %rdi
callq 0x78cc
leaq 0x28(%rsp), %rdi
callq 0x3130
movq %rbx, %rdi
callq 0x3430
nop