Produzione

decompiled_code:
void __fastcall Produzione(int a1, __int64 a2, __int64 a3)
{
*(_QWORD *)(a3 + 8LL * a1) = a2;
}

canonical_decompiled_code:
void __fastcall func15(int a1, __int64 a2, __int64 a3)
{
*(_QWORD *)(a3 + 8LL * a1) = a2;
}

original_code:
void Produzione(int indice,msg messaggio,msg *buffer){
 buffer[indice]=messaggio;
}

canonical_original_code:
void Produzione(int indice, long messaggio, long *buffer){
 buffer[indice]=messaggio;
}


RilascioP

repo: robertovela/sisop

decompiled_code:
int __fastcall RilascioP(int a1, __int64 a2, int a3)
{
*(_DWORD *)(a2 + 4LL * a1) = 3;
return Signal_Sem(a3, 1u);
}

canonical_decompiled_code:
int __fastcall func16(int a1, __int64 a2, int a3)
{
*(_DWORD *)(a2 + 4LL * a1) = 3;
return func9(a3, 1u);
}

original_code:
void RilascioP (int indice,int*stato,int sem){
 stato[indice]=3;
 Signal_Sem(sem,1);
}

canonical_original_code:
void RilascioP(int indice, int *stato, int sem){
 stato[indice]=3;
 Signal_Sem(sem,1);
}

variable_types: indice int

variable_types:
stato
int *

variable_types: sem int

return_type: void


Fornitore

decompiled_code:
__int64 __fastcall Fornitore(__int64 a1, _DWORD *a2, __int64 a3)
{
int v4; // er12
__pid_t *v5; // r14
unsigned int v6; // eax
__int64 result; // rax
_DWORD *v8; // rcx
int i; // edx

v4 = 15;
do
{
enter_monitor(a1);
if ( *a2 == 100 )
wait_condition(a1, 0LL);
v8 = (_DWORD *)(a3 + 4);
for ( i = 0; i != 100; ++i )
{
if ( (unsigned int)(*v8 - 1) > 1 )
break;
v8 += 2;
}
v5 = (__pid_t *)(a3 + 8LL * i);
v5[1] = 2;
leave_monitor(a1);
sleep(2u);
v6 = getpid();
printf("Fornitura effettuata dal Fornitore %d\n", v6);
*v5 = getpid();
enter_monitor(a1);
v5[1] = 1;
++*a2;
result = signal_condition(a1, 1LL);
--v4;
}
while ( v4 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, _DWORD *a2, __int64 a3)
{
int v4; // er12
__pid_t *v5; // r14
unsigned int v6; // eax
__int64 result; // rax
_DWORD *v8; // rcx
int i; // edx

v4 = 15;
do
{
enter_monitor(a1);
if ( *a2 == 100 )
wait_condition(a1, 0LL);
v8 = (_DWORD *)(a3 + 4);
for ( i = 0; i != 100; ++i )
{
if ( (unsigned int)(*v8 - 1) > 1 )
break;
v8 += 2;
}
v5 = (__pid_t *)(a3 + 8LL * i);
v5[1] = 2;
leave_monitor(a1);
sleep(2u);
v6 = getpid();
printf("Fornitura effettuata dal Fornitore %d\n", v6);
*v5 = getpid();
enter_monitor(a1);
v5[1] = 1;
++*a2;
result = signal_condition(a1, 1LL);
--v4;
}
while ( v4 );
return result;
}

original_code:
void Fornitore(Monitor* M ,int* livello_scorte ,Magazzino* magazzino)
{
 int i,k;
 for(k=0;k<15;k++)
 {
  i=0;
  enter_monitor(M);
  if((*livello_scorte)==100)
   wait_condition(M,0);
  while(i<100 && ((*magazzino)[i].stato==1 || (*magazzino)[i].stato==2))
  {
   i++;
  }
  (*magazzino)[i].stato=2;
  leave_monitor(M);
  sleep(2);
  printf("Fornitura effettuata dal Fornitore %d\n",getpid());
  (*magazzino)[i].id_fornitore=getpid();
  enter_monitor(M);
  (*magazzino)[i].stato=1;
  (*livello_scorte)++;
  signal_condition(M,1);
 }
}

canonical_original_code:
void Fornitore(struct Monitor *M, int *livello_scorte, struct Scaffale (*magazzino)[100])
{
 int i; int k;
 for(k=0;k<15;k++)
 {
  i=0;
  enter_monitor(M);
  if((*livello_scorte)==100)
   wait_condition(M,0);
  while(i<100 && ((*magazzino)[i].stato==1 || (*magazzino)[i].stato==2))
  {
   i++;
  }
  (*magazzino)[i].stato=2;
  leave_monitor(M);
  sleep(2);
  printf("Fornitura effettuata dal Fornitore %d\n",getpid());
  (*magazzino)[i].id_fornitore=getpid();
  enter_monitor(M);
  (*magazzino)[i].stato=1;
  (*livello_scorte)++;
  signal_condition(M,1);
 }
}

variable_types: struct Monitor { int mutex; int num_var_cond; int id_conds; int *cond_counts; int id_shared; } *

variable_types: struct Scaffale { unsigned int id_fornitore; unsigned int stato; } (*)[100]

variable_types: i int

variable_types: k int


Cliente

decompiled_code:
__int64 __fastcall Cliente(__int64 a1, _DWORD *a2, __int64 a3)
{
int v4; // er13
unsigned int *v5; // r15
__int64 result; // rax
_DWORD *v7; // rax
unsigned int i; // ebx

v4 = 15;
do
{
enter_monitor(a1);
if ( !*a2 )
wait_condition(a1, 1LL);
v7 = (_DWORD *)(a3 + 4);
for ( i = 0; i != 100; ++i )
{
if ( (*v7 & 0xFFFFFFFD) != 0 )
break;
v7 += 2;
}
v5 = (unsigned int *)(a3 + 8LL * (int)i);
v5[1] = 2;
leave_monitor(a1);
sleep(2u);
printf("Acquisto effettuato, merce venduta dal Fornitore %d \n", *v5);
printf("magazzino[%d].stato=%d\n", i, v5[1]);
enter_monitor(a1);
v5[1] = 0;
--*a2;
result = signal_condition(a1, 0LL);
--v4;
}
while ( v4 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, _DWORD *a2, __int64 a3)
{
int v4; // er13
unsigned int *v5; // r15
__int64 result; // rax
_DWORD *v7; // rax
unsigned int i; // ebx

v4 = 15;
do
{
enter_monitor(a1);
if ( !*a2 )
wait_condition(a1, 1LL);
v7 = (_DWORD *)(a3 + 4);
for ( i = 0; i != 100; ++i )
{
if ( (*v7 & 0xFFFFFFFD) != 0 )
break;
v7 += 2;
}
v5 = (unsigned int *)(a3 + 8LL * (int)i);
v5[1] = 2;
leave_monitor(a1);
sleep(2u);
printf("Acquisto effettuato, merce venduta dal Fornitore %d \n", *v5);
printf("magazzino[%d].stato=%d\n", i, v5[1]);
enter_monitor(a1);
v5[1] = 0;
--*a2;
result = signal_condition(a1, 0LL);
--v4;
}
while ( v4 );
return result;
}

original_code:
void Cliente(Monitor* M ,int* livello_scorte ,Magazzino* magazzino)
{
 int i,k;
 for(k=0;k<15;k++)
 {
  i=0;
  enter_monitor(M);
  if((*livello_scorte)==0)
   wait_condition(M,1);
  while(i<100 && ((*magazzino)[i].stato==0 || (*magazzino)[i].stato==2))
  {
   i++;
  }
  (*magazzino)[i].stato=2;
  leave_monitor(M);
  sleep(2);
  printf("Acquisto effettuato, merce venduta dal Fornitore %d \n",(*magazzino)[i].id_fornitore);
  printf("magazzino[%d].stato=%d\n",i,(*magazzino)[i].stato);
  enter_monitor(M);
  (*magazzino)[i].stato=0;
  (*livello_scorte)--;
  signal_condition(M,0);
 }
}

canonical_original_code:
void Cliente(struct Monitor *M, int *livello_scorte, struct Scaffale (*magazzino)[100])
{
 int i; int k;
 for(k=0;k<15;k++)
 {
  i=0;
  enter_monitor(M);
  if((*livello_scorte)==0)
   wait_condition(M,1);
  while(i<100 && ((*magazzino)[i].stato==0 || (*magazzino)[i].stato==2))
  {
   i++;
  }
  (*magazzino)[i].stato=2;
  leave_monitor(M);
  sleep(2);
  printf("Acquisto effettuato, merce venduta dal Fornitore %d \n",(*magazzino)[i].id_fornitore);
  printf("magazzino[%d].stato=%d\n",i,(*magazzino)[i].stato);
  enter_monitor(M);
  (*magazzino)[i].stato=0;
  (*livello_scorte)--;
  signal_condition(M,0);
 }
}

user_defined_types: struct Monitor { int mutex; int num_var_cond; int id_conds; int *cond_counts; int id_shared; }

user_defined_types: struct Scaffale { unsigned int id_fornitore; unsigned int stato; }


Servizio

decompiled_code:
unsigned int __fastcall Servizio(__int64 a1, __int64 a2)
{
unsigned int v2; // eax
int v3; // er12
__int16 v4; // ax
const char *v5; // rbp
unsigned int v6; // er15
unsigned int v7; // er14
unsigned int v8; // eax
unsigned int result; // eax

v2 = time(0LL);
srand(v2);
v3 = 20;
do
{
InizioScrittura(a1, a2);
*(_DWORD *)a2 = rand() % 101 - 50;
*(_DWORD *)(a2 + 4) = rand() % 101;
v4 = rand() % 2;
*(_WORD *)(a2 + 8) = v4;
v5 = "no";
if ( v4 )
v5 = "si";
v6 = *(_DWORD *)(a2 + 4);
v7 = *(_DWORD *)a2;
v8 = getpid();
printf(format, v8, v7, v6, v5);
FineScrittura(a1, a2);
result = sleep(2u);
--v3;
}
while ( v3 );
return result;
}

canonical_decompiled_code:
unsigned int __fastcall func11(__int64 a1, __int64 a2)
{
unsigned int v2; // eax
int v3; // er12
__int16 v4; // ax
const char *v5; // rbp
unsigned int v6; // er15
unsigned int v7; // er14
unsigned int v8; // eax
unsigned int result; // eax

v2 = time(0LL);
srand(v2);
v3 = 20;
do
{
func9(a1, a2);
*(_DWORD *)a2 = rand() % 101 - 50;
*(_DWORD *)(a2 + 4) = rand() % 101;
v4 = rand() % 2;
*(_WORD *)(a2 + 8) = v4;
v5 = "no";
if ( v4 )
v5 = "si";
v6 = *(_DWORD *)(a2 + 4);
v7 = *(_DWORD *)a2;
v8 = getpid();
printf(format, v8, v7, v6, v5);
func10(a1, a2);
result = sleep(2u);
--v3;
}
while ( v3 );
return result;
}

original_code:
void Servizio(Monitor* m, Buffer * buf){
 srand(time(0));
 int i;
 for(i=0; i<20; i++) {
  InizioScrittura(m,buf);
  buf->meteo.temperatura = (rand()%101)-50;
  buf->meteo.umidita = rand()%101;
  buf->meteo.pioggia = rand()%2;
  printf("<%d> scrittura: Temperatura=%d, Umidità=%d, Pioggia=%s\n", getpid(), buf->meteo.temperatura, buf->meteo.umidita, (buf->meteo.pioggia ? "si" : "no") );
  FineScrittura(m,buf);
  sleep(2);
 }
}

canonical_original_code:
void Servizio(struct Monitor *m, struct Buffer *buf){
 srand(time(0));
 int i;
 for(i=0; i<20; i++) {
  InizioScrittura(m,buf);
  buf->meteo.temperatura = (rand()%101)-50;
  buf->meteo.umidita = rand()%101;
  buf->meteo.pioggia = rand()%2;
  printf("<%d> scrittura: Temperatura=%d, Umidità=%d, Pioggia=%s\n", getpid(), buf->meteo.temperatura, buf->meteo.umidita, (buf->meteo.pioggia ? "si" : "no") );
  FineScrittura(m,buf);
  sleep(2);
 }
}

variable_types: struct Monitor { int mutex; int urgent_sem; int num_var_cond; int id_conds; int id_shared; int *cond_counts; int *urgent_count; } *

variable_types: struct Buffer { struct meteo { int temperatura; unsigned int umidita; unsigned short pioggia; } meteo; unsigned short occupato; unsigned int numlettori; } *

user_defined_types: struct Buffer { struct meteo meteo; unsigned short occupato; unsigned int numlettori; }


Utente

decompiled_code:
unsigned int __fastcall Utente(__int64 a1, __int64 a2)
{
int v2; // er12
const char *v3; // rbp
unsigned int v4; // er15
unsigned int v5; // er14
unsigned int v6; // eax
unsigned int result; // eax

v2 = 10;
do
{
InizioLettura(a1, a2);
v3 = "no";
if ( *(_WORD *)(a2 + 8) )
v3 = "si";
v4 = *(_DWORD *)(a2 + 4);
v5 = *(_DWORD *)a2;
v6 = getpid();
printf(aDLetturaTemper, v6, v5, v4, v3);
FineLettura(a1, a2);
result = sleep(1u);
--v2;
}
while ( v2 );
return result;
}

canonical_decompiled_code:
unsigned int __fastcall func12(__int64 a1, __int64 a2)
{
int v2; // er12
const char *v3; // rbp
unsigned int v4; // er15
unsigned int v5; // er14
unsigned int v6; // eax
unsigned int result; // eax

v2 = 10;
do
{
func7(a1, a2);
v3 = "no";
if ( *(_WORD *)(a2 + 8) )
v3 = "si";
v4 = *(_DWORD *)(a2 + 4);
v5 = *(_DWORD *)a2;
v6 = getpid();
printf(aDLetturaTemper, v6, v5, v4, v3);
func8(a1, a2);
result = sleep(1u);
--v2;
}
while ( v2 );
return result;
}

original_code:
void Utente(Monitor* m, Buffer * buf) {
 int i;
 for(i=0; i<10; i++) {
  InizioLettura(m,buf);
  printf("<%d> lettura: Temperatura=%d, Umidità=%d, Pioggia=%s\n", getpid(), buf->meteo.temperatura, buf->meteo.umidita, (buf->meteo.pioggia ? "si" : "no") );
  FineLettura(m,buf);
  sleep(1);
 }
}

canonical_original_code:
void Utente(struct Monitor *m, struct Buffer *buf) {
 int i;
 for(i=0; i<10; i++) {
  InizioLettura(m,buf);
  printf("<%d> lettura: Temperatura=%d, Umidità=%d, Pioggia=%s\n", getpid(), buf->meteo.temperatura, buf->meteo.umidita, (buf->meteo.pioggia ? "si" : "no") );
  FineLettura(m,buf);
  sleep(1);
 }
}

user_defined_types: struct Monitor { int mutex; int urgent_sem; int num_var_cond; int id_conds; int id_shared; int *cond_counts; int *urgent_count; }

user_defined_types: struct meteo { int temperatura; unsigned int umidita; unsigned short pioggia; }


InizioLettura

decompiled_code:
__int64 __fastcall InizioLettura(__int64 a1, __int64 a2)
{
enter_monitor();
if ( *(_WORD *)(a2 + 12) && !*(_DWORD *)(a2 + 16) )
wait_condition(a1, 0LL);
*(_WORD *)(a2 + 12) = 1;
++*(_DWORD *)(a2 + 16);
signal_condition(a1, 0LL);
return leave_monitor(a1);
}

original_code:
void InizioLettura(Monitor* m, Buffer * buf){
 enter_monitor(m);
 if (buf->occupato && buf->numlettori==0)
  wait_condition(m,0);
 buf->occupato = 1;
 buf->numlettori=buf->numlettori+1;
 signal_condition(m,0);
 leave_monitor(m);
}

canonical_original_code:
void InizioLettura(struct Monitor *m, struct Buffer *buf){
 enter_monitor(m);
 if (buf->occupato && buf->numlettori==0)
  wait_condition(m,0);
 buf->occupato = 1;
 buf->numlettori=buf->numlettori+1;
 signal_condition(m,0);
 leave_monitor(m);
}


FineLettura

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

enter_monitor();
v2 = *(_DWORD *)(a2 + 16) - 1;
*(_DWORD *)(a2 + 16) = v2;
if ( !v2 )
{
*(_WORD *)(a2 + 12) = 0;
signal_condition(a1, 1LL);
}
return leave_monitor(a1);
}

original_code:
void FineLettura(Monitor* m, Buffer * buf) {
 enter_monitor(m);
 buf->numlettori=buf->numlettori-1;
 if (buf->numlettori==0) {
       buf->occupato=0;
  signal_condition(m,1);
 }
 leave_monitor(m);
}

canonical_original_code:
void FineLettura(struct Monitor *m, struct Buffer *buf) {
 enter_monitor(m);
 buf->numlettori=buf->numlettori-1;
 if (buf->numlettori==0) {
       buf->occupato=0;
  signal_condition(m,1);
 }
 leave_monitor(m);
}


InizioScrittura

decompiled_code:
__int64 __fastcall InizioScrittura(__int64 a1, __int64 a2)
{
enter_monitor();
if ( *(_WORD *)(a2 + 12) )
wait_condition(a1, 1LL);
*(_WORD *)(a2 + 12) = 1;
return leave_monitor(a1);
}

original_code:
void InizioScrittura(Monitor* m,Buffer*buf){
 enter_monitor(m);
 if (buf->occupato)
  wait_condition(m,1);
 buf->occupato = 1;
 leave_monitor(m);
}

canonical_original_code:
void InizioScrittura(struct Monitor *m, struct Buffer *buf){
 enter_monitor(m);
 if (buf->occupato)
  wait_condition(m,1);
 buf->occupato = 1;
 leave_monitor(m);
}


FineScrittura

decompiled_code:
__int64 __fastcall FineScrittura(__int64 a1, __int64 a2)
{
enter_monitor();
if ( (int)queue_condition(a1, 1LL) <= 0 )
{
if ( (int)queue_condition(a1, 0LL) > 0 )
signal_condition(a1, 0LL);
else
*(_WORD *)(a2 + 12) = 0;
}
else
{
signal_condition(a1, 1LL);
}
return leave_monitor(a1);
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, __int64 a2)
{
func16();
if ( (int)func20(a1, 1LL) <= 0 )
{
if ( (int)func20(a1, 0LL) > 0 )
signal_condition(a1, 0LL);
else
*(_WORD *)(a2 + 12) = 0;
}
else
{
signal_condition(a1, 1LL);
}
return func17(a1);
}

original_code:
void FineScrittura(Monitor* m, Buffer*buf){
 enter_monitor(m);
 if (queue_condition(m,1)>0) {
  signal_condition(m,1);
        } else if (queue_condition(m,0)>0) {
  signal_condition(m,0);
 } else {
  buf->occupato = 0;
 }
 leave_monitor(m);
}

canonical_original_code:
void FineScrittura(struct Monitor *m, struct Buffer *buf){
 enter_monitor(m);
 if (queue_condition(m,1)>0) {
  signal_condition(m,1);
        } else if (queue_condition(m,0)>0) {
  signal_condition(m,0);
 } else {
  buf->occupato = 0;
 }
 leave_monitor(m);
}


InizioConsumo

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

for ( result = pthread_mutex_lock(&mutex); !ok_consumo; result = pthread_cond_wait(&ok_cons_cv, &mutex) )
;
return result;
}

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

for ( result = pthread_mutex_lock(&mutex); !ok_consumo; result = pthread_cond_wait(&ok_cons_cv, &mutex) )
;
return result;
}

original_code:
void InizioConsumo(){
 pthread_mutex_lock(&mutex);
 while (ok_consumo==0)
  pthread_cond_wait(&ok_cons_cv,&mutex);
}


FineConsumo

decompiled_code:
int FineConsumo()
{
ok_produzione = 1;
ok_consumo = 0;
pthread_cond_signal(&ok_prod_cv);
return pthread_mutex_unlock(&mutex);
}

canonical_decompiled_code:
int func1()
{
ok_produzione = 1;
ok_consumo = 0;
pthread_cond_signal(&ok_prod_cv);
return pthread_mutex_unlock(&mutex);
}

original_code:
void FineConsumo(){
        ok_produzione = 1;
 ok_consumo = 0;
 pthread_cond_signal(&ok_prod_cv);
 pthread_mutex_unlock(&mutex);
}


InizioProduzione

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

for ( result = pthread_mutex_lock(&mutex); !ok_produzione; result = pthread_cond_wait(&ok_prod_cv, &mutex) )
;
return result;
}

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

for ( result = pthread_mutex_lock(&mutex); !ok_produzione; result = pthread_cond_wait(&ok_prod_cv, &mutex) )
;
return result;
}

original_code:
void InizioProduzione(){
 pthread_mutex_lock(&mutex);
 while (ok_produzione==0)
  pthread_cond_wait(&ok_prod_cv,&mutex);
}


FineProduzione

decompiled_code:
int FineProduzione()
{
ok_consumo = 1;
ok_produzione = 0;
pthread_cond_signal(&ok_cons_cv);
return pthread_mutex_unlock(&mutex);
}

canonical_decompiled_code:
int func3()
{
ok_consumo = 1;
ok_produzione = 0;
pthread_cond_signal(&ok_cons_cv);
return pthread_mutex_unlock(&mutex);
}

original_code:
void FineProduzione (){
 ok_consumo = 1;
 ok_produzione = 0;
 pthread_cond_signal(&ok_cons_cv);
 pthread_mutex_unlock(&mutex);
}

canonical_original_code:
void FineProduzione(){
 ok_consumo = 1;
 ok_produzione = 0;
 pthread_cond_signal(&ok_cons_cv);
 pthread_mutex_unlock(&mutex);
}


Produttore

decompiled_code:
void __fastcall __noreturn Produttore(unsigned int a1)
{
struct timezone tz; // [rsp+8h] [rbp-20h] BYREF
struct timeval tv; // [rsp+10h] [rbp-18h] BYREF

InizioProduzione();
gettimeofday(&tv, &tz);
mess = tv.tv_usec;
printf("Thread#%d Valore PRODOTTO = <%d> \n", a1, tv.tv_usec);
FineProduzione();
pthread_exit(0LL);
}

canonical_decompiled_code:
void __fastcall __noreturn func4(unsigned int a1)
{
struct timezone tz; // [rsp+8h] [rbp-20h] BYREF
struct timeval tv; // [rsp+10h] [rbp-18h] BYREF

func2();
gettimeofday(&tv, &tz);
mess = tv.tv_usec;
printf("Thread#%d Valore PRODOTTO = <%d> \n", a1, tv.tv_usec);
func3();
pthread_exit(0LL);
}

original_code:
void *Produttore(void* id) {
  InizioProduzione();
                struct timeval t1;
                struct timezone t2;
                gettimeofday(&t1,&t2);
                msg val =t1.tv_usec;
         int my_id = (int) id;
                mess = val;
         printf("Thread#%d Valore PRODOTTO = <%d> \n", my_id, mess);
  FineProduzione();
  pthread_exit(((void *)0));
}

canonical_original_code:
void *Produttore(void *id) {
  InizioProduzione();
                struct timeval t1;
                struct timezone t2;
                gettimeofday(&t1,&t2);
                long val = t1.tv_usec;
         int my_id = (int) id;
                mess = val;
         printf("Thread#%d Valore PRODOTTO = <%d> \n", my_id, mess);
  FineProduzione();
  pthread_exit(((void *)0));
}

variable_types:
id
void *

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

variable_types: struct timezone { int tz_minuteswest; int tz_dsttime; }

variable_types: val long

return_type: void *


Consumatore

decompiled_code:
void __fastcall __noreturn Consumatore(unsigned int a1)
{
InizioConsumo();
printf("Thread #%d, valore CONSUMATO = <%d> \n", a1, mess);
FineConsumo();
pthread_exit(0LL);
}

canonical_decompiled_code:
void __fastcall __noreturn func5(unsigned int a1)
{
func0();
printf("Thread #%d, valore CONSUMATO = <%d> \n", a1, mess);
func1();
pthread_exit(0LL);
}

original_code:
void * Consumatore (void * id) {
  InizioConsumo();
  int my_id = (int) id;
         printf("Thread #%d, valore CONSUMATO = <%d> \n", my_id, mess);
  FineConsumo();
  pthread_exit(((void *)0));
}

canonical_original_code:
void *Consumatore(void *id) {
  InizioConsumo();
  int my_id = (int) id;
         printf("Thread #%d, valore CONSUMATO = <%d> \n", my_id, mess);
  FineConsumo();
  pthread_exit(((void *)0));
}


Prodotto

decompiled_code:
void __fastcall __noreturn Prodotto(void *a1)
{
__int64 v1; // [rsp+0h] [rbp-18h] BYREF
unsigned int v2; // [rsp+8h] [rbp-10h]

v1 = *(_QWORD *)a1;
v2 = *((_DWORD *)a1 + 3) * *((_DWORD *)a1 + 2);
pthread_mutex_lock(&mutex);
printf("\nSono Prodotto di Server. Invio del calcolo: %d\n\n", v2);
if ( msgsnd(id_s, &v1, 8uLL, 0) >= 0 )
{
pthread_mutex_unlock(&mutex);
free(a1);
pthread_exit(0LL);
}
perror("Errore invio risposta server");
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func7(void *a1)
{
__int64 v1; // [rsp+0h] [rbp-18h] BYREF
unsigned int v2; // [rsp+8h] [rbp-10h]

v1 = *(_QWORD *)a1;
v2 = *((_DWORD *)a1 + 3) * *((_DWORD *)a1 + 2);
pthread_mutex_lock(&mutex);
printf("\nSono Prodotto di Server. Invio del calcolo: %d\n\n", v2);
if ( msgsnd(id_s, &v1, 8uLL, 0) >= 0 )
{
pthread_mutex_unlock(&mutex);
free(a1);
pthread_exit(0LL);
}
perror("Errore invio risposta server");
exit(1);
}

original_code:
void* Prodotto(void* v){
 int ret;
 Buffer_C* BC=(Buffer_C*) v;
 Buffer_S BS;
 BS.pid=BC->pid;
 BS.v3=BC->v1*BC->v2;
 pthread_mutex_lock(&mutex);
  printf("\nSono Prodotto di Server. Invio del calcolo: %d\n\n",BS.v3);
  ret = msgsnd(id_s, &BS, sizeof(Buffer_S)-sizeof(long), 0);
  if(ret < 0) {
   perror("Errore invio risposta server");
   exit(1);
  }
 pthread_mutex_unlock(&mutex);
 free(BC);
 pthread_exit(((void *)0));
}

canonical_original_code:
void *Prodotto(void *v){
 int ret;
 struct Buffer_C *BC = (Buffer_C*) v;
 struct Buffer_S BS;
 BS.pid=BC->pid;
 BS.v3=BC->v1*BC->v2;
 pthread_mutex_lock(&mutex);
  printf("\nSono Prodotto di Server. Invio del calcolo: %d\n\n",BS.v3);
  ret = msgsnd(id_s, &BS, sizeof(Buffer_S)-sizeof(long), 0);
  if(ret < 0) {
   perror("Errore invio risposta server");
   exit(1);
  }
 pthread_mutex_unlock(&mutex);
 free(BC);
 pthread_exit(((void *)0));
}

variable_types:
v
void *

variable_types: ret int

variable_types: struct Buffer_C { long pid; int v1; int v2; } *

variable_types:
BS
struct Buffer_S { long pid; int v3; }


client

decompiled_code:
int client()
{
unsigned int v0; // eax
unsigned int i; // ebx
unsigned int v2; // eax
int result; // eax
__int64 v4; // [rsp+0h] [rbp-28h] BYREF
unsigned int v5; // [rsp+8h] [rbp-20h]
unsigned int v6; // [rsp+Ch] [rbp-1Ch]
char msgp[8]; // [rsp+10h] [rbp-18h] BYREF
unsigned int v8; // [rsp+18h] [rbp-10h]

v0 = getpid();
srand(v0);
v4 = getpid();
v5 = rand() % 101;
v6 = rand() % 101;
for ( i = 0; i != 5; ++i )
{
printf("Richiesta %d Inviata (%d, %d) [PID=%ld]\n\n", i, v5, v6, v4);
if ( msgsnd(id_c, &v4, 8uLL, 0) < 0 )
{
perror("Errore invio richiesta client");
exit(1);
}
v2 = getpid();
if ( (int)msgrcv(id_s, msgp, 8uLL, v2, 0) < 0 )
{
perror("Errore ricezione risposta client");
exit(1);
}
result = printf("Risposta %d Ricevuta (%d) [PID=%ld]\n\n", i, v8, v4);
}
return result;
}

canonical_decompiled_code:
int func8()
{
unsigned int v0; // eax
unsigned int i; // ebx
unsigned int v2; // eax
int result; // eax
__int64 v4; // [rsp+0h] [rbp-28h] BYREF
unsigned int v5; // [rsp+8h] [rbp-20h]
unsigned int v6; // [rsp+Ch] [rbp-1Ch]
char msgp[8]; // [rsp+10h] [rbp-18h] BYREF
unsigned int v8; // [rsp+18h] [rbp-10h]

v0 = getpid();
srand(v0);
v4 = getpid();
v5 = rand() % 101;
v6 = rand() % 101;
for ( i = 0; i != 5; ++i )
{
printf("Richiesta %d Inviata (%d, %d) [PID=%ld]\n\n", i, v5, v6, v4);
if ( msgsnd(id_c, &v4, 8uLL, 0) < 0 )
{
perror("Errore invio richiesta client");
exit(1);
}
v2 = getpid();
if ( (int)msgrcv(id_s, msgp, 8uLL, v2, 0) < 0 )
{
perror("Errore ricezione risposta client");
exit(1);
}
result = printf("Risposta %d Ricevuta (%d) [PID=%ld]\n\n", i, v8, v4);
}
return result;
}

original_code:
void client(){
 int k;
 int ret;
 srand(getpid());
 Buffer_S BS;
 Buffer_C BC;
 BC.pid=getpid();
 BC.v1=rand()%101;
 BC.v2=rand()%101;
 for(k=0;k<5;k++){
  printf("Richiesta %d Inviata (%d, %d) [PID=%ld]\n\n", k, BC.v1, BC.v2, BC.pid);
  ret = msgsnd(id_c, &BC, sizeof(Buffer_C)-sizeof(long), 0);
  if(ret < 0) {
   perror("Errore invio richiesta client");
   exit(1);
  }
  ret = msgrcv(id_s, &BS, sizeof(Buffer_S)-sizeof(long), getpid(), 0);
  if(ret < 0) {
   perror("Errore ricezione risposta client");
   exit(1);
  }
  printf("Risposta %d Ricevuta (%d) [PID=%ld]\n\n", k, BS.v3, BC.pid);
 }
}

canonical_original_code:
void client(){
 int k;
 int ret;
 srand(getpid());
 struct Buffer_S BS;
 struct Buffer_C BC;
 BC.pid=getpid();
 BC.v1=rand()%101;
 BC.v2=rand()%101;
 for(k=0;k<5;k++){
  printf("Richiesta %d Inviata (%d, %d) [PID=%ld]\n\n", k, BC.v1, BC.v2, BC.pid);
  ret = msgsnd(id_c, &BC, sizeof(Buffer_C)-sizeof(long), 0);
  if(ret < 0) {
   perror("Errore invio richiesta client");
   exit(1);
  }
  ret = msgrcv(id_s, &BS, sizeof(Buffer_S)-sizeof(long), getpid(), 0);
  if(ret < 0) {
   perror("Errore ricezione risposta client");
   exit(1);
  }
  printf("Risposta %d Ricevuta (%d) [PID=%ld]\n\n", k, BS.v3, BC.pid);
 }
}

variable_types: struct Buffer_C { long pid; int v1; int v2; }


server

decompiled_code:
void __noreturn server()
{
_QWORD *v0; // rbx
pthread_t newthread; // [rsp+8h] [rbp-50h] BYREF
pthread_attr_t attr; // [rsp+10h] [rbp-48h] BYREF

pthread_attr_init(&attr);
pthread_mutex_init(&mutex, 0LL);
while ( 1 )
{
v0 = malloc(0x10uLL);
*((_DWORD *)v0 + 2) = 0;
*((_DWORD *)v0 + 3) = 0;
*v0 = 0LL;
if ( (int)msgrcv(id_c, v0, 8uLL, 0LL, 0) < 0 )
break;
if ( v0[1] == -1LL )
exit(0);
pthread_create(&newthread, &attr, (void *(*)(void *))Prodotto, v0);
}
perror("Errore ricezione richiesta server");
exit(1);
}

canonical_decompiled_code:
void __noreturn func9()
{
_QWORD *v0; // rbx
pthread_t newthread; // [rsp+8h] [rbp-50h] BYREF
pthread_attr_t attr; // [rsp+10h] [rbp-48h] BYREF

pthread_attr_init(&attr);
pthread_mutex_init(&mutex, 0LL);
while ( 1 )
{
v0 = malloc(0x10uLL);
*((_DWORD *)v0 + 2) = 0;
*((_DWORD *)v0 + 3) = 0;
*v0 = 0LL;
if ( (int)msgrcv(id_c, v0, 8uLL, 0LL, 0) < 0 )
break;
if ( v0[1] == -1LL )
exit(0);
pthread_create(&newthread, &attr, (void *(*)(void *))Prodotto, v0);
}
perror("Errore ricezione richiesta server");
exit(1);
}

original_code:
void server(){
 int k;
 int ret;
 pthread_attr_t attr;
 pthread_attr_init(&attr);
 pthread_mutex_init(&mutex,((void *)0));
 while(1){
  Buffer_C * BC = (Buffer_C*) malloc(sizeof(Buffer_C));
  BC->v1=0;
  BC->v2=0;
  BC->pid=0;
  ret = msgrcv(id_c, BC, sizeof(Buffer_C)-sizeof(long), 0, 0);
  if(ret < 0) {
   perror("Errore ricezione richiesta server");
   exit(1);
  }
  if(BC->v1==-1 && BC->v2==-1){
   exit(0);
  }
  pthread_t t;
  pthread_create(&t, &attr, Prodotto, (void*) BC);
 }
}

canonical_original_code:
void server(){
 int k;
 int ret;
 union pthread_attr_t attr;
 pthread_attr_init(&attr);
 pthread_mutex_init(&mutex,((void *)0));
 while(1){
  struct Buffer_C *BC = (Buffer_C*) malloc(sizeof(Buffer_C));
  BC->v1=0;
  BC->v2=0;
  BC->pid=0;
  ret = msgrcv(id_c, BC, sizeof(Buffer_C)-sizeof(long), 0, 0);
  if(ret < 0) {
   perror("Errore ricezione richiesta server");
   exit(1);
  }
  if(BC->v1==-1 && BC->v2==-1){
   exit(0);
  }
  unsigned long t;
  pthread_create(&t, &attr, Prodotto, (void *) BC);
 }
}

variable_types: union pthread_attr_t { char __size[56]; long __align; }

variable_types:
t
unsigned long

user_defined_types: struct Buffer_C { long pid; int v1; int v2; }


prenota

decompiled_code:
__int64 __fastcall prenota(unsigned int a1, __int64 a2)
{
accedi_prenotati();
++*(_DWORD *)(a2 + 20);
return lascia_prenotati(a1);
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int a1, __int64 a2)
{
func16();
++*(_DWORD *)(a2 + 20);
return func17(a1);
}

original_code:
void prenota(int semid,esame_t* esame){
 accedi_prenotati(semid);
 esame->numero_prenotati += 1;
 lascia_prenotati(semid);
}

canonical_original_code:
void prenota(int semid, struct tipo_esame *esame){
 accedi_prenotati(semid);
 esame->numero_prenotati += 1;
 lascia_prenotati(semid);
}

variable_types: semid int

variable_types: struct tipo_esame { char prossimo_appello[20]; int numero_prenotati; int numero_lettori; } *


decompiled_code:
__int64 __fastcall stampa_appello(unsigned int a1, const char *a2)
{
unsigned int v2; // eax

inizio_lettura();
v2 = getpid();
printf("Processo studente %d - Data di appello: %s\n", v2, a2);
return fine_lettura(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int a1, const char *a2)
{
unsigned int v2; // eax

func12();
v2 = getpid();
printf("Processo studente %d - Data di appello: %s\n", v2, a2);
return func13(a1, a2);
}

original_code:
void stampa_appello(int semid,esame_t* esame){
 inizio_lettura(semid,esame);
 printf("Processo studente %d - Data di appello: %s\n",getpid(),esame->prossimo_appello);
 fine_lettura(semid,esame);
}

canonical_original_code:
void stampa_appello(int semid, struct tipo_esame *esame){
 inizio_lettura(semid,esame);
 printf("Processo studente %d - Data di appello: %s\n",getpid(),esame->prossimo_appello);
 fine_lettura(semid,esame);
}

user_defined_types: struct tipo_esame { char prossimo_appello[20]; int numero_prenotati; int numero_lettori; }


decompiled_code:
int __fastcall wait_sem(int a1, unsigned __int16 a2)
{
struct sembuf sops; // [rsp+Ah] [rbp-Eh] BYREF

sops.sem_num = a2;
sops.sem_flg = 0;
sops.sem_op = -1;
return semop(a1, &sops, 1uLL);
}

canonical_decompiled_code:
int __fastcall func10(int a1, unsigned __int16 a2)
{
struct sembuf sops; // [rsp+Ah] [rbp-Eh] BYREF

sops.sem_num = a2;
sops.sem_flg = 0;
sops.sem_op = -1;
return semop(a1, &sops, 1uLL);
}

original_code:
void wait_sem(int idsem,int numsem){
 struct sembuf sem_buf;
 sem_buf.sem_num = numsem;
 sem_buf.sem_flg=0;
 sem_buf.sem_op=-1;
 semop(idsem,&sem_buf,1);
}

canonical_original_code:
void wait_sem(int idsem, int numsem){
 struct sembuf sem_buf;
 sem_buf.sem_num = numsem;
 sem_buf.sem_flg=0;
 sem_buf.sem_op=-1;
 semop(idsem,&sem_buf,1);
}

variable_types: idsem int

variable_types: numsem int

variable_types: struct sembuf { unsigned short sem_num; short sem_op; short sem_flg; }


decompiled_code:
int __fastcall signal_sem(int a1, unsigned __int16 a2)
{
struct sembuf sops; // [rsp+Ah] [rbp-Eh] BYREF

sops.sem_num = a2;
sops.sem_flg = 0;
sops.sem_op = 1;
return semop(a1, &sops, 1uLL);
}

canonical_decompiled_code:
int __fastcall func11(int a1, unsigned __int16 a2)
{
struct sembuf sops; // [rsp+Ah] [rbp-Eh] BYREF

sops.sem_num = a2;
sops.sem_flg = 0;
sops.sem_op = 1;
return semop(a1, &sops, 1uLL);
}

original_code:
void signal_sem(int idsem,int numsem){
 struct sembuf sem_buf;
 sem_buf.sem_num = numsem;
 sem_buf.sem_flg=0;
 sem_buf.sem_op=1;
 semop(idsem,&sem_buf,1);
}

canonical_original_code:
void signal_sem(int idsem, int numsem){
 struct sembuf sem_buf;
 sem_buf.sem_num = numsem;
 sem_buf.sem_flg=0;
 sem_buf.sem_op=1;
 semop(idsem,&sem_buf,1);
}

user_defined_types: struct sembuf { unsigned short sem_num; short sem_op; short sem_flg; }


decompiled_code:
int __fastcall inizio_lettura(int a1, __int64 a2)
{
__int64 v3; // rsi

wait_sem(a1, 0);
v3 = (unsigned int)(*(_DWORD *)(a2 + 24) + 1);
*(_DWORD *)(a2 + 24) = v3;
printf("DEBUG: Numero lettori %d\n", v3);
if ( *(_DWORD *)(a2 + 24) == 1 )
wait_sem(a1, 1u);
return signal_sem(a1, 0);
}

canonical_decompiled_code:
int __fastcall func12(int a1, __int64 a2)
{
__int64 v3; // rsi

func10(a1, 0);
v3 = (unsigned int)(*(_DWORD *)(a2 + 24) + 1);
*(_DWORD *)(a2 + 24) = v3;
printf("DEBUG: Numero lettori %d\n", v3);
if ( *(_DWORD *)(a2 + 24) == 1 )
func10(a1, 1u);
return func11(a1, 0);
}

original_code:
void inizio_lettura(int sem,esame_t* esame){
 wait_sem(sem,0);
 esame->numero_lettori = esame->numero_lettori+1;
 printf("DEBUG: Numero lettori %d\n",esame->numero_lettori);
 if(esame->numero_lettori == 1)
  wait_sem(sem,1);
 signal_sem(sem,0);
}

canonical_original_code:
void inizio_lettura(int sem, struct tipo_esame *esame){
 wait_sem(sem,0);
 esame->numero_lettori = esame->numero_lettori+1;
 printf("DEBUG: Numero lettori %d\n",esame->numero_lettori);
 if(esame->numero_lettori == 1)
  wait_sem(sem,1);
 signal_sem(sem,0);
}

variable_types: sem int


decompiled_code:
int __fastcall fine_lettura(int a1, __int64 a2)
{
__int64 v3; // rsi

wait_sem(a1, 0);
v3 = (unsigned int)(*(_DWORD *)(a2 + 24) - 1);
*(_DWORD *)(a2 + 24) = v3;
printf("DEBUG: Numero lettori %d\n", v3);
if ( !*(_DWORD *)(a2 + 24) )
signal_sem(a1, 1u);
return signal_sem(a1, 0);
}

canonical_decompiled_code:
int __fastcall func13(int a1, __int64 a2)
{
__int64 v3; // rsi

func10(a1, 0);
v3 = (unsigned int)(*(_DWORD *)(a2 + 24) - 1);
*(_DWORD *)(a2 + 24) = v3;
printf("DEBUG: Numero lettori %d\n", v3);
if ( !*(_DWORD *)(a2 + 24) )
func11(a1, 1u);
return func11(a1, 0);
}

original_code:
void fine_lettura(int sem,esame_t* esame){
 wait_sem(sem,0);
 esame->numero_lettori = esame->numero_lettori - 1;
 printf("DEBUG: Numero lettori %d\n",esame->numero_lettori);
 if(esame->numero_lettori == 0)
  signal_sem(sem,1);
 signal_sem(sem,0);
}

canonical_original_code:
void fine_lettura(int sem, struct tipo_esame *esame){
 wait_sem(sem,0);
 esame->numero_lettori = esame->numero_lettori - 1;
 printf("DEBUG: Numero lettori %d\n",esame->numero_lettori);
 if(esame->numero_lettori == 0)
  signal_sem(sem,1);
 signal_sem(sem,0);
}


decompiled_code:
int __fastcall inizio_scrittura(int a1)
{
wait_sem(a1, 1u);
return puts("DEBUG: Inizio scrittura");
}

canonical_decompiled_code:
int __fastcall func14(int a1)
{
func10(a1, 1u);
return puts("DEBUG: Inizio scrittura");
}

original_code:
void inizio_scrittura(int sem){
 wait_sem(sem,1);
 printf("DEBUG: Inizio scrittura\n");
}


decompiled_code:
int __fastcall fine_scrittura(int a1)
{
signal_sem(a1, 1u);
return puts("DEBUG: Fine scrittura");
}

canonical_decompiled_code:
int __fastcall func15(int a1)
{
func11(a1, 1u);
return puts("DEBUG: Fine scrittura");
}

original_code:
void fine_scrittura(int sem){
 signal_sem(sem,1);
 printf("DEBUG: Fine scrittura\n");
}


decompiled_code:
int __fastcall accedi_prenotati(int a1)
{
wait_sem(a1, 2u);
return puts("DEBUG: Inizio scrittura prenotati");
}

canonical_decompiled_code:
int __fastcall func16(int a1)
{
func10(a1, 2u);
return puts("DEBUG: Inizio scrittura prenotati");
}

original_code:
void accedi_prenotati(int sem){
 wait_sem(sem,2);
 printf("DEBUG: Inizio scrittura prenotati\n");
}


decompiled_code:
int __fastcall lascia_prenotati(int a1)
{
signal_sem(a1, 2u);
return puts("DEBUG: Fine scrittura prenotati");
}

canonical_decompiled_code:
int __fastcall func17(int a1)
{
func11(a1, 2u);
return puts("DEBUG: Fine scrittura prenotati");
}

original_code:
void lascia_prenotati(int sem){
 signal_sem(sem,2);
 printf("DEBUG: Fine scrittura prenotati\n");
}


esegui

decompiled_code:
__int64 __fastcall esegui(unsigned int a1, const char *a2)
{
__int64 v2; // rbx

v2 = (unsigned int)(rand() % 8 + 1);
printf("Sono studente e aspetto tempo %d secondi\n", v2);
sleep(v2);
stampa_appello(a1, a2);
return prenota(a1, (__int64)a2);
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned int a1, const char *a2)
{
__int64 v2; // rbx

v2 = (unsigned int)(rand() % 8 + 1);
printf("Sono studente e aspetto tempo %d secondi\n", v2);
sleep(v2);
func8(a1, a2);
return func7(a1, (__int64)a2);
}

original_code:
void esegui(int semid,esame_t* esame){
 int i;
 int t;
 t = 1 + (rand() % 8);
 printf("Sono studente e aspetto tempo %d secondi\n",t);
 sleep(t);
 stampa_appello(semid,esame);
 prenota(semid,esame);
}

canonical_original_code:
void esegui(int semid, struct tipo_esame *esame){
 int i;
 int t;
 t = 1 + (rand() % 8);
 printf("Sono studente e aspetto tempo %d secondi\n",t);
 sleep(t);
 stampa_appello(semid,esame);
 prenota(semid,esame);
}

variable_types: i int

variable_types: t int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
key_t v3; // ebp
key_t v4; // ebx
unsigned int v5; // ebp
const char *v6; // r12
__int64 v7; // rbx
struct timeval v9; // [rsp+0h] [rbp-28h] BYREF

v3 = ftok(".", 83);
v4 = ftok(".", 80);
gettimeofday(&v9, 0LL);
srand(LODWORD(v9.tv_usec) * LODWORD(v9.tv_sec));
v5 = shmget(v3, 0x1CuLL, 948);
v6 = (const char *)shmat(v5, 0LL, 0);
v7 = (unsigned int)semget(v4, 0, 0);
printf("Debug [PS] - idshm %d idsem %d\n", v5, v7);
esegui(v7, v6);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
key_t v3; // ebp
key_t v4; // ebx
unsigned int v5; // ebp
const char *v6; // r12
__int64 v7; // rbx
struct timeval v9; // [rsp+0h] [rbp-28h] BYREF

v3 = ftok(".", 83);
v4 = ftok(".", 80);
gettimeofday(&v9, 0LL);
srand(LODWORD(v9.tv_usec) * LODWORD(v9.tv_sec));
v5 = shmget(v3, 0x1CuLL, 948);
v6 = (const char *)shmat(v5, 0LL, 0);
v7 = (unsigned int)semget(v4, 0, 0);
printf("Debug [PS] - idshm %d idsem %d\n", v5, v7);
func9(v7, v6);
return 0;
}

original_code:
int main(int argc,char* argv[]){
 key_t key_shm,key_sem;
 int shmid,semid;
 key_shm = ftok(".",'S');
 key_sem = ftok(".",'P');
 esame_t* esame = ((void *)0);
 struct timeval t1;
 gettimeofday(&t1, ((void *)0));
 srand(t1.tv_usec * t1.tv_sec);
 shmid = shmget(key_shm,sizeof(esame_t),01000|0664);
 esame = (esame_t*) shmat(shmid,0,0);
 semid = semget(key_sem,0,0);
 printf("Debug [PS] - idshm %d idsem %d\n",shmid,semid);
 esegui(semid,esame);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[]){
 int key_shm; int key_sem;
 int shmid; int semid;
 key_shm = ftok(".",'S');
 key_sem = ftok(".",'P');
 struct tipo_esame *esame = ((void *)0);
 struct timeval t1;
 gettimeofday(&t1, ((void *)0));
 srand(t1.tv_usec * t1.tv_sec);
 shmid = shmget(key_shm,sizeof(esame_t),01000|0664);
 esame = (struct tipo_esame *) shmat(shmid,0,0);
 semid = semget(key_sem,0,0);
 printf("Debug [PS] - idshm %d idsem %d\n",shmid,semid);
 esegui(semid,esame);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: shmid int

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

return_type: int


decompiled_code:
__int64 __fastcall azzera_prenotati(unsigned int a1, __int64 a2)
{
inizio_lettura();
accedi_prenotati(a1);
putchar(10);
puts("-------Stampa stato esame------");
printf("Data di esame: %s\n", (const char *)a2);
printf("Numero prenotati: %d\n", *(unsigned int *)(a2 + 20));
puts("-------------------------------");
putchar(10);
*(_DWORD *)(a2 + 20) = 0;
lascia_prenotati(a1);
return fine_lettura(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int a1, __int64 a2)
{
func12();
func16(a1);
putchar(10);
puts("-------Stampa stato esame------");
printf("Data di esame: %s\n", (const char *)a2);
printf("Numero prenotati: %d\n", *(unsigned int *)(a2 + 20));
puts("-------------------------------");
putchar(10);
*(_DWORD *)(a2 + 20) = 0;
func17(a1);
return func13(a1, a2);
}

original_code:
void azzera_prenotati(int semid,esame_t* esame){
 inizio_lettura(semid,esame);
 accedi_prenotati(semid);
 printf("\n");
 printf("-------Stampa stato esame------\n");
 printf("Data di esame: %s\n",esame->prossimo_appello);
 printf("Numero prenotati: %d\n",esame->numero_prenotati);
 printf("-------------------------------\n");
 printf("\n");
 esame->numero_prenotati = 0;
 lascia_prenotati(semid);
 fine_lettura(semid,esame);
}

canonical_original_code:
void azzera_prenotati(int semid, struct tipo_esame *esame){
 inizio_lettura(semid,esame);
 accedi_prenotati(semid);
 printf("\n");
 printf("-------Stampa stato esame------\n");
 printf("Data di esame: %s\n",esame->prossimo_appello);
 printf("Numero prenotati: %d\n",esame->numero_prenotati);
 printf("-------------------------------\n");
 printf("\n");
 esame->numero_prenotati = 0;
 lascia_prenotati(semid);
 fine_lettura(semid,esame);
}


decompiled_code:
__int64 __fastcall aggiorna_data(unsigned int a1, char *a2, const char *a3)
{
printf("DEBUG: Aggiorna data %s\n", a3);
inizio_scrittura(a1);
strcpy(a2, a3);
printf("DEBUG: Prossimo appello %s\n", a2);
return fine_scrittura(a1);
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int a1, char *a2, const char *a3)
{
printf("DEBUG: Aggiorna data %s\n", a3);
func14(a1);
strcpy(a2, a3);
printf("DEBUG: Prossimo appello %s\n", a2);
return func15(a1);
}

original_code:
void aggiorna_data(int semid,esame_t* esame,char* data){
 printf("DEBUG: Aggiorna data %s\n",data);
 inizio_scrittura(semid);
 strcpy(&esame->prossimo_appello,data);
 printf("DEBUG: Prossimo appello %s\n",esame->prossimo_appello);
 fine_scrittura(semid);
}

canonical_original_code:
void aggiorna_data(int semid, struct tipo_esame *esame, char *data){
 printf("DEBUG: Aggiorna data %s\n",data);
 inizio_scrittura(semid);
 strcpy(&esame->prossimo_appello,data);
 printf("DEBUG: Prossimo appello %s\n",esame->prossimo_appello);
 fine_scrittura(semid);
}

variable_types:
data
char *


canonical_original_code:
void inizio_scrittura(int sem){
 wait_sem(sem,1);
 printf("DEBUG: Inizio scrittura\n");
}


canonical_original_code:
void fine_scrittura(int sem){
 signal_sem(sem,1);
 printf("DEBUG: Fine scrittura\n");
}


canonical_original_code:
void accedi_prenotati(int sem){
 wait_sem(sem,2);
 printf("DEBUG: Inizio scrittura prenotati\n");
}


canonical_original_code:
void lascia_prenotati(int sem){
 signal_sem(sem,2);
 printf("DEBUG: Fine scrittura prenotati\n");
}


esegui

decompiled_code:
__int64 __fastcall esegui(unsigned int a1, char *a2)
{
int i; // ebx
__int64 result; // rax

puts("Docente in esecuzione");
for ( i = 1; ; ++i )
{
if ( i == 2 )
{
aggiorna_data(a1, a2, "05/03/2013");
sleep(3u);
azzera_prenotati(a1, (__int64)a2);
continue;
}
if ( i == 3 )
break;
if ( i == 1 )
{
aggiorna_data(a1, a2, "14/02/2013");
sleep(3u);
azzera_prenotati(a1, (__int64)a2);
}
else
{
aggiorna_data(a1, a2, "default");
sleep(3u);
result = azzera_prenotati(a1, (__int64)a2);
if ( i > 2 )
return result;
}
}
aggiorna_data(a1, a2, "02/04/2013");
sleep(3u);
return azzera_prenotati(a1, (__int64)a2);
}

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

puts("Docente in esecuzione");
for ( i = 1; ; ++i )
{
if ( i == 2 )
{
func8(a1, a2, "05/03/2013");
sleep(3u);
func7(a1, (__int64)a2);
continue;
}
if ( i == 3 )
break;
if ( i == 1 )
{
func8(a1, a2, "14/02/2013");
sleep(3u);
func7(a1, (__int64)a2);
}
else
{
func8(a1, a2, "default");
sleep(3u);
result = func7(a1, (__int64)a2);
if ( i > 2 )
return result;
}
}
func8(a1, a2, "02/04/2013");
sleep(3u);
return func7(a1, (__int64)a2);
}

original_code:
void esegui(int semid,esame_t* esame){
 printf("Docente in esecuzione\n");
 int i;
 char* data;
 for(i=0; i < 3;i++){
  switch(i){
   case 0:
   data = "14/02/2013";
   break;
   case 1:
   data = "05/03/2013";
   break;
   case 2:
   data = "02/04/2013";
   break;
   default:
   data = "default";
   break;
  }
   aggiorna_data(semid,esame,data);
  sleep(3);
  azzera_prenotati(semid,esame);
 }
}

canonical_original_code:
void esegui(int semid, struct tipo_esame *esame){
 printf("Docente in esecuzione\n");
 int i;
 char *data;
 for(i=0; i < 3;i++){
  switch(i){
   case 0:
   data = "14/02/2013";
   break;
   case 1:
   data = "05/03/2013";
   break;
   case 2:
   data = "02/04/2013";
   break;
   default:
   data = "default";
   break;
  }
   aggiorna_data(semid,esame,data);
  sleep(3);
  azzera_prenotati(semid,esame);
 }
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
key_t v3; // ebp
key_t v4; // ebx
unsigned int v5; // ebp
char *v6; // r12
__int64 v7; // rbx

v3 = ftok(".", 83);
v4 = ftok(".", 80);
v5 = shmget(v3, 0LL, 0);
v6 = (char *)shmat(v5, 0LL, 0);
v7 = (unsigned int)semget(v4, 0, 0);
printf("Debug [PD] : idshm %d idsem %d\n", v5, v7);
esegui(v7, v6);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
key_t v3; // ebp
key_t v4; // ebx
unsigned int v5; // ebp
char *v6; // r12
__int64 v7; // rbx

v3 = ftok(".", 83);
v4 = ftok(".", 80);
v5 = shmget(v3, 0LL, 0);
v6 = (char *)shmat(v5, 0LL, 0);
v7 = (unsigned int)semget(v4, 0, 0);
printf("Debug [PD] : idshm %d idsem %d\n", v5, v7);
func9(v7, v6);
return 0;
}

original_code:
int main(int argc,char* argv[]){
 key_t key_shm,key_sem;
 int shmid,semid;
 key_shm = ftok(".",'S');
 key_sem = ftok(".",'P');
 esame_t* esame = ((void *)0);
 shmid = shmget(key_shm,0,0);
 esame = (esame_t*) (shmat(shmid,0,0));
 semid = semget(key_sem,0,0);
 printf("Debug [PD] : idshm %d idsem %d\n",shmid,semid);
 esegui(semid,esame);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[]){
 int key_shm; int key_sem;
 int shmid; int semid;
 key_shm = ftok(".",'S');
 key_sem = ftok(".",'P');
 struct tipo_esame *esame = ((void *)0);
 shmid = shmget(key_shm,0,0);
 esame = (struct tipo_esame *) (shmat(shmid,0,0));
 semid = semget(key_sem,0,0);
 printf("Debug [PD] : idshm %d idsem %d\n",shmid,semid);
 esegui(semid,esame);
 return 0;
}


StackInit

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

pthread_mutex_init((pthread_mutex_t *)(a1 + 16), 0LL);
pthread_cond_init((pthread_cond_t *)(a1 + 56), 0LL);
pthread_cond_init((pthread_cond_t *)(a1 + 104), 0LL);
result = malloc(4LL * a2);
*(_QWORD *)a1 = result;
*(_DWORD *)(a1 + 8) = a2;
*(_DWORD *)(a1 + 12) = 0;
return result;
}

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

pthread_mutex_init((pthread_mutex_t *)(a1 + 16), 0LL);
pthread_cond_init((pthread_cond_t *)(a1 + 56), 0LL);
pthread_cond_init((pthread_cond_t *)(a1 + 104), 0LL);
result = malloc(4LL * a2);
*(_QWORD *)a1 = result;
*(_DWORD *)(a1 + 8) = a2;
*(_DWORD *)(a1 + 12) = 0;
return result;
}

original_code:
void StackInit(Stack * s, int dim) {
 pthread_mutex_init( &(s->m), ((void *)0) );
 pthread_cond_init( &(s->ok_push), ((void *)0) );
 pthread_cond_init( &(s->ok_pop), ((void *)0) );
 s->dati = (Elem *) malloc(sizeof(Elem)*dim);
 s->dim = dim;
 s->testa = 0;
}

canonical_original_code:
void StackInit(struct Stack *s, int dim) {
 pthread_mutex_init( &(s->m), ((void *)0) );
 pthread_cond_init( &(s->ok_push), ((void *)0) );
 pthread_cond_init( &(s->ok_pop), ((void *)0) );
 s->dati = (int *) malloc(sizeof(Elem)*dim);
 s->dim = dim;
 s->testa = 0;
}

variable_types: struct Stack { int *dati; int dim; int testa; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } m; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } ok_push; union pthread_cond_t ok_pop; } *

variable_types: dim int

user_defined_types: struct Stack { int *dati; int dim; int testa; union pthread_mutex_t m; union pthread_cond_t ok_push; union pthread_cond_t ok_pop; }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: union pthread_cond_t { struct __pthread_cond_s __data; char __size[48]; long long __align; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }


StackRemove

decompiled_code:
void __fastcall StackRemove(__int64 a1)
{
pthread_mutex_destroy((pthread_mutex_t *)(a1 + 16));
pthread_cond_destroy((pthread_cond_t *)(a1 + 56));
pthread_cond_destroy((pthread_cond_t *)(a1 + 104));
free(*(void **)a1);
}

canonical_decompiled_code:
void __fastcall func8(__int64 a1)
{
pthread_mutex_destroy((pthread_mutex_t *)(a1 + 16));
pthread_cond_destroy((pthread_cond_t *)(a1 + 56));
pthread_cond_destroy((pthread_cond_t *)(a1 + 104));
free(*(void **)a1);
}

original_code:
void StackRemove(Stack * s) {
 pthread_mutex_destroy( &(s->m) );
 pthread_cond_destroy( &(s->ok_push) );
 pthread_cond_destroy( &(s->ok_pop) );
 free(s->dati);
}

canonical_original_code:
void StackRemove(struct Stack *s) {
 pthread_mutex_destroy( &(s->m) );
 pthread_cond_destroy( &(s->ok_push) );
 pthread_cond_destroy( &(s->ok_pop) );
 free(s->dati);
}

user_defined_types: struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; }

user_defined_types: struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; }


StackPush

decompiled_code:
int __fastcall StackPush(__int64 a1, int a2)
{
pthread_mutex_t *v2; // rbp
int i; // eax

v2 = (pthread_mutex_t *)(a1 + 16);
pthread_mutex_lock((pthread_mutex_t *)(a1 + 16));
for ( i = *(_DWORD *)(a1 + 12); *(_DWORD *)(a1 + 8) == i; i = *(_DWORD *)(a1 + 12) )
pthread_cond_wait((pthread_cond_t *)(a1 + 56), v2);
*(_DWORD *)(*(_QWORD *)a1 + 4LL * i) = a2;
++*(_DWORD *)(a1 + 12);
pthread_cond_signal((pthread_cond_t *)(a1 + 104));
return pthread_mutex_unlock(v2);
}

canonical_decompiled_code:
int __fastcall func9(__int64 a1, int a2)
{
pthread_mutex_t *v2; // rbp
int i; // eax

v2 = (pthread_mutex_t *)(a1 + 16);
pthread_mutex_lock((pthread_mutex_t *)(a1 + 16));
for ( i = *(_DWORD *)(a1 + 12); *(_DWORD *)(a1 + 8) == i; i = *(_DWORD *)(a1 + 12) )
pthread_cond_wait((pthread_cond_t *)(a1 + 56), v2);
*(_DWORD *)(*(_QWORD *)a1 + 4LL * i) = a2;
++*(_DWORD *)(a1 + 12);
pthread_cond_signal((pthread_cond_t *)(a1 + 104));
return pthread_mutex_unlock(v2);
}

original_code:
void StackPush(Stack * s, Elem e) {
 pthread_mutex_lock( &(s->m) );
 while( s->dim==s->testa )
  pthread_cond_wait( &(s->ok_push), &(s->m) );
 s->dati[s->testa] = e;
 s->testa++;
 pthread_cond_signal( &(s->ok_pop) );
 pthread_mutex_unlock( &(s->m) );
}

canonical_original_code:
void StackPush(struct Stack *s, int e) {
 pthread_mutex_lock( &(s->m) );
 while( s->dim==s->testa )
  pthread_cond_wait( &(s->ok_push), &(s->m) );
 s->dati[s->testa] = e;
 s->testa++;
 pthread_cond_signal( &(s->ok_pop) );
 pthread_mutex_unlock( &(s->m) );
}

variable_types: e int


StackPop

decompiled_code:
__int64 __fastcall StackPop(__int64 a1)
{
pthread_mutex_t *v1; // rbp
int i; // eax
int v3; // eax
unsigned int v4; // er12

v1 = (pthread_mutex_t *)(a1 + 16);
pthread_mutex_lock((pthread_mutex_t *)(a1 + 16));
for ( i = *(_DWORD *)(a1 + 12); !i; i = *(_DWORD *)(a1 + 12) )
pthread_cond_wait((pthread_cond_t *)(a1 + 104), v1);
v3 = i - 1;
*(_DWORD *)(a1 + 12) = v3;
v4 = *(_DWORD *)(*(_QWORD *)a1 + 4LL * v3);
pthread_cond_signal((pthread_cond_t *)(a1 + 56));
pthread_mutex_unlock(v1);
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
pthread_mutex_t *v1; // rbp
int i; // eax
int v3; // eax
unsigned int v4; // er12

v1 = (pthread_mutex_t *)(a1 + 16);
pthread_mutex_lock((pthread_mutex_t *)(a1 + 16));
for ( i = *(_DWORD *)(a1 + 12); !i; i = *(_DWORD *)(a1 + 12) )
pthread_cond_wait((pthread_cond_t *)(a1 + 104), v1);
v3 = i - 1;
*(_DWORD *)(a1 + 12) = v3;
v4 = *(_DWORD *)(*(_QWORD *)a1 + 4LL * v3);
pthread_cond_signal((pthread_cond_t *)(a1 + 56));
pthread_mutex_unlock(v1);
return v4;
}

original_code:
Elem StackPop(Stack * s) {
 int elemento;
 pthread_mutex_lock( &(s->m) );
 while( s->testa==0 )
  pthread_cond_wait( &(s->ok_pop), &(s->m) );
 s->testa--;
 elemento=s->dati[s->testa];
 pthread_cond_signal( &(s->ok_push) );
 pthread_mutex_unlock( &(s->m) );
 return elemento;
}

canonical_original_code:
int StackPop(struct Stack *s) {
 int elemento;
 pthread_mutex_lock( &(s->m) );
 while( s->testa==0 )
  pthread_cond_wait( &(s->ok_pop), &(s->m) );
 s->testa--;
 elemento=s->dati[s->testa];
 pthread_cond_signal( &(s->ok_push) );
 pthread_mutex_unlock( &(s->m) );
 return elemento;
}

variable_types: elemento int


StackSize

decompiled_code:
__int64 __fastcall StackSize(__int64 a1)
{
unsigned int v1; // ebx

pthread_mutex_lock((pthread_mutex_t *)(a1 + 16));
v1 = *(_DWORD *)(a1 + 12);
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 16));
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
unsigned int v1; // ebx

pthread_mutex_lock((pthread_mutex_t *)(a1 + 16));
v1 = *(_DWORD *)(a1 + 12);
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 16));
return v1;
}

original_code:
int StackSize(Stack * s) {
 int size;
 pthread_mutex_lock( &(s->m) );
 size = s->testa;
 pthread_mutex_unlock( &(s->m) );
 return size;
}

canonical_original_code:
int StackSize(struct Stack *s) {
 int size;
 pthread_mutex_lock( &(s->m) );
 size = s->testa;
 pthread_mutex_unlock( &(s->m) );
 return size;
}

variable_types: size int


Inserisci

decompiled_code:
void __fastcall __noreturn Inserisci(void *a1)
{
int v1; // ebp
unsigned int v2; // ebx

v1 = 4;
do
{
v2 = rand() % 11;
StackPush((__int64)a1, v2);
printf("Inserimento: %d\n", v2);
sleep(1u);
--v1;
}
while ( v1 );
pthread_exit(0LL);
}

canonical_decompiled_code:
void __fastcall __noreturn func12(void *a1)
{
int v1; // ebp
unsigned int v2; // ebx

v1 = 4;
do
{
v2 = rand() % 11;
func9((__int64)a1, v2);
printf("Inserimento: %d\n", v2);
sleep(1u);
--v1;
}
while ( v1 );
pthread_exit(0LL);
}

original_code:
void *Inserisci(void * s)
{
 int i;
 Elem v;
 for(i=0; i<4; i++) {
  v = rand() % 11;
  StackPush(s, v);
  printf("Inserimento: %d\n", v);
  sleep(1);
 }
 pthread_exit(((void *)0));
}

canonical_original_code:
void *Inserisci(void *s)
{
 int i;
 int v;
 for(i=0; i<4; i++) {
  v = rand() % 11;
  StackPush(s, v);
  printf("Inserimento: %d\n", v);
  sleep(1);
 }
 pthread_exit(((void *)0));
}

variable_types:
s
void *

variable_types: v int


Preleva

decompiled_code:
void __fastcall __noreturn Preleva(void *a1)
{
int v1; // er12
__int64 v2; // rbx
__int64 v3; // rbp

v1 = 10;
do
{
v2 = (unsigned int)StackPop((__int64)a1);
printf("Prelievo: %d\n", v2);
v3 = (unsigned int)StackPop((__int64)a1);
printf("Prelievo: %d\n", v3);
printf("Somma: %d\n", (unsigned int)(v2 + v3));
sleep(3u);
--v1;
}
while ( v1 );
pthread_exit(0LL);
}

canonical_decompiled_code:
void __fastcall __noreturn func13(void *a1)
{
int v1; // er12
__int64 v2; // rbx
__int64 v3; // rbp

v1 = 10;
do
{
v2 = (unsigned int)func10((__int64)a1);
printf("Prelievo: %d\n", v2);
v3 = (unsigned int)func10((__int64)a1);
printf("Prelievo: %d\n", v3);
printf("Somma: %d\n", (unsigned int)(v2 + v3));
sleep(3u);
--v1;
}
while ( v1 );
pthread_exit(0LL);
}

original_code:
void *Preleva(void * s)
{
 int i;
 Elem v1, v2;
 for(i=0; i<10; i++) {
  v1=StackPop(s);
  printf("Prelievo: %d\n", v1);
  v2=StackPop(s);
  printf("Prelievo: %d\n", v2);
  printf("Somma: %d\n", v1+v2);
  sleep(3);
 }
 pthread_exit(((void *)0));
}

canonical_original_code:
void *Preleva(void *s)
{
 int i;
 int v1; int v2;
 for(i=0; i<10; i++) {
  v1=StackPop(s);
  printf("Prelievo: %d\n", v1);
  v2=StackPop(s);
  printf("Prelievo: %d\n", v2);
  printf("Somma: %d\n", v1+v2);
  sleep(3);
 }
 pthread_exit(((void *)0));
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
void *v4; // r12
pthread_t *v5; // rbx
pthread_t *v6; // rbp
pthread_attr_t v8; // [rsp+0h] [rbp-98h] BYREF
pthread_t newthread[5]; // [rsp+40h] [rbp-58h] BYREF
pthread_t v10; // [rsp+68h] [rbp-30h] BYREF
__int64 v11; // [rsp+70h] [rbp-28h] BYREF

v3 = time(0LL);
srand(v3);
v4 = malloc(0x98uLL);
StackInit((__int64)v4, 4);
pthread_attr_init(&v8);
pthread_attr_setdetachstate(&v8, 0);
v5 = newthread;
v6 = newthread;
do
pthread_create(v6++, 0LL, (void *(*)(void *))Inserisci, v4);
while ( v6 != &v10 );
pthread_create(&v10, 0LL, (void *(*)(void *))Preleva, v4);
do
pthread_join(*v5++, 0LL);
while ( v5 != (pthread_t *)&v11 );
StackRemove((__int64)v4);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
void *v4; // r12
pthread_t *v5; // rbx
pthread_t *v6; // rbp
pthread_attr_t v8; // [rsp+0h] [rbp-98h] BYREF
pthread_t newthread[5]; // [rsp+40h] [rbp-58h] BYREF
pthread_t v10; // [rsp+68h] [rbp-30h] BYREF
__int64 v11; // [rsp+70h] [rbp-28h] BYREF

v3 = time(0LL);
srand(v3);
v4 = malloc(0x98uLL);
func7((__int64)v4, 4);
pthread_attr_init(&v8);
pthread_attr_setdetachstate(&v8, 0);
v5 = newthread;
v6 = newthread;
do
pthread_create(v6++, 0LL, (void *(*)(void *))Inserisci, v4);
while ( v6 != &v10 );
pthread_create(&v10, 0LL, (void *(*)(void *))Preleva, v4);
do
pthread_join(*v5++, 0LL);
while ( v5 != (pthread_t *)&v11 );
func8((__int64)v4);
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 pthread_t threads[6];
 pthread_attr_t attr;
 int rc;
 int i;
 srand(time(((void *)0)));
 Stack * stack = (Stack *)malloc(sizeof(Stack));
 StackInit(stack, 4);
 pthread_attr_init(&attr);
 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
 for(i=0; i<5; i++) {
  pthread_create(&threads[i], ((void *)0), Inserisci, (void *)stack);
 }
 pthread_create(&threads[5], ((void *)0), Preleva, (void *)stack);
 for(i=0; i<6; i++) {
  pthread_join(threads[i], ((void *)0));
 }
 StackRemove(stack);
}

canonical_original_code:
int main(int argc, char *argv[])
{
 unsigned long threads[6];
 union pthread_attr_t attr;
 int rc;
 int i;
 srand(time(((void *)0)));
 struct Stack *stack = (Stack *)malloc(sizeof(Stack));
 StackInit(stack, 4);
 pthread_attr_init(&attr);
 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
 for(i=0; i<5; i++) {
  pthread_create(&threads[i], ((void *)0), Inserisci, (void *)stack);
 }
 pthread_create(&threads[5], ((void *)0), Preleva, (void *)stack);
 for(i=0; i<6; i++) {
  pthread_join(threads[i], ((void *)0));
 }
 StackRemove(stack);
}

variable_types:
threads
unsigned long [6]

variable_types: union pthread_attr_t { char __size[56]; long __align; }

variable_types: rc int


decompiled_code:
__int64 __fastcall produci_alta_prio(__int64 a1)
{
__int64 v1; // rbp
unsigned int v2; // er12
int v3; // eax
unsigned int v4; // eax

v1 = a1 + 16;
enter_monitor(a1 + 16);
puts("Produttore 1 entrato nel monitor...");
while ( *(_DWORD *)(a1 + 48) == 3 )
wait_condition(v1, 0LL);
v2 = rand() % 12;
v3 = *(_DWORD *)(a1 + 40);
*(_DWORD *)(a1 + 4LL * v3) = v2;
*(_DWORD *)(a1 + 40) = (v3 + 1) % 3;
++*(_DWORD *)(a1 + 48);
v4 = getpid();
printf("Produttore 1 con pid %d ha prodotto %d\n", v4, v2);
signal_condition(v1, 2LL);
return leave_monitor(v1);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
__int64 v1; // rbp
unsigned int v2; // er12
int v3; // eax
unsigned int v4; // eax

v1 = a1 + 16;
func15(a1 + 16);
puts("Produttore 1 entrato nel monitor...");
while ( *(_DWORD *)(a1 + 48) == 3 )
func18(v1, 0LL);
v2 = rand() % 12;
v3 = *(_DWORD *)(a1 + 40);
*(_DWORD *)(a1 + 4LL * v3) = v2;
*(_DWORD *)(a1 + 40) = (v3 + 1) % 3;
++*(_DWORD *)(a1 + 48);
v4 = getpid();
printf("Produttore 1 con pid %d ha prodotto %d\n", v4, v2);
func19(v1, 2LL);
return func16(v1);
}

original_code:
void produci_alta_prio(PriorityProdCons* p){
 int value;
 enter_monitor(&p->m);
 printf("Produttore 1 entrato nel monitor...\n");
 while(p->count == 3) {
  wait_condition(&p->m,0);
 }
 value = rand() % 12 ;
 p->buffer[p->testa] = value;
 p->testa = ++(p->testa) % 3;
 p->count++;
 printf("Produttore 1 con pid %d ha prodotto %d\n",getpid(),value);
 signal_condition(&p->m,2);
 leave_monitor(&p->m);
}

canonical_original_code:
void produci_alta_prio(struct PriorityProdCons *p){
 int value;
 enter_monitor(&p->m);
 printf("Produttore 1 entrato nel monitor...\n");
 while(p->count == 3) {
  wait_condition(&p->m,0);
 }
 value = rand() % 12 ;
 p->buffer[p->testa] = value;
 p->testa = ++(p->testa) % 3;
 p->count++;
 printf("Produttore 1 con pid %d ha prodotto %d\n",getpid(),value);
 signal_condition(&p->m,2);
 leave_monitor(&p->m);
}

variable_types: struct PriorityProdCons { int buffer[3]; struct Monitor { int mutex; int num_var_cond; int id_conds; int id_shared; int *cond_counts; } m; int testa; int coda; int count; } *

variable_types: value int

user_defined_types: struct PriorityProdCons { int buffer[3]; struct Monitor m; int testa; int coda; int count; }


decompiled_code:
__int64 __fastcall produci_bassa_prio(__int64 a1)
{
__int64 v1; // rbp
unsigned int v2; // er12
int v3; // eax
unsigned int v4; // eax

v1 = a1 + 16;
enter_monitor(a1 + 16);
puts("Produttore 2 entrato nel monitor...");
while ( *(_DWORD *)(a1 + 48) == 3 )
wait_condition(v1, 1LL);
v2 = rand() % 12 + 13;
v3 = *(_DWORD *)(a1 + 40);
*(_DWORD *)(a1 + 4LL * v3) = v2;
*(_DWORD *)(a1 + 40) = (v3 + 1) % 3;
++*(_DWORD *)(a1 + 48);
v4 = getpid();
printf("Produttore 2 con pid %d ha prodotto %d\n", v4, v2);
signal_condition(v1, 2LL);
return leave_monitor(v1);
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
__int64 v1; // rbp
unsigned int v2; // er12
int v3; // eax
unsigned int v4; // eax

v1 = a1 + 16;
func15(a1 + 16);
puts("Produttore 2 entrato nel monitor...");
while ( *(_DWORD *)(a1 + 48) == 3 )
func18(v1, 1LL);
v2 = rand() % 12 + 13;
v3 = *(_DWORD *)(a1 + 40);
*(_DWORD *)(a1 + 4LL * v3) = v2;
*(_DWORD *)(a1 + 40) = (v3 + 1) % 3;
++*(_DWORD *)(a1 + 48);
v4 = getpid();
printf("Produttore 2 con pid %d ha prodotto %d\n", v4, v2);
func19(v1, 2LL);
return func16(v1);
}

original_code:
void produci_bassa_prio(PriorityProdCons* p){
 int value;
 enter_monitor(&p->m);
 printf("Produttore 2 entrato nel monitor...\n");
 while(p->count == 3) {
  wait_condition(&p->m,1);
 }
 value = 13 + (rand() % 12) ;
 p->buffer[p->testa] = value;
 p->testa = ++(p->testa) % 3;
 p->count++;
 printf("Produttore 2 con pid %d ha prodotto %d\n",getpid(),value);
 signal_condition(&p->m,2);
 leave_monitor(&p->m);
}

canonical_original_code:
void produci_bassa_prio(struct PriorityProdCons *p){
 int value;
 enter_monitor(&p->m);
 printf("Produttore 2 entrato nel monitor...\n");
 while(p->count == 3) {
  wait_condition(&p->m,1);
 }
 value = 13 + (rand() % 12) ;
 p->buffer[p->testa] = value;
 p->testa = ++(p->testa) % 3;
 p->count++;
 printf("Produttore 2 con pid %d ha prodotto %d\n",getpid(),value);
 signal_condition(&p->m,2);
 leave_monitor(&p->m);
}

user_defined_types: struct Monitor { int mutex; int num_var_cond; int id_conds; int id_shared; int *cond_counts; }


consuma

decompiled_code:
__int64 __fastcall consuma(__int64 a1)
{
__int64 v1; // rbp
int i; // eax
int v3; // edx
unsigned int v4; // er12
unsigned int v5; // eax

v1 = a1 + 16;
enter_monitor(a1 + 16);
for ( i = *(_DWORD *)(a1 + 48); !i; i = *(_DWORD *)(a1 + 48) )
wait_condition(v1, 2LL);
v3 = *(_DWORD *)(a1 + 44);
v4 = *(_DWORD *)(a1 + 4LL * v3);
*(_DWORD *)(a1 + 44) = (v3 + 1) % 3;
*(_DWORD *)(a1 + 48) = i - 1;
v5 = getpid();
printf("Consumatore con pid %d ha consumato valore %d\n", v5, v4);
if ( (int)queue_condition(v1, 0LL) <= 0 )
signal_condition(v1, 1LL);
else
signal_condition(v1, 0LL);
return leave_monitor(v1);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
__int64 v1; // rbp
int i; // eax
int v3; // edx
unsigned int v4; // er12
unsigned int v5; // eax

v1 = a1 + 16;
func15(a1 + 16);
for ( i = *(_DWORD *)(a1 + 48); !i; i = *(_DWORD *)(a1 + 48) )
func18(v1, 2LL);
v3 = *(_DWORD *)(a1 + 44);
v4 = *(_DWORD *)(a1 + 4LL * v3);
*(_DWORD *)(a1 + 44) = (v3 + 1) % 3;
*(_DWORD *)(a1 + 48) = i - 1;
v5 = getpid();
printf("Consumatore con pid %d ha consumato valore %d\n", v5, v4);
if ( (int)func20(v1, 0LL) <= 0 )
func19(v1, 1LL);
else
func19(v1, 0LL);
return func16(v1);
}

original_code:
void consuma(PriorityProdCons* p){
 int value;
 enter_monitor(&p->m);
 while(p->count == 0){
  wait_condition(&p->m,2);
 }
 value = p->buffer[p->coda];
 p->coda = ++(p->coda) % 3;
 p->count--;
 printf("Consumatore con pid %d ha consumato valore %d\n",getpid(),value);
 if(queue_condition(&p->m,0) > 0)
  signal_condition(&p->m,0);
 else
  signal_condition(&p->m,1);
 leave_monitor(&p->m);
}

canonical_original_code:
void consuma(struct PriorityProdCons *p){
 int value;
 enter_monitor(&p->m);
 while(p->count == 0){
  wait_condition(&p->m,2);
 }
 value = p->buffer[p->coda];
 p->coda = ++(p->coda) % 3;
 p->count--;
 printf("Consumatore con pid %d ha consumato valore %d\n",getpid(),value);
 if(queue_condition(&p->m,0) > 0)
  signal_condition(&p->m,0);
 else
  signal_condition(&p->m,1);
 leave_monitor(&p->m);
}


decompiled_code:
__int64 __fastcall queue_condition(__int64 a1, int a2)
{
return *(unsigned int *)(*(_QWORD *)(a1 + 16) + 4LL * a2);
}

canonical_decompiled_code:
__int64 __fastcall func20(__int64 a1, int a2)
{
return *(unsigned int *)(*(_QWORD *)(a1 + 16) + 4LL * a2);
}

original_code:
int queue_condition(Monitor * M, int id_var){
 return M->cond_counts[id_var];
}

canonical_original_code:
int queue_condition(struct Monitor *M, int id_var){
 return M->cond_counts[id_var];
}

variable_types: struct Monitor { int mutex; int num_var_cond; int id_conds; int id_shared; int *cond_counts; } *


PrintHello

decompiled_code:
void __fastcall __noreturn PrintHello(void *a1)
{
printf("\n%d: Hello World!\n", a1);
pthread_exit(0LL);
}

canonical_decompiled_code:
void __fastcall __noreturn func7(void *a1)
{
printf("\n%d: Hello World!\n", a1);
pthread_exit(0LL);
}

original_code:
void *PrintHello(void *threadid)
{
   printf("\n%d: Hello World!\n", threadid);
   pthread_exit(((void *)0));
}

variable_types:
threadid
void *


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
char *v3; // rbx
unsigned int v4; // eax
_BYTE savedregs[72]; // [rsp+0h] [rbp+0h] BYREF

v3 = 0LL;
while ( 1 )
{
printf("Creating thread %d\n", (unsigned int)v3);
v4 = pthread_create((pthread_t *)savedregs, 0LL, (void *(*)(void *))PrintHello, v3);
if ( v4 )
break;
if ( ++v3 == (char *)5 )
pthread_exit(0LL);
}
printf("ERROR; return code from pthread_create() is %d\n", v4);
exit(-1);
}

original_code:
int main(int argc, char *argv[])
{
pthread_t threads[5];
int rc, t;
for(t=0;t<5;t++){
  printf("Creating thread %d\n", t);
  rc = pthread_create(&threads[t], ((void *)0), PrintHello, (void *)t);
  if (rc){
    printf("ERROR; return code from pthread_create() is %d\n", rc);
    exit(-1);
    }
  }
pthread_exit(((void *)0));
}

canonical_original_code:
int main(int argc, char *argv[])
{
unsigned long threads[5];
int rc; int t;
for(t=0;t<5;t++){
  printf("Creating thread %d\n", t);
  rc = pthread_create(&threads[t], ((void *)0), PrintHello, (void *)t);
  if (rc){
    printf("ERROR; return code from pthread_create() is %d\n", rc);
    exit(-1);
    }
  }
pthread_exit(((void *)0));
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
threads
unsigned long [5]

variable_types: t int


decompiled_code:
int __fastcall Leggi_Sem(int a1, int a2)
{
return semctl(a1, a2, 12);
}

canonical_decompiled_code:
int __fastcall func3(int a1, int a2)
{
return semctl(a1, a2, 12);
}

original_code:
int Leggi_Sem(int id_sem, int numsem) {
  return semctl(id_sem,numsem,12);
}

variable_types: numsem int


decompiled_code:
int __fastcall Wait_Sem(int a1, unsigned __int16 a2)
{
struct sembuf sops; // [rsp+Ah] [rbp-Eh] BYREF

sops.sem_num = a2;
sops.sem_flg = 0;
sops.sem_op = -1;
return semop(a1, &sops, 1uLL);
}

canonical_decompiled_code:
int __fastcall func0(int a1, unsigned __int16 a2)
{
struct sembuf sops; // [rsp+Ah] [rbp-Eh] BYREF

sops.sem_num = a2;
sops.sem_flg = 0;
sops.sem_op = -1;
return semop(a1, &sops, 1uLL);
}

original_code:
void Wait_Sem(int id_sem, int numsem) {
       struct sembuf sem_buf;
       sem_buf.sem_num=numsem;
       sem_buf.sem_flg=0;
       sem_buf.sem_op=-1;
       semop(id_sem,&sem_buf,1);
}

variable_types: struct sembuf { unsigned short sem_num; short sem_op; short sem_flg; }


decompiled_code:
int __fastcall Signal_Sem(int a1, unsigned __int16 a2)
{
struct sembuf sops; // [rsp+Ah] [rbp-Eh] BYREF

sops.sem_num = a2;
sops.sem_flg = 0;
sops.sem_op = 1;
return semop(a1, &sops, 1uLL);
}

canonical_decompiled_code:
int __fastcall func1(int a1, unsigned __int16 a2)
{
struct sembuf sops; // [rsp+Ah] [rbp-Eh] BYREF

sops.sem_num = a2;
sops.sem_flg = 0;
sops.sem_op = 1;
return semop(a1, &sops, 1uLL);
}

original_code:
void Signal_Sem (int id_sem,int numsem) {
       struct sembuf sem_buf;
       sem_buf.sem_num=numsem;
       sem_buf.sem_flg=0;
       sem_buf.sem_op=1;
       semop(id_sem,&sem_buf,1);
}

canonical_original_code:
void Signal_Sem(int id_sem, int numsem) {
       struct sembuf sem_buf;
       sem_buf.sem_num=numsem;
       sem_buf.sem_flg=0;
       sem_buf.sem_op=1;
       semop(id_sem,&sem_buf,1);
}


decompiled_code:
int __fastcall Queue_Sem(int a1, int a2)
{
return semctl(a1, a2, 14, 0LL);
}

canonical_decompiled_code:
int __fastcall func2(int a1, int a2)
{
return semctl(a1, a2, 14, 0LL);
}

original_code:
int Queue_Sem(int id_sem, int numsem) {
 return semctl(id_sem,numsem,14,((void *)0));
}


canonical_decompiled_code:
__int64 __fastcall func21(__int64 a1, int a2)
{
return *(unsigned int *)(*(_QWORD *)(a1 + 16) + 4LL * a2);
}


repo: robertqingsong/shine

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

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

original_code:
CData *create_data( const CDataHeader *pDataHeader )
{
 CData *pRetCode = ((void *)0);
 return pRetCode;
}

canonical_original_code:
struct CData_t *create_data(struct CDataHeader_t *pDataHeader)
{
 struct CData_t *pRetCode = ((void *)0);
 return pRetCode;
}

variable_types:
pDataHeader
struct CDataHeader_t *

variable_types: struct CData_t { struct CDataSlice_t { struct CDataHeader_t { unsigned short iDataId; unsigned char iDataSubId; unsigned char iDataSubIdRange; } stDataHeader; unsigned short iTotalDataSize; unsigned int iCurrentSliceSize; } *pDataSliceArray; unsigned short iDataSliceArraySize; unsigned char *pDataBuf; unsigned short iDataBufSize; } *

user_defined_types: struct CData_t { struct CDataSlice_t *pDataSliceArray; unsigned short iDataSliceArraySize; unsigned char *pDataBuf; unsigned short iDataBufSize; }

user_defined_types: struct CDataSlice_t { struct CDataHeader_t stDataHeader; unsigned short iTotalDataSize; unsigned int iCurrentSliceSize; }


decompiled_code:
void destroy_data()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code:
void destroy_data( CData *pData )
{
}

canonical_original_code:
void destroy_data(struct CData_t *pData)
{
}

user_defined_types: struct CDataHeader_t { unsigned short iDataId; unsigned char iDataSubId; unsigned char iDataSubIdRange; }


decompiled_code:
__int64 add_data_slice()
{
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func2()
{
return 0xFFFFFFFFLL;
}

original_code:
int32_t add_data_slice( CData *pData, const CDataSlice *pDataSlice )
{
 int32_t iRetCode = -1;
 return iRetCode;
}

canonical_original_code:
int add_data_slice(struct CData_t *pData, struct CDataSlice_t *pDataSlice)
{
 int iRetCode = -1;
 return iRetCode;
}

variable_types:
pDataSlice
struct CDataSlice_t *

variable_types: iRetCode int


decompiled_code:
__int64 is_shine_manager_ready()
{
return (unsigned int)-(fg_ShineManager == 0);
}

canonical_decompiled_code:
__int64 func0()
{
return (unsigned int)-(fg_ShineManager == 0);
}

original_code:
static int32_t is_shine_manager_ready( void )
{
 int32_t iRetCode = -1;
 if ( fg_ShineManager.iInitFlag )
  iRetCode = 0;
 return iRetCode;
}

canonical_original_code:
static int is_shine_manager_ready()
{
 int iRetCode = -1;
 if ( fg_ShineManager.iInitFlag )
  iRetCode = 0;
 return iRetCode;
}


decompiled_code:
__int64 shine_session_event()
{
return 0xFFFFFFFFLL;
}

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

original_code:
static int32_t shine_session_event( const struct CSession_t *pThis,
     const C_SESSION_EVENT eEvent,
     const CEventParam *pEventParam,
     const int32_t iEventParamSize,
     void *pUserData )
{
 int32_t iRetCode = -1;
 return iRetCode;
}

canonical_original_code:
static int shine_session_event(struct CSession_t *pThis, enum CSessionEvent_t eEvent, struct CEventParam_t *pEventParam, int iEventParamSize, void *pUserData)
{
 int iRetCode = -1;
 return iRetCode;
}

variable_types: struct CSession_t { int (*init)(struct CSession_t *pThis, struct CSessionParam_t { char pIP[32]; unsigned short iPort; char pLocalIP[32]; unsigned short iLocalPort; } *pParam); void (*release)(struct CSession_t *pThis); int (*handle_input)(struct CSession_t *pThis, struct CSocket_t { int iSocketId; struct CReactor_t { struct CNetEngine_t { int iEngineId; int iIsRunning; struct CThread_t { struct CPine_t { struct CBTreeNode_t {  } BTNode; } PineSuper; void *(*thread)(void *pParam); enum C_THREAD_PRIORITY { OS_THREAD_PRIORITY_LOW=0, OS_THREAD_PRIORITY_NORMAL=1, OS_THREAD_PRIORITY_HIGH=2 } ePriority; void *pParam; unsigned long long iTid; int iQuitFlag; } *pEngineThread; } *pEngine; int (*fReactorCallback)(struct CReactor_t *pReactorId, struct CSocket_t *pSocketId, void *pUserData); struct CQueue_t { struct CQueueNode_t { struct CListNode_t { void *pData; struct CListNode_t *Prev; struct CListNode_t *Next; } LNode; } *Front; struct CQueueNode_t *Rear; int iMaxQueueWaterLevel; int iCurrentQueueWaterLevel; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } Locker; } stSocketRemoveQ; union pthread_mutex_t Locker; void *pUserData; } *pOwnerReactor; void *pUserData; } *pSocket); int (*handle_output)(struct CSession_t *pThis, unsigned char *pOutDatabuf, int iOutDataLen, struct CNetAddr_t { char pIP[32]; unsigned short iPort; unsigned short iLocalPort; } *pNetAddr); int (*handle_business)(struct CSession_t *pThis, struct CSocket_t *pSocket, unsigned char *pInData, int iInDataLen, struct CNetAddr_t *pNetAddr, void *pUserData); int (*handle_event)(struct CSession_t *pThis, enum CSessionEvent_t { EVENT_READ_ERROR=0, EVENT_WRITE_ERROR=1, EVENT_ACCEPT_ERROR=2, EVENT_ACCEPT_NEW_STREAM_CLIENT_NOTIFY=3 } eEvent, struct CEventParam_t { struct CSocket_t *pSocket; struct CNetAddr_t stNetAddr; } *pEventParam, int iEventParamSize, void *pUserData); struct CSessionParam_t stSessionParam; struct CReactor_t *pOwnerReactor; struct CSocket_t *pSocket; struct CNetAddr_t stPeerAddr; int iBlockId; void *pResultCode; void *pUserData; union pthread_mutex_t Locker; } *

variable_types:
pEventParam
struct CEventParam_t *

variable_types: iEventParamSize int

variable_types:
pUserData
void *

user_defined_types: struct CSession_t { int (*init)(struct CSession_t *pThis, struct CSessionParam_t *pParam); void (*release)(struct CSession_t *pThis); int (*handle_input)(struct CSession_t *pThis, struct CSocket_t *pSocket); int (*handle_output)(struct CSession_t *pThis, unsigned char *pOutDatabuf, int iOutDataLen, struct CNetAddr_t *pNetAddr); int (*handle_business)(struct CSession_t *pThis, struct CSocket_t *pSocket, unsigned char *pInData, int iInDataLen, struct CNetAddr_t *pNetAddr, void *pUserData); int (*handle_event)(struct CSession_t *pThis, enum CSessionEvent_t eEvent, struct CEventParam_t *pEventParam, int iEventParamSize, void *pUserData); struct CSessionParam_t stSessionParam; struct CReactor_t *pOwnerReactor; struct CSocket_t *pSocket; struct CNetAddr_t stPeerAddr; int iBlockId; void *pResultCode; void *pUserData; union pthread_mutex_t Locker; }

user_defined_types: struct CSocket_t { int iSocketId; struct CReactor_t *pOwnerReactor; void *pUserData; }

user_defined_types: struct CReactor_t { struct CNetEngine_t *pEngine; int (*fReactorCallback)(struct CReactor_t *pReactorId, struct CSocket_t *pSocketId, void *pUserData); struct CQueue_t stSocketRemoveQ; union pthread_mutex_t Locker; void *pUserData; }

user_defined_types: struct CQueue_t { struct CQueueNode_t *Front; struct CQueueNode_t *Rear; int iMaxQueueWaterLevel; int iCurrentQueueWaterLevel; union pthread_mutex_t Locker; }

user_defined_types: struct CNetEngine_t { int iEngineId; int iIsRunning; struct CThread_t *pEngineThread; }

user_defined_types: struct CQueueNode_t { struct CListNode_t LNode; }

user_defined_types: struct CThread_t { struct CPine_t PineSuper; void *(*thread)(void *pParam); enum C_THREAD_PRIORITY ePriority; void *pParam; unsigned long long iTid; int iQuitFlag; }

user_defined_types: struct CPine_t { struct CBTreeNode_t BTNode; }


original_code:
static int32_t shine_session_business( const struct CSession_t *pThis,
      const CSocket *pSocket,
        const int8u_t *pInData,
        const int32_t iInDataLen,
        const CNetAddr *pNetAddr,
        void *pUserData )
{
 int32_t iRetCode = -1;
 CShine *pShine = (CShine *)pUserData;
 CCommonHeader *pMsgHeader = ((void *)0);
 log_print( "shine session business calling.................." );
 if ( !pShine || !pInData || iInDataLen <= 0 )
 {
  log_print( "param is invalid???????????????????????????" );
  return iRetCode;
 }
 if ( pShine->pBlock )
 {
  block_exiting( pShine->pBlock );
  pMsgHeader = (CCommonHeader *)pInData;
  switch ( pMsgHeader->iMsgId )
  {
  case (0x02):
  {
   AckTellPeer *pAckTellPeerMsg = (AckTellPeer *)pInData;
   memcpy( pShine->pPeerIP, pAckTellPeerMsg->pPeerIP, strlen(pAckTellPeerMsg->pPeerIP) );
   pShine->iPeerPort = pAckTellPeerMsg->iPeerPort;
   pShine->iState = (0);
   log_print( "peer ip:%s, port:%d", pShine->pPeerIP, pShine->iPeerPort );
  }break ;
  default:
  {
   log_print( "unknown msg id?????????????????????" );
  }break ;
  }
  block_post( pShine->pBlock );
 }
 else
  log_print( "shine block is NULL???????????????????" );
 return iRetCode;
}

canonical_original_code:
static int shine_session_business(struct CSession_t *pThis, struct CSocket_t *pSocket, unsigned char *pInData, int iInDataLen, struct CNetAddr_t *pNetAddr, void *pUserData)
{
 int iRetCode = -1;
 struct CShine_t *pShine = (CShine *)pUserData;
 struct CCommonHeader_t *pMsgHeader = ((void *)0);
 log_print( "shine session business calling.................." );
 if ( !pShine || !pInData || iInDataLen <= 0 )
 {
  log_print( "param is invalid???????????????????????????" );
  return iRetCode;
 }
 if ( pShine->pBlock )
 {
  block_exiting( pShine->pBlock );
  pMsgHeader = (struct CCommonHeader_t *)pInData;
  switch ( pMsgHeader->iMsgId )
  {
  case (0x02):
  {
   struct CAckTellPeer_t *pAckTellPeerMsg = (AckTellPeer *)pInData;
   memcpy( pShine->pPeerIP, pAckTellPeerMsg->pPeerIP, strlen(pAckTellPeerMsg->pPeerIP) );
   pShine->iPeerPort = pAckTellPeerMsg->iPeerPort;
   pShine->iState = (0);
   log_print( "peer ip:%s, port:%d", pShine->pPeerIP, pShine->iPeerPort );
  }break ;
  default:
  {
   log_print( "unknown msg id?????????????????????" );
  }break ;
  }
  block_post( pShine->pBlock );
 }
 else
  log_print( "shine block is NULL???????????????????" );
 return iRetCode;
}

variable_types:
pSocket
struct CSocket_t *

variable_types:
pInData
unsigned char *

variable_types: iInDataLen int

variable_types:
pNetAddr
struct CNetAddr_t *

variable_types: struct CShine_t { struct CShineParam_t { char pShineId[-1]; char pServerIP[32]; unsigned short iServerPort; char pLocalIP[-1]; unsigned short iLocalPort; char pUserName[64]; char pUserPassword[64]; int iIsReliable; } stShineParam; struct CTunnel_t { struct CSession_t { int (*init)(struct CSession_t *pThis, struct CSessionParam_t { char pIP[32]; unsigned short iPort; char pLocalIP[32]; unsigned short iLocalPort; } *pParam); void (*release)(struct CSession_t *pThis); int (*handle_input)(struct CSession_t *pThis, struct CSocket_t { int iSocketId; struct CReactor_t { struct CNetEngine_t { int iEngineId; int iIsRunning; struct CThread_t { struct CPine_t { struct CBTreeNode_t {  } BTNode; } PineSuper; void *(*thread)(void *pParam); enum C_THREAD_PRIORITY { OS_THREAD_PRIORITY_LOW=0, OS_THREAD_PRIORITY_NORMAL=1, OS_THREAD_PRIORITY_HIGH=2 } ePriority; void *pParam; unsigned long long iTid; int iQuitFlag; } *pEngineThread; } *pEngine; int (*fReactorCallback)(struct CReactor_t *pReactorId, struct CSocket_t *pSocketId, void *pUserData); struct CQueue_t { struct CQueueNode_t { struct CListNode_t { void *pData; struct CListNode_t *Prev; struct CListNode_t *Next; } LNode; } *Front; struct CQueueNode_t *Rear; int iMaxQueueWaterLevel; int iCurrentQueueWaterLevel; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } Locker; } stSocketRemoveQ; union pthread_mutex_t Locker; void *pUserData; } *pOwnerReactor; void *pUserData; } *pSocket); int (*handle_output)(struct CSession_t *pThis, unsigned char *pOutDatabuf, int iOutDataLen, struct CNetAddr_t { char pIP[32]; unsigned short iPort; unsigned short iLocalPort; } *pNetAddr); int (*handle_business)(struct CSession_t *pThis, struct CSocket_t *pSocket, unsigned char *pInData, int iInDataLen, struct CNetAddr_t *pNetAddr, void *pUserData); int (*handle_event)(struct CSession_t *pThis, enum CSessionEvent_t { EVENT_READ_ERROR=0, EVENT_WRITE_ERROR=1, EVENT_ACCEPT_ERROR=2, EVENT_ACCEPT_NEW_STREAM_CLIENT_NOTIFY=3 } eEvent, struct CEventParam_t { struct CSocket_t *pSocket; struct CNetAddr_t stNetAddr; } *pEventParam, int iEventParamSize, void *pUserData); struct CSessionParam_t stSessionParam; struct CReactor_t *pOwnerReactor; struct CSocket_t *pSocket; struct CNetAddr_t stPeerAddr; int iBlockId; void *pResultCode; void *pUserData; union pthread_mutex_t Locker; } *pSession; } *ppTunnelArray[-1]; int iCurrentTunnelIndex; struct CSession_t *pServerSession; void *pBlock; int iState; char pPeerIP[-1]; unsigned short iPeerPort; union pthread_mutex_t Locker; } *

variable_types: struct CCommonHeader_t { int iMsgId; int iMsgSize; } *

variable_types: struct CAckTellPeer_t { struct CCommonHeader_t { int iMsgId; int iMsgSize; } header; char pPeerIP[-1]; unsigned short iPeerPort; } *

user_defined_types: struct CShine_t { struct CShineParam_t stShineParam; struct CTunnel_t *ppTunnelArray[-1]; int iCurrentTunnelIndex; struct CSession_t *pServerSession; void *pBlock; int iState; char pPeerIP[-1]; unsigned short iPeerPort; union pthread_mutex_t Locker; }

user_defined_types: struct CAckTellPeer_t { struct CCommonHeader_t header; char pPeerIP[-1]; unsigned short iPeerPort; }

user_defined_types: struct CTunnel_t { struct CSession_t *pSession; }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }


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

result = 0LL;
if ( !fg_ShineManager )
{
word_8B4 = -13606;
if ( (int)init_session() < 0 )
{
result = 0xFFFFFFFFLL;
}
else
{
fg_ShineManager = 1;
result = init_block();
}
}
return result;
}

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

result = 0LL;
if ( !fg_ShineManager )
{
word_8B4 = -13606;
if ( (int)init_session() < 0 )
{
result = 0xFFFFFFFFLL;
}
else
{
fg_ShineManager = 1;
result = init_block();
}
}
return result;
}

original_code:
int32_t init_shine( void )
{
 int32_t iRetCode = -1;
 if ( !fg_ShineManager.iInitFlag )
 {
  fg_ShineManager.iLocalPortIndex = 51930;
  if ( init_session( ) >= 0 )
  {
   fg_ShineManager.iInitFlag = 1;
   iRetCode = init_block( );
  }
 }
 else
  iRetCode = 0;
 return iRetCode;
}

canonical_original_code:
int init_shine()
{
 int iRetCode = -1;
 if ( !fg_ShineManager.iInitFlag )
 {
  fg_ShineManager.iLocalPortIndex = 51930;
  if ( init_session( ) >= 0 )
  {
   fg_ShineManager.iInitFlag = 1;
   iRetCode = init_block( );
  }
 }
 else
  iRetCode = 0;
 return iRetCode;
}


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

if ( fg_ShineManager )
{
release_block();
result = release_session();
fg_ShineManager = 0;
}
return result;
}

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

if ( fg_ShineManager )
{
release_block();
result = release_session();
fg_ShineManager = 0;
}
return result;
}

original_code:
void release_shine( void )
{
 if ( fg_ShineManager.iInitFlag )
 {
  release_block( );
  release_session( );
  fg_ShineManager.iInitFlag = 0;
 }
}

canonical_original_code:
void release_shine()
{
 if ( fg_ShineManager.iInitFlag )
 {
  release_block( );
  release_session( );
  fg_ShineManager.iInitFlag = 0;
 }
}


decompiled_code:
__int64 __fastcall close_shine(__int64 a1)
{
__int64 result; // rax
int v2; // edx
int i; // eax

result = is_shine_manager_ready();
if ( a1 && (int)result >= 0 )
{
lock(a1 + 584);
v2 = *(_DWORD *)(a1 + 520);
if ( v2 > 0 )
{
for ( i = 0; i != v2; ++i )
;
}
destroy_session(*(_QWORD *)(a1 + 528));
*(_QWORD *)(a1 + 528) = 0LL;
result = unlock(a1 + 584);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
__int64 result; // rax
int v2; // edx
int i; // eax

result = func0();
if ( a1 && (int)result >= 0 )
{
lock(a1 + 584);
v2 = *(_DWORD *)(a1 + 520);
if ( v2 > 0 )
{
for ( i = 0; i != v2; ++i )
;
}
destroy_session(*(_QWORD *)(a1 + 528));
*(_QWORD *)(a1 + 528) = 0LL;
result = unlock(a1 + 584);
}
return result;
}

original_code:
void close_shine( void *pHandle )
{
 if ( is_shine_manager_ready( ) < 0 )
  return ;
 if ( pHandle )
 {
  CShine *pShine = (CShine *)pHandle;
  int32_t i = 0;
  CTunnel *pTunnel = ((void *)0);
  lock( &( pShine->Locker ) );
  for ( i = 0; i < pShine->iCurrentTunnelIndex; i++ )
  {
   pTunnel = pShine->ppTunnelArray[i];
   destroy_tunnel( pTunnel );
  }
  destroy_session( pShine->pServerSession );
  pShine->pServerSession = ((void *)0);
  unlock( &( pShine->Locker ) );
 }
}

canonical_original_code:
void close_shine(void *pHandle)
{
 if ( is_shine_manager_ready( ) < 0 )
  return ;
 if ( pHandle )
 {
  struct CShine_t *pShine = (CShine *)pHandle;
  int i = 0;
  struct CTunnel_t *pTunnel = ((void *)0);
  lock( &( pShine->Locker ) );
  for ( i = 0; i < pShine->iCurrentTunnelIndex; i++ )
  {
   pTunnel = pShine->ppTunnelArray[i];
   destroy_tunnel( pTunnel );
  }
  destroy_session( pShine->pServerSession );
  pShine->pServerSession = ((void *)0);
  unlock( &( pShine->Locker ) );
 }
}

variable_types:
pHandle
void *

variable_types: i int

variable_types: struct CTunnel_t { struct CSession_t { int (*init)(struct CSession_t *pThis, struct CSessionParam_t { char pIP[32]; unsigned short iPort; char pLocalIP[32]; unsigned short iLocalPort; } *pParam); void (*release)(struct CSession_t *pThis); int (*handle_input)(struct CSession_t *pThis, struct CSocket_t { int iSocketId; struct CReactor_t { struct CNetEngine_t { int iEngineId; int iIsRunning; struct CThread_t { struct CPine_t { struct CBTreeNode_t {  } BTNode; } PineSuper; void *(*thread)(void *pParam); enum C_THREAD_PRIORITY { OS_THREAD_PRIORITY_LOW=0, OS_THREAD_PRIORITY_NORMAL=1, OS_THREAD_PRIORITY_HIGH=2 } ePriority; void *pParam; unsigned long long iTid; int iQuitFlag; } *pEngineThread; } *pEngine; int (*fReactorCallback)(struct CReactor_t *pReactorId, struct CSocket_t *pSocketId, void *pUserData); struct CQueue_t { struct CQueueNode_t { struct CListNode_t { void *pData; struct CListNode_t *Prev; struct CListNode_t *Next; } LNode; } *Front; struct CQueueNode_t *Rear; int iMaxQueueWaterLevel; int iCurrentQueueWaterLevel; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } Locker; } stSocketRemoveQ; union pthread_mutex_t Locker; void *pUserData; } *pOwnerReactor; void *pUserData; } *pSocket); int (*handle_output)(struct CSession_t *pThis, unsigned char *pOutDatabuf, int iOutDataLen, struct CNetAddr_t { char pIP[32]; unsigned short iPort; unsigned short iLocalPort; } *pNetAddr); int (*handle_business)(struct CSession_t *pThis, struct CSocket_t *pSocket, unsigned char *pInData, int iInDataLen, struct CNetAddr_t *pNetAddr, void *pUserData); int (*handle_event)(struct CSession_t *pThis, enum CSessionEvent_t { EVENT_READ_ERROR=0, EVENT_WRITE_ERROR=1, EVENT_ACCEPT_ERROR=2, EVENT_ACCEPT_NEW_STREAM_CLIENT_NOTIFY=3 } eEvent, struct CEventParam_t { struct CSocket_t *pSocket; struct CNetAddr_t stNetAddr; } *pEventParam, int iEventParamSize, void *pUserData); struct CSessionParam_t stSessionParam; struct CReactor_t *pOwnerReactor; struct CSocket_t *pSocket; struct CNetAddr_t stPeerAddr; int iBlockId; void *pResultCode; void *pUserData; union pthread_mutex_t Locker; } *pSession; } *

user_defined_types: struct CShineParam_t { char pShineId[-1]; char pServerIP[32]; unsigned short iServerPort; char pLocalIP[-1]; unsigned short iLocalPort; char pUserName[64]; char pUserPassword[64]; int iIsReliable; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }


decompiled_code:
__int64 __fastcall open_shine_tunnel(__int64 a1, const char *a2)
{
int v2; // er13
unsigned int v3; // er14
int v5; // eax

if ( (int)is_shine_manager_ready() < 0 )
return (unsigned int)-1;
if ( !a1 || !a2 )
return (unsigned int)-1;
lock(a1 + 584);
v2 = *(_DWORD *)(a1 + 520);
v3 = -1;
if ( v2 <= 31 )
{
*(_QWORD *)(a1 + 8LL * v2 + 264) = create_tunnel(a1, a2, 1);
v5 = *(_DWORD *)(a1 + 520);
if ( *(_QWORD *)(a1 + 8LL * v5 + 264) )
{
*(_DWORD *)(a1 + 520) = v5 + 1;
log_print("create tunnel ok!!!!!!!!!!!!!!!!!!");
v3 = 0;
}
else
{
log_print("create tunnel failed?????????????????");
v3 = -1;
}
}
unlock(a1 + 584);
return v3;
}

original_code:
int32_t open_shine_tunnel( void *pHandle, int8_t *pPeerShineId )
{
 int32_t iRetCode = -1;
 if ( is_shine_manager_ready( ) < 0 )
  return iRetCode;
 if ( pHandle && pPeerShineId )
 {
  CShine *pShine = (CShine *)pHandle;
  lock( &( pShine->Locker ) );
  if ( pShine->iCurrentTunnelIndex < (32) )
  {
   pShine->ppTunnelArray[pShine->iCurrentTunnelIndex] = create_tunnel( pShine, pPeerShineId, SHINE_ROLE_SHARE_SERVICE );
   if ( pShine->ppTunnelArray[pShine->iCurrentTunnelIndex] )
   {
    (pShine->iCurrentTunnelIndex)++;
    log_print( "create tunnel ok!!!!!!!!!!!!!!!!!!" );
    iRetCode = 0;
   }
   else
    log_print( "create tunnel failed?????????????????" );
  }
  unlock( &( pShine->Locker ) );
 }
 return iRetCode;
}

canonical_original_code:
int open_shine_tunnel(void *pHandle, char *pPeerShineId)
{
 int iRetCode = -1;
 if ( is_shine_manager_ready( ) < 0 )
  return iRetCode;
 if ( pHandle && pPeerShineId )
 {
  struct CShine_t *pShine = (CShine *)pHandle;
  lock( &( pShine->Locker ) );
  if ( pShine->iCurrentTunnelIndex < (32) )
  {
   pShine->ppTunnelArray[pShine->iCurrentTunnelIndex] = create_tunnel( pShine, pPeerShineId, SHINE_ROLE_SHARE_SERVICE );
   if ( pShine->ppTunnelArray[pShine->iCurrentTunnelIndex] )
   {
    (pShine->iCurrentTunnelIndex)++;
    log_print( "create tunnel ok!!!!!!!!!!!!!!!!!!" );
    iRetCode = 0;
   }
   else
    log_print( "create tunnel failed?????????????????" );
  }
  unlock( &( pShine->Locker ) );
 }
 return iRetCode;
}

variable_types:
pPeerShineId
char *

user_defined_types: enum CSessionEvent_t { EVENT_READ_ERROR=0, EVENT_WRITE_ERROR=1, EVENT_ACCEPT_ERROR=2, EVENT_ACCEPT_NEW_STREAM_CLIENT_NOTIFY=3 }

user_defined_types: struct CSessionParam_t { char pIP[32]; unsigned short iPort; char pLocalIP[32]; unsigned short iLocalPort; }

user_defined_types: struct CNetAddr_t { char pIP[32]; unsigned short iPort; unsigned short iLocalPort; }

user_defined_types: struct CEventParam_t { struct CSocket_t *pSocket; struct CNetAddr_t stNetAddr; }

user_defined_types: struct CListNode_t { void *pData; struct CListNode_t *Prev; struct CListNode_t *Next; }

user_defined_types: struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; }

user_defined_types: enum C_THREAD_PRIORITY { OS_THREAD_PRIORITY_LOW=0, OS_THREAD_PRIORITY_NORMAL=1, OS_THREAD_PRIORITY_HIGH=2 }


decompiled_code:
__int64 close_shine_tunnel()
{
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func7()
{
return 0xFFFFFFFFLL;
}

original_code:
int32_t close_shine_tunnel( void *pHandle, int32_t iTunnelId )
{
 int32_t iRetCode = -1;
 if ( is_shine_manager_ready( ) < 0 )
  return iRetCode;
 return iRetCode;
}

canonical_original_code:
int close_shine_tunnel(void *pHandle, int iTunnelId)
{
 int iRetCode = -1;
 if ( is_shine_manager_ready( ) < 0 )
  return iRetCode;
 return iRetCode;
}

variable_types: iTunnelId int


decompiled_code:
__int64 start_shine_tunnel()
{
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func8()
{
return 0xFFFFFFFFLL;
}

original_code:
int32_t start_shine_tunnel( void *pHandle )
{
 int32_t iRetCode = -1;
 if ( is_shine_manager_ready( ) < 0 )
  return iRetCode;
 return iRetCode;
}

canonical_original_code:
int start_shine_tunnel(void *pHandle)
{
 int iRetCode = -1;
 if ( is_shine_manager_ready( ) < 0 )
  return iRetCode;
 return iRetCode;
}

variable_types: iRetCode int


decompiled_code:
__int64 stop_shine_tunnel()
{
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func9()
{
return 0xFFFFFFFFLL;
}

original_code:
int32_t stop_shine_tunnel( void *pHandle, const int32_t iTunnelId )
{
 int32_t iRetCode = -1;
 if ( is_shine_manager_ready( ) < 0 )
  return iRetCode;
 return iRetCode;
}

canonical_original_code:
int stop_shine_tunnel(void *pHandle, int iTunnelId)
{
 int iRetCode = -1;
 if ( is_shine_manager_ready( ) < 0 )
  return iRetCode;
 return iRetCode;
}


decompiled_code:
__int64 read_shine_data()
{
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func10()
{
return 0xFFFFFFFFLL;
}

original_code:
int32_t read_shine_data( const void *pHandle, int8u_t *pRecvBuf, const int32_t iRecvBufSize )
{
 int32_t iRetCode = -1;
 if ( is_shine_manager_ready( ) < 0 )
  return iRetCode;
 return iRetCode;
}

canonical_original_code:
int read_shine_data(void *pHandle, unsigned char *pRecvBuf, int iRecvBufSize)
{
 int iRetCode = -1;
 if ( is_shine_manager_ready( ) < 0 )
  return iRetCode;
 return iRetCode;
}

variable_types:
pRecvBuf
unsigned char *

variable_types: iRecvBufSize int


decompiled_code:
__int64 write_shine_data()
{
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func11()
{
return 0xFFFFFFFFLL;
}

original_code:
int32_t write_shine_data( const void *pHandle, const int8u_t *pSendBuf, const int32_t iSendBufSize )
{
 int32_t iRetCode = -1;
 if ( is_shine_manager_ready( ) < 0 )
  return iRetCode;
 return iRetCode;
}

canonical_original_code:
int write_shine_data(void *pHandle, unsigned char *pSendBuf, int iSendBufSize)
{
 int iRetCode = -1;
 if ( is_shine_manager_ready( ) < 0 )
  return iRetCode;
 return iRetCode;
}

variable_types:
pSendBuf
unsigned char *

variable_types: iSendBufSize int


InitAll

repo: robn/tinysid

decompiled_code:
__int64 InitAll()
{
PrefsInit();
MemoryInit();
SIDInit();
return CPUInit();
}

canonical_decompiled_code:
__int64 func0()
{
PrefsInit();
MemoryInit();
SIDInit();
return CPUInit();
}

original_code:
void InitAll(int argc, char **argv)
{
    PrefsInit(argc, argv);
    MemoryInit();
    SIDInit();
    CPUInit();
}

variable_types: argc int

variable_types:
argv
char **


ExitAll

decompiled_code:
__int64 ExitAll()
{
CPUExit();
SIDExit();
MemoryExit();
return PrefsExit();
}

canonical_decompiled_code:
__int64 func1()
{
CPUExit();
SIDExit();
MemoryExit();
return PrefsExit();
}

original_code:
void ExitAll()
{
    CPUExit();
    SIDExit();
    MemoryExit();
    PrefsExit();
}


SelectSong

decompiled_code:
__int64 __fastcall SelectSong(int a1)
{
char v1; // bl
__int64 v2; // rdi

if ( number_of_songs <= a1 )
{
current_song = 0;
SIDReset(0LL);
v1 = 0;
goto LABEL_5;
}
v1 = a1;
current_song = a1;
SIDReset(0LL);
if ( a1 <= 31 )
{
LABEL_5:
v2 = (speed_flags & (1 << v1)) == 0 ? 50 : 60;
goto LABEL_6;
}
v2 = 50LL;
LABEL_6:
SIDSetReplayFreq(v2);
SIDAdjustSpeed(100LL);
return CPUExecute((unsigned __int16)init_adr, (unsigned __int8)current_song, 0LL, 0LL, 1000000LL);
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1)
{
char v1; // bl
__int64 v2; // rdi

if ( number_of_songs <= a1 )
{
current_song = 0;
SIDReset(0LL);
v1 = 0;
goto LABEL_5;
}
v1 = a1;
current_song = a1;
SIDReset(0LL);
if ( a1 <= 31 )
{
LABEL_5:
v2 = (speed_flags & (1 << v1)) == 0 ? 50 : 60;
goto LABEL_6;
}
v2 = 50LL;
LABEL_6:
SIDSetReplayFreq(v2);
SIDAdjustSpeed(100LL);
return CPUExecute((unsigned __int16)init_adr, (unsigned __int8)current_song, 0LL, 0LL, 1000000LL);
}

original_code:
void SelectSong(int num)
{
    if (num >= number_of_songs)
        num = 0;
    current_song = num;
    SIDReset(0);
    int freq = 50;
    if (num < 32)
        freq = speed_flags & (1 << num) ? 60 : 50;
    SIDSetReplayFreq(freq);
    SIDAdjustSpeed(100);
    CPUExecute(init_adr, current_song, 0, 0, 1000000);
}

variable_types: num int

variable_types: freq int


UpdatePlayAdr

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

if ( play_adr_from_irq_vec )
{
if ( (*((_BYTE *)&ram + 1) & 2) != 0 )
{
result = *((unsigned __int16 *)&ram + 394);
play_adr = *((_WORD *)&ram + 394);
}
else
{
result = *((unsigned __int16 *)&ram + 0x7FFF);
play_adr = *((_WORD *)&ram + 0x7FFF);
}
}
return result;
}

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

if ( play_adr_from_irq_vec )
{
if ( (*((_BYTE *)&ram + 1) & 2) != 0 )
{
result = *((unsigned __int16 *)&ram + 394);
play_adr = *((_WORD *)&ram + 394);
}
else
{
result = *((unsigned __int16 *)&ram + 0x7FFF);
play_adr = *((_WORD *)&ram + 0x7FFF);
}
}
return result;
}

original_code:
void UpdatePlayAdr()
{
    if (play_adr_from_irq_vec) {
        if (ram[1] & 2)
            play_adr = (ram[0x0315] << 8) | ram[0x0314];
        else
            play_adr = (ram[0xffff] << 8) | ram[0xfffe];
    }
}


MemoryExit

decompiled_code:
void MemoryExit()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
void MemoryExit()
{
}

canonical_original_code:
void MemoryExit()
{
}


MemoryClear

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

memset(ram, 0, 0xE000uLL);
result = 0x4040404040404040LL;
memset((void *)(unsigned int)((_DWORD)ram + 57344), 0x40u, 0x2000uLL);
ram[1] = 7;
ram[788] = 49;
ram[789] = -22;
return result;
}


MemoryInit

decompiled_code:
__int64 MemoryInit()
{
return MemoryClear();
}

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

original_code:
void MemoryInit()
{
    MemoryClear();
}

canonical_original_code:
void MemoryInit()
{
    MemoryClear();
}


PrefsPrintUsage

decompiled_code:
int PrefsPrintUsage()
{
puts("\nGeneral options:");
print_options((__int64)&common_prefs_items);
return puts("\nBoolean options are specified as '--OPTION true|on|yes' or\n'--OPTION false|off|no'.");
}

canonical_decompiled_code:
int func9()
{
puts("\nGeneral options:");
func8((__int64)&common_prefs_items);
return puts("\nBoolean options are specified as '--OPTION true|on|yes' or\n'--OPTION false|off|no'.");
}

original_code:
void PrefsPrintUsage()
{
    printf("\nGeneral options:\n");
    print_options(common_prefs_items);
    printf("\nBoolean options are specified as '--OPTION true|on|yes' or\n'--OPTION false|off|no'.\n");
}


PrefsSetCallbackString

decompiled_code:
__int64 __fastcall PrefsSetCallbackString(char *a1, __int64 a2)
{
return set_callback(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func11(char *a1, __int64 a2)
{
return func1(a1, a2);
}

original_code:
void PrefsSetCallbackString(const char *name, prefs_func_string f)
{
    set_callback(name, (prefs_func)f);
}

canonical_original_code:
void PrefsSetCallbackString(char *name, void (*f)(char *, char *, char *))
{
    set_callback(name, (void (*)(char *, int, int))f);
}

variable_types:
name
char *

variable_types:
f
void (*)(char *, char *, char *)


decompiled_code:
__int64 __fastcall PrefsSetCallbackInt32(char *a1, __int64 a2)
{
return set_callback(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func13(char *a1, __int64 a2)
{
return func1(a1, a2);
}

original_code:
void PrefsSetCallbackInt32(const char *name, prefs_func_int32 f)
{
    set_callback(name, (prefs_func)f);
}

canonical_original_code:
void PrefsSetCallbackInt32(char *name, void (*f)(char *, int, int))
{
    set_callback(name, (void (*)(char *, int, int))f);
}

variable_types:
f
void (*)(char *, int, int)


quit

decompiled_code:
void quit(void)
{
ExitAll();
SDL_Quit();
}

canonical_decompiled_code:
void func0(void)
{
ExitAll();
SDL_Quit();
}

original_code:
static void quit()
{
    ExitAll();
    SDL_Quit();
}