// File: /workspace/github_c_makefile_star2_O2/Carton32[P]quectel-CM/QmiWwanCM.c
// Function: QmiWwanSendQMI
static int QmiWwanSendQMI(PQCQMIMSG pRequest) {
    struct pollfd pollfds[]= {{cdc_wdm_fd, POLLOUT, 0}};
    int ret;

    if (cdc_wdm_fd == -1) {
        dbg_time("%s cdc_wdm_fd = -1", __func__);
        return -ENODEV;
    }

    if (pRequest->QMIHdr.QMIType != QMUX_TYPE_CTL) {
        pRequest->QMIHdr.ClientId = qmiclientId[pRequest->QMIHdr.QMIType];
        if (pRequest->QMIHdr.ClientId == 0) {
            dbg_time("QMIType %d has no clientID", pRequest->QMIHdr.QMIType);
            return -ENODEV;
        }

        if (pRequest->QMIHdr.QMIType == QMUX_TYPE_WDS_IPV6)
            pRequest->QMIHdr.QMIType = QMUX_TYPE_WDS;
    }

    do {
        ret = poll(pollfds, sizeof(pollfds)/sizeof(pollfds[0]), 5000);
    } while ((ret < 0) && (errno == EINTR));

    if (pollfds[0].revents & POLLOUT) {
        ssize_t nwrites = le16_to_cpu(pRequest->QMIHdr.Length) + 1;
        ret = write(cdc_wdm_fd, pRequest, nwrites);
        if (ret == nwrites) {
            ret = 0;
        } else {
            dbg_time("%s write=%d, errno: %d (%s)", __func__, ret, errno, strerror(errno));
        }
    } else {
        dbg_time("%s poll=%d, revents = 0x%x, errno: %d (%s)", __func__, ret, pollfds[0].revents, errno, strerror(errno));
    }

    return ret;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl 0x239e7(%rip), %eax     # 0x292f0
movl %eax, (%rsp)
movl $0x4, 0x4(%rsp)
cmpl $-0x1, %eax
je 0x5a29
movq %rdi, %r14
movzbl 0x4(%rdi), %eax
testq %rax, %rax
je 0x5949
leaq 0x23a10(%rip), %rcx     # 0x29340
movb (%rax,%rcx), %cl
movb %cl, 0x5(%r14)
testb %cl, %cl
je 0x5b61
cmpl $0x11, %eax
jne 0x5949
movb $0x1, 0x4(%r14)
movq %rsp, %r15
pushq $0x1
popq %r12
movq %r15, %rdi
movq %r12, %rsi
movl $0x1388, %edx           # imm = 0x1388
callq 0x53d0
movl %eax, %ebx
testl %eax, %eax
jns 0x5970
callq 0x5070
cmpl $0x4, (%rax)
je 0x5950
testb $0x4, 0x6(%rsp)
jne 0x5a8e
movq 0x23636(%rip), %rax     # 0x28fb8
movq (%rax), %r15
callq 0xe343
movq %rax, %r12
movswl 0x6(%rsp), %ebp
callq 0x5070
movq %rax, %r14
movl (%rax), %r13d
movl %r13d, %edi
callq 0x5540
movq %rax, %r10
leaq 0x16731(%rip), %rsi     # 0x1c0e0
leaq 0x166d8(%rip), %rcx     # 0x1c08e
movq %r15, %rdi
movq %r12, %rdx
movl %ebx, %r8d
movl %ebp, %r9d
xorl %eax, %eax
pushq %r10
pushq %r13
callq 0x52c0
popq %rcx
popq %rdx
leaq 0x242d2(%rip), %rax     # 0x29ca8
movq (%rax), %r15
testq %r15, %r15
je 0x5bb9
callq 0xe343
movq %rax, %r12
movswl 0x6(%rsp), %ebp
movl (%r14), %r14d
movl %r14d, %edi
callq 0x5540
movq %rax, %r10
leaq 0x166dc(%rip), %rsi     # 0x1c0e0
leaq 0x16683(%rip), %rcx     # 0x1c08e
movq %r15, %rdi
movq %r12, %rdx
movl %ebx, %r8d
movl %ebp, %r9d
xorl %eax, %eax
pushq %r10
pushq %r14
callq 0x52c0
popq %rcx
popq %rdx
jmp 0x5bb9
movq 0x23588(%rip), %rax     # 0x28fb8
movq (%rax), %rbx
callq 0xe343
leaq 0x16636(%rip), %rsi     # 0x1c075
leaq 0x16648(%rip), %rcx     # 0x1c08e
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x52c0
leaq 0x2424e(%rip), %rax     # 0x29ca8
movq (%rax), %r14
pushq $-0x13
popq %rbx
testq %r14, %r14
je 0x5bb9
callq 0xe343
leaq 0x16600(%rip), %rsi     # 0x1c075
leaq 0x16612(%rip), %rcx     # 0x1c08e
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x52c0
jmp 0x5bb9
movzwl 0x1(%r14), %edi
callq 0xe73e
movzwl %ax, %r15d
incq %r15
movl 0x2384b(%rip), %edi     # 0x292f0
movq %r14, %rsi
movq %r15, %rdx
callq 0x5100
movq %rax, %r14
movslq %r14d, %rax
xorl %ebx, %ebx
cmpq %r15, %rax
je 0x5bb9
movq 0x234f0(%rip), %rax     # 0x28fb8
movq (%rax), %r15
callq 0xe343
movq %rax, %r12
callq 0x5070
movq %rax, %rbx
movl (%rax), %ebp
movl %ebp, %edi
callq 0x5540
movq %rax, %r10
subq $0x8, %rsp
leaq 0x165cc(%rip), %rsi     # 0x1c0be
leaq 0x16595(%rip), %rcx     # 0x1c08e
movq %r15, %rdi
movq %r12, %rdx
movl %r14d, %r8d
movl %ebp, %r9d
xorl %eax, %eax
pushq %r10
callq 0x52c0
popq %rcx
popq %rdx
leaq 0x24191(%rip), %rax     # 0x29ca8
movq (%rax), %r15
testq %r15, %r15
je 0x5b5c
callq 0xe343
movq %rax, %r12
movl (%rbx), %ebx
movl %ebx, %edi
callq 0x5540
movq %rax, %r10
subq $0x8, %rsp
leaq 0x16580(%rip), %rsi     # 0x1c0be
leaq 0x16549(%rip), %rcx     # 0x1c08e
movq %r15, %rdi
movq %r12, %rdx
movl %r14d, %r8d
movl %ebx, %r9d
xorl %eax, %eax
pushq %r10
callq 0x52c0
popq %rcx
popq %rdx
movl %r14d, %ebx
jmp 0x5bb9
movq 0x23450(%rip), %rax     # 0x28fb8
movq (%rax), %rbx
callq 0xe343
movzbl 0x4(%r14), %ecx
leaq 0x16521(%rip), %rsi     # 0x1c09d
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x52c0
leaq 0x24118(%rip), %rax     # 0x29ca8
movq (%rax), %r15
pushq $-0x13
popq %rbx
testq %r15, %r15
je 0x5bb9
callq 0xe343
movzbl 0x4(%r14), %ecx
leaq 0x164f1(%rip), %rsi     # 0x1c09d
movq %r15, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x52c0
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq