// File: /workspace/github_c_makefile_star2_O0/Carton32[P]quectel-CM/atc.c
// Function: atc_init
static int atc_init(PROFILE_T *profile) {
    int err;
    char *cmd;
    ATResponse *p_response = NULL;


    err = at_handshake();
    if (err) {
        dbg_time("handshake fail, TODO ... ");
        goto exit;
    }
	
    s_pdp = profile->pdp;
    at_send_command_singleline("AT+QCFG=\"usbnet\"", "+QCFG:", NULL);
    at_send_command_multiline("AT+QNETDEVCTL=?", "+QNETDEVCTL:", NULL);
    at_send_command("AT+CGREG=2", NULL); //GPRS Network Registration Status
    at_send_command("AT+CEREG=2", NULL); //EPS Network Registration Status
    at_send_command("AT+C5GREG=2", NULL); //5GS Network Registration Status

    err = at_send_command_singleline("AT+QNETDEVSTATUS=?", "+QNETDEVSTATUS:", &p_response);
    if (at_response_error(err, p_response))
        asr_style_atc = 1; //EC200T/EC100Y do not support this AT, but RG801/RG500U support 
    safe_at_response_free(p_response);

    err = at_send_command_singleline("AT+QCFG=\"NAT\"", "+QCFG:", &p_response);
    if (!at_response_error(err, p_response)) {
        int old_nat, new_nat = asr_style_atc ? 1 : 0;

        err = at_tok_scanf(p_response->p_intermediates->line, "%s%d", NULL, &old_nat);
        if (err == 2 && old_nat != new_nat) {
            safe_at_response_free(p_response);
            asprintf(&cmd, "AT+QCFG=\"NAT\",%d", new_nat);
            err = at_send_command(cmd, &p_response);
            safe_free(cmd);
            if (!at_response_error(err, p_response)) {
                err = at_send_command("at+cfun=1,1",NULL);
                if (!err)
                    g_donot_exit_when_modem_hangup = 1;
                //reboot to take effect
            }
            safe_at_response_free(p_response);
        }
        err = 0;
    }
    safe_at_response_free(p_response);

exit:
    return err;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq $0x0, -0x20(%rbp)
movb $0x0, %al
callq 0x270d0
movl %eax, -0xc(%rbp)
cmpl $0x0, -0xc(%rbp)
je 0x2322a
jmp 0x231c6
movq 0x13e13(%rip), %rax     # 0x36fe0
movq (%rax), %rax
movq %rax, -0x30(%rbp)
callq 0x13930
movq -0x30(%rbp), %rdi
movq %rax, %rdx
leaq 0xd01b(%rip), %rsi      # 0x30202
movb $0x0, %al
callq 0x52c0
leaq 0x14c73(%rip), %rax     # 0x37e68
cmpq $0x0, (%rax)
je 0x23223
leaq 0x14c66(%rip), %rax     # 0x37e68
movq (%rax), %rax
movq %rax, -0x38(%rbp)
callq 0x13930
movq -0x38(%rbp), %rdi
movq %rax, %rdx
leaq 0xcfe6(%rip), %rsi      # 0x30202
movb $0x0, %al
callq 0x52c0
jmp 0x23225
jmp 0x23469
movq -0x8(%rbp), %rax
movl 0x48(%rax), %eax
movl %eax, 0x15ed1(%rip)     # 0x39108
leaq 0xcfe4(%rip), %rdi      # 0x30222
leaq 0xcfee(%rip), %rsi      # 0x30233
xorl %eax, %eax
movl %eax, %edx
callq 0x26e80
leaq 0xcfe5(%rip), %rdi      # 0x3023a
leaq 0xcfee(%rip), %rsi      # 0x3024a
xorl %eax, %eax
movl %eax, %edx
callq 0x27030
leaq 0xcfeb(%rip), %rdi      # 0x30257
xorl %eax, %eax
movl %eax, %esi
callq 0x26d90
leaq 0xcfe6(%rip), %rdi      # 0x30262
xorl %eax, %eax
movl %eax, %esi
callq 0x26d90
leaq 0xcfe1(%rip), %rdi      # 0x3026d
xorl %eax, %eax
movl %eax, %esi
callq 0x26d90
leaq 0xcfdd(%rip), %rdi      # 0x30279
leaq 0xcfe9(%rip), %rsi      # 0x3028c
leaq -0x20(%rbp), %rdx
callq 0x26e80
movl %eax, -0xc(%rbp)
cmpl $0x0, -0xc(%rbp)
jne 0x232d0
cmpq $0x0, -0x20(%rbp)
je 0x232d0
movq -0x20(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x232d0
movq -0x20(%rbp), %rax
cmpl $0x0, (%rax)
jne 0x232da
movl $0x1, 0x15e32(%rip)     # 0x3910c
cmpq $0x0, -0x20(%rbp)
je 0x232f2
movq -0x20(%rbp), %rdi
callq 0x26d20
movq $0x0, -0x20(%rbp)
leaq 0xcfa3(%rip), %rdi      # 0x3029c
leaq 0xcf33(%rip), %rsi      # 0x30233
leaq -0x20(%rbp), %rdx
callq 0x26e80
movl %eax, -0xc(%rbp)
cmpl $0x0, -0xc(%rbp)
jne 0x2344f
cmpq $0x0, -0x20(%rbp)
je 0x2344f
movq -0x20(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x2344f
movq -0x20(%rbp), %rax
cmpl $0x0, (%rax)
je 0x2344f
movl 0x15dc9(%rip), %edx     # 0x3910c
xorl %eax, %eax
movl $0x1, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
movl %eax, -0x28(%rbp)
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %rdi
leaq 0xd0e0(%rip), %rsi      # 0x30446
xorl %eax, %eax
movl %eax, %edx
leaq -0x24(%rbp), %rcx
movb $0x0, %al
callq 0x28860
movl %eax, -0xc(%rbp)
cmpl $0x2, -0xc(%rbp)
jne 0x23448
movl -0x24(%rbp), %eax
cmpl -0x28(%rbp), %eax
je 0x23448
cmpq $0x0, -0x20(%rbp)
je 0x233a6
movq -0x20(%rbp), %rdi
callq 0x26d20
movq $0x0, -0x20(%rbp)
movl -0x28(%rbp), %edx
leaq -0x18(%rbp), %rdi
leaq 0xcef6(%rip), %rsi      # 0x302aa
movb $0x0, %al
callq 0x53c0
movq -0x18(%rbp), %rdi
leaq -0x20(%rbp), %rsi
callq 0x26d90
movl %eax, -0xc(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x233e3
movq -0x18(%rbp), %rdi
callq 0x5040
movq $0x0, -0x18(%rbp)
jmp 0x233e5
cmpl $0x0, -0xc(%rbp)
jne 0x2342e
cmpq $0x0, -0x20(%rbp)
je 0x2342e
movq -0x20(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x2342e
movq -0x20(%rbp), %rax
cmpl $0x0, (%rax)
je 0x2342e
leaq 0xceae(%rip), %rdi      # 0x302bb
xorl %eax, %eax
movl %eax, %esi
callq 0x26d90
movl %eax, -0xc(%rbp)
cmpl $0x0, -0xc(%rbp)
jne 0x2342c
leaq 0x1416a(%rip), %rax     # 0x37590
movl $0x1, (%rax)
jmp 0x2342e
cmpq $0x0, -0x20(%rbp)
je 0x23446
movq -0x20(%rbp), %rdi
callq 0x26d20
movq $0x0, -0x20(%rbp)
jmp 0x23448
movl $0x0, -0xc(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x23467
movq -0x20(%rbp), %rdi
callq 0x26d20
movq $0x0, -0x20(%rbp)
jmp 0x23469
movl -0xc(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)