disconnectirc

decompiled_code:
__int64 __fastcall disconnectirc(int fd)
{
unsigned int v1; // er12

v1 = quit("Terminated...", fd);
sleep(1u);
if ( close(fd) == -1 )
errprint("close(sckt)");
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func11(int fd)
{
unsigned int v1; // er12

v1 = func10("Terminated...", fd);
sleep(1u);
if ( close(fd) == -1 )
errprint("close(sckt)");
return v1;
}

original_code:
int disconnectirc(int sckt)
{
    int ret;
    ret = quit("Terminated...", sckt);
    sleep(1);
    if (close(sckt) == -1) {
        errprint("close(sckt)");
    }
    return ret;
}


strfind

decompiled_code:
__int64 __fastcall strfind(char *s1, char *s2)
{
char *v2; // rbx
char *v3; // r12
size_t v4; // rax
const char *v5; // rdi

v2 = s1;
v3 = &s1[strnlen(s1, 0x400uLL)];
do
{
if ( v2 == v3 )
return 0LL;
v4 = strnlen(s2, 0x400uLL);
v5 = v2++;
}
while ( strncmp(v5, s2, v4) );
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *s1, char *s2)
{
char *v2; // rbx
char *v3; // r12
size_t v4; // rax
const char *v5; // rdi

v2 = s1;
v3 = &s1[strnlen(s1, 0x400uLL)];
do
{
if ( v2 == v3 )
return 0LL;
v4 = strnlen(s2, 0x400uLL);
v5 = v2++;
}
while ( strncmp(v5, s2, v4) );
return 1LL;
}

original_code:
int strfind(char *s1, char *s2)
{
    int i;
    for (i=0; i<strnlen(s1, 1024); i++) {
        if (strncmp(s1+i, s2, strnlen(s2, 1024)) == 0) {
            return 1;
        }
    }
    return 0;
}

variable_types: i int

return_type: int


getmsg

decompiled_code:
__int64 __fastcall getmsg(char *s, const char *a2)
{
__int64 v2; // r13
size_t v3; // r14
size_t v4; // rbx
unsigned int v5; // er12
char v7[1064]; // [rsp+0h] [rbp-428h] BYREF

v2 = 0LL;
snprintf(v7, 0x400uLL, "%s", a2);
v3 = strnlen(s, 0x400uLL);
while ( 1 )
{
if ( v3 == v2 )
return (unsigned int)-1;
v4 = strnlen(v7, 0x400uLL);
v5 = strncmp(&s[v2], v7, v4);
if ( !v5 )
break;
++v2;
}
snprintf(s, 0x400uLL, "%s", &s[v4 + v2]);
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func4(char *s, const char *a2)
{
__int64 v2; // r13
size_t v3; // r14
size_t v4; // rbx
unsigned int v5; // er12
char v7[1064]; // [rsp+0h] [rbp-428h] BYREF

v2 = 0LL;
snprintf(v7, 0x400uLL, "%s", a2);
v3 = strnlen(s, 0x400uLL);
while ( 1 )
{
if ( v3 == v2 )
return (unsigned int)-1;
v4 = strnlen(v7, 0x400uLL);
v5 = strncmp(&s[v2], v7, v4);
if ( !v5 )
break;
++v2;
}
snprintf(s, 0x400uLL, "%s", &s[v4 + v2]);
return v5;
}

original_code:
int getmsg(char *s, char *key)
{
    int i;
    char tmp[1024];
    snprintf(tmp, 1024, "%s", key);
    for (i=0; i<strnlen(s, 1024); i++) {
        if (strncmp(s+i, tmp, strnlen(tmp, 1024)) == 0) {
            snprintf(s, 1024, "%s", s+i+strnlen(tmp, 1024));
            return 0;
        }
    }
    return -1;
}

variable_types:
s
char *

variable_types:
key
char *

variable_types:
tmp
char [1024]


usernamecount

decompiled_code:
__int64 __fastcall usernamecount(const char *a1)
{
size_t v1; // rcx
unsigned __int64 v2; // rax
char v3; // dl
int v4; // esi

v1 = strnlen(a1, 0x400uLL);
v2 = 2LL;
do
{
v4 = v2;
if ( v1 <= v2 )
return 0xFFFFFFFFLL;
v3 = a1[v2++];
}
while ( v3 != 33 );
return (unsigned int)(v4 - 1);
}

canonical_decompiled_code:
__int64 __fastcall func5(const char *a1)
{
size_t v1; // rcx
unsigned __int64 v2; // rax
char v3; // dl
int v4; // esi

v1 = strnlen(a1, 0x400uLL);
v2 = 2LL;
do
{
v4 = v2;
if ( v1 <= v2 )
return 0xFFFFFFFFLL;
v3 = a1[v2++];
}
while ( v3 != 33 );
return (unsigned int)(v4 - 1);
}

original_code:
int usernamecount(char *s)
{
    int i;
    for (i=2; i<strnlen(s, 1024); i++) {
        if (strncmp(s+i, "!", strnlen("!", 1024)) == 0) {
            return i-1;
        }
    }
    return -1;
}


osinfo

decompiled_code:
__int64 __fastcall osinfo(char *dest)
{
size_t v1; // rax
size_t v2; // rax
size_t v3; // rax
size_t v4; // rax
size_t v5; // rax
__int64 result; // rax
struct utsname name; // [rsp+10h] [rbp-1A8h] BYREF

if ( uname(&name) == -1 )
{
errprint("uname()");
result = 0xFFFFFFFFLL;
}
else
{
strcpy(dest, "System: ");
v1 = strnlen(dest, 0x400uLL);
strncat(dest, name.sysname, 1023 - v1);
v2 = strnlen(dest, 0x400uLL);
strncat(dest, ", release: ", 1023 - v2);
v3 = strnlen(dest, 0x400uLL);
strncat(dest, name.release, 1023 - v3);
v4 = strnlen(dest, 0x400uLL);
strncat(dest, ", architecture: ", 1023 - v4);
v5 = strnlen(dest, 0x400uLL);
strncat(dest, name.machine, 1023 - v5);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(char *dest)
{
size_t v1; // rax
size_t v2; // rax
size_t v3; // rax
size_t v4; // rax
size_t v5; // rax
__int64 result; // rax
struct utsname name; // [rsp+10h] [rbp-1A8h] BYREF

if ( uname(&name) == -1 )
{
func1("uname()");
result = 0xFFFFFFFFLL;
}
else
{
strcpy(dest, "System: ");
v1 = strnlen(dest, 0x400uLL);
strncat(dest, name.sysname, 1023 - v1);
v2 = strnlen(dest, 0x400uLL);
strncat(dest, ", release: ", 1023 - v2);
v3 = strnlen(dest, 0x400uLL);
strncat(dest, name.release, 1023 - v3);
v4 = strnlen(dest, 0x400uLL);
strncat(dest, ", architecture: ", 1023 - v4);
v5 = strnlen(dest, 0x400uLL);
strncat(dest, name.machine, 1023 - v5);
result = 0LL;
}
return result;
}

original_code:
int osinfo(char *info)
{
    struct utsname name;
    if (uname(&name) == -1) {
        errprint("uname()");
        return -1;
    }
    snprintf(info, 1024, "%s", "System: ");
    strncat(info, name.sysname, 1024 -strnlen(info, 1024)-1);
    strncat(info, ", release: ", 1024 -strnlen(info, 1024)-1);
    strncat(info, name.release, 1024 -strnlen(info, 1024)-1);
    strncat(info, ", architecture: ", 1024 -strnlen(info, 1024)-1);
    strncat(info, name.machine, 1024 -strnlen(info, 1024)-1);
    return 0;
}

variable_types:
info
char *

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


readline

decompiled_code:
__int64 __fastcall readline(int fd, _BYTE *a2, __int64 a3)
{
__int64 v4; // r12
__int64 v5; // rbx
ssize_t v6; // rax
char v7; // al
char buf[41]; // [rsp+Fh] [rbp-29h] BYREF

if ( a3 <= 1 )
{
v4 = 1LL;
}
else
{
v4 = a3;
v5 = 1LL;
while ( 1 )
{
while ( 1 )
{
v6 = read(fd, buf, 1uLL);
if ( v6 != 1 )
break;
v7 = buf[0];
*a2 = buf[0];
if ( v7 == 10 )
{
v4 = v5;
++a2;
goto LABEL_9;
}
++v5;
++a2;
if ( v5 == v4 )
goto LABEL_9;
}
if ( !v6 )
break;
if ( *_errno_location() != 4 )
return -1LL;
if ( ++v5 == v4 )
goto LABEL_9;
}
v4 = 0LL;
if ( v5 == 1 )
return v4;
v4 = v5;
}
LABEL_9:
*a2 = 0;
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func9(int fd, _BYTE *a2, __int64 a3)
{
__int64 v4; // r12
__int64 v5; // rbx
ssize_t v6; // rax
char v7; // al
char buf[41]; // [rsp+Fh] [rbp-29h] BYREF

if ( a3 <= 1 )
{
v4 = 1LL;
}
else
{
v4 = a3;
v5 = 1LL;
while ( 1 )
{
while ( 1 )
{
v6 = read(fd, buf, 1uLL);
if ( v6 != 1 )
break;
v7 = buf[0];
*a2 = buf[0];
if ( v7 == 10 )
{
v4 = v5;
++a2;
goto LABEL_9;
}
++v5;
++a2;
if ( v5 == v4 )
goto LABEL_9;
}
if ( !v6 )
break;
if ( *_errno_location() != 4 )
return -1LL;
if ( ++v5 == v4 )
goto LABEL_9;
}
v4 = 0LL;
if ( v5 == 1 )
return v4;
v4 = v5;
}
LABEL_9:
*a2 = 0;
return v4;
}

original_code:
ssize_t readline(int fd, void *vptr, size_t maxlen)
{
    ssize_t n, rc;
    char c, *ptr;
    ptr = vptr;
    for (n=1; n < (ssize_t)maxlen; n++) {
        if((rc=read(fd, &c, 1)) == 1) {
            *ptr++ = c;
            if (c == '\n') {
                break;
            }
        } else if (rc == 0) {
            if (n == 1) {
                return (0);
            } else {
                break;
            }
        } else if ((*__errno_location ()) != 4) {
            return -1;
        }
    }
    *ptr = '\0';
    return n;
}

canonical_original_code:
long readline(int fd, void *vptr, unsigned long maxlen)
{
    long n; long rc;
    char c; char *ptr;
    ptr = vptr;
    for (n=1; n < (long)maxlen; n++) {
        if((rc=read(fd, &c, 1)) == 1) {
            *ptr++ = c;
            if (c == '\n') {
                break;
            }
        } else if (rc == 0) {
            if (n == 1) {
                return (0);
            } else {
                break;
            }
        } else if ((*__errno_location ()) != 4) {
            return -1;
        }
    }
    *ptr = '\0';
    return n;
}

variable_types: fd int

variable_types:
vptr
void *

variable_types:
maxlen
unsigned long

variable_types: n long

variable_types: rc long

variable_types: c char

variable_types:
ptr
char *

return_type: long


repo: fsferrara/legacy-address-book

decompiled_code:
int apri_file_r()
{
int result; // eax

result = open("./rubrica", 0, 436LL);
if ( result == -1 )
{
perror("open di apri_file_r()");
exit(1);
}
return result;
}

canonical_decompiled_code:
int func0()
{
int result; // eax

result = open("./rubrica", 0, 436LL);
if ( result == -1 )
{
perror("open di apri_file_r()");
exit(1);
}
return result;
}

original_code:
int apri_file_r(void) {
 int fd;
 if((fd = open("./rubrica", 00, 0664)) == -1)
  perror("open di apri_file_r()"), exit(1);
 return fd;
}

canonical_original_code:
int apri_file_r() {
 int fd;
 if((fd = open("./rubrica", 00, 0664)) == -1)
  perror("open di apri_file_r()"), exit(1);
 return fd;
}


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

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

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

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

original_code:
void chiudi_file(int fd) {
 if (close(fd) == -1)
  perror("close di chiudi_file()"), exit(1);
}

return_type: void


original_code:
int leggi_record(int fd, struct contatto *record, int *posizione) {
 ssize_t letto;
 int i;
 char buffer;
 i=0;
 buffer='\t';
 while(buffer != '\0') {
  switch((letto=read(fd, &buffer, sizeof(char)))) {
   case sizeof(char):
    if (buffer == '\t') {
     buffer = '\0';
    }
    record->nome[i++]=buffer;
    (*posizione)++;
    break;
   case 0:
    return 1;
    break;
   default:
    perror("read di leggi_record()");
    exit(1);
    break;
  }
 }
 i=0;
 buffer='\t';
 while(buffer != '\0') {
  switch((letto=read(fd, &buffer, sizeof(char)))) {
   case sizeof(char):
    if (buffer == '\t') {
     buffer = '\0';
    }
    record->cognome[i++]=buffer;
    (*posizione)++;
    break;
   case 0:
    return 1;
    break;
   default:
    perror("read di leggi_record()");
    exit(1);
    break;
  }
 }
 i=0;
 buffer='\t';
 while(buffer != '\0') {
  switch((letto=read(fd, &buffer, sizeof(char)))) {
   case sizeof(char):
    if (buffer == '\t') {
     buffer = '\0';
    }
    record->indirizzo[i++]=buffer;
    (*posizione)++;
    break;
   case 0:
    return 1;
    break;
   default:
    perror("read di leggi_record()");
    exit(1);
    break;
  }
 }
 i=0;
 buffer='\t';
 while(buffer != '\0') {
  switch((letto=read(fd, &buffer, sizeof(char)))) {
   case sizeof(char):
    if (buffer == '\t') {
     buffer = '\0';
    }
    record->telefono[i++]=buffer;
    (*posizione)++;
    break;
   case 0:
    return 1;
    break;
   default:
    perror("read di leggi_record()");
    exit(1);
    break;
  }
 }
 i=0;
 buffer='\t';
 while(buffer != '\0') {
  switch((letto=read(fd, &buffer, sizeof(char)))) {
   case sizeof(char):
    if (buffer == '\t') {
     buffer = '\0';
    }
    record->email[i++]=buffer;
    (*posizione)++;
    break;
   case 0:
    return 1;
    break;
   default:
    perror("read di leggi_record()");
    exit(1);
    break;
  }
 }
 i=0;
 buffer='\t';
 while(buffer != '\n') {
  switch((letto=read(fd, &buffer, sizeof(char)))) {
   case sizeof(char):
    if (buffer != '\n')
     record->marcatura=buffer;
    (*posizione)++;
    break;
   case 0:
    return 1;
    break;
   default:
    perror("read di leggi_record()");
    exit(1);
    break;
  }
 }
 return 0;
}

canonical_original_code:
int leggi_record(int fd, struct contatto *record, int *posizione) {
 long letto;
 int i;
 char buffer;
 i=0;
 buffer='\t';
 while(buffer != '\0') {
  switch((letto=read(fd, &buffer, sizeof(char)))) {
   case sizeof(char):
    if (buffer == '\t') {
     buffer = '\0';
    }
    record->nome[i++]=buffer;
    (*posizione)++;
    break;
   case 0:
    return 1;
    break;
   default:
    perror("read di leggi_record()");
    exit(1);
    break;
  }
 }
 i=0;
 buffer='\t';
 while(buffer != '\0') {
  switch((letto=read(fd, &buffer, sizeof(char)))) {
   case sizeof(char):
    if (buffer == '\t') {
     buffer = '\0';
    }
    record->cognome[i++]=buffer;
    (*posizione)++;
    break;
   case 0:
    return 1;
    break;
   default:
    perror("read di leggi_record()");
    exit(1);
    break;
  }
 }
 i=0;
 buffer='\t';
 while(buffer != '\0') {
  switch((letto=read(fd, &buffer, sizeof(char)))) {
   case sizeof(char):
    if (buffer == '\t') {
     buffer = '\0';
    }
    record->indirizzo[i++]=buffer;
    (*posizione)++;
    break;
   case 0:
    return 1;
    break;
   default:
    perror("read di leggi_record()");
    exit(1);
    break;
  }
 }
 i=0;
 buffer='\t';
 while(buffer != '\0') {
  switch((letto=read(fd, &buffer, sizeof(char)))) {
   case sizeof(char):
    if (buffer == '\t') {
     buffer = '\0';
    }
    record->telefono[i++]=buffer;
    (*posizione)++;
    break;
   case 0:
    return 1;
    break;
   default:
    perror("read di leggi_record()");
    exit(1);
    break;
  }
 }
 i=0;
 buffer='\t';
 while(buffer != '\0') {
  switch((letto=read(fd, &buffer, sizeof(char)))) {
   case sizeof(char):
    if (buffer == '\t') {
     buffer = '\0';
    }
    record->email[i++]=buffer;
    (*posizione)++;
    break;
   case 0:
    return 1;
    break;
   default:
    perror("read di leggi_record()");
    exit(1);
    break;
  }
 }
 i=0;
 buffer='\t';
 while(buffer != '\n') {
  switch((letto=read(fd, &buffer, sizeof(char)))) {
   case sizeof(char):
    if (buffer != '\n')
     record->marcatura=buffer;
    (*posizione)++;
    break;
   case 0:
    return 1;
    break;
   default:
    perror("read di leggi_record()");
    exit(1);
    break;
  }
 }
 return 0;
}

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

variable_types:
posizione
int *

variable_types: letto long

variable_types: buffer char


decompiled_code:
__int64 __fastcall scrivi_record(int fd, void *buf, _DWORD *a3)
{
bool v4; // zf
_BYTE *v5; // r12
_BYTE *v6; // r12
_BYTE *v7; // r12
_BYTE *v8; // r12
_BYTE *v9; // r12
__int64 result; // rax
char bufa; // [rsp+Eh] [rbp-2Ah] BYREF
char v12[41]; // [rsp+Fh] [rbp-29h] BYREF

v4 = *(_BYTE *)buf == 0;
bufa = 9;
v12[0] = 10;
if ( !v4 )
{
v5 = buf;
while ( write(fd, v5, 1uLL) == 1 )
{
++v5;
++*a3;
if ( !*v5 )
goto LABEL_5;
}
LABEL_29:
perror("write");
exit(1);
}
LABEL_5:
if ( write(fd, &bufa, 1uLL) != 1 )
goto LABEL_29;
++*a3;
if ( *((_BYTE *)buf + 40) )
{
v6 = (char *)buf + 40;
while ( write(fd, v6, 1uLL) == 1 )
{
++v6;
++*a3;
if ( !*v6 )
goto LABEL_10;
}
goto LABEL_29;
}
LABEL_10:
if ( write(fd, &bufa, 1uLL) != 1 )
goto LABEL_29;
++*a3;
if ( *((_BYTE *)buf + 80) )
{
v7 = (char *)buf + 80;
while ( write(fd, v7, 1uLL) == 1 )
{
++v7;
++*a3;
if ( !*v7 )
goto LABEL_15;
}
goto LABEL_29;
}
LABEL_15:
if ( write(fd, &bufa, 1uLL) != 1 )
goto LABEL_29;
++*a3;
if ( *((_BYTE *)buf + 170) )
{
v8 = (char *)buf + 170;
while ( write(fd, v8, 1uLL) == 1 )
{
++v8;
++*a3;
if ( !*v8 )
goto LABEL_20;
}
goto LABEL_29;
}
LABEL_20:
if ( write(fd, &bufa, 1uLL) != 1 )
goto LABEL_29;
++*a3;
if ( *((_BYTE *)buf + 210) )
{
v9 = (char *)buf + 210;
while ( write(fd, v9, 1uLL) == 1 )
{
++v9;
++*a3;
if ( !*v9 )
goto LABEL_25;
}
goto LABEL_29;
}
LABEL_25:
if ( write(fd, &bufa, 1uLL) != 1 )
goto LABEL_29;
++*a3;
if ( write(fd, (char *)buf + 250, 1uLL) != 1 )
goto LABEL_29;
++*a3;
if ( write(fd, v12, 1uLL) != 1 )
goto LABEL_29;
result = (unsigned int)(*a3 + 1);
*a3 = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(int fd, void *buf, _DWORD *a3)
{
bool v4; // zf
_BYTE *v5; // r12
_BYTE *v6; // r12
_BYTE *v7; // r12
_BYTE *v8; // r12
_BYTE *v9; // r12
__int64 result; // rax
char bufa; // [rsp+Eh] [rbp-2Ah] BYREF
char v12[41]; // [rsp+Fh] [rbp-29h] BYREF

v4 = *(_BYTE *)buf == 0;
bufa = 9;
v12[0] = 10;
if ( !v4 )
{
v5 = buf;
while ( write(fd, v5, 1uLL) == 1 )
{
++v5;
++*a3;
if ( !*v5 )
goto LABEL_5;
}
LABEL_29:
perror("write");
exit(1);
}
LABEL_5:
if ( write(fd, &bufa, 1uLL) != 1 )
goto LABEL_29;
++*a3;
if ( *((_BYTE *)buf + 40) )
{
v6 = (char *)buf + 40;
while ( write(fd, v6, 1uLL) == 1 )
{
++v6;
++*a3;
if ( !*v6 )
goto LABEL_10;
}
goto LABEL_29;
}
LABEL_10:
if ( write(fd, &bufa, 1uLL) != 1 )
goto LABEL_29;
++*a3;
if ( *((_BYTE *)buf + 80) )
{
v7 = (char *)buf + 80;
while ( write(fd, v7, 1uLL) == 1 )
{
++v7;
++*a3;
if ( !*v7 )
goto LABEL_15;
}
goto LABEL_29;
}
LABEL_15:
if ( write(fd, &bufa, 1uLL) != 1 )
goto LABEL_29;
++*a3;
if ( *((_BYTE *)buf + 170) )
{
v8 = (char *)buf + 170;
while ( write(fd, v8, 1uLL) == 1 )
{
++v8;
++*a3;
if ( !*v8 )
goto LABEL_20;
}
goto LABEL_29;
}
LABEL_20:
if ( write(fd, &bufa, 1uLL) != 1 )
goto LABEL_29;
++*a3;
if ( *((_BYTE *)buf + 210) )
{
v9 = (char *)buf + 210;
while ( write(fd, v9, 1uLL) == 1 )
{
++v9;
++*a3;
if ( !*v9 )
goto LABEL_25;
}
goto LABEL_29;
}
LABEL_25:
if ( write(fd, &bufa, 1uLL) != 1 )
goto LABEL_29;
++*a3;
if ( write(fd, (char *)buf + 250, 1uLL) != 1 )
goto LABEL_29;
++*a3;
if ( write(fd, v12, 1uLL) != 1 )
goto LABEL_29;
result = (unsigned int)(*a3 + 1);
*a3 = result;
return result;
}

original_code:
int scrivi_record(int fd, struct contatto *record, int *posizione)
{
 int i;
 char tab='\t';
 char nl='\n';
 i=0;
 while(record->nome[i] != '\0') {
  if(write(fd, (void *) &(record->nome[i++]), sizeof(char)) != sizeof(char))
   perror("write"), exit(1);
  (*posizione)++;
 }
 if(write(fd, (void *) &tab, sizeof(char)) != sizeof(char))
  perror("write"), exit(1);
 (*posizione)++;
 i=0;
 while(record->cognome[i] != '\0') {
  if(write(fd, (void *) &(record->cognome[i++]), sizeof(char)) != sizeof(char))
   perror("write"), exit(1);
  (*posizione)++;
 }
 if(write(fd, (void *) &tab, sizeof(char)) != sizeof(char))
  perror("write"), exit(1);
 (*posizione)++;
 i=0;
 while(record->indirizzo[i] != '\0') {
  if(write(fd, (void *) &(record->indirizzo[i++]), sizeof(char)) != sizeof(char))
   perror("write"), exit(1);
  (*posizione)++;
 }
 if(write(fd, (void *) &tab, sizeof(char)) != sizeof(char))
  perror("write"), exit(1);
 (*posizione)++;
 i=0;
 while(record->telefono[i] != '\0') {
  if(write(fd, (void *) &(record->telefono[i++]), sizeof(char)) != sizeof(char))
   perror("write"), exit(1);
  (*posizione)++;
 }
 if(write(fd, (void *) &tab, sizeof(char)) != sizeof(char))
  perror("write"), exit(1);
 (*posizione)++;
 i=0;
 while(record->email[i] != '\0') {
  if(write(fd, (void *) &(record->email[i++]), sizeof(char)) != sizeof(char))
   perror("write"), exit(1);
  (*posizione)++;
 }
 if(write(fd, (void *) &tab, sizeof(char)) != sizeof(char))
  perror("write"), exit(1);
 (*posizione)++;
 if(write(fd, (void *) &(record->marcatura), sizeof(char)) != sizeof(char))
  perror("write"), exit(1);
 (*posizione)++;
 if(write(fd, (void *) &nl, sizeof(char)) != sizeof(char))
  perror("write"), exit(1);
 (*posizione)++;
 return (*posizione);
}

canonical_original_code:
int scrivi_record(int fd, struct contatto *record, int *posizione)
{
 int i;
 char tab = '\t';
 char nl = '\n';
 i=0;
 while(record->nome[i] != '\0') {
  if(write(fd, (void *) &(record->nome[i++]), sizeof(char)) != sizeof(char))
   perror("write"), exit(1);
  (*posizione)++;
 }
 if(write(fd, (void *) &tab, sizeof(char)) != sizeof(char))
  perror("write"), exit(1);
 (*posizione)++;
 i=0;
 while(record->cognome[i] != '\0') {
  if(write(fd, (void *) &(record->cognome[i++]), sizeof(char)) != sizeof(char))
   perror("write"), exit(1);
  (*posizione)++;
 }
 if(write(fd, (void *) &tab, sizeof(char)) != sizeof(char))
  perror("write"), exit(1);
 (*posizione)++;
 i=0;
 while(record->indirizzo[i] != '\0') {
  if(write(fd, (void *) &(record->indirizzo[i++]), sizeof(char)) != sizeof(char))
   perror("write"), exit(1);
  (*posizione)++;
 }
 if(write(fd, (void *) &tab, sizeof(char)) != sizeof(char))
  perror("write"), exit(1);
 (*posizione)++;
 i=0;
 while(record->telefono[i] != '\0') {
  if(write(fd, (void *) &(record->telefono[i++]), sizeof(char)) != sizeof(char))
   perror("write"), exit(1);
  (*posizione)++;
 }
 if(write(fd, (void *) &tab, sizeof(char)) != sizeof(char))
  perror("write"), exit(1);
 (*posizione)++;
 i=0;
 while(record->email[i] != '\0') {
  if(write(fd, (void *) &(record->email[i++]), sizeof(char)) != sizeof(char))
   perror("write"), exit(1);
  (*posizione)++;
 }
 if(write(fd, (void *) &tab, sizeof(char)) != sizeof(char))
  perror("write"), exit(1);
 (*posizione)++;
 if(write(fd, (void *) &(record->marcatura), sizeof(char)) != sizeof(char))
  perror("write"), exit(1);
 (*posizione)++;
 if(write(fd, (void *) &nl, sizeof(char)) != sizeof(char))
  perror("write"), exit(1);
 (*posizione)++;
 return (*posizione);
}

variable_types: i int

variable_types: tab char

variable_types: nl char

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


decompiled_code:
void __fastcall prendi_record_sentinella(__int64 a1)
{
*(_BYTE *)(a1 + 250) = 83;
}

original_code:
void prendi_record_sentinella(struct contatto *record) {
 record->marcatura = 'S';
}


decompiled_code:
__int64 __fastcall nuovo_record(void *buf)
{
int v1; // eax
int v2; // ebp
unsigned int v3; // er13
int v5; // [rsp+Ch] [rbp-12Ch] BYREF
char s1[40]; // [rsp+10h] [rbp-128h] BYREF
char v7[256]; // [rsp+38h] [rbp-100h] BYREF

v5 = 0;
v1 = open("./rubrica", 2, 436LL);
if ( v1 == -1 )
{
perror("open di nuovo_record()");
exit(1);
}
v2 = v1;
v3 = 0;
while ( !(unsigned int)leggi_record(v2, s1, &v5) )
{
if ( !(unsigned int)cancellato(s1) && !strcmp(s1, (const char *)buf) && !strcmp(v7, (const char *)buf + 40) )
v3 = 1;
}
if ( !v3 )
scrivi_record(v2, buf, &v5);
if ( close(v2) == -1 )
{
perror("close di nuovo_record()");
exit(1);
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func5(void *buf)
{
int v1; // eax
int v2; // ebp
unsigned int v3; // er13
int v5; // [rsp+Ch] [rbp-12Ch] BYREF
char s1[40]; // [rsp+10h] [rbp-128h] BYREF
char v7[256]; // [rsp+38h] [rbp-100h] BYREF

v5 = 0;
v1 = open("./rubrica", 2, 436LL);
if ( v1 == -1 )
{
perror("open di nuovo_record()");
exit(1);
}
v2 = v1;
v3 = 0;
while ( !(unsigned int)func2(v2, s1, &v5) )
{
if ( !(unsigned int)cancellato(s1) && !strcmp(s1, (const char *)buf) && !strcmp(v7, (const char *)buf + 40) )
v3 = 1;
}
if ( !v3 )
func3(v2, buf, &v5);
if ( close(v2) == -1 )
{
perror("close di nuovo_record()");
exit(1);
}
return v3;
}

original_code:
int nuovo_record(struct contatto *new) {
 int fd, numero_fittizio=0;
 int errore = 0;
 struct contatto buff;
 if((fd = open("./rubrica", 02, 0664)) == -1)
  perror("open di nuovo_record()"), exit(1);
 while(leggi_record(fd, &buff, &numero_fittizio) == 0) {
  if (!cancellato(&buff))
   if ((strcmp(buff.nome, new->nome)==0) && (strcmp(buff.cognome, new->cognome)==0))
    errore=1;
 }
 if (!errore)
  scrivi_record(fd, new, &numero_fittizio);
 if (close(fd) == -1)
  perror("close di nuovo_record()"), exit(1);
 return errore;
}

canonical_original_code:
int nuovo_record(struct contatto *new) {
 int fd; int numero_fittizio = 0;
 int errore = 0;
 struct contatto buff;
 if((fd = open("./rubrica", 02, 0664)) == -1)
  perror("open di nuovo_record()"), exit(1);
 while(leggi_record(fd, &buff, &numero_fittizio) == 0) {
  if (!cancellato(&buff))
   if ((strcmp(buff.nome, new->nome)==0) && (strcmp(buff.cognome, new->cognome)==0))
    errore=1;
 }
 if (!errore)
  scrivi_record(fd, new, &numero_fittizio);
 if (close(fd) == -1)
  perror("close di nuovo_record()"), exit(1);
 return errore;
}

variable_types: errore int

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


decompiled_code:
int reset_database()
{
int v0; // eax
int result; // eax

v0 = open("./rubrica", 577, 436LL);
if ( v0 == -1 )
{
perror("open di reset_database()");
exit(1);
}
result = close(v0);
if ( result == -1 )
{
perror("close di reset_database()");
exit(1);
}
return result;
}

canonical_decompiled_code:
int func6()
{
int v0; // eax
int result; // eax

v0 = open("./rubrica", 577, 436LL);
if ( v0 == -1 )
{
perror("open di reset_database()");
exit(1);
}
result = close(v0);
if ( result == -1 )
{
perror("close di reset_database()");
exit(1);
}
return result;
}

original_code:
void reset_database(void)
{
 int fd;
 fd = open("./rubrica", 0100 | 01000 | 01, 0664);
 if (fd == -1)
  perror("open di reset_database()"), exit(1);
 if (close(fd) == -1)
  perror("close di reset_database()"), exit(1);
}

canonical_original_code:
void reset_database()
{
 int fd;
 fd = open("./rubrica", 0100 | 01000 | 01, 0664);
 if (fd == -1)
  perror("open di reset_database()"), exit(1);
 if (close(fd) == -1)
  perror("close di reset_database()"), exit(1);
}


idoneo

original_code:
int idoneo(struct contatto *criterio, struct contatto *record)
{
 if(strcmp("", criterio->nome) != 0)
  if(strcmp(record->nome, criterio->nome) != 0)
   return 0;
 if(strcmp("", criterio->cognome) != 0)
  if(strcmp(record->cognome, criterio->cognome) != 0)
   return 0;
 if(strcmp("", criterio->indirizzo) != 0)
  if(strcmp(record->indirizzo, criterio->indirizzo) != 0)
   return 0;
 if(strcmp("", criterio->telefono) != 0)
  if(strcmp(record->telefono, criterio->telefono) != 0)
   return 0;
 if(strcmp("", criterio->email) != 0)
  if(strcmp(record->email, criterio->email) != 0)
   return 0;
 if(record->marcatura == 'X')
  return 0;
 return 1;
}

variable_types:
record
struct contatto *


decompiled_code:
__int64 __fastcall trova_record(char *s2)
{
int v1; // eax
int v2; // ebp
int v3; // ebx
unsigned int v4; // er12
unsigned int v6; // [rsp+Ch] [rbp-12Ch] BYREF
char s1[40]; // [rsp+10h] [rbp-128h] BYREF
char v8[256]; // [rsp+38h] [rbp-100h] BYREF

v6 = 0;
v1 = open("./rubrica", 0, 436LL);
if ( v1 == -1 )
{
perror("open di trova_record()");
exit(1);
}
v2 = v1;
v3 = 1;
v4 = 0;
while ( !(unsigned int)leggi_record(v2, s1, &v6) )
{
if ( v3 != 1 )
{
if ( close(v2) == -1 )
{
LABEL_15:
perror("close di trova_record()");
exit(1);
}
return v4;
}
if ( !(unsigned int)cancellato(s1) && !strcmp(s1, s2) && !strcmp(v8, s2 + 40) )
v3 = 0;
else
v4 = v6;
}
if ( close(v2) == -1 )
goto LABEL_15;
if ( v3 )
v4 = -1;
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func8(char *s2)
{
int v1; // eax
int v2; // ebp
int v3; // ebx
unsigned int v4; // er12
unsigned int v6; // [rsp+Ch] [rbp-12Ch] BYREF
char s1[40]; // [rsp+10h] [rbp-128h] BYREF
char v8[256]; // [rsp+38h] [rbp-100h] BYREF

v6 = 0;
v1 = open("./rubrica", 0, 436LL);
if ( v1 == -1 )
{
perror("open di trova_record()");
exit(1);
}
v2 = v1;
v3 = 1;
v4 = 0;
while ( !(unsigned int)func2(v2, s1, &v6) )
{
if ( v3 != 1 )
{
if ( close(v2) == -1 )
{
LABEL_15:
perror("close di trova_record()");
exit(1);
}
return v4;
}
if ( !(unsigned int)cancellato(s1) && !strcmp(s1, s2) && !strcmp(v8, s2 + 40) )
v3 = 0;
else
v4 = v6;
}
if ( close(v2) == -1 )
goto LABEL_15;
if ( v3 )
v4 = -1;
return v4;
}

original_code:
int trova_record(struct ricerca_contatto *cerco)
{
 int posizione = 0;
 int vecchia_posizione = 0;
 int letto, fd;
 int flag = 1;
 struct contatto buffer;
 if((fd = open("./rubrica", 00, 0664)) == -1)
  perror("open di trova_record()"), exit(1);
 while ((leggi_record(fd, &buffer, &posizione) == 0) && (flag == 1)) {
  if (!cancellato(&buffer))
   if ((strcmp(buffer.nome, cerco->nome)==0) && (strcmp(buffer.cognome, cerco->cognome)==0))
    flag = 0;
  if (flag)
   vecchia_posizione = posizione;
 }
 if (close(fd) == -1)
  perror("close di trova_record()"), exit(1);
 if (flag)
  return -1;
 return vecchia_posizione;
}

canonical_original_code:
int trova_record(struct ricerca_contatto *cerco)
{
 int posizione = 0;
 int vecchia_posizione = 0;
 int letto; int fd;
 int flag = 1;
 struct contatto buffer;
 if((fd = open("./rubrica", 00, 0664)) == -1)
  perror("open di trova_record()"), exit(1);
 while ((leggi_record(fd, &buffer, &posizione) == 0) && (flag == 1)) {
  if (!cancellato(&buffer))
   if ((strcmp(buffer.nome, cerco->nome)==0) && (strcmp(buffer.cognome, cerco->cognome)==0))
    flag = 0;
  if (flag)
   vecchia_posizione = posizione;
 }
 if (close(fd) == -1)
  perror("close di trova_record()"), exit(1);
 if (flag)
  return -1;
 return vecchia_posizione;
}

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

variable_types: posizione int

variable_types: letto int

variable_types: fd int

variable_types: flag int


decompiled_code:
__int64 __fastcall cancella_record(char *a1)
{
int v1; // eax
int v2; // ebx
int v3; // eax
int v4; // ebp
int v5; // ebx
int v6; // eax
char buf; // [rsp+Eh] [rbp-1Ah] BYREF
char v9[25]; // [rsp+Fh] [rbp-19h] BYREF

v9[0] = 88;
v1 = trova_record(a1);
if ( v1 != -1 )
{
v2 = v1;
v3 = open("./rubrica", 2, 436LL);
v4 = v3;
if ( v3 == -1 )
{
perror("open di cancella_record()");
exit(1);
}
if ( lseek(v3, v2, 0) == -1 )
{
perror("lseek di cancella_record()");
exit(1);
}
v5 = 0;
while ( 1 )
{
v6 = read(v4, &buf, 1uLL);
if ( !v6 )
break;
if ( v6 != 1 )
{
perror("read di leggi_record()");
exit(1);
}
v5 += buf == 9;
if ( v5 == 5 )
{
if ( write(v4, v9, 1uLL) != 1 )
{
perror("write");
exit(1);
}
if ( close(v4) == -1 )
{
perror("close di cancella_record()");
exit(1);
}
return 0LL;
}
}
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(char *a1)
{
int v1; // eax
int v2; // ebx
int v3; // eax
int v4; // ebp
int v5; // ebx
int v6; // eax
char buf; // [rsp+Eh] [rbp-1Ah] BYREF
char v9[25]; // [rsp+Fh] [rbp-19h] BYREF

v9[0] = 88;
v1 = func8(a1);
if ( v1 != -1 )
{
v2 = v1;
v3 = open("./rubrica", 2, 436LL);
v4 = v3;
if ( v3 == -1 )
{
perror("open di cancella_record()");
exit(1);
}
if ( lseek(v3, v2, 0) == -1 )
{
perror("lseek di cancella_record()");
exit(1);
}
v5 = 0;
while ( 1 )
{
v6 = read(v4, &buf, 1uLL);
if ( !v6 )
break;
if ( v6 != 1 )
{
perror("read di leggi_record()");
exit(1);
}
v5 += buf == 9;
if ( v5 == 5 )
{
if ( write(v4, v9, 1uLL) != 1 )
{
perror("write");
exit(1);
}
if ( close(v4) == -1 )
{
perror("close di cancella_record()");
exit(1);
}
return 0LL;
}
}
}
return 1LL;
}

original_code:
int cancella_record(struct ricerca_contatto *cancello)
{
 int fd;
 int letto;
 int flag=1;
 int contatore;
 int i=0;
 char car;
 char canc = 'X';
 struct contatto buffer;
 if ((contatore = trova_record(cancello)) == -1)
  return 1;
 if((fd = open("./rubrica", 02, 0664)) == -1)
  perror("open di cancella_record()"), exit(1);
 if (lseek(fd, contatore, 0) == -1)
  perror("lseek di cancella_record()"), exit(1);
 while(i < 5) {
  switch((letto=read(fd, &car, sizeof(char)))) {
   case sizeof(char):
    if (car == '\t')
     i++;
    break;
   case 0:
    return 1;
    break;
   default:
    perror("read di leggi_record()");
    exit(1);
    break;
  }
 }
 if(write(fd, (void *) &canc, sizeof(char)) != sizeof(char))
  perror("write"), exit(1);
 if (close(fd) == -1)
  perror("close di cancella_record()"), exit(1);
 return 0;
}

canonical_original_code:
int cancella_record(struct ricerca_contatto *cancello)
{
 int fd;
 int letto;
 int flag = 1;
 int contatore;
 int i = 0;
 char car;
 char canc = 'X';
 struct contatto buffer;
 if ((contatore = trova_record(cancello)) == -1)
  return 1;
 if((fd = open("./rubrica", 02, 0664)) == -1)
  perror("open di cancella_record()"), exit(1);
 if (lseek(fd, contatore, 0) == -1)
  perror("lseek di cancella_record()"), exit(1);
 while(i < 5) {
  switch((letto=read(fd, &car, sizeof(char)))) {
   case sizeof(char):
    if (car == '\t')
     i++;
    break;
   case 0:
    return 1;
    break;
   default:
    perror("read di leggi_record()");
    exit(1);
    break;
  }
 }
 if(write(fd, (void *) &canc, sizeof(char)) != sizeof(char))
  perror("write"), exit(1);
 if (close(fd) == -1)
  perror("close di cancella_record()"), exit(1);
 return 0;
}

variable_types: contatore int

variable_types: car char

variable_types: canc char

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


decompiled_code:
__int64 __fastcall modifica_record(void *buf, char *a2)
{
__int64 result; // rax

result = cancella_record(a2);
if ( (_DWORD)result != 1 )
result = (unsigned int)nuovo_record(buf) == 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(void *buf, char *a2)
{
__int64 result; // rax

result = func9(a2);
if ( (_DWORD)result != 1 )
result = (unsigned int)func5(buf) == 1;
return result;
}

original_code:
int modifica_record(struct contatto *new, struct ricerca_contatto *cerca) {
 if(cancella_record(cerca) == 1)
  return 1;
 if(nuovo_record(new) == 1)
  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; } *


decompiled_code:
__int64 compatta_tabella()
{
int v0; // ebp
int v2; // [rsp+8h] [rbp-110h] BYREF
int v3; // [rsp+Ch] [rbp-10Ch] BYREF
char buf[264]; // [rsp+10h] [rbp-108h] BYREF

v2 = 0;
v3 = 0;
v0 = open("./rubrica", 2, 436LL);
if ( v0 == -1 )
{
perror("open di compatta_tabella()");
exit(1);
}
while ( !(unsigned int)leggi_record(v0, buf, &v2) )
{
if ( (unsigned int)cancellato(buf) )
{
while ( !(unsigned int)leggi_record(v0, buf, &v2) )
{
if ( !(unsigned int)cancellato(buf) )
{
if ( lseek(v0, v3, 0) == -1 || (scrivi_record(v0, buf, &v3), lseek(v0, v2, 0) == -1) )
{
perror("lseek di cancella_record()");
exit(1);
}
}
}
}
else
{
v3 = v2;
}
}
if ( close(v0) == -1 )
{
perror("close di compatta_tabella()");
exit(1);
}
if ( v3 == v2 )
return 1LL;
if ( truncate("./rubrica", v3) == -1 )
{
perror("truncate di compatta_tabella()");
exit(1);
}
return 0LL;
}

canonical_decompiled_code:
__int64 func11()
{
int v0; // ebp
int v2; // [rsp+8h] [rbp-110h] BYREF
int v3; // [rsp+Ch] [rbp-10Ch] BYREF
char buf[264]; // [rsp+10h] [rbp-108h] BYREF

v2 = 0;
v3 = 0;
v0 = open("./rubrica", 2, 436LL);
if ( v0 == -1 )
{
perror("open di compatta_tabella()");
exit(1);
}
while ( !(unsigned int)func2(v0, buf, &v2) )
{
if ( (unsigned int)cancellato(buf) )
{
while ( !(unsigned int)func2(v0, buf, &v2) )
{
if ( !(unsigned int)cancellato(buf) )
{
if ( lseek(v0, v3, 0) == -1 || (func3(v0, buf, &v3), lseek(v0, v2, 0) == -1) )
{
perror("lseek di cancella_record()");
exit(1);
}
}
}
}
else
{
v3 = v2;
}
}
if ( close(v0) == -1 )
{
perror("close di compatta_tabella()");
exit(1);
}
if ( v3 == v2 )
return 1LL;
if ( truncate("./rubrica", v3) == -1 )
{
perror("truncate di compatta_tabella()");
exit(1);
}
return 0LL;
}

original_code:
int compatta_tabella(void) {
 int fd;
 int lettura=0, scrittura=0;
 struct contatto buffer;
 if((fd = open("./rubrica", 02, 0664)) == -1)
  perror("open di compatta_tabella()"), exit(1);
 while (leggi_record(fd, &buffer, &lettura) == 0) {
  if (!cancellato(&buffer))
   scrittura=lettura;
  else {
   while (leggi_record(fd, &buffer, &lettura) == 0) {
    if (!cancellato(&buffer)) {
     if (lseek(fd, scrittura, 0) == -1)
      perror("lseek di cancella_record()"), exit(1);
     scrivi_record(fd, &buffer, &scrittura);
     if (lseek(fd, lettura, 0) == -1)
      perror("lseek di cancella_record()"), exit(1);
    }
   }
  }
 }
 if (close(fd) == -1)
  perror("close di compatta_tabella()"), exit(1);
 if (scrittura == lettura)
  return 1;
 else
  if (truncate("./rubrica", scrittura) == -1)
   perror("truncate di compatta_tabella()"), exit(1);
 return 0;
}

canonical_original_code:
int compatta_tabella() {
 int fd;
 int lettura = 0; int scrittura = 0;
 struct contatto buffer;
 if((fd = open("./rubrica", 02, 0664)) == -1)
  perror("open di compatta_tabella()"), exit(1);
 while (leggi_record(fd, &buffer, &lettura) == 0) {
  if (!cancellato(&buffer))
   scrittura=lettura;
  else {
   while (leggi_record(fd, &buffer, &lettura) == 0) {
    if (!cancellato(&buffer)) {
     if (lseek(fd, scrittura, 0) == -1)
      perror("lseek di cancella_record()"), exit(1);
     scrivi_record(fd, &buffer, &scrittura);
     if (lseek(fd, lettura, 0) == -1)
      perror("lseek di cancella_record()"), exit(1);
    }
   }
  }
 }
 if (close(fd) == -1)
  perror("close di compatta_tabella()"), exit(1);
 if (scrittura == lettura)
  return 1;
 else
  if (truncate("./rubrica", scrittura) == -1)
   perror("truncate di compatta_tabella()"), exit(1);
 return 0;
}

variable_types: lettura int

variable_types: scrittura int


decompiled_code:
void *__fastcall r_stampa_contatti(void *a1)
{
unsigned int v1; // ebp

v1 = *(_DWORD *)a1;
if ( (unsigned int)trasmetti_opzione(*(unsigned int *)a1, 97LL) )
fatal_error(v1);
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func1(void *a1)
{
unsigned int v1; // ebp

v1 = *(_DWORD *)a1;
if ( (unsigned int)trasmetti_opzione(*(unsigned int *)a1, 97LL) )
func0(v1);
return 0LL;
}

original_code:
void *r_stampa_contatti(void *id_c) {
 int id_connessione = *((int *) id_c);
 if(trasmetti_opzione(id_connessione, 'a'))
  fatal_error(id_connessione);
 return ((void *)0);
}

return_type: void *


decompiled_code:
void *__fastcall r_cerca_contatto(void *a1)
{
unsigned int v1; // ebp
_BYTE v3[264]; // [rsp+0h] [rbp-108h] BYREF

v1 = *(_DWORD *)a1;
if ( (unsigned int)trasmetti_opzione(*(unsigned int *)a1, 98LL)
|| (fwrite("Premere semplicemente <INVIO> per non dare il valore\n", 1uLL, 0x35uLL, stdout),
inserisci_record(v3),
(unsigned int)trasmetti(v1, v3, 251LL)) )
{
fatal_error(v1);
}
fwrite("\nContatti trovati:\n", 1uLL, 0x13uLL, stdout);
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func2(void *a1)
{
unsigned int v1; // ebp
_BYTE v3[264]; // [rsp+0h] [rbp-108h] BYREF

v1 = *(_DWORD *)a1;
if ( (unsigned int)trasmetti_opzione(*(unsigned int *)a1, 98LL)
|| (fwrite("Premere semplicemente <INVIO> per non dare il valore\n", 1uLL, 0x35uLL, stdout),
inserisci_record(v3),
(unsigned int)trasmetti(v1, v3, 251LL)) )
{
func0(v1);
}
fwrite("\nContatti trovati:\n", 1uLL, 0x13uLL, stdout);
return 0LL;
}

original_code:
void *r_cerca_contatto(void *id_c) {
 int id_connessione = *((int *) id_c);
 struct contatto cerca;
 if(trasmetti_opzione(id_connessione, 'b'))
  fatal_error(id_connessione);
 fprintf(stdout,"Premere semplicemente <INVIO> per non dare il valore\n");
 inserisci_record(&cerca);
 if(trasmetti(id_connessione, &cerca, sizeof(struct contatto)))
  fatal_error(id_connessione);
 fprintf(stdout,"\nContatti trovati:\n");
 return ((void *)0);
}


decompiled_code:
void *__fastcall r_modifica_contatto(void *a1)
{
unsigned int v1; // ebp
_BYTE v3[88]; // [rsp+0h] [rbp-58h] BYREF

v1 = *(_DWORD *)a1;
if ( (unsigned int)trasmetti_opzione(*(unsigned int *)a1, 99LL)
|| (fwrite("Dare tutti i valori richiesti:\n", 1uLL, 0x1FuLL, stdout),
inserisci_record_ricerca(v3),
(unsigned int)trasmetti(v1, v3, 80LL)) )
{
fatal_error(v1);
}
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func3(void *a1)
{
unsigned int v1; // ebp
_BYTE v3[88]; // [rsp+0h] [rbp-58h] BYREF

v1 = *(_DWORD *)a1;
if ( (unsigned int)trasmetti_opzione(*(unsigned int *)a1, 99LL)
|| (fwrite("Dare tutti i valori richiesti:\n", 1uLL, 0x1FuLL, stdout),
inserisci_record_ricerca(v3),
(unsigned int)trasmetti(v1, v3, 80LL)) )
{
func0(v1);
}
return 0LL;
}

original_code:
void *r_modifica_contatto(void *id_c) {
 int id_connessione = *((int *) id_c);
 struct ricerca_contatto modifico;
 if(trasmetti_opzione(id_connessione, 'c'))
  fatal_error(id_connessione);
 fprintf(stdout,"Dare tutti i valori richiesti:\n");
 inserisci_record_ricerca(&modifico);
 if(trasmetti(id_connessione, &modifico, sizeof(struct ricerca_contatto)))
  fatal_error(id_connessione);
 return ((void *)0);
}

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


decompiled_code:
void *__fastcall r_modifica_contatto2(void *a1)
{
unsigned int v1; // ebp
_BYTE v3[264]; // [rsp+0h] [rbp-108h] BYREF

v1 = *(_DWORD *)a1;
fwrite("Reinserisci i dati del contatto per modificarlo\n", 1uLL, 0x30uLL, stdout);
inserisci_record(v3);
if ( (unsigned int)trasmetti(v1, v3, 251LL) )
fatal_error(v1);
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func4(void *a1)
{
unsigned int v1; // ebp
_BYTE v3[264]; // [rsp+0h] [rbp-108h] BYREF

v1 = *(_DWORD *)a1;
fwrite("Reinserisci i dati del contatto per modificarlo\n", 1uLL, 0x30uLL, stdout);
inserisci_record(v3);
if ( (unsigned int)trasmetti(v1, v3, 251LL) )
func0(v1);
return 0LL;
}

original_code:
void *r_modifica_contatto2(void *id_c) {
 int id_connessione = *((int *) id_c);
 struct contatto new;
 fprintf(stdout,"Reinserisci i dati del contatto per modificarlo\n");
 inserisci_record(&new);
 if(trasmetti(id_connessione, &new, sizeof(struct contatto)))
  fatal_error(id_connessione);
 return ((void *)0);
}


decompiled_code:
void *__fastcall r_nuovo_contatto(void *a1)
{
unsigned int v1; // ebp
_BYTE v3[264]; // [rsp+0h] [rbp-108h] BYREF

v1 = *(_DWORD *)a1;
if ( (unsigned int)trasmetti_opzione(*(unsigned int *)a1, 100LL)
|| (inserisci_record(v3), (unsigned int)trasmetti(v1, v3, 251LL)) )
{
fatal_error(v1);
}
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func5(void *a1)
{
unsigned int v1; // ebp
_BYTE v3[264]; // [rsp+0h] [rbp-108h] BYREF

v1 = *(_DWORD *)a1;
if ( (unsigned int)trasmetti_opzione(*(unsigned int *)a1, 100LL)
|| (inserisci_record(v3), (unsigned int)trasmetti(v1, v3, 251LL)) )
{
func0(v1);
}
return 0LL;
}

original_code:
void *r_nuovo_contatto(void *id_c) {
 int id_connessione = *((int *) id_c);
 struct contatto new;
 if(trasmetti_opzione(id_connessione, 'd'))
  fatal_error(id_connessione);
 inserisci_record(&new);
 if(trasmetti(id_connessione, &new, sizeof(struct contatto)))
  fatal_error(id_connessione);
 return ((void *)0);
}


decompiled_code:
void *__fastcall r_cancella_contatto(void *a1)
{
unsigned int v1; // ebp
_BYTE v3[88]; // [rsp+0h] [rbp-58h] BYREF

v1 = *(_DWORD *)a1;
if ( (unsigned int)trasmetti_opzione(*(unsigned int *)a1, 101LL)
|| (fwrite("Dare tutti i valori richiesti:\n", 1uLL, 0x1FuLL, stdout),
inserisci_record_ricerca(v3),
(unsigned int)trasmetti(v1, v3, 80LL)) )
{
fatal_error(v1);
}
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func6(void *a1)
{
unsigned int v1; // ebp
_BYTE v3[88]; // [rsp+0h] [rbp-58h] BYREF

v1 = *(_DWORD *)a1;
if ( (unsigned int)trasmetti_opzione(*(unsigned int *)a1, 101LL)
|| (fwrite("Dare tutti i valori richiesti:\n", 1uLL, 0x1FuLL, stdout),
inserisci_record_ricerca(v3),
(unsigned int)trasmetti(v1, v3, 80LL)) )
{
func0(v1);
}
return 0LL;
}

original_code:
void *r_cancella_contatto(void *id_c) {
 int id_connessione = *((int *) id_c);
 struct ricerca_contatto cancella;
 if(trasmetti_opzione(id_connessione, 'e'))
  fatal_error(id_connessione);
 fprintf(stdout,"Dare tutti i valori richiesti:\n");
 inserisci_record_ricerca(&cancella);
 if(trasmetti(id_connessione, &cancella, sizeof(struct ricerca_contatto)))
  fatal_error(id_connessione);
 return ((void *)0);
}


decompiled_code:
void *__fastcall r_compact_tabella(void *a1)
{
unsigned int v1; // ebp

v1 = *(_DWORD *)a1;
if ( (unsigned int)trasmetti_opzione(*(unsigned int *)a1, 102LL) )
fatal_error(v1);
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func7(void *a1)
{
unsigned int v1; // ebp

v1 = *(_DWORD *)a1;
if ( (unsigned int)trasmetti_opzione(*(unsigned int *)a1, 102LL) )
func0(v1);
return 0LL;
}

original_code:
void *r_compact_tabella(void *id_c) {
 int id_connessione = *((int *) id_c);
 if(trasmetti_opzione(id_connessione, 'f'))
  fatal_error(id_connessione);
 return ((void *)0);
}


decompiled_code:
void *__fastcall r_program_exit(void *a1)
{
unsigned int v1; // ebp

v1 = *(_DWORD *)a1;
if ( (unsigned int)trasmetti_opzione(*(unsigned int *)a1, 103LL) )
fatal_error(v1);
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func8(void *a1)
{
unsigned int v1; // ebp

v1 = *(_DWORD *)a1;
if ( (unsigned int)trasmetti_opzione(*(unsigned int *)a1, 103LL) )
func0(v1);
return 0LL;
}

original_code:
void *r_program_exit(void *id_c) {
 int id_connessione = *((int *) id_c);
 if(trasmetti_opzione(id_connessione, 'g'))
  fatal_error(id_connessione);
 return ((void *)0);
}


decompiled_code:
__int64 __fastcall program_exit(__int64 a1)
{
__int64 result; // rax
char v2[9]; // [rsp+Fh] [rbp-9h] BYREF

result = ricevi_opzione(a1, v2);
if ( (_DWORD)result )
fatal_error(a1);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1)
{
__int64 result; // rax
char v2[9]; // [rsp+Fh] [rbp-9h] BYREF

result = ricevi_opzione(a1, v2);
if ( (_DWORD)result )
func0(a1);
return result;
}

original_code:
void program_exit(int id_connessione)
{
 char risultato;
 if(ricevi_opzione(id_connessione, &risultato))
  fatal_error(id_connessione);
}

variable_types: risultato char


decompiled_code:
size_t stampa_menu()
{
fwrite("[]=-=-=-=-=-=-=-=-=-=-=-=[MENU]=-=-=-=-=-=-=-=-=-=-=-=[]\n", 1uLL, 0x39uLL, stdout);
fwrite("Scegli una delle seguenti opzioni:\n\n", 1uLL, 0x24uLL, stdout);
fwrite("\t1) Stampa tutti i contatti\n", 1uLL, 0x1CuLL, stdout);
fwrite("\t2) Cerca un contatto\n", 1uLL, 0x16uLL, stdout);
fwrite("\t3) Modifica un contatto\n", 1uLL, 0x19uLL, stdout);
fwrite("\t4) Nuovo contatto\n", 1uLL, 0x13uLL, stdout);
fwrite("\t5) Cancella un contatto\n", 1uLL, 0x19uLL, stdout);
fwrite("\t6) Compact tabella\n", 1uLL, 0x14uLL, stdout);
fwrite("\t7) ESCI\n\n", 1uLL, 0xAuLL, stdout);
return fwrite("Inserisci la tua scelta: ", 1uLL, 0x19uLL, stdout);
}

canonical_decompiled_code:
size_t func16()
{
fwrite("[]=-=-=-=-=-=-=-=-=-=-=-=[MENU]=-=-=-=-=-=-=-=-=-=-=-=[]\n", 1uLL, 0x39uLL, stdout);
fwrite("Scegli una delle seguenti opzioni:\n\n", 1uLL, 0x24uLL, stdout);
fwrite("\t1) Stampa tutti i contatti\n", 1uLL, 0x1CuLL, stdout);
fwrite("\t2) Cerca un contatto\n", 1uLL, 0x16uLL, stdout);
fwrite("\t3) Modifica un contatto\n", 1uLL, 0x19uLL, stdout);
fwrite("\t4) Nuovo contatto\n", 1uLL, 0x13uLL, stdout);
fwrite("\t5) Cancella un contatto\n", 1uLL, 0x19uLL, stdout);
fwrite("\t6) Compact tabella\n", 1uLL, 0x14uLL, stdout);
fwrite("\t7) ESCI\n\n", 1uLL, 0xAuLL, stdout);
return fwrite("Inserisci la tua scelta: ", 1uLL, 0x19uLL, stdout);
}

original_code:
void stampa_menu(void)
{
 fprintf(stdout,"[]=-=-=-=-=-=-=-=-=-=-=-=[MENU]=-=-=-=-=-=-=-=-=-=-=-=[]\n");
 fprintf(stdout,"Scegli una delle seguenti opzioni:\n\n");
 fprintf(stdout,"\t1) Stampa tutti i contatti\n");
 fprintf(stdout,"\t2) Cerca un contatto\n");
 fprintf(stdout,"\t3) Modifica un contatto\n");
 fprintf(stdout,"\t4) Nuovo contatto\n");
 fprintf(stdout,"\t5) Cancella un contatto\n");
 fprintf(stdout,"\t6) Compact tabella\n");
 fprintf(stdout,"\t7) ESCI\n\n");
 fprintf(stdout,"Inserisci la tua scelta: ");
}

canonical_original_code:
void stampa_menu()
{
 fprintf(stdout,"[]=-=-=-=-=-=-=-=-=-=-=-=[MENU]=-=-=-=-=-=-=-=-=-=-=-=[]\n");
 fprintf(stdout,"Scegli una delle seguenti opzioni:\n\n");
 fprintf(stdout,"\t1) Stampa tutti i contatti\n");
 fprintf(stdout,"\t2) Cerca un contatto\n");
 fprintf(stdout,"\t3) Modifica un contatto\n");
 fprintf(stdout,"\t4) Nuovo contatto\n");
 fprintf(stdout,"\t5) Cancella un contatto\n");
 fprintf(stdout,"\t6) Compact tabella\n");
 fprintf(stdout,"\t7) ESCI\n\n");
 fprintf(stdout,"Inserisci la tua scelta: ");
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbp
unsigned int v4; // er12
int v5; // eax
__int64 v6; // rsi
int result; // eax
char v8; // [rsp+Fh] [rbp-29h] BYREF
unsigned int arg; // [rsp+10h] [rbp-28h] BYREF
int v10; // [rsp+14h] [rbp-24h] BYREF
pthread_t newthread[4]; // [rsp+18h] [rbp-20h] BYREF

if ( argc == 2 )
{
v3 = argv[1];
if ( !strcmp(v3, "-h") || !strcmp(v3, "--help") )
{
stampa_help(*argv);
exit(0);
}
v4 = 3456;
}
else if ( argc == 3 )
{
v5 = atoi(argv[2]);
v3 = argv[1];
v4 = v5;
}
else
{
if ( argc <= 1 )
{
v6 = 3456LL;
goto LABEL_27;
}
v3 = argv[1];
v4 = 3456;
}
v6 = v4;
if ( strcmp(v3, "localhost") )
{
arg = connetti(v3, v4);
LABEL_8:
fwrite("Benvenuto, sei connesso con la rubrica\n", 1uLL, 0x27uLL, stdout);
while ( 1 )
{
fwrite("\n\nPremere INVIO per continuare", 1uLL, 0x1EuLL, stdout);
getchar();
fwrite("\n\n\n\n\n", 1uLL, 5uLL, stdout);
stampa_menu();
_isoc99_scanf("%d", &v10);
getchar();
fwrite("\n\n\n\n\n", 1uLL, 5uLL, stdout);
switch ( v10 )
{
case 1:
fwrite("[]=-=-=-=-=[STAMPA CONTATTI]=-=-=-=-=[]\n\n", 1uLL, 0x29uLL, stdout);
pthread_create(newthread, 0LL, r_stampa_contatti, &arg);
stampa_contatti(arg);
goto LABEL_11;
case 2:
fwrite("[]=-=-=-=-=-=[CERCA CONTATTO]=-=-=-=-=-=[]\n\n", 1uLL, 0x2CuLL, stdout);
pthread_create(newthread, 0LL, r_cerca_contatto, &arg);
cerca_contatto(arg);
goto LABEL_11;
case 3:
fwrite("[]=-=-=-=-=[MODIFICA CONTATTO]=-=-=-=-=[]\n\n", 1uLL, 0x2BuLL, stdout);
pthread_create(newthread, 0LL, r_modifica_contatto, &arg);
modifica_contatto(arg);
goto LABEL_11;
case 4:
fwrite("[]=-=-=-=-=-=[NUOVO CONTATTO]=-=-=-=-=-=[]\n\n", 1uLL, 0x2CuLL, stdout);
pthread_create(newthread, 0LL, r_nuovo_contatto, &arg);
nuovo_contatto(arg);
goto LABEL_11;
case 5:
fwrite("[]=-=-=-=-=[CANCELLA CONTATTO]=-=-=-=-=[]\n\n", 1uLL, 0x2BuLL, stdout);
pthread_create(newthread, 0LL, r_cancella_contatto, &arg);
cancella_contatto(arg);
goto LABEL_11;
case 6:
fwrite("[]=-=-=-=-=-=[COMPACT TABELLA]=-=-=-=-=-=[]\n\n", 1uLL, 0x2DuLL, stdout);
pthread_create(newthread, 0LL, r_compact_tabella, &arg);
compact_tabella(arg);
if ( pthread_join(newthread[0], 0LL) )
goto LABEL_17;
break;
case 7:
pthread_create(newthread, 0LL, r_program_exit, &arg);
program_exit(arg);
LABEL_11:
if ( pthread_join(newthread[0], 0LL) )
{
LABEL_17:
fwrite("Impossibile aspettare il tread\n", 1uLL, 0x1FuLL, stderr);
exit(1);
}
return result;
default:
fwrite("[ERRORE] Scelta errata!\n", 1uLL, 0x18uLL, stdout);
break;
}
if ( (unsigned int)ricevi_opzione(arg, &v8) )
fatal_error(arg);
if ( v8 == 108 )
break;
if ( v10 == 7 )
goto LABEL_24;
}
fwrite(&unk_CC8, 1uLL, 0x39uLL, stdout);
fwrite(&unk_D08, 1uLL, 0x1EuLL, stdout);
v10 = 7;
LABEL_24:
chiudi_connessione(arg);
fwrite("Arrivederci\n", 1uLL, 0xCuLL, stdout);
exit(0);
}
LABEL_27:
arg = connetti("127.0.0.1", v6);
goto LABEL_8;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbp
unsigned int v4; // er12
int v5; // eax
__int64 v6; // rsi
int result; // eax
char v8; // [rsp+Fh] [rbp-29h] BYREF
unsigned int arg; // [rsp+10h] [rbp-28h] BYREF
int v10; // [rsp+14h] [rbp-24h] BYREF
pthread_t newthread[4]; // [rsp+18h] [rbp-20h] BYREF

if ( argc == 2 )
{
v3 = argv[1];
if ( !strcmp(v3, "-h") || !strcmp(v3, "--help") )
{
func17(*argv);
exit(0);
}
v4 = 3456;
}
else if ( argc == 3 )
{
v5 = atoi(argv[2]);
v3 = argv[1];
v4 = v5;
}
else
{
if ( argc <= 1 )
{
v6 = 3456LL;
goto LABEL_27;
}
v3 = argv[1];
v4 = 3456;
}
v6 = v4;
if ( strcmp(v3, "localhost") )
{
arg = connetti(v3, v4);
LABEL_8:
fwrite("Benvenuto, sei connesso con la rubrica\n", 1uLL, 0x27uLL, stdout);
while ( 1 )
{
fwrite("\n\nPremere INVIO per continuare", 1uLL, 0x1EuLL, stdout);
getchar();
fwrite("\n\n\n\n\n", 1uLL, 5uLL, stdout);
func16();
_isoc99_scanf("%d", &v10);
getchar();
fwrite("\n\n\n\n\n", 1uLL, 5uLL, stdout);
switch ( v10 )
{
case 1:
fwrite("[]=-=-=-=-=[STAMPA CONTATTI]=-=-=-=-=[]\n\n", 1uLL, 0x29uLL, stdout);
pthread_create(newthread, 0LL, r_stampa_contatti, &arg);
func9(arg);
goto LABEL_11;
case 2:
fwrite("[]=-=-=-=-=-=[CERCA CONTATTO]=-=-=-=-=-=[]\n\n", 1uLL, 0x2CuLL, stdout);
pthread_create(newthread, 0LL, r_cerca_contatto, &arg);
func10(arg);
goto LABEL_11;
case 3:
fwrite("[]=-=-=-=-=[MODIFICA CONTATTO]=-=-=-=-=[]\n\n", 1uLL, 0x2BuLL, stdout);
pthread_create(newthread, 0LL, r_modifica_contatto, &arg);
func11(arg);
goto LABEL_11;
case 4:
fwrite("[]=-=-=-=-=-=[NUOVO CONTATTO]=-=-=-=-=-=[]\n\n", 1uLL, 0x2CuLL, stdout);
pthread_create(newthread, 0LL, r_nuovo_contatto, &arg);
func12(arg);
goto LABEL_11;
case 5:
fwrite("[]=-=-=-=-=[CANCELLA CONTATTO]=-=-=-=-=[]\n\n", 1uLL, 0x2BuLL, stdout);
pthread_create(newthread, 0LL, r_cancella_contatto, &arg);
func13(arg);
goto LABEL_11;
case 6:
fwrite("[]=-=-=-=-=-=[COMPACT TABELLA]=-=-=-=-=-=[]\n\n", 1uLL, 0x2DuLL, stdout);
pthread_create(newthread, 0LL, r_compact_tabella, &arg);
func14(arg);
if ( pthread_join(newthread[0], 0LL) )
goto LABEL_17;
break;
case 7:
pthread_create(newthread, 0LL, r_program_exit, &arg);
func15(arg);
LABEL_11:
if ( pthread_join(newthread[0], 0LL) )
{
LABEL_17:
fwrite("Impossibile aspettare il tread\n", 1uLL, 0x1FuLL, stderr);
exit(1);
}
return result;
default:
fwrite("[ERRORE] Scelta errata!\n", 1uLL, 0x18uLL, stdout);
break;
}
if ( (unsigned int)ricevi_opzione(arg, &v8) )
func0(arg);
if ( v8 == 108 )
break;
if ( v10 == 7 )
goto LABEL_24;
}
fwrite(&unk_CC8, 1uLL, 0x39uLL, stdout);
fwrite(&unk_D08, 1uLL, 0x1EuLL, stdout);
v10 = 7;
LABEL_24:
chiudi_connessione(arg);
fwrite("Arrivederci\n", 1uLL, 0xCuLL, stdout);
exit(0);
}
LABEL_27:
arg = connetti("127.0.0.1", v6);
goto LABEL_8;
}

original_code:
int main(int argc, char *argv[]) {
 int temp;
 struct elemento *arg;
 pthread_t tid;
 int i, parametro_riconosciuto=0;
 int portnum = 3456;
 int debug_info = 0;
 for (i=1 ; i<argc ; i++) {
  if ((strcmp(argv[i],"-r") == 0) || (strcmp(argv[i],"--reset") == 0)) {
   reset_database();
   exit(0);
  }
  if ((strcmp(argv[i],"-h") == 0) || (strcmp(argv[i],"--help") == 0)) {
   stampa_help(argv[0]);
   exit(0);
  }
  if ((strcmp(argv[i],"-p") == 0) || (strcmp(argv[i],"--port") == 0)) {
   parametro_riconosciuto = 1;
   portnum = atoi(argv[++i]);
  }
  if ((strcmp(argv[i],"-v") == 0) || (strcmp(argv[i],"--verbose") == 0)) {
   parametro_riconosciuto = 1;
   debug_info = 1;
  }
  if (!parametro_riconosciuto) {
   fprintf(stdout,"OPZIONE NON RICONOSCIUTA.\n");
   stampa_help(argv[0]);
   exit(1);
  }
 }
 lista = adtl_crealista();
 main_thread = pthread_self();
 pthread_mutex_init(&scrittura, ((void *)0));
 pthread_mutex_init(&lettura, ((void *)0));
 pthread_mutex_init(&m_lista, ((void *)0));
 if (signal(2,handler_term) == ((__sighandler_t) -1))
  perror("signal"), exit(1);
 id_socket = avvia_server(10, portnum);
 fprintf(stdout,"Server avviato... premere <Control+C> per uscire.\n");
 while(1) {
  temp = accetta_connessione(id_socket);
  pthread_mutex_lock(&m_lista);
   lista = adtl_inserisci(lista, temp, debug_info);
   arg = adtl_elem_addr(lista, temp);
   pthread_create(&tid, ((void *)0), (void *(*)()) servi_client, arg);
  pthread_mutex_unlock(&m_lista);
  pthread_detach(tid);
 }
 exit(0);
}

canonical_original_code:
int main(int argc, char *argv[]) {
 int temp;
 struct elemento *arg;
 unsigned long tid;
 int i; int parametro_riconosciuto = 0;
 int portnum = 3456;
 int debug_info = 0;
 for (i=1 ; i<argc ; i++) {
  if ((strcmp(argv[i],"-r") == 0) || (strcmp(argv[i],"--reset") == 0)) {
   reset_database();
   exit(0);
  }
  if ((strcmp(argv[i],"-h") == 0) || (strcmp(argv[i],"--help") == 0)) {
   stampa_help(argv[0]);
   exit(0);
  }
  if ((strcmp(argv[i],"-p") == 0) || (strcmp(argv[i],"--port") == 0)) {
   parametro_riconosciuto = 1;
   portnum = atoi(argv[++i]);
  }
  if ((strcmp(argv[i],"-v") == 0) || (strcmp(argv[i],"--verbose") == 0)) {
   parametro_riconosciuto = 1;
   debug_info = 1;
  }
  if (!parametro_riconosciuto) {
   fprintf(stdout,"OPZIONE NON RICONOSCIUTA.\n");
   stampa_help(argv[0]);
   exit(1);
  }
 }
 lista = adtl_crealista();
 main_thread = pthread_self();
 pthread_mutex_init(&scrittura, ((void *)0));
 pthread_mutex_init(&lettura, ((void *)0));
 pthread_mutex_init(&m_lista, ((void *)0));
 if (signal(2,handler_term) == ((__sighandler_t) -1))
  perror("signal"), exit(1);
 id_socket = avvia_server(10, portnum);
 fprintf(stdout,"Server avviato... premere <Control+C> per uscire.\n");
 while(1) {
  temp = accetta_connessione(id_socket);
  pthread_mutex_lock(&m_lista);
   lista = adtl_inserisci(lista, temp, debug_info);
   arg = adtl_elem_addr(lista, temp);
   pthread_create(&tid, ((void *)0), (void *(*)()) servi_client, arg);
  pthread_mutex_unlock(&m_lista);
  pthread_detach(tid);
 }
 exit(0);
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: temp int

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

variable_types:
tid
unsigned long

variable_types: i int

variable_types: portnum int


decompiled_code:
void handler_term()
{
pthread_t v0; // rax

v0 = pthread_self();
if ( pthread_equal(main_thread, v0) )
{
fwrite("Chiusura del server in corso...\n", 1uLL, 0x20uLL, stdout);
devo_terminare = 1;
arresta_server((unsigned int)id_socket);
pthread_exit(0LL);
}
}

canonical_decompiled_code:
void func0()
{
pthread_t v0; // rax

v0 = pthread_self();
if ( pthread_equal(main_thread, v0) )
{
fwrite("Chiusura del server in corso...\n", 1uLL, 0x20uLL, stdout);
devo_terminare = 1;
arresta_server((unsigned int)id_socket);
pthread_exit(0LL);
}
}

original_code:
static void handler_term(int signo) {
 int elemento;
 if(pthread_equal(main_thread,pthread_self()) != 0) {
  fprintf(stdout,"Chiusura del server in corso...\n");
  devo_terminare=1;
  arresta_server(id_socket);
  pthread_exit(0);
 }
}

variable_types: signo int

variable_types: elemento int


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
__int64 v4; // r8
int v5; // er13
const char **v6; // r15
unsigned int v7; // ebx
unsigned int v8; // er14
int i; // er12
bool v10; // cf
bool v11; // zf
char *v12; // rbp
__int64 v13; // r9
bool v14; // cf
bool v15; // zf
bool v16; // cf
bool v17; // zf
const char *v18; // rdi
__int64 v19; // rcx
bool v20; // cf
bool v21; // zf
int v22; // eax
unsigned int v23; // ebp
void *v24; // rax
pthread_t newthread[8]; // [rsp+8h] [rbp-40h] BYREF

if ( argc <= 1 )
{
v7 = 0;
v8 = 3456;
}
else
{
v5 = argc;
v6 = argv;
v7 = 0;
v8 = 3456;
v4 = 0LL;
for ( i = 1; i < v5; ++i )
{
v12 = (char *)v6[i];
v13 = i;
envp = (const char **)(unsigned __int8)*v12;
v14 = (unsigned int)envp < 0x2D;
v15 = (_DWORD)envp == 45;
if ( (_DWORD)envp == 45 )
{
v14 = (unsigned __int8)v12[1] < 0x72u;
v15 = v12[1] == 114;
if ( v12[1] == 114 )
{
v14 = 0;
v15 = v12[2] == 0;
if ( !v12[2] )
goto LABEL_37;
}
}
*(_QWORD *)&argc = "--reset";
v3 = 8LL;
argv = (const char **)v6[i];
do
{
if ( !v3 )
break;
v14 = *(_BYTE *)argv < **(_BYTE **)&argc;
v15 = *(_BYTE *)argv == **(_BYTE **)&argc;
argv = (const char **)((char *)argv + 1);
++*(_QWORD *)&argc;
--v3;
}
while ( v15 );
if ( (!v14 && !v15) == v14 )
{
LABEL_37:
reset_database(*(_QWORD *)&argc, argv, envp, v3, v4, v13 * 8);
exit(0);
}
v16 = (unsigned int)envp < 0x2D;
v17 = (_DWORD)envp == 45;
if ( (_DWORD)envp == 45 )
{
v16 = (unsigned __int8)v12[1] < 0x68u;
v17 = v12[1] == 104;
if ( v12[1] == 104 )
{
v16 = 0;
v17 = v12[2] == 0;
if ( !v12[2] )
goto LABEL_38;
}
}
v18 = "--help";
v19 = 7LL;
argv = (const char **)v6[i];
do
{
if ( !v19 )
break;
v16 = *(_BYTE *)argv < *v18;
v17 = *(_BYTE *)argv == *v18;
argv = (const char **)((char *)argv + 1);
++v18;
--v19;
}
while ( v17 );
if ( (!v16 && !v17) == v16 )
{
LABEL_38:
stampa_help(*v6);
exit(0);
}
v20 = (unsigned int)envp < 0x2D;
v21 = (_DWORD)envp == 45;
if ( (_DWORD)envp == 45 )
{
v20 = (unsigned __int8)v12[1] < 0x70u;
v21 = v12[1] == 112;
if ( v12[1] == 112 )
{
v20 = 0;
v21 = v12[2] == 0;
if ( !v12[2] )
goto LABEL_24;
}
}
*(_QWORD *)&argc = "--port";
v3 = 7LL;
argv = (const char **)v6[i];
do
{
if ( !v3 )
break;
v20 = *(_BYTE *)argv < **(_BYTE **)&argc;
v21 = *(_BYTE *)argv == **(_BYTE **)&argc;
argv = (const char **)((char *)argv + 1);
++*(_QWORD *)&argc;
--v3;
}
while ( v21 );
if ( (!v20 && !v21) == v20 )
{
LABEL_24:
v12 = (char *)v6[v13 + 1];
++i;
*(_QWORD *)&argc = v12;
v22 = atoi(v12);
LODWORD(v4) = 1;
v8 = v22;
}
v10 = (unsigned __int8)*v12 < 0x2Du;
v11 = *v12 == 45;
if ( *v12 == 45 )
{
v10 = (unsigned __int8)v12[1] < 0x76u;
v11 = v12[1] == 118;
if ( v12[1] == 118 )
{
v10 = 0;
v11 = v12[2] == 0;
if ( !v12[2] )
goto LABEL_5;
}
}
*(_QWORD *)&argc = "--verbose";
v3 = 10LL;
argv = (const char **)v12;
do
{
if ( !v3 )
break;
v10 = *(_BYTE *)argv < **(_BYTE **)&argc;
v11 = *(_BYTE *)argv == **(_BYTE **)&argc;
argv = (const char **)((char *)argv + 1);
++*(_QWORD *)&argc;
--v3;
}
while ( v11 );
if ( (!v10 && !v11) == v10 )
{
LABEL_5:
v7 = 1;
}
else if ( !(_DWORD)v4 )
{
fwrite("OPZIONE NON RICONOSCIUTA.\n", 1uLL, 0x1AuLL, stdout);
stampa_help(*v6);
exit(1);
}
v4 = 1LL;
}
}
lista = adtl_crealista(*(_QWORD *)&argc, argv, envp, v3, v4);
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, v8);
fwrite("Server avviato... premere <Control+C> per uscire.\n", 1uLL, 0x32uLL, stdout);
while ( 1 )
{
v23 = accetta_connessione((unsigned int)id_socket);
pthread_mutex_lock(&m_lista);
lista = adtl_inserisci(lista, v23, v7);
v24 = (void *)adtl_elem_addr(lista, v23);
pthread_create(newthread, 0LL, (void *(*)(void *))servi_client, v24);
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
__int64 v4; // r8
int v5; // er13
const char **v6; // r15
unsigned int v7; // ebx
unsigned int v8; // er14
int i; // er12
bool v10; // cf
bool v11; // zf
char *v12; // rbp
__int64 v13; // r9
bool v14; // cf
bool v15; // zf
bool v16; // cf
bool v17; // zf
const char *v18; // rdi
__int64 v19; // rcx
bool v20; // cf
bool v21; // zf
int v22; // eax
unsigned int v23; // ebp
void *v24; // rax
pthread_t newthread[8]; // [rsp+8h] [rbp-40h] BYREF

if ( argc <= 1 )
{
v7 = 0;
v8 = 3456;
}
else
{
v5 = argc;
v6 = argv;
v7 = 0;
v8 = 3456;
v4 = 0LL;
for ( i = 1; i < v5; ++i )
{
v12 = (char *)v6[i];
v13 = i;
envp = (const char **)(unsigned __int8)*v12;
v14 = (unsigned int)envp < 0x2D;
v15 = (_DWORD)envp == 45;
if ( (_DWORD)envp == 45 )
{
v14 = (unsigned __int8)v12[1] < 0x72u;
v15 = v12[1] == 114;
if ( v12[1] == 114 )
{
v14 = 0;
v15 = v12[2] == 0;
if ( !v12[2] )
goto LABEL_37;
}
}
*(_QWORD *)&argc = "--reset";
v3 = 8LL;
argv = (const char **)v6[i];
do
{
if ( !v3 )
break;
v14 = *(_BYTE *)argv < **(_BYTE **)&argc;
v15 = *(_BYTE *)argv == **(_BYTE **)&argc;
argv = (const char **)((char *)argv + 1);
++*(_QWORD *)&argc;
--v3;
}
while ( v15 );
if ( (!v14 && !v15) == v14 )
{
LABEL_37:
reset_database(*(_QWORD *)&argc, argv, envp, v3, v4, v13 * 8);
exit(0);
}
v16 = (unsigned int)envp < 0x2D;
v17 = (_DWORD)envp == 45;
if ( (_DWORD)envp == 45 )
{
v16 = (unsigned __int8)v12[1] < 0x68u;
v17 = v12[1] == 104;
if ( v12[1] == 104 )
{
v16 = 0;
v17 = v12[2] == 0;
if ( !v12[2] )
goto LABEL_38;
}
}
v18 = "--help";
v19 = 7LL;
argv = (const char **)v6[i];
do
{
if ( !v19 )
break;
v16 = *(_BYTE *)argv < *v18;
v17 = *(_BYTE *)argv == *v18;
argv = (const char **)((char *)argv + 1);
++v18;
--v19;
}
while ( v17 );
if ( (!v16 && !v17) == v16 )
{
LABEL_38:
func9(*v6);
exit(0);
}
v20 = (unsigned int)envp < 0x2D;
v21 = (_DWORD)envp == 45;
if ( (_DWORD)envp == 45 )
{
v20 = (unsigned __int8)v12[1] < 0x70u;
v21 = v12[1] == 112;
if ( v12[1] == 112 )
{
v20 = 0;
v21 = v12[2] == 0;
if ( !v12[2] )
goto LABEL_24;
}
}
*(_QWORD *)&argc = "--port";
v3 = 7LL;
argv = (const char **)v6[i];
do
{
if ( !v3 )
break;
v20 = *(_BYTE *)argv < **(_BYTE **)&argc;
v21 = *(_BYTE *)argv == **(_BYTE **)&argc;
argv = (const char **)((char *)argv + 1);
++*(_QWORD *)&argc;
--v3;
}
while ( v21 );
if ( (!v20 && !v21) == v20 )
{
LABEL_24:
v12 = (char *)v6[v13 + 1];
++i;
*(_QWORD *)&argc = v12;
v22 = atoi(v12);
LODWORD(v4) = 1;
v8 = v22;
}
v10 = (unsigned __int8)*v12 < 0x2Du;
v11 = *v12 == 45;
if ( *v12 == 45 )
{
v10 = (unsigned __int8)v12[1] < 0x76u;
v11 = v12[1] == 118;
if ( v12[1] == 118 )
{
v10 = 0;
v11 = v12[2] == 0;
if ( !v12[2] )
goto LABEL_5;
}
}
*(_QWORD *)&argc = "--verbose";
v3 = 10LL;
argv = (const char **)v12;
do
{
if ( !v3 )
break;
v10 = *(_BYTE *)argv < **(_BYTE **)&argc;
v11 = *(_BYTE *)argv == **(_BYTE **)&argc;
argv = (const char **)((char *)argv + 1);
++*(_QWORD *)&argc;
--v3;
}
while ( v11 );
if ( (!v10 && !v11) == v10 )
{
LABEL_5:
v7 = 1;
}
else if ( !(_DWORD)v4 )
{
fwrite("OPZIONE NON RICONOSCIUTA.\n", 1uLL, 0x1AuLL, stdout);
func9(*v6);
exit(1);
}
v4 = 1LL;
}
}
lista = adtl_crealista(*(_QWORD *)&argc, argv, envp, v3, v4);
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, v8);
fwrite("Server avviato... premere <Control+C> per uscire.\n", 1uLL, 0x32uLL, stdout);
while ( 1 )
{
v23 = accetta_connessione((unsigned int)id_socket);
pthread_mutex_lock(&m_lista);
lista = adtl_inserisci(lista, v23, v7);
v24 = (void *)adtl_elem_addr(lista, v23);
pthread_create(newthread, 0LL, (void *(*)(void *))servi_client, v24);
pthread_mutex_unlock(&m_lista);
pthread_detach(newthread[0]);
}
}
perror("signal");
exit(1);
}

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


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


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

v6 = 0;
if ( a2 )
{
v5 = pthread_self();
fprintf(stdout, "[thread %d] stampa contatti\n", v5);
}
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, v7, &v6) )
{
if ( !(unsigned int)cancellato(v7) && (unsigned int)trasmetti(a1, v7, 251LL) )
goto LABEL_13;
}
chiudi_file(v2);
pthread_mutex_lock(&lettura);
if ( !--num_lettori )
pthread_mutex_unlock(&scrittura);
pthread_mutex_unlock(&lettura);
prendi_record_sentinella(v7);
result = trasmetti(a1, v7, 251LL);
if ( (_DWORD)result )
{
LABEL_13:
v4 = pthread_self();
fatal_error(a1, v4, a2);
}
return result;
}

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

v6 = 0;
if ( a2 )
{
v5 = pthread_self();
fprintf(stdout, "[thread %d] stampa contatti\n", v5);
}
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, v7, &v6) )
{
if ( !(unsigned int)cancellato(v7) && (unsigned int)trasmetti(a1, v7, 251LL) )
goto LABEL_13;
}
chiudi_file(v2);
pthread_mutex_lock(&lettura);
if ( !--num_lettori )
pthread_mutex_unlock(&scrittura);
pthread_mutex_unlock(&lettura);
prendi_record_sentinella(v7);
result = trasmetti(a1, v7, 251LL);
if ( (_DWORD)result )
{
LABEL_13:
v4 = pthread_self();
func1(a1, v4, 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; // ebp
__int64 result; // rax
__int64 v4; // rax
pthread_t v5; // r14
int v6; // [rsp+Ch] [rbp-22Ch] BYREF
char v7[256]; // [rsp+10h] [rbp-228h] BYREF
char v8[296]; // [rsp+110h] [rbp-128h] BYREF

v6 = 0;
if ( a2 )
{
v5 = pthread_self();
fprintf(stdout, "[thread %d] cerca contatto\n", v5);
if ( (unsigned int)ricevi((unsigned int)a1, v7, 251LL) )
goto LABEL_13;
fprintf(stdout, "-------------Ricevuto record da %d:\n", v5);
stampa_record(v7);
fwrite("Fine record-----------------------------\n", 1uLL, 0x29uLL, stdout);
}
else if ( (unsigned int)ricevi(a1, v7, 251LL) )
{
goto LABEL_13;
}
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, &v6) )
{
if ( (unsigned int)idoneo(v7, v8) == 1 && (unsigned int)trasmetti((unsigned int)a1, v8, 251LL) )
goto LABEL_13;
}
chiudi_file(v2);
pthread_mutex_lock(&lettura);
if ( !--num_lettori )
pthread_mutex_unlock(&scrittura);
pthread_mutex_unlock(&lettura);
prendi_record_sentinella(v8);
result = trasmetti((unsigned int)a1, v8, 251LL);
if ( (_DWORD)result )
{
LABEL_13:
v4 = pthread_self();
fatal_error(a1, v4, a2);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int a2)
{
unsigned int v2; // ebp
__int64 result; // rax
__int64 v4; // rax
pthread_t v5; // r14
int v6; // [rsp+Ch] [rbp-22Ch] BYREF
char v7[256]; // [rsp+10h] [rbp-228h] BYREF
char v8[296]; // [rsp+110h] [rbp-128h] BYREF

v6 = 0;
if ( a2 )
{
v5 = pthread_self();
fprintf(stdout, "[thread %d] cerca contatto\n", v5);
if ( (unsigned int)ricevi((unsigned int)a1, v7, 251LL) )
goto LABEL_13;
fprintf(stdout, "-------------Ricevuto record da %d:\n", v5);
stampa_record(v7);
fwrite("Fine record-----------------------------\n", 1uLL, 0x29uLL, stdout);
}
else if ( (unsigned int)ricevi(a1, v7, 251LL) )
{
goto LABEL_13;
}
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, &v6) )
{
if ( (unsigned int)idoneo(v7, v8) == 1 && (unsigned int)trasmetti((unsigned int)a1, v8, 251LL) )
goto LABEL_13;
}
chiudi_file(v2);
pthread_mutex_lock(&lettura);
if ( !--num_lettori )
pthread_mutex_unlock(&scrittura);
pthread_mutex_unlock(&lettura);
prendi_record_sentinella(v8);
result = trasmetti((unsigned int)a1, v8, 251LL);
if ( (_DWORD)result )
{
LABEL_13:
v4 = pthread_self();
func1(a1, v4, 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);
}


decompiled_code:
int __fastcall modifica_contatto(unsigned int a1, int a2)
{
int v2; // ebx
int v3; // eax
int result; // eax
__int64 v5; // rax
pthread_t v6; // rax
_BYTE v7[80]; // [rsp+0h] [rbp-168h] BYREF
char v8[280]; // [rsp+50h] [rbp-118h] BYREF

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

canonical_decompiled_code:
int __fastcall func4(unsigned int a1, int a2)
{
int v2; // ebx
int v3; // eax
int result; // eax
__int64 v5; // rax
pthread_t v6; // rax
_BYTE v7[80]; // [rsp+0h] [rbp-168h] BYREF
char v8[280]; // [rsp+50h] [rbp-118h] BYREF

if ( a2 )
{
v6 = pthread_self();
fprintf(stdout, "[thread %d] modifica contatto\n", v6);
}
if ( (unsigned int)ricevi(a1, v7, 80LL) )
goto LABEL_15;
pthread_mutex_lock(&lettura);
if ( ++num_lettori == 1 )
pthread_mutex_lock(&scrittura);
pthread_mutex_unlock(&lettura);
v2 = trova_record(v7);
pthread_mutex_lock(&lettura);
if ( !--num_lettori )
pthread_mutex_unlock(&scrittura);
pthread_mutex_unlock(&lettura);
if ( v2 >= 0 )
{
if ( !(unsigned int)trasmetti_opzione(a1, 104LL) && !(unsigned int)ricevi(a1, v8, 251LL) )
{
pthread_mutex_lock(&scrittura);
v3 = modifica_record(v8, v7);
if ( !(unsigned int)trasmetti_opzione(a1, 104 - ((unsigned int)(v3 == 0) - 1)) )
return pthread_mutex_unlock(&scrittura);
}
LABEL_15:
v5 = pthread_self();
func1(a1, v5, a2);
}
result = trasmetti_opzione(a1, 105LL);
if ( result )
goto LABEL_15;
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: posizione int


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

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

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

if ( a2 )
{
v4 = pthread_self();
fprintf(stdout, "[thread %d] nuovo contatto\n", v4);
if ( (unsigned int)ricevi((unsigned int)a1, v6, 251LL) )
{
LABEL_7:
v5 = pthread_self();
func1(a1, v5, a2);
}
fprintf(stdout, "-------------Ricevuto record da %d:\n", v4);
stampa_record(v6);
fwrite("Fine record-----------------------------\n", 1uLL, 0x29uLL, stdout);
}
else if ( (unsigned int)ricevi(a1, v6, 251LL) )
{
goto LABEL_7;
}
pthread_mutex_lock(&scrittura);
v2 = nuovo_record(v6);
if ( (unsigned int)trasmetti_opzione((unsigned int)a1, 104 - ((unsigned int)(v2 == 0) - 1)) )
goto LABEL_7;
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
_BYTE v6[104]; // [rsp+0h] [rbp-68h] BYREF

if ( a2 )
{
v4 = pthread_self();
fprintf(stdout, "[thread %d] cancella contatto\n", v4);
}
if ( (unsigned int)ricevi(a1, v6, 80LL)
|| (pthread_mutex_lock(&scrittura),
v2 = cancella_record(v6),
(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 func6(unsigned int a1, int a2)
{
int v2; // eax
pthread_t v4; // rax
__int64 v5; // rax
_BYTE v6[104]; // [rsp+0h] [rbp-68h] BYREF

if ( a2 )
{
v4 = pthread_self();
fprintf(stdout, "[thread %d] cancella contatto\n", v4);
}
if ( (unsigned int)ricevi(a1, v6, 80LL)
|| (pthread_mutex_lock(&scrittura),
v2 = cancella_record(v6),
(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 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);
}


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 v4; // er12
int v6; // eax

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

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

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

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


trasmetti

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

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

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

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

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:
_BOOL8 __fastcall ricevi_opzione(int a1, void *a2)
{
return (int)read(a1, a2, 1uLL) <= 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(int a1, void *a2)
{
return (int)read(a1, a2, 1uLL) <= 0;
}

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:
_BOOL8 __fastcall trasmetti_opzione(int a1, char a2)
{
char buf[12]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = a2;
return (int)write(a1, buf, 1uLL) <= 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(int a1, char a2)
{
char buf[12]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = a2;
return (int)write(a1, buf, 1uLL) <= 0;
}

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)
{
while ( 1 )
{
if ( !a1 )
return 0LL;
if ( *(_DWORD *)a1 == a2 )
break;
a1 = *(_QWORD *)(a1 + 8);
}
return a1;
}

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

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

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


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; // edx
int v3; // eax
unsigned int v4; // er12
struct sockaddr v6; // [rsp+0h] [rbp-28h] BYREF

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

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

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

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