// File: goodix[P]gdix_hid_firmware_update/gt_update.cpp
// Function: GTupdate::check_update()
int GTupdate::check_update()
{
	int ret;
	if (!dev->IsOpened()) {
		gdix_err("No dev is Opened.");
		return -2;
	}
	if (!image->IsOpened()) {
		gdix_err("No image is Opened.");
		return -2;
	}
	gdix_dbg("dev PID is %s, image PID is %s\n", dev->GetProductID(),
			 image->GetProductID());

	/* compare PID */
	ret = memcmp(dev->GetProductID(), image->GetProductID(), 4);
	if (ret)
		return -1;

	gdix_dbg("dev major ver:0x%x,Minor ver:0x%x\n",
			 dev->GetFirmwareVersionMajor(), dev->GetFirmwareVersionMinor());
	gdix_dbg("fw_image major ver:0x%x,Minor ver:0x%x\n",
			 image->GetFirmwareVersionMajor(),
			 image->GetFirmwareVersionMinor());
	if (dev->GetFirmwareVersionMajor() != image->GetFirmwareVersionMajor() ||
		dev->GetFirmwareVersionMinor() != image->GetFirmwareVersionMinor()) {
		return 0;
	} else {
		return -2;
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x20(%rbp)
movq 0x8(%rax), %rdi
movq (%rdi), %rax
callq *0x18(%rax)
testb $0x1, %al
jne 0x6092
jmp 0x6054
leaq 0x2023e(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0x6084
movq 0x1ff71(%rip), %rax     # 0x25fd8
movq (%rax), %rdi
leaq 0x16219(%rip), %rsi     # 0x1c28a
leaq 0x16235(%rip), %rdx     # 0x1c2ad
movl $0x18, %ecx
movb $0x0, %al
callq 0x5190
jmp 0x6086
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
jmp 0x62c2
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rdi
movq (%rdi), %rax
callq *0x90(%rax)
testb $0x1, %al
jne 0x60e7
jmp 0x60a9
leaq 0x201e9(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0x60d9
movq 0x1ff1c(%rip), %rax     # 0x25fd8
movq (%rax), %rdi
leaq 0x161f4(%rip), %rsi     # 0x1c2ba
leaq 0x161e0(%rip), %rdx     # 0x1c2ad
movl $0x1c, %ecx
movb $0x0, %al
callq 0x5190
jmp 0x60db
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
jmp 0x62c2
jmp 0x60e9
leaq 0x201a9(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0x614b
movq -0x20(%rbp), %rax
movq 0x1feb8(%rip), %rcx     # 0x25fb8
movq (%rcx), %rcx
movq %rcx, -0x30(%rbp)
movq 0x8(%rax), %rdi
movq (%rdi), %rax
callq *0x70(%rax)
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, -0x28(%rbp)
movq 0x10(%rax), %rdi
movq (%rdi), %rax
callq *0x10(%rax)
movq -0x30(%rbp), %rdi
movq -0x28(%rbp), %r8
movq %rax, %r9
leaq 0x161a7(%rip), %rsi     # 0x1c2df
leaq 0x1616e(%rip), %rdx     # 0x1c2ad
movl $0x20, %ecx
movb $0x0, %al
callq 0x5190
jmp 0x614d
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rdi
movq (%rdi), %rax
callq *0x70(%rax)
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, -0x38(%rbp)
movq 0x10(%rax), %rdi
movq (%rdi), %rax
callq *0x10(%rax)
movq -0x38(%rbp), %rdi
movq %rax, %rsi
movl $0x4, %edx
callq 0x5090
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
je 0x6196
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x62c2
jmp 0x6198
leaq 0x200fa(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0x61f8
movq -0x20(%rbp), %rax
movq 0x1fe09(%rip), %rcx     # 0x25fb8
movq (%rcx), %rcx
movq %rcx, -0x48(%rbp)
movq 0x8(%rax), %rdi
movq (%rdi), %rax
callq *0x60(%rax)
movl %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, -0x3c(%rbp)
movq 0x8(%rax), %rdi
movq (%rdi), %rax
callq *0x68(%rax)
movq -0x48(%rbp), %rdi
movl -0x3c(%rbp), %r8d
movl %eax, %r9d
leaq 0x1612b(%rip), %rsi     # 0x1c310
leaq 0x160c1(%rip), %rdx     # 0x1c2ad
movl $0x28, %ecx
movb $0x0, %al
callq 0x5190
jmp 0x61fa
jmp 0x61fc
leaq 0x20096(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0x625c
movq -0x20(%rbp), %rax
movq 0x1fda5(%rip), %rcx     # 0x25fb8
movq (%rcx), %rcx
movq %rcx, -0x58(%rbp)
movq 0x10(%rax), %rdi
movq (%rdi), %rax
callq *0x28(%rax)
movl %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, -0x4c(%rbp)
movq 0x10(%rax), %rdi
movq (%rdi), %rax
callq *0x30(%rax)
movq -0x58(%rbp), %rdi
movl -0x4c(%rbp), %r8d
movl %eax, %r9d
leaq 0x160fb(%rip), %rsi     # 0x1c344
leaq 0x1605d(%rip), %rdx     # 0x1c2ad
movl $0x2b, %ecx
movb $0x0, %al
callq 0x5190
jmp 0x625e
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rdi
movq (%rdi), %rax
callq *0x60(%rax)
movl %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, -0x5c(%rbp)
movq 0x10(%rax), %rdi
movq (%rdi), %rax
callq *0x28(%rax)
movl %eax, %ecx
movl -0x5c(%rbp), %eax
cmpl %ecx, %eax
jne 0x62b2
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rdi
movq (%rdi), %rax
callq *0x68(%rax)
movl %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, -0x60(%rbp)
movq 0x10(%rax), %rdi
movq (%rdi), %rax
callq *0x30(%rax)
movl %eax, %ecx
movl -0x60(%rbp), %eax
cmpl %ecx, %eax
je 0x62bb
movl $0x0, -0x4(%rbp)
jmp 0x62c2
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax,%rax)