// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movsbl 0x28(%rax), %eax
cmpl $0x0, %eax
je 0x5708
movq -0x10(%rbp), %rdi
addq $0x28, %rdi
leaq 0x25a7d(%rip), %rsi     # 0x2b155
callq 0x52a0
cmpl $0x0, %eax
jne 0x5708
movq -0x10(%rbp), %rdi
addq $0x8a, %rdi
callq 0x6bd0
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x18(%rbp)
je 0x5706
movl -0x18(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x58ed
jmp 0x5708
movq -0x10(%rbp), %rax
cmpb $0x0, 0x28(%rax)
jne 0x577b
movl $0x0, -0x14(%rbp)
cmpl $0xa, -0x14(%rbp)
jae 0x5768
movl $0x27, %edi
xorl %eax, %eax
movl %eax, %edx
movq %rdx, %rsi
callq 0x6c70
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0x3e8, %edx            # imm = 0x3E8
leaq 0x25929(%rip), %rcx     # 0x2b06c
callq 0xc670
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x18(%rbp)
jne 0x5753
jmp 0x5768
movl $0x1, %edi
callq 0x5550
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x5719
cmpl $0x0, -0x18(%rbp)
je 0x5779
movl -0x18(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x58ed
jmp 0x577b
movl $0x21, %edi
leaq 0x16d9(%rip), %rsi      # 0x6e60
xorl %eax, %eax
movl %eax, %edx
callq 0x6c70
movq %rax, %rdi
leaq -0x20(%rbp), %rsi
movl $0x7530, %edx           # imm = 0x7530
leaq 0x258c9(%rip), %rcx     # 0x2b06c
callq 0xc670
movq -0x10(%rbp), %rax
cmpl $0x0, 0x10a(%rax)
je 0x585b
cmpq $0x0, -0x20(%rbp)
je 0x5859
movq -0x20(%rbp), %rax
movzwl 0xf(%rax), %eax
cmpl $0x0, %eax
jne 0x5857
movq -0x20(%rbp), %rax
movzwl 0x11(%rax), %eax
cmpl $0x0, %eax
jne 0x5857
movb $0x0, -0x21(%rbp)
movb $0x0, -0x21(%rbp)
movzbl -0x21(%rbp), %eax
movq -0x20(%rbp), %rcx
movzbl 0x16(%rcx), %ecx
cmpl %ecx, %eax
jge 0x5855
movq -0x20(%rbp), %rax
addq $0x6, %rax
addq $0x11, %rax
movzbl -0x21(%rbp), %ecx
imulq $0x5, %rcx, %rcx
addq %rcx, %rax
movzbl (%rax), %eax
cmpl $0x1a, %eax
jne 0x5849
movq -0x20(%rbp), %rax
addq $0x6, %rax
addq $0x11, %rax
movzbl -0x21(%rbp), %ecx
imulq $0x5, %rcx, %rcx
addq %rcx, %rax
movzwl 0x3(%rax), %eax
cmpl $0x10, %eax
setg %al
andb $0x1, %al
movzbl %al, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x112(%rax)
jmp 0x584b
movb -0x21(%rbp), %al
addb $0x1, %al
movb %al, -0x21(%rbp)
jmp 0x57ea
jmp 0x5857
jmp 0x5859
jmp 0x585b
cmpq $0x0, -0x20(%rbp)
je 0x586b
movq -0x20(%rbp), %rdi
callq 0x5040
movl $0x1, %edi
callq 0x66d0
movb %al, 0x31c86(%rip)      # 0x37501
movq -0x10(%rbp), %rax
cmpb $0x0, 0x51(%rax)
je 0x5895
movl $0x1, %edi
callq 0x66d0
movb %al, 0x31c7c(%rip)      # 0x37511
movl $0x2, %edi
callq 0x66d0
movb %al, 0x31c5d(%rip)      # 0x37502
movl $0x3, %edi
callq 0x66d0
movb %al, 0x31c4e(%rip)      # 0x37503
movl $0xb, %edi
callq 0x66d0
movb %al, 0x31c46(%rip)      # 0x3750b
movl $0x1a, %edi
callq 0x66d0
movb %al, 0x31c45(%rip)      # 0x3751a
movzbl 0x31c3e(%rip), %ecx     # 0x3751a
movq -0x10(%rbp), %rax
movl %ecx, 0x122(%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)