decompiled_code:
void __fastcall CKI_FunctionList_Free(void *ptr)
{
log_printf("CKI_FunctionList_Free: entered\n");
if ( ptr )
free(ptr);
}

canonical_decompiled_code:
void __fastcall func15(void *ptr)
{
log_printf("CKI_FunctionList_Free: entered\n");
if ( ptr )
free(ptr);
}

original_code:
void CKI_FunctionList_Free(CK_FUNCTION_LIST_PTR pFunctionList) {
    log_printf("CKI_FunctionList_Free: entered\n");
    if (pFunctionList==((void *)0)) return;
    free(pFunctionList);
    return;
}

canonical_original_code:
void CKI_FunctionList_Free(struct CK_FUNCTION_LIST *pFunctionList) {
    log_printf("CKI_FunctionList_Free: entered\n");
    if (pFunctionList==((void *)0)) return;
    free(pFunctionList);
    return;
}

variable_types: struct CK_FUNCTION_LIST { struct CK_VERSION { unsigned char major; unsigned char minor; } version; unsigned long (*C_Initialize)(void *pReserved); unsigned long (*C_Finalize)(void *pReserved); unsigned long (*C_GetInfo)(struct CK_INFO { struct CK_VERSION cryptokiVersion; unsigned char manufacturerID[32]; unsigned long flags; unsigned char libraryDescription[32]; struct CK_VERSION libraryVersion; } *pInfo); unsigned long (*C_GetFunctionList)(struct CK_FUNCTION_LIST **ppFunctionList); unsigned long (*C_GetSlotList)(unsigned char tokenPresent, unsigned long *pSlotList, unsigned long *pulCount); unsigned long (*C_GetSlotInfo)(unsigned long slotID, struct CK_SLOT_INFO { unsigned char slotDescription[64]; unsigned char manufacturerID[32]; unsigned long flags; struct CK_VERSION hardwareVersion; struct CK_VERSION firmwareVersion; } *pInfo); unsigned long (*C_GetTokenInfo)(unsigned long slotID, struct CK_TOKEN_INFO { unsigned char label[32]; unsigned char manufacturerID[32]; unsigned char model[16]; unsigned char serialNumber[16]; unsigned long flags; unsigned long ulMaxSessionCount; unsigned long ulSessionCount; unsigned long ulMaxRwSessionCount; unsigned long ulRwSessionCount; unsigned long ulMaxPinLen; unsigned long ulMinPinLen; unsigned long ulTotalPublicMemory; unsigned long ulFreePublicMemory; unsigned long ulTotalPrivateMemory; unsigned long ulFreePrivateMemory; struct CK_VERSION hardwareVersion; struct CK_VERSION firmwareVersion; unsigned char utcTime[16]; } *pInfo); unsigned long (*C_GetMechanismList)(unsigned long slotID, unsigned short *pMechanismList, unsigned long *pulCount); unsigned long (*C_GetMechanismInfo)(unsigned long slotID, unsigned short type, struct CK_MECHANISM_INFO { unsigned long ulMinKeySize; unsigned long ulMaxKeySize; unsigned long flags; } *pInfo); unsigned long (*C_InitToken)(unsigned long slotID, unsigned char *pPin, unsigned long ulPinLen, unsigned char *pLabel); unsigned long (*C_InitPIN)(unsigned long hSession, unsigned char *pPin, unsigned long ulPinLen); unsigned long (*C_SetPIN)(unsigned long hSession, unsigned char *pOldPin, unsigned long ulOldLen, unsigned char *pNewPin, unsigned long ulNewLen); unsigned long (*C_OpenSession)(unsigned long slotID, unsigned long flags, void *pApplication, unsigned long *Notify, unsigned long *phSession); unsigned long (*C_CloseSession)(unsigned long hSession); unsigned long (*C_CloseAllSessions)(unsigned long slotID); unsigned long (*C_GetSessionInfo)(unsigned long hSession, struct CK_SESSION_INFO { unsigned long slotID; unsigned long state; unsigned long flags; unsigned long ulDeviceError; } *pInfo); unsigned long (*C_GetOperationState)(unsigned long hSession, unsigned char *pOperationState, unsigned long *pulOperationStateLen); unsigned long (*C_SetOperationState)(unsigned long hSession, unsigned char *pOperationState, unsigned long ulOperationStateLen, unsigned long hEncryptionKey, unsigned long hAuthenticationKey); unsigned long (*C_Login)(unsigned long hSession, unsigned long userType, unsigned char *pPin, unsigned long ulPinLen); unsigned long (*C_Logout)(unsigned long hSession); unsigned long (*C_CreateObject)(unsigned long hSession, struct CK_ATTRIBUTE { unsigned long type; void *value; unsigned long ulValueLen; } *pTemplate, unsigned long ulCount, unsigned long *pObject); unsigned long (*C_CopyObject)(unsigned long hSession, unsigned long hObject, struct CK_ATTRIBUTE *pTemplate, unsigned long ulCount, unsigned long *pNewObject); unsigned long (*C_DestroyObject)(unsigned long hSession, unsigned long hObject); unsigned long (*C_GetObjectSize)(unsigned long hSession, unsigned long hObject, unsigned long *pulSize); unsigned long (*C_GetAttributeValue)(unsigned long hSession, unsigned long hObject, struct CK_ATTRIBUTE *pTemplate, unsigned long ulCount); unsigned long (*C_SetAttributeValue)(unsigned long hSession, unsigned long hObject, struct CK_ATTRIBUTE *pTemplate, unsigned long ulCount); unsigned long (*C_FindObjectsInit)(unsigned long hSession, struct CK_ATTRIBUTE *pTemplate, unsigned long ulCount); unsigned long (*C_FindObjects)(unsigned long hSession, unsigned long *phObject, unsigned long ulMaxObjectCount, unsigned long *pulObjectCount); unsigned long (*C_FindObjectsFinal)(unsigned long hSession); unsigned long (*C_EncryptInit)(unsigned long hSession, struct CK_MECHANISM { unsigned short mechanism; void *pParameter; unsigned long ulParameterLen; } *pMechanism, unsigned long hKey); unsigned long (*C_Encrypt)(unsigned long hSession, unsigned char *pData, unsigned long ulDataLen, unsigned char *pEncryptedData, unsigned long *pulEncryptedDataLen); unsigned long (*C_EncryptUpdate)(unsigned long hSession, unsigned char *pPart, unsigned long ulPartLen, unsigned char *pEncryptedPart, unsigned long *pulEncryptedPartLen); unsigned long (*C_EncryptFinal)(unsigned long hSession, unsigned char *pLastEncryptedPart, unsigned long *pulLastEncyptedPartLen); unsigned long (*C_DecryptInit)(unsigned long hSession, struct CK_MECHANISM *pMechanism, unsigned long hKey); unsigned long (*C_Decrypt)(unsigned long hSession, unsigned char *pEncryptedData, unsigned long ulEncryptedDataLen, unsigned long *pulDataLen); unsigned long (*C_DecryptUpdate)(unsigned long hSession, unsigned char *pEncryptedPart, unsigned long ulEncryptedPartLen, unsigned char *pPart, unsigned long *pulPartLen); unsigned long (*C_DecryptFinal)(unsigned long hSession, unsigned char *pLastPart, unsigned long *pulLastPartLen); unsigned long (*C_DigestInit)(unsigned long hSession, struct CK_MECHANISM *pMechanism); unsigned long (*C_Digest)(unsigned long hSession, unsigned char *pData, unsigned long ulDataLen, unsigned char *pDigest, unsigned long *pulDigestLen); unsigned long (*C_DigestUpdate)(unsigned long hSession, unsigned char *pPart, unsigned long ulPartLen); unsigned long (*C_DigestKey)(unsigned long hSession, unsigned long hKey); unsigned long (*C_DigestFinal)(unsigned long hSession, unsigned char *pDigest, unsigned long *pulDigestLen); unsigned long (*C_SignInit)(unsigned long hSession, struct CK_MECHANISM *pMechanism, unsigned long hKey); unsigned long (*C_Sign)(unsigned long hSession, unsigned char *pData, unsigned long ulDataLen, unsigned char *pSignature, unsigned long *pulSignatureLen); unsigned long (*C_SignUpdate)(unsigned long hSession, unsigned char *pData, unsigned long ulPartLen); unsigned long (*C_SignFinal)(unsigned long hSession, unsigned char *pSignature, unsigned long *pulSignatureLen); unsigned long (*C_SignRecoverInit)(unsigned long hSession, struct CK_MECHANISM *pMechanism, unsigned long hKey); unsigned long (*C_SignRecover)(unsigned long hSession, unsigned char *pData, unsigned long ulDataLen, unsigned char *pSignature, unsigned long *pulSignature); unsigned long (*C_VerifyInit)(unsigned long hSession, struct CK_MECHANISM *pMechanism, unsigned long hKey); unsigned long (*C_Verify)(unsigned long hSession, unsigned char *pData, unsigned long ulDataLen, unsigned char *pSignature, unsigned long ulSignatureLen); unsigned long (*C_VerifyUpdate)(unsigned long hSession, unsigned char *pPart, unsigned long ulPartLen); unsigned long (*C_VerifyFinal)(unsigned long hSession, unsigned char *pSignature, unsigned long ulSignatureLen); unsigned long (*C_VerifyRecoverInit)(unsigned long hSession, struct CK_MECHANISM *pMechanism, unsigned long hKey); unsigned long (*C_VerifyRecover)(unsigned long hSession, unsigned char *pSignature, unsigned long ulSignatureLen, unsigned char *pData, unsigned long *pulDataLen); unsigned long (*C_DigestEncryptUpdate)(unsigned long hSession, unsigned char *pPart, unsigned long ulPartLen, unsigned char *pEncryptedPart, unsigned long *pulEncryptedPartLen); unsigned long (*C_DecryptDigestUpdate)(unsigned long hSession, unsigned char *pEncryptedPart, unsigned long pEncryptedPartLen, unsigned char *pPart, unsigned long *pulPartLen); unsigned long (*C_SignEncryptUpdate)(unsigned long hSession, unsigned char *pPart, unsigned long ulPartLen, unsigned char *pEncryptedPart, unsigned long *pulEncryptedPartLen); unsigned long (*C_DecryptVerifyUpdate)(unsigned long hSession, unsigned char *pEncryptedPart, unsigned long ulEncryptedPartLen, unsigned char *pPart, unsigned long *pulPartLen); unsigned long (*C_GenerateKey)(unsigned long hSession, struct CK_MECHANISM *pMechanism, struct CK_ATTRIBUTE *pTemplate, unsigned long ulCount, unsigned long *phKey); unsigned long (*C_GenerateKeyPair)(unsigned long hSession, struct CK_MECHANISM *pMechanism, struct CK_ATTRIBUTE *pPublicKeyTemplate, unsigned long ulPublicKeyAttributeCount, struct CK_ATTRIBUTE *pPrivateKeyTemplate, unsigned long ulPrivateKeyAttributeCount, unsigned long *phPublicKey, unsigned long *phPrivateKey); unsigned long (*C_WrapKey)(unsigned long hSession, struct CK_MECHANISM *pMechanism, unsigned long hWrappingKey, unsigned long hKey, unsigned char *pWrappedKey, unsigned long *pulWrappedKeyLen); unsigned long (*C_UnwrapKey)(unsigned long hSession, struct CK_MECHANISM *pMechanism, unsigned long hUnwrappingKey, unsigned char *pWrappedKey, unsigned long ulWrappedKeyLen, struct CK_ATTRIBUTE *pTemplate, unsigned long ulAttributeCount, unsigned long *phKey); unsigned long (*C_DeriveKey)(unsigned long hSession, struct CK_MECHANISM *pMechanism, unsigned long hBaseKey, struct CK_ATTRIBUTE *pTemplate, unsigned long ulAttributeCount, unsigned long *phKey); unsigned long (*C_SeedRandom)(unsigned long hSession, unsigned char *pSeed, unsigned long ulSeedLen); unsigned long (*C_GenerateRandom)(unsigned long hSession, unsigned char *pRandomData, unsigned long ulRandomLen); unsigned long (*C_GetFunctionStatus)(unsigned long hSession); unsigned long (*C_CancelFunction)(unsigned long hSession); } *

