// File: rpavlik[P]edid-decode/parse-cta-block.cpp
// Function: cta_hdmi_audio_block(unsigned char const*, unsigned int)
static void cta_hdmi_audio_block(const unsigned char *x, unsigned length)
{
	unsigned num_descs;

	if (length < 2) {
		fail("Empty Data Block with length %u.\n", length);
		return;
	}
	if (x[0] & 3)
		printf("    Max Stream Count: %u\n", (x[0] & 3) + 1);
	if (x[0] & 4)
		printf("    Supports MS NonMixed\n");

	num_descs = x[1] & 7;
	if (num_descs == 0)
		return;
	length -= 2;
	x += 2;
	while (length >= 4) {
		if (length > 4) {
			unsigned format = x[0] & 0xf;

			printf("    %s, max channels %u\n", audio_format(format).c_str(),
			       (x[1] & 0x1f)+1);
			printf("      Supported sample rates (kHz):%s%s%s%s%s%s%s\n",
			       (x[2] & 0x40) ? " 192" : "",
			       (x[2] & 0x20) ? " 176.4" : "",
			       (x[2] & 0x10) ? " 96" : "",
			       (x[2] & 0x08) ? " 88.2" : "",
			       (x[2] & 0x04) ? " 48" : "",
			       (x[2] & 0x02) ? " 44.1" : "",
			       (x[2] & 0x01) ? " 32" : "");
			if (format == 1)
				printf("      Supported sample sizes (bits):%s%s%s\n",
				       (x[3] & 0x04) ? " 24" : "",
				       (x[3] & 0x02) ? " 20" : "",
				       (x[3] & 0x01) ? " 16" : "");
		} else {
			unsigned sad = ((x[2] << 16) | (x[1] << 8) | x[0]);
			unsigned i;

			switch (x[3] >> 4) {
			case 1:
				printf("    Speaker Allocation for 10.2 channels:\n");
				break;
			case 2:
				printf("    Speaker Allocation for 22.2 channels:\n");
				break;
			case 3:
				printf("    Speaker Allocation for 30.2 channels:\n");
				break;
			default:
				printf("    Unknown Speaker Allocation (0x%02x)\n", x[3] >> 4);
				return;
			}

			for (i = 0; i < ARRAY_SIZE(speaker_map); i++) {
				if ((sad >> i) & 1)
					printf("      %s\n", speaker_map[i]);
			}
		}
		length -= 4;
		x += 4;
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
cmpl $0x2, -0xc(%rbp)
jae 0x1b73d
movl -0xc(%rbp), %edx
xorl %edi, %edi
leaq 0x1de7e(%rip), %rsi     # 0x395af
movb $0x0, %al
callq 0x47d0
jmp 0x1baa0
movq -0x8(%rbp), %rax
movzbl (%rax), %eax
andl $0x3, %eax
cmpl $0x0, %eax
je 0x1b767
movq -0x8(%rbp), %rax
movzbl (%rax), %esi
andl $0x3, %esi
addl $0x1, %esi
leaq 0x20fb5(%rip), %rdi     # 0x3c715
movb $0x0, %al
callq 0x4050
movq -0x8(%rbp), %rax
movzbl (%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x1b784
leaq 0x20fb2(%rip), %rdi     # 0x3c72f
movb $0x0, %al
callq 0x4050
movq -0x8(%rbp), %rax
movzbl 0x1(%rax), %eax
andl $0x7, %eax
movl %eax, -0x10(%rbp)
cmpl $0x0, -0x10(%rbp)
jne 0x1b79d
jmp 0x1baa0
movl -0xc(%rbp), %eax
subl $0x2, %eax
movl %eax, -0xc(%rbp)
movq -0x8(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x8(%rbp)
cmpl $0x4, -0xc(%rbp)
jb 0x1baa0
cmpl $0x4, -0xc(%rbp)
jbe 0x1b9a9
movq -0x8(%rbp), %rax
movzbl (%rax), %eax
andl $0xf, %eax
movl %eax, -0x14(%rbp)
movzbl -0x14(%rbp), %esi
leaq -0x38(%rbp), %rdi
movq %rdi, -0x58(%rbp)
callq 0x1ea20
movq -0x58(%rbp), %rdi
callq 0x4150
movq %rax, %rsi
movq -0x8(%rbp), %rax
movzbl 0x1(%rax), %edx
andl $0x1f, %edx
incl %edx
leaq 0x20f45(%rip), %rdi     # 0x3c749
xorl %eax, %eax
callq 0x4050
jmp 0x1b80d
leaq -0x38(%rbp), %rdi
callq 0x41f0
movq -0x8(%rbp), %rax
movzbl 0x2(%rax), %ecx
andl $0x40, %ecx
leaq 0x14691(%rip), %rsi     # 0x2feb9
leaq 0x20f66(%rip), %rax     # 0x3c795
cmpl $0x0, %ecx
cmovneq %rax, %rsi
movq -0x8(%rbp), %rax
movzbl 0x2(%rax), %ecx
andl $0x20, %ecx
leaq 0x14671(%rip), %rdx     # 0x2feb9
leaq 0x20f4b(%rip), %rax     # 0x3c79a
cmpl $0x0, %ecx
cmovneq %rax, %rdx
movq -0x8(%rbp), %rax
movzbl 0x2(%rax), %edi
andl $0x10, %edi
leaq 0x14651(%rip), %rcx     # 0x2feb9
leaq 0x20f32(%rip), %rax     # 0x3c7a1
cmpl $0x0, %edi
cmovneq %rax, %rcx
movq -0x8(%rbp), %rax
movzbl 0x2(%rax), %edi
andl $0x8, %edi
leaq 0x14631(%rip), %r8      # 0x2feb9
leaq 0x20f16(%rip), %rax     # 0x3c7a5
cmpl $0x0, %edi
cmovneq %rax, %r8
movq -0x8(%rbp), %rax
movzbl 0x2(%rax), %edi
andl $0x4, %edi
leaq 0x14611(%rip), %r9      # 0x2feb9
leaq 0x20efc(%rip), %rax     # 0x3c7ab
cmpl $0x0, %edi
cmovneq %rax, %r9
movq -0x8(%rbp), %rax
movzbl 0x2(%rax), %edi
andl $0x2, %edi
leaq 0x145f1(%rip), %r10     # 0x2feb9
leaq 0x20ee0(%rip), %rax     # 0x3c7af
cmpl $0x0, %edi
cmovneq %rax, %r10
movq -0x8(%rbp), %rax
movzbl 0x2(%rax), %r11d
andl $0x1, %r11d
leaq 0x145cf(%rip), %rax     # 0x2feb9
leaq 0x20ec4(%rip), %rdi     # 0x3c7b5
cmpl $0x0, %r11d
cmovneq %rdi, %rax
leaq 0x20e62(%rip), %rdi     # 0x3c762
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
movb $0x0, %al
callq 0x4050
cmpl $0x1, -0x14(%rbp)
jne 0x1b9a4
movq -0x8(%rbp), %rax
movzbl 0x3(%rax), %ecx
andl $0x4, %ecx
leaq 0x1458d(%rip), %rsi     # 0x2feb9
leaq 0x20eb2(%rip), %rax     # 0x3c7e5
cmpl $0x0, %ecx
cmovneq %rax, %rsi
movq -0x8(%rbp), %rax
movzbl 0x3(%rax), %ecx
andl $0x2, %ecx
leaq 0x1456d(%rip), %rdx     # 0x2feb9
leaq 0x20e96(%rip), %rax     # 0x3c7e9
cmpl $0x0, %ecx
cmovneq %rax, %rdx
movq -0x8(%rbp), %rax
movzbl 0x3(%rax), %edi
andl $0x1, %edi
leaq 0x1454d(%rip), %rcx     # 0x2feb9
leaq 0x20e7a(%rip), %rax     # 0x3c7ed
cmpl $0x0, %edi
cmovneq %rax, %rcx
leaq 0x20e38(%rip), %rdi     # 0x3c7b9
movb $0x0, %al
callq 0x4050
jmp 0x1b9a4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x41f0
jmp 0x1baa6
jmp 0x1ba86
movq -0x8(%rbp), %rcx
movzbl 0x2(%rcx), %eax
shll $0x10, %eax
movzbl 0x1(%rcx), %edx
shll $0x8, %edx
orl %edx, %eax
movzbl (%rcx), %ecx
orl %ecx, %eax
movl %eax, -0x48(%rbp)
movq -0x8(%rbp), %rax
movzbl 0x3(%rax), %eax
shrl $0x4, %eax
movl %eax, -0x5c(%rbp)
subl $0x1, %eax
je 0x1b9ee
jmp 0x1b9da
movl -0x5c(%rbp), %eax
subl $0x2, %eax
je 0x1b9fe
jmp 0x1b9e4
movl -0x5c(%rbp), %eax
subl $0x3, %eax
je 0x1ba0e
jmp 0x1ba1e
leaq 0x20dfc(%rip), %rdi     # 0x3c7f1
movb $0x0, %al
callq 0x4050
jmp 0x1ba39
leaq 0x20e17(%rip), %rdi     # 0x3c81c
movb $0x0, %al
callq 0x4050
jmp 0x1ba39
leaq 0x20e32(%rip), %rdi     # 0x3c847
movb $0x0, %al
callq 0x4050
jmp 0x1ba39
movq -0x8(%rbp), %rax
movzbl 0x3(%rax), %esi
sarl $0x4, %esi
leaq 0x20e42(%rip), %rdi     # 0x3c872
movb $0x0, %al
callq 0x4050
jmp 0x1baa0
movl $0x0, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
cmpq $0x15, %rax
jae 0x1ba84
movl -0x48(%rbp), %eax
movl -0x4c(%rbp), %ecx
shrl %cl, %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x1ba77
movl -0x4c(%rbp), %eax
movl %eax, %ecx
leaq 0x2fc3b(%rip), %rax     # 0x4b6a0
movq (%rax,%rcx,8), %rsi
leaq 0x1e4a5(%rip), %rdi     # 0x39f15
movb $0x0, %al
callq 0x4050
jmp 0x1ba79
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x1ba40
jmp 0x1ba86
movl -0xc(%rbp), %eax
subl $0x4, %eax
movl %eax, -0xc(%rbp)
movq -0x8(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x8(%rbp)
jmp 0x1b7b2
addq $0x70, %rsp
popq %rbp
retq
movq -0x40(%rbp), %rdi
callq 0x4550
nop