// File: rpavlik[P]edid-decode/parse-base-block.cpp
// Function: edid_state::print_standard_timing(char const*, unsigned char, unsigned char, bool, bool)
void edid_state::print_standard_timing(const char *prefix, unsigned char b1, unsigned char b2,
				       bool gtf_only, bool show_both)
{
	const struct timings *t;
	struct timings formula = {};
	unsigned hratio, vratio;
	unsigned hact, vact, refresh;
	unsigned char dmt_id = 0;

	if (b1 <= 0x01) {
		if (b1 != 0x01 || b2 != 0x01)
			fail("Use 0x0101 as the invalid Standard Timings code, not 0x%02x%02x.\n", b1, b2);
		return;
	}

	t = find_std_id((b1 << 8) | b2, dmt_id);
	if (t) {
		char type[16];
		sprintf(type, "DMT 0x%02x", dmt_id);
		print_timings(prefix, t, type);
		return;
	}
	hact = (b1 + 31) * 8;
	switch ((b2 >> 6) & 0x3) {
	case 0x00:
		if (gtf_only || show_both || base.edid_minor >= 3) {
			hratio = 16;
			vratio = 10;
		} else {
			hratio = 1;
			vratio = 1;
		}
		break;
	case 0x01:
		hratio = 4;
		vratio = 3;
		break;
	case 0x02:
		hratio = 5;
		vratio = 4;
		break;
	case 0x03:
		hratio = 16;
		vratio = 9;
		break;
	}
	vact = (double)hact * vratio / hratio;
	vact = 8 * ((vact + 7) / 8);
	refresh = (b2 & 0x3f) + 60;

	formula.hact = hact;
	formula.vact = vact;
	formula.hratio = hratio;
	formula.vratio = vratio;

	if (!gtf_only && (show_both || base.edid_minor >= 4)) {
		if (show_both || base.supports_cvt) {
			edid_cvt_mode(refresh, formula);
			print_timings(prefix, &formula, "CVT     ",
				      show_both ? "" : "EDID 1.4 source");
		}
		/*
		 * An EDID 1.3 source will assume GTF, so both GTF and CVT
		 * have to be supported.
		 */
		edid_gtf_mode(refresh, formula);
		if (base.supports_cvt)
			print_timings(prefix, &formula, "GTF     ", "EDID 1.3 source");
		else
			print_timings(prefix, &formula, "GTF     ");
	} else if (gtf_only || base.edid_minor >= 2) {
		edid_gtf_mode(refresh, formula);
		print_timings(prefix, &formula, "GTF     ");
	} else {
		printf("%sUnknown : %5ux%-5u %3u.000 Hz %3u:%u\n",
		       prefix, hact, vact, refresh, hratio, vratio);
		min_vert_freq_hz = min(min_vert_freq_hz, refresh);
		max_vert_freq_hz = max(max_vert_freq_hz, refresh);
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xe0, %rsp
movl %r8d, -0xbc(%rbp)
movl %ecx, %eax
movl -0xbc(%rbp), %ecx
movl %eax, -0xb8(%rbp)
movl %edx, %eax
movl -0xb8(%rbp), %edx
movl %eax, -0xb4(%rbp)
movq %rsi, %rax
movl -0xb4(%rbp), %esi
movq %rax, -0xb0(%rbp)
movq %rdi, %r8
movq -0xb0(%rbp), %rdi
movb %r9b, %al
movq %r8, -0x8(%rbp)
movq %rdi, -0x10(%rbp)
movb %sil, -0x11(%rbp)
movb %dl, -0x12(%rbp)
andb $0x1, %cl
movb %cl, -0x13(%rbp)
andb $0x1, %al
movb %al, -0x14(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xa8(%rbp)
leaq -0x74(%rbp), %rdi
xorl %esi, %esi
movl $0x54, %edx
callq 0x41c0
movb $0x0, -0x89(%rbp)
movzbl -0x11(%rbp), %eax
cmpl $0x1, %eax
jg 0xf7af
movzbl -0x11(%rbp), %eax
cmpl $0x1, %eax
jne 0xf792
movzbl -0x12(%rbp), %eax
cmpl $0x1, %eax
je 0xf7aa
movzbl -0x11(%rbp), %edx
movzbl -0x12(%rbp), %ecx
xorl %edi, %edi
leaq 0x242ff(%rip), %rsi     # 0x33aa2
movb $0x0, %al
callq 0x47d0
jmp 0xfb84
movzbl -0x11(%rbp), %eax
shll $0x8, %eax
movzbl -0x12(%rbp), %ecx
orl %ecx, %eax
leaq -0x89(%rbp), %rsi
movzwl %ax, %edi
callq 0xfb90
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0xf823
leaq -0xa0(%rbp), %rdi
movzbl -0x89(%rbp), %edx
leaq 0x202ce(%rip), %rsi     # 0x2fab9
movb $0x0, %al
callq 0x40a0
movq -0xa8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x20(%rbp), %rdx
leaq -0xa0(%rbp), %rcx
leaq 0x206aa(%rip), %r8      # 0x2feb9
xorl %r9d, %r9d
movl $0x1, (%rsp)
callq 0x50c0
jmp 0xfb84
movzbl -0x11(%rbp), %ecx
movl %ecx, %eax
leal 0xf8(,%rax,8), %eax
movl %eax, -0x80(%rbp)
movzbl -0x12(%rbp), %eax
shrl $0x6, %eax
movl %eax, %ecx
movq %rcx, -0xc8(%rbp)
subl $0x3, %eax
ja 0xf8cd
movq -0xc8(%rbp), %rax
leaq 0x21dea(%rip), %rcx     # 0x31644
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
testb $0x1, -0x13(%rbp)
jne 0xf87f
testb $0x1, -0x14(%rbp)
jne 0xf87f
movq -0xa8(%rbp), %rax
cmpl $0x3, 0x88(%rax)
jb 0xf88f
movl $0x10, -0x78(%rbp)
movl $0xa, -0x7c(%rbp)
jmp 0xf89d
movl $0x1, -0x78(%rbp)
movl $0x1, -0x7c(%rbp)
jmp 0xf8cd
movl $0x4, -0x78(%rbp)
movl $0x3, -0x7c(%rbp)
jmp 0xf8cd
movl $0x5, -0x78(%rbp)
movl $0x4, -0x7c(%rbp)
jmp 0xf8cd
movl $0x10, -0x78(%rbp)
movl $0x9, -0x7c(%rbp)
movl -0x80(%rbp), %eax
cvtsi2sd %rax, %xmm0
movl -0x7c(%rbp), %eax
cvtsi2sd %rax, %xmm1
mulsd %xmm1, %xmm0
movl -0x78(%rbp), %eax
cvtsi2sd %rax, %xmm1
divsd %xmm1, %xmm0
cvttsd2si %xmm0, %rax
movl %eax, -0x84(%rbp)
movl -0x84(%rbp), %eax
addl $0x7, %eax
shrl $0x3, %eax
shll $0x3, %eax
movl %eax, -0x84(%rbp)
movzbl -0x12(%rbp), %eax
andl $0x3f, %eax
addl $0x3c, %eax
movl %eax, -0x88(%rbp)
movl -0x80(%rbp), %eax
movl %eax, -0x74(%rbp)
movl -0x84(%rbp), %eax
movl %eax, -0x70(%rbp)
movl -0x78(%rbp), %eax
movl %eax, -0x6c(%rbp)
movl -0x7c(%rbp), %eax
movl %eax, -0x68(%rbp)
testb $0x1, -0x13(%rbp)
jne 0xfa4a
testb $0x1, -0x14(%rbp)
jne 0xf95c
movq -0xa8(%rbp), %rax
cmpl $0x4, 0x88(%rax)
jb 0xfa4a
testb $0x1, -0x14(%rbp)
jne 0xf972
movq -0xa8(%rbp), %rax
testb $0x1, 0xb8(%rax)
je 0xf9c5
movq -0xa8(%rbp), %rdi
movl -0x88(%rbp), %esi
leaq -0x74(%rbp), %rdx
callq 0x2e180
movq -0xa8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movb -0x14(%rbp), %cl
leaq 0x24150(%rip), %r8      # 0x33aed
leaq 0x20515(%rip), %rax     # 0x2feb9
testb $0x1, %cl
cmovneq %rax, %r8
leaq -0x74(%rbp), %rdx
leaq 0x2412e(%rip), %rcx     # 0x33ae4
xorl %r9d, %r9d
movl $0x1, (%rsp)
callq 0x50c0
movq -0xa8(%rbp), %rdi
movl -0x88(%rbp), %esi
leaq -0x74(%rbp), %rdx
callq 0x2d7d0
movq -0xa8(%rbp), %rax
testb $0x1, 0xb8(%rax)
je 0xfa19
movq -0xa8(%rbp), %rdi
movq -0x10(%rbp), %rsi
leaq -0x74(%rbp), %rdx
leaq 0x240fc(%rip), %rcx     # 0x33afd
leaq 0x240fe(%rip), %r8      # 0x33b06
xorl %r9d, %r9d
movl $0x1, (%rsp)
callq 0x50c0
jmp 0xfa45
movq -0xa8(%rbp), %rdi
movq -0x10(%rbp), %rsi
leaq -0x74(%rbp), %rdx
leaq 0x240ce(%rip), %rcx     # 0x33afd
leaq 0x20483(%rip), %r8      # 0x2feb9
xorl %r9d, %r9d
movl $0x1, (%rsp)
callq 0x50c0
jmp 0xfb84
testb $0x1, -0x13(%rbp)
jne 0xfa60
movq -0xa8(%rbp), %rax
cmpl $0x2, 0x88(%rax)
jb 0xfaa7
movq -0xa8(%rbp), %rdi
movl -0x88(%rbp), %esi
leaq -0x74(%rbp), %rdx
callq 0x2d7d0
movq -0xa8(%rbp), %rdi
movq -0x10(%rbp), %rsi
leaq -0x74(%rbp), %rdx
leaq 0x24071(%rip), %rcx     # 0x33afd
leaq 0x20426(%rip), %r8      # 0x2feb9
xorl %r9d, %r9d
movl $0x1, (%rsp)
callq 0x50c0
jmp 0xfb82
movq -0x10(%rbp), %rsi
movl -0x80(%rbp), %edx
movl -0x84(%rbp), %ecx
movl -0x88(%rbp), %r8d
movl -0x78(%rbp), %r9d
movl -0x7c(%rbp), %edi
movq %rsp, %rax
movl %edi, (%rax)
leaq 0x24048(%rip), %rdi     # 0x33b16
xorl %eax, %eax
callq 0x4050
movq -0xa8(%rbp), %rax
movsd 0x60(%rax), %xmm1
movl -0x88(%rbp), %eax
cvtsi2sd %rax, %xmm0
ucomisd %xmm1, %xmm0
jbe 0xfb08
movq -0xa8(%rbp), %rax
movsd 0x60(%rax), %xmm0
movsd %xmm0, -0xd0(%rbp)
jmp 0xfb1b
movl -0x88(%rbp), %eax
cvtsi2sd %rax, %xmm0
movsd %xmm0, -0xd0(%rbp)
movq -0xa8(%rbp), %rax
movsd -0xd0(%rbp), %xmm0
movsd %xmm0, 0x60(%rax)
movsd 0x68(%rax), %xmm0
movl -0x88(%rbp), %eax
cvtsi2sd %rax, %xmm1
ucomisd %xmm1, %xmm0
jbe 0xfb5b
movq -0xa8(%rbp), %rax
movsd 0x68(%rax), %xmm0
movsd %xmm0, -0xd8(%rbp)
jmp 0xfb6e
movl -0x88(%rbp), %eax
cvtsi2sd %rax, %xmm0
movsd %xmm0, -0xd8(%rbp)
movq -0xa8(%rbp), %rax
movsd -0xd8(%rbp), %xmm0
movsd %xmm0, 0x68(%rax)
jmp 0xfb84
addq $0xe0, %rsp
popq %rbp
retq
nopl (%rax)