// File: /workspace/github_cpp_makefile_star2_O2/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 $0x48, %rsp
movq %rsi, 0x10(%rsp)
movq %rdi, %rbx
movl 0x8(%rdi), %eax
pushq $0x1
popq %r12
cmpl $0x1, %eax
jne 0x523c
movb $0x1, 0x978(%rbx)
movq %r12, %r15
jmp 0x5276
cmpb $0x0, 0x978(%rbx)
je 0x5255
cmpl $0x80, %eax
jne 0x5268
movb $0x1, 0x979(%rbx)
jmp 0x5270
leaq 0x153b9(%rip), %rsi     # 0x1a615
xorl %edi, %edi
xorl %eax, %eax
callq 0x362c
movl 0x8(%rbx), %eax
movq %r12, %r15
cmpl $0x2, %eax
jb 0x5276
movl $0x80, %r15d
movl %r15d, %eax
shll $0x7, %eax
movq %rax, 0x18(%rsp)
incq %r15
xorl %r14d, %r14d
movl $0x80, %ebp
xorl %r13d, %r13d
movq %rbx, 0x20(%rsp)
cmpq $0x3f80, %rbp           # imm = 0x3F80
je 0x53bb
movq 0x10(%rsp), %rax
movb (%rax,%r12), %al
testb %al, %al
je 0x5351
incl %r13d
cmpq %r13, %r12
movq %r13, 0x8(%rsp)
je 0x52e1
testb $0x1, %r14b
jne 0x52e1
xorl %edi, %edi
leaq 0x15376(%rip), %rsi     # 0x1a644
xorl %eax, %eax
callq 0x362c
movq 0x10(%rsp), %rax
movb (%rax,%r12), %al
movb $0x1, %r14b
movzbl %al, %esi
leaq 0x28(%rsp), %r13
movq %r13, %rdi
callq 0x50da
movq 0x28(%rsp), %rdx
leaq 0x1536e(%rip), %rdi     # 0x1a66b
movl %r15d, %esi
xorl %eax, %eax
callq 0x3030
movq %r13, %rdi
callq 0x3130
movl 0x4(%rbx), %eax
cmpq %rax, %r15
jae 0x5384
movq 0x10(%rsp), %rax
movzbl (%rax,%r12), %r8d
movq 0x18(%rsp), %rax
addq %rbp, %rax
leaq 0x33ea0(%rip), %rcx     # 0x391d0
movzbl (%rcx,%rax), %ecx
cmpb %cl, %r8b
je 0x534c
xorl %edi, %edi
leaq 0x15354(%rip), %rsi     # 0x1a696
movl %r15d, %edx
xorl %eax, %eax
callq 0x362c
movl %r14d, %ebx
jmp 0x539f
movl 0x4(%rbx), %eax
cmpq %rax, %r15
jae 0x537f
movq 0x18(%rsp), %rax
addq %rbp, %rax
leaq 0x33e68(%rip), %rcx     # 0x391d0
movzbl (%rcx,%rax), %ecx
xorl %edi, %edi
leaq 0x1535a(%rip), %rsi     # 0x1a6cf
movl %r15d, %edx
xorl %eax, %eax
callq 0x362c
movl %r14d, %ebx
jmp 0x53a4
movb $0x1, %bl
testb $0x1, %r14b
jne 0x539f
xorl %edi, %edi
leaq 0x152e7(%rip), %rsi     # 0x1a67c
movl %r15d, %edx
xorl %eax, %eax
callq 0x362c
movq 0x8(%rsp), %r13
incq %r12
subq $-0x80, %rbp
incq %r15
movl %ebx, %r14d
movq 0x20(%rsp), %rbx
jmp 0x5294
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq