// File: /workspace/github_cpp_makefile_star2_O1/rpavlik[P]edid-decode/parse-displayid-block.cpp
// Function: edid_state::parse_displayid_color_characteristics(unsigned char const*)
void edid_state::parse_displayid_color_characteristics(const unsigned char *x)
{
	check_displayid_datablock_revision(x[1], 0xf8, 1);

	unsigned cie_year = (x[1] & 0x80) ? 1976 : 1931;
	unsigned xfer_id = (x[1] >> 3) & 0x0f;
	unsigned num_whitepoints = x[3] & 0x0f;
	unsigned num_primaries = (x[3] >> 4) & 0x07;
	bool temporal_color = x[3] & 0x80;
	unsigned offset = 4;

	printf("    Uses %s color\n", temporal_color ? "temporal" : "spatial");
	printf("    Uses %u CIE (x, y) coordinates\n", cie_year);
	if (xfer_id) {
		printf("    Associated with Transfer Characteristics Data Block with Identifier %u\n", xfer_id);
		if (!(dispid.preparsed_xfer_ids & (1 << xfer_id)))
			fail("Missing Transfer Characteristics Data Block with Identifier %u.\n", xfer_id);
	}
	if (!num_primaries) {
		printf("    Uses color space %s\n",
		       x[4] >= ARRAY_SIZE(std_colorspace_ids) ? "Reserved" :
								std_colorspace_ids[x[4]]);
		offset++;
	}
	for (unsigned i = 0; i < num_primaries; i++) {
		unsigned idx = offset + 3 * i;

		printf("    Primary #%u: (%.4f, %.4f)\n", i,
		       fp2d(x[idx] | ((x[idx + 1] & 0x0f) << 8)),
		       fp2d(((x[idx + 1] & 0xf0) >> 4) | (x[idx + 2] << 4)));
	}
	offset += 3 * num_primaries;
	for (unsigned i = 0; i < num_whitepoints; i++) {
		unsigned idx = offset + 3 * i;

		printf("    White point #%u: (%.4f, %.4f)\n", i,
		       fp2d(x[idx] | ((x[idx + 1] & 0x0f) << 8)),
		       fp2d(((x[idx + 1] & 0xf0) >> 4) | (x[idx + 2] << 4)));
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq %rdi, %r14
movzbl 0x1(%rsi), %edx
andl $0x7, %edx
cmpl $0x1, %edx
je 0x1665f
leaq 0x18522(%rip), %rsi     # 0x2eb70
movl $0x1, %edi
movl $0x1, %ecx
xorl %eax, %eax
callq 0x37ec
movzbl 0x1(%rbx), %ebp
testb %bpl, %bpl
movl $0x78b, %eax            # imm = 0x78B
movl $0x7b8, %r15d           # imm = 0x7B8
cmovnsl %eax, %r15d
shrl $0x3, %ebp
movzbl 0x3(%rbx), %r12d
movl %r12d, %r13d
shrl $0x4, %r13d
andl $0x7, %r13d
testb %r12b, %r12b
leaq 0x18663(%rip), %rax     # 0x2ecf5
leaq 0x18653(%rip), %rsi     # 0x2ecec
cmovnsq %rax, %rsi
leaq 0x18635(%rip), %rdi     # 0x2ecd9
xorl %eax, %eax
callq 0x3030
leaq 0x1864b(%rip), %rdi     # 0x2ecfd
movl %r15d, %esi
xorl %eax, %eax
callq 0x3030
andl $0xf, %ebp
je 0x166f0
leaq 0x18659(%rip), %rdi     # 0x2ed21
movl %ebp, %esi
xorl %eax, %eax
callq 0x3030
movzwl 0x914(%r14), %eax
btl %ebp, %eax
jb 0x166f0
leaq 0x18688(%rip), %rsi     # 0x2ed6d
xorl %edi, %edi
movl %ebp, %edx
xorl %eax, %eax
callq 0x37ec
movl $0x4, %ebp
testl %r13d, %r13d
jne 0x1672e
movzbl 0x4(%rbx), %eax
cmpq $0x8, %rax
jbe 0x1670d
leaq 0x1ae75(%rip), %rsi     # 0x31580
jmp 0x1671b
leaq 0x1822c(%rip), %rcx     # 0x2e940
movslq (%rcx,%rax,4), %rsi
addq %rcx, %rsi
leaq 0x1868c(%rip), %rdi     # 0x2edae
xorl %eax, %eax
callq 0x3030
movl $0x5, %ebp
movq %rbx, (%rsp)
andl $0xf, %r12d
testl %r13d, %r13d
je 0x167a5
movq (%rsp), %rax
leaq (%rax,%rbp), %rbx
addq $0x2, %rbx
xorl %r14d, %r14d
leaq 0x18676(%rip), %r15     # 0x2edc7
movzbl -0x2(%rbx), %eax
movzbl -0x1(%rbx), %ecx
movl %ecx, %edx
andl $0xf, %edx
shll $0x8, %edx
orl %eax, %edx
xorps %xmm0, %xmm0
cvtsi2sd %edx, %xmm0
movsd 0x137ee(%rip), %xmm2    # 0x29f60
mulsd %xmm2, %xmm0
shrl $0x4, %ecx
movzbl (%rbx), %eax
shll $0x4, %eax
orl %ecx, %eax
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
mulsd %xmm2, %xmm1
movq %r15, %rdi
movl %r14d, %esi
movb $0x2, %al
callq 0x3030
incq %r14
addq $0x3, %rbx
cmpq %r14, %r13
jne 0x16751
testl %r12d, %r12d
je 0x1681f
movl %r13d, %eax
leaq (%rax,%rax,2), %rax
addq %rax, %rbp
movq (%rsp), %rax
leaq (%rax,%rbp), %r15
addq $0x2, %r15
xorl %ebx, %ebx
leaq 0x1861d(%rip), %r14     # 0x2ede6
movzbl -0x2(%r15), %eax
movzbl -0x1(%r15), %ecx
movl %ecx, %edx
andl $0xf, %edx
shll $0x8, %edx
orl %eax, %edx
xorps %xmm0, %xmm0
cvtsi2sd %edx, %xmm0
movsd 0x13774(%rip), %xmm2    # 0x29f60
mulsd %xmm2, %xmm0
shrl $0x4, %ecx
movzbl (%r15), %eax
shll $0x4, %eax
orl %ecx, %eax
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
mulsd %xmm2, %xmm1
movq %r14, %rdi
movl %ebx, %esi
movb $0x2, %al
callq 0x3030
incq %rbx
addq $0x3, %r15
cmpq %rbx, %r12
jne 0x167c9
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq