// File: /workspace/github_c_makefile_star2_O2/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
andq $0x0, 0x30(%rsp)
andq $0x0, 0x28(%rsp)
movq %rdi, %r14
movq (%rdi), %rbx
movq 0x8(%rdi), %r15
testq %rbx, %rbx
leaq 0x52cb(%rip), %rax      # 0x1cea1
cmoveq %rax, %rbx
testq %r15, %r15
cmoveq %rax, %r15
movq 0x10(%rdi), %r12
testq %r12, %r12
cmoveq %rax, %r12
movq 0x113c5(%rip), %rax     # 0x28fb8
movq (%rax), %r13
callq 0xe343
movl 0x48(%r14), %r8d
movq (%r14), %r9
movups 0x8(%r14), %xmm0
movl 0x18(%r14), %ecx
movslq 0x1c(%r14), %rdx
leaq 0x1118a(%rip), %rbp     # 0x28da0
movq (%rbp,%rdx,8), %rdx
movq %rdx, 0x18(%rsp)
movl %ecx, 0x10(%rsp)
movups %xmm0, (%rsp)
leaq 0x6d99(%rip), %rsi      # 0x1e9c8
leaq 0x6dae(%rip), %rcx      # 0x1e9e4
movq %r13, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x52c0
leaq 0x1205e(%rip), %rax     # 0x29ca8
movq (%rax), %r13
testq %r13, %r13
je 0x17c98
callq 0xe343
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 0x6d44(%rip), %rsi      # 0x1e9c8
leaq 0x6d59(%rip), %rcx      # 0x1e9e4
movq %r13, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x52c0
leaq 0x256(%r14), %rdi
movq %rbx, %rsi
callq 0x52a0
testl %eax, %eax
jne 0x17d47
leaq 0x296(%r14), %rdi
movq %r15, %rsi
callq 0x52a0
testl %eax, %eax
jne 0x17d47
leaq 0x2d6(%r14), %rdi
movq %r12, %rsi
callq 0x52a0
testl %eax, %eax
jne 0x17d47
movl 0x31a(%r14), %eax
cmpl 0x1c(%r14), %eax
jne 0x17d47
movl 0x316(%r14), %eax
cmpl 0x18(%r14), %eax
jne 0x17d47
movq 0x112be(%rip), %rax     # 0x28fb8
movq (%rax), %rbx
callq 0xe343
leaq 0x6ced(%rip), %rsi      # 0x1e9f6
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x52c0
leaq 0x11f8b(%rip), %rax     # 0x29ca8
movq (%rax), %rbx
testq %rbx, %rbx
je 0x17e64
callq 0xe343
leaq 0x6cc1(%rip), %rsi      # 0x1e9f6
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x52c0
jmp 0x17e64
movl 0x131f3(%rip), %eax     # 0x2af40
cmpl $0x4, %eax
je 0x17d8d
cmpl $0x5, %eax
jne 0x17e55
movq %rbp, %r13
movl 0x48(%r14), %edx
movl 0x18(%r14), %eax
movl 0x1c(%r14), %ecx
movl %eax, 0x8(%rsp)
movq %r12, (%rsp)
leaq 0x9379(%rip), %rsi      # 0x210f2
leaq 0x28(%rsp), %rdi
movq %rbx, %r8
movq %r15, %r9
xorl %eax, %eax
callq 0x53c0
jmp 0x17db7
movl 0x18(%r14), %eax
movl 0x48(%r14), %edx
movl %eax, (%rsp)
leaq 0x9375(%rip), %rsi      # 0x21114
leaq 0x28(%rsp), %rdi
movq %rbx, %rcx
movq %r15, %r8
movq %r12, %r9
xorl %eax, %eax
callq 0x53c0
movq %rbp, %r13
movq 0x28(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x19d64
movl %eax, %ebp
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x17ddd
callq 0x5040
andq $0x0, 0x28(%rsp)
testl %ebp, %ebp
setne %al
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
sete %cl
orb %al, %cl
je 0x17df8
testq %rdi, %rdi
jne 0x17e04
jmp 0x17e0f
cmpq $0x0, 0x8(%rdi)
je 0x17e04
cmpl $0x0, (%rdi)
jne 0x17e55
callq 0x19d1e
andq $0x0, 0x30(%rsp)
movl 0x48(%r14), %edx
movslq 0x1c(%r14), %rax
movq (%r13,%rax,8), %rcx
leaq 0x9310(%rip), %rsi      # 0x21133
leaq 0x28(%rsp), %r14
movq %r14, %rdi
movq %rbx, %r8
xorl %eax, %eax
callq 0x53c0
movq (%r14), %rdi
leaq 0x30(%rsp), %rsi
callq 0x19d64
movq (%r14), %rdi
testq %rdi, %rdi
je 0x17e55
callq 0x5040
andq $0x0, 0x28(%rsp)
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x17e64
callq 0x19d1e
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq