// File: /workspace/github_c_makefile_star2_O1/Carton32[P]quectel-CM/QmiWwanCM.c
// Function: QmiWwanInit
static int QmiWwanInit(PROFILE_T *profile) {
    unsigned i;
    int ret;
    PQCQMIMSG pResponse;

    if (profile->proxy[0] && !strcmp(profile->proxy, LIBQMI_PROXY)) {
        ret = libqmi_proxy_open(profile->qmichannel);
        if (ret)
            return ret;
    }

    if (!profile->proxy[0]) {
        for (i = 0; i < 10; i++) {
            ret = QmiThreadSendQMITimeout(ComposeQCTLMsg(QMICTL_SYNC_REQ, NULL, NULL), NULL, 1 * 1000, __func__);
            if (!ret)
                break;
            sleep(1);
        }
        if (ret)
            return ret;
    }

    QmiThreadSendQMI(ComposeQCTLMsg(QMICTL_GET_VERSION_REQ, CtlGetVersionReq, NULL), &pResponse);
    if (profile->qmap_mode) {
        if (pResponse) {
            if (pResponse->CTLMsg.QMICTLMsgHdrRsp.QMUXResult == 0 && pResponse->CTLMsg.QMICTLMsgHdrRsp.QMUXError == 0) {
                uint8_t  NumElements = 0;

                for (NumElements = 0; NumElements < pResponse->CTLMsg.GetVersionRsp.NumElements; NumElements++) {
#if 0
                    dbg_time("QMUXType = %02x Version = %d.%d",
                        pResponse->CTLMsg.GetVersionRsp.TypeVersion[NumElements].QMUXType,
                        pResponse->CTLMsg.GetVersionRsp.TypeVersion[NumElements].MajorVersion,
                        pResponse->CTLMsg.GetVersionRsp.TypeVersion[NumElements].MinorVersion);
#endif
                    if (pResponse->CTLMsg.GetVersionRsp.TypeVersion[NumElements].QMUXType == QMUX_TYPE_WDS_ADMIN)
                        profile->qmap_version = (pResponse->CTLMsg.GetVersionRsp.TypeVersion[NumElements].MinorVersion > 16);
                }
            }
        }
    }
    if (pResponse) free(pResponse);
    qmiclientId[QMUX_TYPE_WDS] = QmiWwanGetClientID(QMUX_TYPE_WDS);
    if (profile->enable_ipv6)
        qmiclientId[QMUX_TYPE_WDS_IPV6] = QmiWwanGetClientID(QMUX_TYPE_WDS);
    qmiclientId[QMUX_TYPE_DMS] = QmiWwanGetClientID(QMUX_TYPE_DMS);
    qmiclientId[QMUX_TYPE_NAS] = QmiWwanGetClientID(QMUX_TYPE_NAS);
    qmiclientId[QMUX_TYPE_UIM] = QmiWwanGetClientID(QMUX_TYPE_UIM);
    qmiclientId[QMUX_TYPE_WDS_ADMIN] = QmiWwanGetClientID(QMUX_TYPE_WDS_ADMIN);
    profile->wda_client = qmiclientId[QMUX_TYPE_WDS_ADMIN];

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10, %rsp
movq %rdi, %rbx
leaq 0x28(%rdi), %r14
cmpb $0x0, 0x28(%rdi)
je 0x579c
leaq 0x189ed(%rip), %rsi     # 0x1e119
movq %r14, %rdi
callq 0x52a0
testl %eax, %eax
jne 0x579c
leaq 0x8a(%rbx), %rdx
leaq 0x1074(%rip), %rsi      # 0x67ba
movl $0xff00, %edi           # imm = 0xFF00
callq 0x6683
leaq 0x188e5(%rip), %rcx     # 0x1e03c
leaq 0x8(%rsp), %r15
movq %rax, %rdi
movq %r15, %rsi
movl $0x7530, %edx           # imm = 0x7530
callq 0xa317
testl %eax, %eax
sete %al
movq (%r15), %rdi
testq %rdi, %rdi
setne %cl
andb %al, %cl
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
cmpb $0x1, %cl
jne 0x5792
cmpw $0x0, 0xf(%rdi)
je 0x590d
xorl %eax, %eax
testb %al, %al
je 0x58fd
cmpb $0x0, (%r14)
je 0x58ac
leaq 0xfed(%rip), %rsi       # 0x679a
movl $0x21, %edi
xorl %edx, %edx
callq 0x6683
leaq 0x18870(%rip), %rcx     # 0x1e030
leaq 0x8(%rsp), %r14
movq %rax, %rdi
movq %r14, %rsi
movl $0x7530, %edx           # imm = 0x7530
callq 0xa317
cmpl $0x0, 0x10a(%rbx)
setne %al
movq (%r14), %rdi
testq %rdi, %rdi
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x582e
cmpw $0x0, 0xf(%rdi)
jne 0x582e
cmpw $0x0, 0x11(%rdi)
jne 0x582e
cmpb $0x0, 0x16(%rdi)
je 0x582e
leaq 0x1a(%rdi), %rax
xorl %ecx, %ecx
cmpb $0x1a, -0x3(%rax)
jne 0x581e
xorl %edx, %edx
cmpw $0x11, (%rax)
setae %dl
movl %edx, 0x112(%rbx)
incq %rcx
movzbl 0x16(%rdi), %edx
addq $0x5, %rax
cmpq %rdx, %rcx
jb 0x5809
testq %rdi, %rdi
je 0x5838
callq 0x5040
movl $0x1, %edi
callq 0x6359
movb %al, 0x24af9(%rip)      # 0x2a341
cmpb $0x0, 0x51(%rbx)
je 0x585e
movl $0x1, %edi
callq 0x6359
movb %al, 0x24af3(%rip)      # 0x2a351
movl $0x2, %edi
callq 0x6359
movb %al, 0x24ad4(%rip)      # 0x2a342
movl $0x3, %edi
callq 0x6359
movb %al, 0x24ac5(%rip)      # 0x2a343
movl $0xb, %edi
callq 0x6359
movb %al, 0x24abd(%rip)      # 0x2a34b
movl $0x1a, %edi
callq 0x6359
movb %al, 0x24abc(%rip)      # 0x2a35a
movzbl %al, %eax
movl %eax, 0x122(%rbx)
xorl %r15d, %r15d
jmp 0x58fd
movl $0xa, %r12d
leaq 0x18777(%rip), %r14     # 0x1e030
xorl %r15d, %r15d
movl $0x27, %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0x6683
movq %rax, %rdi
xorl %esi, %esi
movl $0x3e8, %edx            # imm = 0x3E8
movq %r14, %rcx
callq 0xa317
testl %eax, %eax
je 0x58f4
movl %eax, %ebp
movl $0x1, %edi
callq 0x5540
decl %r12d
jne 0x58b9
movl %ebp, %r15d
testl %r15d, %r15d
je 0x57a6
movl %r15d, %eax
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
xorl %eax, %eax
cmpw $0x0, 0x11(%rdi)
jne 0x5794
callq 0x5040
movb $0x1, %al
xorl %r15d, %r15d
jmp 0x5794