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;
}


repo: dimitarpeikov/eclib

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;
}

return_type: unsigned int


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; } *

variable_types:
pBuffer
void *

variable_types:
nUnits
unsigned short

variable_types:
nSize
unsigned short

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:
int __fastcall eclib_array_find(__int128 a1, _WORD *a2)
{
int result; // eax
int v3; // er13
__int64 v4; // r12
unsigned __int8 v5; // bp
int v6; // ebx
unsigned __int8 v7; // al
__int64 v8; // [rsp+10h] [rbp-58h]
int v9; // [rsp+18h] [rbp-50h]
unsigned __int16 v10; // [rsp+24h] [rbp-44h]
unsigned __int16 v11; // [rsp+26h] [rbp-42h]

result = 3;
if ( a1 == 0 )
return result;
v11 = *(_WORD *)(a1 + 2);
v10 = (v11 + 7) >> 3;
if ( !v10 )
return 2;
v8 = *(_QWORD *)(a1 + 8);
v3 = 0;
v4 = 0LL;
while ( 1 )
{
v7 = *(_BYTE *)(v8 + v4);
if ( !v7 )
goto LABEL_12;
if ( v11 >= v3 + 8 )
break;
v5 = v11 - v3;
if ( (_BYTE)v11 != (_BYTE)v3 )
goto LABEL_5;
LABEL_12:
++v4;
v3 += 8;
if ( v10 <= (unsigned __int16)v4 )
return 2;
}
v5 = 8;
LABEL_5:
v6 = 0;
v9 = v7;
while ( 1 )
{
if ( (v9 & (1 << v6)) == 1 )
{
result = memcmp(
(const void *)(*(_QWORD *)(a1 + 16) + *(unsigned __int16 *)(a1 + 4) * (v6 + v3)),
*((const void **)&a1 + 1),
*(unsigned __int16 *)(a1 + 4));
if ( !result )
break;
}
if ( v5 <= (unsigned __int8)++v6 )
goto LABEL_12;
}
if ( a2 )
{
*a2 = v4;
result = 0;
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(__int128 a1, _WORD *a2)
{
int result; // eax
int v3; // er13
__int64 v4; // r12
unsigned __int8 v5; // bp
int v6; // ebx
unsigned __int8 v7; // al
__int64 v8; // [rsp+10h] [rbp-58h]
int v9; // [rsp+18h] [rbp-50h]
unsigned __int16 v10; // [rsp+24h] [rbp-44h]
unsigned __int16 v11; // [rsp+26h] [rbp-42h]

result = 3;
if ( a1 == 0 )
return result;
v11 = *(_WORD *)(a1 + 2);
v10 = (v11 + 7) >> 3;
if ( !v10 )
return 2;
v8 = *(_QWORD *)(a1 + 8);
v3 = 0;
v4 = 0LL;
while ( 1 )
{
v7 = *(_BYTE *)(v8 + v4);
if ( !v7 )
goto LABEL_12;
if ( v11 >= v3 + 8 )
break;
v5 = v11 - v3;
if ( (_BYTE)v11 != (_BYTE)v3 )
goto LABEL_5;
LABEL_12:
++v4;
v3 += 8;
if ( v10 <= (unsigned __int16)v4 )
return 2;
}
v5 = 8;
LABEL_5:
v6 = 0;
v9 = v7;
while ( 1 )
{
if ( (v9 & (1 << v6)) == 1 )
{
result = memcmp(
(const void *)(*(_QWORD *)(a1 + 16) + *(unsigned __int16 *)(a1 + 4) * (v6 + v3)),
*((const void **)&a1 + 1),
*(unsigned __int16 *)(a1 + 4));
if ( !result )
break;
}
if ( v5 <= (unsigned __int8)++v6 )
goto LABEL_12;
}
if ( a2 )
{
*a2 = v4;
result = 0;
}
return result;
}

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:
pData
void *

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

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 }

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(__int64 a1, unsigned __int64 a2, _WORD *a3)
{
__int64 result; // rax
unsigned __int16 v7; // si
unsigned __int16 v8; // cx
__int64 v9; // rbx
unsigned __int8 v10; // al
unsigned __int8 v11; // dl
int v12; // ecx
int v13; // eax
unsigned int v14; // er14

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

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, unsigned __int64 a2, _WORD *a3)
{
__int64 result; // rax
unsigned __int16 v7; // si
unsigned __int16 v8; // cx
__int64 v9; // rbx
unsigned __int8 v10; // al
unsigned __int8 v11; // dl
int v12; // ecx
int v13; // eax
unsigned int v14; // er14

result = 3LL;
if ( a2 | a1 )
{
v7 = *(_WORD *)(a1 + 2);
v8 = (v7 + 7) >> 3;
if ( v8 )
{
v9 = 0LL;
while ( 1 )
{
v10 = *(_BYTE *)(*(_QWORD *)(a1 + 8) + v9);
if ( v10 != 0xFF )
break;
if ( v8 <= (unsigned __int16)++v9 )
return 2LL;
}
if ( v7 >= 8 * (unsigned __int16)v9 + 8 )
{
v11 = 8;
}
else
{
v11 = v7 - 8 * v9;
if ( (_BYTE)v7 == 8 * (_BYTE)v9 )
return 2LL;
}
v12 = v10;
if ( (v10 & 1) != 0 )
{
v13 = 1;
while ( v11 > (unsigned __int8)v13 )
{
v14 = v13++;
if ( !_bittest(&v12, v14) )
goto LABEL_16;
}
result = 2LL;
}
else
{
v14 = 0;
LABEL_16:
memcpy(
(void *)(*(_QWORD *)(a1 + 16) + (int)(*(unsigned __int16 *)(a1 + 4) * (8 * (unsigned __int16)v9 + v14))),
(const void *)a2,
*(unsigned __int16 *)(a1 + 4));
*(_BYTE *)(*(_QWORD *)(a1 + 8) + v9) |= 1 << v14;
result = 0LL;
if ( a3 )
*a3 = v9;
}
}
else
{
result = 2LL;
}
}
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;
}

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_array_get(__int64 a1, unsigned __int16 a2, unsigned __int64 a3)
{
unsigned int v4; // edx
int v5; // er8

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

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, unsigned __int16 a2, unsigned __int64 a3)
{
unsigned int v4; // edx
int v5; // er8

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

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)
{
_BYTE *v2; // rax
int v3; // ecx
int v4; // edx
unsigned int v5; // esi

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

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

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

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 )
result = (_WORD)v3 != HIWORD(v4);
else
result = v1 != 59;
if ( (_WORD)v3 == (_WORD)v6 )
{
if ( !v5 )
result = 1LL;
}
else if ( v2 != 59 || 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 )
result = (_WORD)v3 != HIWORD(v4);
else
result = v1 != 59;
if ( (_WORD)v3 == (_WORD)v6 )
{
if ( !v5 )
result = 1LL;
}
else if ( v2 != 59 || 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));
}

return_type: void


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(unsigned __int16 a1)
{
bool result; // al

result = 0;
if ( (a1 & 3) == 0 )
result = 100 * (a1 / 0x64u) != a1;
return result;
}

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

result = 0;
if ( (a1 & 3) == 0 )
result = 100 * (a1 / 0x64u) != a1;
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; // ebx
bool v1; // di
unsigned int v2; // eax
unsigned int v3; // edx
__int64 v4; // rax

v0 = HIWORD(calendar_internal_date);
v1 = calendar_get_leap_year(HIWORD(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;
do
v3 += (unsigned __int8)calendar_month_days[v4++];
while ( BYTE1(calendar_internal_date) > (unsigned __int8)v4 );
if ( v1 )
v3 -= (BYTE1(calendar_internal_date) <= 1u) - 1;
}
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; // ebx
bool v1; // di
unsigned int v2; // eax
unsigned int v3; // edx
__int64 v4; // rax

v0 = HIWORD(calendar_internal_date);
v1 = func13(HIWORD(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;
do
v3 += (unsigned __int8)calendar_month_days[v4++];
while ( BYTE1(calendar_internal_date) > (unsigned __int8)v4 );
if ( v1 )
v3 -= (BYTE1(calendar_internal_date) <= 1u) - 1;
}
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()
{
__int16 v0; // bx
bool v1; // cl
__int64 result; // rax

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

canonical_decompiled_code:
__int64 func15()
{
__int16 v0; // bx
bool v1; // cl
__int64 result; // rax

v0 = HIWORD(calendar_internal_date);
v1 = func13(HIWORD(calendar_internal_date));
LOBYTE(calendar_internal_date) = calendar_internal_date + 1;
result = (unsigned __int8)calendar_internal_date;
if ( (unsigned __int8)calendar_internal_date > v1
+ (unsigned __int8)calendar_month_days[BYTE1(calendar_internal_date)] )
{
LOBYTE(calendar_internal_date) = 0;
if ( (unsigned __int8)(BYTE1(calendar_internal_date) + 1) > 0xBu )
{
BYTE1(calendar_internal_date) = 0;
HIWORD(calendar_internal_date) = v0 + 1;
}
else
{
++BYTE1(calendar_internal_date);
}
}
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) = 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
{
++BYTE1(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) = 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
{
++BYTE1(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)
{
_BOOL4 v3; // eax

v3 = seconds_tick_test();
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)
{
_BOOL4 v3; // eax

v3 = func7();
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;
}

canonical_decompiled_code:
__int64 func0()
{
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 *

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)
{
if ( !a1 )
return 3LL;
*(_WORD *)(a1 + 4) = 0;
*(_WORD *)(a1 + 6) = 0;
return 0LL;
}

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;
}

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 __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;
}


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;
}

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_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;
}

return_type: unsigned short


decompiled_code:
__int64 __fastcall eclib_queue2_get_tail_index(unsigned __int16 *a1)
{
unsigned int v1; // edx

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

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;
}

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

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

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

result = 0LL;
if ( a1 )
{
result = (unsigned int)*a1;
if ( (_DWORD)result )
{
result = (unsigned int)__CFADD__(a2, (_DWORD)result) + a2 + (_DWORD)result;
*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 int v0; // eax
unsigned __int16 v1; // bx
unsigned int v2; // ebp
unsigned __int16 v3; // bx
__int16 v4; // bp
unsigned __int16 v5; // bx
__int16 v6; // bp
unsigned __int16 v7; // bx
int v8; // er12
int v9; // er13
int v10; // ebx
unsigned int v11; // er14
int v12; // eax
int v13; // er14
int v14; // er12
int v15; // ebx
unsigned int v16; // er13
int v17; // eax
char v19[4]; // [rsp+8h] [rbp-30h] BYREF
int v20[11]; // [rsp+Ch] [rbp-2Ch] BYREF

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


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

v0 = eclib_set_version();
printf("%s: %s\tv.%x\n", "eclib_test_set.c", "May 23 2025", v0);
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;
v1 = 0;
do
{
v2 = (unsigned int)eclib_set_add(u16Set, v12);
printf("set_add( %d ), %d\n", (unsigned __int16)v12[0], v2);
LOWORD(v1) = v1 - (((_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 = v1 - ((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(v1) = 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(v1) = v1 - (((_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(v1) = v1 - ((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(v1) = v1 - (((_DWORD)v10 == 0) - 1);
eclib_set_dump(u16Set);
eclib_set_dump(u16Set2);
eclib_set_dump(u16Set3);
return v1;
}

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

v0 = eclib_set_version();
printf("%s: %s\tv.%x\n", "eclib_test_set.c", "May 23 2025", v0);
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;
v1 = 0;
do
{
v2 = (unsigned int)eclib_set_add(u16Set, v12);
printf("set_add( %d ), %d\n", (unsigned __int16)v12[0], v2);
LOWORD(v1) = v1 - (((_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 = v1 - ((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(v1) = 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(v1) = v1 - (((_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(v1) = v1 - ((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(v1) = v1 - (((_DWORD)v10 == 0) - 1);
eclib_set_dump(u16Set);
eclib_set_dump(u16Set2);
eclib_set_dump(u16Set3);
return v1;
}

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
unsigned __int16 v13; // [rsp+Ch] [rbp-Ch] BYREF
__int16 v14[5]; // [rsp+Eh] [rbp-Ah] BYREF

v13 = 0;
eclib_set_init(container, 2LL, 10LL);
v14[0] = 1;
v0 = eclib_set_add(container, v14);
printf("eclib_set_add(1): %s\n", (&set_error_msg)[v0]);
v14[0] = 2;
v1 = eclib_set_add(container, v14);
printf("eclib_set_add(2): %s\n", (&set_error_msg)[v1]);
v14[0] = 2;
v2 = eclib_set_find(container, v14, &v13);
printf("eclib_set_find(2): %s, %d\n", (&set_error_msg)[v2], v13);
v14[0] = 1;
v3 = eclib_set_find(container, v14, &v13);
printf("eclib_set_find(1): %s, %d\n", (&set_error_msg)[v3], v13);
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]);
v14[0] = 2;
v6 = eclib_set_find(container, v14, &v13);
printf("eclib_set_find(2): %s, %d - error expected\n", (&set_error_msg)[v6], v13);
v14[0] = 1;
v7 = eclib_set_find(container, v14, &v13);
printf("eclib_set_find(1): %s, %d\n", (&set_error_msg)[v7], v13);
v14[0] = 2;
v8 = eclib_set_add(container, v14);
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, v14, &v13);
printf("eclib_set_find(2): %s, %d\n", (&set_error_msg)[v10], v13);
--v14[0];
v11 = eclib_set_find(container, v14, &v13);
printf("eclib_set_find(1): %s, %d - error expected\n", (&set_error_msg)[v11], v13);
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
unsigned __int16 v13; // [rsp+Ch] [rbp-Ch] BYREF
__int16 v14[5]; // [rsp+Eh] [rbp-Ah] BYREF

v13 = 0;
eclib_set_init(container, 2LL, 10LL);
v14[0] = 1;
v0 = eclib_set_add(container, v14);
printf("eclib_set_add(1): %s\n", (&set_error_msg)[v0]);
v14[0] = 2;
v1 = eclib_set_add(container, v14);
printf("eclib_set_add(2): %s\n", (&set_error_msg)[v1]);
v14[0] = 2;
v2 = eclib_set_find(container, v14, &v13);
printf("eclib_set_find(2): %s, %d\n", (&set_error_msg)[v2], v13);
v14[0] = 1;
v3 = eclib_set_find(container, v14, &v13);
printf("eclib_set_find(1): %s, %d\n", (&set_error_msg)[v3], v13);
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]);
v14[0] = 2;
v6 = eclib_set_find(container, v14, &v13);
printf("eclib_set_find(2): %s, %d - error expected\n", (&set_error_msg)[v6], v13);
v14[0] = 1;
v7 = eclib_set_find(container, v14, &v13);
printf("eclib_set_find(1): %s, %d\n", (&set_error_msg)[v7], v13);
v14[0] = 2;
v8 = eclib_set_add(container, v14);
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, v14, &v13);
printf("eclib_set_find(2): %s, %d\n", (&set_error_msg)[v10], v13);
--v14[0];
v11 = eclib_set_find(container, v14, &v13);
printf("eclib_set_find(1): %s, %d - error expected\n", (&set_error_msg)[v11], v13);
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()
{
unsigned int v0; // eax
__int16 v1; // bp
__int64 v2; // rbx
unsigned int v3; // eax
unsigned int v4; // eax
unsigned int v5; // eax
__int16 v7[13]; // [rsp+Eh] [rbp-1Ah] BYREF

v0 = eclib_array_version();
printf("%s: %s\tv.%x\n", "eclib_test_array.c", "May 23 2025", v0);
v7[0] = 0;
v1 = 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);
v1 -= ((_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 v1 != 1;
}

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

v0 = eclib_array_version();
printf("%s: %s\tv.%x\n", "eclib_test_array.c", "May 23 2025", v0);
v7[0] = 0;
v1 = 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);
v1 -= ((_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 v1 != 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


decompiled_code:
__int64 eclib_test_button()
{
unsigned int v0; // eax
unsigned int i; // er12
_DWORD *v3; // rbx

v0 = eclib_timer_version();
printf("%s: %s\tv.%x\n", "eclib_test_button.c", "May 23 2025", v0);
_counter_1ms = 1;
eclib_button_init(&buttonContext);
for ( i = 0; timeSimulation[33] > _counter_1ms; ++_counter_1ms )
{
v3 = timeSimulation;
do
{
if ( *v3 == _counter_1ms )
{
eclib_button_set(&buttonContext, *((unsigned __int8 *)v3 + 4), *((unsigned __int8 *)v3 + 5));
i += v3[2] != *((_DWORD *)off_1D8 + 5 * *((unsigned __int8 *)v3 + 4) + 3);
}
v3 += 3;
}
while ( v3 != (_DWORD *)(unsigned int)((_DWORD)timeSimulation + 144) );
eclib_button_process(&buttonContext);
}
printf("%s: %s\terrors detected: %d\n", "eclib_test_button.c", "May 23 2025", (unsigned __int16)i);
return i;
}

canonical_decompiled_code:
__int64 func1()
{
unsigned int v0; // eax
unsigned int i; // er12
_DWORD *v3; // rbx

v0 = eclib_timer_version();
printf("%s: %s\tv.%x\n", "eclib_test_button.c", "May 23 2025", v0);
_counter_1ms = 1;
eclib_button_init(&buttonContext);
for ( i = 0; timeSimulation[33] > _counter_1ms; ++_counter_1ms )
{
v3 = timeSimulation;
do
{
if ( *v3 == _counter_1ms )
{
eclib_button_set(&buttonContext, *((unsigned __int8 *)v3 + 4), *((unsigned __int8 *)v3 + 5));
i += v3[2] != *((_DWORD *)off_1D8 + 5 * *((unsigned __int8 *)v3 + 4) + 3);
}
v3 += 3;
}
while ( v3 != (_DWORD *)(unsigned int)((_DWORD)timeSimulation + 144) );
eclib_button_process(&buttonContext);
}
printf("%s: %s\terrors detected: %d\n", "eclib_test_button.c", "May 23 2025", (unsigned __int16)i);
return i;
}

original_code:
uint16_t eclib_test_button() {
 uint16_t idx = 0;
 uint16_t errors = 0;
 uint32_t eclib_timer_version_id = eclib_timer_version();
 printf("%s: %s\tv.%x\n", "eclib_test_button.c", "Apr 23 2024", eclib_timer_version_id);
 __counter_1ms = 1;
 eclib_button_init(&buttonContext);
 for (; __counter_1ms < timeSimulation[sizeof(timeSimulation) / sizeof(timeSimulation[0]) - 1].time; __counter_1ms ++) {
  idx = 0;
  while (idx < (sizeof(timeSimulation) / sizeof(timeSimulation[0]))) {
   if (timeSimulation[idx].time == __counter_1ms) {
    eclib_button_set(&buttonContext, timeSimulation[idx].button, timeSimulation[idx].value);
    if (timeSimulation[idx].expState != buttonContext.buttonStatePtr[timeSimulation[idx].button].value) {
     errors ++;
    }
   }
   idx ++;
  }
  eclib_button_process(&buttonContext);
 }
 printf("%s: %s\terrors detected: %d\n", "eclib_test_button.c", "Apr 23 2024", errors);
 return errors;
}

canonical_original_code:
unsigned short eclib_test_button() {
 unsigned short idx = 0;
 unsigned short errors = 0;
 unsigned int eclib_timer_version_id = eclib_timer_version();
 printf("%s: %s\tv.%x\n", "eclib_test_button.c", "Apr 23 2024", eclib_timer_version_id);
 __counter_1ms = 1;
 eclib_button_init(&buttonContext);
 for (; __counter_1ms < timeSimulation[sizeof(timeSimulation) / sizeof(timeSimulation[0]) - 1].time; __counter_1ms ++) {
  idx = 0;
  while (idx < (sizeof(timeSimulation) / sizeof(timeSimulation[0]))) {
   if (timeSimulation[idx].time == __counter_1ms) {
    eclib_button_set(&buttonContext, timeSimulation[idx].button, timeSimulation[idx].value);
    if (timeSimulation[idx].expState != buttonContext.buttonStatePtr[timeSimulation[idx].button].value) {
     errors ++;
    }
   }
   idx ++;
  }
  eclib_button_process(&buttonContext);
 }
 printf("%s: %s\terrors detected: %d\n", "eclib_test_button.c", "Apr 23 2024", errors);
 return errors;
}

variable_types:
idx
unsigned short

variable_types:
errors
unsigned short


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

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

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

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


original_code:
eclib_status_t eclib_button_init(eclib_button_context_ptr_t buttonsContextPtr) {
 uint16_t idx;
 eclib_status_t result = ECLIB_OK;
 if (((void *)0) != buttonsContextPtr) {
  for (idx = 0; idx < buttonsContextPtr->buttonCount; idx ++) {
   buttonsContextPtr->buttonStatePtr[idx].state = ECLIB_BUTTON_STATE_INIT;
   buttonsContextPtr->buttonStatePtr[idx].value = ECLIB_BUTTON_STATE_INIT;
   buttonsContextPtr->buttonStatePtr[idx].lastChange = 0L;
   buttonsContextPtr->buttonStatePtr[idx].autoRepeatChange = 0L;
   buttonsContextPtr->buttonStatePtr[idx].eventMask = 0L;
  }
 } else {
  result = ECLIB_ERROR;
 }
 return result;
}

canonical_original_code:
enum eclib_status_enum eclib_button_init(struct eclib_button_context_t *buttonsContextPtr) {
 unsigned short idx;
 enum eclib_status_enum result = ECLIB_OK;
 if (((void *)0) != buttonsContextPtr) {
  for (idx = 0; idx < buttonsContextPtr->buttonCount; idx ++) {
   buttonsContextPtr->buttonStatePtr[idx].state = ECLIB_BUTTON_STATE_INIT;
   buttonsContextPtr->buttonStatePtr[idx].value = ECLIB_BUTTON_STATE_INIT;
   buttonsContextPtr->buttonStatePtr[idx].lastChange = 0L;
   buttonsContextPtr->buttonStatePtr[idx].autoRepeatChange = 0L;
   buttonsContextPtr->buttonStatePtr[idx].eventMask = 0L;
  }
 } else {
  result = ECLIB_ERROR;
 }
 return result;
}

variable_types: struct eclib_button_context_t { struct eclib_button_definition_t { unsigned int shortClick; unsigned int normalClick; unsigned int longClick; unsigned int autoRepeat; unsigned int stick; unsigned int eventMask; void (*callback)(unsigned char buttonId, 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 } reason); } *buttonsDefPtr; struct eclib_button_state_t { unsigned int lastChange; unsigned int autoRepeatChange; enum eclib_button_status { ECLIB_BUTTON_STATE_UNINIT=0, ECLIB_BUTTON_STATE_INIT=1, ECLIB_BUTTON_STATE_RELEASED=2, ECLIB_BUTTON_STATE_PRESSED=3, ECLIB_BUTTON_STATE_REPEAT=4, ECLIB_BUTTON_STATE_STICK_FAILURE=5 } state; enum eclib_button_status { ECLIB_BUTTON_STATE_UNINIT=0, ECLIB_BUTTON_STATE_INIT=1, ECLIB_BUTTON_STATE_RELEASED=2, ECLIB_BUTTON_STATE_PRESSED=3, ECLIB_BUTTON_STATE_REPEAT=4, ECLIB_BUTTON_STATE_STICK_FAILURE=5 } value; unsigned int eventMask; } *buttonStatePtr; unsigned int lastProcess; unsigned char buttonCount; } *

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 }

user_defined_types: struct eclib_button_context_t { struct eclib_button_definition_t *buttonsDefPtr; struct eclib_button_state_t *buttonStatePtr; unsigned int lastProcess; unsigned char buttonCount; }

user_defined_types: struct eclib_button_definition_t { unsigned int shortClick; unsigned int normalClick; unsigned int longClick; unsigned int autoRepeat; unsigned int stick; unsigned int eventMask; void (*callback)(unsigned char buttonId, enum eclib_button_reason reason); }

user_defined_types: struct eclib_button_state_t { unsigned int lastChange; unsigned int autoRepeatChange; enum eclib_button_status state; enum eclib_button_status value; unsigned int eventMask; }


decompiled_code:
__int64 __fastcall eclib_button_process(__int64 a1)
{
__int64 result; // rax
unsigned __int16 v2; // bp
void (__fastcall *v3)(_QWORD, __int64); // rax
void (__fastcall *v4)(_QWORD, __int64); // rax
void (__fastcall *v5)(_QWORD, __int64); // rax
void (__fastcall *v6)(_QWORD, __int64); // rax
__int64 v7; // r12
unsigned int *v8; // rbx
unsigned int v9; // er14
int v10; // eax
void (__fastcall *v11)(_QWORD, __int64); // rax
void (__fastcall *v12)(_QWORD, __int64); // rax
int v13[15]; // [rsp+Ch] [rbp-3Ch] BYREF

v13[0] = 0;
result = eclib_timer_start_timer(v13);
if ( *(_BYTE *)(a1 + 20) )
{
v2 = 0;
do
{
v7 = *(_QWORD *)(a1 + 8) + 20LL * v2;
v8 = (unsigned int *)(*(_QWORD *)a1 + 32LL * v2);
v9 = v8[5];
if ( (unsigned __int8)eclib_timer_is_timer_started(v7) )
{
v10 = *(_DWORD *)(v7 + 16);
if ( (v10 & 0x10) == 0 )
{
if ( (v9 & 1) != 0 && (v10 & 1) == 0 && (unsigned __int8)eclib_timer_is_elapsed_timeout(v7, *v8) )
{
v3 = (void (__fastcall *)(_QWORD, __int64))*((_QWORD *)v8 + 3);
if ( v3 )
v3((unsigned __int8)v2, 1LL);
*(_DWORD *)(v7 + 16) |= 1u;
}
if ( (v9 & 2) != 0
&& (*(_BYTE *)(v7 + 16) & 2) == 0
&& (unsigned __int8)eclib_timer_is_elapsed_timeout(v7, v8[1]) )
{
v4 = (void (__fastcall *)(_QWORD, __int64))*((_QWORD *)v8 + 3);
if ( v4 )
v4((unsigned __int8)v2, 2LL);
*(_DWORD *)(v7 + 16) |= 2u;
}
if ( (v9 & 4) != 0
&& (*(_BYTE *)(v7 + 16) & 4) == 0
&& (unsigned __int8)eclib_timer_is_elapsed_timeout(v7, v8[2]) )
{
v5 = (void (__fastcall *)(_QWORD, __int64))*((_QWORD *)v8 + 3);
if ( v5 )
v5((unsigned __int8)v2, 3LL);
*(_DWORD *)(v7 + 16) |= 4u;
}
if ( (v9 & 8) != 0 )
{
if ( (*(_BYTE *)(v7 + 16) & 8) == 0 )
goto LABEL_42;
if ( (unsigned __int8)eclib_timer_is_elapsed_timeout(v7 + 4, v8[3]) )
{
v6 = (void (__fastcall *)(_QWORD, __int64))*((_QWORD *)v8 + 3);
if ( v6 )
v6((unsigned __int8)v2, 4LL);
*(_DWORD *)(v7 + 8) = 4;
*(_DWORD *)(v7 + 16) |= 8u;
eclib_timer_start_timer(v7 + 4);
}
if ( (*(_BYTE *)(v7 + 16) & 8) == 0 )
{
LABEL_42:
if ( (unsigned __int8)eclib_timer_is_elapsed_timeout(v7 + 4, v8[1] + v8[3]) )
{
v11 = (void (__fastcall *)(_QWORD, __int64))*((_QWORD *)v8 + 3);
if ( v11 )
v11((unsigned __int8)v2, 4LL);
*(_DWORD *)(v7 + 8) = 4;
*(_DWORD *)(v7 + 16) |= 8u;
eclib_timer_start_timer(v7 + 4);
}
}
}
if ( (v9 & 0x10) != 0 && (unsigned __int8)eclib_timer_is_elapsed_timeout(v7, v8[4]) )
{
v12 = (void (__fastcall *)(_QWORD, __int64))*((_QWORD *)v8 + 3);
if ( v12 )
v12((unsigned __int8)v2, 5LL);
*(_DWORD *)(v7 + 16) |= 0x10u;
}
}
}
++v2;
result = *(unsigned __int8 *)(a1 + 20);
}
while ( (unsigned __int16)result > v2 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 result; // rax
unsigned __int16 v2; // bp
void (__fastcall *v3)(_QWORD, __int64); // rax
void (__fastcall *v4)(_QWORD, __int64); // rax
void (__fastcall *v5)(_QWORD, __int64); // rax
void (__fastcall *v6)(_QWORD, __int64); // rax
__int64 v7; // r12
unsigned int *v8; // rbx
unsigned int v9; // er14
int v10; // eax
void (__fastcall *v11)(_QWORD, __int64); // rax
void (__fastcall *v12)(_QWORD, __int64); // rax
int v13[15]; // [rsp+Ch] [rbp-3Ch] BYREF

v13[0] = 0;
result = eclib_timer_start_timer(v13);
if ( *(_BYTE *)(a1 + 20) )
{
v2 = 0;
do
{
v7 = *(_QWORD *)(a1 + 8) + 20LL * v2;
v8 = (unsigned int *)(*(_QWORD *)a1 + 32LL * v2);
v9 = v8[5];
if ( (unsigned __int8)eclib_timer_is_timer_started(v7) )
{
v10 = *(_DWORD *)(v7 + 16);
if ( (v10 & 0x10) == 0 )
{
if ( (v9 & 1) != 0 && (v10 & 1) == 0 && (unsigned __int8)eclib_timer_is_elapsed_timeout(v7, *v8) )
{
v3 = (void (__fastcall *)(_QWORD, __int64))*((_QWORD *)v8 + 3);
if ( v3 )
v3((unsigned __int8)v2, 1LL);
*(_DWORD *)(v7 + 16) |= 1u;
}
if ( (v9 & 2) != 0
&& (*(_BYTE *)(v7 + 16) & 2) == 0
&& (unsigned __int8)eclib_timer_is_elapsed_timeout(v7, v8[1]) )
{
v4 = (void (__fastcall *)(_QWORD, __int64))*((_QWORD *)v8 + 3);
if ( v4 )
v4((unsigned __int8)v2, 2LL);
*(_DWORD *)(v7 + 16) |= 2u;
}
if ( (v9 & 4) != 0
&& (*(_BYTE *)(v7 + 16) & 4) == 0
&& (unsigned __int8)eclib_timer_is_elapsed_timeout(v7, v8[2]) )
{
v5 = (void (__fastcall *)(_QWORD, __int64))*((_QWORD *)v8 + 3);
if ( v5 )
v5((unsigned __int8)v2, 3LL);
*(_DWORD *)(v7 + 16) |= 4u;
}
if ( (v9 & 8) != 0 )
{
if ( (*(_BYTE *)(v7 + 16) & 8) == 0 )
goto LABEL_42;
if ( (unsigned __int8)eclib_timer_is_elapsed_timeout(v7 + 4, v8[3]) )
{
v6 = (void (__fastcall *)(_QWORD, __int64))*((_QWORD *)v8 + 3);
if ( v6 )
v6((unsigned __int8)v2, 4LL);
*(_DWORD *)(v7 + 8) = 4;
*(_DWORD *)(v7 + 16) |= 8u;
eclib_timer_start_timer(v7 + 4);
}
if ( (*(_BYTE *)(v7 + 16) & 8) == 0 )
{
LABEL_42:
if ( (unsigned __int8)eclib_timer_is_elapsed_timeout(v7 + 4, v8[1] + v8[3]) )
{
v11 = (void (__fastcall *)(_QWORD, __int64))*((_QWORD *)v8 + 3);
if ( v11 )
v11((unsigned __int8)v2, 4LL);
*(_DWORD *)(v7 + 8) = 4;
*(_DWORD *)(v7 + 16) |= 8u;
eclib_timer_start_timer(v7 + 4);
}
}
}
if ( (v9 & 0x10) != 0 && (unsigned __int8)eclib_timer_is_elapsed_timeout(v7, v8[4]) )
{
v12 = (void (__fastcall *)(_QWORD, __int64))*((_QWORD *)v8 + 3);
if ( v12 )
v12((unsigned __int8)v2, 5LL);
*(_DWORD *)(v7 + 16) |= 0x10u;
}
}
}
++v2;
result = *(unsigned __int8 *)(a1 + 20);
}
while ( (unsigned __int16)result > v2 );
}
return result;
}

original_code:
void eclib_button_process(eclib_button_context_ptr_t buttonsContextPtr) {
 uint16_t idx;
 uint32_t localTimer = 0L;
 uint32_t eventButtonMask;
 eclib_button_state_ptr_t btnStatePtr;
 eclib_button_definition_ptr_t btnDefPtr;
 eclib_timer_start_timer(&localTimer);
 for (idx = 0; idx < buttonsContextPtr->buttonCount; idx ++) {
  btnStatePtr = &(buttonsContextPtr->buttonStatePtr[idx]);
  btnDefPtr = &(buttonsContextPtr->buttonsDefPtr[idx]);
  eventButtonMask = btnDefPtr->eventMask;
  if ((0 != eclib_timer_is_timer_started(&btnStatePtr->lastChange)) && !(btnStatePtr->eventMask & 0x10)) {
   if ((eventButtonMask & 0x01) && !(btnStatePtr->eventMask & 0x01)) {
    if (eclib_timer_is_elapsed_timeout(&btnStatePtr->lastChange, btnDefPtr->shortClick)) {
     if (btnDefPtr->callback) {
      btnDefPtr->callback(idx, ECLIB_BUTTON_SHORT_CLICK);
     }
     btnStatePtr->eventMask |= 0x01;
    }
   }
   if ((eventButtonMask & 0x02) && !(btnStatePtr->eventMask & 0x02)) {
    if (eclib_timer_is_elapsed_timeout(&btnStatePtr->lastChange, btnDefPtr->normalClick)) {
     if (btnDefPtr->callback) {
      btnDefPtr->callback(idx, ECLIB_BUTTON_NORMAL_CLICK);
     }
     btnStatePtr->eventMask |= 0x02;
    }
   }
   if ((eventButtonMask & 0x04) && !(btnStatePtr->eventMask & 0x04)) {
    if (eclib_timer_is_elapsed_timeout(&btnStatePtr->lastChange, btnDefPtr->longClick)) {
     if (btnDefPtr->callback) {
      btnDefPtr->callback(idx, ECLIB_BUTTON_LONG_CLICK);
     }
     btnStatePtr->eventMask |= 0x04;
    }
   }
   if ((eventButtonMask & 0x08) && (btnStatePtr->eventMask & 0x08)) {
    if (eclib_timer_is_elapsed_timeout(&btnStatePtr->autoRepeatChange, btnDefPtr->autoRepeat)) {
     if (btnDefPtr->callback) {
      btnDefPtr->callback(idx, ECLIB_BUTTON_AUTO_REPEAT);
     }
     btnStatePtr->state = ECLIB_BUTTON_STATE_REPEAT;
     btnStatePtr->eventMask |= 0x08;
     eclib_timer_start_timer(&btnStatePtr->autoRepeatChange);
    }
   }
   if ((eventButtonMask & 0x08) && !(btnStatePtr->eventMask & 0x08)) {
    if (eclib_timer_is_elapsed_timeout(&btnStatePtr->autoRepeatChange, btnDefPtr->normalClick + btnDefPtr->autoRepeat)) {
     if (btnDefPtr->callback) {
      btnDefPtr->callback(idx, ECLIB_BUTTON_AUTO_REPEAT);
     }
     btnStatePtr->state = ECLIB_BUTTON_STATE_REPEAT;
     btnStatePtr->eventMask |= 0x08;
     eclib_timer_start_timer(&btnStatePtr->autoRepeatChange);
    }
   }
   if (eventButtonMask & 0x10) {
    if (eclib_timer_is_elapsed_timeout(&btnStatePtr->lastChange, btnDefPtr->stick)) {
     if (btnDefPtr->callback) {
      btnDefPtr->callback(idx, ECLIB_BUTTON_STATE_STICK_FAILURE);
     }
     btnStatePtr->eventMask |= 0x10;
    }
   }
  }
 }
}

canonical_original_code:
void eclib_button_process(struct eclib_button_context_t *buttonsContextPtr) {
 unsigned short idx;
 unsigned int localTimer = 0L;
 unsigned int eventButtonMask;
 struct eclib_button_state_t *btnStatePtr;
 struct eclib_button_definition_t *btnDefPtr;
 eclib_timer_start_timer(&localTimer);
 for (idx = 0; idx < buttonsContextPtr->buttonCount; idx ++) {
  btnStatePtr = &(buttonsContextPtr->buttonStatePtr[idx]);
  btnDefPtr = &(buttonsContextPtr->buttonsDefPtr[idx]);
  eventButtonMask = btnDefPtr->eventMask;
  if ((0 != eclib_timer_is_timer_started(&btnStatePtr->lastChange)) && !(btnStatePtr->eventMask & 0x10)) {
   if ((eventButtonMask & 0x01) && !(btnStatePtr->eventMask & 0x01)) {
    if (eclib_timer_is_elapsed_timeout(&btnStatePtr->lastChange, btnDefPtr->shortClick)) {
     if (btnDefPtr->callback) {
      btnDefPtr->callback(idx, ECLIB_BUTTON_SHORT_CLICK);
     }
     btnStatePtr->eventMask |= 0x01;
    }
   }
   if ((eventButtonMask & 0x02) && !(btnStatePtr->eventMask & 0x02)) {
    if (eclib_timer_is_elapsed_timeout(&btnStatePtr->lastChange, btnDefPtr->normalClick)) {
     if (btnDefPtr->callback) {
      btnDefPtr->callback(idx, ECLIB_BUTTON_NORMAL_CLICK);
     }
     btnStatePtr->eventMask |= 0x02;
    }
   }
   if ((eventButtonMask & 0x04) && !(btnStatePtr->eventMask & 0x04)) {
    if (eclib_timer_is_elapsed_timeout(&btnStatePtr->lastChange, btnDefPtr->longClick)) {
     if (btnDefPtr->callback) {
      btnDefPtr->callback(idx, ECLIB_BUTTON_LONG_CLICK);
     }
     btnStatePtr->eventMask |= 0x04;
    }
   }
   if ((eventButtonMask & 0x08) && (btnStatePtr->eventMask & 0x08)) {
    if (eclib_timer_is_elapsed_timeout(&btnStatePtr->autoRepeatChange, btnDefPtr->autoRepeat)) {
     if (btnDefPtr->callback) {
      btnDefPtr->callback(idx, ECLIB_BUTTON_AUTO_REPEAT);
     }
     btnStatePtr->state = ECLIB_BUTTON_STATE_REPEAT;
     btnStatePtr->eventMask |= 0x08;
     eclib_timer_start_timer(&btnStatePtr->autoRepeatChange);
    }
   }
   if ((eventButtonMask & 0x08) && !(btnStatePtr->eventMask & 0x08)) {
    if (eclib_timer_is_elapsed_timeout(&btnStatePtr->autoRepeatChange, btnDefPtr->normalClick + btnDefPtr->autoRepeat)) {
     if (btnDefPtr->callback) {
      btnDefPtr->callback(idx, ECLIB_BUTTON_AUTO_REPEAT);
     }
     btnStatePtr->state = ECLIB_BUTTON_STATE_REPEAT;
     btnStatePtr->eventMask |= 0x08;
     eclib_timer_start_timer(&btnStatePtr->autoRepeatChange);
    }
   }
   if (eventButtonMask & 0x10) {
    if (eclib_timer_is_elapsed_timeout(&btnStatePtr->lastChange, btnDefPtr->stick)) {
     if (btnDefPtr->callback) {
      btnDefPtr->callback(idx, ECLIB_BUTTON_STATE_STICK_FAILURE);
     }
     btnStatePtr->eventMask |= 0x10;
    }
   }
  }
 }
}

variable_types:
localTimer
unsigned int

variable_types:
eventButtonMask
unsigned int

variable_types: struct eclib_button_state_t { unsigned int lastChange; unsigned int autoRepeatChange; enum eclib_button_status { ECLIB_BUTTON_STATE_UNINIT=0, ECLIB_BUTTON_STATE_INIT=1, ECLIB_BUTTON_STATE_RELEASED=2, ECLIB_BUTTON_STATE_PRESSED=3, ECLIB_BUTTON_STATE_REPEAT=4, ECLIB_BUTTON_STATE_STICK_FAILURE=5 } state; enum eclib_button_status { ECLIB_BUTTON_STATE_UNINIT=0, ECLIB_BUTTON_STATE_INIT=1, ECLIB_BUTTON_STATE_RELEASED=2, ECLIB_BUTTON_STATE_PRESSED=3, ECLIB_BUTTON_STATE_REPEAT=4, ECLIB_BUTTON_STATE_STICK_FAILURE=5 } value; unsigned int eventMask; } *

variable_types: struct eclib_button_definition_t { unsigned int shortClick; unsigned int normalClick; unsigned int longClick; unsigned int autoRepeat; unsigned int stick; unsigned int eventMask; void (*callback)(unsigned char buttonId, 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 } reason); } *


decompiled_code:
__int64 __fastcall eclib_button_set(__int64 a1, unsigned __int8 a2, int a3)
{
__int64 result; // rax
_DWORD *v5; // rbx
int v6[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v6[0] = 0;
if ( !a1 )
return 3LL;
result = 0LL;
if ( *(_BYTE *)(a1 + 20) > a2 )
{
v5 = (_DWORD *)(*(_QWORD *)(a1 + 8) + 20LL * a2);
result = 0LL;
if ( v5[2] != a3 )
{
if ( a3 == 3 )
eclib_timer_start_timer(v6);
else
eclib_timer_stop_timer(v6);
eclib_timer_start_timer(v5);
v5[1] = *v5;
v5[3] = a3;
v5[4] = 0;
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, unsigned __int8 a2, int a3)
{
__int64 result; // rax
_DWORD *v5; // rbx
int v6[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v6[0] = 0;
if ( !a1 )
return 3LL;
result = 0LL;
if ( *(_BYTE *)(a1 + 20) > a2 )
{
v5 = (_DWORD *)(*(_QWORD *)(a1 + 8) + 20LL * a2);
result = 0LL;
if ( v5[2] != a3 )
{
if ( a3 == 3 )
eclib_timer_start_timer(v6);
else
eclib_timer_stop_timer(v6);
eclib_timer_start_timer(v5);
v5[1] = *v5;
v5[3] = a3;
v5[4] = 0;
result = 0LL;
}
}
return result;
}

original_code:
eclib_status_t eclib_button_set(eclib_button_context_ptr_t buttonsContextPtr, uint8_t buttonIndex, eclib_button_status_t buttonState) {
 uint32_t timer = 0L;
 eclib_button_state_ptr_t statePtr;
 eclib_status_t result = ECLIB_OK;
 if (0 != buttonsContextPtr) {
  if (buttonIndex < buttonsContextPtr->buttonCount) {
   statePtr = &(buttonsContextPtr->buttonStatePtr[buttonIndex]);
   if (statePtr->state != buttonState) {
    if (ECLIB_BUTTON_STATE_PRESSED == buttonState) {
     eclib_timer_start_timer(&timer);
    } else {
     eclib_timer_stop_timer(&timer);
     if (ECLIB_BUTTON_STATE_RELEASED == statePtr->state) {
      if (statePtr->state & 0x10) {
       statePtr->state = ECLIB_BUTTON_STATE_STICK_FAILURE;
      } else {
       if (statePtr->state & 0x04) {
        statePtr->state = ECLIB_BUTTON_LONG_CLICK;
       } else {
        if (statePtr->state & 0x02) {
         statePtr->state = ECLIB_BUTTON_NORMAL_CLICK;
        } else {
         if (statePtr->state & 0x01) {
          statePtr->state = ECLIB_BUTTON_SHORT_CLICK;
         } else {
         }
        }
       }
      }
     }
    }
    eclib_timer_start_timer(&statePtr->lastChange);
    statePtr->autoRepeatChange = statePtr->lastChange;
    statePtr->value = buttonState;
    statePtr->eventMask = 0L;
   }
  }
 } else {
  result = ECLIB_NULL_POINTER;
 }
 return result;
}

canonical_original_code:
enum eclib_status_enum eclib_button_set(struct eclib_button_context_t *buttonsContextPtr, unsigned char buttonIndex, enum eclib_button_status buttonState) {
 unsigned int timer = 0L;
 struct eclib_button_state_t *statePtr;
 enum eclib_status_enum result = ECLIB_OK;
 if (0 != buttonsContextPtr) {
  if (buttonIndex < buttonsContextPtr->buttonCount) {
   statePtr = &(buttonsContextPtr->buttonStatePtr[buttonIndex]);
   if (statePtr->state != buttonState) {
    if (ECLIB_BUTTON_STATE_PRESSED == buttonState) {
     eclib_timer_start_timer(&timer);
    } else {
     eclib_timer_stop_timer(&timer);
     if (ECLIB_BUTTON_STATE_RELEASED == statePtr->state) {
      if (statePtr->state & 0x10) {
       statePtr->state = ECLIB_BUTTON_STATE_STICK_FAILURE;
      } else {
       if (statePtr->state & 0x04) {
        statePtr->state = ECLIB_BUTTON_LONG_CLICK;
       } else {
        if (statePtr->state & 0x02) {
         statePtr->state = ECLIB_BUTTON_NORMAL_CLICK;
        } else {
         if (statePtr->state & 0x01) {
          statePtr->state = ECLIB_BUTTON_SHORT_CLICK;
         } else {
         }
        }
       }
      }
     }
    }
    eclib_timer_start_timer(&statePtr->lastChange);
    statePtr->autoRepeatChange = statePtr->lastChange;
    statePtr->value = buttonState;
    statePtr->eventMask = 0L;
   }
  }
 } else {
  result = ECLIB_NULL_POINTER;
 }
 return result;
}

variable_types:
buttonIndex
unsigned char

variable_types: enum eclib_button_status { ECLIB_BUTTON_STATE_UNINIT=0, ECLIB_BUTTON_STATE_INIT=1, ECLIB_BUTTON_STATE_RELEASED=2, ECLIB_BUTTON_STATE_PRESSED=3, ECLIB_BUTTON_STATE_REPEAT=4, ECLIB_BUTTON_STATE_STICK_FAILURE=5 }

variable_types:
timer
unsigned int

user_defined_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 }