decompiled_code:
__int64 __fastcall libelf_release_all(__int64 a1)
{
__int64 i; // rbx
__int64 result; // rax

if ( *(_DWORD *)(a1 + 24) == 1 )
{
for ( i = *(_QWORD *)(a1 + 72); i; i = *(_QWORD *)(i + 16) )
{
result = *(unsigned int *)(i + 60);
if ( (_DWORD)result )
result = libelf_release_all(i);
}
}
return result;
}

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

if ( *(_DWORD *)(a1 + 24) == 1 )
{
for ( i = *(_QWORD *)(a1 + 72); i; i = *(_QWORD *)(i + 16) )
{
result = *(unsigned int *)(i + 60);
if ( (_DWORD)result )
result = func0(i);
}
}
return result;
}

original_code:
static void
__attribute__ ((unused))
libelf_release_all (Elf *elf)
{
  if (elf->kind == ELF_K_AR)
    {
      Elf *child = elf->state.ar.children;
      while (child != ((void *)0))
 {
   if (child->ref_count != 0)
     libelf_release_all (child);
   child = child->next;
 }
    }
  ((void) (elf->lock));
}

canonical_original_code:
static void libelf_release_all(struct Elf *elf)
{
  if (elf->kind == ELF_K_AR)
    {
      struct Elf *child = elf->state.ar.children;
      while (child != ((void *)0))
 {
   if (child->ref_count != 0)
     libelf_release_all (child);
   child = child->next;
 }
    }
  ((void) (elf->lock));
}

variable_types: struct Elf { void *map_address; struct Elf *parent; struct Elf *next; enum Elf_Kind { ELF_K_NONE=0, ELF_K_AR=1, ELF_K_COFF=2, ELF_K_ELF=3, ELF_K_NUM=4 } kind; enum Elf_Cmd { ELF_C_NULL=0, ELF_C_READ=1, ELF_C_RDWR=2, ELF_C_WRITE=3, ELF_C_CLR=4, ELF_C_SET=5, ELF_C_FDDONE=6, ELF_C_FDREAD=7, ELF_C_READ_MMAP=8, ELF_C_RDWR_MMAP=9, ELF_C_WRITE_MMAP=10, ELF_C_READ_MMAP_PRIVATE=11, ELF_C_EMPTY=12, ELF_C_NUM=13 } cmd; unsigned int class; int fildes; long start_offset; unsigned long maximum_size; int flags; int ref_count; int lock; union { struct { void *ehdr; void *shdr; void *phdr; struct Elf_ScnList { unsigned int cnt; unsigned int max; struct Elf_ScnList *next; struct Elf_Scn { struct Elf_Data_List { struct Elf_Data_Scn { struct Elf_Data { void *d_buf; enum Elf_Type { ELF_T_BYTE=0, ELF_T_ADDR=1, ELF_T_DYN=2, ELF_T_EHDR=3, ELF_T_HALF=4, ELF_T_OFF=5, ELF_T_PHDR=6, ELF_T_RELA=7, ELF_T_REL=8, ELF_T_SHDR=9, ELF_T_SWORD=10, ELF_T_SYM=11, ELF_T_WORD=12, ELF_T_XWORD=13, ELF_T_SXWORD=14, ELF_T_VDEF=15, ELF_T_VDAUX=16, ELF_T_VNEED=17, ELF_T_VNAUX=18, ELF_T_NHDR=19, ELF_T_SYMINFO=20, ELF_T_MOVE=21, ELF_T_LIB=22, ELF_T_GNUHASH=23, ELF_T_AUXV=24, ELF_T_NUM=25 } d_type; unsigned int d_version; unsigned long d_size; long d_off; unsigned long d_align; } d; struct Elf_Scn *s; } data; struct Elf_Data_List *next; int flags; } data_list; struct Elf_Data_List *data_list_rear; struct Elf_Data_Scn rawdata; int data_read; int shndx_index; unsigned long index; struct Elf *elf; union { struct Elf32_Shdr { unsigned int sh_name; unsigned int sh_type; unsigned int sh_flags; unsigned int sh_addr; unsigned int sh_offset; unsigned int sh_size; unsigned int sh_link; unsigned int sh_info; unsigned int sh_addralign; unsigned int sh_entsize; } *e32; struct Elf64_Shdr { unsigned int sh_name; unsigned int sh_type; unsigned long sh_flags; unsigned long sh_addr; unsigned long sh_offset; unsigned long sh_size; unsigned int sh_link; unsigned int sh_info; unsigned long sh_addralign; unsigned long sh_entsize; } *e64; } shdr; unsigned int shdr_flags; unsigned int flags; char *rawdata_base; char *data_base; struct Elf_ScnList *list; } data[]; } *scns_last; struct Elf_Data_Chunk { struct Elf_Data_Scn data; union { struct Elf_Scn dummy_scn; struct Elf_Data_Chunk *next; }; } *rawchunks; unsigned int scnincr; int ehdr_flags; int phdr_flags; int shdr_malloced; long sizestr_offset; } elf; struct { struct Elf32_Ehdr { unsigned char e_ident[-1]; unsigned short e_type; unsigned short e_machine; unsigned int e_version; unsigned int e_entry; unsigned int e_phoff; unsigned int e_shoff; unsigned int e_flags; unsigned short e_ehsize; unsigned short e_phentsize; unsigned short e_phnum; unsigned short e_shentsize; unsigned short e_shnum; unsigned short e_shstrndx; } *ehdr; struct Elf32_Shdr *shdr; struct Elf32_Phdr { unsigned int p_type; unsigned int p_offset; unsigned int p_vaddr; unsigned int p_paddr; unsigned int p_filesz; unsigned int p_memsz; unsigned int p_flags; unsigned int p_align; } *phdr; struct Elf_ScnList *scns_last; struct Elf_Data_Chunk *rawchunks; unsigned int scnincr; int ehdr_flags; int phdr_flags; int shdr_malloced; long sizestr_offset; struct Elf32_Ehdr ehdr_mem; char __e32scnspad[-1]; struct Elf_ScnList scns; } elf32; struct { struct Elf64_Ehdr { unsigned char e_ident[-1]; unsigned short e_type; unsigned short e_machine; unsigned int e_version; unsigned long e_entry; unsigned long e_phoff; unsigned long e_shoff; unsigned int e_flags; unsigned short e_ehsize; unsigned short e_phentsize; unsigned short e_phnum; unsigned short e_shentsize; unsigned short e_shnum; unsigned short e_shstrndx; } *ehdr; struct Elf64_Shdr *shdr; struct Elf64_Phdr { unsigned int p_type; unsigned int p_flags; unsigned long p_offset; unsigned long p_vaddr; unsigned long p_paddr; unsigned long p_filesz; unsigned long p_memsz; unsigned long p_align; } *phdr; struct Elf_ScnList *scns_last; struct Elf_Data_Chunk *rawchunks; unsigned int scnincr; int ehdr_flags; int phdr_flags; int shdr_malloced; long sizestr_offset; struct Elf64_Ehdr ehdr_mem; struct Elf_ScnList scns; } elf64; struct { struct Elf *children; struct Elf_Arsym { char *as_name; unsigned long as_off; unsigned long as_hash; } *ar_sym; unsigned long ar_sym_num; char *long_names; unsigned long long_names_len; long offset; struct Elf_Arhdr { char *ar_name; long ar_date; unsigned int ar_uid; unsigned int ar_gid; unsigned int ar_mode; long ar_size; char *ar_rawname; } elf_ar_hdr; struct ar_hdr { char ar_name[16]; char ar_date[12]; char ar_uid[6]; char ar_mode[8]; char ar_size[10]; char ar_fmag[2]; } ar_hdr; char ar_name[16]; char raw_name[17]; } ar; } state; } *


repo: sabotage-linux/libelf-compat

original_code:
static void
set_address (Elf *elf, size_t offset)
{
  if (elf->kind == ELF_K_AR)
    {
      Elf *child = elf->state.ar.children;
      while (child != ((void *)0))
 {
   if (child->map_address == ((void *)0))
     {
       child->map_address = elf->map_address;
       child->start_offset -= offset;
       if (child->kind == ELF_K_AR)
  child->state.ar.offset -= offset;
       set_address (child, offset);
     }
   child = child->next;
 }
    }
}

canonical_original_code:
static void set_address(struct Elf *elf, unsigned long offset)
{
  if (elf->kind == ELF_K_AR)
    {
      struct Elf *child = elf->state.ar.children;
      while (child != ((void *)0))
 {
   if (child->map_address == ((void *)0))
     {
       child->map_address = elf->map_address;
       child->start_offset -= offset;
       if (child->kind == ELF_K_AR)
  child->state.ar.offset -= offset;
       set_address (child, offset);
     }
   child = child->next;
 }
    }
}

variable_types:
offset
unsigned long

return_type: void

user_defined_types: struct Elf { void *map_address; struct Elf *parent; struct Elf *next; enum Elf_Kind kind; enum Elf_Cmd cmd; unsigned int class; int fildes; long start_offset; unsigned long maximum_size; int flags; int ref_count; int lock; union { struct { void *ehdr; void *shdr; void *phdr; struct Elf_ScnList *scns_last; struct Elf_Data_Chunk *rawchunks; unsigned int scnincr; int ehdr_flags; int phdr_flags; int shdr_malloced; long sizestr_offset; } elf; struct { struct Elf32_Ehdr *ehdr; struct Elf32_Shdr *shdr; struct Elf32_Phdr *phdr; struct Elf_ScnList *scns_last; struct Elf_Data_Chunk *rawchunks; unsigned int scnincr; int ehdr_flags; int phdr_flags; int shdr_malloced; long sizestr_offset; struct Elf32_Ehdr ehdr_mem; char __e32scnspad[-1]; struct Elf_ScnList scns; } elf32; struct { struct Elf64_Ehdr *ehdr; struct Elf64_Shdr *shdr; struct Elf64_Phdr *phdr; struct Elf_ScnList *scns_last; struct Elf_Data_Chunk *rawchunks; unsigned int scnincr; int ehdr_flags; int phdr_flags; int shdr_malloced; long sizestr_offset; struct Elf64_Ehdr ehdr_mem; struct Elf_ScnList scns; } elf64; struct { struct Elf *children; struct Elf_Arsym *ar_sym; unsigned long ar_sym_num; char *long_names; unsigned long long_names_len; long offset; struct Elf_Arhdr elf_ar_hdr; struct ar_hdr ar_hdr; char ar_name[16]; char raw_name[17]; } ar; } state; }

user_defined_types: enum Elf_Kind { ELF_K_NONE=0, ELF_K_AR=1, ELF_K_COFF=2, ELF_K_ELF=3, ELF_K_NUM=4 }

user_defined_types: enum Elf_Cmd { ELF_C_NULL=0, ELF_C_READ=1, ELF_C_RDWR=2, ELF_C_WRITE=3, ELF_C_CLR=4, ELF_C_SET=5, ELF_C_FDDONE=6, ELF_C_FDREAD=7, ELF_C_READ_MMAP=8, ELF_C_RDWR_MMAP=9, ELF_C_WRITE_MMAP=10, ELF_C_READ_MMAP_PRIVATE=11, ELF_C_EMPTY=12, ELF_C_NUM=13 }

user_defined_types: struct Elf_Arhdr { char *ar_name; long ar_date; unsigned int ar_uid; unsigned int ar_gid; unsigned int ar_mode; long ar_size; char *ar_rawname; }

user_defined_types: struct ar_hdr { char ar_name[16]; char ar_date[12]; char ar_uid[6]; char ar_mode[8]; char ar_size[10]; char ar_fmag[2]; }

user_defined_types: struct Elf_ScnList { unsigned int cnt; unsigned int max; struct Elf_ScnList *next; struct Elf_Scn data[]; }

user_defined_types: struct Elf_Data_Chunk { struct Elf_Data_Scn data; union { struct Elf_Scn dummy_scn; struct Elf_Data_Chunk *next; }; }

user_defined_types: struct Elf32_Ehdr { unsigned char e_ident[-1]; unsigned short e_type; unsigned short e_machine; unsigned int e_version; unsigned int e_entry; unsigned int e_phoff; unsigned int e_shoff; unsigned int e_flags; unsigned short e_ehsize; unsigned short e_phentsize; unsigned short e_phnum; unsigned short e_shentsize; unsigned short e_shnum; unsigned short e_shstrndx; }

user_defined_types: struct Elf32_Phdr { unsigned int p_type; unsigned int p_offset; unsigned int p_vaddr; unsigned int p_paddr; unsigned int p_filesz; unsigned int p_memsz; unsigned int p_flags; unsigned int p_align; }

user_defined_types: struct Elf64_Ehdr { unsigned char e_ident[-1]; unsigned short e_type; unsigned short e_machine; unsigned int e_version; unsigned long e_entry; unsigned long e_phoff; unsigned long e_shoff; unsigned int e_flags; unsigned short e_ehsize; unsigned short e_phentsize; unsigned short e_phnum; unsigned short e_shentsize; unsigned short e_shnum; unsigned short e_shstrndx; }

user_defined_types: struct Elf64_Phdr { unsigned int p_type; unsigned int p_flags; unsigned long p_offset; unsigned long p_vaddr; unsigned long p_paddr; unsigned long p_filesz; unsigned long p_memsz; unsigned long p_align; }

user_defined_types: struct Elf_Arsym { char *as_name; unsigned long as_off; unsigned long as_hash; }

user_defined_types: struct Elf_Scn { struct Elf_Data_List data_list; struct Elf_Data_List *data_list_rear; struct Elf_Data_Scn rawdata; int data_read; int shndx_index; unsigned long index; struct Elf *elf; union { struct Elf32_Shdr *e32; struct Elf64_Shdr *e64; } shdr; unsigned int shdr_flags; unsigned int flags; char *rawdata_base; char *data_base; struct Elf_ScnList *list; }

user_defined_types: struct Elf_Data_List { struct Elf_Data_Scn data; struct Elf_Data_List *next; int flags; }

user_defined_types: struct Elf_Data_Scn { struct Elf_Data d; struct Elf_Scn *s; }

user_defined_types: struct Elf_Data { void *d_buf; enum Elf_Type d_type; unsigned int d_version; unsigned long d_size; long d_off; unsigned long d_align; }

user_defined_types: struct Elf32_Shdr { unsigned int sh_name; unsigned int sh_type; unsigned int sh_flags; unsigned int sh_addr; unsigned int sh_offset; unsigned int sh_size; unsigned int sh_link; unsigned int sh_info; unsigned int sh_addralign; unsigned int sh_entsize; }

user_defined_types: struct Elf64_Shdr { unsigned int sh_name; unsigned int sh_type; unsigned long sh_flags; unsigned long sh_addr; unsigned long sh_offset; unsigned long sh_size; unsigned int sh_link; unsigned int sh_info; unsigned long sh_addralign; unsigned long sh_entsize; }

user_defined_types: enum Elf_Type { ELF_T_BYTE=0, ELF_T_ADDR=1, ELF_T_DYN=2, ELF_T_EHDR=3, ELF_T_HALF=4, ELF_T_OFF=5, ELF_T_PHDR=6, ELF_T_RELA=7, ELF_T_REL=8, ELF_T_SHDR=9, ELF_T_SWORD=10, ELF_T_SYM=11, ELF_T_WORD=12, ELF_T_XWORD=13, ELF_T_SXWORD=14, ELF_T_VDEF=15, ELF_T_VDAUX=16, ELF_T_VNEED=17, ELF_T_VNAUX=18, ELF_T_NHDR=19, ELF_T_SYMINFO=20, ELF_T_MOVE=21, ELF_T_LIB=22, ELF_T_GNUHASH=23, ELF_T_AUXV=24, ELF_T_NUM=25 }


createlinkList

repo: sachin-rajput/basic-ds-algo

decompiled_code:
_QWORD *createlinkList()
{
_QWORD *result; // rax

result = malloc(0x10uLL);
*result = 0LL;
result[1] = 0LL;
return result;
}

canonical_decompiled_code:
_QWORD *func7()
{
_QWORD *result; // rax

result = malloc(0x10uLL);
*result = 0LL;
result[1] = 0LL;
return result;
}

original_code:
linkList *createlinkList()
{
 linkList *newlinkList = (linkList*)malloc(sizeof(linkList));
 newlinkList->head = ((void *)0);
 newlinkList->tail = ((void *)0);
 return newlinkList;
}

canonical_original_code:
struct linkList *createlinkList()
{
 struct linkList *newlinkList = (linkList*)malloc(sizeof(linkList));
 newlinkList->head = ((void *)0);
 newlinkList->tail = ((void *)0);
 return newlinkList;
}

variable_types: struct linkList { struct nodePtr { struct nodePtr *next; struct data { int value; } *dataPtr; } *head; struct nodePtr *tail; } *

user_defined_types: struct linkList { struct nodePtr *head; struct nodePtr *tail; }

user_defined_types: struct nodePtr { struct nodePtr *next; struct data *dataPtr; }


searchValue

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

result = *a1;
if ( !*a1 )
return 0LL;
while ( **(_DWORD **)(result + 8) != a2 )
{
result = *(_QWORD *)result;
if ( !result )
return result;
}
return 1LL;
}

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

result = *a1;
if ( !*a1 )
return 0LL;
while ( **(_DWORD **)(result + 8) != a2 )
{
result = *(_QWORD *)result;
if ( !result )
return result;
}
return 1LL;
}

original_code:
int searchValue(linkList *ll,int value)
{
 node *temp,*prev;
 prev = ll->head;
 for(temp= ll->head; temp != ((void *)0); temp=temp->next) {
  if(temp->dataPtr->value == value) {
   return 1;
  }
  prev = temp;
 }
 return 0;
}

canonical_original_code:
int searchValue(struct linkList *ll, int value)
{
 struct nodePtr *temp; struct nodePtr *prev;
 prev = ll->head;
 for(temp= ll->head; temp != ((void *)0); temp=temp->next) {
  if(temp->dataPtr->value == value) {
   return 1;
  }
  prev = temp;
 }
 return 0;
}

variable_types: value int

variable_types: struct nodePtr { struct nodePtr *next; struct data { int value; } *dataPtr; } *

return_type: int


checkHead

decompiled_code:
_BOOL8 __fastcall checkHead(_QWORD *a1)
{
return *a1 != 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func10(_QWORD *a1)
{
return *a1 != 0LL;
}

original_code:
int checkHead(linkList *ll)
{
 if(ll->head) return 1;
 return 0;
}

canonical_original_code:
int checkHead(struct linkList *ll)
{
 if(ll->head) return 1;
 return 0;
}


checkTail

decompiled_code:
_BOOL8 __fastcall checkTail(__int64 a1)
{
return *(_QWORD *)(a1 + 8) != 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func11(__int64 a1)
{
return *(_QWORD *)(a1 + 8) != 0LL;
}

original_code:
int checkTail(linkList *ll)
{
 if(ll->tail) return 1;
 return 0;
}

canonical_original_code:
int checkTail(struct linkList *ll)
{
 if(ll->tail) return 1;
 return 0;
}


printlinkList

decompiled_code:
int __fastcall printlinkList(__int64 ***a1)
{
int result; // eax
__int64 **v2; // rbx

result = checkEmpty(a1);
if ( result )
{
v2 = *a1;
puts(">>==============Printing linkList from front================<<");
for ( ; v2; v2 = (__int64 **)*v2 )
printf("%d\n", *(unsigned int *)v2[1]);
result = puts(">>==============Printing linkList finished================<<");
}
return result;
}

canonical_decompiled_code:
int __fastcall func17(__int64 ***a1)
{
int result; // eax
__int64 **v2; // rbx

result = func12(a1);
if ( result )
{
v2 = *a1;
puts(">>==============Printing linkList from front================<<");
for ( ; v2; v2 = (__int64 **)*v2 )
printf("%d\n", *(unsigned int *)v2[1]);
result = puts(">>==============Printing linkList finished================<<");
}
return result;
}

original_code:
void printlinkList(linkList *ll)
{
 if(!checkEmpty(ll)) return;
 node *temp = ll->head;
 printf(">>==============Printing linkList from front================<<\n");
 while(temp != ((void *)0)) {
  printf("%d\n",temp->dataPtr->value);
  temp = temp->next;
 }
 printf(">>==============Printing linkList finished================<<\n");
}

canonical_original_code:
void printlinkList(struct linkList *ll)
{
 if(!checkEmpty(ll)) return;
 struct nodePtr *temp = ll->head;
 printf(">>==============Printing linkList from front================<<\n");
 while(temp != ((void *)0)) {
  printf("%d\n",temp->dataPtr->value);
  temp = temp->next;
 }
 printf(">>==============Printing linkList finished================<<\n");
}


lengthlinkList

decompiled_code:
__int64 __fastcall lengthlinkList(_QWORD *a1)
{
unsigned int v1; // er8
_QWORD *v2; // rax

v1 = checkEmpty(a1);
if ( v1 )
{
v2 = (_QWORD *)*a1;
v1 = 0;
if ( *a1 )
{
do
{
v2 = (_QWORD *)*v2;
++v1;
}
while ( v2 );
}
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func18(_QWORD *a1)
{
unsigned int v1; // er8
_QWORD *v2; // rax

v1 = func12(a1);
if ( v1 )
{
v2 = (_QWORD *)*a1;
v1 = 0;
if ( *a1 )
{
do
{
v2 = (_QWORD *)*v2;
++v1;
}
while ( v2 );
}
}
return v1;
}

original_code:
int lengthlinkList(linkList *ll)
{
 if(!checkEmpty(ll)) return 0;
 node *temp = ll->head;
 int i= 0;
 while(temp != ((void *)0)) {
  i++;
  temp = temp->next;
 }
 return i;
}

canonical_original_code:
int lengthlinkList(struct linkList *ll)
{
 if(!checkEmpty(ll)) return 0;
 struct nodePtr *temp = ll->head;
 int i = 0;
 while(temp != ((void *)0)) {
  i++;
  temp = temp->next;
 }
 return i;
}

variable_types: i int


cleanlinkList

decompiled_code:
int __fastcall cleanlinkList(void *ptr)
{
int result; // eax
void **v2; // rbx
void **v3; // rbp

result = checkEmpty(ptr);
if ( result )
{
v2 = *(void ***)ptr;
if ( *(_QWORD *)ptr )
{
do
{
v3 = v2;
v2 = (void **)*v2;
free(v3[1]);
free(v3);
}
while ( v2 );
}
free(ptr);
result = puts(">>==============Linklist memory cleaned ================<<");
}
return result;
}

canonical_decompiled_code:
int __fastcall func21(void *ptr)
{
int result; // eax
void **v2; // rbx
void **v3; // rbp

result = func12(ptr);
if ( result )
{
v2 = *(void ***)ptr;
if ( *(_QWORD *)ptr )
{
do
{
v3 = v2;
v2 = (void **)*v2;
free(v3[1]);
free(v3);
}
while ( v2 );
}
free(ptr);
result = puts(">>==============Linklist memory cleaned ================<<");
}
return result;
}

original_code:
void cleanlinkList(linkList *ll)
{
 if(!checkEmpty(ll)) return;
 node *temp = ll->head;
 node *curr = temp;
 while(temp !=((void *)0)) {
  curr=temp->next;
  free(temp->dataPtr);
  free(temp);
  temp = curr;
 }
 free(ll);
 printf(">>==============Linklist memory cleaned ================<<\n");
}

canonical_original_code:
void cleanlinkList(struct linkList *ll)
{
 if(!checkEmpty(ll)) return;
 struct nodePtr *temp = ll->head;
 struct nodePtr *curr = temp;
 while(temp !=((void *)0)) {
  curr=temp->next;
  free(temp->dataPtr);
  free(temp);
  temp = curr;
 }
 free(ll);
 printf(">>==============Linklist memory cleaned ================<<\n");
}


popwithValue

original_code:
void popwithValue(linkList *ll,int value)
{
 node *temp,*prev;
 prev = ll->head;
 for(temp= ll->head; temp != ((void *)0); temp=temp->next) {
  if(temp->dataPtr->value == value) {
   prev->next = temp->next;
   temp->next = ((void *)0);
   printf(">>==============Node pop'd with value : %d ================<<\n",value);
   free(temp->dataPtr);
   free(temp);
   return;
  }
  prev = temp;
 }
}

canonical_original_code:
void popwithValue(struct linkList *ll, int value)
{
 struct nodePtr *temp; struct nodePtr *prev;
 prev = ll->head;
 for(temp= ll->head; temp != ((void *)0); temp=temp->next) {
  if(temp->dataPtr->value == value) {
   prev->next = temp->next;
   temp->next = ((void *)0);
   printf(">>==============Node pop'd with value : %d ================<<\n",value);
   free(temp->dataPtr);
   free(temp);
   return;
  }
  prev = temp;
 }
}


checkEmpty

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

result = 0LL;
if ( *a1 )
result = a1[1] != 0LL;
return result;
}

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

result = 0LL;
if ( *a1 )
result = a1[1] != 0LL;
return result;
}

original_code:
int checkEmpty(linkList *ll)
{
 if(ll->head && ll->tail) return 1;
 return 0;
}

canonical_original_code:
int checkEmpty(struct linkList *ll)
{
 if(ll->head && ll->tail) return 1;
 return 0;
}


addFront

decompiled_code:
int __fastcall addFront(_QWORD *a1, unsigned int a2)
{
_QWORD *v2; // rdx

createNode(a2);
if ( checkEmpty(a1) )
{
*v2 = *a1;
*a1 = v2;
}
else
{
*a1 = v2;
a1[1] = v2;
}
return printf("Node added at front of linkList with value : %d\n", a2);
}

canonical_decompiled_code:
int __fastcall func13(_QWORD *a1, unsigned int a2)
{
_QWORD *v2; // rdx

createNode(a2);
if ( func12(a1) )
{
*v2 = *a1;
*a1 = v2;
}
else
{
*a1 = v2;
a1[1] = v2;
}
return printf("Node added at front of linkList with value : %d\n", a2);
}

original_code:
void addFront(linkList *ll,int value)
{
 node *newNode = createNode(value);
 if(!checkEmpty(ll)) {
  ll->head = newNode;
  ll->tail = newNode;
 } else {
  newNode->next = ll->head;
  ll->head = newNode;
 }
 printf("Node added at front of linkList with value : %d\n",value);
}

canonical_original_code:
void addFront(struct linkList *ll, int value)
{
 struct nodePtr *newNode = createNode(value);
 if(!checkEmpty(ll)) {
  ll->head = newNode;
  ll->tail = newNode;
 } else {
  newNode->next = ll->head;
  ll->head = newNode;
 }
 printf("Node added at front of linkList with value : %d\n",value);
}


addBack

decompiled_code:
int __fastcall addBack(__int64 a1, unsigned int a2)
{
__int64 v2; // rdx

createNode(a2);
if ( checkEmpty((_QWORD *)a1) )
**(_QWORD **)(a1 + 8) = v2;
else
*(_QWORD *)a1 = v2;
*(_QWORD *)(a1 + 8) = v2;
return printf("Node added at back of linkList with value : %d\n", a2);
}

canonical_decompiled_code:
int __fastcall func14(__int64 a1, unsigned int a2)
{
__int64 v2; // rdx

createNode(a2);
if ( func12((_QWORD *)a1) )
**(_QWORD **)(a1 + 8) = v2;
else
*(_QWORD *)a1 = v2;
*(_QWORD *)(a1 + 8) = v2;
return printf("Node added at back of linkList with value : %d\n", a2);
}

original_code:
void addBack(linkList *ll,int value)
{
 node *newNode = createNode(value);
 if(!checkEmpty(ll)) {
  ll->head = newNode;
  ll->tail = newNode;
 } else {
  ll->tail->next = newNode;
  ll->tail = newNode;
 }
 printf("Node added at back of linkList with value : %d\n",value);
}

canonical_original_code:
void addBack(struct linkList *ll, int value)
{
 struct nodePtr *newNode = createNode(value);
 if(!checkEmpty(ll)) {
  ll->head = newNode;
  ll->tail = newNode;
 } else {
  ll->tail->next = newNode;
  ll->tail = newNode;
 }
 printf("Node added at back of linkList with value : %d\n",value);
}


popFront

original_code:
void popFront(linkList *ll)
{
 if(!checkEmpty(ll)) return;
 node *temp = ll->head;
 ll->head = ll->head->next;
 printf(">>==============Node pop'd from front ================<<\n");
 free(temp->dataPtr);
 free(temp);
}

canonical_original_code:
void popFront(struct linkList *ll)
{
 if(!checkEmpty(ll)) return;
 struct nodePtr *temp = ll->head;
 ll->head = ll->head->next;
 printf(">>==============Node pop'd from front ================<<\n");
 free(temp->dataPtr);
 free(temp);
}


popBack

original_code:
void popBack(linkList *ll)
{
 if(!checkEmpty(ll)) return;
 node *temp = ll->head;
 node *prev = temp;
 while(temp != ((void *)0)) {
  if(temp->next == ((void *)0)) {
   node *temp = ll->tail;
   ll->tail = prev;
   prev->next = ((void *)0);
   printf(">>==============Node pop'd from back ================<<\n");
   free(temp->dataPtr);
   free(temp);
   return;
  }
  prev = temp;
  temp = temp->next;
 }
}

canonical_original_code:
void popBack(struct linkList *ll)
{
 if(!checkEmpty(ll)) return;
 struct nodePtr *temp = ll->head;
 struct nodePtr *prev = temp;
 while(temp != ((void *)0)) {
  if(temp->next == ((void *)0)) {
   struct nodePtr *temp = ll->tail;
   ll->tail = prev;
   prev->next = ((void *)0);
   printf(">>==============Node pop'd from back ================<<\n");
   free(temp->dataPtr);
   free(temp);
   return;
  }
  prev = temp;
  temp = temp->next;
 }
}


addatPosition

decompiled_code:
int __fastcall addatPosition(_QWORD *a1, unsigned int a2)
{
int v2; // eax
unsigned int v3; // edx
unsigned int v5; // er12
_QWORD *v6; // rsi
_QWORD *v7; // rax
int v8; // edx
_QWORD *v9; // rcx

v2 = lengthlinkList(a1) + 1;
if ( v2 < (int)a2 )
{
LODWORD(v7) = puts("You entered the position out of the bound!");
}
else
{
v5 = v3;
if ( a2 == 1 )
{
addFront(a1, v3);
v6 = createNode(v5);
v7 = (_QWORD *)*a1;
if ( *a1 )
{
v9 = (_QWORD *)*a1;
LABEL_12:
*v9 = v6;
*v6 = v7;
LODWORD(v7) = printf(">>==============Node added at position %d with value : %d================<<\n", a2, v5);
}
}
else
{
if ( v2 == a2 )
addBack((__int64)a1, v3);
v6 = createNode(v5);
v7 = (_QWORD *)*a1;
if ( *a1 )
{
v8 = 1;
while ( 1 )
{
v9 = v7;
v7 = (_QWORD *)*v7;
++v8;
if ( !v7 )
break;
if ( a2 == v8 )
goto LABEL_12;
}
}
}
}
return (int)v7;
}

canonical_decompiled_code:
int __fastcall func19(_QWORD *a1, unsigned int a2)
{
int v2; // eax
unsigned int v3; // edx
unsigned int v5; // er12
_QWORD *v6; // rsi
_QWORD *v7; // rax
int v8; // edx
_QWORD *v9; // rcx

v2 = func18(a1) + 1;
if ( v2 < (int)a2 )
{
LODWORD(v7) = puts("You entered the position out of the bound!");
}
else
{
v5 = v3;
if ( a2 == 1 )
{
func13(a1, v3);
v6 = createNode(v5);
v7 = (_QWORD *)*a1;
if ( *a1 )
{
v9 = (_QWORD *)*a1;
LABEL_12:
*v9 = v6;
*v6 = v7;
LODWORD(v7) = printf(">>==============Node added at position %d with value : %d================<<\n", a2, v5);
}
}
else
{
if ( v2 == a2 )
func14((__int64)a1, v3);
v6 = createNode(v5);
v7 = (_QWORD *)*a1;
if ( *a1 )
{
v8 = 1;
while ( 1 )
{
v9 = v7;
v7 = (_QWORD *)*v7;
++v8;
if ( !v7 )
break;
if ( a2 == v8 )
goto LABEL_12;
}
}
}
}
return (int)v7;
}

original_code:
void addatPosition(linkList *ll,int position,int value)
{
 int length = lengthlinkList(ll);
 if(position > length + 1) {
  printf("You entered the position out of the bound!\n");
  return;
 }
 node *temp,*prev;
 int i = 1;
 if(position == 1) {
  addFront(ll,value);
 } else if(position == length + 1) {
  addBack(ll,value);
 }
 node *newNode = createNode(value);
 prev = ll->head;
 for(temp= ll->head; temp != ((void *)0); temp=temp->next) {
  if(i == position) {
   prev->next = newNode;
   newNode->next = temp;
   printf(">>==============Node added at position %d with value : %d================<<\n",position,value);
   return;
  }
  prev = temp;
  i++;
 }
}

canonical_original_code:
void addatPosition(struct linkList *ll, int position, int value)
{
 int length = lengthlinkList(ll);
 if(position > length + 1) {
  printf("You entered the position out of the bound!\n");
  return;
 }
 struct nodePtr *temp; struct nodePtr *prev;
 int i = 1;
 if(position == 1) {
  addFront(ll,value);
 } else if(position == length + 1) {
  addBack(ll,value);
 }
 struct nodePtr *newNode = createNode(value);
 prev = ll->head;
 for(temp= ll->head; temp != ((void *)0); temp=temp->next) {
  if(i == position) {
   prev->next = newNode;
   newNode->next = temp;
   printf(">>==============Node added at position %d with value : %d================<<\n",position,value);
   return;
  }
  prev = temp;
  i++;
 }
}

variable_types: position int

variable_types: length int


popatPosition

decompiled_code:
void __fastcall popatPosition(void ***a1, unsigned int a2)
{
int v2; // eax
void **v3; // rbp
int v4; // eax
void **v5; // rdx

v2 = lengthlinkList(a1);
if ( v2 < (int)a2 )
{
puts("You entered the position out of the bound!");
}
else if ( a2 == 1 )
{
popFront(a1);
v3 = *a1;
if ( *a1 )
{
v5 = *a1;
LABEL_12:
*v5 = *v3;
*v3 = 0LL;
printf(">>==============Node pop'd at position %d ================<<\n", a2);
free(v3[1]);
free(v3);
}
}
else
{
if ( v2 == a2 )
popBack(a1);
v3 = *a1;
if ( *a1 )
{
v4 = 1;
while ( 1 )
{
v5 = v3;
v3 = (void **)*v3;
++v4;
if ( !v3 )
break;
if ( a2 == v4 )
goto LABEL_12;
}
}
}
}

canonical_decompiled_code:
void __fastcall func20(void ***a1, unsigned int a2)
{
int v2; // eax
void **v3; // rbp
int v4; // eax
void **v5; // rdx

v2 = func18(a1);
if ( v2 < (int)a2 )
{
puts("You entered the position out of the bound!");
}
else if ( a2 == 1 )
{
func15(a1);
v3 = *a1;
if ( *a1 )
{
v5 = *a1;
LABEL_12:
*v5 = *v3;
*v3 = 0LL;
printf(">>==============Node pop'd at position %d ================<<\n", a2);
free(v3[1]);
free(v3);
}
}
else
{
if ( v2 == a2 )
func16(a1);
v3 = *a1;
if ( *a1 )
{
v4 = 1;
while ( 1 )
{
v5 = v3;
v3 = (void **)*v3;
++v4;
if ( !v3 )
break;
if ( a2 == v4 )
goto LABEL_12;
}
}
}
}

original_code:
void popatPosition(linkList *ll,int position)
{
 int length = lengthlinkList(ll);
 if(position > length) {
  printf("You entered the position out of the bound!\n");
  return;
 }
 node *temp,*prev;
 int i = 1;
 if(position == 1) {
  popFront(ll);
 } else if(position == length) {
  popBack(ll);
 }
 prev = ll->head;
 for(temp= ll->head; temp != ((void *)0); temp=temp->next) {
  if(i == position) {
   prev->next = temp->next;
   temp->next = ((void *)0);
   printf(">>==============Node pop'd at position %d ================<<\n",position);
   free(temp->dataPtr);
   free(temp);
   return;
  }
  prev = temp;
  i++;
 }
}

canonical_original_code:
void popatPosition(struct linkList *ll, int position)
{
 int length = lengthlinkList(ll);
 if(position > length) {
  printf("You entered the position out of the bound!\n");
  return;
 }
 struct nodePtr *temp; struct nodePtr *prev;
 int i = 1;
 if(position == 1) {
  popFront(ll);
 } else if(position == length) {
  popBack(ll);
 }
 prev = ll->head;
 for(temp= ll->head; temp != ((void *)0); temp=temp->next) {
  if(i == position) {
   prev->next = temp->next;
   temp->next = ((void *)0);
   printf(">>==============Node pop'd at position %d ================<<\n",position);
   free(temp->dataPtr);
   free(temp);
   return;
  }
  prev = temp;
  i++;
 }
}


createlinklist

decompiled_code:
_QWORD *createlinklist()
{
_QWORD *result; // rax

result = malloc(0x10uLL);
*result = 0LL;
result[1] = 0LL;
return result;
}

original_code:
dlinklist* createlinklist()
{
 dlinklist* ll = (dlinklist*)malloc(sizeof(dlinklist));
 ll->head = ((void *)0);
 ll->tail = ((void *)0);
 return ll;
}

canonical_original_code:
struct dlinklist *createlinklist()
{
 struct dlinklist *ll = (dlinklist*)malloc(sizeof(dlinklist));
 ll->head = ((void *)0);
 ll->tail = ((void *)0);
 return ll;
}

variable_types: struct dlinklist { struct nodePtr { struct nodePtr *next; struct nodePtr *prev; struct data { float val; } *dataPtr; } *head; struct nodePtr *tail; } *

user_defined_types: struct dlinklist { struct nodePtr *head; struct nodePtr *tail; }

user_defined_types: struct nodePtr { struct nodePtr *next; struct nodePtr *prev; struct data *dataPtr; }


listSize

decompiled_code:
__int64 __fastcall listSize(_QWORD *a1)
{
unsigned int v1; // er8
_QWORD *v2; // rax

v1 = checkEmpty(a1);
if ( v1 )
{
v2 = (_QWORD *)*a1;
v1 = 0;
if ( *a1 )
{
do
{
v2 = (_QWORD *)*v2;
++v1;
}
while ( v2 );
}
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func13(_QWORD *a1)
{
unsigned int v1; // er8
_QWORD *v2; // rax

v1 = func11(a1);
if ( v1 )
{
v2 = (_QWORD *)*a1;
v1 = 0;
if ( *a1 )
{
do
{
v2 = (_QWORD *)*v2;
++v1;
}
while ( v2 );
}
}
return v1;
}

original_code:
int listSize(dlinklist *ll)
{
 if(!checkEmpty(ll)) return 0;
 node *temp = ll->head;
 int size = 0;
 while(temp != ((void *)0)) {
  size++;
  temp = temp->next;
 }
 return size;
}

canonical_original_code:
int listSize(struct dlinklist *ll)
{
 if(!checkEmpty(ll)) return 0;
 struct nodePtr *temp = ll->head;
 int size = 0;
 while(temp != ((void *)0)) {
  size++;
  temp = temp->next;
 }
 return size;
}

variable_types: struct nodePtr { struct nodePtr *next; struct nodePtr *prev; struct data { float val; } *dataPtr; } *

variable_types: size int


searchRemove

decompiled_code:
int __fastcall searchRemove(void **a1, float a2)
{
void *v2; // rax
void *v4; // rbp
float *v5; // rdi

v2 = *a1;
if ( *a1 )
{
v4 = *a1;
while ( 1 )
{
v5 = (float *)*((_QWORD *)v4 + 2);
if ( a2 == *v5 )
break;
v4 = *(void **)v4;
if ( !v4 )
return (int)v2;
}
if ( v4 == v2 )
{
popFront(a1);
}
else if ( v4 == a1[1] )
{
popBack((void ***)a1);
}
else
{
**((_QWORD **)v4 + 1) = *(_QWORD *)v4;
free(v5);
free(v4);
}
LODWORD(v2) = printf(">>==============Node with value: %f pop'd ================<<\n", a2);
}
return (int)v2;
}

original_code:
void searchRemove(dlinklist *ll,float val)
{
 node *temp = ll->head;
 data *tempdata;
 while(temp != ((void *)0)) {
  if(temp->dataPtr->val == val) {
   if(temp == ll->head) {
    popFront(ll);
   } else if(temp == ll->tail) {
    popBack(ll);
   } else {
    temp->prev->next = temp->next;
    temp->next = ((void *)0);
    tempdata = temp->dataPtr;
    free(tempdata);
    free(temp);
   }
   printf(">>==============Node with value: %f pop'd ================<<\n",val);
   return;
  } else {
   temp = temp->next;
  }
 }
}

canonical_original_code:
void searchRemove(struct dlinklist *ll, float val)
{
 struct nodePtr *temp = ll->head;
 struct data *tempdata;
 while(temp != ((void *)0)) {
  if(temp->dataPtr->val == val) {
   if(temp == ll->head) {
    popFront(ll);
   } else if(temp == ll->tail) {
    popBack(ll);
   } else {
    temp->prev->next = temp->next;
    temp->next = ((void *)0);
    tempdata = temp->dataPtr;
    free(tempdata);
    free(temp);
   }
   printf(">>==============Node with value: %f pop'd ================<<\n",val);
   return;
  } else {
   temp = temp->next;
  }
 }
}

variable_types: val float

variable_types:
tempdata
struct data { float val; } *


createStack

decompiled_code:
_QWORD *createStack()
{
_QWORD *v0; // r12

v0 = malloc(8uLL);
*v0 = createlinklist();
return v0;
}

canonical_decompiled_code:
_QWORD *func22()
{
_QWORD *v0; // r12

v0 = malloc(8uLL);
*v0 = func7();
return v0;
}

original_code:
stack* createStack()
{
 stack* new_stack = (stack*)malloc(sizeof(stack));
 new_stack->ll = createlinklist();
 return new_stack;
}

canonical_original_code:
struct stack *createStack()
{
 struct stack *new_stack = (stack*)malloc(sizeof(stack));
 new_stack->ll = createlinklist();
 return new_stack;
}

variable_types: struct stack { struct dlinklist { struct nodePtr { struct nodePtr *next; struct nodePtr *prev; struct data { float val; } *dataPtr; } *head; struct nodePtr *tail; } *ll; } *


stackPush

decompiled_code:
int __fastcall stackPush(_QWORD **a1, __int64 a2)
{
return addBack(*a1, a2);
}

canonical_decompiled_code:
int __fastcall func23(_QWORD **a1, __int64 a2)
{
return func10(*a1, a2);
}

original_code:
void stackPush(stack *s,data *d)
{
 addBack(s->ll,d);
}

canonical_original_code:
void stackPush(struct stack *s, struct data *d)
{
 addBack(s->ll,d);
}

variable_types:
d
struct data *


stackPrint

decompiled_code:
int __fastcall stackPrint(__int64 ****a1)
{
return printList(*a1);
}

canonical_decompiled_code:
int __fastcall func25(__int64 ****a1)
{
return func12(*a1);
}

original_code:
void stackPrint(stack *s)
{
 printList(s->ll);
}

canonical_original_code:
void stackPrint(struct stack *s)
{
 printList(s->ll);
}


stackSize

decompiled_code:
__int64 __fastcall stackSize(_QWORD **a1)
{
return listSize(*a1);
}

canonical_decompiled_code:
__int64 __fastcall func26(_QWORD **a1)
{
return func13(*a1);
}

original_code:
int stackSize(stack *s)
{
 return listSize(s->ll);
}

canonical_original_code:
int stackSize(struct stack *s)
{
 return listSize(s->ll);
}


stackClean

decompiled_code:
void __fastcall stackClean(void *ptr)
{
cleanList(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func27(void *ptr)
{
func19(*(void **)ptr);
free(ptr);
}

original_code:
void stackClean(stack *s)
{
 cleanList(s->ll);
 free(s);
}

canonical_original_code:
void stackClean(struct stack *s)
{
 cleanList(s->ll);
 free(s);
}


repo: sachitmuckaden/gtthreads

decompiled_code:
__int64 schedule_next()
{
ucontext_t **v0; // rbx
__int64 v1; // rax
int v2; // edx
_QWORD *v4; // rax

sigprocmask(0, &threadprocmask, 0LL);
if ( size_of_q(&readyqueue) > 1 )
{
v0 = (ucontext_t **)current_thrcb;
if ( *(_DWORD *)(current_thrcb + 20) )
{
v4 = (_QWORD *)queue_remove(&readyqueue, *(_QWORD *)(current_thrcb + 8));
queue_insert_normal(&deletequeue, *v4);
v0 = (ucontext_t **)current_thrcb;
}
do
{
v1 = queue_next(&readyqueue);
v2 = *(_DWORD *)(v1 + 16);
current_thrcb = v1;
}
while ( v2 );
interval.it_value.tv_usec = timeslice;
sigprocmask(1, &threadprocmask, 0LL);
if ( setmain )
{
setitimer(ITIMER_VIRTUAL, &interval, 0LL);
swapcontext(*v0, *(const ucontext_t **)current_thrcb);
}
else
{
setmain = 1;
setitimer(ITIMER_VIRTUAL, &interval, 0LL);
swapcontext(&main_ctxt, *(const ucontext_t **)current_thrcb);
}
}
sigprocmask(1, &threadprocmask, 0LL);
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
ucontext_t **v0; // rbx
__int64 v1; // rax
int v2; // edx
_QWORD *v4; // rax

sigprocmask(0, &threadprocmask, 0LL);
if ( size_of_q(&readyqueue) > 1 )
{
v0 = (ucontext_t **)current_thrcb;
if ( *(_DWORD *)(current_thrcb + 20) )
{
v4 = (_QWORD *)queue_remove(&readyqueue, *(_QWORD *)(current_thrcb + 8));
queue_insert_normal(&deletequeue, *v4);
v0 = (ucontext_t **)current_thrcb;
}
do
{
v1 = queue_next(&readyqueue);
v2 = *(_DWORD *)(v1 + 16);
current_thrcb = v1;
}
while ( v2 );
interval.it_value.tv_usec = timeslice;
sigprocmask(1, &threadprocmask, 0LL);
if ( setmain )
{
setitimer(ITIMER_VIRTUAL, &interval, 0LL);
swapcontext(*v0, *(const ucontext_t **)current_thrcb);
}
else
{
setmain = 1;
setitimer(ITIMER_VIRTUAL, &interval, 0LL);
swapcontext(&main_ctxt, *(const ucontext_t **)current_thrcb);
}
}
sigprocmask(1, &threadprocmask, 0LL);
return 0LL;
}

original_code:
void* schedule_next(int signum)
{
 sigprocmask(0, &threadprocmask, ((void *)0));
 if (size_of_q(&readyqueue)>1)
 {
  if(current_thrcb->iscomplete)
  {
   queue_insert_normal(&deletequeue, (queue_remove(&readyqueue, current_thrcb->thrid))->thrcb);
  }
  if(0)printf("Scheduling next thread-----------------\n");
  gtthread_tcb* tmpthr;
  tmpthr = current_thrcb;
  current_thrcb = queue_next(&readyqueue);
  while(current_thrcb->isblocked)
  {
   if(0)printf("Current thread blocked: %ld\n", (long)current_thrcb->thrid);
   current_thrcb = queue_next(&readyqueue);
  }
  if(0)printf("Swapping %ld for %ld\n", tmpthr->thrid, current_thrcb->thrid);
  interval.it_value.tv_usec = timeslice;
  sigprocmask(1, &threadprocmask, ((void *)0));
  if(!setmain)
  {
   if(0)printf("Main has been set\n");
   setmain = 1;
   setitimer(ITIMER_VIRTUAL, &interval, ((void *)0));
   swapcontext(&main_ctxt, current_thrcb->ctxt);
  }
  else
  {
   setitimer(ITIMER_VIRTUAL, &interval, ((void *)0));
   swapcontext(tmpthr->ctxt, current_thrcb->ctxt);
  }
 }
 sigprocmask(1, &threadprocmask, ((void *)0));
 return (void*) 0;
}

canonical_original_code:
void *schedule_next(int signum)
{
 sigprocmask(0, &threadprocmask, ((void *)0));
 if (size_of_q(&readyqueue)>1)
 {
  if(current_thrcb->iscomplete)
  {
   queue_insert_normal(&deletequeue, (queue_remove(&readyqueue, current_thrcb->thrid))->thrcb);
  }
  if(0)printf("Scheduling next thread-----------------\n");
  struct gtthread_tcb *tmpthr;
  tmpthr = current_thrcb;
  current_thrcb = queue_next(&readyqueue);
  while(current_thrcb->isblocked)
  {
   if(0)printf("Current thread blocked: %ld\n", (long)current_thrcb->thrid);
   current_thrcb = queue_next(&readyqueue);
  }
  if(0)printf("Swapping %ld for %ld\n", tmpthr->thrid, current_thrcb->thrid);
  interval.it_value.tv_usec = timeslice;
  sigprocmask(1, &threadprocmask, ((void *)0));
  if(!setmain)
  {
   if(0)printf("Main has been set\n");
   setmain = 1;
   setitimer(ITIMER_VIRTUAL, &interval, ((void *)0));
   swapcontext(&main_ctxt, current_thrcb->ctxt);
  }
  else
  {
   setitimer(ITIMER_VIRTUAL, &interval, ((void *)0));
   swapcontext(tmpthr->ctxt, current_thrcb->ctxt);
  }
 }
 sigprocmask(1, &threadprocmask, ((void *)0));
 return (void *) 0;
}

variable_types: signum int

variable_types: struct gtthread_tcb { struct ucontext_t { unsigned long uc_flags; struct ucontext_t *uc_link; struct stack_t { void *ss_sp; int ss_flags; unsigned long ss_size; } uc_stack; struct mcontext_t { long long gregs[23]; struct _libc_fpstate { unsigned short cwd; unsigned short swd; unsigned short ftw; unsigned short fop; unsigned long rip; unsigned long rdp; unsigned int mxcsr; unsigned int mxcr_mask; struct _libc_fpxreg { unsigned short significand[4]; unsigned short exponent; unsigned short __glibc_reserved1[3]; } _st[8]; struct _libc_xmmreg { unsigned int element[4]; } _xmm[16]; unsigned int __glibc_reserved1[24]; } *fpregs; unsigned long long __reserved1[8]; } uc_mcontext; struct __sigset_t { unsigned long __val[-1]; } uc_sigmask; struct _libc_fpstate __fpregs_mem; unsigned long long __ssp[4]; } *ctxt; long thrid; int isblocked; int iscomplete; void *ret; struct queue { struct queue_node { struct gtthread_tcb *thrcb; struct queue_node *next; struct queue_node *prev; } *front; struct queue_node *back; long nelements; struct queue_node *current; } join_queue; void *joinval; } *

return_type: void *

user_defined_types: struct gtthread_tcb { struct ucontext_t *ctxt; long thrid; int isblocked; int iscomplete; void *ret; struct queue join_queue; void *joinval; }

user_defined_types: struct queue { struct queue_node *front; struct queue_node *back; long nelements; struct queue_node *current; }

user_defined_types: struct ucontext_t { unsigned long uc_flags; struct ucontext_t *uc_link; struct stack_t uc_stack; struct mcontext_t uc_mcontext; struct __sigset_t uc_sigmask; struct _libc_fpstate __fpregs_mem; unsigned long long __ssp[4]; }

user_defined_types: struct mcontext_t { long long gregs[23]; struct _libc_fpstate *fpregs; unsigned long long __reserved1[8]; }

user_defined_types: struct _libc_fpstate { unsigned short cwd; unsigned short swd; unsigned short ftw; unsigned short fop; unsigned long rip; unsigned long rdp; unsigned int mxcsr; unsigned int mxcr_mask; struct _libc_fpxreg _st[8]; struct _libc_xmmreg _xmm[16]; unsigned int __glibc_reserved1[24]; }


initializesighandler

decompiled_code:
__int64 initializesighandler()
{
sigemptyset(&threadprocmask);
sigaddset(&threadprocmask, 26);
new_action.__val[0] = (unsigned __int64)schedule_next;
memset((void *)(unsigned int)((_DWORD)&new_action + 8), 0, 0x90uLL);
sigemptyset((sigset_t *)(unsigned int)((_DWORD)&new_action + 8));
*((_DWORD *)&new_action + 34) = 0;
return (sigaction(26, (const struct sigaction *)&new_action, 0LL) >> 31) | 1u;
}

canonical_decompiled_code:
__int64 func1()
{
sigemptyset(&threadprocmask);
sigaddset(&threadprocmask, 26);
new_action.__val[0] = (unsigned __int64)schedule_next;
memset((void *)(unsigned int)((_DWORD)&new_action + 8), 0, 0x90uLL);
sigemptyset((sigset_t *)(unsigned int)((_DWORD)&new_action + 8));
*((_DWORD *)&new_action + 34) = 0;
return (sigaction(26, (const struct sigaction *)&new_action, 0LL) >> 31) | 1u;
}

original_code:
int initializesighandler()
{
 sigemptyset(&threadprocmask);
 sigaddset(&threadprocmask, 26);
 memset(&new_action,0, sizeof(new_action));
 new_action.__sigaction_handler.sa_handler = &schedule_next;
 sigemptyset (&new_action.sa_mask);
 new_action.sa_flags = 0;
 if(0)printf("Signal handler set up\n");
 if(sigaction (26, &new_action, ((void *)0))<0)
   return -1;
 return 1;
}


decompiled_code:
int __fastcall gtthread_init(__suseconds_t a1)
{
_QWORD *v1; // rax

initializesighandler();
interval.it_value.tv_usec = a1;
interval.it_interval = 0LL;
timeslice = a1;
interval.it_value.tv_sec = 0LL;
current_thr_id = 0LL;
active_threads = 0;
setmain = 0;
queue_init(&readyqueue);
queue_init(&deletequeue);
v1 = malloc(0x48uLL);
v1[1] = 0LL;
v1[2] = 0LL;
*v1 = &main_ctxt;
main_thrcb = (__int64)v1;
queue_init(v1 + 4);
*(_QWORD *)(main_thrcb + 64) = 0LL;
queue_insert(&readyqueue);
queue_set_current(&readyqueue);
initialized = 1;
current_thrcb = main_thrcb;
return setitimer(ITIMER_VIRTUAL, &interval, 0LL);
}

canonical_decompiled_code:
int __fastcall func2(__suseconds_t a1)
{
_QWORD *v1; // rax

func1();
interval.it_value.tv_usec = a1;
interval.it_interval = 0LL;
timeslice = a1;
interval.it_value.tv_sec = 0LL;
current_thr_id = 0LL;
active_threads = 0;
setmain = 0;
queue_init(&readyqueue);
queue_init(&deletequeue);
v1 = malloc(0x48uLL);
v1[1] = 0LL;
v1[2] = 0LL;
*v1 = &main_ctxt;
main_thrcb = (__int64)v1;
queue_init(v1 + 4);
*(_QWORD *)(main_thrcb + 64) = 0LL;
queue_insert(&readyqueue);
queue_set_current(&readyqueue);
initialized = 1;
current_thrcb = main_thrcb;
return setitimer(ITIMER_VIRTUAL, &interval, 0LL);
}

original_code:
void gtthread_init(long period)
{
 int rc = 0;
 if((rc=initializesighandler())<0)
 {
  if(0)printf("Signal handler error\n");
 }
 memset(&interval,0,sizeof(interval));
 interval.it_interval.tv_sec = 0;
 interval.it_interval.tv_usec = 0;
 interval.it_value.tv_sec = 0;
 interval.it_value.tv_usec = period;
 timeslice = period;
 current_thr_id = 0;
 active_threads = 0;
 setmain = 0;
 queue_init(&readyqueue);
 queue_init(&deletequeue);
 main_thrcb = (gtthread_tcb*) malloc(sizeof(gtthread_tcb));
 main_thrcb->thrid = 0;
 main_thrcb->isblocked = 0;
 main_thrcb->iscomplete = 0;
 main_thrcb->ctxt =&main_ctxt;
 queue_init(&main_thrcb->join_queue);
 main_thrcb->joinval = ((void *)0);
 queue_insert(&readyqueue, main_thrcb);
 queue_set_current(&readyqueue);
 current_thrcb = main_thrcb;
 initialized = 1;
 setitimer(ITIMER_VIRTUAL, &interval, ((void *)0));
}

canonical_original_code:
void gtthread_init(long period)
{
 int rc = 0;
 if((rc=initializesighandler())<0)
 {
  if(0)printf("Signal handler error\n");
 }
 memset(&interval,0,sizeof(interval));
 interval.it_interval.tv_sec = 0;
 interval.it_interval.tv_usec = 0;
 interval.it_value.tv_sec = 0;
 interval.it_value.tv_usec = period;
 timeslice = period;
 current_thr_id = 0;
 active_threads = 0;
 setmain = 0;
 queue_init(&readyqueue);
 queue_init(&deletequeue);
 main_thrcb = (struct gtthread_tcb *) malloc(sizeof(gtthread_tcb));
 main_thrcb->thrid = 0;
 main_thrcb->isblocked = 0;
 main_thrcb->iscomplete = 0;
 main_thrcb->ctxt =&main_ctxt;
 queue_init(&main_thrcb->join_queue);
 main_thrcb->joinval = ((void *)0);
 queue_insert(&readyqueue, main_thrcb);
 queue_set_current(&readyqueue);
 current_thrcb = main_thrcb;
 initialized = 1;
 setitimer(ITIMER_VIRTUAL, &interval, ((void *)0));
}

variable_types: period long

variable_types: rc int

user_defined_types: struct stack_t { void *ss_sp; int ss_flags; unsigned long ss_size; }

user_defined_types: struct __sigset_t { unsigned long __val[-1]; }

user_defined_types: struct queue_node { struct gtthread_tcb *thrcb; struct queue_node *next; struct queue_node *prev; }

user_defined_types: struct _libc_fpxreg { unsigned short significand[4]; unsigned short exponent; unsigned short __glibc_reserved1[3]; }

user_defined_types: struct _libc_xmmreg { unsigned int element[4]; }


decompiled_code:
__int64 __fastcall gtthread_create(__int64 *a1, __int64 a2, __int64 a3)
{
_QWORD *v3; // rbp
__int64 v4; // rax
ucontext_t *ucp; // [rsp+18h] [rbp-20h]

sigprocmask(0, &threadprocmask, 0LL);
if ( !initialized )
{
puts("Attempted to create without initializing");
exit(0);
}
ucp = (ucontext_t *)malloc(0x3C8uLL);
if ( getcontext(ucp) == -1 )
return 0xFFFFFFFFLL;
ucp->uc_stack.ss_sp = malloc(0x4000uLL);
ucp->uc_stack.ss_size = 0x4000LL;
ucp->uc_link = 0LL;
if ( sigemptyset(&ucp->uc_sigmask) < 0 )
return 0xFFFFFFFFLL;
makecontext(ucp, wrapper_function, 2, a2, a3);
v3 = malloc(0x48uLL);
*v3 = ucp;
v4 = current_thr_id;
v3[2] = 0LL;
++v4;
v3[8] = 0LL;
current_thr_id = v4;
v3[1] = v4;
*a1 = v4;
queue_init(v3 + 4);
queue_insert(&readyqueue);
sigprocmask(1, &threadprocmask, 0LL);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 *a1, __int64 a2, __int64 a3)
{
_QWORD *v3; // rbp
__int64 v4; // rax
ucontext_t *ucp; // [rsp+18h] [rbp-20h]

sigprocmask(0, &threadprocmask, 0LL);
if ( !initialized )
{
puts("Attempted to create without initializing");
exit(0);
}
ucp = (ucontext_t *)malloc(0x3C8uLL);
if ( getcontext(ucp) == -1 )
return 0xFFFFFFFFLL;
ucp->uc_stack.ss_sp = malloc(0x4000uLL);
ucp->uc_stack.ss_size = 0x4000LL;
ucp->uc_link = 0LL;
if ( sigemptyset(&ucp->uc_sigmask) < 0 )
return 0xFFFFFFFFLL;
makecontext(ucp, wrapper_function, 2, a2, a3);
v3 = malloc(0x48uLL);
*v3 = ucp;
v4 = current_thr_id;
v3[2] = 0LL;
++v4;
v3[8] = 0LL;
current_thr_id = v4;
v3[1] = v4;
*a1 = v4;
queue_init(v3 + 4);
queue_insert(&readyqueue);
sigprocmask(1, &threadprocmask, 0LL);
return 1LL;
}

original_code:
int gtthread_create(gtthread_t* thread,
                     void *(*start_routine)(void *),
                     void *arg)
{
 ucontext_t* ctxt;
 gtthread_tcb* tcb;
 sigprocmask(0, &threadprocmask, ((void *)0));
 if(!initialized)
 {
  printf("Attempted to create without initializing\n");
  exit(0);
 }
 ctxt = (ucontext_t*)malloc(sizeof(ucontext_t));
 if (getcontext(ctxt) == -1)
 {
  if(0)printf("Getcontext error\n");
  return -1;
 }
 char* stck = (char*)malloc(16384* sizeof(char));
 ctxt->uc_stack.ss_sp = stck;
 ctxt->uc_stack.ss_size = 16384*sizeof(char);
 ctxt->uc_link = ((void *)0);
 if(sigemptyset(&ctxt->uc_sigmask)<0)
 {
  return -1;
 }
 makecontext(ctxt, wrapper_function, 2, start_routine, arg);
 tcb = (gtthread_tcb*) malloc(sizeof(gtthread_tcb));
 tcb->ctxt = ctxt;
 tcb->thrid = ++current_thr_id;
 *thread = tcb->thrid;
 tcb->isblocked = 0;
 tcb->iscomplete = 0;
 tcb->joinval = ((void *)0);
 queue_init(&tcb->join_queue);
 queue_insert(&readyqueue, tcb);
 if(0)printf("Create returning\n");
 sigprocmask(1, &threadprocmask, ((void *)0));
 return 1;
}

canonical_original_code:
int gtthread_create(long *thread, void *(*start_routine)(void *), void *arg)
{
 struct ucontext_t *ctxt;
 struct gtthread_tcb *tcb;
 sigprocmask(0, &threadprocmask, ((void *)0));
 if(!initialized)
 {
  printf("Attempted to create without initializing\n");
  exit(0);
 }
 ctxt = (struct ucontext_t *)malloc(sizeof(ucontext_t));
 if (getcontext(ctxt) == -1)
 {
  if(0)printf("Getcontext error\n");
  return -1;
 }
 char *stck = (char*)malloc(16384* sizeof(char));
 ctxt->uc_stack.ss_sp = stck;
 ctxt->uc_stack.ss_size = 16384*sizeof(char);
 ctxt->uc_link = ((void *)0);
 if(sigemptyset(&ctxt->uc_sigmask)<0)
 {
  return -1;
 }
 makecontext(ctxt, wrapper_function, 2, start_routine, arg);
 tcb = (struct gtthread_tcb *) malloc(sizeof(gtthread_tcb));
 tcb->ctxt = ctxt;
 tcb->thrid = ++current_thr_id;
 *thread = tcb->thrid;
 tcb->isblocked = 0;
 tcb->iscomplete = 0;
 tcb->joinval = ((void *)0);
 queue_init(&tcb->join_queue);
 queue_insert(&readyqueue, tcb);
 if(0)printf("Create returning\n");
 sigprocmask(1, &threadprocmask, ((void *)0));
 return 1;
}

variable_types:
thread
long *

variable_types:
arg
void *

variable_types: struct ucontext_t { unsigned long uc_flags; struct ucontext_t *uc_link; struct stack_t { void *ss_sp; int ss_flags; unsigned long ss_size; } uc_stack; struct mcontext_t { long long gregs[23]; struct _libc_fpstate { unsigned short cwd; unsigned short swd; unsigned short ftw; unsigned short fop; unsigned long rip; unsigned long rdp; unsigned int mxcsr; unsigned int mxcr_mask; struct _libc_fpxreg { unsigned short significand[4]; unsigned short exponent; unsigned short __glibc_reserved1[3]; } _st[8]; struct _libc_xmmreg { unsigned int element[4]; } _xmm[16]; unsigned int __glibc_reserved1[24]; } *fpregs; unsigned long long __reserved1[8]; } uc_mcontext; struct __sigset_t { unsigned long __val[-1]; } uc_sigmask; struct _libc_fpstate __fpregs_mem; unsigned long long __ssp[4]; } *

variable_types:
stck
char *


decompiled_code:
__int64 __fastcall gtthread_join(__int64 a1, _QWORD *a2)
{
__int64 v2; // rax
__int64 v4; // rax

sigprocmask(0, &threadprocmask, 0LL);
v2 = queue_search(&readyqueue, a1);
if ( v2 )
{
queue_insert_normal(v2 + 32, current_thrcb);
*(_DWORD *)(current_thrcb + 16) = 1;
schedule_next(26LL);
if ( a2 )
*a2 = *(_QWORD *)(current_thrcb + 64);
LABEL_4:
sigprocmask(1, &threadprocmask, 0LL);
return 0LL;
}
v4 = queue_search(&deletequeue, a1);
if ( v4 )
{
if ( a2 )
*a2 = *(_QWORD *)(v4 + 24);
goto LABEL_4;
}
sigprocmask(1, &threadprocmask, 0LL);
return 3LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, _QWORD *a2)
{
__int64 v2; // rax
__int64 v4; // rax

sigprocmask(0, &threadprocmask, 0LL);
v2 = queue_search(&readyqueue, a1);
if ( v2 )
{
queue_insert_normal(v2 + 32, current_thrcb);
*(_DWORD *)(current_thrcb + 16) = 1;
func0(26LL);
if ( a2 )
*a2 = *(_QWORD *)(current_thrcb + 64);
LABEL_4:
sigprocmask(1, &threadprocmask, 0LL);
return 0LL;
}
v4 = queue_search(&deletequeue, a1);
if ( v4 )
{
if ( a2 )
*a2 = *(_QWORD *)(v4 + 24);
goto LABEL_4;
}
sigprocmask(1, &threadprocmask, 0LL);
return 3LL;
}

original_code:
int gtthread_join(gtthread_t thread, void **status)
{
 sigprocmask(0, &threadprocmask, ((void *)0));
 gtthread_tcb* joinable = queue_search(&readyqueue, thread);
 if(joinable==((void *)0))
 {
  joinable = queue_search(&deletequeue,thread);
  if(joinable!=((void *)0))
  {
   if(0)printf("Thread over returning\n");
   if(status!=((void *)0))
    *status = joinable->ret;
   sigprocmask(1, &threadprocmask, ((void *)0));
   return 0;
  }
 }
 if(joinable==((void *)0))
 {
  sigprocmask(1, &threadprocmask, ((void *)0));
  return 3;
 }
 queue_insert_normal(&joinable->join_queue, current_thrcb);
 current_thrcb->isblocked =1;
 schedule_next(26);
 if(status!=((void *)0))
  *status = current_thrcb->joinval;
 sigprocmask(1, &threadprocmask, ((void *)0));
 return 0;
}

canonical_original_code:
int gtthread_join(long thread, void **status)
{
 sigprocmask(0, &threadprocmask, ((void *)0));
 struct gtthread_tcb *joinable = queue_search(&readyqueue, thread);
 if(joinable==((void *)0))
 {
  joinable = queue_search(&deletequeue,thread);
  if(joinable!=((void *)0))
  {
   if(0)printf("Thread over returning\n");
   if(status!=((void *)0))
    *status = joinable->ret;
   sigprocmask(1, &threadprocmask, ((void *)0));
   return 0;
  }
 }
 if(joinable==((void *)0))
 {
  sigprocmask(1, &threadprocmask, ((void *)0));
  return 3;
 }
 queue_insert_normal(&joinable->join_queue, current_thrcb);
 current_thrcb->isblocked =1;
 schedule_next(26);
 if(status!=((void *)0))
  *status = current_thrcb->joinval;
 sigprocmask(1, &threadprocmask, ((void *)0));
 return 0;
}

variable_types: thread long

variable_types:
status
void **


decompiled_code:
__int64 gtthread_yield()
{
return schedule_next(2LL);
}

canonical_decompiled_code:
__int64 func5()
{
return func0(2LL);
}

original_code:
void gtthread_yield(void)
{
 schedule_next(2);
}

canonical_original_code:
void gtthread_yield()
{
 schedule_next(2);
}


decompiled_code:
__int64 gtthread_self()
{
return *(_QWORD *)(current_thrcb + 8);
}

canonical_decompiled_code:
__int64 func6()
{
return *(_QWORD *)(current_thrcb + 8);
}

original_code:
gtthread_t gtthread_self(void)
{
 return current_thrcb->thrid;
}

canonical_original_code:
long gtthread_self()
{
 return current_thrcb->thrid;
}

return_type: long


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

sigprocmask(0, &threadprocmask, 0LL);
v2 = current_thrcb;
*(_DWORD *)(current_thrcb + 20) = 1;
v2 += 32LL;
*(_QWORD *)(v2 - 8) = a1;
if ( size_of_q(v2) > 0 )
queue_unblock_all(current_thrcb + 32, a1);
if ( size_of_q(&readyqueue) <= 0 )
return sigprocmask(1, &threadprocmask, 0LL);
sigprocmask(1, &threadprocmask, 0LL);
return schedule_next(2LL);
}

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

sigprocmask(0, &threadprocmask, 0LL);
v2 = current_thrcb;
*(_DWORD *)(current_thrcb + 20) = 1;
v2 += 32LL;
*(_QWORD *)(v2 - 8) = a1;
if ( size_of_q(v2) > 0 )
queue_unblock_all(current_thrcb + 32, a1);
if ( size_of_q(&readyqueue) <= 0 )
return sigprocmask(1, &threadprocmask, 0LL);
sigprocmask(1, &threadprocmask, 0LL);
return func0(2LL);
}

original_code:
void gtthread_exit(void *retval)
{
 sigprocmask(0, &threadprocmask, ((void *)0));
 current_thrcb->iscomplete = 1;
 current_thrcb->ret = retval;
 if(size_of_q(&(current_thrcb->join_queue))>0)
 {
  queue_unblock_all(&(current_thrcb->join_queue), retval);
 }
 if(size_of_q(&readyqueue)>0)
 {
  sigprocmask(1, &threadprocmask, ((void *)0));
  schedule_next(2);
 }
 else
  sigprocmask(1, &threadprocmask, ((void *)0));
}

variable_types:
retval
void *


decompiled_code:
void __fastcall wrapper_function(__int64 (__fastcall *a1)(__int64), __int64 a2)
{
__int64 v2; // rbp

v2 = a1(a2);
sigprocmask(0, &threadprocmask, 0LL);
sigprocmask(1, &threadprocmask, 0LL);
gtthread_exit(v2);
}

canonical_decompiled_code:
void __fastcall func8(__int64 (__fastcall *a1)(__int64), __int64 a2)
{
__int64 v2; // rbp

v2 = a1(a2);
sigprocmask(0, &threadprocmask, 0LL);
sigprocmask(1, &threadprocmask, 0LL);
func7(v2);
}

original_code:
void wrapper_function(void*(*start_routine(void*)), void* params)
{
 void* retval;
 retval = start_routine(params);
 sigprocmask(0, &threadprocmask, ((void *)0));
 if(0)
 {
 }
 sigprocmask(1, &threadprocmask, ((void *)0));
 gtthread_exit(retval);
}

canonical_original_code:
void wrapper_function(void **start_routine(void *), void *params)
{
 void *retval;
 retval = start_routine(params);
 sigprocmask(0, &threadprocmask, ((void *)0));
 if(0)
 {
 }
 sigprocmask(1, &threadprocmask, ((void *)0));
 gtthread_exit(retval);
}

variable_types:
params
void *


decompiled_code:
__int64 __fastcall gtthread_cancel(__int64 a1)
{
_DWORD *v1; // rax
_DWORD *v2; // rbp
__int64 v3; // rax
__int64 v4; // rbx
__int64 v5; // r12
_QWORD *v6; // rax
__int64 result; // rax

sigprocmask(0, &threadprocmask, 0LL);
v1 = malloc(4uLL);
*v1 = 15;
v2 = v1;
v3 = queue_search(&readyqueue, a1);
if ( v3 )
{
*(_DWORD *)(v3 + 20) = 1;
v4 = v3;
v5 = v3 + 32;
v6 = (_QWORD *)queue_remove(&readyqueue, a1);
queue_insert_normal(&deletequeue, *v6);
if ( size_of_q(v5) > 0 )
queue_unblock_all(v5, v2);
*(_QWORD *)(v4 + 24) = v2;
sigprocmask(1, &threadprocmask, 0LL);
result = 1LL;
}
else
{
sigprocmask(1, &threadprocmask, 0LL);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
_DWORD *v1; // rax
_DWORD *v2; // rbp
__int64 v3; // rax
__int64 v4; // rbx
__int64 v5; // r12
_QWORD *v6; // rax
__int64 result; // rax

sigprocmask(0, &threadprocmask, 0LL);
v1 = malloc(4uLL);
*v1 = 15;
v2 = v1;
v3 = queue_search(&readyqueue, a1);
if ( v3 )
{
*(_DWORD *)(v3 + 20) = 1;
v4 = v3;
v5 = v3 + 32;
v6 = (_QWORD *)queue_remove(&readyqueue, a1);
queue_insert_normal(&deletequeue, *v6);
if ( size_of_q(v5) > 0 )
queue_unblock_all(v5, v2);
*(_QWORD *)(v4 + 24) = v2;
sigprocmask(1, &threadprocmask, 0LL);
result = 1LL;
}
else
{
sigprocmask(1, &threadprocmask, 0LL);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int gtthread_cancel(gtthread_t thread)
{
 sigprocmask(0, &threadprocmask, ((void *)0));
 int* retval = (void*) malloc(sizeof(int));
 *retval = 15;
 gtthread_tcb* canceltcb = queue_search(&readyqueue, thread);
 if(canceltcb==((void *)0))
 {
  sigprocmask(1, &threadprocmask, ((void *)0));
  return -1;
 }
 canceltcb->iscomplete = 1;
 queue_insert_normal(&deletequeue, (queue_remove(&readyqueue, thread))->thrcb);
 if(0)printf("Succesfully removed from queue\n");
 if(size_of_q(&(canceltcb->join_queue))>0)
 {
  queue_unblock_all(&(canceltcb->join_queue), (void*)retval);
 }
 canceltcb->ret = (void*) retval;
 sigprocmask(1, &threadprocmask, ((void *)0));
 return 1;
}

canonical_original_code:
int gtthread_cancel(long thread)
{
 sigprocmask(0, &threadprocmask, ((void *)0));
 int *retval = (void*) malloc(sizeof(int));
 *retval = 15;
 struct gtthread_tcb *canceltcb = queue_search(&readyqueue, thread);
 if(canceltcb==((void *)0))
 {
  sigprocmask(1, &threadprocmask, ((void *)0));
  return -1;
 }
 canceltcb->iscomplete = 1;
 queue_insert_normal(&deletequeue, (queue_remove(&readyqueue, thread))->thrcb);
 if(0)printf("Succesfully removed from queue\n");
 if(size_of_q(&(canceltcb->join_queue))>0)
 {
  queue_unblock_all(&(canceltcb->join_queue), (void *)retval);
 }
 canceltcb->ret = (void *) retval;
 sigprocmask(1, &threadprocmask, ((void *)0));
 return 1;
}

variable_types:
retval
int *


decompiled_code:
_BOOL8 __fastcall gtthread_equal(__int64 a1, __int64 a2)
{
return a1 == a2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func10(__int64 a1, __int64 a2)
{
return a1 == a2;
}

original_code:
int gtthread_equal(gtthread_t t1, gtthread_t t2)
{
 return t1==t2;
}

canonical_original_code:
int gtthread_equal(long t1, long t2)
{
 return t1==t2;
}


decompiled_code:
__int64 __fastcall gtthread_mutex_init(__int64 a1)
{
sigprocmask(0, &threadprocmask, 0LL);
*(_DWORD *)a1 = 0;
*(_QWORD *)(a1 + 8) = -1LL;
sigprocmask(1, &threadprocmask, 0LL);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
sigprocmask(0, &threadprocmask, 0LL);
*(_DWORD *)a1 = 0;
*(_QWORD *)(a1 + 8) = -1LL;
sigprocmask(1, &threadprocmask, 0LL);
return 0LL;
}

original_code:
int gtthread_mutex_init(gtthread_mutex_t *mutex)
{
 sigprocmask(0, &threadprocmask, ((void *)0));
 mutex->lock = 0;
 mutex->owner = -1;
 sigprocmask(1, &threadprocmask, ((void *)0));
 return 0;
}

canonical_original_code:
int gtthread_mutex_init(struct gtthread_mutex_t *mutex)
{
 sigprocmask(0, &threadprocmask, ((void *)0));
 mutex->lock = 0;
 mutex->owner = -1;
 sigprocmask(1, &threadprocmask, ((void *)0));
 return 0;
}

variable_types: struct gtthread_mutex_t { int lock; long owner; } *


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

sigprocmask(0, &threadprocmask, 0LL);
v1 = *(_QWORD *)(current_thrcb + 8);
if ( *(_QWORD *)(a1 + 8) == v1 )
{
sigprocmask(1, &threadprocmask, 0LL);
result = 35LL;
}
else
{
if ( *(_DWORD *)a1 )
{
do
{
sigprocmask(1, &threadprocmask, 0LL);
schedule_next(2LL);
}
while ( *(_DWORD *)a1 );
v1 = *(_QWORD *)(current_thrcb + 8);
}
*(_QWORD *)(a1 + 8) = v1;
*(_DWORD *)a1 = 1;
sigprocmask(1, &threadprocmask, 0LL);
result = 0LL;
}
return result;
}

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

sigprocmask(0, &threadprocmask, 0LL);
v1 = *(_QWORD *)(current_thrcb + 8);
if ( *(_QWORD *)(a1 + 8) == v1 )
{
sigprocmask(1, &threadprocmask, 0LL);
result = 35LL;
}
else
{
if ( *(_DWORD *)a1 )
{
do
{
sigprocmask(1, &threadprocmask, 0LL);
func0(2LL);
}
while ( *(_DWORD *)a1 );
v1 = *(_QWORD *)(current_thrcb + 8);
}
*(_QWORD *)(a1 + 8) = v1;
*(_DWORD *)a1 = 1;
sigprocmask(1, &threadprocmask, 0LL);
result = 0LL;
}
return result;
}

original_code:
int gtthread_mutex_lock(gtthread_mutex_t *mutex)
{
 sigprocmask(0, &threadprocmask, ((void *)0));
 if(mutex->owner==current_thrcb->thrid)
 {
  sigprocmask(1, &threadprocmask, ((void *)0));
  return 35;
 }
 while(mutex->lock)
 {
  sigprocmask(1, &threadprocmask, ((void *)0));
  if(0)printf("Waiting for lock####################################################\n");
  schedule_next(2);
 }
 mutex->lock = 1;
 if(0)printf("Acquired finally\n");
 mutex->owner = current_thrcb->thrid;
 sigprocmask(1, &threadprocmask, ((void *)0));
 return 0;
}

canonical_original_code:
int gtthread_mutex_lock(struct gtthread_mutex_t *mutex)
{
 sigprocmask(0, &threadprocmask, ((void *)0));
 if(mutex->owner==current_thrcb->thrid)
 {
  sigprocmask(1, &threadprocmask, ((void *)0));
  return 35;
 }
 while(mutex->lock)
 {
  sigprocmask(1, &threadprocmask, ((void *)0));
  if(0)printf("Waiting for lock####################################################\n");
  schedule_next(2);
 }
 mutex->lock = 1;
 if(0)printf("Acquired finally\n");
 mutex->owner = current_thrcb->thrid;
 sigprocmask(1, &threadprocmask, ((void *)0));
 return 0;
}

user_defined_types: struct gtthread_mutex_t { int lock; long owner; }


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

sigprocmask(0, &threadprocmask, 0LL);
if ( *(_QWORD *)(current_thrcb + 8) == *(_QWORD *)(a1 + 8) && *(_DWORD *)a1 )
{
*(_DWORD *)a1 = 0;
*(_QWORD *)(a1 + 8) = -1LL;
sigprocmask(1, &threadprocmask, 0LL);
result = 0LL;
}
else
{
sigprocmask(1, &threadprocmask, 0LL);
result = 1LL;
}
return result;
}

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

sigprocmask(0, &threadprocmask, 0LL);
if ( *(_QWORD *)(current_thrcb + 8) == *(_QWORD *)(a1 + 8) && *(_DWORD *)a1 )
{
*(_DWORD *)a1 = 0;
*(_QWORD *)(a1 + 8) = -1LL;
sigprocmask(1, &threadprocmask, 0LL);
result = 0LL;
}
else
{
sigprocmask(1, &threadprocmask, 0LL);
result = 1LL;
}
return result;
}

original_code:
int gtthread_mutex_unlock(gtthread_mutex_t *mutex)
{
 sigprocmask(0, &threadprocmask, ((void *)0));
 if(current_thrcb->thrid!=mutex->owner)
 {
  sigprocmask(1, &threadprocmask, ((void *)0));
  return 1;
 }
 else if(!mutex->lock)
 {
  sigprocmask(1, &threadprocmask, ((void *)0));
  return 1;
 }
 else
 {
  mutex->lock = 0;
  mutex->owner = -1;
 }
 sigprocmask(1, &threadprocmask, ((void *)0));
 return 0;
}

canonical_original_code:
int gtthread_mutex_unlock(struct gtthread_mutex_t *mutex)
{
 sigprocmask(0, &threadprocmask, ((void *)0));
 if(current_thrcb->thrid!=mutex->owner)
 {
  sigprocmask(1, &threadprocmask, ((void *)0));
  return 1;
 }
 else if(!mutex->lock)
 {
  sigprocmask(1, &threadprocmask, ((void *)0));
  return 1;
 }
 else
 {
  mutex->lock = 0;
  mutex->owner = -1;
 }
 sigprocmask(1, &threadprocmask, ((void *)0));
 return 0;
}


original_code:
int queue_insert(queue_t* q, gtthread_tcb* qthrcb)
{
 queue_node* qnode = (queue_node*) malloc(sizeof(queue_node));
 qnode->thrcb = qthrcb;
 if(q->nelements==0)
 {
  q->front = q->back = qnode;
  qnode->prev = ((void *)0);
 }
 else
 {
  q->back->next=qnode;
  qnode->prev = q->back;
  q->back = qnode;
 }
 qnode->next = q->front;
 q->front->prev = q->back;
 q->nelements++;
 return 1;
}

canonical_original_code:
int queue_insert(struct queue *q, struct gtthread_tcb *qthrcb)
{
 struct queue_node *qnode = (queue_node*) malloc(sizeof(queue_node));
 qnode->thrcb = qthrcb;
 if(q->nelements==0)
 {
  q->front = q->back = qnode;
  qnode->prev = ((void *)0);
 }
 else
 {
  q->back->next=qnode;
  qnode->prev = q->back;
  q->back = qnode;
 }
 qnode->next = q->front;
 q->front->prev = q->back;
 q->nelements++;
 return 1;
}

variable_types: struct queue { struct queue_node { struct gtthread_tcb { struct ucontext_t { unsigned long uc_flags; struct ucontext_t *uc_link; struct stack_t { void *ss_sp; int ss_flags; unsigned long ss_size; } uc_stack; struct mcontext_t { long long gregs[23]; struct _libc_fpstate { unsigned short cwd; unsigned short swd; unsigned short ftw; unsigned short fop; unsigned long rip; unsigned long rdp; unsigned int mxcsr; unsigned int mxcr_mask; struct _libc_fpxreg { unsigned short significand[4]; unsigned short exponent; unsigned short __glibc_reserved1[3]; } _st[8]; struct _libc_xmmreg { unsigned int element[4]; } _xmm[16]; unsigned int __glibc_reserved1[24]; } *fpregs; unsigned long long __reserved1[8]; } uc_mcontext; struct __sigset_t { unsigned long __val[-1]; } uc_sigmask; struct _libc_fpstate __fpregs_mem; unsigned long long __ssp[4]; } *ctxt; long thrid; int isblocked; int iscomplete; void *ret; struct queue join_queue; void *joinval; } *thrcb; struct queue_node *next; struct queue_node *prev; } *front; struct queue_node *back; long nelements; struct queue_node *current; } *

variable_types:
qthrcb
struct gtthread_tcb *

variable_types: struct queue_node { struct gtthread_tcb { struct ucontext_t { unsigned long uc_flags; struct ucontext_t *uc_link; struct stack_t { void *ss_sp; int ss_flags; unsigned long ss_size; } uc_stack; struct mcontext_t { long long gregs[23]; struct _libc_fpstate { unsigned short cwd; unsigned short swd; unsigned short ftw; unsigned short fop; unsigned long rip; unsigned long rdp; unsigned int mxcsr; unsigned int mxcr_mask; struct _libc_fpxreg { unsigned short significand[4]; unsigned short exponent; unsigned short __glibc_reserved1[3]; } _st[8]; struct _libc_xmmreg { unsigned int element[4]; } _xmm[16]; unsigned int __glibc_reserved1[24]; } *fpregs; unsigned long long __reserved1[8]; } uc_mcontext; struct __sigset_t { unsigned long __val[-1]; } uc_sigmask; struct _libc_fpstate __fpregs_mem; unsigned long long __ssp[4]; } *ctxt; long thrid; int isblocked; int iscomplete; void *ret; struct queue { struct queue_node *front; struct queue_node *back; long nelements; struct queue_node *current; } join_queue; void *joinval; } *thrcb; struct queue_node *next; struct queue_node *prev; } *


original_code:
gtthread_tcb* queue_next(queue_t* q)
{
 q->current = q->current->next;
 return q->current->thrcb;
}

canonical_original_code:
struct gtthread_tcb *queue_next(struct queue *q)
{
 q->current = q->current->next;
 return q->current->thrcb;
}

variable_types:
q
struct queue *

return_type: struct gtthread_tcb { struct ucontext_t { unsigned long uc_flags; struct ucontext_t *uc_link; struct stack_t { void *ss_sp; int ss_flags; unsigned long ss_size; } uc_stack; struct mcontext_t { long long gregs[23]; struct _libc_fpstate { unsigned short cwd; unsigned short swd; unsigned short ftw; unsigned short fop; unsigned long rip; unsigned long rdp; unsigned int mxcsr; unsigned int mxcr_mask; struct _libc_fpxreg { unsigned short significand[4]; unsigned short exponent; unsigned short __glibc_reserved1[3]; } _st[8]; struct _libc_xmmreg { unsigned int element[4]; } _xmm[16]; unsigned int __glibc_reserved1[24]; } *fpregs; unsigned long long __reserved1[8]; } uc_mcontext; struct __sigset_t { unsigned long __val[-1]; } uc_sigmask; struct _libc_fpstate __fpregs_mem; unsigned long long __ssp[4]; } *ctxt; long thrid; int isblocked; int iscomplete; void *ret; struct queue { struct queue_node { struct gtthread_tcb *thrcb; struct queue_node *next; struct queue_node *prev; } *front; struct queue_node *back; long nelements; struct queue_node *current; } join_queue; void *joinval; } *


decompiled_code:
__int64 __fastcall size_of_q(__int64 a1)
{
return *(_QWORD *)(a1 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return *(_QWORD *)(a1 + 16);
}

original_code:
long size_of_q(queue_t* q)
{
 return q->nelements;
}

canonical_original_code:
long size_of_q(struct queue *q)
{
 return q->nelements;
}


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

result = *(_QWORD *)(a1 + 8);
*(_QWORD *)(a1 + 24) = result;
return result;
}

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

result = *(_QWORD *)(a1 + 8);
*(_QWORD *)(a1 + 24) = result;
return result;
}

original_code:
void queue_set_current(queue_t* q)
{
 q->current= q->back;
}

canonical_original_code:
void queue_set_current(struct queue *q)
{
 q->current= q->back;
}


original_code:
gtthread_tcb* queue_get(queue_t* q)
{
 if(q->nelements == 0)
 {
  if(0)
   printf("Attempted to remove node from empty queue");
  return ((void *)0);
 }
 queue_node* tmpnode;
 tmpnode = q->front;
 q->front = q->front->next;
 q->nelements--;
 return tmpnode->thrcb;
}

canonical_original_code:
struct gtthread_tcb *queue_get(struct queue *q)
{
 if(q->nelements == 0)
 {
  if(0)
   printf("Attempted to remove node from empty queue");
  return ((void *)0);
 }
 struct queue_node *tmpnode;
 tmpnode = q->front;
 q->front = q->front->next;
 q->nelements--;
 return tmpnode->thrcb;
}


decompiled_code:
__int64 __fastcall queue_search(__int64 a1, __int64 a2)
{
__int64 v3; // rdi
_QWORD *v4; // rdx
__int64 v5; // rax

v3 = *(_QWORD *)(a1 + 16);
if ( !v3 )
return 0LL;
v4 = *(_QWORD **)a1;
if ( v3 <= 0 )
return 0LL;
v5 = 0LL;
while ( *(_QWORD *)(*v4 + 8LL) != a2 )
{
v4 = (_QWORD *)v4[1];
if ( v3 < v5 + 2 )
return 0LL;
++v5;
}
return *v4;
}

original_code:
gtthread_tcb* queue_search(queue_t* q, gtthread_t thread)
{
 if(q->nelements==0)
 {
  return ((void *)0);
 }
 queue_node* current_node;
 current_node = q->front;
 int count = 1;
 while(count<=q->nelements)
 {
  if(current_node->thrcb->thrid==thread)
   return current_node->thrcb;
  current_node = current_node->next;
  count++;
 }
 return ((void *)0);
}

canonical_original_code:
struct gtthread_tcb *queue_search(struct queue *q, long thread)
{
 if(q->nelements==0)
 {
  return ((void *)0);
 }
 struct queue_node *current_node;
 current_node = q->front;
 int count = 1;
 while(count<=q->nelements)
 {
  if(current_node->thrcb->thrid==thread)
   return current_node->thrcb;
  current_node = current_node->next;
  count++;
 }
 return ((void *)0);
}

variable_types: count int


original_code:
int queue_insert_normal(queue_t* q, gtthread_tcb* qthrcb)
{
 queue_node* qnode = (queue_node*) malloc(sizeof(queue_node));
 qnode->thrcb = qthrcb;
 if(q->nelements==0)
 {
  q->front = q->back = qnode;
  qnode->prev = ((void *)0);
 }
 else
 {
  q->back->next=qnode;
  qnode->prev = q->back;
  q->back = qnode;
 }
 qnode->next = ((void *)0);
 q->nelements++;
 return 1;
}

canonical_original_code:
int queue_insert_normal(struct queue *q, struct gtthread_tcb *qthrcb)
{
 struct queue_node *qnode = (queue_node*) malloc(sizeof(queue_node));
 qnode->thrcb = qthrcb;
 if(q->nelements==0)
 {
  q->front = q->back = qnode;
  qnode->prev = ((void *)0);
 }
 else
 {
  q->back->next=qnode;
  qnode->prev = q->back;
  q->back = qnode;
 }
 qnode->next = ((void *)0);
 q->nelements++;
 return 1;
}


original_code:
static void nrsynth_update_volume(nrsynth_t *n){
  n->volume_total_l = n->expression * n->volume * (1.0 - n->panpot) * 0.50;
  n->volume_total_r = n->expression * n->volume * ( n->panpot) * 0.50;
}

canonical_original_code:
static void nrsynth_update_volume(struct nrsynth_t *n){
  n->volume_total_l = n->expression * n->volume * (1.0 - n->panpot) * 0.50;
  n->volume_total_r = n->expression * n->volume * ( n->panpot) * 0.50;
}

variable_types: struct nrsynth_t { struct nrsynth_inst_t { int status; unsigned int elapsed; float velocity; unsigned int attack_time; unsigned int sustain_time; unsigned int release_time; int pitchmode; float rnd; int key; } inst[4]; int keymap[128]; float expression; float panpot; float volume; float volume_total_l; float volume_total_r; } *

user_defined_types: struct nrsynth_t { struct nrsynth_inst_t inst[4]; int keymap[128]; float expression; float panpot; float volume; float volume_total_l; float volume_total_r; }


decompiled_code:
float __fastcall nrsynth_inst_adsr(_DWORD *a1)
{
unsigned int v1; // edx
int v2; // eax
unsigned int v3; // eax
float result; // xmm0_4
int v5; // ecx

v1 = a1[1];
v2 = a1[3];
if ( v1 < v2 )
return (float)(int)v1 / (float)v2;
v3 = a1[4] + v2;
result = *(float *)&LC4;
if ( v1 >= v3 )
{
v5 = a1[5];
if ( v1 >= v3 + v5 )
{
*a1 = 0;
result = 0.0;
}
else
{
result = (float)(int)(v5 + v3 - v1) / (float)v5;
}
}
return result;
}

canonical_decompiled_code:
float __fastcall func1(_DWORD *a1)
{
unsigned int v1; // edx
int v2; // eax
unsigned int v3; // eax
float result; // xmm0_4
int v5; // ecx

v1 = a1[1];
v2 = a1[3];
if ( v1 < v2 )
return (float)(int)v1 / (float)v2;
v3 = a1[4] + v2;
result = *(float *)&LC4;
if ( v1 >= v3 )
{
v5 = a1[5];
if ( v1 >= v3 + v5 )
{
*a1 = 0;
result = 0.0;
}
else
{
result = (float)(int)(v5 + v3 - v1) / (float)v5;
}
}
return result;
}

original_code:
static float nrsynth_inst_adsr(nrsynth_inst_t *ni){
  if(ni->elapsed < ni->attack_time){
    return (float)ni->elapsed / (float)ni->attack_time;
  }else if(ni->elapsed < ni->attack_time + ni->sustain_time){
    return 1.0;
  }else if(ni->elapsed < ni->attack_time + ni->sustain_time + ni->release_time){
    return (float)(ni->release_time - (ni->elapsed - (ni->attack_time + ni->sustain_time))) / (float)ni->release_time;
  }else{
    ni->status = NRSYNTH_INST_UNUSED;
    return 0.0;
  }
}

canonical_original_code:
static float nrsynth_inst_adsr(struct nrsynth_inst_t *ni){
  if(ni->elapsed < ni->attack_time){
    return (float)ni->elapsed / (float)ni->attack_time;
  }else if(ni->elapsed < ni->attack_time + ni->sustain_time){
    return 1.0;
  }else if(ni->elapsed < ni->attack_time + ni->sustain_time + ni->release_time){
    return (float)(ni->release_time - (ni->elapsed - (ni->attack_time + ni->sustain_time))) / (float)ni->release_time;
  }else{
    ni->status = NRSYNTH_INST_UNUSED;
    return 0.0;
  }
}

variable_types: struct nrsynth_inst_t { int status; unsigned int elapsed; float velocity; unsigned int attack_time; unsigned int sustain_time; unsigned int release_time; int pitchmode; float rnd; int key; } *

return_type: float


decompiled_code:
float __fastcall nrsynth_inst_getwave(__int64 a1)
{
float v1; // xmm2_4

v1 = *(float *)(a1 + 28);
return (float)(nrsynth_inst_adsr((_DWORD *)a1) * v1) * *(float *)(a1 + 8);
}

canonical_decompiled_code:
float __fastcall func2(__int64 a1)
{
float v1; // xmm2_4

v1 = *(float *)(a1 + 28);
return (float)(func1((_DWORD *)a1) * v1) * *(float *)(a1 + 8);
}

original_code:
static float nrsynth_inst_getwave(nrsynth_inst_t *ni){
  return
    ni->rnd *
    nrsynth_inst_adsr(ni) *
    ni->velocity;
}

canonical_original_code:
static float nrsynth_inst_getwave(struct nrsynth_inst_t *ni){
  return
    ni->rnd *
    nrsynth_inst_adsr(ni) *
    ni->velocity;
}

user_defined_types: struct nrsynth_inst_t { int status; unsigned int elapsed; float velocity; unsigned int attack_time; unsigned int sustain_time; unsigned int release_time; int pitchmode; float rnd; int key; }


decompiled_code:
__int64 __fastcall nrsynth_inst_next(__int64 a1)
{
int v1; // edx
__int64 result; // rax
float v3; // xmm0_4
unsigned __int64 v4; // rdx

v1 = *(_DWORD *)(a1 + 24);
result = (unsigned int)(*(_DWORD *)(a1 + 4) + 1);
*(_DWORD *)(a1 + 4) = result;
if ( v1 == 1 )
{
if ( (result & 1) != 0 )
return result;
}
else if ( v1 == 2 )
{
if ( (result & 7) != 0 )
return result;
}
else if ( v1 )
{
return result;
}
result = xor128();
if ( result < 0 )
{
v4 = result;
result &= 1u;
v3 = (float)(int)(result | (v4 >> 1)) + (float)(int)(result | (v4 >> 1));
}
else
{
v3 = (float)(int)result;
}
*(float *)(a1 + 28) = (float)(v3 * 4.6566129e-10) - 1.0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
int v1; // edx
__int64 result; // rax
float v3; // xmm0_4
unsigned __int64 v4; // rdx

v1 = *(_DWORD *)(a1 + 24);
result = (unsigned int)(*(_DWORD *)(a1 + 4) + 1);
*(_DWORD *)(a1 + 4) = result;
if ( v1 == 1 )
{
if ( (result & 1) != 0 )
return result;
}
else if ( v1 == 2 )
{
if ( (result & 7) != 0 )
return result;
}
else if ( v1 )
{
return result;
}
result = xor128();
if ( result < 0 )
{
v4 = result;
result &= 1u;
v3 = (float)(int)(result | (v4 >> 1)) + (float)(int)(result | (v4 >> 1));
}
else
{
v3 = (float)(int)result;
}
*(float *)(a1 + 28) = (float)(v3 * 4.6566129e-10) - 1.0;
return result;
}

original_code:
static void nrsynth_inst_next(nrsynth_inst_t *ni){
  ni->elapsed ++;
  switch(ni->pitchmode){
  case 0:
    ni->rnd = (float)xor128()/(float)0x80000000 - 1.0;
    break;
  case 1:
    if((ni->elapsed & 0x1) == 0)
      ni->rnd = (float)xor128()/(float)0x80000000 - 1.0;
    break;
  case 2:
    if((ni->elapsed & 0x7) == 0)
      ni->rnd = (float)xor128()/(float)0x80000000 - 1.0;
    break;
  }
}

canonical_original_code:
static void nrsynth_inst_next(struct nrsynth_inst_t *ni){
  ni->elapsed ++;
  switch(ni->pitchmode){
  case 0:
    ni->rnd = (float)xor128()/(float)0x80000000 - 1.0;
    break;
  case 1:
    if((ni->elapsed & 0x1) == 0)
      ni->rnd = (float)xor128()/(float)0x80000000 - 1.0;
    break;
  case 2:
    if((ni->elapsed & 0x7) == 0)
      ni->rnd = (float)xor128()/(float)0x80000000 - 1.0;
    break;
  }
}


original_code:
void nrsynth_init(nrsynth_t *n){
  memcpy(n->inst, nrsynth_presets, sizeof(nrsynth_inst_t) * 4);
  memcpy(n->keymap, nrsynth_keymap_default, sizeof(int)*128);
  n->expression = 1.0;
  n->panpot = 0.5;
  n->volume = 1.0;
  nrsynth_update_volume(n);
}

canonical_original_code:
void nrsynth_init(struct nrsynth_t *n){
  memcpy(n->inst, nrsynth_presets, sizeof(nrsynth_inst_t) * 4);
  memcpy(n->keymap, nrsynth_keymap_default, sizeof(int)*128);
  n->expression = 1.0;
  n->panpot = 0.5;
  n->volume = 1.0;
  nrsynth_update_volume(n);
}


decompiled_code:
__int64 nrsynth_create()
{
void *v0; // rax
__int64 v1; // r9

v0 = calloc(0x2A4uLL, 1uLL);
nrsynth_init((__int64)v0);
return v1;
}

canonical_decompiled_code:
__int64 func5()
{
void *v0; // rax
__int64 v1; // r9

v0 = calloc(0x2A4uLL, 1uLL);
func4((__int64)v0);
return v1;
}

original_code:
nrsynth_t *nrsynth_create(){
  nrsynth_t *n;
  n = (nrsynth_t *)malloc(sizeof(nrsynth_t));
  memset(n, 0, sizeof(nrsynth_t));
  nrsynth_init(n);
  return n;
}

canonical_original_code:
struct nrsynth_t *nrsynth_create(){
  struct nrsynth_t *n;
  n = (struct nrsynth_t *)malloc(sizeof(nrsynth_t));
  memset(n, 0, sizeof(nrsynth_t));
  nrsynth_init(n);
  return n;
}

return_type: struct nrsynth_t { struct nrsynth_inst_t { int status; unsigned int elapsed; float velocity; unsigned int attack_time; unsigned int sustain_time; unsigned int release_time; int pitchmode; float rnd; int key; } inst[4]; int keymap[128]; float expression; float panpot; float volume; float volume_total_l; float volume_total_r; } *


decompiled_code:
// attributes: thunk
void nrsynth_destroy(void *ptr)
{
free(ptr);
}

canonical_decompiled_code:
void func6(void *ptr)
{
free(ptr);
}

original_code:
void nrsynth_destroy(nrsynth_t *n){
  free(n);
}

canonical_original_code:
void nrsynth_destroy(struct nrsynth_t *n){
  free(n);
}


decompiled_code:
__int64 __fastcall nrsynth_play(__int64 a1, int a2, float a3)
{
__int64 result; // rax

result = *(int *)(a1 + 4LL * a2 + 144);
if ( (_DWORD)result != -1 )
{
result = a1 + 36 * result;
*(_DWORD *)(result + 32) = a2;
*(_QWORD *)result = 1LL;
*(float *)(result + 8) = a3;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, int a2, float a3)
{
__int64 result; // rax

result = *(int *)(a1 + 4LL * a2 + 144);
if ( (_DWORD)result != -1 )
{
result = a1 + 36 * result;
*(_DWORD *)(result + 32) = a2;
*(_QWORD *)result = 1LL;
*(float *)(result + 8) = a3;
}
return result;
}

original_code:
void nrsynth_play(nrsynth_t *n, int key, float velocity){
  int inst_index = n->keymap[key];
    if(inst_index != -1){
    nrsynth_inst_t *ni = &n->inst[inst_index];
    ni->key = key;
    ni->status = NRSYNTH_INST_PLAYING;
    ni->elapsed = 0;
    ni->velocity = velocity;
  }
}

canonical_original_code:
void nrsynth_play(struct nrsynth_t *n, int key, float velocity){
  int inst_index = n->keymap[key];
    if(inst_index != -1){
    struct nrsynth_inst_t *ni = &n->inst[inst_index];
    ni->key = key;
    ni->status = NRSYNTH_INST_PLAYING;
    ni->elapsed = 0;
    ni->velocity = velocity;
  }
}

variable_types: key int

variable_types: velocity float


decompiled_code:
__int64 __fastcall nrsynth_render(unsigned int *a1, __int64 a2, unsigned int a3, int a4)
{
unsigned int *v4; // r14
__int64 result; // rax
int v8; // er15
float v9; // xmm0_4
float v10; // [rsp+8h] [rbp-40h]
float v11; // [rsp+Ch] [rbp-3Ch]

v4 = a1;
v10 = *((float *)a1 + 167);
v11 = *((float *)a1 + 168);
do
{
result = *v4;
if ( (_DWORD)result )
{
result = audiobuf_seek(a2, a3);
if ( a4 > 0 )
{
v8 = 0;
do
{
++v8;
v9 = nrsynth_inst_getwave((__int64)v4);
audiobuf_add(a2, 0LL, v9 * v10);
audiobuf_add(a2, 1LL, v11 * v9);
result = nrsynth_inst_next((__int64)v4);
}
while ( a4 != v8 );
}
}
v4 += 9;
}
while ( a1 + 36 != v4 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int *a1, __int64 a2, unsigned int a3, int a4)
{
unsigned int *v4; // r14
__int64 result; // rax
int v8; // er15
float v9; // xmm0_4
float v10; // [rsp+8h] [rbp-40h]
float v11; // [rsp+Ch] [rbp-3Ch]

v4 = a1;
v10 = *((float *)a1 + 167);
v11 = *((float *)a1 + 168);
do
{
result = *v4;
if ( (_DWORD)result )
{
result = audiobuf_seek(a2, a3);
if ( a4 > 0 )
{
v8 = 0;
do
{
++v8;
v9 = func2((__int64)v4);
audiobuf_add(a2, 0LL, v9 * v10);
audiobuf_add(a2, 1LL, v11 * v9);
result = func3((__int64)v4);
}
while ( a4 != v8 );
}
}
v4 += 9;
}
while ( a1 + 36 != v4 );
return result;
}

original_code:
void nrsynth_render(nrsynth_t *n, audiobuf_t *a, int start, int size){
  int i,j;
  float f;
  nrsynth_inst_t *ni;
  float l,r;
  float vl,vr;
  vl =n->volume_total_l;
  vr =n->volume_total_r;
  for(i = 0; i < 4; i ++){
    ni = &n->inst[i];
    if(ni->status == NRSYNTH_INST_UNUSED) continue;
    audiobuf_seek(a, start);
    for(j = 0; j < size; j ++){
      f = nrsynth_inst_getwave(ni);
      l = f * vl;
      r = f * vr;
      audiobuf_add(a, 0, l);
      audiobuf_add(a, 1, r);
      nrsynth_inst_next(ni);
    }
  }
}

canonical_original_code:
void nrsynth_render(struct nrsynth_t *n, struct audiobuf_t *a, int start, int size){
  int i; int j;
  float f;
  struct nrsynth_inst_t *ni;
  float l; float r;
  float vl; float vr;
  vl =n->volume_total_l;
  vr =n->volume_total_r;
  for(i = 0; i < 4; i ++){
    ni = &n->inst[i];
    if(ni->status == NRSYNTH_INST_UNUSED) continue;
    audiobuf_seek(a, start);
    for(j = 0; j < size; j ++){
      f = nrsynth_inst_getwave(ni);
      l = f * vl;
      r = f * vr;
      audiobuf_add(a, 0, l);
      audiobuf_add(a, 1, r);
      nrsynth_inst_next(ni);
    }
  }
}

variable_types: struct audiobuf_t { int n_channels; int sampling_rate; int qbit; float **data; int *index; int size; } *

variable_types: start int

variable_types: size int

variable_types: i int

variable_types: j int

variable_types: f float

variable_types: l float

variable_types: r float

variable_types: vl float

variable_types: vr float


decompiled_code:
void __fastcall nrsynth_midi(float *a1, _DWORD *a2)
{
int v2; // eax
int v3; // eax
int v4; // eax

v2 = a2[4];
if ( v2 == 144 )
{
v4 = a2[6];
if ( v4 )
nrsynth_play((__int64)a1, a2[5], (float)((float)v4 * (float)v4) / 16129.0);
}
else if ( v2 == 176 )
{
v3 = a2[5];
switch ( v3 )
{
case 10:
a1[165] = (float)(int)a2[6] / 127.0;
nrsynth_update_volume(a1);
break;
case 11:
a1[164] = (float)(int)a2[6] / 127.0;
nrsynth_update_volume(a1);
break;
case 7:
a1[166] = (float)(int)a2[6] / 127.0;
nrsynth_update_volume(a1);
break;
}
}
}

original_code:
void nrsynth_midi(nrsynth_t *n, midievent_t *e){
  switch(e->type){
  case 0x80:
    break;
  case 0x90:
    if(e->shortparam[1] != 0){
      nrsynth_play(n, e->shortparam[0], (float)e->shortparam[1]*(float)e->shortparam[1]/(127.0*127.0));
    }
    break;
  case 0xa0:
    break;
  case 0xb0:
    switch(e->shortparam[0]){
    case 7:
      n->volume = (float)e->shortparam[1]/127.0;
      nrsynth_update_volume(n);
      break;
    case 10:
      n->panpot = (float)e->shortparam[1]/127.0;
      nrsynth_update_volume(n);
      break;
    case 11:
      n->expression = (float)e->shortparam[1]/127.0;
      nrsynth_update_volume(n);
      break;
    default:
      ;
    }
    break;
  case 0xc0:
    break;
  case 0xd0:
    break;
  case 0xe0:
    break;
  default:
    ;
  }
}

canonical_original_code:
void nrsynth_midi(struct nrsynth_t *n, struct midievent_t *e){
  switch(e->type){
  case 0x80:
    break;
  case 0x90:
    if(e->shortparam[1] != 0){
      nrsynth_play(n, e->shortparam[0], (float)e->shortparam[1]*(float)e->shortparam[1]/(127.0*127.0));
    }
    break;
  case 0xa0:
    break;
  case 0xb0:
    switch(e->shortparam[0]){
    case 7:
      n->volume = (float)e->shortparam[1]/127.0;
      nrsynth_update_volume(n);
      break;
    case 10:
      n->panpot = (float)e->shortparam[1]/127.0;
      nrsynth_update_volume(n);
      break;
    case 11:
      n->expression = (float)e->shortparam[1]/127.0;
      nrsynth_update_volume(n);
      break;
    default:
      ;
    }
    break;
  case 0xc0:
    break;
  case 0xd0:
    break;
  case 0xe0:
    break;
  default:
    ;
  }
}

variable_types: struct midievent_t { unsigned int absolute_time; unsigned int ticks; int is_meta; int channel; int type; int shortparam[4]; int longparam_size; char *longparam_char; int longparam_int; } *


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

if ( a2 <= 3 && (v2 = (_DWORD *)(a1 + 36LL * (int)a2), *v2) )
result = (unsigned int)v2[8];
else
result = 0xFFFFFFFFLL;
return result;
}

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

if ( a2 <= 3 && (v2 = (_DWORD *)(a1 + 36LL * (int)a2), *v2) )
result = (unsigned int)v2[8];
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int nrsynth_get_current_key(nrsynth_t *n, int index){
  if(index < 0 || index >= 4){
    return -1;
  }
  nrsynth_inst_t *ni = &n->inst[index];
  if(ni->status == NRSYNTH_INST_UNUSED) return -1;
  return ni->key;
}

canonical_original_code:
int nrsynth_get_current_key(struct nrsynth_t *n, int index){
  if(index < 0 || index >= 4){
    return -1;
  }
  struct nrsynth_inst_t *ni = &n->inst[index];
  if(ni->status == NRSYNTH_INST_UNUSED) return -1;
  return ni->key;
}

variable_types: index int


seventh

decompiled_code:
__int64 __fastcall seventh(__int64 a1, __int64 a2, unsigned int a3, unsigned int a4, unsigned int a5, unsigned int a6, unsigned int a7)
{
wtssynth_keyon(a1, a3, 1.0);
wtssynth_keyon(a1, a4, 1.0);
wtssynth_keyon(a1, a5, 1.0);
wtssynth_keyon(a1, a6, 1.0);
wtssynth_render(a1, a2, (unsigned int)g_current_time, a7);
g_current_time += a7;
wtssynth_keyoff(a1, a3);
wtssynth_keyoff(a1, a4);
wtssynth_keyoff(a1, a5);
return wtssynth_keyoff(a1, a6);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, unsigned int a3, unsigned int a4, unsigned int a5, unsigned int a6, unsigned int a7)
{
wtssynth_keyon(a1, a3, 1.0);
wtssynth_keyon(a1, a4, 1.0);
wtssynth_keyon(a1, a5, 1.0);
wtssynth_keyon(a1, a6, 1.0);
wtssynth_render(a1, a2, (unsigned int)g_current_time, a7);
g_current_time += a7;
wtssynth_keyoff(a1, a3);
wtssynth_keyoff(a1, a4);
wtssynth_keyoff(a1, a5);
return wtssynth_keyoff(a1, a6);
}

original_code:
void seventh(wtssynth_t *w, audiobuf_t *a, int key1, int key2, int key3, int key4, int len){
  wtssynth_keyon(w, key1, 1.0);
  wtssynth_keyon(w, key2, 1.0);
  wtssynth_keyon(w, key3, 1.0);
  wtssynth_keyon(w, key4, 1.0);
  wtssynth_render(w, a, g_current_time, len);
  g_current_time += len;
  wtssynth_keyoff(w, key1);
  wtssynth_keyoff(w, key2);
  wtssynth_keyoff(w, key3);
  wtssynth_keyoff(w, key4);
}

canonical_original_code:
void seventh(struct wtssynth_t *w, struct audiobuf_t *a, int key1, int key2, int key3, int key4, int len){
  wtssynth_keyon(w, key1, 1.0);
  wtssynth_keyon(w, key2, 1.0);
  wtssynth_keyon(w, key3, 1.0);
  wtssynth_keyon(w, key4, 1.0);
  wtssynth_render(w, a, g_current_time, len);
  g_current_time += len;
  wtssynth_keyoff(w, key1);
  wtssynth_keyoff(w, key2);
  wtssynth_keyoff(w, key3);
  wtssynth_keyoff(w, key4);
}

variable_types: struct wtssynth_t { struct wtsconfig_t { int sampling_rate; float panpot; float volume; float expression; float modulation; float pitchbend; float pitchbend_delta; float volume_total_l; float volume_total_r; struct wtstone_t { float wave[32]; float attack_time; float total_level; float decay_time; float sustain_level; float release_time; unsigned int attack_time_int; unsigned int decay_time_int; unsigned int release_time_int; unsigned int attack_decay_time_int; } presets[16]; int tonemap[128]; int current_preset; } *config; struct wtsvoice_t { int status; unsigned int elapsed; unsigned int phase; unsigned int delta; unsigned int keyoff_time; float keyoff_level; float pitchbend; float velocity; int key; float amp; float lpf_inbuf[3]; float lpf_outbuf[3]; } voice[16]; int voiceover; int midi_key; } *

variable_types: len int

user_defined_types: struct wtssynth_t { struct wtsconfig_t *config; struct wtsvoice_t voice[16]; int voiceover; int midi_key; }

user_defined_types: struct audiobuf_t { int n_channels; int sampling_rate; int qbit; float **data; int *index; int size; }

user_defined_types: struct wtsconfig_t { int sampling_rate; float panpot; float volume; float expression; float modulation; float pitchbend; float pitchbend_delta; float volume_total_l; float volume_total_r; struct wtstone_t presets[16]; int tonemap[128]; int current_preset; }


decompiled_code:
__int64 __fastcall seventh_midi(__int64 a1, __int64 a2, unsigned int a3, unsigned int a4, unsigned int a5, unsigned int a6, unsigned int a7)
{
__int64 v10; // rax
__int64 v11; // rbx
__int64 v12; // rax
__int64 v13; // r15
__int64 v14; // r14
__int64 v15; // r13
__int64 v16; // r12
__int64 v18; // [rsp+0h] [rbp-78h]
__int64 v19; // [rsp+0h] [rbp-78h]
__int64 v20; // [rsp+0h] [rbp-78h]
__int64 v21; // [rsp+0h] [rbp-78h]
__int64 v22; // [rsp+0h] [rbp-78h]
__int64 v23; // [rsp+0h] [rbp-78h]
__int64 v24; // [rsp+0h] [rbp-78h]
__int64 v25; // [rsp+18h] [rbp-60h]
__int64 v26; // [rsp+20h] [rbp-58h]
__int64 v28; // [rsp+30h] [rbp-48h]

v10 = midievent_create_short(0LL, 0LL, 144LL, a3, 100LL, 0LL, 0LL);
LODWORD(v18) = 0;
v25 = v10;
v11 = midievent_create_short(0LL, 0LL, 144LL, a4, 100LL, 0LL, v18);
LODWORD(v19) = 0;
v12 = midievent_create_short(0LL, 0LL, 144LL, a5, 100LL, 0LL, v19);
LODWORD(v20) = 0;
v26 = v12;
v13 = midievent_create_short(0LL, 0LL, 144LL, a6, 100LL, 0LL, v20);
LODWORD(v21) = 0;
v14 = midievent_create_short(0LL, 0LL, 128LL, a3, 0LL, 0LL, v21);
LODWORD(v22) = 0;
v15 = midievent_create_short(0LL, 0LL, 128LL, a4, 0LL, 0LL, v22);
LODWORD(v23) = 0;
v16 = midievent_create_short(0LL, 0LL, 128LL, a5, 0LL, 0LL, v23);
LODWORD(v24) = 0;
v28 = midievent_create_short(0LL, 0LL, 128LL, a6, 0LL, 0LL, v24);
wtssynth_midi(a1, v25);
wtssynth_midi(a1, v11);
wtssynth_midi(a1, v26);
wtssynth_midi(a1, v13);
wtssynth_render(a1, a2, (unsigned int)g_current_time, a7);
g_current_time += a7;
wtssynth_midi(a1, v14);
wtssynth_midi(a1, v15);
wtssynth_midi(a1, v16);
wtssynth_midi(a1, v28);
midievent_destroy(v25);
midievent_destroy(v11);
midievent_destroy(v26);
midievent_destroy(v13);
midievent_destroy(v14);
midievent_destroy(v15);
midievent_destroy(v16);
return midievent_destroy(v28);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, unsigned int a3, unsigned int a4, unsigned int a5, unsigned int a6, unsigned int a7)
{
__int64 v10; // rax
__int64 v11; // rbx
__int64 v12; // rax
__int64 v13; // r15
__int64 v14; // r14
__int64 v15; // r13
__int64 v16; // r12
__int64 v18; // [rsp+0h] [rbp-78h]
__int64 v19; // [rsp+0h] [rbp-78h]
__int64 v20; // [rsp+0h] [rbp-78h]
__int64 v21; // [rsp+0h] [rbp-78h]
__int64 v22; // [rsp+0h] [rbp-78h]
__int64 v23; // [rsp+0h] [rbp-78h]
__int64 v24; // [rsp+0h] [rbp-78h]
__int64 v25; // [rsp+18h] [rbp-60h]
__int64 v26; // [rsp+20h] [rbp-58h]
__int64 v28; // [rsp+30h] [rbp-48h]

v10 = midievent_create_short(0LL, 0LL, 144LL, a3, 100LL, 0LL, 0LL);
LODWORD(v18) = 0;
v25 = v10;
v11 = midievent_create_short(0LL, 0LL, 144LL, a4, 100LL, 0LL, v18);
LODWORD(v19) = 0;
v12 = midievent_create_short(0LL, 0LL, 144LL, a5, 100LL, 0LL, v19);
LODWORD(v20) = 0;
v26 = v12;
v13 = midievent_create_short(0LL, 0LL, 144LL, a6, 100LL, 0LL, v20);
LODWORD(v21) = 0;
v14 = midievent_create_short(0LL, 0LL, 128LL, a3, 0LL, 0LL, v21);
LODWORD(v22) = 0;
v15 = midievent_create_short(0LL, 0LL, 128LL, a4, 0LL, 0LL, v22);
LODWORD(v23) = 0;
v16 = midievent_create_short(0LL, 0LL, 128LL, a5, 0LL, 0LL, v23);
LODWORD(v24) = 0;
v28 = midievent_create_short(0LL, 0LL, 128LL, a6, 0LL, 0LL, v24);
wtssynth_midi(a1, v25);
wtssynth_midi(a1, v11);
wtssynth_midi(a1, v26);
wtssynth_midi(a1, v13);
wtssynth_render(a1, a2, (unsigned int)g_current_time, a7);
g_current_time += a7;
wtssynth_midi(a1, v14);
wtssynth_midi(a1, v15);
wtssynth_midi(a1, v16);
wtssynth_midi(a1, v28);
midievent_destroy(v25);
midievent_destroy(v11);
midievent_destroy(v26);
midievent_destroy(v13);
midievent_destroy(v14);
midievent_destroy(v15);
midievent_destroy(v16);
return midievent_destroy(v28);
}

original_code:
void seventh_midi(wtssynth_t *w, audiobuf_t *a, int key1, int key2, int key3, int key4, int len){
  midievent_t *e1, *e2, *e3, *e4, *e5, *e6, *e7, *e8;
  e1 = midievent_create_short(0, 0, 0x90, key1, 100, 0, 0);
  e2 = midievent_create_short(0, 0, 0x90, key2, 100, 0, 0);
  e3 = midievent_create_short(0, 0, 0x90, key3, 100, 0, 0);
  e4 = midievent_create_short(0, 0, 0x90, key4, 100, 0, 0);
  e5 = midievent_create_short(0, 0, 0x80, key1, 0, 0, 0);
  e6 = midievent_create_short(0, 0, 0x80, key2, 0, 0, 0);
  e7 = midievent_create_short(0, 0, 0x80, key3, 0, 0, 0);
  e8 = midievent_create_short(0, 0, 0x80, key4, 0, 0, 0);
  wtssynth_midi(w, e1);
  wtssynth_midi(w, e2);
  wtssynth_midi(w, e3);
  wtssynth_midi(w, e4);
  wtssynth_render(w, a, g_current_time, len);
  g_current_time += len;
  wtssynth_midi(w, e5);
  wtssynth_midi(w, e6);
  wtssynth_midi(w, e7);
  wtssynth_midi(w, e8);
  midievent_destroy(e1);
  midievent_destroy(e2);
  midievent_destroy(e3);
  midievent_destroy(e4);
  midievent_destroy(e5);
  midievent_destroy(e6);
  midievent_destroy(e7);
  midievent_destroy(e8);
}

canonical_original_code:
void seventh_midi(struct wtssynth_t *w, struct audiobuf_t *a, int key1, int key2, int key3, int key4, int len){
  struct midievent_t *e1; struct midievent_t *e2; struct midievent_t *e3; struct midievent_t *e4; struct midievent_t *e5; struct midievent_t *e6; struct midievent_t *e7; struct midievent_t *e8;
  e1 = midievent_create_short(0, 0, 0x90, key1, 100, 0, 0);
  e2 = midievent_create_short(0, 0, 0x90, key2, 100, 0, 0);
  e3 = midievent_create_short(0, 0, 0x90, key3, 100, 0, 0);
  e4 = midievent_create_short(0, 0, 0x90, key4, 100, 0, 0);
  e5 = midievent_create_short(0, 0, 0x80, key1, 0, 0, 0);
  e6 = midievent_create_short(0, 0, 0x80, key2, 0, 0, 0);
  e7 = midievent_create_short(0, 0, 0x80, key3, 0, 0, 0);
  e8 = midievent_create_short(0, 0, 0x80, key4, 0, 0, 0);
  wtssynth_midi(w, e1);
  wtssynth_midi(w, e2);
  wtssynth_midi(w, e3);
  wtssynth_midi(w, e4);
  wtssynth_render(w, a, g_current_time, len);
  g_current_time += len;
  wtssynth_midi(w, e5);
  wtssynth_midi(w, e6);
  wtssynth_midi(w, e7);
  wtssynth_midi(w, e8);
  midievent_destroy(e1);
  midievent_destroy(e2);
  midievent_destroy(e3);
  midievent_destroy(e4);
  midievent_destroy(e5);
  midievent_destroy(e6);
  midievent_destroy(e7);
  midievent_destroy(e8);
}

user_defined_types: struct midievent_t { unsigned int absolute_time; unsigned int ticks; int is_meta; int channel; int type; int shortparam[4]; int longparam_size; char *longparam_char; int longparam_int; }

user_defined_types: struct wtsvoice_t { int status; unsigned int elapsed; unsigned int phase; unsigned int delta; unsigned int keyoff_time; float keyoff_level; float pitchbend; float velocity; int key; float amp; float lpf_inbuf[3]; float lpf_outbuf[3]; }

user_defined_types: struct wtstone_t { float wave[32]; float attack_time; float total_level; float decay_time; float sustain_level; float release_time; unsigned int attack_time_int; unsigned int decay_time_int; unsigned int release_time_int; unsigned int attack_decay_time_int; }