LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_cpp_makefile_star2_O2/chenhn123[P]wdt_util_src/wdt_ct/wdt_ct.cpp
// Function: print_help(char const*)
void print_help(const char *prog_name)
{
	print_version();
	
	printf("\nUsage: %s [OPTIONS] [FW_FILE|SUB-ARGU]\n", prog_name);
	printf("\t-h, --help\tPrint this message\n");
	printf("\t-d, --device\ti2c device file associated with the device\n");	
	printf("\t-u, --update\tUpdate firmware with verification\n");
	printf("\t-f, --no_force\tNot to force updating firmware\n");
	printf("\t-b, --no_bind\tNot to rebind driver after firmware updated\n");	
	printf("\t-r, --no_rpara\tNo need to update the recovery parameter\n");
	printf("\t-s, --info\tPrint the info associated with the devcie\n");
	printf("\t-w, --wif-info\tPrint the info associated with wif image file.\n");
	printf("\t-v, --fw-ver\tRead the fw version from the device\n");	
	printf("\t-c, --cfg-ver\tRead the cfg version from the device\n");		
	printf("\t-i, --hw-id\tRead the hardware id from the device\n");			
	printf("\t-x, --ext-info\tShow more information\n");
	printf("\t-k, --block\tUpdate fw by block\n");
}

// Assembly:
pushq %rbx
movq %rdi, %rbx
callq 0x23ec
leaq 0x7c65(%rip), %rdi      # 0xa07d
movq %rbx, %rsi
xorl %eax, %eax
callq 0x2050
leaq 0x7cfc(%rip), %rdi      # 0xa125
callq 0x2270
leaq 0x7d0f(%rip), %rdi      # 0xa144
callq 0x2270
leaq 0x7d3c(%rip), %rdi      # 0xa17d
callq 0x2270
leaq 0x7d60(%rip), %rdi      # 0xa1ad
callq 0x2270
leaq 0x7d83(%rip), %rdi      # 0xa1dc
callq 0x2270
leaq 0x7db2(%rip), %rdi      # 0xa217
callq 0x2270
leaq 0x7ddf(%rip), %rdi      # 0xa250
callq 0x2270
leaq 0x7e09(%rip), %rdi      # 0xa286
callq 0x2270
leaq 0x7e3c(%rip), %rdi      # 0xa2c5
callq 0x2270
leaq 0x7e62(%rip), %rdi      # 0xa2f7
callq 0x2270
leaq 0x7e8a(%rip), %rdi      # 0xa32b
callq 0x2270
leaq 0x7eb0(%rip), %rdi      # 0xa35d
callq 0x2270
leaq 0x7eca(%rip), %rdi      # 0xa383
popq %rbx
jmp 0x2270
// File: /workspace/github_cpp_makefile_star2_O2/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 %r15
pushq %r14
pushq %rbx
subq $0x390, %rsp            # imm = 0x390
xorps %xmm0, %xmm0
movq %rsp, %rdx
movaps %xmm0, (%rdx)
movaps %xmm0, 0x10(%rdx)
movaps %xmm0, 0x20(%rdx)
movaps %xmm0, 0x30(%rdx)
movaps %xmm0, 0x40(%rdx)
andq $0x0, 0x50(%rdx)
callq 0x25d7
xorl %ebx, %ebx
testl %eax, %eax
je 0x2883
testb $0x70, 0x1(%rsp)
jne 0x27a2
callq 0x23ec
callq 0x2596
testl %eax, %eax
je 0x27f9
leaq 0x58(%rsp), %r15
xorl %ebx, %ebx
movl $0x338, %edx            # imm = 0x338
movq %r15, %rdi
xorl %esi, %esi
callq 0x2110
movq %rsp, %r14
movq %r15, %rdi
movq %r14, %rsi
callq 0x66d8
testl %eax, %eax
je 0x2802
movq %r14, 0x2d8(%rsp)
callq 0x2565
movq %rax, %r14
movl (%rsp), %eax
testb $0x1, %al
jne 0x2810
testw $0x7008, %ax            # imm = 0x7008
je 0x2864
leaq 0x48ee(%rip), %rax      # 0x70e5
jmp 0x2817
leaq 0x7ba3(%rip), %rdi      # 0xa3a3
jmp 0x2809
leaq 0x7bbe(%rip), %rdi      # 0xa3c7
callq 0x2270
jmp 0x2883
leaq 0x4526(%rip), %rax      # 0x6d3d
leaq 0x58(%rsp), %rdi
movq %rsp, %r15
movq %r15, %rsi
callq *%rax
movl %eax, %ebx
movl (%r15), %eax
testb $0x1, %al
je 0x2883
andl $0x40, %eax
shrl $0x6, %eax
testl %ebx, %ebx
sete %cl
orb %al, %cl
jne 0x284a
leaq 0x58(%rsp), %rdi
callq 0x7b1d
testl %eax, %eax
je 0x2875
callq 0x2565
subl %r14d, %eax
leaq 0x786f(%rip), %rdi      # 0xa0c8
movl %eax, %esi
xorl %eax, %eax
callq 0x2050
jmp 0x2883
xorl %ebx, %ebx
btl $0x8, %eax
jae 0x2883
leaq 0x4ed4(%rip), %rax      # 0x7747
jmp 0x2817
leaq 0x7b68(%rip), %rdi      # 0xa3e4
callq 0x2270
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x390, %rsp            # imm = 0x390
popq %rbx
popq %r14
popq %r15
retq
nop
// File: /workspace/github_cpp_makefile_star2_O2/chenhn123[P]wdt_util_src/wdt_ct/w8755_funcs.cpp
// Function: wh_w8755_dev_exec_report_type_write(WdtDevice*, unsigned char, unsigned char*, int)
int wh_w8755_dev_exec_report_type_write(WDT_DEV* pdev, BYTE type, BYTE *pbuf, int size)
{
	W8755_WRITE_DATA write_data;

	if (!pdev || !pbuf)
		return 0;

	memset(&write_data, 0, sizeof(write_data));

	write_data.DD.rpt_id = W8755_RPTID_WRITE_DATA;
	write_data.DD.type = type;
	write_data.DD.size = size;

	memcpy(&write_data.DD.data[0], pbuf, size);

	if (g_func_dev_basic.p_wh_set_feature)
		return g_func_dev_basic.p_wh_set_feature(pdev, write_data.buffer, 4 + write_data.DD.size);		

	return 0;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
subq $0x40, %rsp
movl %ecx, %ebp
testq %rdi, %rdi
sete %al
testq %rdx, %rdx
sete %cl
xorl %r14d, %r14d
orb %al, %cl
jne 0x2903
movq %rdi, %rbx
leaq 0x4(%rsp), %rdi
xorps %xmm0, %xmm0
movups %xmm0, 0x2c(%rdi)
movups %xmm0, 0x20(%rdi)
movups %xmm0, 0x10(%rdi)
movups %xmm0, (%rdi)
movb $0x8, -0x4(%rdi)
movb %sil, -0x3(%rdi)
movw %bp, -0x2(%rdi)
movslq %ebp, %rax
movq %rdx, %rsi
movq %rax, %rdx
callq 0x2150
cmpq $0x0, 0xea9b(%rip)      # 0x11388
je 0x2903
movzwl %bp, %edx
addl $0x4, %edx
movq %rsp, %rsi
movq %rbx, %rdi
callq 0x3749
movl %eax, %r14d
movl %r14d, %eax
addq $0x40, %rsp
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/chenhn123[P]wdt_util_src/wdt_ct/w8755_funcs.cpp
// Function: wh_w8755_dev_exec_set_report_read(WdtDevice*, unsigned char, unsigned char*, int)
int wh_w8755_dev_exec_set_report_read(WDT_DEV* pdev, BYTE type, BYTE *pbuf, int size)
{
	W8755_WRITE_DATA write_data;

	if (!pdev || !pbuf || !g_func_dev_basic.p_wh_set_feature)
		return 0;

	write_data.DD.rpt_id = W8755_RPTID_REQ_READ;	
	write_data.DD.type = type;
	write_data.DD.size = size;
	
	return g_func_dev_basic.p_wh_set_feature(pdev, write_data.buffer, 4);	
}

// Assembly:
xorl %eax, %eax
testq %rdi, %rdi
je 0x2948
testq %rdx, %rdx
je 0x2948
cmpq $0x0, 0xea65(%rip)      # 0x11388
je 0x2948
subq $0x48, %rsp
leaq 0x8(%rsp), %rax
movb $0x6, (%rax)
movb %sil, 0x1(%rax)
movw %cx, 0x2(%rax)
pushq $0x4
popq %rdx
movq %rax, %rsi
callq 0x3749
addq $0x48, %rsp
retq
// File: /workspace/github_cpp_makefile_star2_O2/chenhn123[P]wdt_util_src/wdt_ct/w8755_funcs.cpp
// Function: wh_w8755_dev_exec_get_report_read(WdtDevice*, unsigned char, unsigned char*, int)
int wh_w8755_dev_exec_get_report_read(WDT_DEV* pdev, BYTE type, BYTE *pbuf, int size)
{
	W8755_READ_DATA read_data;
	int retval;
	UINT32 read_checksum, calc_checksum;
	
	if (!pdev || !pbuf || !g_func_dev_basic.p_wh_get_feature)
		return 0;

	memset(&read_data.buffer[0], 0xff, 4);
	memset(&read_data.buffer[4], 0, 60);
			
	read_data.DD.rpt_id = W8755_RPTID_READ_DATA;
	read_data.DD.type = type;
	retval = g_func_dev_basic.p_wh_get_feature(pdev, read_data.buffer, 64);
	if (!retval)
		return 0;

	if (read_data.DD.rpt_id != W8755_RPTID_READ_DATA) {
		wh_printf("%s: wrong rpt_id\n", __func__);
		return 0;
	}
		
	read_checksum = read_data.DD.checksum;
	calc_checksum = 0;
	for (int i=0; i<60; i++)
		calc_checksum += read_data.DD.data[i];
		
	if (read_checksum != calc_checksum) {
		wh_printf("%s: wrong chksum\n", __func__);
		return 0;
	}
	
	memcpy(pbuf, read_data.DD.data, size);
	return 1;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
subq $0x40, %rsp
xorl %r14d, %r14d
testq %rdi, %rdi
je 0x2a03
movq %rdx, %rbx
testq %rdx, %rdx
je 0x2a03
cmpq $0x0, 0xea1f(%rip)      # 0x11390
je 0x2a03
movl %ecx, %ebp
movq %rsp, %rax
movl $0xffffff07, (%rax)     # imm = 0xFFFFFF07
xorps %xmm0, %xmm0
movups %xmm0, 0x4(%rax)
movups %xmm0, 0x14(%rax)
movups %xmm0, 0x24(%rax)
movups %xmm0, 0x30(%rax)
movb %sil, 0x1(%rax)
pushq $0x40
popq %rdx
movq %rax, %rsi
callq 0x375a
testl %eax, %eax
je 0x2a03
cmpb $0x7, (%rsp)
jne 0x29cd
leaq 0x4(%rsp), %rsi
movzwl -0x2(%rsi), %eax
xorl %ecx, %ecx
pushq $0x4
popq %rdx
cmpq $0x40, %rdx
je 0x29d6
movzbl (%rsp,%rdx), %edi
addl %edi, %ecx
incq %rdx
jmp 0x29bc
leaq 0x7a88(%rip), %rdi      # 0xa45c
jmp 0x29f2
cmpl %eax, %ecx
jne 0x29eb
movslq %ebp, %rdx
movq %rbx, %rdi
callq 0x2150
pushq $0x1
popq %r14
jmp 0x2a03
leaq 0x7a9e(%rip), %rdi      # 0xa490
leaq 0x7a75(%rip), %rsi      # 0xa46e
xorl %r14d, %r14d
xorl %eax, %eax
callq 0x24bf
movl %r14d, %eax
addq $0x40, %rsp
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/chenhn123[P]wdt_util_src/wdt_ct/w8755_funcs.cpp
// Function: wh_w8755_dev_exec_report_type_read(WdtDevice*, unsigned char, unsigned char*, int, int)
int wh_w8755_dev_exec_report_type_read(WDT_DEV* pdev, BYTE type, BYTE *pbuf, int size, int offset)
{
	int retval;
	int i_size;

	if (offset & TYPE_READ_OFFSET_SET)
		i_size = offset & 0xFF;
	else
		i_size = size;

	retval = wh_w8755_dev_exec_set_report_read(pdev, type, pbuf, i_size);
	if (!retval)
		return 0;

	return wh_w8755_dev_exec_get_report_read(pdev, type, pbuf, size);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movl %ecx, %ebx
movq %rdx, %r14
movl %esi, %ebp
movq %rdi, %r15
btl $0x10, %r8d
movzbl %r8b, %ecx
cmovael %ebx, %ecx
callq 0x290f
testl %eax, %eax
je 0x2a50
movzbl %bpl, %esi
movq %r15, %rdi
movq %r14, %rdx
movl %ebx, %ecx
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x2949
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/chenhn123[P]wdt_util_src/wdt_ct/w8755_funcs.cpp
// Function: wh_w8755_dev_flash_write_data_page(WdtDevice*, unsigned char*, unsigned int, int)
int wh_w8755_dev_flash_write_data_page(WDT_DEV* pdev, BYTE* data, UINT32 address, int length)
{
	int	addr_start, data_len, packet_size;
	BYTE*	psource_data = 0;
	int	count = 0;
	int	retval = 1;

	if (!data)
		return 0;

	/* address and length should be align to 4 */
	if ((address & 0x3) != 0 || (length & 0x3) != 0)
		return 0;

	/* to make sure the data not exceed a sector */
	if ((address >> 8) != ((address + length - 1) >> 8))		
		return 0;

	data_len = length;
	addr_start = address;
	psource_data = data;

	packet_size = W8755_PACKET_SIZE;
	
	/* set the address to the device first */
	retval = wh_w8755_dev_exec_report_type_write(pdev, W8755_ISP_SET_FLASH_ADDRESS,
						     (BYTE *) &addr_start, 4);
	if (!retval)
		return 0;

	/* since the address is incremental, the following step just keep writting the flash data */
	while(data_len)	{		
		if (data_len < W8755_PACKET_SIZE)
			packet_size = data_len;

		if (!wh_w8755_dev_exec_report_type_write(pdev, W8755_ISP_SET_FLASH,
							 psource_data, packet_size)) {
			printf("can't set flash: 0x%x\n", addr_start);
			retval = 0;
			break;			
		}

		data_len = data_len - packet_size;
		psource_data = psource_data + packet_size;
		addr_start = addr_start + packet_size;


		wh_udelay(FLASH_PAGE_WRITE_DELAY_US);
		count++;
	}

	return retval; 
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
xorl %ebp, %ebp
testq %rsi, %rsi
je 0x2b4c
movl %ecx, %ebx
movl %ecx, %eax
orl %edx, %eax
testb $0x3, %al
jne 0x2b4c
leal (%rdx,%rbx), %eax
decl %eax
xorl %edx, %eax
cmpl $0xff, %eax
ja 0x2b4c
movq %rsi, %r14
movq %rdi, %r15
leaq 0x4(%rsp), %rax
movl %edx, (%rax)
pushq $0x4
popq %rcx
movl $0x87, %esi
movq %rax, %rdx
callq 0x2894
testl %eax, %eax
je 0x2b4c
movl %eax, %r12d
pushq $0x3c
popq %rbp
pushq $0x64
popq %r13
testl %ebx, %ebx
je 0x2b33
cmpl $0x3c, %ebx
cmovll %ebx, %ebp
movq %r15, %rdi
movl $0x83, %esi
movq %r14, %rdx
movl %ebp, %ecx
callq 0x2894
testl %eax, %eax
je 0x2b38
subl %ebp, %ebx
movslq %ebp, %rax
addq %rax, %r14
addl %ebp, 0x4(%rsp)
movl %r13d, %edi
callq 0x2560
jmp 0x2afd
movl %r12d, %ebp
jmp 0x2b4c
movl 0x4(%rsp), %esi
leaq 0x795f(%rip), %rdi      # 0xa4a2
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x2050
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/chenhn123[P]wdt_util_src/wdt_ct/w8755_funcs.cpp
// Function: wh_w8755_dev_flash_write_data(WdtDevice*, unsigned char*, unsigned int, int)
int wh_w8755_dev_flash_write_data(WDT_DEV* pdev, BYTE* pdata, UINT32 start_addr, int size)
{
	int retval = 0;
	unsigned int	write_base;
	unsigned int	write_size;

	write_base = 0x100;

	if (start_addr & 0xFF) {
		unsigned int 	size_partial;
		size_partial = write_base - (start_addr & 0xFF);
		
		WRITE_FLASH_PAGE(size_partial);			
	}

	while (size) {
		if ((start_addr & 0xfff) == 0)
			printf("base addr: 0x%x\n", start_addr);
	
		WRITE_FLASH_PAGE(write_base);			
	}

	return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %ecx, %r12d
movl %edx, %ebx
movq %rsi, %r14
movq %rdi, %r15
movl %edx, %eax
andl $0xff, %eax
je 0x2bb7
movl $0x100, %r13d           # imm = 0x100
subl %eax, %r13d
movl %r13d, %eax
subl %r12d, %eax
movl %r12d, %ecx
cmovll %r13d, %ecx
negl %eax
xorl %ebp, %ebp
cmpl %r13d, %r12d
movl %eax, %r12d
cmovlel %ebp, %r12d
movq %r15, %rdi
movq %r14, %rsi
movl %ebx, %edx
callq 0x2aa0
testl %eax, %eax
je 0x2c23
addq %r13, %r14
addl %r13d, %ebx
xorl %ebp, %ebp
movl $0x100, %r13d           # imm = 0x100
testl %r12d, %r12d
je 0x2c1c
testw $0xfff, %bx             # imm = 0xFFF
jne 0x2bdb
leaq 0x78e7(%rip), %rdi      # 0xa4b9
movl %ebx, %esi
xorl %eax, %eax
callq 0x2050
cmpl %r13d, %r12d
movl $0x100, %ecx            # imm = 0x100
cmovll %r12d, %ecx
movq %r15, %rdi
movq %r14, %rsi
movl %ebx, %edx
callq 0x2aa0
testl %eax, %eax
je 0x2c21
addq $0x100, %r14            # imm = 0x100
addl $0x100, %ebx            # imm = 0x100
cmpl $0x101, %r12d           # imm = 0x101
leal -0x100(%r12), %eax
cmovll %ebp, %eax
movl %eax, %r12d
jmp 0x2bbf
pushq $0x1
popq %rbp
jmp 0x2c23
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/chenhn123[P]wdt_util_src/wdt_ct/w8755_funcs.cpp
// Function: wh_w8755_i2c_delay(WdtDevice*, unsigned long)
int wh_w8755_i2c_delay(WDT_DEV* pdev, unsigned long delay)
{
        /* if the fw version is not supported,  just delay the max period and return */
        if (pdev->board_info.dev_info.w8755_dev_info.protocol_version < 0x01000006)
                wh_sleep(delay);
        else {
                BYTE rc = W8755_ISP_RSP_BUSY;
                unsigned long   start_tick = get_current_ms();
                int retval;
                BYTE readByte[8];
                int count = 0;
                unsigned long time_period = 0;
                int delay_slot = 10;

                if (delay < 100)
                        delay_slot = 5;

                if (!pdev || !pdev->dev_handle)
                                return 0;

                while (rc != W8755_ISP_RSP_OK && ((get_current_ms() - start_tick) < (delay + 100))) {

                        /* polling interval => 10ms */
                        wh_sleep(delay_slot);

                        retval = wh_i2c_rx(pdev, 0x2C, readByte, 3);
                        if (!retval)
                                continue;
                        else
                                /* 3 byte format: 0x0, 0x0, status */
                                rc = readByte[2];

                        count ++;
                }

                time_period = (get_current_ms() - start_tick);
                if (time_period > (delay + 50))
                        wh_printf("%s: timeout %d occured!\n", __func__, (int) time_period);

                return time_period;
        }

        return delay;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %rbx
cmpl $0x1000005, 0x1f8(%rdi) # imm = 0x1000005
ja 0x2f06
movl %ebx, %edi
callq 0x2555
jmp 0x2fa2
movq %rdi, %r14
callq 0x2565
movq %rax, %r15
xorl %eax, %eax
cmpq $0x64, %rbx
setae %cl
cmpq $0x0, 0x50(%r14)
je 0x2fa0
movb %cl, %al
leal (%rax,%rax,4), %ebp
addl $0x5, %ebp
movq %rbx, 0x8(%rsp)
leaq 0x64(%rbx), %r12
movb $-0x2, %al
leaq 0x10(%rsp), %r13
pushq $0x3
popq %rbx
negb %al
jo 0x2f6e
callq 0x2565
subq %r15, %rax
cmpq %r12, %rax
jae 0x2f6e
movl %ebp, %edi
callq 0x2555
movq %r14, %rdi
pushq $0x2c
popq %rsi
movq %r13, %rdx
movl %ebx, %ecx
callq 0x8dca
testl %eax, %eax
je 0x2f40
movb 0x12(%rsp), %al
jmp 0x2f3c
callq 0x2565
movq %rax, %rbx
subq %r15, %rbx
movq 0x8(%rsp), %rax
addq $0x32, %rax
cmpq %rax, %rbx
jbe 0x2fa2
leaq 0x7794(%rip), %rdi      # 0xa722
leaq 0x77a6(%rip), %rsi      # 0xa73b
movl %ebx, %edx
xorl %eax, %eax
callq 0x24bf
jmp 0x2fa2
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/chenhn123[P]wdt_util_src/wdt_ct/w8755_funcs.cpp
// Function: wh_w8755_dev_read_flash_status_register(WdtDevice*, unsigned int*)
unsigned int wh_w8755_dev_read_flash_status_register(WDT_DEV* pdev, unsigned int *pdata)
{
	BYTE				buf[64];

	*pdata = 0xff;

 	if (!wh_w8755_dev_exec_report_type_read(pdev, W8755_ISP_GET_FLASH_STATUS, buf, DataPayloadSize, 0)) {
		wh_printf("%s: report type read error\n", __func__);
		return 0;
	}

	*pdata = (unsigned int) buf[0];

	return 1;
}

// Assembly:
pushq %r14
pushq %rbx
subq $0x48, %rsp
movq %rsi, %r14
movl $0xff, (%rsi)
pushq $0x64
popq %rsi
movq %rsp, %rdx
pushq $0x3c
popq %rcx
xorl %ebx, %ebx
xorl %r8d, %r8d
callq 0x2a0f
testl %eax, %eax
je 0x2fe6
movzbl (%rsp), %eax
movl %eax, (%r14)
pushq $0x1
popq %rbx
jmp 0x2ffb
leaq 0x74ef(%rip), %rdi      # 0xa4dc
leaq 0x7504(%rip), %rsi      # 0xa4f8
xorl %eax, %eax
callq 0x24bf
movl %ebx, %eax
addq $0x48, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_cpp_makefile_star2_O2/chenhn123[P]wdt_util_src/wdt_ct/w8755_funcs.cpp
// Function: wh_w8755_dev_write_flash_status_register(WdtDevice*, unsigned int)
unsigned int wh_w8755_dev_write_flash_status_register(WDT_DEV* pdev, unsigned int r)
{
	BYTE				data;
	unsigned int		result;
	int					timeout_count = 0;
	
	data = (BYTE) (r & 0xff);

	if (!wh_w8755_dev_exec_report_type_write(pdev, W8755_ISP_SET_FLASH_STATUS, &data, 1)) {
		wh_printf("%s: report type write error\n", __func__);
		return 0;
	}

	/* timeout should be limit to 1 second */
	result = 0xFF;
	while ((result & 0x01) && (timeout_count < 100) ) {
		wh_w8755_dev_read_flash_status_register(pdev, &result);
		wh_printf("count: %d, (%d)\n", timeout_count, result);
		wh_sleep(10);
		timeout_count ++;
	}

	if (timeout_count >= 100)
		wh_printf("%s: error in timeout !\n", __func__);

	return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %r14
leaq 0x3(%rsp), %rdx
movb %sil, (%rdx)
pushq $0x1
popq %rcx
movl $0x84, %esi
callq 0x2894
testl %eax, %eax
je 0x3091
leaq 0x4(%rsp), %r15
movl $0xff, (%r15)
movl $0xff, %ebx
leaq 0x7522(%rip), %r12      # 0xa566
pushq $0xa
popq %rbp
xorl %r13d, %r13d
testb $0x1, %bl
je 0x307f
cmpl $0x63, %r13d
ja 0x307f
movq %r14, %rdi
movq %r15, %rsi
callq 0x2fb3
movl 0x4(%rsp), %ebx
movq %r12, %rdi
movl %r13d, %esi
movl %ebx, %edx
xorl %eax, %eax
callq 0x24bf
movl %ebp, %edi
callq 0x2555
incl %r13d
jmp 0x304a
cmpl $0x64, %r13d
jb 0x30aa
leaq 0x74eb(%rip), %rdi      # 0xa577
pushq $0x1
popq %rbx
jmp 0x309a
xorl %ebx, %ebx
leaq 0x7486(%rip), %rdi      # 0xa520
leaq 0x749c(%rip), %rsi      # 0xa53d
xorl %eax, %eax
callq 0x24bf
jmp 0x30ad
pushq $0x1
popq %rbx
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/chenhn123[P]wdt_util_src/wdt_ct/w8755_funcs.cpp
// Function: wh_w8755_dev_flash_erase(WdtDevice*, unsigned int, int)
int wh_w8755_dev_flash_erase(WDT_DEV* pdev, unsigned int address, int size)
{
	if (address == 0 && size == FLS_SZ) {
		if (!wh_w8755_dev_send_commands(pdev, WH_CMD_FLASH_ERASEALL, 0)) {			
			printf("Flash chip erase fails\n");
			return 0;
		}

		return 1;
	} else {
		if (!IS_ADDR_SECTOR_ALIGNED(address))
			return 0;
		
		while (size > 0)
		{
			if (IS_ADDR_BLK64_ALIGNED(address) && size >= FLS_BLK64_SZ) {
				if (!wh_w8755_dev_send_commands(pdev, WH_CMD_FLASH_ERASE64K, address)) {
					printf("Flash 64k block erase fails: 0x%x\n", address);
					break;
				}			
				
				address += FLS_BLK64_SZ;
				size -= FLS_BLK64_SZ;
			} else if (IS_ADDR_BLK64_ALIGNED(address) && size >= FLS_BLK32_SZ) {
				if (!wh_w8755_dev_send_commands(pdev, WH_CMD_FLASH_ERASE32K, address)) {
					printf("Flash 32k block erase fails: 0x%x\n", address);
					break;
				}
				
				address += FLS_BLK32_SZ;
				size -= FLS_BLK32_SZ;
			} else	{
				if (!wh_w8755_dev_send_commands(pdev, WH_CMD_FLASH_ERASE4K, address)) {
					printf("Flash 4k block erase fails: 0x%x\n", address);
					break;
				}
		
				address += FLS_SEC_SZ;
				size -= FLS_SEC_SZ;
			}
		}
	}
	
	return (size <= 0);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %r14
movl %edx, %eax
xorl $0x80000, %eax          # imm = 0x80000
orl %esi, %eax
jne 0x30f8
pushq $0x12
popq %rsi
xorl %r15d, %r15d
movq %r14, %rdi
xorl %edx, %edx
callq 0x2c34
testl %eax, %eax
je 0x31a0
pushq $0x1
popq %r15
jmp 0x31d9
movl %esi, %ebp
xorl %r15d, %r15d
testw $0xfff, %bp             # imm = 0xFFF
jne 0x31d9
movl %edx, %ebx
pushq $0x14
popq %r12
pushq $0x15
popq %r13
pushq $0x13
popq %r15
testl %ebx, %ebx
jle 0x31d0
testw %bp, %bp
setne %al
cmpl $0x10000, %ebx          # imm = 0x10000
setb %cl
orb %al, %cl
jne 0x314f
movq %r14, %rdi
movl %r12d, %esi
movl %ebp, %edx
callq 0x2c34
testl %eax, %eax
je 0x31ae
addl $0x10000, %ebp          # imm = 0x10000
movl $0xffff0000, %eax       # imm = 0xFFFF0000
jmp 0x3199
testw %bp, %bp
setne %al
cmpl $0x8000, %ebx           # imm = 0x8000
setb %cl
movq %r14, %rdi
orb %al, %cl
jne 0x3180
movl %r13d, %esi
movl %ebp, %edx
callq 0x2c34
testl %eax, %eax
je 0x31c0
orl $0x8000, %ebp           # imm = 0x8000
movl $0xffff8000, %eax       # imm = 0xFFFF8000
jmp 0x3199
movl %r15d, %esi
movl %ebp, %edx
callq 0x2c34
testl %eax, %eax
je 0x31b7
addl $0x1000, %ebp           # imm = 0x1000
movl $0xfffff000, %eax       # imm = 0xFFFFF000
addl %eax, %ebx
jmp 0x3116
leaq 0x75bf(%rip), %rdi      # 0xa766
callq 0x2270
jmp 0x31d9
leaq 0x73da(%rip), %rdi      # 0xa58f
jmp 0x31c7
leaq 0x7417(%rip), %rdi      # 0xa5d5
jmp 0x31c7
leaq 0x73eb(%rip), %rdi      # 0xa5b2
movl %ebp, %esi
xorl %eax, %eax
callq 0x2050
xorl %r15d, %r15d
testl %ebx, %ebx
setle %r15b
movl %r15d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/chenhn123[P]wdt_util_src/wdt_ct/w8755_funcs.cpp
// Function: wh_w8755_dev_flash_get_checksum(WdtDevice*, unsigned int*, unsigned int, int)
int wh_w8755_dev_flash_get_checksum(WDT_DEV* pdev, UINT32* pchecksum, UINT32 address, int size)
{
	BYTE			buf[64];
	unsigned int	checksum;
	int				delay;	

	put_unaligned_le32(address, &buf[0]);
	put_unaligned_le32(size, &buf[4]);
	
	if (!wh_w8755_dev_exec_report_type_write(pdev, W8755_ISP_SET_CHECKSUM_CALC, buf, 8)) {
		printf("%s: report type write error!\n", __func__);
		return 0;
	}

	delay = (size + 1023) / 1024;
	delay = wh_w8755_i2c_delay(pdev, delay * 4);
	wh_printf("chksum delay: %d ms\n", delay);

	if (!wh_w8755_dev_exec_report_type_read(pdev, W8755_ISP_GET_CHECKSUM, buf, DataPayloadSize, 0)) {
		wh_printf("%s: report type read chksum error!\n", __func__);
		return 0;
	}

	checksum = get_unaligned_le16(buf);
	*pchecksum = checksum;

	return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x48, %rsp
movl %ecx, %ebp
movq %rsi, %rbx
movq %rdi, %r14
movq %rsp, %r15
movl %edx, %edi
movq %r15, %rsi
callq 0x668e
leaq 0x4(%rsp), %rsi
movl %ebp, %edi
callq 0x668e
pushq $0x8
popq %rcx
movq %r14, %rdi
movl $0x88, %esi
movq %r15, %rdx
callq 0x2894
testl %eax, %eax
je 0x3287
addl $0x3ff, %ebp            # imm = 0x3FF
movl $0x400, %ecx            # imm = 0x400
movl %ebp, %eax
cltd
idivl %ecx
shll $0x2, %eax
movslq %eax, %rsi
movq %r14, %rdi
callq 0x2edd
leaq 0x73e3(%rip), %rdi      # 0xa635
xorl %ebp, %ebp
movl %eax, %esi
xorl %eax, %eax
callq 0x24bf
pushq $0x65
popq %rsi
movq %rsp, %rdx
pushq $0x3c
popq %rcx
movq %r14, %rdi
xorl %r8d, %r8d
callq 0x2a0f
testl %eax, %eax
je 0x32a0
movq %rsp, %rdi
callq 0x6683
movzwl %ax, %eax
movl %eax, (%rbx)
pushq $0x1
popq %rbp
jmp 0x32b5
leaq 0x7369(%rip), %rdi      # 0xa5f7
leaq 0x7380(%rip), %rsi      # 0xa615
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x2050
jmp 0x32b5
leaq 0x73a3(%rip), %rdi      # 0xa64a
leaq 0x7367(%rip), %rsi      # 0xa615
xorl %eax, %eax
callq 0x24bf
movl %ebp, %eax
addq $0x48, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/chenhn123[P]wdt_util_src/wdt_ct/w8755_funcs.cpp
// Function: wh_w8755_dev_parse_new_dev_info(WdtDevice*, WeidaDeviceInfoNew*)
int wh_w8755_dev_parse_new_dev_info(WDT_DEV* pdev, W8755_DEV_INFO_NEW *pdev_info_new)
{
	BYTE	buffer[32];
	int	retval;

	retval = wh_w8755_dev_get_new_device_info(pdev, buffer, 0, 32);
	if (!retval)
		return 0;
	
	pdev_info_new->protocol_version = get_unaligned_le32(&buffer[0x00]);
	pdev_info_new->firmware_id = get_unaligned_le32(&buffer[0x04]);
	pdev_info_new->status = get_unaligned_le32(&buffer[0x08]);
	pdev_info_new->config_size = get_unaligned_le16(&buffer[0x10]);
	pdev_info_new->parameter_map_sum = get_unaligned_le16(&buffer[0x12]);
	pdev_info_new->firmware_revision = get_unaligned_le16(&buffer[0x14]);
	pdev_info_new->max_points = buffer[0x16];
	pdev_info_new->bytes_per_point = buffer[0x16];
	pdev_info_new->customer_config_id = get_unaligned_le32(&buffer[0x18]);

	pdev_info_new->boot_partition = W8755_BP_DEFAULT;
	if (pdev_info_new->protocol_version >= 0x01010000) {
		if (buffer[0x001E] == 0xB1)
			pdev_info_new->boot_partition = W8755_BP_PRIMARY;
		else if (buffer[0x001E] == 0xB2)
			pdev_info_new->boot_partition = W8755_BP_SECONDARY;
	}	



	return true;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
subq $0x20, %rsp
movq %rsi, %rbx
movq %rsp, %rsi
xorl %ebp, %ebp
pushq $0x20
popq %rcx
xorl %edx, %edx
callq 0x2a5d
testl %eax, %eax
je 0x3382
movq %rsp, %rdi
callq 0x6687
movl %eax, (%rbx)
leaq 0x4(%rsp), %rdi
callq 0x6687
movl %eax, 0x4(%rbx)
leaq 0x8(%rsp), %rdi
callq 0x6687
movl %eax, 0x8(%rbx)
leaq 0x10(%rsp), %rdi
callq 0x6683
movzwl %ax, %eax
movl %eax, 0xc(%rbx)
leaq 0x12(%rsp), %rdi
callq 0x6683
movzwl %ax, %eax
movl %eax, 0x10(%rbx)
leaq 0x14(%rsp), %r14
movq %r14, %rdi
callq 0x6683
movzwl %ax, %eax
movl %eax, 0x14(%rbx)
movzbl 0x2(%r14), %eax
movl %eax, 0x18(%rbx)
movl %eax, 0x1c(%rbx)
leaq 0x18(%rsp), %rdi
callq 0x6687
movl %eax, 0x20(%rbx)
andl $0x0, 0x24(%rbx)
cmpl $0x1010000, (%rbx)      # imm = 0x1010000
jb 0x337f
movzbl 0x1e(%rsp), %eax
pushq $0x1
popq %rbp
movl %ebp, %ecx
cmpl $0xb1, %eax
je 0x337a
cmpl $0xb2, %eax
jne 0x3382
pushq $0x2
popq %rcx
movl %ecx, 0x24(%rbx)
jmp 0x3382
pushq $0x1
popq %rbp
movl %ebp, %eax
addq $0x20, %rsp
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/chenhn123[P]wdt_util_src/wdt_ct/w8755_funcs.cpp
// Function: wh_w8755_dev_verify_chunk_by_read_checksum(WdtDevice*, ChunkInfoEx*)
int wh_w8755_dev_verify_chunk_by_read_checksum(WDT_DEV* pdev, CHUNK_INFO_EX* pChunk)
{
	int retval = 0, result = 1;
	UINT32	bin_checksum;
	UINT32	read_checksum;
	
	retval = wh_w8755_dev_send_commands(pdev, WH_CMD_ALGO_STOP, 0);
	if (!retval)
		return retval;
		
	printf("Calculating checksum...\n");
	
	bin_checksum = misr_for_bytes(0, pChunk->pData, 0, pChunk->chuckInfo.length);

	retval = wh_w8755_dev_flash_get_checksum(pdev, &read_checksum, pChunk->chuckInfo.targetStartAddr, pChunk->chuckInfo.length);
	if (!retval)
		return retval;

	if (bin_checksum != read_checksum) {
		printf("Checksum mismatch!!! Original=0x%x, Flash checksum=0x%x", bin_checksum, read_checksum);
		result = 0;
	}
	
	retval = wh_w8755_dev_send_commands(pdev, WH_CMD_ALGO_START, 0);
	if (!retval)
		return retval;
		
	return result;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rsi, %r14
movq %rdi, %rbx
pushq $0x2
popq %rsi
xorl %ebp, %ebp
xorl %edx, %edx
callq 0x2c34
testl %eax, %eax
je 0x3637
leaq 0x7217(%rip), %rdi      # 0xa7e8
callq 0x2270
movq 0x18(%r14), %rsi
movl 0x4(%r14), %ecx
xorl %ebp, %ebp
xorl %edi, %edi
xorl %edx, %edx
callq 0x7ddb
movl %eax, %r15d
movl (%r14), %edx
movl 0x4(%r14), %ecx
leaq 0x4(%rsp), %rsi
movq %rbx, %rdi
callq 0x31eb
testl %eax, %eax
je 0x3637
movzwl %r15w, %esi
movl 0x4(%rsp), %edx
cmpl %esi, %edx
jne 0x3615
pushq $0x1
popq %rbp
jmp 0x3625
leaq 0x7072(%rip), %rdi      # 0xa68e
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x2050
pushq $0x3
popq %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x2c34
testl %eax, %eax
cmovel %eax, %ebp
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/chenhn123[P]wdt_util_src/wdt_ct/w8755_funcs.cpp
// Function: wh_w8755_dev_program_chunk_verify(WdtDevice*, ChunkInfoEx*, int)
int wh_w8755_dev_program_chunk_verify(WDT_DEV* pdev, CHUNK_INFO_EX* pInputChunk, int option)
{
	int retval = 0;
	int ret = 0;

	CHUNK_INFO_EX	*pChunk = pInputChunk;
	FUNC_PTR_STRUCT_DEV_OPERATION funcs;

	memset(&funcs, 0, sizeof(FUNC_PTR_STRUCT_DEV_OPERATION));	

	retval = wh_w8755_dev_send_commands(pdev, WH_CMD_ALGO_STOP, 0);
	if (!retval)
		return retval;
		
	retval = wh_w8755_dev_send_commands(pdev, WH_CMD_FLASH_UNLOCK, 0);
	if (!retval)
		return retval;

	retval = wh_w8755_dev_flash_erase(pdev, pChunk->chuckInfo.targetStartAddr, pChunk->chuckInfo.length);
	if (!retval)
		goto chunk_exit;
		
	printf("Chunk program begin ...\n");
	retval = wh_w8755_dev_flash_write_data(pdev, pChunk->pData, pChunk->chuckInfo.targetStartAddr, pChunk->chuckInfo.length);
	if (!retval)
		goto chunk_exit;
	printf("Chunk program end...\n");

	if (wh_w8755_dev_verify_chunk(pdev, pInputChunk) <= 0) {
		printf("Checksum failed\n");
		goto chunk_exit;
	}
		
chunk_exit:
	ret = wh_w8755_dev_send_commands(pdev, WH_CMD_FLASH_LOCK, 0);
	if (!ret)
		return ret;
	
	ret = wh_w8755_dev_send_commands(pdev, WH_CMD_ALGO_START, 0);
	if (!ret)
		return ret;
		
	return retval;

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rsi, %r14
movq %rdi, %rbx
pushq $0x2
popq %rsi
xorl %ebp, %ebp
xorl %edx, %edx
callq 0x2c34
testl %eax, %eax
je 0x3715
pushq $0x11
popq %rsi
xorl %ebp, %ebp
movq %rbx, %rdi
xorl %edx, %edx
callq 0x2c34
testl %eax, %eax
je 0x3715
movl (%r14), %esi
movl 0x4(%r14), %edx
movq %rbx, %rdi
callq 0x30be
xorl %ebp, %ebp
movl $0x0, %r12d
testl %eax, %eax
je 0x36ee
leaq 0x7161(%rip), %rdi      # 0xa800
callq 0x2270
movq 0x18(%r14), %rsi
movl (%r14), %edx
movl 0x4(%r14), %ecx
movq %rbx, %rdi
callq 0x2b5d
movl $0x0, %r12d
testl %eax, %eax
je 0x36ee
movl %eax, %r15d
leaq 0x714d(%rip), %rdi      # 0xa818
callq 0x2270
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3720
testl %eax, %eax
jne 0x36eb
leaq 0x7147(%rip), %rdi      # 0xa82d
callq 0x2270
movl %r15d, %r12d
pushq $0x10
popq %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x2c34
testl %eax, %eax
je 0x3715
pushq $0x3
popq %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x2c34
testl %eax, %eax
cmovel %eax, %r12d
movl %r12d, %ebp
movl %ebp, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/chenhn123[P]wdt_util_src/wdt_ct/w8755_funcs.cpp
// Function: wh_w8755_dev_flash_read_data(WdtDevice*, unsigned char*, unsigned int, int)
int wh_w8755_dev_flash_read_data(WDT_DEV* pdev, BYTE* data, UINT32 address, int length)
{
	int		addr_start, data_len, packet_size;
	BYTE*	 psource_data = 0;
	int		count = 0;
	int		retval = 1;

	if (!pdev || !data)
		return 0;

	// address and length should be align to 4
	if ((address & 0x3) != 0 || (length & 0x3) != 0)
		return 0;

	data_len = length;
	addr_start = address;
	psource_data = data;

	packet_size = W8755_PACKET_SIZE;

	retval = wh_w8755_dev_exec_report_type_write(pdev, W8755_ISP_SET_FLASH_ADDRESS, (BYTE *) &addr_start, 4);
	if (!retval)
		return 0;

	while(data_len)	{
		if (data_len < W8755_PACKET_SIZE)
			packet_size = data_len;

		if (!wh_w8755_dev_exec_report_type_read(pdev, W8755_ISP_GET_FLASH, psource_data, packet_size, 0)) {
			wh_printf("can't get flash: 0x%x\n", addr_start);
			break;
		}

		data_len = data_len - packet_size;
		psource_data = psource_data + packet_size;
		addr_start = addr_start + packet_size;

		wh_sleep(1);
		count++;
	}

	return retval;

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %ecx, %ebx
testq %rdi, %rdi
sete %al
testq %rsi, %rsi
sete %cl
xorl %ebp, %ebp
orb %al, %cl
jne 0x384d
movl %ebx, %eax
orl %edx, %eax
testb $0x3, %al
jne 0x384d
movq %rsi, %r14
movq %rdi, %r15
leaq 0x4(%rsp), %rax
movl %edx, (%rax)
pushq $0x4
popq %rcx
movl $0x87, %esi
movq %rax, %rdx
callq 0x2894
testl %eax, %eax
je 0x384d
movl %eax, (%rsp)
pushq $0x3c
popq %r12
pushq $0x63
popq %r13
pushq $0x1
popq %rbp
testl %ebx, %ebx
je 0x384a
cmpl $0x3c, %ebx
cmovll %ebx, %r12d
movq %r15, %rdi
movl %r13d, %esi
movq %r14, %rdx
movl %r12d, %ecx
xorl %r8d, %r8d
callq 0x2a0f
testl %eax, %eax
je 0x3838
subl %r12d, %ebx
movslq %r12d, %rax
addq %rax, %r14
addl %r12d, 0x4(%rsp)
movl %ebp, %edi
callq 0x2555
jmp 0x37fe
movl 0x4(%rsp), %esi
leaq 0x6e83(%rip), %rdi      # 0xa6c6
xorl %eax, %eax
callq 0x24bf
movl (%rsp), %ebp
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/chenhn123[P]wdt_util_src/wdt_ct/w8755_funcs.cpp
// Function: wh_w8755_prepare_data(WdtDevice*, BoardInfo*, int)
int wh_w8755_dev_set_basic_op(WDT_DEV *pdev)
{
	if (!pdev)
		return 0;

	g_func_dev_basic.p_wh_get_feature = wh_w8755_dev_get_feature;
	g_func_dev_basic.p_wh_set_feature = wh_w8755_dev_set_feature;
	g_func_dev_basic.p_wh_read_report = wh_w8755_dev_read_report;

	return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
testq %rdi, %rdi
je 0x3ab2
movq %rsi, %r14
movq %rdi, %rbx
leaq -0x2fd(%rip), %rax      # 0x375a
movq %rax, 0xd932(%rip)      # 0x11390
leaq -0x31c(%rip), %rax      # 0x3749
movq %rax, 0xd91c(%rip)      # 0x11388
leaq 0x70(%rsi), %r15
movq %r15, %rsi
callq 0x32c2
testl %eax, %eax
je 0x3abb
movq 0x20(%r15), %rax
movq %rax, 0x218(%rbx)
movups (%r15), %xmm0
movups 0x10(%r15), %xmm1
movups %xmm1, 0x208(%rbx)
movups %xmm0, 0x1f8(%rbx)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x385e
testl %eax, %eax
je 0x3ad8
pushq $0x1
popq %rbp
jmp 0x3ae8
leaq 0x6c24(%rip), %rdi      # 0xa6dd
jmp 0x3adf
leaq 0x6c2a(%rip), %rdi      # 0xa6ec
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x24bf
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0x2e7b
jmp 0x3ae8
leaq 0x6c29(%rip), %rdi      # 0xa708
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x24bf
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)
// File: /workspace/github_cpp_makefile_star2_O2/chenhn123[P]wdt_util_src/wdt_ct/w8760_funcs.cpp
// Function: wh_w8760_get_feature_devinfo(ReportFeatureDevInfo*, unsigned char*)
int wh_w8760_get_feature_devinfo(W8760_REPORT_FEATURE_DEVINFO* report_feature_devinfo, BYTE* buf)
{
	if (!report_feature_devinfo || !buf)
		return 0;

	report_feature_devinfo->firmware_id = get_unaligned_le32(&buf[1]);	
	report_feature_devinfo->hardware_id = get_unaligned_le32(&buf[5]);
	report_feature_devinfo->serial_no = get_unaligned_le32(&buf[9]);
	report_feature_devinfo->n_touches_usb = buf[13];
	report_feature_devinfo->n_bytes_touch = buf[14];
	memcpy(report_feature_devinfo->platform_id, &buf[16], 8);
	memcpy(report_feature_devinfo->rom_signature, &buf[24], 8);

	report_feature_devinfo->protocol_version = buf[32];	
	report_feature_devinfo->firmware_rev_ext = buf[33];	
	report_feature_devinfo->parameter_section_size = get_unaligned_le16(&buf[34]);	
	report_feature_devinfo->parameter_mapid = get_unaligned_le16(&buf[36]);	
	memcpy(report_feature_devinfo->program_name_fourcc, &buf[38], 4);	
	memcpy(report_feature_devinfo->trackingid_or_old_part_num, &buf[42], 8);	
	
	return 1;
}

// Assembly:
testq %rdi, %rdi
sete %cl
testq %rsi, %rsi
sete %dl
xorl %eax, %eax
orb %cl, %dl
jne 0x3b9a
pushq %r14
pushq %rbx
pushq %rax
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x1(%rsi), %rdi
callq 0x6687
movl %eax, (%rbx)
leaq 0x5(%r14), %rdi
callq 0x6687
movl %eax, 0x4(%rbx)
leaq 0x9(%r14), %rdi
callq 0x6687
movl %eax, 0x8(%rbx)
movb 0xd(%r14), %al
movb %al, 0xc(%rbx)
movb 0xe(%r14), %al
movb %al, 0xd(%rbx)
movq 0x10(%r14), %rax
movq %rax, 0xf(%rbx)
movq 0x18(%r14), %rax
movq %rax, 0x17(%rbx)
movb 0x20(%r14), %al
movb %al, 0x1f(%rbx)
movb 0x21(%r14), %al
movb %al, 0x20(%rbx)
leaq 0x22(%r14), %rdi
callq 0x6683
movw %ax, 0x21(%rbx)
leaq 0x24(%r14), %rdi
callq 0x6683
movw %ax, 0x23(%rbx)
movl 0x26(%r14), %eax
movl %eax, 0x25(%rbx)
movq 0x2a(%r14), %rax
movq %rax, 0x29(%rbx)
pushq $0x1
popq %rax
addq $0x8, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_cpp_makefile_star2_O2/chenhn123[P]wdt_util_src/wdt_ct/w8760_funcs.cpp
// Function: wh_w8760_dev_set_feature(WdtDevice*, unsigned char*, unsigned int)
int wh_w8760_dev_set_feature(WDT_DEV* pdev, BYTE* buf, UINT32 buf_size)
{
	if (!pdev)
		return 0;

	if (buf[0] == W8760_COMMAND9 || buf[0] == W8760_PIPE9)
		buf_size = 10;
	else if (buf[0] == W8760_COMMAND63 || buf[0] == W8760_PIPE63 || 
		buf[0] == W8760_BLOCK63 )
		buf_size = 64;
	else {
		wh_printf("Feature id is not supported! (%d)\n", buf[0]);
		return 0;
	}
	
	if (pdev->intf_index == INTERFACE_I2C)
		return wh_i2c_set_feature(pdev, buf, buf_size);	

	return 0;
}

// Assembly:
testq %rdi, %rdi
je 0x3bf2
movzbl (%rsi), %eax
leal -0x6(%rax), %ecx
cmpb $0x9, %cl
jae 0x3bdd
movzbl %cl, %ecx
movl $0x1a3, %edx            # imm = 0x1A3
btl %ecx, %edx
jae 0x3bdd
cmpl $0x2, (%rdi)
jne 0x3bf2
leaq 0x6cd3(%rip), %rax      # 0xa8a8
movl (%rax,%rcx,4), %edx
jmp 0x8e72
pushq %rax
leaq 0x6ce7(%rip), %rdi      # 0xa8cc
movl %eax, %esi
xorl %eax, %eax
callq 0x24bf
addq $0x8, %rsp
xorl %eax, %eax
retq
// File: /workspace/github_cpp_makefile_star2_O2/chenhn123[P]wdt_util_src/wdt_ct/w8760_funcs.cpp
// Function: wh_w8760_dev_get_feature(WdtDevice*, unsigned char*, unsigned int)
int wh_w8760_dev_get_feature(WDT_DEV* pdev, BYTE* buf, UINT32 buf_size)
{
	if (!pdev)
		return 0;

	if (buf[0] == W8760_COMMAND9 || buf[0] == W8760_PIPE9)
		buf_size = 10;
	else if (buf[0] == W8760_COMMAND63 || buf[0] == W8760_PIPE63 || 
		buf[0] == W8760_BLOCK63 || buf[0] == VND_REQ_DEV_INFO)
		buf_size = 64;
	else {
		wh_printf("Feature id is not supported! (%d)\n", buf[0]);
		return 0;
	}
			
	if (pdev->intf_index == INTERFACE_I2C)
		return wh_i2c_get_feature(pdev, buf, buf_size);	

	return 0;
}

// Assembly:
testq %rdi, %rdi
je 0x3c43
movzbl (%rsi), %eax
cmpl $0xe, %eax
ja 0x3c1a
movl $0x4880, %ecx           # imm = 0x4880
btl %eax, %ecx
jb 0x3c21
movl $0x2040, %ecx           # imm = 0x2040
btl %eax, %ecx
jae 0x3c1a
pushq $0xa
jmp 0x3c23
cmpl $0xf2, %eax
jne 0x3c2e
pushq $0x40
popq %rdx
cmpl $0x2, (%rdi)
jne 0x3c43
jmp 0x8a10
pushq %rax
leaq 0x6c96(%rip), %rdi      # 0xa8cc
movl %eax, %esi
xorl %eax, %eax
callq 0x24bf
addq $0x8, %rsp
xorl %eax, %eax
retq
// File: /workspace/github_cpp_makefile_star2_O2/chenhn123[P]wdt_util_src/wdt_ct/w8760_funcs.cpp
// Function: wh_w8760_dev_command_read(WdtDevice*, unsigned char*, int, unsigned char*, int, int)
int wh_w8760_dev_command_read(WDT_DEV *pdev, BYTE* cmd, int cmd_size, BYTE* data, int start, int size)
{
	BYTE buf[64];
	if (wh_w8760_dev_command_write(pdev, cmd, 0, cmd_size) > 0) {
		if (size > 9)
			buf[0] = W8760_COMMAND63;
		else 
			buf[0] = W8760_COMMAND9;

		if (wh_w8760_dev_get_feature(pdev, buf, size) > 0) {
			memcpy(&data[start], &buf[1], size);
			return 1;
		}
	}
		  
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x40, %rsp
movl %r9d, %ebx
movl %r8d, %ebp
movq %rcx, %r14
movq %rdi, %r12
callq 0x3bac
xorl %r15d, %r15d
testl %eax, %eax
jle 0x3cb1
cmpl $0xa, %ebx
setge %al
orb $0x6, %al
movq %rsp, %rsi
movb %al, (%rsi)
movq %r12, %rdi
callq 0x3bf5
testl %eax, %eax
jle 0x3cb1
movslq %ebp, %rax
addq %rax, %r14
leaq 0x1(%rsp), %rsi
movslq %ebx, %rdx
movq %r14, %rdi
callq 0x2150
pushq $0x1
popq %r15
movl %r15d, %eax
addq $0x40, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/chenhn123[P]wdt_util_src/wdt_ct/w8760_funcs.cpp
// Function: wh_w8760_dev_write_items(WdtDevice*, int, unsigned char*, int, int, int)
int wh_w8760_dev_write_items(WDT_DEV *pdev, int cmd_id, BYTE* buffer, int start, int item_size, int item_count)
{
	int size = item_count * item_size;
	BYTE cmd[64];

	cmd[0] = W8760_COMMAND9;
	cmd[1] = cmd_id;
	cmd[2] = item_count;
	memcpy(&cmd[3], &buffer[start], size);

	return wh_w8760_dev_command_write(pdev, cmd, 0, size + 3);
}

// Assembly:
pushq %rbx
subq $0x40, %rsp
movq %rdi, %rbx
imull %r9d, %r8d
leaq 0x3(%rsp), %rdi
movb $0x6, -0x3(%rdi)
movb %sil, -0x2(%rdi)
movb %r9b, -0x1(%rdi)
movslq %ecx, %rsi
addq %rdx, %rsi
movslq %r8d, %rdx
callq 0x2150
movq %rsp, %rsi
movq %rbx, %rdi
callq 0x3bac
addq $0x40, %rsp
popq %rbx
retq
// File: /workspace/github_cpp_makefile_star2_O2/chenhn123[P]wdt_util_src/wdt_ct/w8760_funcs.cpp
// Function: wh_w8760_dev_write_array(WdtDevice*, int, unsigned char*, int, int, int)
int wh_w8760_dev_write_array(WDT_DEV *pdev, int cmd_id, BYTE* buffer, int start, int item_size, int item_count)
{
	int max_write_batch = (W8760_USB_MAX_PAYLOAD_SIZE - 2) / item_size;
	int i = start;

	while (item_count >= max_write_batch) {
		if (wh_w8760_dev_write_items(pdev, cmd_id, buffer, i, item_size, max_write_batch) <= 0)
			return 0;

		i += max_write_batch * item_size;
		item_count -= max_write_batch;
	}

	if (item_count > 0) 
		return wh_w8760_dev_write_items(pdev, cmd_id, buffer, i, item_size, item_count);

	return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %r8d, %ebx
movl %ecx, %ebp
movq %rdx, 0x10(%rsp)
movl %esi, 0xc(%rsp)
movq %rdi, %r12
pushq $0x3d
popq %rax
xorl %edx, %edx
idivl %r8d
movl %eax, %r13d
movl %eax, %r14d
imull %r8d, %r14d
movl %r9d, %r15d
subl %r13d, %r15d
jl 0x3d86
movq %r12, %rdi
movl 0xc(%rsp), %esi
movq 0x10(%rsp), %rdx
movl %ebp, %ecx
movl %ebx, %r8d
movl %r13d, %r9d
callq 0x3cec
testl %eax, %eax
jle 0x3daf
addl %r14d, %ebp
movl %r15d, %r9d
jmp 0x3d5c
testl %r9d, %r9d
jle 0x3db3
movq %r12, %rdi
movl 0xc(%rsp), %esi
movq 0x10(%rsp), %rdx
movl %ebp, %ecx
movl %ebx, %r8d
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3cec
xorl %eax, %eax
jmp 0x3db6
pushq $0x1
popq %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/chenhn123[P]wdt_util_src/wdt_ct/w8760_funcs.cpp
// Function: wh_w8760_dev_wait_cmd_end(WdtDevice*, int, int)
int wh_w8760_dev_wait_cmd_end(WDT_DEV* pdev, int timeout_ms, int invt_ms)
{
	int polling_timeout_ms = 5000;
	int polling_intv_ms = 5;
	int status;
	BYTE	status_buf[4];

	if (timeout_ms)
		polling_timeout_ms = timeout_ms;
	if (invt_ms)
		polling_intv_ms = invt_ms;	
	
	do
	{
		if (wh_w8760_dev_get_device_status(pdev, &status_buf[0], 0, 1) <= 0)
			return 0;
		
		status = status_buf[0];
		if ((status & W8760_COMMAND_BUSY) == 0) {			
			return 1;
		}

		wh_sleep(polling_intv_ms);
		polling_timeout_ms -= polling_intv_ms;		
	} while (polling_timeout_ms > 0);

	wh_printf("%s: timeout occured (%d)!\n", __func__, polling_timeout_ms * polling_intv_ms);	
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
testl %esi, %esi
movl $0x1388, %r12d          # imm = 0x1388
cmovnel %esi, %r12d
testl %edx, %edx
pushq $0x5
popq %r14
cmovnel %edx, %r14d
movl %r14d, %ebp
imull %r12d, %ebp
movl %r14d, %r15d
imull %r14d, %r15d
xorl %r13d, %r13d
movq %rbx, %rdi
leaq 0x4(%rsp), %rsi
xorl %edx, %edx
pushq $0x1
popq %rcx
callq 0x3e5c
testl %eax, %eax
je 0x3e4a
testb $0x1, 0x4(%rsp)
je 0x3e46
movl %r14d, %edi
callq 0x2555
subl %r14d, %r12d
subl %r15d, %ebp
testl %r12d, %r12d
jg 0x3dfa
leaq 0x6abe(%rip), %rdi      # 0xa8ef
leaq 0x6ad2(%rip), %rsi      # 0xa90a
xorl %r13d, %r13d
movl %ebp, %edx
xorl %eax, %eax
callq 0x24bf
jmp 0x3e4a
pushq $0x1
popq %r13
movl %r13d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/chenhn123[P]wdt_util_src/wdt_ct/w8760_funcs.cpp
// Function: wh_w8760_dev_run_program_from_background(WdtDevice*, unsigned int)
int wh_w8760_dev_run_program_from_background(WDT_DEV* pdev, UINT32 program_address)
{
	BYTE cmd[2 + 4 + 4];
	cmd[0] = W8760_COMMAND63;
	cmd[1] = W8760_RUN_PROGRAM_FORM_BACKGROUND;
	put_unaligned_le32(program_address, &cmd[2]);
	put_unaligned_le32(0, &cmd[6]);
	return wh_w8760_dev_command_write(pdev, cmd, 0, sizeof(cmd));	
}

// Assembly:
pushq %rbx
subq $0x10, %rsp
movl %esi, %eax
movq %rdi, %rbx
leaq 0x8(%rsp), %rsi
movw $0xe507, -0x2(%rsi)     # imm = 0xE507
movl %eax, %edi
callq 0x668e
leaq 0xc(%rsp), %rsi
xorl %edi, %edi
callq 0x668e
leaq 0x6(%rsp), %rsi
movq %rbx, %rdi
callq 0x3bac
addq $0x10, %rsp
popq %rbx
retq
// File: /workspace/github_cpp_makefile_star2_O2/chenhn123[P]wdt_util_src/wdt_ct/w8760_funcs.cpp
// Function: wh_w8760_dev_get_hid_descriptor_register(WdtDevice*, unsigned short*)
int wh_w8760_dev_get_hid_descriptor_register(WDT_DEV* pdev, UINT16* pvalue)
{
	BYTE cmd[] = { W8760_COMMAND9, W8760_GET_HID_DESCRIPTOR_REGISTER };
	BYTE buf[4];

	*pvalue = 0x20;
	if (wh_w8760_dev_command_read(pdev, cmd, sizeof(cmd), buf, 0, 2) <= 0)
		return 0;

	*pvalue = get_unaligned_le16(buf);
	return 1;
}

// Assembly:
pushq %rbp
pushq %rbx
pushq %rax
movq %rsi, %rbx
leaq 0x2(%rsp), %rsi
movw $0xcf06, (%rsi)         # imm = 0xCF06
movw $0x20, (%rbx)
leaq 0x4(%rsp), %rcx
xorl %ebp, %ebp
pushq $0x2
popq %r9
xorl %r8d, %r8d
callq 0x3c5a
testl %eax, %eax
je 0x3efa
leaq 0x4(%rsp), %rdi
callq 0x6683
movw %ax, (%rbx)
pushq $0x1
popq %rbp
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/chenhn123[P]wdt_util_src/wdt_ct/w8760_funcs.cpp
// Function: wh_w8760_dev_set_n_check_device_mode(WdtDevice*, unsigned char, int, int)
int wh_w8760_dev_set_n_check_device_mode(WDT_DEV* pdev, BYTE mode, int timeout_ms, int intv_ms)
{
	int polling_timeout_ms = 100;
	int polling_intv_ms = 5;

	/* if device in isp mode, just return */
	if (pdev->board_info.dev_type & FW_WDT8760_2_ISP)
		return 1;

	if (timeout_ms)
		polling_timeout_ms = timeout_ms;
	if (intv_ms)
		polling_intv_ms = intv_ms;

	do {
		wh_w8760_dev_set_device_mode(pdev, mode);

		if (wh_w8760_dev_get_device_mode(pdev) == mode)
			return 1;

		wh_sleep(polling_intv_ms);
		polling_timeout_ms -= polling_intv_ms;
	} while (polling_timeout_ms > 0);
	
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq $0x1
popq %rbx
testb $0x50, 0x189(%rdi)
jne 0x3fb5
movq %rdi, %r14
testl %edx, %edx
pushq $0x64
popq %r12
cmovnel %edx, %r12d
testl %ecx, %ecx
pushq $0x5
popq %rbp
cmovnel %ecx, %ebp
movzbl %sil, %r15d
movq %r14, %rdi
movl %r15d, %esi
callq 0x3f19
movq %r14, %rdi
callq 0x3f32
cmpl %r15d, %eax
je 0x3fb5
movl %ebp, %edi
callq 0x2555
subl %ebp, %r12d
testl %r12d, %r12d
jg 0x3f8c
xorl %ebx, %ebx
movl %ebx, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq