// File: /workspace/github_cpp_makefile_star2_O2/goodix[P]gdix_hid_firmware_update/gtx9/gtx9.cpp
// Function: GTx9Device::SendConfig(unsigned char*, int)
int GTx9Device::SendConfig(unsigned char *config, int len)
{
	int ret;
	uint8_t cmdBuf[5] = {0};
	uint8_t tmpBuf[4096] = {0};

	/* start write cfg */
	cmdBuf[0] = 0x04;
	ret = WriteSpeCmd(cmdBuf, 1);
	if (ret < 0) {
		gdix_err("Failed write cfg prepare cmd\n");
		return ret;
	}

	/* try send config */
	ret = Write(0x13B74, config, len);
	if (ret < 0) {
		gdix_err("Failed write config data\n");
		goto exit;
	}

	/* read back config */
	ret = Read(0x13B74, tmpBuf, len);
	if (ret < 0) {
		gdix_err("Failed read back config\n");
		goto exit;
	}

	if (memcmp(config, tmpBuf, len)) {
		gdix_err("Config data read back compare file\n");
		ret = -EINVAL;
		goto exit;
	}
	cmdBuf[0] = 0x05;
	ret = WriteSpeCmd(cmdBuf, 1);
	if (ret < 0)
		gdix_err("Failed send config data ready cmd\n");

exit:
	cmdBuf[0] = 0x06;
	ret = WriteSpeCmd(cmdBuf, 1);
	if (ret < 0)
		gdix_err("Failed send config write end command\n");

	return ret;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x1010, %rsp           # imm = 0x1010
movl %edx, %r15d
movq %rsi, %r14
movq %rdi, %rbx
leaq 0xb(%rsp), %r12
andl $0x0, 0x1(%r12)
leaq 0x10(%rsp), %rdi
movl $0x1000, %edx           # imm = 0x1000
xorl %esi, %esi
callq 0x5080
movb $0x4, (%r12)
movq (%rbx), %rax
pushq $0x1
popq %rdx
movq %rbx, %rdi
movq %r12, %rsi
callq *0x40(%rax)
testl %eax, %eax
js 0xf506
movq (%rbx), %rax
movq %rbx, %rdi
movl $0x13b74, %esi          # imm = 0x13B74
movq %r14, %rdx
movl %r15d, %ecx
callq *0x30(%rax)
testl %eax, %eax
js 0xf53a
movq (%rbx), %rax
leaq 0x10(%rsp), %rdx
movq %rbx, %rdi
movl $0x13b74, %esi          # imm = 0x13B74
movl %r15d, %ecx
callq *0x20(%rax)
testl %eax, %eax
js 0xf565
movslq %r15d, %rdx
leaq 0x10(%rsp), %rsi
movq %r14, %rdi
callq 0x50f0
testl %eax, %eax
je 0xf597
leaq 0x10db6(%rip), %rax     # 0x20291
cmpb $0x1, (%rax)
jne 0xf5bb
movq 0x10aed(%rip), %rax     # 0x1ffd8
movq (%rax), %rdi
leaq 0x8746(%rip), %rsi      # 0x17c3b
leaq 0x86df(%rip), %rdx      # 0x17bdb
movl $0x10c, %ecx            # imm = 0x10C
jmp 0xf58e
movl %eax, %ebp
leaq 0x10d82(%rip), %rax     # 0x20291
cmpb $0x1, (%rax)
jne 0xf5e1
movq 0x10ab9(%rip), %rax     # 0x1ffd8
movq (%rax), %rdi
leaq 0x8683(%rip), %rsi      # 0x17bac
leaq 0x86ab(%rip), %rdx      # 0x17bdb
movl $0xf9, %ecx
jmp 0xf610
leaq 0x10d50(%rip), %rax     # 0x20291
cmpb $0x1, (%rax)
jne 0xf5bb
movq 0x10a8b(%rip), %rax     # 0x1ffd8
movq (%rax), %rdi
leaq 0x868f(%rip), %rsi      # 0x17be6
leaq 0x867d(%rip), %rdx      # 0x17bdb
movl $0x100, %ecx            # imm = 0x100
jmp 0xf58e
leaq 0x10d25(%rip), %rax     # 0x20291
cmpb $0x1, (%rax)
jne 0xf5bb
movq 0x10a60(%rip), %rax     # 0x1ffd8
movq (%rax), %rdi
leaq 0x868f(%rip), %rsi      # 0x17c11
leaq 0x8652(%rip), %rdx      # 0x17bdb
movl $0x107, %ecx            # imm = 0x107
xorl %eax, %eax
callq 0x5180
jmp 0xf5bb
leaq 0xb(%rsp), %rsi
movb $0x5, (%rsi)
movq (%rbx), %rax
pushq $0x1
popq %rdx
movq %rbx, %rdi
callq *0x40(%rax)
testl %eax, %eax
jns 0xf5bb
leaq 0x10cdb(%rip), %rax     # 0x20291
cmpb $0x1, (%rax)
je 0xf619
leaq 0xb(%rsp), %rsi
movb $0x6, (%rsi)
movq (%rbx), %rax
pushq $0x1
popq %rdx
movq %rbx, %rdi
callq *0x40(%rax)
movl %eax, %ebp
testl %eax, %eax
jns 0xf5e1
leaq 0x10cb5(%rip), %rax     # 0x20291
cmpb $0x1, (%rax)
je 0xf5f3
movl %ebp, %eax
addq $0x1010, %rsp           # imm = 0x1010
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq 0x109de(%rip), %rax     # 0x1ffd8
movq (%rax), %rdi
leaq 0x86a0(%rip), %rsi      # 0x17ca4
leaq 0x85d0(%rip), %rdx      # 0x17bdb
movl $0x119, %ecx            # imm = 0x119
xorl %eax, %eax
callq 0x5180
jmp 0xf5e1
movq 0x109b8(%rip), %rax     # 0x1ffd8
movq (%rax), %rdi
leaq 0x8646(%rip), %rsi      # 0x17c70
leaq 0x85aa(%rip), %rdx      # 0x17bdb
movl $0x113, %ecx            # imm = 0x113
jmp 0xf58e
nop