// File: rpavlik[P]edid-decode/edid-decode.cpp
// Function: edid_state::parse_block_map(unsigned char const*)
void edid_state::parse_block_map(const unsigned char *x)
{
	unsigned last_valid_block_tag = 0;
	bool fail_once = false;
	unsigned offset = 1;
	unsigned i;

	if (block_nr == 1)
		block_map.saw_block_1 = true;
	else if (!block_map.saw_block_1)
		fail("No EDID Block Map Extension found in block 1.\n");
	else if (block_nr == 128)
		block_map.saw_block_128 = true;

	if (block_nr > 1)
		offset = 128;

	for (i = 1; i < 127; i++) {
		unsigned block = offset + i;

		if (x[i]) {
			last_valid_block_tag++;
			if (i != last_valid_block_tag && !fail_once) {
				fail("Valid block tags are not consecutive.\n");
				fail_once = true;
			}
			printf("  Block %3u: %s\n", block, block_name(x[i]).c_str());
			if (block >= num_blocks) {
				if (!fail_once)
					fail("Invalid block number %u.\n", block);
				fail_once = true;
			} else if (x[i] != edid[block * EDID_PAGE_SIZE]) {
				fail("Block %u tag mismatch: expected 0x%02x, but got 0x%02x.\n",
				     block, edid[block * EDID_PAGE_SIZE], x[i]);
			}
		} else if (block < num_blocks) {
			fail("Block %u tag mismatch: expected 0x%02x, but got 0x00.\n",
			     block, edid[block * EDID_PAGE_SIZE]);
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x60(%rbp)
movl $0x0, -0x14(%rbp)
movb $0x0, -0x15(%rbp)
movl $0x1, -0x1c(%rbp)
cmpl $0x1, 0x8(%rax)
jne 0x7ecd
movq -0x60(%rbp), %rax
movb $0x1, 0x978(%rax)
jmp 0x7f08
movq -0x60(%rbp), %rax
testb $0x1, 0x978(%rax)
jne 0x7eec
xorl %edi, %edi
leaq 0x2786c(%rip), %rsi     # 0x2f74f
movb $0x0, %al
callq 0x47d0
jmp 0x7f06
movq -0x60(%rbp), %rax
cmpl $0x80, 0x8(%rax)
jne 0x7f04
movq -0x60(%rbp), %rax
movb $0x1, 0x979(%rax)
jmp 0x7f06
jmp 0x7f08
movq -0x60(%rbp), %rax
cmpl $0x1, 0x8(%rax)
jbe 0x7f19
movl $0x80, -0x1c(%rbp)
movl $0x1, -0x20(%rbp)
cmpl $0x7f, -0x20(%rbp)
jae 0x809e
movl -0x1c(%rbp), %eax
addl -0x20(%rbp), %eax
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rax
movl -0x20(%rbp), %ecx
cmpb $0x0, (%rax,%rcx)
je 0x8058
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
movl -0x20(%rbp), %eax
cmpl -0x14(%rbp), %eax
je 0x7f6f
testb $0x1, -0x15(%rbp)
jne 0x7f6f
xorl %edi, %edi
leaq 0x2781a(%rip), %rsi     # 0x2f77e
movb $0x0, %al
callq 0x47d0
movb $0x1, -0x15(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x64(%rbp)
movq -0x10(%rbp), %rax
movl -0x20(%rbp), %ecx
movzbl (%rax,%rcx), %esi
leaq -0x48(%rbp), %rdi
movq %rdi, -0x70(%rbp)
callq 0x7a10
movq -0x70(%rbp), %rdi
callq 0x4150
movl -0x64(%rbp), %esi
movq %rax, %rdx
leaq 0x27802(%rip), %rdi     # 0x2f7a5
xorl %eax, %eax
callq 0x4050
jmp 0x7fac
leaq -0x48(%rbp), %rdi
callq 0x41f0
movq -0x60(%rbp), %rcx
movl -0x24(%rbp), %eax
cmpl 0x4(%rcx), %eax
jb 0x7ffc
testb $0x1, -0x15(%rbp)
jne 0x7ff6
movl -0x24(%rbp), %edx
xorl %edi, %edi
leaq 0x277e3(%rip), %rsi     # 0x2f7b6
movb $0x0, %al
callq 0x47d0
jmp 0x7ff6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x41f0
jmp 0x80a4
movb $0x1, -0x15(%rbp)
jmp 0x8056
movq -0x10(%rbp), %rax
movl -0x20(%rbp), %ecx
movzbl (%rax,%rcx), %eax
movl -0x24(%rbp), %ecx
shll $0x7, %ecx
movl %ecx, %ecx
movl %ecx, %edx
leaq 0x48608(%rip), %rcx     # 0x50620
movzbl (%rcx,%rdx), %ecx
cmpl %ecx, %eax
je 0x8054
movl -0x24(%rbp), %edx
movl -0x24(%rbp), %eax
shll $0x7, %eax
movl %eax, %eax
movl %eax, %ecx
leaq 0x485ec(%rip), %rax     # 0x50620
movzbl (%rax,%rcx), %ecx
movq -0x10(%rbp), %rax
movl -0x20(%rbp), %esi
movzbl (%rax,%rsi), %r8d
xorl %edi, %edi
leaq 0x27783(%rip), %rsi     # 0x2f7d0
movb $0x0, %al
callq 0x47d0
jmp 0x8056
jmp 0x808e
movq -0x60(%rbp), %rcx
movl -0x24(%rbp), %eax
cmpl 0x4(%rcx), %eax
jae 0x808c
movl -0x24(%rbp), %edx
movl -0x24(%rbp), %eax
shll $0x7, %eax
movl %eax, %eax
movl %eax, %ecx
leaq 0x485a8(%rip), %rax     # 0x50620
movzbl (%rax,%rcx), %ecx
xorl %edi, %edi
leaq 0x27784(%rip), %rsi     # 0x2f809
movb $0x0, %al
callq 0x47d0
jmp 0x808e
jmp 0x8090
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x7f20
addq $0x70, %rsp
popq %rbp
retq
movq -0x50(%rbp), %rdi
callq 0x4550
nopl (%rax)