createListenSocket

decompiled_code:
__int64 __fastcall createListenSocket(int a1, int a2, __int64 a3)
{
unsigned int v3; // ebp
int v4; // eax
struct addrinfo *i; // rbx
int v6; // eax
const char *v8; // rax
char s[10]; // [rsp+Eh] [rbp-5Ah] BYREF
struct addrinfo *pai; // [rsp+18h] [rbp-50h] BYREF
struct addrinfo req; // [rsp+20h] [rbp-48h] BYREF

if ( (unsigned int)(a3 - 1) > 0xF423E )
_assert_fail("port > 0 && port <= 999999", "../sockhelp.c", 0x5Au, "createListenSocket");
req.ai_protocol = 0;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
req.ai_family = a1;
req.ai_socktype = a2;
req.ai_flags = 1;
sprintf(s, "%d", a3);
v4 = getaddrinfo(0LL, s, &req, &pai);
if ( v4 )
{
v8 = gai_strerror(v4);
fprintf(stderr, "Error occured in getaddrinfo: %s\n", v8);
}
else
{
for ( i = pai; i; i = i->ai_next )
{
v6 = socket(i->ai_family, i->ai_socktype, i->ai_protocol);
v3 = v6;
if ( v6 != -1 )
{
if ( bind(v6, i->ai_addr, i->ai_addrlen) != -1 )
break;
close(v3);
}
}
freeaddrinfo(pai);
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1, int a2, __int64 a3)
{
unsigned int v3; // ebp
int v4; // eax
struct addrinfo *i; // rbx
int v6; // eax
const char *v8; // rax
char s[10]; // [rsp+Eh] [rbp-5Ah] BYREF
struct addrinfo *pai; // [rsp+18h] [rbp-50h] BYREF
struct addrinfo req; // [rsp+20h] [rbp-48h] BYREF

if ( (unsigned int)(a3 - 1) > 0xF423E )
_assert_fail("port > 0 && port <= 999999", "../sockhelp.c", 0x5Au, "createListenSocket");
req.ai_protocol = 0;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
req.ai_family = a1;
req.ai_socktype = a2;
req.ai_flags = 1;
sprintf(s, "%d", a3);
v4 = getaddrinfo(0LL, s, &req, &pai);
if ( v4 )
{
v8 = gai_strerror(v4);
fprintf(stderr, "Error occured in getaddrinfo: %s\n", v8);
}
else
{
for ( i = pai; i; i = i->ai_next )
{
v6 = socket(i->ai_family, i->ai_socktype, i->ai_protocol);
v3 = v6;
if ( v6 != -1 )
{
if ( bind(v6, i->ai_addr, i->ai_addrlen) != -1 )
break;
close(v3);
}
}
freeaddrinfo(pai);
}
return v3;
}

original_code:
int createListenSocket( int fam, int type, unsigned int port )
{
 struct addrinfo hints, *local, *it;
 char numString[10];
 int sockfd;
 int success;
 ((void) sizeof ((port > 0 && port <= 999999) ? 1 : 0), __extension__ ({ if (port > 0 && port <= 999999) ; else __assert_fail ("port > 0 && port <= 999999", "../sockhelp.c", 90, __extension__ __PRETTY_FUNCTION__); }));
 memset( &hints, 0, sizeof( hints ) );
 hints.ai_family = fam;
 hints.ai_socktype = type;
 hints.ai_flags = 0x0001;
 sprintf( numString, "%d", port );
 if( ( success = getaddrinfo( ((void *)0), numString, &hints, &local ) ) == 0 )
 {
  for( it = local; it != ((void *)0); it = it->ai_next )
  {
   if( ( sockfd = socket( it->ai_family, it->ai_socktype, it->ai_protocol ) ) != -1 )
   {
    if( bind( sockfd, it->ai_addr, it->ai_addrlen ) != -1 )
    {
     break;
    }
    else
    {
     close( sockfd );
    }
   }
  }
  freeaddrinfo( local );
 }
 else
 {
  fprintf( stderr, "Error occured in getaddrinfo: %s\n", gai_strerror( success ) );
 }
 return sockfd;
}

canonical_original_code:
int createListenSocket(int fam, int type, unsigned int port)
{
 struct addrinfo hints; struct addrinfo *local; struct addrinfo *it;
 char numString[10];
 int sockfd;
 int success;
 ((void) sizeof ((port > 0 && port <= 999999) ? 1 : 0), __extension__ ({ if (port > 0 && port <= 999999) ; else __assert_fail ("port > 0 && port <= 999999", "../sockhelp.c", 90, __extension__ __PRETTY_FUNCTION__); }));
 memset( &hints, 0, sizeof( hints ) );
 hints.ai_family = fam;
 hints.ai_socktype = type;
 hints.ai_flags = 0x0001;
 sprintf( numString, "%d", port );
 if( ( success = getaddrinfo( ((void *)0), numString, &hints, &local ) ) == 0 )
 {
  for( it = local; it != ((void *)0); it = it->ai_next )
  {
   if( ( sockfd = socket( it->ai_family, it->ai_socktype, it->ai_protocol ) ) != -1 )
   {
    if( bind( sockfd, it->ai_addr, it->ai_addrlen ) != -1 )
    {
     break;
    }
    else
    {
     close( sockfd );
    }
   }
  }
  freeaddrinfo( local );
 }
 else
 {
  fprintf( stderr, "Error occured in getaddrinfo: %s\n", gai_strerror( success ) );
 }
 return sockfd;
}

variable_types:
port
unsigned int

variable_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ai_addr; char *ai_canonname; struct addrinfo *ai_next; } *

variable_types:
numString
char [10]

variable_types: success int

user_defined_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr *ai_addr; char *ai_canonname; struct addrinfo *ai_next; }


createBroadcastSocket

repo: timpeskett/nmuw

