// File: /workspace/github_cpp_makefile_star2_O3/rpavlik[P]edid-decode/parse-cta-block.cpp
// Function: cta_dolby_video(unsigned char const*, unsigned int)
static void cta_dolby_video(const unsigned char *x, unsigned length)
{
	unsigned char version = (x[0] >> 5) & 0x07;

	printf("    Version: %u (%u bytes)\n", version, length + 5);
	if (x[0] & 0x01)
		printf("    Supports YUV422 12 bit\n");

	if (version == 0) {
		if (x[0] & 0x02)
			printf("    Supports 2160p60\n");
		if (x[0] & 0x04)
			printf("    Supports global dimming\n");
		unsigned char dm_version = x[16];
		printf("    DM Version: %u.%u\n", dm_version >> 4, dm_version & 0xf);
		printf("    Target Min PQ: %u\n", (x[14] << 4) | (x[13] >> 4));
		printf("    Target Max PQ: %u\n", (x[15] << 4) | (x[13] & 0xf));
		printf("    Rx, Ry: %.8f, %.8f\n",
		       ((x[1] >> 4) | (x[2] << 4)) / 4096.0,
		       ((x[1] & 0xf) | (x[3] << 4)) / 4096.0);
		printf("    Gx, Gy: %.8f, %.8f\n",
		       ((x[4] >> 4) | (x[5] << 4)) / 4096.0,
		       ((x[4] & 0xf) | (x[6] << 4)) / 4096.0);
		printf("    Bx, By: %.8f, %.8f\n",
		       ((x[7] >> 4) | (x[8] << 4)) / 4096.0,
		       ((x[7] & 0xf) | (x[9] << 4)) / 4096.0);
		printf("    Wx, Wy: %.8f, %.8f\n",
		       ((x[10] >> 4) | (x[11] << 4)) / 4096.0,
		       ((x[10] & 0xf) | (x[12] << 4)) / 4096.0);
		return;
	}

	if (version == 1) {
		if (x[0] & 0x02)
			printf("    Supports 2160p60\n");
		if (x[1] & 0x01)
			printf("    Supports global dimming\n");
		unsigned char dm_version = (x[0] >> 2) & 0x07;
		printf("    DM Version: %u.x\n", dm_version + 2);
		printf("    Colorimetry: %s\n", (x[2] & 0x01) ? "P3-D65" : "ITU-R BT.709");
		printf("    Low Latency: %s\n", (x[3] & 0x01) ? "Standard + Low Latency" : "Only Standard");
		printf("    Target Max Luminance: %u cd/m^2\n", 100 + (x[1] >> 1) * 50);
		double lm = (x[2] >> 1) / 127.0;
		printf("    Target Min Luminance: %.8f cd/m^2\n", lm * lm);
		if (length == 10) {
			printf("    Rx, Ry: %.8f, %.8f\n", x[4] / 256.0, x[5] / 256.0);
			printf("    Gx, Gy: %.8f, %.8f\n", x[6] / 256.0, x[7] / 256.0);
			printf("    Bx, By: %.8f, %.8f\n", x[8] / 256.0, x[9] / 256.0);
		} else {
			double xmin = 0.625;
			double xstep = (0.74609375 - xmin) / 31.0;
			double ymin = 0.25;
			double ystep = (0.37109375 - ymin) / 31.0;

			printf("    Unique Rx, Ry: %.8f, %.8f\n",
			       xmin + xstep * (x[6] >> 3),
			       ymin + ystep * (((x[6] & 0x7) << 2) | (x[4] & 0x01) | ((x[5] & 0x01) << 1)));
			xstep = 0.49609375 / 127.0;
			ymin = 0.5;
			ystep = (0.99609375 - ymin) / 127.0;
			printf("    Unique Gx, Gy: %.8f, %.8f\n",
			       xstep * (x[4] >> 1), ymin + ystep * (x[5] >> 1));
			xmin = 0.125;
			xstep = (0.15234375 - xmin) / 7.0;
			ymin = 0.03125;
			ystep = (0.05859375 - ymin) / 7.0;
			printf("    Unique Bx, By: %.8f, %.8f\n",
			       xmin + xstep * (x[3] >> 5),
			       ymin + ystep * ((x[3] >> 2) & 0x07));
		}
		return;
	}

	if (version == 2) {
		if (x[0] & 0x02)
			printf("    Supports Backlight Control\n");
		if (x[1] & 0x04)
			printf("    Supports global dimming\n");
		unsigned char dm_version = (x[0] >> 2) & 0x07;
		printf("    DM Version: %u.x\n", dm_version + 2);
		printf("    Backlt Min Luma: %u cd/m^2\n", 25 + (x[1] & 0x03) * 25);
		printf("    Interface: ");
		switch (x[2] & 0x03) {
		case 0: printf("Low-Latency\n"); break;
		case 1: printf("Low-Latency + Low-Latency-HDMI\n"); break;
		case 2: printf("Standard + Low-Latency\n"); break;
		case 3: printf("Standard + Low-Latency + Low-Latency-HDMI\n"); break;
		}
		printf("    Supports 10b 12b 444: ");
		switch ((x[3] & 0x01) << 1 | (x[4] & 0x01)) {
		case 0: printf("Not supported\n"); break;
		case 1: printf("10 bit\n"); break;
		case 2: printf("12 bit\n"); break;
		case 3: printf("Reserved\n"); break;
		}
		printf("    Target Min PQ v2: %u\n", 20 * (x[1] >> 3));
		printf("    Target Max PQ v2: %u\n", 2055 + 65 * (x[2] >> 3));

		double xmin = 0.625;
		double xstep = (0.74609375 - xmin) / 31.0;
		double ymin = 0.25;
		double ystep = (0.37109375 - ymin) / 31.0;

		printf("    Unique Rx, Ry: %.8f, %.8f\n",
		       xmin + xstep * (x[5] >> 3),
		       ymin + ystep * (x[6] >> 3));
		xstep = 0.49609375 / 127.0;
		ymin = 0.5;
		ystep = (0.99609375 - ymin) / 127.0;
		printf("    Unique Gx, Gy: %.8f, %.8f\n",
		       xstep * (x[3] >> 1), ymin + ystep * (x[4] >> 1));
		xmin = 0.125;
		xstep = (0.15234375 - xmin) / 7.0;
		ymin = 0.03125;
		ystep = (0.05859375 - ymin) / 7.0;
		printf("    Unique Bx, By: %.8f, %.8f\n",
		       xmin + xstep * (x[5] & 0x07),
		       ymin + ystep * (x[6] & 0x07));
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movl %esi, %r14d
movq %rdi, %rbx
movzbl (%rdi), %r15d
movl %r15d, %ebp
shrl $0x5, %ebp
leal 0x5(%r14), %edx
leaq 0x19c2e(%rip), %rdi     # 0x2beab
movl %ebp, %esi
xorl %eax, %eax
callq 0x3030
testb $0x1, (%rbx)
je 0x12297
leaq 0x1b74e(%rip), %rdi     # 0x2d9e0
callq 0x3380
cmpb $0x1f, %r15b
ja 0x1243b
movb (%rbx), %al
testb $0x2, %al
je 0x122b5
leaq 0x1b7c2(%rip), %rdi     # 0x2da70
callq 0x3380
movb (%rbx), %al
testb $0x4, %al
je 0x122c5
leaq 0x1b7c5(%rip), %rdi     # 0x2da85
callq 0x3380
movzbl 0x10(%rbx), %edx
movl %edx, %esi
shrl $0x4, %esi
andl $0xf, %edx
leaq 0x19bef(%rip), %rdi     # 0x2bec7
xorl %eax, %eax
callq 0x3030
movzbl 0xe(%rbx), %eax
shll $0x4, %eax
movzbl 0xd(%rbx), %esi
shrl $0x4, %esi
orl %eax, %esi
leaq 0x19be8(%rip), %rdi     # 0x2bede
xorl %eax, %eax
callq 0x3030
movzbl 0xf(%rbx), %eax
shll $0x4, %eax
movzbl 0xd(%rbx), %esi
andl $0xf, %esi
orl %eax, %esi
leaq 0x19be1(%rip), %rdi     # 0x2bef5
xorl %eax, %eax
callq 0x3030
movzbl 0x1(%rbx), %eax
movl %eax, %ecx
shrl $0x4, %ecx
movzbl 0x2(%rbx), %edx
shll $0x4, %edx
orl %ecx, %edx
cvtsi2sd %edx, %xmm0
movsd 0x17c4f(%rip), %xmm2    # 0x29f88
mulsd %xmm2, %xmm0
andl $0xf, %eax
movzbl 0x3(%rbx), %ecx
shll $0x4, %ecx
orl %eax, %ecx
cvtsi2sd %ecx, %xmm1
mulsd %xmm2, %xmm1
leaq 0x19bb4(%rip), %rdi     # 0x2bf0c
movb $0x2, %al
callq 0x3030
movzbl 0x4(%rbx), %eax
movl %eax, %ecx
shrl $0x4, %ecx
movzbl 0x5(%rbx), %edx
shll $0x4, %edx
orl %ecx, %edx
xorps %xmm0, %xmm0
cvtsi2sd %edx, %xmm0
movsd 0x17c08(%rip), %xmm2    # 0x29f88
mulsd %xmm2, %xmm0
andl $0xf, %eax
movzbl 0x6(%rbx), %ecx
shll $0x4, %ecx
orl %eax, %ecx
xorps %xmm1, %xmm1
cvtsi2sd %ecx, %xmm1
mulsd %xmm2, %xmm1
leaq 0x19b82(%rip), %rdi     # 0x2bf24
movb $0x2, %al
callq 0x3030
movzbl 0x7(%rbx), %eax
movl %eax, %ecx
shrl $0x4, %ecx
movzbl 0x8(%rbx), %edx
shll $0x4, %edx
orl %ecx, %edx
xorps %xmm0, %xmm0
cvtsi2sd %edx, %xmm0
movsd 0x17bbe(%rip), %xmm2    # 0x29f88
mulsd %xmm2, %xmm0
andl $0xf, %eax
movzbl 0x9(%rbx), %ecx
shll $0x4, %ecx
orl %eax, %ecx
xorps %xmm1, %xmm1
cvtsi2sd %ecx, %xmm1
mulsd %xmm2, %xmm1
leaq 0x19b50(%rip), %rdi     # 0x2bf3c
movb $0x2, %al
callq 0x3030
movzbl 0xa(%rbx), %eax
movl %eax, %ecx
shrl $0x4, %ecx
movzbl 0xb(%rbx), %edx
shll $0x4, %edx
orl %ecx, %edx
xorps %xmm0, %xmm0
cvtsi2sd %edx, %xmm0
movsd 0x17b74(%rip), %xmm2    # 0x29f88
mulsd %xmm2, %xmm0
andl $0xf, %eax
movzbl 0xc(%rbx), %ecx
shll $0x4, %ecx
orl %eax, %ecx
xorps %xmm1, %xmm1
cvtsi2sd %ecx, %xmm1
mulsd %xmm2, %xmm1
leaq 0x19b1e(%rip), %rdi     # 0x2bf54
jmp 0x12859
cmpb $0x2, %bpl
je 0x125b8
movzbl %bpl, %eax
cmpl $0x1, %eax
jne 0x12766
testb $0x2, (%rbx)
je 0x12463
leaq 0x1b612(%rip), %rdi     # 0x2da70
callq 0x3380
testb $0x1, 0x1(%rbx)
je 0x12475
leaq 0x1b615(%rip), %rdi     # 0x2da85
callq 0x3380
movzbl (%rbx), %esi
shrl $0x2, %esi
andl $0x7, %esi
addl $0x2, %esi
leaq 0x19ae4(%rip), %rdi     # 0x2bf6c
xorl %eax, %eax
callq 0x3030
testb $0x1, 0x2(%rbx)
leaq 0x19b04(%rip), %rax     # 0x2bf9e
leaq 0x19af6(%rip), %rsi     # 0x2bf97
cmoveq %rax, %rsi
leaq 0x19ad6(%rip), %rdi     # 0x2bf82
xorl %eax, %eax
callq 0x3030
testb $0x1, 0x3(%rbx)
leaq 0x19b19(%rip), %rax     # 0x2bfd7
leaq 0x19afb(%rip), %rsi     # 0x2bfc0
cmoveq %rax, %rsi
leaq 0x19adb(%rip), %rdi     # 0x2bfab
xorl %eax, %eax
callq 0x3030
movzbl 0x1(%rbx), %eax
shrl %eax
imull $0x32, %eax, %esi
addl $0x64, %esi
leaq 0x19afb(%rip), %rdi     # 0x2bfe5
xorl %eax, %eax
callq 0x3030
movb 0x2(%rbx), %al
shrb %al
movzbl %al, %eax
cvtsi2sd %eax, %xmm0
divsd 0x17a7b(%rip), %xmm0    # 0x29f80
mulsd %xmm0, %xmm0
leaq 0x19afa(%rip), %rdi     # 0x2c00a
movb $0x1, %al
callq 0x3030
cmpl $0xa, %r14d
jne 0x12771
movzbl 0x4(%rbx), %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd 0x17a2c(%rip), %xmm2    # 0x29f60
mulsd %xmm2, %xmm0
movzbl 0x5(%rbx), %eax
cvtsi2sd %eax, %xmm1
mulsd %xmm2, %xmm1
leaq 0x199c1(%rip), %rdi     # 0x2bf0c
movb $0x2, %al
callq 0x3030
movzbl 0x6(%rbx), %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd 0x179fb(%rip), %xmm2    # 0x29f60
mulsd %xmm2, %xmm0
movzbl 0x7(%rbx), %eax
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
mulsd %xmm2, %xmm1
leaq 0x199a5(%rip), %rdi     # 0x2bf24
movb $0x2, %al
callq 0x3030
movzbl 0x8(%rbx), %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd 0x179c7(%rip), %xmm2    # 0x29f60
mulsd %xmm2, %xmm0
movzbl 0x9(%rbx), %eax
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
mulsd %xmm2, %xmm1
leaq 0x19989(%rip), %rdi     # 0x2bf3c
jmp 0x12859
testb $0x2, (%rbx)
je 0x125c9
leaq 0x1b437(%rip), %rdi     # 0x2d9fb
callq 0x3380
testb $0x4, 0x1(%rbx)
je 0x125db
leaq 0x1b4af(%rip), %rdi     # 0x2da85
callq 0x3380
movzbl (%rbx), %esi
shrl $0x2, %esi
andl $0x7, %esi
addl $0x2, %esi
leaq 0x1997e(%rip), %rdi     # 0x2bf6c
xorl %eax, %eax
callq 0x3030
movzbl 0x1(%rbx), %eax
andl $0x3, %eax
leal (%rax,%rax,4), %eax
leal (%rax,%rax,4), %esi
addl $0x19, %esi
leaq 0x19a82(%rip), %rdi     # 0x2c08e
xorl %eax, %eax
callq 0x3030
leaq 0x19a94(%rip), %rdi     # 0x2c0ae
xorl %eax, %eax
callq 0x3030
movzbl 0x2(%rbx), %eax
andl $0x3, %eax
leaq 0x178e1(%rip), %rcx     # 0x29f10
movslq (%rcx,%rax,4), %rdi
addq %rcx, %rdi
callq 0x3380
leaq 0x19a7c(%rip), %rdi     # 0x2c0be
xorl %eax, %eax
callq 0x3030
movzbl 0x3(%rbx), %eax
andl $0x1, %eax
movzbl 0x4(%rbx), %ecx
andl $0x1, %ecx
leal (%rcx,%rax,2), %eax
leaq 0x178bf(%rip), %rcx     # 0x29f20
movslq (%rcx,%rax,4), %rdi
addq %rcx, %rdi
callq 0x3380
movzbl 0x1(%rbx), %eax
shrl %eax
andl $-0x4, %eax
leal (%rax,%rax,4), %esi
leaq 0x19a59(%rip), %rdi     # 0x2c0d9
xorl %eax, %eax
callq 0x3030
movzbl 0x2(%rbx), %eax
shrl $0x3, %eax
movl %eax, %ecx
shll $0x6, %ecx
leal (%rax,%rcx), %esi
addl $0x807, %esi            # imm = 0x807
leaq 0x19a50(%rip), %rdi     # 0x2c0f3
xorl %eax, %eax
callq 0x3030
movb 0x5(%rbx), %al
movb 0x6(%rbx), %cl
shrb $0x3, %al
movzbl %al, %eax
cvtsi2sd %eax, %xmm0
movsd 0x1789e(%rip), %xmm2    # 0x29f60
mulsd %xmm2, %xmm0
addsd 0x1789a(%rip), %xmm0    # 0x29f68
shrb $0x3, %cl
movzbl %cl, %eax
cvtsi2sd %eax, %xmm1
mulsd %xmm2, %xmm1
addsd 0x1788c(%rip), %xmm1    # 0x29f70
leaq 0x19946(%rip), %rdi     # 0x2c031
movb $0x2, %al
callq 0x3030
movb 0x3(%rbx), %al
movb 0x4(%rbx), %cl
shrb %al
movzbl %al, %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
shrb %cl
movzbl %cl, %eax
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
movsd 0x17848(%rip), %xmm2    # 0x29f60
mulsd %xmm2, %xmm0
mulsd %xmm2, %xmm1
addsd 0xd8e8(%rip), %xmm1     # 0x20010
leaq 0x19921(%rip), %rdi     # 0x2c050
movb $0x2, %al
callq 0x3030
movb 0x5(%rbx), %al
andb $0x7, %al
movzbl %al, %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movb 0x6(%rbx), %al
movsd 0x17810(%rip), %xmm2    # 0x29f60
mulsd %xmm2, %xmm0
addsd 0x1781c(%rip), %xmm0    # 0x29f78
andb $0x7, %al
movzbl %al, %eax
jmp 0x1283f
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movzbl 0x6(%rbx), %eax
movl %eax, %ecx
shrl $0x3, %ecx
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
movsd 0x177d7(%rip), %xmm1    # 0x29f60
mulsd %xmm1, %xmm0
movapd %xmm1, %xmm2
addsd 0x177cf(%rip), %xmm0    # 0x29f68
andl $0x7, %eax
movzbl 0x4(%rbx), %ecx
andl $0x1, %ecx
leal (%rcx,%rax,4), %eax
movzbl 0x5(%rbx), %ecx
andl $0x1, %ecx
leal (%rax,%rcx,2), %eax
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
mulsd %xmm2, %xmm1
addsd 0x177ad(%rip), %xmm1    # 0x29f70
leaq 0x19867(%rip), %rdi     # 0x2c031
movb $0x2, %al
callq 0x3030
movb 0x4(%rbx), %al
movb 0x5(%rbx), %cl
shrb %al
movzbl %al, %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
shrb %cl
movzbl %cl, %eax
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
movsd 0x17769(%rip), %xmm2    # 0x29f60
mulsd %xmm2, %xmm0
mulsd %xmm2, %xmm1
addsd 0xd809(%rip), %xmm1     # 0x20010
leaq 0x19842(%rip), %rdi     # 0x2c050
movb $0x2, %al
callq 0x3030
movzbl 0x3(%rbx), %eax
movl %eax, %ecx
shrl $0x5, %ecx
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
movsd 0x17733(%rip), %xmm2    # 0x29f60
mulsd %xmm2, %xmm0
addsd 0x1773f(%rip), %xmm0    # 0x29f78
shrl $0x2, %eax
andl $0x7, %eax
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
mulsd %xmm2, %xmm1
addsd 0x176f6(%rip), %xmm1    # 0x29f48
leaq 0x19816(%rip), %rdi     # 0x2c06f
movb $0x2, %al
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x3030