ConvertTimeStringNew

decompiled_code:
double __fastcall ConvertTimeStringNew(char *nptr)
{
int v2; // er12
const unsigned __int16 *v3; // rcx
char *v4; // rbx
double result; // xmm0_8
struct tm *v6; // rax
const char *v7; // r13
char *v8; // r14
int v9; // ebp
int v10; // ebx
int v11; // er13
time_t timer; // [rsp+8h] [rbp-80h] BYREF
struct tm tp; // [rsp+10h] [rbp-78h] BYREF
int v14; // [rsp+54h] [rbp-34h] BYREF
int v15; // [rsp+58h] [rbp-30h] BYREF
int v16[11]; // [rsp+5Ch] [rbp-2Ch] BYREF

v2 = 0;
if ( DST == 1 )
{
timer = time(0LL);
v6 = localtime(&timer);
if ( v6 )
v2 = v6->tm_isdst;
}
do
{
if ( !iswspace(*nptr) )
break;
++nptr;
}
while ( *nptr );
v3 = *__ctype_b_loc();
v4 = nptr;
while ( (v3[*v4] & 0x800) != 0 )
{
if ( !*++v4 )
return -1.0;
}
result = -1.0;
if ( *v4 == 45 )
{
do
{
if ( !*++v4 )
return -1.0;
}
while ( *v4 == 45 );
v7 = v4;
while ( (v3[*v7] & 0x800) != 0 )
{
if ( !*++v7 )
return -1.0;
}
result = -1.0;
if ( *v7 == 45 )
{
do
{
if ( !*++v7 )
return -1.0;
}
while ( *v7 == 45 );
v8 = (char *)v7;
while ( (v3[*v8] & 0x800) != 0 )
{
if ( !*++v8 )
return -1.0;
}
result = -1.0;
if ( *v8 == 32 )
{
while ( iswspace(*v8) )
{
if ( !*++v8 )
return -1.0;
}
v9 = atoi(nptr);
v10 = atoi(v4);
v11 = atoi(v7);
result = -1.0;
if ( (int)ConvertTime(v8, v16, &v15, &v14) >= 0 )
{
tp.tm_yday = 0;
*(&tp.tm_isdst + 1) = 0;
tp.tm_gmtoff = 0LL;
tp.tm_zone = 0LL;
tp.tm_sec = v14;
tp.tm_min = v15;
tp.tm_hour = v16[0];
tp.tm_mday = v11;
tp.tm_mon = v10 - 1;
*(_QWORD *)&tp.tm_year = (unsigned int)(v9 - 1900);
tp.tm_isdst = v2;
result = (double)(int)mktime(&tp);
}
}
}
}
return result;
}

canonical_decompiled_code:
double __fastcall func11(char *nptr)
{
int v2; // er12
const unsigned __int16 *v3; // rcx
char *v4; // rbx
double result; // xmm0_8
struct tm *v6; // rax
const char *v7; // r13
char *v8; // r14
int v9; // ebp
int v10; // ebx
int v11; // er13
time_t timer; // [rsp+8h] [rbp-80h] BYREF
struct tm tp; // [rsp+10h] [rbp-78h] BYREF
int v14; // [rsp+54h] [rbp-34h] BYREF
int v15; // [rsp+58h] [rbp-30h] BYREF
int v16[11]; // [rsp+5Ch] [rbp-2Ch] BYREF

v2 = 0;
if ( DST == 1 )
{
timer = time(0LL);
v6 = localtime(&timer);
if ( v6 )
v2 = v6->tm_isdst;
}
do
{
if ( !iswspace(*nptr) )
break;
++nptr;
}
while ( *nptr );
v3 = *__ctype_b_loc();
v4 = nptr;
while ( (v3[*v4] & 0x800) != 0 )
{
if ( !*++v4 )
return -1.0;
}
result = -1.0;
if ( *v4 == 45 )
{
do
{
if ( !*++v4 )
return -1.0;
}
while ( *v4 == 45 );
v7 = v4;
while ( (v3[*v7] & 0x800) != 0 )
{
if ( !*++v7 )
return -1.0;
}
result = -1.0;
if ( *v7 == 45 )
{
do
{
if ( !*++v7 )
return -1.0;
}
while ( *v7 == 45 );
v8 = (char *)v7;
while ( (v3[*v8] & 0x800) != 0 )
{
if ( !*++v8 )
return -1.0;
}
result = -1.0;
if ( *v8 == 32 )
{
while ( iswspace(*v8) )
{
if ( !*++v8 )
return -1.0;
}
v9 = atoi(nptr);
v10 = atoi(v4);
v11 = atoi(v7);
result = -1.0;
if ( (int)func9(v8, v16, &v15, &v14) >= 0 )
{
tp.tm_yday = 0;
*(&tp.tm_isdst + 1) = 0;
tp.tm_gmtoff = 0LL;
tp.tm_zone = 0LL;
tp.tm_sec = v14;
tp.tm_min = v15;
tp.tm_hour = v16[0];
tp.tm_mday = v11;
tp.tm_mon = v10 - 1;
*(_QWORD *)&tp.tm_year = (unsigned int)(v9 - 1900);
tp.tm_isdst = v2;
result = (double)(int)mktime(&tp);
}
}
}
}
return result;
}

original_code:
double ConvertTimeStringNew(char *ts)
{
 int day;
 int mon;
 int date;
 int hour;
 int min;
 int sec;
 int year;
 int err;
 struct tm t;
 struct tm *now;
 time_t utc;
 double ret;
 char *curr;
 time_t tval;
 int dst;
 if(DST == 1) {
  tval = time(((void *)0));
  now = localtime(&tval);
  if(now != ((void *)0)) {
   dst = now->tm_isdst;
  } else {
   dst = 0;
  }
 } else {
  dst = 0;
 }
 curr = ts;
 while(iswspace(*curr))
 {
  curr++;
  if(*curr == 0)
  {
   break;
  }
 }
 year = atoi(curr);
 while(((*__ctype_b_loc ())[(int) ((*curr))] & (unsigned short int) _ISdigit))
 {
  curr++;
  if(*curr == 0)
  {
   return(-1.0);
  }
 }
 if(*curr != '-') {
  return(-1.0);
 }
 while(*curr == '-')
 {
  curr++;
  if(*curr == 0)
  {
   return(-1.0);
  }
 }
 mon = atoi(curr) - 1;
 while(((*__ctype_b_loc ())[(int) ((*curr))] & (unsigned short int) _ISdigit))
 {
  curr++;
  if(*curr == 0)
  {
   return(-1.0);
  }
 }
 if(*curr != '-') {
  return(-1.0);
 }
 while(*curr == '-')
 {
  curr++;
  if(*curr == 0)
  {
   return(-1.0);
  }
 }
 date = atoi(curr);
 while(((*__ctype_b_loc ())[(int) ((*curr))] & (unsigned short int) _ISdigit))
 {
  curr++;
  if(*curr == 0)
  {
   return(-1.0);
  }
 }
 if(*curr != ' ') {
  return(-1.0);
 }
 while(iswspace(*curr))
 {
  curr++;
  if(*curr == 0)
  {
   return(-1.0);
  }
 }
 err = ConvertTime(curr,&hour,&min,&sec);
 if(err < 0)
 {
  return(-1.0);
 }
 memset(&t,0,sizeof(t));
 t.tm_sec = sec;
 t.tm_min = min;
 t.tm_hour = hour;
 t.tm_mday = date;
 t.tm_mon = mon;
 t.tm_year = year - 1900;
 t.tm_wday = day;
 t.tm_isdst = dst;
 utc = mktime(&t);
 ret = (double)utc;
 return(ret);
}

canonical_original_code:
double ConvertTimeStringNew(char *ts)
{
 int day;
 int mon;
 int date;
 int hour;
 int min;
 int sec;
 int year;
 int err;
 struct tm t;
 struct tm *now;
 long utc;
 double ret;
 char *curr;
 long tval;
 int dst;
 if(DST == 1) {
  tval = time(((void *)0));
  now = localtime(&tval);
  if(now != ((void *)0)) {
   dst = now->tm_isdst;
  } else {
   dst = 0;
  }
 } else {
  dst = 0;
 }
 curr = ts;
 while(iswspace(*curr))
 {
  curr++;
  if(*curr == 0)
  {
   break;
  }
 }
 year = atoi(curr);
 while(((*__ctype_b_loc ())[(int) ((*curr))] & (unsigned short) _ISdigit))
 {
  curr++;
  if(*curr == 0)
  {
   return(-1.0);
  }
 }
 if(*curr != '-') {
  return(-1.0);
 }
 while(*curr == '-')
 {
  curr++;
  if(*curr == 0)
  {
   return(-1.0);
  }
 }
 mon = atoi(curr) - 1;
 while(((*__ctype_b_loc ())[(int) ((*curr))] & (unsigned short) _ISdigit))
 {
  curr++;
  if(*curr == 0)
  {
   return(-1.0);
  }
 }
 if(*curr != '-') {
  return(-1.0);
 }
 while(*curr == '-')
 {
  curr++;
  if(*curr == 0)
  {
   return(-1.0);
  }
 }
 date = atoi(curr);
 while(((*__ctype_b_loc ())[(int) ((*curr))] & (unsigned short) _ISdigit))
 {
  curr++;
  if(*curr == 0)
  {
   return(-1.0);
  }
 }
 if(*curr != ' ') {
  return(-1.0);
 }
 while(iswspace(*curr))
 {
  curr++;
  if(*curr == 0)
  {
   return(-1.0);
  }
 }
 err = ConvertTime(curr,&hour,&min,&sec);
 if(err < 0)
 {
  return(-1.0);
 }
 memset(&t,0,sizeof(t));
 t.tm_sec = sec;
 t.tm_min = min;
 t.tm_hour = hour;
 t.tm_mday = date;
 t.tm_mon = mon;
 t.tm_year = year - 1900;
 t.tm_wday = day;
 t.tm_isdst = dst;
 utc = mktime(&t);
 ret = (double)utc;
 return(ret);
}

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

variable_types:
curr
char *

variable_types: tval long

variable_types: dst int


DlistNodeInit

repo: richwolski/euca-cutils

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

result = malloc(0x18uLL);
if ( result )
{
*result = 0LL;
result[1] = 0LL;
result[2] = 0LL;
}
return result;
}

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

result = malloc(0x18uLL);
if ( result )
{
*result = 0LL;
result[1] = 0LL;
result[2] = 0LL;
}
return result;
}

original_code:
DlistNode *DlistNodeInit()
{
 DlistNode *dn;
 dn = (DlistNode *)malloc(sizeof(DlistNode));
 if(dn == ((void *)0))
 {
  return(((void *)0));
 }
 memset(dn,0,sizeof(DlistNode));
 return(dn);
}

canonical_original_code:
struct dlist_node_stc *DlistNodeInit()
{
 struct dlist_node_stc *dn;
 dn = (struct dlist_node_stc *)malloc(sizeof(DlistNode));
 if(dn == ((void *)0))
 {
  return(((void *)0));
 }
 memset(dn,0,sizeof(DlistNode));
 return(dn);
}

variable_types: struct dlist_node_stc { struct dlist_node_stc *next; struct dlist_node_stc *prev; union hval_un { int i; long i64; double d; void *v; char *s; unsigned long l; } value; } *

user_defined_types: struct dlist_node_stc { struct dlist_node_stc *next; struct dlist_node_stc *prev; union hval_un value; }


DlistNodeFree

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

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

original_code:
void DlistNodeFree(DlistNode *dn)
{
 free(dn);
}

canonical_original_code:
void DlistNodeFree(struct dlist_node_stc *dn)
{
 free(dn);
}

return_type: void

user_defined_types: union hval_un { int i; long i64; double d; void *v; char *s; unsigned long l; }


DlistInit

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

result = malloc(0x18uLL);
if ( result )
{
*result = 0LL;
result[1] = 0LL;
result[2] = 0LL;
}
return result;
}

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

result = malloc(0x18uLL);
if ( result )
{
*result = 0LL;
result[1] = 0LL;
result[2] = 0LL;
}
return result;
}

original_code:
Dlist *DlistInit()
{
 Dlist *dl;
 dl = (Dlist *)malloc(sizeof(Dlist));
 if(dl == ((void *)0))
 {
  return(((void *)0));
 }
 memset(dl,0,sizeof(Dlist));
 return(dl);
}

canonical_original_code:
struct dlist_stc *DlistInit()
{
 struct dlist_stc *dl;
 dl = (struct dlist_stc *)malloc(sizeof(Dlist));
 if(dl == ((void *)0))
 {
  return(((void *)0));
 }
 memset(dl,0,sizeof(Dlist));
 return(dl);
}

variable_types: struct dlist_stc { struct dlist_node_stc { struct dlist_node_stc *next; struct dlist_node_stc *prev; union hval_un { int i; long i64; double d; void *v; char *s; unsigned long l; } value; } *first; struct dlist_node_stc *last; int count; } *

user_defined_types: struct dlist_stc { struct dlist_node_stc *first; struct dlist_node_stc *last; int count; }


DlistRemove