decompiled_code:
__int64 createBroadcastSocket()
{
int v0; // eax
unsigned int v1; // ebx
int optval[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v0 = socket(2, 2, 0);
v1 = v0;
if ( v0 != -1 )
{
optval[0] = 1;
if ( setsockopt(v0, 1, 6, optval, 4u) == -1 )
{
close(v1);
v1 = -1;
}
}
return v1;
}

canonical_decompiled_code:
__int64 func6()
{
int v0; // eax
unsigned int v1; // ebx
int optval[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v0 = socket(2, 2, 0);
v1 = v0;
if ( v0 != -1 )
{
optval[0] = 1;
if ( setsockopt(v0, 1, 6, optval, 4u) == -1 )
{
close(v1);
v1 = -1;
}
}
return v1;
}

original_code:
int createBroadcastSocket( void )
{
 int sockfd, bcast;
 if( ( sockfd = socket( 2, SOCK_DGRAM, 0 ) ) == -1 )
 {
  return -1;
 }
 bcast = 1;
 if( setsockopt( sockfd, 1, 6, &bcast, sizeof( bcast ) ) == -1 )
 {
  close( sockfd );
  return -1;
 }
 return sockfd;
}

canonical_original_code:
int createBroadcastSocket()
{
 int sockfd; int bcast;
 if( ( sockfd = socket( 2, SOCK_DGRAM, 0 ) ) == -1 )
 {
  return -1;
 }
 bcast = 1;
 if( setsockopt( sockfd, 1, 6, &bcast, sizeof( bcast ) ) == -1 )
 {
  close( sockfd );
  return -1;
 }
 return sockfd;
}

variable_types: sockfd int

variable_types: bcast int

return_type: int


sendBroadcast

decompiled_code:
__int64 __fastcall sendBroadcast(int fd, __int16 a2)
{
char buf; // [rsp+Fh] [rbp-19h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-18h] BYREF

buf = 1;
addr.sa_family = 2;
*(_WORD *)addr.sa_data = _bswap_16(a2);
inet_pton(2, "255.255.255.255", &addr.sa_data[2]);
*(_QWORD *)&addr.sa_data[6] = 0LL;
return (unsigned int)-(sendto(fd, &buf, 1uLL, 0, &addr, 0x10u) != 1);
}

canonical_decompiled_code:
__int64 __fastcall func7(int fd, __int16 a2)
{
char buf; // [rsp+Fh] [rbp-19h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-18h] BYREF

buf = 1;
addr.sa_family = 2;
*(_WORD *)addr.sa_data = func0(a2);
inet_pton(2, "255.255.255.255", &addr.sa_data[2]);
*(_QWORD *)&addr.sa_data[6] = 0LL;
return (unsigned int)-(sendto(fd, &buf, 1uLL, 0, &addr, 0x10u) != 1);
}

original_code:
int sendBroadcast( int sockfd, unsigned int port )
{
 struct sockaddr_in bcastaddr;
 unsigned char data = 1;
 socklen_t len;
 bcastaddr.sin_family = 2;
 bcastaddr.sin_port = htons( port );
 inet_pton( bcastaddr.sin_family, "255.255.255.255", &bcastaddr.sin_addr );
 memset( bcastaddr.sin_zero, '\0', sizeof( bcastaddr.sin_zero ) );
 len = sizeof( bcastaddr );
 if( sendto( sockfd, &data, sizeof( data ), 0, (struct sockaddr*)&bcastaddr, len ) != sizeof( data ) )
 {
  return -1;
 }
 return 0;
}

canonical_original_code:
int sendBroadcast(int sockfd, unsigned int port)
{
 struct sockaddr_in bcastaddr;
 unsigned char data = 1;
 unsigned int len;
 bcastaddr.sin_family = 2;
 bcastaddr.sin_port = htons( port );
 inet_pton( bcastaddr.sin_family, "255.255.255.255", &bcastaddr.sin_addr );
 memset( bcastaddr.sin_zero, '\0', sizeof( bcastaddr.sin_zero ) );
 len = sizeof( bcastaddr );
 if( sendto( sockfd, &data, sizeof( data ), 0, (struct sockaddr *)&bcastaddr, len ) != sizeof( data ) )
 {
  return -1;
 }
 return 0;
}

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:
data
unsigned char

variable_types:
len
unsigned int

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

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


recvBroadcast

decompiled_code:
_BOOL8 __fastcall recvBroadcast(int a1, struct sockaddr *a2)
{
int v2; // edx
_BOOL8 result; // rax
char buf[10]; // [rsp+2h] [rbp-16h] BYREF
socklen_t addr_len[3]; // [rsp+Ch] [rbp-Ch] BYREF

addr_len[0] = 16;
v2 = recvfrom(a1, buf, 0xAuLL, 0, a2, addr_len);
result = 1LL;
if ( v2 == 1 )
result = buf[0] != 1;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func8(int a1, struct sockaddr *a2)
{
int v2; // edx
_BOOL8 result; // rax
char buf[10]; // [rsp+2h] [rbp-16h] BYREF
socklen_t addr_len[3]; // [rsp+Ch] [rbp-Ch] BYREF

addr_len[0] = 16;
v2 = recvfrom(a1, buf, 0xAuLL, 0, a2, addr_len);
result = 1LL;
if ( v2 == 1 )
result = buf[0] != 1;
return result;
}

original_code:
int recvBroadcast( int sockfd, struct sockaddr_in *addr )
{
 socklen_t addrSize;
 char buf[10];
 int bytesRead;
 addrSize = sizeof( *addr );
 bytesRead = recvfrom( sockfd, &buf, sizeof( buf ), 0, (struct sockaddr*)addr, &addrSize );
 if( bytesRead == 1 && buf[0] == 1 )
 {
  return 0;
 }
 return 1;
}

canonical_original_code:
int recvBroadcast(int sockfd, struct sockaddr_in *addr)
{
 unsigned int addrSize;
 char buf[10];
 int bytesRead;
 addrSize = sizeof( *addr );
 bytesRead = recvfrom( sockfd, &buf, sizeof( buf ), 0, (struct sockaddr *)addr, &addrSize );
 if( bytesRead == 1 && buf[0] == 1 )
 {
  return 0;
 }
 return 1;
}

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:
addrSize
unsigned int

variable_types:
buf
char [10]

variable_types: bytesRead int


setSocketBlock

decompiled_code:
int __fastcall setSocketBlock(int a1)
{
return fcntl(a1, 4, 2048LL);
}

canonical_decompiled_code:
int __fastcall func9(int a1)
{
return fcntl(a1, 4, 2048LL);
}

original_code:
int setSocketBlock( int sockfd )
{
 return fcntl( sockfd, 4, 04000 );
}

canonical_original_code:
int setSocketBlock(int sockfd)
{
 return fcntl( sockfd, 4, 04000 );
}


sendAll

decompiled_code:
__int64 __fastcall sendAll(int fd, void *buf, int a3, int a4)
{
int v5; // ebx
int v8; // eax

v5 = a3;
if ( a3 <= 0 )
return 1LL;
do
{
v8 = send(fd, buf, v5, a4);
if ( v8 == -1 )
return 0LL;
v5 -= v8;
buf = (char *)buf + v8;
}
while ( v5 > 0 );
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(int fd, void *buf, int a3, int a4)
{
int v5; // ebx
int v8; // eax

v5 = a3;
if ( a3 <= 0 )
return 1LL;
do
{
v8 = send(fd, buf, v5, a4);
if ( v8 == -1 )
return 0LL;
v5 -= v8;
buf = (char *)buf + v8;
}
while ( v5 > 0 );
return 1LL;
}

original_code:
boolean sendAll( int sockfd, const char *data, int datSize, int flags )
{
 boolean success = TRUE;
 int bytesSent;
 while( datSize > 0 && success == TRUE )
 {
  bytesSent = send( sockfd, data, datSize, flags );
  if( bytesSent == -1 )
  {
   success = FALSE;
  }
  else
  {
   datSize -= bytesSent;
   data += bytesSent;
  }
 }
 return success;
}

canonical_original_code:
enum boolean sendAll(int sockfd, char *data, int datSize, int flags)
{
 enum boolean success = TRUE;
 int bytesSent;
 while( datSize > 0 && success == TRUE )
 {
  bytesSent = send( sockfd, data, datSize, flags );
  if( bytesSent == -1 )
  {
   success = FALSE;
  }
  else
  {
   datSize -= bytesSent;
   data += bytesSent;
  }
 }
 return success;
}

variable_types:
data
char *

variable_types: datSize int

variable_types: flags int

variable_types:
success
enum boolean { FALSE=0, TRUE=1 }

variable_types: bytesSent int

return_type: enum boolean { FALSE=0, TRUE=1 }


sendMsg

decompiled_code:
__int64 __fastcall sendMsg(int fd, unsigned int a2, __int64 a3)
{
__int64 (__fastcall *v4)(__int64); // rax
__int64 v5; // rbp
unsigned int v6; // ebx
int v7; // er13
void *ptr; // [rsp+0h] [rbp-38h] BYREF
__int16 v10; // [rsp+8h] [rbp-30h]

if ( serNumEnt > a2 && (v4 = *(&serArray + a2)) != 0LL )
{
if ( !a3 )
_assert_fail("dataStruct != NULL", "../netmsg.c", 0x35u, "sendMsg");
v5 = v4(a3);
v10 = *(_WORD *)(v5 + 8) + 4;
ptr = malloc(v10);
serialiseUInt(&ptr, a2, 0LL, 15LL, 4LL);
serialiseInt(&ptr, *(__int16 *)(v5 + 8), 16LL, 31LL, 2LL);
memcpy((char *)ptr + 4, *(const void **)v5, *(__int16 *)(v5 + 8));
v6 = sendAll(fd, ptr, v10, 0);
free(*(void **)v5);
free((void *)v5);
free(ptr);
}
else
{
if ( a3 )
{
v7 = deserialiseInt(a3, 0LL, 15LL);
v10 = v7 + 4;
ptr = malloc((__int16)(v7 + 4));
serialiseUInt(&ptr, a2, 0LL, 15LL, 4LL);
serialiseInt(&ptr, v7, 16LL, 31LL, 4LL);
memcpy((char *)ptr + 4, (const void *)(a3 + 2), v10 - 4);
}
else
{
v10 = 4;
ptr = malloc(4uLL);
serialiseUInt(&ptr, a2, 0LL, 15LL, 4LL);
serialiseInt(&ptr, 0LL, 16LL, 31LL, 4LL);
}
v6 = sendAll(fd, ptr, v10, 0);
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func1(int fd, unsigned int a2, __int64 a3)
{
__int64 (__fastcall *v4)(__int64); // rax
__int64 v5; // rbp
unsigned int v6; // ebx
int v7; // er13
void *ptr; // [rsp+0h] [rbp-38h] BYREF
__int16 v10; // [rsp+8h] [rbp-30h]

if ( serNumEnt > a2 && (v4 = *(&serArray + a2)) != 0LL )
{
if ( !a3 )
_assert_fail("dataStruct != NULL", "../netmsg.c", 0x35u, "sendMsg");
v5 = v4(a3);
v10 = *(_WORD *)(v5 + 8) + 4;
ptr = malloc(v10);
serialiseUInt(&ptr, a2, 0LL, 15LL, 4LL);
serialiseInt(&ptr, *(__int16 *)(v5 + 8), 16LL, 31LL, 2LL);
memcpy((char *)ptr + 4, *(const void **)v5, *(__int16 *)(v5 + 8));
v6 = func0(fd, ptr, v10, 0);
free(*(void **)v5);
free((void *)v5);
free(ptr);
}
else
{
if ( a3 )
{
v7 = deserialiseInt(a3, 0LL, 15LL);
v10 = v7 + 4;
ptr = malloc((__int16)(v7 + 4));
serialiseUInt(&ptr, a2, 0LL, 15LL, 4LL);
serialiseInt(&ptr, v7, 16LL, 31LL, 4LL);
memcpy((char *)ptr + 4, (const void *)(a3 + 2), v10 - 4);
}
else
{
v10 = 4;
ptr = malloc(4uLL);
serialiseUInt(&ptr, a2, 0LL, 15LL, 4LL);
serialiseInt(&ptr, 0LL, 16LL, 31LL, 4LL);
}
v6 = func0(fd, ptr, v10, 0);
}
return v6;
}

original_code:
boolean sendMsg( int sockfd, MsgType type, void *dataStruct )
{
 SerialData outDat, *serStruct;
 boolean success = TRUE;
 int bodyLen = 0;
 if( type >= serNumEnt || serArray[type] == ((void *)0) )
 {
  if( dataStruct != ((void *)0) )
  {
   bodyLen = deserialiseInt( dataStruct, 0, 2 * 8 - 1 );
  }
  outDat.len = 2 + 2 + bodyLen;
  outDat.sdata = malloc( outDat.len * sizeof( *outDat.sdata ) );
  serialiseUInt( &outDat, type, 0, 2 * 8 - 1, sizeof( type ) );
  serialiseInt( &outDat, bodyLen, 2 * 8, 2 * 8 + 2 * 8 - 1, sizeof( bodyLen ) );
  if( dataStruct != ((void *)0) )
  {
   memcpy( outDat.sdata + 2 + 2, (char*)dataStruct + 2, outDat.len - 2 - 2 );
  }
  success = sendAll( sockfd, (char*)outDat.sdata, outDat.len, 0);
 }
 else
 {
  ((void) sizeof ((dataStruct != ((void *)0)) ? 1 : 0), __extension__ ({ if (dataStruct != ((void *)0)) ; else __assert_fail ("dataStruct != NULL", "../netmsg.c", 53, __extension__ __PRETTY_FUNCTION__); }));
  serStruct = serArray[type]( dataStruct );
  outDat.len = serStruct->len + 2 + 2;
  outDat.sdata = malloc( ( outDat.len ) * sizeof( *serStruct->sdata ) );
         serialiseUInt( &outDat, type, 0, 2 * 8 - 1, sizeof( type ) );
  serialiseInt( &outDat, serStruct->len, 2 * 8, 2 * 8 + 2 * 8 - 1, sizeof( serStruct->len ) );
  memcpy( outDat.sdata + 2 + 2, serStruct->sdata, serStruct->len );
  success = sendAll( sockfd, (char*)outDat.sdata, outDat.len * sizeof( *outDat.sdata ), 0 );
  free( serStruct->sdata );
  free( serStruct );
  free( outDat.sdata );
 }
 return success;
}

canonical_original_code:
enum boolean sendMsg(int sockfd, enum MsgType type, void *dataStruct)
{
 struct SerialData outDat; struct SerialData *serStruct;
 enum boolean success = TRUE;
 int bodyLen = 0;
 if( type >= serNumEnt || serArray[type] == ((void *)0) )
 {
  if( dataStruct != ((void *)0) )
  {
   bodyLen = deserialiseInt( dataStruct, 0, 2 * 8 - 1 );
  }
  outDat.len = 2 + 2 + bodyLen;
  outDat.sdata = malloc( outDat.len * sizeof( *outDat.sdata ) );
  serialiseUInt( &outDat, type, 0, 2 * 8 - 1, sizeof( type ) );
  serialiseInt( &outDat, bodyLen, 2 * 8, 2 * 8 + 2 * 8 - 1, sizeof( bodyLen ) );
  if( dataStruct != ((void *)0) )
  {
   memcpy( outDat.sdata + 2 + 2, (char *)dataStruct + 2, outDat.len - 2 - 2 );
  }
  success = sendAll( sockfd, (char *)outDat.sdata, outDat.len, 0);
 }
 else
 {
  ((void) sizeof ((dataStruct != ((void *)0)) ? 1 : 0), __extension__ ({ if (dataStruct != ((void *)0)) ; else __assert_fail ("dataStruct != NULL", "../netmsg.c", 53, __extension__ __PRETTY_FUNCTION__); }));
  serStruct = serArray[type]( dataStruct );
  outDat.len = serStruct->len + 2 + 2;
  outDat.sdata = malloc( ( outDat.len ) * sizeof( *serStruct->sdata ) );
         serialiseUInt( &outDat, type, 0, 2 * 8 - 1, sizeof( type ) );
  serialiseInt( &outDat, serStruct->len, 2 * 8, 2 * 8 + 2 * 8 - 1, sizeof( serStruct->len ) );
  memcpy( outDat.sdata + 2 + 2, serStruct->sdata, serStruct->len );
  success = sendAll( sockfd, (char *)outDat.sdata, outDat.len * sizeof( *outDat.sdata ), 0 );
  free( serStruct->sdata );
  free( serStruct );
  free( outDat.sdata );
 }
 return success;
}

variable_types: enum MsgType { KEYPRESS=0, KEYRELEASE=1, POINTERSET=2, POINTERMOVE=3, POINTERPRESS=4, POINTERRELEASE=5, SETRESOLUTION=6, DISPLAYNUM=7, STOPDISPLAYNUM=8, CONNECT=9, DISCONNECT=10, ALLOW=11, DENY=12, CLOSE=13, NOMSG=14 }

variable_types:
dataStruct
void *

variable_types: struct SerialData { unsigned char *sdata; short len; } *

variable_types: bodyLen int


recvExact

decompiled_code:
__int64 __fastcall recvExact(int fd, void *buf, int a3, int a4)
{
int v5; // ebx
int v8; // eax

v5 = a3;
if ( a3 <= 0 )
return 1LL;
do
{
v8 = recv(fd, buf, v5, a4);
if ( v8 <= 0 )
return 0LL;
v5 -= v8;
buf = (char *)buf + v8;
}
while ( v5 > 0 );
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(int fd, void *buf, int a3, int a4)
{
int v5; // ebx
int v8; // eax

v5 = a3;
if ( a3 <= 0 )
return 1LL;
do
{
v8 = recv(fd, buf, v5, a4);
if ( v8 <= 0 )
return 0LL;
v5 -= v8;
buf = (char *)buf + v8;
}
while ( v5 > 0 );
return 1LL;
}

original_code:
boolean recvExact( int sockfd, char *buf, int len, int flags )
{
 boolean success = TRUE;
 int bytesRead;
 while( success && len > 0 )
 {
  if( (bytesRead = recv( sockfd, buf, len, flags ) ) > 0 )
  {
   len -= bytesRead;
   buf += bytesRead;
  }
  else
  {
   success = FALSE;
  }
 }
 return success;
}

canonical_original_code:
enum boolean recvExact(int sockfd, char *buf, int len, int flags)
{
 enum boolean success = TRUE;
 int bytesRead;
 while( success && len > 0 )
 {
  if( (bytesRead = recv( sockfd, buf, len, flags ) ) > 0 )
  {
   len -= bytesRead;
   buf += bytesRead;
  }
  else
  {
   success = FALSE;
  }
 }
 return success;
}

variable_types: sockfd int

variable_types:
buf
char *

variable_types: len int


CreateToggleWndDat

decompiled_code:
_DWORD *CreateToggleWndDat()
{
_DWORD *result; // rax

result = malloc(8uLL);
*result = 0;
return result;
}

canonical_decompiled_code:
_DWORD *func6()
{
_DWORD *result; // rax

result = malloc(8uLL);
*result = 0;
return result;
}

original_code:
static ToggleWndDat *CreateToggleWndDat( void )
{
 ToggleWndDat *twd;
 twd = malloc( sizeof( twd ) );
 twd->isToggle = FALSE;
 return twd;
}

canonical_original_code:
static struct ToggleWndDat *CreateToggleWndDat()
{
 struct ToggleWndDat *twd;
 twd = malloc( sizeof( twd ) );
 twd->isToggle = FALSE;
 return twd;
}

variable_types: struct ToggleWndDat { enum boolean { FALSE=0, TRUE=1 } isToggle; } *

user_defined_types: struct ToggleWndDat { enum boolean isToggle; }


DestroyToggleWndDat

decompiled_code:
void __fastcall DestroyToggleWndDat(void *a1)
{
free(a1);
}

canonical_decompiled_code:
void __fastcall func8(void *a1)
{
free(a1);
}

original_code:
static void DestroyToggleWndDat( ToggleWndDat *twd )
{
 free( twd );
}

canonical_original_code:
static void DestroyToggleWndDat(struct ToggleWndDat *twd)
{
 free( twd );
}

return_type: void


CreateNumWndDat

decompiled_code:
_DWORD *CreateNumWndDat()
{
_DWORD *result; // rax

result = malloc(4uLL);
*result = 0;
return result;
}

canonical_decompiled_code:
_DWORD *func0()
{
_DWORD *result; // rax

result = malloc(4uLL);
*result = 0;
return result;
}

original_code:
NumWndDat *CreateNumWndDat( void )
{
 NumWndDat *nwd;
 nwd = malloc( sizeof( *nwd ) );
 nwd->numWnd = 0;
 return nwd;
}

canonical_original_code:
struct NumWndDat *CreateNumWndDat()
{
 struct NumWndDat *nwd;
 nwd = malloc( sizeof( *nwd ) );
 nwd->numWnd = 0;
 return nwd;
}

variable_types:
nwd
struct NumWndDat { int numWnd; } *

return_type: struct NumWndDat { int numWnd; } *


DestroyNumWndDat

decompiled_code:
void __fastcall DestroyNumWndDat(void *a1)
{
free(a1);
}

canonical_decompiled_code:
void __fastcall func1(void *a1)
{
free(a1);
}

original_code:
void DestroyNumWndDat( NumWndDat *inData )
{
 free( inData );
}

canonical_original_code:
void DestroyNumWndDat(struct NumWndDat *inData)
{
 free( inData );
}

variable_types:
inData
struct NumWndDat { int numWnd; } *


cleanup

decompiled_code:
void cleanup(void)
{
if ( pr )
stl_reader_delete();
}

canonical_decompiled_code:
void func0(void)
{
if ( pr )
stl_reader_delete();
}

original_code:
static void cleanup(void)
{
 if (pr) stl_reader_delete(pr);
}

canonical_original_code:
static void cleanup()
{
 if (pr) stl_reader_delete(pr);
}


decompiled_code:
int __fastcall check_structure(__int64 a1)
{
char *v1; // rax
int v2; // edx
__int64 v3; // rcx
_DWORD *v4; // rax
__int64 v5; // rsi
int v6; // edx
int v7; // edx
__int64 v8; // rcx
_DWORD *v9; // rax
__int64 v10; // rsi
int v11; // edx
int result; // eax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

printf("// Name of the solid: %s\n", (const char *)a1);
time(&timer);
v1 = ctime(&timer);
printf("// Generated by stl2pov 2.4.4 on %s", v1);
v2 = *(_DWORD *)(a1 + 112);
if ( v2 <= 0 )
goto LABEL_10;
v3 = *(_QWORD *)(a1 + 88);
v4 = (_DWORD *)(v3 + 12);
v5 = v3 + 16LL * (unsigned int)(v2 - 1) + 28;
v6 = 0;
do
{
v6 += *v4 < 3;
v4 += 4;
}
while ( v4 != (_DWORD *)v5 );
if ( !v6 )
LABEL_10:
puts("// - All vertices used by 3 or more triangles, good.");
v7 = *(_DWORD *)(a1 + 116);
if ( v7 <= 0 )
goto LABEL_11;
v8 = *(_QWORD *)(a1 + 96);
v9 = (_DWORD *)(v8 + 16);
v10 = v8 + 20LL * (unsigned int)(v7 - 1) + 36;
v11 = 0;
do
{
v11 += *v9 != 2;
v9 += 5;
}
while ( v9 != (_DWORD *)v10 );
if ( v11 )
{
puts("// ! Warning: some edges are not used by two triangles.");
puts("// (There might be visible gaps between triangles.)");
}
else
{
LABEL_11:
puts("// - All edges used by 2 triangles, good.");
}
if ( 2 * *(_DWORD *)(a1 + 116) == 3 * *(_DWORD *)(a1 + 120) )
puts("// - 2 x #edges == 3 x #triangles, good.");
result = *(_DWORD *)(a1 + 112) + *(_DWORD *)(a1 + 120) - *(_DWORD *)(a1 + 116);
if ( result == 2 )
result = puts("// - The solid meets Euler's Rule, good.");
return result;
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1)
{
char *v1; // rax
int v2; // edx
__int64 v3; // rcx
_DWORD *v4; // rax
__int64 v5; // rsi
int v6; // edx
int v7; // edx
__int64 v8; // rcx
_DWORD *v9; // rax
__int64 v10; // rsi
int v11; // edx
int result; // eax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

printf("// Name of the solid: %s\n", (const char *)a1);
time(&timer);
v1 = ctime(&timer);
printf("// Generated by stl2pov 2.4.4 on %s", v1);
v2 = *(_DWORD *)(a1 + 112);
if ( v2 <= 0 )
goto LABEL_10;
v3 = *(_QWORD *)(a1 + 88);
v4 = (_DWORD *)(v3 + 12);
v5 = v3 + 16LL * (unsigned int)(v2 - 1) + 28;
v6 = 0;
do
{
v6 += *v4 < 3;
v4 += 4;
}
while ( v4 != (_DWORD *)v5 );
if ( !v6 )
LABEL_10:
puts("// - All vertices used by 3 or more triangles, good.");
v7 = *(_DWORD *)(a1 + 116);
if ( v7 <= 0 )
goto LABEL_11;
v8 = *(_QWORD *)(a1 + 96);
v9 = (_DWORD *)(v8 + 16);
v10 = v8 + 20LL * (unsigned int)(v7 - 1) + 36;
v11 = 0;
do
{
v11 += *v9 != 2;
v9 += 5;
}
while ( v9 != (_DWORD *)v10 );
if ( v11 )
{
puts("// ! Warning: some edges are not used by two triangles.");
puts("// (There might be visible gaps between triangles.)");
}
else
{
LABEL_11:
puts("// - All edges used by 2 triangles, good.");
}
if ( 2 * *(_DWORD *)(a1 + 116) == 3 * *(_DWORD *)(a1 + 120) )
puts("// - 2 x #edges == 3 x #triangles, good.");
result = *(_DWORD *)(a1 + 112) + *(_DWORD *)(a1 + 120) - *(_DWORD *)(a1 + 116);
if ( result == 2 )
result = puts("// - The solid meets Euler's Rule, good.");
return result;
}

original_code:
void check_structure(struct stl_reader *r)
{
 int i, open = 0;
 time_t tm;
 printf("// Name of the solid: %s\n", r->name);
 time(&tm);
 printf("// Generated by ""stl2pov"" ""2.4.4"" on %s", ctime(&tm));
 for (i=0; i<r->nv; i++) {
  if (r->v[i].refcnt<3) {
   open++;
  }
 }
 if (open==0) {
  printf("// - All vertices used by 3 or more " "triangles, good.\n");
 }
 open = 0;
 for (i=0; i<r->ne; i++) {
  if (r->e[i].refcnt!=2) {
   open++;
  }
 }
 if (open==0) {
  puts("// - All edges used by 2 triangles, good.");
 } else {
  puts("// ! Warning: some edges are not used by two triangles.");
  puts("//   (There might be visible gaps between triangles.)");
 }
 if ((2*r->ne)==(3*r->nf)) {
  puts("// - 2 x #edges == 3 x #triangles, good.");
 }
 if ((r->nf - r->ne + r->nv)==2) {
  puts("// - The solid meets Euler's Rule, good.");
 }
}

canonical_original_code:
void check_structure(struct stl_reader *r)
{
 int i; int open = 0;
 long tm;
 printf("// Name of the solid: %s\n", r->name);
 time(&tm);
 printf("// Generated by ""stl2pov"" ""2.4.4"" on %s", ctime(&tm));
 for (i=0; i<r->nv; i++) {
  if (r->v[i].refcnt<3) {
   open++;
  }
 }
 if (open==0) {
  printf("// - All vertices used by 3 or more " "triangles, good.\n");
 }
 open = 0;
 for (i=0; i<r->ne; i++) {
  if (r->e[i].refcnt!=2) {
   open++;
  }
 }
 if (open==0) {
  puts("// - All edges used by 2 triangles, good.");
 } else {
  puts("// ! Warning: some edges are not used by two triangles.");
  puts("//   (There might be visible gaps between triangles.)");
 }
 if ((2*r->ne)==(3*r->nf)) {
  puts("// - 2 x #edges == 3 x #triangles, good.");
 }
 if ((r->nf - r->ne + r->nv)==2) {
  puts("// - The solid meets Euler's Rule, good.");
 }
}

variable_types: struct stl_reader { char name[85]; struct vertex { float xyz[3]; int refcnt; } *v; struct edge { int vertex[2]; int facet[2]; int refcnt; } *e; struct facet { int vertex[3]; int edges[3]; float normal[3]; } *f; int nv; float pdone; char *buf; long buflen; int fmt; } *

variable_types: i int

variable_types: open int

variable_types: tm long

user_defined_types: struct stl_reader { char name[85]; struct vertex *v; struct edge *e; struct facet *f; int nv; float pdone; char *buf; long buflen; int fmt; }


variable_types: k int

variable_types: p double

user_defined_types: struct vertex { float xyz[3]; int refcnt; }

user_defined_types: struct edge { int vertex[2]; int facet[2]; int refcnt; }

user_defined_types: struct facet { int vertex[3]; int edges[3]; float normal[3]; }


original_code:
void print_smooth_mesh(struct stl_reader *r)
{
 int i, k1, k2, k3, r1, r2, r3;
 float n1[3], n2[3], n3[3];
 double p;
 printf("#declare m_%s = mesh {\n", r->name);
 for (i=0; i<r->nf; i++) {
  k1 = r->f[i].vertex[0];
  k2 = r->f[i].vertex[1];
  k3 = r->f[i].vertex[2];
  r1 = calc_vertex_normal(r, i, k1, n1);
  r2 = calc_vertex_normal(r, i, k2, n2);
  r3 = calc_vertex_normal(r, i, k3, n3);
  if (r1||r2||r3) {
   printf("  smooth_triangle { // #%d\n", i+1);
   printf("    <%g, %g, %g>, <%g, %g, %g>,\n",
          (double)r->v[k1].xyz[0],
          (double)r->v[k1].xyz[1],
          (double)r->v[k1].xyz[2],
          (double)n1[0], (double)n1[1], (double)n1[2]);
   printf("    <%g, %g, %g>, <%g, %g, %g>,\n",
          (double)r->v[k2].xyz[0],
          (double)r->v[k2].xyz[1],
          (double)r->v[k2].xyz[2],
          (double)n2[0], (double)n2[1], (double)n2[2]);
   printf("    <%g, %g, %g>, <%g, %g, %g>\n",
          (double)r->v[k3].xyz[0],
          (double)r->v[k3].xyz[1],
          (double)r->v[k3].xyz[2],
          (double)n3[0], (double)n3[1], (double)n3[2]);
  } else {
   printf("  triangle { // #%d\n", i+1);
   printf("    <%g, %g, %g>,\n",
          (double)r->v[k1].xyz[0],
          (double)r->v[k1].xyz[1],
          (double)r->v[k1].xyz[2]);
   printf("    <%g, %g, %g>,\n",
          (double)r->v[k2].xyz[0],
          (double)r->v[k2].xyz[1],
          (double)r->v[k2].xyz[2]);
   printf("    <%g, %g, %g>\n",
          (double)r->v[k3].xyz[0],
          (double)r->v[k3].xyz[1],
          (double)r->v[k3].xyz[2]);
  }
  puts("  }");
  p= ((double)i)/r->nf*100;
  fprintf(stderr, "\r%3.0f%% done", p);
  fflush(stderr);
 }
 printf("} // end of mesh m_%s\n", r->name);
}

canonical_original_code:
void print_smooth_mesh(struct stl_reader *r)
{
 int i; int k1; int k2; int k3; int r1; int r2; int r3;
 float n1[3]; float n2[3]; float n3[3];
 double p;
 printf("#declare m_%s = mesh {\n", r->name);
 for (i=0; i<r->nf; i++) {
  k1 = r->f[i].vertex[0];
  k2 = r->f[i].vertex[1];
  k3 = r->f[i].vertex[2];
  r1 = calc_vertex_normal(r, i, k1, n1);
  r2 = calc_vertex_normal(r, i, k2, n2);
  r3 = calc_vertex_normal(r, i, k3, n3);
  if (r1||r2||r3) {
   printf("  smooth_triangle { // #%d\n", i+1);
   printf("    <%g, %g, %g>, <%g, %g, %g>,\n",
          (double)r->v[k1].xyz[0],
          (double)r->v[k1].xyz[1],
          (double)r->v[k1].xyz[2],
          (double)n1[0], (double)n1[1], (double)n1[2]);
   printf("    <%g, %g, %g>, <%g, %g, %g>,\n",
          (double)r->v[k2].xyz[0],
          (double)r->v[k2].xyz[1],
          (double)r->v[k2].xyz[2],
          (double)n2[0], (double)n2[1], (double)n2[2]);
   printf("    <%g, %g, %g>, <%g, %g, %g>\n",
          (double)r->v[k3].xyz[0],
          (double)r->v[k3].xyz[1],
          (double)r->v[k3].xyz[2],
          (double)n3[0], (double)n3[1], (double)n3[2]);
  } else {
   printf("  triangle { // #%d\n", i+1);
   printf("    <%g, %g, %g>,\n",
          (double)r->v[k1].xyz[0],
          (double)r->v[k1].xyz[1],
          (double)r->v[k1].xyz[2]);
   printf("    <%g, %g, %g>,\n",
          (double)r->v[k2].xyz[0],
          (double)r->v[k2].xyz[1],
          (double)r->v[k2].xyz[2]);
   printf("    <%g, %g, %g>\n",
          (double)r->v[k3].xyz[0],
          (double)r->v[k3].xyz[1],
          (double)r->v[k3].xyz[2]);
  }
  puts("  }");
  p= ((double)i)/r->nf*100;
  fprintf(stderr, "\r%3.0f%% done", p);
  fflush(stderr);
 }
 printf("} // end of mesh m_%s\n", r->name);
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
__int64 v4; // rax
const char *v5; // rdx
int result; // eax
__int64 v7; // r8
const char **v8; // r15
char *v9; // r12
float v10; // xmm0_4
int i; // [rsp+Ch] [rbp-4Ch]
char *endptr; // [rsp+18h] [rbp-40h] BYREF

if ( argc <= 1 )
{
fwrite("stl2pov 2.4.4\n", 1uLL, 0xEuLL, stderr);
fwrite("Usage: stl2pov [-s] [-e distance] filename\n\n", 1uLL, 0x2CuLL, stderr);
print_license(stderr);
result = 0;
}
else
{
v3 = 1;
for ( i = 0; v3 < argc - 1; ++v3 )
{
v7 = v3;
if ( !strcmp(argv[v7], "-s") )
{
fwrite("Using smooth triangles.\n", 1uLL, 0x18uLL, stderr);
i = 1;
}
else if ( !strcmp(argv[v3], "-e") )
{
++v3;
v8 = &argv[v7 + 1];
v9 = (char *)*v8;
endptr = v9;
v10 = strtof(v9, &endptr);
if ( v9 == endptr )
{
warning("unreadable distance \"%s\" ignored.\n", *v8);
}
else
{
epsilon2 = v10 * v10;
fprintf(stderr, "Epsilon = %g units.\n", v10);
}
}
else
{
warning("unrecognized option \"%s\" ignored.\n", argv[v3]);
}
}
atexit(cleanup);
v4 = stl_reader_init(argv[argc - 1]);
pr = v4;
if ( v4 )
{
v5 = "binary";
if ( *(_DWORD *)(v4 + 160) != 1 )
v5 = "text";
fprintf(stderr, "Scanning %s format STL file (%d triangles)\n", v5, *(unsigned int *)(v4 + 124));
while ( !(unsigned int)stl_reader_step(pr) )
{
fprintf(stderr, "\r%3.0f%% done", *(float *)(pr + 128));
fflush(stderr);
}
fwrite("\r100% done\n", 1uLL, 0xBuLL, stderr);
check_structure(pr);
fwrite("Writing output...\n", 1uLL, 0x12uLL, stderr);
if ( i )
print_smooth_mesh(pr);
else
print_mesh(pr);
fwrite("\r100% done\n", 1uLL, 0xBuLL, stderr);
fflush(stderr);
result = 0;
}
else
{
result = 1;
}
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
__int64 v4; // rax
const char *v5; // rdx
int result; // eax
__int64 v7; // r8
const char **v8; // r15
char *v9; // r12
float v10; // xmm0_4
int i; // [rsp+Ch] [rbp-4Ch]
char *endptr; // [rsp+18h] [rbp-40h] BYREF

if ( argc <= 1 )
{
fwrite("stl2pov 2.4.4\n", 1uLL, 0xEuLL, stderr);
fwrite("Usage: stl2pov [-s] [-e distance] filename\n\n", 1uLL, 0x2CuLL, stderr);
print_license(stderr);
result = 0;
}
else
{
v3 = 1;
for ( i = 0; v3 < argc - 1; ++v3 )
{
v7 = v3;
if ( !strcmp(argv[v7], "-s") )
{
fwrite("Using smooth triangles.\n", 1uLL, 0x18uLL, stderr);
i = 1;
}
else if ( !strcmp(argv[v3], "-e") )
{
++v3;
v8 = &argv[v7 + 1];
v9 = (char *)*v8;
endptr = v9;
v10 = strtof(v9, &endptr);
if ( v9 == endptr )
{
warning("unreadable distance \"%s\" ignored.\n", *v8);
}
else
{
epsilon2 = v10 * v10;
fprintf(stderr, "Epsilon = %g units.\n", v10);
}
}
else
{
warning("unrecognized option \"%s\" ignored.\n", argv[v3]);
}
}
atexit(cleanup);
v4 = stl_reader_init(argv[argc - 1]);
pr = v4;
if ( v4 )
{
v5 = "binary";
if ( *(_DWORD *)(v4 + 160) != 1 )
v5 = "text";
fprintf(stderr, "Scanning %s format STL file (%d triangles)\n", v5, *(unsigned int *)(v4 + 124));
while ( !(unsigned int)stl_reader_step(pr) )
{
fprintf(stderr, "\r%3.0f%% done", *(float *)(pr + 128));
fflush(stderr);
}
fwrite("\r100% done\n", 1uLL, 0xBuLL, stderr);
func1(pr);
fwrite("Writing output...\n", 1uLL, 0x12uLL, stderr);
if ( i )
func3(pr);
else
func2(pr);
fwrite("\r100% done\n", 1uLL, 0xBuLL, stderr);
fflush(stderr);
result = 0;
}
else
{
result = 1;
}
}
return result;
}

original_code:
int main(int argc, char *argv[])
{
 int smooth = 0;
 int n;
 char *p, *ep;
 float dist;
 char *fmt;
 if (argc < 2) {
  fputs("stl2pov"" ""2.4.4""\n", stderr);
  fputs("Usage: ""stl2pov"" [-s] [-e distance] filename\n\n",
        stderr);
  print_license(stderr);
  return 0;
 }
 for (n=1; n<(argc-1); n++) {
  if (strcmp(argv[n], "-s")==0) {
   smooth = 1;
   fprintf(stderr, "Using smooth triangles.\n");
  } else if (strcmp(argv[n], "-e")==0) {
   n++;
   p = ep = argv[n];
   dist = strtof(p, &ep);
   if (p == ep) {
    warning("unreadable distance \"%s\" ignored.\n",
     argv[n]);
   } else {
    epsilon2 = dist*dist;
    fprintf(stderr, "Epsilon = %g units.\n", dist);
   }
  } else {
   warning("unrecognized option \"%s\" ignored.\n",
    argv[n]);
  }
 }
 atexit(cleanup);
 pr = stl_reader_init(argv[argc-1]);
 if (pr == ((void *)0)) {
  return 1;
 }
 if (pr->fmt == 1) {
  fmt = "binary";
 } else {
  fmt = "text";
 }
 fprintf(stderr, "Scanning %s format STL file (%d triangles)\n", fmt,
  pr->maxnf);
 repeat:
 if (stl_reader_step(pr) == 0) {
  fprintf(stderr, "\r%3.0f%% done", (double)pr->pdone);
  fflush(stderr);
  goto repeat;
 }
 fputs("\r100% done\n",stderr);
 check_structure(pr);
 fputs("Writing output...\n",stderr);
 if (smooth) {
  print_smooth_mesh(pr);
 } else {
  print_mesh(pr);
 }
 fputs("\r100% done\n",stderr);
 fflush(stderr);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 int smooth = 0;
 int n;
 char *p; char *ep;
 float dist;
 char *fmt;
 if (argc < 2) {
  fputs("stl2pov"" ""2.4.4""\n", stderr);
  fputs("Usage: ""stl2pov"" [-s] [-e distance] filename\n\n",
        stderr);
  print_license(stderr);
  return 0;
 }
 for (n=1; n<(argc-1); n++) {
  if (strcmp(argv[n], "-s")==0) {
   smooth = 1;
   fprintf(stderr, "Using smooth triangles.\n");
  } else if (strcmp(argv[n], "-e")==0) {
   n++;
   p = ep = argv[n];
   dist = strtof(p, &ep);
   if (p == ep) {
    warning("unreadable distance \"%s\" ignored.\n",
     argv[n]);
   } else {
    epsilon2 = dist*dist;
    fprintf(stderr, "Epsilon = %g units.\n", dist);
   }
  } else {
   warning("unrecognized option \"%s\" ignored.\n",
    argv[n]);
  }
 }
 atexit(cleanup);
 pr = stl_reader_init(argv[argc-1]);
 if (pr == ((void *)0)) {
  return 1;
 }
 if (pr->fmt == 1) {
  fmt = "binary";
 } else {
  fmt = "text";
 }
 fprintf(stderr, "Scanning %s format STL file (%d triangles)\n", fmt,
  pr->maxnf);
 repeat:
 if (stl_reader_step(pr) == 0) {
  fprintf(stderr, "\r%3.0f%% done", (double)pr->pdone);
  fflush(stderr);
  goto repeat;
 }
 fputs("\r100% done\n",stderr);
 check_structure(pr);
 fputs("Writing output...\n",stderr);
 if (smooth) {
  print_smooth_mesh(pr);
 } else {
  print_mesh(pr);
 }
 fputs("\r100% done\n",stderr);
 fflush(stderr);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: smooth int

variable_types: n int

variable_types:
p
char *

variable_types:
ep
char *

variable_types: dist float

variable_types:
fmt
char *


fatal

decompiled_code:
void __noreturn fatal(const char *a1, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a1);
fwrite("stl2pov error: ", 1uLL, 0xFuLL, stderr);
vfprintf(stderr, a1, arg);
exit(1);
}

canonical_decompiled_code:
void __noreturn func0(const char *a1, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a1);
fwrite("stl2pov error: ", 1uLL, 0xFuLL, stderr);
vfprintf(stderr, a1, arg);
exit(1);
}

original_code:
void fatal(const char *fmt, ...)
{
 va_list ap;
 ((void) (0));
 __builtin_va_start(ap,fmt);
 fputs("stl2pov"" error: ", stderr);
 vfprintf(stderr, fmt, ap);
 exit(1);
}

canonical_original_code:
void fatal(char *fmt, ...)
{
 __builtin_va_list ap;
 ((void) (0));
 __builtin_va_start(ap,fmt);
 fputs("stl2pov"" error: ", stderr);
 vfprintf(stderr, fmt, ap);
 exit(1);
}


warning

decompiled_code:
int warning(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
fwrite("stl2pov warning: ", 1uLL, 0x11uLL, stderr);
return vfprintf(stderr, format, arg);
}

canonical_decompiled_code:
int func1(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
fwrite("stl2pov warning: ", 1uLL, 0x11uLL, stderr);
return vfprintf(stderr, format, arg);
}

original_code:
void warning(const char *fmt, ...)
{
 va_list ap;
 ((void) (0));
 __builtin_va_start(ap,fmt);
 fputs("stl2pov"" warning: ", stderr);
 vfprintf(stderr, fmt, ap);
}

canonical_original_code:
void warning(char *fmt, ...)
{
 __builtin_va_list ap;
 ((void) (0));
 __builtin_va_start(ap,fmt);
 fputs("stl2pov"" warning: ", stderr);
 vfprintf(stderr, fmt, ap);
}


normalize

original_code:
void normalize(float xyz[3])
{
 float len = sqrtf(xyz[0]*xyz[0]+xyz[1]*xyz[1]+xyz[2]*xyz[2]);
 xyz[0] /= len;
 xyz[1] /= len;
 xyz[2] /= len;
}

variable_types:
xyz
float [3]

variable_types: len float


cosphi

variable_types:
a
float [3]

variable_types:
b
float [3]

variable_types: t float

variable_types: n float

return_type: float


decompiled_code:
__int64 __fastcall dec_to_hex_pair(unsigned int a1)
{
size_t v1; // rax
char s; // [rsp+Bh] [rbp-1Dh] BYREF

sprintf(&s, "%x", a1);
v1 = strlen(&s);
if ( v1 == 4 || v1 == 3 )
__isoc99_sscanf();
__isoc99_sscanf();
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int a1)
{
size_t v1; // rax
char s; // [rsp+Bh] [rbp-1Dh] BYREF

sprintf(&s, "%x", a1);
v1 = strlen(&s);
if ( v1 == 4 || v1 == 3 )
__isoc99_sscanf();
__isoc99_sscanf();
return 0LL;
}

original_code:
int dec_to_hex_pair (int i, char *o0, char *o1)
{
  char hx[5];
  char *hxp = hx;
  sprintf(hx, "%x", i);
  if (strlen(hx) == 4) {
    sscanf(hxp, "%2x", (unsigned int*)o0);
    hxp += 2;
  }
  else if (strlen(hx) == 3) {
    sscanf(hxp, "%1x", (unsigned int*)o0);
    hxp += 1;
  }
  sscanf(hxp, "%2x", (unsigned int*)o1);
  return 0;
}

canonical_original_code:
int dec_to_hex_pair(int i, char *o0, char *o1)
{
  char hx[5];
  char *hxp = hx;
  sprintf(hx, "%x", i);
  if (strlen(hx) == 4) {
    sscanf(hxp, "%2x", (unsigned int *)o0);
    hxp += 2;
  }
  else if (strlen(hx) == 3) {
    sscanf(hxp, "%1x", (unsigned int *)o0);
    hxp += 1;
  }
  sscanf(hxp, "%2x", (unsigned int *)o1);
  return 0;
}

variable_types: i int

variable_types:
hx
char [5]

variable_types:
hxp
char *


decompiled_code:
__int64 __fastcall gen_frame_00(__int64 a1, int a2, int a3, int a4, int a5)
{
*(_DWORD *)a1 = 0;
*(_BYTE *)(a1 + 4) = 8;
dec_to_hex_pair((int)((double)a2 / 0.06));
dec_to_hex_pair((int)((double)a3 / 0.06));
dec_to_hex_pair((int)((double)a4 / 0.06));
dec_to_hex_pair((int)((double)a5 / 0.06));
return 0LL;
}

original_code:
int gen_frame_00 (struct can_frame *frame, int fl_speed, int fr_speed, int rl_speed, int rr_speed)
{
  frame->can_id = 0x00;
  frame->can_dlc = 8;
  dec_to_hex_pair((fl_speed/0.06), (char*) &(frame->data[0]), (char*) &(frame->data[1]));
  dec_to_hex_pair((fr_speed/0.06), (char*) &frame->data[2], (char*) &frame->data[3]);
  dec_to_hex_pair((rl_speed/0.06), (char*) &frame->data[4], (char*) &frame->data[5]);
  dec_to_hex_pair((rr_speed/0.06), (char *) &frame->data[6], (char*) &frame->data[7]);
  return 0;
}

canonical_original_code:
int gen_frame_00(struct can_frame *frame, int fl_speed, int fr_speed, int rl_speed, int rr_speed)
{
  frame->can_id = 0x00;
  frame->can_dlc = 8;
  dec_to_hex_pair((fl_speed/0.06), (char *) &(frame->data[0]), (char *) &(frame->data[1]));
  dec_to_hex_pair((fr_speed/0.06), (char *) &frame->data[2], (char *) &frame->data[3]);
  dec_to_hex_pair((rl_speed/0.06), (char *) &frame->data[4], (char *) &frame->data[5]);
  dec_to_hex_pair((rr_speed/0.06), (char *) &frame->data[6], (char *) &frame->data[7]);
  return 0;
}

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


decompiled_code:
__int64 __fastcall gen_frame_08(__int64 a1, int a2, int a3, int a4, int a5)
{
*(_DWORD *)a1 = 8;
*(_BYTE *)(a1 + 4) = 8;
dec_to_hex_pair(10 * a2);
dec_to_hex_pair(10 * a3);
dec_to_hex_pair(10 * a4);
dec_to_hex_pair((int)((double)a5 * 81.92));
return 0LL;
}

original_code:
int gen_frame_08 (struct can_frame *frame, int tpsa, int tpsb, int pps, int fbwTargetTps)
{
  frame->can_id = 0x08;
  frame->can_dlc = 8;
  dec_to_hex_pair((tpsa*10), (char*) &(frame->data[0]), (char*) &(frame->data[1]));
  dec_to_hex_pair((tpsb*10), (char*) &frame->data[2], (char*) &frame->data[3]);
  dec_to_hex_pair((pps*10), (char*) &frame->data[4], (char*) &frame->data[5]);
  dec_to_hex_pair((fbwTargetTps*81.92), (char *) &frame->data[6], (char*) &frame->data[7]);
  return 0;
}

canonical_original_code:
int gen_frame_08(struct can_frame *frame, int tpsa, int tpsb, int pps, int fbwTargetTps)
{
  frame->can_id = 0x08;
  frame->can_dlc = 8;
  dec_to_hex_pair((tpsa*10), (char *) &(frame->data[0]), (char *) &(frame->data[1]));
  dec_to_hex_pair((tpsb*10), (char *) &frame->data[2], (char *) &frame->data[3]);
  dec_to_hex_pair((pps*10), (char *) &frame->data[4], (char *) &frame->data[5]);
  dec_to_hex_pair((fbwTargetTps*81.92), (char *) &frame->data[6], (char *) &frame->data[7]);
  return 0;
}

variable_types: tpsa int

variable_types: tpsb int

variable_types: pps int

variable_types: fbwTargetTps int

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


original_code:
int gen_frame_10 (struct can_frame *frame, int act, int ect, int eot, int fl)
{
  frame->can_id = 0x10;
  frame->can_dlc = 8;
  dec_to_hex_pair((act+100)*10, (char*) &(frame->data[0]), (char*) &(frame->data[1]));
  dec_to_hex_pair((ect+100)*10, (char*) &frame->data[2], (char*) &frame->data[3]);
  dec_to_hex_pair((eot+100)*10, (char*) &frame->data[4], (char*) &frame->data[5]);
  dec_to_hex_pair(fl*10, (char *) &frame->data[6], (char*) &frame->data[7]);
  return 0;
}

canonical_original_code:
int gen_frame_10(struct can_frame *frame, int act, int ect, int eot, int fl)
{
  frame->can_id = 0x10;
  frame->can_dlc = 8;
  dec_to_hex_pair((act+100)*10, (char *) &(frame->data[0]), (char *) &(frame->data[1]));
  dec_to_hex_pair((ect+100)*10, (char *) &frame->data[2], (char *) &frame->data[3]);
  dec_to_hex_pair((eot+100)*10, (char *) &frame->data[4], (char *) &frame->data[5]);
  dec_to_hex_pair(fl*10, (char *) &frame->data[6], (char *) &frame->data[7]);
  return 0;
}

variable_types: act int

variable_types: ect int

variable_types: eot int

variable_types: fl int


original_code:
int gen_frame_18 (struct can_frame *frame, int tex1, int tex2, int tex3, int aat)
{
  frame->can_id = 0x18;
  frame->can_dlc = 8;
  dec_to_hex_pair((tex1+100)*10, (char*) &(frame->data[0]), (char*) &(frame->data[1]));
  dec_to_hex_pair((tex2+100)*10, (char*) &frame->data[2], (char*) &frame->data[3]);
  dec_to_hex_pair((tex3+100)*10, (char*) &frame->data[4], (char*) &frame->data[5]);
  dec_to_hex_pair((aat+100)*10, (char *) &frame->data[6], (char*) &frame->data[7]);
  return 0;
}

canonical_original_code:
int gen_frame_18(struct can_frame *frame, int tex1, int tex2, int tex3, int aat)
{
  frame->can_id = 0x18;
  frame->can_dlc = 8;
  dec_to_hex_pair((tex1+100)*10, (char *) &(frame->data[0]), (char *) &(frame->data[1]));
  dec_to_hex_pair((tex2+100)*10, (char *) &frame->data[2], (char *) &frame->data[3]);
  dec_to_hex_pair((tex3+100)*10, (char *) &frame->data[4], (char *) &frame->data[5]);
  dec_to_hex_pair((aat+100)*10, (char *) &frame->data[6], (char *) &frame->data[7]);
  return 0;
}

variable_types: aat int


original_code:
int gen_frame_20 (struct can_frame *frame, int ecut, int spt1, int spt2, int spt3)
{
  frame->can_id = 0x20;
  frame->can_dlc = 8;
  dec_to_hex_pair((ecut+100)*10, (char*) &(frame->data[0]), (char*) &(frame->data[1]));
  dec_to_hex_pair((spt1+100)*10, (char*) &frame->data[2], (char*) &frame->data[3]);
  dec_to_hex_pair((spt2+100)*10, (char*) &frame->data[4], (char*) &frame->data[5]);
  dec_to_hex_pair((spt3+100)*10, (char *) &frame->data[6], (char*) &frame->data[7]);
  return 0;
}

canonical_original_code:
int gen_frame_20(struct can_frame *frame, int ecut, int spt1, int spt2, int spt3)
{
  frame->can_id = 0x20;
  frame->can_dlc = 8;
  dec_to_hex_pair((ecut+100)*10, (char *) &(frame->data[0]), (char *) &(frame->data[1]));
  dec_to_hex_pair((spt1+100)*10, (char *) &frame->data[2], (char *) &frame->data[3]);
  dec_to_hex_pair((spt2+100)*10, (char *) &frame->data[4], (char *) &frame->data[5]);
  dec_to_hex_pair((spt3+100)*10, (char *) &frame->data[6], (char *) &frame->data[7]);
  return 0;
}

variable_types: ecut int


decompiled_code:
__int64 __fastcall gen_frame_70(__int64 a1, unsigned int a2, unsigned int a3, unsigned int a4, int a5)
{
*(_DWORD *)a1 = 112;
*(_BYTE *)(a1 + 4) = 8;
dec_to_hex_pair(a2);
dec_to_hex_pair(a3);
dec_to_hex_pair(a4);
dec_to_hex_pair((int)((double)a5 / 0.06));
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, unsigned int a2, unsigned int a3, unsigned int a4, int a5)
{
*(_DWORD *)a1 = 112;
*(_BYTE *)(a1 + 4) = 8;
func7(a2);
func7(a3);
func7(a4);
func7((int)((double)a5 / 0.06));
return 0LL;
}

original_code:
int gen_frame_70 (struct can_frame *frame, int rpm, int map, int engineStatus, int car_speed)
{
  frame->can_id = 0x70;
  frame->can_dlc = 8;
  dec_to_hex_pair(rpm, (char*) &(frame->data[0]), (char*) &(frame->data[1]));
  dec_to_hex_pair(map, (char*) &frame->data[2], (char*) &frame->data[3]);
  dec_to_hex_pair(engineStatus, (char*) &frame->data[4], (char*) &frame->data[5]);
  dec_to_hex_pair((car_speed/0.06), (char *) &frame->data[6], (char*) &frame->data[7]);
  return 0;
}

canonical_original_code:
int gen_frame_70(struct can_frame *frame, int rpm, int map, int engineStatus, int car_speed)
{
  frame->can_id = 0x70;
  frame->can_dlc = 8;
  dec_to_hex_pair(rpm, (char *) &(frame->data[0]), (char *) &(frame->data[1]));
  dec_to_hex_pair(map, (char *) &frame->data[2], (char *) &frame->data[3]);
  dec_to_hex_pair(engineStatus, (char *) &frame->data[4], (char *) &frame->data[5]);
  dec_to_hex_pair((car_speed/0.06), (char *) &frame->data[6], (char *) &frame->data[7]);
  return 0;
}

variable_types: rpm int

variable_types: map int

variable_types: engineStatus int


main

original_code:
int main(int argc, char **argv)
{
  int s;
  struct sockaddr_can addr;
  struct ifreq ifr;
  s = socket(29, SOCK_RAW, 1);
  strcpy(ifr.ifr_ifrn.ifrn_name, "vcan0" );
  ioctl(s, 0x8933, &ifr);
  addr.can_family = 29;
  addr.can_ifindex = ifr.ifr_ifru.ifru_ivalue;
  bind(s, (struct sockaddr *)&addr, sizeof(addr));
  srand((unsigned)time(((void *)0)));
  struct can_frame frame;
  int nbytes;
  int rpm = 1000;
  int speed = 0;
  int gear = 1;
  unsigned int i=0;
  while (speed < 300) {
 struct can_frame frame;
   int r;
    gen_frame_00 (&frame, speed+1, speed+2, speed+3, speed+4);
    nbytes = write(s, &frame, sizeof(struct can_frame));
    r = rand()%5;
    if (speed%10 == 1) {
      gen_frame_08 (&frame, 31, 31, 86, r);
      nbytes = write(s, &frame, sizeof(struct can_frame));
    }
    if ((speed+2)%10 == 1) {
        gen_frame_10 (&frame, 27, 72+r, 110-r, 42);
        nbytes = write(s, &frame, sizeof(struct can_frame));
    }
    gen_frame_70 (&frame, rpm, 50, 0, speed);
    nbytes = write(s, &frame, sizeof(struct can_frame));
    rpm += (25 / gear);
    if (i%10 == 1)
      speed += 1;
    if (rpm > 8700) {
      rpm = 3500;
      gear += 1;
    }
    if (speed == 300) {
      speed = 0;
      rpm = 1000;
      gear = 1;
    }
    i += 1;
    usleep (10000);
  }
  return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
  int s;
  struct sockaddr_can addr;
  struct ifreq ifr;
  s = socket(29, SOCK_RAW, 1);
  strcpy(ifr.ifr_ifrn.ifrn_name, "vcan0" );
  ioctl(s, 0x8933, &ifr);
  addr.can_family = 29;
  addr.can_ifindex = ifr.ifr_ifru.ifru_ivalue;
  bind(s, (struct sockaddr *)&addr, sizeof(addr));
  srand((unsigned int)time(((void *)0)));
  struct can_frame frame;
  int nbytes;
  int rpm = 1000;
  int speed = 0;
  int gear = 1;
  unsigned int i = 0;
  while (speed < 300) {
 struct can_frame frame;
   int r;
    gen_frame_00 (&frame, speed+1, speed+2, speed+3, speed+4);
    nbytes = write(s, &frame, sizeof(struct can_frame));
    r = rand()%5;
    if (speed%10 == 1) {
      gen_frame_08 (&frame, 31, 31, 86, r);
      nbytes = write(s, &frame, sizeof(struct can_frame));
    }
    if ((speed+2)%10 == 1) {
        gen_frame_10 (&frame, 27, 72+r, 110-r, 42);
        nbytes = write(s, &frame, sizeof(struct can_frame));
    }
    gen_frame_70 (&frame, rpm, 50, 0, speed);
    nbytes = write(s, &frame, sizeof(struct can_frame));
    rpm += (25 / gear);
    if (i%10 == 1)
      speed += 1;
    if (rpm > 8700) {
      rpm = 3500;
      gear += 1;
    }
    if (speed == 300) {
      speed = 0;
      rpm = 1000;
      gear = 1;
    }
    i += 1;
    usleep (10000);
  }
  return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: s int

variable_types: struct sockaddr_can { unsigned short can_family; int can_ifindex; union { struct { unsigned int rx_id; } tp; } can_addr; }

variable_types: struct ifreq { union { char ifrn_name[16]; } ifr_ifrn; union { struct sockaddr { unsigned short sa_family; char sa_data[14]; } ifru_addr; struct sockaddr ifru_dstaddr; struct sockaddr ifru_broadaddr; struct sockaddr ifru_netmask; struct sockaddr ifru_hwaddr; short ifru_flags; int ifru_ivalue; int ifru_mtu; struct ifmap { unsigned long mem_start; unsigned long mem_end; unsigned short base_addr; unsigned char irq; unsigned char dma; unsigned char port; } ifru_map; char ifru_slave[16]; char ifru_newname[16]; char *ifru_data; } ifr_ifru; }

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

variable_types: nbytes int

variable_types: speed int

variable_types: gear int

variable_types:
i
unsigned int

variable_types: r int

user_defined_types: struct ifreq { union { char ifrn_name[16]; } ifr_ifrn; union { struct sockaddr ifru_addr; struct sockaddr ifru_dstaddr; struct sockaddr ifru_broadaddr; struct sockaddr ifru_netmask; struct sockaddr ifru_hwaddr; short ifru_flags; int ifru_ivalue; int ifru_mtu; struct ifmap ifru_map; char ifru_slave[16]; char ifru_newname[16]; char *ifru_data; } ifr_ifru; }


validarUsuarioMensaje

decompiled_code:
__int64 __fastcall validarUsuarioMensaje(char *a1, char *a2, const char **a3)
{
char *v3; // rbx
char *v4; // r15
const char *v5; // rbp
size_t v6; // rax
void *v7; // rbx
size_t v8; // rax
char *v9; // rsi
char *v10; // rbx
int i; // er14
__int64 result; // rax
char *v13; // rsi
char *v14; // r12
int j; // er13
char *v16; // rbx
char *v17; // rbp
char *v18; // rax
char *v19; // rax
const char *s1; // [rsp+0h] [rbp-2968h]
char *v22; // [rsp+10h] [rbp-2958h]
char v24[512]; // [rsp+20h] [rbp-2948h] BYREF
char s[10056]; // [rsp+220h] [rbp-2748h] BYREF

v3 = strtok(a1, " ");
v4 = strtok(0LL, " ");
s1 = strtok(0LL, " ");
memset(s, 0, 0x2710uLL);
memset(v24, 0, sizeof(v24));
trimwhitespace(s1);
downcase(v4);
downcase(v3);
v22 = v3;
if ( strcmp(v3, "pull") && strcmp(v3, "status") )
return 0xFFFFFFFFLL;
v5 = *a3;
v6 = strlen(*a3);
v7 = malloc(v6);
v8 = strlen(v5);
memset(v7, 0, v8);
strcpy((char *)v7, v5);
v9 = strtok((char *)v7, "\n");
if ( v9 )
{
strcpy(s, v9);
v10 = &s[100];
for ( i = 0; ; ++i )
{
v13 = strtok(0LL, "\n");
if ( !v13 )
break;
strcpy(v10, v13);
v10 += 100;
}
if ( i < 0 )
{
result = 0xFFFFFFFFLL;
}
else
{
v14 = s;
for ( j = 0; j <= i; ++j )
{
v16 = strtok(v14, ":");
v17 = strtok(0LL, ":");
if ( !strcmp(v4, v16) && !strcmp(s1, v17) )
{
strcpy(a2, v16);
strcpy(a2 + 30, v17);
v18 = strtok(0LL, ":");
strcpy(a2 + 60, v18);
v19 = strtok(0LL, ":");
strcpy(a2 + 90, v19);
return (unsigned int)-((unsigned int)procesarComandos(v22, a2, a3) == -1);
}
v14 += 100;
}
result = 0xFFFFFFFFLL;
}
}
else
{
write(1, "Error archivo de configuracion\n", 0x1FuLL);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1, char *a2, const char **a3)
{
char *v3; // rbx
char *v4; // r15
const char *v5; // rbp
size_t v6; // rax
void *v7; // rbx
size_t v8; // rax
char *v9; // rsi
char *v10; // rbx
int i; // er14
__int64 result; // rax
char *v13; // rsi
char *v14; // r12
int j; // er13
char *v16; // rbx
char *v17; // rbp
char *v18; // rax
char *v19; // rax
const char *s1; // [rsp+0h] [rbp-2968h]
char *v22; // [rsp+10h] [rbp-2958h]
char v24[512]; // [rsp+20h] [rbp-2948h] BYREF
char s[10056]; // [rsp+220h] [rbp-2748h] BYREF

v3 = strtok(a1, " ");
v4 = strtok(0LL, " ");
s1 = strtok(0LL, " ");
memset(s, 0, 0x2710uLL);
memset(v24, 0, sizeof(v24));
trimwhitespace(s1);
downcase(v4);
downcase(v3);
v22 = v3;
if ( strcmp(v3, "pull") && strcmp(v3, "status") )
return 0xFFFFFFFFLL;
v5 = *a3;
v6 = strlen(*a3);
v7 = malloc(v6);
v8 = strlen(v5);
memset(v7, 0, v8);
strcpy((char *)v7, v5);
v9 = strtok((char *)v7, "\n");
if ( v9 )
{
strcpy(s, v9);
v10 = &s[100];
for ( i = 0; ; ++i )
{
v13 = strtok(0LL, "\n");
if ( !v13 )
break;
strcpy(v10, v13);
v10 += 100;
}
if ( i < 0 )
{
result = 0xFFFFFFFFLL;
}
else
{
v14 = s;
for ( j = 0; j <= i; ++j )
{
v16 = strtok(v14, ":");
v17 = strtok(0LL, ":");
if ( !strcmp(v4, v16) && !strcmp(s1, v17) )
{
strcpy(a2, v16);
strcpy(a2 + 30, v17);
v18 = strtok(0LL, ":");
strcpy(a2 + 60, v18);
v19 = strtok(0LL, ":");
strcpy(a2 + 90, v19);
return (unsigned int)-((unsigned int)procesarComandos(v22, a2, a3) == -1);
}
v14 += 100;
}
result = 0xFFFFFFFFLL;
}
}
else
{
write(1, "Error archivo de configuracion\n", 0x1FuLL);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int validarUsuarioMensaje(char *mensaje, DatosUsuario * datosUsuario, DatosConfig *configuracion){
  int i = 0, valido = 0, fd = 0, linea = 0, lineaActual = 0;
  char * comando = strtok(mensaje, " ");
  char * usuarioMensaje = strtok(((void *)0), " ");
  char * passwordMensaje = strtok(((void *)0), " ");
  char *token, *usuario, *password;
  char lineas[100][100];
  char buffer[512];
  memset(lineas, 0, sizeof lineas);
  memset(buffer, 0, sizeof buffer);
  trimwhitespace(passwordMensaje);
  downcase(usuarioMensaje);
  downcase(comando);
  if(strcmp(comando, "pull") != 0 && strcmp(comando, "status") != 0){
    return -1;
  }
  char * aux = (char *)malloc(strlen(configuracion->dbUsuarios) * sizeof(char));
  memset(aux, 0, strlen(configuracion->dbUsuarios)* sizeof(char));
  strcpy(aux, configuracion->dbUsuarios);
  if((token = strtok(aux, "\n")) == ((void *)0)){
    write(1,"Error archivo de configuracion\n",31);
    return -1;
  }
  strcpy(lineas[lineaActual], token);
  while((token = strtok(((void *)0),"\n")) != ((void *)0)){
    lineaActual++;
    strcpy(lineas[lineaActual], token);
  }
  for(i = 0; i<=lineaActual;i++){
    usuario = strtok(lineas[i], ":");
    password = strtok(((void *)0),":");
    if((strcmp(usuarioMensaje, usuario) == 0) && (strcmp(passwordMensaje, password)) == 0){
      valido = 1;
      strcpy(datosUsuario->username, usuario);
      strcpy(datosUsuario->password, password);
      strcpy(datosUsuario->usernameGit, strtok(((void *)0),":"));
      strcpy(datosUsuario->passwordGit, strtok(((void *)0),":"));
      break;
    }
  }
  if(!valido)
    return -1;
  int status = procesarComandos(comando, datosUsuario, configuracion);
  if(status == -1){
    return -1;
  }
  return 0;
}

canonical_original_code:
int validarUsuarioMensaje(char *mensaje, struct DATOSUSUARIO *datosUsuario, struct DATOSCONFIG *configuracion){
  int i = 0; int valido = 0; int fd = 0; int linea = 0; int lineaActual = 0;
  char *comando = strtok(mensaje, " ");
  char *usuarioMensaje = strtok(((void *)0), " ");
  char *passwordMensaje = strtok(((void *)0), " ");
  char *token; char *usuario; char *password;
  char lineas[100][100];
  char buffer[512];
  memset(lineas, 0, sizeof lineas);
  memset(buffer, 0, sizeof buffer);
  trimwhitespace(passwordMensaje);
  downcase(usuarioMensaje);
  downcase(comando);
  if(strcmp(comando, "pull") != 0 && strcmp(comando, "status") != 0){
    return -1;
  }
  char *aux = (char *)malloc(strlen(configuracion->dbUsuarios) * sizeof(char));
  memset(aux, 0, strlen(configuracion->dbUsuarios)* sizeof(char));
  strcpy(aux, configuracion->dbUsuarios);
  if((token = strtok(aux, "\n")) == ((void *)0)){
    write(1,"Error archivo de configuracion\n",31);
    return -1;
  }
  strcpy(lineas[lineaActual], token);
  while((token = strtok(((void *)0),"\n")) != ((void *)0)){
    lineaActual++;
    strcpy(lineas[lineaActual], token);
  }
  for(i = 0; i<=lineaActual;i++){
    usuario = strtok(lineas[i], ":");
    password = strtok(((void *)0),":");
    if((strcmp(usuarioMensaje, usuario) == 0) && (strcmp(passwordMensaje, password)) == 0){
      valido = 1;
      strcpy(datosUsuario->username, usuario);
      strcpy(datosUsuario->password, password);
      strcpy(datosUsuario->usernameGit, strtok(((void *)0),":"));
      strcpy(datosUsuario->passwordGit, strtok(((void *)0),":"));
      break;
    }
  }
  if(!valido)
    return -1;
  int status = procesarComandos(comando, datosUsuario, configuracion);
  if(status == -1){
    return -1;
  }
  return 0;
}

variable_types:
mensaje
char *

variable_types: struct DATOSUSUARIO { char username[30]; char password[30]; char usernameGit[30]; char passwordGit[30]; } *

variable_types: struct DATOSCONFIG { char *dbUsuarios; char backupPath[30]; int puerto; } *

variable_types: i int

variable_types: valido int

variable_types: fd int

variable_types: linea int

variable_types: lineaActual int

variable_types:
comando
char *

variable_types:
usuarioMensaje
char *

variable_types:
passwordMensaje
char *

variable_types:
token
char *

variable_types:
usuario
char *

variable_types:
password
char *

variable_types:
lineas
char [100][100]

variable_types:
buffer
char [512]

variable_types:
aux
char *

variable_types: status int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // ebx
__off_t v5; // rbp
void *v6; // r14
int v7; // ebx
int v9; // ebp
__pid_t v10; // eax
unsigned int v11; // ebx
__int64 v12[5]; // [rsp+0h] [rbp-78h] BYREF
unsigned int v13; // [rsp+28h] [rbp-50h]
struct sockaddr addr; // [rsp+30h] [rbp-48h] BYREF
socklen_t addr_len[11]; // [rsp+4Ch] [rbp-2Ch] BYREF

addr_len[0] = 0;
*(_QWORD *)&addr.sa_family = 0LL;
*(_QWORD *)&addr.sa_data[6] = 0LL;
v3 = open("db_usuarios", 0, envp);
if ( v3 < 0 )
{
perror("open:");
v7 = -1;
}
else
{
v4 = v3;
v5 = lseek(v3, 0LL, 2);
lseek(v4, 0LL, 0);
v6 = malloc(++v5);
read(v4, v6, v5);
v12[0] = (__int64)v6;
v7 = recuperarParametros((unsigned int)argc, argv, v12);
if ( v7 )
{
v7 = -1;
}
else
{
v9 = iniciarServidor(v13);
v10 = fork();
if ( v10 == -1 )
{
die("No se pudo forkear");
}
else if ( !v10 )
{
while ( 1 )
{
addr_len[0] = 16;
v11 = accept(v9, &addr, addr_len);
if ( v11 == -1 )
die("No se pudo aceptar la conexion");
atenderCliente(v11, v12);
if ( close(v11) == -1 )
die("No se pudo cerrar el socket");
}
}
while ( waitpid(-1, 0LL, 0) > 0 )
;
close(v9);
}
}
return v7;
}

original_code:
int main (int argc, char * const argv[])
{
 int fd = 0, fd_cliente = 0, longitud_cliente = 0, puerto = 0,
 cpid = 0, i = 0, file_fd = 0;
 off_t fileSize;
 unsigned long long fileSizeL;
 struct sockaddr cliente;
 DatosConfig configuracion;
 pthread_t tid;
 char * dbUsuarios;
 memset(&cliente,0, sizeof (struct sockaddr));
 if ((file_fd = open ("db_usuarios", 00)) < 0)
 {
  perror("open:");
  return -1;
 }
 fileSize = lseek(file_fd , 0L , 2);
 lseek(file_fd,0L, 0);
 fileSizeL=(unsigned long long) fileSize;
 dbUsuarios = (char *) malloc(sizeof(char) * (fileSizeL+1) );
 read (file_fd, dbUsuarios, fileSizeL+1);
 configuracion.dbUsuarios = dbUsuarios;
 if (recuperarParametros(argc, argv, &configuracion) != 0)
  return -1;
 fd = iniciarServidor(configuracion.puerto);
 for (i = 0; i < 1; i++) {
  cpid = fork();
  if (cpid == -1) {
   die("No se pudo forkear");
  }
  if (cpid == 0) {
   for (;;) {
    longitud_cliente = sizeof cliente;
    fd_cliente = accept(fd, &cliente, &longitud_cliente);
    if (fd_cliente == -1) {
     die("No se pudo aceptar la conexion");
    }
    atenderCliente(fd_cliente, &configuracion);
    if(close(fd_cliente) == -1){
     die("No se pudo cerrar el socket");
    }
   }
  }
 }
 while (waitpid(-1, ((void *)0), 0) > 0);
 close(fd);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 int fd = 0; int fd_cliente = 0; int longitud_cliente = 0; int puerto = 0; int cpid = 0; int i = 0; int file_fd = 0;
 long fileSize;
 unsigned long long fileSizeL;
 struct sockaddr cliente;
 struct DATOSCONFIG configuracion;
 unsigned long tid;
 char *dbUsuarios;
 memset(&cliente,0, sizeof (struct sockaddr));
 if ((file_fd = open ("db_usuarios", 00)) < 0)
 {
  perror("open:");
  return -1;
 }
 fileSize = lseek(file_fd , 0L , 2);
 lseek(file_fd,0L, 0);
 fileSizeL=(unsigned long long) fileSize;
 dbUsuarios = (char *) malloc(sizeof(char) * (fileSizeL+1) );
 read (file_fd, dbUsuarios, fileSizeL+1);
 configuracion.dbUsuarios = dbUsuarios;
 if (recuperarParametros(argc, argv, &configuracion) != 0)
  return -1;
 fd = iniciarServidor(configuracion.puerto);
 for (i = 0; i < 1; i++) {
  cpid = fork();
  if (cpid == -1) {
   die("No se pudo forkear");
  }
  if (cpid == 0) {
   for (;;) {
    longitud_cliente = sizeof cliente;
    fd_cliente = accept(fd, &cliente, &longitud_cliente);
    if (fd_cliente == -1) {
     die("No se pudo aceptar la conexion");
    }
    atenderCliente(fd_cliente, &configuracion);
    if(close(fd_cliente) == -1){
     die("No se pudo cerrar el socket");
    }
   }
  }
 }
 while (waitpid(-1, ((void *)0), 0) > 0);
 close(fd);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: puerto int

variable_types: cpid int

variable_types: fileSize long

variable_types:
fileSizeL
unsigned long long

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

variable_types: struct DATOSCONFIG { char *dbUsuarios; char backupPath[30]; int puerto; }

variable_types:
tid
unsigned long

variable_types:
dbUsuarios
char *


recuperarParametros

decompiled_code:
__int64 __fastcall recuperarParametros(int argc, char **argv, __int64 a3)
{
char *v3; // r15
int i; // er13
unsigned int v5; // ebx
int v6; // eax
int v7; // ebp
char *v8; // rdi
char *v9; // rax
char *v10; // rax
char *v11; // rbx
size_t v12; // rax
char *v15; // [rsp+10h] [rbp-258h] BYREF
char *save_ptr; // [rsp+18h] [rbp-250h] BYREF
char buf[523]; // [rsp+20h] [rbp-248h] BYREF
char nptr[4]; // [rsp+22Bh] [rbp-3Dh] BYREF
char v19; // [rsp+22Fh] [rbp-39h]

*(_DWORD *)nptr = 0;
v19 = 0;
memset(buf, 0, 0x200uLL);
for ( i = 0; ; i = 1 )
{
v5 = getopt(argc, argv, "hp:");
if ( v5 == -1 )
break;
if ( v5 != 112 )
{
printf("Uso: %s\n", *argv);
puts("-h Muestra esta ayuda");
puts("-p XX Sobreescribe el puerto de escucha");
puts("Indique puerto de escucha por defecto en archivo: gitbox.cfg");
exit(1);
}
v3 = optarg;
}
if ( i )
strncpy(nptr, v3, 5uLL);
v6 = open("server.cfg", 0);
v7 = v6;
if ( v6 < 0 )
{
perror("open:");
}
else
{
read(v6, buf, 0x200uLL);
close(v7);
v8 = strtok_r(buf, "\n", &save_ptr);
if ( v8 )
{
strtok_r(v8, "=", &v15);
v9 = strtok_r(0LL, "=", &v15);
if ( !i )
strncpy(nptr, v9, 5uLL);
v10 = strtok_r(0LL, "\n", &save_ptr);
strtok_r(v10, "=", &v15);
v11 = strtok_r(0LL, "=", &v15);
v12 = strlen(v11);
strncpy((char *)(a3 + 8), v11, v12);
*(_DWORD *)(a3 + 40) = atoi(nptr);
v5 = 0;
}
else
{
write(1, "Error archivo de configuracion\n", 0x1FuLL);
}
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func0(int argc, char **argv, __int64 a3)
{
char *v3; // r15
int i; // er13
unsigned int v5; // ebx
int v6; // eax
int v7; // ebp
char *v8; // rdi
char *v9; // rax
char *v10; // rax
char *v11; // rbx
size_t v12; // rax
char *v15; // [rsp+10h] [rbp-258h] BYREF
char *save_ptr; // [rsp+18h] [rbp-250h] BYREF
char buf[523]; // [rsp+20h] [rbp-248h] BYREF
char nptr[4]; // [rsp+22Bh] [rbp-3Dh] BYREF
char v19; // [rsp+22Fh] [rbp-39h]

*(_DWORD *)nptr = 0;
v19 = 0;
memset(buf, 0, 0x200uLL);
for ( i = 0; ; i = 1 )
{
v5 = getopt(argc, argv, "hp:");
if ( v5 == -1 )
break;
if ( v5 != 112 )
{
printf("Uso: %s\n", *argv);
puts("-h Muestra esta ayuda");
puts("-p XX Sobreescribe el puerto de escucha");
puts("Indique puerto de escucha por defecto en archivo: gitbox.cfg");
exit(1);
}
v3 = optarg;
}
if ( i )
strncpy(nptr, v3, 5uLL);
v6 = open("server.cfg", 0);
v7 = v6;
if ( v6 < 0 )
{
perror("open:");
}
else
{
read(v6, buf, 0x200uLL);
close(v7);
v8 = strtok_r(buf, "\n", &save_ptr);
if ( v8 )
{
strtok_r(v8, "=", &v15);
v9 = strtok_r(0LL, "=", &v15);
if ( !i )
strncpy(nptr, v9, 5uLL);
v10 = strtok_r(0LL, "\n", &save_ptr);
strtok_r(v10, "=", &v15);
v11 = strtok_r(0LL, "=", &v15);
v12 = strlen(v11);
strncpy((char *)(a3 + 8), v11, v12);
*(_DWORD *)(a3 + 40) = atoi(nptr);
v5 = 0;
}
else
{
write(1, "Error archivo de configuracion\n", 0x1FuLL);
}
}
return v5;
}

original_code:
int recuperarParametros(int argc, char * const argv[], DatosConfig *configuracion)
{
 int fd = 0, opcion = 0, i = 0, popt = 0;
 char puerto[5], buffer[512];
 char *pvalue, *token, *token2, *save1, *save2;
 memset(puerto,0,sizeof puerto);
 memset(buffer,0,sizeof buffer);
 while((opcion = getopt (argc, argv, "hp:")) != -1){
  switch(opcion){
   case 'p':
    popt = 1;
    pvalue = optarg;
    break;
   case 'h':
   default:
    printf ("Uso: %s\n", argv[0]);
    printf ("-h Muestra esta ayuda\n");
    printf ("-p XX Sobreescribe el puerto de escucha\n");
    printf ("Indique puerto de escucha por defecto en archivo: gitbox.cfg\n");
    exit(1);
  }
 }
 if(popt){
  strncpy(puerto,pvalue,sizeof puerto);
 }
 if ((fd = open ("server.cfg", 00)) < 0)
 {
  perror("open:");
  return -1;
 }
 read(fd, buffer, sizeof buffer);
 close(fd);
 if((token = strtok_r(buffer,"\n",&save1)) == ((void *)0)){
    write(1,"Error archivo de configuracion\n",31);
    return -1;
 }
 strtok_r(token,"=",&save2);
 token2 = strtok_r(((void *)0),"=",&save2);
 if(!popt){
  strncpy(puerto, token2, sizeof puerto);
 }
 token = strtok_r(((void *)0),"\n",&save1);
 strtok_r(token,"=",&save2);
 token2 = strtok_r(((void *)0),"=",&save2);
 strncpy(configuracion->backupPath, token2, strlen(token2));
 configuracion->puerto = atoi(puerto);
 return 0;
}

canonical_original_code:
int recuperarParametros(int argc, char *argv[], struct DATOSCONFIG *configuracion)
{
 int fd = 0; int opcion = 0; int i = 0; int popt = 0;
 char puerto[5]; char buffer[512];
 char *pvalue; char *token; char *token2; char *save1; char *save2;
 memset(puerto,0,sizeof puerto);
 memset(buffer,0,sizeof buffer);
 while((opcion = getopt (argc, argv, "hp:")) != -1){
  switch(opcion){
   case 'p':
    popt = 1;
    pvalue = optarg;
    break;
   case 'h':
   default:
    printf ("Uso: %s\n", argv[0]);
    printf ("-h Muestra esta ayuda\n");
    printf ("-p XX Sobreescribe el puerto de escucha\n");
    printf ("Indique puerto de escucha por defecto en archivo: gitbox.cfg\n");
    exit(1);
  }
 }
 if(popt){
  strncpy(puerto,pvalue,sizeof puerto);
 }
 if ((fd = open ("server.cfg", 00)) < 0)
 {
  perror("open:");
  return -1;
 }
 read(fd, buffer, sizeof buffer);
 close(fd);
 if((token = strtok_r(buffer,"\n",&save1)) == ((void *)0)){
    write(1,"Error archivo de configuracion\n",31);
    return -1;
 }
 strtok_r(token,"=",&save2);
 token2 = strtok_r(((void *)0),"=",&save2);
 if(!popt){
  strncpy(puerto, token2, sizeof puerto);
 }
 token = strtok_r(((void *)0),"\n",&save1);
 strtok_r(token,"=",&save2);
 token2 = strtok_r(((void *)0),"=",&save2);
 strncpy(configuracion->backupPath, token2, strlen(token2));
 configuracion->puerto = atoi(puerto);
 return 0;
}

variable_types: struct DATOSCONFIG { char *dbUsuarios; char backupPath[30]; int puerto; } *

variable_types: fd int

variable_types: opcion int

variable_types: i int

variable_types: popt int

variable_types:
puerto
char [5]

variable_types:
pvalue
char *

variable_types:
token
char *


procesarComandos

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

if ( !strcmp(a1, "pull") )
result = procesarComandoPull(a2, a3 + 8);
else
result = 0xFFFFFFFFLL;
return result;
}

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

if ( !strcmp(a1, "pull") )
result = procesarComandoPull(a2, a3 + 8);
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int procesarComandos(char *comando, DatosUsuario *datosUsuario, DatosConfig *configuracion){
    if(strcmp(comando, "pull") == 0){
      int status = procesarComandoPull(datosUsuario, configuracion->backupPath);
      return status;
    }
    else if(strcmp(comando, "status") == 0){}
    return -1;
}

canonical_original_code:
int procesarComandos(char *comando, struct DATOSUSUARIO *datosUsuario, struct DATOSCONFIG *configuracion){
    if(strcmp(comando, "pull") == 0){
      int status = procesarComandoPull(datosUsuario, configuracion->backupPath);
      return status;
    }
    else if(strcmp(comando, "status") == 0){}
    return -1;
}

variable_types:
comando
char *

variable_types: struct DATOSUSUARIO { char username[30]; char password[30]; char usernameGit[30]; char passwordGit[30]; } *

variable_types: status int

user_defined_types: struct DATOSCONFIG { char *dbUsuarios; char backupPath[30]; int puerto; }


trimwhitespace

decompiled_code:
char *__fastcall trimwhitespace(char *s)
{
const unsigned __int16 *v2; // rbp
char *v3; // rax

v2 = *_ctype_b_loc();
while ( (v2[*s] & 0x2000) != 0 )
++s;
if ( *s )
{
v3 = &s[strlen(s) - 1];
if ( s < v3 )
{
do
{
if ( (v2[*v3] & 0x2000) == 0 )
break;
--v3;
}
while ( s != v3 );
}
v3[1] = 0;
}
return s;
}

canonical_decompiled_code:
char *__fastcall func0(char *s)
{
const unsigned __int16 *v2; // rbp
char *v3; // rax

v2 = *_ctype_b_loc();
while ( (v2[*s] & 0x2000) != 0 )
++s;
if ( *s )
{
v3 = &s[strlen(s) - 1];
if ( s < v3 )
{
do
{
if ( (v2[*v3] & 0x2000) == 0 )
break;
--v3;
}
while ( s != v3 );
}
v3[1] = 0;
}
return s;
}

original_code:
char *trimwhitespace(char *str)
{
  char *end;
  while(((*__ctype_b_loc ())[(int) ((*str))] & (unsigned short int) _ISspace)) str++;
  if(*str == 0)
    return str;
  end = str + strlen(str) - 1;
  while(end > str && ((*__ctype_b_loc ())[(int) ((*end))] & (unsigned short int) _ISspace)) end--;
  *(end+1) = 0;
  return str;
}

canonical_original_code:
char *trimwhitespace(char *str)
{
  char *end;
  while(((*__ctype_b_loc ())[(int) ((*str))] & (unsigned short) _ISspace)) str++;
  if(*str == 0)
    return str;
  end = str + strlen(str) - 1;
  while(end > str && ((*__ctype_b_loc ())[(int) ((*end))] & (unsigned short) _ISspace)) end--;
  *(end+1) = 0;
  return str;
}

variable_types:
str
char *

variable_types:
end
char *

return_type: char *


die

decompiled_code:
void __fastcall __noreturn die(const char *a1)
{
perror(a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func1(const char *a1)
{
perror(a1);
exit(1);
}

original_code:
void die(char *msg){
  perror(msg);
  exit(1);
}

variable_types:
msg
char *


itos

decompiled_code:
int __fastcall itos(char *a1, unsigned int a2)
{
return sprintf(a1, "%d", a2);
}

canonical_decompiled_code:
int __fastcall func2(char *a1, unsigned int a2)
{
return sprintf(a1, "%d", a2);
}

original_code:
void itos(char *string, int number){
  sprintf(string,"%d",number);
}

variable_types:
string
char *

variable_types: number int


downcase

decompiled_code:
void __fastcall downcase(char *a1)
{
char v1; // bl
char *v2; // rbp
const __int32_t **v3; // rdx

v1 = *a1;
if ( *a1 )
{
v2 = a1;
v3 = _ctype_tolower_loc();
do
{
*v2++ = (*v3)[v1];
v1 = *v2;
}
while ( *v2 );
}
}

canonical_decompiled_code:
void __fastcall func3(char *a1)
{
char v1; // bl
char *v2; // rbp
const __int32_t **v3; // rdx

v1 = *a1;
if ( *a1 )
{
v2 = a1;
v3 = _ctype_tolower_loc();
do
{
*v2++ = (*v3)[v1];
v1 = *v2;
}
while ( *v2 );
}
}

original_code:
void downcase(char *string){
  int i = 0;
  for(i = 0; string[i]; i++){
    string[i] = tolower(string[i]);
  }
}


iniciarServidor

decompiled_code:
__int64 __fastcall iniciarServidor(unsigned int a1)
{
int v1; // eax
unsigned int v2; // ebx
char s[5]; // [rsp+3h] [rbp-55h] BYREF
struct addrinfo *pai; // [rsp+8h] [rbp-50h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-48h] BYREF
int optval[3]; // [rsp+4Ch] [rbp-Ch] BYREF

optval[0] = 1;
sprintf(s, "%d", a1);
*(_QWORD *)&req.ai_flags = 1LL;
*(_QWORD *)&req.ai_socktype = 1LL;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
if ( getaddrinfo(0LL, s, &req, &pai) )
{
perror("getaddrinfo:");
exit(1);
}
do
{
v1 = socket(pai->ai_family, pai->ai_socktype, pai->ai_protocol);
v2 = v1;
if ( v1 >= 0 )
{
setsockopt(v1, 1, 2, optval, 4u);
if ( bind(v2, pai->ai_addr, pai->ai_addrlen) )
{
perror("bind");
exit(1);
}
}
pai = pai->ai_next;
}
while ( pai );
freeaddrinfo(0LL);
listen(v2, 10);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1)
{
int v1; // eax
unsigned int v2; // ebx
char s[5]; // [rsp+3h] [rbp-55h] BYREF
struct addrinfo *pai; // [rsp+8h] [rbp-50h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-48h] BYREF
int optval[3]; // [rsp+4Ch] [rbp-Ch] BYREF

optval[0] = 1;
sprintf(s, "%d", a1);
*(_QWORD *)&req.ai_flags = 1LL;
*(_QWORD *)&req.ai_socktype = 1LL;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
if ( getaddrinfo(0LL, s, &req, &pai) )
{
perror("getaddrinfo:");
exit(1);
}
do
{
v1 = socket(pai->ai_family, pai->ai_socktype, pai->ai_protocol);
v2 = v1;
if ( v1 >= 0 )
{
setsockopt(v1, 1, 2, optval, 4u);
if ( bind(v2, pai->ai_addr, pai->ai_addrlen) )
{
perror("bind");
exit(1);
}
}
pai = pai->ai_next;
}
while ( pai );
freeaddrinfo(0LL);
listen(v2, 10);
return v2;
}

original_code:
int iniciarServidor (int puerto)
{
  int fd = 0, opc = 1, sfd = 0;
  struct addrinfo Direccion,*res;
  char auxport[5];
  sprintf(auxport,"%d",puerto);
  memset(&Direccion,0, sizeof (struct addrinfo));
  Direccion.ai_family = 0;
  Direccion.ai_socktype= SOCK_STREAM;
  Direccion.ai_flags = 0x0001;
  if((getaddrinfo(((void *)0),auxport,&Direccion,&res))!=0){
    perror("getaddrinfo:");
    exit(1);
  }
  do
  {
    sfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
    if (sfd < 0)
      continue;
    setsockopt(sfd,1,2,&opc,sizeof (opc));
    if (bind(sfd, res->ai_addr, res->ai_addrlen) != 0){
      perror("bind");
      exit(1);
    }
  }while((res=res->ai_next)!=((void *)0));
  freeaddrinfo(res);
  listen(sfd,10);
  return sfd;
}

canonical_original_code:
int iniciarServidor(int puerto)
{
  int fd = 0; int opc = 1; int sfd = 0;
  struct addrinfo Direccion; struct addrinfo *res;
  char auxport[5];
  sprintf(auxport,"%d",puerto);
  memset(&Direccion,0, sizeof (struct addrinfo));
  Direccion.ai_family = 0;
  Direccion.ai_socktype= SOCK_STREAM;
  Direccion.ai_flags = 0x0001;
  if((getaddrinfo(((void *)0),auxport,&Direccion,&res))!=0){
    perror("getaddrinfo:");
    exit(1);
  }
  do
  {
    sfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
    if (sfd < 0)
      continue;
    setsockopt(sfd,1,2,&opc,sizeof (opc));
    if (bind(sfd, res->ai_addr, res->ai_addrlen) != 0){
      perror("bind");
      exit(1);
    }
  }while((res=res->ai_next)!=((void *)0));
  freeaddrinfo(res);
  listen(sfd,10);
  return sfd;
}

variable_types: puerto int

variable_types: opc int

variable_types: sfd int

variable_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ai_addr; char *ai_canonname; struct addrinfo *ai_next; } *

variable_types:
auxport
char [5]


procesarComandoPull

decompiled_code:
__int64 __fastcall procesarComandoPull(char *src, char *path)
{
size_t v2; // rax
size_t v3; // rax
size_t v4; // rax
int v5; // eax
unsigned int v7; // ebx
unsigned int v8; // eax
char *file[5]; // [rsp+0h] [rbp-E8h] BYREF
int stat_loc; // [rsp+2Ch] [rbp-BCh] BYREF
char s[184]; // [rsp+30h] [rbp-B8h] BYREF

stat_loc = 0;
strcat(s, "https://");
v2 = strlen(src + 60);
strncat(s, src + 60, v2);
*(_WORD *)&s[strlen(s)] = 58;
v3 = strlen(src + 90);
strncat(s, src + 90, v3);
strcat(s, "@github.com");
*(_WORD *)&s[strlen(s)] = 47;
v4 = strlen(src + 60);
strncat(s, src + 60, v4);
*(_WORD *)&s[strlen(s)] = 47;
strcat(s, "gitbox.git");
file[0] = (char *)&unk_1B6;
file[1] = "pull";
file[2] = s;
file[3] = "master";
file[4] = 0LL;
v5 = fork();
if ( v5 < 0 )
{
puts("*** ERROR: forking child process failed");
exit(1);
}
if ( !v5 )
{
v7 = getpgrp();
v8 = getpid();
printf("%d belongs to process group %d\n", v8, v7);
strcat(path, src);
chdir(path);
execvp(file[0], file);
puts("*** ERROR: exec failed");
exit(1);
}
waitpid(v5, &stat_loc, 0);
return (unsigned int)stat_loc;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *src, char *path)
{
size_t v2; // rax
size_t v3; // rax
size_t v4; // rax
int v5; // eax
unsigned int v7; // ebx
unsigned int v8; // eax
char *file[5]; // [rsp+0h] [rbp-E8h] BYREF
int stat_loc; // [rsp+2Ch] [rbp-BCh] BYREF
char s[184]; // [rsp+30h] [rbp-B8h] BYREF

stat_loc = 0;
strcat(s, "https://");
v2 = strlen(src + 60);
strncat(s, src + 60, v2);
*(_WORD *)&s[strlen(s)] = 58;
v3 = strlen(src + 90);
strncat(s, src + 90, v3);
strcat(s, "@github.com");
*(_WORD *)&s[strlen(s)] = 47;
v4 = strlen(src + 60);
strncat(s, src + 60, v4);
*(_WORD *)&s[strlen(s)] = 47;
strcat(s, "gitbox.git");
file[0] = (char *)&unk_1B6;
file[1] = "pull";
file[2] = s;
file[3] = "master";
file[4] = 0LL;
v5 = fork();
if ( v5 < 0 )
{
puts("*** ERROR: forking child process failed");
exit(1);
}
if ( !v5 )
{
v7 = getpgrp();
v8 = getpid();
printf("%d belongs to process group %d\n", v8, v7);
strcat(path, src);
chdir(path);
execvp(file[0], file);
puts("*** ERROR: exec failed");
exit(1);
}
waitpid(v5, &stat_loc, 0);
return (unsigned int)stat_loc;
}

original_code:
int procesarComandoPull(DatosUsuario *datosUsuario, char * path){
  char origin[130];
  pid_t pid;
  int status = 0;
  strncat(origin, "https://",8);
  strncat(origin, datosUsuario->usernameGit, strlen(datosUsuario->usernameGit));
  strncat(origin, ":",1);
  strncat(origin, datosUsuario->passwordGit, strlen(datosUsuario->passwordGit));
  strncat(origin, "@github.com",11);
  strncat(origin, "/", 1);
  strncat(origin, datosUsuario->usernameGit, strlen(datosUsuario->usernameGit));
  strncat(origin, "/", 1);
  strncat(origin, "gitbox.git",10);
  char *command[] = { "git", "pull", origin, "master", ((void *)0) };
  pid = fork();
  if (pid < 0) {
      printf("*** ERROR: forking child process failed\n");
      exit(1);
  }
  else if (pid == 0) {
      printf( "%d belongs to process group %d\n", getpid(), getpgrp() );
      strcat(path,datosUsuario->username);
      chdir(path);
      execvp(command[0], command);
      printf("*** ERROR: exec failed\n");
      exit(1);
  }
  else{
      waitpid(pid, &status, 0);
    switch(status){
      case 0:
        return 0;
        break;
      default:
        return status;
        break;
    }
  }
}

canonical_original_code:
int procesarComandoPull(struct DATOSUSUARIO *datosUsuario, char *path){
  char origin[130];
  int pid;
  int status = 0;
  strncat(origin, "https://",8);
  strncat(origin, datosUsuario->usernameGit, strlen(datosUsuario->usernameGit));
  strncat(origin, ":",1);
  strncat(origin, datosUsuario->passwordGit, strlen(datosUsuario->passwordGit));
  strncat(origin, "@github.com",11);
  strncat(origin, "/", 1);
  strncat(origin, datosUsuario->usernameGit, strlen(datosUsuario->usernameGit));
  strncat(origin, "/", 1);
  strncat(origin, "gitbox.git",10);
  char *command[] = { "git", "pull", origin, "master", ((void *)0) };
  pid = fork();
  if (pid < 0) {
      printf("*** ERROR: forking child process failed\n");
      exit(1);
  }
  else if (pid == 0) {
      printf( "%d belongs to process group %d\n", getpid(), getpgrp() );
      strcat(path,datosUsuario->username);
      chdir(path);
      execvp(command[0], command);
      printf("*** ERROR: exec failed\n");
      exit(1);
  }
  else{
      waitpid(pid, &status, 0);
    switch(status){
      case 0:
        return 0;
        break;
      default:
        return status;
        break;
    }
  }
}

variable_types:
path
char *

variable_types:
origin
char [130]

variable_types: pid int

variable_types:
command
char *[]

user_defined_types: struct DATOSUSUARIO { char username[30]; char password[30]; char usernameGit[30]; char passwordGit[30]; }


atenderCliente

decompiled_code:
__int64 __fastcall atenderCliente(int fd, __int64 a2)
{
__int64 result; // rax
_BYTE v3[128]; // [rsp+0h] [rbp-298h] BYREF
char v4[128]; // [rsp+80h] [rbp-218h] BYREF
__int16 v5; // [rsp+100h] [rbp-198h]
char v6[296]; // [rsp+110h] [rbp-188h] BYREF
int v7; // [rsp+238h] [rbp-60h]
__int64 buf[6]; // [rsp+240h] [rbp-58h] BYREF
__int16 v9; // [rsp+270h] [rbp-28h]

buf[0] = 0LL;
buf[1] = 0LL;
buf[2] = 0LL;
buf[3] = 0LL;
buf[4] = 0LL;
buf[5] = 0LL;
v9 = 0;
memset(v6, 0, sizeof(v6));
v7 = 0;
memset(v4, 0, sizeof(v4));
v5 = 0;
memset(v3, 0, 0x78uLL);
if ( write(fd, "Bienvenido a GitBox\n", 0x14uLL) == -1 )
{
perror("Write: \n");
result = 0xFFFFFFFFLL;
}
else
{
read(fd, buf, 0x32uLL);
result = (unsigned int)-((unsigned int)validarUsuarioMensaje(buf, v3, a2) == -1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int fd, __int64 a2)
{
__int64 result; // rax
_BYTE v3[128]; // [rsp+0h] [rbp-298h] BYREF
char v4[128]; // [rsp+80h] [rbp-218h] BYREF
__int16 v5; // [rsp+100h] [rbp-198h]
char v6[296]; // [rsp+110h] [rbp-188h] BYREF
int v7; // [rsp+238h] [rbp-60h]
__int64 buf[6]; // [rsp+240h] [rbp-58h] BYREF
__int16 v9; // [rsp+270h] [rbp-28h]

buf[0] = 0LL;
buf[1] = 0LL;
buf[2] = 0LL;
buf[3] = 0LL;
buf[4] = 0LL;
buf[5] = 0LL;
v9 = 0;
memset(v6, 0, sizeof(v6));
v7 = 0;
memset(v4, 0, sizeof(v4));
v5 = 0;
memset(v3, 0, 0x78uLL);
if ( write(fd, "Bienvenido a GitBox\n", 0x14uLL) == -1 )
{
perror("Write: \n");
result = 0xFFFFFFFFLL;
}
else
{
read(fd, buf, 0x32uLL);
result = (unsigned int)-((unsigned int)validarUsuarioMensaje(buf, v3, a2) == -1);
}
return result;
}

original_code:
int atenderCliente(int fd_cliente, DatosConfig *configuracion)
{
 int bytesLeidos = 0;
 char mensaje[50], strAux[300], origin[130];
 DatosUsuario datosUsuario;
 memset(mensaje, 0, sizeof mensaje);
 memset(strAux, 0, sizeof strAux);
 memset(origin, 0, sizeof origin);
 memset(&datosUsuario, 0, sizeof (struct DATOSUSUARIO));
 if((write(fd_cliente,"Bienvenido a GitBox\n", 20))==-1){
  perror("Write: \n");
  return -1;
 }
 bytesLeidos = read (fd_cliente, mensaje, sizeof mensaje);
 if(validarUsuarioMensaje(mensaje, &datosUsuario, configuracion) == -1){
  return -1;
 }
 return 0;
}

canonical_original_code:
int atenderCliente(int fd_cliente, struct DATOSCONFIG *configuracion)
{
 int bytesLeidos = 0;
 char mensaje[50]; char strAux[300]; char origin[130];
 struct DATOSUSUARIO datosUsuario;
 memset(mensaje, 0, sizeof mensaje);
 memset(strAux, 0, sizeof strAux);
 memset(origin, 0, sizeof origin);
 memset(&datosUsuario, 0, sizeof (struct DATOSUSUARIO));
 if((write(fd_cliente,"Bienvenido a GitBox\n", 20))==-1){
  perror("Write: \n");
  return -1;
 }
 bytesLeidos = read (fd_cliente, mensaje, sizeof mensaje);
 if(validarUsuarioMensaje(mensaje, &datosUsuario, configuracion) == -1){
  return -1;
 }
 return 0;
}

variable_types: struct DATOSCONFIG { char *dbUsuarios; char backupPath[30]; int puerto; } *

variable_types: bytesLeidos int

variable_types:
mensaje
char [50]

variable_types:
strAux
char [300]

variable_types: struct DATOSUSUARIO { char username[30]; char password[30]; char usernameGit[30]; char passwordGit[30]; }


repo: tinito/ppsi-chibios

decompiled_code:
__int64 __fastcall pty_server_do_count(__int64 a1, __int64 a2, _QWORD *a3)
{
*a3 = *(_QWORD *)saved_pc;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, _QWORD *a3)
{
*a3 = *(_QWORD *)saved_pc;
return 0LL;
}

original_code:
static int pty_server_do_count(const struct minipc_pd *pd,
          uint32_t *args, void *ret)
{
 *(struct pty_counts *)ret = *saved_pc;
 return 0;
}

canonical_original_code:
static int pty_server_do_count(struct minipc_pd *pd, unsigned int *args, void *ret)
{
 *(struct pty_counts *)ret = *saved_pc;
 return 0;
}

variable_types: struct minipc_pd { int (*f)(struct minipc_pd *, unsigned int *args, void *retval); char name[20]; unsigned int flags; unsigned int retval; unsigned int args[]; } *

variable_types:
args
unsigned int *

variable_types:
ret
void *


decompiled_code:
__int64 __fastcall pty_server_do_stat(__int64 a1, const char *a2, __m128i *a3)
{
struct stat v5; // [rsp+0h] [rbp-98h] BYREF

if ( stat(a2, &v5) < 0 )
return 0xFFFFFFFFLL;
*a3 = _mm_loadu_si128((const __m128i *)&v5);
a3[1] = _mm_loadu_si128((const __m128i *)&v5.st_nlink);
a3[2] = _mm_loadu_si128((const __m128i *)&v5.st_gid);
a3[3] = _mm_loadu_si128((const __m128i *)&v5.st_size);
a3[4] = _mm_loadu_si128((const __m128i *)&v5.st_blocks);
a3[5] = _mm_loadu_si128((const __m128i *)&v5.st_atim.tv_nsec);
a3[6] = _mm_loadu_si128((const __m128i *)&v5.st_mtim.tv_nsec);
a3[7] = _mm_loadu_si128((const __m128i *)&v5.st_ctim.tv_nsec);
a3[8] = _mm_loadu_si128((const __m128i *)&v5.__unused[1]);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, const char *a2, __m128i *a3)
{
struct stat v5; // [rsp+0h] [rbp-98h] BYREF

if ( stat(a2, &v5) < 0 )
return 0xFFFFFFFFLL;
*a3 = _mm_loadu_si128((const __m128i *)&v5);
a3[1] = _mm_loadu_si128((const __m128i *)&v5.st_nlink);
a3[2] = _mm_loadu_si128((const __m128i *)&v5.st_gid);
a3[3] = _mm_loadu_si128((const __m128i *)&v5.st_size);
a3[4] = _mm_loadu_si128((const __m128i *)&v5.st_blocks);
a3[5] = _mm_loadu_si128((const __m128i *)&v5.st_atim.tv_nsec);
a3[6] = _mm_loadu_si128((const __m128i *)&v5.st_mtim.tv_nsec);
a3[7] = _mm_loadu_si128((const __m128i *)&v5.st_ctim.tv_nsec);
a3[8] = _mm_loadu_si128((const __m128i *)&v5.__unused[1]);
return 0LL;
}

original_code:
static int pty_server_do_stat(const struct minipc_pd *pd,
          uint32_t *args, void *ret)
{
 struct stat stbuf;
 char *fname = (void *)args;
 if (stat(fname, &stbuf) < 0)
  return -1;
 memcpy(ret, &stbuf, sizeof(stbuf));
 return 0;
}

canonical_original_code:
static int pty_server_do_stat(struct minipc_pd *pd, unsigned int *args, void *ret)
{
 struct stat stbuf;
 char *fname = (void *)args;
 if (stat(fname, &stbuf) < 0)
  return -1;
 memcpy(ret, &stbuf, sizeof(stbuf));
 return 0;
}

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

variable_types:
fname
char *

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

user_defined_types: struct minipc_pd { int (*f)(struct minipc_pd *, unsigned int *args, void *retval); char name[20]; unsigned int flags; unsigned int retval; unsigned int args[]; }


decompiled_code:
__int64 __fastcall pty_server_do_strlen(__int64 a1, const char *a2, _DWORD *a3)
{
*a3 = strlen(a2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, const char *a2, _DWORD *a3)
{
*a3 = strlen(a2);
return 0LL;
}

original_code:
static int pty_server_do_strlen(const struct minipc_pd *pd,
          uint32_t *args, void *ret)
{
 char *s = (void *)args;
 *(int *)ret = strlen(s);
 return 0;
}

canonical_original_code:
static int pty_server_do_strlen(struct minipc_pd *pd, unsigned int *args, void *ret)
{
 char *s = (void *)args;
 *(int *)ret = strlen(s);
 return 0;
}

variable_types:
s
char *


decompiled_code:
__int64 __fastcall pty_server_do_strcat(__int64 a1, const char *a2, char *a3)
{
const char *v4; // r12
size_t v5; // rax
char v7[280]; // [rsp+0h] [rbp-118h] BYREF

v4 = (const char *)minipc_get_next_arg(a2, *(unsigned int *)(a1 + 36));
strncpy(v7, a2, 0x100uLL);
v5 = strlen(a2);
strncat(v7, v4, 256 - v5);
strcpy(a3, v7);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, const char *a2, char *a3)
{
const char *v4; // r12
size_t v5; // rax
char v7[280]; // [rsp+0h] [rbp-118h] BYREF

v4 = (const char *)minipc_get_next_arg(a2, *(unsigned int *)(a1 + 36));
strncpy(v7, a2, 0x100uLL);
v5 = strlen(a2);
strncat(v7, v4, 256 - v5);
strcpy(a3, v7);
return 0LL;
}

original_code:
static int pty_server_do_strcat(const struct minipc_pd *pd,
          uint32_t *args, void *ret)
{
 char *s, *t;
 char scat[256];
 s = (void *)args;
 args = minipc_get_next_arg(args, pd->args[0]);
 t = (void *)args;
 strncpy(scat, s, sizeof(scat));
 strncat(scat, t, sizeof(scat) - strlen(s));
 strcpy(ret, scat);
 return 0;
}

canonical_original_code:
static int pty_server_do_strcat(struct minipc_pd *pd, unsigned int *args, void *ret)
{
 char *s; char *t;
 char scat[256];
 s = (void *)args;
 args = minipc_get_next_arg(args, pd->args[0]);
 t = (void *)args;
 strncpy(scat, s, sizeof(scat));
 strncat(scat, t, sizeof(scat) - strlen(s));
 strcpy(ret, scat);
 return 0;
}

variable_types:
t
char *

variable_types:
scat
char [256]


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

v2 = strlen(a2);
write(saved_fdm, a2, v2);
write(saved_fdm, &unk_1F4, 1uLL);
return 0LL;
}

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

v2 = strlen(a2);
write(saved_fdm, a2, v2);
write(saved_fdm, &unk_1F4, 1uLL);
return 0LL;
}

original_code:
static int pty_server_do_feed(const struct minipc_pd *pd,
          uint32_t *args, void *ret)
{
 char *command = (void *)args;
 int wrote;
 wrote = write(saved_fdm, command, strlen(command));
 wrote += write(saved_fdm, "\n", 1);
 return 0;
}

canonical_original_code:
static int pty_server_do_feed(struct minipc_pd *pd, unsigned int *args, void *ret)
{
 char *command = (void *)args;
 int wrote;
 wrote = write(saved_fdm, command, strlen(command));
 wrote += write(saved_fdm, "\n", 1);
 return 0;
}

variable_types:
command
char *

variable_types: wrote int


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

v2 = (const char *)minipc_get_next_arg(a2, *(unsigned int *)(a1 + 36));
setenv(a2, v2, 1);
return 0LL;
}

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

v2 = (const char *)minipc_get_next_arg(a2, *(unsigned int *)(a1 + 36));
setenv(a2, v2, 1);
return 0LL;
}

original_code:
static int pty_server_do_setenv(const struct minipc_pd *pd,
          uint32_t *args, void *ret)
{
 char *envname = (void *)args;
 char *envval;
 args = minipc_get_next_arg(args, pd->args[0]);
 envval = (void *)args;
 setenv(envname, envval, 1);
 return 0;
}

canonical_original_code:
static int pty_server_do_setenv(struct minipc_pd *pd, unsigned int *args, void *ret)
{
 char *envname = (void *)args;
 char *envval;
 args = minipc_get_next_arg(args, pd->args[0]);
 envval = (void *)args;
 setenv(envname, envval, 1);
 return 0;
}

variable_types:
envname
char *

variable_types:
envval
char *


decompiled_code:
__int64 __fastcall pty_server_do_getenv(__int64 a1, const char *a2, char *a3)
{
char *v4; // rax

v4 = getenv(a2);
strcpy(a3, v4);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, const char *a2, char *a3)
{
char *v4; // rax

v4 = getenv(a2);
strcpy(a3, v4);
return 0LL;
}

original_code:
static int pty_server_do_getenv(const struct minipc_pd *pd,
          uint32_t *args, void *ret)
{
 char *envname = (void *)args;
 char *res = getenv(envname);
 strcpy(ret, res);
 return 0;
}

canonical_original_code:
static int pty_server_do_getenv(struct minipc_pd *pd, unsigned int *args, void *ret)
{
 char *envname = (void *)args;
 char *res = getenv(envname);
 strcpy(ret, res);
 return 0;
}

variable_types:
res
char *