// File: /workspace/github_c_makefile_star2_O0/seuscq[P]rtk_hciattach/hciattach_rtk.c
// Function: rtk_get_bt_firmware
int rtk_get_bt_firmware(struct btrtl_info *btrtl, RT_U8 **fw_buf)
{
	const char *filename;
	struct stat st;
	int fd = -1;
	size_t fwsize;
	static char firmware_file_name[PATH_MAX] = { 0 };
	int ret = 0;

	sprintf(firmware_file_name, "%s", FIRMWARE_DIRECTORY);
	strcat(firmware_file_name, btrtl->patch_ent->patch_file);
	filename = firmware_file_name;

	if (stat(filename, &st) < 0) {
		RS_ERR("Can't access firmware %s, %s", filename,
		       strerror(errno));
		return -1;
	}

	fwsize = st.st_size;

	if ((fd = open(filename, O_RDONLY)) < 0) {
		RS_ERR("Can't open firmware, errno:%d", errno);
		return -1;
	}

	if (!(*fw_buf = malloc(fwsize))) {
		RS_ERR("Can't alloc memory for fw&config, errno:%d", errno);
		close(fd);
		return -1;
	}

	if (read(fd, *fw_buf, fwsize) < (ssize_t) fwsize) {
		free(*fw_buf);
		*fw_buf = NULL;
		close(fd);
		return -1;
	}
	RS_DBG("Load FW OK");
	close(fd);
	return fwsize;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xf0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl $0xffffffff, -0xb4(%rbp) # imm = 0xFFFFFFFF
movl $0x0, -0xc4(%rbp)
leaq 0xa452(%rip), %rdi      # 0x10780
leaq 0x56eb(%rip), %rsi      # 0xba20
leaq 0x56e7(%rip), %rdx      # 0xba23
movb $0x0, %al
callq 0x2270
movq -0x10(%rbp), %rax
movq 0x90(%rax), %rax
movq 0x10(%rax), %rsi
leaq 0xa427(%rip), %rdi      # 0x10780
callq 0x2260
leaq 0xa41b(%rip), %rax      # 0x10780
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x2160
cmpl $0x0, %eax
jge 0x63da
jmp 0x6380
movq 0x9c71(%rip), %rax      # 0xfff8
movq (%rax), %rax
movq %rax, -0xd8(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0xd0(%rbp)
callq 0x2040
movl (%rax), %edi
callq 0x2290
movq -0xd8(%rbp), %rdi
movq -0xd0(%rbp), %rcx
movq %rax, %r8
leaq 0x5866(%rip), %rsi      # 0xbc26
leaq 0x51c2(%rip), %rdx      # 0xb589
movb $0x0, %al
callq 0x2150
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6533
movq -0x80(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq -0x20(%rbp), %rdi
xorl %esi, %esi
movb $0x0, %al
callq 0x21f0
movl %eax, -0xb4(%rbp)
cmpl $0x0, %eax
jge 0x643f
jmp 0x63ff
movq 0x9bf2(%rip), %rax      # 0xfff8
movq (%rax), %rax
movq %rax, -0xe0(%rbp)
callq 0x2040
movq -0xe0(%rbp), %rdi
movl (%rax), %ecx
leaq 0x5829(%rip), %rsi      # 0xbc4e
leaq 0x515d(%rip), %rdx      # 0xb589
movb $0x0, %al
callq 0x2150
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6533
movq -0xc0(%rbp), %rdi
callq 0x2190
movq -0x18(%rbp), %rcx
movq %rax, (%rcx)
cmpq $0x0, %rax
jne 0x64a5
jmp 0x645a
movq 0x9b97(%rip), %rax      # 0xfff8
movq (%rax), %rax
movq %rax, -0xe8(%rbp)
callq 0x2040
movq -0xe8(%rbp), %rdi
movl (%rax), %ecx
leaq 0x57f7(%rip), %rsi      # 0xbc77
leaq 0x5102(%rip), %rdx      # 0xb589
movb $0x0, %al
callq 0x2150
movl -0xb4(%rbp), %edi
callq 0x2100
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6533
movl -0xb4(%rbp), %edi
movq -0x18(%rbp), %rax
movq (%rax), %rsi
movq -0xc0(%rbp), %rdx
callq 0x2110
cmpq -0xc0(%rbp), %rax
jge 0x64f2
movq -0x18(%rbp), %rax
movq (%rax), %rdi
callq 0x2030
movq -0x18(%rbp), %rax
movq $0x0, (%rax)
movl -0xb4(%rbp), %edi
callq 0x2100
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6533
jmp 0x64f4
cmpb $0x0, 0x9dd5(%rip)      # 0x102d0
je 0x651c
movq 0x9af4(%rip), %rax      # 0xfff8
movq (%rax), %rdi
leaq 0x579f(%rip), %rsi      # 0xbcad
leaq 0x5074(%rip), %rdx      # 0xb589
movb $0x0, %al
callq 0x2150
jmp 0x651e
movl -0xb4(%rbp), %edi
callq 0x2100
movq -0xc0(%rbp), %rax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xf0, %rsp
popq %rbp
retq
nop