// File: /workspace/github_c_makefile_star2_O2/Carton32[P]quectel-CM/QMIThread.c
// Function: WdsModifyProfileSettingsReq
static USHORT WdsModifyProfileSettingsReq(PQMUX_MSG pMUXMsg, void *arg) {
    USHORT TLVLength = 0;
    UCHAR *pTLV;
    PROFILE_T *profile = (PROFILE_T *)arg;
    PQMIWDS_PDPTYPE pPdpType;

    pMUXMsg->ModifyProfileSettingsReq.Length = cpu_to_le16(sizeof(QMIWDS_MODIFY_PROFILE_SETTINGS_REQ_MSG) - 4);
    pMUXMsg->ModifyProfileSettingsReq.TLVType = 0x01;
    pMUXMsg->ModifyProfileSettingsReq.TLVLength = cpu_to_le16(0x02);
    pMUXMsg->ModifyProfileSettingsReq.ProfileType = 0x00; // 0 ~ 3GPP, 1 ~ 3GPP2
    pMUXMsg->ModifyProfileSettingsReq.ProfileIndex = profile->pdp;

    pTLV = (UCHAR *)(&pMUXMsg->ModifyProfileSettingsReq + 1);

    pPdpType = (PQMIWDS_PDPTYPE)(pTLV + TLVLength);
    pPdpType->TLVType = 0x11;
    pPdpType->TLVLength = cpu_to_le16(0x01);
    pPdpType->PdpType = profile->iptype;
    TLVLength +=(le16_to_cpu(pPdpType->TLVLength) + sizeof(QCQMICTL_TLV_HDR));

    // Set APN Name
    if (profile->apn) {
        PQMIWDS_APNNAME pApnName = (PQMIWDS_APNNAME)(pTLV + TLVLength);
        pApnName->TLVType = 0x14;
        pApnName->TLVLength = cpu_to_le16(strlen(profile->apn));
        qstrcpy((char *)&pApnName->ApnName, profile->apn);
        TLVLength +=(le16_to_cpu(pApnName->TLVLength) + sizeof(QCQMICTL_TLV_HDR));
    }

    // Set User Name
    if (profile->user) {
        PQMIWDS_USERNAME pUserName = (PQMIWDS_USERNAME)(pTLV + TLVLength);
        pUserName->TLVType = 0x1B;
        pUserName->TLVLength = cpu_to_le16(strlen(profile->user));
        qstrcpy((char *)&pUserName->UserName, profile->user);
        TLVLength += (le16_to_cpu(pUserName->TLVLength) + sizeof(QCQMICTL_TLV_HDR));
    }

    // Set Password
    if (profile->password) {
        PQMIWDS_PASSWD pPasswd = (PQMIWDS_PASSWD)(pTLV + TLVLength);
        pPasswd->TLVType = 0x1C;
        pPasswd->TLVLength = cpu_to_le16(strlen(profile->password));
        qstrcpy((char *)&pPasswd->Passwd, profile->password);
        TLVLength +=(le16_to_cpu(pPasswd->TLVLength) + sizeof(QCQMICTL_TLV_HDR));
    }

    // Set Auth Protocol
    if (profile->user && profile->password) {
        PQMIWDS_AUTH_PREFERENCE pAuthPref = (PQMIWDS_AUTH_PREFERENCE)(pTLV + TLVLength);
        pAuthPref->TLVType = 0x1D;
        pAuthPref->TLVLength = cpu_to_le16(0x01);
        pAuthPref->AuthPreference = profile->auth; // 0 ~ None, 1 ~ Pap, 2 ~ Chap, 3 ~ MsChapV2
        TLVLength += (le16_to_cpu(pAuthPref->TLVLength) + sizeof(QCQMICTL_TLV_HDR));
    }

    return sizeof(QMIWDS_MODIFY_PROFILE_SETTINGS_REQ_MSG) + TLVLength;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq %rdi, %r14
pushq $0x5
popq %rdi
callq 0xe749
movw %ax, 0x5(%r14)
movb $0x1, 0x7(%r14)
pushq $0x2
popq %rdi
callq 0xe749
movw %ax, 0x8(%r14)
movb $0x0, 0xa(%r14)
movb 0x48(%rbx), %al
movb %al, 0xb(%r14)
leaq 0xc(%r14), %r12
movb $0x11, 0xc(%r14)
pushq $0x1
popq %rdi
callq 0xe749
movw %ax, 0xd(%r14)
movb 0x1c(%rbx), %cl
movb %cl, 0xf(%r14)
movzwl %ax, %edi
callq 0xe73e
movl %eax, %r15d
leal 0x3(%r15), %r14d
movq (%rbx), %rdi
testq %rdi, %rdi
je 0xda6f
movzwl %r14w, %eax
leaq (%r12,%rax), %r14
addq $0x3, %r14
movb $0x14, -0x3(%r14)
callq 0x5160
movzwl %ax, %edi
callq 0xe749
movw %ax, -0x2(%r14)
movq (%rbx), %rsi
movq %r14, %rdi
callq 0xd9ad
movzwl -0x2(%r14), %edi
callq 0xe73e
leal (%r15,%rax), %r14d
addl $0x6, %r14d
movq 0x8(%rbx), %rdi
testq %rdi, %rdi
je 0xdab8
movzwl %r14w, %eax
leaq (%r12,%rax), %r15
addq $0x3, %r15
movb $0x1b, -0x3(%r15)
callq 0x5160
movzwl %ax, %edi
callq 0xe749
movw %ax, -0x2(%r15)
movq 0x8(%rbx), %rsi
movq %r15, %rdi
callq 0xd9ad
movzwl -0x2(%r15), %edi
callq 0xe73e
addl %eax, %r14d
addl $0x3, %r14d
movq 0x10(%rbx), %rdi
testq %rdi, %rdi
je 0xdb01
movzwl %r14w, %eax
leaq (%r12,%rax), %r15
addq $0x3, %r15
movb $0x1c, -0x3(%r15)
callq 0x5160
movzwl %ax, %edi
callq 0xe749
movw %ax, -0x2(%r15)
movq 0x10(%rbx), %rsi
movq %r15, %rdi
callq 0xd9ad
movzwl -0x2(%r15), %edi
callq 0xe73e
addl %eax, %r14d
addl $0x3, %r14d
cmpq $0x0, 0x8(%rbx)
je 0xdb3d
cmpq $0x0, 0x10(%rbx)
je 0xdb3d
movzwl %r14w, %r15d
movb $0x1d, (%r12,%r15)
pushq $0x1
popq %rdi
callq 0xe749
movw %ax, 0x1(%r12,%r15)
movb 0x18(%rbx), %cl
movb %cl, 0x3(%r12,%r15)
movzwl %ax, %edi
callq 0xe73e
addl %eax, %r14d
addl $0x3, %r14d
addl $0x9, %r14d
movl %r14d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq