// File: /workspace/github_c_makefile_star2_O0/xiane[P]libvphevcodec/vdi.cpp
// Function: vdi_wait_vpu_busy(unsigned int, unsigned int, unsigned int)
s32 vdi_wait_vpu_busy(u32 core_idx, u32 timeoutMs, u32 addr_bit_busy_flag) {
    ulong elapse, cur;
    struct timeval tv;
    s32 i;
    u32 normalReg = 1;
    tv.tv_sec = 0;
    tv.tv_usec = 0;
    gettimeofday(&tv, NULL);
    elapse = tv.tv_sec * 1000 + tv.tv_usec / 1000;

    if (addr_bit_busy_flag & 0x8000)
        normalReg = 0;

    i = 0;
    while (1) {
        if (normalReg == 1) {
            if (vdi_read_register(core_idx, addr_bit_busy_flag) == 0)
                break;
        } else {
            if (vdi_fio_read_register(core_idx, addr_bit_busy_flag) == 0)
                break;
        }
        i++;
        gettimeofday(&tv, NULL);
        cur = tv.tv_sec * 1000 + tv.tv_usec / 1000;
        if ((cur - elapse) > timeoutMs) {
            for (i = 0; i < 20; i++) {
                VLOG(ERR, "[VDI] vdi_wait_vpu_busy timeout, timeoutMs: %d, PC=0x%x",
						timeoutMs, vdi_read_register(core_idx, W4_VCPU_CUR_PC));
            }
            return -1;
        }
        usleep(5);
    }
    VLOG(DEBUG, "[VDI] vdi_wait_vpu_busy i = %d", i);
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movl %edi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movl $0x1, -0x38(%rbp)
movq $0x0, -0x30(%rbp)
movq $0x0, -0x28(%rbp)
leaq -0x30(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x22a0
imulq $0x3e8, -0x30(%rbp), %rax # imm = 0x3E8
movq %rax, -0x40(%rbp)
movq -0x28(%rbp), %rax
movl $0x3e8, %ecx            # imm = 0x3E8
cqto
idivq %rcx
movq %rax, %rcx
movq -0x40(%rbp), %rax
addq %rcx, %rax
movq %rax, -0x18(%rbp)
movl -0x10(%rbp), %eax
andl $0x8000, %eax           # imm = 0x8000
cmpl $0x0, %eax
je 0xb541
movl $0x0, -0x38(%rbp)
movl $0x0, -0x34(%rbp)
cmpl $0x1, -0x38(%rbp)
jne 0xb565
movl -0x8(%rbp), %edi
movl -0x10(%rbp), %esi
callq 0x2210
cmpl $0x0, %eax
jne 0xb563
jmp 0xb632
jmp 0xb57c
movl -0x8(%rbp), %edi
movl -0x10(%rbp), %esi
callq 0x2030
cmpl $0x0, %eax
jne 0xb57a
jmp 0xb632
jmp 0xb57c
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
leaq -0x30(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x22a0
imulq $0x3e8, -0x30(%rbp), %rax # imm = 0x3E8
movq %rax, -0x48(%rbp)
movq -0x28(%rbp), %rax
movl $0x3e8, %ecx            # imm = 0x3E8
cqto
idivq %rcx
movq %rax, %rcx
movq -0x48(%rbp), %rax
addq %rcx, %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
subq -0x18(%rbp), %rax
movl -0xc(%rbp), %ecx
cmpq %rcx, %rax
jbe 0xb623
movl $0x0, -0x34(%rbp)
cmpl $0x14, -0x34(%rbp)
jge 0xb61a
jmp 0xb5d9
movl -0xc(%rbp), %eax
movl %eax, -0x4c(%rbp)
movl -0x8(%rbp), %edi
movl $0x4, %esi
callq 0x2210
movl -0x4c(%rbp), %esi
movl %eax, %edx
leaq 0x25188(%rip), %rdi     # 0x30780
movb $0x0, %al
callq 0x2050
leaq 0x24c60(%rip), %rdi     # 0x30266
movb $0x0, %al
callq 0x2050
jmp 0xb60f
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0xb5d1
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xb63d
movl $0x5, %edi
callq 0x2240
jmp 0xb548
jmp 0xb634
jmp 0xb636
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)