// File: /workspace/github_cpp_makefile_star2_O1/rpavlik[P]edid-decode/parse-base-block.cpp
// Function: edid_state::detailed_cvt_descriptor(char const*, unsigned char const*, bool)
void edid_state::detailed_cvt_descriptor(const char *prefix, const unsigned char *x, bool first)
{
	static const unsigned char empty[3] = { 0, 0, 0 };
	struct timings cvt_t = {};
	unsigned char preferred;

	if (!first && !memcmp(x, empty, 3))
		return;

	cvt_t.vact = x[0];
	if (!cvt_t.vact)
		fail("CVT byte 0 is 0, which is a reserved value.\n");
	cvt_t.vact |= (x[1] & 0xf0) << 4;
	cvt_t.vact++;
	cvt_t.vact *= 2;

	switch (x[1] & 0x0c) {
	case 0x00:
	default: /* avoids 'width/ratio may be used uninitialized' warnings */
		cvt_t.hratio = 4;
		cvt_t.vratio = 3;
		break;
	case 0x04:
		cvt_t.hratio = 16;
		cvt_t.vratio = 9;
		break;
	case 0x08:
		cvt_t.hratio = 16;
		cvt_t.vratio = 10;
		break;
	case 0x0c:
		cvt_t.hratio = 15;
		cvt_t.vratio = 9;
		break;
	}
	cvt_t.hact = 8 * (((cvt_t.vact * cvt_t.hratio) / cvt_t.vratio) / 8);

	if (x[1] & 0x03)
		fail("Reserved bits of CVT byte 1 are non-zero.\n");
	if (x[2] & 0x80)
		fail("Reserved bit of CVT byte 2 is non-zero.\n");
	if (!(x[2] & 0x1f))
		fail("CVT byte 2 does not support any vertical rates.\n");
	preferred = (x[2] & 0x60) >> 5;
	if (preferred == 1 && (x[2] & 0x01))
		preferred = 4;
	if (!(x[2] & (1 << (4 - preferred))))
		fail("The preferred CVT Vertical Rate is not supported.\n");

	static const char *s_pref = "preferred vertical rate";

	if (x[2] & 0x10) {
		edid_cvt_mode(50, cvt_t);
		print_timings(prefix, &cvt_t, "CVT", preferred == 0 ? s_pref : "");
	}
	if (x[2] & 0x08) {
		edid_cvt_mode(60, cvt_t);
		print_timings(prefix, &cvt_t, "CVT", preferred == 1 ? s_pref : "");
	}
	if (x[2] & 0x04) {
		edid_cvt_mode(75, cvt_t);
		print_timings(prefix, &cvt_t, "CVT", preferred == 2 ? s_pref : "");
	}
	if (x[2] & 0x02) {
		edid_cvt_mode(85, cvt_t);
		print_timings(prefix, &cvt_t, "CVT", preferred == 3 ? s_pref : "");
	}
	if (x[2] & 0x01) {
		cvt_t.rb = RB_CVT_V1;
		edid_cvt_mode(60, cvt_t);
		print_timings(prefix, &cvt_t, "CVT", preferred == 4 ? s_pref : "");
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rdx, %r15
movq %rsi, %rbx
movq %rdi, %r14
xorps %xmm0, %xmm0
movaps %xmm0, 0x50(%rsp)
movaps %xmm0, 0x40(%rsp)
movaps %xmm0, 0x30(%rsp)
movaps %xmm0, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
movl $0x0, 0x60(%rsp)
testl %ecx, %ecx
jne 0x9e74
movzbl 0x2(%r15), %eax
orw (%r15), %ax
je 0xa0f9
movzbl (%r15), %eax
movl %eax, 0x14(%rsp)
testl %eax, %eax
jne 0x9e90
leaq 0x1a870(%rip), %rsi     # 0x246f7
xorl %edi, %edi
xorl %eax, %eax
callq 0x37ec
movzbl 0x1(%r15), %ecx
movl %ecx, %edx
andl $-0x10, %edx
movl 0x14(%rsp), %eax
shll $0x5, %edx
addl %eax, %eax
orl %edx, %eax
addl $0x2, %eax
movl %eax, 0x14(%rsp)
leaq 0x1c921(%rip), %rdx     # 0x267d4
movl %ecx, %esi
andl $0xc, %esi
movl (%rsi,%rdx), %edx
leaq 0x1c922(%rip), %rdi     # 0x267e4
movl (%rsi,%rdi), %esi
movl %edx, 0x18(%rsp)
movl %esi, 0x1c(%rsp)
imull %edx, %eax
xorl %edx, %edx
divl %esi
andl $-0x8, %eax
movl %eax, 0x10(%rsp)
testb $0x3, %cl
je 0x9ef0
leaq 0x1a83d(%rip), %rsi     # 0x24724
xorl %edi, %edi
xorl %eax, %eax
callq 0x37ec
cmpb $0x0, 0x2(%r15)
jns 0x9f07
leaq 0x1a851(%rip), %rsi     # 0x2474f
xorl %edi, %edi
xorl %eax, %eax
callq 0x37ec
testb $0x1f, 0x2(%r15)
jne 0x9f1e
leaq 0x1a863(%rip), %rsi     # 0x24778
xorl %edi, %edi
xorl %eax, %eax
callq 0x37ec
movzbl 0x2(%r15), %eax
movl %eax, %ecx
shrb $0x5, %cl
andb $0x3, %cl
cmpb $0x1, %cl
sete %bpl
andb %al, %bpl
movzbl %cl, %ecx
movl $0x4, %r13d
cmovel %ecx, %r13d
movb $0x4, %cl
subb %r13b, %cl
movzbl %cl, %ecx
btl %ecx, %eax
jb 0x9f5f
leaq 0x1a853(%rip), %rsi     # 0x247a9
xorl %edi, %edi
xorl %eax, %eax
callq 0x37ec
testb $0x10, 0x2(%r15)
je 0x9faf
leaq 0x10(%rsp), %r12
movq %r14, %rdi
movl $0x32, %esi
movq %r12, %rdx
callq 0x1fd24
testb %r13b, %r13b
leaq 0x1a857(%rip), %rax     # 0x247dc
leaq 0x16ced(%rip), %r8      # 0x20c79
cmoveq %rax, %r8
movl $0x1, (%rsp)
leaq 0x26df0(%rip), %rcx     # 0x30d8e
movq %r14, %rdi
movq %rbx, %rsi
movq %r12, %rdx
xorl %r9d, %r9d
callq 0x3ebe
testb $0x8, 0x2(%r15)
je 0xa000
leaq 0x10(%rsp), %r12
movq %r14, %rdi
movl $0x3c, %esi
movq %r12, %rdx
callq 0x1fd24
cmpb $0x1, %r13b
leaq 0x1a806(%rip), %rax     # 0x247dc
leaq 0x16c9c(%rip), %r8      # 0x20c79
cmoveq %rax, %r8
movl $0x1, (%rsp)
leaq 0x26d9f(%rip), %rcx     # 0x30d8e
movq %r14, %rdi
movq %rbx, %rsi
movq %r12, %rdx
xorl %r9d, %r9d
callq 0x3ebe
testb $0x4, 0x2(%r15)
je 0xa051
leaq 0x10(%rsp), %r12
movq %r14, %rdi
movl $0x4b, %esi
movq %r12, %rdx
callq 0x1fd24
cmpb $0x2, %r13b
leaq 0x1a7b5(%rip), %rax     # 0x247dc
leaq 0x16c4b(%rip), %r8      # 0x20c79
cmoveq %rax, %r8
movl $0x1, (%rsp)
leaq 0x26d4e(%rip), %rcx     # 0x30d8e
movq %r14, %rdi
movq %rbx, %rsi
movq %r12, %rdx
xorl %r9d, %r9d
callq 0x3ebe
testb $0x2, 0x2(%r15)
je 0xa0a2
leaq 0x10(%rsp), %r12
movq %r14, %rdi
movl $0x55, %esi
movq %r12, %rdx
callq 0x1fd24
cmpb $0x3, %r13b
leaq 0x1a764(%rip), %rax     # 0x247dc
leaq 0x16bfa(%rip), %r8      # 0x20c79
cmoveq %rax, %r8
movl $0x1, (%rsp)
leaq 0x26cfd(%rip), %rcx     # 0x30d8e
movq %r14, %rdi
movq %rbx, %rsi
movq %r12, %rdx
xorl %r9d, %r9d
callq 0x3ebe
testb $0x1, 0x2(%r15)
je 0xa0f9
movl $0x1, %r12d
leaq 0x10(%rsp), %r15
movl %r12d, 0x14(%r15)
movq %r14, %rdi
movl $0x3c, %esi
movq %r15, %rdx
callq 0x1fd24
leaq 0x1a70d(%rip), %rax     # 0x247dc
leaq 0x16ba3(%rip), %r8      # 0x20c79
testb %bpl, %bpl
cmovneq %rax, %r8
movl %r12d, (%rsp)
leaq 0x26ca6(%rip), %rcx     # 0x30d8e
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
xorl %r9d, %r9d
callq 0x3ebe
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq