// File: /workspace/github_c_makefile_star2_O1/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
movq %rdi, %rbx
xorl %eax, %eax
movq %rax, 0x18(%rsp)
movq %rax, 0x10(%rsp)
movl 0x48(%rdi), %edx
movl %edx, 0x4(%rsp)
movl $0x0, (%rsp)
cmpb $0x0, 0x11fef(%rip)     # 0x2bf3c
je 0x1a026
leaq 0x937d(%rip), %rsi      # 0x232d7
leaq 0x10(%rsp), %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x53b0
movq (%r14), %rdi
leaq 0x9372(%rip), %rsi      # 0x232e5
leaq 0x18(%rsp), %rdx
callq 0x1b3c6
movl %eax, %ebp
movq (%r14), %rdi
testq %rdi, %rdi
je 0x19f95
callq 0x5040
movq $0x0, 0x10(%rsp)
testl %ebp, %ebp
setne %cl
movq 0x18(%rsp), %rax
testq %rax, %rax
sete %dl
orb %cl, %dl
jne 0x1a030
cmpq $0x0, 0x8(%rax)
je 0x1a030
cmpl $0x0, (%rax)
je 0x1a030
movq 0x10(%rax), %rbp
testq %rbp, %rbp
je 0x1a030
xorl %r14d, %r14d
leaq 0x4(%rsp), %r15
leaq 0x8(%rsp), %r12
leaq 0x30(%rsp), %r13
movq %r14, 0x8(%rsp)
movq %r14, 0x30(%rsp)
movq 0x8(%rbp), %rdi
leaq 0x9176(%rip), %rsi      # 0x2315f
movq %r15, %rdx
movq %r12, %rcx
movq %r13, %r8
xorl %eax, %eax
callq 0x1be91
cmpl $0x2, %eax
jl 0x1a01b
movl 0x4(%rsp), %eax
cmpl 0x48(%rbx), %eax
setne %al
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
sete %cl
orb %al, %cl
je 0x1a0f2
movq (%rbp), %rbp
testq %rbp, %rbp
jne 0x19fd4
jmp 0x1a030
movq %rsp, %rsi
movl %edx, %edi
callq 0x1aa08
movl (%rsp), %r15d
testl %r15d, %r15d
je 0x1a0db
cmpl %r15d, 0x126(%rbx)
je 0x1a0db
movl %r15d, 0x126(%rbx)
movq 0xff68(%rip), %rax      # 0x29fc0
movq (%rax), %r14
callq 0xeb2f
movzbl (%rsp), %ebx
movzbl 0x1(%rsp), %ebp
movzbl 0x2(%rsp), %r12d
movzbl 0x3(%rsp), %r13d
leaq 0x9273(%rip), %rsi      # 0x232ef
leaq 0x6c0f(%rip), %rcx      # 0x20c92
movq %r14, %rdi
movq %rax, %rdx
movl %ebx, %r8d
movl %ebp, %r9d
xorl %eax, %eax
pushq %r13
pushq %r12
callq 0x52c0
addq $0x10, %rsp
leaq 0x10c03(%rip), %rax     # 0x2aca8
movq (%rax), %r14
testq %r14, %r14
je 0x1a0db
callq 0xeb2f
leaq 0x9236(%rip), %rsi      # 0x232ef
leaq 0x6bd2(%rip), %rcx      # 0x20c92
movq %r14, %rdi
movq %rax, %rdx
movl %ebx, %r8d
movl %ebp, %r9d
xorl %eax, %eax
pushq %r13
pushq %r12
callq 0x52c0
addq $0x10, %rsp
xorl %eax, %eax
cmpl $0x1, %r15d
sbbl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorps %xmm0, %xmm0
leaq 0x24(%rsp), %rcx
movaps %xmm0, -0x4(%rcx)
leaq 0x28(%rsp), %r8
leaq 0x2c(%rsp), %r9
leaq 0x917f(%rip), %rsi      # 0x2328e
leaq 0x20(%rsp), %r14
movq %r14, %rdx
xorl %eax, %eax
callq 0x5390
movl 0x4(%r14), %eax
movl 0x8(%r14), %ecx
shll $0x8, %eax
orl (%r14), %eax
shll $0x10, %ecx
movl 0xc(%r14), %edx
shll $0x18, %edx
orl %ecx, %edx
orl %eax, %edx
movl %edx, (%rsp)
jmp 0x1a030