decompiled_code:
__int64 print_lo_info()
{
char v1[256]; // [rsp+8h] [rbp-228h] BYREF
char v2[268]; // [rsp+108h] [rbp-128h] BYREF
unsigned int v3; // [rsp+214h] [rbp-1Ch]
unsigned int v4; // [rsp+218h] [rbp-18h]
unsigned int v5; // [rsp+21Ch] [rbp-14h]
unsigned int v6; // [rsp+220h] [rbp-10h]
unsigned int v7; // [rsp+224h] [rbp-Ch]

lo_version();
printf("liblo version string `%s'\n", v1);
printf("liblo version: %d.%d%s\n", v7, v6, v2);
printf("liblo libtool version: %d.%d.%d\n", v5, v4, v3);
printf("liblo MAX_MSG_SIZE: %d\n", 0x8000LL);
printf("liblo MAX_UDP_MSG_SIZE: %d\n", 0xFFFFLL);
printf("liblo LO_DEFAULT_MAX_MSG_SIZE: %d\n", 0xFFFFLL);
putchar(10);
return 0LL;
}

canonical_decompiled_code:
__int64 func7()
{
char v1[256]; // [rsp+8h] [rbp-228h] BYREF
char v2[268]; // [rsp+108h] [rbp-128h] BYREF
unsigned int v3; // [rsp+214h] [rbp-1Ch]
unsigned int v4; // [rsp+218h] [rbp-18h]
unsigned int v5; // [rsp+21Ch] [rbp-14h]
unsigned int v6; // [rsp+220h] [rbp-10h]
unsigned int v7; // [rsp+224h] [rbp-Ch]

lo_version();
printf("liblo version string `%s'\n", v1);
printf("liblo version: %d.%d%s\n", v7, v6, v2);
printf("liblo libtool version: %d.%d.%d\n", v5, v4, v3);
printf("liblo MAX_MSG_SIZE: %d\n", 0x8000LL);
printf("liblo MAX_UDP_MSG_SIZE: %d\n", 0xFFFFLL);
printf("liblo LO_DEFAULT_MAX_MSG_SIZE: %d\n", 0xFFFFLL);
putchar(10);
return 0LL;
}

original_code:
int print_lo_info()
{
 int major, minor, lt_maj, lt_min, lt_bug;
 char extra[256];
 char string[256];
 lo_version(string, 256,
      &major, &minor, extra, 256,
      &lt_maj, &lt_min, &lt_bug);
 printf("liblo version string `%s'\n", string);
 printf("liblo version: %d.%d%s\n", major, minor, extra);
 printf("liblo libtool version: %d.%d.%d\n", lt_maj, lt_min, lt_bug);
 printf("liblo MAX_MSG_SIZE: %d\n", 32768);
 printf("liblo MAX_UDP_MSG_SIZE: %d\n", 65535);
 printf("liblo LO_DEFAULT_MAX_MSG_SIZE: %d\n", 65535);
 printf("\n");
 return 0;
 printf("\n");
 return 1;
}

canonical_original_code:
int print_lo_info()
{
 int major; int minor; int lt_maj; int lt_min; int lt_bug;
 char extra[256];
 char string[256];
 lo_version(string, 256,
      &major, &minor, extra, 256,
      &lt_maj, &lt_min, &lt_bug);
 printf("liblo version string `%s'\n", string);
 printf("liblo version: %d.%d%s\n", major, minor, extra);
 printf("liblo libtool version: %d.%d.%d\n", lt_maj, lt_min, lt_bug);
 printf("liblo MAX_MSG_SIZE: %d\n", 32768);
 printf("liblo MAX_UDP_MSG_SIZE: %d\n", 65535);
 printf("liblo LO_DEFAULT_MAX_MSG_SIZE: %d\n", 65535);
 printf("\n");
 return 0;
 printf("\n");
 return 1;
}

variable_types: major int

variable_types: minor int

variable_types:
extra
char [256]

variable_types:
string
char [256]


main

canonical_name: main

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

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

original_code:
int main(int argc, char *argv[])
{
 return print_lo_info();
}

variable_types: argc int

variable_types:
argv
char *[]

return_type: int


decompiled_code:
void jack_error()
{
;
}

canonical_decompiled_code:
void func7()
{
;
}

original_code:
static void jack_error(const char* err)
{
}

canonical_original_code:
static void jack_error(char *err)
{
}

variable_types:
err
char *

return_type: void


decompiled_code:
size_t shutdown_callback()
{
connection_to_jack_down = 1;
return fwrite("JACK server down!\n", 1uLL, 0x12uLL, stderr);
}

canonical_decompiled_code:
size_t func8()
{
connection_to_jack_down = 1;
return fwrite("JACK server down!\n", 1uLL, 0x12uLL, stderr);
}

original_code:
static void shutdown_callback(void *arg)
{
 connection_to_jack_down=1;
 fprintf(stderr, "JACK server down!\n");
}

variable_types:
arg
void *


decompiled_code:
void __noreturn signal_handler()
{
fwrite("signal received, exiting ...\n", 1uLL, 0x1DuLL, stderr);
if ( !connection_to_jack_down )
jack_client_close();
exit(0);
}

canonical_decompiled_code:
void __noreturn func9()
{
fwrite("signal received, exiting ...\n", 1uLL, 0x1DuLL, stderr);
if ( !connection_to_jack_down )
jack_client_close();
exit(0);
}

original_code:
static void signal_handler(int sig)
{
 fprintf(stderr, "signal received, exiting ...\n");
 if(!connection_to_jack_down)
 {
  jack_client_close(client);
 }
 exit(0);
}

variable_types: sig int


process

decompiled_code:
__int64 __fastcall process(int a1)
{
void *v2; // r12
__int64 i; // rbx
int v4; // eax

if ( !process_enabled )
return 0LL;
buffer_out_midi = jack_port_get_buffer();
jack_midi_clear_buffer();
v2 = (void *)jack_port_get_buffer();
memset(v2, 0, (unsigned int)(4 * a1));
if ( a1 )
{
for ( i = 0LL; i != a1; ++i )
{
if ( !(frame_counter % (unsigned __int64)frames_between_on_off) )
{
fputc(46, stderr);
send_midi_note(channel_counter, pitch_counter, velocity_counter, is_on);
if ( is_on )
{
*((_DWORD *)v2 + i) = 1061997773;
is_on = 0;
}
else
{
*((_DWORD *)v2 + i) = 0;
is_on = 1;
}
if ( velocity_counter + 1 > 127 )
{
velocity_counter = 0;
if ( pitch_counter + 1 > 127 )
{
pitch_counter = 0;
v4 = channel_counter + 1;
if ( channel_counter + 1 > 15 )
v4 = 0;
channel_counter = v4;
}
else
{
++pitch_counter;
}
}
else
{
++velocity_counter;
}
}
++frame_counter;
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(int a1)
{
void *v2; // r12
__int64 i; // rbx
int v4; // eax

if ( !process_enabled )
return 0LL;
buffer_out_midi = jack_port_get_buffer();
jack_midi_clear_buffer();
v2 = (void *)jack_port_get_buffer();
memset(v2, 0, (unsigned int)(4 * a1));
if ( a1 )
{
for ( i = 0LL; i != a1; ++i )
{
if ( !(frame_counter % (unsigned __int64)frames_between_on_off) )
{
fputc(46, stderr);
send_midi_note(channel_counter, pitch_counter, velocity_counter, is_on);
if ( is_on )
{
*((_DWORD *)v2 + i) = 1061997773;
is_on = 0;
}
else
{
*((_DWORD *)v2 + i) = 0;
is_on = 1;
}
if ( velocity_counter + 1 > 127 )
{
velocity_counter = 0;
if ( pitch_counter + 1 > 127 )
{
pitch_counter = 0;
v4 = channel_counter + 1;
if ( channel_counter + 1 > 15 )
v4 = 0;
channel_counter = v4;
}
else
{
++pitch_counter;
}
}
else
{
++velocity_counter;
}
}
++frame_counter;
}
}
return 0LL;
}

original_code:
static int process(jack_nframes_t nframes, void *arg)
{
 if(!process_enabled)
 {
  return 0;
 }
 buffer_out_midi=jack_port_get_buffer(port_out_midi, nframes);
 jack_midi_clear_buffer(buffer_out_midi);
 sample_t *o1;
 o1=(sample_t*)jack_port_get_buffer(ioPortArray[0],nframes);
 memset(o1, 0, nframes*4);
 int k=0;
 for(k=0; k<nframes; k++)
 {
  if(frame_counter % frames_between_on_off==0)
  {
   fprintf(stderr, ".");
   send_midi_note (channel_counter, pitch_counter, velocity_counter, is_on, k);
   if(is_on)
   {
    o1[k]=0.8;
    is_on=0;
   }
   else
   {
    o1[k]=0;
    is_on=1;
   }
   velocity_counter++;
   if(velocity_counter>127)
   {
    velocity_counter=0;
    pitch_counter++;
    if(pitch_counter>127)
    {
     pitch_counter=0;
     channel_counter++;
     if(channel_counter>15)
     {
      channel_counter=0;
     }
    }
   }
  }
  frame_counter++;
 }
 return 0;
}

canonical_original_code:
static int process(unsigned int nframes, void *arg)
{
 if(!process_enabled)
 {
  return 0;
 }
 buffer_out_midi=jack_port_get_buffer(port_out_midi, nframes);
 jack_midi_clear_buffer(buffer_out_midi);
 float *o1;
 o1=(float *)jack_port_get_buffer(ioPortArray[0],nframes);
 memset(o1, 0, nframes*4);
 int k = 0;
 for(k=0; k<nframes; k++)
 {
  if(frame_counter % frames_between_on_off==0)
  {
   fprintf(stderr, ".");
   send_midi_note (channel_counter, pitch_counter, velocity_counter, is_on, k);
   if(is_on)
   {
    o1[k]=0.8;
    is_on=0;
   }
   else
   {
    o1[k]=0;
    is_on=1;
   }
   velocity_counter++;
   if(velocity_counter>127)
   {
    velocity_counter=0;
    pitch_counter++;
    if(pitch_counter>127)
    {
     pitch_counter=0;
     channel_counter++;
     if(channel_counter>15)
     {
      channel_counter=0;
     }
    }
   }
  }
  frame_counter++;
 }
 return 0;
}

variable_types:
nframes
unsigned int

variable_types: k int


decompiled_code:
size_t print_help(void)
{
return fwrite(
"\n"
"commands:\n"
"'CTRL+c' to enter step mode\n"
"in step mode:\n"
"enter a number to process n cycles\n"
"'ENTER' to step one cycle\n"
"'c+ENTER' to continue (leave step mode)\n"
"'CTRL+c+ENTER' to quit\n"
"'h' to show this help\n"
"\n",
1uLL,
0xC8uLL,
stderr);
}

canonical_decompiled_code:
size_t func2(void)
{
return fwrite(
"\n"
"commands:\n"
"'CTRL+c' to enter step mode\n"
"in step mode:\n"
"enter a number to process n cycles\n"
"'ENTER' to step one cycle\n"
"'c+ENTER' to continue (leave step mode)\n"
"'CTRL+c+ENTER' to quit\n"
"'h' to show this help\n"
"\n",
1uLL,
0xC8uLL,
stderr);
}

original_code:
static void print_help (void)
{
 fprintf (stderr, "Usage: oscpp [Options] target_host\n");
 fprintf (stderr, "Options:\n");
 fprintf (stderr, "  Display this text:                     --help\n");
 fprintf (stderr, "  Local port:                    (%s) --lport  <integer>\n",localPort);
 fprintf (stderr, "  Remote port:                   (%s) --rport  <integer>\n",sendToPort);
 fprintf (stderr, "  Delay between messages [usec]:  (1000) --interval  <integer>\n");
 fprintf (stderr, "  Don't send pings (pong only):    (off) --noping\n");
 fprintf (stderr, "  Payload size [bytes]:              (0) --size  <integer>\n");
 fprintf (stderr, "  Limit number of sent messages:   (inf) --count  <integer>\n");
 fprintf (stderr, "target_host:   <string>\n");
 fprintf (stderr, "target_port:   <integer>\n\n");
 fprintf (stderr, "Example: oscpp --interval 100 10.10.10.3 1234\n");
 fprintf (stderr, "oscpp needs to run on the pinged host to get a reply.\n");
 fprintf (stderr, "See http://github.com/7890/jack_tools/\n\n");
 exit (1);
}

canonical_original_code:
static void print_help()
{
 fprintf (stderr, "Usage: oscpp [Options] target_host\n");
 fprintf (stderr, "Options:\n");
 fprintf (stderr, "  Display this text:                     --help\n");
 fprintf (stderr, "  Local port:                    (%s) --lport  <integer>\n",localPort);
 fprintf (stderr, "  Remote port:                   (%s) --rport  <integer>\n",sendToPort);
 fprintf (stderr, "  Delay between messages [usec]:  (1000) --interval  <integer>\n");
 fprintf (stderr, "  Don't send pings (pong only):    (off) --noping\n");
 fprintf (stderr, "  Payload size [bytes]:              (0) --size  <integer>\n");
 fprintf (stderr, "  Limit number of sent messages:   (inf) --count  <integer>\n");
 fprintf (stderr, "target_host:   <string>\n");
 fprintf (stderr, "target_port:   <integer>\n\n");
 fprintf (stderr, "Example: oscpp --interval 100 10.10.10.3 1234\n");
 fprintf (stderr, "oscpp needs to run on the pinged host to get a reply.\n");
 fprintf (stderr, "See http://github.com/7890/jack_tools/\n\n");
 exit (1);
}


freewheel

decompiled_code:
int __fastcall freewheel(int a1, void *a2)
{
int result; // eax

is_freewheeling = a1;
if ( a1 )
fputc(10, stderr);
result = fprintf(stderr, "JACK went to freewheel mode %d\n", (unsigned int)is_freewheeling);
process_enabled = 1;
return result;
}

canonical_decompiled_code:
int __fastcall func4(int a1, void *a2)
{
int result; // eax

is_freewheeling = a1;
if ( a1 )
fputc(10, stderr);
result = fprintf(stderr, "JACK went to freewheel mode %d\n", (unsigned int)is_freewheeling);
process_enabled = 1;
return result;
}

original_code:
static void freewheel(int isfw, void *arg)
{
 lo_message reply=lo_message_new();
 if(isfw)
 {
  lo_message_add_int32(reply,1);
 }
 else
 {
  lo_message_add_int32(reply,0);
 }
 lo_send_message(loa, "/oscev/jack/freewheeling", reply);
 lo_message_free(reply);
 fprintf(stderr,"JACK freewhelling %d\n",isfw);
}

canonical_original_code:
static void freewheel(int isfw, void *arg)
{
 void *reply = lo_message_new();
 if(isfw)
 {
  lo_message_add_int32(reply,1);
 }
 else
 {
  lo_message_add_int32(reply,0);
 }
 lo_send_message(loa, "/oscev/jack/freewheeling", reply);
 lo_message_free(reply);
 fprintf(stderr,"JACK freewhelling %d\n",isfw);
}

variable_types: isfw int

variable_types:
reply
void *


process

decompiled_code:
__int64 __fastcall process(unsigned int a1, void *a2)
{
char v3[32]; // [rsp+10h] [rbp-40h] BYREF
char *nptr; // [rsp+30h] [rbp-20h]
unsigned int v5; // [rsp+38h] [rbp-18h]
int v6; // [rsp+3Ch] [rbp-14h]

if ( !process_enabled || shutdown_in_progress )
return 0LL;
++cycle_count;
v5 = WJACK_last_frame_time(client) - frame_time;
frame_time = (unsigned int)WJACK_last_frame_time(client);
if ( is_freewheeling )
{
fprintf(stderr, "# %ld, %ld (+%d) ", cycle_count, frame_time, v5);
if ( (unsigned __int64)run_n_cycles > 1 )
{
fputc(10, stderr);
--run_n_cycles;
return 0LL;
}
v6 = 0;
std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::basic_string(v3);
while ( !v6 )
{
std::getline<char,std::char_traits<char>,std::allocator<char>>(&std::cin, v3);
nptr = (char *)malloc(0x101uLL);
nptr = (char *)std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::c_str(v3);
run_n_cycles = atoll(nptr);
if ( run_n_cycles )
{
fprintf(stderr, "running for %ld cycles\n", run_n_cycles);
v6 = 1;
}
else if ( (unsigned int)std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::compare(
v3,
&_continue[abi:cxx11]) )
{
if ( (unsigned int)std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::compare(
v3,
&_help[abi:cxx11]) )
{
if ( (unsigned int)std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::compare(
v3,
&_step[abi:cxx11]) )
fwrite("unknown command, enter 'h' for help.\n", 1uLL, 0x25uLL, stderr);
else
v6 = 1;
}
else
{
print_help();
}
}
else
{
return_to_normal_operation = 1;
process_enabled = 0;
v6 = 1;
}
}
std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::~basic_string(v3);
}
else
{
fprintf(stderr, "\r# %d \x1B[0J", cycle_count);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1, void *a2)
{
char v3[32]; // [rsp+10h] [rbp-40h] BYREF
char *nptr; // [rsp+30h] [rbp-20h]
unsigned int v5; // [rsp+38h] [rbp-18h]
int v6; // [rsp+3Ch] [rbp-14h]

if ( !process_enabled || shutdown_in_progress )
return 0LL;
++cycle_count;
v5 = WJACK_last_frame_time(client) - frame_time;
frame_time = (unsigned int)WJACK_last_frame_time(client);
if ( is_freewheeling )
{
fprintf(stderr, "# %ld, %ld (+%d) ", cycle_count, frame_time, v5);
if ( (unsigned __int64)run_n_cycles > 1 )
{
fputc(10, stderr);
--run_n_cycles;
return 0LL;
}
v6 = 0;
std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::basic_string(v3);
while ( !v6 )
{
std::getline<char,std::char_traits<char>,std::allocator<char>>(&std::cin, v3);
nptr = (char *)malloc(0x101uLL);
nptr = (char *)std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::c_str(v3);
run_n_cycles = atoll(nptr);
if ( run_n_cycles )
{
fprintf(stderr, "running for %ld cycles\n", run_n_cycles);
v6 = 1;
}
else if ( (unsigned int)std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::compare(
v3,
&_continue[abi:cxx11]) )
{
if ( (unsigned int)std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::compare(
v3,
&_help[abi:cxx11]) )
{
if ( (unsigned int)std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::compare(
v3,
&_step[abi:cxx11]) )
fwrite("unknown command, enter 'h' for help.\n", 1uLL, 0x25uLL, stderr);
else
v6 = 1;
}
else
{
func2();
}
}
else
{
return_to_normal_operation = 1;
process_enabled = 0;
v6 = 1;
}
}
std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::~basic_string(v3);
}
else
{
fprintf(stderr, "\r# %d \x1B[0J", cycle_count);
}
return 0LL;
}

original_code:
static int process(jack_nframes_t nframes, void *arg)
{
 if(transport_state!=-2)
 {
  transport_state_prev=transport_state;
 }
 transport_state=jack_transport_query(client, ((void *)0));
 if(transport_state!=transport_state_prev)
 {
  lo_message reply=lo_message_new();
  lo_message_add_int32(reply,(int)transport_state);
  lo_send_message(loa, "/oscev/transport", reply);
  lo_message_free(reply);
 }
 return 0;
}

canonical_original_code:
static int process(unsigned int nframes, void *arg)
{
 if(transport_state!=-2)
 {
  transport_state_prev=transport_state;
 }
 transport_state=jack_transport_query(client, ((void *)0));
 if(transport_state!=transport_state_prev)
 {
  void *reply = lo_message_new();
  lo_message_add_int32(reply,(int)transport_state);
  lo_send_message(loa, "/oscev/transport", reply);
  lo_message_free(reply);
 }
 return 0;
}


decompiled_code:
size_t __fastcall print_header(const char *a1)
{
fprintf(stderr, "\n%s v%.2f (format v%.2f)\n", a1, *(float *)&version, *(float *)&format_version);
return fwrite("(C) 2013 - 2014 Thomas Brand <tom@trellis.ch>\n", 1uLL, 0x2FuLL, stderr);
}

canonical_decompiled_code:
size_t __fastcall func0(const char *a1)
{
fprintf(stderr, "\n%s v%.2f (format v%.2f)\n", a1, *(float *)&version, *(float *)&format_version);
return fwrite("(C) 2013 - 2014 Thomas Brand <tom@trellis.ch>\n", 1uLL, 0x2FuLL, stderr);
}

original_code:
void print_header (char *prgname)
{
 fprintf (stderr, "\n%s v%.2f\n", prgname,version);
 fprintf (stderr, "(C) 2014 Thomas Brand  <tom@trellis.ch>\n");
}

canonical_original_code:
void print_header(char *prgname)
{
 fprintf (stderr, "\n%s v%.2f\n", prgname,version);
 fprintf (stderr, "(C) 2014 Thomas Brand  <tom@trellis.ch>\n");
}

variable_types:
prgname
char *


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 *


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


checkKey

decompiled_code:
char *__fastcall checkKey(int a1)
{
_DWORD *v1; // rax
int v2; // edx
char *result; // rax

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

canonical_decompiled_code:
char *__fastcall func9(int a1)
{
_DWORD *v1; // rax
int v2; // edx
char *result; // rax

if ( ((*__ctype_b_loc())[a1] & 0x4000) != 0 && (a1 & 0x100) == 0 )
{
keych_0 = a1;
result = &keych_0;
}
else
{
v1 = &keys;
v2 = 0;
while ( *v1 != a1 )
{
++v2;
v1 += 6;
if ( *v1 == -1 )
return &aArrowUp[24 * v2];
}
result = &aArrowUp[24 * v2];
}
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: ch int

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 *


main

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

signal(3, (__sighandler_t)signal_handler);
signal(15, (__sighandler_t)signal_handler);
signal(1, (__sighandler_t)signal_handler);
signal(2, (__sighandler_t)signal_handler);
setbuf(stdout, 0LL);
if ( argc <= 1 )
{
LABEL_8:
if ( argc <= 3 )
{
if ( argc != 3 )
{
if ( argc <= 1 )
{
LABEL_12:
st = lo_server_thread_new();
lo_server_thread_start();
loa = lo_address_new();
mainwin = initscr();
if ( mainwin )
{
noecho();
curs_set(0);
keypad(mainwin, 1);
v4 = 1;
if ( verbose == 1 )
{
mvprintw(1, 3, "___ sk (sendkeys) ___");
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);
v4 = 5;
}
if ( !quiet )
mvprintw(v4, 3, "(waiting for input)");
while ( 1 )
{
wrefresh(stdscr__NCURSES6_TINFO_5_0_19991023);
v10 = wgetch(stdscr__NCURSES6_TINFO_5_0_19991023);
v11 = v10;
if ( v10 == -1 )
break;
v12 = checkKey(v10);
sendKey(v11, v12);
winsdelln(stdscr__NCURSES6_TINFO_5_0_19991023, -1);
if ( !quiet )
{
if ( verbose == 1 )
{
mvprintw(v4, 3, "0x%x", v11);
v6 = checkKey(v11);
mvprintw(v4, 11, "%s", v6);
if ( v8 ^ v9 | v7 )
{
switch ( indicationCounter )
{
case 0:
case 4:
goto LABEL_29;
case 1:
case 5:
mvprintw(v4, 23, "(/)");
goto LABEL_30;
case 2:
case 6:
mvprintw(v4, 23, "(-)");
goto LABEL_30;
case 3:
case 7:
mvprintw(v4, 23, "(\\)");
goto LABEL_30;
default:
goto LABEL_30;
}
}
indicationCounter = 0;
LABEL_29:
mvprintw(v4, 23, "(|)");
LABEL_30:
++indicationCounter;
}
else
{
v13 = checkKey(v11);
mvprintw(v4, 3, "%s", v13);
}
}
}
signal_handler();
}
fwrite("could not initialize ncurses\n", 1uLL, 0x1DuLL, stderr);
exit(1);
}
LABEL_11:
osc_my_server_port = (char *)argv[1];
goto LABEL_12;
}
}
else
{
osc_send_to_port = (char *)argv[3];
}
osc_send_to_host = (char *)argv[2];
goto LABEL_11;
}
v3 = 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") )
goto LABEL_8;
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)
{
const char *v3; // r12
int v4; // ebp
char *v6; // rax
char v7; // zf
char v8; // sf
char v9; // of
int v10; // eax
unsigned int v11; // ebx
char *v12; // rax
char *v13; // rax

signal(3, (__sighandler_t)signal_handler);
signal(15, (__sighandler_t)signal_handler);
signal(1, (__sighandler_t)signal_handler);
signal(2, (__sighandler_t)signal_handler);
setbuf(stdout, 0LL);
if ( argc <= 1 )
{
LABEL_8:
if ( argc <= 3 )
{
if ( argc != 3 )
{
if ( argc <= 1 )
{
LABEL_12:
st = lo_server_thread_new();
lo_server_thread_start();
loa = lo_address_new();
mainwin = initscr();
if ( mainwin )
{
noecho();
curs_set(0);
keypad(mainwin, 1);
v4 = 1;
if ( verbose == 1 )
{
mvprintw(1, 3, "___ sk (sendkeys) ___");
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);
v4 = 5;
}
if ( !quiet )
mvprintw(v4, 3, "(waiting for input)");
while ( 1 )
{
wrefresh(stdscr__NCURSES6_TINFO_5_0_19991023);
v10 = wgetch(stdscr__NCURSES6_TINFO_5_0_19991023);
v11 = v10;
if ( v10 == -1 )
break;
v12 = func9(v10);
func10(v11, v12);
winsdelln(stdscr__NCURSES6_TINFO_5_0_19991023, -1);
if ( !quiet )
{
if ( verbose == 1 )
{
mvprintw(v4, 3, "0x%x", v11);
v6 = func9(v11);
mvprintw(v4, 11, "%s", v6);
if ( v8 ^ v9 | v7 )
{
switch ( indicationCounter )
{
case 0:
case 4:
goto LABEL_29;
case 1:
case 5:
mvprintw(v4, 23, "(/)");
goto LABEL_30;
case 2:
case 6:
mvprintw(v4, 23, "(-)");
goto LABEL_30;
case 3:
case 7:
mvprintw(v4, 23, "(\\)");
goto LABEL_30;
default:
goto LABEL_30;
}
}
indicationCounter = 0;
LABEL_29:
mvprintw(v4, 23, "(|)");
LABEL_30:
++indicationCounter;
}
else
{
v13 = func9(v11);
mvprintw(v4, 3, "%s", v13);
}
}
}
func8();
}
fwrite("could not initialize ncurses\n", 1uLL, 0x1DuLL, stderr);
exit(1);
}
LABEL_11:
osc_my_server_port = (char *)argv[1];
goto LABEL_12;
}
}
else
{
osc_send_to_port = (char *)argv[3];
}
osc_send_to_host = (char *)argv[2];
goto LABEL_11;
}
v3 = 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") )
goto LABEL_8;
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: indent int

variable_types: lastLine int


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


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
char v4[32]; // [rsp+0h] [rbp-238h] BYREF
char s[8]; // [rsp+20h] [rbp-218h] BYREF
__int64 v6; // [rsp+28h] [rbp-210h]
char v7[480]; // [rsp+30h] [rbp-208h] BYREF
int v8; // [rsp+210h] [rbp-28h]

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

canonical_decompiled_code:
int __fastcall func6(__int64 *a1, int a2)
{
__int64 *v2; // rbx
char v4[32]; // [rsp+0h] [rbp-238h] BYREF
char s[8]; // [rsp+20h] [rbp-218h] BYREF
__int64 v6; // [rsp+28h] [rbp-210h]
char v7[480]; // [rsp+30h] [rbp-208h] BYREF
int v8; // [rsp+210h] [rbp-28h]

*(_QWORD *)s = 0LL;
v6 = 0LL;
memset(v7, 0, sizeof(v7));
v8 = 0;
if ( a2 > 0 )
{
v2 = a1;
do
{
func1(*v2, v4);
sprintf(s, "%s - %s", s, v4);
++v2;
}
while ( v2 != &a1[(unsigned int)(a2 - 1) + 1] );
}
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 __fastcall wait(int a1)
{
int v1; // edi
int i; // eax

v1 = 100 * a1;
if ( v1 > 0 )
{
for ( i = 0; i != v1; ++i )
;
}
}

canonical_decompiled_code:
void __fastcall func8(int a1)
{
int v1; // edi
int i; // eax

v1 = 100 * a1;
if ( v1 > 0 )
{
for ( i = 0; i != v1; ++i )
;
}
}

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(int *a1, int a2)
{
tri_bulle_horloge(a1, a2);
return tri_bulle_site(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func3(int *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

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // er12
int v4; // ebp
unsigned int v5; // ebp
int v6; // ebp
__int64 v7; // rbp
int v8; // eax
__int64 v9; // rax
unsigned int v10; // eax
int v11; // er14
unsigned int v12; // eax
int v13; // eax
__int64 v14; // rbp
int v15; // eax
int v16; // eax
__int64 v17; // rbp
int v18; // eax
int v19; // ebp
int v20; // eax
unsigned int v21; // eax
void *v22; // [rsp+8h] [rbp-D0h]
unsigned int fd; // [rsp+10h] [rbp-C8h]
int v24; // [rsp+14h] [rbp-C4h]
unsigned int v25; // [rsp+14h] [rbp-C4h]
unsigned __int64 v26; // [rsp+18h] [rbp-C0h]
__int64 v27; // [rsp+28h] [rbp-B0h] BYREF
char s[24]; // [rsp+30h] [rbp-A8h] BYREF
unsigned int v29; // [rsp+48h] [rbp-90h] BYREF
int v30; // [rsp+4Ch] [rbp-8Ch] BYREF
char buf[44]; // [rsp+50h] [rbp-88h] BYREF
socklen_t addr_len; // [rsp+7Ch] [rbp-5Ch] BYREF
struct sockaddr v33; // [rsp+80h] [rbp-58h] BYREF
struct sockaddr addr; // [rsp+90h] [rbp-48h] BYREF

v30 = 0;
v29 = 0;
v22 = 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);
}
v3 = argc - 2;
v4 = atoi(argv[1]);
v5 = GetSitePos((unsigned int)(argc - 2), argv) + v4;
printf("Numero de port de ce site %d\n", v5);
addr.sa_family = 2;
*(_DWORD *)&addr.sa_data[2] = (unsigned __int16)_bswap_16(0);
*(_WORD *)addr.sa_data = _bswap_16(v5);
fd = socket(2, 1, 0);
if ( fd != -1 )
{
if ( bind(fd, &addr, 0x10u) != -1 )
{
listen(fd, 30);
v6 = GetSitePos(v3, argv);
if ( v6 )
{
v12 = atoi(argv[1]);
SendSync(argv[2], v12);
puts("Wait Synchro du Site 0");
WaitSync(fd);
puts("Synchro recue de Site 0");
}
else if ( argc <= 3 )
{
puts("Toutes les synchros recues");
}
else
{
do
{
WaitSync(fd);
++v6;
}
while ( v6 != argc - 3 );
puts("Toutes les synchros recues");
v7 = 0LL;
do
{
v8 = atoi(argv[1]);
SendSync(argv[v7 + 3], (unsigned int)(v8 + v7 + 1));
v9 = v7++;
}
while ( v9 != argc - 4 );
}
v10 = GetSitePos(v3, argv);
printf("Je suis le site numero : %d \n", v10);
fcntl(fd, 4, 2048LL);
addr_len = 16;
v24 = 1;
v11 = 1;
while ( 1 )
{
v18 = accept(fd, &v33, &addr_len);
v19 = v18;
if ( v18 <= 0 )
{
v13 = SC();
if ( v24 && v13 == 1 )
{
printf("Requete envoye : %d \n", ++v29);
v25 = GetSitePos(v3, argv);
v26 = v25 | (((unsigned __int64)v29 << 32) | (unsigned int)v26) & 0xFFFFFFFF00000000LL;
RequeteToString(v26, s);
v14 = 0LL;
do
{
if ( v25 == (_DWORD)v14 )
{
v26 = v26 & 0xFFFFFFFF00000000LL | (unsigned int)v14;
push(v26, v22, &v30);
}
else
{
v15 = atoi(argv[1]);
SendMsg(argv[v14 + 2], (unsigned int)(v15 + v14), s);
}
++v14;
}
while ( argc - 2 != v14 );
v24 = 0;
}
}
else
{
buf[(int)read(v18, buf, 0x27uLL)] = 0;
StringToRequete(buf, &v27);
Horloge(&v29, HIDWORD(v27));
if ( (_DWORD)v27 == argc - 1 )
{
printf("Reponse recu : %d \n", v29);
++v11;
}
else if ( (_DWORD)v27 == argc )
{
printf("Liberation recu : %d \n", v29);
pop(v22, &v30);
}
else
{
push(v27, v22, &v30);
sprintf(s, "%d:%d", (unsigned int)(argc - 1), v29);
v20 = atoi(argv[1]);
SendMsg(argv[(int)v27 + 2], (unsigned int)(v20 + v27), s);
printf("Requete recu : %d \n", v29);
}
close(v19);
}
if ( v11 == v3 )
{
v21 = GetSitePos(v3, argv);
v11 = argc - 2;
if ( (unsigned int)isFirst(v22, v21) )
{
puts("Je passe en SC");
wait((__WAIT_STATUS)10000LL);
puts("Je sors de la SC");
v17 = 0LL;
do
{
if ( (unsigned int)GetSitePos(v3, argv) == (_DWORD)v17 )
{
pop(v22, &v30);
}
else
{
sprintf(s, "%d:%d", (unsigned int)argc, v29);
v16 = atoi(argv[1]);
SendMsg(argv[v17 + 2], (unsigned int)(v16 + v17), s);
}
++v17;
}
while ( v17 != argc - 2 );
puts("Envoi des liberations");
v24 = 1;
v11 = 1;
}
}
wait((__WAIT_STATUS)10000LL);
}
}
perror("Bind socket");
exit(-1);
}
perror("Creation socket");
exit(-1);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // er12
int v4; // ebp
unsigned int v5; // ebp
int v6; // ebp
__int64 v7; // rbp
int v8; // eax
__int64 v9; // rax
unsigned int v10; // eax
int v11; // er14
unsigned int v12; // eax
int v13; // eax
__int64 v14; // rbp
int v15; // eax
int v16; // eax
__int64 v17; // rbp
int v18; // eax
int v19; // ebp
int v20; // eax
unsigned int v21; // eax
void *v22; // [rsp+8h] [rbp-D0h]
unsigned int fd; // [rsp+10h] [rbp-C8h]
int v24; // [rsp+14h] [rbp-C4h]
unsigned int v25; // [rsp+14h] [rbp-C4h]
unsigned __int64 v26; // [rsp+18h] [rbp-C0h]
__int64 v27; // [rsp+28h] [rbp-B0h] BYREF
char s[24]; // [rsp+30h] [rbp-A8h] BYREF
unsigned int v29; // [rsp+48h] [rbp-90h] BYREF
int v30; // [rsp+4Ch] [rbp-8Ch] BYREF
char buf[44]; // [rsp+50h] [rbp-88h] BYREF
socklen_t addr_len; // [rsp+7Ch] [rbp-5Ch] BYREF
struct sockaddr v33; // [rsp+80h] [rbp-58h] BYREF
struct sockaddr addr; // [rsp+90h] [rbp-48h] BYREF

v30 = 0;
v29 = 0;
v22 = 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);
}
v3 = argc - 2;
v4 = atoi(argv[1]);
v5 = GetSitePos((unsigned int)(argc - 2), argv) + v4;
printf("Numero de port de ce site %d\n", v5);
addr.sa_family = 2;
*(_DWORD *)&addr.sa_data[2] = (unsigned __int16)func0(0);
*(_WORD *)addr.sa_data = func0(v5);
fd = socket(2, 1, 0);
if ( fd != -1 )
{
if ( bind(fd, &addr, 0x10u) != -1 )
{
listen(fd, 30);
v6 = GetSitePos(v3, argv);
if ( v6 )
{
v12 = atoi(argv[1]);
SendSync(argv[2], v12);
puts("Wait Synchro du Site 0");
WaitSync(fd);
puts("Synchro recue de Site 0");
}
else if ( argc <= 3 )
{
puts("Toutes les synchros recues");
}
else
{
do
{
WaitSync(fd);
++v6;
}
while ( v6 != argc - 3 );
puts("Toutes les synchros recues");
v7 = 0LL;
do
{
v8 = atoi(argv[1]);
SendSync(argv[v7 + 3], (unsigned int)(v8 + v7 + 1));
v9 = v7++;
}
while ( v9 != argc - 4 );
}
v10 = GetSitePos(v3, argv);
printf("Je suis le site numero : %d \n", v10);
fcntl(fd, 4, 2048LL);
addr_len = 16;
v24 = 1;
v11 = 1;
while ( 1 )
{
v18 = accept(fd, &v33, &addr_len);
v19 = v18;
if ( v18 <= 0 )
{
v13 = SC();
if ( v24 && v13 == 1 )
{
printf("Requete envoye : %d \n", ++v29);
v25 = GetSitePos(v3, argv);
v26 = v25 | (((unsigned __int64)v29 << 32) | (unsigned int)v26) & 0xFFFFFFFF00000000LL;
RequeteToString(v26, s);
v14 = 0LL;
do
{
if ( v25 == (_DWORD)v14 )
{
v26 = v26 & 0xFFFFFFFF00000000LL | (unsigned int)v14;
push(v26, v22, &v30);
}
else
{
v15 = atoi(argv[1]);
SendMsg(argv[v14 + 2], (unsigned int)(v15 + v14), s);
}
++v14;
}
while ( argc - 2 != v14 );
v24 = 0;
}
}
else
{
buf[(int)read(v18, buf, 0x27uLL)] = 0;
StringToRequete(buf, &v27);
Horloge(&v29, HIDWORD(v27));
if ( (_DWORD)v27 == argc - 1 )
{
printf("Reponse recu : %d \n", v29);
++v11;
}
else if ( (_DWORD)v27 == argc )
{
printf("Liberation recu : %d \n", v29);
pop(v22, &v30);
}
else
{
push(v27, v22, &v30);
sprintf(s, "%d:%d", (unsigned int)(argc - 1), v29);
v20 = atoi(argv[1]);
SendMsg(argv[(int)v27 + 2], (unsigned int)(v20 + v27), s);
printf("Requete recu : %d \n", v29);
}
close(v19);
}
if ( v11 == v3 )
{
v21 = GetSitePos(v3, argv);
v11 = argc - 2;
if ( (unsigned int)isFirst(v22, v21) )
{
puts("Je passe en SC");
wait((__WAIT_STATUS)10000LL);
puts("Je sors de la SC");
v17 = 0LL;
do
{
if ( (unsigned int)GetSitePos(v3, argv) == (_DWORD)v17 )
{
pop(v22, &v30);
}
else
{
sprintf(s, "%d:%d", (unsigned int)argc, v29);
v16 = atoi(argv[1]);
SendMsg(argv[v17 + 2], (unsigned int)(v16 + v17), s);
}
++v17;
}
while ( v17 != argc - 2 );
puts("Envoi des liberations");
v24 = 1;
v11 = 1;
}
}
wait((__WAIT_STATUS)10000LL);
}
}
perror("Bind socket");
exit(-1);
}
perror("Creation socket");
exit(-1);
}

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[72]; // [rsp+0h] [rbp-48h] BYREF

gethostname(v4, 0x14uLL);
if ( a1 <= 0 )
{
LABEL_5:
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_5;
}
return (unsigned int)v2;
}

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

gethostname(v4, 0x14uLL);
if ( a1 <= 0 )
{
LABEL_5:
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_5;
}
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; // ebx
struct sockaddr v3; // [rsp+0h] [rbp-58h] BYREF
socklen_t addr_len; // [rsp+1Ch] [rbp-3Ch] BYREF
char buf[56]; // [rsp+20h] [rbp-38h] BYREF

addr_len = 16;
printf("WaitSync : ");
fflush(0LL);
v1 = accept(fd, &v3, &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; // ebx
struct sockaddr v3; // [rsp+0h] [rbp-58h] BYREF
socklen_t addr_len; // [rsp+1Ch] [rbp-3Ch] BYREF
char buf[56]; // [rsp+20h] [rbp-38h] BYREF

addr_len = 16;
printf("WaitSync : ");
fflush(0LL);
v1 = accept(fd, &v3, &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; // ebx
struct hostent *v4; // r12
size_t v5; // rax
struct sockaddr v7; // [rsp+0h] [rbp-38h] BYREF
char s[39]; // [rsp+11h] [rbp-27h] BYREF

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

canonical_decompiled_code:
int __fastcall func3(char *name, __int16 a2)
{
int v2; // eax
int v3; // ebx
struct hostent *v4; // r12
size_t v5; // rax
struct sockaddr v7; // [rsp+0h] [rbp-38h] BYREF
char s[39]; // [rsp+11h] [rbp-27h] BYREF

v2 = socket(2, 1, 0);
if ( v2 == -1 )
{
perror("SendSync : Creation socket");
exit(-1);
}
v3 = v2;
v4 = gethostbyname(name);
if ( !v4 )
{
perror("SendSync: Gethostbyname");
exit(-1);
}
v7.sa_family = 2;
*(_WORD *)v7.sa_data = func0(a2);
memcpy(&v7.sa_data[2], *(const void **)v4->h_addr_list, v4->h_length);
if ( connect(v3, &v7, 0x10u) == -1 )
{
perror("SendSync : Connect");
exit(-1);
}
strcpy(s, "**SYNCHRO**");
v5 = strlen(s);
write(v3, s, v5);
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; // ebx
struct hostent *v6; // r12
size_t v7; // rax
struct sockaddr v9[3]; // [rsp+0h] [rbp-38h] BYREF

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

canonical_decompiled_code:
int __fastcall func4(char *name, __int16 a2, const char *a3)
{
int v4; // eax
int v5; // ebx
struct hostent *v6; // r12
size_t v7; // rax
struct sockaddr v9[3]; // [rsp+0h] [rbp-38h] BYREF

v4 = socket(2, 1, 0);
if ( v4 == -1 )
{
perror("SendSync : Creation socket");
exit(-1);
}
v5 = v4;
v6 = gethostbyname(name);
if ( !v6 )
{
perror("SendSync: Gethostbyname");
exit(-1);
}
v9[0].sa_family = 2;
*(_WORD *)v9[0].sa_data = func0(a2);
memcpy(&v9[0].sa_data[2], *(const void **)v6->h_addr_list, v6->h_length);
if ( connect(v5, v9, 0x10u) == -1 )
{
perror("SendSync : Connect");
exit(-1);
}
v7 = strlen(a3);
write(v5, a3, v7);
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; // rbx
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; // rbx
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[4]; // [rsp+8h] [rbp-20h] BYREF

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

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

v4[0] = a2;
result = printf("id=\"0x%X\" dlc=\"%d\" data=\"", (unsigned int)a1, BYTE4(a1));
if ( BYTE4(a1) )
{
v3 = v4;
do
{
result = printf("%X ", *(unsigned __int8 *)v3);
v3 = (__int64 *)((char *)v3 + 1);
}
while ( v3 != (__int64 *)((char *)v4 + 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
size_t v7; // rax
__int64 v8[6]; // [rsp+8h] [rbp-30h]

v8[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
{
sprintf(v4, "<data%d>0x%X</data%d>", (unsigned int)v6, *((unsigned __int8 *)v8 + v6), (unsigned int)v6);
strcat(v3, v4);
*(_QWORD *)v4 = 0LL;
++v6;
}
while ( BYTE4(a2) > (int)v6 );
}
strcpy(v4, "</data></trame>");
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);
strcpy(v3, v4);
v7 = strlen(v3);
(*(void (__fastcall **)(__int64, _QWORD, char *, size_t))(a1 + 8))(a1, 0LL, v3, v7);
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
size_t v7; // rax
__int64 v8[6]; // [rsp+8h] [rbp-30h]

v8[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
{
sprintf(v4, "<data%d>0x%X</data%d>", (unsigned int)v6, *((unsigned __int8 *)v8 + v6), (unsigned int)v6);
strcat(v3, v4);
*(_QWORD *)v4 = 0LL;
++v6;
}
while ( BYTE4(a2) > (int)v6 );
}
strcpy(v4, "</data></trame>");
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);
strcpy(v3, v4);
v7 = strlen(v3);
(*(void (__fastcall **)(__int64, _QWORD, char *, size_t))(a1 + 8))(a1, 0LL, v3, v7);
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; // rbp
char *v15; // rax
char *v16; // r15
char *v17; // r12
char *v18; // rax
__int64 i; // rbp
size_t 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) )
{
v14 = strdup(s);
strtok(v14, "-\n");
v15 = strtok(0LL, "-\n");
sprintf(fileRep, "/home/pi/xml/%s", v15);
printf(aR, fileRep);
initXML();
free(v14);
if ( (unsigned int)can_isok() == 1 )
((void (*)(void))can_close)();
if ( (unsigned int)can_init(can_iface_ptr) )
{
puts("Il y a eu un erreur a l'init du CAN");
exit(1);
}
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 )
{
v16 = strdup(s);
v17 = strtok(v16, " #\n");
if ( v17 )
{
v18 = strtok(0LL, " #\n");
LODWORD(v22) = strtol(v18, 0LL, 16);
v17 = strtok(0LL, " #\n");
for ( i = 0LL; strlen(v17) > 2 * i; ++i )
{
sprintf(sa, "%c%c", (unsigned int)v17[2 * i], (unsigned int)v17[2 * i + 1]);
*((_BYTE *)v23 + i) = strtol(sa, 0LL, 16);
}
}
v20 = strlen(v17);
BYTE4(v22) = ((v20 - 1) >> 1) + ((v20 - 1) & 1);
free(v16);
if ( !(unsigned int)can_isok() && (unsigned int)can_init(can_iface_ptr) )
{
puts("Il y a eu un erreur a l'init du CAN");
exit(1);
}
can_send(v22, v23[0]);
parseXML(a3, v22, v23[0]);
}
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; // rbp
char *v15; // rax
char *v16; // r15
char *v17; // r12
char *v18; // rax
__int64 i; // rbp
size_t 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) )
{
v14 = strdup(s);
strtok(v14, "-\n");
v15 = strtok(0LL, "-\n");
sprintf(fileRep, "/home/pi/xml/%s", v15);
printf(aR, fileRep);
func2();
free(v14);
if ( (unsigned int)can_isok() == 1 )
((void (*)(void))can_close)();
if ( (unsigned int)can_init(can_iface_ptr) )
{
puts("Il y a eu un erreur a l'init du CAN");
exit(1);
}
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 )
{
v16 = strdup(s);
v17 = strtok(v16, " #\n");
if ( v17 )
{
v18 = strtok(0LL, " #\n");
LODWORD(v22) = strtol(v18, 0LL, 16);
v17 = strtok(0LL, " #\n");
for ( i = 0LL; strlen(v17) > 2 * i; ++i )
{
sprintf(sa, "%c%c", (unsigned int)v17[2 * i], (unsigned int)v17[2 * i + 1]);
*((_BYTE *)v23 + i) = strtol(sa, 0LL, 16);
}
}
v20 = strlen(v17);
BYTE4(v22) = ((v20 - 1) >> 1) + ((v20 - 1) & 1);
free(v16);
if ( !(unsigned int)can_isok() && (unsigned int)can_init(can_iface_ptr) )
{
puts("Il y a eu un erreur a l'init du CAN");
exit(1);
}
can_send(v22, v23[0]);
func6(a3, v22, v23[0]);
}
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, __int16 a2)
{
int v3; // edi
int result; // eax
struct sockaddr v5; // [rsp+0h] [rbp-38h] BYREF
unsigned int optval[7]; // [rsp+1Ch] [rbp-1Ch] 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[0] = 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[0]);
v5.sa_family = 2;
*(_DWORD *)&v5.sa_data[2] = _bswap_32(0);
*(_WORD *)v5.sa_data = _bswap_16(a2);
if ( bind(*((_DWORD *)arg + 10), &v5, 0x10u) < 0 )
{
printf("%s @ %d : Error on bind\n", "CServerTcpIP_Start", 447LL);
LABEL_12:
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_12;
}
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_12;
}
return result;
}

canonical_decompiled_code:
int __fastcall func3(void *arg, __int16 a2)
{
int v3; // edi
int result; // eax
struct sockaddr v5; // [rsp+0h] [rbp-38h] BYREF
unsigned int optval[7]; // [rsp+1Ch] [rbp-1Ch] 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[0] = 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[0]);
v5.sa_family = 2;
*(_DWORD *)&v5.sa_data[2] = func2(0);
*(_WORD *)v5.sa_data = func1(a2);
if ( bind(*((_DWORD *)arg + 10), &v5, 0x10u) < 0 )
{
printf("%s @ %d : Error on bind\n", "CServerTcpIP_Start", 447LL);
LABEL_12:
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_12;
}
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_12;
}
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 *