// File: /workspace/github_c_makefile_star2_O1/Carton32[P]quectel-CM/atc.c
// Function: requestSetProfile
static int requestSetProfile(PROFILE_T *profile) {
    int err;
    ATResponse *p_response = NULL;
    char *cmd = NULL;
    const char *new_apn = profile->apn ? profile->apn : "";
    const char *new_user = profile->user ? profile->user : "";
    const char *new_password = profile->password ? profile->password : "";
    const char *ipStr[] = {"NULL", "IPV4", "IPV6", "IPV4V6"};

    dbg_time("%s[%d] %s/%s/%s/%d/%s", __func__,
        profile->pdp, profile->apn, profile->user, profile->password,
        profile->auth,ipStr[profile->iptype]);

    if ( !strcmp(profile->old_apn, new_apn) && !strcmp(profile->old_user, new_user)
        && !strcmp(profile->old_password, new_password)
        && profile->old_iptype == profile->iptype
        && profile->old_auth == profile->auth)
    {
        dbg_time("no need to set skip the rest");
        return 0;
    }

    if (QICSGP_C == 5)
        asprintf(&cmd, "AT+QICSGP=%d,%d,\"%s\",\"%s\",\"%s\",%d",
            profile->pdp, profile->iptype, new_apn, new_user, new_password, profile->auth);
    else if (QICSGP_C == 4)
        asprintf(&cmd, "AT+QICSGP=%d,\"%s\",\"%s\",\"%s\",%d",
            profile->pdp, new_apn, new_user, new_password, profile->auth);
    else
        goto _error;

    err = at_send_command(cmd, &p_response);
    safe_free(cmd);
    if (at_response_error(err, p_response)) {
        safe_at_response_free(p_response);
        asprintf(&cmd, "AT+CGDCONT=%d,\"%s\",\"%s\"", profile->pdp, ipStr[profile->iptype], new_apn);
        err = at_send_command(cmd, &p_response);
        safe_free(cmd);
    }

_error:
    safe_at_response_free(p_response);
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, %r14
xorl %eax, %eax
movq %rax, 0x30(%rsp)
movq %rax, 0x28(%rsp)
movq (%rdi), %rbx
movq 0x8(%rdi), %r15
testq %rbx, %rbx
leaq 0x5ec5(%rip), %rax      # 0x1eea5
cmoveq %rax, %rbx
testq %r15, %r15
cmoveq %rax, %r15
movq 0x10(%rdi), %r12
testq %r12, %r12
cmoveq %rax, %r12
movq 0x10fc3(%rip), %rax     # 0x29fc0
movq (%rax), %r13
callq 0xeb2f
movl 0x48(%r14), %r8d
movq (%r14), %r9
movups 0x8(%r14), %xmm0
movl 0x18(%r14), %ecx
movslq 0x1c(%r14), %rdx
leaq 0x10d10(%rip), %rbp     # 0x29d30
movq (%rbp,%rdx,8), %rdx
movq %rdx, 0x18(%rsp)
movl %ecx, 0x10(%rsp)
movups %xmm0, (%rsp)
leaq 0x7993(%rip), %rsi      # 0x209cc
leaq 0x79a8(%rip), %rcx      # 0x209e8
movq %r13, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x52c0
leaq 0x11c54(%rip), %rax     # 0x2aca8
movq (%rax), %r13
testq %r13, %r13
je 0x190a2
callq 0xeb2f
movl 0x48(%r14), %r8d
movq (%r14), %r9
movups 0x8(%r14), %xmm0
movl 0x18(%r14), %ecx
movslq 0x1c(%r14), %rdx
movq (%rbp,%rdx,8), %rdx
movq %rdx, 0x18(%rsp)
movl %ecx, 0x10(%rsp)
movups %xmm0, (%rsp)
leaq 0x793e(%rip), %rsi      # 0x209cc
leaq 0x7953(%rip), %rcx      # 0x209e8
movq %r13, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x52c0
leaq 0x256(%r14), %rdi
movq %rbx, %rsi
callq 0x52a0
testl %eax, %eax
jne 0x19151
leaq 0x296(%r14), %rdi
movq %r15, %rsi
callq 0x52a0
testl %eax, %eax
jne 0x19151
leaq 0x2d6(%r14), %rdi
movq %r12, %rsi
callq 0x52a0
testl %eax, %eax
jne 0x19151
movl 0x31a(%r14), %eax
cmpl 0x1c(%r14), %eax
jne 0x19151
movl 0x316(%r14), %eax
cmpl 0x18(%r14), %eax
jne 0x19151
movq 0x10ebc(%rip), %rax     # 0x29fc0
movq (%rax), %rbx
callq 0xeb2f
leaq 0x78e7(%rip), %rsi      # 0x209fa
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x52c0
leaq 0x11b81(%rip), %rax     # 0x2aca8
movq (%rax), %rbx
testq %rbx, %rbx
je 0x1927e
callq 0xeb2f
leaq 0x78bb(%rip), %rsi      # 0x209fa
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x52c0
jmp 0x1927e
movl 0x12de9(%rip), %eax     # 0x2bf40
cmpl $0x4, %eax
je 0x19197
cmpl $0x5, %eax
jne 0x19266
movq %rbp, %r13
movl 0x48(%r14), %edx
movl 0x18(%r14), %eax
movl 0x1c(%r14), %ecx
movl %eax, 0x8(%rsp)
movq %r12, (%rsp)
leaq 0x9f2f(%rip), %rsi      # 0x230b2
leaq 0x28(%rsp), %rdi
movq %rbx, %r8
movq %r15, %r9
xorl %eax, %eax
callq 0x53b0
jmp 0x191c1
movl 0x18(%r14), %eax
movl 0x48(%r14), %edx
movl %eax, (%rsp)
leaq 0x9f2b(%rip), %rsi      # 0x230d4
leaq 0x28(%rsp), %rdi
movq %rbx, %rcx
movq %r15, %r8
movq %r12, %r9
xorl %eax, %eax
callq 0x53b0
movq %rbp, %r13
movq 0x28(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x1b323
movl %eax, %ebp
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x191ea
callq 0x5040
movq $0x0, 0x28(%rsp)
testl %ebp, %ebp
setne %al
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
sete %cl
orb %al, %cl
jne 0x1920a
cmpq $0x0, 0x8(%rdi)
je 0x1920a
cmpl $0x0, (%rdi)
jne 0x19266
testq %rdi, %rdi
je 0x1921d
callq 0x1b2da
movq $0x0, 0x30(%rsp)
movl 0x48(%r14), %edx
movslq 0x1c(%r14), %rax
movq (%r13,%rax,8), %rcx
leaq 0x9ec2(%rip), %rsi      # 0x230f3
leaq 0x28(%rsp), %r14
movq %r14, %rdi
movq %rbx, %r8
xorl %eax, %eax
callq 0x53b0
movq (%r14), %rdi
leaq 0x30(%rsp), %rsi
callq 0x1b323
movq (%r14), %rdi
testq %rdi, %rdi
je 0x19266
callq 0x5040
movq $0x0, 0x28(%rsp)
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x1927e
callq 0x1b2da
movq $0x0, 0x30(%rsp)
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq