// File: /workspace/github_c_makefile_star2_O3/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 0x10c53
movq $0x0, (%r14)
cmpl $0x0, 0x196b2(%rip)     # 0x2a30c
jle 0x10d1b
cmpq $0x0, 0x1b0e0(%rip)     # 0x2bd48
je 0x10d25
testq %r15, %r15
je 0x10dac
leaq 0x1b0d2(%rip), %rdi     # 0x2bd50
callq 0x5560
cmpl $0x1000000, 0x8(%r15)   # imm = 0x1000000
jne 0x10c9f
movl $0x2, 0x19671(%rip)     # 0x2a308
movl $0x1, 0x8(%r15)
movl 0x1b08b(%rip), %esi     # 0x2bd30
movq %r15, %rdi
callq 0x10dbe
movq %r15, 0x1b0c4(%rip)     # 0x2bd78
movq $0x0, 0x1b0c1(%rip) # 0x2bd80
movl 0x19647(%rip), %edi     # 0x2a30c
movl 0x4(%r15), %edx
movq %r15, %rsi
callq 0x5100
movq %rax, %rbx
testl %ebx, %ebx
jle 0x10d2f
cmpl %ebx, 0x4(%r15)
jne 0x10d2f
leaq 0x1b0a3(%rip), %rdi     # 0x2bd88
leaq 0x1b064(%rip), %rsi     # 0x2bd50
movl %ebp, %edx
callq 0xecc5
movl %eax, %ebx
testl %eax, %eax
jne 0x10d8e
testq %r14, %r14
sete %cl
movq 0x1b076(%rip), %rax     # 0x2bd80
testq %rax, %rax
sete %dl
xorl %ebx, %ebx
orb %cl, %dl
jne 0x10d8e
movq %rax, (%r14)
jmp 0x10d8e
movl $0xffffffed, %ebx       # imm = 0xFFFFFFED
jmp 0x10db1
movl $0xffffffea, %ebx       # imm = 0xFFFFFFEA
jmp 0x10db1
movq 0x1928a(%rip), %rax     # 0x29fc0
movq (%rax), %r14
callq 0xea3b
leaq 0x106f7(%rip), %rsi     # 0x2143c
leaq 0x10714(%rip), %rcx     # 0x21460
movq %r14, %rdi
movq %rax, %rdx
movl %ebx, %r8d
xorl %eax, %eax
callq 0x52c0
leaq 0x19f45(%rip), %rax     # 0x2aca8
movq (%rax), %r14
testq %r14, %r14
je 0x10d8e
callq 0xea3b
leaq 0x106c5(%rip), %rsi     # 0x2143c
leaq 0x106e2(%rip), %rcx     # 0x21460
movq %r14, %rdi
movq %rax, %rdx
movl %ebx, %r8d
xorl %eax, %eax
callq 0x52c0
xorl %eax, %eax
movq %rax, 0x1afe9(%rip)     # 0x2bd80
movq %rax, 0x1afda(%rip)     # 0x2bd78
leaq 0x1afab(%rip), %rdi     # 0x2bd50
callq 0x5340
jmp 0x10db1
movl $0xfffffff4, %ebx       # imm = 0xFFFFFFF4
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq