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

	if (length % 3) {
		fail("Broken CTA-861 audio block length %d.\n", length);
		return;
	}

	for (i = 0; i < length; i += 3) {
		format = (x[i] & 0x78) >> 3;
		if (format == 0) {
			printf("    Reserved (0x00)\n");
			fail("Audio Format Code 0x00 is reserved.\n");
			continue;
		}
		if (format != 15) {
			ext_format = 0;
			printf("    %s:\n", audio_format(format).c_str());
		} else {
			ext_format = (x[i + 2] & 0xf8) >> 3;
			printf("    %s:\n", audio_ext_format(ext_format).c_str());
		}
		if (format != 15)
			printf("      Max channels: %u\n", (x[i] & 0x07)+1);
		else if (ext_format == 11)
			printf("      MPEG-H 3D Audio Level: %s\n",
			       mpeg_h_3d_audio_level(x[i] & 0x07).c_str());
		else if (ext_format == 13)
			printf("      Max channels: %u\n",
			       (((x[i + 1] & 0x80) >> 3) | ((x[i] & 0x80) >> 4) |
				(x[i] & 0x07))+1);
		else
			printf("      Max channels: %u\n", (x[i] & 0x07)+1);

		printf("      Supported sample rates (kHz):%s%s%s%s%s%s%s\n",
		       (x[i+1] & 0x40) ? " 192" : "",
		       (x[i+1] & 0x20) ? " 176.4" : "",
		       (x[i+1] & 0x10) ? " 96" : "",
		       (x[i+1] & 0x08) ? " 88.2" : "",
		       (x[i+1] & 0x04) ? " 48" : "",
		       (x[i+1] & 0x02) ? " 44.1" : "",
		       (x[i+1] & 0x01) ? " 32" : "");
		if (format == 1 || ext_format == 13) {
			printf("      Supported sample sizes (bits):%s%s%s\n",
			       (x[i+2] & 0x04) ? " 24" : "",
			       (x[i+2] & 0x02) ? " 20" : "",
			       (x[i+2] & 0x01) ? " 16" : "");
		} else if (format <= 8) {
			printf("      Maximum bit rate: %u kb/s\n", x[i+2] * 8);
		} else if (format == 10) {
			// As specified by the "Dolby Audio and Dolby Atmos over HDMI"
			// specification (v1.0).
			if (x[i+2] & 1)
				printf("      Supports Joint Object Coding\n");
			if (x[i+2] & 2)
				printf("      Supports Joint Object Coding with ACMOD28\n");
		} else if (format == 12) {
			if (x[i+2] & 1) {
				printf("      Supports Dolby TrueHD, object audio PCM and channel-based PCM\n");
				printf("      Hash calculation %srequired for object audio PCM or channel-based PCM\n",
				       (x[i+2] & 2) ? "not " : "");
			} else {
				printf("      Supports only Dolby TrueHD\n");
			}
		} else if (format == 14) {
			printf("      Profile: %u\n", x[i+2] & 7);
		} else if (format >= 9 && format <= 13) {
			printf("      Audio Format Code dependent value: 0x%02x\n", x[i+2]);
		} else if (ext_format == 11 && (x[i+2] & 1)) {
			printf("      Supports MPEG-H 3D Audio Low Complexity Profile\n");
		} else if ((ext_format >= 4 && ext_format <= 6) ||
			   ext_format == 8 || ext_format == 10) {
			printf("      AAC audio frame lengths:%s%s\n",
			       (x[i+2] & 4) ? " 1024_TL" : "",
			       (x[i+2] & 2) ? " 960_TL" : "");
			if (ext_format >= 8 && (x[i+2] & 1))
				printf("      Supports %s signaled MPEG Surround data\n",
				       (x[i+2] & 1) ? "implicitly and explicitly" : "only implicitly");
			if (ext_format == 6 && (x[i+2] & 1))
				printf("      Supports 22.2ch System H\n");
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl -0xc(%rbp), %eax
movl $0x3, %ecx
xorl %edx, %edx
divl %ecx
cmpl $0x0, %edx
je 0x1cadb
movl -0xc(%rbp), %edx
xorl %edi, %edi
leaq 0x20846(%rip), %rsi     # 0x3d315
movb $0x0, %al
callq 0x47d0
jmp 0x1d184
movl $0x0, -0x10(%rbp)
movl -0x10(%rbp), %eax
cmpl -0xc(%rbp), %eax
jae 0x1d184
movq -0x8(%rbp), %rax
movl -0x10(%rbp), %ecx
movzbl (%rax,%rcx), %eax
andl $0x78, %eax
sarl $0x3, %eax
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
jne 0x1cb2b
leaq 0x2082d(%rip), %rdi     # 0x3d33c
movb $0x0, %al
callq 0x4050
xorl %edi, %edi
leaq 0x20832(%rip), %rsi     # 0x3d351
movb $0x0, %al
callq 0x47d0
jmp 0x1d176
cmpl $0xf, -0x14(%rbp)
je 0x1cb93
movl $0x0, -0x18(%rbp)
movzbl -0x14(%rbp), %esi
leaq -0x38(%rbp), %rdi
movq %rdi, -0x90(%rbp)
callq 0x1ea20
movq -0x90(%rbp), %rdi
callq 0x4150
movq %rax, %rsi
leaq 0x1758d(%rip), %rdi     # 0x340ef
xorl %eax, %eax
callq 0x4050
jmp 0x1cb6b
leaq -0x38(%rbp), %rdi
callq 0x41f0
jmp 0x1cbff
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x41f0
jmp 0x1d18d
movq -0x8(%rbp), %rax
movl -0x10(%rbp), %ecx
addl $0x2, %ecx
movzbl (%rax,%rcx), %eax
shrl $0x3, %eax
movl %eax, -0x18(%rbp)
movzbl -0x18(%rbp), %esi
leaq -0x68(%rbp), %rdi
movq %rdi, -0x98(%rbp)
callq 0x1f030
movq -0x98(%rbp), %rdi
callq 0x4150
movq %rax, %rsi
leaq 0x1751e(%rip), %rdi     # 0x340ef
xorl %eax, %eax
callq 0x4050
jmp 0x1cbda
leaq -0x68(%rbp), %rdi
callq 0x41f0
jmp 0x1cbff
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x41f0
jmp 0x1d18d
cmpl $0xf, -0x14(%rbp)
je 0x1cc29
movq -0x8(%rbp), %rax
movl -0x10(%rbp), %ecx
movzbl (%rax,%rcx), %esi
andl $0x7, %esi
addl $0x1, %esi
leaq 0x20759(%rip), %rdi     # 0x3d376
movb $0x0, %al
callq 0x4050
jmp 0x1cd17
cmpl $0xb, -0x18(%rbp)
jne 0x1cc9d
movq -0x8(%rbp), %rax
movl -0x10(%rbp), %ecx
movzbl (%rax,%rcx), %esi
andl $0x7, %esi
leaq -0x88(%rbp), %rdi
movq %rdi, -0xa0(%rbp)
callq 0x1f5c0
movq -0xa0(%rbp), %rdi
callq 0x4150
movq %rax, %rsi
leaq 0x20728(%rip), %rdi     # 0x3d38e
xorl %eax, %eax
callq 0x4050
jmp 0x1cc6f
leaq -0x88(%rbp), %rdi
callq 0x41f0
jmp 0x1cd15
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x88(%rbp), %rdi
callq 0x41f0
jmp 0x1d18d
cmpl $0xd, -0x18(%rbp)
jne 0x1ccf4
movq -0x8(%rbp), %rax
movl -0x10(%rbp), %ecx
addl $0x1, %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %esi
andl $0x80, %esi
sarl $0x3, %esi
movq -0x8(%rbp), %rax
movl -0x10(%rbp), %ecx
movzbl (%rax,%rcx), %eax
andl $0x80, %eax
sarl $0x4, %eax
orl %eax, %esi
movq -0x8(%rbp), %rax
movl -0x10(%rbp), %ecx
movzbl (%rax,%rcx), %eax
andl $0x7, %eax
orl %eax, %esi
addl $0x1, %esi
leaq 0x2068b(%rip), %rdi     # 0x3d376
movb $0x0, %al
callq 0x4050
jmp 0x1cd13
movq -0x8(%rbp), %rax
movl -0x10(%rbp), %ecx
movzbl (%rax,%rcx), %esi
andl $0x7, %esi
addl $0x1, %esi
leaq 0x2066a(%rip), %rdi     # 0x3d376
movb $0x0, %al
callq 0x4050
jmp 0x1cd15
jmp 0x1cd17
movq -0x8(%rbp), %rax
movl -0x10(%rbp), %ecx
addl $0x1, %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %ecx
andl $0x40, %ecx
leaq 0x13188(%rip), %rsi     # 0x2feb9
leaq 0x1fa5d(%rip), %rax     # 0x3c795
cmpl $0x0, %ecx
cmovneq %rax, %rsi
movq -0x8(%rbp), %rax
movl -0x10(%rbp), %ecx
addl $0x1, %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %ecx
andl $0x20, %ecx
leaq 0x13160(%rip), %rdx     # 0x2feb9
leaq 0x1fa3a(%rip), %rax     # 0x3c79a
cmpl $0x0, %ecx
cmovneq %rax, %rdx
movq -0x8(%rbp), %rax
movl -0x10(%rbp), %ecx
addl $0x1, %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %edi
andl $0x10, %edi
leaq 0x13138(%rip), %rcx     # 0x2feb9
leaq 0x1fa19(%rip), %rax     # 0x3c7a1
cmpl $0x0, %edi
cmovneq %rax, %rcx
movq -0x8(%rbp), %rax
movl -0x10(%rbp), %edi
addl $0x1, %edi
movl %edi, %edi
movzbl (%rax,%rdi), %edi
andl $0x8, %edi
leaq 0x13110(%rip), %r8      # 0x2feb9
leaq 0x1f9f5(%rip), %rax     # 0x3c7a5
cmpl $0x0, %edi
cmovneq %rax, %r8
movq -0x8(%rbp), %rax
movl -0x10(%rbp), %edi
addl $0x1, %edi
movl %edi, %edi
movzbl (%rax,%rdi), %edi
andl $0x4, %edi
leaq 0x130e8(%rip), %r9      # 0x2feb9
leaq 0x1f9d3(%rip), %rax     # 0x3c7ab
cmpl $0x0, %edi
cmovneq %rax, %r9
movq -0x8(%rbp), %rax
movl -0x10(%rbp), %edi
addl $0x1, %edi
movl %edi, %edi
movzbl (%rax,%rdi), %edi
andl $0x2, %edi
leaq 0x130c0(%rip), %r10     # 0x2feb9
leaq 0x1f9af(%rip), %rax     # 0x3c7af
cmpl $0x0, %edi
cmovneq %rax, %r10
movq -0x8(%rbp), %rax
movl -0x10(%rbp), %edi
addl $0x1, %edi
movl %edi, %edi
movzbl (%rax,%rdi), %r11d
andl $0x1, %r11d
leaq 0x13096(%rip), %rax     # 0x2feb9
leaq 0x1f98b(%rip), %rdi     # 0x3c7b5
cmpl $0x0, %r11d
cmovneq %rdi, %rax
leaq 0x1f929(%rip), %rdi     # 0x3c762
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
movb $0x0, %al
callq 0x4050
cmpl $0x1, -0x14(%rbp)
je 0x1ce59
cmpl $0xd, -0x18(%rbp)
jne 0x1cee4
movq -0x8(%rbp), %rax
movl -0x10(%rbp), %ecx
addl $0x2, %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %ecx
andl $0x4, %ecx
leaq 0x13046(%rip), %rsi     # 0x2feb9
leaq 0x1f96b(%rip), %rax     # 0x3c7e5
cmpl $0x0, %ecx
cmovneq %rax, %rsi
movq -0x8(%rbp), %rax
movl -0x10(%rbp), %ecx
addl $0x2, %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %ecx
andl $0x2, %ecx
leaq 0x1301e(%rip), %rdx     # 0x2feb9
leaq 0x1f947(%rip), %rax     # 0x3c7e9
cmpl $0x0, %ecx
cmovneq %rax, %rdx
movq -0x8(%rbp), %rax
movl -0x10(%rbp), %ecx
addl $0x2, %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %edi
andl $0x1, %edi
leaq 0x12ff6(%rip), %rcx     # 0x2feb9
leaq 0x1f923(%rip), %rax     # 0x3c7ed
cmpl $0x0, %edi
cmovneq %rax, %rcx
leaq 0x1f8e1(%rip), %rdi     # 0x3c7b9
movb $0x0, %al
callq 0x4050
jmp 0x1d174
cmpl $0x8, -0x14(%rbp)
ja 0x1cf10
movq -0x8(%rbp), %rax
movl -0x10(%rbp), %ecx
addl $0x2, %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %esi
shll $0x3, %esi
leaq 0x204ab(%rip), %rdi     # 0x3d3af
movb $0x0, %al
callq 0x4050
jmp 0x1d172
cmpl $0xa, -0x14(%rbp)
jne 0x1cf67
movq -0x8(%rbp), %rax
movl -0x10(%rbp), %ecx
addl $0x2, %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x1cf3c
leaq 0x2049b(%rip), %rdi     # 0x3d3d0
movb $0x0, %al
callq 0x4050
movq -0x8(%rbp), %rax
movl -0x10(%rbp), %ecx
addl $0x2, %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x1cf62
leaq 0x20499(%rip), %rdi     # 0x3d3f4
movb $0x0, %al
callq 0x4050
jmp 0x1d170
cmpl $0xc, -0x14(%rbp)
jne 0x1cfde
movq -0x8(%rbp), %rax
movl -0x10(%rbp), %ecx
addl $0x2, %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x1cfcb
leaq 0x20499(%rip), %rdi     # 0x3d425
movb $0x0, %al
callq 0x4050
movq -0x8(%rbp), %rax
movl -0x10(%rbp), %ecx
addl $0x2, %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %ecx
andl $0x2, %ecx
leaq 0x12f0c(%rip), %rsi     # 0x2feb9
leaq 0x24690(%rip), %rax     # 0x41644
cmpl $0x0, %ecx
cmovneq %rax, %rsi
leaq 0x204a8(%rip), %rdi     # 0x3d46a
movb $0x0, %al
callq 0x4050
jmp 0x1cfd9
leaq 0x204e5(%rip), %rdi     # 0x3d4b7
movb $0x0, %al
callq 0x4050
jmp 0x1d16e
cmpl $0xe, -0x14(%rbp)
jne 0x1d00a
movq -0x8(%rbp), %rax
movl -0x10(%rbp), %ecx
addl $0x2, %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %esi
andl $0x7, %esi
leaq 0x204db(%rip), %rdi     # 0x3d4d9
movb $0x0, %al
callq 0x4050
jmp 0x1d16c
cmpl $0x9, -0x14(%rbp)
jb 0x1d039
cmpl $0xd, -0x14(%rbp)
ja 0x1d039
movq -0x8(%rbp), %rax
movl -0x10(%rbp), %ecx
addl $0x2, %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %esi
leaq 0x204bf(%rip), %rdi     # 0x3d4ec
movb $0x0, %al
callq 0x4050
jmp 0x1d16a
cmpl $0xb, -0x18(%rbp)
jne 0x1d06a
movq -0x8(%rbp), %rax
movl -0x10(%rbp), %ecx
addl $0x2, %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x1d06a
leaq 0x204bf(%rip), %rdi     # 0x3d51d
movb $0x0, %al
callq 0x4050
jmp 0x1d168
cmpl $0x4, -0x18(%rbp)
jb 0x1d076
cmpl $0x6, -0x18(%rbp)
jbe 0x1d086
cmpl $0x8, -0x18(%rbp)
je 0x1d086
cmpl $0xa, -0x18(%rbp)
jne 0x1d166
movq -0x8(%rbp), %rax
movl -0x10(%rbp), %ecx
addl $0x2, %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %ecx
andl $0x4, %ecx
leaq 0x12e19(%rip), %rsi     # 0x2feb9
leaq 0x204d1(%rip), %rax     # 0x3d578
cmpl $0x0, %ecx
cmovneq %rax, %rsi
movq -0x8(%rbp), %rax
movl -0x10(%rbp), %ecx
addl $0x2, %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %ecx
andl $0x2, %ecx
leaq 0x12df1(%rip), %rdx     # 0x2feb9
leaq 0x204b2(%rip), %rax     # 0x3d581
cmpl $0x0, %ecx
cmovneq %rax, %rdx
leaq 0x20477(%rip), %rdi     # 0x3d554
movb $0x0, %al
callq 0x4050
cmpl $0x8, -0x18(%rbp)
jb 0x1d138
movq -0x8(%rbp), %rax
movl -0x10(%rbp), %ecx
addl $0x2, %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x1d138
movq -0x8(%rbp), %rax
movl -0x10(%rbp), %ecx
addl $0x2, %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %ecx
andl $0x1, %ecx
leaq 0x204b6(%rip), %rsi     # 0x3d5d2
leaq 0x20495(%rip), %rax     # 0x3d5b8
cmpl $0x0, %ecx
cmovneq %rax, %rsi
leaq 0x20458(%rip), %rdi     # 0x3d589
movb $0x0, %al
callq 0x4050
cmpl $0x6, -0x18(%rbp)
jne 0x1d164
movq -0x8(%rbp), %rax
movl -0x10(%rbp), %ecx
addl $0x2, %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x1d164
leaq 0x20485(%rip), %rdi     # 0x3d5e2
movb $0x0, %al
callq 0x4050
jmp 0x1d166
jmp 0x1d168
jmp 0x1d16a
jmp 0x1d16c
jmp 0x1d16e
jmp 0x1d170
jmp 0x1d172
jmp 0x1d174
jmp 0x1d176
movl -0x10(%rbp), %eax
addl $0x3, %eax
movl %eax, -0x10(%rbp)
jmp 0x1cae2
addq $0xb0, %rsp
popq %rbp
retq
movq -0x40(%rbp), %rdi
callq 0x4550
nopw %cs:(%rax,%rax)