// File: 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
movq %rsp, %rbp
subq $0x40, %rsp
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq $0x0, -0x28(%rbp)
movq -0x18(%rbp), %rax
movl $0x2, 0x4(%rax)
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
leaq 0xcc4d(%rip), %rdx      # 0xf331
leaq 0x12a95(%rip), %rcx     # 0x15180
leaq -0x20(%rbp), %r8
callq 0x2290
movl %eax, -0x1c(%rbp)
cmpl $-0x1, %eax
je 0x288e
movl -0x1c(%rbp), %eax
addl $-0x62, %eax
movl %eax, %ecx
movq %rcx, -0x38(%rbp)
subl $0x16, %eax
ja 0x2887
movq -0x38(%rbp), %rax
leaq 0xc8e4(%rip), %rcx      # 0xf004
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x2400
movl $0x0, -0x4(%rbp)
jmp 0x28fc
movq 0x12880(%rip), %rax     # 0x14fc8
movq (%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x20, %eax
jne 0x2769
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x274f
movq -0x28(%rbp), %rax
movl (%rax), %eax
subl $0x7665642f, %eax       # imm = 0x7665642F
setne %al
movzbl %al, %eax
cmpl $0x0, %eax
je 0x279b
movq -0x18(%rbp), %rdi
addq $0x18, %rdi
movq -0x28(%rbp), %rdx
leaq 0xcbb5(%rip), %rsi      # 0xf347
movb $0x0, %al
callq 0x2080
jmp 0x27ac
movq -0x18(%rbp), %rdi
addq $0x18, %rdi
movq -0x28(%rbp), %rsi
callq 0x2180
jmp 0x2889
movq -0x18(%rbp), %rax
movl (%rax), %ecx
orl $0x1, %ecx
movl %ecx, (%rax)
movq 0x12805(%rip), %rax     # 0x14fc8
movq (%rax), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x10(%rax)
jmp 0x2889
movq -0x18(%rbp), %rax
movl (%rax), %ecx
orl $0x4, %ecx
movl %ecx, (%rax)
jmp 0x2889
movq -0x18(%rbp), %rax
movl (%rax), %ecx
orl $0x40, %ecx
movl %ecx, (%rax)
jmp 0x2889
movq -0x18(%rbp), %rax
movl (%rax), %ecx
orl $0x20, %ecx
movl %ecx, (%rax)
jmp 0x2889
movq -0x18(%rbp), %rax
movl (%rax), %ecx
orl $0x8, %ecx
movl %ecx, (%rax)
jmp 0x2889
movq -0x18(%rbp), %rax
movl (%rax), %ecx
orl $0x100, %ecx            # imm = 0x100
movl %ecx, (%rax)
movq 0x127a3(%rip), %rax     # 0x14fc8
movq (%rax), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x10(%rax)
jmp 0x2889
movq -0x18(%rbp), %rax
movl (%rax), %ecx
orl $0x1000, %ecx           # imm = 0x1000
movl %ecx, (%rax)
jmp 0x2889
movq -0x18(%rbp), %rax
movl (%rax), %ecx
orl $0x2000, %ecx           # imm = 0x2000
movl %ecx, (%rax)
jmp 0x2889
movq -0x18(%rbp), %rax
movl (%rax), %ecx
orl $0x4000, %ecx           # imm = 0x4000
movl %ecx, (%rax)
jmp 0x2889
movq -0x18(%rbp), %rax
movl (%rax), %ecx
orl $0x10, %ecx
movl %ecx, (%rax)
movl $0x1, 0x12afd(%rip)     # 0x15374
movq -0x18(%rbp), %rax
movl (%rax), %ecx
orl $0x80, %ecx
movl %ecx, (%rax)
jmp 0x2889
jmp 0x2889
jmp 0x26d6
movq 0x12743(%rip), %rax     # 0x14fd8
movl (%rax), %eax
cmpl -0x8(%rbp), %eax
je 0x28f3
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x28d0
movq -0x10(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
leaq 0xca91(%rip), %rdi      # 0xf34f
movb $0x0, %al
callq 0x2050
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x28a3
leaq 0xd3f0(%rip), %rdi      # 0xfcc7
movb $0x0, %al
callq 0x2050
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x2400
movl $0x0, -0x4(%rbp)
jmp 0x28fc
movq -0x18(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)