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

	t.pixclk_khz = 10 * (1 + (x[0] + (x[1] << 8) + (x[2] << 16)));
	t.hact = 8 + 8 * (x[4] | ((x[5] & 0x01) << 8));
	hbl = 8 + 8 * ((x[5] & 0xfe) >> 1);
	t.hfp = 8 + 8 * ((x[6] & 0xf0) >> 4);
	t.hsync = 8 + 8 * (x[6] & 0xf);
	t.hbp = hbl - t.hfp - t.hsync;
	if ((x[3] >> 3) & 0x1)
		t.pos_pol_hsync = true;
	t.vact = 1 + (x[7] | ((x[8] & 0xf) << 8));
	vbl = 1 + x[9];
	t.vfp = 1 + (x[10] >> 4);
	t.vsync = 1 + (x[10] & 0xf);
	t.vbp = vbl - t.vfp - t.vsync;
	if ((x[17] >> 2) & 0x1)
		t.pos_pol_vsync = true;

	if (x[3] & 0x10) {
		t.interlaced = true;
		t.vfp /= 2;
		t.vsync /= 2;
		t.vbp /= 2;
	}

	calc_ratio(&t);

	s += std::to_string(t.hratio) + ":" + std::to_string(t.vratio);

	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 (x[3] & 0x80) {
		s += ", preferred";
		dispid.preferred_timings.push_back(timings_ext(t, "DTD", s));
	}

	print_timings("    ", &t, "DTD", s.c_str(), true);
}

// Assembly:
pushq %r14
pushq %rbx
subq $0x178, %rsp            # imm = 0x178
movq %rsi, %r14
movq %rdi, %rbx
xorps %xmm0, %xmm0
movups %xmm0, 0x50(%rsp)
movups %xmm0, 0x44(%rsp)
movups %xmm0, 0x34(%rsp)
movups %xmm0, 0x24(%rsp)
movups %xmm0, 0x14(%rsp)
leaq 0x15ea8(%rip), %rsi     # 0x28e49
leaq 0x60(%rsp), %rdi
leaq 0xe0(%rsp), %rdx
callq 0x75c4
movzwl (%r14), %eax
movzbl 0x2(%r14), %ecx
shll $0x10, %ecx
orl %eax, %ecx
imull $0xa, %ecx, %eax
addl $0xa, %eax
movl %eax, 0x1c(%rsp)
movzbl 0x4(%r14), %ecx
movzbl 0x5(%r14), %eax
movl %eax, %edx
andl $0x1, %edx
shll $0xb, %edx
leal (%rdx,%rcx,8), %ecx
addl $0x8, %ecx
movl %ecx, 0xc(%rsp)
andl $-0x2, %eax
shll $0x2, %eax
movzbl 0x6(%r14), %ecx
movl %ecx, %edx
shrl $0x4, %edx
leal 0x8(,%rdx,8), %esi
shll $0x3, %edx
movl %esi, 0x28(%rsp)
andl $0xf, %ecx
leal 0x8(,%rcx,8), %esi
movl %esi, 0x2c(%rsp)
leal (%rdx,%rcx,8), %ecx
addl $0x10, %ecx
subl %ecx, %eax
addl $0x8, %eax
movl %eax, 0x30(%rsp)
movb 0x3(%r14), %cl
testb $0x8, %cl
je 0x13030
movb $0x1, 0x34(%rsp)
movzbl 0x7(%r14), %eax
movzbl 0x8(%r14), %edx
andl $0xf, %edx
shll $0x8, %edx
addl %edx, %eax
incl %eax
movl %eax, 0x10(%rsp)
movzbl 0x9(%r14), %eax
movzbl 0xa(%r14), %edi
movl %edi, %r8d
shrl $0x4, %r8d
leal 0x1(%r8), %edx
movl %edx, 0x38(%rsp)
andl $0xf, %edi
leal 0x1(%rdi), %esi
movl %esi, 0x3c(%rsp)
addl %r8d, %edi
addl $0x2, %edi
negl %edi
addl %edi, %eax
incl %eax
movl %eax, 0x40(%rsp)
testb $0x4, 0x11(%r14)
je 0x13087
movb $0x1, 0x44(%rsp)
testb $0x10, %cl
je 0x130ab
movb $0x1, 0x24(%rsp)
shrl %edx
movl %edx, 0x38(%rsp)
shrl %esi
movl %esi, 0x3c(%rsp)
movw $0x2, %cx
cwtd
idivw %cx
cwtl
movl %eax, 0x40(%rsp)
leaq 0xc(%rsp), %rdi
callq 0x38fe
movl 0x14(%rsp), %esi
leaq 0xa0(%rsp), %rdi
callq 0x7675
leaq 0x7fc8(%rip), %rdx      # 0x1b095
leaq 0x80(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
callq 0x75a4
movl 0x18(%rsp), %esi
leaq 0xc0(%rsp), %rdi
callq 0x7675
leaq 0xe0(%rsp), %rdi
leaq 0x80(%rsp), %rsi
leaq 0xc0(%rsp), %rdx
callq 0x76b4
leaq 0x60(%rsp), %rdi
leaq 0xe0(%rsp), %rsi
callq 0x3480
leaq 0xe0(%rsp), %rdi
callq 0x3130
leaq 0xc0(%rsp), %rdi
callq 0x3130
leaq 0x80(%rsp), %rdi
callq 0x3130
leaq 0xa0(%rsp), %rdi
callq 0x3130
movzbl 0x3(%r14), %eax
shrl $0x5, %eax
andl $0x3, %eax
leaq 0x15528(%rip), %rcx     # 0x28690
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x15d03(%rip), %rsi     # 0x28e7b
jmp 0x131ad
leaq 0x15d15(%rip), %rsi     # 0x28e96
jmp 0x131ad
leaq 0x1141d(%rip), %rsi     # 0x245a7
leaq 0x60(%rsp), %rdi
callq 0x3450
leaq 0x15d1e(%rip), %rsi     # 0x28eb9
xorl %edi, %edi
xorl %eax, %eax
callq 0x362c
jmp 0x131b7
leaq 0x15cdd(%rip), %rsi     # 0x28e8a
leaq 0x60(%rsp), %rdi
callq 0x3450
cmpb $0x0, 0x3(%r14)
jns 0x13238
leaq 0x15d19(%rip), %rsi     # 0x28ede
leaq 0x60(%rsp), %rdi
callq 0x3450
leaq 0x70e7(%rip), %rsi      # 0x1a2bd
leaq 0x80(%rsp), %rdi
leaq 0xa0(%rsp), %rdx
callq 0x75c4
leaq 0xe0(%rsp), %rdi
leaq 0xc(%rsp), %rsi
leaq 0x80(%rsp), %rdx
leaq 0x60(%rsp), %rcx
callq 0xbb34
leaq 0x928(%rbx), %rdi
leaq 0xe0(%rsp), %rsi
callq 0x120e8
leaq 0xe0(%rsp), %rdi
callq 0x78cc
leaq 0x80(%rsp), %rdi
callq 0x3130
movq 0x60(%rsp), %r8
movl $0x1, (%rsp)
leaq 0xc24c(%rip), %rsi      # 0x1f497
leaq 0x706b(%rip), %rcx      # 0x1a2bd
leaq 0xc(%rsp), %rdx
pushq $0x1
popq %r9
movq %rbx, %rdi
callq 0x3af0
leaq 0x60(%rsp), %rdi
callq 0x3130
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r14
retq
movq %rax, %rbx
leaq 0xe0(%rsp), %rdi
callq 0x78cc
jmp 0x1328d
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
jmp 0x132da
jmp 0x132e3
movq %rax, %rbx
leaq 0xe0(%rsp), %rdi
callq 0x3130
jmp 0x132ae
movq %rax, %rbx
leaq 0xc0(%rsp), %rdi
callq 0x3130
jmp 0x132c0
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
callq 0x3130
jmp 0x132d2
movq %rax, %rbx
leaq 0xa0(%rsp), %rdi
callq 0x3130
jmp 0x132e6
jmp 0x132e3
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0x3130
movq %rbx, %rdi
callq 0x3430