// File: 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
movq %rsp, %rbp
subq $0xa0, %rsp
movb %cl, %al
movb %dl, %cl
movb %sil, %dl
movq %rdi, -0x8(%rbp)
movb %dl, -0x9(%rbp)
movb %cl, -0xa(%rbp)
andb $0x1, %al
movb %al, -0xb(%rbp)
movb -0xb(%rbp), %dl
leaq 0x22994(%rip), %rcx     # 0x3963f
leaq 0x2299e(%rip), %rax     # 0x39650
testb $0x1, %dl
cmovneq %rcx, %rax
movq %rax, -0x18(%rbp)
movb -0xb(%rbp), %dl
leaq 0x2298f(%rip), %rcx     # 0x39656
leaq 0x26a0e(%rip), %rax     # 0x3d6dc
testb $0x1, %dl
cmovneq %rcx, %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x80(%rbp)
movzbl -0x9(%rbp), %esi
leaq -0x40(%rbp), %rdi
movq %rdi, -0x88(%rbp)
movl $0x1, %edx
callq 0x16f00
movq -0x88(%rbp), %rdi
callq 0x4150
movq -0x80(%rbp), %rsi
movq %rax, %rdx
leaq 0x22953(%rip), %rdi     # 0x39667
xorl %eax, %eax
callq 0x4050
jmp 0x16d1d
leaq -0x40(%rbp), %rdi
callq 0x41f0
movq -0x20(%rbp), %rax
movq %rax, -0x98(%rbp)
movzbl -0xa(%rbp), %esi
leaq -0x70(%rbp), %rdi
movq %rdi, -0xa0(%rbp)
xorl %edx, %edx
movl %edx, -0x8c(%rbp)
callq 0x16f00
movq -0xa0(%rbp), %rdi
callq 0x4150
movq -0x98(%rbp), %rsi
movq %rax, %rdx
movl -0x8c(%rbp), %eax
leaq 0x228f7(%rip), %rdi     # 0x39667
callq 0x4050
jmp 0x16d77
leaq -0x70(%rbp), %rdi
callq 0x41f0
movzbl -0x9(%rbp), %eax
cmpl $0xfb, %eax
jle 0x16de4
movzbl -0x9(%rbp), %eax
cmpl $0xff, %eax
je 0x16de4
movq -0x18(%rbp), %rdx
movzbl -0x9(%rbp), %ecx
xorl %edi, %edi
leaq 0x228d4(%rip), %rsi     # 0x3967b
movb $0x0, %al
callq 0x47d0
jmp 0x16de4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x41f0
jmp 0x16eeb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x41f0
jmp 0x16eeb
movzbl -0xa(%rbp), %eax
cmpl $0xfb, %eax
jle 0x16e12
movzbl -0xa(%rbp), %eax
cmpl $0xff, %eax
je 0x16e12
movq -0x20(%rbp), %rdx
movzbl -0xa(%rbp), %ecx
xorl %edi, %edi
leaq 0x22870(%rip), %rsi     # 0x3967b
movb $0x0, %al
callq 0x47d0
cmpb $0x0, -0x9(%rbp)
je 0x16e23
movzbl -0x9(%rbp), %eax
cmpl $0xfb, %eax
jle 0x16e28
jmp 0x16ee2
cmpb $0x0, -0xa(%rbp)
je 0x16e39
movzbl -0xa(%rbp), %eax
cmpl $0xfb, %eax
jle 0x16e3e
jmp 0x16ee2
movzbl -0x9(%rbp), %eax
shll %eax
addl $0x1, %eax
movl %eax, -0x74(%rbp)
movzbl -0xa(%rbp), %eax
shll %eax
addl $0x1, %eax
movl %eax, -0x78(%rbp)
movl -0x78(%rbp), %eax
cmpl -0x74(%rbp), %eax
jae 0x16e83
movq -0x20(%rbp), %rdx
movq -0x18(%rbp), %rcx
movl -0x78(%rbp), %r8d
movl -0x74(%rbp), %r9d
movl $0x1, %edi
leaq 0x2281f(%rip), %rsi     # 0x39699
movb $0x0, %al
callq 0x47d0
jmp 0x16ee2
movl -0x74(%rbp), %eax
addl $0x14, %eax
cmpl -0x78(%rbp), %eax
jae 0x16eb3
movq -0x18(%rbp), %rdx
movq -0x20(%rbp), %rcx
movl -0x74(%rbp), %r8d
movl -0x78(%rbp), %r9d
movl $0x1, %edi
leaq 0x2284e(%rip), %rsi     # 0x396f8
movb $0x0, %al
callq 0x47d0
jmp 0x16ee0
movl -0x74(%rbp), %eax
cmpl -0x78(%rbp), %eax
jae 0x16ede
movq -0x18(%rbp), %rdx
movq -0x20(%rbp), %rcx
movl -0x74(%rbp), %r8d
movl -0x78(%rbp), %r9d
movl $0x1, %edi
leaq 0x227c2(%rip), %rsi     # 0x39699
movb $0x0, %al
callq 0x47d0
jmp 0x16ee0
jmp 0x16ee2
addq $0xa0, %rsp
popq %rbp
retq
movq -0x48(%rbp), %rdi
callq 0x4550
nopw %cs:(%rax,%rax)