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

	if (length < 2) {
		fail("Empty Data Block with length %u.\n", length);
		return;
	}
	printf("    Electro optical transfer functions:\n");
	for (i = 0; i < 6; i++) {
		if (x[0] & (1 << i)) {
			if (i < ARRAY_SIZE(eotf_map)) {
				printf("      %s\n", eotf_map[i]);
			} else {
				printf("      Unknown (%u)\n", i);
				fail("Unknown EOTF (%u).\n", i);
			}
		}
	}
	printf("    Supported static metadata descriptors:\n");
	for (i = 0; i < 8; i++) {
		if (x[1] & (1 << i))
			printf("      Static metadata type %u\n", i + 1);
	}

	if (length >= 3)
		printf("    Desired content max luminance: %u (%.3f cd/m^2)\n",
		       x[2], 50.0 * pow(2, x[2] / 32.0));

	if (length >= 4)
		printf("    Desired content max frame-average luminance: %u (%.3f cd/m^2)\n",
		       x[3], 50.0 * pow(2, x[3] / 32.0));

	if (length >= 5)
		printf("    Desired content min luminance: %u (%.3f cd/m^2)\n",
		       x[4], (50.0 * pow(2, x[2] / 32.0)) * pow(x[4] / 255.0, 2) / 100.0);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
cmpl $0x2, -0xc(%rbp)
jae 0x1b26d
movl -0xc(%rbp), %edx
xorl %edi, %edi
leaq 0x1e34e(%rip), %rsi     # 0x395af
movb $0x0, %al
callq 0x47d0
jmp 0x1b491
leaq 0x21162(%rip), %rdi     # 0x3c3d6
movb $0x0, %al
callq 0x4050
movl $0x0, -0x10(%rbp)
cmpl $0x6, -0x10(%rbp)
jae 0x1b2fe
movq -0x8(%rbp), %rax
movzbl (%rax), %eax
movl -0x10(%rbp), %ecx
movl $0x1, %edx
shll %cl, %edx
movl %edx, %ecx
andl %ecx, %eax
cmpl $0x0, %eax
je 0x1b2f1
movl -0x10(%rbp), %eax
cmpq $0x4, %rax
jae 0x1b2cb
movl -0x10(%rbp), %eax
movl %eax, %ecx
leaq 0x305b9(%rip), %rax     # 0x4b870
movq (%rax,%rcx,8), %rsi
leaq 0x1ec53(%rip), %rdi     # 0x39f15
movb $0x0, %al
callq 0x4050
jmp 0x1b2ef
movl -0x10(%rbp), %esi
leaq 0x2112a(%rip), %rdi     # 0x3c3ff
movb $0x0, %al
callq 0x4050
movl -0x10(%rbp), %edx
xorl %edi, %edi
leaq 0x2112b(%rip), %rsi     # 0x3c413
movb $0x0, %al
callq 0x47d0
jmp 0x1b2f1
jmp 0x1b2f3
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x1b282
leaq 0x21122(%rip), %rdi     # 0x3c427
movb $0x0, %al
callq 0x4050
movl $0x0, -0x10(%rbp)
cmpl $0x8, -0x10(%rbp)
jae 0x1b355
movq -0x8(%rbp), %rax
movzbl 0x1(%rax), %eax
movl -0x10(%rbp), %ecx
movl $0x1, %edx
shll %cl, %edx
movl %edx, %ecx
andl %ecx, %eax
cmpl $0x0, %eax
je 0x1b348
movl -0x10(%rbp), %esi
addl $0x1, %esi
leaq 0x21112(%rip), %rdi     # 0x3c453
movb $0x0, %al
callq 0x4050
jmp 0x1b34a
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x1b313
cmpl $0x3, -0xc(%rbp)
jb 0x1b3a8
movq -0x8(%rbp), %rax
movzbl 0x2(%rax), %eax
movl %eax, -0x14(%rbp)
movq -0x8(%rbp), %rax
movzbl 0x2(%rax), %eax
cvtsi2sd %eax, %xmm0
movsd 0x1e03e(%rip), %xmm1    # 0x393b8
divsd %xmm1, %xmm0
movl $0x2, %edi
callq 0x20390
movl -0x14(%rbp), %esi
movaps %xmm0, %xmm1
movsd 0x1e01a(%rip), %xmm0    # 0x393b0
mulsd %xmm1, %xmm0
leaq 0x210d1(%rip), %rdi     # 0x3c472
movb $0x1, %al
callq 0x4050
cmpl $0x4, -0xc(%rbp)
jb 0x1b3fb
movq -0x8(%rbp), %rax
movzbl 0x3(%rax), %eax
movl %eax, -0x18(%rbp)
movq -0x8(%rbp), %rax
movzbl 0x3(%rax), %eax
cvtsi2sd %eax, %xmm0
movsd 0x1dfeb(%rip), %xmm1    # 0x393b8
divsd %xmm1, %xmm0
movl $0x2, %edi
callq 0x20390
movl -0x18(%rbp), %esi
movaps %xmm0, %xmm1
movsd 0x1dfc7(%rip), %xmm0    # 0x393b0
mulsd %xmm1, %xmm0
leaq 0x210b3(%rip), %rdi     # 0x3c4a7
movb $0x1, %al
callq 0x4050
cmpl $0x5, -0xc(%rbp)
jb 0x1b491
movq -0x8(%rbp), %rax
movzbl 0x4(%rax), %eax
movl %eax, -0x24(%rbp)
movq -0x8(%rbp), %rax
movzbl 0x2(%rax), %eax
cvtsi2sd %eax, %xmm0
movsd 0x1df94(%rip), %xmm1    # 0x393b8
divsd %xmm1, %xmm0
movl $0x2, %edi
callq 0x20390
movaps %xmm0, %xmm1
movsd 0x1df73(%rip), %xmm0    # 0x393b0
mulsd %xmm1, %xmm0
movsd %xmm0, -0x20(%rbp)
movq -0x8(%rbp), %rax
movzbl 0x4(%rax), %eax
cvtsi2sd %eax, %xmm0
movsd 0x1df66(%rip), %xmm1    # 0x393c0
divsd %xmm1, %xmm0
movl $0x2, %edi
callq 0x203c0
movl -0x24(%rbp), %esi
movaps %xmm0, %xmm1
movsd -0x20(%rbp), %xmm0
mulsd %xmm1, %xmm0
movsd 0x13bb9(%rip), %xmm1    # 0x2f038
divsd %xmm1, %xmm0
leaq 0x21060(%rip), %rdi     # 0x3c4ea
movb $0x1, %al
callq 0x4050
addq $0x30, %rsp
popq %rbp
retq
nopw (%rax,%rax)