// File: /workspace/github_c_makefile_star2_O2/Carton32[P]quectel-CM/atc.c
// Function: requestGetSignalInfo
static int requestGetSignalInfo(void) {
    int retVal = -1;
    int err;
    ATResponse *p_response = NULL;
    int i;
    ATLine *p_cur = NULL;
    char *rat = NULL;
    int cops_act = 0;
    int is_nr5g_nsa = 0, nr5g_sa = 0;
    int verbose = 0;

    err = at_send_command_singleline("at+cops?", "+COPS:", &p_response);
    if (at_response_error(err, p_response)) goto _error;
    if (!p_response->p_intermediates || !p_response->p_intermediates->line) goto _error;

    retVal = 0;
    err = at_tok_scanf(p_response->p_intermediates->line, "%d%d%s%d", NULL, NULL, NULL, &cops_act);
    if (err != 4) goto _error;

    nr5g_sa = (cops_act == 11);

    safe_at_response_free(p_response);
    err = at_send_command_multiline("at+qeng=\"servingcell\"", "+QENG:", &p_response);
    if (at_response_error(err, p_response))
        goto _error;

    for (i = 0, p_cur = p_response->p_intermediates; p_cur != NULL; p_cur = p_cur->p_next, i++) {
        char *type, *state;

        err = at_tok_scanf(p_cur->line, "%s%s", &type, &state);
        if (err != 2 || strcmp(type, "servingcell"))
            continue;

        if (!strcmp(state, "SEARCH") || !strcmp(state, "LIMSRV"))
            continue;

        if (!strcmp(state, "NOCONN") || !strcmp(state, "CONNECT")) {
            err = at_tok_scanf(p_cur->line, "%s%s%s", &type, &state, &rat);
            if (err != 3)
                continue;        
        }
        else {
            rat = state;
        }
       
        if (!strcmp(rat, "NR5G-SA"))
        {
            //+QENG: "servingcell",<state>,"NR5G-SA",<duplex_mode>,<MCC>,<MNC>,<cellID>,<PCID>,<TAC>,<ARFCN>,<band>,<NR_DL_bandwidth>,<RSRP>,<RSRQ>,<SINR>,<tx_power>,<srxlev> 
            //+QENG: "servingcell","NOCONN","NR5G-SA","TDD", 454,12,0,21,4ED,636576,78,3,-85,-11,32,0,5184
            struct qeng_servingcell_nr5g_sa {
                char *cell_type, *state, *rat, *is_tdd;
                int MCC, MNC, cellID/*hex*/;
                int PCID, TAC/*hex*/, ARFCN;
                int band, NR_DL_bandwidth;
                int RSRP, RSRQ, RSSI, SINR;
            };
            struct qeng_servingcell_nr5g_sa nr5g_sa;

            memset(&nr5g_sa, 0, sizeof(nr5g_sa));
            err = at_tok_scanf(p_cur->line, "%s,%s,%s,%s,%d,%d,%x,%d,%x,%d,%d,%d,%d,%d,%d,%d",
                &nr5g_sa.cell_type, &nr5g_sa.state, &nr5g_sa.rat, &nr5g_sa.is_tdd,
                &nr5g_sa.MCC, &nr5g_sa.MNC, &nr5g_sa.cellID, &nr5g_sa.PCID, &nr5g_sa.TAC,
                &nr5g_sa.ARFCN, &nr5g_sa.band, &nr5g_sa.NR_DL_bandwidth,
                &nr5g_sa.RSRP, &nr5g_sa.RSRQ, &nr5g_sa.RSSI, &nr5g_sa.SINR);

            if (err >= 13 && verbose) {
                dbg_time("%s,%s,%s,%s,%d,%d,%x,%d,%x,%d,%d,%d,%d,%d,%d,%d",
                    nr5g_sa.cell_type, nr5g_sa.state, nr5g_sa.rat, nr5g_sa.is_tdd,
                    nr5g_sa.MCC, nr5g_sa.MNC, nr5g_sa.cellID, nr5g_sa.PCID, nr5g_sa.TAC,
                    nr5g_sa.ARFCN, nr5g_sa.band, nr5g_sa.NR_DL_bandwidth,
                    nr5g_sa.RSRP, nr5g_sa.RSRQ, nr5g_sa.RSSI, nr5g_sa.SINR);
            }
        }
        else if (!strcmp(rat, "NR5G-NSA"))
        {
            //+QENG: "NR5G-NSA",<MCC>,<MNC>,<PCID>,<RSRP>,< SINR>,<RSRQ>,<ARFCN>,<band>
            struct qeng_servingcell_nr5g_nsa {
                char *mcc, *mnc;
                int pcid, rsrp, sinr, rsrq;
            };
            struct qeng_servingcell_nr5g_nsa nr5g_nsa;
           
            memset(&nr5g_nsa, 0, sizeof(nr5g_nsa));
            err = at_tok_scanf(p_cur->line, "%s%s%s%s%d%d%d%dd",
                NULL, NULL, &nr5g_nsa.mcc, &nr5g_nsa.mnc, &nr5g_nsa.pcid, &nr5g_nsa.rsrp, &nr5g_nsa.sinr, &nr5g_nsa.rsrq);
            if (err == 8 && verbose)
            {
                dbg_time("mcc=%s, mnc=%s, pcid=%d, rsrp=%d, sinr=%d, rsrq=%d",
                    nr5g_nsa.mcc, nr5g_nsa.mnc, nr5g_nsa.pcid, nr5g_nsa.rsrp, nr5g_nsa.sinr, nr5g_nsa.rsrq);
            }

            is_nr5g_nsa = 1;
        }
        else if (!strcmp(rat, "LTE"))
        {
            //+QENG: "LTE",<is_tdd>,<MCC>,<MNC>,<cellID>,<PCID>,<earfcn>,<freq_band_ind>,<UL_bandwidth>,<DL_bandwidth>,<TAC>,<RSRP>,<RSRQ>,<RSSI>,<SINR>,<CQI>,<tx_power>,<srxlev>
            struct qeng_servingcell_lte {
                char *is_tdd, *mcc, *mnc;
                int cellID/*hex*/, pcid, earfcn, freq_band_ind, ul_bandwidth, dl_bandwidth;
                int tac/*hex*/, rsrp, rsrq, rssi, sinr, cqi,tx_power,srxlev;
            };
            struct qeng_servingcell_lte lte;

            memset(&lte, 0, sizeof(lte));
            if (!strcmp(rat, state))
                err = at_tok_scanf(p_cur->line, "%s%s%s%s%s%x%d%d%d%d%d%x%d%d%d%d%d%d%d",
                    NULL, NULL, &lte.is_tdd, &lte.mcc, &lte.mnc,
                    &lte.cellID, &lte.pcid, &lte.earfcn, &lte.freq_band_ind, &lte.ul_bandwidth, &lte.dl_bandwidth,
                    &lte.tac, &lte.rsrp, &lte.rsrq, &lte.rssi, &lte.sinr, &lte.cqi, &lte.tx_power, &lte.srxlev);
            else
                 err = at_tok_scanf(p_cur->line, "%s%s%s%s%s%s%x%d%d%d%d%d%x%d%d%d%d%d%d%d",
                    NULL, NULL, NULL, &lte.is_tdd, &lte.mcc, &lte.mnc,
                    &lte.cellID, &lte.pcid, &lte.earfcn, &lte.freq_band_ind, &lte.ul_bandwidth, &lte.dl_bandwidth,
                    &lte.tac, &lte.rsrp, &lte.rsrq, &lte.rssi, &lte.sinr, &lte.cqi, &lte.tx_power, &lte.srxlev);
            
                if (err >= 18 && verbose)
                {
                    dbg_time("is_tdd=%s, mcc=%s, mnc=%s", lte.is_tdd, lte.mcc, lte.mnc);
                    dbg_time("cellID=%x, pcid=%d, earfcn=%d", lte.cellID, lte.pcid, lte.earfcn);
                    dbg_time("freq_band_ind=%d, ul_bandwidth=%d, dl_bandwidth=%d", lte.freq_band_ind, lte.ul_bandwidth, lte.dl_bandwidth);
                    dbg_time("tac=%x, rsrp=%d, rsrq=%d, rssi=%d, sinr=%d", lte.tac, lte.rsrp, lte.rsrq, lte.rssi, lte.sinr);
                    dbg_time("cqi=%d, tx_power=%d, earfcn=%d", lte.cqi, lte.tx_power, lte.srxlev);
                }
        }
    }

    if (is_nr5g_nsa) {
        int endc_avl, plmn_info_list_r15_avl, endc_rstr, nr5g_basic;

        is_nr5g_nsa = 0;
        safe_at_response_free(p_response);
        err = at_send_command_multiline("at+qendc", "+QENDC:", &p_response);
        if (at_response_error(err, p_response)) goto _error;
        if (!p_response->p_intermediates || !p_response->p_intermediates->line) goto _error;

        err = at_tok_scanf(p_response->p_intermediates->line, "%d%d%d%d",
            &endc_avl, &plmn_info_list_r15_avl, &endc_rstr, &nr5g_basic);
        if (err == 4 && nr5g_basic) {
            is_nr5g_nsa = 1;
        }
    }

    if (verbose)
        dbg_time("cops_act=%d, nr5g_nsa=%d, nr5g_sa=%d", cops_act, is_nr5g_nsa, nr5g_sa);

_error:
    safe_at_response_free(p_response);
    return retVal;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
leaq 0x8(%rsp), %rbx
andq $0x0, (%rbx)
andq $0x0, 0x78(%rsp)
andl $0x0, 0x84(%rsp)
leaq 0x8671(%rip), %rdi      # 0x21344
leaq 0x8501(%rip), %rsi      # 0x211db
movq %rbx, %rdx
callq 0x19e06
testl %eax, %eax
setne %al
movq (%rbx), %rbx
testq %rbx, %rbx
sete %cl
pushq $-0x1
popq %r14
orb %al, %cl
je 0x18d06
testq %rbx, %rbx
jne 0x19161
jmp 0x19169
cmpq $0x0, 0x8(%rbx)
je 0x19161
cmpl $0x0, (%rbx)
je 0x19161
movq 0x10(%rbx), %rax
testq %rax, %rax
je 0x19161
movq 0x8(%rax), %rdi
testq %rdi, %rdi
je 0x19161
leaq 0x84a7(%rip), %rsi      # 0x211e2
xorl %r14d, %r14d
leaq 0x84(%rsp), %r9
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x1a825
movq 0x8(%rsp), %rbx
cmpl $0x4, %eax
jne 0x18cf8
testq %rbx, %rbx
je 0x18d71
movq %rbx, %rdi
callq 0x19d1e
andq $0x0, 0x8(%rsp)
leaq 0x85d5(%rip), %rdi      # 0x2134d
leaq 0x85e4(%rip), %rsi      # 0x21363
leaq 0x8(%rsp), %rbx
movq %rbx, %rdx
callq 0x19ed7
testl %eax, %eax
setne %al
movq (%rbx), %rbx
testq %rbx, %rbx
sete %cl
orb %al, %cl
jne 0x18cf8
xorl %r14d, %r14d
cmpq $0x0, 0x8(%rbx)
je 0x19161
cmpl $0x0, (%rbx)
je 0x19161
addq $0x10, %rbx
leaq 0x83dd(%rip), %r14      # 0x211a1
leaq 0x88(%rsp), %r15
leaq 0x70(%rsp), %r12
leaq 0x8592(%rip), %r13      # 0x2136a
movl $0x0, 0x6c(%rsp)
movq (%rbx), %rbx
testq %rbx, %rbx
je 0x1917e
movq 0x8(%rbx), %rdi
movq %r14, %rsi
movq %r15, %rdx
movq %r12, %rcx
xorl %eax, %eax
callq 0x1a825
cmpl $0x2, %eax
jne 0x18de0
movq 0x88(%rsp), %rdi
movq %r13, %rsi
callq 0x52a0
testl %eax, %eax
jne 0x18de0
movq 0x70(%rsp), %rbp
movq %rbp, %rdi
leaq 0x854e(%rip), %rsi      # 0x21376
callq 0x52a0
testl %eax, %eax
je 0x18de0
movq %rbp, %rdi
leaq 0x8542(%rip), %rsi      # 0x2137d
callq 0x52a0
testl %eax, %eax
je 0x18de0
movq %rbp, %rdi
leaq 0x8536(%rip), %rsi      # 0x21384
callq 0x52a0
testl %eax, %eax
je 0x18e71
movq %rbp, %rdi
leaq 0x6d28(%rip), %rsi      # 0x1fb89
callq 0x52a0
testl %eax, %eax
je 0x18e71
movq %rbp, 0x78(%rsp)
jmp 0x18e9c
movq 0x8(%rbx), %rdi
leaq 0x844b(%rip), %rsi      # 0x212c7
movq %r15, %rdx
movq %r12, %rcx
leaq 0x78(%rsp), %r8
xorl %eax, %eax
callq 0x1a825
cmpl $0x3, %eax
jne 0x18de0
movq 0x78(%rsp), %rbp
movq %rbp, %rdi
leaq 0x84e5(%rip), %rsi      # 0x2138b
callq 0x52a0
testl %eax, %eax
je 0x18fb3
movq %rbp, %rdi
leaq 0x8506(%rip), %rsi      # 0x213c3
callq 0x52a0
testl %eax, %eax
je 0x1905b
movq %rbp, %rdi
leaq 0x5bb1(%rip), %rsi      # 0x1ea85
callq 0x52a0
testl %eax, %eax
jne 0x18de0
xorps %xmm0, %xmm0
movaps %xmm0, 0x50(%rsp)
movaps %xmm0, 0x40(%rsp)
movaps %xmm0, 0x30(%rsp)
movaps %xmm0, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
movq 0x70(%rsp), %rsi
movq %rbp, %rdi
callq 0x52a0
movq 0x8(%rbx), %rdi
testl %eax, %eax
je 0x190b4
leaq 0x84c1(%rip), %rsi      # 0x213de
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
leaq 0x10(%rsp), %r9
xorl %eax, %eax
leaq 0x5c(%rsp), %r10
pushq %r10
leaq 0x60(%rsp), %r10
pushq %r10
leaq 0x64(%rsp), %r10
pushq %r10
leaq 0x68(%rsp), %r10
pushq %r10
leaq 0x6c(%rsp), %r10
pushq %r10
leaq 0x70(%rsp), %r10
pushq %r10
leaq 0x74(%rsp), %r10
pushq %r10
leaq 0x78(%rsp), %r10
pushq %r10
leaq 0x7c(%rsp), %r10
pushq %r10
leaq 0x80(%rsp), %r10
pushq %r10
leaq 0x84(%rsp), %r10
pushq %r10
leaq 0x88(%rsp), %r10
pushq %r10
leaq 0x8c(%rsp), %r10
pushq %r10
leaq 0x90(%rsp), %r10
pushq %r10
leaq 0x90(%rsp), %r10
pushq %r10
leaq 0x90(%rsp), %r10
jmp 0x1914e
xorps %xmm0, %xmm0
movaps %xmm0, 0x50(%rsp)
movaps %xmm0, 0x40(%rsp)
movaps %xmm0, 0x30(%rsp)
movaps %xmm0, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
movq 0x8(%rbx), %rdi
leaq 0x83b9(%rip), %rsi      # 0x21393
leaq 0x10(%rsp), %rdx
leaq 0x18(%rsp), %rcx
leaq 0x20(%rsp), %r8
leaq 0x28(%rsp), %r9
xorl %eax, %eax
leaq 0x5c(%rsp), %r10
pushq %r10
leaq 0x60(%rsp), %r10
pushq %r10
leaq 0x64(%rsp), %r10
pushq %r10
leaq 0x68(%rsp), %r10
pushq %r10
leaq 0x6c(%rsp), %r10
pushq %r10
leaq 0x70(%rsp), %r10
pushq %r10
leaq 0x74(%rsp), %r10
pushq %r10
leaq 0x78(%rsp), %r10
pushq %r10
leaq 0x7c(%rsp), %r10
pushq %r10
leaq 0x80(%rsp), %r10
pushq %r10
leaq 0x84(%rsp), %r10
pushq %r10
leaq 0x88(%rsp), %r10
pushq %r10
callq 0x1a825
addq $0x60, %rsp
jmp 0x18de0
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
movq 0x8(%rbx), %rdi
leaq 0x8359(%rip), %rsi      # 0x213cc
xorl %edx, %edx
xorl %ecx, %ecx
leaq 0x10(%rsp), %r8
leaq 0x18(%rsp), %r9
xorl %eax, %eax
leaq 0x2c(%rsp), %r10
pushq %r10
leaq 0x30(%rsp), %r10
pushq %r10
leaq 0x34(%rsp), %r10
pushq %r10
leaq 0x38(%rsp), %r10
pushq %r10
callq 0x1a825
addq $0x20, %rsp
pushq $0x1
popq %rax
movl %eax, 0x6c(%rsp)
jmp 0x18de0
subq $0x8, %rsp
leaq 0x8321(%rip), %rsi      # 0x213e0
xorl %edx, %edx
xorl %ecx, %ecx
leaq 0x18(%rsp), %r8
leaq 0x20(%rsp), %r9
xorl %eax, %eax
leaq 0x64(%rsp), %r10
pushq %r10
leaq 0x68(%rsp), %r10
pushq %r10
leaq 0x6c(%rsp), %r10
pushq %r10
leaq 0x70(%rsp), %r10
pushq %r10
leaq 0x74(%rsp), %r10
pushq %r10
leaq 0x78(%rsp), %r10
pushq %r10
leaq 0x7c(%rsp), %r10
pushq %r10
leaq 0x80(%rsp), %r10
pushq %r10
leaq 0x84(%rsp), %r10
pushq %r10
leaq 0x88(%rsp), %r10
pushq %r10
leaq 0x8c(%rsp), %r10
pushq %r10
leaq 0x90(%rsp), %r10
pushq %r10
leaq 0x94(%rsp), %r10
pushq %r10
leaq 0x98(%rsp), %r10
pushq %r10
leaq 0x98(%rsp), %r10
pushq %r10
callq 0x1a825
addq $0x80, %rsp
jmp 0x18de0
movq %rbx, %rdi
callq 0x19d1e
movl %r14d, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %r14d, %r14d
movq 0x8(%rsp), %rbx
cmpl $0x0, 0x6c(%rsp)
je 0x18cf8
testq %rbx, %rbx
je 0x191a4
movq %rbx, %rdi
callq 0x19d1e
andq $0x0, 0x8(%rsp)
leaq 0x825c(%rip), %rdi      # 0x21407
leaq 0x825e(%rip), %rsi      # 0x21410
leaq 0x8(%rsp), %rbx
movq %rbx, %rdx
callq 0x19ed7
testl %eax, %eax
setne %al
movq (%rbx), %rbx
testq %rbx, %rbx
sete %cl
orb %al, %cl
jne 0x18cf8
cmpq $0x0, 0x8(%rbx)
je 0x18cf8
cmpl $0x0, (%rbx)
je 0x18cf8
movq 0x10(%rbx), %rax
testq %rax, %rax
je 0x18cf8
movq 0x8(%rax), %rdi
testq %rdi, %rdi
je 0x18cf8
leaq 0x81f4(%rip), %rsi      # 0x213fe
leaq 0x10(%rsp), %rdx
leaq 0x88(%rsp), %rcx
leaq 0x70(%rsp), %r8
leaq 0x94(%rsp), %r9
xorl %eax, %eax
callq 0x1a825
movq 0x8(%rsp), %rbx
jmp 0x18cf8