// File: /workspace/github_cpp_makefile_star2_O1/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 0x1627c
movq %rbx, %rdi
movl $0x16, %esi
movl $0x16, %edx
xorl %ecx, %ecx
callq 0x165ab
testb %al, %al
je 0x19228
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 0x1847a(%rip), %rdi     # 0x31589
callq 0x3380
leaq 0x1660b(%rip), %rdi     # 0x2f726
xorl %eax, %eax
callq 0x3030
movq %r15, %rbp
movl %r15d, %eax
andl $0x7, %eax
leaq 0x1844e(%rip), %r15     # 0x31580
movq %r15, %rdi
cmpl $0x3, %eax
ja 0x19148
leaq 0x159e3(%rip), %rcx     # 0x2eb24
movslq (%rcx,%rax,4), %rdi
addq %rcx, %rdi
callq 0x3380
leaq 0x165fa(%rip), %rdi     # 0x2f74e
xorl %eax, %eax
callq 0x3030
movl %ebp, %eax
shrl $0x3, %eax
andl $0x3, %eax
cmpl $0x1, %eax
leaq 0x18481(%rip), %rcx     # 0x315ee
cmoveq %rcx, %r15
testl %eax, %eax
leaq 0x1490e(%rip), %rdi     # 0x2da88
cmovneq %r15, %rdi
callq 0x3380
testb %bpl, %bpl
leaq 0x18489(%rip), %rax     # 0x31616
leaq 0x184c5(%rip), %rdi     # 0x31659
cmovnsq %rax, %rdi
callq 0x3380
leal (%r12,%r14), %esi
incl %esi
movq 0x30(%rsp), %rax
movq 0x28(%rsp), %rcx
leal (%rax,%rcx), %edx
incl %edx
leaq 0x165e1(%rip), %rdi     # 0x2f79a
xorl %eax, %eax
callq 0x3030
leaq 0x16608(%rip), %rdi     # 0x2f7cf
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 0x165fe(%rip), %rdi     # 0x2f7ea
movl %r15d, %esi
movl %r12d, %edx
xorl %eax, %eax
callq 0x3030
testb $0x40, %bpl
jne 0x19237
cmpb $0x0, 0xc(%rsp)
movq 0x20(%rsp), %r14
movl 0x10(%rsp), %ebp
je 0x19305
leaq 0x16676(%rip), %rsi     # 0x2f890
xorl %edi, %edi
xorl %eax, %eax
callq 0x37ec
jmp 0x19305
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 0x192e1
movzbl 0xc(%rbx), %eax
imull %r13d, %eax
cvtsi2sd %eax, %xmm0
divsd 0x1539e(%rip), %xmm0    # 0x2e600
leaq 0x1659d(%rip), %rdi     # 0x2f806
movb $0x1, %al
callq 0x3030
movzbl 0xd(%rbx), %eax
imull %r13d, %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
divsd 0x15379(%rip), %xmm0    # 0x2e600
leaq 0x16599(%rip), %rdi     # 0x2f827
movb $0x1, %al
callq 0x3030
movzbl 0xe(%rbx), %eax
imull %r13d, %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
divsd 0x15354(%rip), %xmm0    # 0x2e600
leaq 0x16598(%rip), %rdi     # 0x2f84b
movb $0x1, %al
callq 0x3030
movzbl 0xf(%rbx), %eax
imull %r13d, %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
divsd 0x1532f(%rip), %xmm0    # 0x2e600
leaq 0x16596(%rip), %rdi     # 0x2f86e
movb $0x1, %al
callq 0x3030
jmp 0x192f1
leaq 0x165a8(%rip), %rsi     # 0x2f890
xorl %edi, %edi
xorl %eax, %eax
callq 0x37ec
leaq 0x164f2(%rip), %rdi     # 0x2f7ea
movl %r15d, %esi
movl %r12d, %edx
xorl %eax, %eax
callq 0x3030
movzbl 0x10(%rbx), %esi
movzbl 0x11(%rbx), %edx
movzbl 0x12(%rbx), %ecx
leaq 0x165b5(%rip), %rax     # 0x2f8cd
leaq 0x165e8(%rip), %rdi     # 0x2f907
testb %bpl, %bpl
cmovneq %rax, %rdi
xorl %eax, %eax
callq 0x3030
movzwl 0x13(%rbx), %esi
leaq 0x16601(%rip), %rdi     # 0x2f939
xorl %eax, %eax
callq 0x3030
cmpb $0x1, 0x52(%r14)
jne 0x19360
leaq 0x1834e(%rip), %rdi     # 0x3169b
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3380
movl 0x15(%rbx), %esi
leaq 0x165f6(%rip), %rdi     # 0x2f960
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3030
nop