LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_cpp_makefile_star2_O3/chenhn123[P]wdt_util_src/wdt_ct/w8790_funcs.cpp
// Function: wh_w8790_dev_write_flash_page(WdtDevice*, unsigned char*, int, int)
int wh_w8790_dev_write_flash_page(WDT_DEV* pdev, BYTE* buf, int addr, int size)
{
	int retval = 0;
	unsigned int	write_base;
	unsigned int	write_size;

	write_base = W8790_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_w8790_dev_write_flash(pdev, addr, (BYTE*)buf, 0/*offset*/, write_size);
		if (!retval)
			return retval;
		buf = buf + size_partial;
		addr = addr + size_partial;
	}

	while (size)
	{
		if (size > (int)write_base) {
			write_size = write_base;
			size = size - write_base;
		}
		else {
			write_size = size;
			size = 0;
		}
		retval = wh_w8790_dev_write_flash(pdev, addr, (BYTE*)buf, 0/*offset*/, 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, %r12d
movl %edx, %ebx
movq %rsi, %r14
movq %rdi, %r15
movl %edx, %eax
andl $0xff, %eax
je 0x60b3
movl $0x100, %r13d           # imm = 0x100
subl %eax, %r13d
movl %r13d, %eax
subl %r12d, %eax
movl %r12d, %r8d
cmovll %r13d, %r8d
negl %eax
xorl %ebp, %ebp
cmpl %r13d, %r12d
movl %eax, %r12d
cmovlel %ebp, %r12d
movq %r15, %rdi
movl %ebx, %esi
movq %r14, %rdx
xorl %ecx, %ecx
callq 0x5f21
testl %eax, %eax
je 0x6114
addq %r13, %r14
addl %r13d, %ebx
movl $0x1, %ebp
testl %r12d, %r12d
je 0x6114
movl $0x100, %r13d           # imm = 0x100
xorl %ebp, %ebp
cmpl %r13d, %r12d
movl $0x100, %r8d            # imm = 0x100
cmovll %r12d, %r8d
movq %r15, %rdi
movl %ebx, %esi
movq %r14, %rdx
xorl %ecx, %ecx
callq 0x5f21
testl %eax, %eax
je 0x6112
cmpl $0x101, %r12d           # imm = 0x101
leal -0x100(%r12), %eax
cmovll %ebp, %eax
addq $0x100, %r14            # imm = 0x100
addl $0x100, %ebx            # imm = 0x100
movl %eax, %r12d
testl %eax, %eax
jne 0x60c5
movl $0x1, %ebp
jmp 0x6114
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/w8790_funcs.cpp
// Function: wh_w8790_dev_protect_flash(WdtDevice*, unsigned short)
int wh_w8790_dev_protect_flash(WDT_DEV* pdev, UINT16 protect_mask)
{
	UINT16 mask = protect_mask;

	BYTE cmd[10] = { W8790_COMMAND9, (BYTE)W8790_PROTECT_FLASH, 0, 0, 0, 0 };
	put_unaligned_le16(mask, &cmd[2]);
	put_unaligned_le16((UINT16)~mask, &cmd[4]);

	return wh_w8790_dev_command_write(pdev, cmd, 0, sizeof(cmd));
}

// Assembly:
pushq %r14
pushq %rbx
subq $0x18, %rsp
movl %esi, %ebx
movq %rdi, %r14
leaq 0xa(%rsp), %rsi
movw $0x0, 0x6(%rsi)
movq $0xd406, -0x2(%rsi)     # imm = 0xD406
movl %ebx, %edi
callq 0x6f6e
leaq 0xc(%rsp), %rsi
xorl $0xffff, %ebx           # imm = 0xFFFF
movl %ebx, %edi
callq 0x6f6e
leaq 0x8(%rsp), %rsi
movq %r14, %rdi
callq 0x5179
movl $0x1, %ebx
testl %eax, %eax
jne 0x6183
leaq 0x59ca(%rip), %rdi      # 0xbb44
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x2506
movl %ebx, %eax
addq $0x18, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_cpp_makefile_star2_O3/chenhn123[P]wdt_util_src/wdt_ct/w8790_funcs.cpp
// Function: wh_w8790_dev_flash_get_checksum(WdtDevice*, unsigned int*, unsigned int, int, unsigned int)
int wh_w8790_dev_flash_get_checksum(WDT_DEV* pdev, UINT32* pchksum, UINT32 flash_address,
	int size, UINT32 init_sum)
{
	BYTE cmd[10] = { 0 };
	BYTE buf[2] = { 0 };

	*pchksum = 0;

	cmd[0] = W8790_COMMAND9;
	cmd[1] = (BYTE)W8790_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_w8790_dev_command_write(pdev, cmd, 0, sizeof(cmd)) <= 0)
		return 0;

	if (wh_w8790_dev_wait_cmd_end(pdev, 0, 0) <= 0)
		return 0;

	if (wh_w8790_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
movq %rdi, %r14
leaq 0x6(%rsp), %rsi
movq $0x0, (%rsi)
movw $0x0, 0x2(%rsp)
movl $0x0, (%rbx)
movw $0xd506, -0x2(%rsi)     # imm = 0xD506
movl %edx, %edi
callq 0x6f72
leaq 0x9(%rsp), %rsi
movl %r15d, %edi
callq 0x6f72
leaq 0xc(%rsp), %rsi
movzwl %bp, %edi
callq 0x6f6e
leaq 0x4(%rsp), %rsi
movq %r14, %rdi
callq 0x5179
testl %eax, %eax
je 0x624c
xorl %ebp, %ebp
movq %r14, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x5caa
testl %eax, %eax
je 0x625c
leaq 0xe(%rsp), %rsi
movw $0xc706, (%rsi)         # imm = 0xC706
movb $0x2, 0x2(%rsi)
xorl %ebp, %ebp
movl %ebp, 0x3(%rsi)
movl %ebp, 0x6(%rsi)
leaq 0x2(%rsp), %rcx
movq %r14, %rdi
xorl %r8d, %r8d
movl $0x2, %r9d
callq 0x53d0
testl %eax, %eax
je 0x625c
leaq 0x2(%rsp), %rdi
callq 0x6f67
movzwl %ax, %eax
movl %eax, (%rbx)
movl $0x1, %ebp
jmp 0x625c
leaq 0x58f1(%rip), %rdi      # 0xbb44
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x2506
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O3/chenhn123[P]wdt_util_src/wdt_ct/w8790_funcs.cpp
// Function: wh_w8790_dev_set_block_access(WdtDevice*, unsigned char, unsigned int, unsigned int*)
int wh_w8790_dev_set_block_access(WDT_DEV* pdev, BYTE type, UINT32 offset, UINT32* pblk_size)
{
	BYTE response[4] = { 0 };
	BYTE cmd[10] = { 0 };
	int block_size = 0;

	*pblk_size = 0;

	cmd[0] = W8790_COMMAND9;
	cmd[1] = (BYTE)W8790_SET_BLOCK_ACCESS;
	cmd[2] = type;
	cmd[3] = (BYTE)(offset >> 0);
	cmd[4] = (BYTE)(offset >> 8);
	cmd[5] = (BYTE)(offset >> 16);

	if (wh_w8790_dev_command_read(pdev, cmd, sizeof(cmd), response, 0, 4) <= 0)
	{
		wh_printf("%s: Failed !\n", __FUNCTION__);
		return 0;
	}
		

	block_size = response[1] | (response[2] << 8) | (response[3] << 16);

	if (response[0] == (BYTE)type && block_size != 0x00FFFFFF)
		*pblk_size = block_size;

	return 1;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
subq $0x10, %rsp
movq %rcx, %r14
movl %esi, %ebp
xorl %ebx, %ebx
movq %rsp, %rcx
movl %ebx, (%rcx)
leaq 0x6(%rsp), %rsi
movl %ebx, 0x6(%rsi)
movl %ebx, (%r14)
movw $0xe006, (%rsi)         # imm = 0xE006
movb %bpl, 0x2(%rsi)
movb %dl, 0x3(%rsi)
movb %dh, 0xa(%rsp)
shrl $0x10, %edx
movb %dl, 0x5(%rsi)
xorl %r8d, %r8d
movl $0x4, %r9d
callq 0x53d0
testl %eax, %eax
je 0x62d6
movl $0x1, %ebx
cmpb %bpl, (%rsp)
jne 0x62eb
movzwl 0x1(%rsp), %ecx
movzbl 0x3(%rsp), %eax
shll $0x10, %eax
orl %ecx, %eax
cmpl $0xffffff, %eax         # imm = 0xFFFFFF
je 0x62eb
movl %eax, (%r14)
jmp 0x62eb
leaq 0x58dd(%rip), %rdi      # 0xbbba
leaq 0x58e4(%rip), %rsi      # 0xbbc8
xorl %eax, %eax
callq 0x2506
movl %ebx, %eax
addq $0x10, %rsp
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O3/chenhn123[P]wdt_util_src/wdt_ct/w8790_funcs.cpp
// Function: wh_w8790_dev_block_checksum(WdtDevice*, unsigned int*, unsigned int, unsigned int)
int wh_w8790_dev_block_checksum(WDT_DEV* pdev, UINT32* pchksum, UINT32 size, UINT32 init_value)
{
	BYTE cmd[10] = { 0 };
	BYTE buf[8] = { 0 };

	cmd[0] = W8790_COMMAND9;
	cmd[1] = W8790_BLOCK_CHECKSUM;
	put_unaligned_le32(size, &cmd[2]);
	put_unaligned_le16(init_value, &cmd[5]);

	if (wh_w8790_dev_command_write(pdev, cmd, 0, sizeof(cmd)) <= 0)
		return 0;

	if (wh_w8790_dev_wait_cmd_end(pdev, 0, 0) <= 0)
		return 0;

	if (wh_w8790_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 $0x28, %rsp
movl %ecx, %ebp
movq %rsi, %rbx
movq %rdi, %r15
leaq 0x16(%rsp), %rsi
xorl %r14d, %r14d
movq %r14, (%rsi)
movq %r14, 0x8(%rsp)
movw $0xe306, -0x2(%rsi)     # imm = 0xE306
movl %edx, %edi
callq 0x6f72
leaq 0x19(%rsp), %rsi
movzwl %bp, %edi
callq 0x6f6e
leaq 0x14(%rsp), %rsi
movq %r15, %rdi
callq 0x5179
testl %eax, %eax
je 0x63a7
movq %r15, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x5caa
testl %eax, %eax
je 0x63b8
leaq 0x1e(%rsp), %rsi
movw $0xc706, (%rsi)         # imm = 0xC706
movb $0x2, 0x2(%rsi)
xorl %r14d, %r14d
movl %r14d, 0x3(%rsi)
movl %r14d, 0x6(%rsi)
leaq 0x8(%rsp), %rcx
movq %r15, %rdi
xorl %r8d, %r8d
movl $0x2, %r9d
callq 0x53d0
testl %eax, %eax
je 0x63b8
leaq 0x8(%rsp), %rdi
callq 0x6f67
movzwl %ax, %eax
movl %eax, (%rbx)
movl $0x1, %r14d
jmp 0x63b8
leaq 0x5796(%rip), %rdi      # 0xbb44
xorl %r14d, %r14d
xorl %eax, %eax
callq 0x2506
movl %r14d, %eax
addq $0x28, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O3/chenhn123[P]wdt_util_src/wdt_ct/w8790_funcs.cpp
// Function: wh_w8790_dev_flash_read_data(WdtDevice*, unsigned char*, unsigned int, int)
int wh_w8790_dev_flash_read_data(WDT_DEV* pdev, BYTE* data, UINT32 address, int length)
{
	if (!pdev || !data)
		return 0;

	// address and length should be align to 4
	if ((address & 0x3) != 0 || (length & 0x3) != 0)
		return 0;


	if (!wh_w8790_dev_set_flash_address(pdev, address))
		return 0;

	return wh_w8790_dev_read_flash(pdev, data, length);
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movl %ecx, %ebx
testq %rdi, %rdi
sete %al
testq %rsi, %rsi
sete %cl
orb %al, %cl
jne 0x63e5
movl %ebx, %eax
orl %edx, %eax
testb $0x3, %al
je 0x63ed
xorl %eax, %eax
popq %rbx
popq %r14
popq %r15
retq
movq %rsi, %r14
movq %rdi, %r15
movl %edx, %esi
callq 0x5604
testl %eax, %eax
je 0x63e5
movq %r15, %rdi
movl $0xd1, %esi
movq %r14, %rdx
xorl %ecx, %ecx
movl $0x1, %r8d
movl %ebx, %r9d
popq %rbx
popq %r14
popq %r15
jmp 0x548d
// File: /workspace/github_cpp_makefile_star2_O3/chenhn123[P]wdt_util_src/wdt_ct/w8790_funcs.cpp
// Function: w8790_dev_flash_write_4k(WdtDevice*, unsigned char*, unsigned int, int)
int w8790_dev_flash_write_4k(WDT_DEV* pdev, BYTE* data, UINT32 address, int size) {
	int retval = 0;
	int page_size;
	int retry_count = 0;
	int start_addr = address;
	UINT32 calc_checksum, read_checksum;

	BYTE* pdata = data;


	while (size) {
		if (size > (int)WDT_PAGE_SIZE) {
			page_size = WDT_PAGE_SIZE;
			size = size - WDT_PAGE_SIZE;
		} else {

			page_size = size;
			size = 0;
		}

		for (retry_count = 0; retry_count < RETRY_COUNT; retry_count++) {

			if(retry_count > 0)
				wh_w8790_dev_send_commands(pdev, WH_CMD_FLASH_ERASE4K, start_addr);


			retval = wh_w8790_dev_write_flash_page(pdev, pdata, start_addr, page_size);
			if (!retval)
				continue;

			calc_checksum = misr_for_bytes(0, pdata, 0, page_size);

			retval = wh_w8790_dev_flash_get_checksum(pdev, &read_checksum, start_addr, page_size, 0);
			if (read_checksum == calc_checksum)
				break;
			else
				printf("checksum failed (%d): %d <> %d\n", retry_count, read_checksum, calc_checksum);

		}


		if (retry_count == RETRY_COUNT) {
			printf("***** retry failed *****\n");
			break;
		}
		start_addr = start_addr + page_size;
		pdata = pdata + page_size;
	}

	if (retry_count == RETRY_COUNT) {
		printf("stop 4k chunk program : fail \n");
		return 0;
	}
	return 1;
}

// Assembly:
movl $0x1, %eax
testl %ecx, %ecx
je 0x6528
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %edx, %ebp
movq %rsi, %r14
movq %rdi, %r15
movl $0x1000, %eax           # imm = 0x1000
leal -0x1000(%rcx), %edx
movl %edx, 0x8(%rsp)
cmpl %eax, %ecx
movl $0x1000, %r12d          # imm = 0x1000
movq %rcx, 0x10(%rsp)
cmovll %ecx, %r12d
xorl %ebx, %ebx
testl %ebx, %ebx
je 0x6476
movq %r15, %rdi
movl %ebp, %esi
movl $0x1000, %edx           # imm = 0x1000
callq 0x66b4
movq %r15, %rdi
movq %r14, %rsi
movl %ebp, %edx
movl %r12d, %ecx
callq 0x6057
testl %eax, %eax
je 0x64ce
xorl %edi, %edi
movq %r14, %rsi
xorl %edx, %edx
movl %r12d, %ecx
callq 0x88e6
movzwl %ax, %r13d
movq %r15, %rdi
leaq 0xc(%rsp), %rsi
movl %ebp, %edx
movl %r12d, %ecx
xorl %r8d, %r8d
callq 0x618d
movl 0xc(%rsp), %edx
cmpl %r13d, %edx
je 0x64d7
leaq 0x51ac(%rip), %rdi      # 0xb66e
movl %ebx, %esi
movl %r13d, %ecx
xorl %eax, %eax
callq 0x2050
incl %ebx
cmpl $0x3, %ebx
jne 0x6463
jmp 0x6500
addl %r12d, %ebp
movslq %r12d, %rax
addq %rax, %r14
cmpl $0x1001, 0x10(%rsp)     # imm = 0x1001
movl 0x8(%rsp), %eax
movl %eax, %ecx
movl $0x1000, %eax           # imm = 0x1000
jge 0x6446
movl $0x1, %eax
jmp 0x651a
leaq 0x52aa(%rip), %rdi      # 0xb7b1
callq 0x2270
leaq 0x52b7(%rip), %rdi      # 0xb7ca
callq 0x2270
xorl %eax, %eax
addq $0x18, %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/w8790_funcs.cpp
// Function: wh_w8790_dev_get_device_info(WdtDevice*, unsigned char*, int, int)
int wh_w8790_dev_get_device_info(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_INFO;
	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
movq %rsi, %rcx
leaq 0xe(%rsp), %rsi
movw $0x0, 0x8(%rsi)
movl $0x0, 0x4(%rsi)
movw $0xc806, (%rsi)         # imm = 0xC806
movb %dl, 0x2(%rsi)
movb %r9b, 0x3(%rsi)
xorl %r8d, %r8d
callq 0x53d0
addq $0x18, %rsp
retq
// File: /workspace/github_cpp_makefile_star2_O3/chenhn123[P]wdt_util_src/wdt_ct/w8790_funcs.cpp
// Function: wh_w8790_dev_flash_erase(WdtDevice*, unsigned int, int)
int wh_w8790_dev_flash_erase(WDT_DEV* pdev, UINT32 address, int size)
{
	int ret = wh_w8790_dev_flash_erase_cmd(pdev, address, size);

	if (ret <= 0)
		printf("%s: addr: %x, size: %x\n", __FUNCTION__, address, size);

	return ret;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
movl %edx, %ebx
movl %esi, %ebp
callq 0x5e18
movl %eax, %r14d
testl %eax, %eax
jne 0x66e1
leaq 0x5307(%rip), %rdi      # 0xb9d6
leaq 0x5510(%rip), %rsi      # 0xbbe6
movl %ebp, %edx
movl %ebx, %ecx
xorl %eax, %eax
callq 0x2050
movl %r14d, %eax
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O3/chenhn123[P]wdt_util_src/wdt_ct/w8790_funcs.cpp
// Function: wh_w8790_dev_write_register(WdtDevice*, unsigned int, unsigned int)
int wh_w8790_dev_write_register(WDT_DEV* pdev, UINT32 address, UINT32 reg_value)
{
    BYTE cmd[10] = { 0 };
    
    cmd[0] = W8790_COMMAND9;
    cmd[1] = (BYTE)W8790_WRITE_REGISTER;
    put_unaligned_le32(address, &cmd[2]);
    put_unaligned_le32(reg_value, &cmd[6]);

    return wh_w8790_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
movq $0x0, (%rsi)
movw $0xdf06, -0x2(%rsi)     # imm = 0xDF06
movl %eax, %edi
callq 0x6f72
leaq 0x14(%rsp), %rsi
movl %ebx, %edi
callq 0x6f72
leaq 0xe(%rsp), %rsi
movq %r14, %rdi
callq 0x5179
movl $0x1, %ebx
testl %eax, %eax
jne 0x6742
leaq 0x540b(%rip), %rdi      # 0xbb44
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x2506
movl %ebx, %eax
addq $0x18, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_cpp_makefile_star2_O3/chenhn123[P]wdt_util_src/wdt_ct/w8790_funcs.cpp
// Function: wh_w8790_flash_section_validate(unsigned char*, unsigned int, int)
int wh_w8790_flash_section_validate(BYTE* data, UINT32 datalength, int start = 0)
{
	int ret = 0;
	W8790_FLASH_SECTION_HEADER header;

	header.Param1 = get_unaligned_le32(&data[12]);
	header.Param0 = get_unaligned_le32(&data[8]);
	header.PayloadSize = get_unaligned_le32(&data[4]);
	header.HeaderChecksum = get_unaligned_le16(&data[2]);
	header.Checksum = get_unaligned_le16(&data[0]);
	if (header.HeaderChecksum != wh_w8790_flash_section_header_checksum(header))
	{
		wh_printf("Invalid section header. \n");
		return 0;
	}
	if (start + sizeof(header) + header.PayloadSize > datalength)
	{
		wh_printf("Invalid section length. \n");
		return 0;
	}
	BYTE* payload;
	payload = (BYTE*)calloc(header.PayloadSize, sizeof(BYTE));
	if (!payload) {
		wh_printf("calloc fail !\n");
		return 0;
	}
	memcpy(payload, &data[16], header.PayloadSize);

	if (header.Checksum != misr_for_bytes(header.HeaderChecksum, payload, 0, header.PayloadSize / sizeof(BYTE))) {
		ret = 0;
		wh_printf("Payload checksum error.\n");
	}
	else 
	{
		ret = 1;
	}
		
	if (payload)
		free(payload);
	return ret;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %edx, (%rsp)
movl %esi, 0x4(%rsp)
movq %rdi, %rbx
addq $0xc, %rdi
callq 0x6f6b
movl %eax, %r14d
shlq $0x20, %r14
leaq 0x8(%rbx), %rdi
callq 0x6f6b
movl %eax, %ebp
orq %r14, %rbp
leaq 0x4(%rbx), %rdi
callq 0x6f6b
movl %eax, %r14d
movq %r14, %r13
shlq $0x20, %r13
leaq 0x2(%rbx), %rdi
callq 0x6f67
movl %eax, %r12d
movl %r12d, %r15d
shll $0x10, %r15d
orq %r13, %r15
movq %rbx, %rdi
callq 0x6f67
movl %eax, %r13d
movzwl %ax, %edi
orq %r15, %rdi
movq %rbp, %rsi
callq 0x674c
cmpw %ax, %r12w
jne 0x681c
movslq (%rsp), %rax
addq %r14, %rax
addq $0x10, %rax
movl 0x4(%rsp), %ecx
cmpq %rcx, %rax
jbe 0x683d
leaq 0x53ff(%rip), %rdi      # 0xbc19
jmp 0x6823
leaq 0x53dc(%rip), %rdi      # 0xbbff
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x2506
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x1, %esi
movq %r14, %rdi
callq 0x2130
testq %rax, %rax
je 0x689a
movq %rax, %r15
addq $0x10, %rbx
movq %rax, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x2150
movzwl %r12w, %edi
movq %r15, %rsi
xorl %edx, %edx
movl %r14d, %ecx
callq 0x88e6
movl $0x1, %ebx
cmpw %ax, %r13w
je 0x6890
leaq 0x53bb(%rip), %rdi      # 0xbc42
xorl %eax, %eax
callq 0x2506
xorl %ebx, %ebx
movq %r15, %rdi
callq 0x21e0
jmp 0x682c
leaq 0x5392(%rip), %rdi      # 0xbc33
jmp 0x6823
// File: /workspace/github_cpp_makefile_star2_O3/chenhn123[P]wdt_util_src/wdt_ct/w8790_funcs.cpp
// Function: wh_w8790_prepare_data(WdtDevice*, BoardInfo*)
int wh_w8790_prepare_data(WDT_DEV* pdev, BOARD_INFO* p_out_board_info)
{
	if (!pdev || !p_out_board_info)
		return 0;
	wh_w8790_dev_set_basic_op(pdev);



	if (!wh_w8790_dev_identify_platform(pdev)) {
		wh_printf("can't get platform identify!\n");
		return 0;
	}
	//I:0x49 S:0x53 P:0x50 
	if (pdev->board_info.dev_info.w8790_feature_devinfo.program_name_fourcc[0] == 'I' &&
		pdev->board_info.dev_info.w8790_feature_devinfo.program_name_fourcc[1] == 'S' &&
		pdev->board_info.dev_info.w8790_feature_devinfo.program_name_fourcc[2] == 'P')
	{
		p_out_board_info->dev_type = FW_WDT8790_ISP;
		wh_printf("It is ISP mode!\n");


		return 1;

	}


	W8790_PCT pct_data;


	if (wh_w8790_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_id2 = 0;

		W8790_PARAMETER_INFO parameter_info;
		wh_w8790_dev_read_parameter_table_info(pdev, &parameter_info);
		UINT32 cksum;
		wh_w8790_dev_read_parameters_get_checksum(pdev, parameter_info, &cksum);
		p_out_board_info->sys_param.xmls_id1 = cksum;

		return 1;
	}

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x28, %rsp
testq %rdi, %rdi
sete %al
testq %rsi, %rsi
sete %cl
xorl %ebp, %ebp
orb %al, %cl
jne 0x6cec
movq %rsi, %rbx
movq %rdi, %r14
callq 0x52bd
testl %eax, %eax
je 0x6cd8
cmpb $0x49, 0x220(%r14)
jne 0x6c66
cmpb $0x53, 0x221(%r14)
jne 0x6c66
cmpb $0x50, 0x222(%r14)
jne 0x6c66
movl $0x201, (%rbx)          # imm = 0x201
leaq 0x5137(%rip), %rdi      # 0xbd94
xorl %eax, %eax
callq 0x2506
jmp 0x6cd1
leaq 0xa(%rsp), %rsi
movq %r14, %rdi
callq 0x5327
testl %eax, %eax
je 0x6cea
movzbl 0xc(%rsp), %eax
movw %ax, 0x24(%rbx)
movzbl 0xb(%rsp), %eax
movw %ax, 0x26(%rbx)
movd 0xe(%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(%rbx)
movw $0x0, 0x22(%rbx)
leaq 0x18(%rsp), %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0x588c
movq (%r15), %rsi
movl 0x8(%r15), %edx
leaq 0x14(%rsp), %r15
movq %r14, %rdi
movq %r15, %rcx
callq 0x68a3
movzwl (%r15), %eax
movw %ax, 0x20(%rbx)
movl $0x1, %ebp
jmp 0x6cec
leaq 0x5097(%rip), %rdi      # 0xbd76
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x2506
jmp 0x6cec
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x28, %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/wdt_dev_api.cpp
// Function: wh_get_device_access_func(int, FuncPtrStructDevAccess*)
int wh_get_device_access_func(int interfaceIndex, FUNC_PTR_STRUCT_DEV_ACCESS*  pFuncs)
{
	if (!pFuncs)
		return 0;

	if (interfaceIndex == INTERFACE_I2C) {
		pFuncs->p_wh_scan_device = (LPFUNC_wh_scan_device) wh_i2c_scan_device;
		pFuncs->p_wh_get_device = (LPFUNC_wh_get_device) wh_i2c_get_device;
		pFuncs->p_wh_open_device = (LPFUNC_wh_open_device) wh_i2c_open_device;
		pFuncs->p_wh_close_device = (LPFUNC_wh_close_device) wh_i2c_close_device;
		pFuncs->p_wh_prepare_data = (LPFUNC_wh_prepare_data) wh_i2c_prepare_data;			
		return 1;
	}

	return 0;
}

// Assembly:
testq %rsi, %rsi
sete %cl
cmpl $0x2, %edi
setne %dl
xorl %eax, %eax
orb %cl, %dl
jne 0x6d49
leaq 0x2056(%rip), %rax      # 0x8d6b
movq %rax, (%rsi)
leaq 0x213b(%rip), %rax      # 0x8e5a
movq %rax, 0x8(%rsi)
leaq 0x2163(%rip), %rax      # 0x8e8d
movq %rax, 0x10(%rsi)
leaq 0x2228(%rip), %rax      # 0x8f5d
movq %rax, 0x18(%rsi)
leaq 0x23ab(%rip), %rax      # 0x90eb
movq %rax, 0x20(%rsi)
movl $0x1, %eax
retq
// File: /workspace/github_cpp_makefile_star2_O3/chenhn123[P]wdt_util_src/wdt_ct/wdt_dev_api.cpp
// Function: wh_get_device_private_access_func(WdtDevice*, FuncPtrStructDevOperation*)
int wh_get_device_private_access_func(WDT_DEV* pdev,  FUNC_PTR_STRUCT_DEV_OPERATION*  pFuncs)
{
	if (!pFuncs || !pdev)
		return 0;

	if (pdev->board_info.dev_type & FW_WDT8755) {
		pFuncs->p_wh_program_chunk = (LPFUNC_wh_program_chunk) wh_w8755_dev_program_chunk;
		pFuncs->p_wh_verify_chunk	= (LPFUNC_wh_verify_chunk) wh_w8755_dev_verify_chunk;
		pFuncs->p_wh_flash_write_data = (LPFUNC_wh_flash_write_data) wh_w8755_dev_flash_write_data;
		pFuncs->p_wh_flash_get_checksum = (LPFUNC_wh_flash_get_checksum) wh_w8755_dev_flash_get_checksum;
 		pFuncs->p_wh_send_commands = (LPFUNC_wh_send_commands) wh_w8755_dev_send_commands;

		return wh_w8755_dev_set_basic_op(pdev);
	}

	if (pdev->board_info.dev_type & FW_WDT8760_2) {
		pFuncs->p_wh_program_chunk = (LPFUNC_wh_program_chunk) wh_w8760_dev_program_chunk;
		pFuncs->p_wh_verify_chunk	= (LPFUNC_wh_verify_chunk) wh_w8760_dev_verify_chunk;
		pFuncs->p_wh_flash_write_data = (LPFUNC_wh_flash_write_data) wh_w8760_dev_flash_write_data;
		pFuncs->p_wh_flash_get_checksum = (LPFUNC_wh_flash_get_checksum) wh_w8760_dev_flash_get_checksum;
 		pFuncs->p_wh_send_commands = (LPFUNC_wh_send_commands) wh_w8760_dev_send_commands;

		return wh_w8760_dev_set_basic_op(pdev);
	}
	if (pdev->board_info.dev_type & FW_WDT8790) {
		pFuncs->p_wh_flash_write_data = (LPFUNC_wh_flash_write_data)wh_w8790_dev_flash_write_data;
		pFuncs->p_wh_flash_get_checksum = (LPFUNC_wh_flash_get_checksum)wh_w8790_dev_flash_get_checksum;
		pFuncs->p_wh_send_commands = (LPFUNC_wh_send_commands)wh_w8790_dev_send_commands;
		pFuncs->p_wh_flash_erase = (LPFUNC_wh_flash_erase)wh_w8790_dev_flash_erase;


		return wh_w8790_dev_set_basic_op(pdev);
	}


	return 0;

}

// Assembly:
testq %rsi, %rsi
sete %al
testq %rdi, %rdi
sete %cl
orb %al, %cl
jne 0x6deb
movl 0x188(%rdi), %eax
testb $0x20, %al
jne 0x6daa
testl $0x2800, %eax           # imm = 0x2800
je 0x6de5
leaq -0x1cea(%rip), %rax     # 0x508c
movq %rax, (%rsi)
leaq -0x21b5(%rip), %rax     # 0x4bcb
movq %rax, 0x8(%rsi)
leaq -0x22ea(%rip), %rax     # 0x4aa1
movq %rax, 0x18(%rsi)
leaq -0x2275(%rip), %rax     # 0x4b21
movq %rax, 0x20(%rsi)
leaq -0x24c9(%rip), %rax     # 0x48d8
movq %rax, 0x28(%rsi)
jmp 0x3ef3
leaq -0x3433(%rip), %rax     # 0x397e
movq %rax, (%rsi)
leaq -0x3449(%rip), %rax     # 0x3972
movq %rax, 0x8(%rsi)
leaq -0x4110(%rip), %rax     # 0x2cb6
movq %rax, 0x18(%rsi)
leaq -0x39da(%rip), %rax     # 0x33f7
movq %rax, 0x20(%rsi)
leaq -0x4044(%rip), %rax     # 0x2d98
movq %rax, 0x28(%rsi)
jmp 0x39ce
btl $0x9, %eax
jb 0x6dee
xorl %eax, %eax
retq
leaq -0x77b(%rip), %rax      # 0x667a
movq %rax, 0x18(%rsi)
leaq -0xc73(%rip), %rax      # 0x618d
movq %rax, 0x20(%rsi)
leaq -0x8e2(%rip), %rax      # 0x6529
movq %rax, 0x28(%rsi)
leaq -0x762(%rip), %rax      # 0x66b4
movq %rax, 0x30(%rsi)
jmp 0x5203
// File: /workspace/github_cpp_makefile_star2_O3/chenhn123[P]wdt_util_src/wdt_ct/wdt_dev_api.cpp
// Function: check_firmware_id(WdtDevice*, unsigned int)
int check_firmware_id(WDT_DEV *pdev, UINT32 fwid)
{
	if ((fwid & 0xF0000000) == 0x30000000) {
		if (pdev->pparam->argus & OPTION_INFO)		
			printf("It is WDT8755 or WDT8752 !\n");	
		return FW_WDT8755;
	}

	if ((fwid & 0xFFFF0000) == 0xFFFF0000) {
		if (pdev->pparam->argus & OPTION_INFO)		
			printf("It is WDT8752 recovery fw !\n");	
		return FW_WDT8755;
	}	

	if ((fwid & 0xF0000000) == 0x40000000) {
		if (pdev->pparam->argus & OPTION_INFO)	
			printf("It is WDT8760 alike !\n");	
		return FW_WDT8760;
	}

	if ((fwid & 0xFF000000) == 0x51000000) {
                if(pdev->pparam->argus & OPTION_INFO)
                        printf("It is WDT8730 !\n");
                return FW_NOT_SUPPORT;

        }

	//TODO: We will add new devices here and should before FW_WDT8970 for compatibility.

	if ((fwid & 0xFF000000) == 0x50000000) {
		if(pdev->pparam->argus & OPTION_INFO)
			printf("It is WDT8790 !\n");
		return FW_WDT8790;

	}
	
	return FW_WITH_CMD;
}

// Assembly:
pushq %rbx
movl %esi, %eax
andl $0xf0000000, %eax       # imm = 0xF0000000
cmpl $0x30000000, %eax       # imm = 0x30000000
jne 0x6ece
movq 0x280(%rdi), %rax
movl $0x20, %ebx
testb $0x8, (%rax)
je 0x6f63
leaq 0x5738(%rip), %rdi      # 0xc601
jmp 0x6f5e
cmpl $0xffff0000, %esi       # imm = 0xFFFF0000
jb 0x6ef0
movq 0x280(%rdi), %rax
movl $0x20, %ebx
testb $0x8, (%rax)
je 0x6f63
leaq 0x56f7(%rip), %rdi      # 0xc5e5
jmp 0x6f5e
cmpl $0x40000000, %eax       # imm = 0x40000000
jne 0x6f11
movq 0x280(%rdi), %rax
movl $0x800, %ebx            # imm = 0x800
testb $0x8, (%rax)
je 0x6f63
leaq 0x56c0(%rip), %rdi      # 0xc5cf
jmp 0x6f5e
andl $0xff000000, %esi       # imm = 0xFF000000
cmpl $0x50000000, %esi       # imm = 0x50000000
je 0x6f46
movl $0x2, %ebx
cmpl $0x51000000, %esi       # imm = 0x51000000
jne 0x6f63
movq 0x280(%rdi), %rax
movl $0x4, %ebx
testb $0x8, (%rax)
je 0x6f63
leaq 0x567b(%rip), %rdi      # 0xc5bf
jmp 0x6f5e
movq 0x280(%rdi), %rax
movl $0x200, %ebx            # imm = 0x200
testb $0x8, (%rax)
je 0x6f63
leaq 0x5651(%rip), %rdi      # 0xc5af
callq 0x2270
movl %ebx, %eax
popq %rbx
retq
// File: /workspace/github_cpp_makefile_star2_O3/chenhn123[P]wdt_util_src/wdt_ct/wdt_dev_api.cpp
// Function: check_is_all_ff(unsigned char*, int)
int check_is_all_ff(BYTE* data, int length)
{
	if (data == 0)
		return 0;

	int idx;

	for (idx = 0; idx < length; idx++)
		if (data[idx] != 0xFF)
			return 0;
	return 1;
}

// Assembly:
testq %rdi, %rdi
je 0x6f96
movl $0x1, %eax
testl %esi, %esi
jle 0x6f95
movl %esi, %ecx
xorl %edx, %edx
cmpb $-0x1, (%rdi,%rdx)
jne 0x6f96
incq %rdx
cmpq %rdx, %rcx
jne 0x6f87
retq
xorl %eax, %eax
retq
// File: /workspace/github_cpp_makefile_star2_O3/chenhn123[P]wdt_util_src/wdt_ct/wdt_dev_api.cpp
// Function: count_ff_bytes(unsigned char*, int, int)
int count_ff_bytes(BYTE* data, int start, int size)
{
	int count = 0;
	for (int i = 0; i < size; i++)
	{
		if (data[start + i] == 0xFF)
			count++;
	}
	return count;
}

// Assembly:
testl %edx, %edx
jle 0x6fbe
movslq %esi, %rax
movl %edx, %ecx
addq %rax, %rdi
xorl %edx, %edx
xorl %eax, %eax
xorl %esi, %esi
cmpb $-0x1, (%rdi,%rdx)
sete %sil
addl %esi, %eax
incq %rdx
cmpq %rdx, %rcx
jne 0x6fa9
retq
xorl %eax, %eax
retq
// File: /workspace/github_cpp_makefile_star2_O3/chenhn123[P]wdt_util_src/wdt_ct/wdt_dev_api.cpp
// Function: wh_open_whiff_file(char*)
WH_HANDLE wh_open_whiff_file(char* path)
{
	FILE*			pfile = NULL;
	WIF_FILE 		*pcur_wif = NULL;

	pfile = fopen(path, "rb");
	if (!pfile)
		return NULL;

	pcur_wif = (WIF_FILE*) malloc(sizeof(WIF_FILE));
	if (!pcur_wif) {
		fclose(pfile);
		return NULL;
	}

	/* set file ptr to the end */
	fseek(pfile, 0, SEEK_END);
	pcur_wif->data_len = ftell(pfile);

	/* set the file ptr the beginning */
	rewind(pfile);		

	pcur_wif->pdata = (BYTE*) malloc(pcur_wif->data_len + 32);

	if (!pcur_wif->pdata)
		goto failed;

	if (fread(pcur_wif->pdata, 1, pcur_wif->data_len, pfile) == pcur_wif->data_len)	{	
		process_whiff_file(pcur_wif);
		fclose(pfile);

		return (WH_HANDLE) pcur_wif;
	}

failed:
	wh_close_whiff_file((WH_HANDLE) pcur_wif);
		
	return NULL;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
leaq 0x5528(%rip), %rsi      # 0xc55b
callq 0x21d0
testq %rax, %rax
je 0x70ef
movq %rax, %r14
movl $0x18, %edi
callq 0x21f0
testq %rax, %rax
je 0x70e7
movq %rax, %rbx
movq %r14, %rdi
xorl %esi, %esi
movl $0x2, %edx
callq 0x21c0
movq %r14, %rdi
callq 0x2030
movq %rax, %r15
movl %r15d, 0x8(%rbx)
movq %r14, %rdi
callq 0x2070
leal 0x20(%r15), %edi
callq 0x21f0
movq %rax, (%rbx)
testq %rax, %rax
je 0x70dd
movq %rax, %r12
movl %r15d, %r13d
movl $0x1, %esi
movq %rax, %rdi
movq %r13, %rdx
movq %r14, %rcx
callq 0x2240
cmpq %r13, %rax
jne 0x70dd
cmpl $0x46464952, (%r12)     # imm = 0x46464952
jne 0x70d3
cmpl $0x46494857, 0x8(%r12)  # imm = 0x46494857
jne 0x70d3
cmpl %r15d, 0x4(%r12)
jne 0x70d3
addq $0xc, %r12
movq %r12, 0x10(%rbx)
movq %r14, %rdi
callq 0x21a0
jmp 0x70f1
movq %rbx, %rdi
callq 0x70fe
jmp 0x70ef
movq %r14, %rdi
callq 0x21a0
xorl %ebx, %ebx
movq %rbx, %rax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
// File: /workspace/github_cpp_makefile_star2_O3/chenhn123[P]wdt_util_src/wdt_ct/wdt_dev_api.cpp
// Function: wh_close_whiff_file(void*)
int wh_close_whiff_file(WH_HANDLE handle)
{
	WIF_FILE	*pcur_wif = (WIF_FILE*) handle;

	if (pcur_wif) {
		if (pcur_wif->pdata)
			free(pcur_wif->pdata);

		free(pcur_wif);
		return 1;
	}

	return 0;
}

// Assembly:
testq %rdi, %rdi
je 0x7123
pushq %rbx
movq %rdi, %rbx
movq (%rdi), %rdi
testq %rdi, %rdi
je 0x7114
callq 0x21e0
movq %rbx, %rdi
callq 0x21e0
movl $0x1, %eax
popq %rbx
retq
xorl %eax, %eax
retq
// File: /workspace/github_cpp_makefile_star2_O3/chenhn123[P]wdt_util_src/wdt_ct/wdt_dev_api.cpp
// Function: wh_get_chunk_info(void*, unsigned int, ChunkInfoEx*)
int wh_get_chunk_info(WH_HANDLE handle, UINT32 chunk_index, CHUNK_INFO_EX* pchunk_info_ex)
{
	WIF_FILE	*pcur_wif = (WIF_FILE*) handle;

	if (!pcur_wif)
		return 0;

	UINT32	chunk_four_cc = get_chunk_fourcc (chunk_index);

	if (!chunk_four_cc)
		return 0;

	if (!pcur_wif->pformat_chunk)
		return 0;

	/* check if the chunk is existed */
	if (pcur_wif->pformat_chunk->enableFlag | chunk_index) {
		
		/* 12 is the header size */
		UINT32	chunk_start_pos = 12 + sizeof (FORMAT_CHUNK);
		CHUNK_DATA*	pchunk_data = NULL;

		while (chunk_start_pos < pcur_wif->data_len) {
			pchunk_data = (CHUNK_DATA*) & pcur_wif->pdata[chunk_start_pos];

			/* we got it */
			if (pchunk_data->ckID == chunk_four_cc)	{
				memcpy((void*) &pchunk_info_ex->chuckInfo, (void*) &pchunk_data->chunkInfo, sizeof(CHUNK_INFO));
				pchunk_info_ex->length = pchunk_data->chunkInfo.length;
				pchunk_info_ex->pData = (BYTE*) &pcur_wif->pdata[chunk_start_pos + 8 + sizeof(CHUNK_INFO)];
				
				return 1;
			} else
				/* 8 is the header size */
				chunk_start_pos = chunk_start_pos + pchunk_data->ckSize + 8;
		}
	}

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
xorl %ebx, %ebx
testq %rdi, %rdi
je 0x71ae
movq %rdx, %r14
movl %esi, %ebp
movq %rdi, %r15
movl %esi, %edi
callq 0x86c3
testl %eax, %eax
je 0x71ae
movq 0x10(%r15), %rcx
testq %rcx, %rcx
je 0x71ae
orl 0xc(%rcx), %ebp
je 0x71ae
movl 0x8(%r15), %edx
cmpl $0x29, %edx
jb 0x71ae
movq (%r15), %rsi
movl $0x28, %ecx
movl %ecx, %r8d
leaq (%rsi,%r8), %rdi
cmpl %eax, (%rsi,%r8)
je 0x7181
movl 0x4(%rdi), %edi
addl %edi, %ecx
addl $0x8, %ecx
cmpl %edx, %ecx
jb 0x7166
jmp 0x71ae
movq 0x18(%rdi), %rax
movq %rax, 0x10(%r14)
movups 0x8(%rdi), %xmm0
movups %xmm0, (%r14)
movl 0xc(%rdi), %eax
movl %eax, 0x20(%r14)
movq (%r15), %rax
addl $0x8, %ecx
addq %rcx, %rax
addq $0x18, %rax
movq %rax, 0x18(%r14)
movl $0x1, %ebx
movl %ebx, %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/wdt_dev_api.cpp
// Function: load_wif(WdtDevice*, char*)
int load_wif(WDT_DEV *pdev, char *path)
{
	if (!pdev || !path)
		return 0;

	strcpy(pdev->wif_access.wif_path, path);

	pdev->wif_access.wif_handle = pdev->func_wh_open_whiff(pdev->wif_access.wif_path);

	if (!pdev->wif_access.wif_handle) {
		wh_printf("Parse input file error");
		return 0;
	}

	memset(&pdev->wif_access.wif_chunk_info, 0, sizeof(CHUNK_INFO_EX));

	return 1;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
testq %rdi, %rdi
sete %al
testq %rsi, %rsi
sete %cl
xorl %ebp, %ebp
orb %al, %cl
jne 0x7228
movq %rdi, %rbx
leaq 0x58(%rdi), %r14
movq %r14, %rdi
callq 0x2180
movq %r14, %rdi
callq *0x308(%rbx)
movq %rax, 0x158(%rbx)
testq %rax, %rax
je 0x7218
xorps %xmm0, %xmm0
movups %xmm0, 0x170(%rbx)
movups %xmm0, 0x160(%rbx)
movq $0x0, 0x180(%rbx)
movl $0x1, %ebp
jmp 0x7228
leaq 0x4c41(%rip), %rdi      # 0xbe60
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x2506
movl %ebp, %eax
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O3/chenhn123[P]wdt_util_src/wdt_ct/wdt_dev_api.cpp
// Function: fw_version_check(ExecParam*, BoardInfo*, ChunkInfoEx*)
int fw_version_check(EXEC_PARAM *pparam, BOARD_INFO *pinfo, CHUNK_INFO_EX *pchunk_info)
{
	if (!pparam || !pinfo || !pchunk_info)
		return 0;

	char	fw_id = ((pchunk_info->chuckInfo.versionNumber >> 12) & 0xF);
	char	chip_id = ((pinfo->firmware_id >> 12) & 0xF);
	
	if (fw_id != chip_id) {
		printf("This firmware is not matched with this chip, fwid(%x), chip_id(%x)\n", fw_id, chip_id);
		return 0;
	} 

	if (pinfo->dev_type & FW_WDT8760) {
		if ((pchunk_info->chuckInfo.temp & 0xFF000000) != 0x31000000) {			
			printf("The device type is not matched with this firmware (%x)\n", pchunk_info->chuckInfo.temp);
			return 0;
		}
	} else if (pinfo->dev_type & FW_WDT8762) {
		if ((pchunk_info->chuckInfo.temp & 0xFF000000) != 0x32000000) { 		
			printf("The device type is not matched with this firmware (%x)\n", pchunk_info->chuckInfo.temp);
			return 0;
		}
	}

	wh_printf("The firmware vession: dev %x, wif %x\n", pinfo->firmware_id,
			  pchunk_info->chuckInfo.versionNumber); 

	unsigned int fw_ver = pchunk_info->chuckInfo.versionNumber & 0xFFF;
	unsigned int chip_fw_ver = pinfo->firmware_id & 0xFFF;

	/* just ignore the recovery firmware */
	if (( fw_ver <= chip_fw_ver) && (chip_fw_ver != 0xFFF)) 
		return 2;

	return 1;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
testq %rdi, %rdi
sete %al
testq %rsi, %rsi
sete %cl
orb %al, %cl
testq %rdx, %rdx
sete %al
xorl %ebp, %ebp
orb %cl, %al
jne 0x7584
movq %rdx, %r14
movq %rsi, %rbx
movl 0xc(%rdx), %edx
movl %edx, %eax
shrl $0xc, %eax
andl $0xf, %eax
movl 0x10(%rsi), %esi
movl %esi, %ecx
shrl $0xc, %ecx
andl $0xf, %ecx
cmpl %ecx, %eax
jne 0x752b
movl (%rbx), %eax
btl $0xb, %eax
jb 0x7541
btl $0xd, %eax
jae 0x7555
movl 0x14(%r14), %eax
movl %eax, %ecx
andl $0xff000000, %ecx       # imm = 0xFF000000
cmpl $0x32000000, %ecx       # imm = 0x32000000
je 0x7555
leaq 0x4a43(%rip), %rdi      # 0xbf61
xorl %ebp, %ebp
movl %eax, %esi
xorl %eax, %eax
callq 0x2050
jmp 0x7584
leaq 0x49eb(%rip), %rdi      # 0xbf1d
xorl %ebp, %ebp
movl %eax, %esi
movl %ecx, %edx
xorl %eax, %eax
callq 0x2050
jmp 0x7584
movl 0x14(%r14), %eax
movl %eax, %ecx
andl $0xff000000, %ecx       # imm = 0xFF000000
cmpl $0x31000000, %ecx       # imm = 0x31000000
jne 0x7517
leaq 0x4a3d(%rip), %rdi      # 0xbf99
xorl %eax, %eax
callq 0x2506
movl $0xfff, %eax            # imm = 0xFFF
movl 0xc(%r14), %ecx
andl %eax, %ecx
movl 0x10(%rbx), %edx
andl %eax, %edx
cmpl %edx, %ecx
setbe %cl
cmpl %eax, %edx
setne %al
andb %cl, %al
movzbl %al, %ebp
incl %ebp
movl %ebp, %eax
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O3/chenhn123[P]wdt_util_src/wdt_ct/wdt_dev_api.cpp
// Function: config_id_check(ExecParam*, BoardInfo*, ChunkInfoEx*)
int config_id_check(EXEC_PARAM *pparam, BOARD_INFO *pinfo, CHUNK_INFO_EX *pchunk_info)
{
	if (!pparam || !pinfo || !pchunk_info)
		return 0;

	unsigned int 	xmlId = 0;

	if (pchunk_info->chuckInfo.attribute & 0x2)
		xmlId = pchunk_info->chuckInfo.versionNumber;

	wh_printf("The config data in dev: %04x, wif: %04x\n", xmlId, pinfo->sys_param.xmls_id1);
	if (xmlId == pinfo->sys_param.xmls_id1) 
		return 2;

	return 1;
}

// Assembly:
pushq %rbp
pushq %rbx
pushq %rax
movq %rsi, %rbx
testq %rdi, %rdi
sete %al
testq %rsi, %rsi
sete %cl
orb %al, %cl
testq %rdx, %rdx
sete %sil
xorl %eax, %eax
orb %cl, %sil
jne 0x75d9
xorl %ebp, %ebp
testb $0x2, 0x10(%rdx)
je 0x75b8
movl 0xc(%rdx), %ebp
movzwl 0x20(%rbx), %edx
leaq 0x49fc(%rip), %rdi      # 0xbfbf
movl %ebp, %esi
xorl %eax, %eax
callq 0x2506
movzwl 0x20(%rbx), %ecx
xorl %eax, %eax
cmpl %ecx, %ebp
sete %al
incl %eax
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O3/chenhn123[P]wdt_util_src/wdt_ct/wdt_dev_api.cpp
// Function: program_one_chunk(WdtDevice*, char const*, unsigned int, unsigned int, ChunkInfoEx*)
int program_one_chunk(WDT_DEV *pdev, const char *chunk_name, UINT32 chunk_id, UINT32 option, CHUNK_INFO_EX *pinfo)
{
	CHUNK_INFO_EX	chunk_info;
	CHUNK_INFO_EX	*pchunk_info = NULL;

	if (!pdev)
		return 0;

	if (pinfo == NULL) {
		memset(&chunk_info, 0, sizeof(CHUNK_INFO_EX));
		if (pdev->func_wh_get_chunk_info(pdev->wif_access.wif_handle, chunk_id, &chunk_info))
			pchunk_info = &chunk_info;
		else
			return 1;
	} else
		pchunk_info = pinfo;

	if (!pchunk_info)
		return 0;
		
	printf("\n[%s] programming ....\n", chunk_name);
				
	if (!pdev->funcs_device_private.p_wh_program_chunk(pdev, pchunk_info, option ))	{
		char	msg[64];

		sprintf(msg, "[%s] Write chunk error", chunk_name);
		wh_printf(msg);
		return 0;	
	}

	printf("[%s] chunk program : pass...\n", chunk_name);
	return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x70, %rsp
testq %rdi, %rdi
je 0x7676
movq %r8, %r12
movl %ecx, %r14d
movq %rsi, %rbx
movq %rdi, %r15
testq %r8, %r8
jne 0x7637
xorps %xmm0, %xmm0
movq %rsp, %r12
movaps %xmm0, 0x10(%r12)
movaps %xmm0, (%r12)
movq $0x0, 0x20(%r12)
movq 0x158(%r15), %rdi
movl %edx, %esi
movq %r12, %rdx
callq *0x318(%r15)
testl %eax, %eax
je 0x766f
leaq 0x49aa(%rip), %rdi      # 0xbfe8
xorl %ebp, %ebp
movq %rbx, %rsi
xorl %eax, %eax
callq 0x2050
movq %r15, %rdi
movq %r12, %rsi
movl %r14d, %edx
callq *0x2b0(%r15)
testl %eax, %eax
je 0x767a
leaq 0x49b2(%rip), %rdi      # 0xc017
movq %rbx, %rsi
xorl %eax, %eax
callq 0x2050
movl $0x1, %ebp
jmp 0x769d
xorl %ebp, %ebp
jmp 0x769d
leaq 0x497f(%rip), %rsi      # 0xc000
leaq 0x30(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x2080
movq %r14, %rdi
xorl %eax, %eax
callq 0x2506
movl %ebp, %eax
addq $0x70, %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/wdt_dev_api.cpp
// Function: show_wif_info(WdtDevice*, ExecParam*)
int show_wif_info(WDT_DEV *pdev, EXEC_PARAM *pparam)
{
	if (!pdev || !pparam)
		return 0;
	if(show_wif2_info((char*)pparam->image_file))
		return 1;

	if (!load_wif(pdev, (char*)pparam->image_file))
		return 0;

	CHUNK_INFO_EX chunk_info_ex;
	if (pdev->func_wh_get_chunk_info(pdev->wif_access.wif_handle, CHUNK_ID_FRWR, &chunk_info_ex)) 
		printf("FW id: 0x%08x\n", chunk_info_ex.chuckInfo.versionNumber);

	if (pdev->func_wh_get_chunk_info(pdev->wif_access.wif_handle, CHUNK_ID_CNFG, &chunk_info_ex)) {
		UINT32	config_id = 0;
		
		if (chunk_info_ex.chuckInfo.attribute & 0x2)
			config_id = chunk_info_ex.chuckInfo.versionNumber;
		printf("Config id: 0x%x\n", config_id);		
	}
	
	if (!close_wif(pdev))
		return 0; 
	
	return 1;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
subq $0x30, %rsp
testq %rdi, %rdi
sete %al
testq %rsi, %rsi
sete %cl
xorl %ebp, %ebp
orb %al, %cl
jne 0x8164
movq %rsi, %r14
movq %rdi, %rbx
movq 0x10(%rsi), %rdi
callq 0xa388
movl $0x1, %ebp
testl %eax, %eax
je 0x816f
movl %ebp, %eax
addq $0x30, %rsp
popq %rbx
popq %r14
popq %rbp
retq
movq 0x10(%r14), %rsi
movq %rbx, %rdi
callq 0x71bb
movl $0x0, %ebp
testl %eax, %eax
je 0x8164
movq 0x158(%rbx), %rdi
leaq 0x8(%rsp), %rdx
movl $0x1, %esi
callq *0x318(%rbx)
testl %eax, %eax
je 0x81b1
movl 0x14(%rsp), %esi
leaq 0x4259(%rip), %rdi      # 0xc403
xorl %eax, %eax
callq 0x2050
movq 0x158(%rbx), %rdi
leaq 0x8(%rsp), %rdx
movl $0x2, %esi
callq *0x318(%rbx)
testl %eax, %eax
je 0x81e8
movl 0x18(%rsp), %esi
shll $0x1e, %esi
sarl $0x1f, %esi
andl 0x14(%rsp), %esi
leaq 0x4231(%rip), %rdi      # 0xc412
xorl %eax, %eax
callq 0x2050
movq 0x158(%rbx), %rdi
callq *0x310(%rbx)
movl $0x1, %ebp
testl %eax, %eax
jne 0x8164
leaq 0x3c6e(%rip), %rdi      # 0xbe77
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x2506
jmp 0x8164
// File: /workspace/github_cpp_makefile_star2_O3/chenhn123[P]wdt_util_src/wdt_ct/wdt_dev_api.cpp
// Function: find_hid_dev_name(int, int, int, char*)
int find_hid_dev_name(int bus, int vid, int pid, char *device_name)
{
	int ret = 0;
	struct dirent * dev_dir_entry;
	DIR * dev_dir;
	char device_ids[32];

	snprintf(device_ids, 15, "%04X:%04X:%04X", bus, vid, pid);

	dev_dir = opendir("/sys/bus/hid/devices");
	if (!dev_dir) {
		printf("open dev dir failed !\n");
		return 0;
	}

	while ((dev_dir_entry = readdir(dev_dir)) != NULL) {
		if (!strncmp(dev_dir_entry->d_name, device_ids, 14)) {
			strcpy(device_name, dev_dir_entry->d_name);
			ret = 1;
			break;
		}
	}
	closedir(dev_dir);

	return ret;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x20, %rsp
movq %rcx, %rbx
movl %edx, %r9d
movl %esi, %r8d
movl %edi, %ecx
leaq 0x41ee(%rip), %rdx      # 0xc423
xorl %ebp, %ebp
movq %rsp, %rdi
movl $0xf, %esi
xorl %eax, %eax
callq 0x2290
leaq 0x41e5(%rip), %rdi      # 0xc432
callq 0x2250
testq %rax, %rax
je 0x8297
movq %rax, %r14
movq %rsp, %r15
movq %r14, %rdi
callq 0x2260
testq %rax, %rax
je 0x82a5
movq %rax, %r12
addq $0x13, %r12
movl $0xe, %edx
movq %r12, %rdi
movq %r15, %rsi
callq 0x20e0
testl %eax, %eax
jne 0x825d
movq %rbx, %rdi
movq %r12, %rsi
callq 0x2180
movl $0x1, %ebp
jmp 0x82a7
leaq 0x445a(%rip), %rdi      # 0xc6f8
callq 0x2270
jmp 0x82af
xorl %ebp, %ebp
movq %r14, %rdi
callq 0x22a0
movl %ebp, %eax
addq $0x20, %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/wdt_dev_api.cpp
// Function: write_devname_to_sys_attr(char const*, char const*)
int write_devname_to_sys_attr(const char *attr, const char *action)
{
	int fd;
	ssize_t size;

	fd = open(attr, O_WRONLY);
	if (fd < 0) {
		printf("%s: open file error !", __func__);
		return 0;
	}

	for (;;) {
		size = write(fd, action, strlen(action));
		if (size < 0) {
			if (errno == EINTR)
				continue;

			return 0;
		}
		break;
	}

	close(fd);

	return (size == (ssize_t) strlen(action));
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rsi, %rbx
xorl %ebp, %ebp
movl $0x1, %esi
xorl %eax, %eax
callq 0x2140
testl %eax, %eax
js 0x850e
movl %eax, %r14d
movq %rbx, %rdi
callq 0x20d0
movl %r14d, %edi
movq %rbx, %rsi
movq %rax, %rdx
callq 0x20b0
testq %rax, %rax
jns 0x8525
callq 0x2040
cmpl $0x4, (%rax)
je 0x84e5
xorl %ebp, %ebp
jmp 0x8541
leaq 0x3f73(%rip), %rdi      # 0xc488
leaq 0x3f82(%rip), %rsi      # 0xc49e
xorl %eax, %eax
callq 0x2050
jmp 0x8541
movq %rax, %r15
movl %r14d, %edi
callq 0x22e0
movq %rbx, %rdi
callq 0x20d0
xorl %ebp, %ebp
cmpq %rax, %r15
sete %bpl
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/wdt_dev_api.cpp
// Function: rebind_driver(WdtDevice*)
int rebind_driver(WDT_DEV *pdev)
{
	int 	bus = 0x18;
	int 	vendor = pdev->board_info.vid;
	int 	product = pdev->board_info.pid;
	char	hid_dev_name[64];
	char	driver_path[64];
	char	i2c_dev_name[64];
	char	attr_str[70];

	printf("Start to rebind driver !\n");

	if (!find_hid_dev_name(bus, vendor, product, hid_dev_name)) {
		printf("Not found hid device: 0x%x:0x%x:0x%x\n", bus, vendor, product);
		return 0;
	}



	strcpy(driver_path, "/sys/bus/i2c/drivers/");

	if (!find_device_name(hid_dev_name, i2c_dev_name, driver_path)) {
		printf("find device name failed %s\n", hid_dev_name);
		return 0;
	}


	sprintf(attr_str, "%s%s", driver_path, "unbind");


	if (!write_devname_to_sys_attr(attr_str, i2c_dev_name)) {
		printf("failed to unbind HID device %s %s\n", attr_str, i2c_dev_name);
		return 0;
	}
	
	wh_sleep(300);

	sprintf(attr_str, "%s%s", driver_path, "bind");

	if (!write_devname_to_sys_attr(attr_str, i2c_dev_name)) {
		printf("failed to bind HID device %s %s\n", attr_str, i2c_dev_name);
		return 0;
	}

	wh_sleep(300);

	printf("Rebind driver is done !\n");

	return 1;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
subq $0x110, %rsp            # imm = 0x110
movl 0x18c(%rdi), %ebp
movl 0x190(%rdi), %r14d
leaq 0x41a1(%rip), %rdi      # 0xc70e
callq 0x2270
leaq 0xd0(%rsp), %rcx
movl $0x18, %edi
movl %ebp, %esi
movl %r14d, %edx
callq 0x8217
testl %eax, %eax
je 0x8660
movups 0x3f46(%rip), %xmm0     # 0xc4de
leaq 0x90(%rsp), %rdx
movaps %xmm0, (%rdx)
movabsq $0x2f737265766972, %rax # imm = 0x2F737265766972
movq %rax, 0xe(%rdx)
leaq 0xd0(%rsp), %rdi
movq %rsp, %rsi
callq 0x82be
testl %eax, %eax
je 0x867c
leaq 0x3e95(%rip), %rsi      # 0xc465
leaq 0x3f39(%rip), %rcx      # 0xc510
xorl %ebx, %ebx
leaq 0x40(%rsp), %r14
leaq 0x90(%rsp), %rdx
movq %r14, %rdi
xorl %eax, %eax
callq 0x2080
movq %rsp, %rsi
movq %r14, %rdi
callq 0x84c6
testl %eax, %eax
je 0x8696
movl $0x12c, %edi            # imm = 0x12C
callq 0x259c
leaq 0x3e51(%rip), %rsi      # 0xc465
leaq 0x2ad4(%rip), %rcx      # 0xb0ef
xorl %ebx, %ebx
leaq 0x40(%rsp), %r14
leaq 0x90(%rsp), %rdx
movq %r14, %rdi
xorl %eax, %eax
callq 0x2080
movq %rsp, %rsi
movq %r14, %rdi
callq 0x84c6
testl %eax, %eax
je 0x869f
movl $0x12c, %edi            # imm = 0x12C
callq 0x259c
leaq 0x40d3(%rip), %rdi      # 0xc727
callq 0x2270
movl $0x1, %ebx
jmp 0x86b5
leaq 0x3e51(%rip), %rdi      # 0xc4b8
xorl %ebx, %ebx
movl $0x18, %esi
movl %ebp, %edx
movl %r14d, %ecx
xorl %eax, %eax
callq 0x2050
jmp 0x86b5
leaq 0x3e71(%rip), %rdi      # 0xc4f4
xorl %ebx, %ebx
leaq 0xd0(%rsp), %rsi
xorl %eax, %eax
callq 0x2050
jmp 0x86b5
leaq 0x3e7a(%rip), %rdi      # 0xc517
jmp 0x86a6
leaq 0x3e94(%rip), %rdi      # 0xc53a
leaq 0x40(%rsp), %rsi
movq %rsp, %rdx
xorl %eax, %eax
callq 0x2050
movl %ebx, %eax
addq $0x110, %rsp            # imm = 0x110
popq %rbx
popq %r14
popq %rbp
retq