// File: /workspace/github_c_makefile_star2_O3/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, %rbx
movl %edi, %ebp
movq $0x0, 0x10(%rsp)
leaq 0xcb6(%rip), %r13       # 0x2004
movq 0x2c83(%rip), %r12      # 0x3fd8
movq $0x0, 0x8(%rsp)
movl $0x0, 0x4(%rsp)
xorl %r14d, %r14d
xorl %r15d, %r15d
movl %ebp, %edi
movq %rbx, %rsi
movq %r13, %rdx
callq 0x1110
cmpl $0x66, %eax
jne 0x1384
movq (%r12), %r15
jmp 0x136c
cmpl $0x71, %eax
jg 0x13a9
cmpl $-0x1, %eax
je 0x13d4
cmpl $0x62, %eax
jne 0x17e2
movq (%r12), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x10c0
movq %rax, %r14
jmp 0x136c
cmpl $0x72, %eax
je 0x13c1
cmpl $0x77, %eax
jne 0x17e2
movl $0x1, 0x4(%rsp)
jmp 0x136c
movb $0x1, %al
movq %rax, 0x8(%rsp)
movl $0x241, %eax            # imm = 0x241
movq %rax, 0x10(%rsp)
jmp 0x136c
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testq %r14, %r14
je 0x1431
leaq 0xc32(%rip), %rdi       # 0x2017
movl $0x2, %esi
xorl %eax, %eax
callq 0x1100
testl %eax, %eax
movl 0x4(%rsp), %r12d
js 0x1836
movl %eax, %ebx
movl $0x40000, %esi          # imm = 0x40000
xorl %edi, %edi
movl $0x3, %edx
movl $0x1, %ecx
movl %eax, %r8d
movq %r14, %r9
callq 0x1060
movq %rax, %r14
cmpq $-0x1, %rax
jne 0x143e
leaq 0xbf4(%rip), %rsi       # 0x2020
jmp 0x1886
xorl %r14d, %r14d
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movl 0x4(%rsp), %r12d
testq %r15, %r15
je 0x146d
cmpb $0x2d, (%r15)
jne 0x1454
cmpb $0x0, 0x1(%r15)
je 0x178c
movq %r15, %rdi
movq 0x10(%rsp), %rsi
xorl %eax, %eax
callq 0x1100
movl %eax, %ebp
testl %eax, %eax
js 0x183f
testl %r12d, %r12d
setne %al
movq 0x8(%rsp), %rcx
orb %cl, %al
testb $0x1, %al
je 0x1518
testq %r14, %r14
je 0x1855
testl %ebp, %ebp
js 0x185a
testb $0x1, %cl
je 0x1593
movq %r14, %rdi
xorl %esi, %esi
callq 0x1892
movl %eax, %r15d
leaq 0x18(%rsp), %rsi
movl %eax, (%rsi)
movl $0x4, %edx
movl %ebp, %edi
callq 0x1050
cmpb $0x5a, %r15b
sete %al
shrl $0x10, %r15d
addl $0x7, %r15d
andl $-0x4, %r15d
cmpl $0x5, %r15d
setae %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x17ab
movl $0x4, %r12d
leaq 0x18(%rsp), %r13
movq %r14, %rdi
movl %r12d, %esi
callq 0x1892
movl %eax, 0x18(%rsp)
movl $0x4, %edx
movl %ebp, %edi
movq %r13, %rsi
callq 0x1050
addl $0x4, %r12d
cmpl %r12d, %r15d
ja 0x14ec
jmp 0x17ab
testq %r14, %r14
je 0x170f
movq %r14, %rdi
xorl %esi, %esi
callq 0x1892
cmpb $0x5a, %al
jne 0x17ab
movl %ebx, 0x4(%rsp)
shrl $0x10, %eax
movq %rax, 0x8(%rsp)
leal 0x3(%rax), %r12d
andl $-0x4, %r12d
movq %r12, %rdi
callq 0x10e0
movq %rax, %r13
testl %r12d, %r12d
je 0x1575
xorl %ebx, %ebx
leaq 0x4(%rbx), %r15
movq %r14, %rdi
movl %r15d, %esi
callq 0x1892
movl %eax, (%r13,%rbx)
movq %r15, %rbx
cmpq %r12, %r15
jb 0x1559
movq %r13, %rdi
movq 0x8(%rsp), %rsi
callq 0x1943
movq %r13, %rdi
callq 0x1030
movl 0x4(%rsp), %ebx
jmp 0x17ab
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
leaq 0x18(%rsp), %rsi
movl $0x0, (%rsi)
movl $0x4, %edx
movl %ebp, %edi
callq 0x10b0
testq %rax, %rax
jle 0x1797
movl %ebx, 0x4(%rsp)
xorl %r15d, %r15d
movl $0xffe00000, %ebx       # imm = 0xFFE00000
cmpl $0x1000000, %r15d       # imm = 0x1000000
jae 0x1802
movl 0x18(%rsp), %r13d
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
andl %ebx, %eax
orl $0xc000, %eax           # imm = 0xC000
movl %eax, 0x260(%r14)
btl $0x12, 0x260(%r14)
jae 0x165f
movl $0xffffff9c, %r12d      # imm = 0xFFFFFF9C
movl $0x64, %edi
callq 0x1150
incl %r12d
btl $0x12, 0x260(%r14)
jb 0x163e
testl %r12d, %r12d
je 0x1823
movl %r15d, %eax
shrl $0x2, %eax
movl %r13d, 0x264(%r14)
movl 0x260(%r14), %ecx
andl %ebx, %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)
btl $0x12, 0x260(%r14)
jae 0x16c8
movl $0xffffff9c, %r12d      # imm = 0xFFFFFF9C
movl $0x64, %edi
callq 0x1150
incl %r12d
btl $0x12, 0x260(%r14)
jb 0x16a7
testl %r12d, %r12d
je 0x181a
movq %r14, %rdi
movl %r15d, %esi
callq 0x1892
cmpl %r13d, %eax
jne 0x17e7
addl $0x4, %r15d
movl $0x0, 0x18(%rsp)
movl $0x4, %edx
movl %ebp, %edi
leaq 0x18(%rsp), %rsi
callq 0x10b0
testq %rax, %rax
jg 0x15e9
shrl $0x2, %r15d
movl 0x4(%rsp), %ebx
jmp 0x179a
testl %ebp, %ebp
js 0x185f
movl %ebx, %r13d
leaq 0x18(%rsp), %rsi
movl %ebp, %edi
callq 0x1140
testl %eax, %eax
js 0x1864
movq 0x48(%rsp), %r12
movslq %r12d, %rbx
movq %rbx, %rdi
callq 0x10e0
movq %rax, %r15
movl %ebp, %edi
movq %rax, %rsi
movq %rbx, %rdx
callq 0x10b0
cmpq %rbx, %rax
jl 0x186d
movl (%r15), %esi
cmpb $0x5a, %sil
jne 0x1876
shrl $0x10, %esi
leal 0x4(%rsi), %eax
cmpl %r12d, %eax
ja 0x187f
movl %r13d, %ebx
movq %r15, %rdi
addq $0x4, %rdi
callq 0x1943
movq %r15, %rdi
callq 0x1030
jmp 0x17af
movl %r12d, %ebp
xorl $0x1, %ebp
jmp 0x146d
xorl %r15d, %r15d
leaq 0x987(%rip), %rdi       # 0x2128
movl %r15d, %esi
xorl %eax, %eax
callq 0x1080
testl %ebp, %ebp
js 0x17b6
movl %ebp, %edi
callq 0x10a0
testl %ebx, %ebx
js 0x17ce
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
callq 0x1209
leaq 0x914(%rip), %rsi       # 0x2102
movl $0x47, %edi
movl %r15d, %edx
movl %eax, %ecx
movl %r13d, %r8d
xorl %eax, %eax
callq 0x1070
leaq 0x8c8(%rip), %rsi       # 0x20d1
movl $0x47, %edi
movl $0x1000000, %edx        # imm = 0x1000000
xorl %eax, %eax
callq 0x1070
leaq 0x8cc(%rip), %rsi       # 0x20ed
jmp 0x182a
leaq 0x911(%rip), %rsi       # 0x213b
movl $0x47, %edi
xorl %eax, %eax
callq 0x1070
leaq 0x7cf(%rip), %rsi       # 0x200c
jmp 0x1886
leaq 0x7ee(%rip), %rsi       # 0x2034
movl $0x47, %edi
movq %r15, %rdx
xorl %eax, %eax
callq 0x10d0
callq 0x11d6
callq 0x11a3
callq 0x1170
leaq 0x924(%rip), %rsi       # 0x218f
jmp 0x1886
leaq 0x92e(%rip), %rsi       # 0x21a2
jmp 0x1886
leaq 0x935(%rip), %rsi       # 0x21b2
jmp 0x1886
leaq 0x93c(%rip), %rsi       # 0x21c2
movl $0x47, %edi
xorl %eax, %eax
callq 0x10d0