decompiled_code:
__int64 __fastcall uart_init(int a1, int a2)
{
speed_t v2; // ebx
int v3; // ebp
unsigned int v4; // eax
tcflag_t v5; // eax
cc_t *v6; // rax
int v7; // ebx
__int64 result; // rax
struct termios v9; // [rsp+0h] [rbp-F8h] BYREF
struct sigaction v10; // [rsp+40h] [rbp-B8h] BYREF
char v11; // [rsp+DCh] [rbp-1Ch]
char v12[3]; // [rsp+DDh] [rbp-1Bh] BYREF

v11 = 17;
qmemcpy(v12, "\"3D", sizeof(v12));
hostendian = 0;
if ( a1 == 19200 )
{
v2 = 14;
}
else if ( a1 > 19200 )
{
if ( a1 == 115200 )
{
v2 = 4098;
}
else if ( a1 <= 115200 )
{
if ( a1 == 38400 )
{
v2 = 15;
}
else
{
if ( a1 != 57600 )
goto LABEL_22;
v2 = 4097;
}
}
else
{
v2 = 4099;
if ( a1 != 230400 )
goto LABEL_22;
}
}
else if ( a1 == 2400 )
{
v2 = 11;
}
else if ( a1 <= 2400 )
{
if ( a1 == 1200 )
{
v2 = 9;
}
else
{
if ( a1 != 1800 )
goto LABEL_22;
v2 = 10;
}
}
else
{
if ( a1 != 4800 )
{
if ( a1 == 9600 )
{
v2 = 13;
goto LABEL_11;
}
LABEL_22:
generateError("Unsupported baud rate requested");
return 0LL;
}
v2 = 12;
}
LABEL_11:
v3 = open("/dev/ttyAMA0", 2306);
uartfd = v3;
if ( v3 == -1 )
{
generateError("Could not open /dev/ttyAMA0");
result = 0LL;
}
else
{
v10.sa_handler = (__sighandler_t)sigHandlerIO;
v10.sa_flags = 0;
v10.sa_restorer = 0LL;
sigaction(29, &v10, 0LL);
v4 = getpid();
fcntl(v3, 8, v4);
fcntl(uartfd, 4, 0x2000LL);
v9.c_iflag = 0;
if ( a2 )
{
v9.c_iflag = 16;
v9.c_oflag = 0;
v5 = 944;
if ( a2 != 1 )
v5 = 432;
v9.c_cflag = v5;
}
else
{
v9.c_oflag = 0;
v9.c_cflag = 176;
}
v9.c_lflag = 0;
v6 = v9.c_cc;
do
*v6++ = 0;
while ( v6 != &v9.c_cc[32] );
v9.c_cc[6] = 0;
v9.c_cc[5] = 0;
cfsetospeed(&v9, v2);
cfsetispeed(&v9, v2);
v7 = uartfd;
tcsetattr(uartfd, 2, &v9);
tcflow(v7, 3);
tcflush(v7, 2);
qb_initialize(&queuebuffer);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, int a2)
{
speed_t v2; // ebx
int v3; // ebp
unsigned int v4; // eax
tcflag_t v5; // eax
cc_t *v6; // rax
int v7; // ebx
__int64 result; // rax
struct termios v9; // [rsp+0h] [rbp-F8h] BYREF
struct sigaction v10; // [rsp+40h] [rbp-B8h] BYREF
char v11; // [rsp+DCh] [rbp-1Ch]
char v12[3]; // [rsp+DDh] [rbp-1Bh] BYREF

v11 = 17;
qmemcpy(v12, "\"3D", sizeof(v12));
hostendian = 0;
if ( a1 == 19200 )
{
v2 = 14;
}
else if ( a1 > 19200 )
{
if ( a1 == 115200 )
{
v2 = 4098;
}
else if ( a1 <= 115200 )
{
if ( a1 == 38400 )
{
v2 = 15;
}
else
{
if ( a1 != 57600 )
goto LABEL_22;
v2 = 4097;
}
}
else
{
v2 = 4099;
if ( a1 != 230400 )
goto LABEL_22;
}
}
else if ( a1 == 2400 )
{
v2 = 11;
}
else if ( a1 <= 2400 )
{
if ( a1 == 1200 )
{
v2 = 9;
}
else
{
if ( a1 != 1800 )
goto LABEL_22;
v2 = 10;
}
}
else
{
if ( a1 != 4800 )
{
if ( a1 == 9600 )
{
v2 = 13;
goto LABEL_11;
}
LABEL_22:
func2("Unsupported baud rate requested");
return 0LL;
}
v2 = 12;
}
LABEL_11:
v3 = open("/dev/ttyAMA0", 2306);
uartfd = v3;
if ( v3 == -1 )
{
func2("Could not open /dev/ttyAMA0");
result = 0LL;
}
else
{
v10.sa_handler = (__sighandler_t)sigHandlerIO;
v10.sa_flags = 0;
v10.sa_restorer = 0LL;
sigaction(29, &v10, 0LL);
v4 = getpid();
fcntl(v3, 8, v4);
fcntl(uartfd, 4, 0x2000LL);
v9.c_iflag = 0;
if ( a2 )
{
v9.c_iflag = 16;
v9.c_oflag = 0;
v5 = 944;
if ( a2 != 1 )
v5 = 432;
v9.c_cflag = v5;
}
else
{
v9.c_oflag = 0;
v9.c_cflag = 176;
}
v9.c_lflag = 0;
v6 = v9.c_cc;
do
*v6++ = 0;
while ( v6 != &v9.c_cc[32] );
v9.c_cc[6] = 0;
v9.c_cc[5] = 0;
cfsetospeed(&v9, v2);
cfsetispeed(&v9, v2);
v7 = uartfd;
tcsetattr(uartfd, 2, &v9);
tcflow(v7, 3);
tcflush(v7, 2);
qb_initialize(&queuebuffer);
result = 1LL;
}
return result;
}

original_code:
int uart_init(int baudrate, UARTParity parity) {
 uint32_t test;
 char *set = (char *)&test;
 set[0] = 0x11;
 set[1] = 0x22;
 set[2] = 0x33;
 set[3] = 0x44;
 if (test == 0x11223344)
  hostendian = 1;
 else if (test == 0x44332211)
  hostendian = 0;
 else
  hostendian = -1;
 speed_t baud;
 switch (baudrate) {
  case 1200:
   baud = 0000011;
   break;
  case 1800:
   baud = 0000012;
   break;
  case 2400:
   baud = 0000013;
   break;
  case 4800:
   baud = 0000014;
   break;
  case 9600:
   baud = 0000015;
   break;
  case 19200:
   baud = 0000016;
   break;
  case 38400:
   baud = 0000017;
   break;
  case 57600:
   baud = 0010001;
   break;
  case 115200:
   baud = 0010002;
   break;
  case 230400:
   baud = 0010003;
   break;
  default:
   generateError("Unsupported baud rate requested");
   return 0;
 }
 uartfd = open("/dev/ttyAMA0", 02 | 0400 | 04000);
 if (uartfd == -1) {
  generateError("Could not open /dev/ttyAMA0");
  return 0;
 }
 struct sigaction sa;
 sa.__sigaction_handler.sa_handler = sigHandlerIO;
 sa.sa_flags = 0;
 sa.sa_restorer = ((void *)0);
 sigaction(29, &sa, ((void *)0));
 fcntl(uartfd, 8, getpid());
 fcntl(uartfd, 4, 020000);
 struct termios tprops;
 tprops.c_iflag = 0;
 if (parity != UART_PARDISABLE)
  tprops.c_iflag = 0000020;
 tprops.c_oflag = 0;
 tprops.c_cflag = 0000060 | 0000200;
 if (parity != UART_PARDISABLE) {
  tprops.c_cflag |= 0000400;
  if (parity == UART_PARODD)
   tprops.c_cflag |= 0001000;
 }
 tprops.c_lflag = 0;
 int cc;
 for (cc = 0; cc < 32; ++cc)
  tprops.c_cc[cc] = '\0';
 tprops.c_cc[6] = 0;
 tprops.c_cc[5] = 0;
 cfsetospeed(&tprops, baud);
 cfsetispeed(&tprops, baud);
 tcsetattr(uartfd, 2, &tprops);
 tcflow(uartfd, 1 | 3);
 tcflush(uartfd, 2);
 qb_initialize(&queuebuffer);
 return 1;
}

canonical_original_code:
int uart_init(int baudrate, enum _UARTParity parity) {
 unsigned int test;
 char *set = (char *)&test;
 set[0] = 0x11;
 set[1] = 0x22;
 set[2] = 0x33;
 set[3] = 0x44;
 if (test == 0x11223344)
  hostendian = 1;
 else if (test == 0x44332211)
  hostendian = 0;
 else
  hostendian = -1;
 unsigned int baud;
 switch (baudrate) {
  case 1200:
   baud = 0000011;
   break;
  case 1800:
   baud = 0000012;
   break;
  case 2400:
   baud = 0000013;
   break;
  case 4800:
   baud = 0000014;
   break;
  case 9600:
   baud = 0000015;
   break;
  case 19200:
   baud = 0000016;
   break;
  case 38400:
   baud = 0000017;
   break;
  case 57600:
   baud = 0010001;
   break;
  case 115200:
   baud = 0010002;
   break;
  case 230400:
   baud = 0010003;
   break;
  default:
   generateError("Unsupported baud rate requested");
   return 0;
 }
 uartfd = open("/dev/ttyAMA0", 02 | 0400 | 04000);
 if (uartfd == -1) {
  generateError("Could not open /dev/ttyAMA0");
  return 0;
 }
 struct sigaction sa;
 sa.__sigaction_handler.sa_handler = sigHandlerIO;
 sa.sa_flags = 0;
 sa.sa_restorer = ((void *)0);
 sigaction(29, &sa, ((void *)0));
 fcntl(uartfd, 8, getpid());
 fcntl(uartfd, 4, 020000);
 struct termios tprops;
 tprops.c_iflag = 0;
 if (parity != UART_PARDISABLE)
  tprops.c_iflag = 0000020;
 tprops.c_oflag = 0;
 tprops.c_cflag = 0000060 | 0000200;
 if (parity != UART_PARDISABLE) {
  tprops.c_cflag |= 0000400;
  if (parity == UART_PARODD)
   tprops.c_cflag |= 0001000;
 }
 tprops.c_lflag = 0;
 int cc;
 for (cc = 0; cc < 32; ++cc)
  tprops.c_cc[cc] = '\0';
 tprops.c_cc[6] = 0;
 tprops.c_cc[5] = 0;
 cfsetospeed(&tprops, baud);
 cfsetispeed(&tprops, baud);
 tcsetattr(uartfd, 2, &tprops);
 tcflow(uartfd, 1 | 3);
 tcflush(uartfd, 2);
 qb_initialize(&queuebuffer);
 return 1;
}

variable_types: baudrate int

variable_types: enum _UARTParity { UART_PARDISABLE=0, UART_PARODD=1, UART_PAREVEN=2 }

variable_types:
test
unsigned int

variable_types:
set
char *

variable_types:
baud
unsigned int

variable_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } *, void *); } __sigaction_handler; struct __sigset_t { unsigned long __val[-1]; } sa_mask; int sa_flags; void (*sa_restorer)(); }

variable_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; }

variable_types: cc int

user_defined_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t *, void *); } __sigaction_handler; struct __sigset_t sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; }


decompiled_code:
__int64 uart_deinit()
{
__int64 result; // rax

if ( close(uartfd) )
{
generateError("Could not close /dev/ttyAMA0");
result = 0LL;
}
else
{
qb_free(&queuebuffer);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 func4()
{
__int64 result; // rax

if ( close(uartfd) )
{
func2("Could not close /dev/ttyAMA0");
result = 0LL;
}
else
{
qb_free(&queuebuffer);
result = 1LL;
}
return result;
}

original_code:
int uart_deinit() {
 if (close(uartfd) != 0) {
  generateError("Could not close /dev/ttyAMA0");
  return 0;
 }
 qb_free(&queuebuffer);
 return 1;
}

return_type: int


decompiled_code:
__int64 __fastcall uart_write(void *buf, size_t n)
{
__int64 result; // rax

if ( uartfd == -1 )
{
generateError("UART has not been initialized");
result = 0LL;
}
else
{
write(uartfd, buf, n);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(void *buf, size_t n)
{
__int64 result; // rax

if ( uartfd == -1 )
{
func2("UART has not been initialized");
result = 0LL;
}
else
{
write(uartfd, buf, n);
result = 1LL;
}
return result;
}

original_code:
int uart_write(const void *buffer, size_t len) {
 if (uartfd == -1) {
  generateError("UART has not been initialized");
  return 0;
 }
 write(uartfd, buffer, len);
 return 1;
}

canonical_original_code:
int uart_write(void *buffer, unsigned long len) {
 if (uartfd == -1) {
  generateError("UART has not been initialized");
  return 0;
 }
 write(uartfd, buffer, len);
 return 1;
}

variable_types:
buffer
void *

variable_types:
len
unsigned long


decompiled_code:
__int64 __fastcall uart_writeChar(char a1)
{
char buf[12]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = a1;
return uart_write(buf, 1uLL);
}

canonical_decompiled_code:
__int64 __fastcall func6(char a1)
{
char buf[12]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = a1;
return func5(buf, 1uLL);
}

original_code:
int uart_writeChar(char c) {
 return uart_write(&c, 1);
}

variable_types: c char


decompiled_code:
__int64 __fastcall uart_writeUBE16(__int16 a1)
{
__int64 result; // rax
__int16 v2[9]; // [rsp+Ch] [rbp-1Ch] BYREF
char buf[10]; // [rsp+1Eh] [rbp-Ah] BYREF

v2[0] = a1;
if ( hostendian == 1 )
return uart_write(v2, 2uLL);
if ( hostendian )
{
generateError("System endianness is not supported. Use uart_write()");
result = 0LL;
}
else
{
swapEndian(v2, buf, 2LL);
result = uart_write(buf, 2uLL);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int16 a1)
{
__int64 result; // rax
__int16 v2[9]; // [rsp+Ch] [rbp-1Ch] BYREF
char buf[10]; // [rsp+1Eh] [rbp-Ah] BYREF

v2[0] = a1;
if ( hostendian == 1 )
return func5(v2, 2uLL);
if ( hostendian )
{
func2("System endianness is not supported. Use uart_write()");
result = 0LL;
}
else
{
func0(v2, buf, 2LL);
result = func5(buf, 2uLL);
}
return result;
}

original_code:
int uart_writeUBE16(uint16_t i) {
 if (hostendian == 1)
  return uart_write(&i, 2);
 else if (hostendian == 0) {
  uint16_t swapped;
  swapEndian(&i, &swapped, 2);
  return uart_write(&swapped, 2);
 } else {
  generateError("System endianness is not supported. Use uart_write()");
  return 0;
 }
}

canonical_original_code:
int uart_writeUBE16(unsigned short i) {
 if (hostendian == 1)
  return uart_write(&i, 2);
 else if (hostendian == 0) {
  unsigned short swapped;
  swapEndian(&i, &swapped, 2);
  return uart_write(&swapped, 2);
 } else {
  generateError("System endianness is not supported. Use uart_write()");
  return 0;
 }
}

variable_types:
i
unsigned short

variable_types:
swapped
unsigned short


decompiled_code:
__int64 __fastcall uart_writeUBE32(int a1)
{
__int64 result; // rax
int v2[4]; // [rsp+Ch] [rbp-1Ch] BYREF
char buf[10]; // [rsp+1Eh] [rbp-Ah] BYREF

v2[0] = a1;
if ( hostendian == 1 )
return uart_write(v2, 4uLL);
if ( hostendian )
{
generateError("System endianness is not supported. Use uart_write()");
result = 0LL;
}
else
{
swapEndian(v2, buf, 4LL);
result = uart_write(buf, 4uLL);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1)
{
__int64 result; // rax
int v2[4]; // [rsp+Ch] [rbp-1Ch] BYREF
char buf[10]; // [rsp+1Eh] [rbp-Ah] BYREF

v2[0] = a1;
if ( hostendian == 1 )
return func5(v2, 4uLL);
if ( hostendian )
{
func2("System endianness is not supported. Use uart_write()");
result = 0LL;
}
else
{
func0(v2, buf, 4LL);
result = func5(buf, 4uLL);
}
return result;
}

original_code:
int uart_writeUBE32(uint32_t i) {
 if (hostendian == 1)
  return uart_write(&i, 4);
 else if (hostendian == 0) {
  uint16_t swapped;
  swapEndian(&i, &swapped, 4);
  return uart_write(&swapped, 4);
 } else {
  generateError("System endianness is not supported. Use uart_write()");
  return 0;
 }
}

canonical_original_code:
int uart_writeUBE32(unsigned int i) {
 if (hostendian == 1)
  return uart_write(&i, 4);
 else if (hostendian == 0) {
  unsigned short swapped;
  swapEndian(&i, &swapped, 4);
  return uart_write(&swapped, 4);
 } else {
  generateError("System endianness is not supported. Use uart_write()");
  return 0;
 }
}

variable_types:
i
unsigned int


decompiled_code:
__int64 __fastcall uart_read(__int64 a1, __int64 a2)
{
if ( uartfd != -1 )
return qb_pop(queuebuffer, a1, a2);
generateError("UART has not been initialized");
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 a2)
{
if ( uartfd != -1 )
return qb_pop(queuebuffer, a1, a2);
func2("UART has not been initialized");
return 0LL;
}

original_code:
int uart_read(void *buffer, size_t len) {
 if (uartfd == -1) {
  generateError("UART has not been initialized");
  return 0;
 }
 return qb_pop(queuebuffer, buffer, len);
}

canonical_original_code:
int uart_read(void *buffer, unsigned long len) {
 if (uartfd == -1) {
  generateError("UART has not been initialized");
  return 0;
 }
 return qb_pop(queuebuffer, buffer, len);
}


decompiled_code:
__int64 __fastcall uart_readChar(__int64 a1)
{
return uart_read(a1, 1LL);
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
return func9(a1, 1LL);
}

original_code:
int uart_readChar(char *c) {
 return uart_read(c, 1);
}

variable_types:
c
char *


decompiled_code:
__int64 __fastcall uart_readUBE16(_BYTE *a1)
{
unsigned int v1; // ebx
char v3[26]; // [rsp+Eh] [rbp-1Ah] BYREF

if ( uartfd == -1 )
{
generateError("UART has not been initialized");
v1 = 0;
}
else if ( (int)qb_getSize(queuebuffer) <= 1 )
{
generateError("Not enough data in queue to read 16-bit integer");
v1 = 0;
}
else
{
v1 = hostendian;
if ( hostendian == 1 )
{
qb_pop(queuebuffer, a1, 2LL);
}
else if ( hostendian )
{
generateError("System endianness is not supported. Use uart_write()");
v1 = 0;
}
else
{
qb_pop(queuebuffer, v3, 2LL);
swapEndian(v3, a1, 2LL);
v1 = 1;
}
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func11(_BYTE *a1)
{
unsigned int v1; // ebx
char v3[26]; // [rsp+Eh] [rbp-1Ah] BYREF

if ( uartfd == -1 )
{
func2("UART has not been initialized");
v1 = 0;
}
else if ( (int)qb_getSize(queuebuffer) <= 1 )
{
func2("Not enough data in queue to read 16-bit integer");
v1 = 0;
}
else
{
v1 = hostendian;
if ( hostendian == 1 )
{
qb_pop(queuebuffer, a1, 2LL);
}
else if ( hostendian )
{
func2("System endianness is not supported. Use uart_write()");
v1 = 0;
}
else
{
qb_pop(queuebuffer, v3, 2LL);
func0(v3, a1, 2LL);
v1 = 1;
}
}
return v1;
}

original_code:
int uart_readUBE16(uint16_t *i) {
 if (uartfd == -1) {
  generateError("UART has not been initialized");
  return 0;
 }
 if (qb_getSize(queuebuffer) >= 2) {
  if (hostendian == 1) {
   qb_pop(queuebuffer, i, 2);
   return 1;
  }
  else if (hostendian == 0) {
   uint16_t be;
   qb_pop(queuebuffer, &be, 2);
   swapEndian(&be, i, 2);
   return 1;
  } else {
   generateError("System endianness is not supported. Use uart_write()");
   return 0;
  }
 } else {
  generateError("Not enough data in queue to read 16-bit integer");
  return 0;
 }
}

canonical_original_code:
int uart_readUBE16(unsigned short *i) {
 if (uartfd == -1) {
  generateError("UART has not been initialized");
  return 0;
 }
 if (qb_getSize(queuebuffer) >= 2) {
  if (hostendian == 1) {
   qb_pop(queuebuffer, i, 2);
   return 1;
  }
  else if (hostendian == 0) {
   unsigned short be;
   qb_pop(queuebuffer, &be, 2);
   swapEndian(&be, i, 2);
   return 1;
  } else {
   generateError("System endianness is not supported. Use uart_write()");
   return 0;
  }
 } else {
  generateError("Not enough data in queue to read 16-bit integer");
  return 0;
 }
}

variable_types:
i
unsigned short *

variable_types:
be
unsigned short


decompiled_code:
__int64 __fastcall uart_readUBE32(_BYTE *a1)
{
unsigned int v1; // ebx
char v3[28]; // [rsp+Ch] [rbp-1Ch] BYREF

if ( uartfd == -1 )
{
generateError("UART has not been initialized");
v1 = 0;
}
else if ( (int)qb_getSize(queuebuffer) <= 3 )
{
generateError("Not enough data in queue to read 32-bit integer");
v1 = 0;
}
else
{
v1 = hostendian;
if ( hostendian == 1 )
{
qb_pop(queuebuffer, a1, 4LL);
}
else if ( hostendian )
{
generateError("System endianness is not supported. Use uart_write()");
v1 = 0;
}
else
{
qb_pop(queuebuffer, v3, 4LL);
swapEndian(v3, a1, 4LL);
v1 = 1;
}
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func12(_BYTE *a1)
{
unsigned int v1; // ebx
char v3[28]; // [rsp+Ch] [rbp-1Ch] BYREF

if ( uartfd == -1 )
{
func2("UART has not been initialized");
v1 = 0;
}
else if ( (int)qb_getSize(queuebuffer) <= 3 )
{
func2("Not enough data in queue to read 32-bit integer");
v1 = 0;
}
else
{
v1 = hostendian;
if ( hostendian == 1 )
{
qb_pop(queuebuffer, a1, 4LL);
}
else if ( hostendian )
{
func2("System endianness is not supported. Use uart_write()");
v1 = 0;
}
else
{
qb_pop(queuebuffer, v3, 4LL);
func0(v3, a1, 4LL);
v1 = 1;
}
}
return v1;
}

original_code:
int uart_readUBE32(uint32_t *i) {
 if (uartfd == -1) {
  generateError("UART has not been initialized");
  return 0;
 }
 if (qb_getSize(queuebuffer) >= 4) {
  if (hostendian == 1) {
   qb_pop(queuebuffer, i, 4);
   return 1;
  }
  else if (hostendian == 0) {
   uint32_t be;
   qb_pop(queuebuffer, &be, 4);
   swapEndian(&be, i, 4);
   return 1;
  } else {
   generateError("System endianness is not supported. Use uart_write()");
   return 0;
  }
 } else {
  generateError("Not enough data in queue to read 32-bit integer");
  return 0;
 }
}

canonical_original_code:
int uart_readUBE32(unsigned int *i) {
 if (uartfd == -1) {
  generateError("UART has not been initialized");
  return 0;
 }
 if (qb_getSize(queuebuffer) >= 4) {
  if (hostendian == 1) {
   qb_pop(queuebuffer, i, 4);
   return 1;
  }
  else if (hostendian == 0) {
   unsigned int be;
   qb_pop(queuebuffer, &be, 4);
   swapEndian(&be, i, 4);
   return 1;
  } else {
   generateError("System endianness is not supported. Use uart_write()");
   return 0;
  }
 } else {
  generateError("Not enough data in queue to read 32-bit integer");
  return 0;
 }
}

variable_types:
i
unsigned int *

variable_types:
be
unsigned int


decompiled_code:
__int64 uart_getInputQueueSize()
{
if ( queuebuffer )
return qb_getSize(queuebuffer);
generateError("UART has not been initialized");
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func13()
{
if ( queuebuffer )
return qb_getSize(queuebuffer);
func2("UART has not been initialized");
return 0xFFFFFFFFLL;
}

original_code:
int uart_getInputQueueSize() {
 if (!queuebuffer) {
  generateError("UART has not been initialized");
  return -1;
 }
 return qb_getSize(queuebuffer);
}


decompiled_code:
const char *uart_getLastError()
{
const char *result; // rax

result = "No error";
if ( error )
{
error = 0;
result = error_str;
}
return result;
}

canonical_decompiled_code:
const char *func14()
{
const char *result; // rax

result = "No error";
if ( error )
{
error = 0;
result = error_str;
}
return result;
}

original_code:
char *uart_getLastError() {
 if (error) {
  error = 0;
  return error_str;
 } else
  return "No error";
}

return_type: char *


generateError

decompiled_code:
char *__fastcall generateError(char *src)
{
error = 1;
return strncpy(error_str, src, 0x80uLL);
}

canonical_decompiled_code:
char *__fastcall func2(char *src)
{
error = 1;
return strncpy(error_str, src, 0x80uLL);
}

original_code:
void generateError(const char *str) {
 error = 1;
 strncpy(error_str, str, 128);
}

canonical_original_code:
void generateError(char *str) {
 error = 1;
 strncpy(error_str, str, 128);
}

variable_types:
str
char *

return_type: void


quit

decompiled_code:
void __fastcall __noreturn quit(int status)
{
tcsetattr(0, 0, &in_oldattr);
exit(status);
}

canonical_decompiled_code:
void __fastcall __noreturn func7(int status)
{
tcsetattr(0, 0, &in_oldattr);
exit(status);
}

original_code:
void quit(int code) {
 tcsetattr(0, 0, &in_oldattr);
 exit(code);
}

variable_types: code int


ignoreInput

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

do
result = getchar();
while ( (_BYTE)result != 0xFF && (_BYTE)result != 10 );
return result;
}

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

do
result = getchar();
while ( (_BYTE)result != 0xFF && (_BYTE)result != 10 );
return result;
}

original_code:
void ignoreInput() {
 char c;
 while ((c = getchar()) != '\n' && c != (-1));
}


decompiled_code:
__int64 gpio_init()
{
int v0; // eax
int v1; // ebx
__int64 result; // rax

v0 = open("/dev/mem", 1052674);
if ( v0 < 0 )
{
generateError("gpio_init: Failed to open /dev/mem");
result = 0LL;
}
else
{
v1 = v0;
gpio_base = mmap(0LL, 0x1000uLL, 3, 1, v0, 538968064LL);
if ( gpio_base == (void *)-1LL )
{
generateError("gpio_init: Failed to create memory mapping for GPIO_BASE");
result = 0LL;
}
else
{
close(v1);
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 func9()
{
int v0; // eax
int v1; // ebx
__int64 result; // rax

v0 = open("/dev/mem", 1052674);
if ( v0 < 0 )
{
func8("gpio_init: Failed to open /dev/mem");
result = 0LL;
}
else
{
v1 = v0;
gpio_base = mmap(0LL, 0x1000uLL, 3, 1, v0, 538968064LL);
if ( gpio_base == (void *)-1LL )
{
func8("gpio_init: Failed to create memory mapping for GPIO_BASE");
result = 0LL;
}
else
{
close(v1);
result = 1LL;
}
}
return result;
}

original_code:
int gpio_init() {
 int memfd = -1;
 memfd = open("/dev/mem", 02 | 04010000);
 if (memfd < 0) {
  generateError("gpio_init: Failed to open /dev/mem");
  return 0;
 }
 gpio_base = mmap(((void *)0), (4*1024), 0x1 | 0x2,
   0x01, memfd, 0x20200000);
 if (gpio_base == ((void *) -1)) {
  generateError("gpio_init: Failed to create memory mapping for GPIO_BASE");
  return 0;
 }
 close(memfd);
 return 1;
}

variable_types: memfd int


decompiled_code:
__int64 gpio_deinit()
{
__int64 result; // rax

if ( munmap(gpio_base, 0x1000uLL) < 0 )
{
generateError("gpio_deinit: Failed to unmap GPIO_BASE");
result = 0LL;
}
else
{
gpio_base = 0LL;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 func10()
{
__int64 result; // rax

if ( munmap(gpio_base, 0x1000uLL) < 0 )
{
func8("gpio_deinit: Failed to unmap GPIO_BASE");
result = 0LL;
}
else
{
gpio_base = 0LL;
result = 1LL;
}
return result;
}

original_code:
int gpio_deinit() {
 uint8_t *gpio_temp = (uint8_t *)gpio_base;
 if (munmap(gpio_temp, (4*1024)) < 0) {
  generateError("gpio_deinit: Failed to unmap GPIO_BASE");
  return 0;
 } else {
  gpio_base = 0;
  return 1;
 }
}

canonical_original_code:
int gpio_deinit() {
 unsigned char *gpio_temp = (uint8_t *)gpio_base;
 if (munmap(gpio_temp, (4*1024)) < 0) {
  generateError("gpio_deinit: Failed to unmap GPIO_BASE");
  return 0;
 } else {
  gpio_base = 0;
  return 1;
 }
}


decompiled_code:
__int64 __fastcall gpio_setMode(unsigned int a1, int a2)
{
unsigned int v2; // ecx
int *v3; // rdx
__int64 result; // rax

if ( a1 > 0x35 )
{
generateError("gpio_setMode: Bad pin number requested");
result = 0LL;
}
else
{
v2 = 3 * (a1 % 0xA);
v3 = (int *)((char *)gpio_base + (int)(4 * (a1 / 0xA)));
if ( a2 )
{
if ( a2 == 1 )
{
*v3 = *v3 & ~(7 << v2) | (1 << v2);
result = 1LL;
}
else
{
generateError("gpio_setMode: Unknown GPIOMode requested\n");
result = 0LL;
}
}
else
{
*v3 &= ~(7 << v2);
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(unsigned int a1, int a2)
{
unsigned int v2; // ecx
int *v3; // rdx
__int64 result; // rax

if ( a1 > 0x35 )
{
func8("gpio_setMode: Bad pin number requested");
result = 0LL;
}
else
{
v2 = 3 * (a1 % 0xA);
v3 = (int *)((char *)gpio_base + (int)(4 * (a1 / 0xA)));
if ( a2 )
{
if ( a2 == 1 )
{
*v3 = *v3 & ~(7 << v2) | (1 << v2);
result = 1LL;
}
else
{
func8("gpio_setMode: Unknown GPIOMode requested\n");
result = 0LL;
}
}
else
{
*v3 &= ~(7 << v2);
result = 1LL;
}
}
return result;
}

original_code:
int gpio_setMode(unsigned int pin, GPIOMode mode) {
 if (pin <= 53) {
  int fsel_offset = (pin / 10) * 4;
  int offset = (pin % 10) * 3;
  int i;
  uint32_t *fsel = (uint32_t *)(gpio_base + fsel_offset);
  switch (mode) {
   case GPIO_MODE_OUT:{
    uint32_t current = *fsel;
    *fsel = (~(0x7 << offset) & current) | ((uint32_t)01 << offset);
    } break;
   case GPIO_MODE_IN:{
    uint32_t current = *fsel;
    *fsel = (~(0x7 << offset) & current);
   } break;
   default:
    generateError("gpio_setMode: Unknown GPIOMode requested\n");
    return 0;
    break;
  }
  return 1;
 } else {
  generateError("gpio_setMode: Bad pin number requested");
  return 0;
 }
}

canonical_original_code:
int gpio_setMode(unsigned int pin, enum GPIOMode mode) {
 if (pin <= 53) {
  int fsel_offset = (pin / 10) * 4;
  int offset = (pin % 10) * 3;
  int i;
  unsigned int *fsel = (uint32_t *)(gpio_base + fsel_offset);
  switch (mode) {
   case GPIO_MODE_OUT:{
    unsigned int current = *fsel;
    *fsel = (~(0x7 << offset) & current) | ((unsigned int)01 << offset);
    } break;
   case GPIO_MODE_IN:{
    unsigned int current = *fsel;
    *fsel = (~(0x7 << offset) & current);
   } break;
   default:
    generateError("gpio_setMode: Unknown GPIOMode requested\n");
    return 0;
    break;
  }
  return 1;
 } else {
  generateError("gpio_setMode: Bad pin number requested");
  return 0;
 }
}

variable_types:
pin
unsigned int

variable_types: enum GPIOMode { GPIO_MODE_IN=0, GPIO_MODE_OUT=1 }

variable_types: offset int

variable_types: i int

variable_types:
fsel
unsigned int *

variable_types:
current
unsigned int


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

if ( a1 > 0x36 )
{
generateError("gpio_write: Bad pin number requested");
result = 0LL;
}
else if ( a2 )
{
if ( a2 == 1 )
{
*(_DWORD *)((char *)gpio_base + (int)(4 * (a1 >> 5) + 28)) = 1 << a1;
result = 1LL;
}
else
{
generateError("gpio_write: Unsupported GPIOValue\n");
result = 0LL;
}
}
else
{
*(_DWORD *)((char *)gpio_base + (int)(4 * (a1 >> 5) + 40)) = 1 << a1;
result = 1LL;
}
return result;
}

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

if ( a1 > 0x36 )
{
func8("gpio_write: Bad pin number requested");
result = 0LL;
}
else if ( a2 )
{
if ( a2 == 1 )
{
*(_DWORD *)((char *)gpio_base + (int)(4 * (a1 >> 5) + 28)) = 1 << a1;
result = 1LL;
}
else
{
func8("gpio_write: Unsupported GPIOValue\n");
result = 0LL;
}
}
else
{
*(_DWORD *)((char *)gpio_base + (int)(4 * (a1 >> 5) + 40)) = 1 << a1;
result = 1LL;
}
return result;
}

original_code:
int gpio_write(unsigned int pin, GPIOValue val) {
 if (pin <= 54) {
  switch (val) {
   case LOW: {
    int clr_offset = 0x00000028 + (pin / 32) * 4;
    int offset = pin % 32;
    uint32_t *clr = (uint32_t *)(gpio_base + clr_offset);
    *clr = (uint32_t)1 << offset;
   } break;
   case HIGH: {
    int set_offset = 0x0000001C + (pin / 32) * 4;
    int offset = pin % 32;
    uint32_t *set = (uint32_t *)(gpio_base + set_offset);
    *set = (uint32_t)1 << offset;
   } break;
   default:
    generateError("gpio_write: Unsupported GPIOValue\n");
    return 0;
    break;
  }
  return 1;
 } else {
  generateError("gpio_write: Bad pin number requested");
  return 0;
 }
}

canonical_original_code:
int gpio_write(unsigned int pin, enum GPIOValue val) {
 if (pin <= 54) {
  switch (val) {
   case LOW: {
    int clr_offset = 0x00000028 + (pin / 32) * 4;
    int offset = pin % 32;
    unsigned int *clr = (uint32_t *)(gpio_base + clr_offset);
    *clr = (unsigned int)1 << offset;
   } break;
   case HIGH: {
    int set_offset = 0x0000001C + (pin / 32) * 4;
    int offset = pin % 32;
    unsigned int *set = (uint32_t *)(gpio_base + set_offset);
    *set = (unsigned int)1 << offset;
   } break;
   default:
    generateError("gpio_write: Unsupported GPIOValue\n");
    return 0;
    break;
  }
  return 1;
 } else {
  generateError("gpio_write: Bad pin number requested");
  return 0;
 }
}

variable_types:
val
enum GPIOValue { LOW=0, HIGH=1 }

variable_types:
clr
unsigned int *

variable_types:
set
unsigned int *


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

if ( a1 > 0x35 )
{
generateError("gpio_read: Bad pin number requested");
result = 0LL;
}
else
{
result = (*((_DWORD *)gpio_base + (a1 >> 5) + 13) >> a1) & 1;
*a2 = result;
}
return result;
}

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

if ( a1 > 0x35 )
{
func8("gpio_read: Bad pin number requested");
result = 0LL;
}
else
{
result = (*((_DWORD *)gpio_base + (a1 >> 5) + 13) >> a1) & 1;
*a2 = result;
}
return result;
}

original_code:
int gpio_read(unsigned int pin, int *value) {
 if (pin <= 53) {
  uint32_t *lvloffset = (uint32_t *) (gpio_base + 0x00000034 + (pin / 32) * 4);
  uint32_t val = *lvloffset;
  uint32_t dummy = *lvloffset;
  val = (val >> (pin % 32)) & 0x1;
  *value = val;
 } else {
  generateError("gpio_read: Bad pin number requested");
  return 0;
 }
}

canonical_original_code:
int gpio_read(unsigned int pin, int *value) {
 if (pin <= 53) {
  unsigned int *lvloffset = (uint32_t *) (gpio_base + 0x00000034 + (pin / 32) * 4);
  unsigned int val = *lvloffset;
  unsigned int dummy = *lvloffset;
  val = (val >> (pin % 32)) & 0x1;
  *value = val;
 } else {
  generateError("gpio_read: Bad pin number requested");
  return 0;
 }
}

variable_types:
value
int *

variable_types:
lvloffset
unsigned int *

variable_types:
val
unsigned int

variable_types:
dummy
unsigned int


decompiled_code:
const char *gpio_getLastError()
{
const char *result; // rax

result = "No error";
if ( error )
{
error = 0;
result = error_str;
}
return result;
}

original_code:
char *gpio_getLastError() {
 if (error) {
  error = 0;
  return error_str;
 } else
  return "No error";
}


generateError

canonical_decompiled_code:
char *__fastcall func8(char *src)
{
error = 1;
return strncpy(error_str, src, 0x80uLL);
}

original_code:
static void generateError(const char *str) {
 error = 1;
 strncpy(error_str, str, 128);
}

canonical_original_code:
static void generateError(char *str) {
 error = 1;
 strncpy(error_str, str, 128);
}


repo: urbo-escom/c-ip-subnetting

decompiled_code:
char *__fastcall SubnetCalcUtil_get_info(__int64 a1, int a2)
{
__int64 v3; // r12
char v4; // al
const char *v5; // rax

if ( (unsigned int)IP_is_valid_id() )
{
if ( a2 > 1 && (int)(IP_host_bits(a1) - 1) > a2 )
{
if ( (unsigned int)IP_ip_to_dot_decimal(a1, ip_s) == -1 )
{
v5 = (const char *)IP_strerror();
snprintf(info, 0x401uLL, "error At conversion of %lx: %s", a1, v5);
}
else
{
v3 = IP_subnets_size((unsigned int)a2);
v4 = IP_class(a1);
snprintf(info, 0x401uLL, "%s %c %d %lu", ip_s, (unsigned int)v4, (unsigned int)a2, v3);
}
}
else
{
snprintf(info, 0x401uLL, "error Inadequate subnet bits (%d bits) for %lx", (unsigned int)a2, a1);
}
}
else
{
snprintf(info, 0x401uLL, "error Invalid ID for %lx", a1);
}
return info;
}

canonical_decompiled_code:
char *__fastcall func0(__int64 a1, int a2)
{
__int64 v3; // r12
char v4; // al
const char *v5; // rax

if ( (unsigned int)IP_is_valid_id() )
{
if ( a2 > 1 && (int)(IP_host_bits(a1) - 1) > a2 )
{
if ( (unsigned int)IP_ip_to_dot_decimal(a1, ip_s) == -1 )
{
v5 = (const char *)IP_strerror();
snprintf(info, 0x401uLL, "error At conversion of %lx: %s", a1, v5);
}
else
{
v3 = IP_subnets_size((unsigned int)a2);
v4 = IP_class(a1);
snprintf(info, 0x401uLL, "%s %c %d %lu", ip_s, (unsigned int)v4, (unsigned int)a2, v3);
}
}
else
{
snprintf(info, 0x401uLL, "error Inadequate subnet bits (%d bits) for %lx", (unsigned int)a2, a1);
}
}
else
{
snprintf(info, 0x401uLL, "error Invalid ID for %lx", a1);
}
return info;
}

original_code:
extern char* SubnetCalcUtil_get_info(
  IP_T ip, int subnet_bits) {
 if (!IP_is_valid_id(ip)) {
  snprintf(info, 1025, "error Invalid ID for %lx", ip);
  return info;
 }
 if (!(1 < subnet_bits && subnet_bits < IP_host_bits(ip) - 1)) {
  snprintf(info, 1025, "error "
   "Inadequate subnet bits (%d bits) for %lx",
   subnet_bits, ip);
  return info;
 }
 if (IP_ip_to_dot_decimal(ip, ip_s) == -1) {
  snprintf(info, 1025, "error At conversion of %lx: %s",
           ip, IP_strerror());
  return info;
 }
 snprintf(info, 1025, "%s %c %d %lu", ip_s, IP_class(ip),
          subnet_bits, IP_subnets_size(subnet_bits));
 return info;
}

canonical_original_code:
extern char *SubnetCalcUtil_get_info(unsigned long ip, int subnet_bits) {
 if (!IP_is_valid_id(ip)) {
  snprintf(info, 1025, "error Invalid ID for %lx", ip);
  return info;
 }
 if (!(1 < subnet_bits && subnet_bits < IP_host_bits(ip) - 1)) {
  snprintf(info, 1025, "error "
   "Inadequate subnet bits (%d bits) for %lx",
   subnet_bits, ip);
  return info;
 }
 if (IP_ip_to_dot_decimal(ip, ip_s) == -1) {
  snprintf(info, 1025, "error At conversion of %lx: %s",
           ip, IP_strerror());
  return info;
 }
 snprintf(info, 1025, "%s %c %d %lu", ip_s, IP_class(ip),
          subnet_bits, IP_subnets_size(subnet_bits));
 return info;
}

variable_types:
ip
unsigned long


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

time(&timer);
v0 = localtime(&timer);
strftime(buffer, 0x1BuLL, "[%Y:%m:%d %H:%M:%S]", v0);
return buffer;
}

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

time(&timer);
v0 = localtime(&timer);
strftime(buffer, 0x1BuLL, "[%Y:%m:%d %H:%M:%S]", v0);
return buffer;
}

original_code:
static char* get_time() {
 time_t timer;
 struct tm* tm_info;
 time(&timer);
 tm_info = localtime(&timer);
 strftime(buffer, 27, "[%Y:%m:%d %H:%M:%S]", tm_info);
 return buffer;
}

canonical_original_code:
static char *get_time() {
 long timer;
 struct tm *tm_info;
 time(&timer);
 tm_info = localtime(&timer);
 strftime(buffer, 27, "[%Y:%m:%d %H:%M:%S]", tm_info);
 return buffer;
}

variable_types: timer long

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


decompiled_code:
__int64 __fastcall Socket_get_ip(__int64 a1)
{
Socket_peername(a1);
return a1 + 64;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
func2(a1);
return a1 + 64;
}

original_code:
extern char* Socket_get_ip(Socket_T* sock) {
 Socket_peername(sock);
 return sock->peer_ip;
}

canonical_original_code:
extern char *Socket_get_ip(struct Socket_T *sock) {
 Socket_peername(sock);
 return sock->peer_ip;
}

variable_types: struct Socket_T { int sockfd_dest; int sockfd_src; 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; } hints; struct addrinfo *result; char peer_ip[20]; char peer_port[20]; char *address; char *portnum; } *

user_defined_types: struct Socket_T { int sockfd_dest; int sockfd_src; struct addrinfo hints; struct addrinfo *result; char peer_ip[20]; char peer_port[20]; char *address; char *portnum; }

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


decompiled_code:
__int64 __fastcall Socket_get_port(__int64 a1)
{
Socket_peername(a1);
return a1 + 84;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
func2(a1);
return a1 + 84;
}

original_code:
extern char* Socket_get_port(Socket_T* sock) {
 Socket_peername(sock);
 return sock->peer_port;
}

canonical_original_code:
extern char *Socket_get_port(struct Socket_T *sock) {
 Socket_peername(sock);
 return sock->peer_port;
}

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


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

time(&timer);
v0 = localtime(&timer);
strftime(buffer, 0x1BuLL, "[%Y:%m:%d %H:%M:%S]", v0);
return buffer;
}

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


decompiled_code:
__int64 __fastcall IP_host_bits_by_hosts_per_subnet(unsigned __int64 a1)
{
char *v2; // rax
char *v3; // rbx
unsigned int v4; // ebp
char *v5; // rax
int v6; // edi
char *v7; // rbx
char *v8; // rax
char *v10; // rax
int v11[3]; // [rsp+4h] [rbp-34h] BYREF
char v12; // [rsp+10h] [rbp-28h] BYREF

v11[0] = 8;
v11[1] = 16;
v11[2] = 24;
v2 = get_time();
fprintf(
stderr,
"[DEBUG]%s (%s:%d) Finding suitable Class for %lu hosts/subnet\n",
v2,
"src/subnetting/ip_util_hosts_per_subnet.c",
12LL,
a1);
v3 = (char *)v11;
do
{
v4 = *(_DWORD *)v3;
v5 = get_time();
fprintf(stderr, "[DEBUG]%s (%s:%d) ---%d bits\n", v5, "src/subnetting/ip_util_hosts_per_subnet.c", 16LL, v4);
if ( max_hosts(v4) >= a1 )
{
v10 = get_time();
fprintf(
stderr,
"[DEBUG]%s (%s:%d) Found with %d bits\n",
v10,
"src/subnetting/ip_util_hosts_per_subnet.c",
18LL,
v4);
return v4;
}
v3 += 4;
}
while ( v3 != &v12 );
IP_set_strerror("Too many hosts/subnet: %lu", a1);
v6 = *_errno_location();
v7 = "None";
if ( v6 )
v7 = strerror(v6);
v8 = get_time();
fprintf(
stderr,
"[WARN]%s (%s:%d: errno: %s) Too many hosts/subnet: %lu\n",
v8,
"src/subnetting/ip_util_hosts_per_subnet.c",
24LL,
v7,
a1);
return (unsigned int)-1;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int64 a1)
{
char *v2; // rax
char *v3; // rbx
unsigned int v4; // ebp
char *v5; // rax
int v6; // edi
char *v7; // rbx
char *v8; // rax
char *v10; // rax
int v11[3]; // [rsp+4h] [rbp-34h] BYREF
char v12; // [rsp+10h] [rbp-28h] BYREF

v11[0] = 8;
v11[1] = 16;
v11[2] = 24;
v2 = func1();
fprintf(
stderr,
"[DEBUG]%s (%s:%d) Finding suitable Class for %lu hosts/subnet\n",
v2,
"src/subnetting/ip_util_hosts_per_subnet.c",
12LL,
a1);
v3 = (char *)v11;
do
{
v4 = *(_DWORD *)v3;
v5 = func1();
fprintf(stderr, "[DEBUG]%s (%s:%d) ---%d bits\n", v5, "src/subnetting/ip_util_hosts_per_subnet.c", 16LL, v4);
if ( func0(v4) >= a1 )
{
v10 = func1();
fprintf(
stderr,
"[DEBUG]%s (%s:%d) Found with %d bits\n",
v10,
"src/subnetting/ip_util_hosts_per_subnet.c",
18LL,
v4);
return v4;
}
v3 += 4;
}
while ( v3 != &v12 );
IP_set_strerror("Too many hosts/subnet: %lu", a1);
v6 = *_errno_location();
v7 = "None";
if ( v6 )
v7 = strerror(v6);
v8 = func1();
fprintf(
stderr,
"[WARN]%s (%s:%d: errno: %s) Too many hosts/subnet: %lu\n",
v8,
"src/subnetting/ip_util_hosts_per_subnet.c",
24LL,
v7,
a1);
return (unsigned int)-1;
}

original_code:
extern int IP_host_bits_by_hosts_per_subnet(host_size_t hosts_per_subnet) {
 int hosts[3] = {8, 16, 24};
 fprintf(stderr, "[DEBUG]%s (%s:%d) " "Finding suitable Class for %lu hosts/subnet" "\n", get_time(), "src/subnetting/ip_util_hosts_per_subnet.c", 12, hosts_per_subnet);
 int i;
 for(i = 0; i < sizeof(hosts)/sizeof(int); i++) {
  fprintf(stderr, "[DEBUG]%s (%s:%d) " "---%d bits" "\n", get_time(), "src/subnetting/ip_util_hosts_per_subnet.c", 16, hosts[i]);
  if (hosts_per_subnet <= max_hosts(hosts[i])) {
   fprintf(stderr, "[DEBUG]%s (%s:%d) " "Found with %d bits" "\n", get_time(), "src/subnetting/ip_util_hosts_per_subnet.c", 18, hosts[i]);
   return hosts[i];
  }
 }
 IP_set_strerror("Too many hosts/subnet: %lu", hosts_per_subnet);
 fprintf(stderr, "[WARN]%s (%s:%d: errno: %s) " "Too many hosts/subnet: %lu" "\n", get_time(), "src/subnetting/ip_util_hosts_per_subnet.c", 24, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ()))), hosts_per_subnet);
 return -1;
}

canonical_original_code:
extern int IP_host_bits_by_hosts_per_subnet(unsigned long hosts_per_subnet) {
 int hosts[3] = {8, 16, 24};
 fprintf(stderr, "[DEBUG]%s (%s:%d) " "Finding suitable Class for %lu hosts/subnet" "\n", get_time(), "src/subnetting/ip_util_hosts_per_subnet.c", 12, hosts_per_subnet);
 int i;
 for(i = 0; i < sizeof(hosts)/sizeof(int); i++) {
  fprintf(stderr, "[DEBUG]%s (%s:%d) " "---%d bits" "\n", get_time(), "src/subnetting/ip_util_hosts_per_subnet.c", 16, hosts[i]);
  if (hosts_per_subnet <= max_hosts(hosts[i])) {
   fprintf(stderr, "[DEBUG]%s (%s:%d) " "Found with %d bits" "\n", get_time(), "src/subnetting/ip_util_hosts_per_subnet.c", 18, hosts[i]);
   return hosts[i];
  }
 }
 IP_set_strerror("Too many hosts/subnet: %lu", hosts_per_subnet);
 fprintf(stderr, "[WARN]%s (%s:%d: errno: %s) " "Too many hosts/subnet: %lu" "\n", get_time(), "src/subnetting/ip_util_hosts_per_subnet.c", 24, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ()))), hosts_per_subnet);
 return -1;
}

variable_types:
hosts
int [3]


decompiled_code:
void reset_strerror()
{
str_err = 0;
}

canonical_decompiled_code:
void func0()
{
str_err = 0;
}

original_code:
static void reset_strerror(void) {
 str_err[0] = '\0';
}

canonical_original_code:
static void reset_strerror() {
 str_err[0] = '\0';
}


decompiled_code:
char *set_strerror()
{
int *v0; // rax
char *v1; // rax

v0 = _errno_location();
v1 = strerror(*v0);
return strcpy(&str_err, v1);
}

canonical_decompiled_code:
char *func1()
{
int *v0; // rax
char *v1; // rax

v0 = _errno_location();
v1 = strerror(*v0);
return strcpy(&str_err, v1);
}

original_code:
static void set_strerror(void) {
 strcpy(str_err, strerror((*__errno_location ())));
}

canonical_original_code:
static void set_strerror() {
 strcpy(str_err, strerror((*__errno_location ())));
}


decompiled_code:
char *__fastcall Socket_set_errno(int a1)
{
error_code = a1;
return set_strerror();
}

canonical_decompiled_code:
char *__fastcall func2(int a1)
{
error_code = a1;
return func1();
}

original_code:
extern void Socket_set_errno(int error) {
 error_code = error;
 set_strerror();
}

variable_types: error int


canonical_decompiled_code:
void func3()
{
error_code = 0;
func0();
}

original_code:
extern void Socket_reset_errno(void) {
 error_code = 0;
 reset_strerror();
}

canonical_original_code:
extern void Socket_reset_errno() {
 error_code = 0;
 reset_strerror();
}


decompiled_code:
__int64 Socket_errno()
{
return (unsigned int)error_code;
}

canonical_decompiled_code:
__int64 func4()
{
return (unsigned int)error_code;
}

original_code:
extern int Socket_errno(void) {
 return error_code;
}

canonical_original_code:
extern int Socket_errno() {
 return error_code;
}


decompiled_code:
char *Socket_strerror()
{
return &str_err;
}

canonical_decompiled_code:
char *func5()
{
return &str_err;
}

original_code:
extern char* Socket_strerror(void) {
 return str_err;
}

canonical_original_code:
extern char *Socket_strerror() {
 return str_err;
}


decompiled_code:
__int64 __fastcall Socket_set_hints(__int64 a1)
{
char *v1; // rax
char *v2; // rax
char *v3; // rax
char *v5; // rax

v1 = get_time();
fprintf(stderr, "[DEBUG]%s (%s:%d) Zeroing the sock->hints\n", v1, "src/network/bsd-win-setup-set-hints.c", 8LL);
*(_QWORD *)(a1 + 8) = 0LL;
*(_QWORD *)(a1 + 16) = 0LL;
*(_QWORD *)(a1 + 24) = 0LL;
*(_QWORD *)(a1 + 32) = 0LL;
*(_QWORD *)(a1 + 40) = 0LL;
*(_QWORD *)(a1 + 48) = 0LL;
v2 = get_time();
fprintf(
stderr,
"[DEBUG]%s (%s:%d) Setting socktype and protocol\n",
v2,
"src/network/bsd-win-setup-set-hints.c",
11LL);
*(_DWORD *)(a1 + 16) = 1;
*(_DWORD *)(a1 + 20) = 6;
if ( *(_QWORD *)(a1 + 104) )
{
v3 = get_time();
fprintf(stderr, "[DEBUG]%s (%s:%d) Setting up client socket\n", v3, "src/network/bsd-win-setup-set-hints.c", 20LL);
*(_DWORD *)(a1 + 12) = 0;
}
else
{
v5 = get_time();
fprintf(stderr, "[DEBUG]%s (%s:%d) Setting up server socket\n", v5, "src/network/bsd-win-setup-set-hints.c", 16LL);
*(_DWORD *)(a1 + 12) = 2;
*(_DWORD *)(a1 + 8) = 1;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
char *v1; // rax
char *v2; // rax
char *v3; // rax
char *v5; // rax

v1 = func0();
fprintf(stderr, "[DEBUG]%s (%s:%d) Zeroing the sock->hints\n", v1, "src/network/bsd-win-setup-set-hints.c", 8LL);
*(_QWORD *)(a1 + 8) = 0LL;
*(_QWORD *)(a1 + 16) = 0LL;
*(_QWORD *)(a1 + 24) = 0LL;
*(_QWORD *)(a1 + 32) = 0LL;
*(_QWORD *)(a1 + 40) = 0LL;
*(_QWORD *)(a1 + 48) = 0LL;
v2 = func0();
fprintf(
stderr,
"[DEBUG]%s (%s:%d) Setting socktype and protocol\n",
v2,
"src/network/bsd-win-setup-set-hints.c",
11LL);
*(_DWORD *)(a1 + 16) = 1;
*(_DWORD *)(a1 + 20) = 6;
if ( *(_QWORD *)(a1 + 104) )
{
v3 = func0();
fprintf(stderr, "[DEBUG]%s (%s:%d) Setting up client socket\n", v3, "src/network/bsd-win-setup-set-hints.c", 20LL);
*(_DWORD *)(a1 + 12) = 0;
}
else
{
v5 = func0();
fprintf(stderr, "[DEBUG]%s (%s:%d) Setting up server socket\n", v5, "src/network/bsd-win-setup-set-hints.c", 16LL);
*(_DWORD *)(a1 + 12) = 2;
*(_DWORD *)(a1 + 8) = 1;
}
return 0LL;
}

original_code:
extern int Socket_set_hints(Socket_T* sock) {
 fprintf(stderr, "[DEBUG]%s (%s:%d) " "Zeroing the sock->hints" "\n", get_time(), "src/network/bsd-win-setup-set-hints.c", 8);
 memset(&(sock->hints), 0, sizeof(sock->hints));
 fprintf(stderr, "[DEBUG]%s (%s:%d) " "Setting socktype and protocol" "\n", get_time(), "src/network/bsd-win-setup-set-hints.c", 11);
 sock->hints.ai_socktype = SOCK_STREAM;
 sock->hints.ai_protocol = IPPROTO_TCP;
 if (sock->address == ((void *)0)) {
  fprintf(stderr, "[DEBUG]%s (%s:%d) " "Setting up server socket" "\n", get_time(), "src/network/bsd-win-setup-set-hints.c", 16);
  sock->hints.ai_family = 2;
  sock->hints.ai_flags = 0x0001;
 } else {
  fprintf(stderr, "[DEBUG]%s (%s:%d) " "Setting up client socket" "\n", get_time(), "src/network/bsd-win-setup-set-hints.c", 20);
  sock->hints.ai_family = 0;
 }
 return 0;
}

canonical_original_code:
extern int Socket_set_hints(struct Socket_T *sock) {
 fprintf(stderr, "[DEBUG]%s (%s:%d) " "Zeroing the sock->hints" "\n", get_time(), "src/network/bsd-win-setup-set-hints.c", 8);
 memset(&(sock->hints), 0, sizeof(sock->hints));
 fprintf(stderr, "[DEBUG]%s (%s:%d) " "Setting socktype and protocol" "\n", get_time(), "src/network/bsd-win-setup-set-hints.c", 11);
 sock->hints.ai_socktype = SOCK_STREAM;
 sock->hints.ai_protocol = IPPROTO_TCP;
 if (sock->address == ((void *)0)) {
  fprintf(stderr, "[DEBUG]%s (%s:%d) " "Setting up server socket" "\n", get_time(), "src/network/bsd-win-setup-set-hints.c", 16);
  sock->hints.ai_family = 2;
  sock->hints.ai_flags = 0x0001;
 } else {
  fprintf(stderr, "[DEBUG]%s (%s:%d) " "Setting up client socket" "\n", get_time(), "src/network/bsd-win-setup-set-hints.c", 20);
  sock->hints.ai_family = 0;
 }
 return 0;
}


decompiled_code:
__int64 Socket_startup()
{
char *v0; // rax

v0 = get_time();
fprintf(stderr, "[DEBUG]%s (%s:%d) Socket startup succeded\n", v0, "src/network/bsd-win-setup-startup.c", 18LL);
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
char *v0; // rax

v0 = func0();
fprintf(stderr, "[DEBUG]%s (%s:%d) Socket startup succeded\n", v0, "src/network/bsd-win-setup-startup.c", 18LL);
return 0LL;
}

original_code:
extern int Socket_startup() {
 fprintf(stderr, "[DEBUG]%s (%s:%d) " "Socket startup succeded" "\n", get_time(), "src/network/bsd-win-setup-startup.c", 18);
 return 0;
}


decompiled_code:
char *__fastcall SubnetCalc_subnetting_by_ip_and_hosts(__int64 a1, __int64 a2, __int64 a3)
{
unsigned int v4; // eax

v4 = IP_subnet_bits_by_total_hosts();
if ( v4 != -1 )
return (char *)SubnetCalcUtil_subnetting(a1, v4, a3);
sprintf(info, "error Too many hosts (%lu) for %lx", a1, a2);
return info;
}

canonical_decompiled_code:
char *__fastcall func0(__int64 a1, __int64 a2, __int64 a3)
{
unsigned int v4; // eax

v4 = IP_subnet_bits_by_total_hosts();
if ( v4 != -1 )
return (char *)SubnetCalcUtil_subnetting(a1, v4, a3);
sprintf(info, "error Too many hosts (%lu) for %lx", a1, a2);
return info;
}

original_code:
extern char* SubnetCalc_subnetting_by_ip_and_hosts(
  IP_T ip, host_size_t hosts, Subnet subnet_number) {
 int subnet_bits = IP_subnet_bits_by_total_hosts(ip, hosts);
 do{ if(subnet_bits == -1) { sprintf(info, "error Too many hosts (%lu) for %lx", ip, hosts); return info; } } while(0);
 return SubnetCalcUtil_subnetting(ip, subnet_bits, subnet_number);
}

canonical_original_code:
extern char *SubnetCalc_subnetting_by_ip_and_hosts(unsigned long ip, unsigned long hosts, unsigned long subnet_number) {
 int subnet_bits = IP_subnet_bits_by_total_hosts(ip, hosts);
 do{ if(subnet_bits == -1) { sprintf(info, "error Too many hosts (%lu) for %lx", ip, hosts); return info; } } while(0);
 return SubnetCalcUtil_subnetting(ip, subnet_bits, subnet_number);
}

variable_types:
hosts
unsigned long


decompiled_code:
char *__fastcall SubnetCalc_subnetting_by_ip_and_hosts_per_subnet(__int64 a1, __int64 a2, __int64 a3)
{
unsigned int v4; // eax

v4 = IP_subnet_bits_by_hosts_per_subnet();
if ( v4 != -1 )
return (char *)SubnetCalcUtil_subnetting(a1, v4, a3);
sprintf(info, "error Too many hosts per subnet (%lu) for %lx", a1, a2);
return info;
}

canonical_decompiled_code:
char *__fastcall func1(__int64 a1, __int64 a2, __int64 a3)
{
unsigned int v4; // eax

v4 = IP_subnet_bits_by_hosts_per_subnet();
if ( v4 != -1 )
return (char *)SubnetCalcUtil_subnetting(a1, v4, a3);
sprintf(info, "error Too many hosts per subnet (%lu) for %lx", a1, a2);
return info;
}

original_code:
extern char* SubnetCalc_subnetting_by_ip_and_hosts_per_subnet(
  IP_T ip, host_size_t hosts_per_subnet, Subnet subnet_number) {
 int subnet_bits =
  IP_subnet_bits_by_hosts_per_subnet(ip, hosts_per_subnet);
 do{ if(subnet_bits == -1) { sprintf(info, "error Too many hosts per subnet (%lu) for %lx", ip, hosts_per_subnet); return info; } } while(0);
 return SubnetCalcUtil_subnetting(ip, subnet_bits, subnet_number);
}

canonical_original_code:
extern char *SubnetCalc_subnetting_by_ip_and_hosts_per_subnet(unsigned long ip, unsigned long hosts_per_subnet, unsigned long subnet_number) {
 int subnet_bits = IP_subnet_bits_by_hosts_per_subnet(ip, hosts_per_subnet);
 do{ if(subnet_bits == -1) { sprintf(info, "error Too many hosts per subnet (%lu) for %lx", ip, hosts_per_subnet); return info; } } while(0);
 return SubnetCalcUtil_subnetting(ip, subnet_bits, subnet_number);
}


decompiled_code:
char *__fastcall SubnetCalc_subnetting_by_ip_and_subnets(__int64 a1, __int64 a2, __int64 a3)
{
unsigned int v4; // eax

v4 = IP_subnet_bits_by_subnets();
if ( v4 != -1 )
return (char *)SubnetCalcUtil_subnetting(a1, v4, a3);
sprintf(info, "error Too many subnets (%lu) for %lx", a1, a2);
return info;
}

canonical_decompiled_code:
char *__fastcall func2(__int64 a1, __int64 a2, __int64 a3)
{
unsigned int v4; // eax

v4 = IP_subnet_bits_by_subnets();
if ( v4 != -1 )
return (char *)SubnetCalcUtil_subnetting(a1, v4, a3);
sprintf(info, "error Too many subnets (%lu) for %lx", a1, a2);
return info;
}

original_code:
extern char* SubnetCalc_subnetting_by_ip_and_subnets(
  IP_T ip, subnet_size_t subnets, Subnet subnet_number) {
 int subnet_bits = IP_subnet_bits_by_subnets(ip, subnets);
 do{ if(subnet_bits == -1) { sprintf(info, "error Too many subnets (%lu) for %lx", ip, subnets); return info; } } while(0);
 return SubnetCalcUtil_subnetting(ip, subnet_bits, subnet_number);
}

canonical_original_code:
extern char *SubnetCalc_subnetting_by_ip_and_subnets(unsigned long ip, unsigned long subnets, unsigned long subnet_number) {
 int subnet_bits = IP_subnet_bits_by_subnets(ip, subnets);
 do{ if(subnet_bits == -1) { sprintf(info, "error Too many subnets (%lu) for %lx", ip, subnets); return info; } } while(0);
 return SubnetCalcUtil_subnetting(ip, subnet_bits, subnet_number);
}

variable_types:
subnets
unsigned long


decompiled_code:
__int64 __fastcall IP_subnet_bits_by_hosts_per_subnet(__int64 a1, __int64 a2)
{
char *v2; // rax
int v3; // eax
int v4; // ebx
int v5; // ebp
int v6; // ebp
char *v7; // rax
int v9; // edi
char *v10; // rbx
char *v11; // rax

v2 = get_time();
fprintf(
stderr,
"[DEBUG]%s (%s:%d) Finding suitable subnetting for %lx with %lu hosts/subnet\n",
v2,
"src/subnetting/ip_util_subnet_bits_by_host_per_subnet.c",
7LL,
a1,
a2);
v3 = ((int)a2 + 2) >> 1;
if ( !v3 )
goto LABEL_10;
v4 = 0;
do
{
++v4;
v3 >>= 1;
}
while ( v3 );
if ( v4 && a2 && (v5 = IP_host_bits(a1), v5 != -1) && (v6 = v5 - v4, v6 > 1) )
{
v7 = get_time();
fprintf(
stderr,
"[DEBUG]%s (%s:%d) Found %d suitable\n",
v7,
"src/subnetting/ip_util_subnet_bits_by_host_per_subnet.c",
23LL,
(unsigned int)v6);
}
else
{
LABEL_10:
IP_set_strerror("IP %lx can't handle %lu hosts/subnet", a1, a2);
v9 = *_errno_location();
v10 = "None";
if ( v9 )
v10 = strerror(v9);
v11 = get_time();
fprintf(
stderr,
"[WARN]%s (%s:%d: errno: %s) Subnetting bits failed\n",
v11,
"src/subnetting/ip_util_subnet_bits_by_host_per_subnet.c",
30LL,
v10);
v6 = -1;
}
return (unsigned int)v6;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
char *v2; // rax
int v3; // eax
int v4; // ebx
int v5; // ebp
int v6; // ebp
char *v7; // rax
int v9; // edi
char *v10; // rbx
char *v11; // rax

v2 = func0();
fprintf(
stderr,
"[DEBUG]%s (%s:%d) Finding suitable subnetting for %lx with %lu hosts/subnet\n",
v2,
"src/subnetting/ip_util_subnet_bits_by_host_per_subnet.c",
7LL,
a1,
a2);
v3 = ((int)a2 + 2) >> 1;
if ( !v3 )
goto LABEL_10;
v4 = 0;
do
{
++v4;
v3 >>= 1;
}
while ( v3 );
if ( v4 && a2 && (v5 = IP_host_bits(a1), v5 != -1) && (v6 = v5 - v4, v6 > 1) )
{
v7 = func0();
fprintf(
stderr,
"[DEBUG]%s (%s:%d) Found %d suitable\n",
v7,
"src/subnetting/ip_util_subnet_bits_by_host_per_subnet.c",
23LL,
(unsigned int)v6);
}
else
{
LABEL_10:
IP_set_strerror("IP %lx can't handle %lu hosts/subnet", a1, a2);
v9 = *_errno_location();
v10 = "None";
if ( v9 )
v10 = strerror(v9);
v11 = func0();
fprintf(
stderr,
"[WARN]%s (%s:%d: errno: %s) Subnetting bits failed\n",
v11,
"src/subnetting/ip_util_subnet_bits_by_host_per_subnet.c",
30LL,
v10);
v6 = -1;
}
return (unsigned int)v6;
}

original_code:
extern int IP_subnet_bits_by_hosts_per_subnet(
  IP_T ip, host_size_t hosts_per_subnet) {
 fprintf(stderr, "[DEBUG]%s (%s:%d) " "Finding suitable subnetting for %lx with %lu hosts/subnet" "\n", get_time(), "src/subnetting/ip_util_subnet_bits_by_host_per_subnet.c", 7, ip, hosts_per_subnet);
 int aux = hosts_per_subnet + 2;
 int log2 = 0;
 while (aux >>= 1) ++log2;
 if (log2 != 0 && 0UL < hosts_per_subnet) {
  int host_bits = IP_host_bits(ip);
  if (host_bits != -1 && (1 < host_bits - log2)) {
   fprintf(stderr, "[DEBUG]%s (%s:%d) " "Found %d suitable" "\n", get_time(), "src/subnetting/ip_util_subnet_bits_by_host_per_subnet.c", 23, host_bits - log2);
   return host_bits - log2;
  }
 }
 IP_set_strerror("IP %lx can't handle %lu hosts/subnet",
          ip, hosts_per_subnet);
 fprintf(stderr, "[WARN]%s (%s:%d: errno: %s) " "Subnetting bits failed" "\n", get_time(), "src/subnetting/ip_util_subnet_bits_by_host_per_subnet.c", 30, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ()))));
 return -1;
}

canonical_original_code:
extern int IP_subnet_bits_by_hosts_per_subnet(unsigned long ip, unsigned long hosts_per_subnet) {
 fprintf(stderr, "[DEBUG]%s (%s:%d) " "Finding suitable subnetting for %lx with %lu hosts/subnet" "\n", get_time(), "src/subnetting/ip_util_subnet_bits_by_host_per_subnet.c", 7, ip, hosts_per_subnet);
 int aux = hosts_per_subnet + 2;
 int log2 = 0;
 while (aux >>= 1) ++log2;
 if (log2 != 0 && 0UL < hosts_per_subnet) {
  int host_bits = IP_host_bits(ip);
  if (host_bits != -1 && (1 < host_bits - log2)) {
   fprintf(stderr, "[DEBUG]%s (%s:%d) " "Found %d suitable" "\n", get_time(), "src/subnetting/ip_util_subnet_bits_by_host_per_subnet.c", 23, host_bits - log2);
   return host_bits - log2;
  }
 }
 IP_set_strerror("IP %lx can't handle %lu hosts/subnet",
          ip, hosts_per_subnet);
 fprintf(stderr, "[WARN]%s (%s:%d: errno: %s) " "Subnetting bits failed" "\n", get_time(), "src/subnetting/ip_util_subnet_bits_by_host_per_subnet.c", 30, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ()))));
 return -1;
}

variable_types: aux int


decompiled_code:
__int64 __fastcall IP_subnet_bits_by_subnets(__int64 a1, __int64 a2)
{
char *v2; // rax
unsigned int v3; // ebx
unsigned int v4; // er12
char *v5; // rax
int v7; // edi
char *v8; // rbp
char *v9; // rax

v2 = get_time();
fprintf(
stderr,
"[DEBUG]%s (%s:%d) Finding suitable subnetting for %lx with %lu subnets\n",
v2,
"src/subnetting/ip_util_subnet_bits_by_host_per_subnet.c",
36LL,
a1,
a2);
v3 = IP_subnet_bits_by_hosts_per_subnet(a1, a2);
if ( v3 == -1 )
{
v7 = *_errno_location();
v8 = "None";
if ( v7 )
v8 = strerror(v7);
v9 = get_time();
fprintf(
stderr,
"[WARN]%s (%s:%d: errno: %s) Subnetting bits failed\n",
v9,
"src/subnetting/ip_util_subnet_bits_by_host_per_subnet.c",
46LL,
v8);
}
else
{
v4 = IP_host_bits(a1) - v3;
v5 = get_time();
fprintf(
stderr,
"[DEBUG]%s (%s:%d) Found %d suitable\n",
v5,
"src/subnetting/ip_util_subnet_bits_by_host_per_subnet.c",
43LL,
v4);
v3 = IP_host_bits(a1) - v3;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
char *v2; // rax
unsigned int v3; // ebx
unsigned int v4; // er12
char *v5; // rax
int v7; // edi
char *v8; // rbp
char *v9; // rax

v2 = func0();
fprintf(
stderr,
"[DEBUG]%s (%s:%d) Finding suitable subnetting for %lx with %lu subnets\n",
v2,
"src/subnetting/ip_util_subnet_bits_by_host_per_subnet.c",
36LL,
a1,
a2);
v3 = func1(a1, a2);
if ( v3 == -1 )
{
v7 = *_errno_location();
v8 = "None";
if ( v7 )
v8 = strerror(v7);
v9 = func0();
fprintf(
stderr,
"[WARN]%s (%s:%d: errno: %s) Subnetting bits failed\n",
v9,
"src/subnetting/ip_util_subnet_bits_by_host_per_subnet.c",
46LL,
v8);
}
else
{
v4 = IP_host_bits(a1) - v3;
v5 = func0();
fprintf(
stderr,
"[DEBUG]%s (%s:%d) Found %d suitable\n",
v5,
"src/subnetting/ip_util_subnet_bits_by_host_per_subnet.c",
43LL,
v4);
v3 = IP_host_bits(a1) - v3;
}
return v3;
}

original_code:
extern int IP_subnet_bits_by_subnets(
  IP_T ip, subnet_size_t subnets) {
 fprintf(stderr, "[DEBUG]%s (%s:%d) " "Finding suitable subnetting for %lx with %lu subnets" "\n", get_time(), "src/subnetting/ip_util_subnet_bits_by_host_per_subnet.c", 36, ip, subnets);
 int comp_bits = IP_subnet_bits_by_hosts_per_subnet(
  ip, (host_size_t)subnets);
 if (comp_bits != -1) {
  fprintf(stderr, "[DEBUG]%s (%s:%d) " "Found %d suitable" "\n", get_time(), "src/subnetting/ip_util_subnet_bits_by_host_per_subnet.c", 43, IP_host_bits(ip) - comp_bits);
  return IP_host_bits(ip) - comp_bits;
 }
 fprintf(stderr, "[WARN]%s (%s:%d: errno: %s) " "Subnetting bits failed" "\n", get_time(), "src/subnetting/ip_util_subnet_bits_by_host_per_subnet.c", 46, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ()))));
 return -1;
}

