// File: rpavlik[P]edid-decode/edid-decode.cpp
// Function: edid_state::parse_edid()
int edid_state::parse_edid()
{
	hide_serial_numbers = options[OptHideSerialNumbers];

	for (unsigned i = 1; i < num_blocks; i++)
		preparse_extension(edid + i * EDID_PAGE_SIZE);

	if (options[OptPhysicalAddress]) {
		printf("%x.%x.%x.%x\n",
		       (cta.preparsed_phys_addr >> 12) & 0xf,
		       (cta.preparsed_phys_addr >> 8) & 0xf,
		       (cta.preparsed_phys_addr >> 4) & 0xf,
		       cta.preparsed_phys_addr & 0xf);
		return 0;
	}

	if (!options[OptSkipHexDump]) {
		printf("edid-decode (hex):\n\n");
		for (unsigned i = 0; i < num_blocks; i++) {
			hex_block("", edid + i * EDID_PAGE_SIZE, EDID_PAGE_SIZE, false);
			if (i == num_blocks - 1 && options[OptOnlyHexDump])
				return 0;
			printf("\n");
		}
		printf("----------------\n\n");
	}

	block = block_name(0x00);
	printf("Block %u, %s:\n", block_nr, block.c_str());
	parse_base_block(edid);

	for (unsigned i = 1; i < num_blocks; i++) {
		block_nr++;
		printf("\n----------------\n");
		parse_extension(edid + i * EDID_PAGE_SIZE);
	}

	block = "";
	block_nr = EDID_MAX_BLOCKS;

	if (has_cta)
		cta_resolve_svrs();

	if (options[OptPreferredTimings] && base.preferred_timing.is_valid()) {
		printf("\n----------------\n");
		printf("\nPreferred Video Timing if only Block 0 is parsed:\n");
		print_timings("  ", base.preferred_timing, true, false);
	}

	if (options[OptNativeTimings] &&
	    base.preferred_timing.is_valid() && base.preferred_is_also_native) {
		printf("\n----------------\n");
		printf("\nNative Video Timing if only Block 0 is parsed:\n");
		print_timings("  ", base.preferred_timing, true, false);
	}

	if (options[OptPreferredTimings] && !cta.preferred_timings.empty()) {
		printf("\n----------------\n");
		printf("\nPreferred Video Timing%s if Block 0 and CTA-861 Blocks are parsed:\n",
		       cta.preferred_timings.size() > 1 ? "s" : "");
		for (vec_timings_ext::iterator iter = cta.preferred_timings.begin();
		     iter != cta.preferred_timings.end(); ++iter)
			print_timings("  ", *iter, true, false);
	}

	if (options[OptNativeTimings] && !cta.native_timings.empty()) {
		printf("\n----------------\n");
		printf("\nNative Video Timing%s if Block 0 and CTA-861 Blocks are parsed:\n",
		       cta.native_timings.size() > 1 ? "s" : "");
		for (vec_timings_ext::iterator iter = cta.native_timings.begin();
		     iter != cta.native_timings.end(); ++iter)
			print_timings("  ", *iter, true, false);
	}

	if (options[OptPreferredTimings] && !dispid.preferred_timings.empty()) {
		printf("\n----------------\n");
		printf("\nPreferred Video Timing%s if Block 0 and DisplayID Blocks are parsed:\n",
		       dispid.preferred_timings.size() > 1 ? "s" : "");
		for (vec_timings_ext::iterator iter = dispid.preferred_timings.begin();
		     iter != dispid.preferred_timings.end(); ++iter)
			print_timings("  ", *iter, true, false);
	}

	if (!options[OptCheck] && !options[OptCheckInline])
		return 0;

	check_base_block();
	if (has_cta)
		check_cta_blocks();
	if (has_dispid)
		check_displayid_blocks();

	printf("\n----------------\n");

	if (!options[OptSkipSHA] && strlen(STRING(SHA))) {
		printf("\nedid-decode SHA: %s %s\n", STRING(SHA), STRING(DATE));
	}

	if (options[OptCheck]) {
		if (warnings)
			show_msgs(true);
		if (failures)
			show_msgs(false);
	}
	printf("\nEDID conformity: %s\n", failures ? "FAIL" : "PASS");
	return failures ? -2 : 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x78(%rbp)
cmpb $0x0, 0x48263(%rip)     # 0x50591
setne %cl
andb $0x1, %cl
movb %cl, 0x52(%rax)
movl $0x1, -0x14(%rbp)
movq -0x78(%rbp), %rcx
movl -0x14(%rbp), %eax
cmpl 0x4(%rcx), %eax
jae 0x8370
movq -0x78(%rbp), %rdi
movl -0x14(%rbp), %eax
shll $0x7, %eax
movl %eax, %eax
leaq 0x482c3(%rip), %rsi     # 0x50620
addq %rax, %rsi
callq 0x80b0
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x833e
cmpb $0x0, 0x481e9(%rip)     # 0x50560
je 0x83ca
movq -0x78(%rbp), %rax
movzwl 0x2d0(%rax), %esi
sarl $0xc, %esi
andl $0xf, %esi
movzwl 0x2d0(%rax), %edx
sarl $0x8, %edx
andl $0xf, %edx
movzwl 0x2d0(%rax), %ecx
sarl $0x4, %ecx
andl $0xf, %ecx
movzwl 0x2d0(%rax), %r8d
andl $0xf, %r8d
leaq 0x313c5(%rip), %rdi     # 0x3977c
movb $0x0, %al
callq 0x4050
movl $0x0, -0x4(%rbp)
jmp 0x89f2
cmpb $0x0, 0x481b2(%rip)     # 0x50583
jne 0x8470
leaq 0x27505(%rip), %rdi     # 0x2f8e3
movb $0x0, %al
callq 0x4050
movl $0x0, -0x18(%rbp)
movq -0x78(%rbp), %rcx
movl -0x18(%rbp), %eax
cmpl 0x4(%rcx), %eax
jae 0x8462
movl -0x18(%rbp), %eax
shll $0x7, %eax
movl %eax, %eax
leaq 0x48219(%rip), %rsi     # 0x50620
addq %rax, %rsi
leaq 0x27aa8(%rip), %rdi     # 0x2feb9
movl $0x80, %edx
xorl %ecx, %ecx
movl $0x10, %r8d
callq 0x7860
movq -0x78(%rbp), %rcx
movl -0x18(%rbp), %eax
movl 0x4(%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jne 0x8449
cmpb $0x0, 0x4811d(%rip)     # 0x50558
je 0x8449
movl $0x0, -0x4(%rbp)
jmp 0x89f2
leaq 0x274b9(%rip), %rdi     # 0x2f909
movb $0x0, %al
callq 0x4050
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x83ec
leaq 0x2748f(%rip), %rdi     # 0x2f8f8
movb $0x0, %al
callq 0x4050
leaq -0x38(%rbp), %rdi
xorl %esi, %esi
callq 0x7a10
movq -0x78(%rbp), %rdi
addq $0x10, %rdi
leaq -0x38(%rbp), %rsi
callq 0x43d0
leaq -0x38(%rbp), %rdi
callq 0x41f0
movq -0x78(%rbp), %rdi
movl 0x8(%rdi), %eax
movl %eax, -0x7c(%rbp)
addq $0x10, %rdi
callq 0x4150
movl -0x7c(%rbp), %esi
movq %rax, %rdx
leaq 0x273ad(%rip), %rdi     # 0x2f862
movb $0x0, %al
callq 0x4050
movq -0x78(%rbp), %rdi
leaq 0x48159(%rip), %rsi     # 0x50620
callq 0x12dd0
movl $0x1, -0x3c(%rbp)
movq -0x78(%rbp), %rcx
movl -0x3c(%rbp), %eax
cmpl 0x4(%rcx), %eax
jae 0x8520
movq -0x78(%rbp), %rax
movl 0x8(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x8(%rax)
leaq 0x27418(%rip), %rdi     # 0x2f90b
movb $0x0, %al
callq 0x4050
movq -0x78(%rbp), %rdi
movl -0x3c(%rbp), %eax
shll $0x7, %eax
movl %eax, %eax
leaq 0x48113(%rip), %rsi     # 0x50620
addq %rax, %rsi
callq 0x8110
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x84d3
movq -0x78(%rbp), %rdi
addq $0x10, %rdi
leaq 0x2798a(%rip), %rsi     # 0x2feb9
callq 0x4420
movq -0x78(%rbp), %rax
movl $0x100, 0x8(%rax)       # imm = 0x100
testb $0x1, 0x50(%rax)
je 0x854e
movq -0x78(%rbp), %rdi
callq 0x1e4e0
cmpb $0x0, 0x4802b(%rip)     # 0x50580
je 0x85b3
movq -0x78(%rbp), %rdi
addq $0x88, %rdi
addq $0x40, %rdi
callq 0xb880
testb $0x1, %al
jne 0x8571
jmp 0x85b3
leaq 0x27393(%rip), %rdi     # 0x2f90b
movb $0x0, %al
callq 0x4050
leaq 0x27398(%rip), %rdi     # 0x2f91e
movb $0x0, %al
callq 0x4050
movq -0x78(%rbp), %rdi
movq %rdi, %rdx
addq $0x88, %rdx
addq $0x40, %rdx
leaq 0x2c23b(%rip), %rsi     # 0x347e1
movl $0x1, %ecx
xorl %r8d, %r8d
callq 0xb8a0
cmpb $0x0, 0x47fc4(%rip)     # 0x5057e
je 0x8625
movq -0x78(%rbp), %rdi
addq $0x88, %rdi
addq $0x40, %rdi
callq 0xb880
testb $0x1, %al
jne 0x85d6
jmp 0x8625
movq -0x78(%rbp), %rax
testb $0x1, 0xc6(%rax)
je 0x8625
leaq 0x27321(%rip), %rdi     # 0x2f90b
movb $0x0, %al
callq 0x4050
leaq 0x2735a(%rip), %rdi     # 0x2f952
movb $0x0, %al
callq 0x4050
movq -0x78(%rbp), %rdi
movq %rdi, %rdx
addq $0x88, %rdx
addq $0x40, %rdx
leaq 0x2c1c9(%rip), %rsi     # 0x347e1
movl $0x1, %ecx
xorl %r8d, %r8d
callq 0xb8a0
cmpb $0x0, 0x47f54(%rip)     # 0x50580
je 0x870b
movq -0x78(%rbp), %rdi
addq $0x180, %rdi            # imm = 0x180
addq $0x40, %rdi
callq 0xb930
testb $0x1, %al
jne 0x870b
leaq 0x272b6(%rip), %rdi     # 0x2f90b
movb $0x0, %al
callq 0x4050
movq -0x78(%rbp), %rdi
addq $0x180, %rdi            # imm = 0x180
addq $0x40, %rdi
callq 0xb970
movq %rax, %rcx
leaq 0x2783f(%rip), %rsi     # 0x2feb9
leaq 0x2793c(%rip), %rax     # 0x2ffbd
cmpq $0x1, %rcx
cmovaq %rax, %rsi
leaq 0x272f3(%rip), %rdi     # 0x2f983
movb $0x0, %al
callq 0x4050
movq -0x78(%rbp), %rdi
addq $0x180, %rdi            # imm = 0x180
addq $0x40, %rdi
callq 0xb9a0
movq %rax, -0x48(%rbp)
movq -0x78(%rbp), %rdi
addq $0x180, %rdi            # imm = 0x180
addq $0x40, %rdi
callq 0xba10
movq %rax, -0x50(%rbp)
leaq -0x48(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0xb9d0
testb $0x1, %al
jne 0x86da
jmp 0x8709
leaq -0x48(%rbp), %rdi
callq 0xba40
movq -0x78(%rbp), %rdi
movq %rax, %rdx
leaq 0x2c0f0(%rip), %rsi     # 0x347e1
movl $0x1, %ecx
xorl %r8d, %r8d
callq 0xb8a0
leaq -0x48(%rbp), %rdi
callq 0xba60
jmp 0x86af
jmp 0x870b
cmpb $0x0, 0x47e6c(%rip)     # 0x5057e
je 0x87fd
movq -0x78(%rbp), %rdi
addq $0x180, %rdi            # imm = 0x180
addq $0x128, %rdi            # imm = 0x128
callq 0xb930
testb $0x1, %al
jne 0x87fd
leaq 0x271cd(%rip), %rdi     # 0x2f90b
movb $0x0, %al
callq 0x4050
movq -0x78(%rbp), %rdi
addq $0x180, %rdi            # imm = 0x180
addq $0x128, %rdi            # imm = 0x128
callq 0xb970
movq %rax, %rcx
leaq 0x27753(%rip), %rsi     # 0x2feb9
leaq 0x27850(%rip), %rax     # 0x2ffbd
cmpq $0x1, %rcx
cmovaq %rax, %rsi
leaq 0x2724c(%rip), %rdi     # 0x2f9c8
movb $0x0, %al
callq 0x4050
movq -0x78(%rbp), %rdi
addq $0x180, %rdi            # imm = 0x180
addq $0x128, %rdi            # imm = 0x128
callq 0xb9a0
movq %rax, -0x58(%rbp)
movq -0x78(%rbp), %rdi
addq $0x180, %rdi            # imm = 0x180
addq $0x128, %rdi            # imm = 0x128
callq 0xba10
movq %rax, -0x60(%rbp)
leaq -0x58(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0xb9d0
testb $0x1, %al
jne 0x87cc
jmp 0x87fb
leaq -0x58(%rbp), %rdi
callq 0xba40
movq -0x78(%rbp), %rdi
movq %rax, %rdx
leaq 0x2bffe(%rip), %rsi     # 0x347e1
movl $0x1, %ecx
xorl %r8d, %r8d
callq 0xb8a0
leaq -0x58(%rbp), %rdi
callq 0xba60
jmp 0x879e
jmp 0x87fd
cmpb $0x0, 0x47d7c(%rip)     # 0x50580
je 0x88e3
movq -0x78(%rbp), %rdi
addq $0x910, %rdi            # imm = 0x910
addq $0x18, %rdi
callq 0xb930
testb $0x1, %al
jne 0x88e3
leaq 0x270de(%rip), %rdi     # 0x2f90b
movb $0x0, %al
callq 0x4050
movq -0x78(%rbp), %rdi
addq $0x910, %rdi            # imm = 0x910
addq $0x18, %rdi
callq 0xb970
movq %rax, %rcx
leaq 0x27667(%rip), %rsi     # 0x2feb9
leaq 0x27764(%rip), %rax     # 0x2ffbd
cmpq $0x1, %rcx
cmovaq %rax, %rsi
leaq 0x271a2(%rip), %rdi     # 0x2fa0a
movb $0x0, %al
callq 0x4050
movq -0x78(%rbp), %rdi
addq $0x910, %rdi            # imm = 0x910
addq $0x18, %rdi
callq 0xb9a0
movq %rax, -0x68(%rbp)
movq -0x78(%rbp), %rdi
addq $0x910, %rdi            # imm = 0x910
addq $0x18, %rdi
callq 0xba10
movq %rax, -0x70(%rbp)
leaq -0x68(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0xb9d0
testb $0x1, %al
jne 0x88b2
jmp 0x88e1
leaq -0x68(%rbp), %rdi
callq 0xba40
movq -0x78(%rbp), %rdi
movq %rax, %rdx
leaq 0x2bf18(%rip), %rsi     # 0x347e1
movl $0x1, %ecx
xorl %r8d, %r8d
callq 0xb8a0
leaq -0x68(%rbp), %rdi
callq 0xba60
jmp 0x8887
jmp 0x88e3
cmpb $0x0, 0x47c89(%rip)     # 0x50573
jne 0x8901
cmpb $0x0, 0x47c60(%rip)     # 0x50553
jne 0x8901
movl $0x0, -0x4(%rbp)
jmp 0x89f2
movq -0x78(%rbp), %rdi
callq 0x14200
movq -0x78(%rbp), %rax
testb $0x1, 0x50(%rax)
je 0x891d
movq -0x78(%rbp), %rdi
callq 0x1e600
movq -0x78(%rbp), %rax
testb $0x1, 0x51(%rax)
je 0x8930
movq -0x78(%rbp), %rdi
callq 0x2a830
leaq 0x26fd4(%rip), %rdi     # 0x2f90b
movb $0x0, %al
callq 0x4050
cmpb $0x0, 0x47c4b(%rip)     # 0x50590
jne 0x8963
leaq 0x27103(%rip), %rdi     # 0x2fa51
leaq 0x27115(%rip), %rsi     # 0x2fa6a
leaq 0x2711b(%rip), %rdx     # 0x2fa77
movb $0x0, %al
callq 0x4050
cmpb $0x0, 0x47c09(%rip)     # 0x50573
je 0x8996
movq -0x78(%rbp), %rax
cmpl $0x0, 0x7c(%rax)
je 0x8980
movl $0x1, %edi
callq 0x8a00
movq -0x78(%rbp), %rax
cmpl $0x0, 0x80(%rax)
je 0x8994
xorl %edi, %edi
callq 0x8a00
jmp 0x8996
movq -0x78(%rbp), %rax
cmpl $0x0, 0x80(%rax)
je 0x89b3
leaq 0x26891(%rip), %rax     # 0x2f23b
movq %rax, -0x88(%rbp)
jmp 0x89c3
leaq 0x270e7(%rip), %rax     # 0x2faa1
movq %rax, -0x88(%rbp)
jmp 0x89c3
movq -0x88(%rbp), %rsi
leaq 0x270ba(%rip), %rdi     # 0x2fa8b
movb $0x0, %al
callq 0x4050
movq -0x78(%rbp), %rax
movl 0x80(%rax), %edx
xorl %eax, %eax
movl $0xfffffffe, %ecx       # imm = 0xFFFFFFFE
cmpl $0x0, %edx
cmovnel %ecx, %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x90, %rsp
popq %rbp
retq
nop