// File: /workspace/github_c_makefile_star2_O1/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 0xca6(%rip), %r13       # 0x2004
movq 0x2c73(%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 0x1120
cmpl $0x66, %eax
jne 0x1394
movq (%r12), %r15
jmp 0x137c
cmpl $0x71, %eax
jg 0x13b9
cmpl $-0x1, %eax
je 0x13e4
cmpl $0x62, %eax
jne 0x1802
movq (%r12), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x10d0
movq %rax, %r14
jmp 0x137c
cmpl $0x72, %eax
je 0x13d1
cmpl $0x77, %eax
jne 0x1802
movl $0x1, 0x4(%rsp)
jmp 0x137c
movb $0x1, %al
movq %rax, 0x8(%rsp)
movl $0x241, %eax            # imm = 0x241
movq %rax, 0x10(%rsp)
jmp 0x137c
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testq %r14, %r14
je 0x1441
leaq 0xc22(%rip), %rdi       # 0x2017
movl $0x2, %esi
xorl %eax, %eax
callq 0x1110
testl %eax, %eax
movl 0x4(%rsp), %ebx
js 0x1856
movl %eax, %r13d
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 0x144e
leaq 0xbe4(%rip), %rsi       # 0x2020
jmp 0x1890
xorl %r14d, %r14d
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
movl 0x4(%rsp), %ebx
testq %r15, %r15
je 0x1496
leaq 0xdab(%rip), %rsi       # 0x2205
movq %r15, %rdi
callq 0x10c0
testl %eax, %eax
je 0x1491
movq %r15, %rdi
movq 0x10(%rsp), %rsi
xorl %eax, %eax
callq 0x1110
movl %eax, %ebp
testl %eax, %eax
jns 0x1496
leaq 0xbb2(%rip), %rsi       # 0x2034
movl $0x47, %edi
movq %r15, %rdx
xorl %eax, %eax
callq 0x10e0
movl %ebx, %ebp
xorl $0x1, %ebp
testl %ebx, %ebx
setne %al
movq 0x8(%rsp), %rcx
orb %cl, %al
testb $0x1, %al
je 0x1555
testq %r14, %r14
je 0x185f
movl %r13d, 0x4(%rsp)
testl %ebp, %ebp
js 0x1864
testb $0x1, %cl
je 0x15cd
movq %r14, %rdi
xorl %esi, %esi
callq 0x189c
movl %eax, %r15d
leaq 0x18(%rsp), %rsi
movl %eax, (%rsi)
movl $0x4, %edx
movl %ebp, %edi
callq 0x1050
movzbl %r15b, %ebx
cmpl $0x5a, %ebx
sete %al
shrl $0x10, %r15d
addl $0x7, %r15d
andl $-0x4, %r15d
cmpl $0x5, %r15d
setae %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x174d
movl $0x8, %r13d
leaq 0x18(%rsp), %r12
leal -0x4(%r13), %esi
movq %r14, %rdi
callq 0x189c
movl %eax, 0x18(%rsp)
movl $0x4, %edx
movl %ebp, %edi
movq %r12, %rsi
callq 0x1050
cmpl $0x5a, %ebx
jne 0x174d
leal 0x4(%r13), %eax
cmpl %r13d, %r15d
movl %eax, %r13d
ja 0x151c
jmp 0x174d
testq %r14, %r14
je 0x1754
movq %r14, %rdi
xorl %esi, %esi
callq 0x189c
cmpb $0x5a, %al
jne 0x17c9
movl %r13d, 0x4(%rsp)
shrl $0x10, %eax
movq %rax, 0x8(%rsp)
leal 0x3(%rax), %r12d
andl $-0x4, %r12d
movq %r12, %rdi
callq 0x10f0
movq %rax, %r13
testl %r12d, %r12d
je 0x15b3
xorl %ebx, %ebx
leaq 0x4(%rbx), %r15
movq %r14, %rdi
movl %r15d, %esi
callq 0x189c
movl %eax, (%r13,%rbx)
movq %r15, %rbx
cmpq %r12, %r15
jb 0x1597
movq %r13, %rdi
movq 0x8(%rsp), %rsi
callq 0x194d
movq %r13, %rdi
callq 0x1030
jmp 0x174d
movl $0xa000, 0x260(%r14) # imm = 0xA000
movl $0x3e8, %edi            # imm = 0x3E8
callq 0x1160
movl $0x2000, 0x260(%r14) # imm = 0x2000
movl $0x3e8, %edi            # imm = 0x3E8
callq 0x1160
leaq 0x18(%rsp), %rsi
movl $0x0, (%rsi)
movl $0x4, %edx
movl %ebp, %edi
callq 0x10b0
xorl %r15d, %r15d
testq %rax, %rax
jle 0x173c
movl $0xffe00000, %ebx       # imm = 0xFFE00000
cmpl $0x1000000, %r15d       # imm = 0x1000000
jae 0x1822
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 0x1695
movl $0xffffff9c, %r12d      # imm = 0xFFFFFF9C
movl $0x64, %edi
callq 0x1160
incl %r12d
btl $0x12, 0x260(%r14)
jb 0x1674
testl %r12d, %r12d
je 0x1843
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 0x16fe
movl $0xffffff9c, %r12d      # imm = 0xFFFFFF9C
movl $0x64, %edi
callq 0x1160
incl %r12d
btl $0x12, 0x260(%r14)
jb 0x16dd
testl %r12d, %r12d
je 0x183a
movq %r14, %rdi
movl %r15d, %esi
callq 0x189c
cmpl %r13d, %eax
jne 0x1807
addl $0x4, %r15d
movl $0x0, 0x18(%rsp)
movl $0x4, %edx
movl %ebp, %edi
leaq 0x18(%rsp), %rsi
callq 0x10b0
testq %rax, %rax
jg 0x161f
shrl $0x2, %r15d
leaq 0x9e5(%rip), %rdi       # 0x2128
movl %r15d, %esi
xorl %eax, %eax
callq 0x1080
movl 0x4(%rsp), %r13d
jmp 0x17c9
testl %ebp, %ebp
js 0x1869
leaq 0x18(%rsp), %rsi
movl %ebp, %edi
callq 0x1150
testl %eax, %eax
js 0x186e
movq 0x48(%rsp), %r12
movslq %r12d, %rbx
movq %rbx, %rdi
callq 0x10f0
movq %rax, %r15
movl %ebp, %edi
movq %rax, %rsi
movq %rbx, %rdx
callq 0x10b0
cmpq %rbx, %rax
jl 0x1877
movl (%r15), %esi
cmpb $0x5a, %sil
jne 0x1880
shrl $0x10, %esi
leal 0x4(%rsi), %eax
cmpl %r12d, %eax
ja 0x1889
movq %r15, %rdi
addq $0x4, %rdi
callq 0x194d
movq %r15, %rdi
callq 0x1030
testl %ebp, %ebp
js 0x17d4
movl %ebp, %edi
callq 0x10a0
testl %r13d, %r13d
js 0x17ee
movl $0x40000, %esi          # imm = 0x40000
movq %r14, %rdi
callq 0x1100
movl %r13d, %edi
callq 0x10a0
xorl %eax, %eax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x1219
leaq 0x8f4(%rip), %rsi       # 0x2102
movl $0x47, %edi
movl %r15d, %edx
movl %eax, %ecx
movl %r13d, %r8d
xorl %eax, %eax
callq 0x1070
leaq 0x8a8(%rip), %rsi       # 0x20d1
movl $0x47, %edi
movl $0x1000000, %edx        # imm = 0x1000000
xorl %eax, %eax
callq 0x1070
leaq 0x8ac(%rip), %rsi       # 0x20ed
jmp 0x184a
leaq 0x8f1(%rip), %rsi       # 0x213b
movl $0x47, %edi
xorl %eax, %eax
callq 0x1070
leaq 0x7af(%rip), %rsi       # 0x200c
jmp 0x1890
callq 0x11e6
callq 0x11b3
callq 0x1180
leaq 0x91a(%rip), %rsi       # 0x218f
jmp 0x1890
leaq 0x924(%rip), %rsi       # 0x21a2
jmp 0x1890
leaq 0x92b(%rip), %rsi       # 0x21b2
jmp 0x1890
leaq 0x932(%rip), %rsi       # 0x21c2
movl $0x47, %edi
xorl %eax, %eax
callq 0x10e0