addatPosition

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

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

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

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

repo: sachin-rajput/basic-ds-algo

decompiled_code:
void __fastcall popatPosition(void ***a1, unsigned int a2)
{
int v2; // eax
void **v3; // rbx
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_9:
*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 )
{
++v4;
v5 = v3;
v3 = (void **)*v3;
if ( !v3 )
break;
if ( a2 == v4 )
goto LABEL_9;
}
}
}
}

canonical_decompiled_code:
void __fastcall func20(void ***a1, unsigned int a2)
{
int v2; // eax
void **v3; // rbx
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_9:
*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 )
{
++v4;
v5 = v3;
v3 = (void **)*v3;
if ( !v3 )
break;
if ( a2 == v4 )
goto LABEL_9;
}
}
}
}

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

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

variable_types: i int

return_type: void

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

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


createlinklist

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:
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; // edx
_QWORD *v2; // rax

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

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

v1 = func10(a1);
if ( v1 )
{
v2 = (_QWORD *)*a1;
if ( *a1 )
{
v1 = 0;
do
{
++v1;
v2 = (_QWORD *)*v2;
}
while ( v2 );
}
else
{
v1 = 0;
}
}
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

return_type: int


searchRemove

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; // rbx

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

canonical_decompiled_code:
_QWORD *func19()
{
_QWORD *v0; // rbx

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(__int64 *a1, __int64 a2)
{
return addBack(*a1, a2);
}

canonical_decompiled_code:
int __fastcall func20(__int64 *a1, __int64 a2)
{
return func9(*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 func21(__int64 ****a1)
{
return func11(*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 func22(_QWORD **a1)
{
return func12(*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 func23(void *ptr)
{
func16(*(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
_QWORD *v2; // rax

sigprocmask(0, &threadprocmask, 0LL);
if ( size_of_q(&readyqueue) > 1 )
{
if ( *(_DWORD *)(current_thrcb + 20) )
{
v2 = (_QWORD *)queue_remove(&readyqueue, *(_QWORD *)(current_thrcb + 8));
queue_insert_normal(&deletequeue, *v2);
}
v0 = (ucontext_t **)current_thrcb;
for ( current_thrcb = queue_next(&readyqueue); *(_DWORD *)(current_thrcb + 16); current_thrcb = queue_next(&readyqueue) )
;
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
_QWORD *v2; // rax

sigprocmask(0, &threadprocmask, 0LL);
if ( size_of_q(&readyqueue) > 1 )
{
if ( *(_DWORD *)(current_thrcb + 20) )
{
v2 = (_QWORD *)queue_remove(&readyqueue, *(_QWORD *)(current_thrcb + 8));
queue_insert_normal(&deletequeue, *v2);
}
v0 = (ucontext_t **)current_thrcb;
for ( current_thrcb = queue_next(&readyqueue); *(_DWORD *)(current_thrcb + 16); current_thrcb = queue_next(&readyqueue) )
;
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);
memset((void *)(unsigned int)((_DWORD)&new_action + 8), 0, 0x90uLL);
new_action.__val[0] = (unsigned __int64)schedule_next;
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);
memset((void *)(unsigned int)((_DWORD)&new_action + 8), 0, 0x90uLL);
new_action.__val[0] = (unsigned __int64)schedule_next;
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_interval.tv_sec = 0LL;
interval.it_interval.tv_usec = 0LL;
interval.it_value.tv_sec = 0LL;
interval.it_value.tv_usec = a1;
timeslice = a1;
current_thr_id = 0LL;
active_threads = 0;
setmain = 0;
queue_init(&readyqueue);
queue_init(&deletequeue);
v1 = malloc(0x48uLL);
main_thrcb = (__int64)v1;
v1[1] = 0LL;
*((_DWORD *)v1 + 4) = 0;
*((_DWORD *)v1 + 5) = 0;
*v1 = &main_ctxt;
queue_init(v1 + 4);
*(_QWORD *)(main_thrcb + 64) = 0LL;
queue_insert(&readyqueue);
queue_set_current(&readyqueue);
current_thrcb = main_thrcb;
initialized = 1;
return setitimer(ITIMER_VIRTUAL, &interval, 0LL);
}

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

func1();
interval.it_interval.tv_sec = 0LL;
interval.it_interval.tv_usec = 0LL;
interval.it_value.tv_sec = 0LL;
interval.it_value.tv_usec = a1;
timeslice = a1;
current_thr_id = 0LL;
active_threads = 0;
setmain = 0;
queue_init(&readyqueue);
queue_init(&deletequeue);
v1 = malloc(0x48uLL);
main_thrcb = (__int64)v1;
v1[1] = 0LL;
*((_DWORD *)v1 + 4) = 0;
*((_DWORD *)v1 + 5) = 0;
*v1 = &main_ctxt;
queue_init(v1 + 4);
*(_QWORD *)(main_thrcb + 64) = 0LL;
queue_insert(&readyqueue);
queue_set_current(&readyqueue);
current_thrcb = main_thrcb;
initialized = 1;
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:
int __fastcall gtthread_create(__int64 *a1, __int64 a2, __int64 a3)
{
int result; // eax
int v4; // edx
_QWORD *v5; // rbx
__int64 v6; // 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);
result = getcontext(ucp);
if ( result != -1 )
{
ucp->uc_stack.ss_sp = malloc(0x4000uLL);
ucp->uc_stack.ss_size = 0x4000LL;
ucp->uc_link = 0LL;
v4 = sigemptyset(&ucp->uc_sigmask);
result = -1;
if ( v4 >= 0 )
{
makecontext(ucp, wrapper_function, 2, a2, a3);
v5 = malloc(0x48uLL);
*v5 = ucp;
v6 = current_thr_id + 1;
current_thr_id = v6;
v5[1] = v6;
*a1 = v6;
*((_DWORD *)v5 + 4) = 0;
*((_DWORD *)v5 + 5) = 0;
v5[8] = 0LL;
queue_init(v5 + 4);
queue_insert(&readyqueue);
sigprocmask(1, &threadprocmask, 0LL);
result = 1;
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func3(__int64 *a1, __int64 a2, __int64 a3)
{
int result; // eax
int v4; // edx
_QWORD *v5; // rbx
__int64 v6; // 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);
result = getcontext(ucp);
if ( result != -1 )
{
ucp->uc_stack.ss_sp = malloc(0x4000uLL);
ucp->uc_stack.ss_size = 0x4000LL;
ucp->uc_link = 0LL;
v4 = sigemptyset(&ucp->uc_sigmask);
result = -1;
if ( v4 >= 0 )
{
makecontext(ucp, wrapper_function, 2, a2, a3);
v5 = malloc(0x48uLL);
*v5 = ucp;
v6 = current_thr_id + 1;
current_thr_id = v6;
v5[1] = v6;
*a1 = v6;
*((_DWORD *)v5 + 4) = 0;
*((_DWORD *)v5 + 5) = 0;
v5[8] = 0LL;
queue_init(v5 + 4);
queue_insert(&readyqueue);
sigprocmask(1, &threadprocmask, 0LL);
result = 1;
}
}
return result;
}

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;
*(_QWORD *)(v2 + 24) = a1;
if ( size_of_q(v2 + 32) > 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;
*(_QWORD *)(v2 + 24) = a1;
if ( size_of_q(v2 + 32) > 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; // rbx

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; // rbx

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; // rbp
__int64 v2; // rax
__int64 v3; // rbx
_QWORD *v4; // rax
__int64 result; // rax

sigprocmask(0, &threadprocmask, 0LL);
v1 = malloc(4uLL);
*v1 = 15;
v2 = queue_search(&readyqueue, a1);
if ( v2 )
{
v3 = v2;
*(_DWORD *)(v2 + 20) = 1;
v4 = (_QWORD *)queue_remove(&readyqueue, a1);
queue_insert_normal(&deletequeue, *v4);
if ( size_of_q(v3 + 32) > 0 )
queue_unblock_all(v3 + 32, v1);
*(_QWORD *)(v3 + 24) = v1;
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; // rbp
__int64 v2; // rax
__int64 v3; // rbx
_QWORD *v4; // rax
__int64 result; // rax

sigprocmask(0, &threadprocmask, 0LL);
v1 = malloc(4uLL);
*v1 = 15;
v2 = queue_search(&readyqueue, a1);
if ( v2 )
{
v3 = v2;
*(_DWORD *)(v2 + 20) = 1;
v4 = (_QWORD *)queue_remove(&readyqueue, a1);
queue_insert_normal(&deletequeue, *v4);
if ( size_of_q(v3 + 32) > 0 )
queue_unblock_all(v3 + 32, v1);
*(_QWORD *)(v3 + 24) = v1;
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 result; // rax

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

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

sigprocmask(0, &threadprocmask, 0LL);
if ( *(_QWORD *)(a1 + 8) == *(_QWORD *)(current_thrcb + 8) )
{
sigprocmask(1, &threadprocmask, 0LL);
result = 35LL;
}
else
{
while ( *(_DWORD *)a1 )
{
sigprocmask(1, &threadprocmask, 0LL);
func0(2LL);
}
*(_DWORD *)a1 = 1;
*(_QWORD *)(a1 + 8) = *(_QWORD *)(current_thrcb + 8);
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 i; // rax
__int64 v6; // rcx

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

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:
__m64 __fastcall nrsynth_inst_adsr(_DWORD *a1)
{
unsigned int v1; // edx
int v2; // eax
unsigned int v3; // eax
__m64 result; // xmm0_8
int v5; // ecx

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

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

v1 = a1[1];
v2 = a1[3];
if ( v1 < v2 )
{
*((_DWORD *)&result + 1) = 0;
*(float *)&result.m64_u64 = (float)(int)v1 / (float)v2;
}
else
{
v3 = a1[4] + v2;
result = (__m64)(unsigned int)LC4;
if ( v1 >= v3 )
{
v5 = a1[5];
if ( v1 >= v3 + v5 )
{
*a1 = 0;
result = 0LL;
}
else
{
*((_DWORD *)&result + 1) = 0;
*(float *)&result.m64_u64 = (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; // xmm1_4

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

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

v1 = *(float *)(a1 + 28);
return (float)(v1 * *(float *)&func1((_DWORD *)a1).m64_u64) * *(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)
{
__int64 result; // rax
int v2; // edx
float v3; // xmm0_4
unsigned __int64 v4; // rdx
float v5; // xmm0_4
unsigned __int64 v6; // rdx
float v7; // xmm0_4
unsigned __int64 v8; // rdx

result = (unsigned int)(*(_DWORD *)(a1 + 4) + 1);
*(_DWORD *)(a1 + 4) = result;
v2 = *(_DWORD *)(a1 + 24);
switch ( v2 )
{
case 1:
if ( (result & 1) == 0 )
{
result = xor128();
if ( result < 0 )
{
v6 = (unsigned __int64)result >> 1;
result &= 1u;
v5 = (float)(int)(result | v6) + (float)(int)(result | v6);
}
else
{
v5 = (float)(int)result;
}
*(float *)(a1 + 28) = (float)(v5 * 4.6566129e-10) - 1.0;
}
break;
case 2:
if ( (result & 7) == 0 )
{
result = xor128();
if ( result < 0 )
{
v8 = (unsigned __int64)result >> 1;
result &= 1u;
v7 = (float)(int)(result | v8) + (float)(int)(result | v8);
}
else
{
v7 = (float)(int)result;
}
*(float *)(a1 + 28) = (float)(v7 * 4.6566129e-10) - 1.0;
}
break;
case 0:
result = xor128();
if ( result < 0 )
{
v4 = (unsigned __int64)result >> 1;
result &= 1u;
v3 = (float)(int)(result | v4) + (float)(int)(result | v4);
}
else
{
v3 = (float)(int)result;
}
*(float *)(a1 + 28) = (float)(v3 * 4.6566129e-10) - 1.0;
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
__int64 result; // rax
int v2; // edx
float v3; // xmm0_4
unsigned __int64 v4; // rdx
float v5; // xmm0_4
unsigned __int64 v6; // rdx
float v7; // xmm0_4
unsigned __int64 v8; // rdx

result = (unsigned int)(*(_DWORD *)(a1 + 4) + 1);
*(_DWORD *)(a1 + 4) = result;
v2 = *(_DWORD *)(a1 + 24);
switch ( v2 )
{
case 1:
if ( (result & 1) == 0 )
{
result = xor128();
if ( result < 0 )
{
v6 = (unsigned __int64)result >> 1;
result &= 1u;
v5 = (float)(int)(result | v6) + (float)(int)(result | v6);
}
else
{
v5 = (float)(int)result;
}
*(float *)(a1 + 28) = (float)(v5 * 4.6566129e-10) - 1.0;
}
break;
case 2:
if ( (result & 7) == 0 )
{
result = xor128();
if ( result < 0 )
{
v8 = (unsigned __int64)result >> 1;
result &= 1u;
v7 = (float)(int)(result | v8) + (float)(int)(result | v8);
}
else
{
v7 = (float)(int)result;
}
*(float *)(a1 + 28) = (float)(v7 * 4.6566129e-10) - 1.0;
}
break;
case 0:
result = xor128();
if ( result < 0 )
{
v4 = (unsigned __int64)result >> 1;
result &= 1u;
v3 = (float)(int)(result | v4) + (float)(int)(result | v4);
}
else
{
v3 = (float)(int)result;
}
*(float *)(a1 + 28) = (float)(v3 * 4.6566129e-10) - 1.0;
break;
}
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:
_DWORD *nrsynth_create()
{
_DWORD *v0; // rbx

v0 = malloc(0x2A4uLL);
memset(v0, 0, 0x2A0uLL);
v0[168] = 0;
nrsynth_init((__int64)v0);
return v0;
}

canonical_decompiled_code:
_DWORD *func6()
{
_DWORD *v0; // rbx

v0 = malloc(0x2A4uLL);
memset(v0, 0, 0x2A0uLL);
v0[168] = 0;
func5((__int64)v0);
return v0;
}

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:
void __fastcall nrsynth_destroy(void *a1)
{
free(a1);
}

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

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 = *(unsigned int *)(a1 + 4LL * a2 + 144);
if ( (_DWORD)result != -1 )
{
*(_DWORD *)(a1 + 36LL * (int)result + 32) = a2;
result = a1 + 36LL * (int)result;
*(_DWORD *)result = 1;
*(_DWORD *)(result + 4) = 0;
*(float *)(result + 8) = a3;
}
return result;
}

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

result = *(unsigned int *)(a1 + 4LL * a2 + 144);
if ( (_DWORD)result != -1 )
{
*(_DWORD *)(a1 + 36LL * (int)result + 32) = a2;
result = a1 + 36LL * (int)result;
*(_DWORD *)result = 1;
*(_DWORD *)(result + 4) = 0;
*(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(__int64 a1, __int64 a2, unsigned int a3, int a4)
{
_DWORD *v5; // r13
__int64 result; // rax
int v7; // ebx
float v8; // xmm0_4
float v9; // [rsp+4h] [rbp-44h]
float v10; // [rsp+8h] [rbp-40h]

v9 = *(float *)(a1 + 668);
v10 = *(float *)(a1 + 672);
v5 = (_DWORD *)a1;
do
{
if ( *v5 )
{
result = audiobuf_seek(a2, a3);
if ( a4 > 0 )
{
v7 = 0;
do
{
v8 = nrsynth_inst_getwave((__int64)v5);
audiobuf_add(a2, 0LL, v8 * v9);
audiobuf_add(a2, 1LL, v10 * v8);
result = nrsynth_inst_next((__int64)v5);
++v7;
}
while ( a4 != v7 );
}
}
v5 += 9;
}
while ( v5 != (_DWORD *)(a1 + 144) );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 a2, unsigned int a3, int a4)
{
_DWORD *v5; // r13
__int64 result; // rax
int v7; // ebx
float v8; // xmm0_4
float v9; // [rsp+4h] [rbp-44h]
float v10; // [rsp+8h] [rbp-40h]

v9 = *(float *)(a1 + 668);
v10 = *(float *)(a1 + 672);
v5 = (_DWORD *)a1;
do
{
if ( *v5 )
{
result = audiobuf_seek(a2, a3);
if ( a4 > 0 )
{
v7 = 0;
do
{
v8 = func2((__int64)v5);
audiobuf_add(a2, 0LL, v8 * v9);
audiobuf_add(a2, 1LL, v10 * v8);
result = func3((__int64)v5);
++v7;
}
while ( a4 != v7 );
}
}
v5 += 9;
}
while ( v5 != (_DWORD *)(a1 + 144) );
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 )
{
v3 = a2[6];
if ( v3 )
nrsynth_play((__int64)a1, a2[5], (float)((float)v3 * (float)v3) / 16129.0);
}
else if ( v2 == 176 )
{
v4 = a2[5];
switch ( v4 )
{
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, signed int a2)
{
if ( (unsigned int)a2 > 3 )
return 0xFFFFFFFFLL;
if ( *(_DWORD *)(a1 + 36LL * a2) )
return *(unsigned int *)(a1 + 36LL * a2 + 32);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, signed int a2)
{
if ( (unsigned int)a2 > 3 )
return 0xFFFFFFFFLL;
if ( *(_DWORD *)(a1 + 36LL * a2) )
return *(unsigned int *)(a1 + 36LL * a2 + 32);
return 0xFFFFFFFFLL;
}

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 v11; // r15
__int64 v12; // r14
__int64 v13; // r13
__int64 v14; // r12
__int64 v15; // rbp
__int64 v17; // [rsp+0h] [rbp-68h]
__int64 v18; // [rsp+0h] [rbp-68h]
__int64 v19; // [rsp+0h] [rbp-68h]
__int64 v20; // [rsp+0h] [rbp-68h]
__int64 v21; // [rsp+0h] [rbp-68h]
__int64 v22; // [rsp+0h] [rbp-68h]
__int64 v23; // [rsp+0h] [rbp-68h]
__int64 v24; // [rsp+10h] [rbp-58h]
__int64 v25; // [rsp+18h] [rbp-50h]
__int64 v26; // [rsp+20h] [rbp-48h]

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

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 v11; // r15
__int64 v12; // r14
__int64 v13; // r13
__int64 v14; // r12
__int64 v15; // rbp
__int64 v17; // [rsp+0h] [rbp-68h]
__int64 v18; // [rsp+0h] [rbp-68h]
__int64 v19; // [rsp+0h] [rbp-68h]
__int64 v20; // [rsp+0h] [rbp-68h]
__int64 v21; // [rsp+0h] [rbp-68h]
__int64 v22; // [rsp+0h] [rbp-68h]
__int64 v23; // [rsp+0h] [rbp-68h]
__int64 v24; // [rsp+10h] [rbp-58h]
__int64 v25; // [rsp+18h] [rbp-50h]
__int64 v26; // [rsp+20h] [rbp-48h]

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

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


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
_QWORD *v4; // r12
__int64 v5; // rbp
__int64 v6; // rbx
__int64 v7; // r13
unsigned int v8; // er14
unsigned int v9; // er15
int v10; // er14
__int64 i; // rsi
int j; // er14

v3 = wtssynth_create(argc, argv, envp);
if ( !v3 )
_assert_fail("w != NULL", "wtssynth_test.c", 0x7Fu, "main");
v4 = (_QWORD *)v3;
v5 = audiobuf_create(352800LL, 2LL, 44100LL, 16LL);
if ( !v5 )
_assert_fail("a != NULL", "wtssynth_test.c", 0x82u, "main");
v6 = nrsynth_create();
if ( !v6 )
_assert_fail("n != NULL", "wtssynth_test.c", 0x85u, "main");
v7 = sdelay_create();
if ( !v7 )
_assert_fail("s != NULL", "wtssynth_test.c", 0x88u, "main");
wtsconfig_programchange(*v4, 8LL);
g_current_time = 0;
seventh_midi((__int64)v4, v5, key_C4, key_E5, key_G5, key_B5, 0xAC44u);
v8 = key_C6;
v9 = key_F5;
seventh_midi((__int64)v4, v5, key_D4, key_F5, key_A5, key_C6, 0xAC44u);
seventh_midi((__int64)v4, v5, key_E4, key_G5, key_B5, key_D6, 0xAC44u);
seventh_midi((__int64)v4, v5, key_Dp4, key_G5, key_Ap5, key_D6, 0xAC44u);
seventh_midi((__int64)v4, v5, key_D4, v9, key_A5, v8, 0x15888u);
seventh_midi((__int64)v4, v5, key_Cp4, v9, key_Gp5, v8, 0x15888u);
g_current_time = 0;
v10 = 0;
for ( i = 35LL; ; i = (v10 & 1) == 0 ? 35 : 38 )
{
nrsynth_play(v6, i, 1.0);
nrsynth_render(v6, v5, (unsigned int)g_current_time, 22050LL);
g_current_time += 22050;
if ( ++v10 == 16 )
break;
}
g_current_time = 0;
for ( j = 0; j != 32; ++j )
{
nrsynth_play(v6, 4 * (unsigned int)(j % 4 == 2) + 42, 1.0);
nrsynth_render(v6, v5, (unsigned int)g_current_time, 11025LL);
g_current_time += 11025;
}
sdelay_set_drywet(v7, 0.80000001, 0.5);
sdelay_render(v7, v5, 0LL, 352800LL);
audiobuf_save_header(v5, "test.wav");
audiobuf_save_append(v5, "test.wav");
sdelay_destroy(v7);
nrsynth_destroy(v6);
audiobuf_destroy(v5);
wtssynth_destroy(v4);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
_QWORD *v4; // r12
__int64 v5; // rbp
__int64 v6; // rbx
__int64 v7; // r13
unsigned int v8; // er14
unsigned int v9; // er15
int v10; // er14
__int64 i; // rsi
int j; // er14

v3 = wtssynth_create(argc, argv, envp);
if ( !v3 )
_assert_fail("w != NULL", "wtssynth_test.c", 0x7Fu, "main");
v4 = (_QWORD *)v3;
v5 = audiobuf_create(352800LL, 2LL, 44100LL, 16LL);
if ( !v5 )
_assert_fail("a != NULL", "wtssynth_test.c", 0x82u, "main");
v6 = nrsynth_create();
if ( !v6 )
_assert_fail("n != NULL", "wtssynth_test.c", 0x85u, "main");
v7 = sdelay_create();
if ( !v7 )
_assert_fail("s != NULL", "wtssynth_test.c", 0x88u, "main");
wtsconfig_programchange(*v4, 8LL);
g_current_time = 0;
func1((__int64)v4, v5, key_C4, key_E5, key_G5, key_B5, 0xAC44u);
v8 = key_C6;
v9 = key_F5;
func1((__int64)v4, v5, key_D4, key_F5, key_A5, key_C6, 0xAC44u);
func1((__int64)v4, v5, key_E4, key_G5, key_B5, key_D6, 0xAC44u);
func1((__int64)v4, v5, key_Dp4, key_G5, key_Ap5, key_D6, 0xAC44u);
func1((__int64)v4, v5, key_D4, v9, key_A5, v8, 0x15888u);
func1((__int64)v4, v5, key_Cp4, v9, key_Gp5, v8, 0x15888u);
g_current_time = 0;
v10 = 0;
for ( i = 35LL; ; i = (v10 & 1) == 0 ? 35 : 38 )
{
nrsynth_play(v6, i, 1.0);
nrsynth_render(v6, v5, (unsigned int)g_current_time, 22050LL);
g_current_time += 22050;
if ( ++v10 == 16 )
break;
}
g_current_time = 0;
for ( j = 0; j != 32; ++j )
{
nrsynth_play(v6, 4 * (unsigned int)(j % 4 == 2) + 42, 1.0);
nrsynth_render(v6, v5, (unsigned int)g_current_time, 11025LL);
g_current_time += 11025;
}
sdelay_set_drywet(v7, 0.80000001, 0.5);
sdelay_render(v7, v5, 0LL, 352800LL);
audiobuf_save_header(v5, "test.wav");
audiobuf_save_append(v5, "test.wav");
sdelay_destroy(v7);
nrsynth_destroy(v6);
audiobuf_destroy(v5);
wtssynth_destroy(v4);
return 0;
}

original_code:
int main(int argc, char *argv[]){
  int i;
  wtssynth_t *w;
  audiobuf_t *a;
  nrsynth_t *n;
  sdelay_t *s;
  int delta = 44100;
  w = wtssynth_create();
  ((void) sizeof ((w != ((void *)0)) ? 1 : 0), __extension__ ({ if (w != ((void *)0)) ; else __assert_fail ("w != NULL", "wtssynth_test.c", 127, __extension__ __PRETTY_FUNCTION__); }));
  a = audiobuf_create(44100 * 8, 2, 44100, 16);;
  ((void) sizeof ((a != ((void *)0)) ? 1 : 0), __extension__ ({ if (a != ((void *)0)) ; else __assert_fail ("a != NULL", "wtssynth_test.c", 130, __extension__ __PRETTY_FUNCTION__); }));
  n = nrsynth_create();
  ((void) sizeof ((n != ((void *)0)) ? 1 : 0), __extension__ ({ if (n != ((void *)0)) ; else __assert_fail ("n != NULL", "wtssynth_test.c", 133, __extension__ __PRETTY_FUNCTION__); }));
  s = sdelay_create();
  ((void) sizeof ((s != ((void *)0)) ? 1 : 0), __extension__ ({ if (s != ((void *)0)) ; else __assert_fail ("s != NULL", "wtssynth_test.c", 136, __extension__ __PRETTY_FUNCTION__); }));
  wtsconfig_programchange(w->config, 8);
  g_current_time = 0;
  seventh_midi(w, a, key_C4, key_E5, key_G5, key_B5, delta);
  seventh_midi(w, a, key_D4, key_F5, key_A5, key_C6, delta);
  seventh_midi(w, a, key_E4, key_G5, key_B5, key_D6, delta);
  seventh_midi(w, a, key_Dp4, key_G5, key_Ap5, key_D6, delta);
  seventh_midi(w, a, key_D4, key_F5, key_A5, key_C6, delta*2);
  seventh_midi(w, a, key_Cp4, key_F5, key_Gp5, key_C6, delta*2);
  g_current_time = 0;
  for(i = 0; i < 16; i++){
    nrsynth_play(n, i%2 == 0 ? 35 : 38, 1.0);
    nrsynth_render(n, a, g_current_time, 44100 * 8/16);
    g_current_time += 44100 * 8/16;
  }
  g_current_time = 0;
  for(i = 0; i < 32; i++){
    nrsynth_play(n, i%4 == 2 ? 46 : 42, 1.0);
    nrsynth_render(n, a, g_current_time, 44100 * 8/32);
    g_current_time += 44100 * 8/32;
  }
  sdelay_set_drywet(s, 0.8, 0.5);
  sdelay_render(s, a, 0, 44100 * 8);
  audiobuf_save_header(a, "test.wav");audiobuf_save_append(a, "test.wav");
  sdelay_destroy(s);
  nrsynth_destroy(n);
  audiobuf_destroy(a);
  wtssynth_destroy(w);
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[]){
  int i;
  struct wtssynth_t *w;
  struct audiobuf_t *a;
  struct nrsynth_t *n;
  struct sdelay_t *s;
  int delta = 44100;
  w = wtssynth_create();
  ((void) sizeof ((w != ((void *)0)) ? 1 : 0), __extension__ ({ if (w != ((void *)0)) ; else __assert_fail ("w != NULL", "wtssynth_test.c", 127, __extension__ __PRETTY_FUNCTION__); }));
  a = audiobuf_create(44100 * 8, 2, 44100, 16);;
  ((void) sizeof ((a != ((void *)0)) ? 1 : 0), __extension__ ({ if (a != ((void *)0)) ; else __assert_fail ("a != NULL", "wtssynth_test.c", 130, __extension__ __PRETTY_FUNCTION__); }));
  n = nrsynth_create();
  ((void) sizeof ((n != ((void *)0)) ? 1 : 0), __extension__ ({ if (n != ((void *)0)) ; else __assert_fail ("n != NULL", "wtssynth_test.c", 133, __extension__ __PRETTY_FUNCTION__); }));
  s = sdelay_create();
  ((void) sizeof ((s != ((void *)0)) ? 1 : 0), __extension__ ({ if (s != ((void *)0)) ; else __assert_fail ("s != NULL", "wtssynth_test.c", 136, __extension__ __PRETTY_FUNCTION__); }));
  wtsconfig_programchange(w->config, 8);
  g_current_time = 0;
  seventh_midi(w, a, key_C4, key_E5, key_G5, key_B5, delta);
  seventh_midi(w, a, key_D4, key_F5, key_A5, key_C6, delta);
  seventh_midi(w, a, key_E4, key_G5, key_B5, key_D6, delta);
  seventh_midi(w, a, key_Dp4, key_G5, key_Ap5, key_D6, delta);
  seventh_midi(w, a, key_D4, key_F5, key_A5, key_C6, delta*2);
  seventh_midi(w, a, key_Cp4, key_F5, key_Gp5, key_C6, delta*2);
  g_current_time = 0;
  for(i = 0; i < 16; i++){
    nrsynth_play(n, i%2 == 0 ? 35 : 38, 1.0);
    nrsynth_render(n, a, g_current_time, 44100 * 8/16);
    g_current_time += 44100 * 8/16;
  }
  g_current_time = 0;
  for(i = 0; i < 32; i++){
    nrsynth_play(n, i%4 == 2 ? 46 : 42, 1.0);
    nrsynth_render(n, a, g_current_time, 44100 * 8/32);
    g_current_time += 44100 * 8/32;
  }
  sdelay_set_drywet(s, 0.8, 0.5);
  sdelay_render(s, a, 0, 44100 * 8);
  audiobuf_save_header(a, "test.wav");audiobuf_save_append(a, "test.wav");
  sdelay_destroy(s);
  nrsynth_destroy(n);
  audiobuf_destroy(a);
  wtssynth_destroy(w);
  return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

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

variable_types: struct sdelay_t { struct sdelay_allpass_t { struct audiobuf_t { int n_channels; int sampling_rate; int qbit; float **data; int *index; int size; } *tap; float gain; float current_output_l; float current_output_r; } *apfilter[3]; float gain; float dry; float wet; float current_output_l; float current_output_r; } *

variable_types: delta int

user_defined_types: struct sdelay_t { struct sdelay_allpass_t *apfilter[3]; float gain; float dry; float wet; float current_output_l; float current_output_r; }

user_defined_types: struct sdelay_allpass_t { struct audiobuf_t *tap; float gain; float current_output_l; float current_output_r; }


decompiled_code:
void __fastcall audiobuf_destroy(void *ptr)
{
__int64 v2; // rbx
void *v3; // rdi

if ( ptr )
{
if ( *((_QWORD *)ptr + 2) )
{
if ( *((_QWORD *)ptr + 3) )
{
if ( *(int *)ptr > 0 )
{
v2 = 0LL;
do
{
v3 = *(void **)(*((_QWORD *)ptr + 2) + 8 * v2);
if ( !v3 )
break;
free(v3);
++v2;
}
while ( *(_DWORD *)ptr > (int)v2 );
}
free(*((void **)ptr + 3));
}
free(*((void **)ptr + 2));
}
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
__int64 v2; // rbx
void *v3; // rdi

if ( ptr )
{
if ( *((_QWORD *)ptr + 2) )
{
if ( *((_QWORD *)ptr + 3) )
{
if ( *(int *)ptr > 0 )
{
v2 = 0LL;
do
{
v3 = *(void **)(*((_QWORD *)ptr + 2) + 8 * v2);
if ( !v3 )
break;
free(v3);
++v2;
}
while ( *(_DWORD *)ptr > (int)v2 );
}
free(*((void **)ptr + 3));
}
free(*((void **)ptr + 2));
}
free(ptr);
}
}

original_code:
void audiobuf_destroy(audiobuf_t *a){
  int i;
  if(a == ((void *)0)) return;
  if(a->data == ((void *)0)) goto free1;
  if(a->index == ((void *)0)) goto free2;
  for(i = 0; i < a->n_channels; i ++){
    if(a->data[i] == ((void *)0)){
      goto free3;
    }else{
      free(a->data[i]);
    }
  }
 free3:
  free(a->index);
 free2:
  free(a->data);
 free1:
  free(a);
}

canonical_original_code:
void audiobuf_destroy(struct audiobuf_t *a){
  int i;
  if(a == ((void *)0)) return;
  if(a->data == ((void *)0)) goto free1;
  if(a->index == ((void *)0)) goto free2;
  for(i = 0; i < a->n_channels; i ++){
    if(a->data[i] == ((void *)0)){
      goto free3;
    }else{
      free(a->data[i]);
    }
  }
 free3:
  free(a->index);
 free2:
  free(a->data);
 free1:
  free(a);
}

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


decompiled_code:
__int64 __fastcall audiobuf_copy(unsigned int *a1, unsigned int *a2)
{
int v2; // er10
__int64 result; // rax
__int64 v4; // r9
__int64 v5; // rdx

v2 = a1[8];
if ( (int)a2[8] <= v2 )
v2 = a2[8];
result = *a1;
if ( (int)*a2 <= (int)result )
result = *a2;
if ( (int)result > 0 )
{
v4 = 8LL * (unsigned int)result;
v5 = 0LL;
do
{
result = 0LL;
if ( v2 > 0 )
{
do
{
*(_DWORD *)(*(_QWORD *)(*((_QWORD *)a2 + 2) + v5) + result) = *(_DWORD *)(*(_QWORD *)(*((_QWORD *)a1 + 2) + v5)
+ result);
result += 4LL;
}
while ( result != 4LL * (unsigned int)(v2 - 1) + 4 );
}
v5 += 8LL;
}
while ( v5 != v4 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int *a1, unsigned int *a2)
{
int v2; // er10
__int64 result; // rax
__int64 v4; // r9
__int64 v5; // rdx

v2 = a1[8];
if ( (int)a2[8] <= v2 )
v2 = a2[8];
result = *a1;
if ( (int)*a2 <= (int)result )
result = *a2;
if ( (int)result > 0 )
{
v4 = 8LL * (unsigned int)result;
v5 = 0LL;
do
{
result = 0LL;
if ( v2 > 0 )
{
do
{
*(_DWORD *)(*(_QWORD *)(*((_QWORD *)a2 + 2) + v5) + result) = *(_DWORD *)(*(_QWORD *)(*((_QWORD *)a1 + 2) + v5)
+ result);
result += 4LL;
}
while ( result != 4LL * (unsigned int)(v2 - 1) + 4 );
}
v5 += 8LL;
}
while ( v5 != v4 );
}
return result;
}

original_code:
void audiobuf_copy(audiobuf_t *src, audiobuf_t *dst){
  int i,j;
  int maxdata = src->size < dst->size ? src->size : dst->size;
  int maxchannel = src->n_channels < dst->n_channels ? src->n_channels : dst->n_channels;
  for(i = 0; i < maxchannel; i ++){
    for(j = 0; j < maxdata; j ++){
      dst->data[i][j] = src->data[i][j];
    }
  }
}

canonical_original_code:
void audiobuf_copy(struct audiobuf_t *src, struct audiobuf_t *dst){
  int i; int j;
  int maxdata = src->size < dst->size ? src->size : dst->size;
  int maxchannel = src->n_channels < dst->n_channels ? src->n_channels : dst->n_channels;
  for(i = 0; i < maxchannel; i ++){
    for(j = 0; j < maxdata; j ++){
      dst->data[i][j] = src->data[i][j];
    }
  }
}

variable_types:
dst
struct audiobuf_t *

variable_types: i int

variable_types: maxdata int

variable_types: maxchannel int


decompiled_code:
__int64 __fastcall audoibuf_merge(unsigned int *a1, unsigned int *a2)
{
int v2; // er11
__int64 result; // rax
__int64 v4; // r10
__int64 v5; // rcx
float *v6; // rdx

v2 = a1[8];
if ( (int)a2[8] <= v2 )
v2 = a2[8];
result = *a1;
if ( (int)*a2 <= (int)result )
result = *a2;
if ( (int)result > 0 )
{
v4 = 8LL * (unsigned int)result;
v5 = 0LL;
do
{
result = 0LL;
if ( v2 > 0 )
{
do
{
v6 = (float *)(*(_QWORD *)(*((_QWORD *)a2 + 2) + v5) + result);
*v6 = *v6 + *(float *)(*(_QWORD *)(*((_QWORD *)a1 + 2) + v5) + result);
result += 4LL;
}
while ( result != 4LL * (unsigned int)(v2 - 1) + 4 );
}
v5 += 8LL;
}
while ( v5 != v4 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int *a1, unsigned int *a2)
{
int v2; // er11
__int64 result; // rax
__int64 v4; // r10
__int64 v5; // rcx
float *v6; // rdx

v2 = a1[8];
if ( (int)a2[8] <= v2 )
v2 = a2[8];
result = *a1;
if ( (int)*a2 <= (int)result )
result = *a2;
if ( (int)result > 0 )
{
v4 = 8LL * (unsigned int)result;
v5 = 0LL;
do
{
result = 0LL;
if ( v2 > 0 )
{
do
{
v6 = (float *)(*(_QWORD *)(*((_QWORD *)a2 + 2) + v5) + result);
*v6 = *v6 + *(float *)(*(_QWORD *)(*((_QWORD *)a1 + 2) + v5) + result);
result += 4LL;
}
while ( result != 4LL * (unsigned int)(v2 - 1) + 4 );
}
v5 += 8LL;
}
while ( v5 != v4 );
}
return result;
}

original_code:
void audoibuf_merge(audiobuf_t *src, audiobuf_t *dst){
  int i,j;
  int maxdata = src->size < dst->size ? src->size : dst->size;
  int maxchannel = src->n_channels < dst->n_channels ? src->n_channels : dst->n_channels;
  for(i = 0; i < maxchannel; i ++){
    for(j = 0; j < maxdata; j ++){
      dst->data[i][j] += src->data[i][j];
    }
  }
}

canonical_original_code:
void audoibuf_merge(struct audiobuf_t *src, struct audiobuf_t *dst){
  int i; int j;
  int maxdata = src->size < dst->size ? src->size : dst->size;
  int maxchannel = src->n_channels < dst->n_channels ? src->n_channels : dst->n_channels;
  for(i = 0; i < maxchannel; i ++){
    for(j = 0; j < maxdata; j ++){
      dst->data[i][j] += src->data[i][j];
    }
  }
}

variable_types: j int


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

if ( *(int *)a1 > 0 )
{
v1 = 0LL;
do
{
memset(*(void **)(*(_QWORD *)(a1 + 16) + 8 * v1), 0, 4LL * *(int *)(a1 + 32));
result = *(_QWORD *)(a1 + 24);
*(_DWORD *)(result + 4 * v1++) = 0;
}
while ( *(_DWORD *)a1 > (int)v1 );
}
return result;
}

original_code:
void audiobuf_clear(audiobuf_t *a){
  int i;
  for(i = 0; i < a->n_channels; i++){
    memset(a->data[i], 0, sizeof(float) * a->size);
    a->index[i] = 0;
  }
}

canonical_original_code:
void audiobuf_clear(struct audiobuf_t *a){
  int i;
  for(i = 0; i < a->n_channels; i++){
    memset(a->data[i], 0, sizeof(float) * a->size);
    a->index[i] = 0;
  }
}


decompiled_code:
int *__fastcall audiobuf_duplicate(int *a1)
{
int *v1; // rbp

v1 = audiobuf_create(a1[8], *a1, a1[1], a1[2]);
audiobuf_copy((unsigned int *)a1, (unsigned int *)v1);
return v1;
}

canonical_decompiled_code:
int *__fastcall func5(int *a1)
{
int *v1; // rbp

v1 = func4(a1[8], *a1, a1[1], a1[2]);
func1((unsigned int *)a1, (unsigned int *)v1);
return v1;
}

original_code:
audiobuf_t *audiobuf_duplicate(audiobuf_t *a){
  audiobuf_t *b;
  b = audiobuf_create(a->size, a->n_channels, a->sampling_rate, a->qbit);
  audiobuf_copy(a, b);
  return b;
}

canonical_original_code:
struct audiobuf_t *audiobuf_duplicate(struct audiobuf_t *a){
  struct audiobuf_t *b;
  b = audiobuf_create(a->size, a->n_channels, a->sampling_rate, a->qbit);
  audiobuf_copy(a, b);
  return b;
}

variable_types:
a
struct audiobuf_t *

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


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

if ( *(int *)a1 > 0 )
{
v1 = 0LL;
do
*(_DWORD *)(*(_QWORD *)(a1 + 24) + 4 * v1++) = 0;
while ( *(_DWORD *)a1 > (int)v1 );
}
}

original_code:
void audiobuf_rewind(audiobuf_t *a){
  int i;
  for(i = 0; i < a->n_channels; i++){
    a->index[i] = 0;
  }
}

canonical_original_code:
void audiobuf_rewind(struct audiobuf_t *a){
  int i;
  for(i = 0; i < a->n_channels; i++){
    a->index[i] = 0;
  }
}


decompiled_code:
void __fastcall audiobuf_seek(__int64 a1, int a2)
{
__int64 v2; // rax

if ( *(int *)a1 > 0 )
{
v2 = 0LL;
do
*(_DWORD *)(*(_QWORD *)(a1 + 24) + 4 * v2++) = a2;
while ( *(_DWORD *)a1 > (int)v2 );
}
}

original_code:
void audiobuf_seek(audiobuf_t *a, int pos){
  int i;
  for(i = 0; i < a->n_channels; i++){
    a->index[i] = pos;
  }
}

canonical_original_code:
void audiobuf_seek(struct audiobuf_t *a, int pos){
  int i;
  for(i = 0; i < a->n_channels; i++){
    a->index[i] = pos;
  }
}

variable_types: pos int


decompiled_code:
float __fastcall audiobuf_get(__int64 a1, int a2)
{
return *(float *)(*(_QWORD *)(*(_QWORD *)(a1 + 16) + 8LL * a2) + 4LL * *(int *)(*(_QWORD *)(a1 + 24) + 4LL * a2));
}

original_code:
float audiobuf_get(audiobuf_t *a, int channel){
  return a->data[channel][a->index[channel]];
}

canonical_original_code:
float audiobuf_get(struct audiobuf_t *a, int channel){
  return a->data[channel][a->index[channel]];
}

variable_types: channel int


original_code:
void audiobuf_wrap(audiobuf_t *a){
  int i;
  for(i = 0 ; i < a->n_channels; i ++){
    if(a->index[i] >= a->size) a->index[i] = 0;
  }
}

canonical_original_code:
void audiobuf_wrap(struct audiobuf_t *a){
  int i;
  for(i = 0 ; i < a->n_channels; i ++){
    if(a->index[i] >= a->size) a->index[i] = 0;
  }
}


decompiled_code:
__int64 __fastcall sdelay_allpass_process(float *a1, float a2, float a3)
{
__m128i v3; // xmm3
__m128i v4; // xmm6
float v6; // [rsp+Ch] [rbp-2Ch]
float v7; // [rsp+10h] [rbp-28h]
float v8; // [rsp+14h] [rbp-24h]

v6 = a1[2];
v7 = audiobuf_get(*(_QWORD *)a1, 0LL);
v8 = audiobuf_get(*(_QWORD *)a1, 1LL);
v3 = (__m128i)LODWORD(v6);
*(float *)v3.m128i_i32 = v6 * v7;
v4 = v3;
*(float *)v4.m128i_i32 = (float)(v6 * v7) + a2;
audiobuf_write(*(_QWORD *)a1, 0LL, *(double *)v4.m128i_i64);
audiobuf_write(*(_QWORD *)a1, 1LL, COERCE_DOUBLE((unsigned __int64)COERCE_UNSIGNED_INT((float)(v6 * v8) + a3)));
a1[3] = v7 - (float)(COERCE_FLOAT(_mm_cvtsi128_si32(v4)) * v6);
a1[4] = v8 - (float)((float)((float)(v6 * v8) + a3) * v6);
return audiobuf_wrap(*(_QWORD *)a1);
}

canonical_decompiled_code:
__int64 __fastcall func2(float *a1, float a2, float a3)
{
__m128i v3; // xmm3
__m128i v4; // xmm6
float v6; // [rsp+Ch] [rbp-2Ch]
float v7; // [rsp+10h] [rbp-28h]
float v8; // [rsp+14h] [rbp-24h]

v6 = a1[2];
v7 = audiobuf_get(*(_QWORD *)a1, 0LL);
v8 = audiobuf_get(*(_QWORD *)a1, 1LL);
v3 = (__m128i)LODWORD(v6);
*(float *)v3.m128i_i32 = v6 * v7;
v4 = v3;
*(float *)v4.m128i_i32 = (float)(v6 * v7) + a2;
audiobuf_write(*(_QWORD *)a1, 0LL, *(double *)v4.m128i_i64);
audiobuf_write(*(_QWORD *)a1, 1LL, COERCE_DOUBLE((unsigned __int64)COERCE_UNSIGNED_INT((float)(v6 * v8) + a3)));
a1[3] = v7 - (float)(COERCE_FLOAT(_mm_cvtsi128_si32(v4)) * v6);
a1[4] = v8 - (float)((float)((float)(v6 * v8) + a3) * v6);
return audiobuf_wrap(*(_QWORD *)a1);
}

original_code:
static void sdelay_allpass_process(sdelay_allpass_t *a, float l, float r){
  float g = a->gain;
  float dl,dr;
  dl = audiobuf_get(a->tap, 0);
  dr = audiobuf_get(a->tap, 1);
  audiobuf_write(a->tap, 0, l+dl*g);
  audiobuf_write(a->tap, 1, r+dr*g);
  a->current_output_l = dl - (l+dl*g)*g;
  a->current_output_r = dr - (r+dr*g)*g;
  audiobuf_wrap(a->tap);
}

canonical_original_code:
static void sdelay_allpass_process(struct sdelay_allpass_t *a, float l, float r){
  float g = a->gain;
  float dl; float dr;
  dl = audiobuf_get(a->tap, 0);
  dr = audiobuf_get(a->tap, 1);
  audiobuf_write(a->tap, 0, l+dl*g);
  audiobuf_write(a->tap, 1, r+dr*g);
  a->current_output_l = dl - (l+dl*g)*g;
  a->current_output_r = dr - (r+dr*g)*g;
  audiobuf_wrap(a->tap);
}

variable_types: struct sdelay_allpass_t { struct audiobuf_t { int n_channels; int sampling_rate; int qbit; float **data; int *index; int size; } *tap; float gain; float current_output_l; float current_output_r; } *

variable_types: l float

variable_types: r float

variable_types: g float

variable_types: dl float

variable_types: dr float


decompiled_code:
__int64 __fastcall sdelay_process(float **a1, float a2, float a3)
{
sdelay_allpass_process(*a1, a2, a3);
sdelay_allpass_process(a1[1], (*a1)[3], (*a1)[4]);
return sdelay_allpass_process(a1[2], a1[1][3], a1[1][4]);
}

original_code:
static void sdelay_process(sdelay_t *s, float l, float r){
  int i;
  sdelay_allpass_process(s->apfilter[0], l, r);
  for(i = 1; i < 3; i++){
    sdelay_allpass_process(s->apfilter[i],
      s->apfilter[i-1]->current_output_l,
      s->apfilter[i-1]->current_output_r);
  }
}

canonical_original_code:
static void sdelay_process(struct sdelay_t *s, float l, float r){
  int i;
  sdelay_allpass_process(s->apfilter[0], l, r);
  for(i = 1; i < 3; i++){
    sdelay_allpass_process(s->apfilter[i],
      s->apfilter[i-1]->current_output_l,
      s->apfilter[i-1]->current_output_r);
  }
}

variable_types: struct sdelay_t { struct sdelay_allpass_t { struct audiobuf_t { int n_channels; int sampling_rate; int qbit; float **data; int *index; int size; } *tap; float gain; float current_output_l; float current_output_r; } *apfilter[3]; float gain; float dry; float wet; float current_output_l; float current_output_r; } *


decompiled_code:
void __fastcall sdelay_allpass_destroy(void *ptr)
{
audiobuf_destroy(*(_QWORD *)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func4(void *ptr)
{
audiobuf_destroy(*(_QWORD *)ptr);
free(ptr);
}

original_code:
void sdelay_allpass_destroy(sdelay_allpass_t *a){
  audiobuf_destroy(a->tap);
  free(a);
}

canonical_original_code:
void sdelay_allpass_destroy(struct sdelay_allpass_t *a){
  audiobuf_destroy(a->tap);
  free(a);
}