decompiled_code:
void *__fastcall token_bucket_func(void *a1)
{
__useconds_t v1; // ebx
double v2; // xmm0_8
double **v3; // rax
double *v4; // r12
double **v5; // rbp
int v6; // edx
__int64 v8; // rsi
double v9; // xmm0_8
double v10; // xmm1_8
__int64 v11; // rsi

v1 = (int)(1000.0 / *(double *)&r * 1000.0);
do
{
while ( 1 )
{
usleep(v1);
gettimeofday(&tim, 0LL);
v2 = (double)(int)tim.tv_usec / 1000000.0 + (double)SLODWORD(tim.tv_sec);
*(double *)&t7 = v2;
if ( B > token_counter )
break;
printf("%012.3fms: Token t%d arrives, dropped\n", (v2 - *(double *)&t1) * 1000.0, (unsigned int)token_no);
++drop_tokens;
++token_no;
LABEL_3:
if ( packet_count_Q1exit == num_afterdrop )
return 0LL;
}
pthread_mutex_lock(&mut_lock);
printf(
"%012.3fms: Token t%d arrives, token bucket now has %d tokens\n",
(*(double *)&t7 - *(double *)&t1) * 1000.0,
(unsigned int)++token_no,
(unsigned int)++token_counter);
pthread_mutex_unlock(&mut_lock);
if ( (unsigned int)My402ListEmpty(&Queue_one) )
goto LABEL_3;
v3 = (double **)My402ListFirst(&Queue_one);
v4 = *v3;
v5 = v3;
pthread_mutex_lock(&mut_lock);
v6 = *((_DWORD *)v4 + 4);
if ( v6 <= token_counter )
{
token_counter -= v6;
My402ListUnlink(&Queue_one, v5);
++packet_count_Q1exit;
gettimeofday(&tim, 0LL);
v8 = *(unsigned int *)v4;
v9 = (double)(int)tim.tv_usec / 1000000.0 + (double)SLODWORD(tim.tv_sec);
v10 = v9 - v4[4];
*(double *)&t9 = v9;
*(double *)&time_in_Q1 = *(double *)&time_in_Q1 + v10;
printf(
"%012.3fms: Packet p%d leaves Q1, time in Q1: %.3fms, token bucket now has %d tokens\n",
(v9 - *(double *)&t1) * 1000.0,
v8,
v10 * 1000.0,
(unsigned int)token_counter);
*((_QWORD *)v4 + 5) = t9;
My402ListAppend(&Queue_two, v4);
pthread_cond_signal(&signal_server);
gettimeofday(&tim, 0LL);
v11 = *(unsigned int *)v4;
*(double *)&t10 = (double)(int)tim.tv_usec / 1000000.0 + (double)SLODWORD(tim.tv_sec);
printf("%012.3fms: Packet p%d enters Q2\n", (*(double *)&t10 - *(double *)&t1) * 1000.0, v11);
}
pthread_mutex_unlock(&mut_lock);
}
while ( packet_count_Q1exit != num_afterdrop );
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func0(void *a1)
{
__useconds_t v1; // ebx
double v2; // xmm0_8
double **v3; // rax
double *v4; // r12
double **v5; // rbp
int v6; // edx
__int64 v8; // rsi
double v9; // xmm0_8
double v10; // xmm1_8
__int64 v11; // rsi

v1 = (int)(1000.0 / *(double *)&r * 1000.0);
do
{
while ( 1 )
{
usleep(v1);
gettimeofday(&tim, 0LL);
v2 = (double)(int)tim.tv_usec / 1000000.0 + (double)SLODWORD(tim.tv_sec);
*(double *)&t7 = v2;
if ( B > token_counter )
break;
printf("%012.3fms: Token t%d arrives, dropped\n", (v2 - *(double *)&t1) * 1000.0, (unsigned int)token_no);
++drop_tokens;
++token_no;
LABEL_3:
if ( packet_count_Q1exit == num_afterdrop )
return 0LL;
}
pthread_mutex_lock(&mut_lock);
printf(
"%012.3fms: Token t%d arrives, token bucket now has %d tokens\n",
(*(double *)&t7 - *(double *)&t1) * 1000.0,
(unsigned int)++token_no,
(unsigned int)++token_counter);
pthread_mutex_unlock(&mut_lock);
if ( (unsigned int)My402ListEmpty(&Queue_one) )
goto LABEL_3;
v3 = (double **)My402ListFirst(&Queue_one);
v4 = *v3;
v5 = v3;
pthread_mutex_lock(&mut_lock);
v6 = *((_DWORD *)v4 + 4);
if ( v6 <= token_counter )
{
token_counter -= v6;
My402ListUnlink(&Queue_one, v5);
++packet_count_Q1exit;
gettimeofday(&tim, 0LL);
v8 = *(unsigned int *)v4;
v9 = (double)(int)tim.tv_usec / 1000000.0 + (double)SLODWORD(tim.tv_sec);
v10 = v9 - v4[4];
*(double *)&t9 = v9;
*(double *)&time_in_Q1 = *(double *)&time_in_Q1 + v10;
printf(
"%012.3fms: Packet p%d leaves Q1, time in Q1: %.3fms, token bucket now has %d tokens\n",
(v9 - *(double *)&t1) * 1000.0,
v8,
v10 * 1000.0,
(unsigned int)token_counter);
*((_QWORD *)v4 + 5) = t9;
My402ListAppend(&Queue_two, v4);
pthread_cond_signal(&signal_server);
gettimeofday(&tim, 0LL);
v11 = *(unsigned int *)v4;
*(double *)&t10 = (double)(int)tim.tv_usec / 1000000.0 + (double)SLODWORD(tim.tv_sec);
printf("%012.3fms: Packet p%d enters Q2\n", (*(double *)&t10 - *(double *)&t1) * 1000.0, v11);
}
pthread_mutex_unlock(&mut_lock);
}
while ( packet_count_Q1exit != num_afterdrop );
return 0LL;
}

original_code:
void *token_bucket_func()
{
 My402ListElem *Queue1_elem = ((void *)0);
 MyPacketInfo *Queue1_head_data = ((void *)0);
 double token_arrival = (1000/r);
 double token_sleep = token_arrival *1000;
 int token_sleep1 = (int)token_sleep;
 while(1)
 {
   usleep(token_sleep1);
   gettimeofday(&tim,((void *)0));
   t7 = tim.tv_sec + (tim.tv_usec)/1000000.0;
   if ( token_counter > (B-1) )
   {
    printf("%012.3fms: Token t%d arrives, dropped\n",(t7-t1)*1000,token_no);
    drop_tokens ++;
    token_no ++;
   }
   else
   {
    pthread_mutex_lock(&mut_lock);
    token_counter ++;
    token_no ++;
    printf("%012.3fms: Token t%d arrives, token bucket now has %d tokens\n", (t7-t1)*1000, token_no, token_counter);
    pthread_mutex_unlock(&mut_lock);
    if(!My402ListEmpty(&Queue_one))
    {
     Queue1_elem = My402ListFirst(&Queue_one);
     Queue1_head_data = (MyPacketInfo*)Queue1_elem->obj;
     pthread_mutex_lock(&mut_lock);
     if ( Queue1_head_data->P <= token_counter )
     {
      token_counter = token_counter - Queue1_head_data->P;
      My402ListUnlink(&Queue_one, Queue1_elem);
      packet_count_Q1exit ++;
      gettimeofday(&tim,((void *)0));
      t9 = tim.tv_sec + (tim.tv_usec)/1000000.0;
      double time_Q1 = (t9-Queue1_head_data->Q1_entry_time);
      time_in_Q1 = time_in_Q1 + time_Q1;
      printf("%012.3fms: Packet p%d leaves Q1, time in Q1: %.3fms, token bucket now has %d tokens\n",(t9-t1)*1000, Queue1_head_data->packet_no, (t9-(Queue1_head_data->Q1_entry_time))*1000, token_counter);
      Queue1_head_data->Q2_entry_time = t9;
      My402ListAppend(&Queue_two,(void*)Queue1_head_data);
      pthread_cond_signal(&signal_server);
      gettimeofday(&tim,((void *)0));
      t10 = tim.tv_sec + (tim.tv_usec)/1000000.0;
      printf("%012.3fms: Packet p%d enters Q2\n", (t10-t1)*1000, Queue1_head_data->packet_no);
     }
     pthread_mutex_unlock(&mut_lock);
    }
   }
   if( packet_count_Q1exit == num_afterdrop )
   {
    break;
   }
 }
 return 0;
}

canonical_original_code:
void *token_bucket_func()
{
 struct tagMy402ListElem *Queue1_elem = ((void *)0);
 struct myPacketInfoStructure *Queue1_head_data = ((void *)0);
 double token_arrival = (1000/r);
 double token_sleep = token_arrival *1000;
 int token_sleep1 = (int)token_sleep;
 while(1)
 {
   usleep(token_sleep1);
   gettimeofday(&tim,((void *)0));
   t7 = tim.tv_sec + (tim.tv_usec)/1000000.0;
   if ( token_counter > (B-1) )
   {
    printf("%012.3fms: Token t%d arrives, dropped\n",(t7-t1)*1000,token_no);
    drop_tokens ++;
    token_no ++;
   }
   else
   {
    pthread_mutex_lock(&mut_lock);
    token_counter ++;
    token_no ++;
    printf("%012.3fms: Token t%d arrives, token bucket now has %d tokens\n", (t7-t1)*1000, token_no, token_counter);
    pthread_mutex_unlock(&mut_lock);
    if(!My402ListEmpty(&Queue_one))
    {
     Queue1_elem = My402ListFirst(&Queue_one);
     Queue1_head_data = (struct myPacketInfoStructure *)Queue1_elem->obj;
     pthread_mutex_lock(&mut_lock);
     if ( Queue1_head_data->P <= token_counter )
     {
      token_counter = token_counter - Queue1_head_data->P;
      My402ListUnlink(&Queue_one, Queue1_elem);
      packet_count_Q1exit ++;
      gettimeofday(&tim,((void *)0));
      t9 = tim.tv_sec + (tim.tv_usec)/1000000.0;
      double time_Q1 = (t9-Queue1_head_data->Q1_entry_time);
      time_in_Q1 = time_in_Q1 + time_Q1;
      printf("%012.3fms: Packet p%d leaves Q1, time in Q1: %.3fms, token bucket now has %d tokens\n",(t9-t1)*1000, Queue1_head_data->packet_no, (t9-(Queue1_head_data->Q1_entry_time))*1000, token_counter);
      Queue1_head_data->Q2_entry_time = t9;
      My402ListAppend(&Queue_two,(void *)Queue1_head_data);
      pthread_cond_signal(&signal_server);
      gettimeofday(&tim,((void *)0));
      t10 = tim.tv_sec + (tim.tv_usec)/1000000.0;
      printf("%012.3fms: Packet p%d enters Q2\n", (t10-t1)*1000, Queue1_head_data->packet_no);
     }
     pthread_mutex_unlock(&mut_lock);
    }
   }
   if( packet_count_Q1exit == num_afterdrop )
   {
    break;
   }
 }
 return 0;
}

variable_types: struct tagMy402ListElem { void *obj; struct tagMy402ListElem *next; struct tagMy402ListElem *prev; } *

variable_types: struct myPacketInfoStructure { int packet_no; double pkt_arrival; int P; double pkt_service; double Q1_entry_time; double Q2_entry_time; } *


decompiled_code:
void *__fastcall server_func(void *a1)
{
double **v1; // rax
double *v2; // rbx
__int64 v3; // rsi
__useconds_t v4; // ebp
__int64 v5; // rsi
double v6; // xmm0_8
double v7; // xmm2_8

do
{
pthread_mutex_lock(&mut_lock);
if ( (unsigned int)My402ListEmpty(&Queue_two) )
pthread_cond_wait(&signal_server, &mut_lock);
v1 = (double **)My402ListFirst(&Queue_two);
v2 = *v1;
My402ListUnlink(&Queue_two, v1);
gettimeofday(&tim, 0LL);
v3 = *(unsigned int *)v2;
*(double *)&t14 = (double)(int)tim.tv_usec / 1000000.0 + (double)SLODWORD(tim.tv_sec);
printf(
"%012.3fms: Packet p%d begins service at S, time in Q2 = %.3fms\n",
(*(double *)&t14 - *(double *)&t1) * 1000.0,
v3,
(*(double *)&t14 - v2[5]) * 1000.0);
*(double *)&time_in_Q2 = *(double *)&t14 - v2[5] + *(double *)&time_in_Q2;
gettimeofday(&tim, 0LL);
++packet_count_Q2exit;
*(double *)&t12 = (double)(int)tim.tv_usec / 1000000.0 + (double)SLODWORD(tim.tv_sec);
v4 = (int)(1000.0 * v2[3]);
pthread_mutex_unlock(&mut_lock);
usleep(v4);
gettimeofday(&tim, 0LL);
v5 = *(unsigned int *)v2;
v6 = (double)(int)tim.tv_usec / 1000000.0;
++server_count;
*(double *)&t8 = v6 + (double)SLODWORD(tim.tv_sec);
v7 = *(double *)&t8 - v2[4];
*(double *)&service_time = *(double *)&t8 - *(double *)&t12 + *(double *)&service_time;
*(double *)&time_in_sys = *(double *)&time_in_sys + v7;
*(double *)&time_sd = v7 * v7 / (double)(server_count * server_count) + *(double *)&time_sd;
printf(
"%012.3fms: Packet p%d departs S, service time: %.3fms, time in system: %.3fms\n",
(*(double *)&t8 - *(double *)&t1) * 1000.0,
v5,
v2[3],
v7 * 1000.0);
*(double *)&time_in_S = *(double *)&t8 - *(double *)&t12 + *(double *)&time_in_S;
}
while ( packet_count_Q2exit != num_afterdrop && packet_Q1enter );
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func1(void *a1)
{
double **v1; // rax
double *v2; // rbx
__int64 v3; // rsi
__useconds_t v4; // ebp
__int64 v5; // rsi
double v6; // xmm0_8
double v7; // xmm2_8

do
{
pthread_mutex_lock(&mut_lock);
if ( (unsigned int)My402ListEmpty(&Queue_two) )
pthread_cond_wait(&signal_server, &mut_lock);
v1 = (double **)My402ListFirst(&Queue_two);
v2 = *v1;
My402ListUnlink(&Queue_two, v1);
gettimeofday(&tim, 0LL);
v3 = *(unsigned int *)v2;
*(double *)&t14 = (double)(int)tim.tv_usec / 1000000.0 + (double)SLODWORD(tim.tv_sec);
printf(
"%012.3fms: Packet p%d begins service at S, time in Q2 = %.3fms\n",
(*(double *)&t14 - *(double *)&t1) * 1000.0,
v3,
(*(double *)&t14 - v2[5]) * 1000.0);
*(double *)&time_in_Q2 = *(double *)&t14 - v2[5] + *(double *)&time_in_Q2;
gettimeofday(&tim, 0LL);
++packet_count_Q2exit;
*(double *)&t12 = (double)(int)tim.tv_usec / 1000000.0 + (double)SLODWORD(tim.tv_sec);
v4 = (int)(1000.0 * v2[3]);
pthread_mutex_unlock(&mut_lock);
usleep(v4);
gettimeofday(&tim, 0LL);
v5 = *(unsigned int *)v2;
v6 = (double)(int)tim.tv_usec / 1000000.0;
++server_count;
*(double *)&t8 = v6 + (double)SLODWORD(tim.tv_sec);
v7 = *(double *)&t8 - v2[4];
*(double *)&service_time = *(double *)&t8 - *(double *)&t12 + *(double *)&service_time;
*(double *)&time_in_sys = *(double *)&time_in_sys + v7;
*(double *)&time_sd = v7 * v7 / (double)(server_count * server_count) + *(double *)&time_sd;
printf(
"%012.3fms: Packet p%d departs S, service time: %.3fms, time in system: %.3fms\n",
(*(double *)&t8 - *(double *)&t1) * 1000.0,
v5,
v2[3],
v7 * 1000.0);
*(double *)&time_in_S = *(double *)&t8 - *(double *)&t12 + *(double *)&time_in_S;
}
while ( packet_count_Q2exit != num_afterdrop && packet_Q1enter );
return 0LL;
}

original_code:
void *server_func()
{
 while(1)
 {
  pthread_mutex_lock(&mut_lock);
  if (My402ListEmpty(&Queue_two))
   pthread_cond_wait(&signal_server, &mut_lock);
  My402ListElem *Queue2_elem = ((void *)0);
  MyPacketInfo *Q2_head_data = ((void *)0);
  Queue2_elem = My402ListFirst(&Queue_two);
  Q2_head_data = (MyPacketInfo*)Queue2_elem->obj;
  My402ListUnlink(&Queue_two, Queue2_elem);
  gettimeofday(&tim,((void *)0));
  t14 = tim.tv_sec + (tim.tv_usec)/1000000.0;
  printf("%012.3fms: Packet p%d begins service at S, time in Q2 = %.3fms\n",(t14-t1)*1000, Q2_head_data->packet_no, (t14-(Q2_head_data->Q2_entry_time))*1000);
  double time_Q2 = (t14-Q2_head_data->Q2_entry_time);
  time_in_Q2 = time_in_Q2 + time_Q2;
  gettimeofday(&tim,((void *)0));
  t12 = tim.tv_sec + (tim.tv_usec)/1000000.0;
  packet_count_Q2exit ++;
  double server_sleep = (Q2_head_data->pkt_service) * 1000;
  int server_sleep1 = (int)server_sleep;
  pthread_mutex_unlock(&mut_lock);
  usleep(server_sleep1);
  gettimeofday(&tim,((void *)0));
  t8 = tim.tv_sec + (tim.tv_usec)/1000000.0;
  double serv_time = t8-t12;
  service_time = service_time + serv_time;
  server_count ++;
  double time_sys = (t8-(Q2_head_data->Q1_entry_time));
  time_in_sys = time_in_sys + time_sys;
  time_sd = time_sd + (( time_sys * time_sys )/( server_count * server_count ));
  printf("%012.3fms: Packet p%d departs S, service time: %.3fms, time in system: %.3fms\n",(t8-t1)*1000, Q2_head_data->packet_no, Q2_head_data->pkt_service,(t8-(Q2_head_data->Q1_entry_time))*1000);
  double time_S = (t8-t12);
  time_in_S = time_in_S + time_S;
  if( packet_count_Q2exit == num_afterdrop )
  {
   break;
  }
  else if( packet_Q1enter == 0)
  {
   break;
  }
 }
 return 0;
}

canonical_original_code:
void *server_func()
{
 while(1)
 {
  pthread_mutex_lock(&mut_lock);
  if (My402ListEmpty(&Queue_two))
   pthread_cond_wait(&signal_server, &mut_lock);
  struct tagMy402ListElem *Queue2_elem = ((void *)0);
  struct myPacketInfoStructure *Q2_head_data = ((void *)0);
  Queue2_elem = My402ListFirst(&Queue_two);
  Q2_head_data = (struct myPacketInfoStructure *)Queue2_elem->obj;
  My402ListUnlink(&Queue_two, Queue2_elem);
  gettimeofday(&tim,((void *)0));
  t14 = tim.tv_sec + (tim.tv_usec)/1000000.0;
  printf("%012.3fms: Packet p%d begins service at S, time in Q2 = %.3fms\n",(t14-t1)*1000, Q2_head_data->packet_no, (t14-(Q2_head_data->Q2_entry_time))*1000);
  double time_Q2 = (t14-Q2_head_data->Q2_entry_time);
  time_in_Q2 = time_in_Q2 + time_Q2;
  gettimeofday(&tim,((void *)0));
  t12 = tim.tv_sec + (tim.tv_usec)/1000000.0;
  packet_count_Q2exit ++;
  double server_sleep = (Q2_head_data->pkt_service) * 1000;
  int server_sleep1 = (int)server_sleep;
  pthread_mutex_unlock(&mut_lock);
  usleep(server_sleep1);
  gettimeofday(&tim,((void *)0));
  t8 = tim.tv_sec + (tim.tv_usec)/1000000.0;
  double serv_time = t8-t12;
  service_time = service_time + serv_time;
  server_count ++;
  double time_sys = (t8-(Q2_head_data->Q1_entry_time));
  time_in_sys = time_in_sys + time_sys;
  time_sd = time_sd + (( time_sys * time_sys )/( server_count * server_count ));
  printf("%012.3fms: Packet p%d departs S, service time: %.3fms, time in system: %.3fms\n",(t8-t1)*1000, Q2_head_data->packet_no, Q2_head_data->pkt_service,(t8-(Q2_head_data->Q1_entry_time))*1000);
  double time_S = (t8-t12);
  time_in_S = time_in_S + time_S;
  if( packet_count_Q2exit == num_afterdrop )
  {
   break;
  }
  else if( packet_Q1enter == 0)
  {
   break;
  }
 }
 return 0;
}

return_type: void *

user_defined_types: struct tagMy402ListElem { void *obj; struct tagMy402ListElem *next; struct tagMy402ListElem *prev; }

user_defined_types: struct myPacketInfoStructure { int packet_no; double pkt_arrival; int P; double pkt_service; double Q1_entry_time; double Q2_entry_time; }


decompiled_code:
void *__fastcall server_termination_func(void *a1)
{
pthread_mutex_lock(&mut_lock2);
pthread_cond_wait(&terminate_server, &mut_lock2);
pthread_mutex_unlock(&mut_lock2);
if ( pthread_cancel(server_thread) || pthread_cancel(token_thread) )
{
fwrite("Pthread_cancel failed\n", 1uLL, 0x16uLL, stderr);
exit(1);
}
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func2(void *a1)
{
pthread_mutex_lock(&mut_lock2);
pthread_cond_wait(&terminate_server, &mut_lock2);
pthread_mutex_unlock(&mut_lock2);
if ( pthread_cancel(server_thread) || pthread_cancel(token_thread) )
{
fwrite("Pthread_cancel failed\n", 1uLL, 0x16uLL, stderr);
exit(1);
}
return 0LL;
}

original_code:
void *server_termination_func()
{
 pthread_mutex_lock(&mut_lock2);
 pthread_cond_wait(&terminate_server,&mut_lock2);
 pthread_mutex_unlock(&mut_lock2);
  int ret5 = pthread_cancel(server_thread);
  if( ret5 != 0 )
  {
   fprintf(stderr,"Pthread_cancel failed\n");
   exit(1);
  }
  int ret6 = pthread_cancel(token_thread);
  if ( ret6 != 0 )
  {
   fprintf(stderr, "Pthread_cancel failed\n");
   exit(1);
  }
  return 0;
}


decompiled_code:
_DWORD *make_packets()
{
_DWORD *result; // rax
double v1; // xmm2_8
double v2; // xmm3_8
int v3; // edx
char *v4; // rax
char **v5; // rbx
int v6; // ebx
int v7; // edx
double v8; // [rsp+0h] [rbp-28h]
double v9; // [rsp+8h] [rbp-20h]
char delim[11]; // [rsp+1Dh] [rbp-Bh] BYREF

if ( file_flag == 1 )
{
strcpy(delim, " \t");
fgets(buf, 1026, fp);
v4 = strtok(buf, delim);
str = (__int64)v4;
if ( v4 )
{
v5 = &a;
do
{
*v5++ = v4;
v4 = strtok(0LL, delim);
str = (__int64)v4;
}
while ( v4 );
}
v9 = atof(a);
v6 = atoi(*(&a + 1));
v8 = atof(*(&a + 2));
result = malloc(0x30uLL);
Queue_data = (__int64)result;
v7 = packet_no + 1;
result[4] = v6;
packet_no = v7;
*result = v7;
*((_QWORD *)result + 4) = 0LL;
*((_QWORD *)result + 5) = 0LL;
*((double *)result + 1) = v9;
*((double *)result + 3) = v8;
}
else
{
result = malloc(0x30uLL);
Queue_data = (__int64)result;
v1 = fmin(10000.0, 1000.0 / *(double *)&mu);
v2 = fmin(10000.0, 1000.0 / *(double *)&lambda);
*result = ++packet_no;
v3 = P;
*((_QWORD *)result + 4) = 0LL;
result[4] = v3;
*((_QWORD *)result + 5) = 0LL;
*((double *)result + 1) = v2;
*((double *)result + 3) = v1;
}
return result;
}

canonical_decompiled_code:
_DWORD *func3()
{
_DWORD *result; // rax
double v1; // xmm2_8
double v2; // xmm3_8
int v3; // edx
char *v4; // rax
char **v5; // rbx
int v6; // ebx
int v7; // edx
double v8; // [rsp+0h] [rbp-28h]
double v9; // [rsp+8h] [rbp-20h]
char delim[11]; // [rsp+1Dh] [rbp-Bh] BYREF

if ( file_flag == 1 )
{
strcpy(delim, " \t");
fgets(buf, 1026, fp);
v4 = strtok(buf, delim);
str = (__int64)v4;
if ( v4 )
{
v5 = &a;
do
{
*v5++ = v4;
v4 = strtok(0LL, delim);
str = (__int64)v4;
}
while ( v4 );
}
v9 = atof(a);
v6 = atoi(*(&a + 1));
v8 = atof(*(&a + 2));
result = malloc(0x30uLL);
Queue_data = (__int64)result;
v7 = packet_no + 1;
result[4] = v6;
packet_no = v7;
*result = v7;
*((_QWORD *)result + 4) = 0LL;
*((_QWORD *)result + 5) = 0LL;
*((double *)result + 1) = v9;
*((double *)result + 3) = v8;
}
else
{
result = malloc(0x30uLL);
Queue_data = (__int64)result;
v1 = fmin(10000.0, 1000.0 / *(double *)&mu);
v2 = fmin(10000.0, 1000.0 / *(double *)&lambda);
*result = ++packet_no;
v3 = P;
*((_QWORD *)result + 4) = 0LL;
result[4] = v3;
*((_QWORD *)result + 5) = 0LL;
*((double *)result + 1) = v2;
*((double *)result + 3) = v1;
}
return result;
}

original_code:
void make_packets()
{
 if( file_flag == 1)
 {
  int j = 0;
  char delim[] = " \t";
  fgets( buf, sizeof(buf), fp );
  str = strtok(buf,delim);
  while( str != ((void *)0))
  {
   a[j] = str;
   j++;
   str = strtok( ((void *)0),delim);
  }
  char *p_a = a[0];
  char *r_t = a[1];
  char *p_s = a[2];
  double pkt_arr = atof(p_a);
  int token_req = atoi(r_t);
  double pkt_ser = atof(p_s);
  Queue_data = (MyPacketInfo*)malloc(sizeof(MyPacketInfo));
  packet_no = packet_no + 1;
  Queue_data->packet_no = packet_no;
  Queue_data->pkt_arrival = pkt_arr;
  Queue_data->P = token_req;
  Queue_data->pkt_service = pkt_ser;
  Queue_data->Q1_entry_time = 0.0;
  Queue_data->Q2_entry_time = 0.0;
 }
 else
 {
  Queue_data = (MyPacketInfo*)malloc(sizeof(MyPacketInfo));
  packet_no = packet_no + 1;
  Queue_data->packet_no = packet_no;
  double packet_arr = (1000)/lambda;
  if( packet_arr > 10000 )
  {
   packet_arr = 10000.0;
  }
  Queue_data->pkt_arrival = packet_arr;
  Queue_data->P = P;
  double s_time = (1000)/mu;
  if( s_time > 10000 )
  {
   s_time = 10000.0;
  }
  Queue_data->pkt_service = s_time;
  Queue_data->Q1_entry_time = 0.0;
  Queue_data->Q2_entry_time = 0.0;
 }
}

canonical_original_code:
void make_packets()
{
 if( file_flag == 1)
 {
  int j = 0;
  char delim[] = " \t";
  fgets( buf, sizeof(buf), fp );
  str = strtok(buf,delim);
  while( str != ((void *)0))
  {
   a[j] = str;
   j++;
   str = strtok( ((void *)0),delim);
  }
  char *p_a = a[0];
  char *r_t = a[1];
  char *p_s = a[2];
  double pkt_arr = atof(p_a);
  int token_req = atoi(r_t);
  double pkt_ser = atof(p_s);
  Queue_data = (struct myPacketInfoStructure *)malloc(sizeof(MyPacketInfo));
  packet_no = packet_no + 1;
  Queue_data->packet_no = packet_no;
  Queue_data->pkt_arrival = pkt_arr;
  Queue_data->P = token_req;
  Queue_data->pkt_service = pkt_ser;
  Queue_data->Q1_entry_time = 0.0;
  Queue_data->Q2_entry_time = 0.0;
 }
 else
 {
  Queue_data = (struct myPacketInfoStructure *)malloc(sizeof(MyPacketInfo));
  packet_no = packet_no + 1;
  Queue_data->packet_no = packet_no;
  double packet_arr = (1000)/lambda;
  if( packet_arr > 10000 )
  {
   packet_arr = 10000.0;
  }
  Queue_data->pkt_arrival = packet_arr;
  Queue_data->P = P;
  double s_time = (1000)/mu;
  if( s_time > 10000 )
  {
   s_time = 10000.0;
  }
  Queue_data->pkt_service = s_time;
  Queue_data->Q1_entry_time = 0.0;
  Queue_data->Q2_entry_time = 0.0;
 }
}

variable_types: j int

variable_types:
delim
char []

return_type: void


decompiled_code:
void *__fastcall packet_arrival(void *a1)
{
unsigned int *v1; // rax
__int64 v2; // rdx
bool v3; // cc
double v4; // xmm0_8
double v5; // xmm1_8
double v6; // xmm0_8
__int64 v7; // rsi
double **v8; // rax
double *v9; // rbx
double **v10; // rbp
int v11; // edx
__int64 v12; // rsi
double v13; // xmm0_8
double v14; // xmm1_8
__int64 v15; // rsi
void *result; // rax

i = 1;
num_afterdrop = num;
if ( num > 0 )
{
do
{
make_packets();
gettimeofday(&tim, 0LL);
*(double *)&t2 = (double)(int)tim.tv_usec / 1000000.0 + (double)SLODWORD(tim.tv_sec);
usleep((int)(1000.0 * *(double *)(Queue_data + 8)));
gettimeofday(&tim, 0LL);
v1 = (unsigned int *)Queue_data;
v2 = *(unsigned int *)(Queue_data + 16);
v3 = (int)v2 <= B;
v4 = (double)(int)tim.tv_usec / 1000000.0 + (double)SLODWORD(tim.tv_sec);
v5 = v4 - *(double *)&t2;
*(double *)(Queue_data + 32) = v4;
t3 = *(_QWORD *)&v4;
v6 = (v4 - *(double *)&t1) * 1000.0;
*(double *)&interarr_time = v5 + *(double *)&interarr_time;
if ( v3 )
{
printf(
"%012.3fms: Packet p%d arives, needs %d tokens, inter-arrival time: %.3f\n",
v6,
*v1,
v2,
*((double *)v1 + 1));
My402ListAppend(&Queue_one, Queue_data);
++packet_Q1enter;
gettimeofday(&tim, 0LL);
v7 = *(unsigned int *)Queue_data;
*(double *)&t4 = (double)(int)tim.tv_usec / 1000000.0 + (double)SLODWORD(tim.tv_sec);
printf("%012.3fms: Packet p%d enters Q1\n", (*(double *)&t4 - *(double *)&t1) * 1000.0, v7);
v8 = (double **)My402ListFirst(&Queue_one);
v9 = *v8;
v10 = v8;
pthread_mutex_lock(&mut_lock);
v11 = *((_DWORD *)v9 + 4);
if ( v11 <= token_counter )
{
token_counter -= v11;
My402ListUnlink(&Queue_one, v10);
++packet_count_Q1exit;
gettimeofday(&tim, 0LL);
v12 = *(unsigned int *)v9;
v13 = (double)(int)tim.tv_usec / 1000000.0 + (double)SLODWORD(tim.tv_sec);
v14 = v13 - v9[4];
*(double *)&t5 = v13;
*(double *)&time_in_Q1 = *(double *)&time_in_Q1 + v14;
printf(
"%012.3fms: Packet p%d leaves Q1, time in Q1: %.3fms, token bucket now has %d tokens\n",
(v13 - *(double *)&t1) * 1000.0,
v12,
v14 * 1000.0,
(unsigned int)token_counter);
*((_QWORD *)v9 + 5) = t5;
My402ListAppend(&Queue_two, v9);
pthread_cond_signal(&signal_server);
gettimeofday(&tim, 0LL);
v15 = *(unsigned int *)v9;
*(double *)&t6 = (double)(int)tim.tv_usec / 1000000.0 + (double)SLODWORD(tim.tv_sec);
printf("%012.3fms: Packet p%d enters Q2\n", (*(double *)&t6 - *(double *)&t1) * 1000.0, v15);
}
pthread_mutex_unlock(&mut_lock);
}
else
{
printf("%012.3fms: Packet p%d arrives, needs %d tokens, dropped\n", v6, *v1, v2);
--num_afterdrop;
pthread_mutex_lock(&mut_lock2);
++drop_packets;
pthread_mutex_unlock(&mut_lock2);
}
++i;
}
while ( i <= num );
}
pthread_mutex_lock(&mut_lock2);
drop_pkts = drop_packets;
if ( drop_packets == num )
{
pthread_mutex_unlock(&mut_lock2);
pthread_cond_signal(&terminate_server);
result = 0LL;
}
else
{
pthread_mutex_unlock(&mut_lock2);
if ( pthread_cancel(end_server) )
{
fwrite("Pthread_cancel failed\n", 1uLL, 0x16uLL, stderr);
exit(1);
}
result = 0LL;
}
return result;
}

canonical_decompiled_code:
void *__fastcall func4(void *a1)
{
unsigned int *v1; // rax
__int64 v2; // rdx
bool v3; // cc
double v4; // xmm0_8
double v5; // xmm1_8
double v6; // xmm0_8
__int64 v7; // rsi
double **v8; // rax
double *v9; // rbx
double **v10; // rbp
int v11; // edx
__int64 v12; // rsi
double v13; // xmm0_8
double v14; // xmm1_8
__int64 v15; // rsi
void *result; // rax

i = 1;
num_afterdrop = num;
if ( num > 0 )
{
do
{
func3();
gettimeofday(&tim, 0LL);
*(double *)&t2 = (double)(int)tim.tv_usec / 1000000.0 + (double)SLODWORD(tim.tv_sec);
usleep((int)(1000.0 * *(double *)(Queue_data + 8)));
gettimeofday(&tim, 0LL);
v1 = (unsigned int *)Queue_data;
v2 = *(unsigned int *)(Queue_data + 16);
v3 = (int)v2 <= B;
v4 = (double)(int)tim.tv_usec / 1000000.0 + (double)SLODWORD(tim.tv_sec);
v5 = v4 - *(double *)&t2;
*(double *)(Queue_data + 32) = v4;
t3 = *(_QWORD *)&v4;
v6 = (v4 - *(double *)&t1) * 1000.0;
*(double *)&interarr_time = v5 + *(double *)&interarr_time;
if ( v3 )
{
printf(
"%012.3fms: Packet p%d arives, needs %d tokens, inter-arrival time: %.3f\n",
v6,
*v1,
v2,
*((double *)v1 + 1));
My402ListAppend(&Queue_one, Queue_data);
++packet_Q1enter;
gettimeofday(&tim, 0LL);
v7 = *(unsigned int *)Queue_data;
*(double *)&t4 = (double)(int)tim.tv_usec / 1000000.0 + (double)SLODWORD(tim.tv_sec);
printf("%012.3fms: Packet p%d enters Q1\n", (*(double *)&t4 - *(double *)&t1) * 1000.0, v7);
v8 = (double **)My402ListFirst(&Queue_one);
v9 = *v8;
v10 = v8;
pthread_mutex_lock(&mut_lock);
v11 = *((_DWORD *)v9 + 4);
if ( v11 <= token_counter )
{
token_counter -= v11;
My402ListUnlink(&Queue_one, v10);
++packet_count_Q1exit;
gettimeofday(&tim, 0LL);
v12 = *(unsigned int *)v9;
v13 = (double)(int)tim.tv_usec / 1000000.0 + (double)SLODWORD(tim.tv_sec);
v14 = v13 - v9[4];
*(double *)&t5 = v13;
*(double *)&time_in_Q1 = *(double *)&time_in_Q1 + v14;
printf(
"%012.3fms: Packet p%d leaves Q1, time in Q1: %.3fms, token bucket now has %d tokens\n",
(v13 - *(double *)&t1) * 1000.0,
v12,
v14 * 1000.0,
(unsigned int)token_counter);
*((_QWORD *)v9 + 5) = t5;
My402ListAppend(&Queue_two, v9);
pthread_cond_signal(&signal_server);
gettimeofday(&tim, 0LL);
v15 = *(unsigned int *)v9;
*(double *)&t6 = (double)(int)tim.tv_usec / 1000000.0 + (double)SLODWORD(tim.tv_sec);
printf("%012.3fms: Packet p%d enters Q2\n", (*(double *)&t6 - *(double *)&t1) * 1000.0, v15);
}
pthread_mutex_unlock(&mut_lock);
}
else
{
printf("%012.3fms: Packet p%d arrives, needs %d tokens, dropped\n", v6, *v1, v2);
--num_afterdrop;
pthread_mutex_lock(&mut_lock2);
++drop_packets;
pthread_mutex_unlock(&mut_lock2);
}
++i;
}
while ( i <= num );
}
pthread_mutex_lock(&mut_lock2);
drop_pkts = drop_packets;
if ( drop_packets == num )
{
pthread_mutex_unlock(&mut_lock2);
pthread_cond_signal(&terminate_server);
result = 0LL;
}
else
{
pthread_mutex_unlock(&mut_lock2);
if ( pthread_cancel(end_server) )
{
fwrite("Pthread_cancel failed\n", 1uLL, 0x16uLL, stderr);
exit(1);
}
result = 0LL;
}
return result;
}

original_code:
void *packet_arrival()
{
 My402ListElem *Queue_elem = ((void *)0);
 MyPacketInfo *Q1_head_data = ((void *)0);
 num_afterdrop = num;
 for ( i = 1 ; i <= num ; i++)
 {
  make_packets();
  gettimeofday(&tim,((void *)0));
  t2 = tim.tv_sec + (tim.tv_usec)/1000000.0;
  double arrival_sleep = (Queue_data->pkt_arrival)*1000;
  int arrival_sleep1 = (int)arrival_sleep;
  usleep(arrival_sleep1);
  gettimeofday(&tim,((void *)0));
  t3 = tim.tv_sec + (tim.tv_usec)/1000000.0;
  Queue_data->Q1_entry_time = t3;
  double inter_time = (t3-t2);
  interarr_time = interarr_time + inter_time;
  if ( Queue_data->P > B )
  {
   printf("%012.3fms: Packet p%d arrives, needs %d tokens, dropped\n", (t3-t1)*1000, Queue_data->packet_no, Queue_data->P);
   num_afterdrop --;
   pthread_mutex_lock(&mut_lock2);
   drop_packets ++;
   pthread_mutex_unlock(&mut_lock2);
  }
  else
  {
     printf("%012.3fms: Packet p%d arives, needs %d tokens, inter-arrival time: %.3f\n",(t3-t1)*1000, Queue_data->packet_no, Queue_data->P, Queue_data->pkt_arrival );
     My402ListAppend(&Queue_one, (void*)Queue_data);
     packet_Q1enter ++;
     gettimeofday(&tim,((void *)0));
     t4 = tim.tv_sec + (tim.tv_usec)/1000000.0;
     printf("%012.3fms: Packet p%d enters Q1\n",(t4-t1)*1000, Queue_data->packet_no);
     Queue_elem = My402ListFirst(&Queue_one);
     Q1_head_data = (MyPacketInfo*)Queue_elem->obj;
     pthread_mutex_lock(&mut_lock);
     if ( Q1_head_data->P <= token_counter )
     {
      token_counter = token_counter - Q1_head_data->P;
      My402ListUnlink(&Queue_one, Queue_elem);
      packet_count_Q1exit ++;
      gettimeofday(&tim,((void *)0));
      t5 = tim.tv_sec + (tim.tv_usec)/1000000.0;
      double time_Q1 = (t5-Q1_head_data->Q1_entry_time);
      time_in_Q1 = time_in_Q1 + time_Q1;
      printf("%012.3fms: Packet p%d leaves Q1, time in Q1: %.3fms, token bucket now has %d tokens\n",(t5-t1)*1000, Q1_head_data->packet_no, (t5-(Q1_head_data->Q1_entry_time))*1000, token_counter);
      Q1_head_data->Q2_entry_time = t5;
      My402ListAppend(&Queue_two,(void*)Q1_head_data);
      pthread_cond_signal(&signal_server);
      gettimeofday(&tim,((void *)0));
      t6 = tim.tv_sec + (tim.tv_usec)/1000000.0;
      printf("%012.3fms: Packet p%d enters Q2\n", (t6-t1)*1000, Q1_head_data->packet_no);
     }
     pthread_mutex_unlock(&mut_lock);
  }
 }
 pthread_mutex_lock(&mut_lock2);
 drop_pkts = drop_packets;
 if ( drop_pkts == num )
 {
  pthread_mutex_unlock(&mut_lock2);
  pthread_cond_signal(&terminate_server);
 }
 else
 {
  pthread_mutex_unlock(&mut_lock2);
  int ret7 = pthread_cancel(end_server);
  if( ret7 != 0 )
  {
   fprintf(stderr,"Pthread_cancel failed\n");
   exit(1);
  }
 }
 return 0;
}

canonical_original_code:
void *packet_arrival()
{
 struct tagMy402ListElem *Queue_elem = ((void *)0);
 struct myPacketInfoStructure *Q1_head_data = ((void *)0);
 num_afterdrop = num;
 for ( i = 1 ; i <= num ; i++)
 {
  make_packets();
  gettimeofday(&tim,((void *)0));
  t2 = tim.tv_sec + (tim.tv_usec)/1000000.0;
  double arrival_sleep = (Queue_data->pkt_arrival)*1000;
  int arrival_sleep1 = (int)arrival_sleep;
  usleep(arrival_sleep1);
  gettimeofday(&tim,((void *)0));
  t3 = tim.tv_sec + (tim.tv_usec)/1000000.0;
  Queue_data->Q1_entry_time = t3;
  double inter_time = (t3-t2);
  interarr_time = interarr_time + inter_time;
  if ( Queue_data->P > B )
  {
   printf("%012.3fms: Packet p%d arrives, needs %d tokens, dropped\n", (t3-t1)*1000, Queue_data->packet_no, Queue_data->P);
   num_afterdrop --;
   pthread_mutex_lock(&mut_lock2);
   drop_packets ++;
   pthread_mutex_unlock(&mut_lock2);
  }
  else
  {
     printf("%012.3fms: Packet p%d arives, needs %d tokens, inter-arrival time: %.3f\n",(t3-t1)*1000, Queue_data->packet_no, Queue_data->P, Queue_data->pkt_arrival );
     My402ListAppend(&Queue_one, (void *)Queue_data);
     packet_Q1enter ++;
     gettimeofday(&tim,((void *)0));
     t4 = tim.tv_sec + (tim.tv_usec)/1000000.0;
     printf("%012.3fms: Packet p%d enters Q1\n",(t4-t1)*1000, Queue_data->packet_no);
     Queue_elem = My402ListFirst(&Queue_one);
     Q1_head_data = (struct myPacketInfoStructure *)Queue_elem->obj;
     pthread_mutex_lock(&mut_lock);
     if ( Q1_head_data->P <= token_counter )
     {
      token_counter = token_counter - Q1_head_data->P;
      My402ListUnlink(&Queue_one, Queue_elem);
      packet_count_Q1exit ++;
      gettimeofday(&tim,((void *)0));
      t5 = tim.tv_sec + (tim.tv_usec)/1000000.0;
      double time_Q1 = (t5-Q1_head_data->Q1_entry_time);
      time_in_Q1 = time_in_Q1 + time_Q1;
      printf("%012.3fms: Packet p%d leaves Q1, time in Q1: %.3fms, token bucket now has %d tokens\n",(t5-t1)*1000, Q1_head_data->packet_no, (t5-(Q1_head_data->Q1_entry_time))*1000, token_counter);
      Q1_head_data->Q2_entry_time = t5;
      My402ListAppend(&Queue_two,(void *)Q1_head_data);
      pthread_cond_signal(&signal_server);
      gettimeofday(&tim,((void *)0));
      t6 = tim.tv_sec + (tim.tv_usec)/1000000.0;
      printf("%012.3fms: Packet p%d enters Q2\n", (t6-t1)*1000, Q1_head_data->packet_no);
     }
     pthread_mutex_unlock(&mut_lock);
  }
 }
 pthread_mutex_lock(&mut_lock2);
 drop_pkts = drop_packets;
 if ( drop_pkts == num )
 {
  pthread_mutex_unlock(&mut_lock2);
  pthread_cond_signal(&terminate_server);
 }
 else
 {
  pthread_mutex_unlock(&mut_lock2);
  int ret7 = pthread_cancel(end_server);
  if( ret7 != 0 )
  {
   fprintf(stderr,"Pthread_cancel failed\n");
   exit(1);
  }
 }
 return 0;
}


decompiled_code:
int print_statistics()
{
double v1; // xmm1_8
double v2; // xmm0_8
double v3; // [rsp+8h] [rbp-10h]
double v4; // [rsp+8h] [rbp-10h]

puts("\nStatistics\n");
v3 = *(double *)&t11 - *(double *)&t1;
printf("Average packet inter-arrival time: %.6fs\n", *(double *)&interarr_time / (double)num);
if ( server_count )
printf("Average packet service time: %.6fs\n\n", *(double *)&service_time / (double)server_count);
else
puts("Average packet service time: NA All packets are dropped\n");
printf("Average number of packets in Q1: %.6f\n", *(double *)&time_in_Q1 / v3);
printf("Average number of packets in Q2: %.6f\n", *(double *)&time_in_Q2 / v3);
printf("Average number of packets in S: %.6f\n\n", *(double *)&time_in_S / v3);
if ( server_count )
{
v4 = *(double *)&time_in_sys / (double)server_count;
printf("Average time spent in system: %.6fs\n", v4);
v1 = *(double *)&time_sd - v4 * v4;
if ( v1 < 0.0 )
v2 = sqrt(v1);
else
v2 = sqrt(v1);
printf("Standard Deviation for time spent in the system: %.6fms\n\n", v2);
}
else
{
puts("Average time spent in system: NA All packets are dropped");
puts("Standard Deviation for time spent in the system: NA All packets are dropped\n");
}
if ( token_no )
printf("Token drop probability: %.6f\n", (double)drop_tokens / (double)token_no);
else
puts("Token drop probability: NA Zero tokens are generated");
return printf("Packet drop probability: %.6f\n\n", (double)(drop_packets / num));
}

canonical_decompiled_code:
int func5()
{
double v1; // xmm1_8
double v2; // xmm0_8
double v3; // [rsp+8h] [rbp-10h]
double v4; // [rsp+8h] [rbp-10h]

puts("\nStatistics\n");
v3 = *(double *)&t11 - *(double *)&t1;
printf("Average packet inter-arrival time: %.6fs\n", *(double *)&interarr_time / (double)num);
if ( server_count )
printf("Average packet service time: %.6fs\n\n", *(double *)&service_time / (double)server_count);
else
puts("Average packet service time: NA All packets are dropped\n");
printf("Average number of packets in Q1: %.6f\n", *(double *)&time_in_Q1 / v3);
printf("Average number of packets in Q2: %.6f\n", *(double *)&time_in_Q2 / v3);
printf("Average number of packets in S: %.6f\n\n", *(double *)&time_in_S / v3);
if ( server_count )
{
v4 = *(double *)&time_in_sys / (double)server_count;
printf("Average time spent in system: %.6fs\n", v4);
v1 = *(double *)&time_sd - v4 * v4;
if ( v1 < 0.0 )
v2 = sqrt(v1);
else
v2 = sqrt(v1);
printf("Standard Deviation for time spent in the system: %.6fms\n\n", v2);
}
else
{
puts("Average time spent in system: NA All packets are dropped");
puts("Standard Deviation for time spent in the system: NA All packets are dropped\n");
}
if ( token_no )
printf("Token drop probability: %.6f\n", (double)drop_tokens / (double)token_no);
else
puts("Token drop probability: NA Zero tokens are generated");
return printf("Packet drop probability: %.6f\n\n", (double)(drop_packets / num));
}

original_code:
void print_statistics()
{
 double avg_time_sys = 0;
 printf("\nStatistics\n\n");
 double total_em_time = (t11-t1);
 double avg_inter_time = interarr_time/num;
 printf("Average packet inter-arrival time: %.6fs\n",avg_inter_time);
 if ( server_count == 0)
 {
  printf("Average packet service time: NA All packets are dropped\n\n");
 }
 else
 {
  double avg_service_time = service_time/server_count;
  printf("Average packet service time: %.6fs\n\n",avg_service_time);
 }
 double avg_pkts_Q1 = time_in_Q1/total_em_time;
 printf("Average number of packets in Q1: %.6f\n",avg_pkts_Q1);
 double avg_pkts_Q2 = time_in_Q2/total_em_time;
 printf("Average number of packets in Q2: %.6f\n",avg_pkts_Q2);
 double avg_pkts_S = time_in_S/total_em_time;
 printf("Average number of packets in S: %.6f\n\n",avg_pkts_S);
 if ( server_count == 0)
 {
  printf("Average time spent in system: NA All packets are dropped\n");
  printf("Standard Deviation for time spent in the system: NA All packets are dropped\n\n");
 }
 else
 {
  avg_time_sys = time_in_sys/server_count;
  printf("Average time spent in system: %.6fs\n",avg_time_sys);
  double varience = (time_sd -((avg_time_sys)*(avg_time_sys)));
  double std_dev = sqrt(varience);
  printf("Standard Deviation for time spent in the system: %.6fms\n\n",std_dev);
 }
 if( token_no == 0)
 {
  printf("Token drop probability: NA Zero tokens are generated\n");
 }
 else
 {
  double token_drop_prob = (double)drop_tokens/(double)token_no;
  printf("Token drop probability: %.6f\n",token_drop_prob);
 }
  double packet_drop_prob = drop_packets/num;
  printf("Packet drop probability: %.6f\n\n",packet_drop_prob);
}

variable_types: varience double


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rdx
int v4; // eax
FILE *v5; // rax
int v6; // er12
int v7; // ebp
int v8; // ebx
int v9; // eax
int result; // eax
int longind[7]; // [rsp+Ch] [rbp-1Ch] BYREF

My402ListInit(&Queue_one, argv, envp);
My402ListInit(&Queue_two, argv, v3);
longind[0] = 0;
while ( 1 )
{
v4 = getopt_long_only(argc, (char *const *)argv, &shortopts, &long_options_0, longind);
if ( v4 == -1 )
break;
switch ( v4 )
{
case 'b':
B = atoi(optarg);
break;
case 'l':
lambda = atof(optarg);
break;
case 'm':
mu = atof(optarg);
break;
case 'n':
num = atoi(optarg);
num_afterdrop = num;
if ( !num )
{
fwrite("Number of packets are 0\n", 1uLL, 0x18uLL, stderr);
exit(1);
}
return result;
case 'p':
P = atoi(optarg);
break;
case 'r':
r = atof(optarg);
break;
case 't':
v5 = fopen(optarg, "r");
fp = v5;
file_name = (__int64)optarg;
if ( !v5 )
{
fprintf(stderr, "Cannot open file %s to read\n", optarg);
exit(1);
}
file_flag = 1;
fgets(buf, 1026, v5);
num = atoi(buf);
num_afterdrop = num;
break;
default:
continue;
}
}
if ( file_flag == 1 )
{
puts("\nEmulation Parameters:");
printf("\tr:%.2f\n", *(double *)&r);
printf("\tB:%d\n", (unsigned int)B);
printf("\ttsfile:%s\n\n", (const char *)file_name);
}
else
{
puts("\nEmulation Parameters:");
printf("\tlambda = %.2f\n", *(double *)&lambda);
printf("\tmu = %.2f\n", *(double *)&mu);
printf("\tr = %.2f\n", *(double *)&r);
printf("\tB = %d\n", (unsigned int)B);
printf("\tP = %d\n", (unsigned int)P);
printf("\tnumber to arrive = %d\n\n", (unsigned int)num);
}
gettimeofday(&tim, 0LL);
*(double *)&t1 = (double)(int)tim.tv_usec / 1000000.0 + (double)SLODWORD(tim.tv_sec);
printf("%012.3fms: Emulation Begins\n", (*(double *)&t1 - *(double *)&t1) * 1000.0);
v6 = pthread_create(&arrival_thread, 0LL, packet_arrival, 0LL);
v7 = pthread_create(&token_thread, 0LL, token_bucket_func, 0LL);
v8 = pthread_create(&server_thread, 0LL, server_func, 0LL);
v9 = pthread_create(&end_server, 0LL, server_termination_func, 0LL);
if ( v6 )
{
fwrite("Arrival thread creation failed\n", 1uLL, 0x1FuLL, stderr);
exit(1);
}
if ( v7 )
{
fwrite("Token Thread creation failed\n", 1uLL, 0x1DuLL, stderr);
exit(1);
}
if ( v9 | v8 )
{
fwrite("Server Thread creation failed\n", 1uLL, 0x1EuLL, stderr);
exit(1);
}
pthread_join(arrival_thread, 0LL);
pthread_join(token_thread, 0LL);
pthread_join(server_thread, 0LL);
pthread_join(end_server, 0LL);
gettimeofday(&tim, 0LL);
*(double *)&t11 = (double)(int)tim.tv_usec / 1000000.0 + (double)SLODWORD(tim.tv_sec);
print_statistics();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rdx
int v4; // eax
FILE *v5; // rax
int v6; // er12
int v7; // ebp
int v8; // ebx
int v9; // eax
int result; // eax
int longind[7]; // [rsp+Ch] [rbp-1Ch] BYREF

My402ListInit(&Queue_one, argv, envp);
My402ListInit(&Queue_two, argv, v3);
longind[0] = 0;
while ( 1 )
{
v4 = getopt_long_only(argc, (char *const *)argv, &shortopts, &long_options_0, longind);
if ( v4 == -1 )
break;
switch ( v4 )
{
case 'b':
B = atoi(optarg);
break;
case 'l':
lambda = atof(optarg);
break;
case 'm':
mu = atof(optarg);
break;
case 'n':
num = atoi(optarg);
num_afterdrop = num;
if ( !num )
{
fwrite("Number of packets are 0\n", 1uLL, 0x18uLL, stderr);
exit(1);
}
return result;
case 'p':
P = atoi(optarg);
break;
case 'r':
r = atof(optarg);
break;
case 't':
v5 = fopen(optarg, "r");
fp = v5;
file_name = (__int64)optarg;
if ( !v5 )
{
fprintf(stderr, "Cannot open file %s to read\n", optarg);
exit(1);
}
file_flag = 1;
fgets(buf, 1026, v5);
num = atoi(buf);
num_afterdrop = num;
break;
default:
continue;
}
}
if ( file_flag == 1 )
{
puts("\nEmulation Parameters:");
printf("\tr:%.2f\n", *(double *)&r);
printf("\tB:%d\n", (unsigned int)B);
printf("\ttsfile:%s\n\n", (const char *)file_name);
}
else
{
puts("\nEmulation Parameters:");
printf("\tlambda = %.2f\n", *(double *)&lambda);
printf("\tmu = %.2f\n", *(double *)&mu);
printf("\tr = %.2f\n", *(double *)&r);
printf("\tB = %d\n", (unsigned int)B);
printf("\tP = %d\n", (unsigned int)P);
printf("\tnumber to arrive = %d\n\n", (unsigned int)num);
}
gettimeofday(&tim, 0LL);
*(double *)&t1 = (double)(int)tim.tv_usec / 1000000.0 + (double)SLODWORD(tim.tv_sec);
printf("%012.3fms: Emulation Begins\n", (*(double *)&t1 - *(double *)&t1) * 1000.0);
v6 = pthread_create(&arrival_thread, 0LL, packet_arrival, 0LL);
v7 = pthread_create(&token_thread, 0LL, token_bucket_func, 0LL);
v8 = pthread_create(&server_thread, 0LL, server_func, 0LL);
v9 = pthread_create(&end_server, 0LL, server_termination_func, 0LL);
if ( v6 )
{
fwrite("Arrival thread creation failed\n", 1uLL, 0x1FuLL, stderr);
exit(1);
}
if ( v7 )
{
fwrite("Token Thread creation failed\n", 1uLL, 0x1DuLL, stderr);
exit(1);
}
if ( v9 | v8 )
{
fwrite("Server Thread creation failed\n", 1uLL, 0x1EuLL, stderr);
exit(1);
}
pthread_join(arrival_thread, 0LL);
pthread_join(token_thread, 0LL);
pthread_join(server_thread, 0LL);
pthread_join(end_server, 0LL);
gettimeofday(&tim, 0LL);
*(double *)&t11 = (double)(int)tim.tv_usec / 1000000.0 + (double)SLODWORD(tim.tv_sec);
func5();
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 int opt = 0;
 My402ListInit(&Queue_one);
 My402ListInit(&Queue_two);
 static struct option long_options[] = {
        {"lambda", 1, 0, 'l' },
        {"mu", 1, 0, 'm' },
        {"r", 1, 0, 'r' },
        {"B", 1, 0, 'b' },
  {"P", 1, 0, 'p'},
  {"n", 1, 0, 'n'},
  {"t", 1, 0, 't'},
        {0, 0, 0, 0 }
    };
 int long_index =0;
    while ((opt = getopt_long_only(argc, argv,"",
                   long_options, &long_index )) != -1) {
        switch (opt) {
             case 'l' : lambda = atof(optarg);
                 break;
             case 'm' : mu = atof(optarg);
                 break;
             case 'r' : r = atof(optarg);
                 break;
             case 'b' : B = atoi(optarg);
                 break;
    case 'p' : P = atoi(optarg);
    break;
    case 'n' : num = atoi(optarg);
      num_afterdrop = num;
      if(num == 0)
      {
       fprintf(stderr,"Number of packets are 0\n");
       exit(1);
      }
    break;
    case 't' : fp = fopen(optarg, "r");
      file_name = optarg;
      if ( fp == ((void *)0))
      {
       fprintf(stderr,"Cannot open file %s to read\n",optarg);
       exit(1);
      }
      file_flag = 1;
      fgets(buf, sizeof(buf), fp);
      num = atoi(buf);
      num_afterdrop = num;
    break;
        }
    }
 if( file_flag == 1)
 {
  printf("\nEmulation Parameters:\n");
  printf("	r:%.2f\n",r);
  printf("	B:%d\n",B);
  printf("	tsfile:%s\n\n",file_name);
 }
 else
 {
  printf("\nEmulation Parameters:\n");
  printf("	lambda = %.2f\n",lambda);
  printf("	mu = %.2f\n",mu);
  printf("	r = %.2f\n",r);
  printf("	B = %d\n",B);
  printf("	P = %d\n",P);
  printf("	number to arrive = %d\n\n",num);
 }
 gettimeofday(&tim,((void *)0));
 t1 = tim.tv_sec + (tim.tv_usec)/1000000.0;
 printf("%012.3fms: Emulation Begins\n",(t1-t1)*1000);
 int ret1 = pthread_create(&arrival_thread, 0, packet_arrival, ((void *)0));
 int ret2 = pthread_create(&token_thread, 0, token_bucket_func, ((void *)0));
 int ret3 = pthread_create(&server_thread, 0, server_func, ((void *)0));
 int ret4 = pthread_create(&end_server, 0, server_termination_func, ((void *)0));
 if( ret1 != 0 )
 {
  fprintf(stderr,"Arrival thread creation failed\n");
  exit(1);
 }
 if( ret2 != 0 )
 {
  fprintf(stderr,"Token Thread creation failed\n");
  exit(1);
 }
 if( ret3 != 0 )
 {
  fprintf(stderr,"Server Thread creation failed\n");
  exit(1);
 }
 if( ret4 != 0 )
 {
  fprintf(stderr,"Server Thread creation failed\n");
  exit(1);
 }
 pthread_join(arrival_thread,0);
 pthread_join(token_thread,0);
 pthread_join(server_thread,0);
 pthread_join(end_server,0);
 gettimeofday(&tim,((void *)0));
 t11 = tim.tv_sec + (tim.tv_usec)/1000000.0;
 print_statistics();
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 int opt = 0;
 My402ListInit(&Queue_one);
 My402ListInit(&Queue_two);
 static struct option long_options[] = {
        {"lambda", 1, 0, 'l' },
        {"mu", 1, 0, 'm' },
        {"r", 1, 0, 'r' },
        {"B", 1, 0, 'b' },
  {"P", 1, 0, 'p'},
  {"n", 1, 0, 'n'},
  {"t", 1, 0, 't'},
        {0, 0, 0, 0 }
    };
 int long_index = 0;
    while ((opt = getopt_long_only(argc, argv,"",
                   long_options, &long_index )) != -1) {
        switch (opt) {
             case 'l' : lambda = atof(optarg);
                 break;
             case 'm' : mu = atof(optarg);
                 break;
             case 'r' : r = atof(optarg);
                 break;
             case 'b' : B = atoi(optarg);
                 break;
    case 'p' : P = atoi(optarg);
    break;
    case 'n' : num = atoi(optarg);
      num_afterdrop = num;
      if(num == 0)
      {
       fprintf(stderr,"Number of packets are 0\n");
       exit(1);
      }
    break;
    case 't' : fp = fopen(optarg, "r");
      file_name = optarg;
      if ( fp == ((void *)0))
      {
       fprintf(stderr,"Cannot open file %s to read\n",optarg);
       exit(1);
      }
      file_flag = 1;
      fgets(buf, sizeof(buf), fp);
      num = atoi(buf);
      num_afterdrop = num;
    break;
        }
    }
 if( file_flag == 1)
 {
  printf("\nEmulation Parameters:\n");
  printf("	r:%.2f\n",r);
  printf("	B:%d\n",B);
  printf("	tsfile:%s\n\n",file_name);
 }
 else
 {
  printf("\nEmulation Parameters:\n");
  printf("	lambda = %.2f\n",lambda);
  printf("	mu = %.2f\n",mu);
  printf("	r = %.2f\n",r);
  printf("	B = %d\n",B);
  printf("	P = %d\n",P);
  printf("	number to arrive = %d\n\n",num);
 }
 gettimeofday(&tim,((void *)0));
 t1 = tim.tv_sec + (tim.tv_usec)/1000000.0;
 printf("%012.3fms: Emulation Begins\n",(t1-t1)*1000);
 int ret1 = pthread_create(&arrival_thread, 0, packet_arrival, ((void *)0));
 int ret2 = pthread_create(&token_thread, 0, token_bucket_func, ((void *)0));
 int ret3 = pthread_create(&server_thread, 0, server_func, ((void *)0));
 int ret4 = pthread_create(&end_server, 0, server_termination_func, ((void *)0));
 if( ret1 != 0 )
 {
  fprintf(stderr,"Arrival thread creation failed\n");
  exit(1);
 }
 if( ret2 != 0 )
 {
  fprintf(stderr,"Token Thread creation failed\n");
  exit(1);
 }
 if( ret3 != 0 )
 {
  fprintf(stderr,"Server Thread creation failed\n");
  exit(1);
 }
 if( ret4 != 0 )
 {
  fprintf(stderr,"Server Thread creation failed\n");
  exit(1);
 }
 pthread_join(arrival_thread,0);
 pthread_join(token_thread,0);
 pthread_join(server_thread,0);
 pthread_join(end_server,0);
 gettimeofday(&tim,((void *)0));
 t11 = tim.tv_sec + (tim.tv_usec)/1000000.0;
 print_statistics();
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: opt int

variable_types: struct option { char *name; int has_arg; int *flag; int val; } []

return_type: int


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

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

original_code:
int My402ListLength(My402List *list)
{
 return (list->num_members);
}

canonical_original_code:
int My402ListLength(struct tagMy402List *list)
{
 return (list->num_members);
}

variable_types: struct tagMy402List { int num_members; struct tagMy402ListElem { void *obj; struct tagMy402ListElem *next; struct tagMy402ListElem *prev; } anchor; int (*Length)(struct tagMy402List *); int (*Empty)(struct tagMy402List *); int (*Append)(struct tagMy402List *, void *); int (*Prepend)(struct tagMy402List *, void *); void (*Unlink)(struct tagMy402List *, struct tagMy402ListElem *); int (*InsertBefore)(struct tagMy402List *, void *, struct tagMy402ListElem *); int (*InsertAfter)(struct tagMy402List *, void *, struct tagMy402ListElem *); struct tagMy402ListElem *(*First)(struct tagMy402List *); struct tagMy402ListElem *(*Last)(struct tagMy402List *); struct tagMy402ListElem *(*Next)(struct tagMy402List *, struct tagMy402ListElem *cur); struct tagMy402ListElem *(*Prev)(struct tagMy402List *, struct tagMy402ListElem *cur); struct tagMy402ListElem *(*Find)(struct tagMy402List *, void *obj); } *

user_defined_types: struct tagMy402List { int num_members; struct tagMy402ListElem anchor; int (*Length)(struct tagMy402List *); int (*Empty)(struct tagMy402List *); int (*Append)(struct tagMy402List *, void *); int (*Prepend)(struct tagMy402List *, void *); void (*Unlink)(struct tagMy402List *, struct tagMy402ListElem *); int (*InsertBefore)(struct tagMy402List *, void *, struct tagMy402ListElem *); int (*InsertAfter)(struct tagMy402List *, void *, struct tagMy402ListElem *); struct tagMy402ListElem *(*First)(struct tagMy402List *); struct tagMy402ListElem *(*Last)(struct tagMy402List *); struct tagMy402ListElem *(*Next)(struct tagMy402List *, struct tagMy402ListElem *cur); struct tagMy402ListElem *(*Prev)(struct tagMy402List *, struct tagMy402ListElem *cur); struct tagMy402ListElem *(*Find)(struct tagMy402List *, void *obj); }


decompiled_code:
_BOOL8 __fastcall My402ListEmpty(_DWORD *a1)
{
return *a1 == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(_DWORD *a1)
{
return *a1 == 0;
}

original_code:
int My402ListEmpty(My402List *list)
{
 if(list->num_members == 0)
 {
  return 1;
 }
 else
 {
  return 0;
 }
}

canonical_original_code:
int My402ListEmpty(struct tagMy402List *list)
{
 if(list->num_members == 0)
 {
  return 1;
 }
 else
 {
  return 0;
 }
}


decompiled_code:
__int64 __fastcall My402ListInsertAfter(_DWORD *a1, __int64 a2, __int64 a3)
{
_QWORD *v4; // rax
__int64 v5; // rdx
__int64 result; // rax

v4 = malloc(0x18uLL);
v5 = *(_QWORD *)(a3 + 8);
v4[2] = a3;
v4[1] = v5;
*(_QWORD *)(a3 + 8) = v4;
*(_QWORD *)(v5 + 16) = v4;
*v4 = a2;
result = 1LL;
++*a1;
return result;
}

original_code:
int My402ListInsertAfter(My402List* list, void* obj, My402ListElem* elem)
{
  My402ListElem *newnode = (My402ListElem*)malloc(sizeof(My402ListElem));
  My402ListElem *next_node = elem->next;
  elem->next = newnode;
  newnode->prev = elem;
  newnode->next = next_node;
  next_node->prev = newnode;
  newnode->obj = obj;
  (list->num_members)++;
  return 1;
}

canonical_original_code:
int My402ListInsertAfter(struct tagMy402List *list, void *obj, struct tagMy402ListElem *elem)
{
  struct tagMy402ListElem *newnode = (My402ListElem*)malloc(sizeof(My402ListElem));
  struct tagMy402ListElem *next_node = elem->next;
  elem->next = newnode;
  newnode->prev = elem;
  newnode->next = next_node;
  next_node->prev = newnode;
  newnode->obj = obj;
  (list->num_members)++;
  return 1;
}

variable_types:
obj
void *

variable_types:
elem
struct tagMy402ListElem *


decompiled_code:
__int64 __fastcall My402ListInsertBefore(_DWORD *a1, __int64 a2, __int64 a3)
{
_QWORD *v4; // rax
__int64 v5; // rdx
__int64 result; // rax

v4 = malloc(0x18uLL);
v5 = *(_QWORD *)(a3 + 16);
*(_QWORD *)(v5 + 8) = v4;
v4[2] = v5;
v4[1] = a3;
*v4 = a2;
*(_QWORD *)(a3 + 16) = v4;
result = 1LL;
++*a1;
return result;
}

original_code:
int My402ListInsertBefore(My402List* list, void* obj, My402ListElem* elem)
{
  My402ListElem *newnode = (My402ListElem*)malloc(sizeof(My402ListElem));
  My402ListElem *prev_node = elem->prev;
  prev_node->next = newnode;
  newnode->prev = prev_node;
  newnode->next = elem;
  elem->prev = newnode;
  newnode->obj = obj;
  (list->num_members)++;
  return 1;
}

canonical_original_code:
int My402ListInsertBefore(struct tagMy402List *list, void *obj, struct tagMy402ListElem *elem)
{
  struct tagMy402ListElem *newnode = (My402ListElem*)malloc(sizeof(My402ListElem));
  struct tagMy402ListElem *prev_node = elem->prev;
  prev_node->next = newnode;
  newnode->prev = prev_node;
  newnode->next = elem;
  elem->prev = newnode;
  newnode->obj = obj;
  (list->num_members)++;
  return 1;
}


decompiled_code:
__int64 __fastcall My402ListFirst(__int64 a1)
{
return *(_QWORD *)(a1 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
return *(_QWORD *)(a1 + 16);
}

original_code:
My402ListElem *My402ListFirst(My402List* list)
{
  return list->anchor.next;
}

canonical_original_code:
struct tagMy402ListElem *My402ListFirst(struct tagMy402List *list)
{
  return list->anchor.next;
}

variable_types: struct tagMy402List { int num_members; struct tagMy402ListElem anchor; int (*Length)(struct tagMy402List *); int (*Empty)(struct tagMy402List *); int (*Append)(struct tagMy402List *, void *); int (*Prepend)(struct tagMy402List *, void *); void (*Unlink)(struct tagMy402List *, struct tagMy402ListElem *); int (*InsertBefore)(struct tagMy402List *, void *, struct tagMy402ListElem *); int (*InsertAfter)(struct tagMy402List *, void *, struct tagMy402ListElem *); struct tagMy402ListElem *(*First)(struct tagMy402List *); struct tagMy402ListElem *(*Last)(struct tagMy402List *); struct tagMy402ListElem *(*Next)(struct tagMy402List *, struct tagMy402ListElem *cur); struct tagMy402ListElem *(*Prev)(struct tagMy402List *, struct tagMy402ListElem *cur); struct tagMy402ListElem *(*Find)(struct tagMy402List *, void *obj); } *

return_type: struct tagMy402ListElem { void *obj; struct tagMy402ListElem *next; struct tagMy402ListElem *prev; } *


original_code:
int My402ListPrepend(My402List* list, void* obj)
{
 My402ListElem *newnode = (My402ListElem *)malloc(sizeof(My402ListElem));
 if(newnode == ((void *)0))
 {
  return 0;
 }
 My402ListElem *curr;
 if(list->anchor.next == ((void *)0))
 {
  list->anchor.next = newnode;
  list->anchor.prev = newnode;
  newnode->next = &list->anchor;
  newnode->prev = &list->anchor;
  newnode->obj = obj;
 }
 else
 {
  curr = My402ListFirst(list);
  curr->prev = newnode;
  newnode->next = curr;
  list->anchor.next = newnode;
  newnode->prev = &list->anchor;
  newnode->obj = obj;
 }
 (list->num_members)++;
 return 1;
}

canonical_original_code:
int My402ListPrepend(struct tagMy402List *list, void *obj)
{
 struct tagMy402ListElem *newnode = (My402ListElem *)malloc(sizeof(My402ListElem));
 if(newnode == ((void *)0))
 {
  return 0;
 }
 struct tagMy402ListElem *curr;
 if(list->anchor.next == ((void *)0))
 {
  list->anchor.next = newnode;
  list->anchor.prev = newnode;
  newnode->next = &list->anchor;
  newnode->prev = &list->anchor;
  newnode->obj = obj;
 }
 else
 {
  curr = My402ListFirst(list);
  curr->prev = newnode;
  newnode->next = curr;
  list->anchor.next = newnode;
  newnode->prev = &list->anchor;
  newnode->obj = obj;
 }
 (list->num_members)++;
 return 1;
}


decompiled_code:
__int64 __fastcall My402ListLast(__int64 a1)
{
return *(_QWORD *)(a1 + 24);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
return *(_QWORD *)(a1 + 24);
}

original_code:
My402ListElem *My402ListLast(My402List* list)
{
  return list->anchor.prev;
}

canonical_original_code:
struct tagMy402ListElem *My402ListLast(struct tagMy402List *list)
{
  return list->anchor.prev;
}


original_code:
extern int My402ListAppend(My402List* list, void* obj)
{
 My402ListElem *newnode = (My402ListElem *)malloc(sizeof(My402ListElem));
 if(newnode == ((void *)0))
 {
  return 0;
 }
 My402ListElem *curr;
 if (list->anchor.next == ((void *)0))
 {
  list->anchor.next = newnode;
  list->anchor.prev = newnode;
  newnode->next =&list->anchor;
  newnode->prev =&list->anchor;
  newnode->obj = obj;
 }
 else
 {
  curr = My402ListLast(list);
  curr->next = newnode;
  newnode->prev = curr;
  newnode->next = &list->anchor;
  list->anchor.prev = newnode;
  newnode->obj = obj;
 }
 (list->num_members)++;
 return 1;
}

canonical_original_code:
extern int My402ListAppend(struct tagMy402List *list, void *obj)
{
 struct tagMy402ListElem *newnode = (My402ListElem *)malloc(sizeof(My402ListElem));
 if(newnode == ((void *)0))
 {
  return 0;
 }
 struct tagMy402ListElem *curr;
 if (list->anchor.next == ((void *)0))
 {
  list->anchor.next = newnode;
  list->anchor.prev = newnode;
  newnode->next =&list->anchor;
  newnode->prev =&list->anchor;
  newnode->obj = obj;
 }
 else
 {
  curr = My402ListLast(list);
  curr->next = newnode;
  newnode->prev = curr;
  newnode->next = &list->anchor;
  list->anchor.prev = newnode;
  newnode->obj = obj;
 }
 (list->num_members)++;
 return 1;
}


decompiled_code:
__int64 __fastcall My402ListNext(__int64 a1, __int64 a2)
{
__int64 result; // rax

result = *(_QWORD *)(a2 + 8);
if ( result == a1 + 8 )
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, __int64 a2)
{
__int64 result; // rax

result = *(_QWORD *)(a2 + 8);
if ( result == a1 + 8 )
result = 0LL;
return result;
}

original_code:
My402ListElem *My402ListNext(My402List* list, My402ListElem* elem)
{
 if(elem->next == &list->anchor)
 {
  return ((void *)0);
 }
 else
  return elem->next;
}

canonical_original_code:
struct tagMy402ListElem *My402ListNext(struct tagMy402List *list, struct tagMy402ListElem *elem)
{
 if(elem->next == &list->anchor)
 {
  return ((void *)0);
 }
 else
  return elem->next;
}


decompiled_code:
__int64 __fastcall My402ListPrev(__int64 a1, __int64 a2)
{
__int64 result; // rax

result = *(_QWORD *)(a2 + 16);
if ( result == a1 + 8 )
result = 0LL;
return result;
}

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

result = *(_QWORD *)(a2 + 16);
if ( result == a1 + 8 )
result = 0LL;
return result;
}

original_code:
My402ListElem *My402ListPrev(My402List* list, My402ListElem* elem)
{
 if(elem->prev == &list->anchor)
 {
  return ((void *)0);
 }
 else
 return elem->prev;
}

canonical_original_code:
struct tagMy402ListElem *My402ListPrev(struct tagMy402List *list, struct tagMy402ListElem *elem)
{
 if(elem->prev == &list->anchor)
 {
  return ((void *)0);
 }
 else
 return elem->prev;
}


decompiled_code:
__int64 My402ListInit()
{
return 1LL;
}

canonical_decompiled_code:
__int64 func12()
{
return 1LL;
}

original_code:
int My402ListInit(My402List* list)
{
 My402List *mylist;
 mylist = (My402List *)malloc(sizeof(My402List));
 mylist->num_members= 0;
 mylist->anchor.next = ((void *)0);
 mylist->anchor.prev = ((void *)0);
 mylist->anchor.obj = ((void *)0);
 return 1;
}

canonical_original_code:
int My402ListInit(struct tagMy402List *list)
{
 struct tagMy402List *mylist;
 mylist = (struct tagMy402List *)malloc(sizeof(My402List));
 mylist->num_members= 0;
 mylist->anchor.next = ((void *)0);
 mylist->anchor.prev = ((void *)0);
 mylist->anchor.obj = ((void *)0);
 return 1;
}


repo: apurvam/Block-FS

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v4; // [rsp+0h] [rbp-28h] BYREF
const char **v5; // [rsp+8h] [rbp-20h]
int v6; // [rsp+10h] [rbp-18h]

v4 = argc;
v5 = argv;
v6 = 0;
if ( (unsigned int)fuse_opt_parse(&v4, blockfs, &blockfs_opts, 0LL) == -1 )
{
puts("failure in fuse_opt_parse");
exit(1);
}
printf("The cache device is : %s\n", (const char *)blockfs[0]);
printf("The block device is : %s\n", (const char *)blockfs[1]);
blockfs_init();
umask(0);
return fuse_main_real(v4, v5, &blockfs_oper, 360LL, 0LL);
}

original_code:
int main(int argc, char *argv[])
{
  struct fuse_args args = { argc, argv, 0 };
  if ( fuse_opt_parse(&args, &blockfs, blockfs_opts, 0) == -1 ){
    printf ("failure in fuse_opt_parse\n");
    exit(1);
  }
  printf ("The cache device is : %s\n", blockfs.cache_device);
  printf ("The block device is : %s\n", blockfs.block_device);
  blockfs_init();
  umask(0);
  return fuse_main_real(args.argc, args.argv, &blockfs_oper, sizeof(*(&blockfs_oper)), ((void *)0));
}

variable_types: struct fuse_args { int argc; char **argv; int allocated; }


decompiled_code:
void __fastcall add_multicast_interface(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
unsigned int v3; // eax
__int64 v4; // rax

if ( *(_DWORD *)a1 == 3 )
{
v2 = *(_QWORD *)(a1 + 8);
v3 = multicast_create_sock_server(a2, "239.255.255.223", 11223LL, 6LL);
*(_DWORD *)(v2 + 8) = v3;
v4 = amt_event_set(v2, v3, 2LL);
amt_event_add(*(_QWORD *)v2, v4, event_read_cb, v4);
}
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
unsigned int v3; // eax
__int64 v4; // rax

if ( *(_DWORD *)a1 == 3 )
{
v2 = *(_QWORD *)(a1 + 8);
v3 = multicast_create_sock_server(a2, "239.255.255.223", 11223LL, 6LL);
*(_DWORD *)(v2 + 8) = v3;
v4 = amt_event_set(v2, v3, 2LL);
amt_event_add(*(_QWORD *)v2, v4, event_read_cb, v4);
}
}

original_code:
void add_multicast_interface(struct amt_handle *handle, char *ip)
{
 struct amt_event *event;
 struct amt_multicast *multicast;
 if(handle->type != 3)
  return;
 multicast = handle->point;
 multicast->sock_server = multicast_create_sock_server(ip, "239.255.255.223", 11223, 6);
 event = amt_event_set(&multicast->event_base, multicast->sock_server, 2);
 amt_event_add(multicast->event_base, event, event_read_cb, event);
}

variable_types: struct amt_handle { int type; void *point; } *

variable_types:
ip
char *

variable_types: struct amt_event { struct list_head { struct list_head *next; } list; struct amt_event_base { struct list_head head; 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; } mutex; unsigned long loop_tid; int event_num; int exit_flag; } **base; int sock; int tcp_udp_type; void (*read_cb)(void *arg); void *data; struct list_head write_list; union pthread_mutex_t write_mutex; int status; int err_code; } *

variable_types: struct amt_multicast { struct amt_event_base { struct list_head { struct list_head *next; } head; 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; } mutex; unsigned long loop_tid; int event_num; int exit_flag; } *event_base; int sock_server; struct amt_event { struct list_head list; struct amt_event_base **base; int sock; int tcp_udp_type; void (*read_cb)(void *arg); void *data; struct list_head write_list; union pthread_mutex_t write_mutex; int status; int err_code; } *event_client; struct sockaddr { unsigned short sa_family; char sa_data[14]; } sock_addr; struct amt_multicast_callback { void (*log_cb)(int tag, char *log); int (*recv_multicast)(char *buf, int size, char *ip); } cb; struct amt_log_handle { int log_flag; void (*log_cb)(int tag, char *log); } log_handle; } *

user_defined_types: struct amt_multicast { struct amt_event_base *event_base; int sock_server; struct amt_event *event_client; struct sockaddr sock_addr; struct amt_multicast_callback cb; struct amt_log_handle log_handle; }

user_defined_types: struct amt_event_base { struct list_head head; union pthread_mutex_t mutex; unsigned long loop_tid; int event_num; int exit_flag; }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; 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; }


decompiled_code:
__int64 __fastcall deinit_multicast_sock(void *ptr)
{
__int64 result; // rax

if ( *(_DWORD *)ptr == 3 )
{
amt_event_base_deinit(**((_QWORD **)ptr + 1));
free(*((void **)ptr + 1));
free(ptr);
result = communicator_deinit();
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(void *ptr)
{
__int64 result; // rax

if ( *(_DWORD *)ptr == 3 )
{
amt_event_base_deinit(**((_QWORD **)ptr + 1));
free(*((void **)ptr + 1));
free(ptr);
result = communicator_deinit();
}
return result;
}

original_code:
void deinit_multicast_sock(struct amt_handle *handle)
{
 struct amt_multicast *multicast;
 if(handle->type != 3)
  return;
 multicast = handle->point;
 amt_event_base_deinit(multicast->event_base);
 free(handle->point);
 free(handle);
 communicator_deinit();
}

user_defined_types: struct amt_handle { int type; void *point; }

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

user_defined_types: struct amt_multicast_callback { void (*log_cb)(int tag, char *log); int (*recv_multicast)(char *buf, int size, char *ip); }

user_defined_types: struct amt_log_handle { int log_flag; void (*log_cb)(int tag, char *log); }

user_defined_types: struct amt_event { struct list_head list; struct amt_event_base **base; int sock; int tcp_udp_type; void (*read_cb)(void *arg); void *data; struct list_head write_list; union pthread_mutex_t write_mutex; int status; int err_code; }

user_defined_types: struct list_head { struct list_head *next; }

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


decompiled_code:
__int64 __fastcall control_multicast_log(__int64 a1)
{
__int64 v1; // rdi
__int64 result; // rax

if ( *(_DWORD *)a1 == 3 )
{
v1 = *(_QWORD *)(a1 + 8);
if ( *(_QWORD *)(v1 + 40) )
result = amt_log_control(v1 + 56);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
__int64 v1; // rdi
__int64 result; // rax

if ( *(_DWORD *)a1 == 3 )
{
v1 = *(_QWORD *)(a1 + 8);
if ( *(_QWORD *)(v1 + 40) )
result = amt_log_control(v1 + 56);
}
return result;
}

original_code:
void control_multicast_log(struct amt_handle *handle, int tag_on)
{
 struct amt_multicast *multicast;
 if(handle->type != 3)
  return;
 multicast = handle->point;
 if(multicast->cb.log_cb)
  amt_log_control(&multicast->log_handle, tag_on);
}


decompiled_code:
__int64 __fastcall send_multicast(__int64 a1, __int64 a2, __int64 a3)
{
__int64 result; // rax

if ( *(_DWORD *)a1 == 3 )
result = amt_event_buffer_write_sync(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 16LL), a2, a3, *(_QWORD *)(a1 + 8) + 24LL);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2, __int64 a3)
{
__int64 result; // rax

if ( *(_DWORD *)a1 == 3 )
result = amt_event_buffer_write_sync(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 16LL), a2, a3, *(_QWORD *)(a1 + 8) + 24LL);
return result;
}

original_code:
void send_multicast(struct amt_handle *handle, char *buf, int size)
{
 struct amt_multicast *multicast;
 if(handle->type != 3)
  return;
 multicast = handle->point;
 amt_event_buffer_write_sync(multicast->event_client, buf, size, &multicast->sock_addr);
}

variable_types:
buf
char *

variable_types: size int


decompiled_code:
int __fastcall event_read_cb(__int64 a1)
{
__int64 v1; // r13
int v2; // eax
unsigned int v3; // er12
__int64 v4; // rbp
const char *v5; // rax
size_t v6; // r14
char *v7; // rax
__int64 (__fastcall *v8)(char *, _QWORD, char *); // rax
int v9; // eax
int v10; // ebx
int v12; // [rsp+Ch] [rbp-63Ch] BYREF
char v13[16]; // [rsp+10h] [rbp-638h] BYREF
char dest[32]; // [rsp+20h] [rbp-628h] BYREF
char v15[1544]; // [rsp+40h] [rbp-608h] BYREF

v1 = *(_QWORD *)(a1 + 16);
v2 = amt_event_buffer_read(a1, v15, 1500LL, v13);
if ( v2 <= 0 )
{
LODWORD(v8) = _amt_log(32LL, v1 + 56, "socket error\n");
}
else
{
v3 = v2;
v4 = get_local_ip(&v12);
v5 = (const char *)amt_get_ip(v13);
strncpy(dest, v5, 0x10uLL);
while ( 1 )
{
v9 = v12;
v10 = --v12;
if ( !v9 )
break;
v6 = strlen(dest);
v7 = inet_ntoa(*(struct in_addr *)(v4 + 4LL * v10));
LODWORD(v8) = strncmp(v7, dest, v6);
if ( !(_DWORD)v8 )
return (int)v8;
}
v8 = *(__int64 (__fastcall **)(char *, _QWORD, char *))(v1 + 48);
if ( v8 )
LODWORD(v8) = v8(v15, v3, dest);
}
return (int)v8;
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1)
{
__int64 v1; // r13
int v2; // eax
unsigned int v3; // er12
__int64 v4; // rbp
const char *v5; // rax
size_t v6; // r14
char *v7; // rax
__int64 (__fastcall *v8)(char *, _QWORD, char *); // rax
int v9; // eax
int v10; // ebx
int v12; // [rsp+Ch] [rbp-63Ch] BYREF
char v13[16]; // [rsp+10h] [rbp-638h] BYREF
char dest[32]; // [rsp+20h] [rbp-628h] BYREF
char v15[1544]; // [rsp+40h] [rbp-608h] BYREF

v1 = *(_QWORD *)(a1 + 16);
v2 = amt_event_buffer_read(a1, v15, 1500LL, v13);
if ( v2 <= 0 )
{
LODWORD(v8) = _amt_log(32LL, v1 + 56, "socket error\n");
}
else
{
v3 = v2;
v4 = get_local_ip(&v12);
v5 = (const char *)amt_get_ip(v13);
strncpy(dest, v5, 0x10uLL);
while ( 1 )
{
v9 = v12;
v10 = --v12;
if ( !v9 )
break;
v6 = strlen(dest);
v7 = inet_ntoa(*(struct in_addr *)(v4 + 4LL * v10));
LODWORD(v8) = strncmp(v7, dest, v6);
if ( !(_DWORD)v8 )
return (int)v8;
}
v8 = *(__int64 (__fastcall **)(char *, _QWORD, char *))(v1 + 48);
if ( v8 )
LODWORD(v8) = v8(v15, v3, dest);
}
return (int)v8;
}

original_code:
static void event_read_cb(void *arg)
{
 int size;
 struct sockaddr addr;
 char buffer[1500];
 struct amt_event *event = arg;
 struct amt_multicast *multicast = (struct amt_multicast*)event->base;
 size = amt_event_buffer_read(event, buffer, 1500, &addr);
 if(size <= 0)
 {
  __amt_log((1 << 5), &multicast->log_handle, "socket error\n");
 }
 else
 {
  int num;
  int self = 0;
  char dst_ip[32];
  struct in_addr *addr_list = get_local_ip(&num);
  strncpy(dst_ip, amt_get_ip(&addr), 16);
  while(num--)
  {
   if(strncmp(inet_ntoa(addr_list[num]), dst_ip, strlen(dst_ip)) == 0)
   {
    self = 1;
    break;
   }
  }
  if(!self && multicast->cb.recv_multicast)
   multicast->cb.recv_multicast(buffer, size, dst_ip);
 }
}

variable_types:
arg
void *

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

variable_types:
buffer
char [1500]

variable_types: num int

variable_types: self int

variable_types: struct in_addr { unsigned int s_addr; } *


decompiled_code:
__int64 test1()
{
__int64 v0; // rbp
unsigned int v1; // eax
const void *v2; // rax
const void *v3; // rax
const void *v4; // rax
const void *v5; // rax
const void *v6; // rax
const void *v7; // rax
const void *v8; // rax
const void *v9; // rax
const void *v10; // rax
const void *v11; // rax
const void *v12; // rax
const void *v13; // rax
const void *v14; // rax
const void *v15; // rsi
__int64 v16; // r12
int v17; // ebp
int v19[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v0 = ida_encode_create(1LL, 11LL, 7LL);
v1 = ida_encode_block_size(v0);
printf("block size = %d\n", v1);
v19[0] = ida_encode_data(v0, str);
printf("encode size = %d\n", (unsigned int)v19[0]);
v2 = (const void *)ida_encode_key_vector(v0, 0LL, v19);
memcpy(&key, v2, v19[0]);
v3 = (const void *)ida_encode_output_vector(v0, 0LL, v19);
memcpy(&encode, v3, v19[0]);
v4 = (const void *)ida_encode_key_vector(v0, 1LL, v19);
memcpy((char *)&key + v19[0], v4, v19[0]);
v5 = (const void *)ida_encode_output_vector(v0, 1LL, v19);
memcpy((char *)&encode + v19[0], v5, v19[0]);
v6 = (const void *)ida_encode_key_vector(v0, 2LL, v19);
memcpy((char *)&key + 2 * v19[0], v6, v19[0]);
v7 = (const void *)ida_encode_output_vector(v0, 2LL, v19);
memcpy((char *)&encode + 2 * v19[0], v7, v19[0]);
v8 = (const void *)ida_encode_key_vector(v0, 3LL, v19);
memcpy((char *)&key + 3 * v19[0], v8, v19[0]);
v9 = (const void *)ida_encode_output_vector(v0, 3LL, v19);
memcpy((char *)&encode + 3 * v19[0], v9, v19[0]);
v10 = (const void *)ida_encode_key_vector(v0, 4LL, v19);
memcpy((char *)&key + 4 * v19[0], v10, v19[0]);
v11 = (const void *)ida_encode_output_vector(v0, 4LL, v19);
memcpy((char *)&encode + 4 * v19[0], v11, v19[0]);
v12 = (const void *)ida_encode_key_vector(v0, 9LL, v19);
memcpy((char *)&key + 5 * v19[0], v12, v19[0]);
v13 = (const void *)ida_encode_output_vector(v0, 9LL, v19);
memcpy((char *)&encode + 5 * v19[0], v13, v19[0]);
v14 = (const void *)ida_encode_key_vector(v0, 6LL, v19);
memcpy((char *)&key + 6 * v19[0], v14, v19[0]);
v15 = (const void *)ida_encode_output_vector(v0, 6LL, v19);
memcpy((char *)&encode + 6 * v19[0], v15, v19[0]);
ida_encode_free(v0);
v16 = ida_decode_create(1LL, 7LL);
v17 = ida_decode_set_key(v16, &key);
if ( v17 > 0 )
v17 = ida_decode_data(v16, &encode, decode);
printf("decode str : %s\n", decode);
printf("ret size = %d\n", (unsigned int)v17);
return ida_decode_free(v16);
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v0; // rbp
unsigned int v1; // eax
const void *v2; // rax
const void *v3; // rax
const void *v4; // rax
const void *v5; // rax
const void *v6; // rax
const void *v7; // rax
const void *v8; // rax
const void *v9; // rax
const void *v10; // rax
const void *v11; // rax
const void *v12; // rax
const void *v13; // rax
const void *v14; // rax
const void *v15; // rsi
__int64 v16; // r12
int v17; // ebp
int v19[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v0 = ida_encode_create(1LL, 11LL, 7LL);
v1 = ida_encode_block_size(v0);
printf("block size = %d\n", v1);
v19[0] = ida_encode_data(v0, str);
printf("encode size = %d\n", (unsigned int)v19[0]);
v2 = (const void *)ida_encode_key_vector(v0, 0LL, v19);
memcpy(&key, v2, v19[0]);
v3 = (const void *)ida_encode_output_vector(v0, 0LL, v19);
memcpy(&encode, v3, v19[0]);
v4 = (const void *)ida_encode_key_vector(v0, 1LL, v19);
memcpy((char *)&key + v19[0], v4, v19[0]);
v5 = (const void *)ida_encode_output_vector(v0, 1LL, v19);
memcpy((char *)&encode + v19[0], v5, v19[0]);
v6 = (const void *)ida_encode_key_vector(v0, 2LL, v19);
memcpy((char *)&key + 2 * v19[0], v6, v19[0]);
v7 = (const void *)ida_encode_output_vector(v0, 2LL, v19);
memcpy((char *)&encode + 2 * v19[0], v7, v19[0]);
v8 = (const void *)ida_encode_key_vector(v0, 3LL, v19);
memcpy((char *)&key + 3 * v19[0], v8, v19[0]);
v9 = (const void *)ida_encode_output_vector(v0, 3LL, v19);
memcpy((char *)&encode + 3 * v19[0], v9, v19[0]);
v10 = (const void *)ida_encode_key_vector(v0, 4LL, v19);
memcpy((char *)&key + 4 * v19[0], v10, v19[0]);
v11 = (const void *)ida_encode_output_vector(v0, 4LL, v19);
memcpy((char *)&encode + 4 * v19[0], v11, v19[0]);
v12 = (const void *)ida_encode_key_vector(v0, 9LL, v19);
memcpy((char *)&key + 5 * v19[0], v12, v19[0]);
v13 = (const void *)ida_encode_output_vector(v0, 9LL, v19);
memcpy((char *)&encode + 5 * v19[0], v13, v19[0]);
v14 = (const void *)ida_encode_key_vector(v0, 6LL, v19);
memcpy((char *)&key + 6 * v19[0], v14, v19[0]);
v15 = (const void *)ida_encode_output_vector(v0, 6LL, v19);
memcpy((char *)&encode + 6 * v19[0], v15, v19[0]);
ida_encode_free(v0);
v16 = ida_decode_create(1LL, 7LL);
v17 = ida_decode_set_key(v16, &key);
if ( v17 > 0 )
v17 = ida_decode_data(v16, &encode, decode);
printf("decode str : %s\n", decode);
printf("ret size = %d\n", (unsigned int)v17);
return ida_decode_free(v16);
}

original_code:
void test1(void)
{
 char *p;
 int index, size;
 struct ida_encode *enc;
 struct ida_decode *dec;
 enc = ida_encode_create(1, 11, 7);
 printf("block size = %d\n", ida_encode_block_size(enc));
 size = ida_encode_data(enc, str);
 printf("encode size = %d\n", size);
 {
  index = 0;
  p = ida_encode_key_vector(enc, index, &size);
  memcpy(key + size * 0, p, size);
  p = ida_encode_output_vector(enc, index, &size);
  memcpy(encode + size * 0, p, size);
  index = 1;
  p = ida_encode_key_vector(enc, index, &size);
  memcpy(key + size * 1, p, size);
  p = ida_encode_output_vector(enc, index, &size);
  memcpy(encode + size * 1, p, size);
  index = 2;
  p = ida_encode_key_vector(enc, index, &size);
  memcpy(key + size * 2, p, size);
  p = ida_encode_output_vector(enc, index, &size);
  memcpy(encode + size * 2, p, size);
  index = 3;
  p = ida_encode_key_vector(enc, index, &size);
  memcpy(key + size * 3, p, size);
  p = ida_encode_output_vector(enc, index, &size);
  memcpy(encode + size * 3, p, size);
  index = 4;
  p = ida_encode_key_vector(enc, index, &size);
  memcpy(key + size * 4, p, size);
  p = ida_encode_output_vector(enc, index, &size);
  memcpy(encode + size * 4, p, size);
  index = 9;
  p = ida_encode_key_vector(enc, index, &size);
  memcpy(key + size * 5, p, size);
  p = ida_encode_output_vector(enc, index, &size);
  memcpy(encode + size * 5, p, size);
  index = 6;
  p = ida_encode_key_vector(enc, index, &size);
  memcpy(key + size * 6, p, size);
  p = ida_encode_output_vector(enc, index, &size);
  memcpy(encode + size * 6, p, size);
 }
 ida_encode_free(enc);
 dec = ida_decode_create(1, 7);
 {
  int ret;
  ret = ida_decode_set_key(dec, key);
  if(ret > 0)
   ret = ida_decode_data(dec, encode, decode);
  printf("decode str : %s\n", decode);
  printf("ret size = %d\n", ret);
 }
 ida_decode_free(dec);
}

canonical_original_code:
void test1()
{
 char *p;
 int index; int size;
 struct ida_encode *enc;
 struct ida_decode *dec;
 enc = ida_encode_create(1, 11, 7);
 printf("block size = %d\n", ida_encode_block_size(enc));
 size = ida_encode_data(enc, str);
 printf("encode size = %d\n", size);
 {
  index = 0;
  p = ida_encode_key_vector(enc, index, &size);
  memcpy(key + size * 0, p, size);
  p = ida_encode_output_vector(enc, index, &size);
  memcpy(encode + size * 0, p, size);
  index = 1;
  p = ida_encode_key_vector(enc, index, &size);
  memcpy(key + size * 1, p, size);
  p = ida_encode_output_vector(enc, index, &size);
  memcpy(encode + size * 1, p, size);
  index = 2;
  p = ida_encode_key_vector(enc, index, &size);
  memcpy(key + size * 2, p, size);
  p = ida_encode_output_vector(enc, index, &size);
  memcpy(encode + size * 2, p, size);
  index = 3;
  p = ida_encode_key_vector(enc, index, &size);
  memcpy(key + size * 3, p, size);
  p = ida_encode_output_vector(enc, index, &size);
  memcpy(encode + size * 3, p, size);
  index = 4;
  p = ida_encode_key_vector(enc, index, &size);
  memcpy(key + size * 4, p, size);
  p = ida_encode_output_vector(enc, index, &size);
  memcpy(encode + size * 4, p, size);
  index = 9;
  p = ida_encode_key_vector(enc, index, &size);
  memcpy(key + size * 5, p, size);
  p = ida_encode_output_vector(enc, index, &size);
  memcpy(encode + size * 5, p, size);
  index = 6;
  p = ida_encode_key_vector(enc, index, &size);
  memcpy(key + size * 6, p, size);
  p = ida_encode_output_vector(enc, index, &size);
  memcpy(encode + size * 6, p, size);
 }
 ida_encode_free(enc);
 dec = ida_decode_create(1, 7);
 {
  int ret;
  ret = ida_decode_set_key(dec, key);
  if(ret > 0)
   ret = ida_decode_data(dec, encode, decode);
  printf("decode str : %s\n", decode);
  printf("ret size = %d\n", ret);
 }
 ida_decode_free(dec);
}

variable_types:
p
char *

variable_types: index int

variable_types: struct ida_encode { int width; int n; int m; int size; struct gf2_matrix { int rows; int cols; int width; unsigned char *values; } *key; struct gf2_matrix *input; struct gf2_matrix *output; } *

variable_types: struct ida_decode { int width; int m; int size; struct gf2_matrix { int rows; int cols; int width; unsigned char *values; } *key; struct gf2_matrix *input; struct gf2_matrix *output; } *

variable_types: ret int

user_defined_types: struct ida_encode { int width; int n; int m; int size; struct gf2_matrix *key; struct gf2_matrix *input; struct gf2_matrix *output; }

user_defined_types: struct ida_decode { int width; int m; int size; struct gf2_matrix *key; struct gf2_matrix *input; struct gf2_matrix *output; }


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
test1(argc, argv, envp);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func0(argc, argv, envp);
return 0;
}

original_code:
int main(void)
{
 test1();
 return 0;
}

canonical_original_code:
int main()
{
 test1();
 return 0;
}


decompiled_code:
void sensor_data()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
void sensor_data(unsigned int num, struct amt_sensor_data *sensor)
{
}

variable_types:
num
unsigned int

variable_types: struct amt_sensor_data { short sensor_type; float data[3]; } *


decompiled_code:
int __fastcall log_cb(__int64 a1, const char *a2)
{
return printf("%s", a2);
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1, const char *a2)
{
return printf("%s", a2);
}

original_code:
void log_cb(int tag, const char *log)
{
 printf("%s", log);
}

canonical_original_code:
void log_cb(int tag, char *log)
{
 printf("%s", log);
}

variable_types: tag int

variable_types:
log
char *


decompiled_code:
int __fastcall mouse_data(unsigned int a1, unsigned int a2, unsigned int a3, unsigned int a4)
{
return printf("%s x = %d y = %d button = %d press = %d\n", "mouse_data", a1, a2, a3, a4);
}

canonical_decompiled_code:
int __fastcall func2(unsigned int a1, unsigned int a2, unsigned int a3, unsigned int a4)
{
return printf("%s x = %d y = %d button = %d press = %d\n", "mouse_data", a1, a2, a3, a4);
}

original_code:
void mouse_data(int x, int y, int button, int press)
{
 printf("%s x = %d y = %d button = %d press = %d\n", __func__, x, y, button, press);
}

variable_types: x int

variable_types: y int

variable_types: button int

variable_types: press int


decompiled_code:
int __fastcall touch_data(unsigned int a1, unsigned int *a2, unsigned int *a3, unsigned int *a4)
{
return printf("%s num = %d x = %d y = %d press = %d\n", "touch_data", a1, *a2, *a3, *a4);
}

canonical_decompiled_code:
int __fastcall func3(unsigned int a1, unsigned int *a2, unsigned int *a3, unsigned int *a4)
{
return printf("%s num = %d x = %d y = %d press = %d\n", "touch_data", a1, *a2, *a3, *a4);
}

original_code:
void touch_data(unsigned int num, int *x, int *y, int *press)
{
 printf("%s num = %d x = %d y = %d press = %d\n", __func__, num, *x, *y, *press);
}

variable_types:
x
int *

variable_types:
y
int *

variable_types:
press
int *


decompiled_code:
int __fastcall key_data(unsigned int a1, unsigned int a2)
{
return printf("%s code = %d press = %d\n", "key_data", a1, a2);
}

canonical_decompiled_code:
int __fastcall func4(unsigned int a1, unsigned int a2)
{
return printf("%s code = %d press = %d\n", "key_data", a1, a2);
}

original_code:
void key_data(int code, int press)
{
 printf("%s code = %d press = %d\n", __func__, code, press);
}

variable_types: code int


decompiled_code:
// attributes: thunk
int update_test(const char *s)
{
return puts(s);
}

canonical_decompiled_code:
int func5(const char *s)
{
return puts(s);
}

original_code:
void update_test(char *test)
{
 printf("%s\n", test);
}

variable_types:
test
char *


original_code:
int galois_field_create_tables(int index, struct gf2_table *table)
{
 int i, j, size, prim_poly;
 if(!table)
  return -1;
 table->index = index;
 size = (1 << index) * sizeof(unsigned short);
 if(index == 8)
  prim_poly = prim_poly_8;
 else if(index == 16)
  prim_poly = prim_poly_16;
 else
  return -1;
 table->log = malloc(size);
 if(!table->log)
  return -1;
 table->exp = malloc(size);
 if(!table->exp)
 {
  free(table->log);
  table->log = ((void *)0);
  return -1;
 }
 if(index == 8)
 {
  table->mult = malloc((1 << 8) * (1 << 8));
  if(!table->mult)
  {
   free(table->log);
   free(table->exp);
   table->log = ((void *)0);
   table->exp = ((void *)0);
   return -1;
  }
  table->div = malloc((1 << 8) * (1 << 8));
  if(!table->div)
  {
   free(table->log);
   free(table->exp);
   free(table->mult);
   table->log = ((void *)0);
   table->exp = ((void *)0);
   table->mult = ((void *)0);
   return -1;
  }
 }
 for(i = 0, j = 1; i < (1 << index); i++)
 {
  table->log[j] = (unsigned short)i;
  table->exp[i] = (unsigned short)j;
  j = j << 1;
  if(j & (1 << index))
   j = j ^ prim_poly;
 }
 table->log[1] = 0;
 if(table->mult)
 {
  unsigned short x, y, p, q, logx, logy;
  for(x = 0; x < (1 << 8); x++)
  {
   for(y = 0; y < (1 << 8); y++)
   {
    i = (x << 8) | y;
    if(y == 0)
    {
     table->mult[i] = 0;
     table->div[i] = 0xff;
     continue;
    }
    if(x == 0)
    {
     table->mult[i] = 0;
     table->div[i] = 0;
     continue;
    }
    logx = table->log[x];
    logy = table->log[y];
    p = logx + logy;
    if(p >= ((1 << 8) - 1))
     p -= (1 << 8) - 1;
    if(logx < logy)
     logx += (1 << 8) - 1;
    q = logx - logy;
    table->mult[i] = table->exp[p] & ((1 << 8) - 1);
    table->div[i] = table->exp[q] & ((1 << 8) - 1);
   }
  }
 }
 return 0;
}

canonical_original_code:
int galois_field_create_tables(int index, struct gf2_table *table)
{
 int i; int j; int size; int prim_poly;
 if(!table)
  return -1;
 table->index = index;
 size = (1 << index) * sizeof(unsigned short);
 if(index == 8)
  prim_poly = prim_poly_8;
 else if(index == 16)
  prim_poly = prim_poly_16;
 else
  return -1;
 table->log = malloc(size);
 if(!table->log)
  return -1;
 table->exp = malloc(size);
 if(!table->exp)
 {
  free(table->log);
  table->log = ((void *)0);
  return -1;
 }
 if(index == 8)
 {
  table->mult = malloc((1 << 8) * (1 << 8));
  if(!table->mult)
  {
   free(table->log);
   free(table->exp);
   table->log = ((void *)0);
   table->exp = ((void *)0);
   return -1;
  }
  table->div = malloc((1 << 8) * (1 << 8));
  if(!table->div)
  {
   free(table->log);
   free(table->exp);
   free(table->mult);
   table->log = ((void *)0);
   table->exp = ((void *)0);
   table->mult = ((void *)0);
   return -1;
  }
 }
 for(i = 0, j = 1; i < (1 << index); i++)
 {
  table->log[j] = (unsigned short)i;
  table->exp[i] = (unsigned short)j;
  j = j << 1;
  if(j & (1 << index))
   j = j ^ prim_poly;
 }
 table->log[1] = 0;
 if(table->mult)
 {
  unsigned short x; unsigned short y; unsigned short p; unsigned short q; unsigned short logx; unsigned short logy;
  for(x = 0; x < (1 << 8); x++)
  {
   for(y = 0; y < (1 << 8); y++)
   {
    i = (x << 8) | y;
    if(y == 0)
    {
     table->mult[i] = 0;
     table->div[i] = 0xff;
     continue;
    }
    if(x == 0)
    {
     table->mult[i] = 0;
     table->div[i] = 0;
     continue;
    }
    logx = table->log[x];
    logy = table->log[y];
    p = logx + logy;
    if(p >= ((1 << 8) - 1))
     p -= (1 << 8) - 1;
    if(logx < logy)
     logx += (1 << 8) - 1;
    q = logx - logy;
    table->mult[i] = table->exp[p] & ((1 << 8) - 1);
    table->div[i] = table->exp[q] & ((1 << 8) - 1);
   }
  }
 }
 return 0;
}

variable_types: index int

variable_types: struct gf2_table { int index; unsigned short *log; unsigned short *exp; unsigned char *mult; unsigned char *div; } *

variable_types: i int

variable_types: j int

variable_types: size int

variable_types:
x
unsigned short

variable_types:
y
unsigned short

variable_types:
p
unsigned short

variable_types:
q
unsigned short

variable_types:
logx
unsigned short

variable_types:
logy
unsigned short


decompiled_code:
__int64 __fastcall galois_multiply_w8(unsigned __int8 a1, unsigned __int8 a2)
{
return *((unsigned __int8 *)qword_518 + (a2 | (a1 << 8)));
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int8 a1, unsigned __int8 a2)
{
return *((unsigned __int8 *)qword_518 + (a2 | (a1 << 8)));
}

original_code:
unsigned char galois_multiply_w8(unsigned char x, unsigned char y)
{
 return gf2_table_8.mult[(x << 8) | y];
}

variable_types:
x
unsigned char

variable_types:
y
unsigned char

return_type: unsigned char


decompiled_code:
__int64 __fastcall galois_divide_w8(unsigned __int8 a1, unsigned __int8 a2)
{
return *((unsigned __int8 *)qword_520 + (a2 | (a1 << 8)));
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int8 a1, unsigned __int8 a2)
{
return *((unsigned __int8 *)qword_520 + (a2 | (a1 << 8)));
}

original_code:
unsigned char galois_divide_w8(unsigned char x, unsigned char y)
{
 return gf2_table_8.div[(x << 8) | y];
}


decompiled_code:
__int64 __fastcall galois_multiply_w16(unsigned __int16 a1, unsigned __int16 a2)
{
int v2; // edx
__int64 v3; // rax

if ( !a1 || !a2 )
return 0LL;
v2 = *((unsigned __int16 *)qword_4C8 + a1) + *((unsigned __int16 *)qword_4C8 + a2);
v3 = (unsigned int)(v2 - 0xFFFF);
if ( v2 <= 65534 )
v3 = *((unsigned __int16 *)qword_4C8 + a1) + (unsigned int)*((unsigned __int16 *)qword_4C8 + a2);
return *((unsigned __int16 *)qword_4D0 + v3);
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned __int16 a1, unsigned __int16 a2)
{
int v2; // edx
__int64 v3; // rax

if ( !a1 || !a2 )
return 0LL;
v2 = *((unsigned __int16 *)qword_4C8 + a1) + *((unsigned __int16 *)qword_4C8 + a2);
v3 = (unsigned int)(v2 - 0xFFFF);
if ( v2 <= 65534 )
v3 = *((unsigned __int16 *)qword_4C8 + a1) + (unsigned int)*((unsigned __int16 *)qword_4C8 + a2);
return *((unsigned __int16 *)qword_4D0 + v3);
}

original_code:
unsigned short galois_multiply_w16(unsigned short x, unsigned short y)
{
 unsigned int p;
 unsigned short logx, logy;
 if(x == 0 || y == 0)
  return 0;
 logx = gf2_table_16.log[x];
 logy = gf2_table_16.log[y];
 p = logx + logy;
 if(p >= ((1 << 16) - 1))
  p -= (1 << 16) - 1;
 return gf2_table_16.exp[p];
}

canonical_original_code:
unsigned short galois_multiply_w16(unsigned short x, unsigned short y)
{
 unsigned int p;
 unsigned short logx; unsigned short logy;
 if(x == 0 || y == 0)
  return 0;
 logx = gf2_table_16.log[x];
 logy = gf2_table_16.log[y];
 p = logx + logy;
 if(p >= ((1 << 16) - 1))
  p -= (1 << 16) - 1;
 return gf2_table_16.exp[p];
}

variable_types:
p
unsigned int

return_type: unsigned short


decompiled_code:
__int64 __fastcall galois_divide_w16(unsigned __int16 a1, unsigned __int16 a2)
{
__int64 result; // rax
unsigned __int16 v3; // cx
int v4; // esi
int v5; // eax

result = 0xFFFFFFFFLL;
if ( a2 )
{
result = 0LL;
if ( a1 )
{
v3 = *((_WORD *)qword_4C8 + a1);
v4 = *((unsigned __int16 *)qword_4C8 + a2);
v5 = v3;
if ( v3 < (unsigned __int16)v4 )
v5 = v3 + 0xFFFF;
result = *((unsigned __int16 *)qword_4D0 + (unsigned int)(v5 - v4));
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned __int16 a1, unsigned __int16 a2)
{
__int64 result; // rax
unsigned __int16 v3; // cx
int v4; // esi
int v5; // eax

result = 0xFFFFFFFFLL;
if ( a2 )
{
result = 0LL;
if ( a1 )
{
v3 = *((_WORD *)qword_4C8 + a1);
v4 = *((unsigned __int16 *)qword_4C8 + a2);
v5 = v3;
if ( v3 < (unsigned __int16)v4 )
v5 = v3 + 0xFFFF;
result = *((unsigned __int16 *)qword_4D0 + (unsigned int)(v5 - v4));
}
}
return result;
}

original_code:
unsigned short galois_divide_w16(unsigned short x, unsigned short y)
{
 unsigned int q;
 unsigned short logx, logy;
 if(y == 0)
  return 0xffff;
 if(x == 0)
  return 0;
 logx = gf2_table_16.log[x];
 logy = gf2_table_16.log[y];
 q = logx;
 if(q < logy)
  q += (1 << 16) - 1;
 q -= logy;
 return gf2_table_16.exp[q];
}

canonical_original_code:
unsigned short galois_divide_w16(unsigned short x, unsigned short y)
{
 unsigned int q;
 unsigned short logx; unsigned short logy;
 if(y == 0)
  return 0xffff;
 if(x == 0)
  return 0;
 logx = gf2_table_16.log[x];
 logy = gf2_table_16.log[y];
 q = logx;
 if(q < logy)
  q += (1 << 16) - 1;
 q -= logy;
 return gf2_table_16.exp[q];
}

variable_types:
q
unsigned int


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

if ( a1 == 8 )
{
if ( !gf2_flag_8 )
{
result = galois_field_create_tables(8, (__int64)&gf2_table_8);
gf2_flag_8 = 1;
}
}
else if ( a1 == 16 )
{
result = (unsigned int)gf2_flag_16;
if ( !gf2_flag_16 )
{
result = galois_field_create_tables(16, (__int64)&gf2_table_16);
gf2_flag_16 = 1;
}
}
return result;
}

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

if ( a1 == 8 )
{
if ( !gf2_flag_8 )
{
result = func0(8, (__int64)&gf2_table_8);
gf2_flag_8 = 1;
}
}
else if ( a1 == 16 )
{
result = (unsigned int)gf2_flag_16;
if ( !gf2_flag_16 )
{
result = func0(16, (__int64)&gf2_table_16);
gf2_flag_16 = 1;
}
}
return result;
}

original_code:
void galois_init_table(int w)
{
 if(w == 8)
 {
  if(!gf2_flag_8)
  {
   galois_field_create_tables(8, &gf2_table_8);
   gf2_flag_8 = 1;
  }
 }
 else if(w == 16)
 {
  if(!gf2_flag_16)
  {
   galois_field_create_tables(16, &gf2_table_16);
   gf2_flag_16 = 1;
  }
 }
}

variable_types: w int


decompiled_code:
void galois_free_table()
{
if ( !gf2_flag_8 )
{
if ( !gf2_flag_16 )
return;
LABEL_7:
free(qword_4C8);
free(qword_4D0);
qword_4C8 = 0LL;
qword_4D0 = 0LL;
gf2_flag_16 = 0;
return;
}
free(ptr);
free(qword_510);
ptr = 0LL;
qword_510 = 0LL;
if ( qword_518 )
{
free(qword_518);
qword_518 = 0LL;
free(qword_520);
qword_520 = 0LL;
}
gf2_flag_8 = 0;
if ( gf2_flag_16 )
goto LABEL_7;
}

canonical_decompiled_code:
void func6()
{
if ( !gf2_flag_8 )
{
if ( !gf2_flag_16 )
return;
LABEL_7:
free(qword_4C8);
free(qword_4D0);
qword_4C8 = 0LL;
qword_4D0 = 0LL;
gf2_flag_16 = 0;
return;
}
free(ptr);
free(qword_510);
ptr = 0LL;
qword_510 = 0LL;
if ( qword_518 )
{
free(qword_518);
qword_518 = 0LL;
free(qword_520);
qword_520 = 0LL;
}
gf2_flag_8 = 0;
if ( gf2_flag_16 )
goto LABEL_7;
}

original_code:
void galois_free_table(void)
{
 if(gf2_flag_8)
 {
  free(gf2_table_8.log);
  free(gf2_table_8.exp);
  gf2_table_8.log = ((void *)0);
  gf2_table_8.exp = ((void *)0);
  if(gf2_table_8.mult)
  {
   free(gf2_table_8.mult);
   gf2_table_8.mult = ((void *)0);
   free(gf2_table_8.div);
   gf2_table_8.div = ((void *)0);
  }
  gf2_flag_8 = 0;
 }
 if(gf2_flag_16)
 {
  free(gf2_table_16.log);
  free(gf2_table_16.exp);
  gf2_table_16.log = ((void *)0);
  gf2_table_16.exp = ((void *)0);
  gf2_flag_16 = 0;
 }
}

canonical_original_code:
void galois_free_table()
{
 if(gf2_flag_8)
 {
  free(gf2_table_8.log);
  free(gf2_table_8.exp);
  gf2_table_8.log = ((void *)0);
  gf2_table_8.exp = ((void *)0);
  if(gf2_table_8.mult)
  {
   free(gf2_table_8.mult);
   gf2_table_8.mult = ((void *)0);
   free(gf2_table_8.div);
   gf2_table_8.div = ((void *)0);
  }
  gf2_flag_8 = 0;
 }
 if(gf2_flag_16)
 {
  free(gf2_table_16.log);
  free(gf2_table_16.exp);
  gf2_table_16.log = ((void *)0);
  gf2_table_16.exp = ((void *)0);
  gf2_flag_16 = 0;
 }
}


decompiled_code:
__int64 __fastcall get_matrix_vector(__int64 a1, int a2, int *a3)
{
int v3; // eax

if ( !a1 || *(_DWORD *)a1 <= a2 )
return 0LL;
v3 = *(_DWORD *)(a1 + 8) * *(_DWORD *)(a1 + 4);
if ( a3 )
*a3 = v3;
return *(_QWORD *)(a1 + 16) + v3 * a2;
}

original_code:
static char *get_matrix_vector(struct gf2_matrix *matrix, int index, int *size)
{
 int length;
 if(!matrix)
  return ((void *)0);
 if(index >= matrix->rows)
  return ((void *)0);
 length = matrix->cols * matrix->width;
 if(size)
  *size = length;
 return (char *)(matrix->values + index * length);
}

variable_types: struct gf2_matrix { int rows; int cols; int width; unsigned char *values; } *

variable_types:
size
int *

variable_types: length int

return_type: char *


decompiled_code:
__int64 __fastcall alloc_matrix(int a1, int a2, int a3)
{
__int64 v4; // r12
void *v5; // rax
__int64 v7; // rdi

v4 = alloc_empty_matrix();
if ( v4 )
{
v5 = malloc(a3 * a2 * a1);
*(_QWORD *)(v4 + 16) = v5;
if ( !v5 )
{
v7 = v4;
v4 = 0LL;
free_matrix(v7);
}
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, int a2, int a3)
{
__int64 v4; // r12
void *v5; // rax
__int64 v7; // rdi

v4 = alloc_empty_matrix();
if ( v4 )
{
v5 = malloc(a3 * a2 * a1);
*(_QWORD *)(v4 + 16) = v5;
if ( !v5 )
{
v7 = v4;
v4 = 0LL;
free_matrix(v7);
}
}
return v4;
}

original_code:
static struct gf2_matrix *alloc_matrix(int w, int n, int m)
{
 struct gf2_matrix *matrix = alloc_empty_matrix(w, n, m);
 if(!matrix)
  return ((void *)0);
 matrix->values = malloc(w * n * m);
 if(!matrix->values)
 {
  free_matrix(matrix);
  return ((void *)0);
 }
 return matrix;
}

variable_types: n int

variable_types: m int

return_type: struct gf2_matrix { int rows; int cols; int width; unsigned char *values; } *


decompiled_code:
void __fastcall ida_encode_free(void *ptr)
{
if ( ptr )
{
free_matrix(*((_QWORD *)ptr + 2));
free_matrix(*((_QWORD *)ptr + 4));
free_matrix2(*((_QWORD *)ptr + 3));
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
if ( ptr )
{
free_matrix(*((_QWORD *)ptr + 2));
free_matrix(*((_QWORD *)ptr + 4));
free_matrix2(*((_QWORD *)ptr + 3));
free(ptr);
}
}

original_code:
void ida_encode_free(struct ida_encode *ida)
{
 if(!ida)
  return;
 free_matrix(ida->key);
 free_matrix(ida->output);
 free_matrix2(ida->input);
 free(ida);
}

variable_types: struct ida_encode { int width; int n; int m; int size; struct gf2_matrix { int rows; int cols; int width; unsigned char *values; } *key; struct gf2_matrix *input; struct gf2_matrix *output; } *


decompiled_code:
__int64 __fastcall ida_encode_block_size(_DWORD *a1)
{
__int64 result; // rax

if ( a1 )
result = (unsigned int)(a1[2] * a1[2] * *a1);
else
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(_DWORD *a1)
{
__int64 result; // rax

if ( a1 )
result = (unsigned int)(a1[2] * a1[2] * *a1);
else
result = 0LL;
return result;
}

original_code:
int ida_encode_block_size(struct ida_encode *ida)
{
 if(!ida)
  return 0;
 return ida->width * ida->m * ida->m;
}

user_defined_types: struct gf2_matrix { int rows; int cols; int width; unsigned char *values; }


original_code:
int ida_encode_data(struct ida_encode *ida, void *input)
{
 if(!ida || !input)
  return 0;
 ida->input->values = input;
 multiply_matrix(ida->key, ida->input, ida->output);
 return ida->width * ida->m * ida->m;
}

variable_types:
input
void *


decompiled_code:
__int64 __fastcall ida_encode_key_vector(__int64 a1, int a2, int *a3)
{
return get_matrix_vector(*(_QWORD *)(a1 + 16), a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, int a2, int *a3)
{
return func0(*(_QWORD *)(a1 + 16), a2, a3);
}

original_code:
char *ida_encode_key_vector(struct ida_encode *ida, int index, int *size)
{
 return get_matrix_vector(ida->key, index, size);
}

variable_types: index int


decompiled_code:
__int64 __fastcall ida_encode_output_vector(__int64 a1, int a2, int *a3)
{
return get_matrix_vector(*(_QWORD *)(a1 + 32), a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, int a2, int *a3)
{
return func0(*(_QWORD *)(a1 + 32), a2, a3);
}

original_code:
char *ida_encode_output_vector(struct ida_encode *ida, int index, int *size)
{
 return get_matrix_vector(ida->output, index, size);
}