openSock

decompiled_code:
int __fastcall openSock(int *a1, char *a2, char *a3)
{
int v3; // eax
in_addr_t v4; // eax
__int16 v5; // ax
int result; // eax
struct hostent *v7; // rax
char *nptr; // [rsp+8h] [rbp-30h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-28h] BYREF

nptr = a3;
v3 = socket(2, 1, 0);
*a1 = v3;
if ( v3 < 0 )
{
outerr("failed to create socket\n");
exit(1);
}
memmset(&addr, 0LL, 16LL);
v4 = inet_addr(a2);
if ( v4 == -1 )
{
v7 = getHostByName(a2);
if ( !v7 )
{
outerr("unknown server\n");
exit(1);
}
memcpy(&addr.sa_data[2], *(const void **)v7->h_addr_list, v7->h_length);
}
else
{
*(_QWORD *)&addr.sa_data[2] = v4;
}
addr.sa_family = 2;
v5 = strtol(nptr, &nptr, 0);
*(_WORD *)addr.sa_data = _bswap_16(v5);
result = connect(*a1, &addr, 0x10u);
if ( result < 0 )
{
outerr("can't connect to server\n");
exit(1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(int *a1, char *a2, char *a3)
{
int v3; // eax
in_addr_t v4; // eax
__int16 v5; // ax
int result; // eax
struct hostent *v7; // rax
char *nptr; // [rsp+8h] [rbp-30h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-28h] BYREF

nptr = a3;
v3 = socket(2, 1, 0);
*a1 = v3;
if ( v3 < 0 )
{
outerr("failed to create socket\n");
exit(1);
}
memmset(&addr, 0LL, 16LL);
v4 = inet_addr(a2);
if ( v4 == -1 )
{
v7 = func1(a2);
if ( !v7 )
{
outerr("unknown server\n");
exit(1);
}
memcpy(&addr.sa_data[2], *(const void **)v7->h_addr_list, v7->h_length);
}
else
{
*(_QWORD *)&addr.sa_data[2] = v4;
}
addr.sa_family = 2;
v5 = strtol(nptr, &nptr, 0);
*(_WORD *)addr.sa_data = func0(v5);
result = connect(*a1, &addr, 0x10u);
if ( result < 0 )
{
outerr("can't connect to server\n");
exit(1);
}
return result;
}

original_code:
void openSock(SOCKET *sock,ADDRESS server_name,PORT port) {
 struct sockaddr_in server;
 struct hostent *host_info;
 unsigned long addr;
 *sock=socket(2,SOCK_STREAM,0);
 if(*sock<0){
  outerr("failed to create socket\n");
  exit(1);
 }
 memmset(&server,0,sizeof(server));
 if((addr=inet_addr(server_name))!=((in_addr_t) 0xffffffff)) {
  memcpy((char *)&server.sin_addr,&addr,sizeof(addr));
 } else {
  host_info=getHostByName(server_name);
  if(((void *)0)==host_info) {
   outerr("unknown server\n");
   exit(1);
  }
  memcpy((char *)&server.sin_addr,host_info->h_addr_list[0],host_info->h_length);
 }
 server.sin_family=2;
 server.sin_port=htons(strtol(port,&port,0));
 if(connect(*sock,(struct sockaddr*)&server,sizeof(server))<0) {
  outerr("can't connect to server\n");
  exit(1);
 }
}

canonical_original_code:
void openSock(int *sock, char *server_name, char *port) {
 struct sockaddr_in server;
 struct hostent *host_info;
 unsigned long addr;
 *sock=socket(2,SOCK_STREAM,0);
 if(*sock<0){
  outerr("failed to create socket\n");
  exit(1);
 }
 memmset(&server,0,sizeof(server));
 if((addr=inet_addr(server_name))!=((unsigned int) 0xffffffff)) {
  memcpy((char *)&server.sin_addr,&addr,sizeof(addr));
 } else {
  host_info=getHostByName(server_name);
  if(((void *)0)==host_info) {
   outerr("unknown server\n");
   exit(1);
  }
  memcpy((char *)&server.sin_addr,host_info->h_addr_list[0],host_info->h_length);
 }
 server.sin_family=2;
 server.sin_port=htons(strtol(port,&port,0));
 if(connect(*sock,(struct sockaddr *)&server,sizeof(server))<0) {
  outerr("can't connect to server\n");
  exit(1);
 }
}

variable_types:
sock
int *

variable_types:
port
char *

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; }

variable_types:
addr
unsigned long

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }

user_defined_types: struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; }

user_defined_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }


closeSock

repo: vatriani/weather-cli

decompiled_code:
int __fastcall closeSock(int *a1)
{
return shutdown(*a1, 2);
}

canonical_decompiled_code:
int __fastcall func3(int *a1)
{
return shutdown(*a1, 2);
}

original_code: void closeSock(SOCKET *sock) {shutdown(*sock,2);}

canonical_original_code: void closeSock(int *sock) {shutdown(*sock,2);}

return_type: void


sendSplit

decompiled_code:
void __fastcall sendSplit(int *a1, _QWORD *a2)
{
int v2; // ebp
int v3; // eax
char *v4; // rbx
int v5; // ebp
char *v6; // r12
int v7; // eax
char *v8; // rbp
int v9; // eax
int v10; // eax
int v11; // eax

v2 = (int)strmlen(*a2) / 1452;
v3 = strmlen(*a2);
v4 = (char *)*a2;
v5 = (v3 % 1452 > 0) + v2;
if ( v5 )
{
v6 = &v4[1452 * (v5 - 1)];
while ( 1 )
{
if ( (int)strmlen(v4) <= 1450 )
{
v7 = strmlen(v4);
v8 = (char *)malloc(v7 + 1);
v9 = strmlen(v4);
memcpy(v8, v4, v9 + 1);
v10 = strmlen(v4);
v11 = send(*a1, v8, v10 + 1, 0);
}
else
{
v8 = (char *)malloc(0x5ACuLL);
qmemcpy(v8, v4, 0x5ACuLL);
v11 = send(*a1, v8, 0x5ACuLL, 0);
}
if ( v11 == -1 )
outerr("send to failure");
if ( v6 == v4 )
break;
v4 += 1452;
free(v8);
}
free(v8);
}
}

canonical_decompiled_code:
void __fastcall func4(int *a1, _QWORD *a2)
{
int v2; // ebp
int v3; // eax
char *v4; // rbx
int v5; // ebp
char *v6; // r12
int v7; // eax
char *v8; // rbp
int v9; // eax
int v10; // eax
int v11; // eax

v2 = (int)strmlen(*a2) / 1452;
v3 = strmlen(*a2);
v4 = (char *)*a2;
v5 = (v3 % 1452 > 0) + v2;
if ( v5 )
{
v6 = &v4[1452 * (v5 - 1)];
while ( 1 )
{
if ( (int)strmlen(v4) <= 1450 )
{
v7 = strmlen(v4);
v8 = (char *)malloc(v7 + 1);
v9 = strmlen(v4);
memcpy(v8, v4, v9 + 1);
v10 = strmlen(v4);
v11 = send(*a1, v8, v10 + 1, 0);
}
else
{
v8 = (char *)malloc(0x5ACuLL);
qmemcpy(v8, v4, 0x5ACuLL);
v11 = send(*a1, v8, 0x5ACuLL, 0);
}
if ( v11 == -1 )
outerr("send to failure");
if ( v6 == v4 )
break;
v4 += 1452;
free(v8);
}
free(v8);
}
}

original_code:
void sendSplit(SOCKET *sock,MESSAGE *mesg) {
 char *pointer;
 unsigned int iterrations=0;
 char *temp;
 int errorSend;
 iterrations=strmlen((char *)*mesg)/1452;
 if(strmlen((char *)*mesg)%1452>0)
  iterrations++;
 pointer=*mesg;
 while(iterrations>0) {
  if(strmlen(pointer)+1>=1452) {
   temp = malloc(1452);
   memcpy(temp,pointer,1452);
   errorSend=send(*sock,temp,1452,0);
  } else {
   temp = malloc(strmlen(pointer)+1);
   memcpy(temp,pointer,strmlen(pointer)+1);
   errorSend=send(*sock,temp,strmlen(pointer)+1,0);
  }
  if(errorSend==-1) outerr("send to failure");
  --iterrations;
  if(iterrations!=0) pointer=pointer+1452;
  free(temp);
 }
}

canonical_original_code:
void sendSplit(int *sock, char **mesg) {
 char *pointer;
 unsigned int iterrations = 0;
 char *temp;
 int errorSend;
 iterrations=strmlen((char *)*mesg)/1452;
 if(strmlen((char *)*mesg)%1452>0)
  iterrations++;
 pointer=*mesg;
 while(iterrations>0) {
  if(strmlen(pointer)+1>=1452) {
   temp = malloc(1452);
   memcpy(temp,pointer,1452);
   errorSend=send(*sock,temp,1452,0);
  } else {
   temp = malloc(strmlen(pointer)+1);
   memcpy(temp,pointer,strmlen(pointer)+1);
   errorSend=send(*sock,temp,strmlen(pointer)+1,0);
  }
  if(errorSend==-1) outerr("send to failure");
  --iterrations;
  if(iterrations!=0) pointer=pointer+1452;
  free(temp);
 }
}

variable_types:
mesg
char **

variable_types:
pointer
char *

variable_types:
iterrations
unsigned int

variable_types:
temp
char *

variable_types: errorSend int


recvSplit

decompiled_code:
void *__fastcall recvSplit(int *a1, void **a2)
{
size_t i; // rbp
size_t v3; // r13
size_t v4; // r14
void *v5; // rax
void *result; // rax
int v7; // ebx
void *v8; // rax
_BYTE v9[1512]; // [rsp+0h] [rbp-5E8h] BYREF

*a2 = malloc(1uLL);
for ( i = 0LL; ; i = v4 )
{
result = (void *)recv(*a1, v9, 0x5ACuLL, 0);
v7 = (int)result;
if ( (_DWORD)result == -1 )
break;
if ( !(_DWORD)result )
return result;
v3 = (int)result;
v4 = (int)result + i;
v8 = realloc(*a2, v4);
*a2 = v8;
if ( !v8 )
goto LABEL_3;
LABEL_4:
result = memcpy((char *)*a2 + i, v9, v3);
if ( v7 <= 0 )
return result;
}
outerr("server error");
v3 = -1LL;
v4 = i - 1;
v5 = realloc(*a2, i - 1);
*a2 = v5;
if ( !v5 )
{
LABEL_3:
outerr("realoc failed");
goto LABEL_4;
}
return memcpy((char *)*a2 + i, v9, 0xFFFFFFFFFFFFFFFFLL);
}

canonical_decompiled_code:
void *__fastcall func5(int *a1, void **a2)
{
size_t i; // rbp
size_t v3; // r13
size_t v4; // r14
void *v5; // rax
void *result; // rax
int v7; // ebx
void *v8; // rax
_BYTE v9[1512]; // [rsp+0h] [rbp-5E8h] BYREF

*a2 = malloc(1uLL);
for ( i = 0LL; ; i = v4 )
{
result = (void *)recv(*a1, v9, 0x5ACuLL, 0);
v7 = (int)result;
if ( (_DWORD)result == -1 )
break;
if ( !(_DWORD)result )
return result;
v3 = (int)result;
v4 = (int)result + i;
v8 = realloc(*a2, v4);
*a2 = v8;
if ( !v8 )
goto LABEL_3;
LABEL_4:
result = memcpy((char *)*a2 + i, v9, v3);
if ( v7 <= 0 )
return result;
}
outerr("server error");
v3 = -1LL;
v4 = i - 1;
v5 = realloc(*a2, i - 1);
*a2 = v5;
if ( !v5 )
{
LABEL_3:
outerr("realoc failed");
goto LABEL_4;
}
return memcpy((char *)*a2 + i, v9, 0xFFFFFFFFFFFFFFFFLL);
}

original_code:
void recvSplit(SOCKET *sock,MESSAGE *mesg) {
 char temp[1452];
 int bytes;
 char *pointer;
 unsigned long int recB=0;
 if(*mesg==0) free(*mesg);
 *mesg=malloc(1);
 pointer=*mesg;
 do {
  bytes=recv(*sock,&temp,1452,0);
  if(bytes==-1) outerr("server error");
  if(bytes==0) return;
  recB+=bytes;
  *mesg=(char *)realloc(*mesg,recB);
  if(*mesg==0) outerr("realoc failed");
  pointer=*mesg+recB-bytes;
  memcpy(pointer,&temp[0],bytes);
 } while(bytes>0);
}

canonical_original_code:
void recvSplit(int *sock, char **mesg) {
 char temp[1452];
 int bytes;
 char *pointer;
 unsigned long recB = 0;
 if(*mesg==0) free(*mesg);
 *mesg=malloc(1);
 pointer=*mesg;
 do {
  bytes=recv(*sock,&temp,1452,0);
  if(bytes==-1) outerr("server error");
  if(bytes==0) return;
  recB+=bytes;
  *mesg=(char *)realloc(*mesg,recB);
  if(*mesg==0) outerr("realoc failed");
  pointer=*mesg+recB-bytes;
  memcpy(pointer,&temp[0],bytes);
 } while(bytes>0);
}

variable_types:
temp
char [1452]

variable_types: bytes int

variable_types:
recB
unsigned long


fetchFromHeader

decompiled_code:
__int64 __fastcall fetchFromHeader(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // rbx
__int64 v5; // rbx

v4 = ((__int64 (*)(void))strmstr)();
if ( !v4 )
outerr("key does not exists");
v5 = strmstr(v4, ": ") + 2;
*(_BYTE *)strmstr(v5, "\r\n") = 0;
return strmcat(a3, v5);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // rbx
__int64 v5; // rbx

v4 = ((__int64 (*)(void))strmstr)();
if ( !v4 )
outerr("key does not exists");
v5 = strmstr(v4, ": ") + 2;
*(_BYTE *)strmstr(v5, "\r\n") = 0;
return strmcat(a3, v5);
}

original_code:
void fetchFromHeader(char *header,char *key, char **value) {
 char *fetchingkeypos;
 fetchingkeypos=strmstr(header,key);
 if(fetchingkeypos==((void *)0)) outerr("key does not exists");
 fetchingkeypos=strmstr(fetchingkeypos,": ")+2;
 if(fetchingkeypos==((void *)0)) outerr("no standard formating");
 *strmstr(fetchingkeypos,"\r\n")='\0';
 strmcat(value,fetchingkeypos);
}

canonical_original_code:
void fetchFromHeader(char *header, char *key, char **value) {
 char *fetchingkeypos;
 fetchingkeypos=strmstr(header,key);
 if(fetchingkeypos==((void *)0)) outerr("key does not exists");
 fetchingkeypos=strmstr(fetchingkeypos,": ")+2;
 if(fetchingkeypos==((void *)0)) outerr("no standard formating");
 *strmstr(fetchingkeypos,"\r\n")='\0';
 strmcat(value,fetchingkeypos);
}

variable_types:
header
char *

variable_types:
key
char *

variable_types:
value
char **

variable_types:
fetchingkeypos
char *


mallocate

decompiled_code:
void __fastcall mallocate(_BYTE *a1, char a2, int a3)
{
_BYTE *v3; // rax
__int64 v4; // rdx

if ( a3 )
{
v3 = a1;
v4 = (__int64)&a1[a3 - 1 + 1];
do
*v3++ = a2;
while ( v3 != (_BYTE *)v4 );
}
}

original_code:
void mallocate(char *array, char c, int size) {
 register unsigned int counter = 0;
 for(;counter < size; counter++)
  array[counter] = c;
}

variable_types:
array
char *

variable_types: c char

variable_types: size int

variable_types:
counter
unsigned int


freeChar

decompiled_code:
void __fastcall freeChar(void **a1)
{
void *v2; // rdi

v2 = *a1;
if ( v2 )
{
free(v2);
*a1 = 0LL;
}
}

canonical_decompiled_code:
void __fastcall func2(void **a1)
{
void *v2; // rdi

v2 = *a1;
if ( v2 )
{
free(v2);
*a1 = 0LL;
}
}

original_code:
void freeChar(char** tmp) {
 if(*tmp != ((void *)0)) {
  free(*tmp);
  *tmp = ((void *)0);
 }
}

canonical_original_code:
void freeChar(char **tmp) {
 if(*tmp != ((void *)0)) {
  free(*tmp);
  *tmp = ((void *)0);
 }
}

variable_types:
tmp
char **


strmlen

decompiled_code:
__int64 __fastcall strmlen(_BYTE *a1)
{
_BYTE *v1; // rax
unsigned int v2; // ecx

if ( !a1 )
return 0;
if ( !*a1 )
return 0;
v1 = a1;
do
v2 = 1 - (_DWORD)a1 + (_DWORD)v1++;
while ( *v1 );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func3(_BYTE *a1)
{
_BYTE *v1; // rax
unsigned int v2; // ecx

if ( !a1 )
return 0;
if ( !*a1 )
return 0;
v1 = a1;
do
v2 = 1 - (_DWORD)a1 + (_DWORD)v1++;
while ( *v1 );
return v2;
}

original_code:
int strmlen(char *s) {
 register int n = 0;
 if(s == ((void *)0))
  return 0;
 for (; *s != 0; ++s)
  ++n;
 return n;
}

variable_types:
s
char *

variable_types: n int

return_type: int


strmcmp

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

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

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

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

original_code:
int strmcmp(char *s, char *t) {
 register int i = 0;
 for (; s[i] == t[i]; ++i)
  if (s[i] == '\0')
   return 0;
 return s[i] - t[i];
}

variable_types:
t
char *

variable_types: i int


strmncmp

decompiled_code:
__int64 __fastcall strmncmp(char *a1, char *a2, int a3)
{
char v4; // dl
char v5; // cl
__int64 v6; // r8
__int64 v7; // rax

v4 = *a1;
v5 = *a2;
if ( *a1 != *a2 || a3 == 1 )
return (unsigned int)(v4 - v5);
v6 = (unsigned int)(a3 - 2) + 2LL;
v7 = 1LL;
while ( v4 )
{
v4 = a1[v7];
v5 = a2[v7];
if ( v4 == v5 && ++v7 != v6 )
continue;
return (unsigned int)(v4 - v5);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(char *a1, char *a2, int a3)
{
char v4; // dl
char v5; // cl
__int64 v6; // r8
__int64 v7; // rax

v4 = *a1;
v5 = *a2;
if ( *a1 != *a2 || a3 == 1 )
return (unsigned int)(v4 - v5);
v6 = (unsigned int)(a3 - 2) + 2LL;
v7 = 1LL;
while ( v4 )
{
v4 = a1[v7];
v5 = a2[v7];
if ( v4 == v5 && ++v7 != v6 )
continue;
return (unsigned int)(v4 - v5);
}
return 0LL;
}

original_code:
int strmncmp(char *s, char *t, unsigned int size) {
 register int i = 0;
 --size;
 for (; s[i] == t[i] && i < size; ++i)
  if (s[i] == '\0' || i == size)
   return 0;
 return s[i] - t[i];
}

variable_types:
size
unsigned int


strmcat

original_code:
void strmcat(char **base_str,char *append_str) {
 char *tmp = ((void *)0);
 int const applen = strmlen(append_str);
 int const baselen = strmlen(*base_str);
 if(*base_str == ((void *)0)) {
  *base_str = (char*)malloc(applen + 1);
  if(*base_str != ((void *)0))
   memcpy(*base_str, append_str, applen + 1);
 } else {
  tmp = *base_str;
  *base_str = malloc(baselen + applen + 1);
  if(*base_str!=((void *)0)) {
   memcpy(*base_str, tmp, baselen);
   memcpy(*base_str + strmlen(tmp), append_str, applen+1);
  }
 }
 freeChar(&tmp);
}

canonical_original_code:
void strmcat(char **base_str, char *append_str) {
 char *tmp = ((void *)0);
 int applen = strmlen(append_str);
 int baselen = strmlen(*base_str);
 if(*base_str == ((void *)0)) {
  *base_str = (char *)malloc(applen + 1);
  if(*base_str != ((void *)0))
   memcpy(*base_str, append_str, applen + 1);
 } else {
  tmp = *base_str;
  *base_str = malloc(baselen + applen + 1);
  if(*base_str!=((void *)0)) {
   memcpy(*base_str, tmp, baselen);
   memcpy(*base_str + strmlen(tmp), append_str, applen+1);
  }
 }
 freeChar(&tmp);
}

variable_types:
tmp
char *

variable_types: applen int

variable_types: baselen int


strmreplace

decompiled_code:
__int64 __fastcall strmreplace(char **a1, char *a2, _BYTE *a3)
{
char *v4; // r14
int v5; // er15
int v6; // er12
_BYTE *v7; // r12
int v8; // eax
char *v9; // r15
char *v10; // r14
int v11; // eax
int v12; // eax
char *v13; // rbx
int v14; // eax
__int64 v15; // rbx
int v16; // eax
__int64 v17; // rbx
int v18; // eax
int v20; // [rsp+4h] [rbp-64h]
_BYTE *v21; // [rsp+8h] [rbp-60h]
_BYTE *v22; // [rsp+10h] [rbp-58h] BYREF
_BYTE *v23; // [rsp+18h] [rbp-50h] BYREF
_BYTE *v24; // [rsp+20h] [rbp-48h] BYREF

v4 = *a1;
if ( !strmstr(*a1, a2) )
return 0xFFFFFFFFLL;
v5 = strmlen(v4) + 1;
v6 = v5 - strmlen(a2);
v20 = v6 + strmlen(a3);
v7 = malloc(v5);
v22 = v7;
v23 = malloc(v5);
v8 = strmlen(a3);
v21 = malloc(v8 + v5);
v24 = v21;
memcpy((__int64)v7, (__int64)v4, v5);
*a1 = 0LL;
v9 = strmstr(v7, a2);
v10 = &v9[(int)strmlen(a2)];
v11 = strmlen(v10);
memcpy((__int64)v21, (__int64)v10, v11 + 1);
*strmstr(v7, a2) = 0;
v12 = strmlen(v22);
memcpy((__int64)v23, (__int64)v22, v12 + 1);
v13 = (char *)malloc(v20 + 2);
*a1 = v13;
v14 = strmlen(v23);
memcpy((__int64)v13, (__int64)v23, v14);
v15 = (__int64)&v13[(int)strmlen(v23)];
v16 = strmlen(a3);
memcpy(v15, (__int64)a3, v16);
v17 = (int)strmlen(a3) + v15;
v18 = strmlen(v24);
memcpy(v17, (__int64)v24, v18 + 1);
freeChar((void **)&v22);
freeChar((void **)&v23);
freeChar((void **)&v24);
return 0LL;
}

original_code:
int strmreplace(char **string, char *replace_hint, char *insert_word) {
 int oldLen;
 int newLen;
 char *tmp[3];
 char *pointer;
 pointer = strmstr(*string, replace_hint);
 if(pointer == ((void *)0))
  return -1;
 oldLen = strmlen(*string)+1;
 newLen = oldLen-strmlen(replace_hint)+strmlen(insert_word)+1;
 tmp[0] = malloc(oldLen);
 tmp[1] = malloc(oldLen);
 tmp[2] = malloc(oldLen + strmlen(insert_word));
 memcpy(tmp[0], *string, oldLen);
 *string = ((void *)0);
 pointer = strmstr(tmp[0], replace_hint);
 pointer += strmlen(replace_hint);
 memcpy(tmp[2], pointer, strmlen(pointer)+1);
 pointer = strmstr(tmp[0], replace_hint);
 *pointer = '\0';
 memcpy(tmp[1], tmp[0], strmlen(tmp[0])+1);
 *string = malloc(newLen+1);
 pointer = *string;
 memcpy(pointer, tmp[1], strmlen(tmp[1]));
 pointer += strmlen(tmp[1]);
 memcpy(pointer, insert_word, strmlen(insert_word));
 pointer += strmlen(insert_word);
 memcpy(pointer, tmp[2], strmlen(tmp[2])+1);
 freeChar(&tmp[0]);
 freeChar(&tmp[1]);
 freeChar(&tmp[2]);
 return 0;
}

variable_types:
string
char **

variable_types: oldLen int

variable_types: newLen int

variable_types:
tmp
char *[3]

variable_types:
pointer
char *


strmrreplace

decompiled_code:
__int64 __fastcall strmrreplace(char **a1, char *a2, _BYTE *a3)
{
__int64 result; // rax

do
result = strmreplace(a1, a2, a3);
while ( !(_DWORD)result );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(char **a1, char *a2, _BYTE *a3)
{
__int64 result; // rax

do
result = func9(a1, a2, a3);
while ( !(_DWORD)result );
return result;
}

original_code:
void strmrreplace(char **string, char *replace_hint, char *insert_word) {
 while( strmreplace(string,replace_hint,insert_word)==0);
}


strmdelsp

decompiled_code:
void __fastcall strmdelsp(_BYTE *a1)
{
void *v1; // rsp
int v2; // eax
unsigned int i; // ebx
unsigned int v4; // eax
unsigned int v5; // eax
char v6; // dl
_BYTE v7[40]; // [rsp-28h] [rbp-28h] BYREF

if ( a1 )
{
v1 = alloca((int)(strmlen(a1) + 1));
v2 = strmlen(a1);
memcpy((__int64)v7, (__int64)a1, v2 + 1);
for ( i = 1; ; i = v5 + 1 )
{
v4 = strmlen(v7);
if ( i >= v4 )
break;
v5 = i - 1;
v6 = v7[i];
if ( v6 <= 31 )
{
v7[v5] = 0;
}
else
{
v7[v5] = v6;
v5 = i;
}
}
memcpy((__int64)a1, (__int64)v7, (int)(v4 + 1));
}
}

canonical_decompiled_code:
void __fastcall func11(_BYTE *a1)
{
void *v1; // rsp
int v2; // eax
unsigned int i; // ebx
unsigned int v4; // eax
unsigned int v5; // eax
char v6; // dl
_BYTE v7[40]; // [rsp-28h] [rbp-28h] BYREF

if ( a1 )
{
v1 = alloca((int)(strmlen(a1) + 1));
v2 = func3(a1);
func0((__int64)v7, (__int64)a1, v2 + 1);
for ( i = 1; ; i = v5 + 1 )
{
v4 = func3(v7);
if ( i >= v4 )
break;
v5 = i - 1;
v6 = v7[i];
if ( v6 <= 31 )
{
v7[v5] = 0;
}
else
{
v7[v5] = v6;
v5 = i;
}
}
func0((__int64)a1, (__int64)v7, (int)(v4 + 1));
}
}

original_code:
void strmdelsp(char *s) {
 if(s != ((void *)0)) {
  char test[strmlen(s)+1];
  register unsigned int counter=1;
  memcpy(test,s,strmlen(s)+1);
  for(;counter<(strmlen(test));++counter) {
   test[counter-1]=test[counter];
   if(test[counter]<32)
    test[--counter]=0;
  }
  memcpy(s,test,strmlen(test)+1);
 }
}

canonical_original_code:
void strmdelsp(char *s) {
 if(s != ((void *)0)) {
  char test[-1];
  register unsigned int counter = 1;
  memcpy(test,s,strmlen(s)+1);
  for(;counter<(strmlen(test));++counter) {
   test[counter-1]=test[counter];
   if(test[counter]<32)
    test[--counter]=0;
  }
  memcpy(s,test,strmlen(test)+1);
 }
}

variable_types:
test
char [-1]


strmverscmp

decompiled_code:
__int64 __fastcall strmverscmp(unsigned __int8 *a1, unsigned __int8 *a2)
{
unsigned __int8 *v3; // rsi
unsigned __int8 v4; // dl
unsigned __int8 *v5; // rdi
unsigned __int8 v6; // r8
int v7; // eax
unsigned int v8; // ecx
unsigned __int8 v9; // dl
int v10; // eax

if ( a1 == a2 )
return 0;
v3 = a1 + 1;
v4 = *a1;
v5 = a2 + 1;
v6 = *a2;
v7 = ((unsigned int)v4 - 48 <= 9) + (v4 == 48);
v8 = v4 - v6;
if ( v4 && !v8 )
{
do
{
v9 = *v3++;
v6 = *v5++;
v7 = next_state_1[v7] | ((v9 == 48) + ((unsigned int)v9 - 48 <= 9));
v8 = v9 - v6;
}
while ( v9 && !v8 );
}
v10 = result_type_0[(4 * v7) | (((unsigned int)v6 - 48 <= 9) + (v6 == 48))];
if ( v10 != 2 )
{
if ( v10 == 3 )
{
while ( (unsigned int)*v3++ - 48 <= 9 )
{
if ( (unsigned int)*v5++ - 48 > 9 )
return 1;
}
if ( (unsigned int)*v5 - 48 <= 9 )
v8 = -1;
}
else
{
v8 = v10;
}
}
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func12(unsigned __int8 *a1, unsigned __int8 *a2)
{
unsigned __int8 *v3; // rsi
unsigned __int8 v4; // dl
unsigned __int8 *v5; // rdi
unsigned __int8 v6; // r8
int v7; // eax
unsigned int v8; // ecx
unsigned __int8 v9; // dl
int v10; // eax

if ( a1 == a2 )
return 0;
v3 = a1 + 1;
v4 = *a1;
v5 = a2 + 1;
v6 = *a2;
v7 = ((unsigned int)v4 - 48 <= 9) + (v4 == 48);
v8 = v4 - v6;
if ( v4 && !v8 )
{
do
{
v9 = *v3++;
v6 = *v5++;
v7 = next_state_1[v7] | ((v9 == 48) + ((unsigned int)v9 - 48 <= 9));
v8 = v9 - v6;
}
while ( v9 && !v8 );
}
v10 = result_type_0[(4 * v7) | (((unsigned int)v6 - 48 <= 9) + (v6 == 48))];
if ( v10 != 2 )
{
if ( v10 == 3 )
{
while ( (unsigned int)*v3++ - 48 <= 9 )
{
if ( (unsigned int)*v5++ - 48 > 9 )
return 1;
}
if ( (unsigned int)*v5 - 48 <= 9 )
v8 = -1;
}
else
{
v8 = v10;
}
}
return v8;
}

variable_types: state int

variable_types: diff int


outplain

decompiled_code:
ssize_t __fastcall outplain(void *buf)
{
int v1; // eax

v1 = strmlen();
return write(1, buf, v1);
}

canonical_decompiled_code:
ssize_t __fastcall func0(void *buf)
{
int v1; // eax

v1 = strmlen();
return write(1, buf, v1);
}

original_code: static inline void outplain(char *tmp) {write(1,tmp,strmlen(tmp));}


styledOutput

decompiled_code:
ssize_t __fastcall styledOutput(void *buf, void *a2)
{
outplain(&unk_195);
outplain(buf);
outplain(&unk_197);
outplain(a2);
return outplain(&unk_199);
}

canonical_decompiled_code:
ssize_t __fastcall func1(void *buf, void *a2)
{
func0(&unk_195);
func0(buf);
func0(&unk_197);
func0(a2);
return func0(&unk_199);
}

original_code:
void styledOutput(char *type, char *mesg) {
 outplain("[");
 outplain(type);
 outplain("]");
 outplain(mesg);
 outplain("\n");
}

variable_types:
type
char *

variable_types:
mesg
char *


outerr

decompiled_code:
ssize_t __fastcall outerr(void *a1)
{
return styledOutput(&unk_19B, a1);
}

canonical_decompiled_code:
ssize_t __fastcall func2(void *a1)
{
return func1(&unk_19B, a1);
}

original_code:
void outerr(char *tmp) {
 styledOutput("err",tmp);
}


outfatal

decompiled_code:
void __fastcall __noreturn outfatal(void *a1)
{
outerr(a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func3(void *a1)
{
func2(a1);
exit(1);
}

original_code:
void outfatal(char *tmp) {
 outerr(tmp);
 exit(1);
}


outstat

decompiled_code:
ssize_t __fastcall outstat(void *buf)
{
outplain(" => ");
outplain(buf);
return outplain(&unk_199);
}

canonical_decompiled_code:
ssize_t __fastcall func4(void *buf)
{
func0(" => ");
func0(buf);
return func0(&unk_199);
}

original_code:
void outstat(char *tmp) {
 outplain("  =>  ");
 outplain(tmp);
 outplain("\n");
}


showHelp

decompiled_code:
void __fastcall showHelp(__int64 a1, __int64 a2)
{
void *ptr[4]; // [rsp+8h] [rbp-20h] BYREF

ptr[0] = 0LL;
strmcat(ptr, "%1 for Linux, BSD and Windows\nuse: %1 %2\n\n");
strmreplace(ptr, "%1", a1);
strmreplace(ptr, "%1", a1);
strmreplace(ptr, "%2", a2);
outplain(ptr[0]);
free(ptr[0]);
}

canonical_decompiled_code:
void __fastcall func5(__int64 a1, __int64 a2)
{
void *ptr[4]; // [rsp+8h] [rbp-20h] BYREF

ptr[0] = 0LL;
strmcat(ptr, "%1 for Linux, BSD and Windows\nuse: %1 %2\n\n");
strmreplace(ptr, "%1", a1);
strmreplace(ptr, "%1", a1);
strmreplace(ptr, "%2", a2);
func0(ptr[0]);
free(ptr[0]);
}

original_code:
void showHelp(char *app_name, char *app_help) {
 char *buffer = ((void *)0);
 strmcat(&buffer, "%1  for Linux, BSD and Windows\nuse: %1 %2\n\n");
 strmreplace(&buffer,"%1",app_name);
 strmreplace(&buffer,"%1",app_name);
 strmreplace(&buffer,"%2",app_help);
 outplain(buffer);
 free(buffer);
}

variable_types:
buffer
char *


showVersion

decompiled_code:
void __fastcall showVersion(__int64 a1, __int64 a2)
{
void *ptr[4]; // [rsp+8h] [rbp-20h] BYREF

ptr[0] = 0LL;
strmcat(
ptr,
"%1 %2\n"
"Copyright (C) %3 Niels Neumann <vatriani.nn@googlemail.com\n"
"License GPLv3+: GNU GPL Version 3 or later <http://gnu.org/licenses/gpl.html>. \n"
"This is free software: you are free to change and redistribute it. \n"
"There is NO WARRANTY, to the extent permitted by law.\n"
"\n");
strmreplace(ptr, "%1", a1);
strmreplace(ptr, "%2", a2);
strmreplace(ptr, "%3", "May 23 2025");
outplain(ptr[0]);
free(ptr[0]);
}

canonical_decompiled_code:
void __fastcall func6(__int64 a1, __int64 a2)
{
void *ptr[4]; // [rsp+8h] [rbp-20h] BYREF

ptr[0] = 0LL;
strmcat(
ptr,
"%1 %2\n"
"Copyright (C) %3 Niels Neumann <vatriani.nn@googlemail.com\n"
"License GPLv3+: GNU GPL Version 3 or later <http://gnu.org/licenses/gpl.html>. \n"
"This is free software: you are free to change and redistribute it. \n"
"There is NO WARRANTY, to the extent permitted by law.\n"
"\n");
strmreplace(ptr, "%1", a1);
strmreplace(ptr, "%2", a2);
strmreplace(ptr, "%3", "May 23 2025");
func0(ptr[0]);
free(ptr[0]);
}

original_code:
void showVersion(char *app_name, char *app_version) {
 char *buffer = ((void *)0);
 strmcat(&buffer, "%1 %2\nCopyright (C) %3 Niels Neumann  <vatriani.nn@googlemail.com\nLicense GPLv3+: GNU GPL Version 3 or later <http://gnu.org/licenses/gpl.html>. \nThis is free software: you are free to change and redistribute it. \nThere is NO WARRANTY, to the extent permitted by law.\n\n");
 strmreplace(&buffer,"%1",app_name);
 strmreplace(&buffer,"%2",app_version);
 strmreplace(&buffer,"%3","Apr 23 2024");
 outplain(buffer);
 free(buffer);
}


main

canonical_name: main

repo: vbouchaud/spamholeReturn

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

v3 = _xpg_basename((char *)*argv);
openlog(v3, 1, 16);
printf("spamhole reference implementation %s by I)ruid [CAU]\n", "0.4");
syslog(6, "spamhole reference implementation %s by I)ruid [CAU] started...\n", "0.4");
if ( access("/var/spamhole", 0) )
{
if ( mkdir("/var/spamhole", 0x1C0u) < 0 )
{
perror("mkdir");
syslog(3, "Error: Unable to create working dir of '%s'\n", "/var/spamhole");
exit(-1);
}
if ( chown("/var/spamhole", 0x63u, 0) < 0 )
{
perror("chown");
syslog(3, "Error: Unable to change owner of '%s' to UID %d\n", "/var/spamhole", 99LL);
exit(-1);
}
}
if ( access("/var/spamhole", 7) )
{
perror("chdir");
syslog(3, "Error: Unable to use working dir of '%s' Check permissions\n", "/var/spamhole");
exit(-1);
}
chdir("/var/spamhole");
v4 = fork();
if ( v4 < 0 )
{
perror("fork");
exit(-1);
}
if ( !v4 )
spamhole();
return 0;
}

original_code:
int main( int argc, char *argv[] ) {
 pid_t pid;
 openlog( __xpg_basename(argv[0]), 0x01, (2<<3) );
 printf( "spamhole reference implementation %s by I)ruid [CAU]\n", "0.4" );
 syslog( 6, "spamhole reference implementation %s by I)ruid [CAU] started...\n", "0.4" );
 if( access( "/var/spamhole", 0 ) != 0 ) {
  if( mkdir( "/var/spamhole", 0100|0400|0200 ) < 0 ) {
   perror("mkdir");
   syslog( 3, "Error: Unable to create working dir of '%s'\n", "/var/spamhole" );
   exit(-1);
  }
  if( chown( "/var/spamhole", 99, 0 ) < 0 ) {
   perror("chown");
   syslog( 3, "Error: Unable to change owner of '%s' to UID %d\n", "/var/spamhole", 99 );
   exit(-1);
  }
 }
 if( access( "/var/spamhole", 0|4|2|1 ) == 0 ) {
  chdir( "/var/spamhole" );
 } else {
  perror("chdir");
  syslog( 3, "Error: Unable to use working dir of '%s' Check permissions\n", "/var/spamhole" );
  exit(-1);
 }
 pid=fork();
 if (pid<0) {
  perror("fork");
  exit(-1);
 }
 else if (pid==0) spamhole();
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
 int pid;
 openlog( __xpg_basename(argv[0]), 0x01, (2<<3) );
 printf( "spamhole reference implementation %s by I)ruid [CAU]\n", "0.4" );
 syslog( 6, "spamhole reference implementation %s by I)ruid [CAU] started...\n", "0.4" );
 if( access( "/var/spamhole", 0 ) != 0 ) {
  if( mkdir( "/var/spamhole", 0100|0400|0200 ) < 0 ) {
   perror("mkdir");
   syslog( 3, "Error: Unable to create working dir of '%s'\n", "/var/spamhole" );
   exit(-1);
  }
  if( chown( "/var/spamhole", 99, 0 ) < 0 ) {
   perror("chown");
   syslog( 3, "Error: Unable to change owner of '%s' to UID %d\n", "/var/spamhole", 99 );
   exit(-1);
  }
 }
 if( access( "/var/spamhole", 0|4|2|1 ) == 0 ) {
  chdir( "/var/spamhole" );
 } else {
  perror("chdir");
  syslog( 3, "Error: Unable to use working dir of '%s' Check permissions\n", "/var/spamhole" );
  exit(-1);
 }
 pid=fork();
 if (pid<0) {
  perror("fork");
  exit(-1);
 }
 else if (pid==0) spamhole();
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: pid int


repo: vchahun/foma

decompiled_code:
__int64 __fastcall my_completion(__int64 a1, int a2)
{
smatch = a2;
return rl_completion_matches(a1, my_generator);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2)
{
smatch = a2;
return rl_completion_matches(a1, my_generator);
}

original_code:
static char **my_completion(const char *text, int start, int end) {
    char **matches;
    matches = (char **)((void *)0);
    smatch = start;
    matches = rl_completion_matches ((char*)text, &my_generator);
    return (matches);
}

canonical_original_code:
static char **my_completion(char *text, int start, int end) {
    char **matches;
    matches = (char **)((void *)0);
    smatch = start;
    matches = rl_completion_matches ((char *)text, &my_generator);
    return (matches);
}

variable_types:
text
char *

variable_types: start int

variable_types: end int

variable_types:
matches
char **

return_type: char **


decompiled_code:
char *__fastcall my_generator(__int64 a1, int a2)
{
const char *v2; // rbp
size_t v3; // r12
const char *v4; // rbx

v2 = rl_line_buffer;
if ( !a2 )
{
list_index_3 = 0;
list_index2_2 = 0;
nummatches_1 = 0;
len_0 = strlen(rl_line_buffer);
}
v3 = len_0;
while ( 1 )
{
v4 = cmd[list_index_3];
if ( !v4 )
break;
++list_index_3;
if ( !strncmp(v4, v2, v3) )
{
++nummatches_1;
return strdup(&v4[smatch]);
}
}
if ( rl_point > 0 )
{
while ( 1 )
{
v4 = abbrvcmd[list_index2_2];
if ( !v4 )
break;
++list_index2_2;
if ( !strncmp(v4, v2, v3) )
return strdup(&v4[smatch]);
}
}
return (char *)v4;
}

canonical_decompiled_code:
char *__fastcall func1(__int64 a1, int a2)
{
const char *v2; // rbp
size_t v3; // r12
const char *v4; // rbx

v2 = rl_line_buffer;
if ( !a2 )
{
list_index_3 = 0;
list_index2_2 = 0;
nummatches_1 = 0;
len_0 = strlen(rl_line_buffer);
}
v3 = len_0;
while ( 1 )
{
v4 = cmd[list_index_3];
if ( !v4 )
break;
++list_index_3;
if ( !strncmp(v4, v2, v3) )
{
++nummatches_1;
return strdup(&v4[smatch]);
}
}
if ( rl_point > 0 )
{
while ( 1 )
{
v4 = abbrvcmd[list_index2_2];
if ( !v4 )
break;
++list_index2_2;
if ( !strncmp(v4, v2, v3) )
return strdup(&v4[smatch]);
}
}
return (char *)v4;
}

original_code:
char *my_generator(const char *text, int state) {
    static int list_index, list_index2, len, nummatches;
    char *name;
    text = rl_line_buffer;
    if (!state) {
        list_index = 0;
        list_index2 = 0;
        nummatches = 0;
        len = strlen(text);
    }
    while ((name = cmd[list_index])) {
        list_index++;
        if (strncmp (name, text, len) == 0) {
            nummatches++;
            return(strdup(name+smatch));
        }
    }
    if (rl_point > 0) {
        while ((name = abbrvcmd[list_index2])) {
            list_index2++;
            if (strncmp (name, text, len) == 0)
                return(strdup(name+smatch));
        }
    }
    return ((char *)((void *)0));
}

canonical_original_code:
char *my_generator(char *text, int state) {
    static int list_index; static int list_index2; static int len; static int nummatches;
    char *name;
    text = rl_line_buffer;
    if (!state) {
        list_index = 0;
        list_index2 = 0;
        nummatches = 0;
        len = strlen(text);
    }
    while ((name = cmd[list_index])) {
        list_index++;
        if (strncmp (name, text, len) == 0) {
            nummatches++;
            return(strdup(name+smatch));
        }
    }
    if (rl_point > 0) {
        while ((name = abbrvcmd[list_index2])) {
            list_index2++;
            if (strncmp (name, text, len) == 0)
                return(strdup(name+smatch));
        }
    }
    return ((char *)((void *)0));
}

variable_types: len int

variable_types: nummatches int

variable_types:
name
char *

return_type: char *


xprintf

decompiled_code:
void xprintf()
{
;
}

canonical_decompiled_code:
void func2()
{
;
}

original_code: void xprintf(char *string) { return ; printf("%s",string); }

variable_types:
string
char *


decompiled_code:
void *__fastcall rl_gets(const char *a1)
{
char *v1; // rax

if ( use_readline == 1 )
{
if ( line_read )
{
free(line_read);
line_read = 0LL;
}
goto LABEL_7;
}
if ( use_readline )
{
LABEL_7:
line_read = (void *)readline(a1);
goto LABEL_8;
}
printf("%s", a1);
v1 = fgets(no_readline_line, 511, stdin);
line_read = v1;
if ( !v1 )
return line_read;
strip_newline(v1);
LABEL_8:
if ( use_readline == 1 && line_read && *(_BYTE *)line_read )
add_history();
return line_read;
}

canonical_decompiled_code:
void *__fastcall func3(const char *a1)
{
char *v1; // rax

if ( use_readline == 1 )
{
if ( line_read )
{
free(line_read);
line_read = 0LL;
}
goto LABEL_7;
}
if ( use_readline )
{
LABEL_7:
line_read = (void *)readline(a1);
goto LABEL_8;
}
printf("%s", a1);
v1 = fgets(no_readline_line, 511, stdin);
line_read = v1;
if ( !v1 )
return line_read;
strip_newline(v1);
LABEL_8:
if ( use_readline == 1 && line_read && *(_BYTE *)line_read )
add_history();
return line_read;
}

original_code:
char *rl_gets(char *prompt) {
    if (use_readline == 1) {
        if (line_read) {
            free(line_read);
            line_read = (char *)((void *)0);
        }
    }
    if (use_readline == 0) {
        printf("%s",prompt);
        line_read = fgets(no_readline_line, 511, stdin);
        if (line_read != ((void *)0)) {
            strip_newline(line_read);
        }
    } else {
        line_read = readline(prompt);
    }
    if (use_readline == 1) {
        if (line_read && *line_read)
            add_history(line_read);
    }
    return (line_read);
}

variable_types:
prompt
char *


decompiled_code:
int print_help()
{
printf("%s", usagestring);
puts("Options:");
puts("-e \"command\"\texecute a command on startup (-e can be invoked several times)");
puts("-f scriptfile\tread commands from scriptfile on startup, and quit");
puts("-l scriptfile\tread commands from scriptfile on startup");
puts("-p\t\tpipe-mode");
puts("-q\t\tquiet mode (more quiet than pipe-mode)");
puts("-r\t\tdon't use readline library for input");
puts("-s\t\tstop execution and exit");
return puts("-v\t\tprint version number");
}

canonical_decompiled_code:
int func4()
{
printf("%s", usagestring);
puts("Options:");
puts("-e \"command\"\texecute a command on startup (-e can be invoked several times)");
puts("-f scriptfile\tread commands from scriptfile on startup, and quit");
puts("-l scriptfile\tread commands from scriptfile on startup");
puts("-p\t\tpipe-mode");
puts("-q\t\tquiet mode (more quiet than pipe-mode)");
puts("-r\t\tdon't use readline library for input");
puts("-s\t\tstop execution and exit");
return puts("-v\t\tprint version number");
}

original_code:
void print_help() {
    printf("%s",usagestring);
    printf("Options:\n");
    printf("-e \"command\"\texecute a command on startup (-e can be invoked several times)\n");
    printf("-f scriptfile\tread commands from scriptfile on startup, and quit\n");
    printf("-l scriptfile\tread commands from scriptfile on startup\n");
    printf("-p\t\tpipe-mode\n");
    printf("-q\t\tquiet mode (more quiet than pipe-mode)\n");
    printf("-r\t\tdon't use readline library for input\n");
    printf("-s\t\tstop execution and exit\n");
    printf("-v\t\tprint version number\n");
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v5; // eax
char *v6; // rsi
unsigned __int64 v7; // rdi
int v8; // eax
__int64 v9; // rax
__int64 v10; // r13
unsigned int v11; // eax
char v13[104]; // [rsp+0h] [rbp-68h] BYREF

stack_init(argc, argv, envp);
v5 = time(0LL);
srand(v5);
while ( 1 )
{
v6 = (char *)argv;
v7 = (unsigned int)argc;
v8 = getopt(argc, (char *const *)argv, "e:f:hl:pqrsv");
if ( v8 == -1 )
break;
switch ( v8 )
{
case 'e':
my_interfaceparse(optarg);
break;
case 'f':
v9 = file_to_mem(optarg);
if ( v9 )
{
input_is_file = 1;
my_interfaceparse(v9);
}
exit(0);
case 'h':
print_help();
exit(0);
case 'l':
v10 = file_to_mem(optarg);
if ( v10 )
{
input_is_file = 1;
my_interfaceparse(v10);
xxfree(v10);
}
break;
case 'p':
pipe_mode = 1;
break;
case 'q':
quiet_mode = 1;
break;
case 'r':
use_readline = 0;
break;
case 's':
exit(0);
case 'v':
printf("%s %i.%i.%i%s\n", *argv, 0LL, 9LL, 16LL, "alpha");
exit(0);
default:
fputs(usagestring, stderr);
exit(1);
}
}
if ( !__PAIR64__(pipe_mode, quiet_mode) )
{
v6 = disclaimer;
v7 = (unsigned __int64)"%s";
printf("%s", disclaimer);
}
rl_basic_word_break_characters = " >";
rl_attempted_completion_function = my_completion;
while ( 1 )
{
if ( !promptmode )
{
v11 = stack_size(v7, v6);
v6 = "foma[%i]: ";
sprintf(v13, "foma[%i]: ", v11);
}
if ( promptmode == 1 )
{
if ( apply_direction != 1 || (strcpy(v13, "apply down> "), v6 = &LC15[13], promptmode == 1) )
{
if ( apply_direction != 2 || (strcpy(v13, "apply up> "), v6 = &LC16[11], promptmode == 1) )
{
if ( apply_direction == 3 )
strcpy(v13, "apply med> ");
}
}
}
if ( __PAIR64__(pipe_mode, quiet_mode) )
v13[0] = 0;
v7 = (unsigned __int64)rl_gets(v13);
if ( v7 )
goto LABEL_29;
if ( !promptmode )
{
putchar(10);
exit(0);
}
if ( promptmode != 1 )
{
LABEL_29:
input_is_file = 0;
my_interfaceparse(v7);
}
else
{
promptmode = 0;
v7 = 10LL;
putchar(10);
}
}
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v5; // eax
char *v6; // rsi
unsigned __int64 v7; // rdi
int v8; // eax
__int64 v9; // rax
__int64 v10; // r13
unsigned int v11; // eax
char v13[104]; // [rsp+0h] [rbp-68h] BYREF

stack_init(argc, argv, envp);
v5 = time(0LL);
srand(v5);
while ( 1 )
{
v6 = (char *)argv;
v7 = (unsigned int)argc;
v8 = getopt(argc, (char *const *)argv, "e:f:hl:pqrsv");
if ( v8 == -1 )
break;
switch ( v8 )
{
case 'e':
my_interfaceparse(optarg);
break;
case 'f':
v9 = file_to_mem(optarg);
if ( v9 )
{
input_is_file = 1;
my_interfaceparse(v9);
}
exit(0);
case 'h':
func4();
exit(0);
case 'l':
v10 = file_to_mem(optarg);
if ( v10 )
{
input_is_file = 1;
my_interfaceparse(v10);
xxfree(v10);
}
break;
case 'p':
pipe_mode = 1;
break;
case 'q':
quiet_mode = 1;
break;
case 'r':
use_readline = 0;
break;
case 's':
exit(0);
case 'v':
printf("%s %i.%i.%i%s\n", *argv, 0LL, 9LL, 16LL, "alpha");
exit(0);
default:
fputs(usagestring, stderr);
exit(1);
}
}
if ( !__PAIR64__(pipe_mode, quiet_mode) )
{
v6 = disclaimer;
v7 = (unsigned __int64)"%s";
printf("%s", disclaimer);
}
rl_basic_word_break_characters = " >";
rl_attempted_completion_function = my_completion;
while ( 1 )
{
if ( !promptmode )
{
v11 = stack_size(v7, v6);
v6 = "foma[%i]: ";
sprintf(v13, "foma[%i]: ", v11);
}
if ( promptmode == 1 )
{
if ( apply_direction != 1 || (strcpy(v13, "apply down> "), v6 = &LC15[13], promptmode == 1) )
{
if ( apply_direction != 2 || (strcpy(v13, "apply up> "), v6 = &LC16[11], promptmode == 1) )
{
if ( apply_direction == 3 )
strcpy(v13, "apply med> ");
}
}
}
if ( __PAIR64__(pipe_mode, quiet_mode) )
v13[0] = 0;
v7 = (unsigned __int64)func3(v13);
if ( v7 )
goto LABEL_29;
if ( !promptmode )
{
putchar(10);
exit(0);
}
if ( promptmode != 1 )
{
LABEL_29:
input_is_file = 0;
my_interfaceparse(v7);
}
else
{
promptmode = 0;
v7 = 10LL;
putchar(10);
}
}
}

original_code:
int main(int argc, char *argv[]) {
    int opt;
    char *scriptfile, prompt[50];
    extern void my_interfaceparse(char *my_string);
    stack_init();
    srand ((unsigned int)time(((void *)0)));
    while ((opt = getopt(argc, argv, "e:f:hl:pqrsv")) != -1) {
        switch(opt) {
        case 'e':
            my_interfaceparse(optarg);
            break;
        case 'f':
            scriptfile = file_to_mem(optarg);
            if (scriptfile != ((void *)0)) {
                input_is_file = 1;
                my_interfaceparse(scriptfile);
            }
            exit(0);
        case 'h':
            print_help();
            exit(0);
        case 'l':
            scriptfile = file_to_mem(optarg);
            if (scriptfile != ((void *)0)) {
                input_is_file = 1;
                my_interfaceparse(scriptfile);
  xxfree(scriptfile);
            }
            break;
        case 'p':
            pipe_mode = 1;
            break;
        case 'q':
            quiet_mode = 1;
            break;
        case 'r':
            use_readline = 0;
            break;
        case 's':
   exit(0);
        case 'v':
            printf("%s %i.%i.%i%s\n",argv[0],0,9,16,"alpha");
            exit(0);
        default:
            fprintf(stderr, "%s", usagestring);
            exit(1);
        }
    }
    if (!pipe_mode && !quiet_mode)
        printf("%s",disclaimer);
    rl_basic_word_break_characters = " >";
    rl_attempted_completion_function = my_completion;
    for(;;) {
        if (promptmode == 0)
            sprintf(prompt, "foma[%i]: ",stack_size());
        if (promptmode == 1 && apply_direction == 1)
            sprintf(prompt, "apply down> ");
        if (promptmode == 1 && apply_direction == 2)
            sprintf(prompt, "apply up> ");
        if (promptmode == 1 && apply_direction == 3)
            sprintf(prompt, "apply med> ");
        if (pipe_mode || quiet_mode)
            prompt[0] = '\0';
        command = rl_gets(prompt);
        if (command == ((void *)0) && promptmode == 0) {
            printf("\n");
            exit(0);
        }
        if (command == ((void *)0) && promptmode == 1) {
            promptmode = 0;
            printf("\n");
            continue;
        }
        input_is_file = 0;
        my_interfaceparse(command);
    }
}

canonical_original_code:
int main(int argc, char *argv[]) {
    int opt;
    char *scriptfile; char prompt[50];
    extern void my_interfaceparse(char *my_string);
    stack_init();
    srand ((unsigned int)time(((void *)0)));
    while ((opt = getopt(argc, argv, "e:f:hl:pqrsv")) != -1) {
        switch(opt) {
        case 'e':
            my_interfaceparse(optarg);
            break;
        case 'f':
            scriptfile = file_to_mem(optarg);
            if (scriptfile != ((void *)0)) {
                input_is_file = 1;
                my_interfaceparse(scriptfile);
            }
            exit(0);
        case 'h':
            print_help();
            exit(0);
        case 'l':
            scriptfile = file_to_mem(optarg);
            if (scriptfile != ((void *)0)) {
                input_is_file = 1;
                my_interfaceparse(scriptfile);
  xxfree(scriptfile);
            }
            break;
        case 'p':
            pipe_mode = 1;
            break;
        case 'q':
            quiet_mode = 1;
            break;
        case 'r':
            use_readline = 0;
            break;
        case 's':
   exit(0);
        case 'v':
            printf("%s %i.%i.%i%s\n",argv[0],0,9,16,"alpha");
            exit(0);
        default:
            fprintf(stderr, "%s", usagestring);
            exit(1);
        }
    }
    if (!pipe_mode && !quiet_mode)
        printf("%s",disclaimer);
    rl_basic_word_break_characters = " >";
    rl_attempted_completion_function = my_completion;
    for(;;) {
        if (promptmode == 0)
            sprintf(prompt, "foma[%i]: ",stack_size());
        if (promptmode == 1 && apply_direction == 1)
            sprintf(prompt, "apply down> ");
        if (promptmode == 1 && apply_direction == 2)
            sprintf(prompt, "apply up> ");
        if (promptmode == 1 && apply_direction == 3)
            sprintf(prompt, "apply med> ");
        if (pipe_mode || quiet_mode)
            prompt[0] = '\0';
        command = rl_gets(prompt);
        if (command == ((void *)0) && promptmode == 0) {
            printf("\n");
            exit(0);
        }
        if (command == ((void *)0) && promptmode == 1) {
            promptmode = 0;
            printf("\n");
            continue;
        }
        input_is_file = 0;
        my_interfaceparse(command);
    }
}

variable_types: opt int

variable_types:
scriptfile
char *

variable_types:
prompt
char [50]


decompiled_code:
_QWORD *sh_init()
{
_QWORD *v0; // rbx

v0 = (_QWORD *)xxmalloc(16LL);
*v0 = xxcalloc(0x1FFFLL, 24LL);
return v0;
}

canonical_decompiled_code:
_QWORD *func0()
{
_QWORD *v0; // rbx

v0 = (_QWORD *)xxmalloc(16LL);
*v0 = xxcalloc(0x1FFFLL, 24LL);
return v0;
}

original_code:
struct sh_handle *sh_init() {
    struct sh_handle *sh;
    sh = xxmalloc(sizeof(struct sh_handle));
    sh->hash = xxcalloc(8191, sizeof(struct sh_hashtable));
    return(sh);
}

variable_types: struct sh_handle { struct sh_hashtable { char *string; int value; struct sh_hashtable *next; } *hash; int lastvalue; } *

user_defined_types: struct sh_handle { struct sh_hashtable *hash; int lastvalue; }


decompiled_code:
__int64 __fastcall sh_done(_QWORD *a1)
{
__int64 i; // r12
_QWORD *v2; // rbp
_QWORD *v3; // rbx
_QWORD *v4; // rbx

for ( i = 0LL; i != 196584; i += 24LL )
{
v4 = (_QWORD *)(*a1 + i);
if ( *v4 )
((void (*)(void))xxfree)();
v3 = (_QWORD *)v4[2];
while ( v3 )
{
v2 = v3;
v3 = (_QWORD *)v3[2];
if ( *v2 )
((void (*)(void))xxfree)();
xxfree(v2);
}
}
xxfree(*a1);
return xxfree(a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1)
{
__int64 i; // r12
_QWORD *v2; // rbp
_QWORD *v3; // rbx
_QWORD *v4; // rbx

for ( i = 0LL; i != 196584; i += 24LL )
{
v4 = (_QWORD *)(*a1 + i);
if ( *v4 )
((void (*)(void))xxfree)();
v3 = (_QWORD *)v4[2];
while ( v3 )
{
v2 = v3;
v3 = (_QWORD *)v3[2];
if ( *v2 )
((void (*)(void))xxfree)();
xxfree(v2);
}
}
xxfree(*a1);
return xxfree(a1);
}

original_code:
void sh_done(struct sh_handle *sh) {
    int i;
    struct sh_hashtable *hash, *hashp;
    for (i=0; i < 8191; i++) {
 hash = sh->hash + i;
 if (hash->string != ((void *)0))
     xxfree(hash->string);
 for (hash=hash->next ; hash != ((void *)0) ; hash = hashp) {
     hashp = hash->next;
     if (hash->string != ((void *)0))
  xxfree(hash->string);
     xxfree(hash);
 }
    }
    xxfree(sh->hash);
    xxfree(sh);
}

canonical_original_code:
void sh_done(struct sh_handle *sh) {
    int i;
    struct sh_hashtable *hash; struct sh_hashtable *hashp;
    for (i=0; i < 8191; i++) {
 hash = sh->hash + i;
 if (hash->string != ((void *)0))
     xxfree(hash->string);
 for (hash=hash->next ; hash != ((void *)0) ; hash = hashp) {
     hashp = hash->next;
     if (hash->string != ((void *)0))
  xxfree(hash->string);
     xxfree(hash);
 }
    }
    xxfree(sh->hash);
    xxfree(sh);
}

variable_types: i int

variable_types: struct sh_hashtable { char *string; int value; struct sh_hashtable *next; } *


decompiled_code:
__int64 __fastcall sh_get_value(__int64 a1)
{
return *(unsigned int *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
return *(unsigned int *)(a1 + 8);
}

original_code:
int sh_get_value(struct sh_handle *sh) {
    return(sh->lastvalue);
}

user_defined_types: struct sh_hashtable { char *string; int value; struct sh_hashtable *next; }


decompiled_code:
__int64 __fastcall sh_hashf(char *a1)
{
char v1; // al
unsigned int v2; // edx

v1 = *a1;
if ( *a1 )
{
v2 = 0;
do
{
++a1;
v2 = v1 + 101 * v2;
v1 = *a1;
}
while ( *a1 );
}
else
{
v2 = 0;
}
return v2 % 0x1FFF;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *a1)
{
char v1; // al
unsigned int v2; // edx

v1 = *a1;
if ( *a1 )
{
v2 = 0;
do
{
++a1;
v2 = v1 + 101 * v2;
v1 = *a1;
}
while ( *a1 );
}
else
{
v2 = 0;
}
return v2 % 0x1FFF;
}

original_code:
unsigned int sh_hashf(char *string) {
    register unsigned int hash;
    hash = 0;
    while (*string != '\0') {
        hash = hash * 101 + *string++;
    }
    return (hash % 8191);
}

variable_types:
hash
unsigned int

return_type: unsigned int


decompiled_code:
const char *__fastcall sh_find_string(__int64 a1, char *a2)
{
__int64 v3; // rbx
const char *v4; // rdi

v3 = *(_QWORD *)a1 + 24LL * (unsigned int)sh_hashf(a2);
if ( !v3 )
return 0LL;
while ( 1 )
{
v4 = *(const char **)v3;
if ( !*(_QWORD *)v3 )
break;
if ( !strcmp(v4, a2) )
{
*(_DWORD *)(a1 + 8) = *(_DWORD *)(v3 + 8);
return *(const char **)v3;
}
v3 = *(_QWORD *)(v3 + 16);
if ( !v3 )
return 0LL;
}
return v4;
}

canonical_decompiled_code:
const char *__fastcall func4(__int64 a1, char *a2)
{
__int64 v3; // rbx
const char *v4; // rdi

v3 = *(_QWORD *)a1 + 24LL * (unsigned int)func3(a2);
if ( !v3 )
return 0LL;
while ( 1 )
{
v4 = *(const char **)v3;
if ( !*(_QWORD *)v3 )
break;
if ( !strcmp(v4, a2) )
{
*(_DWORD *)(a1 + 8) = *(_DWORD *)(v3 + 8);
return *(const char **)v3;
}
v3 = *(_QWORD *)(v3 + 16);
if ( !v3 )
return 0LL;
}
return v4;
}

original_code:
char *sh_find_string(struct sh_handle *sh, char *string) {
    struct sh_hashtable *hash;
    for (hash = sh->hash + sh_hashf(string) ; hash != ((void *)0); hash = hash->next) {
 if (hash->string == ((void *)0))
     return ((void *)0);
 if (strcmp(hash->string, string) == 0) {
     sh->lastvalue = hash->value;
     return(hash->string);
 }
    }
    return ((void *)0);
}


decompiled_code:
__int64 __fastcall sh_add_string(_QWORD *a1, char *a2, int a3)
{
__int64 v4; // r13
__int64 v5; // rbx
__int64 result; // rax

v4 = *a1 + 24LL * (unsigned int)sh_hashf(a2);
if ( *(_QWORD *)v4 )
{
v5 = xxmalloc(24LL);
*(_QWORD *)v5 = xxstrdup(a2);
*(_DWORD *)(v5 + 8) = a3;
*(_QWORD *)(v5 + 16) = *(_QWORD *)(v4 + 16);
*(_QWORD *)(v4 + 16) = v5;
result = *(_QWORD *)v5;
}
else
{
result = xxstrdup(a2);
*(_QWORD *)v4 = result;
*(_DWORD *)(v4 + 8) = a3;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(_QWORD *a1, char *a2, int a3)
{
__int64 v4; // r13
__int64 v5; // rbx
__int64 result; // rax

v4 = *a1 + 24LL * (unsigned int)func3(a2);
if ( *(_QWORD *)v4 )
{
v5 = xxmalloc(24LL);
*(_QWORD *)v5 = xxstrdup(a2);
*(_DWORD *)(v5 + 8) = a3;
*(_QWORD *)(v5 + 16) = *(_QWORD *)(v4 + 16);
*(_QWORD *)(v4 + 16) = v5;
result = *(_QWORD *)v5;
}
else
{
result = xxstrdup(a2);
*(_QWORD *)v4 = result;
*(_DWORD *)(v4 + 8) = a3;
}
return result;
}

original_code:
char *sh_add_string(struct sh_handle *sh, char *string, int value) {
    struct sh_hashtable *hash, *newhash;
    hash = sh->hash + sh_hashf(string);
    if (hash->string == ((void *)0)) {
 hash->string = xxstrdup(string);
 hash->value = value;
 return(hash->string);
    } else {
 newhash = xxmalloc(sizeof(struct sh_hashtable));
 newhash->string = xxstrdup(string);
 newhash->value = value;
 newhash->next = hash->next;
 hash->next = newhash;
 return(newhash->string);
    }
}

canonical_original_code:
char *sh_add_string(struct sh_handle *sh, char *string, int value) {
    struct sh_hashtable *hash; struct sh_hashtable *newhash;
    hash = sh->hash + sh_hashf(string);
    if (hash->string == ((void *)0)) {
 hash->string = xxstrdup(string);
 hash->value = value;
 return(hash->string);
    } else {
 newhash = xxmalloc(sizeof(struct sh_hashtable));
 newhash->string = xxstrdup(string);
 newhash->value = value;
 newhash->next = hash->next;
 hash->next = newhash;
 return(newhash->string);
    }
}

variable_types: value int


decompiled_code:
__int64 __fastcall sh_find_add_string(_QWORD *a1, char *a2, int a3)
{
__int64 result; // rax

result = (__int64)sh_find_string((__int64)a1, a2);
if ( !result )
result = sh_add_string(a1, a2, a3);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(_QWORD *a1, char *a2, int a3)
{
__int64 result; // rax

result = (__int64)func4((__int64)a1, a2);
if ( !result )
result = func5(a1, a2, a3);
return result;
}

original_code:
char *sh_find_add_string(struct sh_handle *sh, char *string, int value) {
    char *s;
    s = sh_find_string(sh, string);
    if (s == ((void *)0))
 return (sh_add_string(sh, string, value));
    else
 return(s);
}

variable_types:
s
char *


decompiled_code:
_BOOL8 ptr_stack_isempty()
{
return ptr_stack_top == -1;
}

canonical_decompiled_code:
_BOOL8 func0()
{
return ptr_stack_top == -1;
}

original_code:
int ptr_stack_isempty() {
    return ptr_stack_top == -1;
}


decompiled_code:
void ptr_stack_clear()
{
ptr_stack_top = -1;
}

canonical_decompiled_code:
void func1()
{
ptr_stack_top = -1;
}


decompiled_code:
__int64 ptr_stack_pop()
{
int v0; // eax

v0 = ptr_stack_top--;
return ptr_stack[v0];
}

canonical_decompiled_code:
__int64 func2()
{
int v0; // eax

v0 = ptr_stack_top--;
return ptr_stack[v0];
}

original_code:
void *ptr_stack_pop() {
    return ptr_stack[ptr_stack_top--];
}

return_type: void *


decompiled_code:
_BOOL8 ptr_stack_isfull()
{
return ptr_stack_top == (_DWORD)&unk_1FFFFF;
}

canonical_decompiled_code:
_BOOL8 func3()
{
return ptr_stack_top == (_DWORD)&unk_1FFFFF;
}

original_code:
int ptr_stack_isfull() {
    return (ptr_stack_top == (2097152 - 1));
}


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

if ( ptr_stack_isfull() )
{
fwrite("Pointer stack full!\n", 1uLL, 0x14uLL, stderr);
exit(1);
}
result = ++ptr_stack_top;
ptr_stack[ptr_stack_top] = a1;
return result;
}

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

if ( func3() )
{
fwrite("Pointer stack full!\n", 1uLL, 0x14uLL, stderr);
exit(1);
}
result = ++ptr_stack_top;
ptr_stack[ptr_stack_top] = a1;
return result;
}

original_code:
void ptr_stack_push(void *ptr) {
    if (ptr_stack_isfull()) {
        fprintf(stderr, "Pointer stack full!\n");
        exit(1);
    }
    ptr_stack[++ptr_stack_top] = ptr;
}

variable_types:
ptr
void *


decompiled_code:
_BOOL8 int_stack_isempty()
{
return top == -1;
}

canonical_decompiled_code:
_BOOL8 func5()
{
return top == -1;
}

original_code:
int int_stack_isempty() {
  return top == -1;
}


decompiled_code:
void int_stack_clear()
{
top = -1;
}

canonical_decompiled_code:
void func6()
{
top = -1;
}

original_code:
void int_stack_clear() {
  top = -1;
}

canonical_original_code:
void int_stack_clear() {
  top = -1;
}


decompiled_code:
__int64 __fastcall int_stack_find(int a1)
{
unsigned int v1; // esi
__int64 v2; // rax

v1 = 0;
if ( !int_stack_isempty() )
{
v1 = 0;
if ( top >= 0 )
{
v2 = 0LL;
while ( a[v2] != a1 )
{
if ( top < (int)++v2 )
return v1;
}
v1 = 1;
}
}
return v1;
}

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

v1 = 0;
if ( !func5() )
{
v1 = 0;
if ( top >= 0 )
{
v2 = 0LL;
while ( a[v2] != a1 )
{
if ( top < (int)++v2 )
return v1;
}
v1 = 1;
}
}
return v1;
}

original_code:
int int_stack_find (int entry) {
  int i;
  if (int_stack_isempty()) {
    return 0;
  }
  for(i = 0; i <= top ; i++) {
    if (entry == a[i]) {
      return 1;
    }
  }
  return 0;
}

canonical_original_code:
int int_stack_find(int entry) {
  int i;
  if (int_stack_isempty()) {
    return 0;
  }
  for(i = 0; i <= top ; i++) {
    if (entry == a[i]) {
      return 1;
    }
  }
  return 0;
}

variable_types: entry int


decompiled_code:
__int64 int_stack_size()
{
return (unsigned int)(top + 1);
}

canonical_decompiled_code:
__int64 func8()
{
return (unsigned int)(top + 1);
}

original_code:
int int_stack_size () {
  return (top + 1);
}

canonical_original_code:
int int_stack_size() {
  return (top + 1);
}


decompiled_code:
__int64 int_stack_pop()
{
int v0; // eax

v0 = top--;
return (unsigned int)a[v0];
}

canonical_decompiled_code:
__int64 func9()
{
int v0; // eax

v0 = top--;
return (unsigned int)a[v0];
}

original_code:
int int_stack_pop() {
  return a[top--];
}


decompiled_code:
_BOOL8 int_stack_isfull()
{
return top == (_DWORD)&unk_1FFFFF;
}

canonical_decompiled_code:
_BOOL8 func10()
{
return top == (_DWORD)&unk_1FFFFF;
}

original_code:
int int_stack_isfull() {
  return (top == (2097152 - 1));
}


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

if ( int_stack_isfull() )
{
fwrite("Stack full!\n", 1uLL, 0xCuLL, stderr);
exit(1);
}
result = ++top;
a[top] = a1;
return result;
}

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

if ( func10() )
{
fwrite("Stack full!\n", 1uLL, 0xCuLL, stderr);
exit(1);
}
result = ++top;
a[top] = a1;
return result;
}

original_code:
void int_stack_push(int c) {
  if (int_stack_isfull()) {
    fprintf(stderr, "Stack full!\n");
    exit(1);
  }
  a[++top] = c;
}

variable_types: c int


ssortcmp

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

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

original_code:
int ssortcmp(struct ssort *a, struct ssort *b) {
  return(strcmp(a->symbol, b->symbol));
}

variable_types: struct ssort { char *symbol; int number; } *

variable_types:
b
struct ssort *


original_code:
struct sigma *sigma_remove(char *symbol, struct sigma *sigma) {
  struct sigma *sigma_start, *sigma_prev = ((void *)0);
  sigma_prev = ((void *)0);
  sigma_start = sigma;
  for ( ; sigma != ((void *)0) && sigma->number != -1; sigma_prev = sigma, sigma=sigma->next) {
    if (strcmp(sigma->symbol,symbol) == 0) {
      if (sigma_prev == ((void *)0)) {
 sigma_start = sigma->next;
 xxfree(sigma->symbol);
 xxfree(sigma);
      } else {
 (sigma_prev)->next = sigma->next;
 xxfree(sigma->symbol);
 xxfree(sigma);
      }
      break;
    }
  }
  return(sigma_start);
}

canonical_original_code:
struct sigma *sigma_remove(char *symbol, struct sigma *sigma) {
  struct sigma *sigma_start; struct sigma *sigma_prev = ((void *)0);
  sigma_prev = ((void *)0);
  sigma_start = sigma;
  for ( ; sigma != ((void *)0) && sigma->number != -1; sigma_prev = sigma, sigma=sigma->next) {
    if (strcmp(sigma->symbol,symbol) == 0) {
      if (sigma_prev == ((void *)0)) {
 sigma_start = sigma->next;
 xxfree(sigma->symbol);
 xxfree(sigma);
      } else {
 (sigma_prev)->next = sigma->next;
 xxfree(sigma->symbol);
 xxfree(sigma);
      }
      break;
    }
  }
  return(sigma_start);
}

variable_types:
symbol
char *

variable_types:
sigma
struct sigma *

variable_types: struct sigma { int number; char *symbol; struct sigma *next; } *


original_code:
struct sigma *sigma_remove_num(int num, struct sigma *sigma) {
  struct sigma *sigma_start, *sigma_prev = ((void *)0);
  sigma_prev = ((void *)0);
  sigma_start = sigma;
  for ( ; sigma != ((void *)0) && sigma->number != -1; sigma_prev = sigma, sigma=sigma->next) {
    if (sigma->number == num) {
      if (sigma_prev == ((void *)0)) {
 sigma_start = sigma->next;
 xxfree(sigma->symbol);
 xxfree(sigma);
      } else {
 (sigma_prev)->next = sigma->next;
 xxfree(sigma->symbol);
 xxfree(sigma);
      }
      break;
    }
  }
  return(sigma_start);
}

canonical_original_code:
struct sigma *sigma_remove_num(int num, struct sigma *sigma) {
  struct sigma *sigma_start; struct sigma *sigma_prev = ((void *)0);
  sigma_prev = ((void *)0);
  sigma_start = sigma;
  for ( ; sigma != ((void *)0) && sigma->number != -1; sigma_prev = sigma, sigma=sigma->next) {
    if (sigma->number == num) {
      if (sigma_prev == ((void *)0)) {
 sigma_start = sigma->next;
 xxfree(sigma->symbol);
 xxfree(sigma);
      } else {
 (sigma_prev)->next = sigma->next;
 xxfree(sigma->symbol);
 xxfree(sigma);
      }
      break;
    }
  }
  return(sigma_start);
}

variable_types: num int

return_type: struct sigma { int number; char *symbol; struct sigma *next; } *


original_code:
int sigma_add_special (int symbol, struct sigma *sigma) {
    struct sigma *sigma_previous = ((void *)0), *sigma_splice = ((void *)0);
    char *str = ((void *)0);
    if (symbol == 0)
        str = xxstrdup("@_EPSILON_SYMBOL_@");
    if (symbol == 2)
        str = xxstrdup("@_IDENTITY_SYMBOL_@");
    if (symbol == 1)
        str = xxstrdup("@_UNKNOWN_SYMBOL_@");
    if (sigma->number == -1) {
      sigma->number = symbol;
    } else {
        for (;(sigma != ((void *)0)) && (sigma->number < symbol) && (sigma->number!=-1); sigma_previous=sigma,sigma = sigma->next) {
      }
      sigma_splice = xxmalloc(sizeof(struct sigma));
      if (sigma_previous != ((void *)0)) {
 (sigma_previous)->next = sigma_splice;
 sigma_splice->number = symbol;
 sigma_splice->symbol = str;
 (sigma_splice)->next = sigma;
 return(symbol);
      } else {
 sigma_splice->symbol = sigma->symbol;
 sigma_splice->number = sigma->number;
 sigma_splice->next = sigma->next;
 sigma->number = symbol;
 sigma->symbol = str;
 sigma->next = sigma_splice;
 return(symbol);
      }
    }
    sigma->next = ((void *)0);
    sigma->symbol = str;
    return(symbol);
}

canonical_original_code:
int sigma_add_special(int symbol, struct sigma *sigma) {
    struct sigma *sigma_previous = ((void *)0); struct sigma *sigma_splice = ((void *)0);
    char *str = ((void *)0);
    if (symbol == 0)
        str = xxstrdup("@_EPSILON_SYMBOL_@");
    if (symbol == 2)
        str = xxstrdup("@_IDENTITY_SYMBOL_@");
    if (symbol == 1)
        str = xxstrdup("@_UNKNOWN_SYMBOL_@");
    if (sigma->number == -1) {
      sigma->number = symbol;
    } else {
        for (;(sigma != ((void *)0)) && (sigma->number < symbol) && (sigma->number!=-1); sigma_previous=sigma,sigma = sigma->next) {
      }
      sigma_splice = xxmalloc(sizeof(struct sigma));
      if (sigma_previous != ((void *)0)) {
 (sigma_previous)->next = sigma_splice;
 sigma_splice->number = symbol;
 sigma_splice->symbol = str;
 (sigma_splice)->next = sigma;
 return(symbol);
      } else {
 sigma_splice->symbol = sigma->symbol;
 sigma_splice->number = sigma->number;
 sigma_splice->next = sigma->next;
 sigma->number = symbol;
 sigma->symbol = str;
 sigma->next = sigma_splice;
 return(symbol);
      }
    }
    sigma->next = ((void *)0);
    sigma->symbol = str;
    return(symbol);
}

variable_types: symbol int

variable_types:
str
char *

user_defined_types: struct sigma { int number; char *symbol; struct sigma *next; }


original_code:
int sigma_add (char *symbol, struct sigma *sigma) {
  int assert = -1;
  struct sigma *sigma_previous = ((void *)0), *sigma_splice = ((void *)0);
  if (strcmp(symbol, "@_EPSILON_SYMBOL_@") == 0)
    assert = 0;
  if (strcmp(symbol,"@_IDENTITY_SYMBOL_@") == 0)
    assert = 2;
  if (strcmp(symbol,"@_UNKNOWN_SYMBOL_@") == 0)
    assert = 1;
  if (assert == -1) {
    if (sigma->number == -1) {
  sigma->number = 3;
    } else {
      for (; sigma->next != ((void *)0); sigma = sigma->next) {
      }
      sigma->next = xxmalloc(sizeof(struct sigma));
      if ((sigma->number)+1 < 3) {
 (sigma->next)->number = 3;
      } else {
 (sigma->next)->number = (sigma->number)+1;
      }
      sigma = sigma->next;
    }
    sigma->next = ((void *)0);
    sigma->symbol = xxstrdup(symbol);
    return(sigma->number);
  } else {
    if (sigma->number == -1) {
      sigma->number = assert;
    } else {
      for (;(sigma != ((void *)0)) && (sigma->number < assert) && (sigma->number!=-1); sigma_previous=sigma,sigma = sigma->next) {
      }
      sigma_splice = xxmalloc(sizeof(struct sigma));
      if (sigma_previous != ((void *)0)) {
 (sigma_previous)->next = sigma_splice;
 sigma_splice->number = assert;
 sigma_splice->symbol = xxmalloc(sizeof(char)*(strlen(symbol)+1));
 strcpy(sigma_splice->symbol, symbol);
 (sigma_splice)->next = sigma;
 return(assert);
      } else {
 sigma_splice->symbol = sigma->symbol;
 sigma_splice->number = sigma->number;
 sigma_splice->next = sigma->next;
 sigma->number = assert;
 sigma->symbol = xxmalloc(sizeof(char)*(strlen(symbol)+1));
 strcpy(sigma->symbol, symbol);
 sigma->next = sigma_splice;
 return(assert);
      }
    }
    sigma->next = ((void *)0);
    sigma->symbol = xxstrdup(symbol);
    return(assert);
  }
}

canonical_original_code:
int sigma_add(char *symbol, struct sigma *sigma) {
  int assert = -1;
  struct sigma *sigma_previous = ((void *)0); struct sigma *sigma_splice = ((void *)0);
  if (strcmp(symbol, "@_EPSILON_SYMBOL_@") == 0)
    assert = 0;
  if (strcmp(symbol,"@_IDENTITY_SYMBOL_@") == 0)
    assert = 2;
  if (strcmp(symbol,"@_UNKNOWN_SYMBOL_@") == 0)
    assert = 1;
  if (assert == -1) {
    if (sigma->number == -1) {
  sigma->number = 3;
    } else {
      for (; sigma->next != ((void *)0); sigma = sigma->next) {
      }
      sigma->next = xxmalloc(sizeof(struct sigma));
      if ((sigma->number)+1 < 3) {
 (sigma->next)->number = 3;
      } else {
 (sigma->next)->number = (sigma->number)+1;
      }
      sigma = sigma->next;
    }
    sigma->next = ((void *)0);
    sigma->symbol = xxstrdup(symbol);
    return(sigma->number);
  } else {
    if (sigma->number == -1) {
      sigma->number = assert;
    } else {
      for (;(sigma != ((void *)0)) && (sigma->number < assert) && (sigma->number!=-1); sigma_previous=sigma,sigma = sigma->next) {
      }
      sigma_splice = xxmalloc(sizeof(struct sigma));
      if (sigma_previous != ((void *)0)) {
 (sigma_previous)->next = sigma_splice;
 sigma_splice->number = assert;
 sigma_splice->symbol = xxmalloc(sizeof(char)*(strlen(symbol)+1));
 strcpy(sigma_splice->symbol, symbol);
 (sigma_splice)->next = sigma;
 return(assert);
      } else {
 sigma_splice->symbol = sigma->symbol;
 sigma_splice->number = sigma->number;
 sigma_splice->next = sigma->next;
 sigma->number = assert;
 sigma->symbol = xxmalloc(sizeof(char)*(strlen(symbol)+1));
 strcpy(sigma->symbol, symbol);
 sigma->next = sigma_splice;
 return(assert);
      }
    }
    sigma->next = ((void *)0);
    sigma->symbol = xxstrdup(symbol);
    return(assert);
  }
}

variable_types: assert int


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

if ( !a1 )
return 0xFFFFFFFFLL;
result = 0xFFFFFFFFLL;
do
{
if ( (int)result < (int)*a1 )
result = *a1;
a1 = (unsigned int *)*((_QWORD *)a1 + 2);
}
while ( a1 );
return result;
}

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

if ( !a1 )
return 0xFFFFFFFFLL;
result = 0xFFFFFFFFLL;
do
{
if ( (int)result < (int)*a1 )
result = *a1;
a1 = (unsigned int *)*((_QWORD *)a1 + 2);
}
while ( a1 );
return result;
}

original_code:
int sigma_max(struct sigma *sigma) {
  int i;
  for (i=-1; sigma != ((void *)0); sigma = sigma->next)
      i = sigma->number > i ? sigma->number : i;
  return(i);
}

variable_types: i int


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

if ( !a1 )
return 0LL;
LODWORD(result) = 0;
do
{
result = (unsigned int)(result + 1);
a1 = *(_QWORD *)(a1 + 16);
}
while ( a1 );
return result;
}

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

if ( !a1 )
return 0LL;
LODWORD(result) = 0;
do
{
result = (unsigned int)(result + 1);
a1 = *(_QWORD *)(a1 + 16);
}
while ( a1 );
return result;
}

original_code:
int sigma_size(struct sigma *sigma) {
  int i;
  for(i=0; sigma != ((void *)0); sigma = sigma->next)
    i++;
  return(i);
}


decompiled_code:
__int64 __fastcall sigma_to_list(unsigned int *a1)
{
unsigned int *v1; // rbx
int v2; // eax
__int64 i; // rcx

v1 = a1;
v2 = sigma_max(a1);
for ( i = xxcalloc(v2 + 1, 8LL); v1; v1 = (unsigned int *)*((_QWORD *)v1 + 2) )
{
if ( *v1 == -1 )
break;
*(_QWORD *)(i + 8LL * (int)*v1) = *((_QWORD *)v1 + 1);
}
return i;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int *a1)
{
unsigned int *v1; // rbx
int v2; // eax
__int64 i; // rcx

v1 = a1;
v2 = func5(a1);
for ( i = xxcalloc(v2 + 1, 8LL); v1; v1 = (unsigned int *)*((_QWORD *)v1 + 2) )
{
if ( *v1 == -1 )
break;
*(_QWORD *)(i + 8LL * (int)*v1) = *((_QWORD *)v1 + 1);
}
return i;
}

original_code:
struct fsm_sigma_list *sigma_to_list(struct sigma *sigma) {
    struct fsm_sigma_list *sl;
    struct sigma *s;
    sl = xxcalloc(sigma_max(sigma)+1,sizeof(struct fsm_sigma_list));
    for (s = sigma; s != ((void *)0) && s->number != -1; s = s->next) {
        (sl+(s->number))->symbol = s->symbol;
    }
    return sl;
}

variable_types: struct fsm_sigma_list { char *symbol; } *


original_code:
int sigma_add_number(struct sigma *sigma, char *symbol, int number) {
    struct sigma *newsigma, *prev_sigma;
    prev_sigma = ((void *)0);
    if (sigma->number == -1) {
        sigma->symbol = xxstrdup(symbol);
        sigma->number = number;
        sigma->next = ((void *)0);
        return(1);
    }
    for (newsigma = sigma; newsigma != ((void *)0); newsigma = newsigma->next) {
        prev_sigma = newsigma;
    }
    newsigma = xxmalloc(sizeof(struct sigma));
    newsigma->symbol = xxstrdup(symbol);
    newsigma->number = number;
    newsigma->next = ((void *)0);
    prev_sigma->next = newsigma;
    return(1);
}

canonical_original_code:
int sigma_add_number(struct sigma *sigma, char *symbol, int number) {
    struct sigma *newsigma; struct sigma *prev_sigma;
    prev_sigma = ((void *)0);
    if (sigma->number == -1) {
        sigma->symbol = xxstrdup(symbol);
        sigma->number = number;
        sigma->next = ((void *)0);
        return(1);
    }
    for (newsigma = sigma; newsigma != ((void *)0); newsigma = newsigma->next) {
        prev_sigma = newsigma;
    }
    newsigma = xxmalloc(sizeof(struct sigma));
    newsigma->symbol = xxstrdup(symbol);
    newsigma->number = number;
    newsigma->next = ((void *)0);
    prev_sigma->next = newsigma;
    return(1);
}

variable_types: number int


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

if ( !a2 )
return 0xFFFFFFFFLL;
result = *a2;
if ( (_DWORD)result != -1 )
{
while ( a1 != (_DWORD)result )
{
a2 = (unsigned int *)*((_QWORD *)a2 + 2);
if ( !a2 )
return 0xFFFFFFFFLL;
result = *a2;
if ( (_DWORD)result == -1 )
return result;
}
}
return result;
}

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

if ( !a2 )
return 0xFFFFFFFFLL;
result = *a2;
if ( (_DWORD)result != -1 )
{
while ( a1 != (_DWORD)result )
{
a2 = (unsigned int *)*((_QWORD *)a2 + 2);
if ( !a2 )
return 0xFFFFFFFFLL;
result = *a2;
if ( (_DWORD)result == -1 )
return result;
}
}
return result;
}

original_code:
int sigma_find_number(int number, struct sigma *sigma) {
    if (sigma == ((void *)0))
        return -1;
    if (sigma->number == -1) {
        return -1;
    }
    for (;(sigma != ((void *)0)) && (sigma->number != -1); sigma = sigma->next) {
        if (number == sigma->number) {
            return (sigma->number);
        }
    }
    return -1;
}


original_code:
void sigma_cleanup (struct fsm *net, int force) {
    int i,j,first,maxsigma,*attested;
    struct fsm_state *fsm;
    struct sigma *sig, *sig_prev, *sign;
    if (force == 0) {
        if (sigma_find_number(2, net->sigma) != -1)
            return;
        if (sigma_find_number(1, net->sigma) != -1)
            return;
    }
    maxsigma = sigma_max(net->sigma);
    if (maxsigma < 0) { return; }
    attested = xxmalloc(sizeof(int)*(maxsigma+1));
    for (i=0; i<=maxsigma; i++)
        *(attested+i) = 0;
    fsm = net->states;
    for (i=0; (fsm+i)->state_no != -1; i++) {
        if ((fsm+i)->in >=0)
            *(attested+(fsm+i)->in) = 1;
        if ((fsm+i)->out >=0)
            *(attested+(fsm+i)->out) = 1;
    }
    for (i=3,j=3; i<=maxsigma;i++ ) {
        if (*(attested+i)) {
            *(attested+i) = j;
            j++;
        }
    }
    for (i=0; (fsm+i)->state_no != -1; i++) {
        if ((fsm+i)->in > 2)
            (fsm+i)->in = *(attested+(fsm+i)->in);
        if ((fsm+i)->out > 2)
            (fsm+i)->out = *(attested+(fsm+i)->out);
    }
    sig_prev = ((void *)0);
    for (sig = net->sigma; sig != ((void *)0) && sig->number != -1; sig = sign) {
        first = 1;
 sign = sig->next;
        if (!*(attested+(sig->number))) {
     xxfree(sig->symbol);
     xxfree(sig);
            if (sig_prev != ((void *)0)) {
                sig_prev->next = sign;
                first = 0;
            } else {
                first = 0;
                net->sigma = sign;
            }
        } else {
            sig->number = sig->number >= 3 ? *(attested+(sig->number)) : sig->number;
        }
        if (first)
            sig_prev = sig;
    }
    xxfree(attested);
    return;
}

canonical_original_code:
void sigma_cleanup(struct fsm *net, int force) {
    int i; int j; int first; int maxsigma; int *attested;
    struct fsm_state *fsm;
    struct sigma *sig; struct sigma *sig_prev; struct sigma *sign;
    if (force == 0) {
        if (sigma_find_number(2, net->sigma) != -1)
            return;
        if (sigma_find_number(1, net->sigma) != -1)
            return;
    }
    maxsigma = sigma_max(net->sigma);
    if (maxsigma < 0) { return; }
    attested = xxmalloc(sizeof(int)*(maxsigma+1));
    for (i=0; i<=maxsigma; i++)
        *(attested+i) = 0;
    fsm = net->states;
    for (i=0; (fsm+i)->state_no != -1; i++) {
        if ((fsm+i)->in >=0)
            *(attested+(fsm+i)->in) = 1;
        if ((fsm+i)->out >=0)
            *(attested+(fsm+i)->out) = 1;
    }
    for (i=3,j=3; i<=maxsigma;i++ ) {
        if (*(attested+i)) {
            *(attested+i) = j;
            j++;
        }
    }
    for (i=0; (fsm+i)->state_no != -1; i++) {
        if ((fsm+i)->in > 2)
            (fsm+i)->in = *(attested+(fsm+i)->in);
        if ((fsm+i)->out > 2)
            (fsm+i)->out = *(attested+(fsm+i)->out);
    }
    sig_prev = ((void *)0);
    for (sig = net->sigma; sig != ((void *)0) && sig->number != -1; sig = sign) {
        first = 1;
 sign = sig->next;
        if (!*(attested+(sig->number))) {
     xxfree(sig->symbol);
     xxfree(sig);
            if (sig_prev != ((void *)0)) {
                sig_prev->next = sign;
                first = 0;
            } else {
                first = 0;
                net->sigma = sign;
            }
        } else {
            sig->number = sig->number >= 3 ? *(attested+(sig->number)) : sig->number;
        }
        if (first)
            sig_prev = sig;
    }
    xxfree(attested);
    return;
}

variable_types: struct fsm { char name[40]; int arity; int arccount; int statecount; int linecount; int finalcount; long long pathcount; int is_deterministic; int is_pruned; int is_minimized; int is_epsilon_free; int is_loop_free; int is_completed; int arcs_sorted_in; int arcs_sorted_out; struct fsm_state { int state_no; short in; short out; int target; char final_state; char start_state; } *states; struct sigma { int number; char *symbol; struct sigma *next; } *sigma; struct medlookup { int *confusion_matrix; } *medlookup; } *

variable_types: force int

variable_types: j int

variable_types: first int

variable_types: maxsigma int

variable_types:
attested
int *

user_defined_types: struct fsm { char name[40]; int arity; int arccount; int statecount; int linecount; int finalcount; long long pathcount; int is_deterministic; int is_pruned; int is_minimized; int is_epsilon_free; int is_loop_free; int is_completed; int arcs_sorted_in; int arcs_sorted_out; struct fsm_state *states; struct sigma *sigma; struct medlookup *medlookup; }


decompiled_code:
__int64 __fastcall sigma_string(int a1, int *a2)
{
int v2; // eax

if ( !a2 )
return 0LL;
v2 = *a2;
if ( *a2 == -1 )
return 0LL;
while ( 1 )
{
if ( a1 == v2 )
return *((_QWORD *)a2 + 1);
a2 = (int *)*((_QWORD *)a2 + 2);
if ( !a2 )
break;
v2 = *a2;
if ( *a2 == -1 )
return 0LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func11(int a1, int *a2)
{
int v2; // eax

if ( !a2 )
return 0LL;
v2 = *a2;
if ( *a2 == -1 )
return 0LL;
while ( 1 )
{
if ( a1 == v2 )
return *((_QWORD *)a2 + 1);
a2 = (int *)*((_QWORD *)a2 + 2);
if ( !a2 )
break;
v2 = *a2;
if ( *a2 == -1 )
return 0LL;
}
return 0LL;
}

original_code:
char *sigma_string(int number, struct sigma *sigma) {
    if (sigma == ((void *)0))
        return ((void *)0);
    if (sigma->number == -1) {
        return ((void *)0);
    }
    for (;(sigma != ((void *)0)) && (sigma->number != -1); sigma = sigma->next) {
        if (number == sigma->number) {
            return (sigma->symbol);
        }
    }
    return ((void *)0);
}


decompiled_code:
__int64 __fastcall sigma_find(char *s2, _DWORD *a2)
{
_DWORD *v2; // rbx
unsigned int v3; // ebp

v2 = a2;
v3 = *a2;
if ( *a2 != -1 )
{
while ( strcmp(*((const char **)v2 + 1), s2) )
{
v2 = (_DWORD *)*((_QWORD *)v2 + 2);
if ( !v2 )
return (unsigned int)-1;
v3 = *v2;
if ( *v2 == -1 )
return v3;
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func12(char *s2, _DWORD *a2)
{
_DWORD *v2; // rbx
unsigned int v3; // ebp

v2 = a2;
v3 = *a2;
if ( *a2 != -1 )
{
while ( strcmp(*((const char **)v2 + 1), s2) )
{
v2 = (_DWORD *)*((_QWORD *)v2 + 2);
if ( !v2 )
return (unsigned int)-1;
v3 = *v2;
if ( *v2 == -1 )
return v3;
}
}
return v3;
}

original_code:
int sigma_find(char *symbol, struct sigma *sigma) {
    if (sigma->number == -1) {
        return -1;
    }
    for (; sigma != ((void *)0) && sigma->number != -1 ; sigma = sigma->next) {
        if (strcmp(sigma->symbol, symbol) == 0) {
            return (sigma->number);
        }
    }
    return -1;
}


original_code:
int sigma_sort(struct fsm *net) {
  int(*comp)() = ssortcmp;
  int size, i, max, *replacearray;
  struct ssort *ssort;
  struct sigma *sigma;
  struct fsm_state *fsm_state;
  size = sigma_max(net->sigma);
  if (size < 0) { return 1; }
  ssort = xxmalloc(sizeof(struct ssort)*size);
  for (i=0, sigma=net->sigma; sigma != ((void *)0); sigma=sigma->next) {
    if (sigma->number > 2) {
      ssort[i].symbol = (char *)sigma->symbol;
      ssort[i].number = sigma->number;
      i++;
    }
  }
  max = i;
  qsort(ssort, max, sizeof(struct ssort), comp);
  replacearray = xxmalloc(sizeof(int)*(size+3));
  for (i=0; i<max; i++)
      replacearray[(ssort+i)->number] = i+3;
  for(i=0, fsm_state = net->states; (fsm_state+i)->state_no != -1; i++) {
    if ((fsm_state+i)->in > 2)
      (fsm_state+i)->in = replacearray[(fsm_state+i)->in];
    if ((fsm_state+i)->out > 2)
      (fsm_state+i)->out = replacearray[(fsm_state+i)->out];
  }
  for (i=0, sigma=net->sigma; sigma != ((void *)0); sigma=sigma->next) {
    if (sigma->number > 2) {
      sigma->number = i+3;
      sigma->symbol = (ssort+i)->symbol;
      i++;
    }
  }
  xxfree(replacearray);
  xxfree(ssort);
  return(1);
}

canonical_original_code:
int sigma_sort(struct fsm *net) {
  int (*comp)() = ssortcmp;
  int size; int i; int max; int *replacearray;
  struct ssort *ssort;
  struct sigma *sigma;
  struct fsm_state *fsm_state;
  size = sigma_max(net->sigma);
  if (size < 0) { return 1; }
  ssort = xxmalloc(sizeof(struct ssort)*size);
  for (i=0, sigma=net->sigma; sigma != ((void *)0); sigma=sigma->next) {
    if (sigma->number > 2) {
      ssort[i].symbol = (char *)sigma->symbol;
      ssort[i].number = sigma->number;
      i++;
    }
  }
  max = i;
  qsort(ssort, max, sizeof(struct ssort), comp);
  replacearray = xxmalloc(sizeof(int)*(size+3));
  for (i=0; i<max; i++)
      replacearray[(ssort+i)->number] = i+3;
  for(i=0, fsm_state = net->states; (fsm_state+i)->state_no != -1; i++) {
    if ((fsm_state+i)->in > 2)
      (fsm_state+i)->in = replacearray[(fsm_state+i)->in];
    if ((fsm_state+i)->out > 2)
      (fsm_state+i)->out = replacearray[(fsm_state+i)->out];
  }
  for (i=0, sigma=net->sigma; sigma != ((void *)0); sigma=sigma->next) {
    if (sigma->number > 2) {
      sigma->number = i+3;
      sigma->symbol = (ssort+i)->symbol;
      i++;
    }
  }
  xxfree(replacearray);
  xxfree(ssort);
  return(1);
}

variable_types:
comp
int (*)()

variable_types: size int

variable_types: max int

variable_types:
replacearray
int *

variable_types: struct ssort { char *symbol; int number; } *

variable_types: struct fsm_state { int state_no; short in; short out; int target; char final_state; char start_state; } *

user_defined_types: struct medlookup { int *confusion_matrix; }


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

result = xxmalloc(24LL);
*(_DWORD *)result = -1;
*(_QWORD *)(result + 16) = 0LL;
*(_QWORD *)(result + 8) = 0LL;
return result;
}

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

result = xxmalloc(24LL);
*(_DWORD *)result = -1;
*(_QWORD *)(result + 16) = 0LL;
*(_QWORD *)(result + 8) = 0LL;
return result;
}

original_code:
struct sigma *sigma_create() {
  struct sigma *sigma;
  sigma = xxmalloc(sizeof(struct sigma));
  sigma->number = -1;
  sigma->next = ((void *)0);
  sigma->symbol = ((void *)0);
  return(sigma);
}

variable_types: struct sigma { int number; char *symbol; struct sigma *next; } *


decompiled_code:
__int64 stack_size()
{
__int64 v0; // rax
unsigned int v1; // edx

v0 = *(_QWORD *)(main_stack + 32);
if ( !v0 )
return 0;
v1 = 0;
do
{
++v1;
v0 = *(_QWORD *)(v0 + 32);
}
while ( v0 );
return v1;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v0; // rax
unsigned int v1; // edx

v0 = *(_QWORD *)(main_stack + 32);
if ( !v0 )
return 0;
v1 = 0;
do
{
++v1;
v0 = *(_QWORD *)(v0 + 32);
}
while ( v0 );
return v1;
}

original_code:
int stack_size() {
  int i;
  struct stack_entry *stack_ptr;
  for (i=0, stack_ptr = main_stack; stack_ptr->next != ((void *)0); i++)
    stack_ptr = stack_ptr->next;
  return i;
}

variable_types: struct stack_entry { int number; struct apply_handle { int ptr; int curr_ptr; int ipos; int opos; int mode; int printcount; int *numlines; int *statemap; int *marks; struct sigma_trie { int signum; struct sigma_trie *next; } *sigma_trie; struct sigmatch_array { int signumber; int consumes; } *sigmatch_array; struct sigma_trie_arrays { struct sigma_trie *arr; struct sigma_trie_arrays *next; } *sigma_trie_arrays; int binsearch; int indexed; int state_has_index; int sigma_size; int sigmatch_array_size; int current_instring_length; int has_flags; int obey_flags; int show_flags; int print_space; int print_pairs; int apply_stack_ptr; int apply_stack_top; int oldflagneg; int outstringtop; int iterate_old; int iterator; unsigned char *flagstates; char *outstring; char *instring; struct sigs { char *symbol; int length; } *sigs; char *oldflagvalue; struct fsm { char name[40]; int arity; int arccount; int statecount; int linecount; int finalcount; long long pathcount; int is_deterministic; int is_pruned; int is_minimized; int is_epsilon_free; int is_loop_free; int is_completed; int arcs_sorted_in; int arcs_sorted_out; struct fsm_state { int state_no; short in; short out; int target; char final_state; char start_state; } *states; struct sigma { int number; char *symbol; struct sigma *next; } *sigma; struct medlookup { int *confusion_matrix; } *medlookup; } *last_net; struct fsm_state *gstates; struct sigma *gsigma; struct apply_state_index { int fsmptr; struct apply_state_index *next; } **index_in; struct flag_list { char *name; char *value; short neg; struct flag_list *next; } *flag_list; struct flag_lookup { int type; char *name; char *value; } *flag_lookup; struct searchstack { int offset; struct apply_state_index *iptr; int state_has_index; int opos; int ipos; int visitmark; char *flagname; char *flagvalue; int flagneg; } *searchstack; } *ah; struct apply_med_handle { struct astarnode { short wordpos; int fsmstate; short f; short g; short h; int in; int out; int parent; } *agenda; int bytes_per_letter_array; unsigned char *letterbits; unsigned char *nletterbits; int astarcount; int heapcount; int heap_size; int agenda_size; int maxdepth; int maxsigma; int wordlen; int utf8len; int cost; int nummatches; int curr_state; int curr_g; int curr_pos; int lines; int curr_agenda_offset; int curr_node_has_match; int med_limit; int med_cutoff; int med_max_heap_size; int nodes_expanded; int *cm; char *word; char *instring; int instring_length; char *outstring; int outstring_length; char *align_symbol; int *heap; int *intword; struct sh_handle { struct sh_hashtable { char *string; int value; struct sh_hashtable *next; } *hash; int lastvalue; } *sigmahash; struct state_array { struct fsm_state *transitions; } *state_array; struct fsm *net; struct fsm_state *curr_ptr; _Bool hascm; } *amedh; struct fsm *fsm; struct stack_entry *next; struct stack_entry *previous; } *

user_defined_types: struct stack_entry { int number; struct apply_handle *ah; struct apply_med_handle *amedh; struct fsm *fsm; struct stack_entry *next; struct stack_entry *previous; }

user_defined_types: struct apply_handle { int ptr; int curr_ptr; int ipos; int opos; int mode; int printcount; int *numlines; int *statemap; int *marks; struct sigma_trie *sigma_trie; struct sigmatch_array *sigmatch_array; struct sigma_trie_arrays *sigma_trie_arrays; int binsearch; int indexed; int state_has_index; int sigma_size; int sigmatch_array_size; int current_instring_length; int has_flags; int obey_flags; int show_flags; int print_space; int print_pairs; int apply_stack_ptr; int apply_stack_top; int oldflagneg; int outstringtop; int iterate_old; int iterator; unsigned char *flagstates; char *outstring; char *instring; struct sigs *sigs; char *oldflagvalue; struct fsm *last_net; struct fsm_state *gstates; struct sigma *gsigma; struct apply_state_index **index_in; struct flag_list *flag_list; struct flag_lookup *flag_lookup; struct searchstack *searchstack; }

user_defined_types: struct apply_med_handle { struct astarnode *agenda; int bytes_per_letter_array; unsigned char *letterbits; unsigned char *nletterbits; int astarcount; int heapcount; int heap_size; int agenda_size; int maxdepth; int maxsigma; int wordlen; int utf8len; int cost; int nummatches; int curr_state; int curr_g; int curr_pos; int lines; int curr_agenda_offset; int curr_node_has_match; int med_limit; int med_cutoff; int med_max_heap_size; int nodes_expanded; int *cm; char *word; char *instring; int instring_length; char *outstring; int outstring_length; char *align_symbol; int *heap; int *intword; struct sh_handle *sigmahash; struct state_array *state_array; struct fsm *net; struct fsm_state *curr_ptr; _Bool hascm; }


decompiled_code:
__int64 stack_init()
{
__int64 v0; // rax

main_stack = xxmalloc(48LL);
*(_DWORD *)main_stack = -1;
v0 = main_stack;
*(_QWORD *)(main_stack + 24) = 0LL;
*(_QWORD *)(v0 + 32) = 0LL;
*(_QWORD *)(v0 + 40) = 0LL;
return 1LL;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 v0; // rax

main_stack = xxmalloc(48LL);
*(_DWORD *)main_stack = -1;
v0 = main_stack;
*(_QWORD *)(main_stack + 24) = 0LL;
*(_QWORD *)(v0 + 32) = 0LL;
*(_QWORD *)(v0 + 40) = 0LL;
return 1LL;
}

original_code:
int stack_init() {
  main_stack = xxmalloc(sizeof(struct stack_entry));
  main_stack->number = -1;
  main_stack->fsm = ((void *)0);
  main_stack->next = ((void *)0);
  main_stack->previous = ((void *)0);
  return 1;
}

user_defined_types: struct sigma_trie { int signum; struct sigma_trie *next; }

user_defined_types: struct sigmatch_array { int signumber; int consumes; }

user_defined_types: struct sigma_trie_arrays { struct sigma_trie *arr; struct sigma_trie_arrays *next; }

user_defined_types: struct sigs { char *symbol; int length; }

user_defined_types: struct flag_list { char *name; char *value; short neg; struct flag_list *next; }

user_defined_types: struct flag_lookup { int type; char *name; char *value; }

user_defined_types: struct searchstack { int offset; struct apply_state_index *iptr; int state_has_index; int opos; int ipos; int visitmark; char *flagname; char *flagvalue; int flagneg; }

user_defined_types: struct astarnode { short wordpos; int fsmstate; short f; short g; short h; int in; int out; int parent; }

user_defined_types: struct state_array { struct fsm_state *transitions; }

user_defined_types: struct apply_state_index { int fsmptr; struct apply_state_index *next; }

user_defined_types: struct fsm_state { int state_no; short in; short out; int target; char final_state; char start_state; }


decompiled_code:
__int64 __fastcall stack_add(char *s)
{
_QWORD *v1; // rbx
int v2; // ebp
_QWORD *v3; // r12
_DWORD *v4; // rax
unsigned int v6; // eax

fsm_count();
if ( !*s )
{
v6 = rand();
sprintf(s, "%X", v6);
}
v1 = (_QWORD *)main_stack;
if ( *(_DWORD *)main_stack == -1 )
{
v3 = 0LL;
v2 = 0;
}
else
{
v2 = 0;
do
{
v3 = v1;
v1 = (_QWORD *)v1[4];
++v2;
}
while ( *(_DWORD *)v1 != -1 );
}
v4 = (_DWORD *)xxmalloc(48LL);
v1[4] = v4;
v1[3] = s;
v1[1] = 0LL;
v1[2] = 0LL;
*(_DWORD *)v1 = v2;
v1[5] = v3;
*v4 = -1;
*(_QWORD *)(v1[4] + 24LL) = 0LL;
*(_QWORD *)(v1[4] + 32LL) = 0LL;
*(_QWORD *)(v1[4] + 40LL) = v1;
if ( !quiet_mode )
print_stats(s);
return *(unsigned int *)v1;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *s)
{
_QWORD *v1; // rbx
int v2; // ebp
_QWORD *v3; // r12
_DWORD *v4; // rax
unsigned int v6; // eax

fsm_count();
if ( !*s )
{
v6 = rand();
sprintf(s, "%X", v6);
}
v1 = (_QWORD *)main_stack;
if ( *(_DWORD *)main_stack == -1 )
{
v3 = 0LL;
v2 = 0;
}
else
{
v2 = 0;
do
{
v3 = v1;
v1 = (_QWORD *)v1[4];
++v2;
}
while ( *(_DWORD *)v1 != -1 );
}
v4 = (_DWORD *)xxmalloc(48LL);
v1[4] = v4;
v1[3] = s;
v1[1] = 0LL;
v1[2] = 0LL;
*(_DWORD *)v1 = v2;
v1[5] = v3;
*v4 = -1;
*(_QWORD *)(v1[4] + 24LL) = 0LL;
*(_QWORD *)(v1[4] + 32LL) = 0LL;
*(_QWORD *)(v1[4] + 40LL) = v1;
if ( !quiet_mode )
print_stats(s);
return *(unsigned int *)v1;
}

original_code:
int stack_add(struct fsm *fsm) {
  int i;
  struct stack_entry *stack_ptr, *stack_ptr_previous;
  stack_ptr_previous = ((void *)0);
  fsm_count(fsm);
  if (strcmp(fsm->name,"") == 0)
      sprintf(fsm->name, "%X",rand());
  for (i=0, stack_ptr = main_stack; stack_ptr->number != -1; i++) {
    stack_ptr_previous = stack_ptr;
    stack_ptr = stack_ptr->next;
  }
  stack_ptr->next = xxmalloc(sizeof(struct stack_entry));
  stack_ptr->fsm = fsm;
  stack_ptr->ah = ((void *)0);
  stack_ptr->amedh = ((void *)0);
  stack_ptr->number = i;
  stack_ptr->previous = stack_ptr_previous;
  (stack_ptr->next)->number = -1;
  (stack_ptr->next)->fsm = ((void *)0);
  (stack_ptr->next)->next = ((void *)0);
  (stack_ptr->next)->previous = stack_ptr;
  if (!quiet_mode)
      print_stats(fsm);
  return(stack_ptr->number);
}

canonical_original_code:
int stack_add(struct fsm *fsm) {
  int i;
  struct stack_entry *stack_ptr; struct stack_entry *stack_ptr_previous;
  stack_ptr_previous = ((void *)0);
  fsm_count(fsm);
  if (strcmp(fsm->name,"") == 0)
      sprintf(fsm->name, "%X",rand());
  for (i=0, stack_ptr = main_stack; stack_ptr->number != -1; i++) {
    stack_ptr_previous = stack_ptr;
    stack_ptr = stack_ptr->next;
  }
  stack_ptr->next = xxmalloc(sizeof(struct stack_entry));
  stack_ptr->fsm = fsm;
  stack_ptr->ah = ((void *)0);
  stack_ptr->amedh = ((void *)0);
  stack_ptr->number = i;
  stack_ptr->previous = stack_ptr_previous;
  (stack_ptr->next)->number = -1;
  (stack_ptr->next)->fsm = ((void *)0);
  (stack_ptr->next)->next = ((void *)0);
  (stack_ptr->next)->previous = stack_ptr;
  if (!quiet_mode)
      print_stats(fsm);
  return(stack_ptr->number);
}

variable_types: i int

user_defined_types: struct sigma { int number; char *symbol; struct sigma *next; }

user_defined_types: struct sh_handle { struct sh_hashtable *hash; int lastvalue; }

user_defined_types: struct sh_hashtable { char *string; int value; struct sh_hashtable *next; }


decompiled_code:
_BOOL8 stack_isempty()
{
return *(_QWORD *)(main_stack + 32) == 0LL;
}

canonical_decompiled_code:
_BOOL8 func3()
{
return *(_QWORD *)(main_stack + 32) == 0LL;
}

original_code:
int stack_isempty () {
  if (main_stack->next == ((void *)0)) {
    return 1;
  } else {
    return 0;
  }
}

canonical_original_code:
int stack_isempty() {
  if (main_stack->next == ((void *)0)) {
    return 1;
  } else {
    return 0;
  }
}


decompiled_code:
__int64 stack_find_top()
{
__int64 v0; // rax
__int64 v1; // rdx

v0 = main_stack;
if ( *(_DWORD *)main_stack == -1 )
return 0LL;
do
{
v1 = v0;
v0 = *(_QWORD *)(v0 + 32);
}
while ( *(_DWORD *)v0 != -1 );
return v1;
}

canonical_decompiled_code:
__int64 func4()
{
__int64 v0; // rax
__int64 v1; // rdx

v0 = main_stack;
if ( *(_DWORD *)main_stack == -1 )
return 0LL;
do
{
v1 = v0;
v0 = *(_QWORD *)(v0 + 32);
}
while ( *(_DWORD *)v0 != -1 );
return v1;
}

original_code:
struct stack_entry *stack_find_top () {
  struct stack_entry *stack_ptr;
  if (main_stack->number == -1) {
    return ((void *)0);
  }
  for (stack_ptr = main_stack; (stack_ptr->next)->number != -1; stack_ptr = stack_ptr->next);
  return(stack_ptr);
}

canonical_original_code:
struct stack_entry *stack_find_top() {
  struct stack_entry *stack_ptr;
  if (main_stack->number == -1) {
    return ((void *)0);
  }
  for (stack_ptr = main_stack; (stack_ptr->next)->number != -1; stack_ptr = stack_ptr->next);
  return(stack_ptr);
}

return_type: struct stack_entry { int number; struct apply_handle { int ptr; int curr_ptr; int ipos; int opos; int mode; int printcount; int *numlines; int *statemap; int *marks; struct sigma_trie { int signum; struct sigma_trie *next; } *sigma_trie; struct sigmatch_array { int signumber; int consumes; } *sigmatch_array; struct sigma_trie_arrays { struct sigma_trie *arr; struct sigma_trie_arrays *next; } *sigma_trie_arrays; int binsearch; int indexed; int state_has_index; int sigma_size; int sigmatch_array_size; int current_instring_length; int has_flags; int obey_flags; int show_flags; int print_space; int print_pairs; int apply_stack_ptr; int apply_stack_top; int oldflagneg; int outstringtop; int iterate_old; int iterator; unsigned char *flagstates; char *outstring; char *instring; struct sigs { char *symbol; int length; } *sigs; char *oldflagvalue; struct fsm { char name[40]; int arity; int arccount; int statecount; int linecount; int finalcount; long long pathcount; int is_deterministic; int is_pruned; int is_minimized; int is_epsilon_free; int is_loop_free; int is_completed; int arcs_sorted_in; int arcs_sorted_out; struct fsm_state { int state_no; short in; short out; int target; char final_state; char start_state; } *states; struct sigma { int number; char *symbol; struct sigma *next; } *sigma; struct medlookup { int *confusion_matrix; } *medlookup; } *last_net; struct fsm_state *gstates; struct sigma *gsigma; struct apply_state_index { int fsmptr; struct apply_state_index *next; } **index_in; struct flag_list { char *name; char *value; short neg; struct flag_list *next; } *flag_list; struct flag_lookup { int type; char *name; char *value; } *flag_lookup; struct searchstack { int offset; struct apply_state_index *iptr; int state_has_index; int opos; int ipos; int visitmark; char *flagname; char *flagvalue; int flagneg; } *searchstack; } *ah; struct apply_med_handle { struct astarnode { short wordpos; int fsmstate; short f; short g; short h; int in; int out; int parent; } *agenda; int bytes_per_letter_array; unsigned char *letterbits; unsigned char *nletterbits; int astarcount; int heapcount; int heap_size; int agenda_size; int maxdepth; int maxsigma; int wordlen; int utf8len; int cost; int nummatches; int curr_state; int curr_g; int curr_pos; int lines; int curr_agenda_offset; int curr_node_has_match; int med_limit; int med_cutoff; int med_max_heap_size; int nodes_expanded; int *cm; char *word; char *instring; int instring_length; char *outstring; int outstring_length; char *align_symbol; int *heap; int *intword; struct sh_handle { struct sh_hashtable { char *string; int value; struct sh_hashtable *next; } *hash; int lastvalue; } *sigmahash; struct state_array { struct fsm_state *transitions; } *state_array; struct fsm *net; struct fsm_state *curr_ptr; _Bool hascm; } *amedh; struct fsm *fsm; struct stack_entry *next; struct stack_entry *previous; } *

user_defined_types: struct stack_entry { int number; struct apply_handle *ah; struct apply_med_handle *amedh; struct fsm *fsm; struct stack_entry *next; struct stack_entry *previous; }

user_defined_types: struct fsm { char name[40]; int arity; int arccount; int statecount; int linecount; int finalcount; long long pathcount; int is_deterministic; int is_pruned; int is_minimized; int is_epsilon_free; int is_loop_free; int is_completed; int arcs_sorted_in; int arcs_sorted_out; struct fsm_state *states; struct sigma *sigma; struct medlookup *medlookup; }