// File: /workspace/github_c_makefile_star2_O2/Carton32[P]quectel-CM/atc.c
// Function: requestGetIPAddress
static int requestGetIPAddress(PROFILE_T *profile, int curIpFamily) {
    int err;
    ATResponse *p_response = NULL;
    char *cmd = NULL;
    ATLine *p_cur = NULL;
    int pdp = profile->pdp;
    unsigned int v4Addr = 0;

    (void)curIpFamily;

    if (!asr_style_atc) {
        err = at_netdevstatus(pdp, &v4Addr);
        goto _error;
    }

    asprintf(&cmd, "AT+CGPADDR=%d", profile->pdp);
    err = at_send_command_singleline(cmd, "+CGPADDR:", &p_response);
    safe_free(cmd);
    if (at_response_error(err, p_response))
        goto _error;

    //+CGPADDR: 1,"10.201.80.91","2409:8930:4B3:41C7:F9B8:3D9B:A2F7:CA96"
    for (p_cur = p_response->p_intermediates; p_cur != NULL; p_cur = p_cur->p_next)
    {
        char *ipv4 = NULL;
        char *ipv6 = NULL;

        err = at_tok_scanf(p_cur->line, "%d%s%s", &pdp, &ipv4, &ipv6);
        if (err < 2 || pdp != profile->pdp)
            continue;

        if (ipv4) {
            int addr[4] = {0, 0, 0, 0};

            sscanf(ipv4, "%d.%d.%d.%d", &addr[0], &addr[1], &addr[2], &addr[3]);
            v4Addr = (addr[0]) | (addr[1]<<8) | (addr[2]<<16) | (addr[3]<<24);
            break;
        }
    }

_error:
    if (v4Addr && profile->ipv4.Address != v4Addr) {
        unsigned char *v4 = (unsigned char *)&v4Addr;

        profile->ipv4.Address = v4Addr;
        dbg_time("%s %d.%d.%d.%d", __func__, v4[0], v4[1], v4[2], v4[3]);    
    }
        
    //dbg_time("%s err=%d", __func__, err);
    return v4Addr ? 0 : -1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
andq $0x0, 0x18(%rsp)
movq %rdi, %r14
andq $0x0, 0x10(%rsp)
movl 0x48(%rdi), %edx
andl $0x0, 0x4(%rsp)
movl %edx, (%rsp)
cmpb $0x0, 0x124a5(%rip)     # 0x2af3c
pushq $-0x1
popq %rbx
je 0x18bc7
leaq 0x8870(%rip), %rsi      # 0x21317
leaq 0x10(%rsp), %r15
movq %r15, %rdi
xorl %eax, %eax
callq 0x53c0
movq (%r15), %rdi
leaq 0x8865(%rip), %rsi      # 0x21325
leaq 0x18(%rsp), %rdx
callq 0x19e06
movl %eax, %ebp
movq (%r15), %rdi
testq %rdi, %rdi
je 0x18adf
callq 0x5040
andq $0x0, 0x10(%rsp)
testl %ebp, %ebp
setne %al
movq 0x18(%rsp), %rbx
testq %rbx, %rbx
sete %cl
orb %al, %cl
jne 0x18c90
cmpq $0x0, 0x8(%rbx)
je 0x18c90
cmpl $0x0, (%rbx)
je 0x18c90
addq $0x10, %rbx
leaq 0x8689(%rip), %r15      # 0x2119f
movq %rsp, %r12
leaq 0x8(%rsp), %r13
leaq 0x30(%rsp), %rbp
movq (%rbx), %rbx
testq %rbx, %rbx
je 0x18c90
andq $0x0, 0x8(%rsp)
andq $0x0, 0x30(%rsp)
movq 0x8(%rbx), %rdi
movq %r15, %rsi
movq %r12, %rdx
movq %r13, %rcx
movq %rbp, %r8
xorl %eax, %eax
callq 0x1a825
cmpl $0x2, %eax
jl 0x18b23
movl (%rsp), %eax
cmpl 0x48(%r14), %eax
setne %al
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
sete %cl
orb %al, %cl
jne 0x18b23
xorps %xmm0, %xmm0
leaq 0x24(%rsp), %rcx
movaps %xmm0, -0x4(%rcx)
leaq 0x28(%rsp), %r8
leaq 0x2c(%rsp), %r9
leaq 0x8741(%rip), %rsi      # 0x212ce
leaq 0x20(%rsp), %r12
movq %r12, %rdx
xorl %eax, %eax
callq 0x5390
movl (%r12), %r15d
movl 0x4(%r12), %ebp
shll $0x8, %ebp
orl %r15d, %ebp
movl 0x8(%r12), %eax
shll $0x10, %eax
movl 0xc(%r12), %r12d
shll $0x18, %r12d
orl %eax, %r12d
orl %ebp, %r12d
pushq $-0x1
popq %rbx
jmp 0x18bdf
leaq 0x4(%rsp), %r15
movl %edx, %edi
movq %r15, %rsi
callq 0x19553
movl (%r15), %ebp
movl %ebp, %r12d
movl %ebp, %r15d
testl %r12d, %r12d
je 0x18c93
xorl %ebx, %ebx
cmpl %r12d, 0x126(%r14)
je 0x18c93
shrl $0x8, %ebp
movl %r12d, %r13d
shrl $0x10, %r13d
movl %r12d, 0x126(%r14)
shrl $0x18, %r12d
movq 0x103a5(%rip), %rax     # 0x28fb8
movq (%rax), %r14
callq 0xe343
movl $0xff, %ecx
andl %ecx, %r15d
andl %ecx, %ebp
andl %ecx, %r13d
leaq 0x8700(%rip), %rsi      # 0x2132f
leaq 0x606e(%rip), %rcx      # 0x1eca4
xorl %ebx, %ebx
movq %r14, %rdi
movq %rax, %rdx
movl %r15d, %r8d
movl %ebp, %r9d
xorl %eax, %eax
pushq %r12
pushq %r13
callq 0x52c0
popq %rcx
popq %rdx
leaq 0x11050(%rip), %rax     # 0x29ca8
movq (%rax), %r14
testq %r14, %r14
je 0x18c93
callq 0xe343
leaq 0x86c3(%rip), %rsi      # 0x2132f
leaq 0x6031(%rip), %rcx      # 0x1eca4
xorl %ebx, %ebx
movq %r14, %rdi
movq %rax, %rdx
movl %r15d, %r8d
movl %ebp, %r9d
xorl %eax, %eax
pushq %r12
pushq %r13
callq 0x52c0
popq %rcx
popq %rdx
jmp 0x18c93
pushq $-0x1
popq %rbx
movl %ebx, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq