// File: /workspace/github_cpp_makefile_star2_O1/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, %r12d
leaq 0x1aef7(%rip), %rax     # 0x2a1b7
leaq 0x1af01(%rip), %rbx     # 0x2a1c8
testl %ecx, %ecx
cmovneq %rax, %rbx
leaq 0x1aefa(%rip), %rax     # 0x2a1ce
leaq 0x1de2d(%rip), %r14     # 0x2d108
cmovneq %rax, %r14
leaq 0x8(%rsp), %r15
movq %r15, %rdi
movl $0x1, %edx
callq 0xf439
movq (%r15), %rdx
leaq 0x1aee4(%rip), %rdi     # 0x2a1df
movq %rbx, %rsi
xorl %eax, %eax
callq 0x3030
movq (%r15), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0xf31f
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x3260
movzbl %bpl, %r15d
leaq 0x8(%rsp), %r13
movq %r13, %rdi
movl %r15d, %esi
xorl %edx, %edx
callq 0xf439
movq (%r13), %rdx
leaq 0x1ae9f(%rip), %rdi     # 0x2a1df
movq %r14, %rsi
xorl %eax, %eax
callq 0x3030
movq (%r13), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0xf365
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x3260
movzbl %r12b, %r12d
leal 0x4(%r12), %r13d
cmpb $0x2, %r13b
ja 0xf38a
leaq 0x1ae78(%rip), %rsi     # 0x2a1f3
xorl %edi, %edi
movq %rbx, %rdx
movl %r12d, %ecx
xorl %eax, %eax
callq 0x37ec
addb $0x4, %bpl
cmpb $0x2, %bpl
ja 0xf3aa
leaq 0x1ae58(%rip), %rsi     # 0x2a1f3
xorl %edi, %edi
movq %r14, %rdx
movl %r15d, %ecx
xorl %eax, %eax
callq 0x37ec
cmpb $0x5, %r13b
setb %al
cmpb $0x5, %bpl
setb %cl
orb %al, %cl
jne 0xf42a
movl %r12d, %eax
addl %r12d, %r12d
leal 0x1(,%rax,2), %r9d
movl %r15d, %eax
addl %r15d, %r15d
leal 0x1(,%rax,2), %eax
cmpl %r12d, %r15d
jae 0xf3f3
leaq 0x1ae2e(%rip), %rsi     # 0x2a211
movl $0x1, %edi
movq %r14, %rdx
movq %rbx, %rcx
movl %eax, %r8d
jmp 0xf423
leal 0x15(%r12), %ecx
cmpl %r15d, %ecx
jbe 0xf40b
cmpl %r15d, %r12d
jae 0xf42a
leaq 0x1ae08(%rip), %rsi     # 0x2a211
jmp 0xf412
leaq 0x1ae5e(%rip), %rsi     # 0x2a270
movl $0x1, %edi
movq %rbx, %rdx
movq %r14, %rcx
movl %r9d, %r8d
movl %eax, %r9d
xorl %eax, %eax
callq 0x37ec
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq