// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movl %edi, -0x4(%rbp)
movq %rsi, -0x10(%rbp)
cmpl $0x1, -0x4(%rbp)
jb 0xb19a
jmp 0xb329
movl -0x4(%rbp), %eax
movl %eax, %ecx
leaq 0x2806a(%rip), %rax     # 0x33210
imulq $0x2888, %rcx, %rcx     # imm = 0x2888
addq %rcx, %rax
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0xb1d2
movq -0x18(%rbp), %rax
cmpl $0x0, 0x4(%rax)
jl 0xb1d2
movq -0x18(%rbp), %rax
movzbl 0x8(%rax), %eax
cmpl $0x0, %eax
jne 0xb1d7
jmp 0xb329
movq -0x10(%rbp), %rax
cmpl $0x0, (%rax)
jne 0xb1e5
jmp 0xb329
leaq -0x40(%rbp), %rdi
xorl %esi, %esi
movl $0x20, %edx
callq 0x20f0
movl $0x0, -0x1c(%rbp)
cmpl $0x100, -0x1c(%rbp)     # imm = 0x100
jge 0xb2a1
movq -0x18(%rbp), %rax
addq $0x80, %rax
movslq -0x1c(%rbp), %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jne 0xb291
movq -0x18(%rbp), %rax
addq $0x80, %rax
movslq -0x1c(%rbp), %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl $0x0, 0x20(%rax)
movq -0x18(%rbp), %rax
movl 0x2880(%rax), %ecx
addl $-0x1, %ecx
movl %ecx, 0x2880(%rax)
movq -0x18(%rbp), %rax
addq $0x80, %rax
movslq -0x1c(%rbp), %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rcx
movq %rcx, -0x40(%rbp)
movq 0x8(%rax), %rcx
movq %rcx, -0x38(%rbp)
movq 0x10(%rax), %rcx
movq %rcx, -0x30(%rbp)
movq 0x18(%rax), %rax
movq %rax, -0x28(%rbp)
jmp 0xb2a1
jmp 0xb293
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0xb1fc
cmpl $0x0, -0x40(%rbp)
jne 0xb2cb
jmp 0xb2a9
movq -0x28(%rbp), %rsi
leaq 0x2542d(%rip), %rdi     # 0x306e1
movb $0x0, %al
callq 0x2050
leaq 0x24fa4(%rip), %rdi     # 0x30266
movb $0x0, %al
callq 0x2050
jmp 0xb329
movq -0x18(%rbp), %rax
movl 0x4(%rax), %edi
movl $0x40205601, %esi       # imm = 0x40205601
leaq -0x40(%rbp), %rdx
movb $0x0, %al
callq 0x2230
movq -0x28(%rbp), %rdi
movl -0x40(%rbp), %eax
movl %eax, %esi
callq 0x2100
cmpl $0x0, %eax
je 0xb319
jmp 0xb2f7
movq -0x28(%rbp), %rsi
leaq 0x2540c(%rip), %rdi     # 0x3070e
movb $0x0, %al
callq 0x2050
leaq 0x24f56(%rip), %rdi     # 0x30266
movb $0x0, %al
callq 0x2050
jmp 0xb319
movq -0x10(%rbp), %rdi
xorl %esi, %esi
movl $0x20, %edx
callq 0x20f0
addq $0x40, %rsp
popq %rbp
retq
nop