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

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

	if (x[13] & 0x80) {
		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);
	if (x[2] & 0x40) {
		double aspect_mult = x[14] * 3.0 / 256.0;
		unsigned size_mult = 1 + (x[16] >> 4);

		t.vsize_mm = size_mult * (1 + (x[15] | ((x[16] & 0xf) << 8)));
		t.hsize_mm = t.vsize_mm * aspect_mult;
	}

	switch ((x[13] >> 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[2] & 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
xorpd %xmm0, %xmm0
movupd %xmm0, 0x50(%rsp)
movupd %xmm0, 0x44(%rsp)
movupd %xmm0, 0x34(%rsp)
movupd %xmm0, 0x24(%rsp)
movupd %xmm0, 0x14(%rsp)
leaq 0x141ec(%rip), %rsi     # 0x28e49
leaq 0x60(%rsp), %rdi
leaq 0xe0(%rsp), %rdx
callq 0x75c4
movzwl (%r14), %eax
movzbl 0x2(%r14), %ecx
andl $0x3f, %ecx
shll $0x10, %ecx
addl %ecx, %eax
incl %eax
movl %eax, 0x1c(%rsp)
movzbl 0x3(%r14), %eax
movzbl 0x4(%r14), %ecx
movl %ecx, %edx
andl $0x3f, %edx
shll $0x8, %edx
addl %edx, %eax
incl %eax
movl %eax, 0xc(%rsp)
testb %cl, %cl
jns 0x14ca9
movb $0x1, 0x34(%rsp)
movzbl 0x7(%r14), %eax
movzbl 0x9(%r14), %ecx
movl %ecx, %edx
andl $0xf, %edx
shll $0x8, %edx
orl %eax, %edx
movzbl 0x8(%r14), %eax
shll $0x4, %ecx
andl $0xf00, %ecx            # imm = 0xF00
leal (%rcx,%rax), %esi
addl %ecx, %eax
incl %eax
movl %eax, 0x28(%rsp)
movzbl 0xa(%r14), %eax
leal 0x1(%rax), %ecx
movl %ecx, 0x2c(%rsp)
notl %edx
addl %esi, %eax
addl %edx, %eax
pushq $-0x2
popq %rcx
subl %eax, %ecx
movl %ecx, 0x30(%rsp)
movzbl 0x5(%r14), %eax
movzbl 0x6(%r14), %ecx
movl %ecx, %edx
andl $0x3f, %edx
shll $0x8, %edx
addl %edx, %eax
incl %eax
movl %eax, 0x10(%rsp)
testb %cl, %cl
jns 0x14d14
movb $0x1, 0x44(%rsp)
movzbl 0xb(%r14), %eax
movzbl 0xc(%r14), %esi
leal 0x1(%rsi), %ecx
movl %ecx, 0x38(%rsp)
movzbl 0xd(%r14), %edi
movl %edi, %r8d
andl $0xf, %r8d
leal 0x1(%r8), %edx
movl %edx, 0x3c(%rsp)
addl %r8d, %esi
incl %esi
subl %esi, %eax
movl %eax, 0x40(%rsp)
testb %dil, %dil
jns 0x14d68
movb $0x1, 0x24(%rsp)
shrl %ecx
movl %ecx, 0x38(%rsp)
shrl %edx
movl %edx, 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 0x630b(%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
testb $0x40, 0x2(%r14)
leaq 0x1405c(%rip), %rsi     # 0x28e7b
jne 0x14e3c
movzbl 0xd(%r14), %eax
shrl $0x5, %eax
andl $0x3, %eax
leaq 0x13935(%rip), %rcx     # 0x28768
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movzbl 0xe(%r14), %eax
cvtsi2sd %eax, %xmm0
mulsd 0x137f3(%rip), %xmm0    # 0x28640
mulsd 0xf10b(%rip), %xmm0     # 0x23f60
movzbl 0x10(%r14), %eax
movl %eax, %ecx
shrl $0x4, %ecx
incl %ecx
movzbl 0xf(%r14), %edx
andl $0xf, %eax
shll $0x8, %eax
addl %edx, %eax
incl %eax
imull %ecx, %eax
cvtsi2sd %eax, %xmm1
mulsd %xmm0, %xmm1
cvttsd2si %xmm1, %rcx
movl %eax, 0x58(%rsp)
movl %ecx, 0x54(%rsp)
movzbl 0xd(%r14), %eax
shrl $0x5, %eax
andl $0x3, %eax
leaq 0x138ce(%rip), %rcx     # 0x28768
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x13fe0(%rip), %rsi     # 0x28e8a
jmp 0x14eb3
leaq 0x13fe3(%rip), %rsi     # 0x28e96
leaq 0x60(%rsp), %rdi
callq 0x3450
jmp 0x14ee0
leaq 0xf6e1(%rip), %rsi      # 0x245a7
leaq 0x60(%rsp), %rdi
callq 0x3450
leaq 0x13fe2(%rip), %rsi     # 0x28eb9
xorl %edi, %edi
xorl %eax, %eax
callq 0x362c
cmpb $0x0, 0x2(%r14)
jns 0x14f61
leaq 0x13ff0(%rip), %rsi     # 0x28ede
leaq 0x60(%rsp), %rdi
callq 0x3450
leaq 0x53be(%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 0xa523(%rip), %rsi      # 0x1f497
leaq 0x5342(%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 0x14fb6
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
jmp 0x15003
jmp 0x1500c
movq %rax, %rbx
leaq 0xe0(%rsp), %rdi
callq 0x3130
jmp 0x14fd7
movq %rax, %rbx
leaq 0xc0(%rsp), %rdi
callq 0x3130
jmp 0x14fe9
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
callq 0x3130
jmp 0x14ffb
movq %rax, %rbx
leaq 0xa0(%rsp), %rdi
callq 0x3130
jmp 0x1500f
jmp 0x1500c
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0x3130
movq %rbx, %rdi
callq 0x3430
nop