// File: /workspace/github_cpp_makefile_star2_O3/rpavlik[P]edid-decode/parse-di-ext-block.cpp
// Function: edid_state::parse_display_xfer(unsigned char const*)
void edid_state::parse_display_xfer(const unsigned char *x)
{
	data_block = "Display Transfer Characteristics - Gamma";
	printf("  %s:\n", data_block.c_str());

	unsigned char v = x[0x51];
	unsigned num_entries = v & 0x3f;

	switch ((v & 0xc0) >> 6) {
	case 0x00:
		printf("    No Display Transfer Characteristics\n");
		if (!memchk(x + 0x51, 46))
			fail("Bytes 0x51-0x7e should be 0.\n");
		return;
	case 0x03:
		fail("Bits 7-6 of byte 0x51 cannot be 0x03.\n");
		return;
	default:
		break;
	}

	if (((v & 0xc0) >> 6) == 0x01) {
		if (!num_entries || num_entries > 45)
			fail("White Curve with %u entries.\n", num_entries);
		if (num_entries > 45)
			num_entries = 45;
		if (!memchk(x + 0x52 + num_entries, 45 - num_entries))
			fail("Bytes 0x%02x-0x7e should be 0.\n", 0x52 + num_entries);
		printf("    White Curve (%u entries):\n", num_entries);
		hex_block("      ", x + 0x52, num_entries, false, 15);
	} else {
		if (!num_entries || num_entries > 15)
			fail("Sub-Channel Curve with %u entries.\n", num_entries);
		if (num_entries > 15)
			num_entries = 15;
		printf("    Sub-Channel 0 (Blue) Curve with %u entries:\n", num_entries);
		hex_block("      ", x + 0x52, num_entries, false);
		if (!memchk(x + 0x52 + num_entries, 15 - num_entries))
			fail("Bytes 0x%02x-0x7e should be 0.\n", 0x52 + num_entries);
		printf("    Sub-Channel 1 (Green) Curve with %u entries:\n", num_entries);
		hex_block("      ", x + 0x52 + 15, num_entries, false);
		if (!memchk(x + 0x52 + 15 + num_entries, 15 - num_entries))
			fail("Bytes 0x%02x-0x7e should be 0.\n", 0x52 + 15 + num_entries);
		printf("    Sub-Channel 2 (Red) Curve with %u entries:\n", num_entries);
		hex_block("      ", x + 0x52 + 30, num_entries, false);
		if (!memchk(x + 0x52 + 30 + num_entries, 15 - num_entries))
			fail("Bytes 0x%02x-0x7e should be 0.\n", 0x52 + 30 + num_entries);
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq %rdi, %r14
addq $0x30, %rdi
movq 0x38(%r14), %rdx
leaq 0x1412d(%rip), %rcx     # 0x32a59
movl $0x28, %r8d
xorl %esi, %esi
callq 0x3390
movq 0x30(%r14), %rsi
leaq 0x64c7(%rip), %rdi      # 0x24e0b
xorl %eax, %eax
callq 0x3030
movzbl 0x51(%rbx), %eax
movl %eax, %r15d
andl $0x3f, %r15d
shrl $0x6, %eax
leaq 0x1316c(%rip), %rcx     # 0x31acc
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
addq $0x51, %rbx
leaq 0x149cf(%rip), %rdi     # 0x33343
callq 0x3380
movq %rbx, %rdi
movl $0x2e, %esi
xorl %edx, %edx
callq 0x5ba5
testb %al, %al
jne 0x1eabb
leaq 0x140eb(%rip), %rsi     # 0x32a82
jmp 0x1eacd
leal -0x10(%r15), %eax
cmpl $-0x10, %eax
ja 0x1e9b8
leaq 0x14178(%rip), %rsi     # 0x32b24
xorl %edi, %edi
movl %r15d, %edx
xorl %eax, %eax
callq 0x37cc
cmpl $0xf, %r15d
movl $0xf, %r14d
cmovbl %r15d, %r14d
leaq 0x1417b(%rip), %rdi     # 0x32b48
movl %r14d, %esi
xorl %eax, %eax
callq 0x3030
leaq 0x52(%rbx), %rsi
leaq 0x6ab3(%rip), %rdi      # 0x25495
movl %r14d, %edx
xorl %ecx, %ecx
movl $0x10, %r8d
callq 0x5bd2
leaq (%rbx,%r14), %rdi
addq $0x52, %rdi
movl %r14d, %ebp
xorl $0xf, %ebp
movl %ebp, %esi
xorl %edx, %edx
callq 0x5ba5
testb %al, %al
jne 0x1ea21
leal 0x52(%r14), %edx
leaq 0x140cd(%rip), %rsi     # 0x32ae5
xorl %edi, %edi
xorl %eax, %eax
callq 0x37cc
leaq 0x14151(%rip), %rdi     # 0x32b79
movl %r14d, %esi
xorl %eax, %eax
callq 0x3030
leaq 0x61(%rbx), %rsi
leaq 0x6a58(%rip), %rdi      # 0x25495
movl %r14d, %edx
xorl %ecx, %ecx
movl $0x10, %r8d
callq 0x5bd2
leaq (%rbx,%r14), %rdi
addq $0x61, %rdi
movl %ebp, %esi
xorl %edx, %edx
callq 0x5ba5
testb %al, %al
jne 0x1ea76
leal 0x61(%r14), %edx
leaq 0x14078(%rip), %rsi     # 0x32ae5
xorl %edi, %edi
xorl %eax, %eax
callq 0x37cc
leaq 0x1412e(%rip), %rdi     # 0x32bab
movl %r14d, %esi
xorl %eax, %eax
callq 0x3030
leaq 0x70(%rbx), %rsi
leaq 0x6a03(%rip), %rdi      # 0x25495
movl %r14d, %edx
xorl %ecx, %ecx
movl $0x10, %r8d
callq 0x5bd2
leaq (%rbx,%r14), %rdi
addq $0x70, %rdi
movl %ebp, %esi
xorl %edx, %edx
callq 0x5ba5
testb %al, %al
je 0x1eb6b
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
leaq 0x13fd3(%rip), %rsi     # 0x32aa0
xorl %edi, %edi
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x37cc
leal -0x2e(%r15), %eax
cmpl $-0x2e, %eax
ja 0x1eafc
leaq 0x13fd7(%rip), %rsi     # 0x32ac7
xorl %edi, %edi
movl %r15d, %edx
xorl %eax, %eax
callq 0x37cc
movl $0x2d, %esi
cmpl %esi, %r15d
cmovael %esi, %r15d
leaq (%rbx,%r15), %rdi
addq $0x52, %rdi
addq $0x52, %rbx
subl %r15d, %esi
xorl %edx, %edx
callq 0x5ba5
testb %al, %al
jne 0x1eb36
leal 0x52(%r15), %edx
leaq 0x13fb8(%rip), %rsi     # 0x32ae5
xorl %edi, %edi
xorl %eax, %eax
callq 0x37cc
leaq 0x13fc8(%rip), %rdi     # 0x32b05
movl %r15d, %esi
xorl %eax, %eax
callq 0x3030
leaq 0x6947(%rip), %rdi      # 0x25495
movq %rbx, %rsi
movl %r15d, %edx
xorl %ecx, %ecx
movl $0xf, %r8d
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x5bd2
orl $0x70, %r14d
leaq 0x13f6f(%rip), %rsi     # 0x32ae5
xorl %edi, %edi
movl %r14d, %edx
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x37cc