main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rbx
int v4; // ebx
unsigned int v5; // eax
unsigned int v6; // ebp
__int64 v7; // rax
const char *v8; // rax
const char *v10; // rax
char v11; // zf
char v12; // sf
char v13; // of

signal(3, signal_handler);
signal(15, signal_handler);
signal(1, signal_handler);
signal(2, signal_handler);
setbuf(stdout, 0LL);
if ( argc <= 1 )
{
LABEL_12:
st = lo_server_thread_new();
lo_server_thread_start();
loa = lo_address_new();
mainwin = initscr();
if ( mainwin )
{
noecho();
v4 = 1;
curs_set(0);
keypad(mainwin, 1);
if ( verbose == 1 )
{
mvprintw(1, 3, "___ sk (sendkeys) ___");
v4 = 5;
mvprintw(2, 3, "sending OSC to %s:%s", osc_send_to_host, osc_send_to_port);
mvprintw(3, 3, "sending OSC from (my) port %s", osc_my_server_port);
}
if ( !quiet )
mvprintw(v4, 3, "(waiting for input)");
while ( 1 )
{
wrefresh(stdscr__NCURSES6_TINFO_5_0_19991023);
v5 = wgetch(stdscr__NCURSES6_TINFO_5_0_19991023);
v6 = v5;
if ( v5 == -1 )
break;
v7 = checkKey(v5);
sendKey(v6, v7);
winsdelln(stdscr__NCURSES6_TINFO_5_0_19991023, -1);
if ( !quiet )
{
if ( verbose == 1 )
{
mvprintw(v4, 3, "0x%x", v6);
v10 = (const char *)checkKey(v6);
mvprintw(v4, 11, "%s", v10);
if ( v12 ^ v13 | v11 )
{
switch ( indicationCounter )
{
case 0:
case 4:
goto LABEL_26;
case 1:
case 5:
mvprintw(v4, 23, "(/)");
goto LABEL_27;
case 2:
case 6:
mvprintw(v4, 23, "(-)");
goto LABEL_27;
case 3:
case 7:
mvprintw(v4, 23, "(\\)");
goto LABEL_27;
default:
goto LABEL_27;
}
}
indicationCounter = 0;
LABEL_26:
mvprintw(v4, 23, "(|)");
LABEL_27:
++indicationCounter;
}
else
{
v8 = (const char *)checkKey(v6);
mvprintw(v4, 3, "%s", v8);
}
}
}
signal_handler(3);
}
fwrite("could not initialize ncurses\n", 1uLL, 0x1DuLL, stderr);
exit(1);
}
v3 = (char *)argv[1];
if ( !strcmp(v3, "-h") || !strcmp(v3, "--help") )
{
puts("syntax: sk <osc local port> <osc remote host> <osc remote port>\n");
}
else if ( !strcmp(v3, "-v") || !strcmp(v3, "--version") )
{
printf("%f\n", 0.2);
}
else
{
if ( strcmp(v3, "-i") && strcmp(v3, "--info") )
{
if ( argc <= 3 )
{
if ( argc != 3 )
goto LABEL_11;
}
else
{
osc_send_to_port = (char *)argv[3];
}
osc_send_to_host = (char *)argv[2];
LABEL_11:
osc_my_server_port = v3;
goto LABEL_12;
}
printf("sk version %f, Copyright (C) 2013 Thomas Brand\n", 0.2);
puts("sk comes with ABSOLUTELY NO WARRANTY;");
puts("This is free software, and you are welcome to redistribute it");
puts("under certain conditions; see COPYING for details.");
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rbx
int v4; // ebx
unsigned int v5; // eax
unsigned int v6; // ebp
__int64 v7; // rax
const char *v8; // rax
const char *v10; // rax
char v11; // zf
char v12; // sf
char v13; // of

signal(3, signal_handler);
signal(15, signal_handler);
signal(1, signal_handler);
signal(2, signal_handler);
setbuf(stdout, 0LL);
if ( argc <= 1 )
{
LABEL_12:
st = lo_server_thread_new();
lo_server_thread_start();
loa = lo_address_new();
mainwin = initscr();
if ( mainwin )
{
noecho();
v4 = 1;
curs_set(0);
keypad(mainwin, 1);
if ( verbose == 1 )
{
mvprintw(1, 3, "___ sk (sendkeys) ___");
v4 = 5;
mvprintw(2, 3, "sending OSC to %s:%s", osc_send_to_host, osc_send_to_port);
mvprintw(3, 3, "sending OSC from (my) port %s", osc_my_server_port);
}
if ( !quiet )
mvprintw(v4, 3, "(waiting for input)");
while ( 1 )
{
wrefresh(stdscr__NCURSES6_TINFO_5_0_19991023);
v5 = wgetch(stdscr__NCURSES6_TINFO_5_0_19991023);
v6 = v5;
if ( v5 == -1 )
break;
v7 = func9(v5);
func10(v6, v7);
winsdelln(stdscr__NCURSES6_TINFO_5_0_19991023, -1);
if ( !quiet )
{
if ( verbose == 1 )
{
mvprintw(v4, 3, "0x%x", v6);
v10 = (const char *)func9(v6);
mvprintw(v4, 11, "%s", v10);
if ( v12 ^ v13 | v11 )
{
switch ( indicationCounter )
{
case 0:
case 4:
goto LABEL_26;
case 1:
case 5:
mvprintw(v4, 23, "(/)");
goto LABEL_27;
case 2:
case 6:
mvprintw(v4, 23, "(-)");
goto LABEL_27;
case 3:
case 7:
mvprintw(v4, 23, "(\\)");
goto LABEL_27;
default:
goto LABEL_27;
}
}
indicationCounter = 0;
LABEL_26:
mvprintw(v4, 23, "(|)");
LABEL_27:
++indicationCounter;
}
else
{
v8 = (const char *)func9(v6);
mvprintw(v4, 3, "%s", v8);
}
}
}
func8(3);
}
fwrite("could not initialize ncurses\n", 1uLL, 0x1DuLL, stderr);
exit(1);
}
v3 = (char *)argv[1];
if ( !strcmp(v3, "-h") || !strcmp(v3, "--help") )
{
puts("syntax: sk <osc local port> <osc remote host> <osc remote port>\n");
}
else if ( !strcmp(v3, "-v") || !strcmp(v3, "--version") )
{
printf("%f\n", 0.2);
}
else
{
if ( strcmp(v3, "-i") && strcmp(v3, "--info") )
{
if ( argc <= 3 )
{
if ( argc != 3 )
goto LABEL_11;
}
else
{
osc_send_to_port = (char *)argv[3];
}
osc_send_to_host = (char *)argv[2];
LABEL_11:
osc_my_server_port = v3;
goto LABEL_12;
}
printf("sk version %f, Copyright (C) 2013 Thomas Brand\n", 0.2);
puts("sk comes with ABSOLUTELY NO WARRANTY;");
puts("This is free software, and you are welcome to redistribute it");
puts("under certain conditions; see COPYING for details.");
}
return 0;
}

original_code:
int main (int argc, char *argv[])
{
 int ch;
 signal(3, signal_handler);
 signal(15, signal_handler);
 signal(1, signal_handler);
 signal(2, signal_handler);
 setbuf(stdout, ((void *)0));
 if (argc >=2 &&
  (strcmp(argv[1], "-h")==0 || strcmp(argv[1], "--help")==0))
 {
  printf("syntax: sk <osc local port> <osc remote host> <osc remote port>\n\n");
  return(0);
 }
 else if (argc >= 2 &&
  (strcmp(argv[1], "-v")==0 || strcmp(argv[1], "--version")==0))
 {
  printf("%f\n", version);
  return(0);
 }
 if (argc >= 2 &&
  (strcmp(argv[1], "-i")==0 || strcmp(argv[1], "--info")==0))
 {
  printf("sk version %f, Copyright (C) 2013  Thomas Brand\n", version);
  printf("sk comes with ABSOLUTELY NO WARRANTY;\n");
  printf("This is free software, and you are welcome to redistribute it\n");
  printf("under certain conditions; see COPYING for details.\n");
  return(0);
 }
 if (argc >= 4)
 {
  osc_send_to_port=argv[3];
 }
 if (argc >= 3)
 {
  osc_send_to_host=argv[2];
 }
 if (argc >= 2)
 {
  osc_my_server_port=argv[1];
 }
 st=lo_server_thread_new(osc_my_server_port, error);
 lo_server_thread_start(st);
 loa=lo_address_new(osc_send_to_host, osc_send_to_port);
 if ((mainwin=initscr())==((void *)0))
 {
  fprintf(stderr, "could not initialize ncurses\n");
  exit(1);
 }
 noecho();
 curs_set(0);
 keypad(mainwin, 1);
 int indent=3;
 int lastLine=1;
 if(verbose==1)
 {
  mvprintw(1, indent, "___ sk (sendkeys) ___");
  mvprintw(2, indent, "sending OSC to %s:%s", osc_send_to_host, osc_send_to_port);
  mvprintw(3, indent, "sending OSC from (my) port %s", osc_my_server_port);
  lastLine=5;
 }
 if(quiet==0)
 {
  mvprintw(lastLine, indent, "(waiting for input)");
 }
 wrefresh(stdscr);
 while (1)
 {
  ch=wgetch(stdscr);
  if(ch==-1)
  {
   signal_handler(3);
  }
  sendKey(ch, checkKey(ch));
  winsdelln(stdscr,-1);
  if(quiet==0 && verbose==1)
  {
   mvprintw(lastLine, indent, "0x%x", ch);
   mvprintw(lastLine, indent+8, "%s", checkKey(ch));
   if(indicationCounter>7)
   {
    indicationCounter=0;
   }
   switch(indicationCounter)
   {
    case 0:
     mvprintw(lastLine, indent+20, "(|)");
     break;
    case 1:
     mvprintw(lastLine, indent+20, "(/)");
     break;
    case 2:
     mvprintw(lastLine, indent+20, "(-)");
     break;
    case 3:
     mvprintw(lastLine, indent+20, "(\\)");
     break;
    case 4:
     mvprintw(lastLine, indent+20, "(|)");
     break;
    case 5:
     mvprintw(lastLine, indent+20, "(/)");
     break;
    case 6:
     mvprintw(lastLine, indent+20, "(-)");
     break;
    case 7:
     mvprintw(lastLine, indent+20, "(\\)");
     break;
   }
   indicationCounter++;
  }
  else if(quiet==0)
  {
   mvprintw(lastLine, indent, "%s", checkKey(ch));
  }
  wrefresh(stdscr);
 }
}

canonical_original_code:
int main(int argc, char *argv[])
{
 int ch;
 signal(3, signal_handler);
 signal(15, signal_handler);
 signal(1, signal_handler);
 signal(2, signal_handler);
 setbuf(stdout, ((void *)0));
 if (argc >=2 &&
  (strcmp(argv[1], "-h")==0 || strcmp(argv[1], "--help")==0))
 {
  printf("syntax: sk <osc local port> <osc remote host> <osc remote port>\n\n");
  return(0);
 }
 else if (argc >= 2 &&
  (strcmp(argv[1], "-v")==0 || strcmp(argv[1], "--version")==0))
 {
  printf("%f\n", version);
  return(0);
 }
 if (argc >= 2 &&
  (strcmp(argv[1], "-i")==0 || strcmp(argv[1], "--info")==0))
 {
  printf("sk version %f, Copyright (C) 2013  Thomas Brand\n", version);
  printf("sk comes with ABSOLUTELY NO WARRANTY;\n");
  printf("This is free software, and you are welcome to redistribute it\n");
  printf("under certain conditions; see COPYING for details.\n");
  return(0);
 }
 if (argc >= 4)
 {
  osc_send_to_port=argv[3];
 }
 if (argc >= 3)
 {
  osc_send_to_host=argv[2];
 }
 if (argc >= 2)
 {
  osc_my_server_port=argv[1];
 }
 st=lo_server_thread_new(osc_my_server_port, error);
 lo_server_thread_start(st);
 loa=lo_address_new(osc_send_to_host, osc_send_to_port);
 if ((mainwin=initscr())==((void *)0))
 {
  fprintf(stderr, "could not initialize ncurses\n");
  exit(1);
 }
 noecho();
 curs_set(0);
 keypad(mainwin, 1);
 int indent = 3;
 int lastLine = 1;
 if(verbose==1)
 {
  mvprintw(1, indent, "___ sk (sendkeys) ___");
  mvprintw(2, indent, "sending OSC to %s:%s", osc_send_to_host, osc_send_to_port);
  mvprintw(3, indent, "sending OSC from (my) port %s", osc_my_server_port);
  lastLine=5;
 }
 if(quiet==0)
 {
  mvprintw(lastLine, indent, "(waiting for input)");
 }
 wrefresh(stdscr);
 while (1)
 {
  ch=wgetch(stdscr);
  if(ch==-1)
  {
   signal_handler(3);
  }
  sendKey(ch, checkKey(ch));
  winsdelln(stdscr,-1);
  if(quiet==0 && verbose==1)
  {
   mvprintw(lastLine, indent, "0x%x", ch);
   mvprintw(lastLine, indent+8, "%s", checkKey(ch));
   if(indicationCounter>7)
   {
    indicationCounter=0;
   }
   switch(indicationCounter)
   {
    case 0:
     mvprintw(lastLine, indent+20, "(|)");
     break;
    case 1:
     mvprintw(lastLine, indent+20, "(/)");
     break;
    case 2:
     mvprintw(lastLine, indent+20, "(-)");
     break;
    case 3:
     mvprintw(lastLine, indent+20, "(\\)");
     break;
    case 4:
     mvprintw(lastLine, indent+20, "(|)");
     break;
    case 5:
     mvprintw(lastLine, indent+20, "(/)");
     break;
    case 6:
     mvprintw(lastLine, indent+20, "(-)");
     break;
    case 7:
     mvprintw(lastLine, indent+20, "(\\)");
     break;
   }
   indicationCounter++;
  }
  else if(quiet==0)
  {
   mvprintw(lastLine, indent, "%s", checkKey(ch));
  }
  wrefresh(stdscr);
 }
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: ch int

variable_types: indent int

variable_types: lastLine int


error

decompiled_code:
int __fastcall error(unsigned int a1, const char *a2, const char *a3)
{
return printf("liblo server error %d in path %s: %s\n", a1, a3, a2);
}

canonical_decompiled_code:
int __fastcall func7(unsigned int a1, const char *a2, const char *a3)
{
return printf("liblo server error %d in path %s: %s\n", a1, a3, a2);
}

original_code:
void error(int num, const char *msg, const char *path)
{
 printf("liblo server error %d in path %s: %s\n", num, path, msg);
}

canonical_original_code:
void error(int num, char *msg, char *path)
{
 printf("liblo server error %d in path %s: %s\n", num, path, msg);
}

variable_types: num int

variable_types:
msg
char *

variable_types:
path
char *

return_type: void


decompiled_code:
void __noreturn signal_handler()
{
delwin(mainwin);
endwin();
wrefresh(stdscr__NCURSES6_TINFO_5_0_19991023);
echo();
curs_set(1);
exit(0);
}

canonical_decompiled_code:
void __noreturn func8()
{
delwin(mainwin);
endwin();
wrefresh(stdscr__NCURSES6_TINFO_5_0_19991023);
echo();
curs_set(1);
exit(0);
}

original_code:
static void signal_handler(int sig)
{
 delwin(mainwin);
 endwin();
 wrefresh(stdscr);
 echo();
 curs_set(1);
 exit(0);
}

variable_types: sig int


checkKey

decompiled_code:
char *__fastcall checkKey(int a1)
{
int v1; // eax
int *v2; // rdx
int v3; // ecx
char *result; // rax

if ( ((*__ctype_b_loc())[a1] & 0x4000) != 0 && (a1 & 0x100) == 0 )
{
keych_0 = a1;
result = &keych_0;
}
else
{
v1 = keys;
v2 = (int *)&unk_404138;
v3 = 0;
do
{
if ( a1 == v1 )
break;
v1 = *v2;
v2 += 6;
++v3;
}
while ( v1 != -1 );
result = &aArrowUp[24 * v3];
}
return result;
}

canonical_decompiled_code:
char *__fastcall func9(int a1)
{
int v1; // eax
int *v2; // rdx
int v3; // ecx
char *result; // rax

if ( ((*__ctype_b_loc())[a1] & 0x4000) != 0 && (a1 & 0x100) == 0 )
{
keych_0 = a1;
result = &keych_0;
}
else
{
v1 = keys;
v2 = (int *)&unk_404138;
v3 = 0;
do
{
if ( a1 == v1 )
break;
v1 = *v2;
v2 += 6;
++v3;
}
while ( v1 != -1 );
result = &aArrowUp[24 * v3];
}
return result;
}

original_code:
char *checkKey(int ch)
{
 static char keych[2]={0};
 if (((*__ctype_b_loc ())[(int) ((ch))] & (unsigned short int) _ISprint) && !(ch & 0400))
 {
  keych[0]=ch;
  return keych;
 }
 else
 {
  int n=0;
  do
  {
   if (keys[n].code==ch)
   {
    return keys[n].name;
   }
   n++;
  } while (keys[n].code != -1);
  return keys[n].name;
 }
}

canonical_original_code:
char *checkKey(int ch)
{
 static char keych[2] = {0};
 if (((*__ctype_b_loc ())[(int) ((ch))] & (unsigned short) _ISprint) && !(ch & 0400))
 {
  keych[0]=ch;
  return keych;
 }
 else
 {
  int n = 0;
  do
  {
   if (keys[n].code==ch)
   {
    return keys[n].name;
   }
   n++;
  } while (keys[n].code != -1);
  return keys[n].name;
 }
}

variable_types:
keych
char [2]

variable_types: n int

return_type: char *


sendKey

decompiled_code:
__int64 sendKey()
{
lo_message_new();
lo_message_add_int32();
lo_message_add_string();
lo_send_message();
return lo_message_free();
}

canonical_decompiled_code:
__int64 func10()
{
lo_message_new();
lo_message_add_int32();
lo_message_add_string();
lo_send_message();
return lo_message_free();
}

original_code:
void sendKey(int key, char *ckey)
{
 lo_message reply=lo_message_new();
 lo_message_add_int32(reply, key);
 lo_message_add_string(reply, ckey);
 lo_send_message (loa, "/key", reply);
 lo_message_free (reply);
}

canonical_original_code:
void sendKey(int key, char *ckey)
{
 void *reply = lo_message_new();
 lo_message_add_int32(reply, key);
 lo_message_add_string(reply, ckey);
 lo_send_message (loa, "/key", reply);
 lo_message_free (reply);
}

variable_types: key int

variable_types:
ckey
char *

variable_types:
reply
void *


StringToRequete

decompiled_code:
int __fastcall StringToRequete(char *a1, int *a2)
{
char *v2; // rax
char *v3; // rax
int result; // eax

v2 = strtok(a1, ":");
*a2 = atoi(v2);
v3 = strtok(0LL, " ");
result = atoi(v3);
a2[1] = result;
return result;
}

canonical_decompiled_code:
int __fastcall func0(char *a1, int *a2)
{
char *v2; // rax
char *v3; // rax
int result; // eax

v2 = strtok(a1, ":");
*a2 = atoi(v2);
v3 = strtok(0LL, " ");
result = atoi(v3);
a2[1] = result;
return result;
}

original_code:
void StringToRequete(char * pString, struct Requete * pRequete){
 char *token= strtok(pString, ":");
 pRequete->site = atoi(token);
 token = strtok(((void *)0), " ");
 pRequete->horloge = atoi(token);
}

canonical_original_code:
void StringToRequete(char *pString, struct Requete *pRequete){
 char *token = strtok(pString, ":");
 pRequete->site = atoi(token);
 token = strtok(((void *)0), " ");
 pRequete->horloge = atoi(token);
}

variable_types:
pString
char *

variable_types: struct Requete { int site; int horloge; } *

variable_types:
token
char *


RequeteToString

decompiled_code:
int __fastcall RequeteToString(__int64 a1, char *a2)
{
return sprintf(a2, "%d:%d", a1, a1 >> 32);
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1, char *a2)
{
return sprintf(a2, "%d:%d", a1, a1 >> 32);
}

original_code:
void RequeteToString(struct Requete pRequete, char * pString){
 sprintf(pString, "%d:%d",pRequete.site,pRequete.horloge);
}

canonical_original_code:
void RequeteToString(struct Requete pRequete, char *pString){
 sprintf(pString, "%d:%d",pRequete.site,pRequete.horloge);
}

variable_types: struct Requete { int site; int horloge; }


SC

decompiled_code:
_BOOL8 SC()
{
return rand() % 10 == 9;
}

canonical_decompiled_code:
_BOOL8 func2()
{
return rand() % 10 == 9;
}

return_type: int


push

decompiled_code:
__int64 __fastcall push(__int64 a1, __int64 a2, _DWORD *a3)
{
*(_QWORD *)(a2 + 8LL * (int)(*a3)++) = a1;
return tri_bulle(a2);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, _DWORD *a3)
{
*(_QWORD *)(a2 + 8LL * (int)(*a3)++) = a1;
return tri_bulle(a2);
}

original_code:
void push(struct Requete pRequete,struct Requete * PILE, int* pMax){
 PILE[*pMax] = pRequete;
 *pMax+=1;
 tri_bulle(PILE, *pMax);
}

canonical_original_code:
void push(struct Requete pRequete, struct Requete *PILE, int *pMax){
 PILE[*pMax] = pRequete;
 *pMax+=1;
 tri_bulle(PILE, *pMax);
}

variable_types:
PILE
struct Requete *

variable_types:
pMax
int *

user_defined_types: struct Requete { int site; int horloge; }


pop

decompiled_code:
__int64 __fastcall pop(_QWORD *a1, _DWORD *a2)
{
*a1 = a1[--*a2];
return tri_bulle(a1);
}

canonical_decompiled_code:
__int64 __fastcall func4(_QWORD *a1, _DWORD *a2)
{
*a1 = a1[--*a2];
return tri_bulle(a1);
}

original_code:
void pop(struct Requete * PILE, int *pMax){
 PILE[0] = PILE[*pMax-1];
 *pMax -= 1;
 tri_bulle(PILE, *pMax);
}

canonical_original_code:
void pop(struct Requete *PILE, int *pMax){
 PILE[0] = PILE[*pMax-1];
 *pMax -= 1;
 tri_bulle(PILE, *pMax);
}


isFirst

decompiled_code:
_BOOL8 __fastcall isFirst(_DWORD *a1, int a2)
{
return *a1 == a2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func5(_DWORD *a1, int a2)
{
return *a1 == a2;
}

original_code:
int isFirst(struct Requete * PILE, int pSite){
 return (PILE[0].site == pSite) ? 1 : 0;
}

canonical_original_code:
int isFirst(struct Requete *PILE, int pSite){
 return (PILE[0].site == pSite) ? 1 : 0;
}

variable_types: pSite int


PILEtoString

decompiled_code:
int __fastcall PILEtoString(__int64 *a1, int a2)
{
__int64 *v2; // rbx
__int64 v3; // r12
__int64 v4; // rdi
char v6[32]; // [rsp-20h] [rbp-248h] BYREF
char s[16]; // [rsp+0h] [rbp-228h] BYREF
char v8[480]; // [rsp+10h] [rbp-218h] BYREF
int v9; // [rsp+1F0h] [rbp-38h]

v2 = a1;
*(_OWORD *)s = 0LL;
memset(v8, 0, sizeof(v8));
v9 = 0;
if ( a2 > 0 )
{
v3 = (__int64)&a1[(unsigned int)(a2 - 1) + 1];
do
{
v4 = *v2++;
RequeteToString(v4, v6);
sprintf(s, "%s - %s", s, v6);
}
while ( v2 != (__int64 *)v3 );
}
sprintf(s, "%s - %d", s, (unsigned int)a2);
return printf("%s \n", s);
}

original_code:
void PILEtoString(struct Requete * PILE,int pMax){
 int i;
 char vString[500] = "";
 for(i=0;i<pMax;i++){
  char Buffer[20];
  RequeteToString(PILE[i], Buffer);
  sprintf(vString, "%s - %s", vString, Buffer);
 }
 sprintf(vString, "%s - %d", vString, pMax);
 printf("%s \n",vString);
}

canonical_original_code:
void PILEtoString(struct Requete *PILE, int pMax){
 int i;
 char vString[500] = "";
 for(i=0;i<pMax;i++){
  char Buffer[20];
  RequeteToString(PILE[i], Buffer);
  sprintf(vString, "%s - %s", vString, Buffer);
 }
 sprintf(vString, "%s - %d", vString, pMax);
 printf("%s \n",vString);
}

variable_types: pMax int

variable_types: i int

variable_types:
vString
char [500]

variable_types:
Buffer
char [20]


Horloge

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

result = (unsigned int)(*a1 + 1);
if ( *a1 < a2 )
result = (unsigned int)(a2 + 1);
*a1 = result;
return result;
}

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

result = (unsigned int)(*a1 + 1);
if ( *a1 < a2 )
result = (unsigned int)(a2 + 1);
*a1 = result;
return result;
}

original_code:
void Horloge(int * pHorloge, int pHorlogeMessage){
 if(pHorlogeMessage > *pHorloge){
  *pHorloge = pHorlogeMessage+1;
 } else{
  *pHorloge += 1;
 }
}

canonical_original_code:
void Horloge(int *pHorloge, int pHorlogeMessage){
 if(pHorlogeMessage > *pHorloge){
  *pHorloge = pHorlogeMessage+1;
 } else{
  *pHorloge += 1;
 }
}

variable_types:
pHorloge
int *

variable_types: pHorlogeMessage int


wait

decompiled_code:
void wait()
{
;
}

canonical_decompiled_code:
void func8()
{
;
}

canonical_original_code:
void wait(int pTps){
 int i; int c;
 for(i=0; i<pTps*100; i++){
  c=c*50;
  c=c/50;
  c=c*33;
  c=c/33;
 }
}

variable_types: pTps int

variable_types: c int


original_code:
int tri_bulle_horloge(struct Requete * t, int n) {
 int num_balayage, i;
 for (num_balayage = 1 ; num_balayage < n ; ++num_balayage)
  for (i = 1 ; i < n ; ++i)
   if (t[i].horloge < t[i-1].horloge)
     permute(&t[i], &t[i-1]);
 return 0;
}

canonical_original_code:
int tri_bulle_horloge(struct Requete *t, int n) {
 int num_balayage; int i;
 for (num_balayage = 1 ; num_balayage < n ; ++num_balayage)
  for (i = 1 ; i < n ; ++i)
   if (t[i].horloge < t[i-1].horloge)
     permute(&t[i], &t[i-1]);
 return 0;
}

variable_types: n int


original_code:
int tri_bulle_site(struct Requete * t, int n) {
 int num_balayage, i;
 for (num_balayage = 1 ; num_balayage < n ; ++num_balayage)
  for (i = 1 ; i < n ; ++i)
   if (t[i].site < t[i-1].site && t[i].horloge == t[i-1].horloge)
     permute(&t[i], &t[i-1]);
 return 0;
}

canonical_original_code:
int tri_bulle_site(struct Requete *t, int n) {
 int num_balayage; int i;
 for (num_balayage = 1 ; num_balayage < n ; ++num_balayage)
  for (i = 1 ; i < n ; ++i)
   if (t[i].site < t[i-1].site && t[i].horloge == t[i-1].horloge)
     permute(&t[i], &t[i-1]);
 return 0;
}


decompiled_code:
__int64 __fastcall tri_bulle(__int64 *a1, int a2)
{
tri_bulle_horloge(a1, a2);
return tri_bulle_site(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 *a1, int a2)
{
func1(a1, a2);
return func2(a1, a2);
}

original_code:
int tri_bulle(struct Requete * t, int n) {
 tri_bulle_horloge(t,n);
 tri_bulle_site(t,n);
}

canonical_original_code:
int tri_bulle(struct Requete *t, int n) {
 tri_bulle_horloge(t,n);
 tri_bulle_site(t,n);
}


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // er12
const char **v4; // rbx
void *v5; // rax
void *v6; // r13
unsigned int v7; // ebp
int v8; // er14
unsigned int v9; // er14
int v10; // edx
int v11; // er15
int v12; // ebx
__int64 v13; // r15
int v14; // eax
__int64 v15; // rax
unsigned int v16; // eax
int v17; // er15
int v18; // eax
int v19; // er14
int v20; // eax
unsigned int v21; // eax
__int64 v22; // r14
int v23; // eax
const char *v24; // rdi
__int64 v25; // rsi
unsigned int v26; // eax
__int64 v27; // rax
__int64 v28; // rbp
__int64 v29; // r14
unsigned __int64 v30; // r12
int v31; // eax
const char *v32; // rdi
__int64 v33; // rsi
unsigned int v34; // [rsp+8h] [rbp-F0h]
int v35; // [rsp+10h] [rbp-E8h]
__int64 v36; // [rsp+10h] [rbp-E8h]
unsigned int v37; // [rsp+18h] [rbp-E0h]
unsigned __int64 v38; // [rsp+18h] [rbp-E0h]
unsigned int fd; // [rsp+20h] [rbp-D8h]
unsigned int v40; // [rsp+24h] [rbp-D4h]
unsigned int v41; // [rsp+2Ch] [rbp-CCh]
socklen_t addr_len; // [rsp+3Ch] [rbp-BCh] BYREF
int v43; // [rsp+40h] [rbp-B8h] BYREF
unsigned int v44; // [rsp+44h] [rbp-B4h] BYREF
__int64 v45; // [rsp+48h] [rbp-B0h] BYREF
struct sockaddr addr; // [rsp+50h] [rbp-A8h] BYREF
struct sockaddr v47; // [rsp+60h] [rbp-98h] BYREF
char s[32]; // [rsp+70h] [rbp-88h] BYREF
char buf[104]; // [rsp+90h] [rbp-68h] BYREF

v3 = argc;
v4 = argv;
v43 = 0;
v44 = 0;
v5 = malloc(0x9C40uLL);
if ( argc <= 2 )
{
printf("Erreur: il faut donner au moins 2 sites pour faire fonctionner l'application: NumeroPortBase et liste_des_sites");
exit(-1);
}
v6 = v5;
v7 = argc - 2;
v8 = atoi(argv[1]);
v9 = GetSitePos((unsigned int)(argc - 2), argv) + v8;
printf("Numero de port de ce site %d\n", v9);
addr.sa_family = 2;
*(_DWORD *)&addr.sa_data[2] = (unsigned __int16)_bswap_16(0);
*(_WORD *)addr.sa_data = _bswap_16(v9);
fd = socket(2, 1, v10);
if ( fd == -1 )
{
perror("Creation socket");
exit(-1);
}
if ( bind(fd, &addr, 0x10u) == -1 )
{
perror("Bind socket");
exit(-1);
}
listen(fd, 30);
v11 = GetSitePos(v7, argv);
if ( v11 )
{
v26 = atoi(argv[1]);
SendSync(argv[2], v26);
puts("Wait Synchro du Site 0");
WaitSync(fd);
puts("Synchro recue de Site 0");
}
else if ( argc == 3 )
{
puts("Toutes les synchros recues");
}
else
{
v12 = v11;
do
{
++v12;
WaitSync(fd);
}
while ( v12 != argc - 3 );
v4 = argv;
v13 = 0LL;
puts("Toutes les synchros recues");
do
{
v14 = atoi(argv[1]);
SendSync(argv[v13 + 3], (unsigned int)(v14 + v13 + 1));
v15 = v13++;
}
while ( argc - 4 != v15 );
}
v16 = GetSitePos(v7, v4);
v17 = 1;
printf("Je suis le site numero : %d \n", v16);
fcntl(fd, 4, 2048LL);
addr_len = 16;
v35 = 1;
v34 = argc - 1;
while ( 1 )
{
v18 = accept(fd, &v47, &addr_len);
v19 = v18;
if ( v18 <= 0 )
{
if ( (unsigned int)SC() == 1 && v35 )
{
printf("Requete envoye : %d \n", ++v44);
v36 = (unsigned int)GetSitePos(v7, v4);
v38 = v36 | (((unsigned __int64)v44 << 32) | v37) & 0xFFFFFFFF00000000LL;
RequeteToString(v38, s);
v27 = v7;
v41 = v7;
v28 = 0LL;
v29 = v27;
v40 = v3;
v30 = v38;
do
{
while ( (_DWORD)v36 != (_DWORD)v28 )
{
v31 = atoi(v4[1]);
v32 = v4[v28 + 2];
v33 = (unsigned int)(v31 + v28++);
SendMsg(v32, v33, s);
if ( v28 == v29 )
goto LABEL_33;
}
++v28;
v30 = v36 | v30 & 0xFFFFFFFF00000000LL;
push(v30, v6, &v43);
}
while ( v28 != v29 );
LABEL_33:
v7 = v41;
v37 = v30;
v35 = 0;
v3 = v40;
}
}
else
{
buf[(int)read(v18, buf, 0x27uLL)] = 0;
StringToRequete(buf, &v45);
Horloge(&v44, HIDWORD(v45));
if ( (_DWORD)v45 == v34 )
{
++v17;
printf("Reponse recu : %d \n", v44);
}
else if ( (_DWORD)v45 == v3 )
{
printf("Liberation recu : %d \n", v44);
pop(v6, &v43);
}
else
{
push(v45, v6, &v43);
sprintf(s, "%d:%d", v34, v44);
v20 = atoi(v4[1]);
SendMsg(v4[(int)v45 + 2], (unsigned int)(v20 + v45), s);
printf("Requete recu : %d \n", v44);
}
close(v19);
}
if ( v17 == v7 )
{
v21 = GetSitePos(v7, v4);
if ( (unsigned int)isFirst(v6, v21) )
{
v22 = 0LL;
puts("Je passe en SC");
wait((__WAIT_STATUS)10000LL);
puts("Je sors de la SC");
do
{
while ( (unsigned int)GetSitePos(v7, v4) != (_DWORD)v22 )
{
sprintf(s, "%d:%d", v3, v44);
v23 = atoi(v4[1]);
v24 = v4[v22 + 2];
v25 = (unsigned int)(v23 + v22++);
SendMsg(v24, v25, s);
if ( v7 == v22 )
goto LABEL_23;
}
++v22;
pop(v6, &v43);
}
while ( v7 != v22 );
LABEL_23:
v17 = 1;
puts("Envoi des liberations");
v35 = 1;
}
}
wait((__WAIT_STATUS)10000LL);
}
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // er12
const char **v4; // rbx
void *v5; // rax
void *v6; // r13
unsigned int v7; // ebp
int v8; // er14
unsigned int v9; // er14
int v10; // edx
int v11; // er15
int v12; // ebx
__int64 v13; // r15
int v14; // eax
__int64 v15; // rax
unsigned int v16; // eax
int v17; // er15
int v18; // eax
int v19; // er14
int v20; // eax
unsigned int v21; // eax
__int64 v22; // r14
int v23; // eax
const char *v24; // rdi
__int64 v25; // rsi
unsigned int v26; // eax
__int64 v27; // rax
__int64 v28; // rbp
__int64 v29; // r14
unsigned __int64 v30; // r12
int v31; // eax
const char *v32; // rdi
__int64 v33; // rsi
unsigned int v34; // [rsp+8h] [rbp-F0h]
int v35; // [rsp+10h] [rbp-E8h]
__int64 v36; // [rsp+10h] [rbp-E8h]
unsigned int v37; // [rsp+18h] [rbp-E0h]
unsigned __int64 v38; // [rsp+18h] [rbp-E0h]
unsigned int fd; // [rsp+20h] [rbp-D8h]
unsigned int v40; // [rsp+24h] [rbp-D4h]
unsigned int v41; // [rsp+2Ch] [rbp-CCh]
socklen_t addr_len; // [rsp+3Ch] [rbp-BCh] BYREF
int v43; // [rsp+40h] [rbp-B8h] BYREF
unsigned int v44; // [rsp+44h] [rbp-B4h] BYREF
__int64 v45; // [rsp+48h] [rbp-B0h] BYREF
struct sockaddr addr; // [rsp+50h] [rbp-A8h] BYREF
struct sockaddr v47; // [rsp+60h] [rbp-98h] BYREF
char s[32]; // [rsp+70h] [rbp-88h] BYREF
char buf[104]; // [rsp+90h] [rbp-68h] BYREF

v3 = argc;
v4 = argv;
v43 = 0;
v44 = 0;
v5 = malloc(0x9C40uLL);
if ( argc <= 2 )
{
printf("Erreur: il faut donner au moins 2 sites pour faire fonctionner l'application: NumeroPortBase et liste_des_sites");
exit(-1);
}
v6 = v5;
v7 = argc - 2;
v8 = atoi(argv[1]);
v9 = GetSitePos((unsigned int)(argc - 2), argv) + v8;
printf("Numero de port de ce site %d\n", v9);
addr.sa_family = 2;
*(_DWORD *)&addr.sa_data[2] = (unsigned __int16)func0(0);
*(_WORD *)addr.sa_data = func0(v9);
fd = socket(2, 1, v10);
if ( fd == -1 )
{
perror("Creation socket");
exit(-1);
}
if ( bind(fd, &addr, 0x10u) == -1 )
{
perror("Bind socket");
exit(-1);
}
listen(fd, 30);
v11 = GetSitePos(v7, argv);
if ( v11 )
{
v26 = atoi(argv[1]);
SendSync(argv[2], v26);
puts("Wait Synchro du Site 0");
WaitSync(fd);
puts("Synchro recue de Site 0");
}
else if ( argc == 3 )
{
puts("Toutes les synchros recues");
}
else
{
v12 = v11;
do
{
++v12;
WaitSync(fd);
}
while ( v12 != argc - 3 );
v4 = argv;
v13 = 0LL;
puts("Toutes les synchros recues");
do
{
v14 = atoi(argv[1]);
SendSync(argv[v13 + 3], (unsigned int)(v14 + v13 + 1));
v15 = v13++;
}
while ( argc - 4 != v15 );
}
v16 = GetSitePos(v7, v4);
v17 = 1;
printf("Je suis le site numero : %d \n", v16);
fcntl(fd, 4, 2048LL);
addr_len = 16;
v35 = 1;
v34 = argc - 1;
while ( 1 )
{
v18 = accept(fd, &v47, &addr_len);
v19 = v18;
if ( v18 <= 0 )
{
if ( (unsigned int)SC() == 1 && v35 )
{
printf("Requete envoye : %d \n", ++v44);
v36 = (unsigned int)GetSitePos(v7, v4);
v38 = v36 | (((unsigned __int64)v44 << 32) | v37) & 0xFFFFFFFF00000000LL;
RequeteToString(v38, s);
v27 = v7;
v41 = v7;
v28 = 0LL;
v29 = v27;
v40 = v3;
v30 = v38;
do
{
while ( (_DWORD)v36 != (_DWORD)v28 )
{
v31 = atoi(v4[1]);
v32 = v4[v28 + 2];
v33 = (unsigned int)(v31 + v28++);
SendMsg(v32, v33, s);
if ( v28 == v29 )
goto LABEL_33;
}
++v28;
v30 = v36 | v30 & 0xFFFFFFFF00000000LL;
push(v30, v6, &v43);
}
while ( v28 != v29 );
LABEL_33:
v7 = v41;
v37 = v30;
v35 = 0;
v3 = v40;
}
}
else
{
buf[(int)read(v18, buf, 0x27uLL)] = 0;
StringToRequete(buf, &v45);
Horloge(&v44, HIDWORD(v45));
if ( (_DWORD)v45 == v34 )
{
++v17;
printf("Reponse recu : %d \n", v44);
}
else if ( (_DWORD)v45 == v3 )
{
printf("Liberation recu : %d \n", v44);
pop(v6, &v43);
}
else
{
push(v45, v6, &v43);
sprintf(s, "%d:%d", v34, v44);
v20 = atoi(v4[1]);
SendMsg(v4[(int)v45 + 2], (unsigned int)(v20 + v45), s);
printf("Requete recu : %d \n", v44);
}
close(v19);
}
if ( v17 == v7 )
{
v21 = GetSitePos(v7, v4);
if ( (unsigned int)isFirst(v6, v21) )
{
v22 = 0LL;
puts("Je passe en SC");
wait((__WAIT_STATUS)10000LL);
puts("Je sors de la SC");
do
{
while ( (unsigned int)GetSitePos(v7, v4) != (_DWORD)v22 )
{
sprintf(s, "%d:%d", v3, v44);
v23 = atoi(v4[1]);
v24 = v4[v22 + 2];
v25 = (unsigned int)(v23 + v22++);
SendMsg(v24, v25, s);
if ( v7 == v22 )
goto LABEL_23;
}
++v22;
pop(v6, &v43);
}
while ( v7 != v22 );
LABEL_23:
v17 = 1;
puts("Envoi des liberations");
v35 = 1;
}
}
wait((__WAIT_STATUS)10000LL);
}
}

original_code:
int main (int argc, char* argv[]) {
 struct sockaddr_in sock_add, sock_add_dist;
 int size_sock, s_ecoute, s_service;
 char texte[40];
 int i,l,v,vMax=0, vHorloge = 0, vCompteur=1, vBoolean=1;
 Requete* PILE;
 PILE = malloc(5000 * sizeof(Requete) );
 int PortBase=-1;
 int NSites=-1;
 if (argc<3) {
  printf("Erreur: il faut donner au moins 2 sites pour faire fonctionner l'application: NumeroPortBase et liste_des_sites");
 exit(-1);
 }
 NSites=argc-2;
 PortBase=atoi(argv[1])+GetSitePos(NSites, argv);
 printf("Numero de port de ce site %d\n",PortBase);
 sock_add.sin_family = 2;
 sock_add.sin_addr.s_addr= htons(((in_addr_t) 0x00000000));
 sock_add.sin_port = htons(PortBase);
 if ( (s_ecoute=socket(2, SOCK_STREAM,0))==-1) {
  perror("Creation socket");
  exit(-1);
 }
 if ( bind(s_ecoute,(struct sockaddr*) &sock_add,sizeof(struct sockaddr_in))==-1) {
  perror("Bind socket");
  exit(-1);
 }
 listen(s_ecoute,30);
 if (GetSitePos(NSites, argv) ==0) {
  for(i=0;i<NSites-1;i++){
   WaitSync(s_ecoute);
  }
  puts("Toutes les synchros recues");
  for(i=0;i<NSites-1;i++){
   SendSync(argv[3+i], atoi(argv[1])+i+1);
  }
 }else{
  SendSync(argv[2], atoi(argv[1]));
  puts("Wait Synchro du Site 0");
  WaitSync(s_ecoute);
  puts("Synchro recue de  Site 0");
 }
 printf("Je suis le site numero : %d \n",GetSitePos(NSites, argv) );
 fcntl(s_ecoute,4,04000);
 size_sock=sizeof(struct sockaddr_in);
 while(1){
  s_service=accept(s_ecoute,(struct sockaddr*) &sock_add_dist,&size_sock);
  if (s_service>0) {
   l=read(s_service,texte,39);
   texte[l] ='\0';
   Requete Requete1;
   StringToRequete(texte, &Requete1);
   Horloge(&vHorloge, Requete1.horloge);
   if(Requete1.site == NSites +1){
    printf("Reponse recu : %d \n", vHorloge);
    vCompteur ++;
   } else if(Requete1.site == NSites +2){
    printf("Liberation recu : %d \n",vHorloge);
    pop(PILE, &vMax);
   } else {
    push(Requete1, PILE,&vMax);
    char vTexte[20];
    sprintf(vTexte,"%d:%d",NSites+1,vHorloge);
    SendMsg(argv[2+Requete1.site], atoi(argv[1])+Requete1.site, vTexte);
    printf("Requete recu : %d \n",vHorloge);
   }
   close (s_service);
  }else if(SC() == 1 && vBoolean){
   vHorloge++;
   printf("Requete envoye : %d \n", vHorloge);
   vBoolean = 0;
   Requete Requete1;
   Requete1.site = GetSitePos(NSites, argv);
   Requete1.horloge = vHorloge;
   char vBuffer[20];
   RequeteToString(Requete1,vBuffer);
   for(i=0;i<NSites;i++){
    if(i != Requete1.site ){
     SendMsg(argv[2+i], atoi(argv[1])+i, vBuffer);
    } else{
     push(Requete1, PILE,&vMax);
    }
   }
  }
    if(vCompteur == NSites ){
   if(isFirst(PILE, GetSitePos(NSites, argv) )) {
    puts("Je passe en SC");
    vCompteur = 1;
    vBoolean = 1;
    wait(10000);
    puts("Je sors de la SC");
    for(i=0;i<NSites;i++){
     if(i != GetSitePos(NSites, argv) ){
      char vTexte[20];
      sprintf(vTexte,"%d:%d",NSites+2,vHorloge);
      SendMsg(argv[2+i], atoi(argv[1])+i, vTexte);
     } else {
      pop(PILE, &vMax);
     }
    }
    puts("Envoi des liberations");
   }
  }
  wait(10000);
 }
 puts("merdouille");
 PILEtoString(PILE, vMax);
 free(PILE);
 close (s_ecoute);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
 struct sockaddr_in sock_add; struct sockaddr_in sock_add_dist;
 int size_sock; int s_ecoute; int s_service;
 char texte[40];
 int i; int l; int v; int vMax = 0; int vHorloge = 0; int vCompteur = 1; int vBoolean = 1;
 struct Requete *PILE;
 PILE = malloc(5000 * sizeof(Requete) );
 int PortBase = -1;
 int NSites = -1;
 if (argc<3) {
  printf("Erreur: il faut donner au moins 2 sites pour faire fonctionner l'application: NumeroPortBase et liste_des_sites");
 exit(-1);
 }
 NSites=argc-2;
 PortBase=atoi(argv[1])+GetSitePos(NSites, argv);
 printf("Numero de port de ce site %d\n",PortBase);
 sock_add.sin_family = 2;
 sock_add.sin_addr.s_addr= htons(((unsigned int) 0x00000000));
 sock_add.sin_port = htons(PortBase);
 if ( (s_ecoute=socket(2, SOCK_STREAM,0))==-1) {
  perror("Creation socket");
  exit(-1);
 }
 if ( bind(s_ecoute,(struct sockaddr *) &sock_add,sizeof(struct sockaddr_in))==-1) {
  perror("Bind socket");
  exit(-1);
 }
 listen(s_ecoute,30);
 if (GetSitePos(NSites, argv) ==0) {
  for(i=0;i<NSites-1;i++){
   WaitSync(s_ecoute);
  }
  puts("Toutes les synchros recues");
  for(i=0;i<NSites-1;i++){
   SendSync(argv[3+i], atoi(argv[1])+i+1);
  }
 }else{
  SendSync(argv[2], atoi(argv[1]));
  puts("Wait Synchro du Site 0");
  WaitSync(s_ecoute);
  puts("Synchro recue de  Site 0");
 }
 printf("Je suis le site numero : %d \n",GetSitePos(NSites, argv) );
 fcntl(s_ecoute,4,04000);
 size_sock=sizeof(struct sockaddr_in);
 while(1){
  s_service=accept(s_ecoute,(struct sockaddr *) &sock_add_dist,&size_sock);
  if (s_service>0) {
   l=read(s_service,texte,39);
   texte[l] ='\0';
   struct Requete Requete1;
   StringToRequete(texte, &Requete1);
   Horloge(&vHorloge, Requete1.horloge);
   if(Requete1.site == NSites +1){
    printf("Reponse recu : %d \n", vHorloge);
    vCompteur ++;
   } else if(Requete1.site == NSites +2){
    printf("Liberation recu : %d \n",vHorloge);
    pop(PILE, &vMax);
   } else {
    push(Requete1, PILE,&vMax);
    char vTexte[20];
    sprintf(vTexte,"%d:%d",NSites+1,vHorloge);
    SendMsg(argv[2+Requete1.site], atoi(argv[1])+Requete1.site, vTexte);
    printf("Requete recu : %d \n",vHorloge);
   }
   close (s_service);
  }else if(SC() == 1 && vBoolean){
   vHorloge++;
   printf("Requete envoye : %d \n", vHorloge);
   vBoolean = 0;
   struct Requete Requete1;
   Requete1.site = GetSitePos(NSites, argv);
   Requete1.horloge = vHorloge;
   char vBuffer[20];
   RequeteToString(Requete1,vBuffer);
   for(i=0;i<NSites;i++){
    if(i != Requete1.site ){
     SendMsg(argv[2+i], atoi(argv[1])+i, vBuffer);
    } else{
     push(Requete1, PILE,&vMax);
    }
   }
  }
    if(vCompteur == NSites ){
   if(isFirst(PILE, GetSitePos(NSites, argv) )) {
    puts("Je passe en SC");
    vCompteur = 1;
    vBoolean = 1;
    wait(10000);
    puts("Je sors de la SC");
    for(i=0;i<NSites;i++){
     if(i != GetSitePos(NSites, argv) ){
      char vTexte[20];
      sprintf(vTexte,"%d:%d",NSites+2,vHorloge);
      SendMsg(argv[2+i], atoi(argv[1])+i, vTexte);
     } else {
      pop(PILE, &vMax);
     }
    }
    puts("Envoi des liberations");
   }
  }
  wait(10000);
 }
 puts("merdouille");
 PILEtoString(PILE, vMax);
 free(PILE);
 close (s_ecoute);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

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

variable_types:
texte
char [40]

variable_types: l int

variable_types: v int

variable_types: vMax int

variable_types: vHorloge int

variable_types: vCompteur int

variable_types: vBoolean int

variable_types: PortBase int

variable_types: NSites int

variable_types:
vTexte
char [20]

variable_types:
vBuffer
char [20]

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

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


GetSitePos

decompiled_code:
__int64 __fastcall GetSitePos(int a1, __int64 a2)
{
__int64 v2; // rbx
char v4[56]; // [rsp+0h] [rbp-38h] BYREF

gethostname(v4, 0x14uLL);
if ( a1 <= 0 )
{
LABEL_6:
puts("Indice du Site courant non trouve' dans la liste");
exit(-1);
}
v2 = 0LL;
while ( strcmp(v4, *(const char **)(a2 + 8 * v2 + 16)) )
{
if ( ++v2 == a1 )
goto LABEL_6;
}
return (unsigned int)v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, __int64 a2)
{
__int64 v2; // rbx
char v4[56]; // [rsp+0h] [rbp-38h] BYREF

gethostname(v4, 0x14uLL);
if ( a1 <= 0 )
{
LABEL_6:
puts("Indice du Site courant non trouve' dans la liste");
exit(-1);
}
v2 = 0LL;
while ( strcmp(v4, *(const char **)(a2 + 8 * v2 + 16)) )
{
if ( ++v2 == a1 )
goto LABEL_6;
}
return (unsigned int)v2;
}

original_code:
int GetSitePos(int NbSites, char *argv[]) {
 char MySiteName[20];
 int MySitePos=-1;
 int i;
 gethostname(MySiteName, 20);
 for (i=0;i<NbSites;i++){
  if (strcmp(MySiteName,argv[i+2])==0) {
   MySitePos=i;
   return MySitePos;
  }
 }
 puts("Indice du Site courant non trouve' dans la liste");
 exit(-1);
 return (-1);
}

canonical_original_code:
int GetSitePos(int NbSites, char *argv[]) {
 char MySiteName[20];
 int MySitePos = -1;
 int i;
 gethostname(MySiteName, 20);
 for (i=0;i<NbSites;i++){
  if (strcmp(MySiteName,argv[i+2])==0) {
   MySitePos=i;
   return MySitePos;
  }
 }
 puts("Indice du Site courant non trouve' dans la liste");
 exit(-1);
 return (-1);
}

variable_types: NbSites int

variable_types:
MySiteName
char [20]

variable_types: MySitePos int

variable_types: i int


WaitSync

decompiled_code:
int __fastcall WaitSync(int fd)
{
int v1; // ebp
socklen_t addr_len; // [rsp+Ch] [rbp-4Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-48h] BYREF
char buf[56]; // [rsp+20h] [rbp-38h] BYREF

addr_len = 16;
printf("WaitSync : ");
fflush(0LL);
v1 = accept(fd, &addr, &addr_len);
buf[(int)read(v1, buf, 0x27uLL)] = 0;
puts(buf);
fflush(0LL);
return close(v1);
}

canonical_decompiled_code:
int __fastcall func2(int fd)
{
int v1; // ebp
socklen_t addr_len; // [rsp+Ch] [rbp-4Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-48h] BYREF
char buf[56]; // [rsp+20h] [rbp-38h] BYREF

addr_len = 16;
printf("WaitSync : ");
fflush(0LL);
v1 = accept(fd, &addr, &addr_len);
buf[(int)read(v1, buf, 0x27uLL)] = 0;
puts(buf);
fflush(0LL);
return close(v1);
}

original_code:
void WaitSync(int s_ecoute) {
 char texte[40];
 int l, s_service, size_sock;
 struct sockaddr_in sock_add_dist;
 size_sock=sizeof(struct sockaddr_in);
 printf("WaitSync : ");fflush(0);
 s_service=accept(s_ecoute,(struct sockaddr*) &sock_add_dist,&size_sock);
 l=read(s_service,texte,39);
 texte[l] ='\0';
 printf("%s\n",texte); fflush(0);
 close (s_service);
}

canonical_original_code:
void WaitSync(int s_ecoute) {
 char texte[40];
 int l; int s_service; int size_sock;
 struct sockaddr_in sock_add_dist;
 size_sock=sizeof(struct sockaddr_in);
 printf("WaitSync : ");fflush(0);
 s_service=accept(s_ecoute,(struct sockaddr *) &sock_add_dist,&size_sock);
 l=read(s_service,texte,39);
 texte[l] ='\0';
 printf("%s\n",texte); fflush(0);
 close (s_service);
}


SendSync

decompiled_code:
int __fastcall SendSync(char *name, __int16 a2)
{
int v2; // eax
int v3; // ebp
__int16 v4; // ax
__int64 v5; // rdx
size_t v6; // r8
size_t v7; // rax
char s[15]; // [rsp+1h] [rbp-37h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-28h] BYREF

v2 = socket(2, 1, 0);
if ( v2 == -1 )
{
perror("SendSync : Creation socket");
exit(-1);
}
v3 = v2;
if ( !gethostbyname(name) )
{
perror("SendSync: Gethostbyname");
exit(-1);
}
addr.sa_family = 2;
v4 = _bswap_16(a2);
v6 = *(int *)(v5 + 20);
*(_WORD *)addr.sa_data = v4;
memcpy(&addr.sa_data[2], **(const void ***)(v5 + 24), v6);
if ( connect(v3, &addr, 0x10u) == -1 )
{
perror("SendSync : Connect");
exit(-1);
}
strcpy(s, "**SYNCHRO**");
v7 = strlen(s);
write(v3, s, v7);
return close(v3);
}

canonical_decompiled_code:
int __fastcall func3(char *name, __int16 a2)
{
int v2; // eax
int v3; // ebp
__int16 v4; // ax
__int64 v5; // rdx
size_t v6; // r8
size_t v7; // rax
char s[15]; // [rsp+1h] [rbp-37h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-28h] BYREF

v2 = socket(2, 1, 0);
if ( v2 == -1 )
{
perror("SendSync : Creation socket");
exit(-1);
}
v3 = v2;
if ( !gethostbyname(name) )
{
perror("SendSync: Gethostbyname");
exit(-1);
}
addr.sa_family = 2;
v4 = func0(a2);
v6 = *(int *)(v5 + 20);
*(_WORD *)addr.sa_data = v4;
memcpy(&addr.sa_data[2], **(const void ***)(v5 + 24), v6);
if ( connect(v3, &addr, 0x10u) == -1 )
{
perror("SendSync : Connect");
exit(-1);
}
strcpy(s, "**SYNCHRO**");
v7 = strlen(s);
write(v3, s, v7);
return close(v3);
}

original_code:
void SendSync(char *Site, int Port) {
 int s_emis, size_sock;
 char chaine[15];
 struct sockaddr_in sock_add_emis;
 struct hostent* hp;
 if( (s_emis = socket(2, SOCK_STREAM,0) )==-1) {
  perror("SendSync : Creation socket");
  exit(-1);
 }
 if( (hp = gethostbyname(Site) ) == ((void *)0)) {
  perror("SendSync: Gethostbyname");
  exit(-1);
 }
 size_sock=sizeof(struct sockaddr_in);
 sock_add_emis.sin_family = 2;
 sock_add_emis.sin_port = htons(Port);
 memcpy(&sock_add_emis.sin_addr.s_addr, hp->h_addr_list[0], hp->h_length);
 if( connect(s_emis, (struct sockaddr*) &sock_add_emis,size_sock)==-1) {
  perror("SendSync : Connect");
  exit(-1);
 }
 sprintf(chaine,"**SYNCHRO**");
 write(s_emis,chaine,strlen(chaine));
 close (s_emis);
}

canonical_original_code:
void SendSync(char *Site, int Port) {
 int s_emis; int size_sock;
 char chaine[15];
 struct sockaddr_in sock_add_emis;
 struct hostent *hp;
 if( (s_emis = socket(2, SOCK_STREAM,0) )==-1) {
  perror("SendSync : Creation socket");
  exit(-1);
 }
 if( (hp = gethostbyname(Site) ) == ((void *)0)) {
  perror("SendSync: Gethostbyname");
  exit(-1);
 }
 size_sock=sizeof(struct sockaddr_in);
 sock_add_emis.sin_family = 2;
 sock_add_emis.sin_port = htons(Port);
 memcpy(&sock_add_emis.sin_addr.s_addr, hp->h_addr_list[0], hp->h_length);
 if( connect(s_emis, (struct sockaddr *) &sock_add_emis,size_sock)==-1) {
  perror("SendSync : Connect");
  exit(-1);
 }
 sprintf(chaine,"**SYNCHRO**");
 write(s_emis,chaine,strlen(chaine));
 close (s_emis);
}

variable_types:
Site
char *

variable_types: Port int

variable_types:
chaine
char [15]

variable_types: struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; } *


SendMsg

decompiled_code:
int __fastcall SendMsg(char *name, __int16 a2, const char *a3)
{
int v4; // eax
int v5; // ebp
__int16 v6; // ax
__int64 v7; // rdx
size_t v8; // r8
size_t v9; // rax
struct sockaddr v11[3]; // [rsp+0h] [rbp-38h] BYREF

v4 = socket(2, 1, 0);
if ( v4 == -1 )
{
perror("SendSync : Creation socket");
exit(-1);
}
v5 = v4;
if ( !gethostbyname(name) )
{
perror("SendSync: Gethostbyname");
exit(-1);
}
v11[0].sa_family = 2;
v6 = _bswap_16(a2);
v8 = *(int *)(v7 + 20);
*(_WORD *)v11[0].sa_data = v6;
memcpy(&v11[0].sa_data[2], **(const void ***)(v7 + 24), v8);
if ( connect(v5, v11, 0x10u) == -1 )
{
perror("SendSync : Connect");
exit(-1);
}
v9 = strlen(a3);
write(v5, a3, v9);
return close(v5);
}

canonical_decompiled_code:
int __fastcall func4(char *name, __int16 a2, const char *a3)
{
int v4; // eax
int v5; // ebp
__int16 v6; // ax
__int64 v7; // rdx
size_t v8; // r8
size_t v9; // rax
struct sockaddr v11[3]; // [rsp+0h] [rbp-38h] BYREF

v4 = socket(2, 1, 0);
if ( v4 == -1 )
{
perror("SendSync : Creation socket");
exit(-1);
}
v5 = v4;
if ( !gethostbyname(name) )
{
perror("SendSync: Gethostbyname");
exit(-1);
}
v11[0].sa_family = 2;
v6 = func0(a2);
v8 = *(int *)(v7 + 20);
*(_WORD *)v11[0].sa_data = v6;
memcpy(&v11[0].sa_data[2], **(const void ***)(v7 + 24), v8);
if ( connect(v5, v11, 0x10u) == -1 )
{
perror("SendSync : Connect");
exit(-1);
}
v9 = strlen(a3);
write(v5, a3, v9);
return close(v5);
}

original_code:
void SendMsg(char *Site, int Port, char* vString) {
 struct hostent* hp;
 int s_emis, size_sock;
 struct sockaddr_in sock_add_emis;
 if( (s_emis=socket(2, SOCK_STREAM,0) )==-1) {
  perror("SendSync : Creation socket");
  exit(-1);
 }
 if( (hp=gethostbyname(Site)) == ((void *)0)) {
  perror("SendSync: Gethostbyname");
  exit(-1);
 }
 size_sock=sizeof(struct sockaddr_in);
 sock_add_emis.sin_family = 2;
 sock_add_emis.sin_port = htons(Port);
 memcpy(&sock_add_emis.sin_addr.s_addr, hp->h_addr_list[0], hp->h_length);
 if (connect(s_emis, (struct sockaddr*) &sock_add_emis,size_sock)==-1) {
  perror("SendSync : Connect");
  exit(-1);
 }
 write(s_emis,vString,strlen(vString));
 close (s_emis);
}

canonical_original_code:
void SendMsg(char *Site, int Port, char *vString) {
 struct hostent *hp;
 int s_emis; int size_sock;
 struct sockaddr_in sock_add_emis;
 if( (s_emis=socket(2, SOCK_STREAM,0) )==-1) {
  perror("SendSync : Creation socket");
  exit(-1);
 }
 if( (hp=gethostbyname(Site)) == ((void *)0)) {
  perror("SendSync: Gethostbyname");
  exit(-1);
 }
 size_sock=sizeof(struct sockaddr_in);
 sock_add_emis.sin_family = 2;
 sock_add_emis.sin_port = htons(Port);
 memcpy(&sock_add_emis.sin_addr.s_addr, hp->h_addr_list[0], hp->h_length);
 if (connect(s_emis, (struct sockaddr *) &sock_add_emis,size_sock)==-1) {
  perror("SendSync : Connect");
  exit(-1);
 }
 write(s_emis,vString,strlen(vString));
 close (s_emis);
}

variable_types:
vString
char *

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

user_defined_types: struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; }


sigterm

decompiled_code:
void __fastcall sigterm(unsigned int a1)
{
fprintf(stderr, "Signal recu : %d\n", a1);
serveur_running = 0;
}

canonical_decompiled_code:
void __fastcall func0(unsigned int a1)
{
fprintf(stderr, "Signal recu : %d\n", a1);
serveur_running = 0;
}

original_code:
void sigterm(int signo)
{
 fprintf(stderr, "Signal recu : %d\n", signo);
 serveur_running = 0;
}

variable_types: signo int


onConnect

decompiled_code:
int __fastcall onConnect(__int64 a1, __int64 a2)
{
return printf(
"%s @ %d : New client %s:%d\n",
"onConnect",
234LL,
*(const char **)(a2 + 8),
*(unsigned int *)(a2 + 16));
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1, __int64 a2)
{
return printf(
"%s @ %d : New client %s:%d\n",
"onConnect",
234LL,
*(const char **)(a2 + 8),
*(unsigned int *)(a2 + 16));
}

original_code:
void onConnect (CServerTcpIP *this, Client *from, void *pdata){
 printf("%s @ %d : " "New client %s:%d\n", __FUNCTION__, 234, from->adresseIP, from->port);
}

canonical_original_code:
void onConnect(struct _CServerTcpIP *this, struct _Client *from, void *pdata){
 printf("%s @ %d : " "New client %s:%d\n", __FUNCTION__, 234, from->adresseIP, from->port);
}

variable_types: struct _CServerTcpIP { void (*Free)(struct _CServerTcpIP *this); int (*Send)(struct _CServerTcpIP *this, struct _Client { int fd; char *adresseIP; unsigned int port; struct _Client *next; } *destinataire, char *buffer, unsigned int buffer_size); int (*GetNbClientsConnected)(struct _CServerTcpIP *this); int (*Start)(struct _CServerTcpIP *this, unsigned short port); int (*Stop)(struct _CServerTcpIP *this); int m_fdListen; unsigned long m_threadListen; struct _Client *m_clistClients; int m_iClientNumber; void (*m_callback)(char *buffer, unsigned int buffer_size, struct _CServerTcpIP *this, struct _Client *from, void *pdata); void (*m_connect_callback)(struct _CServerTcpIP *this, struct _Client *from, void *pdata); void *m_pvPrivateData; } *

variable_types:
from
struct _Client *

variable_types:
pdata
void *

user_defined_types: struct _CServerTcpIP { void (*Free)(struct _CServerTcpIP *this); int (*Send)(struct _CServerTcpIP *this, struct _Client *destinataire, char *buffer, unsigned int buffer_size); int (*GetNbClientsConnected)(struct _CServerTcpIP *this); int (*Start)(struct _CServerTcpIP *this, unsigned short port); int (*Stop)(struct _CServerTcpIP *this); int m_fdListen; unsigned long m_threadListen; struct _Client *m_clistClients; int m_iClientNumber; void (*m_callback)(char *buffer, unsigned int buffer_size, struct _CServerTcpIP *this, struct _Client *from, void *pdata); void (*m_connect_callback)(struct _CServerTcpIP *this, struct _Client *from, void *pdata); void *m_pvPrivateData; }


timestamp

decompiled_code:
char *timestamp()
{
char *v0; // r12
struct timeval v2; // [rsp+0h] [rbp-18h] BYREF

v0 = (char *)malloc(0x10uLL);
gettimeofday(&v2, 0LL);
sprintf(v0, "%d%d", v2.tv_sec, v2.tv_usec / 1000);
return v0;
}

canonical_decompiled_code:
char *func3()
{
char *v0; // r12
struct timeval v2; // [rsp+0h] [rbp-18h] BYREF

v0 = (char *)malloc(0x10uLL);
gettimeofday(&v2, 0LL);
sprintf(v0, "%d%d", v2.tv_sec, v2.tv_usec / 1000);
return v0;
}

original_code:
char *timestamp(){
 struct timeval tv;
 char *timestamp = malloc (sizeof (*timestamp) * 16);
 gettimeofday(&tv,((void *)0));
 sprintf(timestamp,"%d%d",tv.tv_sec, tv.tv_usec/1000);
 return timestamp;
}

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

variable_types:
timestamp
char *


afficheTrame

decompiled_code:
int __fastcall afficheTrame(__int64 a1, __int64 a2)
{
int result; // eax
__int64 *v3; // rbx
__int64 v4; // rsi
__int64 v5[4]; // [rsp+8h] [rbp-20h] BYREF

v5[0] = a2;
result = printf("id=\"0x%X\" dlc=\"%d\" data=\"", (unsigned int)a1, BYTE4(a1));
if ( BYTE4(a1) )
{
v3 = v5;
do
{
v4 = *(unsigned __int8 *)v3;
v3 = (__int64 *)((char *)v3 + 1);
result = printf("%X ", v4);
}
while ( v3 != (__int64 *)((char *)v5 + BYTE4(a1)) );
}
return result;
}

canonical_decompiled_code:
int __fastcall func5(__int64 a1, __int64 a2)
{
int result; // eax
__int64 *v3; // rbx
__int64 v4; // rsi
__int64 v5[4]; // [rsp+8h] [rbp-20h] BYREF

v5[0] = a2;
result = printf("id=\"0x%X\" dlc=\"%d\" data=\"", (unsigned int)a1, BYTE4(a1));
if ( BYTE4(a1) )
{
v3 = v5;
do
{
v4 = *(unsigned __int8 *)v3;
v3 = (__int64 *)((char *)v3 + 1);
result = printf("%X ", v4);
}
while ( v3 != (__int64 *)((char *)v5 + BYTE4(a1)) );
}
return result;
}

original_code:
void afficheTrame(struct can_frame cf){
 int i = 0;
 printf("id=\"0x%X\" dlc=\"%d\" data=\"", cf.can_id, cf.can_dlc);
 for(i = 0;i < cf.can_dlc;i++){
  printf("%X ",cf.data[i]);
 }
}

variable_types: struct can_frame { unsigned int can_id; unsigned char can_dlc; unsigned char __pad; unsigned char __res0; unsigned char __res1; unsigned char data[8]; }


parseXML

decompiled_code:
void __fastcall parseXML(__int64 a1, __int64 a2, __int64 a3)
{
char *v3; // r12
char *v4; // rbp
char *v5; // rax
__int64 v6; // rbx
__int64 v7; // rcx
__int64 v8; // r8
__int64 v9; // rdx
char *v10; // rax
__int64 v11[6]; // [rsp+8h] [rbp-30h]

v11[0] = a3;
v3 = (char *)malloc(0x800uLL);
v4 = (char *)malloc(0x800uLL);
v5 = timestamp();
sprintf(v3, "<trame><id>0x%X</id><dlc>%d</dlc><timestamp>%s</timestamp><data>", (unsigned int)a2, BYTE4(a2), v5);
if ( BYTE4(a2) )
{
v6 = 0LL;
do
{
v7 = *((unsigned __int8 *)v11 + v6);
v8 = (unsigned int)v6;
v9 = (unsigned int)v6++;
sprintf(v4, "<data%d>0x%X</data%d>", v9, v7, v8);
strcat(v3, v4);
*(_QWORD *)v4 = 0LL;
}
while ( BYTE4(a2) > (int)v6 );
}
*(__m128i *)v4 = _mm_load_si128((const __m128i *)&LC16);
strcat(v3, v4);
*(_QWORD *)v4 = 0LL;
ecrireXML(v3);
sprintf(v4, "<?xml version=\"1.0\" encoding=\"UTF-8\"?><%s>%s</%s>\n", can_iface_ptr, v3, can_iface_ptr);
v10 = stpcpy(v3, v4);
(*(void (__fastcall **)(__int64, _QWORD, char *, signed __int64))(a1 + 8))(a1, 0LL, v3, v10 - v3);
free(v4);
free(v3);
}

canonical_decompiled_code:
void __fastcall func6(__int64 a1, __int64 a2, __int64 a3)
{
char *v3; // r12
char *v4; // rbp
char *v5; // rax
__int64 v6; // rbx
__int64 v7; // rcx
__int64 v8; // r8
__int64 v9; // rdx
char *v10; // rax
__int64 v11[6]; // [rsp+8h] [rbp-30h]

v11[0] = a3;
v3 = (char *)malloc(0x800uLL);
v4 = (char *)malloc(0x800uLL);
v5 = func3();
sprintf(v3, "<trame><id>0x%X</id><dlc>%d</dlc><timestamp>%s</timestamp><data>", (unsigned int)a2, BYTE4(a2), v5);
if ( BYTE4(a2) )
{
v6 = 0LL;
do
{
v7 = *((unsigned __int8 *)v11 + v6);
v8 = (unsigned int)v6;
v9 = (unsigned int)v6++;
sprintf(v4, "<data%d>0x%X</data%d>", v9, v7, v8);
strcat(v3, v4);
*(_QWORD *)v4 = 0LL;
}
while ( BYTE4(a2) > (int)v6 );
}
*(__m128i *)v4 = _mm_load_si128((const __m128i *)&LC16);
strcat(v3, v4);
*(_QWORD *)v4 = 0LL;
func4(v3);
sprintf(v4, "<?xml version=\"1.0\" encoding=\"UTF-8\"?><%s>%s</%s>\n", can_iface_ptr, v3, can_iface_ptr);
v10 = stpcpy(v3, v4);
(*(void (__fastcall **)(__int64, _QWORD, char *, signed __int64))(a1 + 8))(a1, 0LL, v3, v10 - v3);
free(v4);
free(v3);
}

original_code:
void parseXML(CServerTcpIP *this, struct can_frame cf){
 int i = 0;
 char *trame = malloc (sizeof (*trame) * 2048);
 char *temp = malloc (sizeof (*temp) * 2048);
 sprintf(trame, "<trame><id>0x%X</id><dlc>%d</dlc><timestamp>%s</timestamp><data>", cf.can_id, cf.can_dlc, timestamp());
 for(i = 0;i < cf.can_dlc;i++){
  sprintf(temp, "<data%d>0x%X</data%d>", i, cf.data[i], i);
  strcat(trame, temp);
  memset (temp, 0, sizeof (temp));
 }
 sprintf(temp, "</data></trame>");
 strcat(trame, temp);
 memset (temp, 0, sizeof (temp));
 ecrireXML(trame);
 sprintf(temp, "<?xml version=\"1.0\" encoding=\"UTF-8\"?><%s>%s</%s>\n", can_iface_ptr, trame, can_iface_ptr);
 strcpy(trame, temp);
 this->Send (this, ((void *)0), trame, strlen(trame));
 free(temp);
 free(trame);
}

canonical_original_code:
void parseXML(struct _CServerTcpIP *this, struct can_frame cf){
 int i = 0;
 char *trame = malloc (sizeof (*trame) * 2048);
 char *temp = malloc (sizeof (*temp) * 2048);
 sprintf(trame, "<trame><id>0x%X</id><dlc>%d</dlc><timestamp>%s</timestamp><data>", cf.can_id, cf.can_dlc, timestamp());
 for(i = 0;i < cf.can_dlc;i++){
  sprintf(temp, "<data%d>0x%X</data%d>", i, cf.data[i], i);
  strcat(trame, temp);
  memset (temp, 0, sizeof (temp));
 }
 sprintf(temp, "</data></trame>");
 strcat(trame, temp);
 memset (temp, 0, sizeof (temp));
 ecrireXML(trame);
 sprintf(temp, "<?xml version=\"1.0\" encoding=\"UTF-8\"?><%s>%s</%s>\n", can_iface_ptr, trame, can_iface_ptr);
 strcpy(trame, temp);
 this->Send (this, ((void *)0), trame, strlen(trame));
 free(temp);
 free(trame);
}

variable_types:
trame
char *

variable_types:
temp
char *

user_defined_types: struct can_frame { unsigned int can_id; unsigned char can_dlc; unsigned char __pad; unsigned char __res0; unsigned char __res1; unsigned char data[8]; }

user_defined_types: struct _Client { int fd; char *adresseIP; unsigned int port; struct _Client *next; }


protocole

decompiled_code:
char __fastcall protocole(char *s, unsigned int a2, __int64 a3, __int64 a4)
{
bool v7; // al
bool v8; // cf
bool v9; // zf
const char *v10; // rsi
__int64 v11; // rcx
char *v12; // rdi
char result; // al
char *v14; // r14
__int64 v15; // r15
char *v16; // rax
char *v17; // rbx
size_t v18; // rax
char *v19; // r14
char *v20; // rax
char sa[3]; // [rsp+Dh] [rbp-4Bh] BYREF
__int64 v22; // [rsp+10h] [rbp-48h]
__int64 v23[8]; // [rsp+18h] [rbp-40h]

printf("%s @ %d : Client %s:%d\n", "protocole", 129LL, *(const char **)(a4 + 8), *(unsigned int *)(a4 + 16));
printf("%s @ %d : %d octets recu : %s\n", "protocole", 130LL, a2, s);
if ( !memcmp("enregistrer", s, 0xBuLL) )
{
v19 = strdup(s);
strtok(v19, "-\n");
v20 = strtok(0LL, "-\n");
sprintf(fileRep, "/home/pi/xml/%s", v20);
printf(aR, fileRep);
initXML();
free(v19);
if ( (unsigned int)can_isok() == 1 )
((void (*)(void))can_close)();
if ( (unsigned int)can_init(can_iface_ptr) )
goto LABEL_24;
if ( (unsigned int)can_bind_receive(0LL, 0LL, 0LL, 0LL, dump) )
fwrite("Erreur au bind de reception\n", 1uLL, 0x1CuLL, stderr);
}
v7 = memcmp("cansend", s, 7uLL) != 0;
v8 = 0;
v9 = !v7;
if ( !v7 )
{
v14 = strdup(s);
if ( strtok(v14, " #\n") )
{
v15 = 0LL;
v16 = strtok(0LL, " #\n");
LODWORD(v22) = strtol(v16, 0LL, 16);
v17 = strtok(0LL, " #\n");
while ( 1 )
{
v18 = strlen(v17);
if ( v18 <= 2 * v15 )
break;
sprintf(sa, "%c%c", (unsigned int)v17[2 * v15], (unsigned int)v17[2 * v15 + 1]);
*((_BYTE *)v23 + v15++) = strtol(sa, 0LL, 16);
}
}
else
{
v18 = strlen(0LL);
}
BYTE4(v22) = ((v18 - 1) >> 1) + ((v18 - 1) & 1);
free(v14);
if ( (unsigned int)can_isok() || !(unsigned int)can_init(can_iface_ptr) )
{
can_send(v22, v23[0]);
parseXML(a3, v22, v23[0]);
goto LABEL_3;
}
LABEL_24:
puts("Il y a eu un erreur a l'init du CAN");
exit(1);
}
LABEL_3:
v10 = "stop";
v11 = 4LL;
v12 = s;
do
{
if ( !v11 )
break;
v8 = (unsigned int)*v10 < (unsigned __int8)*v12;
v9 = *v10++ == (unsigned __int8)*v12++;
--v11;
}
while ( v9 );
if ( (!v8 && !v9) == v8 )
can_close(v12, v10);
v9 = memcmp("exit", s, 4uLL) == 0;
result = !v9;
if ( v9 )
{
result = (*(__int64 (__fastcall **)(__int64, __int64, const char *, __int64))(a3 + 8))(a3, a4, "Bye bye !\n", 10LL);
serveur_running = 0;
}
return result;
}

canonical_decompiled_code:
char __fastcall func7(char *s, unsigned int a2, __int64 a3, __int64 a4)
{
bool v7; // al
bool v8; // cf
bool v9; // zf
const char *v10; // rsi
__int64 v11; // rcx
char *v12; // rdi
char result; // al
char *v14; // r14
__int64 v15; // r15
char *v16; // rax
char *v17; // rbx
size_t v18; // rax
char *v19; // r14
char *v20; // rax
char sa[3]; // [rsp+Dh] [rbp-4Bh] BYREF
__int64 v22; // [rsp+10h] [rbp-48h]
__int64 v23[8]; // [rsp+18h] [rbp-40h]

printf("%s @ %d : Client %s:%d\n", "protocole", 129LL, *(const char **)(a4 + 8), *(unsigned int *)(a4 + 16));
printf("%s @ %d : %d octets recu : %s\n", "protocole", 130LL, a2, s);
if ( !memcmp("enregistrer", s, 0xBuLL) )
{
v19 = strdup(s);
strtok(v19, "-\n");
v20 = strtok(0LL, "-\n");
sprintf(fileRep, "/home/pi/xml/%s", v20);
printf(aR, fileRep);
func2();
free(v19);
if ( (unsigned int)can_isok() == 1 )
((void (*)(void))can_close)();
if ( (unsigned int)can_init(can_iface_ptr) )
goto LABEL_24;
if ( (unsigned int)can_bind_receive(0LL, 0LL, 0LL, 0LL, dump) )
fwrite("Erreur au bind de reception\n", 1uLL, 0x1CuLL, stderr);
}
v7 = memcmp("cansend", s, 7uLL) != 0;
v8 = 0;
v9 = !v7;
if ( !v7 )
{
v14 = strdup(s);
if ( strtok(v14, " #\n") )
{
v15 = 0LL;
v16 = strtok(0LL, " #\n");
LODWORD(v22) = strtol(v16, 0LL, 16);
v17 = strtok(0LL, " #\n");
while ( 1 )
{
v18 = strlen(v17);
if ( v18 <= 2 * v15 )
break;
sprintf(sa, "%c%c", (unsigned int)v17[2 * v15], (unsigned int)v17[2 * v15 + 1]);
*((_BYTE *)v23 + v15++) = strtol(sa, 0LL, 16);
}
}
else
{
v18 = strlen(0LL);
}
BYTE4(v22) = ((v18 - 1) >> 1) + ((v18 - 1) & 1);
free(v14);
if ( (unsigned int)can_isok() || !(unsigned int)can_init(can_iface_ptr) )
{
can_send(v22, v23[0]);
func6(a3, v22, v23[0]);
goto LABEL_3;
}
LABEL_24:
puts("Il y a eu un erreur a l'init du CAN");
exit(1);
}
LABEL_3:
v10 = "stop";
v11 = 4LL;
v12 = s;
do
{
if ( !v11 )
break;
v8 = (unsigned int)*v10 < (unsigned __int8)*v12;
v9 = *v10++ == (unsigned __int8)*v12++;
--v11;
}
while ( v9 );
if ( (!v8 && !v9) == v8 )
can_close(v12, v10);
v9 = memcmp("exit", s, 4uLL) == 0;
result = !v9;
if ( v9 )
{
result = (*(__int64 (__fastcall **)(__int64, __int64, const char *, __int64))(a3 + 8))(a3, a4, "Bye bye !\n", 10LL);
serveur_running = 0;
}
return result;
}

original_code:
void protocole (char *buffer, unsigned int buffer_size, CServerTcpIP *this, Client *expediteur, void *private_data){
 printf("%s @ %d : " "Client %s:%d\n", __FUNCTION__, 129, expediteur->adresseIP, expediteur->port);
 printf("%s @ %d : " "%d octets recu : %s\n", __FUNCTION__, 130, buffer_size, buffer);
 if (strncmp ("enregistrer", buffer, 11) == 0) {
  char *separateur = "-\n";
  char *Chaine_Entrante;
  char *nom;
  nom = malloc (sizeof (*nom) * 256);
  Chaine_Entrante = strdup(buffer);
  nom = strtok(Chaine_Entrante, separateur);
  nom = strtok(((void *)0), separateur);
  sprintf(fileRep, "/home/pi/xml/%s",nom);
  printf("Répertoire du fichier : %s\n",fileRep);
  initXML();
  free(Chaine_Entrante);
  if(can_isok() == 1){
   can_close();
  }
  void dump(CServerTcpIP *this, struct can_frame cf);
  if(can_init(can_iface_ptr)){
   printf("Il y a eu un erreur a l'init du CAN\n");
   exit(1);
  }
  if(can_bind_receive(0x000, 0x000, ((void *)0), 0, dump)){
   fprintf(stderr, "Erreur au bind de reception\n");
  }
 }
 if (strncmp ("cansend", buffer, 7) == 0) {
  char *separateur = " #\n";
  char *Chaine_Entrante;
  char *trame;
  struct can_frame msg;
  int i, j;
  char data[3];
  j =0;
  trame = malloc (sizeof (*trame) * 256);
  Chaine_Entrante = strdup(buffer);
  trame = strtok(Chaine_Entrante, separateur);
  if(trame != ((void *)0)){
   trame = strtok(((void *)0), separateur);
   msg.can_id = (int)strtol(trame, ((void *)0), 16);
  }
  if(trame != ((void *)0)){
   trame = strtok(((void *)0), separateur);
   for(i=0;i<strlen(trame);i+=2){
    sprintf(data, "%c%c", trame[i], trame[i+1]);
    msg.data[j] = (int)strtol(data, ((void *)0), 16);
    j++;
   }
  }
  msg.can_dlc = (strlen(trame)-1)/2+(strlen(trame)-1)%2;
  free(Chaine_Entrante);
  if(can_isok() == 0){
   if(can_init(can_iface_ptr)){
    printf("Il y a eu un erreur a l'init du CAN\n");
    exit(1);
   }
  }
  can_send (msg);
  parseXML(this, msg);
 }
 if (strncmp ("stop", buffer, 4) == 0) {
  can_close();
 }
 if (strncmp ("exit", buffer, 4) == 0) {
  this->Send (this, expediteur, "Bye bye !\n", sizeof ("Bye bye !\n") -1);
  serveur_running = 0;
 }
}

