// File: 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 %rbp
movq %rsp, %rbp
subq $0x220, %rsp            # imm = 0x220
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x200(%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, -0x30(%rbp)
movaps %xmm0, -0x40(%rbp)
movaps %xmm0, -0x50(%rbp)
movaps %xmm0, -0x60(%rbp)
movaps %xmm0, -0x70(%rbp)
movl $0x0, -0x20(%rbp)
leaq -0x99(%rbp), %rdi
movq %rdi, -0x1f8(%rbp)
callq 0x4560
movq -0x1f8(%rbp), %rdx
leaq 0x1b6d8(%rip), %rsi     # 0x3e4f5
leaq -0x98(%rbp), %rdi
callq 0xb510
jmp 0x22e2b
leaq -0x99(%rbp), %rdi
callq 0x4370
movq -0x10(%rbp), %rax
movzbl (%rax), %eax
movq -0x10(%rbp), %rcx
movzbl 0x1(%rcx), %ecx
shll $0x8, %ecx
addl %ecx, %eax
movq -0x10(%rbp), %rcx
movzbl 0x2(%rcx), %ecx
shll $0x10, %ecx
addl %ecx, %eax
addl $0x1, %eax
imull $0xa, %eax, %eax
movl %eax, -0x60(%rbp)
movq -0x10(%rbp), %rax
movzbl 0x4(%rax), %eax
movq -0x10(%rbp), %rcx
movzbl 0x5(%rcx), %ecx
andl $0x1, %ecx
shll $0x8, %ecx
orl %ecx, %eax
shll $0x3, %eax
addl $0x8, %eax
movl %eax, -0x70(%rbp)
movq -0x10(%rbp), %rax
movzbl 0x5(%rax), %eax
andl $0xfe, %eax
sarl %eax
shll $0x3, %eax
addl $0x8, %eax
movl %eax, -0x74(%rbp)
movq -0x10(%rbp), %rax
movzbl 0x6(%rax), %eax
andl $0xf0, %eax
sarl $0x4, %eax
shll $0x3, %eax
addl $0x8, %eax
movl %eax, -0x54(%rbp)
movq -0x10(%rbp), %rax
movzbl 0x6(%rax), %eax
andl $0xf, %eax
shll $0x3, %eax
addl $0x8, %eax
movl %eax, -0x50(%rbp)
movl -0x74(%rbp), %eax
subl -0x54(%rbp), %eax
subl -0x50(%rbp), %eax
movl %eax, -0x4c(%rbp)
movq -0x10(%rbp), %rax
movzbl 0x3(%rax), %eax
sarl $0x3, %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x22f0f
movb $0x1, -0x48(%rbp)
jmp 0x22f0f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa8(%rbp)
movl %eax, -0xac(%rbp)
leaq -0x99(%rbp), %rdi
callq 0x4370
jmp 0x23324
movq -0x10(%rbp), %rax
movzbl 0x7(%rax), %eax
movq -0x10(%rbp), %rcx
movzbl 0x8(%rcx), %ecx
andl $0xf, %ecx
shll $0x8, %ecx
orl %ecx, %eax
addl $0x1, %eax
movl %eax, -0x6c(%rbp)
movq -0x10(%rbp), %rax
movzbl 0x9(%rax), %eax
addl $0x1, %eax
movl %eax, -0x78(%rbp)
movq -0x10(%rbp), %rax
movzbl 0xa(%rax), %eax
sarl $0x4, %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
movq -0x10(%rbp), %rax
movzbl 0xa(%rax), %eax
andl $0xf, %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
movl -0x78(%rbp), %eax
subl -0x44(%rbp), %eax
subl -0x40(%rbp), %eax
movl %eax, -0x3c(%rbp)
movq -0x10(%rbp), %rax
movzbl 0x11(%rax), %eax
sarl $0x2, %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x22f80
movb $0x1, -0x38(%rbp)
movq -0x10(%rbp), %rax
movzbl 0x3(%rax), %eax
andl $0x10, %eax
cmpl $0x0, %eax
je 0x22fb2
movb $0x1, -0x58(%rbp)
movl -0x44(%rbp), %eax
shrl %eax
movl %eax, -0x44(%rbp)
movl -0x40(%rbp), %eax
shrl %eax
movl %eax, -0x40(%rbp)
movl -0x3c(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, -0x3c(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x4c30
jmp 0x22fbd
movl -0x68(%rbp), %esi
leaq -0x110(%rbp), %rdi
callq 0xb6d0
jmp 0x22fce
leaq 0xe385(%rip), %rdx      # 0x3135a
leaq -0xf0(%rbp), %rdi
leaq -0x110(%rbp), %rsi
callq 0xb4c0
jmp 0x22fea
movl -0x64(%rbp), %esi
leaq -0x130(%rbp), %rdi
callq 0xb6d0
jmp 0x22ffb
leaq -0xd0(%rbp), %rdi
leaq -0xf0(%rbp), %rsi
leaq -0x130(%rbp), %rdx
callq 0xb7b0
jmp 0x23017
leaq -0x98(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0x43f0
jmp 0x2302c
leaq -0xd0(%rbp), %rdi
callq 0x41f0
leaq -0x130(%rbp), %rdi
callq 0x41f0
leaq -0xf0(%rbp), %rdi
callq 0x41f0
leaq -0x110(%rbp), %rdi
callq 0x41f0
movq -0x10(%rbp), %rax
movzbl 0x3(%rax), %eax
shrl $0x5, %eax
andl $0x3, %eax
movl %eax, %ecx
movq %rcx, -0x208(%rbp)
subl $0x3, %eax
ja 0x2319c
movq -0x208(%rbp), %rax
leaq 0x1ab2e(%rip), %rcx     # 0x3dbb8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa8(%rbp)
movl %eax, -0xac(%rbp)
jmp 0x23318
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa8(%rbp)
movl %eax, -0xac(%rbp)
jmp 0x2311c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa8(%rbp)
movl %eax, -0xac(%rbp)
jmp 0x23110
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa8(%rbp)
movl %eax, -0xac(%rbp)
jmp 0x23104
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa8(%rbp)
movl %eax, -0xac(%rbp)
leaq -0xd0(%rbp), %rdi
callq 0x41f0
leaq -0x130(%rbp), %rdi
callq 0x41f0
leaq -0xf0(%rbp), %rdi
callq 0x41f0
leaq -0x110(%rbp), %rdi
callq 0x41f0
jmp 0x23318
leaq 0x1b3fd(%rip), %rsi     # 0x3e531
leaq -0x98(%rbp), %rdi
callq 0x4300
jmp 0x23142
jmp 0x2319c
leaq 0x1b3f5(%rip), %rsi     # 0x3e540
leaq -0x98(%rbp), %rdi
callq 0x4300
jmp 0x23159
jmp 0x2319c
leaq 0x1b3ea(%rip), %rsi     # 0x3e54c
leaq -0x98(%rbp), %rdi
callq 0x4300
jmp 0x23170
jmp 0x2319c
leaq 0x16c02(%rip), %rsi     # 0x39d7b
leaq -0x98(%rbp), %rdi
callq 0x4300
jmp 0x23187
leaq 0x1b3e1(%rip), %rsi     # 0x3e56f
xorl %edi, %edi
movb %dil, %al
callq 0x47d0
jmp 0x2319a
jmp 0x2319c
movq -0x10(%rbp), %rax
movzbl 0x3(%rax), %eax
andl $0x80, %eax
cmpl $0x0, %eax
je 0x232c5
leaq 0x1b3db(%rip), %rsi     # 0x3e594
leaq -0x98(%rbp), %rdi
callq 0x4300
jmp 0x231c7
movq -0x200(%rbp), %rax
addq $0x928, %rax            # imm = 0x928
movq %rax, -0x218(%rbp)
leaq -0x1e9(%rbp), %rdi
movq %rdi, -0x210(%rbp)
callq 0x4560
movq -0x210(%rbp), %rdx
leaq 0xc1f3(%rip), %rsi      # 0x2f3ef
leaq -0x1e8(%rbp), %rdi
callq 0xb510
jmp 0x2320a
leaq -0x1c8(%rbp), %rdi
leaq -0x70(%rbp), %rsi
leaq -0x1e8(%rbp), %rdx
leaq -0x98(%rbp), %rcx
callq 0x148f0
jmp 0x2322a
movq -0x218(%rbp), %rdi
leaq -0x1c8(%rbp), %rsi
callq 0x1ff90
jmp 0x2323f
leaq -0x1c8(%rbp), %rdi
callq 0xc3d0
leaq -0x1e8(%rbp), %rdi
callq 0x41f0
leaq -0x1e9(%rbp), %rdi
callq 0x4370
jmp 0x232c5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa8(%rbp)
movl %eax, -0xac(%rbp)
jmp 0x232b7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa8(%rbp)
movl %eax, -0xac(%rbp)
jmp 0x232ab
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa8(%rbp)
movl %eax, -0xac(%rbp)
leaq -0x1c8(%rbp), %rdi
callq 0xc3d0
leaq -0x1e8(%rbp), %rdi
callq 0x41f0
leaq -0x1e9(%rbp), %rdi
callq 0x4370
jmp 0x23318
leaq -0x98(%rbp), %rdi
callq 0x4150
movq -0x200(%rbp), %rdi
movq %rax, %r8
movq %rsp, %rax
movl $0x1, (%rax)
leaq 0x114f4(%rip), %rsi     # 0x347df
leaq 0xc0fd(%rip), %rcx      # 0x2f3ef
leaq -0x70(%rbp), %rdx
movl $0x1, %r9d
callq 0x50c0
jmp 0x23303
leaq -0x98(%rbp), %rdi
callq 0x41f0
addq $0x220, %rsp            # imm = 0x220
popq %rbp
retq
leaq -0x98(%rbp), %rdi
callq 0x41f0
movq -0xa8(%rbp), %rdi
callq 0x4550