// File: /workspace/github_c_makefile_star2_O3/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, 0x70(%rsp)
movl $0x0, 0x7c(%rsp)
leaq 0x943c(%rip), %rdi      # 0x23324
leaq 0x92cc(%rip), %rsi      # 0x231bb
movq %rbx, %rdx
callq 0x1afa9
testl %eax, %eax
setne %al
movq (%rbx), %rdi
testq %rdi, %rdi
sete %cl
orb %al, %cl
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
je 0x19f1c
testq %rdi, %rdi
jne 0x1a3a0
jmp 0x1a3a5
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
cmpq $0x0, 0x8(%rdi)
je 0x1a3a0
cmpl $0x0, (%rdi)
je 0x1a3a0
movq 0x10(%rdi), %rax
testq %rax, %rax
je 0x1a3a0
movq 0x8(%rax), %rax
testq %rax, %rax
je 0x1a3a0
leaq 0x926c(%rip), %rsi      # 0x231c2
xorl %ebx, %ebx
leaq 0x7c(%rsp), %r9
movq %rax, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x1bb39
movq 0x8(%rsp), %rdi
cmpl $0x4, %eax
jne 0x19f0e
testq %rdi, %rdi
je 0x19f8b
callq 0x1aeb5
movq $0x0, 0x8(%rsp)
leaq 0x939b(%rip), %rdi      # 0x2332d
leaq 0x93aa(%rip), %rsi      # 0x23343
leaq 0x8(%rsp), %r14
movq %r14, %rdx
callq 0x1b08f
testl %eax, %eax
setne %al
movq (%r14), %rdi
testq %rdi, %rdi
sete %cl
orb %al, %cl
jne 0x19f0e
xorl %ebx, %ebx
cmpq $0x0, 0x8(%rdi)
je 0x1a3a0
cmpl $0x0, (%rdi)
je 0x1a3a0
movq 0x10(%rdi), %r12
testq %r12, %r12
je 0x1a3a0
movb $0x1, %al
movq %rax, 0x80(%rsp)
leaq 0x9191(%rip), %rbp      # 0x23181
leaq 0x88(%rsp), %r14
leaq 0x68(%rsp), %rbx
leaq 0x9346(%rip), %r15      # 0x2334a
movq 0x8(%r12), %rdi
movq %rbp, %rsi
movq %r14, %rdx
movq %rbx, %rcx
xorl %eax, %eax
callq 0x1bb39
cmpl $0x2, %eax
jne 0x1a032
movq 0x88(%rsp), %rdi
movq %r15, %rsi
callq 0x52a0
testl %eax, %eax
je 0x1a040
movq (%r12), %r12
testq %r12, %r12
jne 0x1a004
jmp 0x1a3b9
movq 0x68(%rsp), %r13
movq %r13, %rdi
leaq 0x9307(%rip), %rsi      # 0x23356
callq 0x52a0
testl %eax, %eax
je 0x1a032
movq %r13, %rdi
leaq 0x92fb(%rip), %rsi      # 0x2335d
callq 0x52a0
testl %eax, %eax
je 0x1a032
movq %r13, %rdi
leaq 0x92ef(%rip), %rsi      # 0x23364
callq 0x52a0
testl %eax, %eax
je 0x1a098
movq %r13, %rdi
leaq 0x7ae5(%rip), %rsi      # 0x21b6d
callq 0x52a0
testl %eax, %eax
je 0x1a098
movq %r13, 0x70(%rsp)
jmp 0x1a0c4
movq 0x8(%r12), %rdi
leaq 0x9203(%rip), %rsi      # 0x232a7
movq %r14, %rdx
movq %rbx, %rcx
leaq 0x70(%rsp), %r8
xorl %eax, %eax
callq 0x1bb39
cmpl $0x3, %eax
jne 0x1a032
movq 0x70(%rsp), %r13
movq %r13, %rdi
leaq 0x929d(%rip), %rsi      # 0x2336b
callq 0x52a0
testl %eax, %eax
je 0x1a1dc
movq %r13, %rdi
leaq 0x92be(%rip), %rsi      # 0x233a3
callq 0x52a0
testl %eax, %eax
je 0x1a332
movq %r13, %rdi
leaq 0x6989(%rip), %rsi      # 0x20a85
callq 0x52a0
testl %eax, %eax
jne 0x1a032
xorps %xmm0, %xmm0
movaps %xmm0, 0x50(%rsp)
movaps %xmm0, 0x40(%rsp)
movaps %xmm0, 0x30(%rsp)
movaps %xmm0, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
movq 0x68(%rsp), %rsi
movq %r13, %rdi
callq 0x52a0
movq 0x8(%r12), %rdi
testl %eax, %eax
je 0x1a285
leaq 0x9278(%rip), %rsi      # 0x233be
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 0x1a31f
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 0x916f(%rip), %rsi      # 0x23373
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 0x1bb39
addq $0x60, %rsp
jmp 0x1a032
subq $0x8, %rsp
leaq 0x9130(%rip), %rsi      # 0x233c0
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 0x1bb39
addq $0x80, %rsp
jmp 0x1a032
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
movq 0x8(%r12), %rdi
movq $0x0, 0x80(%rsp)
leaq 0x9055(%rip), %rsi      # 0x233ac
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 0x1bb39
addq $0x20, %rsp
movq (%r12), %r12
testq %r12, %r12
jne 0x1a004
movq 0x8(%rsp), %rdi
jmp 0x1a3ce
callq 0x1aeb5
movl %ebx, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %ebx, %ebx
movq 0x8(%rsp), %rdi
testb $0x1, 0x80(%rsp)
jne 0x19f0e
testq %rdi, %rdi
je 0x1a3e1
callq 0x1aeb5
movq $0x0, 0x8(%rsp)
leaq 0x8fff(%rip), %rdi      # 0x233e7
leaq 0x9001(%rip), %rsi      # 0x233f0
leaq 0x8(%rsp), %rbx
movq %rbx, %rdx
callq 0x1b08f
testl %eax, %eax
setne %al
movq (%rbx), %rdi
testq %rdi, %rdi
sete %cl
orb %al, %cl
jne 0x1a45c
cmpq $0x0, 0x8(%rdi)
je 0x1a45c
cmpl $0x0, (%rdi)
je 0x1a45c
movq 0x10(%rdi), %rax
testq %rax, %rax
je 0x1a45c
movq 0x8(%rax), %rax
testq %rax, %rax
je 0x1a45c
leaq 0x8fab(%rip), %rsi      # 0x233de
leaq 0x10(%rsp), %rdx
leaq 0x88(%rsp), %rcx
leaq 0x68(%rsp), %r8
leaq 0x94(%rsp), %r9
movq %rax, %rdi
xorl %eax, %eax
callq 0x1bb39
movq 0x8(%rsp), %rdi
xorl %ebx, %ebx
jmp 0x19f0e