canonical_original_code:
void protocole(char *buffer, unsigned int buffer_size, struct _CServerTcpIP *this, struct _Client *expediteur, void *private_data){
 printf("%s @ %d : " "Client %s:%d\n", __FUNCTION__, 129, expediteur->adresseIP, expediteur->port);
 printf("%s @ %d : " "%d octets recu : %s\n", __FUNCTION__, 130, buffer_size, buffer);
 if (strncmp ("enregistrer", buffer, 11) == 0) {
  char *separateur = "-\n";
  char *Chaine_Entrante;
  char *nom;
  nom = malloc (sizeof (*nom) * 256);
  Chaine_Entrante = strdup(buffer);
  nom = strtok(Chaine_Entrante, separateur);
  nom = strtok(((void *)0), separateur);
  sprintf(fileRep, "/home/pi/xml/%s",nom);
  printf("Répertoire du fichier : %s\n",fileRep);
  initXML();
  free(Chaine_Entrante);
  if(can_isok() == 1){
   can_close();
  }
  void dump(struct _CServerTcpIP *this, struct can_frame cf);
  if(can_init(can_iface_ptr)){
   printf("Il y a eu un erreur a l'init du CAN\n");
   exit(1);
  }
  if(can_bind_receive(0x000, 0x000, ((void *)0), 0, dump)){
   fprintf(stderr, "Erreur au bind de reception\n");
  }
 }
 if (strncmp ("cansend", buffer, 7) == 0) {
  char *separateur = " #\n";
  char *Chaine_Entrante;
  char *trame;
  struct can_frame msg;
  int i; int j;
  char data[3];
  j =0;
  trame = malloc (sizeof (*trame) * 256);
  Chaine_Entrante = strdup(buffer);
  trame = strtok(Chaine_Entrante, separateur);
  if(trame != ((void *)0)){
   trame = strtok(((void *)0), separateur);
   msg.can_id = (int)strtol(trame, ((void *)0), 16);
  }
  if(trame != ((void *)0)){
   trame = strtok(((void *)0), separateur);
   for(i=0;i<strlen(trame);i+=2){
    sprintf(data, "%c%c", trame[i], trame[i+1]);
    msg.data[j] = (int)strtol(data, ((void *)0), 16);
    j++;
   }
  }
  msg.can_dlc = (strlen(trame)-1)/2+(strlen(trame)-1)%2;
  free(Chaine_Entrante);
  if(can_isok() == 0){
   if(can_init(can_iface_ptr)){
    printf("Il y a eu un erreur a l'init du CAN\n");
    exit(1);
   }
  }
  can_send (msg);
  parseXML(this, msg);
 }
 if (strncmp ("stop", buffer, 4) == 0) {
  can_close();
 }
 if (strncmp ("exit", buffer, 4) == 0) {
  this->Send (this, expediteur, "Bye bye !\n", sizeof ("Bye bye !\n") -1);
  serveur_running = 0;
 }
}

variable_types:
buffer
char *

variable_types:
expediteur
struct _Client *

variable_types:
separateur
char *

variable_types:
nom
char *

variable_types: void (struct _CServerTcpIP { void (*Free)(struct _CServerTcpIP *this); int (*Send)(struct _CServerTcpIP *this, struct _Client { int fd; char *adresseIP; unsigned int port; struct _Client *next; } *destinataire, char *buffer, unsigned int buffer_size); int (*GetNbClientsConnected)(struct _CServerTcpIP *this); int (*Start)(struct _CServerTcpIP *this, unsigned short port); int (*Stop)(struct _CServerTcpIP *this); int m_fdListen; unsigned long m_threadListen; struct _Client *m_clistClients; int m_iClientNumber; void (*m_callback)(char *buffer, unsigned int buffer_size, struct _CServerTcpIP *this, struct _Client *from, void *pdata); void (*m_connect_callback)(struct _CServerTcpIP *this, struct _Client *from, void *pdata); void *m_pvPrivateData; } *this, struct can_frame { unsigned int can_id; unsigned char can_dlc; unsigned char __pad; unsigned char __res0; unsigned char __res1; unsigned char data[8]; } cf)

variable_types: j int

variable_types:
data
char [3]


dump

decompiled_code:
void __fastcall dump(__int64 a1, __int64 a2, __int64 a3)
{
if ( (_DWORD)a2 )
parseXML(a1, a2, a3);
}

canonical_decompiled_code:
void __fastcall func8(__int64 a1, __int64 a2, __int64 a3)
{
if ( (_DWORD)a2 )
func6(a1, a2, a3);
}

original_code:
void dump(CServerTcpIP *this, struct can_frame cf){
 if(cf.can_id != 0){
  parseXML(this, cf);
 }
}

canonical_original_code:
void dump(struct _CServerTcpIP *this, struct can_frame cf){
 if(cf.can_id != 0){
  parseXML(this, cf);
 }
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax

signal(15, (__sighandler_t)sigterm);
signal(1, (__sighandler_t)sigterm);
signal(2, (__sighandler_t)sigterm);
printf(
"%s @ %d : Server is listening on port 1234.\nIf a client say \"exit\", he will stop the server.\n",
"main",
266LL);
v3 = CServerTcpIP_New(protocole, onConnect, 0LL);
this = v3;
if ( v3 )
{
if ( (*(unsigned int (__fastcall **)(__int64, __int64))(v3 + 24))(v3, 1234LL) )
{
printf("%s @ %d : Can't start the listen socket\n", "main", 284LL);
}
else
{
serveur_running = 1;
do
sleep(5u);
while ( serveur_running );
if ( (unsigned int)can_isok() == 1 )
can_close(5LL, 1234LL);
(*(void (__fastcall **)(__int64))this)(this);
}
}
else
{
printf("%s @ %d : Can't create CServerTcpIP object\n", "main", 275LL);
}
return 0;
}

original_code:
int main(int argc, char * argv[]){
 signal(15, sigterm);
 signal(1, sigterm);
 signal(2, sigterm);
 int ret;
 printf("%s @ %d : " "Server is listening on port 1234.\nIf a client say \"exit\", he will stop the server.\n", __FUNCTION__, 266);
 this = CServerTcpIP_New (protocole, onConnect, ((void *)0));
 if (this == (CServerTcpIP *) ((void *)0)) {
  printf("%s @ %d : " "Can't create CServerTcpIP object\n", __FUNCTION__, 275);
  return 0;
 }
 ret = this->Start (this, 1234);
 if (ret != 0) {
  printf("%s @ %d : " "Can't start the listen socket\n", __FUNCTION__, 284);
  return 0;
 }
 serveur_running = 1;
 while(serveur_running){
  sleep(5);
 }
 if(can_isok() == 1){
  can_close();
 }
 this->Free (this);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[]){
 signal(15, sigterm);
 signal(1, sigterm);
 signal(2, sigterm);
 int ret;
 printf("%s @ %d : " "Server is listening on port 1234.\nIf a client say \"exit\", he will stop the server.\n", __FUNCTION__, 266);
 this = CServerTcpIP_New (protocole, onConnect, ((void *)0));
 if (this == (struct _CServerTcpIP *) ((void *)0)) {
  printf("%s @ %d : " "Can't create CServerTcpIP object\n", __FUNCTION__, 275);
  return 0;
 }
 ret = this->Start (this, 1234);
 if (ret != 0) {
  printf("%s @ %d : " "Can't start the listen socket\n", __FUNCTION__, 284);
  return 0;
 }
 serveur_running = 1;
 while(serveur_running){
  sleep(5);
 }
 if(can_isok() == 1){
  can_close();
 }
 this->Free (this);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: ret int


decompiled_code:
__int64 __fastcall CServerTcpIP_GetNbClientsConnected(__int64 a1)
{
return *(unsigned int *)(a1 + 64);
}

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

original_code:
static int
CServerTcpIP_GetNbClientsConnected (CServerTcpIP *this)
{
 return this->m_iClientNumber;
}

canonical_original_code:
static int CServerTcpIP_GetNbClientsConnected(struct _CServerTcpIP *this)
{
 return this->m_iClientNumber;
}

variable_types: struct _CServerTcpIP { void (*Free)(struct _CServerTcpIP *this); int (*Send)(struct _CServerTcpIP *this, struct _Client { int fd; char *adresseIP; unsigned int port; struct _Client *next; } *destinataire, char *buffer, unsigned int buffer_size); int (*GetNbClientsConnected)(struct _CServerTcpIP *this); int (*Start)(struct _CServerTcpIP *this, unsigned short port); int (*Stop)(struct _CServerTcpIP *this); int m_fdListen; unsigned long m_threadListen; struct _Client *m_clistClients; int m_iClientNumber; void (*m_callback)(char *buffer, unsigned int buffer_size, struct _CServerTcpIP *this, struct _Client *from, void *pdata); void (*m_connect_callback)(struct _CServerTcpIP *this, struct _Client *from, void *pdata); void *m_pvPrivateData; } *


decompiled_code:
int __fastcall CServerTcpIP_Start(void *arg, unsigned __int16 a2)
{
int v3; // eax
__int16 v4; // ax
int v5; // edi
socklen_t v6; // edx
int result; // eax
unsigned int optval; // [rsp+Ch] [rbp-2Ch] BYREF
struct sockaddr v9[2]; // [rsp+10h] [rbp-28h] BYREF

if ( *((int *)arg + 10) >= 0 )
{
printf("%s @ %d : Listen socket already opened.\n", "CServerTcpIP_Start", 419LL);
return 0;
}
v3 = socket(2, 1, 0);
*((_DWORD *)arg + 10) = v3;
if ( v3 < 0 )
{
printf("%s @ %d : Can't create the socket\n", "CServerTcpIP_Start", 426LL);
return -1;
}
optval = 1;
if ( setsockopt(v3, 1, 2, &optval, 4u) )
printf("%s @ %d : Error on setsockopt with command SO_REUSEADDR and arg=%d\n", "CServerTcpIP_Start", 438LL, optval);
v9[0].sa_family = 2;
*(_DWORD *)&v9[0].sa_data[2] = _bswap_32_constprop_0(a2, v9, 16LL);
v4 = _bswap_16(a2);
v5 = *((_DWORD *)arg + 10);
*(_WORD *)v9[0].sa_data = v4;
if ( bind(v5, v9, v6) < 0 )
{
printf("%s @ %d : Error on bind\n", "CServerTcpIP_Start", 447LL);
LABEL_11:
close(*((_DWORD *)arg + 10));
*((_DWORD *)arg + 10) = -1;
return -1;
}
if ( listen(*((_DWORD *)arg + 10), 512) < 0 )
{
printf("%s @ %d : Error on listen\n", "CServerTcpIP_Start", 454LL);
goto LABEL_11;
}
result = pthread_create((pthread_t *)arg + 6, 0LL, CServerTcpIP_Runtime, arg);
if ( result )
{
printf("%s @ %d : Error on pthread_create\n", "CServerTcpIP_Start", 461LL);
shutdown(*((_DWORD *)arg + 10), 2);
goto LABEL_11;
}
return result;
}

canonical_decompiled_code:
int __fastcall func4(void *arg, unsigned __int16 a2)
{
int v3; // eax
__int16 v4; // ax
int v5; // edi
socklen_t v6; // edx
int result; // eax
unsigned int optval; // [rsp+Ch] [rbp-2Ch] BYREF
struct sockaddr v9[2]; // [rsp+10h] [rbp-28h] BYREF

if ( *((int *)arg + 10) >= 0 )
{
printf("%s @ %d : Listen socket already opened.\n", "CServerTcpIP_Start", 419LL);
return 0;
}
v3 = socket(2, 1, 0);
*((_DWORD *)arg + 10) = v3;
if ( v3 < 0 )
{
printf("%s @ %d : Can't create the socket\n", "CServerTcpIP_Start", 426LL);
return -1;
}
optval = 1;
if ( setsockopt(v3, 1, 2, &optval, 4u) )
printf("%s @ %d : Error on setsockopt with command SO_REUSEADDR and arg=%d\n", "CServerTcpIP_Start", 438LL, optval);
v9[0].sa_family = 2;
*(_DWORD *)&v9[0].sa_data[2] = func3(a2, v9, 16LL);
v4 = func1(a2);
v5 = *((_DWORD *)arg + 10);
*(_WORD *)v9[0].sa_data = v4;
if ( bind(v5, v9, v6) < 0 )
{
printf("%s @ %d : Error on bind\n", "CServerTcpIP_Start", 447LL);
LABEL_11:
close(*((_DWORD *)arg + 10));
*((_DWORD *)arg + 10) = -1;
return -1;
}
if ( listen(*((_DWORD *)arg + 10), 512) < 0 )
{
printf("%s @ %d : Error on listen\n", "CServerTcpIP_Start", 454LL);
goto LABEL_11;
}
result = pthread_create((pthread_t *)arg + 6, 0LL, CServerTcpIP_Runtime, arg);
if ( result )
{
printf("%s @ %d : Error on pthread_create\n", "CServerTcpIP_Start", 461LL);
shutdown(*((_DWORD *)arg + 10), 2);
goto LABEL_11;
}
return result;
}

original_code:
static int
CServerTcpIP_Start (CServerTcpIP *this, unsigned short port)
{
 int ret;
 int sock_opt;
 struct sockaddr_in addr_serv;
 if (this->m_fdListen >= 0) {
  printf("%s @ %d : " "Listen socket already opened.\n", __FUNCTION__, 419);
  return 0;
 }
 this->m_fdListen = socket (2, SOCK_STREAM, 0);
 if (this->m_fdListen < 0) {
  printf("%s @ %d : " "Can't create the socket\n", __FUNCTION__, 426);
  return -1;
 }
 sock_opt = 1;
 ret = setsockopt (this->m_fdListen, 1, 2, (void *) &sock_opt, sizeof (sock_opt));
 if (ret != 0) {
  printf("%s @ %d : " "Error on setsockopt with command SO_REUSEADDR and arg=%d\n", __FUNCTION__, 438, sock_opt);
 }
 addr_serv.sin_family = 2;
    addr_serv.sin_addr.s_addr = htonl(((in_addr_t) 0x00000000));
    addr_serv.sin_port = htons (port);
    ret = bind (this->m_fdListen, (struct sockaddr *) &addr_serv, sizeof(addr_serv));
 if (ret < 0) {
  printf("%s @ %d : " "Error on bind\n", __FUNCTION__, 447);
  goto socket_error;
 }
 ret = listen (this->m_fdListen, (512));
 if (ret < 0) {
  printf("%s @ %d : " "Error on listen\n", __FUNCTION__, 454);
  goto socket_error;
 }
 ret = pthread_create(&(this->m_threadListen), ((void *)0), CServerTcpIP_Runtime, this);
 if (ret != 0) {
  printf("%s @ %d : " "Error on pthread_create\n", __FUNCTION__, 461);
  goto thread_error;
 }
 return 0;
thread_error:
 shutdown (this->m_fdListen, SHUT_RDWR);
socket_error:
 close (this->m_fdListen);
 this->m_fdListen = -1;
 return -1;
}

canonical_original_code:
static int CServerTcpIP_Start(struct _CServerTcpIP *this, unsigned short port)
{
 int ret;
 int sock_opt;
 struct sockaddr_in addr_serv;
 if (this->m_fdListen >= 0) {
  printf("%s @ %d : " "Listen socket already opened.\n", __FUNCTION__, 419);
  return 0;
 }
 this->m_fdListen = socket (2, SOCK_STREAM, 0);
 if (this->m_fdListen < 0) {
  printf("%s @ %d : " "Can't create the socket\n", __FUNCTION__, 426);
  return -1;
 }
 sock_opt = 1;
 ret = setsockopt (this->m_fdListen, 1, 2, (void *) &sock_opt, sizeof (sock_opt));
 if (ret != 0) {
  printf("%s @ %d : " "Error on setsockopt with command SO_REUSEADDR and arg=%d\n", __FUNCTION__, 438, sock_opt);
 }
 addr_serv.sin_family = 2;
    addr_serv.sin_addr.s_addr = htonl(((unsigned int) 0x00000000));
    addr_serv.sin_port = htons (port);
    ret = bind (this->m_fdListen, (struct sockaddr *) &addr_serv, sizeof(addr_serv));
 if (ret < 0) {
  printf("%s @ %d : " "Error on bind\n", __FUNCTION__, 447);
  goto socket_error;
 }
 ret = listen (this->m_fdListen, (512));
 if (ret < 0) {
  printf("%s @ %d : " "Error on listen\n", __FUNCTION__, 454);
  goto socket_error;
 }
 ret = pthread_create(&(this->m_threadListen), ((void *)0), CServerTcpIP_Runtime, this);
 if (ret != 0) {
  printf("%s @ %d : " "Error on pthread_create\n", __FUNCTION__, 461);
  goto thread_error;
 }
 return 0;
thread_error:
 shutdown (this->m_fdListen, SHUT_RDWR);
socket_error:
 close (this->m_fdListen);
 this->m_fdListen = -1;
 return -1;
}

variable_types:
port
unsigned short

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


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

if ( a2 < 0 )
return 0LL;
for ( result = *(_QWORD *)(a1 + 56); result; result = *(_QWORD *)(result + 24) )
{
if ( *(_DWORD *)result == a2 )
break;
}
return result;
}

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

if ( a2 < 0 )
return 0LL;
for ( result = *(_QWORD *)(a1 + 56); result; result = *(_QWORD *)(result + 24) )
{
if ( *(_DWORD *)result == a2 )
break;
}
return result;
}

original_code:
Client *CServerTcpIP_FindClient (CServerTcpIP* this, int fd)
{
 if (fd < 0)
  return (Client *) ((void *)0);
 if (this->m_clistClients == (Client *) ((void *)0)) {
  return (Client *) ((void *)0);
 } else {
  Client *curseur = this->m_clistClients;
  do {
   if (curseur->fd == fd) {
    return curseur;
   }
   curseur = curseur->next;
  } while (curseur != (Client *) ((void *)0));
 }
 return (Client *) ((void *)0);
}

canonical_original_code:
struct _Client *CServerTcpIP_FindClient(struct _CServerTcpIP *this, int fd)
{
 if (fd < 0)
  return (struct _Client *) ((void *)0);
 if (this->m_clistClients == (struct _Client *) ((void *)0)) {
  return (struct _Client *) ((void *)0);
 } else {
  struct _Client *curseur = this->m_clistClients;
  do {
   if (curseur->fd == fd) {
    return curseur;
   }
   curseur = curseur->next;
  } while (curseur != (struct _Client *) ((void *)0));
 }
 return (struct _Client *) ((void *)0);
}

variable_types: struct _CServerTcpIP { void (*Free)(struct _CServerTcpIP *this); int (*Send)(struct _CServerTcpIP *this, struct _Client *destinataire, char *buffer, unsigned int buffer_size); int (*GetNbClientsConnected)(struct _CServerTcpIP *this); int (*Start)(struct _CServerTcpIP *this, unsigned short port); int (*Stop)(struct _CServerTcpIP *this); int m_fdListen; unsigned long m_threadListen; struct _Client *m_clistClients; int m_iClientNumber; void (*m_callback)(char *buffer, unsigned int buffer_size, struct _CServerTcpIP *this, struct _Client *from, void *pdata); void (*m_connect_callback)(struct _CServerTcpIP *this, struct _Client *from, void *pdata); void *m_pvPrivateData; } *

variable_types: fd int

variable_types: struct _Client { int fd; char *adresseIP; unsigned int port; struct _Client *next; } *


