decompiled_code:
__int64 __fastcall rn_ban(const char *a1, __int64 a2, __int64 a3, int a4, __int64 a5)
{
__int64 v5; // rbp
__int64 v6; // r15
unsigned int v7; // eax
__int64 v8; // rbx
int v9; // er12
__int64 v10; // rbp
unsigned int v12; // [rsp+Ch] [rbp-4Ch]

v5 = a3;
v6 = a5;
v7 = a4 + time(0LL);
v12 = v7;
if ( *((_QWORD *)a1 + 22) )
{
if ( (unsigned int)br_add(*(_QWORD *)a1, a2, v6, 114LL, v5, v7) )
{
v8 = *(_QWORD *)(*((_QWORD *)a1 + 22) + 632LL);
v9 = 0;
do
{
if ( !v8 )
break;
v10 = *(_QWORD *)(v8 + 64);
if ( v10 && (!*(_BYTE *)(v8 + 73) || strchr(a1 + 8, 111)) )
{
if ( (unsigned int)wildicmp(a2, v10) )
{
makeBanSpace(*((_QWORD *)a1 + 22), v9 + 1);
sprintf(newmask, "*!*@%s", *(const char **)(v8 + 48));
br_add(*(_QWORD *)a1, newmask, a5, 100LL, a3, v12);
sprintf(banbuf, "MODE %s +b %s", *(const char **)a1, newmask);
quickMsg(banbuf);
v9 += enforce_ban(*((_QWORD *)a1 + 22), newmask, a5, a3, v12);
}
}
v8 = *(_QWORD *)(v8 + 104);
}
while ( config[256] > v9 );
save_chans("chans.txt");
}
else
{
v9 = -1;
}
}
else
{
v9 = -1;
}
return (unsigned int)v9;
}

canonical_decompiled_code:
__int64 __fastcall func3(const char *a1, __int64 a2, __int64 a3, int a4, __int64 a5)
{
__int64 v5; // rbp
__int64 v6; // r15
unsigned int v7; // eax
__int64 v8; // rbx
int v9; // er12
__int64 v10; // rbp
unsigned int v12; // [rsp+Ch] [rbp-4Ch]

v5 = a3;
v6 = a5;
v7 = a4 + time(0LL);
v12 = v7;
if ( *((_QWORD *)a1 + 22) )
{
if ( (unsigned int)br_add(*(_QWORD *)a1, a2, v6, 114LL, v5, v7) )
{
v8 = *(_QWORD *)(*((_QWORD *)a1 + 22) + 632LL);
v9 = 0;
do
{
if ( !v8 )
break;
v10 = *(_QWORD *)(v8 + 64);
if ( v10 && (!*(_BYTE *)(v8 + 73) || strchr(a1 + 8, 111)) )
{
if ( (unsigned int)wildicmp(a2, v10) )
{
func1(*((_QWORD *)a1 + 22), v9 + 1);
sprintf(newmask, "*!*@%s", *(const char **)(v8 + 48));
br_add(*(_QWORD *)a1, newmask, a5, 100LL, a3, v12);
sprintf(banbuf, "MODE %s +b %s", *(const char **)a1, newmask);
quickMsg(banbuf);
v9 += enforce_ban(*((_QWORD *)a1 + 22), newmask, a5, a3, v12);
}
}
v8 = *(_QWORD *)(v8 + 104);
}
while ( config[256] > v9 );
save_chans("chans.txt");
}
else
{
v9 = -1;
}
}
else
{
v9 = -1;
}
return (unsigned int)v9;
}

original_code:
int rn_ban(struct chanRec *theChan, char *mask, char *setby, int secs, char *reason)
{
 int count;
 struct suser *i;
 secs += time(((void *)0));
 if(!theChan->physical)
  return -1;
 if(!br_add(theChan->name, mask, reason, 'r', setby, secs))
  return -1;
 i = theChan->physical->user;
 count = 0;
 while(i)
 {
  if(i->realname && (!i->isOp || strchr(theChan->flags, 'o')) )
   if(wildicmp(mask, i->realname))
   {
    makeBanSpace(theChan->physical, count + 1);
    sprintf(newmask, "*!*@%s", i->host);
    br_add(theChan->name, newmask, reason, 'd', setby, secs);
    sprintf(banbuf, "MODE %s +b %s", theChan->name, newmask);
    quickMsg(banbuf);
    count += enforce_ban(theChan->physical, newmask, reason, setby, secs);
   }
  i = i->next;
  if(count >= config.maxkicks)
   break;
 }
 save_chans("chans.txt");
 return count;
}

variable_types: count int

variable_types: struct suser { char nick[33]; char *ident; char *host; char *mask; char *realname; char isVoice; char isOp; int lastMsg; int flines; int joinTime; int nickchanges; int lastNick; int idleMsg; struct suser *next; struct suser *prev; } *


repo: ipacker/fireclaw

decompiled_code:
char *__fastcall chkfor_rn_ban(_QWORD *a1, __int64 a2)
{
char *result; // rax
__int64 v3; // rbx
int v4; // er13

result = (char *)a1[84];
v3 = *((_QWORD *)result + 23);
if ( v3 )
{
v4 = 0;
do
{
if ( *(_BYTE *)(v3 + 16) == 114 )
{
result = (char *)wildicmp(*(_QWORD *)v3, *(_QWORD *)(a2 + 64));
if ( (_DWORD)result )
{
if ( !*(_BYTE *)(a2 + 73) || (result = strchr((const char *)(a1[84] + 8LL), 111)) != 0LL )
{
makeBanSpace((__int64)a1, ++v4);
sprintf(newmask, "*!*@%s", *(const char **)(a2 + 48));
br_add(*a1, newmask, *(_QWORD *)(v3 + 8), 100LL, *(_QWORD *)(v3 + 24), *(unsigned int *)(v3 + 32));
sprintf(banbuf, "MODE %s +b %s", (const char *)*a1, newmask);
quickMsg(banbuf);
result = (char *)enforce_ban(
a1,
newmask,
*(_QWORD *)(v3 + 8),
*(_QWORD *)(v3 + 24),
*(unsigned int *)(v3 + 32));
}
}
}
v3 = *(_QWORD *)(v3 + 40);
}
while ( v3 );
if ( v4 > 0 )
result = (char *)save_chans("chans.txt");
}
return result;
}

canonical_decompiled_code:
char *__fastcall func4(_QWORD *a1, __int64 a2)
{
char *result; // rax
__int64 v3; // rbx
int v4; // er13

result = (char *)a1[84];
v3 = *((_QWORD *)result + 23);
if ( v3 )
{
v4 = 0;
do
{
if ( *(_BYTE *)(v3 + 16) == 114 )
{
result = (char *)wildicmp(*(_QWORD *)v3, *(_QWORD *)(a2 + 64));
if ( (_DWORD)result )
{
if ( !*(_BYTE *)(a2 + 73) || (result = strchr((const char *)(a1[84] + 8LL), 111)) != 0LL )
{
func1((__int64)a1, ++v4);
sprintf(newmask, "*!*@%s", *(const char **)(a2 + 48));
br_add(*a1, newmask, *(_QWORD *)(v3 + 8), 100LL, *(_QWORD *)(v3 + 24), *(unsigned int *)(v3 + 32));
sprintf(banbuf, "MODE %s +b %s", (const char *)*a1, newmask);
quickMsg(banbuf);
result = (char *)enforce_ban(
a1,
newmask,
*(_QWORD *)(v3 + 8),
*(_QWORD *)(v3 + 24),
*(unsigned int *)(v3 + 32));
}
}
}
v3 = *(_QWORD *)(v3 + 40);
}
while ( v3 );
if ( v4 > 0 )
result = (char *)save_chans("chans.txt");
}
return result;
}

original_code:
void chkfor_rn_ban(struct schan *theChan, struct suser *theUser)
{
 struct softBan *i;
 int count = 0;
 i = theChan->record->softbans;
 while(i)
 {
  if(i->type == 'r' && wildicmp(i->banmask, theUser->realname) && (!theUser->isOp || strchr(theChan->record->flags, 'o')))
  {
   makeBanSpace(theChan, count + 1);
   sprintf(newmask, "*!*@%s", theUser->host);
   br_add(theChan->name, newmask, i->reason, 'd', i->setby, i->expires);
   sprintf(banbuf, "MODE %s +b %s", theChan->name, newmask);
   quickMsg(banbuf);
   enforce_ban(theChan, newmask, i->reason, i->setby, i->expires);
   count++;
  }
  i = i->next;
 }
 if(count > 0)
  save_chans("chans.txt");
 return;
}

variable_types: struct schan { char *name; char topic[-1]; char modes[-1]; char key[-1]; int limit; int tsLim; struct criminalRecord { char nick[33]; char *identhost; char longTerm; char shortTerm; int laststamp; int lastJoin; int njoins; struct repeat { int id; int ts; char count; } trackrepeat[30]; struct criminalRecord *prev; struct criminalRecord *next; } *nortyusers; struct sban { char *mask; char *setby; int ts; struct sban *next; struct sban *prev; } *bans; struct suser { char nick[33]; char *ident; char *host; char *mask; char *realname; char isVoice; char isOp; int lastMsg; int flines; int joinTime; int nickchanges; int lastNick; int idleMsg; struct suser *next; struct suser *prev; } *user; int userSize; int banSize; int flood_last; int flood_lines; struct schan *next; struct schan *prev; struct chanRec { char *name; char flags[-1]; char key[-1]; char goodModes[-1]; char badModes[-1]; struct schan *physical; struct softBan { char *banmask; char *reason; char type; char *setby; int expires; struct softBan *next; struct softBan *prev; } *softbans; struct chanRec *next; struct chanRec *prev; } *record; } *

variable_types:
theUser
struct suser *

return_type: void

user_defined_types: struct schan { char *name; char topic[-1]; char modes[-1]; char key[-1]; int limit; int tsLim; struct criminalRecord *nortyusers; struct sban *bans; struct suser *user; int userSize; int banSize; int flood_last; int flood_lines; struct schan *next; struct schan *prev; struct chanRec *record; }

user_defined_types: struct criminalRecord { char nick[33]; char *identhost; char longTerm; char shortTerm; int laststamp; int lastJoin; int njoins; struct repeat trackrepeat[30]; struct criminalRecord *prev; struct criminalRecord *next; }

user_defined_types: struct chanRec { char *name; char flags[-1]; char key[-1]; char goodModes[-1]; char badModes[-1]; struct schan *physical; struct softBan *softbans; struct chanRec *next; struct chanRec *prev; }


searchForMissedBans

