FormatAddress

decompiled_code:
__int64 __fastcall FormatAddress(const struct sockaddr *a1, socklen_t a2, char *a3, unsigned int a4)
{
unsigned int v6; // eax
unsigned int v7; // ebx
size_t v8; // r14
char serv[32]; // [rsp+0h] [rbp-458h] BYREF
char host[1080]; // [rsp+20h] [rbp-438h] BYREF

if ( !a1 || !a3 )
return (unsigned int)-1;
v6 = getnameinfo(a1, a2, host, 0x401u, serv, 0x20u, 3);
v7 = v6;
if ( v6 )
{
debug_outputlnA("%s %u : %d", "resolve.c", 66LL, v6);
}
else
{
v8 = strlen(host);
if ( v8 + strlen(serv) + 1 > a4 )
{
v7 = -1;
}
else if ( serv[0] == 48 )
{
v7 = format_string_into_buffer(a3, (int)a4, "%s", host);
}
else if ( a1->sa_family == 2 || a1->sa_family == 10 )
{
v7 = format_string_into_buffer(a3, (int)a4, "%s:%s", host, serv);
}
else
{
*a3 = 0;
}
}
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func2(const struct sockaddr *a1, socklen_t a2, char *a3, unsigned int a4)
{
unsigned int v6; // eax
unsigned int v7; // ebx
size_t v8; // r14
char serv[32]; // [rsp+0h] [rbp-458h] BYREF
char host[1080]; // [rsp+20h] [rbp-438h] BYREF

if ( !a1 || !a3 )
return (unsigned int)-1;
v6 = getnameinfo(a1, a2, host, 0x401u, serv, 0x20u, 3);
v7 = v6;
if ( v6 )
{
debug_outputlnA("%s %u : %d", "resolve.c", 66LL, v6);
}
else
{
v8 = strlen(host);
if ( v8 + strlen(serv) + 1 > a4 )
{
v7 = -1;
}
else if ( serv[0] == 48 )
{
v7 = func0(a3, (int)a4, "%s", host);
}
else if ( a1->sa_family == 2 || a1->sa_family == 10 )
{
v7 = func0(a3, (int)a4, "%s:%s", host, serv);
}
else
{
*a3 = 0;
}
}
return v7;
}

original_code:
int FormatAddress(struct sockaddr *sa, int salen, char *addrbuf, int addrbuflen)
{
    char host[1025],
            service[32];
    int hostlen = 1025,
            servlen = 32,
            rc;
    if ((sa == ((void *)0)) || (addrbuf == ((void *)0)))
        return (-1);
    rc = getnameinfo(sa, salen, host, hostlen, service, servlen, 1 | 2 );
    if (rc != 0)
    {
        debug_outputlnA("%s %u : %d", "resolve.c", 66, rc);
        return rc;
    }
    if ( (strlen(host) + strlen(service) + 1) > (unsigned)addrbuflen)
        return (-1);
    if (strncmp(service, "0", 1) != 0)
    {
        if (sa->sa_family == 2)
        {
            rc = format_string_into_buffer(addrbuf, addrbuflen, "%s:%s", host, service);
        }
        else if (sa->sa_family == 10)
        {
            rc = format_string_into_buffer(addrbuf, addrbuflen, "%s:%s", host, service);
        }
        else
            addrbuf[0] = '\0';
    }
    else
    {
        rc = format_string_into_buffer(addrbuf, addrbuflen, "%s", host);
    }
    return rc;
}

canonical_original_code:
int FormatAddress(struct sockaddr *sa, int salen, char *addrbuf, int addrbuflen)
{
    char host[1025]; char service[32];
    int hostlen = 1025; int servlen = 32; int rc;
    if ((sa == ((void *)0)) || (addrbuf == ((void *)0)))
        return (-1);
    rc = getnameinfo(sa, salen, host, hostlen, service, servlen, 1 | 2 );
    if (rc != 0)
    {
        debug_outputlnA("%s %u : %d", "resolve.c", 66, rc);
        return rc;
    }
    if ( (strlen(host) + strlen(service) + 1) > (unsigned int)addrbuflen)
        return (-1);
    if (strncmp(service, "0", 1) != 0)
    {
        if (sa->sa_family == 2)
        {
            rc = format_string_into_buffer(addrbuf, addrbuflen, "%s:%s", host, service);
        }
        else if (sa->sa_family == 10)
        {
            rc = format_string_into_buffer(addrbuf, addrbuflen, "%s:%s", host, service);
        }
        else
            addrbuf[0] = '\0';
    }
    else
    {
        rc = format_string_into_buffer(addrbuf, addrbuflen, "%s", host);
    }
    return rc;
}

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

variable_types: salen int

variable_types: addrbuflen int

variable_types:
host
char [1025]

variable_types:
service
char [32]

variable_types: hostlen int

variable_types: servlen int


ResolveAddress

repo: TomaszOstaszewski/Mcast

decompiled_code:
struct addrinfo *__fastcall ResolveAddress(const char *a1, const char *a2, int a3, int a4, int a5)
{
return sResolveAddress(a1, a2, a3, a4, a5, a1 != 0LL);
}

canonical_decompiled_code:
struct addrinfo *__fastcall func3(const char *a1, const char *a2, int a3, int a4, int a5)
{
return func1(a1, a2, a3, a4, a5, a1 != 0LL);
}

original_code:
struct addrinfo *ResolveAddress(char *addr, char *port, int af, int type, int proto)
{
    int flags = 0;
    if (((void *)0) != addr)
        flags = 0x0001;
    return sResolveAddress(addr, port, af, type, proto, flags);
}

variable_types:
addr
char *

variable_types:
port
char *

variable_types: af int

variable_types: type int

variable_types: proto int

variable_types: flags int

return_type: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ai_addr; char *ai_canonname; struct addrinfo *ai_next; } *

user_defined_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr *ai_addr; char *ai_canonname; struct addrinfo *ai_next; }


ResolveAddressWithFlags

decompiled_code:
struct addrinfo *__fastcall ResolveAddressWithFlags(const char *a1, const char *a2, int a3, int a4, int a5, int a6)
{
return sResolveAddress(a1, a2, a3, a4, a5, a6);
}

canonical_decompiled_code:
struct addrinfo *__fastcall func4(const char *a1, const char *a2, int a3, int a4, int a5, int a6)
{
return func1(a1, a2, a3, a4, a5, a6);
}

original_code:
struct addrinfo *ResolveAddressWithFlags(char *addr, char *port, int af, int type, int proto, int flags)
{
    return sResolveAddress(addr, port, af, type, proto, flags);
}

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


decompiled_code:
void sigint_handle()
{
g_stop_processing = 1;
}

canonical_decompiled_code:
void func0()
{
g_stop_processing = 1;
}

original_code:
static void sigint_handle(int signal)
{
    g_stop_processing = 1;
}

variable_types: signal int

return_type: void


decompiled_code:
__int64 __fastcall get_samples_buffer(__int64 a1)
{
return a1 + 44;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return a1 + 44;
}

original_code:
const int8_t * get_samples_buffer(struct master_riff_chunk const * p_header)
{
    wav_format_chunk_2_t const * p_wave_format_chunk;
    plainwaveformat_t const * p_plainwave;
    wav_subchunk_t const * p_subchunk;
    p_wave_format_chunk = &p_header->format_chunk_2_;
    p_plainwave = &p_wave_format_chunk->plain_wav_;
    p_subchunk = &p_plainwave->subchunk_;
    return &p_subchunk->samples8_[0];
}

canonical_original_code:
char *get_samples_buffer(struct master_riff_chunk *p_header)
{
    struct wav_format_chunk_2 *p_wave_format_chunk;
    struct plainwaveformat *p_plainwave;
    struct wav_subchunk *p_subchunk;
    p_wave_format_chunk = &p_header->format_chunk_2_;
    p_plainwave = &p_wave_format_chunk->plain_wav_;
    p_subchunk = &p_plainwave->subchunk_;
    return &p_subchunk->samples8_[0];
}

variable_types: struct master_riff_chunk { unsigned char ckid_[4]; unsigned int cksize_; union { struct wav_format_chunk_2 { unsigned char waveid_[4]; unsigned char ckid_[4]; unsigned int cksize_; union { unsigned short wFormatTag_; struct plainwaveformat { struct waveformat_tag { unsigned short wFormatTag; unsigned short nChannels; unsigned int nSamplesPerSec; unsigned int nAvgBytesPerSec; unsigned short nBlockAlign; } wavFormat_; struct wav_subchunk { unsigned char subchunkId_[4]; unsigned int subchunk_size_; union { char samples8_[1]; short samples16_[1]; int samples32_[1]; }; } subchunk_; } plain_wav_; struct pcm_waveformat { struct waveformat_tag wf; unsigned short wBitsPerSample; struct wav_subchunk subchunk_; } pcm_wav_; struct extensiblewav { struct waveformat_tag wavFormat_; unsigned short cbSize_; unsigned short wValidBitsPerSample_; } ext_wav_; }; } format_chunk_2_; unsigned char data_u8_[1]; unsigned short data_u16_[1]; unsigned int data_u32_[1]; }; } *

variable_types: struct wav_format_chunk_2 { unsigned char waveid_[4]; unsigned char ckid_[4]; unsigned int cksize_; union { unsigned short wFormatTag_; struct plainwaveformat { struct waveformat_tag { unsigned short wFormatTag; unsigned short nChannels; unsigned int nSamplesPerSec; unsigned int nAvgBytesPerSec; unsigned short nBlockAlign; } wavFormat_; struct wav_subchunk { unsigned char subchunkId_[4]; unsigned int subchunk_size_; union { char samples8_[1]; short samples16_[1]; int samples32_[1]; }; } subchunk_; } plain_wav_; struct pcm_waveformat { struct waveformat_tag wf; unsigned short wBitsPerSample; struct wav_subchunk subchunk_; } pcm_wav_; struct extensiblewav { struct waveformat_tag wavFormat_; unsigned short cbSize_; unsigned short wValidBitsPerSample_; } ext_wav_; }; } *

variable_types: struct plainwaveformat { struct waveformat_tag { unsigned short wFormatTag; unsigned short nChannels; unsigned int nSamplesPerSec; unsigned int nAvgBytesPerSec; unsigned short nBlockAlign; } wavFormat_; struct wav_subchunk { unsigned char subchunkId_[4]; unsigned int subchunk_size_; union { char samples8_[1]; short samples16_[1]; int samples32_[1]; }; } subchunk_; } *

variable_types: struct wav_subchunk { unsigned char subchunkId_[4]; unsigned int subchunk_size_; union { char samples8_[1]; short samples16_[1]; int samples32_[1]; }; } *

return_type: char *

user_defined_types: struct master_riff_chunk { unsigned char ckid_[4]; unsigned int cksize_; union { struct wav_format_chunk_2 format_chunk_2_; unsigned char data_u8_[1]; unsigned short data_u16_[1]; unsigned int data_u32_[1]; }; }

user_defined_types: struct wav_format_chunk_2 { unsigned char waveid_[4]; unsigned char ckid_[4]; unsigned int cksize_; union { unsigned short wFormatTag_; struct plainwaveformat plain_wav_; struct pcm_waveformat pcm_wav_; struct extensiblewav ext_wav_; }; }

user_defined_types: struct plainwaveformat { struct waveformat_tag wavFormat_; struct wav_subchunk subchunk_; }


decompiled_code:
__int64 __fastcall get_samples_buffer_size(__int64 a1)
{
return *(unsigned int *)(a1 + 40);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
return *(unsigned int *)(a1 + 40);
}

original_code:
size_t get_samples_buffer_size(struct master_riff_chunk const * p_header)
{
    wav_format_chunk_2_t const * p_wave_format_chunk;
    plainwaveformat_t const * p_plainwave;
    wav_subchunk_t const * p_subchunk;
    p_wave_format_chunk = &p_header->format_chunk_2_;
    p_plainwave = &p_wave_format_chunk->plain_wav_;
    p_subchunk = &p_plainwave->subchunk_;
    return p_subchunk->subchunk_size_;
}

canonical_original_code:
unsigned long get_samples_buffer_size(struct master_riff_chunk *p_header)
{
    struct wav_format_chunk_2 *p_wave_format_chunk;
    struct plainwaveformat *p_plainwave;
    struct wav_subchunk *p_subchunk;
    p_wave_format_chunk = &p_header->format_chunk_2_;
    p_plainwave = &p_wave_format_chunk->plain_wav_;
    p_subchunk = &p_plainwave->subchunk_;
    return p_subchunk->subchunk_size_;
}

return_type: unsigned long

user_defined_types: struct wav_subchunk { unsigned char subchunkId_[4]; unsigned int subchunk_size_; union { char samples8_[1]; short samples16_[1]; int samples32_[1]; }; }

user_defined_types: struct waveformat_tag { unsigned short wFormatTag; unsigned short nChannels; unsigned int nSamplesPerSec; unsigned int nAvgBytesPerSec; unsigned short nBlockAlign; }

user_defined_types: struct pcm_waveformat { struct waveformat_tag wf; unsigned short wBitsPerSample; struct wav_subchunk subchunk_; }

user_defined_types: struct extensiblewav { struct waveformat_tag wavFormat_; unsigned short cbSize_; unsigned short wValidBitsPerSample_; }


canonical_original_code:
static void sigint_handle(int signal)
{
    g_stop_processing = 1;
}


decompiled_code:
int __fastcall dump_buffer(__int64 a1, __int64 a2, __int64 a3, unsigned int a4)
{
return fprintf(stderr, "%4.4u %s : %u \n", 31LL, "dump_buffer", a4);
}

canonical_decompiled_code:
int __fastcall func4(__int64 a1, __int64 a2, __int64 a3, unsigned int a4)
{
return fprintf(stderr, "%4.4u %s : %u \n", 31LL, "dump_buffer", a4);
}

original_code:
void dump_buffer(const uint8_t * p_buffer, size_t length, struct sockaddr * p_from, socklen_t from_length)
{
    fprintf(stderr, "%4.4u %s : %u \n", 31, __func__, from_length);
}

canonical_original_code:
void dump_buffer(unsigned char *p_buffer, unsigned long length, struct sockaddr *p_from, unsigned int from_length)
{
    fprintf(stderr, "%4.4u %s : %u \n", 31, __func__, from_length);
}

variable_types:
length
unsigned long

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


cut

repo: Tombapic/YoRo

decompiled_code:
__int64 __fastcall cut(__int64 a1, char *a2)
{
char *v2; // rax
char *v3; // rsi
__int64 v4; // rbx
__int64 result; // rax
char delim[2]; // [rsp+Eh] [rbp-1Ah] BYREF

strcpy(delim, " ");
v2 = strtok(a2, delim);
if ( !v2 )
return 0LL;
v3 = v2;
v4 = 1LL;
do
{
strcpy(*(char **)(a1 + 8 * v4 - 8), v3);
v3 = strtok(0LL, delim);
result = (unsigned int)v4++;
}
while ( v3 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, char *a2)
{
char *v2; // rax
char *v3; // rsi
__int64 v4; // rbx
__int64 result; // rax
char delim[2]; // [rsp+Eh] [rbp-1Ah] BYREF

strcpy(delim, " ");
v2 = strtok(a2, delim);
if ( !v2 )
return 0LL;
v3 = v2;
v4 = 1LL;
do
{
strcpy(*(char **)(a1 + 8 * v4 - 8), v3);
v3 = strtok(0LL, delim);
result = (unsigned int)v4++;
}
while ( v3 );
return result;
}

original_code:
int cut(char** tableau,char* source)
{
 char delims[] = " ";
 char *result = ((void *)0);
 int i=0;
 int nombre_mots=0;
 result = strtok( source, delims );
 while( result != ((void *)0) )
 {
  strcpy(tableau[i],result);
  result = strtok( ((void *)0), delims );
  i++;
  nombre_mots= nombre_mots+1;
 }
 return nombre_mots;
}

canonical_original_code:
int cut(char **tableau, char *source)
{
 char delims[] = " ";
 char *result = ((void *)0);
 int i = 0;
 int nombre_mots = 0;
 result = strtok( source, delims );
 while( result != ((void *)0) )
 {
  strcpy(tableau[i],result);
  result = strtok( ((void *)0), delims );
  i++;
  nombre_mots= nombre_mots+1;
 }
 return nombre_mots;
}

variable_types:
tableau
char **

variable_types:
source
char *

variable_types:
delims
char []

variable_types:
result
char *

variable_types: i int

return_type: int


decompiled_code:
__int64 __fastcall search_request(int fd)
{
void **v1; // rbp
void **v2; // rbx
unsigned int v3; // er13
char *v4; // rax
__int64 v5; // rbx
char v7[520]; // [rsp+0h] [rbp-438h] BYREF
unsigned int v8; // [rsp+208h] [rbp-230h] BYREF
int v9; // [rsp+20Ch] [rbp-22Ch] BYREF
int buf[138]; // [rsp+210h] [rbp-228h] BYREF

v8 = 0;
v1 = (void **)malloc(0xF0uLL);
v2 = v1;
do
*v2++ = malloc(0x32uLL);
while ( v2 != v1 + 30 );
strcpy((char *)buf, "search");
v3 = send(fd, buf, 0x200uLL, 0);
if ( v3 == -1 )
{
printf("sock_err (send search)= %d\n", 0xFFFFFFFFLL);
}
else
{
print_header();
puts(aAppuyezSurUneT_1);
getchar();
getchar();
fgets(v7, 512, stdin);
v4 = strchr(v7, 10);
if ( v4 )
*v4 = 0;
v9 = cut((__int64)v1, v7);
v3 = send(fd, &v9, 0x200uLL, 0);
if ( v3 != -1 )
{
if ( v9 <= 0 )
{
LABEL_11:
v3 = recv(fd, &v8, 0x200uLL, 0);
if ( v3 != -1 )
{
print_header();
printf("%d fichier(s) trouve(s), appuyez sur une touche pour les afficher.\n", v8);
getchar();
v3 = v8;
}
}
else
{
v5 = 0LL;
while ( 1 )
{
v3 = send(fd, v1[v5], 0x200uLL, 0);
if ( v3 == -1 )
break;
if ( v9 <= (int)++v5 )
goto LABEL_11;
}
}
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func5(int fd)
{
void **v1; // rbp
void **v2; // rbx
unsigned int v3; // er13
char *v4; // rax
__int64 v5; // rbx
char v7[520]; // [rsp+0h] [rbp-438h] BYREF
unsigned int v8; // [rsp+208h] [rbp-230h] BYREF
int v9; // [rsp+20Ch] [rbp-22Ch] BYREF
int buf[138]; // [rsp+210h] [rbp-228h] BYREF

v8 = 0;
v1 = (void **)malloc(0xF0uLL);
v2 = v1;
do
*v2++ = malloc(0x32uLL);
while ( v2 != v1 + 30 );
strcpy((char *)buf, "search");
v3 = send(fd, buf, 0x200uLL, 0);
if ( v3 == -1 )
{
printf("sock_err (send search)= %d\n", 0xFFFFFFFFLL);
}
else
{
func2();
puts(aAppuyezSurUneT_1);
getchar();
getchar();
fgets(v7, 512, stdin);
v4 = strchr(v7, 10);
if ( v4 )
*v4 = 0;
v9 = func4((__int64)v1, v7);
v3 = send(fd, &v9, 0x200uLL, 0);
if ( v3 != -1 )
{
if ( v9 <= 0 )
{
LABEL_11:
v3 = recv(fd, &v8, 0x200uLL, 0);
if ( v3 != -1 )
{
func2();
printf("%d fichier(s) trouve(s), appuyez sur une touche pour les afficher.\n", v8);
getchar();
v3 = v8;
}
}
else
{
v5 = 0LL;
while ( 1 )
{
v3 = send(fd, v1[v5], 0x200uLL, 0);
if ( v3 == -1 )
break;
if ( v9 <= (int)++v5 )
goto LABEL_11;
}
}
}
}
return v3;
}

original_code:
int search_request(SOCKET sock)
{
 int sock_err=0;
 char buf[512];
 int i;
 int nbr_mots;
 int nbr_files=0;
 char text[512];
 char **tableau= (char**)malloc(30*sizeof(char*));
 for(i=0;i<30;i++){
  tableau[i] = (char*) malloc (50*sizeof(char));
 }
 strcpy(buf, "search");
 sock_err = send(sock, buf, 512, 0);
 if(sock_err == -1) {
  printf("sock_err (send search)= %d\n",sock_err);
  return -1;
 }
 print_header();
 printf("Appuyez sur une touche, donnez la liste de vos mots clés, puis appuyez sur une touche.\n\n");
 getchar();
 getchar();
 fgets(text,sizeof text,stdin);
 char *p = strchr(text, '\n');
 if (p)
 {
  *p = 0;
 }
 nbr_mots = cut(tableau,text);
 sock_err = send(sock,&nbr_mots, 512, 0);
 if(sock_err == -1) return -1;
 for(i=0; i<nbr_mots;i++){
  sock_err = send(sock, tableau[i], 512, 0);
  if(sock_err == -1) return -1;
 }
 sock_err = recv(sock,&nbr_files, 512, 0);
 if(sock_err == -1) return -1;
 else
 {
  print_header();
  printf("%d fichier(s) trouve(s), appuyez sur une touche pour les afficher.\n" , nbr_files);
  getchar();
 }
 return nbr_files;
}

canonical_original_code:
int search_request(int sock)
{
 int sock_err = 0;
 char buf[512];
 int i;
 int nbr_mots;
 int nbr_files = 0;
 char text[512];
 char **tableau = (char**)malloc(30*sizeof(char*));
 for(i=0;i<30;i++){
  tableau[i] = (char *) malloc (50*sizeof(char));
 }
 strcpy(buf, "search");
 sock_err = send(sock, buf, 512, 0);
 if(sock_err == -1) {
  printf("sock_err (send search)= %d\n",sock_err);
  return -1;
 }
 print_header();
 printf("Appuyez sur une touche, donnez la liste de vos mots clés, puis appuyez sur une touche.\n\n");
 getchar();
 getchar();
 fgets(text,sizeof text,stdin);
 char *p = strchr(text, '\n');
 if (p)
 {
  *p = 0;
 }
 nbr_mots = cut(tableau,text);
 sock_err = send(sock,&nbr_mots, 512, 0);
 if(sock_err == -1) return -1;
 for(i=0; i<nbr_mots;i++){
  sock_err = send(sock, tableau[i], 512, 0);
  if(sock_err == -1) return -1;
 }
 sock_err = recv(sock,&nbr_files, 512, 0);
 if(sock_err == -1) return -1;
 else
 {
  print_header();
  printf("%d fichier(s) trouve(s), appuyez sur une touche pour les afficher.\n" , nbr_files);
  getchar();
 }
 return nbr_files;
}

variable_types: sock int

variable_types:
buf
char [512]

variable_types:
text
char [512]

variable_types:
p
char *


decompiled_code:
__int64 __fastcall receive_search_result(int fd, int a2)
{
int v2; // ebx
unsigned int v3; // edx
char v5[536]; // [rsp+0h] [rbp-218h] BYREF

if ( a2 <= 0 )
{
LABEL_5:
puts("\nAppuyez sur une touche pour retourner au menu principal");
getchar();
v3 = 0;
}
else
{
v2 = 0;
while ( 1 )
{
v3 = recv(fd, v5, 0x200uLL, 0);
if ( v3 == -1 )
break;
puts(v5);
if ( a2 == ++v2 )
goto LABEL_5;
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func6(int fd, int a2)
{
int v2; // ebx
unsigned int v3; // edx
char v5[536]; // [rsp+0h] [rbp-218h] BYREF

if ( a2 <= 0 )
{
LABEL_5:
puts("\nAppuyez sur une touche pour retourner au menu principal");
getchar();
v3 = 0;
}
else
{
v2 = 0;
while ( 1 )
{
v3 = recv(fd, v5, 0x200uLL, 0);
if ( v3 == -1 )
break;
puts(v5);
if ( a2 == ++v2 )
goto LABEL_5;
}
}
return v3;
}

original_code:
int receive_search_result(SOCKET sock,int nbr_files)
{
 int sock_err =0;
 int i;
 char buf[512];
 for(i=0; i<nbr_files;i++)
 {
   sock_err = recv(sock, buf, 512, 0);
  if(sock_err == -1) return -1;
  else
  {
   printf("%s\n" , buf);
  }
 }
 printf("\nAppuyez sur une touche pour retourner au menu principal\n");
 getchar();
 return 0;
}

canonical_original_code:
int receive_search_result(int sock, int nbr_files)
{
 int sock_err = 0;
 int i;
 char buf[512];
 for(i=0; i<nbr_files;i++)
 {
   sock_err = recv(sock, buf, 512, 0);
  if(sock_err == -1) return -1;
  else
  {
   printf("%s\n" , buf);
  }
 }
 printf("\nAppuyez sur une touche pour retourner au menu principal\n");
 getchar();
 return 0;
}


decompiled_code:
__int64 __fastcall handle_user(int fd)
{
int v2; // eax
int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

v3[0] = 0;
print_header();
do
{
print_header();
puts("1. Rechercher un fichier");
puts("2. Telecharger un fichier");
puts("3. Ajouter une description");
puts("4. Se deconnecter");
_isoc99_scanf("%1d", v3);
switch ( v3[0] )
{
case 1:
v2 = search_request(fd);
receive_search_result(fd, v2);
break;
case 2:
download_file(fd);
break;
case 3:
add_description((unsigned int)fd);
break;
}
}
while ( v3[0] != 4 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(int fd)
{
int v2; // eax
int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

v3[0] = 0;
func2();
do
{
func2();
puts("1. Rechercher un fichier");
puts("2. Telecharger un fichier");
puts("3. Ajouter une description");
puts("4. Se deconnecter");
_isoc99_scanf("%1d", v3);
switch ( v3[0] )
{
case 1:
v2 = func5(fd);
func6(fd, v2);
break;
case 2:
func3(fd);
break;
case 3:
func7((unsigned int)fd);
break;
}
}
while ( v3[0] != 4 );
return 0LL;
}

original_code:
int handle_user(SOCKET sock, SOCKADDR_IN sin)
{
 int user_choice = 0;
 int nbr_files =0;
 print_header();
 while(user_choice != 4)
 {
   print_header();
   printf("1. Rechercher un fichier\n");
   printf("2. Telecharger un fichier\n");
   printf("3. Ajouter une description\n");
   printf("4. Se deconnecter\n");
   scanf("%1d", &user_choice);
   if(user_choice == 1)
   {
    nbr_files = search_request(sock);
    receive_search_result(sock,nbr_files);
   }
   else if(user_choice == 2)
    download_file(sock);
   else if(user_choice == 3)
    add_description(sock);
 }
 return 0;
}

canonical_original_code:
int handle_user(int sock, struct sockaddr_in sin)
{
 int user_choice = 0;
 int nbr_files = 0;
 print_header();
 while(user_choice != 4)
 {
   print_header();
   printf("1. Rechercher un fichier\n");
   printf("2. Telecharger un fichier\n");
   printf("3. Ajouter une description\n");
   printf("4. Se deconnecter\n");
   scanf("%1d", &user_choice);
   if(user_choice == 1)
   {
    nbr_files = search_request(sock);
    receive_search_result(sock,nbr_files);
   }
   else if(user_choice == 2)
    download_file(sock);
   else if(user_choice == 3)
    add_description(sock);
 }
 return 0;
}

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

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


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // er12
unsigned int v6; // ebp
unsigned __int16 v7; // bx
char *v8; // rax
__pid_t v9; // eax
__pid_t v10; // eax
socklen_t addr_len; // [rsp+Ch] [rbp-4Ch] BYREF
struct sockaddr v12; // [rsp+10h] [rbp-48h] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-38h] BYREF
int stat_loc[7]; // [rsp+3Ch] [rbp-1Ch] BYREF

system("clear");
printf("--------------------------------------------------------------------------------");
puts(" SERVEUR CENTRAL");
puts("--------------------------------------------------------------------------------");
addr_len = 16;
v3 = socket(2, 1, 0);
if ( v3 == -1 )
{
puts("Erreur : echec de la creation de la socket.");
}
else
{
v4 = v3;
*(_DWORD *)&addr.sa_data[2] = _bswap_32(0);
addr.sa_family = 2;
*(_WORD *)addr.sa_data = _bswap_16(2013);
if ( bind(v4, &addr, 0x10u) == -1 )
{
puts("Erreur : echec du parametrage de la socket.");
}
else if ( listen(v4, 5) == -1 )
{
puts("Erreur : echec de l'ecoute de la socket.");
}
else
{
while ( 1 )
{
v6 = accept(v4, &v12, &addr_len);
v7 = _bswap_16(*(__int16 *)v12.sa_data);
v8 = inet_ntoa(*(struct in_addr *)&v12.sa_data[2]);
printf("Connexion de %s sur la socket %d depuis le port %d.\n\n", v8, v6, v7);
if ( v6 == -1 )
break;
v9 = fork();
if ( v9 != -1 )
{
if ( !v9 )
{
handle_client(v6, *(__int64 *)&v12.sa_family);
close(v6);
v10 = getpid();
kill(v10, 15);
}
waitpid(-1, stat_loc, 1);
}
}
puts("Erreur : echec de la connexion avec le client.");
}
}
return 1;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // er12
unsigned int v6; // ebp
unsigned __int16 v7; // bx
char *v8; // rax
__pid_t v9; // eax
__pid_t v10; // eax
socklen_t addr_len; // [rsp+Ch] [rbp-4Ch] BYREF
struct sockaddr v12; // [rsp+10h] [rbp-48h] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-38h] BYREF
int stat_loc[7]; // [rsp+3Ch] [rbp-1Ch] BYREF

system("clear");
printf("--------------------------------------------------------------------------------");
puts(" SERVEUR CENTRAL");
puts("--------------------------------------------------------------------------------");
addr_len = 16;
v3 = socket(2, 1, 0);
if ( v3 == -1 )
{
puts("Erreur : echec de la creation de la socket.");
}
else
{
v4 = v3;
*(_DWORD *)&addr.sa_data[2] = func0(0);
addr.sa_family = 2;
*(_WORD *)addr.sa_data = func1(2013);
if ( bind(v4, &addr, 0x10u) == -1 )
{
puts("Erreur : echec du parametrage de la socket.");
}
else if ( listen(v4, 5) == -1 )
{
puts("Erreur : echec de l'ecoute de la socket.");
}
else
{
while ( 1 )
{
v6 = accept(v4, &v12, &addr_len);
v7 = func1(*(__int16 *)v12.sa_data);
v8 = inet_ntoa(*(struct in_addr *)&v12.sa_data[2]);
printf("Connexion de %s sur la socket %d depuis le port %d.\n\n", v8, v6, v7);
if ( v6 == -1 )
break;
v9 = fork();
if ( v9 != -1 )
{
if ( !v9 )
{
func9(v6, *(__int64 *)&v12.sa_family);
close(v6);
v10 = getpid();
kill(v10, 15);
}
waitpid(-1, stat_loc, 1);
}
}
puts("Erreur : echec de la connexion avec le client.");
}
}
return 1;
}

original_code:
int main(int argc, char *argv[])
{
 system("clear");
 printf("--------------------------------------------------------------------------------");
 printf("                                SERVEUR CENTRAL\n");
 printf("--------------------------------------------------------------------------------\n");
 int status;
 int sock_err;
 SOCKET sock;
 SOCKADDR_IN sin;
 socklen_t ssize = sizeof(sin);
 SOCKET csock;
 SOCKADDR_IN csin;
 socklen_t csize = sizeof(csin);
 sock = socket(2, SOCK_STREAM, 0);
 if(sock == -1)
 {
  printf("Erreur : echec de la creation de la socket.\n");
  return 1;
 }
 sin.sin_addr.s_addr = htonl(((in_addr_t) 0x00000000));
 sin.sin_family = 2;
 sin.sin_port = htons(2013);
 sock_err = bind(sock, (SOCKADDR*)&sin, ssize);
 if(sock_err == -1)
 {
  printf("Erreur : echec du parametrage de la socket.\n");
  return 1;
 }
 sock_err = listen(sock, 5);
 if(sock_err == -1)
 {
  printf("Erreur : echec de l'ecoute de la socket.\n");
  return 1;
 }
 while(1)
 {
  csock = accept(sock, (SOCKADDR*)&csin, &csize);
  printf("Connexion de %s sur la socket %d depuis le port %d.\n\n", inet_ntoa(csin.sin_addr),
    csock, htons(csin.sin_port));
  if(csock == -1)
  {
   printf("Erreur : echec de la connexion avec le client.\n");
   return 1;
  }
  switch(fork())
  {
   case -1 :
   break;
   case 0 :
    handle_client(csock, csin);
    close(csock);
    kill(getpid(), 15);
   default :
    waitpid(-1, &status, 1);
  }
 }
 close(sock);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 system("clear");
 printf("--------------------------------------------------------------------------------");
 printf("                                SERVEUR CENTRAL\n");
 printf("--------------------------------------------------------------------------------\n");
 int status;
 int sock_err;
 int sock;
 struct sockaddr_in sin;
 unsigned int ssize = sizeof(sin);
 int csock;
 struct sockaddr_in csin;
 unsigned int csize = sizeof(csin);
 sock = socket(2, SOCK_STREAM, 0);
 if(sock == -1)
 {
  printf("Erreur : echec de la creation de la socket.\n");
  return 1;
 }
 sin.sin_addr.s_addr = htonl(((unsigned int) 0x00000000));
 sin.sin_family = 2;
 sin.sin_port = htons(2013);
 sock_err = bind(sock, (struct sockaddr *)&sin, ssize);
 if(sock_err == -1)
 {
  printf("Erreur : echec du parametrage de la socket.\n");
  return 1;
 }
 sock_err = listen(sock, 5);
 if(sock_err == -1)
 {
  printf("Erreur : echec de l'ecoute de la socket.\n");
  return 1;
 }
 while(1)
 {
  csock = accept(sock, (struct sockaddr *)&csin, &csize);
  printf("Connexion de %s sur la socket %d depuis le port %d.\n\n", inet_ntoa(csin.sin_addr),
    csock, htons(csin.sin_port));
  if(csock == -1)
  {
   printf("Erreur : echec de la connexion avec le client.\n");
   return 1;
  }
  switch(fork())
  {
   case -1 :
   break;
   case 0 :
    handle_client(csock, csin);
    close(csock);
    kill(getpid(), 15);
   default :
    waitpid(-1, &status, 1);
  }
 }
 close(sock);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: status int

variable_types:
ssize
unsigned int

variable_types: csock int

variable_types:
csize
unsigned int


decompiled_code:
__int64 __fastcall create_account(int fd)
{
__int64 result; // rax
char *v2; // rax
char *v3; // rax
bool v4; // zf
char *v5; // rax
char *v6; // rax
char key[3]; // [rsp+Dh] [rbp-21Bh] BYREF
int buf[134]; // [rsp+10h] [rbp-218h] BYREF

strcpy(key, "YR");
print_header();
buf[0] = 6579297;
result = send(fd, buf, 0x200uLL, 0);
if ( (_DWORD)result != -1 )
{
printf("Login ? ");
_isoc99_scanf("%14s", buf);
result = send(fd, buf, 0x200uLL, 0);
if ( (_DWORD)result != -1 )
{
v2 = getpass("Password ? ");
strcpy((char *)buf, v2);
v3 = crypt(key, (const char *)buf);
strcpy((char *)buf, v3);
result = send(fd, buf, 0x200uLL, 0);
if ( (_DWORD)result != -1 )
{
for ( result = recv(fd, buf, 0x200uLL, 0); (_DWORD)result != -1; result = recv(fd, buf, 0x200uLL, 0) )
{
v4 = strcmp((const char *)buf, "addok") == 0;
result = !v4;
if ( v4 )
break;
puts("Cet identifiant existe deja dans la base, veuillez reessayer.");
printf("Login ? ");
_isoc99_scanf("%14s", buf);
result = send(fd, buf, 0x200uLL, 0);
if ( (_DWORD)result == -1 )
break;
v5 = getpass("Password ? ");
strcpy((char *)buf, v5);
v6 = crypt(key, (const char *)buf);
strcpy((char *)buf, v6);
result = send(fd, buf, 0x200uLL, 0);
if ( (_DWORD)result == -1 )
break;
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int fd)
{
__int64 result; // rax
char *v2; // rax
char *v3; // rax
bool v4; // zf
char *v5; // rax
char *v6; // rax
char key[3]; // [rsp+Dh] [rbp-21Bh] BYREF
int buf[134]; // [rsp+10h] [rbp-218h] BYREF

strcpy(key, "YR");
print_header();
buf[0] = 6579297;
result = send(fd, buf, 0x200uLL, 0);
if ( (_DWORD)result != -1 )
{
printf("Login ? ");
_isoc99_scanf("%14s", buf);
result = send(fd, buf, 0x200uLL, 0);
if ( (_DWORD)result != -1 )
{
v2 = getpass("Password ? ");
strcpy((char *)buf, v2);
v3 = crypt(key, (const char *)buf);
strcpy((char *)buf, v3);
result = send(fd, buf, 0x200uLL, 0);
if ( (_DWORD)result != -1 )
{
for ( result = recv(fd, buf, 0x200uLL, 0); (_DWORD)result != -1; result = recv(fd, buf, 0x200uLL, 0) )
{
v4 = strcmp((const char *)buf, "addok") == 0;
result = !v4;
if ( v4 )
break;
puts("Cet identifiant existe deja dans la base, veuillez reessayer.");
printf("Login ? ");
_isoc99_scanf("%14s", buf);
result = send(fd, buf, 0x200uLL, 0);
if ( (_DWORD)result == -1 )
break;
v5 = getpass("Password ? ");
strcpy((char *)buf, v5);
v6 = crypt(key, (const char *)buf);
strcpy((char *)buf, v6);
result = send(fd, buf, 0x200uLL, 0);
if ( (_DWORD)result == -1 )
break;
}
}
}
}
return result;
}

original_code:
int create_account(SOCKET sock)
{
 int sock_err;
 char buf[512];
 char salt[] = "YR";
 char* bufcrypt;
 print_header();
 strcpy(buf, "add");
 sock_err = send(sock, buf, 512, 0);
 if(sock_err == -1) return -1;
 printf("Login ? ");
 scanf("%14s", buf);
 sock_err = send(sock, buf, 512, 0);
 if(sock_err == -1) return -1;
 strcpy(buf, getpass("Password ? "));
 bufcrypt= crypt(salt,buf);
 strcpy(buf,bufcrypt);
 sock_err = send(sock, buf, 512, 0);
 if(sock_err == -1) return -1;
 sock_err = recv(sock, buf, 512, 0);
 if(sock_err == -1) return -1;
 while(strcmp(buf, "addok") != 0)
 {
  printf("Cet identifiant existe deja dans la base, veuillez reessayer.\n");
  printf("Login ? ");
  scanf("%14s", buf);
  sock_err = send(sock, buf, 512, 0);
  if(sock_err == -1) return -1;
  strcpy(buf, getpass("Password ? "));
  bufcrypt= crypt(salt,buf);
  strcpy(buf,bufcrypt);
  sock_err = send(sock, buf, 512, 0);
  if(sock_err == -1) return -1;
  sock_err = recv(sock, buf, 512, 0);
  if(sock_err == -1) return -1;
 }
 return 0;
}

canonical_original_code:
int create_account(int sock)
{
 int sock_err;
 char buf[512];
 char salt[] = "YR";
 char *bufcrypt;
 print_header();
 strcpy(buf, "add");
 sock_err = send(sock, buf, 512, 0);
 if(sock_err == -1) return -1;
 printf("Login ? ");
 scanf("%14s", buf);
 sock_err = send(sock, buf, 512, 0);
 if(sock_err == -1) return -1;
 strcpy(buf, getpass("Password ? "));
 bufcrypt= crypt(salt,buf);
 strcpy(buf,bufcrypt);
 sock_err = send(sock, buf, 512, 0);
 if(sock_err == -1) return -1;
 sock_err = recv(sock, buf, 512, 0);
 if(sock_err == -1) return -1;
 while(strcmp(buf, "addok") != 0)
 {
  printf("Cet identifiant existe deja dans la base, veuillez reessayer.\n");
  printf("Login ? ");
  scanf("%14s", buf);
  sock_err = send(sock, buf, 512, 0);
  if(sock_err == -1) return -1;
  strcpy(buf, getpass("Password ? "));
  bufcrypt= crypt(salt,buf);
  strcpy(buf,bufcrypt);
  sock_err = send(sock, buf, 512, 0);
  if(sock_err == -1) return -1;
  sock_err = recv(sock, buf, 512, 0);
  if(sock_err == -1) return -1;
 }
 return 0;
}

variable_types:
salt
char []

variable_types:
bufcrypt
char *


authenticate

decompiled_code:
__int64 __fastcall authenticate(int fd)
{
__int64 v2; // rdx
char *v3; // rax
char *v4; // rax
bool v5; // cf
bool v6; // zf
char *v7; // rax
char *v8; // rax
unsigned int v9; // eax
__int64 *v10; // rsi
const char *v11; // rdi
__int64 v12; // rcx
char i; // al
unsigned int v14; // eax
unsigned int v15; // eax
char key[3]; // [rsp+Dh] [rbp-22Bh] BYREF
__int64 buf[65]; // [rsp+10h] [rbp-228h] BYREF
char v19[25]; // [rsp+21Fh] [rbp-19h] BYREF

strcpy(key, "YR");
((void (*)(void))print_header)();
strcpy((char *)buf, "auth");
LODWORD(v2) = send(fd, buf, 0x200uLL, 0);
if ( (_DWORD)v2 != -1 )
{
printf("Login ? ");
_isoc99_scanf("%14s", buf);
LODWORD(v2) = send(fd, buf, 0x200uLL, 0);
if ( (_DWORD)v2 != -1 )
{
v3 = getpass("Password ? ");
strcpy((char *)buf, v3);
v4 = crypt(key, (const char *)buf);
strcpy((char *)buf, v4);
LODWORD(v2) = send(fd, buf, 0x200uLL, 0);
if ( (_DWORD)v2 != -1 )
{
recv(fd, buf, 0x200uLL, 0);
while ( 1 )
{
v10 = buf;
v11 = "authok";
v12 = 7LL;
do
{
if ( !v12 )
break;
v5 = *(_BYTE *)v10 < *v11;
v6 = *(_BYTE *)v10 == *v11;
v10 = (__int64 *)((char *)v10 + 1);
++v11;
--v12;
}
while ( v6 );
if ( (!v5 && !v6) == v5 )
break;
print_header(v11, v10, v2);
printf("Identifiant et/ou mot de passe incorrect. Reessayer ? (o/n) ");
_isoc99_scanf("%c", v19);
for ( i = v19[0]; (unsigned __int8)(v19[0] - 110) > 1u; i = v19[0] )
_isoc99_scanf("%c", v19);
if ( i != 111 )
{
strcpy((char *)buf, "authabort");
v14 = send(fd, buf, 0x200uLL, 0);
LODWORD(v2) = v14;
if ( v14 != -1 )
{
print_header((unsigned int)fd, buf, v14);
puts("Authentification annulee.");
puts("Appuyez sur une touche pour continuer.");
getchar();
getchar();
LODWORD(v2) = 1;
}
return (unsigned int)v2;
}
strcpy((char *)buf, "authretry");
send(fd, buf, 0x200uLL, 0);
printf("Login ? ");
_isoc99_scanf("%14s", buf);
LODWORD(v2) = send(fd, buf, 0x200uLL, 0);
if ( (_DWORD)v2 != -1 )
{
v7 = getpass("Password ? ");
strcpy((char *)buf, v7);
v8 = crypt(key, (const char *)buf);
strcpy((char *)buf, v8);
LODWORD(v2) = send(fd, buf, 0x200uLL, 0);
if ( (_DWORD)v2 != -1 )
{
v9 = recv(fd, buf, 0x200uLL, 0);
v2 = v9;
v5 = v9 != -1;
v6 = v9 == -1;
if ( v9 != -1 )
continue;
}
}
return (unsigned int)v2;
}
buf[0] = 0x6B636168747561LL;
v15 = send(fd, buf, 0x200uLL, 0);
LODWORD(v2) = v15;
if ( v15 != -1 )
{
print_header((unsigned int)fd, buf, v15);
puts("Vous etes maintenant authentifie.");
puts("Appuyez sur une touche pour continuer.");
getchar();
getchar();
LODWORD(v2) = 0;
}
}
}
}
return (unsigned int)v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(int fd)
{
__int64 v2; // rdx
char *v3; // rax
char *v4; // rax
bool v5; // cf
bool v6; // zf
char *v7; // rax
char *v8; // rax
unsigned int v9; // eax
__int64 *v10; // rsi
const char *v11; // rdi
__int64 v12; // rcx
char i; // al
unsigned int v14; // eax
unsigned int v15; // eax
char key[3]; // [rsp+Dh] [rbp-22Bh] BYREF
__int64 buf[65]; // [rsp+10h] [rbp-228h] BYREF
char v19[25]; // [rsp+21Fh] [rbp-19h] BYREF

strcpy(key, "YR");
((void (*)(void))print_header)();
strcpy((char *)buf, "auth");
LODWORD(v2) = send(fd, buf, 0x200uLL, 0);
if ( (_DWORD)v2 != -1 )
{
printf("Login ? ");
_isoc99_scanf("%14s", buf);
LODWORD(v2) = send(fd, buf, 0x200uLL, 0);
if ( (_DWORD)v2 != -1 )
{
v3 = getpass("Password ? ");
strcpy((char *)buf, v3);
v4 = crypt(key, (const char *)buf);
strcpy((char *)buf, v4);
LODWORD(v2) = send(fd, buf, 0x200uLL, 0);
if ( (_DWORD)v2 != -1 )
{
recv(fd, buf, 0x200uLL, 0);
while ( 1 )
{
v10 = buf;
v11 = "authok";
v12 = 7LL;
do
{
if ( !v12 )
break;
v5 = *(_BYTE *)v10 < *v11;
v6 = *(_BYTE *)v10 == *v11;
v10 = (__int64 *)((char *)v10 + 1);
++v11;
--v12;
}
while ( v6 );
if ( (!v5 && !v6) == v5 )
break;
print_header(v11, v10, v2);
printf("Identifiant et/ou mot de passe incorrect. Reessayer ? (o/n) ");
_isoc99_scanf("%c", v19);
for ( i = v19[0]; (unsigned __int8)(v19[0] - 110) > 1u; i = v19[0] )
_isoc99_scanf("%c", v19);
if ( i != 111 )
{
strcpy((char *)buf, "authabort");
v14 = send(fd, buf, 0x200uLL, 0);
LODWORD(v2) = v14;
if ( v14 != -1 )
{
print_header((unsigned int)fd, buf, v14);
puts("Authentification annulee.");
puts("Appuyez sur une touche pour continuer.");
getchar();
getchar();
LODWORD(v2) = 1;
}
return (unsigned int)v2;
}
strcpy((char *)buf, "authretry");
send(fd, buf, 0x200uLL, 0);
printf("Login ? ");
_isoc99_scanf("%14s", buf);
LODWORD(v2) = send(fd, buf, 0x200uLL, 0);
if ( (_DWORD)v2 != -1 )
{
v7 = getpass("Password ? ");
strcpy((char *)buf, v7);
v8 = crypt(key, (const char *)buf);
strcpy((char *)buf, v8);
LODWORD(v2) = send(fd, buf, 0x200uLL, 0);
if ( (_DWORD)v2 != -1 )
{
v9 = recv(fd, buf, 0x200uLL, 0);
v2 = v9;
v5 = v9 != -1;
v6 = v9 == -1;
if ( v9 != -1 )
continue;
}
}
return (unsigned int)v2;
}
buf[0] = 0x6B636168747561LL;
v15 = send(fd, buf, 0x200uLL, 0);
LODWORD(v2) = v15;
if ( v15 != -1 )
{
print_header((unsigned int)fd, buf, v15);
puts("Vous etes maintenant authentifie.");
puts("Appuyez sur une touche pour continuer.");
getchar();
getchar();
LODWORD(v2) = 0;
}
}
}
}
return (unsigned int)v2;
}

original_code:
int authenticate(SOCKET sock)
{
 int sock_err;
 char user_choice;
 char buf[512];
 char salt[] = "YR";
 char* bufcrypt;
 print_header();
 strcpy(buf, "auth");
 sock_err = send(sock, buf, 512, 0);
 if(sock_err == -1) return -1;
 printf("Login ? ");
 scanf("%14s", buf);
 sock_err = send(sock, buf, 512, 0);
 if(sock_err == -1) return -1;
 strcpy(buf, getpass("Password ? "));
 bufcrypt= crypt(salt,buf);
 strcpy(buf,bufcrypt);
 sock_err = send(sock, buf, 512, 0);
 if(sock_err == -1) return -1;
 sock_err = recv(sock, buf, 512, 0);
 while(strcmp(buf, "authok") != 0)
 {
  print_header();
  printf("Identifiant et/ou mot de passe incorrect. Reessayer ? (o/n) ");
  scanf("%c", &user_choice);
  while((user_choice!='o') && (user_choice!='n')) scanf("%c", &user_choice);
  if(user_choice == 'o')
  {
   strcpy(buf, "authretry");
   sock_err = send(sock, buf, 512, 0);
   printf("Login ? ");
   scanf("%14s", buf);
   sock_err = send(sock, buf, 512, 0);
   if(sock_err == -1) return -1;
   strcpy(buf, getpass("Password ? "));
   bufcrypt= crypt(salt,buf);
   strcpy(buf,bufcrypt);
   sock_err = send(sock, buf, 512, 0);
   if(sock_err == -1) return -1;
   sock_err = recv(sock, buf, 512, 0);
   if(sock_err == -1) return -1;
  }
  else
  {
   strcpy(buf, "authabort");
   sock_err = send(sock, buf, 512, 0);
   if(sock_err == -1) return -1;
   print_header();
   printf("Authentification annulee.\n");
   printf("Appuyez sur une touche pour continuer.\n");
   getchar();
   getchar();
   return 1;
  }
 }
 strcpy(buf, "authack");
 sock_err = send(sock, buf, 512, 0);
 if(sock_err == -1) return -1;
 print_header();
 printf("Vous etes maintenant authentifie.\n");
 printf("Appuyez sur une touche pour continuer.\n");
 getchar();
 getchar();
 return 0;
}

canonical_original_code:
int authenticate(int sock)
{
 int sock_err;
 char user_choice;
 char buf[512];
 char salt[] = "YR";
 char *bufcrypt;
 print_header();
 strcpy(buf, "auth");
 sock_err = send(sock, buf, 512, 0);
 if(sock_err == -1) return -1;
 printf("Login ? ");
 scanf("%14s", buf);
 sock_err = send(sock, buf, 512, 0);
 if(sock_err == -1) return -1;
 strcpy(buf, getpass("Password ? "));
 bufcrypt= crypt(salt,buf);
 strcpy(buf,bufcrypt);
 sock_err = send(sock, buf, 512, 0);
 if(sock_err == -1) return -1;
 sock_err = recv(sock, buf, 512, 0);
 while(strcmp(buf, "authok") != 0)
 {
  print_header();
  printf("Identifiant et/ou mot de passe incorrect. Reessayer ? (o/n) ");
  scanf("%c", &user_choice);
  while((user_choice!='o') && (user_choice!='n')) scanf("%c", &user_choice);
  if(user_choice == 'o')
  {
   strcpy(buf, "authretry");
   sock_err = send(sock, buf, 512, 0);
   printf("Login ? ");
   scanf("%14s", buf);
   sock_err = send(sock, buf, 512, 0);
   if(sock_err == -1) return -1;
   strcpy(buf, getpass("Password ? "));
   bufcrypt= crypt(salt,buf);
   strcpy(buf,bufcrypt);
   sock_err = send(sock, buf, 512, 0);
   if(sock_err == -1) return -1;
   sock_err = recv(sock, buf, 512, 0);
   if(sock_err == -1) return -1;
  }
  else
  {
   strcpy(buf, "authabort");
   sock_err = send(sock, buf, 512, 0);
   if(sock_err == -1) return -1;
   print_header();
   printf("Authentification annulee.\n");
   printf("Appuyez sur une touche pour continuer.\n");
   getchar();
   getchar();
   return 1;
  }
 }
 strcpy(buf, "authack");
 sock_err = send(sock, buf, 512, 0);
 if(sock_err == -1) return -1;
 print_header();
 printf("Vous etes maintenant authentifie.\n");
 printf("Appuyez sur une touche pour continuer.\n");
 getchar();
 getchar();
 return 0;
}


isDigit

decompiled_code:
_BOOL8 __fastcall isDigit(char a1)
{
return (unsigned __int8)(a1 - 48) <= 9u;
}

canonical_decompiled_code:
_BOOL8 __fastcall func9(char a1)
{
return (unsigned __int8)(a1 - 48) <= 9u;
}

original_code:
int isDigit(const char c) {
 return '0' <= c && c <= '9';
}

canonical_original_code:
int isDigit(char c) {
 return '0' <= c && c <= '9';
}

variable_types: c char


calc

original_code:
void calc(const char* input, char* output) {
 char buffer[8192];
 int n, i, j, k, m, mul;
 int args[2];
 n = strlen(input);
 if (debug)
  fprintf(stderr, "Analyzing: %s[length=%d]\n", input, n);
 for (i = 0; i < n - 1; ++i)
  if (!isDigit(input[i]) && input[i] != ' ' && input[i] != ':' &&
   !(input[i] == '-' && i + 1 < n - 1 && input[i + 1] != ' '))
   break;
 if (i == n - 1) {
  if (debug)
   fprintf(stderr, "No operators found! i = %d, n - 1 = %d\n", i, n - 1);
  strcpy(output, input);
  return;
 }
 m = i;
 if (debug)
  fprintf(stderr, "First operator (%c) at: %d\n", input[m], m);
 for (j = 0; j < n && input[j] != ':'; ++j)
  output[j] = input[j];
 for (k = 0; k < 2; ++k, ++j)
  output[j] = input[j];
 for (k = 1; k >= 0; --k) {
  args[k] = 0;
  for (; i >= 0 && !isDigit(input[i]); --i);
  for (mul = 1; i >= 0 && isDigit(input[i]); --i) {
   args[k] += (input[i] - '0') * mul;
   mul *= 10;
  }
  if (input[i] == '-') {
   args[k] *= -1;
   --i;
  }
 }
 ++i;
 switch (input[m]) {
  case '+':
   k = args[0] + args[1];
   break;
  case '-':
   k = args[0] - args[1];
   break;
  case '*':
   k = args[0] * args[1];
   break;
  case '/':
   k = args[0] / args[1];
   break;
 }
 if (debug)
  fprintf(stderr, "i = %d j = %d k = %d m = %d, operands: %d %d\n", i, j, k, m, args[0], args[1]);
 sprintf(buffer, "%d", k);
 k = strlen(buffer);
 if (debug) {
  fprintf(stderr, "result: %s\n", buffer);
  fprintf(stderr, "%d %d %d\n", i, j, m);
 }
 memcpy(output + j, input + j, i - j);
 memcpy(output + i, buffer, k);
 memcpy(output + i + k, input + m + 1, strlen(input) - m);
 if (debug)
  fprintf(stderr, "output: %s\n", output);
}

canonical_original_code:
void calc(char *input, char *output) {
 char buffer[8192];
 int n; int i; int j; int k; int m; int mul;
 int args[2];
 n = strlen(input);
 if (debug)
  fprintf(stderr, "Analyzing: %s[length=%d]\n", input, n);
 for (i = 0; i < n - 1; ++i)
  if (!isDigit(input[i]) && input[i] != ' ' && input[i] != ':' &&
   !(input[i] == '-' && i + 1 < n - 1 && input[i + 1] != ' '))
   break;
 if (i == n - 1) {
  if (debug)
   fprintf(stderr, "No operators found! i = %d, n - 1 = %d\n", i, n - 1);
  strcpy(output, input);
  return;
 }
 m = i;
 if (debug)
  fprintf(stderr, "First operator (%c) at: %d\n", input[m], m);
 for (j = 0; j < n && input[j] != ':'; ++j)
  output[j] = input[j];
 for (k = 0; k < 2; ++k, ++j)
  output[j] = input[j];
 for (k = 1; k >= 0; --k) {
  args[k] = 0;
  for (; i >= 0 && !isDigit(input[i]); --i);
  for (mul = 1; i >= 0 && isDigit(input[i]); --i) {
   args[k] += (input[i] - '0') * mul;
   mul *= 10;
  }
  if (input[i] == '-') {
   args[k] *= -1;
   --i;
  }
 }
 ++i;
 switch (input[m]) {
  case '+':
   k = args[0] + args[1];
   break;
  case '-':
   k = args[0] - args[1];
   break;
  case '*':
   k = args[0] * args[1];
   break;
  case '/':
   k = args[0] / args[1];
   break;
 }
 if (debug)
  fprintf(stderr, "i = %d j = %d k = %d m = %d, operands: %d %d\n", i, j, k, m, args[0], args[1]);
 sprintf(buffer, "%d", k);
 k = strlen(buffer);
 if (debug) {
  fprintf(stderr, "result: %s\n", buffer);
  fprintf(stderr, "%d %d %d\n", i, j, m);
 }
 memcpy(output + j, input + j, i - j);
 memcpy(output + i, buffer, k);
 memcpy(output + i + k, input + m + 1, strlen(input) - m);
 if (debug)
  fprintf(stderr, "output: %s\n", output);
}

variable_types:
input
char *

variable_types:
output
char *

variable_types:
buffer
char [8192]

variable_types: n int

variable_types: j int

variable_types: k int

variable_types: m int

variable_types: mul int

variable_types:
args
int [2]


syserr

decompiled_code:
void __noreturn syserr(char *format, ...)
{
int *v1; // rbx
char *v2; // rax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
fwrite("ERROR: ", 1uLL, 7uLL, stderr);
vfprintf(stderr, format, arg);
v1 = __errno_location();
v2 = strerror(*v1);
fprintf(stderr, " (%d; %s)\n", (unsigned int)*v1, v2);
exit(1);
}

canonical_decompiled_code:
void __noreturn func11(char *format, ...)
{
int *v1; // rbx
char *v2; // rax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
fwrite("ERROR: ", 1uLL, 7uLL, stderr);
vfprintf(stderr, format, arg);
v1 = __errno_location();
v2 = strerror(*v1);
fprintf(stderr, " (%d; %s)\n", (unsigned int)*v1, v2);
exit(1);
}

original_code:
void syserr(const char *fmt, ...) {
 va_list fmt_args;
 fprintf(stderr, "ERROR: ");
 __builtin_va_start(fmt_args,fmt);
 vfprintf(stderr, fmt, fmt_args);
 __builtin_va_end(fmt_args);
 fprintf(stderr," (%d; %s)\n", (*__errno_location ()), strerror((*__errno_location ())));
 exit(1);
}

canonical_original_code:
void syserr(char *fmt, ...) {
 __builtin_va_list fmt_args;
 fprintf(stderr, "ERROR: ");
 __builtin_va_start(fmt_args,fmt);
 vfprintf(stderr, fmt, fmt_args);
 __builtin_va_end(fmt_args);
 fprintf(stderr," (%d; %s)\n", (*__errno_location ()), strerror((*__errno_location ())));
 exit(1);
}

variable_types:
fmt
char *


fatal

decompiled_code:
void __noreturn fatal(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
fwrite("ERROR: ", 1uLL, 7uLL, stderr);
vfprintf(stderr, format, arg);
fputc(10, stderr);
exit(1);
}

canonical_decompiled_code:
void __noreturn func12(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
fwrite("ERROR: ", 1uLL, 7uLL, stderr);
vfprintf(stderr, format, arg);
fputc(10, stderr);
exit(1);
}

original_code:
void fatal(const char *fmt, ...) {
 va_list fmt_args;
 fprintf(stderr, "ERROR: ");
 __builtin_va_start(fmt_args,fmt);
 vfprintf(stderr, fmt, fmt_args);
 __builtin_va_end(fmt_args);
 fprintf(stderr,"\n");
 exit(1);
}

canonical_original_code:
void fatal(char *fmt, ...) {
 __builtin_va_list fmt_args;
 fprintf(stderr, "ERROR: ");
 __builtin_va_start(fmt_args,fmt);
 vfprintf(stderr, fmt, fmt_args);
 __builtin_va_end(fmt_args);
 fprintf(stderr,"\n");
 exit(1);
}


main

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

while ( 1 )
{
readInput((__int64)&input);
if ( input == 35 )
break;
calc(&input, output);
v3 = strlen(output);
if ( write(1, output, v3) == -1 )
{
v4 = getpid();
syserr("Error while passing the results through pipe [executor %d]\n", v4);
}
}
if ( write(1, "#\n", 2uLL) == -1 )
{
v6 = getpid();
syserr("Error while passing the kill command [executor %d]\n", v6);
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
size_t v3; // rax
unsigned int v4; // eax
unsigned int v6; // eax

while ( 1 )
{
func8((__int64)&input);
if ( input == 35 )
break;
func10(&input, output);
v3 = strlen(output);
if ( write(1, output, v3) == -1 )
{
v4 = getpid();
func11("Error while passing the results through pipe [executor %d]\n", v4);
}
}
if ( write(1, "#\n", 2uLL) == -1 )
{
v6 = getpid();
func11("Error while passing the kill command [executor %d]\n", v6);
}
return 0;
}

original_code:
int main() {
 while (1) {
  readInput(input);
  if (input[0] == '#') {
   if (write(1, "#\n", 2) == -1)
    syserr("Error while passing the kill command [executor %d]\n", getpid());
   break;
  }
  if (debug)
   fprintf(stderr, "Executor %d: Read: %s\n", getpid(), input);
  calc(input, output);
  if (write(1, output, strlen(output)) == -1)
   syserr("Error while passing the results through pipe [executor %d]\n", getpid());
 }
 return 0;
}


inRoute

decompiled_code:
__int64 __fastcall inRoute(__int64 a1, _QWORD *a2)
{
while ( *a2 != a1 )
{
a2 = (_QWORD *)a2[1];
if ( !a2 )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, _QWORD *a2)
{
while ( *a2 != a1 )
{
a2 = (_QWORD *)a2[1];
if ( !a2 )
return 0LL;
}
return 1LL;
}

original_code:
static int inRoute(NODE *node, LIST_ELEMENT *route) {
    while (route->self != node) {
        route = ((LIST_ELEMENT*) route)->nextElement;
        if (route == ((void *)0))
            return 0;
    }
    return 1;
}

canonical_original_code:
static int inRoute(struct NODE *node, struct LIST_ELEMENT *route) {
    while (route->self != node) {
        route = ((struct LIST_ELEMENT *) route)->nextElement;
        if (route == ((void *)0))
            return 0;
    }
    return 1;
}

variable_types: struct NODE { unsigned int dist; void *parent; unsigned int no; } *

variable_types: struct LIST_ELEMENT { void *self; void *nextElement; } *


freeRoute

decompiled_code:
__int64 __fastcall freeRoute(_QWORD *a1)
{
_QWORD *v1; // rbx
__int64 result; // rax

v1 = (_QWORD *)a1[1];
if ( v1 )
{
while ( 1 )
{
free(a1);
result = v1[1];
a1 = v1;
if ( !result )
break;
v1 = (_QWORD *)v1[1];
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1)
{
_QWORD *v1; // rbx
__int64 result; // rax

v1 = (_QWORD *)a1[1];
if ( v1 )
{
while ( 1 )
{
free(a1);
result = v1[1];
a1 = v1;
if ( !result )
break;
v1 = (_QWORD *)v1[1];
}
}
return result;
}

original_code:
void freeRoute(LIST_ELEMENT* route) {
    LIST_ELEMENT* tmp = route;
    while (route->nextElement) {
        tmp = route;
        route = route->nextElement;
        free(tmp);
    }
}

canonical_original_code:
void freeRoute(struct LIST_ELEMENT *route) {
    struct LIST_ELEMENT *tmp = route;
    while (route->nextElement) {
        tmp = route;
        route = route->nextElement;
        free(tmp);
    }
}

user_defined_types: struct LIST_ELEMENT { void *self; void *nextElement; }


original_code:
void bellman_ford(unsigned int startX, unsigned int startY) {
    int V = graph.N;
    int E = graph.E;
    graph.nodes[startX + (5) * startY]->dist = 0;
    int i, j;
    for (i = 1; i <= V - 1; i++) {
        for (j = 0; j < E; j++) {
            int penalty = 0;
            int u = graph.edges[j]->src;
            int v = graph.edges[j]->dst;
            int parent = -1;
            parent = findNode(graph.nodes[u]->parent);
            int dir = 0;
            if (parent >= 0) {
                dir = u - parent;
            }
            if ((v - u) != dir && dir != 0) {
                penalty = 5;
            }
            unsigned int weight = graph.edges[j]->weight + penalty;
            if ((graph.nodes[u]->dist + weight) < graph.nodes[v]->dist) {
                graph.nodes[v]->dist = graph.nodes[u]->dist + weight;
                graph.nodes[v]->parent = graph.nodes[u];
            }
        }
    }
}

canonical_original_code:
void bellman_ford(unsigned int startX, unsigned int startY) {
    int V = graph.N;
    int E = graph.E;
    graph.nodes[startX + (5) * startY]->dist = 0;
    int i; int j;
    for (i = 1; i <= V - 1; i++) {
        for (j = 0; j < E; j++) {
            int penalty = 0;
            int u = graph.edges[j]->src;
            int v = graph.edges[j]->dst;
            int parent = -1;
            parent = findNode(graph.nodes[u]->parent);
            int dir = 0;
            if (parent >= 0) {
                dir = u - parent;
            }
            if ((v - u) != dir && dir != 0) {
                penalty = 5;
            }
            unsigned int weight = graph.edges[j]->weight + penalty;
            if ((graph.nodes[u]->dist + weight) < graph.nodes[v]->dist) {
                graph.nodes[v]->dist = graph.nodes[u]->dist + weight;
                graph.nodes[v]->parent = graph.nodes[u];
            }
        }
    }
}

variable_types:
startX
unsigned int

variable_types:
startY
unsigned int

variable_types: V int

variable_types: E int

variable_types: i int

variable_types: penalty int

variable_types: u int

variable_types: v int

variable_types: parent int

variable_types: dir int

variable_types:
weight
unsigned int


printRoute

decompiled_code:
__int64 __fastcall printRoute(int a1, int a2, int a3, int a4)
{
_QWORD *v4; // r15
__int64 v5; // r14
__int64 v6; // r12
unsigned int i; // ebx
unsigned int j; // ebx
int v10; // [rsp+0h] [rbp-48h]
unsigned int v11; // [rsp+4h] [rbp-44h]

v4 = traceRoute(a1, a2, a3, a4);
v10 = 0;
v11 = 1;
v5 = 0LL;
do
{
v6 = 40 * v5;
for ( i = 0; ; ++i )
{
if ( (unsigned int)inRoute(*(_QWORD *)(graph[1] + v6), v4) || a1 == i && a2 == (_DWORD)v5 )
putchar(42);
else
putchar(32);
printf("%.2d ", i + v10);
if ( (int)findEdge(i, (unsigned int)v5, i + 1, (unsigned int)v5) < 0 )
printf(" ");
else
printf("- ");
v6 += 8LL;
if ( i == 4 )
break;
}
putchar(10);
for ( j = 0; j != 5; ++j )
{
if ( (int)findEdge(j, (unsigned int)v5, j, v11) < 0 )
printf(" ");
else
printf(" | ");
}
putchar(10);
++v5;
++v11;
v10 += 5;
}
while ( v10 != 25 );
return freeRoute(v4);
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, int a2, int a3, int a4)
{
_QWORD *v4; // r15
__int64 v5; // r14
__int64 v6; // r12
unsigned int i; // ebx
unsigned int j; // ebx
int v10; // [rsp+0h] [rbp-48h]
unsigned int v11; // [rsp+4h] [rbp-44h]

v4 = traceRoute(a1, a2, a3, a4);
v10 = 0;
v11 = 1;
v5 = 0LL;
do
{
v6 = 40 * v5;
for ( i = 0; ; ++i )
{
if ( (unsigned int)func0(*(_QWORD *)(graph[1] + v6), v4) || a1 == i && a2 == (_DWORD)v5 )
putchar(42);
else
putchar(32);
printf("%.2d ", i + v10);
if ( (int)findEdge(i, (unsigned int)v5, i + 1, (unsigned int)v5) < 0 )
printf(" ");
else
printf("- ");
v6 += 8LL;
if ( i == 4 )
break;
}
putchar(10);
for ( j = 0; j != 5; ++j )
{
if ( (int)findEdge(j, (unsigned int)v5, j, v11) < 0 )
printf(" ");
else
printf(" | ");
}
putchar(10);
++v5;
++v11;
v10 += 5;
}
while ( v10 != 25 );
return func1(v4);
}

original_code:
void printRoute(int strtX, int strtY, int dstX, int dstY) {
    LIST_ELEMENT *rt = traceRoute(strtX, strtY, dstX, dstY);
    int i, j;
    for (j = 0; j < (5); j++) {
        for (i = 0; i < (5); i++) {
            if ((inRoute(graph.nodes[i + j * (5)], rt)) || (i == strtX && j == strtY)) {
                printf("*");
            }
            else
                printf(" ");
            printf("%.2d  ", (i+(5)*j));
            if (findEdge(i, j, i + 1, j) >= 0)
                printf("- ");
            else
                printf("  ");
        }
        printf("\n");
        for (i = 0; i < (5); i++) {
            if (findEdge(i, j, i, j + 1) >= 0)
                printf("  |    ");
            else
                printf("       ");
        }
        printf("\n");
    }
    freeRoute(rt);
}

canonical_original_code:
void printRoute(int strtX, int strtY, int dstX, int dstY) {
    struct LIST_ELEMENT *rt = traceRoute(strtX, strtY, dstX, dstY);
    int i; int j;
    for (j = 0; j < (5); j++) {
        for (i = 0; i < (5); i++) {
            if ((inRoute(graph.nodes[i + j * (5)], rt)) || (i == strtX && j == strtY)) {
                printf("*");
            }
            else
                printf(" ");
            printf("%.2d  ", (i+(5)*j));
            if (findEdge(i, j, i + 1, j) >= 0)
                printf("- ");
            else
                printf("  ");
        }
        printf("\n");
        for (i = 0; i < (5); i++) {
            if (findEdge(i, j, i, j + 1) >= 0)
                printf("  |    ");
            else
                printf("       ");
        }
        printf("\n");
    }
    freeRoute(rt);
}

variable_types: strtX int

variable_types: strtY int

variable_types: dstX int

variable_types: dstY int

variable_types: j int


explore

decompiled_code:
void __fastcall explore(__int64 a1, __int64 a2, __int64 a3, int a4)
{
while ( a4 )
;
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1, __int64 a2, __int64 a3, int a4)
{
while ( a4 )
;
}

original_code:
void explore(int *mines, int startX, int startY, int n){
 int pos[2];
 pos[0] = startX;
 pos[1] = startY;
 EDGE* visited = malloc(sizeof(EDGE*)*(((5)-2)*((5)-2)*4 + 4*2 + ((2*3*((5)-2)) + 2*3*((5)-2))));
 while(n){
 }
}

canonical_original_code:
void explore(int *mines, int startX, int startY, int n){
 int pos[2];
 pos[0] = startX;
 pos[1] = startY;
 struct EDGE *visited = malloc(sizeof(EDGE*)*(((5)-2)*((5)-2)*4 + 4*2 + ((2*3*((5)-2)) + 2*3*((5)-2))));
 while(n){
 }
}

variable_types:
mines
int *

variable_types: startX int

variable_types: startY int

variable_types: n int

variable_types:
pos
int [2]

variable_types: struct EDGE { unsigned int src; unsigned int dst; unsigned int weight; } *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
initializeGrid(argc, argv, envp);
initMines(&graph, 13LL, 5LL, 5LL);
bellman_ford(0LL, 0LL);
printRoute(0LL, 0LL, 4LL, 4LL);
deinitializeGrid();
return 0;
}

original_code:
int main(int argc, char** argv) {
    initializeGrid();
 int* mines = initMines(&graph, 13, (5), (5));
    bellman_ford(0, 0);
    printRoute(0, 0, 4, 4);
    deinitializeGrid();
    return (0);
}

canonical_original_code:
int main(int argc, char **argv) {
    initializeGrid();
 int *mines = initMines(&graph, 13, (5), (5));
    bellman_ford(0, 0);
    printRoute(0, 0, 4, 4);
    deinitializeGrid();
    return (0);
}

variable_types: argc int

variable_types:
argv
char **


findEdge

decompiled_code:
__int64 __fastcall findEdge(int a1, int a2, int a3, int a4)
{
int v5; // ecx
int v6; // edi
int v7; // er9
__int64 v8; // rax
unsigned int v9; // esi
_DWORD *v10; // rdx

v5 = *(&graph + 1);
if ( v5 <= 0 )
return (unsigned int)-1;
v6 = a1 + 5 * a2;
v7 = a3 + 5 * a4;
v8 = 0LL;
while ( 1 )
{
v9 = v8;
v10 = *(_DWORD **)(*((_QWORD *)&graph + 2) + 8 * v8);
if ( *v10 == v6 && v10[1] == v7 )
break;
if ( ++v8 == v5 )
return (unsigned int)-1;
}
return v9;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, int a2, int a3, int a4)
{
int v5; // ecx
int v6; // edi
int v7; // er9
__int64 v8; // rax
unsigned int v9; // esi
_DWORD *v10; // rdx

v5 = *(&graph + 1);
if ( v5 <= 0 )
return (unsigned int)-1;
v6 = a1 + 5 * a2;
v7 = a3 + 5 * a4;
v8 = 0LL;
while ( 1 )
{
v9 = v8;
v10 = *(_DWORD **)(*((_QWORD *)&graph + 2) + 8 * v8);
if ( *v10 == v6 && v10[1] == v7 )
break;
if ( ++v8 == v5 )
return (unsigned int)-1;
}
return v9;
}

original_code:
int findEdge(int sx, int sy, int dx, int dy) {
    int i;
    for (i = 0; i < graph.E; i++) {
        if (graph.edges[i]->src == (sx+(5)*sy) && graph.edges[i]->dst == (dx+(5)*dy)) {
            return i;
        }
    }
    return -1;
}

variable_types: sx int

variable_types: sy int

variable_types: dx int

variable_types: dy int

variable_types: i int


removeEdge

decompiled_code:
void __fastcall removeEdge(int a1, int a2, int a3, int a4)
{
int v4; // ebp
int v5; // ebx
int v6; // eax
int v7; // eax

v4 = *(&graph + 1);
if ( v4 > 0 )
{
v5 = findEdge(a1, a2, a3, a4);
v6 = 0;
while ( v5 < 0 )
{
if ( ++v6 == v4 )
return;
}
free(*(void **)(*((_QWORD *)&graph + 2) + 8LL * v5));
v7 = *(&graph + 1) - 1;
if ( v7 > v5 )
memmove(
(void *)(8LL * v5 + *((_QWORD *)&graph + 2)),
(const void *)(*((_QWORD *)&graph + 2) + 8LL * v5 + 8),
8LL * (v7 - v5));
--*(&graph + 1);
}
}

canonical_decompiled_code:
void __fastcall func2(int a1, int a2, int a3, int a4)
{
int v4; // ebp
int v5; // ebx
int v6; // eax
int v7; // eax

v4 = *(&graph + 1);
if ( v4 > 0 )
{
v5 = func1(a1, a2, a3, a4);
v6 = 0;
while ( v5 < 0 )
{
if ( ++v6 == v4 )
return;
}
free(*(void **)(*((_QWORD *)&graph + 2) + 8LL * v5));
v7 = *(&graph + 1) - 1;
if ( v7 > v5 )
memmove(
(void *)(8LL * v5 + *((_QWORD *)&graph + 2)),
(const void *)(*((_QWORD *)&graph + 2) + 8LL * v5 + 8),
8LL * (v7 - v5));
--*(&graph + 1);
}
}

original_code:
void removeEdge(int sx, int sy, int dx, int dy) {
    int i, tmp = 0;
    for (i = 0; i < graph.E; i++) {
        if ((tmp = findEdge(sx, sy, dx, dy)) >= 0) {
            free(graph.edges[tmp]);
            if (tmp < (graph.E - 1))
                memmove(&graph.edges[tmp], &graph.edges[tmp + 1], ((graph.E - 1) - tmp) * sizeof (EDGE*));
            graph.E--;
            return;
        }
    }
}

canonical_original_code:
void removeEdge(int sx, int sy, int dx, int dy) {
    int i; int tmp = 0;
    for (i = 0; i < graph.E; i++) {
        if ((tmp = findEdge(sx, sy, dx, dy)) >= 0) {
            free(graph.edges[tmp]);
            if (tmp < (graph.E - 1))
                memmove(&graph.edges[tmp], &graph.edges[tmp + 1], ((graph.E - 1) - tmp) * sizeof (struct EDGE *));
            graph.E--;
            return;
        }
    }
}

variable_types: tmp int

user_defined_types: struct EDGE { unsigned int src; unsigned int dst; unsigned int weight; }


initializeGrid

original_code:
void initializeGrid(void) {
    graph.nodes = malloc(sizeof (NODE*) * (5) * (5));
    graph.edges = malloc(sizeof(EDGE*)*(((5)-2)*((5)-2)*4 + 4*2 + ((2*3*((5)-2)) + 2*3*((5)-2))));
    int i, j;
    for (i = 0; i < (5); i++) {
        for (j = 0; j < (5); j++) {
            graph.nodes[i + j * (5)] = malloc(sizeof (NODE));
            graph.nodes[i + j * (5)]->dist = 0x7fffffff;
            graph.nodes[i + j * (5)]->parent = ((void *)0);
            graph.nodes[i + j * (5)]->no = i + j*(5);
            if (i != 0) {
                graph.edges[graph.E] = malloc(sizeof (EDGE));
                initEdge(graph.edges[graph.E], i, j, -1);
                graph.E++;
            }
            if (i != ((5) - 1)) {
                graph.edges[graph.E] = malloc(sizeof (EDGE));
                initEdge(graph.edges[graph.E], i, j, 1);
                graph.E++;
            }
            if (j != 0) {
                graph.edges[graph.E] = malloc(sizeof (EDGE));
                initEdge(graph.edges[graph.E], i, j, -(5));
                graph.E++;
            }
            if (j != ((5) - 1)) {
                graph.edges[graph.E] = malloc(sizeof (EDGE));
                initEdge(graph.edges[graph.E], i, j, (5));
                graph.E++;
            }
        }
    }
    graph.N = (5)*(5);
}

canonical_original_code:
void initializeGrid() {
    graph.nodes = malloc(sizeof (struct NODE *) * (5) * (5));
    graph.edges = malloc(sizeof(struct EDGE *)*(((5)-2)*((5)-2)*4 + 4*2 + ((2*3*((5)-2)) + 2*3*((5)-2))));
    int i; int j;
    for (i = 0; i < (5); i++) {
        for (j = 0; j < (5); j++) {
            graph.nodes[i + j * (5)] = malloc(sizeof (NODE));
            graph.nodes[i + j * (5)]->dist = 0x7fffffff;
            graph.nodes[i + j * (5)]->parent = ((void *)0);
            graph.nodes[i + j * (5)]->no = i + j*(5);
            if (i != 0) {
                graph.edges[graph.E] = malloc(sizeof (EDGE));
                initEdge(graph.edges[graph.E], i, j, -1);
                graph.E++;
            }
            if (i != ((5) - 1)) {
                graph.edges[graph.E] = malloc(sizeof (EDGE));
                initEdge(graph.edges[graph.E], i, j, 1);
                graph.E++;
            }
            if (j != 0) {
                graph.edges[graph.E] = malloc(sizeof (EDGE));
                initEdge(graph.edges[graph.E], i, j, -(5));
                graph.E++;
            }
            if (j != ((5) - 1)) {
                graph.edges[graph.E] = malloc(sizeof (EDGE));
                initEdge(graph.edges[graph.E], i, j, (5));
                graph.E++;
            }
        }
    }
    graph.N = (5)*(5);
}

user_defined_types: struct NODE { unsigned int dist; void *parent; unsigned int no; }


deinitializeGrid

decompiled_code:
void deinitializeGrid()
{
__int64 v0; // rbx
__int64 v1; // rbx

if ( graph > 0 )
{
v0 = 0LL;
do
free(*(void **)(*((_QWORD *)&graph + 1) + 8 * v0++));
while ( graph > (int)v0 );
}
if ( *(&graph + 1) > 0 )
{
v1 = 0LL;
do
free(*(void **)(*((_QWORD *)&graph + 2) + 8 * v1++));
while ( *(&graph + 1) > (int)v1 );
}
free(*((void **)&graph + 1));
free(*((void **)&graph + 2));
}

original_code:
void deinitializeGrid(void) {
    int i;
    for (i = 0; i < graph.N; i++) {
        free(graph.nodes[i]);
    }
    for (i = 0; i < graph.E; i++) {
        free(graph.edges[i]);
    }
    free(graph.nodes);
    free(graph.edges);
}

canonical_original_code:
void deinitializeGrid() {
    int i;
    for (i = 0; i < graph.N; i++) {
        free(graph.nodes[i]);
    }
    for (i = 0; i < graph.E; i++) {
        free(graph.edges[i]);
    }
    free(graph.nodes);
    free(graph.edges);
}


findNode

decompiled_code:
__int64 __fastcall findNode(__int64 a1)
{
_QWORD *v1; // rax
__int64 v2; // rdx

if ( !a1 )
return 0xFFFFFFFFLL;
if ( graph <= 0 )
return 0xFFFFFFFFLL;
v1 = (_QWORD *)*((_QWORD *)&graph + 1);
v2 = (__int64)&v1[(unsigned int)(graph - 1) + 1];
while ( *v1 != a1 )
{
if ( ++v1 == (_QWORD *)v2 )
return 0xFFFFFFFFLL;
}
return *(unsigned int *)(a1 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
_QWORD *v1; // rax
__int64 v2; // rdx

if ( !a1 )
return 0xFFFFFFFFLL;
if ( graph <= 0 )
return 0xFFFFFFFFLL;
v1 = (_QWORD *)*((_QWORD *)&graph + 1);
v2 = (__int64)&v1[(unsigned int)(graph - 1) + 1];
while ( *v1 != a1 )
{
if ( ++v1 == (_QWORD *)v2 )
return 0xFFFFFFFFLL;
}
return *(unsigned int *)(a1 + 16);
}

original_code:
int findNode(void* node) {
    int i;
    if (node) {
        for (i = 0; i < graph.N; i++) {
            if (graph.nodes[i] == ((NODE*) node))
                return graph.nodes[i]->no;
        }
    }
    return -1;
}

canonical_original_code:
int findNode(void *node) {
    int i;
    if (node) {
        for (i = 0; i < graph.N; i++) {
            if (graph.nodes[i] == ((struct NODE *) node))
                return graph.nodes[i]->no;
        }
    }
    return -1;
}

variable_types:
node
void *


intInList

decompiled_code:
__int64 __fastcall intInList(_DWORD *a1, int a2, int a3)
{
_DWORD *v3; // rax
__int64 v4; // rdx

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

canonical_decompiled_code:
__int64 __fastcall func0(_DWORD *a1, int a2, int a3)
{
_DWORD *v3; // rax
__int64 v4; // rdx

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

original_code:
int intInList(int* list, int val, int size){
 int i;
 for(i=0; i<size; i++){
  if(list[i]==val)
   return 1;
 }
 return 0;
}

canonical_original_code:
int intInList(int *list, int val, int size){
 int i;
 for(i=0; i<size; i++){
  if(list[i]==val)
   return 1;
 }
 return 0;
}

variable_types:
list
int *

variable_types: val int

variable_types: size int


repo: TooDumbForAName/ncsa-httpd

decompiled_code:
__int64 __fastcall allocate_strings(__int64 a1, int a2, unsigned int a3)
{
unsigned int v3; // er12
_BYTE *v4; // rax
_BYTE *v5; // rbx
_DWORD *v6; // rax
int v7; // edx

v3 = a3;
if ( a3 )
{
while ( 1 )
{
v4 = malloc(a2);
v5 = v4;
if ( !v4 )
return 1;
*v4 = 0;
v6 = malloc(0x18uLL);
if ( !v6 )
break;
*(_QWORD *)v6 = v5;
v6[2] = a2;
v7 = *(_DWORD *)(a1 + 8);
if ( v7 )
{
*((_QWORD *)v6 + 2) = *(_QWORD *)a1;
*(_QWORD *)a1 = v6;
*(_DWORD *)(a1 + 8) = v7 + 1;
}
else
{
*(_QWORD *)a1 = v6;
*((_QWORD *)v6 + 2) = 0LL;
*(_DWORD *)(a1 + 8) = 1;
}
if ( !--v3 )
return v3;
}
v3 = 1;
}
return v3;
}

original_code:
int allocate_strings(string_list *slist, int length, int num)
{
  string_item *stmp;
  char *S;
  while (num) {
    if (!(S = (char *) malloc(length * sizeof(char))))
      return 1;
    S[0] = '\0';
    if (!(stmp = (string_item *) malloc(sizeof(string_item))))
      return 1;
    stmp->string = S;
    stmp->length = length;
    if (slist->num == 0) {
      slist->first = stmp;
      stmp->next = ((void *)0);
      slist->num = 1;
    } else {
      stmp->next = slist->first;
      slist->first = stmp;
      slist->num++;
    }
    num--;
  }
  return 0;
}

canonical_original_code:
int allocate_strings(struct _string_list *slist, int length, int num)
{
  struct _string_item *stmp;
  char *S;
  while (num) {
    if (!(S = (char *) malloc(length * sizeof(char))))
      return 1;
    S[0] = '\0';
    if (!(stmp = (struct _string_item *) malloc(sizeof(string_item))))
      return 1;
    stmp->string = S;
    stmp->length = length;
    if (slist->num == 0) {
      slist->first = stmp;
      stmp->next = ((void *)0);
      slist->num = 1;
    } else {
      stmp->next = slist->first;
      slist->first = stmp;
      slist->num++;
    }
    num--;
  }
  return 0;
}

variable_types: struct _string_list { struct _string_item { char *string; int length; int type; struct _string_item *next; } *first; int num; } *

variable_types: length int

variable_types: num int

variable_types:
S
char *

user_defined_types: struct _string_list { struct _string_item *first; int num; }


decompiled_code:
__int64 initialize_string_allocate()
{
*((_DWORD *)&free_list + 2) = 0;
free_list = 0LL;
*((_DWORD *)&used_list + 2) = 0;
used_list = 0LL;
allocate_strings((__int64)&free_list, 0x2000, 5u);
allocate_strings((__int64)&free_list, 256, 5u);
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
*((_DWORD *)&free_list + 2) = 0;
free_list = 0LL;
*((_DWORD *)&used_list + 2) = 0;
used_list = 0LL;
func0((__int64)&free_list, 0x2000, 5u);
func0((__int64)&free_list, 256, 5u);
return 0LL;
}

original_code:
int initialize_string_allocate()
{
  free_list.num = 0;
  free_list.first = ((void *)0);
  used_list.num = 0;
  used_list.first = ((void *)0);
  allocate_strings(&free_list,8192,5);
  allocate_strings(&free_list,256,5);
  return 0;
}


decompiled_code:
__int64 initialize_allocate()
{
initialize_string_allocate();
return 0LL;
}

canonical_decompiled_code:
__int64 func2()
{
func1();
return 0LL;
}

original_code:
int initialize_allocate()
{
   initialize_string_allocate();
   return 0;
}


original_code:
int remove_string_item(string_list *slist, string_item *sitem)
{
  string_item *stmp,*last;
  int x;
  stmp = slist->first;
  last = ((void *)0);
  for(x = 0; x < slist->num ; x++) {
    if (stmp == sitem) {
      if (stmp == slist->first) {
 slist->first = slist->first->next;
      } else {
 last->next = stmp->next;
      }
      slist->num--;
      stmp->next = ((void *)0);
      return 1;
    }
    last = stmp;
    stmp = stmp->next;
  }
  return 0;
}

canonical_original_code:
int remove_string_item(struct _string_list *slist, struct _string_item *sitem)
{
  struct _string_item *stmp; struct _string_item *last;
  int x;
  stmp = slist->first;
  last = ((void *)0);
  for(x = 0; x < slist->num ; x++) {
    if (stmp == sitem) {
      if (stmp == slist->first) {
 slist->first = slist->first->next;
      } else {
 last->next = stmp->next;
      }
      slist->num--;
      stmp->next = ((void *)0);
      return 1;
    }
    last = stmp;
    stmp = stmp->next;
  }
  return 0;
}

variable_types:
sitem
struct _string_item *

variable_types: struct _string_item { char *string; int length; int type; struct _string_item *next; } *

variable_types: x int


original_code:
int add_string_item(string_list *slist, string_item *sitem)
{
  if (slist->num == 0) {
    slist->first = sitem;
    slist->num = 1;
  } else {
    sitem->next = slist->first;
    slist->first = sitem;
    slist->num++;
  }
  return 1;
}

canonical_original_code:
int add_string_item(struct _string_list *slist, struct _string_item *sitem)
{
  if (slist->num == 0) {
    slist->first = sitem;
    slist->num = 1;
  } else {
    sitem->next = slist->first;
    slist->first = sitem;
    slist->num++;
  }
  return 1;
}

user_defined_types: struct _string_item { char *string; int length; int type; struct _string_item *next; }


newString

decompiled_code:
__int64 __fastcall newString(int a1, int a2)
{
unsigned int v2; // edx
__int64 v3; // rbx
int v4; // edx
int v5; // eax
__int64 *v6; // rax
__int64 result; // rax

if ( !*((_DWORD *)&free_list + 2) )
{
if ( a1 == 0x2000 || (v2 = 1, a1 == 256) )
v2 = 5;
allocate_strings((__int64)&free_list, a1, v2);
}
v3 = free_list;
v4 = *((_DWORD *)&free_list + 2);
if ( v4 <= 0 )
{
LABEL_9:
allocate_strings((__int64)&used_list, a1, 1u);
v6 = (__int64 *)used_list;
*(_DWORD *)(used_list + 12) = a2;
result = *v6;
}
else
{
v5 = 0;
while ( *(_DWORD *)(v3 + 8) != a1 )
{
v3 = *(_QWORD *)(v3 + 16);
if ( ++v5 == v4 )
goto LABEL_9;
}
remove_string_item(&free_list, v3);
add_string_item((__int64)&used_list, v3);
*(_DWORD *)(v3 + 12) = a2;
result = *(_QWORD *)v3;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1, int a2)
{
unsigned int v2; // edx
__int64 v3; // rbx
int v4; // edx
int v5; // eax
__int64 *v6; // rax
__int64 result; // rax

if ( !*((_DWORD *)&free_list + 2) )
{
if ( a1 == 0x2000 || (v2 = 1, a1 == 256) )
v2 = 5;
func0((__int64)&free_list, a1, v2);
}
v3 = free_list;
v4 = *((_DWORD *)&free_list + 2);
if ( v4 <= 0 )
{
LABEL_9:
func0((__int64)&used_list, a1, 1u);
v6 = (__int64 *)used_list;
*(_DWORD *)(used_list + 12) = a2;
result = *v6;
}
else
{
v5 = 0;
while ( *(_DWORD *)(v3 + 8) != a1 )
{
v3 = *(_QWORD *)(v3 + 16);
if ( ++v5 == v4 )
goto LABEL_9;
}
func3(&free_list, v3);
func4((__int64)&used_list, v3);
*(_DWORD *)(v3 + 12) = a2;
result = *(_QWORD *)v3;
}
return result;
}

original_code:
char* newString(int length, int type)
{
  int num, x;
  string_item *sitem;
  if (free_list.num == 0) {
    if ((length == 8192) || (length == 256))
      num = 5;
    else
      num = 1;
    allocate_strings(&free_list, length, num);
  }
  sitem = free_list.first;
  for(x = 0; x < free_list.num ; x++) {
    if (sitem->length == length) {
      remove_string_item(&free_list,sitem);
      add_string_item(&used_list,sitem);
      sitem->type = type;
      return sitem->string;
    }
    sitem = sitem->next;
  }
  allocate_strings(&used_list, length, 1);
  used_list.first->type = type;
  return used_list.first->string;
}

canonical_original_code:
char *newString(int length, int type)
{
  int num; int x;
  struct _string_item *sitem;
  if (free_list.num == 0) {
    if ((length == 8192) || (length == 256))
      num = 5;
    else
      num = 1;
    allocate_strings(&free_list, length, num);
  }
  sitem = free_list.first;
  for(x = 0; x < free_list.num ; x++) {
    if (sitem->length == length) {
      remove_string_item(&free_list,sitem);
      add_string_item(&used_list,sitem);
      sitem->type = type;
      return sitem->string;
    }
    sitem = sitem->next;
  }
  allocate_strings(&used_list, length, 1);
  used_list.first->type = type;
  return used_list.first->string;
}

variable_types: type int


freeString

decompiled_code:
__int64 __fastcall freeString(_BYTE *a1)
{
_QWORD *v1; // rbx
int v2; // edx
int v3; // eax
__int64 result; // rax

if ( !a1 )
return 0LL;
v1 = (_QWORD *)used_list;
v2 = *((_DWORD *)&used_list + 2);
if ( v2 <= 0 )
{
LABEL_6:
log_error("Attempt to Free String not in Use", *(_QWORD *)(gConfiguration + 96LL));
result = 0LL;
}
else
{
v3 = 0;
while ( (_BYTE *)*v1 != a1 )
{
v1 = (_QWORD *)v1[2];
if ( ++v3 == v2 )
goto LABEL_6;
}
*a1 = 0;
remove_string_item(&used_list, (__int64)v1);
add_string_item((__int64)&free_list, (__int64)v1);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(_BYTE *a1)
{
_QWORD *v1; // rbx
int v2; // edx
int v3; // eax
__int64 result; // rax

if ( !a1 )
return 0LL;
v1 = (_QWORD *)used_list;
v2 = *((_DWORD *)&used_list + 2);
if ( v2 <= 0 )
{
LABEL_6:
log_error("Attempt to Free String not in Use", *(_QWORD *)(gConfiguration + 96LL));
result = 0LL;
}
else
{
v3 = 0;
while ( (_BYTE *)*v1 != a1 )
{
v1 = (_QWORD *)v1[2];
if ( ++v3 == v2 )
goto LABEL_6;
}
*a1 = 0;
func3(&used_list, (__int64)v1);
func4((__int64)&free_list, (__int64)v1);
result = 1LL;
}
return result;
}

original_code:
int freeString(char *string)
{
  int x;
  string_item *sitem;
  if (string == ((void *)0)) return 0;
  sitem = used_list.first;
  for(x = 0; x < used_list.num ; x++) {
    if (sitem->string == string) {
      string[0] = '\0';
      remove_string_item(&used_list,sitem);
      add_string_item(&free_list,sitem);
      return 1;
    }
    sitem = sitem->next;
  }
  log_error("Attempt to Free String not in Use",gConfiguration->error_log);
  return 0;
}

canonical_original_code:
int freeString(char *string)
{
  int x;
  struct _string_item *sitem;
  if (string == ((void *)0)) return 0;
  sitem = used_list.first;
  for(x = 0; x < used_list.num ; x++) {
    if (sitem->string == string) {
      string[0] = '\0';
      remove_string_item(&used_list,sitem);
      add_string_item(&free_list,sitem);
      return 1;
    }
    sitem = sitem->next;
  }
  log_error("Attempt to Free String not in Use",gConfiguration->error_log);
  return 0;
}

variable_types:
string
char *


sizeofString

decompiled_code:
__int64 __fastcall sizeofString(__int64 a1)
{
__int64 v1; // rax
int v2; // ecx
int v3; // edx

if ( !a1 )
return 0xFFFFFFFFLL;
v1 = used_list;
v2 = *((_DWORD *)&used_list + 2);
if ( v2 <= 0 )
return 0xFFFFFFFFLL;
v3 = 0;
while ( *(_QWORD *)v1 != a1 )
{
v1 = *(_QWORD *)(v1 + 16);
if ( ++v3 == v2 )
return 0xFFFFFFFFLL;
}
return *(unsigned int *)(v1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
__int64 v1; // rax
int v2; // ecx
int v3; // edx

if ( !a1 )
return 0xFFFFFFFFLL;
v1 = used_list;
v2 = *((_DWORD *)&used_list + 2);
if ( v2 <= 0 )
return 0xFFFFFFFFLL;
v3 = 0;
while ( *(_QWORD *)v1 != a1 )
{
v1 = *(_QWORD *)(v1 + 16);
if ( ++v3 == v2 )
return 0xFFFFFFFFLL;
}
return *(unsigned int *)(v1 + 8);
}

original_code:
int sizeofString(char *string)
{
  int x;
  string_item *sitem;
  if (string == ((void *)0)) return -1;
  sitem = used_list.first;
  for(x = 0; x < used_list.num ; x++) {
    if (sitem->string == string) {
      return sitem->length;
    }
    sitem = sitem->next;
  }
  return -1;
}

canonical_original_code:
int sizeofString(char *string)
{
  int x;
  struct _string_item *sitem;
  if (string == ((void *)0)) return -1;
  sitem = used_list.first;
  for(x = 0; x < used_list.num ; x++) {
    if (sitem->string == string) {
      return sitem->length;
    }
    sitem = sitem->next;
  }
  return -1;
}


freeAllStrings

decompiled_code:
__int64 __fastcall freeAllStrings(int a1)
{
__int64 v1; // rsi
__int64 v2; // rbp

v1 = used_list;
if ( !*((_DWORD *)&used_list + 2) )
return 1LL;
if ( used_list )
{
v2 = 0LL;
do
{
if ( *(_DWORD *)(v1 + 12) > a1 )
{
v2 = v1;
v1 = *(_QWORD *)(v1 + 16);
}
else
{
**(_BYTE **)v1 = 0;
if ( used_list == v1 )
{
used_list = *(_QWORD *)(v1 + 16);
--*((_DWORD *)&used_list + 2);
*(_QWORD *)(v1 + 16) = 0LL;
add_string_item((__int64)&free_list, v1);
v1 = used_list;
}
else
{
--*((_DWORD *)&used_list + 2);
*(_QWORD *)(v2 + 16) = *(_QWORD *)(v1 + 16);
add_string_item((__int64)&free_list, v1);
v1 = *(_QWORD *)(v2 + 16);
}
}
}
while ( *((_DWORD *)&used_list + 2) && v1 );
}
return 1LL;
}

original_code:
int freeAllStrings(int type)
{
   string_item *sitem,*slast;
   slast = ((void *)0);
   sitem = used_list.first;
   while (used_list.num && (sitem != ((void *)0))) {
     if (sitem->type <= type) {
       sitem->string[0] = '\0';
       if (sitem == used_list.first) {
  used_list.first = sitem->next;
  used_list.num--;
  sitem->next = ((void *)0);
  add_string_item(&free_list,sitem);
  sitem = used_list.first;
       } else {
  used_list.num--;
  slast->next = sitem->next;
  add_string_item(&free_list,sitem);
  sitem = slast->next;
       }
     } else {
       slast = sitem;
       sitem = sitem->next;
     }
   }
   return 1;
}

canonical_original_code:
int freeAllStrings(int type)
{
   struct _string_item *sitem; struct _string_item *slast;
   slast = ((void *)0);
   sitem = used_list.first;
   while (used_list.num && (sitem != ((void *)0))) {
     if (sitem->type <= type) {
       sitem->string[0] = '\0';
       if (sitem == used_list.first) {
  used_list.first = sitem->next;
  used_list.num--;
  sitem->next = ((void *)0);
  add_string_item(&free_list,sitem);
  sitem = used_list.first;
       } else {
  used_list.num--;
  slast->next = sitem->next;
  add_string_item(&free_list,sitem);
  sitem = slast->next;
       }
     } else {
       slast = sitem;
       sitem = sitem->next;
     }
   }
   return 1;
}


dupStringP

decompiled_code:
char *__fastcall dupStringP(char *src, int a2)
{
int v2; // ebx
char *v3; // rbp
char *result; // rax

v2 = 256;
if ( (int)strlen(src) > 256 )
v2 = 0x2000;
v3 = (char *)newString(v2, a2);
result = strncpy(v3, src, v2);
v3[v2 - 1] = 0;
return result;
}

canonical_decompiled_code:
char *__fastcall func9(char *src, int a2)
{
int v2; // ebx
char *v3; // rbp
char *result; // rax

v2 = 256;
if ( (int)strlen(src) > 256 )
v2 = 0x2000;
v3 = (char *)func5(v2, a2);
result = strncpy(v3, src, v2);
v3[v2 - 1] = 0;
return result;
}

original_code:
char *dupStringP(char *str_in, int type)
{
   int req_len;
   char *str_out;
   req_len = strlen(str_in);
   if (req_len <= 256)
     req_len = 256;
    else
     req_len = 8192;
    str_out = newString(req_len,type);
    strncpy(str_out,str_in,req_len);
    str_out[req_len-1] = '\0';
    return str_out;
}


plustospace

decompiled_code:
__int64 __fastcall plustospace(_BYTE *a1)
{
__int64 result; // rax

for ( result = (unsigned __int8)*a1; (_BYTE)result; result = (unsigned __int8)*a1 )
{
if ( (_BYTE)result == 43 )
*a1 = 32;
++a1;
}
return result;
}

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

for ( result = (unsigned __int8)*a1; (_BYTE)result; result = (unsigned __int8)*a1 )
{
if ( (_BYTE)result == 43 )
*a1 = 32;
++a1;
}
return result;
}

original_code:
void plustospace(char *str) {
    register int x;
    for(x=0;str[x];x++) if(str[x] == '+') str[x] = ' ';
}

variable_types:
str
char *


ind

decompiled_code:
__int64 __fastcall ind(char *a1, char a2)
{
char v2; // dl
__int64 v3; // rax
unsigned int v4; // ecx

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

canonical_decompiled_code:
__int64 __fastcall func10(char *a1, char a2)
{
char v2; // dl
__int64 v3; // rax
unsigned int v4; // ecx

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

original_code:
int ind(char *s, char c) {
    register int x;
    for(x=0;s[x];x++)
        if(s[x] == c) return x;
    return -1;
}

variable_types:
s
char *

variable_types: c char


main

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

if ( (unsigned int)(argc - 2) > 1 )
usage(*argv);
v3 = argv[argc - 1];
v4 = strlen(v3);
v5 = (char *)malloc(v4 + 1);
strcpy(v5, v3);
plustospace(v5);
unescape_url((unsigned __int8 *)v5);
if ( argc == 3 )
{
if ( strcmp(argv[1], "-e") )
usage(*argv);
escape_shell_cmd(v5);
}
printf("%s", v5);
return 0;
}

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

if ( (unsigned int)(argc - 2) > 1 )
func12(*argv);
v3 = argv[argc - 1];
v4 = strlen(v3);
v5 = (char *)malloc(v4 + 1);
strcpy(v5, v3);
func7(v5);
func9((unsigned __int8 *)v5);
if ( argc == 3 )
{
if ( strcmp(argv[1], "-e") )
func12(*argv);
func11(v5);
}
printf("%s", v5);
return 0;
}

original_code:
int main(int argc, char **argv)
{
 char pre_digest[2048];
 char digest[33];
 if (argc != 4)
 {
  fprintf(stderr, "\n%s is useful for generating the digest entries for\n", argv[0]);
  fprintf(stderr, "your .htdigest file\n\n");
  fprintf(stderr, "Usage: %s username realm password\n", argv[0]);
  exit(-1);
 }
 sprintf(pre_digest, "%s:%s:%s", argv[1], argv[2], argv[3]);
 md5(pre_digest, digest);
 printf("%s:%s:%s\n", argv[1], argv[2], digest);
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
digest
char [33]


usage

decompiled_code:
void __fastcall __noreturn usage(const char *a1)
{
fprintf(stderr, "Usage:\n%s [-e] url\n", a1);
fwrite("The -e switch automatically escapes shell characters like ^ and &\n", 1uLL, 0x42uLL, stderr);
fwrite("and url is the encoded url string\n", 1uLL, 0x22uLL, stderr);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func12(const char *a1)
{
fprintf(stderr, "Usage:\n%s [-e] url\n", a1);
fwrite("The -e switch automatically escapes shell characters like ^ and &\n", 1uLL, 0x42uLL, stderr);
fwrite("and url is the encoded url string\n", 1uLL, 0x22uLL, stderr);
exit(1);
}

original_code:
void usage(char *name) {
    fprintf(stderr,"Usage:\n%s [-e] url\n",name);
    fprintf(stderr,
"The -e switch automatically escapes shell characters like ^ and &\n");
    fprintf(stderr,"and url is the encoded url string\n");
    exit(1);
}

variable_types:
name
char *


timeout

decompiled_code:
void __fastcall __noreturn timeout(int a1)
{
longjmp(timebuf, a1);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(int a1)
{
longjmp(timebuf, a1);
}

original_code:
static void timeout(int sig)
{
    longjmp(timebuf, sig);
}

variable_types: sig int


decompiled_code:
int __fastcall bind_connect(int fd, const struct sockaddr *a2, const struct sockaddr *a3, socklen_t a4)
{
if ( bind(fd, a2, a4) >= 0 )
return connect(fd, a3, a4);
syslog(3, "bind: %m");
return -1;
}

canonical_decompiled_code:
int __fastcall func2(int fd, const struct sockaddr *a2, const struct sockaddr *a3, socklen_t a4)
{
if ( bind(fd, a2, a4) >= 0 )
return connect(fd, a3, a4);
syslog(3, "bind: %m");
return -1;
}

original_code:
int bind_connect(int s, struct sockaddr* local, struct sockaddr* remote,
       int length)
{
    if (bind(s, local, length) < 0) {
 syslog(3, "bind: %m");
 return (-1);
    } else {
 return (connect(s, remote, length));
    }
}

canonical_original_code:
int bind_connect(int s, struct sockaddr *local, struct sockaddr *remote, int length)
{
    if (bind(s, local, length) < 0) {
 syslog(3, "bind: %m");
 return (-1);
    } else {
 return (connect(s, remote, length));
    }
}

variable_types: s int

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

variable_types:
remote
struct sockaddr *