// File: /workspace/github_cpp_makefile_star2_O2/goodix[P]gdix_hid_firmware_update/gtx9/gtx9_i2c_update.cpp
// Function: gdix_read_version(goodix_fw_version*)
static int gdix_read_version(struct goodix_fw_version *version)
{
	int ret;
	uint8_t temp_pid[8] = {0};
	uint8_t buf[sizeof(struct goodix_fw_version)] = {0};

	ret = i2c_read(0x10014, buf, sizeof(buf));
	if (ret < 0) {
		gdix_err("read version failed\n");
		return ret;
	}

	if (checksum_cmp(buf, sizeof(buf), CHECKSUM_MODE_U8_LE)) {
		gdix_err("invalid fw version, checksum err\n");
		return -1;
	}

	memcpy(version, buf, sizeof(*version));
	memcpy(temp_pid, version->rom_pid, sizeof(version->rom_pid));
	gdix_dbg("rom_pid:%s\n", temp_pid);
	gdix_dbg("rom_vid:%*ph\n", (int)sizeof(version->rom_vid), version->rom_vid);
	gdix_dbg("pid:%s\n", version->patch_pid);
	gdix_dbg("vid:%*ph\n", (int)sizeof(version->patch_vid), version->patch_vid);
	gdix_dbg("sensor_id:%d\n", version->sensor_id);

	return 0;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
subq $0x30, %rsp
movq %rdi, %rbx
andq $0x0, 0x8(%rsp)
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %rsi
movups %xmm0, 0xc(%rsi)
movaps %xmm0, (%rsi)
pushq $0x1c
popq %rdx
movl $0x10014, %edi          # imm = 0x10014
callq 0x113f6
testl %eax, %eax
js 0x1128c
leaq 0x10(%rsp), %rdi
pushq $0x1c
popq %rsi
xorl %edx, %edx
callq 0x10068
testl %eax, %eax
je 0x112c8
leaq 0xf030(%rip), %rax      # 0x20291
pushq $-0x1
popq %rbp
cmpb $0x1, (%rax)
jne 0x113eb
movq 0xed64(%rip), %rax      # 0x1ffd8
movq (%rax), %rdi
leaq 0x7237(%rip), %rsi      # 0x184b5
leaq 0x721e(%rip), %rdx      # 0x184a3
movl $0x1ce, %ecx            # imm = 0x1CE
jmp 0x112bc
leaq 0xeffe(%rip), %rax      # 0x20291
pushq $-0x1
popq %rbp
cmpb $0x1, (%rax)
jne 0x113eb
movq 0xed32(%rip), %rax      # 0x1ffd8
movq (%rax), %rdi
leaq 0x71cd(%rip), %rsi      # 0x1847d
leaq 0x71ec(%rip), %rdx      # 0x184a3
movl $0x1c9, %ecx            # imm = 0x1C9
xorl %eax, %eax
callq 0x5180
jmp 0x113eb
movups 0x1c(%rsp), %xmm0
movups %xmm0, 0xc(%rbx)
movaps 0x10(%rsp), %xmm0
movups %xmm0, (%rbx)
movl 0x10(%rsp), %eax
movl %eax, 0x8(%rsp)
movzwl 0x14(%rsp), %eax
movw %ax, 0xc(%rsp)
leaq 0xef9f(%rip), %r14      # 0x20291
movb (%r14), %al
cmpb $0x1, %al
jne 0x11325
movq 0xecb8(%rip), %rax      # 0x1ffb8
movq (%rax), %rdi
leaq 0x71de(%rip), %rsi      # 0x184e8
leaq 0x7192(%rip), %rdx      # 0x184a3
leaq 0x8(%rsp), %r8
movl $0x1d4, %ecx            # imm = 0x1D4
xorl %eax, %eax
callq 0x5180
movb (%r14), %al
testb $0x1, %al
je 0x11358
movq 0xec88(%rip), %rax      # 0x1ffb8
movq (%rax), %rdi
leaq 0x6(%rbx), %r9
leaq 0x71c7(%rip), %rsi      # 0x18505
leaq 0x715e(%rip), %rdx      # 0x184a3
pushq $0x3
popq %r8
movl $0x1d5, %ecx            # imm = 0x1D5
xorl %eax, %eax
callq 0x5180
movb (%r14), %al
testb $0x1, %al
je 0x11387
movq 0xec55(%rip), %rax      # 0x1ffb8
movq (%rax), %rdi
leaq 0xa(%rbx), %r8
leaq 0x4aa8(%rip), %rsi      # 0x15e19
leaq 0x712b(%rip), %rdx      # 0x184a3
movl $0x1d6, %ecx            # imm = 0x1D6
xorl %eax, %eax
callq 0x5180
movb (%r14), %al
testb $0x1, %al
je 0x113ba
movq 0xec26(%rip), %rax      # 0x1ffb8
movq (%rax), %rdi
leaq 0x12(%rbx), %r9
leaq 0x7184(%rip), %rsi      # 0x18524
leaq 0x70fc(%rip), %rdx      # 0x184a3
pushq $0x4
popq %r8
movl $0x1d7, %ecx            # imm = 0x1D7
xorl %eax, %eax
callq 0x5180
movb (%r14), %al
xorl %ebp, %ebp
testb $0x1, %al
je 0x113eb
movq 0xebf1(%rip), %rax      # 0x1ffb8
movq (%rax), %rdi
movzbl 0x17(%rbx), %r8d
leaq 0x7169(%rip), %rsi      # 0x1853f
leaq 0x70c6(%rip), %rdx      # 0x184a3
xorl %ebp, %ebp
movl $0x1d8, %ecx            # imm = 0x1D8
xorl %eax, %eax
callq 0x5180
movl %ebp, %eax
addq $0x30, %rsp
popq %rbx
popq %r14
popq %rbp
retq