// File: /workspace/github_c_makefile_star2_O1/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
xorl %eax, %eax
leaq 0x8(%rsp), %rbx
movq %rax, (%rbx)
movq %rax, 0x78(%rsp)
movl $0x0, 0x84(%rsp)
leaq 0x9190(%rip), %rdi      # 0x23304
leaq 0x9020(%rip), %rsi      # 0x2319b
movq %rbx, %rdx
callq 0x1b3c6
testl %eax, %eax
setne %cl
movq (%rbx), %rax
testq %rax, %rax
sete %dl
orb %cl, %dl
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jne 0x1a6a2
cmpq $0x0, 0x8(%rax)
je 0x1a6a2
cmpl $0x0, (%rax)
je 0x1a6a2
movq 0x10(%rax), %rax
testq %rax, %rax
je 0x1a6a2
movq 0x8(%rax), %rdi
testq %rdi, %rdi
je 0x1a6a2
leaq 0x8fcf(%rip), %rsi      # 0x231a2
xorl %ebx, %ebx
leaq 0x84(%rsp), %r9
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x1be91
cmpl $0x4, %eax
jne 0x1a6a2
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x1a20c
callq 0x1b2da
movq $0x0, 0x8(%rsp)
leaq 0x90fa(%rip), %rdi      # 0x2330d
leaq 0x9109(%rip), %rsi      # 0x23323
leaq 0x8(%rsp), %r14
movq %r14, %rdx
callq 0x1b498
testl %eax, %eax
setne %cl
movq (%r14), %rax
testq %rax, %rax
sete %dl
orb %cl, %dl
jne 0x1a6a2
cmpq $0x0, 0x8(%rax)
je 0x1a6a2
cmpl $0x0, (%rax)
je 0x1a6a2
movq 0x10(%rax), %r12
testq %r12, %r12
je 0x1a6a2
leaq 0x8efc(%rip), %rbp      # 0x23161
leaq 0x88(%rsp), %rbx
leaq 0x70(%rsp), %r14
leaq 0x90b1(%rip), %r15      # 0x2332a
movl $0x0, 0x6c(%rsp)
movq 0x8(%r12), %rdi
movq %rbp, %rsi
movq %rbx, %rdx
movq %r14, %rcx
xorl %eax, %eax
callq 0x1be91
cmpl $0x2, %eax
jne 0x1a2af
movq 0x88(%rsp), %rdi
movq %r15, %rsi
callq 0x52a0
testl %eax, %eax
je 0x1a2bd
movq (%r12), %r12
testq %r12, %r12
jne 0x1a281
jmp 0x1a60a
movq 0x70(%rsp), %r13
movq %r13, %rdi
leaq 0x906a(%rip), %rsi      # 0x23336
callq 0x52a0
testl %eax, %eax
je 0x1a2af
movq %r13, %rdi
leaq 0x905e(%rip), %rsi      # 0x2333d
callq 0x52a0
testl %eax, %eax
je 0x1a2af
movq %r13, %rdi
leaq 0x9052(%rip), %rsi      # 0x23344
callq 0x52a0
testl %eax, %eax
je 0x1a315
movq %r13, %rdi
leaq 0x7840(%rip), %rsi      # 0x21b45
callq 0x52a0
testl %eax, %eax
je 0x1a315
movq %r13, 0x78(%rsp)
jmp 0x1a33c
movq 0x8(%r12), %rdi
leaq 0x8f66(%rip), %rsi      # 0x23287
movq %rbx, %rdx
movq %r14, %rcx
leaq 0x78(%rsp), %r8
xorl %eax, %eax
callq 0x1be91
cmpl $0x3, %eax
jne 0x1a2af
movq 0x78(%rsp), %r13
movq %r13, %rdi
leaq 0x9000(%rip), %rsi      # 0x2334b
callq 0x52a0
testl %eax, %eax
je 0x1a459
movq %r13, %rdi
leaq 0x9021(%rip), %rsi      # 0x23383
callq 0x52a0
testl %eax, %eax
je 0x1a502
movq %r13, %rdi
leaq 0x6710(%rip), %rsi      # 0x20a89
callq 0x52a0
testl %eax, %eax
jne 0x1a2af
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 %r13, %rdi
callq 0x52a0
movq 0x8(%r12), %rdi
testl %eax, %eax
je 0x1a55d
leaq 0x8fdb(%rip), %rsi      # 0x2339e
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 0x1a5f7
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(%r12), %rdi
leaq 0x8ed2(%rip), %rsi      # 0x23353
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 0x1be91
addq $0x60, %rsp
jmp 0x1a2af
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
movq 0x8(%r12), %rdi
leaq 0x8e71(%rip), %rsi      # 0x2338c
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 0x1be91
addq $0x20, %rsp
movl $0x1, 0x6c(%rsp)
jmp 0x1a2af
subq $0x8, %rsp
leaq 0x8e38(%rip), %rsi      # 0x233a0
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 0x1be91
addq $0x80, %rsp
jmp 0x1a2af
xorl %ebx, %ebx
cmpl $0x0, 0x6c(%rsp)
je 0x1a6a2
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x1a62f
callq 0x1b2da
movq $0x0, 0x8(%rsp)
leaq 0x8d91(%rip), %rdi      # 0x233c7
leaq 0x8d93(%rip), %rsi      # 0x233d0
leaq 0x8(%rsp), %r14
movq %r14, %rdx
callq 0x1b498
testl %eax, %eax
setne %cl
movq (%r14), %rax
testq %rax, %rax
sete %dl
orb %cl, %dl
jne 0x1a6a2
cmpq $0x0, 0x8(%rax)
je 0x1a6a2
cmpl $0x0, (%rax)
je 0x1a6a2
movq 0x10(%rax), %rax
testq %rax, %rax
je 0x1a6a2
movq 0x8(%rax), %rdi
testq %rdi, %rdi
je 0x1a6a2
leaq 0x8d3d(%rip), %rsi      # 0x233be
leaq 0x10(%rsp), %rdx
leaq 0x88(%rsp), %rcx
leaq 0x70(%rsp), %r8
leaq 0x94(%rsp), %r9
xorl %eax, %eax
callq 0x1be91
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x1a6ba
callq 0x1b2da
movq $0x0, 0x8(%rsp)
movl %ebx, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq