// File: /workspace/github_c_makefile_star2_O1/Carton32[P]quectel-CM/mbim-cm.c
// Function: mbim_send_command
static int mbim_send_command(MBIM_MESSAGE_HEADER *pRequest, MBIM_COMMAND_DONE_T **ppCmdDone, unsigned msecs) {
    int ret;

    if (ppCmdDone)
         *ppCmdDone = NULL;

    if (mbim_fd <= 0)
        return -ENODEV;

   if (s_tid_reader == 0)
      return -EINVAL;

    if (!pRequest)
        return -ENOMEM;

    pthread_mutex_lock(&mbim_command_mutex);

    if (pRequest) {
        if (pRequest->TransactionId == (0xFFFFFF + 1)) { //quectel-mbim-proxy need 0xFF000000 to indicat client
            TransactionId = 1;
            pRequest->TransactionId = htole32(TransactionId++);
        }
        mbim_dump(pRequest, mbim_verbose);
    }

    mbim_pRequest = pRequest;
    mbim_pResponse = NULL;

    ret = write(mbim_fd, pRequest, le32toh(pRequest->MessageLength));

    if (ret > 0 && (uint32_t)ret == le32toh(pRequest->MessageLength)) {
        ret = pthread_cond_timeout_np(&mbim_command_cond, &mbim_command_mutex, msecs);
        if (!ret) {
            if (mbim_pResponse && ppCmdDone) {
                *ppCmdDone = (MBIM_COMMAND_DONE_T *)mbim_pResponse;
            }
        }
    } else {
        mbim_debug("%s pthread_cond_timeout_np=%d", __func__, ret);
    }

    mbim_pRequest = mbim_pResponse = NULL;

    pthread_mutex_unlock(&mbim_command_mutex);

    return ret;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movl %edx, %ebp
movq %rsi, %r14
movq %rdi, %r15
testq %rsi, %rsi
je 0x10d24
movq $0x0, (%r14)
cmpl $0x0, 0x195e1(%rip)     # 0x2a30c
jle 0x10dec
cmpq $0x0, 0x1b00f(%rip)     # 0x2bd48
je 0x10df6
testq %r15, %r15
je 0x10e7d
leaq 0x1b001(%rip), %rdi     # 0x2bd50
callq 0x5560
cmpl $0x1000000, 0x8(%r15)   # imm = 0x1000000
jne 0x10d70
movl $0x2, 0x195a0(%rip)     # 0x2a308
movl $0x1, 0x8(%r15)
movl 0x1afba(%rip), %esi     # 0x2bd30
movq %r15, %rdi
callq 0x10e8f
movq %r15, 0x1aff3(%rip)     # 0x2bd78
movq $0x0, 0x1aff0(%rip) # 0x2bd80
movl 0x19576(%rip), %edi     # 0x2a30c
movl 0x4(%r15), %edx
movq %r15, %rsi
callq 0x5100
movq %rax, %rbx
testl %ebx, %ebx
jle 0x10e00
cmpl %ebx, 0x4(%r15)
jne 0x10e00
leaq 0x1afd2(%rip), %rdi     # 0x2bd88
leaq 0x1af93(%rip), %rsi     # 0x2bd50
movl %ebp, %edx
callq 0xedc5
movl %eax, %ebx
testl %eax, %eax
jne 0x10e5f
testq %r14, %r14
sete %cl
movq 0x1afa5(%rip), %rax     # 0x2bd80
testq %rax, %rax
sete %dl
xorl %ebx, %ebx
orb %cl, %dl
jne 0x10e5f
movq %rax, (%r14)
jmp 0x10e5f
movl $0xffffffed, %ebx       # imm = 0xFFFFFFED
jmp 0x10e82
movl $0xffffffea, %ebx       # imm = 0xFFFFFFEA
jmp 0x10e82
movq 0x191b9(%rip), %rax     # 0x29fc0
movq (%rax), %r14
callq 0xeb2f
leaq 0x105fe(%rip), %rsi     # 0x21414
leaq 0x1061b(%rip), %rcx     # 0x21438
movq %r14, %rdi
movq %rax, %rdx
movl %ebx, %r8d
xorl %eax, %eax
callq 0x52c0
leaq 0x19e74(%rip), %rax     # 0x2aca8
movq (%rax), %r14
testq %r14, %r14
je 0x10e5f
callq 0xeb2f
leaq 0x105cc(%rip), %rsi     # 0x21414
leaq 0x105e9(%rip), %rcx     # 0x21438
movq %r14, %rdi
movq %rax, %rdx
movl %ebx, %r8d
xorl %eax, %eax
callq 0x52c0
xorl %eax, %eax
movq %rax, 0x1af18(%rip)     # 0x2bd80
movq %rax, 0x1af09(%rip)     # 0x2bd78
leaq 0x1aeda(%rip), %rdi     # 0x2bd50
callq 0x5340
jmp 0x10e82
movl $0xfffffff4, %ebx       # imm = 0xFFFFFFF4
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq