// File: /workspace/github_c_makefile_star2_O0/Carton32[P]quectel-CM/atc.c
// Function: requestGetProfile
static int requestGetProfile(PROFILE_T *profile) {
    int retVal = -1;
    int err;
    ATResponse *p_response = NULL;
    char *cmd = NULL;
    int pdp;
    int old_iptype = 1; // 1 ~ IPV4, 2 ~ IPV6, 3 ~ IPV4V6
    char *old_apn = "", *old_user = "", *old_password = "";
    int old_auth = 0;
    const char *ipStr[] = {"NULL", "IPV4", "IPV6", "IPV4V6"};

    if (profile->enable_ipv4 && profile->enable_ipv6)
        profile->iptype = 3;
    else if (profile->enable_ipv6)
        profile->iptype = 2;
    else
        profile->iptype = 1;

_re_check:
    asprintf(&cmd, "AT+QICSGP=%d", profile->pdp);
    err = at_send_command_singleline(cmd, "+QICSGP:", &p_response);
    safe_free(cmd);
    if (err == AT_ERROR_INVALID_RESPONSE && p_response == NULL) {
        //bug of RG801H
        safe_at_response_free(p_response);
        asprintf(&cmd, "AT+QICSGP=%d,%d,\"\",\"\",\"\",0", profile->pdp, profile->iptype);
        err = at_send_command(cmd, &p_response);
        safe_free(cmd);
        if (!at_response_error(err, p_response)) {
            safe_at_response_free(p_response);
            goto _re_check;
        }
    }

    if (!at_response_error(err, p_response)) {
        QICSGP_C = at_tok_count(p_response->p_intermediates->line);
        if (QICSGP_C > 5)
            QICSGP_C = 5;

        if (QICSGP_C == 5)
            err = at_tok_scanf(p_response->p_intermediates->line,
                "%d%d%s%s%s%d", &pdp, &old_iptype, &old_apn,  &old_user, &old_password, &old_auth);
        else if (QICSGP_C == 4)
            err = at_tok_scanf(p_response->p_intermediates->line,
                "%d%s%s%s%d", &pdp, &old_apn,  &old_user, &old_password, &old_auth);
        else
            goto _error;

        if (err != (QICSGP_C + 1) || pdp != profile->pdp)
            goto _error;
    }
    else {
        ATLine *atLine = NULL;
        char *cgdcont_iptype = NULL;

        safe_at_response_free(p_response);
        err = at_send_command_multiline("AT+CGDCONT?", "+CGDCONT:", &p_response);
        if (at_response_error(err, p_response))
            goto _error;

        atLine = p_response->p_intermediates;
        while (atLine) {
            err = at_tok_scanf(atLine->line, "%d%s%s", &pdp, &cgdcont_iptype, &old_apn);
            if (err == 3 && pdp == profile->pdp) {
                if (!strcasecmp(cgdcont_iptype, ipStr[3]))
                    old_iptype = 3;
                else if (!strcasecmp(cgdcont_iptype, ipStr[2]))
                     old_iptype = 2;
                else
                    old_iptype = 1;
               break;
            }
            old_apn = NULL;
            atLine = atLine->p_next;
        }
    }

    retVal = 0;

_error:
    if (!old_apn) old_apn = "";
    if (!old_user) old_user = "";
    if (!old_password) old_password = "";

    strncpy(profile->old_apn, old_apn, sizeof(profile->old_apn));
    strncpy(profile->old_user, old_user, sizeof(profile->old_user));
    strncpy(profile->old_password, old_password, sizeof(profile->old_password));
    profile->old_auth = old_auth;
    profile->old_iptype = old_iptype; 

    dbg_time("%s[%d] %s/%s/%s/%d/%s", __func__,
        profile->pdp, profile->old_apn, profile->old_user, profile->old_password,
        profile->old_auth, ipStr[profile->old_iptype]);

    safe_at_response_free(p_response);

    return retVal;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
subq $0xa8, %rsp
movq %rdi, -0x10(%rbp)
movl $0xffffffff, -0x14(%rbp) # imm = 0xFFFFFFFF
movq $0x0, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movl $0x1, -0x30(%rbp)
leaq 0x7e34(%rip), %rax      # 0x2c009
movq %rax, -0x38(%rbp)
leaq 0x7e29(%rip), %rax      # 0x2c009
movq %rax, -0x40(%rbp)
leaq 0x7e1e(%rip), %rax      # 0x2c009
movq %rax, -0x48(%rbp)
movl $0x0, -0x4c(%rbp)
movq 0x12bd3(%rip), %rax     # 0x36dd0
movq %rax, -0x70(%rbp)
movq 0x12bd0(%rip), %rax     # 0x36dd8
movq %rax, -0x68(%rbp)
movq 0x12bcd(%rip), %rax     # 0x36de0
movq %rax, -0x60(%rbp)
movq 0x12bca(%rip), %rax     # 0x36de8
movq %rax, -0x58(%rbp)
movq -0x10(%rbp), %rax
movzbl 0x50(%rax), %eax
cmpl $0x0, %eax
je 0x24249
movq -0x10(%rbp), %rax
movzbl 0x51(%rax), %eax
cmpl $0x0, %eax
je 0x24249
movq -0x10(%rbp), %rax
movl $0x3, 0x1c(%rax)
jmp 0x2426d
movq -0x10(%rbp), %rax
cmpb $0x0, 0x51(%rax)
je 0x24260
movq -0x10(%rbp), %rax
movl $0x2, 0x1c(%rax)
jmp 0x2426b
movq -0x10(%rbp), %rax
movl $0x1, 0x1c(%rax)
jmp 0x2426d
jmp 0x2426f
movq -0x10(%rbp), %rax
movl 0x48(%rax), %edx
leaq -0x28(%rbp), %rdi
leaq 0xc12a(%rip), %rsi      # 0x303ab
movb $0x0, %al
callq 0x53c0
movq -0x28(%rbp), %rdi
leaq 0xc125(%rip), %rsi      # 0x303b8
leaq -0x20(%rbp), %rdx
callq 0x26e80
movl %eax, -0x18(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x242b7
movq -0x28(%rbp), %rdi
callq 0x5040
movq $0x0, -0x28(%rbp)
jmp 0x242b9
cmpl $-0x6, -0x18(%rbp)
jne 0x24370
cmpq $0x0, -0x20(%rbp)
jne 0x24370
cmpq $0x0, -0x20(%rbp)
je 0x242e6
movq -0x20(%rbp), %rdi
callq 0x26d20
movq $0x0, -0x20(%rbp)
movq -0x10(%rbp), %rax
movl 0x48(%rax), %edx
movq -0x10(%rbp), %rax
movl 0x1c(%rax), %ecx
leaq -0x28(%rbp), %rdi
leaq 0xc0c2(%rip), %rsi      # 0x303c1
movb $0x0, %al
callq 0x53c0
movq -0x28(%rbp), %rdi
leaq -0x20(%rbp), %rsi
callq 0x26d90
movl %eax, -0x18(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x2432e
movq -0x28(%rbp), %rdi
callq 0x5040
movq $0x0, -0x28(%rbp)
jmp 0x24330
cmpl $0x0, -0x18(%rbp)
jne 0x2436e
cmpq $0x0, -0x20(%rbp)
je 0x2436e
movq -0x20(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x2436e
movq -0x20(%rbp), %rax
cmpl $0x0, (%rax)
je 0x2436e
cmpq $0x0, -0x20(%rbp)
je 0x24369
movq -0x20(%rbp), %rdi
callq 0x26d20
movq $0x0, -0x20(%rbp)
jmp 0x2426f
jmp 0x24370
cmpl $0x0, -0x18(%rbp)
jne 0x24481
cmpq $0x0, -0x20(%rbp)
je 0x24481
movq -0x20(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x24481
movq -0x20(%rbp), %rax
cmpl $0x0, (%rax)
je 0x24481
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %rdi
callq 0x287f0
movl %eax, 0x14d58(%rip)     # 0x39110
cmpl $0x5, 0x14d51(%rip)     # 0x39110
jle 0x243cb
movl $0x5, 0x14d45(%rip)     # 0x39110
cmpl $0x5, 0x14d3e(%rip)     # 0x39110
jne 0x24414
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %rdi
leaq 0xbff5(%rip), %rsi      # 0x303dc
leaq -0x2c(%rbp), %rdx
leaq -0x30(%rbp), %rcx
leaq -0x38(%rbp), %r8
leaq -0x40(%rbp), %r9
leaq -0x48(%rbp), %r10
leaq -0x4c(%rbp), %rax
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
movb $0x0, %al
callq 0x28860
movl %eax, -0x18(%rbp)
jmp 0x2445b
cmpl $0x4, 0x14cf5(%rip)     # 0x39110
jne 0x24454
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %rdi
leaq 0xbfae(%rip), %rsi      # 0x303de
leaq -0x2c(%rbp), %rdx
leaq -0x38(%rbp), %rcx
leaq -0x40(%rbp), %r8
leaq -0x48(%rbp), %r9
leaq -0x4c(%rbp), %rax
movq %rax, (%rsp)
movb $0x0, %al
callq 0x28860
movl %eax, -0x18(%rbp)
jmp 0x24459
jmp 0x24599
jmp 0x2445b
movl -0x18(%rbp), %eax
movl 0x14cac(%rip), %ecx     # 0x39110
addl $0x1, %ecx
cmpl %ecx, %eax
jne 0x24477
movl -0x2c(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x48(%rcx), %eax
je 0x2447c
jmp 0x24599
jmp 0x24592
movq $0x0, -0x78(%rbp)
movq $0x0, -0x80(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x244a9
movq -0x20(%rbp), %rdi
callq 0x26d20
movq $0x0, -0x20(%rbp)
leaq 0xbf39(%rip), %rdi      # 0x303e9
leaq 0xbf3e(%rip), %rsi      # 0x303f5
leaq -0x20(%rbp), %rdx
callq 0x27030
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x18(%rbp)
jne 0x244e4
cmpq $0x0, -0x20(%rbp)
je 0x244e4
movq -0x20(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x244e4
movq -0x20(%rbp), %rax
cmpl $0x0, (%rax)
jne 0x244e9
jmp 0x24599
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x78(%rbp)
cmpq $0x0, -0x78(%rbp)
je 0x24590
movq -0x78(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0xbef0(%rip), %rsi      # 0x303ff
leaq -0x2c(%rbp), %rdx
leaq -0x80(%rbp), %rcx
leaq -0x38(%rbp), %r8
movb $0x0, %al
callq 0x28860
movl %eax, -0x18(%rbp)
cmpl $0x3, -0x18(%rbp)
jne 0x24578
movl -0x2c(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x48(%rcx), %eax
jne 0x24578
movq -0x80(%rbp), %rdi
movq -0x58(%rbp), %rsi
callq 0x5050
cmpl $0x0, %eax
jne 0x24552
movl $0x3, -0x30(%rbp)
jmp 0x24576
movq -0x80(%rbp), %rdi
movq -0x60(%rbp), %rsi
callq 0x5050
cmpl $0x0, %eax
jne 0x2456d
movl $0x2, -0x30(%rbp)
jmp 0x24574
movl $0x1, -0x30(%rbp)
jmp 0x24576
jmp 0x24590
movq $0x0, -0x38(%rbp)
movq -0x78(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x78(%rbp)
jmp 0x244f5
jmp 0x24592
movl $0x0, -0x14(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0x245ab
leaq 0x7a62(%rip), %rax      # 0x2c009
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x40(%rbp)
jne 0x245bd
leaq 0x7a50(%rip), %rax      # 0x2c009
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x48(%rbp)
jne 0x245cf
leaq 0x7a3e(%rip), %rax      # 0x2c009
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rdi
addq $0x256, %rdi            # imm = 0x256
movq -0x38(%rbp), %rsi
movl $0x40, %edx
callq 0x5080
movq -0x10(%rbp), %rdi
addq $0x296, %rdi            # imm = 0x296
movq -0x40(%rbp), %rsi
movl $0x40, %edx
callq 0x5080
movq -0x10(%rbp), %rdi
addq $0x2d6, %rdi            # imm = 0x2D6
movq -0x48(%rbp), %rsi
movl $0x40, %edx
callq 0x5080
movl -0x4c(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x316(%rax)
movl -0x30(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x31a(%rax)
movq 0x129a5(%rip), %rax     # 0x36fe0
movq (%rax), %rax
movq %rax, -0x88(%rbp)
callq 0x13930
movq -0x88(%rbp), %rdi
movq %rax, %rdx
movq -0x10(%rbp), %rax
movl 0x48(%rax), %r8d
movq -0x10(%rbp), %r9
addq $0x256, %r9             # imm = 0x256
movq -0x10(%rbp), %rbx
addq $0x296, %rbx            # imm = 0x296
movq -0x10(%rbp), %r11
addq $0x2d6, %r11            # imm = 0x2D6
movq -0x10(%rbp), %rax
movl 0x316(%rax), %r10d
movq -0x10(%rbp), %rax
movslq 0x31a(%rax), %rax
movq -0x70(%rbp,%rax,8), %rax
leaq 0x9509(%rip), %rsi      # 0x2dba8
leaq 0x9553(%rip), %rcx      # 0x2dbf9
movq %rbx, (%rsp)
movq %r11, 0x8(%rsp)
movl %r10d, 0x10(%rsp)
movq %rax, 0x18(%rsp)
movb $0x0, %al
callq 0x52c0
leaq 0x137a1(%rip), %rax     # 0x37e68
cmpq $0x0, (%rax)
je 0x2475d
leaq 0x13790(%rip), %rax     # 0x37e68
movq (%rax), %rax
movq %rax, -0x90(%rbp)
callq 0x13930
movq -0x90(%rbp), %rdi
movq %rax, %rdx
movq -0x10(%rbp), %rax
movl 0x48(%rax), %r8d
movq -0x10(%rbp), %r9
addq $0x256, %r9             # imm = 0x256
movq -0x10(%rbp), %rbx
addq $0x296, %rbx            # imm = 0x296
movq -0x10(%rbp), %r11
addq $0x2d6, %r11            # imm = 0x2D6
movq -0x10(%rbp), %rax
movl 0x316(%rax), %r10d
movq -0x10(%rbp), %rax
movslq 0x31a(%rax), %rax
movq -0x70(%rbp,%rax,8), %rax
leaq 0x946c(%rip), %rsi      # 0x2dba8
leaq 0x94b6(%rip), %rcx      # 0x2dbf9
movq %rbx, (%rsp)
movq %r11, 0x8(%rsp)
movl %r10d, 0x10(%rsp)
movq %rax, 0x18(%rsp)
movb $0x0, %al
callq 0x52c0
jmp 0x2475f
cmpq $0x0, -0x20(%rbp)
je 0x24777
movq -0x20(%rbp), %rdi
callq 0x26d20
movq $0x0, -0x20(%rbp)
movl -0x14(%rbp), %eax
addq $0xa8, %rsp
popq %rbx
popq %rbp
retq
nopw %cs:(%rax,%rax)