// File: /workspace/github_cpp_makefile_star2_O3/rpavlik[P]edid-decode/edid-decode.cpp
// Function: edid_from_file(char const*, _IO_FILE*)
static int edid_from_file(const char *from_file, FILE *error)
{
#ifdef O_BINARY
	// Windows compatibility
	int flags = O_RDONLY | O_BINARY;
#else
	int flags = O_RDONLY;
#endif
	int fd;

	if (!strcmp(from_file, "-")) {
		from_file = "stdin";
		fd = 0;
	} else if ((fd = open(from_file, flags)) == -1) {
		perror(from_file);
		return -1;
	}

	odd_hex_digits = false;
	if (!extract_edid(fd, error)) {
		if (!state.edid_size) {
			fprintf(error, "EDID of '%s' was empty.\n", from_file);
			return -1;
		}
		fprintf(error, "EDID extract of '%s' failed: ", from_file);
		if (odd_hex_digits)
			fprintf(error, "odd number of hexadecimal digits.\n");
		else
			fprintf(error, "unknown format.\n");
		return -1;
	}
	if (state.edid_size % EDID_PAGE_SIZE) {
		fprintf(error, "EDID length %u is not a multiple of %u.\n",
			state.edid_size, EDID_PAGE_SIZE);
		return -1;
	}
	state.num_blocks = state.edid_size / EDID_PAGE_SIZE;
	if (fd != 0)
		close(fd);

	if (memcmp(edid, "\x00\xFF\xFF\xFF\xFF\xFF\xFF\x00", 8)) {
		fprintf(error, "No EDID header found in '%s'.\n", from_file);
		return -1;
	}
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %rsi, %rbx
movq %rdi, %r14
cmpb $0x2d, (%rdi)
jne 0x787a
cmpb $0x0, 0x1(%r14)
je 0x793e
movq %r14, %rdi
xorl %esi, %esi
xorl %eax, %eax
callq 0x3170
cmpl $-0x1, %eax
je 0x795e
movl %eax, %ebp
movb $0x0, 0x3f918(%rip)     # 0x471b0
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %r15
movaps %xmm0, (%r15)
movq $0x0, 0x10(%r15)
leaq 0x30(%rsp), %r12
movl $0x80, %edx
movl %ebp, %edi
movq %r12, %rsi
callq 0x3340
testq %rax, %rax
js 0x7a21
je 0x78e5
movq 0x18(%rsp), %rsi
leaq (%rsp,%rax), %rcx
addq $0x30, %rcx
movq %r15, %rdi
movq %r12, %rdx
callq 0x8b70
jmp 0x78b1
movq 0x10(%rsp), %r15
movq 0x18(%rsp), %r12
cmpq %r12, %r15
je 0x794c
leaq 0x1973d(%rip), %rsi     # 0x21038
movq %r15, %rdi
callq 0x3080
testq %rax, %rax
jne 0x791c
leaq 0x19735(%rip), %rsi     # 0x21044
movq %r15, %rdi
callq 0x3080
testq %rax, %rax
je 0x796b
movq %rax, %rdi
movl $0x3a, %esi
callq 0x30e0
movq %rax, %rdi
movl $0x1, %esi
callq 0x81d5
movl %eax, %r13d
jmp 0x7a24
xorl %ebp, %ebp
leaq 0x19638(%rip), %r14     # 0x20f7f
jmp 0x7891
movl $0x0, 0x32d8a(%rip)     # 0x3a6e0
xorl %r13d, %r13d
jmp 0x7a29
movq %r14, %rdi
callq 0x31e0
jmp 0x7af9
leaq 0x196e5(%rip), %rsi     # 0x21057
movq %r15, %rdi
callq 0x3080
testq %rax, %rax
je 0x7994
movq %rax, %rdi
movl $0x7b, %esi
callq 0x30e0
leaq 0x1(%rax), %rdi
xorl %esi, %esi
jmp 0x7931
leaq 0x196d5(%rip), %rsi     # 0x21070
movq %r15, %rdi
callq 0x3080
testq %rax, %rax
je 0x7b10
movq %rax, %rdi
movl $0x3e, %esi
callq 0x30e0
testq %rax, %rax
je 0x7a21
movq %rax, %r12
incq %r12
cmpb $0x0, 0x1(%rax)
je 0x7a00
movq %r12, %r13
xorl %r15d, %r15d
cmpq $0xff, %r15
ja 0x7a00
cmpb $0x0, 0x1(%r13)
je 0x7a00
movq %r13, %rdi
movl $0x1, %esi
callq 0x8456
testb %al, %al
je 0x7a21
addq $0x2, %r15
cmpb $0x0, 0x2(%r13)
leaq 0x2(%r13), %r13
jne 0x79d0
movq %r12, %rdi
leaq 0x19666(%rip), %rsi     # 0x21070
callq 0x3080
testq %rax, %rax
jne 0x79ac
cmpl $0x0, 0x32cc5(%rip)     # 0x3a6e0
setne %r13b
jmp 0x7a24
xorl %r13d, %r13d
movq 0x10(%rsp), %r15
testq %r15, %r15
je 0x7a3e
movq 0x20(%rsp), %rsi
subq %r15, %rsi
movq %r15, %rdi
callq 0x3260
movl 0x32c9c(%rip), %edx     # 0x3a6e0
testb %r13b, %r13b
je 0x7a69
testb $0x7f, %dl
je 0x7a98
leaq 0x1959b(%rip), %rsi     # 0x20ff0
movq %rbx, %rdi
movl $0x80, %ecx
xorl %eax, %eax
callq 0x3330
jmp 0x7af9
testl %edx, %edx
je 0x7aca
leaq 0x1952a(%rip), %rsi     # 0x20f9e
movq %rbx, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x3330
cmpb $0x1, 0x3f728(%rip)     # 0x471b0
jne 0x7ae0
leaq 0x1952b(%rip), %rdi     # 0x20fbc
movl $0x22, %esi
jmp 0x7aec
shrl $0x7, %edx
movl %edx, 0x32c43(%rip)     # 0x3a6e4
testl %ebp, %ebp
je 0x7aac
movl %ebp, %edi
callq 0x3440
xorl %eax, %eax
movabsq $0xffffffffffff00, %rcx # imm = 0xFFFFFFFFFFFF00
cmpq %rcx, 0x376f1(%rip)     # 0x3f1b0
je 0x7afe
leaq 0x19551(%rip), %rsi     # 0x21019
jmp 0x7ad1
leaq 0x194b4(%rip), %rsi     # 0x20f85
movq %rbx, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x3330
jmp 0x7af9
leaq 0x194f8(%rip), %rdi     # 0x20fdf
movl $0x10, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x3430
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x19560(%rip), %rsi     # 0x21077
movq %r15, %rdi
callq 0x3080
testq %rax, %rax
jne 0x7b38
leaq 0x19557(%rip), %rsi     # 0x21082
movq %r15, %rdi
callq 0x3080
testq %rax, %rax
je 0x7b45
movq %rax, %rdi
callq 0x82bc
jmp 0x7936
leaq 0x1953c(%rip), %rsi     # 0x21088
movq %r15, %rdi
callq 0x3080
testq %rax, %rax
je 0x7b7a
leaq 0x19537(%rip), %rsi     # 0x21097
movq %rax, %rdi
callq 0x3080
testq %rax, %rax
je 0x7b7a
movq %rax, %rdi
callq 0x83b2
jmp 0x7936
xorl %r13d, %r13d
movsbl (%r15,%r13), %edi
movl %edi, 0xc(%rsp)
callq 0x3040
testl %eax, %eax
jne 0x7bc4
movl $0x4, %edx
leaq 0x19551(%rip), %rdi     # 0x210ec
movl 0xc(%rsp), %esi
callq 0x3280
testq %rax, %rax
jne 0x7bc4
movl 0xc(%rsp), %edi
callq 0x3350
cmpl $0x78, %eax
je 0x7bc4
movl 0xc(%rsp), %edi
callq 0x3090
testl %eax, %eax
je 0x7bd5
incq %r13
cmpq $0x20, %r13
jne 0x7b7d
movq %r15, %rdi
jmp 0x792c
subq %r15, %r12
cmpq $0x8001, %r12           # imm = 0x8001
jb 0x7c02
leaq 0x194b4(%rip), %rsi     # 0x2109c
xorl %r13d, %r13d
movl $0x8000, %ecx           # imm = 0x8000
movq %rbx, %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0x3330
jmp 0x7a24
leaq 0x375a7(%rip), %rdi     # 0x3f1b0
movq %r15, %rsi
movq %r12, %rdx
callq 0x31d0
movl %r12d, 0x32ac5(%rip)    # 0x3a6e0
movb $0x1, %r13b
jmp 0x7a24
jmp 0x7c25
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x7c3f
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x3260
movq %rbx, %rdi
callq 0x3400