decompiled_code:
unsigned __int64 __fastcall convertFrame2RGB(__int64 a1)
{
__int64 v1; // r13
unsigned __int64 result; // rax
unsigned __int64 i; // rbp
unsigned __int8 v5; // r15
int v6; // er12
int v7; // eax
unsigned __int8 v8; // [rsp+0h] [rbp-38h]

v1 = *(_QWORD *)buffers;
result = *(_QWORD *)(buffers + 8) - 16LL;
if ( result > 3 )
{
for ( i = 0LL; i < result; ++i )
{
v5 = *(_BYTE *)(v1 + 4 * i + 3);
v8 = *(_BYTE *)(v1 + 4 * i + 1);
v6 = YUV444toRGB(*(_BYTE *)(v1 + 4 * i), v8, v5);
rgb1_1 = v6;
byte_4040ED = BYTE2(v6);
v7 = YUV444toRGB(*(_BYTE *)(v1 + 4 * i + 2), v8, v5);
rgb2_0 = v7;
byte_4040EA = BYTE2(v7);
*(_WORD *)a1 = v6;
*(_BYTE *)(a1 + 2) = BYTE2(v6);
*(_WORD *)(a1 + 3) = v7;
*(_BYTE *)(a1 + 5) = BYTE2(v7);
a1 += 6LL;
result = (*(_QWORD *)(buffers + 8) >> 2) - 4LL;
}
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func15(__int64 a1)
{
__int64 v1; // r13
unsigned __int64 result; // rax
unsigned __int64 i; // rbp
unsigned __int8 v5; // r15
int v6; // er12
int v7; // eax
unsigned __int8 v8; // [rsp+0h] [rbp-38h]

v1 = *(_QWORD *)buffers;
result = *(_QWORD *)(buffers + 8) - 16LL;
if ( result > 3 )
{
for ( i = 0LL; i < result; ++i )
{
v5 = *(_BYTE *)(v1 + 4 * i + 3);
v8 = *(_BYTE *)(v1 + 4 * i + 1);
v6 = func14(*(_BYTE *)(v1 + 4 * i), v8, v5);
rgb1_1 = v6;
byte_4040ED = BYTE2(v6);
v7 = func14(*(_BYTE *)(v1 + 4 * i + 2), v8, v5);
rgb2_0 = v7;
byte_4040EA = BYTE2(v7);
*(_WORD *)a1 = v6;
*(_BYTE *)(a1 + 2) = BYTE2(v6);
*(_WORD *)(a1 + 3) = v7;
*(_BYTE *)(a1 + 5) = BYTE2(v7);
a1 += 6LL;
result = (*(_QWORD *)(buffers + 8) >> 2) - 4LL;
}
}
return result;
}

original_code:
void convertFrame2RGB(u8 * rgb_buf)
{
  int i;
  static struct RGB rgb1;
  static struct RGB rgb2;
  int indexYuv;
  int indexRgb;
  u8 * pixel_p = (u8*)buffers[0].start;
  for(i=0;i<buffers[0].length / 4 - 4;i++){
    indexYuv = i*4;
    indexRgb = i*6;
    rgb1 = YUV444toRGB(pixel_p[indexYuv + 0],
         pixel_p[indexYuv + 1],
         pixel_p[indexYuv + 3]);
    rgb2 = YUV444toRGB(pixel_p[indexYuv + 2],
         pixel_p[indexYuv + 1],
         pixel_p[indexYuv + 3]);
    rgb_buf[indexRgb+0] = rgb1.R;
    rgb_buf[indexRgb+1] = rgb1.G;
    rgb_buf[indexRgb+2] = rgb1.B;
    rgb_buf[indexRgb+3] = rgb2.R;
    rgb_buf[indexRgb+4] = rgb2.G;
    rgb_buf[indexRgb+5] = rgb2.B;
  }
}

canonical_original_code:
void convertFrame2RGB(unsigned char *rgb_buf)
{
  int i;
  static struct RGB rgb1;
  static struct RGB rgb2;
  int indexYuv;
  int indexRgb;
  unsigned char *pixel_p = (u8*)buffers[0].start;
  for(i=0;i<buffers[0].length / 4 - 4;i++){
    indexYuv = i*4;
    indexRgb = i*6;
    rgb1 = YUV444toRGB(pixel_p[indexYuv + 0],
         pixel_p[indexYuv + 1],
         pixel_p[indexYuv + 3]);
    rgb2 = YUV444toRGB(pixel_p[indexYuv + 2],
         pixel_p[indexYuv + 1],
         pixel_p[indexYuv + 3]);
    rgb_buf[indexRgb+0] = rgb1.R;
    rgb_buf[indexRgb+1] = rgb1.G;
    rgb_buf[indexRgb+2] = rgb1.B;
    rgb_buf[indexRgb+3] = rgb2.R;
    rgb_buf[indexRgb+4] = rgb2.G;
    rgb_buf[indexRgb+5] = rgb2.B;
  }
}

variable_types: i int

variable_types: indexYuv int

variable_types: indexRgb int

user_defined_types: struct RGB { unsigned char R; unsigned char G; unsigned char B; }


gethostbyname

decompiled_code:
__int64 __fastcall gethostbyname(const char *a1)
{
unsigned int v1; // ebp
FILE *v2; // rax

if ( !lib_gethostbyname_2 )
lib_gethostbyname_2 = (__int64 (__fastcall *)(_QWORD))_my_loadfun("gethostbyname");
v1 = getpid();
v2 = (FILE *)_my_getlog();
fprintf(v2, "Process %d is resolving (gethostbyname): %s\n", v1, a1);
return lib_gethostbyname_2(a1);
}

canonical_decompiled_code:
__int64 __fastcall func8(const char *a1)
{
unsigned int v1; // ebp
FILE *v2; // rax

if ( !lib_gethostbyname_2 )
lib_gethostbyname_2 = (__int64 (__fastcall *)(_QWORD))func7("gethostbyname");
v1 = getpid();
v2 = (FILE *)func6();
fprintf(v2, "Process %d is resolving (gethostbyname): %s\n", v1, a1);
return lib_gethostbyname_2(a1);
}

original_code:
__attribute__((visibility("default")))
struct hostent *gethostbyname(const char *name)
{
 static struct hostent *(*lib_gethostbyname)
  (const char *name) = ((void *)0);
 if (!lib_gethostbyname) {
  lib_gethostbyname = __my_loadfun("gethostbyname");
 }
 fprintf(__my_getlog(), "Process %d is resolving (gethostbyname): %s\n",
  getpid(), name);
 return lib_gethostbyname(name);
}

canonical_original_code:
struct hostent *gethostbyname(char *name)
{
 static struct hostent *(*lib_gethostbyname)(char *name) = ((void *)0);
 if (!lib_gethostbyname) {
  lib_gethostbyname = __my_loadfun("gethostbyname");
 }
 fprintf(__my_getlog(), "Process %d is resolving (gethostbyname): %s\n",
  getpid(), name);
 return lib_gethostbyname(name);
}

variable_types:
name
char *

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


random

decompiled_code:
__int64 random()
{
return _my_random();
}

canonical_decompiled_code:
__int64 func7()
{
return func6();
}

original_code:
__attribute__((visibility("default")))
long int random(void)
{
 return __my_random();
}

canonical_original_code:
long random()
{
 return __my_random();
}

return_type: long


srandom

decompiled_code:
int __fastcall srandom(unsigned int a1)
{
return fprintf(stderr, "Ignoring random seed: %u\n", a1);
}

canonical_decompiled_code:
int __fastcall func8(unsigned int a1)
{
return fprintf(stderr, "Ignoring random seed: %u\n", a1);
}

original_code:
__attribute__((visibility("default")))
void srandom(unsigned int seed)
{
 fprintf(stderr, "Ignoring random seed: %u\n", seed);
}

variable_types:
seed
unsigned int

return_type: void


decompiled_code:
__int64 SDL_WM_GrabInput()
{
if ( !lib_SDL_WM_GrabInput_0 )
lib_SDL_WM_GrabInput_0 = (__int64 (__fastcall *)(_QWORD))dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "SDL_WM_GrabInput");
return lib_SDL_WM_GrabInput_0(0xFFFFFFFFLL);
}

canonical_decompiled_code:
__int64 func6()
{
if ( !lib_SDL_WM_GrabInput_0 )
lib_SDL_WM_GrabInput_0 = (__int64 (__fastcall *)(_QWORD))dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "SDL_WM_GrabInput");
return lib_SDL_WM_GrabInput_0(0xFFFFFFFFLL);
}

original_code:
__attribute__((visibility("default")))
SDL_GrabMode SDL_WM_GrabInput(SDL_GrabMode mode __attribute__((unused)))
{
        static SDL_GrabMode (*lib_SDL_WM_GrabInput) (SDL_GrabMode mode) = ((void *)0);
        if (!lib_SDL_WM_GrabInput) {
                lib_SDL_WM_GrabInput = dlsym(((void *) -1l), "SDL_WM_GrabInput");
        }
        return lib_SDL_WM_GrabInput(SDL_GRAB_QUERY);
}

canonical_original_code:
enum SDL_GrabMode SDL_WM_GrabInput(enum SDL_GrabMode mode)
{
        static enum SDL_GrabMode (*lib_SDL_WM_GrabInput)(enum SDL_GrabMode mode) = ((void *)0);
        if (!lib_SDL_WM_GrabInput) {
                lib_SDL_WM_GrabInput = dlsym(((void *) -1l), "SDL_WM_GrabInput");
        }
        return lib_SDL_WM_GrabInput(SDL_GRAB_QUERY);
}

variable_types: enum SDL_GrabMode { SDL_GRAB_QUERY=-1, SDL_GRAB_OFF=0, SDL_GRAB_ON=1, SDL_GRAB_FULLSCREEN=2 } (*)(enum SDL_GrabMode { SDL_GRAB_QUERY=-1, SDL_GRAB_OFF=0, SDL_GRAB_ON=1, SDL_GRAB_FULLSCREEN=2 } mode)


decompiled_code:
__int64 SDL_ShowCursor()
{
return 1LL;
}

canonical_decompiled_code:
__int64 func7()
{
return 1LL;
}

original_code:
__attribute__((visibility("default")))
int SDL_ShowCursor(int i __attribute__((unused)))
{
     return 1;
}

canonical_original_code:
int SDL_ShowCursor(int i)
{
     return 1;
}

return_type: int


usage

decompiled_code:
int __fastcall usage(const char *a1)
{
return fprintf(stderr, "usage: %s r|w </dev/node> <nbytes> [skip]\n", a1);
}

canonical_decompiled_code:
int __fastcall func7(const char *a1)
{
return fprintf(stderr, "usage: %s r|w </dev/node> <nbytes> [skip]\n", a1);
}

original_code:
void usage(char *prgname)
{
 fprintf(stderr, "usage: %s r|w </dev/node> <nbytes> [skip]\n", prgname);
}

variable_types:
prgname
char *


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // r13
signed __int64 v4; // rbx
int v5; // ebp
_QWORD *v6; // r12
signed __int64 v7; // r14
int result; // eax
unsigned __int64 v9; // rbp
__int64 v10; // rdx
int fd; // [rsp+Ch] [rbp-3Ch]

if ( argc <= 3 )
goto LABEL_14;
v3 = atol(argv[3]);
if ( v3 <= 0 )
{
puts("How much is the fish?");
return 0;
}
v4 = 0LL;
if ( argc == 5 )
v4 = (unsigned __int64)atol(argv[4]) >> 3;
if ( strcmp(argv[1], "r") )
{
v5 = 2;
if ( !strcmp(argv[1], "w") )
goto LABEL_7;
LABEL_14:
usage(*argv);
return 1;
}
v5 = 1;
LABEL_7:
fd = open(argv[2], 2);
if ( fd < 0 )
{
perror("Can't open() device");
result = 1;
}
else
{
printf("nbytes = %ld\n", v3);
if ( v4 )
printf("skip = %ld\n", v4);
v6 = mmap(0LL, v3, v5, 1, fd, 0LL);
if ( v6 == (_QWORD *)-1LL )
{
perror("Can't mmap device");
result = 1;
}
else
{
v7 = (unsigned __int64)v3 >> 3;
if ( v5 == 2 )
{
puts("Writing...");
if ( v4 < v7 )
{
do
{
v6[v4] = v4;
if ( !(8 * v4 % 0x6400000uLL) )
printf("%ld\n", (unsigned __int64)(8 * v4) >> 20);
++v4;
}
while ( v7 != v4 );
}
putchar(10);
puts("Done");
}
else if ( v4 < v7 )
{
do
{
v9 = 8 * v4;
v10 = v6[v4];
if ( v10 != v4 )
printf("%ld: %ld\n", v4, v10);
if ( v9 == 104857600 * (v9 / 0x6400000) )
printf("%ld\n", v9 >> 20);
++v4;
}
while ( v7 != v4 );
}
puts("Unmapping...");
munmap(v6, v3);
puts("Syncing...");
fsync(fd);
puts("Closing...");
close(fd);
puts("Bye.");
result = 0;
}
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // r13
signed __int64 v4; // rbx
int v5; // ebp
_QWORD *v6; // r12
signed __int64 v7; // r14
int result; // eax
unsigned __int64 v9; // rbp
__int64 v10; // rdx
int fd; // [rsp+Ch] [rbp-3Ch]

if ( argc <= 3 )
goto LABEL_14;
v3 = atol(argv[3]);
if ( v3 <= 0 )
{
puts("How much is the fish?");
return 0;
}
v4 = 0LL;
if ( argc == 5 )
v4 = (unsigned __int64)atol(argv[4]) >> 3;
if ( strcmp(argv[1], "r") )
{
v5 = 2;
if ( !strcmp(argv[1], "w") )
goto LABEL_7;
LABEL_14:
func7(*argv);
return 1;
}
v5 = 1;
LABEL_7:
fd = open(argv[2], 2);
if ( fd < 0 )
{
perror("Can't open() device");
result = 1;
}
else
{
printf("nbytes = %ld\n", v3);
if ( v4 )
printf("skip = %ld\n", v4);
v6 = mmap(0LL, v3, v5, 1, fd, 0LL);
if ( v6 == (_QWORD *)-1LL )
{
perror("Can't mmap device");
result = 1;
}
else
{
v7 = (unsigned __int64)v3 >> 3;
if ( v5 == 2 )
{
puts("Writing...");
if ( v4 < v7 )
{
do
{
v6[v4] = v4;
if ( !(8 * v4 % 0x6400000uLL) )
printf("%ld\n", (unsigned __int64)(8 * v4) >> 20);
++v4;
}
while ( v7 != v4 );
}
putchar(10);
puts("Done");
}
else if ( v4 < v7 )
{
do
{
v9 = 8 * v4;
v10 = v6[v4];
if ( v10 != v4 )
printf("%ld: %ld\n", v4, v10);
if ( v9 == 104857600 * (v9 / 0x6400000) )
printf("%ld\n", v9 >> 20);
++v4;
}
while ( v7 != v4 );
}
puts("Unmapping...");
munmap(v6, v3);
puts("Syncing...");
fsync(fd);
puts("Closing...");
close(fd);
puts("Bye.");
result = 0;
}
}
return result;
}

original_code:
int main(int argc, char **argv)
{
 int prot;
 int fd;
 int ret;
 long nbytes;
 long nelements;
 long skip;
 long i;
 unsigned long *diskp;
 if (argc < 4) {
  usage(argv[0]);
  return 1;
 }
 nbytes = atol(argv[3]);
 if (nbytes <= 0) {
  printf("How much is the fish?\n");
  return 0;
 }
 nelements = nbytes / sizeof(unsigned long);
 if (argc == 5) {
  skip = atol(argv[4]) / sizeof(unsigned long);
 } else {
  skip = 0;
 }
 if (!strcmp(argv[1], "r")) {
  prot = 0x1;
 } else if (!strcmp(argv[1], "w")) {
  prot = 0x2;
 } else {
  usage(argv[0]);
  return 1;
 }
 fd = open(argv[2], 02);
 if (fd < 0) {
  perror("Can't open() device");
  return 1;
 }
 printf("nbytes = %ld\n", nbytes);
 if (skip)
  printf("skip = %ld\n", skip);
 diskp = (unsigned long *) mmap(((void *)0), nbytes, prot, 0x01, fd, 0);
 if (diskp == ((void *) -1)) {
  perror("Can't mmap device");
  return 1;
 }
 if (prot == 0x2) {
  printf("Writing...\n");
  for (i = skip; i < nelements; i++) {
   diskp[i] = i;
   if (!((i * sizeof(unsigned long) % ((1024 * 1024) * 100)))) {
    printf("%ld\n", (i * sizeof (unsigned long) / (1024 * 1024)));
   }
  }
  printf("\n");
  printf("Done\n");
 } else {
  for (i = skip; i < nelements; i++) {
   if (diskp[i] != i) {
    printf("%ld: %ld\n", i, diskp[i]);
   }
   if (!((i * sizeof(unsigned long) % ((1024 * 1024) * 100))))
    printf("%ld\n", (i * sizeof (unsigned long) / (1024 * 1024)));
  }
 }
 printf("Unmapping...\n");
 munmap((void *)diskp, nbytes);
 printf("Syncing...\n");
  fsync(fd);
 printf("Closing...\n");
 close(fd);
 printf("Bye.\n");
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: prot int

variable_types: fd int

variable_types: ret int

variable_types: nbytes long

variable_types: nelements long

variable_types: skip long

variable_types: i long

variable_types:
diskp
unsigned long *


decompiled_code:
_BOOL8 __fastcall match_tap(int a1, int a2)
{
return a1 == a2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(int a1, int a2)
{
return a1 == a2;
}

original_code:
static int match_tap(int port_fd, int data_fd, void *port_data,
       int port_data_len, void *data)
{
  return(port_fd == data_fd);
}

variable_types:
data
void *


decompiled_code:
void __fastcall free_port(_QWORD *a1)
{
_QWORD *v1; // rax

v1 = (_QWORD *)a1[1];
if ( v1 )
*v1 = *a1;
else
head = *a1;
if ( *a1 )
*(_QWORD *)(*a1 + 8LL) = a1[1];
free(a1);
}

canonical_decompiled_code:
void __fastcall func1(_QWORD *a1)
{
_QWORD *v1; // rax

v1 = (_QWORD *)a1[1];
if ( v1 )
*v1 = *a1;
else
head = *a1;
if ( *a1 )
*(_QWORD *)(*a1 + 8LL) = a1[1];
free(a1);
}

original_code:
static void free_port(struct port *port)
{
  if(port->prev) port->prev->next = port->next;
  else head = port->next;
  if(port->next) port->next->prev = port->prev;
  free(port);
}

variable_types: struct port { struct port *next; struct port *prev; int control; void *data; int data_len; unsigned char src[6]; void (*sender)(int fd, void *packet, int len, void *data); } *


decompiled_code:
int __fastcall send_dst(__int64 a1, _BYTE *a2, unsigned int a3, int a4)
{
__int64 v6; // rax
__int64 i; // rbx

v6 = find_in_hash(a2);
if ( v6 )
{
if ( !(a4 | *a2 & 1) )
{
LODWORD(v6) = (*(__int64 (__fastcall **)(_QWORD, _BYTE *, _QWORD, _QWORD))(v6 + 48))(
*(unsigned int *)(v6 + 16),
a2,
a3,
*(_QWORD *)(v6 + 24));
return v6;
}
}
else if ( (*a2 & 1) == 0 )
{
printf(
"unknown Addr: %02x:%02x:%02x:%02x:%02x:%02x from port ",
(unsigned __int8)a2[6],
(unsigned __int8)a2[7],
(unsigned __int8)a2[8],
(unsigned __int8)a2[9],
(unsigned __int8)a2[10],
(unsigned __int8)a2[11]);
if ( a1 )
LODWORD(v6) = printf("%d\n", *(unsigned int *)(a1 + 16));
else
LODWORD(v6) = puts("UNKNOWN");
}
for ( i = head; i; i = *(_QWORD *)i )
{
if ( a1 != i )
LODWORD(v6) = (*(__int64 (__fastcall **)(_QWORD, _BYTE *, _QWORD, _QWORD))(i + 48))(
*(unsigned int *)(i + 16),
a2,
a3,
*(_QWORD *)(i + 24));
}
return v6;
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1, _BYTE *a2, unsigned int a3, int a4)
{
__int64 v6; // rax
__int64 i; // rbx

v6 = find_in_hash(a2);
if ( v6 )
{
if ( !(a4 | *a2 & 1) )
{
LODWORD(v6) = (*(__int64 (__fastcall **)(_QWORD, _BYTE *, _QWORD, _QWORD))(v6 + 48))(
*(unsigned int *)(v6 + 16),
a2,
a3,
*(_QWORD *)(v6 + 24));
return v6;
}
}
else if ( (*a2 & 1) == 0 )
{
printf(
"unknown Addr: %02x:%02x:%02x:%02x:%02x:%02x from port ",
(unsigned __int8)a2[6],
(unsigned __int8)a2[7],
(unsigned __int8)a2[8],
(unsigned __int8)a2[9],
(unsigned __int8)a2[10],
(unsigned __int8)a2[11]);
if ( a1 )
LODWORD(v6) = printf("%d\n", *(unsigned int *)(a1 + 16));
else
LODWORD(v6) = puts("UNKNOWN");
}
for ( i = head; i; i = *(_QWORD *)i )
{
if ( a1 != i )
LODWORD(v6) = (*(__int64 (__fastcall **)(_QWORD, _BYTE *, _QWORD, _QWORD))(i + 48))(
*(unsigned int *)(i + 16),
a2,
a3,
*(_QWORD *)(i + 24));
}
return v6;
}

original_code:
static void send_dst(struct port *port, struct packet *packet, int len,
       int hub)
{
  struct port *target, *p;
  target = find_in_hash(packet->header.dest);
  if((target == ((void *)0)) || ((packet->header.dest[0] & 1) == 1) || hub){
    if((target == ((void *)0)) && !((packet->header.dest[0] & 1) == 1)){
      printf("unknown Addr: %02x:%02x:%02x:%02x:%02x:%02x from port ",
      packet->header.src[0], packet->header.src[1],
      packet->header.src[2], packet->header.src[3],
      packet->header.src[4], packet->header.src[5]);
      if(port == ((void *)0)) printf("UNKNOWN\n");
      else printf("%d\n", port->control);
    }
    for(p = head; p != ((void *)0); p = p->next){
      if(p == port) continue;
      (*p->sender)(p->control, packet, len, p->data);
    }
  }
  else (*target->sender)(target->control, packet, len, target->data);
}

canonical_original_code:
static void send_dst(struct port *port, struct packet *packet, int len, int hub)
{
  struct port *target; struct port *p;
  target = find_in_hash(packet->header.dest);
  if((target == ((void *)0)) || ((packet->header.dest[0] & 1) == 1) || hub){
    if((target == ((void *)0)) && !((packet->header.dest[0] & 1) == 1)){
      printf("unknown Addr: %02x:%02x:%02x:%02x:%02x:%02x from port ",
      packet->header.src[0], packet->header.src[1],
      packet->header.src[2], packet->header.src[3],
      packet->header.src[4], packet->header.src[5]);
      if(port == ((void *)0)) printf("UNKNOWN\n");
      else printf("%d\n", port->control);
    }
    for(p = head; p != ((void *)0); p = p->next){
      if(p == port) continue;
      (*p->sender)(p->control, packet, len, p->data);
    }
  }
  else (*target->sender)(target->control, packet, len, target->data);
}

variable_types: struct packet { struct { unsigned char dest[6]; unsigned char src[6]; unsigned char proto[2]; } header; unsigned char data[1500]; } *

variable_types: len int

variable_types: hub int

user_defined_types: struct port { struct port *next; struct port *prev; int control; void *data; int data_len; unsigned char src[6]; void (*sender)(int fd, void *packet, int len, void *data); }


original_code:
static void update_src(struct port *port, struct packet *p)
{
  struct port *last;
  if(((p->header.src[0] & 1) == 1)) return;
  last = find_in_hash(p->header.src);
  if(port != last){
    printf(" Addr: %02x:%02x:%02x:%02x:%02x:%02x New port %d",
    p->header.src[0], p->header.src[1], p->header.src[2],
    p->header.src[3], p->header.src[4], p->header.src[5],
    port->control);
    if(last != ((void *)0)){
      printf(" old port %d", last->control);
      delete_hash(p->header.src);
    }
    printf("\n");
    memcpy(port->src, p->header.src, sizeof(port->src));
    insert_into_hash(p->header.src, port);
  }
  update_entry_time(p->header.src);
}

user_defined_types: struct packet { struct { unsigned char dest[6]; unsigned char src[6]; unsigned char proto[2]; } header; unsigned char data[1500]; }


decompiled_code:
int __fastcall handle_data(unsigned int a1, int a2, unsigned __int8 *a3, unsigned int a4, __int64 a5, unsigned int (__fastcall *a6)(_QWORD, _QWORD, _QWORD, _QWORD, __int64))
{
__int64 v10; // rbx

v10 = head;
if ( head )
{
while ( !a6(*(unsigned int *)(v10 + 16), a1, *(_QWORD *)(v10 + 24), *(unsigned int *)(v10 + 32), a5) )
{
v10 = *(_QWORD *)v10;
if ( !v10 )
goto LABEL_4;
}
update_src(v10, a3);
}
else
{
LABEL_4:
puts("Unknown connection for packet, shouldn't happen.");
v10 = 0LL;
}
return send_dst(v10, a3, a4, a2);
}

canonical_decompiled_code:
int __fastcall func5(unsigned int a1, int a2, unsigned __int8 *a3, unsigned int a4, __int64 a5, unsigned int (__fastcall *a6)(_QWORD, _QWORD, _QWORD, _QWORD, __int64))
{
__int64 v10; // rbx

v10 = head;
if ( head )
{
while ( !a6(*(unsigned int *)(v10 + 16), a1, *(_QWORD *)(v10 + 24), *(unsigned int *)(v10 + 32), a5) )
{
v10 = *(_QWORD *)v10;
if ( !v10 )
goto LABEL_4;
}
func4(v10, a3);
}
else
{
LABEL_4:
puts("Unknown connection for packet, shouldn't happen.");
v10 = 0LL;
}
return func3(v10, a3, a4, a2);
}

original_code:
static void handle_data(int fd, int hub, struct packet *packet, int len,
   void *data, int (*matcher)(int port_fd, int data_fd,
         void *port_data,
         int port_data_len,
         void *data))
{
  struct port *p;
  for(p = head; p != ((void *)0); p = p->next){
    if((*matcher)(p->control, fd, p->data, p->data_len, data)) break;
  }
  if(p != ((void *)0)) update_src(p, packet);
  else printf("Unknown connection for packet, shouldn't happen.\n");
  send_dst(p, packet, len, hub);
}

variable_types: int (*)(int port_fd, int data_fd, void *port_data, int port_data_len, void *data)


decompiled_code:
_BOOL8 __fastcall match_sock(__int64 a1, __int64 a2, __int64 a3, int a4, __int64 a5)
{
_BOOL8 result; // rax

result = 0LL;
if ( a4 == 116 )
result = memcmp((const void *)(a3 + 4), (const void *)(a5 + 4), 0x6EuLL) == 0;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func6(__int64 a1, __int64 a2, __int64 a3, int a4, __int64 a5)
{
_BOOL8 result; // rax

result = 0LL;
if ( a4 == 116 )
result = memcmp((const void *)(a3 + 4), (const void *)(a5 + 4), 0x6EuLL) == 0;
return result;
}

original_code:
static int match_sock(int port_fd, int data_fd, void *port_data,
        int port_data_len, void *data)
{
  struct sock_data *mine = data;
  struct sock_data *port = port_data;
  if(port_data_len != sizeof(*mine)) return(0);
  return(!memcmp(&port->sock, &mine->sock, sizeof(mine->sock)));
}

variable_types: struct sock_data { int fd; struct sockaddr_un { unsigned short sun_family; char sun_path[108]; } sock; } *

user_defined_types: struct sock_data { int fd; struct sockaddr_un sock; }


decompiled_code:
void __fastcall send_sock(__int64 a1, const void *a2, int a3, unsigned int *a4)
{
if ( a3 != (unsigned int)sendto(*a4, a2, a3, 0, (const struct sockaddr *)(a4 + 1), 0x6Eu) )
{
fprintf(stderr, "send_sock sending to fd %d ", *a4);
perror(&byte_604);
}
}

canonical_decompiled_code:
void __fastcall func7(__int64 a1, const void *a2, int a3, unsigned int *a4)
{
if ( a3 != (unsigned int)sendto(*a4, a2, a3, 0, (const struct sockaddr *)(a4 + 1), 0x6Eu) )
{
fprintf(stderr, "send_sock sending to fd %d ", *a4);
perror(&byte_604);
}
}

original_code:
static void send_sock(int fd, void *packet, int len, void *data)
{
  struct sock_data *mine = data;
  int err;
  err = sendto(mine->fd, packet, len, 0, (struct sockaddr *) &mine->sock,
        sizeof(mine->sock));
  if(err != len){
    fprintf(stderr, "send_sock sending to fd %d ", mine->fd);
    perror("");
  }
}

variable_types:
packet
void *

variable_types: err int

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

user_defined_types: struct sockaddr_un { unsigned short sun_family; char sun_path[108]; }


decompiled_code:
void __fastcall close_port(unsigned int a1)
{
__int64 v1; // rbx

v1 = head;
if ( head )
{
while ( *(_DWORD *)(v1 + 16) != a1 )
{
v1 = *(_QWORD *)v1;
if ( !v1 )
goto LABEL_4;
}
delete_hash(v1 + 36);
free_port((_QWORD *)v1);
}
else
{
LABEL_4:
fprintf(stderr, "No port associated with descriptor %d\n", a1);
}
}

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

v1 = head;
if ( head )
{
while ( *(_DWORD *)(v1 + 16) != a1 )
{
v1 = *(_QWORD *)v1;
if ( !v1 )
goto LABEL_4;
}
delete_hash(v1 + 36);
func1((_QWORD *)v1);
}
else
{
LABEL_4:
fprintf(stderr, "No port associated with descriptor %d\n", a1);
}
}

original_code:
void close_port(int fd)
{
  struct port *port;
  for(port = head; port != ((void *)0); port = port->next){
    if(port->control == fd) break;
  }
  if(port == ((void *)0)){
    fprintf(stderr, "No port associated with descriptor %d\n", fd);
    return;
  }
  delete_hash(port->src);
  free_port(port);
}


decompiled_code:
void __fastcall handle_tap_data(unsigned int a1, int a2)
{
signed int v2; // eax
unsigned __int8 v3[1544]; // [rsp+0h] [rbp-608h] BYREF

v2 = read(a1, v3, 0x5EAuLL);
if ( v2 < 0 )
{
if ( *_errno_location() != 11 )
perror("Reading tap data");
}
else
{
handle_data(a1, a2, v3, v2, 0LL, (unsigned int (__fastcall *)(_QWORD, _QWORD, _QWORD, _QWORD, __int64))match_tap);
}
}

canonical_decompiled_code:
void __fastcall func9(unsigned int a1, int a2)
{
signed int v2; // eax
unsigned __int8 v3[1544]; // [rsp+0h] [rbp-608h] BYREF

v2 = read(a1, v3, 0x5EAuLL);
if ( v2 < 0 )
{
if ( *_errno_location() != 11 )
perror("Reading tap data");
}
else
{
func5(a1, a2, v3, v2, 0LL, (unsigned int (__fastcall *)(_QWORD, _QWORD, _QWORD, _QWORD, __int64))match_tap);
}
}

original_code:
void handle_tap_data(int fd, int hub)
{
  struct packet packet;
  int len;
  len = read(fd, &packet, sizeof(packet));
  if(len < 0){
    if((*__errno_location ()) != 11) perror("Reading tap data");
    return;
  }
  handle_data(fd, hub, &packet, len, ((void *)0), match_tap);
}

variable_types: struct packet { struct { unsigned char dest[6]; unsigned char src[6]; unsigned char proto[2]; } header; unsigned char data[1500]; }


decompiled_code:
__int64 __fastcall setup_port(int a1, __int64 a2, __int64 a3, int a4)
{
_QWORD *v6; // rax
__int64 v7; // rdx
__int64 result; // rax

v6 = malloc(0x38uLL);
if ( v6 )
{
v7 = head;
*v6 = head;
if ( v7 )
*(_QWORD *)(v7 + 8) = v6;
v6[1] = 0LL;
*((_DWORD *)v6 + 4) = a1;
v6[3] = a3;
*((_DWORD *)v6 + 8) = a4;
v6[6] = a2;
head = (__int64)v6;
puts("New connection");
result = 0LL;
}
else
{
perror("malloc");
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(int a1, __int64 a2, __int64 a3, int a4)
{
_QWORD *v6; // rax
__int64 v7; // rdx
__int64 result; // rax

v6 = malloc(0x38uLL);
if ( v6 )
{
v7 = head;
*v6 = head;
if ( v7 )
*(_QWORD *)(v7 + 8) = v6;
v6[1] = 0LL;
*((_DWORD *)v6 + 4) = a1;
v6[3] = a3;
*((_DWORD *)v6 + 8) = a4;
v6[6] = a2;
head = (__int64)v6;
puts("New connection");
result = 0LL;
}
else
{
perror("malloc");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int setup_port(int fd, void (*sender)(int fd, void *packet, int len,
          void *data), void *data, int data_len)
{
  struct port *port;
  port = malloc(sizeof(struct port));
  if(port == ((void *)0)){
    perror("malloc");
    return(-1);
  }
  port->next = head;
  if(head) head->prev = port;
  port->prev = ((void *)0);
  port->control = fd;
  port->data = data;
  port->data_len = data_len;
  port->sender = sender;
  head = port;
  printf("New connection\n");
  return(0);
}

variable_types: fd int

variable_types: void (*)(int fd, void *packet, int len, void *data)


decompiled_code:
void __fastcall handle_sock_data(int a1, int a2)
{
signed int v2; // eax
socklen_t addr_len; // [rsp+Ch] [rbp-68Ch] BYREF
int v4; // [rsp+10h] [rbp-688h] BYREF
struct sockaddr addr; // [rsp+14h] [rbp-684h] BYREF
unsigned __int8 buf[1544]; // [rsp+90h] [rbp-608h] BYREF

addr_len = 110;
v2 = recvfrom(a1, buf, 0x5EAuLL, 0, &addr, &addr_len);
if ( v2 < 0 )
{
if ( *_errno_location() != 11 )
perror("handle_sock_data");
}
else
{
v4 = a1;
handle_data(
a1,
a2,
buf,
v2,
(__int64)&v4,
(unsigned int (__fastcall *)(_QWORD, _QWORD, _QWORD, _QWORD, __int64))match_sock);
}
}

canonical_decompiled_code:
void __fastcall func11(int a1, int a2)
{
signed int v2; // eax
socklen_t addr_len; // [rsp+Ch] [rbp-68Ch] BYREF
int v4; // [rsp+10h] [rbp-688h] BYREF
struct sockaddr addr; // [rsp+14h] [rbp-684h] BYREF
unsigned __int8 buf[1544]; // [rsp+90h] [rbp-608h] BYREF

addr_len = 110;
v2 = recvfrom(a1, buf, 0x5EAuLL, 0, &addr, &addr_len);
if ( v2 < 0 )
{
if ( *_errno_location() != 11 )
perror("handle_sock_data");
}
else
{
v4 = a1;
func5(
a1,
a2,
buf,
v2,
(__int64)&v4,
(unsigned int (__fastcall *)(_QWORD, _QWORD, _QWORD, _QWORD, __int64))match_sock);
}
}

original_code:
void handle_sock_data(int fd, int hub)
{
  struct packet packet;
  struct sock_data data;
  int len;
  unsigned int socklen = sizeof(data.sock);
  len = recvfrom(fd, &packet, sizeof(packet), 0,
   (struct sockaddr *) &data.sock, &socklen);
  if(len < 0){
    if((*__errno_location ()) != 11) perror("handle_sock_data");
    return;
  }
  data.fd = fd;
  handle_data(fd, hub, &packet, len, &data, match_sock);
}

variable_types: struct sock_data { int fd; struct sockaddr_un { unsigned short sun_family; char sun_path[108]; } sock; }

variable_types:
socklen
unsigned int


original_code:
int setup_sock_port(int fd, struct sockaddr_un *name, int data_fd)
{
  struct sock_data *data;
  data = malloc(sizeof(*data));
  if(data == ((void *)0)){
    perror("setup_sock_port");
    return(-1);
  }
  *data = ((struct sock_data) { fd : data_fd,
    sock : *name });
  return(setup_port(fd, send_sock, data, sizeof(*data)));
}

variable_types: struct sockaddr_un { unsigned short sun_family; char sun_path[108]; } *


decompiled_code:
__int64 __fastcall handle_port(int a1)
{
__int64 v2; // rdi

v2 = head;
if ( !head )
return 1LL;
while ( *(_DWORD *)(v2 + 16) != a1 )
{
v2 = *(_QWORD *)v2;
if ( !v2 )
return 1LL;
}
service_port(v2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func13(int a1)
{
__int64 v2; // rdi

v2 = head;
if ( !head )
return 1LL;
while ( *(_DWORD *)(v2 + 16) != a1 )
{
v2 = *(_QWORD *)v2;
if ( !v2 )
return 1LL;
}
func2(v2);
return 0LL;
}

original_code:
int handle_port(int fd)
{
  struct port *p;
  for(p = head; p != ((void *)0); p = p->next){
    if(p->control == fd){
      service_port(p);
      return(0);
    }
  }
  return(1);
}


decompiled_code:
int __fastcall slip_name(int a1, __int64 a2, __int64 a3)
{
int result; // eax

result = ioctl(a1, 0x8910uLL, a2);
if ( result < 0 )
{
output_errno(a3, "Getting slip line discipline");
write_output(1LL, a3);
exit(1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(int a1, __int64 a2, __int64 a3)
{
int result; // eax

result = ioctl(a1, 0x8910uLL, a2);
if ( result < 0 )
{
output_errno(a3, "Getting slip line discipline");
write_output(1LL, a3);
exit(1);
}
return result;
}

original_code:
static void slip_name(int fd, char *name, struct output *output)
{
  if(ioctl(fd, 0x8910, name) < 0){
    output_errno(output, "Getting slip line discipline");
    write_output(1, output);
    exit(1);
  }
}

variable_types:
name
char *

variable_types: struct output { int total; int used; char *buffer; } *


decompiled_code:
__int64 __fastcall slip_v0_v2(__int64 a1, __int64 a2)
{
const char *v2; // rbp
int v3; // eax
__int64 v4; // r8
__int64 result; // rax
int v6; // eax
char v7[33]; // [rsp+7h] [rbp-21h] BYREF

v2 = *(const char **)a2;
if ( setreuid(0, 0) < 0 )
{
perror("slip - setreuid failed");
exit(1);
}
if ( !strcmp(v2, "up") )
{
v6 = atoi(*(const char **)(a2 + 8));
result = slip_up(v6, *(_QWORD *)(a2 + 16), *(_QWORD *)(a2 + 24), 0LL, 0LL);
}
else
{
if ( strcmp(v2, "down") )
{
printf("slip - Unknown op '%s'\n", v2);
exit(1);
}
v3 = atoi(*(const char **)(a2 + 8));
slip_name(v3, (__int64)v7, 0LL);
result = slip_down((__int64)v7, *(_QWORD *)(a2 + 16), 0LL, 0LL, v4);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
const char *v2; // rbp
int v3; // eax
__int64 v4; // r8
__int64 result; // rax
int v6; // eax
char v7[33]; // [rsp+7h] [rbp-21h] BYREF

v2 = *(const char **)a2;
if ( setreuid(0, 0) < 0 )
{
perror("slip - setreuid failed");
exit(1);
}
if ( !strcmp(v2, "up") )
{
v6 = atoi(*(const char **)(a2 + 8));
result = func1(v6, *(_QWORD *)(a2 + 16), *(_QWORD *)(a2 + 24), 0LL, 0LL);
}
else
{
if ( strcmp(v2, "down") )
{
printf("slip - Unknown op '%s'\n", v2);
exit(1);
}
v3 = atoi(*(const char **)(a2 + 8));
func0(v3, (__int64)v7, 0LL);
result = func2((__int64)v7, *(_QWORD *)(a2 + 16), 0LL, 0LL, v4);
}
return result;
}

original_code:
void slip_v0_v2(int argc, char **argv)
{
  char *op = argv[0], dev[sizeof("slnnnnn\0")];
  if(setreuid(0, 0) < 0){
    perror("slip - setreuid failed");
    exit(1);
  }
  if(!strcmp(op, "up"))
    slip_up(atoi(argv[1]), argv[2], argv[3], ((void *)0), ((void *)0));
  else if(!strcmp(op, "down")){
    slip_name(atoi(argv[1]), dev, ((void *)0));
    slip_down(dev, argv[2], ((void *)0), ((void *)0));
  }
  else {
    printf("slip - Unknown op '%s'\n", op);
    exit(1);
  }
}

canonical_original_code:
void slip_v0_v2(int argc, char **argv)
{
  char *op = argv[0]; char dev[-1];
  if(setreuid(0, 0) < 0){
    perror("slip - setreuid failed");
    exit(1);
  }
  if(!strcmp(op, "up"))
    slip_up(atoi(argv[1]), argv[2], argv[3], ((void *)0), ((void *)0));
  else if(!strcmp(op, "down")){
    slip_name(atoi(argv[1]), dev, ((void *)0));
    slip_down(dev, argv[2], ((void *)0), ((void *)0));
  }
  else {
    printf("slip - Unknown op '%s'\n", op);
    exit(1);
  }
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
op
char *

variable_types:
dev
char [-1]


decompiled_code:
__int64 __fastcall slip_v3(__int64 a1, __int64 a2)
{
const char *v2; // rbp
int v3; // eax
__int64 v4; // r8
int v6; // eax
char v7[9]; // [rsp+7h] [rbp-31h] BYREF
int v8[2]; // [rsp+10h] [rbp-28h] BYREF
__int64 v9; // [rsp+18h] [rbp-20h]

v8[0] = 0;
v8[1] = 0;
v9 = 0LL;
v2 = *(const char **)a2;
if ( setreuid(0, 0) < 0 )
{
output_errno(v8, "slip - setreuid failed");
exit(1);
}
if ( !strcmp(v2, "up") )
{
v6 = atoi(*(const char **)(a2 + 8));
slip_up(v6, *(_QWORD *)(a2 + 16), *(_QWORD *)(a2 + 24), 0LL, (__int64)v8);
}
else
{
if ( strcmp(v2, "down") )
{
printf("slip - Unknown op '%s'\n", v2);
exit(1);
}
v3 = atoi(*(const char **)(a2 + 8));
slip_name(v3, (__int64)v7, (__int64)v8);
slip_down((__int64)v7, *(_QWORD *)(a2 + 16), 0LL, (__int64)v8, v4);
}
return write_output(1LL, v8);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2)
{
const char *v2; // rbp
int v3; // eax
__int64 v4; // r8
int v6; // eax
char v7[9]; // [rsp+7h] [rbp-31h] BYREF
int v8[2]; // [rsp+10h] [rbp-28h] BYREF
__int64 v9; // [rsp+18h] [rbp-20h]

v8[0] = 0;
v8[1] = 0;
v9 = 0LL;
v2 = *(const char **)a2;
if ( setreuid(0, 0) < 0 )
{
output_errno(v8, "slip - setreuid failed");
exit(1);
}
if ( !strcmp(v2, "up") )
{
v6 = atoi(*(const char **)(a2 + 8));
func1(v6, *(_QWORD *)(a2 + 16), *(_QWORD *)(a2 + 24), 0LL, (__int64)v8);
}
else
{
if ( strcmp(v2, "down") )
{
printf("slip - Unknown op '%s'\n", v2);
exit(1);
}
v3 = atoi(*(const char **)(a2 + 8));
func0(v3, (__int64)v7, (__int64)v8);
func2((__int64)v7, *(_QWORD *)(a2 + 16), 0LL, (__int64)v8, v4);
}
return write_output(1LL, v8);
}

original_code:
void slip_v3(int argc, char **argv)
{
  struct output output = { 0, 0, ((void *)0) };
  char *op = argv[0], dev[sizeof("slnnnnn\0")];
  if(setreuid(0, 0) < 0){
    output_errno(&output, "slip - setreuid failed");
    exit(1);
  }
  if(!strcmp(op, "up"))
    slip_up(atoi(argv[1]), argv[2], argv[3], ((void *)0), &output);
  else if(!strcmp(op, "down")){
    slip_name(atoi(argv[1]), dev, &output);
    slip_down(dev, argv[2], ((void *)0), &output);
  }
  else {
    printf("slip - Unknown op '%s'\n", op);
    exit(1);
  }
  write_output(1, &output);
}

canonical_original_code:
void slip_v3(int argc, char **argv)
{
  struct output output = { 0, 0, ((void *)0) };
  char *op = argv[0]; char dev[-1];
  if(setreuid(0, 0) < 0){
    output_errno(&output, "slip - setreuid failed");
    exit(1);
  }
  if(!strcmp(op, "up"))
    slip_up(atoi(argv[1]), argv[2], argv[3], ((void *)0), &output);
  else if(!strcmp(op, "down")){
    slip_name(atoi(argv[1]), dev, &output);
    slip_down(dev, argv[2], ((void *)0), &output);
  }
  else {
    printf("slip - Unknown op '%s'\n", op);
    exit(1);
  }
  write_output(1, &output);
}

variable_types: struct output { int total; int used; char *buffer; }


decompiled_code:
__int64 __fastcall slip_v4(int a1, const char **a2)
{
__int64 v2; // r8
char v4[9]; // [rsp+7h] [rbp-31h] BYREF
int v5[2]; // [rsp+10h] [rbp-28h] BYREF
__int64 v6; // [rsp+18h] [rbp-20h]

v5[0] = 0;
v5[1] = 0;
v6 = 0LL;
if ( setreuid(0, 0) < 0 )
{
output_errno(v5, "slip - setreuid failed");
exit(1);
}
if ( a1 <= 0 )
{
add_output(v5, "uml_net : too few arguments to slip_v4\n", 0xFFFFFFFFLL);
write_output(1LL, v5);
exit(1);
}
if ( a1 <= 1 )
{
add_output(v5, "uml_net : too few arguments to slip_v4\n", 0xFFFFFFFFLL);
write_output(1LL, v5);
exit(1);
}
if ( !strcmp(*a2, "up") )
{
slip_up(0, (__int64)a2[1], 0LL, 0LL, (__int64)v5);
}
else
{
if ( strcmp(*a2, "down") )
{
printf("slip - Unknown op '%s'\n", *a2);
exit(1);
}
slip_name(0, (__int64)v4, (__int64)v5);
slip_down((__int64)v4, 0LL, 0LL, (__int64)v5, v2);
}
return write_output(1LL, v5);
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1, const char **a2)
{
__int64 v2; // r8
char v4[9]; // [rsp+7h] [rbp-31h] BYREF
int v5[2]; // [rsp+10h] [rbp-28h] BYREF
__int64 v6; // [rsp+18h] [rbp-20h]

v5[0] = 0;
v5[1] = 0;
v6 = 0LL;
if ( setreuid(0, 0) < 0 )
{
output_errno(v5, "slip - setreuid failed");
exit(1);
}
if ( a1 <= 0 )
{
add_output(v5, "uml_net : too few arguments to slip_v4\n", 0xFFFFFFFFLL);
write_output(1LL, v5);
exit(1);
}
if ( a1 <= 1 )
{
add_output(v5, "uml_net : too few arguments to slip_v4\n", 0xFFFFFFFFLL);
write_output(1LL, v5);
exit(1);
}
if ( !strcmp(*a2, "up") )
{
func1(0, (__int64)a2[1], 0LL, 0LL, (__int64)v5);
}
else
{
if ( strcmp(*a2, "down") )
{
printf("slip - Unknown op '%s'\n", *a2);
exit(1);
}
func0(0, (__int64)v4, (__int64)v5);
func2((__int64)v4, 0LL, 0LL, (__int64)v5, v2);
}
return write_output(1LL, v5);
}

original_code:
void slip_v4(int argc, char **argv)
{
  struct output output = { 0, 0, ((void *)0) };
  char *op, dev[sizeof("slnnnnn\0")];
  if(setreuid(0, 0) < 0){
    output_errno(&output, "slip - setreuid failed");
    exit(1);
  }
  if(argc < 1){
    add_output(&output, "uml_net : too few arguments to slip_v4\n", -1);
    write_output(1, &output);
    exit(1);
  }
  op = argv[0];
  if(argc < 2){
      add_output(&output, "uml_net : too few arguments to slip_v4\n", -1);
      write_output(1, &output);
      exit(1);
  }
  if(!strcmp(op, "up")){
    slip_up(0, argv[1], ((void *)0), ((void *)0), &output);
  }
  else if(!strcmp(op, "down")){
    slip_name(0, dev, &output);
    slip_down(dev, ((void *)0), ((void *)0), &output);
  }
  else {
    printf("slip - Unknown op '%s'\n", op);
    exit(1);
  }
  write_output(1, &output);
}

canonical_original_code:
void slip_v4(int argc, char **argv)
{
  struct output output = { 0, 0, ((void *)0) };
  char *op; char dev[-1];
  if(setreuid(0, 0) < 0){
    output_errno(&output, "slip - setreuid failed");
    exit(1);
  }
  if(argc < 1){
    add_output(&output, "uml_net : too few arguments to slip_v4\n", -1);
    write_output(1, &output);
    exit(1);
  }
  op = argv[0];
  if(argc < 2){
      add_output(&output, "uml_net : too few arguments to slip_v4\n", -1);
      write_output(1, &output);
      exit(1);
  }
  if(!strcmp(op, "up")){
    slip_up(0, argv[1], ((void *)0), ((void *)0), &output);
  }
  else if(!strcmp(op, "down")){
    slip_name(0, dev, &output);
    slip_down(dev, ((void *)0), ((void *)0), &output);
  }
  else {
    printf("slip - Unknown op '%s'\n", op);
    exit(1);
  }
  write_output(1, &output);
}

user_defined_types: struct output { int total; int used; char *buffer; }


decompiled_code:
__int64 __fastcall do_exec(char **argv, unsigned int a2, __int64 a3)
{
__int64 v3; // rbx
char **v4; // rbp
__pid_t v5; // eax
__pid_t v6; // ebp
__pid_t v7; // eax
__int64 result; // rax
int v9; // edx
ssize_t v10; // rax
char v11[260]; // [rsp+0h] [rbp-138h] BYREF
int pipedes[2]; // [rsp+104h] [rbp-34h] BYREF
int stat_loc; // [rsp+10Ch] [rbp-2Ch] BYREF

if ( a3 )
{
v3 = a3;
add_output(a3, &unk_AD3, 0xFFFFFFFFLL);
if ( *argv )
{
v4 = argv;
do
{
add_output(v3, &unk_AD5, 0xFFFFFFFFLL);
add_output(v3, *v4++, 0xFFFFFFFFLL);
}
while ( *v4 );
}
add_output(v3, &unk_AD7, 0xFFFFFFFFLL);
if ( pipe(pipedes) >= 0 )
{
v5 = fork();
v6 = v5;
if ( v5 )
{
if ( v5 >= 0 )
{
close(pipedes[1]);
while ( 1 )
{
v10 = read(pipedes[0], v11, 0x100uLL);
if ( (int)v10 <= 0 )
break;
add_output(v3, v11, v10);
}
if ( (int)v10 < 0 )
output_errno(v3, "Reading command output");
goto LABEL_12;
}
LABEL_21:
output_errno(v3, "fork failed");
return 0xFFFFFFFFLL;
}
close(pipedes[0]);
if ( dup2(pipedes[1], 1) < 0 || dup2(pipedes[1], 2) < 0 )
perror("dup2");
LABEL_19:
execvp(*argv, argv);
fprintf(stderr, "Failed to exec '%s'", *argv);
perror(&byte_B00);
exit(1);
}
perror("Creating pipe");
}
v7 = fork();
v6 = v7;
if ( !v7 )
goto LABEL_19;
v3 = 0LL;
if ( v7 < 0 )
{
v3 = 0LL;
goto LABEL_21;
}
LABEL_12:
if ( waitpid(v6, &stat_loc, 0) < 0 )
{
output_errno(v3, "waitpid");
result = 0xFFFFFFFFLL;
}
else
{
result = a2;
if ( a2 )
{
v9 = stat_loc & 0x7F;
result = v9 | (unsigned int)BYTE1(stat_loc);
if ( v9 | BYTE1(stat_loc) )
{
sprintf(v11, "'%s' didn't exit with status 0\n", *argv);
add_output(v3, v11, 0xFFFFFFFFLL);
result = 0xFFFFFFFFLL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char **argv, unsigned int a2, __int64 a3)
{
__int64 v3; // rbx
char **v4; // rbp
__pid_t v5; // eax
__pid_t v6; // ebp
__pid_t v7; // eax
__int64 result; // rax
int v9; // edx
ssize_t v10; // rax
char v11[260]; // [rsp+0h] [rbp-138h] BYREF
int pipedes[2]; // [rsp+104h] [rbp-34h] BYREF
int stat_loc; // [rsp+10Ch] [rbp-2Ch] BYREF

if ( a3 )
{
v3 = a3;
add_output(a3, &unk_AD3, 0xFFFFFFFFLL);
if ( *argv )
{
v4 = argv;
do
{
add_output(v3, &unk_AD5, 0xFFFFFFFFLL);
add_output(v3, *v4++, 0xFFFFFFFFLL);
}
while ( *v4 );
}
add_output(v3, &unk_AD7, 0xFFFFFFFFLL);
if ( pipe(pipedes) >= 0 )
{
v5 = fork();
v6 = v5;
if ( v5 )
{
if ( v5 >= 0 )
{
close(pipedes[1]);
while ( 1 )
{
v10 = read(pipedes[0], v11, 0x100uLL);
if ( (int)v10 <= 0 )
break;
add_output(v3, v11, v10);
}
if ( (int)v10 < 0 )
output_errno(v3, "Reading command output");
goto LABEL_12;
}
LABEL_21:
output_errno(v3, "fork failed");
return 0xFFFFFFFFLL;
}
close(pipedes[0]);
if ( dup2(pipedes[1], 1) < 0 || dup2(pipedes[1], 2) < 0 )
perror("dup2");
LABEL_19:
execvp(*argv, argv);
fprintf(stderr, "Failed to exec '%s'", *argv);
perror(&byte_B00);
exit(1);
}
perror("Creating pipe");
}
v7 = fork();
v6 = v7;
if ( !v7 )
goto LABEL_19;
v3 = 0LL;
if ( v7 < 0 )
{
v3 = 0LL;
goto LABEL_21;
}
LABEL_12:
if ( waitpid(v6, &stat_loc, 0) < 0 )
{
output_errno(v3, "waitpid");
result = 0xFFFFFFFFLL;
}
else
{
result = a2;
if ( a2 )
{
v9 = stat_loc & 0x7F;
result = v9 | (unsigned int)BYTE1(stat_loc);
if ( v9 | BYTE1(stat_loc) )
{
sprintf(v11, "'%s' didn't exit with status 0\n", *argv);
add_output(v3, v11, 0xFFFFFFFFLL);
result = 0xFFFFFFFFLL;
}
}
}
return result;
}

original_code:
int do_exec(char **args, int need_zero, struct output *output)
{
  int pid, status, fds[2], n;
  char buf[256], **arg;
  if(output){
    add_output(output, "*", -1);
    for(arg = args; *arg; arg++){
      add_output(output, " ", -1);
      add_output(output, *arg, -1);
    }
    add_output(output, "\n", -1);
    if(pipe(fds) < 0){
      perror("Creating pipe");
      output = ((void *)0);
    }
  }
  if((pid = fork()) == 0){
    if(output){
      close(fds[0]);
      if((dup2(fds[1], 1) < 0) || (dup2(fds[1], 2) < 0)) perror("dup2");
    }
    execvp(args[0], args);
    fprintf(stderr, "Failed to exec '%s'", args[0]);
    perror("");
    exit(1);
  }
  else if(pid < 0){
    output_errno(output, "fork failed");
    return(-1);
  }
  if(output){
    close(fds[1]);
    while((n = read(fds[0], buf, sizeof(buf))) > 0) add_output(output, buf, n);
    if(n < 0) output_errno(output, "Reading command output");
  }
  if(waitpid(pid, &status, 0) < 0){
    output_errno(output, "waitpid");
    return(-1);
  }
  if(need_zero && (!(((status) & 0x7f) == 0) || ((((status) & 0xff00) >> 8) != 0))){
    sprintf(buf, "'%s' didn't exit with status 0\n", args[0]);
    add_output(output, buf, -1);
    return(-1);
  }
  return(0);
}

canonical_original_code:
int do_exec(char **args, int need_zero, struct output *output)
{
  int pid; int status; int fds[2]; int n;
  char buf[256]; char **arg;
  if(output){
    add_output(output, "*", -1);
    for(arg = args; *arg; arg++){
      add_output(output, " ", -1);
      add_output(output, *arg, -1);
    }
    add_output(output, "\n", -1);
    if(pipe(fds) < 0){
      perror("Creating pipe");
      output = ((void *)0);
    }
  }
  if((pid = fork()) == 0){
    if(output){
      close(fds[0]);
      if((dup2(fds[1], 1) < 0) || (dup2(fds[1], 2) < 0)) perror("dup2");
    }
    execvp(args[0], args);
    fprintf(stderr, "Failed to exec '%s'", args[0]);
    perror("");
    exit(1);
  }
  else if(pid < 0){
    output_errno(output, "fork failed");
    return(-1);
  }
  if(output){
    close(fds[1]);
    while((n = read(fds[0], buf, sizeof(buf))) > 0) add_output(output, buf, n);
    if(n < 0) output_errno(output, "Reading command output");
  }
  if(waitpid(pid, &status, 0) < 0){
    output_errno(output, "waitpid");
    return(-1);
  }
  if(need_zero && (!(((status) & 0x7f) == 0) || ((((status) & 0xff00) >> 8) != 0))){
    sprintf(buf, "'%s' didn't exit with status 0\n", args[0]);
    add_output(output, buf, -1);
    return(-1);
  }
  return(0);
}

variable_types:
args
char **

variable_types: pid int

variable_types: status int

variable_types:
fds
int [2]

variable_types: n int

variable_types:
buf
char [256]

variable_types:
arg
char **


decompiled_code:
__int64 __fastcall is_a_device(const char *a1)
{
size_t v1; // r13
unsigned int i; // ebp

v1 = strlen(a1);
for ( i = 0; i < v1; ++i )
{
if ( ((*_ctype_b_loc())[a1[i]] & 8) == 0 )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1)
{
size_t v1; // r13
unsigned int i; // ebp

v1 = strlen(a1);
for ( i = 0; i < v1; ++i )
{
if ( ((*_ctype_b_loc())[a1[i]] & 8) == 0 )
return 0LL;
}
return 1LL;
}

original_code:
int is_a_device(char *dev)
{
  unsigned i;
  for(i = 0; i < strlen(dev); i++){
    if(!((*__ctype_b_loc ())[(int) ((dev[i]))] & (unsigned short int) _ISalnum)) return(0);
  }
  return(1);
}

canonical_original_code:
int is_a_device(char *dev)
{
  unsigned int i;
  for(i = 0; i < strlen(dev); i++){
    if(!((*__ctype_b_loc ())[(int) ((dev[i]))] & (unsigned short) _ISalnum)) return(0);
  }
  return(1);
}

variable_types:
dev
char *

variable_types:
i
unsigned int


decompiled_code:
__int64 __fastcall route_and_arp(char *a1, char *a2, __int64 a3, unsigned int a4, __int64 a5)
{
unsigned int v8; // er13
char *v10[6]; // [rsp+0h] [rbp-F8h] BYREF
char *argv[8]; // [rsp+30h] [rbp-C8h] BYREF
char *v12[4]; // [rsp+70h] [rbp-88h] BYREF
char s[104]; // [rsp+90h] [rbp-68h] BYREF

v12[0] = "bash";
v12[1] = "-c";
v12[2] = s;
v12[3] = 0LL;
argv[0] = "route";
argv[1] = "add";
argv[2] = "-host";
argv[3] = a2;
argv[4] = "dev";
argv[5] = a1;
argv[6] = 0LL;
v10[0] = "arp";
v10[1] = "-Ds";
v10[2] = a2;
v10[3] = "eth0";
v10[4] = "pub";
v10[5] = 0LL;
if ( (unsigned int)is_a_device(a1) )
{
v8 = do_exec(argv, a4, a5);
if ( v8 )
{
v8 = -1;
}
else
{
snprintf(s, 0x34uLL, "echo 1 > /proc/sys/net/ipv4/conf/%.9s/proxy_arp", a1);
do_exec(v12, 0, a5);
if ( a3 )
local_net_do(v10, 3, (__int64)a2, a3, a1, a5);
else
do_exec(v10, 0, a5);
}
}
else
{
add_output(a5, "Device doesn't contain only alphanumeric characters\n", 0xFFFFFFFFLL);
v8 = -1;
}
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *a1, char *a2, __int64 a3, unsigned int a4, __int64 a5)
{
unsigned int v8; // er13
char *v10[6]; // [rsp+0h] [rbp-F8h] BYREF
char *argv[8]; // [rsp+30h] [rbp-C8h] BYREF
char *v12[4]; // [rsp+70h] [rbp-88h] BYREF
char s[104]; // [rsp+90h] [rbp-68h] BYREF

v12[0] = "bash";
v12[1] = "-c";
v12[2] = s;
v12[3] = 0LL;
argv[0] = "route";
argv[1] = "add";
argv[2] = "-host";
argv[3] = a2;
argv[4] = "dev";
argv[5] = a1;
argv[6] = 0LL;
v10[0] = "arp";
v10[1] = "-Ds";
v10[2] = a2;
v10[3] = "eth0";
v10[4] = "pub";
v10[5] = 0LL;
if ( (unsigned int)func2(a1) )
{
v8 = func0(argv, a4, a5);
if ( v8 )
{
v8 = -1;
}
else
{
snprintf(s, 0x34uLL, "echo 1 > /proc/sys/net/ipv4/conf/%.9s/proxy_arp", a1);
func0(v12, 0, a5);
if ( a3 )
func1(v10, 3, (__int64)a2, a3, a1, a5);
else
func0(v10, 0, a5);
}
}
else
{
add_output(a5, "Device doesn't contain only alphanumeric characters\n", 0xFFFFFFFFLL);
v8 = -1;
}
return v8;
}

original_code:
int route_and_arp(char *dev, char *addr, char *netmask, int need_route,
    struct output *output)
{
  char echo[sizeof("echo 1 > /proc/sys/net/ipv4/conf/XXXXXXXXX/proxy_arp")];
  char *echo_argv[] = { "bash", "-c", echo, ((void *)0) };
  char *route_argv[] = { "route", "add", "-host", addr, "dev", dev, ((void *)0) };
  char *arp_argv[] = { "arp", "-Ds", addr, "eth0", "pub", ((void *)0) };
  if(!is_a_device(dev)){
    add_output(output, "Device doesn't contain only alphanumeric characters\n",
        -1);
    return(-1);
  }
  if(do_exec(route_argv, need_route, output)) return(-1);
  snprintf(echo, sizeof(echo) - 1,
    "echo 1 > /proc/sys/net/ipv4/conf/%.9s/proxy_arp", dev);
  do_exec(echo_argv, 0, output);
  if(netmask) local_net_do(arp_argv, 3, addr, netmask, dev, output);
  else do_exec(arp_argv, 0, output);
  return(0);
}

canonical_original_code:
int route_and_arp(char *dev, char *addr, char *netmask, int need_route, struct output *output)
{
  char echo[-1];
  char *echo_argv[] = { "bash", "-c", echo, ((void *)0) };
  char *route_argv[] = { "route", "add", "-host", addr, "dev", dev, ((void *)0) };
  char *arp_argv[] = { "arp", "-Ds", addr, "eth0", "pub", ((void *)0) };
  if(!is_a_device(dev)){
    add_output(output, "Device doesn't contain only alphanumeric characters\n",
        -1);
    return(-1);
  }
  if(do_exec(route_argv, need_route, output)) return(-1);
  snprintf(echo, sizeof(echo) - 1,
    "echo 1 > /proc/sys/net/ipv4/conf/%.9s/proxy_arp", dev);
  do_exec(echo_argv, 0, output);
  if(netmask) local_net_do(arp_argv, 3, addr, netmask, dev, output);
  else do_exec(arp_argv, 0, output);
  return(0);
}

variable_types:
addr
char *

variable_types:
netmask
char *

variable_types:
echo
char [-1]


decompiled_code:
__int64 __fastcall no_route_and_arp(char *a1, char *a2, __int64 a3, __int64 a4)
{
__int64 result; // rax
char *v7[8]; // [rsp+0h] [rbp-108h] BYREF
char *argv[8]; // [rsp+40h] [rbp-C8h] BYREF
char *v9[4]; // [rsp+80h] [rbp-88h] BYREF
char s[104]; // [rsp+A0h] [rbp-68h] BYREF

v9[0] = "bash";
v9[1] = "-c";
v9[2] = s;
v9[3] = 0LL;
argv[0] = "route";
argv[1] = "del";
argv[2] = "-host";
argv[3] = a2;
argv[4] = "dev";
argv[5] = a1;
argv[6] = 0LL;
v7[0] = "arp";
v7[1] = "-i";
v7[2] = "eth0";
v7[3] = "-d";
v7[4] = a2;
v7[5] = "pub";
v7[6] = 0LL;
if ( (unsigned int)is_a_device(a1) )
{
do_exec(argv, 0, a4);
snprintf(s, 0x34uLL, "echo 0 > /proc/sys/net/ipv4/conf/%.9s/proxy_arp", a1);
do_exec(v9, 0, a4);
if ( a3 )
local_net_do(v7, 2, (__int64)a2, a3, a1, a4);
else
do_exec(v7, 0, a4);
result = 0LL;
}
else
{
add_output(a4, "Device doesn't contain only alphanumeric characters\n", 0xFFFFFFFFLL);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(char *a1, char *a2, __int64 a3, __int64 a4)
{
__int64 result; // rax
char *v7[8]; // [rsp+0h] [rbp-108h] BYREF
char *argv[8]; // [rsp+40h] [rbp-C8h] BYREF
char *v9[4]; // [rsp+80h] [rbp-88h] BYREF
char s[104]; // [rsp+A0h] [rbp-68h] BYREF

v9[0] = "bash";
v9[1] = "-c";
v9[2] = s;
v9[3] = 0LL;
argv[0] = "route";
argv[1] = "del";
argv[2] = "-host";
argv[3] = a2;
argv[4] = "dev";
argv[5] = a1;
argv[6] = 0LL;
v7[0] = "arp";
v7[1] = "-i";
v7[2] = "eth0";
v7[3] = "-d";
v7[4] = a2;
v7[5] = "pub";
v7[6] = 0LL;
if ( (unsigned int)func2(a1) )
{
func0(argv, 0, a4);
snprintf(s, 0x34uLL, "echo 0 > /proc/sys/net/ipv4/conf/%.9s/proxy_arp", a1);
func0(v9, 0, a4);
if ( a3 )
func1(v7, 2, (__int64)a2, a3, a1, a4);
else
func0(v7, 0, a4);
result = 0LL;
}
else
{
add_output(a4, "Device doesn't contain only alphanumeric characters\n", 0xFFFFFFFFLL);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int no_route_and_arp(char *dev, char *addr, char *netmask,
       struct output *output)
{
  char echo[sizeof("echo 0 > /proc/sys/net/ipv4/conf/XXXXXXXXX/proxy_arp")];
  char *no_echo_argv[] = { "bash", "-c", echo, ((void *)0) };
  char *no_route_argv[] = { "route", "del", "-host", addr, "dev", dev, ((void *)0) };
  char *no_arp_argv[] = { "arp", "-i", "eth0", "-d", addr, "pub", ((void *)0) };
  if(!is_a_device(dev)){
    add_output(output, "Device doesn't contain only alphanumeric characters\n",
        -1);
    return(-1);
  }
  do_exec(no_route_argv, 0, output);
  snprintf(echo, sizeof(echo) - 1,
    "echo 0 > /proc/sys/net/ipv4/conf/%.9s/proxy_arp", dev);
  do_exec(no_echo_argv, 0, output);
  if(netmask) local_net_do(no_arp_argv, 2, addr, netmask, dev, output);
  else do_exec(no_arp_argv, 0, output);
  return(0);
}

canonical_original_code:
int no_route_and_arp(char *dev, char *addr, char *netmask, struct output *output)
{
  char echo[-1];
  char *no_echo_argv[] = { "bash", "-c", echo, ((void *)0) };
  char *no_route_argv[] = { "route", "del", "-host", addr, "dev", dev, ((void *)0) };
  char *no_arp_argv[] = { "arp", "-i", "eth0", "-d", addr, "pub", ((void *)0) };
  if(!is_a_device(dev)){
    add_output(output, "Device doesn't contain only alphanumeric characters\n",
        -1);
    return(-1);
  }
  do_exec(no_route_argv, 0, output);
  snprintf(echo, sizeof(echo) - 1,
    "echo 0 > /proc/sys/net/ipv4/conf/%.9s/proxy_arp", dev);
  do_exec(no_echo_argv, 0, output);
  if(netmask) local_net_do(no_arp_argv, 2, addr, netmask, dev, output);
  else do_exec(no_arp_argv, 0, output);
  return(0);
}

variable_types: struct output { int total; int used; char *buffer; } *


decompiled_code:
__int64 __fastcall forward_ip(__int64 a1)
{
char *v2[5]; // [rsp+0h] [rbp-28h] BYREF

v2[0] = "bash";
v2[1] = "-c";
v2[2] = "echo 1 > /proc/sys/net/ipv4/ip_forward";
v2[3] = 0LL;
return do_exec(v2, 0, a1);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
char *v2[5]; // [rsp+0h] [rbp-28h] BYREF

v2[0] = "bash";
v2[1] = "-c";
v2[2] = "echo 1 > /proc/sys/net/ipv4/ip_forward";
v2[3] = 0LL;
return func0(v2, 0, a1);
}

original_code:
void forward_ip(struct output *output)
{
  char *forw_argv[] = { "bash", "-c",
   "echo 1 > /proc/sys/net/ipv4/ip_forward", ((void *)0) };
  do_exec(forw_argv, 0, output);
}


decompiled_code:
int __fastcall address_change(unsigned int a1, unsigned __int8 *a2, char *a3, unsigned __int8 *a4, __int64 a5)
{
char v9[32]; // [rsp+8h] [rbp-68h] BYREF
char s[72]; // [rsp+28h] [rbp-48h] BYREF

snprintf(s, 0x10uLL, "%d.%d.%d.%d", *a2, a2[1], a2[2], a2[3]);
if ( a4 )
{
snprintf(v9, 0x10uLL, "%d.%d.%d.%d", *a4, a4[1], a4[2], a4[3]);
a4 = (unsigned __int8 *)v9;
}
if ( !a1 )
return route_and_arp(a3, s, (__int64)a4, 0, a5);
if ( a1 == 1 )
return no_route_and_arp(a3, s, (__int64)a4, a5);
return fprintf(stderr, "address_change - bad op : %d\n", a1);
}

canonical_decompiled_code:
int __fastcall func6(unsigned int a1, unsigned __int8 *a2, char *a3, unsigned __int8 *a4, __int64 a5)
{
char v9[32]; // [rsp+8h] [rbp-68h] BYREF
char s[72]; // [rsp+28h] [rbp-48h] BYREF

snprintf(s, 0x10uLL, "%d.%d.%d.%d", *a2, a2[1], a2[2], a2[3]);
if ( a4 )
{
snprintf(v9, 0x10uLL, "%d.%d.%d.%d", *a4, a4[1], a4[2], a4[3]);
a4 = (unsigned __int8 *)v9;
}
if ( !a1 )
return func3(a3, s, (__int64)a4, 0, a5);
if ( a1 == 1 )
return func4(a3, s, (__int64)a4, a5);
return fprintf(stderr, "address_change - bad op : %d\n", a1);
}

original_code:
void address_change(enum change_type what, unsigned char *addr_str, char *dev,
      unsigned char *netmask_str, struct output *output)
{
  char addr[sizeof("255.255.255.255\0")];
  char netmask[sizeof("255.255.255.255\0")], *n = ((void *)0);
  snprintf(addr, sizeof(addr) - 1, "%d.%d.%d.%d", addr_str[0], addr_str[1],
    addr_str[2], addr_str[3]);
  if(netmask_str != ((void *)0)){
    snprintf(netmask, sizeof(netmask) - 1, "%d.%d.%d.%d", netmask_str[0],
      netmask_str[1], netmask_str[2], netmask_str[3]);
    n = netmask;
  }
  switch(what){
  case ADD_ADDR:
    route_and_arp(dev, addr, n, 0, output);
    break;
  case DEL_ADDR:
    no_route_and_arp(dev, addr, n, output);
    break;
  default:
    fprintf(stderr, "address_change - bad op : %d\n", what);
    return;
  }
}

canonical_original_code:
void address_change(enum change_type what, unsigned char *addr_str, char *dev, unsigned char *netmask_str, struct output *output)
{
  char addr[-1];
  char netmask[-1]; char *n = ((void *)0);
  snprintf(addr, sizeof(addr) - 1, "%d.%d.%d.%d", addr_str[0], addr_str[1],
    addr_str[2], addr_str[3]);
  if(netmask_str != ((void *)0)){
    snprintf(netmask, sizeof(netmask) - 1, "%d.%d.%d.%d", netmask_str[0],
      netmask_str[1], netmask_str[2], netmask_str[3]);
    n = netmask;
  }
  switch(what){
  case ADD_ADDR:
    route_and_arp(dev, addr, n, 0, output);
    break;
  case DEL_ADDR:
    no_route_and_arp(dev, addr, n, output);
    break;
  default:
    fprintf(stderr, "address_change - bad op : %d\n", what);
    return;
  }
}

variable_types: enum change_type { ADD_ADDR=0, DEL_ADDR=1 }

variable_types:
addr
char [-1]

variable_types:
netmask
char [-1]

variable_types:
n
char *


decompiled_code:
int __fastcall mk_node(char *path, unsigned int a2, unsigned int a3)
{
int result; // eax
int v5; // eax
struct stat v6; // [rsp+0h] [rbp-A8h] BYREF

result = stat(path, &v6);
if ( result )
{
if ( *_errno_location() == 2 )
{
v5 = makedev(a2, a3);
result = mknod(path, 0x2180u, v5);
}
else
{
result = -1;
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func7(char *path, unsigned int a2, unsigned int a3)
{
int result; // eax
int v5; // eax
struct stat v6; // [rsp+0h] [rbp-A8h] BYREF

result = stat(path, &v6);
if ( result )
{
if ( *_errno_location() == 2 )
{
v5 = makedev(a2, a3);
result = mknod(path, 0x2180u, v5);
}
else
{
result = -1;
}
}
return result;
}

original_code:
int mk_node(char *devname, int major, int minor)
{
  struct stat statval;
  int retval;
  retval = stat(devname, &statval);
  if(retval == 0) return(0);
  else if((*__errno_location ()) != 2){
    return -1;
  }
  return(mknod(devname, 0020000|0400|0200, makedev(major, minor)));
}

variable_types:
devname
char *

variable_types: major int

variable_types: minor int

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

variable_types: retval int

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


decompiled_code:
__int64 __fastcall add_address_v4(__int64 a1, __int64 a2)
{
int v3[2]; // [rsp+0h] [rbp-18h] BYREF
__int64 v4; // [rsp+8h] [rbp-10h]

v3[0] = 0;
v3[1] = 0;
v4 = 0LL;
if ( setreuid(0, 0) < 0 )
{
output_errno(v3, "setreuid");
exit(1);
}
route_and_arp(*(char **)a2, *(char **)(a2 + 8), *(_QWORD *)(a2 + 16), 0, (__int64)v3);
return write_output(1LL, v3);
}

original_code:
void add_address_v4(int argc, char **argv)
{
  struct output output = { 0, 0, ((void *)0) };
  if(setreuid(0, 0) < 0){
    output_errno(&output, "setreuid");
    exit(1);
  }
  route_and_arp(argv[0], argv[1], argv[2], 0, &output);
  write_output(1, &output);
}

variable_types: argc int

variable_types:
argv
char **

variable_types: struct output { int total; int used; char *buffer; }


decompiled_code:
__int64 __fastcall del_address_v4(__int64 a1, __int64 a2)
{
int v3[2]; // [rsp+0h] [rbp-18h] BYREF
__int64 v4; // [rsp+8h] [rbp-10h]

v3[0] = 0;
v3[1] = 0;
v4 = 0LL;
if ( setreuid(0, 0) < 0 )
{
output_errno(v3, "setreuid");
exit(1);
}
no_route_and_arp(*(char **)a2, *(char **)(a2 + 8), *(_QWORD *)(a2 + 16), (__int64)v3);
return write_output(1LL, v3);
}

original_code:
void del_address_v4(int argc, char **argv)
{
  struct output output = { 0, 0, ((void *)0) };
  if(setreuid(0, 0) < 0){
    output_errno(&output, "setreuid");
    exit(1);
  }
  no_route_and_arp(argv[0], argv[1], argv[2], &output);
  write_output(1, &output);
}


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

if ( setreuid(0, 0) < 0 )
{
output_errno(a5, "setreuid");
exit(1);
}
if ( !strcmp(a1, "add") )
result = route_and_arp(a2, a3, a4, 0, a5);
else
result = no_route_and_arp(a2, a3, a4, a5);
return result;
}

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

if ( setreuid(0, 0) < 0 )
{
output_errno(a5, "setreuid");
exit(1);
}
if ( !strcmp(a1, "add") )
result = func3(a2, a3, a4, 0, a5);
else
result = func4(a2, a3, a4, a5);
return result;
}

original_code:
void change_addr(char *op, char *dev, char *address, char *netmask,
   struct output *output)
{
  if(setreuid(0, 0) < 0){
    output_errno(output, "setreuid");
    exit(1);
  }
  if(!strcmp(op, "add")) route_and_arp(dev, address, netmask, 0, output);
  else no_route_and_arp(dev, address, netmask, output);
}

variable_types:
op
char *

variable_types:
dev
char *

variable_types:
address
char *


decompiled_code:
__int64 __fastcall cow_seek_file(int a1, __off64_t a2)
{
__off64_t v2; // rdx
__int64 result; // rax

v2 = lseek64(a1, a2, 0);
result = 0LL;
if ( a2 != v2 )
result = (unsigned int)-*_errno_location();
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, __off64_t a2)
{
__off64_t v2; // rdx
__int64 result; // rax

v2 = lseek64(a1, a2, 0);
result = 0LL;
if ( a2 != v2 )
result = (unsigned int)-*_errno_location();
return result;
}

original_code:
static inline int cow_seek_file(int fd, __u64 offset)
{
 __u64 actual;
 actual = lseek64(fd, offset, 0);
 if(actual != offset)
  return(-(*__errno_location ()));
 return(0);
}

canonical_original_code:
static inline int cow_seek_file(int fd, unsigned long long offset)
{
 unsigned long long actual;
 actual = lseek64(fd, offset, 0);
 if(actual != offset)
  return(-(*__errno_location ()));
 return(0);
}

variable_types: fd int

variable_types:
offset
unsigned long long

variable_types:
actual
unsigned long long


decompiled_code:
void *__fastcall cow_malloc(int a1)
{
return malloc(a1);
}

canonical_decompiled_code:
void *__fastcall func1(int a1)
{
return malloc(a1);
}

original_code:
static inline void *cow_malloc(int size)
{
 return(malloc(size));
}

variable_types: size int

return_type: void *


decompiled_code:
__int64 __fastcall cow_file_size(char *file, __off_t *a2)
{
__int64 result; // rax
int *v3; // rbp
int v4; // eax
int v5; // er12
int *v6; // rbp
int *v7; // rbp
int v8; // [rsp+Ch] [rbp-ACh] BYREF
struct stat64 v9; // [rsp+10h] [rbp-A8h] BYREF

if ( stat64(file, &v9) == -1 )
{
v3 = _errno_location();
printf("Couldn't stat \"%s\" : errno = %d\n", file, (unsigned int)*v3);
result = (unsigned int)-*v3;
}
else if ( (v9.st_mode & 0xF000) == 24576 )
{
v4 = open64(file, 0);
v5 = v4;
if ( v4 < 0 )
{
v6 = _errno_location();
printf("Couldn't open \"%s\", errno = %d\n", file, (unsigned int)*v6);
result = (unsigned int)-*v6;
}
else if ( ioctl(v4, 0x1260uLL, &v8) < 0 )
{
v7 = _errno_location();
printf("Couldn't get the block size of \"%s\", errno = %d\n", file, (unsigned int)*v7);
close(v5);
result = (unsigned int)-*v7;
}
else
{
*a2 = (__int64)v8 << 9;
close(v5);
result = 0LL;
}
}
else
{
*a2 = v9.st_size;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *file, __off_t *a2)
{
__int64 result; // rax
int *v3; // rbp
int v4; // eax
int v5; // er12
int *v6; // rbp
int *v7; // rbp
int v8; // [rsp+Ch] [rbp-ACh] BYREF
struct stat64 v9; // [rsp+10h] [rbp-A8h] BYREF

if ( stat64(file, &v9) == -1 )
{
v3 = _errno_location();
printf("Couldn't stat \"%s\" : errno = %d\n", file, (unsigned int)*v3);
result = (unsigned int)-*v3;
}
else if ( (v9.st_mode & 0xF000) == 24576 )
{
v4 = open64(file, 0);
v5 = v4;
if ( v4 < 0 )
{
v6 = _errno_location();
printf("Couldn't open \"%s\", errno = %d\n", file, (unsigned int)*v6);
result = (unsigned int)-*v6;
}
else if ( ioctl(v4, 0x1260uLL, &v8) < 0 )
{
v7 = _errno_location();
printf("Couldn't get the block size of \"%s\", errno = %d\n", file, (unsigned int)*v7);
close(v5);
result = (unsigned int)-*v7;
}
else
{
*a2 = (__int64)v8 << 9;
close(v5);
result = 0LL;
}
}
else
{
*a2 = v9.st_size;
result = 0LL;
}
return result;
}

original_code:
static inline int cow_file_size(char *file, __u64 *size_out)
{
 struct stat64 buf;
 if (stat64(file, &buf) == -1) {
  printf("Couldn't stat \"%s\" : errno = %d\n", file, (*__errno_location ()));
  return(-(*__errno_location ()));
 }
 if(((((buf.st_mode)) & 0170000) == (0060000))){
  int fd, blocks;
  if((fd = open(file, 00)) < 0){
   printf("Couldn't open \"%s\", errno = %d\n", file,
       (*__errno_location ()));
   return(-(*__errno_location ()));
  }
  if(ioctl(fd, (((0U) << (((0 +8)+8)+14)) | (((0x12)) << (0 +8)) | (((96)) << 0) | ((0) << ((0 +8)+8))), &blocks) < 0){
   printf("Couldn't get the block size of \"%s\", "
       "errno = %d\n", file, (*__errno_location ()));
   close(fd);
   return(-(*__errno_location ()));
  }
  *size_out = ((long long) blocks) * 512;
  close(fd);
  return(0);
 }
 *size_out = buf.st_size;
 return(0);
}

canonical_original_code:
static inline int cow_file_size(char *file, unsigned long long *size_out)
{
 struct stat64 buf;
 if (stat64(file, &buf) == -1) {
  printf("Couldn't stat \"%s\" : errno = %d\n", file, (*__errno_location ()));
  return(-(*__errno_location ()));
 }
 if(((((buf.st_mode)) & 0170000) == (0060000))){
  int fd; int blocks;
  if((fd = open(file, 00)) < 0){
   printf("Couldn't open \"%s\", errno = %d\n", file,
       (*__errno_location ()));
   return(-(*__errno_location ()));
  }
  if(ioctl(fd, (((0U) << (((0 +8)+8)+14)) | (((0x12)) << (0 +8)) | (((96)) << 0) | ((0) << ((0 +8)+8))), &blocks) < 0){
   printf("Couldn't get the block size of \"%s\", "
       "errno = %d\n", file, (*__errno_location ()));
   close(fd);
   return(-(*__errno_location ()));
  }
  *size_out = ((long long) blocks) * 512;
  close(fd);
  return(0);
 }
 *size_out = buf.st_size;
 return(0);
}

variable_types:
file
char *

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

variable_types: blocks int

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


decompiled_code:
__int64 __fastcall cow_write_file(int a1, const void *a2, int a3)
{
unsigned int v3; // edx

v3 = write(a1, a2, a3);
if ( v3 == -1 )
v3 = -*_errno_location();
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1, const void *a2, int a3)
{
unsigned int v3; // edx

v3 = write(a1, a2, a3);
if ( v3 == -1 )
v3 = -*_errno_location();
return v3;
}

original_code:
static inline int cow_write_file(int fd, void *buf, int size)
{
 int ret = write(fd, buf, size);
 if (ret == -1)
  return(-(*__errno_location ()));
 return(ret);
}

variable_types:
buf
void *

variable_types: ret int


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

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

original_code:
static inline void cow_free(void *ptr)
{
 free(ptr);
}

variable_types:
ptr
void *


decompiled_code:
char *__fastcall cow_strdup(const char *a1)
{
return strdup(a1);
}

canonical_decompiled_code:
char *__fastcall func8(const char *a1)
{
return strdup(a1);
}

original_code:
static inline char *cow_strdup(char *str)
{
 return(strdup(str));
}

variable_types:
str
char *

return_type: char *


decompiled_code:
__int64 __fastcall cow_sizes(int a1, __int64 a2, int a3, int a4, int a5, unsigned __int64 *a6, _DWORD *a7)
{
unsigned __int64 v7; // rax
__int64 result; // rax
unsigned __int64 v9; // rax

if ( a1 > 2 )
{
v9 = ((a3 + a2 - 1) / (unsigned __int64)a3 + 7) >> 3;
*a6 = v9;
result = (unsigned int)(a4 * ((a4 + (int)v9 + a5 - 1) / a4));
}
else
{
v7 = (a2 + a3 - 1) / (unsigned __int64)(8 * a3);
*a6 = v7;
result = (unsigned int)(a3 * ((a3 + a5 + (int)v7 - 1) / a3));
}
*a7 = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1, __int64 a2, int a3, int a4, int a5, unsigned __int64 *a6, _DWORD *a7)
{
unsigned __int64 v7; // rax
__int64 result; // rax
unsigned __int64 v9; // rax

if ( a1 > 2 )
{
v9 = ((a3 + a2 - 1) / (unsigned __int64)a3 + 7) >> 3;
*a6 = v9;
result = (unsigned int)(a4 * ((a4 + (int)v9 + a5 - 1) / a4));
}
else
{
v7 = (a2 + a3 - 1) / (unsigned __int64)(8 * a3);
*a6 = v7;
result = (unsigned int)(a3 * ((a3 + a5 + (int)v7 - 1) / a3));
}
*a7 = result;
return result;
}

original_code:
void cow_sizes(int version, __u64 size, int sectorsize, int align,
        int bitmap_offset, unsigned long *bitmap_len_out,
        int *data_offset_out)
{
 if(version < 3){
  *bitmap_len_out = (size + sectorsize - 1) / (8 * sectorsize);
  *data_offset_out = bitmap_offset + *bitmap_len_out;
  *data_offset_out = (*data_offset_out + sectorsize - 1) /
   sectorsize;
  *data_offset_out *= sectorsize;
 }
 else {
  *bitmap_len_out = (((size) + (sectorsize) - 1) / (sectorsize));
  *bitmap_len_out = (((*bitmap_len_out) + (8) - 1) / (8));
  *data_offset_out = bitmap_offset + *bitmap_len_out;
  *data_offset_out = (((*data_offset_out) + (align) - 1) / (align)) * (align);
 }
}

canonical_original_code:
void cow_sizes(int version, unsigned long long size, int sectorsize, int align, int bitmap_offset, unsigned long *bitmap_len_out, int *data_offset_out)
{
 if(version < 3){
  *bitmap_len_out = (size + sectorsize - 1) / (8 * sectorsize);
  *data_offset_out = bitmap_offset + *bitmap_len_out;
  *data_offset_out = (*data_offset_out + sectorsize - 1) /
   sectorsize;
  *data_offset_out *= sectorsize;
 }
 else {
  *bitmap_len_out = (((size) + (sectorsize) - 1) / (sectorsize));
  *bitmap_len_out = (((*bitmap_len_out) + (8) - 1) / (8));
  *data_offset_out = bitmap_offset + *bitmap_len_out;
  *data_offset_out = (((*data_offset_out) + (align) - 1) / (align)) * (align);
 }
}

variable_types: version int

variable_types:
size
unsigned long long

variable_types: sectorsize int

variable_types: align int


decompiled_code:
__int64 __fastcall write_cow_header(const char *a1, int a2, char *a3, unsigned int a4, unsigned int a5, __off_t *a6)
{
int v8; // eax
char *v9; // rbp
unsigned int v10; // ebx
int v12; // eax
int v13; // er12
int v14; // eax
int v15; // er12
unsigned int v16; // eax
unsigned int v17; // er12
struct stat64 v20; // [rsp+10h] [rbp-C8h] BYREF

v8 = cow_seek_file(a2, 0LL);
if ( v8 < 0 )
{
v10 = v8;
printf("write_cow_header - lseek failed, err = %d\n", (unsigned int)-v8);
}
else
{
v9 = (char *)cow_malloc(4128);
if ( v9 )
{
*(_DWORD *)v9 = _bswap_32(0x4F4F4F4Du);
*((_DWORD *)v9 + 1) = _bswap_32(3u);
if ( strlen(a3) > 0xFFF )
{
printf("Backing file name \"%s\" is too long - names are limited to %zd characters\n", a3, 0xFFFuLL);
v10 = -22;
}
else
{
v10 = absolutize(v9 + 32, 0x1000uLL, a3);
if ( v10 )
{
v10 = -22;
}
else
{
v12 = stat64(v9 + 32, &v20);
v13 = v12;
if ( v12 < 0 )
{
printf("write_cow_header - backing file '%s' mtime request failed, err = %d\n", v9 + 32, (unsigned int)-v12);
v10 = v13;
}
else
{
v14 = cow_file_size(v9 + 32, a6);
v15 = v14;
if ( v14 < 0 )
{
printf(
"write_cow_header - couldn't get size of backing file '%s', err = %d\n",
v9 + 32,
(unsigned int)-v14);
v10 = v15;
}
else
{
*((_DWORD *)v9 + 2) = _bswap_32(v20.st_mtim.tv_sec);
*(_QWORD *)(v9 + 12) = _bswap_64(*a6);
*((_DWORD *)v9 + 5) = _bswap_32(a4);
*((_DWORD *)v9 + 6) = _bswap_32(a5);
*((_DWORD *)v9 + 7) = 0;
v16 = cow_write_file(a2, v9, 4128);
v17 = v16;
if ( v16 != 4128 )
{
printf("write_cow_header - write of header to new COW file '%s' failed, err = %d\n", a1, -v16);
v10 = v17;
}
}
}
}
}
cow_free(v9);
}
else
{
puts("write_cow_header - failed to allocate COW V3 header");
v10 = -12;
}
}
return v10;
}

canonical_decompiled_code:
__int64 __fastcall func10(const char *a1, int a2, char *a3, unsigned int a4, unsigned int a5, __off_t *a6)
{
int v8; // eax
char *v9; // rbp
unsigned int v10; // ebx
int v12; // eax
int v13; // er12
int v14; // eax
int v15; // er12
unsigned int v16; // eax
unsigned int v17; // er12
struct stat64 v20; // [rsp+10h] [rbp-C8h] BYREF

v8 = func0(a2, 0LL);
if ( v8 < 0 )
{
v10 = v8;
printf("write_cow_header - lseek failed, err = %d\n", (unsigned int)-v8);
}
else
{
v9 = (char *)func1(4128);
if ( v9 )
{
*(_DWORD *)v9 = func5(0x4F4F4F4Du);
*((_DWORD *)v9 + 1) = func5(3u);
if ( strlen(a3) > 0xFFF )
{
printf("Backing file name \"%s\" is too long - names are limited to %zd characters\n", a3, 0xFFFuLL);
v10 = -22;
}
else
{
v10 = func2(v9 + 32, 0x1000uLL, a3);
if ( v10 )
{
v10 = -22;
}
else
{
v12 = stat64(v9 + 32, &v20);
v13 = v12;
if ( v12 < 0 )
{
printf("write_cow_header - backing file '%s' mtime request failed, err = %d\n", v9 + 32, (unsigned int)-v12);
v10 = v13;
}
else
{
v14 = func3(v9 + 32, a6);
v15 = v14;
if ( v14 < 0 )
{
printf(
"write_cow_header - couldn't get size of backing file '%s', err = %d\n",
v9 + 32,
(unsigned int)-v14);
v10 = v15;
}
else
{
*((_DWORD *)v9 + 2) = func5(v20.st_mtim.tv_sec);
*(_QWORD *)(v9 + 12) = func4(*a6);
*((_DWORD *)v9 + 5) = func5(a4);
*((_DWORD *)v9 + 6) = func5(a5);
*((_DWORD *)v9 + 7) = 0;
v16 = func6(a2, v9, 4128);
v17 = v16;
if ( v16 != 4128 )
{
printf("write_cow_header - write of header to new COW file '%s' failed, err = %d\n", a1, -v16);
v10 = v17;
}
}
}
}
}
func7(v9);
}
else
{
puts("write_cow_header - failed to allocate COW V3 header");
v10 = -12;
}
}
return v10;
}

original_code:
int write_cow_header(char *cow_file, int fd, char *backing_file,
       int sectorsize, int alignment, unsigned long long *size)
{
 struct cow_header_v3 *header;
 struct stat64 buf;
 int err;
 err = cow_seek_file(fd, 0);
 if(err < 0){
  printf("write_cow_header - lseek failed, err = %d\n", -err);
  goto out;
 }
 err = -12;
 header = cow_malloc(sizeof(*header));
 if(header == ((void *)0)){
  printf("write_cow_header - failed to allocate COW V3 header\n");
  goto out;
 }
 header->magic = htonl(0x4f4f4f4d);
 header->version = htonl(3);
 err = -22;
 if(strlen(backing_file) > sizeof(header->backing_file) - 1){
  printf("Backing file name \"%s\" is too long - names are "
      "limited to %zd characters\n", backing_file,
      sizeof(header->backing_file) - 1);
  goto out_free;
 }
 if(absolutize(header->backing_file, sizeof(header->backing_file),
        backing_file))
  goto out_free;
 err = stat64(header->backing_file, &buf);
 if(err < 0){
  printf("write_cow_header - backing file '%s' mtime "
      "request failed, err = %d\n", header->backing_file,
      -err);
  goto out_free;
 }
 err = cow_file_size(header->backing_file, size);
 if(err < 0){
  printf("write_cow_header - couldn't get size of "
      "backing file '%s', err = %d\n",
      header->backing_file, -err);
  goto out_free;
 }
 header->mtime = htonl(buf.st_mtim.tv_sec);
 header->size = __bswap_64 (*size);
 header->sectorsize = htonl(sectorsize);
 header->alignment = htonl(alignment);
 header->cow_format = 0;
 err = cow_write_file(fd, header, sizeof(*header));
 if(err != sizeof(*header)){
  printf("write_cow_header - write of header to "
      "new COW file '%s' failed, err = %d\n", cow_file,
      -err);
  goto out_free;
 }
 err = 0;
 out_free:
 cow_free(header);
 out:
 return(err);
}

variable_types: alignment int

variable_types:
size
unsigned long long *

variable_types: struct cow_header_v3 { unsigned int magic; unsigned int version; unsigned int mtime; unsigned long long size; unsigned int sectorsize; unsigned int alignment; unsigned int cow_format; char backing_file[4096]; } *

variable_types: err int

user_defined_types: struct timespec { long tv_sec; long tv_nsec; }


decompiled_code:
ssize_t __fastcall file_reader(__off64_t offset, void *a2, int a3, int *a4)
{
return pread64(*a4, a2, a3, offset);
}

canonical_decompiled_code:
ssize_t __fastcall func11(__off64_t offset, void *a2, int a3, int *a4)
{
return pread64(*a4, a2, a3, offset);
}

original_code:
int file_reader(__u64 offset, char *buf, int len, void *arg)
{
 int fd = *((int *) arg);
 return(pread(fd, buf, len, offset));
}

canonical_original_code:
int file_reader(unsigned long long offset, char *buf, int len, void *arg)
{
 int fd = *((int *) arg);
 return(pread(fd, buf, len, offset));
}

variable_types:
offset
unsigned long long

variable_types:
buf
char *

variable_types: len int

variable_types:
arg
void *

variable_types: fd int


decompiled_code:
__int64 __fastcall init_cow_file(int a1, const char *a2, char *a3, unsigned int a4, signed int a5, int *a6, unsigned __int64 *a7, _DWORD *a8)
{
unsigned int v11; // ebx
int v13; // er8
int v14; // eax
int v15; // ebp
int v16; // eax
int v17; // ebp
char v18; // [rsp+7h] [rbp-41h] BYREF
__off_t v19[8]; // [rsp+8h] [rbp-40h] BYREF

v18 = 0;
v11 = write_cow_header(a2, a1, a3, a4, a5, v19);
if ( !v11 )
{
v13 = a5 * ((a5 + 4127LL) / (unsigned __int64)a5);
*a6 = v13;
cow_sizes(3, v19[0], a4, a5, v13, a7, a8);
v14 = cow_seek_file(a1, v19[0] + (int)*a8 - 1);
v15 = v14;
if ( v14 < 0 )
{
printf("cow bitmap lseek failed : err = %d\n", (unsigned int)-v14);
v11 = v15;
}
else
{
v16 = cow_write_file(a1, &v18, 1);
v17 = v16;
if ( v16 != 1 )
{
printf("Write of bitmap to new COW file '%s' failed, err = %d\n", a2, (unsigned int)-v16);
v11 = -22;
if ( v17 < 0 )
v11 = v17;
}
}
}
return v11;
}

canonical_decompiled_code:
__int64 __fastcall func13(int a1, const char *a2, char *a3, unsigned int a4, signed int a5, int *a6, unsigned __int64 *a7, _DWORD *a8)
{
unsigned int v11; // ebx
int v13; // er8
int v14; // eax
int v15; // ebp
int v16; // eax
int v17; // ebp
char v18; // [rsp+7h] [rbp-41h] BYREF
__off_t v19[8]; // [rsp+8h] [rbp-40h] BYREF

v18 = 0;
v11 = func10(a2, a1, a3, a4, a5, v19);
if ( !v11 )
{
v13 = a5 * ((a5 + 4127LL) / (unsigned __int64)a5);
*a6 = v13;
func9(3, v19[0], a4, a5, v13, a7, a8);
v14 = func0(a1, v19[0] + (int)*a8 - 1);
v15 = v14;
if ( v14 < 0 )
{
printf("cow bitmap lseek failed : err = %d\n", (unsigned int)-v14);
v11 = v15;
}
else
{
v16 = func6(a1, &v18, 1);
v17 = v16;
if ( v16 != 1 )
{
printf("Write of bitmap to new COW file '%s' failed, err = %d\n", a2, (unsigned int)-v16);
v11 = -22;
if ( v17 < 0 )
v11 = v17;
}
}
}
return v11;
}

original_code:
int init_cow_file(int fd, char *cow_file, char *backing_file, int sectorsize,
    int alignment, int *bitmap_offset_out,
    unsigned long *bitmap_len_out, int *data_offset_out)
{
 unsigned long long size, offset;
 char zero = 0;
 int err;
 err = write_cow_header(cow_file, fd, backing_file, sectorsize,
          alignment, &size);
 if(err)
  goto out;
 *bitmap_offset_out = (((sizeof(struct cow_header_v3)) + (alignment) - 1) / (alignment)) * (alignment);
 cow_sizes(3, size, sectorsize, alignment, *bitmap_offset_out,
    bitmap_len_out, data_offset_out);
 offset = *data_offset_out + size - sizeof(zero);
 err = cow_seek_file(fd, offset);
 if(err < 0){
  printf("cow bitmap lseek failed : err = %d\n", -err);
  goto out;
 }
 err = cow_write_file(fd, &zero, sizeof(zero));
 if(err != sizeof(zero)){
  printf("Write of bitmap to new COW file '%s' failed, "
      "err = %d\n", cow_file, -err);
  if (err >= 0)
   err = -22;
  goto out;
 }
 return(0);
 out:
 return(err);
}

canonical_original_code:
int init_cow_file(int fd, char *cow_file, char *backing_file, int sectorsize, int alignment, int *bitmap_offset_out, unsigned long *bitmap_len_out, int *data_offset_out)
{
 unsigned long long size; unsigned long long offset;
 char zero = 0;
 int err;
 err = write_cow_header(cow_file, fd, backing_file, sectorsize,
          alignment, &size);
 if(err)
  goto out;
 *bitmap_offset_out = (((sizeof(struct cow_header_v3)) + (alignment) - 1) / (alignment)) * (alignment);
 cow_sizes(3, size, sectorsize, alignment, *bitmap_offset_out,
    bitmap_len_out, data_offset_out);
 offset = *data_offset_out + size - sizeof(zero);
 err = cow_seek_file(fd, offset);
 if(err < 0){
  printf("cow bitmap lseek failed : err = %d\n", -err);
  goto out;
 }
 err = cow_write_file(fd, &zero, sizeof(zero));
 if(err != sizeof(zero)){
  printf("Write of bitmap to new COW file '%s' failed, "
      "err = %d\n", cow_file, -err);
  if (err >= 0)
   err = -22;
  goto out;
 }
 return(0);
 out:
 return(err);
}

variable_types: zero char

user_defined_types: struct cow_header_v3 { unsigned int magic; unsigned int version; unsigned int mtime; unsigned long long size; unsigned int sectorsize; unsigned int alignment; unsigned int cow_format; char backing_file[4096]; }


decompiled_code:
__int64 __fastcall open_socket(const char *a1)
{
int v1; // eax
unsigned int v2; // ebx
unsigned int v3; // eax
struct sockaddr v5[6]; // [rsp+0h] [rbp-88h] BYREF
__int64 v6; // [rsp+66h] [rbp-22h]

v1 = socket(1, 2, 0);
if ( v1 < 0 )
{
perror("socket");
exit(1);
}
v2 = v1;
v5[0].sa_family = 1;
*(_QWORD *)v5[0].sa_data = 0LL;
v6 = 0LL;
memset(&v5[0].sa_data[6], 0, 0x60uLL);
v3 = getpid();
sprintf(&v5[0].sa_data[1], "%5d", v3);
if ( bind(v2, v5, 0x6Eu) < 0 )
{
perror("bind");
exit(1);
}
snprintf(v5[0].sa_data, 0x6CuLL, "%s", a1);
if ( connect(v2, v5, 0x6Eu) )
{
perror("connect");
exit(1);
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func7(const char *a1)
{
int v1; // eax
unsigned int v2; // ebx
unsigned int v3; // eax
struct sockaddr v5[6]; // [rsp+0h] [rbp-88h] BYREF
__int64 v6; // [rsp+66h] [rbp-22h]

v1 = socket(1, 2, 0);
if ( v1 < 0 )
{
perror("socket");
exit(1);
}
v2 = v1;
v5[0].sa_family = 1;
*(_QWORD *)v5[0].sa_data = 0LL;
v6 = 0LL;
memset(&v5[0].sa_data[6], 0, 0x60uLL);
v3 = getpid();
sprintf(&v5[0].sa_data[1], "%5d", v3);
if ( bind(v2, v5, 0x6Eu) < 0 )
{
perror("bind");
exit(1);
}
snprintf(v5[0].sa_data, 0x6CuLL, "%s", a1);
if ( connect(v2, v5, 0x6Eu) )
{
perror("connect");
exit(1);
}
return v2;
}

original_code:
static int open_socket(char *name)
{
  struct sockaddr_un sock;
  int fd;
  if((fd = socket(1, SOCK_DGRAM, 0)) < 0){
    perror("socket");
    exit(1);
  }
  sock.sun_family = 1;
  memset(sock.sun_path, 0, sizeof(sock.sun_path));
  sprintf(&sock.sun_path[1], "%5d", getpid());
  if(bind(fd, (struct sockaddr *) &sock, sizeof(sock)) < 0){
    perror("bind");
    exit(1);
  }
  snprintf(sock.sun_path, sizeof(sock.sun_path), "%s", name);
  if(connect(fd, (struct sockaddr *) &sock, sizeof(sock))){
    perror("connect");
    exit(1);
  }
  return(fd);
}

variable_types:
name
char *

variable_types: struct sockaddr_un { unsigned short sun_family; char sun_path[108]; }


decompiled_code:
__int64 __fastcall send_fd(int a1, int a2, void *a3, socklen_t a4, __int64 a5, int a6)
{
ssize_t v6; // rdx
__int64 result; // rax
__int64 v8[2]; // [rsp+0h] [rbp-78h] BYREF
struct msghdr message; // [rsp+10h] [rbp-68h] BYREF
__int64 v10; // [rsp+50h] [rbp-28h] BYREF
int v11; // [rsp+58h] [rbp-20h]
int v12; // [rsp+5Ch] [rbp-1Ch]
int v13; // [rsp+60h] [rbp-18h]

message.msg_name = a3;
message.msg_namelen = a4;
v8[0] = a5;
v8[1] = a6;
message.msg_iov = (iovec *)v8;
message.msg_iovlen = 1LL;
message.msg_flags = 0;
message.msg_control = &v10;
v11 = 1;
v12 = 1;
v10 = 20LL;
v13 = a1;
message.msg_controllen = 20LL;
v6 = sendmsg(a2, &message, 0);
result = 0LL;
if ( v6 < 0 )
result = (unsigned int)-*__errno_location();
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1, int a2, void *a3, socklen_t a4, __int64 a5, int a6)
{
ssize_t v6; // rdx
__int64 result; // rax
__int64 v8[2]; // [rsp+0h] [rbp-78h] BYREF
struct msghdr message; // [rsp+10h] [rbp-68h] BYREF
__int64 v10; // [rsp+50h] [rbp-28h] BYREF
int v11; // [rsp+58h] [rbp-20h]
int v12; // [rsp+5Ch] [rbp-1Ch]
int v13; // [rsp+60h] [rbp-18h]

message.msg_name = a3;
message.msg_namelen = a4;
v8[0] = a5;
v8[1] = a6;
message.msg_iov = (iovec *)v8;
message.msg_iovlen = 1LL;
message.msg_flags = 0;
message.msg_control = &v10;
v11 = 1;
v12 = 1;
v10 = 20LL;
v13 = a1;
message.msg_controllen = 20LL;
v6 = sendmsg(a2, &message, 0);
result = 0LL;
if ( v6 < 0 )
result = (unsigned int)-*__errno_location();
return result;
}

original_code:
int send_fd(int fd, int target, struct sockaddr *to, int to_len, void *msg,
     int msg_len)
{
 char anc[((((sizeof(fd)) + sizeof (size_t) - 1) & (size_t) ~(sizeof (size_t) - 1)) + (((sizeof (struct cmsghdr)) + sizeof (size_t) - 1) & (size_t) ~(sizeof (size_t) - 1)))];
 struct msghdr hdr;
 struct cmsghdr *cmsg;
 struct iovec iov;
 int *fd_ptr;
 hdr.msg_name = to;
 hdr.msg_namelen = to_len;
 iov = ((struct iovec) { iov_base : msg,
           iov_len : msg_len });
 hdr.msg_iov = &iov;
 hdr.msg_iovlen = 1;
 hdr.msg_flags = 0;
 hdr.msg_control = anc;
 hdr.msg_controllen = sizeof(anc);
 cmsg = ((size_t) (&hdr)->msg_controllen >= sizeof (struct cmsghdr) ? (struct cmsghdr *) (&hdr)->msg_control : (struct cmsghdr *) 0);
 cmsg->cmsg_level = 1;
 cmsg->cmsg_type = SCM_RIGHTS;
 cmsg->cmsg_len = ((((sizeof (struct cmsghdr)) + sizeof (size_t) - 1) & (size_t) ~(sizeof (size_t) - 1)) + (sizeof(fd)));
 fd_ptr = (int *) ((cmsg)->__cmsg_data);
 *fd_ptr = fd;
 hdr.msg_controllen = cmsg->cmsg_len;
 if(sendmsg(target, &hdr, 0) < 0)
  return -(*__errno_location ());
 return 0;
}

canonical_original_code:
int send_fd(int fd, int target, struct sockaddr *to, int to_len, void *msg, int msg_len)
{
 char anc[-1];
 struct msghdr hdr;
 struct cmsghdr *cmsg;
 struct iovec iov;
 int *fd_ptr;
 hdr.msg_name = to;
 hdr.msg_namelen = to_len;
 iov = ((struct iovec) { iov_base : msg,
           iov_len : msg_len });
 hdr.msg_iov = &iov;
 hdr.msg_iovlen = 1;
 hdr.msg_flags = 0;
 hdr.msg_control = anc;
 hdr.msg_controllen = sizeof(anc);
 cmsg = ((unsigned long) (&hdr)->msg_controllen >= sizeof (struct cmsghdr) ? (struct cmsghdr *) (&hdr)->msg_control : (struct cmsghdr *) 0);
 cmsg->cmsg_level = 1;
 cmsg->cmsg_type = SCM_RIGHTS;
 cmsg->cmsg_len = ((((sizeof (struct cmsghdr)) + sizeof (unsigned long) - 1) & (unsigned long) ~(sizeof (unsigned long) - 1)) + (sizeof(fd)));
 fd_ptr = (int *) ((cmsg)->__cmsg_data);
 *fd_ptr = fd;
 hdr.msg_controllen = cmsg->cmsg_len;
 if(sendmsg(target, &hdr, 0) < 0)
  return -(*__errno_location ());
 return 0;
}

variable_types: target int

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

variable_types:
msg
void *

variable_types:
anc
char [-1]

variable_types: struct msghdr { void *msg_name; unsigned int msg_namelen; struct iovec { void *iov_base; unsigned long iov_len; } *msg_iov; unsigned long msg_iovlen; void *msg_control; unsigned long msg_controllen; int msg_flags; }

variable_types: struct cmsghdr { unsigned long cmsg_len; int cmsg_level; int cmsg_type; unsigned char __cmsg_data[]; } *

user_defined_types: struct msghdr { void *msg_name; unsigned int msg_namelen; struct iovec *msg_iov; unsigned long msg_iovlen; void *msg_control; unsigned long msg_controllen; int msg_flags; }


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebp
__pid_t v5[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v3 = 3;
if ( argc > 1 && !strcmp(argv[1], "-uml-socket") )
v3 = open_socket(argv[2]);
signal(1, (__sighandler_t)1);
if ( ioctl(0, 0x5422uLL, 0LL) < 0 )
perror("TIOCNOTTY failed in port-helper, check UML's exec call for xterm or telnetd");
v5[0] = getpid();
send_fd(0LL, v3, 0LL, 0LL, v5, 4LL);
pause();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebp
__pid_t v5[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v3 = 3;
if ( argc > 1 && !strcmp(argv[1], "-uml-socket") )
v3 = func7(argv[2]);
signal(1, (__sighandler_t)1);
if ( ioctl(0, 0x5422uLL, 0LL) < 0 )
perror("TIOCNOTTY failed in port-helper, check UML's exec call for xterm or telnetd");
v5[0] = getpid();
func8(0LL, v3, 0LL, 0LL, v5, 4LL);
pause();
return 0;
}

original_code:
int main(int argc, char **argv)
{
  int fd, pid;
  if((argc > 1) && !strcmp(argv[1], "-uml-socket")) {
 fd = open_socket(argv[2]);
  } else {
 fd = 3;
  }
  signal(1, ((__sighandler_t) 1));
  if(ioctl(0, 0x5422, 0) < 0)
    perror("TIOCNOTTY failed in port-helper, check UML's exec call for xterm or telnetd");
  pid = getpid();
  send_fd(0, fd, ((void *)0), 0, &pid, sizeof(pid));
  pause();
  return(0);
}

canonical_original_code:
int main(int argc, char **argv)
{
  int fd; int pid;
  if((argc > 1) && !strcmp(argv[1], "-uml-socket")) {
 fd = open_socket(argv[2]);
  } else {
 fd = 3;
  }
  signal(1, ((void (*)(int)) 1));
  if(ioctl(0, 0x5422, 0) < 0)
    perror("TIOCNOTTY failed in port-helper, check UML's exec call for xterm or telnetd");
  pid = getpid();
  send_fd(0, fd, ((void *)0), 0, &pid, sizeof(pid));
  pause();
  return(0);
}

variable_types: argc int

variable_types:
argv
char **

variable_types: pid int


decompiled_code:
void __fastcall write_output(int fd, __int64 a2)
{
if ( a2 )
{
if ( write(fd, (const void *)(a2 + 4), 4uLL) != 4 )
{
perror("write_output : write of length failed");
exit(1);
}
if ( write(fd, *(const void **)(a2 + 8), *(int *)(a2 + 4)) != *(_DWORD *)(a2 + 4) )
{
perror("write_output : write of data failed");
exit(1);
}
*(_DWORD *)(a2 + 4) = 0;
}
}

canonical_decompiled_code:
void __fastcall func0(int fd, __int64 a2)
{
if ( a2 )
{
if ( write(fd, (const void *)(a2 + 4), 4uLL) != 4 )
{
perror("write_output : write of length failed");
exit(1);
}
if ( write(fd, *(const void **)(a2 + 8), *(int *)(a2 + 4)) != *(_DWORD *)(a2 + 4) )
{
perror("write_output : write of data failed");
exit(1);
}
*(_DWORD *)(a2 + 4) = 0;
}
}

original_code:
void write_output(int fd, struct output *output)
{
  if(output == ((void *)0)) return;
  if(write(fd, &output->used, sizeof(output->used)) != sizeof(output->used)){
    perror("write_output : write of length failed");
    exit(1);
  }
  if(write(fd, output->buffer, output->used) != output->used){
    perror("write_output : write of data failed");
    exit(1);
  }
  output->used = 0;
}

variable_types: struct output { int total; int used; char *buffer; } *


original_code:
void add_output(struct output *output, char *new, int len)
{
  int n, start;
  if(output == ((void *)0)){
    fprintf(stderr, "%s", new);
    return;
  }
  if(len == -1) len = strlen(new);
  n = len;
  if(output->used == 0) n++;
  if(output->used + n > output->total){
    output->total = output->used + n;
    output->total = (output->total + 4095) & ~4095;
    if(output->buffer == ((void *)0)){
      if((output->buffer = malloc(output->total)) == ((void *)0)){
 perror("mallocing new output buffer");
 *output = ((struct output) { 0, 0, ((void *)0)});
 return;
      }
    }
    else if((output->buffer = realloc(output->buffer, output->total)) == ((void *)0)){
 perror("reallocing new output buffer");
 *output = ((struct output) { 0, 0, ((void *)0)});
 return;
    }
  }
  if(output->used == 0) start = 0;
  else start = output->used - 1;
  strncpy(&output->buffer[start], new, len);
  output->used += n;
  output->buffer[output->used - 1] = '\0';
}

canonical_original_code:
void add_output(struct output *output, char *new, int len)
{
  int n; int start;
  if(output == ((void *)0)){
    fprintf(stderr, "%s", new);
    return;
  }
  if(len == -1) len = strlen(new);
  n = len;
  if(output->used == 0) n++;
  if(output->used + n > output->total){
    output->total = output->used + n;
    output->total = (output->total + 4095) & ~4095;
    if(output->buffer == ((void *)0)){
      if((output->buffer = malloc(output->total)) == ((void *)0)){
 perror("mallocing new output buffer");
 *output = ((struct output) { 0, 0, ((void *)0)});
 return;
      }
    }
    else if((output->buffer = realloc(output->buffer, output->total)) == ((void *)0)){
 perror("reallocing new output buffer");
 *output = ((struct output) { 0, 0, ((void *)0)});
 return;
    }
  }
  if(output->used == 0) start = 0;
  else start = output->used - 1;
  strncpy(&output->buffer[start], new, len);
  output->used += n;
  output->buffer[output->used - 1] = '\0';
}

variable_types:
new
char *

variable_types: n int

variable_types: start int


decompiled_code:
void __fastcall output_errno(__int64 a1, const char *a2)
{
int *v2; // rax
char *v3; // rax

if ( a1 )
{
add_output(a1, a2, -1);
add_output(a1, ": ", -1);
v2 = _errno_location();
v3 = strerror(*v2);
add_output(a1, v3, -1);
add_output(a1, "\n", -1);
}
else
{
perror(a2);
}
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1, const char *a2)
{
int *v2; // rax
char *v3; // rax

if ( a1 )
{
func1(a1, a2, -1);
func1(a1, ": ", -1);
v2 = _errno_location();
v3 = strerror(*v2);
func1(a1, v3, -1);
func1(a1, "\n", -1);
}
else
{
perror(a2);
}
}

original_code:
void output_errno(struct output *output, char *str)
{
  if(output == ((void *)0)) perror(str);
  else {
    add_output(output, str, -1);
    add_output(output, ": ", -1);
    add_output(output, strerror((*__errno_location ())), -1);
    add_output(output, "\n", -1);
  }
}

variable_types:
str
char *


decompiled_code:
__int64 __fastcall ubd_test_bit(unsigned __int64 a1, __int64 a2)
{
return (*(_QWORD *)(a2 + 8 * (a1 >> 6)) >> (a1 & 0x3F)) & 1LL;
}

original_code:
static inline int ubd_test_bit(__u64 bit, unsigned long *data)
{
 int bits, off;
 __u64 n;
 bits = sizeof(data[0]) * 8;
 n = bit / bits;
 off = bit % bits;
 return((data[n] & (1UL << off)) != 0);
}

canonical_original_code:
static inline int ubd_test_bit(unsigned long long bit, unsigned long *data)
{
 int bits; int off;
 unsigned long long n;
 bits = sizeof(data[0]) * 8;
 n = bit / bits;
 off = bit % bits;
 return((data[n] & (1UL << off)) != 0);
}

variable_types:
bit
unsigned long long

variable_types:
data
unsigned long *

variable_types: bits int

variable_types: off int

variable_types:
n
unsigned long long