// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movw $0x0, -0x12(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x28(%rbp)
movl $0x5, %edi
callq 0x13ff0
movw %ax, %cx
movq -0x8(%rbp), %rax
movw %cx, 0x5(%rax)
movq -0x8(%rbp), %rax
movb $0x1, 0x7(%rax)
movl $0x2, %edi
callq 0x13ff0
movw %ax, %cx
movq -0x8(%rbp), %rax
movw %cx, 0x8(%rax)
movq -0x8(%rbp), %rax
movb $0x0, 0xa(%rax)
movq -0x28(%rbp), %rax
movl 0x48(%rax), %eax
movb %al, %cl
movq -0x8(%rbp), %rax
movb %cl, 0xb(%rax)
movq -0x8(%rbp), %rax
addq $0x3, %rax
addq $0x9, %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movzwl -0x12(%rbp), %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movb $0x11, (%rax)
movl $0x1, %edi
callq 0x13ff0
movw %ax, %cx
movq -0x30(%rbp), %rax
movw %cx, 0x1(%rax)
movq -0x28(%rbp), %rax
movl 0x1c(%rax), %eax
movb %al, %cl
movq -0x30(%rbp), %rax
movb %cl, 0x3(%rax)
movq -0x30(%rbp), %rax
movzwl 0x1(%rax), %edi
callq 0x13ed0
movzwl %ax, %eax
movl %eax, %ecx
addq $0x3, %rcx
movzwl -0x12(%rbp), %eax
addq %rcx, %rax
movw %ax, -0x12(%rbp)
movq -0x28(%rbp), %rax
cmpq $0x0, (%rax)
je 0x11e4e
movq -0x20(%rbp), %rax
movzwl -0x12(%rbp), %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movb $0x14, (%rax)
movq -0x28(%rbp), %rax
movq (%rax), %rdi
callq 0x5160
movzwl %ax, %edi
callq 0x13ff0
movw %ax, %cx
movq -0x38(%rbp), %rax
movw %cx, 0x1(%rax)
movq -0x38(%rbp), %rdi
addq $0x3, %rdi
movq -0x28(%rbp), %rax
movq (%rax), %rsi
callq 0x11cb0
movq -0x38(%rbp), %rax
movzwl 0x1(%rax), %edi
callq 0x13ed0
movzwl %ax, %eax
movl %eax, %ecx
addq $0x3, %rcx
movzwl -0x12(%rbp), %eax
addq %rcx, %rax
movw %ax, -0x12(%rbp)
movq -0x28(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x11ec8
movq -0x20(%rbp), %rax
movzwl -0x12(%rbp), %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movb $0x1b, (%rax)
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x5160
movzwl %ax, %edi
callq 0x13ff0
movw %ax, %cx
movq -0x40(%rbp), %rax
movw %cx, 0x1(%rax)
movq -0x40(%rbp), %rdi
addq $0x3, %rdi
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rsi
callq 0x11cb0
movq -0x40(%rbp), %rax
movzwl 0x1(%rax), %edi
callq 0x13ed0
movzwl %ax, %eax
movl %eax, %ecx
addq $0x3, %rcx
movzwl -0x12(%rbp), %eax
addq %rcx, %rax
movw %ax, -0x12(%rbp)
movq -0x28(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x11f42
movq -0x20(%rbp), %rax
movzwl -0x12(%rbp), %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movb $0x1c, (%rax)
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x5160
movzwl %ax, %edi
callq 0x13ff0
movw %ax, %cx
movq -0x48(%rbp), %rax
movw %cx, 0x1(%rax)
movq -0x48(%rbp), %rdi
addq $0x3, %rdi
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rsi
callq 0x11cb0
movq -0x48(%rbp), %rax
movzwl 0x1(%rax), %edi
callq 0x13ed0
movzwl %ax, %eax
movl %eax, %ecx
addq $0x3, %rcx
movzwl -0x12(%rbp), %eax
addq %rcx, %rax
movw %ax, -0x12(%rbp)
movq -0x28(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x11fb7
movq -0x28(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x11fb7
movq -0x20(%rbp), %rax
movzwl -0x12(%rbp), %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movb $0x1d, (%rax)
movl $0x1, %edi
callq 0x13ff0
movw %ax, %cx
movq -0x50(%rbp), %rax
movw %cx, 0x1(%rax)
movq -0x28(%rbp), %rax
movl 0x18(%rax), %eax
movb %al, %cl
movq -0x50(%rbp), %rax
movb %cl, 0x3(%rax)
movq -0x50(%rbp), %rax
movzwl 0x1(%rax), %edi
callq 0x13ed0
movzwl %ax, %eax
movl %eax, %ecx
addq $0x3, %rcx
movzwl -0x12(%rbp), %eax
addq %rcx, %rax
movw %ax, -0x12(%rbp)
movzwl -0x12(%rbp), %eax
addq $0x9, %rax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)