// File: /workspace/github_c_makefile_star2_O2/truenas[P]binaries/src/plx_eeprom.c
// Function: main
int
main(int argc, char **argv)
{
	int fd = -1, dfd = -1, c, r = 0, w = 0;
	uint64_t base = 0;
	uint8_t	*mem = NULL;
	char *fn = NULL;

	while ((c = getopt(argc, argv, "b:f:hrw")) != -1) {
		switch (c) {
		case 'b':
			base = strtoll(optarg, NULL, 0);
			break;
		case 'f':
			fn = optarg;
			break;
		case 'r':
			r = 1;
			break;
		case 'w':
			w = 1;
			break;
		case 'h':
		default:
			usage();
		}
	}

	if (base != 0) {
		fd = open("/dev/mem", O_RDWR);
		if (fd < 0)
			err(EX_OSERR, "Can't open /dev/mem");
		mem = mmap(NULL, 256*1024, PROT_READ | PROT_WRITE, MAP_SHARED, fd, base);
		if (mem == MAP_FAILED)
			err(EX_OSERR, "Can't mmap /dev/mem");
	}

	if (fn != NULL) {
		if (strcmp(fn, "-") != 0) {
			dfd = open(fn, r ? (O_WRONLY | O_TRUNC | O_CREAT) : O_RDONLY);
			if (dfd < 0)
				err(EX_OSERR, "Can't open %s", fn);
		} else
			dfd = w ? STDIN_FILENO : STDOUT_FILENO;
	}

	if (r || w) {
		if (mem == NULL) {
			warnx("Base address not specified");
			usage();
		}
		if (dfd < 0) {
			warnx("File name not specified");
			usage();
		}
		if (r)
			plx_eeprom_read_raw(mem, dfd);
		else
			plx_eeprom_write_raw(mem, dfd);
	} else if (mem != NULL) {
		plx_eeprom_print(mem);
	} else if (dfd >= 0) {
		plx_file_print(dfd);
	} else {
		warnx("Neither base address nor file name specified");
		usage();
	}

	if (dfd >= 0)
		close(dfd);
	if (fd >= 0) {
		munmap(mem, 256*1024);
		close(fd);
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movq %rsi, %r14
movl %edi, %ebp
movq $0x0, 0x8(%rsp)
leaq 0xd76(%rip), %r13       # 0x2004
movq 0x2d43(%rip), %r12      # 0x3fd8
movq $0x0, 0x10(%rsp)
movl $0x0, (%rsp)
xorl %ebx, %ebx
xorl %r15d, %r15d
movl %ebp, %edi
movq %r14, %rsi
movq %r13, %rdx
callq 0x1110
cmpl $0x66, %eax
jne 0x12c2
movq (%r12), %r15
jmp 0x12aa
cmpl $-0x1, %eax
je 0x1307
cmpl $0x77, %eax
je 0x12ec
cmpl $0x72, %eax
je 0x12f4
cmpl $0x62, %eax
jne 0x16a3
movq (%r12), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x10c0
movq %rax, %rbx
jmp 0x12aa
pushq $0x1
popq %rax
movl %eax, (%rsp)
jmp 0x12aa
movb $0x1, %al
movq %rax, 0x10(%rsp)
movl $0x241, %eax            # imm = 0x241
movq %rax, 0x8(%rsp)
jmp 0x12aa
pushq $-0x1
popq %rbp
testq %rbx, %rbx
je 0x1359
leaq 0xd01(%rip), %rdi       # 0x2017
pushq $0x2
popq %rsi
xorl %eax, %eax
callq 0x1100
testl %eax, %eax
js 0x16f1
pushq $0x3
popq %rdx
pushq $0x1
popq %rcx
movl $0x40000, %esi          # imm = 0x40000
xorl %edi, %edi
movl %eax, 0x4(%rsp)
movl %eax, %r8d
movq %rbx, %r9
callq 0x1060
movq %rax, %r14
cmpq $-0x1, %rax
jne 0x1360
leaq 0xccc(%rip), %rsi       # 0x2020
jmp 0x1755
xorl %r14d, %r14d
movl %ebp, 0x4(%rsp)
testq %r15, %r15
movl (%rsp), %ebx
je 0x1392
cmpb $0x2d, (%r15)
jne 0x1379
cmpb $0x0, 0x1(%r15)
je 0x1699
movq %r15, %rdi
movq 0x8(%rsp), %rsi
xorl %eax, %eax
callq 0x1100
movl %eax, %ebp
testl %eax, %eax
js 0x16fa
testl %ebx, %ebx
setne %al
movq 0x10(%rsp), %rcx
orb %cl, %al
testb $0x1, %al
movl %ebp, (%rsp)
je 0x142a
testq %r14, %r14
je 0x170e
testl %ebp, %ebp
js 0x1717
testb $0x1, %cl
je 0x1481
movq %r14, %rdi
xorl %esi, %esi
callq 0x1784
movl %eax, %ebx
leaq 0x18(%rsp), %rsi
movl %eax, (%rsi)
pushq $0x4
popq %rdx
movl %ebp, %edi
callq 0x1050
cmpb $0x5a, %bl
jne 0x165e
shrl $0x10, %ebx
addl $0x7, %ebx
andl $-0x4, %ebx
pushq $0x4
popq %r15
leaq 0x18(%rsp), %r12
pushq $0x4
popq %r13
cmpl %r15d, %ebx
jbe 0x165e
movq %r14, %rdi
movl %r15d, %esi
callq 0x1784
movl %eax, 0x18(%rsp)
movl %ebp, %edi
movq %r12, %rsi
movq %r13, %rdx
callq 0x1050
addl $0x4, %r15d
jmp 0x13ff
testq %r14, %r14
je 0x15d3
movq %r14, %rdi
xorl %esi, %esi
callq 0x1784
movl %eax, %ebx
cmpb $0x5a, %bl
jne 0x165e
shrl $0x10, %ebx
leal 0x3(%rbx), %r15d
andl $-0x4, %r15d
movq %r15, %rdi
callq 0x10e0
movq %rax, %r12
xorl %ebp, %ebp
cmpq %r15, %rbp
jae 0x1649
leaq 0x4(%rbp), %r13
movq %r14, %rdi
movl %r13d, %esi
callq 0x1784
movl %eax, (%r12,%rbp)
movq %r13, %rbp
jmp 0x1460
movl $0xa000, 0x260(%r14) # imm = 0xA000
movl $0x3e8, %edi            # imm = 0x3E8
callq 0x1150
movl $0x2000, 0x260(%r14) # imm = 0x2000
movl $0x3e8, %edi            # imm = 0x3E8
callq 0x1150
xorl %r15d, %r15d
pushq $-0x64
popq %r13
pushq $0x64
popq %rbx
andl $0x0, 0x18(%rsp)
movl %ebp, %edi
leaq 0x18(%rsp), %rsi
pushq $0x4
popq %rdx
callq 0x10b0
testq %rax, %rax
jle 0x15b9
cmpl $0x1000000, %r15d       # imm = 0x1000000
jae 0x16a8
movl 0x18(%rsp), %r12d
movl 0x26c(%r14), %eax
movl $0xffffff00, %ecx       # imm = 0xFFFFFF00
andl %ecx, %eax
movl %r15d, %ecx
shrl $0x10, %ecx
orl %eax, %ecx
movl %ecx, 0x26c(%r14)
movl 0x260(%r14), %eax
movl $0xffe00000, %ecx       # imm = 0xFFE00000
andl %ecx, %eax
orl $0xc000, %eax           # imm = 0xC000
movl %eax, 0x260(%r14)
movl %r13d, %ebp
btl $0x12, 0x260(%r14)
jae 0x1534
movl %ebx, %edi
callq 0x1150
incl %ebp
jmp 0x151e
testl %ebp, %ebp
je 0x16be
movl %r15d, %eax
shrl $0x2, %eax
movl %r12d, 0x264(%r14)
movl 0x260(%r14), %ecx
movl $0xffe00000, %edx       # imm = 0xFFE00000
andl %edx, %ecx
movl %r15d, %edx
shll $0x5, %edx
andl $0x100000, %edx         # imm = 0x100000
andl $0x1fff, %eax           # imm = 0x1FFF
orl %edx, %eax
addl %ecx, %eax
addl $0x4000, %eax           # imm = 0x4000
movl %eax, 0x260(%r14)
movl %r13d, %ebp
btl $0x12, 0x260(%r14)
jae 0x1591
movl %ebx, %edi
callq 0x1150
incl %ebp
jmp 0x157b
testl %ebp, %ebp
je 0x16c7
movq %r14, %rdi
movl %r15d, %esi
callq 0x1784
cmpl %r12d, %eax
movl (%rsp), %ebp
jne 0x16d8
addl $0x4, %r15d
jmp 0x14b5
shrl $0x2, %r15d
leaq 0xb64(%rip), %rdi       # 0x2128
movl %r15d, %esi
xorl %eax, %eax
callq 0x1080
jmp 0x165e
testl %ebp, %ebp
js 0x1720
leaq 0x18(%rsp), %rsi
movl %ebp, %edi
callq 0x1140
testl %eax, %eax
js 0x1733
movq 0x48(%rsp), %r12
movslq %r12d, %r15
movq %r15, %rdi
callq 0x10e0
movq %rax, %rbx
movl %ebp, %edi
movq %rax, %rsi
movq %r15, %rdx
callq 0x10b0
cmpq %r15, %rax
jl 0x173c
movl (%rbx), %esi
cmpb $0x5a, %sil
jne 0x1745
shrl $0x10, %esi
leal 0x4(%rsi), %eax
cmpl %r12d, %eax
ja 0x174e
movq %rbx, %rdi
addq $0x4, %rdi
callq 0x1820
movq %rbx, %rdi
callq 0x1030
jmp 0x1662
movq %r12, %rdi
movl %ebx, %esi
callq 0x1820
movq %r12, %rdi
callq 0x1030
movl (%rsp), %ebp
testl %ebp, %ebp
js 0x1669
movl %ebp, %edi
callq 0x10a0
movl 0x4(%rsp), %ebx
testl %ebx, %ebx
js 0x1685
movl $0x40000, %esi          # imm = 0x40000
movq %r14, %rdi
callq 0x10f0
movl %ebx, %edi
callq 0x10a0
xorl %eax, %eax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %ebx, %ebp
xorl $0x1, %ebp
jmp 0x1392
callq 0x175f
leaq 0xa22(%rip), %rsi       # 0x20d1
pushq $0x47
popq %rdi
movl $0x1000000, %edx        # imm = 0x1000000
xorl %eax, %eax
callq 0x1070
leaq 0xa76(%rip), %rsi       # 0x213b
jmp 0x16ce
leaq 0xa1f(%rip), %rsi       # 0x20ed
pushq $0x47
popq %rdi
xorl %eax, %eax
callq 0x1070
leaq 0xa23(%rip), %rsi       # 0x2102
pushq $0x47
popq %rdi
movl %r15d, %edx
movl %eax, %ecx
movl %r12d, %r8d
xorl %eax, %eax
callq 0x1070
leaq 0x914(%rip), %rsi       # 0x200c
jmp 0x1755
leaq 0x933(%rip), %rsi       # 0x2034
pushq $0x47
popq %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x10d0
leaq 0x92d(%rip), %rdi       # 0x2042
jmp 0x1727
leaq 0x93f(%rip), %rdi       # 0x205d
jmp 0x1727
leaq 0x94e(%rip), %rdi       # 0x2075
xorl %eax, %eax
callq 0x1090
callq 0x175f
leaq 0xa55(%rip), %rsi       # 0x218f
jmp 0x1755
leaq 0xa5f(%rip), %rsi       # 0x21a2
jmp 0x1755
leaq 0xa66(%rip), %rsi       # 0x21b2
jmp 0x1755
leaq 0xa6d(%rip), %rsi       # 0x21c2
pushq $0x47
popq %rdi
xorl %eax, %eax
callq 0x10d0