decompiled_code:
void __fastcall DlistRemove(void *ptr)
{
_QWORD *v2; // rdi
_QWORD *v3; // rbx
void *v4; // rdi

v2 = *(_QWORD **)ptr;
if ( v2 )
{
v3 = (_QWORD *)*v2;
free(v2);
while ( v3 )
{
v4 = v3;
v3 = (_QWORD *)*v3;
free(v4);
}
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func3(void *ptr)
{
_QWORD *v2; // rdi
_QWORD *v3; // rbx
void *v4; // rdi

v2 = *(_QWORD **)ptr;
if ( v2 )
{
v3 = (_QWORD *)*v2;
free(v2);
while ( v3 )
{
v4 = v3;
v3 = (_QWORD *)*v3;
free(v4);
}
}
free(ptr);
}

original_code:
void DlistRemove(Dlist *dl)
{
 DlistNode *dn;
 DlistNode *curr;
 dn = dl->first;
 if(dn != ((void *)0))
 {
  curr = dn->next;
  free(dn);
  while(curr != ((void *)0))
  {
   dn = curr;
   curr = curr->next;
   free(dn);
  }
 }
 free(dl);
}

canonical_original_code:
void DlistRemove(struct dlist_stc *dl)
{
 struct dlist_node_stc *dn;
 struct dlist_node_stc *curr;
 dn = dl->first;
 if(dn != ((void *)0))
 {
  curr = dn->next;
  free(dn);
  while(curr != ((void *)0))
  {
   dn = curr;
   curr = curr->next;
   free(dn);
  }
 }
 free(dl);
}


DlistDelete

original_code:
void DlistDelete(Dlist *dl, DlistNode *dn)
{
 if(dl->count == 0)
 {
  return;
 }
 if(dl->first == dn)
 {
  dl->first = dl->first->next;
  if(dl->first)
  {
   dl->first->prev = ((void *)0);
  }
 }
 else if(dl->last == dn)
 {
  dl->last = dl->last->prev;
  if(dl->last)
  {
   dl->last->next = ((void *)0);
  }
 }
 else
 {
  dn->next->prev = dn->prev;
  dn->prev->next = dn->next;
 }
 dl->count--;
 return;
}

canonical_original_code:
void DlistDelete(struct dlist_stc *dl, struct dlist_node_stc *dn)
{
 if(dl->count == 0)
 {
  return;
 }
 if(dl->first == dn)
 {
  dl->first = dl->first->next;
  if(dl->first)
  {
   dl->first->prev = ((void *)0);
  }
 }
 else if(dl->last == dn)
 {
  dl->last = dl->last->prev;
  if(dl->last)
  {
   dl->last->next = ((void *)0);
  }
 }
 else
 {
  dn->next->prev = dn->prev;
  dn->prev->next = dn->next;
 }
 dl->count--;
 return;
}

variable_types:
dn
struct dlist_node_stc *


InitTXL

decompiled_code:
_QWORD *InitTXL()
{
_QWORD *v0; // rax
_QWORD *v1; // rbx
__int64 v2; // rbp
__int64 v3; // rbp

v0 = malloc(0x18uLL);
v1 = v0;
if ( v0 )
{
*v0 = 0LL;
v0[1] = 0LL;
v0[2] = 0LL;
v2 = DlistInit();
v1[1] = v2;
if ( v2 )
{
v3 = RBInitS();
v1[2] = v3;
if ( !v3 )
{
DlistRemove(v1[1]);
free(v1);
v1 = 0LL;
}
}
else
{
free(v1);
v1 = 0LL;
}
}
return v1;
}

canonical_decompiled_code:
_QWORD *func0()
{
_QWORD *v0; // rax
_QWORD *v1; // rbx
__int64 v2; // rbp
__int64 v3; // rbp

v0 = malloc(0x18uLL);
v1 = v0;
if ( v0 )
{
*v0 = 0LL;
v0[1] = 0LL;
v0[2] = 0LL;
v2 = DlistInit();
v1[1] = v2;
if ( v2 )
{
v3 = RBInitS();
v1[2] = v3;
if ( !v3 )
{
DlistRemove(v1[1]);
free(v1);
v1 = 0LL;
}
}
else
{
free(v1);
v1 = 0LL;
}
}
return v1;
}

original_code:
TXL *InitTXL()
{
 TXL *tl;
 tl = (TXL *)malloc(sizeof(TXL));
 if(tl == ((void *)0)) {
  return(((void *)0));
 }
 memset(tl,0,sizeof(TXL));
 tl->list = DlistInit();
 if(tl->list == ((void *)0)) {
  free(tl);
  return(((void *)0));
 }
 tl->index = RBInitS();
 if(tl->index == ((void *)0)) {
  DlistRemove(tl->list);
  free(tl);
  return(((void *)0));
 }
 return(tl);
}

canonical_original_code:
struct text_list_stc *InitTXL()
{
 struct text_list_stc *tl;
 tl = (struct text_list_stc *)malloc(sizeof(TXL));
 if(tl == ((void *)0)) {
  return(((void *)0));
 }
 memset(tl,0,sizeof(TXL));
 tl->list = DlistInit();
 if(tl->list == ((void *)0)) {
  free(tl);
  return(((void *)0));
 }
 tl->index = RBInitS();
 if(tl->index == ((void *)0)) {
  DlistRemove(tl->list);
  free(tl);
  return(((void *)0));
 }
 return(tl);
}

variable_types: struct text_list_stc { int count; struct dlist_stc { struct dlist_node_stc { struct dlist_node_stc *next; struct dlist_node_stc *prev; union hval_un { int i; long i64; double d; void *v; char *s; unsigned long l; } value; } *first; struct dlist_node_stc *last; int count; } *list; struct rb_stc { unsigned char color; struct rb_stc *left; struct rb_stc *right; struct rb_stc *parent; struct rb_stc *prev; struct rb_stc *next; struct key_type_stc { unsigned char type; union hval_un key; } key; union hval_un value; } *index; } *

user_defined_types: struct text_list_stc { int count; struct dlist_stc *list; struct rb_stc *index; }

user_defined_types: struct rb_stc { unsigned char color; struct rb_stc *left; struct rb_stc *right; struct rb_stc *parent; struct rb_stc *prev; struct rb_stc *next; struct key_type_stc key; union hval_un value; }


DestroyTXL

decompiled_code:
void __fastcall DestroyTXL(void *ptr)
{
_QWORD *v2; // rax
_QWORD *v3; // rbx
void *v4; // rdi

v2 = (_QWORD *)*((_QWORD *)ptr + 1);
if ( v2 )
{
v3 = (_QWORD *)*v2;
if ( *v2 )
{
do
{
v4 = (void *)v3[2];
if ( v4 )
free(v4);
v3 = (_QWORD *)*v3;
}
while ( v3 );
}
DlistRemove(*((_QWORD *)ptr + 1));
}
if ( *((_QWORD *)ptr + 2) )
RBDestroyS();
free(ptr);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
_QWORD *v2; // rax
_QWORD *v3; // rbx
void *v4; // rdi

v2 = (_QWORD *)*((_QWORD *)ptr + 1);
if ( v2 )
{
v3 = (_QWORD *)*v2;
if ( *v2 )
{
do
{
v4 = (void *)v3[2];
if ( v4 )
free(v4);
v3 = (_QWORD *)*v3;
}
while ( v3 );
}
DlistRemove(*((_QWORD *)ptr + 1));
}
if ( *((_QWORD *)ptr + 2) )
RBDestroyS();
free(ptr);
}

original_code:
void DestroyTXL(TXL *tl)
{
 DlistNode *dl;
 char *s;
 if(tl->list != ((void *)0)) {
  for((dl)=(tl->list)->first; (dl)!=((void *)0); (dl) = (dl)->next)
  {
   s = dl->value.s;
   if(s != ((void *)0)) {
    free(s);
   }
  }
  DlistRemove(tl->list);
 }
 if(tl->index != ((void *)0)) {
  RBDestroyS(tl->index);
 }
 free(tl);
 return;
}

canonical_original_code:
void DestroyTXL(struct text_list_stc *tl)
{
 struct dlist_node_stc *dl;
 char *s;
 if(tl->list != ((void *)0)) {
  for((dl)=(tl->list)->first; (dl)!=((void *)0); (dl) = (dl)->next)
  {
   s = dl->value.s;
   if(s != ((void *)0)) {
    free(s);
   }
  }
  DlistRemove(tl->list);
 }
 if(tl->index != ((void *)0)) {
  RBDestroyS(tl->index);
 }
 free(tl);
 return;
}

variable_types:
s
char *

user_defined_types: struct key_type_stc { unsigned char type; union hval_un key; }


AppendWordTXL

decompiled_code:
__int64 __fastcall AppendWordTXL(__int64 a1, const char *a2)
{
__int64 result; // rax
size_t v3; // rax
void *v4; // r12
size_t v5; // rax
__int64 v6; // r13

result = 1LL;
if ( a2 )
{
v3 = strlen(a2);
v4 = malloc(v3 + 1);
if ( v4 )
{
v5 = strlen(a2);
memset(v4, 0, v5 + 1);
strcpy((char *)v4, a2);
v6 = DlistAppend(*(_QWORD *)(a1 + 8), v4);
if ( v6 )
{
if ( !RBFindS(*(_QWORD *)(a1 + 16), a2) )
RBInsertS(*(_QWORD *)(a1 + 16), v4, v6);
++*(_DWORD *)a1;
result = 1LL;
}
else
{
free(v4);
result = 0LL;
}
}
else
{
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, const char *a2)
{
__int64 result; // rax
size_t v3; // rax
void *v4; // r12
size_t v5; // rax
__int64 v6; // r13

result = 1LL;
if ( a2 )
{
v3 = strlen(a2);
v4 = malloc(v3 + 1);
if ( v4 )
{
v5 = strlen(a2);
memset(v4, 0, v5 + 1);
strcpy((char *)v4, a2);
v6 = DlistAppend(*(_QWORD *)(a1 + 8), v4);
if ( v6 )
{
if ( !RBFindS(*(_QWORD *)(a1 + 16), a2) )
RBInsertS(*(_QWORD *)(a1 + 16), v4, v6);
++*(_DWORD *)a1;
result = 1LL;
}
else
{
free(v4);
result = 0LL;
}
}
else
{
result = 0LL;
}
}
return result;
}

original_code:
int AppendWordTXL(TXL *tl, char *word)
{
 char *local_word;
 DlistNode *dn;
 RB *rb;
 if(word == ((void *)0)) {
  return(1);
 }
 local_word = (char *)malloc(strlen(word) + 1);
 if(local_word == ((void *)0)) {
  return(0);
 }
 memset(local_word,0,strlen(word)+1);
 strcpy(local_word,word);
 dn = DlistAppend(tl->list,(Hval)local_word);
 if(dn == ((void *)0)) {
  free(local_word);
  return(0);
 }
 rb = RBFindS(tl->index,word);
 if(rb == ((void *)0)) {
  RBInsertS(tl->index,local_word,(Hval)(void *)dn);
 }
 tl->count++;
 return(1);
}

canonical_original_code:
int AppendWordTXL(struct text_list_stc *tl, char *word)
{
 char *local_word;
 struct dlist_node_stc *dn;
 struct rb_stc *rb;
 if(word == ((void *)0)) {
  return(1);
 }
 local_word = (char *)malloc(strlen(word) + 1);
 if(local_word == ((void *)0)) {
  return(0);
 }
 memset(local_word,0,strlen(word)+1);
 strcpy(local_word,word);
 dn = DlistAppend(tl->list,(union hval_un)local_word);
 if(dn == ((void *)0)) {
  free(local_word);
  return(0);
 }
 rb = RBFindS(tl->index,word);
 if(rb == ((void *)0)) {
  RBInsertS(tl->index,local_word,(union hval_un)(void *)dn);
 }
 tl->count++;
 return(1);
}

variable_types:
word
char *

variable_types: struct rb_stc { unsigned char color; struct rb_stc *left; struct rb_stc *right; struct rb_stc *parent; struct rb_stc *prev; struct rb_stc *next; struct key_type_stc { unsigned char type; union hval_un { int i; long i64; double d; void *v; char *s; unsigned long l; } key; } key; union hval_un value; } *

return_type: int


FindWord

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

result = RBFindS(*(_QWORD *)(a1 + 16), a2);
if ( result )
result = *(_QWORD *)(result + 64);
return result;
}

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

result = RBFindS(*(_QWORD *)(a1 + 16), a2);
if ( result )
result = *(_QWORD *)(result + 64);
return result;
}

original_code:
DlistNode *FindWord(TXL *tl, char *word)
{
 RB *rb;
 rb = RBFindS(tl->index,word);
 if(rb != ((void *)0)) {
  return((DlistNode *)(rb->value.v));
 } else {
  return(((void *)0));
 }
}

canonical_original_code:
struct dlist_node_stc *FindWord(struct text_list_stc *tl, char *word)
{
 struct rb_stc *rb;
 rb = RBFindS(tl->index,word);
 if(rb != ((void *)0)) {
  return((struct dlist_node_stc *)(rb->value.v));
 } else {
  return(((void *)0));
 }
}

variable_types: struct text_list_stc { int count; struct dlist_stc { struct dlist_node_stc *first; struct dlist_node_stc *last; int count; } *list; struct rb_stc { unsigned char color; struct rb_stc *left; struct rb_stc *right; struct rb_stc *parent; struct rb_stc *prev; struct rb_stc *next; struct key_type_stc { unsigned char type; union hval_un key; } key; union hval_un value; } *index; } *

return_type: struct dlist_node_stc { struct dlist_node_stc *next; struct dlist_node_stc *prev; union hval_un { int i; long i64; double d; void *v; char *s; unsigned long l; } value; } *


FindSubStr

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

v2 = DlistInit();
if ( v2 )
{
for ( i = **(__int64 ***)(a1 + 8); i; i = (__int64 *)*i )
{
if ( strstr((const char *)i[2], a2) )
DlistAppend(v2, i);
}
}
return v2;
}

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

v2 = DlistInit();
if ( v2 )
{
for ( i = **(__int64 ***)(a1 + 8); i; i = (__int64 *)*i )
{
if ( strstr((const char *)i[2], a2) )
DlistAppend(v2, i);
}
}
return v2;
}

original_code:
Dlist *FindSubStr(TXL *tl, char *str)
{
 Dlist *sslist;
 DlistNode *curr;
 char *found;
 sslist = DlistInit();
 if(sslist == ((void *)0)) {
  return(((void *)0));
 }
 for((curr)=(tl->list)->first; (curr)!=((void *)0); (curr) = (curr)->next)
 {
  found = strstr(curr->value.s,str);
  if(found != ((void *)0)) {
   DlistAppend(sslist,(Hval)(void *)curr);
  }
 }
 return(sslist);
}

canonical_original_code:
struct dlist_stc *FindSubStr(struct text_list_stc *tl, char *str)
{
 struct dlist_stc *sslist;
 struct dlist_node_stc *curr;
 char *found;
 sslist = DlistInit();
 if(sslist == ((void *)0)) {
  return(((void *)0));
 }
 for((curr)=(tl->list)->first; (curr)!=((void *)0); (curr) = (curr)->next)
 {
  found = strstr(curr->value.s,str);
  if(found != ((void *)0)) {
   DlistAppend(sslist,(union hval_un)(void *)curr);
  }
 }
 return(sslist);
}

variable_types: struct text_list_stc { int count; struct dlist_stc *list; struct rb_stc { unsigned char color; struct rb_stc *left; struct rb_stc *right; struct rb_stc *parent; struct rb_stc *prev; struct rb_stc *next; struct key_type_stc { unsigned char type; union hval_un key; } key; union hval_un value; } *index; } *

variable_types:
str
char *

variable_types:
found
char *

return_type: struct dlist_stc { struct dlist_node_stc { struct dlist_node_stc *next; struct dlist_node_stc *prev; union hval_un { int i; long i64; double d; void *v; char *s; unsigned long l; } value; } *first; struct dlist_node_stc *last; int count; } *


IsInStr

