// File: /workspace/github_cpp_makefile_star2_O2/rpavlik[P]edid-decode/parse-cta-block.cpp
// Function: edid_state::hdmi_latency(unsigned char, unsigned char, bool)
void edid_state::hdmi_latency(unsigned char vid_lat, unsigned char aud_lat,
			      bool is_ilaced)
{
	const char *vid = is_ilaced ? "Interlaced video" : "Video";
	const char *aud = is_ilaced ? "Interlaced audio" : "Audio";

	printf("    %s latency: %s\n", vid, hdmi_latency2s(vid_lat, true).c_str());
	printf("    %s latency: %s\n", aud, hdmi_latency2s(aud_lat, false).c_str());

	if (vid_lat > 251 && vid_lat != 0xff)
		fail("Invalid %s latency value %u.\n", vid, vid_lat);
	if (aud_lat > 251 && aud_lat != 0xff)
		fail("Invalid %s latency value %u.\n", aud, aud_lat);

	if (!vid_lat || vid_lat > 251)
		return;
	if (!aud_lat || aud_lat > 251)
		return;

	unsigned vid_ms = 1 + 2 * vid_lat;
	unsigned aud_ms = 1 + 2 * aud_lat;

	// HDMI 2.0 latency checks for devices without HDMI output
	if (aud_ms < vid_ms)
		warn("%s latency < %s latency (%u ms < %u ms). This is discouraged for devices without HDMI output.\n",
		     aud, vid, aud_ms, vid_ms);
	else if (vid_ms + 20 < aud_ms)
		warn("%s latency + 20 < %s latency (%u + 20 ms < %u ms). This is forbidden for devices without HDMI output.\n",
		     vid, aud, vid_ms, aud_ms);
	else if (vid_ms < aud_ms)
		warn("%s latency < %s latency (%u ms < %u ms). This is discouraged for devices without HDMI output.\n",
		     vid, aud, vid_ms, aud_ms);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %edx, %ebp
movl %esi, %r15d
leaq 0x17527(%rip), %rax     # 0x241df
leaq 0x17531(%rip), %r14     # 0x241f0
testl %ecx, %ecx
cmovneq %rax, %r14
leaq 0x1752a(%rip), %rax     # 0x241f6
leaq 0x1a45d(%rip), %rbx     # 0x27130
cmovneq %rax, %rbx
leaq 0x8(%rsp), %r12
pushq $0x1
popq %rdx
movq %r12, %rdi
callq 0xcdf6
movq (%r12), %rdx
leaq 0x17515(%rip), %r13     # 0x24207
movq %r13, %rdi
movq %r14, %rsi
xorl %eax, %eax
callq 0x3030
movq %r12, %rdi
callq 0x3130
leaq 0x8(%rsp), %r12
movq %r12, %rdi
movl %ebp, %esi
xorl %edx, %edx
callq 0xcdf6
movq (%r12), %rdx
movq %r13, %rdi
movq %rbx, %rsi
xorl %eax, %eax
callq 0x3030
movq %r12, %rdi
callq 0x3130
leal 0x4(%r15), %r12d
cmpb $0x2, %r12b
ja 0xcd51
leaq 0x174d9(%rip), %rsi     # 0x2421b
xorl %edi, %edi
movq %r14, %rdx
movl %r15d, %ecx
xorl %eax, %eax
callq 0x362c
movzbl %bpl, %ecx
leal 0x4(%rcx), %eax
cmpb $0x2, %al
ja 0xcd71
leaq 0x174b8(%rip), %rsi     # 0x2421b
xorl %edi, %edi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x362c
jmp 0xcde7
cmpb $0x5, %r12b
setb %dl
cmpb $0x5, %al
setb %al
orb %dl, %al
jne 0xcde7
movl %r15d, %eax
addl %r15d, %r15d
leal 0x1(,%rax,2), %r9d
movl %ecx, %eax
addl %ecx, %ecx
leal 0x1(,%rax,2), %eax
cmpl %r15d, %ecx
jae 0xcdb4
leaq 0x17493(%rip), %rsi     # 0x24239
pushq $0x1
popq %rdi
movq %rbx, %rdx
movq %r14, %rcx
movl %eax, %r8d
jmp 0xcde0
leal 0x15(%r15), %edx
cmpl %ecx, %edx
jbe 0xcdca
cmpl %ecx, %r15d
jae 0xcde7
leaq 0x17471(%rip), %rsi     # 0x24239
jmp 0xcdd1
leaq 0x174c7(%rip), %rsi     # 0x24298
pushq $0x1
popq %rdi
movq %r14, %rdx
movq %rbx, %rcx
movl %r9d, %r8d
movl %eax, %r9d
xorl %eax, %eax
callq 0x362c
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq