// File: /workspace/github_cpp_makefile_star2_O1/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
movq $0x0, 0x8(%rsp)
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %rsi
movups %xmm0, 0xc(%rsi)
movaps %xmm0, (%rsi)
movl $0x10014, %edi          # imm = 0x10014
movl $0x1c, %edx
callq 0x1267f
testl %eax, %eax
js 0x12647
xorl %eax, %eax
xorl %ecx, %ecx
movzbl 0x10(%rsp,%rax), %edx
addl %edx, %ecx
incq %rax
cmpq $0x1a, %rax
jne 0x12503
movzwl %cx, %eax
movzwl 0x2a(%rsp), %ecx
cmpl %ecx, %eax
jne 0x1265c
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 0xed44(%rip), %r14      # 0x21291
cmpb $0x1, (%r14)
jne 0x1257c
movq 0xea5e(%rip), %rax      # 0x20fb8
movq (%rax), %rdi
leaq 0x6fc4(%rip), %rsi      # 0x19528
leaq 0x6f78(%rip), %rdx      # 0x194e3
leaq 0x8(%rsp), %r8
movl $0x1d4, %ecx            # imm = 0x1D4
xorl %eax, %eax
callq 0x5180
cmpb $0x1, (%r14)
jne 0x125b0
movq 0xea2f(%rip), %rax      # 0x20fb8
movq (%rax), %rdi
leaq 0x6(%rbx), %r9
leaq 0x6fae(%rip), %rsi      # 0x19545
leaq 0x6f45(%rip), %rdx      # 0x194e3
movl $0x1d5, %ecx            # imm = 0x1D5
movl $0x3, %r8d
xorl %eax, %eax
callq 0x5180
cmpb $0x1, (%r14)
jne 0x125de
movq 0xe9fb(%rip), %rax      # 0x20fb8
movq (%rax), %rdi
leaq 0xa(%rbx), %r8
leaq 0x48af(%rip), %rsi      # 0x16e7a
leaq 0x6f11(%rip), %rdx      # 0x194e3
movl $0x1d6, %ecx            # imm = 0x1D6
xorl %eax, %eax
callq 0x5180
cmpb $0x1, (%r14)
jne 0x12612
movq 0xe9cd(%rip), %rax      # 0x20fb8
movq (%rax), %rdi
leaq 0x12(%rbx), %r9
leaq 0x6f6b(%rip), %rsi      # 0x19564
leaq 0x6ee3(%rip), %rdx      # 0x194e3
movl $0x1d7, %ecx            # imm = 0x1D7
movl $0x4, %r8d
xorl %eax, %eax
callq 0x5180
xorl %ebp, %ebp
cmpb $0x1, (%r14)
jne 0x1266d
movq 0xe997(%rip), %rax      # 0x20fb8
movq (%rax), %rdi
movzbl 0x17(%rbx), %r8d
leaq 0x6f4f(%rip), %rsi      # 0x1957f
leaq 0x6eac(%rip), %rdx      # 0x194e3
xorl %ebp, %ebp
movl $0x1d8, %ecx            # imm = 0x1D8
xorl %eax, %eax
callq 0x5180
jmp 0x1266d
movl %eax, %ebp
leaq 0xec41(%rip), %rax      # 0x21291
cmpb $0x1, (%rax)
jne 0x1266d
callq 0x6480
jmp 0x1266d
leaq 0xec2e(%rip), %rax      # 0x21291
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
cmpb $0x1, (%rax)
je 0x12678
movl %ebp, %eax
addq $0x30, %rsp
popq %rbx
popq %r14
popq %rbp
retq
callq 0x645c
jmp 0x1266d