// File: /workspace/github_c_makefile_star2_O1/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 0x2493b(%rip), %eax     # 0x2a2f0
movl %eax, (%rsp)
movl $0x4, 0x4(%rsp)
cmpl $-0x1, %eax
je 0x5ad7
movq %rdi, %r14
movzbl 0x4(%rdi), %eax
testq %rax, %rax
je 0x59f5
leaq 0x24964(%rip), %rcx     # 0x2a340
movb (%rax,%rcx), %cl
movb %cl, 0x5(%r14)
testb %cl, %cl
je 0x5c15
cmpl $0x11, %eax
jne 0x59f5
movb $0x1, 0x4(%r14)
movq %rsp, %r15
movl $0x1, %esi
movq %r15, %rdi
movl $0x1388, %edx           # imm = 0x1388
callq 0x53c0
movl %eax, %ebx
testl %eax, %eax
jns 0x5a1a
callq 0x5070
cmpl $0x4, (%rax)
je 0x59f8
testb $0x4, 0x6(%rsp)
jne 0x5b3e
movq 0x24594(%rip), %rax     # 0x29fc0
movq (%rax), %r15
callq 0xeb2f
movq %rax, %r12
movswl 0x6(%rsp), %ebp
callq 0x5070
movq %rax, %r14
movl (%rax), %r13d
movl %r13d, %edi
callq 0x5530
movq %rax, %r10
leaq 0x18687(%rip), %rsi     # 0x1e0e0
leaq 0x1862e(%rip), %rcx     # 0x1e08e
movq %r15, %rdi
movq %r12, %rdx
movl %ebx, %r8d
movl %ebp, %r9d
xorl %eax, %eax
pushq %r10
pushq %r13
callq 0x52c0
addq $0x10, %rsp
leaq 0x25226(%rip), %rax     # 0x2aca8
movq (%rax), %r15
testq %r15, %r15
je 0x5c6f
callq 0xeb2f
movq %rax, %r12
movswl 0x6(%rsp), %ebp
movl (%r14), %r14d
movl %r14d, %edi
callq 0x5530
movq %rax, %r10
leaq 0x18630(%rip), %rsi     # 0x1e0e0
leaq 0x185d7(%rip), %rcx     # 0x1e08e
movq %r15, %rdi
movq %r12, %rdx
movl %ebx, %r8d
movl %ebp, %r9d
xorl %eax, %eax
pushq %r10
pushq %r14
callq 0x52c0
addq $0x10, %rsp
jmp 0x5c6f
movq 0x244e2(%rip), %rax     # 0x29fc0
movq (%rax), %rbx
callq 0xeb2f
leaq 0x18588(%rip), %rsi     # 0x1e075
leaq 0x1859a(%rip), %rcx     # 0x1e08e
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x52c0
leaq 0x251a0(%rip), %rax     # 0x2aca8
movq (%rax), %r14
movl $0xffffffed, %ebx       # imm = 0xFFFFFFED
testq %r14, %r14
je 0x5c6f
callq 0xeb2f
leaq 0x18550(%rip), %rsi     # 0x1e075
leaq 0x18562(%rip), %rcx     # 0x1e08e
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x52c0
jmp 0x5c6f
movzwl 0x1(%r14), %edi
callq 0xef61
movzwl %ax, %r15d
incq %r15
movl 0x2479b(%rip), %edi     # 0x2a2f0
movq %r14, %rsi
movq %r15, %rdx
callq 0x5100
movq %rax, %r14
movslq %r14d, %rax
xorl %ebx, %ebx
cmpq %r15, %rax
je 0x5c6f
movq 0x24448(%rip), %rax     # 0x29fc0
movq (%rax), %r15
callq 0xeb2f
movq %rax, %r12
callq 0x5070
movq %rax, %rbx
movl (%rax), %ebp
movl %ebp, %edi
callq 0x5530
movq %rax, %r10
subq $0x8, %rsp
leaq 0x1851c(%rip), %rsi     # 0x1e0be
leaq 0x184e5(%rip), %rcx     # 0x1e08e
movq %r15, %rdi
movq %r12, %rdx
movl %r14d, %r8d
movl %ebp, %r9d
xorl %eax, %eax
pushq %r10
callq 0x52c0
addq $0x10, %rsp
leaq 0x250df(%rip), %rax     # 0x2aca8
movq (%rax), %r15
testq %r15, %r15
je 0x5c10
callq 0xeb2f
movq %rax, %r12
movl (%rbx), %ebx
movl %ebx, %edi
callq 0x5530
movq %rax, %r10
subq $0x8, %rsp
leaq 0x184ce(%rip), %rsi     # 0x1e0be
leaq 0x18497(%rip), %rcx     # 0x1e08e
movq %r15, %rdi
movq %r12, %rdx
movl %r14d, %r8d
movl %ebx, %r9d
xorl %eax, %eax
pushq %r10
callq 0x52c0
addq $0x10, %rsp
movl %r14d, %ebx
jmp 0x5c6f
movq 0x243a4(%rip), %rax     # 0x29fc0
movq (%rax), %rbx
callq 0xeb2f
movzbl 0x4(%r14), %ecx
leaq 0x1846d(%rip), %rsi     # 0x1e09d
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x52c0
leaq 0x25064(%rip), %rax     # 0x2aca8
movq (%rax), %r15
movl $0xffffffed, %ebx       # imm = 0xFFFFFFED
testq %r15, %r15
je 0x5c6f
callq 0xeb2f
movzbl 0x4(%r14), %ecx
leaq 0x1843b(%rip), %rsi     # 0x1e09d
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