// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x17295
movq -0x18(%rbp), %rax
movq $0x0, (%rax)
cmpl $0x0, 0x20194(%rip)     # 0x37430
jg 0x172aa
movl $0xffffffed, -0x4(%rbp) # imm = 0xFFFFFFED
jmp 0x17475
cmpq $0x0, 0x21c56(%rip)     # 0x38f08
jne 0x172c0
movl $0xffffffea, -0x4(%rbp) # imm = 0xFFFFFFEA
jmp 0x17475
cmpq $0x0, -0x10(%rbp)
jne 0x172d3
movl $0xfffffff4, -0x4(%rbp) # imm = 0xFFFFFFF4
jmp 0x17475
leaq 0x21c36(%rip), %rdi     # 0x38f10
callq 0x5570
cmpq $0x0, -0x10(%rbp)
je 0x1732b
movq -0x10(%rbp), %rax
cmpl $0x1000000, 0x8(%rax)   # imm = 0x1000000
jne 0x1731c
movl $0x1, 0x2012f(%rip)     # 0x3742c
movl 0x20129(%rip), %edi     # 0x3742c
movl %edi, %eax
addl $0x1, %eax
movl %eax, 0x2011e(%rip)     # 0x3742c
callq 0x191c0
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x10(%rbp), %rdi
movl 0x21bca(%rip), %esi     # 0x38ef0
callq 0x17560
movq -0x10(%rbp), %rax
movq %rax, 0x21c02(%rip)     # 0x38f38
movq $0x0, 0x21bff(%rip) # 0x38f40
movl 0x200e9(%rip), %eax     # 0x37430
movl %eax, -0x2c(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movl 0x4(%rax), %edi
callq 0x191c0
movl -0x2c(%rbp), %edi
movq -0x28(%rbp), %rsi
movl %eax, %eax
movl %eax, %edx
callq 0x5100
movl %eax, -0x20(%rbp)
cmpl $0x0, -0x20(%rbp)
jle 0x173d4
movl -0x20(%rbp), %eax
movl %eax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movl 0x4(%rax), %edi
callq 0x191c0
movl %eax, %ecx
movl -0x30(%rbp), %eax
cmpl %ecx, %eax
jne 0x173d4
movl -0x1c(%rbp), %edx
leaq 0x21bac(%rip), %rdi     # 0x38f48
leaq 0x21b6d(%rip), %rsi     # 0x38f10
callq 0x13cb0
movl %eax, -0x20(%rbp)
cmpl $0x0, -0x20(%rbp)
jne 0x173d2
cmpq $0x0, 0x21b87(%rip)     # 0x38f40
je 0x173d0
cmpq $0x0, -0x18(%rbp)
je 0x173d0
movq 0x21b77(%rip), %rcx     # 0x38f40
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
jmp 0x173d2
jmp 0x1744d
jmp 0x173d6
movq 0x1fc03(%rip), %rax     # 0x36fe0
movq (%rax), %rax
movq %rax, -0x38(%rbp)
callq 0x13930
movq -0x38(%rbp), %rdi
movq %rax, %rdx
movl -0x20(%rbp), %r8d
leaq 0x172a9(%rip), %rsi     # 0x2e6a4
leaq 0x172c6(%rip), %rcx     # 0x2e6c8
movb $0x0, %al
callq 0x52c0
leaq 0x20a58(%rip), %rax     # 0x37e68
cmpq $0x0, (%rax)
je 0x17449
leaq 0x20a4b(%rip), %rax     # 0x37e68
movq (%rax), %rax
movq %rax, -0x40(%rbp)
callq 0x13930
movq -0x40(%rbp), %rdi
movq %rax, %rdx
movl -0x20(%rbp), %r8d
leaq 0x17269(%rip), %rsi     # 0x2e6a4
leaq 0x17286(%rip), %rcx     # 0x2e6c8
movb $0x0, %al
callq 0x52c0
jmp 0x1744b
jmp 0x1744d
movq $0x0, 0x21ae8(%rip) # 0x38f40
movq $0x0, 0x21ad5(%rip) # 0x38f38
leaq 0x21aa6(%rip), %rdi     # 0x38f10
callq 0x5350
movl -0x20(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nop