// File: /workspace/github_c_makefile_star2_O3/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 0x2495d(%rip), %eax     # 0x2a2f0
movl %eax, (%rsp)
movl $0x4, 0x4(%rsp)
cmpl $-0x1, %eax
je 0x5ab5
movq %rdi, %r14
movzbl 0x4(%rdi), %eax
testq %rax, %rax
je 0x59d3
leaq 0x24986(%rip), %rcx     # 0x2a340
movb (%rax,%rcx), %cl
movb %cl, 0x5(%r14)
testb %cl, %cl
je 0x5bf3
cmpl $0x11, %eax
jne 0x59d3
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 0x59f8
callq 0x5070
cmpl $0x4, (%rax)
je 0x59d6
testb $0x4, 0x6(%rsp)
jne 0x5b1c
movq 0x245b6(%rip), %rax     # 0x29fc0
movq (%rax), %r15
callq 0xea3b
movq %rax, %r12
movswl 0x6(%rsp), %ebp
callq 0x5070
movq %rax, %r14
movl (%rax), %r13d
movl %r13d, %edi
callq 0x5530
movq %rax, %r10
leaq 0x186a9(%rip), %rsi     # 0x1e0e0
leaq 0x18650(%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 0x25248(%rip), %rax     # 0x2aca8
movq (%rax), %r15
testq %r15, %r15
je 0x5c4d
callq 0xea3b
movq %rax, %r12
movswl 0x6(%rsp), %ebp
movl (%r14), %r14d
movl %r14d, %edi
callq 0x5530
movq %rax, %r10
leaq 0x18652(%rip), %rsi     # 0x1e0e0
leaq 0x185f9(%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 0x5c4d
movq 0x24504(%rip), %rax     # 0x29fc0
movq (%rax), %rbx
callq 0xea3b
leaq 0x185aa(%rip), %rsi     # 0x1e075
leaq 0x185bc(%rip), %rcx     # 0x1e08e
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x52c0
leaq 0x251c2(%rip), %rax     # 0x2aca8
movq (%rax), %r14
movl $0xffffffed, %ebx       # imm = 0xFFFFFFED
testq %r14, %r14
je 0x5c4d
callq 0xea3b
leaq 0x18572(%rip), %rsi     # 0x1e075
leaq 0x18584(%rip), %rcx     # 0x1e08e
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x52c0
jmp 0x5c4d
movzwl 0x1(%r14), %edi
callq 0xee73
movzwl %ax, %r15d
incq %r15
movl 0x247bd(%rip), %edi     # 0x2a2f0
movq %r14, %rsi
movq %r15, %rdx
callq 0x5100
movq %rax, %r14
movslq %r14d, %rax
xorl %ebx, %ebx
cmpq %r15, %rax
je 0x5c4d
movq 0x2446a(%rip), %rax     # 0x29fc0
movq (%rax), %r15
callq 0xea3b
movq %rax, %r12
callq 0x5070
movq %rax, %rbx
movl (%rax), %ebp
movl %ebp, %edi
callq 0x5530
movq %rax, %r10
subq $0x8, %rsp
leaq 0x1853e(%rip), %rsi     # 0x1e0be
leaq 0x18507(%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 0x25101(%rip), %rax     # 0x2aca8
movq (%rax), %r15
testq %r15, %r15
je 0x5bee
callq 0xea3b
movq %rax, %r12
movl (%rbx), %ebx
movl %ebx, %edi
callq 0x5530
movq %rax, %r10
subq $0x8, %rsp
leaq 0x184f0(%rip), %rsi     # 0x1e0be
leaq 0x184b9(%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 0x5c4d
movq 0x243c6(%rip), %rax     # 0x29fc0
movq (%rax), %rbx
callq 0xea3b
movzbl 0x4(%r14), %ecx
leaq 0x1848f(%rip), %rsi     # 0x1e09d
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x52c0
leaq 0x25086(%rip), %rax     # 0x2aca8
movq (%rax), %r15
movl $0xffffffed, %ebx       # imm = 0xFFFFFFED
testq %r15, %r15
je 0x5c4d
callq 0xea3b
movzbl 0x4(%r14), %ecx
leaq 0x1845d(%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