// File: /workspace/github_cpp_makefile_star2_O3/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 0x1611c
movq %rbx, %rdi
movl $0x16, %esi
movl $0x16, %edx
xorl %ecx, %ecx
callq 0x1644b
testb %al, %al
je 0x190f2
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 0x185f0(%rip), %rdi     # 0x315c9
callq 0x3380
leaq 0x16781(%rip), %rdi     # 0x2f766
xorl %eax, %eax
callq 0x3030
movq %r15, %rbp
movl %r15d, %eax
andl $0x7, %eax
leaq 0x185c4(%rip), %r15     # 0x315c0
movq %r15, %rdi
cmpl $0x3, %eax
ja 0x19012
leaq 0x15b41(%rip), %rcx     # 0x2eb4c
movslq (%rcx,%rax,4), %rdi
addq %rcx, %rdi
callq 0x3380
leaq 0x16770(%rip), %rdi     # 0x2f78e
xorl %eax, %eax
callq 0x3030
movl %ebp, %eax
shrl $0x3, %eax
andl $0x3, %eax
cmpl $0x1, %eax
leaq 0x185f7(%rip), %rcx     # 0x3162e
cmoveq %rcx, %r15
testl %eax, %eax
leaq 0x14a6c(%rip), %rdi     # 0x2dab0
cmovneq %r15, %rdi
callq 0x3380
testb %bpl, %bpl
leaq 0x185ff(%rip), %rax     # 0x31656
leaq 0x1863b(%rip), %rdi     # 0x31699
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 0x16757(%rip), %rdi     # 0x2f7da
xorl %eax, %eax
callq 0x3030
leaq 0x1677e(%rip), %rdi     # 0x2f80f
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 0x16774(%rip), %rdi     # 0x2f82a
movl %r15d, %esi
movl %r12d, %edx
xorl %eax, %eax
callq 0x3030
testb $0x40, %bpl
jne 0x19101
cmpb $0x0, 0xc(%rsp)
movq 0x20(%rsp), %r14
movl 0x10(%rsp), %ebp
je 0x191cf
leaq 0x167ec(%rip), %rsi     # 0x2f8d0
xorl %edi, %edi
xorl %eax, %eax
callq 0x37cc
jmp 0x191cf
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 0x191ab
movzbl 0xc(%rbx), %eax
imull %r13d, %eax
cvtsi2sd %eax, %xmm0
divsd 0x154fc(%rip), %xmm0    # 0x2e628
leaq 0x16713(%rip), %rdi     # 0x2f846
movb $0x1, %al
callq 0x3030
movzbl 0xd(%rbx), %eax
imull %r13d, %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
divsd 0x154d7(%rip), %xmm0    # 0x2e628
leaq 0x1670f(%rip), %rdi     # 0x2f867
movb $0x1, %al
callq 0x3030
movzbl 0xe(%rbx), %eax
imull %r13d, %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
divsd 0x154b2(%rip), %xmm0    # 0x2e628
leaq 0x1670e(%rip), %rdi     # 0x2f88b
movb $0x1, %al
callq 0x3030
movzbl 0xf(%rbx), %eax
imull %r13d, %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
divsd 0x1548d(%rip), %xmm0    # 0x2e628
leaq 0x1670c(%rip), %rdi     # 0x2f8ae
movb $0x1, %al
callq 0x3030
jmp 0x191bb
leaq 0x1671e(%rip), %rsi     # 0x2f8d0
xorl %edi, %edi
xorl %eax, %eax
callq 0x37cc
leaq 0x16668(%rip), %rdi     # 0x2f82a
movl %r15d, %esi
movl %r12d, %edx
xorl %eax, %eax
callq 0x3030
movzbl 0x10(%rbx), %esi
movzbl 0x11(%rbx), %edx
movzbl 0x12(%rbx), %ecx
leaq 0x1672b(%rip), %rax     # 0x2f90d
leaq 0x1675e(%rip), %rdi     # 0x2f947
testb %bpl, %bpl
cmovneq %rax, %rdi
xorl %eax, %eax
callq 0x3030
movzwl 0x13(%rbx), %esi
leaq 0x16777(%rip), %rdi     # 0x2f979
xorl %eax, %eax
callq 0x3030
cmpb $0x1, 0x52(%r14)
jne 0x1922a
leaq 0x184c4(%rip), %rdi     # 0x316db
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3380
movl 0x15(%rbx), %esi
leaq 0x1676c(%rip), %rdi     # 0x2f9a0
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3030
nop