decompiled_code:
void __fastcall CServerTcpIP_FreeClient(void *ptr)
{
shutdown(*(_DWORD *)ptr, 2);
printf("%s @ %d : Close fd=%d\n", "CServerTcpIP_FreeClient", 88LL, *(unsigned int *)ptr);
close(*(_DWORD *)ptr);
free(*((void **)ptr + 1));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func6(void *ptr)
{
shutdown(*(_DWORD *)ptr, 2);
printf("%s @ %d : Close fd=%d\n", "CServerTcpIP_FreeClient", 88LL, *(unsigned int *)ptr);
close(*(_DWORD *)ptr);
free(*((void **)ptr + 1));
free(ptr);
}

original_code:
void CServerTcpIP_FreeClient (Client *client)
{
 shutdown (client->fd, SHUT_RDWR);
 printf("%s @ %d : " "Close fd=%d\n", __FUNCTION__, 88, client->fd);
 close (client->fd);
 free (client->adresseIP);
 free (client);
}

canonical_original_code:
void CServerTcpIP_FreeClient(struct _Client *client)
{
 shutdown (client->fd, SHUT_RDWR);
 printf("%s @ %d : " "Close fd=%d\n", __FUNCTION__, 88, client->fd);
 close (client->fd);
 free (client->adresseIP);
 free (client);
}


original_code:
void CServerTcpIP_AddClient (CServerTcpIP *this, Client *client)
{
 if (this == (CServerTcpIP *) ((void *)0))
  return;
 if (client == (Client *) ((void *)0))
  return;
 if (this->m_clistClients == (Client *) ((void *)0)) {
  this->m_clistClients = client;
 } else {
  Client *curseur = this->m_clistClients;
  while (curseur->next != (Client *) ((void *)0)) {
   curseur = curseur->next;
  }
  curseur->next = client;
 }
 this->m_iClientNumber = this->m_iClientNumber + 1;
}

canonical_original_code:
void CServerTcpIP_AddClient(struct _CServerTcpIP *this, struct _Client *client)
{
 if (this == (struct _CServerTcpIP *) ((void *)0))
  return;
 if (client == (struct _Client *) ((void *)0))
  return;
 if (this->m_clistClients == (struct _Client *) ((void *)0)) {
  this->m_clistClients = client;
 } else {
  struct _Client *curseur = this->m_clistClients;
  while (curseur->next != (struct _Client *) ((void *)0)) {
   curseur = curseur->next;
  }
  curseur->next = client;
 }
 this->m_iClientNumber = this->m_iClientNumber + 1;
}

variable_types:
client
struct _Client *


decompiled_code:
void __fastcall CServerTcpIP_DelClient(__int64 a1, _QWORD *a2)
{
_QWORD *v3; // rbp
_QWORD *v4; // rdi
_QWORD *v5; // rdx
__int64 v6; // rax
__int64 v7; // rax

if ( a2 && a1 )
{
v3 = *(_QWORD **)(a1 + 56);
if ( v3 )
{
if ( v3 == a2 )
{
CServerTcpIP_FreeClient(*(void **)(a1 + 56));
v7 = v3[3];
--*(_DWORD *)(a1 + 64);
*(_QWORD *)(a1 + 56) = v7;
}
else
{
v4 = (_QWORD *)v3[3];
v5 = 0LL;
while ( 1 )
{
v6 = v4[3];
if ( v4 == a2 )
{
v5[3] = v6;
--*(_DWORD *)(a1 + 64);
CServerTcpIP_FreeClient(v4);
return;
}
v5 = v4;
if ( !v6 )
break;
v4 = (_QWORD *)v4[3];
}
printf("%s @ %d : Client fantome !\n", "CServerTcpIP_DelClient", 164LL);
}
}
else
{
printf("%s @ %d : Client fantome !\n", "CServerTcpIP_DelClient", 147LL);
}
}
}

canonical_decompiled_code:
void __fastcall func8(__int64 a1, _QWORD *a2)
{
_QWORD *v3; // rbp
_QWORD *v4; // rdi
_QWORD *v5; // rdx
__int64 v6; // rax
__int64 v7; // rax

if ( a2 && a1 )
{
v3 = *(_QWORD **)(a1 + 56);
if ( v3 )
{
if ( v3 == a2 )
{
func6(*(void **)(a1 + 56));
v7 = v3[3];
--*(_DWORD *)(a1 + 64);
*(_QWORD *)(a1 + 56) = v7;
}
else
{
v4 = (_QWORD *)v3[3];
v5 = 0LL;
while ( 1 )
{
v6 = v4[3];
if ( v4 == a2 )
{
v5[3] = v6;
--*(_DWORD *)(a1 + 64);
func6(v4);
return;
}
v5 = v4;
if ( !v6 )
break;
v4 = (_QWORD *)v4[3];
}
printf("%s @ %d : Client fantome !\n", "CServerTcpIP_DelClient", 164LL);
}
}
else
{
printf("%s @ %d : Client fantome !\n", "CServerTcpIP_DelClient", 147LL);
}
}
}

original_code:
void CServerTcpIP_DelClient (CServerTcpIP *this, Client *client)
{
 Client *curseur;
 Client *curseur_prec = ((void *)0);
 if (this == (CServerTcpIP *) ((void *)0))
  return;
 if (client == (Client *) ((void *)0))
  return;
 if (this->m_clistClients == (Client *) ((void *)0)) {
  printf("%s @ %d : " "Client fantome !\n", __FUNCTION__, 147);
  return;
 }
 if (this->m_clistClients == client) {
  CServerTcpIP_FreeClient (client);
  this->m_clistClients = client->next;
  this->m_iClientNumber = this->m_iClientNumber - 1;
  return;
 }
 curseur = this->m_clistClients->next;
 while (curseur != client) {
  curseur_prec = curseur;
  curseur = curseur->next;
  if (curseur == (Client *) ((void *)0)){
   printf("%s @ %d : " "Client fantome !\n", __FUNCTION__, 164);
   return;
  }
 }
 curseur_prec->next = curseur->next;
 this->m_iClientNumber = this->m_iClientNumber - 1;
 CServerTcpIP_FreeClient (curseur);
}

canonical_original_code:
void CServerTcpIP_DelClient(struct _CServerTcpIP *this, struct _Client *client)
{
 struct _Client *curseur;
 struct _Client *curseur_prec = ((void *)0);
 if (this == (struct _CServerTcpIP *) ((void *)0))
  return;
 if (client == (struct _Client *) ((void *)0))
  return;
 if (this->m_clistClients == (struct _Client *) ((void *)0)) {
  printf("%s @ %d : " "Client fantome !\n", __FUNCTION__, 147);
  return;
 }
 if (this->m_clistClients == client) {
  CServerTcpIP_FreeClient (client);
  this->m_clistClients = client->next;
  this->m_iClientNumber = this->m_iClientNumber - 1;
  return;
 }
 curseur = this->m_clistClients->next;
 while (curseur != client) {
  curseur_prec = curseur;
  curseur = curseur->next;
  if (curseur == (struct _Client *) ((void *)0)){
   printf("%s @ %d : " "Client fantome !\n", __FUNCTION__, 164);
   return;
  }
 }
 curseur_prec->next = curseur->next;
 this->m_iClientNumber = this->m_iClientNumber - 1;
 CServerTcpIP_FreeClient (curseur);
}


decompiled_code:
void __fastcall __noreturn CServerTcpIP_Runtime(void *a1)
{
nfds_t v2; // r14
struct pollfd *v3; // r12
int v4; // eax
__int64 v5; // rdx
struct pollfd *v6; // rax
int v7; // ecx
int v8; // eax
struct pollfd *v9; // r13
int i; // er15
void (__fastcall *v11)(char *, _QWORD, __int64, __int64, _QWORD); // rbp
__int64 v12; // rax
unsigned int v13; // er11
__int64 v14; // rdx
int v15; // eax
__int16 v16; // ax
_QWORD *v17; // rax
_QWORD *v18; // rbp
int v19; // eax
char *v20; // rax
char *v21; // rax
__int16 v22; // di
unsigned __int16 v23; // ax
__int64 v24; // rdx
const char *v25; // rcx
void (__fastcall *v26)(void *, _QWORD *, _QWORD); // rax
int v27; // [rsp+4h] [rbp-2864h]
int v28; // [rsp+8h] [rbp-2860h]
socklen_t addr_len; // [rsp+1Ch] [rbp-284Ch] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-2848h] BYREF
char s[10296]; // [rsp+30h] [rbp-2838h] BYREF

addr_len = 16;
pthread_setcancelstate(0, 0LL);
pthread_setcanceltype(0, 0LL);
LABEL_2:
while ( 1 )
{
v27 = *((_DWORD *)a1 + 16);
v2 = v27 + 1;
v3 = (struct pollfd *)malloc(8 * v2);
if ( v3 )
break;
printf("%s @ %d : Erreur critique sur l'allocation de pfd\n", "CServerTcpIP_Runtime", 253LL);
}
v4 = *((_DWORD *)a1 + 10);
v3->events = 3;
v5 = *((_QWORD *)a1 + 7);
v3->fd = v4;
if ( v27 > 0 )
{
v6 = v3 + 1;
do
{
v7 = *(_DWORD *)v5;
++v6;
v5 = *(_QWORD *)(v5 + 24);
v6[-1].fd = v7;
v6[-1].events = 3;
}
while ( v6 != &v3[(unsigned int)(v27 - 1) + 2] );
}
do
{
LABEL_6:
while ( 1 )
{
pthread_testcancel();
v8 = poll(v3, v2, 5000);
if ( v8 >= 0 )
break;
printf("%s @ %d : Erreur sur le poll\n", "CServerTcpIP_Runtime", 276LL);
}
}
while ( !v8 || v27 + 1 <= 0 );
v28 = 0;
v9 = v3;
for ( i = 0; ; i = v15 )
{
v16 = v9->revents;
if ( (v16 & 3) == 0 )
break;
if ( i )
{
memset(s, 0, 0x2800uLL);
if ( (int)recv(v9->fd, s, 0x2800uLL, 0) > 0 )
{
v11 = (void (__fastcall *)(char *, _QWORD, __int64, __int64, _QWORD))*((_QWORD *)a1 + 9);
if ( v11 )
{
v12 = CServerTcpIP_FindClient((__int64)a1, v9->fd);
v11(s, v13, v14, v12, *((_QWORD *)a1 + 11));
}
LABEL_14:
v15 = i + 1;
++v9;
if ( v27 <= i )
goto LABEL_26;
continue;
}
goto LABEL_18;
}
v18 = malloc(0x20uLL);
v19 = accept(*((_DWORD *)a1 + 10), &addr, &addr_len);
*(_DWORD *)v18 = v19;
if ( v19 >= 0 )
{
v18[3] = 0LL;
v20 = inet_ntoa(*(struct in_addr *)&addr.sa_data[2]);
v21 = strdup(v20);
v22 = *(_WORD *)addr.sa_data;
v18[1] = v21;
v23 = _bswap_16(v22);
*((_DWORD *)v18 + 4) = v23;
printf("%s @ %d : Connection de IP=%s:%d\n", "CServerTcpIP_Runtime", v24, v25, v23);
CServerTcpIP_AddClient((__int64)a1, (__int64)v18);
v26 = (void (__fastcall *)(void *, _QWORD *, _QWORD))*((_QWORD *)a1 + 10);
if ( v26 )
v26(a1, v18, *((_QWORD *)a1 + 11));
goto LABEL_19;
}
++v9;
free(v18);
v15 = 1;
if ( v27 <= 0 )
{
LABEL_26:
if ( v28 )
{
LABEL_27:
free(v3);
goto LABEL_2;
}
goto LABEL_6;
}
LABEL_15:
;
}
if ( (v16 & 0x18) == 0 )
goto LABEL_14;
LABEL_18:
v17 = (_QWORD *)CServerTcpIP_FindClient((__int64)a1, v9->fd);
CServerTcpIP_DelClient((__int64)a1, v17);
LABEL_19:
v15 = i + 1;
++v9;
if ( v27 <= i )
goto LABEL_27;
v28 = 1;
goto LABEL_15;
}

canonical_decompiled_code:
void __fastcall __noreturn func9(void *a1)
{
nfds_t v2; // r14
struct pollfd *v3; // r12
int v4; // eax
__int64 v5; // rdx
struct pollfd *v6; // rax
int v7; // ecx
int v8; // eax
struct pollfd *v9; // r13
int i; // er15
void (__fastcall *v11)(char *, _QWORD, __int64, __int64, _QWORD); // rbp
__int64 v12; // rax
unsigned int v13; // er11
__int64 v14; // rdx
int v15; // eax
__int16 v16; // ax
_QWORD *v17; // rax
_QWORD *v18; // rbp
int v19; // eax
char *v20; // rax
char *v21; // rax
__int16 v22; // di
unsigned __int16 v23; // ax
__int64 v24; // rdx
const char *v25; // rcx
void (__fastcall *v26)(void *, _QWORD *, _QWORD); // rax
int v27; // [rsp+4h] [rbp-2864h]
int v28; // [rsp+8h] [rbp-2860h]
socklen_t addr_len; // [rsp+1Ch] [rbp-284Ch] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-2848h] BYREF
char s[10296]; // [rsp+30h] [rbp-2838h] BYREF

addr_len = 16;
pthread_setcancelstate(0, 0LL);
pthread_setcanceltype(0, 0LL);
LABEL_2:
while ( 1 )
{
v27 = *((_DWORD *)a1 + 16);
v2 = v27 + 1;
v3 = (struct pollfd *)malloc(8 * v2);
if ( v3 )
break;
printf("%s @ %d : Erreur critique sur l'allocation de pfd\n", "CServerTcpIP_Runtime", 253LL);
}
v4 = *((_DWORD *)a1 + 10);
v3->events = 3;
v5 = *((_QWORD *)a1 + 7);
v3->fd = v4;
if ( v27 > 0 )
{
v6 = v3 + 1;
do
{
v7 = *(_DWORD *)v5;
++v6;
v5 = *(_QWORD *)(v5 + 24);
v6[-1].fd = v7;
v6[-1].events = 3;
}
while ( v6 != &v3[(unsigned int)(v27 - 1) + 2] );
}
do
{
LABEL_6:
while ( 1 )
{
pthread_testcancel();
v8 = poll(v3, v2, 5000);
if ( v8 >= 0 )
break;
printf("%s @ %d : Erreur sur le poll\n", "CServerTcpIP_Runtime", 276LL);
}
}
while ( !v8 || v27 + 1 <= 0 );
v28 = 0;
v9 = v3;
for ( i = 0; ; i = v15 )
{
v16 = v9->revents;
if ( (v16 & 3) == 0 )
break;
if ( i )
{
memset(s, 0, 0x2800uLL);
if ( (int)recv(v9->fd, s, 0x2800uLL, 0) > 0 )
{
v11 = (void (__fastcall *)(char *, _QWORD, __int64, __int64, _QWORD))*((_QWORD *)a1 + 9);
if ( v11 )
{
v12 = func5((__int64)a1, v9->fd);
v11(s, v13, v14, v12, *((_QWORD *)a1 + 11));
}
LABEL_14:
v15 = i + 1;
++v9;
if ( v27 <= i )
goto LABEL_26;
continue;
}
goto LABEL_18;
}
v18 = malloc(0x20uLL);
v19 = accept(*((_DWORD *)a1 + 10), &addr, &addr_len);
*(_DWORD *)v18 = v19;
if ( v19 >= 0 )
{
v18[3] = 0LL;
v20 = inet_ntoa(*(struct in_addr *)&addr.sa_data[2]);
v21 = strdup(v20);
v22 = *(_WORD *)addr.sa_data;
v18[1] = v21;
v23 = func1(v22);
*((_DWORD *)v18 + 4) = v23;
printf("%s @ %d : Connection de IP=%s:%d\n", "CServerTcpIP_Runtime", v24, v25, v23);
func7((__int64)a1, (__int64)v18);
v26 = (void (__fastcall *)(void *, _QWORD *, _QWORD))*((_QWORD *)a1 + 10);
if ( v26 )
v26(a1, v18, *((_QWORD *)a1 + 11));
goto LABEL_19;
}
++v9;
free(v18);
v15 = 1;
if ( v27 <= 0 )
{
LABEL_26:
if ( v28 )
{
LABEL_27:
free(v3);
goto LABEL_2;
}
goto LABEL_6;
}
LABEL_15:
;
}
if ( (v16 & 0x18) == 0 )
goto LABEL_14;
LABEL_18:
v17 = (_QWORD *)func5((__int64)a1, v9->fd);
func8((__int64)a1, v17);
LABEL_19:
v15 = i + 1;
++v9;
if ( v27 <= i )
goto LABEL_27;
v28 = 1;
goto LABEL_15;
}

original_code:
void *
CServerTcpIP_Runtime (void *pdata)
{
 CServerTcpIP *this = (CServerTcpIP *)pdata;
 char buffer_rx[(10*1024)];
 int i, ret, readed;
 int pfd_size;
 struct pollfd *pfd = ((void *)0);
 Client *curseur;
 Client *welcome;
 struct sockaddr_in addr_client;
 unsigned int size_addr_client = sizeof(struct sockaddr_in);
 int flag;
 pthread_setcancelstate (PTHREAD_CANCEL_ENABLE, ((void *)0));
 pthread_setcanceltype (PTHREAD_CANCEL_DEFERRED, ((void *)0));
 while (1)
 {
  if (pfd != (struct pollfd *) ((void *)0))
   free (pfd);
  pfd_size = 1 + this->m_iClientNumber;
  pfd = (struct pollfd *) malloc (pfd_size * sizeof (struct pollfd));
  if (pfd == (struct pollfd *) ((void *)0)) {
   printf("%s @ %d : " "Erreur critique sur l'allocation de pfd\n", __FUNCTION__, 253);
   continue;
  }
  pfd[0].fd = this->m_fdListen;
  pfd[0].events = 0x001 | 0x002;
  curseur = this->m_clistClients;
  for (i=0; i<(pfd_size-1); i++) {
   pfd[i+1].fd = curseur->fd;
   pfd[i+1].events = 0x001 | 0x002;
   curseur = curseur->next;
  }
  flag = 0;
  do {
   pthread_testcancel ();
   ret = poll (pfd, pfd_size, 5000 );
   if (ret < 0) {
    printf("%s @ %d : " "Erreur sur le poll\n", __FUNCTION__, 276);
   } else if (ret == 0) {
    do {} while(0);
   } else {
    for (i=0; i<pfd_size; i++) {
     if (pfd[i].revents & (0x001 | 0x002)) {
      if (i == 0) {
       welcome = (Client *) malloc (sizeof (Client));
       welcome->fd = accept(this->m_fdListen, (struct sockaddr *) &addr_client, &size_addr_client);
       if (welcome->fd < 0) {
        free (welcome);
       } else {
        welcome->next = ((void *)0);
        welcome->adresseIP = strdup(inet_ntoa(addr_client.sin_addr));
        welcome->port = ntohs(addr_client.sin_port);
        printf("%s @ %d : " "Connection de IP=%s:%d\n", __FUNCTION__, 296, welcome->adresseIP, welcome->port);
        CServerTcpIP_AddClient (this, welcome);
        if (this->m_connect_callback != (CServerTcpIP_connect_t) ((void *)0)) {
         this->m_connect_callback (this, welcome, this->m_pvPrivateData);
        }
        flag = 1;
       }
      } else {
       memset (buffer_rx, '\0', (10*1024));
       readed = recv (pfd[i].fd, buffer_rx, (10*1024), 0);
       if (readed <= 0) {
        CServerTcpIP_DelClient (this, CServerTcpIP_FindClient (this, pfd[i].fd));
        flag = 1;
       } else {
        if (this->m_callback != (CServerTcpIP_rx_t) ((void *)0)) {
         Client *tmp = CServerTcpIP_FindClient (this, pfd[i].fd);
         this->m_callback (buffer_rx, readed, this, tmp, this->m_pvPrivateData);
        }
       }
      }
     } else if (pfd[i].revents & (0x008 | 0x010)) {
      CServerTcpIP_DelClient (this, CServerTcpIP_FindClient (this, pfd[i].fd));
      flag = 1;
     }
    }
   }
  } while (!flag);
 }
}

canonical_original_code:
void *CServerTcpIP_Runtime(void *pdata)
{
 struct _CServerTcpIP *this = (CServerTcpIP *)pdata;
 char buffer_rx[-1];
 int i; int ret; int readed;
 int pfd_size;
 struct pollfd *pfd = ((void *)0);
 struct _Client *curseur;
 struct _Client *welcome;
 struct sockaddr_in addr_client;
 unsigned int size_addr_client = sizeof(struct sockaddr_in);
 int flag;
 pthread_setcancelstate (PTHREAD_CANCEL_ENABLE, ((void *)0));
 pthread_setcanceltype (PTHREAD_CANCEL_DEFERRED, ((void *)0));
 while (1)
 {
  if (pfd != (struct pollfd *) ((void *)0))
   free (pfd);
  pfd_size = 1 + this->m_iClientNumber;
  pfd = (struct pollfd *) malloc (pfd_size * sizeof (struct pollfd));
  if (pfd == (struct pollfd *) ((void *)0)) {
   printf("%s @ %d : " "Erreur critique sur l'allocation de pfd\n", __FUNCTION__, 253);
   continue;
  }
  pfd[0].fd = this->m_fdListen;
  pfd[0].events = 0x001 | 0x002;
  curseur = this->m_clistClients;
  for (i=0; i<(pfd_size-1); i++) {
   pfd[i+1].fd = curseur->fd;
   pfd[i+1].events = 0x001 | 0x002;
   curseur = curseur->next;
  }
  flag = 0;
  do {
   pthread_testcancel ();
   ret = poll (pfd, pfd_size, 5000 );
   if (ret < 0) {
    printf("%s @ %d : " "Erreur sur le poll\n", __FUNCTION__, 276);
   } else if (ret == 0) {
    do {} while(0);
   } else {
    for (i=0; i<pfd_size; i++) {
     if (pfd[i].revents & (0x001 | 0x002)) {
      if (i == 0) {
       welcome = (struct _Client *) malloc (sizeof (Client));
       welcome->fd = accept(this->m_fdListen, (struct sockaddr *) &addr_client, &size_addr_client);
       if (welcome->fd < 0) {
        free (welcome);
       } else {
        welcome->next = ((void *)0);
        welcome->adresseIP = strdup(inet_ntoa(addr_client.sin_addr));
        welcome->port = ntohs(addr_client.sin_port);
        printf("%s @ %d : " "Connection de IP=%s:%d\n", __FUNCTION__, 296, welcome->adresseIP, welcome->port);
        CServerTcpIP_AddClient (this, welcome);
        if (this->m_connect_callback != (CServerTcpIP_connect_t) ((void *)0)) {
         this->m_connect_callback (this, welcome, this->m_pvPrivateData);
        }
        flag = 1;
       }
      } else {
       memset (buffer_rx, '\0', (10*1024));
       readed = recv (pfd[i].fd, buffer_rx, (10*1024), 0);
       if (readed <= 0) {
        CServerTcpIP_DelClient (this, CServerTcpIP_FindClient (this, pfd[i].fd));
        flag = 1;
       } else {
        if (this->m_callback != (CServerTcpIP_rx_t) ((void *)0)) {
         struct _Client *tmp = CServerTcpIP_FindClient (this, pfd[i].fd);
         this->m_callback (buffer_rx, readed, this, tmp, this->m_pvPrivateData);
        }
       }
      }
     } else if (pfd[i].revents & (0x008 | 0x010)) {
      CServerTcpIP_DelClient (this, CServerTcpIP_FindClient (this, pfd[i].fd));
      flag = 1;
     }
    }
   }
  } while (!flag);
 }
}

variable_types:
pdata
void *

variable_types: i int

variable_types: readed int

variable_types: struct pollfd { int fd; short events; short revents; } *

variable_types: flag int

return_type: void *


decompiled_code:
__int64 __fastcall CServerTcpIP_Stop(__int64 a1)
{
int v1; // eax
_QWORD *v2; // rsi
__int64 result; // rax

if ( *(int *)(a1 + 40) < 0 )
{
printf("%s @ %d : Warning listen socket may be not started !\n", "CServerTcpIP_Stop", 182LL);
result = 0xFFFFFFFFLL;
}
else
{
if ( pthread_cancel(*(_QWORD *)(a1 + 48)) < 0 )
{
printf("%s @ %d : No thread to stop !\n", "CServerTcpIP_Stop", 189LL);
}
else
{
v1 = pthread_join(*(_QWORD *)(a1 + 48), 0LL);
if ( !v1 || v1 == -3 )
printf("%s @ %d : Reception thread stopped\n", "CServerTcpIP_Stop", 193LL);
else
printf("%s @ %d : Can't join the Reception thread !\n", "CServerTcpIP_Stop", 195LL);
}
shutdown(*(_DWORD *)(a1 + 40), 2);
close(*(_DWORD *)(a1 + 40));
v2 = *(_QWORD **)(a1 + 56);
for ( *(_DWORD *)(a1 + 40) = -1; v2; v2 = *(_QWORD **)(a1 + 56) )
CServerTcpIP_DelClient(a1, v2);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
int v1; // eax
_QWORD *v2; // rsi
__int64 result; // rax

if ( *(int *)(a1 + 40) < 0 )
{
printf("%s @ %d : Warning listen socket may be not started !\n", "CServerTcpIP_Stop", 182LL);
result = 0xFFFFFFFFLL;
}
else
{
if ( pthread_cancel(*(_QWORD *)(a1 + 48)) < 0 )
{
printf("%s @ %d : No thread to stop !\n", "CServerTcpIP_Stop", 189LL);
}
else
{
v1 = pthread_join(*(_QWORD *)(a1 + 48), 0LL);
if ( !v1 || v1 == -3 )
printf("%s @ %d : Reception thread stopped\n", "CServerTcpIP_Stop", 193LL);
else
printf("%s @ %d : Can't join the Reception thread !\n", "CServerTcpIP_Stop", 195LL);
}
shutdown(*(_DWORD *)(a1 + 40), 2);
close(*(_DWORD *)(a1 + 40));
v2 = *(_QWORD **)(a1 + 56);
for ( *(_DWORD *)(a1 + 40) = -1; v2; v2 = *(_QWORD **)(a1 + 56) )
func8(a1, v2);
result = 0LL;
}
return result;
}

original_code:
static int
CServerTcpIP_Stop (CServerTcpIP *this)
{
 int ret;
 if (this->m_fdListen < 0) {
  printf("%s @ %d : " "Warning listen socket may be not started !\n", __FUNCTION__, 182);
  return -1;
 }
 ret = pthread_cancel (this->m_threadListen);
 if (ret < 0) {
  printf("%s @ %d : " "No thread to stop !\n", __FUNCTION__, 189);
 } else {
  ret = pthread_join (this->m_threadListen, ((void *)0));
  if (ret == 0 || ret == -3) {
   printf("%s @ %d : " "Reception thread stopped\n", __FUNCTION__, 193);
  } else {
   printf("%s @ %d : " "Can't join the Reception thread !\n", __FUNCTION__, 195);
  }
 }
 shutdown (this->m_fdListen, SHUT_RDWR);
 close (this->m_fdListen);
 this->m_fdListen = -1;
 while (this->m_clistClients != (Client *)((void *)0)) {
  do {} while(0);
  CServerTcpIP_DelClient (this, this->m_clistClients);
 }
 return 0;
}

canonical_original_code:
static int CServerTcpIP_Stop(struct _CServerTcpIP *this)
{
 int ret;
 if (this->m_fdListen < 0) {
  printf("%s @ %d : " "Warning listen socket may be not started !\n", __FUNCTION__, 182);
  return -1;
 }
 ret = pthread_cancel (this->m_threadListen);
 if (ret < 0) {
  printf("%s @ %d : " "No thread to stop !\n", __FUNCTION__, 189);
 } else {
  ret = pthread_join (this->m_threadListen, ((void *)0));
  if (ret == 0 || ret == -3) {
   printf("%s @ %d : " "Reception thread stopped\n", __FUNCTION__, 193);
  } else {
   printf("%s @ %d : " "Can't join the Reception thread !\n", __FUNCTION__, 195);
  }
 }
 shutdown (this->m_fdListen, SHUT_RDWR);
 close (this->m_fdListen);
 this->m_fdListen = -1;
 while (this->m_clistClients != (struct _Client *)((void *)0)) {
  do {} while(0);
  CServerTcpIP_DelClient (this, this->m_clistClients);
 }
 return 0;
}


decompiled_code:
void __fastcall CServerTcpIP_Free(void *ptr)
{
CServerTcpIP_Stop((__int64)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func11(void *ptr)
{
func10((__int64)ptr);
free(ptr);
}

original_code:
static void
CServerTcpIP_Free (CServerTcpIP *this)
{
 CServerTcpIP_Stop (this);
 free (this);
}

canonical_original_code:
static void CServerTcpIP_Free(struct _CServerTcpIP *this)
{
 CServerTcpIP_Stop (this);
 free (this);
}