LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_cpp_makefile_star2_O1/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 0x2(%rsp), %rsi
movq $0x0, -0x2(%rsi)
movw $0x0, 0x6(%rsi)
movw $0xd006, -0x2(%rsi)     # imm = 0xD006
movl %eax, %edi
callq 0x7032
movq %rsp, %rsi
movq %rbx, %rdi
callq 0x5199
movl $0x1, %ebx
testl %eax, %eax
jne 0x567c
leaq 0x64d1(%rip), %rdi      # 0xbb44
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x2506
movl %ebx, %eax
addq $0x10, %rsp
popq %rbx
retq
// File: /workspace/github_cpp_makefile_star2_O1/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 $0x20, %rsp
xorl %ebx, %ebx
testq %rsi, %rsi
je 0x57f0
movq %rsi, %r14
movq %rdi, %r15
movl $0x10, %esi
callq 0x562e
testl %eax, %eax
je 0x57f0
leaq 0x16(%rsp), %rsi
movw $0xd106, (%rsi)         # imm = 0xD106
movb $0x10, 0x2(%rsi)
xorl %ebx, %ebx
movl %ebx, 0x3(%rsi)
movl %ebx, 0x6(%rsi)
leaq 0x4(%rsp), %rcx
movq %r15, %rdi
xorl %r8d, %r8d
movl $0x10, %r9d
callq 0x53f0
testl %eax, %eax
je 0x57f0
leaq 0x8(%rsp), %r12
xorl %ebx, %ebx
xorl %edi, %edi
movq %r12, %rsi
xorl %edx, %edx
movl $0xc, %ecx
callq 0x8966
cmpw -0x2(%r12), %ax
jne 0x57f0
movl 0x8(%rsp), %eax
addl $-0x20, %eax
cmpl $0x3df, %eax            # imm = 0x3DF
ja 0x57f0
movq %r15, %rdi
movl $0x20, %esi
callq 0x562e
testl %eax, %eax
je 0x57f0
movl 0x8(%rsp), %r13d
leal 0x10(%r13), %edi
callq 0x21f0
testq %rax, %rax
je 0x57e4
movq %rax, %r12
movq %r15, %rdi
movl $0xd1, %esi
movq %rax, %rdx
xorl %ecx, %ecx
movl $0x1, %r8d
movl %r13d, %r9d
callq 0x54ad
movl %eax, %ebx
testl %eax, %eax
je 0x57da
movq %r12, %rdi
callq 0x702b
movl %eax, (%r14)
leaq 0x4(%r12), %rdi
callq 0x702b
movl %eax, 0x4(%r14)
leaq 0x8(%r12), %rdi
callq 0x702b
movl %eax, 0x8(%r14)
leaq 0xc(%r12), %rdi
callq 0x702b
movl %eax, 0xc(%r14)
movq %r12, %rdi
addq $0x10, %rdi
callq 0x702b
movl %eax, 0x10(%r14)
movq %r12, %rdi
callq 0x21e0
jmp 0x57f0
leaq 0x65d4(%rip), %rdi      # 0xbdbf
callq 0x2270
movl %ebx, %eax
addq $0x20, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
// File: /workspace/github_cpp_makefile_star2_O1/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
movl $0x1, %ebx
testb $0x1, 0x188(%rdi)
jne 0x5868
movq %rdi, %r14
testl %edx, %edx
movl $0x64, %r12d
cmovnel %edx, %r12d
testl %ecx, %ecx
movl $0x5, %r13d
cmovnel %ecx, %r13d
imull $0x3e8, %r13d, %ebp     # imm = 0x3E8
movzbl %sil, %r15d
movq %r14, %rdi
movl %r15d, %esi
callq 0x5879
movq %r14, %rdi
callq 0x55a5
cmpl %r15d, %eax
je 0x5868
movl %ebp, %edi
callq 0x2230
subl %r13d, %r12d
testl %r12d, %r12d
jg 0x583f
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_O1/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:
pushq %rbx
subq $0x10, %rsp
movq %rsp, %rax
movq $0x0, (%rax)
movw $0x0, 0x8(%rax)
movw $0xca06, (%rax)         # imm = 0xCA06
movb %sil, 0x2(%rax)
movq %rax, %rsi
callq 0x5199
movl $0x1, %ebx
testl %eax, %eax
jne 0x58b8
leaq 0x6295(%rip), %rdi      # 0xbb44
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x2506
movl %ebx, %eax
addq $0x10, %rsp
popq %rbx
retq
// File: /workspace/github_cpp_makefile_star2_O1/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
movq %rsp, %rsi
movq $0x0, (%rsi)
movw $0x0, 0x8(%rsi)
movw $0xcd06, (%rsi)         # imm = 0xCD06
leaq 0x10(%rsp), %rcx
xorl %ebp, %ebp
xorl %r8d, %r8d
movl $0xa, %r9d
callq 0x53f0
testl %eax, %eax
je 0x5941
leaq 0x10(%rsp), %rdi
callq 0x7027
movw %ax, (%rbx)
leaq 0x12(%rsp), %rdi
callq 0x7027
movw %ax, 0x2(%rbx)
leaq 0x14(%rsp), %rdi
callq 0x7027
movw %ax, 0x4(%rbx)
leaq 0x16(%rsp), %rdi
callq 0x7027
movw %ax, 0x6(%rbx)
leaq 0x18(%rsp), %rdi
callq 0x7027
movw %ax, 0x8(%rbx)
movl $0x1, %ebp
movl %ebp, %eax
addq $0x58, %rsp
popq %rbx
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O1/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
movl $0x3f, %eax
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 0x5199
addq $0x40, %rsp
popq %rbx
retq
// File: /workspace/github_cpp_makefile_star2_O1/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 %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movl %ecx, %r15d
movl %edx, %ebp
movq %rdi, %rbx
cmpl $0x40, %ecx
movq %rsi, 0x8(%rsp)
jl 0x5a30
leaq 0x11(%rsp), %r13
movslq %ebp, %r14
addq %rsi, %r14
leaq 0x10(%rsp), %r12
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movaps %xmm0, 0x40(%rsp)
movaps %xmm0, 0x30(%rsp)
movaps %xmm0, 0x20(%rsp)
movb $0xb, 0x10(%rsp)
movups (%r14), %xmm0
movups 0x10(%r14), %xmm1
movups 0x20(%r14), %xmm2
movups 0x2f(%r14), %xmm3
movups %xmm3, 0x2f(%r13)
movups %xmm2, 0x20(%r13)
movups %xmm1, 0x10(%r13)
movups %xmm0, (%r13)
movq %rbx, %rdi
movq %r12, %rsi
callq 0x5199
testl %eax, %eax
jle 0x5a84
leal -0x3f(%r15), %eax
addq $0x3f, %r14
addl $0x3f, %ebp
cmpl $0x7e, %r15d
movl %eax, %r15d
jg 0x59c8
jmp 0x5a33
movl %r15d, %eax
testl %eax, %eax
jle 0x5a7d
xorps %xmm0, %xmm0
leaq 0x11(%rsp), %rdi
movaps %xmm0, -0x1(%rdi)
movaps %xmm0, 0x2f(%rdi)
movaps %xmm0, 0x1f(%rdi)
cmpl $0x3f, %eax
movl $0x3f, %edx
cmovll %eax, %edx
movaps %xmm0, 0xf(%rdi)
movb $0xb, -0x1(%rdi)
movslq %ebp, %rax
movq 0x8(%rsp), %rsi
addq %rax, %rsi
callq 0x2150
leaq 0x10(%rsp), %rsi
movq %rbx, %rdi
callq 0x5199
jmp 0x5a86
movl $0x1, %eax
jmp 0x5a86
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O1/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 0x51de
testl %eax, %eax
jle 0x5af0
cmpl $0x3f, %r14d
movl $0x3f, %eax
cmovll %r14d, %eax
movslq %ebp, %rcx
addq %rcx, %rbx
leaq 0x1(%rsp), %rsi
movslq %eax, %rdx
movq %rbx, %rdi
callq 0x2150
movl $0x1, %eax
jmp 0x5af2
xorl %eax, %eax
addq $0x40, %rsp
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O1/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 %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movl %ecx, %r15d
movl %edx, %ebp
movq %rdi, %r14
cmpl $0x40, %ecx
movq %rsi, 0x8(%rsp)
jl 0x5b90
leaq 0x11(%rsp), %r13
movslq %ebp, %rbx
addq %rsi, %rbx
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movaps %xmm0, 0x40(%rsp)
movaps %xmm0, 0x30(%rsp)
movaps %xmm0, 0x20(%rsp)
movb $0xb, 0x10(%rsp)
movq %r14, %rdi
leaq 0x10(%rsp), %rsi
callq 0x51de
testl %eax, %eax
jle 0x5be7
movups (%r13), %xmm0
movups 0x10(%r13), %xmm1
movups 0x20(%r13), %xmm2
movups 0x2f(%r13), %xmm3
movups %xmm3, 0x2f(%rbx)
movups %xmm2, 0x20(%rbx)
movups %xmm1, 0x10(%rbx)
movups %xmm0, (%rbx)
leal -0x3f(%r15), %r12d
addq $0x3f, %rbx
addl $0x3f, %ebp
cmpl $0x7e, %r15d
movl %r12d, %r15d
jg 0x5b26
jmp 0x5b93
movl %r15d, %r12d
testl %r12d, %r12d
jle 0x5be0
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %rsi
movaps %xmm0, (%rsi)
movaps %xmm0, 0x30(%rsi)
movaps %xmm0, 0x20(%rsi)
movaps %xmm0, 0x10(%rsi)
movb $0xb, (%rsi)
movq %r14, %rdi
callq 0x51de
testl %eax, %eax
jle 0x5be7
cmpl $0x3f, %r12d
movl $0x3f, %edx
cmovll %r12d, %edx
movslq %ebp, %rax
movq 0x8(%rsp), %rdi
addq %rax, %rdi
leaq 0x11(%rsp), %rsi
callq 0x2150
movl $0x1, %eax
jmp 0x5be9
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O1/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
callq 0x5199
movl $0x1, %ebx
testl %eax, %eax
jne 0x5c5a
leaq 0x5ef3(%rip), %rdi      # 0xbb44
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x2506
movl %ebx, %eax
addq $0x40, %rsp
popq %rbx
retq
// File: /workspace/github_cpp_makefile_star2_O1/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 %r9d, %ebx
movl %r8d, %ebp
movl %ecx, %r14d
movq %rdx, 0x10(%rsp)
movl %esi, 0xc(%rsp)
movq %rdi, %r13
movl $0x3d, %eax
xorl %edx, %edx
idivl %r8d
cmpl %r9d, %eax
jg 0x5cc7
movl %eax, %r15d
movl %eax, %r12d
imull %ebp, %r12d
movq %r13, %rdi
movl 0xc(%rsp), %esi
movq 0x10(%rsp), %rdx
movl %r14d, %ecx
movl %ebp, %r8d
movl %r15d, %r9d
callq 0x5bf8
testl %eax, %eax
je 0x5cfa
addl %r12d, %r14d
subl %r15d, %ebx
cmpl %r15d, %ebx
jge 0x5c9e
testl %ebx, %ebx
jle 0x5cf3
movq %r13, %rdi
movl 0xc(%rsp), %esi
movq 0x10(%rsp), %rdx
movl %r14d, %ecx
movl %ebp, %r8d
movl %ebx, %r9d
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x5bf8
movl $0x1, %eax
jmp 0x5cfc
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_O1/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 $0x28, %rsp
movl %edx, %ebx
movl %esi, %ebp
movq %rdi, %r14
leaq 0xc(%rsp), %rax
movl $0x0, (%rax)
callq 0x25ac
movq %rax, 0x20(%rsp)
testl %ebp, %ebp
movl $0x1388, %r15d          # imm = 0x1388
cmovnel %ebp, %r15d
testl %ebx, %ebx
movl $0xa, %r12d
cmovnel %ebx, %r12d
movl %r12d, %ebp
imull %r15d, %ebp
movl %r12d, %ebx
imull %r12d, %ebx
xorl %r13d, %r13d
movq $0x0, 0x10(%rsp)
movw $0x0, 0x18(%rsp)
movl $0x100c906, 0x10(%rsp)  # imm = 0x100C906
movq %r14, %rdi
leaq 0x10(%rsp), %rsi
leaq 0xc(%rsp), %rcx
xorl %r8d, %r8d
movl $0x1, %r9d
callq 0x53f0
testl %eax, %eax
je 0x5df4
testb $0x1, 0xc(%rsp)
je 0x5dca
movl %r12d, %edi
callq 0x259c
subl %r12d, %r15d
subl %ebx, %ebp
testl %r15d, %r15d
jg 0x5d5e
leaq 0x5b3a(%rip), %rdi      # 0xb8ef
leaq 0x5daf(%rip), %rsi      # 0xbb6b
xorl %r13d, %r13d
movl %ebp, %edx
xorl %eax, %eax
callq 0x2506
jmp 0x5df4
callq 0x25ac
movl $0x1, %r13d
subq 0x20(%rsp), %rax
je 0x5df4
leaq 0x5d76(%rip), %rdi      # 0xbb59
leaq 0x5d81(%rip), %rsi      # 0xbb6b
movq %rax, %rdx
xorl %eax, %eax
callq 0x2506
movl %r13d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O1/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 %rbx
subq $0x10, %rsp
movq %rdi, %rbx
movq %rsp, %rax
movq $0x0, (%rax)
movw $0x0, 0x8(%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 0x5199
testl %eax, %eax
je 0x5ec8
movq %rbx, %rdi
movl $0x1770, %esi           # imm = 0x1770
xorl %edx, %edx
callq 0x5d0b
movl %eax, %ebx
jmp 0x5ed8
leaq 0x5c75(%rip), %rdi      # 0xbb44
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x2506
movl %ebx, %eax
addq $0x10, %rsp
popq %rbx
retq
// File: /workspace/github_cpp_makefile_star2_O1/chenhn123[P]wdt_util_src/wdt_ct/w8790_funcs.cpp
// Function: wh_w8790_dev_write_flash_cmd(WdtDevice*, unsigned char*, int, int)
int wh_w8790_dev_write_flash_cmd(WDT_DEV* pdev, BYTE* buf, int start, int size)
{
	if (size > W8790_USB_MAX_PAYLOAD_SIZE - 2) {
		wh_printf("%s: payload data overrun\n", __FUNCTION__);
		return 0;
	}

	BYTE cmd[W8790_USB_MAX_PAYLOAD_SIZE + 1] = { 0 };

	cmd[0] = W8790_COMMAND63;
	cmd[1] = (BYTE)W8790_WRITE_FLASH;
	cmd[2] = (BYTE)size;
	memcpy(&cmd[3], &buf[start], size);

	if (wh_w8790_dev_command_write(pdev, cmd, 0, size + 3) > 0)
		return wh_w8790_dev_wait_cmd_end(pdev, 0, 0);
	wh_printf("w8790_write_cmd fail \n)");
	return 0;
}

// Assembly:
pushq %rbx
subq $0x40, %rsp
cmpl $0x3e, %ecx
jl 0x5f03
leaq 0x5a33(%rip), %rdi      # 0xb924
leaq 0x5c8d(%rip), %rsi      # 0xbb85
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x2506
jmp 0x5f72
movq %rdi, %rbx
xorps %xmm0, %xmm0
leaq 0x3(%rsp), %rdi
movaps %xmm0, -0x3(%rdi)
movaps %xmm0, 0x2d(%rdi)
movaps %xmm0, 0x1d(%rdi)
movaps %xmm0, 0xd(%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 0x5199
testl %eax, %eax
je 0x5f54
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x5d0b
movl %eax, %ebx
jmp 0x5f72
leaq 0x5be9(%rip), %rdi      # 0xbb44
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x2506
leaq 0x5c37(%rip), %rdi      # 0xbba2
xorl %eax, %eax
callq 0x2506
movl %ebx, %eax
addq $0x40, %rsp
popq %rbx
retq
// File: /workspace/github_cpp_makefile_star2_O1/chenhn123[P]wdt_util_src/wdt_ct/w8790_funcs.cpp
// Function: wh_w8790_dev_write_flash(WdtDevice*, int, unsigned char*, int, int)
int wh_w8790_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 = W8790_USB_MAX_PAYLOAD_SIZE - 2;
	int cur_addr = 0xFFFFFFFF;

	while (byte_count >= max_payload_size) {
		if ((addr & 0xfff) == 0)
			printf("base addr: 0x%x\n", addr);
		if (!check_is_all_ff(&buf[offset], max_payload_size)) {
			if (cur_addr != addr) {
				if (!wh_w8790_dev_set_flash_address(pdev, addr))
					return 0;
			}
			if (wh_w8790_dev_write_flash_cmd(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_w8790_dev_set_flash_address(pdev, addr))
			return 0;
	}
	if (byte_count > 0) {
		if ((addr & 0xfff) == 0)
			wh_printf("base addr: 0x%x\n", addr);
		return wh_w8790_dev_write_flash_cmd(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, %r13d
movl %ecx, %ebx
movl %esi, %r12d
movq %rdi, 0x8(%rsp)
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
cmpl $0x3d, %r8d
movq %rdx, 0x10(%rsp)
jl 0x6045
movslq %ebx, %rbp
addq %rdx, %rbp
testl $0xfff, %r12d           # imm = 0xFFF
jne 0x5fca
leaq 0x54f9(%rip), %rdi      # 0xb4b9
movl %r12d, %esi
xorl %eax, %eax
callq 0x2050
movq %rbp, %rdi
movl $0x3d, %esi
callq 0x7035
testl %eax, %eax
je 0x5fee
leaq 0x597b(%rip), %rdi      # 0xb95d
movl %r12d, %esi
xorl %eax, %eax
callq 0x2506
jmp 0x6027
cmpl %r15d, %r12d
je 0x6008
movq 0x8(%rsp), %rdi
movl %r12d, %esi
callq 0x562e
testl %eax, %eax
je 0x609f
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
movl %ebx, %edx
movl $0x3d, %ecx
callq 0x5ee0
testl %eax, %eax
je 0x609f
leal 0x3d(%r12), %r15d
leal -0x3d(%r13), %r14d
addl $0x3d, %r12d
addq $0x3d, %rbp
addl $0x3d, %ebx
cmpl $0x79, %r13d
movl %r14d, %r13d
jg 0x5fb0
jmp 0x6048
movl %r13d, %r14d
cmpl %r12d, %r15d
je 0x605e
movq 0x8(%rsp), %rdi
movl %r12d, %esi
callq 0x562e
testl %eax, %eax
je 0x609f
testl %r14d, %r14d
jle 0x60a3
testl $0xfff, %r12d           # imm = 0xFFF
jne 0x607d
leaq 0x5446(%rip), %rdi      # 0xb4b9
movl %r12d, %esi
xorl %eax, %eax
callq 0x2506
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
movl %ebx, %edx
movl %r14d, %ecx
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x5ee0
xorl %eax, %eax
jmp 0x60a8
movl $0x1, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O1/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 0x6117
movl $0x100, %r13d           # imm = 0x100
subl %eax, %r13d
movl %r13d, %eax
subl %r12d, %eax
movl %r12d, %r8d
cmovll %r13d, %r8d
negl %eax
xorl %ecx, %ecx
cmpl %r13d, %r12d
movl %eax, %r12d
cmovlel %ecx, %r12d
movq %r15, %rdi
movl %ebx, %esi
movq %r14, %rdx
xorl %ecx, %ecx
callq 0x5f7a
testl %eax, %eax
cmovel %eax, %r13d
je 0x6178
addl %r13d, %ebx
addq %r13, %r14
movl $0x1, %eax
testl %r12d, %r12d
je 0x6178
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 0x5f7a
testl %eax, %eax
je 0x6176
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 0x6129
movl $0x1, %eax
jmp 0x6178
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O1/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 0x702e
leaq 0xc(%rsp), %rsi
xorl $0xffff, %ebx           # imm = 0xFFFF
movl %ebx, %edi
callq 0x702e
leaq 0x8(%rsp), %rsi
movq %r14, %rdi
callq 0x5199
movl $0x1, %ebx
testl %eax, %eax
jne 0x61e5
leaq 0x5968(%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_O1/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 %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %r8d, %r15d
movl %ecx, %r12d
movq %rsi, %rbx
movq %rdi, %r14
xorl %ebp, %ebp
leaq 0x18(%rsp), %r13
movw %bp, (%r13)
movq $0x0, -0x8(%r13)
movw %bp, 0xe(%rsp)
movl $0x0, (%rsi)
movw $0xd506, -0x8(%r13)     # imm = 0xD506
leaq 0x12(%rsp), %rsi
movl %edx, %edi
callq 0x7032
leaq 0x15(%rsp), %rsi
movl %r12d, %edi
callq 0x7032
movzwl %r15w, %edi
movq %r13, %rsi
callq 0x702e
leaq 0x10(%rsp), %rsi
movq %r14, %rdi
callq 0x5199
testl %eax, %eax
je 0x62bb
movq %r14, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x5d0b
testl %eax, %eax
je 0x62cb
leaq 0x1e(%rsp), %rsi
movw $0xc706, (%rsi)         # imm = 0xC706
movb $0x2, 0x2(%rsi)
xorl %ebp, %ebp
movl %ebp, 0x3(%rsi)
movl %ebp, 0x6(%rsi)
leaq 0xe(%rsp), %rcx
movq %r14, %rdi
xorl %r8d, %r8d
movl $0x2, %r9d
callq 0x53f0
testl %eax, %eax
je 0x62cb
leaq 0xe(%rsp), %rdi
callq 0x7027
movzwl %ax, %eax
movl %eax, (%rbx)
movl $0x1, %ebp
jmp 0x62cb
leaq 0x5882(%rip), %rdi      # 0xbb44
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x2506
movl %ebp, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O1/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 $0x20, %rsp
movq %rcx, %r14
movl %esi, %ebp
xorl %ebx, %ebx
leaq 0xc(%rsp), %rcx
movl %ebx, (%rcx)
leaq 0x10(%rsp), %rsi
movw $0x0, 0x8(%rsi)
movq $0x0, (%rsi)
movl %ebx, (%r14)
movw $0xe006, (%rsi)         # imm = 0xE006
movb %bpl, 0x2(%rsi)
movb %dl, 0x3(%rsi)
movb %dh, 0x14(%rsp)
shrl $0x10, %edx
movb %dl, 0x5(%rsi)
xorl %r8d, %r8d
movl $0x4, %r9d
callq 0x53f0
testl %eax, %eax
je 0x6356
movl $0x1, %ebx
cmpb %bpl, 0xc(%rsp)
jne 0x636b
movzwl 0xd(%rsp), %ecx
movzbl 0xf(%rsp), %eax
shll $0x10, %eax
orl %ecx, %eax
cmpl $0xffffff, %eax         # imm = 0xFFFFFF
je 0x636b
movl %eax, (%r14)
jmp 0x636b
leaq 0x585d(%rip), %rdi      # 0xbbba
leaq 0x5864(%rip), %rsi      # 0xbbc8
xorl %eax, %eax
callq 0x2506
movl %ebx, %eax
addq $0x20, %rsp
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O1/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
xorl %r14d, %r14d
leaq 0x12(%rsp), %rsi
movq %r14, -0x2(%rsi)
movw $0x0, 0x6(%rsi)
movq %r14, 0x8(%rsp)
movw $0xe306, -0x2(%rsi)     # imm = 0xE306
movl %edx, %edi
callq 0x7032
leaq 0x15(%rsp), %rsi
movzwl %bp, %edi
callq 0x702e
leaq 0x10(%rsp), %rsi
movq %r15, %rdi
callq 0x5199
testl %eax, %eax
je 0x642e
movq %r15, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x5d0b
testl %eax, %eax
je 0x643f
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 0x53f0
testl %eax, %eax
je 0x643f
leaq 0x8(%rsp), %rdi
callq 0x7027
movzwl %ax, %eax
movl %eax, (%rbx)
movl $0x1, %r14d
jmp 0x643f
leaq 0x570f(%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_O1/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 0x646c
movl %ebx, %eax
orl %edx, %eax
testb $0x3, %al
je 0x6474
xorl %eax, %eax
popq %rbx
popq %r14
popq %r15
retq
movq %rsi, %r14
movq %rdi, %r15
movl %edx, %esi
callq 0x562e
testl %eax, %eax
je 0x646c
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 0x54ad
// File: /workspace/github_cpp_makefile_star2_O1/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 0x65ae
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %edx, %ebp
movq %rsi, %r14
movq %rdi, %r15
movl %ecx, %r12d
leal -0x1000(%r12), %eax
cmpl $0x1001, %ecx           # imm = 0x1001
movl $0x0, %ecx
cmovll %ecx, %eax
movl %eax, (%rsp)
movl $0x1000, %eax           # imm = 0x1000
cmpl %eax, %r12d
cmovgel %eax, %r12d
xorl %ebx, %ebx
testl %ebx, %ebx
je 0x6502
movq %r15, %rdi
movl %ebp, %esi
movl $0x1000, %edx           # imm = 0x1000
callq 0x673a
movq %r15, %rdi
movq %r14, %rsi
movl %ebp, %edx
movl %r12d, %ecx
callq 0x60b7
testl %eax, %eax
je 0x655a
xorl %edi, %edi
movq %r14, %rsi
xorl %edx, %edx
movl %r12d, %ecx
callq 0x8966
movzwl %ax, %r13d
movq %r15, %rdi
leaq 0x4(%rsp), %rsi
movl %ebp, %edx
movl %r12d, %ecx
xorl %r8d, %r8d
callq 0x61ef
movl 0x4(%rsp), %edx
cmpl %r13d, %edx
je 0x6566
leaq 0x5120(%rip), %rdi      # 0xb66e
movl %ebx, %esi
movl %r13d, %ecx
xorl %eax, %eax
callq 0x2050
incl %ebx
cmpl $0x3, %ebx
jne 0x64ef
movl $0x3, %ebx
cmpl $0x3, %ebx
je 0x6586
addl %r12d, %ebp
movslq %r12d, %rax
addq %rax, %r14
movl (%rsp), %ecx
testl %ecx, %ecx
jne 0x64c5
movl $0x1, %eax
jmp 0x65a0
leaq 0x5224(%rip), %rdi      # 0xb7b1
callq 0x2270
leaq 0x5231(%rip), %rdi      # 0xb7ca
callq 0x2270
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O1/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 0x8(%rsp), %rsi
movq $0x0, (%rsi)
movw $0x0, 0x8(%rsi)
movw $0xc806, (%rsi)         # imm = 0xC806
movb %dl, 0x2(%rsi)
movb %r9b, 0x3(%rsi)
xorl %r8d, %r8d
callq 0x53f0
addq $0x18, %rsp
retq
// File: /workspace/github_cpp_makefile_star2_O1/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 0x5e73
movl %eax, %r14d
testl %eax, %eax
jne 0x6767
leaq 0x5281(%rip), %rdi      # 0xb9d6
leaq 0x548a(%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_O1/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 0xa(%rsp), %rsi
movq $0x0, -0x2(%rsi)
movw $0x0, 0x6(%rsi)
movw $0xdf06, -0x2(%rsi)     # imm = 0xDF06
movl %eax, %edi
callq 0x7032
leaq 0xe(%rsp), %rsi
movl %ebx, %edi
callq 0x7032
leaq 0x8(%rsp), %rsi
movq %r14, %rdi
callq 0x5199
movl $0x1, %ebx
testl %eax, %eax
jne 0x67cf
leaq 0x537e(%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_O1/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 0x702b
movl %eax, %r14d
shlq $0x20, %r14
leaq 0x8(%rbx), %rdi
callq 0x702b
movl %eax, %ebp
orq %r14, %rbp
leaq 0x4(%rbx), %rdi
callq 0x702b
movl %eax, %r14d
movq %r14, %r13
shlq $0x20, %r13
leaq 0x2(%rbx), %rdi
callq 0x7027
movl %eax, %r12d
movl %r12d, %r15d
shll $0x10, %r15d
orq %r13, %r15
movq %rbx, %rdi
callq 0x7027
movl %eax, %r13d
movzwl %ax, %edi
orq %r15, %rdi
movq %rbp, %rsi
callq 0x67d9
cmpw %ax, %r12w
jne 0x68a9
movslq (%rsp), %rax
addq %r14, %rax
addq $0x10, %rax
movl 0x4(%rsp), %ecx
cmpq %rcx, %rax
jbe 0x68ca
leaq 0x5372(%rip), %rdi      # 0xbc19
jmp 0x68b0
leaq 0x534f(%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 0x6927
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 0x8966
movl $0x1, %ebx
cmpw %ax, %r13w
je 0x691d
leaq 0x532e(%rip), %rdi      # 0xbc42
xorl %eax, %eax
callq 0x2506
xorl %ebx, %ebx
movq %r15, %rdi
callq 0x21e0
jmp 0x68b9
leaq 0x5305(%rip), %rdi      # 0xbc33
jmp 0x68b0
// File: /workspace/github_cpp_makefile_star2_O1/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 0x6dad
movq %rsi, %rbx
movq %rdi, %r14
callq 0x52dd
testl %eax, %eax
je 0x6d99
cmpb $0x49, 0x220(%r14)
jne 0x6d12
cmpb $0x53, 0x221(%r14)
jne 0x6d12
cmpb $0x50, 0x222(%r14)
jne 0x6d12
movl $0x201, (%rbx)          # imm = 0x201
leaq 0x508e(%rip), %rdi      # 0xbd94
xorl %eax, %eax
callq 0x2506
jmp 0x6d92
leaq 0xa(%rsp), %rsi
movq %r14, %rdi
callq 0x5347
testl %eax, %eax
je 0x6dab
movzbl 0xc(%rsp), %eax
movw %ax, 0x24(%rbx)
movzbl 0xe(%rsp), %eax
movw %ax, 0x28(%rbx)
movzbl 0xf(%rsp), %eax
movw %ax, 0x2a(%rbx)
movzbl 0xb(%rsp), %eax
movw %ax, 0x26(%rbx)
movzbl 0x10(%rsp), %eax
movw %ax, 0x2c(%rbx)
movzbl 0x11(%rsp), %eax
movw %ax, 0x2e(%rbx)
movw $0x0, 0x22(%rbx)
leaq 0x18(%rsp), %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0x58c0
movq (%r15), %rsi
movl 0x8(%r15), %edx
leaq 0x14(%rsp), %r15
movq %r14, %rdi
movq %r15, %rcx
callq 0x6930
movzwl (%r15), %eax
movw %ax, 0x20(%rbx)
movl $0x1, %ebp
jmp 0x6dad
leaq 0x4fd6(%rip), %rdi      # 0xbd76
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x2506
jmp 0x6dad
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x28, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O1/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 0x6e09
leaq 0x2008(%rip), %rax      # 0x8ddd
movq %rax, (%rsi)
leaq 0x20ed(%rip), %rax      # 0x8ecc
movq %rax, 0x8(%rsi)
leaq 0x2115(%rip), %rax      # 0x8eff
movq %rax, 0x10(%rsi)
leaq 0x21da(%rip), %rax      # 0x8fcf
movq %rax, 0x18(%rsi)
leaq 0x235f(%rip), %rax      # 0x915f
movq %rax, 0x20(%rsi)
movl $0x1, %eax
retq