bittype

original_code:
int bittype(dbref player) {
  int level = 0;
  {if(debugmem && debugmem->stacktop < 1000) { debugmem->callstack[debugmem->stacktop].filenum = UTILS_C; debugmem->callstack[debugmem->stacktop++].linenum = 26; debugmem->stackval = (debugmem->stacktop > debugmem->stackval ? debugmem->stacktop : debugmem->stackval); } else if(debugmem) { printf("Debug Stack Overflow! (line %d of fp %d)\n", 26, UTILS_C); exit(1); }};
  if ( !((((player) >= 0) && ((player) < mudstate.db_top) && ((db[player].flags & 0x7) <= 0x4)) && !((db[player].flags & 0x00004000) != 0) && !((db[player].flags2 & 0x00400000) != 0)) )
     return 0;
  if( ((player) == ((dbref) 1)) ) {
    level = 7;
  } else if( (evlevchk(player,5) ? mudstate.evalresult : ((db[player].flags & 0x00200000) || ((player) == ((dbref) 1)) || ((db[db[player].owner].flags & 0x00200000) && (((db[player].flags & 0x02000000) != 0) || ((db[db[player].owner].flags & 0x02000000) != 0) || ((player) == db[player].owner))))) ) {
    level = 6;
  } else if( (evlevchk(player,4) ? mudstate.evalresult : ((db[player].flags & 0x00000010) || (evlevchk(player,5) ? mudstate.evalresult : ((db[player].flags & 0x00200000) || ((player) == ((dbref) 1)) || ((db[db[player].owner].flags & 0x00200000) && (((db[player].flags & 0x02000000) != 0) || ((db[db[player].owner].flags & 0x02000000) != 0) || ((player) == db[player].owner))))) || ((player) == ((dbref) 1)) || ((db[db[player].owner].flags & 0x00000010) && (((db[player].flags & 0x02000000) != 0) || ((db[db[player].owner].flags & 0x02000000) != 0) || ((player) == db[player].owner))))) ) {
    level = 5;
  } else if( (evlevchk(player,3) ? mudstate.evalresult : ((db[player].flags2 & 0x00000100) || (evlevchk(player,4) ? mudstate.evalresult : ((db[player].flags & 0x00000010) || (evlevchk(player,5) ? mudstate.evalresult : ((db[player].flags & 0x00200000) || ((player) == ((dbref) 1)) || ((db[db[player].owner].flags & 0x00200000) && (((db[player].flags & 0x02000000) != 0) || ((db[db[player].owner].flags & 0x02000000) != 0) || ((player) == db[player].owner))))) || ((player) == ((dbref) 1)) || ((db[db[player].owner].flags & 0x00000010) && (((db[player].flags & 0x02000000) != 0) || ((db[db[player].owner].flags & 0x02000000) != 0) || ((player) == db[player].owner))))) || ((db[db[player].owner].flags2 & 0x00000100) && (((db[player].flags & 0x02000000) != 0) || ((db[db[player].owner].flags & 0x02000000) != 0) || ((player) == db[player].owner))))) ) {
    level = 4;
  } else if( (evlevchk(player,2) ? mudstate.evalresult : ((db[player].flags2 & 0x20000000) || (evlevchk(player,3) ? mudstate.evalresult : ((db[player].flags2 & 0x00000100) || (evlevchk(player,4) ? mudstate.evalresult : ((db[player].flags & 0x00000010) || (evlevchk(player,5) ? mudstate.evalresult : ((db[player].flags & 0x00200000) || ((player) == ((dbref) 1)) || ((db[db[player].owner].flags & 0x00200000) && (((db[player].flags & 0x02000000) != 0) || ((db[db[player].owner].flags & 0x02000000) != 0) || ((player) == db[player].owner))))) || ((player) == ((dbref) 1)) || ((db[db[player].owner].flags & 0x00000010) && (((db[player].flags & 0x02000000) != 0) || ((db[db[player].owner].flags & 0x02000000) != 0) || ((player) == db[player].owner))))) || ((db[db[player].owner].flags2 & 0x00000100) && (((db[player].flags & 0x02000000) != 0) || ((db[db[player].owner].flags & 0x02000000) != 0) || ((player) == db[player].owner))))) || ((db[db[player].owner].flags2 & 0x20000000) && (((db[player].flags & 0x02000000) != 0) || ((db[db[player].owner].flags & 0x02000000) != 0) || ((player) == db[player].owner))))) ) {
    level = 3;
  } else if( (evlevchk(player,1) ? mudstate.evalresult : ((db[player].flags2 & 0x00000400) || (evlevchk(player,2) ? mudstate.evalresult : ((db[player].flags2 & 0x20000000) || (evlevchk(player,3) ? mudstate.evalresult : ((db[player].flags2 & 0x00000100) || (evlevchk(player,4) ? mudstate.evalresult : ((db[player].flags & 0x00000010) || (evlevchk(player,5) ? mudstate.evalresult : ((db[player].flags & 0x00200000) || ((player) == ((dbref) 1)) || ((db[db[player].owner].flags & 0x00200000) && (((db[player].flags & 0x02000000) != 0) || ((db[db[player].owner].flags & 0x02000000) != 0) || ((player) == db[player].owner))))) || ((player) == ((dbref) 1)) || ((db[db[player].owner].flags & 0x00000010) && (((db[player].flags & 0x02000000) != 0) || ((db[db[player].owner].flags & 0x02000000) != 0) || ((player) == db[player].owner))))) || ((db[db[player].owner].flags2 & 0x00000100) && (((db[player].flags & 0x02000000) != 0) || ((db[db[player].owner].flags & 0x02000000) != 0) || ((player) == db[player].owner))))) || ((db[db[player].owner].flags2 & 0x20000000) && (((db[player].flags & 0x02000000) != 0) || ((db[db[player].owner].flags & 0x02000000) != 0) || ((player) == db[player].owner))))) || (evlevchk(player,3) ? mudstate.evalresult : ((db[player].flags2 & 0x00000100) || (evlevchk(player,4) ? mudstate.evalresult : ((db[player].flags & 0x00000010) || (evlevchk(player,5) ? mudstate.evalresult : ((db[player].flags & 0x00200000) || ((player) == ((dbref) 1)) || ((db[db[player].owner].flags & 0x00200000) && (((db[player].flags & 0x02000000) != 0) || ((db[db[player].owner].flags & 0x02000000) != 0) || ((player) == db[player].owner))))) || ((player) == ((dbref) 1)) || ((db[db[player].owner].flags & 0x00000010) && (((db[player].flags & 0x02000000) != 0) || ((db[db[player].owner].flags & 0x02000000) != 0) || ((player) == db[player].owner))))) || ((db[db[player].owner].flags2 & 0x00000100) && (((db[player].flags & 0x02000000) != 0) || ((db[db[player].owner].flags & 0x02000000) != 0) || ((player) == db[player].owner))))) || (evlevchk(player,4) ? mudstate.evalresult : ((db[player].flags & 0x00000010) || (evlevchk(player,5) ? mudstate.evalresult : ((db[player].flags & 0x00200000) || ((player) == ((dbref) 1)) || ((db[db[player].owner].flags & 0x00200000) && (((db[player].flags & 0x02000000) != 0) || ((db[db[player].owner].flags & 0x02000000) != 0) || ((player) == db[player].owner))))) || ((player) == ((dbref) 1)) || ((db[db[player].owner].flags & 0x00000010) && (((db[player].flags & 0x02000000) != 0) || ((db[db[player].owner].flags & 0x02000000) != 0) || ((player) == db[player].owner))))) || ((db[db[player].owner].flags2 & 0x00000400) && (((db[player].flags & 0x02000000) != 0) || ((db[db[player].owner].flags & 0x02000000) != 0) || ((player) == db[player].owner))))) ) {
    level = 2;
  } else if( (((db[player].flags2 & 0x01000000) != 0) || ((((db[player].owner) >= 0) && ((db[player].owner) < mudstate.db_top) && ((db[db[player].owner].flags & 0x7) <= 0x4)) && (db[db[player].owner].flags2 & 0x01000000) != 0)) || (((db[player].flags2 & 0x00200000) != 0) || ((((db[player].owner) >= 0) && ((db[player].owner) < mudstate.db_top) && ((db[db[player].owner].flags & 0x7) <= 0x4)) && (db[db[player].owner].flags2 & 0x00200000) != 0)) ) {
    level = 0;
  } else {
    level = 1;
  }
  {{if(debugmem && debugmem->stacktop > 0) { debugmem->stacktop--; } else if(debugmem) { printf("Debug Stack Underflow! (line %d of fp %d)\n",47, UTILS_C); exit(1); }}; return (level);};
}

canonical_original_code:
int bittype(int player) {
  int level = 0;
  {if(debugmem && debugmem->stacktop < 1000) { debugmem->callstack[debugmem->stacktop].filenum = UTILS_C; debugmem->callstack[debugmem->stacktop++].linenum = 26; debugmem->stackval = (debugmem->stacktop > debugmem->stackval ? debugmem->stacktop : debugmem->stackval); } else if(debugmem) { printf("Debug Stack Overflow! (line %d of fp %d)\n", 26, UTILS_C); exit(1); }};
  if ( !((((player) >= 0) && ((player) < mudstate.db_top) && ((db[player].flags & 0x7) <= 0x4)) && !((db[player].flags & 0x00004000) != 0) && !((db[player].flags2 & 0x00400000) != 0)) )
     return 0;
  if( ((player) == ((int) 1)) ) {
    level = 7;
  } else if( (evlevchk(player,5) ? mudstate.evalresult : ((db[player].flags & 0x00200000) || ((player) == ((int) 1)) || ((db[db[player].owner].flags & 0x00200000) && (((db[player].flags & 0x02000000) != 0) || ((db[db[player].owner].flags & 0x02000000) != 0) || ((player) == db[player].owner))))) ) {
    level = 6;
  } else if( (evlevchk(player,4) ? mudstate.evalresult : ((db[player].flags & 0x00000010) || (evlevchk(player,5) ? mudstate.evalresult : ((db[player].flags & 0x00200000) || ((player) == ((int) 1)) || ((db[db[player].owner].flags & 0x00200000) && (((db[player].flags & 0x02000000) != 0) || ((db[db[player].owner].flags & 0x02000000) != 0) || ((player) == db[player].owner))))) || ((player) == ((int) 1)) || ((db[db[player].owner].flags & 0x00000010) && (((db[player].flags & 0x02000000) != 0) || ((db[db[player].owner].flags & 0x02000000) != 0) || ((player) == db[player].owner))))) ) {
    level = 5;
  } else if( (evlevchk(player,3) ? mudstate.evalresult : ((db[player].flags2 & 0x00000100) || (evlevchk(player,4) ? mudstate.evalresult : ((db[player].flags & 0x00000010) || (evlevchk(player,5) ? mudstate.evalresult : ((db[player].flags & 0x00200000) || ((player) == ((int) 1)) || ((db[db[player].owner].flags & 0x00200000) && (((db[player].flags & 0x02000000) != 0) || ((db[db[player].owner].flags & 0x02000000) != 0) || ((player) == db[player].owner))))) || ((player) == ((int) 1)) || ((db[db[player].owner].flags & 0x00000010) && (((db[player].flags & 0x02000000) != 0) || ((db[db[player].owner].flags & 0x02000000) != 0) || ((player) == db[player].owner))))) || ((db[db[player].owner].flags2 & 0x00000100) && (((db[player].flags & 0x02000000) != 0) || ((db[db[player].owner].flags & 0x02000000) != 0) || ((player) == db[player].owner))))) ) {
    level = 4;
  } else if( (evlevchk(player,2) ? mudstate.evalresult : ((db[player].flags2 & 0x20000000) || (evlevchk(player,3) ? mudstate.evalresult : ((db[player].flags2 & 0x00000100) || (evlevchk(player,4) ? mudstate.evalresult : ((db[player].flags & 0x00000010) || (evlevchk(player,5) ? mudstate.evalresult : ((db[player].flags & 0x00200000) || ((player) == ((int) 1)) || ((db[db[player].owner].flags & 0x00200000) && (((db[player].flags & 0x02000000) != 0) || ((db[db[player].owner].flags & 0x02000000) != 0) || ((player) == db[player].owner))))) || ((player) == ((int) 1)) || ((db[db[player].owner].flags & 0x00000010) && (((db[player].flags & 0x02000000) != 0) || ((db[db[player].owner].flags & 0x02000000) != 0) || ((player) == db[player].owner))))) || ((db[db[player].owner].flags2 & 0x00000100) && (((db[player].flags & 0x02000000) != 0) || ((db[db[player].owner].flags & 0x02000000) != 0) || ((player) == db[player].owner))))) || ((db[db[player].owner].flags2 & 0x20000000) && (((db[player].flags & 0x02000000) != 0) || ((db[db[player].owner].flags & 0x02000000) != 0) || ((player) == db[player].owner))))) ) {
    level = 3;
  } else if( (evlevchk(player,1) ? mudstate.evalresult : ((db[player].flags2 & 0x00000400) || (evlevchk(player,2) ? mudstate.evalresult : ((db[player].flags2 & 0x20000000) || (evlevchk(player,3) ? mudstate.evalresult : ((db[player].flags2 & 0x00000100) || (evlevchk(player,4) ? mudstate.evalresult : ((db[player].flags & 0x00000010) || (evlevchk(player,5) ? mudstate.evalresult : ((db[player].flags & 0x00200000) || ((player) == ((int) 1)) || ((db[db[player].owner].flags & 0x00200000) && (((db[player].flags & 0x02000000) != 0) || ((db[db[player].owner].flags & 0x02000000) != 0) || ((player) == db[player].owner))))) || ((player) == ((int) 1)) || ((db[db[player].owner].flags & 0x00000010) && (((db[player].flags & 0x02000000) != 0) || ((db[db[player].owner].flags & 0x02000000) != 0) || ((player) == db[player].owner))))) || ((db[db[player].owner].flags2 & 0x00000100) && (((db[player].flags & 0x02000000) != 0) || ((db[db[player].owner].flags & 0x02000000) != 0) || ((player) == db[player].owner))))) || ((db[db[player].owner].flags2 & 0x20000000) && (((db[player].flags & 0x02000000) != 0) || ((db[db[player].owner].flags & 0x02000000) != 0) || ((player) == db[player].owner))))) || (evlevchk(player,3) ? mudstate.evalresult : ((db[player].flags2 & 0x00000100) || (evlevchk(player,4) ? mudstate.evalresult : ((db[player].flags & 0x00000010) || (evlevchk(player,5) ? mudstate.evalresult : ((db[player].flags & 0x00200000) || ((player) == ((int) 1)) || ((db[db[player].owner].flags & 0x00200000) && (((db[player].flags & 0x02000000) != 0) || ((db[db[player].owner].flags & 0x02000000) != 0) || ((player) == db[player].owner))))) || ((player) == ((int) 1)) || ((db[db[player].owner].flags & 0x00000010) && (((db[player].flags & 0x02000000) != 0) || ((db[db[player].owner].flags & 0x02000000) != 0) || ((player) == db[player].owner))))) || ((db[db[player].owner].flags2 & 0x00000100) && (((db[player].flags & 0x02000000) != 0) || ((db[db[player].owner].flags & 0x02000000) != 0) || ((player) == db[player].owner))))) || (evlevchk(player,4) ? mudstate.evalresult : ((db[player].flags & 0x00000010) || (evlevchk(player,5) ? mudstate.evalresult : ((db[player].flags & 0x00200000) || ((player) == ((int) 1)) || ((db[db[player].owner].flags & 0x00200000) && (((db[player].flags & 0x02000000) != 0) || ((db[db[player].owner].flags & 0x02000000) != 0) || ((player) == db[player].owner))))) || ((player) == ((int) 1)) || ((db[db[player].owner].flags & 0x00000010) && (((db[player].flags & 0x02000000) != 0) || ((db[db[player].owner].flags & 0x02000000) != 0) || ((player) == db[player].owner))))) || ((db[db[player].owner].flags2 & 0x00000400) && (((db[player].flags & 0x02000000) != 0) || ((db[db[player].owner].flags & 0x02000000) != 0) || ((player) == db[player].owner))))) ) {
    level = 2;
  } else if( (((db[player].flags2 & 0x01000000) != 0) || ((((db[player].owner) >= 0) && ((db[player].owner) < mudstate.db_top) && ((db[db[player].owner].flags & 0x7) <= 0x4)) && (db[db[player].owner].flags2 & 0x01000000) != 0)) || (((db[player].flags2 & 0x00200000) != 0) || ((((db[player].owner) >= 0) && ((db[player].owner) < mudstate.db_top) && ((db[db[player].owner].flags & 0x7) <= 0x4)) && (db[db[player].owner].flags2 & 0x00200000) != 0)) ) {
    level = 0;
  } else {
    level = 1;
  }
  {{if(debugmem && debugmem->stacktop > 0) { debugmem->stacktop--; } else if(debugmem) { printf("Debug Stack Underflow! (line %d of fp %d)\n",47, UTILS_C); exit(1); }}; return (level);};
}

