// File: /workspace/github_cpp_makefile_star2_O3/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 0x5fb0
movb $0x1, 0x978(%rbx)
movl $0x1, %edx
jmp 0x5feb
cmpb $0x0, 0x978(%rbx)
je 0x5fc9
cmpl $0x80, %eax
jne 0x5fdc
movb $0x1, 0x979(%rbx)
jmp 0x5fe6
leaq 0x1a645(%rip), %rsi     # 0x20615
xorl %edi, %edi
xorl %eax, %eax
callq 0x37cc
movl 0x8(%rbx), %eax
movl $0x1, %edx
cmpl $0x2, %eax
jb 0x5feb
movl $0x80, %edx
movl %edx, %eax
shll $0x7, %eax
leaq 0x391b9(%rip), %rcx     # 0x3f1b0
leaq (%rax,%rcx), %r12
addq $0x80, %r12
xorl %r15d, %r15d
movl $0x1, %r13d
xorl %r14d, %r14d
movq %rbx, 0x10(%rsp)
movq %rdx, (%rsp)
leaq (%rdx,%r13), %rbp
movq 0x8(%rsp), %rax
movb (%rax,%r13), %al
testb %al, %al
je 0x60c7
incl %r14d
cmpq %r14, %r13
je 0x6056
testb $0x1, %r15b
jne 0x6056
xorl %edi, %edi
leaq 0x1a601(%rip), %rsi     # 0x20644
xorl %eax, %eax
callq 0x37cc
movq 0x8(%rsp), %rax
movb (%rax,%r13), %al
movb $0x1, %r15b
movzbl %al, %esi
leaq 0x18(%rsp), %rdi
callq 0x5d3e
movq 0x18(%rsp), %rdx
leaq 0x1a5fc(%rip), %rdi     # 0x2066b
movl %ebp, %esi
xorl %eax, %eax
callq 0x3030
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x6094
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x3260
movl 0x4(%rbx), %eax
cmpq %rax, %rbp
jae 0x60f5
movq 0x8(%rsp), %rax
movzbl (%rax,%r13), %r8d
movzbl (%r12), %ecx
cmpb %cl, %r8b
je 0x60c2
xorl %edi, %edi
leaq 0x1a5dd(%rip), %rsi     # 0x20696
movl %ebp, %edx
xorl %eax, %eax
callq 0x37cc
movl %r15d, %ebx
jmp 0x610f
movl 0x4(%rbx), %eax
cmpq %rax, %rbp
jae 0x60f0
movzbl (%r12), %ecx
movq (%rsp), %rax
leal (%rax,%r13), %edx
xorl %edi, %edi
leaq 0x1a5ea(%rip), %rsi     # 0x206cf
xorl %eax, %eax
callq 0x37cc
movq (%rsp), %rdx
movl %r15d, %ebx
jmp 0x6113
movb $0x1, %bl
testb $0x1, %r15b
jne 0x610f
xorl %edi, %edi
leaq 0x1a576(%rip), %rsi     # 0x2067c
movl %ebp, %edx
xorl %eax, %eax
callq 0x37cc
movq (%rsp), %rdx
incq %r13
subq $-0x80, %r12
movl %ebx, %r15d
cmpq $0x7f, %r13
movq 0x10(%rsp), %rbx
jne 0x6017
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop