// File: /workspace/github_c_makefile_star2_O3/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 %rbx
pushq %rax
movq %rdi, %rbx
cmpb $0x0, 0x28(%rdi)
je 0x58b4
leaq 0x28(%rbx), %r14
leaq 0x189ee(%rip), %rsi     # 0x1e119
movq %r14, %rdi
callq 0x52a0
testl %eax, %eax
je 0x5849
leaq 0xfce(%rip), %rsi       # 0x6710
movl $0x21, %edi
xorl %edx, %edx
callq 0x65f9
leaq 0x188db(%rip), %rcx     # 0x1e030
movq %rsp, %r14
movq %rax, %rdi
movq %r14, %rsi
movl $0x7530, %edx           # imm = 0x7530
callq 0xa273
cmpl $0x0, 0x10a(%rbx)
setne %al
movq (%r14), %rdi
testq %rdi, %rdi
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x57c9
cmpw $0x0, 0xf(%rdi)
jne 0x57ce
cmpw $0x0, 0x11(%rdi)
jne 0x57ce
movb 0x16(%rdi), %dl
testb %dl, %dl
je 0x57ce
movq %rdi, %rax
addq $0x1a, %rax
xorl %ecx, %ecx
cmpb $0x1a, -0x3(%rax)
jne 0x57b8
xorl %edx, %edx
cmpw $0x11, (%rax)
setae %dl
movl %edx, 0x112(%rbx)
movb 0x16(%rdi), %dl
incq %rcx
movzbl %dl, %esi
addq $0x5, %rax
cmpq %rsi, %rcx
jb 0x57a0
jmp 0x57ce
testq %rdi, %rdi
je 0x57d3
callq 0x5040
movl $0x1, %edi
callq 0x62cf
movb %al, 0x24b5e(%rip)      # 0x2a341
cmpb $0x0, 0x51(%rbx)
je 0x57f9
movl $0x1, %edi
callq 0x62cf
movb %al, 0x24b58(%rip)      # 0x2a351
movl $0x2, %edi
callq 0x62cf
movb %al, 0x24b39(%rip)      # 0x2a342
movl $0x3, %edi
callq 0x62cf
movb %al, 0x24b2a(%rip)      # 0x2a343
movl $0xb, %edi
callq 0x62cf
movb %al, 0x24b22(%rip)      # 0x2a34b
movl $0x1a, %edi
callq 0x62cf
movb %al, 0x24b21(%rip)      # 0x2a35a
movzbl %al, %eax
movl %eax, 0x122(%rbx)
xorl %ebp, %ebp
jmp 0x58fa
leaq 0x8a(%rbx), %rdx
leaq 0xed9(%rip), %rsi       # 0x6730
movl $0xff00, %edi           # imm = 0xFF00
callq 0x65f9
leaq 0x187d4(%rip), %rcx     # 0x1e03c
movq %rsp, %r15
movq %rax, %rdi
movq %r15, %rsi
movl $0x7530, %edx           # imm = 0x7530
callq 0xa273
testl %eax, %eax
sete %al
movq (%r15), %rdi
testq %rdi, %rdi
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x589e
cmpw $0x0, 0xf(%rdi)
jne 0x589e
cmpw $0x0, 0x11(%rdi)
je 0x58a5
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0x58fa
callq 0x5040
cmpb $0x0, (%r14)
jne 0x573b
movl $0xa, %r15d
leaq 0x1876f(%rip), %r14     # 0x1e030
movl $0x27, %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0x65f9
movq %rax, %rdi
xorl %esi, %esi
movl $0x3e8, %edx            # imm = 0x3E8
movq %r14, %rcx
callq 0xa273
testl %eax, %eax
je 0x573b
movl %eax, %ebp
movl $0x1, %edi
callq 0x5540
decl %r15d
jne 0x58c1
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq