LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_c_makefile_star2_O2/LeoFu9487[P]push_swap/libft/ft_memory.c
// Function: ft_memory
void	*ft_memory(size_t elem_cnt,
size_t elem_size, void *del, t_memory type)
{
	static t_list	*head;
	void			*new_mem;

	if (type == push)
	{
		new_mem = ft_calloc_2(elem_cnt, elem_size);
		if (!new_mem)
			ft_putstr_fd("ERROR_IN_FT_MEMORY_0\n", 1);
		else if (!(ft_lstadd_front(&head, ft_lstnew_2(new_mem))))
			ft_putstr_fd("ERROR_IN_FT_MEMORY_1\n", 1);
		return (new_mem);
	}
	if (type == pop)
		ft_lstdelone_2(&head, ft_lstfind(head, del), free);
	else
		ft_lstclear_2(&head, free);
	return (NULL);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
cmpl $0x1, %ecx
je 0x26ac
testl %ecx, %ecx
jne 0x26f8
movq %rsi, %r14
imulq %rdi, %r14
movq %r14, %rdi
callq 0x1060
testq %rax, %rax
je 0x272b
movq %rax, %rbx
movq %rax, %rdi
xorl %esi, %esi
movq %r14, %rdx
callq 0x25a8
pushq $0x10
popq %rdi
callq 0x1060
movq %rax, %r14
testq %rax, %rax
je 0x2747
movq %rbx, (%r14)
andq $0x0, 0x8(%r14)
jmp 0x2756
movq 0x39ad(%rip), %rdi      # 0x6060
movq %rdx, %rsi
callq 0x27bc
testq %rax, %rax
je 0x27a9
movq %rax, %rbx
movq 0x3992(%rip), %rcx      # 0x6060
cmpq %rax, %rcx
je 0x277a
testq %rcx, %rcx
je 0x279a
movq %rcx, %rax
movq 0x8(%rcx), %rcx
cmpq %rbx, %rcx
jne 0x26d7
addq $0x8, %rax
movq %rbx, %rcx
jmp 0x2781
movq 0x3961(%rip), %r14      # 0x6060
andq $0x0, 0x3959(%rip)      # 0x6060
xorl %ebx, %ebx
testq %r14, %r14
je 0x27ab
movq (%r14), %rdi
callq 0x1030
movq 0x8(%r14), %r15
movq %r14, %rdi
callq 0x1030
movq %r15, %r14
jmp 0x2709
leaq 0x9b8(%rip), %rdi       # 0x30ea
pushq $0x1
popq %rbx
movl %ebx, %esi
callq 0x1d00
leaq 0x97b(%rip), %rdi       # 0x30be
movl %ebx, %esi
jmp 0x27a4
leaq 0x9b2(%rip), %rdi       # 0x3100
pushq $0x1
popq %rsi
callq 0x1d00
leaq 0x3903(%rip), %rdi      # 0x6060
movq %r14, %rsi
callq 0x27d8
testl %eax, %eax
jne 0x27ab
leaq 0x964(%rip), %rdi       # 0x30d4
pushq $0x1
popq %rsi
callq 0x1d00
jmp 0x27ab
leaq 0x38df(%rip), %rax      # 0x6060
movq 0x8(%rcx), %rcx
movq %rcx, (%rax)
movq (%rbx), %rdi
callq 0x1030
movq %rbx, %rdi
callq 0x1030
jmp 0x27a9
leaq 0x975(%rip), %rdi       # 0x3116
pushq $0x1
popq %rsi
callq 0x1d00
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)
// File: /workspace/github_c_makefile_star2_O2/LeoFu9487[P]push_swap/libft/ft_lstfind.c
// Function: ft_lstfind
t_list	*ft_lstfind(t_list *head, void *target)
{
	while (head)
	{
		if (head->content == target)
			return (head);
		head = head->next;
	}
	return (NULL);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, %rax
testq %rax, %rax
je 0x27d3
cmpq %rsi, (%rax)
je 0x27d3
movq 0x8(%rax), %rax
jmp 0x27c3
popq %rbp
retq
nopl (%rax)
// File: /workspace/github_c_makefile_star2_O2/LeoFu9487[P]push_swap/libft/ft_lstadd_front.c
// Function: ft_lstadd_front
int	ft_lstadd_front(t_list **lst, t_list *new)
{
	if (!new || !lst)
	{
		ft_putstr_fd("ERROR_IN_FT_LSTADD_FRONT\n", 1);
		return (0);
	}
	if (!*lst)
	{
		*lst = new;
		return (1);
	}
	new->next = *lst;
	*lst = new;
	return (1);
}

// Assembly:
testq %rsi, %rsi
setne %al
testq %rdi, %rdi
setne %cl
testb %al, %cl
je 0x27fb
movq (%rdi), %rax
testq %rax, %rax
je 0x27f4
movq %rax, 0x8(%rsi)
movq %rsi, (%rdi)
pushq $0x1
popq %rax
retq
pushq %rbp
movq %rsp, %rbp
leaq 0x929(%rip), %rdi       # 0x312f
pushq $0x1
popq %rsi
callq 0x1d00
xorl %eax, %eax
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/tudurom[P]disputils/randr.c
// Function: get_providers
int
get_providers(xcb_connection_t * conn, xcb_screen_t * scrn, xcb_randr_provider_t ** ps)
{
	xcb_randr_get_providers_cookie_t pc;
	pc = xcb_randr_get_providers(conn, scrn->root);

	xcb_randr_get_providers_reply_t *pr;
	pr = xcb_randr_get_providers_reply(conn, pc, NULL);
	if (!pr)
		errx(1, "Could not aquire the array of providers.");

	*ps = xcb_randr_get_providers_providers(pr);

	return xcb_randr_get_providers_providers_length(pr);
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq %rdx, %rbx
movq %rdi, %r14
movl (%rsi), %esi
callq 0x11e0
movq %r14, %rdi
movl %eax, %esi
xorl %edx, %edx
callq 0x1180
testq %rax, %rax
je 0x15cf
movq %rax, %r14
movq %rax, %rdi
callq 0x1090
movq %rax, (%rbx)
movq %r14, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x1170
leaq 0xa97(%rip), %rsi       # 0x206d
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x10b0
// File: /workspace/github_c_makefile_star2_O2/tudurom[P]disputils/randr.c
// Function: get_outputs
int
get_outputs(xcb_connection_t * conn, xcb_randr_provider_t provider, xcb_randr_output_t ** os)
{
	xcb_randr_get_provider_info_cookie_t pic;
	pic = xcb_randr_get_provider_info(conn, provider, 0);

	xcb_randr_get_provider_info_reply_t *pir;
	pir = xcb_randr_get_provider_info_reply(conn, pic, NULL);
	if (!pir)
		errx(1, "Could not aquire the array of outputs.");

	*os = xcb_randr_get_provider_info_outputs(pir);
	return xcb_randr_get_provider_info_outputs_length(pir);
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq %rdx, %rbx
movq %rdi, %r14
xorl %edx, %edx
callq 0x1040
movq %r14, %rdi
movl %eax, %esi
xorl %edx, %edx
callq 0x11b0
testq %rax, %rax
je 0x161f
movq %rax, %r14
movq %rax, %rdi
callq 0x1060
movq %rax, (%rbx)
movq %r14, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x1220
leaq 0xa70(%rip), %rsi       # 0x2096
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x10b0
// File: /workspace/github_c_makefile_star2_O2/tudurom[P]disputils/randr.c
// Function: get_output_info
xcb_randr_get_output_info_reply_t *
get_output_info(xcb_connection_t * conn, xcb_randr_output_t output)
{
	xcb_randr_get_output_info_cookie_t oic;

	oic = xcb_randr_get_output_info(conn, output, 0);
	xcb_randr_get_output_info_reply_t *output_info_reply;

	output_info_reply = xcb_randr_get_output_info_reply(conn, oic, NULL);
	if (!output_info_reply)
		errx(1, "Could not get output info.");

	return output_info_reply;
}

// Assembly:
pushq %rbx
movq %rdi, %rbx
xorl %edx, %edx
callq 0x1230
movq %rbx, %rdi
movl %eax, %esi
xorl %edx, %edx
callq 0x11f0
testq %rax, %rax
je 0x164e
popq %rbx
retq
leaq 0xa68(%rip), %rsi       # 0x20bd
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x10b0
// File: /workspace/github_c_makefile_star2_O2/tudurom[P]disputils/randr.c
// Function: get_output_name
uint8_t*
get_output_name(xcb_connection_t * conn, xcb_randr_output_t output)
{
	xcb_randr_get_output_info_reply_t *r;

	r = get_output_info(conn, output);
	uint8_t *name = xcb_randr_get_output_info_name(r);
	int len = xcb_randr_get_output_info_name_length(r);
	uint8_t *ret  =
		malloc(sizeof(uint8_t) * len + 1);
	int i;
	for (i = 0; i < xcb_randr_get_output_info_name_length(r); i++) {
		ret[i] = name[i];
	}
	ret[len] = '\0';
	return ret;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
callq 0x1630
movq %rax, %rbx
movq %rax, %rdi
callq 0x1160
movq %rax, %r14
movq %rbx, %rdi
callq 0x1070
movslq %eax, %r12
leaq 0x1(%r12), %rdi
callq 0x1150
movq %rax, %r15
xorl %r13d, %r13d
movq %rbx, %rdi
callq 0x1070
cltq
cmpq %rax, %r13
jge 0x16b2
movb (%r14,%r13), %al
movb %al, (%r15,%r13)
incq %r13
jmp 0x1696
movb $0x0, (%r15,%r12)
movq %r15, %rax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O2/tudurom[P]disputils/randr.c
// Function: get_focused_window
xcb_window_t
get_focused_window(xcb_connection_t * conn)
{
	xcb_window_t    win = 0;
	xcb_get_input_focus_cookie_t input_focus_cookie;
	xcb_get_input_focus_reply_t *input_focus_reply;

	input_focus_cookie = xcb_get_input_focus(conn);
	input_focus_reply = xcb_get_input_focus_reply(conn, input_focus_cookie, NULL);
	if (!input_focus_reply)
		errx(1, "Cannot get focused window.");
	win = input_focus_reply->focus;
	free(input_focus_reply);
	return win;
}

// Assembly:
pushq %rbx
movq %rdi, %rbx
callq 0x10e0
movq %rbx, %rdi
movl %eax, %esi
xorl %edx, %edx
callq 0x10d0
testq %rax, %rax
je 0x1711
movl 0x8(%rax), %ebx
movq %rax, %rdi
callq 0x1030
movl %ebx, %eax
popq %rbx
retq
leaq 0x9c0(%rip), %rsi       # 0x20d8
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x10b0
// File: /workspace/github_c_makefile_star2_O2/tudurom[P]disputils/randr.c
// Function: get_window_geometry
xcb_get_geometry_reply_t *
get_window_geometry(xcb_connection_t * conn, xcb_window_t window)
{
	xcb_get_geometry_cookie_t get_geometry_cookie;
	xcb_get_geometry_reply_t *get_geometry_reply;

	get_geometry_cookie = xcb_get_geometry(conn, window);
	get_geometry_reply = xcb_get_geometry_reply(conn, get_geometry_cookie, NULL);

	if (!get_geometry_reply)
		errx(1, "0x%08x: no such window", window);
	return get_geometry_reply;
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movl %esi, %ebx
movq %rdi, %r14
callq 0x1130
movq %r14, %rdi
movl %eax, %esi
xorl %edx, %edx
callq 0x10f0
testq %rax, %rax
je 0x1749
addq $0x8, %rsp
popq %rbx
popq %r14
retq
leaq 0x9a3(%rip), %rsi       # 0x20f3
pushq $0x1
popq %rdi
movl %ebx, %edx
xorl %eax, %eax
callq 0x10b0
// File: /workspace/github_c_makefile_star2_O2/tudurom[P]disputils/randr.c
// Function: get_primary_output
xcb_randr_get_output_primary_reply_t *
get_primary_output(xcb_connection_t * conn)
{
	xcb_screen_t   *scrn;
	xcb_window_t    root;
	xcb_randr_get_output_primary_cookie_t c;
	xcb_randr_get_output_primary_reply_t *primary_output;

	get_screen(conn, &scrn);
	root = scrn->root;

	c = xcb_randr_get_output_primary(conn, root);
	primary_output = xcb_randr_get_output_primary_reply(conn, c, NULL);

	return primary_output;
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq %rsp, %r14
movq %r14, %rsi
callq 0x1564
movq (%r14), %rax
movl (%rax), %esi
movq %rbx, %rdi
callq 0x1210
movq %rbx, %rdi
movl %eax, %esi
xorl %edx, %edx
callq 0x1080
addq $0x8, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_c_makefile_star2_O2/xiane[P]libvphevcodec/AML_HEVCEncoder.cpp
// Function: dumpCodedPicture(AMVHEVCEncHandle_s*, int, unsigned char const*, unsigned int)
void dumpCodedPicture(AMVHEVCEncHandle *Handle, const int idx, const unsigned char *buffer, const uint32_t nal_length) {
    VLOG(INFO, "-------------- Picture[%d] dump --------------", idx);
    VLOG(INFO, " widthxheight - %dx%d", Handle->src_pics[idx].width, Handle->src_pics[idx].height);
    VLOG(INFO, " nal_type     - %x", Handle->src_pics[idx].type);
    VLOG(INFO, " order, pts   - %d, %ld", Handle->src_pics[idx].order,  Handle->src_pics[idx].pts);
    VLOG(INFO, " nal_length   - %d", nal_length);
    VLOG(INFO, "-------------- NAL + PayLoad Start -----------------");

    int max_stride = nal_length / 4;
    for (int i = 0; i < max_stride; i += 8)
        VLOG(INFO, "[%d] %2x %2x %2x %2x %2x %2x %2x %2x", i,
                buffer[i], buffer[i+1], buffer[i+2], buffer[i+3], buffer[i+4], buffer[i+5], buffer[i+6], buffer[i+7]);

    for(int i=0; i < nal_length%4; i++)
        VLOG(INFO, "[%d] %2x", i, buffer[i]);

    VLOG(INFO, "-------------- PayLoad End -------------------");
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %ecx, %r13d
movq %rdx, %r14
movl %esi, %r12d
movq %rdi, %r15
leaq 0x2841e(%rip), %rdi     # 0x2a8c8
xorl %eax, %eax
callq 0x2050
pushq $0xa
popq %rbx
movl %ebx, %edi
callq 0x2230
movslq %r12d, %rax
imulq $0x50, %rax, %r12
movl 0xe4(%r15,%r12), %esi
movl 0xe8(%r15,%r12), %edx
leaq 0x2841e(%rip), %rdi     # 0x2a8f7
xorl %eax, %eax
callq 0x2050
movl %ebx, %edi
callq 0x2230
movl 0xb8(%r15,%r12), %esi
leaq 0x28417(%rip), %rdi     # 0x2a90d
xorl %eax, %eax
callq 0x2050
movl %ebx, %edi
callq 0x2230
movl 0xe0(%r15,%r12), %esi
movq 0xa0(%r15,%r12), %rdx
leaq 0x28405(%rip), %rdi     # 0x2a920
xorl %eax, %eax
callq 0x2050
movl %ebx, %edi
callq 0x2230
leaq 0x28408(%rip), %rdi     # 0x2a938
movl %r13d, %esi
xorl %eax, %eax
callq 0x2050
movl %ebx, %edi
callq 0x2230
leaq 0x28403(%rip), %rdi     # 0x2a94b
xorl %eax, %eax
callq 0x2050
movl %ebx, %edi
callq 0x2230
movq %r13, (%rsp)
shrl $0x2, %r13d
leaq 0x2841b(%rip), %r15     # 0x2a980
xorl %r12d, %r12d
cmpq %r13, %r12
jae 0x25c1
movzbl (%r14,%r12), %edx
movzbl 0x1(%r14,%r12), %ecx
movzbl 0x2(%r14,%r12), %r8d
movzbl 0x3(%r14,%r12), %r9d
movzbl 0x4(%r14,%r12), %r10d
movzbl 0x5(%r14,%r12), %r11d
movzbl 0x6(%r14,%r12), %ebp
movzbl 0x7(%r14,%r12), %ebx
movq %r15, %rdi
movl %r12d, %esi
xorl %eax, %eax
pushq %rbx
pushq %rbp
pushq %r11
pushq %r10
callq 0x2050
addq $0x20, %rsp
pushq $0xa
popq %rdi
callq 0x2230
addq $0x8, %r12
jmp 0x2568
movq (%rsp), %rbx
andl $0x3, %ebx
leaq 0x283d6(%rip), %r15     # 0x2a9a5
pushq $0xa
popq %rbp
xorl %r12d, %r12d
cmpq %r12, %rbx
je 0x25f8
movzbl (%r14,%r12), %edx
movq %r15, %rdi
movl %r12d, %esi
xorl %eax, %eax
callq 0x2050
movl %ebp, %edi
callq 0x2230
incq %r12
jmp 0x25d5
leaq 0x283af(%rip), %rdi     # 0x2a9ae
xorl %eax, %eax
callq 0x2050
pushq $0xa
popq %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2230
// File: /workspace/github_c_makefile_star2_O2/xiane[P]libvphevcodec/AML_HEVCEncoder.cpp
// Function: Wave4BitIssueCommand(unsigned int, unsigned int, unsigned int)
void Wave4BitIssueCommand(Uint32 coreIdx, Uint32 instanceIndex, Uint32 cmd) {

	(void)instanceIndex;

    VpuWriteReg(coreIdx, W4_VPU_BUSY_STATUS, 1);
    VpuWriteReg(coreIdx, W4_RET_SUCCESS, 0);  //for debug
    //VpuWriteReg(coreIdx, W4_CORE_INDEX, 0);
    //VpuWriteReg(coreIdx, W4_INST_INDEX, (instanceIndex & 0xffff) | (codecMode << 16));

    VpuWriteReg(coreIdx, W4_COMMAND, cmd);
    VpuWriteReg(coreIdx, W4_VPU_HOST_INT_REQ, 1);
    return;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
movl %edx, %ebx
movl %edi, %ebp
pushq $0x70
popq %rsi
pushq $0x1
popq %r14
movl %r14d, %edx
callq 0x2160
movl %ebp, %edi
movl $0x110, %esi            # imm = 0x110
xorl %edx, %edx
callq 0x2160
movl %ebp, %edi
movl $0x100, %esi            # imm = 0x100
movl %ebx, %edx
callq 0x2160
pushq $0x38
popq %rsi
movl %ebp, %edi
movl %r14d, %edx
popq %rbx
popq %r14
popq %rbp
jmp 0x2160
// File: /workspace/github_c_makefile_star2_O2/xiane[P]libvphevcodec/AML_HEVCEncoder.cpp
// Function: Wave4VpuReset(AMVHEVCEncHandle_s*, unsigned int, int)
AMVEnc_Status Wave4VpuReset(AMVHEVCEncHandle *Handle, Uint32 coreIdx, int resetMode) {
    u32 val = 0;

    // VPU doesn't send response. Force to set BUSY flag to 0.
    VpuWriteReg(coreIdx, W4_VPU_BUSY_STATUS, 0);

    if (resetMode == SW_RESET_SAFETY) {
        Wave4VpuSleepWake(Handle, coreIdx, 1, NULL, 0, 0);
    }

    switch (resetMode) {
    case SW_RESET_ON_BOOT:
        val = W4_RST_BLOCK_ALL;
        break;
    case SW_RESET_FORCE:
        val = W4_RST_BLOCK_BCLK_ALL | W4_RST_BLOCK_CCLK_ALL;
        break;
    case SW_RESET_SAFETY:
        val = W4_RST_BLOCK_ACLK_ALL | W4_RST_BLOCK_BCLK_ALL | W4_RST_BLOCK_CCLK_ALL;
        break;
    default:
        return AMVENC_NOT_SUPPORTED;
    }

    if (val) {
        VpuWriteReg(coreIdx, W4_VPU_RESET_REQ, val);
        if (vdi_wait_vpu_busy(coreIdx, VPU_BUSY_CHECK_TIMEOUT, W4_VPU_RESET_STATUS) == -1) {
            VpuWriteReg(coreIdx, W4_VPU_RESET_REQ, 0);
            VLOG(INFO, "Wave4VpuReset time out reset");
            reset_error = 1;
            return AMVENC_TIMEOUT;
        }
        VpuWriteReg(coreIdx, W4_VPU_RESET_REQ, 0);
    }

    if (resetMode == SW_RESET_SAFETY || resetMode == SW_RESET_ON_BOOT) {
        Wave4VpuSleepWake(Handle, coreIdx, 0, NULL, 0, val);
    }
    return AMVENC_SUCCESS;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %edx, %ebp
movl %esi, %ebx
movq %rdi, %r14
pushq $0x70
popq %rsi
movl %ebx, %edi
xorl %edx, %edx
callq 0x2160
cmpl $0x2, %ebp
je 0x4596
cmpl $0x1, %ebp
je 0x458e
testl %ebp, %ebp
jne 0x460f
pushq $0x1
popq %rdx
movq %r14, %rdi
movl %ebx, %esi
xorl %r9d, %r9d
callq 0x21e0
movl $0xffffff, %r15d        # imm = 0xFFFFFF
jmp 0x459c
movl $0xffff, %r15d          # imm = 0xFFFF
jmp 0x459c
movl $0xfffffff, %r15d       # imm = 0xFFFFFFF
pushq $0x50
popq %r12
movl %ebx, %edi
movl %r12d, %esi
movl %r15d, %edx
callq 0x2160
pushq $0x54
popq %rdx
movl %ebx, %edi
movl $0x1388, %esi           # imm = 0x1388
callq 0x2060
movl %eax, %r13d
movl %ebx, %edi
movl %r12d, %esi
xorl %edx, %edx
callq 0x2160
cmpl $-0x1, %r13d
je 0x45ee
pushq $0x1
popq %r12
testl $0xfffffffd, %ebp       # imm = 0xFFFFFFFD
jne 0x4613
movq %r14, %rdi
movl %ebx, %esi
xorl %edx, %edx
movl %r15d, %r9d
callq 0x21e0
jmp 0x4613
leaq 0x277c2(%rip), %rdi     # 0x2bdb7
xorl %eax, %eax
callq 0x2050
pushq $0xa
popq %rdi
callq 0x2230
movb $0x1, 0x2abe9(%rip)     # 0x2f1f4
pushq $-0x24
jmp 0x4611
pushq $-0x2
popq %r12
movl %r12d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/xiane[P]libvphevcodec/AML_HEVCEncoder.cpp
// Function: AML_HEVCEncNAL(AMVHEVCEncHandle_s*, unsigned char*, unsigned int*, int*)
AMVEnc_Status AML_HEVCEncNAL(AMVHEVCEncHandle *Handle, unsigned char *buffer, unsigned int *buf_nal_size, int *nal_type) {
    AMVEnc_Status ret = AMVENC_FAIL;
    int end = 0;
    int reset_count = 0;

    if (reset_error)
        return ret;
retry:
    ret = Wave4VpuEncEncPic(Handle, Handle->src_idx, end, buffer, buf_nal_size, nal_type);

    if (ret != AMVENC_SUCCESS) {
        if (ret == AMVENC_OVERFLOW)
            return ret;
        if (reset_mode == 2) {
            Wave4VpuCreateInstance(Handle, 0);
        }
        Wave4VpuEncSeqInit(Handle, 0);
        if (Handle->mGopIdx == 0)
            Wave4VpuEncSeqSet(Handle);
        Handle->src_count = VpuReadReg(Handle->instance_id, W4_RET_ENC_MIN_SRC_BUF_NUM);
        Wave4VpuEncRegisterFrame(Handle, 0);
        Handle->src_idx = 0;
        reset_count++;
        if (reset_count < 5)
            goto retry;

        //ret = AMVENC_REENCODE_PICTURE;
        //return ret;
    }
    Handle->src_idx++;
    Handle->src_idx = Handle->src_idx % Handle->src_count;
    Handle->enc_counter++;

    return AMVENC_PICTURE_READY;
}

// Assembly:
xorl %eax, %eax
cmpb $0x0, 0x28c61(%rip)     # 0x2f1f4
jne 0x6646
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rcx, %r14
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %rbx
movl 0x4(%rdi), %r13d
pushq $0x5
popq %rbp
movq %rbx, %rdi
movl %r13d, %esi
xorl %edx, %edx
movq %r12, %rcx
movq %r15, %r8
movq %r14, %r9
callq 0x23b0
cmpl $-0x27, %eax
je 0x6638
cmpl $0x1, %eax
je 0x6625
movq %rbx, %rdi
xorl %esi, %esi
callq 0x21c0
movq %rbx, %rdi
xorl %esi, %esi
callq 0x2090
cmpl $0x0, 0x304(%rbx)
jne 0x65fc
movq %rbx, %rdi
callq 0x20e0
movl (%rbx), %edi
movl $0x1d8, %esi            # imm = 0x1D8
callq 0x2210
movl %eax, 0x8(%rbx)
xorl %r13d, %r13d
movq %rbx, %rdi
xorl %esi, %esi
callq 0x2330
andl $0x0, 0x4(%rbx)
decl %ebp
jne 0x65b7
pushq $0x1
popq %rax
jmp 0x662a
movl 0x4(%rbx), %eax
incl %eax
xorl %edx, %edx
divl 0x8(%rbx)
movl %edx, 0x4(%rbx)
incl 0x2c(%rbx)
pushq $0x2
popq %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/xiane[P]libvphevcodec/libvp_hevc_codec.cpp
// Function: vl_video_encoder_destroy
int vl_video_encoder_destroy(vl_codec_handle_t codec_handle) {
    AMVHEVCEncHandle *handle = (AMVHEVCEncHandle *)codec_handle;
    AML_HEVCRelease(handle);
    if (handle->mSPSPPSData)
        free(handle->mSPSPPSData);
    if (handle->mEncParams)
        destroyEncParams(handle->mEncParams);
    if (handle)
        delete handle;
    return 1;
}

// Assembly:
pushq %rbx
movq %rdi, %rbx
callq 0x2280
movq 0x2f0(%rbx), %rdi
callq 0x2200
movq 0x2e0(%rbx), %rdi
testq %rdi, %rdi
je 0x6c4c
callq 0x20c0
testq %rbx, %rbx
je 0x6c5e
movl $0x310, %esi            # imm = 0x310
movq %rbx, %rdi
callq 0x21d0
pushq $0x1
popq %rax
popq %rbx
retq
nop
// File: /workspace/github_c_makefile_star2_O2/xiane[P]libvphevcodec/vdi.cpp
// Function: vdi_get_instance_pool(unsigned int)
vpu_instance_pool_t *vdi_get_instance_pool(u32 core_idx) {
    vdi_info_t *vdi;
    vpu_buffer_t vdb;

    if (core_idx >= MAX_NUM_VPU_CORE)
        return NULL;

    vdi = &s_vdi_info[core_idx];
    if (!vdi || vdi->vpu_fd < 0 || vdi->opened == 0)
        return NULL;

    memset(&vdb, 0x00, sizeof(vpu_buffer_t));
    memset(&vdi->instance_pool, 0x00, sizeof(vpu_buffer_t));
    if (!vdi->pvip) {
        vdb.size = sizeof(vpu_instance_pool_t);
        vdb.cached = 0;
        if (ioctl(vdi->vpu_fd, VDI_IOCTL_GET_INSTANCE_POOL, &vdb) < 0) {
            VLOG(ERR, "[VDI] fail to allocate get instance pool physical space=0x%x", vdb.size);
            return NULL;
        }

        vdb.virt_addr = (ulong) mmap(NULL, vdb.size, PROT_READ | PROT_WRITE, MAP_SHARED, vdi->vpu_fd, 0);
        if ((void *) vdb.virt_addr == MAP_FAILED) {
            VLOG(ERR, "[VDI] fail to map instance pool phyaddr=0x%lx, size = 0x%x", vdb.phys_addr, vdb.size);
            return NULL;
        }
        vdi->instance_pool = vdb;
        vdi->pvip = (vpu_instance_pool_t *) (vdb.virt_addr + (core_idx * sizeof(vpu_instance_pool_t)));
        VLOG(DEBUG, "[VDI] instance pool physaddr=0x%lx, virtaddr=0x%lx, base=0x%lx, size=0x%x",
                                                          vdb.phys_addr, vdb.virt_addr, vdb.base, vdb.size);
    }
    return (vpu_instance_pool_t *) vdi->pvip;
}

// Assembly:
pushq %rbx
subq $0x20, %rsp
testl %edi, %edi
je 0x6f5b
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x20, %rsp
popq %rbx
retq
movl 0x282a3(%rip), %edi     # 0x2f204
xorl %ebx, %ebx
testl %edi, %edi
js 0x6f52
cmpb $0x0, 0x2829a(%rip)     # 0x2f208
je 0x6f52
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rsp)
andq $0x0, 0x18(%rsp)
movaps %xmm0, 0x282bb(%rip)    # 0x2f240
movaps %xmm0, 0x282c4(%rip)    # 0x2f250
movq 0x2827d(%rip), %rbx     # 0x2f210
testq %rbx, %rbx
jne 0x6f52
movq %rsp, %rbx
movq $0x20028, (%rbx)        # imm = 0x20028
movl $0x40205605, %esi       # imm = 0x40205605
movq %rbx, %rdx
xorl %eax, %eax
callq 0x2240
movl (%rbx), %esi
testl %eax, %eax
js 0x6fff
movl 0x28246(%rip), %r8d     # 0x2f204
pushq $0x3
popq %rdx
pushq $0x1
popq %rcx
xorl %edi, %edi
xorl %r9d, %r9d
callq 0x2340
movq %rax, 0x18(%rsp)
cmpq $-0x1, %rax
je 0x7011
movq %rax, %rbx
movups (%rsp), %xmm0
movups 0x10(%rsp), %xmm1
movaps %xmm1, 0x28264(%rip)    # 0x2f250
movaps %xmm0, 0x2824d(%rip)    # 0x2f240
movq %rax, 0x28216(%rip)     # 0x2f210
jmp 0x6f52
leaq 0x25512(%rip), %rdi     # 0x2c518
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x2050
jmp 0x7029
movq 0x8(%rsp), %rsi
movl (%rsp), %edx
leaq 0x25535(%rip), %rdi     # 0x2c555
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x2050
pushq $0xa
popq %rdi
callq 0x2230
jmp 0x6f52
// File: /workspace/github_c_makefile_star2_O2/xiane[P]libvphevcodec/vdi.cpp
// Function: vdi_set_clock_gate(unsigned int, unsigned int)
s32 vdi_set_clock_gate(u32 core_idx, u32 enable) {
    vdi_info_t *vdi;
    s32 ret;

    if (core_idx >= MAX_NUM_VPU_CORE)
        return -1;

    vdi = &s_vdi_info[core_idx];
    if (!vdi || vdi->vpu_fd < 0 || vdi->opened == 0)
        return -1;

    vdi->clock_state = enable;
    ret = ioctl(vdi->vpu_fd, VDI_IOCTL_SET_CLOCK_GATE, &enable);
    return ret;
}

// Assembly:
pushq %rax
movl %esi, 0x4(%rsp)
pushq $-0x1
popq %rax
testl %edi, %edi
jne 0x706c
movl 0x281bc(%rip), %edi     # 0x2f204
testl %edi, %edi
js 0x706c
cmpb $0x0, 0x281b5(%rip)     # 0x2f208
je 0x706c
movl %esi, 0x281c1(%rip)     # 0x2f21c
leaq 0x4(%rsp), %rdx
movl $0x40045603, %esi       # imm = 0x40045603
xorl %eax, %eax
callq 0x2240
popq %rcx
retq
// File: /workspace/github_c_makefile_star2_O2/xiane[P]libvphevcodec/vdi.cpp
// Function: vdi_release(unsigned int)
s32 vdi_release(u32 core_idx) {
    s32 i;
    vpu_buffer_t vdb;
    vdi_info_t *vdi;

    if (core_idx >= MAX_NUM_VPU_CORE)
        return 0;

    vdi = &s_vdi_info[core_idx];
    if (!vdi || vdi->vpu_fd < 0 || vdi->opened == 0)
        return 0;

    if (vdi->task_num > 1) {
        // means that the opened instance remains
        vdi->task_num--;
        return 0;
    }

    if (vdi->vdb_register.virt_addr)
        munmap((void *) vdi->vdb_register.virt_addr, vdi->vdb_register.size);

    memset(&vdi->vdb_register, 0x00, sizeof(vpu_buffer_t));
    vdb.size = 0;
    // get common memory information to free virtual address
    for (i = 0; i < MAX_VPU_BUFFER_POOL; i++) {
        if (vdi->vpu_common_memory.phys_addr >= vdi->vpu_buffer_pool[i].vdb.phys_addr
           && vdi->vpu_common_memory.phys_addr < (vdi->vpu_buffer_pool[i].vdb.phys_addr + vdi->vpu_buffer_pool[i].vdb.size)) {
            vdi->vpu_buffer_pool[i].inuse = 0;
            vdi->vpu_buffer_pool_count--;
            vdb = vdi->vpu_buffer_pool[i].vdb;
            break;
        }
    }

    if (vdb.size > 0) {
        munmap((void *) vdb.virt_addr, vdb.size);
        memset(&vdi->vpu_common_memory, 0x00, sizeof(vpu_buffer_t));
    }

    if (vdi->instance_pool.virt_addr)
        munmap((void *) vdi->instance_pool.virt_addr, vdi->instance_pool.size);

    vdi->task_num--;

    if (vdi->vpu_fd >= 0) {
        close(vdi->vpu_fd);
        vdi->vpu_fd = -1;
    }
    memset(vdi, 0x00, sizeof(vdi_info_t));
    vdi->vpu_fd = -1;
    return 0;
}

// Assembly:
testl %edi, %edi
je 0x7075
xorl %eax, %eax
retq
cmpl $0x0, 0x28188(%rip)     # 0x2f204
js 0x7072
cmpb $0x0, 0x28183(%rip)     # 0x2f208
je 0x7072
movl 0x2818b(%rip), %eax     # 0x2f218
cmpl $0x2, %eax
jb 0x709c
decl %eax
movl %eax, 0x2817e(%rip)     # 0x2f218
jmp 0x7072
pushq %rax
movq 0x28194(%rip), %rdi     # 0x2f238
testq %rdi, %rdi
je 0x70b4
movl 0x28171(%rip), %esi     # 0x2f220
callq 0x2100
xorps %xmm0, %xmm0
movaps %xmm0, 0x28172(%rip)    # 0x2f230
movaps %xmm0, 0x2815b(%rip)    # 0x2f220
movq 0x2819c(%rip), %rdx     # 0x2f268
xorl %eax, %eax
leaq 0x2812b(%rip), %rcx     # 0x2f200
cmpq $0x2800, %rax           # imm = 0x2800
je 0x7137
movq 0x88(%rax,%rcx), %rsi
cmpq %rsi, %rdx
jb 0x70f9
movl 0x80(%rax,%rcx), %edi
addq %rdi, %rsi
cmpq %rsi, %rdx
jb 0x70ff
addq $0x28, %rax
jmp 0x70d5
andl $0x0, 0xa0(%rax,%rcx)
decl 0x2a973(%rip)           # 0x31a80
movl 0x80(%rax,%rcx), %esi
testq %rsi, %rsi
je 0x7137
movq 0x98(%rax,%rcx), %rdi
callq 0x2100
xorps %xmm0, %xmm0
movaps %xmm0, 0x28130(%rip)    # 0x2f260
movaps %xmm0, 0x28139(%rip)    # 0x2f270
movq 0x2811a(%rip), %rdi     # 0x2f258
testq %rdi, %rdi
je 0x714e
movl 0x280f7(%rip), %esi     # 0x2f240
callq 0x2100
decl 0x280c4(%rip)           # 0x2f218
movl 0x280aa(%rip), %edi     # 0x2f204
testl %edi, %edi
js 0x7163
callq 0x2390
leaq 0x28096(%rip), %rdi     # 0x2f200
movl $0x2888, %edx           # imm = 0x2888
xorl %esi, %esi
callq 0x20f0
orl $-0x1, 0x28087(%rip)    # 0x2f204
addq $0x8, %rsp
jmp 0x7072
// File: /workspace/github_c_makefile_star2_O2/xiane[P]libvphevcodec/vdi.cpp
// Function: vdi_set_bit_firmware_to_pm(unsigned int, unsigned short const*)
s32 vdi_set_bit_firmware_to_pm(u32 core_idx, const u16 *code) {
    s32 i;
    vpu_bit_firmware_info_t bit_firmware_info;
    vdi_info_t *vdi;

    if (core_idx >= MAX_NUM_VPU_CORE)
        return 0;

    vdi = &s_vdi_info[core_idx];
    if (!vdi || vdi->vpu_fd < 0 || vdi->opened == 0)
        return 0;

    bit_firmware_info.size = sizeof(vpu_bit_firmware_info_t);
    bit_firmware_info.core_idx = core_idx;
    bit_firmware_info.reg_base_offset = 0;
    for (i = 0; i < 512; i++)
        bit_firmware_info.bit_code[i] = code[i];

    if (write(vdi->vpu_fd, &bit_firmware_info, bit_firmware_info.size) < 0) {
        VLOG(ERR, "[VDI] fail to vdi_set_bit_firmware core=%d", bit_firmware_info.core_idx);
        return -1;
    }
    return 0;
}

// Assembly:
xorl %eax, %eax
testl %edi, %edi
je 0x718d
retq
movl 0x28071(%rip), %edi     # 0x2f204
testl %edi, %edi
js 0x718c
cmpb $0x0, 0x2806a(%rip)     # 0x2f208
je 0x718c
subq $0x418, %rsp            # imm = 0x418
movq $0x40c, 0xc(%rsp)       # imm = 0x40C
andl $0x0, 0x14(%rsp)
xorl %eax, %eax
cmpq $0x200, %rax            # imm = 0x200
je 0x71cd
movzwl (%rsi,%rax,2), %ecx
movw %cx, 0x18(%rsp,%rax,2)
incq %rax
jmp 0x71b7
leaq 0xc(%rsp), %rsi
movl $0x40c, %edx            # imm = 0x40C
callq 0x20d0
movq %rax, %rcx
xorl %eax, %eax
testq %rcx, %rcx
jns 0x7201
leaq 0x25300(%rip), %rdi     # 0x2c4ed
xorl %esi, %esi
xorl %eax, %eax
callq 0x2050
pushq $0xa
popq %rdi
callq 0x2230
pushq $-0x1
popq %rax
addq $0x418, %rsp            # imm = 0x418
retq
// File: /workspace/github_c_makefile_star2_O2/xiane[P]libvphevcodec/vdi.cpp
// Function: vdi_get_common_memory(unsigned int, vpu_buffer_t*)
s32 vdi_get_common_memory(u32 core_idx, vpu_buffer_t *vb) {
    vdi_info_t *vdi;

    if (core_idx >= MAX_NUM_VPU_CORE)
        return -1;

    vdi = &s_vdi_info[core_idx];
    if (!vdi || vdi->vpu_fd < 0 || vdi->opened == 0)
        return -1;

    memcpy(vb, &vdi->vpu_common_memory, sizeof(vpu_buffer_t));
    return 0;
}

// Assembly:
pushq $-0x1
popq %rax
testl %edi, %edi
je 0x7211
retq
cmpl $0x0, 0x27fec(%rip)     # 0x2f204
js 0x7210
cmpb $0x0, 0x27fe7(%rip)     # 0x2f208
je 0x7210
movaps 0x28046(%rip), %xmm0    # 0x2f270
movups %xmm0, 0x10(%rsi)
movaps 0x2802b(%rip), %xmm0    # 0x2f260
movups %xmm0, (%rsi)
xorl %eax, %eax
retq
// File: /workspace/github_c_makefile_star2_O2/xiane[P]libvphevcodec/vdi.cpp
// Function: vdi_open_instance(unsigned int, unsigned int)
s32 vdi_open_instance(u32 core_idx, u32 inst_idx) {
    vdi_info_t *vdi;
    vpudrv_inst_info_t inst_info;
    u32* pCodecInst;

    if (core_idx >= MAX_NUM_VPU_CORE)
        return -1;

    vdi = &s_vdi_info[core_idx];
    if (!vdi || vdi->vpu_fd < 0 || vdi->opened == 0)
        return -1;

    inst_info.core_idx = core_idx;
    inst_info.inst_idx = inst_idx;
    if (ioctl(vdi->vpu_fd, VDI_IOCTL_OPEN_INSTANCE, &inst_info) < 0) {
        VLOG(ERR, "[VDI] fail to deliver open instance num inst_idx=%d", inst_idx);
        return -1;
    }
    vdi->pvip->vpu_instance_num = inst_info.inst_open_count;
    pCodecInst = (u32 *) vdi->pvip->codecInstPool[inst_idx];
    pCodecInst[0] = 1;
    return 0;
}

// Assembly:
pushq %rbp
pushq %rbx
subq $0x18, %rsp
pushq $-0x1
popq %rbx
testl %edi, %edi
je 0x7251
movl %ebx, %eax
addq $0x18, %rsp
popq %rbx
popq %rbp
retq
movl 0x27fad(%rip), %edi     # 0x2f204
testl %edi, %edi
js 0x7248
cmpb $0x0, 0x27fa6(%rip)     # 0x2f208
je 0x7248
movl %esi, %ebp
leaq 0xc(%rsp), %rdx
andl $0x0, (%rdx)
movl %esi, 0x4(%rdx)
movl $0x400c5609, %esi       # imm = 0x400C5609
xorl %eax, %eax
callq 0x2240
testl %eax, %eax
js 0x72a3
movl 0x14(%rsp), %eax
movq 0x27f84(%rip), %rcx     # 0x2f210
movl %eax, 0x20020(%rcx)
movl %ebp, %eax
shlq $0xf, %rax
movl $0x1, (%rcx,%rax)
xorl %ebx, %ebx
jmp 0x7248
leaq 0x252e6(%rip), %rdi     # 0x2c590
movl %ebp, %esi
xorl %eax, %eax
callq 0x2050
pushq $0xa
popq %rdi
callq 0x2230
jmp 0x7248
// File: /workspace/github_c_makefile_star2_O2/xiane[P]libvphevcodec/vdi.cpp
// Function: vdi_get_instance_num(unsigned int)
s32 vdi_get_instance_num(u32 core_idx) {
    vdi_info_t *vdi;

    if (core_idx >= MAX_NUM_VPU_CORE)
        return -1;

    vdi = &s_vdi_info[core_idx];
    if (!vdi || vdi->vpu_fd < 0 || vdi->opened == 0)
        return -1;

    return vdi->pvip->vpu_instance_num;
}

// Assembly:
pushq $-0x1
popq %rax
testl %edi, %edi
je 0x7347
retq
cmpl $0x0, 0x27eb6(%rip)     # 0x2f204
js 0x7346
cmpb $0x0, 0x27eb1(%rip)     # 0x2f208
je 0x7346
movq 0x27eb0(%rip), %rax     # 0x2f210
movl 0x20020(%rax), %eax
retq
// File: /workspace/github_c_makefile_star2_O2/xiane[P]libvphevcodec/vdi.cpp
// Function: vdi_read_register(unsigned int, unsigned int)
u32 vdi_read_register(u32 core_idx, u32 addr) {
    vdi_info_t *vdi;
    ulong *reg_addr;

    if (core_idx >= MAX_NUM_VPU_CORE)
        return (u32) -1;

    vdi = &s_vdi_info[core_idx];
    if (!vdi || vdi->vpu_fd < 0 || vdi->opened == 0)
        return (u32) -1;

    reg_addr = (ulong *) (addr + (ulong) vdi->vdb_register.virt_addr);
    return *(volatile u32 *) reg_addr;
}

// Assembly:
pushq $-0x1
popq %rax
testl %edi, %edi
je 0x73bc
retq
cmpl $0x0, 0x27e41(%rip)     # 0x2f204
js 0x73bb
cmpb $0x0, 0x27e3c(%rip)     # 0x2f208
je 0x73bb
movl %esi, %eax
movq 0x27e61(%rip), %rcx     # 0x2f238
movl (%rcx,%rax), %eax
retq
// File: /workspace/github_c_makefile_star2_O2/xiane[P]libvphevcodec/vdi.cpp
// Function: vdi_fio_read_register(unsigned int, unsigned int)
u32 vdi_fio_read_register(u32 core_idx, u32 addr) {
    u32 ctrl;
    u32 count = 0;
    u32 data = 0xffffffff;

    ctrl = (addr & 0xffff);
    ctrl |= (0 << 16); /* read operation */
    vdi_write_register(core_idx, W4_VPU_FIO_CTRL_ADDR, ctrl);
    count = FIO_TIMEOUT;
    while (count--) {
        ctrl = vdi_read_register(core_idx, W4_VPU_FIO_CTRL_ADDR);
        if (ctrl & 0x80000000) {
            data = vdi_read_register(core_idx, W4_VPU_FIO_DATA);
            break;
        }
    }
    return data;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
movl %edi, %ebx
movzwl %si, %edx
pushq $0x20
popq %rbp
movl %ebp, %esi
callq 0x2160
movl $0xffffd8ef, %r14d      # imm = 0xFFFFD8EF
incl %r14d
je 0x7414
movl %ebx, %edi
movl %ebp, %esi
callq 0x2210
testl %eax, %eax
jns 0x73f4
pushq $0x24
popq %rsi
movl %ebx, %edi
popq %rbx
popq %r14
popq %rbp
jmp 0x2210
pushq $-0x1
popq %rax
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/xiane[P]libvphevcodec/vdi.cpp
// Function: vdi_fio_write_register(unsigned int, unsigned int, unsigned int)
void vdi_fio_write_register(u32 core_idx, u32 addr, u32 data) {
    u32 ctrl;
    vdi_write_register(core_idx, W4_VPU_FIO_DATA, data);
    ctrl = (addr & 0xffff);
    ctrl |= (1 << 16); /* write operation */
    vdi_write_register(core_idx, W4_VPU_FIO_CTRL_ADDR, ctrl);
}

// Assembly:
pushq %rbp
pushq %rbx
pushq %rax
movl %esi, %ebx
movl %edi, %ebp
pushq $0x24
popq %rsi
callq 0x2160
movzwl %bx, %edx
orl $0x10000, %edx          # imm = 0x10000
pushq $0x20
popq %rsi
movl %ebp, %edi
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0x2160
// File: /workspace/github_c_makefile_star2_O2/xiane[P]libvphevcodec/vdi.cpp
// Function: ReadRegVCE(unsigned int, unsigned int, unsigned int)
u32 ReadRegVCE(u32 core_idx, u32 vce_core_idx, u32 vce_addr) {
    s32 vcpu_reg_addr;
    s32 udata;
    s32 vce_core_base = 0x8000 + 0x1000 * vce_core_idx;

    vdi_fio_write_register(core_idx, VCORE_DBG_READY(vce_core_idx), 0);

    vcpu_reg_addr = vce_addr >> 2;

    vdi_fio_write_register(core_idx, VCORE_DBG_ADDR(vce_core_idx), vcpu_reg_addr + vce_core_base);

    if (vdi_fio_read_register(0, VCORE_DBG_READY(vce_core_idx)) == 1)
        udata = vdi_fio_read_register(0, VCORE_DBG_DATA(vce_core_idx));
    else
        udata = -1;
    return udata;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movl %edx, %r14d
movl %esi, %ebx
movl %edi, %ebp
shll $0xc, %ebx
leal 0x8308(%rbx), %r15d
movl %r15d, %esi
xorl %edx, %edx
callq 0x2070
shrl $0x2, %r14d
leal 0x8300(%rbx), %esi
leal (%rbx,%r14), %edx
addl $0x8000, %edx           # imm = 0x8000
movl %ebp, %edi
callq 0x2070
xorl %edi, %edi
movl %r15d, %esi
callq 0x2030
cmpl $0x1, %eax
jne 0x7510
addl $0x8304, %ebx           # imm = 0x8304
xorl %edi, %edi
movl %ebx, %esi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x2030
pushq $-0x1
popq %rax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/xiane[P]libvphevcodec/vdi.cpp
// Function: vdi_clear_memory(unsigned int, unsigned int, unsigned int)
s32 vdi_clear_memory(u32 core_idx, u32 addr, u32 len) {
    vdi_info_t *vdi;
    vpu_buffer_t vdb;
    ulong offset;
    s32 i;
    u8 *zero;
    if (core_idx >= MAX_NUM_VPU_CORE)
        return -1;

    vdi = &s_vdi_info[core_idx];
    if (!vdi || vdi->vpu_fd < 0 || vdi->opened == 0)
        return -1;

    memset(&vdb, 0x00, sizeof(vpu_buffer_t));

    for (i = 0; i < MAX_VPU_BUFFER_POOL; i++) {
        if (vdi->vpu_buffer_pool[i].inuse == 1) {
            vdb = vdi->vpu_buffer_pool[i].vdb;
            if (addr >= vdb.phys_addr && addr < (vdb.phys_addr + vdb.size))
                break;
        }
    }
    if (!vdb.size) {
        VLOG(ERR, "address 0x%08x is not mapped address!!!", addr);
        return -1;
    }

    zero = (u8 *) malloc(len);
    if (!zero)
        return -1;

    memset((void *) zero, 0x00, len);
    offset = addr - (ulong) vdb.phys_addr;
    memcpy((void *) ((ulong) vdb.virt_addr + offset), zero, len);
    free(zero);
    return len;
}

// Assembly:
pushq %rbp
pushq %rbx
pushq %rax
pushq $-0x1
popq %rbx
testl %edi, %edi
je 0x7531
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
cmpl $0x0, 0x27ccc(%rip)     # 0x2f204
js 0x7528
cmpb $0x0, 0x27cc7(%rip)     # 0x2f208
je 0x7528
movl %edx, %ebp
movl %esi, %edi
xorl %eax, %eax
movl $0xa0, %r8d
leaq 0x27caa(%rip), %r9      # 0x2f200
xorl %ecx, %ecx
xorl %edx, %edx
cmpq $0x28a0, %r8            # imm = 0x28A0
je 0x758f
cmpl $0x1, (%r8,%r9)
jne 0x7589
movl -0x20(%r8,%r9), %edx
movq -0x18(%r8,%r9), %rax
movq -0x8(%r8,%r9), %rcx
cmpq %rdi, %rax
ja 0x7589
movq %rdx, %r10
addq %rax, %r10
cmpq %rdi, %r10
ja 0x758f
addq $0x28, %r8
jmp 0x755a
testl %edx, %edx
je 0x75a6
movl %ebp, %edx
subq %rax, %rdi
addq %rcx, %rdi
xorl %esi, %esi
callq 0x20f0
movl %ebp, %ebx
jmp 0x7528
leaq 0x25017(%rip), %rdi     # 0x2c5c4
xorl %eax, %eax
callq 0x2050
pushq $0xa
popq %rdi
callq 0x2230
jmp 0x7528
// File: /workspace/github_c_makefile_star2_O2/xiane[P]libvphevcodec/vdi.cpp
// Function: vdi_set_sdram(unsigned int, unsigned int, unsigned int, unsigned char)
void vdi_set_sdram(u32 core_idx, u32 addr, u32 len, u8 data) {
    vdi_info_t *vdi;
    u8 *buf;

    if (core_idx >= MAX_NUM_VPU_CORE)
        return;

    vdi = &s_vdi_info[core_idx];
    if (!vdi || vdi->vpu_fd < 0 || vdi->opened == 0)
        return;

    buf = (u8 *) malloc(len);
    if (!buf)
        return;

    memset(buf, data, len);
    vdi_write_memory(core_idx, addr, buf, len);
    free(buf);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
testl %edi, %edi
je 0x75d6
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x0, 0x27c27(%rip)     # 0x2f204
js 0x75cd
cmpb $0x0, 0x27c22(%rip)     # 0x2f208
je 0x75cd
movl %ecx, %r14d
movl %edx, %ebx
movl %esi, %ebp
movl %edx, %r12d
movq %r12, %rdi
callq 0x2220
testq %rax, %rax
je 0x75cd
movq %rax, %r15
movzbl %r14b, %esi
movq %rax, %rdi
movq %r12, %rdx
callq 0x20f0
xorl %edi, %edi
movl %ebp, %esi
movq %r15, %rdx
movl %ebx, %ecx
callq 0x2120
movq %r15, %rdi
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x2200
// File: /workspace/github_c_makefile_star2_O2/xiane[P]libvphevcodec/vdi.cpp
// Function: vdi_write_memory(unsigned int, unsigned int, unsigned char*, unsigned int)
s32 vdi_write_memory(u32 core_idx, u32 addr, u8 *data, u32 len) {
    vdi_info_t *vdi;
    vpu_buffer_t vdb;
    ulong offset;
    s32 i;

    if (core_idx >= MAX_NUM_VPU_CORE)
        return -1;

    vdi = &s_vdi_info[core_idx];
    if (!vdi || vdi->vpu_fd < 0 || vdi->opened == 0)
        return -1;

    memset(&vdb, 0x00, sizeof(vpu_buffer_t));

    for (i = 0; i < MAX_VPU_BUFFER_POOL; i++) {
        if (vdi->vpu_buffer_pool[i].inuse == 1) {
            vdb = vdi->vpu_buffer_pool[i].vdb;
            if (addr >= vdb.phys_addr && addr < (vdb.phys_addr + vdb.size))
                break;
        }
    }

    if (!vdb.size) {
        VLOG(ERR, "address 0x%08x is not mapped address!!!", addr);
        return -1;
    }
    offset = addr - (ulong) vdb.phys_addr;
    memcpy((void *) ((ulong) vdb.virt_addr + offset), data, len);
    return len;
}

// Assembly:
pushq %rbp
pushq %rbx
pushq %rax
pushq $-0x1
popq %rbx
testl %edi, %edi
je 0x7642
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
cmpl $0x0, 0x27bbb(%rip)     # 0x2f204
js 0x7639
cmpb $0x0, 0x27bb6(%rip)     # 0x2f208
je 0x7639
movl %ecx, %ebp
movl %esi, %edi
xorl %eax, %eax
movl $0xa0, %r9d
leaq 0x27b99(%rip), %r10     # 0x2f200
xorl %ecx, %ecx
xorl %r8d, %r8d
cmpq $0x28a0, %r9            # imm = 0x28A0
je 0x76a1
cmpl $0x1, (%r9,%r10)
jne 0x769b
movl -0x20(%r9,%r10), %eax
movq -0x18(%r9,%r10), %rcx
movq -0x8(%r9,%r10), %r8
cmpq %rdi, %rcx
ja 0x769b
movq %rax, %r11
addq %rcx, %r11
cmpq %rdi, %r11
ja 0x76a1
addq $0x28, %r9
jmp 0x766c
testl %eax, %eax
je 0x76bf
subq %rcx, %rdi
addq %r8, %rdi
movl %ebp, %eax
movq %rdx, %rsi
movq %rax, %rdx
callq 0x2150
movl %ebp, %ebx
jmp 0x7639
leaq 0x24efe(%rip), %rdi     # 0x2c5c4
xorl %eax, %eax
callq 0x2050
pushq $0xa
popq %rdi
callq 0x2230
jmp 0x7639
// File: /workspace/github_c_makefile_star2_O2/xiane[P]libvphevcodec/vdi.cpp
// Function: vdi_read_memory(unsigned int, unsigned int, unsigned char*, unsigned int)
s32 vdi_read_memory(u32 core_idx, u32 addr, u8 *data, u32 len) {
    vdi_info_t *vdi;
    vpu_buffer_t vdb;
    ulong offset;
    s32 i;

    if (core_idx >= MAX_NUM_VPU_CORE)
        return -1;

    vdi = &s_vdi_info[core_idx];
    if (!vdi || vdi->vpu_fd < 0 || vdi->opened == 0)
        return -1;

    memset(&vdb, 0x00, sizeof(vpu_buffer_t));

    for (i = 0; i < MAX_VPU_BUFFER_POOL; i++) {
        if (vdi->vpu_buffer_pool[i].inuse == 1) {
            vdb = vdi->vpu_buffer_pool[i].vdb;
            if (addr >= vdb.phys_addr && addr < (vdb.phys_addr + vdb.size))
                break;
        }
    }

    if (!vdb.size)
        return -1;

    offset = addr - (ulong) vdb.phys_addr;
    memcpy(data, (void *) ((ulong) vdb.virt_addr + offset), len);
    return len;
}

// Assembly:
pushq $-0x1
popq %rax
testl %edi, %edi
je 0x76e2
retq
cmpl $0x0, 0x27b1b(%rip)     # 0x2f204
js 0x76e1
cmpb $0x0, 0x27b16(%rip)     # 0x2f208
je 0x76e1
pushq %rbx
movl %ecx, %ebx
movl %esi, %esi
xorl %ecx, %ecx
movl $0xa0, %r9d
leaq 0x27af8(%rip), %r10     # 0x2f200
xorl %edi, %edi
xorl %r8d, %r8d
cmpq $0x28a0, %r9            # imm = 0x28A0
je 0x7742
cmpl $0x1, (%r9,%r10)
jne 0x773c
movl -0x20(%r9,%r10), %ecx
movq -0x18(%r9,%r10), %rdi
movq -0x8(%r9,%r10), %r8
cmpq %rsi, %rdi
ja 0x773c
movq %rcx, %r11
addq %rdi, %r11
cmpq %rsi, %r11
ja 0x7742
addq $0x28, %r9
jmp 0x770d
testl %ecx, %ecx
je 0x775b
subq %rdi, %rsi
addq %r8, %rsi
movl %ebx, %eax
movq %rdx, %rdi
movq %rax, %rdx
callq 0x2150
movl %ebx, %eax
popq %rbx
retq
// File: /workspace/github_c_makefile_star2_O2/xiane[P]libvphevcodec/vdi.cpp
// Function: vdi_attach_dma_memory(unsigned int, vpu_buffer_t*)
s32 vdi_attach_dma_memory(u32 core_idx, vpu_buffer_t *vb) {
    vdi_info_t *vdi;
    s32 i;
    vpu_buffer_t vdb;

    if (core_idx >= MAX_NUM_VPU_CORE)
        return -1;

    vdi = &s_vdi_info[core_idx];
    if (!vdi || vdi->vpu_fd < 0 || vdi->opened == 0)
        return -1;

    memset(&vdb, 0x00, sizeof(vpu_buffer_t));

    vdb.size = vb->size;
    vdb.phys_addr = vb->phys_addr;
    vdb.base = vb->base;
    vdb.virt_addr = vb->virt_addr;
    vdb.cached = vb->cached;

    for (i = 0; i < MAX_VPU_BUFFER_POOL; i++) {
        if (vdi->vpu_buffer_pool[i].vdb.phys_addr == vb->phys_addr) {
            vdi->vpu_buffer_pool[i].vdb = vdb;
            vdi->vpu_buffer_pool[i].inuse = 1;
            break;
        }
    }
    if (i == MAX_VPU_BUFFER_POOL) {
        for (i = 0; i < MAX_VPU_BUFFER_POOL; i++) {
            if (vdi->vpu_buffer_pool[i].inuse == 0) {
                vdi->vpu_buffer_pool[i].vdb = vdb;
                vdi->vpu_buffer_pool_count++;
                vdi->vpu_buffer_pool[i].inuse = 1;
                break;
            }
        }
    }
    VLOG(INFO, "[VDI] vdi_attach_dma_memory, physaddr=0x%lx, virtaddr=0x%lx, size=0x%x, index=%d",
                                                                    vb->phys_addr, vb->virt_addr, vb->size, i);
    return 0;
}

// Assembly:
pushq %rbx
pushq $-0x1
popq %rbx
testl %edi, %edi
jne 0x7972
cmpl $0x0, 0x27968(%rip)     # 0x2f204
js 0x7972
cmpb $0x0, 0x2795f(%rip)     # 0x2f208
je 0x7972
movl (%rsi), %edi
movl 0x4(%rsi), %edx
movq 0x8(%rsi), %r9
movq 0x10(%rsi), %rcx
movq 0x18(%rsi), %rax
leaq 0x279b9(%rip), %r10     # 0x2f280
xorl %r8d, %r8d
cmpq $0x100, %r8             # imm = 0x100
je 0x78e2
cmpq %r9, 0x8(%r10)
je 0x7904
incq %r8
addq $0x28, %r10
jmp 0x78ca
leaq 0x279b7(%rip), %r10     # 0x2f2a0
xorl %r8d, %r8d
cmpq $0x100, %r8             # imm = 0x100
je 0x7915
cmpl $0x0, (%r10)
je 0x791d
incq %r8
addq $0x28, %r10
jmp 0x78ec
movl %edi, (%r10)
movl %edx, 0x4(%r10)
movq %rcx, 0x10(%r10)
movq %rax, 0x18(%r10)
jmp 0x7937
movl $0x100, %r8d            # imm = 0x100
jmp 0x794d
movl %edi, -0x20(%r10)
movl %edx, -0x1c(%r10)
movq %r9, -0x18(%r10)
movq %rcx, -0x10(%r10)
movq %rax, -0x8(%r10)
incl 0x2a149(%rip)           # 0x31a80
imulq $0x28, %r8, %rax
leaq 0x278be(%rip), %rcx     # 0x2f200
movl $0x1, 0xa0(%rax,%rcx)
movq 0x8(%rsi), %rax
movq 0x18(%rsi), %rdx
movl (%rsi), %ecx
leaq 0x24d0d(%rip), %rdi     # 0x2c66b
xorl %ebx, %ebx
movq %rax, %rsi
xorl %eax, %eax
callq 0x2050
pushq $0xa
popq %rdi
callq 0x2230
movl %ebx, %eax
popq %rbx
retq
// File: /workspace/github_c_makefile_star2_O2/xiane[P]libvphevcodec/vdi.cpp
// Function: vdi_dettach_dma_memory(unsigned int, vpu_buffer_t*)
s32 vdi_dettach_dma_memory(u32 core_idx, vpu_buffer_t *vb) {
    vdi_info_t *vdi;
    s32 i;

    if (core_idx >= MAX_NUM_VPU_CORE)
        return -1;

    vdi = &s_vdi_info[core_idx];
    if (!vdi || vdi->vpu_fd < 0 || vdi->opened == 0)
        return -1;

    if (vb->size == 0)
        return -1;

    for (i = 0; i < MAX_VPU_BUFFER_POOL; i++) {
        if (vdi->vpu_buffer_pool[i].vdb.phys_addr == vb->phys_addr) {
            vdi->vpu_buffer_pool[i].inuse = 0;
            vdi->vpu_buffer_pool_count--;
            break;
        }
    }
    return 0;
}

// Assembly:
pushq $-0x1
popq %rax
testl %edi, %edi
je 0x797e
retq
cmpl $0x0, 0x2787f(%rip)     # 0x2f204
js 0x797d
cmpb $0x0, 0x2787a(%rip)     # 0x2f208
je 0x797d
cmpl $0x0, (%rsi)
je 0x797d
movq 0x8(%rsi), %rcx
movl $0x88, %esi
leaq 0x2785b(%rip), %rdx     # 0x2f200
xorl %eax, %eax
leaq 0x28(%rsi), %rdi
cmpq $0x28b0, %rdi           # imm = 0x28B0
je 0x797d
cmpq %rcx, (%rsi,%rdx)
movq %rdi, %rsi
jne 0x79a7
andl $0x0, -0x10(%rdi,%rdx)
decl 0x2a0b8(%rip)           # 0x31a80
retq
// File: /workspace/github_c_makefile_star2_O2/xiane[P]libvphevcodec/vdi.cpp
// Function: vdi_free_dma_memory(unsigned int, vpu_buffer_t*)
void vdi_free_dma_memory(u32 core_idx, vpu_buffer_t *vb) {
    vdi_info_t *vdi;
    s32 i;
    vpu_buffer_t vdb;

    if (core_idx >= MAX_NUM_VPU_CORE)
        return;

    vdi = &s_vdi_info[core_idx];
    if (!vdi || vdi->vpu_fd < 0 || vdi->opened == 0)
        return;

    if (vb->size == 0)
        return;

    memset(&vdb, 0x00, sizeof(vpu_buffer_t));

    for (i = 0; i < MAX_VPU_BUFFER_POOL; i++) {
        if (vdi->vpu_buffer_pool[i].vdb.phys_addr == vb->phys_addr) {
            vdi->vpu_buffer_pool[i].inuse = 0;
            vdi->vpu_buffer_pool_count--;
            vdb = vdi->vpu_buffer_pool[i].vdb;
            break;
        }
    }

    if (!vdb.size) {
        VLOG(ERR, "[VDI] invalid buffer to free address = 0x%lx", vdb.virt_addr);
        return;
    }

    ioctl(vdi->vpu_fd, VDI_IOCTL_FREE_PHYSICALMEMORY, &vdb);

    if (munmap((void *) vdb.virt_addr, vdb.size) != 0) {
        VLOG(ERR, "[VDI] fail to vdi_free_dma_memory virtial address = 0x%lx", vdb.virt_addr);
    }
    memset(vb, 0, sizeof(vpu_buffer_t));
}

// Assembly:
pushq %r14
pushq %rbx
subq $0x28, %rsp
testl %edi, %edi
je 0x79dc
addq $0x28, %rsp
popq %rbx
popq %r14
retq
movl 0x27822(%rip), %edi     # 0x2f204
testl %edi, %edi
js 0x79d4
cmpb $0x0, 0x2781b(%rip)     # 0x2f208
je 0x79d4
movq %rsi, %rbx
cmpl $0x0, (%rsi)
je 0x79d4
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movaps %xmm0, (%rsp)
movq 0x8(%rbx), %rcx
movl $0x88, %esi
leaq 0x277ed(%rip), %rax     # 0x2f200
leaq 0x28(%rsi), %rdx
cmpq $0x28b0, %rdx           # imm = 0x28B0
je 0x7a99
cmpq %rcx, (%rsi,%rax)
movq %rdx, %rsi
jne 0x7a13
andl $0x0, -0x10(%rdx,%rax)
decl 0x2a04c(%rip)           # 0x31a80
movups -0x30(%rdx,%rax), %xmm0
movups -0x20(%rdx,%rax), %xmm1
movaps %xmm0, (%rsp)
movaps %xmm1, 0x10(%rsp)
cmpl $0x0, (%rsp)
je 0x7a99
movq %rsp, %r14
movl $0x40205601, %esi       # imm = 0x40205601
movq %r14, %rdx
xorl %eax, %eax
callq 0x2240
movq 0x18(%r14), %rdi
movl (%r14), %esi
callq 0x2100
testl %eax, %eax
je 0x7a8a
movq 0x18(%rsp), %rsi
leaq 0x24c6e(%rip), %rdi     # 0x2c6e9
xorl %eax, %eax
callq 0x2050
pushq $0xa
popq %rdi
callq 0x2230
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rbx)
movups %xmm0, (%rbx)
jmp 0x79d4
movq 0x18(%rsp), %rsi
leaq 0x24c17(%rip), %rdi     # 0x2c6bc
xorl %eax, %eax
callq 0x2050
pushq $0xa
popq %rdi
addq $0x28, %rsp
popq %rbx
popq %r14
jmp 0x2230