// File: /workspace/github_c_makefile_star2_O0/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
subq $0x40, %rsp
movq 0x9949(%rip), %rax      # 0x10738
movq %rax, -0x18(%rbp)
movl $0x10, %edi
callq 0x2190
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x6e36
jmp 0x6e0a
movq 0x91e7(%rip), %rax      # 0xfff8
movq (%rax), %rdi
leaq 0x4fac(%rip), %rsi      # 0xbdc7
leaq 0x4767(%rip), %rdx      # 0xb589
movb $0x0, %al
callq 0x2150
movq $0x0, -0x8(%rbp)
jmp 0x7139
movq -0x18(%rbp), %rax
movw 0xc(%rax), %cx
movq -0x18(%rbp), %rax
movw %cx, 0xc(%rax)
cmpb $0x0, 0x9483(%rip)      # 0x102d0
je 0x6e7e
movq 0x91a2(%rip), %rax      # 0xfff8
movq (%rax), %rdi
movq -0x18(%rbp), %rax
movl 0x8(%rax), %ecx
movq -0x18(%rbp), %rax
movzwl 0xc(%rax), %r8d
leaq 0x4f89(%rip), %rsi      # 0xbdf9
leaq 0x4712(%rip), %rdx      # 0xb589
movb $0x0, %al
callq 0x2150
jmp 0x6e80
movw $0x0, -0xa(%rbp)
movzwl -0xa(%rbp), %eax
movq -0x18(%rbp), %rcx
movzwl 0xc(%rcx), %ecx
cmpl %ecx, %eax
jge 0x70ef
jmp 0x6e9c
cmpb $0x0, 0x942d(%rip)      # 0x102d0
je 0x6eea
movq 0x914c(%rip), %rax      # 0xfff8
movq (%rax), %rax
movq %rax, -0x38(%rbp)
movq 0x987e(%rip), %rdi      # 0x10738
addq $0xe, %rdi
movzwl -0xa(%rbp), %eax
shll %eax
cltq
addq %rax, %rdi
callq 0x7150
movq -0x38(%rbp), %rdi
movzwl %ax, %ecx
leaq 0x4f3e(%rip), %rsi      # 0xbe1a
leaq 0x46a6(%rip), %rdx      # 0xb589
movb $0x0, %al
callq 0x2150
jmp 0x6eec
movq 0x9845(%rip), %rdi      # 0x10738
addq $0xe, %rdi
movzwl -0xa(%rbp), %eax
shll %eax
cltq
addq %rax, %rdi
callq 0x7150
movzwl %ax, %eax
movzbl 0x97ee(%rip), %ecx      # 0x106ff
addl $0x1, %ecx
cmpl %ecx, %eax
jne 0x70dc
movzbl 0x97dc(%rip), %eax      # 0x106ff
addl $0x1, %eax
movw %ax, %cx
movq -0x20(%rbp), %rax
movw %cx, (%rax)
movq 0x9801(%rip), %rdi      # 0x10738
addq $0xe, %rdi
movq -0x18(%rbp), %rax
movzwl 0xc(%rax), %eax
shll %eax
cltq
addq %rax, %rdi
movzwl -0xa(%rbp), %eax
shll %eax
cltq
addq %rax, %rdi
callq 0x7150
movw %ax, %cx
movq -0x20(%rbp), %rax
movw %cx, 0x2(%rax)
movq 0x97cc(%rip), %rdi      # 0x10738
addq $0xe, %rdi
movq -0x18(%rbp), %rax
movzwl 0xc(%rax), %eax
shll $0x2, %eax
cltq
addq %rax, %rdi
movzwl -0xa(%rbp), %eax
shll $0x2, %eax
cltq
addq %rax, %rdi
callq 0x4ab0
movl %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x4(%rax)
cmpb $0x0, 0x932f(%rip)      # 0x102d0
je 0x6fca
movq 0x904e(%rip), %rax      # 0xfff8
movq (%rax), %rdi
movq -0x20(%rbp), %rax
movzwl 0x2(%rax), %ecx
leaq 0x4e72(%rip), %rsi      # 0xbe2e
leaq 0x45c6(%rip), %rdx      # 0xb589
movb $0x0, %al
callq 0x2150
jmp 0x6fcc
jmp 0x6fce
cmpb $0x0, 0x92fb(%rip)      # 0x102d0
je 0x6ffd
movq 0x901a(%rip), %rax      # 0xfff8
movq (%rax), %rdi
movq -0x20(%rbp), %rax
movl 0x4(%rax), %ecx
leaq 0x4e59(%rip), %rsi      # 0xbe48
leaq 0x4593(%rip), %rdx      # 0xb589
movb $0x0, %al
callq 0x2150
jmp 0x6fff
movq 0x9732(%rip), %rdi      # 0x10738
movq -0x20(%rbp), %rax
movl 0x4(%rax), %eax
addq %rax, %rdi
movq -0x20(%rbp), %rax
movzwl 0x2(%rax), %eax
cltq
addq %rax, %rdi
addq $-0x8, %rdi
callq 0x4ab0
movl %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x8(%rax)
movq 0x9702(%rip), %rdi      # 0x10738
movq -0x20(%rbp), %rax
movl 0x4(%rax), %eax
addq %rax, %rdi
movq -0x20(%rbp), %rax
movzwl 0x2(%rax), %eax
cltq
addq %rax, %rdi
addq $-0xc, %rdi
callq 0x4ab0
movl %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0xc(%rax)
movq 0x8f92(%rip), %rax      # 0xfff8
movq (%rax), %rdi
movq -0x20(%rbp), %rax
movl 0x8(%rax), %ecx
leaq 0x4deb(%rip), %rsi      # 0xbe62
leaq 0x450b(%rip), %rdx      # 0xb589
movb $0x0, %al
callq 0x2150
movq -0x20(%rbp), %rax
movl 0xc(%rax), %eax
shrl $0x10, %eax
andl $0x7ff, %eax            # imm = 0x7FF
movq -0x20(%rbp), %rcx
movl 0xc(%rcx), %ecx
shrl $0x1b, %ecx
imull $0x2710, %ecx, %ecx     # imm = 0x2710
addl %ecx, %eax
movl %eax, -0x30(%rbp)
movq 0x8f48(%rip), %rax      # 0xfff8
movq (%rax), %rdi
movl -0x30(%rbp), %ecx
movq -0x20(%rbp), %rax
movl 0xc(%rax), %r8d
andl $0xffff, %r8d           # imm = 0xFFFF
leaq 0x4dad(%rip), %rsi      # 0xbe79
leaq 0x44b6(%rip), %rdx      # 0xb589
movb $0x0, %al
callq 0x2150
jmp 0x70ef
jmp 0x70de
movw -0xa(%rbp), %ax
addw $0x1, %ax
movw %ax, -0xa(%rbp)
jmp 0x6e86
movzwl -0xa(%rbp), %eax
movq -0x18(%rbp), %rcx
movzwl 0xc(%rcx), %ecx
cmpl %ecx, %eax
jne 0x7131
jmp 0x7101
movq 0x8ef0(%rip), %rax      # 0xfff8
movq (%rax), %rdi
leaq 0x4d8d(%rip), %rsi      # 0xbe9f
leaq 0x4470(%rip), %rdx      # 0xb589
movb $0x0, %al
callq 0x2150
movq -0x20(%rbp), %rdi
callq 0x2030
movq $0x0, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)