// File: /workspace/github_cpp_makefile_star2_O3/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), %r15d
movl %r15d, %edx
andl $0x7, %edx
cmpl $0x1, %edx
je 0x1650b
leaq 0x186ba(%rip), %rsi     # 0x2ebb0
movl $0x1, %edi
movl $0x1, %ecx
xorl %eax, %eax
callq 0x37cc
movb 0x1(%rbx), %r15b
testb %r15b, %r15b
movl $0x78b, %eax            # imm = 0x78B
movl $0x7b8, %ebp            # imm = 0x7B8
cmovnsl %eax, %ebp
shrb $0x3, %r15b
andb $0xf, %r15b
movzbl 0x3(%rbx), %r12d
movl %r12d, %r13d
shrl $0x4, %r13d
andl $0x7, %r13d
testb %r12b, %r12b
leaq 0x187f8(%rip), %rax     # 0x2ed35
leaq 0x187e8(%rip), %rsi     # 0x2ed2c
cmovnsq %rax, %rsi
leaq 0x187ca(%rip), %rdi     # 0x2ed19
xorl %eax, %eax
callq 0x3030
leaq 0x187e0(%rip), %rdi     # 0x2ed3d
movl %ebp, %esi
xorl %eax, %eax
callq 0x3030
testb %r15b, %r15b
je 0x1659e
movzbl %r15b, %ebp
leaq 0x187eb(%rip), %rdi     # 0x2ed61
movl %ebp, %esi
xorl %eax, %eax
callq 0x3030
movzwl 0x914(%r14), %eax
btl %ebp, %eax
jb 0x1659e
leaq 0x1881a(%rip), %rsi     # 0x2edad
xorl %edi, %edi
movl %ebp, %edx
xorl %eax, %eax
callq 0x37cc
andl $0xf, %r12d
testl %r13d, %r13d
je 0x16611
leaq 0x6(%rbx), %rbp
xorl %r14d, %r14d
leaq 0x18852(%rip), %r15     # 0x2ee07
movzbl -0x2(%rbp), %eax
movzbl -0x1(%rbp), %ecx
movl %ecx, %edx
andl $0xf, %edx
shll $0x8, %edx
orl %eax, %edx
xorps %xmm0, %xmm0
cvtsi2sd %edx, %xmm0
movsd 0x139b2(%rip), %xmm2    # 0x29f88
mulsd %xmm2, %xmm0
shrl $0x4, %ecx
movzbl (%rbp), %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, %rbp
cmpq %r14, %r13
jne 0x165b5
movl $0x4, %eax
jmp 0x16645
movzbl 0x4(%rbx), %eax
cmpq $0x8, %rax
jbe 0x16624
leaq 0x1af9e(%rip), %rsi     # 0x315c0
jmp 0x16632
leaq 0x1833d(%rip), %rcx     # 0x2e968
movslq (%rcx,%rax,4), %rsi
addq %rcx, %rsi
leaq 0x187b5(%rip), %rdi     # 0x2edee
xorl %eax, %eax
callq 0x3030
movl $0x5, %eax
testl %r12d, %r12d
je 0x166bb
movl %r13d, %ecx
leaq (%rcx,%rcx,2), %rcx
addq %rcx, %rax
leaq (%rbx,%rax), %r15
addq $0x2, %r15
xorl %ebx, %ebx
leaq 0x187c1(%rip), %r14     # 0x2ee26
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 0x13900(%rip), %xmm2    # 0x29f88
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 0x16665
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq