// File: /workspace/github_c_makefile_star2_O1/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, %r14
movq %rdi, %rbx
movl $0x5, %edi
callq 0xef6c
movw %ax, 0x5(%rbx)
movb $0x1, 0x7(%rbx)
movl $0x2, %edi
callq 0xef6c
movw %ax, 0x8(%rbx)
movb $0x0, 0xa(%rbx)
movb 0x48(%r14), %al
movb %al, 0xb(%rbx)
movb $0x11, 0xc(%rbx)
movl $0x1, %edi
callq 0xef6c
movw %ax, 0xd(%rbx)
movb 0x1c(%r14), %cl
movb %cl, 0xf(%rbx)
movzwl %ax, %edi
callq 0xef61
movl %eax, %r12d
leal 0x3(%r12), %r15d
movq (%r14), %rdi
testq %rdi, %rdi
je 0xe202
movzwl %r15w, %r15d
movb $0x14, 0xc(%rbx,%r15)
callq 0x5160
movzwl %ax, %edi
callq 0xef6c
movw %ax, 0xd(%rbx,%r15)
movq (%r14), %rax
movb (%rax), %cl
movb %cl, 0xf(%rbx,%r15)
testb %cl, %cl
je 0xe1ef
leaq (%r15,%rbx), %rcx
addq $0x10, %rcx
xorl %edx, %edx
movb 0x1(%rax,%rdx), %sil
movb %sil, (%rcx,%rdx)
incq %rdx
testb %sil, %sil
jne 0xe1de
movzwl 0xd(%rbx,%r15), %edi
callq 0xef61
leal (%r12,%rax), %r15d
addl $0x6, %r15d
movq 0x8(%r14), %rdi
testq %rdi, %rdi
je 0xe264
movzwl %r15w, %r12d
movb $0x1b, 0xc(%rbx,%r12)
callq 0x5160
movzwl %ax, %edi
callq 0xef6c
movw %ax, 0xd(%rbx,%r12)
movq 0x8(%r14), %rax
movb (%rax), %cl
movb %cl, 0xf(%rbx,%r12)
testb %cl, %cl
je 0xe252
leaq (%r12,%rbx), %rcx
addq $0x10, %rcx
xorl %edx, %edx
movb 0x1(%rax,%rdx), %sil
movb %sil, (%rcx,%rdx)
incq %rdx
testb %sil, %sil
jne 0xe241
movzwl 0xd(%rbx,%r12), %edi
callq 0xef61
addl %eax, %r15d
addl $0x3, %r15d
movq 0x10(%r14), %rdi
testq %rdi, %rdi
je 0xe2c6
movzwl %r15w, %r12d
movb $0x1c, 0xc(%rbx,%r12)
callq 0x5160
movzwl %ax, %edi
callq 0xef6c
movw %ax, 0xd(%rbx,%r12)
movq 0x10(%r14), %rax
movb (%rax), %cl
movb %cl, 0xf(%rbx,%r12)
testb %cl, %cl
je 0xe2b4
leaq (%r12,%rbx), %rcx
addq $0x10, %rcx
xorl %edx, %edx
movb 0x1(%rax,%rdx), %sil
movb %sil, (%rcx,%rdx)
incq %rdx
testb %sil, %sil
jne 0xe2a3
movzwl 0xd(%rbx,%r12), %edi
callq 0xef61
addl %eax, %r15d
addl $0x3, %r15d
cmpq $0x0, 0x8(%r14)
je 0xe306
cmpq $0x0, 0x10(%r14)
je 0xe306
movzwl %r15w, %r12d
movb $0x1d, 0xc(%rbx,%r12)
movl $0x1, %edi
callq 0xef6c
movw %ax, 0xd(%rbx,%r12)
movb 0x18(%r14), %cl
movb %cl, 0xf(%rbx,%r12)
movzwl %ax, %edi
callq 0xef61
addl %eax, %r15d
addl $0x3, %r15d
addl $0x9, %r15d
movl %r15d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq