PrintTemplateFact

decompiled_code:
__int64 __fastcall PrintTemplateFact(__int64 a1, __int64 a2, __int64 a3, int a4, int a5)
{
_QWORD *v7; // rbx
__int64 v8; // rbx
_QWORD *v9; // r13
int v10; // er14
__int64 v11; // r14
_QWORD *v14; // [rsp+8h] [rbp-70h]
char v15[8]; // [rsp+10h] [rbp-68h] BYREF
__int16 v16; // [rsp+18h] [rbp-60h]
__int64 v17; // [rsp+20h] [rbp-58h]

v7 = *(_QWORD **)(a3 + 32);
v14 = v7;
EnvPrintRouter(a1, a2, "(");
EnvPrintRouter(a1, a2, *(_QWORD *)(*v7 + 24LL));
v8 = v7[6];
if ( v8 )
{
v9 = (_QWORD *)(a3 + 128);
v10 = 0;
while ( 1 )
{
if ( a5 && (*(_BYTE *)(v8 + 8) & 8) == 0 )
{
DeftemplateSlotDefault(a1, v14, v8, v15, 1LL);
if ( (*(_BYTE *)(v8 + 8) & 1) != 0 )
{
if ( (unsigned int)MultifieldsEqual(v17, *v9) )
{
v8 = *(_QWORD *)(v8 + 32);
LABEL_21:
if ( !v8 )
return EnvPrintRouter(a1, a2, ")");
goto LABEL_13;
}
}
else if ( v16 == *((_WORD *)v9 - 4) && v17 == *v9 )
{
v8 = *(_QWORD *)(v8 + 32);
goto LABEL_21;
}
}
if ( !v10 )
EnvPrintRouter(a1, a2, " ");
if ( a4 )
EnvPrintRouter(a1, a2, "\n ");
EnvPrintRouter(a1, a2, "(");
EnvPrintRouter(a1, a2, *(_QWORD *)(*(_QWORD *)v8 + 24LL));
if ( (*(_BYTE *)(v8 + 8) & 1) != 0 )
{
v11 = *v9;
if ( *(_QWORD *)(*v9 + 8LL) )
{
EnvPrintRouter(a1, a2, " ");
PrintMultifield(a1, a2, *v9, 0LL, *(_QWORD *)(v11 + 8) - 1LL, 0LL);
}
}
else
{
EnvPrintRouter(a1, a2, " ");
PrintAtom(a1, a2, *((unsigned __int16 *)v9 - 4), *v9);
}
EnvPrintRouter(a1, a2, ")");
v8 = *(_QWORD *)(v8 + 32);
if ( !v8 )
return EnvPrintRouter(a1, a2, ")");
EnvPrintRouter(a1, a2, " ");
v10 = 1;
LABEL_13:
v9 += 2;
}
}
return EnvPrintRouter(a1, a2, ")");
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2, __int64 a3, int a4, int a5)
{
_QWORD *v7; // rbx
__int64 v8; // rbx
_QWORD *v9; // r13
int v10; // er14
__int64 v11; // r14
_QWORD *v14; // [rsp+8h] [rbp-70h]
char v15[8]; // [rsp+10h] [rbp-68h] BYREF
__int16 v16; // [rsp+18h] [rbp-60h]
__int64 v17; // [rsp+20h] [rbp-58h]

v7 = *(_QWORD **)(a3 + 32);
v14 = v7;
EnvPrintRouter(a1, a2, "(");
EnvPrintRouter(a1, a2, *(_QWORD *)(*v7 + 24LL));
v8 = v7[6];
if ( v8 )
{
v9 = (_QWORD *)(a3 + 128);
v10 = 0;
while ( 1 )
{
if ( a5 && (*(_BYTE *)(v8 + 8) & 8) == 0 )
{
DeftemplateSlotDefault(a1, v14, v8, v15, 1LL);
if ( (*(_BYTE *)(v8 + 8) & 1) != 0 )
{
if ( (unsigned int)MultifieldsEqual(v17, *v9) )
{
v8 = *(_QWORD *)(v8 + 32);
LABEL_21:
if ( !v8 )
return EnvPrintRouter(a1, a2, ")");
goto LABEL_13;
}
}
else if ( v16 == *((_WORD *)v9 - 4) && v17 == *v9 )
{
v8 = *(_QWORD *)(v8 + 32);
goto LABEL_21;
}
}
if ( !v10 )
EnvPrintRouter(a1, a2, " ");
if ( a4 )
EnvPrintRouter(a1, a2, "\n ");
EnvPrintRouter(a1, a2, "(");
EnvPrintRouter(a1, a2, *(_QWORD *)(*(_QWORD *)v8 + 24LL));
if ( (*(_BYTE *)(v8 + 8) & 1) != 0 )
{
v11 = *v9;
if ( *(_QWORD *)(*v9 + 8LL) )
{
EnvPrintRouter(a1, a2, " ");
PrintMultifield(a1, a2, *v9, 0LL, *(_QWORD *)(v11 + 8) - 1LL, 0LL);
}
}
else
{
EnvPrintRouter(a1, a2, " ");
PrintAtom(a1, a2, *((unsigned __int16 *)v9 - 4), *v9);
}
EnvPrintRouter(a1, a2, ")");
v8 = *(_QWORD *)(v8 + 32);
if ( !v8 )
return EnvPrintRouter(a1, a2, ")");
EnvPrintRouter(a1, a2, " ");
v10 = 1;
LABEL_13:
v9 += 2;
}
}
return EnvPrintRouter(a1, a2, ")");
}

original_code:
void PrintTemplateFact(
  void *theEnv,
  char *logicalName,
  struct fact *theFact,
  int seperateLines,
  int ignoreDefaults)
  {
   struct field *sublist;
   int i;
   struct deftemplate *theDeftemplate;
   struct templateSlot *slotPtr;
   DATA_OBJECT tempDO;
   int slotPrinted = 0;
   theDeftemplate = theFact->whichDeftemplate;
   sublist = theFact->theProposition.theFields;
   EnvPrintRouter(theEnv,logicalName,"(");
   EnvPrintRouter(theEnv,logicalName,theDeftemplate->header.name->contents);
   slotPtr = theDeftemplate->slotList;
   i = 0;
   while (slotPtr != ((void *)0))
     {
      if (ignoreDefaults && (slotPtr->defaultDynamic == 0))
        {
         DeftemplateSlotDefault(theEnv,theDeftemplate,slotPtr,&tempDO,1);
         if (slotPtr->multislot == 0)
           {
            if ((((tempDO).type) == sublist[i].type) &&
                (((tempDO).value) == sublist[i].value))
              {
               i++;
               slotPtr = slotPtr->next;
               continue;
              }
           }
         else if (MultifieldsEqual((struct multifield*) ((tempDO).value),
                                   (struct multifield *) sublist[i].value))
           {
            i++;
            slotPtr = slotPtr->next;
            continue;
           }
        }
      if (! slotPrinted)
        {
         slotPrinted = 1;
         EnvPrintRouter(theEnv,logicalName," ");
        }
      if (seperateLines)
        { EnvPrintRouter(theEnv,logicalName,"\n   "); }
      EnvPrintRouter(theEnv,logicalName,"(");
      EnvPrintRouter(theEnv,logicalName,slotPtr->slotName->contents);
      if (slotPtr->multislot == 0)
        {
         EnvPrintRouter(theEnv,logicalName," ");
         PrintAtom(theEnv,logicalName,sublist[i].type,sublist[i].value);
        }
      else
        {
         struct multifield *theSegment;
         theSegment = (struct multifield *) sublist[i].value;
         if (theSegment->multifieldLength > 0)
           {
            EnvPrintRouter(theEnv,logicalName," ");
            PrintMultifield(theEnv,logicalName,(struct multifield *) sublist[i].value,
                            0,(long) theSegment->multifieldLength-1,0);
           }
        }
      i++;
      EnvPrintRouter(theEnv,logicalName,")");
      slotPtr = slotPtr->next;
      if (slotPtr != ((void *)0)) EnvPrintRouter(theEnv,logicalName," ");
     }
   EnvPrintRouter(theEnv,logicalName,")");
  }

canonical_original_code:
void PrintTemplateFact(void *theEnv, char *logicalName, struct fact *theFact, int seperateLines, int ignoreDefaults)
  {
   struct field *sublist;
   int i;
   struct deftemplate *theDeftemplate;
   struct templateSlot *slotPtr;
   struct dataObject tempDO;
   int slotPrinted = 0;
   theDeftemplate = theFact->whichDeftemplate;
   sublist = theFact->theProposition.theFields;
   EnvPrintRouter(theEnv,logicalName,"(");
   EnvPrintRouter(theEnv,logicalName,theDeftemplate->header.name->contents);
   slotPtr = theDeftemplate->slotList;
   i = 0;
   while (slotPtr != ((void *)0))
     {
      if (ignoreDefaults && (slotPtr->defaultDynamic == 0))
        {
         DeftemplateSlotDefault(theEnv,theDeftemplate,slotPtr,&tempDO,1);
         if (slotPtr->multislot == 0)
           {
            if ((((tempDO).type) == sublist[i].type) &&
                (((tempDO).value) == sublist[i].value))
              {
               i++;
               slotPtr = slotPtr->next;
               continue;
              }
           }
         else if (MultifieldsEqual((struct multifield *) ((tempDO).value),
                                   (struct multifield *) sublist[i].value))
           {
            i++;
            slotPtr = slotPtr->next;
            continue;
           }
        }
      if (! slotPrinted)
        {
         slotPrinted = 1;
         EnvPrintRouter(theEnv,logicalName," ");
        }
      if (seperateLines)
        { EnvPrintRouter(theEnv,logicalName,"\n   "); }
      EnvPrintRouter(theEnv,logicalName,"(");
      EnvPrintRouter(theEnv,logicalName,slotPtr->slotName->contents);
      if (slotPtr->multislot == 0)
        {
         EnvPrintRouter(theEnv,logicalName," ");
         PrintAtom(theEnv,logicalName,sublist[i].type,sublist[i].value);
        }
      else
        {
         struct multifield *theSegment;
         theSegment = (struct multifield *) sublist[i].value;
         if (theSegment->multifieldLength > 0)
           {
            EnvPrintRouter(theEnv,logicalName," ");
            PrintMultifield(theEnv,logicalName,(struct multifield *) sublist[i].value,
                            0,(long) theSegment->multifieldLength-1,0);
           }
        }
      i++;
      EnvPrintRouter(theEnv,logicalName,")");
      slotPtr = slotPtr->next;
      if (slotPtr != ((void *)0)) EnvPrintRouter(theEnv,logicalName," ");
     }
   EnvPrintRouter(theEnv,logicalName,")");
  }

variable_types:
theEnv
void *

variable_types:
logicalName
char *

variable_types: seperateLines int

variable_types: ignoreDefaults int

variable_types: struct dataObject { void *supplementalInfo; unsigned short type; void *value; long begin; long end; struct dataObject *next; }

variable_types: slotPrinted int

variable_types: struct multifield { unsigned int busyCount; short depth; unsigned long multifieldLength; struct multifield *next; struct field { unsigned short type; void *value; } theFields[1]; } *

user_defined_types: struct templateSlot { struct symbolHashNode *slotName; unsigned int multislot; unsigned int noDefault; unsigned int defaultPresent; unsigned int defaultDynamic; struct constraintRecord *constraints; struct expr *defaultList; struct templateSlot *next; }

user_defined_types: struct patternEntity { struct patternEntityRecord *theInfo; void *dependents; unsigned int busyCount; long timeTag; }

user_defined_types: struct constructHeader { struct symbolHashNode *name; char *ppForm; struct defmoduleItemHeader *whichModule; long bsaveID; struct constructHeader *next; struct userData *usrData; }

user_defined_types: struct patternEntityRecord { struct entityRecord base; void (*decrementBasisCount)(void *, void *); void (*incrementBasisCount)(void *, void *); void (*matchFunction)(void *, void *); int (*synchronized)(void *, void *); }

user_defined_types: struct defmoduleItemHeader { struct defmodule *theModule; struct constructHeader *firstItem; struct constructHeader *lastItem; }

user_defined_types: struct entityRecord { char *name; unsigned int type; unsigned int copyToEvaluate; unsigned int bitMap; unsigned int addsToRuleComplexity; void (*shortPrintFunction)(void *, char *, void *); void (*longPrintFunction)(void *, char *, void *); int (*deleteFunction)(void *, void *); int (*evaluateFunction)(void *, void *, struct dataObject *); void *(*getNextFunction)(void *, void *); void (*decrementBusyCount)(void *, void *); void (*incrementBusyCount)(void *, void *); void (*propagateDepth)(void *, void *); void (*markNeeded)(void *, void *); void (*install)(void *, void *); void (*deinstall)(void *, void *); struct userData *usrData; }

user_defined_types: struct defmodule { struct symbolHashNode *name; char *ppForm; struct defmoduleItemHeader **itemsArray; struct portItem *importList; struct portItem *exportList; unsigned int visitedFlag; long bsaveID; struct userData *usrData; struct defmodule *next; }

user_defined_types: struct genericMatch { union { void *theValue; struct alphaMatch *theMatch; } gm; }

user_defined_types: struct alphaMatch { struct patternEntity *matchingItem; struct multifieldMarker *markers; struct alphaMatch *next; }


repo: dingram/led-display

decompiled_code:
__int64 __fastcall ldisplay_setAll(int a1)
{
__int64 result; // rax
char v2; // [rsp+8h] [rbp-10h] BYREF
int v3; // [rsp+9h] [rbp-Fh]
__int16 v4; // [rsp+Dh] [rbp-Bh]
char v5; // [rsp+Fh] [rbp-9h]

v3 = 0;
v4 = 0;
v5 = 0;
v2 = brightness;
if ( !a1 )
{
*(_WORD *)((char *)&v3 + 1) = -1;
HIBYTE(v3) = -1;
v4 = -1;
v5 = -1;
}
LOBYTE(v3) = 0;
while ( 1 )
{
result = control_msg(&v2, 8LL);
if ( (int)result < 0 )
break;
LOBYTE(v3) = v3 + 2;
if ( (char)v3 > 6 )
return 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(int a1)
{
__int64 result; // rax
char v2; // [rsp+8h] [rbp-10h] BYREF
int v3; // [rsp+9h] [rbp-Fh]
__int16 v4; // [rsp+Dh] [rbp-Bh]
char v5; // [rsp+Fh] [rbp-9h]

v3 = 0;
v4 = 0;
v5 = 0;
v2 = brightness;
if ( !a1 )
{
*(_WORD *)((char *)&v3 + 1) = -1;
HIBYTE(v3) = -1;
v4 = -1;
v5 = -1;
}
LOBYTE(v3) = 0;
while ( 1 )
{
result = func10(&v2, 8LL);
if ( (int)result < 0 )
break;
LOBYTE(v3) = v3 + 2;
if ( (char)v3 > 6 )
return 0LL;
}
return result;
}

original_code:
int ldisplay_setAll(int val) {
  char msg[] = { _brightness, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  if (!val) {
    int i;
    for (i=2; i<8; ++i)
      msg[i] |= 0xff;
  }
  for (msg[1]=0; msg[1]<7; msg[1]+=2) {
    int ret;
    if ((ret = _control_msg(msg, 8)) < 0) {
      return ret;
    }
  }
  return 0;
}

variable_types: val int

variable_types:
msg
char []

variable_types: i int

variable_types: ret int

return_type: int


decompiled_code:
__int64 ldisplay_reset()
{
return ldisplay_setAll(0);
}

canonical_decompiled_code:
__int64 func13()
{
return func12(0);
}

original_code:
int ldisplay_reset() {
  return ldisplay_setAll(0);
}


decompiled_code:
__int64 __fastcall ldisplay_setDisplay(__int64 a1)
{
unsigned __int8 v1; // dl
char *v2; // rbx
__int64 result; // rax
__int64 v4; // rsi
unsigned int v5; // eax
unsigned int v6; // eax
char v7; // [rsp+8h] [rbp-20h] BYREF
int v8; // [rsp+9h] [rbp-1Fh]
__int16 v9; // [rsp+Dh] [rbp-1Bh] BYREF
char v10; // [rsp+Fh] [rbp-19h]

v8 = 0;
v9 = 0;
v10 = 0;
v7 = brightness;
v1 = 0;
while ( 1 )
{
v4 = 4LL * v1;
v5 = *(_DWORD *)(a1 + v4);
HIBYTE(v8) = ~(unsigned __int8)(v5 >> 13);
BYTE2(v8) = ~(v5 >> 5);
BYTE1(v8) = ~(8 * v5);
if ( v1 > 5u )
{
v9 = 0;
v10 = 0;
}
else
{
v6 = *(_DWORD *)(a1 + v4 + 4);
v10 = ~(unsigned __int8)(v6 >> 13);
HIBYTE(v9) = ~(v6 >> 5);
LOBYTE(v9) = ~(8 * v6) | 7;
}
v2 = &v7;
do
{
v2[2] = swapbits((unsigned __int8)v2[2]);
++v2;
}
while ( v2 != (char *)&v9 + 1 );
result = control_msg(&v7, 8LL);
if ( (int)result < 0 )
break;
v1 = v8 + 2;
LOBYTE(v8) = v1;
if ( v1 > 6u )
return 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1)
{
unsigned __int8 v1; // dl
char *v2; // rbx
__int64 result; // rax
__int64 v4; // rsi
unsigned int v5; // eax
unsigned int v6; // eax
char v7; // [rsp+8h] [rbp-20h] BYREF
int v8; // [rsp+9h] [rbp-1Fh]
__int16 v9; // [rsp+Dh] [rbp-1Bh] BYREF
char v10; // [rsp+Fh] [rbp-19h]

v8 = 0;
v9 = 0;
v10 = 0;
v7 = brightness;
v1 = 0;
while ( 1 )
{
v4 = 4LL * v1;
v5 = *(_DWORD *)(a1 + v4);
HIBYTE(v8) = ~(unsigned __int8)(v5 >> 13);
BYTE2(v8) = ~(v5 >> 5);
BYTE1(v8) = ~(8 * v5);
if ( v1 > 5u )
{
v9 = 0;
v10 = 0;
}
else
{
v6 = *(_DWORD *)(a1 + v4 + 4);
v10 = ~(unsigned __int8)(v6 >> 13);
HIBYTE(v9) = ~(v6 >> 5);
LOBYTE(v9) = ~(8 * v6) | 7;
}
v2 = &v7;
do
{
v2[2] = func8((unsigned __int8)v2[2]);
++v2;
}
while ( v2 != (char *)&v9 + 1 );
result = func10(&v7, 8LL);
if ( (int)result < 0 )
break;
v1 = v8 + 2;
LOBYTE(v8) = v1;
if ( v1 > 6u )
return 0LL;
}
return result;
}

variable_types:
data
unsigned int [7]

variable_types:
msg
unsigned char []


decompiled_code:
__int64 __fastcall ldisplay_showTime(unsigned int a1, unsigned int a2)
{
__int64 result; // rax
__int64 v3[3]; // [rsp+0h] [rbp-48h] BYREF
int v4; // [rsp+18h] [rbp-30h]

if ( a1 > 0x270F )
return 2LL;
result = 2LL;
if ( a2 <= 1 )
{
v3[0] = 0LL;
v3[1] = 0LL;
v3[2] = 0LL;
v4 = 0;
overlay(&time_font_colon, (WINDOW *)v3);
if ( a2 )
{
overlay((const WINDOW *)((char *)&time_segment_font_digits + 28 * (a1 % 0xA)), (WINDOW *)v3);
overlay((const WINDOW *)((char *)&time_segment_font_digits + 28 * (a1 / 0xA % 0xA)), (WINDOW *)v3);
overlay((const WINDOW *)((char *)&time_segment_font_digits + 28 * (a1 / 0x64 % 0xA)), (WINDOW *)v3);
overlay((const WINDOW *)((char *)&time_segment_font_digits + 28 * (a1 / 0x3E8 % 0xA)), (WINDOW *)v3);
}
else
{
overlay((const WINDOW *)((char *)&time_font_digits + 28 * (a1 % 0xA)), (WINDOW *)v3);
overlay((const WINDOW *)((char *)&time_font_digits + 28 * (a1 / 0xA % 0xA)), (WINDOW *)v3);
overlay((const WINDOW *)((char *)&time_font_digits + 28 * (a1 / 0x64 % 0xA)), (WINDOW *)v3);
overlay((const WINDOW *)((char *)&time_font_digits + 28 * (a1 / 0x3E8 % 0xA)), (WINDOW *)v3);
}
result = ldisplay_setDisplay((__int64)v3);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func15(unsigned int a1, unsigned int a2)
{
__int64 result; // rax
__int64 v3[3]; // [rsp+0h] [rbp-48h] BYREF
int v4; // [rsp+18h] [rbp-30h]

if ( a1 > 0x270F )
return 2LL;
result = 2LL;
if ( a2 <= 1 )
{
v3[0] = 0LL;
v3[1] = 0LL;
v3[2] = 0LL;
v4 = 0;
func9(&time_font_colon, (WINDOW *)v3);
if ( a2 )
{
func9((const WINDOW *)((char *)&time_segment_font_digits + 28 * (a1 % 0xA)), (WINDOW *)v3);
func9((const WINDOW *)((char *)&time_segment_font_digits + 28 * (a1 / 0xA % 0xA)), (WINDOW *)v3);
func9((const WINDOW *)((char *)&time_segment_font_digits + 28 * (a1 / 0x64 % 0xA)), (WINDOW *)v3);
func9((const WINDOW *)((char *)&time_segment_font_digits + 28 * (a1 / 0x3E8 % 0xA)), (WINDOW *)v3);
}
else
{
func9((const WINDOW *)((char *)&time_font_digits + 28 * (a1 % 0xA)), (WINDOW *)v3);
func9((const WINDOW *)((char *)&time_font_digits + 28 * (a1 / 0xA % 0xA)), (WINDOW *)v3);
func9((const WINDOW *)((char *)&time_font_digits + 28 * (a1 / 0x64 % 0xA)), (WINDOW *)v3);
func9((const WINDOW *)((char *)&time_font_digits + 28 * (a1 / 0x3E8 % 0xA)), (WINDOW *)v3);
}
result = func14((__int64)v3);
}
return result;
}

original_code:
int ldisplay_showTime(unsigned int time, int style) {
  if (time>9999 || style<0 || style>1) {
    return 2;
  }
  uint32_t buffer[7] = {0};
  _overlay(time_font_colon, buffer, 0, 0);
  if (style) {
    _overlay(time_segment_font_digits[(time )%10], buffer, 0, 0);
    _overlay(time_segment_font_digits[(time/10 )%10], buffer, - 5, 0);
    _overlay(time_segment_font_digits[(time/100 )%10], buffer, -12, 0);
    _overlay(time_segment_font_digits[(time/1000)%10], buffer, -17, 0);
  } else {
    _overlay(time_font_digits[(time )%10], buffer, 0, 0);
    _overlay(time_font_digits[(time/10 )%10], buffer, - 5, 0);
    _overlay(time_font_digits[(time/100 )%10], buffer, -12, 0);
    _overlay(time_font_digits[(time/1000)%10], buffer, -17, 0);
  }
  return ldisplay_setDisplay(buffer);
}

canonical_original_code:
int ldisplay_showTime(unsigned int time, int style) {
  if (time>9999 || style<0 || style>1) {
    return 2;
  }
  unsigned int buffer[7] = {0};
  _overlay(time_font_colon, buffer, 0, 0);
  if (style) {
    _overlay(time_segment_font_digits[(time )%10], buffer, 0, 0);
    _overlay(time_segment_font_digits[(time/10 )%10], buffer, - 5, 0);
    _overlay(time_segment_font_digits[(time/100 )%10], buffer, -12, 0);
    _overlay(time_segment_font_digits[(time/1000)%10], buffer, -17, 0);
  } else {
    _overlay(time_font_digits[(time )%10], buffer, 0, 0);
    _overlay(time_font_digits[(time/10 )%10], buffer, - 5, 0);
    _overlay(time_font_digits[(time/100 )%10], buffer, -12, 0);
    _overlay(time_font_digits[(time/1000)%10], buffer, -17, 0);
  }
  return ldisplay_setDisplay(buffer);
}

variable_types:
time
unsigned int

variable_types: style int

variable_types:
buffer
unsigned int [7]


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

result = 2LL;
if ( (unsigned __int8)a1 > 2u )
a1 = 2;
brightness = a1;
return result;
}

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

result = 2LL;
if ( (unsigned __int8)a1 > 2u )
a1 = 2;
brightness = a1;
return result;
}

original_code:
void ldisplay_setBrightness(unsigned char brightness) {
  if (brightness>2)
    brightness=2;
  _brightness = brightness;
}

variable_types:
brightness
unsigned char

return_type: void


decompiled_code:
__int64 __fastcall ldisplay_showChars(char *a1)
{
__int64 v2[3]; // [rsp+0h] [rbp-48h] BYREF
int v3; // [rsp+18h] [rbp-30h]

v2[0] = 0LL;
v2[1] = 0LL;
v2[2] = 0LL;
v3 = 0;
overlay((const WINDOW *)((char *)&font_std_fixed_ascii + 28 * (unsigned int)*a1), (WINDOW *)v2);
overlay((const WINDOW *)((char *)&font_std_fixed_ascii + 28 * (unsigned int)a1[1]), (WINDOW *)v2);
overlay((const WINDOW *)((char *)&font_std_fixed_ascii + 28 * (unsigned int)a1[2]), (WINDOW *)v2);
overlay((const WINDOW *)((char *)&font_std_fixed_ascii + 28 * (unsigned int)a1[3]), (WINDOW *)v2);
return ldisplay_setDisplay((__int64)v2);
}

canonical_decompiled_code:
__int64 __fastcall func17(char *a1)
{
__int64 v2[3]; // [rsp+0h] [rbp-48h] BYREF
int v3; // [rsp+18h] [rbp-30h]

v2[0] = 0LL;
v2[1] = 0LL;
v2[2] = 0LL;
v3 = 0;
func9((const WINDOW *)((char *)&font_std_fixed_ascii + 28 * (unsigned int)*a1), (WINDOW *)v2);
func9((const WINDOW *)((char *)&font_std_fixed_ascii + 28 * (unsigned int)a1[1]), (WINDOW *)v2);
func9((const WINDOW *)((char *)&font_std_fixed_ascii + 28 * (unsigned int)a1[2]), (WINDOW *)v2);
func9((const WINDOW *)((char *)&font_std_fixed_ascii + 28 * (unsigned int)a1[3]), (WINDOW *)v2);
return func14((__int64)v2);
}

original_code:
int ldisplay_showChars(const char chars[4], char offset) {
  uint32_t buffer[7] = {0};
  _overlay(font_std_fixed_ascii[(unsigned)chars[0]], buffer, offset - 21, 0);
  _overlay(font_std_fixed_ascii[(unsigned)chars[1]], buffer, offset - 16, 0);
  _overlay(font_std_fixed_ascii[(unsigned)chars[2]], buffer, offset - 11, 0);
  _overlay(font_std_fixed_ascii[(unsigned)chars[3]], buffer, offset - 6, 0);
  return ldisplay_setDisplay(buffer);
}

canonical_original_code:
int ldisplay_showChars(char chars[4], char offset) {
  unsigned int buffer[7] = {0};
  _overlay(font_std_fixed_ascii[(unsigned int)chars[0]], buffer, offset - 21, 0);
  _overlay(font_std_fixed_ascii[(unsigned int)chars[1]], buffer, offset - 16, 0);
  _overlay(font_std_fixed_ascii[(unsigned int)chars[2]], buffer, offset - 11, 0);
  _overlay(font_std_fixed_ascii[(unsigned int)chars[3]], buffer, offset - 6, 0);
  return ldisplay_setDisplay(buffer);
}

variable_types:
chars
char [4]

variable_types: offset char


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

if ( udev )
{
usb_release_interface();
result = usb_close();
}
return result;
}

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

if ( udev )
{
usb_release_interface();
result = usb_close();
}
return result;
}

original_code:
void ldisplay_cleanup() {
 if (!udev)
    return;
 usb_release_interface(udev,0);
  usb_close(udev);
}


decompiled_code:
int __fastcall ldisplay_dumpBuffer(_DWORD *a1)
{
_DWORD *v1; // rbp
_DWORD *v2; // r14
int i; // ebx
const char *v4; // rdi

putchar(10);
v1 = a1;
v2 = a1 + 7;
do
{
for ( i = 21; i != -1; --i )
{
v4 = "-";
if ( ((*v1 >> i) & 1) != 0 )
v4 = "#";
printf(v4);
}
putchar(10);
++v1;
}
while ( v1 != v2 );
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func19(_DWORD *a1)
{
_DWORD *v1; // rbp
_DWORD *v2; // r14
int i; // ebx
const char *v4; // rdi

putchar(10);
v1 = a1;
v2 = a1 + 7;
do
{
for ( i = 21; i != -1; --i )
{
v4 = "-";
if ( ((*v1 >> i) & 1) != 0 )
v4 = "#";
printf(v4);
}
putchar(10);
++v1;
}
while ( v1 != v2 );
return putchar(10);
}

original_code:
void ldisplay_dumpBuffer(uint32_t data[7]) {
  int i, j;
  printf("\n");
  for (i=0; i<7; ++i) {
    for (j=21; j>=0; --j) {
      printf( ((data[i] >> j) & 0x1) ? "#" : "-" );
    }
    printf("\n");
  }
  printf("\n");
}

canonical_original_code:
void ldisplay_dumpBuffer(unsigned int data[7]) {
  int i; int j;
  printf("\n");
  for (i=0; i<7; ++i) {
    for (j=21; j>=0; --j) {
      printf( ((data[i] >> j) & 0x1) ? "#" : "-" );
    }
    printf("\n");
  }
  printf("\n");
}

variable_types: j int


putchar

repo: dioptre/newos

decompiled_code:
__int64 __fastcall putchar(char a1)
{
__int64 result; // rax
char v2[12]; // [rsp+Ch] [rbp-Ch] BYREF

v2[0] = a1;
if ( of_output_handle )
result = of_write((unsigned int)of_output_handle, v2, 1LL);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char a1)
{
__int64 result; // rax
char v2[12]; // [rsp+Ch] [rbp-Ch] BYREF

v2[0] = a1;
if ( of_output_handle )
result = of_write((unsigned int)of_output_handle, v2, 1LL);
return result;
}

original_code:
void putchar(char c)
{
 if(of_output_handle != 0)
  of_write(of_output_handle, &c, 1);
}

variable_types: c char


puts

decompiled_code:
__int64 __fastcall puts(char *a1)
{
char *v1; // rbx
__int64 result; // rax

v1 = a1;
for ( result = (unsigned __int8)*a1; (_BYTE)result; result = (unsigned __int8)*v1 )
{
if ( (_BYTE)result == 10 )
putchar(13);
putchar(*v1++);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *a1)
{
char *v1; // rbx
__int64 result; // rax

v1 = a1;
for ( result = (unsigned __int8)*a1; (_BYTE)result; result = (unsigned __int8)*v1 )
{
if ( (_BYTE)result == 10 )
func0(13);
func0(*v1++);
}
return result;
}

original_code:
void puts(char *str)
{
 while(*str) {
  if(*str == '\n')
   putchar('\r');
  putchar(*str);
  str++;
 }
}

variable_types:
str
char *


original_code:
void write_hex(unsigned int val)
{
 char buf[16];
 int pos;
 buf[15] = 0;
 for(pos = 14; pos >= 2 && val != 0; pos--) {
  int hex = val % 16;
  buf[pos] = hex < 10 ? hex + '0' : (hex - 10) + 'a';
  val /= 16;
 }
 buf[pos--] = 'x';
 buf[pos] = '0';
 puts(&buf[pos]);
}

variable_types:
val
unsigned int

variable_types:
buf
char [16]

variable_types: pos int

variable_types: hex int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
FILE *v3; // r12
int v4; // er13
char i; // bp
int v6; // ebx
char ptr[41]; // [rsp+Fh] [rbp-29h] BYREF

v3 = stdin;
v4 = 1;
for ( i = 0; ; ++i )
{
v6 = feof(v3);
if ( v6 || (unsigned int)fread(ptr, 1uLL, 1uLL, v3) != 1 )
break;
if ( (i & 0xF) != 0 )
{
putchar(44);
}
else
{
if ( !v4 )
putchar(10);
printf(".byte\t");
v4 = v6;
}
printf("0x%02x", (unsigned __int8)ptr[0]);
}
putchar(10);
return 0;
}

original_code:
int main(int argc, char **argv)
{
 char *file = ((void *)0);
    section *s;
    if(argc < 2){
usage:
        fprintf(stderr,"usage: %s [--littleendian (default)] [--bigendian ] [ --strip-binary <binary ] [ --strip-debug] [ --sparc | -s ] [ <inifile> ... ] -o <bootfile>\n",argv[0]);
        return 1;
    }
 argc--;
 argv++;
 while(argc){
  if(!strcmp(*argv,"--sparc")) {
   make_sparcboot = 1;
  } else if(!strcmp(*argv, "--bigendian")) {
   target_endian = 1;
  } else if(!strcmp(*argv,"-o")) {
   argc--;
   argv++;
   if(argc) {
    file = *argv;
   } else {
    goto usage;
   }
  } else if(!strcmp(*argv, "--strip-binary")) {
   argc--;
   argv++;
   if(argc) {
    strip_binary = *argv;
   } else {
    goto usage;
   }
  } else if(!strcmp(*argv, "--strip-debug")) {
   strip_debug = 1;
  } else {
   if(load_ini(*argv) == ((void *)0)) {
    fprintf(stderr,"warning: cannot load '%s'\n",*argv);
   }
  }
  argc--;
  argv++;
 }
    if((argc > 3) && !strcmp(argv[3],"-sparc")){
        make_sparcboot = 1;
    }
 if(!file){
  fprintf(stderr,"error: no output specified\n");
  goto usage;
 }
 if(!first){
  fprintf(stderr,"error: no data to write?!\n");
  goto usage;
 }
 makeboot(first,file);
    return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 char *file = ((void *)0);
    struct _section *s;
    if(argc < 2){
usage:
        fprintf(stderr,"usage: %s [--littleendian (default)] [--bigendian ] [ --strip-binary <binary ] [ --strip-debug] [ --sparc | -s ] [ <inifile> ... ] -o <bootfile>\n",argv[0]);
        return 1;
    }
 argc--;
 argv++;
 while(argc){
  if(!strcmp(*argv,"--sparc")) {
   make_sparcboot = 1;
  } else if(!strcmp(*argv, "--bigendian")) {
   target_endian = 1;
  } else if(!strcmp(*argv,"-o")) {
   argc--;
   argv++;
   if(argc) {
    file = *argv;
   } else {
    goto usage;
   }
  } else if(!strcmp(*argv, "--strip-binary")) {
   argc--;
   argv++;
   if(argc) {
    strip_binary = *argv;
   } else {
    goto usage;
   }
  } else if(!strcmp(*argv, "--strip-debug")) {
   strip_debug = 1;
  } else {
   if(load_ini(*argv) == ((void *)0)) {
    fprintf(stderr,"warning: cannot load '%s'\n",*argv);
   }
  }
  argc--;
  argv++;
 }
    if((argc > 3) && !strcmp(argv[3],"-sparc")){
        make_sparcboot = 1;
    }
 if(!file){
  fprintf(stderr,"error: no output specified\n");
  goto usage;
 }
 if(!first){
  fprintf(stderr,"error: no data to write?!\n");
  goto usage;
 }
 makeboot(first,file);
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
file
char *

variable_types: struct _section { struct _section *next; char *name; struct _nvpair { struct _nvpair *next; char *name; char *value; } *firstnv; } *

user_defined_types: struct _section { struct _section *next; char *name; struct _nvpair *firstnv; }


decompiled_code:
__int64 locale_from_utf8()
{
return g_locale_from_utf8();
}

canonical_decompiled_code:
__int64 func11()
{
return g_locale_from_utf8();
}

original_code:
char * locale_from_utf8(const char * str)
{
 gchar * locale_str;
 gsize bytes_written = 0;
 GError * err = ((void *)0);
 locale_str = g_locale_from_utf8(str, -1, ((void *)0), &bytes_written, &err);
 if (err)
 {
  g_log (((gchar*) 0), G_LOG_LEVEL_WARNING, "g_locale_from_utf8 failed: %s", err->message);
  g_error_free(err);
 }
 return locale_str;
}

canonical_original_code:
char *locale_from_utf8(char *str)
{
 char *locale_str;
 unsigned long bytes_written = 0;
 struct _GError *err = ((void *)0);
 locale_str = g_locale_from_utf8(str, -1, ((void *)0), &bytes_written, &err);
 if (err)
 {
  g_log (((char *) 0), G_LOG_LEVEL_WARNING, "g_locale_from_utf8 failed: %s", err->message);
  g_error_free(err);
 }
 return locale_str;
}

variable_types: struct _GError { unsigned int domain; int code; char *message; } *

return_type: char *


decompiled_code:
__int64 get_adapters()
{
struct if_nameindex *v0; // rax
struct if_nameindex *v1; // rbp
struct if_nameindex *i; // rbx

v0 = if_nameindex();
if ( !v0 )
return 1LL;
v1 = v0;
for ( i = v0; i->if_index || i->if_name; ++i )
{
locale_from_utf8(i->if_name);
adapters = g_list_prepend();
}
if_freenameindex(v1);
return 0LL;
}

canonical_decompiled_code:
__int64 func12()
{
struct if_nameindex *v0; // rax
struct if_nameindex *v1; // rbp
struct if_nameindex *i; // rbx

v0 = if_nameindex();
if ( !v0 )
return 1LL;
v1 = v0;
for ( i = v0; i->if_index || i->if_name; ++i )
{
func11(i->if_name);
adapters = g_list_prepend();
}
if_freenameindex(v1);
return 0LL;
}

original_code:
int get_adapters()
{
 struct if_nameindex * a, * i;
 a = if_nameindex();
 if(a == ((void *)0))
  return 1;
 for(i = a; !(i->if_index == 0 && i->if_name == ((void *)0)); i++)
  adapters = g_list_prepend(adapters, locale_from_utf8(i->if_name));
 if_freenameindex(a);
 return 0;
}

canonical_original_code:
int get_adapters()
{
 struct if_nameindex *a; struct if_nameindex *i;
 a = if_nameindex();
 if(a == ((void *)0))
  return 1;
 for(i = a; !(i->if_index == 0 && i->if_name == ((void *)0)); i++)
  adapters = g_list_prepend(adapters, locale_from_utf8(i->if_name));
 if_freenameindex(a);
 return 0;
}

variable_types: struct if_nameindex { unsigned int if_index; char *if_name; } *


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v4; // [rsp+0h] [rbp-18h] BYREF
int v5[3]; // [rsp+Ch] [rbp-Ch] BYREF

v5[0] = argc;
v4 = argv;
gtk_init();
if ( (unsigned int)get_adapters(v5, &v4) )
adapters = g_list_append();
init_interface();
gtk_main();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v4; // [rsp+0h] [rbp-18h] BYREF
int v5[3]; // [rsp+Ch] [rbp-Ch] BYREF

v5[0] = argc;
v4 = argv;
gtk_init();
if ( (unsigned int)func12(v5, &v4) )
adapters = g_list_append();
func13();
gtk_main();
return 0;
}

original_code:
int main(int argc, char ** argv)
{
 gtk_init(&argc, &argv);
 if(get_adapters())
  adapters = g_list_append(adapters, (gpointer)strings[ADAPTERS_FAIL]);
 init_interface();
 gtk_main();
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 gtk_init(&argc, &argv);
 if(get_adapters())
  adapters = g_list_append(adapters, (void *)strings[ADAPTERS_FAIL]);
 init_interface();
 gtk_main();
 return 0;
}


decompiled_code:
void __noreturn exit_server()
{
if ( msgctl(msg_qid, 0, 0LL) == -1 )
syserr("msgctl RMID");
if ( msgctl(client_qid, 0, 0LL) == -1 )
syserr("msgctl RMID");
if ( msgctl(client_end_qid, 0, 0LL) == -1 )
syserr("msgctl RMID");
if ( msgctl(n_qid, 0, 0LL) == -1 )
syserr("msgctl RMID");
exit(0);
}

canonical_decompiled_code:
void __noreturn func0()
{
if ( msgctl(msg_qid, 0, 0LL) == -1 )
syserr("msgctl RMID");
if ( msgctl(client_qid, 0, 0LL) == -1 )
syserr("msgctl RMID");
if ( msgctl(client_end_qid, 0, 0LL) == -1 )
syserr("msgctl RMID");
if ( msgctl(n_qid, 0, 0LL) == -1 )
syserr("msgctl RMID");
exit(0);
}

original_code:
void exit_server(int sig)
{
 if (msgctl(msg_qid, 0, 0) == -1)
  syserr("msgctl RMID");
 if (msgctl(client_qid, 0, 0) == -1)
  syserr("msgctl RMID");
 if (msgctl(client_end_qid, 0, 0) == -1)
  syserr("msgctl RMID");
 if (msgctl(n_qid, 0, 0) == -1)
  syserr("msgctl RMID");
 exit(0);
}

variable_types: sig int


decompiled_code:
void *__fastcall client_thread(void *a1)
{
unsigned int v1; // eax
unsigned int v3; // eax
unsigned int v4; // [rsp+8h] [rbp-10h] BYREF
unsigned int v5; // [rsp+Ch] [rbp-Ch] BYREF

_isoc99_sscanf(a1, "%i %i", &v5, &v4);
fprintf(stderr, "%i %i\n", v5, v4);
v1 = pthread_cond_wait(&waiting[v4], &mutex + (int)v4);
if ( v1 )
syserr("%i. Lock failed", v1);
fwrite("jestem w client_thread\n", 1uLL, 0x17uLL, stderr);
if ( pthread_mutex_lock(&global_mutex) )
syserr("%i. Lock failedd", 1LL);
global_temp = v5;
fprintf(stderr, "\tglobal_temp = pid = %i = %i;\n", v5, v5);
if ( global_temp )
{
v3 = pthread_cond_signal(&wait_for_pair[v4]);
if ( v3 )
syserr("%i. Lock faileddd", v3);
else
fwrite("czekam na mutexaa", 1uLL, 0x11uLL, stderr);
}
if ( pthread_mutex_unlock(&global_mutex) )
syserr("%i. Lock faileddd", 1LL);
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func1(void *a1)
{
unsigned int v1; // eax
unsigned int v3; // eax
unsigned int v4; // [rsp+8h] [rbp-10h] BYREF
unsigned int v5; // [rsp+Ch] [rbp-Ch] BYREF

_isoc99_sscanf(a1, "%i %i", &v5, &v4);
fprintf(stderr, "%i %i\n", v5, v4);
v1 = pthread_cond_wait(&waiting[v4], &mutex + (int)v4);
if ( v1 )
syserr("%i. Lock failed", v1);
fwrite("jestem w client_thread\n", 1uLL, 0x17uLL, stderr);
if ( pthread_mutex_lock(&global_mutex) )
syserr("%i. Lock failedd", 1LL);
global_temp = v5;
fprintf(stderr, "\tglobal_temp = pid = %i = %i;\n", v5, v5);
if ( global_temp )
{
v3 = pthread_cond_signal(&wait_for_pair[v4]);
if ( v3 )
syserr("%i. Lock faileddd", v3);
else
fwrite("czekam na mutexaa", 1uLL, 0x11uLL, stderr);
}
if ( pthread_mutex_unlock(&global_mutex) )
syserr("%i. Lock faileddd", 1LL);
return 0LL;
}

original_code:
void *client_thread(void *data)
{
 int temp;
 char *client= (char *)data;
 int pid, k;
 sscanf(client, "%i %i", &pid, &k);
 fprintf(stderr,"%i %i\n", pid, k);
 if ((temp = pthread_cond_wait(&(waiting[k]), &(mutex[k]))) != 0)
  syserr("%i. Lock failed", temp);
 fprintf(stderr, "jestem w client_thread\n");
 if ((temp = pthread_mutex_lock(&(global_mutex)) != 0))
  syserr("%i. Lock failedd", temp);
 global_temp = pid;
 fprintf(stderr, "	global_temp = pid = %i = %i;\n", pid, global_temp);
 if(global_temp != 0){
  if ((temp = pthread_cond_signal(&(wait_for_pair[k]))) != 0)
   syserr("%i. Lock faileddd", temp);
 else fprintf(stderr, "czekam na mutexaa");
 }
 if ((temp = pthread_mutex_unlock(&(global_mutex)) != 0))
  syserr("%i. Lock faileddd", temp);
 return 0;
}

canonical_original_code:
void *client_thread(void *data)
{
 int temp;
 char *client = (char *)data;
 int pid; int k;
 sscanf(client, "%i %i", &pid, &k);
 fprintf(stderr,"%i %i\n", pid, k);
 if ((temp = pthread_cond_wait(&(waiting[k]), &(mutex[k]))) != 0)
  syserr("%i. Lock failed", temp);
 fprintf(stderr, "jestem w client_thread\n");
 if ((temp = pthread_mutex_lock(&(global_mutex)) != 0))
  syserr("%i. Lock failedd", temp);
 global_temp = pid;
 fprintf(stderr, "	global_temp = pid = %i = %i;\n", pid, global_temp);
 if(global_temp != 0){
  if ((temp = pthread_cond_signal(&(wait_for_pair[k]))) != 0)
   syserr("%i. Lock faileddd", temp);
 else fprintf(stderr, "czekam na mutexaa");
 }
 if ((temp = pthread_mutex_unlock(&(global_mutex)) != 0))
  syserr("%i. Lock faileddd", temp);
 return 0;
}

variable_types:
data
void *

variable_types: temp int

variable_types:
client
char *

variable_types: pid int

variable_types: k int

return_type: void *


decompiled_code:
int make_queues()
{
int result; // eax

msg_qid = msgget(108, 1974);
if ( msg_qid == -1 )
syserr("msgget");
client_qid = msgget(666, 1974);
if ( client_qid == -1 )
syserr("msgget");
client_end_qid = msgget(1234, 1974);
if ( client_end_qid == -1 )
syserr("msgget");
result = msgget(1235, 1974);
n_qid = result;
if ( result == -1 )
result = syserr("msgget");
return result;
}

canonical_decompiled_code:
int func2()
{
int result; // eax

msg_qid = msgget(108, 1974);
if ( msg_qid == -1 )
syserr("msgget");
client_qid = msgget(666, 1974);
if ( client_qid == -1 )
syserr("msgget");
client_end_qid = msgget(1234, 1974);
if ( client_end_qid == -1 )
syserr("msgget");
result = msgget(1235, 1974);
n_qid = result;
if ( result == -1 )
result = syserr("msgget");
return result;
}


decompiled_code:
unsigned __int64 get_info()
{
unsigned int v1; // [rsp+0h] [rbp-FB8h] BYREF
char v2[4004]; // [rsp+8h] [rbp-FB0h] BYREF
unsigned int v3; // [rsp+FACh] [rbp-Ch] BYREF

if ( (int)msgrcv(msg_qid, &v1, 0xFA0uLL, 0LL, 0) < 0 )
syserr("msgrcv");
_isoc99_sscanf(v2, "%i", &v3);
return ((unsigned __int64)v3 << 32) | v1;
}

canonical_decompiled_code:
unsigned __int64 func3()
{
unsigned int v1; // [rsp+0h] [rbp-FB8h] BYREF
char v2[4004]; // [rsp+8h] [rbp-FB0h] BYREF
unsigned int v3; // [rsp+FACh] [rbp-Ch] BYREF

if ( (int)msgrcv(msg_qid, &v1, 0xFA0uLL, 0LL, 0) < 0 )
syserr("msgrcv");
_isoc99_sscanf(v2, "%i", &v3);
return ((unsigned __int64)v3 << 32) | v1;
}

original_code:
Client_info get_info()
{
 int temp, pid, k;
 Mesg mesg;
 if ((temp = msgrcv(msg_qid, &mesg, 4000, 0L, 0)) < 0)
  syserr("msgrcv");
 sscanf(mesg.mesg_data, "%i", &k);
 Client_info a;
 a.pid = (int)mesg.mesg_type;
 a.k = k;
 return a;
}

canonical_original_code:
struct Client_info get_info()
{
 int temp; int pid; int k;
 struct Mesg mesg;
 if ((temp = msgrcv(msg_qid, &mesg, 4000, 0L, 0)) < 0)
  syserr("msgrcv");
 sscanf(mesg.mesg_data, "%i", &k);
 struct Client_info a;
 a.pid = (int)mesg.mesg_type;
 a.k = k;
 return a;
}

variable_types: struct Mesg { long mesg_type; char mesg_data[4000]; }

variable_types:
a
struct Client_info { int pid; int k; }

return_type: struct Client_info { int pid; int k; }


init

decompiled_code:
unsigned int init()
{
__int64 v0; // rbp
__int64 v1; // rbx
unsigned int v2; // er12
unsigned int v3; // eax
unsigned int v4; // eax
unsigned int v5; // eax
unsigned int v6; // eax
unsigned int result; // eax

global_temp = 0;
if ( K < 0 )
{
v2 = 0;
}
else
{
v0 = 0LL;
v1 = 0LL;
do
{
free_resources[v1] = N;
pair_need[v1] = 0;
how_many_waiting[v1] = 0;
if ( pthread_mutex_init(&mutex + v1, 0LL) )
syserr("%i. Mutex init %i failed", 1LL, (unsigned int)v1);
v3 = pthread_cond_init(&waiting[v0], 0LL);
if ( v3 )
syserr("&d Cond init %i failed", v3);
v4 = pthread_cond_init((pthread_cond_t *)((char *)&pair + v0 * 48), 0LL);
if ( v4 )
syserr("&d Cond init %i failed", v4);
v5 = pthread_cond_init(&wait_for_pair[v0], 0LL);
if ( v5 )
syserr("&d Cond init %i failed", v5);
v2 = ++v1;
++v0;
}
while ( K >= (int)v1 );
}
v6 = pthread_attr_init(&attr);
if ( v6 )
syserr("%i. Attr init failed", v6);
if ( pthread_mutex_init(&global_mutex, 0LL) )
syserr("%i. Mutex init %i failed", 1LL, v2);
result = pthread_attr_setdetachstate(&attr, 1);
if ( result )
result = syserr("%i. Set Detach faild", result);
return result;
}

canonical_decompiled_code:
unsigned int func4()
{
__int64 v0; // rbp
__int64 v1; // rbx
unsigned int v2; // er12
unsigned int v3; // eax
unsigned int v4; // eax
unsigned int v5; // eax
unsigned int v6; // eax
unsigned int result; // eax

global_temp = 0;
if ( K < 0 )
{
v2 = 0;
}
else
{
v0 = 0LL;
v1 = 0LL;
do
{
free_resources[v1] = N;
pair_need[v1] = 0;
how_many_waiting[v1] = 0;
if ( pthread_mutex_init(&mutex + v1, 0LL) )
syserr("%i. Mutex init %i failed", 1LL, (unsigned int)v1);
v3 = pthread_cond_init(&waiting[v0], 0LL);
if ( v3 )
syserr("&d Cond init %i failed", v3);
v4 = pthread_cond_init((pthread_cond_t *)((char *)&pair + v0 * 48), 0LL);
if ( v4 )
syserr("&d Cond init %i failed", v4);
v5 = pthread_cond_init(&wait_for_pair[v0], 0LL);
if ( v5 )
syserr("&d Cond init %i failed", v5);
v2 = ++v1;
++v0;
}
while ( K >= (int)v1 );
}
v6 = pthread_attr_init(&attr);
if ( v6 )
syserr("%i. Attr init failed", v6);
if ( pthread_mutex_init(&global_mutex, 0LL) )
syserr("%i. Mutex init %i failed", 1LL, v2);
result = pthread_attr_setdetachstate(&attr, 1);
if ( result )
result = syserr("%i. Set Detach faild", result);
return result;
}

original_code:
void init()
{
 int i = 0;
 int err_id;
 global_temp = 0;
 for(i = 0; i <= K; i++)
 {
  free_resources[i] = N;
  pair_need[i] = 0;
  how_many_waiting[i] = 0;
  if ((err_id = pthread_mutex_init(&(mutex[i]), 0) != 0))
   syserr("%i. Mutex init %i failed", err_id, i);
  if ((err_id = pthread_cond_init(&(waiting[i]), 0)) != 0)
   syserr("&d Cond init %i failed", err_id, i);
  if ((err_id = pthread_cond_init(&(pair[i]), 0)) != 0)
   syserr("&d Cond init %i failed", err_id, i);
  if ((err_id = pthread_cond_init(&(wait_for_pair[i]), 0)) != 0)
   syserr("&d Cond init %i failed", err_id, i);
 }
 if ((err_id = pthread_attr_init(&attr)) != 0 )
  syserr("%i. Attr init failed", err_id);
 if ((err_id = pthread_mutex_init(&(global_mutex), 0) != 0))
  syserr("%i. Mutex init %i failed", err_id, i);
 if ((err_id = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED)) != 0)
  syserr("%i. Set Detach faild", err_id);
}

variable_types: i int


destroy

decompiled_code:
void destroy()
{
__int64 v0; // rbp
__int64 v1; // rbx
unsigned int v2; // eax
unsigned int v3; // eax

if ( K >= 0 )
{
v0 = 0LL;
v1 = 0LL;
do
{
free_resources[v1] = N;
pair_need[v1] = 0;
if ( pthread_mutex_destroy(&mutex + v1) )
syserr("%i. Mutex init %i failed", 1LL, (unsigned int)v1);
v2 = pthread_cond_destroy(&waiting[v0]);
if ( v2 )
syserr("&d Cond init %i failed", v2);
v3 = pthread_cond_destroy((pthread_cond_t *)((char *)&pair + v0 * 48));
if ( v3 )
syserr("&d Cond init %i failed", v3);
++v1;
++v0;
}
while ( K >= (int)v1 );
}
}

canonical_decompiled_code:
void func5()
{
__int64 v0; // rbp
__int64 v1; // rbx
unsigned int v2; // eax
unsigned int v3; // eax

if ( K >= 0 )
{
v0 = 0LL;
v1 = 0LL;
do
{
free_resources[v1] = N;
pair_need[v1] = 0;
if ( pthread_mutex_destroy(&mutex + v1) )
syserr("%i. Mutex init %i failed", 1LL, (unsigned int)v1);
v2 = pthread_cond_destroy(&waiting[v0]);
if ( v2 )
syserr("&d Cond init %i failed", v2);
v3 = pthread_cond_destroy((pthread_cond_t *)((char *)&pair + v0 * 48));
if ( v3 )
syserr("&d Cond init %i failed", v3);
++v1;
++v0;
}
while ( K >= (int)v1 );
}
}

original_code:
void destroy()
{
 int i = 0;
 int err_id;
 for(i = 0; i <= K; i++)
 {
  free_resources[i] = N;
  pair_need[i] = 0;
  if ((err_id = pthread_mutex_destroy(&(mutex[i])) != 0))
   syserr("%i. Mutex init %i failed", err_id, i);
  if ((err_id = pthread_cond_destroy(&(waiting[i]))) != 0)
   syserr("&d Cond init %i failed", err_id, i);
  if ((err_id = pthread_cond_destroy(&(pair[i]))) != 0)
   syserr("&d Cond init %i failed", err_id, i);
 }
}


decompiled_code:
int __fastcall wake_up(int a1)
{
unsigned int v1; // eax

if ( pthread_mutex_unlock(&global_mutex) )
syserr("%i. Lock failed", 1LL);
v1 = pthread_cond_signal(&waiting[a1]);
if ( v1 )
syserr("%i. Lock faileda", v1);
if ( pthread_mutex_lock(&global_mutex) )
syserr("%i. Lock failed", 1LL);
return fprintf(stderr, "pid1 %i\n", (unsigned int)global_temp);
}

canonical_decompiled_code:
int __fastcall func6(int a1)
{
unsigned int v1; // eax

if ( pthread_mutex_unlock(&global_mutex) )
syserr("%i. Lock failed", 1LL);
v1 = pthread_cond_signal(&waiting[a1]);
if ( v1 )
syserr("%i. Lock faileda", v1);
if ( pthread_mutex_lock(&global_mutex) )
syserr("%i. Lock failed", 1LL);
return fprintf(stderr, "pid1 %i\n", (unsigned int)global_temp);
}

original_code:
void wake_up(int k)
{
 int temp, pid1;
 if ((temp = pthread_mutex_unlock(&(global_mutex)) != 0))
  syserr("%i. Lock failed", temp);
 if ((temp = pthread_cond_signal(&(waiting[k]))) != 0)
  syserr("%i. Lock faileda", temp);
 if ((temp = pthread_mutex_lock(&(global_mutex)) != 0))
  syserr("%i. Lock failed", temp);
 fprintf(stderr,"pid1 %i\n", global_temp);
}

canonical_original_code:
void wake_up(int k)
{
 int temp; int pid1;
 if ((temp = pthread_mutex_unlock(&(global_mutex)) != 0))
  syserr("%i. Lock failed", temp);
 if ((temp = pthread_cond_signal(&(waiting[k]))) != 0)
  syserr("%i. Lock faileda", temp);
 if ((temp = pthread_mutex_lock(&(global_mutex)) != 0))
  syserr("%i. Lock failed", temp);
 fprintf(stderr,"pid1 %i\n", global_temp);
}


decompiled_code:
void *__fastcall pair_thread(void *a1)
{
int v1; // ebx
int v2; // er14
unsigned int v3; // eax
int v4; // er15
unsigned int v5; // eax
size_t v6; // rax
size_t v7; // rax
__int64 v9; // [rsp+8h] [rbp-2F50h]
__int64 v10; // [rsp+10h] [rbp-2F48h] BYREF
char v11[4008]; // [rsp+18h] [rbp-2F40h] BYREF
__int64 v12; // [rsp+FC0h] [rbp-1F98h] BYREF
char v13[4008]; // [rsp+FC8h] [rbp-1F90h] BYREF
char msgp[8]; // [rsp+1F70h] [rbp-FE8h] BYREF
char s[4064]; // [rsp+1F78h] [rbp-FE0h] BYREF

v1 = *(_DWORD *)a1;
fwrite("pair thread \n", 1uLL, 0xDuLL, stdout);
if ( pthread_mutex_lock(&global_mutex) )
syserr("%i. Lock failed", 1LL);
wake_up(v1);
v2 = global_temp;
global_temp = 0;
if ( (int)msgrcv(n_qid, msgp, 0xFA0uLL, v2, 0) <= 0 )
syserr("msgrcv");
sprintf(s, "%i", 0LL);
wake_up(v1);
v9 = v1;
v3 = pthread_cond_signal(&wait_for_pair[v9]);
if ( v3 )
syserr("%i. Lock faileda", v3);
v4 = global_temp;
global_temp = 0;
if ( (int)msgrcv(n_qid, msgp, 0xFA0uLL, v4, 0) <= 0 )
syserr("msgrcv");
sprintf(s, "%i", 0LL);
fprintf(stderr, "odebrana wiadomosc: %i\n", 0LL);
v12 = v2;
v10 = v4;
sprintf(v13, "%i", (unsigned int)v4);
sprintf(v11, "%i", (unsigned int)v2);
if ( free_resources[v1] >= 0 )
{
if ( pthread_mutex_unlock(&global_mutex) )
syserr("%i. Lock failed", 1LL);
}
else
{
pair_need[v1] = 0;
if ( pthread_mutex_unlock(&global_mutex) )
syserr("%i. Lock failed", 1LL);
v5 = pthread_cond_wait((pthread_cond_t *)((char *)&pair + v9 * 48), &mutex + v1);
if ( v5 )
syserr("%i. Lock failed", v5);
}
v6 = strlen(v13);
if ( msgsnd(client_qid, &v12, v6, 0) )
syserr("msgsnd");
v7 = strlen(v11);
if ( msgsnd(client_qid, &v10, v7, 0) )
syserr("msgsnd");
if ( (int)msgrcv(client_end_qid, &v12, 0xFA0uLL, v2, 0) <= 0 )
syserr("msgrcv");
if ( (int)msgrcv(client_end_qid, &v10, 0xFA0uLL, v4, 0) <= 0 )
syserr("msgrcv");
if ( pthread_mutex_lock(&global_mutex) )
syserr("%i. Lock failed", 1LL);
pair_need[v1] = 0;
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func7(void *a1)
{
int v1; // ebx
int v2; // er14
unsigned int v3; // eax
int v4; // er15
unsigned int v5; // eax
size_t v6; // rax
size_t v7; // rax
__int64 v9; // [rsp+8h] [rbp-2F50h]
__int64 v10; // [rsp+10h] [rbp-2F48h] BYREF
char v11[4008]; // [rsp+18h] [rbp-2F40h] BYREF
__int64 v12; // [rsp+FC0h] [rbp-1F98h] BYREF
char v13[4008]; // [rsp+FC8h] [rbp-1F90h] BYREF
char msgp[8]; // [rsp+1F70h] [rbp-FE8h] BYREF
char s[4064]; // [rsp+1F78h] [rbp-FE0h] BYREF

v1 = *(_DWORD *)a1;
fwrite("pair thread \n", 1uLL, 0xDuLL, stdout);
if ( pthread_mutex_lock(&global_mutex) )
syserr("%i. Lock failed", 1LL);
func6(v1);
v2 = global_temp;
global_temp = 0;
if ( (int)msgrcv(n_qid, msgp, 0xFA0uLL, v2, 0) <= 0 )
syserr("msgrcv");
sprintf(s, "%i", 0LL);
func6(v1);
v9 = v1;
v3 = pthread_cond_signal(&wait_for_pair[v9]);
if ( v3 )
syserr("%i. Lock faileda", v3);
v4 = global_temp;
global_temp = 0;
if ( (int)msgrcv(n_qid, msgp, 0xFA0uLL, v4, 0) <= 0 )
syserr("msgrcv");
sprintf(s, "%i", 0LL);
fprintf(stderr, "odebrana wiadomosc: %i\n", 0LL);
v12 = v2;
v10 = v4;
sprintf(v13, "%i", (unsigned int)v4);
sprintf(v11, "%i", (unsigned int)v2);
if ( free_resources[v1] >= 0 )
{
if ( pthread_mutex_unlock(&global_mutex) )
syserr("%i. Lock failed", 1LL);
}
else
{
pair_need[v1] = 0;
if ( pthread_mutex_unlock(&global_mutex) )
syserr("%i. Lock failed", 1LL);
v5 = pthread_cond_wait((pthread_cond_t *)((char *)&pair + v9 * 48), &mutex + v1);
if ( v5 )
syserr("%i. Lock failed", v5);
}
v6 = strlen(v13);
if ( msgsnd(client_qid, &v12, v6, 0) )
syserr("msgsnd");
v7 = strlen(v11);
if ( msgsnd(client_qid, &v10, v7, 0) )
syserr("msgsnd");
if ( (int)msgrcv(client_end_qid, &v12, 0xFA0uLL, v2, 0) <= 0 )
syserr("msgrcv");
if ( (int)msgrcv(client_end_qid, &v10, 0xFA0uLL, v4, 0) <= 0 )
syserr("msgrcv");
if ( pthread_mutex_lock(&global_mutex) )
syserr("%i. Lock failed", 1LL);
pair_need[v1] = 0;
return 0LL;
}

original_code:
void *pair_thread(void *data)
{
 int pid1, pid2, temp;
 int k = *(int*)data;
 fprintf(stdout,"pair thread \n");
 if ((temp = pthread_mutex_lock(&(global_mutex)) != 0))
  syserr("%i. Lock failed", temp);
 wake_up(k);
 pid1 = global_temp;
 global_temp = 0;
 Mesg mesg;
 int n1, n2;
 if ((temp = msgrcv(n_qid, &mesg, 4000, (long)(pid1), 0)) <= 0)
  syserr("msgrcv");
 sprintf(mesg.mesg_data, "%i", n1);
 wake_up(k);
 if ((temp = pthread_cond_signal(&(wait_for_pair[k]))) != 0)
  syserr("%i. Lock faileda", temp);
 pid2 = global_temp;
 global_temp = 0;
 if ((temp = msgrcv(n_qid, &mesg, 4000, (long)(pid2), 0)) <= 0)
  syserr("msgrcv");
 sprintf(mesg.mesg_data, "%i", n2);
 fprintf(stderr, "odebrana wiadomosc: %i\n", n2);
 Mesg to_pid1;
 Mesg to_pid2;
 to_pid1.mesg_type = (long)pid1;
 to_pid2.mesg_type = (long)pid2;
 sprintf(to_pid1.mesg_data, "%i", pid2);
 sprintf(to_pid2.mesg_data, "%i", pid1);
 if (free_resources[k] < n1 + n2)
 {
  pair_need[k] = n1 + n2;
  if ((temp = pthread_mutex_unlock(&(global_mutex)) != 0))
   syserr("%i. Lock failed", temp);
  if ((temp = pthread_cond_wait(&(pair[k]), &(mutex[k]))) != 0)
   syserr("%i. Lock failed", temp);
 }else
 {
  if ((temp = pthread_mutex_unlock(&(global_mutex)) != 0))
   syserr("%i. Lock failed", temp);
 }
 if ((temp = msgsnd(client_qid, (char *) &to_pid1, strlen(to_pid1.mesg_data), 0) ) != 0)
  syserr("msgsnd");
 if ((temp = msgsnd(client_qid, (char *) &to_pid2, strlen(to_pid2.mesg_data), 0) ) != 0)
  syserr("msgsnd");
 if ((temp = msgrcv(client_end_qid, &to_pid1, 4000, (long)(pid1), 0)) <= 0)
  syserr("msgrcv");
 if ((temp = msgrcv(client_end_qid, &to_pid2, 4000, (long)(pid2), 0)) <= 0)
  syserr("msgrcv");
 if ((temp = pthread_mutex_lock(&(global_mutex)) != 0))
  syserr("%i. Lock failed", temp);
 free_resources[k] += n1 + n2;
 pair_need[k] = 0;
 if(how_many_waiting[k] >= 2)
 {
 }
 return 0;
}

canonical_original_code:
void *pair_thread(void *data)
{
 int pid1; int pid2; int temp;
 int k = *(int*)data;
 fprintf(stdout,"pair thread \n");
 if ((temp = pthread_mutex_lock(&(global_mutex)) != 0))
  syserr("%i. Lock failed", temp);
 wake_up(k);
 pid1 = global_temp;
 global_temp = 0;
 struct Mesg mesg;
 int n1; int n2;
 if ((temp = msgrcv(n_qid, &mesg, 4000, (long)(pid1), 0)) <= 0)
  syserr("msgrcv");
 sprintf(mesg.mesg_data, "%i", n1);
 wake_up(k);
 if ((temp = pthread_cond_signal(&(wait_for_pair[k]))) != 0)
  syserr("%i. Lock faileda", temp);
 pid2 = global_temp;
 global_temp = 0;
 if ((temp = msgrcv(n_qid, &mesg, 4000, (long)(pid2), 0)) <= 0)
  syserr("msgrcv");
 sprintf(mesg.mesg_data, "%i", n2);
 fprintf(stderr, "odebrana wiadomosc: %i\n", n2);
 struct Mesg to_pid1;
 struct Mesg to_pid2;
 to_pid1.mesg_type = (long)pid1;
 to_pid2.mesg_type = (long)pid2;
 sprintf(to_pid1.mesg_data, "%i", pid2);
 sprintf(to_pid2.mesg_data, "%i", pid1);
 if (free_resources[k] < n1 + n2)
 {
  pair_need[k] = n1 + n2;
  if ((temp = pthread_mutex_unlock(&(global_mutex)) != 0))
   syserr("%i. Lock failed", temp);
  if ((temp = pthread_cond_wait(&(pair[k]), &(mutex[k]))) != 0)
   syserr("%i. Lock failed", temp);
 }else
 {
  if ((temp = pthread_mutex_unlock(&(global_mutex)) != 0))
   syserr("%i. Lock failed", temp);
 }
 if ((temp = msgsnd(client_qid, (char *) &to_pid1, strlen(to_pid1.mesg_data), 0) ) != 0)
  syserr("msgsnd");
 if ((temp = msgsnd(client_qid, (char *) &to_pid2, strlen(to_pid2.mesg_data), 0) ) != 0)
  syserr("msgsnd");
 if ((temp = msgrcv(client_end_qid, &to_pid1, 4000, (long)(pid1), 0)) <= 0)
  syserr("msgrcv");
 if ((temp = msgrcv(client_end_qid, &to_pid2, 4000, (long)(pid2), 0)) <= 0)
  syserr("msgrcv");
 if ((temp = pthread_mutex_lock(&(global_mutex)) != 0))
  syserr("%i. Lock failed", temp);
 free_resources[k] += n1 + n2;
 pair_need[k] = 0;
 if(how_many_waiting[k] >= 2)
 {
 }
 return 0;
}

user_defined_types: struct Mesg { long mesg_type; char mesg_data[4000]; }


decompiled_code:
size_t __fastcall create_thread(unsigned int a1, unsigned int a2)
{
unsigned int v2; // eax
char v4[4008]; // [rsp+0h] [rbp-FB8h] BYREF
pthread_t newthread[2]; // [rsp+FA8h] [rbp-10h] BYREF

sprintf(v4, "%i %i\n", a1, a2);
v2 = pthread_create(newthread, &attr, client_thread, v4);
if ( v2 )
syserr("%i. Pthread create", v2);
return fwrite("Created New Thread\n", 1uLL, 0x13uLL, stderr);
}

canonical_decompiled_code:
size_t __fastcall func8(unsigned int a1, unsigned int a2)
{
unsigned int v2; // eax
char v4[4008]; // [rsp+0h] [rbp-FB8h] BYREF
pthread_t newthread[2]; // [rsp+FA8h] [rbp-10h] BYREF

sprintf(v4, "%i %i\n", a1, a2);
v2 = pthread_create(newthread, &attr, client_thread, v4);
if ( v2 )
syserr("%i. Pthread create", v2);
return fwrite("Created New Thread\n", 1uLL, 0x13uLL, stderr);
}

original_code:
void create_thread(int pid, int k)
{
        int temp;
        pthread_t thread;
        char data[4000];
  sprintf(data, "%i %i\n", pid, k);
        if ((temp = pthread_create(&thread, &attr, client_thread, (void *)data)) != 0)
                syserr("%i. Pthread create", temp);
        fprintf(stderr,"Created New Thread\n");
}

canonical_original_code:
void create_thread(int pid, int k)
{
        int temp;
        unsigned long thread;
        char data[4000];
  sprintf(data, "%i %i\n", pid, k);
        if ((temp = pthread_create(&thread, &attr, client_thread, (void *)data)) != 0)
                syserr("%i. Pthread create", temp);
        fprintf(stderr,"Created New Thread\n");
}

variable_types:
thread
unsigned long

variable_types:
data
char [4000]


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rdx
__int64 v4; // rax
__int64 v5; // rcx
int v6; // edx
unsigned int v7; // eax
pthread_t v8; // [rsp+0h] [rbp-18h] BYREF
unsigned __int64 arg; // [rsp+8h] [rbp-10h] BYREF

if ( argc != 3 )
syserr("Wrong number of parameters", argv, envp);
if ( signal(2, (__sighandler_t)exit_server) == (__sighandler_t)-1LL )
syserr("signal");
K = atoi(argv[1]);
N = atoi(argv[2]);
init();
make_queues();
while ( 1 )
{
arg = get_info();
create_thread(arg, HIDWORD(arg));
v3 = HIDWORD(arg);
v4 = SHIDWORD(arg);
v5 = (unsigned int)(how_many_waiting[SHIDWORD(arg)] + 1);
how_many_waiting[SHIDWORD(arg)] = v5;
printf("info: %i %i %i %i\n", (unsigned int)arg, v3, v5, (unsigned int)pair_need[v4]);
if ( pthread_mutex_lock(&global_mutex) )
syserr("%i. Lock failed", 1LL);
v6 = how_many_waiting[SHIDWORD(arg)];
if ( v6 > 1 && !pair_need[SHIDWORD(arg)] )
{
how_many_waiting[SHIDWORD(arg)] = v6 - 2;
fwrite("Making new pair\n", 1uLL, 0x10uLL, stderr);
v7 = pthread_create(&v8, &attr, pair_thread, (char *)&arg + 4);
if ( v7 )
syserr("%i. Pthread create", v7);
}
if ( pthread_mutex_unlock(&global_mutex) )
syserr("%i. Lock failed", 1LL);
fwrite("End of for loop\n", 1uLL, 0x10uLL, stderr);
}
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rdx
__int64 v4; // rax
__int64 v5; // rcx
int v6; // edx
unsigned int v7; // eax
pthread_t v8; // [rsp+0h] [rbp-18h] BYREF
unsigned __int64 arg; // [rsp+8h] [rbp-10h] BYREF

if ( argc != 3 )
syserr("Wrong number of parameters", argv, envp);
if ( signal(2, (__sighandler_t)exit_server) == (__sighandler_t)-1LL )
syserr("signal");
K = atoi(argv[1]);
N = atoi(argv[2]);
func4();
func2();
while ( 1 )
{
arg = func3();
func8(arg, HIDWORD(arg));
v3 = HIDWORD(arg);
v4 = SHIDWORD(arg);
v5 = (unsigned int)(how_many_waiting[SHIDWORD(arg)] + 1);
how_many_waiting[SHIDWORD(arg)] = v5;
printf("info: %i %i %i %i\n", (unsigned int)arg, v3, v5, (unsigned int)pair_need[v4]);
if ( pthread_mutex_lock(&global_mutex) )
syserr("%i. Lock failed", 1LL);
v6 = how_many_waiting[SHIDWORD(arg)];
if ( v6 > 1 && !pair_need[SHIDWORD(arg)] )
{
how_many_waiting[SHIDWORD(arg)] = v6 - 2;
fwrite("Making new pair\n", 1uLL, 0x10uLL, stderr);
v7 = pthread_create(&v8, &attr, pair_thread, (char *)&arg + 4);
if ( v7 )
syserr("%i. Pthread create", v7);
}
if ( pthread_mutex_unlock(&global_mutex) )
syserr("%i. Lock failed", 1LL);
fwrite("End of for loop\n", 1uLL, 0x10uLL, stderr);
}
}

original_code:
int main(int argc, char **argv)
{
 if (argc != 3)
  syserr("Wrong number of parameters");
 if (signal(2, exit_server) == ((__sighandler_t) -1)){
  syserr("signal");}
 K = atoi(argv[1]);
    N = atoi(argv[2]);
 init();
 make_queues();
 Client_info client;
 for(;;) {
  client = get_info();
  create_thread(client.pid, client.k);
  how_many_waiting[client.k]+= 1;
  printf("info: %i %i %i %i\n", client.pid, client.k, how_many_waiting[client.k], pair_need[client.k]);
  int temp;
  if ((temp = pthread_mutex_lock(&(global_mutex)) != 0))
   syserr("%i. Lock failed", temp);
  if((how_many_waiting[client.k] >= 2) && (pair_need[client.k] == 0))
  {
   how_many_waiting[client.k] -= 2;
   pthread_t thread;
   fprintf(stderr, "Making new pair\n");
   if ((temp = pthread_create(&thread, &attr, pair_thread, (void *)&client.k)) != 0)
                syserr("%i. Pthread create", temp);
  }
  if ((temp = pthread_mutex_unlock(&(global_mutex)) != 0))
   syserr("%i. Lock failed", temp);
  fprintf(stderr, "End of for loop\n");
 }
}

canonical_original_code:
int main(int argc, char **argv)
{
 if (argc != 3)
  syserr("Wrong number of parameters");
 if (signal(2, exit_server) == ((__sighandler_t) -1)){
  syserr("signal");}
 K = atoi(argv[1]);
    N = atoi(argv[2]);
 init();
 make_queues();
 struct Client_info client;
 for(;;) {
  client = get_info();
  create_thread(client.pid, client.k);
  how_many_waiting[client.k]+= 1;
  printf("info: %i %i %i %i\n", client.pid, client.k, how_many_waiting[client.k], pair_need[client.k]);
  int temp;
  if ((temp = pthread_mutex_lock(&(global_mutex)) != 0))
   syserr("%i. Lock failed", temp);
  if((how_many_waiting[client.k] >= 2) && (pair_need[client.k] == 0))
  {
   how_many_waiting[client.k] -= 2;
   unsigned long thread;
   fprintf(stderr, "Making new pair\n");
   if ((temp = pthread_create(&thread, &attr, pair_thread, (void *)&client.k)) != 0)
                syserr("%i. Pthread create", temp);
  }
  if ((temp = pthread_mutex_unlock(&(global_mutex)) != 0))
   syserr("%i. Lock failed", temp);
  fprintf(stderr, "End of for loop\n");
 }
}

variable_types: argc int

variable_types:
client
struct Client_info { int pid; int k; }


syserr

decompiled_code:
void __noreturn syserr(char *format, ...)
{
int *v1; // rbx
char *v2; // rax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
fwrite("ERROR: ", 1uLL, 7uLL, stderr);
vfprintf(stderr, format, arg);
v1 = __errno_location();
v2 = strerror(*v1);
fprintf(stderr, " (%d; %s)\n", (unsigned int)*v1, v2);
exit(1);
}

canonical_decompiled_code:
void __noreturn func7(char *format, ...)
{
int *v1; // rbx
char *v2; // rax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
fwrite("ERROR: ", 1uLL, 7uLL, stderr);
vfprintf(stderr, format, arg);
v1 = __errno_location();
v2 = strerror(*v1);
fprintf(stderr, " (%d; %s)\n", (unsigned int)*v1, v2);
exit(1);
}

original_code:
void syserr(const char *fmt, ...)
{
  va_list fmt_args;
  fprintf(stderr, "ERROR: ");
  __builtin_va_start(fmt_args,fmt);
  vfprintf(stderr, fmt, fmt_args);
  __builtin_va_end(fmt_args);
  fprintf(stderr," (%d; %s)\n", (*__errno_location ()), strerror((*__errno_location ())));
  exit(1);
}

canonical_original_code:
void syserr(char *fmt, ...)
{
  __builtin_va_list fmt_args;
  fprintf(stderr, "ERROR: ");
  __builtin_va_start(fmt_args,fmt);
  vfprintf(stderr, fmt, fmt_args);
  __builtin_va_end(fmt_args);
  fprintf(stderr," (%d; %s)\n", (*__errno_location ()), strerror((*__errno_location ())));
  exit(1);
}

variable_types:
fmt
char *


fatal

decompiled_code:
void __noreturn fatal(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
fwrite("ERROR: ", 1uLL, 7uLL, stderr);
vfprintf(stderr, format, arg);
fputc(10, stderr);
exit(1);
}

canonical_decompiled_code:
void __noreturn func8(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
fwrite("ERROR: ", 1uLL, 7uLL, stderr);
vfprintf(stderr, format, arg);
fputc(10, stderr);
exit(1);
}

original_code:
void fatal(const char *fmt, ...)
{
  va_list fmt_args;
  fprintf(stderr, "ERROR: ");
  __builtin_va_start(fmt_args,fmt);
  vfprintf(stderr, fmt, fmt_args);
  __builtin_va_end(fmt_args);
  fprintf(stderr,"\n");
  exit(1);
}

canonical_original_code:
void fatal(char *fmt, ...)
{
  __builtin_va_list fmt_args;
  fprintf(stderr, "ERROR: ");
  __builtin_va_start(fmt_args,fmt);
  vfprintf(stderr, fmt, fmt_args);
  __builtin_va_end(fmt_args);
  fprintf(stderr,"\n");
  exit(1);
}


repo: disdi/Default-FS

decompiled_code:
ssize_t __fastcall write_super_block(int a1, const void *a2)
{
return write(a1, a2, 0x200uLL);
}

canonical_decompiled_code:
ssize_t __fastcall func7(int a1, const void *a2)
{
return write(a1, a2, 0x200uLL);
}

original_code:
void write_super_block(int dfs_handle, dfs_super_block_t *sb)
{
 write(dfs_handle, sb, sizeof(dfs_super_block_t));
}

canonical_original_code:
void write_super_block(int dfs_handle, struct dfs_super_block *sb)
{
 write(dfs_handle, sb, sizeof(dfs_super_block_t));
}

variable_types: struct dfs_super_block { unsigned int type; unsigned int block_size; unsigned int partition_size; unsigned int entry_size; unsigned int entry_table_size; unsigned int entry_table_block_start; unsigned int entry_count; unsigned int data_block_start; unsigned int reserved[-1]; } *


decompiled_code:
ssize_t __fastcall clear_file_entries(int fd, _DWORD *a2)
{
unsigned int v4; // edi
ssize_t result; // rax
int v6; // esi
unsigned int v7; // ecx
__m128i *v8; // rdx
unsigned int v9; // ebx
_BYTE v10[536]; // [rsp+0h] [rbp-218h] BYREF

v4 = a2[3];
result = a2[1] / v4;
if ( a2[1] >= v4 )
{
v6 = 0;
v7 = 0;
do
{
v8 = (__m128i *)&v10[v6];
*v8 = _mm_load_si128((const __m128i *)&fe);
v8[1] = _mm_load_si128((const __m128i *)&xmmword_4042F0);
v8[2] = _mm_load_si128((const __m128i *)&xmmword_404300);
v8[3] = _mm_load_si128((const __m128i *)&xmmword_404310);
++v7;
v6 += v4;
}
while ( v7 < (unsigned int)result );
}
if ( a2[4] )
{
v9 = 0;
do
{
result = write(fd, v10, 0x200uLL);
++v9;
}
while ( a2[4] > v9 );
}
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func8(int fd, _DWORD *a2)
{
unsigned int v4; // edi
ssize_t result; // rax
int v6; // esi
unsigned int v7; // ecx
__m128i *v8; // rdx
unsigned int v9; // ebx
_BYTE v10[536]; // [rsp+0h] [rbp-218h] BYREF

v4 = a2[3];
result = a2[1] / v4;
if ( a2[1] >= v4 )
{
v6 = 0;
v7 = 0;
do
{
v8 = (__m128i *)&v10[v6];
*v8 = _mm_load_si128((const __m128i *)&fe);
v8[1] = _mm_load_si128((const __m128i *)&xmmword_4042F0);
v8[2] = _mm_load_si128((const __m128i *)&xmmword_404300);
v8[3] = _mm_load_si128((const __m128i *)&xmmword_404310);
++v7;
v6 += v4;
}
while ( v7 < (unsigned int)result );
}
if ( a2[4] )
{
v9 = 0;
do
{
result = write(fd, v10, 0x200uLL);
++v9;
}
while ( a2[4] > v9 );
}
return result;
}

original_code:
void clear_file_entries(int dfs_handle, dfs_super_block_t *sb)
{
 int i;
 byte1_t block[512];
 for (i = 0; i < sb->block_size / sb->entry_size; i++)
 {
  memcpy(block + i * sb->entry_size, &fe, sizeof(fe));
 }
 for (i = 0; i < sb->entry_table_size; i++)
 {
  write(dfs_handle, block, sizeof(block));
 }
}

canonical_original_code:
void clear_file_entries(int dfs_handle, struct dfs_super_block *sb)
{
 int i;
 unsigned char block[512];
 for (i = 0; i < sb->block_size / sb->entry_size; i++)
 {
  memcpy(block + i * sb->entry_size, &fe, sizeof(fe));
 }
 for (i = 0; i < sb->entry_table_size; i++)
 {
  write(dfs_handle, block, sizeof(block));
 }
}

variable_types:
block
unsigned char [512]

user_defined_types: struct dfs_super_block { unsigned int type; unsigned int block_size; unsigned int partition_size; unsigned int entry_size; unsigned int entry_table_size; unsigned int entry_table_block_start; unsigned int entry_count; unsigned int data_block_start; unsigned int reserved[-1]; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
int v4; // eax
int v5; // er12
int *v6; // rax
char *v7; // rax
int *v8; // rax
char *v9; // rax
unsigned __int64 v10[4]; // [rsp+8h] [rbp-20h] BYREF

if ( argc == 2 )
{
v4 = open(argv[1], 2, envp);
v5 = v4;
if ( v4 == -1 )
{
v6 = __errno_location();
v7 = strerror(*v6);
fprintf(stderr, "Error formatting %s: %s\n", argv[1], v7);
result = 2;
}
else if ( ioctl(v4, 0x80081272uLL, v10) == -1 )
{
v8 = __errno_location();
v9 = strerror(*v8);
fprintf(stderr, "Error getting size of %s: %s\n", argv[1], v9);
result = 3;
}
else
{
dword_4040A8 = v10[0] >> 9;
dword_4040B0 = (int)((double)dword_4040A8 * 0.1);
dword_4040B8 = dword_4040A4 * dword_4040B0 / (unsigned int)dword_4040AC;
dword_4040BC = dword_4040B0 + 1;
printf("Partitioning %Ld byte sized %s ... ", v10[0], argv[1]);
fflush(_bss_start);
write_super_block(v5, &sb);
clear_file_entries(v5, &sb);
close(v5);
puts("done");
result = 0;
}
}
else
{
fprintf(stderr, "Usage: %s <partition's device file>\n", *argv);
result = 1;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
int v4; // eax
int v5; // er12
int *v6; // rax
char *v7; // rax
int *v8; // rax
char *v9; // rax
unsigned __int64 v10[4]; // [rsp+8h] [rbp-20h] BYREF

if ( argc == 2 )
{
v4 = open(argv[1], 2, envp);
v5 = v4;
if ( v4 == -1 )
{
v6 = __errno_location();
v7 = strerror(*v6);
fprintf(stderr, "Error formatting %s: %s\n", argv[1], v7);
result = 2;
}
else if ( ioctl(v4, 0x80081272uLL, v10) == -1 )
{
v8 = __errno_location();
v9 = strerror(*v8);
fprintf(stderr, "Error getting size of %s: %s\n", argv[1], v9);
result = 3;
}
else
{
dword_4040A8 = v10[0] >> 9;
dword_4040B0 = (int)((double)dword_4040A8 * 0.1);
dword_4040B8 = dword_4040A4 * dword_4040B0 / (unsigned int)dword_4040AC;
dword_4040BC = dword_4040B0 + 1;
printf("Partitioning %Ld byte sized %s ... ", v10[0], argv[1]);
fflush(_bss_start);
func7(v5, &sb);
func8(v5, &sb);
close(v5);
puts("done");
result = 0;
}
}
else
{
fprintf(stderr, "Usage: %s <partition's device file>\n", *argv);
result = 1;
}
return result;
}

original_code:
int main(int argc, char *argv[])
{
 int dfs_handle;
 byte8_t size;
 if (argc != 2)
 {
  fprintf(stderr, "Usage: %s <partition's device file>\n", argv[0]);
  return 1;
 }
 dfs_handle = open(argv[1], 02);
 if (dfs_handle == -1)
 {
  fprintf(stderr, "Error formatting %s: %s\n", argv[1], strerror((*__errno_location ())));
  return 2;
 }
 if (ioctl(dfs_handle, (((2U) << (((0 +8)+8)+14)) | (((0x12)) << (0 +8)) | (((114)) << 0) | ((((sizeof(size_t)))) << ((0 +8)+8))), &size) == -1)
 {
  fprintf(stderr, "Error getting size of %s: %s\n", argv[1], strerror((*__errno_location ())));
  return 3;
 }
 sb.partition_size = size / 512;
 sb.entry_table_size = sb.partition_size * 0.10;
 sb.entry_count = sb.entry_table_size * sb.block_size / sb.entry_size;
 sb.data_block_start = 1 + sb.entry_table_size;
 printf("Partitioning %Ld byte sized %s ... ", size, argv[1]);
 fflush(stdout);
 write_super_block(dfs_handle, &sb);
 clear_file_entries(dfs_handle, &sb);
 close(dfs_handle);
 printf("done\n");
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 int dfs_handle;
 unsigned long long size;
 if (argc != 2)
 {
  fprintf(stderr, "Usage: %s <partition's device file>\n", argv[0]);
  return 1;
 }
 dfs_handle = open(argv[1], 02);
 if (dfs_handle == -1)
 {
  fprintf(stderr, "Error formatting %s: %s\n", argv[1], strerror((*__errno_location ())));
  return 2;
 }
 if (ioctl(dfs_handle, (((2U) << (((0 +8)+8)+14)) | (((0x12)) << (0 +8)) | (((114)) << 0) | ((((sizeof(unsigned long)))) << ((0 +8)+8))), &size) == -1)
 {
  fprintf(stderr, "Error getting size of %s: %s\n", argv[1], strerror((*__errno_location ())));
  return 3;
 }
 sb.partition_size = size / 512;
 sb.entry_table_size = sb.partition_size * 0.10;
 sb.entry_count = sb.entry_table_size * sb.block_size / sb.entry_size;
 sb.data_block_start = 1 + sb.entry_table_size;
 printf("Partitioning %Ld byte sized %s ... ", size, argv[1]);
 fflush(stdout);
 write_super_block(dfs_handle, &sb);
 clear_file_entries(dfs_handle, &sb);
 close(dfs_handle);
 printf("done\n");
 return 0;
}

variable_types:
argv
char *[]

variable_types:
size
unsigned long long


repo: djbclark/termim

canonical_decompiled_code:
void func0()
{
compose = -1;
min = 0;
}

original_code:
static void
compose_init(void)
{
    compose = -1;
    min = 0;
}

canonical_original_code:
static void compose_init()
{
    compose = -1;
    min = 0;
}


decompiled_code:
void compose_western_init()
{
lang = (__int64)&lang_western;
compose_init();
}

canonical_decompiled_code:
void func1()
{
lang = (__int64)&lang_western;
func0();
}

original_code:
static void
compose_western_init(void)
{
    lang = &lang_western;
    compose_init();
}

canonical_original_code:
static void compose_western_init()
{
    lang = &lang_western;
    compose_init();
}


decompiled_code:
void compose_cyrillic_init()
{
lang = (__int64)&lang_cyrillic;
compose_init();
}

canonical_decompiled_code:
void func2()
{
lang = (__int64)&lang_cyrillic;
func0();
}

original_code:
static void
compose_cyrillic_init(void)
{
    lang = &lang_cyrillic;
    compose_init();
}

canonical_original_code:
static void compose_cyrillic_init()
{
    lang = &lang_cyrillic;
    compose_init();
}


decompiled_code:
void compose_greek_init()
{
lang = (__int64)&lang_greek;
compose_init();
}

canonical_decompiled_code:
void func3()
{
lang = (__int64)&lang_greek;
func0();
}

original_code:
static void
compose_greek_init(void)
{
    lang = &lang_greek;
    compose_init();
}

canonical_original_code:
static void compose_greek_init()
{
    lang = &lang_greek;
    compose_init();
}


decompiled_code:
void compose_thai_init()
{
lang = (__int64)&lang_thai;
compose_init();
}

canonical_decompiled_code:
void func4()
{
lang = (__int64)&lang_thai;
func0();
}

original_code:
static void
compose_thai_init(void)
{
    lang = &lang_thai;
    compose_init();
}

canonical_original_code:
static void compose_thai_init()
{
    lang = &lang_thai;
    compose_init();
}


decompiled_code:
void compose_arabic_init()
{
lang = (__int64)&lang_arabic;
compose_init();
}

canonical_decompiled_code:
void func5()
{
lang = (__int64)&lang_arabic;
func0();
}

original_code:
static void
compose_arabic_init(void)
{
    lang = &lang_arabic;
    compose_init();
}

canonical_original_code:
static void compose_arabic_init()
{
    lang = &lang_arabic;
    compose_init();
}


decompiled_code:
void compose_hebrew_init()
{
lang = (__int64)&lang_hebrew;
compose_init();
}

canonical_decompiled_code:
void func6()
{
lang = (__int64)&lang_hebrew;
func0();
}

original_code:
static void
compose_hebrew_init(void)
{
    lang = &lang_hebrew;
    compose_init();
}

canonical_original_code:
static void compose_hebrew_init()
{
    lang = &lang_hebrew;
    compose_init();
}


decompiled_code:
void kr_init()
{
kr_buflen = 0;
kr_buffer = 0;
}

canonical_decompiled_code:
void func0()
{
kr_buflen = 0;
kr_buffer = 0;
}

original_code:
static void
kr_init(void)
{
  kr_buflen = 0;
  kr_buffer[0] = 0;
}

canonical_original_code:
static void kr_init()
{
  kr_buflen = 0;
  kr_buffer[0] = 0;
}


original_code:
static int
kr_attempt_decode(char *input, int howfar, int *shiftby, int greedy)
{
  int match, matchlen, matchscore, i, j, k, l, ll;
  char *p=input, *q;
  match = -1; matchlen = -1;
  for (i=0; kr_cons[i].code>=0 ; i++) {
    l = strlen(kr_cons[i].text);
    if ((l > matchlen) && !strncmp(p, kr_cons[i].text, l))
      { match = kr_cons[i].code; matchlen = l; }
  }
  kr_elements[howfar] = match;
  p += matchlen;
  *shiftby = matchlen;
  match = -1; matchlen = -1;
  for (i=0; kr_vowels[i].code>=0 ; i++) {
    l = strlen(kr_vowels[i].text);
    if ((l > matchlen) && !strncmp(p, kr_vowels[i].text, l))
      { match = kr_vowels[i].code; matchlen = l; }
  }
  if (match<0) return (howfar+1);
  kr_elements[howfar+1] = match;
  p += matchlen;
  *shiftby += matchlen;
  if (howfar>0) return (howfar+2);
  match = -1; matchlen = -1; matchscore = 3;
  for (i=0; kr_endings[i].code>=0 ; i++) {
    l = strlen(kr_endings[i].text);
    if (!strncmp(p, kr_endings[i].text, l)) {
      j = kr_endings[i].code;
      k = kr_attempt_decode(p+l, 3, &ll, greedy);
      q=p+l+ll;
      if (*q==0 || (q[1]==0 && (*q=='y' || *q=='w' || *q=='c'))) {
        if (greedy && k==4) k=-1;
        if (k > matchscore || (k == matchscore && l < matchlen))
          { match = j; matchlen = l; matchscore = k; }
      }
      if (matchscore == 3)
        if (l > matchlen) { match = j; matchlen = l; }
    }
  }
  kr_elements[2] = match;
  p += matchlen;
  *shiftby += matchlen;
  kr_attempt_decode(p, 3, &ll, greedy);
  return matchscore;
}

canonical_original_code:
static int kr_attempt_decode(char *input, int howfar, int *shiftby, int greedy)
{
  int match; int matchlen; int matchscore; int i; int j; int k; int l; int ll;
  char *p = input; char *q;
  match = -1; matchlen = -1;
  for (i=0; kr_cons[i].code>=0 ; i++) {
    l = strlen(kr_cons[i].text);
    if ((l > matchlen) && !strncmp(p, kr_cons[i].text, l))
      { match = kr_cons[i].code; matchlen = l; }
  }
  kr_elements[howfar] = match;
  p += matchlen;
  *shiftby = matchlen;
  match = -1; matchlen = -1;
  for (i=0; kr_vowels[i].code>=0 ; i++) {
    l = strlen(kr_vowels[i].text);
    if ((l > matchlen) && !strncmp(p, kr_vowels[i].text, l))
      { match = kr_vowels[i].code; matchlen = l; }
  }
  if (match<0) return (howfar+1);
  kr_elements[howfar+1] = match;
  p += matchlen;
  *shiftby += matchlen;
  if (howfar>0) return (howfar+2);
  match = -1; matchlen = -1; matchscore = 3;
  for (i=0; kr_endings[i].code>=0 ; i++) {
    l = strlen(kr_endings[i].text);
    if (!strncmp(p, kr_endings[i].text, l)) {
      j = kr_endings[i].code;
      k = kr_attempt_decode(p+l, 3, &ll, greedy);
      q=p+l+ll;
      if (*q==0 || (q[1]==0 && (*q=='y' || *q=='w' || *q=='c'))) {
        if (greedy && k==4) k=-1;
        if (k > matchscore || (k == matchscore && l < matchlen))
          { match = j; matchlen = l; matchscore = k; }
      }
      if (matchscore == 3)
        if (l > matchlen) { match = j; matchlen = l; }
    }
  }
  kr_elements[2] = match;
  p += matchlen;
  *shiftby += matchlen;
  kr_attempt_decode(p, 3, &ll, greedy);
  return matchscore;
}

variable_types:
input
char *

variable_types: howfar int

variable_types:
shiftby
int *

variable_types: greedy int

variable_types: match int

variable_types: matchlen int

variable_types: matchscore int

variable_types: j int

variable_types: l int

variable_types: ll int

variable_types:
p
char *

variable_types:
q
char *


decompiled_code:
__int64 __fastcall hex_digit(char a1)
{
unsigned __int8 v1; // di

v1 = a1 | 0x20;
if ( (unsigned __int8)(v1 - 48) <= 9u )
return (unsigned int)v1 - 48;
if ( (unsigned __int8)(v1 - 97) > 5u )
return 0xFFFFFFFFLL;
return (unsigned int)v1 - 87;
}

canonical_decompiled_code:
__int64 __fastcall func0(char a1)
{
unsigned __int8 v1; // di

v1 = a1 | 0x20;
if ( (unsigned __int8)(v1 - 48) <= 9u )
return (unsigned int)v1 - 48;
if ( (unsigned __int8)(v1 - 97) > 5u )
return 0xFFFFFFFFLL;
return (unsigned int)v1 - 87;
}

variable_types:
c
unsigned char


decompiled_code:
__int64 __fastcall skip_spaces(unsigned __int8 **a1)
{
const unsigned __int16 **v1; // rsi
__int64 result; // rax

v1 = _ctype_b_loc();
while ( 1 )
{
result = (__int64)*a1;
if ( ((*v1)[**a1] & 0x2000) == 0 )
break;
*a1 = (unsigned __int8 *)(result + 1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned __int8 **a1)
{
const unsigned __int16 **v1; // rsi
__int64 result; // rax

v1 = _ctype_b_loc();
while ( 1 )
{
result = (__int64)*a1;
if ( ((*v1)[**a1] & 0x2000) == 0 )
break;
*a1 = (unsigned __int8 *)(result + 1);
}
return result;
}

original_code:
static void
skip_spaces(unsigned char **p)
{
    while(((*__ctype_b_loc ())[(int) ((**p))] & (unsigned short int) _ISspace))
 (*p)++;
}

canonical_original_code:
static void skip_spaces(unsigned char **p)
{
    while(((*__ctype_b_loc ())[(int) ((**p))] & (unsigned short) _ISspace))
 (*p)++;
}

variable_types:
p
unsigned char **


decompiled_code:
__int64 __fastcall end_of_line(unsigned __int8 **a1)
{
skip_spaces(a1);
return (**a1 == 35) | (unsigned __int8)(**a1 == 0);
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned __int8 **a1)
{
func3(a1);
return (**a1 == 35) | (unsigned __int8)(**a1 == 0);
}

original_code:
static int
end_of_line(unsigned char **p)
{
    skip_spaces(p);
    return(**p == 0 || **p == '#');
}


decompiled_code:
__int64 __fastcall get_key(unsigned __int8 **a1)
{
unsigned __int8 *v2; // r13
unsigned __int8 v3; // bl
const unsigned __int16 *v4; // rax
unsigned __int8 *v5; // rbp
unsigned int v6; // eax
unsigned __int8 *v7; // rdi
unsigned int v8; // ebx
char *endptr; // [rsp+8h] [rbp-30h] BYREF

skip_spaces(a1);
v2 = *a1;
v3 = **a1;
if ( v3 )
{
v4 = *_ctype_b_loc();
v5 = v2;
do
{
if ( (v4[v3] & 0x2000) != 0 )
break;
v3 = *++v5;
}
while ( *v5 );
}
else
{
v5 = *a1;
}
v6 = strtol((const char *)v2, &endptr, 0);
v7 = *a1;
if ( *a1 == (unsigned __int8 *)endptr )
{
v8 = -1;
if ( v5 - v7 == 7 && !memcmp(v7, "compose", 7uLL) )
{
*a1 = v5;
skip_spaces(a1);
v8 = 1110017;
}
}
else
{
v8 = -1;
if ( endptr == (char *)v5 )
{
v8 = v6;
*a1 = v5;
skip_spaces(a1);
}
}
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned __int8 **a1)
{
unsigned __int8 *v2; // r13
unsigned __int8 v3; // bl
const unsigned __int16 *v4; // rax
unsigned __int8 *v5; // rbp
unsigned int v6; // eax
unsigned __int8 *v7; // rdi
unsigned int v8; // ebx
char *endptr; // [rsp+8h] [rbp-30h] BYREF

func3(a1);
v2 = *a1;
v3 = **a1;
if ( v3 )
{
v4 = *_ctype_b_loc();
v5 = v2;
do
{
if ( (v4[v3] & 0x2000) != 0 )
break;
v3 = *++v5;
}
while ( *v5 );
}
else
{
v5 = *a1;
}
v6 = strtol((const char *)v2, &endptr, 0);
v7 = *a1;
if ( *a1 == (unsigned __int8 *)endptr )
{
v8 = -1;
if ( v5 - v7 == 7 && !memcmp(v7, "compose", 7uLL) )
{
*a1 = v5;
func3(a1);
v8 = 1110017;
}
}
else
{
v8 = -1;
if ( endptr == (char *)v5 )
{
v8 = v6;
*a1 = v5;
func3(a1);
}
}
return v8;
}

original_code:
static unsigned
get_key(unsigned char **p)
{
    char *endl;
    unsigned char *end;
    unsigned key;
    int i;
    skip_spaces(p);
    for(end = *p; *end != 0 && !((*__ctype_b_loc ())[(int) ((*end))] & (unsigned short int) _ISspace); end++);
    key = strtol(*p, &endl, 0);
    if((unsigned char *)endl != *p) {
 if(end != (unsigned char *)endl)
     return((unsigned)-1);
 *p = end;
 skip_spaces(p);
 return(key);
    }
    for(i = 0; i < sizeof(special_keys) / sizeof(*special_keys); i++) {
 if(end - *p == strlen(special_keys[i].name) &&
     memcmp(*p, special_keys[i].name, end - *p) == 0) {
     *p = end;
     skip_spaces(p);
     return(special_keys[i].key);
 }
    }
    return((unsigned)-1);
}

canonical_original_code:
static unsigned int get_key(unsigned char **p)
{
    char *endl;
    unsigned char *end;
    unsigned int key;
    int i;
    skip_spaces(p);
    for(end = *p; *end != 0 && !((*__ctype_b_loc ())[(int) ((*end))] & (unsigned short) _ISspace); end++);
    key = strtol(*p, &endl, 0);
    if((unsigned char *)endl != *p) {
 if(end != (unsigned char *)endl)
     return((unsigned int)-1);
 *p = end;
 skip_spaces(p);
 return(key);
    }
    for(i = 0; i < sizeof(special_keys) / sizeof(*special_keys); i++) {
 if(end - *p == strlen(special_keys[i].name) &&
     memcmp(*p, special_keys[i].name, end - *p) == 0) {
     *p = end;
     skip_spaces(p);
     return(special_keys[i].key);
 }
    }
    return((unsigned int)-1);
}

variable_types:
endl
char *

variable_types:
end
unsigned char *

variable_types:
key
unsigned int

variable_types: i int

return_type: unsigned int


decompiled_code:
__int64 __fastcall is_word(char *s1, unsigned __int8 **a2)
{
size_t v2; // rbp
unsigned __int8 *v3; // r13
unsigned int v4; // ebx
unsigned __int8 *v5; // rbp

skip_spaces(a2);
v2 = (int)strlen(s1);
v3 = *a2;
v4 = 0;
if ( !strncmp(s1, (const char *)*a2, v2) )
{
v4 = 0;
v5 = &v3[v2];
if ( ((*_ctype_b_loc())[*v5] & 0x2000) != 0 )
{
*a2 = v5;
skip_spaces(a2);
v4 = 1;
}
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func6(char *s1, unsigned __int8 **a2)
{
size_t v2; // rbp
unsigned __int8 *v3; // r13
unsigned int v4; // ebx
unsigned __int8 *v5; // rbp

func3(a2);
v2 = (int)strlen(s1);
v3 = *a2;
v4 = 0;
if ( !strncmp(s1, (const char *)*a2, v2) )
{
v4 = 0;
v5 = &v3[v2];
if ( ((*_ctype_b_loc())[*v5] & 0x2000) != 0 )
{
*a2 = v5;
func3(a2);
v4 = 1;
}
}
return v4;
}

original_code:
static int
is_word(const unsigned char *w, unsigned char **p)
{
    int l;
    skip_spaces(p);
    l = strlen(w);
    if(strncmp(w, *p, l) != 0)
 return(0);
    if(!((*__ctype_b_loc ())[(int) (((*p)[l]))] & (unsigned short int) _ISspace))
 return(0);
    *p += l;
    skip_spaces(p);
    return(1);
}

canonical_original_code:
static int is_word(unsigned char *w, unsigned char **p)
{
    int l;
    skip_spaces(p);
    l = strlen(w);
    if(strncmp(w, *p, l) != 0)
 return(0);
    if(!((*__ctype_b_loc ())[(int) (((*p)[l]))] & (unsigned short) _ISspace))
 return(0);
    *p += l;
    skip_spaces(p);
    return(1);
}

variable_types:
w
unsigned char *


canonical_original_code:
static unsigned char *get_string(unsigned char **p, int *l)
{
    unsigned char *r; unsigned char *q;
    *l = 0;
    r = q = *p;
    skip_spaces(p);
    if(**p != '"')
 return(((void *)0));
    (*p)++;
    while(**p != '"') {
 switch(**p) {
     case 0:
  return(((void *)0));
     case '\\':
  (*p)++;
  switch(**p) {
      case 'e': case 'E':
   *(q++) = '\033';
   (*l)++;
   (*p)++;
   break;
      case 'n': case 'N':
   *(q++) = '\n';
   (*l)++;
   (*p)++;
   break;
      case 'r': case 'R':
   *(q++) = '\r';
   (*l)++;
   (*p)++;
   break;
      case 't': case 'T':
   *(q++) = '\t';
   (*l)++;
   (*p)++;
   break;
      case '\\':
   *(q++) = '\\';
   (*l)++;
   (*p)++;
   break;
      case '"':
   *(q++) = '"';
   (*l)++;
   (*p)++;
   break;
      case 'x': case 'X':
   if(hex_digit((*p)[1]) < 0 || hex_digit((*p)[2]) < 0)
       fprintf(stderr, "Invalid \\x sequence.\n");
   *(q++) = hex_digit((*p)[1]) * 16 + hex_digit((*p)[2]);
   (*l)++;
   (*p) += 3;
   break;
      case 'u': case 'U':
   {
       unsigned int u = 0; unsigned int lu;
       for((*p)++; hex_digit(**p) >= 0; (*p)++)
    u = u * 16 + hex_digit(**p);
       if(**p == '\\')
    (*p)++;
       lu = to_utf8(u, q);
       q += lu;
       (*l) += lu;
   }
   break;
      default:
   fprintf(stderr, "Unknown escape sequence.\n");
   return(((void *)0));
  }
  break;
     default:
  *(q++) = *((*p)++);
  (*l)++;
  break;
 }
    }
    *q = 0;
    (*p)++;
    skip_spaces(p);
    return(r);
}

variable_types:
l
int *

variable_types:
r
unsigned char *

variable_types:
q
unsigned char *

variable_types:
u
unsigned int

variable_types:
lu
unsigned int

return_type: unsigned char *


decompiled_code:
void tonepy_init()
{
offset = 0;
min = 0;
max = 1301;
block = 0;
}

canonical_decompiled_code:
void func0()
{
offset = 0;
min = 0;
max = 1301;
block = 0;
}

original_code:
static void
tonepy_init(void)
{
    offset = 0;
    min = 0;
    max = (sizeof(tonepy_data) / sizeof(*tonepy_data)) - 1;
    block = 0;
}

canonical_original_code:
static void tonepy_init()
{
    offset = 0;
    min = 0;
    max = (sizeof(tonepy_data) / sizeof(*tonepy_data)) - 1;
    block = 0;
}


decompiled_code:
__int64 __fastcall han_find(char a1, char a2, char *a3)
{
char v5; // dl
__int64 v6; // rax
unsigned int v7; // esi

v5 = *a3;
if ( !v5 )
return (unsigned int)-1;
v6 = 0LL;
while ( 1 )
{
v7 = v6;
if ( a1 == v5 && a3[2 * v6 + 1] == a2 )
break;
++v6;
v5 = a3[2 * v6];
if ( !v5 )
return (unsigned int)-1;
}
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func0(char a1, char a2, char *a3)
{
char v5; // dl
__int64 v6; // rax
unsigned int v7; // esi

v5 = *a3;
if ( !v5 )
return (unsigned int)-1;
v6 = 0LL;
while ( 1 )
{
v7 = v6;
if ( a1 == v5 && a3[2 * v6 + 1] == a2 )
break;
++v6;
v5 = a3[2 * v6];
if ( !v5 )
return (unsigned int)-1;
}
return v7;
}

original_code:
static int
han_find(char c1, char c2, const char *str)
{
  const char *p;
  int i;
  for (p=str, i=0; *p!=0; p+=2, i++)
    if (*p==c1 && p[1]==c2) return i;
  return -1;
}

canonical_original_code:
static int han_find(char c1, char c2, char *str)
{
  char *p;
  int i;
  for (p=str, i=0; *p!=0; p+=2, i++)
    if (*p==c1 && p[1]==c2) return i;
  return -1;
}

variable_types:
str
char *


decompiled_code:
void han_init()
{
han_buflen = 0;
han_buffer = 0;
han_esc_status = 0;
}

canonical_decompiled_code:
void func1()
{
han_buflen = 0;
han_buffer = 0;
han_esc_status = 0;
}

original_code:
static void
han_init(void)
{
  han_buflen = 0;
  han_buffer[0] = 0;
  han_esc_status = 0;
}

canonical_original_code:
static void han_init()
{
  han_buflen = 0;
  han_buffer[0] = 0;
  han_esc_status = 0;
}


decompiled_code:
void chld_handler()
{
keep = 0;
}

canonical_decompiled_code:
void func0()
{
keep = 0;
}

original_code:
static void
chld_handler(int n)
{
    keep = 0;
}

variable_types: n int


decompiled_code:
int winch_handler()
{
__int16 v1[8]; // [rsp+8h] [rbp-10h] BYREF

ioctl(tty, 0x5413uLL, v1);
screen_height = (unsigned __int16)v1[0];
screen_width = (unsigned __int16)v1[1];
if ( v1[0] > 1u )
--v1[0];
return ioctl(slave, 0x5414uLL, v1);
}

canonical_decompiled_code:
int func2()
{
__int16 v1[8]; // [rsp+8h] [rbp-10h] BYREF

ioctl(tty, 0x5413uLL, v1);
screen_height = (unsigned __int16)v1[0];
screen_width = (unsigned __int16)v1[1];
if ( v1[0] > 1u )
--v1[0];
return ioctl(slave, 0x5414uLL, v1);
}

original_code:
static void
winch_handler(int n)
{
    struct winsize ws;
    ioctl(tty, 0x5413, &ws);
    screen_height = ws.ws_row;
    screen_width = ws.ws_col;
    if(ws.ws_row > 1)
 ws.ws_row--;
    ioctl(slave, 0x5414, &ws);
}

variable_types: struct winsize { unsigned short ws_row; unsigned short ws_col; unsigned short ws_xpixel; unsigned short ws_ypixel; }


variable_types:
c
unsigned int

variable_types:
u
unsigned char *


decompiled_code:
int flush_status_line()
{
fwrite("\x1B[u", 1uLL, 3uLL, tty_file);
return fflush(tty_file);
}

canonical_decompiled_code:
int func5()
{
fwrite("\x1B[u", 1uLL, 3uLL, tty_file);
return fflush(tty_file);
}

original_code:
void
flush_status_line(void)
{
    fputs("\033[u", tty_file);
    fflush(tty_file);
}

canonical_original_code:
void flush_status_line()
{
    fputs("\033[u", tty_file);
    fflush(tty_file);
}


decompiled_code:
int print_current_map()
{
status_line();
fprintf(tty_file, "Map: %s", *(const char **)(current_map + 8));
return flush_status_line();
}

canonical_decompiled_code:
int func6()
{
func4();
fprintf(tty_file, "Map: %s", *(const char **)(current_map + 8));
return func5();
}

original_code:
static void
print_current_map(void)
{
    status_line();
    fprintf(tty_file, "Map: %s", current_map->name);
    flush_status_line();
}

canonical_original_code:
static void print_current_map()
{
    status_line();
    fprintf(tty_file, "Map: %s", current_map->name);
    flush_status_line();
}


decompiled_code:
int __fastcall status_line_say(char *s)
{
status_line();
fputs(s, tty_file);
return flush_status_line();
}

canonical_decompiled_code:
int __fastcall func8(char *s)
{
func4();
fputs(s, tty_file);
return func5();
}

original_code:
void
status_line_say(const char *t)
{
    status_line();
    fputs(t, tty_file);
    flush_status_line();
}

canonical_original_code:
void status_line_say(char *t)
{
    status_line();
    fputs(t, tty_file);
    flush_status_line();
}

variable_types:
t
char *


repo: djrbliss/libplayground

decompiled_code:
int playground_init()
{
int result; // eax

result = open("/dev/playground", 0);
playgroundfd = result;
return result;
}

canonical_decompiled_code:
int func6()
{
int result; // eax

result = open("/dev/playground", 0);
playgroundfd = result;
return result;
}

original_code:
int playground_init(void)
{
 playgroundfd = open("/dev/playground", 00);
 return playgroundfd;
}

canonical_original_code:
int playground_init()
{
 playgroundfd = open("/dev/playground", 00);
 return playgroundfd;
}


decompiled_code:
int playground_close()
{
return close(playgroundfd);
}

canonical_decompiled_code:
int func7()
{
return close(playgroundfd);
}

original_code:
int playground_close(void)
{
 return close(playgroundfd);
}


kmalloc

decompiled_code:
int __fastcall kmalloc(int a1, int a2)
{
int v3[10]; // [rsp+0h] [rbp-28h] BYREF

v3[0] = a1;
v3[1] = a2;
return ioctl(playgroundfd, 0x80205001uLL, v3);
}

canonical_decompiled_code:
int __fastcall func8(int a1, int a2)
{
int v3[10]; // [rsp+0h] [rbp-28h] BYREF

v3[0] = a1;
v3[1] = a2;
return ioctl(playgroundfd, 0x80205001uLL, v3);
}

original_code:
int kmalloc(unsigned int index, unsigned int size)
{
 struct playground_args args;
 args.slot = index;
 args.size = size;
 return ioctl(playgroundfd, (((2U) << (((0 +8)+8)+14)) | ((('P')) << (0 +8)) | (((1)) << 0) | ((((sizeof(struct playground_args)))) << ((0 +8)+8))), &args);
}

variable_types:
index
unsigned int

variable_types:
size
unsigned int

variable_types: struct playground_args { unsigned int slot; unsigned int size; unsigned int offset; void *ptr; unsigned char fill; }


decompiled_code:
int __fastcall kmalloc_fill(int a1, int a2, char a3)
{
int v4[6]; // [rsp+0h] [rbp-28h] BYREF
char v5; // [rsp+18h] [rbp-10h]

v4[0] = a1;
v4[1] = a2;
v5 = a3;
return ioctl(playgroundfd, 0x80205006uLL, v4);
}

canonical_decompiled_code:
int __fastcall func9(int a1, int a2, char a3)
{
int v4[6]; // [rsp+0h] [rbp-28h] BYREF
char v5; // [rsp+18h] [rbp-10h]

v4[0] = a1;
v4[1] = a2;
v5 = a3;
return ioctl(playgroundfd, 0x80205006uLL, v4);
}

original_code:
int kmalloc_fill(unsigned int index, unsigned int size, unsigned char fill)
{
 struct playground_args args;
 args.slot = index;
 args.size = size;
 args.fill = fill;
 return ioctl(playgroundfd, (((2U) << (((0 +8)+8)+14)) | ((('P')) << (0 +8)) | (((6)) << 0) | ((((sizeof(struct playground_args)))) << ((0 +8)+8))), &args);
}

variable_types:
fill
unsigned char

user_defined_types: struct playground_args { unsigned int slot; unsigned int size; unsigned int offset; void *ptr; unsigned char fill; }


ktrigger

decompiled_code:
int __fastcall ktrigger(int a1, int a2)
{
int v3[10]; // [rsp+0h] [rbp-28h] BYREF

v3[0] = a1;
v3[2] = a2;
return ioctl(playgroundfd, 0x80205007uLL, v3);
}

canonical_decompiled_code:
int __fastcall func10(int a1, int a2)
{
int v3[10]; // [rsp+0h] [rbp-28h] BYREF

v3[0] = a1;
v3[2] = a2;
return ioctl(playgroundfd, 0x80205007uLL, v3);
}

original_code:
int ktrigger(unsigned int index, unsigned int offset)
{
 struct playground_args args;
 args.slot = index;
 args.offset = offset;
 return ioctl(playgroundfd, (((2U) << (((0 +8)+8)+14)) | ((('P')) << (0 +8)) | (((7)) << 0) | ((((sizeof(struct playground_args)))) << ((0 +8)+8))), &args);
}

variable_types:
offset
unsigned int


kwrite

decompiled_code:
int __fastcall kwrite(int a1, int a2, __int64 a3)
{
int v4[4]; // [rsp+0h] [rbp-28h] BYREF
__int64 v5; // [rsp+10h] [rbp-18h]

v4[0] = a1;
v4[1] = a2;
v5 = a3;
return ioctl(playgroundfd, 0x80205004uLL, v4);
}

canonical_decompiled_code:
int __fastcall func11(int a1, int a2, __int64 a3)
{
int v4[4]; // [rsp+0h] [rbp-28h] BYREF
__int64 v5; // [rsp+10h] [rbp-18h]

v4[0] = a1;
v4[1] = a2;
v5 = a3;
return ioctl(playgroundfd, 0x80205004uLL, v4);
}

original_code:
int kwrite(unsigned int index, unsigned int size, char *data)
{
 struct playground_args args;
 args.slot = index;
 args.size = size;
 args.ptr = data;
 return ioctl(playgroundfd, (((2U) << (((0 +8)+8)+14)) | ((('P')) << (0 +8)) | (((4)) << 0) | ((((sizeof(struct playground_args)))) << ((0 +8)+8))), &args);
}

variable_types:
data
char *


kread

decompiled_code:
int __fastcall kread(int a1, int a2, __int64 a3)
{
int v4[4]; // [rsp+0h] [rbp-28h] BYREF
__int64 v5; // [rsp+10h] [rbp-18h]

v4[0] = a1;
v4[1] = a2;
v5 = a3;
return ioctl(playgroundfd, 0xC0205005uLL, v4);
}

canonical_decompiled_code:
int __fastcall func12(int a1, int a2, __int64 a3)
{
int v4[4]; // [rsp+0h] [rbp-28h] BYREF
__int64 v5; // [rsp+10h] [rbp-18h]

v4[0] = a1;
v4[1] = a2;
v5 = a3;
return ioctl(playgroundfd, 0xC0205005uLL, v4);
}

original_code:
int kread(unsigned int index, unsigned int size, char *data)
{
 struct playground_args args;
 args.slot = index;
 args.size = size;
 args.ptr = data;
 return ioctl(playgroundfd, (((2U|1U) << (((0 +8)+8)+14)) | ((('P')) << (0 +8)) | (((5)) << 0) | ((((sizeof(struct playground_args)))) << ((0 +8)+8))), &args);
}


kfree

decompiled_code:
int __fastcall kfree(int a1)
{
int v2[10]; // [rsp+0h] [rbp-28h] BYREF

v2[0] = a1;
return ioctl(playgroundfd, 0x80205002uLL, v2);
}

canonical_decompiled_code:
int __fastcall func13(int a1)
{
int v2[10]; // [rsp+0h] [rbp-28h] BYREF

v2[0] = a1;
return ioctl(playgroundfd, 0x80205002uLL, v2);
}

original_code:
int kfree(unsigned int index)
{
 struct playground_args args;
 args.slot = index;
 return ioctl(playgroundfd, (((2U) << (((0 +8)+8)+14)) | ((('P')) << (0 +8)) | (((2)) << 0) | ((((sizeof(struct playground_args)))) << ((0 +8)+8))), &args);
}


kdoublefree

decompiled_code:
int __fastcall kdoublefree(int a1)
{
int v2[10]; // [rsp+0h] [rbp-28h] BYREF

v2[0] = a1;
return ioctl(playgroundfd, 0x80205003uLL, v2);
}

canonical_decompiled_code:
int __fastcall func14(int a1)
{
int v2[10]; // [rsp+0h] [rbp-28h] BYREF

v2[0] = a1;
return ioctl(playgroundfd, 0x80205003uLL, v2);
}

original_code:
int kdoublefree(unsigned int index)
{
 struct playground_args args;
 args.slot = index;
 return ioctl(playgroundfd, (((2U) << (((0 +8)+8)+14)) | ((('P')) << (0 +8)) | (((3)) << 0) | ((((sizeof(struct playground_args)))) << ((0 +8)+8))), &args);
}


Date

repo: dkrutsko/Version

decompiled_code:
time_t Date()
{
time_t v0; // rbx
struct tm v2; // [rsp+0h] [rbp-48h] BYREF

v2.tm_sec = 0;
v2.tm_min = 0;
v2.tm_hour = 0;
v2.tm_mday = 1;
v2.tm_mon = 0;
v2.tm_year = 100;
v2.tm_wday = 6;
v2.tm_yday = 0;
v2.tm_isdst = 0;
v0 = time(0LL);
return (v0 - mktime(&v2)) / 86400;
}

canonical_decompiled_code:
time_t func7()
{
time_t v0; // rbx
struct tm v2; // [rsp+0h] [rbp-48h] BYREF

v2.tm_sec = 0;
v2.tm_min = 0;
v2.tm_hour = 0;
v2.tm_mday = 1;
v2.tm_mon = 0;
v2.tm_year = 100;
v2.tm_wday = 6;
v2.tm_yday = 0;
v2.tm_isdst = 0;
v0 = time(0LL);
return (v0 - mktime(&v2)) / 86400;
}

original_code:
static unsigned int Date (void)
{
 time_t lBase;
 time_t lCurr;
 struct tm lTime;
 lTime.tm_sec = 0;
 lTime.tm_min = 0;
 lTime.tm_hour = 0;
 lTime.tm_mday = 1;
 lTime.tm_mon = 0;
 lTime.tm_year = 100;
 lTime.tm_wday = 6;
 lTime.tm_yday = 0;
 lTime.tm_isdst = 0;
 lCurr = time (((void *)0));
 lBase = mktime (&lTime);
 return (unsigned int)
  ((lCurr - lBase) / 86400);
}

canonical_original_code:
static unsigned int Date()
{
 long lBase;
 long lCurr;
 struct tm lTime;
 lTime.tm_sec = 0;
 lTime.tm_min = 0;
 lTime.tm_hour = 0;
 lTime.tm_mday = 1;
 lTime.tm_mon = 0;
 lTime.tm_year = 100;
 lTime.tm_wday = 6;
 lTime.tm_yday = 0;
 lTime.tm_isdst = 0;
 lCurr = time (((void *)0));
 lBase = mktime (&lTime);
 return (unsigned int)
  ((lCurr - lBase) / 86400);
}

variable_types: lBase long

variable_types: lCurr long

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


Time

decompiled_code:
time_t Time()
{
struct tm *v0; // rax
time_t v1; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

timer = time(0LL);
v0 = localtime(&timer);
v0->tm_sec = 0;
v0->tm_min = 0;
v0->tm_hour = 0;
v1 = mktime(v0);
return (timer - v1) / 2;
}

canonical_decompiled_code:
time_t func8()
{
struct tm *v0; // rax
time_t v1; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

timer = time(0LL);
v0 = localtime(&timer);
v0->tm_sec = 0;
v0->tm_min = 0;
v0->tm_hour = 0;
v1 = mktime(v0);
return (timer - v1) / 2;
}

original_code:
static unsigned int Time (void)
{
 time_t lBase;
 time_t lCurr;
 struct tm* lTime;
 lBase = 0;
 lCurr = time (((void *)0));
 lTime = localtime (&lCurr);
 lTime->tm_sec = 0;
 lTime->tm_min = 0;
 lTime->tm_hour = 0;
 lBase = mktime (lTime);
 return (unsigned int)
  ((lCurr - lBase) / 2);
}

canonical_original_code:
static unsigned int Time()
{
 long lBase;
 long lCurr;
 struct tm *lTime;
 lBase = 0;
 lCurr = time (((void *)0));
 lTime = localtime (&lCurr);
 lTime->tm_sec = 0;
 lTime->tm_min = 0;
 lTime->tm_hour = 0;
 lBase = mktime (lTime);
 return (unsigned int)
  ((lCurr - lBase) / 2);
}

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


repo: dloghin/libdsa

original_code:
void delete_node(List* del_node) {
 if (del_node == ((void *)0))
  return;
 if (del_node->prev == ((void *)0))
  return;
 del_node->prev->next = del_node->next;
 if (del_node->next != ((void *)0))
  del_node->next->prev = del_node->prev;
 if (last == del_node)
  last = del_node->prev;
 free(del_node);
}

canonical_original_code:
void delete_node(struct node *del_node) {
 if (del_node == ((void *)0))
  return;
 if (del_node->prev == ((void *)0))
  return;
 del_node->prev->next = del_node->next;
 if (del_node->next != ((void *)0))
  del_node->next->prev = del_node->prev;
 if (last == del_node)
  last = del_node->prev;
 free(del_node);
}

variable_types: struct node { int val; struct node *next; struct node *prev; } *


decompiled_code:
void delete_list()
{
_QWORD *v0; // rbx
void *v1; // rdi

v0 = *(_QWORD **)(head + 8LL);
while ( v0 )
{
v1 = v0;
v0 = (_QWORD *)v0[1];
free(v1);
}
}

canonical_decompiled_code:
void func1()
{
_QWORD *v0; // rbx
void *v1; // rdi

v0 = *(_QWORD **)(head + 8LL);
while ( v0 )
{
v1 = v0;
v0 = (_QWORD *)v0[1];
free(v1);
}
}

original_code:
void delete_list() {
 List* p = head->next;
 List* curr;
 while (p != ((void *)0)) {
  curr = p;
  p = p->next;
  free(curr);
 }
}

canonical_original_code:
void delete_list() {
 struct node *p = head->next;
 struct node *curr;
 while (p != ((void *)0)) {
  curr = p;
  p = p->next;
  free(curr);
 }
}

user_defined_types: struct node { int val; struct node *next; struct node *prev; }


decompiled_code:
int print_list()
{
unsigned int *i; // rbx

for ( i = *(unsigned int **)(head + 8LL); i; i = (unsigned int *)*((_QWORD *)i + 1) )
printf("-> %d ", *i);
return putchar(10);
}

canonical_decompiled_code:
int func2()
{
unsigned int *i; // rbx

for ( i = *(unsigned int **)(head + 8LL); i; i = (unsigned int *)*((_QWORD *)i + 1) )
printf("-> %d ", *i);
return putchar(10);
}

original_code:
void print_list() {
 List* p = head->next;
 while (p != ((void *)0)) {
  printf("-> %d ", p->val);
  p = p->next;
 }
 printf("\n");
}

canonical_original_code:
void print_list() {
 struct node *p = head->next;
 while (p != ((void *)0)) {
  printf("-> %d ", p->val);
  p = p->next;
 }
 printf("\n");
}


add

decompiled_code:
__int64 __fastcall add(int a1)
{
_QWORD *v1; // rax

if ( ptr[a1] )
return 4294967292LL;
v1 = add_node(a1);
ptr[a1] = v1;
return v1 == 0LL ? 0xFFFFFFFB : 0;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
_QWORD *v1; // rax

if ( ptr[a1] )
return 4294967292LL;
v1 = add_node(a1);
ptr[a1] = v1;
return v1 == 0LL ? 0xFFFFFFFB : 0;
}

original_code:
int add(int n) {
 if (ptr[n] != ((void *)0))
  return EINVALARG;
 ptr[n] = add_node(n);
 if (ptr[n] != ((void *)0))
  return SUCCESS;
 return EERROR;
}


delete

decompiled_code:
__int64 __fastcall delete(int a1)
{
_QWORD *v2; // rdi

v2 = (_QWORD *)ptr[a1];
if ( !v2 )
return 4294967292LL;
delete_node(v2);
ptr[a1] = 0LL;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1)
{
_QWORD *v2; // rdi

v2 = (_QWORD *)ptr[a1];
if ( !v2 )
return 4294967292LL;
func0(v2);
ptr[a1] = 0LL;
return 0LL;
}

original_code:
int delete(int n) {
 if (ptr[n] == ((void *)0))
  return EINVALARG;
 delete_node(ptr[n]);
 ptr[n] = ((void *)0);
 return SUCCESS;
}