// File: /workspace/github_c_makefile_star2_O3/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 0x8828(%rip), %r12      # 0xf748
movl $0x10, %edi
callq 0x2190
testq %rax, %rax
je 0x6fdf
movq %rax, %rbx
cmpb $0x0, 0x83a3(%rip)      # 0xf2e0
jne 0x6fe9
cmpw $0x0, 0xc(%r12)
je 0x70df
movq %rbx, -0x30(%rbp)
movb 0x8386(%rip), %al       # 0xf2e0
movq 0x87e7(%rip), %rcx      # 0xf748
xorl %r14d, %r14d
movl %eax, %edx
xorl %r13d, %r13d
xorl %r15d, %r15d
testb %dl, %dl
jne 0x6fa5
xorl %edx, %edx
movq %r14, %rbx
movzwl 0xe(%rcx,%rbx), %esi
movzbl 0x878e(%rip), %edi      # 0xf70f
incl %edi
cmpl %esi, %edi
je 0x7018
incl %r13d
movzwl 0xc(%r12), %esi
incq %r15
addq $0x2, %r14
cmpl %esi, %r13d
jb 0x6f6c
jmp 0x70c3
movq 0x804c(%rip), %rax      # 0xeff8
movq (%rax), %rdi
leaq (%r15,%r15), %rbx
movzwl 0xe(%rcx,%r14), %ecx
leaq 0x2e07(%rip), %rsi      # 0x9dc7
leaq 0x2572(%rip), %rdx      # 0x9539
xorl %eax, %eax
callq 0x2150
movb 0x830c(%rip), %al       # 0xf2e0
movq 0x876d(%rip), %rcx      # 0xf748
movl %eax, %edx
jmp 0x6f75
callq 0x343c
jmp 0x70e7
movzwl 0xc(%r12), %r8d
movq 0x8002(%rip), %rax      # 0xeff8
movq (%rax), %rdi
movl 0x8(%r12), %ecx
leaq 0x2da1(%rip), %rsi      # 0x9da6
leaq 0x252d(%rip), %rdx      # 0x9539
xorl %eax, %eax
callq 0x2150
jmp 0x6f43
leaq 0xe(%rcx), %rdx
movq -0x30(%rbp), %rdi
movw %si, (%rdi)
movzwl 0xc(%r12), %esi
leaq (%rdx,%rsi,2), %rdx
movzwl (%rbx,%rdx), %ebx
movw %bx, 0x2(%rdi)
leaq (%rcx,%rsi,4), %rcx
movl 0xe(%rcx,%r14,2), %r15d
movq %rdi, %r14
movl %r15d, 0x4(%rdi)
testb %al, %al
je 0x7053
movl %ebx, %edi
movl %r15d, %esi
callq 0x33ac
addq 0x86ee(%rip), %r15      # 0xf748
movl -0x8(%rbx,%r15), %ecx
movl %ecx, 0x8(%r14)
movl -0xc(%rbx,%r15), %ebx
movl %ebx, 0xc(%r14)
movq 0x7f85(%rip), %r15      # 0xeff8
movq (%r15), %rdi
leaq 0x2d92(%rip), %rsi      # 0x9e0f
leaq 0x24b5(%rip), %r14      # 0x9539
movq %r14, %rdx
xorl %eax, %eax
callq 0x2150
movl %ebx, %eax
shrl $0x10, %eax
andl $0x7ff, %eax            # imm = 0x7FF
movl %ebx, %ecx
shrl $0x1b, %ecx
imull $0x2710, %ecx, %ecx     # imm = 0x2710
addl %eax, %ecx
movq (%r15), %rdi
movzwl %bx, %r8d
leaq 0x2d73(%rip), %rsi      # 0x9e26
movq %r14, %rdx
xorl %eax, %eax
callq 0x2150
movzwl 0xc(%r12), %esi
cmpw %r13w, %si
movq -0x30(%rbp), %rbx
je 0x70df
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
callq 0x3406
xorl %ebx, %ebx
jmp 0x70cd