decompiled_code:
__int64 clock_init()
{
unsigned __int8 v0; // bl

io_outb(112LL, 11LL);
v0 = io_inb(113LL);
io_outb(112LL, 11LL);
io_outb(113LL, v0 | 0x40u);
return handler_reg(8LL, clock_callback);
}

canonical_decompiled_code:
__int64 func7()
{
unsigned __int8 v0; // bl

io_outb(112LL, 11LL);
v0 = io_inb(113LL);
io_outb(112LL, 11LL);
io_outb(113LL, v0 | 0x40u);
return handler_reg(8LL, clock_callback);
}

original_code:
void clock_init()
{
 char prev;
 io_outb(0x70, 0x0B);
 prev = io_inb(0x71);
 io_outb(0x70, 0x0B);
 io_outb(0x71, prev | 0x40);
 handler_reg(8, &clock_callback);
}

variable_types: prev char


repo: dakk/spiderpig-os

decompiled_code:
__int64 arch_get_clock()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func8()
{
return 0LL;
}

original_code:
uint32_t arch_get_clock()
{
 return 0;
}

canonical_original_code:
unsigned int arch_get_clock()
{
 return 0;
}

return_type: unsigned int


usage

decompiled_code:
int usage()
{
return puts("Usage: mkfs.pfs [-V volume-name] device");
}

canonical_decompiled_code:
int func0()
{
return puts("Usage: mkfs.pfs [-V volume-name] device");
}

original_code:
void usage()
{
 printf("Usage: mkfs.pfs [-V volume-name] device\n");
}

return_type: void


decompiled_code:
__int64 __fastcall mm_init(int a1, int a2)
{
debug_puts("mm_init()\n");
return phys_init((unsigned int)(a1 + a2));
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, int a2)
{
debug_puts("mm_init()\n");
return phys_init((unsigned int)(a1 + a2));
}

original_code:
void mm_init(uint32_t low, uint32_t high)
{
 debug_puts("mm_init()\n");
 phys_init(low + high);
}

canonical_original_code:
void mm_init(unsigned int low, unsigned int high)
{
 debug_puts("mm_init()\n");
 phys_init(low + high);
}

variable_types:
low
unsigned int

variable_types:
high
unsigned int


decompiled_code:
__int64 __fastcall mm_kalloc(int a1)
{
return phys_alloc(((unsigned int)(a1 + 1) >> 12) + 1);
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
return phys_alloc(((unsigned int)(a1 + 1) >> 12) + 1);
}

original_code:
void *mm_kalloc(size_t size)
{
 unsigned bnum = (unsigned) ((size + 1) / (4 * 1024)) + 1;
 return (void *)phys_alloc(bnum);
}

canonical_original_code:
void *mm_kalloc(unsigned int size)
{
 unsigned int bnum = (unsigned) ((size + 1) / (4 * 1024)) + 1;
 return (void *)phys_alloc(bnum);
}

variable_types:
size
unsigned int

variable_types:
bnum
unsigned int

return_type: void *


decompiled_code:
__int64 mm_kfree()
{
return phys_free();
}

canonical_decompiled_code:
__int64 func2()
{
return phys_free();
}

original_code:
void mm_kfree(void *addr)
{
 phys_free(addr);
}

variable_types:
addr
void *


decompiled_code:
__int64 mm_get_total_mem()
{
return (unsigned int)phys_total;
}

canonical_decompiled_code:
__int64 func3()
{
return (unsigned int)phys_total;
}

original_code: uint32_t mm_get_total_mem(){ return phys_total; }

canonical_original_code: unsigned int mm_get_total_mem(){ return phys_total; }


decompiled_code:
__int64 mm_get_used_mem()
{
int v0; // ebx

v0 = phys_page_number;
return 4 * (v0 - (unsigned int)phys_get_free_pages());
}

canonical_decompiled_code:
__int64 func4()
{
int v0; // ebx

v0 = phys_page_number;
return 4 * (v0 - (unsigned int)phys_get_free_pages());
}

original_code:
uint32_t mm_get_used_mem()
{
 return ((phys_page_number - phys_get_free_pages()) * 4);
}

canonical_original_code:
unsigned int mm_get_used_mem()
{
 return ((phys_page_number - phys_get_free_pages()) * 4);
}


decompiled_code:
int show_used_memory()
{
int v0; // ebx
unsigned int v1; // eax
unsigned int v2; // edx
unsigned int v3; // ebx
unsigned int v4; // eax
unsigned int v5; // eax

video_puts_colored(9LL, "\t-> ");
v0 = ((__int64 (*)(void))mm_get_used_mem)();
v1 = mm_get_total_mem();
v2 = 100 * v0 % v1;
v3 = 100 * v0 / v1;
v4 = mm_get_used_mem(9LL, "\t-> ", v2);
printf("used: %dkb (%d%%); ", v4, v3);
v5 = mm_get_total_mem();
return printf("total: %dkb\n", v5);
}

canonical_decompiled_code:
int func5()
{
int v0; // ebx
unsigned int v1; // eax
unsigned int v2; // edx
unsigned int v3; // ebx
unsigned int v4; // eax
unsigned int v5; // eax

video_puts_colored(9LL, "\t-> ");
v0 = ((__int64 (*)(void))mm_get_used_mem)();
v1 = func3();
v2 = 100 * v0 % v1;
v3 = 100 * v0 / v1;
v4 = func4(9LL, "\t-> ", v2);
printf("used: %dkb (%d%%); ", v4, v3);
v5 = func3();
return printf("total: %dkb\n", v5);
}

original_code:
void show_used_memory()
{
 video_puts_colored(0x09, "\t-> ");
 printf("used: %dkb (%d%%);  ", mm_get_used_mem(), mm_get_used_mem() * 100 / mm_get_total_mem());
 printf("total: %dkb\n", mm_get_total_mem());
}


decompiled_code:
int mm_test()
{
__int64 v0; // rbx

debug_puts("mm_test()\n");
show_used_memory();
video_puts("Alloc 1000 blocks of 4*1024 bytes\n");
v0 = phys_alloc(1000LL);
show_used_memory();
video_puts("Delloc 1000 blocks of 4*1024 bytes\n");
phys_free(v0);
return show_used_memory();
}

canonical_decompiled_code:
int func6()
{
__int64 v0; // rbx

debug_puts("mm_test()\n");
func5();
video_puts("Alloc 1000 blocks of 4*1024 bytes\n");
v0 = phys_alloc(1000LL);
func5();
video_puts("Delloc 1000 blocks of 4*1024 bytes\n");
phys_free(v0);
return func5();
}

original_code:
void mm_test()
{
 debug_puts("mm_test()\n");
 show_used_memory();
 video_puts("Alloc 1000 blocks of 4*1024 bytes\n");
 char *data = phys_alloc(1000);
 show_used_memory();
 video_puts("Delloc 1000 blocks of 4*1024 bytes\n");
 phys_free(data);
 show_used_memory();
}

variable_types:
data
char *


decompiled_code:
__int64 __fastcall mm_get_usable_size(__int64 a1)
{
__int64 v1; // rax

v1 = 0LL;
while ( phys_allocated[2 * v1] != a1 )
{
if ( ++v1 == 0x8000 )
return 0LL;
}
return LODWORD(phys_allocated[2 * (int)v1 + 1]);
}

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

v1 = 0LL;
while ( phys_allocated[2 * v1] != a1 )
{
if ( ++v1 == 0x8000 )
return 0LL;
}
return LODWORD(phys_allocated[2 * (int)v1 + 1]);
}

original_code:
uint32_t mm_get_usable_size(void *addr)
{
 int i = 0;
 for(i = 0; i < (1048576 / 32); i++)
  if(phys_allocated[i].address == addr)
   return phys_allocated[i].dim;
 return 0;
}

canonical_original_code:
unsigned int mm_get_usable_size(void *addr)
{
 int i = 0;
 for(i = 0; i < (1048576 / 32); i++)
  if(phys_allocated[i].address == addr)
   return phys_allocated[i].dim;
 return 0;
}

variable_types: i int


realloc

decompiled_code:
void *__fastcall realloc(void *src, size_t n)
{
void *v2; // rbx

v2 = (void *)mm_kalloc((unsigned int)n);
memcpy(v2, src, (unsigned int)n);
free(src);
return v2;
}

canonical_decompiled_code:
void *__fastcall func2(void *src, size_t n)
{
void *v2; // rbx

v2 = (void *)mm_kalloc((unsigned int)n);
memcpy(v2, src, (unsigned int)n);
func1(src);
return v2;
}

original_code:
void *realloc(void *adr, size_t size)
{
 void *new = (void *) mm_kalloc(size);
 memcpy(new, adr, size);
 free(adr);
 return (void *) new;
}

canonical_original_code:
void *realloc(void *adr, unsigned int size)
{
 void *new = (void *) mm_kalloc(size);
 memcpy(new, adr, size);
 free(adr);
 return (void *) new;
}

variable_types:
adr
void *

variable_types:
new
void *


malloc

decompiled_code:
__int64 malloc()
{
++allocazioni;
return mm_kalloc();
}

canonical_decompiled_code:
__int64 func0()
{
++allocazioni;
return mm_kalloc();
}

original_code:
void *malloc(size_t size)
{
 allocazioni++;
 return (void *) mm_kalloc(size);
}

canonical_original_code:
void *malloc(unsigned int size)
{
 allocazioni++;
 return (void *) mm_kalloc(size);
}


free

decompiled_code:
__int64 free()
{
--allocazioni;
return mm_kfree();
}

canonical_decompiled_code:
__int64 func1()
{
--allocazioni;
return mm_kfree();
}

original_code:
void free(void *adr)
{
 allocazioni--;
 mm_kfree(adr);
}


decompiled_code:
__int64 pci_probe()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
return 0LL;
}

original_code:
uint32_t pci_probe()
{
 return 0;
}

canonical_original_code:
unsigned int pci_probe()
{
 return 0;
}


decompiled_code:
__int64 __fastcall pci_read(int a1, int a2, int a3, int a4, char a5)
{
char v5; // bp
__int64 result; // rax

v5 = a4;
io_outd(3320LL, (a2 << 11) | (a3 << 8) | a4 & 0xFFFFFFFC | (a1 << 16) | 0x80000000);
if ( a5 == 2 )
return (unsigned __int16)io_inw((v5 & 2u) + 3324);
if ( a5 == 4 )
return io_ind(3324LL);
result = 255LL;
if ( a5 == 1 )
result = (unsigned __int8)io_inb((v5 & 3u) + 3324);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, int a2, int a3, int a4, char a5)
{
char v5; // bp
__int64 result; // rax

v5 = a4;
io_outd(3320LL, (a2 << 11) | (a3 << 8) | a4 & 0xFFFFFFFC | (a1 << 16) | 0x80000000);
if ( a5 == 2 )
return (unsigned __int16)io_inw((v5 & 2u) + 3324);
if ( a5 == 4 )
return io_ind(3324LL);
result = 255LL;
if ( a5 == 1 )
result = (unsigned __int8)io_inb((v5 & 3u) + 3324);
return result;
}

original_code:
uint32_t pci_read(uint32_t bus, uint32_t device, uint32_t function, uint32_t offset, uint8_t size)
{
 uint32_t value;
 io_outd(0xCF8, 0x80000000 | (bus << 16) | (device << 11) | (function << 8) | (offset & ~3));
 switch (size)
 {
  case 1:
   value = io_inb(0xCFC + (offset & 3)); break;
  case 2:
   value = io_inw(0xCFC + (offset & 2)); break;
  case 4:
   value = io_ind(0xCFC); break;
  default:
   return 0xFF;
 }
 return value;
}

canonical_original_code:
unsigned int pci_read(unsigned int bus, unsigned int device, unsigned int function, unsigned int offset, unsigned char size)
{
 unsigned int value;
 io_outd(0xCF8, 0x80000000 | (bus << 16) | (device << 11) | (function << 8) | (offset & ~3));
 switch (size)
 {
  case 1:
   value = io_inb(0xCFC + (offset & 3)); break;
  case 2:
   value = io_inw(0xCFC + (offset & 2)); break;
  case 4:
   value = io_ind(0xCFC); break;
  default:
   return 0xFF;
 }
 return value;
}

variable_types:
bus
unsigned int

variable_types:
device
unsigned int

variable_types:
function
unsigned int

variable_types:
offset
unsigned int

variable_types:
size
unsigned char

variable_types:
value
unsigned int


original_code:
uint32_t pci_get(uint32_t bus, uint32_t slot, uint32_t func, device_t *dev)
{
 uint32_t tmp = pci_read(bus, slot, func, 0x00, 2);
 if ((tmp == 0xFFFF) || (tmp == 0x0000)) return 0;
 pci_device_t *pci_dev = (pci_device_t *) malloc(sizeof(pci_device_t));
 int i;
 pci_dev->bus = bus;
 pci_dev->device = slot;
 pci_dev->function = func;
 pci_dev->vendor_id = pci_read(bus, slot, func, 0x00, 2);
 pci_dev->device_id = pci_read(bus, slot, func, 0x02, 2);
 pci_dev->class_id = pci_read(bus, slot, func, 0x0B, 1);
 pci_dev->subclass_id = pci_read(bus, slot, func, 0x0A, 1);
 for(i=0;i<6;i++)
 {
  pci_dev->bar[i] = pci_read(bus, slot, func, 0x10 + (i * 4), 4);
 }
 pci_dev->int_line = pci_read(bus, slot, func, 0x3C, 1);
 pci_dev->int_pin = pci_read(bus, slot, func, 0x3D, 1);
 for(i = 0; i < (sizeof(pci_class_code_table)/sizeof(pci_classtable_t)); i++)
  if( (pci_class_code_table[i].class_base == pci_dev->class_id) &&
   (pci_class_code_table[i].class_sub == pci_dev->subclass_id))
  {
   int j;
   strcpy(dev->class, pci_class_code_table[i].desc_base);
   strcpy(dev->class_desc, pci_class_code_table[i].desc_sub);
   strcpy(dev->file, pci_class_code_table[i].file);
   break;
  }
 dev->pci_dev = (void *) pci_dev;
 return 1;
}

canonical_original_code:
unsigned int pci_get(unsigned int bus, unsigned int slot, unsigned int func, struct device_p *dev)
{
 unsigned int tmp = pci_read(bus, slot, func, 0x00, 2);
 if ((tmp == 0xFFFF) || (tmp == 0x0000)) return 0;
 struct pci_device_t *pci_dev = (pci_device_t *) malloc(sizeof(pci_device_t));
 int i;
 pci_dev->bus = bus;
 pci_dev->device = slot;
 pci_dev->function = func;
 pci_dev->vendor_id = pci_read(bus, slot, func, 0x00, 2);
 pci_dev->device_id = pci_read(bus, slot, func, 0x02, 2);
 pci_dev->class_id = pci_read(bus, slot, func, 0x0B, 1);
 pci_dev->subclass_id = pci_read(bus, slot, func, 0x0A, 1);
 for(i=0;i<6;i++)
 {
  pci_dev->bar[i] = pci_read(bus, slot, func, 0x10 + (i * 4), 4);
 }
 pci_dev->int_line = pci_read(bus, slot, func, 0x3C, 1);
 pci_dev->int_pin = pci_read(bus, slot, func, 0x3D, 1);
 for(i = 0; i < (sizeof(pci_class_code_table)/sizeof(pci_classtable_t)); i++)
  if( (pci_class_code_table[i].class_base == pci_dev->class_id) &&
   (pci_class_code_table[i].class_sub == pci_dev->subclass_id))
  {
   int j;
   strcpy(dev->class, pci_class_code_table[i].desc_base);
   strcpy(dev->class_desc, pci_class_code_table[i].desc_sub);
   strcpy(dev->file, pci_class_code_table[i].file);
   break;
  }
 dev->pci_dev = (void *) pci_dev;
 return 1;
}

variable_types:
slot
unsigned int

variable_types:
func
unsigned int

variable_types: struct device_p { unsigned int io_base; char vendor[32]; char vendor_full[32]; char device[32]; char device_desc[32]; char class[32]; char class_desc[32]; char class_prog_desc[32]; unsigned char bus_type; void *pci_dev; unsigned char interrupt; unsigned int base_addresses[6]; char file[32]; struct device_p *next; } *

variable_types:
tmp
unsigned int

variable_types: struct pci_device_t { unsigned int bus; unsigned int function; unsigned int device; unsigned int command; unsigned int status; unsigned int rev_id; unsigned int iface; unsigned int vendor_id; unsigned int device_id; unsigned int class_id; unsigned int subclass_id; unsigned int bar[6]; unsigned int int_line; unsigned int int_pin; } *

variable_types: j int


original_code:
void pci_update(device_t **list)
{
 int bus, slot, func;
 device_t *dev = 0;
 device_t *newdev = 0;
 for(bus = 0; bus < 16; bus++)
  for(slot = 0; slot < 12; slot++)
   for(func = 0; func < 12; func++)
   {
    newdev = (device_t *) malloc(sizeof(device_t));
    if(pci_get(bus, slot, func, newdev))
    {
     newdev->bus_type = 0x01;
     newdev->next = 0;
     device_t *l = *list;
     while(l != 0)
     {
      if( (((pci_device_t * )(l->pci_dev))->bus == ((pci_device_t * )(newdev->pci_dev))->bus) &&
       (((pci_device_t * )(l->pci_dev))->device == ((pci_device_t * )(newdev->pci_dev))->device) &&
       (((pci_device_t * )(l->pci_dev))->function == ((pci_device_t * )(newdev->pci_dev))->function))
      {
       goto free_dev;
      }
      l = l->next;
     }
     if(*list == 0)
      *list = newdev;
     else
      dev->next = newdev;
     dev = newdev;
    }
    else
    {
     free_dev:
      free(newdev);
    }
   }
}

canonical_original_code:
void pci_update(struct device_p **list)
{
 int bus; int slot; int func;
 struct device_p *dev = 0;
 struct device_p *newdev = 0;
 for(bus = 0; bus < 16; bus++)
  for(slot = 0; slot < 12; slot++)
   for(func = 0; func < 12; func++)
   {
    newdev = (struct device_p *) malloc(sizeof(device_t));
    if(pci_get(bus, slot, func, newdev))
    {
     newdev->bus_type = 0x01;
     newdev->next = 0;
     struct device_p *l = *list;
     while(l != 0)
     {
      if( (((struct pci_device_t * )(l->pci_dev))->bus == ((struct pci_device_t * )(newdev->pci_dev))->bus) &&
       (((struct pci_device_t * )(l->pci_dev))->device == ((struct pci_device_t * )(newdev->pci_dev))->device) &&
       (((struct pci_device_t * )(l->pci_dev))->function == ((struct pci_device_t * )(newdev->pci_dev))->function))
      {
       goto free_dev;
      }
      l = l->next;
     }
     if(*list == 0)
      *list = newdev;
     else
      dev->next = newdev;
     dev = newdev;
    }
    else
    {
     free_dev:
      free(newdev);
    }
   }
}

variable_types: struct device_p { unsigned int io_base; char vendor[32]; char vendor_full[32]; char device[32]; char device_desc[32]; char class[32]; char class_desc[32]; char class_prog_desc[32]; unsigned char bus_type; void *pci_dev; unsigned char interrupt; unsigned int base_addresses[6]; char file[32]; struct device_p *next; } **

variable_types: bus int

variable_types: slot int

variable_types: func int

user_defined_types: struct pci_device_t { unsigned int bus; unsigned int function; unsigned int device; unsigned int command; unsigned int status; unsigned int rev_id; unsigned int iface; unsigned int vendor_id; unsigned int device_id; unsigned int class_id; unsigned int subclass_id; unsigned int bar[6]; unsigned int int_line; unsigned int int_pin; }


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

v1 = (int)mm_kalloc(104LL);
*(_QWORD *)(v1 + 64) = (int)mm_kalloc(a1);
*(_QWORD *)(v1 + 72) = (int)mm_kalloc(a1);
strcpy(*(char **)(v1 + 64), src);
*(_DWORD *)(v1 + 80) = 0;
*(_BYTE *)(v1 + 84) = 15;
v1 += 32LL;
devfs_find_freen(&unk_6323, v1);
return devfs_reg_device(0LL, 0LL, v1);
}

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

v1 = (int)mm_kalloc(104LL);
*(_QWORD *)(v1 + 64) = (int)mm_kalloc(a1);
*(_QWORD *)(v1 + 72) = (int)mm_kalloc(a1);
strcpy(*(char **)(v1 + 64), src);
*(_DWORD *)(v1 + 80) = 0;
*(_BYTE *)(v1 + 84) = 15;
v1 += 32LL;
devfs_find_freen(&unk_6323, v1);
return devfs_reg_device(0LL, 0LL, v1);
}

original_code:
term_t *term_new(size_t size)
{
 term_t *t = (term_t *) mm_kalloc(sizeof(term_t));
 t->data = (char *) mm_kalloc(sizeof(char) * size);
 t->input = (char *) mm_kalloc(sizeof(char) * size);
 strcpy(t->data, "\0");
 t->cursor_pos = 0;
 t->color = 0x0F;
 devfs_find_freen("tty", t->dfile);
 devfs_reg_device(0,0, t->dfile);
}

canonical_original_code:
struct term_p *term_new(unsigned int size)
{
 struct term_p *t = (term_t *) mm_kalloc(sizeof(term_t));
 t->data = (char *) mm_kalloc(sizeof(char) * size);
 t->input = (char *) mm_kalloc(sizeof(char) * size);
 strcpy(t->data, "\0");
 t->cursor_pos = 0;
 t->color = 0x0F;
 devfs_find_freen("tty", t->dfile);
 devfs_reg_device(0,0, t->dfile);
}

variable_types:
size
unsigned int

variable_types: struct term_p { char name[32]; char dfile[32]; char *data; char *input; unsigned int cursor_pos; char color; unsigned int size; struct term_p *next; } *


decompiled_code:
__int64 __fastcall term_delete(__int64 a1)
{
devfs_unreg_device(a1 + 32);
mm_kfree(*(_QWORD *)(a1 + 64));
return mm_kfree(a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
devfs_unreg_device(a1 + 32);
mm_kfree(*(_QWORD *)(a1 + 64));
return mm_kfree(a1);
}

original_code:
void term_delete(term_t *t)
{
 devfs_unreg_device(t->dfile);
 mm_kfree(t->data);
 mm_kfree(t);
}

canonical_original_code:
void term_delete(struct term_p *t)
{
 devfs_unreg_device(t->dfile);
 mm_kfree(t->data);
 mm_kfree(t);
}

user_defined_types: struct term_p { char name[32]; char dfile[32]; char *data; char *input; unsigned int cursor_pos; char color; unsigned int size; struct term_p *next; }


decompiled_code:
char *__fastcall term_set_title(char *a1, const char *a2)
{
return strcpy(a1, a2);
}

canonical_decompiled_code:
char *__fastcall func2(char *a1, const char *a2)
{
return strcpy(a1, a2);
}

original_code:
void term_set_title(term_t *t, char *title)
{
 strcpy(t->name, title);
}

canonical_original_code:
void term_set_title(struct term_p *t, char *title)
{
 strcpy(t->name, title);
}

variable_types:
title
char *


decompiled_code:
__int64 message_clear()
{
__int64 v0; // rbp
__int64 i; // rbx
__int64 v2; // rdi
__int64 result; // rax

v0 = task_current;
for ( i = *(_QWORD *)(task_current + 32); i; --*(_DWORD *)(v0 + 24) )
{
v2 = i;
i = *(_QWORD *)(i + 16);
result = mm_kfree(v2);
}
*(_QWORD *)(v0 + 32) = 0LL;
*(_QWORD *)(v0 + 40) = 0LL;
*(_DWORD *)(v0 + 24) = 0;
return result;
}

original_code:
void message_clear()
{
 task_t *t = task_current;
 message_t *first;
 message_t *second = t->msg_start;
 while(second != 0)
 {
  first = second->next;
  mm_kfree(second);
  t->msg_num--;
  second = first;
 }
 t->msg_end = t->msg_start = 0;
 t->msg_num = 0;
}

canonical_original_code:
void message_clear()
{
 struct task_p *t = task_current;
 struct message_p *first;
 struct message_p *second = t->msg_start;
 while(second != 0)
 {
  first = second->next;
  mm_kfree(second);
  t->msg_num--;
  second = first;
 }
 t->msg_end = t->msg_start = 0;
 t->msg_num = 0;
}

variable_types: struct task_p { char name[16]; unsigned char state; unsigned char priority; unsigned int ms_sleep; unsigned int msg_num; struct message_p { char *data; unsigned int size; int pid; struct message_p *next; } *msg_start; struct message_p *msg_end; struct term_p { char name[32]; char dfile[32]; char *data; char *input; unsigned int cursor_pos; char color; unsigned int size; struct term_p *next; } *term; int pid; int uid; struct task_p *next; } *

user_defined_types: struct task_p { char name[16]; unsigned char state; unsigned char priority; unsigned int ms_sleep; unsigned int msg_num; struct message_p *msg_start; struct message_p *msg_end; struct term_p *term; int pid; int uid; struct task_p *next; }


original_code:
uint32_t message_send(pid_t to, char *buf, uint32_t size)
{
 uint32_t x;
 task_t *t = task_get_from_pid(to);
 if(t == 0) return -1;
 if(t->msg_num > 255) return -2;
 if(size >= 255) return -3;
 message_t *tm = (message_t *) mm_kalloc(sizeof(message_t));
 for(x = 0; x < size && x < 255; x++)
  tm->data[x] = buf[x];
 tm->pid = task_get_pid();
 tm->size = size;
 tm->next = 0;
 if(t->msg_start == 0 || t->msg_end == 0)
 {
  t->msg_start = tm;
  t->msg_end = tm;
 }
 else
 {
  t->msg_end->next = tm;
  t->msg_end = tm;
 }
 t->msg_num++;
 return 1;
}

canonical_original_code:
unsigned int message_send(int to, char *buf, unsigned int size)
{
 unsigned int x;
 struct task_p *t = task_get_from_pid(to);
 if(t == 0) return -1;
 if(t->msg_num > 255) return -2;
 if(size >= 255) return -3;
 struct message_p *tm = (message_t *) mm_kalloc(sizeof(message_t));
 for(x = 0; x < size && x < 255; x++)
  tm->data[x] = buf[x];
 tm->pid = task_get_pid();
 tm->size = size;
 tm->next = 0;
 if(t->msg_start == 0 || t->msg_end == 0)
 {
  t->msg_start = tm;
  t->msg_end = tm;
 }
 else
 {
  t->msg_end->next = tm;
  t->msg_end = tm;
 }
 t->msg_num++;
 return 1;
}

variable_types: to int

variable_types:
buf
char *

variable_types:
x
unsigned int

variable_types: struct message_p { char *data; unsigned int size; int pid; struct message_p *next; } *


original_code:
uint32_t message_recv(char *data, pid_t *pid)
{
 task_t *t = task_current;
 if(t == 0) return 0;
 if(t->msg_num < 1) return 0;
 if(t->msg_start == 0) return 0;
 strcpy(data, t->msg_start->data);
 uint32_t size = t->msg_start->size;
 *pid = t->msg_start->pid;
 message_t *msg = t->msg_start->next;
 mm_kfree(t->msg_start);
 t->msg_start = msg;
 if(t->msg_end == 0) t->msg_end = t->msg_start;
 t->msg_num--;
 return size;
}

canonical_original_code:
unsigned int message_recv(char *data, int *pid)
{
 struct task_p *t = task_current;
 if(t == 0) return 0;
 if(t->msg_num < 1) return 0;
 if(t->msg_start == 0) return 0;
 strcpy(data, t->msg_start->data);
 unsigned int size = t->msg_start->size;
 *pid = t->msg_start->pid;
 struct message_p *msg = t->msg_start->next;
 mm_kfree(t->msg_start);
 t->msg_start = msg;
 if(t->msg_end == 0) t->msg_end = t->msg_start;
 t->msg_num--;
 return size;
}

variable_types:
data
char *

variable_types:
pid
int *

user_defined_types: struct message_p { char *data; unsigned int size; int pid; struct message_p *next; }


original_code:
uint32_t smbios_probe(device_t *dev)
{
 char *mem = (unsigned char *) 0xF0000;
 uint32_t length, i;
 char checksum;
 while ((uint32_t) mem < 0x100000)
 {
  if(mem[0] == '_' && mem[1] == 'S' && mem[2] == 'M' && mem[3] == '_')
  {
   length = mem[5];
   checksum = 0;
   for(i = 0; i < length; i++)
    checksum += mem[i];
   if(checksum == 0)
   {
    smbios_mem = mem;
    driver_puts(&driver_smbios, 0x1, "found");
    return 1;
   }
  }
  mem += 16;
 }
 return 0;
}

canonical_original_code:
unsigned int smbios_probe(struct device_p *dev)
{
 char *mem = (unsigned char *) 0xF0000;
 unsigned int length; unsigned int i;
 char checksum;
 while ((unsigned int) mem < 0x100000)
 {
  if(mem[0] == '_' && mem[1] == 'S' && mem[2] == 'M' && mem[3] == '_')
  {
   length = mem[5];
   checksum = 0;
   for(i = 0; i < length; i++)
    checksum += mem[i];
   if(checksum == 0)
   {
    smbios_mem = mem;
    driver_puts(&driver_smbios, 0x1, "found");
    return 1;
   }
  }
  mem += 16;
 }
 return 0;
}

variable_types: struct device_p { unsigned int io_base; char vendor[32]; char vendor_full[32]; char device[32]; char device_desc[32]; char class[32]; char class_desc[32]; char class_prog_desc[32]; unsigned char bus_type; void *pci_dev; unsigned char interrupt; unsigned int base_addresses[6]; char file[32]; struct device_p *next; } *

variable_types:
mem
char *

variable_types:
length
unsigned int

variable_types:
i
unsigned int

variable_types: checksum char


decompiled_code:
__int64 smbios_init()
{
__int64 v0; // rbp
int v1; // ebx
__int64 result; // rax
unsigned int v3; // eax
__int64 v4; // r12

if ( smbios_mem || (unsigned int)smbios_probe(0LL) )
{
devfs_reg_device(0LL, 0LL, "smbios0");
v0 = smbios_mem;
if ( *(_WORD *)(smbios_mem + 28) )
{
v1 = 0;
do
{
v3 = *(_DWORD *)(v0 + 24) + v1 * *(unsigned __int16 *)(v0 + 22);
v4 = v3;
if ( *(_BYTE *)v3 == 4 )
{
printf("core_count: %d\n", *((unsigned __int8 *)&loc_E1 + v3 + 2));
printf("core_enabled: %d\n", *(unsigned __int8 *)(v4 + 228));
printf("voltage: %d\n", *(unsigned __int8 *)(v4 + 209));
printf("max_speed: %d\n", *(unsigned __int16 *)(v4 + 212));
}
++v1;
}
while ( *(unsigned __int16 *)(v0 + 28) > v1 );
result = 0LL;
}
else
{
result = 0LL;
}
}
else
{
driver_puts(driver_smbios, 2LL, "cannot found a valid smbios table");
result = 10LL;
}
return result;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 v0; // rbp
int v1; // ebx
__int64 result; // rax
unsigned int v3; // eax
__int64 v4; // r12

if ( smbios_mem || (unsigned int)func0(0LL) )
{
devfs_reg_device(0LL, 0LL, "smbios0");
v0 = smbios_mem;
if ( *(_WORD *)(smbios_mem + 28) )
{
v1 = 0;
do
{
v3 = *(_DWORD *)(v0 + 24) + v1 * *(unsigned __int16 *)(v0 + 22);
v4 = v3;
if ( *(_BYTE *)v3 == 4 )
{
printf("core_count: %d\n", *((unsigned __int8 *)&loc_E1 + v3 + 2));
printf("core_enabled: %d\n", *(unsigned __int8 *)(v4 + 228));
printf("voltage: %d\n", *(unsigned __int8 *)(v4 + 209));
printf("max_speed: %d\n", *(unsigned __int16 *)(v4 + 212));
}
++v1;
}
while ( *(unsigned __int16 *)(v0 + 28) > v1 );
result = 0LL;
}
else
{
result = 0LL;
}
}
else
{
driver_puts(driver_smbios, 2LL, "cannot found a valid smbios table");
result = 10LL;
}
return result;
}

original_code:
uint32_t smbios_init()
{
 if(smbios_mem == 0)
  if(smbios_probe(0) == 0)
  {
   driver_puts(&driver_smbios, 0x2, "cannot found a valid smbios table");
   return 10;
  }
 devfs_reg_device(0, 0, "smbios0");
 smbios_entry_t *smbios = (smbios_entry_t *) smbios_mem;
 int i;
 for(i = 0; i < smbios->number_of_struct; i++)
 {
  smbios_header_t *head = (smbios_header_t *) (smbios->table_address + smbios->table_length * i);
  if(head->type == 4)
  {
   smbios_type4_t *t4 = (smbios_type4_t *) head + sizeof(smbios_header_t);
   printf("core_count: %d\n", t4->core_count);
   printf("core_enabled: %d\n", t4->core_enabled);
   printf("voltage: %d\n", t4->voltage);
   printf("max_speed: %d\n", t4->max_speed);
  }
 }
 return 0;
}

canonical_original_code:
unsigned int smbios_init()
{
 if(smbios_mem == 0)
  if(smbios_probe(0) == 0)
  {
   driver_puts(&driver_smbios, 0x2, "cannot found a valid smbios table");
   return 10;
  }
 devfs_reg_device(0, 0, "smbios0");
 struct smbios_entry_t *smbios = (smbios_entry_t *) smbios_mem;
 int i;
 for(i = 0; i < smbios->number_of_struct; i++)
 {
  struct smbios_header_t *head = (smbios_header_t *) (smbios->table_address + smbios->table_length * i);
  if(head->type == 4)
  {
   struct smbios_type4_t *t4 = (smbios_type4_t *) head + sizeof(smbios_header_t);
   printf("core_count: %d\n", t4->core_count);
   printf("core_enabled: %d\n", t4->core_enabled);
   printf("voltage: %d\n", t4->voltage);
   printf("max_speed: %d\n", t4->max_speed);
  }
 }
 return 0;
}

variable_types: struct smbios_entry_t { char entry_string[4]; unsigned char checksum; unsigned char length; unsigned char major_version; unsigned char minor_version; unsigned short max_structure_size; unsigned char entry_revision; char formatted_area[5]; char entry_string2[5]; unsigned char checksum2; unsigned short table_length; unsigned int table_address; unsigned short number_of_struct; unsigned char bcd_revision; } *

variable_types: i int

variable_types: struct smbios_header_t { unsigned char type; unsigned char length; unsigned short handle; } *

variable_types: struct smbios_type4_t { unsigned char socket_designation; unsigned char proc_type; unsigned char proc_family; unsigned char proc_manufacturer; unsigned long long proc_id; unsigned char proc_version; unsigned char voltage; unsigned short external_clock; unsigned short max_speed; unsigned short current_speed; unsigned char status; unsigned char proc_upgrade; unsigned short l1_cache_handle; unsigned short l2_cache_handle; unsigned short l3_cache_handle; unsigned char serial_num; unsigned char asset_tag; unsigned char part_number; unsigned char core_count; unsigned char core_enabled; unsigned char thread_count; unsigned short proc_charact; unsigned short proc_family_2; } *


puts

decompiled_code:
void __fastcall puts(_BYTE *a1)
{
for ( ; *a1; ++a1 )
;
}

canonical_decompiled_code:
void __fastcall func1(_BYTE *a1)
{
for ( ; *a1; ++a1 )
;
}

original_code:
void puts(char *str)
{
 while(*str != '\0')
 {
  putchar(*str);
  str++;
 }
}

variable_types:
str
char *


atoi

decompiled_code:
__int64 __fastcall atoi(const char *a1)
{
const char *v1; // rdi
char v2; // al
int v3; // edx
unsigned int v4; // ecx

v1 = &a1[(unsigned int)strlen(a1) - 1];
v2 = *v1;
if ( !*v1 )
return 0;
v3 = 1;
v4 = 0;
do
{
v4 += v3 * (v2 - 48);
v3 *= 10;
v2 = *--v1;
}
while ( *v1 );
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1)
{
const char *v1; // rdi
char v2; // al
int v3; // edx
unsigned int v4; // ecx

v1 = &a1[(unsigned int)strlen(a1) - 1];
v2 = *v1;
if ( !*v1 )
return 0;
v3 = 1;
v4 = 0;
do
{
v4 += v3 * (v2 - 48);
v3 *= 10;
v2 = *--v1;
}
while ( *v1 );
return v4;
}

original_code:
int atoi(const char *str)
{
 int num = 0;
 int pot = 1;
 str += strlen(str)-1;
 while(*str != '\0')
 {
  num += ((int)(*str)-48) * pot;
  pot *= 10;
  str--;
 }
 return num;
}

canonical_original_code:
int atoi(char *str)
{
 int num = 0;
 int pot = 1;
 str += strlen(str)-1;
 while(*str != '\0')
 {
  num += ((int)(*str)-48) * pot;
  pot *= 10;
  str--;
 }
 return num;
}

variable_types: num int

variable_types: pot int

return_type: int


printf

original_code:
int printf(const char *format, ...)
{
 int len = 0;
 char output[255];
 char *current = &output[0];
 va_list ap;
 (ap = &format);
 while(*format != '\0')
 {
  if(*format == '%')
  {
   format++;
   switch (*format)
   {
    case 's':
     current = *((char * *)(ap += sizeof(int)));
     puts(current);
     break;
    case 'c':
     current = *((char * *)(ap += sizeof(int)));
     putchar(current[0]);
     break;
    case 'x':
     puts(itox(*((int *)(ap += sizeof(int)))));
     break;
    case 'd':
     puts(itoa(*((int *)(ap += sizeof(int)))));
     break;
    case '%':
     putchar('%');
     break;
   }
  }
  else
   putchar(*format);
  format++;
  len++;
 }
 return len;
}

canonical_original_code:
int printf(char *format, ...)
{
 int len = 0;
 char output[255];
 char *current = &output[0];
 void *ap;
 (ap = &format);
 while(*format != '\0')
 {
  if(*format == '%')
  {
   format++;
   switch (*format)
   {
    case 's':
     current = *((char **)(ap += sizeof(int)));
     puts(current);
     break;
    case 'c':
     current = *((char **)(ap += sizeof(int)));
     putchar(current[0]);
     break;
    case 'x':
     puts(itox(*((int *)(ap += sizeof(int)))));
     break;
    case 'd':
     puts(itoa(*((int *)(ap += sizeof(int)))));
     break;
    case '%':
     putchar('%');
     break;
   }
  }
  else
   putchar(*format);
  format++;
  len++;
 }
 return len;
}

variable_types:
format
char *

variable_types: len int

variable_types:
output
char [255]

variable_types:
current
char *

variable_types:
ap
void *


getchar

decompiled_code:
__int64 getchar()
{
char v0; // al

v0 = getch();
while ( !v0 )
;
return (unsigned int)v0;
}

canonical_decompiled_code:
__int64 func5()
{
char v0; // al

v0 = func4();
while ( !v0 )
;
return (unsigned int)v0;
}

original_code:
int getchar()
{
 char c;
 while((c = getch()) == 0);
 return c;
}

variable_types: c char


scanf

original_code:
int scanf(const char *format, ...)
{
 int len = 0;
 char buffer[255];
 char *current = &buffer[0];
 int *num;
 va_list ap;
 (ap = &format);
 while(*format != '\0')
 {
  if(*format == '%')
  {
   format++;
   switch (*format)
   {
    case 's':
     current = *((char * *)(ap += sizeof(int)));
     gets(current);
     break;
    case 'c':
     current = *((char * *)(ap += sizeof(int)));
     break;
    case 'd':
     num = *((int * *)(ap += sizeof(int)));
     gets(buffer);
     *num = atoi(buffer);
     break;
   }
  }
  format++;
  len++;
 }
 return len;
}

canonical_original_code:
int scanf(char *format, ...)
{
 int len = 0;
 char buffer[255];
 char *current = &buffer[0];
 int *num;
 void *ap;
 (ap = &format);
 while(*format != '\0')
 {
  if(*format == '%')
  {
   format++;
   switch (*format)
   {
    case 's':
     current = *((char **)(ap += sizeof(int)));
     gets(current);
     break;
    case 'c':
     current = *((char **)(ap += sizeof(int)));
     break;
    case 'd':
     num = *((int **)(ap += sizeof(int)));
     gets(buffer);
     *num = atoi(buffer);
     break;
   }
  }
  format++;
  len++;
 }
 return len;
}

variable_types:
buffer
char [255]

variable_types:
num
int *


fopen

decompiled_code:
void fopen()
{
;
}

canonical_decompiled_code:
void func7()
{
;
}

original_code:
FILE *fopen(const char *path, const char *mode)
{
}

canonical_original_code:
struct FILE *fopen(char *path, char *mode)
{
}

variable_types:
path
char *

variable_types:
mode
char *

return_type: struct FILE { unsigned int fn; } *


fclose

decompiled_code:
void fclose()
{
;
}

canonical_decompiled_code:
void func8()
{
;
}

original_code:
int fclose (FILE *fd)
{
}

canonical_original_code:
int fclose(struct FILE *fd)
{
}

variable_types:
fd
struct FILE { unsigned int fn; } *


fgetc

decompiled_code:
void fgetc()
{
;
}

canonical_decompiled_code:
void func9()
{
;
}

original_code:
int fgetc (FILE *fd)
{
}

canonical_original_code:
int fgetc(struct FILE *fd)
{
}


fputc

decompiled_code:
void fputc()
{
;
}

canonical_decompiled_code:
void func10()
{
;
}

original_code:
int fputc (int ch, FILE *fd)
{
}

canonical_original_code:
int fputc(int ch, struct FILE *fd)
{
}

variable_types: ch int


fseek

decompiled_code:
void fseek()
{
;
}

canonical_decompiled_code:
void func11()
{
;
}

original_code:
int fseek (FILE *fd, long int off, int type)
{
}

canonical_original_code:
int fseek(struct FILE *fd, long off, int type)
{
}

variable_types: off long

variable_types: type int


decompiled_code:
// write access to const memory has been detected, the output may be wrong!
__int64 __fastcall vesa_get_pixel(unsigned int a1, unsigned int a2)
{
if ( *(unsigned __int16 *)(vmi + 18) >= a1 && *(unsigned __int16 *)(vmi + 20) >= a2 )
*(_BYTE *)vesa_draw_pixel = *(_BYTE *)(*(unsigned int *)(vmi + 40)
+ (unsigned __int64)((*(_BYTE *)(vmi + 25) >> 3) * a1
+ *(unsigned __int16 *)(vmi + 16) * a2));
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, unsigned int a2)
{
if ( *(unsigned __int16 *)(vmi + 18) >= a1 && *(unsigned __int16 *)(vmi + 20) >= a2 )
*(_BYTE *)vesa_draw_pixel = *(_BYTE *)(*(unsigned int *)(vmi + 40)
+ (unsigned __int64)((*(_BYTE *)(vmi + 25) >> 3) * a1
+ *(unsigned __int16 *)(vmi + 16) * a2));
return 0LL;
}

original_code:
uint32_t vesa_get_pixel(uint32_t x, uint32_t y)
{
 register char *ptmp;
 if (x < 0 || x > vmi->width || y < 0 || y > vmi->height) return 0;
 x = (x * (vmi->bits_per_pixel >> 3));
 y = (y * vmi->bytes_per_scan_line);
 char *asd = (char *)vmi->phys_base_ptr;
 *ptmp = asd[x+y];
 return *ptmp;
}

canonical_original_code:
unsigned int vesa_get_pixel(unsigned int x, unsigned int y)
{
 register char *ptmp;
 if (x < 0 || x > vmi->width || y < 0 || y > vmi->height) return 0;
 x = (x * (vmi->bits_per_pixel >> 3));
 y = (y * vmi->bytes_per_scan_line);
 char *asd = (char *)vmi->phys_base_ptr;
 *ptmp = asd[x+y];
 return *ptmp;
}

variable_types:
x
unsigned int

variable_types:
y
unsigned int

variable_types:
ptmp
char *

variable_types:
asd
char *


decompiled_code:
void vesa_set_mode()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code:
uint32_t vesa_set_mode(uint32_t x, uint32_t y, uint32_t bit)
{
}

canonical_original_code:
unsigned int vesa_set_mode(unsigned int x, unsigned int y, unsigned int bit)
{
}

variable_types:
bit
unsigned int


decompiled_code:
__int64 vesa_get_mode_info()
{
return vmi;
}

canonical_decompiled_code:
__int64 func2()
{
return vmi;
}

canonical_original_code:
struct vesa_mode_info_t *vesa_get_mode_info()
{
 return vmi;
}

return_type: struct vesa_mode_info_t { unsigned short mode_attributes; unsigned char wina_attributes; unsigned char winb_attributes; unsigned short win_granularity; unsigned short win_size; unsigned short wina_segment; unsigned short winb_segment; unsigned int win_pos_func_ptr; unsigned short bytes_per_scan_line; unsigned short width; unsigned short height; unsigned char char_width; unsigned char char_height; unsigned char num_planes; unsigned char bits_per_pixel; unsigned char num_banks; unsigned char memory_model_type; unsigned char bank_size; unsigned char num_image_pages; unsigned char reserved1; unsigned char red_mask_size; unsigned char red_field_position; unsigned char green_mask_size; unsigned char green_field_position; unsigned char blue_mask_size; unsigned char blue_field_position; unsigned char reserved_mask_size; unsigned char reserved_mask_position; unsigned char direct_color_mode_info; unsigned int phys_base_ptr; unsigned int offscreen_mem_ptr; unsigned short offscreen_mem_size; unsigned short lin_bytes_per_scan_line; unsigned char bnk_num_image_pages; unsigned char lin_num_image_pages; unsigned char lin_red_mask_size; unsigned char lin_red_field_position; unsigned char lin_green_mask_size; unsigned char lin_green_field_position; unsigned char lin_blue_mask_size; unsigned char lin_blue_field_position; unsigned char lin_rsvd_mask_size; unsigned char lin_rsvd_field_position; unsigned int max_pixel_clock; unsigned char reserved4[190]; } *


decompiled_code:
void __fastcall vesa_init(__int64 a1, __int64 a2)
{
vci = a1;
vmi = a2;
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1, __int64 a2)
{
vci = a1;
vmi = a2;
}

original_code:
uint32_t vesa_init(void *vbe_control_info, void *vbe_mode_info)
{
 vci = (vesa_info_t *) vbe_control_info;
 vmi = (vesa_mode_info_t *) vbe_mode_info;
}

canonical_original_code:
unsigned int vesa_init(void *vbe_control_info, void *vbe_mode_info)
{
 vci = (struct vesa_info_t *) vbe_control_info;
 vmi = (struct vesa_mode_info_t *) vbe_mode_info;
}

user_defined_types: struct vesa_info_t { char signature[4]; unsigned short version; unsigned int oem_string_ptr; unsigned int capabilities; unsigned int video_mode_ptr; unsigned short total_memory; unsigned int oem_software_rev; char *oem_vendor_name; char *oem_product_name; char *oem_product_rev; }

user_defined_types: struct vesa_mode_info_t { unsigned short mode_attributes; unsigned char wina_attributes; unsigned char winb_attributes; unsigned short win_granularity; unsigned short win_size; unsigned short wina_segment; unsigned short winb_segment; unsigned int win_pos_func_ptr; unsigned short bytes_per_scan_line; unsigned short width; unsigned short height; unsigned char char_width; unsigned char char_height; unsigned char num_planes; unsigned char bits_per_pixel; unsigned char num_banks; unsigned char memory_model_type; unsigned char bank_size; unsigned char num_image_pages; unsigned char reserved1; unsigned char red_mask_size; unsigned char red_field_position; unsigned char green_mask_size; unsigned char green_field_position; unsigned char blue_mask_size; unsigned char blue_field_position; unsigned char reserved_mask_size; unsigned char reserved_mask_position; unsigned char direct_color_mode_info; unsigned int phys_base_ptr; unsigned int offscreen_mem_ptr; unsigned short offscreen_mem_size; unsigned short lin_bytes_per_scan_line; unsigned char bnk_num_image_pages; unsigned char lin_num_image_pages; unsigned char lin_red_mask_size; unsigned char lin_red_field_position; unsigned char lin_green_mask_size; unsigned char lin_green_field_position; unsigned char lin_blue_mask_size; unsigned char lin_blue_field_position; unsigned char lin_rsvd_mask_size; unsigned char lin_rsvd_field_position; unsigned int max_pixel_clock; unsigned char reserved4[190]; }


decompiled_code:
void eth_up()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
uint32_t eth_up(network_iface_t *iface)
{
}

canonical_original_code:
unsigned int eth_up(struct network_iface_p *iface)
{
}

variable_types: struct network_iface_p { char name[32]; char addr[4]; char mask[4]; char bcast[4]; char mac[6]; unsigned char if_up; unsigned char if_mac; unsigned char if_bcast; unsigned char type; unsigned int tx_bytes; unsigned int rx_bytes; struct driver_p { char name[32]; char desc[128]; char author[128]; unsigned char type; struct driver_fs_t { unsigned int (*mount)(char *, unsigned int, struct inode_p { char name[255]; unsigned int inode_n; unsigned char type; unsigned char ow; void *fs_node; void *fs_driver; struct inode_p *link; struct inode_p *next; struct inode_p *prev; struct inode_p *parent; struct inode_p *childs; } *); unsigned int (*umount)(struct inode_p *); unsigned int (*mkdir)(struct inode_p *, char *); unsigned int (*readdir)(struct inode_p *, unsigned int, struct dirent { char name[255]; unsigned int inode; } *); unsigned int (*get_node)(struct inode_p *, unsigned int, struct inode_p **); unsigned int (*delete_node)(struct inode_p *, char *); unsigned int (*create_node)(struct inode_p *, char *, unsigned int); unsigned int (*write_stat)(struct inode_p *, struct stat { unsigned int st_dev; unsigned int st_ino; int st_uid; int st_gid; unsigned long long st_blksize; unsigned long long st_blocks; } *, unsigned int); unsigned int (*read_stat)(struct inode_p *, struct stat *); unsigned int (*open)(struct inode_p *, char *); unsigned int (*close)(struct inode_p *); unsigned int (*read)(struct inode_p *, char *, unsigned int, unsigned long long); unsigned int (*write)(struct inode_p *, char *, unsigned int, unsigned long long); unsigned int (*link)(struct inode_p *, char *, struct inode_p *, char *); unsigned int (*unlink)(struct inode_p *, char *); unsigned char ifdev; } fs; struct driver_video_t { char *buffer; void (*put_pixel)(unsigned int, unsigned int, unsigned int); unsigned int (*get_pixel)(unsigned int, unsigned int); unsigned int (*set_mode)(unsigned int, unsigned int, unsigned int); } video; unsigned char loaded; unsigned int (*init)(); unsigned int (*free)(); unsigned int (*probe)(struct device_p { unsigned int io_base; char vendor[32]; char vendor_full[32]; char device[32]; char device_desc[32]; char class[32]; char class_desc[32]; char class_prog_desc[32]; unsigned char bus_type; void *pci_dev; unsigned char interrupt; unsigned int base_addresses[6]; char file[32]; struct device_p *next; } *); unsigned int (*read)(struct device_p *, char *, unsigned int, unsigned long long); unsigned int (*write)(struct device_p *, char *, unsigned int, unsigned long long); unsigned int (*ioctl)(struct device_p *, unsigned int, unsigned int, unsigned int); struct driver_p *next; } *drv; struct device_p *dev; void *link_protocol; struct network_iface_p *next; } *

user_defined_types: struct network_iface_p { char name[32]; char addr[4]; char mask[4]; char bcast[4]; char mac[6]; unsigned char if_up; unsigned char if_mac; unsigned char if_bcast; unsigned char type; unsigned int tx_bytes; unsigned int rx_bytes; struct driver_p *drv; struct device_p *dev; void *link_protocol; struct network_iface_p *next; }

user_defined_types: struct driver_p { char name[32]; char desc[128]; char author[128]; unsigned char type; struct driver_fs_t fs; struct driver_video_t video; unsigned char loaded; unsigned int (*init)(); unsigned int (*free)(); unsigned int (*probe)(struct device_p *); unsigned int (*read)(struct device_p *, char *, unsigned int, unsigned long long); unsigned int (*write)(struct device_p *, char *, unsigned int, unsigned long long); unsigned int (*ioctl)(struct device_p *, unsigned int, unsigned int, unsigned int); struct driver_p *next; }

user_defined_types: struct driver_fs_t { unsigned int (*mount)(char *, unsigned int, struct inode_p *); unsigned int (*umount)(struct inode_p *); unsigned int (*mkdir)(struct inode_p *, char *); unsigned int (*readdir)(struct inode_p *, unsigned int, struct dirent *); unsigned int (*get_node)(struct inode_p *, unsigned int, struct inode_p **); unsigned int (*delete_node)(struct inode_p *, char *); unsigned int (*create_node)(struct inode_p *, char *, unsigned int); unsigned int (*write_stat)(struct inode_p *, struct stat *, unsigned int); unsigned int (*read_stat)(struct inode_p *, struct stat *); unsigned int (*open)(struct inode_p *, char *); unsigned int (*close)(struct inode_p *); unsigned int (*read)(struct inode_p *, char *, unsigned int, unsigned long long); unsigned int (*write)(struct inode_p *, char *, unsigned int, unsigned long long); unsigned int (*link)(struct inode_p *, char *, struct inode_p *, char *); unsigned int (*unlink)(struct inode_p *, char *); unsigned char ifdev; }


decompiled_code:
void eth_down()
{
;
}

original_code:
uint32_t eth_down(network_iface_t *iface)
{
}

canonical_original_code:
unsigned int eth_down(struct network_iface_p *iface)
{
}

user_defined_types: struct driver_video_t { char *buffer; void (*put_pixel)(unsigned int, unsigned int, unsigned int); unsigned int (*get_pixel)(unsigned int, unsigned int); unsigned int (*set_mode)(unsigned int, unsigned int, unsigned int); }

user_defined_types: struct device_p { unsigned int io_base; char vendor[32]; char vendor_full[32]; char device[32]; char device_desc[32]; char class[32]; char class_desc[32]; char class_prog_desc[32]; unsigned char bus_type; void *pci_dev; unsigned char interrupt; unsigned int base_addresses[6]; char file[32]; struct device_p *next; }

user_defined_types: struct inode_p { char name[255]; unsigned int inode_n; unsigned char type; unsigned char ow; void *fs_node; void *fs_driver; struct inode_p *link; struct inode_p *next; struct inode_p *prev; struct inode_p *parent; struct inode_p *childs; }

user_defined_types: struct dirent { char name[255]; unsigned int inode; }

user_defined_types: struct stat { unsigned int st_dev; unsigned int st_ino; int st_uid; int st_gid; unsigned long long st_blksize; unsigned long long st_blocks; }


decompiled_code:
__int64 __fastcall eth_handle_frame(__int64 a1, unsigned int *a2)
{
if ( *(_WORD *)(*((_QWORD *)a2 + 1) + 20LL) <= 0x5DBu )
{
printf("eth: received packet (sizeof %d)\n", *a2);
packet_del_header(a2, 26LL);
ip_handle_packet(a1, a2);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, unsigned int *a2)
{
if ( *(_WORD *)(*((_QWORD *)a2 + 1) + 20LL) <= 0x5DBu )
{
printf("eth: received packet (sizeof %d)\n", *a2);
packet_del_header(a2, 26LL);
ip_handle_packet(a1, a2);
}
return 0LL;
}

original_code:
uint32_t eth_handle_frame(network_iface_t *iface, packet_t *p)
{
 eth_header_t *ethead = (eth_header_t *) p->data;
 if(ethead->len < 1500)
 {
  printf("eth: received packet (sizeof %d)\n", p->size);
  packet_del_header(p, sizeof(eth_header_t));
  ip_handle_packet(iface, p);
 }
 return 0;
}

canonical_original_code:
unsigned int eth_handle_frame(struct network_iface_p *iface, struct packet_t *p)
{
 struct eth_header_t *ethead = (eth_header_t *) p->data;
 if(ethead->len < 1500)
 {
  printf("eth: received packet (sizeof %d)\n", p->size);
  packet_del_header(p, sizeof(eth_header_t));
  ip_handle_packet(iface, p);
 }
 return 0;
}

variable_types: struct packet_t { unsigned int size; char *data; } *

variable_types: struct eth_header_t { unsigned char preamble[7]; unsigned char sfd; char dest[6]; char source[6]; unsigned short len; struct llc_t { unsigned char dsap; unsigned char ssap; unsigned char control; } llc; } *

user_defined_types: struct eth_header_t { unsigned char preamble[7]; unsigned char sfd; char dest[6]; char source[6]; unsigned short len; struct llc_t llc; }


original_code:
uint32_t eth_send_frame(network_iface_t *iface, packet_t *p)
{
 ip_header_t *iphead = (ip_header_t *) p->data;
 packet_add_header(p, sizeof(eth_header_t));
 eth_header_t *ethead = (eth_header_t *) p->data;
 ethead->preamble[0] = 0xAA;
 ethead->preamble[1] = 0xAA;
 ethead->preamble[2] = 0xAA;
 ethead->preamble[3] = 0xAA;
 ethead->preamble[4] = 0xAA;
 ethead->preamble[5] = 0xAA;
 ethead->preamble[6] = 0xAA;
 ethead->sfd = 0xAB;
 arp_resolve((char *) &iphead->dest, ethead->dest);
 arp_resolve((char *) &iphead->source, ethead->source);
 ethead->len = sizeof(p->data);
 uint32_t sended_b;
 if((iface->drv)->write != 0)
  sended_b = (iface->drv)->write(iface->dev, p->data, p->size, 0);
 else
  return 0;
 iface->tx_bytes = iface->tx_bytes + sended_b;
 return sended_b;
}

canonical_original_code:
unsigned int eth_send_frame(struct network_iface_p *iface, struct packet_t *p)
{
 struct ip_header_t *iphead = (ip_header_t *) p->data;
 packet_add_header(p, sizeof(eth_header_t));
 struct eth_header_t *ethead = (eth_header_t *) p->data;
 ethead->preamble[0] = 0xAA;
 ethead->preamble[1] = 0xAA;
 ethead->preamble[2] = 0xAA;
 ethead->preamble[3] = 0xAA;
 ethead->preamble[4] = 0xAA;
 ethead->preamble[5] = 0xAA;
 ethead->preamble[6] = 0xAA;
 ethead->sfd = 0xAB;
 arp_resolve((char *) &iphead->dest, ethead->dest);
 arp_resolve((char *) &iphead->source, ethead->source);
 ethead->len = sizeof(p->data);
 unsigned int sended_b;
 if((iface->drv)->write != 0)
  sended_b = (iface->drv)->write(iface->dev, p->data, p->size, 0);
 else
  return 0;
 iface->tx_bytes = iface->tx_bytes + sended_b;
 return sended_b;
}

variable_types: struct ip_header_t { unsigned char version; unsigned char head_len; unsigned char tos; unsigned short total_len; unsigned short ident; unsigned char flags; unsigned short offset; unsigned char time_to_live; unsigned char protocol; unsigned short header_checksum; unsigned int source; unsigned int dest; } *

user_defined_types: struct packet_t { unsigned int size; char *data; }

user_defined_types: struct llc_t { unsigned char dsap; unsigned char ssap; unsigned char control; }


decompiled_code:
int clear_screen()
{
return system("clear");
}

canonical_decompiled_code:
int func0()
{
return system("clear");
}

original_code:
void clear_screen()
{
 system("clear");
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
clear_screen();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func0();
return 0;
}

original_code:
int main(int argc, char **argv)
{
 int choice;
 clear_screen();
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: choice int


decompiled_code:
void apic_probe()
{
;
}

original_code:
uint32_t apic_probe()
{
 uint16_t a;
 uint16_t d;
}

canonical_original_code:
unsigned int apic_probe()
{
 unsigned short a;
 unsigned short d;
}

variable_types:
a
unsigned short

variable_types:
d
unsigned short


decompiled_code:
__int64 apic_get_base()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
return 0LL;
}

original_code:
uint32_t apic_get_base()
{
 uint16_t a;
 uint16_t d;
 return (a&0xfffff000);
}

canonical_original_code:
unsigned int apic_get_base()
{
 unsigned short a;
 unsigned short d;
 return (a&0xfffff000);
}


decompiled_code:
void __fastcall udp_handle_packet(__int64 a1, unsigned int *a2)
{
unsigned int v2; // ebx
__int64 v4; // r12
__int64 v5; // rax
unsigned int v6; // esi
__int64 v7; // rcx
int v8; // edx
__int64 v9[4]; // [rsp+8h] [rbp-20h] BYREF

v4 = *((_QWORD *)a2 + 1);
if ( (unsigned int)video_getx() )
printf("\n");
printf("udp: received packet (sizeof %d) on port %x\n", *a2 - 28LL, *(unsigned __int16 *)(v4 + 162));
while ( (unsigned int)sock_iget(v2, v9) )
{
v5 = v9[0];
if ( *(_WORD *)(v9[0] + 22) == *(_WORD *)(v4 + 160) )
{
if ( *a2 != 28 )
{
v6 = 0;
v7 = 0LL;
do
{
v8 = *(_DWORD *)(v5 + 8228);
*(_BYTE *)(v5 + v8 + 36) = *(_BYTE *)(*((_QWORD *)a2 + 1) + v7 + 28);
*(_DWORD *)(v5 + 8228) = v8 + 1;
++*(_DWORD *)(v5 + 8236);
v7 = ++v6;
}
while ( v6 < (unsigned __int64)*a2 - 28 );
}
break;
}
++v2;
}
free(a2);
}

original_code:
uint32_t udp_handle_packet(network_iface_t *iface, packet_t *p)
{
 ip_header_t *iphead = (ip_header_t *) p->data;
 udp_header_t *udphead = (udp_header_t *) p->data + sizeof(ip_header_t);
 if(video_getx() != 0)
  printf("\n");
 printf("udp: received packet (sizeof %d) on port %x\n", p->size - sizeof(ip_header_t) - sizeof(udp_header_t), udphead->dest_port);
 socket_t *s;
 uint32_t i;
 while(sock_iget(i, &s))
 {
  if(s->port == udphead->source_port)
  {
   for(i = 0; i < (p->size - sizeof(ip_header_t) - sizeof(udp_header_t)); i++)
   {
    s->rec_buf[s->rec_p1] = p->data[i + sizeof(udp_header_t) + sizeof(ip_header_t)];
    s->rec_p1++;
    s->rec_data_len++;
   }
   break;
  }
  i++;
 }
 free(p);
}

canonical_original_code:
unsigned int udp_handle_packet(struct network_iface_p *iface, struct packet_t *p)
{
 struct ip_header_t *iphead = (ip_header_t *) p->data;
 struct udp_header_t *udphead = (udp_header_t *) p->data + sizeof(ip_header_t);
 if(video_getx() != 0)
  printf("\n");
 printf("udp: received packet (sizeof %d) on port %x\n", p->size - sizeof(ip_header_t) - sizeof(udp_header_t), udphead->dest_port);
 struct socket_t *s;
 unsigned int i;
 while(sock_iget(i, &s))
 {
  if(s->port == udphead->source_port)
  {
   for(i = 0; i < (p->size - sizeof(ip_header_t) - sizeof(udp_header_t)); i++)
   {
    s->rec_buf[s->rec_p1] = p->data[i + sizeof(udp_header_t) + sizeof(ip_header_t)];
    s->rec_p1++;
    s->rec_data_len++;
   }
   break;
  }
  i++;
 }
 free(p);
}

variable_types: struct udp_header_t { unsigned short source_port; unsigned short dest_port; unsigned short lenght; unsigned short checksum; } *

variable_types: struct socket_t { struct network_iface_p { char name[32]; char addr[4]; char mask[4]; char bcast[4]; char mac[6]; unsigned char if_up; unsigned char if_mac; unsigned char if_bcast; unsigned char type; unsigned int tx_bytes; unsigned int rx_bytes; struct driver_p { char name[32]; char desc[128]; char author[128]; unsigned char type; struct driver_fs_t { unsigned int (*mount)(char *, unsigned int, struct inode_p { char name[255]; unsigned int inode_n; unsigned char type; unsigned char ow; void *fs_node; void *fs_driver; struct inode_p *link; struct inode_p *next; struct inode_p *prev; struct inode_p *parent; struct inode_p *childs; } *); unsigned int (*umount)(struct inode_p *); unsigned int (*mkdir)(struct inode_p *, char *); unsigned int (*readdir)(struct inode_p *, unsigned int, struct dirent { char name[255]; unsigned int inode; } *); unsigned int (*get_node)(struct inode_p *, unsigned int, struct inode_p **); unsigned int (*delete_node)(struct inode_p *, char *); unsigned int (*create_node)(struct inode_p *, char *, unsigned int); unsigned int (*write_stat)(struct inode_p *, struct stat { unsigned int st_dev; unsigned int st_ino; int st_uid; int st_gid; unsigned long long st_blksize; unsigned long long st_blocks; } *, unsigned int); unsigned int (*read_stat)(struct inode_p *, struct stat *); unsigned int (*open)(struct inode_p *, char *); unsigned int (*close)(struct inode_p *); unsigned int (*read)(struct inode_p *, char *, unsigned int, unsigned long long); unsigned int (*write)(struct inode_p *, char *, unsigned int, unsigned long long); unsigned int (*link)(struct inode_p *, char *, struct inode_p *, char *); unsigned int (*unlink)(struct inode_p *, char *); unsigned char ifdev; } fs; struct driver_video_t { char *buffer; void (*put_pixel)(unsigned int, unsigned int, unsigned int); unsigned int (*get_pixel)(unsigned int, unsigned int); unsigned int (*set_mode)(unsigned int, unsigned int, unsigned int); } video; unsigned char loaded; unsigned int (*init)(); unsigned int (*free)(); unsigned int (*probe)(struct device_p { unsigned int io_base; char vendor[32]; char vendor_full[32]; char device[32]; char device_desc[32]; char class[32]; char class_desc[32]; char class_prog_desc[32]; unsigned char bus_type; void *pci_dev; unsigned char interrupt; unsigned int base_addresses[6]; char file[32]; struct device_p *next; } *); unsigned int (*read)(struct device_p *, char *, unsigned int, unsigned long long); unsigned int (*write)(struct device_p *, char *, unsigned int, unsigned long long); unsigned int (*ioctl)(struct device_p *, unsigned int, unsigned int, unsigned int); struct driver_p *next; } *drv; struct device_p *dev; void *link_protocol; struct network_iface_p *next; } *iface; unsigned int protocol; unsigned int type; unsigned int domain; unsigned char is_server; unsigned short port; char addr[4]; int uid; unsigned int used; char rec_buf[8192]; int rec_p1; int rec_p2; int rec_data_len; char send_buf[8192]; int send_p1; int send_p2; int send_data_len; } *

variable_types:
i
unsigned int

user_defined_types: struct ip_header_t { unsigned char version; unsigned char head_len; unsigned char tos; unsigned short total_len; unsigned short ident; unsigned char flags; unsigned short offset; unsigned char time_to_live; unsigned char protocol; unsigned short header_checksum; unsigned int source; unsigned int dest; }

user_defined_types: struct socket_t { struct network_iface_p *iface; unsigned int protocol; unsigned int type; unsigned int domain; unsigned char is_server; unsigned short port; char addr[4]; int uid; unsigned int used; char rec_buf[8192]; int rec_p1; int rec_p2; int rec_data_len; char send_buf[8192]; int send_p1; int send_p2; int send_data_len; }


decompiled_code:
__int64 __fastcall udp_send_packet(__int64 a1, __int64 a2)
{
_WORD *v2; // rax
__int16 v3; // dx

printf("sending udp pack\n");
packet_add_header(a2, 8LL);
v2 = *(_WORD **)(a2 + 8);
v3 = *(_WORD *)(a1 + 22);
*v2 = v3;
v2[1] = v3;
return ip_send_frame(*(_QWORD *)a1, a2, a1 + 24, *(unsigned __int8 *)(a1 + 8));
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
_WORD *v2; // rax
__int16 v3; // dx

printf("sending udp pack\n");
packet_add_header(a2, 8LL);
v2 = *(_WORD **)(a2 + 8);
v3 = *(_WORD *)(a1 + 22);
*v2 = v3;
v2[1] = v3;
return ip_send_frame(*(_QWORD *)a1, a2, a1 + 24, *(unsigned __int8 *)(a1 + 8));
}

original_code:
uint32_t udp_send_packet(socket_t *s, packet_t *p)
{
 printf("sending udp pack\n");
 packet_add_header(p, sizeof(udp_header_t));
 udp_header_t *h = p->data;
 h->source_port = s->port;
 h->dest_port = s->port;
 return ip_send_frame(s->iface, p, s->addr, s->protocol);
}

canonical_original_code:
unsigned int udp_send_packet(struct socket_t *s, struct packet_t *p)
{
 printf("sending udp pack\n");
 packet_add_header(p, sizeof(udp_header_t));
 struct udp_header_t *h = p->data;
 h->source_port = s->port;
 h->dest_port = s->port;
 return ip_send_frame(s->iface, p, s->addr, s->protocol);
}

user_defined_types: struct udp_header_t { unsigned short source_port; unsigned short dest_port; unsigned short lenght; unsigned short checksum; }


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

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

original_code:
uint32_t pfs_umount(inode_t *root)
{
 return 1;
}

canonical_original_code:
unsigned int pfs_umount(struct inode_p *root)
{
 return 1;
}

variable_types: struct inode_p { char name[255]; unsigned int inode_n; unsigned char type; unsigned char ow; void *fs_node; void *fs_driver; struct inode_p *link; struct inode_p *next; struct inode_p *prev; struct inode_p *parent; struct inode_p *childs; } *


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

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

original_code:
uint32_t pfs_mount(char *dev, uint32_t flags, inode_t *root)
{
 return 1;
}

canonical_original_code:
unsigned int pfs_mount(char *dev, unsigned int flags, struct inode_p *root)
{
 return 1;
}

variable_types:
dev
char *

variable_types:
flags
unsigned int


decompiled_code:
void pfs_read_node()
{
;
}

canonical_decompiled_code:
void func2()
{
;
}

original_code:
uint32_t pfs_read_node(int n, pfs_nodeblock_t *node)
{
}

canonical_original_code:
unsigned int pfs_read_node(int n, struct pfs_nodeblock_t *node)
{
}

variable_types: n int

variable_types: struct pfs_nodeblock_t { unsigned short checksum; char name[128]; unsigned char type; unsigned long long offset; unsigned long long number; unsigned long long parent_n; unsigned long long size; } *


fdopendir

decompiled_code:
__int64 fdopendir()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
return 0LL;
}

original_code:
DIR *fdopendir(int fd)
{
 return 0;
}

canonical_original_code:
struct DIR *fdopendir(int fd)
{
 return 0;
}

variable_types: fd int

return_type: struct DIR { unsigned int i; } *


closedir

decompiled_code:
__int64 closedir()
{
return 0LL;
}

original_code:
int closedir(DIR *fd)
{
 return 0;
}

canonical_original_code:
int closedir(struct DIR *fd)
{
 return 0;
}

variable_types:
fd
struct DIR { unsigned int i; } *


readdir

decompiled_code:
__int64 readdir()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func2()
{
return 0LL;
}

original_code:
int readdir(unsigned int fd, struct dirent *d, unsigned int off)
{
 return 0;
}

variable_types:
fd
unsigned int

variable_types:
d
struct dirent { unsigned int i; } *

variable_types:
off
unsigned int


decompiled_code:
__int64 device_update()
{
void *v0; // rbx
void *v1; // rdi
__int64 result; // rax
char *v3; // rbx
char v4[56]; // [rsp+0h] [rbp-38h] BYREF

v0 = device_list;
while ( v0 )
{
v1 = v0;
v0 = (void *)*((_QWORD *)v0 + 38);
free(v1);
}
device_list = 0LL;
result = pci_update(&device_list);
v3 = (char *)device_list;
if ( device_list )
{
do
{
devfs_find_freen(v3 + 268, v4);
strcpy(v3 + 268, v4);
result = devfs_reg_device(v3, 0LL, v3 + 268);
v3 = (char *)*((_QWORD *)v3 + 38);
}
while ( v3 );
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
void *v0; // rbx
void *v1; // rdi
__int64 result; // rax
char *v3; // rbx
char v4[56]; // [rsp+0h] [rbp-38h] BYREF

v0 = device_list;
while ( v0 )
{
v1 = v0;
v0 = (void *)*((_QWORD *)v0 + 38);
free(v1);
}
device_list = 0LL;
result = pci_update(&device_list);
v3 = (char *)device_list;
if ( device_list )
{
do
{
devfs_find_freen(v3 + 268, v4);
strcpy(v3 + 268, v4);
result = devfs_reg_device(v3, 0LL, v3 + 268);
v3 = (char *)*((_QWORD *)v3 + 38);
}
while ( v3 );
}
return result;
}

original_code:
void device_update()
{
 device_t *dev;
 device_t *next;
 dev = device_list;
 while(dev != 0)
 {
  next = dev->next;
  free(dev);
  dev = next;
 }
 device_list = 0;
  pci_update(&device_list);
 dev = device_list;
 while(dev != 0)
 {
  char tmp[32];
  devfs_find_freen(dev->file, tmp);
  strcpy(dev->file, tmp);
  devfs_reg_device(dev, 0, dev->file);
  switch(dev->bus_type)
  {
   case 0x01:
    break;
   default:
    break;
  }
  dev = dev->next;
 }
}

canonical_original_code:
void device_update()
{
 struct device_p *dev;
 struct device_p *next;
 dev = device_list;
 while(dev != 0)
 {
  next = dev->next;
  free(dev);
  dev = next;
 }
 device_list = 0;
  pci_update(&device_list);
 dev = device_list;
 while(dev != 0)
 {
  char tmp[32];
  devfs_find_freen(dev->file, tmp);
  strcpy(dev->file, tmp);
  devfs_reg_device(dev, 0, dev->file);
  switch(dev->bus_type)
  {
   case 0x01:
    break;
   default:
    break;
  }
  dev = dev->next;
 }
}

variable_types: struct device_p { unsigned int io_base; char vendor[32]; char vendor_full[32]; char device[32]; char device_desc[32]; char class[32]; char class_desc[32]; char class_prog_desc[32]; unsigned char bus_type; void *pci_dev; unsigned char interrupt; unsigned int base_addresses[6]; char file[32]; struct device_p *next; } *

variable_types:
tmp
char [32]


decompiled_code:
__int64 __fastcall device_iget(int a1, _QWORD *a2)
{
_QWORD *v2; // rax
int v3; // edx
__int64 result; // rax

v2 = device_list;
*a2 = 0LL;
if ( !v2 )
return 1LL;
if ( a1 )
{
v3 = 0;
while ( 1 )
{
++v3;
v2 = (_QWORD *)v2[38];
if ( !v2 )
break;
if ( a1 == v3 )
goto LABEL_6;
}
result = 1LL;
}
else
{
LABEL_6:
*a2 = v2;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, _QWORD *a2)
{
_QWORD *v2; // rax
int v3; // edx
__int64 result; // rax

v2 = device_list;
*a2 = 0LL;
if ( !v2 )
return 1LL;
if ( a1 )
{
v3 = 0;
while ( 1 )
{
++v3;
v2 = (_QWORD *)v2[38];
if ( !v2 )
break;
if ( a1 == v3 )
goto LABEL_6;
}
result = 1LL;
}
else
{
LABEL_6:
*a2 = v2;
result = 0LL;
}
return result;
}

original_code:
uint32_t device_iget(uint32_t x, device_t **dev)
{
 device_t *cf = device_list;
 uint32_t i = 0;
 *dev = 0;
 while(cf != 0)
 {
  if(i == x)
  {
   *dev = cf;
   return 0;
  }
  i++;
  cf = cf->next;
 }
 return 1;
}

canonical_original_code:
unsigned int device_iget(unsigned int x, struct device_p **dev)
{
 struct device_p *cf = device_list;
 unsigned int i = 0;
 *dev = 0;
 while(cf != 0)
 {
  if(i == x)
  {
   *dev = cf;
   return 0;
  }
  i++;
  cf = cf->next;
 }
 return 1;
}

variable_types:
x
unsigned int

variable_types: struct device_p { unsigned int io_base; char vendor[32]; char vendor_full[32]; char device[32]; char device_desc[32]; char class[32]; char class_desc[32]; char class_prog_desc[32]; unsigned char bus_type; void *pci_dev; unsigned char interrupt; unsigned int base_addresses[6]; char file[32]; struct device_p *next; } **


decompiled_code:
__int64 __fastcall icmp_handle_packet(__int64 a1, unsigned int *a2)
{
__int64 v2; // r13
unsigned __int8 v3; // bl
__int64 v5; // rsi
__int64 v6; // rax

v2 = *((_QWORD *)a2 + 1);
v3 = *(_BYTE *)(v2 + 80);
if ( (unsigned int)video_getx() )
printf("\n");
printf("icmp: received packet (sizeof %d) request: %d: ", *a2, v3);
switch ( v3 )
{
case 0u:
printf("pong\n");
break;
case 3u:
printf("destination not reachable\n");
break;
case 4u:
printf("source quench\n");
break;
case 5u:
printf("redirect\n");
break;
case 6u:
printf("alternative host address\n");
break;
case 8u:
printf("ping\n");
v5 = packet_create(0LL, 4LL);
v6 = *(_QWORD *)(v5 + 8);
*(_BYTE *)v6 = 0;
*(_WORD *)(v6 + 2) = 0;
ip_send_frame(a1, v5, v2 + 12, 1LL);
break;
case 9u:
printf("router advertisement\n");
break;
case 0xAu:
printf("router selection\n");
break;
case 0xBu:
printf("expired request\n");
break;
case 0xCu:
printf("parameters error\n");
break;
case 0xDu:
printf("timestamp request\n");
break;
case 0xEu:
printf("timestamp reply\n");
break;
case 0xFu:
printf("information request\n");
break;
case 0x10u:
printf("information reply\n");
break;
case 0x11u:
printf("address mask request\n");
break;
case 0x12u:
printf("address mask reply\n");
break;
case 0x1Eu:
printf("traceroute\n");
break;
case 0x1Fu:
printf("datagram conversion error\n");
break;
case 0x20u:
printf("mobile host redirect\n");
break;
case 0x21u:
printf("ipv6 where are you?\n");
break;
case 0x22u:
printf("ipv6 i'm here!\n");
break;
case 0x23u:
printf("mobile registration request\n");
break;
case 0x24u:
printf("mobile registration reply\n");
break;
case 0x25u:
printf("domain name request\n");
break;
case 0x26u:
printf("domain name reply\n");
break;
default:
return 0LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned int *a2)
{
__int64 v2; // r13
unsigned __int8 v3; // bl
__int64 v5; // rsi
__int64 v6; // rax

v2 = *((_QWORD *)a2 + 1);
v3 = *(_BYTE *)(v2 + 80);
if ( (unsigned int)video_getx() )
printf("\n");
printf("icmp: received packet (sizeof %d) request: %d: ", *a2, v3);
switch ( v3 )
{
case 0u:
printf("pong\n");
break;
case 3u:
printf("destination not reachable\n");
break;
case 4u:
printf("source quench\n");
break;
case 5u:
printf("redirect\n");
break;
case 6u:
printf("alternative host address\n");
break;
case 8u:
printf("ping\n");
v5 = packet_create(0LL, 4LL);
v6 = *(_QWORD *)(v5 + 8);
*(_BYTE *)v6 = 0;
*(_WORD *)(v6 + 2) = 0;
ip_send_frame(a1, v5, v2 + 12, 1LL);
break;
case 9u:
printf("router advertisement\n");
break;
case 0xAu:
printf("router selection\n");
break;
case 0xBu:
printf("expired request\n");
break;
case 0xCu:
printf("parameters error\n");
break;
case 0xDu:
printf("timestamp request\n");
break;
case 0xEu:
printf("timestamp reply\n");
break;
case 0xFu:
printf("information request\n");
break;
case 0x10u:
printf("information reply\n");
break;
case 0x11u:
printf("address mask request\n");
break;
case 0x12u:
printf("address mask reply\n");
break;
case 0x1Eu:
printf("traceroute\n");
break;
case 0x1Fu:
printf("datagram conversion error\n");
break;
case 0x20u:
printf("mobile host redirect\n");
break;
case 0x21u:
printf("ipv6 where are you?\n");
break;
case 0x22u:
printf("ipv6 i'm here!\n");
break;
case 0x23u:
printf("mobile registration request\n");
break;
case 0x24u:
printf("mobile registration reply\n");
break;
case 0x25u:
printf("domain name request\n");
break;
case 0x26u:
printf("domain name reply\n");
break;
default:
return 0LL;
}
return 0LL;
}

original_code:
uint32_t icmp_handle_packet(network_iface_t *iface, packet_t *p)
{
 uint8_t protocol;
 ip_header_t *iphead = (ip_header_t *) p->data;
 icmp_header_t *icmphead = (icmp_header_t *) p->data + sizeof(ip_header_t);
 protocol = icmphead->type;
 if(video_getx() != 0)
  printf("\n");
 printf("icmp: received packet (sizeof %d) request: %d: ", p->size, protocol);
 switch(protocol)
 {
  case 0:
   printf("pong\n");
   break;
  case 8:
   printf("ping\n");
   packet_t *pong = packet_create(0, sizeof(icmp_header_t));
   icmp_header_t *ponghead = (icmp_header_t *) pong->data;
   ponghead->type = 0;
   ponghead->checksum = 0;
   ip_send_frame(iface, pong, (char *) &(iphead->source), 1);
   break;
  case 5:
   printf("redirect\n");
   break;
  case 4:
   printf("source quench\n");
   break;
  case 3:
   printf("destination not reachable\n");
   break;
  case 6:
   printf("alternative host address\n");
   break;
  case 9:
   printf("router advertisement\n");
   break;
  case 10:
   printf("router selection\n");
   break;
  case 33:
   printf("ipv6 where are you?\n");
   break;
  case 34:
   printf("ipv6 i'm here!\n");
   break;
  case 17:
   printf("address mask request\n");
   break;
  case 18:
   printf("address mask reply\n");
   break;
  case 13:
   printf("timestamp request\n");
   break;
  case 14:
   printf("timestamp reply\n");
   break;
  case 15:
   printf("information request\n");
   break;
  case 16:
   printf("information reply\n");
   break;
  case 30:
   printf("traceroute\n");
   break;
  case 32:
   printf("mobile host redirect\n");
   break;
  case 35:
   printf("mobile registration request\n");
   break;
  case 36:
   printf("mobile registration reply\n");
   break;
  case 37:
   printf("domain name request\n");
   break;
  case 38:
   printf("domain name reply\n");
   break;
  case 31:
   printf("datagram conversion error\n");
   break;
  case 11:
   printf("expired request\n");
   break;
  case 12:
   printf("parameters error\n");
   break;
  default:
   break;
 }
 return 0;
}

canonical_original_code:
unsigned int icmp_handle_packet(struct network_iface_p *iface, struct packet_t *p)
{
 unsigned char protocol;
 struct ip_header_t *iphead = (ip_header_t *) p->data;
 struct icmp_header_t *icmphead = (icmp_header_t *) p->data + sizeof(ip_header_t);
 protocol = icmphead->type;
 if(video_getx() != 0)
  printf("\n");
 printf("icmp: received packet (sizeof %d) request: %d: ", p->size, protocol);
 switch(protocol)
 {
  case 0:
   printf("pong\n");
   break;
  case 8:
   printf("ping\n");
   struct packet_t *pong = packet_create(0, sizeof(icmp_header_t));
   struct icmp_header_t *ponghead = (icmp_header_t *) pong->data;
   ponghead->type = 0;
   ponghead->checksum = 0;
   ip_send_frame(iface, pong, (char *) &(iphead->source), 1);
   break;
  case 5:
   printf("redirect\n");
   break;
  case 4:
   printf("source quench\n");
   break;
  case 3:
   printf("destination not reachable\n");
   break;
  case 6:
   printf("alternative host address\n");
   break;
  case 9:
   printf("router advertisement\n");
   break;
  case 10:
   printf("router selection\n");
   break;
  case 33:
   printf("ipv6 where are you?\n");
   break;
  case 34:
   printf("ipv6 i'm here!\n");
   break;
  case 17:
   printf("address mask request\n");
   break;
  case 18:
   printf("address mask reply\n");
   break;
  case 13:
   printf("timestamp request\n");
   break;
  case 14:
   printf("timestamp reply\n");
   break;
  case 15:
   printf("information request\n");
   break;
  case 16:
   printf("information reply\n");
   break;
  case 30:
   printf("traceroute\n");
   break;
  case 32:
   printf("mobile host redirect\n");
   break;
  case 35:
   printf("mobile registration request\n");
   break;
  case 36:
   printf("mobile registration reply\n");
   break;
  case 37:
   printf("domain name request\n");
   break;
  case 38:
   printf("domain name reply\n");
   break;
  case 31:
   printf("datagram conversion error\n");
   break;
  case 11:
   printf("expired request\n");
   break;
  case 12:
   printf("parameters error\n");
   break;
  default:
   break;
 }
 return 0;
}

variable_types: struct network_iface_p { char name[32]; char addr[4]; char mask[4]; char bcast[4]; char mac[6]; unsigned char if_up; unsigned char if_mac; unsigned char if_bcast; unsigned char type; unsigned int tx_bytes; unsigned int rx_bytes; struct driver_p { char name[32]; char desc[128]; char author[128]; unsigned char type; struct driver_fs_t { unsigned int (*mount)(char *, unsigned int, struct inode_p { char name[255]; unsigned int inode_n; unsigned char type; unsigned char ow; void *fs_node; void *fs_driver; struct inode_p *link; struct inode_p *next; struct inode_p *prev; struct inode_p *parent; struct inode_p *childs; } *); unsigned int (*umount)(struct inode_p *); unsigned int (*mkdir)(struct inode_p *, char *); unsigned int (*readdir)(struct inode_p *, unsigned int, struct dirent { char name[255]; unsigned int inode; } *); unsigned int (*get_node)(struct inode_p *, unsigned int, struct inode_p **); unsigned int (*delete_node)(struct inode_p *, char *); unsigned int (*create_node)(struct inode_p *, char *, unsigned int); unsigned int (*write_stat)(struct inode_p *, struct stat { unsigned int st_dev; unsigned int st_ino; int st_uid; int st_gid; unsigned long long st_blksize; unsigned long long st_blocks; } *, unsigned int); unsigned int (*read_stat)(struct inode_p *, struct stat *); unsigned int (*open)(struct inode_p *, char *); unsigned int (*close)(struct inode_p *); unsigned int (*read)(struct inode_p *, char *, unsigned int, unsigned long long); unsigned int (*write)(struct inode_p *, char *, unsigned int, unsigned long long); unsigned int (*link)(struct inode_p *, char *, struct inode_p *, char *); unsigned int (*unlink)(struct inode_p *, char *); unsigned char ifdev; } fs; struct driver_video_t { char *buffer; void (*put_pixel)(unsigned int, unsigned int, unsigned int); unsigned int (*get_pixel)(unsigned int, unsigned int); unsigned int (*set_mode)(unsigned int, unsigned int, unsigned int); } video; unsigned char loaded; unsigned int (*init)(); unsigned int (*free)(); unsigned int (*probe)(struct device_p { unsigned int io_base; char vendor[32]; char vendor_full[32]; char device[32]; char device_desc[32]; char class[32]; char class_desc[32]; char class_prog_desc[32]; unsigned char bus_type; void *pci_dev; unsigned char interrupt; unsigned int base_addresses[6]; char file[32]; struct device_p *next; } *); unsigned int (*read)(struct device_p *, char *, unsigned int, unsigned long long); unsigned int (*write)(struct device_p *, char *, unsigned int, unsigned long long); unsigned int (*ioctl)(struct device_p *, unsigned int, unsigned int, unsigned int); struct driver_p *next; } *drv; struct device_p *dev; void *link_protocol; struct network_iface_p *next; } *

variable_types: struct packet_t { unsigned int size; char *data; } *

variable_types:
protocol
unsigned char

variable_types: struct ip_header_t { unsigned char version; unsigned char head_len; unsigned char tos; unsigned short total_len; unsigned short ident; unsigned char flags; unsigned short offset; unsigned char time_to_live; unsigned char protocol; unsigned short header_checksum; unsigned int source; unsigned int dest; } *

variable_types: struct icmp_header_t { unsigned char type; unsigned char code; unsigned short checksum; } *


decompiled_code:
__int64 dns_resolve()
{
return 0LL;
}

original_code:
uint8_t dns_resolve(char *site, char *addr)
{
 return 0;
}

canonical_original_code:
unsigned char dns_resolve(char *site, char *addr)
{
 return 0;
}

variable_types:
site
char *

variable_types:
addr
char *

return_type: unsigned char


localtime

decompiled_code:
__int64 localtime()
{
return 0LL;
}

original_code:
struct tm *localtime(const time_t *timer)
{
 return 0;
}

canonical_original_code:
struct tm *localtime(long *timer)
{
 return 0;
}

variable_types:
timer
long *

return_type: struct tm { int Y; int tm_year; } *


decompiled_code:
__int64 __fastcall ip_handle_packet(__int64 a1, unsigned int *a2)
{
unsigned __int8 v2; // r12

v2 = *(_BYTE *)(*((_QWORD *)a2 + 1) + 9LL);
if ( (unsigned int)video_getx() )
printf("\n");
printf("ip: received packet (sizeof %d) of protocol %x\n", *a2, v2);
udp_handle_packet(a1, a2);
if ( v2 == 1 )
{
icmp_handle_packet(a1, a2);
}
else if ( v2 == 17 )
{
udp_handle_packet(a1, a2);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned int *a2)
{
unsigned __int8 v2; // r12

v2 = *(_BYTE *)(*((_QWORD *)a2 + 1) + 9LL);
if ( (unsigned int)video_getx() )
printf("\n");
printf("ip: received packet (sizeof %d) of protocol %x\n", *a2, v2);
udp_handle_packet(a1, a2);
if ( v2 == 1 )
{
icmp_handle_packet(a1, a2);
}
else if ( v2 == 17 )
{
udp_handle_packet(a1, a2);
}
return 0LL;
}

original_code:
uint32_t ip_handle_packet(network_iface_t *iface, packet_t *p)
{
 uint32_t protocol;
 ip_header_t *iphead = (ip_header_t *) p->data;
 protocol = iphead->protocol;
 if(video_getx() != 0)
  printf("\n");
 printf("ip: received packet (sizeof %d) of protocol %x\n", p->size, protocol);
  udp_handle_packet(iface, p);
 switch(protocol)
 {
  case 1:
   icmp_handle_packet(iface, p);
   break;
  case 17:
   udp_handle_packet(iface, p);
   break;
  case 6:
   break;
 }
 return 0;
}

canonical_original_code:
unsigned int ip_handle_packet(struct network_iface_p *iface, struct packet_t *p)
{
 unsigned int protocol;
 struct ip_header_t *iphead = (ip_header_t *) p->data;
 protocol = iphead->protocol;
 if(video_getx() != 0)
  printf("\n");
 printf("ip: received packet (sizeof %d) of protocol %x\n", p->size, protocol);
  udp_handle_packet(iface, p);
 switch(protocol)
 {
  case 1:
   icmp_handle_packet(iface, p);
   break;
  case 17:
   udp_handle_packet(iface, p);
   break;
  case 6:
   break;
 }
 return 0;
}

variable_types:
protocol
unsigned int


decompiled_code:
__int64 __fastcall ip_send_frame(__int64 a1, __int64 a2, const void *a3)
{
char v5[4]; // [rsp+Ch] [rbp-2Ch] BYREF
char dest[4]; // [rsp+10h] [rbp-28h] BYREF

printf("sending ip frame\n");
memcpy(dest, a3, sizeof(dest));
memcpy(v5, (const void *)(a1 + 32), sizeof(v5));
return (*(__int64 (__fastcall **)(__int64, __int64))(*(_QWORD *)(a1 + 80) + 24LL))(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, const void *a3)
{
char v5[4]; // [rsp+Ch] [rbp-2Ch] BYREF
char dest[4]; // [rsp+10h] [rbp-28h] BYREF

printf("sending ip frame\n");
memcpy(dest, a3, sizeof(dest));
memcpy(v5, (const void *)(a1 + 32), sizeof(v5));
return (*(__int64 (__fastcall **)(__int64, __int64))(*(_QWORD *)(a1 + 80) + 24LL))(a1, a2);
}

original_code:
uint32_t ip_send_frame(network_iface_t *iface, packet_t *p, char *adr, uint8_t proto)
{
 printf("sending ip frame\n");
 ip_header_t header;
 memcpy(&(header.dest), adr, 4);
 memcpy(&(header.source), (iface->addr), 4);
 return ((netlink_t *) (iface->link_protocol))->send_frame(iface, p);
 if((p->size + ((netlink_t *) (iface->link_protocol))->header_size) > ((netlink_t *) (iface->link_protocol))->frame_max_size)
 {
  ip_header_t *fragheader;
  uint32_t i;
  uint32_t nf = (p->size + ((netlink_t *) (iface->link_protocol))->header_size) /
     ((netlink_t *) (iface->link_protocol))->frame_max_size;
  uint32_t offset = 0;
  for(i = 0; i < nf; i++)
  {
   packet_t *frag = packet_create(0, 1);
   fragheader = (ip_header_t *) frag->data;
   fragheader->offset = offset;
   fragheader->time_to_live = 255;
   ((netlink_t *) (iface->link_protocol))->send_frame(iface, frag);
  }
 }
 else
  ((netlink_t *) (iface->link_protocol))->send_frame(iface, p);
 return 0;
}

canonical_original_code:
unsigned int ip_send_frame(struct network_iface_p *iface, struct packet_t *p, char *adr, unsigned char proto)
{
 printf("sending ip frame\n");
 struct ip_header_t header;
 memcpy(&(header.dest), adr, 4);
 memcpy(&(header.source), (iface->addr), 4);
 return ((struct netlink_t *) (iface->link_protocol))->send_frame(iface, p);
 if((p->size + ((struct netlink_t *) (iface->link_protocol))->header_size) > ((struct netlink_t *) (iface->link_protocol))->frame_max_size)
 {
  struct ip_header_t *fragheader;
  unsigned int i;
  unsigned int nf = (p->size + ((netlink_t *) (iface->link_protocol))->header_size) /
     ((netlink_t *) (iface->link_protocol))->frame_max_size;
  unsigned int offset = 0;
  for(i = 0; i < nf; i++)
  {
   struct packet_t *frag = packet_create(0, 1);
   fragheader = (struct ip_header_t *) frag->data;
   fragheader->offset = offset;
   fragheader->time_to_live = 255;
   ((struct netlink_t *) (iface->link_protocol))->send_frame(iface, frag);
  }
 }
 else
  ((struct netlink_t *) (iface->link_protocol))->send_frame(iface, p);
 return 0;
}

variable_types:
adr
char *

variable_types:
proto
unsigned char

variable_types: struct ip_header_t { unsigned char version; unsigned char head_len; unsigned char tos; unsigned short total_len; unsigned short ident; unsigned char flags; unsigned short offset; unsigned char time_to_live; unsigned char protocol; unsigned short header_checksum; unsigned int source; unsigned int dest; }

variable_types:
i
unsigned int

variable_types:
nf
unsigned int

variable_types:
offset
unsigned int

user_defined_types: struct netlink_t { unsigned int (*up)(struct network_iface_p *); unsigned int (*down)(struct network_iface_p *); unsigned int (*handle_frame)(struct network_iface_p *, struct packet_t *); unsigned int (*send_frame)(struct network_iface_p *, struct packet_t *); unsigned int frame_min_size; unsigned int frame_max_size; unsigned int header_size; }


decompiled_code:
__int64 md5_encode()
{
return 32LL;
}

canonical_decompiled_code:
__int64 func0()
{
return 32LL;
}

original_code:
uint32_t md5_encode(char *string, uint32_t size, char *md5_code)
{
 return 32;
}

canonical_original_code:
unsigned int md5_encode(char *string, unsigned int size, char *md5_code)
{
 return 32;
}

variable_types:
string
char *

variable_types:
size
unsigned int


decompiled_code:
_BOOL8 __fastcall elf_check(_BYTE *a1)
{
_BOOL8 result; // rax

result = 0LL;
if ( a1[1] == 69 && a1[2] == 76 && a1[3] == 70 )
result = *a1 == 127;
return result;
}

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

result = 0LL;
if ( a1[1] == 69 && a1[2] == 76 && a1[3] == 70 )
result = *a1 == 127;
return result;
}

original_code:
uint32_t elf_check(char *buf)
{
 elf_header_t *header = (elf_header_t *) buf;
 if( (*(header->ident+1) == 'E') &&
  (*(header->ident+2) == 'L') &&
  (*(header->ident+3) == 'F') &&
  (*(header->ident) == 0x7f))
  return 1;
 return 0;
}

canonical_original_code:
unsigned int elf_check(char *buf)
{
 struct elf_header_t *header = (elf_header_t *) buf;
 if( (*(header->ident+1) == 'E') &&
  (*(header->ident+2) == 'L') &&
  (*(header->ident+3) == 'F') &&
  (*(header->ident) == 0x7f))
  return 1;
 return 0;
}

variable_types:
buf
char *

variable_types: struct elf_header_t { char ident[16]; unsigned short type; unsigned short machine; unsigned int version; unsigned int entry; unsigned int phoff; unsigned int shoff; unsigned int flags; unsigned short ehsize; unsigned short phentsize; unsigned short phnum; unsigned short shentsize; unsigned short shnum; unsigned short shstrndx; } *


decompiled_code:
__int64 __fastcall arp_resolve(void *s1, void *dest)
{
unsigned int v2; // ebx
__int64 v3; // rbp

if ( !arp_table_pointer )
return 0xFFFFFFFFLL;
v2 = 0;
while ( 1 )
{
v3 = 10LL * v2;
if ( !memcmp(s1, (char *)&arp_table + v3, 4uLL) )
break;
if ( arp_table_pointer <= ++v2 )
return 0xFFFFFFFFLL;
}
memcpy(dest, (char *)&arp_table + v3 + 4, 8uLL);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(void *s1, void *dest)
{
unsigned int v2; // ebx
__int64 v3; // rbp

if ( !arp_table_pointer )
return 0xFFFFFFFFLL;
v2 = 0;
while ( 1 )
{
v3 = 10LL * v2;
if ( !memcmp(s1, (char *)&arp_table + v3, 4uLL) )
break;
if ( arp_table_pointer <= ++v2 )
return 0xFFFFFFFFLL;
}
memcpy(dest, (char *)&arp_table + v3 + 4, 8uLL);
return v2;
}

original_code:
int32_t arp_resolve(ip_t ip, mac_t hw)
{
 uint32_t i;
 for(i = 0; i < arp_table_pointer; i++)
 {
  if(memcmp(ip, arp_table[i].ip, 4) == 0)
  {
   memcpy(hw, arp_table[i].mac, 8);
   return i;
  }
 }
 return -1;
}

canonical_original_code:
int arp_resolve(char ip[4], char hw[6])
{
 unsigned int i;
 for(i = 0; i < arp_table_pointer; i++)
 {
  if(memcmp(ip, arp_table[i].ip, 4) == 0)
  {
   memcpy(hw, arp_table[i].mac, 8);
   return i;
  }
 }
 return -1;
}

variable_types:
ip
char [4]

variable_types:
hw
char [6]


decompiled_code:
__int64 arp_request()
{
return 0LL;
}

original_code:
uint32_t arp_request(network_iface_t *iface, ip_t ip)
{
 return 0;
}

canonical_original_code:
unsigned int arp_request(struct network_iface_p *iface, char ip[4])
{
 return 0;
}

variable_types: struct network_iface_p { char name[32]; char addr[4]; char mask[4]; char bcast[4]; char mac[6]; unsigned char if_up; unsigned char if_mac; unsigned char if_bcast; unsigned char type; unsigned int tx_bytes; unsigned int rx_bytes; struct driver_p { char name[32]; char desc[128]; char author[128]; unsigned char type; struct driver_fs_t { unsigned int (*mount)(char *, unsigned int, struct inode_p { char name[255]; unsigned int inode_n; unsigned char type; unsigned char ow; void *fs_node; void *fs_driver; struct inode_p *link; struct inode_p *next; struct inode_p *prev; struct inode_p *parent; struct inode_p *childs; } *); unsigned int (*umount)(struct inode_p *); unsigned int (*mkdir)(struct inode_p *, char *); unsigned int (*readdir)(struct inode_p *, unsigned int, struct dirent { char name[255]; unsigned int inode; } *); unsigned int (*get_node)(struct inode_p *, unsigned int, struct inode_p **); unsigned int (*delete_node)(struct inode_p *, char *); unsigned int (*create_node)(struct inode_p *, char *, unsigned int); unsigned int (*write_stat)(struct inode_p *, struct stat { unsigned int st_dev; unsigned int st_ino; int st_uid; int st_gid; unsigned long long st_blksize; unsigned long long st_blocks; } *, unsigned int); unsigned int (*read_stat)(struct inode_p *, struct stat *); unsigned int (*open)(struct inode_p *, char *); unsigned int (*close)(struct inode_p *); unsigned int (*read)(struct inode_p *, char *, unsigned int, unsigned long long); unsigned int (*write)(struct inode_p *, char *, unsigned int, unsigned long long); unsigned int (*link)(struct inode_p *, char *, struct inode_p *, char *); unsigned int (*unlink)(struct inode_p *, char *); unsigned char ifdev; } fs; struct driver_video_t { char *buffer; void (*put_pixel)(unsigned int, unsigned int, unsigned int); unsigned int (*get_pixel)(unsigned int, unsigned int); unsigned int (*set_mode)(unsigned int, unsigned int, unsigned int); } video; unsigned char loaded; unsigned int (*init)(); unsigned int (*free)(); unsigned int (*probe)(struct device_p { unsigned int io_base; char vendor[32]; char vendor_full[32]; char device[32]; char device_desc[32]; char class[32]; char class_desc[32]; char class_prog_desc[32]; unsigned char bus_type; void *pci_dev; unsigned char interrupt; unsigned int base_addresses[6]; char file[32]; struct device_p *next; } *); unsigned int (*read)(struct device_p *, char *, unsigned int, unsigned long long); unsigned int (*write)(struct device_p *, char *, unsigned int, unsigned long long); unsigned int (*ioctl)(struct device_p *, unsigned int, unsigned int, unsigned int); struct driver_p *next; } *drv; struct device_p *dev; void *link_protocol; struct network_iface_p *next; } *


decompiled_code:
__int64 arp_handle_frame()
{
return 0LL;
}

original_code:
uint32_t arp_handle_frame(network_iface_t *iface, packet_t *p)
{
 return 0;
}

canonical_original_code:
unsigned int arp_handle_frame(struct network_iface_p *iface, struct packet_t *p)
{
 return 0;
}

variable_types: struct packet_t { unsigned int size; char *data; } *


decompiled_code:
__int64 isa_probe()
{
return 0LL;
}

original_code:
uint32_t isa_probe()
{
 return 0;
}

canonical_original_code:
unsigned int isa_probe()
{
 return 0;
}


loadsplash

decompiled_code:
__int64 __fastcall loadsplash(unsigned int a1, unsigned int a2)
{
void *v2; // r12
_BYTE v4[66584]; // [rsp+0h] [rbp-10418h] BYREF

v2 = (void *)*(unsigned int *)(vesa_get_mode_info() + 40);
render_draw_rect_fill(0LL, 0LL, a1, a2, 3722304989LL);
if ( (unsigned int)load_raw_bitmap("/initr/splash.raw", v4, 130LL, 128LL) )
render_bit_map(v4, (unsigned int)((int)a1 / 2 - 64), (unsigned int)((int)a2 / 2 - 65), 130LL, 128LL);
render_write_text(16LL, "SpiderpigOS is loading...", 0xFFFFFFFLL, 10LL, 10LL);
memcpy(v2, &render_buffer, (size_t)&unk_1D4C00);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, unsigned int a2)
{
void *v2; // r12
_BYTE v4[66584]; // [rsp+0h] [rbp-10418h] BYREF

v2 = (void *)*(unsigned int *)(vesa_get_mode_info() + 40);
render_draw_rect_fill(0LL, 0LL, a1, a2, 3722304989LL);
if ( (unsigned int)load_raw_bitmap("/initr/splash.raw", v4, 130LL, 128LL) )
render_bit_map(v4, (unsigned int)((int)a1 / 2 - 64), (unsigned int)((int)a2 / 2 - 65), 130LL, 128LL);
render_write_text(16LL, "SpiderpigOS is loading...", 0xFFFFFFFLL, 10LL, 10LL);
memcpy(v2, &render_buffer, (size_t)&unk_1D4C00);
return 0LL;
}

original_code:
int loadsplash(int x, int y)
{
 uint32_t i;
 int b;
 char *phys;
 char img[130*128*4];
 b = (x - 100) / 5;
 phys = (char *) (((vesa_mode_info_t *) vesa_get_mode_info())->phys_base_ptr);
 render_draw_rect_fill(0, 0, x, y, 0xDDDDDDDD);
 if(load_raw_bitmap("/initr/splash.raw", img, 130, 128))
  render_bit_map((uint32_t *) img, x / 2 - 64, y / 2 - 65, 130, 128);
 render_write_text(16, "SpiderpigOS is loading...", 0xFFFFFFF, 10, 10);
 memcpy(phys, render_buffer, sizeof(render_buffer));
 return 0;
}

canonical_original_code:
int loadsplash(int x, int y)
{
 unsigned int i;
 int b;
 char *phys;
 char img[-1];
 b = (x - 100) / 5;
 phys = (char *) (((struct vesa_mode_info_t *) vesa_get_mode_info())->phys_base_ptr);
 render_draw_rect_fill(0, 0, x, y, 0xDDDDDDDD);
 if(load_raw_bitmap("/initr/splash.raw", img, 130, 128))
  render_bit_map((unsigned int *) img, x / 2 - 64, y / 2 - 65, 130, 128);
 render_write_text(16, "SpiderpigOS is loading...", 0xFFFFFFF, 10, 10);
 memcpy(phys, render_buffer, sizeof(render_buffer));
 return 0;
}

variable_types: x int

variable_types: y int

variable_types: b int

variable_types:
phys
char *

variable_types:
img
char [-1]


decompiled_code:
__int64 __fastcall syscall_call5()
{
__int64 result; // rax

__asm { int 84h }
return (unsigned int)result;
}

canonical_decompiled_code:
__int64 __fastcall func0()
{
__int64 result; // rax

__asm { int 84h }
return (unsigned int)result;
}

original_code:
int syscall_call5(uint32_t call, uint32_t p1, uint32_t p2, uint32_t p3, uint32_t p4, uint32_t p5)
{
 int ret;
 asm ("int %0\n" : : "g" (0x84));
 asm ("movl %%eax, %0\n\t" : "=r" (ret));
 return ret;
}

canonical_original_code:
int syscall_call5(unsigned int call, unsigned int p1, unsigned int p2, unsigned int p3, unsigned int p4, unsigned int p5)
{
 int ret;
 asm ("int %0\n" : : "g" (0x84));
 asm ("movl %%eax, %0\n\t" : "=r" (ret));
 return ret;
}

variable_types:
call
unsigned int

variable_types: ret int


decompiled_code:
__int64 __fastcall timing_beh(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rax
const char *v3; // rbx
const char *v5; // [rsp+0h] [rbp-38h] BYREF
int v6; // [rsp+8h] [rbp-30h]
int v7; // [rsp+Ch] [rbp-2Ch]
void *v8; // [rsp+10h] [rbp-28h]
char **v9; // [rsp+18h] [rbp-20h]
__int64 v10; // [rsp+20h] [rbp-18h]

v5 = "timing_beh";
v1 = *(_QWORD *)(dbug_cfg + 80LL);
v6 = *(_DWORD *)(v1 + 8);
v7 = 25;
v8 = &unk_9E3;
v9 = dbug_unit;
v10 = v1;
dbug_enter(&v5);
v2 = tv_create(*(_QWORD *)(a1 + 80), *(_QWORD *)(a1 + 88));
v3 = (const char *)cons_to_str(v2);
if ( dbug_on )
{
*(_QWORD *)(*(_QWORD *)(dbug_cfg + 80LL) + 16LL) = &unk_9E3;
if ( (unsigned int)dbug_keyword(&unk_9E3) )
{
*(_DWORD *)(*(_QWORD *)(dbug_cfg + 80LL) + 12LL) = 27;
dbug_print("[timestamp] %s", v3);
}
}
fprintf(stderr, "[timestamp] %s\n", v3);
v7 = 29;
return dbug_return(&v5);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rax
const char *v3; // rbx
const char *v5; // [rsp+0h] [rbp-38h] BYREF
int v6; // [rsp+8h] [rbp-30h]
int v7; // [rsp+Ch] [rbp-2Ch]
void *v8; // [rsp+10h] [rbp-28h]
char **v9; // [rsp+18h] [rbp-20h]
__int64 v10; // [rsp+20h] [rbp-18h]

v5 = "timing_beh";
v1 = *(_QWORD *)(dbug_cfg + 80LL);
v6 = *(_DWORD *)(v1 + 8);
v7 = 25;
v8 = &unk_9E3;
v9 = dbug_unit;
v10 = v1;
dbug_enter(&v5);
v2 = tv_create(*(_QWORD *)(a1 + 80), *(_QWORD *)(a1 + 88));
v3 = (const char *)cons_to_str(v2);
if ( dbug_on )
{
*(_QWORD *)(*(_QWORD *)(dbug_cfg + 80LL) + 16LL) = &unk_9E3;
if ( (unsigned int)dbug_keyword(&unk_9E3) )
{
*(_DWORD *)(*(_QWORD *)(dbug_cfg + 80LL) + 12LL) = 27;
dbug_print("[timestamp] %s", v3);
}
}
fprintf(stderr, "[timestamp] %s\n", v3);
v7 = 29;
return dbug_return(&v5);
}

original_code:
void timing_beh (CONFIG* abe__config)
{
 char* s;
 struct dbug_ctx_t dbug_ctx; dbug_ctx.name = ("timing_beh"); dbug_ctx.depth = dbug_cfg->ctx->depth; dbug_ctx.line = 25; dbug_ctx.keyword = ""; dbug_ctx.unit = &dbug_unit; dbug_ctx.caller = dbug_cfg->ctx; dbug_enter (&dbug_ctx);
 s = cons_to_str(tv_create((abe__config)->t_now_s, (abe__config)->t_now_us));
 do{ if(dbug_on && dbug_keyword (dbug_cfg->ctx->keyword = (""))){ dbug_cfg->ctx->line = 27; dbug_print ("[timestamp] %s", s); }}while(0);
 fprintf(stderr, "[timestamp] %s\n", s);
 dbug_ctx.line = 29; dbug_return (&dbug_ctx); return;
}

canonical_original_code:
void timing_beh(struct config *abe__config)
{
 char *s;
 struct dbug_ctx_t dbug_ctx; dbug_ctx.name = ("timing_beh"); dbug_ctx.depth = dbug_cfg->ctx->depth; dbug_ctx.line = 25; dbug_ctx.keyword = ""; dbug_ctx.unit = &dbug_unit; dbug_ctx.caller = dbug_cfg->ctx; dbug_enter (&dbug_ctx);
 s = cons_to_str(tv_create((abe__config)->t_now_s, (abe__config)->t_now_us));
 do{ if(dbug_on && dbug_keyword (dbug_cfg->ctx->keyword = (""))){ dbug_cfg->ctx->line = 27; dbug_print ("[timestamp] %s", s); }}while(0);
 fprintf(stderr, "[timestamp] %s\n", s);
 dbug_ctx.line = 29; dbug_return (&dbug_ctx); return;
}

variable_types: struct config { struct cell { struct cons { struct cons *first; struct cons *rest; } *first; struct cons *rest; long _prev; long _next; } msg_queue; struct cons *gc_root; int q_count; struct cons *q_entry; int msg_cnt_hi; int msg_cnt_lo; int q_limit; long t_epoch; long t_now_s; long t_now_us; struct cons *t_queue; int t_count; } *

variable_types:
s
char *

variable_types: struct dbug_ctx_t { char *name; int depth; int line; char *keyword; struct dbug_unit_t { char *name; char *unit; } *unit; struct dbug_ctx_t *caller; }

user_defined_types: struct dbug_ctx_t { char *name; int depth; int line; char *keyword; struct dbug_unit_t *unit; struct dbug_ctx_t *caller; }

user_defined_types: struct config { struct cell msg_queue; struct cons *gc_root; int q_count; struct cons *q_entry; int msg_cnt_hi; int msg_cnt_lo; int q_limit; long t_epoch; long t_now_s; long t_now_us; struct cons *t_queue; int t_count; }

user_defined_types: struct cell { struct cons *first; struct cons *rest; long _prev; long _next; }


original_code:
void countdown_ring_0_beh (CONFIG* abe__config)
{
 CONS* m = _cdr((abe__config)->q_entry);
 CONS* first = _mine(_car((abe__config)->q_entry));
 int m_int = ((int)(((WORD)(m))>>2));
 struct dbug_ctx_t dbug_ctx; dbug_ctx.name = ("countdown_ring_0_beh"); dbug_ctx.depth = dbug_cfg->ctx->depth; dbug_ctx.line = 47; dbug_ctx.keyword = ""; dbug_ctx.unit = &dbug_unit; dbug_ctx.caller = dbug_cfg->ctx; dbug_enter (&dbug_ctx);
 if (m_int <= 0) {
  abe__become(_car((abe__config)->q_entry),(sink_beh),(((CONS*)(&nil__cons))));
  abe__send((abe__config),(timing_actor),(((CONS*)(&nil__cons))));
 } else {
  abe__send((abe__config),(first),(((CONS*)((((WORD)(m_int - 1))<<2) | ((WORD)(0x00000003))))));
 }
 dbug_ctx.line = 54; dbug_return (&dbug_ctx); return;
}

canonical_original_code:
void countdown_ring_0_beh(struct config *abe__config)
{
 struct cons *m = _cdr((abe__config)->q_entry);
 struct cons *first = _mine(_car((abe__config)->q_entry));
 int m_int = ((int)(((WORD)(m))>>2));
 struct dbug_ctx_t dbug_ctx; dbug_ctx.name = ("countdown_ring_0_beh"); dbug_ctx.depth = dbug_cfg->ctx->depth; dbug_ctx.line = 47; dbug_ctx.keyword = ""; dbug_ctx.unit = &dbug_unit; dbug_ctx.caller = dbug_cfg->ctx; dbug_enter (&dbug_ctx);
 if (m_int <= 0) {
  abe__become(_car((abe__config)->q_entry),(sink_beh),(((struct cons *)(&nil__cons))));
  abe__send((abe__config),(timing_actor),(((struct cons *)(&nil__cons))));
 } else {
  abe__send((abe__config),(first),(((struct cons *)((((WORD)(m_int - 1))<<2) | ((WORD)(0x00000003))))));
 }
 dbug_ctx.line = 54; dbug_return (&dbug_ctx); return;
}

variable_types: struct cons { struct cons *first; struct cons *rest; } *

user_defined_types: struct dbug_unit_t { char *name; char *unit; }


decompiled_code:
__int64 __fastcall countdown_ring_beh(__int64 a1)
{
__int64 v1; // r12
__int64 v2; // rax
__int64 v3; // rbp
__int64 v4; // rax
const char *v6; // [rsp+0h] [rbp-48h] BYREF
int v7; // [rsp+8h] [rbp-40h]
int v8; // [rsp+Ch] [rbp-3Ch]
void *v9; // [rsp+10h] [rbp-38h]
char **v10; // [rsp+18h] [rbp-30h]
__int64 v11; // [rsp+20h] [rbp-28h]

v1 = cdr(*(_QWORD *)(a1 + 48));
v2 = car(*(_QWORD *)(a1 + 48));
v3 = mine(v2);
v6 = "countdown_ring_beh";
v4 = *(_QWORD *)(dbug_cfg + 80LL);
v7 = *(_DWORD *)(v4 + 8);
v8 = 67;
v9 = &unk_9E3;
v10 = dbug_unit;
v11 = v4;
dbug_enter(&v6);
abe__send(a1, v3, v1);
v8 = 69;
return dbug_return(&v6);
}

original_code:
void countdown_ring_beh (CONFIG* abe__config)
{
 CONS* m = _cdr((abe__config)->q_entry);
 CONS* next = _mine(_car((abe__config)->q_entry));
 struct dbug_ctx_t dbug_ctx; dbug_ctx.name = ("countdown_ring_beh"); dbug_ctx.depth = dbug_cfg->ctx->depth; dbug_ctx.line = 67; dbug_ctx.keyword = ""; dbug_ctx.unit = &dbug_unit; dbug_ctx.caller = dbug_cfg->ctx; dbug_enter (&dbug_ctx);
 abe__send((abe__config),(next),(m));
 dbug_ctx.line = 69; dbug_return (&dbug_ctx); return;
}

canonical_original_code:
void countdown_ring_beh(struct config *abe__config)
{
 struct cons *m = _cdr((abe__config)->q_entry);
 struct cons *next = _mine(_car((abe__config)->q_entry));
 struct dbug_ctx_t dbug_ctx; dbug_ctx.name = ("countdown_ring_beh"); dbug_ctx.depth = dbug_cfg->ctx->depth; dbug_ctx.line = 67; dbug_ctx.keyword = ""; dbug_ctx.unit = &dbug_unit; dbug_ctx.caller = dbug_cfg->ctx; dbug_enter (&dbug_ctx);
 abe__send((abe__config),(next),(m));
 dbug_ctx.line = 69; dbug_return (&dbug_ctx); return;
}

user_defined_types: struct cons { struct cons *first; struct cons *rest; }