// File: /workspace/github_c_makefile_star2_O3/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, (%rsp)
movl $0x0, 0x4(%rsp)
cmpb $0x0, 0x122a6(%rip)     # 0x2bf3c
je 0x19d7c
leaq 0x9654(%rip), %rsi      # 0x232f7
leaq 0x10(%rsp), %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x53b0
movq (%r14), %rdi
leaq 0x9649(%rip), %rsi      # 0x23305
leaq 0x18(%rsp), %rdx
callq 0x1afa9
movl %eax, %ebp
movq (%r14), %rdi
testq %rdi, %rdi
je 0x19cde
callq 0x5040
movq $0x0, 0x10(%rsp)
testl %ebp, %ebp
setne %cl
movq 0x18(%rsp), %rax
testq %rax, %rax
sete %dl
orb %cl, %dl
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jne 0x19e50
cmpq $0x0, 0x8(%rax)
je 0x19e50
cmpl $0x0, (%rax)
je 0x19e50
movq 0x10(%rax), %r14
testq %r14, %r14
je 0x19e50
xorl %r15d, %r15d
leaq 0x8(%rsp), %r12
leaq 0x30(%rsp), %r13
movq %r15, 0x8(%rsp)
movq %r15, 0x30(%rsp)
movq 0x8(%r14), %rdi
leaq 0x9441(%rip), %rsi      # 0x2317f
movq %rsp, %rdx
movq %r12, %rcx
movq %r13, %r8
xorl %eax, %eax
callq 0x1bb39
cmpl $0x2, %eax
jl 0x19d6f
movl (%rsp), %eax
cmpl 0x48(%rbx), %eax
setne %al
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
sete %cl
orb %al, %cl
je 0x19e61
movq (%r14), %r14
testq %r14, %r14
jne 0x19d29
jmp 0x19e50
leaq 0x4(%rsp), %r14
movl %edx, %edi
movq %r14, %rsi
callq 0x1a78b
movl (%r14), %r14d
movl %r14d, %r12d
movl %r14d, %r15d
testl %r12d, %r12d
je 0x19e4b
xorl %ebp, %ebp
cmpl %r12d, 0x126(%rbx)
je 0x19e50
shrl $0x8, %r14d
movl %r12d, %r13d
shrl $0x10, %r13d
movl %r12d, 0x126(%rbx)
shrl $0x18, %r12d
movq 0x101f7(%rip), %rax     # 0x29fc0
movq (%rax), %rbx
callq 0xea3b
movl $0xff, %ecx
andl %ecx, %r15d
andl %ecx, %r14d
andl %ecx, %r13d
leaq 0x9529(%rip), %rsi      # 0x2330f
leaq 0x6ea1(%rip), %rcx      # 0x20c8e
xorl %ebp, %ebp
movq %rbx, %rdi
movq %rax, %rdx
movl %r15d, %r8d
movl %r14d, %r9d
xorl %eax, %eax
pushq %r12
pushq %r13
callq 0x52c0
addq $0x10, %rsp
leaq 0x10e97(%rip), %rax     # 0x2aca8
movq (%rax), %rbx
testq %rbx, %rbx
je 0x19e50
callq 0xea3b
leaq 0x94ea(%rip), %rsi      # 0x2330f
leaq 0x6e62(%rip), %rcx      # 0x20c8e
xorl %ebp, %ebp
movq %rbx, %rdi
movq %rax, %rdx
movl %r15d, %r8d
movl %r14d, %r9d
xorl %eax, %eax
pushq %r12
pushq %r13
callq 0x52c0
addq $0x10, %rsp
jmp 0x19e50
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movl %ebp, %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 0x9430(%rip), %rsi      # 0x232ae
leaq 0x20(%rsp), %r12
movq %r12, %rdx
xorl %eax, %eax
callq 0x5390
movl (%r12), %r15d
movl 0x4(%r12), %r14d
shll $0x8, %r14d
orl %r15d, %r14d
movl 0x8(%r12), %eax
shll $0x10, %eax
movl 0xc(%r12), %r12d
shll $0x18, %r12d
orl %eax, %r12d
orl %r14d, %r12d
jmp 0x19d94