canonical_original_code:
extern int IP_subnet_bits_by_subnets(unsigned long ip, unsigned long subnets) {
 fprintf(stderr, "[DEBUG]%s (%s:%d) " "Finding suitable subnetting for %lx with %lu subnets" "\n", get_time(), "src/subnetting/ip_util_subnet_bits_by_host_per_subnet.c", 36, ip, subnets);
 int comp_bits = IP_subnet_bits_by_hosts_per_subnet(
  ip, (host_size_t)subnets);
 if (comp_bits != -1) {
  fprintf(stderr, "[DEBUG]%s (%s:%d) " "Found %d suitable" "\n", get_time(), "src/subnetting/ip_util_subnet_bits_by_host_per_subnet.c", 43, IP_host_bits(ip) - comp_bits);
  return IP_host_bits(ip) - comp_bits;
 }
 fprintf(stderr, "[WARN]%s (%s:%d: errno: %s) " "Subnetting bits failed" "\n", get_time(), "src/subnetting/ip_util_subnet_bits_by_host_per_subnet.c", 46, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ()))));
 return -1;
}


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

time(&timer);
v0 = localtime(&timer);
strftime(buffer, 0x1BuLL, "[%Y:%m:%d %H:%M:%S]", v0);
return buffer;
}

original_code:
static char* get_time() {
 time_t timer;
 struct tm* tm_info;
 time(&timer);
 tm_info = localtime(&timer);
 strftime(buffer, 27, "[%Y:%m:%d %H:%M:%S]", tm_info);
 return buffer;
}


decompiled_code:
__int64 __fastcall IP_dot_decimal_to_ip(const char *a1, __int64 *a2)
{
char *v3; // rax
__int64 v4; // rbx
__int64 v5; // r12
char *v6; // rax
__int64 v7; // r12
char *v8; // rax
__int64 result; // rax
int v10; // edi
char *v11; // rbp
char *v12; // rax
int v13; // edi
char *v14; // rbp
char *v15; // rax
__int64 v16; // rbp
int v17; // edi
char *v18; // rbx
char *v19; // rax
unsigned int v20; // [rsp+0h] [rbp-38h] BYREF
char v21; // [rsp+4h] [rbp-34h] BYREF
char v22; // [rsp+8h] [rbp-30h] BYREF
char v23; // [rsp+Ch] [rbp-2Ch] BYREF

v3 = get_time();
fprintf(stderr, "[DEBUG]%s (%s:%d) Parsing: %s\n", v3, "src/subnetting/ip_util_dot_decimal_to_ip.c", 9LL, a1);
if ( (unsigned int)_isoc99_sscanf(a1, "%d%*[.]%d%*[.]%d%*[.]%d", &v20, &v21, &v22, &v23) == 4 )
{
if ( v20 > 0xDF )
{
IP_set_strerror("Unknown class: %s", a1);
v13 = *_errno_location();
v14 = "None";
if ( v13 )
v14 = strerror(v13);
v15 = get_time();
fprintf(
stderr,
"[WARN]%s (%s:%d: errno: %s) Unknown class: %s\n",
v15,
"src/subnetting/ip_util_dot_decimal_to_ip.c",
20LL,
v14,
a1);
result = 0xFFFFFFFFLL;
}
else
{
*a2 = 0LL;
v4 = 0LL;
while ( 1 )
{
*a2 <<= 8;
v5 = *(&v20 + v4);
if ( (unsigned int)v5 > 0xFF )
break;
v6 = get_time();
fprintf(
stderr,
"[DEBUG]%s (%s:%d) Octect[%d] = %d\n",
v6,
"src/subnetting/ip_util_dot_decimal_to_ip.c",
28LL,
(unsigned int)v4,
v5);
v7 = *a2 + *(&v20 + v4);
*a2 = v7;
if ( ++v4 == 4 )
{
v8 = get_time();
fprintf(
stderr,
"[DEBUG]%s (%s:%d) Parsed IP:%lx\n",
v8,
"src/subnetting/ip_util_dot_decimal_to_ip.c",
38LL,
v7);
return 0LL;
}
}
IP_set_strerror("Octect not in interval: %d", (unsigned int)v5);
v16 = *(&v20 + (int)v4);
v17 = *_errno_location();
v18 = "None";
if ( v17 )
v18 = strerror(v17);
v19 = get_time();
fprintf(
stderr,
"[WARN]%s (%s:%d: errno: %s) Octect not in interval: %d\n",
v19,
"src/subnetting/ip_util_dot_decimal_to_ip.c",
33LL,
v18,
v16);
result = 0xFFFFFFFFLL;
}
}
else
{
IP_set_strerror("Incorrect decimal format ip '%s'", a1);
v10 = *_errno_location();
v11 = "None";
if ( v10 )
v11 = strerror(v10);
v12 = get_time();
fprintf(
stderr,
"[WARN]%s (%s:%d: errno: %s) Incorrect decimal format ip '%s'\n",
v12,
"src/subnetting/ip_util_dot_decimal_to_ip.c",
14LL,
v11,
a1);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1, __int64 *a2)
{
char *v3; // rax
__int64 v4; // rbx
__int64 v5; // r12
char *v6; // rax
__int64 v7; // r12
char *v8; // rax
__int64 result; // rax
int v10; // edi
char *v11; // rbp
char *v12; // rax
int v13; // edi
char *v14; // rbp
char *v15; // rax
__int64 v16; // rbp
int v17; // edi
char *v18; // rbx
char *v19; // rax
unsigned int v20; // [rsp+0h] [rbp-38h] BYREF
char v21; // [rsp+4h] [rbp-34h] BYREF
char v22; // [rsp+8h] [rbp-30h] BYREF
char v23; // [rsp+Ch] [rbp-2Ch] BYREF

v3 = func0();
fprintf(stderr, "[DEBUG]%s (%s:%d) Parsing: %s\n", v3, "src/subnetting/ip_util_dot_decimal_to_ip.c", 9LL, a1);
if ( (unsigned int)_isoc99_sscanf(a1, "%d%*[.]%d%*[.]%d%*[.]%d", &v20, &v21, &v22, &v23) == 4 )
{
if ( v20 > 0xDF )
{
IP_set_strerror("Unknown class: %s", a1);
v13 = *_errno_location();
v14 = "None";
if ( v13 )
v14 = strerror(v13);
v15 = func0();
fprintf(
stderr,
"[WARN]%s (%s:%d: errno: %s) Unknown class: %s\n",
v15,
"src/subnetting/ip_util_dot_decimal_to_ip.c",
20LL,
v14,
a1);
result = 0xFFFFFFFFLL;
}
else
{
*a2 = 0LL;
v4 = 0LL;
while ( 1 )
{
*a2 <<= 8;
v5 = *(&v20 + v4);
if ( (unsigned int)v5 > 0xFF )
break;
v6 = func0();
fprintf(
stderr,
"[DEBUG]%s (%s:%d) Octect[%d] = %d\n",
v6,
"src/subnetting/ip_util_dot_decimal_to_ip.c",
28LL,
(unsigned int)v4,
v5);
v7 = *a2 + *(&v20 + v4);
*a2 = v7;
if ( ++v4 == 4 )
{
v8 = func0();
fprintf(
stderr,
"[DEBUG]%s (%s:%d) Parsed IP:%lx\n",
v8,
"src/subnetting/ip_util_dot_decimal_to_ip.c",
38LL,
v7);
return 0LL;
}
}
IP_set_strerror("Octect not in interval: %d", (unsigned int)v5);
v16 = *(&v20 + (int)v4);
v17 = *_errno_location();
v18 = "None";
if ( v17 )
v18 = strerror(v17);
v19 = func0();
fprintf(
stderr,
"[WARN]%s (%s:%d: errno: %s) Octect not in interval: %d\n",
v19,
"src/subnetting/ip_util_dot_decimal_to_ip.c",
33LL,
v18,
v16);
result = 0xFFFFFFFFLL;
}
}
else
{
IP_set_strerror("Incorrect decimal format ip '%s'", a1);
v10 = *_errno_location();
v11 = "None";
if ( v10 )
v11 = strerror(v10);
v12 = func0();
fprintf(
stderr,
"[WARN]%s (%s:%d: errno: %s) Incorrect decimal format ip '%s'\n",
v12,
"src/subnetting/ip_util_dot_decimal_to_ip.c",
14LL,
v11,
a1);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
extern int IP_dot_decimal_to_ip(char* address, IP_T* ip) {
 unsigned int octect[4];
 int scanned;
 fprintf(stderr, "[DEBUG]%s (%s:%d) " "Parsing: %s" "\n", get_time(), "src/subnetting/ip_util_dot_decimal_to_ip.c", 9, address);
 scanned = sscanf(address, "%d%*[.]%d%*[.]%d%*[.]%d",
                  &octect[0], &octect[1], &octect[2], &octect[3]);
 if (scanned != 4) {
  IP_set_strerror("Incorrect decimal format ip '%s'", address);
  fprintf(stderr, "[WARN]%s (%s:%d: errno: %s) " "Incorrect decimal format ip '%s'" "\n", get_time(), "src/subnetting/ip_util_dot_decimal_to_ip.c", 14, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ()))), address);
  return -1;
 }
 if (223 < octect[0]) {
  IP_set_strerror("Unknown class: %s", address);
  fprintf(stderr, "[WARN]%s (%s:%d: errno: %s) " "Unknown class: %s" "\n", get_time(), "src/subnetting/ip_util_dot_decimal_to_ip.c", 20, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ()))), address);
  return -1;
 }
 *ip = 0UL;
 int i;
 for(i = 0; i < 4; i++) {
  *ip = (*ip) << 8;
  if (0 <= octect[i] && octect[i] <= 255) {
   fprintf(stderr, "[DEBUG]%s (%s:%d) " "Octect[%d] = %d" "\n", get_time(), "src/subnetting/ip_util_dot_decimal_to_ip.c", 28, i, octect[i]);
   *ip += octect[i];
  } else {
   IP_set_strerror(
    "Octect not in interval: %d", octect[i]);
   fprintf(stderr, "[WARN]%s (%s:%d: errno: %s) " "Octect not in interval: %d" "\n", get_time(), "src/subnetting/ip_util_dot_decimal_to_ip.c", 33, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ()))), octect[i]);
   return -1;
  }
 }
 fprintf(stderr, "[DEBUG]%s (%s:%d) " "Parsed IP:%lx" "\n", get_time(), "src/subnetting/ip_util_dot_decimal_to_ip.c", 38, *ip);
 return 0;
}

canonical_original_code:
extern int IP_dot_decimal_to_ip(char *address, unsigned long *ip) {
 unsigned int octect[4];
 int scanned;
 fprintf(stderr, "[DEBUG]%s (%s:%d) " "Parsing: %s" "\n", get_time(), "src/subnetting/ip_util_dot_decimal_to_ip.c", 9, address);
 scanned = sscanf(address, "%d%*[.]%d%*[.]%d%*[.]%d",
                  &octect[0], &octect[1], &octect[2], &octect[3]);
 if (scanned != 4) {
  IP_set_strerror("Incorrect decimal format ip '%s'", address);
  fprintf(stderr, "[WARN]%s (%s:%d: errno: %s) " "Incorrect decimal format ip '%s'" "\n", get_time(), "src/subnetting/ip_util_dot_decimal_to_ip.c", 14, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ()))), address);
  return -1;
 }
 if (223 < octect[0]) {
  IP_set_strerror("Unknown class: %s", address);
  fprintf(stderr, "[WARN]%s (%s:%d: errno: %s) " "Unknown class: %s" "\n", get_time(), "src/subnetting/ip_util_dot_decimal_to_ip.c", 20, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ()))), address);
  return -1;
 }
 *ip = 0UL;
 int i;
 for(i = 0; i < 4; i++) {
  *ip = (*ip) << 8;
  if (0 <= octect[i] && octect[i] <= 255) {
   fprintf(stderr, "[DEBUG]%s (%s:%d) " "Octect[%d] = %d" "\n", get_time(), "src/subnetting/ip_util_dot_decimal_to_ip.c", 28, i, octect[i]);
   *ip += octect[i];
  } else {
   IP_set_strerror(
    "Octect not in interval: %d", octect[i]);
   fprintf(stderr, "[WARN]%s (%s:%d: errno: %s) " "Octect not in interval: %d" "\n", get_time(), "src/subnetting/ip_util_dot_decimal_to_ip.c", 33, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ()))), octect[i]);
   return -1;
  }
 }
 fprintf(stderr, "[DEBUG]%s (%s:%d) " "Parsed IP:%lx" "\n", get_time(), "src/subnetting/ip_util_dot_decimal_to_ip.c", 38, *ip);
 return 0;
}

variable_types:
address
char *

variable_types:
ip
unsigned long *

variable_types:
octect
unsigned int [4]

variable_types: scanned int

variable_types: i int


decompiled_code:
__int64 __fastcall Socket_listen(__int64 a1, unsigned int a2)
{
char *v2; // rax
char *v3; // rax
unsigned int v4; // ebx
const char *v6; // rbp
char *v7; // rax

v2 = get_time();
fprintf(
stderr,
"[DEBUG]%s (%s:%d) Trying to listen to %d connections\n",
v2,
"src/network/bsd-win-sock-listen.c",
9LL,
a2);
if ( listen(*(_DWORD *)(a1 + 4), a2) == -1 )
{
v4 = -1;
Socket_set_errno(4294967288LL);
v6 = (const char *)Socket_strerror();
v7 = get_time();
fprintf(stderr, "[DEBUG]%s (%s:%d) Listen failed: %s\n", v7, "src/network/bsd-win-sock-listen.c", 12LL, v6);
}
else
{
v3 = get_time();
fprintf(stderr, "[DEBUG]%s (%s:%d) Listen succeded\n", v3, "src/network/bsd-win-sock-listen.c", 16LL);
v4 = 0;
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, unsigned int a2)
{
char *v2; // rax
char *v3; // rax
unsigned int v4; // ebx
const char *v6; // rbp
char *v7; // rax

v2 = func0();
fprintf(
stderr,
"[DEBUG]%s (%s:%d) Trying to listen to %d connections\n",
v2,
"src/network/bsd-win-sock-listen.c",
9LL,
a2);
if ( listen(*(_DWORD *)(a1 + 4), a2) == -1 )
{
v4 = -1;
Socket_set_errno(4294967288LL);
v6 = (const char *)Socket_strerror();
v7 = func0();
fprintf(stderr, "[DEBUG]%s (%s:%d) Listen failed: %s\n", v7, "src/network/bsd-win-sock-listen.c", 12LL, v6);
}
else
{
v3 = func0();
fprintf(stderr, "[DEBUG]%s (%s:%d) Listen succeded\n", v3, "src/network/bsd-win-sock-listen.c", 16LL);
v4 = 0;
}
return v4;
}

original_code:
extern int Socket_listen(Socket_T* sock, int connections) {
 fprintf(stderr, "[DEBUG]%s (%s:%d) " "Trying to listen to %d connections" "\n", get_time(), "src/network/bsd-win-sock-listen.c", 9, connections);
 if (listen(sock->sockfd_src, connections) == -1) {
  Socket_set_errno(-8);
  fprintf(stderr, "[DEBUG]%s (%s:%d) " "Listen failed: %s" "\n", get_time(), "src/network/bsd-win-sock-listen.c", 12, Socket_strerror());
  return -1;
 }
 fprintf(stderr, "[DEBUG]%s (%s:%d) " "Listen succeded" "\n", get_time(), "src/network/bsd-win-sock-listen.c", 16);
 return 0;
}

canonical_original_code:
extern int Socket_listen(struct Socket_T *sock, int connections) {
 fprintf(stderr, "[DEBUG]%s (%s:%d) " "Trying to listen to %d connections" "\n", get_time(), "src/network/bsd-win-sock-listen.c", 9, connections);
 if (listen(sock->sockfd_src, connections) == -1) {
  Socket_set_errno(-8);
  fprintf(stderr, "[DEBUG]%s (%s:%d) " "Listen failed: %s" "\n", get_time(), "src/network/bsd-win-sock-listen.c", 12, Socket_strerror());
  return -1;
 }
 fprintf(stderr, "[DEBUG]%s (%s:%d) " "Listen succeded" "\n", get_time(), "src/network/bsd-win-sock-listen.c", 16);
 return 0;
}

variable_types: connections int


decompiled_code:
__int64 __fastcall request_option_code(__int64 a1)
{
__int64 result; // rax
char v2[8216]; // [rsp+0h] [rbp-2018h] BYREF

memset(v2, 0, 0x2001uLL);
if ( (unsigned int)_isoc99_sscanf(a1, &unk_21B, v2) != 1 )
return 0xFFFFFFFFLL;
result = 17LL;
if ( strcmp(v2, "info-by-ip-and-hosts") )
{
result = 18LL;
if ( strcmp(v2, "info-by-ip-and-hosts-per-subnet") )
{
result = 19LL;
if ( strcmp(v2, "info-by-ip-and-subnets") )
{
result = 20LL;
if ( strcmp(v2, "info-by-hosts") )
{
result = 21LL;
if ( strcmp(v2, "info-by-hosts-per-subnet") )
{
result = 22LL;
if ( strcmp(v2, "info-by-subnets") )
{
result = 23LL;
if ( strcmp(v2, "subnetting-by-ip-and-hosts") )
{
result = 24LL;
if ( strcmp(v2, "subnetting-by-ip-and-hosts-per-subnet") )
{
result = 25LL;
if ( strcmp(v2, "subnetting-by-ip-and-subnets") )
{
result = 26LL;
if ( strcmp(v2, "subnetting-by-hosts") )
{
result = 27LL;
if ( strcmp(v2, "subnetting-by-hosts-per-subnet") )
{
result = 28LL;
if ( strcmp(v2, "subnetting-by-subnets") )
{
result = 1000LL;
if ( strcmp(v2, "shutdown") )
result = strcmp(v2, "shutdown\r\n") == 0 ? 1000 : 16;
}
}
}
}
}
}
}
}
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
__int64 result; // rax
char v2[8216]; // [rsp+0h] [rbp-2018h] BYREF

memset(v2, 0, 0x2001uLL);
if ( (unsigned int)_isoc99_sscanf(a1, &unk_21B, v2) != 1 )
return 0xFFFFFFFFLL;
result = 17LL;
if ( strcmp(v2, "info-by-ip-and-hosts") )
{
result = 18LL;
if ( strcmp(v2, "info-by-ip-and-hosts-per-subnet") )
{
result = 19LL;
if ( strcmp(v2, "info-by-ip-and-subnets") )
{
result = 20LL;
if ( strcmp(v2, "info-by-hosts") )
{
result = 21LL;
if ( strcmp(v2, "info-by-hosts-per-subnet") )
{
result = 22LL;
if ( strcmp(v2, "info-by-subnets") )
{
result = 23LL;
if ( strcmp(v2, "subnetting-by-ip-and-hosts") )
{
result = 24LL;
if ( strcmp(v2, "subnetting-by-ip-and-hosts-per-subnet") )
{
result = 25LL;
if ( strcmp(v2, "subnetting-by-ip-and-subnets") )
{
result = 26LL;
if ( strcmp(v2, "subnetting-by-hosts") )
{
result = 27LL;
if ( strcmp(v2, "subnetting-by-hosts-per-subnet") )
{
result = 28LL;
if ( strcmp(v2, "subnetting-by-subnets") )
{
result = 1000LL;
if ( strcmp(v2, "shutdown") )
result = strcmp(v2, "shutdown\r\n") == 0 ? 1000 : 16;
}
}
}
}
}
}
}
}
}
}
}
}
return result;
}

original_code:
extern int request_option_code(const char* request) {
 char s[8193];
 memset(s, 0, sizeof(s));
 if (sscanf(request, "%s", s) != 1)
  return -1;
 if ((strcmp((s), ("info-by-ip-and-hosts")) == 0))
  return 17;
 if ((strcmp((s), ("info-by-ip-and-hosts-per-subnet")) == 0))
  return 18;
 if ((strcmp((s), ("info-by-ip-and-subnets")) == 0))
  return 19;
 if ((strcmp((s), ("info-by-hosts")) == 0))
  return 20;
 if ((strcmp((s), ("info-by-hosts-per-subnet")) == 0))
  return 21;
 if ((strcmp((s), ("info-by-subnets")) == 0))
  return 22;
 if ((strcmp((s), ("subnetting-by-ip-and-hosts")) == 0))
  return 23;
 if ((strcmp((s), ("subnetting-by-ip-and-hosts-per-subnet")) == 0))
  return 24;
 if ((strcmp((s), ("subnetting-by-ip-and-subnets")) == 0))
  return 25;
 if ((strcmp((s), ("subnetting-by-hosts")) == 0))
  return 26;
 if ((strcmp((s), ("subnetting-by-hosts-per-subnet")) == 0))
  return 27;
 if ((strcmp((s), ("subnetting-by-subnets")) == 0))
  return 28;
 if ((strcmp((s), ("shutdown")) == 0) || (strcmp((s), ("shutdown\r\n")) == 0))
  return 1000;
 return 16;
}

canonical_original_code:
extern int request_option_code(char *request) {
 char s[8193];
 memset(s, 0, sizeof(s));
 if (sscanf(request, "%s", s) != 1)
  return -1;
 if ((strcmp((s), ("info-by-ip-and-hosts")) == 0))
  return 17;
 if ((strcmp((s), ("info-by-ip-and-hosts-per-subnet")) == 0))
  return 18;
 if ((strcmp((s), ("info-by-ip-and-subnets")) == 0))
  return 19;
 if ((strcmp((s), ("info-by-hosts")) == 0))
  return 20;
 if ((strcmp((s), ("info-by-hosts-per-subnet")) == 0))
  return 21;
 if ((strcmp((s), ("info-by-subnets")) == 0))
  return 22;
 if ((strcmp((s), ("subnetting-by-ip-and-hosts")) == 0))
  return 23;
 if ((strcmp((s), ("subnetting-by-ip-and-hosts-per-subnet")) == 0))
  return 24;
 if ((strcmp((s), ("subnetting-by-ip-and-subnets")) == 0))
  return 25;
 if ((strcmp((s), ("subnetting-by-hosts")) == 0))
  return 26;
 if ((strcmp((s), ("subnetting-by-hosts-per-subnet")) == 0))
  return 27;
 if ((strcmp((s), ("subnetting-by-subnets")) == 0))
  return 28;
 if ((strcmp((s), ("shutdown")) == 0) || (strcmp((s), ("shutdown\r\n")) == 0))
  return 1000;
 return 16;
}

variable_types:
request
char *


decompiled_code:
__int64 __fastcall IP_private_ip(unsigned int a1, int a2)
{
__int64 v2; // rbx
int v3; // edi
char *v4; // rbp
char *v5; // rax
char v7[72]; // [rsp+0h] [rbp-68h] BYREF
__int64 v8[4]; // [rsp+48h] [rbp-20h] BYREF

v8[0] = -1LL;
if ( a1 == 16 )
{
sprintf(v7, "172.%d.0.0", (unsigned int)(a2 % 16 + 16));
goto LABEL_8;
}
v2 = a1;
if ( a1 == 24 )
{
strcpy(v7, "10.0.0.0");
LABEL_8:
IP_dot_decimal_to_ip(v7, v8);
return v8[0];
}
if ( a1 == 8 )
{
sprintf(v7, "192.168.%d.0", (unsigned int)(a2 % 256));
goto LABEL_8;
}
IP_set_strerror("Unkown class for %d host bits", a1);
v3 = *_errno_location();
v4 = "None";
if ( v3 )
v4 = strerror(v3);
v5 = get_time();
fprintf(
stderr,
"[WARN]%s (%s:%d: errno: %s) Unkown class for %d host bits\n",
v5,
"src/subnetting/ip_util_private_ip.c",
25LL,
v4,
v2);
return -1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1, int a2)
{
__int64 v2; // rbx
int v3; // edi
char *v4; // rbp
char *v5; // rax
char v7[72]; // [rsp+0h] [rbp-68h] BYREF
__int64 v8[4]; // [rsp+48h] [rbp-20h] BYREF

v8[0] = -1LL;
if ( a1 == 16 )
{
sprintf(v7, "172.%d.0.0", (unsigned int)(a2 % 16 + 16));
goto LABEL_8;
}
v2 = a1;
if ( a1 == 24 )
{
strcpy(v7, "10.0.0.0");
LABEL_8:
IP_dot_decimal_to_ip(v7, v8);
return v8[0];
}
if ( a1 == 8 )
{
sprintf(v7, "192.168.%d.0", (unsigned int)(a2 % 256));
goto LABEL_8;
}
IP_set_strerror("Unkown class for %d host bits", a1);
v3 = *_errno_location();
v4 = "None";
if ( v3 )
v4 = strerror(v3);
v5 = func0();
fprintf(
stderr,
"[WARN]%s (%s:%d: errno: %s) Unkown class for %d host bits\n",
v5,
"src/subnetting/ip_util_private_ip.c",
25LL,
v4,
v2);
return -1LL;
}

original_code:
extern IP_T IP_private_ip(int host_bits, int id) {
 IP_T ip = -1L;
 char address[65];
 switch(host_bits) {
  case 24:
   sprintf(address, "10.0.0.0");
   break;
  case 16:
   id = (id % 16) + 16;
   sprintf(address, "172.%d.0.0", id);
   break;
  case 8:
   id = id % 256;
   sprintf(address, "192.168.%d.0", id);
   break;
  default:
   IP_set_strerror("Unkown class for %d host bits",
                   host_bits);
   fprintf(stderr, "[WARN]%s (%s:%d: errno: %s) " "Unkown class for %d host bits" "\n", get_time(), "src/subnetting/ip_util_private_ip.c", 25, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ()))), host_bits);
   return -1L;
   break;
 }
 IP_dot_decimal_to_ip(address, &ip);
 return ip;
}

canonical_original_code:
extern unsigned long IP_private_ip(int host_bits, int id) {
 unsigned long ip = -1L;
 char address[65];
 switch(host_bits) {
  case 24:
   sprintf(address, "10.0.0.0");
   break;
  case 16:
   id = (id % 16) + 16;
   sprintf(address, "172.%d.0.0", id);
   break;
  case 8:
   id = id % 256;
   sprintf(address, "192.168.%d.0", id);
   break;
  default:
   IP_set_strerror("Unkown class for %d host bits",
                   host_bits);
   fprintf(stderr, "[WARN]%s (%s:%d: errno: %s) " "Unkown class for %d host bits" "\n", get_time(), "src/subnetting/ip_util_private_ip.c", 25, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ()))), host_bits);
   return -1L;
   break;
 }
 IP_dot_decimal_to_ip(address, &ip);
 return ip;
}

variable_types: id int

variable_types:
address
char [65]

return_type: unsigned long


decompiled_code:
__int64 __fastcall Socket_timeout(int *a1, int a2)
{
char *v2; // rax
unsigned int v3; // ebx
const char *v5; // rbp
int v6; // edi
char *v7; // r12
char *v8; // rax
__int64 v9[5]; // [rsp+0h] [rbp-28h] BYREF

v2 = get_time();
fprintf(stderr, "[DEBUG]%s (%s:%d) Setting timeout\n", v2, "src/network/bsd-win-sock-timeout.c", 9LL);
v9[0] = a2;
v9[1] = 0LL;
if ( setsockopt(*a1, 1, 20, v9, 0x10u) != -1 )
return 0;
v3 = -1;
Socket_set_errno(4294967281LL);
v5 = (const char *)Socket_strerror();
v6 = *_errno_location();
v7 = "None";
if ( v6 )
v7 = strerror(v6);
v8 = get_time();
fprintf(
stderr,
"[WARN]%s (%s:%d: errno: %s) Timeout set failed: %s\n",
v8,
"src/network/bsd-win-sock-timeout.c",
24LL,
v7,
v5);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func1(int *a1, int a2)
{
char *v2; // rax
unsigned int v3; // ebx
const char *v5; // rbp
int v6; // edi
char *v7; // r12
char *v8; // rax
__int64 v9[5]; // [rsp+0h] [rbp-28h] BYREF

v2 = func0();
fprintf(stderr, "[DEBUG]%s (%s:%d) Setting timeout\n", v2, "src/network/bsd-win-sock-timeout.c", 9LL);
v9[0] = a2;
v9[1] = 0LL;
if ( setsockopt(*a1, 1, 20, v9, 0x10u) != -1 )
return 0;
v3 = -1;
Socket_set_errno(4294967281LL);
v5 = (const char *)Socket_strerror();
v6 = *_errno_location();
v7 = "None";
if ( v6 )
v7 = strerror(v6);
v8 = func0();
fprintf(
stderr,
"[WARN]%s (%s:%d: errno: %s) Timeout set failed: %s\n",
v8,
"src/network/bsd-win-sock-timeout.c",
24LL,
v7,
v5);
return v3;
}

original_code:
extern int Socket_timeout(Socket_T* sock, int seconds) {
 fprintf(stderr, "[DEBUG]%s (%s:%d) " "Setting timeout" "\n", get_time(), "src/network/bsd-win-sock-timeout.c", 9);
 struct timeval timeout;
  timeout.tv_sec = seconds;
  timeout.tv_usec = 0;
        if(setsockopt(sock->sockfd_dest, 1, 20,
            (char *)&timeout,
            sizeof(timeout)) == -1) {
  Socket_set_errno(-15);
  fprintf(stderr, "[WARN]%s (%s:%d: errno: %s) " "Timeout set failed: %s" "\n", get_time(), "src/network/bsd-win-sock-timeout.c", 24, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ()))), Socket_strerror());
  return -1;
 }
 return 0;
}

canonical_original_code:
extern int Socket_timeout(struct Socket_T *sock, int seconds) {
 fprintf(stderr, "[DEBUG]%s (%s:%d) " "Setting timeout" "\n", get_time(), "src/network/bsd-win-sock-timeout.c", 9);
 struct timeval timeout;
  timeout.tv_sec = seconds;
  timeout.tv_usec = 0;
        if(setsockopt(sock->sockfd_dest, 1, 20,
            (char *)&timeout,
            sizeof(timeout)) == -1) {
  Socket_set_errno(-15);
  fprintf(stderr, "[WARN]%s (%s:%d: errno: %s) " "Timeout set failed: %s" "\n", get_time(), "src/network/bsd-win-sock-timeout.c", 24, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ()))), Socket_strerror());
  return -1;
 }
 return 0;
}

variable_types: seconds int

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


decompiled_code:
__int64 __fastcall Socket_accept(int *a1)
{
unsigned int v1; // ebx
char *v2; // rax
char *v3; // rax
unsigned int v4; // ebx
char *v5; // rax
char *v7; // rax
const char *v8; // rbp
int v9; // edi
char *v10; // r12
char *v11; // rax

v1 = *a1;
if ( *a1 != -1 )
{
v7 = get_time();
fprintf(stderr, "[DEBUG]%s (%s:%d) Closing socket: %d\n", v7, "src/network/bsd-win-sock-accept.c", 11LL, v1);
close(*a1);
*a1 = -1;
}
v2 = get_time();
fprintf(stderr, "[DEBUG]%s (%s:%d) Socket startup for accept\n", v2, "src/network/bsd-win-sock-accept.c", 16LL);
if ( (int)Socket_startup() < 0 )
return (unsigned int)-1;
v3 = get_time();
fprintf(stderr, "[DEBUG]%s (%s:%d) Accepting socket\n", v3, "src/network/bsd-win-sock-accept.c", 20LL);
v4 = accept(a1[1], 0LL, 0LL);
*a1 = v4;
if ( v4 == -1 )
{
Socket_set_errno(4294967287LL);
v8 = (const char *)Socket_strerror();
v9 = *_errno_location();
v10 = "None";
if ( v9 )
v10 = strerror(v9);
v11 = get_time();
fprintf(
stderr,
"[ERROR]%s (%s:%d: errno: %s) Accept failed: %s\n",
v11,
"src/network/bsd-win-sock-accept.c",
24LL,
v10,
v8);
}
else
{
v5 = get_time();
fprintf(stderr, "[DEBUG]%s (%s:%d) Socket accepted: %d\n", v5, "src/network/bsd-win-sock-accept.c", 28LL, v4);
v4 = 0;
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func1(int *a1)
{
unsigned int v1; // ebx
char *v2; // rax
char *v3; // rax
unsigned int v4; // ebx
char *v5; // rax
char *v7; // rax
const char *v8; // rbp
int v9; // edi
char *v10; // r12
char *v11; // rax

v1 = *a1;
if ( *a1 != -1 )
{
v7 = func0();
fprintf(stderr, "[DEBUG]%s (%s:%d) Closing socket: %d\n", v7, "src/network/bsd-win-sock-accept.c", 11LL, v1);
close(*a1);
*a1 = -1;
}
v2 = func0();
fprintf(stderr, "[DEBUG]%s (%s:%d) Socket startup for accept\n", v2, "src/network/bsd-win-sock-accept.c", 16LL);
if ( (int)Socket_startup() < 0 )
return (unsigned int)-1;
v3 = func0();
fprintf(stderr, "[DEBUG]%s (%s:%d) Accepting socket\n", v3, "src/network/bsd-win-sock-accept.c", 20LL);
v4 = accept(a1[1], 0LL, 0LL);
*a1 = v4;
if ( v4 == -1 )
{
Socket_set_errno(4294967287LL);
v8 = (const char *)Socket_strerror();
v9 = *_errno_location();
v10 = "None";
if ( v9 )
v10 = strerror(v9);
v11 = func0();
fprintf(
stderr,
"[ERROR]%s (%s:%d: errno: %s) Accept failed: %s\n",
v11,
"src/network/bsd-win-sock-accept.c",
24LL,
v10,
v8);
}
else
{
v5 = func0();
fprintf(stderr, "[DEBUG]%s (%s:%d) Socket accepted: %d\n", v5, "src/network/bsd-win-sock-accept.c", 28LL, v4);
v4 = 0;
}
return v4;
}

original_code:
extern int Socket_accept(Socket_T* sock) {
 if (sock->sockfd_dest != -1) {
  fprintf(stderr, "[DEBUG]%s (%s:%d) " "Closing socket: %d" "\n", get_time(), "src/network/bsd-win-sock-accept.c", 11, sock->sockfd_dest);
  close(sock->sockfd_dest);
  sock->sockfd_dest = -1;
 }
 fprintf(stderr, "[DEBUG]%s (%s:%d) " "Socket startup for accept" "\n", get_time(), "src/network/bsd-win-sock-accept.c", 16);
 if (Socket_startup() < 0)
  return -1;
 fprintf(stderr, "[DEBUG]%s (%s:%d) " "Accepting socket" "\n", get_time(), "src/network/bsd-win-sock-accept.c", 20);
 sock->sockfd_dest = accept(sock->sockfd_src, ((void *)0), ((void *)0));
 if (sock->sockfd_dest == -1) {
  Socket_set_errno(-9);
  fprintf(stderr, "[ERROR]%s (%s:%d: errno: %s) " "Accept failed: %s" "\n", get_time(), "src/network/bsd-win-sock-accept.c", 24, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ()))), Socket_strerror());
  return -1;
 }
 fprintf(stderr, "[DEBUG]%s (%s:%d) " "Socket accepted: %d" "\n", get_time(), "src/network/bsd-win-sock-accept.c", 28, sock->sockfd_dest);
 return 0;
}

canonical_original_code:
extern int Socket_accept(struct Socket_T *sock) {
 if (sock->sockfd_dest != -1) {
  fprintf(stderr, "[DEBUG]%s (%s:%d) " "Closing socket: %d" "\n", get_time(), "src/network/bsd-win-sock-accept.c", 11, sock->sockfd_dest);
  close(sock->sockfd_dest);
  sock->sockfd_dest = -1;
 }
 fprintf(stderr, "[DEBUG]%s (%s:%d) " "Socket startup for accept" "\n", get_time(), "src/network/bsd-win-sock-accept.c", 16);
 if (Socket_startup() < 0)
  return -1;
 fprintf(stderr, "[DEBUG]%s (%s:%d) " "Accepting socket" "\n", get_time(), "src/network/bsd-win-sock-accept.c", 20);
 sock->sockfd_dest = accept(sock->sockfd_src, ((void *)0), ((void *)0));
 if (sock->sockfd_dest == -1) {
  Socket_set_errno(-9);
  fprintf(stderr, "[ERROR]%s (%s:%d: errno: %s) " "Accept failed: %s" "\n", get_time(), "src/network/bsd-win-sock-accept.c", 24, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ()))), Socket_strerror());
  return -1;
 }
 fprintf(stderr, "[DEBUG]%s (%s:%d) " "Socket accepted: %d" "\n", get_time(), "src/network/bsd-win-sock-accept.c", 28, sock->sockfd_dest);
 return 0;
}

variable_types: struct Socket_T { int sockfd_dest; int sockfd_src; 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; } hints; struct addrinfo *result; char peer_ip[20]; char peer_port[20]; char *address; char *portnum; } *


decompiled_code:
__int64 __fastcall Socket_connect(int *a1)
{
char *v2; // rax
__int64 v3; // rbx
char *v4; // rax
int v5; // edi
__int64 result; // rax
const char *v7; // rbx
int v8; // edi
char *v9; // r12
char *v10; // rax
const char *v11; // r13
int v12; // edi
char *v13; // r14
char *v14; // rax
const char *v15; // rbx
int v16; // edi
char *v17; // rbp
char *v18; // rax

v2 = get_time();
fprintf(stderr, "[DEBUG]%s (%s:%d) Searching available addrinfos\n", v2, "src/network/bsd-win-sock-connect.c", 10LL);
v3 = *((_QWORD *)a1 + 7);
if ( v3 )
{
while ( 1 )
{
v4 = get_time();
fprintf(stderr, "[DEBUG]%s (%s:%d) Obtaining socket\n", v4, "src/network/bsd-win-sock-connect.c", 12LL);
v5 = socket(*(_DWORD *)(v3 + 4), *(_DWORD *)(v3 + 8), *(_DWORD *)(v3 + 12));
*a1 = v5;
if ( v5 == -1 )
break;
if ( connect(v5, *(const struct sockaddr **)(v3 + 24), *(_DWORD *)(v3 + 16)) != -1 )
goto LABEL_4;
close(*a1);
Socket_set_errno(4294967286LL);
v11 = (const char *)Socket_strerror();
v12 = *_errno_location();
v13 = "None";
if ( v12 )
v13 = strerror(v12);
v14 = get_time();
fprintf(
stderr,
"[WARN]%s (%s:%d: errno: %s) Unable to connect: %s\n",
v14,
"src/network/bsd-win-sock-connect.c",
27LL,
v13,
v11);
*a1 = -1;
v3 = *(_QWORD *)(v3 + 40);
if ( !v3 )
goto LABEL_12;
}
Socket_set_errno(4294967291LL);
v7 = (const char *)Socket_strerror();
v8 = *_errno_location();
v9 = "None";
if ( v8 )
v9 = strerror(v8);
v10 = get_time();
fprintf(
stderr,
"[ERROR]%s (%s:%d: errno: %s) Invalid socket: %s\n",
v10,
"src/network/bsd-win-sock-connect.c",
19LL,
v9,
v7);
result = (unsigned int)*a1;
}
else
{
LABEL_4:
if ( *a1 == -1 )
{
LABEL_12:
Socket_set_errno(4294967290LL);
v15 = (const char *)Socket_strerror();
v16 = *_errno_location();
v17 = "None";
if ( v16 )
v17 = strerror(v16);
v18 = get_time();
fprintf(
stderr,
"[WARN]%s (%s:%d: errno: %s) Server unavailable: %s\n",
v18,
"src/network/bsd-win-sock-connect.c",
36LL,
v17,
v15);
result = 0xFFFFFFFFLL;
}
else
{
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int *a1)
{
char *v2; // rax
__int64 v3; // rbx
char *v4; // rax
int v5; // edi
__int64 result; // rax
const char *v7; // rbx
int v8; // edi
char *v9; // r12
char *v10; // rax
const char *v11; // r13
int v12; // edi
char *v13; // r14
char *v14; // rax
const char *v15; // rbx
int v16; // edi
char *v17; // rbp
char *v18; // rax

v2 = func0();
fprintf(stderr, "[DEBUG]%s (%s:%d) Searching available addrinfos\n", v2, "src/network/bsd-win-sock-connect.c", 10LL);
v3 = *((_QWORD *)a1 + 7);
if ( v3 )
{
while ( 1 )
{
v4 = func0();
fprintf(stderr, "[DEBUG]%s (%s:%d) Obtaining socket\n", v4, "src/network/bsd-win-sock-connect.c", 12LL);
v5 = socket(*(_DWORD *)(v3 + 4), *(_DWORD *)(v3 + 8), *(_DWORD *)(v3 + 12));
*a1 = v5;
if ( v5 == -1 )
break;
if ( connect(v5, *(const struct sockaddr **)(v3 + 24), *(_DWORD *)(v3 + 16)) != -1 )
goto LABEL_4;
close(*a1);
Socket_set_errno(4294967286LL);
v11 = (const char *)Socket_strerror();
v12 = *_errno_location();
v13 = "None";
if ( v12 )
v13 = strerror(v12);
v14 = func0();
fprintf(
stderr,
"[WARN]%s (%s:%d: errno: %s) Unable to connect: %s\n",
v14,
"src/network/bsd-win-sock-connect.c",
27LL,
v13,
v11);
*a1 = -1;
v3 = *(_QWORD *)(v3 + 40);
if ( !v3 )
goto LABEL_12;
}
Socket_set_errno(4294967291LL);
v7 = (const char *)Socket_strerror();
v8 = *_errno_location();
v9 = "None";
if ( v8 )
v9 = strerror(v8);
v10 = func0();
fprintf(
stderr,
"[ERROR]%s (%s:%d: errno: %s) Invalid socket: %s\n",
v10,
"src/network/bsd-win-sock-connect.c",
19LL,
v9,
v7);
result = (unsigned int)*a1;
}
else
{
LABEL_4:
if ( *a1 == -1 )
{
LABEL_12:
Socket_set_errno(4294967290LL);
v15 = (const char *)Socket_strerror();
v16 = *_errno_location();
v17 = "None";
if ( v16 )
v17 = strerror(v16);
v18 = func0();
fprintf(
stderr,
"[WARN]%s (%s:%d: errno: %s) Server unavailable: %s\n",
v18,
"src/network/bsd-win-sock-connect.c",
36LL,
v17,
v15);
result = 0xFFFFFFFFLL;
}
else
{
result = 0LL;
}
}
return result;
}

original_code:
extern int Socket_connect(Socket_T* sock) {
 struct addrinfo *ptr;
 fprintf(stderr, "[DEBUG]%s (%s:%d) " "Searching available addrinfos" "\n", get_time(), "src/network/bsd-win-sock-connect.c", 10);
 for(ptr = sock->result; ptr != ((void *)0); ptr = ptr->ai_next) {
  fprintf(stderr, "[DEBUG]%s (%s:%d) " "Obtaining socket" "\n", get_time(), "src/network/bsd-win-sock-connect.c", 12);
  sock->sockfd_dest = socket(
   ptr->ai_family,
   ptr->ai_socktype,
   ptr->ai_protocol);
  if (sock->sockfd_dest == -1) {
   Socket_set_errno(-5);
   fprintf(stderr, "[ERROR]%s (%s:%d: errno: %s) " "Invalid socket: %s" "\n", get_time(), "src/network/bsd-win-sock-connect.c", 19, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ()))), Socket_strerror());
   return sock->sockfd_dest;
  }
  if (connect(sock->sockfd_dest, ptr->ai_addr,
             (socklen_t)ptr->ai_addrlen) == -1) {
   close(sock->sockfd_dest);
   Socket_set_errno(-10);
   fprintf(stderr, "[WARN]%s (%s:%d: errno: %s) " "Unable to connect: %s" "\n", get_time(), "src/network/bsd-win-sock-connect.c", 27, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ()))), Socket_strerror());
   sock->sockfd_dest = -1;
   continue;
  }
  break;
 }
 if (sock->sockfd_dest == -1) {
  Socket_set_errno(-6);
  fprintf(stderr, "[WARN]%s (%s:%d: errno: %s) " "Server unavailable: %s" "\n", get_time(), "src/network/bsd-win-sock-connect.c", 36, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ()))), Socket_strerror());
  return -1;
 }
 return 0;
}

canonical_original_code:
extern int Socket_connect(struct Socket_T *sock) {
 struct addrinfo *ptr;
 fprintf(stderr, "[DEBUG]%s (%s:%d) " "Searching available addrinfos" "\n", get_time(), "src/network/bsd-win-sock-connect.c", 10);
 for(ptr = sock->result; ptr != ((void *)0); ptr = ptr->ai_next) {
  fprintf(stderr, "[DEBUG]%s (%s:%d) " "Obtaining socket" "\n", get_time(), "src/network/bsd-win-sock-connect.c", 12);
  sock->sockfd_dest = socket(
   ptr->ai_family,
   ptr->ai_socktype,
   ptr->ai_protocol);
  if (sock->sockfd_dest == -1) {
   Socket_set_errno(-5);
   fprintf(stderr, "[ERROR]%s (%s:%d: errno: %s) " "Invalid socket: %s" "\n", get_time(), "src/network/bsd-win-sock-connect.c", 19, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ()))), Socket_strerror());
   return sock->sockfd_dest;
  }
  if (connect(sock->sockfd_dest, ptr->ai_addr,
             (unsigned int)ptr->ai_addrlen) == -1) {
   close(sock->sockfd_dest);
   Socket_set_errno(-10);
   fprintf(stderr, "[WARN]%s (%s:%d: errno: %s) " "Unable to connect: %s" "\n", get_time(), "src/network/bsd-win-sock-connect.c", 27, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ()))), Socket_strerror());
   sock->sockfd_dest = -1;
   continue;
  }
  break;
 }
 if (sock->sockfd_dest == -1) {
  Socket_set_errno(-6);
  fprintf(stderr, "[WARN]%s (%s:%d: errno: %s) " "Server unavailable: %s" "\n", get_time(), "src/network/bsd-win-sock-connect.c", 36, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ()))), Socket_strerror());
  return -1;
 }
 return 0;
}

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


decompiled_code:
__int64 __fastcall max_subnets(char a1)
{
return (1LL << (a1 - 2)) - 2;
}

canonical_decompiled_code:
__int64 __fastcall func0(char a1)
{
return (1LL << (a1 - 2)) - 2;
}

original_code:
static subnet_size_t max_subnets(int host_bits) {
 return ((1L << (host_bits - 2)) - 2);
}

canonical_original_code:
static unsigned long max_subnets(int host_bits) {
 return ((1L << (host_bits - 2)) - 2);
}


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

time(&timer);
v0 = localtime(&timer);
strftime(buffer, 0x1BuLL, "[%Y:%m:%d %H:%M:%S]", v0);
return buffer;
}

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

time(&timer);
v0 = localtime(&timer);
strftime(buffer, 0x1BuLL, "[%Y:%m:%d %H:%M:%S]", v0);
return buffer;
}

canonical_original_code:
static char *get_time() {
 long timer;
 struct tm *tm_info;
 time(&timer);
 tm_info = localtime(&timer);
 strftime(buffer, 27, "[%Y:%m:%d %H:%M:%S]", tm_info);
 return buffer;
}

variable_types: timer long

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