// File: /workspace/github_cpp_makefile_star2_O1/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 0x19a5d(%rip), %rdi     # 0x2be83
movl %ebp, %esi
xorl %eax, %eax
callq 0x3030
testb $0x1, (%rbx)
je 0x12440
leaq 0x1b57d(%rip), %rdi     # 0x2d9b8
callq 0x3380
cmpb $0x1f, %r15b
ja 0x125e2
testb $0x2, (%rbx)
je 0x1245b
leaq 0x1b5f2(%rip), %rdi     # 0x2da48
callq 0x3380
testb $0x4, (%rbx)
je 0x1246c
leaq 0x1b5f6(%rip), %rdi     # 0x2da5d
callq 0x3380
movzbl 0x10(%rbx), %edx
movl %edx, %esi
shrl $0x4, %esi
andl $0xf, %edx
leaq 0x19a20(%rip), %rdi     # 0x2be9f
xorl %eax, %eax
callq 0x3030
movzbl 0xe(%rbx), %eax
shll $0x4, %eax
movzbl 0xd(%rbx), %esi
shrl $0x4, %esi
orl %eax, %esi
leaq 0x19a19(%rip), %rdi     # 0x2beb6
xorl %eax, %eax
callq 0x3030
movzbl 0xf(%rbx), %eax
shll $0x4, %eax
movzbl 0xd(%rbx), %esi
andl $0xf, %esi
orl %eax, %esi
leaq 0x19a12(%rip), %rdi     # 0x2becd
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 0x17a80(%rip), %xmm2    # 0x29f60
mulsd %xmm2, %xmm0
andl $0xf, %eax
movzbl 0x3(%rbx), %ecx
shll $0x4, %ecx
orl %eax, %ecx
cvtsi2sd %ecx, %xmm1
mulsd %xmm2, %xmm1
leaq 0x199e5(%rip), %rdi     # 0x2bee4
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 0x17a39(%rip), %xmm2    # 0x29f60
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 0x199b3(%rip), %rdi     # 0x2befc
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 0x179ef(%rip), %xmm2    # 0x29f60
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 0x19981(%rip), %rdi     # 0x2bf14
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 0x179a5(%rip), %xmm2    # 0x29f60
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 0x1994f(%rip), %rdi     # 0x2bf2c
jmp 0x12a00
cmpb $0x2, %bpl
je 0x1275f
movzbl %bpl, %eax
cmpl $0x1, %eax
jne 0x1290d
testb $0x2, (%rbx)
je 0x1260a
leaq 0x1b443(%rip), %rdi     # 0x2da48
callq 0x3380
testb $0x1, 0x1(%rbx)
je 0x1261c
leaq 0x1b446(%rip), %rdi     # 0x2da5d
callq 0x3380
movzbl (%rbx), %esi
shrl $0x2, %esi
andl $0x7, %esi
addl $0x2, %esi
leaq 0x19915(%rip), %rdi     # 0x2bf44
xorl %eax, %eax
callq 0x3030
testb $0x1, 0x2(%rbx)
leaq 0x19935(%rip), %rax     # 0x2bf76
leaq 0x19927(%rip), %rsi     # 0x2bf6f
cmoveq %rax, %rsi
leaq 0x19907(%rip), %rdi     # 0x2bf5a
xorl %eax, %eax
callq 0x3030
testb $0x1, 0x3(%rbx)
leaq 0x1994a(%rip), %rax     # 0x2bfaf
leaq 0x1992c(%rip), %rsi     # 0x2bf98
cmoveq %rax, %rsi
leaq 0x1990c(%rip), %rdi     # 0x2bf83
xorl %eax, %eax
callq 0x3030
movzbl 0x1(%rbx), %eax
shrl %eax
imull $0x32, %eax, %esi
addl $0x64, %esi
leaq 0x1992c(%rip), %rdi     # 0x2bfbd
xorl %eax, %eax
callq 0x3030
movb 0x2(%rbx), %al
shrb %al
movzbl %al, %eax
cvtsi2sd %eax, %xmm0
divsd 0x178ac(%rip), %xmm0    # 0x29f58
mulsd %xmm0, %xmm0
leaq 0x1992b(%rip), %rdi     # 0x2bfe2
movb $0x1, %al
callq 0x3030
cmpl $0xa, %r14d
jne 0x12918
movzbl 0x4(%rbx), %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd 0x1785d(%rip), %xmm2    # 0x29f38
mulsd %xmm2, %xmm0
movzbl 0x5(%rbx), %eax
cvtsi2sd %eax, %xmm1
mulsd %xmm2, %xmm1
leaq 0x197f2(%rip), %rdi     # 0x2bee4
movb $0x2, %al
callq 0x3030
movzbl 0x6(%rbx), %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd 0x1782c(%rip), %xmm2    # 0x29f38
mulsd %xmm2, %xmm0
movzbl 0x7(%rbx), %eax
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
mulsd %xmm2, %xmm1
leaq 0x197d6(%rip), %rdi     # 0x2befc
movb $0x2, %al
callq 0x3030
movzbl 0x8(%rbx), %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd 0x177f8(%rip), %xmm2    # 0x29f38
mulsd %xmm2, %xmm0
movzbl 0x9(%rbx), %eax
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
mulsd %xmm2, %xmm1
leaq 0x197ba(%rip), %rdi     # 0x2bf14
jmp 0x12a00
testb $0x2, (%rbx)
je 0x12770
leaq 0x1b268(%rip), %rdi     # 0x2d9d3
callq 0x3380
testb $0x4, 0x1(%rbx)
je 0x12782
leaq 0x1b2e0(%rip), %rdi     # 0x2da5d
callq 0x3380
movzbl (%rbx), %esi
shrl $0x2, %esi
andl $0x7, %esi
addl $0x2, %esi
leaq 0x197af(%rip), %rdi     # 0x2bf44
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 0x198b3(%rip), %rdi     # 0x2c066
xorl %eax, %eax
callq 0x3030
leaq 0x198c5(%rip), %rdi     # 0x2c086
xorl %eax, %eax
callq 0x3030
movzbl 0x2(%rbx), %eax
andl $0x3, %eax
leaq 0x17712(%rip), %rcx     # 0x29ee8
movslq (%rcx,%rax,4), %rdi
addq %rcx, %rdi
callq 0x3380
leaq 0x198ad(%rip), %rdi     # 0x2c096
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 0x176f0(%rip), %rcx     # 0x29ef8
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 0x1988a(%rip), %rdi     # 0x2c0b1
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 0x19881(%rip), %rdi     # 0x2c0cb
xorl %eax, %eax
callq 0x3030
movb 0x5(%rbx), %al
movb 0x6(%rbx), %cl
shrb $0x3, %al
movzbl %al, %eax
cvtsi2sd %eax, %xmm0
movsd 0x176cf(%rip), %xmm2    # 0x29f38
mulsd %xmm2, %xmm0
addsd 0x176cb(%rip), %xmm0    # 0x29f40
shrb $0x3, %cl
movzbl %cl, %eax
cvtsi2sd %eax, %xmm1
mulsd %xmm2, %xmm1
addsd 0x176bd(%rip), %xmm1    # 0x29f48
leaq 0x19777(%rip), %rdi     # 0x2c009
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 0x17679(%rip), %xmm2    # 0x29f38
mulsd %xmm2, %xmm0
mulsd %xmm2, %xmm1
addsd 0xd739(%rip), %xmm1     # 0x20008
leaq 0x19752(%rip), %rdi     # 0x2c028
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 0x17641(%rip), %xmm2    # 0x29f38
mulsd %xmm2, %xmm0
addsd 0x1764d(%rip), %xmm0    # 0x29f50
andb $0x7, %al
movzbl %al, %eax
jmp 0x129e6
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 0x17608(%rip), %xmm1    # 0x29f38
mulsd %xmm1, %xmm0
movapd %xmm1, %xmm2
addsd 0x17600(%rip), %xmm0    # 0x29f40
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 0x175de(%rip), %xmm1    # 0x29f48
leaq 0x19698(%rip), %rdi     # 0x2c009
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 0x1759a(%rip), %xmm2    # 0x29f38
mulsd %xmm2, %xmm0
mulsd %xmm2, %xmm1
addsd 0xd65a(%rip), %xmm1     # 0x20008
leaq 0x19673(%rip), %rdi     # 0x2c028
movb $0x2, %al
callq 0x3030
movzbl 0x3(%rbx), %eax
movl %eax, %ecx
shrl $0x5, %ecx
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
movsd 0x17564(%rip), %xmm2    # 0x29f38
mulsd %xmm2, %xmm0
addsd 0x17570(%rip), %xmm0    # 0x29f50
shrl $0x2, %eax
andl $0x7, %eax
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
mulsd %xmm2, %xmm1
addsd 0x17527(%rip), %xmm1    # 0x29f20
leaq 0x19647(%rip), %rdi     # 0x2c047
movb $0x2, %al
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x3030