// File: /workspace/github_cpp_makefile_star2_O2/rpavlik[P]edid-decode/parse-displayid-block.cpp
// Function: edid_state::parse_displayid_tiled_display_topology(unsigned char const*, bool)
void edid_state::parse_displayid_tiled_display_topology(const unsigned char *x, bool is_v2)
{
	check_displayid_datablock_revision(x[1]);

	if (!check_displayid_datablock_length(x, 22, 22))
		return;

	unsigned caps = x[3];
	unsigned num_v_tile = (x[4] & 0xf) | (x[6] & 0x30);
	unsigned num_h_tile = (x[4] >> 4) | ((x[6] >> 2) & 0x30);
	unsigned tile_v_location = (x[5] & 0xf) | ((x[6] & 0x3) << 4);
	unsigned tile_h_location = (x[5] >> 4) | (((x[6] >> 2) & 0x3) << 4);
	unsigned tile_width = x[7] | (x[8] << 8);
	unsigned tile_height = x[9] | (x[10] << 8);
	unsigned pix_mult = x[11];

	printf("    Capabilities:\n");
	printf("      Behavior if it is the only tile: ");
	switch (caps & 0x07) {
	case 0x00: printf("Undefined\n"); break;
	case 0x01: printf("Image is displayed at the Tile Location\n"); break;
	case 0x02: printf("Image is scaled to fit the entire tiled display\n"); break;
	case 0x03: printf("Image is cloned to all other tiles\n"); break;
	default: printf("Reserved\n"); break;
	}
	printf("      Behavior if more than one tile and fewer than total number of tiles: ");
	switch ((caps >> 3) & 0x03) {
	case 0x00: printf("Undefined\n"); break;
	case 0x01: printf("Image is displayed at the Tile Location\n"); break;
	default: printf("Reserved\n"); break;
	}
	if (caps & 0x80)
		printf("    Tiled display consists of a single physical display enclosure\n");
	else
		printf("    Tiled display consists of multiple physical display enclosures\n");
	printf("    Num horizontal tiles: %u Num vertical tiles: %u\n",
	       num_h_tile + 1, num_v_tile + 1);
	printf("    Tile location: %u, %u\n", tile_h_location, tile_v_location);
	printf("    Tile resolution: %ux%u\n", tile_width + 1, tile_height + 1);
	if (caps & 0x40) {
		if (pix_mult) {
			printf("    Top bevel size: %.1f pixels\n",
			       pix_mult * x[12] / 10.0);
			printf("    Bottom bevel size: %.1f pixels\n",
			       pix_mult * x[13] / 10.0);
			printf("    Right bevel size: %.1f pixels\n",
			       pix_mult * x[14] / 10.0);
			printf("    Left bevel size: %.1f pixels\n",
			       pix_mult * x[15] / 10.0);
		} else {
			fail("No bevel information, but the pixel multiplier is non-zero.\n");
		}
		printf("    Tile resolution: %ux%u\n", tile_width + 1, tile_height + 1);
	} else if (pix_mult) {
		fail("No bevel information, but the pixel multiplier is non-zero.\n");
	}
	if (is_v2)
		printf("    Tiled Display Manufacturer/Vendor ID: %02X-%02X-%02X\n",
		       x[0x10], x[0x11], x[0x12]);
	else
		printf("    Tiled Display Manufacturer/Vendor ID: %c%c%c\n",
		       x[0x10], x[0x11], x[0x12]);
	printf("    Tiled Display Product ID Code: %u\n",
	       x[0x13] | (x[0x14] << 8));
	if (hide_serial_numbers)
		printf("    Tiled Display Serial Number: ...\n");
	else
		printf("    Tiled Display Serial Number: %u\n",
		       x[0x15] | (x[0x16] << 8) | (x[0x17] << 16)| (x[0x18] << 24));
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %edx, %ebp
movq %rsi, %rbx
movq %rdi, %r14
movzbl 0x1(%rsi), %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x123f0
pushq $0x16
popq %rdx
movq %rbx, %rdi
movl %edx, %esi
xorl %ecx, %ecx
callq 0x126fe
testb %al, %al
je 0x14ad5
movl %ebp, 0x10(%rsp)
movq %r14, 0x20(%rsp)
movzbl 0x3(%rbx), %r15d
movzbl 0x4(%rbx), %r12d
movl %r12d, %eax
andl $0xf, %eax
movq %rax, 0x30(%rsp)
movzbl 0x6(%rbx), %eax
movl %eax, %ecx
andl $0x30, %ecx
movq %rcx, 0x28(%rsp)
shrl $0x4, %r12d
movl %eax, %r14d
shrl $0x2, %r14d
andl $-0x10, %r14d
movzbl 0x5(%rbx), %ecx
movl %ecx, %edx
andl $0xf, %edx
movl %eax, %r13d
shll $0x4, %r13d
andl $0x30, %r13d
orl %edx, %r13d
shrl $0x4, %ecx
andl $0xc, %eax
leal (%rcx,%rax,4), %eax
movl %eax, 0x14(%rsp)
movzwl 0x7(%rbx), %eax
movl %eax, 0x1c(%rsp)
movzwl 0x9(%rbx), %eax
movl %eax, 0x18(%rsp)
movzbl 0xb(%rbx), %eax
movl %eax, 0xc(%rsp)
leaq 0x16c0d(%rip), %rdi     # 0x2b5c9
callq 0x33b0
leaq 0x14d9e(%rip), %rdi     # 0x29766
xorl %eax, %eax
callq 0x3030
movq %r15, %rbp
movl %r15d, %eax
andl $0x7, %eax
leaq 0x16be1(%rip), %r15     # 0x2b5c0
movq %r15, %rdi
cmpl $0x3, %eax
ja 0x149f5
leaq 0x14166(%rip), %rcx     # 0x28b54
movslq (%rcx,%rax,4), %rdi
addq %rcx, %rdi
callq 0x33b0
leaq 0x14d8d(%rip), %rdi     # 0x2978e
xorl %eax, %eax
callq 0x3030
movl %ebp, %eax
shrl $0x3, %eax
andl $0x3, %eax
cmpl $0x1, %eax
leaq 0x16c14(%rip), %rcx     # 0x2b62e
cmoveq %rcx, %r15
testl %eax, %eax
leaq 0x1308e(%rip), %rdi     # 0x27ab5
cmovneq %r15, %rdi
callq 0x33b0
testb %bpl, %bpl
leaq 0x16c1c(%rip), %rax     # 0x2b656
leaq 0x16c58(%rip), %rdi     # 0x2b699
cmovnsq %rax, %rdi
callq 0x33b0
leal (%r12,%r14), %esi
incl %esi
movq 0x30(%rsp), %rax
movq 0x28(%rsp), %rcx
leal (%rax,%rcx), %edx
incl %edx
leaq 0x14d74(%rip), %rdi     # 0x297da
xorl %eax, %eax
callq 0x3030
leaq 0x14d9b(%rip), %rdi     # 0x2980f
movl 0x14(%rsp), %esi
movl %r13d, %edx
xorl %eax, %eax
callq 0x3030
movl 0x1c(%rsp), %r15d
incl %r15d
movl 0x18(%rsp), %r12d
incl %r12d
leaq 0x14d91(%rip), %rdi     # 0x2982a
movl %r15d, %esi
movl %r12d, %edx
xorl %eax, %eax
callq 0x3030
testb $0x40, %bpl
jne 0x14ae4
cmpb $0x0, 0xc(%rsp)
movq 0x20(%rsp), %r14
movl 0x10(%rsp), %ebp
je 0x14ba9
leaq 0x14e09(%rip), %rsi     # 0x298d0
xorl %edi, %edi
xorl %eax, %eax
callq 0x362c
jmp 0x14ba9
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl 0xc(%rsp), %r13d
testb %r13b, %r13b
movq 0x20(%rsp), %r14
movl 0x10(%rsp), %ebp
je 0x14b85
movzbl 0xc(%rbx), %eax
imull %r13d, %eax
cvtsi2sd %eax, %xmm0
divsd 0x13b21(%rip), %xmm0    # 0x28630
leaq 0x14d30(%rip), %rdi     # 0x29846
movb $0x1, %al
callq 0x3030
movzbl 0xd(%rbx), %eax
imull %r13d, %eax
cvtsi2sd %eax, %xmm0
divsd 0x13aff(%rip), %xmm0    # 0x28630
leaq 0x14d2f(%rip), %rdi     # 0x29867
movb $0x1, %al
callq 0x3030
movzbl 0xe(%rbx), %eax
imull %r13d, %eax
cvtsi2sd %eax, %xmm0
divsd 0x13add(%rip), %xmm0    # 0x28630
leaq 0x14d31(%rip), %rdi     # 0x2988b
movb $0x1, %al
callq 0x3030
movzbl 0xf(%rbx), %eax
imull %r13d, %eax
cvtsi2sd %eax, %xmm0
divsd 0x13abb(%rip), %xmm0    # 0x28630
leaq 0x14d32(%rip), %rdi     # 0x298ae
movb $0x1, %al
callq 0x3030
jmp 0x14b95
leaq 0x14d44(%rip), %rsi     # 0x298d0
xorl %edi, %edi
xorl %eax, %eax
callq 0x362c
leaq 0x14c8e(%rip), %rdi     # 0x2982a
movl %r15d, %esi
movl %r12d, %edx
xorl %eax, %eax
callq 0x3030
movzbl 0x10(%rbx), %esi
movzbl 0x11(%rbx), %edx
movzbl 0x12(%rbx), %ecx
leaq 0x14d51(%rip), %rax     # 0x2990d
leaq 0x14d84(%rip), %rdi     # 0x29947
testb %bpl, %bpl
cmovneq %rax, %rdi
xorl %eax, %eax
callq 0x3030
movzwl 0x13(%rbx), %esi
leaq 0x14d9d(%rip), %rdi     # 0x29979
xorl %eax, %eax
callq 0x3030
cmpb $0x1, 0x52(%r14)
jne 0x14c04
leaq 0x16aea(%rip), %rdi     # 0x2b6db
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x33b0
movl 0x15(%rbx), %esi
leaq 0x14d92(%rip), %rdi     # 0x299a0
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3030
nop