// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rsi, 0x8(%rsp)
movq %rdi, %rbx
movl 0x8(%rdi), %eax
cmpl $0x1, %eax
jne 0x5f95
movb $0x1, 0x978(%rbx)
jmp 0x5fbe
cmpb $0x0, 0x978(%rbx)
je 0x5fae
cmpl $0x80, %eax
jne 0x5fbe
movb $0x1, 0x979(%rbx)
jmp 0x5fbe
leaq 0x1a650(%rip), %rsi     # 0x20605
xorl %edi, %edi
xorl %eax, %eax
callq 0x37ec
movq %rbx, 0x10(%rsp)
cmpl $0x2, 0x8(%rbx)
movl $0x80, %ebp
movl $0x1, %r15d
cmovbq %r15, %rbp
movl %ebp, %eax
shll $0x7, %eax
leaq 0x391ce(%rip), %rcx     # 0x3f1b0
leaq (%rax,%rcx), %r12
addq $0x80, %r12
xorl %r14d, %r14d
xorl %r13d, %r13d
leaq (%r15,%rbp), %rbx
movq 0x8(%rsp), %rax
cmpb $0x0, (%rax,%r15)
je 0x60a6
incl %r13d
cmpq %r13, %r15
je 0x6028
testb $0x1, %r14b
jne 0x6028
xorl %edi, %edi
leaq 0x1a616(%rip), %rsi     # 0x20634
xorl %eax, %eax
callq 0x37ec
movb $0x1, %r14b
movq 0x8(%rsp), %rax
movzbl (%rax,%r15), %esi
leaq 0x18(%rsp), %rdi
callq 0x5d27
movq 0x18(%rsp), %rdx
leal (%r15,%rbp), %esi
leaq 0x1a60f(%rip), %rdi     # 0x2065b
xorl %eax, %eax
callq 0x3030
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x606f
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x3260
movq 0x10(%rsp), %rax
movl 0x4(%rax), %eax
cmpq %rax, %rbx
jae 0x60e5
movq 0x8(%rsp), %rax
movzbl (%rax,%r15), %r8d
movzbl (%r12), %ecx
cmpb %cl, %r8b
je 0x60cc
leal (%r15,%rbp), %edx
xorl %edi, %edi
leaq 0x1a5e9(%rip), %rsi     # 0x20686
xorl %eax, %eax
callq 0x37ec
jmp 0x60cc
movq 0x10(%rsp), %rax
movl 0x4(%rax), %eax
cmpq %rax, %rbx
jae 0x60cc
movzbl (%r12), %ecx
leal (%r15,%rbp), %edx
xorl %edi, %edi
leaq 0x1a5fa(%rip), %rsi     # 0x206bf
xorl %eax, %eax
callq 0x37ec
movl %r14d, %ebx
incq %r15
subq $-0x80, %r12
movl %ebx, %r14d
cmpq $0x7f, %r15
jne 0x5ff3
jmp 0x6103
movb $0x1, %bl
testb $0x1, %r14b
jne 0x60cf
leal (%r15,%rbp), %edx
xorl %edi, %edi
leaq 0x1a572(%rip), %rsi     # 0x2066c
xorl %eax, %eax
callq 0x37ec
jmp 0x60cf
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq