// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x3a0, %rsp            # imm = 0x3A0
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %rdx
movaps %xmm0, (%rdx)
movaps %xmm0, 0x10(%rdx)
movaps %xmm0, 0x20(%rdx)
movaps %xmm0, 0x30(%rdx)
movaps %xmm0, 0x40(%rdx)
movq $0x0, 0x50(%rdx)
callq 0x2630
xorl %ebx, %ebx
testl %eax, %eax
je 0x28b1
testb $0x70, 0x11(%rsp)
jne 0x2809
leaq 0x9d60(%rip), %rdi      # 0xc554
leaq 0x8865(%rip), %rsi      # 0xb060
leaq 0x8873(%rip), %rdx      # 0xb075
xorl %eax, %eax
callq 0x2050
callq 0x20f0
movl %eax, %ebp
callq 0x2120
testl %ebp, %ebp
setne %cl
testl %eax, %eax
setne %al
andb %cl, %al
cmpb $0x1, %al
jne 0x282e
leaq 0x8b77(%rip), %rdi      # 0xb3a3
jmp 0x28ac
leaq 0x68(%rsp), %r15
xorl %ebx, %ebx
movl $0x338, %edx            # imm = 0x338
movq %r15, %rdi
xorl %esi, %esi
callq 0x2110
leaq 0x10(%rsp), %r14
movq %r15, %rdi
movq %r14, %rsi
callq 0x7081
testl %eax, %eax
je 0x28a5
movq %r14, 0x2e8(%rsp)
movq %rsp, %rbx
movl $0x1, %edi
movq %rbx, %rsi
callq 0x2170
movl $0xfffffc18, %r12d      # imm = 0xFFFFFC18
movabsq $-0x431bde82d7b634db, %rax # imm = 0xBCE4217D2849CB25
imulq 0x8(%rbx)
movq %rdx, %r14
movl 0x10(%rsp), %eax
xorl %ebx, %ebx
testb $0x1, %al
jne 0x28c3
testl $0x7008, %eax           # imm = 0x7008
je 0x2966
leaq 0x52d9(%rip), %rax      # 0x7b7c
jmp 0x28ca
leaq 0x8b1b(%rip), %rdi      # 0xb3c7
callq 0x2270
movl %ebx, %eax
addq $0x3a0, %rsp            # imm = 0x3A0
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0x4e94(%rip), %rax      # 0x775e
xorl %ecx, %ecx
imulq (%rsp), %r12
testb %cl, %cl
jne 0x28e3
leaq 0x68(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq *%rax
movl %eax, %ebx
movl 0x10(%rsp), %eax
testb $0x1, %al
je 0x28b1
andl $0x40, %eax
shrl $0x6, %eax
testl %ebx, %ebx
sete %cl
orb %al, %cl
jne 0x2908
leaq 0x68(%rsp), %rdi
callq 0x85ce
testl %eax, %eax
je 0x297b
movq %r14, %rax
shrq $0x3f, %rax
sarq $0x12, %r14
addq %rax, %r14
movq %rsp, %r15
movl $0x1, %edi
movq %r15, %rsi
callq 0x2170
imull $0x3e8, (%r15), %ecx    # imm = 0x3E8
movabsq $0x431bde82d7b634db, %rax # imm = 0x431BDE82D7B634DB
imulq 0x8(%r15)
movq %rdx, %rax
shrq $0x3f, %rax
shrq $0x12, %rdx
addl %edx, %eax
addl %ecx, %eax
addl %r12d, %r14d
addl %eax, %r14d
leaq 0x8771(%rip), %rdi      # 0xb0c8
movl %r14d, %esi
xorl %eax, %eax
callq 0x2050
jmp 0x28b1
btl $0x8, %eax
setae %cl
jae 0x298e
leaq 0x582e(%rip), %rax      # 0x81a4
jmp 0x28cc
leaq 0x8a62(%rip), %rdi      # 0xb3e4
callq 0x2270
xorl %ebx, %ebx
jmp 0x28b1
xorl %eax, %eax
jmp 0x28cc
nopl (%rax)