user_defined_types: struct CK_FUNCTION_LIST { struct CK_VERSION version; unsigned long (*C_Initialize)(void *pReserved); unsigned long (*C_Finalize)(void *pReserved); unsigned long (*C_GetInfo)(struct CK_INFO *pInfo); unsigned long (*C_GetFunctionList)(struct CK_FUNCTION_LIST **ppFunctionList); unsigned long (*C_GetSlotList)(unsigned char tokenPresent, unsigned long *pSlotList, unsigned long *pulCount); unsigned long (*C_GetSlotInfo)(unsigned long slotID, struct CK_SLOT_INFO *pInfo); unsigned long (*C_GetTokenInfo)(unsigned long slotID, struct CK_TOKEN_INFO *pInfo); unsigned long (*C_GetMechanismList)(unsigned long slotID, unsigned short *pMechanismList, unsigned long *pulCount); unsigned long (*C_GetMechanismInfo)(unsigned long slotID, unsigned short type, struct CK_MECHANISM_INFO *pInfo); unsigned long (*C_InitToken)(unsigned long slotID, unsigned char *pPin, unsigned long ulPinLen, unsigned char *pLabel); unsigned long (*C_InitPIN)(unsigned long hSession, unsigned char *pPin, unsigned long ulPinLen); unsigned long (*C_SetPIN)(unsigned long hSession, unsigned char *pOldPin, unsigned long ulOldLen, unsigned char *pNewPin, unsigned long ulNewLen); unsigned long (*C_OpenSession)(unsigned long slotID, unsigned long flags, void *pApplication, unsigned long *Notify, unsigned long *phSession); unsigned long (*C_CloseSession)(unsigned long hSession); unsigned long (*C_CloseAllSessions)(unsigned long slotID); unsigned long (*C_GetSessionInfo)(unsigned long hSession, struct CK_SESSION_INFO *pInfo); unsigned long (*C_GetOperationState)(unsigned long hSession, unsigned char *pOperationState, unsigned long *pulOperationStateLen); unsigned long (*C_SetOperationState)(unsigned long hSession, unsigned char *pOperationState, unsigned long ulOperationStateLen, unsigned long hEncryptionKey, unsigned long hAuthenticationKey); unsigned long (*C_Login)(unsigned long hSession, unsigned long userType, unsigned char *pPin, unsigned long ulPinLen); unsigned long (*C_Logout)(unsigned long hSession); unsigned long (*C_CreateObject)(unsigned long hSession, struct CK_ATTRIBUTE *pTemplate, unsigned long ulCount, unsigned long *pObject); unsigned long (*C_CopyObject)(unsigned long hSession, unsigned long hObject, struct CK_ATTRIBUTE *pTemplate, unsigned long ulCount, unsigned long *pNewObject); unsigned long (*C_DestroyObject)(unsigned long hSession, unsigned long hObject); unsigned long (*C_GetObjectSize)(unsigned long hSession, unsigned long hObject, unsigned long *pulSize); unsigned long (*C_GetAttributeValue)(unsigned long hSession, unsigned long hObject, struct CK_ATTRIBUTE *pTemplate, unsigned long ulCount); unsigned long (*C_SetAttributeValue)(unsigned long hSession, unsigned long hObject, struct CK_ATTRIBUTE *pTemplate, unsigned long ulCount); unsigned long (*C_FindObjectsInit)(unsigned long hSession, struct CK_ATTRIBUTE *pTemplate, unsigned long ulCount); unsigned long (*C_FindObjects)(unsigned long hSession, unsigned long *phObject, unsigned long ulMaxObjectCount, unsigned long *pulObjectCount); unsigned long (*C_FindObjectsFinal)(unsigned long hSession); unsigned long (*C_EncryptInit)(unsigned long hSession, struct CK_MECHANISM *pMechanism, unsigned long hKey); unsigned long (*C_Encrypt)(unsigned long hSession, unsigned char *pData, unsigned long ulDataLen, unsigned char *pEncryptedData, unsigned long *pulEncryptedDataLen); unsigned long (*C_EncryptUpdate)(unsigned long hSession, unsigned char *pPart, unsigned long ulPartLen, unsigned char *pEncryptedPart, unsigned long *pulEncryptedPartLen); unsigned long (*C_EncryptFinal)(unsigned long hSession, unsigned char *pLastEncryptedPart, unsigned long *pulLastEncyptedPartLen); unsigned long (*C_DecryptInit)(unsigned long hSession, struct CK_MECHANISM *pMechanism, unsigned long hKey); unsigned long (*C_Decrypt)(unsigned long hSession, unsigned char *pEncryptedData, unsigned long ulEncryptedDataLen, unsigned long *pulDataLen); unsigned long (*C_DecryptUpdate)(unsigned long hSession, unsigned char *pEncryptedPart, unsigned long ulEncryptedPartLen, unsigned char *pPart, unsigned long *pulPartLen); unsigned long (*C_DecryptFinal)(unsigned long hSession, unsigned char *pLastPart, unsigned long *pulLastPartLen); unsigned long (*C_DigestInit)(unsigned long hSession, struct CK_MECHANISM *pMechanism); unsigned long (*C_Digest)(unsigned long hSession, unsigned char *pData, unsigned long ulDataLen, unsigned char *pDigest, unsigned long *pulDigestLen); unsigned long (*C_DigestUpdate)(unsigned long hSession, unsigned char *pPart, unsigned long ulPartLen); unsigned long (*C_DigestKey)(unsigned long hSession, unsigned long hKey); unsigned long (*C_DigestFinal)(unsigned long hSession, unsigned char *pDigest, unsigned long *pulDigestLen); unsigned long (*C_SignInit)(unsigned long hSession, struct CK_MECHANISM *pMechanism, unsigned long hKey); unsigned long (*C_Sign)(unsigned long hSession, unsigned char *pData, unsigned long ulDataLen, unsigned char *pSignature, unsigned long *pulSignatureLen); unsigned long (*C_SignUpdate)(unsigned long hSession, unsigned char *pData, unsigned long ulPartLen); unsigned long (*C_SignFinal)(unsigned long hSession, unsigned char *pSignature, unsigned long *pulSignatureLen); unsigned long (*C_SignRecoverInit)(unsigned long hSession, struct CK_MECHANISM *pMechanism, unsigned long hKey); unsigned long (*C_SignRecover)(unsigned long hSession, unsigned char *pData, unsigned long ulDataLen, unsigned char *pSignature, unsigned long *pulSignature); unsigned long (*C_VerifyInit)(unsigned long hSession, struct CK_MECHANISM *pMechanism, unsigned long hKey); unsigned long (*C_Verify)(unsigned long hSession, unsigned char *pData, unsigned long ulDataLen, unsigned char *pSignature, unsigned long ulSignatureLen); unsigned long (*C_VerifyUpdate)(unsigned long hSession, unsigned char *pPart, unsigned long ulPartLen); unsigned long (*C_VerifyFinal)(unsigned long hSession, unsigned char *pSignature, unsigned long ulSignatureLen); unsigned long (*C_VerifyRecoverInit)(unsigned long hSession, struct CK_MECHANISM *pMechanism, unsigned long hKey); unsigned long (*C_VerifyRecover)(unsigned long hSession, unsigned char *pSignature, unsigned long ulSignatureLen, unsigned char *pData, unsigned long *pulDataLen); unsigned long (*C_DigestEncryptUpdate)(unsigned long hSession, unsigned char *pPart, unsigned long ulPartLen, unsigned char *pEncryptedPart, unsigned long *pulEncryptedPartLen); unsigned long (*C_DecryptDigestUpdate)(unsigned long hSession, unsigned char *pEncryptedPart, unsigned long pEncryptedPartLen, unsigned char *pPart, unsigned long *pulPartLen); unsigned long (*C_SignEncryptUpdate)(unsigned long hSession, unsigned char *pPart, unsigned long ulPartLen, unsigned char *pEncryptedPart, unsigned long *pulEncryptedPartLen); unsigned long (*C_DecryptVerifyUpdate)(unsigned long hSession, unsigned char *pEncryptedPart, unsigned long ulEncryptedPartLen, unsigned char *pPart, unsigned long *pulPartLen); unsigned long (*C_GenerateKey)(unsigned long hSession, struct CK_MECHANISM *pMechanism, struct CK_ATTRIBUTE *pTemplate, unsigned long ulCount, unsigned long *phKey); unsigned long (*C_GenerateKeyPair)(unsigned long hSession, struct CK_MECHANISM *pMechanism, struct CK_ATTRIBUTE *pPublicKeyTemplate, unsigned long ulPublicKeyAttributeCount, struct CK_ATTRIBUTE *pPrivateKeyTemplate, unsigned long ulPrivateKeyAttributeCount, unsigned long *phPublicKey, unsigned long *phPrivateKey); unsigned long (*C_WrapKey)(unsigned long hSession, struct CK_MECHANISM *pMechanism, unsigned long hWrappingKey, unsigned long hKey, unsigned char *pWrappedKey, unsigned long *pulWrappedKeyLen); unsigned long (*C_UnwrapKey)(unsigned long hSession, struct CK_MECHANISM *pMechanism, unsigned long hUnwrappingKey, unsigned char *pWrappedKey, unsigned long ulWrappedKeyLen, struct CK_ATTRIBUTE *pTemplate, unsigned long ulAttributeCount, unsigned long *phKey); unsigned long (*C_DeriveKey)(unsigned long hSession, struct CK_MECHANISM *pMechanism, unsigned long hBaseKey, struct CK_ATTRIBUTE *pTemplate, unsigned long ulAttributeCount, unsigned long *phKey); unsigned long (*C_SeedRandom)(unsigned long hSession, unsigned char *pSeed, unsigned long ulSeedLen); unsigned long (*C_GenerateRandom)(unsigned long hSession, unsigned char *pRandomData, unsigned long ulRandomLen); unsigned long (*C_GetFunctionStatus)(unsigned long hSession); unsigned long (*C_CancelFunction)(unsigned long hSession); }


repo: secure-endpoints/kcacred

decompiled_code:
_BYTE *CKI_FunctionList_New()
{
_BYTE *result; // rax

log_printf("CKI_FunctionList_New: entered\n");
result = malloc(0x220uLL);
if ( result )
{
*result = 0;
result[1] = 0;
*((_QWORD *)result + 1) = 0LL;
*((_QWORD *)result + 2) = 0LL;
*((_QWORD *)result + 3) = 0LL;
*((_QWORD *)result + 4) = 0LL;
*((_QWORD *)result + 5) = 0LL;
*((_QWORD *)result + 6) = 0LL;
*((_QWORD *)result + 7) = 0LL;
*((_QWORD *)result + 8) = 0LL;
*((_QWORD *)result + 9) = 0LL;
*((_QWORD *)result + 10) = 0LL;
*((_QWORD *)result + 11) = 0LL;
*((_QWORD *)result + 12) = 0LL;
*((_QWORD *)result + 13) = 0LL;
*((_QWORD *)result + 14) = 0LL;
*((_QWORD *)result + 15) = 0LL;
*((_QWORD *)result + 16) = 0LL;
*((_QWORD *)result + 17) = 0LL;
*((_QWORD *)result + 18) = 0LL;
*((_QWORD *)result + 19) = 0LL;
*((_QWORD *)result + 20) = 0LL;
*((_QWORD *)result + 21) = 0LL;
*((_QWORD *)result + 22) = 0LL;
*((_QWORD *)result + 23) = 0LL;
*((_QWORD *)result + 24) = 0LL;
*((_QWORD *)result + 25) = 0LL;
*((_QWORD *)result + 26) = 0LL;
*((_QWORD *)result + 27) = 0LL;
*((_QWORD *)result + 28) = 0LL;
*((_QWORD *)result + 29) = 0LL;
*((_QWORD *)result + 30) = 0LL;
*((_QWORD *)result + 31) = 0LL;
*((_QWORD *)result + 32) = 0LL;
*((_QWORD *)result + 33) = 0LL;
*((_QWORD *)result + 34) = 0LL;
*((_QWORD *)result + 35) = 0LL;
*((_QWORD *)result + 36) = 0LL;
*((_QWORD *)result + 37) = 0LL;
*((_QWORD *)result + 38) = 0LL;
*((_QWORD *)result + 39) = 0LL;
*((_QWORD *)result + 40) = 0LL;
*((_QWORD *)result + 41) = 0LL;
*((_QWORD *)result + 42) = 0LL;
*((_QWORD *)result + 43) = 0LL;
*((_QWORD *)result + 44) = 0LL;
*((_QWORD *)result + 45) = 0LL;
*((_QWORD *)result + 46) = 0LL;
*((_QWORD *)result + 47) = 0LL;
*((_QWORD *)result + 48) = 0LL;
*((_QWORD *)result + 49) = 0LL;
*((_QWORD *)result + 50) = 0LL;
*((_QWORD *)result + 51) = 0LL;
*((_QWORD *)result + 52) = 0LL;
*((_QWORD *)result + 53) = 0LL;
*((_QWORD *)result + 54) = 0LL;
*((_QWORD *)result + 55) = 0LL;
*((_QWORD *)result + 56) = 0LL;
*((_QWORD *)result + 57) = 0LL;
*((_QWORD *)result + 58) = 0LL;
*((_QWORD *)result + 59) = 0LL;
*((_QWORD *)result + 60) = 0LL;
*((_QWORD *)result + 61) = 0LL;
*((_QWORD *)result + 62) = 0LL;
*((_QWORD *)result + 63) = 0LL;
*((_QWORD *)result + 64) = 0LL;
*((_QWORD *)result + 65) = 0LL;
*((_QWORD *)result + 66) = 0LL;
*((_QWORD *)result + 67) = 0LL;
}
return result;
}

canonical_decompiled_code:
_BYTE *func16()
{
_BYTE *result; // rax

log_printf("CKI_FunctionList_New: entered\n");
result = malloc(0x220uLL);
if ( result )
{
*result = 0;
result[1] = 0;
*((_QWORD *)result + 1) = 0LL;
*((_QWORD *)result + 2) = 0LL;
*((_QWORD *)result + 3) = 0LL;
*((_QWORD *)result + 4) = 0LL;
*((_QWORD *)result + 5) = 0LL;
*((_QWORD *)result + 6) = 0LL;
*((_QWORD *)result + 7) = 0LL;
*((_QWORD *)result + 8) = 0LL;
*((_QWORD *)result + 9) = 0LL;
*((_QWORD *)result + 10) = 0LL;
*((_QWORD *)result + 11) = 0LL;
*((_QWORD *)result + 12) = 0LL;
*((_QWORD *)result + 13) = 0LL;
*((_QWORD *)result + 14) = 0LL;
*((_QWORD *)result + 15) = 0LL;
*((_QWORD *)result + 16) = 0LL;
*((_QWORD *)result + 17) = 0LL;
*((_QWORD *)result + 18) = 0LL;
*((_QWORD *)result + 19) = 0LL;
*((_QWORD *)result + 20) = 0LL;
*((_QWORD *)result + 21) = 0LL;
*((_QWORD *)result + 22) = 0LL;
*((_QWORD *)result + 23) = 0LL;
*((_QWORD *)result + 24) = 0LL;
*((_QWORD *)result + 25) = 0LL;
*((_QWORD *)result + 26) = 0LL;
*((_QWORD *)result + 27) = 0LL;
*((_QWORD *)result + 28) = 0LL;
*((_QWORD *)result + 29) = 0LL;
*((_QWORD *)result + 30) = 0LL;
*((_QWORD *)result + 31) = 0LL;
*((_QWORD *)result + 32) = 0LL;
*((_QWORD *)result + 33) = 0LL;
*((_QWORD *)result + 34) = 0LL;
*((_QWORD *)result + 35) = 0LL;
*((_QWORD *)result + 36) = 0LL;
*((_QWORD *)result + 37) = 0LL;
*((_QWORD *)result + 38) = 0LL;
*((_QWORD *)result + 39) = 0LL;
*((_QWORD *)result + 40) = 0LL;
*((_QWORD *)result + 41) = 0LL;
*((_QWORD *)result + 42) = 0LL;
*((_QWORD *)result + 43) = 0LL;
*((_QWORD *)result + 44) = 0LL;
*((_QWORD *)result + 45) = 0LL;
*((_QWORD *)result + 46) = 0LL;
*((_QWORD *)result + 47) = 0LL;
*((_QWORD *)result + 48) = 0LL;
*((_QWORD *)result + 49) = 0LL;
*((_QWORD *)result + 50) = 0LL;
*((_QWORD *)result + 51) = 0LL;
*((_QWORD *)result + 52) = 0LL;
*((_QWORD *)result + 53) = 0LL;
*((_QWORD *)result + 54) = 0LL;
*((_QWORD *)result + 55) = 0LL;
*((_QWORD *)result + 56) = 0LL;
*((_QWORD *)result + 57) = 0LL;
*((_QWORD *)result + 58) = 0LL;
*((_QWORD *)result + 59) = 0LL;
*((_QWORD *)result + 60) = 0LL;
*((_QWORD *)result + 61) = 0LL;
*((_QWORD *)result + 62) = 0LL;
*((_QWORD *)result + 63) = 0LL;
*((_QWORD *)result + 64) = 0LL;
*((_QWORD *)result + 65) = 0LL;
*((_QWORD *)result + 66) = 0LL;
*((_QWORD *)result + 67) = 0LL;
}
return result;
}

original_code:
CK_FUNCTION_LIST_PTR CKI_FunctionList_New() {
    CK_FUNCTION_LIST_PTR pFunctionList;
    log_printf("CKI_FunctionList_New: entered\n");
    pFunctionList=(CK_FUNCTION_LIST_PTR)malloc(sizeof(CK_FUNCTION_LIST));
    if (pFunctionList==((void *)0)) {
 return(((void *)0));
    }
    pFunctionList->version.major=0;
    pFunctionList->version.minor=0;
    pFunctionList->C_Initialize=((void *)0);
    pFunctionList->C_Finalize=((void *)0);
    pFunctionList->C_GetInfo=((void *)0);
    pFunctionList->C_GetFunctionList=((void *)0);
    pFunctionList->C_GetSlotList=((void *)0);
    pFunctionList->C_GetSlotInfo=((void *)0);
    pFunctionList->C_GetTokenInfo=((void *)0);
    pFunctionList->C_GetMechanismList=((void *)0);
    pFunctionList->C_GetMechanismInfo=((void *)0);
    pFunctionList->C_InitToken=((void *)0);
    pFunctionList->C_InitPIN=((void *)0);
    pFunctionList->C_SetPIN=((void *)0);
    pFunctionList->C_OpenSession=((void *)0);
    pFunctionList->C_CloseSession=((void *)0);
    pFunctionList->C_CloseAllSessions=((void *)0);
    pFunctionList->C_GetSessionInfo=((void *)0);
    pFunctionList->C_GetOperationState=((void *)0);
    pFunctionList->C_SetOperationState=((void *)0);
    pFunctionList->C_Login=((void *)0);
    pFunctionList->C_Logout=((void *)0);
    pFunctionList->C_CreateObject=((void *)0);
    pFunctionList->C_CopyObject=((void *)0);
    pFunctionList->C_DestroyObject=((void *)0);
    pFunctionList->C_GetObjectSize=((void *)0);
    pFunctionList->C_GetAttributeValue=((void *)0);
    pFunctionList->C_SetAttributeValue=((void *)0);
    pFunctionList->C_FindObjectsInit=((void *)0);
    pFunctionList->C_FindObjects=((void *)0);
    pFunctionList->C_FindObjectsFinal=((void *)0);
    pFunctionList->C_EncryptInit=((void *)0);
    pFunctionList->C_Encrypt=((void *)0);
    pFunctionList->C_EncryptUpdate=((void *)0);
    pFunctionList->C_EncryptFinal=((void *)0);
    pFunctionList->C_DecryptInit=((void *)0);
    pFunctionList->C_Decrypt=((void *)0);
    pFunctionList->C_DecryptUpdate=((void *)0);
    pFunctionList->C_DecryptFinal=((void *)0);
    pFunctionList->C_DigestInit=((void *)0);
    pFunctionList->C_Digest=((void *)0);
    pFunctionList->C_DigestUpdate=((void *)0);
    pFunctionList->C_DigestKey=((void *)0);
    pFunctionList->C_DigestFinal=((void *)0);
    pFunctionList->C_SignInit=((void *)0);
    pFunctionList->C_Sign=((void *)0);
    pFunctionList->C_SignUpdate=((void *)0);
    pFunctionList->C_SignFinal=((void *)0);
    pFunctionList->C_SignRecoverInit=((void *)0);
    pFunctionList->C_SignRecover=((void *)0);
    pFunctionList->C_VerifyInit=((void *)0);
    pFunctionList->C_Verify=((void *)0);
    pFunctionList->C_VerifyUpdate=((void *)0);
    pFunctionList->C_VerifyFinal=((void *)0);
    pFunctionList->C_VerifyRecoverInit=((void *)0);
    pFunctionList->C_VerifyRecover=((void *)0);
    pFunctionList->C_DigestEncryptUpdate=((void *)0);
    pFunctionList->C_DecryptDigestUpdate=((void *)0);
    pFunctionList->C_SignEncryptUpdate=((void *)0);
    pFunctionList->C_DecryptVerifyUpdate=((void *)0);
    pFunctionList->C_GenerateKey=((void *)0);
    pFunctionList->C_GenerateKeyPair=((void *)0);
    pFunctionList->C_WrapKey=((void *)0);
    pFunctionList->C_UnwrapKey=((void *)0);
    pFunctionList->C_DeriveKey=((void *)0);
    pFunctionList->C_SeedRandom=((void *)0);
    pFunctionList->C_GenerateRandom=((void *)0);
    pFunctionList->C_GetFunctionStatus=((void *)0);
    pFunctionList->C_CancelFunction=((void *)0);
    return(pFunctionList);
}

canonical_original_code:
struct CK_FUNCTION_LIST *CKI_FunctionList_New() {
    struct CK_FUNCTION_LIST *pFunctionList;
    log_printf("CKI_FunctionList_New: entered\n");
    pFunctionList=(struct CK_FUNCTION_LIST *)malloc(sizeof(CK_FUNCTION_LIST));
    if (pFunctionList==((void *)0)) {
 return(((void *)0));
    }
    pFunctionList->version.major=0;
    pFunctionList->version.minor=0;
    pFunctionList->C_Initialize=((void *)0);
    pFunctionList->C_Finalize=((void *)0);
    pFunctionList->C_GetInfo=((void *)0);
    pFunctionList->C_GetFunctionList=((void *)0);
    pFunctionList->C_GetSlotList=((void *)0);
    pFunctionList->C_GetSlotInfo=((void *)0);
    pFunctionList->C_GetTokenInfo=((void *)0);
    pFunctionList->C_GetMechanismList=((void *)0);
    pFunctionList->C_GetMechanismInfo=((void *)0);
    pFunctionList->C_InitToken=((void *)0);
    pFunctionList->C_InitPIN=((void *)0);
    pFunctionList->C_SetPIN=((void *)0);
    pFunctionList->C_OpenSession=((void *)0);
    pFunctionList->C_CloseSession=((void *)0);
    pFunctionList->C_CloseAllSessions=((void *)0);
    pFunctionList->C_GetSessionInfo=((void *)0);
    pFunctionList->C_GetOperationState=((void *)0);
    pFunctionList->C_SetOperationState=((void *)0);
    pFunctionList->C_Login=((void *)0);
    pFunctionList->C_Logout=((void *)0);
    pFunctionList->C_CreateObject=((void *)0);
    pFunctionList->C_CopyObject=((void *)0);
    pFunctionList->C_DestroyObject=((void *)0);
    pFunctionList->C_GetObjectSize=((void *)0);
    pFunctionList->C_GetAttributeValue=((void *)0);
    pFunctionList->C_SetAttributeValue=((void *)0);
    pFunctionList->C_FindObjectsInit=((void *)0);
    pFunctionList->C_FindObjects=((void *)0);
    pFunctionList->C_FindObjectsFinal=((void *)0);
    pFunctionList->C_EncryptInit=((void *)0);
    pFunctionList->C_Encrypt=((void *)0);
    pFunctionList->C_EncryptUpdate=((void *)0);
    pFunctionList->C_EncryptFinal=((void *)0);
    pFunctionList->C_DecryptInit=((void *)0);
    pFunctionList->C_Decrypt=((void *)0);
    pFunctionList->C_DecryptUpdate=((void *)0);
    pFunctionList->C_DecryptFinal=((void *)0);
    pFunctionList->C_DigestInit=((void *)0);
    pFunctionList->C_Digest=((void *)0);
    pFunctionList->C_DigestUpdate=((void *)0);
    pFunctionList->C_DigestKey=((void *)0);
    pFunctionList->C_DigestFinal=((void *)0);
    pFunctionList->C_SignInit=((void *)0);
    pFunctionList->C_Sign=((void *)0);
    pFunctionList->C_SignUpdate=((void *)0);
    pFunctionList->C_SignFinal=((void *)0);
    pFunctionList->C_SignRecoverInit=((void *)0);
    pFunctionList->C_SignRecover=((void *)0);
    pFunctionList->C_VerifyInit=((void *)0);
    pFunctionList->C_Verify=((void *)0);
    pFunctionList->C_VerifyUpdate=((void *)0);
    pFunctionList->C_VerifyFinal=((void *)0);
    pFunctionList->C_VerifyRecoverInit=((void *)0);
    pFunctionList->C_VerifyRecover=((void *)0);
    pFunctionList->C_DigestEncryptUpdate=((void *)0);
    pFunctionList->C_DecryptDigestUpdate=((void *)0);
    pFunctionList->C_SignEncryptUpdate=((void *)0);
    pFunctionList->C_DecryptVerifyUpdate=((void *)0);
    pFunctionList->C_GenerateKey=((void *)0);
    pFunctionList->C_GenerateKeyPair=((void *)0);
    pFunctionList->C_WrapKey=((void *)0);
    pFunctionList->C_UnwrapKey=((void *)0);
    pFunctionList->C_DeriveKey=((void *)0);
    pFunctionList->C_SeedRandom=((void *)0);
    pFunctionList->C_GenerateRandom=((void *)0);
    pFunctionList->C_GetFunctionStatus=((void *)0);
    pFunctionList->C_CancelFunction=((void *)0);
    return(pFunctionList);
}

return_type: struct CK_FUNCTION_LIST { struct CK_VERSION { unsigned char major; unsigned char minor; } version; unsigned long (*C_Initialize)(void *pReserved); unsigned long (*C_Finalize)(void *pReserved); unsigned long (*C_GetInfo)(struct CK_INFO { struct CK_VERSION cryptokiVersion; unsigned char manufacturerID[32]; unsigned long flags; unsigned char libraryDescription[32]; struct CK_VERSION libraryVersion; } *pInfo); unsigned long (*C_GetFunctionList)(struct CK_FUNCTION_LIST **ppFunctionList); unsigned long (*C_GetSlotList)(unsigned char tokenPresent, unsigned long *pSlotList, unsigned long *pulCount); unsigned long (*C_GetSlotInfo)(unsigned long slotID, struct CK_SLOT_INFO { unsigned char slotDescription[64]; unsigned char manufacturerID[32]; unsigned long flags; struct CK_VERSION hardwareVersion; struct CK_VERSION firmwareVersion; } *pInfo); unsigned long (*C_GetTokenInfo)(unsigned long slotID, struct CK_TOKEN_INFO { unsigned char label[32]; unsigned char manufacturerID[32]; unsigned char model[16]; unsigned char serialNumber[16]; unsigned long flags; unsigned long ulMaxSessionCount; unsigned long ulSessionCount; unsigned long ulMaxRwSessionCount; unsigned long ulRwSessionCount; unsigned long ulMaxPinLen; unsigned long ulMinPinLen; unsigned long ulTotalPublicMemory; unsigned long ulFreePublicMemory; unsigned long ulTotalPrivateMemory; unsigned long ulFreePrivateMemory; struct CK_VERSION hardwareVersion; struct CK_VERSION firmwareVersion; unsigned char utcTime[16]; } *pInfo); unsigned long (*C_GetMechanismList)(unsigned long slotID, unsigned short *pMechanismList, unsigned long *pulCount); unsigned long (*C_GetMechanismInfo)(unsigned long slotID, unsigned short type, struct CK_MECHANISM_INFO { unsigned long ulMinKeySize; unsigned long ulMaxKeySize; unsigned long flags; } *pInfo); unsigned long (*C_InitToken)(unsigned long slotID, unsigned char *pPin, unsigned long ulPinLen, unsigned char *pLabel); unsigned long (*C_InitPIN)(unsigned long hSession, unsigned char *pPin, unsigned long ulPinLen); unsigned long (*C_SetPIN)(unsigned long hSession, unsigned char *pOldPin, unsigned long ulOldLen, unsigned char *pNewPin, unsigned long ulNewLen); unsigned long (*C_OpenSession)(unsigned long slotID, unsigned long flags, void *pApplication, unsigned long *Notify, unsigned long *phSession); unsigned long (*C_CloseSession)(unsigned long hSession); unsigned long (*C_CloseAllSessions)(unsigned long slotID); unsigned long (*C_GetSessionInfo)(unsigned long hSession, struct CK_SESSION_INFO { unsigned long slotID; unsigned long state; unsigned long flags; unsigned long ulDeviceError; } *pInfo); unsigned long (*C_GetOperationState)(unsigned long hSession, unsigned char *pOperationState, unsigned long *pulOperationStateLen); unsigned long (*C_SetOperationState)(unsigned long hSession, unsigned char *pOperationState, unsigned long ulOperationStateLen, unsigned long hEncryptionKey, unsigned long hAuthenticationKey); unsigned long (*C_Login)(unsigned long hSession, unsigned long userType, unsigned char *pPin, unsigned long ulPinLen); unsigned long (*C_Logout)(unsigned long hSession); unsigned long (*C_CreateObject)(unsigned long hSession, struct CK_ATTRIBUTE { unsigned long type; void *value; unsigned long ulValueLen; } *pTemplate, unsigned long ulCount, unsigned long *pObject); unsigned long (*C_CopyObject)(unsigned long hSession, unsigned long hObject, struct CK_ATTRIBUTE *pTemplate, unsigned long ulCount, unsigned long *pNewObject); unsigned long (*C_DestroyObject)(unsigned long hSession, unsigned long hObject); unsigned long (*C_GetObjectSize)(unsigned long hSession, unsigned long hObject, unsigned long *pulSize); unsigned long (*C_GetAttributeValue)(unsigned long hSession, unsigned long hObject, struct CK_ATTRIBUTE *pTemplate, unsigned long ulCount); unsigned long (*C_SetAttributeValue)(unsigned long hSession, unsigned long hObject, struct CK_ATTRIBUTE *pTemplate, unsigned long ulCount); unsigned long (*C_FindObjectsInit)(unsigned long hSession, struct CK_ATTRIBUTE *pTemplate, unsigned long ulCount); unsigned long (*C_FindObjects)(unsigned long hSession, unsigned long *phObject, unsigned long ulMaxObjectCount, unsigned long *pulObjectCount); unsigned long (*C_FindObjectsFinal)(unsigned long hSession); unsigned long (*C_EncryptInit)(unsigned long hSession, struct CK_MECHANISM { unsigned short mechanism; void *pParameter; unsigned long ulParameterLen; } *pMechanism, unsigned long hKey); unsigned long (*C_Encrypt)(unsigned long hSession, unsigned char *pData, unsigned long ulDataLen, unsigned char *pEncryptedData, unsigned long *pulEncryptedDataLen); unsigned long (*C_EncryptUpdate)(unsigned long hSession, unsigned char *pPart, unsigned long ulPartLen, unsigned char *pEncryptedPart, unsigned long *pulEncryptedPartLen); unsigned long (*C_EncryptFinal)(unsigned long hSession, unsigned char *pLastEncryptedPart, unsigned long *pulLastEncyptedPartLen); unsigned long (*C_DecryptInit)(unsigned long hSession, struct CK_MECHANISM *pMechanism, unsigned long hKey); unsigned long (*C_Decrypt)(unsigned long hSession, unsigned char *pEncryptedData, unsigned long ulEncryptedDataLen, unsigned long *pulDataLen); unsigned long (*C_DecryptUpdate)(unsigned long hSession, unsigned char *pEncryptedPart, unsigned long ulEncryptedPartLen, unsigned char *pPart, unsigned long *pulPartLen); unsigned long (*C_DecryptFinal)(unsigned long hSession, unsigned char *pLastPart, unsigned long *pulLastPartLen); unsigned long (*C_DigestInit)(unsigned long hSession, struct CK_MECHANISM *pMechanism); unsigned long (*C_Digest)(unsigned long hSession, unsigned char *pData, unsigned long ulDataLen, unsigned char *pDigest, unsigned long *pulDigestLen); unsigned long (*C_DigestUpdate)(unsigned long hSession, unsigned char *pPart, unsigned long ulPartLen); unsigned long (*C_DigestKey)(unsigned long hSession, unsigned long hKey); unsigned long (*C_DigestFinal)(unsigned long hSession, unsigned char *pDigest, unsigned long *pulDigestLen); unsigned long (*C_SignInit)(unsigned long hSession, struct CK_MECHANISM *pMechanism, unsigned long hKey); unsigned long (*C_Sign)(unsigned long hSession, unsigned char *pData, unsigned long ulDataLen, unsigned char *pSignature, unsigned long *pulSignatureLen); unsigned long (*C_SignUpdate)(unsigned long hSession, unsigned char *pData, unsigned long ulPartLen); unsigned long (*C_SignFinal)(unsigned long hSession, unsigned char *pSignature, unsigned long *pulSignatureLen); unsigned long (*C_SignRecoverInit)(unsigned long hSession, struct CK_MECHANISM *pMechanism, unsigned long hKey); unsigned long (*C_SignRecover)(unsigned long hSession, unsigned char *pData, unsigned long ulDataLen, unsigned char *pSignature, unsigned long *pulSignature); unsigned long (*C_VerifyInit)(unsigned long hSession, struct CK_MECHANISM *pMechanism, unsigned long hKey); unsigned long (*C_Verify)(unsigned long hSession, unsigned char *pData, unsigned long ulDataLen, unsigned char *pSignature, unsigned long ulSignatureLen); unsigned long (*C_VerifyUpdate)(unsigned long hSession, unsigned char *pPart, unsigned long ulPartLen); unsigned long (*C_VerifyFinal)(unsigned long hSession, unsigned char *pSignature, unsigned long ulSignatureLen); unsigned long (*C_VerifyRecoverInit)(unsigned long hSession, struct CK_MECHANISM *pMechanism, unsigned long hKey); unsigned long (*C_VerifyRecover)(unsigned long hSession, unsigned char *pSignature, unsigned long ulSignatureLen, unsigned char *pData, unsigned long *pulDataLen); unsigned long (*C_DigestEncryptUpdate)(unsigned long hSession, unsigned char *pPart, unsigned long ulPartLen, unsigned char *pEncryptedPart, unsigned long *pulEncryptedPartLen); unsigned long (*C_DecryptDigestUpdate)(unsigned long hSession, unsigned char *pEncryptedPart, unsigned long pEncryptedPartLen, unsigned char *pPart, unsigned long *pulPartLen); unsigned long (*C_SignEncryptUpdate)(unsigned long hSession, unsigned char *pPart, unsigned long ulPartLen, unsigned char *pEncryptedPart, unsigned long *pulEncryptedPartLen); unsigned long (*C_DecryptVerifyUpdate)(unsigned long hSession, unsigned char *pEncryptedPart, unsigned long ulEncryptedPartLen, unsigned char *pPart, unsigned long *pulPartLen); unsigned long (*C_GenerateKey)(unsigned long hSession, struct CK_MECHANISM *pMechanism, struct CK_ATTRIBUTE *pTemplate, unsigned long ulCount, unsigned long *phKey); unsigned long (*C_GenerateKeyPair)(unsigned long hSession, struct CK_MECHANISM *pMechanism, struct CK_ATTRIBUTE *pPublicKeyTemplate, unsigned long ulPublicKeyAttributeCount, struct CK_ATTRIBUTE *pPrivateKeyTemplate, unsigned long ulPrivateKeyAttributeCount, unsigned long *phPublicKey, unsigned long *phPrivateKey); unsigned long (*C_WrapKey)(unsigned long hSession, struct CK_MECHANISM *pMechanism, unsigned long hWrappingKey, unsigned long hKey, unsigned char *pWrappedKey, unsigned long *pulWrappedKeyLen); unsigned long (*C_UnwrapKey)(unsigned long hSession, struct CK_MECHANISM *pMechanism, unsigned long hUnwrappingKey, unsigned char *pWrappedKey, unsigned long ulWrappedKeyLen, struct CK_ATTRIBUTE *pTemplate, unsigned long ulAttributeCount, unsigned long *phKey); unsigned long (*C_DeriveKey)(unsigned long hSession, struct CK_MECHANISM *pMechanism, unsigned long hBaseKey, struct CK_ATTRIBUTE *pTemplate, unsigned long ulAttributeCount, unsigned long *phKey); unsigned long (*C_SeedRandom)(unsigned long hSession, unsigned char *pSeed, unsigned long ulSeedLen); unsigned long (*C_GenerateRandom)(unsigned long hSession, unsigned char *pRandomData, unsigned long ulRandomLen); unsigned long (*C_GetFunctionStatus)(unsigned long hSession); unsigned long (*C_CancelFunction)(unsigned long hSession); } *


