// File: /workspace/github_cpp_makefile_star2_O3/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 0x28c1
testb $0x70, 0x11(%rsp)
jne 0x2814
leaq 0x9d55(%rip), %rdi      # 0xc554
leaq 0x885a(%rip), %rsi      # 0xb060
leaq 0x8868(%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 0x283c
leaq 0x8b6c(%rip), %rdi      # 0xb3a3
jmp 0x28bc
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 0x6fc1
testl %eax, %eax
je 0x28b5
movq %r14, 0x2e8(%rsp)
movq %rsp, %rbx
movl $0x1, %edi
movq %rbx, %rsi
callq 0x2170
movl $0xfffffc18, %r12d      # imm = 0xFFFFFC18
imulq (%rbx), %r12
movabsq $-0x431bde82d7b634db, %rax # imm = 0xBCE4217D2849CB25
imulq 0x8(%rbx)
movq %rdx, %r14
movl 0x10(%rsp), %eax
testb $0x1, %al
jne 0x28d3
testl $0x7008, %eax           # imm = 0x7008
je 0x296d
leaq 0x5213(%rip), %rax      # 0x7ac6
jmp 0x28da
leaq 0x8b0b(%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 0x4dd2(%rip), %rax      # 0x76ac
leaq 0x68(%rsp), %rdi
leaq 0x10(%rsp), %r15
movq %r15, %rsi
callq *%rax
movl %eax, %ebx
movl (%r15), %eax
testb $0x1, %al
je 0x28c1
andl $0x40, %eax
shrl $0x6, %eax
testl %ebx, %ebx
sete %cl
orb %al, %cl
jne 0x290f
leaq 0x68(%rsp), %rdi
callq 0x854e
testl %eax, %eax
je 0x2985
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 0x876a(%rip), %rdi      # 0xb0c8
movl %r14d, %esi
xorl %eax, %eax
callq 0x2050
jmp 0x28c1
xorl %ebx, %ebx
btl $0x8, %eax
jae 0x28c1
leaq 0x57b2(%rip), %rax      # 0x8132
jmp 0x28da
leaq 0x8a58(%rip), %rdi      # 0xb3e4
callq 0x2270
xorl %ebx, %ebx
jmp 0x28c1