// File: /workspace/github_cpp_makefile_star2_O3/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 0x124bc
testl %eax, %eax
js 0x12481
xorl %eax, %eax
xorl %ecx, %ecx
movzbl 0x10(%rsp,%rax), %edx
addl %edx, %ecx
incq %rax
cmpq $0x1a, %rax
jne 0x1233d
cmpw %cx, 0x2a(%rsp)
jne 0x12499
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 0xef0f(%rip), %r14      # 0x21291
movb (%r14), %al
cmpb $0x1, %al
jne 0x123b5
movq 0xec28(%rip), %rax      # 0x20fb8
movq (%rax), %rdi
leaq 0x714e(%rip), %rsi      # 0x194e8
leaq 0x7102(%rip), %rdx      # 0x194a3
leaq 0x8(%rsp), %r8
movl $0x1d4, %ecx            # imm = 0x1D4
xorl %eax, %eax
callq 0x5180
movb (%r14), %al
testb $0x1, %al
je 0x123ea
movq 0xebf8(%rip), %rax      # 0x20fb8
movq (%rax), %rdi
leaq 0x6(%rbx), %r9
leaq 0x7137(%rip), %rsi      # 0x19505
leaq 0x70ce(%rip), %rdx      # 0x194a3
movl $0x1d5, %ecx            # imm = 0x1D5
movl $0x3, %r8d
xorl %eax, %eax
callq 0x5180
movb (%r14), %al
testb $0x1, %al
je 0x12419
movq 0xebc3(%rip), %rax      # 0x20fb8
movq (%rax), %rdi
leaq 0xa(%rbx), %r8
leaq 0x4a16(%rip), %rsi      # 0x16e19
leaq 0x7099(%rip), %rdx      # 0x194a3
movl $0x1d6, %ecx            # imm = 0x1D6
xorl %eax, %eax
callq 0x5180
movb (%r14), %al
testb $0x1, %al
je 0x1244e
movq 0xeb94(%rip), %rax      # 0x20fb8
movq (%rax), %rdi
leaq 0x12(%rbx), %r9
leaq 0x70f2(%rip), %rsi      # 0x19524
leaq 0x706a(%rip), %rdx      # 0x194a3
movl $0x1d7, %ecx            # imm = 0x1D7
movl $0x4, %r8d
xorl %eax, %eax
callq 0x5180
movb (%r14), %al
xorl %ebp, %ebp
testb $0x1, %al
je 0x124aa
movq 0xeb5d(%rip), %rax      # 0x20fb8
movq (%rax), %rdi
movzbl 0x17(%rbx), %r8d
leaq 0x70d5(%rip), %rsi      # 0x1953f
leaq 0x7032(%rip), %rdx      # 0x194a3
xorl %ebp, %ebp
movl $0x1d8, %ecx            # imm = 0x1D8
xorl %eax, %eax
callq 0x5180
jmp 0x124aa
leaq 0xee09(%rip), %rax      # 0x21291
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
cmpb $0x1, (%rax)
jne 0x124aa
callq 0x642c
jmp 0x124aa
leaq 0xedf1(%rip), %rax      # 0x21291
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
cmpb $0x1, (%rax)
je 0x124b5
movl %ebp, %eax
addq $0x30, %rsp
popq %rbx
popq %r14
popq %rbp
retq
callq 0x6408
jmp 0x124aa