LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_cpp_makefile_star2_O2/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 0x4002
movq %rdi, %rbx
leaq 0x2(%rsp), %rsi
movb %bpl, -0x1(%rsi)
movl %edx, %edi
callq 0x668e
cmpb $-0x40, %bpl
je 0x3ff7
movb $0x0, 0x5(%rsp)
movq %rsp, %rsi
movq %rbx, %rdi
callq 0x3bac
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_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 0x40f9
pushq %rbx
movq 0xd2d9(%rip), %rcx      # 0x11350
pushq $0x1
popq %rbx
cmpq 0x20f(%rdi), %rcx
je 0x40bd
leaq 0x20f(%rdi), %rcx
movq 0xd2c7(%rip), %rdx      # 0x11358
cmpq (%rcx), %rdx
je 0x40d8
movq 0xd2c3(%rip), %rdx      # 0x11360
cmpq (%rcx), %rdx
jne 0x40f8
movl $0x2000, (%rsi)         # imm = 0x2000
movq 0x280(%rdi), %rax
testb $0x8, (%rax)
je 0x40f6
leaq 0x69ae(%rip), %rdi      # 0xaa69
jmp 0x40f1
movl $0x800, (%rsi)          # imm = 0x800
movq 0x280(%rdi), %rax
testb $0x8, (%rax)
je 0x40f6
leaq 0x69ad(%rip), %rdi      # 0xaa83
jmp 0x40f1
movl $0x2000, (%rsi)         # imm = 0x2000
movq 0x280(%rdi), %rax
testb $0x8, (%rax)
je 0x40f6
leaq 0x6985(%rip), %rdi      # 0xaa76
callq 0x2270
movl %ebx, %eax
popq %rbx
retq
// File: /workspace/github_cpp_makefile_star2_O2/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 0x3bac
testl %eax, %eax
jle 0x413f
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x3dc5
jmp 0x4141
xorl %eax, %eax
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_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 0x416a
leaq 0x67cc(%rip), %rdi      # 0xa924
leaq 0x67df(%rip), %rsi      # 0xa93e
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x24bf
jmp 0x41aa
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 0x3bac
testl %eax, %eax
jle 0x41a8
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x3dc5
movl %eax, %ebx
jmp 0x41aa
xorl %ebx, %ebx
movl %ebx, %eax
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_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, %ebx
movl %ecx, %ebp
movl %esi, %r12d
movq %rdi, 0x8(%rsp)
movslq %ecx, %r13
movq %rdx, 0x10(%rsp)
addq %rdx, %r13
pushq $-0x1
popq %r15
pushq $0x3d
popq %r14
cmpl $0x3d, %ebx
jl 0x424c
movq %r13, %rdi
movl %r14d, %esi
callq 0x6691
testl %eax, %eax
je 0x420b
leaq 0x6762(%rip), %rdi      # 0xa95d
movl %r12d, %esi
xorl %eax, %eax
callq 0x24bf
addl $0x3d, %r12d
jmp 0x4240
cmpl %r12d, %r15d
je 0x4221
movq 0x8(%rsp), %rdi
movl %r12d, %esi
callq 0x404d
testl %eax, %eax
je 0x4287
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
movl %ebp, %edx
movl %r14d, %ecx
callq 0x4147
testl %eax, %eax
je 0x4287
addl $0x3d, %r12d
movl %r12d, %r15d
addl $-0x3d, %ebx
addl $0x3d, %ebp
addq $0x3d, %r13
jmp 0x41e0
cmpl %r12d, %r15d
je 0x4262
movq 0x8(%rsp), %rdi
movl %r12d, %esi
callq 0x404d
testl %eax, %eax
je 0x4287
testl %ebx, %ebx
jle 0x428b
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
movl %ebp, %edx
movl %ebx, %ecx
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x4147
xorl %eax, %eax
jmp 0x428e
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_write_flash_page(WdtDevice*, int, unsigned char*, int)
int wh_w8760_dev_write_flash_page(WDT_DEV* pdev, int addr, BYTE* buf, int size)
{
	int retval = 0;
	unsigned int	write_base;
	unsigned int	write_size;

	write_base = W8760_FLASH_PAGE_SIZE;

	if (addr & 0xFF) {
		unsigned int 	size_partial;
		size_partial = write_base - (addr & 0xFF);
		
		if (size > (int) size_partial) {				
			write_size = size_partial;				
			size = size - size_partial;				
		} else {											
			write_size = size;								
			size = 0;										
		}													
		retval = wh_w8760_dev_write_flash(pdev, addr, (BYTE*) buf, 0, write_size);	
		if (!retval)										
			return retval;									
		buf = buf + size_partial;				
		addr = addr + size_partial;	
	}

	while (size)
	{
		if ((addr & 0xfff) == 0)
			printf("base addr: 0x%x\n", addr);
		if (size > (int) write_base) {				
			write_size = write_base;				
			size = size - write_base;				
		} else {											
			write_size = size;								
			size = 0;										
		}													
		retval = wh_w8760_dev_write_flash(pdev, addr, (BYTE*) buf, 0, write_size);	
		if (!retval)										
			return retval;									
		buf = buf + write_base;				
		addr = addr + write_base;			
	}

	return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %ecx, %r15d
movq %rdx, %rbx
movl %esi, %ebp
movq %rdi, %r14
movl %esi, %eax
andl $0xff, %eax
je 0x42fa
movl $0x100, %r12d           # imm = 0x100
subl %eax, %r12d
movl %r12d, %eax
subl %r15d, %eax
movl %r15d, %r8d
cmovll %r12d, %r8d
negl %eax
xorl %r13d, %r13d
cmpl %r12d, %r15d
movl %eax, %r15d
cmovlel %r13d, %r15d
movq %r14, %rdi
movl %ebp, %esi
movq %rbx, %rdx
xorl %ecx, %ecx
callq 0x41b2
testl %eax, %eax
je 0x436b
addq %r12, %rbx
addl %r12d, %ebp
movl $0x100, %r12d           # imm = 0x100
xorl %r13d, %r13d
testl %r15d, %r15d
je 0x4367
testw $0xfff, %bp             # imm = 0xFFF
jne 0x431f
leaq 0x61a3(%rip), %rdi      # 0xa4b9
movl %ebp, %esi
xorl %eax, %eax
callq 0x2050
cmpl %r12d, %r15d
movl $0x100, %r8d            # imm = 0x100
cmovll %r15d, %r8d
movq %r14, %rdi
movl %ebp, %esi
movq %rbx, %rdx
xorl %ecx, %ecx
callq 0x41b2
testl %eax, %eax
je 0x436b
addq $0x100, %rbx            # imm = 0x100
addl $0x100, %ebp            # imm = 0x100
cmpl $0x101, %r15d           # imm = 0x101
leal -0x100(%r15), %eax
movl $0x0, %ecx
cmovll %ecx, %eax
movl %eax, %r15d
jmp 0x4303
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_protect_flash(WdtDevice*, unsigned short)
int wh_w8760_dev_protect_flash(WDT_DEV* pdev, UINT16 protect_mask)
{
	UINT16 mask = protect_mask;
	
	BYTE cmd[] = { W8760_COMMAND9, (BYTE) W8760_PROTECT_FLASH, 0, 0, 0, 0 };
	put_unaligned_le16(mask, &cmd[2]);
	put_unaligned_le16((UINT16)~mask, &cmd[4]);

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

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
subq $0x10, %rsp
leaq 0xc(%rsp), %rbx
andw $0x0, (%rbx)
movl %esi, %ebp
movq %rdi, %r14
movl $0xd406, -0x4(%rbx)     # imm = 0xD406
leaq 0xa(%rsp), %rsi
movl %ebp, %edi
callq 0x668a
xorl $0xffff, %ebp           # imm = 0xFFFF
movl %ebp, %edi
movq %rbx, %rsi
callq 0x668a
leaq 0x8(%rsp), %rsi
movq %r14, %rdi
callq 0x3bac
addq $0x10, %rsp
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/chenhn123[P]wdt_util_src/wdt_ct/w8760_funcs.cpp
// Function: wh_w8760_dev_checksum_flash(WdtDevice*, unsigned int*, unsigned int, int, unsigned int)
int wh_w8760_dev_checksum_flash(WDT_DEV* pdev, UINT32* pchksum, UINT32 flash_address,
	int size, UINT32 init_sum)
{
	BYTE cmd[10];
	BYTE buf[4];		

	*pchksum = 0;

	cmd[0] = W8760_COMMAND9;
	cmd[1] = (BYTE) W8760_CALCULATE_FLASH_CHECKSUM;
	put_unaligned_le32(flash_address, &cmd[2]);
	put_unaligned_le32(size, &cmd[5]);	
	put_unaligned_le16(init_sum, &cmd[8]);	

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

	if (wh_w8760_dev_read_buf_response (pdev, buf, 2) <= 0)
		return 0;

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

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x18, %rsp
movl %r8d, %ebp
movl %ecx, %r15d
movq %rsi, %rbx
andl $0x0, (%rsi)
movq %rdi, %r14
leaq 0x10(%rsp), %rsi
movw $0xd506, -0x2(%rsi)     # imm = 0xD506
movl %edx, %edi
callq 0x668e
leaq 0x13(%rsp), %rsi
movl %r15d, %edi
callq 0x668e
leaq 0x16(%rsp), %rsi
movzwl %bp, %edi
callq 0x668a
leaq 0xe(%rsp), %rsi
movq %r14, %rdi
callq 0x3bac
xorl %ebp, %ebp
testl %eax, %eax
jle 0x445a
movq %r14, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x3dc5
testl %eax, %eax
je 0x445a
leaq 0xa(%rsp), %rsi
pushq $0x2
popq %rdx
movq %r14, %rdi
callq 0x3f03
testl %eax, %eax
je 0x445a
leaq 0xa(%rsp), %rdi
callq 0x6683
movzwl %ax, %eax
movl %eax, (%rbx)
pushq $0x1
popq %rbp
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
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_register(WdtDevice*, unsigned int, unsigned int)
int wh_w8760_dev_write_register(WDT_DEV* pdev, UINT32 address, UINT32 reg_value)
{
        BYTE cmd[10] = {0};

        cmd[0] = W8760_COMMAND9;
        cmd[1] = (BYTE) W8760_WRITE_REGISTER;
        put_unaligned_le32(address, &cmd[2]);
        put_unaligned_le32(reg_value, &cmd[6]);

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

// Assembly:
pushq %r14
pushq %rbx
subq $0x18, %rsp
movl %edx, %ebx
movl %esi, %eax
movq %rdi, %r14
leaq 0x10(%rsp), %rsi
andq $0x0, (%rsi)
movw $0xdf06, -0x2(%rsi)     # imm = 0xDF06
movl %eax, %edi
callq 0x668e
leaq 0x14(%rsp), %rsi
movl %ebx, %edi
callq 0x668e
leaq 0xe(%rsp), %rsi
movq %r14, %rdi
callq 0x3bac
addq $0x18, %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_flash_erase(WdtDevice*, unsigned int, int)
int wh_w8760_dev_flash_erase(WDT_DEV* pdev, UINT32 address, int size)
{
	int ret = wh_w8760_dev_erase_flash(pdev, address, size);

	if (ret <= 0)
		wh_printf("%s: addr: %x, size: %x\n", __func__, address, size);
	
	return ret;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
movl %edx, %ebx
movl %esi, %ebp
callq 0x40fa
movl %eax, %r14d
testl %eax, %eax
jne 0x4623
leaq 0x63c5(%rip), %rdi      # 0xa9d6
leaq 0x63d6(%rip), %rsi      # 0xa9ee
movl %ebp, %edx
movl %ebx, %ecx
xorl %eax, %eax
callq 0x24bf
movl %r14d, %eax
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/chenhn123[P]wdt_util_src/wdt_ct/w8760_funcs.cpp
// Function: wh_w8760_dev_verify_chunk_by_read_checksum(WdtDevice*, ChunkInfoEx*)
int wh_w8760_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_w8760_dev_set_n_check_device_mode(pdev, W8760_MODE_COMMAND, 0, 0);
	if (!retval)
		return retval;
		
	printf("Calculating checksum...\n");
	
	bin_checksum = misr_for_bytes(0, pChunk->pData, 0, pChunk->chuckInfo.length);

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

	if (bin_checksum != read_checksum) {
		wh_printf("Checksum mismatch!!! Original=0x%x, Flash checksum=0x%x\n", bin_checksum, read_checksum);
		result = 0;
	}
	
	retval = wh_w8760_dev_set_n_check_device_mode(pdev, W8760_MODE_SENSING, 0, 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 $0x90, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x3f5f
testl %eax, %eax
je 0x471e
leaq 0x6132(%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 0x4686
testl %eax, %eax
je 0x471e
movzwl %r15w, %esi
movl 0x4(%rsp), %edx
cmpl %esi, %edx
jne 0x46fa
pushq $0x1
popq %rbp
jmp 0x470a
leaq 0x627e(%rip), %rdi      # 0xa97f
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x24bf
pushq $0x1
popq %rsi
movq %rbx, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x3f5f
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/w8760_funcs.cpp
// Function: wh_w8760_dev_get_device_data(WdtDevice*, unsigned char, int, unsigned char*, int)
int wh_w8760_dev_get_device_data(WDT_DEV* pdev, BYTE type, int offset, BYTE *buf, int size)
{
	BYTE cmd[] = { (BYTE) W8760_COMMAND9, type, (BYTE) offset, (BYTE) size };

	if (type != W8760_GET_DEVICE_INFO && type != W8760_GET_DEVICE_STATUS)
		return 0;

	return wh_w8760_dev_command_read(pdev, cmd, sizeof(cmd), buf, 0,  size);
}

// Assembly:
pushq %rax
movl %r8d, %r9d
movb $0x6, 0x4(%rsp)
movb %sil, 0x5(%rsp)
movb %dl, 0x6(%rsp)
movb %r9b, 0x7(%rsp)
addb $0x36, %sil
xorl %eax, %eax
cmpb $-0x2, %sil
jb 0x4767
leaq 0x4(%rsp), %rsi
xorl %r8d, %r8d
callq 0x3c5a
popq %rcx
retq
// File: /workspace/github_cpp_makefile_star2_O2/chenhn123[P]wdt_util_src/wdt_ct/w8760_funcs.cpp
// Function: wh_w8760_prepare_data(WdtDevice*, BoardInfo*)
int wh_w8760_prepare_data(WDT_DEV* pdev, BOARD_INFO* p_out_board_info)
{
	if (!pdev || !p_out_board_info)
		return 0;

	W8760_PCT_DATA	pct_data;

	/* initialize the basic function for handling the following operations */
	wh_w8760_dev_set_basic_op(pdev);

	if (!wh_w8760_dev_identify_platform(pdev, p_out_board_info))  {
		wh_printf("Can't get platform identify!\n");
		return 0;
	}
	
	if (p_out_board_info->dev_type & FW_WDT8760_2_ISP)
		return 1;

	if (wh_w8760_dev_get_context(pdev, &pct_data)) {
		/* set the default values */
		p_out_board_info->sys_param.Phy_Frmbuf_W= pct_data.n_cs;
		p_out_board_info->sys_param.Phy_X0= pct_data.x1;
		p_out_board_info->sys_param.Phy_X1= pct_data.xn;

		p_out_board_info->sys_param.Phy_Frmbuf_H= pct_data.n_cd;
		p_out_board_info->sys_param.Phy_Y0= pct_data.y1;
		p_out_board_info->sys_param.Phy_Y1= pct_data.yn;
		
		p_out_board_info->sys_param.xmls_id1 = 0;
		p_out_board_info->sys_param.xmls_id2 = 0;

		return 1;
	}

	return 1;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x10, %rsp
testq %rdi, %rdi
sete %al
testq %rsi, %rsi
sete %cl
xorl %ebx, %ebx
orb %al, %cl
jne 0x4858
movq %rsi, %r14
movq %rdi, %r15
callq 0x4059
testl %eax, %eax
je 0x4848
pushq $0x1
popq %rbx
testb $0x50, 0x1(%r14)
jne 0x4858
leaq 0x4(%rsp), %rsi
movq %r15, %rdi
callq 0x4788
testl %eax, %eax
je 0x4858
movzbl 0x6(%rsp), %eax
movw %ax, 0x24(%r14)
movzbl 0x5(%rsp), %eax
movw %ax, 0x26(%r14)
movd 0x8(%rsp), %xmm0
pxor %xmm1, %xmm1
punpcklbw %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1],xmm0[2],xmm1[2],xmm0[3],xmm1[3],xmm0[4],xmm1[4],xmm0[5],xmm1[5],xmm0[6],xmm1[6],xmm0[7],xmm1[7]
movq %xmm0, 0x28(%r14)
andl $0x0, 0x20(%r14)
jmp 0x4858
leaq 0x6169(%rip), %rdi      # 0xa9b8
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x24bf
movl %ebx, %eax
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
retq
// File: /workspace/github_cpp_makefile_star2_O2/chenhn123[P]wdt_util_src/wdt_ct/w8760_funcs.cpp
// Function: wh_w8762_isp_rerun_recovery(WdtDevice*)
int wh_w8762_isp_rerun_recovery(WDT_DEV *pdev)
{
        wh_printf("It is maybe WDT8762 ISP\n");
        wh_w8760_dev_set_men_address(pdev, 0xA022750A);
        wh_w8760_dev_write_men_halfword(pdev, 0);
        wh_w8760_dev_run_program_from_background(pdev, 0x061000);
        wh_printf("Rerun Recovery fw \n");
        return 1;
}

// Assembly:
pushq %rbx
movq %rdi, %rbx
leaq 0x5e28(%rip), %rdi      # 0xaa23
xorl %eax, %eax
callq 0x24bf
movq %rbx, %rdi
movl $0xa022750a, %esi       # imm = 0xA022750A
callq 0x4041
movq %rbx, %rdi
xorl %esi, %esi
callq 0x4009
movq %rbx, %rdi
movl $0x61000, %esi          # imm = 0x61000
callq 0x3e83
leaq 0x5e0f(%rip), %rdi      # 0xaa3c
xorl %eax, %eax
callq 0x24bf
pushq $0x1
popq %rax
popq %rbx
retq
// File: /workspace/github_cpp_makefile_star2_O2/chenhn123[P]wdt_util_src/wdt_ct/w8760_funcs.cpp
// Function: wh_w8760_isp_rerun_recovery(WdtDevice*)
int wh_w8760_isp_rerun_recovery(WDT_DEV *pdev)
{
        wh_printf("It is maybe WDT8760 ISP\n");
        wh_w8760_dev_run_program_from_background(pdev, 0x061000);
        wh_printf("Rerun Recovery fw \n");
        return 1;
}

// Assembly:
pushq %rbx
movq %rdi, %rbx
leaq 0x5e0c(%rip), %rdi      # 0xaa50
xorl %eax, %eax
callq 0x24bf
movq %rbx, %rdi
movl $0x61000, %esi          # imm = 0x61000
callq 0x3e83
leaq 0x5ddd(%rip), %rdi      # 0xaa3c
xorl %eax, %eax
callq 0x24bf
pushq $0x1
popq %rax
popq %rbx
retq
nop
// File: /workspace/github_cpp_makefile_star2_O2/chenhn123[P]wdt_util_src/wdt_ct/w8790_funcs.cpp
// Function: wh_w8790_dev_set_feature(WdtDevice*, unsigned char*, unsigned int)
int wh_w8790_dev_set_feature(WDT_DEV* pdev, BYTE* buf, UINT32 buf_size)
{
	if (!pdev)
		return 0;

	if (buf[0] == W8790_COMMAND9)
		buf_size = 10;
	else if (buf[0] == W8790_COMMAND63 || buf[0] == W8790_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 0x4cba
movzbl (%rsi), %eax
cmpl $0x6, %eax
je 0x4c98
cmpl $0xb, %eax
je 0x4c94
cmpl $0x7, %eax
jne 0x4ca5
pushq $0x40
jmp 0x4c9a
pushq $0xa
popq %rdx
cmpl $0x2, (%rdi)
jne 0x4cba
jmp 0x8e72
pushq %rax
leaq 0x5c1f(%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/w8790_funcs.cpp
// Function: wh_w8790_dev_get_feature(WdtDevice*, unsigned char*, unsigned int)
int wh_w8790_dev_get_feature(WDT_DEV* pdev, BYTE* buf, UINT32 buf_size)
{
	if (!pdev)
		return 0;

	if (buf[0] == W8790_COMMAND9)
		buf_size = 10;
	else if (buf[0] == W8790_COMMAND63 || buf[0] == W8790_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_get_feature(pdev, buf, buf_size);




	return 0;
}

// Assembly:
testq %rdi, %rdi
je 0x4cfa
movzbl (%rsi), %eax
cmpl $0x6, %eax
je 0x4cd8
cmpl $0xb, %eax
je 0x4cd4
cmpl $0x7, %eax
jne 0x4ce5
pushq $0x40
jmp 0x4cda
pushq $0xa
popq %rdx
cmpl $0x2, (%rdi)
jne 0x4cfa
jmp 0x8a10
pushq %rax
leaq 0x5bdf(%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/w8790_funcs.cpp
// Function: wh_w8790_parse_device_info(DevInfo_8790_t*, unsigned char*)
int wh_w8790_parse_device_info(W8790_DEV_INFO* report_feature_devinfo, BYTE* buf)
{
	if (!report_feature_devinfo || !buf)
		return 0;

	report_feature_devinfo->firmware_version = get_unaligned_le32(&buf[1]);
	report_feature_devinfo->hardware_version = get_unaligned_le32(&buf[5]);
	report_feature_devinfo->serial_number = get_unaligned_le32(&buf[9]);
	report_feature_devinfo->max_touches = buf[13];
	report_feature_devinfo->firmware_revision_ext = buf[14];
	report_feature_devinfo->partition = buf[15];
	report_feature_devinfo->partition_format_revision = buf[16];


	memcpy(report_feature_devinfo->part_number, &buf[17], 16);
	memcpy(report_feature_devinfo->rom_signature, &buf[33], 8);
	memcpy(report_feature_devinfo->program_name_fourcc, &buf[41], 4);
	memcpy(report_feature_devinfo->tracking_id, &buf[45], 8);

	return 1;
}

// Assembly:
testq %rdi, %rdi
sete %cl
testq %rsi, %rsi
sete %dl
xorl %eax, %eax
orb %cl, %dl
jne 0x4db4
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)
movb 0xf(%r14), %al
movb %al, 0xe(%rbx)
movb 0x10(%r14), %al
movb %al, 0xf(%rbx)
movups 0x11(%r14), %xmm0
movups %xmm0, 0x10(%rbx)
movq 0x21(%r14), %rax
movq %rax, 0x20(%rbx)
movl 0x29(%r14), %eax
movl %eax, 0x28(%rbx)
movq 0x2d(%r14), %rax
movq %rax, 0x2c(%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/w8790_funcs.cpp
// Function: wh_w8790_dev_identify_platform(WdtDevice*)
int wh_w8790_dev_identify_platform(WDT_DEV* pdev)
{
	// identify chip by reading its ROM.
	if (!pdev )
		return 0;

	if (memcmp(W8790_RomSignatureVerA, pdev->board_info.dev_info.w8790_feature_devinfo.rom_signature, 8) == 0) {
		if (pdev->pparam->argus & OPTION_INFO)		
			printf("WDT8790_VerA\n");

		return 1;
	}
	if (memcmp(W8790_RomSignatureVerB, pdev->board_info.dev_info.w8790_feature_devinfo.rom_signature, 8) == 0) {
                if (pdev->pparam->argus & OPTION_INFO)	
			printf("WDT8790_VerB\n");
		return 1;
	}


	return 0;
}

// Assembly:
xorl %eax, %eax
testq %rdi, %rdi
je 0x4e13
pushq %rbx
movq 0xc5a4(%rip), %rcx      # 0x11368
pushq $0x1
popq %rbx
cmpq 0x218(%rdi), %rcx
je 0x4df8
leaq 0x218(%rdi), %rcx
movq 0xc592(%rip), %rdx      # 0x11370
cmpq (%rcx), %rdx
jne 0x4e12
movq 0x280(%rdi), %rax
testb $0x8, (%rax)
je 0x4e10
leaq 0x5faf(%rip), %rdi      # 0xada5
jmp 0x4e0b
movq 0x280(%rdi), %rax
testb $0x8, (%rax)
je 0x4e10
leaq 0x5fa7(%rip), %rdi      # 0xadb2
callq 0x2270
movl %ebx, %eax
popq %rbx
retq
// File: /workspace/github_cpp_makefile_star2_O2/chenhn123[P]wdt_util_src/wdt_ct/w8790_funcs.cpp
// Function: wh_w8790_dev_get_context(WdtDevice*, ParameterCoordinatePage_8790_t*)
int wh_w8790_dev_get_context(WDT_DEV* pdev, W8790_PCT* pPct)
{
	BYTE  buf[64] = { 0 };

	if (!pdev || !pPct)
		return 0;

	if (wh_w8790_dev_read_parameter_page(pdev, buf, 1) <= 0)
		return 0;

	memcpy(pPct, &buf[0], sizeof(W8790_PCT));

	return 1;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
subq $0x40, %rsp
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
movaps %xmm0, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
movaps %xmm0, (%rsp)
testq %rdi, %rdi
sete %al
testq %rsi, %rsi
sete %cl
xorl %ebp, %ebp
orb %al, %cl
jne 0x4e6d
movq %rsi, %rbx
movq %rsp, %rsi
pushq $0x1
popq %r14
movl %r14d, %edx
callq 0x4e78
testl %eax, %eax
je 0x4e6d
movzwl 0x8(%rsp), %eax
movw %ax, 0x8(%rbx)
movq (%rsp), %rax
movq %rax, (%rbx)
movl %r14d, %ebp
movl %ebp, %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/w8790_funcs.cpp
// Function: wh_w8790_dev_command_read(WdtDevice*, unsigned char*, int, unsigned char*, int, int)
int wh_w8790_dev_command_read(WDT_DEV* pdev, BYTE* cmd, int cmd_size, BYTE* data, int start, int size)
{
	if (wh_w8790_dev_command_write(pdev, cmd, 0, cmd_size) > 0) {

		BYTE	buf[64] = { 0 };
		if (size > 9)
			buf[0] = W8790_COMMAND63;
		else
			buf[0] = W8790_COMMAND9;

		if (wh_w8790_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, %ebp
movl %r8d, %r15d
movq %rcx, %rbx
movq %rdi, %r12
xorl %r14d, %r14d
xorl %edx, %edx
callq 0x4d06
testl %eax, %eax
je 0x4f10
xorps %xmm0, %xmm0
movq %rsp, %rsi
movaps %xmm0, (%rsi)
movaps %xmm0, 0x30(%rsi)
movaps %xmm0, 0x20(%rsi)
movaps %xmm0, 0x10(%rsi)
cmpl $0xa, %ebp
setge %al
orb $0x6, %al
movb %al, (%rsi)
movq %r12, %rdi
callq 0x4cbd
testl %eax, %eax
jle 0x4f10
movslq %r15d, %rax
addq %rax, %rbx
leaq 0x1(%rsp), %rsi
movslq %ebp, %rdx
movq %rbx, %rdi
callq 0x2150
pushq $0x1
popq %r14
movl %r14d, %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/w8790_funcs.cpp
// Function: wh_w8790_dev_read_array(WdtDevice*, int, unsigned char*, int, int, int)
int wh_w8790_dev_read_array(WDT_DEV* pdev, int cmd_id, BYTE* buffer, int start, int item_size, int item_count)
{
	int max_read_batch = W8790_USB_MAX_PAYLOAD_SIZE / item_size;
	int i = start;

	while (item_count >= max_read_batch) {
		if (wh_w8790_dev_read_items(pdev, cmd_id, buffer, i, item_size, max_read_batch) <= 0)
			return 0;
		i += max_read_batch * item_size;
		item_count -= max_read_batch;
	}
	if (item_count > 0)
		return wh_w8790_dev_read_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 $0x3f
popq %rax
xorl %edx, %edx
idivl %r8d
movl %eax, %r13d
movl %eax, %r14d
imull %r8d, %r14d
movl %r9d, %r15d
subl %r13d, %r15d
jl 0x4fb3
movq %r12, %rdi
movl 0xc(%rsp), %esi
movq 0x10(%rsp), %rdx
movl %ebp, %ecx
movl %ebx, %r8d
movl %r13d, %r9d
callq 0x4f20
testl %eax, %eax
je 0x4fdc
addl %r14d, %ebp
movl %r15d, %r9d
jmp 0x4f89
testl %r9d, %r9d
jle 0x4fe0
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 0x4f20
xorl %eax, %eax
jmp 0x4fe3
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/w8790_funcs.cpp
// Function: wh_w8790_dev_get_device_mode(WdtDevice*)
int wh_w8790_dev_get_device_mode(WDT_DEV* pdev)
{
	BYTE	status[4] = { 0 };
	if (!pdev)
		return 0;

	if (wh_w8790_dev_get_device_status(pdev, status, 8, 1))
		return status[0];

	return 0;
}

// Assembly:
pushq %rbx
subq $0x10, %rsp
andl $0x0, 0xc(%rsp)
xorl %ebx, %ebx
testq %rdi, %rdi
je 0x5032
leaq 0xc(%rsp), %rsi
pushq $0x8
popq %rdx
pushq $0x1
popq %rcx
callq 0x503a
testl %eax, %eax
je 0x5032
movzbl 0xc(%rsp), %ebx
movl %ebx, %eax
addq $0x10, %rsp
popq %rbx
retq
// File: /workspace/github_cpp_makefile_star2_O2/chenhn123[P]wdt_util_src/wdt_ct/w8790_funcs.cpp
// Function: wh_w8790_dev_get_device_status(WdtDevice*, unsigned char*, int, int)
int wh_w8790_dev_get_device_status(WDT_DEV* pdev, BYTE* buf, int offset, int size)
{
	BYTE cmd[10] = { 0 };
	cmd[0] = (BYTE)W8790_COMMAND9;// , type, (BYTE)offset, (BYTE)size
	cmd[1] = W8790_GET_DEVICE_STATUS;
	cmd[2] = (BYTE)offset;
	cmd[3] = (BYTE)size;

	return wh_w8790_dev_command_read(pdev, cmd, sizeof(cmd), buf, 0, size);

}

// Assembly:
subq $0x18, %rsp
movl %ecx, %r9d
leaq 0xe(%rsp), %rax
andw $0x0, 0x8(%rax)
movq %rsi, %rcx
andl $0x0, 0x4(%rax)
movw $0xc906, (%rax)         # imm = 0xC906
movb %dl, 0x2(%rax)
movb %r9b, 0x3(%rax)
movq %rax, %rsi
xorl %r8d, %r8d
callq 0x4ea5
addq $0x18, %rsp
retq
// File: /workspace/github_cpp_makefile_star2_O2/chenhn123[P]wdt_util_src/wdt_ct/w8790_funcs.cpp
// Function: wh_w8790_dev_set_flash_address(WdtDevice*, unsigned int)
int wh_w8790_dev_set_flash_address(WDT_DEV* pdev, UINT32 address)
{
	BYTE cmd[10] = { 0 };

	cmd[0] = W8790_COMMAND9;
	cmd[1] = W8790_SET_FLASH_ADDRESS;
	put_unaligned_le32(address, &cmd[2]);

	return wh_w8790_dev_command_write(pdev, cmd, 0, sizeof(cmd));

}

// Assembly:
pushq %rbx
subq $0x10, %rsp
movl %esi, %eax
movq %rdi, %rbx
leaq 0x8(%rsp), %rsi
andq $0x0, (%rsi)
movw $0xd006, -0x2(%rsi)     # imm = 0xD006
movl %eax, %edi
callq 0x668e
leaq 0x6(%rsp), %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x4d06
addq $0x10, %rsp
popq %rbx
retq
// File: /workspace/github_cpp_makefile_star2_O2/chenhn123[P]wdt_util_src/wdt_ct/w8790_funcs.cpp
// Function: wh_w8790_dev_get_section_addr_map(WdtDevice*, FlashMapAddr_8790_t*)
int wh_w8790_dev_get_section_addr_map(WDT_DEV* pdev, W8790_FLASH_MAP* psec_map)
{
	UINT32 firmware_map_table_addr = 0x000010;
	W8790_FLASH_SECTION_HEADER	sec_header;

	if (!psec_map)
		return 0;

	if (wh_w8790_dev_set_flash_address(pdev, firmware_map_table_addr) <= 0)
		return 0;

	if (wh_w8790_dev_read_flash(pdev, (BYTE*)&sec_header, sizeof(W8790_FLASH_SECTION_HEADER)) <= 0)
		return 0;

	if (wh_w8790_section_header_valid(&sec_header) && sec_header.PayloadSize >= 32 && sec_header.PayloadSize < 1024) {
		if (wh_w8790_dev_set_flash_address(pdev, firmware_map_table_addr + sizeof(W8790_FLASH_SECTION_HEADER)) <= 0)
			return 0;
		size_t padata_buffer = sec_header.PayloadSize + 16;
		BYTE* pdata = (BYTE*)malloc(padata_buffer);
		if (!pdata) {
			printf("pdata malloc fail \n");
			return 0;
		}
		int ret = wh_w8790_dev_read_flash(pdev, (BYTE*)pdata, sec_header.PayloadSize);


		if (ret > 0) {
			psec_map->ParameterMap = get_unaligned_le32(&pdata[0]);
			psec_map->MainLoader = get_unaligned_le32(&pdata[4]);
			psec_map->ParameterPrimary = get_unaligned_le32(&pdata[8]);
			psec_map->ParameterExtended = get_unaligned_le32(&pdata[12]);
			psec_map->ParameterPrivate = get_unaligned_le32(&pdata[16]);

		}
		free(pdata);
		return ret;
	}
	return 0;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x10, %rsp
xorl %ebx, %ebx
testq %rsi, %rsi
je 0x51ca
movq %rsi, %r14
movq %rdi, %r15
pushq $0x10
popq %rsi
callq 0x506e
testl %eax, %eax
je 0x51ca
movq %rsp, %rsi
pushq $0x10
popq %rdx
movq %r15, %rdi
callq 0x4ff2
testl %eax, %eax
je 0x51ca
movq %rsp, %rdi
callq 0x50a3
testl %eax, %eax
je 0x51ca
movl 0x4(%rsp), %eax
addl $-0x20, %eax
cmpl $0x3df, %eax            # imm = 0x3DF
ja 0x51ca
pushq $0x20
popq %rsi
movq %r15, %rdi
callq 0x506e
testl %eax, %eax
je 0x51ca
movl 0x4(%rsp), %r13d
leal 0x10(%r13), %edi
callq 0x21f0
testq %rax, %rax
je 0x51be
movq %rax, %r12
movq %r15, %rdi
movq %rax, %rsi
movl %r13d, %edx
callq 0x4ff2
movl %eax, %ebx
testl %eax, %eax
je 0x51b4
movq %r12, %rdi
callq 0x6687
movl %eax, (%r14)
leaq 0x4(%r12), %rdi
callq 0x6687
movl %eax, 0x4(%r14)
leaq 0x8(%r12), %rdi
callq 0x6687
movl %eax, 0x8(%r14)
leaq 0xc(%r12), %rdi
callq 0x6687
movl %eax, 0xc(%r14)
movq %r12, %rdi
addq $0x10, %rdi
callq 0x6687
movl %eax, 0x10(%r14)
movq %r12, %rdi
callq 0x21e0
jmp 0x51ca
leaq 0x5bfa(%rip), %rdi      # 0xadbf
callq 0x2270
movl %ebx, %eax
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
// File: /workspace/github_cpp_makefile_star2_O2/chenhn123[P]wdt_util_src/wdt_ct/w8790_funcs.cpp
// Function: wh_w8790_dev_set_n_check_device_mode(WdtDevice*, unsigned char, int, int)
int wh_w8790_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, we don't check mode
	if (pdev->board_info.dev_type & FW_MAYBE_ISP)
		return 1;

	if (timeout_ms)
		polling_timeout_ms = timeout_ms;
	if (intv_ms)
		polling_intv_ms = intv_ms;

	do {
		wh_w8790_dev_set_device_mode(pdev, mode);

		if (wh_w8790_dev_get_device_mode(pdev) == mode)
			return 1;

		usleep(polling_intv_ms*1000);
		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
pushq $0x1
popq %rbx
testb $0x1, 0x188(%rdi)
jne 0x523c
movq %rdi, %r14
testl %edx, %edx
pushq $0x64
popq %r12
cmovnel %edx, %r12d
testl %ecx, %ecx
pushq $0x5
popq %r13
cmovnel %ecx, %r13d
imull $0x3e8, %r13d, %ebp     # imm = 0x3E8
movzbl %sil, %r15d
movq %r14, %rdi
movl %r15d, %esi
callq 0x524d
movq %r14, %rdi
callq 0x5008
cmpl %r15d, %eax
je 0x523c
movl %ebp, %edi
callq 0x2230
subl %r13d, %r12d
testl %r12d, %r12d
jg 0x5213
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_O2/chenhn123[P]wdt_util_src/wdt_ct/w8790_funcs.cpp
// Function: wh_w8790_dev_set_device_mode(WdtDevice*, unsigned char)
int wh_w8790_dev_set_device_mode(WDT_DEV* pdev, BYTE mode)
{
	BYTE cmd[10] = { 0 };

	cmd[0] = W8790_COMMAND9;
	cmd[1] = W8790_SET_DEVICE_MODE;
	cmd[2] = mode;

	return wh_w8790_dev_command_write(pdev, cmd, 0, 3);
}

// Assembly:
subq $0x18, %rsp
leaq 0xe(%rsp), %rax
andl $0x0, 0x6(%rax)
andl $0x0, 0x3(%rax)
movw $0xca06, (%rax)         # imm = 0xCA06
movb %sil, 0x2(%rax)
movq %rax, %rsi
xorl %edx, %edx
callq 0x4d06
addq $0x18, %rsp
retq
// File: /workspace/github_cpp_makefile_star2_O2/chenhn123[P]wdt_util_src/wdt_ct/w8790_funcs.cpp
// Function: wh_w8790_dev_read_parameter_table_info(WdtDevice*, ParameterTableInfo_8790_t*)
int wh_w8790_dev_read_parameter_table_info(WDT_DEV* pdev, W8790_PARAMETER_INFO* p_out_parameter_info)
{
	BYTE cmd[10] = { 0 };

	cmd[0] = W8790_COMMAND9;
	cmd[1] = W8790_READ_PARAMETER_TABLE_INFO;
	BYTE buf[64];
	

	if (wh_w8790_dev_command_read(pdev, cmd, sizeof(cmd), buf, 0, sizeof(W8790_PARAMETER_INFO))) {
		p_out_parameter_info->PMapID = get_unaligned_le16(&buf[0]);
		p_out_parameter_info->PrimarySector = get_unaligned_le16(&buf[2]);
		p_out_parameter_info->PrimarySize = get_unaligned_le16(&buf[4]);
		p_out_parameter_info->ExtendedSector = get_unaligned_le16(&buf[6]);
		p_out_parameter_info->ExtendedSize = get_unaligned_le16(&buf[8]);
		return 1;
	}
	
	
	return 0;

}

// Assembly:
pushq %rbp
pushq %rbx
subq $0x58, %rsp
movq %rsi, %rbx
leaq 0x6(%rsp), %rsi
andq $0x0, 0x2(%rsi)
movw $0xcd06, (%rsi)         # imm = 0xCD06
leaq 0x10(%rsp), %rcx
xorl %ebp, %ebp
pushq $0xa
popq %r9
xorl %r8d, %r8d
callq 0x4ea5
testl %eax, %eax
je 0x52ed
leaq 0x10(%rsp), %rdi
callq 0x6683
movw %ax, (%rbx)
leaq 0x12(%rsp), %rdi
callq 0x6683
movw %ax, 0x2(%rbx)
leaq 0x14(%rsp), %rdi
callq 0x6683
movw %ax, 0x4(%rbx)
leaq 0x16(%rsp), %rdi
callq 0x6683
movw %ax, 0x6(%rbx)
leaq 0x18(%rsp), %rdi
callq 0x6683
movw %ax, 0x8(%rbx)
pushq $0x1
popq %rbp
movl %ebp, %eax
addq $0x58, %rsp
popq %rbx
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/chenhn123[P]wdt_util_src/wdt_ct/w8790_funcs.cpp
// Function: wh_w8790_dev_one_block_fast_write(WdtDevice*, unsigned char*, int, int)
int wh_w8790_dev_one_block_fast_write(WDT_DEV* pdev, BYTE* data, int start, int size)
{
	BYTE cmd[64] = { 0 };
	int write_size = size;

	if (size > W8790_USB_MAX_PAYLOAD_SIZE)
		write_size = W8790_USB_MAX_PAYLOAD_SIZE;

	cmd[0] = W8790_BLOCK63;
	memcpy(&cmd[1], &data[start], write_size);

	return wh_w8790_dev_set_feature(pdev, cmd, write_size);
}

// Assembly:
pushq %rbx
subq $0x40, %rsp
movq %rdi, %rbx
xorps %xmm0, %xmm0
leaq 0x1(%rsp), %rdi
movaps %xmm0, -0x1(%rdi)
movaps %xmm0, 0x2f(%rdi)
movaps %xmm0, 0x1f(%rdi)
movaps %xmm0, 0xf(%rdi)
cmpl $0x3f, %ecx
pushq $0x3f
popq %rax
cmovll %ecx, %eax
movb $0xb, -0x1(%rdi)
movslq %edx, %rcx
addq %rcx, %rsi
movslq %eax, %rdx
callq 0x2150
movq %rsp, %rsi
movq %rbx, %rdi
callq 0x4c7d
addq $0x40, %rsp
popq %rbx
retq
// File: /workspace/github_cpp_makefile_star2_O2/chenhn123[P]wdt_util_src/wdt_ct/w8790_funcs.cpp
// Function: wh_w8790_dev_block_fast_write(WdtDevice*, unsigned char*, int, int)
int wh_w8790_dev_block_fast_write(WDT_DEV* pdev, BYTE* data, int start, int size)
{
	int payload_size = W8790_USB_MAX_PAYLOAD_SIZE;
	while (size > payload_size) {
		if (wh_w8790_dev_one_block_fast_write(pdev, data, start, payload_size) <= 0)
			return 0;
		start += payload_size;
		size -= payload_size;
	}
	if (size > 0)
		return wh_w8790_dev_one_block_fast_write(pdev, data, start, size);
	return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movl %ecx, %ebx
movl %edx, %ebp
movq %rsi, %r14
movq %rdi, %r15
pushq $0x3f
popq %r12
cmpl $0x40, %ebx
jl 0x5379
movq %r15, %rdi
movq %r14, %rsi
movl %ebp, %edx
movl %r12d, %ecx
callq 0x52f6
testl %eax, %eax
jle 0x5394
addl $0x3f, %ebp
addl $-0x3f, %ebx
jmp 0x5358
testl %ebx, %ebx
jle 0x5398
movq %r15, %rdi
movq %r14, %rsi
movl %ebp, %edx
movl %ebx, %ecx
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x52f6
xorl %eax, %eax
jmp 0x539b
pushq $0x1
popq %rax
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/w8790_funcs.cpp
// Function: wh_w8790_dev_one_block_fast_read(WdtDevice*, unsigned char*, int, int)
int wh_w8790_dev_one_block_fast_read(WDT_DEV* pdev, BYTE* data, int start, int size)
{
	BYTE cmd[64] = { 0 };
	int read_size = size;

	if (size > W8790_USB_MAX_PAYLOAD_SIZE)
		read_size = W8790_USB_MAX_PAYLOAD_SIZE;

	cmd[0] = W8790_BLOCK63;

	if (wh_w8790_dev_get_feature(pdev, cmd, read_size) > 0) {
		memcpy(&data[start], &cmd[1], read_size);
		return 1;
	}

	return 0;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
subq $0x40, %rsp
movl %ecx, %r14d
movl %edx, %ebp
movq %rsi, %rbx
xorps %xmm0, %xmm0
movq %rsp, %rsi
movaps %xmm0, (%rsi)
movaps %xmm0, 0x30(%rsi)
movaps %xmm0, 0x20(%rsi)
movaps %xmm0, 0x10(%rsi)
movb $0xb, (%rsi)
callq 0x4cbd
testl %eax, %eax
jle 0x53fb
cmpl $0x3f, %r14d
pushq $0x3f
popq %rax
cmovll %r14d, %eax
movslq %ebp, %rcx
addq %rcx, %rbx
leaq 0x1(%rsp), %rsi
movslq %eax, %rdx
movq %rbx, %rdi
callq 0x2150
pushq $0x1
popq %rax
jmp 0x53fd
xorl %eax, %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/w8790_funcs.cpp
// Function: wh_w8790_dev_block_fast_read(WdtDevice*, unsigned char*, int, int)
int wh_w8790_dev_block_fast_read(WDT_DEV* pdev, BYTE* data, int start, int size)
{
	int payload_size = W8790_USB_MAX_PAYLOAD_SIZE;

	while (size > payload_size) {
		if (wh_w8790_dev_one_block_fast_read(pdev, data, start, payload_size) <= 0)
			return 0;
		start += payload_size;
		size -= payload_size;
	}

	if (size > 0)
		return wh_w8790_dev_one_block_fast_read(pdev, data, start, size);

	return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movl %ecx, %ebx
movl %edx, %ebp
movq %rsi, %r14
movq %rdi, %r15
pushq $0x3f
popq %r12
cmpl $0x40, %ebx
jl 0x543d
movq %r15, %rdi
movq %r14, %rsi
movl %ebp, %edx
movl %r12d, %ecx
callq 0x53a4
testl %eax, %eax
je 0x5458
addl $0x3f, %ebp
addl $-0x3f, %ebx
jmp 0x541c
testl %ebx, %ebx
jle 0x545c
movq %r15, %rdi
movq %r14, %rsi
movl %ebp, %edx
movl %ebx, %ecx
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x53a4
xorl %eax, %eax
jmp 0x545f
pushq $0x1
popq %rax
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/w8790_funcs.cpp
// Function: wh_w8790_dev_write_items(WdtDevice*, int, unsigned char*, int, int, int)
int wh_w8790_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] = { 0 };

	cmd[0] = W8790_COMMAND9;
	cmd[1] = cmd_id;
	cmd[2] = item_count;
	memcpy(&cmd[3], &buffer[start], size);

	return wh_w8790_dev_command_write(pdev, cmd, 0, size + 3);
}

// Assembly:
pushq %rbx
subq $0x40, %rsp
movq %rdi, %rbx
imull %r9d, %r8d
xorps %xmm0, %xmm0
leaq 0x3(%rsp), %rdi
movaps %xmm0, -0x3(%rdi)
movaps %xmm0, 0x2d(%rdi)
movaps %xmm0, 0x1d(%rdi)
movaps %xmm0, 0xd(%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
xorl %edx, %edx
callq 0x4d06
addq $0x40, %rsp
popq %rbx
retq
// File: /workspace/github_cpp_makefile_star2_O2/chenhn123[P]wdt_util_src/wdt_ct/w8790_funcs.cpp
// Function: wh_w8790_dev_write_array(WdtDevice*, int, unsigned char*, int, int, int)
int wh_w8790_dev_write_array(WDT_DEV* pdev, int cmd_id, BYTE* buffer, int start, int item_size, int item_count)
{
	int max_write_batch = (W8790_USB_MAX_PAYLOAD_SIZE - 2) / item_size;
	int i = start;

	while (item_count >= max_write_batch) {
		if (wh_w8790_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_w8790_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 0x5517
movq %r12, %rdi
movl 0xc(%rsp), %esi
movq 0x10(%rsp), %rdx
movl %ebp, %ecx
movl %ebx, %r8d
movl %r13d, %r9d
callq 0x5468
testl %eax, %eax
je 0x5540
addl %r14d, %ebp
movl %r15d, %r9d
jmp 0x54ed
testl %r9d, %r9d
jle 0x5544
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 0x5468
xorl %eax, %eax
jmp 0x5547
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/w8790_funcs.cpp
// Function: wh_w8790_dev_wait_cmd_end(WdtDevice*, int, int)
int wh_w8790_dev_wait_cmd_end(WDT_DEV* pdev, int timeout_ms, int invt_ms)
{
	int polling_timeout_ms = 5000;
	int polling_intv_ms = 10;
	int status;
	BYTE	status_buf[4] = { 0 };

	unsigned long 	start_tick = get_current_ms();
	unsigned long 	time_period;

	if (timeout_ms)
		polling_timeout_ms = timeout_ms;
	if (invt_ms)
		polling_intv_ms = invt_ms;

	do
	{
		if (wh_w8790_dev_get_device_status(pdev, &status_buf[0], 0, 1) <= 0)
			return 0;

		status = status_buf[0];
		if ((status & W8790_COMMAND_BUSY) == 0) {
			time_period = (get_current_ms() - start_tick);
			if (time_period)
				wh_printf("leave %s : %lums\n", __FUNCTION__, time_period);

			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", __FUNCTION__, polling_timeout_ms * polling_intv_ms);
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %edx, %ebx
movl %esi, %ebp
movq %rdi, %r15
leaq 0xc(%rsp), %rax
andl $0x0, (%rax)
callq 0x2565
movq %rax, 0x10(%rsp)
testl %ebp, %ebp
movl $0x1388, %r14d          # imm = 0x1388
cmovnel %ebp, %r14d
testl %ebx, %ebx
pushq $0xa
popq %r13
cmovnel %ebx, %r13d
movl %r13d, %ebp
imull %r14d, %ebp
movl %r13d, %r12d
imull %r13d, %r12d
xorl %ebx, %ebx
movq %r15, %rdi
leaq 0xc(%rsp), %rsi
xorl %edx, %edx
pushq $0x1
popq %rcx
callq 0x503a
testl %eax, %eax
je 0x5615
testb $0x1, 0xc(%rsp)
je 0x55ee
movl %r13d, %edi
callq 0x2555
subl %r13d, %r14d
subl %r12d, %ebp
testl %r14d, %r14d
jg 0x55a3
leaq 0x5315(%rip), %rdi      # 0xa8ef
leaq 0x558a(%rip), %rsi      # 0xab6b
xorl %ebx, %ebx
movl %ebp, %edx
xorl %eax, %eax
callq 0x24bf
jmp 0x5615
callq 0x2565
subq 0x10(%rsp), %rax
je 0x5612
leaq 0x5558(%rip), %rdi      # 0xab59
leaq 0x5563(%rip), %rsi      # 0xab6b
movq %rax, %rdx
xorl %eax, %eax
callq 0x24bf
pushq $0x1
popq %rbx
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/w8790_funcs.cpp
// Function: wh_w8790_dev_flash_erase_cmd(WdtDevice*, unsigned int, unsigned int)
int wh_w8790_dev_flash_erase_cmd(WDT_DEV* pdev, UINT32 address, UINT32 size)
{
	BYTE cmd[10] = { 0 };

	cmd[0] = W8790_COMMAND9;
	cmd[1] = (BYTE)W8790_ERASE_FLASH;
	cmd[2] = (BYTE)(address >> 12);
	cmd[3] = (BYTE)(((address & 0x0FFF) + size + 4095) >> 12);

	if (wh_w8790_dev_command_write(pdev, cmd, 0, sizeof(cmd)) > 0)
		return wh_w8790_dev_wait_cmd_end(pdev, 6000, 0);

	return 0;
}

// Assembly:
pushq %rbp
pushq %rbx
subq $0x18, %rsp
leaq 0xe(%rsp), %rax
andw $0x0, 0x8(%rax)
andl $0x0, 0x4(%rax)
movq %rdi, %rbx
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)
xorl %ebp, %ebp
movq %rax, %rsi
xorl %edx, %edx
callq 0x4d06
testl %eax, %eax
je 0x56b9
movq %rbx, %rdi
movl $0x1770, %esi           # imm = 0x1770
xorl %edx, %edx
callq 0x5556
movl %eax, %ebp
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %rbp
retq