LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_cpp_makefile_star2_O3/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 %r12
pushq %rbx
subq $0x10, %rsp
xorl %ebp, %ebp
testq %rsi, %rsi
je 0x2ca7
movl %ecx, %ebx
movl %ecx, %eax
orl %edx, %eax
testb $0x3, %al
jne 0x2ca7
leal (%rdx,%rbx), %eax
decl %eax
xorl %edx, %eax
cmpl $0xff, %eax
ja 0x2ca7
movq %rsi, %r14
movq %rdi, %r15
leaq 0xc(%rsp), %rax
movl %edx, (%rax)
movl $0x87, %esi
movq %rax, %rdx
movl $0x4, %ecx
callq 0x2998
testl %eax, %eax
je 0x2ca7
movl %eax, %r12d
testl %ebx, %ebx
je 0x2c8e
movl $0x3c, %ebp
cmpl $0x3c, %ebx
cmovll %ebx, %ebp
movq %r15, %rdi
movl $0x83, %esi
movq %r14, %rdx
movl %ebp, %ecx
callq 0x2998
testl %eax, %eax
je 0x2c93
movslq %ebp, %rax
addq %rax, %r14
addl %ebp, 0xc(%rsp)
movl $0x64, %edi
callq 0x25a7
subl %ebp, %ebx
jne 0x2c5a
movl %r12d, %ebp
jmp 0x2ca7
movl 0xc(%rsp), %esi
leaq 0x8804(%rip), %rdi      # 0xb4a2
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x2050
movl %ebp, %eax
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O3/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 0x2d10
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 0x2bf8
testl %eax, %eax
je 0x2d87
addq %r13, %r14
addl %r13d, %ebx
movl $0x1, %ebp
testl %r12d, %r12d
je 0x2d87
xorl %r13d, %r13d
movl $0x100, %ebp            # imm = 0x100
testl $0xfff, %ebx            # imm = 0xFFF
jne 0x2d3a
leaq 0x8788(%rip), %rdi      # 0xb4b9
movl %ebx, %esi
xorl %eax, %eax
callq 0x2050
cmpl %ebp, %r12d
movl $0x100, %ecx            # imm = 0x100
cmovll %r12d, %ecx
movq %r15, %rdi
movq %r14, %rsi
movl %ebx, %edx
callq 0x2bf8
testl %eax, %eax
je 0x2d85
cmpl $0x101, %r12d           # imm = 0x101
leal -0x100(%r12), %eax
cmovll %r13d, %eax
addq $0x100, %r14            # imm = 0x100
addl $0x100, %ebx            # imm = 0x100
movl %eax, %r12d
testl %eax, %eax
jne 0x2d22
movl $0x1, %ebp
jmp 0x2d87
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_O3/chenhn123[P]wdt_util_src/wdt_ct/w8755_funcs.cpp
// Function: wh_w8755_dev_enable_spi_flash_protection(WdtDevice*, int)
int wh_w8755_dev_enable_spi_flash_protection(WDT_DEV* pdev, int protect)
{
	if (protect) {
		int retval = wh_w8755_dev_send_commands(pdev, WH_CMD_FLASH_PROTECTION_ON, 0);
			
		wh_sleep(20);
		return retval;
	}	
	else
	{
		if (wh_w8755_dev_send_commands(pdev, WH_CMD_FLASH_PROTECTION_OFF, 0)) {
			wh_sleep(20);

			return 1;
		}
	}
	return 0;
}

// Assembly:
pushq %rbp
pushq %rbx
pushq %rax
testl %esi, %esi
je 0x30c7
movl $0x16, %esi
xorl %edx, %edx
callq 0x2d98
movl %eax, %ebx
jmp 0x30de
xorl %ebp, %ebp
movl $0x17, %esi
xorl %edx, %edx
callq 0x2d98
movl $0x1, %ebx
testl %eax, %eax
je 0x30ea
movl $0x14, %edi
callq 0x259c
movl %ebx, %ebp
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %rax
movq %rsi, %rbx
cmpl $0x1000005, 0x1f8(%rdi) # imm = 0x1000005
ja 0x311c
movl %ebx, %edi
callq 0x259c
movl %ebx, %r14d
jmp 0x31ac
movq %rdi, %r14
callq 0x25ac
movq %rax, %r15
xorl %eax, %eax
cmpq $0x64, %rbx
setae %cl
cmpq $0x0, 0x50(%r14)
je 0x31a9
movb %cl, %al
leal (%rax,%rax,4), %ebp
addl $0x5, %ebp
leaq 0x64(%rbx), %r13
movq %rsp, %r12
callq 0x25ac
subq %r15, %rax
cmpq %r13, %rax
jae 0x317b
movl %ebp, %edi
callq 0x259c
movq %r14, %rdi
movl $0x2c, %esi
movq %r12, %rdx
movl $0x3, %ecx
callq 0x996a
testl %eax, %eax
je 0x3146
movb 0x2(%rsp), %al
negb %al
jno 0x3146
callq 0x25ac
movq %rax, %r14
subq %r15, %r14
addq $0x32, %rbx
cmpq %rbx, %r14
jbe 0x31ac
leaq 0x858c(%rip), %rdi      # 0xb722
leaq 0x859e(%rip), %rsi      # 0xb73b
movl %r14d, %edx
xorl %eax, %eax
callq 0x2506
jmp 0x31ac
xorl %r14d, %r14d
movl %r14d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O3/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)
movq %rsp, %rdx
xorl %ebx, %ebx
movl $0x64, %esi
movl $0x3c, %ecx
xorl %r8d, %r8d
callq 0x2b61
testl %eax, %eax
je 0x31f7
movzbl (%rsp), %eax
movl %eax, (%r14)
movl $0x1, %ebx
jmp 0x320c
leaq 0x82de(%rip), %rdi      # 0xb4dc
leaq 0x82f3(%rip), %rsi      # 0xb4f8
xorl %eax, %eax
callq 0x2506
movl %ebx, %eax
addq $0x48, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_cpp_makefile_star2_O3/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 %r12
pushq %rbx
subq $0x10, %rsp
movq %rdi, %rbx
leaq 0xb(%rsp), %rdx
movb %sil, (%rdx)
movl $0x84, %esi
movl $0x1, %ecx
callq 0x2998
testl %eax, %eax
je 0x32a1
leaq 0xc(%rsp), %r14
movl $0xff, (%r14)
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
leaq 0x830e(%rip), %r15      # 0xb566
incl %ebp
movq %rbx, %rdi
movq %r14, %rsi
callq 0x31be
movl 0xc(%rsp), %r12d
movq %r15, %rdi
movl %ebp, %esi
movl %r12d, %edx
xorl %eax, %eax
callq 0x2506
movl $0xa, %edi
callq 0x259c
testb $0x1, %r12b
je 0x328e
cmpl $0x63, %ebp
jb 0x3258
movl $0x1, %ebx
cmpl $0x63, %ebp
jb 0x32b8
leaq 0x82d8(%rip), %rdi      # 0xb577
jmp 0x32aa
xorl %ebx, %ebx
leaq 0x8276(%rip), %rdi      # 0xb520
leaq 0x828c(%rip), %rsi      # 0xb53d
xorl %eax, %eax
callq 0x2506
movl %ebx, %eax
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O3/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, %r15
movl %edx, %eax
xorl $0x80000, %eax          # imm = 0x80000
orl %esi, %eax
jne 0x330a
movq %r15, %rdi
movl $0x12, %esi
xorl %edx, %edx
callq 0x2d98
movl $0x1, %r14d
testl %eax, %eax
jne 0x3317
leaq 0x8466(%rip), %rdi      # 0xb766
callq 0x2270
xorl %r14d, %r14d
jmp 0x3317
movl %esi, %ebp
xorl %r14d, %r14d
testl $0xfff, %esi            # imm = 0xFFF
je 0x3329
movl %r14d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %edx, %ebx
movl $0x1, %r14d
testl %edx, %edx
jle 0x3317
leaq 0x8253(%rip), %r13      # 0xb58f
leaq 0x8292(%rip), %r12      # 0xb5d5
testw %bp, %bp
setne %al
cmpl $0x10000, %ebx          # imm = 0x10000
setb %cl
orb %al, %cl
jne 0x3376
movq %r15, %rdi
movl $0x14, %esi
movl %ebp, %edx
callq 0x2d98
testl %eax, %eax
je 0x33d1
addl $0x10000, %ebp          # imm = 0x10000
movl $0xffff0000, %eax       # imm = 0xFFFF0000
jmp 0x33c4
testw %bp, %bp
setne %al
cmpl $0x8000, %ebx           # imm = 0x8000
setb %cl
movq %r15, %rdi
orb %al, %cl
jne 0x33a9
movl $0x15, %esi
movl %ebp, %edx
callq 0x2d98
testl %eax, %eax
je 0x33d6
orl $0x8000, %ebp           # imm = 0x8000
movl $0xffff8000, %eax       # imm = 0xFFFF8000
jmp 0x33c4
movl $0x13, %esi
movl %ebp, %edx
callq 0x2d98
testl %eax, %eax
je 0x33dd
addl $0x1000, %ebp           # imm = 0x1000
movl $0xfffff000, %eax       # imm = 0xFFFFF000
addl %eax, %ebx
jg 0x3343
jmp 0x3317
movq %r13, %r12
jmp 0x33dd
leaq 0x81d5(%rip), %r12      # 0xb5b2
movq %r12, %rdi
movl %ebp, %esi
xorl %eax, %eax
callq 0x2050
xorl %r14d, %r14d
testl %ebx, %ebx
setle %r14b
jmp 0x3317
// File: /workspace/github_cpp_makefile_star2_O3/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 %r12
pushq %rbx
subq $0x40, %rsp
movl %ecx, %r15d
movq %rsi, %rbx
movq %rdi, %r14
movq %rsp, %r12
movl %edx, %edi
movq %r12, %rsi
callq 0x6f72
leaq 0x4(%rsp), %rsi
movl %r15d, %edi
callq 0x6f72
movq %r14, %rdi
movl $0x88, %esi
movq %r12, %rdx
movl $0x8, %ecx
callq 0x2998
testl %eax, %eax
je 0x34a8
leal 0x3ff(%r15), %eax
addl $0x7fe, %r15d           # imm = 0x7FE
testl %eax, %eax
cmovnsl %eax, %r15d
sarl $0xa, %r15d
shll $0x2, %r15d
movslq %r15d, %rsi
movq %r14, %rdi
callq 0x30f3
leaq 0x81c8(%rip), %rdi      # 0xb635
xorl %ebp, %ebp
movl %eax, %esi
xorl %eax, %eax
callq 0x2506
movq %rsp, %rdx
movq %r14, %rdi
movl $0x65, %esi
movl $0x3c, %ecx
xorl %r8d, %r8d
callq 0x2b61
testl %eax, %eax
je 0x34c1
movq %rsp, %rdi
callq 0x6f67
movzwl %ax, %eax
movl %eax, (%rbx)
movl $0x1, %ebp
jmp 0x34d6
leaq 0x8148(%rip), %rdi      # 0xb5f7
leaq 0x815f(%rip), %rsi      # 0xb615
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x2050
jmp 0x34d6
leaq 0x8182(%rip), %rdi      # 0xb64a
leaq 0x8146(%rip), %rsi      # 0xb615
xorl %eax, %eax
callq 0x2506
movl %ebp, %eax
addq $0x40, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O3/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 %r14
pushq %rbx
subq $0x68, %rsp
movq %rsi, %rbx
leaq 0x20(%rsp), %rdx
movl $0x73, %esi
movl $0x20, %ecx
movl $0x10000, %r8d          # imm = 0x10000
callq 0x2b61
testl %eax, %eax
je 0x35c8
movaps 0x20(%rsp), %xmm0
movaps 0x30(%rsp), %xmm1
leaq 0x10(%rsp), %r14
movaps %xmm1, (%r14)
movaps %xmm0, -0x10(%r14)
movq %rsp, %rdi
callq 0x6f6b
movl %eax, (%rbx)
leaq 0x4(%rsp), %rdi
callq 0x6f6b
movl %eax, 0x4(%rbx)
leaq 0x8(%rsp), %rdi
callq 0x6f6b
movl %eax, 0x8(%rbx)
movq %r14, %rdi
callq 0x6f67
movzwl %ax, %eax
movl %eax, 0xc(%rbx)
leaq 0x12(%rsp), %rdi
callq 0x6f67
movzwl %ax, %eax
movl %eax, 0x10(%rbx)
leaq 0x14(%rsp), %r14
movq %r14, %rdi
callq 0x6f67
movzwl %ax, %eax
movl %eax, 0x14(%rbx)
movzbl 0x2(%r14), %eax
movl %eax, 0x18(%rbx)
movl %eax, 0x1c(%rbx)
leaq 0x18(%rsp), %rdi
callq 0x6f6b
movl %eax, 0x20(%rbx)
movl $0x0, 0x24(%rbx)
movl $0x1, %eax
cmpl $0x1010000, (%rbx)      # imm = 0x1010000
jb 0x35d3
movzbl 0x1e(%rsp), %ecx
cmpl $0xb2, %ecx
je 0x35cc
cmpl $0xb1, %ecx
jne 0x35d3
movl $0x1, 0x24(%rbx)
jmp 0x35d3
xorl %eax, %eax
jmp 0x35d3
movl $0x2, 0x24(%rbx)
addq $0x68, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_cpp_makefile_star2_O3/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
xorl %ebp, %ebp
movl $0x2, %esi
xorl %edx, %edx
callq 0x2d98
testl %eax, %eax
je 0x3881
leaq 0x7fcf(%rip), %rdi      # 0xb7e8
callq 0x2270
movq 0x18(%r14), %rsi
movl 0x4(%r14), %ecx
xorl %ebp, %ebp
xorl %edi, %edi
xorl %edx, %edx
callq 0x88e6
movl %eax, %r15d
movl (%r14), %edx
movl 0x4(%r14), %ecx
leaq 0x4(%rsp), %rsi
movq %rbx, %rdi
callq 0x33f7
testl %eax, %eax
je 0x3881
movzwl %r15w, %esi
movl 0x4(%rsp), %edx
movl $0x1, %ebp
cmpl %esi, %edx
je 0x386d
leaq 0x7e2a(%rip), %rdi      # 0xb68e
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x2050
movq %rbx, %rdi
movl $0x3, %esi
xorl %edx, %edx
callq 0x2d98
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_O3/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
xorl %ebp, %ebp
movl $0x2, %esi
xorl %edx, %edx
callq 0x2d98
testl %eax, %eax
je 0x3967
xorl %ebp, %ebp
movq %rbx, %rdi
xorl %esi, %esi
callq 0x30b0
testl %eax, %eax
je 0x3967
movl (%r14), %esi
movl 0x4(%r14), %edx
movq %rbx, %rdi
callq 0x32c7
xorl %ebp, %ebp
movl $0x0, %r12d
testl %eax, %eax
je 0x393c
leaq 0x7f18(%rip), %rdi      # 0xb800
callq 0x2270
movq 0x18(%r14), %rsi
movl (%r14), %edx
movl 0x4(%r14), %ecx
movq %rbx, %rdi
callq 0x2cb6
movl $0x0, %r12d
testl %eax, %eax
je 0x393c
movl %eax, %r15d
leaq 0x7f04(%rip), %rdi      # 0xb818
callq 0x2270
testq %rbx, %rbx
je 0x392d
movq %rbx, %rdi
movq %r14, %rsi
callq 0x37f3
testl %eax, %eax
jne 0x3939
leaq 0x7ef9(%rip), %rdi      # 0xb82d
callq 0x2270
movl %r15d, %r12d
movq %rbx, %rdi
movl $0x10, %esi
xorl %edx, %edx
callq 0x2d98
testl %eax, %eax
je 0x3967
movq %rbx, %rdi
movl $0x3, %esi
xorl %edx, %edx
callq 0x2d98
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_O3/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 %r12
pushq %rbx
subq $0x10, %rsp
movl %ecx, %ebx
testq %rdi, %rdi
sete %al
testq %rsi, %rsi
sete %cl
xorl %r12d, %r12d
orb %al, %cl
jne 0x3aaa
movl %ebx, %eax
orl %edx, %eax
testb $0x3, %al
jne 0x3aaa
movq %rsi, %r14
movq %rdi, %r15
leaq 0xc(%rsp), %rax
movl %edx, (%rax)
movl $0x87, %esi
movq %rax, %rdx
movl $0x4, %ecx
callq 0x2998
testl %eax, %eax
je 0x3aaa
movl %eax, %ebp
testl %ebx, %ebx
je 0x3aa7
movl $0x3c, %r12d
cmpl $0x3c, %ebx
cmovll %ebx, %r12d
movq %r15, %rdi
movl $0x63, %esi
movq %r14, %rdx
movl %r12d, %ecx
xorl %r8d, %r8d
callq 0x2b61
testl %eax, %eax
je 0x3a95
movslq %r12d, %rax
addq %rax, %r14
addl %r12d, 0xc(%rsp)
movl $0x1, %edi
callq 0x259c
subl %r12d, %ebx
jne 0x3a58
jmp 0x3aa7
movl 0xc(%rsp), %esi
leaq 0x7c26(%rip), %rdi      # 0xb6c6
xorl %eax, %eax
callq 0x2506
movl %ebp, %r12d
movl %r12d, %eax
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O3/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 0x3d5c
movq %rsi, %r14
movq %rdi, %rbx
leaq -0x34c(%rip), %rax      # 0x39ac
movq %rax, 0xd691(%rip)      # 0x11390
leaq -0x36b(%rip), %rax      # 0x399b
movq %rax, 0xd67b(%rip)      # 0x11388
leaq 0x70(%rsi), %r15
movq %r15, %rsi
callq 0x34e5
testl %eax, %eax
je 0x3d6e
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 0x3aba
movl $0x1, %ebp
testl %eax, %eax
jne 0x3d90
leaq 0x79ae(%rip), %rdi      # 0xb708
jmp 0x3d63
leaq 0x797a(%rip), %rdi      # 0xb6dd
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x2506
jmp 0x3d90
leaq 0x7977(%rip), %rdi      # 0xb6ec
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x2506
movq %rbx, %rdi
movl $0x5, %esi
movl $0x1, %edx
callq 0x2d98
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)
// File: /workspace/github_cpp_makefile_star2_O3/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 0x3e44
pushq %r14
pushq %rbx
pushq %rax
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x1(%rsi), %rdi
callq 0x6f6b
movl %eax, (%rbx)
leaq 0x5(%r14), %rdi
callq 0x6f6b
movl %eax, 0x4(%rbx)
leaq 0x9(%r14), %rdi
callq 0x6f6b
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 0x6f67
movw %ax, 0x21(%rbx)
leaq 0x24(%r14), %rdi
callq 0x6f67
movw %ax, 0x23(%rbx)
movl 0x26(%r14), %eax
movl %eax, 0x25(%rbx)
movq 0x2a(%r14), %rax
movq %rax, 0x29(%rbx)
movl $0x1, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_cpp_makefile_star2_O3/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 0x3e9c
movzbl (%rsi), %eax
leal -0x6(%rax), %ecx
cmpb $0x9, %cl
jae 0x3e87
movzbl %cl, %ecx
movl $0x1a3, %edx            # imm = 0x1A3
btl %ecx, %edx
jae 0x3e87
cmpl $0x2, (%rdi)
jne 0x3e9c
leaq 0x7a29(%rip), %rax      # 0xb8a8
movl (%rax,%rcx,4), %edx
jmp 0x9a12
pushq %rax
leaq 0x7a3d(%rip), %rdi      # 0xb8cc
movl %eax, %esi
xorl %eax, %eax
callq 0x2506
addq $0x8, %rsp
xorl %eax, %eax
retq
// File: /workspace/github_cpp_makefile_star2_O3/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 0x3ef0
movzbl (%rsi), %eax
cmpl $0xe, %eax
ja 0x3ec5
movl $0x4880, %ecx           # imm = 0x4880
btl %eax, %ecx
jb 0x3ecc
movl $0xa, %edx
movl $0x2040, %ecx           # imm = 0x2040
btl %eax, %ecx
jb 0x3ed1
cmpl $0xf2, %eax
jne 0x3edb
movl $0x40, %edx
cmpl $0x2, (%rdi)
jne 0x3ef0
jmp 0x958c
pushq %rax
leaq 0x79e9(%rip), %rdi      # 0xb8cc
movl %eax, %esi
xorl %eax, %eax
callq 0x2506
addq $0x8, %rsp
xorl %eax, %eax
retq
// File: /workspace/github_cpp_makefile_star2_O3/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 0x3e56
xorl %r15d, %r15d
testl %eax, %eax
jle 0x3f60
cmpl $0xa, %ebx
setge %al
orb $0x6, %al
movq %rsp, %rsi
movb %al, (%rsi)
movq %r12, %rdi
callq 0x3e9f
testl %eax, %eax
jle 0x3f60
movslq %ebp, %rax
addq %rax, %r14
leaq 0x1(%rsp), %rsi
movslq %ebx, %rdx
movq %r14, %rdi
callq 0x2150
movl $0x1, %r15d
movl %r15d, %eax
addq $0x40, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O3/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 0x3e56
addq $0x40, %rsp
popq %rbx
retq
// File: /workspace/github_cpp_makefile_star2_O3/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 $0x68, %rsp
movl %r9d, %r15d
movl %ecx, %r12d
movq %rdx, %rcx
movl %esi, %r13d
movq %rdi, 0x10(%rsp)
movl $0x3d, %eax
xorl %edx, %edx
idivl %r8d
cmpl %r9d, %eax
movq %rcx, 0x18(%rsp)
movl %r8d, 0xc(%rsp)
jg 0x405f
movl %eax, %r14d
imull %r8d, %eax
movslq %eax, %rbp
movslq %r12d, %rbx
addq %rcx, %rbx
movb $0x6, 0x20(%rsp)
movb %r13b, 0x21(%rsp)
movb %r14b, 0x22(%rsp)
leaq 0x23(%rsp), %rdi
movq %rbx, %rsi
movq %rbp, %rdx
callq 0x2150
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x3e56
testl %eax, %eax
jle 0x40a8
subl %r14d, %r15d
addq %rbp, %rbx
addl %ebp, %r12d
cmpl %r14d, %r15d
jge 0x401f
testl %r15d, %r15d
jle 0x40a1
movl 0xc(%rsp), %ecx
imull %r15d, %ecx
leaq 0x23(%rsp), %rdi
movb $0x6, -0x3(%rdi)
movb %r13b, -0x2(%rdi)
movb %r15b, -0x1(%rdi)
movslq %r12d, %rax
movq 0x18(%rsp), %rsi
addq %rax, %rsi
movslq %ecx, %rdx
callq 0x2150
leaq 0x20(%rsp), %rsi
movq 0x10(%rsp), %rdi
callq 0x3e56
jmp 0x40aa
movl $0x1, %eax
jmp 0x40aa
xorl %eax, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O3/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, %r15d          # imm = 0x1388
cmovnel %esi, %r15d
testl %edx, %edx
movl $0x5, %r14d
cmovnel %edx, %r14d
movl %r14d, %ebp
imull %r15d, %ebp
movl %r14d, %r12d
imull %r14d, %r12d
xorl %r13d, %r13d
movl $0x100c906, (%rsp)      # imm = 0x100C906
movq %rbx, %rdi
movq %rsp, %rsi
leaq 0x4(%rsp), %rcx
xorl %r8d, %r8d
movl $0x1, %r9d
callq 0x3f07
testl %eax, %eax
je 0x4150
testb $0x1, 0x4(%rsp)
je 0x414a
movl %r14d, %edi
callq 0x259c
subl %r14d, %r15d
subl %r12d, %ebp
testl %r15d, %r15d
jg 0x40f0
leaq 0x77ba(%rip), %rdi      # 0xb8ef
leaq 0x77ce(%rip), %rsi      # 0xb90a
xorl %r13d, %r13d
movl %ebp, %edx
xorl %eax, %eax
callq 0x2506
jmp 0x4150
movl $0x1, %r13d
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_O3/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 0x6f72
leaq 0xc(%rsp), %rsi
xorl %edi, %edi
callq 0x6f72
leaq 0x6(%rsp), %rsi
movq %rbx, %rdi
callq 0x3e56
addq $0x10, %rsp
popq %rbx
retq
// File: /workspace/github_cpp_makefile_star2_O3/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
xorl %r8d, %r8d
movl $0x2, %r9d
callq 0x3f07
testl %eax, %eax
je 0x4216
leaq 0x4(%rsp), %rdi
callq 0x6f67
movw %ax, (%rbx)
movl $0x1, %ebp
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O3/chenhn123[P]wdt_util_src/wdt_ct/w8760_funcs.cpp
// Function: wh_w8760_dev_get_device_mode(WdtDevice*)
int wh_w8760_dev_get_device_mode(WDT_DEV* pdev)
{
	BYTE status[4];
	if (!pdev)
		return 0;

	if (wh_w8760_dev_get_device_status(pdev, status, 4, 1))
		return status[0];

	return 0;
}

// Assembly:
pushq %rbx
subq $0x10, %rsp
testq %rdi, %rdi
je 0x428b
leaq 0xc(%rsp), %rsi
movl $0x104c906, (%rsi)      # imm = 0x104C906
leaq 0x8(%rsp), %rcx
xorl %ebx, %ebx
xorl %r8d, %r8d
movl $0x1, %r9d
callq 0x3f07
testl %eax, %eax
je 0x428d
movzbl 0x8(%rsp), %ebx
jmp 0x428d
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x10, %rsp
popq %rbx
retq
// File: /workspace/github_cpp_makefile_star2_O3/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 %r13
pushq %r12
pushq %rbx
pushq %rax
movl $0x1, %ebx
testb $0x50, 0x189(%rdi)
jne 0x4305
movq %rdi, %r14
testl %edx, %edx
movl $0x64, %r12d
cmovnel %edx, %r12d
testl %ecx, %ecx
movl $0x5, %ebp
cmovnel %ecx, %ebp
movzbl %sil, %r13d
leaq 0x5(%rsp), %r15
movw $0xca06, 0x5(%rsp)      # imm = 0xCA06
movb %r13b, 0x7(%rsp)
movq %r14, %rdi
movq %r15, %rsi
callq 0x3e56
movq %r14, %rdi
callq 0x4256
cmpl %r13d, %eax
je 0x4305
movl %ebp, %edi
callq 0x259c
subl %ebp, %r12d
testl %r12d, %r12d
jg 0x42d0
xorl %ebx, %ebx
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_O3/chenhn123[P]wdt_util_src/wdt_ct/w8760_funcs.cpp
// Function: wh_w8760_dev_set_address(WdtDevice*, unsigned char, unsigned int)
int wh_w8760_dev_set_address(WDT_DEV* pdev, BYTE type, UINT32 address)
{
	BYTE cmd[8];

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

	if (!(type == W8760_SET_MEMORY_ADDRESS || type == W8760_SET_FLASH_ADDRESS))
		return 0;
	
	cmd[0] = W8760_COMMAND9;
	cmd[1] = type;
	put_unaligned_le32(address, &cmd[2]);
	if (type != W8760_SET_MEMORY_ADDRESS)
		cmd[5] = 0;

	return wh_w8760_dev_command_write(pdev, cmd, 0, 6);
}

