decompiled_code:
// local variable allocation has failed, the output may be wrong!
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rcx
int v4; // er15
const char **v5; // r12
unsigned int v6; // ebp
unsigned int v7; // er14
int v8; // er8
int i; // ebx
__int64 v10; // r9
bool v11; // al
bool v12; // cf
bool v13; // zf
char v14; // al
bool v15; // cf
bool v16; // zf
unsigned int v17; // ebx
void *v18; // rax
pthread_t newthread[8]; // [rsp+8h] [rbp-40h] BYREF

if ( argc <= 1 )
{
v6 = 0;
v7 = 3456;
}
else
{
v4 = argc;
v5 = argv;
v6 = 0;
v7 = 3456;
v8 = 0;
for ( i = 1; i < v4; ++i )
{
v10 = i;
if ( !strcmp(v5[v10], "-r") || !strcmp(v5[i], "--reset") )
{
reset_database();
exit(0);
}
if ( !strcmp(v5[i], "-h") || !strcmp(v5[i], "--help") )
{
stampa_help(*v5);
exit(0);
}
if ( !strcmp(v5[i], "-p") || (v11 = strcmp(v5[i], "--port") != 0, v12 = 0, v13 = !v11) )
{
++i;
v7 = atoi(v5[v10 + 1]);
v8 = 1;
}
envp = (const char **)v5[i];
*(_QWORD *)&argc = "-v";
v3 = 3LL;
argv = envp;
do
{
if ( !v3 )
break;
v12 = *(_BYTE *)argv < **(_BYTE **)&argc;
v13 = *(_BYTE *)argv == **(_BYTE **)&argc;
argv = (const char **)((char *)argv + 1);
++*(_QWORD *)&argc;
--v3;
}
while ( v13 );
v14 = (!v12 && !v13) - v12;
v15 = 0;
v16 = v14 == 0;
if ( v14 )
{
*(_QWORD *)&argc = "--verbose";
v3 = 10LL;
argv = (const char **)v5[i];
do
{
if ( !v3 )
break;
v15 = *(_BYTE *)argv < **(_BYTE **)&argc;
v16 = *(_BYTE *)argv == **(_BYTE **)&argc;
argv = (const char **)((char *)argv + 1);
++*(_QWORD *)&argc;
--v3;
}
while ( v16 );
if ( (!v15 && !v16) == v15 )
{
v6 = 1;
}
else if ( !v8 )
{
fwrite("OPZIONE NON RICONOSCIUTA.\n", 1uLL, 0x1AuLL, stdout);
stampa_help(*v5);
exit(1);
}
}
else
{
v6 = 1;
}
v8 = 1;
}
}
lista = adtl_crealista(*(_QWORD *)&argc, argv, envp, v3);
main_thread = pthread_self();
pthread_mutex_init(&scrittura, 0LL);
pthread_mutex_init(&lettura, 0LL);
pthread_mutex_init(&m_lista, 0LL);
if ( signal(2, (__sighandler_t)handler_term) != (__sighandler_t)-1LL )
{
id_socket = avvia_server(10LL, v7);
fwrite("Server avviato... premere <Control+C> per uscire.\n", 1uLL, 0x32uLL, stdout);
while ( 1 )
{
v17 = accetta_connessione((unsigned int)id_socket);
pthread_mutex_lock(&m_lista);
lista = adtl_inserisci(lista, v17, v6);
v18 = (void *)adtl_elem_addr(lista, v17);
pthread_create(newthread, 0LL, (void *(*)(void *))servi_client, v18);
pthread_mutex_unlock(&m_lista);
pthread_detach(newthread[0]);
}
}
perror("signal");
exit(1);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rcx
int v4; // er15
const char **v5; // r12
unsigned int v6; // ebp
unsigned int v7; // er14
int v8; // er8
int i; // ebx
__int64 v10; // r9
bool v11; // al
bool v12; // cf
bool v13; // zf
char v14; // al
bool v15; // cf
bool v16; // zf
unsigned int v17; // ebx
void *v18; // rax
pthread_t newthread[8]; // [rsp+8h] [rbp-40h] BYREF

if ( argc <= 1 )
{
v6 = 0;
v7 = 3456;
}
else
{
v4 = argc;
v5 = argv;
v6 = 0;
v7 = 3456;
v8 = 0;
for ( i = 1; i < v4; ++i )
{
v10 = i;
if ( !strcmp(v5[v10], "-r") || !strcmp(v5[i], "--reset") )
{
reset_database();
exit(0);
}
if ( !strcmp(v5[i], "-h") || !strcmp(v5[i], "--help") )
{
func9(*v5);
exit(0);
}
if ( !strcmp(v5[i], "-p") || (v11 = strcmp(v5[i], "--port") != 0, v12 = 0, v13 = !v11) )
{
++i;
v7 = atoi(v5[v10 + 1]);
v8 = 1;
}
envp = (const char **)v5[i];
*(_QWORD *)&argc = "-v";
v3 = 3LL;
argv = envp;
do
{
if ( !v3 )
break;
v12 = *(_BYTE *)argv < **(_BYTE **)&argc;
v13 = *(_BYTE *)argv == **(_BYTE **)&argc;
argv = (const char **)((char *)argv + 1);
++*(_QWORD *)&argc;
--v3;
}
while ( v13 );
v14 = (!v12 && !v13) - v12;
v15 = 0;
v16 = v14 == 0;
if ( v14 )
{
*(_QWORD *)&argc = "--verbose";
v3 = 10LL;
argv = (const char **)v5[i];
do
{
if ( !v3 )
break;
v15 = *(_BYTE *)argv < **(_BYTE **)&argc;
v16 = *(_BYTE *)argv == **(_BYTE **)&argc;
argv = (const char **)((char *)argv + 1);
++*(_QWORD *)&argc;
--v3;
}
while ( v16 );
if ( (!v15 && !v16) == v15 )
{
v6 = 1;
}
else if ( !v8 )
{
fwrite("OPZIONE NON RICONOSCIUTA.\n", 1uLL, 0x1AuLL, stdout);
func9(*v5);
exit(1);
}
}
else
{
v6 = 1;
}
v8 = 1;
}
}
lista = adtl_crealista(*(_QWORD *)&argc, argv, envp, v3);
main_thread = pthread_self();
pthread_mutex_init(&scrittura, 0LL);
pthread_mutex_init(&lettura, 0LL);
pthread_mutex_init(&m_lista, 0LL);
if ( signal(2, (__sighandler_t)handler_term) != (__sighandler_t)-1LL )
{
id_socket = avvia_server(10LL, v7);
fwrite("Server avviato... premere <Control+C> per uscire.\n", 1uLL, 0x32uLL, stdout);
while ( 1 )
{
v17 = accetta_connessione((unsigned int)id_socket);
pthread_mutex_lock(&m_lista);
lista = adtl_inserisci(lista, v17, v6);
v18 = (void *)adtl_elem_addr(lista, v17);
pthread_create(newthread, 0LL, (void *(*)(void *))servi_client, v18);
pthread_mutex_unlock(&m_lista);
pthread_detach(newthread[0]);
}
}
perror("signal");
exit(1);
}

user_defined_types: struct elemento { int connessione; int debug_info; }


repo: fsferrara/legacy-address-book

decompiled_code:
void __fastcall __noreturn fatal_error(unsigned int a1, __int64 a2, int a3)
{
if ( a3 )
fwrite("Errore di rete! Verificare il cavo e/o il programma client\n", 1uLL, 0x3BuLL, stdout);
pthread_mutex_lock(&m_lista);
chiudi_connessione(a1);
lista = adtl_cancella(lista, a1);
pthread_mutex_unlock(&m_lista);
pthread_exit(0LL);
}

canonical_decompiled_code:
void __fastcall __noreturn func1(unsigned int a1, __int64 a2, int a3)
{
if ( a3 )
fwrite("Errore di rete! Verificare il cavo e/o il programma client\n", 1uLL, 0x3BuLL, stdout);
pthread_mutex_lock(&m_lista);
chiudi_connessione(a1);
lista = adtl_cancella(lista, a1);
pthread_mutex_unlock(&m_lista);
pthread_exit(0LL);
}

original_code:
void fatal_error(int id_connessione, pthread_t tid, int debug) {
 if (debug)
  fprintf(stdout,"Errore di rete! Verificare il cavo e/o il programma client\n");
 pthread_mutex_lock(&m_lista);
  chiudi_connessione(id_connessione);
  lista = adtl_cancella(lista, id_connessione);
 pthread_mutex_unlock(&m_lista);
 pthread_exit(((void *)0));
}

canonical_original_code:
void fatal_error(int id_connessione, unsigned long tid, int debug) {
 if (debug)
  fprintf(stdout,"Errore di rete! Verificare il cavo e/o il programma client\n");
 pthread_mutex_lock(&m_lista);
  chiudi_connessione(id_connessione);
  lista = adtl_cancella(lista, id_connessione);
 pthread_mutex_unlock(&m_lista);
 pthread_exit(((void *)0));
}

variable_types:
tid
unsigned long

variable_types: debug int

return_type: void


