decompiled_code:
char *get_actual_time_gmt()
{
struct tm *v0; // rax
time_t timer; // [rsp+8h] [rbp-50h] BYREF
struct tm tp; // [rsp+10h] [rbp-48h] BYREF

timer = time(0LL);
v0 = localtime(&timer);
*(__m128i *)&tp.tm_sec = _mm_loadu_si128((const __m128i *)v0);
*(__m128i *)&tp.tm_mon = _mm_loadu_si128((const __m128i *)&v0->tm_mon);
*(__m128i *)&tp.tm_isdst = _mm_loadu_si128((const __m128i *)&v0->tm_isdst);
tp.tm_zone = v0->tm_zone;
strftime(s_0, 0x1EuLL, "%a, %d %b %Y %H:%M:%S GMT", &tp);
return s_0;
}

canonical_decompiled_code:
char *func0()
{
struct tm *v0; // rax
time_t timer; // [rsp+8h] [rbp-50h] BYREF
struct tm tp; // [rsp+10h] [rbp-48h] BYREF

timer = time(0LL);
v0 = localtime(&timer);
*(__m128i *)&tp.tm_sec = _mm_loadu_si128((const __m128i *)v0);
*(__m128i *)&tp.tm_mon = _mm_loadu_si128((const __m128i *)&v0->tm_mon);
*(__m128i *)&tp.tm_isdst = _mm_loadu_si128((const __m128i *)&v0->tm_isdst);
tp.tm_zone = v0->tm_zone;
strftime(s_0, 0x1EuLL, "%a, %d %b %Y %H:%M:%S GMT", &tp);
return s_0;
}

original_code:
char* get_actual_time_gmt( void ) {
    static char s[ 30 ];
    struct tm tim;
    time_t now;
    now = time( ((void *)0) );
    tim = *( localtime( &now ) );
    strftime( s, 30, "%a, %d %b %Y %H:%M:%S GMT", &tim );
    return ( ( char* )&s );
}

canonical_original_code:
char *get_actual_time_gmt() {
    static char s[30];
    struct tm tim;
    long now;
    now = time( ((void *)0) );
    tim = *( localtime( &now ) );
    strftime( s, 30, "%a, %d %b %Y %H:%M:%S GMT", &tim );
    return ( ( char * )&s );
}

variable_types:
s
char [30]

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; }

variable_types: now long


strdelbslash

repo: OrionExplorer/battery-http-server

decompiled_code:
char *__fastcall strdelbslash(char *haystack)
{
char *result; // rax

while ( 1 )
{
result = strstr(haystack, "//");
if ( !result )
break;
strcpy(result + 1, result + 2);
}
return result;
}

canonical_decompiled_code:
char *__fastcall func0(char *haystack)
{
char *result; // rax

while ( 1 )
{
result = strstr(haystack, "//");
if ( !result )
break;
strcpy(result + 1, result + 2);
}
return result;
}

original_code:
void strdelbslash( char *s1 ) {
    char *c1;
    while( ( c1 = strstr( s1, "//" ) ) ) {
        strcpy( c1 + 1, c1 + 2 );
    }
}

canonical_original_code:
void strdelbslash(char *s1) {
    char *c1;
    while( ( c1 = strstr( s1, "//" ) ) ) {
        strcpy( c1 + 1, c1 + 2 );
    }
}

return_type: void


strdelstr

decompiled_code:
char *__fastcall strdelstr(char *haystack, char *s)
{
int v2; // er13
char *result; // rax
char *v4; // rbx
size_t v5; // rax

v2 = strlen(s);
result = strstr(haystack, s);
if ( result )
{
v4 = result;
do
{
v5 = strlen(&v4[v2]);
memmove(v4, &v4[v2], v5 + 1);
result = strstr(v4, s);
v4 = result;
}
while ( result );
}
return result;
}

canonical_decompiled_code:
char *__fastcall func1(char *haystack, char *s)
{
int v2; // er13
char *result; // rax
char *v4; // rbx
size_t v5; // rax

v2 = strlen(s);
result = strstr(haystack, s);
if ( result )
{
v4 = result;
do
{
v5 = strlen(&v4[v2]);
memmove(v4, &v4[v2], v5 + 1);
result = strstr(v4, s);
v4 = result;
}
while ( result );
}
return result;
}

original_code:
void strdelstr( char *s1, const char* s2 )
{
    int t_len = strlen( s2 );
    if( !strstr( s1, s2 ) ) {
        return;
    }
    while( ( s1 = strstr( s1, s2 ) ) ) {
        memmove( s1, s1 + t_len, 1 + strlen( s1 + t_len ) );
    }
}

canonical_original_code:
void strdelstr(char *s1, char *s2)
{
    int t_len = strlen( s2 );
    if( !strstr( s1, s2 ) ) {
        return;
    }
    while( ( s1 = strstr( s1, s2 ) ) ) {
        memmove( s1, s1 + t_len, 1 + strlen( s1 + t_len ) );
    }
}


strrepchar

decompiled_code:
size_t __fastcall strrepchar(const char *a1, char a2, char a3)
{
size_t result; // rax
unsigned int v5; // ecx
__int64 v6; // rdx

result = strlen(a1);
if ( (int)result > 1 )
{
v5 = result;
result = (size_t)&a1[(int)result];
v6 = result - 1 - v5;
do
{
if ( *(_BYTE *)result == a2 )
*(_BYTE *)result = a3;
--result;
}
while ( result != v6 );
}
return result;
}

canonical_decompiled_code:
size_t __fastcall func2(const char *a1, char a2, char a3)
{
size_t result; // rax
unsigned int v5; // ecx
__int64 v6; // rdx

result = strlen(a1);
if ( (int)result > 1 )
{
v5 = result;
result = (size_t)&a1[(int)result];
v6 = result - 1 - v5;
do
{
if ( *(_BYTE *)result == a2 )
*(_BYTE *)result = a3;
--result;
}
while ( result != v6 );
}
return result;
}

original_code:
void strrepchar( char *s1, char c1, char c2 ) {
    int len = strlen( s1 );
    if( len <= 1 ) {
        return;
    }
    while( len > -1 ) {
        if( s1[ len ] == c1 ) {
            s1[ len ] = c2;
        }
        len--;
    }
}

canonical_original_code:
void strrepchar(char *s1, char c1, char c2) {
    int len = strlen( s1 );
    if( len <= 1 ) {
        return;
    }
    while( len > -1 ) {
        if( s1[ len ] == c1 ) {
            s1[ len ] = c2;
        }
        len--;
    }
}

variable_types: len int


strpos

decompiled_code:
__int64 __fastcall strpos(const char *a1, const char *a2)
{
char *v2; // rax
__int64 result; // rax

v2 = strstr(a1, a2);
if ( v2 )
result = (unsigned int)((_DWORD)v2 - (_DWORD)a1);
else
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(const char *a1, const char *a2)
{
char *v2; // rax
__int64 result; // rax

v2 = strstr(a1, a2);
if ( v2 )
result = (unsigned int)((_DWORD)v2 - (_DWORD)a1);
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int strpos( const char *s1, const char *s2 ) {
    char *p = ( char* )strstr( s1, s2 );
    if( p ) {
        return p - s1;
    }
    return -1;
}

canonical_original_code:
int strpos(char *s1, char *s2) {
    char *p = ( char* )strstr( s1, s2 );
    if( p ) {
        return p - s1;
    }
    return -1;
}

variable_types:
p
char *

return_type: int


decompiled_code:
void __fastcall mem_allocated(__int64 a1, __int64 a2)
{
if ( !a1 )
{
LOG_print("Error: malloc( %d ).\n", a2);
printf("Error: malloc( %d ).\n", (unsigned int)a2);
exit(1);
}
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1, __int64 a2)
{
if ( !a1 )
{
LOG_print("Error: malloc( %d ).\n", a2);
printf("Error: malloc( %d ).\n", (unsigned int)a2);
exit(1);
}
}

original_code:
void mem_allocated( char *ptr, int n ) {
    if( !ptr ) {
        LOG_print( "Error: malloc( %d ).\n", n );
        printf( "Error: malloc( %d ).\n", n );
        exit( 1 );
    }
}

canonical_original_code:
void mem_allocated(char *ptr, int n) {
    if( !ptr ) {
        LOG_print( "Error: malloc( %d ).\n", n );
        printf( "Error: malloc( %d ).\n", n );
        exit( 1 );
    }
}

variable_types:
ptr
char *

variable_types: n int


repo: OrionExplorer/c-server-core

decompiled_code:
void app_terminate()
{
printf("\rService is being closed...");
SOCKET_stop();
puts("ok.");
}

canonical_decompiled_code:
void func0()
{
printf("\rService is being closed...");
SOCKET_stop();
puts("ok.");
}

original_code:
void app_terminate( void ) {
 printf( "\rService is being closed..." );
 SOCKET_stop();
 printf( "ok.\n" );
 return;
}

canonical_original_code:
void app_terminate() {
 printf( "\rService is being closed..." );
 SOCKET_stop();
 printf( "ok.\n" );
 return;
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_sysv_signal(2, (__sighandler_t)app_terminate);
_sysv_signal(13, (__sighandler_t)((char *)app_terminate + 1));
_sysv_signal(6, (__sighandler_t)app_terminate);
_sysv_signal(15, (__sighandler_t)app_terminate);
puts("c-server-core");
SOCKET_main();
return 0;
}

original_code:
int main( void ) {
 signal( 2, ( __sighandler_t )&app_terminate );
  signal( 13, ((__sighandler_t) 1) );
 signal( 6, ( __sighandler_t )&app_terminate );
 signal( 15, ( __sighandler_t )&app_terminate );
 printf( "c-server-core\n");
 SOCKET_main();
 return 0;
}

canonical_original_code:
int main() {
 signal( 2, ( __sighandler_t )&app_terminate );
  signal( 13, ((void (*)(int)) 1) );
 signal( 6, ( __sighandler_t )&app_terminate );
 signal( 15, ( __sighandler_t )&app_terminate );
 printf( "c-server-core\n");
 SOCKET_main();
 return 0;
}


decompiled_code:
void __fastcall SOCKET_modify_clients_count(int a1)
{
if ( a1 <= 0 )
{
if ( http_conn_count - a1 >= 0 )
--http_conn_count;
}
else
{
++http_conn_count;
}
}

canonical_decompiled_code:
void __fastcall func2(int a1)
{
if ( a1 <= 0 )
{
if ( http_conn_count - a1 >= 0 )
--http_conn_count;
}
else
{
++http_conn_count;
}
}

original_code:
void SOCKET_modify_clients_count( int mod ) {
 if( mod > 0 ) {
  http_conn_count++;
 } else {
  if( (http_conn_count - mod) >= 0 ) {
   http_conn_count--;
  }
 }
}

canonical_original_code:
void SOCKET_modify_clients_count(int mod) {
 if( mod > 0 ) {
  http_conn_count++;
 } else {
  if( (http_conn_count - mod) >= 0 ) {
   http_conn_count--;
  }
 }
}

variable_types: mod int


decompiled_code:
void __fastcall SOCKET_close(int fd)
{
*((_QWORD *)&master + fd / 64) &= __ROL8__(-2LL, fd % 64);
shutdown(fd, 2);
close(fd);
SOCKET_modify_clients_count(-1);
}

canonical_decompiled_code:
void __fastcall func3(int fd)
{
*((_QWORD *)&master + fd / 64) &= __ROL8__(-2LL, fd % 64);
shutdown(fd, 2);
close(fd);
func2(-1);
}

original_code:
void SOCKET_close( int socket_descriptor ) {
 ((void) (((&master)->__fds_bits)[((socket_descriptor) / (8 * (int) sizeof (__fd_mask)))] &= ~((__fd_mask) (1UL << ((socket_descriptor) % (8 * (int) sizeof (__fd_mask)))))));
 shutdown( socket_descriptor, SHUT_RDWR );
 close( socket_descriptor );
 SOCKET_modify_clients_count( -1 );
}

canonical_original_code:
void SOCKET_close(int socket_descriptor) {
 ((void) (((&master)->__fds_bits)[((socket_descriptor) / (8 * (int) sizeof (__fd_mask)))] &= ~((__fd_mask) (1UL << ((socket_descriptor) % (8 * (int) sizeof (__fd_mask)))))));
 shutdown( socket_descriptor, SHUT_RDWR );
 close( socket_descriptor );
 SOCKET_modify_clients_count( -1 );
}


decompiled_code:
int SOCKET_stop()
{
close(*(&communication_session_ + 4));
return close(socket_server);
}

canonical_decompiled_code:
int func4()
{
close(*(&communication_session_ + 4));
return close(socket_server);
}

original_code:
void SOCKET_stop( void ) {
 close( communication_session_.socket );
 close( socket_server );
}

canonical_original_code:
void SOCKET_stop() {
 close( communication_session_.socket );
 close( socket_server );
}


decompiled_code:
__int16 SOCKET_initialization()
{
__int16 result; // ax

printf("Initializing...");
socket_server = socket(2, 1, 6);
if ( socket_server == -1 )
{
puts("error creating socket.");
SOCKET_stop();
exit(1);
}
active_port = 1212;
*(_QWORD *)&server_address.sa_data[6] = 0LL;
*(_DWORD *)&server_address.sa_data[2] = _bswap_32(0);
server_address.sa_family = 2;
result = _bswap_16(1212);
*(_WORD *)server_address.sa_data = result;
return result;
}

canonical_decompiled_code:
__int16 func5()
{
__int16 result; // ax

printf("Initializing...");
socket_server = socket(2, 1, 6);
if ( socket_server == -1 )
{
puts("error creating socket.");
func4();
exit(1);
}
active_port = 1212;
*(_QWORD *)&server_address.sa_data[6] = 0LL;
*(_DWORD *)&server_address.sa_data[2] = func0(0);
server_address.sa_family = 2;
result = func1(1212);
*(_WORD *)server_address.sa_data = result;
return result;
}

original_code:
static void SOCKET_initialization( void ) {
 printf("Initializing...");
 socket_server = socket( 2, SOCK_STREAM, IPPROTO_TCP );
 if ( socket_server == ( -1 ) ) {
  printf( "error creating socket.\n" );
  SOCKET_stop();
  exit( 1 );
 }
 active_port = 1212;
 memset( &server_address, 0, sizeof( server_address ) );
 server_address.sin_addr.s_addr = htonl( ((in_addr_t) 0x00000000) );
 server_address.sin_family = 2;
 server_address.sin_port = htons( ( unsigned short )active_port );
}

canonical_original_code:
static void SOCKET_initialization() {
 printf("Initializing...");
 socket_server = socket( 2, SOCK_STREAM, IPPROTO_TCP );
 if ( socket_server == ( -1 ) ) {
  printf( "error creating socket.\n" );
  SOCKET_stop();
  exit( 1 );
 }
 active_port = 1212;
 memset( &server_address, 0, sizeof( server_address ) );
 server_address.sin_addr.s_addr = htonl( ((unsigned int) 0x00000000) );
 server_address.sin_family = 2;
 server_address.sin_port = htons( ( unsigned short )active_port );
}


decompiled_code:
int SOCKET_prepare()
{
int *v1; // rax
int *v2; // rax
int *v3; // rax
int *v4; // rax
int *v5; // rax
int *v6; // rax
int *v7; // rax
__int64 v8[2]; // [rsp+0h] [rbp-28h] BYREF
int optval; // [rsp+14h] [rbp-14h] BYREF
__int64 v10; // [rsp+18h] [rbp-10h] BYREF

v10 = 0LL;
optval = 1;
v8[0] = 0LL;
v8[1] = 20000LL;
memset(&master, 0, 0x80uLL);
memset(&read_fds, 0, sizeof(read_fds));
setuid(0);
setgid(0);
if ( setsockopt(socket_server, 1, 2, &optval, 4u) == -1 )
{
v1 = _errno_location();
printf("setsockopt( SO_REUSEADDR ) error: %d.\n", (unsigned int)*v1);
}
if ( bind(socket_server, &server_address, 0x10u) == -1 )
{
v2 = _errno_location();
printf("bind error: %d.\n", (unsigned int)*v2);
SOCKET_stop();
exit(1);
}
if ( setsockopt(socket_server, 1, 20, v8, 0x10u) == -1 )
{
v3 = _errno_location();
printf("setsockopt( SO_RCVTIMEO ) error: %d.\n", (unsigned int)*v3);
}
if ( setsockopt(socket_server, 1, 21, v8, 0x10u) == -1 )
{
v4 = _errno_location();
printf("setsockopt( SO_SNDTIMEO ) error: %d.\n", (unsigned int)*v4);
}
if ( setsockopt(socket_server, 6, 1, &optval, 4u) == -1 )
{
v5 = _errno_location();
printf("setsockopt( TCP_NODELAY ) error: %d.\n", (unsigned int)*v5);
}
if ( fcntl(socket_server, 4, &v10) == -1 )
{
v6 = _errno_location();
printf("ioctlsocket error: %d.\n", (unsigned int)*v6);
SOCKET_stop();
exit(1);
}
if ( listen(socket_server, 1024) == -1 )
{
v7 = _errno_location();
printf("listen error: %d.\n", (unsigned int)*v7);
SOCKET_stop();
exit(1);
}
return puts("ok.");
}

canonical_decompiled_code:
int func6()
{
int *v1; // rax
int *v2; // rax
int *v3; // rax
int *v4; // rax
int *v5; // rax
int *v6; // rax
int *v7; // rax
__int64 v8[2]; // [rsp+0h] [rbp-28h] BYREF
int optval; // [rsp+14h] [rbp-14h] BYREF
__int64 v10; // [rsp+18h] [rbp-10h] BYREF

v10 = 0LL;
optval = 1;
v8[0] = 0LL;
v8[1] = 20000LL;
memset(&master, 0, 0x80uLL);
memset(&read_fds, 0, sizeof(read_fds));
setuid(0);
setgid(0);
if ( setsockopt(socket_server, 1, 2, &optval, 4u) == -1 )
{
v1 = _errno_location();
printf("setsockopt( SO_REUSEADDR ) error: %d.\n", (unsigned int)*v1);
}
if ( bind(socket_server, &server_address, 0x10u) == -1 )
{
v2 = _errno_location();
printf("bind error: %d.\n", (unsigned int)*v2);
func4();
exit(1);
}
if ( setsockopt(socket_server, 1, 20, v8, 0x10u) == -1 )
{
v3 = _errno_location();
printf("setsockopt( SO_RCVTIMEO ) error: %d.\n", (unsigned int)*v3);
}
if ( setsockopt(socket_server, 1, 21, v8, 0x10u) == -1 )
{
v4 = _errno_location();
printf("setsockopt( SO_SNDTIMEO ) error: %d.\n", (unsigned int)*v4);
}
if ( setsockopt(socket_server, 6, 1, &optval, 4u) == -1 )
{
v5 = _errno_location();
printf("setsockopt( TCP_NODELAY ) error: %d.\n", (unsigned int)*v5);
}
if ( fcntl(socket_server, 4, &v10) == -1 )
{
v6 = _errno_location();
printf("ioctlsocket error: %d.\n", (unsigned int)*v6);
func4();
exit(1);
}
if ( listen(socket_server, 1024) == -1 )
{
v7 = _errno_location();
printf("listen error: %d.\n", (unsigned int)*v7);
func4();
exit(1);
}
return puts("ok.");
}

original_code:
static void SOCKET_prepare( void ) {
 unsigned long b = 0;
 int i = 1;
 int wsa_result = 0;
 struct timeval tv = {0, 0};
 tv.tv_sec = 0;
 tv.tv_usec = 20000;
 do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&master)->__fds_bits)[0]) : "memory"); } while (0);
 do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&read_fds)->__fds_bits)[0]) : "memory"); } while (0);
 setuid( 0 );
 setgid( 0 );
 if( setsockopt( socket_server, 1, 2, &i, sizeof( int ) ) == ( -1 ) ) {
  wsa_result = (*__errno_location ());
  printf( "setsockopt( SO_REUSEADDR ) error: %d.\n", wsa_result );
 }
 if ( bind( socket_server, ( struct sockaddr* )&server_address, sizeof( server_address ) ) == ( -1 ) ) {
  wsa_result = (*__errno_location ());
  printf( "bind error: %d.\n", wsa_result );
  SOCKET_stop();
  exit( 1 );
 }
 if( setsockopt( socket_server, 1, 20, ( char* )&tv, sizeof( struct timeval ) ) == ( -1 ) ) {
  wsa_result = (*__errno_location ());
  printf( "setsockopt( SO_RCVTIMEO ) error: %d.\n", wsa_result );
 }
 if( setsockopt( socket_server, 1, 21, ( char* )&tv, sizeof( struct timeval ) ) == ( -1 ) ) {
  wsa_result = (*__errno_location ());
  printf( "setsockopt( SO_SNDTIMEO ) error: %d.\n", wsa_result );
 }
 if( setsockopt( socket_server, IPPROTO_TCP, 1, ( char * )&i, sizeof( i ) ) == ( -1 ) ) {
  wsa_result = (*__errno_location ());
  printf( "setsockopt( TCP_NODELAY ) error: %d.\n", wsa_result );
 }
 if( fcntl( socket_server, 4, &b ) == ( -1 ) ) {
  wsa_result = (*__errno_location ());
  printf( "ioctlsocket error: %d.\n", wsa_result );
  SOCKET_stop();
  exit( 1 );
 }
 if( listen( socket_server, 1024 ) == ( -1 ) ) {
  wsa_result = (*__errno_location ());
  printf( "listen error: %d.\n", wsa_result );
  SOCKET_stop();
  exit( 1 );
 }
 printf( "ok.\n" );
}

canonical_original_code:
static void SOCKET_prepare() {
 unsigned long b = 0;
 int i = 1;
 int wsa_result = 0;
 struct timeval tv = {0, 0};
 tv.tv_sec = 0;
 tv.tv_usec = 20000;
 do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&master)->__fds_bits)[0]) : "memory"); } while (0);
 do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&read_fds)->__fds_bits)[0]) : "memory"); } while (0);
 setuid( 0 );
 setgid( 0 );
 if( setsockopt( socket_server, 1, 2, &i, sizeof( int ) ) == ( -1 ) ) {
  wsa_result = (*__errno_location ());
  printf( "setsockopt( SO_REUSEADDR ) error: %d.\n", wsa_result );
 }
 if ( bind( socket_server, ( struct sockaddr * )&server_address, sizeof( server_address ) ) == ( -1 ) ) {
  wsa_result = (*__errno_location ());
  printf( "bind error: %d.\n", wsa_result );
  SOCKET_stop();
  exit( 1 );
 }
 if( setsockopt( socket_server, 1, 20, ( char * )&tv, sizeof( struct timeval ) ) == ( -1 ) ) {
  wsa_result = (*__errno_location ());
  printf( "setsockopt( SO_RCVTIMEO ) error: %d.\n", wsa_result );
 }
 if( setsockopt( socket_server, 1, 21, ( char * )&tv, sizeof( struct timeval ) ) == ( -1 ) ) {
  wsa_result = (*__errno_location ());
  printf( "setsockopt( SO_SNDTIMEO ) error: %d.\n", wsa_result );
 }
 if( setsockopt( socket_server, IPPROTO_TCP, 1, ( char * )&i, sizeof( i ) ) == ( -1 ) ) {
  wsa_result = (*__errno_location ());
  printf( "setsockopt( TCP_NODELAY ) error: %d.\n", wsa_result );
 }
 if( fcntl( socket_server, 4, &b ) == ( -1 ) ) {
  wsa_result = (*__errno_location ());
  printf( "ioctlsocket error: %d.\n", wsa_result );
  SOCKET_stop();
  exit( 1 );
 }
 if( listen( socket_server, 1024 ) == ( -1 ) ) {
  wsa_result = (*__errno_location ());
  printf( "listen error: %d.\n", wsa_result );
  SOCKET_stop();
  exit( 1 );
 }
 printf( "ok.\n" );
}

variable_types:
b
unsigned long

variable_types: i int

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

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


original_code:
void SOCKET_release( COMMUNICATION_SESSION *communication_session ) {
 communication_session->socket_descriptor = -1;
 communication_session->data_length = -1;
 communication_session->keep_alive = -1;
}

canonical_original_code:
void SOCKET_release(struct COMMUNICATION_SESSION *communication_session) {
 communication_session->socket_descriptor = -1;
 communication_session->data_length = -1;
 communication_session->keep_alive = -1;
}

variable_types: struct COMMUNICATION_SESSION { 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]; } address; int socket; struct fd_set { long __fds_bits[-1]; } socket_data; unsigned int data_length; int socket_descriptor; char *content[65535]; short keep_alive; } *

user_defined_types: struct COMMUNICATION_SESSION { struct sockaddr_in address; int socket; struct fd_set socket_data; unsigned int data_length; int socket_descriptor; char *content[65535]; short keep_alive; }

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


decompiled_code:
void __fastcall SOCKET_disconnect_client(__int64 a1)
{
int v1; // eax

v1 = *(_DWORD *)(a1 + 156);
if ( v1 == -1 )
SOCKET_release(a1);
else
SOCKET_close(v1);
}

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

v1 = *(_DWORD *)(a1 + 156);
if ( v1 == -1 )
func7(a1);
else
func3(v1);
}

original_code:
void SOCKET_disconnect_client( COMMUNICATION_SESSION *communication_session ) {
 if( communication_session->socket_descriptor != ( -1 ) ) {
  SOCKET_close( communication_session->socket_descriptor );
 } else {
  SOCKET_release( communication_session );
 }
}

canonical_original_code:
void SOCKET_disconnect_client(struct COMMUNICATION_SESSION *communication_session) {
 if( communication_session->socket_descriptor != ( -1 ) ) {
  SOCKET_close( communication_session->socket_descriptor );
 } else {
  SOCKET_release( communication_session );
 }
}


decompiled_code:
void __fastcall SOCKET_send(__int64 a1, int *a2, const char *a3, int a4)
{
char *v6; // rbp
int v7; // eax

v6 = (char *)calloc(0xFFFFuLL, 1uLL);
if ( a4 == -1 )
a4 = strlen(a3);
strncpy(v6, a3, 0xFFFFuLL);
v7 = send(*a2, v6, a4, 0);
*(_DWORD *)(a1 + 152) = v7;
if ( !v7 )
SOCKET_disconnect_client(a1);
free(v6);
}

canonical_decompiled_code:
void __fastcall func9(__int64 a1, int *a2, const char *a3, int a4)
{
char *v6; // rbp
int v7; // eax

v6 = (char *)calloc(0xFFFFuLL, 1uLL);
if ( a4 == -1 )
a4 = strlen(a3);
strncpy(v6, a3, 0xFFFFuLL);
v7 = send(*a2, v6, a4, 0);
*(_DWORD *)(a1 + 152) = v7;
if ( !v7 )
func8(a1);
free(v6);
}

original_code:
void SOCKET_send( COMMUNICATION_SESSION *communication_session, CONNECTED_CLIENT *client, const char *data, unsigned int data_size ) {
 int _data_size = data_size;
 char *data_to_send = ( char * )calloc( 65535, sizeof( char ) );
 if( _data_size == -1 ) {
  _data_size = strlen( data );
 }
 strncpy( data_to_send, data, 65535 );
 if( ( communication_session->data_length = send( client->socket_descriptor, data_to_send, _data_size, 0 ) ) <= 0 ) {
  SOCKET_disconnect_client( communication_session );
 }
 free( data_to_send );
 data_to_send = ((void *)0);
}

canonical_original_code:
void SOCKET_send(struct COMMUNICATION_SESSION *communication_session, struct CONNECTED_CLIENT *client, char *data, unsigned int data_size) {
 int _data_size = data_size;
 char *data_to_send = ( char * )calloc( 65535, sizeof( char ) );
 if( _data_size == -1 ) {
  _data_size = strlen( data );
 }
 strncpy( data_to_send, data, 65535 );
 if( ( communication_session->data_length = send( client->socket_descriptor, data_to_send, _data_size, 0 ) ) <= 0 ) {
  SOCKET_disconnect_client( communication_session );
 }
 free( data_to_send );
 data_to_send = ((void *)0);
}

variable_types: struct CONNECTED_CLIENT { int socket_descriptor; short connected; } *

variable_types:
data
char *


decompiled_code:
char *__fastcall SOCKET_get_remote_ip(const struct sockaddr *a1)
{
*(_QWORD *)ip_addr_0 = 0LL;
qword_829E8 = 0LL;
getnameinfo(a1, 0x10u, ip_addr_0, 0x10u, 0LL, 0, 1);
return ip_addr_0;
}

canonical_decompiled_code:
char *__fastcall func10(const struct sockaddr *a1)
{
*(_QWORD *)ip_addr_0 = 0LL;
qword_829E8 = 0LL;
getnameinfo(a1, 0x10u, ip_addr_0, 0x10u, 0LL, 0, 1);
return ip_addr_0;
}

original_code:
char* SOCKET_get_remote_ip( COMMUNICATION_SESSION *communication_session ) {
 static char ip_addr[ 16 ];
 memset( ip_addr, '\0', 16 );
 getnameinfo( ( struct sockaddr * )&communication_session->address, sizeof( communication_session->address ), ip_addr, sizeof( ip_addr ), ((void *)0), 0, 1 );
 return ( ( char* )&ip_addr );
}

canonical_original_code:
char *SOCKET_get_remote_ip(struct COMMUNICATION_SESSION *communication_session) {
 static char ip_addr[16];
 memset( ip_addr, '\0', 16 );
 getnameinfo( ( struct sockaddr * )&communication_session->address, sizeof( communication_session->address ), ip_addr, sizeof( ip_addr ), ((void *)0), 0, 1 );
 return ( ( char * )&ip_addr );
}

return_type: char *


decompiled_code:
int __fastcall SOCKET_register_client(unsigned int a1)
{
__int64 v1; // rax

v1 = 0LL;
while ( connected_clients[2 * v1] )
{
if ( ++v1 == 1024 )
return v1;
}
connected_clients[2 * (int)v1] = a1;
LOWORD(connected_clients[2 * (int)v1 + 1]) = 1;
LODWORD(v1) = printf("Client connected with descriptor %d.\n", a1);
return v1;
}

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

v1 = 0LL;
while ( connected_clients[2 * v1] )
{
if ( ++v1 == 1024 )
return v1;
}
connected_clients[2 * (int)v1] = a1;
LOWORD(connected_clients[2 * (int)v1 + 1]) = 1;
LODWORD(v1) = printf("Client connected with descriptor %d.\n", a1);
return v1;
}

original_code:
void SOCKET_register_client( int socket_descriptor ) {
 int i;
 for( i = 0; i < 1024; i++ ){
  if( connected_clients[ i ].socket_descriptor == 0 ) {
   connected_clients[ i ].socket_descriptor = socket_descriptor;
   connected_clients[ i ].connected = 1;
   printf("Client connected with descriptor %d.\n", socket_descriptor );
   return;
  }
 }
}

canonical_original_code:
void SOCKET_register_client(int socket_descriptor) {
 int i;
 for( i = 0; i < 1024; i++ ){
  if( connected_clients[ i ].socket_descriptor == 0 ) {
   connected_clients[ i ].socket_descriptor = socket_descriptor;
   connected_clients[ i ].connected = 1;
   printf("Client connected with descriptor %d.\n", socket_descriptor );
   return;
  }
 }
}


decompiled_code:
int __fastcall SOCKET_unregister_client(unsigned int a1)
{
__int64 v1; // rax

v1 = 0LL;
while ( connected_clients[2 * v1] != a1 )
{
if ( ++v1 == 1024 )
return v1;
}
connected_clients[2 * (int)v1] = 0;
LOWORD(connected_clients[2 * (int)v1 + 1]) = 0;
LODWORD(v1) = printf("Client disconnected: %d.\n", a1);
return v1;
}

canonical_decompiled_code:
int __fastcall func12(unsigned int a1)
{
__int64 v1; // rax

v1 = 0LL;
while ( connected_clients[2 * v1] != a1 )
{
if ( ++v1 == 1024 )
return v1;
}
connected_clients[2 * (int)v1] = 0;
LOWORD(connected_clients[2 * (int)v1 + 1]) = 0;
LODWORD(v1) = printf("Client disconnected: %d.\n", a1);
return v1;
}

original_code:
void SOCKET_unregister_client( int socket_descriptor ) {
 int i;
 for( i = 0; i < 1024; i++ ){
  if( connected_clients[ i ].socket_descriptor == socket_descriptor ) {
   connected_clients[ i ].socket_descriptor = 0;
   connected_clients[ i ].connected = 0;
   printf("Client disconnected: %d.\n", socket_descriptor );
   break;
  }
 }
}

canonical_original_code:
void SOCKET_unregister_client(int socket_descriptor) {
 int i;
 for( i = 0; i < 1024; i++ ){
  if( connected_clients[ i ].socket_descriptor == socket_descriptor ) {
   connected_clients[ i ].socket_descriptor = 0;
   connected_clients[ i ].connected = 0;
   printf("Client disconnected: %d.\n", socket_descriptor );
   break;
  }
 }
}


decompiled_code:
void __fastcall SOCKET_process(int fd)
{
int *v1; // rbp
socklen_t v2; // eax

v1 = _errno_location();
*v1 = 0;
*(&communication_session_ + 39) = fd;
memset((void *)(unsigned int)((_DWORD)&communication_session_ + 160), 0, 0xFFFFuLL);
v2 = recv(fd, (void *)(unsigned int)((_DWORD)&communication_session_ + 160), 0xFFFFuLL, 0);
*(&communication_session_ + 38) = v2;
if ( *v1 <= 1 && v2 )
{
printf("Received packet with size %ld.\n", v2);
}
else
{
SOCKET_unregister_client(fd);
SOCKET_close(fd);
}
}

canonical_decompiled_code:
void __fastcall func13(int fd)
{
int *v1; // rbp
socklen_t v2; // eax

v1 = _errno_location();
*v1 = 0;
*(&communication_session_ + 39) = fd;
memset((void *)(unsigned int)((_DWORD)&communication_session_ + 160), 0, 0xFFFFuLL);
v2 = recv(fd, (void *)(unsigned int)((_DWORD)&communication_session_ + 160), 0xFFFFuLL, 0);
*(&communication_session_ + 38) = v2;
if ( *v1 <= 1 && v2 )
{
printf("Received packet with size %ld.\n", v2);
}
else
{
func12(fd);
func3(fd);
}
}

original_code:
static void SOCKET_process( int socket_fd ) {
 CONNECTED_CLIENT *client = SOCKET_find_client( socket_fd );
 extern int (*__errno_location ());
 (*__errno_location ()) = 0;
 communication_session_.socket_descriptor = socket_fd;
 memset( communication_session_.content, '\0', 65535 );
 communication_session_.data_length = recv( ( int )socket_fd, communication_session_.content, 65535, 0 );
 if( (*__errno_location ()) > 1) {
  SOCKET_unregister_client( socket_fd );
  SOCKET_close( socket_fd );
 } else {
  if ( communication_session_.data_length <= 0 ) {
   SOCKET_unregister_client( socket_fd );
   SOCKET_close( socket_fd );
  } else {
   printf( "Received packet with size %ld.\n", communication_session_.data_length );
  }
 }
}

canonical_original_code:
static void SOCKET_process(int socket_fd) {
 struct CONNECTED_CLIENT *client = SOCKET_find_client( socket_fd );
 extern int *__errno_location();
 (*__errno_location ()) = 0;
 communication_session_.socket_descriptor = socket_fd;
 memset( communication_session_.content, '\0', 65535 );
 communication_session_.data_length = recv( ( int )socket_fd, communication_session_.content, 65535, 0 );
 if( (*__errno_location ()) > 1) {
  SOCKET_unregister_client( socket_fd );
  SOCKET_close( socket_fd );
 } else {
  if ( communication_session_.data_length <= 0 ) {
   SOCKET_unregister_client( socket_fd );
   SOCKET_close( socket_fd );
  } else {
   printf( "Received packet with size %ld.\n", communication_session_.data_length );
  }
 }
}

user_defined_types: struct CONNECTED_CLIENT { int socket_descriptor; short connected; }


decompiled_code:
void __noreturn SOCKET_run()
{
int v0; // edx
int i; // ebx
int v2; // eax
int v3; // edx
struct timeval v4; // [rsp+0h] [rbp-28h] BYREF

v0 = socket_server;
*((_QWORD *)&master + socket_server / 64) |= 1LL << (socket_server % 64);
v4.tv_sec = 1LL;
v4.tv_usec = 0LL;
fdmax = v0;
while ( 1 )
{
*(__m128i *)read_fds.fds_bits = _mm_load_si128((const __m128i *)&master);
*(__m128i *)&read_fds.fds_bits[2] = _mm_load_si128((const __m128i *)&master + 1);
*(__m128i *)&read_fds.fds_bits[4] = _mm_load_si128((const __m128i *)&master + 2);
*(__m128i *)&read_fds.fds_bits[6] = _mm_load_si128((const __m128i *)&master + 3);
*(__m128i *)&read_fds.fds_bits[8] = _mm_load_si128((const __m128i *)&master + 4);
*(__m128i *)&read_fds.fds_bits[10] = _mm_load_si128((const __m128i *)&master + 5);
*(__m128i *)&read_fds.fds_bits[12] = _mm_load_si128((const __m128i *)&master + 6);
*(__m128i *)&read_fds.fds_bits[14] = _mm_load_si128((const __m128i *)&master + 7);
if ( select(fdmax + 1, &read_fds, 0LL, 0LL, &v4) == -1 )
break;
for ( i = fdmax; i; --i )
{
if ( (read_fds.fds_bits[i / 64] & (1LL << (i % 64))) != 0 )
{
if ( socket_server == i )
{
SOCKET_modify_clients_count(1);
*(&communication_session_ + 38) = 16;
v2 = accept(
socket_server,
(struct sockaddr *)&communication_session_,
(socklen_t *)(unsigned int)((_DWORD)&communication_session_ + 152));
newfd = v2;
*(&communication_session_ + 39) = v2;
if ( v2 == -1 )
{
puts("Socket closed.");
}
else
{
SOCKET_register_client(v2);
v3 = newfd;
*((_QWORD *)&master + newfd / 64) |= 1LL << (newfd % 64);
if ( v3 > fdmax )
fdmax = v3;
}
}
else
{
SOCKET_process(i);
}
}
}
}
SOCKET_stop();
exit(1);
}

canonical_decompiled_code:
void __noreturn func14()
{
int v0; // edx
int i; // ebx
int v2; // eax
int v3; // edx
struct timeval v4; // [rsp+0h] [rbp-28h] BYREF

v0 = socket_server;
*((_QWORD *)&master + socket_server / 64) |= 1LL << (socket_server % 64);
v4.tv_sec = 1LL;
v4.tv_usec = 0LL;
fdmax = v0;
while ( 1 )
{
*(__m128i *)read_fds.fds_bits = _mm_load_si128((const __m128i *)&master);
*(__m128i *)&read_fds.fds_bits[2] = _mm_load_si128((const __m128i *)&master + 1);
*(__m128i *)&read_fds.fds_bits[4] = _mm_load_si128((const __m128i *)&master + 2);
*(__m128i *)&read_fds.fds_bits[6] = _mm_load_si128((const __m128i *)&master + 3);
*(__m128i *)&read_fds.fds_bits[8] = _mm_load_si128((const __m128i *)&master + 4);
*(__m128i *)&read_fds.fds_bits[10] = _mm_load_si128((const __m128i *)&master + 5);
*(__m128i *)&read_fds.fds_bits[12] = _mm_load_si128((const __m128i *)&master + 6);
*(__m128i *)&read_fds.fds_bits[14] = _mm_load_si128((const __m128i *)&master + 7);
if ( select(fdmax + 1, &read_fds, 0LL, 0LL, &v4) == -1 )
break;
for ( i = fdmax; i; --i )
{
if ( (read_fds.fds_bits[i / 64] & (1LL << (i % 64))) != 0 )
{
if ( socket_server == i )
{
func2(1);
*(&communication_session_ + 38) = 16;
v2 = accept(
socket_server,
(struct sockaddr *)&communication_session_,
(socklen_t *)(unsigned int)((_DWORD)&communication_session_ + 152));
newfd = v2;
*(&communication_session_ + 39) = v2;
if ( v2 == -1 )
{
puts("Socket closed.");
}
else
{
func11(v2);
v3 = newfd;
*((_QWORD *)&master + newfd / 64) |= 1LL << (newfd % 64);
if ( v3 > fdmax )
fdmax = v3;
}
}
else
{
func13(i);
}
}
}
}
func4();
exit(1);
}

original_code:
void SOCKET_run( void ) {
 register int i = 0;
 struct timeval tv;
 pthread_t sthread;
 ((void) (((&master)->__fds_bits)[((socket_server) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((socket_server) % (8 * (int) sizeof (__fd_mask)))))));
 tv.tv_sec = 1;
 tv.tv_usec = 0;
 fdmax = socket_server;
 for( ;"elvis presley lives"; ) {
  read_fds = master;
  if( select( fdmax+1, &read_fds, ((void *)0), ((void *)0), &tv ) == -1 ) {
   SOCKET_stop();
   exit( 1 );
  }
  i = fdmax+1;
  while( --i ) {
   if( ((((&read_fds)->__fds_bits)[((i) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((i) % (8 * (int) sizeof (__fd_mask)))))) != 0) ) {
    if( i == socket_server ) {
     SOCKET_modify_clients_count( 1 );
     communication_session_.data_length = sizeof( struct sockaddr );
     newfd = accept( socket_server, ( struct sockaddr* )&communication_session_.address, &communication_session_.data_length );
     communication_session_.socket_descriptor = newfd;
     if( newfd == -1 ) {
      printf( "Socket closed.\n" );
     } else {
      SOCKET_register_client( newfd );
      ((void) (((&master)->__fds_bits)[((newfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((newfd) % (8 * (int) sizeof (__fd_mask)))))));
      if( newfd > fdmax ) {
       fdmax = newfd;
      }
     }
    } else {
     SOCKET_process( i );
    }
   }
  }
 }
}

canonical_original_code:
void SOCKET_run() {
 register int i = 0;
 struct timeval tv;
 unsigned long sthread;
 ((void) (((&master)->__fds_bits)[((socket_server) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((socket_server) % (8 * (int) sizeof (__fd_mask)))))));
 tv.tv_sec = 1;
 tv.tv_usec = 0;
 fdmax = socket_server;
 for( ;"elvis presley lives"; ) {
  read_fds = master;
  if( select( fdmax+1, &read_fds, ((void *)0), ((void *)0), &tv ) == -1 ) {
   SOCKET_stop();
   exit( 1 );
  }
  i = fdmax+1;
  while( --i ) {
   if( ((((&read_fds)->__fds_bits)[((i) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((i) % (8 * (int) sizeof (__fd_mask)))))) != 0) ) {
    if( i == socket_server ) {
     SOCKET_modify_clients_count( 1 );
     communication_session_.data_length = sizeof( struct sockaddr );
     newfd = accept( socket_server, ( struct sockaddr * )&communication_session_.address, &communication_session_.data_length );
     communication_session_.socket_descriptor = newfd;
     if( newfd == -1 ) {
      printf( "Socket closed.\n" );
     } else {
      SOCKET_register_client( newfd );
      ((void) (((&master)->__fds_bits)[((newfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((newfd) % (8 * (int) sizeof (__fd_mask)))))));
      if( newfd > fdmax ) {
       fdmax = newfd;
      }
     }
    } else {
     SOCKET_process( i );
    }
   }
  }
 }
}

variable_types:
sthread
unsigned long

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


decompiled_code:
void __noreturn SOCKET_main()
{
SOCKET_initialization();
SOCKET_prepare();
SOCKET_run();
}

canonical_decompiled_code:
void __noreturn func15()
{
func5();
func6();
func14();
}

original_code:
void SOCKET_main( void ) {
 ( void )SOCKET_initialization();
 ( void )SOCKET_prepare();
 ( void )SOCKET_run();
 ( void )SOCKET_stop();
}

canonical_original_code:
void SOCKET_main() {
 ( void )SOCKET_initialization();
 ( void )SOCKET_prepare();
 ( void )SOCKET_run();
 ( void )SOCKET_stop();
}


decompiled_code:
int *__fastcall SOCKET_find_client(int a1)
{
int *result; // rax

result = 0LL;
while ( connected_clients[2 * (_QWORD)result] != a1 )
{
result = (int *)((char *)result + 1);
if ( result == (int *)((char *)&loc_3FF + 1) )
return result;
}
return &connected_clients[2 * (int)result];
}

canonical_decompiled_code:
int *__fastcall func16(int a1)
{
int *result; // rax

result = 0LL;
while ( connected_clients[2 * (_QWORD)result] != a1 )
{
result = (int *)((char *)result + 1);
if ( result == (int *)((char *)&loc_3FF + 1) )
return result;
}
return &connected_clients[2 * (int)result];
}

original_code:
CONNECTED_CLIENT* SOCKET_find_client( int socket_descriptor ) {
 int i;
 for( i = 0; i < 1024; i++ ){
  if( connected_clients[ i ].socket_descriptor == socket_descriptor ) {
   return &connected_clients[ i ];
  }
 }
}

canonical_original_code:
struct CONNECTED_CLIENT *SOCKET_find_client(int socket_descriptor) {
 int i;
 for( i = 0; i < 1024; i++ ){
  if( connected_clients[ i ].socket_descriptor == socket_descriptor ) {
   return &connected_clients[ i ];
  }
 }
}

return_type: struct CONNECTED_CLIENT { int socket_descriptor; short connected; } *


repo: Ornicare/CFilesEchanger

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

do
result = getchar();
while ( result != 10 && result != -1 );
return result;
}

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

do
result = getchar();
while ( result != 10 && result != -1 );
return result;
}

original_code:
void clean_stdin(void)
{
    int c;
    do {
        c = getchar();
    } while (c != '\n' && c != (-1));
}

canonical_original_code:
void clean_stdin()
{
    int c;
    do {
        c = getchar();
    } while (c != '\n' && c != (-1));
}

variable_types: c int


sendCommandToServer

decompiled_code:
ssize_t __fastcall sendCommandToServer(int fd, const char *a2)
{
char dest[18]; // [rsp+6h] [rbp-12h] BYREF

strcpy(dest, a2);
return write(fd, dest, 0xAuLL);
}

canonical_decompiled_code:
ssize_t __fastcall func2(int fd, const char *a2)
{
char dest[18]; // [rsp+6h] [rbp-12h] BYREF

strcpy(dest, a2);
return write(fd, dest, 0xAuLL);
}

original_code:
int sendCommandToServer(int sock, char* commande)
{
 char commandReader[10];
     sprintf(commandReader, "%s", commande);
 write(sock, commandReader, sizeof(commandReader));
}

canonical_original_code:
int sendCommandToServer(int sock, char *commande)
{
 char commandReader[10];
     sprintf(commandReader, "%s", commande);
 write(sock, commandReader, sizeof(commandReader));
}

variable_types: sock int

variable_types:
commande
char *

variable_types:
commandReader
char [10]


min

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

result = a2;
if ( (int)a1 <= (int)a2 )
result = a1;
return result;
}

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

result = a2;
if ( (int)a1 <= (int)a2 )
result = a1;
return result;
}

original_code:
int min(int a, int b)
{
 int tmp = a;
 if(a>b) tmp=b;
 return tmp;
}

variable_types: a int

variable_types: b int

variable_types: tmp int


toLowerCase

decompiled_code:
char *__fastcall toLowerCase(char *a1)
{
char v2; // di
char *v3; // rbx

v2 = *a1;
if ( v2 )
{
v3 = a1;
do
{
*v3++ = tolower(v2);
v2 = *v3;
}
while ( *v3 );
}
return a1;
}

canonical_decompiled_code:
char *__fastcall func4(char *a1)
{
char v2; // di
char *v3; // rbx

v2 = *a1;
if ( v2 )
{
v3 = a1;
do
{
*v3++ = tolower(v2);
v2 = *v3;
}
while ( *v3 );
}
return a1;
}

original_code:
char * toLowerCase(char * word)
{
 int i;
 for (i = 0; word[i]; i++)
 word[i] = tolower(word[i]);
 return word;
}

canonical_original_code:
char *toLowerCase(char *word)
{
 int i;
 for (i = 0; word[i]; i++)
 word[i] = tolower(word[i]);
 return word;
}

variable_types:
word
char *


waitingForServerMessage

decompiled_code:
int __fastcall waitingForServerMessage(int a1, const char *a2)
{
int result; // eax
char buf[18]; // [rsp+6h] [rbp-12h] BYREF

read(a1, buf, 0xAuLL);
printf("READ : %s\n", buf);
result = strcmp(buf, a2);
if ( result )
{
puts("Erreur protocolaire");
result = 1;
}
return result;
}

canonical_decompiled_code:
int __fastcall func5(int a1, const char *a2)
{
int result; // eax
char buf[18]; // [rsp+6h] [rbp-12h] BYREF

read(a1, buf, 0xAuLL);
printf("READ : %s\n", buf);
result = strcmp(buf, a2);
if ( result )
{
puts("Erreur protocolaire");
result = 1;
}
return result;
}

original_code:
int waitingForServerMessage(int sock, char* commande)
{
 char commandReader[10];
 read(sock, commandReader, sizeof(commandReader)); if(1) printf("READ : %s\n",commandReader);
 if(strcmp(commandReader,commande)!=0)
 {
  printf("Erreur protocolaire\n");
  return 1;
 }
 return 0;
}

canonical_original_code:
int waitingForServerMessage(int sock, char *commande)
{
 char commandReader[10];
 read(sock, commandReader, sizeof(commandReader)); if(1) printf("READ : %s\n",commandReader);
 if(strcmp(commandReader,commande)!=0)
 {
  printf("Erreur protocolaire\n");
  return 1;
 }
 return 0;
}


getLock

decompiled_code:
_BOOL8 __fastcall getLock(char *file)
{
int v1; // eax
int v2; // ebx
_BOOL8 result; // rax
__int16 v4[4]; // [rsp+0h] [rbp-28h] BYREF
__int64 v5; // [rsp+8h] [rbp-20h]
__int64 v6; // [rsp+10h] [rbp-18h]
__pid_t v7; // [rsp+18h] [rbp-10h]

v4[0] = 1;
v4[1] = 0;
v5 = 0LL;
v6 = 0LL;
v7 = getpid();
v1 = open(file, 2);
if ( v1 == -1 )
{
perror("open");
result = 1LL;
}
else
{
v2 = v1;
if ( fcntl(v1, 5, v4) == -1 )
{
perror("fcntl");
result = 1LL;
}
else
{
close(v2);
result = v4[0] != 2;
}
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func7(char *file)
{
int v1; // eax
int v2; // ebx
_BOOL8 result; // rax
__int16 v4[4]; // [rsp+0h] [rbp-28h] BYREF
__int64 v5; // [rsp+8h] [rbp-20h]
__int64 v6; // [rsp+10h] [rbp-18h]
__pid_t v7; // [rsp+18h] [rbp-10h]

v4[0] = 1;
v4[1] = 0;
v5 = 0LL;
v6 = 0LL;
v7 = getpid();
v1 = open(file, 2);
if ( v1 == -1 )
{
perror("open");
result = 1LL;
}
else
{
v2 = v1;
if ( fcntl(v1, 5, v4) == -1 )
{
perror("fcntl");
result = 1LL;
}
else
{
close(v2);
result = v4[0] != 2;
}
}
return result;
}

original_code:
int getLock(char * filePath)
{
 struct flock fl = {1, 0, 0, 0, 0 };
 int fd;
 fl.l_pid =getpid();
 if ((fd = open(filePath, 02)) == -1) {
  perror("open");
  return 1;
 }
 if (fcntl(fd, 5, &fl) == -1) {
  perror("fcntl");
  return 1;
 }
 close(fd);
 if(fl.l_type==2)
 {
  return 0;
 }
 return 1;
}

canonical_original_code:
int getLock(char *filePath)
{
 struct flock fl = {1, 0, 0, 0, 0 };
 int fd;
 fl.l_pid =getpid();
 if ((fd = open(filePath, 02)) == -1) {
  perror("open");
  return 1;
 }
 if (fcntl(fd, 5, &fl) == -1) {
  perror("fcntl");
  return 1;
 }
 close(fd);
 if(fl.l_type==2)
 {
  return 0;
 }
 return 1;
}

variable_types:
filePath
char *

variable_types: struct flock { short l_type; short l_whence; long l_start; long l_len; int l_pid; }

variable_types: fd int


setLock

decompiled_code:
__int64 __fastcall setLock(char *file)
{
unsigned int v1; // ebx
int v3; // edi
__int16 v4[4]; // [rsp+0h] [rbp-38h] BYREF
__int64 v5; // [rsp+8h] [rbp-30h]
__int64 v6; // [rsp+10h] [rbp-28h]
__pid_t v7; // [rsp+18h] [rbp-20h]

v1 = 1;
if ( !getLock(file) )
{
v1 = 0;
v4[0] = 1;
v4[1] = 0;
v5 = 0LL;
v6 = 0LL;
v7 = getpid();
v3 = open(file, 2);
if ( v3 == -1 )
{
perror("open");
v1 = 1;
}
else if ( fcntl(v3, 7, v4) == -1 )
{
perror("fcntl");
v1 = 1;
}
}
return v1;
}

original_code:
int setLock(char * filePath)
{
 if(getLock(filePath)) return 1;
 struct flock fl = {1, 0, 0, 0, 0 };
 int fd;
 fl.l_pid = getpid();
 if ((fd = open(filePath, 02)) == -1) {
  perror("open");
  return 1;
 }
 if (fcntl(fd, 7, &fl) == -1) {
  perror("fcntl");
  return 1;
 }
 return 0;
}

canonical_original_code:
int setLock(char *filePath)
{
 if(getLock(filePath)) return 1;
 struct flock fl = {1, 0, 0, 0, 0 };
 int fd;
 fl.l_pid = getpid();
 if ((fd = open(filePath, 02)) == -1) {
  perror("open");
  return 1;
 }
 if (fcntl(fd, 7, &fl) == -1) {
  perror("fcntl");
  return 1;
 }
 return 0;
}

user_defined_types: struct flock { short l_type; short l_whence; long l_start; long l_len; int l_pid; }


unLock

decompiled_code:
__int64 __fastcall unLock(char *file)
{
_BOOL4 v1; // edx
__int64 result; // rax
int v3; // ebx
int v4; // edx
__int16 v5[4]; // [rsp+0h] [rbp-28h] BYREF
__int64 v6; // [rsp+8h] [rbp-20h]
__int64 v7; // [rsp+10h] [rbp-18h]
__pid_t v8; // [rsp+18h] [rbp-10h]

v1 = getLock(file);
result = 1LL;
if ( v1 )
{
v5[0] = 2;
v5[1] = 0;
v6 = 0LL;
v7 = 0LL;
v8 = 0;
v3 = open(file, 2);
if ( v3 == -1 )
{
perror("open");
result = 1LL;
}
else
{
v8 = getpid();
v4 = fcntl(v3, 6, v5);
result = 0LL;
if ( v4 == -1 )
{
perror("fcntl");
result = 1LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(char *file)
{
_BOOL4 v1; // edx
__int64 result; // rax
int v3; // ebx
int v4; // edx
__int16 v5[4]; // [rsp+0h] [rbp-28h] BYREF
__int64 v6; // [rsp+8h] [rbp-20h]
__int64 v7; // [rsp+10h] [rbp-18h]
__pid_t v8; // [rsp+18h] [rbp-10h]

v1 = func7(file);
result = 1LL;
if ( v1 )
{
v5[0] = 2;
v5[1] = 0;
v6 = 0LL;
v7 = 0LL;
v8 = 0;
v3 = open(file, 2);
if ( v3 == -1 )
{
perror("open");
result = 1LL;
}
else
{
v8 = getpid();
v4 = fcntl(v3, 6, v5);
result = 0LL;
if ( v4 == -1 )
{
perror("fcntl");
result = 1LL;
}
}
}
return result;
}

original_code:
int unLock(char * filePath)
{
 if(!getLock(filePath)) return 1;
 struct flock fl = {2, 0, 0, 0, 0 };
 int fd;
 if ((fd = open(filePath, 02)) == -1) {
  perror("open");
  return 1;
 }
 fl.l_pid =getpid();
 if (fcntl(fd, 6, &fl) == -1) {
  perror("fcntl");
  return 1;
 }
     return 0;
}

canonical_original_code:
int unLock(char *filePath)
{
 if(!getLock(filePath)) return 1;
 struct flock fl = {2, 0, 0, 0, 0 };
 int fd;
 if ((fd = open(filePath, 02)) == -1) {
  perror("open");
  return 1;
 }
 fl.l_pid =getpid();
 if (fcntl(fd, 6, &fl) == -1) {
  perror("fcntl");
  return 1;
 }
     return 0;
}


decompiled_code:
__int64 __fastcall init_pipe(__int16 a1, unsigned int *a2, _QWORD *a3, _QWORD *a4, unsigned __int8 a5)
{
int v8; // eax
int v9; // ebx
ssize_t v10; // rax
ssize_t v11; // rax
unsigned int v12; // ebp
ssize_t v14; // rax
__int64 v15; // [rsp+0h] [rbp-78h] BYREF
__int64 v16; // [rsp+8h] [rbp-70h] BYREF
__int64 v17; // [rsp+10h] [rbp-68h]
__int64 v18; // [rsp+18h] [rbp-60h]
__int64 v19; // [rsp+20h] [rbp-58h]
struct sockaddr addr; // [rsp+30h] [rbp-48h] BYREF

v8 = socket(2, 2, 0);
if ( v8 >= 0 )
{
v9 = v8;
*(_QWORD *)&addr.sa_family = 0LL;
*(_QWORD *)&addr.sa_data[6] = 0LL;
*(_WORD *)addr.sa_data = _bswap_16(a1);
*(_QWORD *)&addr.sa_data[2] = *a2;
v15 = 0LL;
v16 = 0LL;
v17 = 0LL;
v18 = 0LL;
v19 = 0LL;
if ( (unsigned int)xen_shm_pipe_init(a3, 1LL, 1LL) )
{
puts("Unable to init xen_shm_pipe");
perror("xen_shm_pipe_init");
LABEL_28:
shutdown(v9, 2);
return (unsigned int)-1;
}
if ( (unsigned int)xen_shm_pipe_init(a4, 0LL, 1LL) )
{
puts("Unable to init xen_shm_pipe");
perror("xen_shm_pipe_init");
LABEL_27:
xen_shm_pipe_free(*a3);
goto LABEL_28;
}
LOWORD(v15) = 257;
if ( (unsigned int)xen_shm_pipe_getdomid(*a4, &v16) )
{
puts("Unable to get local domid");
perror("xen_shm_pipe_getdomid");
LABEL_26:
xen_shm_pipe_free(*a4);
goto LABEL_27;
}
v10 = sendto(v9, &v15, 0xCuLL, 0, &addr, 0x10u);
if ( v10 >= 0 )
{
if ( v10 != 12 )
{
LABEL_19:
puts("Unable to send message (bad size=");
perror("sendto");
goto LABEL_25;
}
v11 = recv(v9, &v15, 0x28uLL, 0);
if ( v11 <= 0 )
{
puts("Unable to receive message");
perror("recv");
goto LABEL_25;
}
if ( BYTE1(v15) == 2 )
{
puts("Server error");
goto LABEL_25;
}
if ( BYTE1(v15) != 3 )
{
puts("Protocol error");
goto LABEL_25;
}
if ( (unsigned __int64)v11 <= 0x11 )
{
printf("Bad packet: too short");
goto LABEL_25;
}
if ( (_BYTE)v17 == 1 )
{
puts("xen_shm_pipe_conv_writer_offers not supporter");
goto LABEL_25;
}
if ( (_BYTE)v17 != 2 )
{
puts("Protocol error: bad mode");
LABEL_25:
BYTE1(v15) = 4;
sendto(v9, &v15, 8uLL, 0, &addr, 0x10u);
goto LABEL_26;
}
if ( (unsigned int)xen_shm_pipe_connect(*a4, BYTE1(v17), HIDWORD(v16), (unsigned int)v16) )
{
puts("Unable to connect xen_shm_pipe");
perror("xen_shm_pipe_connect");
goto LABEL_25;
}
v12 = xen_shm_pipe_offers(*a3, a5, HIDWORD(v16), (char *)&v16 + 4, &v16);
if ( v12 )
{
puts("Unable to offer xen_shm_pipe");
perror("xen_shm_pipe_offers");
goto LABEL_25;
}
BYTE1(v15) = 5;
BYTE1(v17) = a5;
v14 = sendto(v9, &v15, 0x12uLL, 0, &addr, 0x10u);
if ( v14 >= 0 )
{
if ( v14 == 18 )
{
shutdown(v9, 2);
return v12;
}
goto LABEL_19;
}
}
puts("Unable to send message");
perror("sendto");
goto LABEL_25;
}
printf("Unable to open an udp socket");
perror("socket");
return (unsigned int)-1;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int16 a1, unsigned int *a2, _QWORD *a3, _QWORD *a4, unsigned __int8 a5)
{
int v8; // eax
int v9; // ebx
ssize_t v10; // rax
ssize_t v11; // rax
unsigned int v12; // ebp
ssize_t v14; // rax
__int64 v15; // [rsp+0h] [rbp-78h] BYREF
__int64 v16; // [rsp+8h] [rbp-70h] BYREF
__int64 v17; // [rsp+10h] [rbp-68h]
__int64 v18; // [rsp+18h] [rbp-60h]
__int64 v19; // [rsp+20h] [rbp-58h]
struct sockaddr addr; // [rsp+30h] [rbp-48h] BYREF

v8 = socket(2, 2, 0);
if ( v8 >= 0 )
{
v9 = v8;
*(_QWORD *)&addr.sa_family = 0LL;
*(_QWORD *)&addr.sa_data[6] = 0LL;
*(_WORD *)addr.sa_data = func0(a1);
*(_QWORD *)&addr.sa_data[2] = *a2;
v15 = 0LL;
v16 = 0LL;
v17 = 0LL;
v18 = 0LL;
v19 = 0LL;
if ( (unsigned int)xen_shm_pipe_init(a3, 1LL, 1LL) )
{
puts("Unable to init xen_shm_pipe");
perror("xen_shm_pipe_init");
LABEL_28:
shutdown(v9, 2);
return (unsigned int)-1;
}
if ( (unsigned int)xen_shm_pipe_init(a4, 0LL, 1LL) )
{
puts("Unable to init xen_shm_pipe");
perror("xen_shm_pipe_init");
LABEL_27:
xen_shm_pipe_free(*a3);
goto LABEL_28;
}
LOWORD(v15) = 257;
if ( (unsigned int)xen_shm_pipe_getdomid(*a4, &v16) )
{
puts("Unable to get local domid");
perror("xen_shm_pipe_getdomid");
LABEL_26:
xen_shm_pipe_free(*a4);
goto LABEL_27;
}
v10 = sendto(v9, &v15, 0xCuLL, 0, &addr, 0x10u);
if ( v10 >= 0 )
{
if ( v10 != 12 )
{
LABEL_19:
puts("Unable to send message (bad size=");
perror("sendto");
goto LABEL_25;
}
v11 = recv(v9, &v15, 0x28uLL, 0);
if ( v11 <= 0 )
{
puts("Unable to receive message");
perror("recv");
goto LABEL_25;
}
if ( BYTE1(v15) == 2 )
{
puts("Server error");
goto LABEL_25;
}
if ( BYTE1(v15) != 3 )
{
puts("Protocol error");
goto LABEL_25;
}
if ( (unsigned __int64)v11 <= 0x11 )
{
printf("Bad packet: too short");
goto LABEL_25;
}
if ( (_BYTE)v17 == 1 )
{
puts("xen_shm_pipe_conv_writer_offers not supporter");
goto LABEL_25;
}
if ( (_BYTE)v17 != 2 )
{
puts("Protocol error: bad mode");
LABEL_25:
BYTE1(v15) = 4;
sendto(v9, &v15, 8uLL, 0, &addr, 0x10u);
goto LABEL_26;
}
if ( (unsigned int)xen_shm_pipe_connect(*a4, BYTE1(v17), HIDWORD(v16), (unsigned int)v16) )
{
puts("Unable to connect xen_shm_pipe");
perror("xen_shm_pipe_connect");
goto LABEL_25;
}
v12 = xen_shm_pipe_offers(*a3, a5, HIDWORD(v16), (char *)&v16 + 4, &v16);
if ( v12 )
{
puts("Unable to offer xen_shm_pipe");
perror("xen_shm_pipe_offers");
goto LABEL_25;
}
BYTE1(v15) = 5;
BYTE1(v17) = a5;
v14 = sendto(v9, &v15, 0x12uLL, 0, &addr, 0x10u);
if ( v14 >= 0 )
{
if ( v14 == 18 )
{
shutdown(v9, 2);
return v12;
}
goto LABEL_19;
}
}
puts("Unable to send message");
perror("sendto");
goto LABEL_25;
}
printf("Unable to open an udp socket");
perror("socket");
return (unsigned int)-1;
}

original_code:
int
init_pipe(in_port_t distant_port, struct in_addr *distant_addr, xen_shm_pipe_p *receive_fd, xen_shm_pipe_p *send_fd, uint8_t proposed_page_page_count)
{
    struct sockaddr_in addr;
    int ret;
    int client_fd;
    int return_value;
    ssize_t len;
    uint8_t buffer[40];
    struct xen_shm_udp_proto_header *header;
    struct xen_shm_udp_proto_client_hello *client_hello;
    struct xen_shm_udp_proto_grant *grant;
    return_value = -1;
    client_fd = socket(2, SOCK_DGRAM, 0);
    if (client_fd < 0) {
        printf("Unable to open an udp socket");
        perror("socket");
        return -1;
    }
    memset(&addr, 0, sizeof(struct sockaddr_in));
    addr.sin_port = htons(distant_port);
    memcpy(&addr.sin_addr, distant_addr,sizeof(struct in_addr));
    memset(buffer, 0, 40);
    header = (struct xen_shm_udp_proto_header*) buffer;
    client_hello = (struct xen_shm_udp_proto_client_hello*) buffer;
    grant = (struct xen_shm_udp_proto_grant*) buffer;
    ret = xen_shm_pipe_init(receive_fd, xen_shm_pipe_mod_read, xen_shm_pipe_conv_reader_offers);
    if (ret != 0) {
        printf("Unable to init xen_shm_pipe\n");
        perror("xen_shm_pipe_init");
        goto shutdown_socket;
    }
    ret = xen_shm_pipe_init(send_fd, xen_shm_pipe_mod_write, xen_shm_pipe_conv_reader_offers);
    if (ret != 0) {
        printf("Unable to init xen_shm_pipe\n");
        perror("xen_shm_pipe_init");
        goto clean_receive_fd;
    }
    header->version = 0x01;
    header->message = 0x01;
    ret = xen_shm_pipe_getdomid(*send_fd, &client_hello->domid);
    if (ret != 0) {
        printf("Unable to get local domid\n");
        perror("xen_shm_pipe_getdomid");
        goto clean_send_fd;
    }
    len = sendto(client_fd, buffer, sizeof(struct xen_shm_udp_proto_client_hello), 0, (struct sockaddr *) &addr, sizeof(struct sockaddr_in));
    if (len < 0) {
        printf("Unable to send message\n");
        perror("sendto");
        goto cancel_server;
    }
    if ((size_t)len != sizeof(struct xen_shm_udp_proto_client_hello)) {
        printf("Unable to send message (bad size=\n");
        perror("sendto");
        goto cancel_server;
    }
    len = recv(client_fd, buffer, 40, 0 );
    if (len <= 0) {
        printf("Unable to receive message\n");
        perror("recv");
        goto cancel_server;
    }
    if (header->message == 0x02) {
        printf("Server error\n");
        goto cancel_server;
    }
    if (header->message != 0x03) {
        printf("Protocol error\n");
        goto cancel_server;
    }
    if ((size_t)len < sizeof(struct xen_shm_udp_proto_grant)) {
        printf("Bad packet: too short");
        goto cancel_server;
    }
    switch (grant->mode) {
        case 0x01:
            printf("xen_shm_pipe_conv_writer_offers not supporter\n");
            goto cancel_server;
        case 0x02:
            break;
        default:
            printf("Protocol error: bad mode\n");
            goto cancel_server;
    }
    ;
    ret = xen_shm_pipe_connect(*send_fd, grant->page_count, grant->domid, grant->grant_ref);
    if (ret != 0) {
        printf("Unable to connect xen_shm_pipe\n");
        perror("xen_shm_pipe_connect");
        goto cancel_server;
    }
    ;
    ret = xen_shm_pipe_offers(*receive_fd, proposed_page_page_count, grant->domid, &grant->domid, &grant->grant_ref);
    ;
    if (ret != 0) {
        printf("Unable to offer xen_shm_pipe\n");
        perror("xen_shm_pipe_offers");
        goto cancel_server;
    }
    header->message = 0x05;
    grant->page_count = proposed_page_page_count;
    len = sendto(client_fd, buffer, sizeof(struct xen_shm_udp_proto_grant), 0, (struct sockaddr *) &addr, sizeof(struct sockaddr_in));
    if (len < 0) {
        printf("Unable to send message\n");
        perror("sendto");
        goto cancel_server;
    }
    if ((size_t)len != sizeof(struct xen_shm_udp_proto_grant)) {
        printf("Unable to send message (bad size=\n");
        perror("sendto");
        goto cancel_server;
    }
    shutdown(client_fd, SHUT_RDWR);
    return 0;
cancel_server:
    header->message = 0x04;
    sendto(client_fd, buffer, sizeof(struct xen_shm_udp_proto_header), 0, (struct sockaddr *) &addr, sizeof(struct sockaddr_in));
clean_send_fd:
    xen_shm_pipe_free(*send_fd);
clean_receive_fd:
    xen_shm_pipe_free(*receive_fd);
shutdown_socket:
    shutdown(client_fd, SHUT_RDWR);
    return return_value;
}

canonical_original_code:
int init_pipe(unsigned short distant_port, struct in_addr *distant_addr, void **receive_fd, void **send_fd, unsigned char proposed_page_page_count)
{
    struct sockaddr_in addr;
    int ret;
    int client_fd;
    int return_value;
    long len;
    unsigned char buffer[40];
    struct xen_shm_udp_proto_header *header;
    struct xen_shm_udp_proto_client_hello *client_hello;
    struct xen_shm_udp_proto_grant *grant;
    return_value = -1;
    client_fd = socket(2, SOCK_DGRAM, 0);
    if (client_fd < 0) {
        printf("Unable to open an udp socket");
        perror("socket");
        return -1;
    }
    memset(&addr, 0, sizeof(struct sockaddr_in));
    addr.sin_port = htons(distant_port);
    memcpy(&addr.sin_addr, distant_addr,sizeof(struct in_addr));
    memset(buffer, 0, 40);
    header = (struct xen_shm_udp_proto_header *) buffer;
    client_hello = (struct xen_shm_udp_proto_client_hello *) buffer;
    grant = (struct xen_shm_udp_proto_grant *) buffer;
    ret = xen_shm_pipe_init(receive_fd, xen_shm_pipe_mod_read, xen_shm_pipe_conv_reader_offers);
    if (ret != 0) {
        printf("Unable to init xen_shm_pipe\n");
        perror("xen_shm_pipe_init");
        goto shutdown_socket;
    }
    ret = xen_shm_pipe_init(send_fd, xen_shm_pipe_mod_write, xen_shm_pipe_conv_reader_offers);
    if (ret != 0) {
        printf("Unable to init xen_shm_pipe\n");
        perror("xen_shm_pipe_init");
        goto clean_receive_fd;
    }
    header->version = 0x01;
    header->message = 0x01;
    ret = xen_shm_pipe_getdomid(*send_fd, &client_hello->domid);
    if (ret != 0) {
        printf("Unable to get local domid\n");
        perror("xen_shm_pipe_getdomid");
        goto clean_send_fd;
    }
    len = sendto(client_fd, buffer, sizeof(struct xen_shm_udp_proto_client_hello), 0, (struct sockaddr *) &addr, sizeof(struct sockaddr_in));
    if (len < 0) {
        printf("Unable to send message\n");
        perror("sendto");
        goto cancel_server;
    }
    if ((unsigned long)len != sizeof(struct xen_shm_udp_proto_client_hello)) {
        printf("Unable to send message (bad size=\n");
        perror("sendto");
        goto cancel_server;
    }
    len = recv(client_fd, buffer, 40, 0 );
    if (len <= 0) {
        printf("Unable to receive message\n");
        perror("recv");
        goto cancel_server;
    }
    if (header->message == 0x02) {
        printf("Server error\n");
        goto cancel_server;
    }
    if (header->message != 0x03) {
        printf("Protocol error\n");
        goto cancel_server;
    }
    if ((unsigned long)len < sizeof(struct xen_shm_udp_proto_grant)) {
        printf("Bad packet: too short");
        goto cancel_server;
    }
    switch (grant->mode) {
        case 0x01:
            printf("xen_shm_pipe_conv_writer_offers not supporter\n");
            goto cancel_server;
        case 0x02:
            break;
        default:
            printf("Protocol error: bad mode\n");
            goto cancel_server;
    }
    ;
    ret = xen_shm_pipe_connect(*send_fd, grant->page_count, grant->domid, grant->grant_ref);
    if (ret != 0) {
        printf("Unable to connect xen_shm_pipe\n");
        perror("xen_shm_pipe_connect");
        goto cancel_server;
    }
    ;
    ret = xen_shm_pipe_offers(*receive_fd, proposed_page_page_count, grant->domid, &grant->domid, &grant->grant_ref);
    ;
    if (ret != 0) {
        printf("Unable to offer xen_shm_pipe\n");
        perror("xen_shm_pipe_offers");
        goto cancel_server;
    }
    header->message = 0x05;
    grant->page_count = proposed_page_page_count;
    len = sendto(client_fd, buffer, sizeof(struct xen_shm_udp_proto_grant), 0, (struct sockaddr *) &addr, sizeof(struct sockaddr_in));
    if (len < 0) {
        printf("Unable to send message\n");
        perror("sendto");
        goto cancel_server;
    }
    if ((unsigned long)len != sizeof(struct xen_shm_udp_proto_grant)) {
        printf("Unable to send message (bad size=\n");
        perror("sendto");
        goto cancel_server;
    }
    shutdown(client_fd, SHUT_RDWR);
    return 0;
cancel_server:
    header->message = 0x04;
    sendto(client_fd, buffer, sizeof(struct xen_shm_udp_proto_header), 0, (struct sockaddr *) &addr, sizeof(struct sockaddr_in));
clean_send_fd:
    xen_shm_pipe_free(*send_fd);
clean_receive_fd:
    xen_shm_pipe_free(*receive_fd);
shutdown_socket:
    shutdown(client_fd, SHUT_RDWR);
    return return_value;
}

variable_types: struct in_addr { unsigned int s_addr; } *

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

variable_types: len long

variable_types:
buffer
unsigned char [40]

variable_types: struct xen_shm_udp_proto_header { unsigned char version; unsigned char message; unsigned short reserved; unsigned int big_reserved; } *

variable_types: struct xen_shm_udp_proto_client_hello { struct xen_shm_udp_proto_header { unsigned char version; unsigned char message; unsigned short reserved; unsigned int big_reserved; } header; unsigned int domid; } *

variable_types: struct xen_shm_udp_proto_grant { struct xen_shm_udp_proto_header { unsigned char version; unsigned char message; unsigned short reserved; unsigned int big_reserved; } header; unsigned int grant_ref; unsigned int domid; unsigned char mode; unsigned char page_count; } *

user_defined_types: struct xen_shm_udp_proto_client_hello { struct xen_shm_udp_proto_header header; unsigned int domid; }

user_defined_types: struct xen_shm_udp_proto_grant { struct xen_shm_udp_proto_header header; unsigned int grant_ref; unsigned int domid; unsigned char mode; unsigned char page_count; }


decompiled_code:
__int64 __fastcall run_client_thread(__int16 a1, unsigned int *a2, unsigned __int8 a3, void *(*a4)(void *), _QWORD *a5, pthread_t *a6)
{
unsigned int v9; // eax
unsigned int v10; // ebx

*((_DWORD *)a5 + 4) = 0;
v9 = init_pipe(a1, a2, a5, a5 + 1, a3);
if ( v9 )
{
v10 = v9;
perror("init pipe");
}
else
{
v10 = pthread_create(a6, 0LL, a4, a5);
if ( v10 )
{
perror("pthread create");
xen_shm_pipe_free(*a5);
xen_shm_pipe_free(a5[1]);
}
}
return v10;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int16 a1, unsigned int *a2, unsigned __int8 a3, void *(*a4)(void *), _QWORD *a5, pthread_t *a6)
{
unsigned int v9; // eax
unsigned int v10; // ebx

*((_DWORD *)a5 + 4) = 0;
v9 = func1(a1, a2, a5, a5 + 1, a3);
if ( v9 )
{
v10 = v9;
perror("init pipe");
}
else
{
v10 = pthread_create(a6, 0LL, a4, a5);
if ( v10 )
{
perror("pthread create");
xen_shm_pipe_free(*a5);
xen_shm_pipe_free(a5[1]);
}
}
return v10;
}

original_code:
int
run_client_thread(in_port_t distant_por, struct in_addr *distant_addr, uint8_t proposed_page_page_count,
        handler_run handler_fct, struct xen_shm_handler_data* hdlr_data, pthread_t* thread_info)
{
    int ret;
    hdlr_data->stop = 0;
    ret = init_pipe(distant_por, distant_addr, &hdlr_data->receive_fd, &hdlr_data->send_fd, proposed_page_page_count);
    if(ret!=0) {
        perror("init pipe");
        return ret;
    }
    ret = pthread_create(thread_info, ((void *)0), (void * (*)(void *))handler_fct, hdlr_data);
    if (ret != 0) {
        perror("pthread create");
        xen_shm_pipe_free(hdlr_data->receive_fd);
        xen_shm_pipe_free(hdlr_data->send_fd);
        return ret;
    }
    return 0;
}

canonical_original_code:
int run_client_thread(unsigned short distant_por, struct in_addr *distant_addr, unsigned char proposed_page_page_count, void *(*handler_fct)(struct xen_shm_handler_data *data), struct xen_shm_handler_data *hdlr_data, unsigned long *thread_info)
{
    int ret;
    hdlr_data->stop = 0;
    ret = init_pipe(distant_por, distant_addr, &hdlr_data->receive_fd, &hdlr_data->send_fd, proposed_page_page_count);
    if(ret!=0) {
        perror("init pipe");
        return ret;
    }
    ret = pthread_create(thread_info, ((void *)0), (void *(*)(void *))handler_fct, hdlr_data);
    if (ret != 0) {
        perror("pthread create");
        xen_shm_pipe_free(hdlr_data->receive_fd);
        xen_shm_pipe_free(hdlr_data->send_fd);
        return ret;
    }
    return 0;
}

variable_types: void *(*)(struct xen_shm_handler_data { void *receive_fd; void *send_fd; int stop; void *private_data; } *data)


decompiled_code:
__int64 __fastcall run_client(__int16 a1, unsigned int *a2, unsigned __int8 a3, __int64 (__fastcall *a4)(__int64), __int64 a5, _QWORD *a6)
{
unsigned int v9; // ebp

*(_DWORD *)(a5 + 16) = 0;
v9 = init_pipe(a1, a2, (_QWORD *)a5, (_QWORD *)(a5 + 8), a3);
if ( v9 )
perror("init pipe");
else
*a6 = a4(a5);
return v9;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int16 a1, unsigned int *a2, unsigned __int8 a3, __int64 (__fastcall *a4)(__int64), __int64 a5, _QWORD *a6)
{
unsigned int v9; // ebp

*(_DWORD *)(a5 + 16) = 0;
v9 = func1(a1, a2, (_QWORD *)a5, (_QWORD *)(a5 + 8), a3);
if ( v9 )
perror("init pipe");
else
*a6 = a4(a5);
return v9;
}

original_code:
int
run_client(in_port_t distant_por, struct in_addr *distant_addr, uint8_t proposed_page_page_count,
        handler_run handler_fct, struct xen_shm_handler_data* hdlr_data, void** returned_value)
{
    int ret;
    hdlr_data->stop = 0;
    ret = init_pipe(distant_por, distant_addr, &hdlr_data->receive_fd, &hdlr_data->send_fd, proposed_page_page_count);
    if(ret!=0) {
        perror("init pipe");
        return ret;
    }
    *returned_value = handler_fct(hdlr_data);
    return 0;
}

canonical_original_code:
int run_client(unsigned short distant_por, struct in_addr *distant_addr, unsigned char proposed_page_page_count, void *(*handler_fct)(struct xen_shm_handler_data *data), struct xen_shm_handler_data *hdlr_data, void **returned_value)
{
    int ret;
    hdlr_data->stop = 0;
    ret = init_pipe(distant_por, distant_addr, &hdlr_data->receive_fd, &hdlr_data->send_fd, proposed_page_page_count);
    if(ret!=0) {
        perror("init pipe");
        return ret;
    }
    *returned_value = handler_fct(hdlr_data);
    return 0;
}

user_defined_types: struct xen_shm_handler_data { void *receive_fd; void *send_fd; int stop; void *private_data; }


decompiled_code:
void __noreturn pipe_read()
{
void *v0; // rax
void *v1; // rbx
__int64 v2; // rax

v0 = malloc((unsigned int)buffer_size);
if ( v0 )
{
v1 = v0;
gettimeofday(&start, 0LL);
while ( 1 )
{
v2 = xen_shm_pipe_read_all(xpipe, v1, (unsigned int)buffer_size);
if ( v2 <= 0 )
break;
byte_count += v2;
}
if ( v2 )
perror("Xen pipe read");
else
puts("End of file ");
clean(0);
}
puts("Memory error");
clean(0);
}

canonical_decompiled_code:
void __noreturn func2()
{
void *v0; // rax
void *v1; // rbx
__int64 v2; // rax

v0 = malloc((unsigned int)buffer_size);
if ( v0 )
{
v1 = v0;
gettimeofday(&start, 0LL);
while ( 1 )
{
v2 = xen_shm_pipe_read_all(xpipe, v1, (unsigned int)buffer_size);
if ( v2 <= 0 )
break;
byte_count += v2;
}
if ( v2 )
perror("Xen pipe read");
else
puts("End of file ");
func0(0);
}
puts("Memory error");
func0(0);
}

original_code:
void pipe_read(void) {
    uint8_t* buffer;
    ssize_t retval;
    if((buffer = malloc(sizeof(uint8_t)*buffer_size))== ((void *)0)) {
        printf("Memory error\n");
        clean(0);
    }
    gettimeofday(&start , ((void *)0));
    while((retval = xen_shm_pipe_read_all(xpipe, buffer, buffer_size)) > 0) {
        byte_count += (uint64_t) retval;
    }
    if(retval == 0) {
        printf("End of file \n");
    } else {
        perror("Xen pipe read");
    }
    clean(0);
}

canonical_original_code:
void pipe_read() {
    unsigned char *buffer;
    long retval;
    if((buffer = malloc(sizeof(unsigned char)*buffer_size))== ((void *)0)) {
        printf("Memory error\n");
        clean(0);
    }
    gettimeofday(&start , ((void *)0));
    while((retval = xen_shm_pipe_read_all(xpipe, buffer, buffer_size)) > 0) {
        byte_count += (unsigned long) retval;
    }
    if(retval == 0) {
        printf("End of file \n");
    } else {
        perror("Xen pipe read");
    }
    clean(0);
}

variable_types:
buffer
unsigned char *

variable_types: retval long


decompiled_code:
void __noreturn pipe_write()
{
int v0; // ebx
_BYTE *v1; // rax
_BYTE *v2; // rbp
_BYTE *v3; // rdx
unsigned int v4; // ebx
__int64 v5; // rax

v0 = buffer_size;
v1 = malloc((unsigned int)buffer_size);
if ( v1 )
{
v2 = v1;
v3 = &v1[v0];
if ( v0 )
{
do
*v1++ = 117;
while ( v1 != v3 );
}
gettimeofday(&start, 0LL);
if ( iterations )
{
v4 = 0;
do
{
v5 = xen_shm_pipe_write_all(xpipe, v2, (unsigned int)buffer_size);
if ( v5 < 0 )
{
perror("Xen pipe write");
clean(0);
}
if ( !v5 )
{
puts("Write retval = 0 !");
clean(0);
}
byte_count += v5;
++v4;
}
while ( iterations > v4 );
}
clean(0);
}
puts("Memory error");
clean(0);
}

canonical_decompiled_code:
void __noreturn func3()
{
int v0; // ebx
_BYTE *v1; // rax
_BYTE *v2; // rbp
_BYTE *v3; // rdx
unsigned int v4; // ebx
__int64 v5; // rax

v0 = buffer_size;
v1 = malloc((unsigned int)buffer_size);
if ( v1 )
{
v2 = v1;
v3 = &v1[v0];
if ( v0 )
{
do
*v1++ = 117;
while ( v1 != v3 );
}
gettimeofday(&start, 0LL);
if ( iterations )
{
v4 = 0;
do
{
v5 = xen_shm_pipe_write_all(xpipe, v2, (unsigned int)buffer_size);
if ( v5 < 0 )
{
perror("Xen pipe write");
func0(0);
}
if ( !v5 )
{
puts("Write retval = 0 !");
func0(0);
}
byte_count += v5;
++v4;
}
while ( iterations > v4 );
}
func0(0);
}
puts("Memory error");
func0(0);
}

original_code:
void pipe_write(void) {
    uint8_t* buffer;
    ssize_t retval;
    uint32_t i;
    if((buffer = malloc(sizeof(uint8_t)*buffer_size))== ((void *)0)) {
        printf("Memory error\n");
        clean(0);
    }
    for(i = 0; i<buffer_size; i++) {
        buffer[i] = 'u';
    }
    gettimeofday(&start , ((void *)0));
    for(i=0; i<iterations; i++) {
        retval = xen_shm_pipe_write_all(xpipe, buffer, buffer_size);
        if(retval < 0) {
            perror("Xen pipe write");
            clean(0);
        } else if(retval == 0) {
            printf("Write retval = 0 !\n");
            clean(0);
        }
        byte_count+=(uint64_t) retval;
    }
    clean(0);
}

canonical_original_code:
void pipe_write() {
    unsigned char *buffer;
    long retval;
    unsigned int i;
    if((buffer = malloc(sizeof(unsigned char)*buffer_size))== ((void *)0)) {
        printf("Memory error\n");
        clean(0);
    }
    for(i = 0; i<buffer_size; i++) {
        buffer[i] = 'u';
    }
    gettimeofday(&start , ((void *)0));
    for(i=0; i<iterations; i++) {
        retval = xen_shm_pipe_write_all(xpipe, buffer, buffer_size);
        if(retval < 0) {
            perror("Xen pipe write");
            clean(0);
        } else if(retval == 0) {
            printf("Write retval = 0 !\n");
            clean(0);
        }
        byte_count+=(unsigned long) retval;
    }
    clean(0);
}

variable_types:
i
unsigned int


decompiled_code:
__sighandler_t init_pipe_reader()
{
unsigned int v1; // [rsp+4h] [rbp-14h] BYREF
unsigned int v2; // [rsp+8h] [rbp-10h] BYREF
unsigned int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

puts("\nInit: Reader - Receiver");
if ( (unsigned int)xen_shm_pipe_init(&xpipe, 1LL, 0LL) )
{
perror("Pipe init");
exit(-1);
}
if ( (unsigned int)xen_shm_pipe_getdomid(xpipe, v3) )
{
perror("Pipe get domid");
clean(0);
}
printf("RECEIVER domain id: %u\n", v3[0]);
printf("Distant domain id: ");
if ( (unsigned int)_isoc99_scanf("%u", &v2) != 1 )
{
printf("Scanf error");
clean(0);
}
printf("Offerer's grant ref: ");
if ( (unsigned int)_isoc99_scanf("%u", &v1) != 1 )
{
printf("Scanf error");
clean(0);
}
if ( (unsigned int)xen_shm_pipe_connect(xpipe, (unsigned __int8)page_count, v2, v1) )
{
perror("Pipe connect");
clean(0);
}
puts("Connected successfully !");
return signal(2, (__sighandler_t)clean);
}

canonical_decompiled_code:
__sighandler_t func4()
{
unsigned int v1; // [rsp+4h] [rbp-14h] BYREF
unsigned int v2; // [rsp+8h] [rbp-10h] BYREF
unsigned int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

puts("\nInit: Reader - Receiver");
if ( (unsigned int)xen_shm_pipe_init(&xpipe, 1LL, 0LL) )
{
perror("Pipe init");
exit(-1);
}
if ( (unsigned int)xen_shm_pipe_getdomid(xpipe, v3) )
{
perror("Pipe get domid");
func0(0);
}
printf("RECEIVER domain id: %u\n", v3[0]);
printf("Distant domain id: ");
if ( (unsigned int)_isoc99_scanf("%u", &v2) != 1 )
{
printf("Scanf error");
func0(0);
}
printf("Offerer's grant ref: ");
if ( (unsigned int)_isoc99_scanf("%u", &v1) != 1 )
{
printf("Scanf error");
func0(0);
}
if ( (unsigned int)xen_shm_pipe_connect(xpipe, (unsigned __int8)page_count, v2, v1) )
{
perror("Pipe connect");
func0(0);
}
puts("Connected successfully !");
return signal(2, (__sighandler_t)clean);
}

original_code:
void init_pipe_reader(void) {
    uint32_t local_domid;
    uint32_t dist_domid;
    uint32_t grant_ref;
    printf("\nInit: Reader - Receiver\n");
    if(xen_shm_pipe_init(&xpipe, xen_shm_pipe_mod_read, xen_shm_pipe_conv_writer_offers)) {
        perror("Pipe init");
        exit(-1);
    }
    pipe_used = 1;
    if(xen_shm_pipe_getdomid(xpipe, &local_domid)) {
        perror("Pipe get domid");
        clean(0);
    }
    printf("RECEIVER domain id: %""u""\n", local_domid);
    printf("Distant domain id: ");
    if((scanf("%""u", &dist_domid)!=1)) {
        printf("Scanf error");
        clean(0);
    }
    printf("Offerer's grant ref: ");
    if((scanf("%""u", &grant_ref)!=1)) {
        printf("Scanf error");
        clean(0);
    }
    if(xen_shm_pipe_connect(xpipe,page_count,dist_domid, grant_ref)) {
        perror("Pipe connect");
        clean(0);
    }
    printf("Connected successfully !\n");
    signal(2, clean);
}

canonical_original_code:
void init_pipe_reader() {
    unsigned int local_domid;
    unsigned int dist_domid;
    unsigned int grant_ref;
    printf("\nInit: Reader - Receiver\n");
    if(xen_shm_pipe_init(&xpipe, xen_shm_pipe_mod_read, xen_shm_pipe_conv_writer_offers)) {
        perror("Pipe init");
        exit(-1);
    }
    pipe_used = 1;
    if(xen_shm_pipe_getdomid(xpipe, &local_domid)) {
        perror("Pipe get domid");
        clean(0);
    }
    printf("RECEIVER domain id: %""u""\n", local_domid);
    printf("Distant domain id: ");
    if((scanf("%""u", &dist_domid)!=1)) {
        printf("Scanf error");
        clean(0);
    }
    printf("Offerer's grant ref: ");
    if((scanf("%""u", &grant_ref)!=1)) {
        printf("Scanf error");
        clean(0);
    }
    if(xen_shm_pipe_connect(xpipe,page_count,dist_domid, grant_ref)) {
        perror("Pipe connect");
        clean(0);
    }
    printf("Connected successfully !\n");
    signal(2, clean);
}


decompiled_code:
__sighandler_t init_pipe_writer()
{
unsigned int v1; // [rsp+4h] [rbp-14h] BYREF
unsigned int v2; // [rsp+8h] [rbp-10h] BYREF
unsigned int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

puts("Init: Writer - Offerer");
if ( (unsigned int)xen_shm_pipe_init(&xpipe, 0LL, 0LL) )
{
perror("Pipe init");
exit(-1);
}
printf("Distant domain id: ");
if ( (unsigned int)_isoc99_scanf("%u", &v2) != 1 )
{
printf("Scanf error");
clean(0);
}
if ( (unsigned int)xen_shm_pipe_offers(xpipe, (unsigned __int8)page_count, v2, v3, &v1) )
{
perror("Pipe get domid");
clean(0);
}
printf("Local domain id: %u\n", v3[0]);
printf("Grant reference id: %u\n", v1);
puts("Will now wait for at most 30 seconds");
if ( (unsigned int)xen_shm_pipe_wait(xpipe, 30000LL) )
{
perror("Pipe wait");
clean(0);
}
puts("Connected successfully !");
return signal(2, (__sighandler_t)clean);
}

canonical_decompiled_code:
__sighandler_t func5()
{
unsigned int v1; // [rsp+4h] [rbp-14h] BYREF
unsigned int v2; // [rsp+8h] [rbp-10h] BYREF
unsigned int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

puts("Init: Writer - Offerer");
if ( (unsigned int)xen_shm_pipe_init(&xpipe, 0LL, 0LL) )
{
perror("Pipe init");
exit(-1);
}
printf("Distant domain id: ");
if ( (unsigned int)_isoc99_scanf("%u", &v2) != 1 )
{
printf("Scanf error");
func0(0);
}
if ( (unsigned int)xen_shm_pipe_offers(xpipe, (unsigned __int8)page_count, v2, v3, &v1) )
{
perror("Pipe get domid");
func0(0);
}
printf("Local domain id: %u\n", v3[0]);
printf("Grant reference id: %u\n", v1);
puts("Will now wait for at most 30 seconds");
if ( (unsigned int)xen_shm_pipe_wait(xpipe, 30000LL) )
{
perror("Pipe wait");
func0(0);
}
puts("Connected successfully !");
return signal(2, (__sighandler_t)clean);
}

original_code:
void init_pipe_writer(void) {
    uint32_t local_domid;
    uint32_t dist_domid;
    uint32_t grant_ref;
    printf("Init: Writer - Offerer\n");
    if(xen_shm_pipe_init(&xpipe, xen_shm_pipe_mod_write, xen_shm_pipe_conv_writer_offers)) {
        perror("Pipe init");
        exit(-1);
    }
    pipe_used = 1;
    printf("Distant domain id: ");
    if((scanf("%""u", &dist_domid)!=1)) {
        printf("Scanf error");
        clean(0);
    }
    if(xen_shm_pipe_offers(xpipe, page_count, dist_domid, &local_domid, &grant_ref)) {
        perror("Pipe get domid");
        clean(0);
    }
    printf("Local domain id: %""u""\n", local_domid);
    printf("Grant reference id: %""u""\n", grant_ref);
    printf("Will now wait for at most 30 seconds\n");
    if(xen_shm_pipe_wait(xpipe, 30*1000)) {
        perror("Pipe wait");
        clean(0);
    }
    printf("Connected successfully !\n");
    signal(2, clean);
}

canonical_original_code:
void init_pipe_writer() {
    unsigned int local_domid;
    unsigned int dist_domid;
    unsigned int grant_ref;
    printf("Init: Writer - Offerer\n");
    if(xen_shm_pipe_init(&xpipe, xen_shm_pipe_mod_write, xen_shm_pipe_conv_writer_offers)) {
        perror("Pipe init");
        exit(-1);
    }
    pipe_used = 1;
    printf("Distant domain id: ");
    if((scanf("%""u", &dist_domid)!=1)) {
        printf("Scanf error");
        clean(0);
    }
    if(xen_shm_pipe_offers(xpipe, page_count, dist_domid, &local_domid, &grant_ref)) {
        perror("Pipe get domid");
        clean(0);
    }
    printf("Local domain id: %""u""\n", local_domid);
    printf("Grant reference id: %""u""\n", grant_ref);
    printf("Will now wait for at most 30 seconds\n");
    if(xen_shm_pipe_wait(xpipe, 30*1000)) {
        perror("Pipe wait");
        clean(0);
    }
    printf("Connected successfully !\n");
    signal(2, clean);
}


decompiled_code:
int __fastcall read_pc_and_size(__int64 a1, __int64 a2)
{
byte_count = 0LL;
if ( !(unsigned int)_isoc99_sscanf(*(_QWORD *)(a2 + 16), "%hhu", &page_count) )
{
puts("Invalid page count");
usage();
}
printf("Page count: %u\n", (unsigned __int8)page_count);
if ( !(unsigned int)_isoc99_sscanf(*(_QWORD *)(a2 + 24), "%u", &buffer_size) )
{
puts("Invalid size");
usage();
}
return printf("Size: %u\n", (unsigned int)buffer_size);
}

canonical_decompiled_code:
int __fastcall func6(__int64 a1, __int64 a2)
{
byte_count = 0LL;
if ( !(unsigned int)_isoc99_sscanf(*(_QWORD *)(a2 + 16), "%hhu", &page_count) )
{
puts("Invalid page count");
func1();
}
printf("Page count: %u\n", (unsigned __int8)page_count);
if ( !(unsigned int)_isoc99_sscanf(*(_QWORD *)(a2 + 24), "%u", &buffer_size) )
{
puts("Invalid size");
func1();
}
return printf("Size: %u\n", (unsigned int)buffer_size);
}

original_code:
void read_pc_and_size(int argc, char **argv) {
    byte_count = 0;
    if(sscanf(argv[2], "%""hhu", &page_count) ) {
        printf("Page count: %""u""\n", page_count);
    } else {
        printf("Invalid page count\n");
        usage();
    }
    if(sscanf(argv[3], "%""u", &buffer_size) ) {
        printf("Size: %""u""\n", buffer_size);
    } else {
        printf("Invalid size\n");
        usage();
    }
}

variable_types: argc int

variable_types:
argv
char **


decompiled_code:
void __fastcall __noreturn pipe_reader(__int64 a1, __int64 a2)
{
if ( (int)a1 <= 3 )
usage();
read_pc_and_size(a1, a2);
init_pipe_reader();
pipe_read();
}

canonical_decompiled_code:
void __fastcall __noreturn func7(__int64 a1, __int64 a2)
{
if ( (int)a1 <= 3 )
func1();
func6(a1, a2);
func4();
func2();
}

original_code:
void pipe_reader(int argc, char **argv) {
    if(argc < 4) {
        usage();
    }
    read_pc_and_size(argc, argv);
    init_pipe_reader();
    pipe_read();
}


decompiled_code:
void __fastcall __noreturn pipe_writer(__int64 a1, __int64 a2)
{
if ( (int)a1 <= 4 )
usage();
read_pc_and_size(a1, a2);
if ( (unsigned int)_isoc99_sscanf(*(_QWORD *)(a2 + 32), "%u", &iterations) )
{
printf("Iterations: %u\n", (unsigned int)iterations);
init_pipe_writer();
pipe_write();
}
puts("Invalid size");
usage();
}

canonical_decompiled_code:
void __fastcall __noreturn func8(__int64 a1, __int64 a2)
{
if ( (int)a1 <= 4 )
func1();
func6(a1, a2);
if ( (unsigned int)_isoc99_sscanf(*(_QWORD *)(a2 + 32), "%u", &iterations) )
{
printf("Iterations: %u\n", (unsigned int)iterations);
func5();
func3();
}
puts("Invalid size");
func1();
}

original_code:
void pipe_writer(int argc, char **argv) {
    if(argc < 5) {
        usage();
    }
    read_pc_and_size(argc, argv);
    if(sscanf(argv[4], "%""u", &iterations) ) {
        printf("Iterations: %""u""\n", iterations);
    } else {
        printf("Invalid size\n");
        usage();
    }
    init_pipe_writer();
    pipe_write();
}


decompiled_code:
void __fastcall __noreturn pipe_ramwriter(int a1, __int64 a2)
{
unsigned int v2; // er13
size_t v3; // rbp
_BYTE *v4; // rbx
_QWORD *v5; // rbp
_BYTE *v6; // rax
int v7; // er9
unsigned int v8; // ecx
__int64 v9; // r10
unsigned int v10; // er8
unsigned int v11; // er8
__int64 v12; // rdi
int v13; // esi
__int64 v14; // rax
__int64 v15; // rax

if ( a1 <= 3 )
usage();
if ( (unsigned int)_isoc99_sscanf(*(_QWORD *)(a2 + 16), "%u", &buffer_size) )
{
printf("Size: %u\n", (unsigned int)buffer_size);
if ( !(unsigned int)_isoc99_sscanf(*(_QWORD *)(a2 + 24), "%u", &iterations) )
{
puts("Invalid size");
usage();
}
printf("Iterations: %u\n", (unsigned int)iterations);
v2 = buffer_size;
v3 = (unsigned int)buffer_size;
v4 = malloc((unsigned int)buffer_size);
if ( v4 )
{
v5 = malloc(v3);
if ( v5 )
{
if ( v2 )
{
v6 = v4;
do
*v6++ = 117;
while ( v6 != &v4[v2] );
}
byte_count = 0LL;
gettimeofday(&start, 0LL);
v7 = iterations;
if ( iterations )
{
v8 = buffer_size;
v9 = (unsigned int)buffer_size;
v10 = 0;
if ( v2 > 7 )
v10 = v2 >> 3;
v11 = 8 * v10;
v12 = 0LL;
v13 = 0;
do
{
v14 = 0LL;
if ( v2 > 7 )
{
do
{
*(_QWORD *)&v4[8 * v14] = v5[v14];
++v14;
}
while ( v2 >> 3 > (unsigned int)v14 );
}
if ( v8 > v11 )
{
v15 = v11;
do
{
*((_BYTE *)v5 + v15) = v4[v15];
++v15;
}
while ( v8 > (unsigned int)v15 );
}
v12 += v9;
++v13;
}
while ( v7 != v13 );
byte_count = v12;
}
clean(0);
}
puts("Memory error");
clean(0);
}
puts("Memory error");
clean(0);
}
puts("Invalid size");
usage();
}

canonical_decompiled_code:
void __fastcall __noreturn func9(int a1, __int64 a2)
{
unsigned int v2; // er13
size_t v3; // rbp
_BYTE *v4; // rbx
_QWORD *v5; // rbp
_BYTE *v6; // rax
int v7; // er9
unsigned int v8; // ecx
__int64 v9; // r10
unsigned int v10; // er8
unsigned int v11; // er8
__int64 v12; // rdi
int v13; // esi
__int64 v14; // rax
__int64 v15; // rax

if ( a1 <= 3 )
func1();
if ( (unsigned int)_isoc99_sscanf(*(_QWORD *)(a2 + 16), "%u", &buffer_size) )
{
printf("Size: %u\n", (unsigned int)buffer_size);
if ( !(unsigned int)_isoc99_sscanf(*(_QWORD *)(a2 + 24), "%u", &iterations) )
{
puts("Invalid size");
func1();
}
printf("Iterations: %u\n", (unsigned int)iterations);
v2 = buffer_size;
v3 = (unsigned int)buffer_size;
v4 = malloc((unsigned int)buffer_size);
if ( v4 )
{
v5 = malloc(v3);
if ( v5 )
{
if ( v2 )
{
v6 = v4;
do
*v6++ = 117;
while ( v6 != &v4[v2] );
}
byte_count = 0LL;
gettimeofday(&start, 0LL);
v7 = iterations;
if ( iterations )
{
v8 = buffer_size;
v9 = (unsigned int)buffer_size;
v10 = 0;
if ( v2 > 7 )
v10 = v2 >> 3;
v11 = 8 * v10;
v12 = 0LL;
v13 = 0;
do
{
v14 = 0LL;
if ( v2 > 7 )
{
do
{
*(_QWORD *)&v4[8 * v14] = v5[v14];
++v14;
}
while ( v2 >> 3 > (unsigned int)v14 );
}
if ( v8 > v11 )
{
v15 = v11;
do
{
*((_BYTE *)v5 + v15) = v4[v15];
++v15;
}
while ( v8 > (unsigned int)v15 );
}
v12 += v9;
++v13;
}
while ( v7 != v13 );
byte_count = v12;
}
func0(0);
}
puts("Memory error");
func0(0);
}
puts("Memory error");
func0(0);
}
puts("Invalid size");
func1();
}

original_code:
void pipe_ramwriter(int argc, char **argv) {
    uint8_t* buffer;
    uint8_t* buffer_2;
    uint32_t i;
    uint32_t j;
    uint32_t aligned_iter;
    if(argc < 4) {
        usage();
    }
    if(sscanf(argv[2], "%""u", &buffer_size) ) {
        printf("Size: %""u""\n", buffer_size);
    } else {
        printf("Invalid size\n");
        usage();
    }
    if(sscanf(argv[3], "%""u", &iterations) ) {
        printf("Iterations: %""u""\n", iterations);
    } else {
        printf("Invalid size\n");
        usage();
    }
    if((buffer = malloc(sizeof(uint8_t)*buffer_size))== ((void *)0)) {
        printf("Memory error\n");
        clean(0);
    }
    if((buffer_2 = malloc(sizeof(uint8_t)*buffer_size))== ((void *)0)) {
        printf("Memory error\n");
        clean(0);
    }
    for(i = 0; i<buffer_size; i++) {
        buffer[i] = 'u';
    }
    aligned_iter = buffer_size/8;
    byte_count = 0;
    gettimeofday(&start , ((void *)0));
    for(i=0; i<iterations; i++) {
        for(j=0; j<aligned_iter ; j++) {
            *((uint64_t*) (&buffer[8*j])) = *((uint64_t*) (&buffer_2[8*j]));
        }
        j = j*8;
        for(; j<buffer_size; j++) {
            buffer_2[j] = buffer[j];
        }
        byte_count+=buffer_size;
    }
    clean(0);
}

canonical_original_code:
void pipe_ramwriter(int argc, char **argv) {
    unsigned char *buffer;
    unsigned char *buffer_2;
    unsigned int i;
    unsigned int j;
    unsigned int aligned_iter;
    if(argc < 4) {
        usage();
    }
    if(sscanf(argv[2], "%""u", &buffer_size) ) {
        printf("Size: %""u""\n", buffer_size);
    } else {
        printf("Invalid size\n");
        usage();
    }
    if(sscanf(argv[3], "%""u", &iterations) ) {
        printf("Iterations: %""u""\n", iterations);
    } else {
        printf("Invalid size\n");
        usage();
    }
    if((buffer = malloc(sizeof(unsigned char)*buffer_size))== ((void *)0)) {
        printf("Memory error\n");
        clean(0);
    }
    if((buffer_2 = malloc(sizeof(unsigned char)*buffer_size))== ((void *)0)) {
        printf("Memory error\n");
        clean(0);
    }
    for(i = 0; i<buffer_size; i++) {
        buffer[i] = 'u';
    }
    aligned_iter = buffer_size/8;
    byte_count = 0;
    gettimeofday(&start , ((void *)0));
    for(i=0; i<iterations; i++) {
        for(j=0; j<aligned_iter ; j++) {
            *((unsigned long *) (&buffer[8*j])) = *((unsigned long *) (&buffer_2[8*j]));
        }
        j = j*8;
        for(; j<buffer_size; j++) {
            buffer_2[j] = buffer[j];
        }
        byte_count+=buffer_size;
    }
    clean(0);
}

variable_types:
j
unsigned int


clean

decompiled_code:
void __fastcall __noreturn clean(int a1)
{
__suseconds_t v1; // rdx
double v2; // xmm1_8
double v3; // xmm0_8
__int64 v4[5]; // [rsp+0h] [rbp-38h] BYREF
unsigned __int8 v5; // [rsp+28h] [rbp-10h]

gettimeofday(&stop, 0LL);
putchar(10);
if ( a1 >= 0 )
printf("Signal received: %i\n", (unsigned int)a1);
printf("Byte count : %lu\n", byte_count);
if ( byte_count )
{
v1 = stop.tv_usec + 1000000 * stop.tv_sec - (start.tv_usec + 1000000 * start.tv_sec);
if ( v1 < 0 )
v2 = (double)(int)(v1 & 1 | ((unsigned __int64)v1 >> 1)) + (double)(int)(v1 & 1 | ((unsigned __int64)v1 >> 1));
else
v2 = (double)(int)v1;
if ( byte_count < 0 )
v3 = (double)(int)(byte_count & 1 | ((unsigned __int64)byte_count >> 1))
+ (double)(int)(byte_count & 1 | ((unsigned __int64)byte_count >> 1));
else
v3 = (double)(int)byte_count;
printf("Time lapse : %f seconds\n", v2 / 1000000.0);
printf("Bandwidth : %f MBps = %f Mbps\n", v3 / v2, v3 / v2 * 8.0);
}
xen_shm_pipe_get_stats(v4, xpipe);
printf("\nWait calls : %lu\n", v4[0]);
printf("Signal calls : %lu\n", v4[2]);
printf("Write calls : %lu\n", v4[4]);
printf("Read calls : %lu\n", v4[3]);
printf("Waiting : %u\n", v5);
printf("Epipe Prone : %lu\n", v4[1]);
puts("Now closing the pipe");
xen_shm_pipe_free(xpipe);
exit(0);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(int a1)
{
__suseconds_t v1; // rdx
double v2; // xmm1_8
double v3; // xmm0_8
__int64 v4[5]; // [rsp+0h] [rbp-38h] BYREF
unsigned __int8 v5; // [rsp+28h] [rbp-10h]

gettimeofday(&stop, 0LL);
putchar(10);
if ( a1 >= 0 )
printf("Signal received: %i\n", (unsigned int)a1);
printf("Byte count : %lu\n", byte_count);
if ( byte_count )
{
v1 = stop.tv_usec + 1000000 * stop.tv_sec - (start.tv_usec + 1000000 * start.tv_sec);
if ( v1 < 0 )
v2 = (double)(int)(v1 & 1 | ((unsigned __int64)v1 >> 1)) + (double)(int)(v1 & 1 | ((unsigned __int64)v1 >> 1));
else
v2 = (double)(int)v1;
if ( byte_count < 0 )
v3 = (double)(int)(byte_count & 1 | ((unsigned __int64)byte_count >> 1))
+ (double)(int)(byte_count & 1 | ((unsigned __int64)byte_count >> 1));
else
v3 = (double)(int)byte_count;
printf("Time lapse : %f seconds\n", v2 / 1000000.0);
printf("Bandwidth : %f MBps = %f Mbps\n", v3 / v2, v3 / v2 * 8.0);
}
xen_shm_pipe_get_stats(v4, xpipe);
printf("\nWait calls : %lu\n", v4[0]);
printf("Signal calls : %lu\n", v4[2]);
printf("Write calls : %lu\n", v4[4]);
printf("Read calls : %lu\n", v4[3]);
printf("Waiting : %u\n", v5);
printf("Epipe Prone : %lu\n", v4[1]);
puts("Now closing the pipe");
xen_shm_pipe_free(xpipe);
exit(0);
}

original_code:
static void
clean(int sig)
{
    uint64_t usec_interval;
    double seconds;
    double bandwidth;
    struct xen_shm_pipe_stats stats;
    gettimeofday(&stop , ((void *)0));
    printf("\n");
    if(sig >= 0) {
        printf("Signal received: %i\n", sig);
    }
    printf("Byte count : %""l" "u""\n", byte_count);
    if(byte_count) {
        usec_interval = (uint64_t) ((stop.tv_sec*1000000 + stop.tv_usec) - (start.tv_sec*1000000 + start.tv_usec));
        seconds = ((double) usec_interval)/1000000.0;
        bandwidth = ((double) byte_count)/((double) usec_interval);
        printf("Time lapse : %f seconds\n", seconds);
        printf("Bandwidth  : %f MBps  =   %f Mbps\n", bandwidth, bandwidth*8);
    }
    stats = xen_shm_pipe_get_stats(xpipe);
    printf("\nWait calls   : %""l" "u""\n", stats.ioctl_count_await);
    printf("Signal calls : %""l" "u""\n", stats.ioctl_count_ssig);
    printf("Write calls  : %""l" "u""\n", stats.write_count);
    printf("Read calls   : %""l" "u""\n", stats.read_count);
    printf("Waiting      : %""u""\n", stats.waiting);
    printf("Epipe Prone  : %""l" "u""\n", stats.ioctl_count_epipe_prone);
    printf("Now closing the pipe\n");
    xen_shm_pipe_free(xpipe);
    exit(0);
}

canonical_original_code:
static void clean(int sig)
{
    unsigned long usec_interval;
    double seconds;
    double bandwidth;
    struct xen_shm_pipe_stats stats;
    gettimeofday(&stop , ((void *)0));
    printf("\n");
    if(sig >= 0) {
        printf("Signal received: %i\n", sig);
    }
    printf("Byte count : %""l" "u""\n", byte_count);
    if(byte_count) {
        usec_interval = (unsigned long) ((stop.tv_sec*1000000 + stop.tv_usec) - (start.tv_sec*1000000 + start.tv_usec));
        seconds = ((double) usec_interval)/1000000.0;
        bandwidth = ((double) byte_count)/((double) usec_interval);
        printf("Time lapse : %f seconds\n", seconds);
        printf("Bandwidth  : %f MBps  =   %f Mbps\n", bandwidth, bandwidth*8);
    }
    stats = xen_shm_pipe_get_stats(xpipe);
    printf("\nWait calls   : %""l" "u""\n", stats.ioctl_count_await);
    printf("Signal calls : %""l" "u""\n", stats.ioctl_count_ssig);
    printf("Write calls  : %""l" "u""\n", stats.write_count);
    printf("Read calls   : %""l" "u""\n", stats.read_count);
    printf("Waiting      : %""u""\n", stats.waiting);
    printf("Epipe Prone  : %""l" "u""\n", stats.ioctl_count_epipe_prone);
    printf("Now closing the pipe\n");
    xen_shm_pipe_free(xpipe);
    exit(0);
}

variable_types: sig int

variable_types: seconds double

variable_types: bandwidth double

variable_types: struct xen_shm_pipe_stats { unsigned long ioctl_count_await; unsigned long ioctl_count_epipe_prone; unsigned long ioctl_count_ssig; unsigned long read_count; unsigned long write_count; unsigned char waiting; }


usage

decompiled_code:
void __noreturn usage()
{
puts("Usage: reader <page_count> <buffer_size>");
puts(" OR writer <page_count> <message_size> <iterations>");
puts(" OR ram_writer <message_size> <iterations>");
exit(-1);
}

canonical_decompiled_code:
void __noreturn func1()
{
puts("Usage: reader <page_count> <buffer_size>");
puts(" OR writer <page_count> <message_size> <iterations>");
puts(" OR ram_writer <message_size> <iterations>");
exit(-1);
}

original_code:
void
usage(void)
{
    printf("Usage: reader <page_count> <buffer_size>\n");
    printf("  OR   writer <page_count> <message_size> <iterations>\n");
    printf("  OR   ram_writer <message_size> <iterations>\n");
    exit(-1);
}

canonical_original_code:
void usage()
{
    printf("Usage: reader <page_count> <buffer_size>\n");
    printf("  OR   writer <page_count> <message_size> <iterations>\n");
    printf("  OR   ram_writer <message_size> <iterations>\n");
    exit(-1);
}


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
const char *v3; // r12
__int64 v4; // rdx

if ( argc > 1 )
{
v3 = argv[1];
if ( strcmp(v3, "reader") )
{
if ( strcmp(v3, "writer") )
{
if ( !strcmp(v3, "ram_writer") )
pipe_ramwriter(argc, (__int64)argv);
usage(v3, "ram_writer", v4);
}
pipe_writer((unsigned int)argc, (__int64)argv);
}
pipe_reader((unsigned int)argc, (__int64)argv);
}
usage(argc, argv, envp);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
const char *v3; // r12
__int64 v4; // rdx

if ( argc > 1 )
{
v3 = argv[1];
if ( strcmp(v3, "reader") )
{
if ( strcmp(v3, "writer") )
{
if ( !strcmp(v3, "ram_writer") )
func9(argc, (__int64)argv);
func1(v3, "ram_writer", v4);
}
func8((unsigned int)argc, (__int64)argv);
}
func7((unsigned int)argc, (__int64)argv);
}
func1(argc, argv, envp);
}

original_code:
int main(int argc, char **argv) {
    if(argc < 2) {
        usage();
    }
    pipe_used = 0;
    if(strcmp(argv[1], "reader") == 0) {
        pipe_reader(argc, argv);
    } else if(strcmp(argv[1], "writer")==0) {
        pipe_writer(argc, argv);
    } else if(strcmp(argv[1], "ram_writer")==0) {
        pipe_ramwriter(argc, argv);
    }
    usage();
    return -1;
}


server

decompiled_code:
__int64 __fastcall server(int a1, _QWORD *a2)
{
__int64 result; // rax
__int64 v3; // [rsp+0h] [rbp-28h] BYREF
char v4; // [rsp+8h] [rbp-20h]
unsigned int v5; // [rsp+18h] [rbp-10h] BYREF
unsigned __int8 v6; // [rsp+1Dh] [rbp-Bh] BYREF
unsigned __int16 v7; // [rsp+1Eh] [rbp-Ah] BYREF

if ( a1 > 5 )
{
puts("Too many arguments");
usage();
result = 0xFFFFFFFFLL;
}
else if ( a1 <= 4 )
{
puts("Not enough arguments");
usage();
result = 0xFFFFFFFFLL;
}
else if ( (unsigned int)_isoc99_sscanf(a2[2], "%hu", &v7) == 1 )
{
if ( (unsigned int)_isoc99_sscanf(a2[3], "%hhu", &v6) == 1 )
{
if ( (unsigned int)_isoc99_sscanf(a2[4], "%u", &v5) == 1 )
{
v3 = v5;
v4 = 1;
result = run_server(v7, v6, &xen_shm_handler_receiver, &v3);
}
else
{
puts("Bad page count");
usage();
result = 0xFFFFFFFFLL;
}
}
else
{
puts("Bad page number");
usage();
result = 0xFFFFFFFFLL;
}
}
else
{
puts("Bad port");
usage();
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, _QWORD *a2)
{
__int64 result; // rax
__int64 v3; // [rsp+0h] [rbp-28h] BYREF
char v4; // [rsp+8h] [rbp-20h]
unsigned int v5; // [rsp+18h] [rbp-10h] BYREF
unsigned __int8 v6; // [rsp+1Dh] [rbp-Bh] BYREF
unsigned __int16 v7; // [rsp+1Eh] [rbp-Ah] BYREF

if ( a1 > 5 )
{
puts("Too many arguments");
func0();
result = 0xFFFFFFFFLL;
}
else if ( a1 <= 4 )
{
puts("Not enough arguments");
func0();
result = 0xFFFFFFFFLL;
}
else if ( (unsigned int)_isoc99_sscanf(a2[2], "%hu", &v7) == 1 )
{
if ( (unsigned int)_isoc99_sscanf(a2[3], "%hhu", &v6) == 1 )
{
if ( (unsigned int)_isoc99_sscanf(a2[4], "%u", &v5) == 1 )
{
v3 = v5;
v4 = 1;
result = run_server(v7, v6, &xen_shm_handler_receiver, &v3);
}
else
{
puts("Bad page count");
func0();
result = 0xFFFFFFFFLL;
}
}
else
{
puts("Bad page number");
func0();
result = 0xFFFFFFFFLL;
}
}
else
{
puts("Bad port");
func0();
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int server(int argc, char **argv) {
    in_port_t port;
    uint8_t page_count;
    uint32_t buffer_size;
    struct xen_shm_handler_transfert tr;
    if (argc > 5) {
        printf("Too many arguments\n");
        usage();
        return -1;
    }
    if (argc < 5) {
        printf("Not enough arguments\n");
        usage();
        return -1;
    }
    if (sscanf(argv[2], "%""hu", &port) != 1) {
        printf("Bad port\n");
        usage();
        return -1;
    }
    if (sscanf(argv[3], "%""hhu", &page_count) != 1) {
        printf("Bad page number\n");
        usage();
        return -1;
    }
    if (sscanf(argv[4], "%""u", &buffer_size) != 1) {
        printf("Bad page count\n");
        usage();
        return -1;
    }
    tr.buffer_len = (size_t) buffer_size;
    tr.print_info = 1;
    return run_server(port, page_count, xen_shm_handler_receiver, &tr);
}

canonical_original_code:
int server(int argc, char **argv) {
    unsigned short port;
    unsigned char page_count;
    unsigned int buffer_size;
    struct xen_shm_handler_transfert tr;
    if (argc > 5) {
        printf("Too many arguments\n");
        usage();
        return -1;
    }
    if (argc < 5) {
        printf("Not enough arguments\n");
        usage();
        return -1;
    }
    if (sscanf(argv[2], "%""hu", &port) != 1) {
        printf("Bad port\n");
        usage();
        return -1;
    }
    if (sscanf(argv[3], "%""hhu", &page_count) != 1) {
        printf("Bad page number\n");
        usage();
        return -1;
    }
    if (sscanf(argv[4], "%""u", &buffer_size) != 1) {
        printf("Bad page count\n");
        usage();
        return -1;
    }
    tr.buffer_len = (unsigned long) buffer_size;
    tr.print_info = 1;
    return run_server(port, page_count, xen_shm_handler_receiver, &tr);
}

variable_types:
port
unsigned short

variable_types: struct xen_shm_handler_transfert { unsigned long buffer_len; unsigned char print_info; }