// File: /workspace/github_c_makefile_star2_O3/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 0x6146(%rip), %rax      # 0x1eea1
cmoveq %rax, %rbx
testq %r15, %r15
cmoveq %rax, %r15
movq 0x10(%rdi), %r12
testq %r12, %r12
cmoveq %rax, %r12
movq 0x11248(%rip), %rax     # 0x29fc0
movq (%rax), %r13
callq 0xea3b
movl 0x48(%r14), %r8d
movq (%r14), %r9
movups 0x8(%r14), %xmm0
movl 0x18(%r14), %ecx
movslq 0x1c(%r14), %rdx
leaq 0x10f95(%rip), %rbp     # 0x29d30
movq (%rbp,%rdx,8), %rdx
movq %rdx, 0x18(%rsp)
movl %ecx, 0x10(%rsp)
movups %xmm0, (%rsp)
leaq 0x7c14(%rip), %rsi      # 0x209c8
leaq 0x7c29(%rip), %rcx      # 0x209e4
movq %r13, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x52c0
leaq 0x11ed9(%rip), %rax     # 0x2aca8
movq (%rax), %r13
testq %r13, %r13
je 0x18e1d
callq 0xea3b
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 0x7bbf(%rip), %rsi      # 0x209c8
leaq 0x7bd4(%rip), %rcx      # 0x209e4
movq %r13, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x52c0
leaq 0x256(%r14), %rdi
movq %rbx, %rsi
callq 0x52a0
testl %eax, %eax
jne 0x18ecc
leaq 0x296(%r14), %rdi
movq %r15, %rsi
callq 0x52a0
testl %eax, %eax
jne 0x18ecc
leaq 0x2d6(%r14), %rdi
movq %r12, %rsi
callq 0x52a0
testl %eax, %eax
jne 0x18ecc
movl 0x31a(%r14), %eax
cmpl 0x1c(%r14), %eax
jne 0x18ecc
movl 0x316(%r14), %eax
cmpl 0x18(%r14), %eax
jne 0x18ecc
movq 0x11141(%rip), %rax     # 0x29fc0
movq (%rax), %rbx
callq 0xea3b
leaq 0x7b68(%rip), %rsi      # 0x209f6
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x52c0
leaq 0x11e06(%rip), %rax     # 0x2aca8
movq (%rax), %rbx
testq %rbx, %rbx
je 0x18ff2
callq 0xea3b
leaq 0x7b3c(%rip), %rsi      # 0x209f6
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x52c0
jmp 0x18ff2
movl 0x1306e(%rip), %eax     # 0x2bf40
cmpl $0x4, %eax
je 0x18f12
cmpl $0x5, %eax
jne 0x18fe3
movq %rbp, %r13
movl 0x48(%r14), %edx
movl 0x18(%r14), %eax
movl 0x1c(%r14), %ecx
movl %eax, 0x8(%rsp)
movq %r12, (%rsp)
leaq 0xa1d4(%rip), %rsi      # 0x230d2
leaq 0x28(%rsp), %rdi
movq %rbx, %r8
movq %r15, %r9
xorl %eax, %eax
callq 0x53b0
jmp 0x18f3c
movl 0x18(%r14), %eax
movl 0x48(%r14), %edx
movl %eax, (%rsp)
leaq 0xa1d0(%rip), %rsi      # 0x230f4
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 0x1aefe
movl %eax, %ebp
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x18f65
callq 0x5040
movq $0x0, 0x28(%rsp)
testl %ebp, %ebp
setne %al
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
sete %cl
orb %al, %cl
je 0x18f80
testq %rdi, %rdi
jne 0x18f8c
jmp 0x18f9a
cmpq $0x0, 0x8(%rdi)
je 0x18f8c
cmpl $0x0, (%rdi)
jne 0x18fe3
callq 0x1aeb5
movq $0x0, 0x30(%rsp)
movl 0x48(%r14), %edx
movslq 0x1c(%r14), %rax
movq (%r13,%rax,8), %rcx
leaq 0xa165(%rip), %rsi      # 0x23113
leaq 0x28(%rsp), %r14
movq %r14, %rdi
movq %rbx, %r8
xorl %eax, %eax
callq 0x53b0
movq (%r14), %rdi
leaq 0x30(%rsp), %rsi
callq 0x1aefe
movq (%r14), %rdi
testq %rdi, %rdi
je 0x18fe3
callq 0x5040
movq $0x0, 0x28(%rsp)
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x18ff2
callq 0x1aeb5
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq