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

if ( a2 <= 0 )
{
LABEL_6:
puts("\nAppuyez sur une touche pour retourner au menu principal");
getchar();
result = 0LL;
}
else
{
v2 = 0;
while ( (unsigned int)recv(fd, v4, 0x200uLL, 0) != -1 )
{
++v2;
puts(v4);
if ( a2 == v2 )
goto LABEL_6;
}
result = 0xFFFFFFFFLL;
}
return result;
}

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

if ( a2 <= 0 )
{
LABEL_6:
puts("\nAppuyez sur une touche pour retourner au menu principal");
getchar();
result = 0LL;
}
else
{
v2 = 0;
while ( (unsigned int)recv(fd, v4, 0x200uLL, 0) != -1 )
{
++v2;
puts(v4);
if ( a2 == v2 )
goto LABEL_6;
}
result = 0xFFFFFFFFLL;
}
return result;
}

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


repo: Tombapic/YoRo

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

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

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

v4[0] = 0;
func2();
do
{
while ( 1 )
{
func2();
puts("1. Rechercher un fichier");
puts("2. Telecharger un fichier");
puts("3. Ajouter une description");
puts("4. Se deconnecter");
_isoc99_scanf("%1d", v4);
v3 = v4[0];
if ( v4[0] != 1 )
break;
v1 = func5(fd);
func6(fd, v1);
if ( v4[0] == 4 )
return 0LL;
}
if ( v4[0] == 2 )
{
func3(fd);
v3 = v4[0];
}
else if ( v4[0] == 3 )
{
func7((unsigned int)fd);
v3 = v4[0];
}
}
while ( v3 != 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: sock int

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

return_type: int

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; // er12
const char *v5; // r12
int v6; // ebp
int v7; // eax
unsigned int v8; // er13
socklen_t v9; // edx
unsigned __int16 v10; // r12
char *v11; // rax
__pid_t v12; // eax
__pid_t v13; // er12
unsigned int v14; // er13
FILE *v15; // r12
int *v16; // rax
FILE *v17; // r13
FILE *v18; // r12
unsigned int v19; // er13
FILE *v20; // r12
__pid_t v21; // eax
FILE *v22; // r12
FILE *v23; // r12
__pid_t v24; // eax
__pid_t v25; // edi
int stat_loc; // [rsp+4h] [rbp-54h] BYREF
int v27; // [rsp+8h] [rbp-50h] BYREF
socklen_t addr_len; // [rsp+Ch] [rbp-4Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-48h] BYREF
struct sockaddr in; // [rsp+20h] [rbp-38h] BYREF
struct sockaddr v31; // [rsp+30h] [rbp-28h] BYREF

if ( argc == 2 )
{
print_header(argc, argv, envp);
v5 = argv[1];
addr_len = 16;
v6 = socket(2, 1, 0);
v7 = socket(2, 1, 0);
v8 = v7;
if ( v6 == -1 || v7 == -1 )
{
v3 = 1;
puts("Erreur : echec de la creation de la socket.");
return v3;
}
addr.sa_family = 2;
*(_DWORD *)&addr.sa_data[2] = _bswap_32_constprop_0();
*(_WORD *)addr.sa_data = _bswap_16(2014);
in.sa_family = 2;
*(_DWORD *)&in.sa_data[2] = inet_addr(v5);
*(_WORD *)in.sa_data = _bswap_16(2013);
if ( connect(v8, &in, v9) == -1 )
{
v3 = 1;
puts("Erreur : echec de la connexion au serveur central.");
return v3;
}
v10 = _bswap_16(*(__int16 *)in.sa_data);
v11 = inet_ntoa(*(struct in_addr *)&in.sa_data[2]);
printf(format, v11, v10);
puts("1. S'authentifier");
puts("2. Creer un compte");
do
{
_isoc99_scanf("%1d", &v27);
v3 = v27;
}
while ( (unsigned int)(v27 - 1) > 1 );
if ( v27 == 1 )
{
if ( (((unsigned int)authenticate(v8) + 1) & 0xFFFFFFFD) == 0 )
{
puts(aErreurEchecDeL_4);
return v3;
}
}
else if ( (unsigned int)create_account(v8) == -1 )
{
v3 = 1;
puts("Erreur : echec de la creation du compte.");
return v3;
}
update_shared_files();
if ( (unsigned int)send_shared_files(v8) == -1 )
{
v3 = 1;
puts("Erreur : echec de l'envoi de la liste des fichiers partages.");
return v3;
}
send(v8, "initok", 0x200uLL, 0);
v12 = fork();
v13 = v12;
if ( v12 == -1 )
{
v3 = 0;
}
else
{
if ( v12 )
{
waitpid(-1, &stat_loc, 1);
handle_user(v8, *(_QWORD *)&in.sa_family, *(_QWORD *)&in.sa_data[6]);
if ( (unsigned int)send(v8, "disconnect", 0x200uLL, 0) != -1 )
{
close(v6);
close(v8);
v25 = v13;
v3 = 0;
kill(v25, 15);
return v3;
}
}
else
{
v14 = bind(v6, &addr, 0x10u);
v15 = fopen("log.txt", "a");
v16 = _errno_location();
fprintf(v15, "bind : %d, errno : %d\n", v14, (unsigned int)*v16);
fclose(v15);
LODWORD(v15) = listen(v6, 5);
v17 = fopen("log.txt", "a");
fprintf(v17, "listen : %d\n", (unsigned int)v15);
fclose(v17);
if ( (_DWORD)v15 == -1 )
{
v3 = 1;
puts("Erreur : echec de l'ecoute de la socket.");
return v3;
}
while ( 1 )
{
v18 = fopen("log.txt", "a");
fwrite("Attente d'un pair\n", 1uLL, 0x12uLL, v18);
fclose(v18);
v19 = accept(v6, &v31, &addr_len);
v20 = fopen("log.txt", "a");
fwrite("Accept\n", 1uLL, 7uLL, v20);
fclose(v20);
if ( v19 == -1 )
break;
v21 = fork();
if ( v21 != -1 )
{
if ( !v21 )
{
v22 = fopen("log.txt", "a");
fwrite(&unk_222, 1uLL, 0x1CuLL, v22);
fclose(v22);
handle_peer(v19, *(_QWORD *)&v31.sa_family, *(_QWORD *)&v31.sa_data[6]);
v23 = fopen("log.txt", "a");
fwrite("Fin de gestion d'un pair\n", 1uLL, 0x19uLL, v23);
fclose(v23);
close(v19);
v24 = getpid();
kill(v24, 15);
}
waitpid(-1, &stat_loc, 1);
}
}
}
v3 = 1;
}
}
else
{
v3 = 1;
puts("Utilisation : host <ip_du_serveur>");
}
return v3;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
const char *v5; // r12
int v6; // ebp
int v7; // eax
unsigned int v8; // er13
socklen_t v9; // edx
unsigned __int16 v10; // r12
char *v11; // rax
__pid_t v12; // eax
__pid_t v13; // er12
unsigned int v14; // er13
FILE *v15; // r12
int *v16; // rax
FILE *v17; // r13
FILE *v18; // r12
unsigned int v19; // er13
FILE *v20; // r12
__pid_t v21; // eax
FILE *v22; // r12
FILE *v23; // r12
__pid_t v24; // eax
__pid_t v25; // edi
int stat_loc; // [rsp+4h] [rbp-54h] BYREF
int v27; // [rsp+8h] [rbp-50h] BYREF
socklen_t addr_len; // [rsp+Ch] [rbp-4Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-48h] BYREF
struct sockaddr in; // [rsp+20h] [rbp-38h] BYREF
struct sockaddr v31; // [rsp+30h] [rbp-28h] BYREF

if ( argc == 2 )
{
print_header(argc, argv, envp);
v5 = argv[1];
addr_len = 16;
v6 = socket(2, 1, 0);
v7 = socket(2, 1, 0);
v8 = v7;
if ( v6 == -1 || v7 == -1 )
{
v3 = 1;
puts("Erreur : echec de la creation de la socket.");
return v3;
}
addr.sa_family = 2;
*(_DWORD *)&addr.sa_data[2] = func1();
*(_WORD *)addr.sa_data = func0(2014);
in.sa_family = 2;
*(_DWORD *)&in.sa_data[2] = inet_addr(v5);
*(_WORD *)in.sa_data = func0(2013);
if ( connect(v8, &in, v9) == -1 )
{
v3 = 1;
puts("Erreur : echec de la connexion au serveur central.");
return v3;
}
v10 = func0(*(__int16 *)in.sa_data);
v11 = inet_ntoa(*(struct in_addr *)&in.sa_data[2]);
printf(format, v11, v10);
puts("1. S'authentifier");
puts("2. Creer un compte");
do
{
_isoc99_scanf("%1d", &v27);
v3 = v27;
}
while ( (unsigned int)(v27 - 1) > 1 );
if ( v27 == 1 )
{
if ( (((unsigned int)authenticate(v8) + 1) & 0xFFFFFFFD) == 0 )
{
puts(aErreurEchecDeL_4);
return v3;
}
}
else if ( (unsigned int)create_account(v8) == -1 )
{
v3 = 1;
puts("Erreur : echec de la creation du compte.");
return v3;
}
update_shared_files();
if ( (unsigned int)send_shared_files(v8) == -1 )
{
v3 = 1;
puts("Erreur : echec de l'envoi de la liste des fichiers partages.");
return v3;
}
send(v8, "initok", 0x200uLL, 0);
v12 = fork();
v13 = v12;
if ( v12 == -1 )
{
v3 = 0;
}
else
{
if ( v12 )
{
waitpid(-1, &stat_loc, 1);
handle_user(v8, *(_QWORD *)&in.sa_family, *(_QWORD *)&in.sa_data[6]);
if ( (unsigned int)send(v8, "disconnect", 0x200uLL, 0) != -1 )
{
close(v6);
close(v8);
v25 = v13;
v3 = 0;
kill(v25, 15);
return v3;
}
}
else
{
v14 = bind(v6, &addr, 0x10u);
v15 = fopen("log.txt", "a");
v16 = _errno_location();
fprintf(v15, "bind : %d, errno : %d\n", v14, (unsigned int)*v16);
fclose(v15);
LODWORD(v15) = listen(v6, 5);
v17 = fopen("log.txt", "a");
fprintf(v17, "listen : %d\n", (unsigned int)v15);
fclose(v17);
if ( (_DWORD)v15 == -1 )
{
v3 = 1;
puts("Erreur : echec de l'ecoute de la socket.");
return v3;
}
while ( 1 )
{
v18 = fopen("log.txt", "a");
fwrite("Attente d'un pair\n", 1uLL, 0x12uLL, v18);
fclose(v18);
v19 = accept(v6, &v31, &addr_len);
v20 = fopen("log.txt", "a");
fwrite("Accept\n", 1uLL, 7uLL, v20);
fclose(v20);
if ( v19 == -1 )
break;
v21 = fork();
if ( v21 != -1 )
{
if ( !v21 )
{
v22 = fopen("log.txt", "a");
fwrite(&unk_222, 1uLL, 0x1CuLL, v22);
fclose(v22);
handle_peer(v19, *(_QWORD *)&v31.sa_family, *(_QWORD *)&v31.sa_data[6]);
v23 = fopen("log.txt", "a");
fwrite("Fin de gestion d'un pair\n", 1uLL, 0x19uLL, v23);
fclose(v23);
close(v19);
v24 = getpid();
kill(v24, 15);
}
waitpid(-1, &stat_loc, 1);
}
}
}
v3 = 1;
}
}
else
{
v3 = 1;
puts("Utilisation : host <ip_du_serveur>");
}
return v3;
}

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

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


decompiled_code:
__int64 __fastcall create_account(int fd)
{
char *v1; // rax
char *v2; // rax
char *v3; // rax
char *v4; // rax
bool v5; // zf
__int64 result; // 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;
if ( (unsigned int)send(fd, buf, 0x200uLL, 0) == -1 )
return 0xFFFFFFFFLL;
printf("Login ? ");
_isoc99_scanf("%14s", buf);
if ( (unsigned int)send(fd, buf, 0x200uLL, 0) == -1 )
return 0xFFFFFFFFLL;
v1 = getpass("Password ? ");
strcpy((char *)buf, v1);
v2 = crypt(key, (const char *)buf);
strcpy((char *)buf, v2);
if ( (unsigned int)send(fd, buf, 0x200uLL, 0) == -1 || (unsigned int)recv(fd, buf, 0x200uLL, 0) == -1 )
return 0xFFFFFFFFLL;
while ( 1 )
{
v5 = strcmp((const char *)buf, "addok") == 0;
result = !v5;
if ( v5 )
break;
puts("Cet identifiant existe deja dans la base, veuillez reessayer.");
printf("Login ? ");
_isoc99_scanf("%14s", buf);
if ( (unsigned int)send(fd, buf, 0x200uLL, 0) != -1 )
{
v3 = getpass("Password ? ");
strcpy((char *)buf, v3);
v4 = crypt(key, (const char *)buf);
strcpy((char *)buf, v4);
if ( (unsigned int)send(fd, buf, 0x200uLL, 0) != -1 && (unsigned int)recv(fd, buf, 0x200uLL, 0) != -1 )
continue;
}
return 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int fd)
{
char *v1; // rax
char *v2; // rax
char *v3; // rax
char *v4; // rax
bool v5; // zf
__int64 result; // 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;
if ( (unsigned int)send(fd, buf, 0x200uLL, 0) == -1 )
return 0xFFFFFFFFLL;
printf("Login ? ");
_isoc99_scanf("%14s", buf);
if ( (unsigned int)send(fd, buf, 0x200uLL, 0) == -1 )
return 0xFFFFFFFFLL;
v1 = getpass("Password ? ");
strcpy((char *)buf, v1);
v2 = crypt(key, (const char *)buf);
strcpy((char *)buf, v2);
if ( (unsigned int)send(fd, buf, 0x200uLL, 0) == -1 || (unsigned int)recv(fd, buf, 0x200uLL, 0) == -1 )
return 0xFFFFFFFFLL;
while ( 1 )
{
v5 = strcmp((const char *)buf, "addok") == 0;
result = !v5;
if ( v5 )
break;
puts("Cet identifiant existe deja dans la base, veuillez reessayer.");
printf("Login ? ");
_isoc99_scanf("%14s", buf);
if ( (unsigned int)send(fd, buf, 0x200uLL, 0) != -1 )
{
v3 = getpass("Password ? ");
strcpy((char *)buf, v3);
v4 = crypt(key, (const char *)buf);
strcpy((char *)buf, v4);
if ( (unsigned int)send(fd, buf, 0x200uLL, 0) != -1 && (unsigned int)recv(fd, buf, 0x200uLL, 0) != -1 )
continue;
}
return 0xFFFFFFFFLL;
}
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:
buf
char [512]

variable_types:
salt
char []

variable_types:
bufcrypt
char *


authenticate

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

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

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

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

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


main

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

while ( 1 )
{
readInput(&input, argv, envp);
if ( input == 35 )
break;
calc(&input);
v3 = strlen(output);
argv = (const char **)output;
if ( write(1, output, v3) == -1 )
{
v5 = getpid();
syserr("Error while passing the results through pipe [executor %d]\n", v5);
}
}
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
char v5; // al
char v6; // al

while ( 1 )
{
func8(&input, argv, envp);
if ( input == 35 )
break;
func10(&input);
v3 = strlen(output);
argv = (const char **)output;
if ( write(1, output, v3) == -1 )
{
v5 = getpid();
func11("Error while passing the results through pipe [executor %d]\n", v5);
}
}
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;
}


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: i int

variable_types: j int

variable_types: k int

variable_types: m int

variable_types: mul int

variable_types:
args
int [2]

return_type: void


syserr

decompiled_code:
void __noreturn syserr(char *format, ...)
{
int *v1; // rbx
char *v2; // rax
gcc_va_list arg; // [rsp+8h] [rbp-E0h] 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-E0h] 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);
}


inRoute

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

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

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: 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)
{
int v4; // er14
unsigned int v5; // ebx
_QWORD *v6; // r15
__int64 v7; // r12
unsigned int i; // ebp
unsigned int v9; // er12
__int64 v11; // [rsp+8h] [rbp-40h]

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

canonical_decompiled_code:
__int64 __fastcall func3(int a1, int a2, int a3, int a4)
{
int v4; // er14
unsigned int v5; // ebx
_QWORD *v6; // r15
__int64 v7; // r12
unsigned int i; // ebp
unsigned int v9; // er12
__int64 v11; // [rsp+8h] [rbp-40h]

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

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: i 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)
{
__int64 v5; // rcx
int v6; // edi
int v7; // er9
__int64 result; // rax
int v9; // er9
_DWORD *v10; // rdx

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

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

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

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


removeEdge

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

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

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
void *v1; // rdi
__int64 v2; // rbx
void *v3; // rdi

if ( graph > 0 )
{
v0 = 0LL;
do
{
v1 = *(void **)(*((_QWORD *)&graph + 1) + 8 * v0++);
free(v1);
}
while ( graph > (int)v0 );
}
if ( *(&graph + 1) > 0 )
{
v2 = 0LL;
do
{
v3 = *(void **)(*((_QWORD *)&graph + 2) + 8 * v2++);
free(v3);
}
while ( *(&graph + 1) > (int)v2 );
}
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 || 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 || 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)
{
__int64 v3; // rax

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

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

if ( a3 <= 0 )
return 0LL;
v3 = (__int64)&a1[a3 - 1 + 1];
while ( *a1 != a2 )
{
if ( ++a1 == (_DWORD *)v3 )
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

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(&free_list, 0x2000, 5);
allocate_strings(&free_list, 256, 5);
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
*((_DWORD *)&free_list + 2) = 0;
free_list = 0LL;
*((_DWORD *)&used_list + 2) = 0;
used_list = 0LL;
func0(&free_list, 0x2000, 5);
func0(&free_list, 256, 5);
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


decompiled_code:
__int64 __fastcall add_string_item(__int64 a1, __int64 a2)
{
int v2; // eax
__int64 result; // rax

v2 = *(_DWORD *)(a1 + 8);
if ( v2 )
{
*(_QWORD *)(a2 + 16) = *(_QWORD *)a1;
*(_DWORD *)(a1 + 8) = v2 + 1;
result = 1LL;
*(_QWORD *)a1 = a2;
}
else
{
*(_QWORD *)a1 = a2;
result = 1LL;
*(_DWORD *)(a1 + 8) = 1;
}
return result;
}

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)
{
int v3; // edx
int v4; // edx
__int64 v5; // rsi
int v6; // eax
__int64 result; // rax
__int64 *v8; // rax

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

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

v3 = *((_DWORD *)&free_list + 2);
if ( !v3 )
{
if ( a1 == 0x2000 || (v4 = 1, a1 == 256) )
v4 = 5;
func0(&free_list, a1, v4);
v3 = *((_DWORD *)&free_list + 2);
}
v5 = free_list;
if ( v3 <= 0 )
{
LABEL_10:
func0(&used_list, a1, 1);
v8 = (__int64 *)used_list;
*(_DWORD *)(used_list + 12) = a2;
result = *v8;
}
else
{
v6 = 0;
while ( *(_DWORD *)(v5 + 8) != a1 )
{
++v6;
v5 = *(_QWORD *)(v5 + 16);
if ( v3 == v6 )
goto LABEL_10;
}
func3(&free_list, v5);
func4((__int64)&used_list, v5);
*(_DWORD *)(v5 + 12) = a2;
result = *(_QWORD *)v5;
}
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

return_type: char *


freeString

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

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

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

if ( !a1 )
return 0LL;
v1 = *((_DWORD *)&used_list + 2);
v2 = (_QWORD *)used_list;
if ( v1 <= 0 )
{
LABEL_7:
log_error("Attempt to Free String not in Use", *(_QWORD *)(gConfiguration + 96LL));
result = 0LL;
}
else
{
v3 = 0;
while ( (_BYTE *)*v2 != a1 )
{
++v3;
v2 = (_QWORD *)v2[2];
if ( v3 == v1 )
goto LABEL_7;
}
*a1 = 0;
func3(&used_list, (__int64)v2);
func4((__int64)&free_list, (__int64)v2);
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)
{
int v1; // ecx
__int64 v2; // rax
int v3; // edx

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

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

if ( !a1 )
return 0xFFFFFFFFLL;
v1 = *((_DWORD *)&used_list + 2);
v2 = used_list;
if ( v1 <= 0 )
return 0xFFFFFFFFLL;
v3 = 0;
while ( *(_QWORD *)v2 != a1 )
{
++v3;
v2 = *(_QWORD *)(v2 + 16);
if ( v3 == v1 )
return 0xFFFFFFFFLL;
}
return *(unsigned int *)(v2 + 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 v3; // r8
__int64 v4; // rax

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

canonical_decompiled_code:
__int64 __fastcall func8(int a1)
{
__int64 v1; // rsi
__int64 v3; // r8
__int64 v4; // rax

v1 = used_list;
if ( *((_DWORD *)&used_list + 2) && used_list )
{
v3 = 0LL;
do
{
if ( *(_DWORD *)(v1 + 12) <= a1 )
{
**(_BYTE **)v1 = 0;
v4 = *(_QWORD *)(v1 + 16);
if ( used_list == v1 )
{
*(_QWORD *)(v1 + 16) = 0LL;
--*((_DWORD *)&used_list + 2);
used_list = v4;
func4((__int64)&free_list, v1);
v1 = used_list;
}
else
{
--*((_DWORD *)&used_list + 2);
*(_QWORD *)(v3 + 16) = v4;
func4((__int64)&free_list, v1);
v1 = *(_QWORD *)(v3 + 16);
}
if ( !*((_DWORD *)&used_list + 2) )
return 1LL;
}
else
{
v3 = v1;
v1 = *(_QWORD *)(v1 + 16);
if ( !*((_DWORD *)&used_list + 2) )
return 1LL;
}
}
while ( 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)
{
size_t v2; // r12
__int64 v4; // rbx
int v5; // eax
int v6; // edi
char *v7; // rax
char *result; // rax

v2 = 256LL;
v4 = 255LL;
v5 = strlen(src);
v6 = 256;
if ( v5 >= 257 )
v4 = 0x1FFFLL;
if ( v5 >= 257 )
{
v2 = 0x2000LL;
v6 = 0x2000;
}
v7 = (char *)newString(v6, a2);
result = strncpy(v7, src, v2);
result[v4] = 0;
return result;
}

canonical_decompiled_code:
char *__fastcall func9(char *src, int a2)
{
size_t v2; // r12
__int64 v4; // rbx
int v5; // eax
int v6; // edi
char *v7; // rax
char *result; // rax

v2 = 256LL;
v4 = 255LL;
v5 = strlen(src);
v6 = 256;
if ( v5 >= 257 )
v4 = 0x1FFFLL;
if ( v5 >= 257 )
{
v2 = 0x2000LL;
v6 = 0x2000;
}
v7 = (char *)func5(v6, a2);
result = strncpy(v7, src, v2);
result[v4] = 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;
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // r13
const char *v4; // r14
size_t v5; // r12
void *v6; // rbp

v3 = argv;
if ( (unsigned int)(argc - 2) > 1 )
goto LABEL_6;
v4 = argv[argc - 1];
v5 = strlen(v4) + 1;
v6 = malloc(v5);
memcpy(v6, v4, v5);
plustospace(v6);
unescape_url(v6);
if ( argc == 3 )
{
argv = (const char **)"-e";
if ( !strcmp(v3[1], "-e") )
{
escape_shell_cmd(v6);
goto LABEL_5;
}
LABEL_6:
usage(*v3, argv, envp);
}
LABEL_5:
printf("%s", (const char *)v6);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // r13
const char *v4; // r14
size_t v5; // r12
void *v6; // rbp

v3 = argv;
if ( (unsigned int)(argc - 2) > 1 )
goto LABEL_6;
v4 = argv[argc - 1];
v5 = strlen(v4) + 1;
v6 = malloc(v5);
memcpy(v6, v4, v5);
func7(v6);
func9(v6);
if ( argc == 3 )
{
argv = (const char **)"-e";
if ( !strcmp(v3[1], "-e") )
{
func11(v6);
goto LABEL_5;
}
LABEL_6:
func12(*v3, argv, envp);
}
LABEL_5:
printf("%s", (const char *)v6);
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]


plustospace

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

while ( 1 )
{
result = (unsigned __int8)*a1;
if ( !(_BYTE)result )
break;
if ( (_BYTE)result == 43 )
*a1 = 32;
++a1;
}
return result;
}

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

while ( 1 )
{
result = (unsigned __int8)*a1;
if ( !(_BYTE)result )
break;
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 result; // rax

v2 = *a1;
if ( !*a1 )
return 0xFFFFFFFFLL;
result = 0LL;
while ( a2 != v2 )
{
v2 = a1[++result];
if ( !v2 )
return 0xFFFFFFFFLL;
}
return (unsigned int)result;
}

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

v2 = *a1;
if ( !*a1 )
return 0xFFFFFFFFLL;
result = 0LL;
while ( a2 != v2 )
{
v2 = a1[++result];
if ( !v2 )
return 0xFFFFFFFFLL;
}
return (unsigned int)result;
}

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


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 func3(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 *


decompiled_code:
void __noreturn dump_form()
{
printf("<TITLE>Form for Submarine Order</TITLE>%c", 10LL);
printf("
Jimmy John's Submarine Order Form
%c", 10LL);
printf("This form will send a faxed order to Jimmy John's in Champaign. Proper password is requred%c", 10LL);
printf("for order to be submitted, otherwise a copy of the order that would have been submitted will%c", 10LL);
printf("will be displayed.
%c", 10LL);
printf("
%c", 10LL);
printf("<FORM ACTION=\"http://hoohoo.ncsa.uiuc.edu:80/htbin/jj\">%c", 10LL);
printf("Password: <INPUT TYPE=\"text\" NAME=\"pwd\" MAXLENGTH=\"20\">
%c", 10LL);
printf("
Sub Type
%c", 10LL);
printf("Select which you would like of the following:
%c", 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"sub\" VALUE=\"0\">%s:%c", sublist, 10LL);
printf("Smoked virginia ham and provolone cheese topped with lettuce, tomato, and mayo.
%c", 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"sub\" VALUE=\"1\">%s:%c", *(&sublist + 1), 10LL);
printf("Medium rare shaved roast beef topped with mayo, lettuce, and tomato.
%c", 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"sub\" VALUE=\"2\">%s:%c", *(&sublist + 2), 10LL);
printf("Tuna, mixed with celery, onions, and sauce, topped with lettuce,%c", 10LL);
printf("tomato, and alfalfa sprouts.
%c", 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"sub\" VALUE=\"3\">%s:%c", *(&sublist + 3), 10LL);
printf("Turkey breast topped with lettuce, mayo, alfalfa sprouts, and mayo.
%c", 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"sub\" VALUE=\"4\">%s:%c", *(&sublist + 4), 10LL);
printf(
"Genoa salami and provolone cheese topped with capacola, onion, lettuce, tomato, and Italian sauce.
%c",
10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"sub\" VALUE=\"5\">%s:%c", *(&sublist + 5), 10LL);
printf("Layers of provolone cheese, separated by avocado, sprouts, lettuce, tomato, and mayo.
%c", 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"sub\" VALUE=\"6\">%s:%c", *(&sublist + 6), 10LL);
printf("1/4 pound of smoked ham, provolone cheese, topped with lettuce,%c", 10LL);
printf("tomato, and mayo.
%c", 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"sub\" VALUE=\"7\">%s:%c", *(&sublist + 7), 10LL);
printf("Shaved roast beef, provolone cheese, french dijon mustard, topped with shaved ham, lettuce,%c", 10LL);
printf("tomato, and mayo.
%c", 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"sub\" VALUE=\"8\">%s:%c", *(&sublist + 8), 10LL);
printf("Genoa salami, Italian capacola, smoked ham, and provolone cheese topped with lettuce,%c", 10LL);
printf("tomato, onions, mayo, and Italian sauce.
%c", 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"sub\" VALUE=\"9\">%s:%c", *(&sublist + 9), 10LL);
printf("1/4 pound of sliced roast beef, provolone cheese, topped with lettuce, tomato, and mayo.
%c", 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"sub\" VALUE=\"10\">%s:%c", *(&sublist + 10), 10LL);
printf("Turkey breast, smoked ham, and provolonecheese topped with lettuce, tomato, and mayo.
%c", 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"sub\" VALUE=\"11\">%s:%c", *(&sublist + 11), 10LL);
printf("Turkey breast, avocado, and cheese topped with lettuce, mayo, alfalfa, and tomato.
%c", 10LL);
printf("
Slim Jim Subs
%c", 10LL);
printf("Subs without veggies or sauce.
%c", 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"slj\" VALUE=\"0\">%s
%c", slimlist[0], 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"slj\" VALUE=\"1\">%s
%c", slimlist[1], 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"slj\" VALUE=\"2\">%s
%c", slimlist[2], 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"slj\" VALUE=\"3\">%s
%c", slimlist[3], 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"slj\" VALUE=\"4\">%s
%c", slimlist[4], 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"slj\" VALUE=\"5\">%s
%c", slimlist[5], 10LL);
printf("
Side orders
%c", 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"sde\" VALUE=\"0\">%s
%c", sidelist[0], 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"sde\" VALUE=\"1\">%s
%c", sidelist[1], 10LL);
printf("
Drinks
%c", 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"pop\" VALUE=\"0\">%s
%c", poplist[0], 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"pop\" VALUE=\"1\">%s
%c", poplist[1], 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"pop\" VALUE=\"2\">%s
%c", poplist[2], 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"pop\" VALUE=\"3\">%s
%c", poplist[3], 10LL);
printf("
Your Address, Phone Number, and Name
%c", 10LL);
printf("<INPUT TYPE=\"text\" NAME=\"name\" MAXLENGTH=\"32\">Name
%c", 10LL);
printf("<INPUT TYPE=\"text\" NAME=\"adr\" MAXLENGTH=\"64\">Address
%c", 10LL);
printf("<INPUT TYPE=\"text\" NAME=\"phone\" MAXLENGTH=\"10\">Phone Number
%c", 10LL);
printf("<INPUT type=\"submit\">%c", 10LL);
printf("</FORM>%c", 10LL);
exit(0);
}

canonical_decompiled_code:
void __noreturn func0()
{
printf("<TITLE>Form for Submarine Order</TITLE>%c", 10LL);
printf("
Jimmy John's Submarine Order Form
%c", 10LL);
printf("This form will send a faxed order to Jimmy John's in Champaign. Proper password is requred%c", 10LL);
printf("for order to be submitted, otherwise a copy of the order that would have been submitted will%c", 10LL);
printf("will be displayed.
%c", 10LL);
printf("
%c", 10LL);
printf("<FORM ACTION=\"http://hoohoo.ncsa.uiuc.edu:80/htbin/jj\">%c", 10LL);
printf("Password: <INPUT TYPE=\"text\" NAME=\"pwd\" MAXLENGTH=\"20\">
%c", 10LL);
printf("
Sub Type
%c", 10LL);
printf("Select which you would like of the following:
%c", 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"sub\" VALUE=\"0\">%s:%c", sublist, 10LL);
printf("Smoked virginia ham and provolone cheese topped with lettuce, tomato, and mayo.
%c", 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"sub\" VALUE=\"1\">%s:%c", *(&sublist + 1), 10LL);
printf("Medium rare shaved roast beef topped with mayo, lettuce, and tomato.
%c", 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"sub\" VALUE=\"2\">%s:%c", *(&sublist + 2), 10LL);
printf("Tuna, mixed with celery, onions, and sauce, topped with lettuce,%c", 10LL);
printf("tomato, and alfalfa sprouts.
%c", 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"sub\" VALUE=\"3\">%s:%c", *(&sublist + 3), 10LL);
printf("Turkey breast topped with lettuce, mayo, alfalfa sprouts, and mayo.
%c", 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"sub\" VALUE=\"4\">%s:%c", *(&sublist + 4), 10LL);
printf(
"Genoa salami and provolone cheese topped with capacola, onion, lettuce, tomato, and Italian sauce.
%c",
10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"sub\" VALUE=\"5\">%s:%c", *(&sublist + 5), 10LL);
printf("Layers of provolone cheese, separated by avocado, sprouts, lettuce, tomato, and mayo.
%c", 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"sub\" VALUE=\"6\">%s:%c", *(&sublist + 6), 10LL);
printf("1/4 pound of smoked ham, provolone cheese, topped with lettuce,%c", 10LL);
printf("tomato, and mayo.
%c", 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"sub\" VALUE=\"7\">%s:%c", *(&sublist + 7), 10LL);
printf("Shaved roast beef, provolone cheese, french dijon mustard, topped with shaved ham, lettuce,%c", 10LL);
printf("tomato, and mayo.
%c", 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"sub\" VALUE=\"8\">%s:%c", *(&sublist + 8), 10LL);
printf("Genoa salami, Italian capacola, smoked ham, and provolone cheese topped with lettuce,%c", 10LL);
printf("tomato, onions, mayo, and Italian sauce.
%c", 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"sub\" VALUE=\"9\">%s:%c", *(&sublist + 9), 10LL);
printf("1/4 pound of sliced roast beef, provolone cheese, topped with lettuce, tomato, and mayo.
%c", 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"sub\" VALUE=\"10\">%s:%c", *(&sublist + 10), 10LL);
printf("Turkey breast, smoked ham, and provolonecheese topped with lettuce, tomato, and mayo.
%c", 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"sub\" VALUE=\"11\">%s:%c", *(&sublist + 11), 10LL);
printf("Turkey breast, avocado, and cheese topped with lettuce, mayo, alfalfa, and tomato.
%c", 10LL);
printf("
Slim Jim Subs
%c", 10LL);
printf("Subs without veggies or sauce.
%c", 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"slj\" VALUE=\"0\">%s
%c", slimlist[0], 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"slj\" VALUE=\"1\">%s
%c", slimlist[1], 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"slj\" VALUE=\"2\">%s
%c", slimlist[2], 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"slj\" VALUE=\"3\">%s
%c", slimlist[3], 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"slj\" VALUE=\"4\">%s
%c", slimlist[4], 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"slj\" VALUE=\"5\">%s
%c", slimlist[5], 10LL);
printf("
Side orders
%c", 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"sde\" VALUE=\"0\">%s
%c", sidelist[0], 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"sde\" VALUE=\"1\">%s
%c", sidelist[1], 10LL);
printf("
Drinks
%c", 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"pop\" VALUE=\"0\">%s
%c", poplist[0], 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"pop\" VALUE=\"1\">%s
%c", poplist[1], 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"pop\" VALUE=\"2\">%s
%c", poplist[2], 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"pop\" VALUE=\"3\">%s
%c", poplist[3], 10LL);
printf("
Your Address, Phone Number, and Name
%c", 10LL);
printf("<INPUT TYPE=\"text\" NAME=\"name\" MAXLENGTH=\"32\">Name
%c", 10LL);
printf("<INPUT TYPE=\"text\" NAME=\"adr\" MAXLENGTH=\"64\">Address
%c", 10LL);
printf("<INPUT TYPE=\"text\" NAME=\"phone\" MAXLENGTH=\"10\">Phone Number
%c", 10LL);
printf("<INPUT type=\"submit\">%c", 10LL);
printf("</FORM>%c", 10LL);
exit(0);
}

original_code:
void dump_form() {
    printf("<TITLE>Form for Submarine Order</TITLE>%c",10);
    printf("
Jimmy John's Submarine Order Form
%c",10);
    printf("This form will send a faxed order to Jimmy John's in Champaign. Proper password is requred%c",10);
    printf("for order to be submitted, otherwise a copy of the order that would have been submitted will%c",10);
    printf("will be displayed.
%c",10);
    printf("
%c",10);
    printf("<FORM ACTION=\"http://hoohoo.ncsa.uiuc.edu:80/htbin/jj\">%c",10);
    printf("Password: <INPUT TYPE=\"text\" NAME=\"pwd\" MAXLENGTH=\"20\">
%c",10);
    printf("
Sub Type
%c",10);
    printf("Select which you would like of the following:
%c",10);
    printf("<INPUT TYPE=\"checkbox\" NAME=\"sub\" VALUE=\"0\">%s:%c",sublist[0],10);
    printf("Smoked virginia ham and provolone cheese topped with lettuce, tomato, and mayo.
%c",10);
    printf("<INPUT TYPE=\"checkbox\" NAME=\"sub\" VALUE=\"1\">%s:%c",sublist[1],10);
    printf("Medium rare shaved roast beef topped with mayo, lettuce, and tomato.
%c",10);
    printf("<INPUT TYPE=\"checkbox\" NAME=\"sub\" VALUE=\"2\">%s:%c",sublist[2],10);
    printf("Tuna, mixed with celery, onions, and sauce, topped with lettuce,%c",10);
    printf("tomato, and alfalfa sprouts.
%c",10);
    printf("<INPUT TYPE=\"checkbox\" NAME=\"sub\" VALUE=\"3\">%s:%c",sublist[3],10);
    printf("Turkey breast topped with lettuce, mayo, alfalfa sprouts, and mayo.
%c",10);
    printf("<INPUT TYPE=\"checkbox\" NAME=\"sub\" VALUE=\"4\">%s:%c",sublist[4],10);
    printf("Genoa salami and provolone cheese topped with capacola, onion, lettuce, tomato, and Italian sauce.
%c",10);
    printf("<INPUT TYPE=\"checkbox\" NAME=\"sub\" VALUE=\"5\">%s:%c",sublist[5],10);
    printf("Layers of provolone cheese, separated by avocado, sprouts, lettuce, tomato, and mayo.
%c",10);
    printf("<INPUT TYPE=\"checkbox\" NAME=\"sub\" VALUE=\"6\">%s:%c",sublist[6],10);
    printf("1/4 pound of smoked ham, provolone cheese, topped with lettuce,%c",10);
    printf("tomato, and mayo.
%c",10);
    printf("<INPUT TYPE=\"checkbox\" NAME=\"sub\" VALUE=\"7\">%s:%c",sublist[7],10);
    printf("Shaved roast beef, provolone cheese, french dijon mustard, topped with shaved ham, lettuce,%c",10);
    printf("tomato, and mayo.
%c",10);
    printf("<INPUT TYPE=\"checkbox\" NAME=\"sub\" VALUE=\"8\">%s:%c",sublist[8],10);
    printf("Genoa salami, Italian capacola, smoked ham, and provolone cheese topped with lettuce,%c",10);
    printf("tomato, onions, mayo, and Italian sauce.
%c",10);
    printf("<INPUT TYPE=\"checkbox\" NAME=\"sub\" VALUE=\"9\">%s:%c",sublist[9],10);
    printf("1/4 pound of sliced roast beef, provolone cheese, topped with lettuce, tomato, and mayo.
%c",10);
    printf("<INPUT TYPE=\"checkbox\" NAME=\"sub\" VALUE=\"10\">%s:%c",sublist[10],10);
    printf("Turkey breast, smoked ham, and provolonecheese topped with lettuce, tomato, and mayo.
%c",10);
    printf("<INPUT TYPE=\"checkbox\" NAME=\"sub\" VALUE=\"11\">%s:%c",sublist[11],10);
    printf("Turkey breast, avocado, and cheese topped with lettuce, mayo, alfalfa, and tomato.
%c",10);
    printf("
Slim Jim Subs
%c",10);
    printf("Subs without veggies or sauce.
%c",10);
    printf("<INPUT TYPE=\"checkbox\" NAME=\"slj\" VALUE=\"0\">%s
%c",slimlist[0],10);
    printf("<INPUT TYPE=\"checkbox\" NAME=\"slj\" VALUE=\"1\">%s
%c",slimlist[1],10);
    printf("<INPUT TYPE=\"checkbox\" NAME=\"slj\" VALUE=\"2\">%s
%c",slimlist[2],10);
    printf("<INPUT TYPE=\"checkbox\" NAME=\"slj\" VALUE=\"3\">%s
%c",slimlist[3],10);
    printf("<INPUT TYPE=\"checkbox\" NAME=\"slj\" VALUE=\"4\">%s
%c",slimlist[4],10);
    printf("<INPUT TYPE=\"checkbox\" NAME=\"slj\" VALUE=\"5\">%s
%c",slimlist[5],10);
    printf("
Side orders
%c",10);
    printf("<INPUT TYPE=\"checkbox\" NAME=\"sde\" VALUE=\"0\">%s
%c",sidelist[0],10);
    printf("<INPUT TYPE=\"checkbox\" NAME=\"sde\" VALUE=\"1\">%s
%c",sidelist[1],10);
    printf("
Drinks
%c",10);
    printf("<INPUT TYPE=\"checkbox\" NAME=\"pop\" VALUE=\"0\">%s
%c",poplist[0],10);
    printf("<INPUT TYPE=\"checkbox\" NAME=\"pop\" VALUE=\"1\">%s
%c",poplist[1],10);
    printf("<INPUT TYPE=\"checkbox\" NAME=\"pop\" VALUE=\"2\">%s
%c",poplist[2],10);
    printf("<INPUT TYPE=\"checkbox\" NAME=\"pop\" VALUE=\"3\">%s
%c",poplist[3],10);
    printf("
Your Address, Phone Number, and Name
%c",10);
    printf("<INPUT TYPE=\"text\" NAME=\"name\" MAXLENGTH=\"32\">Name
%c",10);
    printf("<INPUT TYPE=\"text\" NAME=\"adr\" MAXLENGTH=\"64\">Address
%c",10);
    printf("<INPUT TYPE=\"text\" NAME=\"phone\" MAXLENGTH=\"10\">Phone Number
%c",10);
    printf("<INPUT type=\"submit\">%c",10);
    printf("</FORM>%c",10);
    exit(0);
}


decompiled_code:
void __fastcall __noreturn print_error(const char *a1)
{
printf("<TITLE>Order Not Submitted</TITLE>%c", 10LL);
printf("
Order Not Submitted
%c", 10LL);
printf("Your order has not been submitted, because %s.
%c", a1, 10LL);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func1(const char *a1)
{
printf("<TITLE>Order Not Submitted</TITLE>%c", 10LL);
printf("
Order Not Submitted
%c", 10LL);
printf("Your order has not been submitted, because %s.
%c", a1, 10LL);
exit(1);
}

original_code:
void print_error(char *reason) {
    printf("<TITLE>Order Not Submitted</TITLE>%c",10);
    printf("
Order Not Submitted
%c",10);
    printf("Your order has not been submitted, because %s.
%c",reason,10);
    exit(1);
}

variable_types:
reason
char *


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
char *v3; // rax
char *v4; // rbx
_BOOL8 v5; // r14
int v6; // er15
int v7; // er13
int v8; // er12
int v9; // ebp
FILE *v10; // r14
__int64 v11; // rbx
__int64 v12; // rbx
__int64 v13; // rbx
char v14[10]; // [rsp+6h] [rbp-2C2h] BYREF
char s[32]; // [rsp+10h] [rbp-2B8h] BYREF
char v16[32]; // [rsp+30h] [rbp-298h] BYREF
char dest[64]; // [rsp+50h] [rbp-278h] BYREF
char s1[4]; // [rsp+90h] [rbp-238h] BYREF
char command[312]; // [rsp+190h] [rbp-138h] BYREF

printf("Content-type: text/html%c%c", 10LL, 10LL);
v3 = getenv("QUERY_STRING");
if ( !v3 || (v4 = v3, !*v3) )
dump_form();
tmpnam(s);
if ( fopen(s, "w") )
{
v16[0] = 0;
v14[0] = 0;
dest[0] = 0;
if ( *v4 )
{
LODWORD(v5) = 0;
v6 = 0;
v7 = 0;
v8 = 0;
v9 = 0;
do
{
getword(s1, v4, 61LL);
plustospace(s1);
unescape_url(s1);
if ( *(_DWORD *)s1 == 6584176 )
{
getword(s1, v4, 38LL);
plustospace(s1);
unescape_url(s1);
v5 = strcmp(s1, "HTTPdRocKs") == 0;
}
switch ( *(_DWORD *)s1 )
{
case 0x627573:
getword(s1, v4, 38LL);
plustospace(s1);
unescape_url(s1);
v9 |= 1 << atoi(s1);
break;
case 0x6A6C73:
getword(s1, v4, 38LL);
plustospace(s1);
unescape_url(s1);
v8 |= 1 << atoi(s1);
break;
case 0x656473:
getword(s1, v4, 38LL);
plustospace(s1);
unescape_url(s1);
v7 |= 1 << atoi(s1);
break;
default:
if ( !strcmp(s1, "pop") )
{
getword(s1, v4, 38LL);
plustospace(s1);
unescape_url(s1);
v6 |= 1 << atoi(s1);
}
else if ( !strcmp(s1, "name") )
{
getword(s1, v4, 38LL);
plustospace(s1);
unescape_url(s1);
strcpy(v16, s1);
}
else if ( !strcmp(s1, "phone") )
{
getword(s1, v4, 38LL);
plustospace(s1);
unescape_url(s1);
strcpy(v14, s1);
}
else if ( !strcmp(s1, "adr") )
{
getword(s1, v4, 38LL);
plustospace(s1);
unescape_url(s1);
strcpy(dest, s1);
}
break;
}
}
while ( *v4 );
if ( v16[0] )
{
if ( dest[0] )
{
if ( v14[0] )
{
if ( v7 | v6 | v9 | v8 )
{
if ( v5 )
{
sprintf(command, "/bin/mail %s", "JIMMY_JOHNS_5555680@fax.uiuc.edu");
v10 = popen(command, "w");
if ( !v10 )
print_error("the server was unable to open a pipe to mail");
printf("<TITLE>Order Sent</TITLE>%c", 10LL);
printf("
Order Sent
%c", 10LL);
printf("Your order has been sent to the UIUC e-mail to FAX gateway.
%c", 10LL);
}
else
{
printf("<TITLE>Your Order</TITLE>%c", 10LL);
printf("
Your Order
%c", 10LL);
printf("This is how your order would have looked if it had been sent.
<PLAINTEXT>%c", 10LL);
v10 = stdout;
}
v11 = 0LL;
fprintf(v10, "My name is %s, and I would like to have the following%c", v16, 10LL);
fprintf(v10, "order delivered to %s:%c%c", dest, 10LL, 10LL);
while ( 1 )
{
if ( ((v9 >> v11) & 1) != 0 )
fprintf(v10, "\t(1) %s%c", (&sublist)[v11], 10LL);
if ( ++v11 == 12 )
{
v12 = 0LL;
while ( 1 )
{
if ( ((v8 >> v12) & 1) != 0 )
fprintf(v10, "\t(1) %s Slim Jim%c", slimlist[v12], 10LL);
if ( ++v12 == 6 )
{
if ( (v7 & 1) != 0 )
fprintf(v10, "\t(1) %s%c", sidelist[0], 10LL);
if ( (v7 & 2) != 0 )
fprintf(v10, "\t(1) %s%c", sidelist[1], 10LL);
v13 = 0LL;
while ( 1 )
{
if ( ((v6 >> v13) & 1) != 0 )
fprintf(v10, "\t(1) %s%c", poplist[v13], 10LL);
if ( ++v13 == 4 )
{
fprintf(v10, "%cPlease feel free to call me at %s if there is any%c", 10LL, v14, 10LL);
fprintf(v10, "problem. Thank you.%c%c.%c", 10LL, 10LL, 10LL);
fclose(v10);
exit(0);
}
}
}
}
}
}
}
print_error("you didn't order anything");
}
print_error("you didn't give your phone number");
}
print_error("you didn't give your address");
}
}
print_error("you didn't give your name");
}
printf("<TITLE>Server Error</TITLE>%c", 10LL);
printf("
Server Error
%c", 10LL);
printf("Server unable to get a temporary file. Please try again later.
%c", 10LL);
exit(1);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
char *v3; // rax
char *v4; // rbx
_BOOL8 v5; // r14
int v6; // er15
int v7; // er13
int v8; // er12
int v9; // ebp
FILE *v10; // r14
__int64 v11; // rbx
__int64 v12; // rbx
__int64 v13; // rbx
char v14[10]; // [rsp+6h] [rbp-2C2h] BYREF
char s[32]; // [rsp+10h] [rbp-2B8h] BYREF
char v16[32]; // [rsp+30h] [rbp-298h] BYREF
char dest[64]; // [rsp+50h] [rbp-278h] BYREF
char s1[4]; // [rsp+90h] [rbp-238h] BYREF
char command[312]; // [rsp+190h] [rbp-138h] BYREF

printf("Content-type: text/html%c%c", 10LL, 10LL);
v3 = getenv("QUERY_STRING");
if ( !v3 || (v4 = v3, !*v3) )
func0();
tmpnam(s);
if ( fopen(s, "w") )
{
v16[0] = 0;
v14[0] = 0;
dest[0] = 0;
if ( *v4 )
{
LODWORD(v5) = 0;
v6 = 0;
v7 = 0;
v8 = 0;
v9 = 0;
do
{
getword(s1, v4, 61LL);
plustospace(s1);
unescape_url(s1);
if ( *(_DWORD *)s1 == 6584176 )
{
getword(s1, v4, 38LL);
plustospace(s1);
unescape_url(s1);
v5 = strcmp(s1, "HTTPdRocKs") == 0;
}
switch ( *(_DWORD *)s1 )
{
case 0x627573:
getword(s1, v4, 38LL);
plustospace(s1);
unescape_url(s1);
v9 |= 1 << atoi(s1);
break;
case 0x6A6C73:
getword(s1, v4, 38LL);
plustospace(s1);
unescape_url(s1);
v8 |= 1 << atoi(s1);
break;
case 0x656473:
getword(s1, v4, 38LL);
plustospace(s1);
unescape_url(s1);
v7 |= 1 << atoi(s1);
break;
default:
if ( !strcmp(s1, "pop") )
{
getword(s1, v4, 38LL);
plustospace(s1);
unescape_url(s1);
v6 |= 1 << atoi(s1);
}
else if ( !strcmp(s1, "name") )
{
getword(s1, v4, 38LL);
plustospace(s1);
unescape_url(s1);
strcpy(v16, s1);
}
else if ( !strcmp(s1, "phone") )
{
getword(s1, v4, 38LL);
plustospace(s1);
unescape_url(s1);
strcpy(v14, s1);
}
else if ( !strcmp(s1, "adr") )
{
getword(s1, v4, 38LL);
plustospace(s1);
unescape_url(s1);
strcpy(dest, s1);
}
break;
}
}
while ( *v4 );
if ( v16[0] )
{
if ( dest[0] )
{
if ( v14[0] )
{
if ( v7 | v6 | v9 | v8 )
{
if ( v5 )
{
sprintf(command, "/bin/mail %s", "JIMMY_JOHNS_5555680@fax.uiuc.edu");
v10 = popen(command, "w");
if ( !v10 )
func1("the server was unable to open a pipe to mail");
printf("<TITLE>Order Sent</TITLE>%c", 10LL);
printf("
Order Sent
%c", 10LL);
printf("Your order has been sent to the UIUC e-mail to FAX gateway.
%c", 10LL);
}
else
{
printf("<TITLE>Your Order</TITLE>%c", 10LL);
printf("
Your Order
%c", 10LL);
printf("This is how your order would have looked if it had been sent.
<PLAINTEXT>%c", 10LL);
v10 = stdout;
}
v11 = 0LL;
fprintf(v10, "My name is %s, and I would like to have the following%c", v16, 10LL);
fprintf(v10, "order delivered to %s:%c%c", dest, 10LL, 10LL);
while ( 1 )
{
if ( ((v9 >> v11) & 1) != 0 )
fprintf(v10, "\t(1) %s%c", (&sublist)[v11], 10LL);
if ( ++v11 == 12 )
{
v12 = 0LL;
while ( 1 )
{
if ( ((v8 >> v12) & 1) != 0 )
fprintf(v10, "\t(1) %s Slim Jim%c", slimlist[v12], 10LL);
if ( ++v12 == 6 )
{
if ( (v7 & 1) != 0 )
fprintf(v10, "\t(1) %s%c", sidelist[0], 10LL);
if ( (v7 & 2) != 0 )
fprintf(v10, "\t(1) %s%c", sidelist[1], 10LL);
v13 = 0LL;
while ( 1 )
{
if ( ((v6 >> v13) & 1) != 0 )
fprintf(v10, "\t(1) %s%c", poplist[v13], 10LL);
if ( ++v13 == 4 )
{
fprintf(v10, "%cPlease feel free to call me at %s if there is any%c", 10LL, v14, 10LL);
fprintf(v10, "problem. Thank you.%c%c.%c", 10LL, 10LL, 10LL);
fclose(v10);
exit(0);
}
}
}
}
}
}
}
func1("you didn't order anything");
}
func1("you didn't give your phone number");
}
func1("you didn't give your address");
}
}
func1("you didn't give your name");
}
printf("<TITLE>Server Error</TITLE>%c", 10LL);
printf("
Server Error
%c", 10LL);
printf("Server unable to get a temporary file. Please try again later.
%c", 10LL);
exit(1);
}

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