// File: /workspace/github_c_makefile_star2_O0/Carton32[P]quectel-CM/QMIThread.c
// Function: requestGetSIMStatus
static int requestGetSIMStatus(SIM_Status *pSIMStatus) { //RIL_REQUEST_GET_SIM_STATUS
    PQCQMIMSG pRequest;
    PQCQMIMSG pResponse;
    PQMUX_MSG pMUXMsg;
    int err;
    const char * SIM_Status_String[] = {
        "SIM_ABSENT",
        "SIM_NOT_READY",
        "SIM_READY", /* SIM_READY means the radio state is RADIO_STATE_SIM_READY */
        "SIM_PIN",
        "SIM_PUK",
        "SIM_NETWORK_PERSONALIZATION"
    };

    if (s_9x07)
        pRequest = ComposeQMUXMsg(QMUX_TYPE_UIM, QMIUIM_GET_CARD_STATUS_REQ, NULL, NULL);
    else
        pRequest = ComposeQMUXMsg(QMUX_TYPE_DMS, QMIDMS_UIM_GET_STATE_REQ, NULL, NULL);

    err = QmiThreadSendQMI(pRequest, &pResponse);
    qmi_rsp_check_and_return();

    *pSIMStatus = SIM_ABSENT;
    if (s_9x07)
    {
        PQMIUIM_CARD_STATUS pCardStatus = NULL;
        PQMIUIM_PIN_STATE pPINState = NULL;
        UCHAR CardState = 0x01;
        UCHAR PIN1State = QMI_PIN_STATUS_NOT_VERIF;
        //UCHAR PIN1Retries;
        //UCHAR PUK1Retries;
        //UCHAR PIN2State;
        //UCHAR PIN2Retries;
        //UCHAR PUK2Retries;

        pCardStatus = (PQMIUIM_CARD_STATUS)GetTLV(&pResponse->MUXMsg.QMUXMsgHdr, 0x10);
        if (pCardStatus != NULL)
        {
            pPINState = (PQMIUIM_PIN_STATE)((PUCHAR)pCardStatus + sizeof(QMIUIM_CARD_STATUS) + pCardStatus->AIDLength);
            CardState  = pCardStatus->CardState;
            if (CardState == UIM_CARD_STATE_PRESENT) {
                if (pPINState->UnivPIN == 1)
                {
                   PIN1State = pCardStatus->UPINState;
                   //PIN1Retries = pCardStatus->UPINRetries;
                   //PUK1Retries = pCardStatus->UPUKRetries;
                }
                else
                {
                   PIN1State = pPINState->PIN1State;
                   //PIN1Retries = pPINState->PIN1Retries;
                   //PUK1Retries = pPINState->PUK1Retries;
                }
                //PIN2State = pPINState->PIN2State;
                //PIN2Retries = pPINState->PIN2Retries;
                //PUK2Retries = pPINState->PUK2Retries;
            }
        }

        *pSIMStatus = SIM_ABSENT;
        if ((CardState == 0x01) &&  ((PIN1State == QMI_PIN_STATUS_VERIFIED)|| (PIN1State == QMI_PIN_STATUS_DISABLED)))
        {
            *pSIMStatus = SIM_READY;
        }
        else if (CardState == 0x01)
        {
            if (PIN1State == QMI_PIN_STATUS_NOT_VERIF)
            {
                *pSIMStatus = SIM_PIN;
            }
            if ( PIN1State == QMI_PIN_STATUS_BLOCKED)
            {
                *pSIMStatus = SIM_PUK;
            }
            else if (PIN1State == QMI_PIN_STATUS_PERM_BLOCKED)
            {
                *pSIMStatus = SIM_BAD;
            }
            else if (PIN1State == QMI_PIN_STATUS_NOT_INIT || PIN1State == QMI_PIN_STATUS_VERIFIED || PIN1State == QMI_PIN_STATUS_DISABLED)
            {
                *pSIMStatus = SIM_READY;
            }
        }
        else if (CardState == 0x00 || CardState == 0x02)
        {
        }
        else
        {
        }
    }
    else
    {
    //UIM state. Values:
    // 0x00  UIM initialization completed
    // 0x01  UIM is locked or the UIM failed
    // 0x02  UIM is not present
    // 0x03  Reserved
    // 0xFF  UIM state is currently
    //unavailable
        if (pResponse->MUXMsg.UIMGetStateResp.UIMState == 0x00) {
            *pSIMStatus = SIM_READY;
        } else if (pResponse->MUXMsg.UIMGetStateResp.UIMState == 0x01) {
            *pSIMStatus = SIM_ABSENT;
            err = requestGetPINStatus(pSIMStatus);
        } else if ((pResponse->MUXMsg.UIMGetStateResp.UIMState == 0x02) || (pResponse->MUXMsg.UIMGetStateResp.UIMState == 0xFF)) {
            *pSIMStatus = SIM_ABSENT;
        } else {
            *pSIMStatus = SIM_ABSENT;
        }
    }
    dbg_time("%s SIMStatus: %s", __func__, SIM_Status_String[*pSIMStatus]);

    free(pResponse);

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x10(%rbp)
leaq -0x60(%rbp), %rdi
leaq 0x284d6(%rip), %rsi     # 0x36430
movl $0x30, %edx
callq 0x52f0
cmpl $0x0, 0x29395(%rip)     # 0x37300
je 0xdf89
movl $0xb, %edi
movl $0x2f, %esi
xorl %eax, %eax
movl %eax, %ecx
movq %rcx, %rdx
callq 0x11170
movq %rax, -0x18(%rbp)
jmp 0xdfa3
movl $0x2, %edi
movl $0x44, %esi
xorl %eax, %eax
movl %eax, %ecx
movq %rcx, %rdx
callq 0x11170
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rdi
leaq -0x20(%rbp), %rsi
movl $0x7530, %edx           # imm = 0x7530
leaq 0x1fb89(%rip), %rcx     # 0x2db40
callq 0xc670
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
jl 0xdfd0
cmpq $0x0, -0x20(%rbp)
jne 0xe05e
jmp 0xdfd2
movq 0x29007(%rip), %rax     # 0x36fe0
movq (%rax), %rax
movq %rax, -0x88(%rbp)
callq 0x13930
movq -0x88(%rbp), %rdi
movq %rax, %rdx
movl -0x2c(%rbp), %r8d
leaq 0x1f964(%rip), %rsi     # 0x2d961
leaq 0x1fb3c(%rip), %rcx     # 0x2db40
movb $0x0, %al
callq 0x52c0
leaq 0x29e56(%rip), %rax     # 0x37e68
cmpq $0x0, (%rax)
je 0xe051
leaq 0x29e49(%rip), %rax     # 0x37e68
movq (%rax), %rax
movq %rax, -0x90(%rbp)
callq 0x13930
movq -0x90(%rbp), %rdi
movq %rax, %rdx
movl -0x2c(%rbp), %r8d
leaq 0x1f91e(%rip), %rsi     # 0x2d961
leaq 0x1faf6(%rip), %rcx     # 0x2db40
movb $0x0, %al
callq 0x52c0
jmp 0xe053
movl -0x2c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0xe3f6
movq -0x20(%rbp), %rax
addq $0x6, %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movzwl 0xa(%rax), %edi
callq 0x13ed0
movzwl %ax, %eax
cmpl $0x0, %eax
jne 0xe098
movq -0x28(%rbp), %rax
movzwl 0xc(%rax), %edi
callq 0x13ed0
movzwl %ax, %eax
cmpl $0x0, %eax
je 0xe179
movq -0x28(%rbp), %rax
movzwl 0xc(%rax), %edi
callq 0x13ed0
movw %ax, -0x62(%rbp)
movq 0x28f30(%rip), %rax     # 0x36fe0
movq (%rax), %rax
movq %rax, -0xa0(%rbp)
callq 0x13930
movq %rax, -0x98(%rbp)
movq -0x28(%rbp), %rax
movzwl 0xa(%rax), %edi
callq 0x13ed0
movq -0xa0(%rbp), %rdi
movq -0x98(%rbp), %rdx
movzwl %ax, %r8d
movzwl -0x62(%rbp), %r9d
leaq 0x1f882(%rip), %rsi     # 0x2d973
leaq 0x1fa48(%rip), %rcx     # 0x2db40
movb $0x0, %al
callq 0x52c0
leaq 0x29d62(%rip), %rax     # 0x37e68
cmpq $0x0, (%rax)
je 0xe162
leaq 0x29d55(%rip), %rax     # 0x37e68
movq (%rax), %rax
movq %rax, -0xb0(%rbp)
callq 0x13930
movq %rax, -0xa8(%rbp)
movq -0x28(%rbp), %rax
movzwl 0xa(%rax), %edi
callq 0x13ed0
movq -0xb0(%rbp), %rdi
movq -0xa8(%rbp), %rdx
movzwl %ax, %r8d
movzwl -0x62(%rbp), %r9d
leaq 0x1f81f(%rip), %rsi     # 0x2d973
leaq 0x1f9e5(%rip), %rcx     # 0x2db40
movb $0x0, %al
callq 0x52c0
jmp 0xe164
movq -0x20(%rbp), %rdi
callq 0x5040
movzwl -0x62(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0xe3f6
jmp 0xe17b
movq -0x10(%rbp), %rax
movl $0x0, (%rax)
cmpl $0x0, 0x29174(%rip)     # 0x37300
je 0xe2df
movq $0x0, -0x70(%rbp)
movq $0x0, -0x78(%rbp)
movb $0x1, -0x79(%rbp)
movb $0x1, -0x7a(%rbp)
movq -0x20(%rbp), %rdi
addq $0x6, %rdi
addq $0x3, %rdi
movl $0x10, %esi
callq 0xc580
movq %rax, -0x70(%rbp)
cmpq $0x0, -0x70(%rbp)
je 0xe21e
movq -0x70(%rbp), %rax
addq $0x19, %rax
movq -0x70(%rbp), %rcx
movzbl 0x18(%rcx), %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x78(%rbp)
movq -0x70(%rbp), %rax
movb 0xc(%rax), %al
movb %al, -0x79(%rbp)
movzbl -0x79(%rbp), %eax
cmpl $0x1, %eax
jne 0xe21c
movq -0x78(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x1, %eax
jne 0xe210
movq -0x70(%rbp), %rax
movb 0xd(%rax), %al
movb %al, -0x7a(%rbp)
jmp 0xe21a
movq -0x78(%rbp), %rax
movb 0x1(%rax), %al
movb %al, -0x7a(%rbp)
jmp 0xe21c
jmp 0xe21e
movq -0x10(%rbp), %rax
movl $0x0, (%rax)
movzbl -0x79(%rbp), %eax
cmpl $0x1, %eax
jne 0xe252
movzbl -0x7a(%rbp), %eax
cmpl $0x2, %eax
je 0xe243
movzbl -0x7a(%rbp), %eax
cmpl $0x3, %eax
jne 0xe252
movq -0x10(%rbp), %rax
movl $0x2, (%rax)
jmp 0xe2dd
movzbl -0x79(%rbp), %eax
cmpl $0x1, %eax
jne 0xe2c3
movzbl -0x7a(%rbp), %eax
cmpl $0x1, %eax
jne 0xe26e
movq -0x10(%rbp), %rax
movl $0x3, (%rax)
movzbl -0x7a(%rbp), %eax
cmpl $0x4, %eax
jne 0xe283
movq -0x10(%rbp), %rax
movl $0x4, (%rax)
jmp 0xe2c1
movzbl -0x7a(%rbp), %eax
cmpl $0x5, %eax
jne 0xe298
movq -0x10(%rbp), %rax
movl $0x6, (%rax)
jmp 0xe2bf
movzbl -0x7a(%rbp), %eax
cmpl $0x0, %eax
je 0xe2b3
movzbl -0x7a(%rbp), %eax
cmpl $0x2, %eax
je 0xe2b3
movzbl -0x7a(%rbp), %eax
cmpl $0x3, %eax
jne 0xe2bd
movq -0x10(%rbp), %rax
movl $0x2, (%rax)
jmp 0xe2bf
jmp 0xe2c1
jmp 0xe2db
movzbl -0x79(%rbp), %eax
cmpl $0x0, %eax
je 0xe2d5
movzbl -0x79(%rbp), %eax
cmpl $0x2, %eax
jne 0xe2d7
jmp 0xe2d9
jmp 0xe2d9
jmp 0xe2db
jmp 0xe2dd
jmp 0xe355
movq -0x20(%rbp), %rax
movzbl 0x17(%rax), %eax
cmpl $0x0, %eax
jne 0xe2f8
movq -0x10(%rbp), %rax
movl $0x2, (%rax)
jmp 0xe353
movq -0x20(%rbp), %rax
movzbl 0x17(%rax), %eax
cmpl $0x1, %eax
jne 0xe31d
movq -0x10(%rbp), %rax
movl $0x0, (%rax)
movq -0x10(%rbp), %rdi
callq 0x118f0
movl %eax, -0x2c(%rbp)
jmp 0xe351
movq -0x20(%rbp), %rax
movzbl 0x17(%rax), %eax
cmpl $0x2, %eax
je 0xe339
movq -0x20(%rbp), %rax
movzbl 0x17(%rax), %eax
cmpl $0xff, %eax
jne 0xe345
movq -0x10(%rbp), %rax
movl $0x0, (%rax)
jmp 0xe34f
movq -0x10(%rbp), %rax
movl $0x0, (%rax)
jmp 0xe351
jmp 0xe353
jmp 0xe355
jmp 0xe357
movq 0x28c82(%rip), %rax     # 0x36fe0
movq (%rax), %rax
movq %rax, -0xb8(%rbp)
callq 0x13930
movq -0xb8(%rbp), %rdi
movq %rax, %rdx
movq -0x10(%rbp), %rax
movl (%rax), %eax
movq -0x60(%rbp,%rax,8), %r8
leaq 0x1f7cb(%rip), %rsi     # 0x2db54
leaq 0x1f7b0(%rip), %rcx     # 0x2db40
movb $0x0, %al
callq 0x52c0
leaq 0x29aca(%rip), %rax     # 0x37e68
cmpq $0x0, (%rax)
je 0xe3e4
leaq 0x29abd(%rip), %rax     # 0x37e68
movq (%rax), %rax
movq %rax, -0xc0(%rbp)
callq 0x13930
movq -0xc0(%rbp), %rdi
movq %rax, %rdx
movq -0x10(%rbp), %rax
movl (%rax), %eax
movq -0x60(%rbp,%rax,8), %r8
leaq 0x1f77e(%rip), %rsi     # 0x2db54
leaq 0x1f763(%rip), %rcx     # 0x2db40
movb $0x0, %al
callq 0x52c0
jmp 0xe3e6
movq -0x20(%rbp), %rdi
callq 0x5040
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xc0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)