decompiled_code:
__int64 __fastcall RTIME_Initialise(int *a1, __int64 a2)
{
int v4; // er15
int v5; // ebx
bool v6; // r9
bool v7; // cf
bool v8; // zf
const char **v9; // rbp
__int64 v10; // rcx
const char *v11; // rsi
const char *v12; // rdi
__int64 v13; // rdx
__int64 v14; // rcx

if ( *a1 <= 1 )
{
v4 = 1;
}
else
{
v4 = 1;
v5 = 1;
do
{
v9 = (const char **)(a2 + 8LL * v5);
if ( !strcmp(*v9, "-rtime") )
{
RTIME_enabled = 1;
}
else
{
v6 = strcmp(*v9, "-nortime") != 0;
v7 = 0;
v8 = !v6;
if ( v6 )
{
v10 = 6LL;
v11 = *v9;
v12 = "-help";
do
{
if ( !v10 )
break;
v7 = *v11 < (unsigned int)*v12;
v8 = *v11++ == *v12++;
--v10;
}
while ( v8 );
if ( (!v7 && !v8) == v7 )
{
Log_print("\t-rtime Enable R-Time 8 emulation", v11, *v9, v10);
Log_print("\t-nortime Disable R-Time 8 emulation", v11, v13, v14);
}
*(_QWORD *)(a2 + 8LL * v4++) = *v9;
}
else
{
RTIME_enabled = 0;
}
}
++v5;
}
while ( *a1 > v5 );
}
*a1 = v4;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(int *a1, __int64 a2)
{
int v4; // er15
int v5; // ebx
bool v6; // r9
bool v7; // cf
bool v8; // zf
const char **v9; // rbp
__int64 v10; // rcx
const char *v11; // rsi
const char *v12; // rdi
__int64 v13; // rdx
__int64 v14; // rcx

if ( *a1 <= 1 )
{
v4 = 1;
}
else
{
v4 = 1;
v5 = 1;
do
{
v9 = (const char **)(a2 + 8LL * v5);
if ( !strcmp(*v9, "-rtime") )
{
RTIME_enabled = 1;
}
else
{
v6 = strcmp(*v9, "-nortime") != 0;
v7 = 0;
v8 = !v6;
if ( v6 )
{
v10 = 6LL;
v11 = *v9;
v12 = "-help";
do
{
if ( !v10 )
break;
v7 = *v11 < (unsigned int)*v12;
v8 = *v11++ == *v12++;
--v10;
}
while ( v8 );
if ( (!v7 && !v8) == v7 )
{
Log_print("\t-rtime Enable R-Time 8 emulation", v11, *v9, v10);
Log_print("\t-nortime Disable R-Time 8 emulation", v11, v13, v14);
}
*(_QWORD *)(a2 + 8LL * v4++) = *v9;
}
else
{
RTIME_enabled = 0;
}
}
++v5;
}
while ( *a1 > v5 );
}
*a1 = v4;
return 1LL;
}

original_code:
int RTIME_Initialise(int *argc, char *argv[])
{
 int i;
 int j;
 for (i = j = 1; i < *argc; i++) {
  if (strcmp(argv[i], "-rtime") == 0)
   RTIME_enabled = 1;
  else if (strcmp(argv[i], "-nortime") == 0)
   RTIME_enabled = 0;
  else {
   if (strcmp(argv[i], "-help") == 0) {
    Log_print("\t-rtime           Enable R-Time 8 emulation");
    Log_print("\t-nortime         Disable R-Time 8 emulation");
   }
   argv[j++] = argv[i];
  }
 }
 *argc = j;
 return 1;
}

variable_types:
argc
int *

variable_types:
argv
char *[]

variable_types: i int

variable_types: j int


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

if ( rtime_state == 1 )
{
rtime_state = 2;
if ( rtime_tmp <= 6 )
result = (unsigned int)((int)gettime(rtime_tmp) >> 4);
else
result = (int)regset[rtime_tmp] >> 4;
}
else if ( rtime_state == 2 )
{
rtime_state = 0;
if ( rtime_tmp <= 6 )
result = gettime(rtime_tmp) & 0xF;
else
result = regset[rtime_tmp] & 0xF;
}
else
{
result = 0LL;
}
return result;
}

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

if ( rtime_state == 1 )
{
rtime_state = 2;
if ( rtime_tmp <= 6 )
result = (unsigned int)((int)func1(rtime_tmp) >> 4);
else
result = (int)regset[rtime_tmp] >> 4;
}
else if ( rtime_state == 2 )
{
rtime_state = 0;
if ( rtime_tmp <= 6 )
result = func1(rtime_tmp) & 0xF;
else
result = regset[rtime_tmp] & 0xF;
}
else
{
result = 0LL;
}
return result;
}

original_code:
unsigned char RTIME_GetByte(void)
{
 switch (rtime_state) {
 case 0:
  return 0;
 case 1:
  rtime_state = 2;
  return (
   rtime_tmp <= 6 ?
   gettime(rtime_tmp) :
   regset[rtime_tmp]) >> 4;
 case 2:
  rtime_state = 0;
  return (
   rtime_tmp <= 6 ?
   gettime(rtime_tmp) :
   regset[rtime_tmp]) & 0x0f;
 }
 return 0;
}

canonical_original_code:
unsigned char RTIME_GetByte()
{
 switch (rtime_state) {
 case 0:
  return 0;
 case 1:
  rtime_state = 2;
  return (
   rtime_tmp <= 6 ?
   gettime(rtime_tmp) :
   regset[rtime_tmp]) >> 4;
 case 2:
  rtime_state = 0;
  return (
   rtime_tmp <= 6 ?
   gettime(rtime_tmp) :
   regset[rtime_tmp]) & 0x0f;
 }
 return 0;
}

return_type: unsigned char


decompiled_code:
__int64 __fastcall RTIME_PutByte(unsigned __int8 a1)
{
__int64 result; // rax

result = (unsigned int)rtime_state;
switch ( rtime_state )
{
case 1:
rtime_tmp2 = 16 * a1;
rtime_state = 2;
break;
case 2:
regset[rtime_tmp] = rtime_tmp2 | a1 & 0xF;
rtime_state = 0;
break;
case 0:
rtime_tmp = a1 & 0xF;
rtime_state = 1;
break;
}
return result;
}

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

result = (unsigned int)rtime_state;
switch ( rtime_state )
{
case 1:
rtime_tmp2 = 16 * a1;
rtime_state = 2;
break;
case 2:
regset[rtime_tmp] = rtime_tmp2 | a1 & 0xF;
rtime_state = 0;
break;
case 0:
rtime_tmp = a1 & 0xF;
rtime_state = 1;
break;
}
return result;
}

original_code:
void RTIME_PutByte(unsigned char byte)
{
 switch (rtime_state) {
 case 0:
  rtime_tmp = byte & 0x0f;
  rtime_state = 1;
  break;
 case 1:
  rtime_tmp2 = byte << 4;
  rtime_state = 2;
  break;
 case 2:
  regset[rtime_tmp] = rtime_tmp2 | (byte & 0x0f);
  rtime_state = 0;
  break;
 }
}

variable_types:
byte
unsigned char

return_type: void


decompiled_code:
int __fastcall write32(unsigned int a1)
{
fputc((unsigned __int8)a1, sndoutput);
fputc(BYTE1(a1), sndoutput);
fputc(BYTE2(a1), sndoutput);
return fputc(HIBYTE(a1), sndoutput);
}

canonical_decompiled_code:
int __fastcall func0(unsigned int a1)
{
fputc((unsigned __int8)a1, sndoutput);
fputc(BYTE1(a1), sndoutput);
fputc(BYTE2(a1), sndoutput);
return fputc(HIBYTE(a1), sndoutput);
}

original_code:
static void write32(long x)
{
 fputc(x & 0xff, sndoutput);
 fputc((x >> 8) & 0xff, sndoutput);
 fputc((x >> 16) & 0xff, sndoutput);
 fputc((x >> 24) & 0xff, sndoutput);
}

variable_types: x long


decompiled_code:
_BOOL8 SndSave_IsSoundFileOpen()
{
return sndoutput != 0LL;
}

canonical_decompiled_code:
_BOOL8 func1()
{
return sndoutput != 0LL;
}

original_code:
int SndSave_IsSoundFileOpen(void)
{
 return sndoutput != ((void *)0);
}

canonical_original_code:
int SndSave_IsSoundFileOpen()
{
 return sndoutput != ((void *)0);
}

return_type: int


decompiled_code:
__int64 SndSave_CloseSoundFile()
{
unsigned int v0; // ebx
char v1; // bp

v0 = 1;
if ( sndoutput )
{
if ( (byteswritten & 1) != 0 )
{
v0 = 0;
v1 = 1;
if ( putc(0, sndoutput) == -1 )
{
LABEL_8:
fclose(sndoutput);
sndoutput = 0LL;
return v0;
}
}
else
{
v1 = 0;
}
v0 = fseek(sndoutput, 4LL, 0);
if ( v0 )
{
v0 = 0;
}
else
{
write32(byteswritten + v1 + 36);
if ( !fseek(sndoutput, 40LL, 0) )
{
write32(byteswritten);
v0 = 1;
}
}
goto LABEL_8;
}
return v0;
}

canonical_decompiled_code:
__int64 func2()
{
unsigned int v0; // ebx
char v1; // bp

v0 = 1;
if ( sndoutput )
{
if ( (byteswritten & 1) != 0 )
{
v0 = 0;
v1 = 1;
if ( putc(0, sndoutput) == -1 )
{
LABEL_8:
fclose(sndoutput);
sndoutput = 0LL;
return v0;
}
}
else
{
v1 = 0;
}
v0 = fseek(sndoutput, 4LL, 0);
if ( v0 )
{
v0 = 0;
}
else
{
func0(byteswritten + v1 + 36);
if ( !fseek(sndoutput, 40LL, 0) )
{
func0(byteswritten);
v0 = 1;
}
}
goto LABEL_8;
}
return v0;
}

original_code:
int SndSave_CloseSoundFile(void)
{
 int bSuccess = 1;
 char aligned = 0;
 if (sndoutput != ((void *)0)) {
  if (byteswritten & 1) {
   if (putc(0, sndoutput) == (-1))
    bSuccess = 0;
   else
    aligned = 1;
  }
  if (bSuccess) {
   if (fseek(sndoutput, 4, 0) != 0)
    bSuccess = 0;
   else {
    write32(byteswritten + 36 + aligned);
    if (fseek(sndoutput, 40, 0) != 0)
     bSuccess = 0;
    else {
     write32(byteswritten);
    }
   }
  }
  fclose(sndoutput);
  sndoutput = ((void *)0);
 }
 return bSuccess;
}

canonical_original_code:
int SndSave_CloseSoundFile()
{
 int bSuccess = 1;
 char aligned = 0;
 if (sndoutput != ((void *)0)) {
  if (byteswritten & 1) {
   if (putc(0, sndoutput) == (-1))
    bSuccess = 0;
   else
    aligned = 1;
  }
  if (bSuccess) {
   if (fseek(sndoutput, 4, 0) != 0)
    bSuccess = 0;
   else {
    write32(byteswritten + 36 + aligned);
    if (fseek(sndoutput, 40, 0) != 0)
     bSuccess = 0;
    else {
     write32(byteswritten);
    }
   }
  }
  fclose(sndoutput);
  sndoutput = ((void *)0);
 }
 return bSuccess;
}

variable_types: bSuccess int

variable_types: aligned char


decompiled_code:
__int64 __fastcall SndSave_OpenSoundFile(char *filename)
{
FILE *v1; // rcx
__int64 result; // rax
int v3; // edi
int v4; // edi

SndSave_CloseSoundFile();
v1 = fopen(filename, "wb");
sndoutput = v1;
result = 0LL;
if ( v1 )
{
if ( fwrite("RIFF", 1uLL, 0x16uLL, v1) == 22 )
{
fputc(POKEYSND_num_pokeys, sndoutput);
fputc(0, sndoutput);
write32(POKEYSND_playback_freq);
if ( (POKEYSND_snd_flags & 1) != 0 )
v3 = 2 * POKEYSND_num_pokeys;
else
v3 = POKEYSND_num_pokeys;
write32(POKEYSND_playback_freq * v3);
if ( (POKEYSND_snd_flags & 1) != 0 )
v4 = 2 * POKEYSND_num_pokeys;
else
v4 = POKEYSND_num_pokeys;
fputc(v4, sndoutput);
fputc(0, sndoutput);
fputc((POKEYSND_snd_flags & 1) == 0 ? 8 : 16, sndoutput);
if ( fwrite(&unk_34A, 1uLL, 9uLL, sndoutput) == 9 )
{
byteswritten = 0;
result = 1LL;
}
else
{
fclose(sndoutput);
sndoutput = 0LL;
result = 0LL;
}
}
else
{
fclose(sndoutput);
sndoutput = 0LL;
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *filename)
{
FILE *v1; // rcx
__int64 result; // rax
int v3; // edi
int v4; // edi

func2();
v1 = fopen(filename, "wb");
sndoutput = v1;
result = 0LL;
if ( v1 )
{
if ( fwrite("RIFF", 1uLL, 0x16uLL, v1) == 22 )
{
fputc(POKEYSND_num_pokeys, sndoutput);
fputc(0, sndoutput);
func0(POKEYSND_playback_freq);
if ( (POKEYSND_snd_flags & 1) != 0 )
v3 = 2 * POKEYSND_num_pokeys;
else
v3 = POKEYSND_num_pokeys;
func0(POKEYSND_playback_freq * v3);
if ( (POKEYSND_snd_flags & 1) != 0 )
v4 = 2 * POKEYSND_num_pokeys;
else
v4 = POKEYSND_num_pokeys;
fputc(v4, sndoutput);
fputc(0, sndoutput);
fputc((POKEYSND_snd_flags & 1) == 0 ? 8 : 16, sndoutput);
if ( fwrite(&unk_34A, 1uLL, 9uLL, sndoutput) == 9 )
{
byteswritten = 0;
result = 1LL;
}
else
{
fclose(sndoutput);
sndoutput = 0LL;
result = 0LL;
}
}
else
{
fclose(sndoutput);
sndoutput = 0LL;
result = 0LL;
}
}
return result;
}

original_code:
int SndSave_OpenSoundFile(const char *szFileName)
{
 SndSave_CloseSoundFile();
 sndoutput = fopen(szFileName, "wb");
 if (sndoutput == ((void *)0))
  return 0;
 if (fwrite("RIFF\0\0\0\0WAVEfmt \x10\0\0\0\1\0", 1, 22, sndoutput) != 22) {
  fclose(sndoutput);
  sndoutput = ((void *)0);
  return 0;
 }
 fputc(POKEYSND_num_pokeys, sndoutput);
 fputc(0, sndoutput);
 write32(POKEYSND_playback_freq);
 write32(POKEYSND_playback_freq * (POKEYSND_snd_flags & 1 ? POKEYSND_num_pokeys << 1 : POKEYSND_num_pokeys));
 fputc(POKEYSND_snd_flags & 1 ? POKEYSND_num_pokeys << 1 : POKEYSND_num_pokeys, sndoutput);
 fputc(0, sndoutput);
 fputc(POKEYSND_snd_flags & 1? 16: 8, sndoutput);
 if (fwrite("\0data\0\0\0\0", 1, 9, sndoutput) != 9) {
  fclose(sndoutput);
  sndoutput = ((void *)0);
  return 0;
 }
 byteswritten = 0;
 return 1;
}

canonical_original_code:
int SndSave_OpenSoundFile(char *szFileName)
{
 SndSave_CloseSoundFile();
 sndoutput = fopen(szFileName, "wb");
 if (sndoutput == ((void *)0))
  return 0;
 if (fwrite("RIFF\0\0\0\0WAVEfmt \x10\0\0\0\1\0", 1, 22, sndoutput) != 22) {
  fclose(sndoutput);
  sndoutput = ((void *)0);
  return 0;
 }
 fputc(POKEYSND_num_pokeys, sndoutput);
 fputc(0, sndoutput);
 write32(POKEYSND_playback_freq);
 write32(POKEYSND_playback_freq * (POKEYSND_snd_flags & 1 ? POKEYSND_num_pokeys << 1 : POKEYSND_num_pokeys));
 fputc(POKEYSND_snd_flags & 1 ? POKEYSND_num_pokeys << 1 : POKEYSND_num_pokeys, sndoutput);
 fputc(0, sndoutput);
 fputc(POKEYSND_snd_flags & 1? 16: 8, sndoutput);
 if (fwrite("\0data\0\0\0\0", 1, 9, sndoutput) != 9) {
  fclose(sndoutput);
  sndoutput = ((void *)0);
  return 0;
 }
 byteswritten = 0;
 return 1;
}

variable_types:
szFileName
char *


decompiled_code:
__int64 __fastcall SndSave_WriteToSoundFile(const void *a1, unsigned int a2)
{
unsigned int v2; // ebx
unsigned int v3; // ebp

v2 = 0;
if ( sndoutput )
{
if ( a1 && a2 )
{
v3 = 2 * a2;
if ( (POKEYSND_snd_flags & 1) == 0 )
v3 = a2;
v2 = fwrite(a1, 1uLL, v3, sndoutput);
byteswritten += v2;
if ( v2 != v3 )
SndSave_CloseSoundFile();
}
else
{
v2 = 0;
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func4(const void *a1, unsigned int a2)
{
unsigned int v2; // ebx
unsigned int v3; // ebp

v2 = 0;
if ( sndoutput )
{
if ( a1 && a2 )
{
v3 = 2 * a2;
if ( (POKEYSND_snd_flags & 1) == 0 )
v3 = a2;
v2 = fwrite(a1, 1uLL, v3, sndoutput);
byteswritten += v2;
if ( v2 != v3 )
func2();
}
else
{
v2 = 0;
}
}
return v2;
}

original_code:
int SndSave_WriteToSoundFile(const unsigned char *ucBuffer, unsigned int uiSize)
{
 if (sndoutput && ucBuffer && uiSize) {
  int result;
  if (POKEYSND_snd_flags & 1)
   uiSize <<= 1;
  result = fwrite(ucBuffer, 1, uiSize, sndoutput);
  byteswritten += result;
  if (result != uiSize) {
   SndSave_CloseSoundFile();
  }
  return result;
 }
 return 0;
}

canonical_original_code:
int SndSave_WriteToSoundFile(unsigned char *ucBuffer, unsigned int uiSize)
{
 if (sndoutput && ucBuffer && uiSize) {
  int result;
  if (POKEYSND_snd_flags & 1)
   uiSize <<= 1;
  result = fwrite(ucBuffer, 1, uiSize, sndoutput);
  byteswritten += result;
  if (result != uiSize) {
   SndSave_CloseSoundFile();
  }
  return result;
 }
 return 0;
}

variable_types:
ucBuffer
unsigned char *

variable_types:
uiSize
unsigned int

variable_types: result int


repo: cloudius-systems/glibc-testsuite

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

for ( result = temp_name_list; temp_name_list; result = temp_name_list )
{
remove((const char *)result[3]);
temp_name_list = (_QWORD *)*temp_name_list;
}
return result;
}

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

for ( result = temp_name_list; temp_name_list; result = temp_name_list )
{
remove((const char *)result[3]);
temp_name_list = (_QWORD *)*temp_name_list;
}
return result;
}

original_code:
static void
delete_temp_files (void)
{
  while (temp_name_list != ((void *)0))
    {
      remove (temp_name_list->name);
      temp_name_list = (struct temp_name_list *) temp_name_list->q.q_forw;
    }
}

canonical_original_code:
static void delete_temp_files()
{
  while (temp_name_list != ((void *)0))
    {
      remove (temp_name_list->name);
      temp_name_list = (struct temp_name_list *) temp_name_list->q.q_forw;
    }
}

user_defined_types: struct temp_name_list { struct qelem q; char *name; }

user_defined_types: struct qelem { struct qelem *q_forw; struct qelem *q_back; char q_data[1]; }


decompiled_code:
__int64 do_test()
{
unsigned int v0; // ebx
clockid_t clock_id[3]; // [rsp+Ch] [rbp-Ch] BYREF

v0 = clock_test(0);
if ( clock_getcpuclockid(0, clock_id) )
puts("CPU clock unavailble, skipping test");
else
clock_test(clock_id[0]);
return v0;
}

canonical_decompiled_code:
__int64 func8()
{
unsigned int v0; // ebx
clockid_t clock_id[3]; // [rsp+Ch] [rbp-Ch] BYREF

v0 = func7(0);
if ( clock_getcpuclockid(0, clock_id) )
puts("CPU clock unavailble, skipping test");
else
func7(clock_id[0]);
return v0;
}

original_code:
static int
do_test (void)
{
  pthread_mutex_t m;
  int e = pthread_mutex_init (&m, ((void *)0));
  if (((void *)0) != ((void *)0) && e == 95)
    {
      puts ("cannot support selected type of mutexes");
      return 0;
    }
  else if (e != 0)
    {
      puts ("mutex_init failed");
      return 1;
    }
  if (((void *)0) != ((void *)0) && pthread_mutexattr_destroy (((void *)0)) != 0)
    {
      puts ("mutexattr_destroy failed");
      return 1;
    }
  if (pthread_mutex_lock (&m) != 0)
    {
      puts ("mutex_lock failed");
      return 1;
    }
  if (pthread_mutex_unlock (&m) != 0)
    {
      puts ("mutex_unlock failed");
      return 1;
    }
  if (pthread_mutex_destroy (&m) != 0)
    {
      puts ("mutex_destroy failed");
      return 1;
    }
  return 0;
}

canonical_original_code:
static int do_test()
{
  union pthread_mutex_t m;
  int e = pthread_mutex_init (&m, ((void *)0));
  if (((void *)0) != ((void *)0) && e == 95)
    {
      puts ("cannot support selected type of mutexes");
      return 0;
    }
  else if (e != 0)
    {
      puts ("mutex_init failed");
      return 1;
    }
  if (((void *)0) != ((void *)0) && pthread_mutexattr_destroy (((void *)0)) != 0)
    {
      puts ("mutexattr_destroy failed");
      return 1;
    }
  if (pthread_mutex_lock (&m) != 0)
    {
      puts ("mutex_lock failed");
      return 1;
    }
  if (pthread_mutex_unlock (&m) != 0)
    {
      puts ("mutex_unlock failed");
      return 1;
    }
  if (pthread_mutex_destroy (&m) != 0)
    {
      puts ("mutex_destroy failed");
      return 1;
    }
  return 0;
}

variable_types: union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; }

variable_types: e int

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
char *v4; // rax
const char *v5; // rbp
char *v7; // rax
char *endptr; // [rsp+8h] [rbp-20h] BYREF

mallopt(-6, 42);
setbuf(stdout, 0LL);
while ( 1 )
{
v3 = getopt_long(argc, (char *const *)argv, "+", &options, 0LL);
if ( v3 == -1 )
break;
if ( v3 == 63 )
exit(1);
if ( v3 == 1001 )
test_dir = optarg;
}
v4 = getenv("TIMEOUTFACTOR");
if ( v4 )
{
endptr = v4;
strtoul(v4, &endptr, 0);
}
v5 = test_dir;
if ( test_dir )
{
setenv("TMPDIR", test_dir, 1);
if ( chdir(v5) < 0 )
{
perror("chdir");
exit(1);
}
}
else
{
v7 = getenv("TMPDIR");
test_dir = v7;
if ( !v7 || !*v7 )
test_dir = "/tmp";
}
setvbuf(stdout, 0LL, 2, 0LL);
atexit(delete_temp_files);
argv[optind - 1] = *argv;
return do_test();
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
char *v4; // rax
const char *v5; // rbp
char *v7; // rax
char *endptr; // [rsp+8h] [rbp-20h] BYREF

mallopt(-6, 42);
setbuf(stdout, 0LL);
while ( 1 )
{
v3 = getopt_long(argc, (char *const *)argv, "+", &options, 0LL);
if ( v3 == -1 )
break;
if ( v3 == 63 )
exit(1);
if ( v3 == 1001 )
test_dir = optarg;
}
v4 = getenv("TIMEOUTFACTOR");
if ( v4 )
{
endptr = v4;
strtoul(v4, &endptr, 0);
}
v5 = test_dir;
if ( test_dir )
{
setenv("TMPDIR", test_dir, 1);
if ( chdir(v5) < 0 )
{
perror("chdir");
exit(1);
}
}
else
{
v7 = getenv("TMPDIR");
test_dir = v7;
if ( !v7 || !*v7 )
test_dir = "/tmp";
}
setvbuf(stdout, 0LL, 2, 0LL);
func9(delete_temp_files);
argv[optind - 1] = *argv;
return func8();
}

original_code:
int
main (int argc, char *argv[])
{
  int direct = 1;
  int status;
  int opt;
  unsigned int timeoutfactor = 1;
  pid_t termpid;
  mallopt (-6, 42);
  while ((opt = getopt_long (argc, argv, "+", options, ((void *)0))) != -1)
    switch (opt)
      {
      case '?':
 exit (1);
      case 1000:
 direct = 1;
 break;
      case 1001:
 test_dir = optarg;
 break;
      }
  char *envstr_timeoutfactor = getenv ("TIMEOUTFACTOR");
  if (envstr_timeoutfactor != ((void *)0))
    {
      char *envstr_conv = envstr_timeoutfactor;
      unsigned long int env_fact;
      env_fact = strtoul (envstr_timeoutfactor, &envstr_conv, 0);
      if (*envstr_conv == '\0' && envstr_conv != envstr_timeoutfactor)
 timeoutfactor = (((env_fact)>(1))?(env_fact):(1));
    }
  if (test_dir != ((void *)0))
    {
      setenv ("TMPDIR", test_dir, 1);
      if (chdir (test_dir) < 0)
 {
   perror ("chdir");
   exit (1);
 }
    }
  else
    {
      test_dir = getenv ("TMPDIR");
      if (test_dir == ((void *)0) || test_dir[0] == '\0')
 test_dir = "/tmp";
    }
  setvbuf (stdout, ((void *)0), 2, 0);
  atexit (delete_temp_files);
  argv[optind - 1] = argv[0];
  argv += optind - 1;
  argc -= optind - 1;
  if (direct)
    return do_test ();
  pid = fork ();
  if (pid == 0)
    {
      struct rlimit core_limit;
      core_limit.rlim_cur = 0;
      core_limit.rlim_max = 0;
      setrlimit (RLIMIT_CORE, &core_limit);
      struct rlimit data_limit;
      if (getrlimit (RLIMIT_DATA, &data_limit) == 0)
 {
   if ((64 << 20) == ((__rlim_t) -1))
     data_limit.rlim_cur = data_limit.rlim_max;
   else if (data_limit.rlim_cur > (rlim_t) (64 << 20))
     data_limit.rlim_cur = ((((rlim_t) (64 << 20))<(data_limit.rlim_max))?((rlim_t) (64 << 20)):(data_limit.rlim_max));
   if (setrlimit (RLIMIT_DATA, &data_limit) < 0)
     perror ("setrlimit: RLIMIT_DATA");
 }
      else
 perror ("getrlimit: RLIMIT_DATA");
      setpgid (0, 0);
      exit (do_test ());
    }
  else if (pid < 0)
    {
      perror ("Cannot fork test program");
      exit (1);
    }
  signal (14, signal_handler);
  alarm (2 * timeoutfactor);
  signal (2, signal_handler);
  termpid = (__extension__ ({ long int __result; do __result = (long int) (waitpid (pid, &status, 0)); while (__result == -1L && (*__errno_location ()) == 4); __result; }));
  if (termpid == -1)
    {
      printf ("Waiting for test program failed: %m\n");
      exit (1);
    }
  if (termpid != pid)
    {
      printf ("Oops, wrong test program terminated: expected %ld, got %ld\n",
       (long int) pid, (long int) termpid);
      exit (1);
    }
  if (((status) & 0x7f) != 0)
    {
      if (0 != 0)
 {
   if (((status) & 0x7f) == 0)
     fprintf (stderr,
       "Expected signal '%s' from child, got none\n",
       strsignal (0));
   else
     fprintf (stderr,
       "Incorrect signal from child: got `%s', need `%s'\n",
       strsignal (((status) & 0x7f)),
       strsignal (0));
 }
      else
 fprintf (stderr, "Didn't expect signal from child: got `%s'\n",
   strsignal (((status) & 0x7f)));
      exit (1);
    }
  return (((status) & 0xff00) >> 8);
}

canonical_original_code:
int main(int argc, char *argv[])
{
  int direct = 1;
  int status;
  int opt;
  unsigned int timeoutfactor = 1;
  int termpid;
  mallopt (-6, 42);
  while ((opt = getopt_long (argc, argv, "+", options, ((void *)0))) != -1)
    switch (opt)
      {
      case '?':
 exit (1);
      case 1000:
 direct = 1;
 break;
      case 1001:
 test_dir = optarg;
 break;
      }
  char *envstr_timeoutfactor = getenv ("TIMEOUTFACTOR");
  if (envstr_timeoutfactor != ((void *)0))
    {
      char *envstr_conv = envstr_timeoutfactor;
      unsigned long env_fact;
      env_fact = strtoul (envstr_timeoutfactor, &envstr_conv, 0);
      if (*envstr_conv == '\0' && envstr_conv != envstr_timeoutfactor)
 timeoutfactor = (((env_fact)>(1))?(env_fact):(1));
    }
  if (test_dir != ((void *)0))
    {
      setenv ("TMPDIR", test_dir, 1);
      if (chdir (test_dir) < 0)
 {
   perror ("chdir");
   exit (1);
 }
    }
  else
    {
      test_dir = getenv ("TMPDIR");
      if (test_dir == ((void *)0) || test_dir[0] == '\0')
 test_dir = "/tmp";
    }
  setvbuf (stdout, ((void *)0), 2, 0);
  atexit (delete_temp_files);
  argv[optind - 1] = argv[0];
  argv += optind - 1;
  argc -= optind - 1;
  if (direct)
    return do_test ();
  pid = fork ();
  if (pid == 0)
    {
      struct rlimit core_limit;
      core_limit.rlim_cur = 0;
      core_limit.rlim_max = 0;
      setrlimit (RLIMIT_CORE, &core_limit);
      struct rlimit data_limit;
      if (getrlimit (RLIMIT_DATA, &data_limit) == 0)
 {
   if ((64 << 20) == ((__rlim_t) -1))
     data_limit.rlim_cur = data_limit.rlim_max;
   else if (data_limit.rlim_cur > (rlim_t) (64 << 20))
     data_limit.rlim_cur = ((((rlim_t) (64 << 20))<(data_limit.rlim_max))?((rlim_t) (64 << 20)):(data_limit.rlim_max));
   if (setrlimit (RLIMIT_DATA, &data_limit) < 0)
     perror ("setrlimit: RLIMIT_DATA");
 }
      else
 perror ("getrlimit: RLIMIT_DATA");
      setpgid (0, 0);
      exit (do_test ());
    }
  else if (pid < 0)
    {
      perror ("Cannot fork test program");
      exit (1);
    }
  signal (14, signal_handler);
  alarm (2 * timeoutfactor);
  signal (2, signal_handler);
  termpid = (__extension__ ({ long __result; do __result = (long) (waitpid (pid, &status, 0)); while (__result == -1L && (*__errno_location ()) == 4); __result; }));
  if (termpid == -1)
    {
      printf ("Waiting for test program failed: %m\n");
      exit (1);
    }
  if (termpid != pid)
    {
      printf ("Oops, wrong test program terminated: expected %ld, got %ld\n",
       (long) pid, (long) termpid);
      exit (1);
    }
  if (((status) & 0x7f) != 0)
    {
      if (0 != 0)
 {
   if (((status) & 0x7f) == 0)
     fprintf (stderr,
       "Expected signal '%s' from child, got none\n",
       strsignal (0));
   else
     fprintf (stderr,
       "Incorrect signal from child: got `%s', need `%s'\n",
       strsignal (((status) & 0x7f)),
       strsignal (0));
 }
      else
 fprintf (stderr, "Didn't expect signal from child: got `%s'\n",
   strsignal (((status) & 0x7f)));
      exit (1);
    }
  return (((status) & 0xff00) >> 8);
}

variable_types: argc int

variable_types: direct int

variable_types: status int

variable_types: opt int

variable_types:
timeoutfactor
unsigned int

variable_types: termpid int

variable_types: struct rlimit { unsigned long rlim_cur; unsigned long rlim_max; }


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int *v3; // rbx
void *v4; // rbx
void *v5; // rbx
void *v6; // rbx

v3 = __errno_location();
*v3 = 0;
if ( malloc(0xFFFFFFFFFFFFFFFFLL) )
{
merror("malloc (-1) succeeded.");
}
else if ( *v3 != 12 )
{
merror("errno is not set correctly");
}
v4 = malloc(0xAuLL);
if ( !v4 )
merror("malloc (10) failed.");
if ( realloc(v4, 0LL) )
merror("realloc (p, 0) failed.");
v5 = malloc(0LL);
if ( !v5 )
merror("malloc (0) failed.");
if ( realloc(v5, 0LL) )
merror("realloc (p, 0) failed.");
v6 = malloc(0x80400uLL);
if ( !v6 )
merror("malloc (513K) failed.");
if ( malloc(0xFFFFFFFFFFF80000LL) )
merror("malloc (-512K) succeeded.");
free(v6);
return errors != 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int *v3; // rbx
void *v4; // rbx
void *v5; // rbx
void *v6; // rbx

v3 = __errno_location();
*v3 = 0;
if ( malloc(0xFFFFFFFFFFFFFFFFLL) )
{
func6("malloc (-1) succeeded.");
}
else if ( *v3 != 12 )
{
func6("errno is not set correctly");
}
v4 = malloc(0xAuLL);
if ( !v4 )
func6("malloc (10) failed.");
if ( realloc(v4, 0LL) )
func6("realloc (p, 0) failed.");
v5 = malloc(0LL);
if ( !v5 )
func6("malloc (0) failed.");
if ( realloc(v5, 0LL) )
func6("realloc (p, 0) failed.");
v6 = malloc(0x80400uLL);
if ( !v6 )
func6("malloc (513K) failed.");
if ( malloc(0xFFFFFFFFFFF80000LL) )
func6("malloc (-512K) succeeded.");
free(v6);
return errors != 0;
}

variable_types:
argv
char *[]

user_defined_types: struct rlimit { unsigned long rlim_cur; unsigned long rlim_max; }


repo: cloudsec/wos

decompiled_code:
__int64 __fastcall set_gdt_desc(__int64 a1, int a2, int a3, int a4, int a5)
{
return _set_gdt_desc(a1, a2, a3, 12, a4, a5);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2, int a3, int a4, int a5)
{
return func0(a1, a2, a3, 12, a4, a5);
}

original_code:
void set_gdt_desc(struct gdt_desc *addr, unsigned int base, unsigned int limit,
                int type, int idx)
{
        __set_gdt_desc(addr, base, limit, 0xc, type, idx);
}

variable_types: struct gdt_desc { unsigned int a; unsigned int b; } *

variable_types:
base
unsigned int

variable_types:
limit
unsigned int

variable_types: type int

variable_types: idx int


decompiled_code:
__int64 __fastcall set_ldt_desc(__int64 a1, int a2, int a3, int a4, int a5)
{
return _set_gdt_desc(a1, a2, a3, 0, a4, a5);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int a2, int a3, int a4, int a5)
{
return func0(a1, a2, a3, 0, a4, a5);
}

original_code:
void set_ldt_desc(struct gdt_desc *addr, unsigned int base, unsigned int limit,
                int type, int idx)
{
        __set_gdt_desc(addr, base, limit, 0x0, type, idx);
}

user_defined_types: struct gdt_desc { unsigned int a; unsigned int b; }


decompiled_code:
__int64 __fastcall set_tss_desc(__int64 a1, int a2, int a3, int a4, int a5)
{
return _set_gdt_desc(a1, a2, a3, 0, a4, a5);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int a2, int a3, int a4, int a5)
{
return func0(a1, a2, a3, 0, a4, a5);
}

original_code:
void set_tss_desc(struct gdt_desc *addr, unsigned int base, unsigned int limit,
                int type, int idx)
{
        __set_gdt_desc(addr, base, limit, 0x0, type, idx);
}


original_code:
void setup_gdt(void)
{
        set_gdt_desc(new_gdt, 0x0, 0xffffffff, 0x9a, 0x1);
        set_gdt_desc(new_gdt, 0x0, 0xffffffff, 0x92, 0x2);
        set_gdt_desc(new_gdt, 0xb8000, 0xffff, 0xf2, 0x3);
}

canonical_original_code:
void setup_gdt()
{
        set_gdt_desc(new_gdt, 0x0, 0xffffffff, 0x9a, 0x1);
        set_gdt_desc(new_gdt, 0x0, 0xffffffff, 0x92, 0x2);
        set_gdt_desc(new_gdt, 0xb8000, 0xffff, 0xf2, 0x3);
}


decompiled_code:
__int64 print_init_ldt_list()
{
unsigned int *v0; // rbx
__int64 result; // rax

printk("\nInit init_task ldt table:\n");
v0 = (unsigned int *)&init_task;
do
{
result = printk("0x%x, 0x%x\n", v0[29], v0[28]);
v0 += 2;
}
while ( v0 != (unsigned int *)(unsigned int)((_DWORD)&init_task + 24) );
return result;
}

canonical_decompiled_code:
__int64 func5()
{
unsigned int *v0; // rbx
__int64 result; // rax

printk("\nInit init_task ldt table:\n");
v0 = (unsigned int *)&init_task;
do
{
result = printk("0x%x, 0x%x\n", v0[29], v0[28]);
v0 += 2;
}
while ( v0 != (unsigned int *)(unsigned int)((_DWORD)&init_task + 24) );
return result;
}

original_code:
void print_init_ldt_list(void)
{
        int i = 0;
        printk("\nInit init_task ldt table:\n");
        for (i = 0; i < 3; i++)
                printk("0x%x, 0x%x\n", init_task.ldt[i].b, init_task.ldt[i].a);
}

canonical_original_code:
void print_init_ldt_list()
{
        int i = 0;
        printk("\nInit init_task ldt table:\n");
        for (i = 0; i < 3; i++)
                printk("0x%x, 0x%x\n", init_task.ldt[i].b, init_task.ldt[i].a);
}

variable_types: i int


decompiled_code:
__int64 print_gdt_list()
{
unsigned int *v0; // rbx
__int64 result; // rax

printk("\nGdt Table:\n");
v0 = (unsigned int *)&new_gdt;
do
{
result = printk("0x%x, 0x%x\n", v0[3], v0[2]);
v0 += 2;
}
while ( v0 != (unsigned int *)(unsigned int)((_DWORD)&new_gdt + 24) );
return result;
}

canonical_decompiled_code:
__int64 func6()
{
unsigned int *v0; // rbx
__int64 result; // rax

printk("\nGdt Table:\n");
v0 = (unsigned int *)&new_gdt;
do
{
result = printk("0x%x, 0x%x\n", v0[3], v0[2]);
v0 += 2;
}
while ( v0 != (unsigned int *)(unsigned int)((_DWORD)&new_gdt + 24) );
return result;
}

original_code:
void print_gdt_list(void)
{
        int i = 0;
        printk("\nGdt Table:\n");
        for (i = 1; i <= 3; i++)
                printk("0x%x, 0x%x\n", new_gdt[i].b, new_gdt[i].a);
}

canonical_original_code:
void print_gdt_list()
{
        int i = 0;
        printk("\nGdt Table:\n");
        for (i = 1; i <= 3; i++)
                printk("0x%x, 0x%x\n", new_gdt[i].b, new_gdt[i].a);
}


itoa

original_code:
char *itoa(int num, char *str, int radix)
{
        char string[] = "0123456789abcdefghijklmnopqrstuvwxyz";
        char *s = str, *p;
        char tmp;
        if (num < 0)
                return (void *)0;
        if (!num) {
                *s++ = '\0';
                *s = 0;
                return s;
        }
        while (num) {
                *s++ = string[num % radix];
                num /= radix;
        }
        *s = 0;
        --s;
        for (p = str; p < s; s--, p++) {
                tmp = *p;
                *p = *s;
                *s = tmp;
        }
        return s;
}

canonical_original_code:
char *itoa(int num, char *str, int radix)
{
        char string[] = "0123456789abcdefghijklmnopqrstuvwxyz";
        char *s = str; char *p;
        char tmp;
        if (num < 0)
                return (void *)0;
        if (!num) {
                *s++ = '\0';
                *s = 0;
                return s;
        }
        while (num) {
                *s++ = string[num % radix];
                num /= radix;
        }
        *s = 0;
        --s;
        for (p = str; p < s; s--, p++) {
                tmp = *p;
                *p = *s;
                *s = tmp;
        }
        return s;
}

variable_types: num int

variable_types:
str
char *

variable_types: radix int

variable_types:
string
char []

variable_types:
s
char *

variable_types:
p
char *

variable_types: tmp char

return_type: char *


strlen

decompiled_code:
__int64 __fastcall strlen(__int64 a1)
{
__int64 v1; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
v1 = a1;
do
++v1;
while ( *(_BYTE *)(v1 - 1) );
return (unsigned int)(v1 - a1 - 1);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 v1; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
v1 = a1;
do
++v1;
while ( *(_BYTE *)(v1 - 1) );
return (unsigned int)(v1 - a1 - 1);
}

original_code:
int strlen(char *str)
{
 char *s = str;
 if (!s)
  return -1;
 while (*s++);
 return (int)(s - str - 1);
}


strcmp

decompiled_code:
__int64 __fastcall strcmp(char *a1, char *a2)
{
char v2; // cl
char v3; // dl
__int64 v4; // rax
__int64 result; // rax

v2 = *a1;
v3 = *a2;
if ( *a1 == *a2 )
{
v4 = 1LL;
do
{
v2 = a1[v4++];
v3 = a2[v4 - 1];
}
while ( v2 == v3 );
}
result = 1LL;
if ( v2 <= v3 )
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *a1, char *a2)
{
char v2; // cl
char v3; // dl
__int64 v4; // rax
__int64 result; // rax

v2 = *a1;
v3 = *a2;
if ( *a1 == *a2 )
{
v4 = 1LL;
do
{
v2 = a1[v4++];
v3 = a2[v4 - 1];
}
while ( v2 == v3 );
}
result = 1LL;
if ( v2 <= v3 )
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int strcmp(char *src, char *dst)
{
 char *s = src, *p = dst;
 while (*s == *p) {
  s++;p++;
 }
 if (*s == *p)
  return 0;
 if (*s > *p)
  return 1;
 if (*s < *p)
  return -1;
}

canonical_original_code:
int strcmp(char *src, char *dst)
{
 char *s = src; char *p = dst;
 while (*s == *p) {
  s++;p++;
 }
 if (*s == *p)
  return 0;
 if (*s > *p)
  return 1;
 if (*s < *p)
  return -1;
}

variable_types:
src
char *

variable_types:
dst
char *


strncmp

decompiled_code:
__int64 __fastcall strncmp(char *a1, char *a2, int a3)
{
char v5; // cl
char v6; // dl
__int64 v7; // rax
bool v8; // di
__int64 result; // rax

v5 = *a1;
v6 = *a2;
if ( a3 > 0 && v5 == v6 )
{
v7 = 1LL;
do
{
v5 = a1[v7];
v6 = a2[v7];
v8 = a3 > (int)v7++;
}
while ( v5 == v6 && v8 );
}
result = 0LL;
if ( v5 != v6 )
{
result = 1LL;
if ( v5 <= v6 )
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *a1, char *a2, int a3)
{
char v5; // cl
char v6; // dl
__int64 v7; // rax
bool v8; // di
__int64 result; // rax

v5 = *a1;
v6 = *a2;
if ( a3 > 0 && v5 == v6 )
{
v7 = 1LL;
do
{
v5 = a1[v7];
v6 = a2[v7];
v8 = a3 > (int)v7++;
}
while ( v5 == v6 && v8 );
}
result = 0LL;
if ( v5 != v6 )
{
result = 1LL;
if ( v5 <= v6 )
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int strncmp(char *src, char *dst, int n)
{
        char *s = src, *p = dst;
 int i = 0;
        while ((*s == *p) && i < n) {
                s++;p++;i++;
        }
        if (*s == *p)
                return 0;
        if (*s > *p)
                return 1;
        if (*s < *p)
                return -1;
}

canonical_original_code:
int strncmp(char *src, char *dst, int n)
{
        char *s = src; char *p = dst;
 int i = 0;
        while ((*s == *p) && i < n) {
                s++;p++;i++;
        }
        if (*s == *p)
                return 0;
        if (*s > *p)
                return 1;
        if (*s < *p)
                return -1;
}

variable_types: n int


memcpy

original_code:
void *memcpy(void *dst, void *src, int n)
{
        char *s = src, *p = dst;
        int i = 0;
        while (i < n) {
                *p++ = *s++;
                i++;
        }
}

canonical_original_code:
void *memcpy(void *dst, void *src, int n)
{
        char *s = src; char *p = dst;
        int i = 0;
        while (i < n) {
                *p++ = *s++;
                i++;
        }
}

variable_types:
dst
void *

variable_types:
src
void *

return_type: void *


memset

decompiled_code:
void __fastcall memset(_BYTE *a1, char a2, int a3)
{
_BYTE *v3; // rax

if ( a3 > 0 )
{
v3 = &a1[a3];
do
*a1++ = a2;
while ( a1 != v3 );
}
}

canonical_decompiled_code:
void __fastcall func5(_BYTE *a1, char a2, int a3)
{
_BYTE *v3; // rax

if ( a3 > 0 )
{
v3 = &a1[a3];
do
*a1++ = a2;
while ( a1 != v3 );
}
}

original_code:
void *memset(void *s, int c, int n)
{
 int i;
 char *p = s;
 for (i = 0; i < n; i++)
  *p++ = c;
}

variable_types:
s
void *

variable_types: c int


decompiled_code:
__int64 __fastcall sys_write_s(__int64 a1)
{
return printk(&unk_4F, a1);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return printk(&unk_4F, a1);
}

original_code:
int sys_write_s(char *msg)
{
 printk("%s", msg);
}

variable_types:
msg
char *


decompiled_code:
__int64 __fastcall sys_write_i(unsigned int a1)
{
return printk("!%d\n", a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1)
{
return printk("!%d\n", a1);
}

original_code:
int sys_write_i(int msg)
{
 printk("!%d\n", msg);
}

variable_types: msg int


decompiled_code:
int __fastcall sys_printf(FILE *a1, __int64 a2, void *a3)
{
char format[8]; // [rsp+10h] [rbp-8h] BYREF

return vfprintf(a1, format, a3);
}

canonical_decompiled_code:
int __fastcall func2(FILE *a1, __int64 a2, void *a3)
{
char format[8]; // [rsp+10h] [rbp-8h] BYREF

return vfprintf(a1, format, a3);
}

original_code:
int sys_printf(char *format, ...)
{
 char* arg;
 (arg = (char *)&format + sizeof(format));
 return vfprintf(format, arg);
}

canonical_original_code:
int sys_printf(char *format, ...)
{
 char *arg;
 (arg = (char *)&format + sizeof(format));
 return vfprintf(format, arg);
}

variable_types:
format
char *

variable_types:
arg
char *


decompiled_code:
void __fastcall add_timer(int a1, void (*a2)(void))
{
int v2; // eax
__int64 v3; // r12

if ( a2 )
{
if ( a1 )
{
_disable();
v2 = kmalloc(32LL);
if ( v2 )
{
v3 = v2;
printk("allocte new_timer struct at 0x%x\n", v2);
*(_DWORD *)v3 = a1;
*(_QWORD *)(v3 + 8) = a2;
list_add_tail((_QWORD *)(v3 + 16), &timer_list_head);
}
}
else
{
a2();
}
_enable();
}
}

canonical_decompiled_code:
void __fastcall func4(int a1, void (*a2)(void))
{
int v2; // eax
__int64 v3; // r12

if ( a2 )
{
if ( a1 )
{
_disable();
v2 = kmalloc(32LL);
if ( v2 )
{
v3 = v2;
printk("allocte new_timer struct at 0x%x\n", v2);
*(_DWORD *)v3 = a1;
*(_QWORD *)(v3 + 8) = a2;
func0((_QWORD *)(v3 + 16), &timer_list_head);
}
}
else
{
a2();
}
_enable();
}
}

original_code:
void add_timer(unsigned int jiffies, void (*fn)(void))
{
 struct timer_list *new_timer = (void *)0;
 if (!fn)
  return ;
 if (jiffies <= 0) {
  fn();
  goto out;
 }
 asm("cli\n"::);
 new_timer = (struct timer_list *)kmalloc(sizeof(struct timer_list));
 if (!new_timer)
  goto out;
 printk("allocte new_timer struct at 0x%x\n", new_timer);
 new_timer->jiffies = jiffies;
 new_timer->fn = fn;
 list_add_tail(&(new_timer->list), &timer_list_head);
out:
 asm("sti\n"::);
 return ;
}

canonical_original_code:
void add_timer(unsigned int jiffies, void (*fn)())
{
 struct timer_list *new_timer = (void *)0;
 if (!fn)
  return ;
 if (jiffies <= 0) {
  fn();
  goto out;
 }
 asm("cli\n"::);
 new_timer = (struct timer_list *)kmalloc(sizeof(struct timer_list));
 if (!new_timer)
  goto out;
 printk("allocte new_timer struct at 0x%x\n", new_timer);
 new_timer->jiffies = jiffies;
 new_timer->fn = fn;
 list_add_tail(&(new_timer->list), &timer_list_head);
out:
 asm("sti\n"::);
 return ;
}

variable_types:
jiffies
unsigned int

variable_types:
fn
void (*)()

variable_types: struct timer_list { unsigned int jiffies; void (*fn)(); struct list_head { struct list_head *prev; } list; } *

user_defined_types: struct timer_list { unsigned int jiffies; void (*fn)(); struct list_head list; }


decompiled_code:
__int64 do_timer()
{
__int64 *i; // rbx
__int64 result; // rax
int v2; // eax

for ( i = (__int64 *)*(&timer_list_head + 1); i != &timer_list_head; i = (__int64 *)i[1] )
{
v2 = *((_DWORD *)i - 4) - 1;
*((_DWORD *)i - 4) = v2;
if ( !v2 )
{
((void (*)(void))*(i - 1))();
list_del(i);
}
}
++timer_tick;
if ( !current
|| (result = (unsigned int)(*(_DWORD *)(current + 144) - 1), *(_DWORD *)(current + 144) = result, (int)result <= 0) )
{
result = schedule();
}
return result;
}

canonical_decompiled_code:
__int64 func5()
{
__int64 *i; // rbx
__int64 result; // rax
int v2; // eax

for ( i = (__int64 *)*(&timer_list_head + 1); i != &timer_list_head; i = (__int64 *)i[1] )
{
v2 = *((_DWORD *)i - 4) - 1;
*((_DWORD *)i - 4) = v2;
if ( !v2 )
{
((void (*)(void))*(i - 1))();
list_del(i);
}
}
++timer_tick;
if ( !current
|| (result = (unsigned int)(*(_DWORD *)(current + 144) - 1), *(_DWORD *)(current + 144) = result, (int)result <= 0) )
{
result = schedule();
}
return result;
}

original_code:
void do_timer(unsigned int esp)
{
 struct regs *reg = (struct regs *)esp;
 struct timer_list *s = (void *)0;
 struct list_head *p = (void *)0;
 for (p = (&timer_list_head)->next; p != (&timer_list_head); p = p->next) {
  s = ({ (struct timer_list *)((char * )p - (char *)&(((struct timer_list *)0x0)->list)); });;
  if (s && --(s->jiffies) <= 0) {
   s->fn();
   list_del(p);
  }
 }
 timer_tick++;
 if (current && --current->counter > 0)
  return ;
 ("pid: %d counter is 0.\n", current->pid);
 schedule();
}

variable_types:
esp
unsigned int

variable_types: struct regs { unsigned int ebx; unsigned int ecx; unsigned int edx; unsigned int esi; unsigned int edi; unsigned int ebp; unsigned int eax; unsigned int ds; unsigned int es; unsigned int fs; unsigned int error_code; unsigned int orig_eip; unsigned int orig_cs; unsigned int eflags; unsigned int esp; unsigned int ss; } *

variable_types: struct list_head { struct list_head *prev; } *


decompiled_code:
__int64 __fastcall init_timer(int a1)
{
unsigned __int8 v1; // al
__int64 result; // rax

*(&timer_list_head + 1) = (__int64)&timer_list_head;
timer_list_head = (__int64)&timer_list_head;
__outbyte(0x43u, 0x36u);
__outbyte(0x40u, 1193180 / a1);
__outbyte(0x40u, (unsigned __int16)(1193180 / a1) >> 8);
v1 = __inbyte(0x21u);
result = v1 & 0xFE;
__outbyte(0x21u, result);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1)
{
unsigned __int8 v1; // al
__int64 result; // rax

*(&timer_list_head + 1) = (__int64)&timer_list_head;
timer_list_head = (__int64)&timer_list_head;
__outbyte(0x43u, 0x36u);
__outbyte(0x40u, 1193180 / a1);
__outbyte(0x40u, (unsigned __int16)(1193180 / a1) >> 8);
v1 = __inbyte(0x21u);
result = v1 & 0xFE;
__outbyte(0x21u, result);
return result;
}

original_code:
void init_timer(int hz)
{
        unsigned int divisor = 1193180 / hz;
 do { (&timer_list_head)->next = (&timer_list_head); (&timer_list_head)->prev = (&timer_list_head); }while (0);
        asm("outb %%al, %%dx\n"::"a"(0x36),"d"(0x43));
        asm("outb %%al, %%dx\n"::"a"(divisor&0xff),"d"(0x40));
        asm("outb %%al, %%dx\n"::"a"(divisor>>8),"d"(0x40));
        asm("outb %%al, %%dx\n"::"a"(({ unsigned char ret; asm("inb %%dx, %%al\n":"=a"(ret):"d"(0x21)); ret; })&0xfe),"d"(0x21));
}

variable_types: hz int

variable_types:
divisor
unsigned int

variable_types:
ret
unsigned char


decompiled_code:
void timer_test()
{
add_timer(500, (void (*)(void))_timer_test);
add_timer(500, (void (*)(void))_timer_test1);
add_timer(200, (void (*)(void))_timer_test2);
}

canonical_decompiled_code:
void func7()
{
func4(500, (void (*)(void))_timer_test);
func4(500, (void (*)(void))_timer_test1);
func4(200, (void (*)(void))_timer_test2);
}

original_code:
void timer_test(void)
{
 add_timer(500, __timer_test);
 add_timer(500, __timer_test1);
 add_timer(200, __timer_test2);
}

canonical_original_code:
void timer_test()
{
 add_timer(500, __timer_test);
 add_timer(500, __timer_test1);
 add_timer(200, __timer_test2);
}


decompiled_code:
__int64 get_pid()
{
if ( last_pid > 1024 )
return 0xFFFFFFFFLL;
return (unsigned int)++last_pid;
}

canonical_decompiled_code:
__int64 func1()
{
if ( last_pid > 1024 )
return 0xFFFFFFFFLL;
return (unsigned int)++last_pid;
}

original_code:
int get_pid(void)
{
 int pid;
 if (last_pid > 1024)
  return -1;
 pid = ++last_pid;
 return pid;
}

canonical_original_code:
int get_pid()
{
 int pid;
 if (last_pid > 1024)
  return -1;
 pid = ++last_pid;
 return pid;
}

variable_types: pid int


original_code:
int do_fork(unsigned int esp)
{
 struct task_struct *tsk;
 struct regs *reg = (struct regs *)(esp + 4);
 int pid;
 ("cs: 0x%x, eip: 0x%x, ds: 0x%x, eax: 0x%x, ebx: 0x%x\n"
  "ecx: 0x%x, es: 0x%x, fs: 0x%x, eflags: 0x%x\n"
  "ss: 0x%x, esp: 0x%x, orig_eax: 0x%x\n",
  reg->orig_cs, reg->orig_eip, reg->ds, reg->eax, reg->ebx,
  reg->ecx, reg->es, reg->fs, reg->eflags,
  reg->ss, reg->esp, reg->error_code);
 pid = get_pid();
 if (pid == -1) {
  printk("Get new pid failed.\n");
  return -1;
 }
 ("Get new pid: %d\n", pid);
 tsk = (struct task_struct *)alloc_page(0);
 if (!tsk) {
  ("Alloc tsk page failed.\n");
  return -1;
 }
 printk("Alloc task_struct page at: 0x%x\n", tsk);
 *tsk = *current;
 tsk->tss.prev_task_link = 0;
 tsk->tss.esp0 = (unsigned int)tsk + (4*1024) - 4;
 tsk->tss.ss0 = 0x10;
 tsk->tss.esp1 = 0;
 tsk->tss.ss1 = 0;
 tsk->tss.esp2 = 0;
 tsk->tss.ss2 = 0;
 tsk->tss.eip = reg->orig_eip;
 tsk->tss.eflags = reg->eflags;
 tsk->tss.eax = 0;
 tsk->tss.ebx = reg->ebx;
 tsk->tss.ecx = reg->ecx;
 tsk->tss.edx = reg->edx;
 tsk->tss.esp = reg->esp;
 tsk->tss.ebp = reg->ebp;
 tsk->tss.esi = reg->esi;
 tsk->tss.edi = reg->edi;
 tsk->tss.es = reg->es;
 tsk->tss.cs = reg->orig_cs;
 tsk->tss.ss = reg->ss;
 tsk->tss.ds = reg->ds;
 tsk->tss.fs = reg->fs;
 tsk->tss.gs = 0x17;
 tsk->tss.ldt_sel = ((4 + 2*pid + 1) << 3);
 tsk->tss.io_map = 0x80000000;
 tsk->pid = pid;
 tsk->tss_sel = ((4 + 2*pid) << 3);
 tsk->ldt_sel = ((4 + 2*pid + 1) << 3);
 tsk->state = 0;
 tsk->counter = 15;
 tsk->priority = 200;
 set_tss_desc(new_gdt, (unsigned int)&(tsk->tss), 0x68, 0x89, (4 + 2*pid));
 set_ldt_desc(new_gdt, (unsigned int)&(tsk->ldt), 0x40, 0x82, (4 + 2*pid + 1));
 set_gdt_desc(tsk->ldt, 0x0, 0xffffffff, 0xfa, 1);
 set_gdt_desc(tsk->ldt, 0x0, 0xffffffff, 0xf2, 2);
 copy_page_tables(tsk);
 list_add_tail(&(tsk->list), &task_list_head);
 printk("task esp0: 0x%x, esp: 0x%x\n", tsk->tss.esp0, tsk->tss.esp);
 return pid;
}

variable_types: struct task_struct { struct tss_struct { unsigned int prev_task_link; unsigned int esp0; unsigned int ss0; unsigned int esp1; unsigned int ss1; unsigned int esp2; unsigned int ss2; unsigned int cr3; unsigned int eip; unsigned int eflags; unsigned int eax; unsigned int ecx; unsigned int edx; unsigned int ebx; unsigned int esp; unsigned int ebp; unsigned int esi; unsigned int edi; unsigned int es; unsigned int cs; unsigned int ss; unsigned int ds; unsigned int fs; unsigned int gs; unsigned int ldt_sel; unsigned int io_map; } tss; unsigned int tss_sel; unsigned int ldt_sel; struct gdt_desc { unsigned int a; unsigned int b; } ldt[3]; int pid; int state; int counter; int priority; struct list_head { struct list_head *prev; } list; } *

user_defined_types: struct task_struct { struct tss_struct tss; unsigned int tss_sel; unsigned int ldt_sel; struct gdt_desc ldt[3]; int pid; int state; int counter; int priority; struct list_head list; }

user_defined_types: struct regs { unsigned int ebx; unsigned int ecx; unsigned int edx; unsigned int esi; unsigned int edi; unsigned int ebp; unsigned int eax; unsigned int ds; unsigned int es; unsigned int fs; unsigned int error_code; unsigned int orig_eip; unsigned int orig_cs; unsigned int eflags; unsigned int esp; unsigned int ss; }


original_code:
int sys_creat_task(unsigned int eip)
{
        struct task_struct *tsk;
        int pid;
        pid = get_pid();
        if (pid == -1) {
                ("Get pid failed.\n");
                return -1;
        }
        printk("Get new pid: %d\n", pid);
        tsk = (struct task_struct *)alloc_page(0);
        if (!tsk) {
                ("Alloc tsk page failed.\n");
                return -1;
        }
        ("Alloc tsk page at: 0x%x\n", tsk);
 *tsk = *current;
        tsk->tss.prev_task_link = 0;
        tsk->tss.esp0 = (unsigned int)tsk + (4*1024);
        tsk->tss.ss0 = 0x10;
        tsk->tss.esp1 = 0;
        tsk->tss.ss1 = 0;
        tsk->tss.esp2 = 0;
        tsk->tss.ss2 = 0;
        tsk->tss.eip = eip;
        tsk->tss.eflags = 0x200;
        tsk->tss.eax = 0;
        tsk->tss.ebx = 0;
        tsk->tss.ecx = 0;
        tsk->tss.edx = 0;
        tsk->tss.esp = (unsigned int)alloc_page(0) + (4*1024);
 ("Alloc tsk ring3 stack at 0x%x\n", tsk->tss.esp - (4*1024));
        tsk->tss.ebp = 0;
        tsk->tss.esi = 0;
        tsk->tss.edi = 0;
        tsk->tss.es = 0x17;
        tsk->tss.cs = 0x0f;
        tsk->tss.ss = 0x17;
        tsk->tss.ds = 0x17;
        tsk->tss.fs = 0x17;
        tsk->tss.gs = 0x17;
        tsk->tss.ldt_sel = ((4 + 2*pid + 1) << 3);
        tsk->tss.io_map = 0x80000000;
        tsk->pid = pid;
        tsk->tss_sel = ((4 + 2*pid) << 3);
        tsk->ldt_sel = ((4 + 2*pid + 1) << 3);
        tsk->state = 0;
        tsk->counter = 15;
        tsk->priority = 200;
        set_tss_desc(new_gdt, (unsigned int)&(tsk->tss), 0x68, 0x89, (4 + 2*pid));
        set_ldt_desc(new_gdt, (unsigned int)&(tsk->ldt), 0x40, 0x82, (4 + 2*pid + 1));
        set_gdt_desc(tsk->ldt, 0x0, 0xffffffff, 0xfa, 1);
        set_gdt_desc(tsk->ldt, 0x0, 0xffffffff, 0xf2, 2);
 setup_task_pages(tsk);
        list_add_tail(&(tsk->list), &task_list_head);
 return 0;
}

variable_types:
eip
unsigned int

user_defined_types: struct tss_struct { unsigned int prev_task_link; unsigned int esp0; unsigned int ss0; unsigned int esp1; unsigned int ss1; unsigned int esp2; unsigned int ss2; unsigned int cr3; unsigned int eip; unsigned int eflags; unsigned int eax; unsigned int ecx; unsigned int edx; unsigned int ebx; unsigned int esp; unsigned int ebp; unsigned int esi; unsigned int edi; unsigned int es; unsigned int cs; unsigned int ss; unsigned int ds; unsigned int fs; unsigned int gs; unsigned int ldt_sel; unsigned int io_map; }

user_defined_types: struct list_head { struct list_head *prev; }


panic

decompiled_code:
void __fastcall __noreturn panic(const char *a1, unsigned int a2)
{
printk("\n------------------------------------------\n");
printk("Kernel Panic: %s\tPid: %d\n", a1, *(unsigned int *)(current + 136));
printk("--------------------------------------------\n");
printk(
"error code: 0x%x eip: 0x%x esp: 0x%x eflags: 0x%x\n",
*(unsigned int *)((char *)&loc_27 + a2 + 1),
*(unsigned int *)((char *)&loc_2A + a2 + 2),
*(unsigned int *)((char *)&loc_34 + a2 + 4),
*(unsigned int *)((char *)&loc_34 + a2));
printk("\nGeneral Registers:\n");
printk(
"eax: 0x%x ebx: 0x%x ecx: 0x%x edx: 0x%x\n",
*(unsigned int *)((char *)&loc_15 + a2 + 3),
*(unsigned int *)a2,
*(unsigned int *)((char *)&loc_4 + a2),
*(unsigned int *)((char *)&loc_7 + a2 + 1));
printk("\nSegment Registers:\n");
printk(
"cs: 0x%x ds: 0x%x es: 0x%x ss: 0x%x fs: 0x%x\n",
*(unsigned int *)((char *)&loc_2F + a2 + 1),
*(unsigned int *)((char *)&loc_1A + a2 + 2),
*(unsigned int *)((char *)&loc_1A + a2 + 6),
*(unsigned int *)((char *)&loc_39 + a2 + 3),
*(unsigned int *)((char *)&loc_21 + a2 + 3));
printk("--------------------------------------------\n");
_disable();
__halt();
}

canonical_decompiled_code:
void __fastcall __noreturn func0(const char *a1, unsigned int a2)
{
printk("\n------------------------------------------\n");
printk("Kernel Panic: %s\tPid: %d\n", a1, *(unsigned int *)(current + 136));
printk("--------------------------------------------\n");
printk(
"error code: 0x%x eip: 0x%x esp: 0x%x eflags: 0x%x\n",
*(unsigned int *)((char *)&loc_27 + a2 + 1),
*(unsigned int *)((char *)&loc_2A + a2 + 2),
*(unsigned int *)((char *)&loc_34 + a2 + 4),
*(unsigned int *)((char *)&loc_34 + a2));
printk("\nGeneral Registers:\n");
printk(
"eax: 0x%x ebx: 0x%x ecx: 0x%x edx: 0x%x\n",
*(unsigned int *)((char *)&loc_15 + a2 + 3),
*(unsigned int *)a2,
*(unsigned int *)((char *)&loc_4 + a2),
*(unsigned int *)((char *)&loc_7 + a2 + 1));
printk("\nSegment Registers:\n");
printk(
"cs: 0x%x ds: 0x%x es: 0x%x ss: 0x%x fs: 0x%x\n",
*(unsigned int *)((char *)&loc_2F + a2 + 1),
*(unsigned int *)((char *)&loc_1A + a2 + 2),
*(unsigned int *)((char *)&loc_1A + a2 + 6),
*(unsigned int *)((char *)&loc_39 + a2 + 3),
*(unsigned int *)((char *)&loc_21 + a2 + 3));
printk("--------------------------------------------\n");
_disable();
__halt();
}

original_code:
void panic(char *msg, unsigned int esp)
{
        struct regs *reg = (struct regs *)esp;
 printk("\n------------------------------------------\n");
        printk("Kernel Panic: %s\tPid: %d\n", msg, current->pid);
 printk("--------------------------------------------\n");
        printk("error code: 0x%x eip: 0x%x esp: 0x%x eflags: 0x%x\n",
  reg->error_code, reg->orig_eip, reg->esp, reg->eflags);
        printk("\nGeneral Registers:\n");
        printk("eax: 0x%x ebx: 0x%x ecx: 0x%x edx: 0x%x\n",
                reg->eax, reg->ebx, reg->ecx, reg->edx);
        printk("\nSegment Registers:\n");
        printk("cs: 0x%x ds: 0x%x es: 0x%x ss: 0x%x fs: 0x%x\n",
  reg->orig_cs, reg->ds, reg->es, reg->ss, reg->fs);
 printk("--------------------------------------------\n");
        asm("cli\n\thlt\n"::);
}


oops

decompiled_code:
void __fastcall __noreturn oops(const char *a1)
{
printk("%s\n", a1);
_disable();
__halt();
}

canonical_decompiled_code:
void __fastcall __noreturn func1(const char *a1)
{
printk("%s\n", a1);
_disable();
__halt();
}

original_code:
void oops(char *msg)
{
 printk("%s\n", msg);
 asm("cli\n\thlt\n"::);
}


original_code:
int creat_kthread(unsigned int eip)
{
        struct task_struct *tsk;
        int pid;
        pid = get_pid();
        if (pid == -1) {
                printk("Get pid failed.\n");
                return -1;
        }
        printk("pid: %d\n", pid);
        tsk = (struct task_struct *)alloc_page(2);
        if (!tsk) {
                printk("Alloc tsk page failed.\n");
                return -1;
        }
        printk("Alloc tsk page at: 0x%x\n", tsk);
        tsk->tss.prev_task_link = 0;
        tsk->tss.esp0 = tsk + (4*1024) * 2;
        tsk->tss.ss0 = 0x10;
        tsk->tss.esp1 = 0;
        tsk->tss.ss1 = 0;
        tsk->tss.esp2 = 0;
        tsk->tss.ss2 = 0;
        tsk->tss.cr3 = pg_dir;
        tsk->tss.eip = eip;
        tsk->tss.eflags = 0x200;
        tsk->tss.eax = 0;
        tsk->tss.ebx = 0;
        tsk->tss.ecx = 0;
        tsk->tss.edx = 0;
        tsk->tss.esp = (unsigned int)alloc_page(1) + (4*1024);
        tsk->tss.ebp = 0;
        tsk->tss.esi = 0;
        tsk->tss.edi = 0;
        tsk->tss.es = 0x10;
        tsk->tss.cs = 0x08;
        tsk->tss.ss = 0x10;
        tsk->tss.ds = 0x10;
        tsk->tss.fs = 0x10;
        tsk->tss.gs = 0x10;
        tsk->tss.ldt_sel = ((4 + 2*pid + 1) << 3);
        tsk->tss.io_map = 0x80000000;
        tsk->pid = pid;
        tsk->tss_sel = ((4 + 2*pid) << 3);
        tsk->ldt_sel = ((4 + 2*pid + 1) << 3);
        tsk->state = 0;
        tsk->counter = 15;
        tsk->priority = 200;
        set_tss_desc(new_gdt, (unsigned int)&(tsk->tss), 0x68, 0x89, (4 + 2*pid));
        set_ldt_desc(new_gdt, (unsigned int)&(tsk->ldt), 0x40, 0x82, (4 + 2*pid + 1));
        set_gdt_desc(tsk->ldt, 0x0, 0xffffffff, 0x9a, 1);
        set_gdt_desc(tsk->ldt, 0x0, 0xffffffff, 0x92, 2);
        list_add_tail(&(tsk->list), &task_list_head);
 return 0;
}


decompiled_code:
__int64 do_exit()
{
unsigned int v0; // ebx
__int64 result; // rax
_QWORD *v2; // [rsp+8h] [rbp-10h] BYREF

v2 = 0LL;
v0 = *(_DWORD *)(current + 136);
printk("Pid %d exiting.\n", v0);
if ( !v0 )
oops("Init process try to exit.\n");
_disable();
v2 = (_QWORD *)task_list_head[1];
if ( v2 == task_list_head )
{
_enable();
printk("Del pid %d from task list failed.\n", v0);
result = 0xFFFFFFFFLL;
}
else
{
list_del(&v2);
_enable();
printk("Del pid %d from task list ok.\n", v0);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
unsigned int v0; // ebx
__int64 result; // rax
_QWORD *v2; // [rsp+8h] [rbp-10h] BYREF

v2 = 0LL;
v0 = *(_DWORD *)(current + 136);
printk("Pid %d exiting.\n", v0);
if ( !v0 )
oops("Init process try to exit.\n");
_disable();
v2 = (_QWORD *)task_list_head[1];
if ( v2 == task_list_head )
{
_enable();
printk("Del pid %d from task list failed.\n", v0);
result = 0xFFFFFFFFLL;
}
else
{
list_del(&v2);
_enable();
printk("Del pid %d from task list ok.\n", v0);
result = 0LL;
}
return result;
}

original_code:
int do_exit(void)
{
        struct task_struct *tsk = (void *)0;
        struct list_head *p = (void *)0;
 int pid;
 pid = current->pid;
 printk("Pid %d exiting.\n", pid);
 if (pid == 0)
  oops("Init process try to exit.\n");
 asm("cli\n"::);
        for (p = (&task_list_head)->next; p != (&task_list_head); p = p->next) {
                tsk = ({ (struct task_struct *)((char * )p - (char *)&(((struct task_struct *)0x0)->list)); });;
                if (tsk) {
   list_del(&p);
   asm("sti\n"::);
   printk("Del pid %d from task list ok.\n", pid);
   return 0;
                }
        }
 asm("sti\n"::);
 printk("Del pid %d from task list failed.\n", pid);
 return -1;
}

canonical_original_code:
int do_exit()
{
        struct task_struct *tsk = (void *)0;
        struct list_head *p = (void *)0;
 int pid;
 pid = current->pid;
 printk("Pid %d exiting.\n", pid);
 if (pid == 0)
  oops("Init process try to exit.\n");
 asm("cli\n"::);
        for (p = (&task_list_head)->next; p != (&task_list_head); p = p->next) {
                tsk = ({ (struct task_struct *)((char * )p - (char *)&(((struct task_struct *)0x0)->list)); });;
                if (tsk) {
   list_del(&p);
   asm("sti\n"::);
   printk("Del pid %d from task list ok.\n", pid);
   return 0;
                }
        }
 asm("sti\n"::);
 printk("Del pid %d from task list failed.\n", pid);
 return -1;
}


printk

decompiled_code:
__int64 __fastcall printk(unsigned __int8 *a1)
{
const char *v2; // [rsp+10h] [rbp-8h] BYREF

return vfprintf(a1, &v2);
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int8 *a1)
{
const char *v2; // [rsp+10h] [rbp-8h] BYREF

return func0(a1, &v2);
}

original_code:
int printk(char *format, ...)
{
 char* arg;
 (arg = (char *)&format + sizeof(format));
 return vfprintf(format, arg);
}

canonical_original_code:
int printk(char *format, ...)
{
 char *arg;
 (arg = (char *)&format + sizeof(format));
 return vfprintf(format, arg);
}


repo: cmather/c-skeleton

decompiled_code:
int say_hello()
{
return printf("Hello World");
}

canonical_decompiled_code:
int func6()
{
return printf("Hello World");
}

original_code:
void say_hello()
{
  printf("Hello World");
}


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

if ( a1 == 30 )
return 32LL;
if ( a1 > 30 )
{
result = 64LL;
if ( a1 != 90 )
{
LABEL_8:
fprintf(stderr, "ERROR: unknown particle data format! (format = %ld)\n", a1);
return 0LL;
}
}
else
{
result = 16LL;
if ( a1 != 10 )
{
if ( a1 == 20 )
return 24LL;
goto LABEL_8;
}
}
return result;
}

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

if ( a1 == 30 )
return 32LL;
if ( a1 > 30 )
{
result = 64LL;
if ( a1 != 90 )
{
LABEL_8:
fprintf(stderr, "ERROR: unknown particle data format! (format = %ld)\n", a1);
return 0LL;
}
}
else
{
result = 16LL;
if ( a1 != 10 )
{
if ( a1 == 20 )
return 24LL;
goto LABEL_8;
}
}
return result;
}

original_code:
static inline size_t
pair_sizeof_data( const int64_t pair_format )
{
    switch ( pair_format ) {
        case PAIR_DATA_ID:
            return sizeof( PAIR_ID );
        case PAIR_DATA_SEP:
            return sizeof( PAIR_SEP );
        case PAIR_DATA_PROJ:
            return sizeof( PAIR_PROJ );
        case PAIR_DATA_ALL:
            return sizeof( PAIR_ALL );
    }
    fprintf( stderr, "ERROR: unknown particle data format!  (format = %" "l" "d" ")\n",
             pair_format );
    return 0;
}

canonical_original_code:
static inline unsigned long pair_sizeof_data(long pair_format)
{
    switch ( pair_format ) {
        case PAIR_DATA_ID:
            return sizeof( PAIR_ID );
        case PAIR_DATA_SEP:
            return sizeof( PAIR_SEP );
        case PAIR_DATA_PROJ:
            return sizeof( PAIR_PROJ );
        case PAIR_DATA_ALL:
            return sizeof( PAIR_ALL );
    }
    fprintf( stderr, "ERROR: unknown particle data format!  (format = %" "l" "d" ")\n",
             pair_format );
    return 0;
}

return_type: unsigned long


xcalloc

repo: cmccabe/consensus-fun

decompiled_code:
void *__fastcall xcalloc(size_t a1, size_t a2)
{
void *result; // rax

result = calloc(a1, a2);
if ( !result )
abort();
return result;
}

canonical_decompiled_code:
void *__fastcall func0(size_t a1, size_t a2)
{
void *result; // rax

result = calloc(a1, a2);
if ( !result )
abort();
return result;
}

original_code:
void *xcalloc(size_t nmemb, size_t size)
{
 void *ret = calloc(nmemb, size);
 if (!ret)
  abort();
 return ret;
}

canonical_original_code:
void *xcalloc(unsigned long nmemb, unsigned long size)
{
 void *ret = calloc(nmemb, size);
 if (!ret)
  abort();
 return ret;
}

variable_types:
nmemb
unsigned long

variable_types:
size
unsigned long

variable_types:
ret
void *


usage

decompiled_code:
void __fastcall __noreturn usage(const char *a1, int a2)
{
fprintf(
stderr,
"%s: a consensus protocol demo.\n"
"options:\n"
"-h: this help message\n"
"-n <num-nodes> set the number of acceptors (default: %d)\n"
"-v enable verbose debug messages\n",
a1,
5LL);
exit(a2);
}

canonical_decompiled_code:
void __fastcall __noreturn func1(const char *a1, int a2)
{
fprintf(
stderr,
"%s: a consensus protocol demo.\n"
"options:\n"
"-h: this help message\n"
"-n <num-nodes> set the number of acceptors (default: %d)\n"
"-v enable verbose debug messages\n",
a1,
5LL);
exit(a2);
}

original_code:
static void usage(const char *argv0, int retcode)
{
 fprintf(stderr, "%s: a consensus protocol demo.\noptions:\n-h:                     this help message\n-n <num-nodes>          set the number of acceptors (default: %d)\n-v                      enable verbose debug messages\n", argv0, 5);
 exit(retcode);
}

canonical_original_code:
static void usage(char *argv0, int retcode)
{
 fprintf(stderr, "%s: a consensus protocol demo.\noptions:\n-h:                     this help message\n-n <num-nodes>          set the number of acceptors (default: %d)\n-v                      enable verbose debug messages\n", argv0, 5);
 exit(retcode);
}

variable_types: retcode int


decompiled_code:
int __fastcall parse_argv(int argc, char **argv)
{
int result; // eax

g_num_nodes = 5;
g_verbose = 0;
while ( 1 )
{
result = getopt(argc, argv, "hn:v");
if ( result == -1 )
break;
switch ( result )
{
case 'n':
g_num_nodes = atoi(optarg);
break;
case 'v':
g_verbose = 1;
break;
case 'h':
usage(*argv, 0);
default:
fwrite("failed to parse argument.\n\n", 1uLL, 0x1BuLL, stderr);
usage(*argv, 1);
}
}
if ( g_num_nodes <= 2 )
{
fprintf(stderr, "num_nodes = %d, but we can't run with num_nodes < 3.\n\n", (unsigned int)g_num_nodes);
usage(*argv, 1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(int argc, char **argv)
{
int result; // eax

g_num_nodes = 5;
g_verbose = 0;
while ( 1 )
{
result = getopt(argc, argv, "hn:v");
if ( result == -1 )
break;
switch ( result )
{
case 'n':
g_num_nodes = atoi(optarg);
break;
case 'v':
g_verbose = 1;
break;
case 'h':
func1(*argv, 0);
default:
fwrite("failed to parse argument.\n\n", 1uLL, 0x1BuLL, stderr);
func1(*argv, 1);
}
}
if ( g_num_nodes <= 2 )
{
fprintf(stderr, "num_nodes = %d, but we can't run with num_nodes < 3.\n\n", (unsigned int)g_num_nodes);
func1(*argv, 1);
}
return result;
}

original_code:
static void parse_argv(int argc, char **argv)
{
 int c;
 g_num_nodes = 5;
 g_verbose = 0;
 while ((c = getopt(argc, argv, "hn:v")) != -1) {
  switch (c) {
  case 'h':
   usage(argv[0], 0);
   break;
  case 'n':
   g_num_nodes = atoi(optarg);
   break;
  case 'v':
   g_verbose = 1;
   break;
  default:
   fprintf(stderr, "failed to parse argument.\n\n");
   usage(argv[0], 1);
   break;
  }
 }
 if (g_num_nodes < 3) {
  fprintf(stderr, "num_nodes = %d, but we can't run with "
    "num_nodes < 3.\n\n", g_num_nodes);
  usage(argv[0], 1);
 }
}

variable_types: argc int

variable_types:
argv
char **

variable_types: c int


decompiled_code:
__int64 check_leaders()
{
unsigned int *v0; // rbp
unsigned int *v1; // rax
unsigned int v2; // er12
__int64 v3; // rsi
int v4; // ebx

if ( g_num_nodes <= 0 )
{
v3 = 0xFFFFFFFFLL;
LABEL_10:
printf("successfully elected node %d as leader.\n", v3);
return 0;
}
v0 = (unsigned int *)&unk_C4C;
v1 = (unsigned int *)&unk_C4C;
v2 = 0;
v3 = 0xFFFFFFFFLL;
do
{
if ( (_DWORD)v3 == -1 )
{
v3 = *v1;
}
else if ( *v1 != (_DWORD)v3 )
{
v2 = 1;
}
v1 += 68;
}
while ( v1 != (unsigned int *)((char *)&unk_D5C + 272 * (unsigned int)(g_num_nodes - 1)) );
if ( !v2 )
goto LABEL_10;
v4 = 0;
do
{
fprintf(stderr, "%d: leader = %d\n", (unsigned int)v4++, *v0);
v0 += 68;
}
while ( g_num_nodes > v4 );
return v2;
}

canonical_decompiled_code:
__int64 func5()
{
unsigned int *v0; // rbp
unsigned int *v1; // rax
unsigned int v2; // er12
__int64 v3; // rsi
int v4; // ebx

if ( g_num_nodes <= 0 )
{
v3 = 0xFFFFFFFFLL;
LABEL_10:
printf("successfully elected node %d as leader.\n", v3);
return 0;
}
v0 = (unsigned int *)&unk_C4C;
v1 = (unsigned int *)&unk_C4C;
v2 = 0;
v3 = 0xFFFFFFFFLL;
do
{
if ( (_DWORD)v3 == -1 )
{
v3 = *v1;
}
else if ( *v1 != (_DWORD)v3 )
{
v2 = 1;
}
v1 += 68;
}
while ( v1 != (unsigned int *)((char *)&unk_D5C + 272 * (unsigned int)(g_num_nodes - 1)) );
if ( !v2 )
goto LABEL_10;
v4 = 0;
do
{
fprintf(stderr, "%d: leader = %d\n", (unsigned int)v4++, *v0);
v0 += 68;
}
while ( g_num_nodes > v4 );
return v2;
}

original_code:
static int check_leaders(void)
{
 int i, leader, conflict;
 leader = -1;
 conflict = 0;
 for (i = 0; i < g_num_nodes; ++i) {
  if (leader == -1)
   leader = g_node_data[i].leader;
  else {
   if (leader != g_node_data[i].leader) {
    conflict = 1;
   }
  }
 }
 if (!conflict) {
  printf("successfully elected node %d as leader.\n", leader);
  return 0;
 }
 for (i = 0; i < g_num_nodes; ++i) {
  fprintf(stderr, "%d: leader = %d\n", i, g_node_data[i].leader);
 }
 return 1;
}

canonical_original_code:
static int check_leaders()
{
 int i; int leader; int conflict;
 leader = -1;
 conflict = 0;
 for (i = 0; i < g_num_nodes; ++i) {
  if (leader == -1)
   leader = g_node_data[i].leader;
  else {
   if (leader != g_node_data[i].leader) {
    conflict = 1;
   }
  }
 }
 if (!conflict) {
  printf("successfully elected node %d as leader.\n", leader);
  return 0;
 }
 for (i = 0; i < g_num_nodes; ++i) {
  fprintf(stderr, "%d: leader = %d\n", i, g_node_data[i].leader);
 }
 return 1;
}

variable_types: i int

variable_types: leader int

variable_types: conflict int


decompiled_code:
__int64 __fastcall run_tpc(int a1)
{
int v1; // er12
int v2; // eax
unsigned int *v3; // rbx
__int64 *v4; // r13
unsigned int v5; // ebp
__int64 v6; // rax
__int64 v7; // rbx
__int64 v8; // rbx
char v10[56]; // [rsp+0h] [rbp-38h] BYREF

if ( sem_init(&g_sem_accept_leader, 0, 0) )
abort();
if ( pthread_mutex_init(&g_start_lock, 0LL) )
abort();
v1 = pthread_cond_init(&g_start_cond, 0LL);
if ( v1 )
abort();
g_start = 0;
memset(g_nodes, 0, sizeof(g_nodes));
memset(&g_node_data, 0, 0x8800uLL);
v2 = g_num_nodes;
if ( g_num_nodes > 0 )
{
v3 = (unsigned int *)&g_node_data;
v4 = g_nodes;
v5 = v1;
do
{
snprintf(v10, 0x10uLL, "node_%3d", v5);
*v3 = v5;
v3[67] = -1;
v3[66] = -1;
v6 = worker_start(v10, tpc_handle_msg, 0LL, v3);
*v4 = v6;
if ( !v6 )
{
fprintf(stderr, "failed to allocate node %d\n", v5);
abort();
}
++v5;
v2 = g_num_nodes;
v3 += 68;
++v4;
}
while ( g_num_nodes > (int)v5 );
}
if ( v2 <= 2 )
abort();
send_do_propose(2);
if ( a1 )
{
send_do_propose(0);
send_do_propose(1);
}
pthread_mutex_lock(&g_start_lock);
g_start = 1;
pthread_cond_broadcast(&g_start_cond);
pthread_mutex_unlock(&g_start_lock);
if ( g_num_nodes > 0 )
{
do
{
while ( sem_wait(&g_sem_accept_leader) == -1 && *_errno_location() == 4 )
;
++v1;
}
while ( g_num_nodes > v1 );
if ( g_num_nodes > 0 )
{
v7 = 0LL;
do
worker_stop(g_nodes[v7++]);
while ( g_num_nodes > (int)v7 );
if ( g_num_nodes > 0 )
{
v8 = 0LL;
do
worker_join(g_nodes[v8++]);
while ( g_num_nodes > (int)v8 );
}
}
}
pthread_cond_destroy(&g_start_cond);
g_start = 0;
pthread_mutex_destroy(&g_start_lock);
sem_destroy(&g_sem_accept_leader);
return check_leaders();
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1)
{
int v1; // er12
int v2; // eax
unsigned int *v3; // rbx
__int64 *v4; // r13
unsigned int v5; // ebp
__int64 v6; // rax
__int64 v7; // rbx
__int64 v8; // rbx
char v10[56]; // [rsp+0h] [rbp-38h] BYREF

if ( sem_init(&g_sem_accept_leader, 0, 0) )
abort();
if ( pthread_mutex_init(&g_start_lock, 0LL) )
abort();
v1 = pthread_cond_init(&g_start_cond, 0LL);
if ( v1 )
abort();
g_start = 0;
memset(g_nodes, 0, sizeof(g_nodes));
memset(&g_node_data, 0, 0x8800uLL);
v2 = g_num_nodes;
if ( g_num_nodes > 0 )
{
v3 = (unsigned int *)&g_node_data;
v4 = g_nodes;
v5 = v1;
do
{
snprintf(v10, 0x10uLL, "node_%3d", v5);
*v3 = v5;
v3[67] = -1;
v3[66] = -1;
v6 = worker_start(v10, tpc_handle_msg, 0LL, v3);
*v4 = v6;
if ( !v6 )
{
fprintf(stderr, "failed to allocate node %d\n", v5);
abort();
}
++v5;
v2 = g_num_nodes;
v3 += 68;
++v4;
}
while ( g_num_nodes > (int)v5 );
}
if ( v2 <= 2 )
abort();
func3(2);
if ( a1 )
{
func3(0);
func3(1);
}
pthread_mutex_lock(&g_start_lock);
g_start = 1;
pthread_cond_broadcast(&g_start_cond);
pthread_mutex_unlock(&g_start_lock);
if ( g_num_nodes > 0 )
{
do
{
while ( sem_wait(&g_sem_accept_leader) == -1 && *_errno_location() == 4 )
;
++v1;
}
while ( g_num_nodes > v1 );
if ( g_num_nodes > 0 )
{
v7 = 0LL;
do
worker_stop(g_nodes[v7++]);
while ( g_num_nodes > (int)v7 );
if ( g_num_nodes > 0 )
{
v8 = 0LL;
do
worker_join(g_nodes[v8++]);
while ( g_num_nodes > (int)v8 );
}
}
}
pthread_cond_destroy(&g_start_cond);
g_start = 0;
pthread_mutex_destroy(&g_start_lock);
sem_destroy(&g_sem_accept_leader);
return func5();
}

original_code:
static int run_tpc(int duelling_proposers)
{
 int i;
 if (sem_init(&g_sem_accept_leader, 0, 0))
  abort();
 if (pthread_mutex_init(&g_start_lock, 0))
  abort();
 if (pthread_cond_init(&g_start_cond, 0))
  abort();
 g_start = 0;
 memset(g_nodes, 0, sizeof(g_nodes));
 memset(g_node_data, 0, sizeof(g_node_data));
 for (i = 0; i < g_num_nodes; ++i) {
  char name[16];
  snprintf(name, 16, "node_%3d", i);
  g_node_data[i].id = i;
  g_node_data[i].leader = -1;
  g_node_data[i].coord = -1;
  g_nodes[i] = worker_start(name, tpc_handle_msg,
    ((void *)0), &g_node_data[i]);
  if (!g_nodes[i]) {
   fprintf(stderr, "failed to allocate node %d\n", i);
   abort();
  }
 }
 if (g_num_nodes < 3)
  abort();
 send_do_propose(2);
 if (duelling_proposers) {
  send_do_propose(0);
  send_do_propose(1);
 }
 pthread_mutex_lock(&g_start_lock);
 g_start = 1;
 pthread_cond_broadcast(&g_start_cond);
 pthread_mutex_unlock(&g_start_lock);
 for (i = 0; i < g_num_nodes; ++i) {
  (__extension__ ({ long int __result; do __result = (long int) (sem_wait(&g_sem_accept_leader)); while (__result == -1L && (*__errno_location ()) == 4); __result; }));
 }
 for (i = 0; i < g_num_nodes; ++i) {
  worker_stop(g_nodes[i]);
 }
 for (i = 0; i < g_num_nodes; ++i) {
  worker_join(g_nodes[i]);
 }
 pthread_cond_destroy(&g_start_cond);
 g_start = 0;
 pthread_mutex_destroy(&g_start_lock);
 sem_destroy(&g_sem_accept_leader);
 return check_leaders();
}

canonical_original_code:
static int run_tpc(int duelling_proposers)
{
 int i;
 if (sem_init(&g_sem_accept_leader, 0, 0))
  abort();
 if (pthread_mutex_init(&g_start_lock, 0))
  abort();
 if (pthread_cond_init(&g_start_cond, 0))
  abort();
 g_start = 0;
 memset(g_nodes, 0, sizeof(g_nodes));
 memset(g_node_data, 0, sizeof(g_node_data));
 for (i = 0; i < g_num_nodes; ++i) {
  char name[16];
  snprintf(name, 16, "node_%3d", i);
  g_node_data[i].id = i;
  g_node_data[i].leader = -1;
  g_node_data[i].coord = -1;
  g_nodes[i] = worker_start(name, tpc_handle_msg,
    ((void *)0), &g_node_data[i]);
  if (!g_nodes[i]) {
   fprintf(stderr, "failed to allocate node %d\n", i);
   abort();
  }
 }
 if (g_num_nodes < 3)
  abort();
 send_do_propose(2);
 if (duelling_proposers) {
  send_do_propose(0);
  send_do_propose(1);
 }
 pthread_mutex_lock(&g_start_lock);
 g_start = 1;
 pthread_cond_broadcast(&g_start_cond);
 pthread_mutex_unlock(&g_start_lock);
 for (i = 0; i < g_num_nodes; ++i) {
  (__extension__ ({ long __result; do __result = (long) (sem_wait(&g_sem_accept_leader)); while (__result == -1L && (*__errno_location ()) == 4); __result; }));
 }
 for (i = 0; i < g_num_nodes; ++i) {
  worker_stop(g_nodes[i]);
 }
 for (i = 0; i < g_num_nodes; ++i) {
  worker_join(g_nodes[i]);
 }
 pthread_cond_destroy(&g_start_cond);
 g_start = 0;
 pthread_mutex_destroy(&g_start_lock);
 sem_destroy(&g_sem_accept_leader);
 return check_leaders();
}

variable_types:
name
char [16]


repo: cmoresid/dirapp

decompiled_code:
void __fastcall __noreturn err_quit(const char *a1)
{
fprintf(stderr, "Error: %s\n", a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(const char *a1)
{
fprintf(stderr, "Error: %s\n", a1);
exit(1);
}

original_code:
void err_quit(const char* error)
{
 fprintf(stderr, "Error: %s\n", error);
 exit(1);
}

canonical_original_code:
void err_quit(char *error)
{
 fprintf(stderr, "Error: %s\n", error);
 exit(1);
}

variable_types:
error
char *


decompiled_code:
__int64 __fastcall read_byte(int a1)
{
bool v1; // zf
__int64 result; // rax
char buf[9]; // [rsp+Fh] [rbp-9h] BYREF

v1 = recv(a1, buf, 1uLL, 0) == 0;
result = (unsigned __int8)buf[0];
if ( v1 )
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
bool v1; // zf
__int64 result; // rax
char buf[9]; // [rsp+Fh] [rbp-9h] BYREF

v1 = recv(a1, buf, 1uLL, 0) == 0;
result = (unsigned __int8)buf[0];
if ( v1 )
result = 0LL;
return result;
}

original_code:
byte read_byte(int socketfd)
{
 size_t nbytes;
 byte buff[1];
 if ((nbytes = recv(socketfd, buff, 1, 0)) <= 0) {
  return 0;
 } else {
  return buff[0];
 }
}

canonical_original_code:
unsigned char read_byte(int socketfd)
{
 unsigned long nbytes;
 unsigned char buff[1];
 if ((nbytes = recv(socketfd, buff, 1, 0)) <= 0) {
  return 0;
 } else {
  return buff[0];
 }
}

variable_types: socketfd int

variable_types:
nbytes
unsigned long

variable_types:
buff
unsigned char [1]


decompiled_code:
__int64 __fastcall read_string(int fd, void *buf, int a3)
{
unsigned __int8 v4; // al
__int64 v5; // r14
unsigned __int8 v6; // r12
ssize_t v7; // rdx
__int64 result; // rax

v4 = read_byte(fd);
v5 = v4;
if ( !v4 )
return 0xFFFFFFFFLL;
v6 = v4;
if ( a3 <= (unsigned __int64)v4 )
return 0xFFFFFFFFLL;
v7 = recv(fd, buf, v4, 256);
result = 0LL;
if ( v7 )
{
*((_BYTE *)buf + v5) = 0;
result = v6;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int fd, void *buf, int a3)
{
unsigned __int8 v4; // al
__int64 v5; // r14
unsigned __int8 v6; // r12
ssize_t v7; // rdx
__int64 result; // rax

v4 = func1(fd);
v5 = v4;
if ( !v4 )
return 0xFFFFFFFFLL;
v6 = v4;
if ( a3 <= (unsigned __int64)v4 )
return 0xFFFFFFFFLL;
v7 = recv(fd, buf, v4, 256);
result = 0LL;
if ( v7 )
{
*((_BYTE *)buf + v5) = 0;
result = v6;
}
return result;
}

original_code:
int read_string(int socketfd, byte* buff, int buff_size)
{
 size_t nbytes;
 size_t len;
 if ((len = read_byte(socketfd)) <= 0) {
  return -1;
 }
 if (len >= buff_size) {
  return -1;
 }
 if ((nbytes = recv(socketfd, buff, len, MSG_WAITALL)) <= 0) {
  if (nbytes == 0) {
   return 0;
  } else {
   return -1;
  }
 } else {
  buff[len] = '\0';
  return len;
 }
}

canonical_original_code:
int read_string(int socketfd, unsigned char *buff, int buff_size)
{
 unsigned long nbytes;
 unsigned long len;
 if ((len = read_byte(socketfd)) <= 0) {
  return -1;
 }
 if (len >= buff_size) {
  return -1;
 }
 if ((nbytes = recv(socketfd, buff, len, MSG_WAITALL)) <= 0) {
  if (nbytes == 0) {
   return 0;
  } else {
   return -1;
  }
 } else {
  buff[len] = '\0';
  return len;
 }
}

variable_types:
buff
unsigned char *

variable_types:
len
unsigned long


decompiled_code:
__int64 __fastcall send_byte(int a1, char a2)
{
char buf[9]; // [rsp+Fh] [rbp-9h] BYREF

buf[0] = a2;
return 2 * (unsigned int)(send(a1, buf, 1uLL, 0) > 0) - 1;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, char a2)
{
char buf[9]; // [rsp+Fh] [rbp-9h] BYREF

buf[0] = a2;
return 2 * (unsigned int)(send(a1, buf, 1uLL, 0) > 0) - 1;
}

original_code:
int send_byte(int socketfd, byte b)
{
 byte buff[1];
 buff[0] = b;
 if (send(socketfd, buff, 1, 0) <= 0) {
  return -1;
 }
 return 1;
}

canonical_original_code:
int send_byte(int socketfd, unsigned char b)
{
 unsigned char buff[1];
 buff[0] = b;
 if (send(socketfd, buff, 1, 0) <= 0) {
  return -1;
 }
 return 1;
}

variable_types:
b
unsigned char


decompiled_code:
__int64 __fastcall send_string(int fd, char *src)
{
unsigned __int8 v2; // al
size_t v3; // r14
void *v4; // rsp
unsigned int v5; // ebx
char v7[48]; // [rsp+0h] [rbp-30h] BYREF

v2 = strlen(src);
v3 = v2;
v4 = alloca((v2 + 15) & 0x1F0);
v5 = v2;
if ( (unsigned int)send_byte(fd, v2) != 1 )
return (unsigned int)-1;
strncpy(v7, src, v3);
if ( send(fd, v7, v3, 0) <= 0 )
v5 = -1;
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func4(int fd, char *src)
{
unsigned __int8 v2; // al
size_t v3; // r14
void *v4; // rsp
unsigned int v5; // ebx
char v7[48]; // [rsp+0h] [rbp-30h] BYREF

v2 = strlen(src);
v3 = v2;
v4 = alloca((v2 + 15) & 0x1F0);
v5 = v2;
if ( (unsigned int)func3(fd, v2) != 1 )
return (unsigned int)-1;
strncpy(v7, src, v3);
if ( send(fd, v7, v3, 0) <= 0 )
v5 = -1;
return v5;
}

original_code:
int send_string(int socketfd, const char* str)
{
 byte len;
 len = strlen(str);
 byte byte_str[len];
 if (send_byte(socketfd, len) != 1) {
  return -1;
 }
 strncpy(byte_str, str, len);
 if (send(socketfd, byte_str, len, 0) <= 0) {
  return -1;
 }
 return len;
}

canonical_original_code:
int send_string(int socketfd, char *str)
{
 unsigned char len;
 len = strlen(str);
 unsigned char byte_str[-1];
 if (send_byte(socketfd, len) != 1) {
  return -1;
 }
 strncpy(byte_str, str, len);
 if (send(socketfd, byte_str, len, 0) <= 0) {
  return -1;
 }
 return len;
}

variable_types:
str
char *

variable_types:
len
unsigned char


decompiled_code:
void __fastcall free_mempool(void **a1)
{
free(*a1);
}

canonical_decompiled_code:
void __fastcall func0(void **a1)
{
free(*a1);
}

original_code:
void free_mempool(struct mempool* mp)
{
 free(mp->memblock);
}

canonical_original_code:
void free_mempool(struct mempool *mp)
{
 free(mp->memblock);
}

variable_types: struct mempool { void *memblock; struct memunit { struct memunit *next; struct memunit *prev; } *allocated_memblock; struct memunit *free_memblock; unsigned long unit_size; unsigned long memblock_size; } *

user_defined_types: struct mempool { void *memblock; struct memunit *allocated_memblock; struct memunit *free_memblock; unsigned long unit_size; unsigned long memblock_size; }


original_code:
void mempool_free(struct mempool* mp, void* p)
{
 if (mp->memblock < p && p < (void*)((char*)mp->memblock + mp->memblock_size)) {
  struct memunit* cur_unit = (struct memunit*)((char*)p - sizeof(struct memunit));
  mp->allocated_memblock = cur_unit->next;
  if (mp->allocated_memblock != ((void *)0)) {
   mp->allocated_memblock->prev = ((void *)0);
  }
  cur_unit->next = mp->free_memblock;
  if (mp->free_memblock != ((void *)0)) {
   mp->free_memblock->prev = cur_unit;
  }
  mp->free_memblock = cur_unit;
 } else {
  free(p);
 }
}

canonical_original_code:
void mempool_free(struct mempool *mp, void *p)
{
 if (mp->memblock < p && p < (void *)((char *)mp->memblock + mp->memblock_size)) {
  struct memunit *cur_unit = (struct memunit*)((char*)p - sizeof(struct memunit));
  mp->allocated_memblock = cur_unit->next;
  if (mp->allocated_memblock != ((void *)0)) {
   mp->allocated_memblock->prev = ((void *)0);
  }
  cur_unit->next = mp->free_memblock;
  if (mp->free_memblock != ((void *)0)) {
   mp->free_memblock->prev = cur_unit;
  }
  mp->free_memblock = cur_unit;
 } else {
  free(p);
 }
}

variable_types:
p
void *

variable_types: struct memunit { struct memunit *next; struct memunit *prev; } *


repo: cmwdotme/rcfsutil

decompiled_code:
char *__fastcall print_timestamp(unsigned int a1)
{
struct tm *v1; // rax
char *v2; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

timer = a1;
v1 = gmtime(&timer);
v2 = asctime(v1);
strcpy(timestamp, v2);
*(_BYTE *)(strlen(timestamp) + 2911) = 0;
return timestamp;
}

canonical_decompiled_code:
char *__fastcall func0(unsigned int a1)
{
struct tm *v1; // rax
char *v2; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

timer = a1;
v1 = gmtime(&timer);
v2 = asctime(v1);
strcpy(timestamp, v2);
*(_BYTE *)(strlen(timestamp) + 2911) = 0;
return timestamp;
}

original_code:
char *print_timestamp(unsigned int tvalue)
{
  struct tm *tm;
  time_t time = tvalue;
  tm = gmtime(&time);
  sprintf(timestamp, "%s", asctime(tm));
  timestamp[strlen(timestamp) - 1] = '\0';
  return timestamp;
}

canonical_original_code:
char *print_timestamp(unsigned int tvalue)
{
  struct tm *tm;
  long time = tvalue;
  tm = gmtime(&time);
  sprintf(timestamp, "%s", asctime(tm));
  timestamp[strlen(timestamp) - 1] = '\0';
  return timestamp;
}

variable_types:
tvalue
unsigned int

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

variable_types: time long


decompiled_code:
__int64 __fastcall get_unaligned_le16(unsigned __int16 *a1)
{
return *a1;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int16 *a1)
{
return *a1;
}

original_code:
static inline u16 get_unaligned_le16(const u8 *p)
{
 return p[0] | p[1] << 8;
}

canonical_original_code:
static inline unsigned short get_unaligned_le16(unsigned char *p)
{
 return p[0] | p[1] << 8;
}

variable_types:
p
unsigned char *

return_type: unsigned short


MouseMotion

repo: cnlohr/bridgesim

decompiled_code:
__int64 __fastcall MouseMotion(unsigned int a1, double a2, double a3)
{
float v3; // xmm0_4
float v4; // xmm1_4

v3 = a2;
v4 = a3;
return WindowHandleMouseMove(guiwindow, a1, v3, v4);
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, double a2, double a3)
{
float v3; // xmm0_4
float v4; // xmm1_4

v3 = a2;
v4 = a3;
return WindowHandleMouseMove(guiwindow, a1, v3, v4);
}

original_code:
void MouseMotion( double x, double y, int mask )
{
 WindowHandleMouseMove( guiwindow, x, y, mask );
}

canonical_original_code:
void MouseMotion(double x, double y, int mask)
{
 WindowHandleMouseMove( guiwindow, x, y, mask );
}

variable_types: x double

variable_types: y double

variable_types: mask int


MouseClick

decompiled_code:
__int64 __fastcall MouseClick(unsigned int a1, unsigned int a2, double a3, double a4)
{
float v4; // xmm0_4
float v5; // xmm1_4

v4 = a3;
v5 = a4;
return WindowHandleMouseClick(guiwindow, a1, a2, v4, v5);
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1, unsigned int a2, double a3, double a4)
{
float v4; // xmm0_4
float v5; // xmm1_4

v4 = a3;
v5 = a4;
return WindowHandleMouseClick(guiwindow, a1, a2, v4, v5);
}

original_code:
void MouseClick( double x, double y, int button, int state )
{
 WindowHandleMouseClick( guiwindow, x, y, button, state );
}

canonical_original_code:
void MouseClick(double x, double y, int button, int state)
{
 WindowHandleMouseClick( guiwindow, x, y, button, state );
}

variable_types: button int

variable_types: state int


HandleKeyboard

decompiled_code:
__int64 __fastcall HandleKeyboard(unsigned int a1, unsigned int a2)
{
return WindowHandleKeyboard(guiwindow, a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1, unsigned int a2)
{
return WindowHandleKeyboard(guiwindow, a1, a2);
}

original_code:
void HandleKeyboard( int c, int down )
{
 WindowHandleKeyboard( guiwindow, c, down );
}

canonical_original_code:
void HandleKeyboard(int c, int down)
{
 WindowHandleKeyboard( guiwindow, c, down );
}

variable_types: c int

variable_types: down int


UpdatedDisplay

decompiled_code:
__int64 UpdatedDisplay()
{
char s[55]; // [rsp+1h] [rbp-37h] BYREF

CheckCommonAssets();
glClearColor(0.2, 0.2, 0.2, 0.0);
glClear(16640LL);
glEnable(3042LL);
glBlendFunc(770LL, 771LL);
glEnable(2929LL);
glDepthFunc(513LL);
*guiwindow = (int)ScreenW;
guiwindow[1] = (int)*(float *)&ScreenH;
WindowRender(guiwindow);
glMatrixMode(5889LL);
glLoadIdentity();
glOrtho(0.0, ScreenW, 0.0, *(float *)&ScreenH, -1.0, 1.0);
glDepthFunc(519LL);
glScalef(1.0, -1.0);
glTranslatef(0.0, COERCE_DOUBLE(ScreenH ^ (unsigned __int64)LC7));
glMatrixMode(5888LL);
glLoadIdentity();
sprintf(s, "FPS: %d", fpscount);
glRasterPos2f(80.0, 50.0);
glutBitmapString(&glutBitmap9By15, s);
ActivateTexture(*((_QWORD *)guiwindow + 3));
DrawSquare(0.0, 0.0, ScreenW, *(float *)&ScreenH);
DeactivateTexture(*((_QWORD *)guiwindow + 3));
glLoadIdentity();
return glFlush();
}

canonical_decompiled_code:
__int64 func3()
{
char s[55]; // [rsp+1h] [rbp-37h] BYREF

CheckCommonAssets();
glClearColor(0.2, 0.2, 0.2, 0.0);
glClear(16640LL);
glEnable(3042LL);
glBlendFunc(770LL, 771LL);
glEnable(2929LL);
glDepthFunc(513LL);
*guiwindow = (int)ScreenW;
guiwindow[1] = (int)*(float *)&ScreenH;
WindowRender(guiwindow);
glMatrixMode(5889LL);
glLoadIdentity();
glOrtho(0.0, ScreenW, 0.0, *(float *)&ScreenH, -1.0, 1.0);
glDepthFunc(519LL);
glScalef(1.0, -1.0);
glTranslatef(0.0, COERCE_DOUBLE(ScreenH ^ (unsigned __int64)LC7));
glMatrixMode(5888LL);
glLoadIdentity();
sprintf(s, "FPS: %d", fpscount);
glRasterPos2f(80.0, 50.0);
glutBitmapString(&glutBitmap9By15, s);
ActivateTexture(*((_QWORD *)guiwindow + 3));
DrawSquare(0.0, 0.0, ScreenW, *(float *)&ScreenH);
DeactivateTexture(*((_QWORD *)guiwindow + 3));
glLoadIdentity();
return glFlush();
}

original_code:
void UpdatedDisplay(void)
{
 CheckCommonAssets();
 glClearColor( .2, .2, .2, 0 );
 glClear(0x00004000 | 0x00000100);
 glEnable (0x0BE2);
 glBlendFunc(0x0302, 0x0303);
 glEnable( 0x0B71 );
 glDepthFunc(0x0201);
 guiwindow->width = ScreenW;
 guiwindow->height = ScreenH;
 WindowRender( guiwindow );
 glMatrixMode(0x1701);
 glLoadIdentity();
 glOrtho(0, ScreenW, 0, ScreenH, -1, 1);
 glDepthFunc(0x0207);
 glScalef(1, -1, 1);
 glTranslatef(0, -ScreenH, 0);
 glMatrixMode(0x1700);
 glLoadIdentity();
 char st[15];
 sprintf( st, "FPS: %d", fpscount );
 glRasterPos2f(80, 50);
 glutBitmapString( ((void *) &glutBitmap9By15), st );
 ActivateTexture( guiwindow->torender );
 DrawSquare(0,0,ScreenW,ScreenH );
 DeactivateTexture( guiwindow->torender );
 glLoadIdentity();
 glFlush();
}

canonical_original_code:
void UpdatedDisplay()
{
 CheckCommonAssets();
 glClearColor( .2, .2, .2, 0 );
 glClear(0x00004000 | 0x00000100);
 glEnable (0x0BE2);
 glBlendFunc(0x0302, 0x0303);
 glEnable( 0x0B71 );
 glDepthFunc(0x0201);
 guiwindow->width = ScreenW;
 guiwindow->height = ScreenH;
 WindowRender( guiwindow );
 glMatrixMode(0x1701);
 glLoadIdentity();
 glOrtho(0, ScreenW, 0, ScreenH, -1, 1);
 glDepthFunc(0x0207);
 glScalef(1, -1, 1);
 glTranslatef(0, -ScreenH, 0);
 glMatrixMode(0x1700);
 glLoadIdentity();
 char st[15];
 sprintf( st, "FPS: %d", fpscount );
 glRasterPos2f(80, 50);
 glutBitmapString( ((void *) &glutBitmap9By15), st );
 ActivateTexture( guiwindow->torender );
 DrawSquare(0,0,ScreenW,ScreenH );
 DeactivateTexture( guiwindow->torender );
 glLoadIdentity();
 glFlush();
}

variable_types:
st
char [15]


main

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

StartGlutMain(argc, argv, "test", 640LL, 480LL);
SetupCommonAssets();
guiwindow = (_DWORD *)CreateGUIWindow();
*guiwindow = 300;
guiwindow[1] = 300;
v3 = CreateButton(guiwindow, "Hi!");
WindowAddElement(guiwindow, v3);
SetMouseWarpMode(0LL);
DoGlutLoop();
return 0;
}

original_code:
int main(int argc, char **argv)
{
 StartGlutMain( argc, argv, "test", 640, 480 );
 SetupCommonAssets();
 guiwindow = CreateGUIWindow( );
 guiwindow->width = 300;
 guiwindow->height = 300;
 struct GUIBase * b;
 WindowAddElement( guiwindow, b = CreateButton( guiwindow, "Hi!" ) );
 SetMouseWarpMode( 0 );
 DoGlutLoop();
}

canonical_original_code:
int main(int argc, char **argv)
{
 StartGlutMain( argc, argv, "test", 640, 480 );
 SetupCommonAssets();
 guiwindow = CreateGUIWindow( );
 guiwindow->width = 300;
 guiwindow->height = 300;
 struct GUIBase *b;
 WindowAddElement( guiwindow, b = CreateButton( guiwindow, "Hi!" ) );
 SetMouseWarpMode( 0 );
 DoGlutLoop();
}

variable_types: argc int

variable_types:
argv
char **

variable_types: struct GUIBase { float x; float w; float color[4]; int depressed; int clicked; int focused; struct GUIWindow { int width; int height; int focusid; struct RFBuffer { int width; int use_depth_buffer; enum TextureType { TTUNDEFINED=0, TTGRAYSCALE=1, TTGRAYALPHA=2, TTRGB=3, TTRGBA=4, TTRGBA16=5, TTRGBA32=6 } mtt; unsigned int renderbuffer; unsigned int outputbuffer; int outextures; } *renderbuffer; struct Texture { enum TextureType { TTUNDEFINED=0, TTGRAYSCALE=1, TTGRAYALPHA=2, TTRGB=3, TTRGBA=4, TTRGBA16=5, TTRGBA32=6 } format; unsigned int type; unsigned int texture; int width; int slot; unsigned char *rawdata; } *torender; struct GUIBase *elements[2048]; } *wp; void (*Prerender)(struct GUIBase *b); void (*Render)(struct GUIBase *b); int (*CheckClick)(struct GUIBase *b, float screenx, float screeny, int button, int down); void (*HandleMove)(struct GUIBase *b, float screenx, float screeny, int buttonmask); void (*HandleKeyboard)(struct GUIBase *b, char c, int down, int focused); void (*DestroyMe)(struct GUIBase *b); void (*ProcessClick)(struct GUIBase *b); } *

user_defined_types: struct GUIBase { float x; float w; float color[4]; int depressed; int clicked; int focused; struct GUIWindow *wp; void (*Prerender)(struct GUIBase *b); void (*Render)(struct GUIBase *b); int (*CheckClick)(struct GUIBase *b, float screenx, float screeny, int button, int down); void (*HandleMove)(struct GUIBase *b, float screenx, float screeny, int buttonmask); void (*HandleKeyboard)(struct GUIBase *b, char c, int down, int focused); void (*DestroyMe)(struct GUIBase *b); void (*ProcessClick)(struct GUIBase *b); }

user_defined_types: struct GUIWindow { int width; int height; int focusid; struct RFBuffer *renderbuffer; struct Texture *torender; struct GUIBase *elements[2048]; }

user_defined_types: struct RFBuffer { int width; int use_depth_buffer; enum TextureType mtt; unsigned int renderbuffer; unsigned int outputbuffer; int outextures; }

user_defined_types: struct Texture { enum TextureType format; unsigned int type; unsigned int texture; int width; int slot; unsigned char *rawdata; }


idle

decompiled_code:
__int64 idle()
{
return glutPostRedisplay();
}

canonical_decompiled_code:
__int64 func0()
{
return glutPostRedisplay();
}

original_code:
void idle()
{
 glutPostRedisplay();
}

canonical_original_code:
void idle()
{
 glutPostRedisplay();
}


reshape

decompiled_code:
__int64 __fastcall reshape(int a1, int a2)
{
ScreenW = (float)a1;
ScreenH = (float)a2;
return glViewport(0LL, 0LL, (unsigned int)a1, (unsigned int)a2);
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, int a2)
{
ScreenW = (float)a1;
ScreenH = (float)a2;
return glViewport(0LL, 0LL, (unsigned int)a1, (unsigned int)a2);
}

original_code:
void reshape(int w, int h)
{
 ScreenW = w;
 ScreenH = h;
 glViewport(0, 0, w, h);
}

variable_types: w int

variable_types: h int


display

decompiled_code:
float *display()
{
double v0; // xmm0_8
float *result; // rax

v0 = OGGetAbsoluteTime() - StartTime;
TotalTime = *(_QWORD *)&v0;
DeltaTime = v0 - *(double *)&LastTime_0;
LastTime_0 = *(_QWORD *)&v0;
result = &ScreenW;
if ( ScreenW > 0.0 && (result = &ScreenH, ScreenH > 0.0) || v0 >= 1.0 )
{
if ( v0 > LastFPSTime + 1.0 )
{
LastFPSTime = LastFPSTime + 1.0;
fpscount = framecountsincefps;
printf("FPS: %d\n", framecountsincefps);
framecountsincefps = 0;
}
++framecountsincefps;
RenderW = LODWORD(ScreenW);
RenderH = LODWORD(ScreenH);
UpdatedDisplay();
result = (float *)glFlush();
}
return result;
}

canonical_decompiled_code:
float *func2()
{
double v0; // xmm0_8
float *result; // rax

v0 = OGGetAbsoluteTime() - StartTime;
TotalTime = *(_QWORD *)&v0;
DeltaTime = v0 - *(double *)&LastTime_0;
LastTime_0 = *(_QWORD *)&v0;
result = &ScreenW;
if ( ScreenW > 0.0 && (result = &ScreenH, ScreenH > 0.0) || v0 >= 1.0 )
{
if ( v0 > LastFPSTime + 1.0 )
{
LastFPSTime = LastFPSTime + 1.0;
fpscount = framecountsincefps;
printf("FPS: %d\n", framecountsincefps);
framecountsincefps = 0;
}
++framecountsincefps;
RenderW = LODWORD(ScreenW);
RenderH = LODWORD(ScreenH);
UpdatedDisplay();
result = (float *)glFlush();
}
return result;
}

original_code:
void display(void)
{
 static double LastTime;
 TotalTime = OGGetAbsoluteTime() - StartTime;
 DeltaTime = TotalTime - LastTime;
 LastTime = TotalTime;
 if( ( ScreenW <= 0 || ScreenH <= 0 ) && TotalTime < 1.0 ) return;
 if( LastFPSTime + 1 < TotalTime )
 {
  LastFPSTime += 1;
  fpscount = framecountsincefps;
  printf( "FPS: %d\n", fpscount );
  framecountsincefps = 0;
 }
 framecountsincefps++;
 RenderW = ScreenW;
 RenderH = ScreenH;
 UpdatedDisplay();
 glFlush();
}

canonical_original_code:
void display()
{
 static double LastTime;
 TotalTime = OGGetAbsoluteTime() - StartTime;
 DeltaTime = TotalTime - LastTime;
 LastTime = TotalTime;
 if( ( ScreenW <= 0 || ScreenH <= 0 ) && TotalTime < 1.0 ) return;
 if( LastFPSTime + 1 < TotalTime )
 {
  LastFPSTime += 1;
  fpscount = framecountsincefps;
  printf( "FPS: %d\n", fpscount );
  framecountsincefps = 0;
 }
 framecountsincefps++;
 RenderW = ScreenW;
 RenderH = ScreenH;
 UpdatedDisplay();
 glFlush();
}

variable_types: LastTime double


myupfunc

decompiled_code:
__int64 __fastcall myupfunc(unsigned __int8 a1)
{
return HandleKeyboard(a1, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned __int8 a1)
{
return HandleKeyboard(a1, 0LL);
}

original_code:
void myupfunc( unsigned char key, int x, int y )
{
 HandleKeyboard( key, 0 );
}

canonical_original_code:
void myupfunc(unsigned char key, int x, int y)
{
 HandleKeyboard( key, 0 );
}

variable_types:
key
unsigned char

variable_types: x int

variable_types: y int


mykeyfunc

decompiled_code:
__int64 __fastcall mykeyfunc(unsigned __int8 a1)
{
return HandleKeyboard(a1, 1LL);
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned __int8 a1)
{
return HandleKeyboard(a1, 1LL);
}

original_code:
void mykeyfunc( unsigned char key, int x, int y )
{
 HandleKeyboard( key, 1 );
}

canonical_original_code:
void mykeyfunc(unsigned char key, int x, int y)
{
 HandleKeyboard( key, 1 );
}


myspecialfunc

decompiled_code:
__int64 __fastcall myspecialfunc(__int64 a1)
{
return HandleKeyboard(a1, 1LL);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
return HandleKeyboard(a1, 1LL);
}

original_code:
void myspecialfunc( int key, int x, int y )
{
 HandleKeyboard( key, 1 );
}

canonical_original_code:
void myspecialfunc(int key, int x, int y)
{
 HandleKeyboard( key, 1 );
}

variable_types: key int


myspecialupfunc

decompiled_code:
__int64 __fastcall myspecialupfunc(__int64 a1)
{
return HandleKeyboard(a1, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
return HandleKeyboard(a1, 0LL);
}

original_code:
void myspecialupfunc( int key, int x, int y )
{
 HandleKeyboard( key, 0 );
}

canonical_original_code:
void myspecialupfunc(int key, int x, int y)
{
 HandleKeyboard( key, 0 );
}


mousepassive

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

if ( domousewarp )
{
absoluteMouseMotionX = (double)((int)a1 - (int)(float)(0.5 * RenderW)) + absoluteMouseMotionX;
absoluteMouseMotionY = (double)((int)a2 - (int)(float)(0.5 * RenderH)) + absoluteMouseMotionY;
glutWarpPointer();
result = MouseMotion(
(unsigned int)(a1 - (int)(float)(0.5 * RenderW)),
(unsigned int)(a2 - (int)(float)(0.5 * RenderH)),
(unsigned int)mousebuttonmask);
}
else
{
currentMouseY = (double)(int)a2;
currentMouseX = (double)(int)a1;
result = MouseMotion(a1, a2, (unsigned int)mousebuttonmask);
}
return result;
}

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

if ( domousewarp )
{
absoluteMouseMotionX = (double)((int)a1 - (int)(float)(0.5 * RenderW)) + absoluteMouseMotionX;
absoluteMouseMotionY = (double)((int)a2 - (int)(float)(0.5 * RenderH)) + absoluteMouseMotionY;
glutWarpPointer();
result = MouseMotion(
(unsigned int)(a1 - (int)(float)(0.5 * RenderW)),
(unsigned int)(a2 - (int)(float)(0.5 * RenderH)),
(unsigned int)mousebuttonmask);
}
else
{
currentMouseY = (double)(int)a2;
currentMouseX = (double)(int)a1;
result = MouseMotion(a1, a2, (unsigned int)mousebuttonmask);
}
return result;
}

original_code:
void mousepassive(int x, int y)
{
 if( domousewarp )
 {
  absoluteMouseMotionX += x - (int)(RenderW/2);
  absoluteMouseMotionY += y - (int)(RenderH/2);
  glutWarpPointer( (int)(RenderW/2), (int)(RenderH/2) );
  MouseMotion( x - (int)(RenderW/2), y - (int)(RenderH/2), mousebuttonmask );
 }
 else
 {
  currentMouseY = y;
  currentMouseX = x;
  MouseMotion( x, y, mousebuttonmask );
 }
}


mousemotion

decompiled_code:
__int64 __fastcall mousemotion(__int64 a1, __int64 a2)
{
return mousepassive(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2)
{
return func7(a1, a2);
}

original_code:
void mousemotion(int x, int y)
{
 mousepassive( x, y );
}


mousefunc

decompiled_code:
__int64 __fastcall mousefunc(char a1, int a2, int a3, int a4)
{
int v4; // eax
__int64 result; // rax

if ( a2 )
v4 = mousebuttonmask | (1 << a1);
else
v4 = mousebuttonmask & __ROL4__(-2, a1);
mousebuttonmask = v4;
if ( domousewarp )
result = MouseClick(absoluteMouseMotionX, absoluteMouseMotionY);
else
result = MouseClick((double)a3, (double)a4);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(char a1, int a2, int a3, int a4)
{
int v4; // eax
__int64 result; // rax

if ( a2 )
v4 = mousebuttonmask | (1 << a1);
else
v4 = mousebuttonmask & __ROL4__(-2, a1);
mousebuttonmask = v4;
if ( domousewarp )
result = MouseClick(absoluteMouseMotionX, absoluteMouseMotionY);
else
result = MouseClick((double)a3, (double)a4);
return result;
}

original_code:
void mousefunc( int button, int state, int x, int y )
{
 if( state )
 {
  mousebuttonmask |= 1<<button;
 }
 else
 {
  mousebuttonmask &= ~(1<<button);
 }
 if( domousewarp )
 {
  MouseClick( absoluteMouseMotionX, absoluteMouseMotionY, button, state );
 }
 else
 {
  double dx = x;
  double dy = y;
  MouseClick( dx, dy, button, state );
 }
}

canonical_original_code:
void mousefunc(int button, int state, int x, int y)
{
 if( state )
 {
  mousebuttonmask |= 1<<button;
 }
 else
 {
  mousebuttonmask &= ~(1<<button);
 }
 if( domousewarp )
 {
  MouseClick( absoluteMouseMotionX, absoluteMouseMotionY, button, state );
 }
 else
 {
  double dx = x;
  double dy = y;
  MouseClick( dx, dy, button, state );
 }
}

variable_types: dx double

variable_types: dy double