// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq $0x0, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movq -0x8(%rbp), %rax
movl 0x48(%rax), %eax
movl %eax, -0x2c(%rbp)
movl $0x0, -0x30(%rbp)
cmpl $0x0, 0x13fca(%rip)     # 0x3910c
jne 0x25158
movl -0x2c(%rbp), %edi
leaq -0x30(%rbp), %rsi
callq 0x26790
movl %eax, -0x10(%rbp)
jmp 0x252a1
movq -0x8(%rbp), %rax
movl 0x48(%rax), %edx
leaq -0x20(%rbp), %rdi
leaq 0xb40f(%rip), %rsi      # 0x30579
movb $0x0, %al
callq 0x53c0
movq -0x20(%rbp), %rdi
leaq 0xb40b(%rip), %rsi      # 0x30587
leaq -0x18(%rbp), %rdx
callq 0x26e80
movl %eax, -0x10(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x251a0
movq -0x20(%rbp), %rdi
callq 0x5040
movq $0x0, -0x20(%rbp)
jmp 0x251a2
cmpl $0x0, -0x10(%rbp)
jne 0x251c3
cmpq $0x0, -0x18(%rbp)
je 0x251c3
movq -0x18(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x251c3
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
jne 0x251c8
jmp 0x252a1
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x2529f
movq $0x0, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0xb201(%rip), %rsi      # 0x303ff
leaq -0x2c(%rbp), %rdx
leaq -0x38(%rbp), %rcx
leaq -0x40(%rbp), %r8
movb $0x0, %al
callq 0x28860
movl %eax, -0x10(%rbp)
cmpl $0x2, -0x10(%rbp)
jl 0x25226
movl -0x2c(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x48(%rcx), %eax
je 0x25228
jmp 0x2528f
cmpq $0x0, -0x38(%rbp)
je 0x2528d
leaq -0x50(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x5200
movq -0x38(%rbp), %rdi
leaq -0x50(%rbp), %rdx
leaq -0x50(%rbp), %rcx
addq $0x4, %rcx
leaq -0x50(%rbp), %r8
addq $0x8, %r8
leaq -0x50(%rbp), %r9
addq $0xc, %r9
leaq 0xb2ca(%rip), %rsi      # 0x30530
movb $0x0, %al
callq 0x53a0
movl -0x50(%rbp), %eax
movl -0x4c(%rbp), %ecx
shll $0x8, %ecx
orl %ecx, %eax
movl -0x48(%rbp), %ecx
shll $0x10, %ecx
orl %ecx, %eax
movl -0x44(%rbp), %ecx
shll $0x18, %ecx
orl %ecx, %eax
movl %eax, -0x30(%rbp)
jmp 0x2529f
jmp 0x2528f
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x28(%rbp)
jmp 0x251d4
jmp 0x252a1
cmpl $0x0, -0x30(%rbp)
je 0x25396
movq -0x8(%rbp), %rax
movl 0x126(%rax), %eax
cmpl -0x30(%rbp), %eax
je 0x25396
leaq -0x30(%rbp), %rax
movq %rax, -0x58(%rbp)
movl -0x30(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x126(%rax)
movq 0x11d06(%rip), %rax     # 0x36fe0
movq (%rax), %rax
movq %rax, -0x60(%rbp)
callq 0x13930
movq -0x60(%rbp), %rdi
movq %rax, %rdx
movq -0x58(%rbp), %rax
movzbl (%rax), %r8d
movq -0x58(%rbp), %rax
movzbl 0x1(%rax), %r9d
movq -0x58(%rbp), %rax
movzbl 0x2(%rax), %r10d
movq -0x58(%rbp), %rax
movzbl 0x3(%rax), %eax
leaq 0xb27b(%rip), %rsi      # 0x30591
leaq 0x8b67(%rip), %rcx      # 0x2de84
movl %r10d, (%rsp)
movl %eax, 0x8(%rsp)
movb $0x0, %al
callq 0x52c0
leaq 0x12b35(%rip), %rax     # 0x37e68
cmpq $0x0, (%rax)
je 0x25392
leaq 0x12b28(%rip), %rax     # 0x37e68
movq (%rax), %rax
movq %rax, -0x68(%rbp)
callq 0x13930
movq -0x68(%rbp), %rdi
movq %rax, %rdx
movq -0x58(%rbp), %rax
movzbl (%rax), %r8d
movq -0x58(%rbp), %rax
movzbl 0x1(%rax), %r9d
movq -0x58(%rbp), %rax
movzbl 0x2(%rax), %r10d
movq -0x58(%rbp), %rax
movzbl 0x3(%rax), %eax
leaq 0xb215(%rip), %rsi      # 0x30591
leaq 0x8b01(%rip), %rcx      # 0x2de84
movl %r10d, (%rsp)
movl %eax, 0x8(%rsp)
movb $0x0, %al
callq 0x52c0
jmp 0x25394
jmp 0x25396
movl -0x30(%rbp), %edx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
xorl %ecx, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
addq $0x80, %rsp
popq %rbp
retq
nop