// File: /workspace/github_c_makefile_star2_O1/seuscq[P]rtk_hciattach/hciattach_rtk.c
// Function: rtk_get_patch_entry
struct rtk_epatch_entry *rtk_get_patch_entry(void)
{
	uint16_t i;
	struct rtk_epatch *patch;
	struct rtk_epatch_entry *entry;
	uint8_t *p;
	uint16_t chip_id;
	uint32_t tmp;

	patch = (struct rtk_epatch *)rtk_hw_cfg.fw_buf;
	entry = (struct rtk_epatch_entry *)malloc(sizeof(*entry));
	if (!entry) {
		RS_ERR("failed to allocate mem for patch entry");
		return NULL;
	}

	patch->number_of_patch = le16_to_cpu(patch->number_of_patch);

	RS_DBG("fw_ver 0x%08x, patch_num %d",
	       le32_to_cpu(patch->fw_version), patch->number_of_patch);

	for (i = 0; i < patch->number_of_patch; i++) {
		RS_DBG("chip id 0x%04x",
			get_unaligned_le16(rtk_hw_cfg.fw_buf + 14 + 2 * i));
		if (get_unaligned_le16(rtk_hw_cfg.fw_buf + 14 + 2 * i) ==
		    rtk_hw_cfg.eversion + 1) {
			entry->chipID = rtk_hw_cfg.eversion + 1;
			entry->patch_length =
			    get_unaligned_le16(rtk_hw_cfg.fw_buf + 14 +
					       2 * patch->number_of_patch +
					       2 * i);
			entry->start_offset =
			    get_unaligned_le32(rtk_hw_cfg.fw_buf + 14 +
					       4 * patch->number_of_patch +
					       4 * i);
			RS_DBG("patch length is 0x%x", entry->patch_length);
			RS_DBG("start offset is 0x%x", entry->start_offset);

			entry->svn_ver = get_unaligned_le32(rtk_hw_cfg.fw_buf +
						entry->start_offset +
						entry->patch_length - 8);
			entry->coex_ver = get_unaligned_le32(rtk_hw_cfg.fw_buf +
						entry->start_offset +
						entry->patch_length - 12);

			RS_INFO("Svn version: %8d\n", entry->svn_ver);
			tmp = ((entry->coex_ver >> 16) & 0x7ff) +
			      (entry->coex_ver >> 27) * 10000;
			RS_INFO("Coexistence: BTCOEX_20%06d-%04x\n", tmp,
				(entry->coex_ver & 0xffff));

			break;
		}

	}

	if (i == patch->number_of_patch) {
		RS_ERR("failed to get entry");
		free(entry);
		entry = NULL;
	}

	return entry;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq 0x87ef(%rip), %r12      # 0xf748
movl $0x10, %edi
callq 0x2190
testq %rax, %rax
je 0x6fd7
movq %rax, %rbx
cmpb $0x0, 0x836e(%rip)      # 0xf2e0
jne 0x6fde
cmpw $0x0, 0xc(%r12)
je 0x6fba
xorl %r14d, %r14d
cmpb $0x0, 0x8359(%rip)      # 0xf2e0
jne 0x6fb0
movq 0x87b8(%rip), %rax      # 0xf748
movzwl 0xe(%rax,%r14,2), %edx
movzbl 0x8772(%rip), %ecx      # 0xf70f
incl %ecx
cmpl %edx, %ecx
je 0x7019
incq %r14
cmpw 0xc(%r12), %r14w
jb 0x6f80
jmp 0x6fbd
movl %r14d, %edi
callq 0x3394
jmp 0x6f89
xorl %r14d, %r14d
cmpw 0xc(%r12), %r14w
je 0x700d
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x3429
jmp 0x7015
movzwl 0xc(%r12), %r8d
movq 0x800d(%rip), %rax      # 0xeff8
movq (%rax), %rdi
movl 0x8(%r12), %ecx
leaq 0x2dac(%rip), %rsi      # 0x9da6
leaq 0x2538(%rip), %rdx      # 0x9539
xorl %eax, %eax
callq 0x2150
jmp 0x6f74
movq %rbx, %rdi
callq 0x33f3
xorl %ebx, %ebx
jmp 0x6fc5
movw %cx, (%rbx)
movzwl 0xc(%r12), %ecx
leaq (%rax,%rcx,2), %rdx
movzwl 0xe(%rdx,%r14,2), %r15d
movw %r15w, 0x2(%rbx)
leaq (%rax,%rcx,4), %rax
movl 0xe(%rax,%r14,4), %r13d
movl %r13d, 0x4(%rbx)
cmpb $0x0, 0x829b(%rip)      # 0xf2e0
je 0x704f
movl %r15d, %edi
callq 0x33c9
cmpb $0x0, 0x828a(%rip)      # 0xf2e0
je 0x707a
movq 0x7f99(%rip), %rax      # 0xeff8
movq (%rax), %rdi
leaq 0x2d8c(%rip), %rsi      # 0x9df5
leaq 0x24c9(%rip), %rdx      # 0x9539
movl %r13d, %ecx
xorl %eax, %eax
callq 0x2150
addq 0x86c7(%rip), %r13      # 0xf748
movl -0x8(%r15,%r13), %ecx
movl %ecx, 0x8(%rbx)
movzwl -0xc(%r15,%r13), %edx
movq %rdx, -0x30(%rbp)
movzbl -0xa(%r15,%r13), %eax
shll $0x10, %eax
movzbl -0x9(%r15,%r13), %r15d
movl %r15d, %r13d
shll $0x18, %r13d
orl %eax, %r13d
leal (%rdx,%r13), %eax
movl %eax, 0xc(%rbx)
movq 0x7f3e(%rip), %rax      # 0xeff8
movq (%rax), %rdi
leaq 0x2d4b(%rip), %rsi      # 0x9e0f
leaq 0x246e(%rip), %rdx      # 0x9539
xorl %eax, %eax
callq 0x2150
shrl $0x10, %r13d
andl $0x7ff, %r13d           # imm = 0x7FF
shrl $0x3, %r15d
imull $0x2710, %r15d, %ecx    # imm = 0x2710
addl %r13d, %ecx
movq 0x7f06(%rip), %rax      # 0xeff8
movq (%rax), %rdi
leaq 0x2d2a(%rip), %rsi      # 0x9e26
leaq 0x2436(%rip), %rdx      # 0x9539
movq -0x30(%rbp), %r8
xorl %eax, %eax
callq 0x2150
jmp 0x6fbd