// File: goodix[P]gdix_hid_firmware_update/gtx3/gtx3_update.cpp
// Function: need_upgrade_hid_subsystem(GTmodel*, FirmwareImage*)
bool need_upgrade_hid_subsystem(GTmodel *dev, FirmwareImage *fw_img)
{
	int dev_fw_ver = 0;
	int img_fw_ver = 0;
	int boundary_fw_ver =
		(HID_FORCE_UPDATE_VER_MAJOR << 16) | HID_FORCE_UPDATE_VER_MINOR;

	if (fw_img->GetUpdateFlag() & NEED_UPDATE_HID_SUBSYSTEM) {
		gdix_dbg("get hid subsystem update flag from fw_img file:0x%x\n",
				 fw_img->GetUpdateFlag());
		return true;
	}
	/* ignore the config_id byte */
	dev_fw_ver = (dev->GetFirmwareVersionMajor() << 16) |
				 ((dev->GetFirmwareVersionMinor() >> 8) & 0xFFFF);
	img_fw_ver = (fw_img->GetFirmwareVersionMajor() << 16) |
				 ((fw_img->GetFirmwareVersionMinor() >> 8) & 0xFFFF);

	gdix_dbg("boundery_ver 0x%x, dev_ver 0x%x, fw_ver 0x%x\n", boundary_fw_ver,
			 dev_fw_ver, img_fw_ver);
	if (dev_fw_ver < boundary_fw_ver || img_fw_ver < boundary_fw_ver) {
		gdix_dbg("hid subsystem need update judged by fw_ver\n");
		return true;
	}

	return false;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
movl $0x0, -0x20(%rbp)
movl $0x117, -0x24(%rbp)     # imm = 0x117
movq -0x18(%rbp), %rdi
movq (%rdi), %rax
callq *0xa8(%rax)
andl $0x80, %eax
cmpl $0x0, %eax
je 0xd361
jmp 0xd30e
leaq 0x18f84(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0xd356
movq 0x18c97(%rip), %rax     # 0x25fb8
movq (%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rdi
movq (%rdi), %rax
callq *0xa8(%rax)
movq -0x30(%rbp), %rdi
movl %eax, %r8d
leaq 0x10da8(%rip), %rsi     # 0x1e0eb
leaq 0x10de7(%rip), %rdx     # 0x1e131
movl $0x87, %ecx
movb $0x0, %al
callq 0x5190
jmp 0xd358
movb $0x1, -0x1(%rbp)
jmp 0xd449
movq -0x10(%rbp), %rdi
movq (%rdi), %rax
callq *0x60(%rax)
shll $0x10, %eax
movl %eax, -0x38(%rbp)
movq -0x10(%rbp), %rdi
movq (%rdi), %rax
callq *0x68(%rax)
movl %eax, %ecx
movl -0x38(%rbp), %eax
sarl $0x8, %ecx
andl $0xffff, %ecx           # imm = 0xFFFF
orl %ecx, %eax
movl %eax, -0x1c(%rbp)
movq -0x18(%rbp), %rdi
movq (%rdi), %rax
callq *0x28(%rax)
shll $0x10, %eax
movl %eax, -0x34(%rbp)
movq -0x18(%rbp), %rdi
movq (%rdi), %rax
callq *0x30(%rax)
movl %eax, %ecx
movl -0x34(%rbp), %eax
sarl $0x8, %ecx
andl $0xffff, %ecx           # imm = 0xFFFF
orl %ecx, %eax
movl %eax, -0x20(%rbp)
leaq 0x18ed7(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0xd3f9
movq 0x18bea(%rip), %rax     # 0x25fb8
movq (%rax), %rdi
movl -0x24(%rbp), %r8d
movl -0x1c(%rbp), %r9d
movl -0x20(%rbp), %eax
leaq 0x10d69(%rip), %rsi     # 0x1e14c
leaq 0x10d47(%rip), %rdx     # 0x1e131
movl $0x91, %ecx
movl %eax, (%rsp)
movb $0x0, %al
callq 0x5190
jmp 0xd3fb
movl -0x1c(%rbp), %eax
cmpl -0x24(%rbp), %eax
jl 0xd40b
movl -0x20(%rbp), %eax
cmpl -0x24(%rbp), %eax
jge 0xd445
jmp 0xd40d
leaq 0x18e85(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0xd43d
movq 0x18b98(%rip), %rax     # 0x25fb8
movq (%rax), %rdi
leaq 0x10d61(%rip), %rsi     # 0x1e18b
leaq 0x10d00(%rip), %rdx     # 0x1e131
movl $0x93, %ecx
movb $0x0, %al
callq 0x5190
jmp 0xd43f
movb $0x1, -0x1(%rbp)
jmp 0xd449
movb $0x0, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)