// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x50, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0xffffffff, -0x14(%rbp) # imm = 0xFFFFFFFF
movl $0xffffffff, -0x18(%rbp) # imm = 0xFFFFFFFF
movl $0x0, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movq $0x0, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
leaq 0xd64(%rip), %rdx       # 0x205c
callq 0x1120
movl %eax, -0x1c(%rbp)
cmpl $-0x1, %eax
je 0x1373
movl -0x1c(%rbp), %eax
addl $-0x62, %eax
movl %eax, %ecx
movq %rcx, -0x48(%rbp)
subl $0x15, %eax
ja 0x1369
movq -0x48(%rbp), %rax
leaq 0xce3(%rip), %rcx       # 0x2004
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x2ca7(%rip), %rax      # 0x3fd8
movq (%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x10c0
movq %rax, -0x30(%rbp)
jmp 0x136e
movq 0x2c8c(%rip), %rax      # 0x3fd8
movq (%rax), %rax
movq %rax, -0x40(%rbp)
jmp 0x136e
movl $0x1, -0x20(%rbp)
jmp 0x136e
movl $0x1, -0x24(%rbp)
jmp 0x136e
jmp 0x1369
callq 0x1530
jmp 0x12ea
cmpq $0x0, -0x30(%rbp)
je 0x13ef
leaq 0xcee(%rip), %rdi       # 0x206f
movl $0x2, %esi
movb $0x0, %al
callq 0x1110
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
jge 0x13a9
movl $0x47, %edi
leaq 0xcc2(%rip), %rsi       # 0x2064
movb $0x0, %al
callq 0x10e0
movl -0x14(%rbp), %r8d
movq -0x30(%rbp), %r9
xorl %eax, %eax
movl %eax, %edi
movl $0x40000, %esi          # imm = 0x40000
movl $0x3, %edx
movl $0x1, %ecx
callq 0x1050
movq %rax, -0x38(%rbp)
movq $-0x1, %rax
cmpq %rax, -0x38(%rbp)
jne 0x13ed
movl $0x47, %edi
leaq 0xc92(%rip), %rsi       # 0x2078
movb $0x0, %al
callq 0x10e0
jmp 0x13ef
cmpq $0x0, -0x40(%rbp)
je 0x145d
movq -0x40(%rbp), %rdi
leaq 0xc8b(%rip), %rsi       # 0x208c
callq 0x10b0
cmpl $0x0, %eax
je 0x1448
movq -0x40(%rbp), %rdi
movl -0x20(%rbp), %ecx
xorl %esi, %esi
movl $0x241, %eax            # imm = 0x241
cmpl $0x0, %ecx
cmovnel %eax, %esi
movb $0x0, %al
callq 0x1110
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x18(%rbp)
jge 0x1446
movq -0x40(%rbp), %rdx
movl $0x47, %edi
leaq 0xc4f(%rip), %rsi       # 0x208e
movb $0x0, %al
callq 0x10e0
jmp 0x145b
movl -0x24(%rbp), %edx
movl $0x1, %eax
xorl %ecx, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
movl %eax, -0x18(%rbp)
jmp 0x145d
cmpl $0x0, -0x20(%rbp)
jne 0x1469
cmpl $0x0, -0x24(%rbp)
je 0x14be
cmpq $0x0, -0x38(%rbp)
jne 0x1483
leaq 0xc25(%rip), %rdi       # 0x209c
movb $0x0, %al
callq 0x1080
callq 0x1530
cmpl $0x0, -0x18(%rbp)
jge 0x149c
leaq 0xc27(%rip), %rdi       # 0x20b7
movb $0x0, %al
callq 0x1080
callq 0x1530
cmpl $0x0, -0x20(%rbp)
je 0x14b0
movq -0x38(%rbp), %rdi
movl -0x18(%rbp), %esi
callq 0x1560
jmp 0x14bc
movq -0x38(%rbp), %rdi
movl -0x18(%rbp), %esi
callq 0x1620
jmp 0x14f7
cmpq $0x0, -0x38(%rbp)
je 0x14d0
movq -0x38(%rbp), %rdi
callq 0x1710
jmp 0x14f5
cmpl $0x0, -0x18(%rbp)
jl 0x14e0
movl -0x18(%rbp), %edi
callq 0x17d0
jmp 0x14f3
leaq 0xbe8(%rip), %rdi       # 0x20cf
movb $0x0, %al
callq 0x1080
callq 0x1530
jmp 0x14f5
jmp 0x14f7
cmpl $0x0, -0x18(%rbp)
jl 0x1505
movl -0x18(%rbp), %edi
callq 0x1090
cmpl $0x0, -0x14(%rbp)
jl 0x1521
movq -0x38(%rbp), %rdi
movl $0x40000, %esi          # imm = 0x40000
callq 0x1100
movl -0x14(%rbp), %edi
callq 0x1090
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopw (%rax,%rax)