decompiled_code:
__int64 __fastcall stampa_contatti(unsigned int a1, int a2)
{
unsigned int v2; // ebx
__int64 v3; // rax
pthread_t v4; // rax
__int64 result; // rax
__int64 v6; // rax
int v7; // [rsp+Ch] [rbp-11Ch] BYREF
char v8[280]; // [rsp+10h] [rbp-118h] BYREF

v7 = 0;
if ( a2 )
{
v4 = pthread_self();
fprintf(stdout, "[thread %d] stampa contatti\n", v4);
}
pthread_mutex_lock(&lettura);
if ( ++num_lettori == 1 )
pthread_mutex_lock(&scrittura);
pthread_mutex_unlock(&lettura);
v2 = apri_file_r();
while ( !(unsigned int)leggi_record(v2, v8, &v7) )
{
if ( !(unsigned int)cancellato(v8) )
{
if ( (unsigned int)trasmetti(a1, v8, 251LL) )
{
v3 = pthread_self();
fatal_error(a1, v3, a2);
}
}
}
chiudi_file(v2);
pthread_mutex_lock(&lettura);
if ( !--num_lettori )
pthread_mutex_unlock(&scrittura);
pthread_mutex_unlock(&lettura);
prendi_record_sentinella(v8);
result = trasmetti(a1, v8, 251LL);
if ( (_DWORD)result )
{
v6 = pthread_self();
fatal_error(a1, v6, a2);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1, int a2)
{
unsigned int v2; // ebx
__int64 v3; // rax
pthread_t v4; // rax
__int64 result; // rax
__int64 v6; // rax
int v7; // [rsp+Ch] [rbp-11Ch] BYREF
char v8[280]; // [rsp+10h] [rbp-118h] BYREF

v7 = 0;
if ( a2 )
{
v4 = pthread_self();
fprintf(stdout, "[thread %d] stampa contatti\n", v4);
}
pthread_mutex_lock(&lettura);
if ( ++num_lettori == 1 )
pthread_mutex_lock(&scrittura);
pthread_mutex_unlock(&lettura);
v2 = apri_file_r();
while ( !(unsigned int)leggi_record(v2, v8, &v7) )
{
if ( !(unsigned int)cancellato(v8) )
{
if ( (unsigned int)trasmetti(a1, v8, 251LL) )
{
v3 = pthread_self();
func1(a1, v3, a2);
}
}
}
chiudi_file(v2);
pthread_mutex_lock(&lettura);
if ( !--num_lettori )
pthread_mutex_unlock(&scrittura);
pthread_mutex_unlock(&lettura);
prendi_record_sentinella(v8);
result = trasmetti(a1, v8, 251LL);
if ( (_DWORD)result )
{
v6 = pthread_self();
func1(a1, v6, a2);
}
return result;
}

original_code:
void stampa_contatti(int id_connessione, int debug) {
 struct contatto buff;
 int fd, numero_fittizio=0;
 if (debug)
  fprintf(stdout,"[thread %d] stampa contatti\n", pthread_self());
 pthread_mutex_lock(&lettura);
  num_lettori++;
  if (num_lettori == 1)
   pthread_mutex_lock(&scrittura);
 pthread_mutex_unlock(&lettura);
 fd = apri_file_r();
 while(leggi_record(fd, &buff, &numero_fittizio) == 0) {
  if (!cancellato(&buff))
   if(trasmetti(id_connessione, &buff, sizeof(struct contatto)))
    fatal_error(id_connessione, pthread_self(), debug);
 }
 chiudi_file(fd);
 pthread_mutex_lock(&lettura);
  num_lettori--;
  if (num_lettori == 0)
   pthread_mutex_unlock(&scrittura);
 pthread_mutex_unlock(&lettura);
 prendi_record_sentinella(&buff);
 if(trasmetti(id_connessione, &buff, sizeof(struct contatto)))
  fatal_error(id_connessione, pthread_self(), debug);
}

canonical_original_code:
void stampa_contatti(int id_connessione, int debug) {
 struct contatto buff;
 int fd; int numero_fittizio = 0;
 if (debug)
  fprintf(stdout,"[thread %d] stampa contatti\n", pthread_self());
 pthread_mutex_lock(&lettura);
  num_lettori++;
  if (num_lettori == 1)
   pthread_mutex_lock(&scrittura);
 pthread_mutex_unlock(&lettura);
 fd = apri_file_r();
 while(leggi_record(fd, &buff, &numero_fittizio) == 0) {
  if (!cancellato(&buff))
   if(trasmetti(id_connessione, &buff, sizeof(struct contatto)))
    fatal_error(id_connessione, pthread_self(), debug);
 }
 chiudi_file(fd);
 pthread_mutex_lock(&lettura);
  num_lettori--;
  if (num_lettori == 0)
   pthread_mutex_unlock(&scrittura);
 pthread_mutex_unlock(&lettura);
 prendi_record_sentinella(&buff);
 if(trasmetti(id_connessione, &buff, sizeof(struct contatto)))
  fatal_error(id_connessione, pthread_self(), debug);
}

variable_types: struct contatto { char nome[40]; char cognome[40]; char indirizzo[90]; char telefono[40]; char email[40]; char marcatura; }

variable_types: fd int


decompiled_code:
__int64 __fastcall cerca_contatto(__int64 a1, int a2)
{
unsigned int v2; // ebx
__int64 v3; // rax
pthread_t v4; // rbx
__int64 v5; // rax
__int64 result; // rax
__int64 v7; // rax
int v8; // [rsp+Ch] [rbp-21Ch] BYREF
char v9[256]; // [rsp+10h] [rbp-218h] BYREF
char v10[280]; // [rsp+110h] [rbp-118h] BYREF

v8 = 0;
if ( !a2 )
{
if ( !(unsigned int)ricevi(a1, v10, 251LL) )
goto LABEL_3;
LABEL_12:
v5 = pthread_self();
fatal_error(a1, v5, a2);
}
v4 = pthread_self();
fprintf(stdout, "[thread %d] cerca contatto\n", v4);
if ( (unsigned int)ricevi((unsigned int)a1, v10, 251LL) )
goto LABEL_12;
fprintf(stdout, "-------------Ricevuto record da %d:\n", v4);
stampa_record(v10);
fwrite("Fine record-----------------------------\n", 1uLL, 0x29uLL, stdout);
LABEL_3:
pthread_mutex_lock(&lettura);
if ( ++num_lettori == 1 )
pthread_mutex_lock(&scrittura);
pthread_mutex_unlock(&lettura);
v2 = apri_file_r();
while ( !(unsigned int)leggi_record(v2, v9, &v8) )
{
if ( (unsigned int)idoneo(v10, v9) == 1 )
{
if ( (unsigned int)trasmetti((unsigned int)a1, v9, 251LL) )
{
v3 = pthread_self();
fatal_error(a1, v3, a2);
}
}
}
chiudi_file(v2);
pthread_mutex_lock(&lettura);
if ( !--num_lettori )
pthread_mutex_unlock(&scrittura);
pthread_mutex_unlock(&lettura);
prendi_record_sentinella(v9);
result = trasmetti((unsigned int)a1, v9, 251LL);
if ( (_DWORD)result )
{
v7 = pthread_self();
fatal_error(a1, v7, a2);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int a2)
{
unsigned int v2; // ebx
__int64 v3; // rax
pthread_t v4; // rbx
__int64 v5; // rax
__int64 result; // rax
__int64 v7; // rax
int v8; // [rsp+Ch] [rbp-21Ch] BYREF
char v9[256]; // [rsp+10h] [rbp-218h] BYREF
char v10[280]; // [rsp+110h] [rbp-118h] BYREF

v8 = 0;
if ( !a2 )
{
if ( !(unsigned int)ricevi(a1, v10, 251LL) )
goto LABEL_3;
LABEL_12:
v5 = pthread_self();
func1(a1, v5, a2);
}
v4 = pthread_self();
fprintf(stdout, "[thread %d] cerca contatto\n", v4);
if ( (unsigned int)ricevi((unsigned int)a1, v10, 251LL) )
goto LABEL_12;
fprintf(stdout, "-------------Ricevuto record da %d:\n", v4);
stampa_record(v10);
fwrite("Fine record-----------------------------\n", 1uLL, 0x29uLL, stdout);
LABEL_3:
pthread_mutex_lock(&lettura);
if ( ++num_lettori == 1 )
pthread_mutex_lock(&scrittura);
pthread_mutex_unlock(&lettura);
v2 = apri_file_r();
while ( !(unsigned int)leggi_record(v2, v9, &v8) )
{
if ( (unsigned int)idoneo(v10, v9) == 1 )
{
if ( (unsigned int)trasmetti((unsigned int)a1, v9, 251LL) )
{
v3 = pthread_self();
func1(a1, v3, a2);
}
}
}
chiudi_file(v2);
pthread_mutex_lock(&lettura);
if ( !--num_lettori )
pthread_mutex_unlock(&scrittura);
pthread_mutex_unlock(&lettura);
prendi_record_sentinella(v9);
result = trasmetti((unsigned int)a1, v9, 251LL);
if ( (_DWORD)result )
{
v7 = pthread_self();
func1(a1, v7, a2);
}
return result;
}

original_code:
void cerca_contatto(int id_connessione, int debug) {
 struct contatto cerca;
 struct contatto buff;
 int fd, numero_fittizio=0;
 if (debug)
  fprintf(stdout,"[thread %d] cerca contatto\n", pthread_self());
 if(ricevi(id_connessione, &cerca, sizeof(struct contatto)))
  fatal_error(id_connessione, pthread_self(), debug);
 if (debug) {
  fprintf(stdout,"-------------Ricevuto record da %d:\n", pthread_self());
  stampa_record(&cerca);
  fprintf(stdout,"Fine record-----------------------------\n");
 }
 pthread_mutex_lock(&lettura);
  num_lettori++;
  if (num_lettori == 1)
   pthread_mutex_lock(&scrittura);
 pthread_mutex_unlock(&lettura);
 fd = apri_file_r();
 while(leggi_record(fd, &buff, &numero_fittizio) == 0) {
  if (idoneo(&cerca, &buff) == 1)
   if(trasmetti(id_connessione, &buff, sizeof(struct contatto)))
    fatal_error(id_connessione, pthread_self(), debug);
 }
 chiudi_file(fd);
 pthread_mutex_lock(&lettura);
  num_lettori--;
  if (num_lettori == 0)
   pthread_mutex_unlock(&scrittura);
 pthread_mutex_unlock(&lettura);
 prendi_record_sentinella(&buff);
 if(trasmetti(id_connessione, &buff, sizeof(struct contatto)))
  fatal_error(id_connessione, pthread_self(), debug);
}

canonical_original_code:
void cerca_contatto(int id_connessione, int debug) {
 struct contatto cerca;
 struct contatto buff;
 int fd; int numero_fittizio = 0;
 if (debug)
  fprintf(stdout,"[thread %d] cerca contatto\n", pthread_self());
 if(ricevi(id_connessione, &cerca, sizeof(struct contatto)))
  fatal_error(id_connessione, pthread_self(), debug);
 if (debug) {
  fprintf(stdout,"-------------Ricevuto record da %d:\n", pthread_self());
  stampa_record(&cerca);
  fprintf(stdout,"Fine record-----------------------------\n");
 }
 pthread_mutex_lock(&lettura);
  num_lettori++;
  if (num_lettori == 1)
   pthread_mutex_lock(&scrittura);
 pthread_mutex_unlock(&lettura);
 fd = apri_file_r();
 while(leggi_record(fd, &buff, &numero_fittizio) == 0) {
  if (idoneo(&cerca, &buff) == 1)
   if(trasmetti(id_connessione, &buff, sizeof(struct contatto)))
    fatal_error(id_connessione, pthread_self(), debug);
 }
 chiudi_file(fd);
 pthread_mutex_lock(&lettura);
  num_lettori--;
  if (num_lettori == 0)
   pthread_mutex_unlock(&scrittura);
 pthread_mutex_unlock(&lettura);
 prendi_record_sentinella(&buff);
 if(trasmetti(id_connessione, &buff, sizeof(struct contatto)))
  fatal_error(id_connessione, pthread_self(), debug);
}

user_defined_types: struct contatto { char nome[40]; char cognome[40]; char indirizzo[90]; char telefono[40]; char email[40]; char marcatura; }


decompiled_code:
int __fastcall modifica_contatto(unsigned int a1, int a2)
{
int v2; // er12
int v3; // eax
int result; // eax
pthread_t v5; // rax
__int64 v6; // rax
__int64 v7; // rax
__int64 v8; // rax
__int64 v9; // rax
__int64 v10; // rax
_BYTE v11[256]; // [rsp+0h] [rbp-168h] BYREF
char v12[104]; // [rsp+100h] [rbp-68h] BYREF

if ( a2 )
{
v5 = pthread_self();
fprintf(stdout, "[thread %d] modifica contatto\n", v5);
}
if ( (unsigned int)ricevi(a1, v12, 80LL) )
{
v6 = pthread_self();
fatal_error(a1, v6, a2);
}
pthread_mutex_lock(&lettura);
if ( ++num_lettori == 1 )
pthread_mutex_lock(&scrittura);
pthread_mutex_unlock(&lettura);
v2 = trova_record(v12);
pthread_mutex_lock(&lettura);
if ( !--num_lettori )
pthread_mutex_unlock(&scrittura);
pthread_mutex_unlock(&lettura);
if ( v2 < 0 )
{
result = trasmetti_opzione(a1, 105LL);
if ( result )
{
v10 = pthread_self();
fatal_error(a1, v10, a2);
}
}
else
{
if ( (unsigned int)trasmetti_opzione(a1, 104LL) )
{
v7 = pthread_self();
fatal_error(a1, v7, a2);
}
if ( (unsigned int)ricevi(a1, v11, 251LL) )
{
v8 = pthread_self();
fatal_error(a1, v8, a2);
}
pthread_mutex_lock(&scrittura);
v3 = modifica_record(v11, v12);
if ( (unsigned int)trasmetti_opzione(a1, 104 - ((unsigned int)(v3 == 0) - 1)) )
{
v9 = pthread_self();
fatal_error(a1, v9, a2);
}
result = pthread_mutex_unlock(&scrittura);
}
return result;
}

canonical_decompiled_code:
int __fastcall func4(unsigned int a1, int a2)
{
int v2; // er12
int v3; // eax
int result; // eax
pthread_t v5; // rax
__int64 v6; // rax
__int64 v7; // rax
__int64 v8; // rax
__int64 v9; // rax
__int64 v10; // rax
_BYTE v11[256]; // [rsp+0h] [rbp-168h] BYREF
char v12[104]; // [rsp+100h] [rbp-68h] BYREF

if ( a2 )
{
v5 = pthread_self();
fprintf(stdout, "[thread %d] modifica contatto\n", v5);
}
if ( (unsigned int)ricevi(a1, v12, 80LL) )
{
v6 = pthread_self();
func1(a1, v6, a2);
}
pthread_mutex_lock(&lettura);
if ( ++num_lettori == 1 )
pthread_mutex_lock(&scrittura);
pthread_mutex_unlock(&lettura);
v2 = trova_record(v12);
pthread_mutex_lock(&lettura);
if ( !--num_lettori )
pthread_mutex_unlock(&scrittura);
pthread_mutex_unlock(&lettura);
if ( v2 < 0 )
{
result = trasmetti_opzione(a1, 105LL);
if ( result )
{
v10 = pthread_self();
func1(a1, v10, a2);
}
}
else
{
if ( (unsigned int)trasmetti_opzione(a1, 104LL) )
{
v7 = pthread_self();
func1(a1, v7, a2);
}
if ( (unsigned int)ricevi(a1, v11, 251LL) )
{
v8 = pthread_self();
func1(a1, v8, a2);
}
pthread_mutex_lock(&scrittura);
v3 = modifica_record(v11, v12);
if ( (unsigned int)trasmetti_opzione(a1, 104 - ((unsigned int)(v3 == 0) - 1)) )
{
v9 = pthread_self();
func1(a1, v9, a2);
}
result = pthread_mutex_unlock(&scrittura);
}
return result;
}

original_code:
void modifica_contatto(int id_connessione, int debug) {
 struct ricerca_contatto modifico;
 struct contatto new;
 int posizione;
 if (debug)
  fprintf(stdout,"[thread %d] modifica contatto\n", pthread_self());
 if(ricevi(id_connessione, &modifico, sizeof(struct ricerca_contatto)))
  fatal_error(id_connessione, pthread_self(), debug);
 pthread_mutex_lock(&lettura);
  num_lettori++;
  if (num_lettori == 1)
   pthread_mutex_lock(&scrittura);
 pthread_mutex_unlock(&lettura);
 posizione = trova_record(&modifico);
 pthread_mutex_lock(&lettura);
  num_lettori--;
  if (num_lettori == 0)
   pthread_mutex_unlock(&scrittura);
 pthread_mutex_unlock(&lettura);
 if (posizione >= 0) {
  if(trasmetti_opzione(id_connessione, 'h'))
   fatal_error(id_connessione, pthread_self(), debug);
  if(ricevi(id_connessione, &new, sizeof(struct contatto)))
   fatal_error(id_connessione, pthread_self(), debug);
  pthread_mutex_lock(&scrittura);
  if(trasmetti_opzione(id_connessione, modifica_record(&new, &modifico) ? 'i' : 'h'))
   fatal_error(id_connessione, pthread_self(), debug);
  pthread_mutex_unlock(&scrittura);
 }
 else
  if(trasmetti_opzione(id_connessione, 'i'))
   fatal_error(id_connessione, pthread_self(), debug);
}

variable_types: struct ricerca_contatto { char nome[40]; char cognome[40]; }

variable_types: posizione int


decompiled_code:
int __fastcall nuovo_contatto(__int64 a1, int a2)
{
int v2; // eax
pthread_t v4; // r12
__int64 v5; // rax
__int64 v6; // rax
_BYTE v7[280]; // [rsp+0h] [rbp-118h] BYREF

if ( !a2 )
{
if ( !(unsigned int)ricevi(a1, v7, 251LL) )
goto LABEL_3;
LABEL_7:
v5 = pthread_self();
fatal_error(a1, v5, a2);
}
v4 = pthread_self();
fprintf(stdout, "[thread %d] nuovo contatto\n", v4);
if ( (unsigned int)ricevi((unsigned int)a1, v7, 251LL) )
goto LABEL_7;
fprintf(stdout, "-------------Ricevuto record da %d:\n", v4);
stampa_record(v7);
fwrite("Fine record-----------------------------\n", 1uLL, 0x29uLL, stdout);
LABEL_3:
pthread_mutex_lock(&scrittura);
v2 = nuovo_record(v7);
if ( (unsigned int)trasmetti_opzione((unsigned int)a1, 104 - ((unsigned int)(v2 == 0) - 1)) )
{
v6 = pthread_self();
fatal_error(a1, v6, a2);
}
return pthread_mutex_unlock(&scrittura);
}

canonical_decompiled_code:
int __fastcall func5(__int64 a1, int a2)
{
int v2; // eax
pthread_t v4; // r12
__int64 v5; // rax
__int64 v6; // rax
_BYTE v7[280]; // [rsp+0h] [rbp-118h] BYREF

if ( !a2 )
{
if ( !(unsigned int)ricevi(a1, v7, 251LL) )
goto LABEL_3;
LABEL_7:
v5 = pthread_self();
func1(a1, v5, a2);
}
v4 = pthread_self();
fprintf(stdout, "[thread %d] nuovo contatto\n", v4);
if ( (unsigned int)ricevi((unsigned int)a1, v7, 251LL) )
goto LABEL_7;
fprintf(stdout, "-------------Ricevuto record da %d:\n", v4);
stampa_record(v7);
fwrite("Fine record-----------------------------\n", 1uLL, 0x29uLL, stdout);
LABEL_3:
pthread_mutex_lock(&scrittura);
v2 = nuovo_record(v7);
if ( (unsigned int)trasmetti_opzione((unsigned int)a1, 104 - ((unsigned int)(v2 == 0) - 1)) )
{
v6 = pthread_self();
func1(a1, v6, a2);
}
return pthread_mutex_unlock(&scrittura);
}

original_code:
void nuovo_contatto(int id_connessione, int debug) {
 struct contatto new;
 if (debug)
  fprintf(stdout,"[thread %d] nuovo contatto\n", pthread_self());
 if(ricevi(id_connessione, &new, sizeof(struct contatto)))
  fatal_error(id_connessione, pthread_self(), debug);
 if (debug) {
  fprintf(stdout,"-------------Ricevuto record da %d:\n", pthread_self());
  stampa_record(&new);
  fprintf(stdout,"Fine record-----------------------------\n");
 }
 pthread_mutex_lock(&scrittura);
 if(trasmetti_opzione(id_connessione, nuovo_record(&new) ? 'i' : 'h'))
  fatal_error(id_connessione, pthread_self(), debug);
 pthread_mutex_unlock(&scrittura);
}


decompiled_code:
int __fastcall cancella_contatto(unsigned int a1, int a2)
{
int v2; // eax
pthread_t v4; // rax
__int64 v5; // rax
__int64 v6; // rax
_BYTE v7[104]; // [rsp+0h] [rbp-68h] BYREF

if ( a2 )
{
v4 = pthread_self();
fprintf(stdout, "[thread %d] cancella contatto\n", v4);
}
if ( (unsigned int)ricevi(a1, v7, 80LL) )
{
v5 = pthread_self();
fatal_error(a1, v5, a2);
}
pthread_mutex_lock(&scrittura);
v2 = cancella_record(v7);
if ( (unsigned int)trasmetti_opzione(a1, 104 - ((unsigned int)(v2 == 0) - 1)) )
{
v6 = pthread_self();
fatal_error(a1, v6, a2);
}
return pthread_mutex_unlock(&scrittura);
}

canonical_decompiled_code:
int __fastcall func6(unsigned int a1, int a2)
{
int v2; // eax
pthread_t v4; // rax
__int64 v5; // rax
__int64 v6; // rax
_BYTE v7[104]; // [rsp+0h] [rbp-68h] BYREF

if ( a2 )
{
v4 = pthread_self();
fprintf(stdout, "[thread %d] cancella contatto\n", v4);
}
if ( (unsigned int)ricevi(a1, v7, 80LL) )
{
v5 = pthread_self();
func1(a1, v5, a2);
}
pthread_mutex_lock(&scrittura);
v2 = cancella_record(v7);
if ( (unsigned int)trasmetti_opzione(a1, 104 - ((unsigned int)(v2 == 0) - 1)) )
{
v6 = pthread_self();
func1(a1, v6, a2);
}
return pthread_mutex_unlock(&scrittura);
}

original_code:
void cancella_contatto(int id_connessione, int debug) {
 struct ricerca_contatto cancello;
 if (debug)
  fprintf(stdout,"[thread %d] cancella contatto\n", pthread_self());
 if(ricevi(id_connessione, &cancello, sizeof(struct ricerca_contatto)))
  fatal_error(id_connessione, pthread_self(), debug);
 pthread_mutex_lock(&scrittura);
 if(trasmetti_opzione(id_connessione, cancella_record(&cancello) ? 'i' : 'h'))
  fatal_error(id_connessione, pthread_self(), debug);
 pthread_mutex_unlock(&scrittura);
}

user_defined_types: struct ricerca_contatto { char nome[40]; char cognome[40]; }


decompiled_code:
int __fastcall compact_tabella(unsigned int a1, int a2)
{
int v2; // eax
pthread_t v4; // rax
__int64 v5; // rax

if ( a2 )
{
v4 = pthread_self();
fprintf(stdout, "[thread %d] compact tabella\n", v4);
}
pthread_mutex_lock(&scrittura);
v2 = compatta_tabella();
if ( (unsigned int)trasmetti_opzione(a1, 104 - ((unsigned int)(v2 == 0) - 1)) )
{
v5 = pthread_self();
fatal_error(a1, v5, a2);
}
return pthread_mutex_unlock(&scrittura);
}

canonical_decompiled_code:
int __fastcall func7(unsigned int a1, int a2)
{
int v2; // eax
pthread_t v4; // rax
__int64 v5; // rax

if ( a2 )
{
v4 = pthread_self();
fprintf(stdout, "[thread %d] compact tabella\n", v4);
}
pthread_mutex_lock(&scrittura);
v2 = compatta_tabella();
if ( (unsigned int)trasmetti_opzione(a1, 104 - ((unsigned int)(v2 == 0) - 1)) )
{
v5 = pthread_self();
func1(a1, v5, a2);
}
return pthread_mutex_unlock(&scrittura);
}

original_code:
void compact_tabella(int id_connessione, int debug) {
 if (debug)
  fprintf(stdout,"[thread %d] compact tabella\n", pthread_self());
 pthread_mutex_lock(&scrittura);
  if(trasmetti_opzione(id_connessione, compatta_tabella() ? 'i' : 'h'))
   fatal_error(id_connessione, pthread_self(), debug);
 pthread_mutex_unlock(&scrittura);
}


decompiled_code:
size_t __fastcall stampa_help(const char *a1)
{
fprintf(stdout, "Usa: %s [OPZIONE 1 ... OPZIONE N]\n\n", a1);
fwrite("OPZIONE puo' essere:\n", 1uLL, 0x15uLL, stdout);
fwrite("\t-h oppure --help\tPer visualizzare questa guida\n", 1uLL, 0x30uLL, stdout);
fwrite("\t-r oppure --reset\tPer resettare il database dell'agenda\n", 1uLL, 0x39uLL, stdout);
fwrite("\t-v oppure --verbose\tPer visualizzare le informazioni di debug\n", 1uLL, 0x3FuLL, stdout);
fwrite(
"\t-p <numero porta>\n\toppure\n\t--port <numero porta>\tPer scegliere una porta diversa da quella di default\n",
1uLL,
0x67uLL,
stdout);
fwrite("\nProgetto di Laboratorio di Sistemi Operativi (2004/2005)\n", 1uLL, 0x3AuLL, stdout);
return fwrite("Ferrara Francesco Saverio - 566/811 - fsterrar@studenti.unina.it\n\n", 1uLL, 0x42uLL, stdout);
}

canonical_decompiled_code:
size_t __fastcall func9(const char *a1)
{
fprintf(stdout, "Usa: %s [OPZIONE 1 ... OPZIONE N]\n\n", a1);
fwrite("OPZIONE puo' essere:\n", 1uLL, 0x15uLL, stdout);
fwrite("\t-h oppure --help\tPer visualizzare questa guida\n", 1uLL, 0x30uLL, stdout);
fwrite("\t-r oppure --reset\tPer resettare il database dell'agenda\n", 1uLL, 0x39uLL, stdout);
fwrite("\t-v oppure --verbose\tPer visualizzare le informazioni di debug\n", 1uLL, 0x3FuLL, stdout);
fwrite(
"\t-p <numero porta>\n\toppure\n\t--port <numero porta>\tPer scegliere una porta diversa da quella di default\n",
1uLL,
0x67uLL,
stdout);
fwrite("\nProgetto di Laboratorio di Sistemi Operativi (2004/2005)\n", 1uLL, 0x3AuLL, stdout);
return fwrite("Ferrara Francesco Saverio - 566/811 - fsterrar@studenti.unina.it\n\n", 1uLL, 0x42uLL, stdout);
}

original_code:
void stampa_help(char *nome_eseguibile) {
 fprintf(stdout,"Usa: %s [OPZIONE 1 ... OPZIONE N]\n\n", nome_eseguibile);
 fprintf(stdout,"OPZIONE puo' essere:\n");
 fprintf(stdout,"\t-h oppure --help\tPer visualizzare questa guida\n");
 fprintf(stdout,"\t-r oppure --reset\tPer resettare il database dell'agenda\n");
 fprintf(stdout,"\t-v oppure --verbose\tPer visualizzare le informazioni di debug\n");
 fprintf(stdout,"\t-p <numero porta>\n\toppure\n\t--port <numero porta>\tPer scegliere una porta diversa da quella di default\n");
 fprintf(stdout,"\nProgetto di Laboratorio di Sistemi Operativi (2004/2005)\n");
 fprintf(stdout,"Ferrara Francesco Saverio - 566/811 - fsterrar@studenti.unina.it\n\n");
}


ricevi

decompiled_code:
__int64 __fastcall ricevi(int fd, void *buf, int a3)
{
int v5; // ebx
int v6; // eax

if ( a3 <= 0 )
return 0LL;
v5 = 0;
while ( 1 )
{
v6 = read(fd, buf, a3 - v5);
if ( v6 <= 0 )
break;
v5 += v6;
buf = (char *)buf + v6;
if ( a3 <= v5 )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(int fd, void *buf, int a3)
{
int v5; // ebx
int v6; // eax

if ( a3 <= 0 )
return 0LL;
v5 = 0;
while ( 1 )
{
v6 = read(fd, buf, a3 - v5);
if ( v6 <= 0 )
break;
v5 += v6;
buf = (char *)buf + v6;
if ( a3 <= v5 )
return 0LL;
}
return 1LL;
}

original_code:
int ricevi(int id_connessione, void *buffer, int dimensione) {
 int count=0;
 int byte_letti=0;
 while(count < dimensione) {
  if((byte_letti=read(id_connessione, buffer, dimensione - count)) > 0) {
   count += byte_letti;
   buffer += byte_letti;
  }
  else
   return 1;
 }
 return 0;
}

canonical_original_code:
int ricevi(int id_connessione, void *buffer, int dimensione) {
 int count = 0;
 int byte_letti = 0;
 while(count < dimensione) {
  if((byte_letti=read(id_connessione, buffer, dimensione - count)) > 0) {
   count += byte_letti;
   buffer += byte_letti;
  }
  else
   return 1;
 }
 return 0;
}

variable_types:
buffer
void *

variable_types: dimensione int

variable_types: count int

return_type: int


trasmetti

decompiled_code:
__int64 __fastcall trasmetti(int fd, void *buf, int a3)
{
int v5; // ebx
int v6; // eax

if ( a3 <= 0 )
return 0LL;
v5 = 0;
while ( 1 )
{
v6 = write(fd, buf, a3 - v5);
if ( v6 <= 0 )
break;
v5 += v6;
buf = (char *)buf + v6;
if ( a3 <= v5 )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(int fd, void *buf, int a3)
{
int v5; // ebx
int v6; // eax

if ( a3 <= 0 )
return 0LL;
v5 = 0;
while ( 1 )
{
v6 = write(fd, buf, a3 - v5);
if ( v6 <= 0 )
break;
v5 += v6;
buf = (char *)buf + v6;
if ( a3 <= v5 )
return 0LL;
}
return 1LL;
}

original_code:
int trasmetti(int id_connessione, void *buffer, int dimensione)
{
 int count=0;
 int byte_scritti=0;
 while(count < dimensione) {
  if((byte_scritti=write(id_connessione, buffer, dimensione - count)) > 0) {
   count += byte_scritti;
   buffer += byte_scritti;
  }
  else
   return 1;
 }
 return 0;
}

canonical_original_code:
int trasmetti(int id_connessione, void *buffer, int dimensione)
{
 int count = 0;
 int byte_scritti = 0;
 while(count < dimensione) {
  if((byte_scritti=write(id_connessione, buffer, dimensione - count)) > 0) {
   count += byte_scritti;
   buffer += byte_scritti;
  }
  else
   return 1;
 }
 return 0;
}


decompiled_code:
__int64 __fastcall ricevi_opzione(int fd, void *buf)
{
int v3; // ebx
int v4; // eax

v3 = 0;
while ( 1 )
{
v4 = read(fd, buf, 1 - v3);
if ( v4 <= 0 )
break;
v3 += v4;
buf = (char *)buf + v4;
if ( v3 > 0 )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(int fd, void *buf)
{
int v3; // ebx
int v4; // eax

v3 = 0;
while ( 1 )
{
v4 = read(fd, buf, 1 - v3);
if ( v4 <= 0 )
break;
v3 += v4;
buf = (char *)buf + v4;
if ( v3 > 0 )
return 0LL;
}
return 1LL;
}

original_code:
int ricevi_opzione(int id_connessione, char *buffer_r)
{
 int count=0;
 int byte_letti=0;
 void *buffer = buffer_r;
 int dimensione = sizeof(char);
 while(count < dimensione) {
  if((byte_letti=read(id_connessione, buffer, dimensione - count)) > 0) {
   count += byte_letti;
   buffer += byte_letti;
  }
  else
   return 1;
 }
 return 0;
}

canonical_original_code:
int ricevi_opzione(int id_connessione, char *buffer_r)
{
 int count = 0;
 int byte_letti = 0;
 void *buffer = buffer_r;
 int dimensione = sizeof(char);
 while(count < dimensione) {
  if((byte_letti=read(id_connessione, buffer, dimensione - count)) > 0) {
   count += byte_letti;
   buffer += byte_letti;
  }
  else
   return 1;
 }
 return 0;
}


decompiled_code:
__int64 __fastcall trasmetti_opzione(int fd, char a2)
{
char *v2; // rbp
int v3; // ebx
int v4; // eax
char buf; // [rsp+Ch] [rbp-2Ch] BYREF

buf = a2;
v2 = &buf;
v3 = 0;
while ( 1 )
{
v4 = write(fd, v2, 1 - v3);
if ( v4 <= 0 )
break;
v3 += v4;
v2 += v4;
if ( v3 > 0 )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(int fd, char a2)
{
char *v2; // rbp
int v3; // ebx
int v4; // eax
char buf; // [rsp+Ch] [rbp-2Ch] BYREF

buf = a2;
v2 = &buf;
v3 = 0;
while ( 1 )
{
v4 = write(fd, v2, 1 - v3);
if ( v4 <= 0 )
break;
v3 += v4;
v2 += v4;
if ( v3 > 0 )
return 0LL;
}
return 1LL;
}

original_code:
int trasmetti_opzione(int id_connessione, char buffer_r)
{
 int count=0;
 int byte_scritti=0;
 void *buffer = &buffer_r;
 int dimensione = sizeof(char);
 while(count < dimensione) {
  if((byte_scritti=write(id_connessione, buffer, dimensione - count)) > 0) {
   count += byte_scritti;
   buffer += byte_scritti;
  }
  else
   return 1;
 }
 return 0;
}

canonical_original_code:
int trasmetti_opzione(int id_connessione, char buffer_r)
{
 int count = 0;
 int byte_scritti = 0;
 void *buffer = &buffer_r;
 int dimensione = sizeof(char);
 while(count < dimensione) {
  if((byte_scritti=write(id_connessione, buffer, dimensione - count)) > 0) {
   count += byte_scritti;
   buffer += byte_scritti;
  }
  else
   return 1;
 }
 return 0;
}


sentinella

decompiled_code:
_BOOL8 __fastcall sentinella(__int64 a1)
{
return *(_BYTE *)(a1 + 250) == 83;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(__int64 a1)
{
return *(_BYTE *)(a1 + 250) == 83;
}

original_code:
int sentinella(struct contatto *test) {
 if('S' == test->marcatura)
  return 1;
 return 0;
}

variable_types: struct contatto { char nome[40]; char cognome[40]; char indirizzo[90]; char telefono[40]; char email[40]; char marcatura; } *


cancellato

decompiled_code:
_BOOL8 __fastcall cancellato(__int64 a1)
{
return *(_BYTE *)(a1 + 250) == 88;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(__int64 a1)
{
return *(_BYTE *)(a1 + 250) == 88;
}

original_code:
int cancellato(struct contatto *test) {
 if('X' == test->marcatura)
  return 1;
 return 0;
}


decompiled_code:
int __fastcall stampa_record(const char *a1)
{
fprintf(stdout, "Nome: %s\tCognome: %s\n", a1, a1 + 40);
fprintf(stdout, "Indirizzo: %s\n", a1 + 80);
return fprintf(stdout, "Telefono: %s\tE-Mail: %s\n", a1 + 170, a1 + 210);
}

canonical_decompiled_code:
int __fastcall func2(const char *a1)
{
fprintf(stdout, "Nome: %s\tCognome: %s\n", a1, a1 + 40);
fprintf(stdout, "Indirizzo: %s\n", a1 + 80);
return fprintf(stdout, "Telefono: %s\tE-Mail: %s\n", a1 + 170, a1 + 210);
}

original_code:
void stampa_record(struct contatto *record) {
 fprintf(stdout,"Nome: %s\tCognome: %s\n", record->nome, record->cognome);
 fprintf(stdout,"Indirizzo: %s\n", record->indirizzo);
 fprintf(stdout,"Telefono: %s\tE-Mail: %s\n", record->telefono, record->email);
}


decompiled_code:
__int64 __fastcall adtl_elem_addr(__int64 a1, int a2)
{
if ( !a1 )
return 0LL;
if ( *(_DWORD *)a1 == a2 )
return a1;
return adtl_elem_addr(*(_QWORD *)(a1 + 8));
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2)
{
if ( !a1 )
return 0LL;
if ( *(_DWORD *)a1 == a2 )
return a1;
return func0(*(_QWORD *)(a1 + 8));
}

original_code:
struct elemento *adtl_elem_addr(lista_t lista, int elemento) {
 if (lista != ((void *)0)) {
  if ((lista->elem).connessione == elemento)
   return &(lista->elem);
  else
   return adtl_elem_addr(lista->next, elemento);
 }
 return ((void *)0);
}

canonical_original_code:
struct elemento *adtl_elem_addr(struct nodo *lista, int elemento) {
 if (lista != ((void *)0)) {
  if ((lista->elem).connessione == elemento)
   return &(lista->elem);
  else
   return adtl_elem_addr(lista->next, elemento);
 }
 return ((void *)0);
}

variable_types: struct nodo { struct elemento elem; struct nodo *next; } *

variable_types: elemento int

return_type: struct elemento { int connessione; int debug_info; } *


decompiled_code:
__int64 adtl_crealista()
{
return 0LL;
}

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

original_code:
lista_t adtl_crealista() {
 return ((void *)0);
}

canonical_original_code:
struct nodo *adtl_crealista() {
 return ((void *)0);
}

return_type: struct nodo { struct elemento { int connessione; int debug_info; } elem; struct nodo *next; } *

user_defined_types: struct nodo { struct elemento elem; struct nodo *next; }


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

if ( a1 )
result = *a1;
else
result = 0xFFFFFFFFLL;
return result;
}

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

if ( a1 )
result = *a1;
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int adtl_estrai(lista_t lista)
{
 if (lista != ((void *)0))
  return (lista->elem).connessione;
 return -1;
}

canonical_original_code:
int adtl_estrai(struct nodo *lista)
{
 if (lista != ((void *)0))
  return (lista->elem).connessione;
 return -1;
}

variable_types: struct nodo { struct elemento { int connessione; int debug_info; } elem; struct nodo *next; } *


decompiled_code:
__int64 __fastcall adtl_estrai_elemento(unsigned int *a1)
{
return *a1;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int *a1)
{
return *a1;
}

original_code:
int adtl_estrai_elemento(struct elemento *elem)
{
 return elem->connessione;
}

variable_types: struct elemento { int connessione; int debug_info; } *


decompiled_code:
__int64 __fastcall adtl_estrai_debug_info(__int64 a1)
{
return *(unsigned int *)(a1 + 4);
}

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

original_code:
int adtl_estrai_debug_info(struct elemento *elem)
{
 return elem->debug_info;
}


decompiled_code:
__int64 __fastcall avvia_server(int n, __int16 a2)
{
int v2; // eax
unsigned int v3; // ebx
struct sockaddr v5; // [rsp+0h] [rbp-28h] BYREF

*(_QWORD *)&v5.sa_family = 2LL;
*(_QWORD *)&v5.sa_data[6] = 0LL;
*(_WORD *)v5.sa_data = _bswap_16(a2);
v2 = socket(2, 1, 0);
if ( v2 < 0 )
{
fwrite("avvia_server(): impossibile creare il socket\n", 1uLL, 0x2DuLL, stdout);
exit(1);
}
v3 = v2;
if ( bind(v2, &v5, 0x10u) < 0 )
{
close(v3);
fwrite("avvia_server(): impossibile dare l'indirizzo al socket creato\n", 1uLL, 0x3EuLL, stdout);
exit(1);
}
listen(v3, n);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func1(int n, __int16 a2)
{
int v2; // eax
unsigned int v3; // ebx
struct sockaddr v5; // [rsp+0h] [rbp-28h] BYREF

*(_QWORD *)&v5.sa_family = 2LL;
*(_QWORD *)&v5.sa_data[6] = 0LL;
*(_WORD *)v5.sa_data = func0(a2);
v2 = socket(2, 1, 0);
if ( v2 < 0 )
{
fwrite("avvia_server(): impossibile creare il socket\n", 1uLL, 0x2DuLL, stdout);
exit(1);
}
v3 = v2;
if ( bind(v2, &v5, 0x10u) < 0 )
{
close(v3);
fwrite("avvia_server(): impossibile dare l'indirizzo al socket creato\n", 1uLL, 0x3EuLL, stdout);
exit(1);
}
listen(v3, n);
return v3;
}

original_code:
int avvia_server(int max_connessioni, int portnum) {
 struct sockaddr_in sock_address;
 int id_socket;
 bzero(&sock_address, sizeof(struct sockaddr_in));
 sock_address.sin_family = 2;
 sock_address.sin_port = htons((u_short) portnum);
 id_socket = socket(2, SOCK_STREAM, 0);
 if (id_socket < 0) {
  fprintf(stdout,"avvia_server(): impossibile creare il socket\n");
  exit(1);
 }
 if (bind(id_socket,(struct sockaddr *) &sock_address, sizeof(struct sockaddr_in)) < 0) {
  close(id_socket);
  fprintf(stdout,"avvia_server(): impossibile dare l'indirizzo al socket creato\n");
  exit(1);
 }
 listen(id_socket, max_connessioni);
 return id_socket;
}

canonical_original_code:
int avvia_server(int max_connessioni, int portnum) {
 struct sockaddr_in sock_address;
 int id_socket;
 bzero(&sock_address, sizeof(struct sockaddr_in));
 sock_address.sin_family = 2;
 sock_address.sin_port = htons((unsigned short) portnum);
 id_socket = socket(2, SOCK_STREAM, 0);
 if (id_socket < 0) {
  fprintf(stdout,"avvia_server(): impossibile creare il socket\n");
  exit(1);
 }
 if (bind(id_socket,(struct sockaddr *) &sock_address, sizeof(struct sockaddr_in)) < 0) {
  close(id_socket);
  fprintf(stdout,"avvia_server(): impossibile dare l'indirizzo al socket creato\n");
  exit(1);
 }
 listen(id_socket, max_connessioni);
 return id_socket;
}

variable_types: portnum 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]; }

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

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


decompiled_code:
int __fastcall accetta_connessione(int fd)
{
int result; // eax
socklen_t len; // [rsp+Ch] [rbp-1Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-18h] BYREF

len = 16;
getsockname(fd, &addr, &len);
result = accept(fd, &addr, &len);
if ( result < 0 )
{
close(fd);
fwrite("accetta_connessione(): impossibile accettare una connessione\n", 1uLL, 0x3DuLL, stdout);
exit(1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(int fd)
{
int result; // eax
socklen_t len; // [rsp+Ch] [rbp-1Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-18h] BYREF

len = 16;
getsockname(fd, &addr, &len);
result = accept(fd, &addr, &len);
if ( result < 0 )
{
close(fd);
fwrite("accetta_connessione(): impossibile accettare una connessione\n", 1uLL, 0x3DuLL, stdout);
exit(1);
}
return result;
}

original_code:
int accetta_connessione(int id_socket) {
 struct sockaddr_in i_sock_address;
 int id_connessione;
 int dimensione;
 dimensione = sizeof(struct sockaddr_in);
 getsockname(id_socket, (struct sockaddr *) &i_sock_address, &dimensione);
 id_connessione = accept(id_socket, (struct sockaddr *) &i_sock_address, &dimensione);
 if (id_connessione < 0) {
  close(id_socket);
  fprintf(stdout,"accetta_connessione(): impossibile accettare una connessione\n");
  exit(1);
 }
 return id_connessione;
}


decompiled_code:
int __fastcall arresta_server(int a1)
{
int result; // eax

result = close(a1);
if ( result == -1 )
{
perror("arresta_server()");
exit(1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func4(int a1)
{
int result; // eax

result = close(a1);
if ( result == -1 )
{
perror("arresta_server()");
exit(1);
}
return result;
}

original_code:
void arresta_server(int id_socket) {
 if (close(id_socket) == -1)
  perror("arresta_server()"), exit(1);
}


decompiled_code:
_BOOL8 __fastcall chiudi_connessione(int a1)
{
return close(a1) == -1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(int a1)
{
return close(a1) == -1;
}

original_code:
int chiudi_connessione(int id_connessione) {
 if (close(id_connessione) == -1)
  return 1;
 return 0;
}


decompiled_code:
int __fastcall inserisci_record(__int64 a1)
{
int result; // eax

fwrite("\tNome: ", 1uLL, 7uLL, stdout);
leggistringa(a1);
fwrite("\tCognome: ", 1uLL, 0xAuLL, stdout);
leggistringa(a1 + 40);
fwrite("\tIndirizzo: ", 1uLL, 0xCuLL, stdout);
leggistringa(a1 + 80);
fwrite("\tTelefono: ", 1uLL, 0xBuLL, stdout);
leggistringa(a1 + 170);
fwrite("\tE-Mail: ", 1uLL, 9uLL, stdout);
result = leggistringa(a1 + 210);
*(_BYTE *)(a1 + 250) = 78;
return result;
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1)
{
int result; // eax

fwrite("\tNome: ", 1uLL, 7uLL, stdout);
func0(a1);
fwrite("\tCognome: ", 1uLL, 0xAuLL, stdout);
func0(a1 + 40);
fwrite("\tIndirizzo: ", 1uLL, 0xCuLL, stdout);
func0(a1 + 80);
fwrite("\tTelefono: ", 1uLL, 0xBuLL, stdout);
func0(a1 + 170);
fwrite("\tE-Mail: ", 1uLL, 9uLL, stdout);
result = func0(a1 + 210);
*(_BYTE *)(a1 + 250) = 78;
return result;
}

original_code:
void inserisci_record(struct contatto *new) {
 fprintf(stdout,"\tNome: ");
 leggistringa(new->nome);
 fprintf(stdout,"\tCognome: ");
 leggistringa(new->cognome);
 fprintf(stdout,"\tIndirizzo: ");
 leggistringa(new->indirizzo);
 fprintf(stdout,"\tTelefono: ");
 leggistringa(new->telefono);
 fprintf(stdout,"\tE-Mail: ");
 leggistringa(new->email);
 new->marcatura = 'N';
}


connetti

decompiled_code:
__int64 __fastcall connetti(char *cp, __int16 a2)
{
int v2; // eax
unsigned int v3; // ebx
struct sockaddr buf; // [rsp+0h] [rbp-18h] BYREF

*(_QWORD *)&buf.sa_family = 0LL;
*(_QWORD *)&buf.sa_data[6] = 0LL;
if ( inet_pton(2, cp, &buf.sa_data[2]) <= 0 )
{
fwrite("connetti(): ip inserito non valido\n", 1uLL, 0x23uLL, stdout);
exit(1);
}
buf.sa_family = 2;
*(_WORD *)buf.sa_data = _bswap_16(a2);
v2 = socket(2, 1, 0);
v3 = v2;
if ( v2 < 0 )
{
fwrite("connetti(): impossibile creare il socket\n", 1uLL, 0x29uLL, stdout);
exit(1);
}
if ( connect(v2, &buf, 0x10u) < 0 )
{
close(v3);
perror("connetti(): impossibile connettersi");
exit(1);
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *cp, __int16 a2)
{
int v2; // eax
unsigned int v3; // ebx
struct sockaddr buf; // [rsp+0h] [rbp-18h] BYREF

*(_QWORD *)&buf.sa_family = 0LL;
*(_QWORD *)&buf.sa_data[6] = 0LL;
if ( inet_pton(2, cp, &buf.sa_data[2]) <= 0 )
{
fwrite("connetti(): ip inserito non valido\n", 1uLL, 0x23uLL, stdout);
exit(1);
}
buf.sa_family = 2;
*(_WORD *)buf.sa_data = func0(a2);
v2 = socket(2, 1, 0);
v3 = v2;
if ( v2 < 0 )
{
fwrite("connetti(): impossibile creare il socket\n", 1uLL, 0x29uLL, stdout);
exit(1);
}
if ( connect(v2, &buf, 0x10u) < 0 )
{
close(v3);
perror("connetti(): impossibile connettersi");
exit(1);
}
return v3;
}

original_code:
int connetti(char *ip, int portnum) {
 struct sockaddr_in sock_address;
 int id_connessione;
 bzero(&sock_address, sizeof(struct sockaddr_in));
 if (inet_pton(2, ip, &sock_address.sin_addr) <= 0) {
  fprintf(stdout,"connetti(): ip inserito non valido\n");
  exit(1);
 }
 sock_address.sin_family = 2;
 sock_address.sin_port = htons((u_short) portnum);
 id_connessione = socket(2, SOCK_STREAM, 0);
 if (id_connessione < 0) {
  fprintf(stdout,"connetti(): impossibile creare il socket\n");
  exit(1);
 }
 if (connect(id_connessione, (struct sockaddr *) &sock_address, sizeof(struct sockaddr_in)) < 0) {
  close(id_connessione);
  perror("connetti(): impossibile connettersi");
  exit(1);
 }
 return id_connessione;
}

canonical_original_code:
int connetti(char *ip, int portnum) {
 struct sockaddr_in sock_address;
 int id_connessione;
 bzero(&sock_address, sizeof(struct sockaddr_in));
 if (inet_pton(2, ip, &sock_address.sin_addr) <= 0) {
  fprintf(stdout,"connetti(): ip inserito non valido\n");
  exit(1);
 }
 sock_address.sin_family = 2;
 sock_address.sin_port = htons((unsigned short) portnum);
 id_connessione = socket(2, SOCK_STREAM, 0);
 if (id_connessione < 0) {
  fprintf(stdout,"connetti(): impossibile creare il socket\n");
  exit(1);
 }
 if (connect(id_connessione, (struct sockaddr *) &sock_address, sizeof(struct sockaddr_in)) < 0) {
  close(id_connessione);
  perror("connetti(): impossibile connettersi");
  exit(1);
 }
 return id_connessione;
}

variable_types:
ip
char *


decompiled_code:
int __fastcall chiudi_connessione(int a1)
{
int result; // eax

result = close(a1);
if ( result == -1 )
{
perror("chiudi_connessione()");
exit(1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(int a1)
{
int result; // eax

result = close(a1);
if ( result == -1 )
{
perror("chiudi_connessione()");
exit(1);
}
return result;
}

original_code:
void chiudi_connessione(int id_connessione) {
 if (close(id_connessione) == -1)
  perror("chiudi_connessione()"), exit(1);
}


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // ebx
int buf[3]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = 15728640;
v3 = open("mpv955info", 577, 420LL);
if ( v3 >= 0 )
{
v4 = v3;
if ( write(v3, buf, 4uLL) != 4 )
{
perror("write()");
if ( close(v4) < 0 )
perror("close()");
exit(1);
}
if ( close(v4) >= 0 )
exit(0);
perror("close()");
exit(1);
}
perror("open()");
exit(1);
}

original_code:
int main(int argc, char *argv[]) {
 int fd;
 ssize_t byte;
 mpv955_info_t info;
 int dr_id, major, nodo;
 info.base_address = 0x00F00000;
 fd = open("mpv955info", 01 | 0100 | 01000, 0644);
 if (fd < 0) {
  perror("open()");
  exit(1);
 }
 byte = write(fd, &info, sizeof(mpv955_info_t));
 if (byte != sizeof(mpv955_info_t)) {
  perror("write()");
  if (close(fd) < 0)
   perror("close()");
  exit(1);
 }
 if (close(fd) < 0) {
  perror("close()");
  exit(1);
 }
 exit(0);
}

canonical_original_code:
int main(int argc, char *argv[]) {
 int fd;
 long byte;
 struct mpv955_info info;
 int dr_id; int major; int nodo;
 info.base_address = 0x00F00000;
 fd = open("mpv955info", 01 | 0100 | 01000, 0644);
 if (fd < 0) {
  perror("open()");
  exit(1);
 }
 byte = write(fd, &info, sizeof(mpv955_info_t));
 if (byte != sizeof(mpv955_info_t)) {
  perror("write()");
  if (close(fd) < 0)
   perror("close()");
  exit(1);
 }
 if (close(fd) < 0) {
  perror("close()");
  exit(1);
 }
 exit(0);
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: byte long

variable_types: struct mpv955_info { unsigned int base_address; }

variable_types: major int

variable_types: nodo int


decompiled_code:
void on_bluetooth_activate()
{
if ( !g_isclickinginprogress )
{
g_isclickinginprogress = 1;
if ( g_allowedmodes )
{
adjust_func_state();
if ( !g_iscardin )
{
g_state = 3;
puts("call on_bluetooth_active, return for the g_iscardin = FALSE");
g_isclickinginprogress = 0;
return;
}
if ( !g_state )
{
puts("call onbluetoothactive, the last state already is on_bluetooth");
g_isclickinginprogress = 0;
return;
}
if ( (unsigned int)(g_state - 1) <= 1 )
{
if ( !(unsigned int)unplugdevices() )
{
puts("unplugdivice fail ! ");
g_isclickinginprogress = 0;
return;
}
wait_device_unplug_stable();
}
write_enum_mode(1LL);
if ( g_downfromfile )
tdsp_download_dsp_code_from_file(1LL);
else
tdsp_download_dsp_code(1LL);
usleep(0x7A120u);
tdsp_add_device("Tdspbus\\TdspBluetooth", 23LL, 1LL);
usleep(0x7A120u);
if ( (unsigned int)tdsp_is_download_dspcode_ok() )
{
g_state = 0;
g_isclickinginprogress = 0;
init_tdsp_otherenv("/usr/local/3DSP/usb/btusbcfg.sh");
}
else
{
g_state = 3;
adjust_func_state();
g_isclickinginprogress = 0;
}
}
else
{
puts("the mode: bt(bluetooth) is disabled!");
}
}
}

canonical_decompiled_code:
void func0()
{
if ( !g_isclickinginprogress )
{
g_isclickinginprogress = 1;
if ( g_allowedmodes )
{
adjust_func_state();
if ( !g_iscardin )
{
g_state = 3;
puts("call on_bluetooth_active, return for the g_iscardin = FALSE");
g_isclickinginprogress = 0;
return;
}
if ( !g_state )
{
puts("call onbluetoothactive, the last state already is on_bluetooth");
g_isclickinginprogress = 0;
return;
}
if ( (unsigned int)(g_state - 1) <= 1 )
{
if ( !(unsigned int)unplugdevices() )
{
puts("unplugdivice fail ! ");
g_isclickinginprogress = 0;
return;
}
wait_device_unplug_stable();
}
write_enum_mode(1LL);
if ( g_downfromfile )
tdsp_download_dsp_code_from_file(1LL);
else
tdsp_download_dsp_code(1LL);
usleep(0x7A120u);
tdsp_add_device("Tdspbus\\TdspBluetooth", 23LL, 1LL);
usleep(0x7A120u);
if ( (unsigned int)tdsp_is_download_dspcode_ok() )
{
g_state = 0;
g_isclickinginprogress = 0;
init_tdsp_otherenv("/usr/local/3DSP/usb/btusbcfg.sh");
}
else
{
g_state = 3;
adjust_func_state();
g_isclickinginprogress = 0;
}
}
else
{
puts("the mode: bt(bluetooth) is disabled!");
}
}
}

original_code:
void on_bluetooth_activate()
{
  if (g_isclickinginprogress != 0)
  {
    ;
    return;
  }
  g_isclickinginprogress = 1;
  ;
  if (g_allowedmodes[0] == 0)
  {
    printf("the mode: bt(bluetooth) is disabled!\n");
    return;
  }
  adjust_func_state();
  if (!g_iscardin)
  {
    g_state = 3;
    printf("call on_bluetooth_active, return for the g_iscardin = FALSE\n");
    g_isclickinginprogress = 0;
    return;
  }
  if (g_state == 0)
  {
    printf("call onbluetoothactive, the last state already is on_bluetooth\n");
    g_isclickinginprogress = 0;
    return;
  }
  if (g_state == 1
      || g_state == 2)
  {
    if (0 == unplugdevices())
    {
      printf("unplugdivice fail ! \n");
      g_isclickinginprogress = 0;
      return;
    }
    wait_device_unplug_stable();
  }
  write_enum_mode(1);
  if (g_downfromfile == 0)
  {
    tdsp_download_dsp_code(1);
  }
  else
  {
    tdsp_download_dsp_code_from_file(1);
  }
  usleep(500000);
  tdsp_add_device("Tdspbus\\TdspBluetooth\0", sizeof("Tdspbus\\TdspBluetooth\0"), 1);
  usleep(500000);
  if (tdsp_is_download_dspcode_ok() == 0)
  {
    g_state = 3;
    adjust_func_state();
    g_isclickinginprogress = 0;
    return;
  }
  g_state = 0;
  g_isclickinginprogress = 0;
  init_tdsp_otherenv("/usr/local/3DSP/usb/btusbcfg.sh");
  return;
}


decompiled_code:
void on_wlan_activate()
{
if ( !g_isclickinginprogress )
{
g_isclickinginprogress = 1;
if ( *((_DWORD *)&g_allowedmodes + 1) )
{
adjust_func_state();
if ( g_iscardin )
{
if ( g_state == 1 )
{
puts("\nWLAN menu have been selected already , out !");
g_isclickinginprogress = 0;
}
else
{
usleep(0x7A120u);
if ( (g_state & 0xFFFFFFFD) == 0 )
{
if ( !(unsigned int)unplugdevices() )
{
g_isclickinginprogress = 0;
return;
}
wait_device_unplug_stable();
}
write_enum_mode(2LL);
if ( g_downfromfile )
tdsp_download_dsp_code_from_file(2LL);
else
tdsp_download_dsp_code(2LL);
usleep(0x7A120u);
tdsp_add_device("Tdspbus\\TdspWlan", 18LL, 2LL);
usleep(0xF4240u);
if ( (unsigned int)tdsp_is_download_dspcode_ok() )
{
g_state = 1;
}
else
{
g_state = 3;
adjust_func_state();
}
g_isclickinginprogress = 0;
}
}
else
{
g_state = 3;
g_isclickinginprogress = 0;
puts(" call the function on_wlan_active, return for g_iscardin=FALSE");
}
}
else
{
puts("the mode: wlan is disabled!");
}
}
}

canonical_decompiled_code:
void func1()
{
if ( !g_isclickinginprogress )
{
g_isclickinginprogress = 1;
if ( *((_DWORD *)&g_allowedmodes + 1) )
{
adjust_func_state();
if ( g_iscardin )
{
if ( g_state == 1 )
{
puts("\nWLAN menu have been selected already , out !");
g_isclickinginprogress = 0;
}
else
{
usleep(0x7A120u);
if ( (g_state & 0xFFFFFFFD) == 0 )
{
if ( !(unsigned int)unplugdevices() )
{
g_isclickinginprogress = 0;
return;
}
wait_device_unplug_stable();
}
write_enum_mode(2LL);
if ( g_downfromfile )
tdsp_download_dsp_code_from_file(2LL);
else
tdsp_download_dsp_code(2LL);
usleep(0x7A120u);
tdsp_add_device("Tdspbus\\TdspWlan", 18LL, 2LL);
usleep(0xF4240u);
if ( (unsigned int)tdsp_is_download_dspcode_ok() )
{
g_state = 1;
}
else
{
g_state = 3;
adjust_func_state();
}
g_isclickinginprogress = 0;
}
}
else
{
g_state = 3;
g_isclickinginprogress = 0;
puts(" call the function on_wlan_active, return for g_iscardin=FALSE");
}
}
else
{
puts("the mode: wlan is disabled!");
}
}
}

original_code:
void on_wlan_activate()
{
  if (g_isclickinginprogress != 0)
  {
    ;
    return;
  }
  g_isclickinginprogress = 1;
  ;
  if (g_allowedmodes[1] == 0)
  {
    printf("the mode: wlan is disabled!\n");
    return;
  }
  adjust_func_state();
  if (g_iscardin == 0)
  {
    g_state = 3;
    g_isclickinginprogress = 0;
    printf(" call the function on_wlan_active, return for g_iscardin=FALSE\n");
    return;
  }
  if (g_state == 1)
  {
    printf("\nWLAN menu have been selected already , out !\n");
    g_isclickinginprogress = 0;
    return;
  }
  usleep(500000);
  if (g_state == 0 || g_state == 2)
  {
    if (0 == unplugdevices())
    {
      g_isclickinginprogress = 0;
      return;
    }
    wait_device_unplug_stable();
  }
  write_enum_mode(2);
  if (g_downfromfile == 0)
    tdsp_download_dsp_code(2);
  else
    tdsp_download_dsp_code_from_file(2);
  usleep(500000);
  tdsp_add_device("Tdspbus\\TdspWlan\0", sizeof("Tdspbus\\TdspWlan\0"), 2);
  usleep(1000000);
  if (tdsp_is_download_dspcode_ok() == 0)
  {
    g_state = 3;
    adjust_func_state();
    g_isclickinginprogress = 0;
    return;
  }
  g_state = 1;
  g_isclickinginprogress = 0;
  return;
}


decompiled_code:
void on_coexist_activate()
{
if ( !g_isclickinginprogress )
{
g_isclickinginprogress = 1;
if ( !g_allowedmodes[2] )
{
puts("the mode: combo is disabled!");
return;
}
adjust_func_state();
if ( !g_iscardin )
{
g_state = 3;
g_isclickinginprogress = 0;
puts("on_coexist_active, return for nocardin");
return;
}
if ( g_state == 2 )
{
g_isclickinginprogress = 0;
puts("on_coexist_active, return for its current state also is COEXIST");
return;
}
usleep(0x7A120u);
if ( g_state <= 1u )
{
if ( !(unsigned int)unplugdevices() )
{
g_isclickinginprogress = 0;
puts("on_coexist_active, return for unplugdevices fail");
return;
}
wait_device_unplug_stable();
}
write_enum_mode(3LL);
if ( g_downfromfile )
tdsp_download_dsp_code_from_file(2LL);
else
tdsp_download_dsp_code(2LL);
usleep(0x30D40u);
tdsp_add_device("Tdspbus\\TdspWlan", 18LL, 2LL);
usleep(0xF4240u);
if ( !(unsigned int)tdsp_is_download_dspcode_ok() )
goto LABEL_19;
while ( 1 )
{
tdsp_query_pnp_state(2LL);
if ( g_dsppnpstate == 1 )
break;
tdsp_query_power_state();
if ( g_buspowerstate != 1 )
{
g_isclickinginprogress = 0;
puts("on_coexist_active, return for power fail");
return;
}
usleep(0x7A120u);
}
tdsp_set_init_flag(2LL);
usleep(0x7A120u);
if ( g_downfromfile )
tdsp_download_dsp_code_from_file(1LL);
else
tdsp_download_dsp_code(1LL);
usleep(0x30D40u);
tdsp_add_device("Tdspbus\\TdspBluetooth", 23LL, 1LL);
usleep(0xF4240u);
if ( (unsigned int)tdsp_is_download_dspcode_ok() )
{
tdsp_set_init_flag(1LL);
g_state = 2;
g_isclickinginprogress = 0;
init_tdsp_otherenv("/usr/local/3DSP/usb/btusbcfg.sh");
}
else
{
LABEL_19:
g_state = 3;
adjust_func_state();
g_isclickinginprogress = 0;
puts("on_coexist_active, return for download_dspcode fail");
}
}
}

canonical_decompiled_code:
void func2()
{
if ( !g_isclickinginprogress )
{
g_isclickinginprogress = 1;
if ( !g_allowedmodes[2] )
{
puts("the mode: combo is disabled!");
return;
}
adjust_func_state();
if ( !g_iscardin )
{
g_state = 3;
g_isclickinginprogress = 0;
puts("on_coexist_active, return for nocardin");
return;
}
if ( g_state == 2 )
{
g_isclickinginprogress = 0;
puts("on_coexist_active, return for its current state also is COEXIST");
return;
}
usleep(0x7A120u);
if ( g_state <= 1u )
{
if ( !(unsigned int)unplugdevices() )
{
g_isclickinginprogress = 0;
puts("on_coexist_active, return for unplugdevices fail");
return;
}
wait_device_unplug_stable();
}
write_enum_mode(3LL);
if ( g_downfromfile )
tdsp_download_dsp_code_from_file(2LL);
else
tdsp_download_dsp_code(2LL);
usleep(0x30D40u);
tdsp_add_device("Tdspbus\\TdspWlan", 18LL, 2LL);
usleep(0xF4240u);
if ( !(unsigned int)tdsp_is_download_dspcode_ok() )
goto LABEL_19;
while ( 1 )
{
tdsp_query_pnp_state(2LL);
if ( g_dsppnpstate == 1 )
break;
tdsp_query_power_state();
if ( g_buspowerstate != 1 )
{
g_isclickinginprogress = 0;
puts("on_coexist_active, return for power fail");
return;
}
usleep(0x7A120u);
}
tdsp_set_init_flag(2LL);
usleep(0x7A120u);
if ( g_downfromfile )
tdsp_download_dsp_code_from_file(1LL);
else
tdsp_download_dsp_code(1LL);
usleep(0x30D40u);
tdsp_add_device("Tdspbus\\TdspBluetooth", 23LL, 1LL);
usleep(0xF4240u);
if ( (unsigned int)tdsp_is_download_dspcode_ok() )
{
tdsp_set_init_flag(1LL);
g_state = 2;
g_isclickinginprogress = 0;
init_tdsp_otherenv("/usr/local/3DSP/usb/btusbcfg.sh");
}
else
{
LABEL_19:
g_state = 3;
adjust_func_state();
g_isclickinginprogress = 0;
puts("on_coexist_active, return for download_dspcode fail");
}
}
}

original_code:
void on_coexist_activate()
{
  if (g_isclickinginprogress != 0)
  {
    ;
    return;
  }
  g_isclickinginprogress = 1;
  ;
  if (g_allowedmodes[2] == 0)
  {
    printf("the mode: combo is disabled!\n");
    return;
  }
  adjust_func_state();
  if (!g_iscardin)
  {
    g_state = 3;
    g_isclickinginprogress = 0;
    printf("on_coexist_active, return for nocardin\n");
    return;
  }
  if (g_state == 2)
  {
    g_isclickinginprogress = 0;
    printf("on_coexist_active, return for its current state also is COEXIST\n");
    return;
  }
  usleep(500000);
  if (g_state == 0|| g_state == 1)
  {
    if (0 == unplugdevices())
    {
      g_isclickinginprogress = 0;
      printf("on_coexist_active, return for unplugdevices fail\n");
      return;
    }
    wait_device_unplug_stable();
  }
  write_enum_mode(3);
  if (g_downfromfile == 0)
    tdsp_download_dsp_code(2);
  else
    tdsp_download_dsp_code_from_file(2);
  usleep(200000);
  tdsp_add_device("Tdspbus\\TdspWlan\0", sizeof("Tdspbus\\TdspWlan\0"), 2);
  usleep(1000000);
  if (tdsp_is_download_dspcode_ok() == 0)
  {
    g_state = 3;
    adjust_func_state();
    g_isclickinginprogress = 0;
    printf("on_coexist_active, return for download_dspcode fail\n");
    return;
  }
  while (1)
  {
    tdsp_query_pnp_state(2);
    if (g_dsppnpstate != Started)
    {
      tdsp_query_power_state();
      if (g_buspowerstate != 1)
      {
        g_isclickinginprogress = 0;
        printf("on_coexist_active, return for power fail\n");
        return;
      }
      usleep(500000);
      continue;
    }
    else
    {
      break;
    }
  }
  tdsp_set_init_flag(2);
  usleep(500000);
  if (g_downfromfile == 0)
    tdsp_download_dsp_code(1);
  else
    tdsp_download_dsp_code_from_file(1);
  usleep(200000);
  tdsp_add_device("Tdspbus\\TdspBluetooth\0", sizeof("Tdspbus\\TdspBluetooth\0"), 1);
  usleep(1000000);
  if (tdsp_is_download_dspcode_ok() == 0)
  {
    g_state = 3;
    adjust_func_state();
    g_isclickinginprogress = 0;
    printf("on_coexist_active, return for download_dspcode fail\n");
    return;
  }
  tdsp_set_init_flag(1);
  g_state = 2;
  g_isclickinginprogress = 0;
  init_tdsp_otherenv("/usr/local/3DSP/usb/btusbcfg.sh");
  return;
}


decompiled_code:
void on_unplug_activate()
{
if ( !g_isclickinginprogress )
{
g_isclickinginprogress = 1;
adjust_func_state();
if ( g_state == 3 )
{
g_isclickinginprogress = 0;
return;
}
if ( g_state <= 2u )
{
if ( !(unsigned int)unplugdevices() )
{
g_isclickinginprogress = 0;
return;
}
wait_device_unplug_stable();
}
g_state = 3;
g_isclickinginprogress = 0;
}
}

canonical_decompiled_code:
void func3()
{
if ( !g_isclickinginprogress )
{
g_isclickinginprogress = 1;
adjust_func_state();
if ( g_state == 3 )
{
g_isclickinginprogress = 0;
return;
}
if ( g_state <= 2u )
{
if ( !(unsigned int)unplugdevices() )
{
g_isclickinginprogress = 0;
return;
}
wait_device_unplug_stable();
}
g_state = 3;
g_isclickinginprogress = 0;
}
}

original_code:
void on_unplug_activate()
{
  if (g_isclickinginprogress != 0)
  {
    ;
    return;
  }
  g_isclickinginprogress = 1;
  ;
  adjust_func_state();
  if (g_state == 3)
  {
    g_isclickinginprogress = 0;
    return;
  }
  if (g_state == 0
      || g_state == 1
      || g_state == 2)
  {
    if (0 == unplugdevices())
    {
      ;
      g_isclickinginprogress = 0;
      return;
    }
    wait_device_unplug_stable();
  }
  g_state = 3;
  g_isclickinginprogress = 0;
  return;
}


decompiled_code:
__int64 on_about_activate()
{
return update_ver_string();
}

canonical_decompiled_code:
__int64 func4()
{
return update_ver_string();
}

original_code:
void on_about_activate()
{
  update_ver_string();
}


decompiled_code:
__int64 on_poweron_activate()
{
logging("calling on on_poweron_active ", 457LL);
return tdsp_power_on();
}

canonical_decompiled_code:
__int64 func5()
{
logging("calling on on_poweron_active ", 457LL);
return tdsp_power_on();
}

original_code:
void on_poweron_activate()
{
  logging("calling on on_poweron_active  ", 457);
  tdsp_power_on();
}


decompiled_code:
__int64 on_poweroff_activate()
{
return tdsp_power_off();
}

canonical_decompiled_code:
__int64 func6()
{
return tdsp_power_off();
}

original_code:
void on_poweroff_activate()
{
  ;
  tdsp_power_off();
}


emalloc

repo: fsouza/yatf

decompiled_code:
void *__fastcall emalloc(size_t a1)
{
void *result; // rax

result = malloc(a1);
if ( !result )
{
fwrite("FATAL: can't allocate memory.\n", 1uLL, 0x1EuLL, stderr);
exit(1);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func0(size_t a1)
{
void *result; // rax

result = malloc(a1);
if ( !result )
{
fwrite("FATAL: can't allocate memory.\n", 1uLL, 0x1EuLL, stderr);
exit(1);
}
return result;
}

original_code:
void *
emalloc(size_t size)
{
 void *p;
 p = malloc(size);
 if(p == ((void *)0)) {
  fprintf(stderr, "FATAL: can't allocate memory.\n");
  exit(1);
 }
 return p;
}

canonical_original_code:
void *emalloc(unsigned long size)
{
 void *p;
 p = malloc(size);
 if(p == ((void *)0)) {
  fprintf(stderr, "FATAL: can't allocate memory.\n");
  exit(1);
 }
 return p;
}

variable_types:
size
unsigned long

variable_types:
p
void *

return_type: void *


original_code:
void
free_test(test_t *t)
{
 failure_t *f;
 while(t->failures != ((void *)0)) {
  f = t->failures;
  t->failures = t->failures->next;
  free(f->reason);
  free(f);
 }
}

canonical_original_code:
void free_test(struct test_t *t)
{
 struct failure_t *f;
 while(t->failures != ((void *)0)) {
  f = t->failures;
  t->failures = t->failures->next;
  free(f->reason);
  free(f);
 }
}

variable_types: struct test_t { char *name; struct failure_t { char *reason; struct failure_t *next; } *failures; int failed; void (*fn)(struct test_t *t); } *

user_defined_types: struct test_t { char *name; struct failure_t *failures; int failed; void (*fn)(struct test_t *t); }


original_code:
void
free_suite(void)
{
 registry_t *p;
 while(r != ((void *)0)) {
  p = r;
  r = r->next;
  free_test(p->item);
  free(p->item);
  free(p);
 }
}

canonical_original_code:
void free_suite()
{
 struct test_list_t *p;
 while(r != ((void *)0)) {
  p = r;
  r = r->next;
  free_test(p->item);
  free(p->item);
  free(p);
 }
}

variable_types: struct test_list_t { struct test_t { char *name; struct failure_t { char *reason; struct failure_t *next; } *failures; int failed; void (*fn)(struct test_t *t); } *item; struct test_list_t *next; } *

user_defined_types: struct test_list_t { struct test_t *item; struct test_list_t *next; }


decompiled_code:
__int64 __fastcall test_fail(__int64 a1, const char *a2)
{
_QWORD *v2; // rbp
size_t v3; // rax
char *v4; // rax
__int64 result; // rax

v2 = emalloc(0x10uLL);
v3 = strlen(a2);
v4 = (char *)emalloc(v3 + 1);
*v2 = v4;
strcpy(v4, a2);
result = *(_QWORD *)(a1 + 8);
v2[1] = result;
*(_QWORD *)(a1 + 8) = v2;
*(_DWORD *)(a1 + 16) = 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, const char *a2)
{
_QWORD *v2; // rbp
size_t v3; // rax
char *v4; // rax
__int64 result; // rax

v2 = func0(0x10uLL);
v3 = strlen(a2);
v4 = (char *)func0(v3 + 1);
*v2 = v4;
strcpy(v4, a2);
result = *(_QWORD *)(a1 + 8);
v2[1] = result;
*(_QWORD *)(a1 + 8) = v2;
*(_DWORD *)(a1 + 16) = 1;
return result;
}

original_code:
void
test_fail(test_t *t, char* reason)
{
 failure_t *failure;
 failure = (failure_t *)emalloc(sizeof(failure_t));
 failure->reason = (char *)emalloc((strlen(reason) + 1) * sizeof(char));
 strcpy(failure->reason, reason);
 failure->next = t->failures;
 t->failures = failure;
 t->failed = 1;
}

canonical_original_code:
void test_fail(struct test_t *t, char *reason)
{
 struct failure_t *failure;
 failure = (struct failure_t *)emalloc(sizeof(failure_t));
 failure->reason = (char *)emalloc((strlen(reason) + 1) * sizeof(char));
 strcpy(failure->reason, reason);
 failure->next = t->failures;
 t->failures = failure;
 t->failed = 1;
}

variable_types:
reason
char *

variable_types: struct failure_t { char *reason; struct failure_t *next; } *


decompiled_code:
_BOOL8 run_tests()
{
const char ***v0; // rbx
unsigned int v1; // er13
int v2; // er12
_BOOL8 result; // rax
const char *i; // rbp
__int64 v5; // rdx

v0 = (const char ***)r;
v1 = 0;
v2 = 0;
if ( r )
{
do
{
((void (__fastcall *)(const char **))(*v0)[3])(*v0);
++v2;
if ( *((_DWORD *)*v0 + 4) )
{
printf("FAIL: %s\n", **v0);
for ( i = (*v0)[1]; i; i = (const char *)*((_QWORD *)i + 1) )
printf(" %s\n", *(const char **)i);
putchar(10);
++v1;
}
v0 = (const char ***)v0[1];
}
while ( v0 );
free_suite();
v5 = 115LL;
if ( v2 <= 1 )
v5 = 0LL;
printf("Ran: %d test%c. Succeeded: %d. Failed: %d.\n", (unsigned int)v2, v5, v2 - v1, v1);
result = (int)v1 > 0;
}
else
{
puts("Warning: no tests to run.");
result = 0LL;
}
return result;
}

canonical_decompiled_code:
_BOOL8 func4()
{
const char ***v0; // rbx
unsigned int v1; // er13
int v2; // er12
_BOOL8 result; // rax
const char *i; // rbp
__int64 v5; // rdx

v0 = (const char ***)r;
v1 = 0;
v2 = 0;
if ( r )
{
do
{
((void (__fastcall *)(const char **))(*v0)[3])(*v0);
++v2;
if ( *((_DWORD *)*v0 + 4) )
{
printf("FAIL: %s\n", **v0);
for ( i = (*v0)[1]; i; i = (const char *)*((_QWORD *)i + 1) )
printf(" %s\n", *(const char **)i);
putchar(10);
++v1;
}
v0 = (const char ***)v0[1];
}
while ( v0 );
func2();
v5 = 115LL;
if ( v2 <= 1 )
v5 = 0LL;
printf("Ran: %d test%c. Succeeded: %d. Failed: %d.\n", (unsigned int)v2, v5, v2 - v1, v1);
result = (int)v1 > 0;
}
else
{
puts("Warning: no tests to run.");
result = 0LL;
}
return result;
}

original_code:
int
run_tests(void)
{
 registry_t *p = r;
 failure_t *f;
 int ran, failed, plural;
 ran = failed = 0;
 if(r == ((void *)0)) {
  printf("Warning: no tests to run.\n");
  return 0;
 }
 while(p != ((void *)0)) {
  p->item->fn(p->item);
  ran++;
  if(p->item->failed) {
   printf("FAIL: %s\n", p->item->name);
   f = p->item->failures;
   while(f != ((void *)0)) {
    printf("      %s\n", f->reason);
    f = f->next;
   }
   printf("\n");
   failed++;
  }
  p = p->next;
 }
 free_suite();
 plural = ran > 1 ? 's' : '\0';
 printf("Ran: %d test%c. Succeeded: %d. Failed: %d.\n", ran, plural, ran-failed, failed);
 return failed > 0;
}

canonical_original_code:
int run_tests()
{
 struct test_list_t *p = r;
 struct failure_t *f;
 int ran; int failed; int plural;
 ran = failed = 0;
 if(r == ((void *)0)) {
  printf("Warning: no tests to run.\n");
  return 0;
 }
 while(p != ((void *)0)) {
  p->item->fn(p->item);
  ran++;
  if(p->item->failed) {
   printf("FAIL: %s\n", p->item->name);
   f = p->item->failures;
   while(f != ((void *)0)) {
    printf("      %s\n", f->reason);
    f = f->next;
   }
   printf("\n");
   failed++;
  }
  p = p->next;
 }
 free_suite();
 plural = ran > 1 ? 's' : '\0';
 printf("Ran: %d test%c. Succeeded: %d. Failed: %d.\n", ran, plural, ran-failed, failed);
 return failed > 0;
}

variable_types: ran int

variable_types: failed int

variable_types: plural int

user_defined_types: struct failure_t { char *reason; struct failure_t *next; }


repo: ftnapps/pkg-sbbs

decompiled_code:
int safe_snprintf(char *s, size_t maxlen, const char *a3, ...)
{
int result; // eax
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

va_start(arg, a3);
result = vsnprintf(s, maxlen, a3, arg);
s[maxlen - 1] = 0;
if ( result > 0 && result >= (int)maxlen )
result = maxlen - 1;
return result;
}

canonical_decompiled_code:
int func0(char *s, size_t maxlen, const char *a3, ...)
{
int result; // eax
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

va_start(arg, a3);
result = vsnprintf(s, maxlen, a3, arg);
s[maxlen - 1] = 0;
if ( result > 0 && result >= (int)maxlen )
result = maxlen - 1;
return result;
}

original_code:
int safe_snprintf(char *dst, size_t size, const char *fmt, ...)
{
 va_list argptr;
 int numchars;
 __builtin_va_start(argptr,fmt);
 numchars= vsnprintf(dst,size,fmt,argptr);
 __builtin_va_end(argptr);
 dst[size-1]=0;
 if(numchars>=(int)size && numchars>0)
  numchars=size-1;
 return(numchars);
}

canonical_original_code:
int safe_snprintf(char *dst, unsigned long size, char *fmt, ...)
{
 __builtin_va_list argptr;
 int numchars;
 __builtin_va_start(argptr,fmt);
 numchars= vsnprintf(dst,size,fmt,argptr);
 __builtin_va_end(argptr);
 dst[size-1]=0;
 if(numchars>=(int)size && numchars>0)
  numchars=size-1;
 return(numchars);
}

variable_types:
dst
char *

variable_types:
fmt
char *

variable_types: numchars int


lastchar

decompiled_code:
__int64 __fastcall lastchar(const char *a1)
{
__int64 v1; // rbx
size_t v2; // rax

v1 = (__int64)a1;
v2 = strlen(a1);
if ( v2 )
v1 = (__int64)&a1[v2 - 1];
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1)
{
__int64 v1; // rbx
size_t v2; // rax

v1 = (__int64)a1;
v2 = strlen(a1);
if ( v2 )
v1 = (__int64)&a1[v2 - 1];
return v1;
}

original_code:
char* lastchar(const char* str)
{
 size_t len;
 len = strlen(str);
 if(len)
  return((char*)&str[len-1]);
 return((char*)str);
}

canonical_original_code:
char *lastchar(char *str)
{
 unsigned long len;
 len = strlen(str);
 if(len)
  return((char *)&str[len-1]);
 return((char *)str);
}

variable_types:
str
char *

variable_types:
len
unsigned long

return_type: char *


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

switch ( (char)a1 )
{
case 'a':
result = 7LL;
break;
case 'b':
result = 8LL;
break;
case 'e':
result = 27LL;
break;
case 'f':
result = 12LL;
break;
case 'n':
result = 10LL;
break;
case 'r':
result = 13LL;
break;
case 't':
result = 9LL;
break;
case 'v':
result = 11LL;
break;
default:
result = a1;
break;
}
return result;
}

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

switch ( (char)a1 )
{
case 'a':
result = 7LL;
break;
case 'b':
result = 8LL;
break;
case 'e':
result = 27LL;
break;
case 'f':
result = 12LL;
break;
case 'n':
result = 10LL;
break;
case 'r':
result = 13LL;
break;
case 't':
result = 9LL;
break;
case 'v':
result = 11LL;
break;
default:
result = a1;
break;
}
return result;
}

original_code:
char c_unescape_char(char ch)
{
 switch(ch) {
  case 'e': return(0x1b);
  case 'a': return('\a');
  case 'b': return('\b');
  case 'f': return('\f');
  case 'n': return('\n');
  case 'r': return('\r');
  case 't': return('\t');
  case 'v': return('\v');
 }
 return(ch);
}

variable_types: ch char

return_type: char


decompiled_code:
__int64 __fastcall c_unescape_char_ptr(char *a1, char **a2)
{
const __int32_t **v2; // rax
char v3; // r12
__int64 result; // rax

v2 = _ctype_toupper_loc();
v3 = *a1;
if ( (*v2)[*a1] == 88 )
return strtol(a1 + 1, a2, 16);
if ( ((*_ctype_b_loc())[v3] & 0x800) != 0 )
return strtol(a1 + 1, a2, 8);
result = c_unescape_char(v3);
if ( a2 )
*a2 = a1 + 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *a1, char **a2)
{
const __int32_t **v2; // rax
char v3; // r12
__int64 result; // rax

v2 = _ctype_toupper_loc();
v3 = *a1;
if ( (*v2)[*a1] == 88 )
return strtol(a1 + 1, a2, 16);
if ( ((*_ctype_b_loc())[v3] & 0x800) != 0 )
return strtol(a1 + 1, a2, 8);
result = func2(v3);
if ( a2 )
*a2 = a1 + 1;
return result;
}

original_code:
char c_unescape_char_ptr(const char* str, char** endptr)
{
 char ch;
 if(toupper(*str)=='X')
  ch=(char)strtol(++str,endptr,16);
 else if(((*__ctype_b_loc ())[(int) ((*str))] & (unsigned short int) _ISdigit))
  ch=(char)strtol(++str,endptr,8);
 else {
  ch=c_unescape_char(*(str++));
  if(endptr!=((void *)0))
   *endptr=(char*)str;
 }
 return(ch);
}

canonical_original_code:
char c_unescape_char_ptr(char *str, char **endptr)
{
 char ch;
 if(toupper(*str)=='X')
  ch=(char)strtol(++str,endptr,16);
 else if(((*__ctype_b_loc ())[(int) ((*str))] & (unsigned short) _ISdigit))
  ch=(char)strtol(++str,endptr,8);
 else {
  ch=c_unescape_char(*(str++));
  if(endptr!=((void *)0))
   *endptr=(char *)str;
 }
 return(ch);
}

variable_types:
endptr
char **


decompiled_code:
const char *__fastcall c_unescape_str(const char *a1)
{
const char *v1; // rbp
char *v2; // rax
char *v3; // r12
char *v4; // rdi
char v5; // al
char *v6; // rbx
char *v7; // rax
char *v9; // [rsp+8h] [rbp-20h] BYREF

v1 = a1;
if ( a1 )
{
v2 = strdup(a1);
v3 = v2;
if ( v2 )
{
v4 = v2 + 1;
v9 = v2 + 1;
v5 = *v2;
if ( v5 )
{
v6 = (char *)v1;
do
{
if ( v5 == 92 )
v5 = c_unescape_char_ptr(v4, &v9);
*v6++ = v5;
v7 = v9;
v4 = ++v9;
v5 = *v7;
}
while ( v5 );
}
else
{
v6 = (char *)v1;
}
*v6 = 0;
free(v3);
}
else
{
v1 = 0LL;
}
}
return v1;
}

canonical_decompiled_code:
const char *__fastcall func4(const char *a1)
{
const char *v1; // rbp
char *v2; // rax
char *v3; // r12
char *v4; // rdi
char v5; // al
char *v6; // rbx
char *v7; // rax
char *v9; // [rsp+8h] [rbp-20h] BYREF

v1 = a1;
if ( a1 )
{
v2 = strdup(a1);
v3 = v2;
if ( v2 )
{
v4 = v2 + 1;
v9 = v2 + 1;
v5 = *v2;
if ( v5 )
{
v6 = (char *)v1;
do
{
if ( v5 == 92 )
v5 = func3(v4, &v9);
*v6++ = v5;
v7 = v9;
v4 = ++v9;
v5 = *v7;
}
while ( v5 );
}
else
{
v6 = (char *)v1;
}
*v6 = 0;
free(v3);
}
else
{
v1 = 0LL;
}
}
return v1;
}

original_code:
char* c_unescape_str(char* str)
{
 char ch;
 char* buf;
 char* src;
 char* dst;
 if(str==((void *)0) || (buf=strdup(str))==((void *)0))
  return(((void *)0));
 src=buf;
 dst=str;
 while((ch=*(src++))!=0) {
  if(ch=='\\')
   ch=c_unescape_char_ptr(src,&src);
  *(dst++)=ch;
 }
 *dst=0;
 free(buf);
 return(str);
}

canonical_original_code:
char *c_unescape_str(char *str)
{
 char ch;
 char *buf;
 char *src;
 char *dst;
 if(str==((void *)0) || (buf=strdup(str))==((void *)0))
  return(((void *)0));
 src=buf;
 dst=str;
 while((ch=*(src++))!=0) {
  if(ch=='\\')
   ch=c_unescape_char_ptr(src,&src);
  *(dst++)=ch;
 }
 *dst=0;
 free(buf);
 return(str);
}

variable_types:
buf
char *

variable_types:
src
char *


decompiled_code:
const char *__fastcall c_escape_char(char a1)
{
const char *result; // rax

switch ( a1 )
{
case 0:
result = "\\x00";
break;
case 1:
result = "\\x01";
break;
case 7:
result = "\\a";
break;
case 8:
result = "\\b";
break;
case 9:
result = "\\t";
break;
case 10:
result = "\\n";
break;
case 11:
result = "\\v";
break;
case 12:
result = "\\f";
break;
case 13:
result = "\\r";
break;
case 27:
result = "\\e";
break;
case 34:
result = "\\\"";
break;
case 39:
result = "\\'";
break;
case 92:
result = "\\\\";
break;
default:
result = 0LL;
break;
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func5(char a1)
{
const char *result; // rax

switch ( a1 )
{
case 0:
result = "\\x00";
break;
case 1:
result = "\\x01";
break;
case 7:
result = "\\a";
break;
case 8:
result = "\\b";
break;
case 9:
result = "\\t";
break;
case 10:
result = "\\n";
break;
case 11:
result = "\\v";
break;
case 12:
result = "\\f";
break;
case 13:
result = "\\r";
break;
case 27:
result = "\\e";
break;
case 34:
result = "\\\"";
break;
case 39:
result = "\\'";
break;
case 92:
result = "\\\\";
break;
default:
result = 0LL;
break;
}
return result;
}

original_code:
char* c_escape_char(char ch)
{
 switch(ch) {
  case 0: return("\\x00");
  case 1: return("\\x01");
  case 0x1b: return("\\e");
  case '\a': return("\\a");
  case '\b': return("\\b");
  case '\f': return("\\f");
  case '\n': return("\\n");
  case '\r': return("\\r");
  case '\t': return("\\t");
  case '\v': return("\\v");
  case '\\': return("\\\\");
  case '\"': return("\\\"");
  case '\'': return("\\'");
 }
 return(((void *)0));
}

canonical_original_code:
char *c_escape_char(char ch)
{
 switch(ch) {
  case 0: return("\\x00");
  case 1: return("\\x01");
  case 0x1b: return("\\e");
  case '\a': return("\\a");
  case '\b': return("\\b");
  case '\f': return("\\f");
  case '\n': return("\\n");
  case '\r': return("\\r");
  case '\t': return("\\t");
  case '\v': return("\\v");
  case '\\': return("\\\\");
  case '\"': return("\\\"");
  case '\'': return("\\'");
 }
 return(((void *)0));
}


decompiled_code:
char *__fastcall c_escape_str(char *a1, char *a2, unsigned __int64 a3, int a4)
{
char v4; // bp
char *v5; // r12
char *v7; // rbx
signed __int64 v8; // r13
const char *v9; // rax

v4 = *a1;
if ( *a1 )
{
v5 = a1;
if ( a3 )
{
v7 = a2;
v8 = 0LL;
do
{
if ( a4 && (unsigned __int8)v4 > 0x1Fu || (v9 = c_escape_char(v4)) == 0LL )
{
*v7 = v4;
}
else
{
*v7 = 0;
strncat(a2, v9, a3 - v8);
++v7;
}
++v5;
++v7;
v4 = *v5;
if ( !*v5 )
break;
v8 = v7 - a2;
}
while ( v7 - a2 < a3 );
}
else
{
v7 = a2;
}
}
else
{
v7 = a2;
}
*v7 = 0;
return a2;
}

canonical_decompiled_code:
char *__fastcall func6(char *a1, char *a2, unsigned __int64 a3, int a4)
{
char v4; // bp
char *v5; // r12
char *v7; // rbx
signed __int64 v8; // r13
const char *v9; // rax

v4 = *a1;
if ( *a1 )
{
v5 = a1;
if ( a3 )
{
v7 = a2;
v8 = 0LL;
do
{
if ( a4 && (unsigned __int8)v4 > 0x1Fu || (v9 = func5(v4)) == 0LL )
{
*v7 = v4;
}
else
{
*v7 = 0;
strncat(a2, v9, a3 - v8);
++v7;
}
++v5;
++v7;
v4 = *v5;
if ( !*v5 )
break;
v8 = v7 - a2;
}
while ( v7 - a2 < a3 );
}
else
{
v7 = a2;
}
}
else
{
v7 = a2;
}
*v7 = 0;
return a2;
}

original_code:
char* c_escape_str(const char* src, char* dst, size_t maxlen, int ctrl_only)
{
 const char* s;
 char* d;
 char* e;
 for(s=src,d=dst;*s && (size_t)(d-dst)<maxlen;s++,d++) {
  if((!ctrl_only || (unsigned char)*s < ' ') && (e=c_escape_char(*s))!=((void *)0)) {
   *d=0;
   strncat(dst,e,maxlen-(d-dst));
   d++;
  } else *d=*s;
 }
 *d=0;
 return(dst);
}

canonical_original_code:
char *c_escape_str(char *src, char *dst, unsigned long maxlen, int ctrl_only)
{
 char *s;
 char *d;
 char *e;
 for(s=src,d=dst;*s && (unsigned long)(d-dst)<maxlen;s++,d++) {
  if((!ctrl_only || (unsigned char)*s < ' ') && (e=c_escape_char(*s))!=((void *)0)) {
   *d=0;
   strncat(dst,e,maxlen-(d-dst));
   d++;
  } else *d=*s;
 }
 *d=0;
 return(dst);
}

variable_types:
maxlen
unsigned long

variable_types:
s
char *

variable_types:
d
char *

variable_types:
e
char *


strrev

decompiled_code:
const char *__fastcall strrev(const char *a1)
{
char *v1; // rax
char *v2; // rdx
char v3; // cl

v1 = (char *)&a1[strlen(a1)];
if ( a1 < v1 )
{
v2 = (char *)a1;
do
{
v3 = *v2;
*v2++ = *--v1;
*v1 = v3;
}
while ( v1 > v2 );
}
return a1;
}

canonical_decompiled_code:
const char *__fastcall func9(const char *a1)
{
char *v1; // rax
char *v2; // rdx
char v3; // cl

v1 = (char *)&a1[strlen(a1)];
if ( a1 < v1 )
{
v2 = (char *)a1;
do
{
v3 = *v2;
*v2++ = *--v1;
*v1 = v3;
}
while ( v1 > v2 );
}
return a1;
}

original_code:
char* strrev(char* str)
{
    char t, *i=str, *j=str+strlen(str);
    while (i<j) {
        t=*i; *(i++)=*(--j); *j=t;
    }
    return str;
}

canonical_original_code:
char *strrev(char *str)
{
    char t; char *i = str; char *j = str+strlen(str);
    while (i<j) {
        t=*i; *(i++)=*(--j); *j=t;
    }
    return str;
}

variable_types: t char

variable_types:
i
char *

variable_types:
j
char *


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

result = 0LL;
if ( a1 > 1 )
result = (unsigned int)(random() % a1);
return result;
}

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

result = 0LL;
if ( a1 > 1 )
result = (unsigned int)(random() % a1);
return result;
}

original_code:
int xp_random(int n)
{
 if(n<2)
  return(0);
 return(random()%n);
}

variable_types: n int


ultoa

decompiled_code:
char *__fastcall ultoa(__int64 a1, char *a2, __int64 a3)
{
switch ( (_DWORD)a3 )
{
case 0xA:
sprintf(a2, "%lu", a1);
break;
case 0x10:
sprintf(a2, "%lx", a1);
break;
case 8:
sprintf(a2, "%lo", a1);
break;
default:
sprintf(a2, "bad radix: %d", a3);
break;
}
return a2;
}

canonical_decompiled_code:
char *__fastcall func12(__int64 a1, char *a2, __int64 a3)
{
switch ( (_DWORD)a3 )
{
case 0xA:
sprintf(a2, "%lu", a1);
break;
case 0x10:
sprintf(a2, "%lx", a1);
break;
case 8:
sprintf(a2, "%lo", a1);
break;
default:
sprintf(a2, "bad radix: %d", a3);
break;
}
return a2;
}

original_code:
char* ultoa(ulong val, char* str, int radix)
{
 switch(radix) {
  case 8:
   sprintf(str,"%lo",val);
   break;
  case 10:
   sprintf(str,"%lu",val);
   break;
  case 16:
   sprintf(str,"%lx",val);
   break;
  default:
   sprintf(str,"bad radix: %d",radix);
   break;
 }
 return(str);
}

canonical_original_code:
char *ultoa(unsigned long val, char *str, int radix)
{
 switch(radix) {
  case 8:
   sprintf(str,"%lo",val);
   break;
  case 10:
   sprintf(str,"%lu",val);
   break;
  case 16:
   sprintf(str,"%lx",val);
   break;
  default:
   sprintf(str,"bad radix: %d",radix);
   break;
 }
 return(str);
}

variable_types:
val
unsigned long

variable_types: radix int


decompiled_code:
char *__fastcall os_version(char *s)
{
int *v2; // rax
struct utsname v3; // [rsp+0h] [rbp-198h] BYREF

if ( uname(&v3) < 0 )
{
v2 = _errno_location();
sprintf(s, "Unix (uname errno: %d)", (unsigned int)*v2);
}
else
{
sprintf(s, "%s %s %s", v3.sysname, v3.release, v3.machine);
}
return s;
}

canonical_decompiled_code:
char *__fastcall func13(char *s)
{
int *v2; // rax
struct utsname v3; // [rsp+0h] [rbp-198h] BYREF

if ( uname(&v3) < 0 )
{
v2 = _errno_location();
sprintf(s, "Unix (uname errno: %d)", (unsigned int)*v2);
}
else
{
sprintf(s, "%s %s %s", v3.sysname, v3.release, v3.machine);
}
return s;
}

original_code:
char* os_version(char *str)
{
 struct utsname unixver;
 if(uname(&unixver)<0)
  sprintf(str,"Unix (uname errno: %d)",(*__errno_location ()));
 else
  sprintf(str,"%s %s %s"
   ,unixver.sysname
   ,unixver.release
   ,unixver.machine
   );
 return(str);
}

canonical_original_code:
char *os_version(char *str)
{
 struct utsname unixver;
 if(uname(&unixver)<0)
  sprintf(str,"Unix (uname errno: %d)",(*__errno_location ()));
 else
  sprintf(str,"%s %s %s"
   ,unixver.sysname
   ,unixver.release
   ,unixver.machine
   );
 return(str);
}

variable_types: struct utsname { char sysname[65]; char nodename[65]; char release[65]; char version[65]; char machine[65]; char __domainname[65]; }


decompiled_code:
char *os_cmdshell()
{
return getenv("SHELL");
}

canonical_decompiled_code:
char *func14()
{
return getenv("SHELL");
}

original_code:
char* os_cmdshell(void)
{
 char* shell=getenv("SHELL");
 return(shell);
}

canonical_original_code:
char *os_cmdshell()
{
 char *shell = getenv("SHELL");
 return(shell);
}

variable_types:
shell
char *


msclock

decompiled_code:
__suseconds_t msclock()
{
__suseconds_t result; // rax
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

if ( gettimeofday(&v1, 0LL) == 1 )
result = -1LL;
else
result = (v1.tv_usec + 1000000 * v1.tv_sec) / 1000;
return result;
}

canonical_decompiled_code:
__suseconds_t func15()
{
__suseconds_t result; // rax
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

if ( gettimeofday(&v1, 0LL) == 1 )
result = -1LL;
else
result = (v1.tv_usec + 1000000 * v1.tv_sec) / 1000;
return result;
}

original_code:
clock_t msclock(void)
{
 long long int usecs;
 struct timeval tv;
 if(gettimeofday(&tv,((void *)0))==1)
  return(-1);
 usecs=tv.tv_sec*1000000+tv.tv_usec;
 return((clock_t)(usecs/(1000000/1000)));
}

canonical_original_code:
long msclock()
{
 long long usecs;
 struct timeval tv;
 if(gettimeofday(&tv,((void *)0))==1)
  return(-1);
 usecs=tv.tv_sec*1000000+tv.tv_usec;
 return((clock_t)(usecs/(1000000/1000)));
}

variable_types:
usecs
long long

variable_types: struct timeval { long tv_sec; long tv_usec; }

return_type: long


decompiled_code:
const char *__fastcall truncsp_lines(const char *a1)
{
const char *v1; // rbx
char *v2; // rax
char *v3; // r8
char v4; // cl
const char *v5; // rax
char *v6; // rdi
char v7; // dl
_BYTE *v8; // rdx

v1 = a1;
v2 = strdup(a1);
if ( v2 )
{
v3 = v2;
v4 = *v2;
if ( *v2 )
{
v5 = a1;
v6 = v3;
do
{
v8 = v5;
if ( v4 == 10 && v1 != v5 )
{
do
{
v7 = *(v5 - 1);
if ( (v7 & 0xFB) != 9 && v7 != 32 )
{
v8 = v5;
goto LABEL_10;
}
if ( v7 == 10 )
{
v8 = v5;
goto LABEL_10;
}
--v5;
}
while ( v1 != v5 );
v8 = v5;
}
LABEL_10:
v5 = v8 + 1;
*v8 = v4;
v4 = *++v6;
}
while ( *v6 );
}
else
{
v5 = a1;
}
*v5 = 0;
free(v3);
}
return v1;
}

original_code:
char* truncsp_lines(char* dst)
{
 char* sp;
 char* dp;
 char* src;
 if((src=strdup(dst))==((void *)0))
  return(dst);
 for(sp=src, dp=dst; *sp!=0; sp++) {
  if(*sp=='\n')
   while(dp!=dst
    && (*(dp-1)==' ' || *(dp-1)=='\t' || *(dp-1)=='\r') && *(dp-1)!='\n')
     dp--;
  *(dp++)=*sp;
 }
 *dp=0;
 free(src);
 return(dst);
}

canonical_original_code:
char *truncsp_lines(char *dst)
{
 char *sp;
 char *dp;
 char *src;
 if((src=strdup(dst))==((void *)0))
  return(dst);
 for(sp=src, dp=dst; *sp!=0; sp++) {
  if(*sp=='\n')
   while(dp!=dst
    && (*(dp-1)==' ' || *(dp-1)=='\t' || *(dp-1)=='\r') && *(dp-1)!='\n')
     dp--;
  *(dp++)=*sp;
 }
 *dp=0;
 free(src);
 return(dst);
}

variable_types:
dst
char *

variable_types:
sp
char *

variable_types:
dp
char *


truncnl

decompiled_code:
const char *__fastcall truncnl(const char *a1)
{
size_t v1; // rax
size_t v2; // rsi
char v3; // dl

v1 = strlen(a1);
v2 = v1;
while ( v1 )
{
v3 = a1[v1 - 1];
if ( v3 != 13 && v3 != 10 )
break;
--v1;
}
if ( v2 != v1 )
a1[v1] = 0;
return a1;
}

canonical_decompiled_code:
const char *__fastcall func18(const char *a1)
{
size_t v1; // rax
size_t v2; // rsi
char v3; // dl

v1 = strlen(a1);
v2 = v1;
while ( v1 )
{
v3 = a1[v1 - 1];
if ( v3 != 13 && v3 != 10 )
break;
--v1;
}
if ( v2 != v1 )
a1[v1] = 0;
return a1;
}

original_code:
char* truncnl(char* str)
{
 size_t i,len;
 i=len=strlen(str);
 while(i && (str[i-1]=='\r' || str[i-1]=='\n'))
  i--;
 if(i!=len)
  str[i]=0;
 return(str);
}

canonical_original_code:
char *truncnl(char *str)
{
 unsigned long i; unsigned long len;
 i=len=strlen(str);
 while(i && (str[i-1]=='\r' || str[i-1]=='\n'))
  i--;
 if(i!=len)
  str[i]=0;
 return(str);
}

variable_types:
str
char *

variable_types:
i
unsigned long

variable_types:
len
unsigned long


decompiled_code:
__int64 get_errno()
{
return (unsigned int)*_errno_location();
}

canonical_decompiled_code:
__int64 func19()
{
return (unsigned int)*_errno_location();
}

original_code:
int get_errno(void)
{
 return((*__errno_location ()));
}

canonical_original_code:
int get_errno()
{
 return((*__errno_location ()));
}


decompiled_code:
long double xp_timer()
{
long double result; // fst7
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

if ( gettimeofday(&v1, 0LL) == 1 )
result = -1.0;
else
result = (long double)v1.tv_usec / 1000000.0 + (long double)v1.tv_sec;
return result;
}

canonical_decompiled_code:
long double func20()
{
long double result; // fst7
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

if ( gettimeofday(&v1, 0LL) == 1 )
result = -1.0;
else
result = (long double)v1.tv_usec / 1000000.0 + (long double)v1.tv_sec;
return result;
}

original_code:
long double xp_timer(void)
{
 long double ret;
 struct timeval tv;
 if(gettimeofday(&tv,((void *)0))==1)
  return(-1);
 ret=tv.tv_usec;
 ret /= 1000000;
 ret += tv.tv_sec;
 return(ret);
}

canonical_original_code:
long double xp_timer()
{
 long double ret;
 struct timeval tv;
 if(gettimeofday(&tv,((void *)0))==1)
  return(-1);
 ret=tv.tv_usec;
 ret /= 1000000;
 ret += tv.tv_sec;
 return(ret);
}

variable_types:
ret
long double

return_type: long double

user_defined_types: struct timeval { long tv_sec; long tv_usec; }


ydecode

decompiled_code:
unsigned __int64 __fastcall ydecode(__int64 a1, unsigned __int64 a2, const char *a3, size_t a4)
{
size_t v7; // rdi
unsigned __int64 result; // rax
size_t v9; // rcx
size_t v10; // rsi
char v11; // dl

v7 = a4;
if ( !a4 )
v7 = strlen(a3);
if ( !v7 )
return 0LL;
result = 0LL;
v9 = 0LL;
if ( !a2 )
return 0LL;
do
{
v10 = v9 + 1;
v11 = a3[v9];
if ( v11 == 61 && v10 < v7 )
{
v9 += 2LL;
v11 = a3[v10] - 64;
}
else
{
++v9;
}
++result;
*(_BYTE *)(a1 + result - 1) = v11 - 42;
}
while ( v9 < v7 && a2 > result );
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func0(__int64 a1, unsigned __int64 a2, const char *a3, size_t a4)
{
size_t v7; // rdi
unsigned __int64 result; // rax
size_t v9; // rcx
size_t v10; // rsi
char v11; // dl

v7 = a4;
if ( !a4 )
v7 = strlen(a3);
if ( !v7 )
return 0LL;
result = 0LL;
v9 = 0LL;
if ( !a2 )
return 0LL;
do
{
v10 = v9 + 1;
v11 = a3[v9];
if ( v11 == 61 && v10 < v7 )
{
v9 += 2LL;
v11 = a3[v10] - 64;
}
else
{
++v9;
}
++result;
*(_BYTE *)(a1 + result - 1) = v11 - 42;
}
while ( v9 < v7 && a2 > result );
return result;
}

original_code:
int ydecode(char *target, size_t tlen, const char *source, size_t slen)
{
 char ch;
 size_t rd=0;
 size_t wr=0;
 if(slen==0)
  slen=strlen(source);
 while(rd<slen && wr<tlen) {
  ch=source[rd++];
  if(ch=='=' && rd<slen)
   ch=source[rd++]-64;
  ch-=42;
  target[wr++]=ch;
 }
 return(wr);
}

canonical_original_code:
int ydecode(char *target, unsigned long tlen, char *source, unsigned long slen)
{
 char ch;
 unsigned long rd = 0;
 unsigned long wr = 0;
 if(slen==0)
  slen=strlen(source);
 while(rd<slen && wr<tlen) {
  ch=source[rd++];
  if(ch=='=' && rd<slen)
   ch=source[rd++]-64;
  ch-=42;
  target[wr++]=ch;
 }
 return(wr);
}

variable_types:
target
char *

variable_types:
tlen
unsigned long

variable_types:
source
char *

variable_types:
slen
unsigned long

variable_types: ch char

variable_types:
rd
unsigned long

variable_types:
wr
unsigned long


yencode

decompiled_code:
unsigned __int64 __fastcall yencode(__int64 a1, unsigned __int64 a2, const char *a3, size_t a4)
{
size_t v7; // r8
unsigned __int64 result; // rax
size_t v9; // rdx
unsigned __int64 v10; // rsi
char v11; // cl
char v12; // di

v7 = a4;
if ( !a4 )
v7 = strlen(a3);
result = 0LL;
v9 = 0LL;
if ( !a2 )
return 0LL;
do
{
v12 = a3[v9++];
v11 = v12 + 42;
if ( (unsigned __int8)(v12 + 42) <= 0x3Du && ((1LL << v11) & 0x2000000000002401LL) != 0 )
{
v10 = result + 1;
if ( result + 1 >= a2 )
break;
v11 = v12 + 106;
*(_BYTE *)(a1 + result) = 61;
}
else
{
v10 = result;
}
result = v10 + 1;
*(_BYTE *)(a1 + v10) = v11;
}
while ( v9 <= v7 && a2 > result );
if ( a2 > result )
*(_BYTE *)(a1 + result++) = 0;
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func1(__int64 a1, unsigned __int64 a2, const char *a3, size_t a4)
{
size_t v7; // r8
unsigned __int64 result; // rax
size_t v9; // rdx
unsigned __int64 v10; // rsi
char v11; // cl
char v12; // di

v7 = a4;
if ( !a4 )
v7 = strlen(a3);
result = 0LL;
v9 = 0LL;
if ( !a2 )
return 0LL;
do
{
v12 = a3[v9++];
v11 = v12 + 42;
if ( (unsigned __int8)(v12 + 42) <= 0x3Du && ((1LL << v11) & 0x2000000000002401LL) != 0 )
{
v10 = result + 1;
if ( result + 1 >= a2 )
break;
v11 = v12 + 106;
*(_BYTE *)(a1 + result) = 61;
}
else
{
v10 = result;
}
result = v10 + 1;
*(_BYTE *)(a1 + v10) = v11;
}
while ( v9 <= v7 && a2 > result );
if ( a2 > result )
*(_BYTE *)(a1 + result++) = 0;
return result;
}

original_code:
int yencode(char *target, size_t tlen, const char *source, size_t slen)
{
 char ch;
 size_t rd=0;
 size_t wr=0;
 int done=0;
 if(slen==0)
  slen=strlen(source);
 while(rd<=slen && wr<tlen && !done) {
  ch=source[rd++];
  ch+=42;
  switch(ch) {
   case 0:
   case '\r':
   case '\n':
   case '=':
    if(wr+1>=tlen) {
     done=1;
     continue;
    }
    ch+=64;
    target[wr++]='=';
    break;
  }
  target[wr++]=ch;
 }
 if(wr<tlen)
  target[wr++]=0;
 return(wr);
}

canonical_original_code:
int yencode(char *target, unsigned long tlen, char *source, unsigned long slen)
{
 char ch;
 unsigned long rd = 0;
 unsigned long wr = 0;
 int done = 0;
 if(slen==0)
  slen=strlen(source);
 while(rd<=slen && wr<tlen && !done) {
  ch=source[rd++];
  ch+=42;
  switch(ch) {
   case 0:
   case '\r':
   case '\n':
   case '=':
    if(wr+1>=tlen) {
     done=1;
     continue;
    }
    ch+=64;
    target[wr++]='=';
    break;
  }
  target[wr++]=ch;
 }
 if(wr<tlen)
  target[wr++]=0;
 return(wr);
}

variable_types: done int