// Assembly:
pushq %rbp
pushq %rbx
pushq %rax
movl %esi, %ebp
movq $0x6, (%rsp)
movl %ebp, %ecx
andb $-0x11, %cl
xorl %eax, %eax
cmpb $-0x40, %cl
jne 0x4358
movq %rdi, %rbx
leaq 0x2(%rsp), %rsi
movb %bpl, -0x1(%rsi)
movl %edx, %edi
callq 0x6f72
cmpb $-0x40, %bpl
je 0x434d
movb $0x0, 0x5(%rsp)
movq %rsp, %rsi
movq %rbx, %rdi
callq 0x3e56
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O3/chenhn123[P]wdt_util_src/wdt_ct/w8760_funcs.cpp
// Function: wh_w8760_dev_identify_platform(WdtDevice*, BoardInfo*)
int wh_w8760_dev_identify_platform(WDT_DEV* pdev, BOARD_INFO* pboardInfo)
{
	if (!pdev || !pboardInfo)
		return 0;

	if (memcmp(W8760_RomSignatureVerB, pdev->board_info.dev_info.w8760_feature_devinfo.rom_signature, 8) == 0) {
		pboardInfo->dev_type = FW_WDT8760;
		if (pdev->pparam->argus & OPTION_INFO)		
			printf("WDT8760_VerB\n");
		return 1;
	}

	if (memcmp(W8762_RomSignatureVerA, pdev->board_info.dev_info.w8760_feature_devinfo.rom_signature, 8) == 0) {
		pboardInfo->dev_type = FW_WDT8762;
		if (pdev->pparam->argus & OPTION_INFO)		
			printf("WDT8762_VerA\n");
		return 1;
	}

	if (memcmp(W8762_RomSignatureVerC, pdev->board_info.dev_info.w8760_feature_devinfo.rom_signature, 8) == 0) {
		pboardInfo->dev_type = FW_WDT8762;
		if (pdev->pparam->argus & OPTION_INFO)		
			printf("WDT8762_VerC\n");
		return 1;
	}
	
	return 0;
}