decompiled_code:
void __fastcall CKI_AttributePtr_Free(void *ptr)
{
void *v2; // rdi
void **v3; // rbx

if ( ptr )
{
v2 = (void *)*((_QWORD *)ptr + 1);
if ( v2 )
{
v3 = (void **)((char *)ptr + 8);
do
{
free(v2);
*v3 = 0LL;
v3 += 3;
v2 = *v3;
}
while ( *v3 );
}
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func17(void *ptr)
{
void *v2; // rdi
void **v3; // rbx

if ( ptr )
{
v2 = (void *)*((_QWORD *)ptr + 1);
if ( v2 )
{
v3 = (void **)((char *)ptr + 8);
do
{
free(v2);
*v3 = 0LL;
v3 += 3;
v2 = *v3;
}
while ( *v3 );
}
free(ptr);
}
}

original_code:
void CKI_AttributePtr_Free(CK_ATTRIBUTE_PTR pAttribute) {
    int i;
    if (!pAttribute)
 return;
    for (i=0; pAttribute[i].value; i++) {
 free(pAttribute[i].value);
 pAttribute[i].value = ((void *)0);
    }
    free(pAttribute);
    return;
}

canonical_original_code:
void CKI_AttributePtr_Free(struct CK_ATTRIBUTE *pAttribute) {
    int i;
    if (!pAttribute)
 return;
    for (i=0; pAttribute[i].value; i++) {
 free(pAttribute[i].value);
 pAttribute[i].value = ((void *)0);
    }
    free(pAttribute);
    return;
}

variable_types: struct CK_ATTRIBUTE { unsigned long type; void *value; unsigned long ulValueLen; } *

variable_types: i int

return_type: void


decompiled_code:
__int64 __fastcall connect_x509(const char *a1, unsigned __int16 a2)
{
struct hostent *v2; // rax
struct hostent *v3; // rbp
int v4; // ebx
int *v6; // rax
char *v7; // rax
int *v8; // rax
char *v9; // rax
int *v10; // rax
char *v11; // rax
int optval[2]; // [rsp+8h] [rbp-30h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-28h] BYREF

optval[0] = 1;
optval[1] = 1;
v2 = gethostbyname(a1);
if ( v2 )
{
v3 = v2;
log_printf("%s: Host official name: %s\n", "connect_x509", v2->h_name);
v4 = socket(2, 1, 0);
if ( v4 < 0 )
{
v6 = _errno_location();
v7 = strerror(*v6);
log_printf("%s: Failed creating socket\n%s\n", "connect_x509", v7);
v4 = 0;
}
else
{
log_printf("%s: Issuing connect to port %d\n", "connect_x509", a2);
addr.sa_family = 2;
*(_WORD *)addr.sa_data = _bswap_16(a2);
*(_DWORD *)&addr.sa_data[2] = **(_DWORD **)v3->h_addr_list;
if ( connect(v4, &addr, 0x10u) == -1 )
{
v8 = _errno_location();
v9 = strerror(*v8);
log_printf("%s: Failed connecting socket\n%s\n", "connect_x509", v9);
v4 = 0;
}
else if ( setsockopt(v4, 1, 13, optval, 8u) == -1 )
{
v10 = _errno_location();
v11 = strerror(*v10);
log_printf("%s: Unable to set linger option on socket\n%s\n", "connect_x509", v11);
}
}
}
else
{
log_printf("%s: unknown host\n", "connect_x509");
v4 = 0;
}
return (unsigned int)v4;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1, unsigned __int16 a2)
{
struct hostent *v2; // rax
struct hostent *v3; // rbp
int v4; // ebx
int *v6; // rax
char *v7; // rax
int *v8; // rax
char *v9; // rax
int *v10; // rax
char *v11; // rax
int optval[2]; // [rsp+8h] [rbp-30h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-28h] BYREF

optval[0] = 1;
optval[1] = 1;
v2 = gethostbyname(a1);
if ( v2 )
{
v3 = v2;
log_printf("%s: Host official name: %s\n", "connect_x509", v2->h_name);
v4 = socket(2, 1, 0);
if ( v4 < 0 )
{
v6 = _errno_location();
v7 = strerror(*v6);
log_printf("%s: Failed creating socket\n%s\n", "connect_x509", v7);
v4 = 0;
}
else
{
log_printf("%s: Issuing connect to port %d\n", "connect_x509", a2);
addr.sa_family = 2;
*(_WORD *)addr.sa_data = func0(a2);
*(_DWORD *)&addr.sa_data[2] = **(_DWORD **)v3->h_addr_list;
if ( connect(v4, &addr, 0x10u) == -1 )
{
v8 = _errno_location();
v9 = strerror(*v8);
log_printf("%s: Failed connecting socket\n%s\n", "connect_x509", v9);
v4 = 0;
}
else if ( setsockopt(v4, 1, 13, optval, 8u) == -1 )
{
v10 = _errno_location();
v11 = strerror(*v10);
log_printf("%s: Unable to set linger option on socket\n%s\n", "connect_x509", v11);
}
}
}
else
{
log_printf("%s: unknown host\n", "connect_x509");
v4 = 0;
}
return (unsigned int)v4;
}

original_code:
SOCKET
connect_x509(char *hostname, u_short port_no)
{
    char *rn = "connect_x509";
    struct sockaddr_in peeraddr;
    struct hostent *phostent;
    int optrc;
    SOCKET s;
    struct linger linger = {1, 1};
    phostent = gethostbyname (hostname);
    if( phostent == ((void *)0))
    {
 log_printf("%s: unknown host\n", rn);
 return 0;
    }
    log_printf("%s: Host official name: %s\n", rn, phostent->h_name);
    if ((s = socket(2, SOCK_STREAM, 0)) < 0)
    {
 log_printf("%s: Failed creating socket\n%s\n",
      rn, strerror((*__errno_location ())));
 return 0;
    }
    log_printf("%s: Issuing connect to port %d\n", rn, port_no);
    peeraddr.sin_family = 2;
    peeraddr.sin_port = htons(port_no);
    peeraddr.sin_addr.s_addr = ((struct in_addr *)(phostent->h_addr_list[0]))->s_addr;
    if (connect(s, (struct sockaddr *) &peeraddr, sizeof(struct sockaddr_in)) == -1)
    {
 log_printf("%s: Failed connecting socket\n%s\n",
      rn, strerror((*__errno_location ())));
 return 0;
    }
    optrc = setsockopt (s, 1, 13,
    (char *) &linger, sizeof (struct linger));
    if (optrc == -1)
 log_printf("%s: Unable to set linger option on socket\n%s\n",
      rn, strerror((*__errno_location ())));
    return s;
}

canonical_original_code:
int connect_x509(char *hostname, unsigned short port_no)
{
    char *rn = "connect_x509";
    struct sockaddr_in peeraddr;
    struct hostent *phostent;
    int optrc;
    int s;
    struct linger linger = {1, 1};
    phostent = gethostbyname (hostname);
    if( phostent == ((void *)0))
    {
 log_printf("%s: unknown host\n", rn);
 return 0;
    }
    log_printf("%s: Host official name: %s\n", rn, phostent->h_name);
    if ((s = socket(2, SOCK_STREAM, 0)) < 0)
    {
 log_printf("%s: Failed creating socket\n%s\n",
      rn, strerror((*__errno_location ())));
 return 0;
    }
    log_printf("%s: Issuing connect to port %d\n", rn, port_no);
    peeraddr.sin_family = 2;
    peeraddr.sin_port = htons(port_no);
    peeraddr.sin_addr.s_addr = ((struct in_addr *)(phostent->h_addr_list[0]))->s_addr;
    if (connect(s, (struct sockaddr *) &peeraddr, sizeof(struct sockaddr_in)) == -1)
    {
 log_printf("%s: Failed connecting socket\n%s\n",
      rn, strerror((*__errno_location ())));
 return 0;
    }
    optrc = setsockopt (s, 1, 13,
    (char *) &linger, sizeof (struct linger));
    if (optrc == -1)
 log_printf("%s: Unable to set linger option on socket\n%s\n",
      rn, strerror((*__errno_location ())));
    return s;
}

variable_types:
hostname
char *

variable_types:
rn
char *

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; }

variable_types: struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; } *

variable_types: optrc int

variable_types: s int

variable_types: struct linger { int l_onoff; int l_linger; }

return_type: int

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }

user_defined_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }


original_code:
time_t utc2unix(ASN1_UTCTIME *utctime, time_t *unixtime)
{
    char *utcchars;
    int length, temp;
    time_t utime;
    char *current;
    struct tm tms;
    memset(&tms, '\0', sizeof(tms));
    utime = -1;
    length = utctime->length;
    if (length != 13)
 goto returntime;
    utcchars = (char*) utctime->data;
    if (utcchars[12] != 'Z')
 goto returntime;
    current = utcchars;
    temp = (current[0]-'0')*10 + (current[1]-'0');
    if (temp < 50)
 temp += 100;
    tms.tm_year = temp;
    current+=2;
    temp = (current[0]-'0')*10 + (current[1]-'0');
    temp--;
    tms.tm_mon = temp;
    current+=2;
    temp = (current[0]-'0')*10 + (current[1]-'0');
    tms.tm_mday = temp;
    current+=2;
    temp = (current[0]-'0')*10 + (current[1]-'0');
    tms.tm_hour = temp;
    current+=2;
    temp = (current[0]-'0')*10 + (current[1]-'0');
    tms.tm_min = temp;
    current+=2;
    temp = (current[0]-'0')*10 + (current[1]-'0');
    tms.tm_sec = temp;
    tms.tm_isdst = -1;
    tzset();
    utime = mktime(&tms);
    if (utime != -1) {
 utime = utime - timezone + daylight*3600;
    }
  returntime:
    if (unixtime)
 *unixtime = utime;
    return utime;
}

canonical_original_code:
long utc2unix(struct asn1_string_st *utctime, long *unixtime)
{
    char *utcchars;
    int length; int temp;
    long utime;
    char *current;
    struct tm tms;
    memset(&tms, '\0', sizeof(tms));
    utime = -1;
    length = utctime->length;
    if (length != 13)
 goto returntime;
    utcchars = (char *) utctime->data;
    if (utcchars[12] != 'Z')
 goto returntime;
    current = utcchars;
    temp = (current[0]-'0')*10 + (current[1]-'0');
    if (temp < 50)
 temp += 100;
    tms.tm_year = temp;
    current+=2;
    temp = (current[0]-'0')*10 + (current[1]-'0');
    temp--;
    tms.tm_mon = temp;
    current+=2;
    temp = (current[0]-'0')*10 + (current[1]-'0');
    tms.tm_mday = temp;
    current+=2;
    temp = (current[0]-'0')*10 + (current[1]-'0');
    tms.tm_hour = temp;
    current+=2;
    temp = (current[0]-'0')*10 + (current[1]-'0');
    tms.tm_min = temp;
    current+=2;
    temp = (current[0]-'0')*10 + (current[1]-'0');
    tms.tm_sec = temp;
    tms.tm_isdst = -1;
    tzset();
    utime = mktime(&tms);
    if (utime != -1) {
 utime = utime - timezone + daylight*3600;
    }
  returntime:
    if (unixtime)
 *unixtime = utime;
    return utime;
}

variable_types: struct asn1_string_st { int length; int type; unsigned char *data; long flags; } *

variable_types:
unixtime
long *

variable_types:
utcchars
char *

variable_types: length int

variable_types: temp int

variable_types: utime long

variable_types:
current
char *

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; }

return_type: long


decompiled_code:
_QWORD *PKCS11_FindObjectsInfo_New()
{
_QWORD *result; // rax

log_printf("entering PKCS11_FindObjectsInfo_New\n");
result = malloc(0x20uLL);
if ( result )
{
*result = 0LL;
result[1] = 0LL;
result[2] = 0LL;
*((_BYTE *)result + 24) = 0;
}
return result;
}

canonical_decompiled_code:
_QWORD *func0()
{
_QWORD *result; // rax

log_printf("entering PKCS11_FindObjectsInfo_New\n");
result = malloc(0x20uLL);
if ( result )
{
*result = 0LL;
result[1] = 0LL;
result[2] = 0LL;
*((_BYTE *)result + 24) = 0;
}
return result;
}

original_code:
PKCS11_FINDOBJECTS_INFO * PKCS11_FindObjectsInfo_New() {
    PKCS11_FINDOBJECTS_INFO * FindObjectsInfoPtr;
    log_printf("entering PKCS11_FindObjectsInfo_New\n");
    FindObjectsInfoPtr=(PKCS11_FINDOBJECTS_INFO *)malloc(sizeof(PKCS11_FINDOBJECTS_INFO));
    if (FindObjectsInfoPtr==((void *)0)) {
 return(((void *)0));
    }
    FindObjectsInfoPtr->pTemplate=((void *)0);
    FindObjectsInfoPtr->ulAttrCount=0L;
    FindObjectsInfoPtr->TokenObjectsIndex=0L;
    FindObjectsInfoPtr->isactive=0;
    return(FindObjectsInfoPtr);
}

canonical_original_code:
struct PKCS11_FINDOBJECTS_INFO *PKCS11_FindObjectsInfo_New() {
    struct PKCS11_FINDOBJECTS_INFO *FindObjectsInfoPtr;
    log_printf("entering PKCS11_FindObjectsInfo_New\n");
    FindObjectsInfoPtr=(struct PKCS11_FINDOBJECTS_INFO *)malloc(sizeof(PKCS11_FINDOBJECTS_INFO));
    if (FindObjectsInfoPtr==((void *)0)) {
 return(((void *)0));
    }
    FindObjectsInfoPtr->pTemplate=((void *)0);
    FindObjectsInfoPtr->ulAttrCount=0L;
    FindObjectsInfoPtr->TokenObjectsIndex=0L;
    FindObjectsInfoPtr->isactive=0;
    return(FindObjectsInfoPtr);
}

variable_types: struct PKCS11_FINDOBJECTS_INFO { struct CK_ATTRIBUTE { unsigned long type; void *value; unsigned long ulValueLen; } *pTemplate; unsigned long ulAttrCount; long TokenObjectsIndex; unsigned char isactive; } *

user_defined_types: struct PKCS11_FINDOBJECTS_INFO { struct CK_ATTRIBUTE *pTemplate; unsigned long ulAttrCount; long TokenObjectsIndex; unsigned char isactive; }


decompiled_code:
_QWORD *PKCS11_SignInfo_New()
{
_QWORD *result; // rax

log_printf("entering PKCS11_SignInfo_New\n");
result = malloc(0x28uLL);
if ( result )
{
*result = 0LL;
result[1] = 0LL;
result[2] = 0LL;
*((_BYTE *)result + 24) = 0;
result[4] = 0LL;
}
return result;
}

canonical_decompiled_code:
_QWORD *func1()
{
_QWORD *result; // rax

log_printf("entering PKCS11_SignInfo_New\n");
result = malloc(0x28uLL);
if ( result )
{
*result = 0LL;
result[1] = 0LL;
result[2] = 0LL;
*((_BYTE *)result + 24) = 0;
result[4] = 0LL;
}
return result;
}

original_code:
PKCS11_SIGN_INFO * PKCS11_SignInfo_New() {
    PKCS11_SIGN_INFO * SignInfoPtr;
    log_printf("entering PKCS11_SignInfo_New\n");
    SignInfoPtr=(PKCS11_SIGN_INFO *)malloc(sizeof(PKCS11_SIGN_INFO));
    if (SignInfoPtr==((void *)0)) {
 return(((void *)0));
    }
    SignInfoPtr->pMechanism=((void *)0);
    SignInfoPtr->hKey=0L;
    SignInfoPtr->pSignature=((void *)0);
    SignInfoPtr->isactive=0;
    SignInfoPtr->pulSignatureLen=0L;
    return(SignInfoPtr);
}

canonical_original_code:
struct PKCS11_SIGN_INFO *PKCS11_SignInfo_New() {
    struct PKCS11_SIGN_INFO *SignInfoPtr;
    log_printf("entering PKCS11_SignInfo_New\n");
    SignInfoPtr=(struct PKCS11_SIGN_INFO *)malloc(sizeof(PKCS11_SIGN_INFO));
    if (SignInfoPtr==((void *)0)) {
 return(((void *)0));
    }
    SignInfoPtr->pMechanism=((void *)0);
    SignInfoPtr->hKey=0L;
    SignInfoPtr->pSignature=((void *)0);
    SignInfoPtr->isactive=0;
    SignInfoPtr->pulSignatureLen=0L;
    return(SignInfoPtr);
}

variable_types: struct PKCS11_SIGN_INFO { struct CK_MECHANISM { unsigned short mechanism; void *pParameter; unsigned long ulParameterLen; } *pMechanism; unsigned long hKey; unsigned char *pSignature; unsigned char isactive; unsigned long *pulSignatureLen; } *

user_defined_types: struct PKCS11_SIGN_INFO { struct CK_MECHANISM *pMechanism; unsigned long hKey; unsigned char *pSignature; unsigned char isactive; unsigned long *pulSignatureLen; }


decompiled_code:
_QWORD *PKCS11_Object_New()
{
_QWORD *result; // rax

log_printf("entering PKCS11_Object_New\n");
result = malloc(0x20uLL);
if ( result )
{
*result = 0LL;
result[1] = 0LL;
result[3] = 0LL;
}
return result;
}

canonical_decompiled_code:
_QWORD *func2()
{
_QWORD *result; // rax

log_printf("entering PKCS11_Object_New\n");
result = malloc(0x20uLL);
if ( result )
{
*result = 0LL;
result[1] = 0LL;
result[3] = 0LL;
}
return result;
}

original_code:
PKCS11_OBJECT *PKCS11_Object_New() {
    PKCS11_OBJECT *pObject;
    log_printf("entering PKCS11_Object_New\n");
    pObject=(PKCS11_OBJECT *)malloc(sizeof(PKCS11_OBJECT));
    if (pObject==((void *)0)) {
 return(((void *)0));
    }
    pObject->ulObjectHandle=0L;
    pObject->ulObjectClass=0L;
    pObject->pAttribute=((void *)0);
    return(pObject);
}

canonical_original_code:
struct PKCS11_OBJECT *PKCS11_Object_New() {
    struct PKCS11_OBJECT *pObject;
    log_printf("entering PKCS11_Object_New\n");
    pObject=(struct PKCS11_OBJECT *)malloc(sizeof(PKCS11_OBJECT));
    if (pObject==((void *)0)) {
 return(((void *)0));
    }
    pObject->ulObjectHandle=0L;
    pObject->ulObjectClass=0L;
    pObject->pAttribute=((void *)0);
    return(pObject);
}

variable_types: struct PKCS11_OBJECT { unsigned long ulObjectHandle; unsigned long ulObjectClass; unsigned long ulSessionHandle; struct CK_ATTRIBUTE { unsigned long type; void *value; unsigned long ulValueLen; } *pAttribute; } *

user_defined_types: struct PKCS11_OBJECT { unsigned long ulObjectHandle; unsigned long ulObjectClass; unsigned long ulSessionHandle; struct CK_ATTRIBUTE *pAttribute; }


decompiled_code:
void __fastcall PKCS11_FindObjectsInfo_Free(void *ptr)
{
log_printf("entering PKCS11_FindObjectsInfo_Free\n");
if ( ptr )
{
if ( *(_QWORD *)ptr )
CKI_Attribute_Free();
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func5(void *ptr)
{
log_printf("entering PKCS11_FindObjectsInfo_Free\n");
if ( ptr )
{
if ( *(_QWORD *)ptr )
CKI_Attribute_Free();
free(ptr);
}
}

original_code:
void PKCS11_FindObjectsInfo_Free(PKCS11_FINDOBJECTS_INFO *FindObjectsInfoPtr) {
    log_printf("entering PKCS11_FindObjectsInfo_Free\n");
    if (FindObjectsInfoPtr==((void *)0))
 return;
    if (FindObjectsInfoPtr->pTemplate!=((void *)0))
 CKI_Attribute_Free(FindObjectsInfoPtr->pTemplate);
    free(FindObjectsInfoPtr);
    return;
}

canonical_original_code:
void PKCS11_FindObjectsInfo_Free(struct PKCS11_FINDOBJECTS_INFO *FindObjectsInfoPtr) {
    log_printf("entering PKCS11_FindObjectsInfo_Free\n");
    if (FindObjectsInfoPtr==((void *)0))
 return;
    if (FindObjectsInfoPtr->pTemplate!=((void *)0))
 CKI_Attribute_Free(FindObjectsInfoPtr->pTemplate);
    free(FindObjectsInfoPtr);
    return;
}

user_defined_types: struct CK_ATTRIBUTE { unsigned long type; void *value; unsigned long ulValueLen; }


decompiled_code:
void __fastcall PKCS11_SignInfo_Free(void *ptr)
{
void *v2; // rdi

log_printf("entering PKCS11_SignInfo_Free\n");
if ( ptr )
{
if ( *(_QWORD *)ptr )
CKI_Mechanism_Free();
v2 = (void *)*((_QWORD *)ptr + 2);
if ( v2 )
free(v2);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func6(void *ptr)
{
void *v2; // rdi

log_printf("entering PKCS11_SignInfo_Free\n");
if ( ptr )
{
if ( *(_QWORD *)ptr )
CKI_Mechanism_Free();
v2 = (void *)*((_QWORD *)ptr + 2);
if ( v2 )
free(v2);
free(ptr);
}
}

original_code:
void PKCS11_SignInfo_Free(PKCS11_SIGN_INFO *SignInfoPtr) {
    log_printf("entering PKCS11_SignInfo_Free\n");
    if (SignInfoPtr==((void *)0))
 return;
    if (SignInfoPtr->pMechanism!=((void *)0))
 CKI_Mechanism_Free(SignInfoPtr->pMechanism);
    if (SignInfoPtr->pSignature!=((void *)0))
 free(SignInfoPtr->pSignature);
    free(SignInfoPtr);
    return;
}

canonical_original_code:
void PKCS11_SignInfo_Free(struct PKCS11_SIGN_INFO *SignInfoPtr) {
    log_printf("entering PKCS11_SignInfo_Free\n");
    if (SignInfoPtr==((void *)0))
 return;
    if (SignInfoPtr->pMechanism!=((void *)0))
 CKI_Mechanism_Free(SignInfoPtr->pMechanism);
    if (SignInfoPtr->pSignature!=((void *)0))
 free(SignInfoPtr->pSignature);
    free(SignInfoPtr);
    return;
}

user_defined_types: struct CK_MECHANISM { unsigned short mechanism; void *pParameter; unsigned long ulParameterLen; }


decompiled_code:
void __fastcall PKCS11_Object_Free(void *ptr)
{
log_printf("entering PKCS11_Object_Free\n");
if ( ptr )
{
if ( *((_QWORD *)ptr + 3) )
CKI_AttributePtr_Free();
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func9(void *ptr)
{
log_printf("entering PKCS11_Object_Free\n");
if ( ptr )
{
if ( *((_QWORD *)ptr + 3) )
CKI_AttributePtr_Free();
free(ptr);
}
}

original_code:
void PKCS11_Object_Free(PKCS11_OBJECT *pObject) {
    log_printf("entering PKCS11_Object_Free\n");
    if (pObject==((void *)0))
 return;
    if (pObject->pAttribute!=((void *)0)) {
 CKI_AttributePtr_Free(pObject->pAttribute);
    }
    free(pObject);
    return;
}

canonical_original_code:
void PKCS11_Object_Free(struct PKCS11_OBJECT *pObject) {
    log_printf("entering PKCS11_Object_Free\n");
    if (pObject==((void *)0))
 return;
    if (pObject->pAttribute!=((void *)0)) {
 CKI_AttributePtr_Free(pObject->pAttribute);
    }
    free(pObject);
    return;
}


decompiled_code:
void __fastcall PKCS11_Mechanism_Free(void *ptr)
{
log_printf("entering PKCS11_Mechanism_Free\n");
if ( ptr )
{
if ( *(_QWORD *)ptr )
CKI_MechanismInfo_Free();
if ( *((_QWORD *)ptr + 1) )
CKI_Mechanism_Free();
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func12(void *ptr)
{
log_printf("entering PKCS11_Mechanism_Free\n");
if ( ptr )
{
if ( *(_QWORD *)ptr )
CKI_MechanismInfo_Free();
if ( *((_QWORD *)ptr + 1) )
CKI_Mechanism_Free();
free(ptr);
}
}

original_code:
void PKCS11_Mechanism_Free(PKCS11_MECHANISM *pMechanism) {
    log_printf("entering PKCS11_Mechanism_Free\n");
    if (pMechanism==((void *)0)) return;
    if (pMechanism->pInfo!=((void *)0))
 CKI_MechanismInfo_Free(pMechanism->pInfo);
    if (pMechanism->pMechanism!=((void *)0))
 CKI_Mechanism_Free(pMechanism->pMechanism);
    free(pMechanism);
    return;
}

canonical_original_code:
void PKCS11_Mechanism_Free(struct PKCS11_MECHANISM *pMechanism) {
    log_printf("entering PKCS11_Mechanism_Free\n");
    if (pMechanism==((void *)0)) return;
    if (pMechanism->pInfo!=((void *)0))
 CKI_MechanismInfo_Free(pMechanism->pInfo);
    if (pMechanism->pMechanism!=((void *)0))
 CKI_Mechanism_Free(pMechanism->pMechanism);
    free(pMechanism);
    return;
}

variable_types: struct PKCS11_MECHANISM { struct CK_MECHANISM_INFO { unsigned long ulMinKeySize; unsigned long ulMaxKeySize; unsigned long flags; } *pInfo; struct CK_MECHANISM { unsigned short mechanism; void *pParameter; unsigned long ulParameterLen; } *pMechanism; } *

user_defined_types: struct PKCS11_MECHANISM { struct CK_MECHANISM_INFO *pInfo; struct CK_MECHANISM *pMechanism; }


decompiled_code:
__int64 *PKCS11_Mechanism_New()
{
__int64 *v0; // rax
__int64 *v1; // rbx
__int64 v2; // rbp
__int64 v3; // rbp

log_printf("entering PKCS11_Mechanism_New\n");
v0 = (__int64 *)malloc(0x10uLL);
v1 = v0;
if ( v0 )
{
*v0 = 0LL;
v0[1] = 0LL;
v2 = CKI_MechanismInfo_New();
*v1 = v2;
if ( !v2 || (v3 = CKI_Mechanism_New(), (v1[1] = v3) == 0) )
{
PKCS11_Mechanism_Free(v1);
v1 = 0LL;
}
}
return v1;
}

canonical_decompiled_code:
__int64 *func13()
{
__int64 *v0; // rax
__int64 *v1; // rbx
__int64 v2; // rbp
__int64 v3; // rbp

log_printf("entering PKCS11_Mechanism_New\n");
v0 = (__int64 *)malloc(0x10uLL);
v1 = v0;
if ( v0 )
{
*v0 = 0LL;
v0[1] = 0LL;
v2 = CKI_MechanismInfo_New();
*v1 = v2;
if ( !v2 || (v3 = CKI_Mechanism_New(), (v1[1] = v3) == 0) )
{
func12(v1);
v1 = 0LL;
}
}
return v1;
}

original_code:
PKCS11_MECHANISM *PKCS11_Mechanism_New() {
    PKCS11_MECHANISM *pMechanism;
    log_printf("entering PKCS11_Mechanism_New\n");
    pMechanism=(PKCS11_MECHANISM *)malloc(sizeof(PKCS11_MECHANISM));
    if (pMechanism==((void *)0)) {
 return(((void *)0));
    }
    pMechanism->pInfo=((void *)0);
    pMechanism->pMechanism=((void *)0);
    pMechanism->pInfo=CKI_MechanismInfo_New();
    if (pMechanism->pInfo==((void *)0)) {
 PKCS11_Mechanism_Free(pMechanism);
 return(((void *)0));
    }
    pMechanism->pMechanism=CKI_Mechanism_New();
    if (pMechanism->pMechanism==((void *)0)) {
 PKCS11_Mechanism_Free(pMechanism);
 return(((void *)0));
    }
    return(pMechanism);
}

canonical_original_code:
struct PKCS11_MECHANISM *PKCS11_Mechanism_New() {
    struct PKCS11_MECHANISM *pMechanism;
    log_printf("entering PKCS11_Mechanism_New\n");
    pMechanism=(struct PKCS11_MECHANISM *)malloc(sizeof(PKCS11_MECHANISM));
    if (pMechanism==((void *)0)) {
 return(((void *)0));
    }
    pMechanism->pInfo=((void *)0);
    pMechanism->pMechanism=((void *)0);
    pMechanism->pInfo=CKI_MechanismInfo_New();
    if (pMechanism->pInfo==((void *)0)) {
 PKCS11_Mechanism_Free(pMechanism);
 return(((void *)0));
    }
    pMechanism->pMechanism=CKI_Mechanism_New();
    if (pMechanism->pMechanism==((void *)0)) {
 PKCS11_Mechanism_Free(pMechanism);
 return(((void *)0));
    }
    return(pMechanism);
}

return_type: struct PKCS11_MECHANISM { struct CK_MECHANISM_INFO { unsigned long ulMinKeySize; unsigned long ulMaxKeySize; unsigned long flags; } *pInfo; struct CK_MECHANISM { unsigned short mechanism; void *pParameter; unsigned long ulParameterLen; } *pMechanism; } *


getelt

decompiled_code:
__int64 __fastcall getelt(__int64 *a1, const char *a2)
{
__int64 v2; // rbp
_QWORD *v3; // rbx

if ( !a1 )
return 0LL;
v2 = *a1;
if ( *a1 )
{
v3 = a1 + 1;
while ( strcmp(*(const char **)v2, a2) )
{
v2 = *v3++;
if ( !v2 )
return v2;
}
v2 = *(_QWORD *)(v2 + 8);
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 *a1, const char *a2)
{
__int64 v2; // rbp
_QWORD *v3; // rbx

if ( !a1 )
return 0LL;
v2 = *a1;
if ( *a1 )
{
v3 = a1 + 1;
while ( strcmp(*(const char **)v2, a2) )
{
v2 = *v3++;
if ( !v2 )
return v2;
}
v2 = *(_QWORD *)(v2 + 8);
}
return v2;
}

original_code:
char *getelt(struct a_t **alist, char *name) {
  int i;
  if (!alist) return(((void *)0));
  i=0;
  while (alist[i]) {
   if (!strcmp(alist[i]->name,name)) return(alist[i]->value);
   i++;
  }
  return(((void *)0));
}

variable_types: struct a_t { char *name; char *value; } **

variable_types:
name
char *

variable_types: i int

return_type: char *


getCertAndKey

decompiled_code:
char *__fastcall getCertAndKey(__int64 a1, char *a2, int a3)
{
unsigned int v4; // ebx
char *v5; // rax
char *v6; // r12
unsigned int v7; // ebx
char *v8; // rax
char *v9; // r13
_QWORD *v10; // rbp
_QWORD *v11; // rbx
signed int v12; // eax
_QWORD *v13; // rdx
signed int v14; // eax
_QWORD *v15; // rdx
_QWORD *v16; // rdi
__int64 v18; // [rsp+0h] [rbp-48h] BYREF
unsigned int v19; // [rsp+Ch] [rbp-3Ch] BYREF
__int64 v20; // [rsp+10h] [rbp-38h] BYREF
unsigned int v21[11]; // [rsp+1Ch] [rbp-2Ch] BYREF

v21[0] = 0;
v20 = 0LL;
v19 = 0;
v18 = 0LL;
log_printf("getCertAndKey: entered\n");
if ( (unsigned int)os_getCertAndKey(&v20, v21, &v18, &v19, a2, a3) )
{
v4 = v21[0];
v5 = (char *)malloc(2LL * (v21[0] + 1));
v6 = v5;
if ( v5
&& (b64_encode(v20, v4, v5),
log_printf("getCertAndKey: cert_length=%0d\n", v21[0]),
log_printf("getCertAndKey: cert_enc='%s'\n", v6),
log_printf("getCertAndKey: 4\n"),
v7 = v19,
v8 = (char *)malloc(2LL * (int)(v19 + 1)),
(v9 = v8) != 0LL) )
{
b64_encode(v18, v7, v8);
log_printf("getCertAndKey: key_length=%0d\n", v19);
log_printf("getCertAndKey: key_enc='%s'\n", v9);
log_printf("getCertAndKey: 5\n");
v10 = malloc(0x18uLL);
log_printf("getCertAndKey: 6\n");
if ( v10 )
{
v11 = v10 + 1;
v10[1] = 0LL;
v10[2] = 0LL;
*v10 = malloc(0x10uLL);
log_printf("getCertAndKey: 7\n");
if ( *v10 )
{
v10[1] = malloc(0x10uLL);
log_printf("getCertAndKey: 8\n");
if ( v10[1] )
{
log_printf("getCertAndKey: 9\n");
v12 = (unsigned int)strdup("cert");
v13 = (_QWORD *)*v10;
*v13 = v12;
v13[1] = v6;
v14 = (unsigned int)strdup("key");
v15 = (_QWORD *)v10[1];
*v15 = v14;
v15[1] = v9;
log_printf("getCertAndKey: leaving\n");
return (char *)v10;
}
v16 = (_QWORD *)*v10;
if ( *v10 )
{
do
{
free(v16);
v16 = (_QWORD *)*v11++;
}
while ( v16 );
}
}
free(v10);
}
free(v9);
}
else
{
log_printf("getCertAndKey: out of memory\n");
}
}
else
{
log_printf("getCertAndKey: os_getCertAndKey failed\n");
v6 = 0LL;
}
if ( v6 )
{
free(v6);
v6 = 0LL;
}
return v6;
}

canonical_decompiled_code:
char *__fastcall func2(__int64 a1, char *a2, int a3)
{
unsigned int v4; // ebx
char *v5; // rax
char *v6; // r12
unsigned int v7; // ebx
char *v8; // rax
char *v9; // r13
_QWORD *v10; // rbp
_QWORD *v11; // rbx
signed int v12; // eax
_QWORD *v13; // rdx
signed int v14; // eax
_QWORD *v15; // rdx
_QWORD *v16; // rdi
__int64 v18; // [rsp+0h] [rbp-48h] BYREF
unsigned int v19; // [rsp+Ch] [rbp-3Ch] BYREF
__int64 v20; // [rsp+10h] [rbp-38h] BYREF
unsigned int v21[11]; // [rsp+1Ch] [rbp-2Ch] BYREF

v21[0] = 0;
v20 = 0LL;
v19 = 0;
v18 = 0LL;
log_printf("getCertAndKey: entered\n");
if ( (unsigned int)func1(&v20, v21, &v18, &v19, a2, a3) )
{
v4 = v21[0];
v5 = (char *)malloc(2LL * (v21[0] + 1));
v6 = v5;
if ( v5
&& (b64_encode(v20, v4, v5),
log_printf("getCertAndKey: cert_length=%0d\n", v21[0]),
log_printf("getCertAndKey: cert_enc='%s'\n", v6),
log_printf("getCertAndKey: 4\n"),
v7 = v19,
v8 = (char *)malloc(2LL * (int)(v19 + 1)),
(v9 = v8) != 0LL) )
{
b64_encode(v18, v7, v8);
log_printf("getCertAndKey: key_length=%0d\n", v19);
log_printf("getCertAndKey: key_enc='%s'\n", v9);
log_printf("getCertAndKey: 5\n");
v10 = malloc(0x18uLL);
log_printf("getCertAndKey: 6\n");
if ( v10 )
{
v11 = v10 + 1;
v10[1] = 0LL;
v10[2] = 0LL;
*v10 = malloc(0x10uLL);
log_printf("getCertAndKey: 7\n");
if ( *v10 )
{
v10[1] = malloc(0x10uLL);
log_printf("getCertAndKey: 8\n");
if ( v10[1] )
{
log_printf("getCertAndKey: 9\n");
v12 = (unsigned int)strdup("cert");
v13 = (_QWORD *)*v10;
*v13 = v12;
v13[1] = v6;
v14 = (unsigned int)strdup("key");
v15 = (_QWORD *)v10[1];
*v15 = v14;
v15[1] = v9;
log_printf("getCertAndKey: leaving\n");
return (char *)v10;
}
v16 = (_QWORD *)*v10;
if ( *v10 )
{
do
{
free(v16);
v16 = (_QWORD *)*v11++;
}
while ( v16 );
}
}
free(v10);
}
free(v9);
}
else
{
log_printf("getCertAndKey: out of memory\n");
}
}
else
{
log_printf("getCertAndKey: os_getCertAndKey failed\n");
v6 = 0LL;
}
if ( v6 )
{
free(v6);
v6 = 0LL;
}
return v6;
}

original_code:
struct a_t **getCertAndKey(struct a_t **tattrl, char *name, int namelen)
{
    struct a_t **attrl=((void *)0);
    int cert_length = 0;
    char *cert_der = ((void *)0);
    char *cert_enc = ((void *)0);
    int key_length =0;
    char *key_der = ((void *)0);
    char *key_enc = ((void *)0);
    int i;
    log_printf("getCertAndKey: entered\n");
    if (!os_getCertAndKey(&cert_der, &cert_length,
      &key_der, &key_length,
      name, namelen))
    {
 log_printf("getCertAndKey: os_getCertAndKey failed\n");
 goto error;
    }
    cert_enc=(char *)malloc(sizeof(char)*(cert_length+1)*2);
    if (!cert_enc) {
 log_printf("getCertAndKey: out of memory\n");
 goto error;
    }
    b64_encode(cert_der,cert_length,cert_enc);
    log_printf("getCertAndKey: cert_length=%0d\n", cert_length);
    log_printf("getCertAndKey: cert_enc='%s'\n", cert_enc);
    log_printf("getCertAndKey: 4\n");
    key_enc=(char *)malloc(sizeof(char)*(key_length+1)*2);
    if (!key_enc) {
 log_printf("getCertAndKey: out of memory\n");
 goto error;
    }
    b64_encode(key_der,key_length,key_enc);
    log_printf("getCertAndKey: key_length=%0d\n", key_length);
    log_printf("getCertAndKey: key_enc='%s'\n", key_enc);
    log_printf("getCertAndKey: 5\n");
    attrl=(struct a_t **)malloc(sizeof(struct a_t *)*3);
    log_printf("getCertAndKey: 6\n");
    if (!attrl)
     goto error;
    memset(attrl, 0, sizeof(struct a_t *)*3);
    (attrl)[0]=(struct a_t *)malloc(sizeof(struct a_t));
    log_printf("getCertAndKey: 7\n");
    if (! (attrl)[0]) {
     goto error;
    }
    (attrl)[1]=(struct a_t *)malloc(sizeof(struct a_t));
    log_printf("getCertAndKey: 8\n");
    if (! (attrl)[1]) {
 goto error;
    }
    log_printf("getCertAndKey: 9\n");
    (attrl)[0]->name=_strdup("cert");
    (attrl)[0]->value=cert_enc;
    (attrl)[1]->name=_strdup("key");
    (attrl)[1]->value=key_enc;
    log_printf("getCertAndKey: leaving\n");
    return(attrl);
  error:
    if (attrl) {
 for (i=0;attrl[i];i++) {
     if (attrl[i])
  free(attrl[i]);
 }
 free(attrl);
    }
    if (key_enc)
 free(key_enc);
    if (cert_enc)
 free(cert_enc);
    return ((void *)0);
}

canonical_original_code:
struct a_t **getCertAndKey(struct a_t **tattrl, char *name, int namelen)
{
    struct a_t **attrl = ((void *)0);
    int cert_length = 0;
    char *cert_der = ((void *)0);
    char *cert_enc = ((void *)0);
    int key_length = 0;
    char *key_der = ((void *)0);
    char *key_enc = ((void *)0);
    int i;
    log_printf("getCertAndKey: entered\n");
    if (!os_getCertAndKey(&cert_der, &cert_length,
      &key_der, &key_length,
      name, namelen))
    {
 log_printf("getCertAndKey: os_getCertAndKey failed\n");
 goto error;
    }
    cert_enc=(char *)malloc(sizeof(char)*(cert_length+1)*2);
    if (!cert_enc) {
 log_printf("getCertAndKey: out of memory\n");
 goto error;
    }
    b64_encode(cert_der,cert_length,cert_enc);
    log_printf("getCertAndKey: cert_length=%0d\n", cert_length);
    log_printf("getCertAndKey: cert_enc='%s'\n", cert_enc);
    log_printf("getCertAndKey: 4\n");
    key_enc=(char *)malloc(sizeof(char)*(key_length+1)*2);
    if (!key_enc) {
 log_printf("getCertAndKey: out of memory\n");
 goto error;
    }
    b64_encode(key_der,key_length,key_enc);
    log_printf("getCertAndKey: key_length=%0d\n", key_length);
    log_printf("getCertAndKey: key_enc='%s'\n", key_enc);
    log_printf("getCertAndKey: 5\n");
    attrl=(struct a_t **)malloc(sizeof(struct a_t *)*3);
    log_printf("getCertAndKey: 6\n");
    if (!attrl)
     goto error;
    memset(attrl, 0, sizeof(struct a_t *)*3);
    (attrl)[0]=(struct a_t *)malloc(sizeof(struct a_t));
    log_printf("getCertAndKey: 7\n");
    if (! (attrl)[0]) {
     goto error;
    }
    (attrl)[1]=(struct a_t *)malloc(sizeof(struct a_t));
    log_printf("getCertAndKey: 8\n");
    if (! (attrl)[1]) {
 goto error;
    }
    log_printf("getCertAndKey: 9\n");
    (attrl)[0]->name=_strdup("cert");
    (attrl)[0]->value=cert_enc;
    (attrl)[1]->name=_strdup("key");
    (attrl)[1]->value=key_enc;
    log_printf("getCertAndKey: leaving\n");
    return(attrl);
  error:
    if (attrl) {
 for (i=0;attrl[i];i++) {
     if (attrl[i])
  free(attrl[i]);
 }
 free(attrl);
    }
    if (key_enc)
 free(key_enc);
    if (cert_enc)
 free(cert_enc);
    return ((void *)0);
}

variable_types:
tattrl
struct a_t **

variable_types: namelen int

return_type: struct a_t { char *name; char *value; } **


doauth

decompiled_code:
__int64 __fastcall doauth(char **a1, void **a2)
{
_QWORD *v3; // rax
char *v4; // rax
_QWORD *v5; // rbx
_QWORD *v6; // rbx
__int64 result; // rax
void ***v8; // rdi
__int64 v9; // rbx
void **v10; // rax
void *v11; // rdi
_QWORD *v12; // rdx
void *v13; // rdi
void *v14; // rdi
__int64 v15[2]; // [rsp+0h] [rbp-218h] BYREF
char v16[496]; // [rsp+10h] [rbp-208h] BYREF

v15[0] = 0LL;
v15[1] = 0LL;
memset(v16, 0, sizeof(v16));
log_printf("doauth: entered\n");
*a1 = 0LL;
v3 = malloc(0x18uLL);
*a2 = v3;
if ( !v3 )
{
v8 = (void ***)*a1;
result = 0xFFFFFFFFLL;
if ( !*a1 )
return result;
goto LABEL_25;
}
*v3 = 0LL;
v3[1] = 0LL;
v3[2] = 0LL;
v4 = getCertAndKey((__int64)v3, (char *)v15, 512);
*a1 = v4;
if ( !v4 )
{
log_printf("doauth: doauth 9, couldn't do cert/key\n");
v8 = (void ***)*a1;
if ( !*a1 )
goto LABEL_14;
goto LABEL_25;
}
log_printf("doauth: user name is '%s'\n", (const char *)v15);
v5 = *a2;
*v5 = malloc(0x10uLL);
if ( *(_QWORD *)*a2 )
{
v6 = *a2;
v6[1] = malloc(0x10uLL);
if ( *((_QWORD *)*a2 + 1) )
{
**(_QWORD **)*a2 = (int)strdup("user");
*(_QWORD *)(*(_QWORD *)*a2 + 8LL) = (int)strdup((const char *)v15);
**((_QWORD **)*a2 + 1) = (int)strdup("password");
*(_QWORD *)(*((_QWORD *)*a2 + 1) + 8LL) = (int)strdup(&LC0);
log_printf("doauth: success\n");
return 0LL;
}
}
v8 = (void ***)*a1;
if ( *a1 )
{
LABEL_25:
v10 = *v8;
if ( *v8 )
{
v9 = 0LL;
do
{
if ( *v10 )
free(*v10);
v11 = *(void **)(*(_QWORD *)&(*a1)[v9] + 8LL);
if ( v11 )
free(v11);
free(*(void **)&(*a1)[v9]);
v8 = (void ***)*a1;
v9 += 8LL;
v10 = *(void ***)&(*a1)[v9];
}
while ( v10 );
}
free(v8);
*a1 = 0LL;
LABEL_14:
v12 = *a2;
result = 0xFFFFFFFFLL;
if ( !*a2 )
return result;
goto LABEL_15;
}
v12 = *a2;
LABEL_15:
v13 = (void *)v12[1];
if ( v13 )
free(v13);
v14 = *(void **)*a2;
if ( v14 )
free(v14);
free(*a2);
*a2 = 0LL;
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func3(char **a1, void **a2)
{
_QWORD *v3; // rax
char *v4; // rax
_QWORD *v5; // rbx
_QWORD *v6; // rbx
__int64 result; // rax
void ***v8; // rdi
__int64 v9; // rbx
void **v10; // rax
void *v11; // rdi
_QWORD *v12; // rdx
void *v13; // rdi
void *v14; // rdi
__int64 v15[2]; // [rsp+0h] [rbp-218h] BYREF
char v16[496]; // [rsp+10h] [rbp-208h] BYREF

v15[0] = 0LL;
v15[1] = 0LL;
memset(v16, 0, sizeof(v16));
log_printf("doauth: entered\n");
*a1 = 0LL;
v3 = malloc(0x18uLL);
*a2 = v3;
if ( !v3 )
{
v8 = (void ***)*a1;
result = 0xFFFFFFFFLL;
if ( !*a1 )
return result;
goto LABEL_25;
}
*v3 = 0LL;
v3[1] = 0LL;
v3[2] = 0LL;
v4 = func2((__int64)v3, (char *)v15, 512);
*a1 = v4;
if ( !v4 )
{
log_printf("doauth: doauth 9, couldn't do cert/key\n");
v8 = (void ***)*a1;
if ( !*a1 )
goto LABEL_14;
goto LABEL_25;
}
log_printf("doauth: user name is '%s'\n", (const char *)v15);
v5 = *a2;
*v5 = malloc(0x10uLL);
if ( *(_QWORD *)*a2 )
{
v6 = *a2;
v6[1] = malloc(0x10uLL);
if ( *((_QWORD *)*a2 + 1) )
{
**(_QWORD **)*a2 = (int)strdup("user");
*(_QWORD *)(*(_QWORD *)*a2 + 8LL) = (int)strdup((const char *)v15);
**((_QWORD **)*a2 + 1) = (int)strdup("password");
*(_QWORD *)(*((_QWORD *)*a2 + 1) + 8LL) = (int)strdup(&LC0);
log_printf("doauth: success\n");
return 0LL;
}
}
v8 = (void ***)*a1;
if ( *a1 )
{
LABEL_25:
v10 = *v8;
if ( *v8 )
{
v9 = 0LL;
do
{
if ( *v10 )
free(*v10);
v11 = *(void **)(*(_QWORD *)&(*a1)[v9] + 8LL);
if ( v11 )
free(v11);
free(*(void **)&(*a1)[v9]);
v8 = (void ***)*a1;
v9 += 8LL;
v10 = *(void ***)&(*a1)[v9];
}
while ( v10 );
}
free(v8);
*a1 = 0LL;
LABEL_14:
v12 = *a2;
result = 0xFFFFFFFFLL;
if ( !*a2 )
return result;
goto LABEL_15;
}
v12 = *a2;
LABEL_15:
v13 = (void *)v12[1];
if ( v13 )
free(v13);
v14 = *(void **)*a2;
if ( v14 )
free(v14);
free(*a2);
*a2 = 0LL;
return 0xFFFFFFFFLL;
}

original_code:
int doauth(struct a_t ***attrl, struct a_t ***tattrl)
{
    char user[512]="";
    int i;
    log_printf("doauth: entered\n");
    *attrl=((void *)0);
    *tattrl=((void *)0);
    *tattrl=(struct a_t **)malloc(sizeof(struct a_t *)*3);
    if (!*tattrl) goto error;
    memset(*tattrl, 0, sizeof(struct a_t *)*3);
    *attrl=getCertAndKey(*tattrl, user, sizeof(user));
    if (!*attrl) {
 log_printf("doauth: doauth 9, couldn't do cert/key\n");
 goto error;
    }
    log_printf("doauth: user name is '%s'\n", user);
    (*tattrl)[0]=(struct a_t *)malloc(sizeof(struct a_t));
    if (! (*tattrl)[0]) goto error;
    (*tattrl)[1]=(struct a_t *)malloc(sizeof(struct a_t));
    if (! (*tattrl)[1]) goto error;
    (*tattrl)[0]->name=_strdup("user");
    (*tattrl)[0]->value=_strdup(user);
    (*tattrl)[1]->name=_strdup("password");
    (*tattrl)[1]->value=_strdup("");
    log_printf("doauth: success\n");
    return(0);
  error:
    if (*attrl) {
 for (i=0;(*attrl)[i];i++) {
     if ((*attrl)[i]->name)
  free((*attrl)[i]->name);
     if ((*attrl)[i]->value)
  free((*attrl)[i]->value);
     free((*attrl)[i]);
 }
 free(*attrl);
 *attrl = ((void *)0);
    }
    if (*tattrl) {
 if ((*tattrl)[1])
     free((*tattrl)[1]);
 if ((*tattrl)[0])
     free((*tattrl)[0]);
 free(*tattrl);
 *tattrl = ((void *)0);
    }
    return(-1);
}

canonical_original_code:
int doauth(struct a_t ***attrl, struct a_t ***tattrl)
{
    char user[512] = "";
    int i;
    log_printf("doauth: entered\n");
    *attrl=((void *)0);
    *tattrl=((void *)0);
    *tattrl=(struct a_t **)malloc(sizeof(struct a_t *)*3);
    if (!*tattrl) goto error;
    memset(*tattrl, 0, sizeof(struct a_t *)*3);
    *attrl=getCertAndKey(*tattrl, user, sizeof(user));
    if (!*attrl) {
 log_printf("doauth: doauth 9, couldn't do cert/key\n");
 goto error;
    }
    log_printf("doauth: user name is '%s'\n", user);
    (*tattrl)[0]=(struct a_t *)malloc(sizeof(struct a_t));
    if (! (*tattrl)[0]) goto error;
    (*tattrl)[1]=(struct a_t *)malloc(sizeof(struct a_t));
    if (! (*tattrl)[1]) goto error;
    (*tattrl)[0]->name=_strdup("user");
    (*tattrl)[0]->value=_strdup(user);
    (*tattrl)[1]->name=_strdup("password");
    (*tattrl)[1]->value=_strdup("");
    log_printf("doauth: success\n");
    return(0);
  error:
    if (*attrl) {
 for (i=0;(*attrl)[i];i++) {
     if ((*attrl)[i]->name)
  free((*attrl)[i]->name);
     if ((*attrl)[i]->value)
  free((*attrl)[i]->value);
     free((*attrl)[i]);
 }
 free(*attrl);
 *attrl = ((void *)0);
    }
    if (*tattrl) {
 if ((*tattrl)[1])
     free((*tattrl)[1]);
 if ((*tattrl)[0])
     free((*tattrl)[0]);
 free(*tattrl);
 *tattrl = ((void *)0);
    }
    return(-1);
}

variable_types: struct a_t { char *name; char *value; } ***

variable_types:
tattrl
struct a_t ***

variable_types:
user
char [512]


checkTokenValidity

decompiled_code:
__int64 __fastcall checkTokenValidity(__int64 a1, char *a2)
{
return checkTokenValidity_KRB5(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, char *a2)
{
return func4(a1, a2);
}

original_code:
int checkTokenValidity()
{
 return checkTokenValidity_KRB5();
}


memcpyfast

repo: sehugg/Starthinker

decompiled_code:
void *__fastcall memcpyfast(_BYTE *a1, unsigned int *a2, int a3)
{
void *result; // rax

if ( a3 == 3 )
{
*(_WORD *)a1 = *(_WORD *)a2;
result = (void *)*((unsigned __int8 *)a2 + 2);
a1[2] = (_BYTE)result;
}
else
{
if ( a3 > 3 )
{
if ( a3 == 4 )
{
result = (void *)*a2;
*(_DWORD *)a1 = (_DWORD)result;
return result;
}
}
else
{
if ( a3 == 1 )
{
result = (void *)*(unsigned __int8 *)a2;
*a1 = (_BYTE)result;
return result;
}
if ( a3 == 2 )
{
result = (void *)*(unsigned __int16 *)a2;
*(_WORD *)a1 = (_WORD)result;
return result;
}
}
result = memcpy(a1, a2, a3);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func0(_BYTE *a1, unsigned int *a2, int a3)
{
void *result; // rax

if ( a3 == 3 )
{
*(_WORD *)a1 = *(_WORD *)a2;
result = (void *)*((unsigned __int8 *)a2 + 2);
a1[2] = (_BYTE)result;
}
else
{
if ( a3 > 3 )
{
if ( a3 == 4 )
{
result = (void *)*a2;
*(_DWORD *)a1 = (_DWORD)result;
return result;
}
}
else
{
if ( a3 == 1 )
{
result = (void *)*(unsigned __int8 *)a2;
*a1 = (_BYTE)result;
return result;
}
if ( a3 == 2 )
{
result = (void *)*(unsigned __int16 *)a2;
*(_WORD *)a1 = (_WORD)result;
return result;
}
}
result = memcpy(a1, a2, a3);
}
return result;
}

original_code:
static void memcpyfast(void* dst, const void* src, int size)
{
  switch (size)
  {
    case 1: *((char*)dst) = *((char*)src); break;
    case 2: *((short*)dst) = *((short*)src); break;
    case 3: memcpy(dst,src,size); break;
    case 4: *((int*)dst) = *((int*)src); break;
    default: memcpy(dst,src,size); break;
  }
}

canonical_original_code:
static void memcpyfast(void *dst, void *src, int size)
{
  switch (size)
  {
    case 1: *((char *)dst) = *((char *)src); break;
    case 2: *((short *)dst) = *((short *)src); break;
    case 3: memcpy(dst,src,size); break;
    case 4: *((int *)dst) = *((int *)src); break;
    default: memcpy(dst,src,size); break;
  }
}

variable_types:
dst
void *

variable_types:
src
void *

variable_types: size int


decompiled_code:
__int64 __fastcall rollback_entry(__int64 a1)
{
unsigned int v1; // edx
__int64 result; // rax

v1 = *(_DWORD *)(a1 + 16);
if ( !v1 )
_assert_fail("j->size>0", "journal.c", 0x40u, "rollback_entry");
if ( v1 <= 8 )
memcpyfast(*(_BYTE **)a1, (unsigned int *)(a1 + 8), v1);
else
memcpy(*(void **)a1, *(const void **)(a1 + 8), v1);
result = *(unsigned int *)(a1 + 20);
current_hash = *(_DWORD *)(a1 + 20);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
unsigned int v1; // edx
__int64 result; // rax

v1 = *(_DWORD *)(a1 + 16);
if ( !v1 )
_assert_fail("j->size>0", "journal.c", 0x40u, "rollback_entry");
if ( v1 <= 8 )
func0(*(_BYTE **)a1, (unsigned int *)(a1 + 8), v1);
else
memcpy(*(void **)a1, *(const void **)(a1 + 8), v1);
result = *(unsigned int *)(a1 + 20);
current_hash = *(_DWORD *)(a1 + 20);
return result;
}

original_code:
static void rollback_entry(Journal* j)
{
  ;
  ((void) sizeof ((j->size>0) ? 1 : 0), __extension__ ({ if (j->size>0) ; else __assert_fail ("j->size>0", "journal.c", 64, __extension__ __PRETTY_FUNCTION__); }));
  if (j->size > sizeof(j->mem))
    memcpy(j->dest, j->mem, j->size);
  else
    memcpyfast(j->dest, &j->mem, j->size);
  current_hash = j->hash;
}

canonical_original_code:
static void rollback_entry(struct Journal *j)
{
  ;
  ((void) sizeof ((j->size>0) ? 1 : 0), __extension__ ({ if (j->size>0) ; else __assert_fail ("j->size>0", "journal.c", 64, __extension__ __PRETTY_FUNCTION__); }));
  if (j->size > sizeof(j->mem))
    memcpy(j->dest, j->mem, j->size);
  else
    memcpyfast(j->dest, &j->mem, j->size);
  current_hash = j->hash;
}

variable_types: struct Journal { void *dest; void *mem; unsigned int size; unsigned int hash; } *


decompiled_code:
__int64 __fastcall ai_journal_save(void *src, size_t size)
{
int v2; // eax
int v3; // eax
char *v4; // rbx
void *v5; // rax
__int64 result; // rax

if ( !(_DWORD)size )
_assert_fail("size>0", "journal.c", 0x1Fu, "ai_journal_save");
v2 = jbuffer_size;
if ( jbuffer_top == jbuffer_size )
{
jbuffer_size += jbuffer_inc;
jbuffer = realloc(jbuffer, 24LL * (jbuffer_inc + v2));
}
v3 = jbuffer_top++;
v4 = (char *)jbuffer + 24 * v3;
*(_QWORD *)v4 = src;
*((_DWORD *)v4 + 4) = size;
if ( (unsigned int)size <= 8 )
{
memcpyfast(v4 + 8, (unsigned int *)src, size);
}
else
{
v5 = malloc((unsigned int)size);
*((_QWORD *)v4 + 1) = v5;
memcpy(v5, src, (unsigned int)size);
}
result = (unsigned int)current_hash;
*((_DWORD *)v4 + 5) = current_hash;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(void *src, size_t size)
{
int v2; // eax
int v3; // eax
char *v4; // rbx
void *v5; // rax
__int64 result; // rax

if ( !(_DWORD)size )
_assert_fail("size>0", "journal.c", 0x1Fu, "ai_journal_save");
v2 = jbuffer_size;
if ( jbuffer_top == jbuffer_size )
{
jbuffer_size += jbuffer_inc;
jbuffer = realloc(jbuffer, 24LL * (jbuffer_inc + v2));
}
v3 = jbuffer_top++;
v4 = (char *)jbuffer + 24 * v3;
*(_QWORD *)v4 = src;
*((_DWORD *)v4 + 4) = size;
if ( (unsigned int)size <= 8 )
{
func0(v4 + 8, (unsigned int *)src, size);
}
else
{
v5 = malloc((unsigned int)size);
*((_QWORD *)v4 + 1) = v5;
memcpy(v5, src, (unsigned int)size);
}
result = (unsigned int)current_hash;
*((_DWORD *)v4 + 5) = current_hash;
return result;
}

original_code:
void ai_journal_save(const void* dst, unsigned int size)
{
  ((void) sizeof ((size>0) ? 1 : 0), __extension__ ({ if (size>0) ; else __assert_fail ("size>0", "journal.c", 31, __extension__ __PRETTY_FUNCTION__); }));
  if (jbuffer_top == jbuffer_size)
  {
    jbuffer_size += jbuffer_inc;
    jbuffer = (Journal*) realloc(jbuffer, sizeof(Journal) * jbuffer_size);
  }
  Journal* j = &jbuffer[jbuffer_top++];
  ;
  j->dest = (void*)dst;
  j->size = size;
  if (size > sizeof(j->mem))
  {
    j->mem = malloc(size);
    memcpy(j->mem, dst, size);
  } else {
    memcpyfast(&j->mem, dst, size);
  }
  j->hash = current_hash;
}

canonical_original_code:
void ai_journal_save(void *dst, unsigned int size)
{
  ((void) sizeof ((size>0) ? 1 : 0), __extension__ ({ if (size>0) ; else __assert_fail ("size>0", "journal.c", 31, __extension__ __PRETTY_FUNCTION__); }));
  if (jbuffer_top == jbuffer_size)
  {
    jbuffer_size += jbuffer_inc;
    jbuffer = (struct Journal *) realloc(jbuffer, sizeof(Journal) * jbuffer_size);
  }
  struct Journal *j = &jbuffer[jbuffer_top++];
  ;
  j->dest = (void *)dst;
  j->size = size;
  if (size > sizeof(j->mem))
  {
    j->mem = malloc(size);
    memcpy(j->mem, dst, size);
  } else {
    memcpyfast(&j->mem, dst, size);
  }
  j->hash = current_hash;
}

variable_types:
size
unsigned int

user_defined_types: struct Journal { void *dest; void *mem; unsigned int size; unsigned int hash; }


decompiled_code:
void *__fastcall ai_journal(int a1, _BYTE *a2, unsigned int *a3, unsigned int a4)
{
int v6; // er12

ai_journal_save(a2, a4);
v6 = compute_hash_murmur2(a3, a4, (unsigned int)((_DWORD)a2 - a1));
current_hash ^= compute_hash_murmur2(a2, a4, (unsigned int)((_DWORD)a2 - a1)) ^ v6;
return memcpyfast(a2, a3, a4);
}

canonical_decompiled_code:
void *__fastcall func4(int a1, _BYTE *a2, unsigned int *a3, unsigned int a4)
{
int v6; // er12

func3(a2, a4);
v6 = compute_hash_murmur2(a3, a4, (unsigned int)((_DWORD)a2 - a1));
current_hash ^= compute_hash_murmur2(a2, a4, (unsigned int)((_DWORD)a2 - a1)) ^ v6;
return func0(a2, a3, a4);
}

original_code:
void ai_journal(const void* base, const void* dst, const void* src, unsigned int size)
{
  ai_journal_save(dst, size);
  int index0 = (intptr_t)dst - (intptr_t)base;
  current_hash ^= compute_hash_murmur2(src, size, index0) ^ compute_hash_murmur2(dst, size, index0);
  ;
  memcpyfast((void*)dst, src, size);
}

canonical_original_code:
void ai_journal(void *base, void *dst, void *src, unsigned int size)
{
  ai_journal_save(dst, size);
  int index0 = (intptr_t)dst - (intptr_t)base;
  current_hash ^= compute_hash_murmur2(src, size, index0) ^ compute_hash_murmur2(dst, size, index0);
  ;
  memcpyfast((void *)dst, src, size);
}

variable_types:
base
void *


decompiled_code:
__int64 __fastcall rollback_journal(int a1)
{
__int64 result; // rax
char *v2; // rbx

for ( result = (unsigned int)jbuffer_top; jbuffer_top > a1; result = (unsigned int)jbuffer_top )
{
jbuffer_top = result - 1;
v2 = (char *)jbuffer + 24 * (int)result - 24;
rollback_entry((__int64)v2);
dealloc_entry((__int64)v2);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1)
{
__int64 result; // rax
char *v2; // rbx

for ( result = (unsigned int)jbuffer_top; jbuffer_top > a1; result = (unsigned int)jbuffer_top )
{
jbuffer_top = result - 1;
v2 = (char *)jbuffer + 24 * (int)result - 24;
func1((__int64)v2);
func2((__int64)v2);
}
return result;
}

original_code:
void rollback_journal(int top)
{
  while (jbuffer_top > top)
  {
    Journal* j = &jbuffer[--jbuffer_top];
    rollback_entry(j);
    dealloc_entry(j);
  }
}

canonical_original_code:
void rollback_journal(int top)
{
  while (jbuffer_top > top)
  {
    struct Journal *j = &jbuffer[--jbuffer_top];
    rollback_entry(j);
    dealloc_entry(j);
  }
}

variable_types: top int


decompiled_code:
void commit_journal()
{
jbuffer_top = 0;
}

canonical_decompiled_code:
void func6()
{
jbuffer_top = 0;
}


repo: seiferteric/life

decompiled_code:
__int64 __fastcall get_point(int a1, int a2)
{
return (unsigned int)life[800 * a2 + a1];
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1, int a2)
{
return (unsigned int)life[800 * a2 + a1];
}

original_code:
uint32_t get_point(int x, int y) {
  return life[y][x];
}

canonical_original_code:
unsigned int get_point(int x, int y) {
  return life[y][x];
}

variable_types: x int

variable_types: y int

return_type: unsigned int


decompiled_code:
__int64 __fastcall set_point(int a1, int a2, int a3)
{
__int64 result; // rax

result = *(_QWORD *)(srf + 32);
*(_DWORD *)(result + 4LL * (a1 + 800 * a2)) = a3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1, int a2, int a3)
{
__int64 result; // rax

result = *(_QWORD *)(srf + 32);
*(_DWORD *)(result + 4LL * (a1 + 800 * a2)) = a3;
return result;
}

original_code:
void set_point(int x, int y, uint32_t color) {
  *((uint32_t*)srf->pixels + (800*y + x)) = color;
}

canonical_original_code:
void set_point(int x, int y, unsigned int color) {
  *((unsigned int *)srf->pixels + (800*y + x)) = color;
}

variable_types:
color
unsigned int


init

decompiled_code:
__int64 __fastcall init(time_t *a1)
{
unsigned int v1; // eax
int i; // ebp
int j; // ebx

v1 = time(a1);
srand(v1);
SDL_FillRect();
for ( i = 0; i != 800; ++i )
{
for ( j = 0; j != 800; ++j )
{
if ( rand() % 10 == 1 )
set_point(j, i, 65280);
}
}
return SDL_UpdateRect();
}

canonical_decompiled_code:
__int64 __fastcall func9(time_t *a1)
{
unsigned int v1; // eax
int i; // ebp
int j; // ebx

v1 = time(a1);
srand(v1);
SDL_FillRect();
for ( i = 0; i != 800; ++i )
{
for ( j = 0; j != 800; ++j )
{
if ( rand() % 10 == 1 )
func8(j, i, 65280);
}
}
return SDL_UpdateRect();
}


north

decompiled_code:
__int64 __fastcall north(int a1, int a2)
{
__int64 result; // rax

if ( a2 <= 0 )
result = get_point(a1, 799);
else
result = get_point(a1, a2 - 1);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(int a1, int a2)
{
__int64 result; // rax

if ( a2 <= 0 )
result = func7(a1, 799);
else
result = func7(a1, a2 - 1);
return result;
}

original_code:
uint32_t north(int x, int y) {
  if(y > 0)
    return get_point(x, y-1);
  else
    return get_point(x, (800 - 1));
}

canonical_original_code:
unsigned int north(int x, int y) {
  if(y > 0)
    return get_point(x, y-1);
  else
    return get_point(x, (800 - 1));
}


south

decompiled_code:
__int64 __fastcall south(int a1, int a2)
{
__int64 result; // rax

if ( a2 > 798 )
result = get_point(a1, 0);
else
result = get_point(a1, a2 + 1);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(int a1, int a2)
{
__int64 result; // rax

if ( a2 > 798 )
result = func7(a1, 0);
else
result = func7(a1, a2 + 1);
return result;
}

original_code:
uint32_t south(int x, int y) {
  if(y < (800 - 1))
    return get_point(x, y+1);
  else
    return get_point(x, 0);
}

canonical_original_code:
unsigned int south(int x, int y) {
  if(y < (800 - 1))
    return get_point(x, y+1);
  else
    return get_point(x, 0);
}


east

decompiled_code:
__int64 __fastcall east(int a1, int a2)
{
__int64 result; // rax

if ( a1 > 798 )
result = get_point(0, a2);
else
result = get_point(a1 + 1, a2);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(int a1, int a2)
{
__int64 result; // rax

if ( a1 > 798 )
result = func7(0, a2);
else
result = func7(a1 + 1, a2);
return result;
}

original_code:
uint32_t east(int x, int y) {
  if(x < (800 - 1))
    return get_point(x+1, y);
  else
    return get_point(0, y);
}

canonical_original_code:
unsigned int east(int x, int y) {
  if(x < (800 - 1))
    return get_point(x+1, y);
  else
    return get_point(0, y);
}


west

decompiled_code:
__int64 __fastcall west(int a1, int a2)
{
__int64 result; // rax

if ( a1 <= 0 )
result = get_point(799, a2);
else
result = get_point(a1 - 1, a2);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(int a1, int a2)
{
__int64 result; // rax

if ( a1 <= 0 )
result = func7(799, a2);
else
result = func7(a1 - 1, a2);
return result;
}

original_code:
uint32_t west(int x, int y) {
  if(x > 0)
    return get_point(x-1, y);
  else
    return get_point((800 - 1), y);
}

canonical_original_code:
unsigned int west(int x, int y) {
  if(x > 0)
    return get_point(x-1, y);
  else
    return get_point((800 - 1), y);
}


decompiled_code:
__int64 __fastcall north_west(int a1, int a2)
{
int v2; // eax
bool v3; // cc
int v4; // esi
int v5; // eax
int v6; // edi

v2 = a2 - 1;
v3 = a2 <= 0;
v4 = 799;
if ( !v3 )
v4 = v2;
v5 = a1 - 1;
v3 = a1 <= 0;
v6 = 799;
if ( !v3 )
v6 = v5;
return get_point(v6, v4);
}

original_code:
uint32_t north_west(int x, int y) {
  int nx, ny;
  if(y > 0)
    ny = y -1;
  else
    ny = (800 - 1);
  if(x > 0)
    nx = x-1;
  else
    nx = (800 - 1);
  return get_point(nx, ny);
}

canonical_original_code:
unsigned int north_west(int x, int y) {
  int nx; int ny;
  if(y > 0)
    ny = y -1;
  else
    ny = (800 - 1);
  if(x > 0)
    nx = x-1;
  else
    nx = (800 - 1);
  return get_point(nx, ny);
}

variable_types: nx int

variable_types: ny int


decompiled_code:
__int64 __fastcall north_east(int a1, int a2)
{
int v2; // eax
bool v3; // cc
int v4; // esi
int v5; // eax
int v6; // edi

v2 = a2 - 1;
v3 = a2 <= 0;
v4 = 799;
if ( !v3 )
v4 = v2;
v5 = a1 + 1;
v3 = a1 < 799;
v6 = 0;
if ( v3 )
v6 = v5;
return get_point(v6, v4);
}

original_code:
uint32_t north_east(int x, int y) {
  int nx, ny;
  if(y > 0)
    ny = y -1;
  else
    ny = (800 - 1);
  if(x < (800 - 1))
    nx = x+1;
  else
    nx = 0;
  return get_point(nx, ny);
}

canonical_original_code:
unsigned int north_east(int x, int y) {
  int nx; int ny;
  if(y > 0)
    ny = y -1;
  else
    ny = (800 - 1);
  if(x < (800 - 1))
    nx = x+1;
  else
    nx = 0;
  return get_point(nx, ny);
}


decompiled_code:
__int64 __fastcall south_west(int a1, int a2)
{
int v2; // eax
bool v3; // cc
int v4; // esi
int v5; // eax
int v6; // edi

v2 = a2 + 1;
v3 = a2 < 799;
v4 = 0;
if ( v3 )
v4 = v2;
v5 = a1 - 1;
v3 = a1 <= 0;
v6 = 799;
if ( !v3 )
v6 = v5;
return get_point(v6, v4);
}

original_code:
uint32_t south_west(int x, int y) {
  int nx, ny;
  if(y < (800 - 1))
    ny = y + 1;
  else
    ny = 0;
  if(x > 0)
    nx = x-1;
  else
    nx = (800 - 1);
  return get_point(nx, ny);
}

canonical_original_code:
unsigned int south_west(int x, int y) {
  int nx; int ny;
  if(y < (800 - 1))
    ny = y + 1;
  else
    ny = 0;
  if(x > 0)
    nx = x-1;
  else
    nx = (800 - 1);
  return get_point(nx, ny);
}


decompiled_code:
__int64 __fastcall south_east(int a1, int a2)
{
int v2; // eax
bool v3; // cc
int v4; // esi
int v5; // eax
int v6; // edi

v2 = a2 + 1;
v3 = a2 < 799;
v4 = 0;
if ( v3 )
v4 = v2;
v5 = a1 + 1;
v3 = a1 < 799;
v6 = 0;
if ( v3 )
v6 = v5;
return get_point(v6, v4);
}

original_code:
uint32_t south_east(int x, int y) {
  int nx, ny;
  if(y < (800 - 1))
    ny = y + 1;
  else
    ny = 0;
  if(x < (800 - 1))
    nx = x+1;
  else
    nx = 0;
  return get_point(nx, ny);
}

canonical_original_code:
unsigned int south_east(int x, int y) {
  int nx; int ny;
  if(y < (800 - 1))
    ny = y + 1;
  else
    ny = 0;
  if(x < (800 - 1))
    nx = x+1;
  else
    nx = 0;
  return get_point(nx, ny);
}


decompiled_code:
__int64 __fastcall living_neighbours(int a1, int a2)
{
_BOOL4 v2; // ebx
int v3; // ebx
int v4; // ebx
int v5; // ebx
int v6; // ebx
int v7; // ebx
int v8; // ebx

v2 = north_west(a1, a2) != 0;
v3 = v2 - (((unsigned int)north(a1, a2) == 0) - 1);
v4 = v3 - (((unsigned int)north_east(a1, a2) == 0) - 1);
v5 = v4 - (((unsigned int)west(a1, a2) == 0) - 1);
v6 = v5 - (((unsigned int)east(a1, a2) == 0) - 1);
v7 = v6 - (((unsigned int)south_west(a1, a2) == 0) - 1);
v8 = v7 - (((unsigned int)south(a1, a2) == 0) - 1);
return v8 - ((unsigned int)((unsigned int)south_east(a1, a2) == 0) - 1);
}

canonical_decompiled_code:
__int64 __fastcall func18(int a1, int a2)
{
_BOOL4 v2; // ebx
int v3; // ebx
int v4; // ebx
int v5; // ebx
int v6; // ebx
int v7; // ebx
int v8; // ebx

v2 = func14(a1, a2) != 0;
v3 = v2 - (((unsigned int)func10(a1, a2) == 0) - 1);
v4 = v3 - (((unsigned int)func15(a1, a2) == 0) - 1);
v5 = v4 - (((unsigned int)func13(a1, a2) == 0) - 1);
v6 = v5 - (((unsigned int)func12(a1, a2) == 0) - 1);
v7 = v6 - (((unsigned int)func16(a1, a2) == 0) - 1);
v8 = v7 - (((unsigned int)func11(a1, a2) == 0) - 1);
return v8 - ((unsigned int)((unsigned int)func17(a1, a2) == 0) - 1);
}

original_code:
uint32_t living_neighbours(int x, int y) {
  int count = 0;
  if(north_west(x, y))
    count++;
  if(north(x, y))
    count++;
  if(north_east(x, y))
    count++;
  if(west(x, y))
    count++;
  if(east(x, y))
    count++;
  if(south_west(x, y))
    count++;
  if(south(x, y))
    count++;
  if(south_east(x, y))
    count++;
  return count;
}

canonical_original_code:
unsigned int living_neighbours(int x, int y) {
  int count = 0;
  if(north_west(x, y))
    count++;
  if(north(x, y))
    count++;
  if(north_east(x, y))
    count++;
  if(west(x, y))
    count++;
  if(east(x, y))
    count++;
  if(south_west(x, y))
    count++;
  if(south(x, y))
    count++;
  if(south_east(x, y))
    count++;
  return count;
}

variable_types: count int