// File: /workspace/github_c_makefile_star2_O1/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 0x7500
xorl %eax, %eax
retq
cmpl $0x0, 0x28cdd(%rip)     # 0x301e4
js 0x74fd
cmpb $0x0, 0x28cd8(%rip)     # 0x301e8
je 0x74fd
movl 0x28ce0(%rip), %eax     # 0x301f8
cmpl $0x2, %eax
jb 0x7527
decl %eax
movl %eax, 0x28cd3(%rip)     # 0x301f8
jmp 0x74fd
pushq %rax
movq 0x28ce9(%rip), %rdi     # 0x30218
testq %rdi, %rdi
je 0x753f
movl 0x28cc6(%rip), %esi     # 0x30200
callq 0x20f0
xorps %xmm0, %xmm0
movaps %xmm0, 0x28cc7(%rip)    # 0x30210
movaps %xmm0, 0x28cb0(%rip)    # 0x30200
movq 0x28cf1(%rip), %rdx     # 0x30248
xorl %eax, %eax
leaq 0x28c80(%rip), %rcx     # 0x301e0
movq 0x88(%rax,%rcx), %rsi
cmpq %rsi, %rdx
jb 0x757c
movl 0x80(%rax,%rcx), %edi
addq %rdi, %rsi
cmpq %rsi, %rdx
jb 0x758c
addq $0x28, %rax
cmpq $0x2800, %rax           # imm = 0x2800
jne 0x7560
xorl %edx, %edx
jmp 0x75ac
movl $0x0, 0xa0(%rax,%rcx)
decl 0x2b4c3(%rip)           # 0x32a60
movl 0x80(%rax,%rcx), %edx
movq 0x98(%rax,%rcx), %rdi
testl %edx, %edx
je 0x75c8
movl %edx, %esi
callq 0x20f0
xorps %xmm0, %xmm0
movaps %xmm0, 0x28c7f(%rip)    # 0x30240
movaps %xmm0, 0x28c88(%rip)    # 0x30250
movq 0x28c69(%rip), %rdi     # 0x30238
testq %rdi, %rdi
je 0x75df
movl 0x28c46(%rip), %esi     # 0x30220
callq 0x20f0
decl 0x28c13(%rip)           # 0x301f8
movl 0x28bf9(%rip), %edi     # 0x301e4
testl %edi, %edi
js 0x75fe
callq 0x2370
movl $0xffffffff, 0x28be6(%rip) # imm = 0xFFFFFFFF
leaq 0x28bdb(%rip), %rdi     # 0x301e0
movl $0x2888, %edx           # imm = 0x2888
xorl %esi, %esi
callq 0x20e0
movl $0xffffffff, 0x28bc9(%rip) # imm = 0xFFFFFFFF
addq $0x8, %rsp
jmp 0x74fd