// File: /workspace/github_cpp_makefile_star2_O2/rpavlik[P]edid-decode/parse-cta-block.cpp
// Function: edid_state::cta_sldb(unsigned char const*, unsigned int)
void edid_state::cta_sldb(const unsigned char *x, unsigned length)
{
	if (length < 2) {
		fail("Empty Data Block with length %u.\n", length);
		return;
	}

	unsigned active_cnt = 0;
	unsigned channel_is_active = 0;

	while (length >= 2) {
		printf("    Channel: %u (%sactive)\n", x[0] & 0x1f,
		       (x[0] & 0x20) ? "" : "not ");
		if (x[0] & 0x20) {
			if (channel_is_active & (1U << (x[0] & 0x1f)))
				fail("Channel Index %u was already marked 'Active'.\n",
				     x[0] & 0x1f);
			channel_is_active |= 1U << (x[0] & 0x1f);
			active_cnt++;
		}
		if ((x[1] & 0x1f) < ARRAY_SIZE(speaker_location))
			printf("      Speaker: %s\n", speaker_location[x[1] & 0x1f]);
		if (length >= 5 && (x[0] & 0x40)) {
			printf("      X: %.3f * Xmax\n", decode_uchar_as_double(x[2]));
			printf("      Y: %.3f * Ymax\n", decode_uchar_as_double(x[3]));
			printf("      Z: %.3f * Zmax\n", decode_uchar_as_double(x[4]));
			length -= 3;
			x += 3;
		}

		length -= 2;
		x += 2;
	}
	if (active_cnt != cta.preparsed_speaker_count)
		fail("There are %u active speakers, but 'Speaker Count' is %u.\n",
		     active_cnt, cta.preparsed_speaker_count);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %edx, %ebx
cmpl $0x2, %edx
jae 0xd999
leaq 0x167cf(%rip), %rsi     # 0x2414f
xorl %edi, %edi
movl %ebx, %edx
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x362c
movq %rsi, %r13
movq %rdi, 0x10(%rsp)
leaq 0x1e3ec(%rip), %r14     # 0x2bd94
leaq 0xd2da(%rip), %r15      # 0x1ac89
leaq 0x16ece(%rip), %r12     # 0x24884
xorl %ebp, %ebp
movl $0x0, 0xc(%rsp)
cmpl $0x2, %ebx
jb 0xdaea
movzbl (%r13), %eax
movl %eax, %esi
andl $0x1f, %esi
testb $0x20, %al
movq %r15, %rdx
cmoveq %r14, %rdx
movq %r12, %rdi
xorl %eax, %eax
callq 0x3030
movb (%r13), %al
testb $0x20, %al
je 0xda1e
movzbl %al, %edx
andl $0x1f, %edx
movl 0xc(%rsp), %ecx
btl %edx, %ecx
jae 0xda11
xorl %edi, %edi
leaq 0x16e9a(%rip), %rsi     # 0x248a0
xorl %eax, %eax
callq 0x362c
movb (%r13), %al
movl 0xc(%rsp), %ecx
btsl %eax, %ecx
movl %ecx, 0xc(%rsp)
incl %ebp
movzbl 0x1(%r13), %eax
andl $0x1f, %eax
cmpb $0x1b, %al
ja 0xda46
leaq 0x1634b(%rip), %rcx     # 0x23d7c
movslq (%rcx,%rax,4), %rsi
addq %rcx, %rsi
leaq 0x16e90(%rip), %rdi     # 0x248cf
xorl %eax, %eax
callq 0x3030
cmpl $0x5, %ebx
jb 0xdade
testb $0x40, (%r13)
je 0xdade
movsbl 0x2(%r13), %eax
cvtsi2sd %eax, %xmm0
movsd 0x164d5(%rip), %xmm1    # 0x23f40
mulsd %xmm1, %xmm0
leaq 0x16e6c(%rip), %rdi     # 0x248e2
movb $0x1, %al
callq 0x3030
movl %ebp, %r12d
movq %r15, %rbp
movq %r14, %r15
leaq 0x3(%r13), %r14
movsbl 0x3(%r13), %eax
cvtsi2sd %eax, %xmm0
mulsd 0x164a5(%rip), %xmm0    # 0x23f40
leaq 0x16e56(%rip), %rdi     # 0x248f8
movb $0x1, %al
callq 0x3030
movsbl 0x4(%r13), %eax
cvtsi2sd %eax, %xmm0
mulsd 0x16486(%rip), %xmm0    # 0x23f40
leaq 0x16e4d(%rip), %rdi     # 0x2490e
movb $0x1, %al
callq 0x3030
addl $-0x3, %ebx
movq %r14, %r13
movq %r15, %r14
movq %rbp, %r15
movl %r12d, %ebp
leaq 0x16da6(%rip), %r12     # 0x24884
addl $-0x2, %ebx
addq $0x2, %r13
jmp 0xd9c0
movq 0x10(%rsp), %rax
movl 0x2c8(%rax), %ecx
cmpl %ecx, %ebp
jne 0xdb08
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x16e15(%rip), %rsi     # 0x24924
xorl %edi, %edi
movl %ebp, %edx
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x362c