// File: /workspace/github_cpp_makefile_star2_O2/chenhn123[P]wdt_util_src/wdt_ct/wdt_ct.cpp
// Function: parse_args(int, char**, ExecParam*)
int parse_args(int argc, char* argv[], EXEC_PARAM* pparam)
{
	int 	opt;
	int 	index;
	char	*parg = 0;	

	/* only support I2C here */
	pparam->interface_num = INTERFACE_I2C;

	while ((opt = getopt_long(argc, argv, WDT_UTIL_GETOPTS, long_options, &index)) != -1) {
		switch (opt) {
			case 'h':
				print_help(argv[0]);
				return 0;
			case 'd':
				/* there would be the 0x20 in the leading sometimes */
				parg = optarg;
				while (*parg == 0x20)
					parg++;
				
				if (memcmp("/dev", parg, 4))
					sprintf(pparam->dev_path, "/dev/%s", parg);
				else
					strcpy(pparam->dev_path, parg);
				break;
			case 'u':
				pparam->argus |= OPTION_UPDATE;
				pparam->image_file = optarg;
				break;
			case 'f':
				pparam->argus |= OPTION_NO_FORCE;	
				break;
			case 'b':
				pparam->argus |= OPTION_NO_REBIND;
				break;
			case 'r':
				pparam->argus |= OPTION_NO_RPARAM;	
				break;				
			case 's':
				pparam->argus |= OPTION_INFO;
				break;				
			case 'w':
				pparam->argus |= OPTION_WIF_INFO;
				pparam->image_file = optarg;				
				break;
			case 'v':
				pparam->argus |= OPTION_FW_VER;
				break;
			case 'c':
				pparam->argus |= OPTION_CFG_CHKSUM;
				break;
			case 'i':
				pparam->argus |= OPTION_HW_ID;
				break;
			case 'x':
				pparam->argus |= OPTION_EXTRA_INFO;		
				g_show_extra_info = 1;
			case 'k':
				pparam->argus |= OPTION_BLOCK;
				break;	
			default:
				break;

		}
	}

	if (optind != argc) {
		int i=0; 
		while (i<argc) {
			printf("%s ", argv[i]);
			i++;
		}
		printf("\n");
		
		print_help(argv[0]);
		return 0;
	}

	return pparam->argus;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, %r15
movq %rsi, %rbx
movl %edi, %r14d
movl $0x2, 0x4(%rdx)
leaq 0x18(%rdx), %rax
movq %rax, 0x8(%rsp)
leaq 0xeb8b(%rip), %rbp      # 0x11190
leaq 0x14(%rsp), %r12
leaq 0x79f3(%rip), %r13      # 0xa004
movl %r14d, %edi
movq %rbx, %rsi
leaq 0x7a88(%rip), %rdx      # 0xa0a6
movq %rbp, %rcx
movq %r12, %r8
callq 0x22b0
leal -0x62(%rax), %ecx
cmpl $0x16, %ecx
ja 0x26e3
movslq (%r13,%rcx,4), %rax
addq %r13, %rax
jmpq *%rax
orb $0x40, (%r15)
jmp 0x2611
orb $0x1, 0x1(%r15)
jmp 0x26ac
orb $0x10, 0x1(%r15)
jmp 0x2611
orb $0x4, (%r15)
jmp 0x2611
orb $0x20, 0x1(%r15)
jmp 0x2611
orb $0x8, (%r15)
jmp 0x2611
movl (%r15), %eax
jmp 0x26d6
orb $0x20, (%r15)
jmp 0x2611
movq 0xe950(%rip), %rax      # 0x10fc8
movq (%rax), %rdx
decq %rdx
cmpb $0x20, 0x1(%rdx)
leaq 0x1(%rdx), %rdx
je 0x267e
cmpl $0x7665642f, (%rdx)     # imm = 0x7665642F
je 0x26ee
movq 0x8(%rsp), %rdi
leaq 0x7a20(%rip), %rsi      # 0xa0bc
xorl %eax, %eax
callq 0x2080
jmp 0x2611
orb $0x1, (%r15)
movq 0xe915(%rip), %rax      # 0x10fc8
movq (%rax), %rax
movq %rax, 0x10(%r15)
jmp 0x2611
orb $0x40, 0x1(%r15)
jmp 0x2611
movl (%r15), %eax
orl $0x10, %eax
movb $0x1, 0xecae(%rip)      # 0x11384
orl $0x80, %eax
movl %eax, (%r15)
jmp 0x2611
cmpl $-0x1, %eax
jne 0x2611
jmp 0x2700
movq 0x8(%rsp), %rdi
movq %rdx, %rsi
callq 0x2180
jmp 0x2611
movq 0xe8d1(%rip), %rax      # 0x10fd8
cmpl %r14d, (%rax)
jne 0x2711
movl (%r15), %eax
jmp 0x274e
xorl %eax, %eax
testl %r14d, %r14d
cmovlel %eax, %r14d
leaq 0x79a3(%rip), %r15      # 0xa0c4
xorl %r12d, %r12d
cmpq %r12, %r14
je 0x273c
movq (%rbx,%r12,8), %rsi
movq %r15, %rdi
xorl %eax, %eax
callq 0x2050
incq %r12
jmp 0x2724
pushq $0xa
popq %rdi
callq 0x2200
movq (%rbx), %rdi
callq 0x2408
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq