decompiled_code:
__int64 __fastcall create_backing_file(const char *a1, const char *a2, char *a3)
{
int v4; // er13
int v5; // er14
size_t v6; // rbx
ssize_t v7; // rax
size_t v8; // rbx
unsigned __int64 v9; // rbp
void *v10; // r15
void *v11; // rax
unsigned __int64 i; // rbx
int v13; // eax
size_t v14; // rbp
__off64_t v15; // r12
int v16; // edi
ssize_t v17; // rax
unsigned int v18; // ebp
int v19; // eax
unsigned int v20; // ebp
int v21; // eax
void *buf; // [rsp+0h] [rbp-138h]
__int64 v24; // [rsp+8h] [rbp-130h]
int v25; // [rsp+14h] [rbp-124h]
void *s; // [rsp+18h] [rbp-120h]
unsigned int v27; // [rsp+24h] [rbp-114h] BYREF
__int64 v28; // [rsp+28h] [rbp-110h] BYREF
char *file; // [rsp+30h] [rbp-108h] BYREF
int v30; // [rsp+3Ch] [rbp-FCh] BYREF
unsigned int v31; // [rsp+40h] [rbp-F8h] BYREF
unsigned int v32; // [rsp+44h] [rbp-F4h] BYREF
unsigned __int64 v33; // [rsp+48h] [rbp-F0h] BYREF
_DWORD size[3]; // [rsp+54h] [rbp-E4h] BYREF
struct stat64 v35; // [rsp+60h] [rbp-D8h] BYREF
int fd[15]; // [rsp+FCh] [rbp-3Ch] BYREF

fd[0] = open64(a1, 0);
if ( fd[0] < 0 )
{
perror("COW file open");
exit(1);
}
if ( (unsigned int)read_cow_header(&file_reader, fd, &v32, &file, &v28, &v33, size, &v31, &v27) )
{
fwrite("Reading COW header failed\n", 1uLL, 0x1AuLL, stderr);
exit(1);
}
if ( a3 )
file = a3;
if ( stat64(file, &v35) < 0 )
{
perror("Stating backing file");
exit(1);
}
if ( v35.st_size != v33 )
{
fprintf(stderr, "Size mismatch (%ld vs %ld) of COW header vs backing file \"%s\"\n", v33, v35.st_size, file);
exit(1);
}
if ( v35.st_mtim.tv_sec != v28 )
{
fprintf(stderr, "mtime mismatch (%ld vs %ld) of COW header vs backing file \"%s\"\n", v28, v35.st_mtim.tv_sec, file);
exit(1);
}
if ( !a2 )
{
v21 = open64(file, 2);
v5 = v21;
if ( v21 >= 0 )
{
v4 = v21;
goto LABEL_11;
}
LABEL_22:
perror("Opening backing file");
exit(1);
}
v4 = open64(file, 0);
if ( v4 < 0 )
goto LABEL_22;
v5 = creat64(a2, 0x1A4u);
if ( v5 < 0 )
{
perror("Output file open");
exit(1);
}
LABEL_11:
cow_sizes(v32, v33, size[0], v31, v27, &size[1], &v30);
v6 = *(_QWORD *)&size[1];
buf = malloc(*(size_t *)&size[1]);
if ( !buf )
{
perror("Can't allocate bitmap");
exit(1);
}
v7 = pread64(fd[0], buf, v6, (int)v27);
if ( v7 != *(_QWORD *)&size[1] )
{
perror("Reading COW bitmap");
exit(1);
}
v8 = size[0];
v9 = v33 / size[0];
v25 = v9;
v10 = malloc(size[0]);
v11 = malloc(v8);
s = v11;
if ( !v10 || !v11 )
{
perror("Malloc of buffers");
exit(1);
}
memset(v11, 0, v8);
v24 = (unsigned int)v9;
if ( (_DWORD)v9 )
{
for ( i = 0LL; i != v24; ++i )
{
v14 = size[0];
v15 = i * size[0];
v16 = v4;
if ( (unsigned int)ubd_test_bit(i, (__int64)buf) )
{
v15 += v30;
v16 = fd[0];
}
if ( v5 == v4 && v16 == v4 )
continue;
v17 = pread64(v16, v10, v14, v15);
v18 = size[0];
if ( v17 != size[0] )
{
perror("Reading data");
exit(1);
}
if ( (unsigned int)(v25 - 1) > i && !memcmp(v10, s, size[0]) )
{
if ( v5 != v4 )
continue;
v19 = pread64(v4, v10, v18, i * v18);
v20 = size[0];
if ( size[0] != v19 )
{
perror("Checking backing file for zeros");
exit(1);
}
if ( !memcmp(v10, s, size[0]) )
continue;
memset(v10, 0, v20);
}
v13 = pwrite64(v5, v10, size[0], i * size[0]);
if ( size[0] != v13 )
{
perror("Writing data");
exit(1);
}
}
}
free(buf);
free(v10);
free(s);
close(fd[0]);
close(v5);
close(v4);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1, const char *a2, char *a3)
{
int v4; // er13
int v5; // er14
size_t v6; // rbx
ssize_t v7; // rax
size_t v8; // rbx
unsigned __int64 v9; // rbp
void *v10; // r15
void *v11; // rax
unsigned __int64 i; // rbx
int v13; // eax
size_t v14; // rbp
__off64_t v15; // r12
int v16; // edi
ssize_t v17; // rax
unsigned int v18; // ebp
int v19; // eax
unsigned int v20; // ebp
int v21; // eax
void *buf; // [rsp+0h] [rbp-138h]
__int64 v24; // [rsp+8h] [rbp-130h]
int v25; // [rsp+14h] [rbp-124h]
void *s; // [rsp+18h] [rbp-120h]
unsigned int v27; // [rsp+24h] [rbp-114h] BYREF
__int64 v28; // [rsp+28h] [rbp-110h] BYREF
char *file; // [rsp+30h] [rbp-108h] BYREF
int v30; // [rsp+3Ch] [rbp-FCh] BYREF
unsigned int v31; // [rsp+40h] [rbp-F8h] BYREF
unsigned int v32; // [rsp+44h] [rbp-F4h] BYREF
unsigned __int64 v33; // [rsp+48h] [rbp-F0h] BYREF
_DWORD size[3]; // [rsp+54h] [rbp-E4h] BYREF
struct stat64 v35; // [rsp+60h] [rbp-D8h] BYREF
int fd[15]; // [rsp+FCh] [rbp-3Ch] BYREF

fd[0] = open64(a1, 0);
if ( fd[0] < 0 )
{
perror("COW file open");
exit(1);
}
if ( (unsigned int)read_cow_header(&file_reader, fd, &v32, &file, &v28, &v33, size, &v31, &v27) )
{
fwrite("Reading COW header failed\n", 1uLL, 0x1AuLL, stderr);
exit(1);
}
if ( a3 )
file = a3;
if ( stat64(file, &v35) < 0 )
{
perror("Stating backing file");
exit(1);
}
if ( v35.st_size != v33 )
{
fprintf(stderr, "Size mismatch (%ld vs %ld) of COW header vs backing file \"%s\"\n", v33, v35.st_size, file);
exit(1);
}
if ( v35.st_mtim.tv_sec != v28 )
{
fprintf(stderr, "mtime mismatch (%ld vs %ld) of COW header vs backing file \"%s\"\n", v28, v35.st_mtim.tv_sec, file);
exit(1);
}
if ( !a2 )
{
v21 = open64(file, 2);
v5 = v21;
if ( v21 >= 0 )
{
v4 = v21;
goto LABEL_11;
}
LABEL_22:
perror("Opening backing file");
exit(1);
}
v4 = open64(file, 0);
if ( v4 < 0 )
goto LABEL_22;
v5 = creat64(a2, 0x1A4u);
if ( v5 < 0 )
{
perror("Output file open");
exit(1);
}
LABEL_11:
cow_sizes(v32, v33, size[0], v31, v27, &size[1], &v30);
v6 = *(_QWORD *)&size[1];
buf = malloc(*(size_t *)&size[1]);
if ( !buf )
{
perror("Can't allocate bitmap");
exit(1);
}
v7 = pread64(fd[0], buf, v6, (int)v27);
if ( v7 != *(_QWORD *)&size[1] )
{
perror("Reading COW bitmap");
exit(1);
}
v8 = size[0];
v9 = v33 / size[0];
v25 = v9;
v10 = malloc(size[0]);
v11 = malloc(v8);
s = v11;
if ( !v10 || !v11 )
{
perror("Malloc of buffers");
exit(1);
}
memset(v11, 0, v8);
v24 = (unsigned int)v9;
if ( (_DWORD)v9 )
{
for ( i = 0LL; i != v24; ++i )
{
v14 = size[0];
v15 = i * size[0];
v16 = v4;
if ( (unsigned int)func0(i, (__int64)buf) )
{
v15 += v30;
v16 = fd[0];
}
if ( v5 == v4 && v16 == v4 )
continue;
v17 = pread64(v16, v10, v14, v15);
v18 = size[0];
if ( v17 != size[0] )
{
perror("Reading data");
exit(1);
}
if ( (unsigned int)(v25 - 1) > i && !memcmp(v10, s, size[0]) )
{
if ( v5 != v4 )
continue;
v19 = pread64(v4, v10, v18, i * v18);
v20 = size[0];
if ( size[0] != v19 )
{
perror("Checking backing file for zeros");
exit(1);
}
if ( !memcmp(v10, s, size[0]) )
continue;
memset(v10, 0, v20);
}
v13 = pwrite64(v5, v10, size[0], i * size[0]);
if ( size[0] != v13 )
{
perror("Writing data");
exit(1);
}
}
}
free(buf);
free(v10);
free(s);
close(fd[0]);
close(v5);
close(v4);
return 0LL;
}

original_code:
int create_backing_file(char *in, char *out, char *actual_backing)
{
 int cow_fd, back_fd, in_fd, out_fd;
 struct stat buf;
 unsigned long *bitmap;
 unsigned long bitmap_len;
 unsigned sectorsize, sectors;
 void *sector, *zeros;
 __u64 size, offset, i;
 __u32 version, alignment;
 int data_offset;
        char *backing_file;
        time_t mtime;
        int bitmap_offset, perms, n;
 if((cow_fd = open(in, 00)) < 0){
  perror("COW file open");
  exit(1);
 }
 if(read_cow_header(file_reader, &cow_fd, &version, &backing_file,
      &mtime, &size, &sectorsize, &alignment,
      &bitmap_offset)){
  fprintf(stderr, "Reading COW header failed\n");
  exit(1);
 }
 if(actual_backing != ((void *)0))
  backing_file = actual_backing;
 if(stat(backing_file, &buf) < 0) {
  perror("Stating backing file");
  exit(1);
 }
 if(buf.st_size != size){
  fprintf(stderr,"Size mismatch (%ld vs %ld) of COW header "
   "vs backing file \"%s\"\n", (long int) size,
   (long int) buf.st_size, backing_file);
  exit(1);
 }
 if(buf.st_mtim.tv_sec != mtime) {
  fprintf(stderr,"mtime mismatch (%ld vs %ld) of COW "
   "header vs backing file \"%s\"\n", mtime, buf.st_mtim.tv_sec,
   backing_file);
  exit(1);
 }
 perms = (out != ((void *)0)) ? 00 : 02;
 if((back_fd = open(backing_file, perms)) < 0){
  perror("Opening backing file");
  exit(1);
 }
 if(out != ((void *)0)){
  if((out_fd = creat(out, 0644)) < 0){
   perror("Output file open");
   exit(1);
  }
 }
 else out_fd = back_fd;
 cow_sizes(version, size, sectorsize, alignment, bitmap_offset,
    &bitmap_len, &data_offset);
 bitmap = (unsigned long *) malloc(bitmap_len);
 if(bitmap == ((void *)0)) {
  perror("Can't allocate bitmap");
  exit(1);
 }
 if(pread(cow_fd, bitmap, bitmap_len, bitmap_offset) != bitmap_len){
  perror("Reading COW bitmap");
  exit(1);
 }
 sectors = size / sectorsize;
 sector = malloc(sectorsize);
 zeros = malloc(sectorsize);
 if((sector == ((void *)0)) || (zeros == ((void *)0))){
  perror("Malloc of buffers");
  exit(1);
 }
 memset(zeros, 0, sectorsize);
 for(i = 0; i < sectors; i++){
  offset = i * sectorsize;
  if(ubd_test_bit(i, bitmap)){
   offset += data_offset;
   in_fd = cow_fd;
  }
  else in_fd = back_fd;
  if((out_fd == back_fd) && (in_fd == back_fd))
   continue;
  if(pread(in_fd, sector, sectorsize, offset) != sectorsize){
   perror("Reading data");
   exit(1);
  }
  if((i < sectors - 1) && !memcmp(sector, zeros, sectorsize)){
   if(out_fd != back_fd)
    continue;
   n = pread(back_fd, sector, sectorsize, i * sectorsize);
   if(n != sectorsize){
    perror("Checking backing file for zeros");
    exit(1);
   }
   if(!memcmp(sector, zeros, sectorsize))
    continue;
   memset(sector, 0, sectorsize);
  }
  n = pwrite(out_fd, sector, sectorsize, i * sectorsize);
  if(n != sectorsize){
   perror("Writing data");
   exit(1);
  }
 }
 free(bitmap);
 free(sector);
 free(zeros);
 close(cow_fd);
 close(out_fd);
 close(back_fd);
 return(0);
}

