// File: /workspace/github_cpp_makefile_star2_O3/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 0x100c1
leaq 0x1a0a7(%rip), %rsi     # 0x2a14f
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 0x37cc
movq %rsi, %r12
movq %rdi, 0x10(%rsp)
leaq 0x21cc4(%rip), %r15     # 0x31d94
leaq 0x10bb2(%rip), %r14     # 0x20c89
leaq 0x1a7a6(%rip), %r13     # 0x2a884
movl $0x0, 0xc(%rsp)
xorl %ebp, %ebp
movzbl (%r12), %eax
movl %eax, %esi
andl $0x1f, %esi
testb $0x20, %al
movq %r14, %rdx
cmoveq %r15, %rdx
movq %r13, %rdi
xorl %eax, %eax
callq 0x3030
movb (%r12), %al
testb $0x20, %al
je 0x1013d
movzbl %al, %edx
andl $0x1f, %edx
movl 0xc(%rsp), %ecx
btl %edx, %ecx
jae 0x10130
xorl %edi, %edi
leaq 0x1a77b(%rip), %rsi     # 0x2a8a0
xorl %eax, %eax
callq 0x37cc
movb (%r12), %al
movl 0xc(%rsp), %ecx
btsl %eax, %ecx
movl %ecx, 0xc(%rsp)
incl %ebp
movzbl 0x1(%r12), %eax
andl $0x1f, %eax
cmpb $0x1b, %al
ja 0x10166
leaq 0x19c2b(%rip), %rcx     # 0x29d7c
movslq (%rcx,%rax,4), %rsi
addq %rcx, %rsi
leaq 0x1a770(%rip), %rdi     # 0x2a8cf
xorl %eax, %eax
callq 0x3030
cmpl $0x5, %ebx
jb 0x1020b
testb $0x40, (%r12)
je 0x1020b
movsbl 0x2(%r12), %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd 0x19db1(%rip), %xmm1    # 0x29f40
mulsd %xmm1, %xmm0
leaq 0x1a748(%rip), %rdi     # 0x2a8e2
movb $0x1, %al
callq 0x3030
movl %ebp, %r13d
movq %r14, %rbp
movq %r15, %r14
leaq 0x3(%r12), %r15
movsbl 0x3(%r12), %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
mulsd 0x19d7c(%rip), %xmm0    # 0x29f40
leaq 0x1a72d(%rip), %rdi     # 0x2a8f8
movb $0x1, %al
callq 0x3030
movsbl 0x4(%r12), %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
mulsd 0x19d59(%rip), %xmm0    # 0x29f40
leaq 0x1a720(%rip), %rdi     # 0x2a90e
movb $0x1, %al
callq 0x3030
addl $-0x3, %ebx
movq %r15, %r12
movq %r14, %r15
movq %rbp, %r14
movl %r13d, %ebp
leaq 0x1a679(%rip), %r13     # 0x2a884
addl $-0x2, %ebx
addq $0x2, %r12
cmpl $0x1, %ebx
ja 0x100e8
movq 0x10(%rsp), %rax
movl 0x2c8(%rax), %ecx
cmpl %ecx, %ebp
jne 0x10239
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1a6e4(%rip), %rsi     # 0x2a924
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 0x37cc
nop