decompiled_code:
__int64 __fastcall searchForMissedBans(_QWORD *a1)
{
__int64 i; // rbx
__int64 result; // rax

for ( i = a1[79]; i; i = *(_QWORD *)(i + 104) )
{
result = chkfor_ban((__int64)a1, i);
if ( *(_QWORD *)(i + 64) )
result = (__int64)chkfor_rn_ban(a1, i);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(_QWORD *a1)
{
__int64 i; // rbx
__int64 result; // rax

for ( i = a1[79]; i; i = *(_QWORD *)(i + 104) )
{
result = func5((__int64)a1, i);
if ( *(_QWORD *)(i + 64) )
result = (__int64)func4(a1, i);
}
return result;
}

original_code:
void searchForMissedBans(struct schan *theChan)
{
 struct suser *i;
 i = theChan->user;
 while(i)
 {
  chkfor_ban(theChan, i);
  if(i->realname)
   chkfor_rn_ban(theChan, i);
  i = i->next;
 }
 return;
}

user_defined_types: struct suser { char nick[33]; char *ident; char *host; char *mask; char *realname; char isVoice; char isOp; int lastMsg; int flines; int joinTime; int nickchanges; int lastNick; int idleMsg; struct suser *next; struct suser *prev; }

user_defined_types: struct sban { char *mask; char *setby; int ts; struct sban *next; struct sban *prev; }

user_defined_types: struct repeat { int id; int ts; char count; }

user_defined_types: struct softBan { char *banmask; char *reason; char type; char *setby; int expires; struct softBan *next; struct softBan *prev; }


isSoftBan

decompiled_code:
__int64 __fastcall isSoftBan(__int64 a1, const char *a2)
{
__int64 v2; // rbx

if ( !a1 )
return 0LL;
v2 = *(_QWORD *)(a1 + 184);
if ( !v2 )
return 0LL;
while ( strcmp(*(const char **)v2, a2) )
{
v2 = *(_QWORD *)(v2 + 40);
if ( !v2 )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, const char *a2)
{
__int64 v2; // rbx

if ( !a1 )
return 0LL;
v2 = *(_QWORD *)(a1 + 184);
if ( !v2 )
return 0LL;
while ( strcmp(*(const char **)v2, a2) )
{
v2 = *(_QWORD *)(v2 + 40);
if ( !v2 )
return 0LL;
}
return 1LL;
}

original_code:
int isSoftBan(struct chanRec *c, char *mask)
{
 struct softBan *i;
 if(!c)
  return 0;
 i = c->softbans;
 while(i)
 {
  if(!strcmp(i->banmask, mask))
   return 1;
  i = i->next;
 }
 return 0;
}

variable_types: struct chanRec { char *name; char flags[-1]; char key[-1]; char goodModes[-1]; char badModes[-1]; struct schan { char *name; char topic[-1]; char modes[-1]; char key[-1]; int limit; int tsLim; struct criminalRecord { char nick[33]; char *identhost; char longTerm; char shortTerm; int laststamp; int lastJoin; int njoins; struct repeat { int id; int ts; char count; } trackrepeat[30]; struct criminalRecord *prev; struct criminalRecord *next; } *nortyusers; struct sban { char *mask; char *setby; int ts; struct sban *next; struct sban *prev; } *bans; struct suser { char nick[33]; char *ident; char *host; char *mask; char *realname; char isVoice; char isOp; int lastMsg; int flines; int joinTime; int nickchanges; int lastNick; int idleMsg; struct suser *next; struct suser *prev; } *user; int userSize; int banSize; int flood_last; int flood_lines; struct schan *next; struct schan *prev; struct chanRec *record; } *physical; struct softBan { char *banmask; char *reason; char type; char *setby; int expires; struct softBan *next; struct softBan *prev; } *softbans; struct chanRec *next; struct chanRec *prev; } *

variable_types:
mask
char *

return_type: int


isHardBan

decompiled_code:
__int64 __fastcall isHardBan(__int64 a1, const char *a2)
{
__int64 v2; // rbx

if ( !a1 )
return 0LL;
v2 = *(_QWORD *)(a1 + 624);
if ( !v2 )
return 0LL;
while ( strcmp(*(const char **)v2, a2) )
{
v2 = *(_QWORD *)(v2 + 24);
if ( !v2 )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, const char *a2)
{
__int64 v2; // rbx

if ( !a1 )
return 0LL;
v2 = *(_QWORD *)(a1 + 624);
if ( !v2 )
return 0LL;
while ( strcmp(*(const char **)v2, a2) )
{
v2 = *(_QWORD *)(v2 + 24);
if ( !v2 )
return 0LL;
}
return 1LL;
}

original_code:
int isHardBan(struct schan *c, char *mask)
{
 struct sban *i;
 if(!c)
  return 0;
 i = c->bans;
 while(i)
 {
  if(!strcmp(i->mask, mask))
   return 1;
  i = i->next;
 }
 return 0;
}

variable_types: struct sban { char *mask; char *setby; int ts; struct sban *next; struct sban *prev; } *


expireBans

original_code:
void expireBans()
{
 char targs[513];
 struct chanRec *i;
 struct softBan *b, *d;
 struct sban *h;
 int mc, count, meOp;
 mc = count = 0;
 i = chans.next;
 while(i)
 {
  if(i->physical) {
   meOp = isOp(i->physical, cNick);
   if(!meOp) {
    sprintf(targs, "OP %s %s %s", config.linkname, cNick, i->name);
    send_to_all_links(targs);
   }
  } else {
   meOp = 0;
  }
  mc = 0;
  targs[0] = '\0';
  if(meOp && !check_dependants(i->physical))
  {
   h = i->physical->bans;
   while(h)
   {
    if(!isSoftBan(i, h->mask)) {
     if( !strcmp(h->setby, cNick) || (
      (config.cleanbanlist > 0) &&
      (h->ts < time(0) - (config.cleanbanlist*3600)) &&
      (h->ts > 0) )
       )
     {
      strcat(targs, " "); strcat(targs, h->mask);
      if(++mc >= config.maxmodes)
      {
       unsetBans(i->physical, mc, targs);
       mc = 0;
       targs[0] = '\0';
      }
     }
    }
    h = h->next;
   }
   if(strchr(i->flags, 'I'))
    check_idle_ops(i);
  }
  b = i->softbans;
  while(b)
  {
   d = b->next;
   if( (b->expires < time(((void *)0))) )
   {
    count++;
    if( (b->type != 'r') && main_irc && isHardBan(i->physical, b->banmask) )
    {
     strcat(targs, " "); strcat(targs, b->banmask);
     if(++mc >= config.maxmodes)
     {
      unsetBans(i->physical, mc, targs);
      mc = 0;
      targs[0] = '\0';
     }
    }
    br_del(i, b->banmask);
   }
   b = d;
  }
  if(mc > 0)
  {
   unsetBans(i->physical, mc, targs);
  }
  i = i->next;
 }
 if(count > 0)
  save_chans("chans.txt");
 return;
}

canonical_original_code:
void expireBans()
{
 char targs[513];
 struct chanRec *i;
 struct softBan *b; struct softBan *d;
 struct sban *h;
 int mc; int count; int meOp;
 mc = count = 0;
 i = chans.next;
 while(i)
 {
  if(i->physical) {
   meOp = isOp(i->physical, cNick);
   if(!meOp) {
    sprintf(targs, "OP %s %s %s", config.linkname, cNick, i->name);
    send_to_all_links(targs);
   }
  } else {
   meOp = 0;
  }
  mc = 0;
  targs[0] = '\0';
  if(meOp && !check_dependants(i->physical))
  {
   h = i->physical->bans;
   while(h)
   {
    if(!isSoftBan(i, h->mask)) {
     if( !strcmp(h->setby, cNick) || (
      (config.cleanbanlist > 0) &&
      (h->ts < time(0) - (config.cleanbanlist*3600)) &&
      (h->ts > 0) )
       )
     {
      strcat(targs, " "); strcat(targs, h->mask);
      if(++mc >= config.maxmodes)
      {
       unsetBans(i->physical, mc, targs);
       mc = 0;
       targs[0] = '\0';
      }
     }
    }
    h = h->next;
   }
   if(strchr(i->flags, 'I'))
    check_idle_ops(i);
  }
  b = i->softbans;
  while(b)
  {
   d = b->next;
   if( (b->expires < time(((void *)0))) )
   {
    count++;
    if( (b->type != 'r') && main_irc && isHardBan(i->physical, b->banmask) )
    {
     strcat(targs, " "); strcat(targs, b->banmask);
     if(++mc >= config.maxmodes)
     {
      unsetBans(i->physical, mc, targs);
      mc = 0;
      targs[0] = '\0';
     }
    }
    br_del(i, b->banmask);
   }
   b = d;
  }
  if(mc > 0)
  {
   unsetBans(i->physical, mc, targs);
  }
  i = i->next;
 }
 if(count > 0)
  save_chans("chans.txt");
 return;
}

variable_types:
targs
char [513]

variable_types: struct softBan { char *banmask; char *reason; char type; char *setby; int expires; struct softBan *next; struct softBan *prev; } *

variable_types: mc int

variable_types: meOp int


massMode

decompiled_code:
void __fastcall massMode(const char **a1, char a2, char a3, int a4, const char *a5)
{
char *v8; // rdi
__int64 v9; // rax
__int64 v10; // rax

if ( a1 && a4 > 0 )
{
sprintf(taskbuf, "MODE %s %c", *a1, (unsigned int)a2);
v8 = &taskbuf[strlen(taskbuf)];
v9 = 0LL;
do
v8[v9++] = a3;
while ( a4 > (int)v9 );
v10 = (unsigned int)a4;
if ( a4 <= 0 )
v10 = 1LL;
strcpy(&v8[v10], a5);
quickMsg(taskbuf);
}
}

canonical_decompiled_code:
void __fastcall func0(const char **a1, char a2, char a3, int a4, const char *a5)
{
char *v8; // rdi
__int64 v9; // rax
__int64 v10; // rax

if ( a1 && a4 > 0 )
{
sprintf(taskbuf, "MODE %s %c", *a1, (unsigned int)a2);
v8 = &taskbuf[strlen(taskbuf)];
v9 = 0LL;
do
v8[v9++] = a3;
while ( a4 > (int)v9 );
v10 = (unsigned int)a4;
if ( a4 <= 0 )
v10 = 1LL;
strcpy(&v8[v10], a5);
quickMsg(taskbuf);
}
}

original_code:
void massMode(struct schan *chan, char sign, char mode, int count, char *arguments)
{
 char *pch;
 int i;
 if(!chan || (count < 1))
  return;
 sprintf(taskbuf, "MODE %s %c", chan->name, sign);
 pch = taskbuf + strlen(taskbuf);
 for(i = 0; i < count; i++)
  *pch++ = mode;
 strcpy(pch, arguments);
 quickMsg(taskbuf);
 return;
}

variable_types: sign char

variable_types: mode char

variable_types:
arguments
char *

variable_types:
pch
char *

variable_types: i int


decompiled_code:
int __fastcall check_idle_ops(__int64 a1)
{
time_t v1; // rax
__int64 v2; // rbx

v1 = *(_QWORD *)(a1 + 176);
if ( v1 )
{
v2 = *(_QWORD *)(v1 + 632);
if ( v2 )
{
while ( 1 )
{
if ( *(_BYTE *)(v2 + 73) || *(_BYTE *)(v2 + 72) && config[294] == 1 )
{
v1 = time(0LL) - *(int *)(v2 + 96);
if ( v1 > config[293] )
{
LODWORD(v1) = strcmp(&cNick, (const char *)v2);
if ( (_DWORD)v1 )
break;
}
}
v2 = *(_QWORD *)(v2 + 104);
if ( !v2 )
return v1;
}
sprintf(taskbuf, "WHOIS %s %s", (const char *)v2, (const char *)v2);
LODWORD(v1) = lowMsg(taskbuf);
}
}
return v1;
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1)
{
time_t v1; // rax
__int64 v2; // rbx

v1 = *(_QWORD *)(a1 + 176);
if ( v1 )
{
v2 = *(_QWORD *)(v1 + 632);
if ( v2 )
{
while ( 1 )
{
if ( *(_BYTE *)(v2 + 73) || *(_BYTE *)(v2 + 72) && config[294] == 1 )
{
v1 = time(0LL) - *(int *)(v2 + 96);
if ( v1 > config[293] )
{
LODWORD(v1) = strcmp(&cNick, (const char *)v2);
if ( (_DWORD)v1 )
break;
}
}
v2 = *(_QWORD *)(v2 + 104);
if ( !v2 )
return v1;
}
sprintf(taskbuf, "WHOIS %s %s", (const char *)v2, (const char *)v2);
LODWORD(v1) = lowMsg(taskbuf);
}
}
return v1;
}

original_code:
void check_idle_ops(struct chanRec *theChan)
{
 struct suser *i;
 if(!theChan->physical)
  return;
 i = theChan->physical->user;
 while(i)
 {
  if( (i->isOp || (i->isVoice && config.idlevoice == 1)) &&
   (time(0) - i->idleMsg > config.idle_limit) &&
   strcmp(cNick, i->nick) )
  {
   sprintf(taskbuf, "WHOIS %s %s", i->nick, i->nick);
   lowMsg(taskbuf);
   return;
  }
  i = i->next;
 }
}


decompiled_code:
__int64 __fastcall count_clones(__int64 a1, const char *a2)
{
__int64 v2; // rbx
unsigned int v3; // ebp

v2 = *(_QWORD *)(a1 + 632);
if ( !v2 )
return 0;
v3 = 0;
do
{
v3 += strcmp(a2, *(const char **)(v2 + 48)) == 0;
v2 = *(_QWORD *)(v2 + 104);
}
while ( v2 );
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, const char *a2)
{
__int64 v2; // rbx
unsigned int v3; // ebp

v2 = *(_QWORD *)(a1 + 632);
if ( !v2 )
return 0;
v3 = 0;
do
{
v3 += strcmp(a2, *(const char **)(v2 + 48)) == 0;
v2 = *(_QWORD *)(v2 + 104);
}
while ( v2 );
return v3;
}

original_code:
int count_clones(struct schan *theChan, char *host)
{
 struct suser *i;
 int count = 0;
 i = theChan->user;
 while(i)
 {
  if(!strcmp(host, i->host))
   count++;
  i = i->next;
 }
 return count;
}

variable_types:
host
char *


decompiled_code:
__int64 __fastcall enforce_ban(const char **a1, const char *a2, const char *a3, const char *a4, int a5)
{
size_t v6; // rax
void *v7; // r12
const __int32_t **v8; // r13
size_t v9; // rbx
const char *v10; // rbp
size_t v11; // r12
char *v12; // rbx
_BYTE *v13; // r12
size_t i; // rbx
const char *v15; // r15
_BYTE *v16; // r15
size_t j; // rbx
const char *v18; // r12
const char **v19; // rbx
int v20; // eax
const char *v21; // rsi
const char *v22; // r9
void *ptr; // [rsp+8h] [rbp-280h]
char *v24; // [rsp+10h] [rbp-278h]
int v27; // [rsp+30h] [rbp-258h]
char s[584]; // [rsp+40h] [rbp-248h] BYREF

v27 = check_dependants();
if ( v27 )
{
v27 = 0;
}
else
{
v24 = (char *)myalloc(8LL * config[256]);
v6 = strlen(a2);
v7 = (void *)myalloc(v6 + 1);
ptr = v7;
v8 = _ctype_tolower_loc();
v9 = 0LL;
do
{
*((_BYTE *)v7 + v9) = (*v8)[a2[v9]];
++v9;
}
while ( strlen(a2) >= v9 );
v10 = a1[79];
if ( v10 )
{
do
{
if ( !strcmp(v10, &cNick) )
{
if ( !v10[73] )
{
free(ptr);
free(v24);
return (unsigned int)-1;
}
v11 = 0LL;
}
else
{
v11 = 0LL;
}
while ( 1 )
{
v12 = &s[v11];
if ( strlen(v10) <= v11 )
break;
s[v11] = (*v8)[v10[v11]];
++v11;
}
v13 = v12 + 1;
*v12 = 33;
for ( i = 0LL; ; ++i )
{
v15 = (const char *)*((_QWORD *)v10 + 5);
if ( strlen(v15) <= i )
break;
*v13++ = (*v8)[v15[i]];
}
v16 = v13 + 1;
*v13 = 64;
for ( j = 0LL; ; ++j )
{
v18 = (const char *)*((_QWORD *)v10 + 6);
if ( strlen(v18) <= j )
break;
*v16++ = (*v8)[v18[j]];
}
*v16 = 0;
if ( (unsigned int)wildcmp(ptr, s) )
{
if ( !strcmp(v10, &cNick) )
{
free(ptr);
sprintf(s, "MODE %s -b %s", *a1, a2);
quickMsg(s);
free(v24);
return (unsigned int)-2;
}
*(_QWORD *)&v24[8 * v27++] = v10;
if ( v27 >= config[256] )
break;
}
v10 = (const char *)*((_QWORD *)v10 + 13);
}
while ( v10 );
free(ptr);
if ( v27 > 0 )
{
v19 = (const char **)v24;
do
{
v22 = "+]";
if ( v27 != config[256] )
v22 = "]";
sprintf(s, "KICK %s %s :[%d%s %s (%s)", *a1, *v19, (unsigned int)v27, v22, a3, a4);
if ( a5 > time(0LL) )
{
strcat(s, " Duration: ");
v20 = time(0LL);
v21 = (const char *)small_duration((unsigned int)(a5 - v20));
strcat(s, v21);
}
if ( a5 == -1 )
highMsg(s);
else
quickMsg(s);
++v19;
}
while ( v19 != (const char **)&v24[8 * (v27 - 1) + 8] );
}
}
else
{
free(v7);
}
free(v24);
}
return (unsigned int)v27;
}

canonical_decompiled_code:
__int64 __fastcall func3(const char **a1, const char *a2, const char *a3, const char *a4, int a5)
{
size_t v6; // rax
void *v7; // r12
const __int32_t **v8; // r13
size_t v9; // rbx
const char *v10; // rbp
size_t v11; // r12
char *v12; // rbx
_BYTE *v13; // r12
size_t i; // rbx
const char *v15; // r15
_BYTE *v16; // r15
size_t j; // rbx
const char *v18; // r12
const char **v19; // rbx
int v20; // eax
const char *v21; // rsi
const char *v22; // r9
void *ptr; // [rsp+8h] [rbp-280h]
char *v24; // [rsp+10h] [rbp-278h]
int v27; // [rsp+30h] [rbp-258h]
char s[584]; // [rsp+40h] [rbp-248h] BYREF

v27 = check_dependants();
if ( v27 )
{
v27 = 0;
}
else
{
v24 = (char *)myalloc(8LL * config[256]);
v6 = strlen(a2);
v7 = (void *)myalloc(v6 + 1);
ptr = v7;
v8 = _ctype_tolower_loc();
v9 = 0LL;
do
{
*((_BYTE *)v7 + v9) = (*v8)[a2[v9]];
++v9;
}
while ( strlen(a2) >= v9 );
v10 = a1[79];
if ( v10 )
{
do
{
if ( !strcmp(v10, &cNick) )
{
if ( !v10[73] )
{
free(ptr);
free(v24);
return (unsigned int)-1;
}
v11 = 0LL;
}
else
{
v11 = 0LL;
}
while ( 1 )
{
v12 = &s[v11];
if ( strlen(v10) <= v11 )
break;
s[v11] = (*v8)[v10[v11]];
++v11;
}
v13 = v12 + 1;
*v12 = 33;
for ( i = 0LL; ; ++i )
{
v15 = (const char *)*((_QWORD *)v10 + 5);
if ( strlen(v15) <= i )
break;
*v13++ = (*v8)[v15[i]];
}
v16 = v13 + 1;
*v13 = 64;
for ( j = 0LL; ; ++j )
{
v18 = (const char *)*((_QWORD *)v10 + 6);
if ( strlen(v18) <= j )
break;
*v16++ = (*v8)[v18[j]];
}
*v16 = 0;
if ( (unsigned int)wildcmp(ptr, s) )
{
if ( !strcmp(v10, &cNick) )
{
free(ptr);
sprintf(s, "MODE %s -b %s", *a1, a2);
quickMsg(s);
free(v24);
return (unsigned int)-2;
}
*(_QWORD *)&v24[8 * v27++] = v10;
if ( v27 >= config[256] )
break;
}
v10 = (const char *)*((_QWORD *)v10 + 13);
}
while ( v10 );
free(ptr);
if ( v27 > 0 )
{
v19 = (const char **)v24;
do
{
v22 = "+]";
if ( v27 != config[256] )
v22 = "]";
sprintf(s, "KICK %s %s :[%d%s %s (%s)", *a1, *v19, (unsigned int)v27, v22, a3, a4);
if ( a5 > time(0LL) )
{
strcat(s, " Duration: ");
v20 = time(0LL);
v21 = (const char *)small_duration((unsigned int)(a5 - v20));
strcat(s, v21);
}
if ( a5 == -1 )
highMsg(s);
else
quickMsg(s);
++v19;
}
while ( v19 != (const char **)&v24[8 * (v27 - 1) + 8] );
}
}
else
{
free(v7);
}
free(v24);
}
return (unsigned int)v27;
}

original_code:
int enforce_ban(struct schan *theChan, char *mask, char *reason, char *setby, int expire)
{
 struct suser *i;
 struct suser **kicklist;
 char *wild, lmask[513], *pch;
 int iter, count = 0;
 if(check_dependants(theChan))
  return 0;
 kicklist = (struct suser **)myalloc(config.maxkicks * sizeof(struct suser*));
 wild = (char*)myalloc(strlen(mask)+1);
 for(iter = 0; iter <= strlen(mask); iter++)
  wild[iter] = tolower(mask[iter]);
 i = theChan->user;
 while(i)
 {
  if(!strcmp(i->nick, cNick))
  {
   if(!i->isOp)
   {
    free(wild);
    free(kicklist);
    return -1;
   }
  }
  pch = lmask;
  for(iter = 0; iter < strlen(i->nick); iter++)
   *pch++ = tolower((i->nick)[iter]);
  *pch++ = '!';
  for(iter = 0; iter < strlen(i->ident); iter++)
   *pch++ = tolower((i->ident)[iter]);
  *pch++ = '@';
  for(iter = 0; iter < strlen(i->host); iter++)
   *pch++ = tolower((i->host)[iter]);
  *pch++ = '\0';
  if(wildcmp(wild, lmask))
  {
   if(!strcmp(i->nick, cNick))
   {
    free(wild);
    sprintf(lmask, "MODE %s -b %s", theChan->name, mask);
    quickMsg(lmask);
    free(kicklist);
    return -2;
   }
   kicklist[count] = i;
   if(++count >= config.maxkicks)
    break;
  }
  i = i->next;
 }
 free(wild);
 for(iter = 0; iter < count; iter++)
 {
  sprintf(lmask, "KICK %s %s :[%d%s %s (%s)",
   theChan->name, (kicklist[iter])->nick, count, (count == config.maxkicks) ? "+]" : "]", reason, setby);
  if(expire > time(((void *)0))) {
   strcat(lmask, " Duration: ");
   strcat(lmask, small_duration(expire - time(((void *)0))) );
  }
  if(expire == -1)
   highMsg(lmask);
  else
   quickMsg(lmask);
 }
 free(kicklist);
 return count;
}

canonical_original_code:
int enforce_ban(struct schan *theChan, char *mask, char *reason, char *setby, int expire)
{
 struct suser *i;
 struct suser **kicklist;
 char *wild; char lmask[513]; char *pch;
 int iter; int count = 0;
 if(check_dependants(theChan))
  return 0;
 kicklist = (struct suser **)myalloc(config.maxkicks * sizeof(struct suser *));
 wild = (char *)myalloc(strlen(mask)+1);
 for(iter = 0; iter <= strlen(mask); iter++)
  wild[iter] = tolower(mask[iter]);
 i = theChan->user;
 while(i)
 {
  if(!strcmp(i->nick, cNick))
  {
   if(!i->isOp)
   {
    free(wild);
    free(kicklist);
    return -1;
   }
  }
  pch = lmask;
  for(iter = 0; iter < strlen(i->nick); iter++)
   *pch++ = tolower((i->nick)[iter]);
  *pch++ = '!';
  for(iter = 0; iter < strlen(i->ident); iter++)
   *pch++ = tolower((i->ident)[iter]);
  *pch++ = '@';
  for(iter = 0; iter < strlen(i->host); iter++)
   *pch++ = tolower((i->host)[iter]);
  *pch++ = '\0';
  if(wildcmp(wild, lmask))
  {
   if(!strcmp(i->nick, cNick))
   {
    free(wild);
    sprintf(lmask, "MODE %s -b %s", theChan->name, mask);
    quickMsg(lmask);
    free(kicklist);
    return -2;
   }
   kicklist[count] = i;
   if(++count >= config.maxkicks)
    break;
  }
  i = i->next;
 }
 free(wild);
 for(iter = 0; iter < count; iter++)
 {
  sprintf(lmask, "KICK %s %s :[%d%s %s (%s)",
   theChan->name, (kicklist[iter])->nick, count, (count == config.maxkicks) ? "+]" : "]", reason, setby);
  if(expire > time(((void *)0))) {
   strcat(lmask, " Duration: ");
   strcat(lmask, small_duration(expire - time(((void *)0))) );
  }
  if(expire == -1)
   highMsg(lmask);
  else
   quickMsg(lmask);
 }
 free(kicklist);
 return count;
}

variable_types:
reason
char *

variable_types:
setby
char *

variable_types: expire int

variable_types: struct suser { char nick[33]; char *ident; char *host; char *mask; char *realname; char isVoice; char isOp; int lastMsg; int flines; int joinTime; int nickchanges; int lastNick; int idleMsg; struct suser *next; struct suser *prev; } **

variable_types:
wild
char *

variable_types:
lmask
char [513]

variable_types: iter int

variable_types: count int


isOp

decompiled_code:
_BOOL8 __fastcall isOp(__int64 a1, const char *a2)
{
__int64 v2; // rbx

v2 = *(_QWORD *)(a1 + 632);
if ( !v2 )
return 0LL;
while ( strcmp((const char *)v2, a2) )
{
v2 = *(_QWORD *)(v2 + 104);
if ( !v2 )
return 0LL;
}
return *(_BYTE *)(v2 + 73) != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(__int64 a1, const char *a2)
{
__int64 v2; // rbx

v2 = *(_QWORD *)(a1 + 632);
if ( !v2 )
return 0LL;
while ( strcmp((const char *)v2, a2) )
{
v2 = *(_QWORD *)(v2 + 104);
if ( !v2 )
return 0LL;
}
return *(_BYTE *)(v2 + 73) != 0;
}

original_code:
int isOp(struct schan *chan, char *nick)
{
 struct suser *i = chan->user;
 while(i)
 {
  if(!strcmp(i->nick, nick))
  {
   if(i->isOp)
    return 1;
   else
    return 0;
  }
  i = i->next;
 }
 return 0;
}

variable_types: struct schan { char *name; char topic[-1]; char modes[-1]; char key[-1]; int limit; int tsLim; struct criminalRecord { char nick[33]; char *identhost; char longTerm; char shortTerm; int laststamp; int lastJoin; int njoins; struct repeat { int id; int ts; char count; } trackrepeat[30]; struct criminalRecord *prev; struct criminalRecord *next; } *nortyusers; struct sban { char *mask; char *setby; int ts; struct sban *next; struct sban *prev; } *bans; struct suser { char nick[33]; char *ident; char *host; char *mask; char *realname; char isVoice; char isOp; int lastMsg; int flines; int joinTime; int nickchanges; int lastNick; int idleMsg; struct suser *next; struct suser *prev; } *user; int userSize; int banSize; int flood_last; int flood_lines; struct schan *next; struct schan *prev; struct chanRec { char *name; char flags[-1]; char key[-1]; char goodModes[-1]; char badModes[-1]; struct schan *physical; struct softBan { char *banmask; char *reason; char type; char *setby; int expires; struct softBan *next; struct softBan *prev; } *softbans; struct chanRec *next; struct chanRec *prev; } *record; } *

variable_types:
nick
char *


massDeop

decompiled_code:
void __fastcall massDeop(const char **a1, int a2, const char *a3)
{
int i; // ebx

if ( a1 && a2 > 0 )
{
sprintf(taskbuf, "MODE %s -", *a1);
for ( i = 0; i < a2; ++i )
*(_WORD *)&taskbuf[strlen(taskbuf)] = 111;
strcat(taskbuf, a3);
quickMsg(taskbuf);
}
}

canonical_decompiled_code:
void __fastcall func5(const char **a1, int a2, const char *a3)
{
int i; // ebx

if ( a1 && a2 > 0 )
{
sprintf(taskbuf, "MODE %s -", *a1);
for ( i = 0; i < a2; ++i )
*(_WORD *)&taskbuf[strlen(taskbuf)] = 111;
strcat(taskbuf, a3);
quickMsg(taskbuf);
}
}

original_code:
void massDeop(struct schan *chan, int count, char *args)
{
 int i;
 if(!chan || (count < 1))
  return;
 sprintf(taskbuf, "MODE %s -", chan->name);
 for(i = 0; i < count; i++)
  strcat(taskbuf, "o");
 strcat(taskbuf, args);
 quickMsg(taskbuf);
 return;
}

variable_types:
args
char *


unsetBans

decompiled_code:
void __fastcall unsetBans(const char **a1, int a2, const char *a3)
{
int i; // ebx

if ( a1 && a2 > 0 && isOp((__int64)a1, &cNick) )
{
sprintf(taskbuf, "MODE %s -", *a1);
for ( i = 0; i < a2; ++i )
*(_WORD *)&taskbuf[strlen(taskbuf)] = 98;
strcat(taskbuf, a3);
quickMsg(taskbuf);
}
}

canonical_decompiled_code:
void __fastcall func6(const char **a1, int a2, const char *a3)
{
int i; // ebx

if ( a1 && a2 > 0 && func4((__int64)a1, &cNick) )
{
sprintf(taskbuf, "MODE %s -", *a1);
for ( i = 0; i < a2; ++i )
*(_WORD *)&taskbuf[strlen(taskbuf)] = 98;
strcat(taskbuf, a3);
quickMsg(taskbuf);
}
}

original_code:
void unsetBans(struct schan *chan, int count, char *args)
{
 int i;
 if(!chan || (count < 1))
  return;
 if(!isOp(chan, cNick))
  return;
 sprintf(taskbuf, "MODE %s -", chan->name);
 for(i = 0; i < count; i++)
  strcat(taskbuf, "b");
 strcat(taskbuf, args);
 quickMsg(taskbuf);
 return;
}


sendQUIT

decompiled_code:
__int64 __fastcall sendQUIT(__int64 a1)
{
int v1; // eax
__int64 v2; // rax

v1 = time(0LL);
v2 = fixed_duration((unsigned int)(v1 - tStart));
sprintf(taskbuf, aQuit, "0.93", v2, a1);
return irc_write(taskbuf);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
int v1; // eax
__int64 v2; // rax

v1 = time(0LL);
v2 = fixed_duration((unsigned int)(v1 - tStart));
sprintf(taskbuf, aQuit, "0.93", v2, a1);
return irc_write(taskbuf);
}

original_code:
void sendQUIT(char *extra)
{
 sprintf(taskbuf, "QUIT :\037/\002Fireclaw\002.%s/\037Running %s ~ %s", "0.93", fixed_duration(time(0) - tStart), extra);
 irc_write(taskbuf);
 return;
}

variable_types:
extra
char *


checkBadHost

decompiled_code:
__int64 __fastcall checkBadHost(__int64 a1, __int64 a2)
{
__int64 v2; // r12
__int64 result; // rax
__int64 v4; // rax

v2 = a2 + 322;
set_lower_message(v2, v2);
if ( (unsigned int)regmatch(&swear_norm, a2 + 322) || (result = regmatch(&swear_mild, v2), (_DWORD)result) )
{
v4 = findUser(a1, a2);
result = punish_user(*(_QWORD *)(a1 + 672), v4, 109LL, 0LL, 0LL);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2)
{
__int64 v2; // r12
__int64 result; // rax
__int64 v4; // rax

v2 = a2 + 322;
set_lower_message(v2, v2);
if ( (unsigned int)regmatch(&swear_norm, a2 + 322) || (result = regmatch(&swear_mild, v2), (_DWORD)result) )
{
v4 = findUser(a1, a2);
result = punish_user(*(_QWORD *)(a1 + 672), v4, 109LL, 0LL, 0LL);
}
return result;
}

original_code:
void checkBadHost(struct schan *theChan, sUser *theUser)
{
 set_lower_message(theUser->mask, theUser->mask);
 if(regmatch(&swear_norm, theUser->mask) || regmatch(&swear_mild, theUser->mask))
  punish_user(theChan->record, findUser(theChan, theUser->nick), 'm', 0, 0);
 return;
}

canonical_original_code:
void checkBadHost(struct schan *theChan, struct ircUser *theUser)
{
 set_lower_message(theUser->mask, theUser->mask);
 if(regmatch(&swear_norm, theUser->mask) || regmatch(&swear_mild, theUser->mask))
  punish_user(theChan->record, findUser(theChan, theUser->nick), 'm', 0, 0);
 return;
}

variable_types: struct ircUser { char nick[33]; char ident[33]; char host[256]; char mask[512]; char gnuUser[32]; } *


checkLamehost

decompiled_code:
int __fastcall checkLamehost(__int64 a1, __int64 a2)
{
const char *v2; // rbp
int result; // eax
int v4; // er13
int v5; // er12
int v6; // er14
char *v7; // rbx
unsigned __int64 v8; // rdx
unsigned __int64 v9; // rax
int v10; // er12
__int64 v11; // rbx
__int64 v12; // rax
__int64 v13; // [rsp+0h] [rbp-68h]
__int64 v14; // [rsp+8h] [rbp-60h]
char s[88]; // [rsp+10h] [rbp-58h] BYREF

v13 = a1;
v14 = a2;
v2 = (const char *)(a2 + 66);
result = *(unsigned __int8 *)(a2 + 66 + (int)strlen((const char *)(a2 + 66)) - 1) - 48;
if ( (unsigned __int8)result > 9u )
{
result = regmatch(&safehosts, a2 + 66);
v4 = result;
if ( !result )
{
v5 = regmatch(&swear_norm, a2 + 322);
v6 = v5;
if ( v5 )
{
v6 = 1;
v5 = 30;
}
v7 = strchr(v2, 46);
if ( v7 )
{
while ( 1 )
{
while ( 1 )
{
++v4;
v9 = v7 - v2;
if ( v7 - v2 <= 30 )
break;
v5 += v9;
++v6;
s[0] = 0;
v2 = v7 + 1;
v7 = strchr(v7 + 1, 46);
if ( !v7 )
goto LABEL_27;
}
if ( v9 >= 8 )
{
*(__int64 *)((char *)&v14 + v9) = *((_QWORD *)v7 - 1);
if ( v9 - 1 >= 8 )
{
v8 = 0LL;
do
{
*(_QWORD *)&s[v8] = *(_QWORD *)&v2[v8];
v8 += 8LL;
}
while ( v8 < ((v9 - 1) & 0xFFFFFFFFFFFFFFF8LL) );
}
}
else if ( (v9 & 4) != 0 )
{
*(_DWORD *)s = *(_DWORD *)v2;
*(_DWORD *)&s[v9 - 4] = *((_DWORD *)v7 - 1);
}
else if ( v9 )
{
s[0] = *v2;
if ( (v9 & 2) != 0 )
*(_WORD *)&s[v9 - 2] = *((_WORD *)v7 - 1);
}
s[v9] = 0;
v2 = v7 + 1;
v7 = strchr(v7 + 1, 46);
if ( !v7 )
break;
if ( s[0] )
{
if ( (unsigned int)regmatch(&lamehost_5, s) )
{
v5 += 5;
++v6;
}
if ( (unsigned int)regmatch(&lamehost_10, s) )
{
v5 += 10;
++v6;
}
if ( (unsigned int)regmatch(&lamehost_15, s) )
{
v5 += 15;
++v6;
}
}
}
LABEL_27:
if ( v4 > 4 )
v5 += 10;
v10 = v6 * v5;
result = sprintf(s, "%d spampoints", (unsigned int)v10);
if ( v10 > 50 )
{
v11 = v13;
v12 = findUser(v13, v14);
result = punish_user(*(_QWORD *)(v11 + 672), v12, 104LL, 0LL, s);
}
}
else
{
result = sprintf(s, "%d spampoints", (unsigned int)(v6 * v5));
}
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func9(__int64 a1, __int64 a2)
{
const char *v2; // rbp
int result; // eax
int v4; // er13
int v5; // er12
int v6; // er14
char *v7; // rbx
unsigned __int64 v8; // rdx
unsigned __int64 v9; // rax
int v10; // er12
__int64 v11; // rbx
__int64 v12; // rax
__int64 v13; // [rsp+0h] [rbp-68h]
__int64 v14; // [rsp+8h] [rbp-60h]
char s[88]; // [rsp+10h] [rbp-58h] BYREF

v13 = a1;
v14 = a2;
v2 = (const char *)(a2 + 66);
result = *(unsigned __int8 *)(a2 + 66 + (int)strlen((const char *)(a2 + 66)) - 1) - 48;
if ( (unsigned __int8)result > 9u )
{
result = regmatch(&safehosts, a2 + 66);
v4 = result;
if ( !result )
{
v5 = regmatch(&swear_norm, a2 + 322);
v6 = v5;
if ( v5 )
{
v6 = 1;
v5 = 30;
}
v7 = strchr(v2, 46);
if ( v7 )
{
while ( 1 )
{
while ( 1 )
{
++v4;
v9 = v7 - v2;
if ( v7 - v2 <= 30 )
break;
v5 += v9;
++v6;
s[0] = 0;
v2 = v7 + 1;
v7 = strchr(v7 + 1, 46);
if ( !v7 )
goto LABEL_27;
}
if ( v9 >= 8 )
{
*(__int64 *)((char *)&v14 + v9) = *((_QWORD *)v7 - 1);
if ( v9 - 1 >= 8 )
{
v8 = 0LL;
do
{
*(_QWORD *)&s[v8] = *(_QWORD *)&v2[v8];
v8 += 8LL;
}
while ( v8 < ((v9 - 1) & 0xFFFFFFFFFFFFFFF8LL) );
}
}
else if ( (v9 & 4) != 0 )
{
*(_DWORD *)s = *(_DWORD *)v2;
*(_DWORD *)&s[v9 - 4] = *((_DWORD *)v7 - 1);
}
else if ( v9 )
{
s[0] = *v2;
if ( (v9 & 2) != 0 )
*(_WORD *)&s[v9 - 2] = *((_WORD *)v7 - 1);
}
s[v9] = 0;
v2 = v7 + 1;
v7 = strchr(v7 + 1, 46);
if ( !v7 )
break;
if ( s[0] )
{
if ( (unsigned int)regmatch(&lamehost_5, s) )
{
v5 += 5;
++v6;
}
if ( (unsigned int)regmatch(&lamehost_10, s) )
{
v5 += 10;
++v6;
}
if ( (unsigned int)regmatch(&lamehost_15, s) )
{
v5 += 15;
++v6;
}
}
}
LABEL_27:
if ( v4 > 4 )
v5 += 10;
v10 = v6 * v5;
result = sprintf(s, "%d spampoints", (unsigned int)v10);
if ( v10 > 50 )
{
v11 = v13;
v12 = findUser(v13, v14);
result = punish_user(*(_QWORD *)(v11 + 672), v12, 104LL, 0LL, s);
}
}
else
{
result = sprintf(s, "%d spampoints", (unsigned int)(v6 * v5));
}
}
}
return result;
}

original_code:
void checkLamehost(struct schan *theChan, sUser *theUser)
{
 char field[32];
 int points, len, fields, badfields;
 char *pch, *anchor;
 len = strlen(theUser->host);
 points = fields = badfields = 0;
 anchor = theUser->host;
 if(anchor[len-1] >= '0' && anchor[len-1] <= '9')
  return;
 if(regmatch(&safehosts, anchor))
  return;
 if(regmatch(&swear_norm, theUser->mask)) {
  points += 30;
  badfields++;
 }
 pch = strchr(anchor, '.');
 while(pch)
 {
  fields++;
  if(pch-anchor >= 31) {
   points += (int)(pch-anchor);
   badfields++;
   field[0] = '\0';
  } else {
   memcpy(field, anchor, pch-anchor);
   field[pch-anchor] = '\0';
  }
  anchor = ++pch;
  pch = strchr(anchor, '.');
  if(pch && field[0]) {
   if(regmatch(&lamehost_5, field)) {
    points += 5;
    badfields++;
   }
   if(regmatch(&lamehost_10, field)) {
    points += 10;
    badfields++;
   }
   if(regmatch(&lamehost_15, field)) {
    points += 15;
    badfields++;
   }
  }
 }
 if(fields > 4)
  points += 10;
 points *= badfields;
 sprintf(field, "%d spampoints", points);
 if(points > 50)
  punish_user(theChan->record, findUser(theChan, theUser->nick), 'h', 0, field);
 return;
}

canonical_original_code:
void checkLamehost(struct schan *theChan, struct ircUser *theUser)
{
 char field[32];
 int points; int len; int fields; int badfields;
 char *pch; char *anchor;
 len = strlen(theUser->host);
 points = fields = badfields = 0;
 anchor = theUser->host;
 if(anchor[len-1] >= '0' && anchor[len-1] <= '9')
  return;
 if(regmatch(&safehosts, anchor))
  return;
 if(regmatch(&swear_norm, theUser->mask)) {
  points += 30;
  badfields++;
 }
 pch = strchr(anchor, '.');
 while(pch)
 {
  fields++;
  if(pch-anchor >= 31) {
   points += (int)(pch-anchor);
   badfields++;
   field[0] = '\0';
  } else {
   memcpy(field, anchor, pch-anchor);
   field[pch-anchor] = '\0';
  }
  anchor = ++pch;
  pch = strchr(anchor, '.');
  if(pch && field[0]) {
   if(regmatch(&lamehost_5, field)) {
    points += 5;
    badfields++;
   }
   if(regmatch(&lamehost_10, field)) {
    points += 10;
    badfields++;
   }
   if(regmatch(&lamehost_15, field)) {
    points += 15;
    badfields++;
   }
  }
 }
 if(fields > 4)
  points += 10;
 points *= badfields;
 sprintf(field, "%d spampoints", points);
 if(points > 50)
  punish_user(theChan->record, findUser(theChan, theUser->nick), 'h', 0, field);
 return;
}

variable_types:
field
char [32]

variable_types: points int

variable_types: len int

variable_types: fields int

variable_types: badfields int

variable_types:
anchor
char *

user_defined_types: struct ircUser { char nick[33]; char ident[33]; char host[256]; char mask[512]; char gnuUser[32]; }


decompiled_code:
__int64 service_auth()
{
snprintf(
sendbuf,
0x1FEuLL,
"PRIVMSG %s :%s",
(const char *)(unsigned int)((_DWORD)config + 197),
(const char *)(unsigned int)((_DWORD)config + 325));
return highMsg(sendbuf);
}

canonical_decompiled_code:
__int64 func1()
{
snprintf(
sendbuf,
0x1FEuLL,
"PRIVMSG %s :%s",
(const char *)(unsigned int)((_DWORD)config + 197),
(const char *)(unsigned int)((_DWORD)config + 325));
return highMsg(sendbuf);
}

original_code:
void service_auth()
{
 snprintf(sendbuf, 510, "PRIVMSG %s :%s", config.servicePrefix, config.serviceAuth);
 highMsg(sendbuf);
 return;
}


decompiled_code:
__int64 __fastcall sRelay_butone(const char *a1, __int64 a2)
{
if ( main_irc && config[133] == 35 )
{
snprintf(sendbuf, 0x1FEuLL, "PRIVMSG %s :%s", (const char *)(unsigned int)((_DWORD)config + 133), a1);
lowMsg(sendbuf);
}
snprintf(sendbuf, 0x1FEuLL, "# %s", a1);
return send_to_dcc_butonesock(sendbuf, a2, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1, __int64 a2)
{
if ( main_irc && config[133] == 35 )
{
snprintf(sendbuf, 0x1FEuLL, "PRIVMSG %s :%s", (const char *)(unsigned int)((_DWORD)config + 133), a1);
lowMsg(sendbuf);
}
snprintf(sendbuf, 0x1FEuLL, "# %s", a1);
return send_to_dcc_butonesock(sendbuf, a2, 0LL);
}

original_code:
void sRelay_butone(char *message, struct socket *tso)
{
 if(main_irc && config.relaychan[0] == '#')
 {
  snprintf(sendbuf, 510, "PRIVMSG %s :%s", config.relaychan, message);
  lowMsg(sendbuf);
 }
 snprintf(sendbuf, 510, "# %s", message);
 send_to_dcc_butonesock(sendbuf, tso, 0);
 return;
}

variable_types:
message
char *

variable_types: struct socket { char type; char status; int id; int fd; int last_ts; int con_ts; char checkLink; char buffer[4096]; struct socket *next; } *


sRelay

decompiled_code:
__int64 __fastcall sRelay(const char *a1)
{
if ( main_irc && config[133] == 35 )
{
snprintf(sendbuf, 0x1FEuLL, "PRIVMSG %s :%s", (const char *)(unsigned int)((_DWORD)config + 133), a1);
lowMsg(sendbuf);
}
snprintf(sendbuf, 0x1FEuLL, "# %s", a1);
return send_to_all_dcc(sendbuf, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func3(const char *a1)
{
if ( main_irc && config[133] == 35 )
{
snprintf(sendbuf, 0x1FEuLL, "PRIVMSG %s :%s", (const char *)(unsigned int)((_DWORD)config + 133), a1);
lowMsg(sendbuf);
}
snprintf(sendbuf, 0x1FEuLL, "# %s", a1);
return send_to_all_dcc(sendbuf, 0LL);
}

original_code:
void sRelay(char *message)
{
 if(main_irc && config.relaychan[0] == '#')
 {
  snprintf(sendbuf, 510, "PRIVMSG %s :%s", config.relaychan, message);
  lowMsg(sendbuf);
 }
 snprintf(sendbuf, 510, "# %s", message);
 send_to_all_dcc(sendbuf, 0);
 return;
}


myalloc

decompiled_code:
void *__fastcall myalloc(size_t a1)
{
void *result; // rax
struct mallinfo v2; // [rsp+0h] [rbp-38h] BYREF

result = malloc(a1);
if ( !result )
{
mallinfo(&v2);
fprintf(
out,
"Heap: %d, Used: %d, Spare: %d\n",
(unsigned int)v2.arena,
(unsigned int)v2.uordblks,
(unsigned int)v2.fordblks);
fprintf(out, "*ERROR* Out of memory trying to allocate %d bytes!\n", (unsigned int)a1);
exit(0);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func4(size_t a1)
{
void *result; // rax
struct mallinfo v2; // [rsp+0h] [rbp-38h] BYREF

result = malloc(a1);
if ( !result )
{
mallinfo(&v2);
fprintf(
out,
"Heap: %d, Used: %d, Spare: %d\n",
(unsigned int)v2.arena,
(unsigned int)v2.uordblks,
(unsigned int)v2.fordblks);
fprintf(out, "*ERROR* Out of memory trying to allocate %d bytes!\n", (unsigned int)a1);
exit(0);
}
return result;
}

original_code:
void *myalloc(size_t size)
{
 void *ret = malloc(size);
 if(!ret)
 {
  struct mallinfo mem = mallinfo();
  fprintf(out, "Heap: %d, Used: %d, Spare: %d\n", (int)mem.arena, (int)mem.uordblks, (int)mem.fordblks);
  fprintf(out, "*ERROR* Out of memory trying to allocate %d bytes!\n", (int)size);
  exit(0);
 }
 return ret;
}

canonical_original_code:
void *myalloc(unsigned long size)
{
 void *ret = malloc(size);
 if(!ret)
 {
  struct mallinfo mem = mallinfo();
  fprintf(out, "Heap: %d, Used: %d, Spare: %d\n", (int)mem.arena, (int)mem.uordblks, (int)mem.fordblks);
  fprintf(out, "*ERROR* Out of memory trying to allocate %d bytes!\n", (int)size);
  exit(0);
 }
 return ret;
}

variable_types:
size
unsigned long

variable_types:
ret
void *

variable_types: struct mallinfo { int arena; int ordblks; int smblks; int hblks; int hblkhd; int usmblks; int fsmblks; int uordblks; int fordblks; int keepcost; }

return_type: void *


printmem

decompiled_code:
int printmem()
{
struct mallinfo v1; // [rsp+0h] [rbp-38h] BYREF

mallinfo(&v1);
return fprintf(out, "**********: Heap size: %d bytes.\n", (unsigned int)v1.uordblks);
}

canonical_decompiled_code:
int func5()
{
struct mallinfo v1; // [rsp+0h] [rbp-38h] BYREF

mallinfo(&v1);
return fprintf(out, "**********: Heap size: %d bytes.\n", (unsigned int)v1.uordblks);
}

original_code:
void printmem()
{
 struct mallinfo mem = mallinfo();
 fprintf(out, "**********: Heap size: %d bytes.\n", (int)mem.uordblks);
 return;
}

user_defined_types: struct mallinfo { int arena; int ordblks; int smblks; int hblks; int hblkhd; int usmblks; int fsmblks; int uordblks; int fordblks; int keepcost; }


original_code:
void sort_list(struct tagList *list)
{
 struct tagList buf;
 int changes, iter;
 for(;;)
 {
  changes = 0;
  for(iter = 0; iter < listPos - 1; iter++)
  {
   if(list[iter].count < list[iter+1].count) {
    buf = list[iter];
    list[iter] = list[iter+1];
    list[iter+1] = buf;
    changes++;
   }
  }
  if(changes == 0)
   break;
 }
 return;
}

canonical_original_code:
void sort_list(struct tagList *list)
{
 struct tagList buf;
 int changes; int iter;
 for(;;)
 {
  changes = 0;
  for(iter = 0; iter < listPos - 1; iter++)
  {
   if(list[iter].count < list[iter+1].count) {
    buf = list[iter];
    list[iter] = list[iter+1];
    list[iter+1] = buf;
    changes++;
   }
  }
  if(changes == 0)
   break;
 }
 return;
}

variable_types: struct tagList { char tag[33]; int count; } *

variable_types: changes int

variable_types: iter int


decompiled_code:
__int64 __fastcall match_badurl(char *haystack)
{
_QWORD *v1; // rbx

v1 = badlist;
if ( !badlist )
return 0LL;
while ( !strstr(haystack, (const char *)*v1) )
{
v1 = (_QWORD *)v1[2];
if ( !v1 )
return 0LL;
}
++*((_DWORD *)v1 + 2);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *haystack)
{
_QWORD *v1; // rbx

v1 = badlist;
if ( !badlist )
return 0LL;
while ( !strstr(haystack, (const char *)*v1) )
{
v1 = (_QWORD *)v1[2];
if ( !v1 )
return 0LL;
}
++*((_DWORD *)v1 + 2);
return 1LL;
}

original_code:
int match_badurl(char *text)
{
 struct badUrl *i;
 i = badlist;
 while(i)
 {
  if(strstr(text, i->match)) {
   i->count++;
   return 1;
  }
  i = i->next;
 }
 return 0;
}

variable_types:
text
char *

variable_types: struct badUrl { char *match; int count; struct badUrl *next; } *


decompiled_code:
void init_badurls()
{
badlist = 0LL;
}

canonical_decompiled_code:
void func1()
{
badlist = 0LL;
}

original_code:
void init_badurls()
{
 badlist = ((void *)0);
}


decompiled_code:
void reset_badurls()
{
void **v0; // rbx
void **v1; // rbp

v0 = (void **)badlist;
if ( badlist )
{
do
{
v1 = v0;
v0 = (void **)v0[2];
free(*v1);
free(v1);
}
while ( v0 );
badlist = 0LL;
}
}

canonical_decompiled_code:
void func2()
{
void **v0; // rbx
void **v1; // rbp

v0 = (void **)badlist;
if ( badlist )
{
do
{
v1 = v0;
v0 = (void **)v0[2];
free(*v1);
free(v1);
}
while ( v0 );
badlist = 0LL;
}
}

original_code:
void reset_badurls()
{
 struct badUrl *i, *last;
 if(badlist) {
  i = badlist;
  while(i)
  {
   last = i;
   i = i->next;
   free(last->match);
   free(last);
  }
  badlist = ((void *)0);
 }
 return;
}

canonical_original_code:
void reset_badurls()
{
 struct badUrl *i; struct badUrl *last;
 if(badlist) {
  i = badlist;
  while(i)
  {
   last = i;
   i = i->next;
   free(last->match);
   free(last);
  }
  badlist = ((void *)0);
 }
 return;
}

user_defined_types: struct badUrl { char *match; int count; struct badUrl *next; }


decompiled_code:
int setup_signals()
{
struct sigaction v1; // [rsp+0h] [rbp-A8h] BYREF

sigemptyset(&v1.sa_mask);
v1.sa_flags = 0;
v1.sa_handler = (__sighandler_t)sigint;
sigaction(2, &v1, 0LL);
v1.sa_handler = (__sighandler_t)sighup;
sigaction(1, &v1, 0LL);
v1.sa_handler = (__sighandler_t)(sigint + 1);
sigaction(10, &v1, 0LL);
return sigaction(13, &v1, 0LL);
}

canonical_decompiled_code:
int func2()
{
struct sigaction v1; // [rsp+0h] [rbp-A8h] BYREF

sigemptyset(&v1.sa_mask);
v1.sa_flags = 0;
v1.sa_handler = (__sighandler_t)sigint;
sigaction(2, &v1, 0LL);
v1.sa_handler = (__sighandler_t)sighup;
sigaction(1, &v1, 0LL);
v1.sa_handler = (__sighandler_t)(sigint + 1);
sigaction(10, &v1, 0LL);
return sigaction(13, &v1, 0LL);
}

original_code:
void setup_signals()
{
    struct sigaction sv;
    sigemptyset( &sv.sa_mask );
    sv.sa_flags = 0;
 sv.__sigaction_handler.sa_handler = _sigint;
    sigaction( 2, &sv, ((void *)0) );
    sv.__sigaction_handler.sa_handler = _sighup;
    sigaction( 1, &sv, ((void *)0) );
    sv.__sigaction_handler.sa_handler = ((__sighandler_t) 1);
    sigaction( 10, &sv, ((void *)0) );
    sigaction( 13, &sv, ((void *)0) );
 return;
}

canonical_original_code:
void setup_signals()
{
    struct sigaction sv;
    sigemptyset( &sv.sa_mask );
    sv.sa_flags = 0;
 sv.__sigaction_handler.sa_handler = _sigint;
    sigaction( 2, &sv, ((void *)0) );
    sv.__sigaction_handler.sa_handler = _sighup;
    sigaction( 1, &sv, ((void *)0) );
    sv.__sigaction_handler.sa_handler = ((void (*)(int)) 1);
    sigaction( 10, &sv, ((void *)0) );
    sigaction( 13, &sv, ((void *)0) );
 return;
}

variable_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } *, void *); } __sigaction_handler; struct __sigset_t { unsigned long __val[-1]; } sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t *, void *); } __sigaction_handler; struct __sigset_t sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; }


repo: ircnet/irc

decompiled_code:
void *__fastcall int_to_base64(int a1)
{
char *v1; // rax

v1 = (char *)&buf_6;
do
{
*v1 = saltChars[a1 & 0x3F];
a1 >>= 6;
++v1;
}
while ( v1 != &byte_404156 );
byte_404156 = 0;
return &buf_6;
}

canonical_decompiled_code:
void *__fastcall func7(int a1)
{
char *v1; // rax

v1 = (char *)&buf_6;
do
{
*v1 = saltChars[a1 & 0x3F];
a1 >>= 6;
++v1;
}
while ( v1 != &byte_404156 );
byte_404156 = 0;
return &buf_6;
}

original_code:
char *int_to_base64(int value)
{
  static char buf[5];
  int i;
  for (i = 0; i < 4; i++)
  {
    buf[i] = saltChars[value & 63];
    value >>= 6;
  }
  buf[i] = '\0';
  return buf;
}

variable_types: value int

variable_types:
buf
char [5]

variable_types: i int

return_type: char *


decompiled_code:
char *__fastcall make_ext_salt_para(int a1, const char *a2)
{
const char *v2; // rax

v2 = (const char *)int_to_base64(a1);
sprintf(salt_4, "_%s%s", v2, a2);
return salt_4;
}

canonical_decompiled_code:
char *__fastcall func8(int a1, const char *a2)
{
const char *v2; // rax

v2 = (const char *)func7(a1);
sprintf(salt_4, "_%s%s", v2, a2);
return salt_4;
}

original_code:
char *make_ext_salt_para(int rounds, char *saltpara)
{
  static char salt[10];
  sprintf(salt, "_%s%s", int_to_base64(rounds), saltpara);
  return salt;
}

variable_types: rounds int

variable_types:
saltpara
char *

variable_types:
salt
char [10]


decompiled_code:
char *__fastcall make_md5_salt_para(const char *a1)
{
if ( !a1 || strlen(a1) > 0x10 )
{
puts("Invalid Salt, please use up to 16 random alphanumeric characters");
exit(1);
}
sprintf(salt_3, "$1$%s$", a1);
return salt_3;
}

canonical_decompiled_code:
char *__fastcall func9(const char *a1)
{
if ( !a1 || strlen(a1) > 0x10 )
{
puts("Invalid Salt, please use up to 16 random alphanumeric characters");
exit(1);
}
sprintf(salt_3, "$1$%s$", a1);
return salt_3;
}

original_code:
char *make_md5_salt_para(char *saltpara)
{
  static char salt[21];
  if (saltpara && (strlen(saltpara) <= 16))
  {
    sprintf(salt, "$1$%s$", saltpara);
    return salt;
  }
  printf("Invalid Salt, please use up to 16 random alphanumeric characters\n");
  exit(1);
  return ((void *)0);
}

variable_types:
salt
char [21]


decompiled_code:
char *__fastcall make_bf_salt_para(unsigned int a1, const char *a2)
{
char s[27]; // [rsp+Dh] [rbp-1Bh] BYREF

if ( !a2 || strlen(a2) > 0x16 )
{
puts("Invalid Salt, please use up to 22 random alphanumeric characters");
exit(1);
}
sprintf(s, "%02d", a1);
sprintf(salt_1, "$2a$%s$%s$", s, a2);
return salt_1;
}

canonical_decompiled_code:
char *__fastcall func10(unsigned int a1, const char *a2)
{
char s[27]; // [rsp+Dh] [rbp-1Bh] BYREF

if ( !a2 || strlen(a2) > 0x16 )
{
puts("Invalid Salt, please use up to 22 random alphanumeric characters");
exit(1);
}
sprintf(s, "%02d", a1);
sprintf(salt_1, "$2a$%s$%s$", s, a2);
return salt_1;
}

original_code:
char *make_bf_salt_para(int rounds, char *saltpara)
{
  static char salt[31];
  char tbuf[3];
  if (saltpara && (strlen(saltpara) <= 22))
  {
    sprintf(tbuf, "%02d", rounds);
    sprintf(salt, "$2a$%s$%s$", tbuf, saltpara);
    return salt;
  }
  printf("Invalid Salt, please use up to 22 random alphanumeric characters\n");
  exit(1);
  return ((void *)0);
}

variable_types:
salt
char [31]

variable_types:
tbuf
char [3]


decompiled_code:
_BYTE *make_des_salt()
{
generate_random_salt(salt_7, 2);
byte_404159 = 0;
return salt_7;
}

canonical_decompiled_code:
_BYTE *func11()
{
generate_random_salt(salt_7, 2);
byte_404159 = 0;
return salt_7;
}

original_code:
char *make_des_salt(void)
{
  static char salt[3];
  generate_random_salt(salt, 2);
  salt[2] = '\0';
  return salt;
}

canonical_original_code:
char *make_des_salt()
{
  static char salt[3];
  generate_random_salt(salt, 2);
  salt[2] = '\0';
  return salt;
}

variable_types:
salt
char [3]


decompiled_code:
char *__fastcall make_ext_salt(int a1)
{
const char *v1; // rax

v1 = (const char *)int_to_base64(a1);
sprintf(salt_5, "_%s", v1);
generate_random_salt(byte_40414D, 4);
byte_404151 = 0;
return salt_5;
}

canonical_decompiled_code:
char *__fastcall func12(int a1)
{
const char *v1; // rax

v1 = (const char *)func7(a1);
sprintf(salt_5, "_%s", v1);
generate_random_salt(byte_40414D, 4);
byte_404151 = 0;
return salt_5;
}

original_code:
char *make_ext_salt(int rounds)
{
  static char salt[10];
  sprintf(salt, "_%s", int_to_base64(rounds));
  generate_random_salt(&salt[5], 4);
  salt[9] = '\0';
  return salt;
}


decompiled_code:
char *__fastcall make_bf_salt(unsigned int a1, int a2)
{
char s[11]; // [rsp+Dh] [rbp-Bh] BYREF

if ( a2 > 22 )
{
puts("BlowFish salt length too long");
exit(0);
}
sprintf(s, "%02d", a1);
sprintf(&salt_0, "$2a$%s$", s);
generate_random_salt(byte_4040C7, a2);
*(&salt_0 + a2 + 7) = 36;
*(&salt_0 + a2 + 8) = 0;
return &salt_0;
}

canonical_decompiled_code:
char *__fastcall func14(unsigned int a1, int a2)
{
char s[11]; // [rsp+Dh] [rbp-Bh] BYREF

if ( a2 > 22 )
{
puts("BlowFish salt length too long");
exit(0);
}
sprintf(s, "%02d", a1);
sprintf(&salt_0, "$2a$%s$", s);
generate_random_salt(byte_4040C7, a2);
*(&salt_0 + a2 + 7) = 36;
*(&salt_0 + a2 + 8) = 0;
return &salt_0;
}

original_code:
char *make_bf_salt(int rounds, int length)
{
  static char salt[31];
  char tbuf[3];
  if (length > 22)
  {
    printf("BlowFish salt length too long\n");
    exit(0);
  }
  sprintf(tbuf, "%02d", rounds);
  sprintf(salt, "$2a$%s$", tbuf);
  generate_random_salt(&salt[7], length);
  salt[length+7] = '$';
  salt[length+8] = '\0';
  return salt;
}

variable_types: length int


decompiled_code:
void __noreturn full_usage()
{
puts("mkpasswd [-m|-d|-b|-e] [-l saltlength] [-r rounds] [-s salt] [-p plaintext]");
puts("-m Generate an MD5 password");
puts("-d Generate a DES password");
puts("-b Generate a BlowFish password");
puts("-e Generate an Extended DES password");
puts("-l Specify a length for a random MD5 or BlowFish salt");
puts("-r Specify a number of rounds for a BlowFish or Extended DES password");
puts(" BlowFish: default 4, no more than 6 recommended");
puts(" Extended DES: default 25");
puts("-s Specify a salt, 2 alphanumeric characters for DES, up to 16 for MD5,");
puts(" up to 22 for BlowFish, and 4 for Extended DES");
puts("-p Specify a plaintext password to use");
puts("Example: mkpasswd -m -s 3dr -p test");
exit(0);
}

canonical_decompiled_code:
void __noreturn func15()
{
puts("mkpasswd [-m|-d|-b|-e] [-l saltlength] [-r rounds] [-s salt] [-p plaintext]");
puts("-m Generate an MD5 password");
puts("-d Generate a DES password");
puts("-b Generate a BlowFish password");
puts("-e Generate an Extended DES password");
puts("-l Specify a length for a random MD5 or BlowFish salt");
puts("-r Specify a number of rounds for a BlowFish or Extended DES password");
puts(" BlowFish: default 4, no more than 6 recommended");
puts(" Extended DES: default 25");
puts("-s Specify a salt, 2 alphanumeric characters for DES, up to 16 for MD5,");
puts(" up to 22 for BlowFish, and 4 for Extended DES");
puts("-p Specify a plaintext password to use");
puts("Example: mkpasswd -m -s 3dr -p test");
exit(0);
}

original_code:
void full_usage(void)
{
  printf("mkpasswd [-m|-d|-b|-e] [-l saltlength] [-r rounds] [-s salt] [-p plaintext]\n");
  printf("-m Generate an MD5 password\n");
  printf("-d Generate a DES password\n");
  printf("-b Generate a BlowFish password\n");
  printf("-e Generate an Extended DES password\n");
  printf("-l Specify a length for a random MD5 or BlowFish salt\n");
  printf("-r Specify a number of rounds for a BlowFish or Extended DES password\n");
  printf("   BlowFish:  default 4, no more than 6 recommended\n");
  printf("   Extended DES:  default 25\n");
  printf("-s Specify a salt, 2 alphanumeric characters for DES, up to 16 for MD5,\n");
  printf("   up to 22 for BlowFish, and 4 for Extended DES\n");
  printf("-p Specify a plaintext password to use\n");
  printf("Example: mkpasswd -m -s 3dr -p test\n");
  exit(0);
}

canonical_original_code:
void full_usage()
{
  printf("mkpasswd [-m|-d|-b|-e] [-l saltlength] [-r rounds] [-s salt] [-p plaintext]\n");
  printf("-m Generate an MD5 password\n");
  printf("-d Generate a DES password\n");
  printf("-b Generate a BlowFish password\n");
  printf("-e Generate an Extended DES password\n");
  printf("-l Specify a length for a random MD5 or BlowFish salt\n");
  printf("-r Specify a number of rounds for a BlowFish or Extended DES password\n");
  printf("   BlowFish:  default 4, no more than 6 recommended\n");
  printf("   Extended DES:  default 25\n");
  printf("-s Specify a salt, 2 alphanumeric characters for DES, up to 16 for MD5,\n");
  printf("   up to 22 for BlowFish, and 4 for Extended DES\n");
  printf("-p Specify a plaintext password to use\n");
  printf("Example: mkpasswd -m -s 3dr -p test\n");
  exit(0);
}


decompiled_code:
void __noreturn brief_usage()
{
puts("mkpasswd - password hash generator");
puts("Standard DES: mkpasswd [-d] [-s salt] [-p plaintext]");
puts("Extended DES: mkpasswd -e [-r rounds] [-s salt] [-p plaintext]");
puts(" MD5: mkpasswd -m [-l saltlength] [-s salt] [-p plaintext]");
puts(" BlowFish: mkpasswd -b [-r rounds] [-l saltlength] [-s salt]");
puts(" [-p plaintext]");
puts("Use -h for full usage");
exit(0);
}

canonical_decompiled_code:
void __noreturn func16()
{
puts("mkpasswd - password hash generator");
puts("Standard DES: mkpasswd [-d] [-s salt] [-p plaintext]");
puts("Extended DES: mkpasswd -e [-r rounds] [-s salt] [-p plaintext]");
puts(" MD5: mkpasswd -m [-l saltlength] [-s salt] [-p plaintext]");
puts(" BlowFish: mkpasswd -b [-r rounds] [-l saltlength] [-s salt]");
puts(" [-p plaintext]");
puts("Use -h for full usage");
exit(0);
}

original_code:
void brief_usage(void)
{
  printf("mkpasswd - password hash generator\n");
  printf("Standard DES:  mkpasswd [-d] [-s salt] [-p plaintext]\n");
  printf("Extended DES:  mkpasswd -e [-r rounds] [-s salt] [-p plaintext]\n");
  printf("         MD5:  mkpasswd -m [-l saltlength] [-s salt] [-p plaintext]\n");
  printf("    BlowFish:  mkpasswd -b [-r rounds] [-l saltlength] [-s salt]\n");
  printf("                           [-p plaintext]\n");
  printf("Use -h for full usage\n");
  exit(0);
}

canonical_original_code:
void brief_usage()
{
  printf("mkpasswd - password hash generator\n");
  printf("Standard DES:  mkpasswd [-d] [-s salt] [-p plaintext]\n");
  printf("Extended DES:  mkpasswd -e [-r rounds] [-s salt] [-p plaintext]\n");
  printf("         MD5:  mkpasswd -m [-l saltlength] [-s salt] [-p plaintext]\n");
  printf("    BlowFish:  mkpasswd -b [-r rounds] [-l saltlength] [-s salt]\n");
  printf("                           [-p plaintext]\n");
  printf("Use -h for full usage\n");
  exit(0);
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
char *v4; // r13
char *v5; // r14
unsigned int v6; // eax
char *v7; // rax
int result; // eax
int v9; // [rsp+8h] [rbp-40h]
int v10; // [rsp+Ch] [rbp-3Ch]

v9 = 0;
v10 = 0;
v3 = 0;
v4 = 0LL;
v5 = 0LL;
while ( 1 )
{
v6 = getopt(argc, (char *const *)argv, "mdber:h?l:s:p:");
if ( v6 == -1 )
break;
switch ( v6 )
{
case '?':
brief_usage();
return result;
case 'b':
v3 |= 0x20u;
v9 = 4;
break;
case 'd':
v3 |= 2u;
break;
case 'e':
LOBYTE(v3) = v3 | 0x80;
v9 = 25;
break;
case 'h':
full_usage();
return result;
case 'l':
v3 |= 0x10u;
v10 = atoi(optarg);
break;
case 'm':
v3 |= 1u;
break;
case 'p':
v3 |= 8u;
v5 = optarg;
break;
case 'r':
v3 |= 0x40u;
v9 = atoi(optarg);
break;
case 's':
v3 |= 4u;
v4 = optarg;
break;
default:
printf("Invalid Option: -%c\n", v6);
break;
}
}
if ( (v3 & 1) != 0 )
{
if ( !v10 )
v10 = 8;
if ( (v3 & 4) != 0 )
v4 = make_md5_salt_para(v4);
else
v4 = make_md5_salt(v10);
}
else if ( (v3 & 0x20) != 0 )
{
if ( !v10 )
v10 = 22;
if ( (v3 & 4) != 0 )
v4 = make_bf_salt_para(v9, v4);
else
v4 = make_bf_salt(v9, v10);
}
else if ( (v3 & 0x80u) == 0 )
{
if ( (v3 & 4) != 0 )
{
if ( strlen(v4) != 2 )
{
puts("Invalid salt, please enter 2 alphanumeric characters");
exit(1);
}
}
else
{
v4 = make_des_salt();
}
}
else if ( (v3 & 4) != 0 )
{
if ( strlen(v4) != 4 )
{
puts("Invalid salt, please enter 4 alphanumeric characters");
exit(1);
}
v4 = make_ext_salt_para(v9, v4);
}
else
{
v4 = make_ext_salt(v9);
}
if ( (v3 & 8) != 0 )
{
if ( !v5 )
puts("Please enter a valid password");
}
else
{
v5 = getpass("plaintext: ");
}
v7 = crypt(v5, v4);
puts(v7);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
char *v4; // r13
char *v5; // r14
unsigned int v6; // eax
char *v7; // rax
int result; // eax
int v9; // [rsp+8h] [rbp-40h]
int v10; // [rsp+Ch] [rbp-3Ch]

v9 = 0;
v10 = 0;
v3 = 0;
v4 = 0LL;
v5 = 0LL;
while ( 1 )
{
v6 = getopt(argc, (char *const *)argv, "mdber:h?l:s:p:");
if ( v6 == -1 )
break;
switch ( v6 )
{
case '?':
func16();
return result;
case 'b':
v3 |= 0x20u;
v9 = 4;
break;
case 'd':
v3 |= 2u;
break;
case 'e':
LOBYTE(v3) = v3 | 0x80;
v9 = 25;
break;
case 'h':
func15();
return result;
case 'l':
v3 |= 0x10u;
v10 = atoi(optarg);
break;
case 'm':
v3 |= 1u;
break;
case 'p':
v3 |= 8u;
v5 = optarg;
break;
case 'r':
v3 |= 0x40u;
v9 = atoi(optarg);
break;
case 's':
v3 |= 4u;
v4 = optarg;
break;
default:
printf("Invalid Option: -%c\n", v6);
break;
}
}
if ( (v3 & 1) != 0 )
{
if ( !v10 )
v10 = 8;
if ( (v3 & 4) != 0 )
v4 = func9(v4);
else
v4 = func13(v10);
}
else if ( (v3 & 0x20) != 0 )
{
if ( !v10 )
v10 = 22;
if ( (v3 & 4) != 0 )
v4 = func10(v9, v4);
else
v4 = func14(v9, v10);
}
else if ( (v3 & 0x80u) == 0 )
{
if ( (v3 & 4) != 0 )
{
if ( strlen(v4) != 2 )
{
puts("Invalid salt, please enter 2 alphanumeric characters");
exit(1);
}
}
else
{
v4 = func11();
}
}
else if ( (v3 & 4) != 0 )
{
if ( strlen(v4) != 4 )
{
puts("Invalid salt, please enter 4 alphanumeric characters");
exit(1);
}
v4 = func8(v9, v4);
}
else
{
v4 = func12(v9);
}
if ( (v3 & 8) != 0 )
{
if ( !v5 )
puts("Please enter a valid password");
}
else
{
v5 = getpass("plaintext: ");
}
v7 = crypt(v5, v4);
puts(v7);
return 0;
}

original_code:
int main(int argc, char *argv[])
{
  char *plaintext = ((void *)0);
  extern char *optarg;
  int c;
  char *saltpara = ((void *)0);
  char *salt;
  int flag = 0;
  int length = 0;
  int rounds = 0;
  while( (c=getopt(argc, argv, "mdber:h?l:s:p:")) != -1)
  {
    switch(c)
    {
      case 'm':
        flag |= 0x00000001;
        break;
      case 'd':
        flag |= 0x00000002;
        break;
      case 'b':
        flag |= 0x00000020;
        rounds = 4;
        break;
      case 'e':
        flag |= 0x00000080;
        rounds = 25;
        break;
      case 'l':
        flag |= 0x00000010;
        length = atoi(optarg);
        break;
      case 'r':
        flag |= 0x00000040;
        rounds = atoi(optarg);
        break;
      case 's':
        flag |= 0x00000004;
        saltpara = optarg;
        break;
      case 'p':
        flag |= 0x00000008;
        plaintext = optarg;
        break;
      case 'h':
        full_usage();
        break;
      case '?':
        brief_usage();
        break;
      default:
        printf("Invalid Option: -%c\n", c);
        break;
    }
  }
  if (flag & 0x00000001)
  {
    if (length == 0)
      length = 8;
    if (flag & 0x00000004)
      salt = make_md5_salt_para(saltpara);
    else
      salt = make_md5_salt(length);
  }
  else if (flag & 0x00000020)
  {
    if (length == 0)
      length = 22;
    if (flag & 0x00000004)
      salt = make_bf_salt_para(rounds, saltpara);
    else
      salt = make_bf_salt(rounds, length);
  }
  else if (flag & 0x00000080)
  {
    if (flag & 0x00000004)
    {
      if ((strlen(saltpara) == 4))
      {
        salt = make_ext_salt_para(rounds, saltpara);
      }
      else
      {
        printf("Invalid salt, please enter 4 alphanumeric characters\n");
        exit(1);
      }
    }
    else
    {
      salt = make_ext_salt(rounds);
    }
  }
  else
  {
    if (flag & 0x00000004)
    {
      if ((strlen(saltpara) == 2))
      {
        salt = saltpara;
      }
      else
      {
        printf("Invalid salt, please enter 2 alphanumeric characters\n");
        exit(1);
      }
    }
    else
    {
      salt = make_des_salt();
    }
  }
  if (flag & 0x00000008)
  {
    if (!plaintext)
      printf("Please enter a valid password\n");
  }
  else
  {
    plaintext = getpass("plaintext: ");
  }
  printf("%s\n", crypt(plaintext, salt));
  return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
plaintext
char *

variable_types:
optarg
char *

variable_types: c int

variable_types:
salt
char *

variable_types: flag int


cas

repo: irinaburdova/OS

decompiled_code:
__int64 __fastcall cas(__int64 _RDI, unsigned int a2, int _EDX)
{
__int64 result; // rax

result = a2;
__asm { cmpxchg [rdi], edx }
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 _RDI, unsigned int a2, int _EDX)
{
__int64 result; // rax

result = a2;
__asm { cmpxchg [rdi], edx }
return result;
}

original_code:
void cas(int* value, int cmp, int new_value) {
    int result;
    asm volatile("cmpxchg %1, %2"
        :"=a"(result)
        :"r"(new_value), "m"(*value), "0"(cmp)
        :"memory"
        );
    return;
}

canonical_original_code:
void cas(int *value, int cmp, int new_value) {
    int result;
    asm volatile("cmpxchg %1, %2"
        :"=a"(result)
        :"r"(new_value), "m"(*value), "0"(cmp)
        :"memory"
        );
    return;
}

variable_types:
value
int *

variable_types: cmp int

variable_types: result int


lock

decompiled_code:
int __fastcall lock(_DWORD *a1, int a2)
{
int result; // eax
struct timespec v3; // [rsp+0h] [rbp-28h] BYREF

v3.tv_sec = 0LL;
v3.tv_nsec = 10LL;
do
{
cas((__int64)a1, 0, a2);
result = nanosleep(&v3, 0LL);
}
while ( *a1 != a2 );
return result;
}

canonical_decompiled_code:
int __fastcall func8(_DWORD *a1, int a2)
{
int result; // eax
struct timespec v3; // [rsp+0h] [rbp-28h] BYREF

v3.tv_sec = 0LL;
v3.tv_nsec = 10LL;
do
{
func7((__int64)a1, 0, a2);
result = nanosleep(&v3, 0LL);
}
while ( *a1 != a2 );
return result;
}

original_code:
void lock(int* lock, int who) {
    struct timespec t;
    t.tv_sec = 0;
    t.tv_nsec = 10;
    do {
        cas(lock, 0, who);
        nanosleep(&t, ((void *)0));
    } while (*lock != who);
    return;
}

canonical_original_code:
void lock(int *lock, int who) {
    struct timespec t;
    t.tv_sec = 0;
    t.tv_nsec = 10;
    do {
        cas(lock, 0, who);
        nanosleep(&t, ((void *)0));
    } while (*lock != who);
    return;
}

variable_types:
lock
int *

variable_types: who int

variable_types: struct timespec { long tv_sec; long tv_nsec; }


worker

decompiled_code:
void *__fastcall worker(void *a1)
{
int v1; // ebp
int v2; // ebx
struct timespec v4; // [rsp+0h] [rbp-28h] BYREF

v1 = *(_DWORD *)a1;
v4.tv_sec = 0LL;
v4.tv_nsec = 10LL;
v2 = 500;
do
{
lock(mutex, v1);
++sum;
nanosleep(&v4, 0LL);
unlock(mutex);
--v2;
}
while ( v2 );
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func10(void *a1)
{
int v1; // ebp
int v2; // ebx
struct timespec v4; // [rsp+0h] [rbp-28h] BYREF

v1 = *(_DWORD *)a1;
v4.tv_sec = 0LL;
v4.tv_nsec = 10LL;
v2 = 500;
do
{
func8(mutex, v1);
++sum;
nanosleep(&v4, 0LL);
func9(mutex);
--v2;
}
while ( v2 );
return 0LL;
}

original_code:
void* worker(void *number) {
    int i;
    int id = *((int *) number);
    struct timespec t;
    t.tv_sec = 0;
    t.tv_nsec = 10;
    for (i = 0; i != 500; ++i) {
        lock(&mutex, id);
        ++sum;
        nanosleep(&t, ((void *)0));
        unlock(&mutex);
    }
    return ((void *)0);
}

canonical_original_code:
void *worker(void *number) {
    int i;
    int id = *((int *) number);
    struct timespec t;
    t.tv_sec = 0;
    t.tv_nsec = 10;
    for (i = 0; i != 500; ++i) {
        lock(&mutex, id);
        ++sum;
        nanosleep(&t, ((void *)0));
        unlock(&mutex);
    }
    return ((void *)0);
}

variable_types:
number
void *

variable_types: i int

variable_types: id int

user_defined_types: struct timespec { long tv_sec; long tv_nsec; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 *v3; // r14
pthread_t *v4; // r15
int v5; // ebx
unsigned int v6; // eax
int v7; // er12
__int64 i; // rbx
unsigned int v10; // eax
__int64 v11; // [rsp+0h] [rbp-4E0h] BYREF
_QWORD v12[106]; // [rsp+190h] [rbp-350h] BYREF

v3 = &v11;
v4 = v12;
v5 = 0;
do
{
*(_DWORD *)v3 = ++v5;
v6 = pthread_create(v4, 0LL, worker, v3);
v7 = v6;
if ( v6 )
{
printf("Can't create thread: %d\n", v6);
return 13;
}
v3 = (__int64 *)((char *)v3 + 4);
++v4;
}
while ( v5 != 100 );
for ( i = 0LL; i != 100; ++i )
{
v10 = pthread_join(v12[i], 0LL);
if ( v10 )
printf("Can't join thread %d: %d", (unsigned int)i, v10);
}
printf("%lu\n", sum);
return v7;
}

original_code:
int main() {
    int threads_count = 100;
    pthread_t threads[threads_count];
    int ids[threads_count];
    int error, i;
    for (i = 0; i != threads_count; ++i) {
        ids[i] = i + 1;
        error = pthread_create(&threads[i], ((void *)0), &worker, &ids[i]);
        if (error) {
            printf("Can't create thread: %d\n", error);
            return 13;
        }
    }
    for (i = 0; i != threads_count; ++i) {
        error = pthread_join(threads[i], ((void *)0));
        if (error) {
            printf("Can't join thread %d: %d", i, error);
        }
    }
    printf("%lu\n", sum);
    return 0;
}

canonical_original_code:
int main() {
    int threads_count = 100;
    unsigned long threads[-1];
    int ids[-1];
    int error; int i;
    for (i = 0; i != threads_count; ++i) {
        ids[i] = i + 1;
        error = pthread_create(&threads[i], ((void *)0), &worker, &ids[i]);
        if (error) {
            printf("Can't create thread: %d\n", error);
            return 13;
        }
    }
    for (i = 0; i != threads_count; ++i) {
        error = pthread_join(threads[i], ((void *)0));
        if (error) {
            printf("Can't join thread %d: %d", i, error);
        }
    }
    printf("%lu\n", sum);
    return 0;
}

variable_types:
threads
unsigned long [-1]

variable_types:
ids
int [-1]

variable_types: error int


repo: irtefa/algo

original_code:
int rabin_karp(char text[], char pattern[])
{
 int t_len = strlen(text);
 int p_len = strlen(pattern);
 int i, j;
 if(p_len > t_len)
 {
  return 0;
 }
 int h = 1;
 for (i = 0; i < p_len - 1; i++)
 {
             h = (h*256)%3571;
   }
 for(i = 0; i < p_len; i++)
 {
  if(pattern[i] != text[i])
  {
   break;
  }
 }
 if(i == p_len)
 {
  printf("found at %d\n", i - p_len);
  return 1;
 }
 int hp = 0;
 int ht = 0;
 for(i = 0; i < p_len; i++)
 {
  hp = (hp * 256 + pattern[i]) % 3571;
  ht = (ht * 256 + text[i]) % 3571;
 }
 for(i = 0; i < t_len; i++)
 {
  if(ht == hp)
  {
   for(j = 0; j < p_len; j++)
   {
    if(text[i + j] != pattern[j])
    {
     break;
    }
   }
   if(j == p_len)
   {
    printf("found at %d\n", i);
    return 1;
   }
  }
  ht = (256 * (ht - text[i] * h) + text[i + p_len]) % 3571;
  if(ht < 0)
  {
   ht = ht + 3571;
  }
 }
 return 0;
}

canonical_original_code:
int rabin_karp(char text[], char pattern[])
{
 int t_len = strlen(text);
 int p_len = strlen(pattern);
 int i; int j;
 if(p_len > t_len)
 {
  return 0;
 }
 int h = 1;
 for (i = 0; i < p_len - 1; i++)
 {
             h = (h*256)%3571;
   }
 for(i = 0; i < p_len; i++)
 {
  if(pattern[i] != text[i])
  {
   break;
  }
 }
 if(i == p_len)
 {
  printf("found at %d\n", i - p_len);
  return 1;
 }
 int hp = 0;
 int ht = 0;
 for(i = 0; i < p_len; i++)
 {
  hp = (hp * 256 + pattern[i]) % 3571;
  ht = (ht * 256 + text[i]) % 3571;
 }
 for(i = 0; i < t_len; i++)
 {
  if(ht == hp)
  {
   for(j = 0; j < p_len; j++)
   {
    if(text[i + j] != pattern[j])
    {
     break;
    }
   }
   if(j == p_len)
   {
    printf("found at %d\n", i);
    return 1;
   }
  }
  ht = (256 * (ht - text[i] * h) + text[i + p_len]) % 3571;
  if(ht < 0)
  {
   ht = ht + 3571;
  }
 }
 return 0;
}

variable_types:
text
char []

variable_types:
pattern
char []

variable_types: j int

variable_types: h int

variable_types: hp int

variable_types: ht int


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( (unsigned int)rabin_karp(argv[1], argv[2]) == 1 )
puts("Pattern mathes text");
else
puts("Patter does not match text");
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( (unsigned int)func7(argv[1], argv[2]) == 1 )
puts("Pattern mathes text");
else
puts("Patter does not match text");
return 0;
}

original_code:
int main(int argc, char * argv[])
{
 if(rabin_karp(argv[1], argv[2]) == 1)
 {
  printf("Pattern mathes text\n");
  return 0;
 }
 printf("Patter does not match text\n");
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 if(rabin_karp(argv[1], argv[2]) == 1)
 {
  printf("Pattern mathes text\n");
  return 0;
 }
 printf("Patter does not match text\n");
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


decompiled_code:
__int64 __fastcall brute_force(const char *a1, const char *a2)
{
int v3; // er13
int v4; // ebp
int v5; // eax
int v6; // er9
int v7; // er8
int v8; // er13
__int64 v9; // rsi
__int64 v10; // rax
int v11; // edx

v3 = strlen(a1);
v4 = v3;
v5 = strlen(a2);
if ( v3 <= 0 )
return 0LL;
v6 = v5;
v7 = 0;
v8 = v3 - 1;
v9 = (unsigned int)(v5 - 1);
do
{
if ( v6 <= 0 )
{
v11 = 0;
}
else
{
v10 = 0LL;
if ( v4 <= v7 )
goto LABEL_10;
while ( 1 )
{
v11 = v10;
if ( a1[v10] != a2[v10] )
break;
v11 = v10 + 1;
if ( v10 == v9 )
break;
if ( v10 == v8 - v7 )
goto LABEL_10;
++v10;
}
}
if ( v6 == v11 )
return 1LL;
LABEL_10:
++v7;
++a1;
}
while ( v4 != v7 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(const char *a1, const char *a2)
{
int v3; // er13
int v4; // ebp
int v5; // eax
int v6; // er9
int v7; // er8
int v8; // er13
__int64 v9; // rsi
__int64 v10; // rax
int v11; // edx

v3 = strlen(a1);
v4 = v3;
v5 = strlen(a2);
if ( v3 <= 0 )
return 0LL;
v6 = v5;
v7 = 0;
v8 = v3 - 1;
v9 = (unsigned int)(v5 - 1);
do
{
if ( v6 <= 0 )
{
v11 = 0;
}
else
{
v10 = 0LL;
if ( v4 <= v7 )
goto LABEL_10;
while ( 1 )
{
v11 = v10;
if ( a1[v10] != a2[v10] )
break;
v11 = v10 + 1;
if ( v10 == v9 )
break;
if ( v10 == v8 - v7 )
goto LABEL_10;
++v10;
}
}
if ( v6 == v11 )
return 1LL;
LABEL_10:
++v7;
++a1;
}
while ( v4 != v7 );
return 0LL;
}

original_code:
int brute_force(char text[], char pattern[])
{
 int t_len = strlen(text);
 int p_len = strlen(pattern);
 int i,j;
 for(i=0; i < t_len; i++) {
  for(j=0; j < p_len && i + j < t_len; j++) {
   if(text[i + j] != pattern[j]) {
    break;
   }
  }
  if(j == p_len) {
   return 1;
  }
 }
 return 0;
}

canonical_original_code:
int brute_force(char text[], char pattern[])
{
 int t_len = strlen(text);
 int p_len = strlen(pattern);
 int i; int j;
 for(i=0; i < t_len; i++) {
  for(j=0; j < p_len && i + j < t_len; j++) {
   if(text[i + j] != pattern[j]) {
    break;
   }
  }
  if(j == p_len) {
   return 1;
  }
 }
 return 0;
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( (unsigned int)brute_force(argv[1], argv[2]) == 1 )
puts("There is a match");
else
puts("The pattern is not present");
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( (unsigned int)func7(argv[1], argv[2]) == 1 )
puts("There is a match");
else
puts("The pattern is not present");
return 0;
}

original_code:
int main(int argc, char * argv[])
{
 if(brute_force(argv[1], argv[2]) == 1) {
  printf("There is a match\n");
  return 0;
 }
 printf("The pattern is not present\n");
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 if(brute_force(argv[1], argv[2]) == 1) {
  printf("There is a match\n");
  return 0;
 }
 printf("The pattern is not present\n");
 return 0;
}


repo: ismell/rxh

original_code:
rxJobs *rxJobs_Initialize() {
 rxJobs *jobs = (rxJobs*)xmalloc(sizeof(rxJobs));
 jobs->i = -1;
 jobs->n = 3;
 jobs->cnt = 0;
 jobs->jobs = (rxJob**)xmalloc(sizeof(rxJob*)*jobs->n);
 return jobs;
}

canonical_original_code:
struct rxJobs *rxJobs_Initialize() {
 struct rxJobs *jobs = (rxJobs*)xmalloc(sizeof(rxJobs));
 jobs->i = -1;
 jobs->n = 3;
 jobs->cnt = 0;
 jobs->jobs = (struct rxJob **)xmalloc(sizeof(struct rxJob *)*jobs->n);
 return jobs;
}

variable_types: struct rxJobs { int i; int n; struct rxJob { int id; int pid; int status; int rtn; char *cmd; } **jobs; int cnt; } *

user_defined_types: struct rxJobs { int i; int n; struct rxJob **jobs; int cnt; }


original_code:
int rxJobs_Add(rxJobs *jobs, rxJob *job){
 if (!jobs || !job)
  return -1;
 if (jobs->i >= jobs->n-1) {
  if (0) fprintf(stderr, "Making jobs buffer bigger\n");
  jobs->n += 2;
  jobs->jobs = (rxJob**)xrealloc(jobs->jobs, sizeof(rxJob*)*jobs->n);
 }
 job->id = ++jobs->cnt;
 job->status = 1;
 jobs->jobs[++(jobs->i)] = job;
 printf("[%d] %d\n",job->id, job->pid);
 return 0;
}

canonical_original_code:
int rxJobs_Add(struct rxJobs *jobs, struct rxJob *job){
 if (!jobs || !job)
  return -1;
 if (jobs->i >= jobs->n-1) {
  if (0) fprintf(stderr, "Making jobs buffer bigger\n");
  jobs->n += 2;
  jobs->jobs = (struct rxJob **)xrealloc(jobs->jobs, sizeof(struct rxJob *)*jobs->n);
 }
 job->id = ++jobs->cnt;
 job->status = 1;
 jobs->jobs[++(jobs->i)] = job;
 printf("[%d] %d\n",job->id, job->pid);
 return 0;
}

variable_types:
job
struct rxJob *

user_defined_types: struct rxJob { int id; int pid; int status; int rtn; char *cmd; }


decompiled_code:
int __fastcall rxJob_Print(const char **a1)
{
const char *v1; // rdx
int result; // eax

if ( a1 )
{
v1 = "running";
if ( !*((_DWORD *)a1 + 2) )
v1 = "done";
result = printf("[%d] %-10s %-10d %s\n", *(unsigned int *)a1, v1, *((unsigned int *)a1 + 1), a1[2]);
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(const char **a1)
{
const char *v1; // rdx
int result; // eax

if ( a1 )
{
v1 = "running";
if ( !*((_DWORD *)a1 + 2) )
v1 = "done";
result = printf("[%d] %-10s %-10d %s\n", *(unsigned int *)a1, v1, *((unsigned int *)a1 + 1), a1[2]);
}
return result;
}

original_code:
void rxJob_Print(rxJob *job) {
 char *status;
 if (!job)
  return;
 printf("[%d] %-10s %-10d %s\n", job->id, (job->status ? "running" : "done"), job->pid, job->cmd);
 return;
}

canonical_original_code:
void rxJob_Print(struct rxJob *job) {
 char *status;
 if (!job)
  return;
 printf("[%d] %-10s %-10d %s\n", job->id, (job->status ? "running" : "done"), job->pid, job->cmd);
 return;
}

variable_types: struct rxJob { int id; int pid; int status; int rtn; char *cmd; } *

variable_types:
status
char *


decompiled_code:
int __fastcall rxJobs_Print(__int64 a1)
{
__int64 v1; // rbx
int result; // eax

if ( a1 && *(int *)a1 >= 0 )
{
v1 = 0LL;
do
result = rxJob_Print(*(const char ***)(*(_QWORD *)(a1 + 8) + 8 * v1++));
while ( *(_DWORD *)a1 >= (int)v1 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1)
{
__int64 v1; // rbx
int result; // eax

if ( a1 && *(int *)a1 >= 0 )
{
v1 = 0LL;
do
result = func2(*(const char ***)(*(_QWORD *)(a1 + 8) + 8 * v1++));
while ( *(_DWORD *)a1 >= (int)v1 );
}
return result;
}

original_code:
void rxJobs_Print(rxJobs *jobs) {
 int i;
 if (!jobs || jobs->i < 0)
  return;
 if (0) fprintf(stderr, "n: %d, i: %d\n", jobs->n, jobs->i);
 for (i = 0; i <= jobs->i; i++)
  rxJob_Print(jobs->jobs[i]);
 return;
}

canonical_original_code:
void rxJobs_Print(struct rxJobs *jobs) {
 int i;
 if (!jobs || jobs->i < 0)
  return;
 if (0) fprintf(stderr, "n: %d, i: %d\n", jobs->n, jobs->i);
 for (i = 0; i <= jobs->i; i++)
  rxJob_Print(jobs->jobs[i]);
 return;
}

variable_types: i int


original_code:
void rxJobs_Wait(rxJobs *jobs, int hang) {
 int i = 0, j;
 rxJob *job;
 if (0) fprintf(stderr, "n: %d, I: %d\n", jobs->n, jobs->i);
 if (!jobs || jobs->i < 0)
  return;
 for (i = 0; i <= jobs->i; i++) {
  job = jobs->jobs[i];
  if (0) fprintf(stderr, "   i: %d, I: %d, pid: %d\n", i, jobs->i, job->pid);
  if (job && waitpid(job->pid, &job->rtn, (hang ? 0 : 1))) {
   job->status = 0;
   rxJob_Print(job);
   free(job);
   if (jobs->i-i > 0) {
    if (0) fprintf(stderr, "shifting %d\n", jobs->i-i);
    for (j = i; j < jobs->i; j++) {
     jobs->jobs[j] = jobs->jobs[j+1];
    }
    i--;
   }
   jobs->i--;
  }
 }
 if (0) fprintf(stderr, "final: i) %d, I) %d\n", i, jobs->i);
 return;
}

canonical_original_code:
void rxJobs_Wait(struct rxJobs *jobs, int hang) {
 int i = 0; int j;
 struct rxJob *job;
 if (0) fprintf(stderr, "n: %d, I: %d\n", jobs->n, jobs->i);
 if (!jobs || jobs->i < 0)
  return;
 for (i = 0; i <= jobs->i; i++) {
  job = jobs->jobs[i];
  if (0) fprintf(stderr, "   i: %d, I: %d, pid: %d\n", i, jobs->i, job->pid);
  if (job && waitpid(job->pid, &job->rtn, (hang ? 0 : 1))) {
   job->status = 0;
   rxJob_Print(job);
   free(job);
   if (jobs->i-i > 0) {
    if (0) fprintf(stderr, "shifting %d\n", jobs->i-i);
    for (j = i; j < jobs->i; j++) {
     jobs->jobs[j] = jobs->jobs[j+1];
    }
    i--;
   }
   jobs->i--;
  }
 }
 if (0) fprintf(stderr, "final: i) %d, I) %d\n", i, jobs->i);
 return;
}

variable_types: hang int


decompiled_code:
_BOOL8 __fastcall file_select(const struct dirent *a1)
{
char *v1; // rdx
bool v2; // zf
_BOOL8 result; // rax

v1 = a1->d_name;
v2 = strcmp(a1->d_name, ".") == 0;
result = !v2;
if ( !v2 )
{
v2 = strcmp(v1, "..") == 0;
result = !v2;
if ( !v2 )
result = access(v1, 1) == 0;
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(const struct dirent *a1)
{
char *v1; // rdx
bool v2; // zf
_BOOL8 result; // rax

v1 = a1->d_name;
v2 = strcmp(a1->d_name, ".") == 0;
result = !v2;
if ( !v2 )
{
v2 = strcmp(v1, "..") == 0;
result = !v2;
if ( !v2 )
result = access(v1, 1) == 0;
}
return result;
}

original_code:
int file_select(const struct dirent *entry) {
 if ((strcmp(entry->d_name, ".")== 0) || (strcmp(entry->d_name, "..") == 0))
  return (0);
 return !access(entry->d_name, 1);
}

canonical_original_code:
int file_select(struct dirent *entry) {
 if ((strcmp(entry->d_name, ".")== 0) || (strcmp(entry->d_name, "..") == 0))
  return (0);
 return !access(entry->d_name, 1);
}

variable_types: struct dirent { unsigned long d_ino; long d_off; unsigned short d_reclen; unsigned char d_type; char d_name[256]; } *


decompiled_code:
char *__fastcall command_generator(const char *a1, int a2)
{
int v2; // er12
void *v3; // rbp
void *v4; // rdi
char *v5; // rbx
char *v6; // rax
char *v7; // r13
int v8; // ebp
char *v9; // r12
__int64 v10; // rbp
unsigned __int64 v11; // rbx
_QWORD *v12; // rbp
size_t v13; // r13
__int64 v14; // r14
const char *v15; // r12
const char *v16; // rbx
size_t v17; // rax
char *v18; // rbp
__int64 v19; // r12
void *v21; // rbp
const char *v22; // rdi
__int64 v23; // rbx
char *v24; // rax
char *v25; // rdi
__int64 i; // rbx
char **v27; // rbp
int v28; // eax
int v29; // er13
__int64 v30; // r12
int v32; // [rsp+14h] [rbp-54h]
char *ptr; // [rsp+18h] [rbp-50h]
struct dirent **namelist[8]; // [rsp+28h] [rbp-40h] BYREF

namelist[0] = 0LL;
if ( !a2 )
{
v2 = 0;
list_index_5 = 0;
offset_4 = 0;
v3 = cmds_3;
if ( cmds_3 )
{
v4 = *(void **)cmds_3;
if ( *(_QWORD *)cmds_3 )
{
v5 = (char *)cmds_3 + 8;
do
{
free(v4);
v5 += 8;
v4 = (void *)*((_QWORD *)v5 - 1);
}
while ( v4 );
}
free(v3);
}
v6 = rindex(a1, 47);
if ( v6 )
{
offset_4 = (_DWORD)v6 - (_DWORD)a1 + 1;
v7 = (char *)xcalloc(offset_4, 1LL);
strncpy(v7, a1, offset_4 - 1);
v8 = scandir(
v7,
namelist,
(int (*)(const struct dirent *))file_select,
(int (*)(const struct dirent **, const struct dirent **))&alphasort);
v9 = (char *)xcalloc(v8 + 1, 8LL);
cmds_3 = v9;
if ( v8 > 0 )
{
v10 = 8LL * (unsigned int)v8;
v11 = 0LL;
do
{
*(_QWORD *)&v9[v11] = strdup(namelist[0][v11 / 8]->d_name);
free(namelist[0][v11 / 8]);
v11 += 8LL;
}
while ( v11 != v10 );
}
free(namelist[0]);
free(v7);
}
else
{
v21 = (void *)xmalloc(12000LL);
cmds_3 = v21;
v22 = commands;
if ( commands )
{
v23 = 1LL;
do
{
*((_QWORD *)v21 + v23 - 1) = strdup(v22);
v2 = v23++;
v22 = (&commands)[3 * v23 - 3];
}
while ( v22 );
}
v24 = getenv("PATH");
ptr = strdup(v24);
v25 = strtok(ptr, ":");
if ( v25 )
{
v32 = 1500;
do
{
v28 = scandir(v25, namelist, 0LL, (int (*)(const struct dirent **, const struct dirent **))&alphasort);
v29 = v28;
if ( v28 >= 0 )
{
if ( v2 + v28 >= v32 )
{
v32 += 2 * v28;
cmds_3 = (void *)xrealloc(cmds_3, 8LL * v32);
}
if ( v29 > 0 )
{
for ( i = 0LL; i != v29; ++i )
{
v27 = (char **)((char *)cmds_3 + 8 * v2 + i * 8);
*v27 = strdup(namelist[0][i]->d_name);
free(namelist[0][i]);
}
v2 += v29;
}
free(namelist[0]);
}
v25 = strtok(0LL, ":");
}
while ( v25 );
}
free(ptr);
v30 = 8LL * v2;
cmds_3 = (void *)xrealloc(cmds_3, v30);
*(_QWORD *)((char *)cmds_3 + v30 - 8) = 0LL;
}
len_2 = strlen(&a1[offset_4]);
}
v12 = cmds_3;
v13 = len_2;
v14 = offset_4;
v15 = &a1[offset_4];
while ( 1 )
{
v16 = (const char *)v12[list_index_5];
if ( !v16 )
break;
++list_index_5;
if ( !strncmp(v16, v15, v13) )
{
v17 = strlen(v16);
v18 = (char *)xcalloc(v14 + v17 + 1, 1LL);
v19 = offset_4;
strncpy(v18, a1, offset_4);
strcpy(&v18[v19], v16);
return v18;
}
}
return (char *)v16;
}

canonical_decompiled_code:
char *__fastcall func1(const char *a1, int a2)
{
int v2; // er12
void *v3; // rbp
void *v4; // rdi
char *v5; // rbx
char *v6; // rax
char *v7; // r13
int v8; // ebp
char *v9; // r12
__int64 v10; // rbp
unsigned __int64 v11; // rbx
_QWORD *v12; // rbp
size_t v13; // r13
__int64 v14; // r14
const char *v15; // r12
const char *v16; // rbx
size_t v17; // rax
char *v18; // rbp
__int64 v19; // r12
void *v21; // rbp
const char *v22; // rdi
__int64 v23; // rbx
char *v24; // rax
char *v25; // rdi
__int64 i; // rbx
char **v27; // rbp
int v28; // eax
int v29; // er13
__int64 v30; // r12
int v32; // [rsp+14h] [rbp-54h]
char *ptr; // [rsp+18h] [rbp-50h]
struct dirent **namelist[8]; // [rsp+28h] [rbp-40h] BYREF

namelist[0] = 0LL;
if ( !a2 )
{
v2 = 0;
list_index_5 = 0;
offset_4 = 0;
v3 = cmds_3;
if ( cmds_3 )
{
v4 = *(void **)cmds_3;
if ( *(_QWORD *)cmds_3 )
{
v5 = (char *)cmds_3 + 8;
do
{
free(v4);
v5 += 8;
v4 = (void *)*((_QWORD *)v5 - 1);
}
while ( v4 );
}
free(v3);
}
v6 = rindex(a1, 47);
if ( v6 )
{
offset_4 = (_DWORD)v6 - (_DWORD)a1 + 1;
v7 = (char *)xcalloc(offset_4, 1LL);
strncpy(v7, a1, offset_4 - 1);
v8 = scandir(
v7,
namelist,
(int (*)(const struct dirent *))file_select,
(int (*)(const struct dirent **, const struct dirent **))&alphasort);
v9 = (char *)xcalloc(v8 + 1, 8LL);
cmds_3 = v9;
if ( v8 > 0 )
{
v10 = 8LL * (unsigned int)v8;
v11 = 0LL;
do
{
*(_QWORD *)&v9[v11] = strdup(namelist[0][v11 / 8]->d_name);
free(namelist[0][v11 / 8]);
v11 += 8LL;
}
while ( v11 != v10 );
}
free(namelist[0]);
free(v7);
}
else
{
v21 = (void *)xmalloc(12000LL);
cmds_3 = v21;
v22 = commands;
if ( commands )
{
v23 = 1LL;
do
{
*((_QWORD *)v21 + v23 - 1) = strdup(v22);
v2 = v23++;
v22 = (&commands)[3 * v23 - 3];
}
while ( v22 );
}
v24 = getenv("PATH");
ptr = strdup(v24);
v25 = strtok(ptr, ":");
if ( v25 )
{
v32 = 1500;
do
{
v28 = scandir(v25, namelist, 0LL, (int (*)(const struct dirent **, const struct dirent **))&alphasort);
v29 = v28;
if ( v28 >= 0 )
{
if ( v2 + v28 >= v32 )
{
v32 += 2 * v28;
cmds_3 = (void *)xrealloc(cmds_3, 8LL * v32);
}
if ( v29 > 0 )
{
for ( i = 0LL; i != v29; ++i )
{
v27 = (char **)((char *)cmds_3 + 8 * v2 + i * 8);
*v27 = strdup(namelist[0][i]->d_name);
free(namelist[0][i]);
}
v2 += v29;
}
free(namelist[0]);
}
v25 = strtok(0LL, ":");
}
while ( v25 );
}
free(ptr);
v30 = 8LL * v2;
cmds_3 = (void *)xrealloc(cmds_3, v30);
*(_QWORD *)((char *)cmds_3 + v30 - 8) = 0LL;
}
len_2 = strlen(&a1[offset_4]);
}
v12 = cmds_3;
v13 = len_2;
v14 = offset_4;
v15 = &a1[offset_4];
while ( 1 )
{
v16 = (const char *)v12[list_index_5];
if ( !v16 )
break;
++list_index_5;
if ( !strncmp(v16, v15, v13) )
{
v17 = strlen(v16);
v18 = (char *)xcalloc(v14 + v17 + 1, 1LL);
v19 = offset_4;
strncpy(v18, a1, offset_4);
strcpy(&v18[v19], v16);
return v18;
}
}
return (char *)v16;
}

original_code:
char * command_generator (const char *text, int state) {
 static int list_index, len, offset;
 static char **cmds = ((void *)0);
 struct dirent **files = ((void *)0);
 char *name, *tmp, *cwd;
 int i, j, count, n;
 if (!state) {
  list_index = 0;
  offset = 0;
  if (cmds != ((void *)0)) {
   for (i = 0; cmds[i] != ((void *)0); i++)
    free(cmds[i]);
   free(cmds);
  }
  tmp = rindex(text,'/');
  if (tmp != ((void *)0)) {
   offset = tmp-text+1;
   cwd = xcalloc(offset, sizeof(char));
   strncpy(cwd, text, offset-1);
   count = scandir(cwd, &files, file_select, alphasort);
   cmds = (char**)xcalloc(count+1, sizeof(char*));
   for (i = 0; i < count; i++) {
    cmds[i] = strdup(files[i]->d_name);
    free(files[i]);
   }
   free(files);
   free(cwd);
  } else {
   n = 1500;
   cmds = (char**)xmalloc(sizeof(char*)*n);
   for (i = 0; commands[i].name != ((void *)0); i++) {
    cmds[i] = strdup(commands[i].name);
   }
   tmp = strdup(getenv("PATH"));
   cwd = strtok(tmp , ":");
   while( cwd != ((void *)0) ) {
    count = scandir(cwd, &files, 0, alphasort);
    if (count < 0) {
    } else {
     if (count + i >= n) {
      n = n + count*2;
      cmds = xrealloc(cmds, sizeof(char*)*n);
     }
     for (j = 0; j < count; j++) {
      cmds[i++] = strdup(files[j]->d_name);
      free(files[j]);
     }
     free(files);
    }
    cwd = strtok( ((void *)0), ":");
   }
   free(tmp);
   n = i;
   cmds = xrealloc(cmds, sizeof(char*)*n);
   cmds[n-1] = ((void *)0);
  }
  len = strlen (text+offset);
 }
 while (name = cmds[list_index]) {
  list_index++;
  if (strncmp (name, text+offset, len) == 0) {
   tmp = xcalloc(offset+strlen(name)+1, sizeof(char));
   strncpy(tmp, text, offset);
   strcpy(tmp+offset, name);
   return tmp;
  }
 }
 return ((char *)((void *)0));
}

canonical_original_code:
char *command_generator(char *text, int state) {
 static int list_index; static int len; static int offset;
 static char **cmds = ((void *)0);
 struct dirent **files = ((void *)0);
 char *name; char *tmp; char *cwd;
 int i; int j; int count; int n;
 if (!state) {
  list_index = 0;
  offset = 0;
  if (cmds != ((void *)0)) {
   for (i = 0; cmds[i] != ((void *)0); i++)
    free(cmds[i]);
   free(cmds);
  }
  tmp = rindex(text,'/');
  if (tmp != ((void *)0)) {
   offset = tmp-text+1;
   cwd = xcalloc(offset, sizeof(char));
   strncpy(cwd, text, offset-1);
   count = scandir(cwd, &files, file_select, alphasort);
   cmds = (char **)xcalloc(count+1, sizeof(char *));
   for (i = 0; i < count; i++) {
    cmds[i] = strdup(files[i]->d_name);
    free(files[i]);
   }
   free(files);
   free(cwd);
  } else {
   n = 1500;
   cmds = (char **)xmalloc(sizeof(char *)*n);
   for (i = 0; commands[i].name != ((void *)0); i++) {
    cmds[i] = strdup(commands[i].name);
   }
   tmp = strdup(getenv("PATH"));
   cwd = strtok(tmp , ":");
   while( cwd != ((void *)0) ) {
    count = scandir(cwd, &files, 0, alphasort);
    if (count < 0) {
    } else {
     if (count + i >= n) {
      n = n + count*2;
      cmds = xrealloc(cmds, sizeof(char *)*n);
     }
     for (j = 0; j < count; j++) {
      cmds[i++] = strdup(files[j]->d_name);
      free(files[j]);
     }
     free(files);
    }
    cwd = strtok( ((void *)0), ":");
   }
   free(tmp);
   n = i;
   cmds = xrealloc(cmds, sizeof(char *)*n);
   cmds[n-1] = ((void *)0);
  }
  len = strlen (text+offset);
 }
 while (name = cmds[list_index]) {
  list_index++;
  if (strncmp (name, text+offset, len) == 0) {
   tmp = xcalloc(offset+strlen(name)+1, sizeof(char));
   strncpy(tmp, text, offset);
   strcpy(tmp+offset, name);
   return tmp;
  }
 }
 return ((char *)((void *)0));
}

variable_types:
text
char *

variable_types: state int

variable_types: len int

variable_types: offset int

variable_types:
cmds
char **

variable_types: struct dirent { unsigned long d_ino; long d_off; unsigned short d_reclen; unsigned char d_type; char d_name[256]; } **

variable_types:
name
char *

variable_types:
tmp
char *

variable_types:
cwd
char *

variable_types: count int

variable_types: n int


decompiled_code:
char *__fastcall environment_generator(char *s2, int a2)
{
char **v2; // rax
int v3; // ebp
char *i; // rbx
const char *v5; // rbx
char *v6; // r13
__int64 v7; // r14
const char *v8; // rsi

if ( !a2 )
{
list_index_1 = 0;
len_0 = strlen(s2);
}
v2 = environ;
v3 = list_index_1;
for ( i = environ[list_index_1]; i; i = environ[v7] )
{
list_index_1 = v3 + 1;
v5 = v2[v3];
v6 = strchr(v5, 61);
i = (char *)xcalloc(v6 - v5 + 2, 1LL);
v3 = list_index_1;
v7 = list_index_1;
v8 = environ[list_index_1 - 1];
strncpy(i + 1, v8, v6 - v8);
*i = 36;
if ( !strncmp(i, s2, len_0) )
break;
free(i);
v2 = environ;
}
return i;
}

canonical_decompiled_code:
char *__fastcall func2(char *s2, int a2)
{
char **v2; // rax
int v3; // ebp
char *i; // rbx
const char *v5; // rbx
char *v6; // r13
__int64 v7; // r14
const char *v8; // rsi

if ( !a2 )
{
list_index_1 = 0;
len_0 = strlen(s2);
}
v2 = environ;
v3 = list_index_1;
for ( i = environ[list_index_1]; i; i = environ[v7] )
{
list_index_1 = v3 + 1;
v5 = v2[v3];
v6 = strchr(v5, 61);
i = (char *)xcalloc(v6 - v5 + 2, 1LL);
v3 = list_index_1;
v7 = list_index_1;
v8 = environ[list_index_1 - 1];
strncpy(i + 1, v8, v6 - v8);
*i = 36;
if ( !strncmp(i, s2, len_0) )
break;
free(i);
v2 = environ;
}
return i;
}

original_code:
char *environment_generator (const char *text, int state) {
 static int list_index, len, envlen;
 char *tmp, *env;
 if (!state) {
  list_index = 0;
  len = strlen (text);
 }
 while (environ[list_index] != ((void *)0)) {
  list_index++;
  tmp = strstr(environ[list_index-1],"=");
  env = xcalloc(tmp - environ[list_index-1] +2, sizeof(char));
  strncpy(env+1, environ[list_index-1], tmp - environ[list_index-1]);
  *env = '$';
  if (strncmp (env, text, len) == 0)
   return env;
  free(env);
 }
 return ((char *)((void *)0));
}

canonical_original_code:
char *environment_generator(char *text, int state) {
 static int list_index; static int len; static int envlen;
 char *tmp; char *env;
 if (!state) {
  list_index = 0;
  len = strlen (text);
 }
 while (environ[list_index] != ((void *)0)) {
  list_index++;
  tmp = strstr(environ[list_index-1],"=");
  env = xcalloc(tmp - environ[list_index-1] +2, sizeof(char));
  strncpy(env+1, environ[list_index-1], tmp - environ[list_index-1]);
  *env = '$';
  if (strncmp (env, text, len) == 0)
   return env;
  free(env);
 }
 return ((char *)((void *)0));
}

variable_types: envlen int

variable_types:
env
char *


decompiled_code:
__int64 __fastcall command_completion(_BYTE *a1, int a2, int a3)
{
__int64 v3; // rax
__int64 result; // rax

v3 = charrpos(rl_line_buffer, "|`", (unsigned int)(a3 - a2));
if ( !a2 || v3 )
{
rl_completion_append_character = 32;
result = rl_completion_matches(a1, command_generator);
}
else
{
result = 0LL;
if ( *a1 == 36 )
{
rl_completion_append_character = 32;
result = rl_completion_matches(a1, environment_generator);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(_BYTE *a1, int a2, int a3)
{
__int64 v3; // rax
__int64 result; // rax

v3 = charrpos(rl_line_buffer, "|`", (unsigned int)(a3 - a2));
if ( !a2 || v3 )
{
rl_completion_append_character = 32;
result = rl_completion_matches(a1, command_generator);
}
else
{
result = 0LL;
if ( *a1 == 36 )
{
rl_completion_append_character = 32;
result = rl_completion_matches(a1, environment_generator);
}
}
return result;
}

original_code:
char **command_completion(const char *text, int start, int stop) {
 char **matches = ((void *)0), *cmdSplit;
     cmdSplit = charrpos(rl_line_buffer, "|`", stop-start);
    if (start == 0 || cmdSplit) {
        rl_completion_append_character = ' ';
        matches = rl_completion_matches(text, command_generator);
    } else if (*text == '$') {
        rl_completion_append_character = ' ';
        matches = rl_completion_matches(text, environment_generator);
    }
    return (matches);
}

canonical_original_code:
char **command_completion(char *text, int start, int stop) {
 char **matches = ((void *)0); char *cmdSplit;
     cmdSplit = charrpos(rl_line_buffer, "|`", stop-start);
    if (start == 0 || cmdSplit) {
        rl_completion_append_character = ' ';
        matches = rl_completion_matches(text, command_generator);
    } else if (*text == '$') {
        rl_completion_append_character = ' ';
        matches = rl_completion_matches(text, environment_generator);
    }
    return (matches);
}

variable_types: start int

variable_types: stop int

variable_types:
matches
char **

variable_types:
cmdSplit
char *

return_type: char **