canonical_original_code:
int create_backing_file(char *in, char *out, char *actual_backing)
{
 int cow_fd; int back_fd; int in_fd; int out_fd;
 struct stat buf;
 unsigned long *bitmap;
 unsigned long bitmap_len;
 unsigned int sectorsize; unsigned int sectors;
 void *sector; void *zeros;
 unsigned long long size; unsigned long long offset; unsigned long long i;
 unsigned int version; unsigned int alignment;
 int data_offset;
        char *backing_file;
        long mtime;
        int bitmap_offset; int perms; int n;
 if((cow_fd = open(in, 00)) < 0){
  perror("COW file open");
  exit(1);
 }
 if(read_cow_header(file_reader, &cow_fd, &version, &backing_file,
      &mtime, &size, &sectorsize, &alignment,
      &bitmap_offset)){
  fprintf(stderr, "Reading COW header failed\n");
  exit(1);
 }
 if(actual_backing != ((void *)0))
  backing_file = actual_backing;
 if(stat(backing_file, &buf) < 0) {
  perror("Stating backing file");
  exit(1);
 }
 if(buf.st_size != size){
  fprintf(stderr,"Size mismatch (%ld vs %ld) of COW header "
   "vs backing file \"%s\"\n", (long) size,
   (long) buf.st_size, backing_file);
  exit(1);
 }
 if(buf.st_mtim.tv_sec != mtime) {
  fprintf(stderr,"mtime mismatch (%ld vs %ld) of COW "
   "header vs backing file \"%s\"\n", mtime, buf.st_mtim.tv_sec,
   backing_file);
  exit(1);
 }
 perms = (out != ((void *)0)) ? 00 : 02;
 if((back_fd = open(backing_file, perms)) < 0){
  perror("Opening backing file");
  exit(1);
 }
 if(out != ((void *)0)){
  if((out_fd = creat(out, 0644)) < 0){
   perror("Output file open");
   exit(1);
  }
 }
 else out_fd = back_fd;
 cow_sizes(version, size, sectorsize, alignment, bitmap_offset,
    &bitmap_len, &data_offset);
 bitmap = (unsigned long *) malloc(bitmap_len);
 if(bitmap == ((void *)0)) {
  perror("Can't allocate bitmap");
  exit(1);
 }
 if(pread(cow_fd, bitmap, bitmap_len, bitmap_offset) != bitmap_len){
  perror("Reading COW bitmap");
  exit(1);
 }
 sectors = size / sectorsize;
 sector = malloc(sectorsize);
 zeros = malloc(sectorsize);
 if((sector == ((void *)0)) || (zeros == ((void *)0))){
  perror("Malloc of buffers");
  exit(1);
 }
 memset(zeros, 0, sectorsize);
 for(i = 0; i < sectors; i++){
  offset = i * sectorsize;
  if(ubd_test_bit(i, bitmap)){
   offset += data_offset;
   in_fd = cow_fd;
  }
  else in_fd = back_fd;
  if((out_fd == back_fd) && (in_fd == back_fd))
   continue;
  if(pread(in_fd, sector, sectorsize, offset) != sectorsize){
   perror("Reading data");
   exit(1);
  }
  if((i < sectors - 1) && !memcmp(sector, zeros, sectorsize)){
   if(out_fd != back_fd)
    continue;
   n = pread(back_fd, sector, sectorsize, i * sectorsize);
   if(n != sectorsize){
    perror("Checking backing file for zeros");
    exit(1);
   }
   if(!memcmp(sector, zeros, sectorsize))
    continue;
   memset(sector, 0, sectorsize);
  }
  n = pwrite(out_fd, sector, sectorsize, i * sectorsize);
  if(n != sectorsize){
   perror("Writing data");
   exit(1);
  }
 }
 free(bitmap);
 free(sector);
 free(zeros);
 close(cow_fd);
 close(out_fd);
 close(back_fd);
 return(0);
}

variable_types:
in
char *

variable_types:
out
char *

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:
bitmap
unsigned long *

variable_types:
sectorsize
unsigned int

variable_types:
sectors
unsigned int

variable_types:
sector
void *

variable_types:
zeros
void *

variable_types:
size
unsigned long long

variable_types:
offset
unsigned long long

variable_types:
i
unsigned long long

variable_types:
version
unsigned int

variable_types:
alignment
unsigned int

variable_types: mtime long

variable_types: perms int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r13
int v4; // er12
const char *v5; // rdx
const char **v6; // r14
int v7; // er12
char *v8; // rdx
const char **v10; // r14
int v11; // eax
char *v12; // rdx

v3 = *argv;
v4 = argc - 1;
if ( argc == 1 )
Usage(*argv);
v5 = argv[1];
if ( !strcmp(v5, "-d") )
{
v6 = argv + 2;
v7 = argc - 2;
if ( !strcmp(argv[2], "-b") )
{
v8 = (char *)argv[3];
v6 = argv + 4;
v7 = argc - 4;
}
else
{
v8 = 0LL;
}
if ( v7 != 1 )
Usage(v3);
create_backing_file(*v6, 0LL, v8);
}
else
{
v10 = argv + 1;
v11 = strcmp(v5, "-b");
v12 = 0LL;
if ( !v11 )
{
v12 = (char *)argv[2];
v10 = argv + 3;
v4 = argc - 3;
}
if ( v4 != 2 )
Usage(v3);
create_backing_file(*v10, v10[1], v12);
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r13
int v4; // er12
const char *v5; // rdx
const char **v6; // r14
int v7; // er12
char *v8; // rdx
const char **v10; // r14
int v11; // eax
char *v12; // rdx

v3 = *argv;
v4 = argc - 1;
if ( argc == 1 )
func1(*argv);
v5 = argv[1];
if ( !strcmp(v5, "-d") )
{
v6 = argv + 2;
v7 = argc - 2;
if ( !strcmp(argv[2], "-b") )
{
v8 = (char *)argv[3];
v6 = argv + 4;
v7 = argc - 4;
}
else
{
v8 = 0LL;
}
if ( v7 != 1 )
func1(v3);
func2(*v6, 0LL, v8);
}
else
{
v10 = argv + 1;
v11 = strcmp(v5, "-b");
v12 = 0LL;
if ( !v11 )
{
v12 = (char *)argv[2];
v10 = argv + 3;
v4 = argc - 3;
}
if ( v4 != 2 )
func1(v3);
func2(*v10, v10[1], v12);
}
return 0;
}

original_code:
int main(int argc, char **argv)
{
 char *prog = argv[0];
 char *actual_backing_file = ((void *)0);
 int in_place = 0;
 argv++;
 argc--;
 if(argc == 0)
  Usage(prog);
 if(!strcmp(argv[0], "-d")){
  in_place = 1;
  argv++;
  argc--;
 }
 if(!strcmp(argv[0], "-b")){
  actual_backing_file = argv[1];
  argv += 2;
  argc -= 2;
 }
 if(in_place){
  if(argc != 1) Usage(prog);
  create_backing_file(argv[0], ((void *)0), actual_backing_file);
 }
 else {
  if(argc != 2) Usage(prog);
  create_backing_file(argv[0], argv[1], actual_backing_file);
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
prog
char *

return_type: int


original_code:
static int calc_hash(unsigned char *src)
{
  return ((*(u_int32_t *) &src[0] % 11) ^ src[4] ^ src[5] ) % 128 ;
}

canonical_original_code:
static int calc_hash(unsigned char *src)
{
  return ((*(unsigned int *) &src[0] % 11) ^ src[4] ^ src[5] ) % 128 ;
}

variable_types:
src
unsigned char *


decompiled_code:
__int64 __fastcall for_all_hash(__int64 (__fastcall *a1)(_QWORD *, __int64), __int64 a2)
{
const char *v3; // r13
_QWORD *v4; // rbx
_QWORD *v5; // rdi
__int64 result; // rax

v3 = (const char *)&h;
do
{
v4 = *(_QWORD **)v3;
if ( *(_QWORD *)v3 )
{
do
{
v5 = v4;
v4 = (_QWORD *)*v4;
result = a1(v5, a2);
}
while ( v4 );
}
v3 += 8;
}
while ( v3 != "Hash: %d Addr: %02x:%02x:%02x:%02x:%02x:%02x to port: %s age %ld secs\n" );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 (__fastcall *a1)(_QWORD *, __int64), __int64 a2)
{
const char *v3; // r13
_QWORD *v4; // rbx
_QWORD *v5; // rdi
__int64 result; // rax

v3 = (const char *)&h;
do
{
v4 = *(_QWORD **)v3;
if ( *(_QWORD *)v3 )
{
do
{
v5 = v4;
v4 = (_QWORD *)*v4;
result = a1(v5, a2);
}
while ( v4 );
}
v3 += 8;
}
while ( v3 != "Hash: %d Addr: %02x:%02x:%02x:%02x:%02x:%02x to port: %s age %ld secs\n" );
return result;
}

original_code:
static void for_all_hash(void (*f)(struct hash_entry *, void *), void *arg)
{
  int i;
  struct hash_entry *e, *next;
  for(i = 0; i < 128; i++){
    for(e = h[i]; e; e = next){
      next = e->next;
      (*f)(e, arg);
    }
  }
}

canonical_original_code:
static void for_all_hash(void (*f)(struct hash_entry *, void *), void *arg)
{
  int i;
  struct hash_entry *e; struct hash_entry *next;
  for(i = 0; i < 128; i++){
    for(e = h[i]; e; e = next){
      next = e->next;
      (*f)(e, arg);
    }
  }
}

variable_types: void (*)(struct hash_entry { struct hash_entry *next; struct hash_entry *prev; long last_seen; void *port; unsigned char dst[6]; } *, void *)

variable_types:
arg
void *

variable_types: i int

return_type: void


decompiled_code:
void __fastcall delete_hash_entry(void *ptr)
{
int v1; // eax
_QWORD *v2; // rdx

v1 = calc_hash((__int64)ptr + 32);
v2 = (_QWORD *)*((_QWORD *)ptr + 1);
if ( v2 )
*v2 = *(_QWORD *)ptr;
if ( *(_QWORD *)ptr )
*(_QWORD *)(*(_QWORD *)ptr + 8LL) = *((_QWORD *)ptr + 1);
if ( (void *)h[v1] == ptr )
h[v1] = *(_QWORD *)ptr;
free(ptr);
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
int v1; // eax
_QWORD *v2; // rdx

v1 = func0((__int64)ptr + 32);
v2 = (_QWORD *)*((_QWORD *)ptr + 1);
if ( v2 )
*v2 = *(_QWORD *)ptr;
if ( *(_QWORD *)ptr )
*(_QWORD *)(*(_QWORD *)ptr + 8LL) = *((_QWORD *)ptr + 1);
if ( (void *)h[v1] == ptr )
h[v1] = *(_QWORD *)ptr;
free(ptr);
}

original_code:
static void delete_hash_entry(struct hash_entry *old)
{
  int k = calc_hash(old->dst);
  if(old->prev != ((void *)0)) old->prev->next = old->next;
  if(old->next != ((void *)0)) old->next->prev = old->prev;
  if(h[k] == old) h[k] = old->next;
  free(old);
}

variable_types: struct hash_entry { struct hash_entry *next; struct hash_entry *prev; long last_seen; void *port; unsigned char dst[6]; } *

variable_types: k int


gc

decompiled_code:
void __fastcall gc(_QWORD *a1, _QWORD *a2)
{
if ( a1[2] + 100LL < *a2 )
delete_hash_entry(a1);
}

canonical_decompiled_code:
void __fastcall func3(_QWORD *a1, _QWORD *a2)
{
if ( a1[2] + 100LL < *a2 )
func2(a1);
}

original_code:
static void gc(struct hash_entry *e, void *now)
{
  time_t t = *(time_t *) now;
  if(e->last_seen + 100 < t)
    delete_hash_entry(e);
}

canonical_original_code:
static void gc(struct hash_entry *e, void *now)
{
  long t = *(time_t *) now;
  if(e->last_seen + 100 < t)
    delete_hash_entry(e);
}

variable_types:
now
void *

variable_types: t long

user_defined_types: struct hash_entry { struct hash_entry *next; struct hash_entry *prev; long last_seen; void *port; unsigned char dst[6]; }


decompiled_code:
int __fastcall print_hash_entry(__int64 a1, int *a2)
{
__int64 v2; // r12
const char *v3; // rbp
unsigned int v4; // eax

v2 = *a2 - *(_QWORD *)(a1 + 16);
v3 = (const char *)(*((__int64 (__fastcall **)(_QWORD))a2 + 1))(*(_QWORD *)(a1 + 24));
v4 = calc_hash(a1 + 32);
return printf(
"Hash: %d Addr: %02x:%02x:%02x:%02x:%02x:%02x to port: %s age %ld secs\n",
v4,
*(unsigned __int8 *)(a1 + 32),
*(unsigned __int8 *)(a1 + 33),
*(unsigned __int8 *)(a1 + 34),
*(unsigned __int8 *)(a1 + 35),
*(unsigned __int8 *)(a1 + 36),
*(unsigned __int8 *)(a1 + 37),
v3,
v2);
}

original_code:
static void print_hash_entry(struct hash_entry *e, void *arg)
{
  struct printer *p = arg;
  printf("Hash: %d Addr: %02x:%02x:%02x:%02x:%02x:%02x to port: %s  "
  "age %ld secs\n", calc_hash(e->dst),
  e->dst[0], e->dst[1], e->dst[2], e->dst[3], e->dst[4], e->dst[5],
  (*p->port_id)(e->port), (int) p->now - e->last_seen);
}

variable_types: struct printer { long now; char *(*port_id)(void *); } *


decompiled_code:
int sig_alarm()
{
time_t v1; // [rsp+8h] [rbp-30h] BYREF
struct itimerval newa; // [rsp+10h] [rbp-28h] BYREF

v1 = time(0LL);
for_all_hash((__int64 (__fastcall *)(_QWORD *, __int64))gc, (__int64)&v1);
newa.it_value.tv_sec = 2LL;
newa.it_value.tv_usec = 0LL;
newa.it_interval.tv_sec = 0LL;
newa.it_interval.tv_usec = 0LL;
return setitimer(ITIMER_REAL, &newa, 0LL);
}

canonical_decompiled_code:
int func5()
{
time_t v1; // [rsp+8h] [rbp-30h] BYREF
struct itimerval newa; // [rsp+10h] [rbp-28h] BYREF

v1 = time(0LL);
func1((__int64 (__fastcall *)(_QWORD *, __int64))gc, (__int64)&v1);
newa.it_value.tv_sec = 2LL;
newa.it_value.tv_usec = 0LL;
newa.it_interval.tv_sec = 0LL;
newa.it_interval.tv_usec = 0LL;
return setitimer(ITIMER_REAL, &newa, 0LL);
}

original_code:
static void sig_alarm(int sig)
{
  struct itimerval it;
  time_t t = time(((void *)0));
  for_all_hash(&gc, &t);
  it.it_value.tv_sec = 2;
  it.it_value.tv_usec = 0 ;
  it.it_interval.tv_sec = 0;
  it.it_interval.tv_usec = 0 ;
  setitimer(ITIMER_REAL, &it, ((void *)0));
}

canonical_original_code:
static void sig_alarm(int sig)
{
  struct itimerval it;
  long t = time(((void *)0));
  for_all_hash(&gc, &t);
  it.it_value.tv_sec = 2;
  it.it_value.tv_usec = 0 ;
  it.it_interval.tv_sec = 0;
  it.it_interval.tv_usec = 0 ;
  setitimer(ITIMER_REAL, &it, ((void *)0));
}

variable_types: sig int

variable_types: struct itimerval { struct timeval { long tv_sec; long tv_usec; } it_interval; struct timeval it_value; }

user_defined_types: struct itimerval { struct timeval it_interval; struct timeval it_value; }


decompiled_code:
void __fastcall insert_into_hash(_WORD *a1, __int64 a2)
{
int v2; // ebp
_DWORD *v3; // rax
__int64 v4; // rdx

if ( !find_in_hash(a1) )
{
v2 = calc_hash((__int64)a1);
v3 = malloc(0x28uLL);
if ( v3 )
{
v3[8] = *(_DWORD *)a1;
*((_WORD *)v3 + 18) = a1[2];
v4 = h[v2];
if ( v4 )
*(_QWORD *)(v4 + 8) = v3;
*(_QWORD *)v3 = h[v2];
*((_QWORD *)v3 + 1) = 0LL;
*((_QWORD *)v3 + 3) = a2;
*((_QWORD *)v3 + 2) = 0LL;
h[v2] = (__int64)v3;
}
else
{
perror("Failed to malloc hash entry");
}
}
}

original_code:
void insert_into_hash(unsigned char *src, void *port)
{
  struct hash_entry *new;
  int k = calc_hash(src);
  new = find_in_hash(src);
  if(new != ((void *)0)) return;
  new = malloc(sizeof(*new));
  if(new == ((void *)0)){
    perror("Failed to malloc hash entry");
    return;
  }
  memcpy(&new->dst, src, 6 );
  if(h[k] != ((void *)0)) h[k]->prev = new;
  new->next = h[k];
  new->prev = ((void *)0);
  new->port = port;
  new->last_seen = 0;
  h[k] = new;
}

variable_types:
port
void *


decompiled_code:
time_t __fastcall update_entry_time(void *a1)
{
time_t result; // rax
time_t v2; // rbx

result = (time_t)find_entry(a1);
if ( result )
{
v2 = result;
result = time(0LL);
*(_QWORD *)(v2 + 16) = result;
}
return result;
}

canonical_decompiled_code:
time_t __fastcall func7(void *a1)
{
time_t result; // rax
time_t v2; // rbx

result = (time_t)find_entry(a1);
if ( result )
{
v2 = result;
result = time(0LL);
*(_QWORD *)(v2 + 16) = result;
}
return result;
}

original_code:
void update_entry_time(unsigned char *src)
{
  struct hash_entry *e;
  e = find_entry(src);
  if(e == ((void *)0)) return;
  e->last_seen = time(((void *)0));
}


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

v1 = find_entry(a1);
if ( v1 )
delete_hash_entry(v1);
}

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

v1 = find_entry(a1);
if ( v1 )
func2(v1);
}

original_code:
void delete_hash(unsigned char *dst)
{
  struct hash_entry *old = find_entry(dst);
  if(old == ((void *)0)) return;
  delete_hash_entry(old);
}

variable_types:
dst
unsigned char *


decompiled_code:
__int64 __fastcall print_hash(__int64 a1)
{
__int64 v2[3]; // [rsp+0h] [rbp-18h] BYREF

v2[0] = time(0LL);
v2[1] = a1;
return for_all_hash((__int64 (__fastcall *)(_QWORD *, __int64))print_hash_entry, (__int64)v2);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
__int64 v2[3]; // [rsp+0h] [rbp-18h] BYREF

v2[0] = time(0LL);
v2[1] = a1;
return func1((__int64 (__fastcall *)(_QWORD *, __int64))print_hash_entry, (__int64)v2);
}

original_code:
void print_hash(char *(*port_id)(void *))
{
  struct printer p = ((struct printer) { now : time(((void *)0)),
      port_id : port_id });
  for_all_hash(print_hash_entry, &p);
}

variable_types: struct printer { long now; char *(*port_id)(void *); }


decompiled_code:
void hash_init()
{
__pid_t v0; // eax
struct sigaction v1; // [rsp+0h] [rbp-A8h] BYREF

v1.sa_handler = (__sighandler_t)sig_alarm;
v1.sa_flags = 0x10000000;
if ( sigaction(14, &v1, 0LL) < 0 )
{
perror("Setting handler for SIGALRM");
}
else
{
v0 = getpid();
kill(v0, 14);
}
}

canonical_decompiled_code:
void func10()
{
__pid_t v0; // eax
struct sigaction v1; // [rsp+0h] [rbp-A8h] BYREF

v1.sa_handler = (__sighandler_t)sig_alarm;
v1.sa_flags = 0x10000000;
if ( sigaction(14, &v1, 0LL) < 0 )
{
perror("Setting handler for SIGALRM");
}
else
{
v0 = getpid();
kill(v0, 14);
}
}

original_code:
void hash_init(void)
{
  struct sigaction sa;
  sa.__sigaction_handler.sa_handler = sig_alarm;
  sa.sa_flags = 0x10000000;
  if(sigaction(14, &sa, ((void *)0)) < 0){
    perror("Setting handler for SIGALRM");
    return;
  }
  kill(getpid(), 14);
}

canonical_original_code:
void hash_init()
{
  struct sigaction sa;
  sa.__sigaction_handler.sa_handler = sig_alarm;
  sa.sa_flags = 0x10000000;
  if(sigaction(14, &sa, ((void *)0)) < 0){
    perror("Setting handler for SIGALRM");
    return;
  }
  kill(getpid(), 14);
}

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

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

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


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

if ( (unsigned int)fuse_parse_cmdline() == -1 )
result = 4294967274LL;
else
result = fuse_mount_compat22();
return result;
}

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

if ( (unsigned int)fuse_parse_cmdline() == -1 )
result = 4294967274LL;
else
result = fuse_mount_compat22();
return result;
}

original_code:
static int init_fuse(int argc, char **argv)
{
 struct fuse_args args = { argc, argv, 0 };
 char *mountpoint;
 if (fuse_parse_cmdline(&args, &mountpoint, ((void *)0), ((void *)0)) == -1)
  return -22;
        return fuse_mount_compat22(mountpoint, &args);
}

variable_types: argc int

variable_types:
argv
char **

variable_types: struct fuse_args { int argc; char **argv; int allocated; }

variable_types:
mountpoint
char *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbx
int v4; // eax
char s[20]; // [rsp+4h] [rbp-14h] BYREF

v3 = argv[1];
argv[1] = *argv;
v4 = init_fuse((unsigned int)(argc - 1), argv + 1, envp);
if ( v4 >= 0 )
{
snprintf(s, 0xCuLL, "%d", (unsigned int)v4);
execlp("uml_mconsole", "uml_mconsole", v3, "umlfs", s, 0LL);
perror("Failed to exec uml_mconsole\n");
}
return 1;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbx
int v4; // eax
char s[20]; // [rsp+4h] [rbp-14h] BYREF

v3 = argv[1];
argv[1] = *argv;
v4 = func7((unsigned int)(argc - 1), argv + 1, envp);
if ( v4 >= 0 )
{
snprintf(s, 0xCuLL, "%d", (unsigned int)v4);
execlp("uml_mconsole", "uml_mconsole", v3, "umlfs", s, 0LL);
perror("Failed to exec uml_mconsole\n");
}
return 1;
}

original_code:
int main(int argc, char **argv)
{
 char *umid, fd_arg[sizeof("1234567890\0")];
 int fd;
 umid = argv[1];
 argv[1] = argv[0];
 argv++;
 argc--;
 fd = init_fuse(argc, argv);
 if(fd < 0)
  return 1;
 snprintf(fd_arg, sizeof(fd_arg), "%d", fd);
 execlp("uml_mconsole", "uml_mconsole", umid, "umlfs", fd_arg, ((void *)0));
 perror("Failed to exec uml_mconsole\n");
 return 1;
}

canonical_original_code:
int main(int argc, char **argv)
{
 char *umid; char fd_arg[-1];
 int fd;
 umid = argv[1];
 argv[1] = argv[0];
 argv++;
 argc--;
 fd = init_fuse(argc, argv);
 if(fd < 0)
  return 1;
 snprintf(fd_arg, sizeof(fd_arg), "%d", fd);
 execlp("uml_mconsole", "uml_mconsole", umid, "umlfs", fd_arg, ((void *)0));
 perror("Failed to exec uml_mconsole\n");
 return 1;
}

variable_types:
umid
char *

variable_types: fd int


decompiled_code:
ssize_t __fastcall tuntap_up(int fd, int a2, _BYTE **a3)
{
int v3; // eax
ssize_t result; // rax
__int64 v5; // [rsp+0h] [rbp-C8h] BYREF
int v6; // [rsp+8h] [rbp-C0h]
int v7; // [rsp+Ch] [rbp-BCh]
int v8; // [rsp+10h] [rbp-B8h]
_QWORD *v9; // [rsp+20h] [rbp-A8h] BYREF
__int64 v10; // [rsp+28h] [rbp-A0h]
__int64 v11; // [rsp+30h] [rbp-98h]
__int64 v12; // [rsp+38h] [rbp-90h]
int v13; // [rsp+40h] [rbp-88h] BYREF
int v14; // [rsp+44h] [rbp-84h]
__int64 v15; // [rsp+48h] [rbp-80h]
struct msghdr message; // [rsp+50h] [rbp-78h] BYREF
_QWORD v17[7]; // [rsp+90h] [rbp-38h] BYREF

v13 = 0;
v14 = 0;
v15 = 0LL;
message.msg_control = 0LL;
message.msg_controllen = 0LL;
v9 = 0LL;
v10 = 0LL;
if ( a2 <= 0 )
{
add_output(&v13, "Too few arguments to tuntap_up\n", 0xFFFFFFFFLL);
}
else
{
v3 = do_tuntap_up(*a3, (__int64)&v13, v17);
if ( v3 > 0 )
{
v9 = v17;
v10 = 16LL;
message.msg_control = &v5;
v6 = 1;
v7 = 1;
v5 = 20LL;
message.msg_controllen = 20LL;
v8 = v3;
}
}
v11 = v15;
v12 = v14;
message.msg_name = 0LL;
message.msg_namelen = 0;
message.msg_iov = (iovec *)&v9;
message.msg_iovlen = 2LL;
message.msg_flags = 0;
result = sendmsg(fd, &message, 0);
if ( result < 0 )
{
perror("sendmsg");
exit(1);
}
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func1(int fd, int a2, _BYTE **a3)
{
int v3; // eax
ssize_t result; // rax
__int64 v5; // [rsp+0h] [rbp-C8h] BYREF
int v6; // [rsp+8h] [rbp-C0h]
int v7; // [rsp+Ch] [rbp-BCh]
int v8; // [rsp+10h] [rbp-B8h]
_QWORD *v9; // [rsp+20h] [rbp-A8h] BYREF
__int64 v10; // [rsp+28h] [rbp-A0h]
__int64 v11; // [rsp+30h] [rbp-98h]
__int64 v12; // [rsp+38h] [rbp-90h]
int v13; // [rsp+40h] [rbp-88h] BYREF
int v14; // [rsp+44h] [rbp-84h]
__int64 v15; // [rsp+48h] [rbp-80h]
struct msghdr message; // [rsp+50h] [rbp-78h] BYREF
_QWORD v17[7]; // [rsp+90h] [rbp-38h] BYREF

v13 = 0;
v14 = 0;
v15 = 0LL;
message.msg_control = 0LL;
message.msg_controllen = 0LL;
v9 = 0LL;
v10 = 0LL;
if ( a2 <= 0 )
{
add_output(&v13, "Too few arguments to tuntap_up\n", 0xFFFFFFFFLL);
}
else
{
v3 = func0(*a3, (__int64)&v13, v17);
if ( v3 > 0 )
{
v9 = v17;
v10 = 16LL;
message.msg_control = &v5;
v6 = 1;
v7 = 1;
v5 = 20LL;
message.msg_controllen = 20LL;
v8 = v3;
}
}
v11 = v15;
v12 = v14;
message.msg_name = 0LL;
message.msg_namelen = 0;
message.msg_iov = (iovec *)&v9;
message.msg_iovlen = 2LL;
message.msg_flags = 0;
result = sendmsg(fd, &message, 0);
if ( result < 0 )
{
perror("sendmsg");
exit(1);
}
return result;
}

original_code:
static void tuntap_up(int fd, int argc, char **argv)
{
  struct ifreq ifr;
  struct msghdr msg;
  struct cmsghdr *cmsg;
  struct output output = { 0, 0, ((void *)0) };
  struct iovec iov[2];
  int tap_fd, *fd_ptr;
  char anc[((((sizeof(tap_fd)) + sizeof (size_t) - 1) & (size_t) ~(sizeof (size_t) - 1)) + (((sizeof (struct cmsghdr)) + sizeof (size_t) - 1) & (size_t) ~(sizeof (size_t) - 1)))];
  char *gate_addr;
  msg.msg_control = ((void *)0);
  msg.msg_controllen = 0;
  iov[0].iov_base = ((void *)0);
  iov[0].iov_len = 0;
  if(argc < 1){
    add_output(&output, "Too few arguments to tuntap_up\n", -1);
    goto out;
  }
  gate_addr = argv[0];
  if((tap_fd = do_tuntap_up(gate_addr, &output, &ifr)) > 0){
    iov[0].iov_base = ifr.ifr_ifrn.ifrn_name;
    iov[0].iov_len = 16;
    msg.msg_control = anc;
    msg.msg_controllen = sizeof(anc);
    cmsg = ((size_t) (&msg)->msg_controllen >= sizeof (struct cmsghdr) ? (struct cmsghdr *) (&msg)->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(tap_fd)));
    msg.msg_controllen = cmsg->cmsg_len;
    fd_ptr = (int *) ((cmsg)->__cmsg_data);
    *fd_ptr = tap_fd;
  }
 out:
  iov[1].iov_base = output.buffer;
  iov[1].iov_len = output.used;
  msg.msg_name = ((void *)0);
  msg.msg_namelen = 0;
  msg.msg_iov = iov;
  msg.msg_iovlen = sizeof(iov)/sizeof(iov[0]);
  msg.msg_flags = 0;
  if(sendmsg(fd, &msg, 0) < 0){
    perror("sendmsg");
    exit(1);
  }
}

canonical_original_code:
static void tuntap_up(int fd, int argc, char **argv)
{
  struct ifreq ifr;
  struct msghdr msg;
  struct cmsghdr *cmsg;
  struct output output = { 0, 0, ((void *)0) };
  struct iovec iov[2];
  int tap_fd; int *fd_ptr;
  char anc[-1];
  char *gate_addr;
  msg.msg_control = ((void *)0);
  msg.msg_controllen = 0;
  iov[0].iov_base = ((void *)0);
  iov[0].iov_len = 0;
  if(argc < 1){
    add_output(&output, "Too few arguments to tuntap_up\n", -1);
    goto out;
  }
  gate_addr = argv[0];
  if((tap_fd = do_tuntap_up(gate_addr, &output, &ifr)) > 0){
    iov[0].iov_base = ifr.ifr_ifrn.ifrn_name;
    iov[0].iov_len = 16;
    msg.msg_control = anc;
    msg.msg_controllen = sizeof(anc);
    cmsg = ((unsigned long) (&msg)->msg_controllen >= sizeof (struct cmsghdr) ? (struct cmsghdr *) (&msg)->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(tap_fd)));
    msg.msg_controllen = cmsg->cmsg_len;
    fd_ptr = (int *) ((cmsg)->__cmsg_data);
    *fd_ptr = tap_fd;
  }
 out:
  iov[1].iov_base = output.buffer;
  iov[1].iov_len = output.used;
  msg.msg_name = ((void *)0);
  msg.msg_namelen = 0;
  msg.msg_iov = iov;
  msg.msg_iovlen = sizeof(iov)/sizeof(iov[0]);
  msg.msg_flags = 0;
  if(sendmsg(fd, &msg, 0) < 0){
    perror("sendmsg");
    exit(1);
  }
}

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

variable_types: struct 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[]; } *

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

variable_types: struct iovec { void *iov_base; unsigned long iov_len; } [2]

variable_types:
anc
char [-1]

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

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:
ssize_t __fastcall tuntap_v2(int a1, __int64 a2)
{
const char *v2; // rdx
ssize_t result; // rax
int v4; // eax

v2 = *(const char **)a2;
if ( !strcmp(*(const char **)a2, "up") )
{
v4 = atoi(*(const char **)(a2 + 16));
result = tuntap_up(v4, a1 - 3, (_BYTE **)(a2 + 24));
}
else
{
if ( strcmp(v2, "add") )
{
if ( strcmp(v2, "del") )
{
fprintf(stderr, "Bad tuntap op : '%s'\n", v2);
exit(1);
}
}
result = change_addr(*(_QWORD *)(a2 + 8), *(_QWORD *)(a2 + 16), *(_QWORD *)(a2 + 24), 0LL, 0LL);
}
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func2(int a1, __int64 a2)
{
const char *v2; // rdx
ssize_t result; // rax
int v4; // eax

v2 = *(const char **)a2;
if ( !strcmp(*(const char **)a2, "up") )
{
v4 = atoi(*(const char **)(a2 + 16));
result = func1(v4, a1 - 3, (_BYTE **)(a2 + 24));
}
else
{
if ( strcmp(v2, "add") )
{
if ( strcmp(v2, "del") )
{
fprintf(stderr, "Bad tuntap op : '%s'\n", v2);
exit(1);
}
}
result = change_addr(*(_QWORD *)(a2 + 8), *(_QWORD *)(a2 + 16), *(_QWORD *)(a2 + 24), 0LL, 0LL);
}
return result;
}

original_code:
void tuntap_v2(int argc, char **argv)
{
  char *op = argv[0];
  if(!strcmp(op, "up")) tuntap_up(atoi(argv[2]), argc - 3, argv + 3);
  else if(!strcmp(op, "add") || !strcmp(op, "del"))
    change_addr(argv[1], argv[2], argv[3], ((void *)0), ((void *)0));
  else {
    fprintf(stderr, "Bad tuntap op : '%s'\n", op);
    exit(1);
  }
}

variable_types:
op
char *


decompiled_code:
__int64 __fastcall tuntap_v3(int a1, __int64 a2)
{
const char *v2; // r9
int v4[2]; // [rsp+0h] [rbp-18h] BYREF
__int64 v5; // [rsp+8h] [rbp-10h]

v2 = *(const char **)a2;
v4[0] = 0;
v4[1] = 0;
v5 = 0LL;
if ( !strcmp(v2, "up") )
{
tuntap_up(1, a1 - 2, (_BYTE **)(a2 + 16));
}
else
{
if ( strcmp(v2, "add") && strcmp(v2, "del") )
{
fprintf(stderr, "Bad tuntap op : '%s'\n", v2);
exit(1);
}
change_addr(v2, *(_QWORD *)(a2 + 8), *(_QWORD *)(a2 + 16), 0LL, v4);
}
return write_output(1LL, v4);
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, __int64 a2)
{
const char *v2; // r9
int v4[2]; // [rsp+0h] [rbp-18h] BYREF
__int64 v5; // [rsp+8h] [rbp-10h]

v2 = *(const char **)a2;
v4[0] = 0;
v4[1] = 0;
v5 = 0LL;
if ( !strcmp(v2, "up") )
{
func1(1, a1 - 2, (_BYTE **)(a2 + 16));
}
else
{
if ( strcmp(v2, "add") && strcmp(v2, "del") )
{
fprintf(stderr, "Bad tuntap op : '%s'\n", v2);
exit(1);
}
change_addr(v2, *(_QWORD *)(a2 + 8), *(_QWORD *)(a2 + 16), 0LL, v4);
}
return write_output(1LL, v4);
}

original_code:
void tuntap_v3(int argc, char **argv)
{
  char *op = argv[0];
  struct output output = { 0, 0, ((void *)0) };
  if(!strcmp(op, "up")) tuntap_up(1, argc - 2, argv + 2);
  else if(!strcmp(op, "add") || !strcmp(op, "del"))
    change_addr(op, argv[1], argv[2], ((void *)0), &output);
  else {
    fprintf(stderr, "Bad tuntap op : '%s'\n", op);
    exit(1);
  }
  write_output(1, &output);
}

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


decompiled_code:
ssize_t __fastcall tuntap_v4(int a1, __int64 a2)
{
const char *v2; // r9
int v4[2]; // [rsp+0h] [rbp-18h] BYREF
__int64 v5; // [rsp+8h] [rbp-10h]

v4[0] = 0;
v4[1] = 0;
v5 = 0LL;
if ( a1 <= 0 )
{
add_output(v4, "uml_net : too few arguments to tuntap_v4\n", 0xFFFFFFFFLL);
write_output(1LL, v4);
exit(1);
}
v2 = *(const char **)a2;
if ( !strcmp(*(const char **)a2, "up") )
return tuntap_up(1, a1 - 1, (_BYTE **)(a2 + 8));
if ( strcmp(v2, "add") && strcmp(v2, "del") )
{
fprintf(stderr, "Bad tuntap op : '%s'\n", v2);
exit(1);
}
if ( a1 > 3 )
change_addr(v2, *(_QWORD *)(a2 + 8), *(_QWORD *)(a2 + 16), *(_QWORD *)(a2 + 24), v4);
else
add_output(v4, "uml_net : too few arguments to tuntap change_addr\n", 0xFFFFFFFFLL);
return write_output(1LL, v4);
}

canonical_decompiled_code:
ssize_t __fastcall func4(int a1, __int64 a2)
{
const char *v2; // r9
int v4[2]; // [rsp+0h] [rbp-18h] BYREF
__int64 v5; // [rsp+8h] [rbp-10h]

v4[0] = 0;
v4[1] = 0;
v5 = 0LL;
if ( a1 <= 0 )
{
add_output(v4, "uml_net : too few arguments to tuntap_v4\n", 0xFFFFFFFFLL);
write_output(1LL, v4);
exit(1);
}
v2 = *(const char **)a2;
if ( !strcmp(*(const char **)a2, "up") )
return func1(1, a1 - 1, (_BYTE **)(a2 + 8));
if ( strcmp(v2, "add") && strcmp(v2, "del") )
{
fprintf(stderr, "Bad tuntap op : '%s'\n", v2);
exit(1);
}
if ( a1 > 3 )
change_addr(v2, *(_QWORD *)(a2 + 8), *(_QWORD *)(a2 + 16), *(_QWORD *)(a2 + 24), v4);
else
add_output(v4, "uml_net : too few arguments to tuntap change_addr\n", 0xFFFFFFFFLL);
return write_output(1LL, v4);
}

original_code:
void tuntap_v4(int argc, char **argv)
{
  char *op;
  struct output output = { 0, 0, ((void *)0) };
  if(argc < 1){
    add_output(&output, "uml_net : too few arguments to tuntap_v4\n", -1);
    write_output(1, &output);
    exit(1);
  }
  op = argv[0];
  if(!strcmp(op, "up")) tuntap_up(1, argc - 1, argv + 1);
  else if(!strcmp(op, "add") || !strcmp(op, "del")){
    if(argc < 4)
      add_output(&output, "uml_net : too few arguments to tuntap "
   "change_addr\n", -1);
    else change_addr(op, argv[1], argv[2], argv[3], &output);
    write_output(1, &output);
  }
  else {
    fprintf(stderr, "Bad tuntap op : '%s'\n", op);
    exit(1);
  }
}


decompiled_code:
void __fastcall send_tap(int a1, const void *a2, int a3)
{
if ( a3 != (unsigned int)write(a1, a2, a3) && *_errno_location() != 11 )
perror("send_tap");
}

canonical_decompiled_code:
void __fastcall func0(int a1, const void *a2, int a3)
{
if ( a3 != (unsigned int)write(a1, a2, a3) && *_errno_location() != 11 )
perror("send_tap");
}

original_code:
static void send_tap(int fd, void *packet, int len, void *unused)
{
  int n;
  n = write(fd, packet, len);
  if(n != len){
    if((*__errno_location ()) != 11) perror("send_tap");
  }
}

variable_types:
packet
void *

variable_types: len int

variable_types:
unused
void *

variable_types: n int


decompiled_code:
__int64 __fastcall open_tap(char *src)
{
int v1; // eax
unsigned int v2; // ebx
unsigned int v3; // eax
char v5[8]; // [rsp+0h] [rbp-48h] BYREF
__int64 v6; // [rsp+8h] [rbp-40h]
__int64 v7; // [rsp+10h] [rbp-38h]
__int64 v8; // [rsp+18h] [rbp-30h]
__int64 v9; // [rsp+20h] [rbp-28h]

v1 = open("/dev/net/tun", 2);
if ( v1 < 0 )
{
perror("Failed to open /dev/net/tun");
v2 = -1;
}
else
{
v2 = v1;
v6 = 0LL;
v7 = 4098LL;
v8 = 0LL;
v9 = 0LL;
strncpy(v5, src, 0xFuLL);
if ( ioctl(v2, 0x400454CAuLL, v5) < 0 )
{
perror("TUNSETIFF failed");
close(v2);
v2 = -1;
}
else
{
v3 = setup_port(v2, send_tap, 0LL, 0LL);
if ( v3 )
v2 = v3;
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *src)
{
int v1; // eax
unsigned int v2; // ebx
unsigned int v3; // eax
char v5[8]; // [rsp+0h] [rbp-48h] BYREF
__int64 v6; // [rsp+8h] [rbp-40h]
__int64 v7; // [rsp+10h] [rbp-38h]
__int64 v8; // [rsp+18h] [rbp-30h]
__int64 v9; // [rsp+20h] [rbp-28h]

v1 = open("/dev/net/tun", 2);
if ( v1 < 0 )
{
perror("Failed to open /dev/net/tun");
v2 = -1;
}
else
{
v2 = v1;
v6 = 0LL;
v7 = 4098LL;
v8 = 0LL;
v9 = 0LL;
strncpy(v5, src, 0xFuLL);
if ( ioctl(v2, 0x400454CAuLL, v5) < 0 )
{
perror("TUNSETIFF failed");
close(v2);
v2 = -1;
}
else
{
v3 = setup_port(v2, send_tap, 0LL, 0LL);
if ( v3 )
v2 = v3;
}
}
return v2;
}

original_code:
int open_tap(char *dev)
{
  struct ifreq ifr;
  int fd, err;
  if((fd = open("/dev/net/tun", 02)) < 0){
    perror("Failed to open /dev/net/tun");
    return(-1);
  }
  memset(&ifr, 0, sizeof(ifr));
  ifr.ifr_ifru.ifru_flags = 0x0002 | 0x1000;
  strncpy(ifr.ifr_ifrn.ifrn_name, dev, sizeof(ifr.ifr_ifrn.ifrn_name) - 1);
  if(ioctl(fd, (((1U) << (((0 +8)+8)+14)) | ((('T')) << (0 +8)) | (((202)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), (void *) &ifr) < 0){
    perror("TUNSETIFF failed");
    close(fd);
    return(-1);
  }
  err = setup_port(fd, send_tap, ((void *)0), 0);
  if(err) return(err);
  return(fd);
}

canonical_original_code:
int open_tap(char *dev)
{
  struct ifreq ifr;
  int fd; int err;
  if((fd = open("/dev/net/tun", 02)) < 0){
    perror("Failed to open /dev/net/tun");
    return(-1);
  }
  memset(&ifr, 0, sizeof(ifr));
  ifr.ifr_ifru.ifru_flags = 0x0002 | 0x1000;
  strncpy(ifr.ifr_ifrn.ifrn_name, dev, sizeof(ifr.ifr_ifrn.ifrn_name) - 1);
  if(ioctl(fd, (((1U) << (((0 +8)+8)+14)) | ((('T')) << (0 +8)) | (((202)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), (void *) &ifr) < 0){
    perror("TUNSETIFF failed");
    close(fd);
    return(-1);
  }
  err = setup_port(fd, send_tap, ((void *)0), 0);
  if(err) return(err);
  return(fd);
}

variable_types:
dev
char *

variable_types: err int

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

user_defined_types: struct ifmap { unsigned long mem_start; unsigned long mem_end; unsigned short base_addr; unsigned char irq; unsigned char dma; unsigned char port; }


handler

decompiled_code:
void handler()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
static void handler(int sig)
{
}

canonical_original_code:
static void handler(int sig)
{
}

variable_types: sig int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r12
const char *v4; // r13
unsigned int v5; // eax
unsigned int v6; // er14
int v7; // er12
int v8; // eax
void **v9; // rdx
void (__fastcall *v10)(_QWORD, const char **); // rax
char *endptr; // [rsp+8h] [rbp-D0h] BYREF
struct sigaction v13; // [rsp+10h] [rbp-C8h] BYREF

v3 = argv[1];
v4 = argv[2];
if ( sigaction(17, 0LL, &v13) < 0 )
{
perror("sigaction");
exit(1);
}
v13.sa_handler = (__sighandler_t)handler;
v13.sa_flags = v13.sa_flags & 0xFFFFFFFD | 0x10000000;
if ( sigaction(17, &v13, 0LL) < 0 )
{
perror("sigaction");
exit(1);
}
if ( argc <= 2 )
{
fwrite(
"uml_net : bad argument list - if you're running uml_net by\n"
"hand, don't bother. uml_net is run automatically by UML when\n"
"necessary.\n",
1uLL,
0x84uLL,
stderr);
exit(1);
}
setenv("PATH", "/bin:/usr/bin:/sbin:/usr/sbin", 1);
v5 = strtoul(v3, &endptr, 0);
if ( endptr == v3 )
{
v4 = v3;
v6 = 0;
v7 = 2;
}
else
{
v6 = v5;
if ( v5 > 4 )
{
fprintf(stderr, "Version mismatch - requested version %d, uml_net supports up to version %d\n", v5, 4LL);
exit(1);
}
v7 = 3;
}
if ( !strcmp(v4, "ethertap") )
{
v9 = &ethertap_handlers;
}
else if ( !strcmp(v4, "slip") )
{
v9 = &slip_handlers;
}
else if ( !strcmp(v4, "tuntap") )
{
v9 = (void **)&tuntap_handlers;
}
else if ( !strcmp(v4, "add") )
{
v9 = (void **)&add_handlers;
}
else
{
v8 = strcmp(v4, "del");
v9 = (void **)&del_handlers;
if ( v8 )
{
printf("Unknown transport : '%s'\n", v4);
exit(1);
}
}
v10 = (void (__fastcall *)(_QWORD, const char **))v9[v6];
if ( !v10 )
{
printf("No version #%d handler for '%s'\n", v6, v4);
exit(1);
}
v10((unsigned int)(argc - v7), &argv[v7]);
return 0;
}

original_code:
int main(int argc, char **argv)
{
  char *version = argv[1];
  char *transport = argv[2];
  void (**handlers)(int, char **);
  struct sigaction sa;
  char *out;
  int n = 3;
  unsigned int v;
  if(sigaction(17, ((void *)0), &sa) < 0){
    perror("sigaction");
    exit(1);
  }
  sa.__sigaction_handler.sa_handler = handler;
  sa.sa_flags &= ~2;
  sa.sa_flags |= 0x10000000;
  if(sigaction(17, &sa, ((void *)0)) < 0){
    perror("sigaction");
    exit(1);
  }
  if(argc < 3){
    fprintf(stderr,
     "uml_net : bad argument list - if you're running uml_net by\n"
     "hand, don't bother.  uml_net is run automatically by UML when\n"
     "necessary.\n");
    exit(1);
  }
  setenv("PATH", "/bin:/usr/bin:/sbin:/usr/sbin", 1);
  v = strtoul(version, &out, 0);
  if(out != version){
    if(v > (4)){
      fprintf(stderr, "Version mismatch - requested version %d, uml_net "
       "supports up to version %d\n", v, (4));
      exit(1);
    }
  }
  else {
    v = 0;
    transport = version;
    n = 2;
  }
  if(!strcmp(transport, "ethertap")) handlers = ethertap_handlers;
  else if(!strcmp(transport, "slip")) handlers = slip_handlers;
  else if(!strcmp(transport, "tuntap")) handlers = tuntap_handlers;
  else if(!strcmp(transport, "add")) handlers = add_handlers;
  else if(!strcmp(transport, "del")) handlers = del_handlers;
  else {
    printf("Unknown transport : '%s'\n", transport);
    exit(1);
  }
  if(handlers[v] != ((void *)0)) (*handlers[v])(argc - n, &argv[n]);
  else {
    printf("No version #%d handler for '%s'\n", v, transport);
    exit(1);
  }
  return(0);
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
version
char *

variable_types:
transport
char *

variable_types:
handlers
void (**)(int, char **)

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

variable_types:
out
char *

variable_types:
v
unsigned int


notify

decompiled_code:
void __noreturn notify()
{
int v0; // eax
int v1; // ebx
__int64 v2; // [rsp+0h] [rbp-298h] BYREF
int v3; // [rsp+8h] [rbp-290h]
int v4; // [rsp+Ch] [rbp-28Ch]
int v5; // [rsp+10h] [rbp-288h]
struct sockaddr addr; // [rsp+220h] [rbp-78h] BYREF

v0 = socket(1, 2, 0);
if ( v0 >= 0 )
{
v1 = v0;
addr.sa_family = 1;
strcpy(addr.sa_data, sock_name);
v2 = 3405691582LL;
v3 = 2;
v4 = 2;
v5 = 0;
if ( (int)sendto(v1, &v2, 0x18uLL, 0, &addr, 0x6Eu) < 0 )
perror("sendto");
exit(1);
}
perror("socket");
exit(1);
}

canonical_decompiled_code:
void __noreturn func7()
{
int v0; // eax
int v1; // ebx
__int64 v2; // [rsp+0h] [rbp-298h] BYREF
int v3; // [rsp+8h] [rbp-290h]
int v4; // [rsp+Ch] [rbp-28Ch]
int v5; // [rsp+10h] [rbp-288h]
struct sockaddr addr; // [rsp+220h] [rbp-78h] BYREF

v0 = socket(1, 2, 0);
if ( v0 >= 0 )
{
v1 = v0;
addr.sa_family = 1;
strcpy(addr.sa_data, sock_name);
v2 = 3405691582LL;
v3 = 2;
v4 = 2;
v5 = 0;
if ( (int)sendto(v1, &v2, 0x18uLL, 0, &addr, 0x6Eu) < 0 )
perror("sendto");
exit(1);
}
perror("socket");
exit(1);
}

original_code:
static void notify(int sig)
{
  struct sockaddr_un target;
  struct mconsole_notify packet;
  int sock, len, n;
  sock = socket(1, SOCK_DGRAM, 0);
  if(sock < 0){
    perror("socket");
    exit(1);
  }
  target.sun_family = 1;
  strcpy(target.sun_path, sock_name);
  packet.magic = (0xcafebabe);
  packet.version = 2;
  packet.type = MCONSOLE_HANG;
  packet.len = 0;
  len = sizeof(packet) + packet.len - sizeof(packet.data);
  n = sendto(sock, &packet, len, 0, (struct sockaddr *) &target,
      sizeof(target));
  if(n < 0)
    perror("sendto");
  exit(1);
}

canonical_original_code:
static void notify(int sig)
{
  struct sockaddr_un target;
  struct mconsole_notify packet;
  int sock; int len; int n;
  sock = socket(1, SOCK_DGRAM, 0);
  if(sock < 0){
    perror("socket");
    exit(1);
  }
  target.sun_family = 1;
  strcpy(target.sun_path, sock_name);
  packet.magic = (0xcafebabe);
  packet.version = 2;
  packet.type = MCONSOLE_HANG;
  packet.len = 0;
  len = sizeof(packet) + packet.len - sizeof(packet.data);
  n = sendto(sock, &packet, len, 0, (struct sockaddr *) &target,
      sizeof(target));
  if(n < 0)
    perror("sendto");
  exit(1);
}

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

variable_types: struct mconsole_notify { unsigned long magic; int version; enum { MCONSOLE_SOCKET=0, MCONSOLE_PANIC=1, MCONSOLE_HANG=2 } type; int len; char data[-1]; }

variable_types: sock int


decompiled_code:
void __noreturn kill_tracer()
{
kill(tracing_pid, 2);
sleep(1u);
kill(tracing_pid, 2);
sleep(1u);
kill(tracing_pid, 9);
exit(1);
}

canonical_decompiled_code:
void __noreturn func8()
{
kill(tracing_pid, 2);
sleep(1u);
kill(tracing_pid, 2);
sleep(1u);
kill(tracing_pid, 9);
exit(1);
}

original_code:
static void kill_tracer(int sig)
{
  kill(tracing_pid, 2);
  sleep(1);
  kill(tracing_pid, 2);
  sleep(1);
  kill(tracing_pid, 9);
  exit(1);
}


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
const char *v3; // rdx
void (__noreturn *v4)(); // rsi
__pid_t v5; // eax
int v6; // eax
char *v7; // [rsp+0h] [rbp-18h] BYREF
char buf[9]; // [rsp+Fh] [rbp-9h] BYREF

if ( argc > 2 )
{
v3 = argv[1];
if ( !strcmp(v3, "-pid") )
{
v5 = strtol(argv[2], &v7, 0);
tracing_pid = v5;
if ( *v7 )
exit(1);
v4 = kill_tracer;
if ( kill(v5, 0) )
exit(1);
}
else
{
if ( strcmp(v3, "-mconsole") )
exit(1);
sock_name = (char *)argv[2];
v4 = notify;
}
if ( signal(14, (__sighandler_t)v4) )
exit(1);
if ( write(1, buf, 1uLL) == 1 )
{
while ( 1 )
{
alarm(0x3Cu);
v6 = read(0, buf, 1uLL);
if ( !v6 )
break;
if ( v6 < 0 )
exit(1);
}
exit(0);
}
exit(1);
}
exit(1);
}

original_code:
int main(int argc, char **argv)
{
  void (*handler)(int);
  int n;
  char c, *end;
  if(argc < 3) exit(1);
  if(!strcmp(argv[1], "-pid")){
    tracing_pid = strtol(argv[2], &end, 0);
    if(*end != '\0') exit(1);
    if(kill(tracing_pid, 0)) exit(1);
    handler = kill_tracer;
  }
  else if(!strcmp(argv[1], "-mconsole")){
    sock_name = argv[2];
    handler = notify;
  }
  else exit(1);
  if(signal(14, handler)) exit(1);
  if(write(1, &c, sizeof(c)) != sizeof(c)) exit(1);
  while(1){
    alarm(60);
    n = read(0, &c, sizeof(c));
    if(n == 0) exit(0);
    else if(n < 0) exit(1);
  }
}

canonical_original_code:
int main(int argc, char **argv)
{
  void (*handler)(int);
  int n;
  char c; char *end;
  if(argc < 3) exit(1);
  if(!strcmp(argv[1], "-pid")){
    tracing_pid = strtol(argv[2], &end, 0);
    if(*end != '\0') exit(1);
    if(kill(tracing_pid, 0)) exit(1);
    handler = kill_tracer;
  }
  else if(!strcmp(argv[1], "-mconsole")){
    sock_name = argv[2];
    handler = notify;
  }
  else exit(1);
  if(signal(14, handler)) exit(1);
  if(write(1, &c, sizeof(c)) != sizeof(c)) exit(1);
  while(1){
    alarm(60);
    n = read(0, &c, sizeof(c));
    if(n == 0) exit(0);
    else if(n < 0) exit(1);
  }
}

variable_types:
handler
void (*)(int)

variable_types: c char

variable_types:
end
char *


usage

decompiled_code:
void __fastcall __noreturn usage(const char *a1)
{
fprintf(stderr, "%s usage: \n", a1);
fprintf(stderr, "\t%s [-f] <COW file> <backing file>\n", a1);
fwrite("\t-f forces overwrite of an existing COW file\n", 1uLL, 0x2DuLL, stderr);
exit(2);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(const char *a1)
{
fprintf(stderr, "%s usage: \n", a1);
fprintf(stderr, "\t%s [-f] <COW file> <backing file>\n", a1);
fwrite("\t-f forces overwrite of an existing COW file\n", 1uLL, 0x2DuLL, stderr);
exit(2);
}

original_code:
void usage(const char progname[])
{
 fprintf(stderr, "%s usage: \n", progname);
 fprintf(stderr, "\t%s [-f] <COW file> <backing file>\n", progname);
 fprintf(stderr, "\t-f forces overwrite of an existing COW file\n");
 exit(2);
}

canonical_original_code:
void usage(char progname[])
{
 fprintf(stderr, "%s usage: \n", progname);
 fprintf(stderr, "\t%s [-f] <COW file> <backing file>\n", progname);
 fprintf(stderr, "\t-f forces overwrite of an existing COW file\n");
 exit(2);
}

variable_types:
progname
char []


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r9
__int64 v4; // r8
bool v5; // cf
bool v6; // zf
const char *v9; // rdi
const char *v10; // rsi
__int64 v11; // rcx
const char **v12; // rax
int v13; // esi
const char *v14; // rbp
const char *v15; // r12
unsigned int v16; // ebx
unsigned int v17; // eax
int v18; // ebx
char v20[4]; // [rsp+Ch] [rbp-2Ch] BYREF
char v21[12]; // [rsp+10h] [rbp-28h] BYREF
char v22[28]; // [rsp+1Ch] [rbp-1Ch] BYREF

v3 = *argv;
v4 = (unsigned int)(argc - 1);
v5 = 0;
v6 = argc == 1;
if ( argc - 1 <= 0 )
usage(*argv);
v9 = argv[1];
v10 = "-f";
v11 = 3LL;
do
{
if ( !v11 )
break;
v5 = *v10 < (unsigned int)*v9;
v6 = *v10++ == *v9++;
--v11;
}
while ( v6 );
LOBYTE(v11) = (!v5 && !v6) - v5;
if ( (_BYTE)v11 )
{
v12 = argv + 1;
v13 = 194;
}
else
{
v12 = argv + 2;
v4 = (unsigned int)(argc - 2);
v13 = 66;
}
if ( (int)v4 <= 1 )
usage(v3);
v14 = *v12;
v15 = v12[1];
v16 = open64(*v12, v13, 420LL, v11, v4, v3);
if ( v16 == -1 )
{
perror("open COW file");
exit(1);
}
v17 = sysconf(30);
v18 = init_cow_file(v16, v14, v15, 512LL, v17, v22, v21, v20);
if ( v18 )
{
*_errno_location() = -v18;
perror("write_cow_header");
exit(1);
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r9
__int64 v4; // r8
bool v5; // cf
bool v6; // zf
const char *v9; // rdi
const char *v10; // rsi
__int64 v11; // rcx
const char **v12; // rax
int v13; // esi
const char *v14; // rbp
const char *v15; // r12
unsigned int v16; // ebx
unsigned int v17; // eax
int v18; // ebx
char v20[4]; // [rsp+Ch] [rbp-2Ch] BYREF
char v21[12]; // [rsp+10h] [rbp-28h] BYREF
char v22[28]; // [rsp+1Ch] [rbp-1Ch] BYREF

v3 = *argv;
v4 = (unsigned int)(argc - 1);
v5 = 0;
v6 = argc == 1;
if ( argc - 1 <= 0 )
func0(*argv);
v9 = argv[1];
v10 = "-f";
v11 = 3LL;
do
{
if ( !v11 )
break;
v5 = *v10 < (unsigned int)*v9;
v6 = *v10++ == *v9++;
--v11;
}
while ( v6 );
LOBYTE(v11) = (!v5 && !v6) - v5;
if ( (_BYTE)v11 )
{
v12 = argv + 1;
v13 = 194;
}
else
{
v12 = argv + 2;
v4 = (unsigned int)(argc - 2);
v13 = 66;
}
if ( (int)v4 <= 1 )
func0(v3);
v14 = *v12;
v15 = v12[1];
v16 = open64(*v12, v13, 420LL, v11, v4, v3);
if ( v16 == -1 )
{
perror("open COW file");
exit(1);
}
v17 = sysconf(30);
v18 = init_cow_file(v16, v14, v15, 512LL, v17, v22, v21, v20);
if ( v18 )
{
*_errno_location() = -v18;
perror("write_cow_header");
exit(1);
}
return 0;
}

original_code:
int main(int argc, char *argv[])
{
  int fd;
  int err;
  char *cow_file;
  char *backing_file;
  int bitmap_offset_out;
  unsigned long bitmap_len_out;
  int data_offset_out;
  int flags;
  mode_t mode;
  char *progname;
  progname = argv[0];
  argv++;
  argc--;
  if(argc < 1)
        usage(progname);
  flags = 02 | 0100 | 0;
  mode = 0400 | 0200 | (0400 >> 3) | ((0400 >> 3) >> 3);
  if(strcmp("-f", argv[0]) != 0){
 flags |= 0200;
  }
  else {
   argv++;
   argc--;
  }
  if (argc < 2)
 usage(progname);
  cow_file = argv[0];
  backing_file = argv[1];
  if((fd = open(cow_file, flags, mode)) == -1) {
 perror("open COW file");
 exit(1);
  }
  if((err = init_cow_file(fd, cow_file, backing_file, 512, sysconf(_SC_PAGESIZE),
     &bitmap_offset_out, &bitmap_len_out, &data_offset_out))){
 (*__errno_location ()) = -err;
 perror("write_cow_header");
 exit(1);
  }
  return (0);
}

canonical_original_code:
int main(int argc, char *argv[])
{
  int fd;
  int err;
  char *cow_file;
  char *backing_file;
  int bitmap_offset_out;
  unsigned long bitmap_len_out;
  int data_offset_out;
  int flags;
  unsigned int mode;
  char *progname;
  progname = argv[0];
  argv++;
  argc--;
  if(argc < 1)
        usage(progname);
  flags = 02 | 0100 | 0;
  mode = 0400 | 0200 | (0400 >> 3) | ((0400 >> 3) >> 3);
  if(strcmp("-f", argv[0]) != 0){
 flags |= 0200;
  }
  else {
   argv++;
   argc--;
  }
  if (argc < 2)
 usage(progname);
  cow_file = argv[0];
  backing_file = argv[1];
  if((fd = open(cow_file, flags, mode)) == -1) {
 perror("open COW file");
 exit(1);
  }
  if((err = init_cow_file(fd, cow_file, backing_file, 512, sysconf(_SC_PAGESIZE),
     &bitmap_offset_out, &bitmap_len_out, &data_offset_out))){
 (*__errno_location ()) = -err;
 perror("write_cow_header");
 exit(1);
  }
  return (0);
}

variable_types:
argv
char *[]

variable_types: fd int

variable_types: err int

variable_types: flags int

variable_types:
mode
unsigned int

variable_types:
progname
char *


original_code:
static unsigned int read32(unsigned char *in) {
 unsigned char b[4];
 unsigned int n;
 memcpy(b, in, 4);
 n = (unsigned int) b[3] << 0;
 n |= (unsigned int) b[2] << 8;
 n |= (unsigned int) b[1] << 16;
 n |= (unsigned int) b[0] << 24;
 return n;
}

variable_types:
in
unsigned char *

variable_types:
b
unsigned char [4]

variable_types:
n
unsigned int

return_type: unsigned int


decompiled_code:
int __fastcall ioctl_handle_string(int a1, __int64 a2)
{
return ioctl(a1, 0xC0086801uLL, a2);
}

canonical_decompiled_code:
int __fastcall func7(int a1, __int64 a2)
{
return ioctl(a1, 0xC0086801uLL, a2);
}

original_code:
static int
ioctl_handle_string(int fd,
  struct string_plugin_call_params *params) {
 return ioctl(fd, (((2U|1U) << (((0 +8)+8)+14)) | (((('h'))) << (0 +8)) | (((0x01)) << 0) | ((((sizeof(struct string_plugin_call_params *)))) << ((0 +8)+8))), params);
}

variable_types: struct string_plugin_call_params { unsigned int id; char *string; char *buffer; unsigned int bufsize; } *


repo: xlatb/ministompd

variable_types:
out
unsigned char *

variable_types:
inlen
unsigned long long

variable_types:
k
unsigned char *

variable_types:
b
unsigned long

variable_types:
m
unsigned long

variable_types:
end
unsigned char *

variable_types: left int


decompiled_code:
__int64 printbuf_setup()
{
__int64 i; // rbx
__int64 v1; // rbp
__int64 result; // rax

printbufs = xmalloc(96LL);
for ( i = 0LL; i != 96; i += 16LL )
{
v1 = printbufs + i;
*(_BYTE *)(printbufs + i) = 0;
result = bytestring_new(2048LL);
*(_QWORD *)(v1 + 8) = result;
}
return result;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 i; // rbx
__int64 v1; // rbp
__int64 result; // rax

printbufs = xmalloc(96LL);
for ( i = 0LL; i != 96; i += 16LL )
{
v1 = printbufs + i;
*(_BYTE *)(printbufs + i) = 0;
result = bytestring_new(2048LL);
*(_QWORD *)(v1 + 8) = result;
}
return result;
}

original_code:
static void printbuf_setup(void)
{
  printbufs = xmalloc(sizeof(struct printbuf) * 6);
  for (int i = 0; i < 6; i++)
  {
    printbufs[i].acquired = 0;
    printbufs[i].bs = bytestring_new(2048);
  }
}

canonical_original_code:
static void printbuf_setup()
{
  printbufs = xmalloc(sizeof(struct printbuf) * 6);
  for (int i = 0; i < 6; i++)
  {
    printbufs[i].acquired = 0;
    printbufs[i].bs = bytestring_new(2048);
  }
}

variable_types: i int

user_defined_types: struct printbuf { _Bool acquired; struct bytestring *bs; }

user_defined_types: struct bytestring { unsigned long size; unsigned long length; unsigned char *data; }


decompiled_code:
__int64 printbuf_acquire()
{
__int64 v0; // rax
__int64 v1; // rbx

if ( !printbufs )
printbuf_setup();
v0 = printbufs;
while ( 1 )
{
v1 = v0;
if ( !*(_BYTE *)v0 )
break;
v0 += 16LL;
if ( v0 == printbufs + 96 )
abort();
}
*(_BYTE *)v0 = 1;
bytestring_truncate(*(_QWORD *)(v0 + 8), 0LL);
return *(_QWORD *)(v1 + 8);
}

canonical_decompiled_code:
__int64 func2()
{
__int64 v0; // rax
__int64 v1; // rbx

if ( !printbufs )
func1();
v0 = printbufs;
while ( 1 )
{
v1 = v0;
if ( !*(_BYTE *)v0 )
break;
v0 += 16LL;
if ( v0 == printbufs + 96 )
abort();
}
*(_BYTE *)v0 = 1;
func0(*(_QWORD *)(v0 + 8), 0LL);
return *(_QWORD *)(v1 + 8);
}

original_code:
bytestring *printbuf_acquire(void)
{
  if (printbufs == ((void *)0))
    printbuf_setup();
  for (int i = 0; i < 6; i++)
  {
    if (printbufs[i].acquired == 0)
    {
      printbufs[i].acquired = 1;
      bytestring_truncate(printbufs[i].bs, 0);
      return printbufs[i].bs;
    }
  }
  abort();
}

canonical_original_code:
struct bytestring *printbuf_acquire()
{
  if (printbufs == ((void *)0))
    printbuf_setup();
  for (int i = 0; i < 6; i++)
  {
    if (printbufs[i].acquired == 0)
    {
      printbufs[i].acquired = 1;
      bytestring_truncate(printbufs[i].bs, 0);
      return printbufs[i].bs;
    }
  }
  abort();
}

return_type: struct bytestring { unsigned long size; unsigned long length; unsigned char *data; } *


decompiled_code:
void __fastcall log_set_level(int a1)
{
level = a1;
}

canonical_decompiled_code:
void __fastcall func0(int a1)
{
level = a1;
}

original_code:
void log_set_level(log_level lvl)
{
  level = lvl;
}

canonical_original_code:
void log_set_level(enum log_level lvl)
{
  level = lvl;
}

variable_types: enum log_level { LOG_LEVEL_NONE=0, LOG_LEVEL_ERROR=1, LOG_LEVEL_INFO=2, LOG_LEVEL_VERBOSE=3, LOG_LEVEL_DEBUG=4 }


decompiled_code:
bool __fastcall log_check_level(unsigned int a1)
{
return level >= a1;
}

canonical_decompiled_code:
bool __fastcall func1(unsigned int a1)
{
return level >= a1;
}

original_code:
_Bool log_check_level(log_level lvl)
{
  return (lvl <= level);
}

canonical_original_code:
_Bool log_check_level(enum log_level lvl)
{
  return (lvl <= level);
}

user_defined_types: enum log_level { LOG_LEVEL_NONE=0, LOG_LEVEL_ERROR=1, LOG_LEVEL_INFO=2, LOG_LEVEL_VERBOSE=3, LOG_LEVEL_DEBUG=4 }


decompiled_code:
__int64 log_printf(unsigned int a1, const char *a2, ...)
{
__int64 result; // rax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

result = 0LL;
if ( level >= a1 )
{
va_start(arg, a2);
vdprintf(2, a2, arg);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 func2(unsigned int a1, const char *a2, ...)
{
__int64 result; // rax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

result = 0LL;
if ( level >= a1 )
{
va_start(arg, a2);
vdprintf(2, a2, arg);
result = 1LL;
}
return result;
}

original_code:
_Bool log_printf(log_level lvl, const char *fmt, ...)
{
  va_list args;
  if (lvl > level)
    return 0;
  __builtin_va_start(args,fmt);
  vdprintf(fd, fmt, args);
  __builtin_va_end(args);
  return 1;
}

canonical_original_code:
_Bool log_printf(enum log_level lvl, char *fmt, ...)
{
  __builtin_va_list args;
  if (lvl > level)
    return 0;
  __builtin_va_start(args,fmt);
  vdprintf(fd, fmt, args);
  __builtin_va_end(args);
  return 1;
}

variable_types:
fmt
char *


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

v2 = _errno_location();
v3 = strerror(*v2);
return log_printf(a1, "%s: %s\n", a2, v3);
}

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

v2 = _errno_location();
v3 = strerror(*v2);
return func2(a1, "%s: %s\n", a2, v3);
}

original_code:
_Bool log_perror(log_level lvl, const char *msg)
{
  int err = (*__errno_location ());
  return log_printf(lvl, "%s: %s\n", msg, strerror(err));
}

canonical_original_code:
_Bool log_perror(enum log_level lvl, char *msg)
{
  int err = (*__errno_location ());
  return log_printf(lvl, "%s: %s\n", msg, strerror(err));
}

variable_types:
msg
char *

variable_types: err int


xmalloc

decompiled_code:
void *__fastcall xmalloc(size_t a1)
{
void *result; // rax

result = malloc(a1);
if ( !result )
{
fprintf(stderr, "xmalloc(): Could not allocate %zd bytes.\n", a1);
abort();
}
return result;
}

canonical_decompiled_code:
void *__fastcall func0(size_t a1)
{
void *result; // rax

result = malloc(a1);
if ( !result )
{
fprintf(stderr, "xmalloc(): Could not allocate %zd bytes.\n", a1);
abort();
}
return result;
}

original_code:
void *xmalloc(size_t size)
{
  void *ptr = malloc(size);
  if (ptr)
    return ptr;
  fprintf(stderr, "xmalloc(): Could not allocate %zd bytes.\n", size);
  abort();
}

canonical_original_code:
void *xmalloc(unsigned long size)
{
  void *ptr = malloc(size);
  if (ptr)
    return ptr;
  fprintf(stderr, "xmalloc(): Could not allocate %zd bytes.\n", size);
  abort();
}

variable_types:
size
unsigned long

variable_types:
ptr
void *

return_type: void *


decompiled_code:
void *__fastcall xmalloc_zero(size_t n)
{
void *v1; // rax

v1 = xmalloc(n);
return memset(v1, 0, n);
}

canonical_decompiled_code:
void *__fastcall func1(size_t n)
{
void *v1; // rax

v1 = func0(n);
return memset(v1, 0, n);
}

original_code:
void *xmalloc_zero(size_t size)
{
  void *ptr = xmalloc(size);
  memset(ptr, 0, size);
  return ptr;
}

canonical_original_code:
void *xmalloc_zero(unsigned long size)
{
  void *ptr = xmalloc(size);
  memset(ptr, 0, size);
  return ptr;
}


xrealloc

decompiled_code:
void *__fastcall xrealloc(void *a1, size_t a2)
{
void *result; // rax

result = realloc(a1, a2);
if ( !result )
{
fprintf(stderr, "xrealloc(): Could not allocate %zd bytes\n", a2);
abort();
}
return result;
}

canonical_decompiled_code:
void *__fastcall func2(void *a1, size_t a2)
{
void *result; // rax

result = realloc(a1, a2);
if ( !result )
{
fprintf(stderr, "xrealloc(): Could not allocate %zd bytes\n", a2);
abort();
}
return result;
}

original_code:
void *xrealloc(void *ptr, size_t size)
{
  void *newptr = realloc(ptr, size);
  if (newptr)
    return newptr;
  fprintf(stderr, "xrealloc(): Could not allocate %zd bytes\n", size);
  abort();
}

canonical_original_code:
void *xrealloc(void *ptr, unsigned long size)
{
  void *newptr = realloc(ptr, size);
  if (newptr)
    return newptr;
  fprintf(stderr, "xrealloc(): Could not allocate %zd bytes\n", size);
  abort();
}

variable_types:
newptr
void *


xfree

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

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

original_code:
void xfree(void *ptr)
{
  free(ptr);
}

canonical_original_code:
void xfree(void *ptr)
{
  free(ptr);
}


canonical_original_code:
unsigned long unicode_ucs4_to_utf8(unsigned int ucs4, unsigned char (*utf8)[4])
{
  if (ucs4 > 0x10FFFF)
    return 0;
  else if ((ucs4 >= 0xD800) && (ucs4 <= 0xDFFF))
    return 0;
  if (ucs4 < 0x80)
  {
    (*utf8)[0] = (unsigned char) ucs4;
    return 1;
  }
  else if (ucs4 < 0x0800)
  {
    (*utf8)[0] = (unsigned char) (0xC0 | (ucs4 >> 6));
    (*utf8)[1] = (unsigned char) (0x80 | (ucs4 & 0x3F));
    return 2;
  }
  else if (ucs4 < 0x10000)
  {
    (*utf8)[0] = (unsigned char) (0xE0 | (ucs4 >> 12));
    (*utf8)[1] = (unsigned char) (0x80 | ((ucs4 >> 6) & 0x3F));
    (*utf8)[2] = (unsigned char) (0x80 | (ucs4 & 0x3F));
    return 3;
  }
  else
  {
    (*utf8)[0] = (unsigned char) (0xF0 | (ucs4 >> 18));
    (*utf8)[1] = (unsigned char) (0x80 | ((ucs4 >> 12) & 0x3F));
    (*utf8)[2] = (unsigned char) (0x80 | ((ucs4 >> 6) & 0x3F));
    (*utf8)[3] = (unsigned char) (0x80 | (ucs4 & 0x3F));
    return 4;
  }
}

return_type: unsigned long


decompiled_code:
__int64 __fastcall is_utf8(__int64 a1, unsigned __int64 a2)
{
int v4; // er8
__int64 v5; // rax
int v6; // edx
int v7; // er12
char v8; // dl
__int64 v9; // rax
unsigned __int64 v10; // rdi
char v11; // cl
unsigned int v12; // ecx
__int64 result; // rax
bool v14; // si

if ( !a2 )
return 1LL;
v4 = 0;
v5 = 0LL;
while ( 1 )
{
v8 = *(_BYTE *)(a1 + v5);
if ( v8 < 0 )
break;
LABEL_6:
v5 = ++v4;
if ( v4 >= a2 )
return 1LL;
}
if ( (unsigned __int8)v8 <= 0xC1u )
return 0LL;
if ( (unsigned __int8)v8 <= 0xDFu )
{
v6 = v8 & 0x1F;
v7 = 1;
}
else if ( (unsigned __int8)v8 > 0xEFu )
{
if ( (unsigned __int8)v8 > 0xF4u )
return 0LL;
v6 = v8 & 7;
v7 = 3;
}
else
{
v6 = v8 & 0xF;
v7 = 2;
}
if ( v7 + v4 >= a2 )
return 0LL;
v9 = v4 + 1;
v10 = v4 + (unsigned __int64)(unsigned int)(v7 - 1) + 2;
do
{
v4 = v9;
v11 = *(_BYTE *)(a1 + v9);
if ( (unsigned __int8)(v11 + 0x80) > 0x3Fu )
return 0LL;
v12 = v11 & 0x3F;
v6 = v12 | (v6 << 6);
++v9;
}
while ( v9 != v10 );
result = (unsigned int)(v6 - 55296);
LOBYTE(result) = (unsigned int)(v6 - 128) > 0x10FF7F || (unsigned int)result <= 0x7FF;
if ( !(_BYTE)result )
{
v14 = (unsigned int)(v6 - 128) <= 0x77F;
if ( v14 && v7 != 1 )
return result;
if ( (unsigned int)(v6 - 2048) <= 0xF7FF && v7 != 2 )
{
LOBYTE(v12) = v14 && v7 != 1;
return v12;
}
goto LABEL_6;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, unsigned __int64 a2)
{
int v4; // er8
__int64 v5; // rax
int v6; // edx
int v7; // er12
char v8; // dl
__int64 v9; // rax
unsigned __int64 v10; // rdi
char v11; // cl
unsigned int v12; // ecx
__int64 result; // rax
bool v14; // si

if ( !a2 )
return 1LL;
v4 = 0;
v5 = 0LL;
while ( 1 )
{
v8 = *(_BYTE *)(a1 + v5);
if ( v8 < 0 )
break;
LABEL_6:
v5 = ++v4;
if ( v4 >= a2 )
return 1LL;
}
if ( (unsigned __int8)v8 <= 0xC1u )
return 0LL;
if ( (unsigned __int8)v8 <= 0xDFu )
{
v6 = v8 & 0x1F;
v7 = 1;
}
else if ( (unsigned __int8)v8 > 0xEFu )
{
if ( (unsigned __int8)v8 > 0xF4u )
return 0LL;
v6 = v8 & 7;
v7 = 3;
}
else
{
v6 = v8 & 0xF;
v7 = 2;
}
if ( v7 + v4 >= a2 )
return 0LL;
v9 = v4 + 1;
v10 = v4 + (unsigned __int64)(unsigned int)(v7 - 1) + 2;
do
{
v4 = v9;
v11 = *(_BYTE *)(a1 + v9);
if ( (unsigned __int8)(v11 + 0x80) > 0x3Fu )
return 0LL;
v12 = v11 & 0x3F;
v6 = v12 | (v6 << 6);
++v9;
}
while ( v9 != v10 );
result = (unsigned int)(v6 - 55296);
LOBYTE(result) = (unsigned int)(v6 - 128) > 0x10FF7F || (unsigned int)result <= 0x7FF;
if ( !(_BYTE)result )
{
v14 = (unsigned int)(v6 - 128) <= 0x77F;
if ( v14 && v7 != 1 )
return result;
if ( (unsigned int)(v6 - 2048) <= 0xF7FF && v7 != 2 )
{
LOBYTE(v12) = v14 && v7 != 1;
return v12;
}
goto LABEL_6;
}
return 0LL;
}

original_code:
_Bool is_utf8(const uint8_t *bytes, size_t length)
{
  for (int i = 0; i < length; i++)
  {
    int cont;
    uint32_t ucs4;
    uint8_t b = bytes[i];
    if (b <= 0x7F)
      continue;
    else if (b <= 0xBF)
      return 0;
    else if (b <= 0xC1)
      return 0;
    else if (b <= 0xDF)
    {
      ucs4 = b & 0x1F;
      cont = 1;
    }
    else if (b <= 0xEF)
    {
      ucs4 = b & 0x0F;
      cont = 2;
    }
    else if (b <= 0xF4)
    {
      ucs4 = b & 0x07;
      cont = 3;
    }
    else
      return 0;
    if (i + cont >= length)
      return 0;
    for (int c = 0; c < cont; c++)
    {
      i++;
      b = bytes[i];
      if ((b < 0x80) || (b > 0xBF))
        return 0;
      ucs4 = (ucs4 << 6) | (b & 0x3F);
    }
    if ((ucs4 >= 0xD800) && (ucs4 <= 0xDFFF))
      return 0;
    else if (ucs4 < 0x80)
      return 0;
    else if ((ucs4 >= 0x80) && (ucs4 <= 0x07FF) && (cont != 1))
      return 0;
    else if ((ucs4 >= 0x0800) && (ucs4 <= 0xFFFF) && (cont != 2))
      return 0;
    else if (ucs4 > 0x10FFFF)
      return 0;
  }
  return 1;
}

canonical_original_code:
_Bool is_utf8(unsigned char *bytes, unsigned long length)
{
  for (int i = 0; i < length; i++)
  {
    int cont;
    unsigned int ucs4;
    unsigned char b = bytes[i];
    if (b <= 0x7F)
      continue;
    else if (b <= 0xBF)
      return 0;
    else if (b <= 0xC1)
      return 0;
    else if (b <= 0xDF)
    {
      ucs4 = b & 0x1F;
      cont = 1;
    }
    else if (b <= 0xEF)
    {
      ucs4 = b & 0x0F;
      cont = 2;
    }
    else if (b <= 0xF4)
    {
      ucs4 = b & 0x07;
      cont = 3;
    }
    else
      return 0;
    if (i + cont >= length)
      return 0;
    for (int c = 0; c < cont; c++)
    {
      i++;
      b = bytes[i];
      if ((b < 0x80) || (b > 0xBF))
        return 0;
      ucs4 = (ucs4 << 6) | (b & 0x3F);
    }
    if ((ucs4 >= 0xD800) && (ucs4 <= 0xDFFF))
      return 0;
    else if (ucs4 < 0x80)
      return 0;
    else if ((ucs4 >= 0x80) && (ucs4 <= 0x07FF) && (cont != 1))
      return 0;
    else if ((ucs4 >= 0x0800) && (ucs4 <= 0xFFFF) && (cont != 2))
      return 0;
    else if (ucs4 > 0x10FFFF)
      return 0;
  }
  return 1;
}

variable_types:
bytes
unsigned char *

variable_types:
length
unsigned long

variable_types: cont int

variable_types:
b
unsigned char

variable_types: c int


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

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

original_code:
void destory_cpu(_CPU* cpu) {
  if (cpu != ((void *)0)) {
    free(cpu);
  }
}

canonical_original_code:
void destory_cpu(struct _CPU *cpu) {
  if (cpu != ((void *)0)) {
    free(cpu);
  }
}

variable_types: struct _CPU { long long intr_; long long ctxt_; long long btime_; long long processes_; long long proc_running_; long long proc_blocked_; unsigned int core_num_; union _CPUCore { struct { long long user_; long long nice_; long long system_; long long idle_; long long iowait_; long long irq_; long long softirq_; }; long long argv_[7]; } cores_[]; } *

user_defined_types: struct _CPU { long long intr_; long long ctxt_; long long btime_; long long processes_; long long proc_running_; long long proc_blocked_; unsigned int core_num_; union _CPUCore cores_[]; }


decompiled_code:
void *get_current_cpu()
{
int v0; // eax
unsigned int v1; // ebp
_DWORD *v2; // rax
void *v3; // rbx
void *ptr; // [rsp+8h] [rbp-20h] BYREF

ptr = 0LL;
v0 = read_file_to_end("/proc/stat", &ptr);
if ( v0 >= 0 && (v1 = v0, v2 = create_cpu(), (v3 = v2) != 0LL) )
{
if ( (unsigned int)parse_cpu(ptr, v1, v2) )
{
if ( ptr )
free(ptr);
destory_cpu(v3);
v3 = 0LL;
}
else
{
free(ptr);
}
}
else
{
v3 = ptr;
if ( ptr )
{
free(ptr);
v3 = 0LL;
}
}
return v3;
}

canonical_decompiled_code:
void *func2()
{
int v0; // eax
unsigned int v1; // ebp
_DWORD *v2; // rax
void *v3; // rbx
void *ptr; // [rsp+8h] [rbp-20h] BYREF

ptr = 0LL;
v0 = read_file_to_end("/proc/stat", &ptr);
if ( v0 >= 0 && (v1 = v0, v2 = func0(), (v3 = v2) != 0LL) )
{
if ( (unsigned int)parse_cpu(ptr, v1, v2) )
{
if ( ptr )
free(ptr);
func1(v3);
v3 = 0LL;
}
else
{
free(ptr);
}
}
else
{
v3 = ptr;
if ( ptr )
{
free(ptr);
v3 = 0LL;
}
}
return v3;
}

original_code:
_CPU* get_current_cpu() {
  _CPU* cpu = ((void *)0);
  char* buffer = ((void *)0);
  int length = read_file_to_end("/proc/stat", &buffer);
  if (length < 0) {
    goto CLEAN;
  }
  cpu = _create_cpu();
  if (cpu == ((void *)0)) {
    goto CLEAN;
  }
  if (parse_cpu(buffer, length, cpu)
      != 0) {
    goto CLEAN;
  }
  free(buffer);
  return cpu;
CLEAN:
  if (buffer != ((void *)0)) {
    free(buffer);
  }
  if (cpu != ((void *)0)) {
    destory_cpu(cpu);
  }
  return ((void *)0);
}

canonical_original_code:
struct _CPU *get_current_cpu() {
  struct _CPU *cpu = ((void *)0);
  char *buffer = ((void *)0);
  int length = read_file_to_end("/proc/stat", &buffer);
  if (length < 0) {
    goto CLEAN;
  }
  cpu = _create_cpu();
  if (cpu == ((void *)0)) {
    goto CLEAN;
  }
  if (parse_cpu(buffer, length, cpu)
      != 0) {
    goto CLEAN;
  }
  free(buffer);
  return cpu;
CLEAN:
  if (buffer != ((void *)0)) {
    free(buffer);
  }
  if (cpu != ((void *)0)) {
    destory_cpu(cpu);
  }
  return ((void *)0);
}

variable_types:
buffer
char *

variable_types: length int

return_type: struct _CPU { long long intr_; long long ctxt_; long long btime_; long long processes_; long long proc_running_; long long proc_blocked_; unsigned int core_num_; union _CPUCore { struct { long long user_; long long nice_; long long system_; long long idle_; long long iowait_; long long irq_; long long softirq_; }; long long argv_[7]; } cores_[]; } *


decompiled_code:
_BOOL8 __fastcall is_keep_cpu_precent(_QWORD *a1)
{
_BOOL8 result; // rax

if ( !a1 )
_assert_fail("precent != NULL", "sys_monitor.c", 0x2Cu, "is_keep_cpu_precent");
result = 0LL;
if ( *a1 == -1LL )
result = a1[1] == -1LL;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(_QWORD *a1)
{
_BOOL8 result; // rax

if ( !a1 )
_assert_fail("precent != NULL", "sys_monitor.c", 0x2Cu, "is_keep_cpu_precent");
result = 0LL;
if ( *a1 == -1LL )
result = a1[1] == -1LL;
return result;
}

original_code:
static inline int is_keep_cpu_precent(CPUPrecent *precent) {
  ((void) sizeof ((precent != ((void *)0)) ? 1 : 0), __extension__ ({ if (precent != ((void *)0)) ; else __assert_fail ("precent != NULL", "sys_monitor.c", 44, __extension__ __PRETTY_FUNCTION__); }));
  return precent->intr_ == -1 && precent->ctxt_ == -1;
}

canonical_original_code:
static inline int is_keep_cpu_precent(struct CPUPrecent *precent) {
  ((void) sizeof ((precent != ((void *)0)) ? 1 : 0), __extension__ ({ if (precent != ((void *)0)) ; else __assert_fail ("precent != NULL", "sys_monitor.c", 44, __extension__ __PRETTY_FUNCTION__); }));
  return precent->intr_ == -1 && precent->ctxt_ == -1;
}

variable_types: struct CPUPrecent { long long intr_; long long ctxt_; long long btime_; long long processes_; long long proc_running_; long long proc_blocked_; double user_; double nice_; double system_; double idle_; double iowait_; double irq_; double softirq_; } *


decompiled_code:
_QWORD *create_cpu_monitor()
{
__int64 v0; // rbp
_QWORD *v1; // rax
_QWORD *v2; // rbx

v0 = get_current_cpu();
v1 = malloc(0x70uLL);
v2 = v1;
if ( v1 )
{
*v1 = v0;
memset(v1 + 1, 0, 0x68uLL);
}
else
{
destory_cpu(v0);
}
return v2;
}

canonical_decompiled_code:
_QWORD *func1()
{
__int64 v0; // rbp
_QWORD *v1; // rax
_QWORD *v2; // rbx

v0 = get_current_cpu();
v1 = malloc(0x70uLL);
v2 = v1;
if ( v1 )
{
*v1 = v0;
memset(v1 + 1, 0, 0x68uLL);
}
else
{
destory_cpu(v0);
}
return v2;
}

original_code:
CPUMonitor* create_cpu_monitor() {
  _CPU* cpu = get_current_cpu();
  CPUMonitor* monitor = malloc(sizeof(CPUMonitor));
  if (monitor == ((void *)0)) {
    destory_cpu(cpu);
    return ((void *)0);
  }
  monitor->last_ = cpu;
  monitor->last_precent_ = NullCPUPrecent;
  return monitor;
}

canonical_original_code:
struct CPUMonitor *create_cpu_monitor() {
  struct _CPU *cpu = get_current_cpu();
  struct CPUMonitor *monitor = malloc(sizeof(CPUMonitor));
  if (monitor == ((void *)0)) {
    destory_cpu(cpu);
    return ((void *)0);
  }
  monitor->last_ = cpu;
  monitor->last_precent_ = NullCPUPrecent;
  return monitor;
}

variable_types: struct CPUMonitor { struct _CPU { long long intr_; long long ctxt_; long long btime_; long long processes_; long long proc_running_; long long proc_blocked_; unsigned int core_num_; union _CPUCore { struct { long long user_; long long nice_; long long system_; long long idle_; long long iowait_; long long irq_; long long softirq_; }; long long argv_[7]; } cores_[]; } *last_; struct CPUPrecent { long long intr_; long long ctxt_; long long btime_; long long processes_; long long proc_running_; long long proc_blocked_; double user_; double nice_; double system_; double idle_; double iowait_; double irq_; double softirq_; } last_precent_; } *

user_defined_types: struct CPUMonitor { struct _CPU *last_; struct CPUPrecent last_precent_; }


decompiled_code:
void __fastcall free_cpu_monitor(void *ptr)
{
__int64 v2; // rdi

if ( ptr )
{
v2 = *(_QWORD *)ptr;
if ( v2 )
destory_cpu(v2);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
__int64 v2; // rdi

if ( ptr )
{
v2 = *(_QWORD *)ptr;
if ( v2 )
destory_cpu(v2);
free(ptr);
}
}

original_code:
void free_cpu_monitor(CPUMonitor* monitor) {
  if (monitor != ((void *)0)) {
    if (monitor->last_ != ((void *)0)) {
      destory_cpu(monitor->last_);
      monitor->last_ = ((void *)0);
    }
    free(monitor);
  }
}

canonical_original_code:
void free_cpu_monitor(struct CPUMonitor *monitor) {
  if (monitor != ((void *)0)) {
    if (monitor->last_ != ((void *)0)) {
      destory_cpu(monitor->last_);
      monitor->last_ = ((void *)0);
    }
    free(monitor);
  }
}

user_defined_types: struct CPUPrecent { long long intr_; long long ctxt_; long long btime_; long long processes_; long long proc_running_; long long proc_blocked_; double user_; double nice_; double system_; double idle_; double iowait_; double irq_; double softirq_; }

user_defined_types: union _CPUCore { struct { long long user_; long long nice_; long long system_; long long idle_; long long iowait_; long long irq_; long long softirq_; }; long long argv_[7]; }


decompiled_code:
__int64 __fastcall read_file(int fd, _QWORD *a2)
{
char *v2; // rax
char *v3; // r12
int v4; // ebp
int v5; // ebx
int v6; // eax

*a2 = 0LL;
v2 = (char *)calloc(1uLL, 0x1000uLL);
if ( v2 )
{
v3 = v2;
v4 = 0;
v5 = 4096;
while ( 1 )
{
v6 = read(fd, &v3[v4], v5);
if ( !v6 )
break;
if ( v6 < 0 )
{
if ( *_errno_location() != 4 )
{
free(v3);
return (unsigned int)-1;
}
}
else
{
v4 += v6;
v5 -= v6;
if ( !v5 )
{
v3 = (char *)realloc(v3, 2LL * v4);
if ( !v3 )
break;
v5 = v4;
}
}
}
*a2 = v3;
}
else
{
v4 = -1;
}
return (unsigned int)v4;
}

canonical_decompiled_code:
__int64 __fastcall func0(int fd, _QWORD *a2)
{
char *v2; // rax
char *v3; // r12
int v4; // ebp
int v5; // ebx
int v6; // eax

*a2 = 0LL;
v2 = (char *)calloc(1uLL, 0x1000uLL);
if ( v2 )
{
v3 = v2;
v4 = 0;
v5 = 4096;
while ( 1 )
{
v6 = read(fd, &v3[v4], v5);
if ( !v6 )
break;
if ( v6 < 0 )
{
if ( *_errno_location() != 4 )
{
free(v3);
return (unsigned int)-1;
}
}
else
{
v4 += v6;
v5 -= v6;
if ( !v5 )
{
v3 = (char *)realloc(v3, 2LL * v4);
if ( !v3 )
break;
v5 = v4;
}
}
}
*a2 = v3;
}
else
{
v4 = -1;
}
return (unsigned int)v4;
}

original_code:
static int read_file(int fd, char** buffer) {
  *buffer = ((void *)0);
  char* p = calloc(sizeof(char), 4096);
  if (p == ((void *)0)) {
    return -1;
  }
  int remain = 4096;
  int len = 0;
  while(1) {
    int tlen = read(fd, p + len, remain);
    if (tlen == 0) {
      break;
    } else if (tlen < 0) {
      if ((*__errno_location ()) == 4) {
        continue;
      }
      free(p);
      return -1;
    } else {
      remain -= tlen;
      len += tlen;
      if (remain == 0) {
        p = realloc(p, sizeof(char) * len * 2);
        if (p == ((void *)0)) {
          break;
        }
        remain = len;
      }
    }
  }
  *buffer = p;
  return len;
}

canonical_original_code:
static int read_file(int fd, char **buffer) {
  *buffer = ((void *)0);
  char *p = calloc(sizeof(char), 4096);
  if (p == ((void *)0)) {
    return -1;
  }
  int remain = 4096;
  int len = 0;
  while(1) {
    int tlen = read(fd, p + len, remain);
    if (tlen == 0) {
      break;
    } else if (tlen < 0) {
      if ((*__errno_location ()) == 4) {
        continue;
      }
      free(p);
      return -1;
    } else {
      remain -= tlen;
      len += tlen;
      if (remain == 0) {
        p = realloc(p, sizeof(char) * len * 2);
        if (p == ((void *)0)) {
          break;
        }
        remain = len;
      }
    }
  }
  *buffer = p;
  return len;
}

variable_types: fd int

variable_types:
buffer
char **

variable_types:
p
char *

variable_types: remain int

variable_types: len int

variable_types: tlen int


decompiled_code:
__int64 __fastcall read_file_to_end(const char *a1, _QWORD *a2)
{
int v2; // eax
int v3; // ebx
int v4; // ebp

*a2 = 0LL;
v2 = open(a1, 0);
if ( v2 < 0 )
{
v4 = -1;
}
else
{
v3 = v2;
v4 = read_file(v2, a2);
if ( v4 < 0 )
v4 = -1;
else
close(v3);
}
return (unsigned int)v4;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1, _QWORD *a2)
{
int v2; // eax
int v3; // ebx
int v4; // ebp

*a2 = 0LL;
v2 = open(a1, 0);
if ( v2 < 0 )
{
v4 = -1;
}
else
{
v3 = v2;
v4 = func0(v2, a2);
if ( v4 < 0 )
v4 = -1;
else
close(v3);
}
return (unsigned int)v4;
}

original_code:
int read_file_to_end(const char* name, char** buffer) {
  *buffer = ((void *)0);
  int fd = open(name, 00);
  if (fd < 0) return -1;
  int length = read_file(fd, buffer);
  if (length < 0) return -1;
  close(fd);
  return length;
}

canonical_original_code:
int read_file_to_end(char *name, char **buffer) {
  *buffer = ((void *)0);
  int fd = open(name, 00);
  if (fd < 0) return -1;
  int length = read_file(fd, buffer);
  if (length < 0) return -1;
  close(fd);
  return length;
}

variable_types:
name
char *


original_code:
void print_cpu_precent(CPUPrecent* precent) {
  fprintf(stdout,
      "====================================\n"
      "intr         = %lld\n"
      "ctxt         = %lld\n"
      "btime        = %lld\n"
      "processes    = %lld\n"
      "proc_running = %lld\n"
      "proc_blocked = %lld\n"
      "user         = %.2lf\n"
      "nice         = %.2lf\n"
      "system       = %.2lf\n"
      "idle         = %.2lf\n"
      "iowait       = %.2lf\n"
      "irq          = %.2lf\n"
      "softirq      = %.2lf\n"
      "====================================\n",
      precent->intr_, precent->ctxt_,
      precent->btime_, precent->processes_,
      precent->proc_running_, precent->proc_blocked_, precent->user_,
      precent->nice_, precent->system_, precent->idle_,
      precent->iowait_, precent->irq_, precent->softirq_);
}

canonical_original_code:
void print_cpu_precent(struct CPUPrecent *precent) {
  fprintf(stdout,
      "====================================\n"
      "intr         = %lld\n"
      "ctxt         = %lld\n"
      "btime        = %lld\n"
      "processes    = %lld\n"
      "proc_running = %lld\n"
      "proc_blocked = %lld\n"
      "user         = %.2lf\n"
      "nice         = %.2lf\n"
      "system       = %.2lf\n"
      "idle         = %.2lf\n"
      "iowait       = %.2lf\n"
      "irq          = %.2lf\n"
      "softirq      = %.2lf\n"
      "====================================\n",
      precent->intr_, precent->ctxt_,
      precent->btime_, precent->processes_,
      precent->proc_running_, precent->proc_blocked_, precent->user_,
      precent->nice_, precent->system_, precent->idle_,
      precent->iowait_, precent->irq_, precent->softirq_);
}


original_code:
int parse_cpu(const char* buffer, const int length,
    struct _CPU* cpu) {
  int index = 0;
  _Token name = BeginToken_;
  int got_argc = 0;
  while(index < length) {
    _Token token = _get_token(buffer + index, length);
    if (token.tag_ == &SeparatorTag_) {
      index += token.eptr_ - token.sptr_;
      continue;
    } else if (token.tag_ == &ErrorTag_) {
    } else if (token.tag_ == &EndTag_) {
      break;
    }
    index += token.eptr_ - token.sptr_;
    if (token.tag_ == &NumberTag_) {
      if (name.tag_->id_ <= ERROR) {
        if (got_argc < name.tag_->argc_) {
          _set_cpu_value(&name, got_argc, &token, cpu);
          got_argc++;
        }
      } else {
        return 3;
      }
    } else if (got_argc < name.tag_->argc_) {
      return 2;
    } else {
      name = token;
      got_argc = 0;
    }
  }
  return 0;
}

canonical_original_code:
int parse_cpu(char *buffer, int length, struct _CPU *cpu) {
  int index = 0;
  struct _Token name = BeginToken_;
  int got_argc = 0;
  while(index < length) {
    struct _Token token = _get_token(buffer + index, length);
    if (token.tag_ == &SeparatorTag_) {
      index += token.eptr_ - token.sptr_;
      continue;
    } else if (token.tag_ == &ErrorTag_) {
    } else if (token.tag_ == &EndTag_) {
      break;
    }
    index += token.eptr_ - token.sptr_;
    if (token.tag_ == &NumberTag_) {
      if (name.tag_->id_ <= ERROR) {
        if (got_argc < name.tag_->argc_) {
          _set_cpu_value(&name, got_argc, &token, cpu);
          got_argc++;
        }
      } else {
        return 3;
      }
    } else if (got_argc < name.tag_->argc_) {
      return 2;
    } else {
      name = token;
      got_argc = 0;
    }
  }
  return 0;
}

variable_types: index int

variable_types: struct _Token { struct _Tag { int id_; char *name_; int length_; int argc_; } *tag_; char *sptr_; char *eptr_; long long data_; }

user_defined_types: struct _Token { struct _Tag *tag_; char *sptr_; char *eptr_; long long data_; }


repo: xorver/mikro

original_code:
List *list_erase(List *l)
{
  List *next = l->next;
  if (l->prev)
    l->prev->next = next;
  if (next)
    l->next->prev = l->prev;
  free(l);
  return next;
}

canonical_original_code:
struct _List *list_erase(struct _List *l)
{
  struct _List *next = l->next;
  if (l->prev)
    l->prev->next = next;
  if (next)
    l->next->prev = l->prev;
  free(l);
  return next;
}

variable_types:
l
struct _List *

variable_types: struct _List { void *data; struct _List *next; struct _List *prev; } *


decompiled_code:
__int64 __fastcall list_erased(void **a1)
{
void *v2; // rdi

v2 = *a1;
if ( v2 )
{
free(v2);
*a1 = 0LL;
}
return list_erase(a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(void **a1)
{
void *v2; // rdi

v2 = *a1;
if ( v2 )
{
free(v2);
*a1 = 0LL;
}
return func0(a1);
}

original_code:
List *list_erased(List *l)
{
  if (l->data) {
    free(l->data);
    l->data = 0;
  }
  return list_erase(l);
}

canonical_original_code:
struct _List *list_erased(struct _List *l)
{
  if (l->data) {
    free(l->data);
    l->data = 0;
  }
  return list_erase(l);
}

return_type: struct _List { void *data; struct _List *next; struct _List *prev; } *


decompiled_code:
void __fastcall list_rerase(_QWORD *a1)
{
if ( a1[1] )
list_rerase();
free(a1);
}

canonical_decompiled_code:
void __fastcall func2(_QWORD *a1)
{
if ( a1[1] )
func2();
free(a1);
}

original_code:
void list_rerase(List *l)
{
  if (l->next)
    list_rerase(l->next);
  l->next = 0;
  free(l);
}

canonical_original_code:
void list_rerase(struct _List *l)
{
  if (l->next)
    list_rerase(l->next);
  l->next = 0;
  free(l);
}

user_defined_types: struct _List { void *data; struct _List *next; struct _List *prev; }


decompiled_code:
void __fastcall list_rerased(__int64 a1)
{
if ( *(_QWORD *)(a1 + 8) )
list_rerased();
if ( *(_QWORD *)a1 )
free(*(void **)a1);
free((void *)a1);
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1)
{
if ( *(_QWORD *)(a1 + 8) )
func3();
if ( *(_QWORD *)a1 )
free(*(void **)a1);
free((void *)a1);
}

original_code:
void list_rerased(List *l)
{
  if (l->next)
    list_rerased(l->next);
  l->next = 0;
  if (l->data) {
    free(l->data);
    l->data = 0;
  }
  free(l);
}

canonical_original_code:
void list_rerased(struct _List *l)
{
  if (l->next)
    list_rerased(l->next);
  l->next = 0;
  if (l->data) {
    free(l->data);
    l->data = 0;
  }
  free(l);
}


decompiled_code:
__int64 __fastcall list_front(__int64 a1)
{
__int64 result; // rax

do
{
result = a1;
a1 = *(_QWORD *)(a1 + 16);
}
while ( a1 );
return result;
}

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

do
{
result = a1;
a1 = *(_QWORD *)(a1 + 16);
}
while ( a1 );
return result;
}

original_code:
List *list_front(List *l)
{
  while (l->prev)
    l = l->prev;
  return l;
}

canonical_original_code:
struct _List *list_front(struct _List *l)
{
  while (l->prev)
    l = l->prev;
  return l;
}


original_code:
List *list_push_front(List *l, void *data)
{
  l = list_front(l);
  l->prev = (List *) malloc(sizeof(List));
  l->prev->data = data;
  l->prev->next = l;
  l->prev->prev = 0;
  return l->prev;
}

canonical_original_code:
struct _List *list_push_front(struct _List *l, void *data)
{
  l = list_front(l);
  l->prev = (struct _List *) malloc(sizeof(List));
  l->prev->data = data;
  l->prev->next = l;
  l->prev->prev = 0;
  return l->prev;
}

variable_types:
data
void *


decompiled_code:
__int64 __fastcall list_pop_front(__int64 a1)
{
_QWORD *v1; // rax

v1 = (_QWORD *)list_front(a1);
return list_erase(v1);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
_QWORD *v1; // rax

v1 = (_QWORD *)func4(a1);
return func0(v1);
}

original_code:
void list_pop_front(List *l)
{
  list_erase(list_front(l));
}

canonical_original_code:
void list_pop_front(struct _List *l)
{
  list_erase(list_front(l));
}


decompiled_code:
__int64 __fastcall list_popd_front(__int64 a1)
{
void **v1; // rax

v1 = (void **)list_front(a1);
return list_erased(v1);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
void **v1; // rax

v1 = (void **)func4(a1);
return func1(v1);
}

original_code:
void list_popd_front(List *l)
{
  list_erased(list_front(l));
}

canonical_original_code:
void list_popd_front(struct _List *l)
{
  list_erased(list_front(l));
}


decompiled_code:
__int64 __fastcall list_back(__int64 a1)
{
__int64 result; // rax

do
{
result = a1;
a1 = *(_QWORD *)(a1 + 8);
}
while ( a1 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
__int64 result; // rax

do
{
result = a1;
a1 = *(_QWORD *)(a1 + 8);
}
while ( a1 );
return result;
}

original_code:
List *list_back(List *l)
{
  while (l->next)
    l = l->next;
  return l;
}

canonical_original_code:
struct _List *list_back(struct _List *l)
{
  while (l->next)
    l = l->next;
  return l;
}


original_code:
List *list_push_back(List *l, void *data)
{
  l = list_back(l);
  l->next = (List *) malloc(sizeof(List));
  l->next->data = data;
  l->next->next = 0;
  l->next->prev = l;
  return l->next;
}

canonical_original_code:
struct _List *list_push_back(struct _List *l, void *data)
{
  l = list_back(l);
  l->next = (struct _List *) malloc(sizeof(List));
  l->next->data = data;
  l->next->next = 0;
  l->next->prev = l;
  return l->next;
}


decompiled_code:
__int64 __fastcall list_pop_back(__int64 a1)
{
_QWORD *v1; // rax

v1 = (_QWORD *)list_back(a1);
return list_erase(v1);
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
_QWORD *v1; // rax

v1 = (_QWORD *)func8(a1);
return func0(v1);
}

original_code:
void list_pop_back(List *l)
{
  list_erase(list_back(l));
}

canonical_original_code:
void list_pop_back(struct _List *l)
{
  list_erase(list_back(l));
}


decompiled_code:
__int64 __fastcall list_popd_back(__int64 a1)
{
void **v1; // rax

v1 = (void **)list_back(a1);
return list_erased(v1);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
void **v1; // rax

v1 = (void **)func8(a1);
return func1(v1);
}

original_code:
void list_popd_back(List *l)
{
  list_erased(list_back(l));
}

canonical_original_code:
void list_popd_back(struct _List *l)
{
  list_erased(list_back(l));
}


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

result = a1;
if ( a2 && a1 )
{
v3 = 0;
do
{
++v3;
result = *(_QWORD *)(result + 8);
}
while ( v3 < a2 && result );
}
return result;
}

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

result = a1;
if ( a2 && a1 )
{
v3 = 0;
do
{
++v3;
result = *(_QWORD *)(result + 8);
}
while ( v3 < a2 && result );
}
return result;
}

original_code:
List *list_nth(List *l, unsigned int n)
{
  int i;
  for (i = 0; (i < n) && (l); ++i, l = l->next);
  return l;
}

canonical_original_code:
struct _List *list_nth(struct _List *l, unsigned int n)
{
  int i;
  for (i = 0; (i < n) && (l); ++i, l = l->next);
  return l;
}

variable_types:
n
unsigned int

variable_types: i int