decompiled_code:
__int64 __fastcall stm_process_event(void *key)
{
bool v2; // zf
__int64 v3; // rax
void (__fastcall *v4)(__int64); // rdx
__int64 v5; // r14
void (__fastcall *v6)(__int64); // rdx
int v8; // er12
__int64 v9; // rdi
void (*v10)(void); // rdx
void (*v11)(void); // rdx
void (*v12)(void); // rdx
__int64 v13; // rbp
__int64 v14; // rdi
void (*v15)(void); // rdx
void (*v16)(void); // rdx
unsigned __int16 *v17; // rbp
const void *v18; // r15
size_t v19; // rcx
__compar_fn_t v20; // r8
_WORD *v21; // rbx
int v22; // [rsp+4h] [rbp-54h]
__int64 v23; // [rsp+8h] [rbp-50h]
unsigned __int16 v24; // [rsp+1Ch] [rbp-3Ch] BYREF
unsigned __int16 v25[29]; // [rsp+1Eh] [rbp-3Ah] BYREF

v23 = *(_QWORD *)(fsmContext + 32);
v2 = (unsigned int)eclib_set_clear(v23) == 0;
v3 = fsmContext;
if ( !v2 )
{
v4 = *(void (__fastcall **)(__int64))(fsmContext + 40);
if ( v4 )
{
v4(6LL);
v3 = fsmContext;
}
}
v5 = *(_QWORD *)(v3 + 24);
if ( (unsigned int)eclib_set_get_usage(v5, &v24) && (v6 = *(void (__fastcall **)(__int64))(fsmContext + 40)) != 0LL )
{
v6(2LL);
if ( !v24 )
return 0xFFFFFFFFLL;
}
else if ( !v24 )
{
return 0xFFFFFFFFLL;
}
v22 = 0;
v8 = 0;
while ( !(unsigned int)eclib_set_get(v5, (unsigned __int16)v8, v25) )
{
v17 = (unsigned __int16 *)stm_find_state(v25[0]);
v18 = (const void *)stm_find_transition(v17[2]);
v21 = bsearch(key, v18, v17[3], v19, v20);
if ( v21 || (v21 = bsearch(&_stm_null_event, v18, v17[3], 0x18uLL, (__compar_fn_t)stm_transition_compare)) != 0LL )
{
v9 = v25[0];
v10 = (void (*)(void))stm_find_action(v25[0], v17[7]);
if ( v10 )
{
v10();
v9 = v25[0];
}
v11 = (void (*)(void))stm_find_action(v9, v17[5]);
if ( v11 )
{
v11();
v9 = v25[0];
}
v12 = (void (*)(void))stm_find_action(v9, v21[9]);
if ( v12 )
v12();
v13 = stm_find_state(v21[8]);
if ( v13 )
{
if ( (unsigned int)eclib_set_add(v23, v21 + 8) )
goto LABEL_28;
v14 = v25[0];
v15 = (void (*)(void))stm_find_action(v25[0], *(_WORD *)(v13 + 8));
if ( v15 )
{
v15();
v14 = v25[0];
}
v16 = (void (*)(void))stm_find_action(v14, *(_WORD *)(v13 + 12));
if ( v16 )
v16();
}
v22 = 1;
if ( v24 <= (unsigned __int16)++v8 )
break;
}
else if ( v24 <= (unsigned __int16)++v8 )
{
break;
}
}
if ( !v22 )
return 0xFFFFFFFFLL;
LABEL_28:
eclib_set_copy(v5, v23);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func10(void *key)
{
bool v2; // zf
__int64 v3; // rax
void (__fastcall *v4)(__int64); // rdx
__int64 v5; // r14
void (__fastcall *v6)(__int64); // rdx
int v8; // er12
__int64 v9; // rdi
void (*v10)(void); // rdx
void (*v11)(void); // rdx
void (*v12)(void); // rdx
__int64 v13; // rbp
__int64 v14; // rdi
void (*v15)(void); // rdx
void (*v16)(void); // rdx
unsigned __int16 *v17; // rbp
const void *v18; // r15
size_t v19; // rcx
__compar_fn_t v20; // r8
_WORD *v21; // rbx
int v22; // [rsp+4h] [rbp-54h]
__int64 v23; // [rsp+8h] [rbp-50h]
unsigned __int16 v24; // [rsp+1Ch] [rbp-3Ch] BYREF
unsigned __int16 v25[29]; // [rsp+1Eh] [rbp-3Ah] BYREF

v23 = *(_QWORD *)(fsmContext + 32);
v2 = (unsigned int)eclib_set_clear(v23) == 0;
v3 = fsmContext;
if ( !v2 )
{
v4 = *(void (__fastcall **)(__int64))(fsmContext + 40);
if ( v4 )
{
v4(6LL);
v3 = fsmContext;
}
}
v5 = *(_QWORD *)(v3 + 24);
if ( (unsigned int)eclib_set_get_usage(v5, &v24) && (v6 = *(void (__fastcall **)(__int64))(fsmContext + 40)) != 0LL )
{
v6(2LL);
if ( !v24 )
return 0xFFFFFFFFLL;
}
else if ( !v24 )
{
return 0xFFFFFFFFLL;
}
v22 = 0;
v8 = 0;
while ( !(unsigned int)eclib_set_get(v5, (unsigned __int16)v8, v25) )
{
v17 = (unsigned __int16 *)func4(v25[0]);
v18 = (const void *)func6(v17[2]);
v21 = bsearch(key, v18, v17[3], v19, v20);
if ( v21 || (v21 = bsearch(&_stm_null_event, v18, v17[3], 0x18uLL, (__compar_fn_t)stm_transition_compare)) != 0LL )
{
v9 = v25[0];
v10 = (void (*)(void))func9(v25[0], v17[7]);
if ( v10 )
{
v10();
v9 = v25[0];
}
v11 = (void (*)(void))func9(v9, v17[5]);
if ( v11 )
{
v11();
v9 = v25[0];
}
v12 = (void (*)(void))func9(v9, v21[9]);
if ( v12 )
v12();
v13 = func4(v21[8]);
if ( v13 )
{
if ( (unsigned int)eclib_set_add(v23, v21 + 8) )
goto LABEL_28;
v14 = v25[0];
v15 = (void (*)(void))func9(v25[0], *(_WORD *)(v13 + 8));
if ( v15 )
{
v15();
v14 = v25[0];
}
v16 = (void (*)(void))func9(v14, *(_WORD *)(v13 + 12));
if ( v16 )
v16();
}
v22 = 1;
if ( v24 <= (unsigned __int16)++v8 )
break;
}
else if ( v24 <= (unsigned __int16)++v8 )
{
break;
}
}
if ( !v22 )
return 0xFFFFFFFFLL;
LABEL_28:
eclib_set_copy(v5, v23);
return 0xFFFFFFFFLL;
}

original_code:
stm_index_t stm_process_event(stm_event_ptr_t eventPtr) {
 stm_index_t result = -1;
 stm_transition_ptr_t transitionPtr;
 stm_state_ptr_t statePtr;
 stm_state_ptr_t newStatePtr;
 stm_transition_ptr_t lookupTransitionPtr;
 stm_action_fn_t action;
 eclib_status_t eStatus = ECLIB_ERROR;
 stm_index_t activeStateCount, activeStateIndex;
 stm_index_t index;
 eclib_set_ptr_t activeStateSetPtr;
 eclib_set_ptr_t workingStateSetPtr;
 int transitionDetectionFlag = 0;
 workingStateSetPtr = fsmContext->workStateListPtr;
 eStatus = eclib_set_clear(workingStateSetPtr);
 if (eStatus != ECLIB_OK) {
  if (fsmContext->errorCallback != ((void *)0)) {
   fsmContext->errorCallback(ECLIB_EMPTY);
  }
 }
 activeStateSetPtr = fsmContext->activeStateIndexListPtr;
 eStatus = eclib_set_get_usage(activeStateSetPtr, &activeStateCount);
 if (ECLIB_OK != eStatus) {
  if (fsmContext->errorCallback != ((void *)0)) {
   fsmContext->errorCallback(ECLIB_ERROR);
  }
 }
 for (index = 0; index < activeStateCount; index ++) {
  eStatus = eclib_set_get(activeStateSetPtr, index, &activeStateIndex);
  if (ECLIB_OK != eStatus) {
   break;
  }
  statePtr = stm_find_state(activeStateIndex);
  transitionPtr = stm_find_transition(statePtr->transitionStartIndex);
  lookupTransitionPtr = bsearch( eventPtr,
          transitionPtr,
          statePtr->transitionCount,
          sizeof(stm_transition_t),
          stm_transition_compare);
  if (0 == lookupTransitionPtr) {
   lookupTransitionPtr = bsearch( &__stm_null_event,
          transitionPtr,
          statePtr->transitionCount,
          sizeof(stm_transition_t),
          stm_transition_compare);
  }
  if (0 != lookupTransitionPtr) {
   transitionDetectionFlag = 1;
   action = stm_find_action(activeStateIndex, statePtr->doEndActionIndex);
   if (0 != action) {
    action();
   }
   action = stm_find_action(activeStateIndex, statePtr->exitActionIndex);
   if (0 != action) {
    action();
   }
   action = stm_find_action(activeStateIndex, lookupTransitionPtr->actionIndex);
   if (0 != action) {
    action();
   }
   newStatePtr = stm_find_state(lookupTransitionPtr->toStateIndex);
   if (0 != newStatePtr) {
    eStatus = eclib_set_add(workingStateSetPtr, &lookupTransitionPtr->toStateIndex);
    if (ECLIB_OK != eStatus) {
     break;
    }
    action = stm_find_action(activeStateIndex, newStatePtr->enterActionIndex);
    if (0 != action) {
     action();
    }
    action = stm_find_action(activeStateIndex, newStatePtr->doStartActionIndex);
    if (0 != action) {
     action();
    }
   }
  }
 }
 if (0 != transitionDetectionFlag) {
  eclib_set_copy(activeStateSetPtr, workingStateSetPtr);
 }
 return result;
}

canonical_original_code:
unsigned short stm_process_event(struct stm_event *eventPtr) {
 unsigned short result = -1;
 struct stm_transition *transitionPtr;
 struct stm_state *statePtr;
 struct stm_state *newStatePtr;
 struct stm_transition *lookupTransitionPtr;
 void (*action)();
 enum eclib_status_enum eStatus = ECLIB_ERROR;
 unsigned short activeStateCount; unsigned short activeStateIndex;
 unsigned short index;
 struct eclib_set_struct *activeStateSetPtr;
 struct eclib_set_struct *workingStateSetPtr;
 int transitionDetectionFlag = 0;
 workingStateSetPtr = fsmContext->workStateListPtr;
 eStatus = eclib_set_clear(workingStateSetPtr);
 if (eStatus != ECLIB_OK) {
  if (fsmContext->errorCallback != ((void *)0)) {
   fsmContext->errorCallback(ECLIB_EMPTY);
  }
 }
 activeStateSetPtr = fsmContext->activeStateIndexListPtr;
 eStatus = eclib_set_get_usage(activeStateSetPtr, &activeStateCount);
 if (ECLIB_OK != eStatus) {
  if (fsmContext->errorCallback != ((void *)0)) {
   fsmContext->errorCallback(ECLIB_ERROR);
  }
 }
 for (index = 0; index < activeStateCount; index ++) {
  eStatus = eclib_set_get(activeStateSetPtr, index, &activeStateIndex);
  if (ECLIB_OK != eStatus) {
   break;
  }
  statePtr = stm_find_state(activeStateIndex);
  transitionPtr = stm_find_transition(statePtr->transitionStartIndex);
  lookupTransitionPtr = bsearch( eventPtr,
          transitionPtr,
          statePtr->transitionCount,
          sizeof(stm_transition_t),
          stm_transition_compare);
  if (0 == lookupTransitionPtr) {
   lookupTransitionPtr = bsearch( &__stm_null_event,
          transitionPtr,
          statePtr->transitionCount,
          sizeof(stm_transition_t),
          stm_transition_compare);
  }
  if (0 != lookupTransitionPtr) {
   transitionDetectionFlag = 1;
   action = stm_find_action(activeStateIndex, statePtr->doEndActionIndex);
   if (0 != action) {
    action();
   }
   action = stm_find_action(activeStateIndex, statePtr->exitActionIndex);
   if (0 != action) {
    action();
   }
   action = stm_find_action(activeStateIndex, lookupTransitionPtr->actionIndex);
   if (0 != action) {
    action();
   }
   newStatePtr = stm_find_state(lookupTransitionPtr->toStateIndex);
   if (0 != newStatePtr) {
    eStatus = eclib_set_add(workingStateSetPtr, &lookupTransitionPtr->toStateIndex);
    if (ECLIB_OK != eStatus) {
     break;
    }
    action = stm_find_action(activeStateIndex, newStatePtr->enterActionIndex);
    if (0 != action) {
     action();
    }
    action = stm_find_action(activeStateIndex, newStatePtr->doStartActionIndex);
    if (0 != action) {
     action();
    }
   }
  }
 }
 if (0 != transitionDetectionFlag) {
  eclib_set_copy(activeStateSetPtr, workingStateSetPtr);
 }
 return result;
}

variable_types:
result
unsigned short

variable_types:
action
void (*)()

variable_types: enum eclib_status_enum { ECLIB_OK=0, ECLIB_INITIALIZED=1, ECLIB_ERROR=2, ECLIB_NULL_POINTER=3, ECLIB_NOT_FULL=4, ECLIB_FULL=5, ECLIB_EMPTY=6, ECLIB_FOUND=7, ECLIB_NOT_FOUND=8, ECLIB_OUT_OF_BOUNDS=9, ECLIB_NOT_IMPLEMENTED=10 }

variable_types:
activeStateCount
unsigned short

variable_types:
activeStateIndex
unsigned short

variable_types:
index
unsigned short

variable_types: struct eclib_set_struct { unsigned short nSignature; unsigned short nUnitSize; unsigned short nCount; unsigned short nUsageCount; unsigned char pBuffer[]; } *

variable_types: transitionDetectionFlag int

return_type: unsigned short


repo: dimitarpeikov/eclib

decompiled_code:
__int16 __fastcall eclib_queue_head_inc(__int64 a1)
{
__int16 result; // ax

result = (unsigned __int16)(*(_WORD *)(a1 + 4) + 1) / *(_WORD *)(a1 + 10);
*(_WORD *)(a1 + 4) = (unsigned __int16)(*(_WORD *)(a1 + 4) + 1) % *(_WORD *)(a1 + 10);
return result;
}

original_code:
static void eclib_queue_head_inc( eclib_queue_t * pQueue )
{
 pQueue->nHeadIndex ++;
 pQueue->nHeadIndex %= pQueue->nUnits;
}

canonical_original_code:
static void eclib_queue_head_inc(struct eclib_queue_struct *pQueue)
{
 pQueue->nHeadIndex ++;
 pQueue->nHeadIndex %= pQueue->nUnits;
}

variable_types: struct eclib_queue_struct { enum eclib_signature_enum { ECLIB_SIGNATURE_EMPTY=0, ECLIB_SIGNATURE_QUEUE=4660, ECLIB_SIGNATURE_ARRAY=9029, ECLIB_SIGNATURE_SET=13398, ECLIB_SIGNATURE_BUTTON=17767 } eSignature; unsigned short nHeadIndex; unsigned short nTailIndex; unsigned short nSize; unsigned short nUnits; void *pBuffer; unsigned char nIsFull; } *

return_type: void

user_defined_types: struct eclib_queue_struct { enum eclib_signature_enum eSignature; unsigned short nHeadIndex; unsigned short nTailIndex; unsigned short nSize; unsigned short nUnits; void *pBuffer; unsigned char nIsFull; }


decompiled_code:
__int16 __fastcall eclib_queue_tail_inc(__int64 a1)
{
__int16 result; // ax

result = (unsigned __int16)(*(_WORD *)(a1 + 6) + 1) / *(_WORD *)(a1 + 10);
*(_WORD *)(a1 + 6) = (unsigned __int16)(*(_WORD *)(a1 + 6) + 1) % *(_WORD *)(a1 + 10);
return result;
}

original_code:
static void eclib_queue_tail_inc( eclib_queue_t * pQueue )
{
 pQueue->nTailIndex ++;
 pQueue->nTailIndex %= pQueue->nUnits;
}

canonical_original_code:
static void eclib_queue_tail_inc(struct eclib_queue_struct *pQueue)
{
 pQueue->nTailIndex ++;
 pQueue->nTailIndex %= pQueue->nUnits;
}

user_defined_types: enum eclib_signature_enum { ECLIB_SIGNATURE_EMPTY=0, ECLIB_SIGNATURE_QUEUE=4660, ECLIB_SIGNATURE_ARRAY=9029, ECLIB_SIGNATURE_SET=13398, ECLIB_SIGNATURE_BUTTON=17767 }


decompiled_code:
__int64 eclib_queue_version()
{
return 256LL;
}

canonical_decompiled_code:
__int64 func2()
{
return 256LL;
}

original_code:
uint32_t eclib_queue_version() {
 return 0x0100;
}

canonical_original_code:
unsigned int eclib_queue_version() {
 return 0x0100;
}

return_type: unsigned int


original_code:
eclib_status_t eclib_queue_init( eclib_queue_t * pQueue, void * pBuffer, uint16_t nSize, uint16_t nUnits )
{
 eclib_status_t eStatus = ECLIB_NULL_POINTER;
 if ( ((void *)0) != pQueue )
 {
  if ( ((void *)0) != pBuffer )
  {
   pQueue->nHeadIndex = 0;
   pQueue->nTailIndex = 0;
   pQueue->nUnits = nUnits;
   pQueue->nSize = nSize;
   pQueue->pBuffer = pBuffer;
   pQueue->nIsFull = 0;
   pQueue->eSignature = ECLIB_SIGNATURE_QUEUE;
   eStatus = ECLIB_OK;
  } else {
   pQueue->eSignature = ECLIB_SIGNATURE_EMPTY;
  }
 } else {
 }
 return eStatus;
}

canonical_original_code:
enum eclib_status_enum eclib_queue_init(struct eclib_queue_struct *pQueue, void *pBuffer, unsigned short nSize, unsigned short nUnits)
{
 enum eclib_status_enum eStatus = ECLIB_NULL_POINTER;
 if ( ((void *)0) != pQueue )
 {
  if ( ((void *)0) != pBuffer )
  {
   pQueue->nHeadIndex = 0;
   pQueue->nTailIndex = 0;
   pQueue->nUnits = nUnits;
   pQueue->nSize = nSize;
   pQueue->pBuffer = pBuffer;
   pQueue->nIsFull = 0;
   pQueue->eSignature = ECLIB_SIGNATURE_QUEUE;
   eStatus = ECLIB_OK;
  } else {
   pQueue->eSignature = ECLIB_SIGNATURE_EMPTY;
  }
 } else {
 }
 return eStatus;
}

variable_types:
pBuffer
void *

variable_types:
nSize
unsigned short

variable_types:
nUnits
unsigned short

return_type: enum eclib_status_enum { ECLIB_OK=0, ECLIB_INITIALIZED=1, ECLIB_ERROR=2, ECLIB_NULL_POINTER=3, ECLIB_NOT_FULL=4, ECLIB_FULL=5, ECLIB_EMPTY=6, ECLIB_FOUND=7, ECLIB_NOT_FOUND=8, ECLIB_OUT_OF_BOUNDS=9, ECLIB_NOT_IMPLEMENTED=10 }


decompiled_code:
__int64 __fastcall eclib_queue_clear(__int64 a1)
{
__int64 result; // rax

if ( !a1 )
return 3LL;
*(_DWORD *)(a1 + 4) = 0;
result = 0LL;
*(_BYTE *)(a1 + 24) = 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
__int64 result; // rax

if ( !a1 )
return 3LL;
*(_DWORD *)(a1 + 4) = 0;
result = 0LL;
*(_BYTE *)(a1 + 24) = 0;
return result;
}

original_code:
eclib_status_t eclib_queue_clear( eclib_queue_t * pQueue )
{
 eclib_status_t eStatus = ECLIB_NULL_POINTER;
 if ( ((void *)0) != pQueue )
 {
  pQueue->nHeadIndex = 0;
  pQueue->nTailIndex = 0;
  pQueue->nIsFull = 0;
  eStatus = ECLIB_OK;
 }
 return eStatus;
}

canonical_original_code:
enum eclib_status_enum eclib_queue_clear(struct eclib_queue_struct *pQueue)
{
 enum eclib_status_enum eStatus = ECLIB_NULL_POINTER;
 if ( ((void *)0) != pQueue )
 {
  pQueue->nHeadIndex = 0;
  pQueue->nTailIndex = 0;
  pQueue->nIsFull = 0;
  eStatus = ECLIB_OK;
 }
 return eStatus;
}

user_defined_types: enum eclib_status_enum { ECLIB_OK=0, ECLIB_INITIALIZED=1, ECLIB_ERROR=2, ECLIB_NULL_POINTER=3, ECLIB_NOT_FULL=4, ECLIB_FULL=5, ECLIB_EMPTY=6, ECLIB_FOUND=7, ECLIB_NOT_FOUND=8, ECLIB_OUT_OF_BOUNDS=9, ECLIB_NOT_IMPLEMENTED=10 }


decompiled_code:
__int64 __fastcall eclib_queue_full(__int64 a1)
{
__int64 result; // rax

if ( !a1 )
return 3LL;
*(_DWORD *)(a1 + 4) = 0;
result = 0LL;
*(_BYTE *)(a1 + 24) = 5;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
__int64 result; // rax

if ( !a1 )
return 3LL;
*(_DWORD *)(a1 + 4) = 0;
result = 0LL;
*(_BYTE *)(a1 + 24) = 5;
return result;
}

original_code:
eclib_status_t eclib_queue_full( eclib_queue_t * pQueue )
{
 eclib_status_t eStatus = ECLIB_NULL_POINTER;
 if ( ((void *)0) != pQueue )
 {
  pQueue->nHeadIndex = 0;
  pQueue->nTailIndex = 0;
  pQueue->nIsFull = ECLIB_FULL;
  eStatus = ECLIB_OK;
 }
 return eStatus;
}

canonical_original_code:
enum eclib_status_enum eclib_queue_full(struct eclib_queue_struct *pQueue)
{
 enum eclib_status_enum eStatus = ECLIB_NULL_POINTER;
 if ( ((void *)0) != pQueue )
 {
  pQueue->nHeadIndex = 0;
  pQueue->nTailIndex = 0;
  pQueue->nIsFull = ECLIB_FULL;
  eStatus = ECLIB_OK;
 }
 return eStatus;
}


decompiled_code:
__int64 __fastcall eclib_queue_is_empty(__int64 a1)
{
__int64 result; // rax

if ( !a1 )
return 3LL;
result = 0LL;
if ( !*(_BYTE *)(a1 + 24) && *(_WORD *)(a1 + 4) == *(_WORD *)(a1 + 6) )
result = 6LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
__int64 result; // rax

if ( !a1 )
return 3LL;
result = 0LL;
if ( !*(_BYTE *)(a1 + 24) && *(_WORD *)(a1 + 4) == *(_WORD *)(a1 + 6) )
result = 6LL;
return result;
}

original_code:
eclib_status_t eclib_queue_is_empty( eclib_queue_t * pQueue )
{
 eclib_status_t eStatus = ECLIB_NULL_POINTER;
 if ( ((void *)0) != pQueue )
 {
  if ( 0 == pQueue->nIsFull )
  {
   eStatus = (pQueue->nHeadIndex == pQueue->nTailIndex) ? ECLIB_EMPTY : ECLIB_OK ;
  } else {
   eStatus = ECLIB_OK;
  }
 }
 return eStatus;
}

canonical_original_code:
enum eclib_status_enum eclib_queue_is_empty(struct eclib_queue_struct *pQueue)
{
 enum eclib_status_enum eStatus = ECLIB_NULL_POINTER;
 if ( ((void *)0) != pQueue )
 {
  if ( 0 == pQueue->nIsFull )
  {
   eStatus = (pQueue->nHeadIndex == pQueue->nTailIndex) ? ECLIB_EMPTY : ECLIB_OK ;
  } else {
   eStatus = ECLIB_OK;
  }
 }
 return eStatus;
}


decompiled_code:
__int64 __fastcall eclib_queue_is_full(__int64 a1)
{
__int64 result; // rax

if ( a1 )
result = *(_BYTE *)(a1 + 24) != 0 ? 5 : 0;
else
result = 3LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
__int64 result; // rax

if ( a1 )
result = *(_BYTE *)(a1 + 24) != 0 ? 5 : 0;
else
result = 3LL;
return result;
}

original_code:
eclib_status_t eclib_queue_is_full( eclib_queue_t * pQueue )
{
 eclib_status_t eStatus = ECLIB_NULL_POINTER;
 if ( ((void *)0) != pQueue )
 {
  eStatus = ( 0 == pQueue->nIsFull ) ? ECLIB_OK : ECLIB_FULL;
 }
 return eStatus;
}

canonical_original_code:
enum eclib_status_enum eclib_queue_is_full(struct eclib_queue_struct *pQueue)
{
 enum eclib_status_enum eStatus = ECLIB_NULL_POINTER;
 if ( ((void *)0) != pQueue )
 {
  eStatus = ( 0 == pQueue->nIsFull ) ? ECLIB_OK : ECLIB_FULL;
 }
 return eStatus;
}


decompiled_code:
__int64 __fastcall eclib_queue_push(__int64 a1, const void *a2)
{
__int64 result; // rax

result = eclib_queue_is_full(a1);
if ( (_DWORD)result != 5 )
{
result = 3LL;
if ( a2 )
{
memcpy(
(void *)(*(_QWORD *)(a1 + 16) + *(unsigned __int16 *)(a1 + 8) * *(unsigned __int16 *)(a1 + 4)),
a2,
*(unsigned __int16 *)(a1 + 8));
eclib_queue_head_inc(a1);
result = 0LL;
if ( *(_WORD *)(a1 + 4) == *(_WORD *)(a1 + 6) )
*(_BYTE *)(a1 + 24) = 5;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, const void *a2)
{
__int64 result; // rax

result = func7(a1);
if ( (_DWORD)result != 5 )
{
result = 3LL;
if ( a2 )
{
memcpy(
(void *)(*(_QWORD *)(a1 + 16) + *(unsigned __int16 *)(a1 + 8) * *(unsigned __int16 *)(a1 + 4)),
a2,
*(unsigned __int16 *)(a1 + 8));
func0(a1);
result = 0LL;
if ( *(_WORD *)(a1 + 4) == *(_WORD *)(a1 + 6) )
*(_BYTE *)(a1 + 24) = 5;
}
}
return result;
}

original_code:
eclib_status_t eclib_queue_push( eclib_queue_t * pQueue, void * pData )
{
 eclib_status_t eStatus;
 eStatus = eclib_queue_is_full( pQueue );
 if ( ECLIB_FULL != eStatus )
 {
  if ( ((void *)0) != pData )
  {
   memcpy( ((uint8_t *)pQueue->pBuffer) + pQueue->nSize * pQueue->nHeadIndex, pData, pQueue->nSize );
   eclib_queue_head_inc( pQueue );
   if ( pQueue->nHeadIndex == pQueue->nTailIndex )
   {
    pQueue->nIsFull = ECLIB_FULL;
   }
   eStatus = ECLIB_OK;
  } else {
   eStatus = ECLIB_NULL_POINTER;
  }
 }
 return eStatus;
}

canonical_original_code:
enum eclib_status_enum eclib_queue_push(struct eclib_queue_struct *pQueue, void *pData)
{
 enum eclib_status_enum eStatus;
 eStatus = eclib_queue_is_full( pQueue );
 if ( ECLIB_FULL != eStatus )
 {
  if ( ((void *)0) != pData )
  {
   memcpy( ((unsigned char *)pQueue->pBuffer) + pQueue->nSize * pQueue->nHeadIndex, pData, pQueue->nSize );
   eclib_queue_head_inc( pQueue );
   if ( pQueue->nHeadIndex == pQueue->nTailIndex )
   {
    pQueue->nIsFull = ECLIB_FULL;
   }
   eStatus = ECLIB_OK;
  } else {
   eStatus = ECLIB_NULL_POINTER;
  }
 }
 return eStatus;
}

variable_types:
pData
void *


decompiled_code:
__int64 __fastcall eclib_queue_pop(__int64 a1, void *a2)
{
unsigned int v2; // er12

v2 = eclib_queue_is_empty(a1);
if ( v2 == 6 )
return v2;
if ( a2 )
{
memcpy(
a2,
(const void *)(*(_QWORD *)(a1 + 16) + *(unsigned __int16 *)(a1 + 8) * *(unsigned __int16 *)(a1 + 6)),
*(unsigned __int16 *)(a1 + 8));
eclib_queue_tail_inc(a1);
if ( *(_BYTE *)(a1 + 24) )
*(_BYTE *)(a1 + 24) = 0;
return v2;
}
return 3LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, void *a2)
{
unsigned int v2; // er12

v2 = func6(a1);
if ( v2 == 6 )
return v2;
if ( a2 )
{
memcpy(
a2,
(const void *)(*(_QWORD *)(a1 + 16) + *(unsigned __int16 *)(a1 + 8) * *(unsigned __int16 *)(a1 + 6)),
*(unsigned __int16 *)(a1 + 8));
func1(a1);
if ( *(_BYTE *)(a1 + 24) )
*(_BYTE *)(a1 + 24) = 0;
return v2;
}
return 3LL;
}

original_code:
eclib_status_t eclib_queue_pop( eclib_queue_t * pQueue, void * pData )
{
 eclib_status_t eStatus;
 eStatus = eclib_queue_is_empty( pQueue );
 if ( ECLIB_EMPTY != eStatus )
 {
  if ( ((void *)0) != pData )
  {
   memcpy( pData, ((uint8_t *)pQueue->pBuffer) + pQueue->nSize * pQueue->nTailIndex, pQueue->nSize );
   eclib_queue_tail_inc( pQueue );
   if ( 0 != pQueue->nIsFull )
   {
    pQueue->nIsFull = 0;
   }
  } else {
   eStatus = ECLIB_NULL_POINTER;
  }
 }
 return eStatus;
}

canonical_original_code:
enum eclib_status_enum eclib_queue_pop(struct eclib_queue_struct *pQueue, void *pData)
{
 enum eclib_status_enum eStatus;
 eStatus = eclib_queue_is_empty( pQueue );
 if ( ECLIB_EMPTY != eStatus )
 {
  if ( ((void *)0) != pData )
  {
   memcpy( pData, ((unsigned char *)pQueue->pBuffer) + pQueue->nSize * pQueue->nTailIndex, pQueue->nSize );
   eclib_queue_tail_inc( pQueue );
   if ( 0 != pQueue->nIsFull )
   {
    pQueue->nIsFull = 0;
   }
  } else {
   eStatus = ECLIB_NULL_POINTER;
  }
 }
 return eStatus;
}


decompiled_code:
__int64 __fastcall eclib_queue_peek(__int64 a1, void *a2)
{
unsigned int v2; // er12

v2 = eclib_queue_is_empty(a1);
if ( v2 == 6 )
return v2;
if ( a2 )
{
memcpy(
a2,
(const void *)(*(_QWORD *)(a1 + 16) + *(unsigned __int16 *)(a1 + 8) * *(unsigned __int16 *)(a1 + 6)),
*(unsigned __int16 *)(a1 + 8));
if ( *(_BYTE *)(a1 + 24) )
*(_BYTE *)(a1 + 24) = 0;
return v2;
}
return 3LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, void *a2)
{
unsigned int v2; // er12

v2 = func6(a1);
if ( v2 == 6 )
return v2;
if ( a2 )
{
memcpy(
a2,
(const void *)(*(_QWORD *)(a1 + 16) + *(unsigned __int16 *)(a1 + 8) * *(unsigned __int16 *)(a1 + 6)),
*(unsigned __int16 *)(a1 + 8));
if ( *(_BYTE *)(a1 + 24) )
*(_BYTE *)(a1 + 24) = 0;
return v2;
}
return 3LL;
}

original_code:
eclib_status_t eclib_queue_peek( eclib_queue_t * pQueue, void * pData )
{
 eclib_status_t eStatus;
 eStatus = eclib_queue_is_empty( pQueue );
 if ( ECLIB_EMPTY != eStatus )
 {
  if ( ((void *)0) != pData )
  {
   memcpy( pData, ((uint8_t *)pQueue->pBuffer) + pQueue->nSize * pQueue->nTailIndex, pQueue->nSize );
   if ( 0 != pQueue->nIsFull )
   {
    pQueue->nIsFull = 0;
   }
  } else {
   eStatus = ECLIB_NULL_POINTER;
  }
 }
 return eStatus;
}

canonical_original_code:
enum eclib_status_enum eclib_queue_peek(struct eclib_queue_struct *pQueue, void *pData)
{
 enum eclib_status_enum eStatus;
 eStatus = eclib_queue_is_empty( pQueue );
 if ( ECLIB_EMPTY != eStatus )
 {
  if ( ((void *)0) != pData )
  {
   memcpy( pData, ((unsigned char *)pQueue->pBuffer) + pQueue->nSize * pQueue->nTailIndex, pQueue->nSize );
   if ( 0 != pQueue->nIsFull )
   {
    pQueue->nIsFull = 0;
   }
  } else {
   eStatus = ECLIB_NULL_POINTER;
  }
 }
 return eStatus;
}


decompiled_code:
__int64 __fastcall eclib_queue_get_queue_size(__int64 a1)
{
return *(unsigned __int16 *)(a1 + 10);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
return *(unsigned __int16 *)(a1 + 10);
}

original_code:
uint16_t eclib_queue_get_queue_size(eclib_queue_ptr_t pQueue) {
  return pQueue->nUnits;
}

canonical_original_code:
unsigned short eclib_queue_get_queue_size(struct eclib_queue_struct *pQueue) {
  return pQueue->nUnits;
}


decompiled_code:
__int16 __fastcall eclib_queue_get_usage(_WORD *a1)
{
__int16 result; // ax

result = a1[2] - a1[3];
if ( result < 0 )
result += a1[5];
return result;
}

canonical_decompiled_code:
__int16 __fastcall func12(_WORD *a1)
{
__int16 result; // ax

result = a1[2] - a1[3];
if ( result < 0 )
result += a1[5];
return result;
}

original_code:
uint16_t eclib_queue_get_usage(eclib_queue_ptr_t pQueue) {
  int16_t size = pQueue->nHeadIndex - pQueue->nTailIndex;
  if (size < 0) {
    size += pQueue->nUnits;
  }
  return size;
}

canonical_original_code:
unsigned short eclib_queue_get_usage(struct eclib_queue_struct *pQueue) {
  short size = pQueue->nHeadIndex - pQueue->nTailIndex;
  if (size < 0) {
    size += pQueue->nUnits;
  }
  return size;
}

variable_types: size short


decompiled_code:
__int64 __fastcall eclib_queue_get_head_index(__int64 a1)
{
return *(unsigned __int16 *)(a1 + 4);
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1)
{
return *(unsigned __int16 *)(a1 + 4);
}

original_code:
uint16_t eclib_queue_get_head_index(eclib_queue_ptr_t pQueue) {
  return pQueue->nHeadIndex;
}

canonical_original_code:
unsigned short eclib_queue_get_head_index(struct eclib_queue_struct *pQueue) {
  return pQueue->nHeadIndex;
}


decompiled_code:
__int64 __fastcall eclib_queue_get_tail_index(__int64 a1)
{
return *(unsigned __int16 *)(a1 + 6);
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1)
{
return *(unsigned __int16 *)(a1 + 6);
}

original_code:
uint16_t eclib_queue_get_tail_index(eclib_queue_ptr_t pQueue) {
  return pQueue->nTailIndex;
}

canonical_original_code:
unsigned short eclib_queue_get_tail_index(struct eclib_queue_struct *pQueue) {
  return pQueue->nTailIndex;
}


decompiled_code:
__int64 eclib_array_version()
{
return 256LL;
}

canonical_decompiled_code:
__int64 func0()
{
return 256LL;
}

original_code:
uint32_t eclib_array_version() {
 return 0x0100;
}

canonical_original_code:
unsigned int eclib_array_version() {
 return 0x0100;
}


decompiled_code:
__int64 __fastcall eclib_array_init(__int64 a1, __int64 a2, __int16 a3, __int16 a4)
{
__int64 result; // rax

if ( !a1 || !a2 )
return 3LL;
*(_WORD *)(a1 + 4) = a4;
*(_WORD *)a1 = 9029;
result = 0LL;
*(_WORD *)(a1 + 2) = a3;
*(_QWORD *)(a1 + 16) = a2;
return result;
}

original_code:
eclib_status_t eclib_array_init( eclib_array_t * pArray, void * pBuffer, uint16_t nUnits, uint16_t nSize )
{
 eclib_status_t eStatus = ECLIB_NULL_POINTER;
 if ( ((void *)0) != pArray )
 {
  if ( ((void *)0) != pBuffer )
  {
   eStatus = ECLIB_OK;
   pArray->nSize = nSize;
   pArray->nUnits = nUnits;
   pArray->pBuffer = pBuffer;
   pArray->nSignature = ECLIB_SIGNATURE_ARRAY;
  } else {
  }
 } else {
 }
 return eStatus;
}

canonical_original_code:
enum eclib_status_enum eclib_array_init(struct eclib_array_struct *pArray, void *pBuffer, unsigned short nUnits, unsigned short nSize)
{
 enum eclib_status_enum eStatus = ECLIB_NULL_POINTER;
 if ( ((void *)0) != pArray )
 {
  if ( ((void *)0) != pBuffer )
  {
   eStatus = ECLIB_OK;
   pArray->nSize = nSize;
   pArray->nUnits = nUnits;
   pArray->pBuffer = pBuffer;
   pArray->nSignature = ECLIB_SIGNATURE_ARRAY;
  } else {
  }
 } else {
 }
 return eStatus;
}

variable_types: struct eclib_array_struct { unsigned short nSignature; unsigned short nUnits; unsigned short nSize; unsigned char *pBitmap; void *pBuffer; } *


original_code:
eclib_status_t eclib_array_find( eclib_array_ptr_t pArray, void * pData, uint16_t * pIndex) {
 eclib_status_t eStatus = ECLIB_ERROR;
 uint16_t nIndex;
 uint16_t nMaxIndex;
 uint8_t nIdx;
 uint8_t nBitIndex;
 uint8_t nMaxBitIndex;
 if (( ((void *)0) != pArray ) || (((void *)0) != pData))
 {
  nMaxIndex = ( pArray->nUnits + 7 ) / 8;
  for ( nIndex = 0; nIndex < nMaxIndex; nIndex ++ )
  {
   if ( 0x00 != pArray->pBitmap[ nIndex ] )
   {
    nMaxBitIndex = ((nIndex + 1) * 8 > pArray->nUnits) ? (pArray->nUnits - nIndex * 8) : 8;
    nIdx = pArray->pBitmap[ nIndex ];
    for ( nBitIndex = 0; nBitIndex < nMaxBitIndex; nBitIndex ++ )
    {
     if ( 1 == ( nIdx & ( 1 << nBitIndex )) )
     {
      if (0 == memcmp( ((uint8_t *) pArray->pBuffer) + pArray->nSize * ( nIndex * 8 + nBitIndex ), pData, pArray->nSize )) {
       eStatus = ECLIB_OK;
       if (pIndex != 0) {
        *pIndex = nIndex;
       }
       break;
      }
     }
    }
    if (ECLIB_OK == eStatus) {
     break;
    }
   }
  }
 } else {
  eStatus = ECLIB_NULL_POINTER;
 }
 return eStatus;
}

canonical_original_code:
enum eclib_status_enum eclib_array_find(struct eclib_array_struct *pArray, void *pData, unsigned short *pIndex) {
 enum eclib_status_enum eStatus = ECLIB_ERROR;
 unsigned short nIndex;
 unsigned short nMaxIndex;
 unsigned char nIdx;
 unsigned char nBitIndex;
 unsigned char nMaxBitIndex;
 if (( ((void *)0) != pArray ) || (((void *)0) != pData))
 {
  nMaxIndex = ( pArray->nUnits + 7 ) / 8;
  for ( nIndex = 0; nIndex < nMaxIndex; nIndex ++ )
  {
   if ( 0x00 != pArray->pBitmap[ nIndex ] )
   {
    nMaxBitIndex = ((nIndex + 1) * 8 > pArray->nUnits) ? (pArray->nUnits - nIndex * 8) : 8;
    nIdx = pArray->pBitmap[ nIndex ];
    for ( nBitIndex = 0; nBitIndex < nMaxBitIndex; nBitIndex ++ )
    {
     if ( 1 == ( nIdx & ( 1 << nBitIndex )) )
     {
      if (0 == memcmp( ((unsigned char *) pArray->pBuffer) + pArray->nSize * ( nIndex * 8 + nBitIndex ), pData, pArray->nSize )) {
       eStatus = ECLIB_OK;
       if (pIndex != 0) {
        *pIndex = nIndex;
       }
       break;
      }
     }
    }
    if (ECLIB_OK == eStatus) {
     break;
    }
   }
  }
 } else {
  eStatus = ECLIB_NULL_POINTER;
 }
 return eStatus;
}

variable_types:
pIndex
unsigned short *

variable_types:
nIndex
unsigned short

variable_types:
nMaxIndex
unsigned short

variable_types:
nIdx
unsigned char

variable_types:
nBitIndex
unsigned char

variable_types:
nMaxBitIndex
unsigned char

user_defined_types: struct eclib_array_struct { unsigned short nSignature; unsigned short nUnits; unsigned short nSize; unsigned char *pBitmap; void *pBuffer; }


decompiled_code:
__int64 __fastcall eclib_array_add(__int128 a1, _WORD *a2)
{
__int64 v2; // r14
__int64 result; // rax
int v4; // er9
__int16 v5; // r8
int v6; // edi
__int64 v8; // rbx
unsigned __int8 v9; // al
unsigned __int8 v10; // dl
int v11; // edi
int v12; // eax
unsigned int v13; // ecx
int v14; // er13

v2 = a1;
result = 3LL;
if ( a1 == 0 )
return result;
v4 = *(unsigned __int16 *)(a1 + 2);
v5 = *(_WORD *)(a1 + 2);
v6 = (v4 + 7) >> 3;
if ( !v6 )
return 2LL;
v8 = 0LL;
while ( 1 )
{
v9 = *(_BYTE *)(*(_QWORD *)(v2 + 8) + v8);
if ( v9 != 0xFF )
break;
if ( (unsigned __int16)v6 <= (unsigned __int16)++v8 )
return 2LL;
}
if ( v4 < 8 * (unsigned __int16)(v8 + 1) )
{
v10 = v5 - 8 * v8;
if ( (_BYTE)v5 != 8 * (_BYTE)v8 )
goto LABEL_8;
return 2LL;
}
v10 = 8;
LABEL_8:
v11 = v9;
if ( (v9 & 1) != 0 )
{
v12 = 1;
while ( v10 > (unsigned __int8)v12 )
{
v13 = v12++;
if ( !_bittest(&v11, v13) )
{
v14 = 1 << v13;
goto LABEL_17;
}
}
return 2LL;
}
LOBYTE(v14) = 1;
v13 = 0;
LABEL_17:
memcpy(
(void *)(*(_QWORD *)(v2 + 16) + (int)(*(unsigned __int16 *)(v2 + 4) * (v13 + 8 * (unsigned __int16)v8))),
*((const void **)&a1 + 1),
*(unsigned __int16 *)(v2 + 4));
result = 0LL;
*(_BYTE *)(*(_QWORD *)(v2 + 8) + v8) |= v14;
if ( a2 )
*a2 = v8;
return result;
}

original_code:
eclib_status_t eclib_array_add( eclib_array_t * pArray, void * pData, uint16_t * pIndex )
{
 eclib_status_t eStatus = ECLIB_ERROR;
 uint16_t nIndex;
 uint16_t nMaxIndex;
 uint8_t nIdx;
 uint8_t nBitIndex;
 uint8_t nMaxBitIndex;
 if (( ((void *)0) != pArray ) || (((void *)0) != pData))
 {
  nMaxIndex = ( pArray->nUnits + 7 ) / 8;
  for ( nIndex = 0; nIndex < nMaxIndex; nIndex ++ )
  {
   if ( 0xFF != pArray->pBitmap[ nIndex ] )
   {
    nMaxBitIndex = ((nIndex + 1) * 8 > pArray->nUnits) ? (pArray->nUnits - nIndex * 8) : 8;
    nIdx = pArray->pBitmap[ nIndex ];
    for ( nBitIndex = 0; nBitIndex < nMaxBitIndex; nBitIndex ++ )
    {
     if ( 0 == ( nIdx & ( 1 << nBitIndex )) )
     {
      memcpy( ((uint8_t *) pArray->pBuffer) + pArray->nSize * ( nIndex * 8 + nBitIndex ), pData, pArray->nSize );
      pArray->pBitmap[ nIndex ] |= 1 << nBitIndex;
      if (pIndex != 0) {
       *pIndex = nIndex;
      }
      eStatus = ECLIB_OK;
      break;
     }
    }
    break;
   }
  }
 } else {
  eStatus = ECLIB_NULL_POINTER;
 }
 return eStatus;
}

canonical_original_code:
enum eclib_status_enum eclib_array_add(struct eclib_array_struct *pArray, void *pData, unsigned short *pIndex)
{
 enum eclib_status_enum eStatus = ECLIB_ERROR;
 unsigned short nIndex;
 unsigned short nMaxIndex;
 unsigned char nIdx;
 unsigned char nBitIndex;
 unsigned char nMaxBitIndex;
 if (( ((void *)0) != pArray ) || (((void *)0) != pData))
 {
  nMaxIndex = ( pArray->nUnits + 7 ) / 8;
  for ( nIndex = 0; nIndex < nMaxIndex; nIndex ++ )
  {
   if ( 0xFF != pArray->pBitmap[ nIndex ] )
   {
    nMaxBitIndex = ((nIndex + 1) * 8 > pArray->nUnits) ? (pArray->nUnits - nIndex * 8) : 8;
    nIdx = pArray->pBitmap[ nIndex ];
    for ( nBitIndex = 0; nBitIndex < nMaxBitIndex; nBitIndex ++ )
    {
     if ( 0 == ( nIdx & ( 1 << nBitIndex )) )
     {
      memcpy( ((unsigned char *) pArray->pBuffer) + pArray->nSize * ( nIndex * 8 + nBitIndex ), pData, pArray->nSize );
      pArray->pBitmap[ nIndex ] |= 1 << nBitIndex;
      if (pIndex != 0) {
       *pIndex = nIndex;
      }
      eStatus = ECLIB_OK;
      break;
     }
    }
    break;
   }
  }
 } else {
  eStatus = ECLIB_NULL_POINTER;
 }
 return eStatus;
}

variable_types: enum eclib_status_enum { ECLIB_OK=0, ECLIB_INITIALIZED=1, ECLIB_ERROR=2, ECLIB_NULL_POINTER=3, ECLIB_NOT_FULL=4, ECLIB_FULL=5, ECLIB_EMPTY=6, ECLIB_FOUND=7, ECLIB_NOT_FOUND=8, ECLIB_OUT_OF_BOUNDS=9, ECLIB_NOT_IMPLEMENTED=10 }


decompiled_code:
__int64 __fastcall eclib_array_get(__int64 a1, unsigned __int16 a2, unsigned __int64 a3)
{
__int64 result; // rax
int v4; // ecx

result = 3LL;
if ( a3 | a1 )
{
v4 = *(unsigned __int8 *)(*(_QWORD *)(a1 + 8) + (a2 >> 3));
result = 2LL;
if ( _bittest(&v4, a2 & 7) )
{
memcpy(
(void *)a3,
(const void *)(*(_QWORD *)(a1 + 16) + *(unsigned __int16 *)(a1 + 4) * a2),
*(unsigned __int16 *)(a1 + 4));
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, unsigned __int16 a2, unsigned __int64 a3)
{
__int64 result; // rax
int v4; // ecx

result = 3LL;
if ( a3 | a1 )
{
v4 = *(unsigned __int8 *)(*(_QWORD *)(a1 + 8) + (a2 >> 3));
result = 2LL;
if ( _bittest(&v4, a2 & 7) )
{
memcpy(
(void *)a3,
(const void *)(*(_QWORD *)(a1 + 16) + *(unsigned __int16 *)(a1 + 4) * a2),
*(unsigned __int16 *)(a1 + 4));
result = 0LL;
}
}
return result;
}

original_code:
eclib_status_t eclib_array_get( eclib_array_t * pArray, uint16_t nIndex, void * pData )
{
 eclib_status_t eStatus = ECLIB_ERROR;
 if (( ((void *)0) != pArray ) || (((void *)0) != pData))
 {
  if ( 0 != (pArray->pBitmap[ nIndex / 8 ] & (1 << (nIndex & 7) )) )
  {
   memcpy( pData, ((uint8_t *)pArray->pBuffer) + pArray->nSize * nIndex, pArray->nSize );
   eStatus = ECLIB_OK;
  }
 } else {
  eStatus = ECLIB_NULL_POINTER;
 }
 return eStatus;
}

canonical_original_code:
enum eclib_status_enum eclib_array_get(struct eclib_array_struct *pArray, unsigned short nIndex, void *pData)
{
 enum eclib_status_enum eStatus = ECLIB_ERROR;
 if (( ((void *)0) != pArray ) || (((void *)0) != pData))
 {
  if ( 0 != (pArray->pBitmap[ nIndex / 8 ] & (1 << (nIndex & 7) )) )
  {
   memcpy( pData, ((unsigned char *)pArray->pBuffer) + pArray->nSize * nIndex, pArray->nSize );
   eStatus = ECLIB_OK;
  }
 } else {
  eStatus = ECLIB_NULL_POINTER;
 }
 return eStatus;
}


decompiled_code:
__int64 __fastcall eclib_array_remove(__int64 a1, unsigned __int16 a2)
{
int v2; // ecx
unsigned int v3; // er8
_BYTE *v4; // rax
int v5; // edx

if ( !a1 )
return 3LL;
v2 = a2 & 7;
v3 = 2;
v4 = (_BYTE *)(*(_QWORD *)(a1 + 8) + (a2 >> 3));
v5 = (unsigned __int8)*v4;
if ( _bittest(&v5, v2) )
{
v3 = 0;
*v4 &= ~(1 << v2);
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, unsigned __int16 a2)
{
int v2; // ecx
unsigned int v3; // er8
_BYTE *v4; // rax
int v5; // edx

if ( !a1 )
return 3LL;
v2 = a2 & 7;
v3 = 2;
v4 = (_BYTE *)(*(_QWORD *)(a1 + 8) + (a2 >> 3));
v5 = (unsigned __int8)*v4;
if ( _bittest(&v5, v2) )
{
v3 = 0;
*v4 &= ~(1 << v2);
}
return v3;
}

original_code:
eclib_status_t eclib_array_remove( eclib_array_t * pArray, uint16_t nIndex )
{
 eclib_status_t eStatus = ECLIB_ERROR;
 if ( ((void *)0) != pArray )
 {
  if ( 0 != (pArray->pBitmap[ nIndex / 8 ] & ( 1 << ( nIndex & 7 )) ) )
  {
   pArray->pBitmap[ nIndex / 8 ] &= ~(1 << ( nIndex & 7 ));
   eStatus = ECLIB_OK;
  }
 } else {
  eStatus = ECLIB_NULL_POINTER;
 }
 return eStatus;
}

canonical_original_code:
enum eclib_status_enum eclib_array_remove(struct eclib_array_struct *pArray, unsigned short nIndex)
{
 enum eclib_status_enum eStatus = ECLIB_ERROR;
 if ( ((void *)0) != pArray )
 {
  if ( 0 != (pArray->pBitmap[ nIndex / 8 ] & ( 1 << ( nIndex & 7 )) ) )
  {
   pArray->pBitmap[ nIndex / 8 ] &= ~(1 << ( nIndex & 7 ));
   eStatus = ECLIB_OK;
  }
 } else {
  eStatus = ECLIB_NULL_POINTER;
 }
 return eStatus;
}


decompiled_code:
_BOOL8 seconds_tick_test()
{
unsigned int v0; // eax
char v1; // bl
unsigned __int8 v2; // bp
unsigned int v3; // er12
unsigned int v4; // eax
char v5; // si
unsigned int v6; // ecx
_BOOL8 result; // rax

v0 = calendar_get_time();
v1 = v0;
v2 = BYTE1(v0);
v3 = HIWORD(v0);
do
{
calendar_timer_cb();
v4 = calendar_get_time();
}
while ( (_BYTE)v4 );
v5 = BYTE1(v4);
v6 = HIWORD(v4);
if ( BYTE1(v4) == v2 + 1 )
{
if ( (_WORD)v3 != HIWORD(v4) )
{
result = 1LL;
if ( v2 == 59 )
{
LABEL_6:
if ( !v5 )
return result;
}
return 1LL;
}
result = 0LL;
}
else
{
result = v1 != 59;
if ( (_WORD)v3 != (_WORD)v6 )
{
if ( v2 == 59 )
goto LABEL_6;
return 1LL;
}
}
if ( !v5 )
result = 1LL;
return result;
}

canonical_decompiled_code:
_BOOL8 func7()
{
unsigned int v0; // eax
char v1; // bl
unsigned __int8 v2; // bp
unsigned int v3; // er12
unsigned int v4; // eax
char v5; // si
unsigned int v6; // ecx
_BOOL8 result; // rax

v0 = func11();
v1 = v0;
v2 = BYTE1(v0);
v3 = HIWORD(v0);
do
{
func17();
v4 = func11();
}
while ( (_BYTE)v4 );
v5 = BYTE1(v4);
v6 = HIWORD(v4);
if ( BYTE1(v4) == v2 + 1 )
{
if ( (_WORD)v3 != HIWORD(v4) )
{
result = 1LL;
if ( v2 == 59 )
{
LABEL_6:
if ( !v5 )
return result;
}
return 1LL;
}
result = 0LL;
}
else
{
result = v1 != 59;
if ( (_WORD)v3 != (_WORD)v6 )
{
if ( v2 == 59 )
goto LABEL_6;
return 1LL;
}
}
if ( !v5 )
result = 1LL;
return result;
}

original_code:
test_status_t seconds_tick_test() {
 calendar_time_t start_time;
 calendar_time_t end_time;
 test_status_t result = TEST_OK;
 start_time = calendar_get_time();
 do {
  calendar_timer_cb();
  end_time = calendar_get_time();
 } while (end_time.second != 0);
 if (end_time.minute != (start_time.minute + 1)) {
  if (!((end_time.second == 0) && (start_time.second == 59))) {
   result = TEST_FAIL;
  }
 } else {
  if (start_time.hour != end_time.hour) {
   result = TEST_FAIL;
  }
 }
 if (end_time.hour != start_time.hour) {
  if (!((end_time.minute == 0) && (start_time.minute == 59))) {
   if (end_time.minute > 0) {
    if (end_time.minute != (start_time.minute + 1)) {
     result = TEST_FAIL;
    }
   } else {
    if (end_time.minute != 59) {
     result = TEST_FAIL;
    }
   }
   result = TEST_FAIL;
  }
 } else {
  if (end_time.minute == 0) {
   result = TEST_FAIL;
  }
 }
 return result;
}

canonical_original_code:
enum test_status_t seconds_tick_test() {
 struct calendar_time_t start_time;
 struct calendar_time_t end_time;
 enum test_status_t result = TEST_OK;
 start_time = calendar_get_time();
 do {
  calendar_timer_cb();
  end_time = calendar_get_time();
 } while (end_time.second != 0);
 if (end_time.minute != (start_time.minute + 1)) {
  if (!((end_time.second == 0) && (start_time.second == 59))) {
   result = TEST_FAIL;
  }
 } else {
  if (start_time.hour != end_time.hour) {
   result = TEST_FAIL;
  }
 }
 if (end_time.hour != start_time.hour) {
  if (!((end_time.minute == 0) && (start_time.minute == 59))) {
   if (end_time.minute > 0) {
    if (end_time.minute != (start_time.minute + 1)) {
     result = TEST_FAIL;
    }
   } else {
    if (end_time.minute != 59) {
     result = TEST_FAIL;
    }
   }
   result = TEST_FAIL;
  }
 } else {
  if (end_time.minute == 0) {
   result = TEST_FAIL;
  }
 }
 return result;
}

variable_types: struct calendar_time_t { unsigned char second; unsigned char minute; unsigned short hour; }

variable_types: enum test_status_t { TEST_OK=0, TEST_FAIL=1, TEST_INVALID_VALUE=2, TEST_NULL_POINTER=3 }


decompiled_code:
void calendar_init()
{
calendar_internal_date = 0;
calendar_internal_time = 0;
}

canonical_decompiled_code:
void func8()
{
calendar_internal_date = 0;
calendar_internal_time = 0;
}

original_code:
void calendar_init() {
 memset(&calendar_internal_date, 0, sizeof(calendar_internal_date));
 memset(&calendar_internal_time, 0, sizeof(calendar_internal_time));
}


decompiled_code:
__int64 calendar_get_date()
{
return (unsigned int)calendar_internal_date;
}

canonical_decompiled_code:
__int64 func9()
{
return (unsigned int)calendar_internal_date;
}

canonical_original_code:
struct calendar_date_t calendar_get_date(){
 return calendar_internal_date;
}

return_type: struct calendar_date_t { unsigned char day; unsigned char month; unsigned short year; }


decompiled_code:
void __fastcall calendar_set_date(int a1)
{
calendar_internal_date = a1;
}

canonical_decompiled_code:
void __fastcall func10(int a1)
{
calendar_internal_date = a1;
}

original_code:
void calendar_set_date(calendar_date_t new_date) {
 calendar_internal_date = new_date;
}

canonical_original_code:
void calendar_set_date(struct calendar_date_t new_date) {
 calendar_internal_date = new_date;
}

variable_types: struct calendar_date_t { unsigned char day; unsigned char month; unsigned short year; }


decompiled_code:
__int64 calendar_get_time()
{
return (unsigned int)calendar_internal_time;
}

canonical_decompiled_code:
__int64 func11()
{
return (unsigned int)calendar_internal_time;
}

canonical_original_code:
struct calendar_time_t calendar_get_time() {
 return calendar_internal_time;
}

return_type: struct calendar_time_t { unsigned char second; unsigned char minute; unsigned short hour; }


decompiled_code:
void __fastcall calendar_set_time(int a1)
{
calendar_internal_time = a1;
}

canonical_decompiled_code:
void __fastcall func12(int a1)
{
calendar_internal_time = a1;
}

original_code:
void calendar_set_time(calendar_time_t new_time) {
 calendar_internal_time = new_time;
}

canonical_original_code:
void calendar_set_time(struct calendar_time_t new_time) {
 calendar_internal_time = new_time;
}

user_defined_types: struct calendar_time_t { unsigned char second; unsigned char minute; unsigned short hour; }


decompiled_code:
bool __fastcall calendar_get_leap_year(__int16 a1)
{
bool result; // al

result = 0;
if ( (a1 & 3) == 0 )
result = __ROR2__(23593 * a1, 2) > 0x28Fu;
return result;
}

canonical_decompiled_code:
bool __fastcall func13(__int16 a1)
{
bool result; // al

result = 0;
if ( (a1 & 3) == 0 )
result = __ROR2__(23593 * a1, 2) > 0x28Fu;
return result;
}

original_code:
uint8_t calendar_get_leap_year(uint16_t year) {
 uint8_t leap = 0;
 if (0 == (year % 4)) {
  leap = 1;
  if (0 == year % 100) {
   leap = 0;
  }
 }
 return leap;
}

canonical_original_code:
unsigned char calendar_get_leap_year(unsigned short year) {
 unsigned char leap = 0;
 if (0 == (year % 4)) {
  leap = 1;
  if (0 == year % 100) {
   leap = 0;
  }
 }
 return leap;
}

variable_types:
year
unsigned short

variable_types:
leap
unsigned char

return_type: unsigned char


decompiled_code:
__int64 calendar_get_unix_time()
{
unsigned int v0; // edx
bool v1; // di
unsigned int v2; // eax
unsigned int v3; // ecx
__int64 v4; // rdx
int i; // eax
unsigned int v6; // eax

v1 = calendar_get_leap_year(SHIWORD(calendar_internal_date));
v2 = v0 - 1970;
if ( v0 <= 0x7B1 )
v2 = v0;
v3 = 366 * v2 + (v2 >> 2) - v2 / 0x64;
if ( BYTE1(calendar_internal_date) )
{
v4 = 0LL;
for ( i = 31; ; i = (unsigned __int8)calendar_month_days[v4] )
{
++v4;
v3 += i;
if ( BYTE1(calendar_internal_date) <= (unsigned __int8)v4 )
break;
}
v6 = v3;
v3 -= !v1 - 1;
if ( BYTE1(calendar_internal_date) <= 1u )
v3 = v6;
}
return (unsigned __int8)calendar_internal_time
+ 61 * (BYTE1(calendar_internal_time) + 61 * (HIWORD(calendar_internal_time) + v3 + 24 * v3));
}

canonical_decompiled_code:
__int64 func14()
{
unsigned int v0; // edx
bool v1; // di
unsigned int v2; // eax
unsigned int v3; // ecx
__int64 v4; // rdx
int i; // eax
unsigned int v6; // eax

v1 = func13(SHIWORD(calendar_internal_date));
v2 = v0 - 1970;
if ( v0 <= 0x7B1 )
v2 = v0;
v3 = 366 * v2 + (v2 >> 2) - v2 / 0x64;
if ( BYTE1(calendar_internal_date) )
{
v4 = 0LL;
for ( i = 31; ; i = (unsigned __int8)calendar_month_days[v4] )
{
++v4;
v3 += i;
if ( BYTE1(calendar_internal_date) <= (unsigned __int8)v4 )
break;
}
v6 = v3;
v3 -= !v1 - 1;
if ( BYTE1(calendar_internal_date) <= 1u )
v3 = v6;
}
return (unsigned __int8)calendar_internal_time
+ 61 * (BYTE1(calendar_internal_time) + 61 * (HIWORD(calendar_internal_time) + v3 + 24 * v3));
}

original_code:
uint32_t calendar_get_unix_time() {
 uint32_t unix_time = 0L;
 uint32_t leap_days = 0L;
 uint8_t idx;
 uint8_t leap = calendar_get_leap_year(calendar_internal_date.year);
 unix_time = calendar_internal_date.year;
 if (unix_time >= 1970) {
  unix_time -= 1970;
 }
 leap_days = (unix_time / 4) - (unix_time / 100);
 unix_time += unix_time * 365 + leap_days;
 for (idx = 0; idx < calendar_internal_date.month; idx ++) {
  unix_time += calendar_month_days[idx];
 }
 if ((calendar_internal_date.month > 1) && (0 != leap)) {
  unix_time ++;
 }
 unix_time += unix_time * 24 + calendar_internal_time.hour;
 unix_time += unix_time * 60 + calendar_internal_time.minute;
 unix_time += unix_time * 60 + calendar_internal_time.second;
 return unix_time;
}

canonical_original_code:
unsigned int calendar_get_unix_time() {
 unsigned int unix_time = 0L;
 unsigned int leap_days = 0L;
 unsigned char idx;
 unsigned char leap = calendar_get_leap_year(calendar_internal_date.year);
 unix_time = calendar_internal_date.year;
 if (unix_time >= 1970) {
  unix_time -= 1970;
 }
 leap_days = (unix_time / 4) - (unix_time / 100);
 unix_time += unix_time * 365 + leap_days;
 for (idx = 0; idx < calendar_internal_date.month; idx ++) {
  unix_time += calendar_month_days[idx];
 }
 if ((calendar_internal_date.month > 1) && (0 != leap)) {
  unix_time ++;
 }
 unix_time += unix_time * 24 + calendar_internal_time.hour;
 unix_time += unix_time * 60 + calendar_internal_time.minute;
 unix_time += unix_time * 60 + calendar_internal_time.second;
 return unix_time;
}

variable_types:
idx
unsigned char


decompiled_code:
__int64 calendar_increase_date()
{
bool v0; // al
__int16 v1; // r9
int v2; // edx
int v3; // edx
__int64 result; // rax

v0 = calendar_get_leap_year(SHIWORD(calendar_internal_date));
v2 = (unsigned __int8)calendar_month_days[BYTE1(calendar_internal_date)];
LOBYTE(calendar_internal_date) = calendar_internal_date + 1;
v3 = v0 + v2;
result = (unsigned __int8)calendar_internal_date;
if ( (unsigned __int8)calendar_internal_date > v3 )
{
LOBYTE(calendar_internal_date) = 0;
if ( (unsigned __int8)(BYTE1(calendar_internal_date) + 1) <= 0xBu )
{
++BYTE1(calendar_internal_date);
}
else
{
BYTE1(calendar_internal_date) = 0;
HIWORD(calendar_internal_date) = v1 + 1;
}
}
return result;
}

canonical_decompiled_code:
__int64 func15()
{
bool v0; // al
__int16 v1; // r9
int v2; // edx
int v3; // edx
__int64 result; // rax

v0 = func13(SHIWORD(calendar_internal_date));
v2 = (unsigned __int8)calendar_month_days[BYTE1(calendar_internal_date)];
LOBYTE(calendar_internal_date) = calendar_internal_date + 1;
v3 = v0 + v2;
result = (unsigned __int8)calendar_internal_date;
if ( (unsigned __int8)calendar_internal_date > v3 )
{
LOBYTE(calendar_internal_date) = 0;
if ( (unsigned __int8)(BYTE1(calendar_internal_date) + 1) <= 0xBu )
{
++BYTE1(calendar_internal_date);
}
else
{
BYTE1(calendar_internal_date) = 0;
HIWORD(calendar_internal_date) = v1 + 1;
}
}
return result;
}

original_code:
void calendar_increase_date(void) {
 uint8_t is_leap = calendar_get_leap_year(calendar_internal_date.year);
 calendar_internal_date.day ++;
 if (calendar_internal_date.day > calendar_month_days[calendar_internal_date.month] + is_leap) {
   calendar_internal_date.day = 0;
  calendar_internal_date.month ++;
  if (calendar_internal_date.month > 11) {
   calendar_internal_date.month = 0;
   calendar_internal_date.year ++;
  }
 }
}

canonical_original_code:
void calendar_increase_date() {
 unsigned char is_leap = calendar_get_leap_year(calendar_internal_date.year);
 calendar_internal_date.day ++;
 if (calendar_internal_date.day > calendar_month_days[calendar_internal_date.month] + is_leap) {
   calendar_internal_date.day = 0;
  calendar_internal_date.month ++;
  if (calendar_internal_date.month > 11) {
   calendar_internal_date.month = 0;
   calendar_internal_date.year ++;
  }
 }
}


decompiled_code:
__int64 calendar_increase_time()
{
__int64 result; // rax

result = (unsigned int)(unsigned __int8)calendar_internal_time + 1;
if ( (unsigned __int8)(calendar_internal_time + 1) > 0x3Bu )
{
LOBYTE(calendar_internal_time) = 0;
result = (unsigned int)BYTE1(calendar_internal_time) + 1;
if ( (unsigned __int8)(BYTE1(calendar_internal_time) + 1) <= 0x3Bu )
{
++BYTE1(calendar_internal_time);
}
else
{
BYTE1(calendar_internal_time) = 0;
result = (unsigned int)HIWORD(calendar_internal_time) + 1;
if ( (unsigned __int16)(HIWORD(calendar_internal_time) + 1) > 0x17u )
{
HIWORD(calendar_internal_time) = 0;
result = calendar_increase_date();
}
else
{
++HIWORD(calendar_internal_time);
}
}
}
else
{
LOBYTE(calendar_internal_time) = calendar_internal_time + 1;
}
return result;
}

canonical_decompiled_code:
__int64 func16()
{
__int64 result; // rax

result = (unsigned int)(unsigned __int8)calendar_internal_time + 1;
if ( (unsigned __int8)(calendar_internal_time + 1) > 0x3Bu )
{
LOBYTE(calendar_internal_time) = 0;
result = (unsigned int)BYTE1(calendar_internal_time) + 1;
if ( (unsigned __int8)(BYTE1(calendar_internal_time) + 1) <= 0x3Bu )
{
++BYTE1(calendar_internal_time);
}
else
{
BYTE1(calendar_internal_time) = 0;
result = (unsigned int)HIWORD(calendar_internal_time) + 1;
if ( (unsigned __int16)(HIWORD(calendar_internal_time) + 1) > 0x17u )
{
HIWORD(calendar_internal_time) = 0;
result = func15();
}
else
{
++HIWORD(calendar_internal_time);
}
}
}
else
{
LOBYTE(calendar_internal_time) = calendar_internal_time + 1;
}
return result;
}

original_code:
void calendar_increase_time(void) {
 calendar_internal_time.second ++;
 if (calendar_internal_time.second >= 60) {
  calendar_internal_time.second = 0;
  calendar_internal_time.minute ++;
  if (calendar_internal_time.minute >= 60) {
   calendar_internal_time.minute = 0;
   calendar_internal_time.hour ++;
   if (calendar_internal_time.hour >= 24) {
    calendar_internal_time.hour = 0;
    calendar_increase_date();
   }
  }
 }
}

canonical_original_code:
void calendar_increase_time() {
 calendar_internal_time.second ++;
 if (calendar_internal_time.second >= 60) {
  calendar_internal_time.second = 0;
  calendar_internal_time.minute ++;
  if (calendar_internal_time.minute >= 60) {
   calendar_internal_time.minute = 0;
   calendar_internal_time.hour ++;
   if (calendar_internal_time.hour >= 24) {
    calendar_internal_time.hour = 0;
    calendar_increase_date();
   }
  }
 }
}


decompiled_code:
// attributes: thunk
__int64 calendar_timer_cb(void)
{
return calendar_increase_time();
}

canonical_decompiled_code:
__int64 func17(void)
{
return func16();
}

original_code:
void calendar_timer_cb(void) {
 calendar_increase_time();
}

canonical_original_code:
void calendar_timer_cb() {
 calendar_increase_time();
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax

v3 = seconds_tick_test(argc, argv, envp);
printf("seconds_tick_test() = [%s]\n", (&test_status_t_names)[v3]);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax

v3 = func7(argc, argv, envp);
printf("seconds_tick_test() = [%s]\n", (&test_status_t_names)[v3]);
return 0;
}

original_code:
int main() {
 test_status_t test_result;
 test_result = seconds_tick_test();
 printf("seconds_tick_test() = [%s]\n", test_status_t_names[test_result]);
 return 0;
}

canonical_original_code:
int main() {
 enum test_status_t test_result;
 test_result = seconds_tick_test();
 printf("seconds_tick_test() = [%s]\n", test_status_t_names[test_result]);
 return 0;
}

return_type: int

user_defined_types: enum test_status_t { TEST_OK=0, TEST_FAIL=1, TEST_INVALID_VALUE=2, TEST_NULL_POINTER=3 }


decompiled_code:
__int64 eclib_queue2_version()
{
return 256LL;
}

original_code:
uint32_t eclib_queue2_version() {
 return 0x0100;
}

canonical_original_code:
unsigned int eclib_queue2_version() {
 return 0x0100;
}


original_code:
eclib_status_t eclib_queue2_init( eclib_queue2_t * pQueue, void * pBuffer, uint16_t nSize, uint16_t nUnits )
{
 eclib_status_t eStatus = ECLIB_NULL_POINTER;
 if ( ((void *)0) != pQueue )
 {
  if ( ((void *)0) != pBuffer )
  {
   pQueue->nHeadIndex = 0;
   pQueue->nUsedUnits = 0;
   pQueue->nTotalUnits = nUnits;
   pQueue->nSize = nSize;
   pQueue->pBuffer = pBuffer;
   pQueue->eSignature = ECLIB_SIGNATURE_QUEUE;
   eStatus = ECLIB_OK;
  } else {
   pQueue->eSignature = ECLIB_SIGNATURE_EMPTY;
  }
 } else {
 }
 return eStatus;
}

canonical_original_code:
enum eclib_status_enum eclib_queue2_init(struct eclib_queue2_struct *pQueue, void *pBuffer, unsigned short nSize, unsigned short nUnits)
{
 enum eclib_status_enum eStatus = ECLIB_NULL_POINTER;
 if ( ((void *)0) != pQueue )
 {
  if ( ((void *)0) != pBuffer )
  {
   pQueue->nHeadIndex = 0;
   pQueue->nUsedUnits = 0;
   pQueue->nTotalUnits = nUnits;
   pQueue->nSize = nSize;
   pQueue->pBuffer = pBuffer;
   pQueue->eSignature = ECLIB_SIGNATURE_QUEUE;
   eStatus = ECLIB_OK;
  } else {
   pQueue->eSignature = ECLIB_SIGNATURE_EMPTY;
  }
 } else {
 }
 return eStatus;
}

variable_types: struct eclib_queue2_struct { enum eclib_signature_enum { ECLIB_SIGNATURE_EMPTY=0, ECLIB_SIGNATURE_QUEUE=4660, ECLIB_SIGNATURE_ARRAY=9029, ECLIB_SIGNATURE_SET=13398, ECLIB_SIGNATURE_BUTTON=17767 } eSignature; unsigned short nHeadIndex; unsigned short nUsedUnits; unsigned short nSize; unsigned short nTotalUnits; void *pBuffer; } *

variable_types:
pBuffer
void *

variable_types:
nSize
unsigned short

variable_types:
nUnits
unsigned short

user_defined_types: struct eclib_queue2_struct { enum eclib_signature_enum eSignature; unsigned short nHeadIndex; unsigned short nUsedUnits; unsigned short nSize; unsigned short nTotalUnits; void *pBuffer; }


decompiled_code:
__int64 __fastcall eclib_queue2_clear(__int64 a1)
{
__int64 result; // rax

if ( !a1 )
return 3LL;
*(_WORD *)(a1 + 4) = 0;
result = 0LL;
*(_WORD *)(a1 + 6) = 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 result; // rax

if ( !a1 )
return 3LL;
*(_WORD *)(a1 + 4) = 0;
result = 0LL;
*(_WORD *)(a1 + 6) = 0;
return result;
}

original_code:
eclib_status_t eclib_queue2_clear( eclib_queue2_t * pQueue )
{
 eclib_status_t eStatus = ECLIB_NULL_POINTER;
 if ( ((void *)0) != pQueue )
 {
  pQueue->nHeadIndex = 0;
  pQueue->nUsedUnits = 0;
  eStatus = ECLIB_OK;
 }
 return eStatus;
}

canonical_original_code:
enum eclib_status_enum eclib_queue2_clear(struct eclib_queue2_struct *pQueue)
{
 enum eclib_status_enum eStatus = ECLIB_NULL_POINTER;
 if ( ((void *)0) != pQueue )
 {
  pQueue->nHeadIndex = 0;
  pQueue->nUsedUnits = 0;
  eStatus = ECLIB_OK;
 }
 return eStatus;
}


decompiled_code:
__int64 __fastcall eclib_queue2_full(_WORD *a1)
{
if ( !a1 )
return 3LL;
a1[2] = 0;
a1[3] = a1[5];
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(_WORD *a1)
{
if ( !a1 )
return 3LL;
a1[2] = 0;
a1[3] = a1[5];
return 0LL;
}

original_code:
eclib_status_t eclib_queue2_full( eclib_queue2_t * pQueue )
{
 eclib_status_t eStatus = ECLIB_NULL_POINTER;
 if ( ((void *)0) != pQueue )
 {
  pQueue->nHeadIndex = 0;
  pQueue->nUsedUnits = pQueue->nTotalUnits;
  eStatus = ECLIB_OK;
 }
 return eStatus;
}

canonical_original_code:
enum eclib_status_enum eclib_queue2_full(struct eclib_queue2_struct *pQueue)
{
 enum eclib_status_enum eStatus = ECLIB_NULL_POINTER;
 if ( ((void *)0) != pQueue )
 {
  pQueue->nHeadIndex = 0;
  pQueue->nUsedUnits = pQueue->nTotalUnits;
  eStatus = ECLIB_OK;
 }
 return eStatus;
}


decompiled_code:
__int64 __fastcall eclib_queue2_is_empty(__int64 a1)
{
__int64 result; // rax

if ( a1 )
result = *(_WORD *)(a1 + 6) == 0 ? 6 : 0;
else
result = 3LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
__int64 result; // rax

if ( a1 )
result = *(_WORD *)(a1 + 6) == 0 ? 6 : 0;
else
result = 3LL;
return result;
}

original_code:
eclib_status_t eclib_queue2_is_empty( eclib_queue2_t * pQueue )
{
 eclib_status_t eStatus = ECLIB_NULL_POINTER;
 if ( ((void *)0) != pQueue )
 {
  eStatus = ( 0 == pQueue->nUsedUnits ) ? ECLIB_EMPTY : ECLIB_OK ;
 }
 return eStatus;
}

canonical_original_code:
enum eclib_status_enum eclib_queue2_is_empty(struct eclib_queue2_struct *pQueue)
{
 enum eclib_status_enum eStatus = ECLIB_NULL_POINTER;
 if ( ((void *)0) != pQueue )
 {
  eStatus = ( 0 == pQueue->nUsedUnits ) ? ECLIB_EMPTY : ECLIB_OK ;
 }
 return eStatus;
}


decompiled_code:
__int64 __fastcall eclib_queue2_is_full(__int64 a1)
{
__int64 result; // rax

if ( a1 )
result = 5 * (unsigned int)(*(_WORD *)(a1 + 10) == *(_WORD *)(a1 + 6));
else
result = 3LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
__int64 result; // rax

if ( a1 )
result = 5 * (unsigned int)(*(_WORD *)(a1 + 10) == *(_WORD *)(a1 + 6));
else
result = 3LL;
return result;
}

original_code:
eclib_status_t eclib_queue2_is_full( eclib_queue2_t * pQueue )
{
 eclib_status_t eStatus = ECLIB_NULL_POINTER;
 if ( ((void *)0) != pQueue )
 {
  eStatus = ( pQueue->nTotalUnits == pQueue->nUsedUnits) ? ECLIB_FULL : ECLIB_OK ;
 }
 return eStatus;
}

canonical_original_code:
enum eclib_status_enum eclib_queue2_is_full(struct eclib_queue2_struct *pQueue)
{
 enum eclib_status_enum eStatus = ECLIB_NULL_POINTER;
 if ( ((void *)0) != pQueue )
 {
  eStatus = ( pQueue->nTotalUnits == pQueue->nUsedUnits) ? ECLIB_FULL : ECLIB_OK ;
 }
 return eStatus;
}


original_code:
eclib_status_t eclib_queue2_push( eclib_queue2_t * pQueue, void * pData )
{
 eclib_status_t eStatus = ECLIB_NULL_POINTER;
 eStatus = eclib_queue2_is_full( pQueue );
 if ( ECLIB_OK == eStatus )
 {
  if ( ((void *)0) != pData )
  {
   memcpy( ((uint8_t *)pQueue->pBuffer) + pQueue->nSize * pQueue->nHeadIndex, pData, pQueue->nSize );
   pQueue->nHeadIndex ++;
   if ( pQueue->nHeadIndex >= pQueue->nTotalUnits )
   {
    pQueue->nHeadIndex -= pQueue->nTotalUnits;
   }
   pQueue->nUsedUnits ++;
  }
 }
 return eStatus;
}

canonical_original_code:
enum eclib_status_enum eclib_queue2_push(struct eclib_queue2_struct *pQueue, void *pData)
{
 enum eclib_status_enum eStatus = ECLIB_NULL_POINTER;
 eStatus = eclib_queue2_is_full( pQueue );
 if ( ECLIB_OK == eStatus )
 {
  if ( ((void *)0) != pData )
  {
   memcpy( ((unsigned char *)pQueue->pBuffer) + pQueue->nSize * pQueue->nHeadIndex, pData, pQueue->nSize );
   pQueue->nHeadIndex ++;
   if ( pQueue->nHeadIndex >= pQueue->nTotalUnits )
   {
    pQueue->nHeadIndex -= pQueue->nTotalUnits;
   }
   pQueue->nUsedUnits ++;
  }
 }
 return eStatus;
}

variable_types:
pData
void *


original_code:
eclib_status_t eclib_queue2_pop( eclib_queue2_t * pQueue, void * pData )
{
 eclib_status_t eStatus;
 int16_t nIndex;
 eStatus = eclib_queue2_is_empty( pQueue );
 if ( ECLIB_OK == eStatus )
 {
  if ( ((void *)0) != pData )
  {
   nIndex = pQueue->nHeadIndex - pQueue->nUsedUnits;
   if ( nIndex < 0 )
   {
    nIndex += pQueue->nTotalUnits;
   }
   memcpy( pData, ((uint8_t *)pQueue->pBuffer) + pQueue->nSize * nIndex, pQueue->nSize );
   pQueue->nUsedUnits --;
  } else {
   eStatus = ECLIB_NULL_POINTER;
  }
 }
 return eStatus;
}

canonical_original_code:
enum eclib_status_enum eclib_queue2_pop(struct eclib_queue2_struct *pQueue, void *pData)
{
 enum eclib_status_enum eStatus;
 short nIndex;
 eStatus = eclib_queue2_is_empty( pQueue );
 if ( ECLIB_OK == eStatus )
 {
  if ( ((void *)0) != pData )
  {
   nIndex = pQueue->nHeadIndex - pQueue->nUsedUnits;
   if ( nIndex < 0 )
   {
    nIndex += pQueue->nTotalUnits;
   }
   memcpy( pData, ((unsigned char *)pQueue->pBuffer) + pQueue->nSize * nIndex, pQueue->nSize );
   pQueue->nUsedUnits --;
  } else {
   eStatus = ECLIB_NULL_POINTER;
  }
 }
 return eStatus;
}

variable_types: nIndex short


original_code:
eclib_status_t eclib_queue2_peek( eclib_queue2_t * pQueue, void * pData )
{
 eclib_status_t eStatus;
 int16_t nIndex;
 eStatus = eclib_queue2_is_empty( pQueue );
 if ( ECLIB_OK == eStatus )
 {
  if ( ((void *)0) != pData )
  {
   nIndex = pQueue->nHeadIndex - pQueue->nUsedUnits;
   if ( nIndex < 0 )
   {
    nIndex += pQueue->nTotalUnits;
   }
   memcpy( pData, ((uint8_t *)pQueue->pBuffer) + pQueue->nSize * nIndex, pQueue->nSize );
  } else {
   eStatus = ECLIB_NULL_POINTER;
  }
 }
 return eStatus;
}

canonical_original_code:
enum eclib_status_enum eclib_queue2_peek(struct eclib_queue2_struct *pQueue, void *pData)
{
 enum eclib_status_enum eStatus;
 short nIndex;
 eStatus = eclib_queue2_is_empty( pQueue );
 if ( ECLIB_OK == eStatus )
 {
  if ( ((void *)0) != pData )
  {
   nIndex = pQueue->nHeadIndex - pQueue->nUsedUnits;
   if ( nIndex < 0 )
   {
    nIndex += pQueue->nTotalUnits;
   }
   memcpy( pData, ((unsigned char *)pQueue->pBuffer) + pQueue->nSize * nIndex, pQueue->nSize );
  } else {
   eStatus = ECLIB_NULL_POINTER;
  }
 }
 return eStatus;
}


decompiled_code:
__int64 __fastcall eclib_queue2_get_usage(__int64 a1)
{
return *(unsigned __int16 *)(a1 + 6);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
return *(unsigned __int16 *)(a1 + 6);
}

original_code:
uint16_t eclib_queue2_get_usage( eclib_queue2_ptr_t pQueue ) {
 return pQueue->nUsedUnits;
}

canonical_original_code:
unsigned short eclib_queue2_get_usage(struct eclib_queue2_struct *pQueue) {
 return pQueue->nUsedUnits;
}


decompiled_code:
__int16 __fastcall eclib_queue2_get_tail_index(_WORD *a1)
{
__int16 result; // ax

result = a1[2] - a1[3];
if ( result < 0 )
result += a1[5];
return result;
}

canonical_decompiled_code:
__int16 __fastcall func10(_WORD *a1)
{
__int16 result; // ax

result = a1[2] - a1[3];
if ( result < 0 )
result += a1[5];
return result;
}

original_code:
uint16_t eclib_queue2_get_tail_index( eclib_queue2_ptr_t pQueue ) {
 int16_t nIndex;
 nIndex = pQueue->nHeadIndex - pQueue->nUsedUnits;
 if ( nIndex < 0 )
 {
  nIndex += pQueue->nTotalUnits;
 }
 return nIndex;
}

canonical_original_code:
unsigned short eclib_queue2_get_tail_index(struct eclib_queue2_struct *pQueue) {
 short nIndex;
 nIndex = pQueue->nHeadIndex - pQueue->nUsedUnits;
 if ( nIndex < 0 )
 {
  nIndex += pQueue->nTotalUnits;
 }
 return nIndex;
}


decompiled_code:
__int64 __fastcall eclib_queue2_get_head_index(__int64 a1)
{
return *(unsigned __int16 *)(a1 + 4);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
return *(unsigned __int16 *)(a1 + 4);
}

original_code:
uint16_t eclib_queue2_get_head_index( eclib_queue2_ptr_t pQueue ) {
 return pQueue->nHeadIndex;
}

canonical_original_code:
unsigned short eclib_queue2_get_head_index(struct eclib_queue2_struct *pQueue) {
 return pQueue->nHeadIndex;
}


decompiled_code:
__int64 __fastcall eclib_queue2_get_queue_size(__int64 a1)
{
return *(unsigned __int16 *)(a1 + 10);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
return *(unsigned __int16 *)(a1 + 10);
}

original_code:
uint16_t eclib_queue2_get_queue_size( eclib_queue2_ptr_t pQueue ) {
 return pQueue->nTotalUnits;
}

canonical_original_code:
unsigned short eclib_queue2_get_queue_size(struct eclib_queue2_struct *pQueue) {
 return pQueue->nTotalUnits;
}


decompiled_code:
__int64 eclib_timer_version()
{
return 256LL;
}

canonical_decompiled_code:
__int64 func0()
{
return 256LL;
}

original_code:
uint32_t eclib_timer_version() {
 return 0x0100;
}

canonical_original_code:
unsigned int eclib_timer_version() {
 return 0x0100;
}


decompiled_code:
__int64 __fastcall eclib_timer_start_timer(_DWORD *a1)
{
if ( !a1 )
return 3LL;
*a1 = _counter_1ms;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(_DWORD *a1)
{
if ( !a1 )
return 3LL;
*a1 = _counter_1ms;
return 0LL;
}

original_code:
eclib_status_t eclib_timer_start_timer(eclib_timer_ptr_t pTimer) {
 eclib_status_t result = ECLIB_OK;
 if (((void *)0) != pTimer) {
  (*pTimer) = __counter_1ms;
 } else {
  result = ECLIB_NULL_POINTER;
 }
 return result;
}

canonical_original_code:
enum eclib_status_enum eclib_timer_start_timer(unsigned int *pTimer) {
 enum eclib_status_enum result = ECLIB_OK;
 if (((void *)0) != pTimer) {
  (*pTimer) = __counter_1ms;
 } else {
  result = ECLIB_NULL_POINTER;
 }
 return result;
}

variable_types:
pTimer
unsigned int *


decompiled_code:
__int64 __fastcall eclib_timer_stop_timer(_DWORD *a1)
{
if ( !a1 )
return 3LL;
*a1 = 0;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(_DWORD *a1)
{
if ( !a1 )
return 3LL;
*a1 = 0;
return 0LL;
}

original_code:
eclib_status_t eclib_timer_stop_timer(eclib_timer_ptr_t pTimer) {
 eclib_status_t result = ECLIB_OK;
 if (((void *)0) != pTimer) {
  (*pTimer) = 0L;
 } else {
  result = ECLIB_NULL_POINTER;
 }
 return result;
}

canonical_original_code:
enum eclib_status_enum eclib_timer_stop_timer(unsigned int *pTimer) {
 enum eclib_status_enum result = ECLIB_OK;
 if (((void *)0) != pTimer) {
  (*pTimer) = 0L;
 } else {
  result = ECLIB_NULL_POINTER;
 }
 return result;
}


decompiled_code:
unsigned __int64 __fastcall eclib_timer_get_elapsed_time(unsigned int *a1)
{
unsigned __int64 result; // rax

result = 0LL;
if ( a1 )
{
result = *a1;
if ( (_DWORD)result )
result = (__PAIR64__(_counter_1ms, _counter_1ms) - __PAIR64__(result, result)) >> 32;
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func3(unsigned int *a1)
{
unsigned __int64 result; // rax

result = 0LL;
if ( a1 )
{
result = *a1;
if ( (_DWORD)result )
result = (__PAIR64__(_counter_1ms, _counter_1ms) - __PAIR64__(result, result)) >> 32;
}
return result;
}

original_code:
eclib_timer_t eclib_timer_get_elapsed_time(eclib_timer_ptr_t pTimer) {
 eclib_timer_t _time = 0L;
 if ((((void *)0) != pTimer) && (0 != *pTimer)) {
  _time = __counter_1ms;
  if (_time < (*pTimer)) {
   _time --;
  }
  _time -= (*pTimer);
 }
 return _time;
}

canonical_original_code:
unsigned int eclib_timer_get_elapsed_time(unsigned int *pTimer) {
 unsigned int _time = 0L;
 if ((((void *)0) != pTimer) && (0 != *pTimer)) {
  _time = __counter_1ms;
  if (_time < (*pTimer)) {
   _time --;
  }
  _time -= (*pTimer);
 }
 return _time;
}


decompiled_code:
bool __fastcall eclib_timer_is_elapsed_timeout(unsigned int *a1, unsigned int a2)
{
bool result; // al

result = 0;
if ( a1 )
{
if ( *a1 )
result = (unsigned int)eclib_timer_get_elapsed_time(a1) >= a2;
}
return result;
}

canonical_decompiled_code:
bool __fastcall func4(unsigned int *a1, unsigned int a2)
{
bool result; // al

result = 0;
if ( a1 )
{
if ( *a1 )
result = (unsigned int)func3(a1) >= a2;
}
return result;
}

original_code:
uint8_t eclib_timer_is_elapsed_timeout(eclib_timer_ptr_t pTimer, eclib_timer_t msTimeout) {
  uint8_t result = 0L;
  eclib_timer_t _time = 0L;
  if ((((void *)0) != pTimer) && (0 != *pTimer)) {
    _time = eclib_timer_get_elapsed_time(pTimer);
    if (_time >= msTimeout) {
      result = 1;
    }
  }
  return result;
}

canonical_original_code:
unsigned char eclib_timer_is_elapsed_timeout(unsigned int *pTimer, unsigned int msTimeout) {
  unsigned char result = 0L;
  unsigned int _time = 0L;
  if ((((void *)0) != pTimer) && (0 != *pTimer)) {
    _time = eclib_timer_get_elapsed_time(pTimer);
    if (_time >= msTimeout) {
      result = 1;
    }
  }
  return result;
}

variable_types:
msTimeout
unsigned int

variable_types:
result
unsigned char


decompiled_code:
bool __fastcall eclib_timer_is_timer_started(_DWORD *a1)
{
bool result; // al

result = 0;
if ( a1 )
result = *a1 != 0;
return result;
}

canonical_decompiled_code:
bool __fastcall func5(_DWORD *a1)
{
bool result; // al

result = 0;
if ( a1 )
result = *a1 != 0;
return result;
}

original_code:
uint8_t eclib_timer_is_timer_started(eclib_timer_ptr_t pTimer) {
  uint8_t result = 0L;
  if (((void *)0) != pTimer) {
    result = (0 != (*pTimer));
  }
  return result;
}

canonical_original_code:
unsigned char eclib_timer_is_timer_started(unsigned int *pTimer) {
  unsigned char result = 0L;
  if (((void *)0) != pTimer) {
    result = (0 != (*pTimer));
  }
  return result;
}


decompiled_code:
__int64 __fastcall eclib_timer_add_delta(_DWORD *a1, int a2)
{
__int64 result; // rax
bool v3; // cf

result = 0LL;
if ( a1 )
{
result = (unsigned int)*a1;
if ( (_DWORD)result )
{
v3 = __CFADD__(a2, (_DWORD)result);
result = (unsigned int)(a2 + result);
if ( v3 )
result = (unsigned int)(result + 1);
*a1 = result;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(_DWORD *a1, int a2)
{
__int64 result; // rax
bool v3; // cf

result = 0LL;
if ( a1 )
{
result = (unsigned int)*a1;
if ( (_DWORD)result )
{
v3 = __CFADD__(a2, (_DWORD)result);
result = (unsigned int)(a2 + result);
if ( v3 )
result = (unsigned int)(result + 1);
*a1 = result;
}
}
return result;
}

original_code:
eclib_timer_t eclib_timer_add_delta(eclib_timer_ptr_t pTimer, eclib_timer_t delta) {
 eclib_timer_t result = 0L;
 if ((((void *)0) != pTimer) && (0L != *pTimer)) {
  *pTimer += delta;
  if (*pTimer < delta) {
   (*pTimer) ++;
  }
  result = *pTimer;
 }
 return result;
}

canonical_original_code:
unsigned int eclib_timer_add_delta(unsigned int *pTimer, unsigned int delta) {
 unsigned int result = 0L;
 if ((((void *)0) != pTimer) && (0L != *pTimer)) {
  *pTimer += delta;
  if (*pTimer < delta) {
   (*pTimer) ++;
  }
  result = *pTimer;
 }
 return result;
}

variable_types:
delta
unsigned int

variable_types:
result
unsigned int


decompiled_code:
__int64 eclib_test_queue2()
{
unsigned __int16 v0; // bx
unsigned int v1; // eax
unsigned int v2; // er12
unsigned __int16 v3; // bx
__int16 v4; // r12
unsigned __int16 v5; // bx
__int16 v6; // r12
unsigned __int16 v7; // bx
int v8; // er13
int v9; // ebp
int v10; // ebx
unsigned int v11; // er14
int v12; // eax
int v13; // er13
int v14; // ebp
int v15; // ebx
unsigned int v16; // er14
int v17; // eax
unsigned int i; // [rsp+8h] [rbp-30h] BYREF
char v20[44]; // [rsp+Ch] [rbp-2Ch] BYREF

v0 = 0;
v1 = eclib_queue2_version();
printf("%s: %s\tv.%x\n", "eclib_test_queue2.c", "May 23 2025", v1);
for ( i = 0; i <= 0xA; ++i )
v0 -= ((unsigned int)eclib_queue2_push(&uint16Queue21, &i) == 0) - 1;
i = 0;
v2 = v0 > 1u;
v3 = 0;
do
{
v3 -= ((unsigned int)eclib_queue2_pop(&uint16Queue21, v20) == 0) - 1;
++i;
}
while ( i <= 0xA );
v4 = v2 - ((v3 < 2u) - 1);
v5 = 0;
eclib_queue2_init(&uint16Queue21, &uint16Queue21_buffer, 2LL, 5LL);
for ( i = 0; i <= 5; ++i )
v5 -= ((unsigned int)eclib_queue2_push(&uint16Queue21, &i) == 0) - 1;
i = 0;
v6 = v4 - ((v5 < 7u) - 1);
v7 = 0;
do
{
v7 -= ((unsigned int)eclib_queue2_pop(&uint16Queue21, v20) == 0) - 1;
++i;
}
while ( i <= 5 );
v8 = 100;
LOWORD(v2) = v6 - ((v7 < 7u) - 1);
v9 = clock();
do
{
v10 = 1000;
do
{
eclib_queue2_clear(&uint16Queue23);
for ( i = 0; i <= 0x1387; ++i )
v11 = eclib_queue2_push(&uint16Queue23, &i);
--v10;
}
while ( v10 );
--v8;
}
while ( v8 );
v12 = clock();
v13 = 100;
printf("push<%d>( %d , %d )\t%d\n", i, 1000LL, v11, (unsigned int)(v12 - v9));
v14 = clock();
do
{
v15 = 1000;
do
{
eclib_queue2_full(&uint16Queue23);
for ( i = 0; i <= 0x1387; ++i )
v16 = eclib_queue2_pop(&uint16Queue23, v20);
--v15;
}
while ( v15 );
--v13;
}
while ( v13 );
v17 = clock();
printf("pop<%d>( %d , %d )\t%d\n", i, 1000LL, v16, (unsigned int)(v17 - v14));
return v2;
}

canonical_decompiled_code:
__int64 func0()
{
unsigned __int16 v0; // bx
unsigned int v1; // eax
unsigned int v2; // er12
unsigned __int16 v3; // bx
__int16 v4; // r12
unsigned __int16 v5; // bx
__int16 v6; // r12
unsigned __int16 v7; // bx
int v8; // er13
int v9; // ebp
int v10; // ebx
unsigned int v11; // er14
int v12; // eax
int v13; // er13
int v14; // ebp
int v15; // ebx
unsigned int v16; // er14
int v17; // eax
unsigned int i; // [rsp+8h] [rbp-30h] BYREF
char v20[44]; // [rsp+Ch] [rbp-2Ch] BYREF

v0 = 0;
v1 = eclib_queue2_version();
printf("%s: %s\tv.%x\n", "eclib_test_queue2.c", "May 23 2025", v1);
for ( i = 0; i <= 0xA; ++i )
v0 -= ((unsigned int)eclib_queue2_push(&uint16Queue21, &i) == 0) - 1;
i = 0;
v2 = v0 > 1u;
v3 = 0;
do
{
v3 -= ((unsigned int)eclib_queue2_pop(&uint16Queue21, v20) == 0) - 1;
++i;
}
while ( i <= 0xA );
v4 = v2 - ((v3 < 2u) - 1);
v5 = 0;
eclib_queue2_init(&uint16Queue21, &uint16Queue21_buffer, 2LL, 5LL);
for ( i = 0; i <= 5; ++i )
v5 -= ((unsigned int)eclib_queue2_push(&uint16Queue21, &i) == 0) - 1;
i = 0;
v6 = v4 - ((v5 < 7u) - 1);
v7 = 0;
do
{
v7 -= ((unsigned int)eclib_queue2_pop(&uint16Queue21, v20) == 0) - 1;
++i;
}
while ( i <= 5 );
v8 = 100;
LOWORD(v2) = v6 - ((v7 < 7u) - 1);
v9 = clock();
do
{
v10 = 1000;
do
{
eclib_queue2_clear(&uint16Queue23);
for ( i = 0; i <= 0x1387; ++i )
v11 = eclib_queue2_push(&uint16Queue23, &i);
--v10;
}
while ( v10 );
--v8;
}
while ( v8 );
v12 = clock();
v13 = 100;
printf("push<%d>( %d , %d )\t%d\n", i, 1000LL, v11, (unsigned int)(v12 - v9));
v14 = clock();
do
{
v15 = 1000;
do
{
eclib_queue2_full(&uint16Queue23);
for ( i = 0; i <= 0x1387; ++i )
v16 = eclib_queue2_pop(&uint16Queue23, v20);
--v15;
}
while ( v15 );
--v13;
}
while ( v13 );
v17 = clock();
printf("pop<%d>( %d , %d )\t%d\n", i, 1000LL, v16, (unsigned int)(v17 - v14));
return v2;
}

original_code:
uint16_t eclib_test_queue2(void)
{
 uint16_t nErrors = 0;
 uint16_t nErrorsFound;
 uint32_t i, i2;
 uint32_t n, nn;
 uint32_t start_time = 0L;
 uint32_t end_time = 0L;
 eclib_status_t eStatus;
 uint32_t eclib_queue2_version_id = eclib_queue2_version();
 printf("%s: %s\tv.%x\n", "eclib_test_queue2.c", "Apr 23 2024", eclib_queue2_version_id);
 nErrorsFound = 0;
 for ( i = 0; i <= 10; i ++)
 {
  eStatus = eclib_queue2_push(&uint16Queue21, &i);
  if ( ECLIB_OK != eStatus )
  {
   nErrorsFound ++;
  }
 }
 if ( nErrorsFound > 1 )
 {
  nErrors ++;
 }
 nErrorsFound = 0;
 for ( i = 0; i <= 10; i ++)
 {
  eStatus = eclib_queue2_pop(&uint16Queue21, &i2);
  if ( ECLIB_OK != eStatus )
  {
   nErrorsFound ++;
  }
 }
 if ( nErrorsFound > 1 )
 {
  nErrors ++;
 }
 eclib_queue2_init(&uint16Queue21, uint16Queue21_buffer, sizeof(uint16_t), 5);
 nErrorsFound = 0;
 for ( i = 0; i <= 5; i ++)
 {
  eStatus = eclib_queue2_push(&uint16Queue21, &i);
  if ( ECLIB_OK != eStatus )
  {
   nErrorsFound ++;
  }
 }
 if ( nErrorsFound > ( 1 + 10 - 5 ) )
 {
  nErrors ++;
 }
 nErrorsFound = 0;
 for ( i = 0; i <= 5; i ++)
 {
  eStatus = eclib_queue2_pop(&uint16Queue21, &i2);
  if ( ECLIB_OK != eStatus )
  {
   nErrorsFound ++;
  }
 }
 if ( nErrorsFound > ( 1 + 10 - 5 ) )
 {
  nErrors ++;
 }
 nErrorsFound = 0;
 start_time = clock();
 for ( nn = 0; nn < 100; nn ++ )
 {
  for ( n = 0; n < 1000; n ++)
  {
   eStatus = eclib_queue2_clear( &uint16Queue23 );
   for ( i = 0; i < 5000UL; i ++)
   {
    eStatus = eclib_queue2_push(&uint16Queue23, &i);
    if ( ECLIB_OK != eStatus )
    {
     nErrorsFound ++;
    }
   }
  }
 }
 end_time = clock();
 printf("push<%d>( %d , %d )\t%d\n", i, n, eStatus, end_time-start_time);
 nErrorsFound = 0;
 start_time = clock();
 for ( nn = 0; nn < 100; nn ++ )
 {
  for ( n = 0; n < 1000; n ++)
  {
   eStatus = eclib_queue2_full( &uint16Queue23 );
   for ( i = 0; i < 5000UL; i ++ )
   {
    eStatus = eclib_queue2_pop( &uint16Queue23, &i2 );
    if ( ECLIB_OK != eStatus )
    {
     nErrorsFound ++;
    }
   }
  }
 }
 end_time = clock();
 printf("pop<%d>( %d , %d )\t%d\n", i, n, eStatus, end_time-start_time);
 return nErrors;
}

canonical_original_code:
unsigned short eclib_test_queue2()
{
 unsigned short nErrors = 0;
 unsigned short nErrorsFound;
 unsigned int i; unsigned int i2;
 unsigned int n; unsigned int nn;
 unsigned int start_time = 0L;
 unsigned int end_time = 0L;
 enum eclib_status_enum eStatus;
 unsigned int eclib_queue2_version_id = eclib_queue2_version();
 printf("%s: %s\tv.%x\n", "eclib_test_queue2.c", "Apr 23 2024", eclib_queue2_version_id);
 nErrorsFound = 0;
 for ( i = 0; i <= 10; i ++)
 {
  eStatus = eclib_queue2_push(&uint16Queue21, &i);
  if ( ECLIB_OK != eStatus )
  {
   nErrorsFound ++;
  }
 }
 if ( nErrorsFound > 1 )
 {
  nErrors ++;
 }
 nErrorsFound = 0;
 for ( i = 0; i <= 10; i ++)
 {
  eStatus = eclib_queue2_pop(&uint16Queue21, &i2);
  if ( ECLIB_OK != eStatus )
  {
   nErrorsFound ++;
  }
 }
 if ( nErrorsFound > 1 )
 {
  nErrors ++;
 }
 eclib_queue2_init(&uint16Queue21, uint16Queue21_buffer, sizeof(unsigned short), 5);
 nErrorsFound = 0;
 for ( i = 0; i <= 5; i ++)
 {
  eStatus = eclib_queue2_push(&uint16Queue21, &i);
  if ( ECLIB_OK != eStatus )
  {
   nErrorsFound ++;
  }
 }
 if ( nErrorsFound > ( 1 + 10 - 5 ) )
 {
  nErrors ++;
 }
 nErrorsFound = 0;
 for ( i = 0; i <= 5; i ++)
 {
  eStatus = eclib_queue2_pop(&uint16Queue21, &i2);
  if ( ECLIB_OK != eStatus )
  {
   nErrorsFound ++;
  }
 }
 if ( nErrorsFound > ( 1 + 10 - 5 ) )
 {
  nErrors ++;
 }
 nErrorsFound = 0;
 start_time = clock();
 for ( nn = 0; nn < 100; nn ++ )
 {
  for ( n = 0; n < 1000; n ++)
  {
   eStatus = eclib_queue2_clear( &uint16Queue23 );
   for ( i = 0; i < 5000UL; i ++)
   {
    eStatus = eclib_queue2_push(&uint16Queue23, &i);
    if ( ECLIB_OK != eStatus )
    {
     nErrorsFound ++;
    }
   }
  }
 }
 end_time = clock();
 printf("push<%d>( %d , %d )\t%d\n", i, n, eStatus, end_time-start_time);
 nErrorsFound = 0;
 start_time = clock();
 for ( nn = 0; nn < 100; nn ++ )
 {
  for ( n = 0; n < 1000; n ++)
  {
   eStatus = eclib_queue2_full( &uint16Queue23 );
   for ( i = 0; i < 5000UL; i ++ )
   {
    eStatus = eclib_queue2_pop( &uint16Queue23, &i2 );
    if ( ECLIB_OK != eStatus )
    {
     nErrorsFound ++;
    }
   }
  }
 }
 end_time = clock();
 printf("pop<%d>( %d , %d )\t%d\n", i, n, eStatus, end_time-start_time);
 return nErrors;
}

variable_types:
nErrors
unsigned short

variable_types:
nErrorsFound
unsigned short

variable_types:
i
unsigned int

variable_types:
n
unsigned int

variable_types:
nn
unsigned int

variable_types: enum eclib_status_enum { ECLIB_OK=0, ECLIB_INITIALIZED=1, ECLIB_ERROR=2, ECLIB_NULL_POINTER=3, ECLIB_NOT_FULL=4, ECLIB_FULL=5, ECLIB_EMPTY=6, ECLIB_FOUND=7, ECLIB_NOT_FOUND=8, ECLIB_OUT_OF_BOUNDS=9, ECLIB_NOT_IMPLEMENTED=10 }


decompiled_code:
__int64 eclib_test_set()
{
unsigned int v0; // er12
unsigned int v1; // eax
__int64 v2; // rbx
unsigned int v3; // ebx
__int16 v4; // r12
unsigned int v5; // ebx
__int16 v6; // r12
__int64 v7; // rbx
__int64 v8; // rbx
unsigned int v9; // ebx
__int64 v10; // rbx
__int16 v12[13]; // [rsp+Eh] [rbp-1Ah] BYREF

v0 = 0;
v1 = eclib_set_version();
printf("%s: %s\tv.%x\n", "eclib_test_set.c", "May 23 2025", v1);
eclib_set_init(u16Set, 2LL, 10LL);
eclib_set_init(u16Set2, 2LL, 10LL);
eclib_set_init(u16Set3, 2LL, 20LL);
eclib_set_dump(u16Set);
eclib_set_dump(u16Set2);
eclib_set_dump(u16Set3);
v12[0] = 0;
do
{
v2 = (unsigned int)eclib_set_add(u16Set, v12);
printf("set_add( %d ), %d\n", (unsigned __int16)v12[0], v2);
LOWORD(v0) = v0 - (((_DWORD)v2 == 0) - 1);
++v12[0];
}
while ( v12[0] <= 9u );
eclib_set_dump(u16Set);
eclib_set_dump(u16Set2);
eclib_set_dump(u16Set3);
v3 = eclib_set_remove(u16Set, 1LL);
printf("set_remove( 1, %d ), %d\n", 1LL, v3);
v4 = v0 - ((v3 == 0) - 1);
v5 = eclib_set_remove(u16Set, 3LL);
printf("set_remove( 1, %d ), %d\n", 3LL, v5);
v6 = v4 - ((v5 == 0) - 1);
v7 = (unsigned int)eclib_set_remove(u16Set, 5LL);
printf("set_remove( 1, %d ), %d\n", 5LL, v7);
LOWORD(v0) = v6 - (((_DWORD)v7 == 0) - 1);
eclib_set_dump(u16Set);
eclib_set_dump(u16Set2);
eclib_set_dump(u16Set3);
v12[0] = 0;
do
{
v8 = (unsigned int)eclib_set_add(u16Set2, v12);
printf("set_add( %d ), %d\n", (unsigned __int16)v12[0], v8);
LOWORD(v0) = v0 - (((_DWORD)v8 == 0) - 1);
++v12[0];
}
while ( v12[0] <= 2u );
eclib_set_dump(u16Set);
eclib_set_dump(u16Set2);
eclib_set_dump(u16Set3);
v9 = eclib_set_add_set(u16Set2, u16Set);
printf("set_add_set( 2, 1 ), %d\n", v9);
LOWORD(v0) = v0 - ((v9 == 0) - 1);
eclib_set_dump(u16Set);
eclib_set_dump(u16Set2);
eclib_set_dump(u16Set3);
v10 = (unsigned int)eclib_set_add_set(u16Set3, u16Set2);
printf("set_add_set( 3, 2 ), %d\n", v10);
LOWORD(v0) = v0 - (((_DWORD)v10 == 0) - 1);
eclib_set_dump(u16Set);
eclib_set_dump(u16Set2);
eclib_set_dump(u16Set3);
return v0;
}

canonical_decompiled_code:
__int64 func0()
{
unsigned int v0; // er12
unsigned int v1; // eax
__int64 v2; // rbx
unsigned int v3; // ebx
__int16 v4; // r12
unsigned int v5; // ebx
__int16 v6; // r12
__int64 v7; // rbx
__int64 v8; // rbx
unsigned int v9; // ebx
__int64 v10; // rbx
__int16 v12[13]; // [rsp+Eh] [rbp-1Ah] BYREF

v0 = 0;
v1 = eclib_set_version();
printf("%s: %s\tv.%x\n", "eclib_test_set.c", "May 23 2025", v1);
eclib_set_init(u16Set, 2LL, 10LL);
eclib_set_init(u16Set2, 2LL, 10LL);
eclib_set_init(u16Set3, 2LL, 20LL);
eclib_set_dump(u16Set);
eclib_set_dump(u16Set2);
eclib_set_dump(u16Set3);
v12[0] = 0;
do
{
v2 = (unsigned int)eclib_set_add(u16Set, v12);
printf("set_add( %d ), %d\n", (unsigned __int16)v12[0], v2);
LOWORD(v0) = v0 - (((_DWORD)v2 == 0) - 1);
++v12[0];
}
while ( v12[0] <= 9u );
eclib_set_dump(u16Set);
eclib_set_dump(u16Set2);
eclib_set_dump(u16Set3);
v3 = eclib_set_remove(u16Set, 1LL);
printf("set_remove( 1, %d ), %d\n", 1LL, v3);
v4 = v0 - ((v3 == 0) - 1);
v5 = eclib_set_remove(u16Set, 3LL);
printf("set_remove( 1, %d ), %d\n", 3LL, v5);
v6 = v4 - ((v5 == 0) - 1);
v7 = (unsigned int)eclib_set_remove(u16Set, 5LL);
printf("set_remove( 1, %d ), %d\n", 5LL, v7);
LOWORD(v0) = v6 - (((_DWORD)v7 == 0) - 1);
eclib_set_dump(u16Set);
eclib_set_dump(u16Set2);
eclib_set_dump(u16Set3);
v12[0] = 0;
do
{
v8 = (unsigned int)eclib_set_add(u16Set2, v12);
printf("set_add( %d ), %d\n", (unsigned __int16)v12[0], v8);
LOWORD(v0) = v0 - (((_DWORD)v8 == 0) - 1);
++v12[0];
}
while ( v12[0] <= 2u );
eclib_set_dump(u16Set);
eclib_set_dump(u16Set2);
eclib_set_dump(u16Set3);
v9 = eclib_set_add_set(u16Set2, u16Set);
printf("set_add_set( 2, 1 ), %d\n", v9);
LOWORD(v0) = v0 - ((v9 == 0) - 1);
eclib_set_dump(u16Set);
eclib_set_dump(u16Set2);
eclib_set_dump(u16Set3);
v10 = (unsigned int)eclib_set_add_set(u16Set3, u16Set2);
printf("set_add_set( 3, 2 ), %d\n", v10);
LOWORD(v0) = v0 - (((_DWORD)v10 == 0) - 1);
eclib_set_dump(u16Set);
eclib_set_dump(u16Set2);
eclib_set_dump(u16Set3);
return v0;
}

original_code:
uint16_t eclib_test_set(void) {
 uint16_t nErrors = 0;
 uint16_t i = 0;
 eclib_status_t eStatus = ECLIB_OK;
 uint32_t eclib_set_version_id = eclib_set_version();
 printf("%s: %s\tv.%x\n", "eclib_test_set.c", "Apr 23 2024", eclib_set_version_id);
 eclib_set_init(u16Set, sizeof(uint16_t), 10);
 eclib_set_init(u16Set2, sizeof(uint16_t), 10);
 eclib_set_init(u16Set3, sizeof(uint16_t), 20);
 eclib_set_dump(u16Set);
 eclib_set_dump(u16Set2);
 eclib_set_dump(u16Set3);
  for (i = 0; i < 10; i ++) {
  eStatus = eclib_set_add(u16Set, &i);
  printf("set_add( %d ), %d\n", i, eStatus);
  if ( ECLIB_OK != eStatus )
  {
   nErrors ++;
  }
 }
 eclib_set_dump(u16Set);
 eclib_set_dump(u16Set2);
 eclib_set_dump(u16Set3);
 eStatus = eclib_set_remove(u16Set, 1);
 printf("set_remove( 1, %d ), %d\n", 1, eStatus);
 if ( ECLIB_OK != eStatus )
 {
  nErrors ++;
 }
 eStatus = eclib_set_remove(u16Set, 3);
 printf("set_remove( 1, %d ), %d\n", 3, eStatus);
 if ( ECLIB_OK != eStatus )
 {
  nErrors ++;
 }
 eStatus = eclib_set_remove(u16Set, 5);
 printf("set_remove( 1, %d ), %d\n", 5, eStatus);
 if ( ECLIB_OK != eStatus )
 {
  nErrors ++;
 }
 eclib_set_dump(u16Set);
 eclib_set_dump(u16Set2);
 eclib_set_dump(u16Set3);
 for (i = 0; i < 3; i ++) {
  eStatus = eclib_set_add(u16Set2, &i);
  printf("set_add( %d ), %d\n", i, eStatus);
  if ( ECLIB_OK != eStatus )
  {
   nErrors ++;
  }
 }
 eclib_set_dump(u16Set);
 eclib_set_dump(u16Set2);
 eclib_set_dump(u16Set3);
 eStatus = eclib_set_add_set(u16Set2, u16Set);
 printf("set_add_set( 2, 1 ), %d\n", eStatus);
 if ( ECLIB_OK != eStatus )
 {
  nErrors ++;
 }
 eclib_set_dump(u16Set);
 eclib_set_dump(u16Set2);
 eclib_set_dump(u16Set3);
 eStatus = eclib_set_add_set(u16Set3, u16Set2);
 printf("set_add_set( 3, 2 ), %d\n", eStatus);
 if ( ECLIB_OK != eStatus )
 {
  nErrors ++;
 }
 eclib_set_dump(u16Set);
 eclib_set_dump(u16Set2);
 eclib_set_dump(u16Set3);
 return nErrors;
}

canonical_original_code:
unsigned short eclib_test_set() {
 unsigned short nErrors = 0;
 unsigned short i = 0;
 enum eclib_status_enum eStatus = ECLIB_OK;
 unsigned int eclib_set_version_id = eclib_set_version();
 printf("%s: %s\tv.%x\n", "eclib_test_set.c", "Apr 23 2024", eclib_set_version_id);
 eclib_set_init(u16Set, sizeof(unsigned short), 10);
 eclib_set_init(u16Set2, sizeof(unsigned short), 10);
 eclib_set_init(u16Set3, sizeof(unsigned short), 20);
 eclib_set_dump(u16Set);
 eclib_set_dump(u16Set2);
 eclib_set_dump(u16Set3);
  for (i = 0; i < 10; i ++) {
  eStatus = eclib_set_add(u16Set, &i);
  printf("set_add( %d ), %d\n", i, eStatus);
  if ( ECLIB_OK != eStatus )
  {
   nErrors ++;
  }
 }
 eclib_set_dump(u16Set);
 eclib_set_dump(u16Set2);
 eclib_set_dump(u16Set3);
 eStatus = eclib_set_remove(u16Set, 1);
 printf("set_remove( 1, %d ), %d\n", 1, eStatus);
 if ( ECLIB_OK != eStatus )
 {
  nErrors ++;
 }
 eStatus = eclib_set_remove(u16Set, 3);
 printf("set_remove( 1, %d ), %d\n", 3, eStatus);
 if ( ECLIB_OK != eStatus )
 {
  nErrors ++;
 }
 eStatus = eclib_set_remove(u16Set, 5);
 printf("set_remove( 1, %d ), %d\n", 5, eStatus);
 if ( ECLIB_OK != eStatus )
 {
  nErrors ++;
 }
 eclib_set_dump(u16Set);
 eclib_set_dump(u16Set2);
 eclib_set_dump(u16Set3);
 for (i = 0; i < 3; i ++) {
  eStatus = eclib_set_add(u16Set2, &i);
  printf("set_add( %d ), %d\n", i, eStatus);
  if ( ECLIB_OK != eStatus )
  {
   nErrors ++;
  }
 }
 eclib_set_dump(u16Set);
 eclib_set_dump(u16Set2);
 eclib_set_dump(u16Set3);
 eStatus = eclib_set_add_set(u16Set2, u16Set);
 printf("set_add_set( 2, 1 ), %d\n", eStatus);
 if ( ECLIB_OK != eStatus )
 {
  nErrors ++;
 }
 eclib_set_dump(u16Set);
 eclib_set_dump(u16Set2);
 eclib_set_dump(u16Set3);
 eStatus = eclib_set_add_set(u16Set3, u16Set2);
 printf("set_add_set( 3, 2 ), %d\n", eStatus);
 if ( ECLIB_OK != eStatus )
 {
  nErrors ++;
 }
 eclib_set_dump(u16Set);
 eclib_set_dump(u16Set2);
 eclib_set_dump(u16Set3);
 return nErrors;
}

variable_types:
i
unsigned short


decompiled_code:
__int64 eclib_test_set_2()
{
int v0; // eax
int v1; // eax
int v2; // eax
int v3; // eax
int v4; // eax
int v5; // eax
int v6; // eax
int v7; // eax
int v8; // eax
int v9; // eax
int v10; // eax
int v11; // eax
__int16 v13; // [rsp+Ch] [rbp-Ch] BYREF
__int16 v14[5]; // [rsp+Eh] [rbp-Ah] BYREF

v14[0] = 0;
eclib_set_init(container, 2LL, 10LL);
v13 = 1;
v0 = eclib_set_add(container, &v13);
printf("eclib_set_add(1): %s\n", (&set_error_msg)[v0]);
v13 = 2;
v1 = eclib_set_add(container, &v13);
printf("eclib_set_add(2): %s\n", (&set_error_msg)[v1]);
v13 = 2;
v2 = eclib_set_find(container, &v13, v14);
printf("eclib_set_find(2): %s, %d\n", (&set_error_msg)[v2], (unsigned __int16)v14[0]);
v13 = 1;
v3 = eclib_set_find(container, &v13, v14);
printf("eclib_set_find(1): %s, %d\n", (&set_error_msg)[v3], (unsigned __int16)v14[0]);
v4 = eclib_set_remove(container, 2LL);
printf("eclib_set_remove(2): %s - error expected\n", (&set_error_msg)[v4]);
v5 = eclib_set_remove(container, 1LL);
printf("eclib_set_remove(1): %s\n", (&set_error_msg)[v5]);
v13 = 2;
v6 = eclib_set_find(container, &v13, v14);
printf("eclib_set_find(2): %s, %d - error expected\n", (&set_error_msg)[v6], (unsigned __int16)v14[0]);
v13 = 1;
v7 = eclib_set_find(container, &v13, v14);
printf("eclib_set_find(1): %s, %d\n", (&set_error_msg)[v7], (unsigned __int16)v14[0]);
v13 = 2;
v8 = eclib_set_add(container, &v13);
printf("eclib_set_add(2): %s\n", (&set_error_msg)[v8]);
v9 = eclib_set_remove(container, 0LL);
printf("eclib_set_remove(0): %s\n", (&set_error_msg)[v9]);
v10 = eclib_set_find(container, &v13, v14);
printf("eclib_set_find(2): %s, %d\n", (&set_error_msg)[v10], (unsigned __int16)v14[0]);
--v13;
v11 = eclib_set_find(container, &v13, v14);
printf("eclib_set_find(1): %s, %d - error expected\n", (&set_error_msg)[v11], (unsigned __int16)v14[0]);
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
int v0; // eax
int v1; // eax
int v2; // eax
int v3; // eax
int v4; // eax
int v5; // eax
int v6; // eax
int v7; // eax
int v8; // eax
int v9; // eax
int v10; // eax
int v11; // eax
__int16 v13; // [rsp+Ch] [rbp-Ch] BYREF
__int16 v14[5]; // [rsp+Eh] [rbp-Ah] BYREF

v14[0] = 0;
eclib_set_init(container, 2LL, 10LL);
v13 = 1;
v0 = eclib_set_add(container, &v13);
printf("eclib_set_add(1): %s\n", (&set_error_msg)[v0]);
v13 = 2;
v1 = eclib_set_add(container, &v13);
printf("eclib_set_add(2): %s\n", (&set_error_msg)[v1]);
v13 = 2;
v2 = eclib_set_find(container, &v13, v14);
printf("eclib_set_find(2): %s, %d\n", (&set_error_msg)[v2], (unsigned __int16)v14[0]);
v13 = 1;
v3 = eclib_set_find(container, &v13, v14);
printf("eclib_set_find(1): %s, %d\n", (&set_error_msg)[v3], (unsigned __int16)v14[0]);
v4 = eclib_set_remove(container, 2LL);
printf("eclib_set_remove(2): %s - error expected\n", (&set_error_msg)[v4]);
v5 = eclib_set_remove(container, 1LL);
printf("eclib_set_remove(1): %s\n", (&set_error_msg)[v5]);
v13 = 2;
v6 = eclib_set_find(container, &v13, v14);
printf("eclib_set_find(2): %s, %d - error expected\n", (&set_error_msg)[v6], (unsigned __int16)v14[0]);
v13 = 1;
v7 = eclib_set_find(container, &v13, v14);
printf("eclib_set_find(1): %s, %d\n", (&set_error_msg)[v7], (unsigned __int16)v14[0]);
v13 = 2;
v8 = eclib_set_add(container, &v13);
printf("eclib_set_add(2): %s\n", (&set_error_msg)[v8]);
v9 = eclib_set_remove(container, 0LL);
printf("eclib_set_remove(0): %s\n", (&set_error_msg)[v9]);
v10 = eclib_set_find(container, &v13, v14);
printf("eclib_set_find(2): %s, %d\n", (&set_error_msg)[v10], (unsigned __int16)v14[0]);
--v13;
v11 = eclib_set_find(container, &v13, v14);
printf("eclib_set_find(1): %s, %d - error expected\n", (&set_error_msg)[v11], (unsigned __int16)v14[0]);
return 0LL;
}

original_code:
uint16_t eclib_test_set_2(void) {
 uint16_t nErrors = 0;
 uint16_t data = 1;
 uint16_t index = 0;
 eclib_status_t status;
 eclib_set_init(container, sizeof(uint16_t), 10);
 data = 1;
 status = eclib_set_add(container, &data);
 printf("eclib_set_add(1): %s\n", set_error_msg[status]);
 data = 2;
 status = eclib_set_add(container, &data);
 printf("eclib_set_add(2): %s\n", set_error_msg[status]);
 data = 2;
 status = eclib_set_find(container, &data, &index);
 printf("eclib_set_find(2): %s, %d\n", set_error_msg[status], index);
 data = 1;
 status = eclib_set_find(container, &data, &index);
 printf("eclib_set_find(1): %s, %d\n", set_error_msg[status], index);
 status = eclib_set_remove(container, 2);
 printf("eclib_set_remove(2): %s - error expected\n", set_error_msg[status]);
 status = eclib_set_remove(container, 1);
 printf("eclib_set_remove(1): %s\n", set_error_msg[status]);
 data = 2;
 status = eclib_set_find(container, &data, &index);
 printf("eclib_set_find(2): %s, %d - error expected\n", set_error_msg[status], index);
 data = 1;
 status = eclib_set_find(container, &data, &index);
 printf("eclib_set_find(1): %s, %d\n", set_error_msg[status], index);
 data = 2;
 status = eclib_set_add(container, &data);
 printf("eclib_set_add(2): %s\n", set_error_msg[status]);
 status = eclib_set_remove(container, 0);
 printf("eclib_set_remove(0): %s\n", set_error_msg[status]);
 status = eclib_set_find(container, &data, &index);
 printf("eclib_set_find(2): %s, %d\n", set_error_msg[status], index);
 data --;
 status = eclib_set_find(container, &data, &index);
 printf("eclib_set_find(1): %s, %d - error expected\n", set_error_msg[status], index);
 return nErrors;
}

canonical_original_code:
unsigned short eclib_test_set_2() {
 unsigned short nErrors = 0;
 unsigned short data = 1;
 unsigned short index = 0;
 enum eclib_status_enum status;
 eclib_set_init(container, sizeof(unsigned short), 10);
 data = 1;
 status = eclib_set_add(container, &data);
 printf("eclib_set_add(1): %s\n", set_error_msg[status]);
 data = 2;
 status = eclib_set_add(container, &data);
 printf("eclib_set_add(2): %s\n", set_error_msg[status]);
 data = 2;
 status = eclib_set_find(container, &data, &index);
 printf("eclib_set_find(2): %s, %d\n", set_error_msg[status], index);
 data = 1;
 status = eclib_set_find(container, &data, &index);
 printf("eclib_set_find(1): %s, %d\n", set_error_msg[status], index);
 status = eclib_set_remove(container, 2);
 printf("eclib_set_remove(2): %s - error expected\n", set_error_msg[status]);
 status = eclib_set_remove(container, 1);
 printf("eclib_set_remove(1): %s\n", set_error_msg[status]);
 data = 2;
 status = eclib_set_find(container, &data, &index);
 printf("eclib_set_find(2): %s, %d - error expected\n", set_error_msg[status], index);
 data = 1;
 status = eclib_set_find(container, &data, &index);
 printf("eclib_set_find(1): %s, %d\n", set_error_msg[status], index);
 data = 2;
 status = eclib_set_add(container, &data);
 printf("eclib_set_add(2): %s\n", set_error_msg[status]);
 status = eclib_set_remove(container, 0);
 printf("eclib_set_remove(0): %s\n", set_error_msg[status]);
 status = eclib_set_find(container, &data, &index);
 printf("eclib_set_find(2): %s, %d\n", set_error_msg[status], index);
 data --;
 status = eclib_set_find(container, &data, &index);
 printf("eclib_set_find(1): %s, %d - error expected\n", set_error_msg[status], index);
 return nErrors;
}

variable_types:
data
unsigned short

variable_types:
index
unsigned short


decompiled_code:
_BOOL8 eclib_test_array()
{
__int16 v0; // bp
unsigned int v1; // eax
__int64 v2; // rbx
unsigned int v3; // eax
unsigned int v4; // eax
unsigned int v5; // eax
__int16 v7[13]; // [rsp+Eh] [rbp-1Ah] BYREF

v0 = 0;
v1 = eclib_array_version();
printf("%s: %s\tv.%x\n", "eclib_test_array.c", "May 23 2025", v1);
v7[0] = 0;
do
{
v2 = (unsigned int)eclib_array_add(&uint16Array, v7, 0LL);
printf("array_add<%d>( %d , %d )\n", (unsigned __int16)v7[0], (unsigned __int16)v7[0], v2);
v0 -= ((_DWORD)v2 == 0) - 1;
++v7[0];
}
while ( v7[0] <= 0xAu );
v7[0] = 5;
v3 = eclib_array_remove(&uint16Array, 5LL);
printf("array_remove<%d>( %d )\n", (unsigned __int16)v7[0], v3);
v4 = eclib_array_add(&uint16Array, v7, 0LL);
printf("array_add<%d>( %d , %d )\n", (unsigned __int16)v7[0], (unsigned __int16)v7[0], v4);
v5 = eclib_array_add(&uint16Array, v7, 0LL);
printf("array_add<%d>( %d , %d )\n", (unsigned __int16)v7[0], (unsigned __int16)v7[0], v5);
return v0 != 1;
}

canonical_decompiled_code:
_BOOL8 func0()
{
__int16 v0; // bp
unsigned int v1; // eax
__int64 v2; // rbx
unsigned int v3; // eax
unsigned int v4; // eax
unsigned int v5; // eax
__int16 v7[13]; // [rsp+Eh] [rbp-1Ah] BYREF

v0 = 0;
v1 = eclib_array_version();
printf("%s: %s\tv.%x\n", "eclib_test_array.c", "May 23 2025", v1);
v7[0] = 0;
do
{
v2 = (unsigned int)eclib_array_add(&uint16Array, v7, 0LL);
printf("array_add<%d>( %d , %d )\n", (unsigned __int16)v7[0], (unsigned __int16)v7[0], v2);
v0 -= ((_DWORD)v2 == 0) - 1;
++v7[0];
}
while ( v7[0] <= 0xAu );
v7[0] = 5;
v3 = eclib_array_remove(&uint16Array, 5LL);
printf("array_remove<%d>( %d )\n", (unsigned __int16)v7[0], v3);
v4 = eclib_array_add(&uint16Array, v7, 0LL);
printf("array_add<%d>( %d , %d )\n", (unsigned __int16)v7[0], (unsigned __int16)v7[0], v4);
v5 = eclib_array_add(&uint16Array, v7, 0LL);
printf("array_add<%d>( %d , %d )\n", (unsigned __int16)v7[0], (unsigned __int16)v7[0], v5);
return v0 != 1;
}

original_code:
uint16_t eclib_test_array(void)
{
 uint16_t nErrors = 0;
 uint16_t i;
 eclib_status_t eStatus;
 uint16_t nErrorsFound;
 uint32_t eclib_array_version_id = eclib_array_version();
 printf("%s: %s\tv.%x\n", "eclib_test_array.c", "Apr 23 2024", eclib_array_version_id);
 nErrorsFound = 0;
 for ( i = 0; i <= 10; i ++ )
 {
  eStatus = eclib_array_add( &uint16Array, &i, ((void *)0) );
  printf("array_add<%d>( %d , %d )\n", i, i, eStatus);
  if ( ECLIB_OK != eStatus )
  {
   nErrorsFound ++;
  }
 }
 if ( 1 != nErrorsFound )
 {
  nErrors ++;
 }
 i = 5;
 eStatus = eclib_array_remove( &uint16Array, i );
 printf("array_remove<%d>( %d )\n", i, eStatus);
 if ( ECLIB_OK != eStatus )
 {
  nErrorsFound ++;
 }
 eStatus = eclib_array_add( &uint16Array, &i, ((void *)0) );
 printf("array_add<%d>( %d , %d )\n", i, i, eStatus);
 if ( ECLIB_OK != eStatus )
 {
  nErrorsFound ++;
 }
 eStatus = eclib_array_add( &uint16Array, &i, ((void *)0) );
 printf("array_add<%d>( %d , %d )\n", i, i, eStatus);
 if ( ECLIB_OK != eStatus )
 {
  nErrorsFound ++;
 }
 return nErrors;
}

canonical_original_code:
unsigned short eclib_test_array()
{
 unsigned short nErrors = 0;
 unsigned short i;
 enum eclib_status_enum eStatus;
 unsigned short nErrorsFound;
 unsigned int eclib_array_version_id = eclib_array_version();
 printf("%s: %s\tv.%x\n", "eclib_test_array.c", "Apr 23 2024", eclib_array_version_id);
 nErrorsFound = 0;
 for ( i = 0; i <= 10; i ++ )
 {
  eStatus = eclib_array_add( &uint16Array, &i, ((void *)0) );
  printf("array_add<%d>( %d , %d )\n", i, i, eStatus);
  if ( ECLIB_OK != eStatus )
  {
   nErrorsFound ++;
  }
 }
 if ( 1 != nErrorsFound )
 {
  nErrors ++;
 }
 i = 5;
 eStatus = eclib_array_remove( &uint16Array, i );
 printf("array_remove<%d>( %d )\n", i, eStatus);
 if ( ECLIB_OK != eStatus )
 {
  nErrorsFound ++;
 }
 eStatus = eclib_array_add( &uint16Array, &i, ((void *)0) );
 printf("array_add<%d>( %d , %d )\n", i, i, eStatus);
 if ( ECLIB_OK != eStatus )
 {
  nErrorsFound ++;
 }
 eStatus = eclib_array_add( &uint16Array, &i, ((void *)0) );
 printf("array_add<%d>( %d , %d )\n", i, i, eStatus);
 if ( ECLIB_OK != eStatus )
 {
  nErrorsFound ++;
 }
 return nErrors;
}


decompiled_code:
int __fastcall button_callback_fn(unsigned __int8 a1, unsigned int a2)
{
unsigned int v3[7]; // [rsp+Ch] [rbp-1Ch] BYREF

eclib_timer_start_timer(v3);
return printf("%08d: %d %d\n", v3[0], a1, a2);
}

canonical_decompiled_code:
int __fastcall func0(unsigned __int8 a1, unsigned int a2)
{
unsigned int v3[7]; // [rsp+Ch] [rbp-1Ch] BYREF

eclib_timer_start_timer(v3);
return printf("%08d: %d %d\n", v3[0], a1, a2);
}

original_code:
void button_callback_fn(uint8_t buttonId, eclib_button_reason_t reason) {
 eclib_timer_t t;
 eclib_timer_start_timer(&t);
 printf("%08d: %d %d\n", t, buttonId, reason);
}

canonical_original_code:
void button_callback_fn(unsigned char buttonId, enum eclib_button_reason reason) {
 unsigned int t;
 eclib_timer_start_timer(&t);
 printf("%08d: %d %d\n", t, buttonId, reason);
}

variable_types:
buttonId
unsigned char

variable_types: enum eclib_button_reason { ECLIB_BUTTON_NONE=0, ECLIB_BUTTON_SHORT_CLICK=1, ECLIB_BUTTON_NORMAL_CLICK=2, ECLIB_BUTTON_LONG_CLICK=3, ECLIB_BUTTON_AUTO_REPEAT=4, ECLIB_BUTTON_STICK=5 }

variable_types:
t
unsigned int