decompiled_code:
__int64 __fastcall IsInStr(const char *a1, char a2)
{
size_t v3; // rdi
const char *v4; // rax
const char *v5; // rdi

v3 = strlen(a1);
v4 = a1;
v5 = &a1[v3];
while ( v4 != v5 )
{
if ( *v4++ == a2 )
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(const char *a1, char a2)
{
size_t v3; // rdi
const char *v4; // rax
const char *v5; // rdi

v3 = strlen(a1);
v4 = a1;
v5 = &a1[v3];
while ( v4 != v5 )
{
if ( *v4++ == a2 )
return 1LL;
}
return 0LL;
}

original_code:
int IsInStr(char *str, char c)
{
 int i;
 for(i=0; i < strlen(str); i++)
 {
  if(str[i] == c) {
   return(1);
  }
 }
 return(0);
}

variable_types: c char

variable_types: i int


GetNextWord

decompiled_code:
const char *__fastcall GetNextWord(const char *a1, const char *a2, const char **a3)
{
__int64 v4; // r12
int v5; // er14
const char *v6; // rbp
char *v7; // r13
int v8; // er15
char v9; // si
char *v10; // rax
__int64 v11; // rax
__int64 v14; // [rsp+8h] [rbp-40h]

*a3 = 0LL;
if ( !a1 )
return 0LL;
if ( !(unsigned int)strlen(a1) )
return 0LL;
v4 = 0LL;
while ( 1 )
{
v5 = v4;
if ( !(unsigned int)IsInStr(a2, a1[v4]) )
break;
if ( !a1[++v4] )
return 0LL;
}
v14 = (int)v4;
v7 = (char *)&a1[(int)v4 + 1];
do
{
v8 = v4;
LODWORD(v4) = v4 + 1;
v9 = *v7;
if ( !*v7 )
break;
++v7;
}
while ( !(unsigned int)IsInStr(a2, v9) );
v10 = (char *)malloc((int)v4 - v5 + 1);
v6 = v10;
if ( v10 )
{
memset(v10, 0, (int)v4 - v5 + 1);
if ( v5 < (int)v4 )
{
v11 = v14;
do
{
v6[v11 - v14] = a1[v11];
++v11;
}
while ( v8 > (int)v11 - 1 );
}
*a3 = v6;
v6 = &a1[(int)v4];
if ( !*v6 )
v6 = 0LL;
}
return v6;
}

canonical_decompiled_code:
const char *__fastcall func6(const char *a1, const char *a2, const char **a3)
{
__int64 v4; // r12
int v5; // er14
const char *v6; // rbp
char *v7; // r13
int v8; // er15
char v9; // si
char *v10; // rax
__int64 v11; // rax
__int64 v14; // [rsp+8h] [rbp-40h]

*a3 = 0LL;
if ( !a1 )
return 0LL;
if ( !(unsigned int)strlen(a1) )
return 0LL;
v4 = 0LL;
while ( 1 )
{
v5 = v4;
if ( !(unsigned int)func5(a2, a1[v4]) )
break;
if ( !a1[++v4] )
return 0LL;
}
v14 = (int)v4;
v7 = (char *)&a1[(int)v4 + 1];
do
{
v8 = v4;
LODWORD(v4) = v4 + 1;
v9 = *v7;
if ( !*v7 )
break;
++v7;
}
while ( !(unsigned int)func5(a2, v9) );
v10 = (char *)malloc((int)v4 - v5 + 1);
v6 = v10;
if ( v10 )
{
memset(v10, 0, (int)v4 - v5 + 1);
if ( v5 < (int)v4 )
{
v11 = v14;
do
{
v6[v11 - v14] = a1[v11];
++v11;
}
while ( v8 > (int)v11 - 1 );
}
*a3 = v6;
v6 = &a1[(int)v4];
if ( !*v6 )
v6 = 0LL;
}
return v6;
}

original_code:
char *GetNextWord(char *line, char *separators, char **out_word)
{
 char *word;
 int len;
 int i;
 int j;
 int k;
 int l;
 int size;
 char *curr;
 char *where;
 *out_word = ((void *)0);
 if(line == ((void *)0)) {
  return(((void *)0));
 }
 len = strlen(line);
 if(len == 0) {
  return(((void *)0));
 }
 size = 0;
 i = 0;
 while(IsInStr(separators,line[i]))
 {
  i++;
  if(line[i] == 0) {
   return(((void *)0));
  }
 }
 j = i;
 while(!IsInStr(separators,line[j]))
 {
  j++;
  if(line[j] == 0) {
   break;
  }
 }
 word = (char *)malloc((j - i) + 1);
 if(word == ((void *)0)) {
  return(((void *)0));
 }
 memset(word,0,(j-i)+1);
 l = 0;
 for(k=i,l=0; k < j; k++,l++)
 {
  word[l] = line[k];
 }
 *out_word = word;
 if(line[j] != 0) {
  where = &(line[j]);
 } else {
  where = ((void *)0);
 }
 return(where);
}

variable_types:
line
char *

variable_types:
separators
char *

variable_types: len int

variable_types: j int

variable_types: k int

variable_types: l int

variable_types: size int

variable_types:
where
char *

return_type: char *


Pareto

repo: richwolski/pareto

decompiled_code:
double __fastcall Pareto(double a1, double a2, double a3)
{
double v4; // r14

v4 = pow(a3, a2);
return v4 * a2 / pow(a1, a2 + 1.0);
}

canonical_decompiled_code:
double __fastcall func0(double a1, double a2, double a3)
{
double v4; // r14

v4 = pow(a3, a2);
return v4 * a2 / pow(a1, a2 + 1.0);
}

original_code:
double
Pareto(double y, double a, double b)
{
        double temp;
 temp = (a * pow(b,a)) / pow(y,(a+1.0));
        return(temp);
}

variable_types: y double

variable_types: a double

variable_types: b double

variable_types: temp double

return_type: double


InvertedParetoCDF

decompiled_code:
double __fastcall InvertedParetoCDF(double a1, double a2, double a3)
{
return a3 / pow(1.0 - a1, 1.0 / a2);
}

canonical_decompiled_code:
double __fastcall func1(double a1, double a2, double a3)
{
return a3 / pow(1.0 - a1, 1.0 / a2);
}

original_code:
double InvertedParetoCDF(double y, double a, double b)
{
 return(b / pow((1-y),1.0/a));
}


trans

decompiled_code:
const char *__fastcall trans(const char *a1)
{
const char *result; // rax
int v2; // edx

result = (const char *)strlen(a1);
if ( (int)result > 0 )
{
v2 = (int)result;
result = a1;
do
{
if ( (unsigned __int8)(*result - 97) <= 0x19u )
*result -= 32;
++result;
}
while ( result != &a1[v2 - 1 + 1] );
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func7(const char *a1)
{
const char *result; // rax
int v2; // edx

result = (const char *)strlen(a1);
if ( (int)result > 0 )
{
v2 = (int)result;
result = a1;
do
{
if ( (unsigned __int8)(*result - 97) <= 0x19u )
*result -= 32;
++result;
}
while ( result != &a1[v2 - 1 + 1] );
}
return result;
}

original_code:
void trans(char *str)
{
    int size;
    int iloop;
    size=strlen(str);
    for(iloop=0;iloop<size;iloop++)
    {
        if(str[iloop]>='a' && str[iloop]<='z')
            str[iloop]=str[iloop]-32;
    }
}

variable_types: iloop int


menu

decompiled_code:
__int64 __fastcall menu(void **a1)
{
const char *v1; // rbp
const char *v2; // rbp
const char *v3; // rbp
const char *v4; // rbp
const char *v5; // rbx

puts("Please input file path:");
read(0, a1[5], 0x100uLL);
v1 = (const char *)a1[5];
v1[strlen(v1) - 1] = 0;
puts("Please input file name:(more files are aparted by ';')");
read(0, a1[1], 0x100uLL);
v2 = (const char *)a1[1];
v2[strlen(v2) - 1] = 0;
puts("Please input file auther:");
read(0, a1[2], 0x100uLL);
v3 = (const char *)a1[2];
v3[strlen(v3) - 1] = 0;
puts("Please input E-maill:");
read(0, a1[3], 0x3CuLL);
v4 = (const char *)a1[3];
v4[strlen(v4) - 1] = 0;
puts("Please input file infmation:(less than 1024 bit)");
read(0, a1[4], 0x400uLL);
v5 = (const char *)a1[4];
v5[strlen(v5) - 1] = 0;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(void **a1)
{
const char *v1; // rbp
const char *v2; // rbp
const char *v3; // rbp
const char *v4; // rbp
const char *v5; // rbx

puts("Please input file path:");
read(0, a1[5], 0x100uLL);
v1 = (const char *)a1[5];
v1[strlen(v1) - 1] = 0;
puts("Please input file name:(more files are aparted by ';')");
read(0, a1[1], 0x100uLL);
v2 = (const char *)a1[1];
v2[strlen(v2) - 1] = 0;
puts("Please input file auther:");
read(0, a1[2], 0x100uLL);
v3 = (const char *)a1[2];
v3[strlen(v3) - 1] = 0;
puts("Please input E-maill:");
read(0, a1[3], 0x3CuLL);
v4 = (const char *)a1[3];
v4[strlen(v4) - 1] = 0;
puts("Please input file infmation:(less than 1024 bit)");
read(0, a1[4], 0x400uLL);
v5 = (const char *)a1[4];
v5[strlen(v5) - 1] = 0;
return 1LL;
}

original_code:
int menu(head *p)
{
    printf("Please input file path:\n");
    read(0,p->path,256);
    p->path[strlen(p->path)-1]=0;
    printf("Please input file name:(more files are aparted by ';')\n");
    read(0,p->str,256);
    p->str[strlen(p->str)-1]=0;
    printf("Please input file auther:\n");
    read(0,p->auther,256);
    p->auther[strlen(p->auther)-1]=0;
    printf("Please input E-maill:\n");
    read(0,p->maill,60);
    p->maill[strlen(p->maill)-1]=0;
    printf("Please input file infmation:(less than 1024 bit)\n");
    read(0,p->info,1024);
    p->info[strlen(p->info)-1]=0;
    return 1;
}

canonical_original_code:
int menu(struct complex *p)
{
    printf("Please input file path:\n");
    read(0,p->path,256);
    p->path[strlen(p->path)-1]=0;
    printf("Please input file name:(more files are aparted by ';')\n");
    read(0,p->str,256);
    p->str[strlen(p->str)-1]=0;
    printf("Please input file auther:\n");
    read(0,p->auther,256);
    p->auther[strlen(p->auther)-1]=0;
    printf("Please input E-maill:\n");
    read(0,p->maill,60);
    p->maill[strlen(p->maill)-1]=0;
    printf("Please input file infmation:(less than 1024 bit)\n");
    read(0,p->info,1024);
    p->info[strlen(p->info)-1]=0;
    return 1;
}

variable_types: struct complex { int flag; char *str; char *auther; char *maill; char *info; char *path; } *


main

canonical_name: main

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

v3 = malloc(0x30uLL);
*((_QWORD *)v3 + 1) = malloc(0x100uLL);
*((_QWORD *)v3 + 2) = malloc(0x100uLL);
*((_QWORD *)v3 + 3) = malloc(0x3CuLL);
*((_QWORD *)v3 + 4) = malloc(0x400uLL);
*((_QWORD *)v3 + 5) = malloc(0x100uLL);
if ( argc <= 1 )
{
*(_DWORD *)v3 = 2;
menu((void **)v3);
maker((__int64)v3);
}
else
{
*(_DWORD *)v3 = 1;
v4 = argv + 1;
do
{
strcpy(*((char **)v3 + 1), *v4);
maker((__int64)v3);
v5 = (_QWORD *)*((_QWORD *)v3 + 1);
*v5 = 0LL;
v5[31] = 0LL;
memset(
(void *)((unsigned __int64)(v5 + 1) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)v5 - (((_DWORD)v5 + 8) & 0xFFFFFFF8) + 256) >> 3));
++v4;
}
while ( v4 != &argv[(unsigned int)(argc - 2) + 2] );
}
return 0;
}

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

v3 = malloc(0x30uLL);
*((_QWORD *)v3 + 1) = malloc(0x100uLL);
*((_QWORD *)v3 + 2) = malloc(0x100uLL);
*((_QWORD *)v3 + 3) = malloc(0x3CuLL);
*((_QWORD *)v3 + 4) = malloc(0x400uLL);
*((_QWORD *)v3 + 5) = malloc(0x100uLL);
if ( argc <= 1 )
{
*(_DWORD *)v3 = 2;
func9((void **)v3);
func8((__int64)v3);
}
else
{
*(_DWORD *)v3 = 1;
v4 = argv + 1;
do
{
strcpy(*((char **)v3 + 1), *v4);
func8((__int64)v3);
v5 = (_QWORD *)*((_QWORD *)v3 + 1);
*v5 = 0LL;
v5[31] = 0LL;
memset(
(void *)((unsigned __int64)(v5 + 1) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)v5 - (((_DWORD)v5 + 8) & 0xFFFFFFF8) + 256) >> 3));
++v4;
}
while ( v4 != &argv[(unsigned int)(argc - 2) + 2] );
}
return 0;
}

original_code:
int main(int argc, const char *argv[])
{
    int num;
    int iloop;
    head *p=((void *)0);
    p=malloc(sizeof(head));
    p->str=(char *)malloc(256);
    p->auther=(char *)malloc(256);
    p->maill=(char *)malloc(60);
    p->info=(char *)malloc(1024);
    p->path=(char *)malloc(256);
    if(argc>=2)
    {
        p->flag=1;
        num=argc-1;
        for(iloop=0;iloop<num;iloop++)
        {
            strcpy(p->str,argv[iloop+1]);
            maker(p);
            memset(p->str,0,256);
        }
    }
    else
    {
        p->flag=2;
        menu(p);
        maker(p);
    }
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    int num;
    int iloop;
    struct complex *p = ((void *)0);
    p=malloc(sizeof(head));
    p->str=(char *)malloc(256);
    p->auther=(char *)malloc(256);
    p->maill=(char *)malloc(60);
    p->info=(char *)malloc(1024);
    p->path=(char *)malloc(256);
    if(argc>=2)
    {
        p->flag=1;
        num=argc-1;
        for(iloop=0;iloop<num;iloop++)
        {
            strcpy(p->str,argv[iloop+1]);
            maker(p);
            memset(p->str,0,256);
        }
    }
    else
    {
        p->flag=2;
        menu(p);
        maker(p);
    }
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: num int

user_defined_types: struct complex { int flag; char *str; char *auther; char *maill; char *info; char *path; }


stripname

repo: ricojansen/packman

decompiled_code:
__int64 __fastcall stripname(char **a1, const char *a2)
{
const char *i; // rbx
const char *v3; // rbx
size_t v4; // rax
char *v5; // rbp
const __int32_t *v6; // rax

for ( i = &a2[strlen(a2)]; *i != 47 && *i != 92 && a2 != i; --i )
;
v3 = &i[a2 != i];
v4 = strlen(v3);
v5 = (char *)malloc(v4 + 1);
*a1 = v5;
strcpy(v5, v3);
if ( strlen(v5) == 7 )
{
v6 = *_ctype_tolower_loc();
*v5 = v6[*v5];
v5[1] = v6[v5[1]];
v5[2] = v6[v5[2]];
v5[3] = v6[v5[3]];
v5[4] = v6[v5[4]];
v5[5] = v6[v5[5]];
v5[6] = v6[v5[6]];
}
else
{
fwrite("Hey I haven't got my original name!\n", 1uLL, 0x24uLL, stderr);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(char **a1, const char *a2)
{
const char *i; // rbx
const char *v3; // rbx
size_t v4; // rax
char *v5; // rbp
const __int32_t *v6; // rax

for ( i = &a2[strlen(a2)]; *i != 47 && *i != 92 && a2 != i; --i )
;
v3 = &i[a2 != i];
v4 = strlen(v3);
v5 = (char *)malloc(v4 + 1);
*a1 = v5;
strcpy(v5, v3);
if ( strlen(v5) == 7 )
{
v6 = *_ctype_tolower_loc();
*v5 = v6[*v5];
v5[1] = v6[v5[1]];
v5[2] = v6[v5[2]];
v5[3] = v6[v5[3]];
v5[4] = v6[v5[4]];
v5[5] = v6[v5[5]];
v5[6] = v6[v5[6]];
}
else
{
fwrite("Hey I haven't got my original name!\n", 1uLL, 0x24uLL, stderr);
}
return 0LL;
}

original_code:
int stripname(char **name,char *called) {
char *pos;
 pos=called+strlen(called);
 while(*pos!='\\' && *pos!='/' && pos!=called) pos--;
 if (pos!=called) pos++;
 (*name)=malloc(sizeof(char)*(strlen(pos)+1));
 strcpy((*name),pos);
 if (strlen((*name))!=7) {
  fprintf(stderr,"Hey I haven't got my original name!\n");
 } else {
  (*name)[0]=tolower((*name)[0]);
  (*name)[1]=tolower((*name)[1]);
  (*name)[2]=tolower((*name)[2]);
  (*name)[3]=tolower((*name)[3]);
  (*name)[4]=tolower((*name)[4]);
  (*name)[5]=tolower((*name)[5]);
  (*name)[6]=tolower((*name)[6]);
 }
 return(0);
}

canonical_original_code:
int stripname(char **name, char *called) {
char *pos;
 pos=called+strlen(called);
 while(*pos!='\\' && *pos!='/' && pos!=called) pos--;
 if (pos!=called) pos++;
 (*name)=malloc(sizeof(char)*(strlen(pos)+1));
 strcpy((*name),pos);
 if (strlen((*name))!=7) {
  fprintf(stderr,"Hey I haven't got my original name!\n");
 } else {
  (*name)[0]=tolower((*name)[0]);
  (*name)[1]=tolower((*name)[1]);
  (*name)[2]=tolower((*name)[2]);
  (*name)[3]=tolower((*name)[3]);
  (*name)[4]=tolower((*name)[4]);
  (*name)[5]=tolower((*name)[5]);
  (*name)[6]=tolower((*name)[6]);
 }
 return(0);
}

variable_types:
name
char **

variable_types:
called
char *

variable_types:
pos
char *


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
const char *v3; // r12
size_t v4; // rbp
const char *v5; // r13
size_t v6; // rax
char *v7; // rbp
const char *v8; // r13
char *v9; // rax
char v10; // al
time_t timer; // [rsp+8h] [rbp-1E0h] BYREF
char filename[128]; // [rsp+10h] [rbp-1D8h] BYREF
char dest[264]; // [rsp+90h] [rbp-158h] BYREF
__int64 v14; // [rsp+198h] [rbp-50h] BYREF
__int64 v15[9]; // [rsp+1A0h] [rbp-48h] BYREF

stripname(&progname, *argv);
fprintf(stdout, "%s version %s\n%s\n", progname, Version, Announce);
fwrite("Alpha Release\n", 1uLL, 0xEuLL, stdout);
if ( argc > 2 )
{
strcpy(dest, progname);
fwrite("Programming Version\n", 1uLL, 0x14uLL, stdout);
readconfig(dest);
v3 = (const char *)*(&cfg + 2);
v4 = strlen(v3);
v5 = progname;
v6 = strlen(progname);
v7 = (char *)malloc(v4 + v6);
strcpy(v7, v3);
strcat(v7, v5);
v8 = (const char *)*(&cfg + 6);
if ( v8 )
{
strcpy(filename, v3);
strcat(filename, v8);
logfile = fopen(filename, "a");
if ( !logfile )
fprintf(stderr, "%s : Can't open logfile %s\nLogging Disabled\n", progname, dest);
}
else
{
logfile = 0LL;
}
time(&timer);
v9 = ctime(&timer);
sprintf(filename, "\n%s %s at %s", progname, Version, v9);
printmsg(1LL, filename);
printmsg(2LL, "Configuration :\n");
sprintf(filename, "PACK : <%s>\nUNPACK : <%s>\n", (const char *)cfg, (const char *)*(&cfg + 1));
printmsg(2LL, filename);
sprintf(filename, "FILES : <%s>\nBACKUP : <%s>\n", (const char *)*(&cfg + 2), (const char *)*(&cfg + 7));
printmsg(2LL, filename);
sprintf(filename, "VERBOSE : <%d>\nLOGLEVEL : <%d>\n", *((unsigned int *)&cfg + 10), *((unsigned int *)&cfg + 11));
printmsg(2LL, filename);
sprintf(filename, "LOGFILE : <%s>\n", (const char *)*(&cfg + 6));
printmsg(2LL, filename);
sprintf(filename, "OUTBOUND : <%s>\nINBOUND : <%s>\n\n", (const char *)*(&cfg + 4), (const char *)*(&cfg + 3));
printmsg(2LL, filename);
sprintf(filename, "TEARLINE : <%s>\nORIGIN : <%s>\n\n", (const char *)*(&cfg + 8), (const char *)*(&cfg + 9));
printmsg(2LL, filename);
v15[0] = 0LL;
v15[1] = 0LL;
v15[2] = 0LL;
v15[3] = 0LL;
readtab(v7, v15);
v14 = 0LL;
readlist(v7, &v14);
v10 = *argv[1];
if ( v10 == 97 )
{
addpackets(argv, v15, &v14);
}
else if ( v10 == 120 )
{
extractpackets(argv, v15, &v14);
}
else
{
fprintf(stderr, "%s : Unknown command\n", progname);
}
cleanup(v15, &v14);
fclose(logfile);
}
else
{
fprintf(stderr, "Usage : %s <x|a> <arcmail> [packet] ... [packet]\n", progname);
}
exit(0);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
const char *v3; // r12
size_t v4; // rbp
const char *v5; // r13
size_t v6; // rax
char *v7; // rbp
const char *v8; // r13
char *v9; // rax
char v10; // al
time_t timer; // [rsp+8h] [rbp-1E0h] BYREF
char filename[128]; // [rsp+10h] [rbp-1D8h] BYREF
char dest[264]; // [rsp+90h] [rbp-158h] BYREF
__int64 v14; // [rsp+198h] [rbp-50h] BYREF
__int64 v15[9]; // [rsp+1A0h] [rbp-48h] BYREF

func0(&progname, *argv);
fprintf(stdout, "%s version %s\n%s\n", progname, Version, Announce);
fwrite("Alpha Release\n", 1uLL, 0xEuLL, stdout);
if ( argc > 2 )
{
strcpy(dest, progname);
fwrite("Programming Version\n", 1uLL, 0x14uLL, stdout);
readconfig(dest);
v3 = (const char *)*(&cfg + 2);
v4 = strlen(v3);
v5 = progname;
v6 = strlen(progname);
v7 = (char *)malloc(v4 + v6);
strcpy(v7, v3);
strcat(v7, v5);
v8 = (const char *)*(&cfg + 6);
if ( v8 )
{
strcpy(filename, v3);
strcat(filename, v8);
logfile = fopen(filename, "a");
if ( !logfile )
fprintf(stderr, "%s : Can't open logfile %s\nLogging Disabled\n", progname, dest);
}
else
{
logfile = 0LL;
}
time(&timer);
v9 = ctime(&timer);
sprintf(filename, "\n%s %s at %s", progname, Version, v9);
printmsg(1LL, filename);
printmsg(2LL, "Configuration :\n");
sprintf(filename, "PACK : <%s>\nUNPACK : <%s>\n", (const char *)cfg, (const char *)*(&cfg + 1));
printmsg(2LL, filename);
sprintf(filename, "FILES : <%s>\nBACKUP : <%s>\n", (const char *)*(&cfg + 2), (const char *)*(&cfg + 7));
printmsg(2LL, filename);
sprintf(filename, "VERBOSE : <%d>\nLOGLEVEL : <%d>\n", *((unsigned int *)&cfg + 10), *((unsigned int *)&cfg + 11));
printmsg(2LL, filename);
sprintf(filename, "LOGFILE : <%s>\n", (const char *)*(&cfg + 6));
printmsg(2LL, filename);
sprintf(filename, "OUTBOUND : <%s>\nINBOUND : <%s>\n\n", (const char *)*(&cfg + 4), (const char *)*(&cfg + 3));
printmsg(2LL, filename);
sprintf(filename, "TEARLINE : <%s>\nORIGIN : <%s>\n\n", (const char *)*(&cfg + 8), (const char *)*(&cfg + 9));
printmsg(2LL, filename);
v15[0] = 0LL;
v15[1] = 0LL;
v15[2] = 0LL;
v15[3] = 0LL;
readtab(v7, v15);
v14 = 0LL;
readlist(v7, &v14);
v10 = *argv[1];
if ( v10 == 97 )
{
addpackets(argv, v15, &v14);
}
else if ( v10 == 120 )
{
extractpackets(argv, v15, &v14);
}
else
{
fprintf(stderr, "%s : Unknown command\n", progname);
}
cleanup(v15, &v14);
fclose(logfile);
}
else
{
fprintf(stderr, "Usage : %s <x|a> <arcmail> [packet] ... [packet]\n", progname);
}
exit(0);
}

original_code:
void main(int argc,char **argv) {
struct reroutetab rrt;
struct kludges kl;
char *cmplname,*wlk,configplace[255],txt[128];
int walk,chkv=1968,chka=1968,chkf=1968;
long logtime;
 stripname(&progname,argv[0]);
 fprintf(stdout,"%s version %s\n%s\n",progname,Version,Announce);
 fprintf(stdout,"Alpha Release\n");
 if (argc<3) {
  fprintf(stderr,"Usage : %s <x|a> <arcmail> [packet] ... [packet]\n",progname);
 } else {
  strcpy(configplace,progname);
  fprintf(stdout,"Programming Version\n");
  readconfig(configplace);
  cmplname=(char *)malloc(sizeof(char)*(strlen(cfg.FILES)+strlen(progname)));
  strcpy(cmplname,cfg.FILES);
  strcat(cmplname,progname);
  if (cfg.LOGFILE!=((void *)0)) {
   strcpy(txt,cfg.FILES);
   strcat(txt,cfg.LOGFILE);
   if ((logfile=fopen(txt,"a"))==((void *)0)) {
    fprintf(stderr,"%s : Can't open logfile %s\nLogging Disabled\n",progname,configplace);
   }
  } else {
   logfile=((void *)0);
  }
  time(&logtime);
  sprintf(txt,"\n%s %s at %s",progname,Version,ctime(&logtime));
  printmsg(1,txt);
  printmsg(2,"Configuration :\n");
  sprintf(txt,"PACK     : <%s>\nUNPACK   : <%s>\n",cfg.PACK,cfg.UNPACK);
  printmsg(2,txt);
  sprintf(txt,"FILES    : <%s>\nBACKUP   : <%s>\n",cfg.FILES,cfg.BACKUP);
  printmsg(2,txt);
  sprintf(txt,"VERBOSE  : <%d>\nLOGLEVEL : <%d>\n",cfg.VERBOSE,cfg.LOGLEVEL);
  printmsg(2,txt);
  sprintf(txt,"LOGFILE  : <%s>\n",cfg.LOGFILE);
  printmsg(2,txt);
  sprintf(txt,"OUTBOUND : <%s>\nINBOUND  : <%s>\n\n",cfg.OUTBOUND,cfg.INBOUND);
  printmsg(2,txt);
  sprintf(txt,"TEARLINE : <%s>\nORIGIN   : <%s>\n\n",cfg.TEARLINE,cfg.ORIGIN);
  printmsg(2,txt);
  rrt.orgroot=((void *)0);
  rrt.orgthread=((void *)0);
  rrt.dstroot=((void *)0);
  rrt.dstthread=((void *)0);
  readtab(cmplname,&rrt);
  kl.root=((void *)0);
  readlist(cmplname,&kl);
  switch(argv[1][0]) {
   case 'a': addpackets(argv,&rrt,&kl);
       break;
   case 'x': extractpackets(argv,&rrt,&kl);
       break;
   default : fprintf(stderr,"%s : Unknown command\n",progname);
       break;
  }
  cleanup(&rrt,&kl);
  fclose(logfile);
 }
 exit(0);
}

canonical_original_code:
void main(int argc, char **argv) {
struct reroutetab rrt;
struct kludges kl;
char *cmplname; char *wlk; char configplace[255]; char txt[128];
int walk; int chkv = 1968; int chka = 1968; int chkf = 1968;
long logtime;
 stripname(&progname,argv[0]);
 fprintf(stdout,"%s version %s\n%s\n",progname,Version,Announce);
 fprintf(stdout,"Alpha Release\n");
 if (argc<3) {
  fprintf(stderr,"Usage : %s <x|a> <arcmail> [packet] ... [packet]\n",progname);
 } else {
  strcpy(configplace,progname);
  fprintf(stdout,"Programming Version\n");
  readconfig(configplace);
  cmplname=(char *)malloc(sizeof(char)*(strlen(cfg.FILES)+strlen(progname)));
  strcpy(cmplname,cfg.FILES);
  strcat(cmplname,progname);
  if (cfg.LOGFILE!=((void *)0)) {
   strcpy(txt,cfg.FILES);
   strcat(txt,cfg.LOGFILE);
   if ((logfile=fopen(txt,"a"))==((void *)0)) {
    fprintf(stderr,"%s : Can't open logfile %s\nLogging Disabled\n",progname,configplace);
   }
  } else {
   logfile=((void *)0);
  }
  time(&logtime);
  sprintf(txt,"\n%s %s at %s",progname,Version,ctime(&logtime));
  printmsg(1,txt);
  printmsg(2,"Configuration :\n");
  sprintf(txt,"PACK     : <%s>\nUNPACK   : <%s>\n",cfg.PACK,cfg.UNPACK);
  printmsg(2,txt);
  sprintf(txt,"FILES    : <%s>\nBACKUP   : <%s>\n",cfg.FILES,cfg.BACKUP);
  printmsg(2,txt);
  sprintf(txt,"VERBOSE  : <%d>\nLOGLEVEL : <%d>\n",cfg.VERBOSE,cfg.LOGLEVEL);
  printmsg(2,txt);
  sprintf(txt,"LOGFILE  : <%s>\n",cfg.LOGFILE);
  printmsg(2,txt);
  sprintf(txt,"OUTBOUND : <%s>\nINBOUND  : <%s>\n\n",cfg.OUTBOUND,cfg.INBOUND);
  printmsg(2,txt);
  sprintf(txt,"TEARLINE : <%s>\nORIGIN   : <%s>\n\n",cfg.TEARLINE,cfg.ORIGIN);
  printmsg(2,txt);
  rrt.orgroot=((void *)0);
  rrt.orgthread=((void *)0);
  rrt.dstroot=((void *)0);
  rrt.dstthread=((void *)0);
  readtab(cmplname,&rrt);
  kl.root=((void *)0);
  readlist(cmplname,&kl);
  switch(argv[1][0]) {
   case 'a': addpackets(argv,&rrt,&kl);
       break;
   case 'x': extractpackets(argv,&rrt,&kl);
       break;
   default : fprintf(stderr,"%s : Unknown command\n",progname);
       break;
  }
  cleanup(&rrt,&kl);
  fclose(logfile);
 }
 exit(0);
}

variable_types:
argv
char **

variable_types: struct reroutetab { struct rrlist { struct rrlist *next; struct fidaddr { int Zone; int Net; int Node; int Point; } in; } *orgroot; struct rrlist *dstroot; }

variable_types: struct kludges { struct kludgelist { struct kludgelist *next; struct kludge { char *kludge; char *spec; char *repl; } klg; } *root; }

variable_types:
cmplname
char *

variable_types:
wlk
char *

variable_types:
configplace
char [255]

variable_types:
txt
char [128]

variable_types: walk int

variable_types: chkv int

variable_types: chka int

variable_types: chkf int

variable_types: logtime long

user_defined_types: struct reroutetab { struct rrlist *orgroot; struct rrlist *dstroot; }

user_defined_types: struct kludges { struct kludgelist *root; }

user_defined_types: struct rrlist { struct rrlist *next; struct fidaddr in; }

user_defined_types: struct kludgelist { struct kludgelist *next; struct kludge klg; }


changestr

original_code:
int changestr(char **text,int *pos,struct rrlist *root) {
int type,lentxt;
struct fidaddr fd;
 printmsg(3,"ChangeStr\n");
 while((*text)[*pos]!=(0x0D)) {
  if ((type=parseaddress((*text)+(*pos),&fd,(00)))==-1) {
   printmsg(0,"Address parsing error\n");
   while((*text)[*pos]!=' ' && (*text)[*pos]!='\0' && (*text)[*pos]!=(0x0D)) (*pos)++;
  } else {
   lentxt=0;
   while((*text)[*pos+lentxt]!=' ' && (*text)[*pos+lentxt]!=(0x0D)) lentxt++;
   changeaddr(text,*pos,lentxt,root,&fd,type);
   while((*text)[*pos]!=' ' && (*text)[*pos]!=(0x0D)) (*pos)++;
  }
  if ((*text)[*pos]==' ') (*pos)++;
 }
 return(0);
}

canonical_original_code:
int changestr(char **text, int *pos, struct rrlist *root) {
int type; int lentxt;
struct fidaddr fd;
 printmsg(3,"ChangeStr\n");
 while((*text)[*pos]!=(0x0D)) {
  if ((type=parseaddress((*text)+(*pos),&fd,(00)))==-1) {
   printmsg(0,"Address parsing error\n");
   while((*text)[*pos]!=' ' && (*text)[*pos]!='\0' && (*text)[*pos]!=(0x0D)) (*pos)++;
  } else {
   lentxt=0;
   while((*text)[*pos+lentxt]!=' ' && (*text)[*pos+lentxt]!=(0x0D)) lentxt++;
   changeaddr(text,*pos,lentxt,root,&fd,type);
   while((*text)[*pos]!=' ' && (*text)[*pos]!=(0x0D)) (*pos)++;
  }
  if ((*text)[*pos]==' ') (*pos)++;
 }
 return(0);
}

variable_types:
text
char **

variable_types:
pos
int *

variable_types: struct rrlist { struct rrlist *next; struct fidaddr { int Zone; int Net; int Node; int Point; } in; } *

variable_types: type int

variable_types: lentxt int


changeorigin

original_code:
int changeorigin(char **text,struct rrlist *root) {
int pos;
struct fidaddr fd;
int type,len;
int begin,end,left;
 printmsg(3,"ChangeOrigin\n");
 pos=0;
 while((*text)[pos]!='\0') {
  while((*text)[pos]!='\0' && (*text)[pos]!=(0x0D)) pos++;
  if ((*text)[pos]==(0x0D)) pos++;
  if ((*text)[pos]=='\0') break;
  if (strncmp((*text)+pos," * Origin: ",11)==0) {
   begin=pos+11;;
   while((*text)[pos]!=(0x0D)) pos++;
   while((*text)[pos]!='(') pos--;
   left=pos-1;
   while(!(((*__ctype_b_loc ())[(int) (((*text)[pos]))] & (unsigned short int) _ISalnum) && !((*__ctype_b_loc ())[(int) (((*text)[pos]))] & (unsigned short int) _ISalpha)) && (*text)[pos]!=(0x0D)) pos++;
   if ((*text)[pos]==(0x0D) || (type=parseaddress((*text)+pos,&fd,(00)))==-1) {
    printmsg(0,"Address parsing error\n");
   } else {
    len=0;
    while((*text)[pos+len]!=')') len++;
             changeaddr(text,pos,len,root,&fd,type);
    if (cfg.ORIGIN!=((void *)0)) {
     end=left;
     while((*text)[end]!=(0x0D)) end++;
     if (strlen(cfg.ORIGIN)<(80-(end-left)-11)) {
      (*text)[left]=' ';
      replacestring(text,left-begin,begin,cfg.ORIGIN);
     }
    }
   }
  }
 }
 return(0);
}

canonical_original_code:
int changeorigin(char **text, struct rrlist *root) {
int pos;
struct fidaddr fd;
int type; int len;
int begin; int end; int left;
 printmsg(3,"ChangeOrigin\n");
 pos=0;
 while((*text)[pos]!='\0') {
  while((*text)[pos]!='\0' && (*text)[pos]!=(0x0D)) pos++;
  if ((*text)[pos]==(0x0D)) pos++;
  if ((*text)[pos]=='\0') break;
  if (strncmp((*text)+pos," * Origin: ",11)==0) {
   begin=pos+11;;
   while((*text)[pos]!=(0x0D)) pos++;
   while((*text)[pos]!='(') pos--;
   left=pos-1;
   while(!(((*__ctype_b_loc ())[(int) (((*text)[pos]))] & (unsigned short) _ISalnum) && !((*__ctype_b_loc ())[(int) (((*text)[pos]))] & (unsigned short) _ISalpha)) && (*text)[pos]!=(0x0D)) pos++;
   if ((*text)[pos]==(0x0D) || (type=parseaddress((*text)+pos,&fd,(00)))==-1) {
    printmsg(0,"Address parsing error\n");
   } else {
    len=0;
    while((*text)[pos+len]!=')') len++;
             changeaddr(text,pos,len,root,&fd,type);
    if (cfg.ORIGIN!=((void *)0)) {
     end=left;
     while((*text)[end]!=(0x0D)) end++;
     if (strlen(cfg.ORIGIN)<(80-(end-left)-11)) {
      (*text)[left]=' ';
      replacestring(text,left-begin,begin,cfg.ORIGIN);
     }
    }
   }
  }
 }
 return(0);
}

variable_types: pos int

variable_types: struct fidaddr { int Zone; int Net; int Node; int Point; }

variable_types: len int

variable_types: begin int

variable_types: end int

variable_types: left int


changeseenby

original_code:
int changeseenby(char **text,struct rrlist *root) {
int pos;
 printmsg(3,"ChangeSEENBY\n");
 pos=0;
 while((*text)[pos]!='\0') {
  while((*text)[pos]!='\0' && (*text)[pos]!=(0x0D)) pos++;
  if ((*text)[pos]=='\0') break;
  pos++;
  if (strncmp((*text)+pos,"SEEN-BY: ",9)==0) {
   pos+=9;
   changestr(text,&pos,root);
  }
 }
 return(0);
}

canonical_original_code:
int changeseenby(char **text, struct rrlist *root) {
int pos;
 printmsg(3,"ChangeSEENBY\n");
 pos=0;
 while((*text)[pos]!='\0') {
  while((*text)[pos]!='\0' && (*text)[pos]!=(0x0D)) pos++;
  if ((*text)[pos]=='\0') break;
  pos++;
  if (strncmp((*text)+pos,"SEEN-BY: ",9)==0) {
   pos+=9;
   changestr(text,&pos,root);
  }
 }
 return(0);
}

user_defined_types: struct fidaddr { int Zone; int Net; int Node; int Point; }


doaddress

decompiled_code:
__int64 __fastcall doaddress(_QWORD *a1, unsigned int *a2, __int64 a3, __int64 *a4, int a5)
{
unsigned int v9; // er12
int v10; // er13
unsigned int v11; // er15
int v12; // er12
const unsigned __int16 **v13; // rsi
__int64 v15; // [rsp+8h] [rbp-50h]
char v16[72]; // [rsp+10h] [rbp-48h] BYREF

printmsg(3LL, "DoAddress\n");
v9 = parserepl(a3);
if ( v9 == -1 )
return v9;
v10 = parseaddress(*a1 + (int)*a2, v16, 0LL);
if ( v10 == -1 )
return (unsigned int)-1;
if ( v9 == 1 )
{
v15 = *a4;
}
else
{
if ( v9 != 2 )
{
printmsg(0LL, "Illegal program flow\n");
return (unsigned int)-1;
}
v15 = a4[2];
}
if ( v10 > 8 )
{
v11 = *a2;
v12 = v10 - 9;
goto LABEL_9;
}
v11 = *a2;
v12 = v10 - 1;
if ( v10 )
{
LABEL_9:
v13 = _ctype_b_loc();
do
{
++*a2;
while ( ((*v13)[*(char *)(*a1 + (int)*a2)] & 0x408) == 8 )
++*a2;
--v12;
}
while ( v12 != -1 );
}
v9 = 0;
if ( !a5 )
{
changeaddr(a1, v11, *a2 - v11, v15, v16, (unsigned int)v10);
v9 = 0;
}
return v9;
}

canonical_decompiled_code:
__int64 __fastcall func3(_QWORD *a1, unsigned int *a2, __int64 a3, __int64 *a4, int a5)
{
unsigned int v9; // er12
int v10; // er13
unsigned int v11; // er15
int v12; // er12
const unsigned __int16 **v13; // rsi
__int64 v15; // [rsp+8h] [rbp-50h]
char v16[72]; // [rsp+10h] [rbp-48h] BYREF

printmsg(3LL, "DoAddress\n");
v9 = parserepl(a3);
if ( v9 == -1 )
return v9;
v10 = parseaddress(*a1 + (int)*a2, v16, 0LL);
if ( v10 == -1 )
return (unsigned int)-1;
if ( v9 == 1 )
{
v15 = *a4;
}
else
{
if ( v9 != 2 )
{
printmsg(0LL, "Illegal program flow\n");
return (unsigned int)-1;
}
v15 = a4[2];
}
if ( v10 > 8 )
{
v11 = *a2;
v12 = v10 - 9;
goto LABEL_9;
}
v11 = *a2;
v12 = v10 - 1;
if ( v10 )
{
LABEL_9:
v13 = _ctype_b_loc();
do
{
++*a2;
while ( ((*v13)[*(char *)(*a1 + (int)*a2)] & 0x408) == 8 )
++*a2;
--v12;
}
while ( v12 != -1 );
}
v9 = 0;
if ( !a5 )
{
changeaddr(a1, v11, *a2 - v11, v15, v16, (unsigned int)v10);
v9 = 0;
}
return v9;
}

original_code:
int doaddress(char **text,int *pos,char **rep,struct reroutetab *rrt,int keep) {
int len;
int pos2;
struct fidaddr fd;
int type,typ;
struct rrlist *root;
 printmsg(3,"DoAddress\n");
 if ((type=parserepl(rep))==-1) {
  return(-1);
 } else {
  if ((typ=parseaddress((*text)+*pos,&fd,(00)))==-1) {
   return(-1);
  } else {
   switch(type) {
    case 1 :root=rrt->orgroot;
      break;
    case 2 :root=rrt->dstroot;
      break;
    default:printmsg(0,"Illegal program flow\n");
      return(-1);
   }
   type=typ;
   if (typ>8) {
    typ-=8;
   }
   pos2=*pos;
   while(typ--) {
    (*pos)++;
    while((((*__ctype_b_loc ())[(int) (((*text)[*pos]))] & (unsigned short int) _ISalnum) && !((*__ctype_b_loc ())[(int) (((*text)[*pos]))] & (unsigned short int) _ISalpha))) {
     (*pos)++;
    }
   }
   len=(*pos)-pos2;
   if (!keep) changeaddr(text,pos2,len,root,&fd,type);
  }
 }
 return(0);
}

canonical_original_code:
int doaddress(char **text, int *pos, char **rep, struct reroutetab *rrt, int keep) {
int len;
int pos2;
struct fidaddr fd;
int type; int typ;
struct rrlist *root;
 printmsg(3,"DoAddress\n");
 if ((type=parserepl(rep))==-1) {
  return(-1);
 } else {
  if ((typ=parseaddress((*text)+*pos,&fd,(00)))==-1) {
   return(-1);
  } else {
   switch(type) {
    case 1 :root=rrt->orgroot;
      break;
    case 2 :root=rrt->dstroot;
      break;
    default:printmsg(0,"Illegal program flow\n");
      return(-1);
   }
   type=typ;
   if (typ>8) {
    typ-=8;
   }
   pos2=*pos;
   while(typ--) {
    (*pos)++;
    while((((*__ctype_b_loc ())[(int) (((*text)[*pos]))] & (unsigned short) _ISalnum) && !((*__ctype_b_loc ())[(int) (((*text)[*pos]))] & (unsigned short) _ISalpha))) {
     (*pos)++;
    }
   }
   len=(*pos)-pos2;
   if (!keep) changeaddr(text,pos2,len,root,&fd,type);
  }
 }
 return(0);
}

variable_types:
rep
char **

variable_types: struct reroutetab { struct rrlist { struct rrlist *next; struct fidaddr { int Zone; int Net; int Node; int Point; } in; } *orgroot; struct rrlist *dstroot; } *

variable_types: keep int

variable_types: typ int


doword

decompiled_code:
void __noreturn doword()
{
printmsg(3LL, "DoWord\n");
while ( 1 )
;
}

canonical_decompiled_code:
void __noreturn func4()
{
printmsg(3LL, "DoWord\n");
while ( 1 )
;
}

original_code:
int doword(char **text,int *pos,char **rep,int keep) {
int lenrep;
char *txtrep;
 printmsg(3,"DoWord\n");
 lenrep=0;
 txtrep=*rep;
 while(*txtrep!=' ' || *txtrep!='\0') {
  txtrep++;
  lenrep++;
 }
 txtrep=(char *)malloc(sizeof(char)*(lenrep+1));
 txtrep[lenrep]='\0';
 while(lenrep--) {
  txtrep[lenrep]=(*rep)[lenrep];
 }
 if (!keep) replacestring(text,strlen(txtrep),*pos,txtrep);
 (*pos)+=strlen(txtrep);
 (*rep)+=lenrep;
 return(0);
}

canonical_original_code:
int doword(char **text, int *pos, char **rep, int keep) {
int lenrep;
char *txtrep;
 printmsg(3,"DoWord\n");
 lenrep=0;
 txtrep=*rep;
 while(*txtrep!=' ' || *txtrep!='\0') {
  txtrep++;
  lenrep++;
 }
 txtrep=(char *)malloc(sizeof(char)*(lenrep+1));
 txtrep[lenrep]='\0';
 while(lenrep--) {
  txtrep[lenrep]=(*rep)[lenrep];
 }
 if (!keep) replacestring(text,strlen(txtrep),*pos,txtrep);
 (*pos)+=strlen(txtrep);
 (*rep)+=lenrep;
 return(0);
}

variable_types: lenrep int

variable_types:
txtrep
char *


donum

decompiled_code:
__int64 __fastcall donum(__int64 a1, _DWORD *a2, __int64 a3, int a4)
{
unsigned int v6; // ebx
size_t v8; // rax
char v9[28]; // [rsp+0h] [rbp-48h] BYREF
unsigned int v10[11]; // [rsp+1Ch] [rbp-2Ch] BYREF

printmsg(3LL, "DoNum\n");
if ( (unsigned int)getnum(v10, a3) == -1 )
{
v6 = -1;
printmsg(0LL, "Wasn't a number in replacement specification\n");
}
else
{
sprintf(v9, "%d", v10[0]);
if ( !a4 )
{
v8 = strlen(v9);
replacestring(a1, v8, (unsigned int)*a2, v9);
}
*a2 += strlen(v9);
v6 = 0;
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, _DWORD *a2, __int64 a3, int a4)
{
unsigned int v6; // ebx
size_t v8; // rax
char v9[28]; // [rsp+0h] [rbp-48h] BYREF
unsigned int v10[11]; // [rsp+1Ch] [rbp-2Ch] BYREF

printmsg(3LL, "DoNum\n");
if ( (unsigned int)getnum(v10, a3) == -1 )
{
v6 = -1;
printmsg(0LL, "Wasn't a number in replacement specification\n");
}
else
{
sprintf(v9, "%d", v10[0]);
if ( !a4 )
{
v8 = strlen(v9);
replacestring(a1, v8, (unsigned int)*a2, v9);
}
*a2 += strlen(v9);
v6 = 0;
}
return v6;
}

original_code:
int donum(char **text,int *pos,char **rep,int keep) {
int num;
char txtrep[20];
 printmsg(3,"DoNum\n");
 if (getnum(&num,rep)==-1) {
  printmsg(0,"Wasn't a number in replacement specification\n");
  return(-1);
 } else {
  sprintf(txtrep,"%d",num);
  if (!keep) replacestring(text,strlen(txtrep),*pos,txtrep);
  (*pos)+=strlen(txtrep);
  return(0);
 }
}

canonical_original_code:
int donum(char **text, int *pos, char **rep, int keep) {
int num;
char txtrep[20];
 printmsg(3,"DoNum\n");
 if (getnum(&num,rep)==-1) {
  printmsg(0,"Wasn't a number in replacement specification\n");
  return(-1);
 } else {
  sprintf(txtrep,"%d",num);
  if (!keep) replacestring(text,strlen(txtrep),*pos,txtrep);
  (*pos)+=strlen(txtrep);
  return(0);
 }
}

variable_types:
text
char **

variable_types: num int

variable_types:
txtrep
char [20]


changetearline

original_code:
int changetearline(char **text) {
int pos;
int len;
 printmsg(3,"ChangeTearline\n");
 if (cfg.TEARLINE!=((void *)0)) {
  pos=0;
  while((*text)[pos]!='\0') {
   while((*text)[pos]!='\0' && (*text)[pos]!=(0x0D)) pos++;
   if ((*text)[pos]==(0x0D)) pos++;
   if ((*text)[pos]=='\0') break;
   if (strncmp((*text)+pos,"--- ",4)==0) {
    printmsg(3,"Found Tearline\n");
    pos+=4;
    len=0;
    while(((*text)+pos)[len]!=(0x0D)) len++;
    replacestring(text,len,pos,cfg.TEARLINE);
   }
  }
 }
 return(0);
}


changekludge

decompiled_code:
__int64 __fastcall changekludge(__int64 *a1, __int64 a2, __int64 a3)
{
__int64 v5; // rsi
int v6; // ecx
unsigned __int8 v7; // al
__int64 v8; // rax
unsigned __int8 v9; // dl
int v11[7]; // [rsp+Ch] [rbp-1Ch] BYREF

printmsg(3LL, "ChangeKludge\n");
v11[0] = 0;
LABEL_3:
v5 = *a1;
while ( 1 )
{
v6 = v11[0];
v7 = *(_BYTE *)(v5 + v11[0]);
if ( !v7 )
return 0LL;
if ( v7 > 1u )
{
v8 = v11[0] + 1;
do
{
v6 = v8;
v11[0] = v8;
v9 = *(_BYTE *)(v5 + v8++);
}
while ( v9 > 1u );
if ( !v9 )
continue;
}
v11[0] = v6 + 1;
kludgereplace(a1, v11, a2, a3);
goto LABEL_3;
}
}

original_code:
int changekludge(char **text,struct kludgelist *kll,struct reroutetab *rrt) {
int pos;
 printmsg(3,"ChangeKludge\n");
 pos=0;
 while((*text)[pos]!='\0') {
  while((*text)[pos]!=(0x01) && (*text)[pos]!='\0') pos++;
  if ((*text)[pos]=='\0') continue;
  pos++;
  kludgereplace(text,&pos,kll,rrt);
 }
 return(0);
}

canonical_original_code:
int changekludge(char **text, struct kludgelist *kll, struct reroutetab *rrt) {
int pos;
 printmsg(3,"ChangeKludge\n");
 pos=0;
 while((*text)[pos]!='\0') {
  while((*text)[pos]!=(0x01) && (*text)[pos]!='\0') pos++;
  if ((*text)[pos]=='\0') continue;
  pos++;
  kludgereplace(text,&pos,kll,rrt);
 }
 return(0);
}

variable_types: struct kludgelist { struct kludgelist *next; struct kludge { char *kludge; char *spec; char *repl; } klg; } *


modifypacket

original_code:
int modifypacket(struct packet *pakt,struct reroutetab *rrt,struct kludges *kl) {
struct msglist *walkmsg;
struct fidaddr chg;
 printmsg(3,"ModifyPacket\n");
 chg.Zone=(int)((int)pakt->pkh.origZoneLO+256*(int)pakt->pkh.origZoneHI);
 chg.Net=(int)((int)pakt->pkh.origNetLO+256*(int)pakt->pkh.origNetHI);
 chg.Node=(int)((int)pakt->pkh.origNodeLO+256*(int)pakt->pkh.origNodeHI);
 chg.Point=0;
 dochange(&chg,rrt->orgroot);
 { int qqo; qqo=chg.Zone; pakt->pkh.origZoneHI=(unsigned char)(qqo>>8);pakt->pkh.origZoneLO=(unsigned char)(qqo-256*(int)pakt->pkh.origZoneHI); };
 { int qqo; qqo=chg.Net; pakt->pkh.origNetHI=(unsigned char)(qqo>>8);pakt->pkh.origNetLO=(unsigned char)(qqo-256*(int)pakt->pkh.origNetHI); };
 { int qqo; qqo=chg.Node; pakt->pkh.origNodeHI=(unsigned char)(qqo>>8);pakt->pkh.origNodeLO=(unsigned char)(qqo-256*(int)pakt->pkh.origNodeHI); };
 chg.Zone=(int)((int)pakt->pkh.destZoneLO+256*(int)pakt->pkh.destZoneHI);
 chg.Net=(int)((int)pakt->pkh.destNetLO+256*(int)pakt->pkh.destNetHI);
 chg.Node=(int)((int)pakt->pkh.destNodeLO+256*(int)pakt->pkh.destNodeHI);
 chg.Point=0;
 dochange(&chg,rrt->dstroot);
 { int qqo; qqo=chg.Zone; pakt->pkh.destZoneHI=(unsigned char)(qqo>>8);pakt->pkh.destZoneLO=(unsigned char)(qqo-256*(int)pakt->pkh.destZoneHI); };
 { int qqo; qqo=chg.Net; pakt->pkh.destNetHI=(unsigned char)(qqo>>8);pakt->pkh.destNetLO=(unsigned char)(qqo-256*(int)pakt->pkh.destNetHI); };
 { int qqo; qqo=chg.Node; pakt->pkh.destNodeHI=(unsigned char)(qqo>>8);pakt->pkh.destNodeLO=(unsigned char)(qqo-256*(int)pakt->pkh.destNodeHI); };
 walkmsg=pakt->root;
 while(walkmsg!=((void *)0)) {
  chg.Zone=0;
  chg.Net=(int)((int)walkmsg->pmsg.origNetLO+256*(int)walkmsg->pmsg.origNetHI);
  chg.Node=(int)((int)walkmsg->pmsg.origNodeLO+256*(int)walkmsg->pmsg.origNodeHI);
  chg.Point=0;
  dochange(&chg,rrt->orgroot);
  { int qqo; qqo=chg.Net; walkmsg->pmsg.origNetHI=(unsigned char)(qqo>>8);walkmsg->pmsg.origNetLO=(unsigned char)(qqo-256*(int)walkmsg->pmsg.origNetHI); };
  { int qqo; qqo=chg.Node; walkmsg->pmsg.origNodeHI=(unsigned char)(qqo>>8);walkmsg->pmsg.origNodeLO=(unsigned char)(qqo-256*(int)walkmsg->pmsg.origNodeHI); };
  chg.Zone=0;
  chg.Net=(int)((int)walkmsg->pmsg.destNetLO+256*(int)walkmsg->pmsg.destNetHI);
  chg.Node=(int)((int)walkmsg->pmsg.destNodeLO+256*(int)walkmsg->pmsg.destNodeHI);
  chg.Point=0;
  dochange(&chg,rrt->dstroot);
  { int qqo; qqo=chg.Net; walkmsg->pmsg.destNetHI=(unsigned char)(qqo>>8);walkmsg->pmsg.destNetLO=(unsigned char)(qqo-256*(int)walkmsg->pmsg.destNetHI); };
  { int qqo; qqo=chg.Node; walkmsg->pmsg.destNodeHI=(unsigned char)(qqo>>8);walkmsg->pmsg.destNodeLO=(unsigned char)(qqo-256*(int)walkmsg->pmsg.destNodeHI); };
  changeseenby(&(walkmsg->Text),rrt->dstroot);
        changekludge(&(walkmsg->Text),kl->root,rrt);
  changeorigin(&(walkmsg->Text),rrt->orgroot);
  changetearline(&(walkmsg->Text));
  walkmsg=walkmsg->next;
 }
 return(0);
}

canonical_original_code:
int modifypacket(struct packet *pakt, struct reroutetab *rrt, struct kludges *kl) {
struct msglist *walkmsg;
struct fidaddr chg;
 printmsg(3,"ModifyPacket\n");
 chg.Zone=(int)((int)pakt->pkh.origZoneLO+256*(int)pakt->pkh.origZoneHI);
 chg.Net=(int)((int)pakt->pkh.origNetLO+256*(int)pakt->pkh.origNetHI);
 chg.Node=(int)((int)pakt->pkh.origNodeLO+256*(int)pakt->pkh.origNodeHI);
 chg.Point=0;
 dochange(&chg,rrt->orgroot);
 { int qqo; qqo=chg.Zone; pakt->pkh.origZoneHI=(unsigned char)(qqo>>8);pakt->pkh.origZoneLO=(unsigned char)(qqo-256*(int)pakt->pkh.origZoneHI); };
 { int qqo; qqo=chg.Net; pakt->pkh.origNetHI=(unsigned char)(qqo>>8);pakt->pkh.origNetLO=(unsigned char)(qqo-256*(int)pakt->pkh.origNetHI); };
 { int qqo; qqo=chg.Node; pakt->pkh.origNodeHI=(unsigned char)(qqo>>8);pakt->pkh.origNodeLO=(unsigned char)(qqo-256*(int)pakt->pkh.origNodeHI); };
 chg.Zone=(int)((int)pakt->pkh.destZoneLO+256*(int)pakt->pkh.destZoneHI);
 chg.Net=(int)((int)pakt->pkh.destNetLO+256*(int)pakt->pkh.destNetHI);
 chg.Node=(int)((int)pakt->pkh.destNodeLO+256*(int)pakt->pkh.destNodeHI);
 chg.Point=0;
 dochange(&chg,rrt->dstroot);
 { int qqo; qqo=chg.Zone; pakt->pkh.destZoneHI=(unsigned char)(qqo>>8);pakt->pkh.destZoneLO=(unsigned char)(qqo-256*(int)pakt->pkh.destZoneHI); };
 { int qqo; qqo=chg.Net; pakt->pkh.destNetHI=(unsigned char)(qqo>>8);pakt->pkh.destNetLO=(unsigned char)(qqo-256*(int)pakt->pkh.destNetHI); };
 { int qqo; qqo=chg.Node; pakt->pkh.destNodeHI=(unsigned char)(qqo>>8);pakt->pkh.destNodeLO=(unsigned char)(qqo-256*(int)pakt->pkh.destNodeHI); };
 walkmsg=pakt->root;
 while(walkmsg!=((void *)0)) {
  chg.Zone=0;
  chg.Net=(int)((int)walkmsg->pmsg.origNetLO+256*(int)walkmsg->pmsg.origNetHI);
  chg.Node=(int)((int)walkmsg->pmsg.origNodeLO+256*(int)walkmsg->pmsg.origNodeHI);
  chg.Point=0;
  dochange(&chg,rrt->orgroot);
  { int qqo; qqo=chg.Net; walkmsg->pmsg.origNetHI=(unsigned char)(qqo>>8);walkmsg->pmsg.origNetLO=(unsigned char)(qqo-256*(int)walkmsg->pmsg.origNetHI); };
  { int qqo; qqo=chg.Node; walkmsg->pmsg.origNodeHI=(unsigned char)(qqo>>8);walkmsg->pmsg.origNodeLO=(unsigned char)(qqo-256*(int)walkmsg->pmsg.origNodeHI); };
  chg.Zone=0;
  chg.Net=(int)((int)walkmsg->pmsg.destNetLO+256*(int)walkmsg->pmsg.destNetHI);
  chg.Node=(int)((int)walkmsg->pmsg.destNodeLO+256*(int)walkmsg->pmsg.destNodeHI);
  chg.Point=0;
  dochange(&chg,rrt->dstroot);
  { int qqo; qqo=chg.Net; walkmsg->pmsg.destNetHI=(unsigned char)(qqo>>8);walkmsg->pmsg.destNetLO=(unsigned char)(qqo-256*(int)walkmsg->pmsg.destNetHI); };
  { int qqo; qqo=chg.Node; walkmsg->pmsg.destNodeHI=(unsigned char)(qqo>>8);walkmsg->pmsg.destNodeLO=(unsigned char)(qqo-256*(int)walkmsg->pmsg.destNodeHI); };
  changeseenby(&(walkmsg->Text),rrt->dstroot);
        changekludge(&(walkmsg->Text),kl->root,rrt);
  changeorigin(&(walkmsg->Text),rrt->orgroot);
  changetearline(&(walkmsg->Text));
  walkmsg=walkmsg->next;
 }
 return(0);
}

variable_types: struct packet { struct PacketHeader { unsigned char origNodeLO; unsigned char origNodeHI; unsigned char destNodeLO; unsigned char destNodeHI; unsigned char yearLO; unsigned char yearHI; unsigned char monthLO; unsigned char monthHI; unsigned char dayLO; unsigned char dayHI; unsigned char hourLO; unsigned char hourHI; unsigned char minuteLO; unsigned char minuteHI; unsigned char secondLO; unsigned char secondHI; unsigned char baudLO; unsigned char baudHI; unsigned char ID1; unsigned char ID2; unsigned char origNetLO; unsigned char origNetHI; unsigned char destNetLO; unsigned char destNetHI; unsigned char prodcode; unsigned char serialno; unsigned char password[8]; unsigned char origZoneLO; unsigned char origZoneHI; unsigned char destZoneLO; unsigned char destZoneHI; unsigned char fill[20]; } pkh; struct msglist { struct msglist *next; struct PackedMessage { unsigned char origNodeLO; unsigned char origNodeHI; unsigned char destNodeLO; unsigned char destNodeHI; unsigned char origNetLO; unsigned char origNetHI; unsigned char destNetLO; unsigned char destNetHI; unsigned char AttributeLO; unsigned char AttributeHI; unsigned char costLO; unsigned char costHI; unsigned char DateTime[20]; } pmsg; char FromUser[36]; char ToUser[36]; char Subject[72]; char *Text; } *root; } *

variable_types: struct kludges { struct kludgelist { struct kludgelist *next; struct kludge { char *kludge; char *spec; char *repl; } klg; } *root; } *

variable_types: qqo int

user_defined_types: struct packet { struct PacketHeader pkh; struct msglist *root; }

user_defined_types: struct msglist { struct msglist *next; struct PackedMessage pmsg; char FromUser[36]; char ToUser[36]; char Subject[72]; char *Text; }


pack

decompiled_code:
__int64 __fastcall pack(char *s, __int64 a2)
{
__int64 v3; // rbx
const char *v4; // r13
size_t v5; // r12
size_t v6; // rax
char *v7; // rdi
size_t v8; // rax
__int64 result; // rax
char v10[136]; // [rsp+0h] [rbp-B8h] BYREF
char *sa; // [rsp+88h] [rbp-30h] BYREF

v3 = a2;
printmsg(3LL, "Pack\n");
v4 = cfg;
v5 = strlen(cfg);
v6 = strlen(s);
v7 = (char *)malloc(v5 + v6 + 3);
sa = v7;
if ( v7 )
{
sprintf(v7, "%s %s ", v4, s);
if ( a2 )
{
do
{
sprintf(v10, "%s%s ", *(&cfg + 4), (const char *)v3);
v8 = strlen(sa);
((void (__fastcall *)(char **, _QWORD, size_t, char *))replacestring)(&sa, 0LL, v8, v10);
v3 = *(_QWORD *)(v3 + 16);
}
while ( v3 );
}
system(sa);
result = 0LL;
}
else
{
printmsg(0LL, "Can't allocate memory\n");
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *s, __int64 a2)
{
__int64 v3; // rbx
const char *v4; // r13
size_t v5; // r12
size_t v6; // rax
char *v7; // rdi
size_t v8; // rax
__int64 result; // rax
char v10[136]; // [rsp+0h] [rbp-B8h] BYREF
char *sa; // [rsp+88h] [rbp-30h] BYREF

v3 = a2;
printmsg(3LL, "Pack\n");
v4 = cfg;
v5 = strlen(cfg);
v6 = strlen(s);
v7 = (char *)malloc(v5 + v6 + 3);
sa = v7;
if ( v7 )
{
sprintf(v7, "%s %s ", v4, s);
if ( a2 )
{
do
{
sprintf(v10, "%s%s ", *(&cfg + 4), (const char *)v3);
v8 = strlen(sa);
((void (__fastcall *)(char **, _QWORD, size_t, char *))replacestring)(&sa, 0LL, v8, v10);
v3 = *(_QWORD *)(v3 + 16);
}
while ( v3 );
}
system(sa);
result = 0LL;
}
else
{
printmsg(0LL, "Can't allocate memory\n");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int pack(char *name,struct namelist *root) {
char *buf;
char buf2[128];
int len;
struct namelist *wlk;
 wlk=root;
 printmsg(3,"Pack\n");
 buf=malloc(sizeof(char)*(strlen(cfg.PACK)+strlen(name)+3));
 if (buf==((void *)0)) {
  printmsg(0,"Can't allocate memory\n");
  return(-1);
 }
 sprintf(buf,"%s %s ",cfg.PACK,name);
 while(wlk!=((void *)0)) {
  sprintf(buf2,"%s%s ",cfg.OUTBOUND,wlk->name);
  len=strlen(buf);
  replacestring(&buf,0,strlen(buf),buf2);
  wlk=wlk->next;
 }
 system(buf);
 return(0);
}

canonical_original_code:
int pack(char *name, struct namelist *root) {
char *buf;
char buf2[128];
int len;
struct namelist *wlk;
 wlk=root;
 printmsg(3,"Pack\n");
 buf=malloc(sizeof(char)*(strlen(cfg.PACK)+strlen(name)+3));
 if (buf==((void *)0)) {
  printmsg(0,"Can't allocate memory\n");
  return(-1);
 }
 sprintf(buf,"%s %s ",cfg.PACK,name);
 while(wlk!=((void *)0)) {
  sprintf(buf2,"%s%s ",cfg.OUTBOUND,wlk->name);
  len=strlen(buf);
  replacestring(&buf,0,strlen(buf),buf2);
  wlk=wlk->next;
 }
 system(buf);
 return(0);
}

variable_types:
name
char *

variable_types: struct namelist { char name[13]; struct namelist *next; } *

variable_types:
buf
char *

variable_types: len int


addpackets

decompiled_code:
__int64 __fastcall addpackets(__int64 a1, __int64 a2, __int64 a3)
{
const char *v3; // rbp
__int64 v6; // r12
__int64 v7; // rbx
__int64 v8; // r13
char *v9; // rax
__int64 v10; // rbp
const char *v12; // rsi
const char *v13; // rsi
const char *v14; // rsi
char dest[128]; // [rsp+10h] [rbp-108h] BYREF
char v16[64]; // [rsp+90h] [rbp-88h] BYREF
__int64 v17; // [rsp+D0h] [rbp-48h]
__int64 v18; // [rsp+D8h] [rbp-40h]

v18 = 0LL;
v17 = 0LL;
v3 = *(const char **)(a1 + 24);
if ( v3 )
{
v6 = a1 + 32;
v7 = 0LL;
do
{
v8 = v7;
v9 = (char *)malloc(0x18uLL);
v7 = (__int64)v9;
if ( !v9 )
{
printmsg(0LL, "Addpacket : Memory allocation error\n");
return 0xFFFFFFFFLL;
}
*((_QWORD *)v9 + 2) = v8;
strncpy(v9, v3, 0xCuLL);
*(_BYTE *)(v7 + 12) = 0;
v6 += 8LL;
v3 = *(const char **)(v6 - 8);
}
while ( v3 );
v10 = v7;
do
{
sprintf(dest, "\nProcessing : %s\n", (const char *)v10);
printmsg(1LL, dest);
v12 = *(&cfg + 4);
if ( v12 )
{
strcpy(dest, v12);
strcat(dest, (const char *)v10);
}
else
{
strcpy(dest, (const char *)v10);
}
readpacket(dest, v16);
modifypacket(v16, a2, a3);
writepacket(dest, v16);
v13 = *(&cfg + 7);
if ( v13 )
{
strcpy(dest, v13);
strcat(dest, (const char *)v10);
writepacket(dest, v16);
}
cleanuppacket(v16);
v10 = *(_QWORD *)(v10 + 16);
}
while ( v10 );
}
else
{
v7 = 0LL;
}
v14 = *(&cfg + 4);
if ( v14 )
{
strcpy(dest, v14);
strcat(dest, *(const char **)(a1 + 16));
}
else
{
strcpy(dest, *(const char **)(a1 + 16));
}
pack(dest, v7);
cleanupnamelist(v7);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, __int64 a3)
{
const char *v3; // rbp
__int64 v6; // r12
__int64 v7; // rbx
__int64 v8; // r13
char *v9; // rax
__int64 v10; // rbp
const char *v12; // rsi
const char *v13; // rsi
const char *v14; // rsi
char dest[128]; // [rsp+10h] [rbp-108h] BYREF
char v16[64]; // [rsp+90h] [rbp-88h] BYREF
__int64 v17; // [rsp+D0h] [rbp-48h]
__int64 v18; // [rsp+D8h] [rbp-40h]

v18 = 0LL;
v17 = 0LL;
v3 = *(const char **)(a1 + 24);
if ( v3 )
{
v6 = a1 + 32;
v7 = 0LL;
do
{
v8 = v7;
v9 = (char *)malloc(0x18uLL);
v7 = (__int64)v9;
if ( !v9 )
{
printmsg(0LL, "Addpacket : Memory allocation error\n");
return 0xFFFFFFFFLL;
}
*((_QWORD *)v9 + 2) = v8;
strncpy(v9, v3, 0xCuLL);
*(_BYTE *)(v7 + 12) = 0;
v6 += 8LL;
v3 = *(const char **)(v6 - 8);
}
while ( v3 );
v10 = v7;
do
{
sprintf(dest, "\nProcessing : %s\n", (const char *)v10);
printmsg(1LL, dest);
v12 = *(&cfg + 4);
if ( v12 )
{
strcpy(dest, v12);
strcat(dest, (const char *)v10);
}
else
{
strcpy(dest, (const char *)v10);
}
readpacket(dest, v16);
modifypacket(v16, a2, a3);
writepacket(dest, v16);
v13 = *(&cfg + 7);
if ( v13 )
{
strcpy(dest, v13);
strcat(dest, (const char *)v10);
writepacket(dest, v16);
}
cleanuppacket(v16);
v10 = *(_QWORD *)(v10 + 16);
}
while ( v10 );
}
else
{
v7 = 0LL;
}
v14 = *(&cfg + 4);
if ( v14 )
{
strcpy(dest, v14);
strcat(dest, *(const char **)(a1 + 16));
}
else
{
strcpy(dest, *(const char **)(a1 + 16));
}
func0(dest, v7);
cleanupnamelist(v7);
return 0LL;
}

original_code:
int addpackets(char *argv[],struct reroutetab *rrt,struct kludges *kl) {
struct packet pakt;
struct namelist *root,*wlk;
int ind;
char txt[128];
 pakt.thread=((void *)0);
 pakt.root=((void *)0);
 root=((void *)0);
 ind=3;
 while(argv[ind]!=((void *)0)) {
  wlk=malloc(sizeof(struct namelist));
  if (wlk==((void *)0)) {
   printmsg(0,"Addpacket : Memory allocation error\n");
   return(-1);
  }
  wlk->next=root;
  root=wlk;
  strncpy(wlk->name,argv[ind],12);
  wlk->name[12]='\0';
  ind++;
 }
 wlk=root;
 while(wlk!=((void *)0)) {
  sprintf(txt,"\nProcessing : %s\n",wlk->name);
  printmsg(1,txt);
  if (cfg.OUTBOUND!=((void *)0)) {
   strcpy(txt,cfg.OUTBOUND);
   strcat(txt,wlk->name);
  } else {
   strcpy(txt,wlk->name);
  }
  readpacket(txt,&pakt);
  modifypacket(&pakt,rrt,kl);
  writepacket(txt,&pakt);
  if (cfg.BACKUP!=((void *)0)) {
   strcpy(txt,cfg.BACKUP);
   strcat(txt,wlk->name);
   writepacket(txt,&pakt);
  }
  cleanuppacket(&pakt);
  wlk=wlk->next;
 }
 if (cfg.OUTBOUND!=((void *)0)) {
  strcpy(txt,cfg.OUTBOUND);
  strcat(txt,argv[2]);
 } else {
  strcpy(txt,argv[2]);
 }
 pack(txt,root);
 cleanupnamelist(root);
 return(0);
}

canonical_original_code:
int addpackets(char *argv[], struct reroutetab *rrt, struct kludges *kl) {
struct packet pakt;
struct namelist *root; struct namelist *wlk;
int ind;
char txt[128];
 pakt.thread=((void *)0);
 pakt.root=((void *)0);
 root=((void *)0);
 ind=3;
 while(argv[ind]!=((void *)0)) {
  wlk=malloc(sizeof(struct namelist));
  if (wlk==((void *)0)) {
   printmsg(0,"Addpacket : Memory allocation error\n");
   return(-1);
  }
  wlk->next=root;
  root=wlk;
  strncpy(wlk->name,argv[ind],12);
  wlk->name[12]='\0';
  ind++;
 }
 wlk=root;
 while(wlk!=((void *)0)) {
  sprintf(txt,"\nProcessing : %s\n",wlk->name);
  printmsg(1,txt);
  if (cfg.OUTBOUND!=((void *)0)) {
   strcpy(txt,cfg.OUTBOUND);
   strcat(txt,wlk->name);
  } else {
   strcpy(txt,wlk->name);
  }
  readpacket(txt,&pakt);
  modifypacket(&pakt,rrt,kl);
  writepacket(txt,&pakt);
  if (cfg.BACKUP!=((void *)0)) {
   strcpy(txt,cfg.BACKUP);
   strcat(txt,wlk->name);
   writepacket(txt,&pakt);
  }
  cleanuppacket(&pakt);
  wlk=wlk->next;
 }
 if (cfg.OUTBOUND!=((void *)0)) {
  strcpy(txt,cfg.OUTBOUND);
  strcat(txt,argv[2]);
 } else {
  strcpy(txt,argv[2]);
 }
 pack(txt,root);
 cleanupnamelist(root);
 return(0);
}

variable_types:
argv
char *[]

variable_types: struct packet { struct PacketHeader { unsigned char origNodeLO; unsigned char origNodeHI; unsigned char destNodeLO; unsigned char destNodeHI; unsigned char yearLO; unsigned char yearHI; unsigned char monthLO; unsigned char monthHI; unsigned char dayLO; unsigned char dayHI; unsigned char hourLO; unsigned char hourHI; unsigned char minuteLO; unsigned char minuteHI; unsigned char secondLO; unsigned char secondHI; unsigned char baudLO; unsigned char baudHI; unsigned char ID1; unsigned char ID2; unsigned char origNetLO; unsigned char origNetHI; unsigned char destNetLO; unsigned char destNetHI; unsigned char prodcode; unsigned char serialno; unsigned char password[8]; unsigned char origZoneLO; unsigned char origZoneHI; unsigned char destZoneLO; unsigned char destZoneHI; unsigned char fill[20]; } pkh; struct msglist { struct msglist *next; struct PackedMessage { unsigned char origNodeLO; unsigned char origNodeHI; unsigned char destNodeLO; unsigned char destNodeHI; unsigned char origNetLO; unsigned char origNetHI; unsigned char destNetLO; unsigned char destNetHI; unsigned char AttributeLO; unsigned char AttributeHI; unsigned char costLO; unsigned char costHI; unsigned char DateTime[20]; } pmsg; char FromUser[36]; char ToUser[36]; char Subject[72]; char *Text; } *root; }

variable_types: ind int

variable_types:
txt
char [128]

user_defined_types: struct namelist { char name[13]; struct namelist *next; }

user_defined_types: struct kludge { char *kludge; char *spec; char *repl; }


unpack

decompiled_code:
__int64 __fastcall unpack(char *src, char **a2)
{
const char *v3; // rbp
size_t v4; // rbx
size_t v5; // rax
char *v6; // rax
char *v7; // rbx
char v8; // dl
__int64 v9; // rax
int v10; // esi
__int64 i; // rcx
int v12; // esi
__int64 result; // rax

printmsg(3LL, "UnPack\n");
v3 = *(&cfg + 1);
v4 = strlen(v3);
v5 = strlen(src);
v6 = (char *)malloc(v4 + v5 + 8);
if ( v6 )
{
v7 = v6;
v8 = *v3;
v9 = 1LL;
v10 = 0;
for ( i = 0LL; v8 != 32; v8 = v3[v9 - 1] )
{
v7[v9 - 1] = v8;
v10 = v9;
i = v9++;
}
v7[i] = 32;
v12 = v10 + 1;
v7[v12] = 0;
strcat(v7, ">tmp ");
strcat(v7, &v3[v12]);
*(_WORD *)&v7[strlen(v7)] = 32;
strcat(v7, src);
system(v7);
findnames(a2, "tmp");
system("delete tmp");
result = 0LL;
}
else
{
printf(0LL, "Can't allocate memory", &unk_73D);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *src, char **a2)
{
const char *v3; // rbp
size_t v4; // rbx
size_t v5; // rax
char *v6; // rax
char *v7; // rbx
char v8; // dl
__int64 v9; // rax
int v10; // esi
__int64 i; // rcx
int v12; // esi
__int64 result; // rax

printmsg(3LL, "UnPack\n");
v3 = *(&cfg + 1);
v4 = strlen(v3);
v5 = strlen(src);
v6 = (char *)malloc(v4 + v5 + 8);
if ( v6 )
{
v7 = v6;
v8 = *v3;
v9 = 1LL;
v10 = 0;
for ( i = 0LL; v8 != 32; v8 = v3[v9 - 1] )
{
v7[v9 - 1] = v8;
v10 = v9;
i = v9++;
}
v7[i] = 32;
v12 = v10 + 1;
v7[v12] = 0;
strcat(v7, ">tmp ");
strcat(v7, &v3[v12]);
*(_WORD *)&v7[strlen(v7)] = 32;
strcat(v7, src);
system(v7);
func2(a2, "tmp");
system("delete tmp");
result = 0LL;
}
else
{
printf(0LL, "Can't allocate memory", &unk_73D);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int unpack(char *name,struct namelist **root) {
char *buf;
int pos;
 printmsg(3,"UnPack\n");
 buf=malloc(sizeof(char)*(strlen(cfg.UNPACK)+strlen(name)+strlen(">tmp ")+3));
 if (buf==((void *)0)) {
  printf(0,"Can't allocate memory","");
  return(-1);
 }
 pos=0;
 while(cfg.UNPACK[pos]!=' ') {
  buf[pos]=cfg.UNPACK[pos];
  pos++;
 }
 buf[pos]=cfg.UNPACK[pos];
 pos++;
 buf[pos]='\0';
 strcat(buf,">tmp ");
 strcat(buf,&(cfg.UNPACK[pos]));
 strcat(buf," ");
 strcat(buf,name);
 system(buf);
 findnames(root,"tmp");
 system("delete tmp");
 return(0);
}

canonical_original_code:
int unpack(char *name, struct namelist **root) {
char *buf;
int pos;
 printmsg(3,"UnPack\n");
 buf=malloc(sizeof(char)*(strlen(cfg.UNPACK)+strlen(name)+strlen(">tmp ")+3));
 if (buf==((void *)0)) {
  printf(0,"Can't allocate memory","");
  return(-1);
 }
 pos=0;
 while(cfg.UNPACK[pos]!=' ') {
  buf[pos]=cfg.UNPACK[pos];
  pos++;
 }
 buf[pos]=cfg.UNPACK[pos];
 pos++;
 buf[pos]='\0';
 strcat(buf,">tmp ");
 strcat(buf,&(cfg.UNPACK[pos]));
 strcat(buf," ");
 strcat(buf,name);
 system(buf);
 findnames(root,"tmp");
 system("delete tmp");
 return(0);
}

variable_types: struct namelist { char name[13]; struct namelist *next; } **

variable_types: pos int


extractpackets

decompiled_code:
__int64 __fastcall extractpackets(__int64 a1, __int64 a2, __int64 a3)
{
const char *v5; // rsi
char *i; // rbx
const char *v8; // rsi
const char *v9; // rsi
char v10[136]; // [rsp+0h] [rbp-108h] BYREF
char *src; // [rsp+88h] [rbp-80h] BYREF
char v12[64]; // [rsp+90h] [rbp-78h] BYREF
__int64 v13; // [rsp+D0h] [rbp-38h]
__int64 v14; // [rsp+D8h] [rbp-30h]

v14 = 0LL;
v13 = 0LL;
src = 0LL;
v5 = *(&cfg + 3);
if ( v5 )
{
strcpy(v10, v5);
strcat(v10, *(const char **)(a1 + 16));
}
else
{
strcpy(v10, *(const char **)(a1 + 16));
}
unpack(v10, &src);
for ( i = src; i; i = (char *)*((_QWORD *)i + 2) )
{
sprintf(v10, "\nProcessing : %s\n", i);
printmsg(1LL, v10);
v8 = *(&cfg + 3);
if ( v8 )
{
strcpy(v10, v8);
strcat(v10, i);
}
else
{
strcpy(v10, i);
}
readpacket(v10, v12);
modifypacket(v12, a2, a3);
writepacket(v10, v12);
v9 = *(&cfg + 7);
if ( v9 )
{
strcpy(v10, v9);
strcat(v10, i);
writepacket(v10, v12);
}
cleanuppacket(v12);
}
cleanupnamelist(src);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2, __int64 a3)
{
const char *v5; // rsi
char *i; // rbx
const char *v8; // rsi
const char *v9; // rsi
char v10[136]; // [rsp+0h] [rbp-108h] BYREF
char *src; // [rsp+88h] [rbp-80h] BYREF
char v12[64]; // [rsp+90h] [rbp-78h] BYREF
__int64 v13; // [rsp+D0h] [rbp-38h]
__int64 v14; // [rsp+D8h] [rbp-30h]

v14 = 0LL;
v13 = 0LL;
src = 0LL;
v5 = *(&cfg + 3);
if ( v5 )
{
strcpy(v10, v5);
strcat(v10, *(const char **)(a1 + 16));
}
else
{
strcpy(v10, *(const char **)(a1 + 16));
}
func3(v10, &src);
for ( i = src; i; i = (char *)*((_QWORD *)i + 2) )
{
sprintf(v10, "\nProcessing : %s\n", i);
printmsg(1LL, v10);
v8 = *(&cfg + 3);
if ( v8 )
{
strcpy(v10, v8);
strcat(v10, i);
}
else
{
strcpy(v10, i);
}
readpacket(v10, v12);
modifypacket(v12, a2, a3);
writepacket(v10, v12);
v9 = *(&cfg + 7);
if ( v9 )
{
strcpy(v10, v9);
strcat(v10, i);
writepacket(v10, v12);
}
cleanuppacket(v12);
}
cleanupnamelist(src);
return 0LL;
}

original_code:
int extractpackets(char *argv[],struct reroutetab *rrt,struct kludges *kl) {
struct packet pakt;
struct namelist *root,*wlk;
char txt[128];
 pakt.thread=((void *)0);
 pakt.root=((void *)0);
 root=((void *)0);
 if (cfg.INBOUND!=((void *)0)) {
  strcpy(txt,cfg.INBOUND);
  strcat(txt,argv[2]);
 } else {
  strcpy(txt,argv[2]);
 }
 unpack(txt,&root);
 wlk=root;
 while(wlk!=((void *)0)) {
  sprintf(txt,"\nProcessing : %s\n",wlk->name);
  printmsg(1,txt);
  if (cfg.INBOUND!=((void *)0)) {
   strcpy(txt,cfg.INBOUND);
   strcat(txt,wlk->name);
  } else {
   strcpy(txt,wlk->name);
  }
  readpacket(txt,&pakt);
  modifypacket(&pakt,rrt,kl);
  writepacket(txt,&pakt);
  if (cfg.BACKUP!=((void *)0)) {
   strcpy(txt,cfg.BACKUP);
   strcat(txt,wlk->name);
   writepacket(txt,&pakt);
  }
  cleanuppacket(&pakt);
  wlk=wlk->next;
 }
 cleanupnamelist(root);
 return(0);
}

canonical_original_code:
int extractpackets(char *argv[], struct reroutetab *rrt, struct kludges *kl) {
struct packet pakt;
struct namelist *root; struct namelist *wlk;
char txt[128];
 pakt.thread=((void *)0);
 pakt.root=((void *)0);
 root=((void *)0);
 if (cfg.INBOUND!=((void *)0)) {
  strcpy(txt,cfg.INBOUND);
  strcat(txt,argv[2]);
 } else {
  strcpy(txt,argv[2]);
 }
 unpack(txt,&root);
 wlk=root;
 while(wlk!=((void *)0)) {
  sprintf(txt,"\nProcessing : %s\n",wlk->name);
  printmsg(1,txt);
  if (cfg.INBOUND!=((void *)0)) {
   strcpy(txt,cfg.INBOUND);
   strcat(txt,wlk->name);
  } else {
   strcpy(txt,wlk->name);
  }
  readpacket(txt,&pakt);
  modifypacket(&pakt,rrt,kl);
  writepacket(txt,&pakt);
  if (cfg.BACKUP!=((void *)0)) {
   strcpy(txt,cfg.BACKUP);
   strcat(txt,wlk->name);
   writepacket(txt,&pakt);
  }
  cleanuppacket(&pakt);
  wlk=wlk->next;
 }
 cleanupnamelist(root);
 return(0);
}

variable_types: struct reroutetab { struct rrlist { struct rrlist *next; struct fidaddr { int Zone; int Net; int Node; int Point; } in; } *orgroot; struct rrlist *dstroot; } *

user_defined_types: struct PacketHeader { unsigned char origNodeLO; unsigned char origNodeHI; unsigned char destNodeLO; unsigned char destNodeHI; unsigned char yearLO; unsigned char yearHI; unsigned char monthLO; unsigned char monthHI; unsigned char dayLO; unsigned char dayHI; unsigned char hourLO; unsigned char hourHI; unsigned char minuteLO; unsigned char minuteHI; unsigned char secondLO; unsigned char secondHI; unsigned char baudLO; unsigned char baudHI; unsigned char ID1; unsigned char ID2; unsigned char origNetLO; unsigned char origNetHI; unsigned char destNetLO; unsigned char destNetHI; unsigned char prodcode; unsigned char serialno; unsigned char password[8]; unsigned char origZoneLO; unsigned char origZoneHI; unsigned char destZoneLO; unsigned char destZoneHI; unsigned char fill[20]; }

user_defined_types: struct PackedMessage { unsigned char origNodeLO; unsigned char origNodeHI; unsigned char destNodeLO; unsigned char destNodeHI; unsigned char origNetLO; unsigned char origNetHI; unsigned char destNetLO; unsigned char destNetHI; unsigned char AttributeLO; unsigned char AttributeHI; unsigned char costLO; unsigned char costHI; unsigned char DateTime[20]; }


decide

decompiled_code:
__int64 __fastcall decide(int a1, int a2, int a3)
{
int v3; // eax
__int64 result; // rax

if ( a1 == -1 )
{
LOBYTE(v3) = a2 != -1;
result = (unsigned int)(v3 + 1);
}
else
{
LOBYTE(v3) = a1 == a3;
result = (unsigned int)(2 * v3);
}
return result;
}

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

if ( a1 == -1 )
{
LOBYTE(v3) = a2 != -1;
result = (unsigned int)(v3 + 1);
}
else
{
LOBYTE(v3) = a1 == a3;
result = (unsigned int)(2 * v3);
}
return result;
}

original_code:
char decide(int in,int out,int chg) {
char match;
 match=(0);
 if (in==(-1)) {
  if (out==(-1)) {
   match=(1);
  } else {
   match=(2);
  }
 } else {
  if (chg==in) {
   match=(2);
  }
 }
 return(match);
}

canonical_original_code:
char decide(int in, int out, int chg) {
char match;
 match=(0);
 if (in==(-1)) {
  if (out==(-1)) {
   match=(1);
  } else {
   match=(2);
  }
 } else {
  if (chg==in) {
   match=(2);
  }
 }
 return(match);
}

variable_types: in int

variable_types: out int

variable_types: chg int

variable_types: match char

return_type: char


dochange

original_code:
int dochange(struct fidaddr *chg,struct rrlist *root) {
int rtn=0;
char txt[255];
char matchZone,matchNet,matchNode,matchPoint;
 printmsg(3,"DoChange\n");
 while(root!=((void *)0) && rtn==0) {
  matchZone=matchNet=matchNode=matchPoint=(0);
  matchZone=decide(root->in.Zone,root->out.Zone,chg->Zone);
  matchNet=decide(root->in.Net,root->out.Net,chg->Net);
  matchNode=decide(root->in.Node,root->out.Node,chg->Node);
  matchPoint=decide(root->in.Point,root->out.Point,chg->Point);
  if (matchZone!=(0) && matchNet!=(0) && matchNode!=(0) && matchPoint!=(0)) {
   sprintf(txt,"Address modified from : %d:%d/%d.%d",chg->Zone,chg->Net,chg->Node,chg->Point);
   printmsg(1,txt);
   if (matchZone==(2)) {
    chg->Zone=root->out.Zone;
   }
   if (matchNet==(2)) {
    chg->Net=root->out.Net;
   }
   if (matchNode==(2)) {
    chg->Node=root->out.Node;
   }
   if (matchPoint==(2)) {
    chg->Point=root->out.Point;
   }
   sprintf(txt," to %d:%d/%d.%d\n",chg->Zone,chg->Net,chg->Node,chg->Point);
   printmsg(1,txt);
   rtn=1;
  }
  root=root->next;
 }
 return(rtn);
}

canonical_original_code:
int dochange(struct fidaddr *chg, struct rrlist *root) {
int rtn = 0;
char txt[255];
char matchZone; char matchNet; char matchNode; char matchPoint;
 printmsg(3,"DoChange\n");
 while(root!=((void *)0) && rtn==0) {
  matchZone=matchNet=matchNode=matchPoint=(0);
  matchZone=decide(root->in.Zone,root->out.Zone,chg->Zone);
  matchNet=decide(root->in.Net,root->out.Net,chg->Net);
  matchNode=decide(root->in.Node,root->out.Node,chg->Node);
  matchPoint=decide(root->in.Point,root->out.Point,chg->Point);
  if (matchZone!=(0) && matchNet!=(0) && matchNode!=(0) && matchPoint!=(0)) {
   sprintf(txt,"Address modified from : %d:%d/%d.%d",chg->Zone,chg->Net,chg->Node,chg->Point);
   printmsg(1,txt);
   if (matchZone==(2)) {
    chg->Zone=root->out.Zone;
   }
   if (matchNet==(2)) {
    chg->Net=root->out.Net;
   }
   if (matchNode==(2)) {
    chg->Node=root->out.Node;
   }
   if (matchPoint==(2)) {
    chg->Point=root->out.Point;
   }
   sprintf(txt," to %d:%d/%d.%d\n",chg->Zone,chg->Net,chg->Node,chg->Point);
   printmsg(1,txt);
   rtn=1;
  }
  root=root->next;
 }
 return(rtn);
}

variable_types: struct fidaddr { int Zone; int Net; int Node; int Point; } *

variable_types: struct rrlist { struct rrlist *next; struct fidaddr in; } *

variable_types: rtn int

variable_types:
txt
char [255]

variable_types: matchZone char

variable_types: matchNet char

variable_types: matchNode char

variable_types: matchPoint char


changeaddr

decompiled_code:
__int64 __fastcall changeaddr(__int64 a1, unsigned int a2, unsigned int a3, __int64 *a4, unsigned int *a5, int a6)
{
char *v11; // rax
char *v12; // rbp

printmsg(3LL, "ChangeAddr\n");
if ( (unsigned int)dochange(a5, a4) == 1 )
{
v11 = (char *)malloc(0x19uLL);
v12 = v11;
*v11 = 0;
if ( a6 > 7 )
{
switch ( a6 )
{
case 11:
sprintf(v11, "%d/%d.%d", a5[1], a5[2], a5[3]);
goto LABEL_9;
case 12:
sprintf(v11, "%d:%d/%d.%d", *a5, a5[1], a5[2], a5[3]);
goto LABEL_9;
case 10:
sprintf(v11, "%d.%d", a5[2], a5[3]);
goto LABEL_9;
}
}
else
{
switch ( a6 )
{
case 2:
sprintf(v11, "%d/%d", a5[1], a5[2]);
goto LABEL_9;
case 3:
sprintf(v11, "%d:%d/%d", *a5, a5[1], a5[2]);
goto LABEL_9;
case 1:
sprintf(v11, "%d", a5[2]);
goto LABEL_9;
}
}
printmsg(0LL, "Address rebuild error\n");
LABEL_9:
replacestring(a1, a3, a2, v12);
free(v12);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, unsigned int a2, unsigned int a3, __int64 *a4, unsigned int *a5, int a6)
{
char *v11; // rax
char *v12; // rbp

printmsg(3LL, "ChangeAddr\n");
if ( (unsigned int)func1(a5, a4) == 1 )
{
v11 = (char *)malloc(0x19uLL);
v12 = v11;
*v11 = 0;
if ( a6 > 7 )
{
switch ( a6 )
{
case 11:
sprintf(v11, "%d/%d.%d", a5[1], a5[2], a5[3]);
goto LABEL_9;
case 12:
sprintf(v11, "%d:%d/%d.%d", *a5, a5[1], a5[2], a5[3]);
goto LABEL_9;
case 10:
sprintf(v11, "%d.%d", a5[2], a5[3]);
goto LABEL_9;
}
}
else
{
switch ( a6 )
{
case 2:
sprintf(v11, "%d/%d", a5[1], a5[2]);
goto LABEL_9;
case 3:
sprintf(v11, "%d:%d/%d", *a5, a5[1], a5[2]);
goto LABEL_9;
case 1:
sprintf(v11, "%d", a5[2]);
goto LABEL_9;
}
}
printmsg(0LL, "Address rebuild error\n");
LABEL_9:
replacestring(a1, a3, a2, v12);
free(v12);
}
return 0LL;
}

original_code:
int changeaddr(char **text,int pos,int lentxt,struct rrlist *root,struct fidaddr *fd,int type) {
 printmsg(3,"ChangeAddr\n");
 if (dochange(fd,root)==1) {
  char *buf;
  buf=(char *)malloc(sizeof(char)*25);
  buf[0]='\0';
  if (type<8) {
   switch(type) {
    case 3 : sprintf(buf,"%d:%d/%d",fd->Zone,fd->Net,fd->Node);
       break;
    case 2 : sprintf(buf,"%d/%d",fd->Net,fd->Node);
       break;
    case 1 : sprintf(buf,"%d",fd->Node);
       break;
    default: printmsg(0,"Address rebuild error\n");
       break;
   }
  } else {
   type-=8;
   switch(type) {
    case 4 : sprintf(buf,"%d:%d/%d.%d",fd->Zone,fd->Net,fd->Node,fd->Point);
       break;
    case 3 : sprintf(buf,"%d/%d.%d",fd->Net,fd->Node,fd->Point);
       break;
    case 2 : sprintf(buf,"%d.%d",fd->Node,fd->Point);
       break;
    default: printmsg(0,"Address rebuild error\n");
       break;
   }
  }
  replacestring(text,lentxt,pos,buf);
  free((void *)buf);
 }
 return(0);
}

canonical_original_code:
int changeaddr(char **text, int pos, int lentxt, struct rrlist *root, struct fidaddr *fd, int type) {
 printmsg(3,"ChangeAddr\n");
 if (dochange(fd,root)==1) {
  char *buf;
  buf=(char *)malloc(sizeof(char)*25);
  buf[0]='\0';
  if (type<8) {
   switch(type) {
    case 3 : sprintf(buf,"%d:%d/%d",fd->Zone,fd->Net,fd->Node);
       break;
    case 2 : sprintf(buf,"%d/%d",fd->Net,fd->Node);
       break;
    case 1 : sprintf(buf,"%d",fd->Node);
       break;
    default: printmsg(0,"Address rebuild error\n");
       break;
   }
  } else {
   type-=8;
   switch(type) {
    case 4 : sprintf(buf,"%d:%d/%d.%d",fd->Zone,fd->Net,fd->Node,fd->Point);
       break;
    case 3 : sprintf(buf,"%d/%d.%d",fd->Net,fd->Node,fd->Point);
       break;
    case 2 : sprintf(buf,"%d.%d",fd->Node,fd->Point);
       break;
    default: printmsg(0,"Address rebuild error\n");
       break;
   }
  }
  replacestring(text,lentxt,pos,buf);
  free((void *)buf);
 }
 return(0);
}

variable_types:
text
char **

variable_types: lentxt int

variable_types: struct rrlist { struct rrlist *next; struct fidaddr { int Zone; int Net; int Node; int Point; } in; } *

variable_types:
fd
struct fidaddr *

variable_types: type int

variable_types:
buf
char *


printmsg

decompiled_code:
__int64 __fastcall printmsg(int a1, const char *a2)
{
if ( cfg[10] > a1 )
fputs(a2, stderr);
if ( logfile && cfg[11] > a1 )
fputs(a2, logfile);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, const char *a2)
{
if ( cfg[10] > a1 )
fputs(a2, stderr);
if ( logfile && cfg[11] > a1 )
fputs(a2, logfile);
return 0LL;
}

original_code:
int printmsg(int level,char *msg) {
 if (cfg.VERBOSE>level) {
  fprintf(stderr,"%s",msg);
 }
 if (logfile!=((void *)0) && cfg.LOGLEVEL>level) {
  fprintf(logfile,"%s",msg);
 }
 return(0);
}

canonical_original_code:
int printmsg(int level, char *msg) {
 if (cfg.VERBOSE>level) {
  fprintf(stderr,"%s",msg);
 }
 if (logfile!=((void *)0) && cfg.LOGLEVEL>level) {
  fprintf(logfile,"%s",msg);
 }
 return(0);
}

variable_types: level int

variable_types:
msg
char *


replacestring

decompiled_code:
__int64 __fastcall replacestring(const char **a1, int a2, int a3, const char *a4)
{
int v6; // er12
char *v7; // r15
const char *v8; // rbx
__int64 v9; // r15
int v10; // edx
const char *v11; // rax
__int64 v12; // rsi
char *v13; // rbx
size_t v14; // rax
const char *v15; // rax
__int64 v16; // rax
__int64 v17; // rdx
size_t v19; // rax
const char *v20; // rax
int v21; // eax
unsigned int v22; // edx
__int64 v23; // rcx
const char *v24; // rax

printmsg(3, "Replacestring\n");
v6 = strlen(a4);
v7 = (char *)*a1;
v8 = &(*a1)[a3];
if ( v6 == a2 )
goto LABEL_8;
if ( v6 - a2 >= 0 )
{
v19 = strlen(v7);
v20 = (const char *)realloc(v7, v6 - a2 + v19 + 1);
if ( v20 )
{
*a1 = v20;
v8 = &v20[a3];
v21 = strlen(&v8[a2]);
v22 = v21;
if ( v21 >= 0 )
{
v23 = v21;
v24 = &v8[a2 + (__int64)v21];
do
{
v24[v6 - a2] = *v24;
--v24;
}
while ( v24 != &v8[a2 - 1 + v23 - v22] );
}
goto LABEL_8;
}
LABEL_12:
printmsg(0, "Can't reallocate memory\n");
return 0xFFFFFFFFLL;
}
v9 = a2;
v10 = strlen(&v8[a2]);
if ( v10 >= 0 )
{
v11 = &v8[a2];
v12 = (__int64)&v11[v10 + 1];
do
{
v11[v6 - v9] = *v11;
++v11;
}
while ( v11 != (const char *)v12 );
}
v13 = (char *)*a1;
v14 = strlen(*a1);
v15 = (const char *)realloc(v13, v14 + 1);
if ( !v15 )
goto LABEL_12;
*a1 = v15;
v8 = &v15[a3];
LABEL_8:
if ( v6 <= 0 )
return 0LL;
v16 = 0LL;
do
{
v8[v16] = a4[v16];
v17 = v16++;
}
while ( v17 != v6 - 1 );
return 0LL;
}

original_code:
int replacestring(char **text,int replacelen,int pos,char *string) {
int q,l,shift,len;
char *tmp,*ps;
 printmsg(3,"Replacestring\n");
 len=strlen(string);
 shift=len-replacelen;
 ps=(*text)+pos;
 if (shift!=0) {
  if (shift<0) {
   l=strlen(ps+replacelen);
   for (q=0;q<=l;q++) ps[len+q]=ps[replacelen+q];
   tmp=realloc(*text,strlen(*text)+1);
   if (tmp==((void *)0)) {
    printmsg(0,"Can't reallocate memory\n");
    return(-1);
   }
   *text=tmp;
   ps=*text+pos;
  } else {
   tmp=realloc(*text,strlen(*text)+shift+1);
   if (tmp==((void *)0)) {
    printmsg(0,"Can't reallocate memory\n");
    return(-1);
   }
   *text=tmp;
   ps=*text+pos;
   l=strlen(ps+replacelen);
   for (q=l;q>=0;q--) ps[q+len]=ps[q+replacelen];
  }
 }
 for (q=0;q<len;q++) ps[q]=string[q];
 return(0);
}

canonical_original_code:
int replacestring(char **text, int replacelen, int pos, char *string) {
int q; int l; int shift; int len;
char *tmp; char *ps;
 printmsg(3,"Replacestring\n");
 len=strlen(string);
 shift=len-replacelen;
 ps=(*text)+pos;
 if (shift!=0) {
  if (shift<0) {
   l=strlen(ps+replacelen);
   for (q=0;q<=l;q++) ps[len+q]=ps[replacelen+q];
   tmp=realloc(*text,strlen(*text)+1);
   if (tmp==((void *)0)) {
    printmsg(0,"Can't reallocate memory\n");
    return(-1);
   }
   *text=tmp;
   ps=*text+pos;
  } else {
   tmp=realloc(*text,strlen(*text)+shift+1);
   if (tmp==((void *)0)) {
    printmsg(0,"Can't reallocate memory\n");
    return(-1);
   }
   *text=tmp;
   ps=*text+pos;
   l=strlen(ps+replacelen);
   for (q=l;q>=0;q--) ps[q+len]=ps[q+replacelen];
  }
 }
 for (q=0;q<len;q++) ps[q]=string[q];
 return(0);
}

variable_types: replacelen int

variable_types: pos int

variable_types:
string
char *

variable_types: q int

variable_types: l int

variable_types: shift int

variable_types: len int

variable_types:
tmp
char *

variable_types:
ps
char *


getnum

original_code:
int getnum(int *num,char **line) {
 if ((((*__ctype_b_loc ())[(int) ((**line))] & (unsigned short int) _ISalnum) && !((*__ctype_b_loc ())[(int) ((**line))] & (unsigned short int) _ISalpha))) {
  *num=(int)(**line-'0');
  (*line)++;
  while((((*__ctype_b_loc ())[(int) ((**line))] & (unsigned short int) _ISalnum) && !((*__ctype_b_loc ())[(int) ((**line))] & (unsigned short int) _ISalpha))) {
   *num=*num*10+(int)(**line-'0');
   (*line)++;
  }
  return(0);
 } else {
  return(-1);
 }
}

canonical_original_code:
int getnum(int *num, char **line) {
 if ((((*__ctype_b_loc ())[(int) ((**line))] & (unsigned short) _ISalnum) && !((*__ctype_b_loc ())[(int) ((**line))] & (unsigned short) _ISalpha))) {
  *num=(int)(**line-'0');
  (*line)++;
  while((((*__ctype_b_loc ())[(int) ((**line))] & (unsigned short) _ISalnum) && !((*__ctype_b_loc ())[(int) ((**line))] & (unsigned short) _ISalpha))) {
   *num=*num*10+(int)(**line-'0');
   (*line)++;
  }
  return(0);
 } else {
  return(-1);
 }
}

variable_types:
num
int *

variable_types:
line
char **


strtoupper

decompiled_code:
__int64 __fastcall strtoupper(char *a1)
{
char v1; // bl
char *v2; // rbp
const __int32_t **v3; // rdx

v1 = *a1;
if ( *a1 )
{
v2 = a1;
v3 = _ctype_toupper_loc();
do
{
*v2++ = (*v3)[v1];
v1 = *v2;
}
while ( *v2 );
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *a1)
{
char v1; // bl
char *v2; // rbp
const __int32_t **v3; // rdx

v1 = *a1;
if ( *a1 )
{
v2 = a1;
v3 = _ctype_toupper_loc();
do
{
*v2++ = (*v3)[v1];
v1 = *v2;
}
while ( *v2 );
}
return 0LL;
}

original_code:
int strtoupper(char *str) {
 while(*str!='\0') {
  *str=toupper(*str);
  str++;
 }
 return(0);
}

variable_types:
str
char *