// Assembly:
testq %rdi, %rdi
sete %cl
testq %rsi, %rsi
sete %dl
xorl %eax, %eax
orb %cl, %dl
jne 0x4447
movq 0xcf32(%rip), %rcx      # 0x11350
cmpq 0x20f(%rdi), %rcx
je 0x4448
movq 0xcf2a(%rip), %rcx      # 0x11358
cmpq 0x20f(%rdi), %rcx
je 0x4468
movq 0xcf22(%rip), %rcx      # 0x11360
cmpq 0x20f(%rdi), %rcx
je 0x4488
retq
movl $0x800, (%rsi)          # imm = 0x800
movq 0x280(%rdi), %rcx
movl $0x1, %eax
testb $0x8, (%rcx)
je 0x4447
leaq 0x761d(%rip), %rdi      # 0xba83
jmp 0x44a6
movl $0x2000, (%rsi)         # imm = 0x2000
movq 0x280(%rdi), %rcx
movl $0x1, %eax
testb $0x8, (%rcx)
je 0x4447
leaq 0x75f0(%rip), %rdi      # 0xba76
jmp 0x44a6
movl $0x2000, (%rsi)         # imm = 0x2000
movq 0x280(%rdi), %rcx
movl $0x1, %eax
testb $0x8, (%rcx)
je 0x4447
leaq 0x75c3(%rip), %rdi      # 0xba69
pushq %rax
callq 0x2270
movl $0x1, %eax
addq $0x8, %rsp
retq
// File: /workspace/github_cpp_makefile_star2_O3/chenhn123[P]wdt_util_src/wdt_ct/w8760_funcs.cpp
// Function: wh_w8760_dev_erase_flash(WdtDevice*, unsigned int, unsigned int)
int wh_w8760_dev_erase_flash(WDT_DEV* pdev, UINT32 address, UINT32 size)
{
	BYTE cmd[4];

	cmd[0] = W8760_COMMAND9;
	cmd[1] = (BYTE) W8760_ERASE_FLASH;
	cmd[2] = (BYTE) (address >> 12);
	cmd[3] = (BYTE)(((address & 0x0FFF) + size + 4095) >> 12);

	if (wh_w8760_dev_command_write(pdev, cmd, 0, sizeof(cmd)) > 0)
		return wh_w8760_dev_wait_cmd_end(pdev, 0, 0);

	return 0;
}

