// File: /workspace/github_c_makefile_star2_O2/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 0x10402
andq $0x0, (%r14)
cmpl $0x0, 0x18f03(%rip)     # 0x2930c
jle 0x104c7
cmpq $0x0, 0x1a931(%rip)     # 0x2ad48
je 0x104ce
testq %r15, %r15
je 0x1054f
leaq 0x1a923(%rip), %rdi     # 0x2ad50
callq 0x5570
cmpl $0x1000000, 0x8(%r15)   # imm = 0x1000000
jne 0x1044e
movl $0x2, 0x18ec2(%rip)     # 0x29308
movl $0x1, 0x8(%r15)
movl 0x1a8dc(%rip), %esi     # 0x2ad30
movq %r15, %rdi
callq 0x10583
andq $0x0, 0x1a91c(%rip)     # 0x2ad80
movq %r15, 0x1a90d(%rip)     # 0x2ad78
movl 0x18e9b(%rip), %edi     # 0x2930c
movl 0x4(%r15), %edx
movq %r15, %rsi
callq 0x5100
movq %rax, %rbx
testl %ebx, %ebx
jle 0x104d2
cmpl %ebx, 0x4(%r15)
jne 0x104d2
leaq 0x1a8f7(%rip), %rdi     # 0x2ad88
leaq 0x1a8b8(%rip), %rsi     # 0x2ad50
movl %ebp, %edx
callq 0xe5ba
movl %eax, %ebx
testl %eax, %eax
jne 0x10531
testq %r14, %r14
sete %cl
movq 0x1a8ca(%rip), %rax     # 0x2ad80
testq %rax, %rax
sete %dl
xorl %ebx, %ebx
orb %cl, %dl
jne 0x10531
movq %rax, (%r14)
jmp 0x10531
pushq $-0x13
jmp 0x10551
pushq $-0x16
jmp 0x10551
movq 0x18adf(%rip), %rax     # 0x28fb8
movq (%rax), %r14
callq 0xe343
leaq 0xef70(%rip), %rsi      # 0x1f458
leaq 0xef8d(%rip), %rcx      # 0x1f47c
movq %r14, %rdi
movq %rax, %rdx
movl %ebx, %r8d
xorl %eax, %eax
callq 0x52c0
leaq 0x197a2(%rip), %rax     # 0x29ca8
movq (%rax), %r14
testq %r14, %r14
je 0x10531
callq 0xe343
leaq 0xef3e(%rip), %rsi      # 0x1f458
leaq 0xef5b(%rip), %rcx      # 0x1f47c
movq %r14, %rdi
movq %rax, %rdx
movl %ebx, %r8d
xorl %eax, %eax
callq 0x52c0
andq $0x0, 0x1a847(%rip)     # 0x2ad80
andq $0x0, 0x1a837(%rip)     # 0x2ad78
leaq 0x1a808(%rip), %rdi     # 0x2ad50
callq 0x5340
jmp 0x10552
pushq $-0xc
popq %rbx
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq