// File: chenhn123[P]wdt_util_src/wdt_ct/wdt_ct.cpp
// Function: main
int main(int argc, char * argv[]) 
{
	int		ret = 0;
	int		info_mask = OPTION_FW_VER | OPTION_CFG_CHKSUM | OPTION_HW_ID;
	EXEC_PARAM	exec_param;
	WDT_DEV		wdt_dev;
	unsigned long	start_tick;
	int (*LPFUNC_execution)(WDT_DEV*, EXEC_PARAM*);

	memset((void*) &exec_param, 0, sizeof(EXEC_PARAM));
	if(!parse_args(argc, argv, &exec_param)) {
		return 0;
	}

	if (!(exec_param.argus & info_mask))
		print_version();

	if (!check_privilege()) {
		printf("Must be a root to run this program!\n");
		return 0;
	}

	memset(&wdt_dev, 0, sizeof(WDT_DEV));
	
	if (!load_lib_func_address(&wdt_dev, &exec_param)) {
		printf("Load function table failed !\n");
		return 0;
	}

	wdt_dev.pparam = &exec_param;
	start_tick = get_current_ms();

	LPFUNC_execution = NULL;
	if (exec_param.argus & OPTION_UPDATE)
		LPFUNC_execution = image_file_burn_data_verify; 
	else if (exec_param.argus & (info_mask | OPTION_INFO))
		LPFUNC_execution = show_info; 
	else if (exec_param.argus & OPTION_WIF_INFO)
		LPFUNC_execution = show_wif_info; 
	
	if (LPFUNC_execution)
		ret = LPFUNC_execution(&wdt_dev, &exec_param);

	if (exec_param.argus & OPTION_UPDATE) {
		if (!(exec_param.argus & OPTION_NO_REBIND) && ret) {
			if (!rebind_driver(&wdt_dev)) {
				printf("Faild to rebind driver !\n");
				return 0;
			}
		}
		
		printf("It takes %ums\n", (unsigned int) (get_current_ms() - start_tick));
	}
	
	return ret;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x3c0, %rsp            # imm = 0x3C0
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
movl $0x7000, -0x18(%rbp)    # imm = 0x7000
leaq -0x70(%rbp), %rdi
xorl %esi, %esi
movl $0x58, %edx
callq 0x2110
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
leaq -0x70(%rbp), %rdx
callq 0x26b0
cmpl $0x0, %eax
jne 0x2968
movl $0x0, -0x4(%rbp)
jmp 0x2ae0
movl -0x70(%rbp), %eax
andl -0x18(%rbp), %eax
cmpl $0x0, %eax
jne 0x2978
callq 0x23d0
callq 0x2610
cmpl $0x0, %eax
jne 0x299c
leaq 0xc9ca(%rip), %rdi      # 0xf353
movb $0x0, %al
callq 0x2050
movl $0x0, -0x4(%rbp)
jmp 0x2ae0
leaq -0x3a8(%rbp), %rdi
xorl %esi, %esi
movl $0x338, %edx            # imm = 0x338
callq 0x2110
leaq -0x3a8(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x9300
cmpl $0x0, %eax
jne 0x29de
leaq 0xc9ad(%rip), %rdi      # 0xf378
movb $0x0, %al
callq 0x2050
movl $0x0, -0x4(%rbp)
jmp 0x2ae0
leaq -0x70(%rbp), %rax
movq %rax, -0x128(%rbp)
callq 0x25d0
movq %rax, -0x3b0(%rbp)
movq $0x0, -0x3b8(%rbp)
movl -0x70(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x2a1b
leaq 0x750e(%rip), %rax      # 0x9f20
movq %rax, -0x3b8(%rbp)
jmp 0x2a5a
movl -0x70(%rbp), %eax
movl -0x18(%rbp), %ecx
orl $0x8, %ecx
andl %ecx, %eax
cmpl $0x0, %eax
je 0x2a3b
leaq 0x7ade(%rip), %rax      # 0xa510
movq %rax, -0x3b8(%rbp)
jmp 0x2a58
movl -0x70(%rbp), %eax
andl $0x100, %eax            # imm = 0x100
cmpl $0x0, %eax
je 0x2a56
leaq 0x8351(%rip), %rax      # 0xada0
movq %rax, -0x3b8(%rbp)
jmp 0x2a58
jmp 0x2a5a
cmpq $0x0, -0x3b8(%rbp)
je 0x2a78
leaq -0x3a8(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq *-0x3b8(%rbp)
movl %eax, -0x14(%rbp)
movl -0x70(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x2ada
movl -0x70(%rbp), %eax
andl $0x40, %eax
cmpl $0x0, %eax
jne 0x2abe
cmpl $0x0, -0x14(%rbp)
je 0x2abe
leaq -0x3a8(%rbp), %rdi
callq 0xb2d0
cmpl $0x0, %eax
jne 0x2abc
leaq 0xc8ea(%rip), %rdi      # 0xf396
movb $0x0, %al
callq 0x2050
movl $0x0, -0x4(%rbp)
jmp 0x2ae0
jmp 0x2abe
callq 0x25d0
subq -0x3b0(%rbp), %rax
movl %eax, %esi
leaq 0xc8dd(%rip), %rdi      # 0xf3b0
movb $0x0, %al
callq 0x2050
movl -0x14(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x3c0, %rsp            # imm = 0x3C0
popq %rbp
retq
nopl (%rax)