// Assembly:
pushq %rbx
subq $0x10, %rsp
movq %rdi, %rbx
leaq 0xc(%rsp), %rax
movw $0xd206, (%rax)         # imm = 0xD206
movl %esi, %ecx
shrl $0xc, %ecx
movb %cl, 0x2(%rax)
movl $0xfff, %ecx            # imm = 0xFFF
andl %ecx, %esi
addl %ecx, %edx
addl %esi, %edx
shrl $0xc, %edx
movb %dl, 0x3(%rax)
movq %rax, %rsi
callq 0x3e56
testl %eax, %eax
jle 0x44fb
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x40b9
jmp 0x44fd
xorl %eax, %eax
addq $0x10, %rsp
popq %rbx
retq
// File: /workspace/github_cpp_makefile_star2_O3/chenhn123[P]wdt_util_src/wdt_ct/w8760_funcs.cpp
// Function: wh_w8760_dev_batch_write_flash(WdtDevice*, unsigned char*, int, int)
int wh_w8760_dev_batch_write_flash(WDT_DEV* pdev, BYTE* buf, int start, int size)
{
	if (size > W8760_USB_MAX_PAYLOAD_SIZE - 2) {
		wh_printf("%s: payload data overrun\n", __func__);
		return 0;
	}

	BYTE cmd[W8760_USB_MAX_PAYLOAD_SIZE+1];

	cmd[0] = W8760_COMMAND63;
	cmd[1] = (BYTE) W8760_WRITE_FLASH;
	cmd[2] = (BYTE) size;
	memcpy(&cmd[3], &buf[start], size);

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

// Assembly:
pushq %rbx
subq $0x40, %rsp
cmpl $0x3e, %ecx
jl 0x4526
leaq 0x7410(%rip), %rdi      # 0xb924
leaq 0x7423(%rip), %rsi      # 0xb93e
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x2506
jmp 0x4566
movq %rdi, %rbx
leaq 0x3(%rsp), %rdi
movw $0xd307, -0x3(%rdi)     # imm = 0xD307
movb %cl, -0x1(%rdi)
movslq %edx, %rax
addq %rax, %rsi
movslq %ecx, %rdx
callq 0x2150
movq %rsp, %rsi
movq %rbx, %rdi
callq 0x3e56
testl %eax, %eax
jle 0x4564
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x40b9
movl %eax, %ebx
jmp 0x4566
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x40, %rsp
popq %rbx
retq
// File: /workspace/github_cpp_makefile_star2_O3/chenhn123[P]wdt_util_src/wdt_ct/w8760_funcs.cpp
// Function: wh_w8760_dev_write_flash(WdtDevice*, int, unsigned char*, int, int)
int wh_w8760_dev_write_flash(WDT_DEV* pdev, int addr, BYTE* buf, int start, int size)
{
	int byte_count = size;
	int offset = start;
	int max_payload_size = W8760_USB_MAX_PAYLOAD_SIZE - 2;
	int cur_addr = 0xFFFFFFFF;
	
	while (byte_count >= max_payload_size) {
		if (!check_is_all_ff(&buf[offset], max_payload_size)) {
			if (cur_addr != addr) {
				if (!wh_w8760_dev_set_flash_address(pdev, addr))
					return 0;
			}

			if (wh_w8760_dev_batch_write_flash(pdev, buf, offset, max_payload_size) <= 0)
				return 0;
			cur_addr = addr + max_payload_size;
		} else 
			wh_printf("Already ff, no need to set: 0x%x\n", addr);			
		offset += max_payload_size;
		byte_count -= max_payload_size;
		addr += max_payload_size;
	}

	if (cur_addr != addr) {
		if (!wh_w8760_dev_set_flash_address(pdev, addr))
			return 0;
	}

	if (byte_count > 0) 
		return wh_w8760_dev_batch_write_flash(pdev, buf, offset, byte_count);

	return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %r8d, %r12d
movl %ecx, %ebx
movl %esi, %ebp
movq %rdi, 0x8(%rsp)
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
cmpl $0x3d, %r8d
movq %rdx, 0x10(%rsp)
jl 0x4637
movslq %ebx, %r13
addq %rdx, %r13
movq %r13, %rdi
movl $0x3d, %esi
callq 0x6f75
testl %eax, %eax
je 0x45c9
leaq 0x73a2(%rip), %rdi      # 0xb95d
movl %ebp, %esi
xorl %eax, %eax
callq 0x2506
addl $0x3d, %ebp
jmp 0x461c
cmpl %ebp, %r15d
je 0x45fc
movq $0xd006, (%rsp)         # imm = 0xD006
movl %ebp, %edi
leaq 0x2(%rsp), %rsi
callq 0x6f72
movb $0x0, 0x5(%rsp)
movq 0x8(%rsp), %rdi
movq %rsp, %rsi
callq 0x3e56
testl %eax, %eax
je 0x4689
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
movl %ebx, %edx
movl $0x3d, %ecx
callq 0x4503
testl %eax, %eax
je 0x4689
addl $0x3d, %ebp
movl %ebp, %r15d
leal -0x3d(%r12), %r14d
addq $0x3d, %r13
addl $0x3d, %ebx
cmpl $0x79, %r12d
movl %r14d, %r12d
jg 0x45a3
jmp 0x463a
movl %r12d, %r14d
cmpl %ebp, %r15d
je 0x466e
leaq 0x2(%rsp), %r12
movq $0xd006, -0x2(%r12)     # imm = 0xD006
movl %ebp, %edi
movq %r12, %rsi
callq 0x6f72
movb $0x0, 0x3(%r12)
movq %rsp, %rsi
movq 0x8(%rsp), %rdi
callq 0x3e56
testl %eax, %eax
je 0x4689
testl %r14d, %r14d
jle 0x468d
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
movl %ebx, %edx
movl %r14d, %ecx
callq 0x4503
jmp 0x4692
xorl %eax, %eax
jmp 0x4692
movl $0x1, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq