GetCurrentTime

original_code:
void GetCurrentTime(char *OutHr, char *OutMin, char *OutSec, char *OutYear, char *OutMonth, char *OutDay)
{
 struct tm TimeStruct;
 int HMS_I[3];
 int MDY_I[3];
 char *HMS[3];
 char *MDY[3];
 short Inc = 0;
 time_t TimeT;
 HMS[0] = OutHr;
 HMS[1] = OutMin;
 HMS[2] = OutSec;
 MDY[0] = OutMonth;
 MDY[1] = OutDay;
 MDY[2] = OutYear;
 time(&TimeT);
 localtime_r(&TimeT, &TimeStruct);
 HMS_I[0] = TimeStruct.tm_hour;
 HMS_I[1] = TimeStruct.tm_min;
 HMS_I[2] = TimeStruct.tm_sec;
 MDY_I[0] = TimeStruct.tm_mon + 1;
 MDY_I[1] = TimeStruct.tm_mday;
 MDY_I[2] = TimeStruct.tm_year + 1900;
 for (; Inc < 3; ++Inc)
 {
  if (HMS[Inc] == ((void *)0))
  {
   continue;
  }
  snprintf(HMS[Inc], 16, (HMS_I[Inc] >= 10 ? "%u" : "0%u"), HMS_I[Inc]);
 }
 for (Inc = 0; Inc < 3; ++Inc)
 {
  if (MDY[Inc] != ((void *)0))
  {
   snprintf(MDY[Inc], 16, (MDY_I[Inc] >= 10 ? "%u" : "0%u"), MDY_I[Inc]);
  }
 }
}

canonical_original_code:
void GetCurrentTime(char *OutHr, char *OutMin, char *OutSec, char *OutYear, char *OutMonth, char *OutDay)
{
 struct tm TimeStruct;
 int HMS_I[3];
 int MDY_I[3];
 char *HMS[3];
 char *MDY[3];
 short Inc = 0;
 long TimeT;
 HMS[0] = OutHr;
 HMS[1] = OutMin;
 HMS[2] = OutSec;
 MDY[0] = OutMonth;
 MDY[1] = OutDay;
 MDY[2] = OutYear;
 time(&TimeT);
 localtime_r(&TimeT, &TimeStruct);
 HMS_I[0] = TimeStruct.tm_hour;
 HMS_I[1] = TimeStruct.tm_min;
 HMS_I[2] = TimeStruct.tm_sec;
 MDY_I[0] = TimeStruct.tm_mon + 1;
 MDY_I[1] = TimeStruct.tm_mday;
 MDY_I[2] = TimeStruct.tm_year + 1900;
 for (; Inc < 3; ++Inc)
 {
  if (HMS[Inc] == ((void *)0))
  {
   continue;
  }
  snprintf(HMS[Inc], 16, (HMS_I[Inc] >= 10 ? "%u" : "0%u"), HMS_I[Inc]);
 }
 for (Inc = 0; Inc < 3; ++Inc)
 {
  if (MDY[Inc] != ((void *)0))
  {
   snprintf(MDY[Inc], 16, (MDY_I[Inc] >= 10 ? "%u" : "0%u"), MDY_I[Inc]);
  }
 }
}

variable_types:
OutHr
char *

variable_types:
OutMin
char *

variable_types:
OutSec
char *

variable_types:
OutYear
char *

variable_types:
OutMonth
char *

variable_types:
OutDay
char *

variable_types:
HMS
char *[3]

variable_types:
MDY
char *[3]

variable_types: Inc short

variable_types: TimeT long

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


ObjectProcessRunning

repo: Subsentient/epoch

decompiled_code:
bool __fastcall ObjectProcessRunning(__int64 a1)
{
int v2; // edi
bool result; // al

if ( (*(_BYTE *)(a1 + 142) & 0x20) != 0 && (v2 = ReadPIDFile(a1)) != 0 || (v2 = *(_DWORD *)(a1 + 8), result = 0, v2) )
result = kill(v2, 0) == 0;
return result;
}

canonical_decompiled_code:
bool __fastcall func6(__int64 a1)
{
int v2; // edi
bool result; // al

if ( (*(_BYTE *)(a1 + 142) & 0x20) != 0 && (v2 = func5(a1)) != 0 || (v2 = *(_DWORD *)(a1 + 8), result = 0, v2) )
result = kill(v2, 0) == 0;
return result;
}

original_code:
Bool ObjectProcessRunning(const ObjTable *InObj)
{
 pid_t InPID = 0;
 if (!InObj->Opts.HasPIDFile || !(InPID = ReadPIDFile(InObj)))
 {
  InPID = InObj->ObjectPID;
 }
 if (InPID == 0)
 {
  return false;
 }
 if (kill(InPID, 0) == 0)
 {
  return true;
 }
 else
 {
  return false;
 }
}

canonical_original_code:
char ObjectProcessRunning(struct _EpochObjectTable *InObj)
{
 int InPID = 0;
 if (!InObj->Opts.HasPIDFile || !(InPID = ReadPIDFile(InObj)))
 {
  InPID = InObj->ObjectPID;
 }
 if (InPID == 0)
 {
  return false;
 }
 if (kill(InPID, 0) == 0)
 {
  return true;
 }
 else
 {
  return false;
 }
}

variable_types: struct _EpochObjectTable { unsigned int ObjectStartPriority; unsigned int ObjectStopPriority; unsigned int ObjectPID; unsigned int UserID; unsigned int GroupID; unsigned int StartedSince; char *ObjectID; char *ObjectDescription; char *ObjectStartCommand; char *ObjectPrestartCommand; char *ObjectStopCommand; char *ObjectReloadCommand; char *ObjectPIDFile; char *ObjectWorkingDirectory; char *ObjectStderr; char *ObjectStdout; char *ConfigFile; unsigned char TermSignal; unsigned char ReloadCommandSignal; char Enabled; char Started; struct { unsigned char ExitStatus; unsigned char Value; } ExitStatuses[8]; struct { enum _StopMode { STOP_NONE=0, STOP_COMMAND=1, STOP_PID=2, STOP_PIDFILE=3, STOP_INVALID=4 } StopMode; unsigned int StopTimeout; unsigned short AutoRestart; unsigned int Persistent; unsigned int HaltCmdOnly; unsigned int IsService; unsigned int RawDescription; unsigned int ForceShell; unsigned int HasPIDFile; unsigned int NoStopWait; unsigned int PivotRoot; unsigned int Exec; unsigned int RunOnce; unsigned int StartFailIsCritical; unsigned int StopFailIsCritical; unsigned int NoTrack; unsigned int Interactive; unsigned int Fork; unsigned int ForkScanOnce; } Opts; struct _EnvVarList { char EnvVar[2048]; struct _EnvVarList *Next; struct _EnvVarList *Prev; } *EnvVars; struct _RLTree { char RL[384]; struct _RLTree *Prev; struct _RLTree *Next; } *ObjectRunlevels; struct _EpochObjectTable *Prev; struct _EpochObjectTable *Next; } *

variable_types: InPID int

return_type: char

user_defined_types: struct _EpochObjectTable { unsigned int ObjectStartPriority; unsigned int ObjectStopPriority; unsigned int ObjectPID; unsigned int UserID; unsigned int GroupID; unsigned int StartedSince; char *ObjectID; char *ObjectDescription; char *ObjectStartCommand; char *ObjectPrestartCommand; char *ObjectStopCommand; char *ObjectReloadCommand; char *ObjectPIDFile; char *ObjectWorkingDirectory; char *ObjectStderr; char *ObjectStdout; char *ConfigFile; unsigned char TermSignal; unsigned char ReloadCommandSignal; char Enabled; char Started; struct { unsigned char ExitStatus; unsigned char Value; } ExitStatuses[8]; struct { enum _StopMode StopMode; unsigned int StopTimeout; unsigned short AutoRestart; unsigned int Persistent; unsigned int HaltCmdOnly; unsigned int IsService; unsigned int RawDescription; unsigned int ForceShell; unsigned int HasPIDFile; unsigned int NoStopWait; unsigned int PivotRoot; unsigned int Exec; unsigned int RunOnce; unsigned int StartFailIsCritical; unsigned int StopFailIsCritical; unsigned int NoTrack; unsigned int Interactive; unsigned int Fork; unsigned int ForkScanOnce; } Opts; struct _EnvVarList *EnvVars; struct _RLTree *ObjectRunlevels; struct _EpochObjectTable *Prev; struct _EpochObjectTable *Next; }


GetStateOfTime

decompiled_code:
__int64 __fastcall GetStateOfTime(int a1, int a2, int a3, int a4, int a5, int a6)
{
int v8; // ebp
int v9; // ebx
time_t v10; // rax
unsigned int v11; // er8
time_t timer; // [rsp+0h] [rbp-80h] BYREF
struct tm tp; // [rsp+8h] [rbp-78h] BYREF

v8 = a6 - 1900;
v9 = a4 - 1;
time(&timer);
tp.tm_year = v8;
tp.tm_mon = v9;
tp.tm_mday = a5;
tp.tm_hour = a1;
tp.tm_min = a2;
tp.tm_sec = a3;
tp.tm_isdst = -1;
v10 = mktime(&tp);
if ( v10 == -1 )
return (unsigned int)-1;
v11 = 2;
if ( timer <= v10 )
v11 = timer == v10;
return v11;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1, int a2, int a3, int a4, int a5, int a6)
{
int v8; // ebp
int v9; // ebx
time_t v10; // rax
unsigned int v11; // er8
time_t timer; // [rsp+0h] [rbp-80h] BYREF
struct tm tp; // [rsp+8h] [rbp-78h] BYREF

v8 = a6 - 1900;
v9 = a4 - 1;
time(&timer);
tp.tm_year = v8;
tp.tm_mon = v9;
tp.tm_mday = a5;
tp.tm_hour = a1;
tp.tm_min = a2;
tp.tm_sec = a3;
tp.tm_isdst = -1;
v10 = mktime(&tp);
if ( v10 == -1 )
return (unsigned int)-1;
v11 = 2;
if ( timer <= v10 )
v11 = timer == v10;
return v11;
}

original_code:
short GetStateOfTime(unsigned Hr, unsigned Min, unsigned Sec,
    unsigned Month, unsigned Day, unsigned Year)
{
 time_t CurrentTime, PassedTime;
 struct tm PassedTimeS;
 time(&CurrentTime);
 PassedTimeS.tm_year = Year - 1900;
 PassedTimeS.tm_mon = Month - 1;
 PassedTimeS.tm_mday = Day;
 PassedTimeS.tm_hour = Hr;
 PassedTimeS.tm_min = Min;
 PassedTimeS.tm_sec = Sec;
 PassedTimeS.tm_isdst = -1;
 if ((PassedTime = mktime(&PassedTimeS)) == -1)
 {
  return -1;
 }
 if (PassedTime < CurrentTime)
 {
  return 2;
 }
 else if (PassedTime == CurrentTime)
 {
  return 1;
 }
 else
 {
  return 0;
 }
}

canonical_original_code:
short GetStateOfTime(unsigned int Hr, unsigned int Min, unsigned int Sec, unsigned int Month, unsigned int Day, unsigned int Year)
{
 long CurrentTime; long PassedTime;
 struct tm PassedTimeS;
 time(&CurrentTime);
 PassedTimeS.tm_year = Year - 1900;
 PassedTimeS.tm_mon = Month - 1;
 PassedTimeS.tm_mday = Day;
 PassedTimeS.tm_hour = Hr;
 PassedTimeS.tm_min = Min;
 PassedTimeS.tm_sec = Sec;
 PassedTimeS.tm_isdst = -1;
 if ((PassedTime = mktime(&PassedTimeS)) == -1)
 {
  return -1;
 }
 if (PassedTime < CurrentTime)
 {
  return 2;
 }
 else if (PassedTime == CurrentTime)
 {
  return 1;
 }
 else
 {
  return 0;
 }
}

variable_types:
Hr
unsigned int

variable_types:
Min
unsigned int

variable_types:
Sec
unsigned int

variable_types:
Month
unsigned int

variable_types:
Day
unsigned int

variable_types:
Year
unsigned int

variable_types: CurrentTime long

variable_types: PassedTime 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; }

return_type: short


ProcAvailable

decompiled_code:
bool ProcAvailable()
{
struct stat v1; // [rsp+0h] [rbp-98h] BYREF

return stat("/proc/cmdline", &v1) == 0;
}

canonical_decompiled_code:
bool func8()
{
struct stat v1; // [rsp+0h] [rbp-98h] BYREF

return stat("/proc/cmdline", &v1) == 0;
}

original_code:
Bool ProcAvailable(void)
{
 struct stat FileStat;
 return !stat("/proc/cmdline", &FileStat);
}

canonical_original_code:
char ProcAvailable()
{
 struct stat FileStat;
 return !stat("/proc/cmdline", &FileStat);
}

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


ValidIdentifierName

decompiled_code:
__int64 __fastcall ValidIdentifierName(_BYTE *a1)
{
char v1; // bl
_BYTE *v2; // rbp
const unsigned __int16 *v3; // rdx

v1 = *a1;
if ( !*a1 )
return 1LL;
v2 = a1;
v3 = *_ctype_b_loc();
while ( (v3[v1] & 8) != 0 || v1 == 95 )
{
v1 = *++v2;
if ( !v1 )
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(_BYTE *a1)
{
char v1; // bl
_BYTE *v2; // rbp
const unsigned __int16 *v3; // rdx

v1 = *a1;
if ( !*a1 )
return 1LL;
v2 = a1;
v3 = *_ctype_b_loc();
while ( (v3[v1] & 8) != 0 || v1 == 95 )
{
v1 = *++v2;
if ( !v1 )
return 1LL;
}
return 0LL;
}

original_code:
Bool ValidIdentifierName(const char *const Identifier)
{
 const char *Worker = Identifier;
 for (; *Worker; ++Worker)
 {
  if (!((*__ctype_b_loc ())[(int) ((*Worker))] & (unsigned short int) _ISalnum) && *Worker != '_') return false;
 }
 return true;
}

canonical_original_code:
char ValidIdentifierName(char *Identifier)
{
 char *Worker = Identifier;
 for (; *Worker; ++Worker)
 {
  if (!((*__ctype_b_loc ())[(int) ((*Worker))] & (unsigned short) _ISalnum) && *Worker != '_') return false;
 }
 return true;
}

variable_types:
Identifier
char *

variable_types:
Worker
char *


SendPowerControl

decompiled_code:
__int64 __fastcall SendPowerControl(const char *a1)
{
const char *v2; // r13
const char *v3; // r12
const char *v4; // r14
unsigned int v5; // eax
int v6; // er8
__int64 result; // rax
bool v8; // al
bool v9; // cf
bool v10; // zf
const char *v11; // rdi
__int64 v12; // rcx
const char *v13; // rsi
unsigned int v14; // [rsp+Ch] [rbp-83Ch]
char s1[2056]; // [rsp+10h] [rbp-838h] BYREF
unsigned __int64 v16; // [rsp+818h] [rbp-30h]

v16 = __readfsqword(0x28u);
if ( !strcmp(a1, "INIT_HALT") )
{
v2 = "FAIL INIT_HALT";
v3 = "OK INIT_HALT";
v4 = "Unable to halt.";
v5 = MemBus_Write(a1, 0LL);
if ( !v5 )
{
LABEL_20:
v14 = v5;
SpitError("Failed to write to membus.", 0LL);
return v14;
}
}
else
{
if ( !strcmp(a1, "INIT_POWEROFF") )
{
v2 = "FAIL INIT_POWEROFF";
v3 = "OK INIT_POWEROFF";
v4 = "Unable to power off.";
}
else if ( !strcmp(a1, "INIT_REBOOT") )
{
v2 = "FAIL INIT_REBOOT";
v3 = "OK INIT_REBOOT";
v4 = "Unable to reboot.";
}
else
{
v8 = strcmp(a1, "CADON") != 0;
v9 = 0;
v10 = !v8;
if ( v8 )
{
v11 = "CADOFF";
v12 = 7LL;
v13 = a1;
do
{
if ( !v12 )
break;
v9 = *v13 < (unsigned int)*v11;
v10 = *v13++ == *v11++;
--v12;
}
while ( v10 );
if ( (!v9 && !v10) != v9 )
{
SpitError("Invalid MEMBUS_CODE passed to SendPowerControl().", v13);
return 0LL;
}
v2 = "FAIL CADOFF";
v3 = "OK CADOFF";
v4 = "Unable to disable CTRL-ALT-DEL instant reboot.";
}
else
{
v2 = "FAIL CADON";
v3 = "OK CADON";
v4 = "Unable to enable CTRL-ALT-DEL instant reboot.";
}
}
v5 = MemBus_Write(a1, 0LL);
if ( !v5 )
goto LABEL_20;
}
while ( !(unsigned __int8)MemBus_Read(s1, 0LL) )
usleep(0x3E8u);
MemBus_Write(a1, 0LL);
if ( !strcmp(s1, v3) )
{
ShutdownMemBus(0LL);
result = 1LL;
}
else
{
v6 = strcmp(s1, v2);
result = 1LL;
if ( !v6 )
{
SpitError(v4, v2);
ShutdownMemBus(0LL);
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1)
{
const char *v2; // r13
const char *v3; // r12
const char *v4; // r14
unsigned int v5; // eax
int v6; // er8
__int64 result; // rax
bool v8; // al
bool v9; // cf
bool v10; // zf
const char *v11; // rdi
__int64 v12; // rcx
const char *v13; // rsi
unsigned int v14; // [rsp+Ch] [rbp-83Ch]
char s1[2056]; // [rsp+10h] [rbp-838h] BYREF
unsigned __int64 v16; // [rsp+818h] [rbp-30h]

v16 = __readfsqword(0x28u);
if ( !strcmp(a1, "INIT_HALT") )
{
v2 = "FAIL INIT_HALT";
v3 = "OK INIT_HALT";
v4 = "Unable to halt.";
v5 = MemBus_Write(a1, 0LL);
if ( !v5 )
{
LABEL_20:
v14 = v5;
SpitError("Failed to write to membus.", 0LL);
return v14;
}
}
else
{
if ( !strcmp(a1, "INIT_POWEROFF") )
{
v2 = "FAIL INIT_POWEROFF";
v3 = "OK INIT_POWEROFF";
v4 = "Unable to power off.";
}
else if ( !strcmp(a1, "INIT_REBOOT") )
{
v2 = "FAIL INIT_REBOOT";
v3 = "OK INIT_REBOOT";
v4 = "Unable to reboot.";
}
else
{
v8 = strcmp(a1, "CADON") != 0;
v9 = 0;
v10 = !v8;
if ( v8 )
{
v11 = "CADOFF";
v12 = 7LL;
v13 = a1;
do
{
if ( !v12 )
break;
v9 = *v13 < (unsigned int)*v11;
v10 = *v13++ == *v11++;
--v12;
}
while ( v10 );
if ( (!v9 && !v10) != v9 )
{
SpitError("Invalid MEMBUS_CODE passed to SendPowerControl().", v13);
return 0LL;
}
v2 = "FAIL CADOFF";
v3 = "OK CADOFF";
v4 = "Unable to disable CTRL-ALT-DEL instant reboot.";
}
else
{
v2 = "FAIL CADON";
v3 = "OK CADON";
v4 = "Unable to enable CTRL-ALT-DEL instant reboot.";
}
}
v5 = MemBus_Write(a1, 0LL);
if ( !v5 )
goto LABEL_20;
}
while ( !(unsigned __int8)MemBus_Read(s1, 0LL) )
usleep(0x3E8u);
MemBus_Write(a1, 0LL);
if ( !strcmp(s1, v3) )
{
ShutdownMemBus(0LL);
result = 1LL;
}
else
{
v6 = strcmp(s1, v2);
result = 1LL;
if ( !v6 )
{
SpitError(v4, v2);
ShutdownMemBus(0LL);
result = 0LL;
}
}
return result;
}

original_code:
ReturnCode SendPowerControl(const char *MembusCode)
{
 char InitsResponse[2047], *PCode[2], *PErrMsg;
 if (!strcmp(MembusCode, "INIT_HALT"))
 {
  PCode[0] = "OK" " " "INIT_HALT";
  PCode[1] = "FAIL" " " "INIT_HALT";
  PErrMsg = "Unable to halt.";
 }
 else if (!strcmp(MembusCode, "INIT_POWEROFF"))
 {
  PCode[0] = "OK" " " "INIT_POWEROFF";
  PCode[1] = "FAIL" " " "INIT_POWEROFF";
  PErrMsg = "Unable to power off.";
 }
 else if (!strcmp(MembusCode, "INIT_REBOOT"))
 {
  PCode[0] = "OK" " " "INIT_REBOOT";
  PCode[1] = "FAIL" " " "INIT_REBOOT";
  PErrMsg = "Unable to reboot.";
 }
 else if (!strcmp(MembusCode, "CADON"))
 {
  PCode[0] = "OK" " " "CADON";
  PCode[1] = "FAIL" " " "CADON";
  PErrMsg = "Unable to enable CTRL-ALT-DEL instant reboot.";
 }
 else if (!strcmp(MembusCode, "CADOFF"))
 {
  PCode[0] = "OK" " " "CADOFF";
  PCode[1] = "FAIL" " " "CADOFF";
  PErrMsg = "Unable to disable CTRL-ALT-DEL instant reboot.";
 }
 else
 {
  SpitError("Invalid MEMBUS_CODE passed to SendPowerControl().");
  return FAILURE;
 }
 if (!MemBus_Write(MembusCode, false))
 {
  SpitError("Failed to write to membus.");
  return FAILURE;
 }
 while (!MemBus_Read(InitsResponse, false)) usleep(1000);
 MemBus_Write(MembusCode, false);
 if (!strcmp(InitsResponse, PCode[0]))
 {
  ShutdownMemBus(false);
  return SUCCESS;
 }
 else if (!strcmp(InitsResponse, PCode[1]))
 {
  SpitError(PErrMsg);
  ShutdownMemBus(false);
  return FAILURE;
 }
 return SUCCESS;
}

canonical_original_code:
enum ReturnCode SendPowerControl(char *MembusCode)
{
 char InitsResponse[2047]; char *PCode[2]; char *PErrMsg;
 if (!strcmp(MembusCode, "INIT_HALT"))
 {
  PCode[0] = "OK" " " "INIT_HALT";
  PCode[1] = "FAIL" " " "INIT_HALT";
  PErrMsg = "Unable to halt.";
 }
 else if (!strcmp(MembusCode, "INIT_POWEROFF"))
 {
  PCode[0] = "OK" " " "INIT_POWEROFF";
  PCode[1] = "FAIL" " " "INIT_POWEROFF";
  PErrMsg = "Unable to power off.";
 }
 else if (!strcmp(MembusCode, "INIT_REBOOT"))
 {
  PCode[0] = "OK" " " "INIT_REBOOT";
  PCode[1] = "FAIL" " " "INIT_REBOOT";
  PErrMsg = "Unable to reboot.";
 }
 else if (!strcmp(MembusCode, "CADON"))
 {
  PCode[0] = "OK" " " "CADON";
  PCode[1] = "FAIL" " " "CADON";
  PErrMsg = "Unable to enable CTRL-ALT-DEL instant reboot.";
 }
 else if (!strcmp(MembusCode, "CADOFF"))
 {
  PCode[0] = "OK" " " "CADOFF";
  PCode[1] = "FAIL" " " "CADOFF";
  PErrMsg = "Unable to disable CTRL-ALT-DEL instant reboot.";
 }
 else
 {
  SpitError("Invalid MEMBUS_CODE passed to SendPowerControl().");
  return FAILURE;
 }
 if (!MemBus_Write(MembusCode, false))
 {
  SpitError("Failed to write to membus.");
  return FAILURE;
 }
 while (!MemBus_Read(InitsResponse, false)) usleep(1000);
 MemBus_Write(MembusCode, false);
 if (!strcmp(InitsResponse, PCode[0]))
 {
  ShutdownMemBus(false);
  return SUCCESS;
 }
 else if (!strcmp(InitsResponse, PCode[1]))
 {
  SpitError(PErrMsg);
  ShutdownMemBus(false);
  return FAILURE;
 }
 return SUCCESS;
}

variable_types:
MembusCode
char *

variable_types:
InitsResponse
char [2047]

variable_types:
PCode
char *[2]

variable_types:
PErrMsg
char *

return_type: enum ReturnCode { FAILURE=0, SUCCESS=1, WARNING=2 }


ObjControl

decompiled_code:
__int64 __fastcall ObjControl(const char *a1, const char *a2)
{
int v2; // er8
__int64 result; // rax
int v4; // er8
char v5[2047]; // [rsp+0h] [rbp-3028h] BYREF
char s2[2047]; // [rsp+7FFh] [rbp-2829h] BYREF
char v7[2047]; // [rsp+FFEh] [rbp-202Ah] BYREF
char v8[2051]; // [rsp+17FDh] [rbp-182Bh] BYREF
char s1[2048]; // [rsp+2000h] [rbp-1028h] BYREF
char s[2056]; // [rsp+2800h] [rbp-828h] BYREF
unsigned __int64 v11; // [rsp+3008h] [rbp-20h]

v11 = __readfsqword(0x28u);
snprintf(s, 0x7FFuLL, "%s %s", a2, a1);
if ( !(unsigned int)MemBus_Write(s, 0LL) )
goto LABEL_12;
while ( !(unsigned __int8)MemBus_Read(s1, 0LL) )
usleep(0x3E8u);
snprintf(v5, 0x7FFuLL, "%s %s %s", "OK", a2, a1);
snprintf(s2, 0x7FFuLL, "%s %s %s", "FAIL", a2, a1);
snprintf(v7, 0x7FFuLL, "%s %s", "BADPARAM", s);
snprintf(v8, 0x7FFuLL, "%s %s %s", "WARN", a2, a1);
v2 = strcmp(s1, v5);
result = 1LL;
if ( v2 )
{
if ( strcmp(s1, s2) )
{
v4 = strcmp(s1, v8);
result = 2LL;
if ( !v4 )
return result;
if ( !strcmp(s1, v7) )
{
SpitError("\nWe are being told that we sent a bad parameter.", v7);
return 0LL;
}
SpitError("\nReceived invalid reply from membus.", v7);
}
LABEL_12:
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1, const char *a2)
{
int v2; // er8
__int64 result; // rax
int v4; // er8
char v5[2047]; // [rsp+0h] [rbp-3028h] BYREF
char s2[2047]; // [rsp+7FFh] [rbp-2829h] BYREF
char v7[2047]; // [rsp+FFEh] [rbp-202Ah] BYREF
char v8[2051]; // [rsp+17FDh] [rbp-182Bh] BYREF
char s1[2048]; // [rsp+2000h] [rbp-1028h] BYREF
char s[2056]; // [rsp+2800h] [rbp-828h] BYREF
unsigned __int64 v11; // [rsp+3008h] [rbp-20h]

v11 = __readfsqword(0x28u);
snprintf(s, 0x7FFuLL, "%s %s", a2, a1);
if ( !(unsigned int)MemBus_Write(s, 0LL) )
goto LABEL_12;
while ( !(unsigned __int8)MemBus_Read(s1, 0LL) )
usleep(0x3E8u);
snprintf(v5, 0x7FFuLL, "%s %s %s", "OK", a2, a1);
snprintf(s2, 0x7FFuLL, "%s %s %s", "FAIL", a2, a1);
snprintf(v7, 0x7FFuLL, "%s %s", "BADPARAM", s);
snprintf(v8, 0x7FFuLL, "%s %s %s", "WARN", a2, a1);
v2 = strcmp(s1, v5);
result = 1LL;
if ( v2 )
{
if ( strcmp(s1, s2) )
{
v4 = strcmp(s1, v8);
result = 2LL;
if ( !v4 )
return result;
if ( !strcmp(s1, v7) )
{
SpitError("\nWe are being told that we sent a bad parameter.", v7);
return 0LL;
}
SpitError("\nReceived invalid reply from membus.", v7);
}
LABEL_12:
result = 0LL;
}
return result;
}

original_code:
ReturnCode ObjControl(const char *ObjectID, const char *MemBusSignal)
{
 char RemoteResponse[2047];
 char OutMsg[2047];
 char PossibleResponses[4][2047];
 snprintf(OutMsg, sizeof OutMsg, "%s %s", MemBusSignal, ObjectID);
 if (!MemBus_Write(OutMsg, false))
 {
  return FAILURE;
 }
 while (!MemBus_Read(RemoteResponse, false)) usleep(1000);
 snprintf(PossibleResponses[0], sizeof PossibleResponses[0], "%s %s %s",
  "OK", MemBusSignal, ObjectID);
 snprintf(PossibleResponses[1], sizeof PossibleResponses[1], "%s %s %s",
  "FAIL", MemBusSignal, ObjectID);
 snprintf(PossibleResponses[2], sizeof PossibleResponses[2], "%s %s",
  "BADPARAM", OutMsg);
 snprintf(PossibleResponses[3], sizeof PossibleResponses[3], "%s %s %s",
  "WARN", MemBusSignal, ObjectID);
 if (!strcmp(RemoteResponse, PossibleResponses[0]))
 {
  return SUCCESS;
 }
 else if (!strcmp(RemoteResponse, PossibleResponses[1]))
 {
  return FAILURE;
 }
 else if (!strcmp(RemoteResponse, PossibleResponses[3]))
 {
  return WARNING;
 }
 else if (!strcmp(RemoteResponse, PossibleResponses[2]))
 {
  SpitError("\nWe are being told that we sent a bad parameter.");
  return FAILURE;
 }
 else
 {
  SpitError("\nReceived invalid reply from membus.");
  return FAILURE;
 }
}

canonical_original_code:
enum ReturnCode ObjControl(char *ObjectID, char *MemBusSignal)
{
 char RemoteResponse[2047];
 char OutMsg[2047];
 char PossibleResponses[4][2047];
 snprintf(OutMsg, sizeof OutMsg, "%s %s", MemBusSignal, ObjectID);
 if (!MemBus_Write(OutMsg, false))
 {
  return FAILURE;
 }
 while (!MemBus_Read(RemoteResponse, false)) usleep(1000);
 snprintf(PossibleResponses[0], sizeof PossibleResponses[0], "%s %s %s",
  "OK", MemBusSignal, ObjectID);
 snprintf(PossibleResponses[1], sizeof PossibleResponses[1], "%s %s %s",
  "FAIL", MemBusSignal, ObjectID);
 snprintf(PossibleResponses[2], sizeof PossibleResponses[2], "%s %s",
  "BADPARAM", OutMsg);
 snprintf(PossibleResponses[3], sizeof PossibleResponses[3], "%s %s %s",
  "WARN", MemBusSignal, ObjectID);
 if (!strcmp(RemoteResponse, PossibleResponses[0]))
 {
  return SUCCESS;
 }
 else if (!strcmp(RemoteResponse, PossibleResponses[1]))
 {
  return FAILURE;
 }
 else if (!strcmp(RemoteResponse, PossibleResponses[3]))
 {
  return WARNING;
 }
 else if (!strcmp(RemoteResponse, PossibleResponses[2]))
 {
  SpitError("\nWe are being told that we sent a bad parameter.");
  return FAILURE;
 }
 else
 {
  SpitError("\nReceived invalid reply from membus.");
  return FAILURE;
 }
}

variable_types:
ObjectID
char *

variable_types:
MemBusSignal
char *

variable_types:
RemoteResponse
char [2047]

variable_types:
OutMsg
char [2047]

variable_types:
PossibleResponses
char [4][2047]

user_defined_types: enum ReturnCode { FAILURE=0, SUCCESS=1, WARNING=2 }


EmulShutdown

decompiled_code:
__int64 __fastcall EmulShutdown(int a1, __int64 a2)
{
int v2; // edi
const char **v3; // rbx
int v4; // er13
int v5; // er12
const char *v6; // r15
const char *v7; // rbp
int v8; // edx
char *v9; // rax
char v10; // dl
const char *v11; // rdx
unsigned int v12; // er12
unsigned int v14; // eax
int v15; // eax
__int16 v16; // [rsp+Ch] [rbp-289Ch]
char v17; // [rsp+Fh] [rbp-2899h]
unsigned int v18; // [rsp+10h] [rbp-2898h] BYREF
unsigned int v19; // [rsp+14h] [rbp-2894h] BYREF
time_t timer; // [rsp+18h] [rbp-2890h] BYREF
unsigned int v21; // [rsp+24h] [rbp-2884h] BYREF
unsigned int v22; // [rsp+28h] [rbp-2880h] BYREF
unsigned int v23; // [rsp+30h] [rbp-2878h] BYREF
unsigned int v24; // [rsp+34h] [rbp-2874h] BYREF
unsigned int v25; // [rsp+38h] [rbp-2870h] BYREF
struct tm s2[36]; // [rsp+40h] [rbp-2868h] BYREF
char v27[2047]; // [rsp+83Fh] [rbp-2069h] BYREF
char v28[2050]; // [rsp+103Eh] [rbp-186Ah] BYREF
char v29[32]; // [rsp+1840h] [rbp-1068h] BYREF
char s[2048]; // [rsp+1860h] [rbp-1048h] BYREF
char s1[2056]; // [rsp+2060h] [rbp-848h] BYREF
unsigned __int64 v32; // [rsp+2868h] [rbp-40h]

v32 = __readfsqword(0x28u);
v18 = 0;
v19 = 0;
v2 = a1 - 1;
if ( !v2 )
{
LABEL_66:
v11 = "You must specify one of -hrp.";
goto LABEL_45;
}
v17 = 0;
v3 = (const char **)(a2 + 8);
v16 = 0;
v4 = 0;
v5 = 0;
v6 = 0LL;
do
{
v7 = *v3;
v8 = *(unsigned __int8 *)*v3;
if ( v8 == 45 && v7[1] == 104 && !v7[2] || !strcmp(*v3, "--halt") )
{
LABEL_5:
++v4;
v6 = "INIT_HALT";
goto LABEL_6;
}
if ( v8 == 45 )
{
if ( v7[1] == 72 && !v7[2] )
goto LABEL_5;
if ( v7[1] == 82 && !v7[2] )
{
++v4;
v6 = "INIT_REBOOT";
goto LABEL_6;
}
if ( v7[1] == 114 && !v7[2] )
{
LABEL_24:
++v4;
v6 = "INIT_REBOOT";
goto LABEL_6;
}
}
if ( !strcmp(*v3, "--reboot") )
goto LABEL_24;
if ( v8 == 45 )
{
if ( v7[1] == 112 && !v7[2] )
{
LABEL_30:
++v4;
v6 = "INIT_POWEROFF";
goto LABEL_6;
}
if ( v7[1] == 80 && !v7[2] )
{
++v4;
v6 = "INIT_POWEROFF";
goto LABEL_6;
}
}
if ( !strcmp(*v3, "--poweroff") )
goto LABEL_30;
if ( v8 == 45 && v7[1] == 99 && !v7[2] || !strcmp(*v3, "--cancel") )
{
strcpy(s, "INIT_ABORTHALT");
if ( !v17 )
{
LABEL_41:
snprintf((char *)s2, 0x7FFuLL, "%s %s", "OK", s);
snprintf(v27, 0x7FFuLL, "%s %s", "FAIL", s);
snprintf(v28, 0x7FFuLL, "%s %s", "BADPARAM", s);
v12 = InitMemBus(0LL);
if ( v12 )
{
v12 = MemBus_Write(s, 0LL);
if ( v12 )
{
while ( !(unsigned __int8)MemBus_Read(s1, 0LL) )
usleep(0x3E8u);
if ( v17 )
MemBus_Write(" ", 0LL);
if ( !(unsigned int)ShutdownMemBus(0LL) )
SpitError("Failed to shut down membus! This could spell serious issues.", 0LL);
v12 = 1;
if ( strcmp(s1, (const char *)s2) )
{
if ( !strcmp(s1, v27) )
{
if ( *(_QWORD *)s != 0x4F42415F54494E49LL
|| *(_DWORD *)&s[8] != 1095259218
|| *(_WORD *)&s[12] != 21580
|| (v15 = 0, s[14]) )
{
v15 = 1;
}
v12 = 0;
if ( v15 )
fprintf(
stderr,
"%s\n",
"Failed to schedule shutdown.\nIs another already scheduled? Use shutdown -c to cancel it.");
else
fprintf(stderr, "%s\n", "Failed to abort shutdown. Is a shutdown scheduled?");
}
else
{
v12 = 0;
if ( !strcmp(s1, v28) )
SpitError(
"We are being told that we sent a bad parameter over the membus!Please report this to Epoch, as it's likely a bug.",
v28);
else
SpitError(
"Invalid response received from membus! Please report this to Epoch, as it's likely a bug.",
v28);
}
}
}
else
{
SpitError("Failed to write to membus.", 0LL);
ShutdownMemBus(0LL);
}
}
else
{
SpitError("Failed to connect to membus.", 2047LL);
}
return v12;
}
LABEL_40:
snprintf(s, 0x7FFuLL, "%s", v6);
v17 = 1;
goto LABEL_41;
}
v9 = strchr(*v3, 58);
v10 = *v7;
if ( !v9 )
{
if ( v10 != 43 )
goto LABEL_18;
if ( !(unsigned __int8)AllNumeric(v7 + 1) )
{
v7 = *v3;
goto LABEL_18;
}
v14 = atoi(*v3 + 1);
MinsToDate(v14, &v21, &v22, &v23, &v24, &v25);
time(&timer);
localtime_r(&timer, s2);
snprintf(v29, 0x20uLL, "%u:%u:%d %u/%u/%u", v21, v22, (unsigned int)s2[0].tm_sec, v23, v24, v25);
LABEL_49:
++v16;
goto LABEL_6;
}
if ( v10 != 45 )
{
if ( (unsigned int)_isoc99_sscanf(v7, "%u:%u", &v18, &v19) != 2 )
{
v12 = 0;
puts("Bad time format. Please enter in the format of \"hh:mm\"");
return v12;
}
DateDiff(v18, v19, &s2[0].tm_mon, &s2[0].tm_year, &s2[0].tm_wday);
snprintf(
v29,
0x20uLL,
"%u:%u:%d %u/%u/%u",
v18,
v19,
0LL,
(unsigned int)s2[0].tm_mon,
(unsigned int)s2[0].tm_year,
(unsigned int)s2[0].tm_wday);
goto LABEL_49;
}
LABEL_18:
if ( strcmp(v7, "now") )
{
if ( !strcmp(v7, "--help") )
{
v12 = 1;
puts(
"Usage: shutdown -hrpc [12:00/+10/now] -c\n"
"\n"
"-h -H --halt: Halt the system, don't power down.\n"
"-p -P --poweroff: Power down the system.\n"
"-r -R --reboot: Reboot the system.\n"
"-c --cancel: Cancel a pending shutdown.\n"
"\n"
"Specify time in hh:mm, +m, or \"now\".\n");
}
else
{
v12 = 0;
fprintf(stderr, "Invalid argument %s. See --help for usage.\n", v7);
}
return v12;
}
++v16;
v17 = 1;
LABEL_6:
++v5;
++v3;
}
while ( (__int16)v5 != v2 );
if ( !(_WORD)v4 )
goto LABEL_66;
if ( (__int16)v4 > 1 )
{
v11 = "Please specify only ONE of -hrp.";
goto LABEL_45;
}
v11 = "You must specify a time in the format of hh:mm: or +m.";
if ( v16 )
{
v11 = "Multiple time arguments specified. Please specify only one.";
if ( v16 <= 1 )
{
if ( !v17 )
{
snprintf(s, 0x7FFuLL, "%s %s", v6, v29);
goto LABEL_41;
}
goto LABEL_40;
}
}
LABEL_45:
v12 = 0;
fprintf(stderr, "%s\n", v11);
return v12;
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1, __int64 a2)
{
int v2; // edi
const char **v3; // rbx
int v4; // er13
int v5; // er12
const char *v6; // r15
const char *v7; // rbp
int v8; // edx
char *v9; // rax
char v10; // dl
const char *v11; // rdx
unsigned int v12; // er12
unsigned int v14; // eax
int v15; // eax
__int16 v16; // [rsp+Ch] [rbp-289Ch]
char v17; // [rsp+Fh] [rbp-2899h]
unsigned int v18; // [rsp+10h] [rbp-2898h] BYREF
unsigned int v19; // [rsp+14h] [rbp-2894h] BYREF
time_t timer; // [rsp+18h] [rbp-2890h] BYREF
unsigned int v21; // [rsp+24h] [rbp-2884h] BYREF
unsigned int v22; // [rsp+28h] [rbp-2880h] BYREF
unsigned int v23; // [rsp+30h] [rbp-2878h] BYREF
unsigned int v24; // [rsp+34h] [rbp-2874h] BYREF
unsigned int v25; // [rsp+38h] [rbp-2870h] BYREF
struct tm s2[36]; // [rsp+40h] [rbp-2868h] BYREF
char v27[2047]; // [rsp+83Fh] [rbp-2069h] BYREF
char v28[2050]; // [rsp+103Eh] [rbp-186Ah] BYREF
char v29[32]; // [rsp+1840h] [rbp-1068h] BYREF
char s[2048]; // [rsp+1860h] [rbp-1048h] BYREF
char s1[2056]; // [rsp+2060h] [rbp-848h] BYREF
unsigned __int64 v32; // [rsp+2868h] [rbp-40h]

v32 = __readfsqword(0x28u);
v18 = 0;
v19 = 0;
v2 = a1 - 1;
if ( !v2 )
{
LABEL_66:
v11 = "You must specify one of -hrp.";
goto LABEL_45;
}
v17 = 0;
v3 = (const char **)(a2 + 8);
v16 = 0;
v4 = 0;
v5 = 0;
v6 = 0LL;
do
{
v7 = *v3;
v8 = *(unsigned __int8 *)*v3;
if ( v8 == 45 && v7[1] == 104 && !v7[2] || !strcmp(*v3, "--halt") )
{
LABEL_5:
++v4;
v6 = "INIT_HALT";
goto LABEL_6;
}
if ( v8 == 45 )
{
if ( v7[1] == 72 && !v7[2] )
goto LABEL_5;
if ( v7[1] == 82 && !v7[2] )
{
++v4;
v6 = "INIT_REBOOT";
goto LABEL_6;
}
if ( v7[1] == 114 && !v7[2] )
{
LABEL_24:
++v4;
v6 = "INIT_REBOOT";
goto LABEL_6;
}
}
if ( !strcmp(*v3, "--reboot") )
goto LABEL_24;
if ( v8 == 45 )
{
if ( v7[1] == 112 && !v7[2] )
{
LABEL_30:
++v4;
v6 = "INIT_POWEROFF";
goto LABEL_6;
}
if ( v7[1] == 80 && !v7[2] )
{
++v4;
v6 = "INIT_POWEROFF";
goto LABEL_6;
}
}
if ( !strcmp(*v3, "--poweroff") )
goto LABEL_30;
if ( v8 == 45 && v7[1] == 99 && !v7[2] || !strcmp(*v3, "--cancel") )
{
strcpy(s, "INIT_ABORTHALT");
if ( !v17 )
{
LABEL_41:
snprintf((char *)s2, 0x7FFuLL, "%s %s", "OK", s);
snprintf(v27, 0x7FFuLL, "%s %s", "FAIL", s);
snprintf(v28, 0x7FFuLL, "%s %s", "BADPARAM", s);
v12 = InitMemBus(0LL);
if ( v12 )
{
v12 = MemBus_Write(s, 0LL);
if ( v12 )
{
while ( !(unsigned __int8)MemBus_Read(s1, 0LL) )
usleep(0x3E8u);
if ( v17 )
MemBus_Write(" ", 0LL);
if ( !(unsigned int)ShutdownMemBus(0LL) )
SpitError("Failed to shut down membus! This could spell serious issues.", 0LL);
v12 = 1;
if ( strcmp(s1, (const char *)s2) )
{
if ( !strcmp(s1, v27) )
{
if ( *(_QWORD *)s != 0x4F42415F54494E49LL
|| *(_DWORD *)&s[8] != 1095259218
|| *(_WORD *)&s[12] != 21580
|| (v15 = 0, s[14]) )
{
v15 = 1;
}
v12 = 0;
if ( v15 )
fprintf(
stderr,
"%s\n",
"Failed to schedule shutdown.\nIs another already scheduled? Use shutdown -c to cancel it.");
else
fprintf(stderr, "%s\n", "Failed to abort shutdown. Is a shutdown scheduled?");
}
else
{
v12 = 0;
if ( !strcmp(s1, v28) )
SpitError(
"We are being told that we sent a bad parameter over the membus!Please report this to Epoch, as it's likely a bug.",
v28);
else
SpitError(
"Invalid response received from membus! Please report this to Epoch, as it's likely a bug.",
v28);
}
}
}
else
{
SpitError("Failed to write to membus.", 0LL);
ShutdownMemBus(0LL);
}
}
else
{
SpitError("Failed to connect to membus.", 2047LL);
}
return v12;
}
LABEL_40:
snprintf(s, 0x7FFuLL, "%s", v6);
v17 = 1;
goto LABEL_41;
}
v9 = strchr(*v3, 58);
v10 = *v7;
if ( !v9 )
{
if ( v10 != 43 )
goto LABEL_18;
if ( !(unsigned __int8)AllNumeric(v7 + 1) )
{
v7 = *v3;
goto LABEL_18;
}
v14 = atoi(*v3 + 1);
MinsToDate(v14, &v21, &v22, &v23, &v24, &v25);
time(&timer);
localtime_r(&timer, s2);
snprintf(v29, 0x20uLL, "%u:%u:%d %u/%u/%u", v21, v22, (unsigned int)s2[0].tm_sec, v23, v24, v25);
LABEL_49:
++v16;
goto LABEL_6;
}
if ( v10 != 45 )
{
if ( (unsigned int)_isoc99_sscanf(v7, "%u:%u", &v18, &v19) != 2 )
{
v12 = 0;
puts("Bad time format. Please enter in the format of \"hh:mm\"");
return v12;
}
DateDiff(v18, v19, &s2[0].tm_mon, &s2[0].tm_year, &s2[0].tm_wday);
snprintf(
v29,
0x20uLL,
"%u:%u:%d %u/%u/%u",
v18,
v19,
0LL,
(unsigned int)s2[0].tm_mon,
(unsigned int)s2[0].tm_year,
(unsigned int)s2[0].tm_wday);
goto LABEL_49;
}
LABEL_18:
if ( strcmp(v7, "now") )
{
if ( !strcmp(v7, "--help") )
{
v12 = 1;
puts(
"Usage: shutdown -hrpc [12:00/+10/now] -c\n"
"\n"
"-h -H --halt: Halt the system, don't power down.\n"
"-p -P --poweroff: Power down the system.\n"
"-r -R --reboot: Reboot the system.\n"
"-c --cancel: Cancel a pending shutdown.\n"
"\n"
"Specify time in hh:mm, +m, or \"now\".\n");
}
else
{
v12 = 0;
fprintf(stderr, "Invalid argument %s. See --help for usage.\n", v7);
}
return v12;
}
++v16;
v17 = 1;
LABEL_6:
++v5;
++v3;
}
while ( (__int16)v5 != v2 );
if ( !(_WORD)v4 )
goto LABEL_66;
if ( (__int16)v4 > 1 )
{
v11 = "Please specify only ONE of -hrp.";
goto LABEL_45;
}
v11 = "You must specify a time in the format of hh:mm: or +m.";
if ( v16 )
{
v11 = "Multiple time arguments specified. Please specify only one.";
if ( v16 <= 1 )
{
if ( !v17 )
{
snprintf(s, 0x7FFuLL, "%s %s", v6, v29);
goto LABEL_41;
}
goto LABEL_40;
}
}
LABEL_45:
v12 = 0;
fprintf(stderr, "%s\n", v11);
return v12;
}

original_code:
ReturnCode EmulShutdown(int ArgumentCount, const char **ArgStream)
{
 const char **TPtr = ArgStream + 1;
 unsigned TargetHr = 0, TargetMin = 0;
 const char *THalt = ((void *)0);
 char PossibleResponses[3][2047];
 char TmpBuf[2047], InRecv[2047], TimeFormat[32];
 short Inc = 0;
 short TimeIsSet = 0, HaltModeSet = 0;
 Bool AbortingShutdown = false, ImmediateHalt = false;
 for (; Inc != (ArgumentCount - 1); ++TPtr, ++Inc)
 {
  if (!strcmp(*TPtr, "-h") || !strcmp(*TPtr, "--halt") || !strcmp(*TPtr, "-H"))
  {
   THalt = "INIT_HALT";
   ++HaltModeSet;
   continue;
  }
  else if (!strcmp(*TPtr, "-R") || !strcmp(*TPtr, "-r") || !strcmp(*TPtr, "--reboot"))
  {
   THalt = "INIT_REBOOT";
   ++HaltModeSet;
   continue;
  }
  else if (!strcmp(*TPtr, "-p") || !strcmp(*TPtr, "-P") || !strcmp(*TPtr, "--poweroff"))
  {
   THalt = "INIT_POWEROFF";
   ++HaltModeSet;
   continue;
  }
  else if (!strcmp(*TPtr, "-c") || !strcmp(*TPtr, "--cancel"))
  {
   AbortingShutdown = true;
   snprintf(TmpBuf, sizeof TmpBuf, "%s", "INIT_ABORTHALT");
   break;
  }
  else if (strchr(*TPtr, ':') && **TPtr != '-')
  {
   struct _HaltParams TempParams;
   if (sscanf(*TPtr, "%u:%u", &TargetHr, &TargetMin) != 2)
   {
    puts("Bad time format. Please enter in the format of \"hh:mm\"");
    return FAILURE;
   }
   DateDiff(TargetHr, TargetMin, &TempParams.TargetMonth, &TempParams.TargetDay, &TempParams.TargetYear);
   snprintf(TimeFormat, sizeof TimeFormat, "%u:%u:%d %u/%u/%u",
     TargetHr, TargetMin, 0, TempParams.TargetMonth, TempParams.TargetDay, TempParams.TargetYear);
   ++TimeIsSet;
  }
  else if (**TPtr == '+' && AllNumeric(*TPtr + 1))
  {
   struct _HaltParams TempParams;
   const char *TArg = *TPtr + 1;
   time_t TTime;
   struct tm TimeStruct;
   MinsToDate(atoi(TArg), &TempParams.TargetHour, &TempParams.TargetMin, &TempParams.TargetMonth,
      &TempParams.TargetDay, &TempParams.TargetYear);
   time(&TTime);
   localtime_r(&TTime, &TimeStruct);
   snprintf(TimeFormat, sizeof TimeFormat, "%u:%u:%d %u/%u/%u",
     TempParams.TargetHour, TempParams.TargetMin, (int)TimeStruct.tm_sec, TempParams.TargetMonth,
     TempParams.TargetDay, TempParams.TargetYear);
   ++TimeIsSet;
  }
  else if (!strcmp(*TPtr, "now"))
  {
   ImmediateHalt = true;
   ++TimeIsSet;
  }
  else if (!strcmp(*TPtr, "--help"))
  {
   const char *HelpMsg =
   "Usage: shutdown -hrpc [12:00/+10/now] -c\n\n"
   "-h -H --halt: Halt the system, don't power down.\n"
   "-p -P --poweroff: Power down the system.\n"
   "-r -R --reboot: Reboot the system.\n"
   "-c --cancel: Cancel a pending shutdown.\n\n"
   "Specify time in hh:mm, +m, or \"now\".\n";
   puts(HelpMsg);
   return SUCCESS;
  }
  else
  {
   fprintf(stderr, "Invalid argument %s. See --help for usage.\n", *TPtr);
   return FAILURE;
  }
 }
 if (!AbortingShutdown)
 {
  if (HaltModeSet == 0)
  {
   fprintf(stderr, "%s\n", "You must specify one of -hrp.");
   return FAILURE;
  }
  if (HaltModeSet > 1)
  {
   fprintf(stderr, "%s\n", "Please specify only ONE of -hrp.");
   return FAILURE;
  }
  if (!TimeIsSet)
  {
   fprintf(stderr, "%s\n", "You must specify a time in the format of hh:mm: or +m.");
   return FAILURE;
  }
  if (TimeIsSet > 1)
  {
   fprintf(stderr, "%s\n", "Multiple time arguments specified. Please specify only one.");
   return FAILURE;
  }
  if (!ImmediateHalt)
  {
   snprintf(TmpBuf, sizeof TmpBuf, "%s %s", THalt, TimeFormat);
  }
 }
 if (ImmediateHalt)
 {
  snprintf(TmpBuf, sizeof TmpBuf, "%s", THalt);
 }
 snprintf(PossibleResponses[0], 2047, "%s %s", "OK", TmpBuf);
 snprintf(PossibleResponses[1], 2047, "%s %s", "FAIL", TmpBuf);
 snprintf(PossibleResponses[2], 2047, "%s %s", "BADPARAM", TmpBuf);
 if (!InitMemBus(false))
 {
  SpitError("Failed to connect to membus.");
  return FAILURE;
 }
 if (!MemBus_Write(TmpBuf, false))
 {
  SpitError("Failed to write to membus.");
  ShutdownMemBus(false);
  return FAILURE;
 }
 while (!MemBus_Read(InRecv, false)) usleep(1000);
 if (ImmediateHalt) MemBus_Write(" ", false);
 if (!ShutdownMemBus(false))
 {
  SpitError("Failed to shut down membus! This could spell serious issues.");
 }
 if (!strcmp(InRecv, PossibleResponses[0]))
 {
  return SUCCESS;
 }
 else if (!strcmp(InRecv, PossibleResponses[1]))
 {
  if (!strcmp(TmpBuf, "INIT_ABORTHALT"))
  {
   fprintf(stderr, "%s\n", "Failed to abort shutdown. Is a shutdown scheduled?");
  }
  else
  {
   fprintf(stderr, "%s\n", "Failed to schedule shutdown.\nIs another already scheduled? Use shutdown -c to cancel it.");
  }
  return FAILURE;
 }
 else if (!strcmp(InRecv, PossibleResponses[2]))
 {
  SpitError("We are being told that we sent a bad parameter over the membus!"
     "Please report this to Epoch, as it's likely a bug.");
  return FAILURE;
 }
 else
 {
  SpitError("Invalid response received from membus! Please report this to Epoch, as it's likely a bug.");
  return FAILURE;
 }
}

canonical_original_code:
enum ReturnCode EmulShutdown(int ArgumentCount, char **ArgStream)
{
 char **TPtr = ArgStream + 1;
 unsigned int TargetHr = 0; unsigned int TargetMin = 0;
 char *THalt = ((void *)0);
 char PossibleResponses[3][2047];
 char TmpBuf[2047]; char InRecv[2047]; char TimeFormat[32];
 short Inc = 0;
 short TimeIsSet = 0; short HaltModeSet = 0;
 char AbortingShutdown = false; char ImmediateHalt = false;
 for (; Inc != (ArgumentCount - 1); ++TPtr, ++Inc)
 {
  if (!strcmp(*TPtr, "-h") || !strcmp(*TPtr, "--halt") || !strcmp(*TPtr, "-H"))
  {
   THalt = "INIT_HALT";
   ++HaltModeSet;
   continue;
  }
  else if (!strcmp(*TPtr, "-R") || !strcmp(*TPtr, "-r") || !strcmp(*TPtr, "--reboot"))
  {
   THalt = "INIT_REBOOT";
   ++HaltModeSet;
   continue;
  }
  else if (!strcmp(*TPtr, "-p") || !strcmp(*TPtr, "-P") || !strcmp(*TPtr, "--poweroff"))
  {
   THalt = "INIT_POWEROFF";
   ++HaltModeSet;
   continue;
  }
  else if (!strcmp(*TPtr, "-c") || !strcmp(*TPtr, "--cancel"))
  {
   AbortingShutdown = true;
   snprintf(TmpBuf, sizeof TmpBuf, "%s", "INIT_ABORTHALT");
   break;
  }
  else if (strchr(*TPtr, ':') && **TPtr != '-')
  {
   struct _HaltParams TempParams;
   if (sscanf(*TPtr, "%u:%u", &TargetHr, &TargetMin) != 2)
   {
    puts("Bad time format. Please enter in the format of \"hh:mm\"");
    return FAILURE;
   }
   DateDiff(TargetHr, TargetMin, &TempParams.TargetMonth, &TempParams.TargetDay, &TempParams.TargetYear);
   snprintf(TimeFormat, sizeof TimeFormat, "%u:%u:%d %u/%u/%u",
     TargetHr, TargetMin, 0, TempParams.TargetMonth, TempParams.TargetDay, TempParams.TargetYear);
   ++TimeIsSet;
  }
  else if (**TPtr == '+' && AllNumeric(*TPtr + 1))
  {
   struct _HaltParams TempParams;
   char *TArg = *TPtr + 1;
   long TTime;
   struct tm TimeStruct;
   MinsToDate(atoi(TArg), &TempParams.TargetHour, &TempParams.TargetMin, &TempParams.TargetMonth,
      &TempParams.TargetDay, &TempParams.TargetYear);
   time(&TTime);
   localtime_r(&TTime, &TimeStruct);
   snprintf(TimeFormat, sizeof TimeFormat, "%u:%u:%d %u/%u/%u",
     TempParams.TargetHour, TempParams.TargetMin, (int)TimeStruct.tm_sec, TempParams.TargetMonth,
     TempParams.TargetDay, TempParams.TargetYear);
   ++TimeIsSet;
  }
  else if (!strcmp(*TPtr, "now"))
  {
   ImmediateHalt = true;
   ++TimeIsSet;
  }
  else if (!strcmp(*TPtr, "--help"))
  {
   char *HelpMsg = "Usage: shutdown -hrpc [12:00/+10/now] -c\n\n"
   "-h -H --halt: Halt the system, don't power down.\n"
   "-p -P --poweroff: Power down the system.\n"
   "-r -R --reboot: Reboot the system.\n"
   "-c --cancel: Cancel a pending shutdown.\n\n"
   "Specify time in hh:mm, +m, or \"now\".\n";
   puts(HelpMsg);
   return SUCCESS;
  }
  else
  {
   fprintf(stderr, "Invalid argument %s. See --help for usage.\n", *TPtr);
   return FAILURE;
  }
 }
 if (!AbortingShutdown)
 {
  if (HaltModeSet == 0)
  {
   fprintf(stderr, "%s\n", "You must specify one of -hrp.");
   return FAILURE;
  }
  if (HaltModeSet > 1)
  {
   fprintf(stderr, "%s\n", "Please specify only ONE of -hrp.");
   return FAILURE;
  }
  if (!TimeIsSet)
  {
   fprintf(stderr, "%s\n", "You must specify a time in the format of hh:mm: or +m.");
   return FAILURE;
  }
  if (TimeIsSet > 1)
  {
   fprintf(stderr, "%s\n", "Multiple time arguments specified. Please specify only one.");
   return FAILURE;
  }
  if (!ImmediateHalt)
  {
   snprintf(TmpBuf, sizeof TmpBuf, "%s %s", THalt, TimeFormat);
  }
 }
 if (ImmediateHalt)
 {
  snprintf(TmpBuf, sizeof TmpBuf, "%s", THalt);
 }
 snprintf(PossibleResponses[0], 2047, "%s %s", "OK", TmpBuf);
 snprintf(PossibleResponses[1], 2047, "%s %s", "FAIL", TmpBuf);
 snprintf(PossibleResponses[2], 2047, "%s %s", "BADPARAM", TmpBuf);
 if (!InitMemBus(false))
 {
  SpitError("Failed to connect to membus.");
  return FAILURE;
 }
 if (!MemBus_Write(TmpBuf, false))
 {
  SpitError("Failed to write to membus.");
  ShutdownMemBus(false);
  return FAILURE;
 }
 while (!MemBus_Read(InRecv, false)) usleep(1000);
 if (ImmediateHalt) MemBus_Write(" ", false);
 if (!ShutdownMemBus(false))
 {
  SpitError("Failed to shut down membus! This could spell serious issues.");
 }
 if (!strcmp(InRecv, PossibleResponses[0]))
 {
  return SUCCESS;
 }
 else if (!strcmp(InRecv, PossibleResponses[1]))
 {
  if (!strcmp(TmpBuf, "INIT_ABORTHALT"))
  {
   fprintf(stderr, "%s\n", "Failed to abort shutdown. Is a shutdown scheduled?");
  }
  else
  {
   fprintf(stderr, "%s\n", "Failed to schedule shutdown.\nIs another already scheduled? Use shutdown -c to cancel it.");
  }
  return FAILURE;
 }
 else if (!strcmp(InRecv, PossibleResponses[2]))
 {
  SpitError("We are being told that we sent a bad parameter over the membus!"
     "Please report this to Epoch, as it's likely a bug.");
  return FAILURE;
 }
 else
 {
  SpitError("Invalid response received from membus! Please report this to Epoch, as it's likely a bug.");
  return FAILURE;
 }
}

variable_types: ArgumentCount int

variable_types:
ArgStream
char **

variable_types:
TPtr
char **

variable_types:
TargetHr
unsigned int

variable_types:
TargetMin
unsigned int

variable_types:
THalt
char *

variable_types:
PossibleResponses
char [3][2047]

variable_types:
TmpBuf
char [2047]

variable_types:
InRecv
char [2047]

variable_types:
TimeFormat
char [32]

variable_types: Inc short

variable_types: TimeIsSet short

variable_types: HaltModeSet short

variable_types: AbortingShutdown char

variable_types: ImmediateHalt char

variable_types: struct _HaltParams { int HaltMode; unsigned int TargetHour; unsigned int TargetMin; unsigned int TargetSec; unsigned int TargetMonth; unsigned int TargetDay; unsigned int TargetYear; unsigned int JobID; }

variable_types:
TArg
char *

variable_types: TTime long

variable_types:
HelpMsg
char *


decompiled_code:
__int64 __fastcall lex_comment(__int64 a1, __int64 a2, int a3)
{
_QWORD *v3; // rbx
_BYTE *v4; // rbp
__int64 v5; // rax
__int64 v6; // rsi

v3 = (_QWORD *)(a2 + 8LL * a3);
if ( !*v3 )
{
v4 = &unk_1E3;
goto LABEL_8;
}
v4 = &unk_1E3;
do
{
v5 = ft_strjoin(v4);
v4 = (_BYTE *)v5;
if ( v3[1] )
v4 = (_BYTE *)ft_strjoin(v5);
v6 = v3[1];
++v3;
}
while ( v6 );
if ( v4 )
{
if ( *v4 != 34 )
{
LABEL_8:
free(v4);
return 0LL;
}
if ( v4[ft_strlen(v4) - 1] == 34 )
{
lex_addlex(a1, v4, 1024LL);
goto LABEL_8;
}
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, int a3)
{
_QWORD *v3; // rbx
_BYTE *v4; // rbp
__int64 v5; // rax
__int64 v6; // rsi

v3 = (_QWORD *)(a2 + 8LL * a3);
if ( !*v3 )
{
v4 = &unk_1E3;
goto LABEL_8;
}
v4 = &unk_1E3;
do
{
v5 = ft_strjoin(v4);
v4 = (_BYTE *)v5;
if ( v3[1] )
v4 = (_BYTE *)ft_strjoin(v5);
v6 = v3[1];
++v3;
}
while ( v6 );
if ( v4 )
{
if ( *v4 != 34 )
{
LABEL_8:
free(v4);
return 0LL;
}
if ( v4[ft_strlen(v4) - 1] == 34 )
{
lex_addlex(a1, v4, 1024LL);
goto LABEL_8;
}
}
return 0xFFFFFFFFLL;
}

original_code:
static int lex_comment(t_lexer **list, char **tab, int j)
{
 char *str;
 str = "";
 while (tab[j])
 {
  str = ft_strjoin(str, tab[j]);
  if (tab[j + 1])
   str = ft_strjoin(str, " ");
  j++;
 }
 if (!str)
  return (-1);
 if (str[0] == '"')
 {
  if (str[ft_strlen(str) - 1] == '"')
   lex_addlex(list, str, STR);
  else
   return (-1);
 }
 free(str);
 return (0);
}

canonical_original_code:
static int lex_comment(struct s_lexer **list, char **tab, int j)
{
 char *str;
 str = "";
 while (tab[j])
 {
  str = ft_strjoin(str, tab[j]);
  if (tab[j + 1])
   str = ft_strjoin(str, " ");
  j++;
 }
 if (!str)
  return (-1);
 if (str[0] == '"')
 {
  if (str[ft_strlen(str) - 1] == '"')
   lex_addlex(list, str, STR);
  else
   return (-1);
 }
 free(str);
 return (0);
}

variable_types: struct s_lexer { enum e_type { NOTHING=0, REG=1, IND=2, DIR=4, LAB=8, OP=16, CMD=32, CMD_NAME=64, CMD_COM=128, DIR_LAB=256, IND_LAB=512, STR=1024, ENDOFLINE=2048, COM=4096, WHIT=8192, SEP=16384 } token; char *value; struct s_lexer *next; } **

variable_types:
tab
char **

variable_types: j int

variable_types:
str
char *

return_type: int

user_defined_types: struct s_lexer { enum e_type token; char *value; struct s_lexer *next; }


decompiled_code:
__int64 __fastcall lex_line(__int64 a1, __int64 a2, unsigned int a3)
{
_BYTE **v4; // rax
_BYTE *v5; // rsi
__int64 v6; // rbp
__int64 v7; // rbx

v4 = (_BYTE **)ft_strsplitwhite(a2);
v5 = *v4;
if ( !*v4 )
return 0LL;
v6 = (__int64)v4;
v7 = 0LL;
while ( 1 )
{
if ( (unsigned __int8)(*v5 - 34) <= 1u || *v5 == 59 )
return lex_comment(a1, v6, v7);
if ( (unsigned int)lex_tablex(a1) == -1 )
break;
++v7;
v5 = *(_BYTE **)(v6 + 8 * v7);
if ( !v5 )
return 0LL;
}
return lex_error(v6, a3, (unsigned int)v7);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, unsigned int a3)
{
_BYTE **v4; // rax
_BYTE *v5; // rsi
__int64 v6; // rbp
__int64 v7; // rbx

v4 = (_BYTE **)ft_strsplitwhite(a2);
v5 = *v4;
if ( !*v4 )
return 0LL;
v6 = (__int64)v4;
v7 = 0LL;
while ( 1 )
{
if ( (unsigned __int8)(*v5 - 34) <= 1u || *v5 == 59 )
return func0(a1, v6, v7);
if ( (unsigned int)lex_tablex(a1) == -1 )
break;
++v7;
v5 = *(_BYTE **)(v6 + 8 * v7);
if ( !v5 )
return 0LL;
}
return lex_error(v6, a3, (unsigned int)v7);
}

original_code:
static int lex_line(t_lexer **list, char *str, int line)
{
 char **tab;
 int j;
 j = 0;
 tab = ft_strsplitwhite(str);
 while (tab[j])
 {
  if (*(tab[j]) == ';' || *(tab[j]) == '#' || *(tab[j]) == '"')
   return (lex_comment(list, tab, j));
  else
  {
   if (lex_tablex(list, tab[j]) == -1)
    return (lex_error(tab, line, j));
  }
  j++;
 }
 return (0);
}

canonical_original_code:
static int lex_line(struct s_lexer **list, char *str, int line)
{
 char **tab;
 int j;
 j = 0;
 tab = ft_strsplitwhite(str);
 while (tab[j])
 {
  if (*(tab[j]) == ';' || *(tab[j]) == '#' || *(tab[j]) == '"')
   return (lex_comment(list, tab, j));
  else
  {
   if (lex_tablex(list, tab[j]) == -1)
    return (lex_error(tab, line, j));
  }
  j++;
 }
 return (0);
}

variable_types: line int

user_defined_types: enum e_type { NOTHING=0, REG=1, IND=2, DIR=4, LAB=8, OP=16, CMD=32, CMD_NAME=64, CMD_COM=128, DIR_LAB=256, IND_LAB=512, STR=1024, ENDOFLINE=2048, COM=4096, WHIT=8192, SEP=16384 }


decompiled_code:
__int64 __fastcall lex_lexer(unsigned int a1)
{
unsigned int v1; // ebx
int v2; // eax
__int64 v3; // rdx
__int64 v4; // rcx
__int64 v5; // r8
__int64 v7; // [rsp+0h] [rbp-28h] BYREF
__int64 v8[4]; // [rsp+8h] [rbp-20h] BYREF

v1 = 1;
v7 = 0LL;
v8[0] = 0LL;
while ( 1 )
{
v2 = get_next_line(a1, &v7);
if ( v2 <= 0 )
break;
if ( (unsigned int)lex_line((__int64)v8, v7, v1) == -1 )
return 0LL;
++v1;
lex_addlex(v8, &unk_1E3, 2048LL);
}
v5 = v8[0];
if ( v2 == -1 )
{
ft_putendl_fd("An error occured while reading file", 2LL, v3, v4, v8[0]);
v5 = 0LL;
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1)
{
unsigned int v1; // ebx
int v2; // eax
__int64 v3; // rdx
__int64 v4; // rcx
__int64 v5; // r8
__int64 v7; // [rsp+0h] [rbp-28h] BYREF
__int64 v8[4]; // [rsp+8h] [rbp-20h] BYREF

v1 = 1;
v7 = 0LL;
v8[0] = 0LL;
while ( 1 )
{
v2 = get_next_line(a1, &v7);
if ( v2 <= 0 )
break;
if ( (unsigned int)func1((__int64)v8, v7, v1) == -1 )
return 0LL;
++v1;
lex_addlex(v8, &unk_1E3, 2048LL);
}
v5 = v8[0];
if ( v2 == -1 )
{
ft_putendl_fd("An error occured while reading file", 2LL, v3, v4, v8[0]);
v5 = 0LL;
}
return v5;
}

original_code:
t_lexer *lex_lexer(int fd)
{
 char *str;
 t_lexer *list;
 int ret;
 int line;
 str = ((void *)0);
 list = ((void *)0);
 line = 1;
 while ((ret = get_next_line(fd, &str)) > 0)
 {
  if (lex_line(&list, str, line) == -1)
   return (((void *)0));
  if (ret != 0)
   lex_addlex(&list, "", ENDOFLINE);
  line++;
 }
 if (ret == -1)
 {
  ft_putendl_fd("An error occured while reading file", 2);
  return (((void *)0));
 }
 return (list);
}

canonical_original_code:
struct s_lexer *lex_lexer(int fd)
{
 char *str;
 struct s_lexer *list;
 int ret;
 int line;
 str = ((void *)0);
 list = ((void *)0);
 line = 1;
 while ((ret = get_next_line(fd, &str)) > 0)
 {
  if (lex_line(&list, str, line) == -1)
   return (((void *)0));
  if (ret != 0)
   lex_addlex(&list, "", ENDOFLINE);
  line++;
 }
 if (ret == -1)
 {
  ft_putendl_fd("An error occured while reading file", 2);
  return (((void *)0));
 }
 return (list);
}

variable_types: fd int

variable_types: struct s_lexer { enum e_type { NOTHING=0, REG=1, IND=2, DIR=4, LAB=8, OP=16, CMD=32, CMD_NAME=64, CMD_COM=128, DIR_LAB=256, IND_LAB=512, STR=1024, ENDOFLINE=2048, COM=4096, WHIT=8192, SEP=16384 } token; char *value; struct s_lexer *next; } *

variable_types: ret int


decompiled_code:
__int64 __fastcall ft_strjoinc(__int64 a1, char a2)
{
__int64 v2; // rbx
__int64 result; // rax

v2 = ft_strlen();
result = ft_strnew(v2 + 2);
if ( result )
{
result = ft_memcpy(result, a1, v2);
*(_BYTE *)(result + v2) = a2;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, char a2)
{
__int64 v2; // rbx
__int64 result; // rax

v2 = ft_strlen();
result = ft_strnew(v2 + 2);
if ( result )
{
result = ft_memcpy(result, a1, v2);
*(_BYTE *)(result + v2) = a2;
}
return result;
}

original_code:
char *ft_strjoinc(char const *s1, char const c)
{
 char *join;
 size_t len_s1;
 len_s1 = ft_strlen(s1);
 join = ft_strnew(len_s1 + 2);
 if (join == ((void *)0))
  return (((void *)0));
 join = (char *) ft_memcpy(join, s1, len_s1);
 join[len_s1] = c;
 return (join);
}

canonical_original_code:
char *ft_strjoinc(char *s1, char c)
{
 char *join;
 unsigned long len_s1;
 len_s1 = ft_strlen(s1);
 join = ft_strnew(len_s1 + 2);
 if (join == ((void *)0))
  return (((void *)0));
 join = (char *) ft_memcpy(join, s1, len_s1);
 join[len_s1] = c;
 return (join);
}

variable_types: c char

variable_types:
join
char *

return_type: char *


decompiled_code:
__int64 __fastcall malloc_select(__int64 a1)
{
__int64 v1; // rsi
__int64 v4; // rdi
__int64 v5; // rbx
__int64 v6; // rdx
__int64 v7; // rax

v1 = s_0;
if ( !a1 || s_0 )
return s_0;
v4 = *(_QWORD *)(a1 + 8);
if ( !v4 )
return 0LL;
v5 = 1LL;
do
{
v6 = (unsigned int)v5++;
v7 = build_arg_list(v4, v1, v6);
v4 = *(_QWORD *)(a1 + 8 * v5);
s_0 = v7;
v1 = v7;
}
while ( v4 );
return v1;
}

original_code:
t_select *malloc_select(char **argv)
{
 int i;
 static t_select *s = ((void *)0);
 i = 0;
 if (s == ((void *)0) && argv != ((void *)0))
 {
  while (i++, argv[i] != ((void *)0))
   s = build_arg_list(argv[i], s, i);
 }
 return (s);
}

canonical_original_code:
struct s_select *malloc_select(char **argv)
{
 int i;
 static struct s_select *s = ((void *)0);
 i = 0;
 if (s == ((void *)0) && argv != ((void *)0))
 {
  while (i++, argv[i] != ((void *)0))
   s = build_arg_list(argv[i], s, i);
 }
 return (s);
}

variable_types:
argv
char **

variable_types: i int

variable_types: struct s_select { char *arg; int argnbr; int poscol; int posline; int selected; struct s_select *next; } *


decompiled_code:
__int64 __fastcall select_arg(_DWORD *a1, __int64 a2)
{
__int64 v2; // r8
__int64 v3; // rcx
int v4; // eax
__int64 v5; // rdx
__int64 result; // rax
__int64 v7; // rsi

v2 = a2;
v3 = a2;
v4 = a1[3] * a1[11] + a1[10] / (a1[4] + 1);
if ( v4 <= 0 )
{
LABEL_5:
++*(_DWORD *)(v3 + 20);
result = ft_print_arg(a1, a2);
}
else
{
v5 = 0LL;
while ( v3 )
{
v5 = (unsigned int)(v5 + 1);
v3 = *(_QWORD *)(v3 + 24);
if ( v4 <= (int)v5 )
goto LABEL_5;
}
do
{
v7 = (unsigned int)(v5 + 1);
if ( v4 <= (int)v7 )
select_arg_cold(a1, v7, v5, v3, v2);
v5 = (unsigned int)(v5 + 2);
}
while ( v4 > (int)v5 );
++*(_DWORD *)(v3 + 20);
result = ft_print_arg(a1, v2);
}
return result;
}

original_code:
void select_arg(t_termdata *td, t_select *s)
{
 int i;
 int j;
 t_select *save;
 i = 0;
 j = (td->poslin * td->wnbr) + (td->poscol / (td->padlength + 1));
 save = s;
 while (i < j)
 {
  if (s != ((void *)0))
   s = s->next;
  i++;
 }
 s->selected += 1;
 s = save;
 ft_print_arg(td, s);
}

canonical_original_code:
void select_arg(struct s_termdata *td, struct s_select *s)
{
 int i;
 int j;
 struct s_select *save;
 i = 0;
 j = (td->poslin * td->wnbr) + (td->poscol / (td->padlength + 1));
 save = s;
 while (i < j)
 {
  if (s != ((void *)0))
   s = s->next;
  i++;
 }
 s->selected += 1;
 s = save;
 ft_print_arg(td, s);
}

variable_types: struct s_termdata { char *termtype; int tty; int wnbr; int padlength; int totalline; int totalarg; int lastline; int wincol; int winline; int poscol; int poslin; char *lineup; char *clear; } *

return_type: void

user_defined_types: struct s_select { char *arg; int argnbr; int poscol; int posline; int selected; struct s_select *next; }


decompiled_code:
__int64 __fastcall space_pressed(_DWORD *a1, __int64 a2)
{
select_arg(a1, a2);
return move_cursor(1LL, 0LL, a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func2(_DWORD *a1, __int64 a2)
{
func1(a1, a2);
return move_cursor(1LL, 0LL, a1, a2);
}

original_code:
void space_pressed(t_termdata *td, t_select *s)
{
 select_arg(td, s);
 move_cursor(1, 0, td, s);
}

canonical_original_code:
void space_pressed(struct s_termdata *td, struct s_select *s)
{
 select_arg(td, s);
 move_cursor(1, 0, td, s);
}

user_defined_types: struct s_termdata { char *termtype; int tty; int wnbr; int padlength; int totalline; int totalarg; int lastline; int wincol; int winline; int poscol; int poslin; char *lineup; char *clear; }


decompiled_code:
void __fastcall __noreturn return_selection(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
size_t v3; // rax

v2 = a2;
change_back_term_info();
close(*(_DWORD *)(a1 + 8));
if ( a2 )
{
do
{
while ( *(_DWORD *)(v2 + 20) % 2 != 1 )
{
v2 = *(_QWORD *)(v2 + 24);
if ( !v2 )
goto LABEL_6;
}
v3 = ft_strlen(*(_QWORD *)v2);
write(1, *(const void **)v2, v3);
write(1, &unk_359, 1uLL);
v2 = *(_QWORD *)(v2 + 24);
}
while ( v2 );
}
LABEL_6:
exit(0);
}

canonical_decompiled_code:
void __fastcall __noreturn func3(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
size_t v3; // rax

v2 = a2;
change_back_term_info();
close(*(_DWORD *)(a1 + 8));
if ( a2 )
{
do
{
while ( *(_DWORD *)(v2 + 20) % 2 != 1 )
{
v2 = *(_QWORD *)(v2 + 24);
if ( !v2 )
goto LABEL_6;
}
v3 = ft_strlen(*(_QWORD *)v2);
write(1, *(const void **)v2, v3);
write(1, &unk_359, 1uLL);
v2 = *(_QWORD *)(v2 + 24);
}
while ( v2 );
}
LABEL_6:
exit(0);
}

original_code:
void return_selection(t_termdata *td, t_select *s)
{
 change_back_term_info();
 close(td->tty);
 while (s != ((void *)0))
 {
  if (s->selected % 2 == 1)
  {
   write(1, s->arg, ft_strlen(s->arg));
   write(1, " ", 1);
  }
  s = s->next;
 }
 exit(0);
}

canonical_original_code:
void return_selection(struct s_termdata *td, struct s_select *s)
{
 change_back_term_info();
 close(td->tty);
 while (s != ((void *)0))
 {
  if (s->selected % 2 == 1)
  {
   write(1, s->arg, ft_strlen(s->arg));
   write(1, " ", 1);
  }
  s = s->next;
 }
 exit(0);
}


decompiled_code:
void __fastcall wait_while_read(_DWORD *a1, __int64 a2)
{
__int64 v2; // [rsp+8h] [rbp-50h] BYREF
char buf; // [rsp+10h] [rbp-48h] BYREF
char v4; // [rsp+11h] [rbp-47h]
char v5; // [rsp+12h] [rbp-46h]
char v6; // [rsp+13h] [rbp-45h]

v2 = a2;
if ( a2 )
{
while ( 1 )
{
ft_bzero(&buf, 50LL);
read(0, &buf, 0x32uLL);
switch ( buf )
{
case 27:
if ( !v4 )
return;
if ( v4 == 91 )
{
switch ( v5 )
{
case 'D':
if ( !v6 )
{
move_cursor(0xFFFFFFFFLL, 0LL, a1, v2);
break;
}
break;
case 'C':
if ( !v6 )
{
move_cursor(1LL, 0LL, a1, v2);
break;
}
break;
case 'B':
if ( !v6 )
{
move_cursor(0LL, 1LL, a1, v2);
break;
}
break;
case '3':
goto LABEL_15;
default:
if ( v5 == 65 && !v6 )
{
move_cursor(0LL, 0xFFFFFFFFLL, a1, v2);
break;
}
break;
}
}
LABEL_6:
if ( !v2 )
return;
break;
case 32:
if ( !v4 )
space_pressed(a1, v2);
goto LABEL_6;
case 127:
if ( v4 )
goto LABEL_6;
LABEL_15:
delete_arg(a1, &v2);
if ( !v2 )
return;
break;
default:
if ( buf == 10 && !v4 )
return_selection((__int64)a1, v2);
goto LABEL_6;
}
}
}
}

canonical_decompiled_code:
void __fastcall func4(_DWORD *a1, __int64 a2)
{
__int64 v2; // [rsp+8h] [rbp-50h] BYREF
char buf; // [rsp+10h] [rbp-48h] BYREF
char v4; // [rsp+11h] [rbp-47h]
char v5; // [rsp+12h] [rbp-46h]
char v6; // [rsp+13h] [rbp-45h]

v2 = a2;
if ( a2 )
{
while ( 1 )
{
ft_bzero(&buf, 50LL);
read(0, &buf, 0x32uLL);
switch ( buf )
{
case 27:
if ( !v4 )
return;
if ( v4 == 91 )
{
switch ( v5 )
{
case 'D':
if ( !v6 )
{
move_cursor(0xFFFFFFFFLL, 0LL, a1, v2);
break;
}
break;
case 'C':
if ( !v6 )
{
move_cursor(1LL, 0LL, a1, v2);
break;
}
break;
case 'B':
if ( !v6 )
{
move_cursor(0LL, 1LL, a1, v2);
break;
}
break;
case '3':
goto LABEL_15;
default:
if ( v5 == 65 && !v6 )
{
move_cursor(0LL, 0xFFFFFFFFLL, a1, v2);
break;
}
break;
}
}
LABEL_6:
if ( !v2 )
return;
break;
case 32:
if ( !v4 )
func2(a1, v2);
goto LABEL_6;
case 127:
if ( v4 )
goto LABEL_6;
LABEL_15:
delete_arg(a1, &v2);
if ( !v2 )
return;
break;
default:
if ( buf == 10 && !v4 )
func3((__int64)a1, v2);
goto LABEL_6;
}
}
}
}

variable_types:
buf
char [50]


decompiled_code:
__int64 __fastcall ft_putunbr(unsigned __int64 a1)
{
unsigned __int64 v1; // rbp

LOBYTE(v1) = a1;
if ( a1 > 9 )
{
ft_putunbr(a1 / 0xA);
v1 = a1 % 0xA;
}
return ft_putchar((unsigned __int8)(v1 + 48));
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int64 a1)
{
unsigned __int64 v1; // rbp

LOBYTE(v1) = a1;
if ( a1 > 9 )
{
func0(a1 / 0xA);
v1 = a1 % 0xA;
}
return ft_putchar((unsigned __int8)(v1 + 48));
}

original_code:
void ft_putunbr(unsigned long n)
{
 if (n > 9)
 {
  ft_putunbr(n / 10);
  ft_putunbr(n % 10);
 }
 else if (n <= 9)
 {
  ft_putchar(n + 48);
 }
}

variable_types:
n
unsigned long


variable_types: struct s_dat { unsigned char arena[-1]; struct s_proc { unsigned char reg[-1]; int pc; int carry; unsigned char instruct; unsigned char params; int cycle_to_exec; int nbr_live; struct s_proc *next; } **bgn_lst; struct s_hero { unsigned char *buf; char *name; int hero_num; struct s_hero *next; } *hero_lst; int cycle_to_die; int do_we_check; int nb_checks; int current_cycle; int dump; int last_player_alive; int verbose; } *

variable_types:
proc
struct s_proc *

variable_types:
type
short [2]

variable_types:
val
long [3]

user_defined_types: struct s_dat { unsigned char arena[-1]; struct s_proc **bgn_lst; struct s_hero *hero_lst; int cycle_to_die; int do_we_check; int nb_checks; int current_cycle; int dump; int last_player_alive; int verbose; }


canonical_original_code:
void f_sti(struct s_dat *dat, struct s_proc *proc)
{
 long val[3];
 short type[2];
 int err;
 err = 0;
 type[0] = ((proc->params >> ((3 - 1) * 2)) % 4);
 type[1] = ((proc->params >> ((3 - 2) * 2)) % 4);
 get_params(dat, proc, val, 2);
 if (val[0] > 0 && val[0] <= 4)
 {
  if (type[0] == 1 && val[1] > 0 && val[1] <= 16)
   val[1] = get_val(proc->reg + ((val[1] - 1) * 4), 0, 4);
  else if (type[0] == 1)
   err = 1;
  if (type[1] == 1 && val[2] > 0 && val[2] <= 16)
   val[2] = get_val(proc->reg + ((val[2] - 1) * 4), 0, 4);
  else if (type[1] == 1)
   err = 1;
  if (!err)
   f_sti_exec(dat, proc, type, val);
 }
 move_pc(proc, 2);
}

variable_types: err int

user_defined_types: struct s_hero { unsigned char *buf; char *name; int hero_num; struct s_hero *next; }

user_defined_types: struct s_proc { unsigned char reg[-1]; int pc; int carry; unsigned char instruct; unsigned char params; int cycle_to_exec; int nbr_live; struct s_proc *next; }


decompiled_code:
__int64 __fastcall find_pad(_QWORD *a1)
{
_QWORD *v1; // rbx
unsigned int v2; // er12
unsigned int v3; // eax

if ( !a1 )
return 0LL;
v1 = a1;
v2 = 0;
do
{
while ( ft_strlen(*v1) <= (unsigned __int64)v2 )
{
v1 = (_QWORD *)v1[3];
if ( !v1 )
return v2;
}
v3 = ft_strlen(*v1);
v1 = (_QWORD *)v1[3];
v2 = v3;
}
while ( v1 );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1)
{
_QWORD *v1; // rbx
unsigned int v2; // er12
unsigned int v3; // eax

if ( !a1 )
return 0LL;
v1 = a1;
v2 = 0;
do
{
while ( ft_strlen(*v1) <= (unsigned __int64)v2 )
{
v1 = (_QWORD *)v1[3];
if ( !v1 )
return v2;
}
v3 = ft_strlen(*v1);
v1 = (_QWORD *)v1[3];
v2 = v3;
}
while ( v1 );
return v2;
}

original_code:
int find_pad(t_select *s)
{
 int i;
 t_select *save;
 i = 0;
 save = s;
 while (s != ((void *)0))
 {
  if (ft_strlen(s->arg) > (unsigned int)i)
   i = ft_strlen(s->arg);
  s = s->next;
 }
 s = save;
 return (i);
}

canonical_original_code:
int find_pad(struct s_select *s)
{
 int i;
 struct s_select *save;
 i = 0;
 save = s;
 while (s != ((void *)0))
 {
  if (ft_strlen(s->arg) > (unsigned int)i)
   i = ft_strlen(s->arg);
  s = s->next;
 }
 s = save;
 return (i);
}


decompiled_code:
__int64 __fastcall get_term_data(__int64 a1, _QWORD *a2)
{
char *v3; // rax
const char *v4; // rsi
_QWORD *v5; // rax
int v6; // eax

v3 = getenv("TERM");
*(_QWORD *)a1 = v3;
v4 = v3;
if ( !v3 )
{
ft_error("getenv error");
v4 = *(const char **)a1;
}
if ( tgetent(0LL, v4) == -1 )
ft_error("tgetent error");
*(_DWORD *)(a1 + 32) = tgetnum("co");
*(_DWORD *)(a1 + 36) = tgetnum("li");
*(_QWORD *)(a1 + 48) = tgetstr("up", 0LL);
*(_QWORD *)(a1 + 56) = tgetstr("cl", 0LL);
*(_DWORD *)(a1 + 16) = find_pad(a2);
do
{
v5 = a2;
a2 = (_QWORD *)a2[3];
}
while ( a2 );
v6 = *((_DWORD *)v5 + 2);
*(_DWORD *)(a1 + 8) = 0;
*(_DWORD *)(a1 + 24) = v6;
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, _QWORD *a2)
{
char *v3; // rax
const char *v4; // rsi
_QWORD *v5; // rax
int v6; // eax

v3 = getenv("TERM");
*(_QWORD *)a1 = v3;
v4 = v3;
if ( !v3 )
{
ft_error("getenv error");
v4 = *(const char **)a1;
}
if ( tgetent(0LL, v4) == -1 )
ft_error("tgetent error");
*(_DWORD *)(a1 + 32) = tgetnum("co");
*(_DWORD *)(a1 + 36) = tgetnum("li");
*(_QWORD *)(a1 + 48) = tgetstr("up", 0LL);
*(_QWORD *)(a1 + 56) = tgetstr("cl", 0LL);
*(_DWORD *)(a1 + 16) = func0(a2);
do
{
v5 = a2;
a2 = (_QWORD *)a2[3];
}
while ( a2 );
v6 = *((_DWORD *)v5 + 2);
*(_DWORD *)(a1 + 8) = 0;
*(_DWORD *)(a1 + 24) = v6;
return a1;
}

original_code:
t_termdata *get_term_data(t_termdata *td, t_select *s)
{
 t_select *save;
 if (!(td->termtype = getenv("TERM")))
  ft_error("getenv error");
 if (tgetent(((void *)0), td->termtype) == (-1))
  ft_error("tgetent error");
 td->wincol = tgetnum("co");
 td->winline = tgetnum("li");
 td->lineup = tgetstr("up", ((void *)0));
 td->clear = tgetstr("cl", ((void *)0));
 td->padlength = find_pad(s);
 save = s;
 while (s->next != ((void *)0))
  s = s->next;
 td->totalarg = s->argnbr;
 s = save;
 td->tty = 0;
 return (td);
}

canonical_original_code:
struct s_termdata *get_term_data(struct s_termdata *td, struct s_select *s)
{
 struct s_select *save;
 if (!(td->termtype = getenv("TERM")))
  ft_error("getenv error");
 if (tgetent(((void *)0), td->termtype) == (-1))
  ft_error("tgetent error");
 td->wincol = tgetnum("co");
 td->winline = tgetnum("li");
 td->lineup = tgetstr("up", ((void *)0));
 td->clear = tgetstr("cl", ((void *)0));
 td->padlength = find_pad(s);
 save = s;
 while (s->next != ((void *)0))
  s = s->next;
 td->totalarg = s->argnbr;
 s = save;
 td->tty = 0;
 return (td);
}

variable_types:
td
struct s_termdata *

return_type: struct s_termdata { char *termtype; int tty; int wnbr; int padlength; int totalline; int totalarg; int lastline; int wincol; int winline; int poscol; int poslin; char *lineup; char *clear; } *


decompiled_code:
__int64 __fastcall ft_print_arg(__int64 a1, _QWORD *a2)
{
__int64 v2; // rax
__int64 v3; // rax
__int64 v4; // rax
int v5; // edx
__int64 v6; // rbp
int v7; // eax
int v8; // ecx
char *v9; // rax
int v10; // edx
const char *v11; // rdi
int v12; // eax
__int64 result; // rax
int v14; // [rsp+8h] [rbp-20h] BYREF
unsigned int v15[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v2 = malloc_struct();
v3 = get_term_data(v2, a2);
v4 = change_term_info(v3);
v5 = *(_DWORD *)(v4 + 16);
v6 = v4;
v7 = *(_DWORD *)(v4 + 32);
if ( v5 >= v7 || (v8 = v5 + 1, v7 + (v5 + 1) * *(_DWORD *)(v6 + 24) > v7 * *(_DWORD *)(v6 + 36)) )
{
v9 = tgetstr("cl", 0LL);
tputs(v9, 1, (int (*)(int))&out);
ft_putstr_fd("Not enougth space to display every information", *(unsigned int *)(v6 + 8));
while ( 1 )
{
v10 = *(_DWORD *)(v6 + 16);
v7 = *(_DWORD *)(v6 + 32);
if ( v10 < v7 )
{
v8 = v10 + 1;
if ( v7 + (v10 + 1) * *(_DWORD *)(v6 + 24) <= v7 * *(_DWORD *)(v6 + 36) )
break;
}
v6 = get_term_data(v6, a2);
}
}
v11 = *(const char **)(v6 + 56);
v14 = 0;
v12 = v7 / v8;
v15[0] = 0;
if ( !v12 )
v12 = 1;
*(_DWORD *)(v6 + 12) = v12;
tputs(v11, 1, (int (*)(int))&out);
print_arg_and_count(v6, a2, v15, &v14);
result = v15[0];
if ( (int)v15[0] > 0 )
{
do
{
tputs(*(const char **)(v6 + 48), 1, (int (*)(int))&out);
result = v15[0] - 1;
v15[0] = result;
}
while ( (int)result > 0 );
}
return result;
}

original_code:
void ft_print_arg(t_termdata *td, t_select *s)
{
 int j;
 int line;
 td = malloc_struct();
 td = get_term_data(td, s);
 td = change_term_info(td);
 if (td->wincol < (td->padlength + 1) || ((td->totalarg * (td->padlength + 1) + td->wincol) > (td->wincol * td->winline)))
 {
  tputs(tgetstr("cl", ((void *)0)), 1, out);
  ft_putstr_fd("Not enougth space to display every information", td->tty);
  while ((td->wincol < (td->padlength + 1)) || ((td->totalarg * (td->padlength + 1) + td->wincol) > (td->wincol * td->winline)))
   td = get_term_data(td, s);
 }
 td->wnbr = (int)(td->wincol / (td->padlength + 1));
 if (td->wnbr == 0)
  td->wnbr = 1;
 line = j = 0;
 tputs(td->clear, 1, out);
 print_arg_and_count(td, s, &line, &j);
 while (line > 0)
 {
  tputs(td->lineup, 1, out);
  line--;
 }
}

canonical_original_code:
void ft_print_arg(struct s_termdata *td, struct s_select *s)
{
 int j;
 int line;
 td = malloc_struct();
 td = get_term_data(td, s);
 td = change_term_info(td);
 if (td->wincol < (td->padlength + 1) || ((td->totalarg * (td->padlength + 1) + td->wincol) > (td->wincol * td->winline)))
 {
  tputs(tgetstr("cl", ((void *)0)), 1, out);
  ft_putstr_fd("Not enougth space to display every information", td->tty);
  while ((td->wincol < (td->padlength + 1)) || ((td->totalarg * (td->padlength + 1) + td->wincol) > (td->wincol * td->winline)))
   td = get_term_data(td, s);
 }
 td->wnbr = (int)(td->wincol / (td->padlength + 1));
 if (td->wnbr == 0)
  td->wnbr = 1;
 line = j = 0;
 tputs(td->clear, 1, out);
 print_arg_and_count(td, s, &line, &j);
 while (line > 0)
 {
  tputs(td->lineup, 1, out);
  line--;
 }
}

variable_types: j int

variable_types: line int


decompiled_code:
__int64 __fastcall change_term_info(__int64 a1)
{
char *v2; // rax
char *v3; // rax
char *v4; // rax
int v5; // eax
struct termios v6; // [rsp+0h] [rbp-48h] BYREF

if ( i_0 )
return a1;
v2 = tgetstr("ti", 0LL);
tputs(v2, 1, (int (*)(int))&out);
v3 = tgetstr("vi", 0LL);
tputs(v3, 1, (int (*)(int))&out);
if ( tgetent(0LL, *(const char **)a1) == -1 )
ft_error("tgetent error");
if ( tcgetattr(0, &v6) == -1 )
ft_error("change : tcgetattr error");
v6.c_lflag = v6.c_lflag & 0xFFFFFFF5 | 1;
if ( tcsetattr(0, 1, &v6) == -1 )
ft_error("tcsetattr error");
v4 = ttyname(0);
v5 = open(v4, 1);
*(_DWORD *)(a1 + 8) = v5;
if ( v5 == -1 )
ft_error("Unable to open a fildes");
++i_0;
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
char *v2; // rax
char *v3; // rax
char *v4; // rax
int v5; // eax
struct termios v6; // [rsp+0h] [rbp-48h] BYREF

if ( i_0 )
return a1;
v2 = tgetstr("ti", 0LL);
tputs(v2, 1, (int (*)(int))&out);
v3 = tgetstr("vi", 0LL);
tputs(v3, 1, (int (*)(int))&out);
if ( tgetent(0LL, *(const char **)a1) == -1 )
ft_error("tgetent error");
if ( tcgetattr(0, &v6) == -1 )
ft_error("change : tcgetattr error");
v6.c_lflag = v6.c_lflag & 0xFFFFFFF5 | 1;
if ( tcsetattr(0, 1, &v6) == -1 )
ft_error("tcsetattr error");
v4 = ttyname(0);
v5 = open(v4, 1);
*(_DWORD *)(a1 + 8) = v5;
if ( v5 == -1 )
ft_error("Unable to open a fildes");
++i_0;
return a1;
}

original_code:
t_termdata *change_term_info(t_termdata *s)
{
 static int i = 0;
 struct termios term;
 if (i == 0)
 {
  tputs(tgetstr("ti", ((void *)0)), 1, out);
  tputs(tgetstr("vi", ((void *)0)), 1, out);
  if (tgetent(((void *)0), s->termtype) == (-1))
   ft_error("tgetent error");
  if (tcgetattr(0, &term) == -1)
   ft_error("change : tcgetattr error");
  term.c_lflag &= ~(0000002);
  term.c_lflag &= ~(0000010);
  term.c_lflag |= 0000001;
  if (tcsetattr(0, 1, &term) == -1)
   ft_error("tcsetattr error");
  if ((s->tty = open(ttyname(0), 01)) == -1)
   ft_error("Unable to open a fildes");
  i++;
 }
 return (s);
}

canonical_original_code:
struct s_termdata *change_term_info(struct s_termdata *s)
{
 static int i = 0;
 struct termios term;
 if (i == 0)
 {
  tputs(tgetstr("ti", ((void *)0)), 1, out);
  tputs(tgetstr("vi", ((void *)0)), 1, out);
  if (tgetent(((void *)0), s->termtype) == (-1))
   ft_error("tgetent error");
  if (tcgetattr(0, &term) == -1)
   ft_error("change : tcgetattr error");
  term.c_lflag &= ~(0000002);
  term.c_lflag &= ~(0000010);
  term.c_lflag |= 0000001;
  if (tcsetattr(0, 1, &term) == -1)
   ft_error("tcsetattr error");
  if ((s->tty = open(ttyname(0), 01)) == -1)
   ft_error("Unable to open a fildes");
  i++;
 }
 return (s);
}

variable_types:
s
struct s_termdata *

variable_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; }


decompiled_code:
int change_back_term_info()
{
char *v0; // rax
char *v1; // rax
char *v2; // rax
int result; // eax
struct termios v4; // [rsp+0h] [rbp-48h] BYREF

v0 = tgetstr("cl", 0LL);
tputs(v0, 1, (int (*)(int))&out);
v1 = tgetstr("ve", 0LL);
tputs(v1, 1, (int (*)(int))&out);
v2 = tgetstr("te", 0LL);
tputs(v2, 1, (int (*)(int))&out);
if ( tcgetattr(0, &v4) == -1 )
ft_error("change back : tcgetattr error");
v4.c_lflag |= 0xAu;
result = tcsetattr(0, 0, &v4);
if ( result == -1 )
result = ft_error("tcsetattr error");
return result;
}

canonical_decompiled_code:
int func2()
{
char *v0; // rax
char *v1; // rax
char *v2; // rax
int result; // eax
struct termios v4; // [rsp+0h] [rbp-48h] BYREF

v0 = tgetstr("cl", 0LL);
tputs(v0, 1, (int (*)(int))&out);
v1 = tgetstr("ve", 0LL);
tputs(v1, 1, (int (*)(int))&out);
v2 = tgetstr("te", 0LL);
tputs(v2, 1, (int (*)(int))&out);
if ( tcgetattr(0, &v4) == -1 )
ft_error("change back : tcgetattr error");
v4.c_lflag |= 0xAu;
result = tcsetattr(0, 0, &v4);
if ( result == -1 )
result = ft_error("tcsetattr error");
return result;
}

original_code:
void change_back_term_info(void)
{
 struct termios term;
 tputs(tgetstr("cl", ((void *)0)), 1, out);
 tputs(tgetstr("ve", ((void *)0)), 1, out);
 tputs(tgetstr("te", ((void *)0)), 1, out);
 if (tcgetattr(0, &term) == -1)
  ft_error("change back : tcgetattr error");
 term.c_lflag |= (0000002);
 term.c_lflag |= (0000010);
 if (tcsetattr(0, 0, &term) == -1)
  ft_error("tcsetattr error");
}

canonical_original_code:
void change_back_term_info()
{
 struct termios term;
 tputs(tgetstr("cl", ((void *)0)), 1, out);
 tputs(tgetstr("ve", ((void *)0)), 1, out);
 tputs(tgetstr("te", ((void *)0)), 1, out);
 if (tcgetattr(0, &term) == -1)
  ft_error("change back : tcgetattr error");
 term.c_lflag |= (0000002);
 term.c_lflag |= (0000010);
 if (tcsetattr(0, 0, &term) == -1)
  ft_error("tcsetattr error");
}

user_defined_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; }


decompiled_code:
__int64 __fastcall ft_sort_list(__int64 a1, __int64 a2)
{
int v2; // eax
__int64 result; // rax
int v4; // edx
__int64 v5; // rax
__int64 v6; // rax

v2 = *(_DWORD *)(a2 + 16);
if ( *(_DWORD *)(a2 + 8) == 1 )
{
if ( v2 )
{
if ( v2 != 1 )
return a1;
goto LABEL_12;
}
result = ft_sort_list_elem(a1, 2LL);
v4 = *(_DWORD *)(a2 + 16);
}
else
{
if ( v2 )
{
if ( v2 != 1 )
return a1;
LABEL_9:
v5 = ft_sort_list_elem(a1, 0LL);
return ft_sort_list_elem(v5, 1LL);
}
result = ft_sort_list_elem(a1, 0LL);
v4 = *(_DWORD *)(a2 + 16);
}
if ( v4 == 1 )
{
a1 = result;
if ( *(_DWORD *)(a2 + 8) != 1 )
goto LABEL_9;
LABEL_12:
v6 = ft_sort_list_elem(a1, 2LL);
result = ft_sort_list_elem(v6, 3LL);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
int v2; // eax
__int64 result; // rax
int v4; // edx
__int64 v5; // rax
__int64 v6; // rax

v2 = *(_DWORD *)(a2 + 16);
if ( *(_DWORD *)(a2 + 8) == 1 )
{
if ( v2 )
{
if ( v2 != 1 )
return a1;
goto LABEL_12;
}
result = ft_sort_list_elem(a1, 2LL);
v4 = *(_DWORD *)(a2 + 16);
}
else
{
if ( v2 )
{
if ( v2 != 1 )
return a1;
LABEL_9:
v5 = ft_sort_list_elem(a1, 0LL);
return ft_sort_list_elem(v5, 1LL);
}
result = ft_sort_list_elem(a1, 0LL);
v4 = *(_DWORD *)(a2 + 16);
}
if ( v4 == 1 )
{
a1 = result;
if ( *(_DWORD *)(a2 + 8) != 1 )
goto LABEL_9;
LABEL_12:
v6 = ft_sort_list_elem(a1, 2LL);
result = ft_sort_list_elem(v6, 3LL);
}
return result;
}

original_code:
t_list2 *ft_sort_list(t_list2 *lnk, t_params *p)
{
 if (p->r == 1 && p->t == 0)
 {
  lnk = ft_sort_list_elem(lnk, 2);
 }
 else if (p->t == 0)
 {
  lnk = ft_sort_list_elem(lnk, 0);
 }
 if (p->t == 1)
 {
  if (p->r == 1)
  {
   lnk = ft_sort_list_elem(lnk, 2);
   lnk = ft_sort_list_elem(lnk, 3);
  }
  else
  {
   lnk = ft_sort_list_elem(lnk, 0);
   lnk = ft_sort_list_elem(lnk, 1);
  }
 }
 return (lnk);
}

canonical_original_code:
struct s_list2 *ft_sort_list(struct s_list2 *lnk, struct s_list4 *p)
{
 if (p->r == 1 && p->t == 0)
 {
  lnk = ft_sort_list_elem(lnk, 2);
 }
 else if (p->t == 0)
 {
  lnk = ft_sort_list_elem(lnk, 0);
 }
 if (p->t == 1)
 {
  if (p->r == 1)
  {
   lnk = ft_sort_list_elem(lnk, 2);
   lnk = ft_sort_list_elem(lnk, 3);
  }
  else
  {
   lnk = ft_sort_list_elem(lnk, 0);
   lnk = ft_sort_list_elem(lnk, 1);
  }
 }
 return (lnk);
}

variable_types:
lnk
struct s_list2 *

variable_types: struct s_list4 { int l; int a; int r; int R; int t; int round; } *

return_type: struct s_list2 { char *right; char *owner; char *group; char *name; char *time; char *link; char *size; char *major; char *minor; int blk; long timestamp; struct s_list2 *next; struct s_list2 *prev; } *


decompiled_code:
__int64 __fastcall ft_print_list_recurs(__int64 a1, _DWORD *a2, __int64 a3)
{
__int64 v3; // rbx
__int64 result; // rax
__int64 v5; // rax

if ( *(_BYTE *)(a3 + (int)ft_strirchr(a3, 47LL) + 1) != 46 || (result = (unsigned int)a2[1], (_DWORD)result) )
{
if ( *a2 == 1 )
{
v5 = ft_build_sizes_list(0LL);
ft_define_padding_elem(a1, v5, a2);
}
v3 = ft_sort_list(a1, (__int64)a2);
result = (__int64)ft_print_blk(v3, 0, a2);
do
{
if ( !v3 )
break;
ft_print_hidden_file(v3, a2);
result = ft_print_file(v3, a2);
v3 = *(_QWORD *)(v3 + 88);
}
while ( v3 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, _DWORD *a2, __int64 a3)
{
__int64 v3; // rbx
__int64 result; // rax
__int64 v5; // rax

if ( *(_BYTE *)(a3 + (int)ft_strirchr(a3, 47LL) + 1) != 46 || (result = (unsigned int)a2[1], (_DWORD)result) )
{
if ( *a2 == 1 )
{
v5 = ft_build_sizes_list(0LL);
ft_define_padding_elem(a1, v5, a2);
}
v3 = func0(a1, (__int64)a2);
result = (__int64)ft_print_blk(v3, 0, a2);
do
{
if ( !v3 )
break;
func1(v3, a2);
result = ft_print_file(v3, a2);
v3 = *(_QWORD *)(v3 + 88);
}
while ( v3 );
}
return result;
}

original_code:
void ft_print_list_recurs(t_list2 *lnk, t_params *p, char* dir)
{
 int blkcnt;
 int i;
 t_sizes *sizes;
 sizes = ((void *)0);
 i = ft_strirchr(dir, '/');
 if (dir[i + 1] == '.' && p->a == 0)
  ;
 else
 {
  blkcnt = 0;
  if (p->l == 1)
   ft_define_padding_elem(lnk, ft_build_sizes_list(sizes), p);
  lnk = ft_sort_list(lnk, p);
  ft_print_blk(lnk, blkcnt, p);
  while (lnk)
  {
   ft_print_hidden_file(lnk, p);
   ft_print_file(lnk, p);
   if (lnk->next != ((void *)0))
    lnk = lnk->next;
   else
    break ;
  }
 }
}

canonical_original_code:
void ft_print_list_recurs(struct s_list2 *lnk, struct s_list4 *p, char *dir)
{
 int blkcnt;
 int i;
 struct s_list3 *sizes;
 sizes = ((void *)0);
 i = ft_strirchr(dir, '/');
 if (dir[i + 1] == '.' && p->a == 0)
  ;
 else
 {
  blkcnt = 0;
  if (p->l == 1)
   ft_define_padding_elem(lnk, ft_build_sizes_list(sizes), p);
  lnk = ft_sort_list(lnk, p);
  ft_print_blk(lnk, blkcnt, p);
  while (lnk)
  {
   ft_print_hidden_file(lnk, p);
   ft_print_file(lnk, p);
   if (lnk->next != ((void *)0))
    lnk = lnk->next;
   else
    break ;
  }
 }
}

variable_types: struct s_list2 { char *right; char *owner; char *group; char *name; char *time; char *link; char *size; char *major; char *minor; int blk; long timestamp; struct s_list2 *next; struct s_list2 *prev; } *

variable_types:
dir
char *

variable_types: blkcnt int

variable_types: i int

variable_types: struct s_list3 { int right; int owner; int group; int name; int link; int size; int major; int minor; int time; } *

user_defined_types: struct s_list4 { int l; int a; int r; int R; int t; int round; }


decompiled_code:
ssize_t __fastcall ft_putwchar(int a1)
{
int buf[3]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = a1;
return write(1, buf, 1uLL);
}

canonical_decompiled_code:
ssize_t __fastcall func0(int a1)
{
int buf[3]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = a1;
return write(1, buf, 1uLL);
}

original_code:
void ft_putwchar(wchar_t c)
{
 write(1, &c, 1);
}

canonical_original_code:
void ft_putwchar(int c)
{
 write(1, &c, 1);
}

variable_types: c int


decompiled_code:
ssize_t __fastcall ft_putchar(char a1)
{
char buf[12]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = a1;
return write(1, buf, 1uLL);
}

canonical_decompiled_code:
ssize_t __fastcall func1(char a1)
{
char buf[12]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = a1;
return write(1, buf, 1uLL);
}

original_code:
void ft_putchar(char c)
{
 write(1, &c, 1);
}

variable_types: c char


decompiled_code:
__int64 __fastcall ft_sort_push_back(__int64 a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // rdx

if ( !a1 )
return a2;
v2 = a1;
do
{
v3 = v2;
v2 = *(_QWORD *)(v2 + 8);
}
while ( v2 );
*(_QWORD *)(v3 + 8) = a2;
return a1;
}

original_code:
t_sort *ft_sort_push_back(t_sort *lnk, t_sort *new)
{
 t_sort *save;
 save = lnk;
 if (lnk == ((void *)0))
  return (new);
 while (lnk->next != ((void *)0))
  lnk = lnk->next;
 lnk->next = new;
 return (save);
}

canonical_original_code:
struct s_list_arg *ft_sort_push_back(struct s_list_arg *lnk, struct s_list_arg *new)
{
 struct s_list_arg *save;
 save = lnk;
 if (lnk == ((void *)0))
  return (new);
 while (lnk->next != ((void *)0))
  lnk = lnk->next;
 lnk->next = new;
 return (save);
}

variable_types:
lnk
struct s_list_arg *

variable_types:
new
struct s_list_arg *

variable_types: struct s_list_arg { int val; struct s_list_arg *next; } *


decompiled_code:
__int64 ft_create_empty()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
return 0LL;
}

original_code:
t_sort *ft_create_empty(t_sort *lnk)
{
 lnk = ((void *)0);
 return (lnk);
}

canonical_original_code:
struct s_list_arg *ft_create_empty(struct s_list_arg *lnk)
{
 lnk = ((void *)0);
 return (lnk);
}

return_type: struct s_list_arg { int val; struct s_list_arg *next; } *


decompiled_code:
__int64 __fastcall ft_build_list_a(__int64 a1, __int64 a2)
{
int v2; // eax
_QWORD *v3; // rax

v2 = ft_atoi(a2);
v3 = ft_create_filled_lnk(0LL, v2);
return ft_sort_push_back(a1, (__int64)v3);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
int v2; // eax
_QWORD *v3; // rax

v2 = ft_atoi(a2);
v3 = ft_create_filled_lnk(0LL, v2);
return func0(a1, (__int64)v3);
}

original_code:
t_sort *ft_build_list_a(t_sort *lnk, char *s)
{
 int i;
 t_sort *new;
 i = ft_atoi(s);
 new = ((void *)0);
 new = ft_create_filled_lnk(new, i);
 lnk = ft_sort_push_back(lnk, new);
 return (lnk);
}

canonical_original_code:
struct s_list_arg *ft_build_list_a(struct s_list_arg *lnk, char *s)
{
 int i;
 struct s_list_arg *new;
 i = ft_atoi(s);
 new = ((void *)0);
 new = ft_create_filled_lnk(new, i);
 lnk = ft_sort_push_back(lnk, new);
 return (lnk);
}

variable_types:
s
char *

user_defined_types: struct s_list_arg { int val; struct s_list_arg *next; }


decompiled_code:
__int64 __fastcall ft_deal_with_int_conversion_part1(__int64 a1, __int64 a2)
{
__int64 v3; // rdi
__int64 result; // rax
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rax

v3 = *(_QWORD *)(a1 + 32);
if ( v3 )
{
if ( (unsigned int)ft_strncmp(v3, &unk_60F, 2LL) )
{
if ( (unsigned int)ft_strncmp(*(_QWORD *)(a1 + 32), &unk_612, 1LL) )
{
if ( !(unsigned int)ft_strncmp(*(_QWORD *)(a1 + 32), &unk_614, 2LL)
|| !(unsigned int)ft_strncmp(*(_QWORD *)(a1 + 32), &unk_617, 1LL)
|| (result = ft_strncmp(*(_QWORD *)(a1 + 32), &unk_619, 1LL), !(_DWORD)result) )
{
ft_putnbr(*(_QWORD *)(a2 + 8));
v5 = ft_itoa(*(_QWORD *)(a2 + 8));
result = ft_strlen(v5);
*(_QWORD *)(a2 + 24) += result;
}
}
else
{
ft_putnbr(*(__int16 *)(a2 + 8));
v7 = ft_itoa(*(__int16 *)(a2 + 8));
result = ft_strlen(v7);
*(_QWORD *)(a2 + 24) += result;
}
}
else
{
result = ft_putchar((unsigned int)*(char *)(a2 + 8));
++*(_QWORD *)(a2 + 24);
}
}
else
{
ft_putnbr(*(int *)(a2 + 8));
v6 = ft_itoa(*(int *)(a2 + 8));
result = ft_strlen(v6);
*(_QWORD *)(a2 + 24) += result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
__int64 v3; // rdi
__int64 result; // rax
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rax

v3 = *(_QWORD *)(a1 + 32);
if ( v3 )
{
if ( (unsigned int)ft_strncmp(v3, &unk_60F, 2LL) )
{
if ( (unsigned int)ft_strncmp(*(_QWORD *)(a1 + 32), &unk_612, 1LL) )
{
if ( !(unsigned int)ft_strncmp(*(_QWORD *)(a1 + 32), &unk_614, 2LL)
|| !(unsigned int)ft_strncmp(*(_QWORD *)(a1 + 32), &unk_617, 1LL)
|| (result = ft_strncmp(*(_QWORD *)(a1 + 32), &unk_619, 1LL), !(_DWORD)result) )
{
ft_putnbr(*(_QWORD *)(a2 + 8));
v5 = ft_itoa(*(_QWORD *)(a2 + 8));
result = ft_strlen(v5);
*(_QWORD *)(a2 + 24) += result;
}
}
else
{
ft_putnbr(*(__int16 *)(a2 + 8));
v7 = ft_itoa(*(__int16 *)(a2 + 8));
result = ft_strlen(v7);
*(_QWORD *)(a2 + 24) += result;
}
}
else
{
result = ft_putchar((unsigned int)*(char *)(a2 + 8));
++*(_QWORD *)(a2 + 24);
}
}
else
{
ft_putnbr(*(int *)(a2 + 8));
v6 = ft_itoa(*(int *)(a2 + 8));
result = ft_strlen(v6);
*(_QWORD *)(a2 + 24) += result;
}
return result;
}

original_code:
void ft_deal_with_int_conversion_part1(t_op *op, t_arg *lnk)
{
 if (op->mod)
 {
  if (ft_strncmp(op->mod, "hh", 2) == 0)
  {
   ft_putchar((signed char)lnk->i);
   lnk->ps += 1;
  }
  else if (ft_strncmp(op->mod, "h", 1) == 0)
  {
   ft_putnbr((short)lnk->i);
   lnk->ps += ft_strlen(ft_itoa((short)lnk->i));
  }
  else if (ft_strncmp(op->mod, "ll", 2) == 0
    || ft_strncmp(op->mod, "l", 1) == 0
    || ft_strncmp(op->mod, "q", 1) == 0)
  {
   ft_putnbr((long)lnk->i);
   lnk->ps += ft_strlen(ft_itoa((long)lnk->i));
  }
 }
 else
 {
  ft_putnbr((int)lnk->i);
  lnk->ps += ft_strlen(ft_itoa((int)lnk->i));
 }
}

canonical_original_code:
void ft_deal_with_int_conversion_part1(struct s_option *op, struct s_arg *lnk)
{
 if (op->mod)
 {
  if (ft_strncmp(op->mod, "hh", 2) == 0)
  {
   ft_putchar((char)lnk->i);
   lnk->ps += 1;
  }
  else if (ft_strncmp(op->mod, "h", 1) == 0)
  {
   ft_putnbr((short)lnk->i);
   lnk->ps += ft_strlen(ft_itoa((short)lnk->i));
  }
  else if (ft_strncmp(op->mod, "ll", 2) == 0
    || ft_strncmp(op->mod, "l", 1) == 0
    || ft_strncmp(op->mod, "q", 1) == 0)
  {
   ft_putnbr((long)lnk->i);
   lnk->ps += ft_strlen(ft_itoa((long)lnk->i));
  }
 }
 else
 {
  ft_putnbr((int)lnk->i);
  lnk->ps += ft_strlen(ft_itoa((int)lnk->i));
 }
}

variable_types: struct s_option { int field; char *flag; char separator; int min_width; char starwidth; int precision; char *mod; char conv; int arg_size; struct s_option *next; } *

variable_types: struct s_arg { char *str; long i; unsigned long ull; long ps; struct s_arg *next; } *


decompiled_code:
__int64 __fastcall ft_deal_with_uint_conversion_part1(__int64 a1, __int64 a2)
{
__int64 v3; // rdi
__int64 result; // rax
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rax

v3 = *(_QWORD *)(a1 + 32);
if ( v3 )
{
if ( (unsigned int)ft_strncmp(v3, &unk_60F, 2LL) )
{
if ( (unsigned int)ft_strncmp(*(_QWORD *)(a1 + 32), &unk_612, 1LL) )
{
if ( !(unsigned int)ft_strncmp(*(_QWORD *)(a1 + 32), &unk_614, 2LL)
|| !(unsigned int)ft_strncmp(*(_QWORD *)(a1 + 32), &unk_617, 1LL)
|| (result = ft_strncmp(*(_QWORD *)(a1 + 32), &unk_619, 1LL), !(_DWORD)result) )
{
ft_putunbr(*(_QWORD *)(a2 + 16));
v5 = ft_uitoa(*(_QWORD *)(a2 + 16));
result = ft_strlen(v5);
*(_QWORD *)(a2 + 24) += result;
}
}
else
{
ft_putunbr(*(unsigned __int16 *)(a2 + 16));
v7 = ft_uitoa(*(unsigned __int16 *)(a2 + 16));
result = ft_strlen(v7);
*(_QWORD *)(a2 + 24) += result;
}
}
else
{
result = ft_putchar((unsigned int)*(char *)(a2 + 16));
++*(_QWORD *)(a2 + 24);
}
}
else
{
ft_putunbr(*(unsigned int *)(a2 + 16));
v6 = ft_uitoa(*(unsigned int *)(a2 + 16));
result = ft_strlen(v6);
*(_QWORD *)(a2 + 24) += result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
__int64 v3; // rdi
__int64 result; // rax
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rax

v3 = *(_QWORD *)(a1 + 32);
if ( v3 )
{
if ( (unsigned int)ft_strncmp(v3, &unk_60F, 2LL) )
{
if ( (unsigned int)ft_strncmp(*(_QWORD *)(a1 + 32), &unk_612, 1LL) )
{
if ( !(unsigned int)ft_strncmp(*(_QWORD *)(a1 + 32), &unk_614, 2LL)
|| !(unsigned int)ft_strncmp(*(_QWORD *)(a1 + 32), &unk_617, 1LL)
|| (result = ft_strncmp(*(_QWORD *)(a1 + 32), &unk_619, 1LL), !(_DWORD)result) )
{
ft_putunbr(*(_QWORD *)(a2 + 16));
v5 = ft_uitoa(*(_QWORD *)(a2 + 16));
result = ft_strlen(v5);
*(_QWORD *)(a2 + 24) += result;
}
}
else
{
ft_putunbr(*(unsigned __int16 *)(a2 + 16));
v7 = ft_uitoa(*(unsigned __int16 *)(a2 + 16));
result = ft_strlen(v7);
*(_QWORD *)(a2 + 24) += result;
}
}
else
{
result = ft_putchar((unsigned int)*(char *)(a2 + 16));
++*(_QWORD *)(a2 + 24);
}
}
else
{
ft_putunbr(*(unsigned int *)(a2 + 16));
v6 = ft_uitoa(*(unsigned int *)(a2 + 16));
result = ft_strlen(v6);
*(_QWORD *)(a2 + 24) += result;
}
return result;
}

original_code:
void ft_deal_with_uint_conversion_part1(t_op *op, t_arg *lnk)
{
 if (op->mod)
 {
  if (ft_strncmp(op->mod, "hh", 2) == 0)
  {
   ft_putchar((unsigned char)lnk->ull);
   lnk->ps += 1;
  }
  else if (ft_strncmp(op->mod, "h", 1) == 0)
  {
   ft_putunbr((unsigned short)lnk->ull);
   lnk->ps += ft_strlen((char*)ft_uitoa((unsigned short)lnk->ull));
  }
  else if (ft_strncmp(op->mod, "ll", 2) == 0
    || ft_strncmp(op->mod, "l", 1) == 0
    || ft_strncmp(op->mod, "q", 1) == 0)
  {
   ft_putunbr((unsigned long)lnk->ull);
   lnk->ps += ft_strlen((char*)ft_uitoa((unsigned long)lnk->ull));
  }
 }
 else
 {
  ft_putunbr((unsigned int)lnk->ull);
  lnk->ps += ft_strlen((char*)ft_uitoa((unsigned int)lnk->ull));
 }
}

canonical_original_code:
void ft_deal_with_uint_conversion_part1(struct s_option *op, struct s_arg *lnk)
{
 if (op->mod)
 {
  if (ft_strncmp(op->mod, "hh", 2) == 0)
  {
   ft_putchar((unsigned char)lnk->ull);
   lnk->ps += 1;
  }
  else if (ft_strncmp(op->mod, "h", 1) == 0)
  {
   ft_putunbr((unsigned short)lnk->ull);
   lnk->ps += ft_strlen((char *)ft_uitoa((unsigned short)lnk->ull));
  }
  else if (ft_strncmp(op->mod, "ll", 2) == 0
    || ft_strncmp(op->mod, "l", 1) == 0
    || ft_strncmp(op->mod, "q", 1) == 0)
  {
   ft_putunbr((unsigned long)lnk->ull);
   lnk->ps += ft_strlen((char *)ft_uitoa((unsigned long)lnk->ull));
  }
 }
 else
 {
  ft_putunbr((unsigned int)lnk->ull);
  lnk->ps += ft_strlen((char *)ft_uitoa((unsigned int)lnk->ull));
 }
}

user_defined_types: struct s_option { int field; char *flag; char separator; int min_width; char starwidth; int precision; char *mod; char conv; int arg_size; struct s_option *next; }

user_defined_types: struct s_arg { char *str; long i; unsigned long ull; long ps; struct s_arg *next; }


decompiled_code:
__int64 __fastcall ft_deal_with_hex_spe_conv(__int64 a1, __int64 a2)
{
__int64 v4; // rdi
__int64 result; // rax
__int64 v6; // rsi
__int64 v7; // rax
__int64 v8; // rax
__int64 v9; // rax
__int64 v10; // rax
__int64 v11; // rax
__int64 v12; // rax

v4 = *(_QWORD *)(a1 + 32);
if ( !v4 )
{
v9 = ft_convert_to_hexa(*(unsigned int *)(a2 + 16), (unsigned int)*(char *)(a1 + 40));
ft_putstr(v9);
v10 = ft_convert_to_hexa(*(unsigned int *)(a2 + 16), (unsigned int)*(char *)(a1 + 40));
result = ft_strlen(v10);
*(_QWORD *)(a2 + 24) += result;
return result;
}
if ( !(unsigned int)ft_strncmp(v4, &unk_60F, 2LL) )
{
result = ft_putchar((unsigned int)*(char *)(a2 + 16));
++*(_QWORD *)(a2 + 24);
return result;
}
if ( !(unsigned int)ft_strncmp(*(_QWORD *)(a1 + 32), &unk_612, 1LL) )
{
v11 = ft_convert_to_hexa(*(unsigned __int16 *)(a2 + 16), (unsigned int)*(char *)(a1 + 40));
ft_putstr(v11);
v12 = ft_convert_to_hexa(*(unsigned __int16 *)(a2 + 16), (unsigned int)*(char *)(a1 + 40));
result = ft_strlen(v12);
*(_QWORD *)(a2 + 24) += result;
return result;
}
if ( !(unsigned int)ft_strncmp(*(_QWORD *)(a1 + 32), &unk_614, 2LL)
|| !(unsigned int)ft_strncmp(*(_QWORD *)(a1 + 32), &unk_617, 1LL) )
{
v6 = (unsigned int)*(char *)(a1 + 40);
LABEL_9:
v7 = ft_convert_to_hexa(*(_QWORD *)(a2 + 16), v6);
ft_putstr(v7);
v8 = ft_convert_to_hexa(*(_QWORD *)(a2 + 16), (unsigned int)*(char *)(a1 + 40));
result = ft_strlen(v8);
*(_QWORD *)(a2 + 24) += result;
return result;
}
result = ft_strncmp(*(_QWORD *)(a1 + 32), &unk_619, 1LL);
v6 = (unsigned int)*(char *)(a1 + 40);
if ( !(_DWORD)result || *(_BYTE *)(a1 + 40) == 112 )
goto LABEL_9;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
__int64 v4; // rdi
__int64 result; // rax
__int64 v6; // rsi
__int64 v7; // rax
__int64 v8; // rax
__int64 v9; // rax
__int64 v10; // rax
__int64 v11; // rax
__int64 v12; // rax

v4 = *(_QWORD *)(a1 + 32);
if ( !v4 )
{
v9 = ft_convert_to_hexa(*(unsigned int *)(a2 + 16), (unsigned int)*(char *)(a1 + 40));
ft_putstr(v9);
v10 = ft_convert_to_hexa(*(unsigned int *)(a2 + 16), (unsigned int)*(char *)(a1 + 40));
result = ft_strlen(v10);
*(_QWORD *)(a2 + 24) += result;
return result;
}
if ( !(unsigned int)ft_strncmp(v4, &unk_60F, 2LL) )
{
result = ft_putchar((unsigned int)*(char *)(a2 + 16));
++*(_QWORD *)(a2 + 24);
return result;
}
if ( !(unsigned int)ft_strncmp(*(_QWORD *)(a1 + 32), &unk_612, 1LL) )
{
v11 = ft_convert_to_hexa(*(unsigned __int16 *)(a2 + 16), (unsigned int)*(char *)(a1 + 40));
ft_putstr(v11);
v12 = ft_convert_to_hexa(*(unsigned __int16 *)(a2 + 16), (unsigned int)*(char *)(a1 + 40));
result = ft_strlen(v12);
*(_QWORD *)(a2 + 24) += result;
return result;
}
if ( !(unsigned int)ft_strncmp(*(_QWORD *)(a1 + 32), &unk_614, 2LL)
|| !(unsigned int)ft_strncmp(*(_QWORD *)(a1 + 32), &unk_617, 1LL) )
{
v6 = (unsigned int)*(char *)(a1 + 40);
LABEL_9:
v7 = ft_convert_to_hexa(*(_QWORD *)(a2 + 16), v6);
ft_putstr(v7);
v8 = ft_convert_to_hexa(*(_QWORD *)(a2 + 16), (unsigned int)*(char *)(a1 + 40));
result = ft_strlen(v8);
*(_QWORD *)(a2 + 24) += result;
return result;
}
result = ft_strncmp(*(_QWORD *)(a1 + 32), &unk_619, 1LL);
v6 = (unsigned int)*(char *)(a1 + 40);
if ( !(_DWORD)result || *(_BYTE *)(a1 + 40) == 112 )
goto LABEL_9;
return result;
}

original_code:
void ft_deal_with_hex_spe_conv(t_op *op, t_arg *lnk)
{
 if (op->mod)
 {
  if (ft_strncmp(op->mod, "hh", 2) == 0)
  {
   ft_putchar((unsigned char)lnk->ull);
   lnk->ps += 1;
  }
  else if (ft_strncmp(op->mod, "h", 1) == 0)
  {
   ft_putstr(ft_convert_to_hexa((unsigned short)lnk->ull, op->conv));
   lnk->ps += ft_strlen(ft_convert_to_hexa((unsigned short)lnk->ull, op->conv));
  }
  else if (ft_strncmp(op->mod, "ll", 2) == 0
    || ft_strncmp(op->mod, "l", 1) == 0
    || ft_strncmp(op->mod, "q", 1) == 0 || op->conv == 'p')
  {
   ft_putstr(ft_convert_to_hexa((unsigned long)lnk->ull, op->conv));
   lnk->ps += ft_strlen(ft_convert_to_hexa((unsigned long)lnk->ull, op->conv));
  }
 }
 else
 {
  ft_putstr(ft_convert_to_hexa((unsigned int)lnk->ull, op->conv));
  lnk->ps += ft_strlen(ft_convert_to_hexa((unsigned int)lnk->ull, op->conv));
 }
}

canonical_original_code:
void ft_deal_with_hex_spe_conv(struct s_option *op, struct s_arg *lnk)
{
 if (op->mod)
 {
  if (ft_strncmp(op->mod, "hh", 2) == 0)
  {
   ft_putchar((unsigned char)lnk->ull);
   lnk->ps += 1;
  }
  else if (ft_strncmp(op->mod, "h", 1) == 0)
  {
   ft_putstr(ft_convert_to_hexa((unsigned short)lnk->ull, op->conv));
   lnk->ps += ft_strlen(ft_convert_to_hexa((unsigned short)lnk->ull, op->conv));
  }
  else if (ft_strncmp(op->mod, "ll", 2) == 0
    || ft_strncmp(op->mod, "l", 1) == 0
    || ft_strncmp(op->mod, "q", 1) == 0 || op->conv == 'p')
  {
   ft_putstr(ft_convert_to_hexa((unsigned long)lnk->ull, op->conv));
   lnk->ps += ft_strlen(ft_convert_to_hexa((unsigned long)lnk->ull, op->conv));
  }
 }
 else
 {
  ft_putstr(ft_convert_to_hexa((unsigned int)lnk->ull, op->conv));
  lnk->ps += ft_strlen(ft_convert_to_hexa((unsigned int)lnk->ull, op->conv));
 }
}


decompiled_code:
__int64 __fastcall ft_deal_with_hexa_conversion(__int64 a1, __int64 a2)
{
__int64 v3; // rdi
__int64 v4; // rdi
__int64 v5; // rsi
__int64 result; // rax
__int64 v7; // rdi
__int64 v8[2]; // [rsp+8h] [rbp-10h] BYREF

v3 = *(_QWORD *)(a1 + 8);
v8[0] = a2;
if ( !v3 )
{
if ( *(_BYTE *)(a1 + 40) != 112 )
{
LABEL_11:
v5 = v8[0];
if ( *(_QWORD *)(v8[0] + 16) )
goto LABEL_12;
LABEL_23:
ft_create_padding(a1, v8);
v5 = v8[0];
goto LABEL_12;
}
LABEL_19:
ft_create_padding(a1, v8);
ft_putstr(&unk_61B);
v5 = v8[0];
goto LABEL_12;
}
if ( (unsigned int)ft_strichr(v3, 35LL) != -1
&& *(_QWORD *)(v8[0] + 16)
&& (unsigned int)ft_strichr(*(_QWORD *)(a1 + 8), 48LL) == -1
|| *(_BYTE *)(a1 + 40) == 112 )
{
goto LABEL_19;
}
v4 = *(_QWORD *)(a1 + 8);
if ( !v4 )
goto LABEL_11;
if ( (unsigned int)ft_strichr(v4, 35LL) == -1 )
{
LABEL_21:
if ( *(_BYTE *)(a1 + 40) == 112 )
goto LABEL_9;
goto LABEL_11;
}
if ( *(_QWORD *)(v8[0] + 16) )
{
if ( (unsigned int)ft_strichr(*(_QWORD *)(a1 + 8), 48LL) != -1 )
goto LABEL_9;
goto LABEL_21;
}
if ( *(_BYTE *)(a1 + 40) != 112 )
goto LABEL_23;
LABEL_9:
ft_putstr(&unk_61B);
ft_create_padding(a1, v8);
v5 = v8[0];
LABEL_12:
result = ft_deal_with_hex_spe_conv(a1, v5);
v7 = *(_QWORD *)(a1 + 8);
if ( !v7 || (result = ft_strichr(v7, 35LL), (_DWORD)result == -1) || (result = v8[0], !*(_QWORD *)(v8[0] + 16)) )
{
if ( *(_BYTE *)(a1 + 40) != 112 )
return result;
result = v8[0];
}
*(_QWORD *)(result + 24) += 2LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
__int64 v3; // rdi
__int64 v4; // rdi
__int64 v5; // rsi
__int64 result; // rax
__int64 v7; // rdi
__int64 v8[2]; // [rsp+8h] [rbp-10h] BYREF

v3 = *(_QWORD *)(a1 + 8);
v8[0] = a2;
if ( !v3 )
{
if ( *(_BYTE *)(a1 + 40) != 112 )
{
LABEL_11:
v5 = v8[0];
if ( *(_QWORD *)(v8[0] + 16) )
goto LABEL_12;
LABEL_23:
ft_create_padding(a1, v8);
v5 = v8[0];
goto LABEL_12;
}
LABEL_19:
ft_create_padding(a1, v8);
ft_putstr(&unk_61B);
v5 = v8[0];
goto LABEL_12;
}
if ( (unsigned int)ft_strichr(v3, 35LL) != -1
&& *(_QWORD *)(v8[0] + 16)
&& (unsigned int)ft_strichr(*(_QWORD *)(a1 + 8), 48LL) == -1
|| *(_BYTE *)(a1 + 40) == 112 )
{
goto LABEL_19;
}
v4 = *(_QWORD *)(a1 + 8);
if ( !v4 )
goto LABEL_11;
if ( (unsigned int)ft_strichr(v4, 35LL) == -1 )
{
LABEL_21:
if ( *(_BYTE *)(a1 + 40) == 112 )
goto LABEL_9;
goto LABEL_11;
}
if ( *(_QWORD *)(v8[0] + 16) )
{
if ( (unsigned int)ft_strichr(*(_QWORD *)(a1 + 8), 48LL) != -1 )
goto LABEL_9;
goto LABEL_21;
}
if ( *(_BYTE *)(a1 + 40) != 112 )
goto LABEL_23;
LABEL_9:
ft_putstr(&unk_61B);
ft_create_padding(a1, v8);
v5 = v8[0];
LABEL_12:
result = func2(a1, v5);
v7 = *(_QWORD *)(a1 + 8);
if ( !v7 || (result = ft_strichr(v7, 35LL), (_DWORD)result == -1) || (result = v8[0], !*(_QWORD *)(v8[0] + 16)) )
{
if ( *(_BYTE *)(a1 + 40) != 112 )
return result;
result = v8[0];
}
*(_QWORD *)(result + 24) += 2LL;
return result;
}

original_code:
void ft_deal_with_hexa_conversion(t_op *op, t_arg *lnk)
{
 if ((op->flag && ft_strichr(op->flag, '#') != -1 && lnk->ull != 0
  && ft_strichr(op->flag, '0') == -1) || op->conv == 'p')
 {
  ft_create_padding(op, &lnk);
  ft_putstr("0x");
 }
 else if ((op->flag && ft_strichr(op->flag, '#') != -1 && lnk->ull != 0
   && ft_strichr(op->flag, '0') != -1) || op->conv == 'p')
 {
  ft_putstr("0x");
  ft_create_padding(op, &lnk);
 }
 else if (lnk->ull == 0)
  ft_create_padding(op, &lnk);
 ft_deal_with_hex_spe_conv(op, lnk);
 if ((op->flag && ft_strichr(op->flag, '#') != -1 && lnk->ull != 0)
  || op->conv == 'p')
  lnk->ps += 2;
}

canonical_original_code:
void ft_deal_with_hexa_conversion(struct s_option *op, struct s_arg *lnk)
{
 if ((op->flag && ft_strichr(op->flag, '#') != -1 && lnk->ull != 0
  && ft_strichr(op->flag, '0') == -1) || op->conv == 'p')
 {
  ft_create_padding(op, &lnk);
  ft_putstr("0x");
 }
 else if ((op->flag && ft_strichr(op->flag, '#') != -1 && lnk->ull != 0
   && ft_strichr(op->flag, '0') != -1) || op->conv == 'p')
 {
  ft_putstr("0x");
  ft_create_padding(op, &lnk);
 }
 else if (lnk->ull == 0)
  ft_create_padding(op, &lnk);
 ft_deal_with_hex_spe_conv(op, lnk);
 if ((op->flag && ft_strichr(op->flag, '#') != -1 && lnk->ull != 0)
  || op->conv == 'p')
  lnk->ps += 2;
}