variable_types: level int


repo: kenneaal/RhostMUSH

decompiled_code:
__int64 __fastcall log_db_err(unsigned int a1, unsigned int a2, __int64 a3)
{
__int64 result; // rax

result = mudconf[2026];
if ( (int)result < 0 )
{
result = start_log("DBM", "ERROR");
if ( (_DWORD)result )
{
log_text("Could not ");
log_text(a3);
log_text(" object #");
log_number(a1);
if ( a2 != -1 )
{
log_text(" attr #");
log_number(a2);
}
result = end_log();
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, unsigned int a2, __int64 a3)
{
__int64 result; // rax

result = mudconf[2026];
if ( (int)result < 0 )
{
result = start_log("DBM", "ERROR");
if ( (_DWORD)result )
{
log_text("Could not ");
log_text(a3);
log_text(" object #");
log_number(a1);
if ( a2 != -1 )
{
log_text(" attr #");
log_number(a2);
}
result = end_log();
}
}
return result;
}

original_code:
void log_db_err (int obj, int attr, const char *txt)
{
 if ((((0x80000000) & mudconf.log_options) != 0) && start_log("DBM", "ERROR")) {
  log_text((char *)"Could not ");
  log_text((char *)txt);
  log_text((char *)" object #");
  log_number(obj);
  if (attr != (-1)) {
   log_text((char *)" attr #");
   log_number(attr);
  }
 end_log(); }
}

canonical_original_code:
void log_db_err(int obj, int attr, char *txt)
{
 if ((((0x80000000) & mudconf.log_options) != 0) && start_log("DBM", "ERROR")) {
  log_text((char *)"Could not ");
  log_text((char *)txt);
  log_text((char *)" object #");
  log_number(obj);
  if (attr != (-1)) {
   log_text((char *)" attr #");
   log_number(attr);
  }
 end_log(); }
}

variable_types: obj int

variable_types: attr int

variable_types:
txt
char *

return_type: void


shmConnect

decompiled_code:
void *__fastcall shmConnect(key_t key, int a2, int *a3)
{
char *v5; // rax
int v6; // edi
void *result; // rax
bool v8; // dl
int v9; // edi
int v10; // eax
int v11; // eax
int v12; // eax

*a3 = shmget(key, 0x1F54uLL, a2 == 0 ? 448 : 1984);
v5 = getenv("DEBUG_OVERRIDE");
v6 = *a3;
if ( !v5 )
goto LABEL_18;
if ( v6 >= 0 )
goto LABEL_3;
if ( *v5 == 49 && !v5[1] )
{
v11 = shmget(key, 0x1F54uLL, 960);
*a3 = v11;
if ( v11 < 0 )
{
fprintf(stderr, "** Warning - debug_id '%d' not able to be attached to ** \n", (unsigned int)key);
}
else if ( shmctl(v11, 0, 0LL) < 0 )
{
fprintf(stderr, "** Warning - debug_id '%d' was unable to be cleared **\n", (unsigned int)key);
}
else
{
fprintf(stderr, "** Warning - debug_id '%d' overridden and cleared **\n", (unsigned int)key);
}
v12 = shmget(key, 0x1F54uLL, a2 == 0 ? 448 : 1984);
*a3 = v12;
v6 = v12;
LABEL_18:
if ( v6 >= 0 )
{
LABEL_3:
result = shmat(v6, 0LL, 0);
if ( result == (void *)-1LL )
{
perror("** IPC Error (shmat)");
shmdt((const void *)0xFFFFFFFFFFFFFFFFLL);
shmctl(*a3, 0, 0LL);
v8 = 0;
v9 = 2;
result = 0LL;
}
else
{
v8 = result != 0LL;
v9 = 0;
}
goto LABEL_5;
}
}
v10 = *_errno_location();
if ( v10 == 17 )
{
fprintf(
stderr,
"** Error - possible clash detected for debug_id **\n** Shared memory region already exists for '%d' **\n",
(unsigned int)key);
}
else
{
if ( v10 != 2 )
{
perror("** IPC Error (shmget)");
v9 = 1;
if ( !a2 )
{
fwrite("** Try changing debug_id? ** \n", 1uLL, 0x1EuLL, stderr);
return 0LL;
}
LABEL_12:
exit(v9);
}
fprintf(stderr, "** No shared memory region could be found for debug_id '%d'**\n", (unsigned int)key);
}
v8 = 0;
v9 = 1;
result = 0LL;
LABEL_5:
if ( a2 && !v8 )
goto LABEL_12;
return result;
}

canonical_decompiled_code:
void *__fastcall func0(key_t key, int a2, int *a3)
{
char *v5; // rax
int v6; // edi
void *result; // rax
bool v8; // dl
int v9; // edi
int v10; // eax
int v11; // eax
int v12; // eax

*a3 = shmget(key, 0x1F54uLL, a2 == 0 ? 448 : 1984);
v5 = getenv("DEBUG_OVERRIDE");
v6 = *a3;
if ( !v5 )
goto LABEL_18;
if ( v6 >= 0 )
goto LABEL_3;
if ( *v5 == 49 && !v5[1] )
{
v11 = shmget(key, 0x1F54uLL, 960);
*a3 = v11;
if ( v11 < 0 )
{
fprintf(stderr, "** Warning - debug_id '%d' not able to be attached to ** \n", (unsigned int)key);
}
else if ( shmctl(v11, 0, 0LL) < 0 )
{
fprintf(stderr, "** Warning - debug_id '%d' was unable to be cleared **\n", (unsigned int)key);
}
else
{
fprintf(stderr, "** Warning - debug_id '%d' overridden and cleared **\n", (unsigned int)key);
}
v12 = shmget(key, 0x1F54uLL, a2 == 0 ? 448 : 1984);
*a3 = v12;
v6 = v12;
LABEL_18:
if ( v6 >= 0 )
{
LABEL_3:
result = shmat(v6, 0LL, 0);
if ( result == (void *)-1LL )
{
perror("** IPC Error (shmat)");
shmdt((const void *)0xFFFFFFFFFFFFFFFFLL);
shmctl(*a3, 0, 0LL);
v8 = 0;
v9 = 2;
result = 0LL;
}
else
{
v8 = result != 0LL;
v9 = 0;
}
goto LABEL_5;
}
}
v10 = *_errno_location();
if ( v10 == 17 )
{
fprintf(
stderr,
"** Error - possible clash detected for debug_id **\n** Shared memory region already exists for '%d' **\n",
(unsigned int)key);
}
else
{
if ( v10 != 2 )
{
perror("** IPC Error (shmget)");
v9 = 1;
if ( !a2 )
{
fwrite("** Try changing debug_id? ** \n", 1uLL, 0x1EuLL, stderr);
return 0LL;
}
LABEL_12:
exit(v9);
}
fprintf(stderr, "** No shared memory region could be found for debug_id '%d'**\n", (unsigned int)key);
}
v8 = 0;
v9 = 1;
result = 0LL;
LABEL_5:
if ( a2 && !v8 )
goto LABEL_12;
return result;
}

original_code:
Debugmem * shmConnect(int debug_id, int bCreate, int *pShmid) {
  char *shm = ((void *)0), *env_var = ((void *)0);
  int exitCode = 0;
  int mask = 0700;
  if (bCreate) mask |= 01000 | 02000;
  (*pShmid) = shmget(debug_id, sizeof(Debugmem), mask );
  env_var = getenv("DEBUG_OVERRIDE");
  if ( ((*pShmid) < 0) && (env_var != ((void *)0)) && (strcmp(env_var, "1") == 0) ) {
     (*pShmid) = shmget(debug_id, sizeof(Debugmem), (0700 | 01000) );
     if ( (*pShmid) < 0 ) {
        fprintf(stderr, "** Warning - debug_id '%d' not able to be attached to ** \n", debug_id);
     } else {
        exitCode = shmctl((*pShmid), 0, ((void *)0));
        if ( exitCode < 0 )
           fprintf(stderr, "** Warning - debug_id '%d' was unable to be cleared **\n", debug_id);
        else
           fprintf(stderr, "** Warning - debug_id '%d' overridden and cleared **\n", debug_id);
        exitCode = 0;
     }
     (*pShmid) = shmget(debug_id, sizeof(Debugmem), mask );
  }
  if ((*pShmid) < 0 ) {
    if ((*__errno_location ()) == 17) {
      fprintf(stderr,
       "** Error - possible clash detected for debug_id **\n"
       "** Shared memory region already exists for '%d' **\n", debug_id);
    } else if ((*__errno_location ()) == 2) {
      fprintf(stderr,
       "** No shared memory region could be found for debug_id '%d'**\n",
       debug_id);
    } else {
      perror("** IPC Error (shmget)");
      if (!bCreate) fprintf(stderr, "** Try changing debug_id? ** \n");
    }
    shm = ((void *)0);
    exitCode = 1;
  } else {
    if((shm = shmat((*pShmid), ((void *)0), 0)) == (char *) -1) {
      perror("** IPC Error (shmat)");
      shmdt(shm);
      shmctl((*pShmid), 0, ((void *)0));
      shm = ((void *)0);
      exitCode = 2;
    }
  }
  if (shm || !bCreate) {
    return (Debugmem *) shm;
  } else {
    exit(exitCode);
  }
}

canonical_original_code:
struct Debugmem *shmConnect(int debug_id, int bCreate, int *pShmid) {
  char *shm = ((void *)0); char *env_var = ((void *)0);
  int exitCode = 0;
  int mask = 0700;
  if (bCreate) mask |= 01000 | 02000;
  (*pShmid) = shmget(debug_id, sizeof(Debugmem), mask );
  env_var = getenv("DEBUG_OVERRIDE");
  if ( ((*pShmid) < 0) && (env_var != ((void *)0)) && (strcmp(env_var, "1") == 0) ) {
     (*pShmid) = shmget(debug_id, sizeof(Debugmem), (0700 | 01000) );
     if ( (*pShmid) < 0 ) {
        fprintf(stderr, "** Warning - debug_id '%d' not able to be attached to ** \n", debug_id);
     } else {
        exitCode = shmctl((*pShmid), 0, ((void *)0));
        if ( exitCode < 0 )
           fprintf(stderr, "** Warning - debug_id '%d' was unable to be cleared **\n", debug_id);
        else
           fprintf(stderr, "** Warning - debug_id '%d' overridden and cleared **\n", debug_id);
        exitCode = 0;
     }
     (*pShmid) = shmget(debug_id, sizeof(Debugmem), mask );
  }
  if ((*pShmid) < 0 ) {
    if ((*__errno_location ()) == 17) {
      fprintf(stderr,
       "** Error - possible clash detected for debug_id **\n"
       "** Shared memory region already exists for '%d' **\n", debug_id);
    } else if ((*__errno_location ()) == 2) {
      fprintf(stderr,
       "** No shared memory region could be found for debug_id '%d'**\n",
       debug_id);
    } else {
      perror("** IPC Error (shmget)");
      if (!bCreate) fprintf(stderr, "** Try changing debug_id? ** \n");
    }
    shm = ((void *)0);
    exitCode = 1;
  } else {
    if((shm = shmat((*pShmid), ((void *)0), 0)) == (char *) -1) {
      perror("** IPC Error (shmat)");
      shmdt(shm);
      shmctl((*pShmid), 0, ((void *)0));
      shm = ((void *)0);
      exitCode = 2;
    }
  }
  if (shm || !bCreate) {
    return (struct Debugmem *) shm;
  } else {
    exit(exitCode);
  }
}

variable_types: bCreate int

variable_types:
pShmid
int *

variable_types:
shm
char *

variable_types: exitCode int

variable_types: mask int

return_type: struct Debugmem { int mushport; int debugport; int lastdbfetch; int stacktop; int stackval; struct { int filenum; int linenum; } callstack[1000]; } *


sorttopics

original_code:
void sorttopics( void )
{
  int j, k;
  help_indx temp;
  for( j = 0; j < ntopics; j++ ) {
    for( k = j + 1; k < ntopics; k++ ) {
      if( strcmp(alltopicslc[j].topic, alltopicslc[k].topic) > 0 ) {
        memcpy( &temp, &alltopicslc[j], sizeof(help_indx));
        memcpy( &alltopicslc[j], &alltopicslc[k], sizeof(help_indx));
        memcpy( &alltopicslc[k], &temp, sizeof(help_indx));
        memcpy( &temp, &alltopics[j], sizeof(help_indx));
        memcpy( &alltopics[j], &alltopics[k], sizeof(help_indx));
        memcpy( &alltopics[k], &temp, sizeof(help_indx));
      }
    }
  }
}

canonical_original_code:
void sorttopics()
{
  int j; int k;
  struct help_indx temp;
  for( j = 0; j < ntopics; j++ ) {
    for( k = j + 1; k < ntopics; k++ ) {
      if( strcmp(alltopicslc[j].topic, alltopicslc[k].topic) > 0 ) {
        memcpy( &temp, &alltopicslc[j], sizeof(help_indx));
        memcpy( &alltopicslc[j], &alltopicslc[k], sizeof(help_indx));
        memcpy( &alltopicslc[k], &temp, sizeof(help_indx));
        memcpy( &temp, &alltopics[j], sizeof(help_indx));
        memcpy( &alltopics[j], &alltopics[k], sizeof(help_indx));
        memcpy( &alltopics[k], &temp, sizeof(help_indx));
      }
    }
  }
}

variable_types: j int

variable_types: k int

variable_types: struct help_indx { long pos; int len; char topic[-1]; }


decompiled_code:
__int64 __fastcall real_hashval(_BYTE *a1, unsigned int a2)
{
int v3; // eax
int v4; // esi

if ( !a1 )
return 0LL;
v3 = (char)*a1;
if ( !*a1 )
return 0LL;
v4 = 0;
do
{
++a1;
v4 = v3 + 33 * v4;
v3 = (char)*a1;
}
while ( *a1 );
return v4 & a2;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1, unsigned int a2)
{
int v3; // eax
int v4; // esi

if ( !a1 )
return 0LL;
v3 = (char)*a1;
if ( !*a1 )
return 0LL;
v4 = 0;
do
{
++a1;
v4 = v3 + 33 * v4;
v3 = (char)*a1;
}
while ( *a1 );
return v4 & a2;
}

original_code:
int real_hashval(char *str, int hashmask, const char *fileName, int lineNo)
{
    int hash;
    char *sp;
    if (str == ((void *)0))
 return 0;
    hash = 0;
    for (sp = str; *sp; sp++)
 hash = (hash << 5) + hash + *sp;
    return (hash & hashmask);
}

canonical_original_code:
int real_hashval(char *str, int hashmask, char *fileName, int lineNo)
{
    int hash;
    char *sp;
    if (str == ((void *)0))
 return 0;
    hash = 0;
    for (sp = str; *sp; sp++)
 hash = (hash << 5) + hash + *sp;
    return (hash & hashmask);
}

variable_types:
str
char *

variable_types: hashmask int

variable_types:
fileName
char *

variable_types: lineNo int

variable_types: hash int

variable_types:
sp
char *

return_type: int


info

decompiled_code:
int __fastcall info(int a1, int a2, unsigned int a3)
{
__int64 v3; // rax
const char *v5; // rdx

v3 = (unsigned int)(a1 - 1);
v5 = "*unknown*";
if ( (unsigned int)v3 <= 3 )
v5 = CSWTCH_49[v3];
fprintf(stderr, "%s version %d:", v5, a3);
if ( (a2 & 0x100) != 0 )
fwrite(" Zone", 1uLL, 5uLL, stderr);
if ( (a2 & 0x200) != 0 )
fwrite(" Link", 1uLL, 5uLL, stderr);
if ( (a2 & 0x400) != 0 )
fwrite(" GDBM", 1uLL, 5uLL, stderr);
if ( (a2 & 0x800) != 0 )
fwrite(" AtrName", 1uLL, 8uLL, stderr);
if ( (a2 & 0x1000) == 0 )
{
LABEL_15:
if ( (a2 & 0x2000) == 0 )
goto LABEL_16;
goto LABEL_21;
}
if ( a1 == 1 && a3 == 2 )
{
fwrite(" ExtLocks", 1uLL, 9uLL, stderr);
goto LABEL_15;
}
fwrite(" AtrKey", 1uLL, 7uLL, stderr);
if ( (a2 & 0x2000) == 0 )
{
LABEL_16:
if ( (a2 & 0x4000) == 0 )
goto LABEL_17;
goto LABEL_22;
}
LABEL_21:
fwrite(" Parent", 1uLL, 7uLL, stderr);
if ( (a2 & 0x4000) == 0 )
{
LABEL_17:
if ( (a2 & 0x8000) == 0 )
goto LABEL_18;
LABEL_23:
fwrite(" AtrMoney", 1uLL, 9uLL, stderr);
if ( (a2 & 0x10000) == 0 )
return fputc(10, stderr);
LABEL_24:
fwrite(" ExtFlags", 1uLL, 9uLL, stderr);
return fputc(10, stderr);
}
LABEL_22:
fwrite(" Comm", 1uLL, 5uLL, stderr);
if ( (a2 & 0x8000) != 0 )
goto LABEL_23;
LABEL_18:
if ( (a2 & 0x10000) != 0 )
goto LABEL_24;
return fputc(10, stderr);
}

canonical_decompiled_code:
int __fastcall func0(int a1, int a2, unsigned int a3)
{
__int64 v3; // rax
const char *v5; // rdx

v3 = (unsigned int)(a1 - 1);
v5 = "*unknown*";
if ( (unsigned int)v3 <= 3 )
v5 = CSWTCH_49[v3];
fprintf(stderr, "%s version %d:", v5, a3);
if ( (a2 & 0x100) != 0 )
fwrite(" Zone", 1uLL, 5uLL, stderr);
if ( (a2 & 0x200) != 0 )
fwrite(" Link", 1uLL, 5uLL, stderr);
if ( (a2 & 0x400) != 0 )
fwrite(" GDBM", 1uLL, 5uLL, stderr);
if ( (a2 & 0x800) != 0 )
fwrite(" AtrName", 1uLL, 8uLL, stderr);
if ( (a2 & 0x1000) == 0 )
{
LABEL_15:
if ( (a2 & 0x2000) == 0 )
goto LABEL_16;
goto LABEL_21;
}
if ( a1 == 1 && a3 == 2 )
{
fwrite(" ExtLocks", 1uLL, 9uLL, stderr);
goto LABEL_15;
}
fwrite(" AtrKey", 1uLL, 7uLL, stderr);
if ( (a2 & 0x2000) == 0 )
{
LABEL_16:
if ( (a2 & 0x4000) == 0 )
goto LABEL_17;
goto LABEL_22;
}
LABEL_21:
fwrite(" Parent", 1uLL, 7uLL, stderr);
if ( (a2 & 0x4000) == 0 )
{
LABEL_17:
if ( (a2 & 0x8000) == 0 )
goto LABEL_18;
LABEL_23:
fwrite(" AtrMoney", 1uLL, 9uLL, stderr);
if ( (a2 & 0x10000) == 0 )
return fputc(10, stderr);
LABEL_24:
fwrite(" ExtFlags", 1uLL, 9uLL, stderr);
return fputc(10, stderr);
}
LABEL_22:
fwrite(" Comm", 1uLL, 5uLL, stderr);
if ( (a2 & 0x8000) != 0 )
goto LABEL_23;
LABEL_18:
if ( (a2 & 0x10000) != 0 )
goto LABEL_24;
return fputc(10, stderr);
}

original_code:
void
info(int fmt, int flags, int ver)
{
    const char *cp;
    switch (fmt) {
    case 1:
 cp = "TinyMUSH";
 break;
    case 2:
 cp = "TinyMUSE";
 break;
    case 3:
 cp = "TinyMUD";
 break;
    case 4:
 cp = "TinyMUCK";
 break;
    default:
 cp = "*unknown*";
 break;
    }
    fprintf(stderr, "%s version %d:", cp, ver);
    if (flags & 0x00000100)
 fprintf(stderr, " Zone");
    if (flags & 0x00000200)
 fprintf(stderr, " Link");
    if (flags & 0x00000400)
 fprintf(stderr, " GDBM");
    if (flags & 0x00000800)
 fprintf(stderr, " AtrName");
    if (flags & 0x00001000) {
 if ((fmt == 1) && (ver == 2))
     fprintf(stderr, " ExtLocks");
 else
     fprintf(stderr, " AtrKey");
    }
    if (flags & 0x00002000)
 fprintf(stderr, " Parent");
    if (flags & 0x00004000)
 fprintf(stderr, " Comm");
    if (flags & 0x00008000)
 fprintf(stderr, " AtrMoney");
    if (flags & 0x00010000)
 fprintf(stderr, " ExtFlags");
    fprintf(stderr, "\n");
}

canonical_original_code:
void info(int fmt, int flags, int ver)
{
    char *cp;
    switch (fmt) {
    case 1:
 cp = "TinyMUSH";
 break;
    case 2:
 cp = "TinyMUSE";
 break;
    case 3:
 cp = "TinyMUD";
 break;
    case 4:
 cp = "TinyMUCK";
 break;
    default:
 cp = "*unknown*";
 break;
    }
    fprintf(stderr, "%s version %d:", cp, ver);
    if (flags & 0x00000100)
 fprintf(stderr, " Zone");
    if (flags & 0x00000200)
 fprintf(stderr, " Link");
    if (flags & 0x00000400)
 fprintf(stderr, " GDBM");
    if (flags & 0x00000800)
 fprintf(stderr, " AtrName");
    if (flags & 0x00001000) {
 if ((fmt == 1) && (ver == 2))
     fprintf(stderr, " ExtLocks");
 else
     fprintf(stderr, " AtrKey");
    }
    if (flags & 0x00002000)
 fprintf(stderr, " Parent");
    if (flags & 0x00004000)
 fprintf(stderr, " Comm");
    if (flags & 0x00008000)
 fprintf(stderr, " AtrMoney");
    if (flags & 0x00010000)
 fprintf(stderr, " ExtFlags");
    fprintf(stderr, "\n");
}

variable_types: fmt int

variable_types: flags int

variable_types: ver int

variable_types:
cp
char *


usage

decompiled_code:
size_t __fastcall usage(const char *a1)
{
fprintf(stderr, "Usage: %s gdbm-file [flags] [<in-file] [>out-file]\n", a1);
fwrite(" Available flags are:\n", 1uLL, 0x18uLL, stderr);
fwrite(" C - Perform consistency check\n", 1uLL, 0x24uLL, stderr);
fwrite(" G - Write in gdbm format g - Write in flat file format\n", 1uLL, 0x44uLL, stderr);
fwrite(" K - Store key as an attribute k - Store key in the header\n", 1uLL, 0x42uLL, stderr);
fwrite(" L - Include link information l - Don't include link information\n", 1uLL, 0x49uLL, stderr);
fwrite(" M - Store attr map if GDBM m - Don't store attr map if GDBM\n", 1uLL, 0x47uLL, stderr);
fwrite(" N - Store name as an attribute n - Store name in the header\n", 1uLL, 0x43uLL, stderr);
fwrite(" P - Include parent information p - Don't include parent information\n", 1uLL, 0x4BuLL, stderr);
fwrite(" W - Write the output file b w - Don't write the output file.\n", 1uLL, 0x47uLL, stderr);
fwrite(" X - Create a default GDBM db x - Create a default flat file db\n", 1uLL, 0x48uLL, stderr);
fwrite(" Z - Include zone information z - Don't include zone information\n", 1uLL, 0x49uLL, stderr);
return fwrite(" <number> - Set output version number\n", 1uLL, 0x2BuLL, stderr);
}

canonical_decompiled_code:
size_t __fastcall func1(const char *a1)
{
fprintf(stderr, "Usage: %s gdbm-file [flags] [<in-file] [>out-file]\n", a1);
fwrite(" Available flags are:\n", 1uLL, 0x18uLL, stderr);
fwrite(" C - Perform consistency check\n", 1uLL, 0x24uLL, stderr);
fwrite(" G - Write in gdbm format g - Write in flat file format\n", 1uLL, 0x44uLL, stderr);
fwrite(" K - Store key as an attribute k - Store key in the header\n", 1uLL, 0x42uLL, stderr);
fwrite(" L - Include link information l - Don't include link information\n", 1uLL, 0x49uLL, stderr);
fwrite(" M - Store attr map if GDBM m - Don't store attr map if GDBM\n", 1uLL, 0x47uLL, stderr);
fwrite(" N - Store name as an attribute n - Store name in the header\n", 1uLL, 0x43uLL, stderr);
fwrite(" P - Include parent information p - Don't include parent information\n", 1uLL, 0x4BuLL, stderr);
fwrite(" W - Write the output file b w - Don't write the output file.\n", 1uLL, 0x47uLL, stderr);
fwrite(" X - Create a default GDBM db x - Create a default flat file db\n", 1uLL, 0x48uLL, stderr);
fwrite(" Z - Include zone information z - Don't include zone information\n", 1uLL, 0x49uLL, stderr);
return fwrite(" <number> - Set output version number\n", 1uLL, 0x2BuLL, stderr);
}

original_code:
void
usage(char *prog)
{
    fprintf(stderr, "Usage: %s gdbm-file [flags] [<in-file] [>out-file]\n", prog);
    fprintf(stderr, "   Available flags are:\n");
    fprintf(stderr, "      C - Perform consistency check\n");
    fprintf(stderr, "      G - Write in gdbm format        g - Write in flat file format\n");
    fprintf(stderr, "      K - Store key as an attribute   k - Store key in the header\n");
    fprintf(stderr, "      L - Include link information    l - Don't include link information\n");
    fprintf(stderr, "      M - Store attr map if GDBM      m - Don't store attr map if GDBM\n");
    fprintf(stderr, "      N - Store name as an attribute  n - Store name in the header\n");
    fprintf(stderr, "      P - Include parent information  p - Don't include parent information\n");
    fprintf(stderr, "      W - Write the output file  b    w - Don't write the output file.\n");
    fprintf(stderr, "      X - Create a default GDBM db    x - Create a default flat file db\n");
    fprintf(stderr, "      Z - Include zone information    z - Don't include zone information\n");
    fprintf(stderr, "      <number> - Set output version number\n");
}

variable_types:
prog
char *


strpcmp

decompiled_code:
int __fastcall strpcmp(const void *a1, const void *a2)
{
return strcmp(*(const char **)a1, *(const char **)a2);
}

canonical_decompiled_code:
int __fastcall func0(const void *a1, const void *a2)
{
return strcmp(*(const char **)a1, *(const char **)a2);
}

original_code:
int strpcmp(const void *ap, const void *bp){
  char *a, *b;
  a = *(char **)ap;
  b = *(char **)bp;
  return strcmp(a, b);
}

canonical_original_code:
int strpcmp(void *ap, void *bp){
  char *a; char *b;
  a = *(char **)ap;
  b = *(char **)bp;
  return strcmp(a, b);
}

variable_types:
ap
void *

variable_types:
bp
void *

variable_types:
a
char *

variable_types:
b
char *


usage

decompiled_code:
void __fastcall __noreturn usage(const char *a1)
{
fprintf(stderr, "%s: usage: %s i|s|h|q|Q|p|ip|sp|hp|qp|Qp rnum\n", a1, a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func1(const char *a1)
{
fprintf(stderr, "%s: usage: %s i|s|h|q|Q|p|ip|sp|hp|qp|Qp rnum\n", a1, a1);
exit(1);
}

original_code:
void usage(const char *progname){
  fprintf(stderr, "%s: usage: %s i|s|h|q|Q|p|ip|sp|hp|qp|Qp rnum\n", progname, progname);
  exit(1);
}

canonical_original_code:
void usage(char *progname){
  fprintf(stderr, "%s: usage: %s i|s|h|q|Q|p|ip|sp|hp|qp|Qp rnum\n", progname, progname);
  exit(1);
}

variable_types:
progname
char *


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
const char **v4; // r13
const char **v5; // rbx
const char **v6; // r12
const char **v7; // r15
int v8; // eax
unsigned int v9; // eax
const char *v10; // rdi
const char *v11; // rdi
void *v13; // rdi
char s[88]; // [rsp+10h] [rbp-58h] BYREF

if ( argc != 3 || (v3 = atoi(argv[2]), v3 <= 0) || !strchr("ishqQp", *argv[1]) )
usage(*argv);
v4 = (const char **)cbmalloc(8LL * v3);
v5 = v4;
v6 = &v4[v3];
v7 = v4;
do
{
v8 = rand();
++v7;
v9 = sprintf(s, "%08d", (unsigned int)(v8 % v3 + 1));
*(v7 - 1) = (const char *)cbmemdup(s, v9);
}
while ( v7 != v6 );
v10 = argv[1];
switch ( *v10 )
{
case 'Q':
qsort(v4, v3, 8uLL, strpcmp);
v10 = argv[1];
break;
case 'h':
cbhsort(v4, (unsigned int)v3, 8LL, strpcmp);
v10 = argv[1];
break;
case 'i':
cbisort(v4, (unsigned int)v3, 8LL, strpcmp);
v10 = argv[1];
break;
case 'q':
cbqsort(v4, (unsigned int)v3, 8LL, strpcmp);
v10 = argv[1];
break;
case 's':
cbssort(v4, (unsigned int)v3, 8LL, strpcmp);
v10 = argv[1];
break;
default:
break;
}
if ( strchr(v10, 112) )
{
do
{
v11 = *v5++;
puts(v11);
free((void *)*(v5 - 1));
}
while ( v5 != v6 );
}
else
{
do
{
v13 = (void *)*v5++;
free(v13);
}
while ( v5 != v6 );
}
free(v4);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
const char **v4; // r13
const char **v5; // rbx
const char **v6; // r12
const char **v7; // r15
int v8; // eax
unsigned int v9; // eax
const char *v10; // rdi
const char *v11; // rdi
void *v13; // rdi
char s[88]; // [rsp+10h] [rbp-58h] BYREF

if ( argc != 3 || (v3 = atoi(argv[2]), v3 <= 0) || !strchr("ishqQp", *argv[1]) )
func1(*argv);
v4 = (const char **)cbmalloc(8LL * v3);
v5 = v4;
v6 = &v4[v3];
v7 = v4;
do
{
v8 = rand();
++v7;
v9 = sprintf(s, "%08d", (unsigned int)(v8 % v3 + 1));
*(v7 - 1) = (const char *)cbmemdup(s, v9);
}
while ( v7 != v6 );
v10 = argv[1];
switch ( *v10 )
{
case 'Q':
qsort(v4, v3, 8uLL, strpcmp);
v10 = argv[1];
break;
case 'h':
cbhsort(v4, (unsigned int)v3, 8LL, strpcmp);
v10 = argv[1];
break;
case 'i':
cbisort(v4, (unsigned int)v3, 8LL, strpcmp);
v10 = argv[1];
break;
case 'q':
cbqsort(v4, (unsigned int)v3, 8LL, strpcmp);
v10 = argv[1];
break;
case 's':
cbssort(v4, (unsigned int)v3, 8LL, strpcmp);
v10 = argv[1];
break;
default:
break;
}
if ( strchr(v10, 112) )
{
do
{
v11 = *v5++;
puts(v11);
free((void *)*(v5 - 1));
}
while ( v5 != v6 );
}
else
{
do
{
v13 = (void *)*v5++;
free(v13);
}
while ( v5 != v6 );
}
free(v4);
return 0;
}

original_code:
int main(int argc, char **argv){
  int i, rnum, len;
  char **ivector, buf[32];
  if(argc != 3) usage(argv[0]);
  if((rnum = atoi(argv[2])) < 1) usage(argv[0]);
  if(!strchr("ishqQp", argv[1][0])) usage(argv[0]);
  ivector = cbmalloc(rnum * sizeof(ivector[0]));
  for(i = 0; i < rnum; i++){
    len = sprintf(buf, "%08d", rand() % rnum + i * 0 + 1);
    ivector[i] = cbmemdup(buf, len);
  }
  switch(argv[1][0]){
  case 'i':
    cbisort(ivector, rnum, sizeof(ivector[0]), strpcmp);
    break;
  case 's':
    cbssort(ivector, rnum, sizeof(ivector[0]), strpcmp);
    break;
  case 'h':
    cbhsort(ivector, rnum, sizeof(ivector[0]), strpcmp);
    break;
  case 'q':
    cbqsort(ivector, rnum, sizeof(ivector[0]), strpcmp);
    break;
  case 'Q':
    qsort(ivector, rnum, sizeof(ivector[0]), strpcmp);
    break;
  }
  if(strchr(argv[1], 'p')){
    for(i = 0; i < rnum; i++){
      printf("%s\n", ivector[i]);
      free(ivector[i]);
    }
  } else {
    for(i = 0; i < rnum; i++){
      free(ivector[i]);
    }
  }
  free(ivector);
  return 0;
}

canonical_original_code:
int main(int argc, char **argv){
  int i; int rnum; int len;
  char **ivector; char buf[32];
  if(argc != 3) usage(argv[0]);
  if((rnum = atoi(argv[2])) < 1) usage(argv[0]);
  if(!strchr("ishqQp", argv[1][0])) usage(argv[0]);
  ivector = cbmalloc(rnum * sizeof(ivector[0]));
  for(i = 0; i < rnum; i++){
    len = sprintf(buf, "%08d", rand() % rnum + i * 0 + 1);
    ivector[i] = cbmemdup(buf, len);
  }
  switch(argv[1][0]){
  case 'i':
    cbisort(ivector, rnum, sizeof(ivector[0]), strpcmp);
    break;
  case 's':
    cbssort(ivector, rnum, sizeof(ivector[0]), strpcmp);
    break;
  case 'h':
    cbhsort(ivector, rnum, sizeof(ivector[0]), strpcmp);
    break;
  case 'q':
    cbqsort(ivector, rnum, sizeof(ivector[0]), strpcmp);
    break;
  case 'Q':
    qsort(ivector, rnum, sizeof(ivector[0]), strpcmp);
    break;
  }
  if(strchr(argv[1], 'p')){
    for(i = 0; i < rnum; i++){
      printf("%s\n", ivector[i]);
      free(ivector[i]);
    }
  } else {
    for(i = 0; i < rnum; i++){
      free(ivector[i]);
    }
  }
  free(ivector);
  return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: i int

variable_types: rnum int

variable_types: len int

variable_types:
ivector
char **

variable_types:
buf
char [32]


decompiled_code:
char *real_tprintf(const char *a1, unsigned int a2, char *a3, void **a4, const char *a5, ...)
{
char *v7; // r12
int v9; // er14
int v10; // ebx
size_t v11; // rsi
int v12; // eax
char *v13; // rbx
__int64 v14; // r13
char *v16; // [rsp+10h] [rbp-108h] BYREF
gcc_va_list arg; // [rsp+18h] [rbp-100h] BYREF

va_start(arg, a5);
v7 = a3;
if ( !a3 )
{
a4 = (void **)&v16;
v16 = (char *)getTrackedBuffer();
v7 = v16;
}
v9 = getBufferSize(v7);
v10 = v9 - 1;
if ( v9 <= 0 )
fprintf(stderr, "ERR: (%s:%d) Unknown pool passed to safe_tprintf.\n", a1, a2);
else
v9 = v10 - *(_DWORD *)a4 + (_DWORD)v7;
v11 = v9;
if ( v9 < 0 )
{
v9 = 0;
fprintf(stderr, "WRN: (%s:%d) Zero length buffer in safe_tprintf.\n", a1, a2);
v11 = 0LL;
}
v12 = vsnprintf(v7, v11, a5, arg);
v13 = &v7[v10];
v14 = v12;
*v13 = 0;
if ( v12 < 0 )
{
fprintf(stderr, "ERR: (%s:%d) vsnprintf returned error code (%d).\n", a1, a2, (unsigned int)v12);
goto LABEL_14;
}
if ( v9 >= v12 )
{
LABEL_14:
*a4 = (char *)*a4 + v14 + 1;
return v7;
}
if ( !*a4 )
v13 = 0LL;
*a4 = v13;
return v7;
}

canonical_decompiled_code:
char *func2(const char *a1, unsigned int a2, char *a3, void **a4, const char *a5, ...)
{
char *v7; // r12
int v9; // er14
int v10; // ebx
size_t v11; // rsi
int v12; // eax
char *v13; // rbx
__int64 v14; // r13
char *v16; // [rsp+10h] [rbp-108h] BYREF
gcc_va_list arg; // [rsp+18h] [rbp-100h] BYREF

va_start(arg, a5);
v7 = a3;
if ( !a3 )
{
a4 = (void **)&v16;
v16 = (char *)func0();
v7 = v16;
}
v9 = func1(v7);
v10 = v9 - 1;
if ( v9 <= 0 )
fprintf(stderr, "ERR: (%s:%d) Unknown pool passed to safe_tprintf.\n", a1, a2);
else
v9 = v10 - *(_DWORD *)a4 + (_DWORD)v7;
v11 = v9;
if ( v9 < 0 )
{
v9 = 0;
fprintf(stderr, "WRN: (%s:%d) Zero length buffer in safe_tprintf.\n", a1, a2);
v11 = 0LL;
}
v12 = vsnprintf(v7, v11, a5, arg);
v13 = &v7[v10];
v14 = v12;
*v13 = 0;
if ( v12 < 0 )
{
fprintf(stderr, "ERR: (%s:%d) vsnprintf returned error code (%d).\n", a1, a2, (unsigned int)v12);
goto LABEL_14;
}
if ( v9 >= v12 )
{
LABEL_14:
*a4 = (char *)*a4 + v14 + 1;
return v7;
}
if ( !*a4 )
v13 = 0LL;
*a4 = v13;
return v7;
}

original_code:
char *real_tprintf(char *filename, int lineNo,
     char *buff, char **bp, char *format, ...)
{
  int length, end, ret;
  char *bp2;
  va_list ap;
  __builtin_va_start(ap,format);
  if (buff == ((void *)0)) {
    buff = getTrackedBuffer();
    bp2 = buff;
    bp = &bp2;
  }
  length = getBufferSize(buff);
  end = length - 1;
  if (length > 0) {
    length -= (*bp - buff) + 1;
  } else {
    fprintf(stderr,
     "ERR: (%s:%d) Unknown pool passed to safe_tprintf.\n",
     filename, lineNo);
  }
  if (length < 0) {
    length = 0;
    fprintf(stderr,
     "WRN: (%s:%d) Zero length buffer in safe_tprintf.\n",
     filename, lineNo);
  }
  ret = vsnprintf(buff, length, format, ap);
  __builtin_va_end(ap);
  buff[end] = '\0';
  if (ret < 0) {
     fprintf(stderr,
      "ERR: (%s:%d) vsnprintf returned error code (%d).\n",
      filename, lineNo, ret);
  }
  if (ret <= length) {
     *bp += ret + 1;
  } else {
     for (bp2 = *bp; bp2 != '\0' && bp2 != &buff[end]; bp2++);
     *bp = bp2;
  }
  return buff;
}

canonical_original_code:
char *real_tprintf(char *filename, int lineNo, char *buff, char **bp, char *format, ...)
{
  int length; int end; int ret;
  char *bp2;
  __builtin_va_list ap;
  __builtin_va_start(ap,format);
  if (buff == ((void *)0)) {
    buff = getTrackedBuffer();
    bp2 = buff;
    bp = &bp2;
  }
  length = getBufferSize(buff);
  end = length - 1;
  if (length > 0) {
    length -= (*bp - buff) + 1;
  } else {
    fprintf(stderr,
     "ERR: (%s:%d) Unknown pool passed to safe_tprintf.\n",
     filename, lineNo);
  }
  if (length < 0) {
    length = 0;
    fprintf(stderr,
     "WRN: (%s:%d) Zero length buffer in safe_tprintf.\n",
     filename, lineNo);
  }
  ret = vsnprintf(buff, length, format, ap);
  __builtin_va_end(ap);
  buff[end] = '\0';
  if (ret < 0) {
     fprintf(stderr,
      "ERR: (%s:%d) vsnprintf returned error code (%d).\n",
      filename, lineNo, ret);
  }
  if (ret <= length) {
     *bp += ret + 1;
  } else {
     for (bp2 = *bp; bp2 != '\0' && bp2 != &buff[end]; bp2++);
     *bp = bp2;
  }
  return buff;
}

variable_types:
filename
char *

variable_types: lineNo int

variable_types:
buff
char *

variable_types:
bp
char **

variable_types:
format
char *

variable_types: length int

variable_types: end int

variable_types: ret int

return_type: char *


getBufferSize

decompiled_code:
__int64 getBufferSize()
{
return 10000LL;
}

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

original_code:
int getBufferSize(char *buffer) {
  return 10000;
}

variable_types:
buffer
char *


repo: kennyyu/workshop

decompiled_code:
__int64 __fastcall maximal_subarray_dumb(_DWORD *a1, int a2)
{
__int64 v4; // rbx
__int64 v5; // rdi
unsigned int v6; // er8
_DWORD *v7; // r9
int v8; // esi
_DWORD *v9; // rcx
_DWORD *v10; // rax
int v11; // edx

if ( a2 <= 0 )
return 0LL;
v4 = a2;
v5 = 0LL;
v6 = 0;
do
{
v7 = a1++;
v8 = v5;
v9 = a1;
do
{
v10 = v7;
v11 = 0;
if ( v8 >= (int)v5 )
{
do
v11 += *v10++;
while ( v10 != v9 );
}
if ( (int)v6 < v11 )
v6 = v11;
++v8;
++v9;
}
while ( a2 > v8 );
++v5;
}
while ( v5 != v4 );
return v6;
}

original_code:
int maximal_subarray_dumb(int *array, int n) {
  int max_sum = 0;
  for (int start = 0; start < n; start++) {
    for (int end = start; end < n; end++) {
      int sum = 0;
      for (int i = start; i <= end; i++) {
        sum += array[i];
      }
      max_sum = ((max_sum) > (sum) ? (max_sum) : (sum));
    }
  }
  return max_sum;
}

variable_types:
array
int *

variable_types: n int

variable_types: start int

variable_types: sum int


decompiled_code:
__int64 __fastcall maximal_subarray_space(int *a1, int a2)
{
int v2; // er12
int *v5; // rdi
int v6; // eax
__int64 v7; // rsi
__int64 i; // rdx
__int64 v9; // rax

v2 = 0;
v5 = (int *)malloc(4LL * a2);
v6 = 0;
if ( *a1 >= 0 )
v6 = *a1;
*v5 = v6;
if ( a2 > 1 )
{
v7 = (unsigned int)(a2 - 1);
for ( i = 1LL; ; ++i )
{
v6 += a1[i];
if ( v6 < 0 )
v6 = 0;
v5[i] = v6;
if ( v7 == i )
break;
}
v9 = 0LL;
v2 = 0;
do
{
if ( v2 < v5[v9] )
v2 = v5[v9];
++v9;
}
while ( a2 > (int)v9 );
LABEL_13:
free(v5);
return (unsigned int)v2;
}
if ( a2 == 1 )
{
if ( *v5 >= 0 )
v2 = *v5;
goto LABEL_13;
}
free(v5);
return 0LL;
}

original_code:
int maximal_subarray_space(int *array, int n) {
  int *subproblems = (int *) malloc(n * sizeof(int));
  subproblems[0] = ((array[0]) > (0) ? (array[0]) : (0));
  for (int i = 1; i < n; i++) {
    subproblems[i] = ((subproblems[i-1] + array[i]) > (0) ? (subproblems[i-1] + array[i]) : (0));
  }
  int max = 0;
  for (int i = 0; i < n; i++) {
    max = ((max) > (subproblems[i]) ? (max) : (subproblems[i]));
  }
  free(subproblems);
  return max;
}

variable_types:
subproblems
int *

variable_types: i int

variable_types: max int


decompiled_code:
__int64 __fastcall maximal_subarray(_DWORD *a1, int a2)
{
int v2; // er8
__int64 v3; // rcx
int v4; // eax

if ( a2 <= 0 )
return 0LL;
v2 = 0;
v3 = (__int64)&a1[a2 - 1 + 1];
v4 = 0;
do
{
v4 += *a1;
if ( v4 < 0 )
v4 = 0;
if ( v2 < v4 )
v2 = v4;
++a1;
}
while ( a1 != (_DWORD *)v3 );
return (unsigned int)v2;
}

original_code:
int maximal_subarray(int *array, int n) {
  int max_sum_so_far = 0;
  int current_sum_so_far = 0;
  for (int i = 0; i < n; i++) {
    current_sum_so_far = ((current_sum_so_far + array[i]) > (0) ? (current_sum_so_far + array[i]) : (0));
    max_sum_so_far = ((max_sum_so_far) > (current_sum_so_far) ? (max_sum_so_far) : (current_sum_so_far));
  }
  return max_sum_so_far;
}


swap

decompiled_code:
__int64 __fastcall swap(_DWORD *a1, _DWORD *a2)
{
__int64 result; // rax

result = (unsigned int)*a1;
*a1 = *a2;
*a2 = result;
return result;
}

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

result = (unsigned int)*a1;
*a1 = *a2;
*a2 = result;
return result;
}

original_code:
static inline void swap(int *x, int *y) {
  int temp = *x;
  *x = *y;
  *y = temp;
}

variable_types:
x
int *

variable_types:
y
int *

variable_types: temp int


decompiled_code:
__int64 __fastcall my_random(int a1, int a2)
{
return (unsigned int)(rand() % (a2 - a1) + a1);
}

canonical_decompiled_code:
__int64 __fastcall func13(int a1, int a2)
{
return (unsigned int)(rand() % (a2 - a1) + a1);
}

original_code:
static inline int my_random(int i, int j) {
  return i + rand() % (j - i);
}

variable_types: j int


shuffle

decompiled_code:
void __fastcall shuffle(__int64 a1, int a2)
{
__int64 v3; // rbx
int v4; // eax
_DWORD *v5; // rdi

if ( a2 > 0 )
{
v3 = 0LL;
do
{
v4 = my_random(v3, a2);
v5 = (_DWORD *)(a1 + 4 * v3++);
swap(v5, (_DWORD *)(a1 + 4LL * v4));
}
while ( v3 != a2 );
}
}

original_code:
void shuffle(int *array, int n) {
  for (int i = 0; i < n; i++) {
    swap(&array[i], &array[my_random(i, n)]);
  }
}


decompiled_code:
void __fastcall make_list(_DWORD *a1, int a2)
{
int v2; // edx
int v3; // esi
int v4; // eax

v2 = a2 / 2;
if ( a2 > 0 )
{
v3 = a2 - v2;
v4 = -v2;
do
*a1++ = v4++;
while ( v4 != v3 );
}
}

canonical_decompiled_code:
void __fastcall func15(_DWORD *a1, int a2)
{
int v2; // edx
int v3; // esi
int v4; // eax

v2 = a2 / 2;
if ( a2 > 0 )
{
v3 = a2 - v2;
v4 = -v2;
do
*a1++ = v4++;
while ( v4 != v3 );
}
}

original_code:
void make_list(int *array, int n) {
  int half = n / 2;
  for (int i = 0; i < n; i++) {
    array[i] = i - half;
  }
}

variable_types: half int


decompiled_code:
int __fastcall print_list(unsigned int *a1, int a2)
{
__int64 v2; // rbp
unsigned int *v3; // rbx
__int64 v4; // rsi

if ( a2 > 0 )
{
v2 = (__int64)&a1[a2 - 1 + 1];
v3 = a1;
do
{
v4 = *v3++;
printf("%d ", v4);
}
while ( v3 != (unsigned int *)v2 );
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func16(unsigned int *a1, int a2)
{
__int64 v2; // rbp
unsigned int *v3; // rbx
__int64 v4; // rsi

if ( a2 > 0 )
{
v2 = (__int64)&a1[a2 - 1 + 1];
v3 = a1;
do
{
v4 = *v3++;
printf("%d ", v4);
}
while ( v3 != (unsigned int *)v2 );
}
return putchar(10);
}

original_code:
void print_list(int *array, int n) {
  for (int i = 0; i < n; i++) {
    printf("%d ", array[i]);
  }
  printf("\n");
}


main

repo: kensmith/studies

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rdx
int v4; // ebx
int v5; // ebx
unsigned int v7; // ebp
int v8; // ebx

fprintf(_bss_start, "%s(%d): ENTERING", "gentest.c", 29LL);
v3 = (unsigned int)GENUTIL_function_call_depth;
if ( GENUTIL_function_call_depth < 0 )
goto LABEL_16;
v4 = 0;
fprintf(_bss_start, "(depth:%d)", (unsigned int)GENUTIL_function_call_depth);
if ( GENUTIL_function_call_depth > 0 )
{
do
{
++v4;
fputc(46, _bss_start);
}
while ( GENUTIL_function_call_depth > v4 );
}
fwrite("> ", 1uLL, 2uLL, _bss_start);
fprintf(_bss_start, "%s\n", "main(int argc, char** argv)");
fflush(_bss_start);
++GENUTIL_function_call_depth;
fprintf(_bss_start, "%s(%d): ", "gentest.c", 30LL);
fprintf(_bss_start, "argc: %d", (unsigned int)argc);
fputc(10, _bss_start);
fflush(_bss_start);
fprintf(_bss_start, "%s(%d): ", "gentest.c", 31LL);
fprintf(_bss_start, "argv: %p", argv);
fputc(10, _bss_start);
fflush(_bss_start);
if ( argc != 2 )
{
if ( argc <= 0 )
fwrite("usage: program <number>\n", 1uLL, 0x18uLL, stderr);
else
fprintf(stderr, "usage: %s <number>\n", *argv);
--GENUTIL_function_call_depth;
fprintf(_bss_start, "%s(%d): LEAVING", "gentest.c", 42LL);
v3 = (unsigned int)GENUTIL_function_call_depth;
if ( GENUTIL_function_call_depth >= 0 )
{
v5 = 0;
fprintf(_bss_start, "(depth:%d)", (unsigned int)GENUTIL_function_call_depth);
if ( GENUTIL_function_call_depth > 0 )
{
do
{
++v5;
fputc(46, _bss_start);
}
while ( GENUTIL_function_call_depth > v5 );
}
fwrite("> ", 1uLL, 2uLL, _bss_start);
fprintf(_bss_start, "%s [%d]\n", "main(int argc, char** argv)", 1LL);
fflush(_bss_start);
return 1;
}
LABEL_16:
fprintf(
_bss_start,
"genutil: The function call depth indicator fell to %d, this indicates that not\n"
"genutil: all of the functions are utilizing the entering_function and\n"
"genutil: leaving_function macros correctly. Make sure that all function\n"
"genutil: entrance points contain a call to entering_function and that all\n"
"genutil: function exit points contain a call to leaving_function.\n",
v3);
exit(-1);
}
v7 = atoi(argv[1]);
initialize();
recurse(v7);
--GENUTIL_function_call_depth;
fprintf(_bss_start, "%s(%d): LEAVING", "gentest.c", 50LL);
v3 = (unsigned int)GENUTIL_function_call_depth;
if ( GENUTIL_function_call_depth < 0 )
goto LABEL_16;
v8 = 0;
fprintf(_bss_start, "(depth:%d)", (unsigned int)GENUTIL_function_call_depth);
if ( GENUTIL_function_call_depth > 0 )
{
do
{
++v8;
fputc(46, _bss_start);
}
while ( GENUTIL_function_call_depth > v8 );
}
fwrite("> ", 1uLL, 2uLL, _bss_start);
fprintf(_bss_start, "%s [%d]\n", "main(int argc, char** argv)", 0LL);
fflush(_bss_start);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rdx
int v4; // ebx
int v5; // ebx
unsigned int v7; // ebp
int v8; // ebx

fprintf(_bss_start, "%s(%d): ENTERING", "gentest.c", 29LL);
v3 = (unsigned int)GENUTIL_function_call_depth;
if ( GENUTIL_function_call_depth < 0 )
goto LABEL_16;
v4 = 0;
fprintf(_bss_start, "(depth:%d)", (unsigned int)GENUTIL_function_call_depth);
if ( GENUTIL_function_call_depth > 0 )
{
do
{
++v4;
fputc(46, _bss_start);
}
while ( GENUTIL_function_call_depth > v4 );
}
fwrite("> ", 1uLL, 2uLL, _bss_start);
fprintf(_bss_start, "%s\n", "main(int argc, char** argv)");
fflush(_bss_start);
++GENUTIL_function_call_depth;
fprintf(_bss_start, "%s(%d): ", "gentest.c", 30LL);
fprintf(_bss_start, "argc: %d", (unsigned int)argc);
fputc(10, _bss_start);
fflush(_bss_start);
fprintf(_bss_start, "%s(%d): ", "gentest.c", 31LL);
fprintf(_bss_start, "argv: %p", argv);
fputc(10, _bss_start);
fflush(_bss_start);
if ( argc != 2 )
{
if ( argc <= 0 )
fwrite("usage: program <number>\n", 1uLL, 0x18uLL, stderr);
else
fprintf(stderr, "usage: %s <number>\n", *argv);
--GENUTIL_function_call_depth;
fprintf(_bss_start, "%s(%d): LEAVING", "gentest.c", 42LL);
v3 = (unsigned int)GENUTIL_function_call_depth;
if ( GENUTIL_function_call_depth >= 0 )
{
v5 = 0;
fprintf(_bss_start, "(depth:%d)", (unsigned int)GENUTIL_function_call_depth);
if ( GENUTIL_function_call_depth > 0 )
{
do
{
++v5;
fputc(46, _bss_start);
}
while ( GENUTIL_function_call_depth > v5 );
}
fwrite("> ", 1uLL, 2uLL, _bss_start);
fprintf(_bss_start, "%s [%d]\n", "main(int argc, char** argv)", 1LL);
fflush(_bss_start);
return 1;
}
LABEL_16:
fprintf(
_bss_start,
"genutil: The function call depth indicator fell to %d, this indicates that not\n"
"genutil: all of the functions are utilizing the entering_function and\n"
"genutil: leaving_function macros correctly. Make sure that all function\n"
"genutil: entrance points contain a call to entering_function and that all\n"
"genutil: function exit points contain a call to leaving_function.\n",
v3);
exit(-1);
}
v7 = atoi(argv[1]);
func8();
func7(v7);
--GENUTIL_function_call_depth;
fprintf(_bss_start, "%s(%d): LEAVING", "gentest.c", 50LL);
v3 = (unsigned int)GENUTIL_function_call_depth;
if ( GENUTIL_function_call_depth < 0 )
goto LABEL_16;
v8 = 0;
fprintf(_bss_start, "(depth:%d)", (unsigned int)GENUTIL_function_call_depth);
if ( GENUTIL_function_call_depth > 0 )
{
do
{
++v8;
fputc(46, _bss_start);
}
while ( GENUTIL_function_call_depth > v8 );
}
fwrite("> ", 1uLL, 2uLL, _bss_start);
fprintf(_bss_start, "%s [%d]\n", "main(int argc, char** argv)", 0LL);
fflush(_bss_start);
return 0;
}

original_code:
int main(int argc, char** argv) {
 int number;
 char *GENUTIL_function_name = "main(int argc, char** argv)"; do { int GENUTIL_i; fprintf(stdout, "%s(%d): ENTERING", "gentest.c", 29); if (GENUTIL_function_call_depth < 0) { fprintf(stdout,"genutil: The function call depth indicator fell to %d, this indicates that not\n" "genutil: all of the functions are utilizing the entering_function and\n" "genutil: leaving_function macros correctly.  Make sure that all function\n" "genutil: entrance points contain a call to entering_function and that all\n" "genutil: function exit points contain a call to leaving_function.\n", GENUTIL_function_call_depth); exit(-1); } fprintf(stdout, "(depth:%d)", GENUTIL_function_call_depth); for (GENUTIL_i = 0; GENUTIL_i < GENUTIL_function_call_depth; GENUTIL_i++) { fprintf(stdout, "."); } fprintf(stdout, "> "); fprintf(stdout, "%s\n", GENUTIL_function_name); fflush(stdout); GENUTIL_function_call_depth++; } while (0);
 do { fprintf(stdout, "%s(%d): ", "gentest.c", 30); fprintf(stdout, "argc: %d", argc); fprintf(stdout, "\n"); fflush(stdout); } while (0);
 do { fprintf(stdout, "%s(%d): ", "gentest.c", 31); fprintf(stdout, "argv: %p", argv); fprintf(stdout, "\n"); fflush(stdout); } while (0);
 if (argc != 2) {
  if (argc > 0) {
   fprintf(stderr, "usage: %s <number>\n", argv[0]);
  }
  else {
   fprintf(stderr, "usage: program <number>\n");
  }
  GENUTIL_function_call_depth--; do { int GENUTIL_i; fprintf(stdout, "%s(%d): LEAVING", "gentest.c", 42); if (GENUTIL_function_call_depth < 0) { fprintf(stdout,"genutil: The function call depth indicator fell to %d, this indicates that not\n" "genutil: all of the functions are utilizing the entering_function and\n" "genutil: leaving_function macros correctly.  Make sure that all function\n" "genutil: entrance points contain a call to entering_function and that all\n" "genutil: function exit points contain a call to leaving_function.\n", GENUTIL_function_call_depth); exit(-1); } fprintf(stdout, "(depth:%d)", GENUTIL_function_call_depth); for (GENUTIL_i = 0; GENUTIL_i < GENUTIL_function_call_depth; GENUTIL_i++) { fprintf(stdout, "."); } fprintf(stdout, "> "); fprintf(stdout, "%s [%d]\n", GENUTIL_function_name, (int) 1); fflush(stdout); } while (0);
  return 1;
 }
 number = atoi(argv[1]);
 initialize();
 recurse(number);
 GENUTIL_function_call_depth--; do { int GENUTIL_i; fprintf(stdout, "%s(%d): LEAVING", "gentest.c", 50); if (GENUTIL_function_call_depth < 0) { fprintf(stdout,"genutil: The function call depth indicator fell to %d, this indicates that not\n" "genutil: all of the functions are utilizing the entering_function and\n" "genutil: leaving_function macros correctly.  Make sure that all function\n" "genutil: entrance points contain a call to entering_function and that all\n" "genutil: function exit points contain a call to leaving_function.\n", GENUTIL_function_call_depth); exit(-1); } fprintf(stdout, "(depth:%d)", GENUTIL_function_call_depth); for (GENUTIL_i = 0; GENUTIL_i < GENUTIL_function_call_depth; GENUTIL_i++) { fprintf(stdout, "."); } fprintf(stdout, "> "); fprintf(stdout, "%s [%d]\n", GENUTIL_function_name, (int) 0); fflush(stdout); } while (0);
 return(0);
}

canonical_original_code:
int main(int argc, char **argv) {
 int number;
 char *GENUTIL_function_name = "main(int argc, char** argv)"; do { int GENUTIL_i; fprintf(stdout, "%s(%d): ENTERING", "gentest.c", 29); if (GENUTIL_function_call_depth < 0) { fprintf(stdout,"genutil: The function call depth indicator fell to %d, this indicates that not\n" "genutil: all of the functions are utilizing the entering_function and\n" "genutil: leaving_function macros correctly.  Make sure that all function\n" "genutil: entrance points contain a call to entering_function and that all\n" "genutil: function exit points contain a call to leaving_function.\n", GENUTIL_function_call_depth); exit(-1); } fprintf(stdout, "(depth:%d)", GENUTIL_function_call_depth); for (GENUTIL_i = 0; GENUTIL_i < GENUTIL_function_call_depth; GENUTIL_i++) { fprintf(stdout, "."); } fprintf(stdout, "> "); fprintf(stdout, "%s\n", GENUTIL_function_name); fflush(stdout); GENUTIL_function_call_depth++; } while (0);
 do { fprintf(stdout, "%s(%d): ", "gentest.c", 30); fprintf(stdout, "argc: %d", argc); fprintf(stdout, "\n"); fflush(stdout); } while (0);
 do { fprintf(stdout, "%s(%d): ", "gentest.c", 31); fprintf(stdout, "argv: %p", argv); fprintf(stdout, "\n"); fflush(stdout); } while (0);
 if (argc != 2) {
  if (argc > 0) {
   fprintf(stderr, "usage: %s <number>\n", argv[0]);
  }
  else {
   fprintf(stderr, "usage: program <number>\n");
  }
  GENUTIL_function_call_depth--; do { int GENUTIL_i; fprintf(stdout, "%s(%d): LEAVING", "gentest.c", 42); if (GENUTIL_function_call_depth < 0) { fprintf(stdout,"genutil: The function call depth indicator fell to %d, this indicates that not\n" "genutil: all of the functions are utilizing the entering_function and\n" "genutil: leaving_function macros correctly.  Make sure that all function\n" "genutil: entrance points contain a call to entering_function and that all\n" "genutil: function exit points contain a call to leaving_function.\n", GENUTIL_function_call_depth); exit(-1); } fprintf(stdout, "(depth:%d)", GENUTIL_function_call_depth); for (GENUTIL_i = 0; GENUTIL_i < GENUTIL_function_call_depth; GENUTIL_i++) { fprintf(stdout, "."); } fprintf(stdout, "> "); fprintf(stdout, "%s [%d]\n", GENUTIL_function_name, (int) 1); fflush(stdout); } while (0);
  return 1;
 }
 number = atoi(argv[1]);
 initialize();
 recurse(number);
 GENUTIL_function_call_depth--; do { int GENUTIL_i; fprintf(stdout, "%s(%d): LEAVING", "gentest.c", 50); if (GENUTIL_function_call_depth < 0) { fprintf(stdout,"genutil: The function call depth indicator fell to %d, this indicates that not\n" "genutil: all of the functions are utilizing the entering_function and\n" "genutil: leaving_function macros correctly.  Make sure that all function\n" "genutil: entrance points contain a call to entering_function and that all\n" "genutil: function exit points contain a call to leaving_function.\n", GENUTIL_function_call_depth); exit(-1); } fprintf(stdout, "(depth:%d)", GENUTIL_function_call_depth); for (GENUTIL_i = 0; GENUTIL_i < GENUTIL_function_call_depth; GENUTIL_i++) { fprintf(stdout, "."); } fprintf(stdout, "> "); fprintf(stdout, "%s [%d]\n", GENUTIL_function_name, (int) 0); fflush(stdout); } while (0);
 return(0);
}

variable_types: argc int

variable_types:
argv
char **

variable_types: number int


recurse

decompiled_code:
int __fastcall recurse(int a1)
{
__int64 v1; // rdx
int v2; // ebx
int v3; // ebx

fprintf(_bss_start, "%s(%d): ENTERING", "gentest.c", 7LL);
v1 = (unsigned int)GENUTIL_function_call_depth;
if ( GENUTIL_function_call_depth < 0 )
goto LABEL_12;
fprintf(_bss_start, "(depth:%d)", (unsigned int)GENUTIL_function_call_depth);
if ( GENUTIL_function_call_depth > 0 )
{
v2 = 0;
do
{
++v2;
fputc(46, _bss_start);
}
while ( GENUTIL_function_call_depth > v2 );
}
fwrite("> ", 1uLL, 2uLL, _bss_start);
fprintf(_bss_start, "%s\n", "recurse(int depth)");
fflush(_bss_start);
++GENUTIL_function_call_depth;
fprintf(_bss_start, "%s(%d): ", "gentest.c", 8LL);
fprintf(_bss_start, "depth: %d", (unsigned int)a1);
fputc(10, _bss_start);
fflush(_bss_start);
if ( a1 > 0 )
{
puts("weeee!");
recurse((unsigned int)(a1 - 1));
}
--GENUTIL_function_call_depth;
fprintf(_bss_start, "%s(%d): LEAVING", "gentest.c", 15LL);
v1 = (unsigned int)GENUTIL_function_call_depth;
if ( GENUTIL_function_call_depth < 0 )
{
LABEL_12:
fprintf(
_bss_start,
"genutil: The function call depth indicator fell to %d, this indicates that not\n"
"genutil: all of the functions are utilizing the entering_function and\n"
"genutil: leaving_function macros correctly. Make sure that all function\n"
"genutil: entrance points contain a call to entering_function and that all\n"
"genutil: function exit points contain a call to leaving_function.\n",
v1);
exit(-1);
}
fprintf(_bss_start, "(depth:%d)", (unsigned int)GENUTIL_function_call_depth);
if ( GENUTIL_function_call_depth > 0 )
{
v3 = 0;
do
{
++v3;
fputc(46, _bss_start);
}
while ( GENUTIL_function_call_depth > v3 );
}
fwrite("> ", 1uLL, 2uLL, _bss_start);
fprintf(_bss_start, "%s [%d]\n", "recurse(int depth)", 0LL);
return fflush(_bss_start);
}

canonical_decompiled_code:
int __fastcall func7(int a1)
{
__int64 v1; // rdx
int v2; // ebx
int v3; // ebx

fprintf(_bss_start, "%s(%d): ENTERING", "gentest.c", 7LL);
v1 = (unsigned int)GENUTIL_function_call_depth;
if ( GENUTIL_function_call_depth < 0 )
goto LABEL_12;
fprintf(_bss_start, "(depth:%d)", (unsigned int)GENUTIL_function_call_depth);
if ( GENUTIL_function_call_depth > 0 )
{
v2 = 0;
do
{
++v2;
fputc(46, _bss_start);
}
while ( GENUTIL_function_call_depth > v2 );
}
fwrite("> ", 1uLL, 2uLL, _bss_start);
fprintf(_bss_start, "%s\n", "recurse(int depth)");
fflush(_bss_start);
++GENUTIL_function_call_depth;
fprintf(_bss_start, "%s(%d): ", "gentest.c", 8LL);
fprintf(_bss_start, "depth: %d", (unsigned int)a1);
fputc(10, _bss_start);
fflush(_bss_start);
if ( a1 > 0 )
{
puts("weeee!");
func7((unsigned int)(a1 - 1));
}
--GENUTIL_function_call_depth;
fprintf(_bss_start, "%s(%d): LEAVING", "gentest.c", 15LL);
v1 = (unsigned int)GENUTIL_function_call_depth;
if ( GENUTIL_function_call_depth < 0 )
{
LABEL_12:
fprintf(
_bss_start,
"genutil: The function call depth indicator fell to %d, this indicates that not\n"
"genutil: all of the functions are utilizing the entering_function and\n"
"genutil: leaving_function macros correctly. Make sure that all function\n"
"genutil: entrance points contain a call to entering_function and that all\n"
"genutil: function exit points contain a call to leaving_function.\n",
v1);
exit(-1);
}
fprintf(_bss_start, "(depth:%d)", (unsigned int)GENUTIL_function_call_depth);
if ( GENUTIL_function_call_depth > 0 )
{
v3 = 0;
do
{
++v3;
fputc(46, _bss_start);
}
while ( GENUTIL_function_call_depth > v3 );
}
fwrite("> ", 1uLL, 2uLL, _bss_start);
fprintf(_bss_start, "%s [%d]\n", "recurse(int depth)", 0LL);
return fflush(_bss_start);
}

original_code:
void recurse(int depth) {
 char *GENUTIL_function_name = "recurse(int depth)"; do { int GENUTIL_i; fprintf(stdout, "%s(%d): ENTERING", "gentest.c", 7); if (GENUTIL_function_call_depth < 0) { fprintf(stdout,"genutil: The function call depth indicator fell to %d, this indicates that not\n" "genutil: all of the functions are utilizing the entering_function and\n" "genutil: leaving_function macros correctly.  Make sure that all function\n" "genutil: entrance points contain a call to entering_function and that all\n" "genutil: function exit points contain a call to leaving_function.\n", GENUTIL_function_call_depth); exit(-1); } fprintf(stdout, "(depth:%d)", GENUTIL_function_call_depth); for (GENUTIL_i = 0; GENUTIL_i < GENUTIL_function_call_depth; GENUTIL_i++) { fprintf(stdout, "."); } fprintf(stdout, "> "); fprintf(stdout, "%s\n", GENUTIL_function_name); fflush(stdout); GENUTIL_function_call_depth++; } while (0);
 do { fprintf(stdout, "%s(%d): ", "gentest.c", 8); fprintf(stdout, "depth: %d", depth); fprintf(stdout, "\n"); fflush(stdout); } while (0);
 if (depth > 0) {
  printf("weeee!\n");
  recurse(depth - 1);
 }
 GENUTIL_function_call_depth--; do { int GENUTIL_i; fprintf(stdout, "%s(%d): LEAVING", "gentest.c", 15); if (GENUTIL_function_call_depth < 0) { fprintf(stdout,"genutil: The function call depth indicator fell to %d, this indicates that not\n" "genutil: all of the functions are utilizing the entering_function and\n" "genutil: leaving_function macros correctly.  Make sure that all function\n" "genutil: entrance points contain a call to entering_function and that all\n" "genutil: function exit points contain a call to leaving_function.\n", GENUTIL_function_call_depth); exit(-1); } fprintf(stdout, "(depth:%d)", GENUTIL_function_call_depth); for (GENUTIL_i = 0; GENUTIL_i < GENUTIL_function_call_depth; GENUTIL_i++) { fprintf(stdout, "."); } fprintf(stdout, "> "); fprintf(stdout, "%s [%d]\n", GENUTIL_function_name, (int) 0); fflush(stdout); } while (0);
 return;
}

variable_types: depth int


initialize

decompiled_code:
__int64 initialize()
{
__int64 v0; // rdx
int v1; // ebx
int v2; // ebx

fprintf(_bss_start, "%s(%d): ENTERING", "gentest.c", 20LL);
v0 = (unsigned int)GENUTIL_function_call_depth;
if ( GENUTIL_function_call_depth < 0 )
goto LABEL_10;
fprintf(_bss_start, "(depth:%d)", (unsigned int)GENUTIL_function_call_depth);
if ( GENUTIL_function_call_depth > 0 )
{
v1 = 0;
do
{
++v1;
fputc(46, _bss_start);
}
while ( GENUTIL_function_call_depth > v1 );
}
fwrite("> ", 1uLL, 2uLL, _bss_start);
fprintf(_bss_start, "%s\n", "initialize()");
fflush(_bss_start);
fprintf(_bss_start, "%s(%d): LEAVING", "gentest.c", 22LL);
v0 = (unsigned int)GENUTIL_function_call_depth;
if ( GENUTIL_function_call_depth < 0 )
{
LABEL_10:
fprintf(
_bss_start,
"genutil: The function call depth indicator fell to %d, this indicates that not\n"
"genutil: all of the functions are utilizing the entering_function and\n"
"genutil: leaving_function macros correctly. Make sure that all function\n"
"genutil: entrance points contain a call to entering_function and that all\n"
"genutil: function exit points contain a call to leaving_function.\n",
v0);
exit(-1);
}
fprintf(_bss_start, "(depth:%d)", (unsigned int)GENUTIL_function_call_depth);
if ( GENUTIL_function_call_depth > 0 )
{
v2 = 0;
do
{
++v2;
fputc(46, _bss_start);
}
while ( GENUTIL_function_call_depth > v2 );
}
fwrite("> ", 1uLL, 2uLL, _bss_start);
fprintf(_bss_start, "%s [%d]\n", "initialize()", 4LL);
fflush(_bss_start);
return 4LL;
}

canonical_decompiled_code:
__int64 func8()
{
__int64 v0; // rdx
int v1; // ebx
int v2; // ebx

fprintf(_bss_start, "%s(%d): ENTERING", "gentest.c", 20LL);
v0 = (unsigned int)GENUTIL_function_call_depth;
if ( GENUTIL_function_call_depth < 0 )
goto LABEL_10;
fprintf(_bss_start, "(depth:%d)", (unsigned int)GENUTIL_function_call_depth);
if ( GENUTIL_function_call_depth > 0 )
{
v1 = 0;
do
{
++v1;
fputc(46, _bss_start);
}
while ( GENUTIL_function_call_depth > v1 );
}
fwrite("> ", 1uLL, 2uLL, _bss_start);
fprintf(_bss_start, "%s\n", "initialize()");
fflush(_bss_start);
fprintf(_bss_start, "%s(%d): LEAVING", "gentest.c", 22LL);
v0 = (unsigned int)GENUTIL_function_call_depth;
if ( GENUTIL_function_call_depth < 0 )
{
LABEL_10:
fprintf(
_bss_start,
"genutil: The function call depth indicator fell to %d, this indicates that not\n"
"genutil: all of the functions are utilizing the entering_function and\n"
"genutil: leaving_function macros correctly. Make sure that all function\n"
"genutil: entrance points contain a call to entering_function and that all\n"
"genutil: function exit points contain a call to leaving_function.\n",
v0);
exit(-1);
}
fprintf(_bss_start, "(depth:%d)", (unsigned int)GENUTIL_function_call_depth);
if ( GENUTIL_function_call_depth > 0 )
{
v2 = 0;
do
{
++v2;
fputc(46, _bss_start);
}
while ( GENUTIL_function_call_depth > v2 );
}
fwrite("> ", 1uLL, 2uLL, _bss_start);
fprintf(_bss_start, "%s [%d]\n", "initialize()", 4LL);
fflush(_bss_start);
return 4LL;
}

original_code:
int initialize() {
 char *GENUTIL_function_name = "initialize()"; do { int GENUTIL_i; fprintf(stdout, "%s(%d): ENTERING", "gentest.c", 20); if (GENUTIL_function_call_depth < 0) { fprintf(stdout,"genutil: The function call depth indicator fell to %d, this indicates that not\n" "genutil: all of the functions are utilizing the entering_function and\n" "genutil: leaving_function macros correctly.  Make sure that all function\n" "genutil: entrance points contain a call to entering_function and that all\n" "genutil: function exit points contain a call to leaving_function.\n", GENUTIL_function_call_depth); exit(-1); } fprintf(stdout, "(depth:%d)", GENUTIL_function_call_depth); for (GENUTIL_i = 0; GENUTIL_i < GENUTIL_function_call_depth; GENUTIL_i++) { fprintf(stdout, "."); } fprintf(stdout, "> "); fprintf(stdout, "%s\n", GENUTIL_function_name); fflush(stdout); GENUTIL_function_call_depth++; } while (0);
 GENUTIL_function_call_depth--; do { int GENUTIL_i; fprintf(stdout, "%s(%d): LEAVING", "gentest.c", 22); if (GENUTIL_function_call_depth < 0) { fprintf(stdout,"genutil: The function call depth indicator fell to %d, this indicates that not\n" "genutil: all of the functions are utilizing the entering_function and\n" "genutil: leaving_function macros correctly.  Make sure that all function\n" "genutil: entrance points contain a call to entering_function and that all\n" "genutil: function exit points contain a call to leaving_function.\n", GENUTIL_function_call_depth); exit(-1); } fprintf(stdout, "(depth:%d)", GENUTIL_function_call_depth); for (GENUTIL_i = 0; GENUTIL_i < GENUTIL_function_call_depth; GENUTIL_i++) { fprintf(stdout, "."); } fprintf(stdout, "> "); fprintf(stdout, "%s [%d]\n", GENUTIL_function_name, (int) 4); fflush(stdout); } while (0);
 return 4;
}


main

repo: kephas/maru

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
printf("(define %s %d)\n", "__ELF__", 1LL);
printf("(define %s \"%s\")\n", "__USER_LABEL_PREFIX__", "");
printf("(define %s %d)\n", "__linux__", 1LL);
return 0;
}

original_code:
int main()
{
    printf("(define %s %d)\n", "__ELF__", 1);
    printf("(define %s \"%s\")\n", "__USER_LABEL_PREFIX__", "");
    printf("(define %s %d)\n", "__linux__", 1);
    return 0;
}


repo: kepplemr/operatingSystems

decompiled_code:
void __fastcall __noreturn read_user(void *a1)
{
while ( 1 )
{
sem_wait(&reader_lock);
puts("In reader task");
sleep(2u);
sem_post(&writer_lock);
}
}

canonical_decompiled_code:
void __fastcall __noreturn func7(void *a1)
{
while ( 1 )
{
sem_wait(&reader_lock);
puts("In reader task");
sleep(2u);
sem_post(&writer_lock);
}
}

original_code:
void read_user(void) {
  while (1) {
    sem_wait(&reader_lock);
    printf("In reader task\n");
    sleep(2);
    sem_post(&writer_lock);
  }
}

canonical_original_code:
void read_user() {
  while (1) {
    sem_wait(&reader_lock);
    printf("In reader task\n");
    sleep(2);
    sem_post(&writer_lock);
  }
}


decompiled_code:
void __noreturn write_user()
{
while ( 1 )
{
sem_wait(&writer_lock);
puts("In writer task");
sleep(2u);
sem_post(&reader_lock);
}
}

canonical_decompiled_code:
void __noreturn func8()
{
while ( 1 )
{
sem_wait(&writer_lock);
puts("In writer task");
sleep(2u);
sem_post(&reader_lock);
}
}

original_code:
void write_user(void) {
  while (1) {
    sem_wait(&writer_lock);
    printf("In writer task\n");
    sleep(2);
    sem_post(&reader_lock);
  }
}

canonical_original_code:
void write_user() {
  while (1) {
    sem_wait(&writer_lock);
    printf("In writer task\n");
    sleep(2);
    sem_post(&reader_lock);
  }
}


decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
pthread_t newthread; // [rsp+8h] [rbp-50h] BYREF
pthread_attr_t attr; // [rsp+10h] [rbp-48h] BYREF

sem_init(&writer_lock, 0, 1u);
sem_init(&reader_lock, 0, 1u);
sem_wait(&reader_lock);
pthread_attr_init(&attr);
pthread_create(&newthread, &attr, read_user, 0LL);
write_user();
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
pthread_t newthread; // [rsp+8h] [rbp-50h] BYREF
pthread_attr_t attr; // [rsp+10h] [rbp-48h] BYREF

sem_init(&writer_lock, 0, 1u);
sem_init(&reader_lock, 0, 1u);
sem_wait(&reader_lock);
pthread_attr_init(&attr);
pthread_create(&newthread, &attr, read_user, 0LL);
func8();
}

original_code:
int main() {
  pthread_t read_thread;
  pthread_attr_t attribute;
  sem_init(&writer_lock, 0, 1);
  sem_init(&reader_lock, 0, 1);
  sem_wait(&reader_lock);
  pthread_attr_init(&attribute);
  pthread_create(&read_thread, &attribute, (void *) &read_user, ((void *)0));
  write_user();
  return 0;
}

canonical_original_code:
int main() {
  unsigned long read_thread;
  union pthread_attr_t attribute;
  sem_init(&writer_lock, 0, 1);
  sem_init(&reader_lock, 0, 1);
  sem_wait(&reader_lock);
  pthread_attr_init(&attribute);
  pthread_create(&read_thread, &attribute, (void *) &read_user, ((void *)0));
  write_user();
  return 0;
}

variable_types: union pthread_attr_t { char __size[56]; long __align; }


repo: kepstin/hajimete

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
int *v5; // rax
char *v6; // rax
int *v7; // rax
char *v8; // rax
int *v9; // rax
char *v10; // rax
int *v11; // rax
char *v12; // rax
int *v13; // rax
char *v14; // rax
char v15; // [rsp+1h] [rbp-89h]
int v16; // [rsp+2h] [rbp-88h] BYREF
__int16 v17; // [rsp+6h] [rbp-84h]
char v18; // [rsp+81h] [rbp-9h]

puts("\thajimemasu");
if ( mount("proc", "/proc", "proc", 0LL, 0LL) )
{
v11 = __errno_location();
v12 = strerror(*v11);
printf("Failed to mount /proc: %s\n", v12);
}
if ( mount("sysfs", "/sys", "sysfs", 0LL, 0LL) )
{
v9 = __errno_location();
v10 = strerror(*v9);
printf("Failed to mount /sys: %s\n", v10);
}
read_cmdline_constprop_0_isra_0();
kernel_param_parse(&cmdline, &params);
udev_init();
printf("Detected root as '%s'\n", src);
strncpy((char *)&v16, src, 0x7FuLL);
v18 = 0;
while ( 1 )
{
if ( v16 == 1818585203 && v17 == 108 )
{
rescue();
goto LABEL_15;
}
puts("I'm now going to attempt to mount your root device.");
v3 = exec_run_wait("/bin/mount", 0);
if ( !v3 )
break;
printf("Failed to mount root (%d)\n", v3);
LABEL_15:
printf("Try entering another root device, or 'shell' for a rescue shell\nroot> ");
fgets((char *)&v16, 128, stdin);
*(&v15 + strlen((const char *)&v16)) = 0;
}
puts("Looks good, switching to it.");
udev_kill();
if ( chroot("/newroot") )
{
v7 = __errno_location();
v8 = strerror(*v7);
printf("Failed to chroot: %s\n", v8);
}
else if ( chdir("/") )
{
v5 = __errno_location();
v6 = strerror(*v5);
printf("Failed to chdir to /: %s\n", v6);
}
else
{
puts("And now, running your real init. From now on, it's all you.");
if ( execv(off_4040E8, (char *const *)argv) )
{
v13 = __errno_location();
v14 = strerror(*v13);
printf("Failed to exec %s: %s", off_4040E8, v14);
}
}
puts(
"An unrecoverable error has occurred. Please contact your distribution support\n"
"In your report, include as much of the above text as you can see.");
sleep(5u);
return 1;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
int *v5; // rax
char *v6; // rax
int *v7; // rax
char *v8; // rax
int *v9; // rax
char *v10; // rax
int *v11; // rax
char *v12; // rax
int *v13; // rax
char *v14; // rax
char v15; // [rsp+1h] [rbp-89h]
int v16; // [rsp+2h] [rbp-88h] BYREF
__int16 v17; // [rsp+6h] [rbp-84h]
char v18; // [rsp+81h] [rbp-9h]

puts("\thajimemasu");
if ( mount("proc", "/proc", "proc", 0LL, 0LL) )
{
v11 = __errno_location();
v12 = strerror(*v11);
printf("Failed to mount /proc: %s\n", v12);
}
if ( mount("sysfs", "/sys", "sysfs", 0LL, 0LL) )
{
v9 = __errno_location();
v10 = strerror(*v9);
printf("Failed to mount /sys: %s\n", v10);
}
func8();
func12(&cmdline, &params);
func14();
printf("Detected root as '%s'\n", src);
strncpy((char *)&v16, src, 0x7FuLL);
v18 = 0;
while ( 1 )
{
if ( v16 == 1818585203 && v17 == 108 )
{
func13();
goto LABEL_15;
}
puts("I'm now going to attempt to mount your root device.");
v3 = func7("/bin/mount", 0);
if ( !v3 )
break;
printf("Failed to mount root (%d)\n", v3);
LABEL_15:
printf("Try entering another root device, or 'shell' for a rescue shell\nroot> ");
fgets((char *)&v16, 128, stdin);
*(&v15 + strlen((const char *)&v16)) = 0;
}
puts("Looks good, switching to it.");
func15();
if ( chroot("/newroot") )
{
v7 = __errno_location();
v8 = strerror(*v7);
printf("Failed to chroot: %s\n", v8);
}
else if ( chdir("/") )
{
v5 = __errno_location();
v6 = strerror(*v5);
printf("Failed to chdir to /: %s\n", v6);
}
else
{
puts("And now, running your real init. From now on, it's all you.");
if ( execv(off_4040E8, (char *const *)argv) )
{
v13 = __errno_location();
v14 = strerror(*v13);
printf("Failed to exec %s: %s", off_4040E8, v14);
}
}
puts(
"An unrecoverable error has occurred. Please contact your distribution support\n"
"In your report, include as much of the above text as you can see.");
sleep(5u);
return 1;
}

original_code:
int main(int argc, char *argv[])
{
 int err;
 char root[128];
 int mounted = 0;
 printf("\thajimemasu\n");
 err = mount("proc", "/proc", "proc", 0, ((void *)0));
 if (err)
  printf("Failed to mount /proc: %s\n", strerror((*__errno_location ())));
 err = mount("sysfs", "/sys", "sysfs", 0, ((void *)0));
 if (err)
  printf("Failed to mount /sys: %s\n", strerror((*__errno_location ())));
 err = read_cmdline(cmdline);
 kernel_param_parse(cmdline, params);
 udev_init();
 printf("Detected root as '%s'\n", param_root.value);
 strncpy(root, param_root.value, 128);
 root[127] = '\0';
 while (!mounted) {
  if (strcmp(root, "shell") == 0)
   rescue();
  else {
   printf("I'm now going to attempt to mount your root device.\n");
   err = exec_run_wait("/bin/mount", "/bin/mount",
    "-o", "ro", root, "/newroot", (char *) ((void *)0));
   if (err)
    printf("Failed to mount root (%d)\n", err);
   else
    mounted = 1;
  }
  if (!mounted) {
   printf("Try entering another root device, or 'shell' for a rescue shell\n"
    "root> ");
   fgets(root, 128, stdin);
   root[strlen(root) - 1] = '\0';
  }
 }
 printf("Looks good, switching to it.\n");
 udev_kill();
 err = chroot("/newroot");
 if (err) {
  printf("Failed to chroot: %s\n", strerror((*__errno_location ())));
  goto die_hard;
 }
 err = chdir("/");
 if (err) {
  printf("Failed to chdir to /: %s\n", strerror((*__errno_location ())));
  goto die_hard;
 }
 printf("And now, running your real init. From now on, it's all you.\n");
 err = execv(param_init.value, argv);
 if (err) {
  printf("Failed to exec %s: %s", param_init.value, strerror((*__errno_location ())));
  goto die_hard;
 }
die_hard:
 printf("An unrecoverable error has occurred. Please contact your distribution support\n"
  "In your report, include as much of the above text as you can see.\n");
 sleep(5);
 return 1;
}

variable_types:
argv
char *[]

variable_types: err int

variable_types:
root
char [128]

variable_types: mounted int


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

result = 95LL;
if ( (_BYTE)a1 != 45 )
result = a1;
return result;
}

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

result = 95LL;
if ( (_BYTE)a1 != 45 )
result = a1;
return result;
}

original_code:
static inline char dash2underscore(char c)
{
 if (c == '-')
  return '_';
 return c;
}

variable_types: c char

return_type: char


parameq

decompiled_code:
__int64 __fastcall parameq(__int64 a1)
{
unsigned int i; // esi
char v3; // al
char v4; // cl
__int64 v5; // rdx
__int64 v6; // r8

for ( i = 0; ; ++i )
{
v3 = dash2underscore(*(char *)(a1 + i));
if ( v3 != *(_BYTE *)(v6 + v5) )
return 0LL;
if ( !v4 )
break;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
unsigned int i; // esi
char v3; // al
char v4; // cl
__int64 v5; // rdx
__int64 v6; // r8

for ( i = 0; ; ++i )
{
v3 = func9(*(char *)(a1 + i));
if ( v3 != *(_BYTE *)(v6 + v5) )
return 0LL;
if ( !v4 )
break;
}
return 1LL;
}

original_code:
static inline int parameq(const char *input, const char *paramname)
{
 unsigned int i;
 for (i = 0; dash2underscore(input[i]) == paramname[i]; i++)
  if (input[i] == '\0')
   return 1;
 return 0;
}

canonical_original_code:
static inline int parameq(char *input, char *paramname)
{
 unsigned int i;
 for (i = 0; dash2underscore(input[i]) == paramname[i]; i++)
  if (input[i] == '\0')
   return 1;
 return 0;
}

variable_types:
input
char *

variable_types:
paramname
char *

variable_types:
i
unsigned int


decompiled_code:
void __fastcall parse_one(__int64 a1, __int64 a2, _QWORD *a3)
{
__int64 v4; // r10
int v5; // er11

if ( *a3 )
{
do
{
if ( (unsigned int)parameq(a1) )
*(_QWORD *)(v4 + 8) = a2;
}
while ( a3[v5 + 1] );
}
}

canonical_decompiled_code:
void __fastcall func11(__int64 a1, __int64 a2, _QWORD *a3)
{
__int64 v4; // r10
int v5; // er11

if ( *a3 )
{
do
{
if ( (unsigned int)func10(a1) )
*(_QWORD *)(v4 + 8) = a2;
}
while ( a3[v5 + 1] );
}
}

original_code:
static void parse_one(char *param,
       char *val,
       struct kernel_param *params[])
{
 unsigned int i;
 for (i = 0; params[i]; i++) {
  if (parameq(param, params[i]->name)) {
   params[i]->value = val;
  }
 }
}

variable_types:
param
char *

variable_types:
val
char *

variable_types: struct kernel_param { char *name; char *value; } *[]


decompiled_code:
__int64 __fastcall kernel_param_parse(const char *a1, _QWORD *a2)
{
_BYTE *v2; // rbp
char i; // al
__int64 v5; // [rsp+0h] [rbp-28h] BYREF
__int64 v6[4]; // [rsp+8h] [rbp-20h] BYREF

if ( !a2 )
return 0LL;
v2 = a1;
printf("Kernel Parameters: %s\n", a1);
for ( i = *a1; i == 32; ++v2 )
i = v2[1];
if ( i )
{
do
{
v2 = next_arg(v2, &v5, v6);
parse_one(v5, v6[0], a2);
}
while ( *v2 );
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func12(const char *a1, _QWORD *a2)
{
_BYTE *v2; // rbp
char i; // al
__int64 v5; // [rsp+0h] [rbp-28h] BYREF
__int64 v6[4]; // [rsp+8h] [rbp-20h] BYREF

if ( !a2 )
return 0LL;
v2 = a1;
printf("Kernel Parameters: %s\n", a1);
for ( i = *a1; i == 32; ++v2 )
i = v2[1];
if ( i )
{
do
{
v2 = next_arg(v2, &v5, v6);
func11(v5, v6[0], a2);
}
while ( *v2 );
}
return 0LL;
}

original_code:
int kernel_param_parse(char *args,
   struct kernel_param *params[])
{
 char *param, *val;
 if (!params)
  return 0;
 printf("Kernel Parameters: %s\n", args);
 while (*args == ' ')
  args++;
 while (*args) {
  args = next_arg(args, &param, &val);
  parse_one(param, val, params);
 }
 return 0;
}

canonical_original_code:
int kernel_param_parse(char *args, struct kernel_param *params[])
{
 char *param; char *val;
 if (!params)
  return 0;
 printf("Kernel Parameters: %s\n", args);
 while (*args == ' ')
  args++;
 while (*args) {
  args = next_arg(args, &param, &val);
  parse_one(param, val, params);
 }
 return 0;
}

variable_types:
args
char *

user_defined_types: struct kernel_param { char *name; char *value; }


rescue

decompiled_code:
int __fastcall rescue(double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8)
{
return exec_run_wait("/sbin/sulogin", (__int64)"/sbin/sulogin", a1, a2, a3, a4, a5, a6, a7, a8, 0LL);
}

canonical_decompiled_code:
int __fastcall func13(double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8)
{
return func7("/sbin/sulogin", (__int64)"/sbin/sulogin", a1, a2, a3, a4, a5, a6, a7, a8, 0LL);
}

original_code:
int rescue(void)
{
 return exec_run_wait("/sbin/sulogin", "/sbin/sulogin", (char *) ((void *)0));
}

canonical_original_code:
int rescue()
{
 return exec_run_wait("/sbin/sulogin", "/sbin/sulogin", (char *) ((void *)0));
}


repo: kernelhcy/swiftd

decompiled_code:
int __fastcall mm_cache_show(__int64 a1)
{
int result; // eax

if ( a1 )
{
printf("\nMemory cache name: %s\n", (const char *)a1);
printf("Object size: %d Align: %d\n", *(_QWORD *)(a1 + 256), *(unsigned int *)(a1 + 264));
result = printf("Pre %s next %s\n", *(const char **)(a1 + 304), *(const char **)(a1 + 312));
}
return result;
}

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

if ( a1 )
{
printf("\nMemory cache name: %s\n", (const char *)a1);
printf("Object size: %d Align: %d\n", *(_QWORD *)(a1 + 256), *(unsigned int *)(a1 + 264));
result = printf("Pre %s next %s\n", *(const char **)(a1 + 304), *(const char **)(a1 + 312));
}
return result;
}

original_code:
static void mm_cache_show(struct mm_cache *mc)
{
 if(((void *)0) == mc){
  return;
 }
 printf("\nMemory cache name: %s\n", mc -> name);
 printf("Object size: %d  Align: %d\n", mc -> size, mc -> align);
 printf("Pre %s next %s\n", mc -> pre -> name, mc -> next -> name);
}

variable_types: struct mm_cache { char name[256]; unsigned long size; int align; void (*ctor)(void *); void (*dtor)(void *); unsigned long total_objs; unsigned long total_mm; struct mm_cache *pre; } *


original_code:
void mm_cache_destroy(struct mm_cache *mc)
{
 if(((void *)0) == mc){
  return;
 }
 mc -> next -> pre = mc -> pre;
 mc -> pre -> next = mc -> next;
 if(head == mc){
  head = mc -> next;
 }
 free(mc);
}

user_defined_types: struct mm_cache { char name[256]; unsigned long size; int align; void (*ctor)(void *); void (*dtor)(void *); unsigned long total_objs; unsigned long total_mm; struct mm_cache *pre; }


decompiled_code:
__int64 __fastcall mm_cache_alloc(const char *a1)
{
printf("Alloc an object from : %s\n", a1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(const char *a1)
{
printf("Alloc an object from : %s\n", a1);
return 0LL;
}

original_code:
void * mm_cache_alloc(struct mm_cache *mc)
{
 printf("Alloc an object from : %s\n", mc -> name);
 return ((void *)0);
}

canonical_original_code:
void *mm_cache_alloc(struct mm_cache *mc)
{
 printf("Alloc an object from : %s\n", mc -> name);
 return ((void *)0);
}

return_type: void *


decompiled_code:
int __fastcall mm_cache_free(const char *a1)
{
return printf("Free an object to %s\n", a1);
}

canonical_decompiled_code:
int __fastcall func11(const char *a1)
{
return printf("Free an object to %s\n", a1);
}

original_code:
void mm_cache_free(struct mm_cache *mc, void *p)
{
 printf("Free an object to %s\n", mc -> name);
}

variable_types:
p
void *


decompiled_code:
void mm_cache_shrink()
{
;
}

canonical_decompiled_code:
void func12()
{
;
}

original_code:
void mm_cache_shrink()
{
}

canonical_original_code:
void mm_cache_shrink()
{
}


decompiled_code:
int mm_show()
{
__int64 v0; // rax
__int64 v1; // rbx

if ( head )
{
mm_cache_show(head);
v0 = head;
v1 = *(_QWORD *)(head + 312);
if ( v1 )
{
while ( v0 != v1 )
{
LODWORD(v0) = mm_cache_show(v1);
v1 = *(_QWORD *)(v1 + 312);
if ( !v1 )
break;
v0 = head;
}
}
}
else
{
LODWORD(v0) = puts("Memory cache is empty!");
}
return v0;
}

canonical_decompiled_code:
int func13()
{
__int64 v0; // rax
__int64 v1; // rbx

if ( head )
{
func7(head);
v0 = head;
v1 = *(_QWORD *)(head + 312);
if ( v1 )
{
while ( v0 != v1 )
{
LODWORD(v0) = func7(v1);
v1 = *(_QWORD *)(v1 + 312);
if ( !v1 )
break;
v0 = head;
}
}
}
else
{
LODWORD(v0) = puts("Memory cache is empty!");
}
return v0;
}

original_code:
void mm_show()
{
 if(((void *)0) == head){
  printf("Memory cache is empty!\n");
  return;
 }
 mm_cache_show(head);
 struct mm_cache *tmp = head -> next;
 while(tmp != ((void *)0) && tmp != head)
 {
  mm_cache_show(tmp);
  tmp = tmp -> next;
 }
}


repo: kernelslacker/trinity

decompiled_code:
char **__fastcall lookup_domain(char *s1)
{
char *v1; // r13
unsigned int v2; // eax
size_t v3; // r12
__int64 v4; // rbx
size_t v5; // rax
const char *i; // rbp

if ( !s1 )
return 0LL;
v1 = s1;
v2 = strlen(s1);
v3 = v2;
if ( *s1 == 80 && s1[1] == 70 && s1[2] == 95 )
{
v1 = s1 + 3;
v3 = v2 - 3;
}
v4 = 0LL;
v5 = 6LL;
for ( i = "UNSPEC"; ; v5 = strlen(i) )
{
if ( v3 == v5 && !strncmp(v1, i, v3) )
return &(&domains)[2 * v4];
if ( ++v4 == 48 )
break;
i = (&domains)[2 * v4];
}
return 0LL;
}

canonical_decompiled_code:
char **__fastcall func0(char *s1)
{
char *v1; // r13
unsigned int v2; // eax
size_t v3; // r12
__int64 v4; // rbx
size_t v5; // rax
const char *i; // rbp

if ( !s1 )
return 0LL;
v1 = s1;
v2 = strlen(s1);
v3 = v2;
if ( *s1 == 80 && s1[1] == 70 && s1[2] == 95 )
{
v1 = s1 + 3;
v3 = v2 - 3;
}
v4 = 0LL;
v5 = 6LL;
for ( i = "UNSPEC"; ; v5 = strlen(i) )
{
if ( v3 == v5 && !strncmp(v1, i, v3) )
return &(&domains)[2 * v4];
if ( ++v4 == 48 )
break;
i = (&domains)[2 * v4];
}
return 0LL;
}

original_code:
static const struct domain *lookup_domain(const char *name)
{
 unsigned int i, len;
 if (!name)
  return ((void *)0);
 len = strlen(name);
 if (strncmp(name, "PF_", 3) == 0) {
  name += 3;
  len-=3;
 }
 for (i = 0; i < (sizeof(domains) / sizeof((domains)[0])); i++) {
  if (len != strlen(domains[i].name))
   continue;
  if (strncmp(name, domains[i].name, len) == 0)
   return &domains[i];
 }
 return ((void *)0);
}

canonical_original_code:
static struct domain *lookup_domain(char *name)
{
 unsigned int i; unsigned int len;
 if (!name)
  return ((void *)0);
 len = strlen(name);
 if (strncmp(name, "PF_", 3) == 0) {
  name += 3;
  len-=3;
 }
 for (i = 0; i < (sizeof(domains) / sizeof((domains)[0])); i++) {
  if (len != strlen(domains[i].name))
   continue;
  if (strncmp(name, domains[i].name, len) == 0)
   return &domains[i];
 }
 return ((void *)0);
}

variable_types:
name
char *

variable_types:
len
unsigned int

return_type: struct domain { char *name; unsigned int domain; } *


decompiled_code:
char *__fastcall get_domain_name(int a1)
{
__int64 v1; // rax
int i; // edx

v1 = 0LL;
for ( i = 0; ; i = dword_4E8[4 * v1] )
{
if ( i == a1 )
return (&domains)[2 * (unsigned int)v1];
if ( ++v1 == 48 )
break;
}
return 0LL;
}

canonical_decompiled_code:
char *__fastcall func1(int a1)
{
__int64 v1; // rax
int i; // edx

v1 = 0LL;
for ( i = 0; ; i = dword_4E8[4 * v1] )
{
if ( i == a1 )
return (&domains)[2 * (unsigned int)v1];
if ( ++v1 == 48 )
break;
}
return 0LL;
}

original_code:
const char * get_domain_name(unsigned int domain)
{
 unsigned int i;
 for (i = 0; i < (sizeof(domains) / sizeof((domains)[0])); i++)
  if (domains[i].domain == domain)
   return domains[i].name;
 return ((void *)0);
}

canonical_original_code:
char *get_domain_name(unsigned int domain)
{
 unsigned int i;
 for (i = 0; i < (sizeof(domains) / sizeof((domains)[0])); i++)
  if (domains[i].domain == domain)
   return domains[i].name;
 return ((void *)0);
}

variable_types:
domain
unsigned int


decompiled_code:
__int64 __fastcall find_specific_domain(char *a1)
{
char **v1; // rax
char **v3; // rbx
const char *v4; // rsi

v1 = lookup_domain(a1);
if ( !v1 )
{
v3 = &domains;
outputerr("Domain unknown. Pass one of ");
do
{
v4 = *v3;
v3 += 2;
outputerr("%s ", v4);
}
while ( v3 != (char **)&unk_7E0 );
outputerr("\n");
exit(1);
}
specific_domain = *((_DWORD *)v1 + 2);
return output(2LL, "Using domain %s for all sockets\n", *v1);
}

canonical_decompiled_code:
__int64 __fastcall func2(char *a1)
{
char **v1; // rax
char **v3; // rbx
const char *v4; // rsi

v1 = func0(a1);
if ( !v1 )
{
v3 = &domains;
outputerr("Domain unknown. Pass one of ");
do
{
v4 = *v3;
v3 += 2;
outputerr("%s ", v4);
}
while ( v3 != (char **)&unk_7E0 );
outputerr("\n");
exit(1);
}
specific_domain = *((_DWORD *)v1 + 2);
return output(2LL, "Using domain %s for all sockets\n", *v1);
}

original_code:
void find_specific_domain(const char *domainarg)
{
 const struct domain *p;
 unsigned int i;
 p = lookup_domain(domainarg);
 if (p) {
  specific_domain = p->domain;
  output(2, "Using domain %s for all sockets\n", p->name);
  return;
 }
 outputerr("Domain unknown. Pass one of ");
 for (i = 0; i < (sizeof(domains) / sizeof((domains)[0])); i++)
  outputerr("%s ", domains[i].name);
 outputerr("\n");
 exit(1);
}

canonical_original_code:
void find_specific_domain(char *domainarg)
{
 struct domain *p;
 unsigned int i;
 p = lookup_domain(domainarg);
 if (p) {
  specific_domain = p->domain;
  output(2, "Using domain %s for all sockets\n", p->name);
  return;
 }
 outputerr("Domain unknown. Pass one of ");
 for (i = 0; i < (sizeof(domains) / sizeof((domains)[0])); i++)
  outputerr("%s ", domains[i].name);
 outputerr("\n");
 exit(1);
}

variable_types:
domainarg
char *

variable_types: struct domain { char *name; unsigned int domain; } *


decompiled_code:
__int64 __fastcall find_next_enabled_domain(unsigned int a1)
{
unsigned int v1; // edi
unsigned int v2; // eax
unsigned int v3; // er8
__int64 v4; // rax

v1 = a1 % 0x2D;
v2 = v1;
do
{
v3 = *((_DWORD *)&no_domains + v2);
if ( !v3 )
return v3;
++v2;
}
while ( v2 != 45 );
if ( v1 )
{
v4 = 0LL;
while ( 1 )
{
v3 = *((_DWORD *)&no_domains + v4);
if ( !v3 )
break;
if ( ++v4 == v1 )
return 0xFFFFFFFFLL;
}
return v3;
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1)
{
unsigned int v1; // edi
unsigned int v2; // eax
unsigned int v3; // er8
__int64 v4; // rax

v1 = a1 % 0x2D;
v2 = v1;
do
{
v3 = *((_DWORD *)&no_domains + v2);
if ( !v3 )
return v3;
++v2;
}
while ( v2 != 45 );
if ( v1 )
{
v4 = 0LL;
while ( 1 )
{
v3 = *((_DWORD *)&no_domains + v4);
if ( !v3 )
break;
if ( ++v4 == v1 )
return 0xFFFFFFFFLL;
}
return v3;
}
return 0xFFFFFFFFLL;
}

original_code:
unsigned int find_next_enabled_domain(unsigned int from)
{
 unsigned int i;
 from %= (sizeof(no_domains) / sizeof((no_domains)[0]));
 for (i = from; i < (sizeof(no_domains) / sizeof((no_domains)[0])); i++) {
  if (no_domains[i] == FALSE)
   return no_domains[i];
 }
 for (i = 0; i < from; i++) {
  if (no_domains[i] == FALSE)
   return no_domains[i];
 }
 return -1u;
}

variable_types:
from
unsigned int

return_type: unsigned int


decompiled_code:
void __fastcall parse_exclude_domains(const char *a1)
{
char *v2; // rax
char *v3; // rbp
char *i; // rdi
char **v5; // rax
__int64 v6; // rax

v2 = strdup(a1);
if ( !v2 )
{
outputerr("No free memory\n");
exit(1);
}
v3 = v2;
for ( i = strtok(v2, ","); i; i = strtok(0LL, ",") )
{
v5 = lookup_domain(i);
if ( !v5 )
{
free(v3);
outputerr("Domain unknown in argument %s\n", a1);
exit(1);
}
v6 = *((unsigned int *)v5 + 2);
if ( (unsigned int)v6 > 0x2C )
{
_BUG(
"p->domain >= (sizeof(no_domains) / sizeof((no_domains)[0]))",
"net/domains.c",
"parse_exclude_domains",
156LL);
while ( 1 )
;
}
*((_DWORD *)&no_domains + v6) = 1;
}
free(v3);
}

canonical_decompiled_code:
void __fastcall func4(const char *a1)
{
char *v2; // rax
char *v3; // rbp
char *i; // rdi
char **v5; // rax
__int64 v6; // rax

v2 = strdup(a1);
if ( !v2 )
{
outputerr("No free memory\n");
exit(1);
}
v3 = v2;
for ( i = strtok(v2, ","); i; i = strtok(0LL, ",") )
{
v5 = func0(i);
if ( !v5 )
{
free(v3);
outputerr("Domain unknown in argument %s\n", a1);
exit(1);
}
v6 = *((unsigned int *)v5 + 2);
if ( (unsigned int)v6 > 0x2C )
{
_BUG(
"p->domain >= (sizeof(no_domains) / sizeof((no_domains)[0]))",
"net/domains.c",
"parse_exclude_domains",
156LL);
while ( 1 )
;
}
*((_DWORD *)&no_domains + v6) = 1;
}
free(v3);
}

original_code:
void parse_exclude_domains(const char *arg)
{
 char *_arg = strdup(arg);
 const struct domain *p;
 char *tok;
 if (!_arg) {
  outputerr("No free memory\n");
  exit(1);
 }
 for (tok = strtok(_arg, ","); tok; tok = strtok(((void *)0), ",")) {
  p = lookup_domain(tok);
  if (p) {
   do { if ((p->domain >= (sizeof(no_domains) / sizeof((no_domains)[0])))) { __BUG("p->domain >= (sizeof(no_domains) / sizeof((no_domains)[0]))", "net/domains.c", __func__, 156); do { } while (1); }; } while (0);
   no_domains[p->domain] = TRUE;
  } else
   goto err;
 }
 free(_arg);
 return;
err:
 free(_arg);
 outputerr("Domain unknown in argument %s\n", arg);
 exit(1);
}

canonical_original_code:
void parse_exclude_domains(char *arg)
{
 char *_arg = strdup(arg);
 struct domain *p;
 char *tok;
 if (!_arg) {
  outputerr("No free memory\n");
  exit(1);
 }
 for (tok = strtok(_arg, ","); tok; tok = strtok(((void *)0), ",")) {
  p = lookup_domain(tok);
  if (p) {
   do { if ((p->domain >= (sizeof(no_domains) / sizeof((no_domains)[0])))) { __BUG("p->domain >= (sizeof(no_domains) / sizeof((no_domains)[0]))", "net/domains.c", __func__, 156); do { } while (1); }; } while (0);
   no_domains[p->domain] = TRUE;
  } else
   goto err;
 }
 free(_arg);
 return;
err:
 free(_arg);
 outputerr("Domain unknown in argument %s\n", arg);
 exit(1);
}

variable_types:
arg
char *

variable_types:
tok
char *

user_defined_types: struct domain { char *name; unsigned int domain; }