adduser

decompiled_code:
char *__fastcall adduser(char *a1, char *a2)
{
char *result; // rax

if ( !a2 )
return 0LL;
result = finduser(a1, a2);
if ( !result )
result = createu((__int64)a1, a2);
return result;
}

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

if ( !a2 )
return 0LL;
result = func1(a1, a2);
if ( !result )
result = func0((__int64)a1, a2);
return result;
}

original_code:
TUser * adduser(TUser * ulist, char * name){
  if(!name)
    return ((void *)0);
  TUser * user = finduser(ulist,name);
  if(!user)
    user = _createu(ulist,name);
  return user;
}

canonical_original_code:
struct user *adduser(struct user *ulist, char *name){
  if(!name)
    return ((void *)0);
  struct user *user = finduser(ulist,name);
  if(!user)
    user = _createu(ulist,name);
  return user;
}

return_type: struct user { char id[80]; struct prioritylist { struct prio { int priority; struct queue { struct node { struct task { struct user *owner; unsigned int pid; int priority; char cmd[80]; } *info; struct node *next; } *begin; struct node *end; } *tasks; struct prio *next; } *priorities; } *waiting; struct queue *done; struct user *next; } *


initializeuser

repo: println/scheduler

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

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

original_code:
TUser * initializeuser(void){
  return ((void *)0);
}

canonical_original_code:
struct user *initializeuser(){
  return ((void *)0);
}

user_defined_types: struct user { char id[80]; struct prioritylist *waiting; struct queue *done; struct user *next; }

user_defined_types: struct prioritylist { struct prio *priorities; }

user_defined_types: struct prio { int priority; struct queue *tasks; struct prio *next; }

user_defined_types: struct queue { struct node *begin; struct node *end; }

user_defined_types: struct node { struct task *info; struct node *next; }

user_defined_types: struct task { struct user *owner; unsigned int pid; int priority; char cmd[80]; }


releaseu

decompiled_code:
void __fastcall releaseu(void *ptr)
{
_QWORD *v1; // rbx
_QWORD *v2; // rbp

v1 = ptr;
if ( ptr )
{
do
{
v2 = v1;
v1 = (_QWORD *)v1[12];
releasep(v2[10]);
free(v2);
}
while ( v1 );
}
}

canonical_decompiled_code:
void __fastcall func4(void *ptr)
{
_QWORD *v1; // rbx
_QWORD *v2; // rbp

v1 = ptr;
if ( ptr )
{
do
{
v2 = v1;
v1 = (_QWORD *)v1[12];
releasep(v2[10]);
free(v2);
}
while ( v1 );
}
}

original_code:
void releaseu(TUser * user){
    while(user){
       TUser * u = user;
       user = user->next;
       releasep(u->waiting);
       free(u);
    }
}

canonical_original_code:
void releaseu(struct user *user){
    while(user){
       struct user *u = user;
       user = user->next;
       releasep(u->waiting);
       free(u);
    }
}

variable_types: struct user { char id[80]; struct prioritylist { struct prio { int priority; struct queue { struct node { struct task { struct user *owner; unsigned int pid; int priority; char cmd[80]; } *info; struct node *next; } *begin; struct node *end; } *tasks; struct prio *next; } *priorities; } *waiting; struct queue *done; struct user *next; } *

return_type: void


decompiled_code:
_QWORD *start_base()
{
_QWORD *v0; // rbx

v0 = malloc(0x30uLL);
v0[2] = initializeq();
v0[5] = initializeq();
v0[4] = initializeq();
v0[3] = initializep();
v0[1] = initializeuser();
*(_DWORD *)v0 = 1;
return v0;
}

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

v0 = malloc(0x30uLL);
v0[2] = initializeq();
v0[5] = initializeq();
v0[4] = initializeq();
v0[3] = initializep();
v0[1] = initializeuser();
*(_DWORD *)v0 = 1;
return v0;
}

original_code:
TBase * start_base(void) {
    TBase * base = (TBase*) malloc(sizeof (TBase));
    base->FE = initializeq();
    base->FPSO = initializeq();
    base->FTR = initializeq();
    base->FU = initializep();
    base->users = initializeuser();
    base->pid = 1;
    return base;
}

canonical_original_code:
struct base *start_base() {
    struct base *base = (TBase*) malloc(sizeof (TBase));
    base->FE = initializeq();
    base->FPSO = initializeq();
    base->FTR = initializeq();
    base->FU = initializep();
    base->users = initializeuser();
    base->pid = 1;
    return base;
}

variable_types: struct base { unsigned int pid; struct user { char id[80]; struct prioritylist { struct prio { int priority; struct queue { struct node { struct task { struct user *owner; unsigned int pid; int priority; char cmd[80]; } *info; struct node *next; } *begin; struct node *end; } *tasks; struct prio *next; } *priorities; } *waiting; struct queue *done; struct user *next; } *users; struct queue *FE; struct prioritylist *FU; struct queue *FTR; struct queue *FPSO; } *

user_defined_types: struct base { unsigned int pid; struct user *users; struct queue *FE; struct prioritylist *FU; struct queue *FTR; struct queue *FPSO; }


arrange

decompiled_code:
__int64 __fastcall arrange(_QWORD *a1)
{
__int64 result; // rax
__int64 v2; // rsi

while ( 1 )
{
result = emptyq(a1[2]);
if ( (_DWORD)result )
break;
v2 = pop(a1[2]);
if ( *(_DWORD *)(v2 + 12) )
addtask(a1[3], v2);
else
push(a1[4], v2);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1)
{
__int64 result; // rax
__int64 v2; // rsi

while ( 1 )
{
result = emptyq(a1[2]);
if ( (_DWORD)result )
break;
v2 = pop(a1[2]);
if ( *(_DWORD *)(v2 + 12) )
addtask(a1[3], v2);
else
push(a1[4], v2);
}
return result;
}

original_code:
void arrange(TBase * base) {
    while (!emptyq(base->FE)) {
        Task * task = pop(base->FE);
        if (task->priority == 0)
            push(base->FTR, task);
        else
            addtask(base->FU, task);
    }
}

canonical_original_code:
void arrange(struct base *base) {
    while (!emptyq(base->FE)) {
        struct task *task = pop(base->FE);
        if (task->priority == 0)
            push(base->FTR, task);
        else
            addtask(base->FU, task);
    }
}

variable_types: struct task { struct user { char id[80]; struct prioritylist { struct prio { int priority; struct queue { struct node { struct task *info; struct node *next; } *begin; struct node *end; } *tasks; struct prio *next; } *priorities; } *waiting; struct queue *done; struct user *next; } *owner; unsigned int pid; int priority; char cmd[80]; } *


decompiled_code:
int __fastcall printform_tasks(__int64 a1)
{
int result; // eax

result = emptyq(a1);
if ( !result )
{
printf(" -> ");
printq(a1);
result = putchar(10);
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1)
{
int result; // eax

result = emptyq(a1);
if ( !result )
{
printf(" -> ");
printq(a1);
result = putchar(10);
}
return result;
}

original_code:
void printform_tasks(TQueue * q) {
    if (!emptyq(q)) {
        printf(" -> ");
        printq(q);
        printf("\n");
    }
}

canonical_original_code:
void printform_tasks(struct queue *q) {
    if (!emptyq(q)) {
        printf(" -> ");
        printq(q);
        printf("\n");
    }
}

variable_types: struct queue { struct node { struct task { struct user { char id[80]; struct prioritylist { struct prio { int priority; struct queue *tasks; struct prio *next; } *priorities; } *waiting; struct queue *done; struct user *next; } *owner; unsigned int pid; int priority; char cmd[80]; } *info; struct node *next; } *begin; struct node *end; } *


decompiled_code:
int __fastcall printform_user(const char *a1, __int64 a2)
{
printf("%s", a1);
return printform_tasks(a2);
}

canonical_decompiled_code:
int __fastcall func3(const char *a1, __int64 a2)
{
printf("%s", a1);
return func2(a2);
}

original_code:
void printform_user(char * name, TQueue * q) {
    printf("%s", name);
    printform_tasks(q);
}

canonical_original_code:
void printform_user(char *name, struct queue *q) {
    printf("%s", name);
    printform_tasks(q);
}

variable_types:
name
char *


decompiled_code:
int __fastcall printform_priority(unsigned int a1, __int64 a2)
{
printf("|-%i", a1);
return printform_tasks(a2);
}

canonical_decompiled_code:
int __fastcall func4(unsigned int a1, __int64 a2)
{
printf("|-%i", a1);
return func2(a2);
}

original_code:
void printform_priority(int priority, TQueue * q) {
    printf("|-%i", priority);
    printform_tasks(q);
}

canonical_original_code:
void printform_priority(int priority, struct queue *q) {
    printf("|-%i", priority);
    printform_tasks(q);
}

variable_types: priority int


decompiled_code:
int __fastcall printform_prioritylist(__int64 *a1)
{
__int64 i; // rbx
int result; // eax

for ( i = *a1; i; i = *(_QWORD *)(i + 16) )
result = printform_priority(*(_DWORD *)i, *(_QWORD *)(i + 8));
return result;
}

canonical_decompiled_code:
int __fastcall func5(__int64 *a1)
{
__int64 i; // rbx
int result; // eax

for ( i = *a1; i; i = *(_QWORD *)(i + 16) )
result = func4(*(_DWORD *)i, *(_QWORD *)(i + 8));
return result;
}

original_code:
void printform_prioritylist(PriorityList * plist) {
    TPriority * tmp = plist->priorities;
    while (tmp) {
        printform_priority(tmp->priority, tmp->tasks);
        tmp = tmp->next;
    }
}

canonical_original_code:
void printform_prioritylist(struct prioritylist *plist) {
    struct prio *tmp = plist->priorities;
    while (tmp) {
        printform_priority(tmp->priority, tmp->tasks);
        tmp = tmp->next;
    }
}

variable_types: struct prioritylist { struct prio { int priority; struct queue { struct node { struct task { struct user { char id[80]; struct prioritylist *waiting; struct queue *done; struct user *next; } *owner; unsigned int pid; int priority; char cmd[80]; } *info; struct node *next; } *begin; struct node *end; } *tasks; struct prio *next; } *priorities; } *

variable_types: struct prio { int priority; struct queue { struct node { struct task { struct user { char id[80]; struct prioritylist { struct prio *priorities; } *waiting; struct queue *done; struct user *next; } *owner; unsigned int pid; int priority; char cmd[80]; } *info; struct node *next; } *begin; struct node *end; } *tasks; struct prio *next; } *


decompiled_code:
int __fastcall print_user(__int64 a1)
{
printf("*%s\n", (const char *)a1);
if ( !(unsigned int)emptyp(*(_QWORD *)(a1 + 80)) )
{
puts("Nao executados:");
printform_prioritylist(*(__int64 **)(a1 + 80));
}
if ( !(unsigned int)emptyq(*(_QWORD *)(a1 + 88)) )
{
printf("Executados:");
printform_tasks(*(_QWORD *)(a1 + 88));
}
return puts("-----------------");
}

canonical_decompiled_code:
int __fastcall func6(__int64 a1)
{
printf("*%s\n", (const char *)a1);
if ( !(unsigned int)emptyp(*(_QWORD *)(a1 + 80)) )
{
puts("Nao executados:");
func5(*(__int64 **)(a1 + 80));
}
if ( !(unsigned int)emptyq(*(_QWORD *)(a1 + 88)) )
{
printf("Executados:");
func2(*(_QWORD *)(a1 + 88));
}
return puts("-----------------");
}

original_code:
void print_user(TUser * user) {
    printf("*%s\n", user->id);
    if (!emptyp(user->waiting)) {
        printf("Nao executados:\n");
        printform_prioritylist(user->waiting);
    }
    if (!emptyq(user->done)) {
        printf("Executados:");
        printform_tasks( user->done);
    }
    printf("-----------------\n");
}

canonical_original_code:
void print_user(struct user *user) {
    printf("*%s\n", user->id);
    if (!emptyp(user->waiting)) {
        printf("Nao executados:\n");
        printform_prioritylist(user->waiting);
    }
    if (!emptyq(user->done)) {
        printf("Executados:");
        printform_tasks( user->done);
    }
    printf("-----------------\n");
}


decompiled_code:
int __fastcall print_users(__int64 a1)
{
__int64 i; // rbx
int result; // eax

for ( i = *(_QWORD *)(a1 + 8); i; i = *(_QWORD *)(i + 96) )
result = print_user(i);
return result;
}

canonical_decompiled_code:
int __fastcall func7(__int64 a1)
{
__int64 i; // rbx
int result; // eax

for ( i = *(_QWORD *)(a1 + 8); i; i = *(_QWORD *)(i + 96) )
result = func6(i);
return result;
}

original_code:
void print_users(TBase * base) {
    TUser * user = base->users;
    while (user) {
        print_user(user);
        user = user->next;
    }
}

canonical_original_code:
void print_users(struct base *base) {
    struct user *user = base->users;
    while (user) {
        print_user(user);
        user = user->next;
    }
}


decompiled_code:
int __fastcall print_fe(__int64 a1)
{
printf("FE -> ");
printq(*(_QWORD *)(a1 + 16));
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func8(__int64 a1)
{
printf("FE -> ");
printq(*(_QWORD *)(a1 + 16));
return putchar(10);
}

original_code:
void print_fe(TBase * base) {
    printf("FE -> ");
    printq(base->FE);
    printf("\n");
}

canonical_original_code:
void print_fe(struct base *base) {
    printf("FE -> ");
    printq(base->FE);
    printf("\n");
}


decompiled_code:
int __fastcall print_ftr(__int64 a1)
{
printf("FTR -> ");
printq(*(_QWORD *)(a1 + 32));
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func9(__int64 a1)
{
printf("FTR -> ");
printq(*(_QWORD *)(a1 + 32));
return putchar(10);
}

original_code:
void print_ftr(TBase * base) {
    printf("FTR -> ");
    printq(base->FTR);
    printf("\n");
}

canonical_original_code:
void print_ftr(struct base *base) {
    printf("FTR -> ");
    printq(base->FTR);
    printf("\n");
}


decompiled_code:
int __fastcall print_fpso(__int64 a1)
{
printf("FPSO -> ");
printq(*(_QWORD *)(a1 + 40));
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func10(__int64 a1)
{
printf("FPSO -> ");
printq(*(_QWORD *)(a1 + 40));
return putchar(10);
}

original_code:
void print_fpso(TBase * base) {
    printf("FPSO -> ");
    printq(base->FPSO);
    printf("\n");
}

canonical_original_code:
void print_fpso(struct base *base) {
    printf("FPSO -> ");
    printq(base->FPSO);
    printf("\n");
}


decompiled_code:
int __fastcall print_fu(__int64 a1)
{
printf("FU");
if ( !(unsigned int)emptyp(*(_QWORD *)(a1 + 24)) )
putchar(10);
printform_prioritylist(*(__int64 **)(a1 + 24));
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func11(__int64 a1)
{
printf("FU");
if ( !(unsigned int)emptyp(*(_QWORD *)(a1 + 24)) )
putchar(10);
func5(*(__int64 **)(a1 + 24));
return putchar(10);
}

original_code:
void print_fu(TBase * base) {
    printf("FU");
    if(!emptyp(base->FU))
        printf("\n");
    printform_prioritylist(base->FU);
    printf("\n");
}

canonical_original_code:
void print_fu(struct base *base) {
    printf("FU");
    if(!emptyp(base->FU))
        printf("\n");
    printform_prioritylist(base->FU);
    printf("\n");
}


freebase

decompiled_code:
__int64 __fastcall freebase(_QWORD *a1)
{
dropq(a1[2]);
dropq(a1[5]);
dropq(a1[4]);
dropp(a1[3]);
return releaseu(a1[1]);
}

canonical_decompiled_code:
__int64 __fastcall func12(_QWORD *a1)
{
dropq(a1[2]);
dropq(a1[5]);
dropq(a1[4]);
dropp(a1[3]);
return releaseu(a1[1]);
}

original_code:
void freebase(TBase * base){
    dropq(base->FE);
    dropq(base->FPSO);
    dropq(base->FTR);
    dropp(base->FU);
    releaseu(base->users);
}

canonical_original_code:
void freebase(struct base *base){
    dropq(base->FE);
    dropq(base->FPSO);
    dropq(base->FTR);
    dropp(base->FU);
    releaseu(base->users);
}


newtask

decompiled_code:
__int64 __fastcall newtask(__int64 a1, __int64 a2, int a3, const char *a4)
{
__int64 v6; // r12
int v7; // esi
unsigned int *v8; // rbp

v6 = adduser(*(_QWORD *)(a1 + 8));
v7 = (*(_DWORD *)a1)++;
v8 = (unsigned int *)createtask(v6, v7, a3, a4);
waitingfor((__int64)v8);
push(*(_QWORD *)(a1 + 16), v8);
if ( !*(_QWORD *)(a1 + 8) )
*(_QWORD *)(a1 + 8) = v6;
return v8[2];
}

original_code:
int newtask(TBase * base, char * username, int priority, char * cmd){
  TUser * user = adduser(base->users,username);
  Task * newtask = _createtask(user,base->pid++,priority,cmd);
  _waitingfor(newtask);
  push(base->FE,newtask);
  if(!base->users)
      base->users = user;
  return newtask->pid;
}

canonical_original_code:
int newtask(struct base *base, char *username, int priority, char *cmd){
  struct user *user = adduser(base->users,username);
  struct task *newtask = _createtask(user,base->pid++,priority,cmd);
  _waitingfor(newtask);
  push(base->FE,newtask);
  if(!base->users)
      base->users = user;
  return newtask->pid;
}

variable_types:
username
char *

variable_types:
cmd
char *

return_type: int


execute

decompiled_code:
__int64 __fastcall execute(__int64 a1)
{
unsigned int v1; // ebp

v1 = system((const char *)(a1 + 16));
done((__int64 *)a1);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
unsigned int v1; // ebp

v1 = system((const char *)(a1 + 16));
func2((__int64 *)a1);
return v1;
}

original_code:
int execute(Task * task){
    int exec = system(task->cmd);
    _done(task);
    return exec;
}

canonical_original_code:
int execute(struct task *task){
    int exec = system(task->cmd);
    _done(task);
    return exec;
}

variable_types: exec int


sgn

repo: prinzhf/avprg

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

result = 1LL;
if ( a1 <= 0.0 )
result = (unsigned int)-(a1 < 0.0);
return result;
}

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

result = 1LL;
if ( a1 <= 0.0 )
result = (unsigned int)-(a1 < 0.0);
return result;
}

original_code:
int sgn(double x) {
   if (x > 0.0L)
     return 1.0L;
   else if (x < 0.0L)
     return -1.0L;
   else
     return 0.0L;
}

variable_types: x double


decompiled_code:
int sfx_init()
{
if ( (int)SDL_Init(16LL) < 0 )
{
puts("failed to initialize SDL Audio");
exit(1);
}
puts("SDL Audio sucessfully initialized");
if ( (int)Mix_OpenAudio(22050LL, 32784LL, 2LL, 512LL) < 0 )
puts("failed to Mix OpenAudio");
else
puts("successfully opened Audio");
if ( (int)Mix_AllocateChannels(5LL) < 0 )
{
puts("failed to allocate channel");
exit(1);
}
return puts("succesfully allocated 4 channels");
}

canonical_decompiled_code:
int func1()
{
if ( (int)SDL_Init(16LL) < 0 )
{
puts("failed to initialize SDL Audio");
exit(1);
}
puts("SDL Audio sucessfully initialized");
if ( (int)Mix_OpenAudio(22050LL, 32784LL, 2LL, 512LL) < 0 )
puts("failed to Mix OpenAudio");
else
puts("successfully opened Audio");
if ( (int)Mix_AllocateChannels(5LL) < 0 )
{
puts("failed to allocate channel");
exit(1);
}
return puts("succesfully allocated 4 channels");
}

original_code:
void sfx_init() {
 if(SDL_Init(0x00000010) < 0) {
  printf("failed to initialize SDL Audio\n");
  exit(1);
 } else {
  printf("SDL Audio sucessfully initialized\n");
 }
 if(Mix_OpenAudio(22050, 0x8010, 2, 512) < 0) {
  printf("failed to Mix OpenAudio\n");
 } else {
  printf("successfully opened Audio\n");
 }
 int channels = Mix_AllocateChannels(5);
 if(channels < 0) {
  printf("failed to allocate channel\n");
  exit(1);
 } else {
  printf("succesfully allocated 4 channels\n");
 }
}

variable_types: channels int


resetChannels

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

result = Mix_HaltChannel(0xFFFFFFFFLL);
songpos = 0;
return result;
}

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

result = Mix_HaltChannel(0xFFFFFFFFLL);
songpos = 0;
return result;
}

original_code:
void resetChannels() {
 Mix_HaltChannel(-1);
 songpos = 0;
}


setPan

decompiled_code:
int __fastcall setPan(__int64 a1)
{
__int64 i; // rbx
int result; // eax
float v3; // xmm0_4
const char *v4; // rax

for ( i = 0LL; i != 4; ++i )
{
v3 = *(float *)(a1 + i * 4);
if ( v3 < 0.0 && v3 >= -1.0 )
{
result = Mix_SetPanning(
(unsigned int)channels[i],
(unsigned __int8)(int)(float)(COERCE_FLOAT(LODWORD(v3) ^ LC11) * 255.0),
(unsigned __int8)(int)(float)((float)(v3 + 1.0) * 255.0));
if ( result )
continue;
LABEL_4:
v4 = (const char *)SDL_GetError();
result = printf("Mix_SetPanning: %s\n", v4);
continue;
}
if ( v3 > 0.0 && v3 <= 1.0 )
{
result = Mix_SetPanning(
(unsigned int)channels[i],
(unsigned __int8)(int)(float)((float)(1.0 - v3) * 255.0),
(unsigned __int8)(int)(float)(v3 * 255.0));
if ( !result )
goto LABEL_4;
}
else
{
result = Mix_SetPanning((unsigned int)channels[i], 255LL, 255LL);
if ( !result )
goto LABEL_4;
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func4(__int64 a1)
{
__int64 i; // rbx
int result; // eax
float v3; // xmm0_4
const char *v4; // rax

for ( i = 0LL; i != 4; ++i )
{
v3 = *(float *)(a1 + i * 4);
if ( v3 < 0.0 && v3 >= -1.0 )
{
result = Mix_SetPanning(
(unsigned int)channels[i],
(unsigned __int8)(int)(float)(COERCE_FLOAT(LODWORD(v3) ^ LC11) * 255.0),
(unsigned __int8)(int)(float)((float)(v3 + 1.0) * 255.0));
if ( result )
continue;
LABEL_4:
v4 = (const char *)SDL_GetError();
result = printf("Mix_SetPanning: %s\n", v4);
continue;
}
if ( v3 > 0.0 && v3 <= 1.0 )
{
result = Mix_SetPanning(
(unsigned int)channels[i],
(unsigned __int8)(int)(float)((float)(1.0 - v3) * 255.0),
(unsigned __int8)(int)(float)(v3 * 255.0));
if ( !result )
goto LABEL_4;
}
else
{
result = Mix_SetPanning((unsigned int)channels[i], 255LL, 255LL);
if ( !result )
goto LABEL_4;
}
}
return result;
}

original_code:
void setPan(float* pans) {
 int i;
 for(i = 0; i < 4; i++) {
  if(pans[i] < 0.0 && pans[i] >= -1.0) {
   if(!Mix_SetPanning(channels[i], (int)(255*(pans[i]*(-1))), (int)(255*(1-(pans[i]*(-1)))))) {
       printf("Mix_SetPanning: %s\n", SDL_GetError());
      }
     } else if(pans[i] > 0.0 && pans[i] <= 1.0){
      if(!Mix_SetPanning(channels[i], (int) (255*(1-pans[i])), 255*pans[i])) {
       printf("Mix_SetPanning: %s\n", SDL_GetError());
      }
     } else {
      if(!Mix_SetPanning(channels[i], 255, 255)) {
       printf("Mix_SetPanning: %s\n", SDL_GetError());
      }
     }
 }
}

canonical_original_code:
void setPan(float *pans) {
 int i;
 for(i = 0; i < 4; i++) {
  if(pans[i] < 0.0 && pans[i] >= -1.0) {
   if(!Mix_SetPanning(channels[i], (int)(255*(pans[i]*(-1))), (int)(255*(1-(pans[i]*(-1)))))) {
       printf("Mix_SetPanning: %s\n", SDL_GetError());
      }
     } else if(pans[i] > 0.0 && pans[i] <= 1.0){
      if(!Mix_SetPanning(channels[i], (int) (255*(1-pans[i])), 255*pans[i])) {
       printf("Mix_SetPanning: %s\n", SDL_GetError());
      }
     } else {
      if(!Mix_SetPanning(channels[i], 255, 255)) {
       printf("Mix_SetPanning: %s\n", SDL_GetError());
      }
     }
 }
}

variable_types:
pans
float *

variable_types: i int


handleADSR

decompiled_code:
float __fastcall handleADSR(int a1, int a2, unsigned int a3, float a4, float a5, __int64 a6, __int64 a7, unsigned int a8)
{
float result; // xmm0_4
int v10; // eax
int v11; // eax
float v12; // xmm1_4
float v13; // xmm0_4

result = a5;
if ( a3 != 1 || a8 != 1 )
{
if ( !a1 )
a4 = *(float *)&LC13;
if ( a3 > 1 && a5 >= a4 && (v10 = *(_DWORD *)(chunks[a2] + 16) / a3, v10 >= a1) )
{
v13 = (double)v10 * 0.00000001;
result = v13 + a4;
}
else if ( a8 > 1 )
{
v11 = *(_DWORD *)(chunks[a2] + 16) / a8;
if ( v11 < (unsigned int)a1 )
{
v12 = (double)v11 * 0.00000001;
result = a4 - v12;
}
}
}
return result;
}

canonical_decompiled_code:
float __fastcall func5(int a1, int a2, unsigned int a3, float a4, float a5, __int64 a6, __int64 a7, unsigned int a8)
{
float result; // xmm0_4
int v10; // eax
int v11; // eax
float v12; // xmm1_4
float v13; // xmm0_4

result = a5;
if ( a3 != 1 || a8 != 1 )
{
if ( !a1 )
a4 = *(float *)&LC13;
if ( a3 > 1 && a5 >= a4 && (v10 = *(_DWORD *)(chunks[a2] + 16) / a3, v10 >= a1) )
{
v13 = (double)v10 * 0.00000001;
result = v13 + a4;
}
else if ( a8 > 1 )
{
v11 = *(_DWORD *)(chunks[a2] + 16) / a8;
if ( v11 < (unsigned int)a1 )
{
v12 = (double)v11 * 0.00000001;
result = a4 - v12;
}
}
}
return result;
}

original_code:
float handleADSR(int i, int num, float amp, float finalAmp, int atc, int dec, int sus, int rel) {
 if(atc == 1 && rel == 1)
  return finalAmp;
 if(i == 0)
  amp = 0.001f;
 float adsr = 0.0f;
 if(atc != 1 && atc != 0 && amp <= finalAmp && i <= (int)(chunks[num]->alen/atc)) {
  amp += (float)((chunks[num]->alen/atc)*0.00000001);
  return amp;
 } else if(rel != 1 && rel != 0 && i > (chunks[num]->alen/rel)) {
  amp -= (float)((chunks[num]->alen/rel)*0.00000001);
  return amp;
 } else {
   return finalAmp;
 }
}

variable_types: num int

variable_types: amp float

variable_types: finalAmp float

variable_types: atc int

variable_types: dec int

variable_types: sus int

variable_types: rel int

variable_types: adsr float

return_type: float


generateSineChunk

decompiled_code:
char *__fastcall generateSineChunk(int a1, unsigned int a2, float a3, float a4, __int64 a5, unsigned int a6)
{
unsigned int v6; // er15
unsigned int v7; // er14
__int64 i; // rbx
float v10; // [rsp+Ch] [rbp-4Ch]
double v11; // [rsp+10h] [rbp-48h]

v6 = rels[a1];
v7 = decs[a1];
v11 = a3 * 6.283185307179586;
v10 = a4;
for ( i = 0LL; i != 44100; ++i )
{
v10 = handleADSR(i, a1, a2, v10, a4, v7, a6, v6);
streams[176400 * a1 + i] = (int)((float)(32767.0 * v10) * sin((double)(int)i * v11 / 44100.0));
}
return (char *)&streams[176400 * a1];
}

canonical_decompiled_code:
char *__fastcall func6(int a1, unsigned int a2, float a3, float a4, __int64 a5, unsigned int a6)
{
unsigned int v6; // er15
unsigned int v7; // er14
__int64 i; // rbx
float v10; // [rsp+Ch] [rbp-4Ch]
double v11; // [rsp+10h] [rbp-48h]

v6 = rels[a1];
v7 = decs[a1];
v11 = a3 * 6.283185307179586;
v10 = a4;
for ( i = 0LL; i != 44100; ++i )
{
v10 = func5(i, a1, a2, v10, a4, v7, a6, v6);
streams[176400 * a1 + i] = (int)((float)(32767.0 * v10) * sin((double)(int)i * v11 / 44100.0));
}
return (char *)&streams[176400 * a1];
}

original_code:
Uint8* generateSineChunk(float freq, int num, float amp, int atc, int rel, int sus, int dec) {
 int i;
 double generated;
 float finalAmp = amp;
 for(i = 0; i < 44100; i++) {
  amp = handleADSR(i, num, amp, finalAmp, atc, decs[num], sus, rels[num]);
  generated = (32767*amp)*sin((3.14159265358979323846*2.0)*freq*i/44100);
  ((Sint16*) streams[num])[i] = ((Sint16) generated);
 }
 return (Uint8*) streams[num];
}

canonical_original_code:
unsigned char *generateSineChunk(float freq, int num, float amp, int atc, int rel, int sus, int dec) {
 int i;
 double generated;
 float finalAmp = amp;
 for(i = 0; i < 44100; i++) {
  amp = handleADSR(i, num, amp, finalAmp, atc, decs[num], sus, rels[num]);
  generated = (32767*amp)*sin((3.14159265358979323846*2.0)*freq*i/44100);
  ((short *) streams[num])[i] = ((short) generated);
 }
 return (unsigned char *) streams[num];
}

variable_types: freq float

variable_types: generated double

return_type: unsigned char *


playChannels

decompiled_code:
__int64 __fastcall playChannels(__int64 a1, __int64 a2, __int64 a3)
{
__int64 i; // rbx
__int64 v5; // r14
int v6; // eax
__int64 result; // rax
float v8; // xmm0_4
__int64 v9; // r14
__int64 v10; // r14
__int64 v11; // r14
__int64 v12; // r14

setPan((__int64)&pans);
for ( i = 0LL; i != 4; ++i )
{
v8 = *(float *)(a1 + 4 * i);
if ( v8 == -1.0 )
{
result = Mix_ExpireChannel((unsigned int)channels[i], 0xFFFFFFFFLL);
}
else
{
switch ( *(_DWORD *)(a3 + 4 * i) )
{
case 1:
v5 = chunks[i];
*(_QWORD *)(v5 + 8) = generateSineChunk(
i,
atcs[i],
v8,
*(float *)(a2 + 4 * i),
(unsigned int)rels[i],
suss[i]);
break;
case 3:
v10 = chunks[i];
*(_QWORD *)(v10 + 8) = generateTriangleChunk(
i,
atcs[i],
rels[i],
suss[i],
decs[i],
v8,
*(float *)(a2 + 4 * i));
break;
case 4:
v11 = chunks[i];
*(_QWORD *)(v11 + 8) = generateSawChunk(i, atcs[i], rels[i], suss[i], decs[i], v8, *(float *)(a2 + 4 * i));
break;
case 5:
v12 = chunks[i];
*(_QWORD *)(v12 + 8) = generateNoiseChunk(i, atcs[i], rels[i], suss[i], decs[i], v8, *(float *)(a2 + 4 * i));
break;
default:
v9 = chunks[i];
*(_QWORD *)(v9 + 8) = generateSquareChunk(i, atcs[i], rels[i], suss[i], decs[i], v8, *(float *)(a2 + 4 * i));
break;
}
v6 = suss[i];
if ( v6 == 1 )
*(_DWORD *)(chunks[i] + 16) = 44100;
else
*(_DWORD *)(chunks[i] + 16) = v6 << 12;
result = Mix_PlayChannelTimed((unsigned int)channels[i], chunks[i], 0LL, 0xFFFFFFFFLL);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2, __int64 a3)
{
__int64 i; // rbx
__int64 v5; // r14
int v6; // eax
__int64 result; // rax
float v8; // xmm0_4
__int64 v9; // r14
__int64 v10; // r14
__int64 v11; // r14
__int64 v12; // r14

func4((__int64)&pans);
for ( i = 0LL; i != 4; ++i )
{
v8 = *(float *)(a1 + 4 * i);
if ( v8 == -1.0 )
{
result = Mix_ExpireChannel((unsigned int)channels[i], 0xFFFFFFFFLL);
}
else
{
switch ( *(_DWORD *)(a3 + 4 * i) )
{
case 1:
v5 = chunks[i];
*(_QWORD *)(v5 + 8) = func6(
i,
atcs[i],
v8,
*(float *)(a2 + 4 * i),
(unsigned int)rels[i],
suss[i]);
break;
case 3:
v10 = chunks[i];
*(_QWORD *)(v10 + 8) = generateTriangleChunk(
i,
atcs[i],
rels[i],
suss[i],
decs[i],
v8,
*(float *)(a2 + 4 * i));
break;
case 4:
v11 = chunks[i];
*(_QWORD *)(v11 + 8) = generateSawChunk(i, atcs[i], rels[i], suss[i], decs[i], v8, *(float *)(a2 + 4 * i));
break;
case 5:
v12 = chunks[i];
*(_QWORD *)(v12 + 8) = generateNoiseChunk(i, atcs[i], rels[i], suss[i], decs[i], v8, *(float *)(a2 + 4 * i));
break;
default:
v9 = chunks[i];
*(_QWORD *)(v9 + 8) = generateSquareChunk(i, atcs[i], rels[i], suss[i], decs[i], v8, *(float *)(a2 + 4 * i));
break;
}
v6 = suss[i];
if ( v6 == 1 )
*(_DWORD *)(chunks[i] + 16) = 44100;
else
*(_DWORD *)(chunks[i] + 16) = v6 << 12;
result = Mix_PlayChannelTimed((unsigned int)channels[i], chunks[i], 0LL, 0xFFFFFFFFLL);
}
}
return result;
}

original_code:
void playChannels(float* freqs, float* amps, int* waveforms, CHANNEL* chan) {
 int i;
 setPan(pans);
 for(i = 0; i < 4; i++){
  if(freqs[i] != -1.0) {
   switch(waveforms[i]) {
    case 1: chunks[i]->abuf = generateSineChunk(freqs[i], i, amps[i], atcs[i], rels[i], suss[i], decs[i]); break;
    case 2: chunks[i]->abuf = generateSquareChunk(freqs[i], i, amps[i], atcs[i], rels[i], suss[i], decs[i]); break;
    case 3: chunks[i]->abuf = generateTriangleChunk(freqs[i], i, amps[i], atcs[i], rels[i], suss[i], decs[i]); break;
    case 4: chunks[i]->abuf = generateSawChunk(freqs[i], i, amps[i], atcs[i], rels[i], suss[i], decs[i]); break;
    case 5: chunks[i]->abuf = generateNoiseChunk(freqs[i], i, amps[i], atcs[i], rels[i], suss[i], decs[i]); break;
    default: chunks[i]->abuf = generateSquareChunk(freqs[i], i, amps[i], atcs[i], rels[i], suss[i], decs[i]); break;
   }
   if(suss[i] != 1)
    chunks[i]->alen = (4096*suss[i]);
   else
    chunks[i]->alen = 44100;
   Mix_PlayChannelTimed(channels[i],chunks[i],0,-1);
  } else {
   Mix_ExpireChannel(channels[i], -1);
  }
 }
}

canonical_original_code:
void playChannels(float *freqs, float *amps, int *waveforms, struct channel *chan) {
 int i;
 setPan(pans);
 for(i = 0; i < 4; i++){
  if(freqs[i] != -1.0) {
   switch(waveforms[i]) {
    case 1: chunks[i]->abuf = generateSineChunk(freqs[i], i, amps[i], atcs[i], rels[i], suss[i], decs[i]); break;
    case 2: chunks[i]->abuf = generateSquareChunk(freqs[i], i, amps[i], atcs[i], rels[i], suss[i], decs[i]); break;
    case 3: chunks[i]->abuf = generateTriangleChunk(freqs[i], i, amps[i], atcs[i], rels[i], suss[i], decs[i]); break;
    case 4: chunks[i]->abuf = generateSawChunk(freqs[i], i, amps[i], atcs[i], rels[i], suss[i], decs[i]); break;
    case 5: chunks[i]->abuf = generateNoiseChunk(freqs[i], i, amps[i], atcs[i], rels[i], suss[i], decs[i]); break;
    default: chunks[i]->abuf = generateSquareChunk(freqs[i], i, amps[i], atcs[i], rels[i], suss[i], decs[i]); break;
   }
   if(suss[i] != 1)
    chunks[i]->alen = (4096*suss[i]);
   else
    chunks[i]->alen = 44100;
   Mix_PlayChannelTimed(channels[i],chunks[i],0,-1);
  } else {
   Mix_ExpireChannel(channels[i], -1);
  }
 }
}

variable_types:
freqs
float *

variable_types:
amps
float *

variable_types:
waveforms
int *

variable_types: struct channel { unsigned char line; int tempo; char name[128]; char description[128]; struct channel_values { unsigned int waveform; float amp; float pan; char tone[3]; float freq; int atc; int dec; int sus; int rel; char wholeChan[128]; } *chanval[4]; int lines; } *

user_defined_types: struct channel { unsigned char line; int tempo; char name[128]; char description[128]; struct channel_values *chanval[4]; int lines; }


timerCallback

decompiled_code:
__int64 __fastcall timerCallback(unsigned int a1)
{
__int64 v2; // rcx
__int64 v3; // rdi
unsigned __int64 i; // rax
int *v5; // rdx

v2 = chan;
if ( *(_DWORD *)(chan + 296) <= songpos )
songpos = 0;
v3 = 164LL * songpos;
for ( i = 0LL; i != 16; i += 4LL )
{
v5 = (int *)(*(_QWORD *)(v2 + 2 * i + 264) + v3);
freqs[i / 4] = v5[4];
amps[i / 4] = v5[1];
waveforms[i / 4] = *v5;
pans[i / 4] = v5[2];
atcs[i / 4] = v5[5];
suss[i / 4] = v5[7];
rels[i / 4] = v5[8];
decs[i / 4] = v5[6];
}
playChannels((__int64)freqs, (__int64)amps, (__int64)waveforms);
++songpos;
moveSong(window, chan);
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int a1)
{
__int64 v2; // rcx
__int64 v3; // rdi
unsigned __int64 i; // rax
int *v5; // rdx

v2 = chan;
if ( *(_DWORD *)(chan + 296) <= songpos )
songpos = 0;
v3 = 164LL * songpos;
for ( i = 0LL; i != 16; i += 4LL )
{
v5 = (int *)(*(_QWORD *)(v2 + 2 * i + 264) + v3);
freqs[i / 4] = v5[4];
amps[i / 4] = v5[1];
waveforms[i / 4] = *v5;
pans[i / 4] = v5[2];
atcs[i / 4] = v5[5];
suss[i / 4] = v5[7];
rels[i / 4] = v5[8];
decs[i / 4] = v5[6];
}
func7((__int64)freqs, (__int64)amps, (__int64)waveforms);
++songpos;
moveSong(window, chan);
return a1;
}

original_code:
Uint32 timerCallback(Uint32 intervall, void *parameter) {
 int i;
 if(songpos >= chan->lines)
  songpos = 0;
 for(i = 0; i < 4; i++) {
  freqs[i] = chan->chanval[i][songpos].freq;
  amps[i] = chan->chanval[i][songpos].amp;
  waveforms[i] = chan->chanval[i][songpos].waveform;
  pans[i] = chan->chanval[i][songpos].pan;
  atcs[i] = chan->chanval[i][songpos].atc;
  suss[i] = chan->chanval[i][songpos].sus;
  rels[i] = chan->chanval[i][songpos].rel;
  decs[i] = chan->chanval[i][songpos].dec;
 }
 playChannels(freqs, amps, waveforms, chan);
 songpos++;
 moveSong(window, chan, songpos);
 return intervall;
}

canonical_original_code:
unsigned int timerCallback(unsigned int intervall, void *parameter) {
 int i;
 if(songpos >= chan->lines)
  songpos = 0;
 for(i = 0; i < 4; i++) {
  freqs[i] = chan->chanval[i][songpos].freq;
  amps[i] = chan->chanval[i][songpos].amp;
  waveforms[i] = chan->chanval[i][songpos].waveform;
  pans[i] = chan->chanval[i][songpos].pan;
  atcs[i] = chan->chanval[i][songpos].atc;
  suss[i] = chan->chanval[i][songpos].sus;
  rels[i] = chan->chanval[i][songpos].rel;
  decs[i] = chan->chanval[i][songpos].dec;
 }
 playChannels(freqs, amps, waveforms, chan);
 songpos++;
 moveSong(window, chan, songpos);
 return intervall;
}

variable_types:
intervall
unsigned int

variable_types:
parameter
void *

return_type: unsigned int


getNoteFrequency

decompiled_code:
float __fastcall getNoteFrequency(char *s2)
{
__int64 v2; // rbx
const char *v3; // rdi

v2 = 0LL;
v3 = "c-2";
while ( strcmp(v3, s2) )
{
v3 = namedNotes[++v2];
if ( !v3 )
return 0.0;
}
return frequencedNotes[(int)v2];
}

canonical_decompiled_code:
float __fastcall func0(char *s2)
{
__int64 v2; // rbx
const char *v3; // rdi

v2 = 0LL;
v3 = "c-2";
while ( strcmp(v3, s2) )
{
v3 = namedNotes[++v2];
if ( !v3 )
return 0.0;
}
return frequencedNotes[(int)v2];
}

original_code:
float getNoteFrequency(char noteName[]) {
     int i;
     float frequency = 0.0;
     for(i = 0; namedNotes[i]; i++) {
             if(strcmp(namedNotes[i], noteName) == 0) {
             frequency = frequencedNotes[i];
             return frequency;
         }
     }
     return 0.0;
}

variable_types:
noteName
char []

variable_types: i int

variable_types: frequency float


nrerror

repo: prjemian/lake

decompiled_code:
void __fastcall __noreturn nrerror(const char *a1)
{
fwrite("Numerical Recipes run-time error...\n", 1uLL, 0x24uLL, stderr);
fprintf(stderr, "%s\n", a1);
fwrite("...now exiting to system...\n", 1uLL, 0x1CuLL, stderr);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(const char *a1)
{
fwrite("Numerical Recipes run-time error...\n", 1uLL, 0x24uLL, stderr);
fprintf(stderr, "%s\n", a1);
fwrite("...now exiting to system...\n", 1uLL, 0x1CuLL, stderr);
exit(1);
}

original_code:
void nrerror(char error_text[])
{
    fprintf(stderr,"Numerical Recipes run-time error...\n");
    fprintf(stderr,"%s\n",error_text);
    fprintf(stderr,"...now exiting to system...\n");
    exit(1);
}


vector

decompiled_code:
char *__fastcall vector(__int64 a1, __int64 a2)
{
char *v2; // rax

v2 = (char *)malloc(4 * (a2 - a1) + 8);
if ( !v2 )
nrerror("allocation failure in vector()");
return &v2[4 * (1 - a1)];
}

canonical_decompiled_code:
char *__fastcall func1(__int64 a1, __int64 a2)
{
char *v2; // rax

v2 = (char *)malloc(4 * (a2 - a1) + 8);
if ( !v2 )
func0("allocation failure in vector()");
return &v2[4 * (1 - a1)];
}

original_code:
float *vector(long nl, long nh)
{
    float *v;
    v=(float *)malloc((size_t) ((nh-nl+1+1)*sizeof(float)));
    if (!v) nrerror("allocation failure in vector()");
    return v-nl+1;
}

canonical_original_code:
float *vector(long nl, long nh)
{
    float *v;
    v=(float *)malloc((unsigned long) ((nh-nl+1+1)*sizeof(float)));
    if (!v) nrerror("allocation failure in vector()");
    return v-nl+1;
}

variable_types: nl long

variable_types: nh long

variable_types:
v
float *

return_type: float *


ivector

decompiled_code:
char *__fastcall ivector(__int64 a1, __int64 a2)
{
char *v2; // rax

v2 = (char *)malloc(4 * (a2 - a1) + 8);
if ( !v2 )
nrerror("allocation failure in ivector()");
return &v2[4 * (1 - a1)];
}

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

v2 = (char *)malloc(4 * (a2 - a1) + 8);
if ( !v2 )
func0("allocation failure in ivector()");
return &v2[4 * (1 - a1)];
}

original_code:
int *ivector(long nl, long nh)
{
    int *v;
    v=(int *)malloc((size_t) ((nh-nl+1+1)*sizeof(int)));
    if (!v) nrerror("allocation failure in ivector()");
    return v-nl+1;
}

canonical_original_code:
int *ivector(long nl, long nh)
{
    int *v;
    v=(int *)malloc((unsigned long) ((nh-nl+1+1)*sizeof(int)));
    if (!v) nrerror("allocation failure in ivector()");
    return v-nl+1;
}

variable_types:
v
int *

return_type: int *


cvector

decompiled_code:
__int64 __fastcall cvector(__int64 a1, __int64 a2)
{
void *v2; // rax

v2 = malloc(a2 - a1 + 2);
if ( !v2 )
nrerror("allocation failure in cvector()");
return (__int64)v2 - a1 + 1;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
void *v2; // rax

v2 = malloc(a2 - a1 + 2);
if ( !v2 )
func0("allocation failure in cvector()");
return (__int64)v2 - a1 + 1;
}

original_code:
unsigned char *cvector(long nl, long nh)
{
    unsigned char *v;
    v=(unsigned char *)malloc((size_t) ((nh-nl+1+1)*sizeof(unsigned char)));
    if (!v) nrerror("allocation failure in cvector()");
    return v-nl+1;
}

canonical_original_code:
unsigned char *cvector(long nl, long nh)
{
    unsigned char *v;
    v=(unsigned char *)malloc((unsigned long) ((nh-nl+1+1)*sizeof(unsigned char)));
    if (!v) nrerror("allocation failure in cvector()");
    return v-nl+1;
}

variable_types:
v
unsigned char *


lvector

decompiled_code:
char *__fastcall lvector(__int64 a1, __int64 a2)
{
char *v2; // rax

v2 = (char *)malloc(8 * (a2 - a1) + 16);
if ( !v2 )
nrerror("allocation failure in lvector()");
return &v2[8 * (1 - a1)];
}

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

v2 = (char *)malloc(8 * (a2 - a1) + 16);
if ( !v2 )
func0("allocation failure in lvector()");
return &v2[8 * (1 - a1)];
}

original_code:
unsigned long *lvector(long nl, long nh)
{
    unsigned long *v;
    v=(unsigned long *)malloc((size_t) ((nh-nl+1+1)*sizeof(long)));
    if (!v) nrerror("allocation failure in lvector()");
    return v-nl+1;
}

canonical_original_code:
unsigned long *lvector(long nl, long nh)
{
    unsigned long *v;
    v=(unsigned long *)malloc((unsigned long) ((nh-nl+1+1)*sizeof(long)));
    if (!v) nrerror("allocation failure in lvector()");
    return v-nl+1;
}

variable_types:
v
unsigned long *

return_type: unsigned long *


dvector

decompiled_code:
char *__fastcall dvector(__int64 a1, __int64 a2)
{
char *v2; // rax

v2 = (char *)malloc(8 * (a2 - a1) + 16);
if ( !v2 )
nrerror("allocation failure in dvector()");
return &v2[8 * (1 - a1)];
}

canonical_decompiled_code:
char *__fastcall func5(__int64 a1, __int64 a2)
{
char *v2; // rax

v2 = (char *)malloc(8 * (a2 - a1) + 16);
if ( !v2 )
func0("allocation failure in dvector()");
return &v2[8 * (1 - a1)];
}

original_code:
double *dvector(long nl, long nh)
{
    double *v;
    v=(double *)malloc((size_t) ((nh-nl+1+1)*sizeof(double)));
    if (!v) nrerror("allocation failure in dvector()");
    return v-nl+1;
}

canonical_original_code:
double *dvector(long nl, long nh)
{
    double *v;
    v=(double *)malloc((unsigned long) ((nh-nl+1+1)*sizeof(double)));
    if (!v) nrerror("allocation failure in dvector()");
    return v-nl+1;
}

variable_types:
v
double *

return_type: double *


matrix

original_code:
float **matrix(long nrl, long nrh, long ncl, long nch)
{
    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
    float **m;
    m=(float **) malloc((size_t)((nrow+1)*sizeof(float*)));
    if (!m) nrerror("allocation failure 1 in matrix()");
    m += 1;
    m -= nrl;
    m[nrl]=(float *) malloc((size_t)((nrow*ncol+1)*sizeof(float)));
    if (!m[nrl]) nrerror("allocation failure 2 in matrix()");
    m[nrl] += 1;
    m[nrl] -= ncl;
    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
    return m;
}

canonical_original_code:
float **matrix(long nrl, long nrh, long ncl, long nch)
{
    long i; long nrow = nrh-nrl+1; long ncol = nch-ncl+1;
    float **m;
    m=(float **) malloc((unsigned long)((nrow+1)*sizeof(float *)));
    if (!m) nrerror("allocation failure 1 in matrix()");
    m += 1;
    m -= nrl;
    m[nrl]=(float *) malloc((unsigned long)((nrow*ncol+1)*sizeof(float)));
    if (!m[nrl]) nrerror("allocation failure 2 in matrix()");
    m[nrl] += 1;
    m[nrl] -= ncl;
    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
    return m;
}

variable_types: nrl long

variable_types: nrh long

variable_types: ncl long

variable_types: nch long

variable_types: i long

variable_types: nrow long

variable_types: ncol long

variable_types:
m
float **

return_type: float **


dmatrix

original_code:
double **dmatrix(long nrl, long nrh, long ncl, long nch)
{
    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
    double **m;
    m=(double **) malloc((size_t)((nrow+1)*sizeof(double*)));
    if (!m) nrerror("allocation failure 1 in matrix()");
    m += 1;
    m -= nrl;
    m[nrl]=(double *) malloc((size_t)((nrow*ncol+1)*sizeof(double)));
    if (!m[nrl]) nrerror("allocation failure 2 in matrix()");
    m[nrl] += 1;
    m[nrl] -= ncl;
    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
    return m;
}

canonical_original_code:
double **dmatrix(long nrl, long nrh, long ncl, long nch)
{
    long i; long nrow = nrh-nrl+1; long ncol = nch-ncl+1;
    double **m;
    m=(double **) malloc((unsigned long)((nrow+1)*sizeof(double *)));
    if (!m) nrerror("allocation failure 1 in matrix()");
    m += 1;
    m -= nrl;
    m[nrl]=(double *) malloc((unsigned long)((nrow*ncol+1)*sizeof(double)));
    if (!m[nrl]) nrerror("allocation failure 2 in matrix()");
    m[nrl] += 1;
    m[nrl] -= ncl;
    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
    return m;
}

variable_types:
m
double **

return_type: double **


imatrix

original_code:
int **imatrix(long nrl, long nrh, long ncl, long nch)
{
    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
    int **m;
    m=(int **) malloc((size_t)((nrow+1)*sizeof(int*)));
    if (!m) nrerror("allocation failure 1 in matrix()");
    m += 1;
    m -= nrl;
    m[nrl]=(int *) malloc((size_t)((nrow*ncol+1)*sizeof(int)));
    if (!m[nrl]) nrerror("allocation failure 2 in matrix()");
    m[nrl] += 1;
    m[nrl] -= ncl;
    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
    return m;
}

canonical_original_code:
int **imatrix(long nrl, long nrh, long ncl, long nch)
{
    long i; long nrow = nrh-nrl+1; long ncol = nch-ncl+1;
    int **m;
    m=(int **) malloc((unsigned long)((nrow+1)*sizeof(int *)));
    if (!m) nrerror("allocation failure 1 in matrix()");
    m += 1;
    m -= nrl;
    m[nrl]=(int *) malloc((unsigned long)((nrow*ncol+1)*sizeof(int)));
    if (!m[nrl]) nrerror("allocation failure 2 in matrix()");
    m[nrl] += 1;
    m[nrl] -= ncl;
    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
    return m;
}

variable_types:
m
int **

return_type: int **


submatrix

original_code:
float **submatrix(float **a, long oldrl, long oldrh, long oldcl, long oldch,
    long newrl, long newcl)
{
    long i,j,nrow=oldrh-oldrl+1,ncol=oldcl-newcl;
    float **m;
    m=(float **) malloc((size_t) ((nrow+1)*sizeof(float*)));
    if (!m) nrerror("allocation failure in submatrix()");
    m += 1;
    m -= newrl;
    for(i=oldrl,j=newrl;i<=oldrh;i++,j++) m[j]=a[i]+ncol;
    return m;
}

canonical_original_code:
float **submatrix(float **a, long oldrl, long oldrh, long oldcl, long oldch, long newrl, long newcl)
{
    long i; long j; long nrow = oldrh-oldrl+1; long ncol = oldcl-newcl;
    float **m;
    m=(float **) malloc((unsigned long) ((nrow+1)*sizeof(float *)));
    if (!m) nrerror("allocation failure in submatrix()");
    m += 1;
    m -= newrl;
    for(i=oldrl,j=newrl;i<=oldrh;i++,j++) m[j]=a[i]+ncol;
    return m;
}

variable_types:
a
float **

variable_types: oldrl long

variable_types: oldrh long

variable_types: oldcl long

variable_types: oldch long

variable_types: newrl long

variable_types: newcl long

variable_types: j long


original_code:
float **convert_matrix(float *a, long nrl, long nrh, long ncl, long nch)
{
    long i,j,nrow=nrh-nrl+1,ncol=nch-ncl+1;
    float **m;
    m=(float **) malloc((size_t) ((nrow+1)*sizeof(float*)));
    if (!m) nrerror("allocation failure in convert_matrix()");
    m += 1;
    m -= nrl;
    m[nrl]=a-ncl;
    for(i=1,j=nrl+1;i<nrow;i++,j++) m[j]=m[j-1]+ncol;
    return m;
}

canonical_original_code:
float **convert_matrix(float *a, long nrl, long nrh, long ncl, long nch)
{
    long i; long j; long nrow = nrh-nrl+1; long ncol = nch-ncl+1;
    float **m;
    m=(float **) malloc((unsigned long) ((nrow+1)*sizeof(float *)));
    if (!m) nrerror("allocation failure in convert_matrix()");
    m += 1;
    m -= nrl;
    m[nrl]=a-ncl;
    for(i=1,j=nrl+1;i<nrow;i++,j++) m[j]=m[j-1]+ncol;
    return m;
}

variable_types:
a
float *

variable_types: nrl long

variable_types: nrh long


original_code:
float ***f3tensor(long nrl, long nrh, long ncl, long nch, long ndl, long ndh)
{
    long i,j,nrow=nrh-nrl+1,ncol=nch-ncl+1,ndep=ndh-ndl+1;
    float ***t;
    t=(float ***) malloc((size_t)((nrow+1)*sizeof(float**)));
    if (!t) nrerror("allocation failure 1 in f3tensor()");
    t += 1;
    t -= nrl;
    t[nrl]=(float **) malloc((size_t)((nrow*ncol+1)*sizeof(float*)));
    if (!t[nrl]) nrerror("allocation failure 2 in f3tensor()");
    t[nrl] += 1;
    t[nrl] -= ncl;
    t[nrl][ncl]=(float *) malloc((size_t)((nrow*ncol*ndep+1)*sizeof(float)));
    if (!t[nrl][ncl]) nrerror("allocation failure 3 in f3tensor()");
    t[nrl][ncl] += 1;
    t[nrl][ncl] -= ndl;
    for(j=ncl+1;j<=nch;j++) t[nrl][j]=t[nrl][j-1]+ndep;
    for(i=nrl+1;i<=nrh;i++) {
        t[i]=t[i-1]+ncol;
        t[i][ncl]=t[i-1][ncl]+ncol*ndep;
        for(j=ncl+1;j<=nch;j++) t[i][j]=t[i][j-1]+ndep;
    }
    return t;
}

canonical_original_code:
float ***f3tensor(long nrl, long nrh, long ncl, long nch, long ndl, long ndh)
{
    long i; long j; long nrow = nrh-nrl+1; long ncol = nch-ncl+1; long ndep = ndh-ndl+1;
    float ***t;
    t=(float ***) malloc((unsigned long)((nrow+1)*sizeof(float **)));
    if (!t) nrerror("allocation failure 1 in f3tensor()");
    t += 1;
    t -= nrl;
    t[nrl]=(float **) malloc((unsigned long)((nrow*ncol+1)*sizeof(float *)));
    if (!t[nrl]) nrerror("allocation failure 2 in f3tensor()");
    t[nrl] += 1;
    t[nrl] -= ncl;
    t[nrl][ncl]=(float *) malloc((unsigned long)((nrow*ncol*ndep+1)*sizeof(float)));
    if (!t[nrl][ncl]) nrerror("allocation failure 3 in f3tensor()");
    t[nrl][ncl] += 1;
    t[nrl][ncl] -= ndl;
    for(j=ncl+1;j<=nch;j++) t[nrl][j]=t[nrl][j-1]+ndep;
    for(i=nrl+1;i<=nrh;i++) {
        t[i]=t[i-1]+ncol;
        t[i][ncl]=t[i-1][ncl]+ncol*ndep;
        for(j=ncl+1;j<=nch;j++) t[i][j]=t[i][j-1]+ndep;
    }
    return t;
}

variable_types: ncl long

variable_types: nch long

variable_types: ndl long

variable_types: ndh long

variable_types: i long

variable_types: ndep long

variable_types:
t
float ***

return_type: float ***


decompiled_code:
void __fastcall free_vector(__int64 a1, __int64 a2)
{
free((void *)(a1 + 4 * a2 - 4));
}

canonical_decompiled_code:
void __fastcall func12(__int64 a1, __int64 a2)
{
free((void *)(a1 + 4 * a2 - 4));
}

original_code:
void free_vector(float *v, long nl, long nh)
{
    free((char*) (v+nl-1));
}

canonical_original_code:
void free_vector(float *v, long nl, long nh)
{
    free((char *) (v+nl-1));
}

variable_types:
v
float *

variable_types: nl long

variable_types: nh long


decompiled_code:
void __fastcall free_ivector(__int64 a1, __int64 a2)
{
free((void *)(a1 + 4 * a2 - 4));
}

canonical_decompiled_code:
void __fastcall func13(__int64 a1, __int64 a2)
{
free((void *)(a1 + 4 * a2 - 4));
}

original_code:
void free_ivector(int *v, long nl, long nh)
{
    free((char*) (v+nl-1));
}

canonical_original_code:
void free_ivector(int *v, long nl, long nh)
{
    free((char *) (v+nl-1));
}

variable_types:
v
int *


decompiled_code:
void __fastcall free_cvector(__int64 a1, __int64 a2)
{
free((void *)(a1 + a2 - 1));
}

canonical_decompiled_code:
void __fastcall func14(__int64 a1, __int64 a2)
{
free((void *)(a1 + a2 - 1));
}

original_code:
void free_cvector(unsigned char *v, long nl, long nh)
{
    free((char*) (v+nl-1));
}

canonical_original_code:
void free_cvector(unsigned char *v, long nl, long nh)
{
    free((char *) (v+nl-1));
}

variable_types:
v
unsigned char *


decompiled_code:
void __fastcall free_lvector(__int64 a1, __int64 a2)
{
free((void *)(a1 + 8 * a2 - 8));
}

canonical_decompiled_code:
void __fastcall func15(__int64 a1, __int64 a2)
{
free((void *)(a1 + 8 * a2 - 8));
}

original_code:
void free_lvector(unsigned long *v, long nl, long nh)
{
    free((char*) (v+nl-1));
}

canonical_original_code:
void free_lvector(unsigned long *v, long nl, long nh)
{
    free((char *) (v+nl-1));
}

variable_types:
v
unsigned long *


decompiled_code:
void __fastcall free_dvector(__int64 a1, __int64 a2)
{
free((void *)(a1 + 8 * a2 - 8));
}

canonical_decompiled_code:
void __fastcall func16(__int64 a1, __int64 a2)
{
free((void *)(a1 + 8 * a2 - 8));
}

original_code:
void free_dvector(double *v, long nl, long nh)
{
    free((char*) (v+nl-1));
}

canonical_original_code:
void free_dvector(double *v, long nl, long nh)
{
    free((char *) (v+nl-1));
}

variable_types:
v
double *


original_code:
void free_matrix(float **m, long nrl, long nrh, long ncl, long nch)
{
    free((char*) (m[nrl]+ncl-1));
    free((char*) (m+nrl-1));
}

canonical_original_code:
void free_matrix(float **m, long nrl, long nrh, long ncl, long nch)
{
    free((char *) (m[nrl]+ncl-1));
    free((char *) (m+nrl-1));
}

variable_types:
m
float **


original_code:
void free_dmatrix(double **m, long nrl, long nrh, long ncl, long nch)
{
    free((char*) (m[nrl]+ncl-1));
    free((char*) (m+nrl-1));
}

canonical_original_code:
void free_dmatrix(double **m, long nrl, long nrh, long ncl, long nch)
{
    free((char *) (m[nrl]+ncl-1));
    free((char *) (m+nrl-1));
}

variable_types:
m
double **

variable_types: nrl long


original_code:
void free_imatrix(int **m, long nrl, long nrh, long ncl, long nch)
{
    free((char*) (m[nrl]+ncl-1));
    free((char*) (m+nrl-1));
}

canonical_original_code:
void free_imatrix(int **m, long nrl, long nrh, long ncl, long nch)
{
    free((char *) (m[nrl]+ncl-1));
    free((char *) (m+nrl-1));
}

variable_types:
m
int **

variable_types: nrh long

variable_types: ncl long


decompiled_code:
void __fastcall free_submatrix(__int64 a1, __int64 a2)
{
free((void *)(a1 + 8 * a2 - 8));
}

canonical_decompiled_code:
void __fastcall func20(__int64 a1, __int64 a2)
{
free((void *)(a1 + 8 * a2 - 8));
}

original_code:
void free_submatrix(float **b, long nrl, long nrh, long ncl, long nch)
{
    free((char*) (b+nrl-1));
}

canonical_original_code:
void free_submatrix(float **b, long nrl, long nrh, long ncl, long nch)
{
    free((char *) (b+nrl-1));
}

variable_types:
b
float **

variable_types: nch long


decompiled_code:
void __fastcall free_convert_matrix(__int64 a1, __int64 a2)
{
free((void *)(a1 + 8 * a2 - 8));
}

canonical_decompiled_code:
void __fastcall func21(__int64 a1, __int64 a2)
{
free((void *)(a1 + 8 * a2 - 8));
}

original_code:
void free_convert_matrix(float **b, long nrl, long nrh, long ncl, long nch)
{
    free((char*) (b+nrl-1));
}

canonical_original_code:
void free_convert_matrix(float **b, long nrl, long nrh, long ncl, long nch)
{
    free((char *) (b+nrl-1));
}


original_code:
void free_f3tensor(float ***t, long nrl, long nrh, long ncl, long nch,
    long ndl, long ndh)
{
    free((char*) (t[nrl][ncl]+ndl-1));
    free((char*) (t[nrl]+ncl-1));
    free((char*) (t+nrl-1));
}

canonical_original_code:
void free_f3tensor(float ***t, long nrl, long nrh, long ncl, long nch, long ndl, long ndh)
{
    free((char *) (t[nrl][ncl]+ndl-1));
    free((char *) (t[nrl]+ncl-1));
    free((char *) (t+nrl-1));
}

variable_types: ndl long

variable_types: ndh long


SumClr

decompiled_code:
void SumClr()
{
sum_weight = 0LL;
sum_x = 0LL;
sum_x2 = 0LL;
sum_y = 0LL;
sum_y2 = 0LL;
sum_xy = 0LL;
}

canonical_decompiled_code:
void func0()
{
sum_weight = 0LL;
sum_x = 0LL;
sum_x2 = 0LL;
sum_y = 0LL;
sum_y2 = 0LL;
sum_xy = 0LL;
}


SwtAdd

decompiled_code:
void __fastcall SwtAdd(double a1, double a2, double a3)
{
double v3; // xmm3_8
double v4; // xmm0_8
double v5; // xmm1_8

v3 = 1.0 / (a3 * a3);
v4 = a1 * v3;
v5 = a2 * v3;
*(double *)&sum_weight = v3 + *(double *)&sum_weight;
*(double *)&sum_x = v4 + *(double *)&sum_x;
*(double *)&sum_x2 = v4 * v4 + *(double *)&sum_x2;
*(double *)&sum_y = v5 + *(double *)&sum_y;
*(double *)&sum_y2 = v5 * v5 + *(double *)&sum_y2;
*(double *)&sum_xy = v4 * v5 + *(double *)&sum_xy;
}

canonical_decompiled_code:
void __fastcall func1(double a1, double a2, double a3)
{
double v3; // xmm3_8
double v4; // xmm0_8
double v5; // xmm1_8

v3 = 1.0 / (a3 * a3);
v4 = a1 * v3;
v5 = a2 * v3;
*(double *)&sum_weight = v3 + *(double *)&sum_weight;
*(double *)&sum_x = v4 + *(double *)&sum_x;
*(double *)&sum_x2 = v4 * v4 + *(double *)&sum_x2;
*(double *)&sum_y = v5 + *(double *)&sum_y;
*(double *)&sum_y2 = v5 * v5 + *(double *)&sum_y2;
*(double *)&sum_xy = v4 * v5 + *(double *)&sum_xy;
}

original_code:
void SwtAdd (double x, double y, double z)
{
    double weight = 1/(z*z);
    double xWt = x * weight;
    double yWt = y * weight;
    sum_weight += weight;
    sum_x += xWt;
    sum_x2 += xWt*xWt;
    sum_y += yWt;
    sum_y2 += yWt*yWt;
    sum_xy += xWt*yWt;
}

canonical_original_code:
void SwtAdd(double x, double y, double z)
{
    double weight = 1/(z*z);
    double xWt = x * weight;
    double yWt = y * weight;
    sum_weight += weight;
    sum_x += xWt;
    sum_x2 += xWt*xWt;
    sum_y += yWt;
    sum_y2 += yWt*yWt;
    sum_xy += xWt*yWt;
}

variable_types: x double

variable_types: y double

variable_types: z double

variable_types: weight double

variable_types: xWt double

variable_types: yWt double


SumAdd

decompiled_code:
void __fastcall SumAdd(double a1, double a2)
{
SwtAdd(a1, a2, 1.0);
}

canonical_decompiled_code:
void __fastcall func2(double a1, double a2)
{
func1(a1, a2, 1.0);
}

original_code:
void SumAdd (double x, double y)
{
    SwtAdd (x, y, (double) 1.0);
}

canonical_original_code:
void SumAdd(double x, double y)
{
    SwtAdd (x, y, (double) 1.0);
}


SwtSub

decompiled_code:
void __fastcall SwtSub(double a1, double a2, double a3)
{
double v3; // xmm3_8
double v4; // xmm0_8
double v5; // xmm1_8

v3 = 1.0 / (a3 * a3);
v4 = a1 * v3;
v5 = a2 * v3;
*(double *)&sum_weight = *(double *)&sum_weight - v3;
*(double *)&sum_x = *(double *)&sum_x - v4;
*(double *)&sum_x2 = *(double *)&sum_x2 - v4 * v4;
*(double *)&sum_y = *(double *)&sum_y - v5;
*(double *)&sum_y2 = *(double *)&sum_y2 - v5 * v5;
*(double *)&sum_xy = *(double *)&sum_xy - v4 * v5;
}

canonical_decompiled_code:
void __fastcall func3(double a1, double a2, double a3)
{
double v3; // xmm3_8
double v4; // xmm0_8
double v5; // xmm1_8

v3 = 1.0 / (a3 * a3);
v4 = a1 * v3;
v5 = a2 * v3;
*(double *)&sum_weight = *(double *)&sum_weight - v3;
*(double *)&sum_x = *(double *)&sum_x - v4;
*(double *)&sum_x2 = *(double *)&sum_x2 - v4 * v4;
*(double *)&sum_y = *(double *)&sum_y - v5;
*(double *)&sum_y2 = *(double *)&sum_y2 - v5 * v5;
*(double *)&sum_xy = *(double *)&sum_xy - v4 * v5;
}

original_code:
void SwtSub (double x, double y, double z)
{
    double weight = 1/(z*z);
    double xWt = x * weight;
    double yWt = y * weight;
    sum_weight -= weight;
    sum_x -= xWt;
    sum_x2 -= xWt*xWt;
    sum_y -= yWt;
    sum_y2 -= yWt*yWt;
    sum_xy -= xWt*yWt;
}

canonical_original_code:
void SwtSub(double x, double y, double z)
{
    double weight = 1/(z*z);
    double xWt = x * weight;
    double yWt = y * weight;
    sum_weight -= weight;
    sum_x -= xWt;
    sum_x2 -= xWt*xWt;
    sum_y -= yWt;
    sum_y2 -= yWt*yWt;
    sum_xy -= xWt*yWt;
}


SumSub

decompiled_code:
void __fastcall SumSub(double a1, double a2)
{
SwtSub(a1, a2, 1.0);
}

canonical_decompiled_code:
void __fastcall func4(double a1, double a2)
{
func3(a1, a2, 1.0);
}

original_code:
void SumSub (double x, double y)
{
    SwtSub (x, y, (double) 1.0);
}

canonical_original_code:
void SumSub(double x, double y)
{
    SwtSub (x, y, (double) 1.0);
}


MeanXY

decompiled_code:
void __fastcall MeanXY(double *a1, double *a2)
{
double v2; // xmm1_8

v2 = *(double *)&sum_weight;
*a1 = *(double *)&sum_x / *(double *)&sum_weight;
*a2 = *(double *)&sum_y / v2;
}

canonical_decompiled_code:
void __fastcall func5(double *a1, double *a2)
{
double v2; // xmm1_8

v2 = *(double *)&sum_weight;
*a1 = *(double *)&sum_x / *(double *)&sum_weight;
*a2 = *(double *)&sum_y / v2;
}

original_code:
void MeanXY (double *xMean, double *yMean)
{
    *xMean = sum_x / sum_weight;
    *yMean = sum_y / sum_weight;
}

canonical_original_code:
void MeanXY(double *xMean, double *yMean)
{
    *xMean = sum_x / sum_weight;
    *yMean = sum_y / sum_weight;
}

variable_types:
xMean
double *

variable_types:
yMean
double *


SDevXY

decompiled_code:
void __fastcall SDevXY(double *a1, double *a2)
{
double v2; // rbp
double v3; // xmm0_8
double v4; // xmm0_8
double v5; // xmm1_8
double v6; // xmm1_8
double v7; // xmm1_8
double v8; // xmm1_8

*a1 = 0.0;
v2 = *(double *)&sum_weight;
v3 = *(double *)&sum_x * *(double *)&sum_x / *(double *)&sum_weight;
if ( *(double *)&sum_x2 > v3 )
{
v5 = (*(double *)&sum_x2 - v3) / *(double *)&sum_weight;
if ( v5 < 0.0 )
v6 = sqrt(v5);
else
v6 = sqrt(v5);
*a1 = v6;
}
*a2 = 0.0;
v4 = *(double *)&sum_y * *(double *)&sum_y / v2;
if ( *(double *)&sum_y2 > v4 )
{
v7 = (*(double *)&sum_y2 - v4) / v2;
if ( v7 < 0.0 )
v8 = sqrt(v7);
else
v8 = sqrt(v7);
*a2 = v8;
}
}

canonical_decompiled_code:
void __fastcall func6(double *a1, double *a2)
{
double v2; // rbp
double v3; // xmm0_8
double v4; // xmm0_8
double v5; // xmm1_8
double v6; // xmm1_8
double v7; // xmm1_8
double v8; // xmm1_8

*a1 = 0.0;
v2 = *(double *)&sum_weight;
v3 = *(double *)&sum_x * *(double *)&sum_x / *(double *)&sum_weight;
if ( *(double *)&sum_x2 > v3 )
{
v5 = (*(double *)&sum_x2 - v3) / *(double *)&sum_weight;
if ( v5 < 0.0 )
v6 = sqrt(v5);
else
v6 = sqrt(v5);
*a1 = v6;
}
*a2 = 0.0;
v4 = *(double *)&sum_y * *(double *)&sum_y / v2;
if ( *(double *)&sum_y2 > v4 )
{
v7 = (*(double *)&sum_y2 - v4) / v2;
if ( v7 < 0.0 )
v8 = sqrt(v7);
else
v8 = sqrt(v7);
*a2 = v8;
}
}

original_code:
void SDevXY (double *xDev, double *yDev)
{
    *xDev = 0.0;
    if (sum_x2 > ((sum_x*sum_x)/sum_weight) )
        *xDev = sqrt (( sum_x2 - ( (sum_x*sum_x)/sum_weight) )/sum_weight);
    *yDev = 0.0;
    if (sum_y2 > ((sum_y*sum_y)/sum_weight) )
        *yDev = sqrt (( sum_y2 - ( (sum_y*sum_y)/sum_weight) )/sum_weight);
}

canonical_original_code:
void SDevXY(double *xDev, double *yDev)
{
    *xDev = 0.0;
    if (sum_x2 > ((sum_x*sum_x)/sum_weight) )
        *xDev = sqrt (( sum_x2 - ( (sum_x*sum_x)/sum_weight) )/sum_weight);
    *yDev = 0.0;
    if (sum_y2 > ((sum_y*sum_y)/sum_weight) )
        *yDev = sqrt (( sum_y2 - ( (sum_y*sum_y)/sum_weight) )/sum_weight);
}

variable_types:
xDev
double *

variable_types:
yDev
double *


SErrXY

decompiled_code:
void __fastcall SErrXY(double *a1, double *a2)
{
double v2; // rbp
double v3; // xmm0_8
double v4; // xmm0_8
double v5; // xmm1_8
double v6; // xmm1_8
double v7; // xmm1_8
double v8; // xmm1_8

*a1 = 0.0;
v2 = *(double *)&sum_weight;
v3 = *(double *)&sum_x * *(double *)&sum_x / *(double *)&sum_weight;
if ( *(double *)&sum_x2 > v3 )
{
v5 = (*(double *)&sum_x2 - v3) / (*(double *)&sum_weight - 1.0);
if ( v5 < 0.0 )
v6 = sqrt(v5);
else
v6 = sqrt(v5);
*a1 = v6;
}
*a2 = 0.0;
v4 = *(double *)&sum_y * *(double *)&sum_y / v2;
if ( *(double *)&sum_y2 > v4 )
{
v7 = (*(double *)&sum_y2 - v4) / (v2 - 1.0);
if ( v7 < 0.0 )
v8 = sqrt(v7);
else
v8 = sqrt(v7);
*a2 = v8;
}
}

canonical_decompiled_code:
void __fastcall func7(double *a1, double *a2)
{
double v2; // rbp
double v3; // xmm0_8
double v4; // xmm0_8
double v5; // xmm1_8
double v6; // xmm1_8
double v7; // xmm1_8
double v8; // xmm1_8

*a1 = 0.0;
v2 = *(double *)&sum_weight;
v3 = *(double *)&sum_x * *(double *)&sum_x / *(double *)&sum_weight;
if ( *(double *)&sum_x2 > v3 )
{
v5 = (*(double *)&sum_x2 - v3) / (*(double *)&sum_weight - 1.0);
if ( v5 < 0.0 )
v6 = sqrt(v5);
else
v6 = sqrt(v5);
*a1 = v6;
}
*a2 = 0.0;
v4 = *(double *)&sum_y * *(double *)&sum_y / v2;
if ( *(double *)&sum_y2 > v4 )
{
v7 = (*(double *)&sum_y2 - v4) / (v2 - 1.0);
if ( v7 < 0.0 )
v8 = sqrt(v7);
else
v8 = sqrt(v7);
*a2 = v8;
}
}

original_code:
void SErrXY (double *xErr, double *yErr)
{
    *xErr = 0.0;
    if (sum_x2 > ((sum_x*sum_x)/sum_weight) )
        *xErr = sqrt (( sum_x2 - ( (sum_x*sum_x)/sum_weight) )/( sum_weight-1 ));
    *yErr = 0.0;
    if (sum_y2 > ((sum_y*sum_y)/sum_weight) )
        *yErr = sqrt (( sum_y2 - ((sum_y*sum_y)/sum_weight) )/( sum_weight-1 ));
}

canonical_original_code:
void SErrXY(double *xErr, double *yErr)
{
    *xErr = 0.0;
    if (sum_x2 > ((sum_x*sum_x)/sum_weight) )
        *xErr = sqrt (( sum_x2 - ( (sum_x*sum_x)/sum_weight) )/( sum_weight-1 ));
    *yErr = 0.0;
    if (sum_y2 > ((sum_y*sum_y)/sum_weight) )
        *yErr = sqrt (( sum_y2 - ((sum_y*sum_y)/sum_weight) )/( sum_weight-1 ));
}

variable_types:
xErr
double *

variable_types:
yErr
double *


SumLR

decompiled_code:
void __fastcall SumLR(double *a1, double *a2)
{
double v2; // xmm0_8
double v3; // xmm2_8
double v4; // xmm3_8
double v5; // xmm4_8
double v6; // xmm5_8

v2 = *(double *)&sum_x2;
v3 = *(double *)&sum_x;
v4 = *(double *)&sum_weight * *(double *)&sum_x2 - v3 * v3;
v5 = *(double *)&sum_xy;
v6 = *(double *)&sum_y;
*a1 = (*(double *)&sum_weight * *(double *)&sum_xy - *(double *)&sum_x * *(double *)&sum_y) / v4;
*a2 = (v2 * v6 - v3 * v5) / v4;
}

canonical_decompiled_code:
void __fastcall func8(double *a1, double *a2)
{
double v2; // xmm0_8
double v3; // xmm2_8
double v4; // xmm3_8
double v5; // xmm4_8
double v6; // xmm5_8

v2 = *(double *)&sum_x2;
v3 = *(double *)&sum_x;
v4 = *(double *)&sum_weight * *(double *)&sum_x2 - v3 * v3;
v5 = *(double *)&sum_xy;
v6 = *(double *)&sum_y;
*a1 = (*(double *)&sum_weight * *(double *)&sum_xy - *(double *)&sum_x * *(double *)&sum_y) / v4;
*a2 = (v2 * v6 - v3 * v5) / v4;
}

original_code:
void SumLR (double *slope, double *constant)
{
    double determ = (sum_weight*sum_x2 - sum_x*sum_x);
    *slope = (sum_weight*sum_xy - sum_x*sum_y) / determ;
    *constant = (sum_x2*sum_y - sum_x*sum_xy) / determ;
}

canonical_original_code:
void SumLR(double *slope, double *constant)
{
    double determ = (sum_weight*sum_x2 - sum_x*sum_x);
    *slope = (sum_weight*sum_xy - sum_x*sum_y) / determ;
    *constant = (sum_x2*sum_y - sum_x*sum_xy) / determ;
}

variable_types:
slope
double *

variable_types:
constant
double *

variable_types: determ double


VarLR

decompiled_code:
void __fastcall VarLR(double *a1, double *a2)
{
double v2; // rbx
double v3; // xmm0_8
double v4; // xmm0_8
double v5; // xmm0_8
double v6; // xmm0_8
double v7; // [rsp+8h] [rbp-20h]

v2 = *(double *)&sum_x2;
v7 = *(double *)&sum_x2 * *(double *)&sum_weight - *(double *)&sum_x * *(double *)&sum_x;
v3 = *(double *)&sum_weight / v7;
if ( *(double *)&sum_weight / v7 < 0.0 )
v4 = sqrt(v3);
else
v4 = sqrt(v3);
*a1 = v4;
v5 = v2 / v7;
if ( v2 / v7 < 0.0 )
v6 = sqrt(v5);
else
v6 = sqrt(v5);
*a2 = v6;
}

canonical_decompiled_code:
void __fastcall func9(double *a1, double *a2)
{
double v2; // rbx
double v3; // xmm0_8
double v4; // xmm0_8
double v5; // xmm0_8
double v6; // xmm0_8
double v7; // [rsp+8h] [rbp-20h]

v2 = *(double *)&sum_x2;
v7 = *(double *)&sum_x2 * *(double *)&sum_weight - *(double *)&sum_x * *(double *)&sum_x;
v3 = *(double *)&sum_weight / v7;
if ( *(double *)&sum_weight / v7 < 0.0 )
v4 = sqrt(v3);
else
v4 = sqrt(v3);
*a1 = v4;
v5 = v2 / v7;
if ( v2 / v7 < 0.0 )
v6 = sqrt(v5);
else
v6 = sqrt(v5);
*a2 = v6;
}

original_code:
void VarLR (double *slope, double *constant)
{
    double determ = (sum_weight*sum_x2 - sum_x*sum_x);
    *slope = sqrt (sum_weight / determ);
    *constant = sqrt (sum_x2 / determ);
}

canonical_original_code:
void VarLR(double *slope, double *constant)
{
    double determ = (sum_weight*sum_x2 - sum_x*sum_x);
    *slope = sqrt (sum_weight / determ);
    *constant = sqrt (sum_x2 / determ);
}


AskString

decompiled_code:
char *__fastcall AskString(const char *a1, const char *a2)
{
char *result; // rax
char v3[264]; // [rsp+0h] [rbp-108h] BYREF

printf("%s <%s> ==> ", a1, a2);
result = fgets(v3, 256, stdin);
if ( v3[0] )
result = (char *)_isoc99_sscanf(v3, "%s\n", a2);
return result;
}

canonical_decompiled_code:
char *__fastcall func1(const char *a1, const char *a2)
{
char *result; // rax
char v3[264]; // [rsp+0h] [rbp-108h] BYREF

printf("%s <%s> ==> ", a1, a2);
result = fgets(v3, 256, stdin);
if ( v3[0] )
result = (char *)_isoc99_sscanf(v3, "%s\n", a2);
return result;
}

original_code:
void AskString (char *question, char *answer)
{
    char reply[256];
    printf ("%s <%s> ==> ", question, answer);
    fgets (reply, 256, stdin);
    if (reply[0])
        sscanf (reply, "%s\n", answer);
}

canonical_original_code:
void AskString(char *question, char *answer)
{
    char reply[256];
    printf ("%s <%s> ==> ", question, answer);
    fgets (reply, 256, stdin);
    if (reply[0])
        sscanf (reply, "%s\n", answer);
}

variable_types:
question
char *

variable_types:
answer
char *

variable_types:
reply
char [256]


AskDouble

decompiled_code:
char *__fastcall AskDouble(const char *a1, double *a2)
{
char *result; // rax
char v3[264]; // [rsp+0h] [rbp-108h] BYREF

printf("%s <%lg> ==> ", a1, *a2);
result = fgets(v3, 256, stdin);
if ( v3[0] )
result = (char *)_isoc99_sscanf(v3, "%le", a2);
return result;
}

canonical_decompiled_code:
char *__fastcall func2(const char *a1, double *a2)
{
char *result; // rax
char v3[264]; // [rsp+0h] [rbp-108h] BYREF

printf("%s <%lg> ==> ", a1, *a2);
result = fgets(v3, 256, stdin);
if ( v3[0] )
result = (char *)_isoc99_sscanf(v3, "%le", a2);
return result;
}

original_code:
void AskDouble (char *question, double *answer)
{
    char reply[256];
    printf ("%s <%lg> ==> ", question, *answer);
    fgets (reply, 256, stdin);
    if (reply[0])
        sscanf (reply, "%le", answer);
}

canonical_original_code:
void AskDouble(char *question, double *answer)
{
    char reply[256];
    printf ("%s <%lg> ==> ", question, *answer);
    fgets (reply, 256, stdin);
    if (reply[0])
        sscanf (reply, "%le", answer);
}

variable_types:
answer
double *


AskInt

decompiled_code:
char *__fastcall AskInt(const char *a1, unsigned int *a2)
{
char *result; // rax
char v3[264]; // [rsp+0h] [rbp-108h] BYREF

printf("%s <%d> ==> ", a1, *a2);
result = fgets(v3, 256, stdin);
if ( v3[0] )
result = (char *)_isoc99_sscanf(v3, "%d", a2);
return result;
}

canonical_decompiled_code:
char *__fastcall func3(const char *a1, unsigned int *a2)
{
char *result; // rax
char v3[264]; // [rsp+0h] [rbp-108h] BYREF

printf("%s <%d> ==> ", a1, *a2);
result = fgets(v3, 256, stdin);
if ( v3[0] )
result = (char *)_isoc99_sscanf(v3, "%d", a2);
return result;
}

original_code:
void AskInt (char *question, int *answer)
{
    char reply[256];
    printf ("%s <%d> ==> ", question, *answer);
    fgets (reply, 256, stdin);
    if (reply[0])
        sscanf (reply, "%d", answer);
}

canonical_original_code:
void AskInt(char *question, int *answer)
{
    char reply[256];
    printf ("%s <%d> ==> ", question, *answer);
    fgets (reply, 256, stdin);
    if (reply[0])
        sscanf (reply, "%d", answer);
}

variable_types:
answer
int *


AskYesOrNo

decompiled_code:
__int64 __fastcall AskYesOrNo(const char *a1, unsigned __int8 a2)
{
char v3[264]; // [rsp+0h] [rbp-108h] BYREF

printf("%s (Y=yes, N=no) <%c> ==> ", a1, (unsigned int)(char)a2);
fgets(v3, 256, stdin);
if ( v3[0] == 89 )
goto LABEL_8;
if ( v3[0] <= 89 )
{
if ( !v3[0] )
{
v3[0] = a2;
return (unsigned __int8)v3[0];
}
if ( v3[0] == 78 )
goto LABEL_5;
LABEL_11:
v3[0] = 0;
return (unsigned __int8)v3[0];
}
if ( v3[0] != 110 )
{
if ( v3[0] != 121 )
goto LABEL_11;
LABEL_8:
v3[0] = 121;
return (unsigned __int8)v3[0];
}
LABEL_5:
v3[0] = 110;
return (unsigned __int8)v3[0];
}

canonical_decompiled_code:
__int64 __fastcall func4(const char *a1, unsigned __int8 a2)
{
char v3[264]; // [rsp+0h] [rbp-108h] BYREF

printf("%s (Y=yes, N=no) <%c> ==> ", a1, (unsigned int)(char)a2);
fgets(v3, 256, stdin);
if ( v3[0] == 89 )
goto LABEL_8;
if ( v3[0] <= 89 )
{
if ( !v3[0] )
{
v3[0] = a2;
return (unsigned __int8)v3[0];
}
if ( v3[0] == 78 )
goto LABEL_5;
LABEL_11:
v3[0] = 0;
return (unsigned __int8)v3[0];
}
if ( v3[0] != 110 )
{
if ( v3[0] != 121 )
goto LABEL_11;
LABEL_8:
v3[0] = 121;
return (unsigned __int8)v3[0];
}
LABEL_5:
v3[0] = 110;
return (unsigned __int8)v3[0];
}

original_code:
char AskYesOrNo (char *question, char standard)
{
    char reply[256];
    do {
        printf ("%s (Y=yes, N=no) <%c> ==> ", question, standard);
        fgets (reply, 256, stdin);
        switch (reply[0]) {
            case (char) 0:
                reply[0] = standard;
                break;
            case 'y':
            case 'Y':
                reply[0] = 'y';
                break;
            case 'n':
            case 'N':
                reply[0] = 'n';
                break;
            default:
                reply[0] = 0;
        }
    } while (!reply);
    return reply[0];
}

canonical_original_code:
char AskYesOrNo(char *question, char standard)
{
    char reply[256];
    do {
        printf ("%s (Y=yes, N=no) <%c> ==> ", question, standard);
        fgets (reply, 256, stdin);
        switch (reply[0]) {
            case (char) 0:
                reply[0] = standard;
                break;
            case 'y':
            case 'Y':
                reply[0] = 'y';
                break;
            case 'n':
            case 'N':
                reply[0] = 'n';
                break;
            default:
                reply[0] = 0;
        }
    } while (!reply);
    return reply[0];
}

variable_types: standard char

return_type: char


Spinner

decompiled_code:
int __fastcall Spinner(int a1)
{
int v1; // eax

v1 = a1 % 4;
if ( a1 % 4 == 2 )
{
putchar(47);
}
else if ( v1 > 2 )
{
putchar(124);
}
else if ( (a1 & 3) != 0 )
{
if ( v1 == 1 )
putchar(45);
}
else
{
putchar(92);
}
putchar(8);
return fflush(stdout);
}

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

v1 = a1 % 4;
if ( a1 % 4 == 2 )
{
putchar(47);
}
else if ( v1 > 2 )
{
putchar(124);
}
else if ( (a1 & 3) != 0 )
{
if ( v1 == 1 )
putchar(45);
}
else
{
putchar(92);
}
putchar(8);
return fflush(stdout);
}

original_code:
void Spinner (int i)
{
    switch (i % 4) {
        case 1: printf ("%c", '-'); break;
        case 2: printf ("%c", '/'); break;
        case 3: printf ("%c", '|'); break;
        case 0: printf ("%c", '\\'); break;
    }
    printf ("%c", 0x08);
    fflush(stdout);
}

canonical_original_code:
void Spinner(int i)
{
    switch (i % 4) {
        case 1: printf ("%c", '-'); break;
        case 2: printf ("%c", '/'); break;
        case 3: printf ("%c", '|'); break;
        case 0: printf ("%c", '\\'); break;
    }
    printf ("%c", 0x08);
    fflush(stdout);
}

variable_types: i int


Iswap

decompiled_code:
__int64 __fastcall Iswap(_DWORD *a1, _DWORD *a2)
{
__int64 result; // rax

result = (unsigned int)*a1;
*a1 = *a2;
*a2 = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(_DWORD *a1, _DWORD *a2)
{
__int64 result; // rax

result = (unsigned int)*a1;
*a1 = *a2;
*a2 = result;
return result;
}

original_code:
void Iswap (int *a, int *b)
{
    int c = *a;
    *a = *b;
    *b = c;
}

canonical_original_code:
void Iswap(int *a, int *b)
{
    int c = *a;
    *a = *b;
    *b = c;
}

variable_types:
a
int *

variable_types:
b
int *

variable_types: c int


Plot

original_code:
void Plot (int n, double *x, double *y)
{
    char screen[(20)+2][(75)+2+1];
    int i, r, c, nRow, nCol;
    double xMin, xMax, yMin, yMax, ColDel, RowDel;
    if (n < 2) return;
    for (r = 0; r < (20)+2; r++) {
        for (c = 0; c < (75)+2; c++)
            screen[r][c] = ' ';
        screen[r][(75)+2] = (char) 0;
    }
    for (r = 1; r <= (20); r++) {
        screen[r][0] = '|';
        screen[r][(75)+1] = '|';
    }
    for (c = 1; c <= (75); c++) {
        screen[0][c] = '-';
        screen[(20)+1][c] = '-';
    }
    xMin = x[1];
    xMax = x[1];
    yMin = y[1];
    yMax = y[1];
    for (i = 2; i <= n; i++) {
        xMin = (dminarg1=(xMin),dminarg2=(x[i]),(dminarg1) < (dminarg2) ? (dminarg1) : (dminarg2));
        xMax = (dmaxarg1=(xMax),dmaxarg2=(x[i]),(dmaxarg1) > (dmaxarg2) ? (dmaxarg1) : (dmaxarg2));
        yMin = (dminarg1=(yMin),dminarg2=(y[i]),(dminarg1) < (dminarg2) ? (dminarg1) : (dminarg2));
        yMax = (dmaxarg1=(yMax),dmaxarg2=(y[i]),(dmaxarg1) > (dmaxarg2) ? (dmaxarg1) : (dmaxarg2));
    }
    ColDel = ((75) - 1) / (xMax - xMin);
    RowDel = ((20) - 1) / (yMax - yMin);
    for (i = 1; i <= n; i++) {
        c = ColDel * (x[i] - xMin) + 1;
        r = RowDel * (y[i] - yMin) + 1;
        screen[r][c] = 'O';
    }
    printf ("row:    min=%lg   step=%lg   max=%lg\n", xMin, ColDel, xMax);
    printf ("column: min=%lg   step=%lg   max=%lg\n", yMin, RowDel, yMax);
    for (r = (20) + 1; r >= 0; r--)
        printf ("%s\n", screen[r]);
}

canonical_original_code:
void Plot(int n, double *x, double *y)
{
    char screen[-1][-1];
    int i; int r; int c; int nRow; int nCol;
    double xMin; double xMax; double yMin; double yMax; double ColDel; double RowDel;
    if (n < 2) return;
    for (r = 0; r < (20)+2; r++) {
        for (c = 0; c < (75)+2; c++)
            screen[r][c] = ' ';
        screen[r][(75)+2] = (char) 0;
    }
    for (r = 1; r <= (20); r++) {
        screen[r][0] = '|';
        screen[r][(75)+1] = '|';
    }
    for (c = 1; c <= (75); c++) {
        screen[0][c] = '-';
        screen[(20)+1][c] = '-';
    }
    xMin = x[1];
    xMax = x[1];
    yMin = y[1];
    yMax = y[1];
    for (i = 2; i <= n; i++) {
        xMin = (dminarg1=(xMin),dminarg2=(x[i]),(dminarg1) < (dminarg2) ? (dminarg1) : (dminarg2));
        xMax = (dmaxarg1=(xMax),dmaxarg2=(x[i]),(dmaxarg1) > (dmaxarg2) ? (dmaxarg1) : (dmaxarg2));
        yMin = (dminarg1=(yMin),dminarg2=(y[i]),(dminarg1) < (dminarg2) ? (dminarg1) : (dminarg2));
        yMax = (dmaxarg1=(yMax),dmaxarg2=(y[i]),(dmaxarg1) > (dmaxarg2) ? (dmaxarg1) : (dmaxarg2));
    }
    ColDel = ((75) - 1) / (xMax - xMin);
    RowDel = ((20) - 1) / (yMax - yMin);
    for (i = 1; i <= n; i++) {
        c = ColDel * (x[i] - xMin) + 1;
        r = RowDel * (y[i] - yMin) + 1;
        screen[r][c] = 'O';
    }
    printf ("row:    min=%lg   step=%lg   max=%lg\n", xMin, ColDel, xMax);
    printf ("column: min=%lg   step=%lg   max=%lg\n", yMin, RowDel, yMax);
    for (r = (20) + 1; r >= 0; r--)
        printf ("%s\n", screen[r]);
}

variable_types: n int

variable_types:
x
double *

variable_types:
y
double *

variable_types:
screen
char [-1][-1]

variable_types: r int

variable_types: nRow int

variable_types: nCol int

variable_types: xMin double

variable_types: xMax double

variable_types: yMin double

variable_types: yMax double

variable_types: ColDel double

variable_types: RowDel double


ResPlot

original_code:
void ResPlot (int n, double *x)
{
    char screen[(20)+2][(75)+2+1];
    int i, r, c, nRow, nCol, mPlus, mMinus, nPack;
    double xMin, xMax, ColDel, RowDel;
    if (n < 2) return;
    nPack = ((double) n / (75) - 1.0/n) + 1;
    nCol = ((double) n - 1./n)/nPack + 1;
    for (r = 0; r < (20)+2; r++) {
        for (c = 0; c < nCol+2; c++)
            screen[r][c] = ' ';
        screen[r][nCol+2] = (char) 0;
    }
    for (r = 1; r <= (20); r++) {
        screen[r][0] = '|';
        screen[r][nCol+1] = '|';
    }
    for (c = 1; c <= nCol; c++) {
        screen[0][c] = '-';
        screen[(20)+1][c] = '-';
    }
    xMin = x[1];
    xMax = x[1];
    for (i = 2; i <= n; i++) {
        xMin = (dminarg1=(xMin),dminarg2=(x[i]),(dminarg1) < (dminarg2) ? (dminarg1) : (dminarg2));
        xMax = (dmaxarg1=(xMax),dmaxarg2=(x[i]),(dmaxarg1) > (dmaxarg2) ? (dmaxarg1) : (dmaxarg2));
    }
    RowDel = ((20) - 1) / (xMax - xMin);
    mMinus = RowDel*(-1.0 - xMin) + 1;
    mPlus = RowDel*( 1.0 - xMin) + 1;
    for (c = 1; c < nCol+1; c++) {
        screen[mMinus][c] = '=';
        screen[mPlus][c] = '=';
    }
    for (i = 1; i <= n; i++) {
        c = ((double) i - 1./n)/nPack + 1;
        r = RowDel * (x[i] - xMin) + 1;
        screen[r][c] = 'O';
    }
    printf ("row:    min=%lg   step=%lg   max=%lg\n", xMin, RowDel, xMax);
    printf ("column: min=%d    max=%d\n", 1, n);
    for (r = (20) + 1; r >= 0; r--)
        printf ("%s\n", screen[r]);
}

canonical_original_code:
void ResPlot(int n, double *x)
{
    char screen[-1][-1];
    int i; int r; int c; int nRow; int nCol; int mPlus; int mMinus; int nPack;
    double xMin; double xMax; double ColDel; double RowDel;
    if (n < 2) return;
    nPack = ((double) n / (75) - 1.0/n) + 1;
    nCol = ((double) n - 1./n)/nPack + 1;
    for (r = 0; r < (20)+2; r++) {
        for (c = 0; c < nCol+2; c++)
            screen[r][c] = ' ';
        screen[r][nCol+2] = (char) 0;
    }
    for (r = 1; r <= (20); r++) {
        screen[r][0] = '|';
        screen[r][nCol+1] = '|';
    }
    for (c = 1; c <= nCol; c++) {
        screen[0][c] = '-';
        screen[(20)+1][c] = '-';
    }
    xMin = x[1];
    xMax = x[1];
    for (i = 2; i <= n; i++) {
        xMin = (dminarg1=(xMin),dminarg2=(x[i]),(dminarg1) < (dminarg2) ? (dminarg1) : (dminarg2));
        xMax = (dmaxarg1=(xMax),dmaxarg2=(x[i]),(dmaxarg1) > (dmaxarg2) ? (dmaxarg1) : (dmaxarg2));
    }
    RowDel = ((20) - 1) / (xMax - xMin);
    mMinus = RowDel*(-1.0 - xMin) + 1;
    mPlus = RowDel*( 1.0 - xMin) + 1;
    for (c = 1; c < nCol+1; c++) {
        screen[mMinus][c] = '=';
        screen[mPlus][c] = '=';
    }
    for (i = 1; i <= n; i++) {
        c = ((double) i - 1./n)/nPack + 1;
        r = RowDel * (x[i] - xMin) + 1;
        screen[r][c] = 'O';
    }
    printf ("row:    min=%lg   step=%lg   max=%lg\n", xMin, RowDel, xMax);
    printf ("column: min=%d    max=%d\n", 1, n);
    for (r = (20) + 1; r >= 0; r--)
        printf ("%s\n", screen[r]);
}

variable_types: i int

variable_types: mPlus int

variable_types: mMinus int

variable_types: nPack int


BSearch

decompiled_code:
void __fastcall BSearch(__int64 a1, int a2, int *a3, double a4)
{
int i; // edx
int j; // edx
int v7; // eax
int k; // edx
int v9; // eax

*a3 = -1;
if ( *(double *)(a1 + 8) <= a4 )
{
*a3 = a2 + 1;
if ( a4 <= *(double *)(a1 + 8LL * a2) )
{
if ( iLo <= 0 || iLo >= iHi || iHi > a2 )
{
iLo = 1;
iHi = a2;
}
for ( i = iLo; *(double *)(a1 + 8LL * i) > a4; iLo = i )
i /= 2;
for ( j = iHi; a4 > *(double *)(a1 + 8LL * j); iHi = j )
j = (j + a2 + 1) / 2;
*a3 = j;
v7 = iHi;
for ( k = iLo; iHi - iLo > 1; k = iLo )
{
v9 = (v7 + k) / 2;
*a3 = v9;
if ( a4 < *(double *)(a1 + 8LL * v9) )
iHi = v9;
else
iLo = v9;
v7 = iHi;
}
}
}
}

canonical_decompiled_code:
void __fastcall func11(__int64 a1, int a2, int *a3, double a4)
{
int i; // edx
int j; // edx
int v7; // eax
int k; // edx
int v9; // eax

*a3 = -1;
if ( *(double *)(a1 + 8) <= a4 )
{
*a3 = a2 + 1;
if ( a4 <= *(double *)(a1 + 8LL * a2) )
{
if ( iLo <= 0 || iLo >= iHi || iHi > a2 )
{
iLo = 1;
iHi = a2;
}
for ( i = iLo; *(double *)(a1 + 8LL * i) > a4; iLo = i )
i /= 2;
for ( j = iHi; a4 > *(double *)(a1 + 8LL * j); iHi = j )
j = (j + a2 + 1) / 2;
*a3 = j;
v7 = iHi;
for ( k = iLo; iHi - iLo > 1; k = iLo )
{
v9 = (v7 + k) / 2;
*a3 = v9;
if ( a4 < *(double *)(a1 + 8LL * v9) )
iHi = v9;
else
iLo = v9;
v7 = iHi;
}
}
}
}

original_code:
void BSearch (double z, double *x, int NumPts, int *iTest)
{
    *iTest = -1;
    if (z < x[1]) return;
    *iTest = NumPts + 1;
    if (z > x[NumPts]) return;
    if (iLo < 1 || iHi > NumPts || iLo >= iHi) {
      iLo = 1;
      iHi = NumPts;
    }
    while (z < x[iLo])
        iLo /= 2;
    while (z > x[iHi])
      iHi = (iHi + 1 + NumPts) / 2;
    *iTest = iHi;
    while (iHi - iLo > 1) {
        *iTest = (iLo + iHi) / 2;
        if (z >= x[*iTest])
            iLo = *iTest;
        else
            iHi = *iTest;
    }
}

canonical_original_code:
void BSearch(double z, double *x, int NumPts, int *iTest)
{
    *iTest = -1;
    if (z < x[1]) return;
    *iTest = NumPts + 1;
    if (z > x[NumPts]) return;
    if (iLo < 1 || iHi > NumPts || iLo >= iHi) {
      iLo = 1;
      iHi = NumPts;
    }
    while (z < x[iLo])
        iLo /= 2;
    while (z > x[iHi])
      iHi = (iHi + 1 + NumPts) / 2;
    *iTest = iHi;
    while (iHi - iLo > 1) {
        *iTest = (iLo + iHi) / 2;
        if (z >= x[*iTest])
            iLo = *iTest;
        else
            iHi = *iTest;
    }
}

variable_types: z double

variable_types: NumPts int

variable_types:
iTest
int *


strtrim

original_code:
void strtrim (char *inStr, char *outStr, char* list)
{
  char *in = inStr;
  char *out = outStr;
  *outStr = 0;
  while (*in) {
    if (!((*__ctype_b_loc ())[(int) ((*in))] & (unsigned short int) _ISspace)) {
      *out = *in;
      out++;
      *out = 0;
    }
    in++;
  }
}

canonical_original_code:
void strtrim(char *inStr, char *outStr, char *list)
{
  char *in = inStr;
  char *out = outStr;
  *outStr = 0;
  while (*in) {
    if (!((*__ctype_b_loc ())[(int) ((*in))] & (unsigned short) _ISspace)) {
      *out = *in;
      out++;
      *out = 0;
    }
    in++;
  }
}

variable_types:
inStr
char *

variable_types:
outStr
char *

variable_types:
list
char *

variable_types:
in
char *

variable_types:
out
char *


reverse

repo: profil/miniature-society

decompiled_code:
void __fastcall reverse(__int64 a1, const char *a2)
{
char *v2; // rbx
char *v3; // rax
char v4; // dl

if ( a2 )
{
v2 = (char *)a2;
if ( *a2 )
{
v3 = (char *)&a2[strlen(a2) - 1];
if ( a2 < v3 )
{
do
{
v4 = *v2;
*v2 = *v3;
*v3 = v4;
++v2;
--v3;
}
while ( v2 < v3 );
}
}
}
}

original_code:
void reverse(int socket, char *data) {
 char tmp, *p;
 if(data == ((void *)0) || !(*data))
  return;
 p = data + strlen(data) - 1;
 while(p > data) {
  tmp = *data;
  *data = *p;
  *p = tmp;
  data++;
  p--;
 }
}

canonical_original_code:
void reverse(int socket, char *data) {
 char tmp; char *p;
 if(data == ((void *)0) || !(*data))
  return;
 p = data + strlen(data) - 1;
 while(p > data) {
  tmp = *data;
  *data = *p;
  *p = tmp;
  data++;
  p--;
 }
}

variable_types: socket int

variable_types:
data
char *

variable_types: tmp char

variable_types:
p
char *


whoami

decompiled_code:
int __fastcall whoami(unsigned int a1, char *a2)
{
return snprintf(a2, 0x400uLL, "%d\n", a1);
}

canonical_decompiled_code:
int __fastcall func9(unsigned int a1, char *a2)
{
return snprintf(a2, 0x400uLL, "%d\n", a1);
}

original_code:
void whoami(int s, char *data) {
 snprintf(data, 1024, "%d\n", s);
}

variable_types: s int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er14
void *v4; // r13
int v5; // ebx
int v7; // eax
__int64 v8; // r12
int v9; // eax
char *v10; // rax
char *v11; // r12
size_t v12; // rax
size_t v13; // rbp
int v14; // eax
unsigned __int64 v15; // rcx
bool v16; // zf
int v17; // ebp
size_t v18; // rax
int fd; // [rsp+Ch] [rbp-1ECh]
socklen_t addr_len; // [rsp+1Ch] [rbp-1DCh] BYREF
fd_set readfds; // [rsp+20h] [rbp-1D8h] BYREF
__m128i v22[8]; // [rsp+A0h] [rbp-158h] BYREF
char *s2; // [rsp+120h] [rbp-D8h]
void (__fastcall *v24)(__int64, const char *); // [rsp+128h] [rbp-D0h]
char *v25; // [rsp+130h] [rbp-C8h]
int (__fastcall *v26)(unsigned int, char *); // [rsp+138h] [rbp-C0h]
struct sockaddr addr; // [rsp+140h] [rbp-B8h] BYREF

s2 = "reverse";
v24 = reverse;
v25 = "whoami";
v26 = whoami;
if ( argc <= 2 )
{
fprintf(stderr, "usage: %s <host> <port>\n", *argv);
}
else
{
fd = con(argv[1], argv[2], 0);
if ( listen(fd, 10) == -1 )
{
close(fd);
fwrite("Error listening!\n", 1uLL, 0x11uLL, stderr);
}
else
{
memset(v22, 0, sizeof(v22));
memset(&readfds, 0, sizeof(readfds));
v22[0].m128i_i64[fd / 64] |= 1LL << (fd % 64);
v3 = fd;
LABEL_4:
while ( 1 )
{
v4 = malloc(0x400uLL);
*(__m128i *)readfds.fds_bits = _mm_loadu_si128(v22);
*(__m128i *)&readfds.fds_bits[2] = _mm_loadu_si128(&v22[1]);
*(__m128i *)&readfds.fds_bits[4] = _mm_loadu_si128(&v22[2]);
*(__m128i *)&readfds.fds_bits[6] = _mm_loadu_si128(&v22[3]);
*(__m128i *)&readfds.fds_bits[8] = _mm_loadu_si128(&v22[4]);
*(__m128i *)&readfds.fds_bits[10] = _mm_loadu_si128(&v22[5]);
*(__m128i *)&readfds.fds_bits[12] = _mm_loadu_si128(&v22[6]);
*(__m128i *)&readfds.fds_bits[14] = _mm_loadu_si128(&v22[7]);
if ( select(v3 + 1, &readfds, 0LL, 0LL, 0LL) == -1 )
break;
v5 = 0;
if ( v3 >= 0 )
{
while ( 1 )
{
v8 = 1LL << (v5 % 64);
if ( (readfds.fds_bits[v5 / 64] & v8) != 0 )
break;
LABEL_18:
if ( v3 < ++v5 )
goto LABEL_4;
}
if ( fd == v5 )
{
addr_len = 128;
v7 = accept(v5, &addr, &addr_len);
if ( v7 == -1 )
{
fwrite("Error in accept()\n", 1uLL, 0x12uLL, stderr);
}
else
{
v22[0].m128i_i64[v7 / 64] |= 1LL << (v7 % 64);
if ( v3 < v7 )
v3 = v7;
puts("Connected by someone!");
}
goto LABEL_18;
}
v9 = recv(v5, v4, 0x3FFuLL, 0);
if ( v9 <= 0 )
{
if ( v9 )
fwrite("Error in recv()\n", 1uLL, 0x10uLL, stderr);
else
fprintf(stderr, "Socket %d disconnected.\n", (unsigned int)v5);
close(v5);
v22[0].m128i_i64[v5 / 64] &= ~v8;
goto LABEL_18;
}
*((_BYTE *)v4 + v9) = 0;
printf("Got data: %s\nProcessing and sending...\n", (const char *)v4);
v10 = strchr((const char *)v4, 59);
v11 = v10;
if ( !v10 )
{
LABEL_25:
v12 = strlen((const char *)v4);
send(v5, v4, v12, 0);
goto LABEL_18;
}
v13 = v10 - (_BYTE *)v4;
v14 = strncmp((const char *)v4, s2, v10 - (_BYTE *)v4);
if ( v14 )
{
if ( strncmp((const char *)v4, v25, v13) )
{
LABEL_28:
v15 = v11 - (_BYTE *)v4;
if ( (unsigned __int64)(v11 - (_BYTE *)v4) > 0xA )
v15 = 10LL;
v16 = memcmp(v4, "broadcast", v15) == 0;
v17 = !v16;
if ( v16 )
{
puts("Sending broadcast...");
v4 = v11 + 1;
if ( v3 >= 0 )
{
do
{
if ( (v22[0].m128i_i64[v17 / 64] & (1LL << (v17 % 64))) != 0 && fd != v17 && v5 != v17 )
{
v18 = strlen(v11 + 1);
send(v17, v11 + 1, v18, 0);
}
++v17;
}
while ( v17 <= v3 );
}
}
goto LABEL_25;
}
v14 = 1;
}
v4 = v11 + 1;
(*(&v24 + 2 * v14))((unsigned int)v5, v11 + 1);
goto LABEL_28;
}
}
fwrite("Error in select()\n", 1uLL, 0x12uLL, stderr);
}
}
return 1;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er14
void *v4; // r13
int v5; // ebx
int v7; // eax
__int64 v8; // r12
int v9; // eax
char *v10; // rax
char *v11; // r12
size_t v12; // rax
size_t v13; // rbp
int v14; // eax
unsigned __int64 v15; // rcx
bool v16; // zf
int v17; // ebp
size_t v18; // rax
int fd; // [rsp+Ch] [rbp-1ECh]
socklen_t addr_len; // [rsp+1Ch] [rbp-1DCh] BYREF
fd_set readfds; // [rsp+20h] [rbp-1D8h] BYREF
__m128i v22[8]; // [rsp+A0h] [rbp-158h] BYREF
char *s2; // [rsp+120h] [rbp-D8h]
void (__fastcall *v24)(__int64, const char *); // [rsp+128h] [rbp-D0h]
char *v25; // [rsp+130h] [rbp-C8h]
int (__fastcall *v26)(unsigned int, char *); // [rsp+138h] [rbp-C0h]
struct sockaddr addr; // [rsp+140h] [rbp-B8h] BYREF

s2 = "reverse";
v24 = reverse;
v25 = "whoami";
v26 = whoami;
if ( argc <= 2 )
{
fprintf(stderr, "usage: %s <host> <port>\n", *argv);
}
else
{
fd = func7(argv[1], argv[2], 0);
if ( listen(fd, 10) == -1 )
{
close(fd);
fwrite("Error listening!\n", 1uLL, 0x11uLL, stderr);
}
else
{
memset(v22, 0, sizeof(v22));
memset(&readfds, 0, sizeof(readfds));
v22[0].m128i_i64[fd / 64] |= 1LL << (fd % 64);
v3 = fd;
LABEL_4:
while ( 1 )
{
v4 = malloc(0x400uLL);
*(__m128i *)readfds.fds_bits = _mm_loadu_si128(v22);
*(__m128i *)&readfds.fds_bits[2] = _mm_loadu_si128(&v22[1]);
*(__m128i *)&readfds.fds_bits[4] = _mm_loadu_si128(&v22[2]);
*(__m128i *)&readfds.fds_bits[6] = _mm_loadu_si128(&v22[3]);
*(__m128i *)&readfds.fds_bits[8] = _mm_loadu_si128(&v22[4]);
*(__m128i *)&readfds.fds_bits[10] = _mm_loadu_si128(&v22[5]);
*(__m128i *)&readfds.fds_bits[12] = _mm_loadu_si128(&v22[6]);
*(__m128i *)&readfds.fds_bits[14] = _mm_loadu_si128(&v22[7]);
if ( select(v3 + 1, &readfds, 0LL, 0LL, 0LL) == -1 )
break;
v5 = 0;
if ( v3 >= 0 )
{
while ( 1 )
{
v8 = 1LL << (v5 % 64);
if ( (readfds.fds_bits[v5 / 64] & v8) != 0 )
break;
LABEL_18:
if ( v3 < ++v5 )
goto LABEL_4;
}
if ( fd == v5 )
{
addr_len = 128;
v7 = accept(v5, &addr, &addr_len);
if ( v7 == -1 )
{
fwrite("Error in accept()\n", 1uLL, 0x12uLL, stderr);
}
else
{
v22[0].m128i_i64[v7 / 64] |= 1LL << (v7 % 64);
if ( v3 < v7 )
v3 = v7;
puts("Connected by someone!");
}
goto LABEL_18;
}
v9 = recv(v5, v4, 0x3FFuLL, 0);
if ( v9 <= 0 )
{
if ( v9 )
fwrite("Error in recv()\n", 1uLL, 0x10uLL, stderr);
else
fprintf(stderr, "Socket %d disconnected.\n", (unsigned int)v5);
close(v5);
v22[0].m128i_i64[v5 / 64] &= ~v8;
goto LABEL_18;
}
*((_BYTE *)v4 + v9) = 0;
printf("Got data: %s\nProcessing and sending...\n", (const char *)v4);
v10 = strchr((const char *)v4, 59);
v11 = v10;
if ( !v10 )
{
LABEL_25:
v12 = strlen((const char *)v4);
send(v5, v4, v12, 0);
goto LABEL_18;
}
v13 = v10 - (_BYTE *)v4;
v14 = strncmp((const char *)v4, s2, v10 - (_BYTE *)v4);
if ( v14 )
{
if ( strncmp((const char *)v4, v25, v13) )
{
LABEL_28:
v15 = v11 - (_BYTE *)v4;
if ( (unsigned __int64)(v11 - (_BYTE *)v4) > 0xA )
v15 = 10LL;
v16 = memcmp(v4, "broadcast", v15) == 0;
v17 = !v16;
if ( v16 )
{
puts("Sending broadcast...");
v4 = v11 + 1;
if ( v3 >= 0 )
{
do
{
if ( (v22[0].m128i_i64[v17 / 64] & (1LL << (v17 % 64))) != 0 && fd != v17 && v5 != v17 )
{
v18 = strlen(v11 + 1);
send(v17, v11 + 1, v18, 0);
}
++v17;
}
while ( v17 <= v3 );
}
}
goto LABEL_25;
}
v14 = 1;
}
v4 = v11 + 1;
(*(&v24 + 2 * v14))((unsigned int)v5, v11 + 1);
goto LABEL_28;
}
}
fwrite("Error in select()\n", 1uLL, 0x12uLL, stderr);
}
}
return 1;
}

original_code:
int main(int argc, char *argv[]) {
 int s, inc, numfds;
 struct sockaddr_storage sinc;
 struct commands cmd[] = { {"reverse", reverse},
        {"whoami", whoami}
       };
 fd_set md, rd;
 if(argc < 3) {
  fprintf(stderr, "usage: %s <host> <port>\n", argv[0]);
  return 1;
 }
 s = con(argv[1], argv[2], 0);
 if(listen(s, 10) == -1) {
  close(s);
  fprintf(stderr, "Error listening!\n");
  return 1;
 }
 numfds = s;
 do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&md)->__fds_bits)[0]) : "memory"); } while (0);
 do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&rd)->__fds_bits)[0]) : "memory"); } while (0);
 ((void) (((&md)->__fds_bits)[((s) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((s) % (8 * (int) sizeof (__fd_mask)))))));
 while(1) {
  int msglen, i;
  socklen_t addr_len;
  char *data = malloc(sizeof(char) * 1024);
  rd = md;
  if(select(numfds+1, &rd, 0, 0, 0) == -1) {
   fprintf(stderr, "Error in select()\n");
   return 1;
  }
  for(i = 0; i <= numfds; i++) {
   if(((((&rd)->__fds_bits)[((i) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((i) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
    if(i == s) {
     addr_len = sizeof sinc;
     if((inc = accept(s, (struct sockaddr *)&sinc, &addr_len)) == -1) {
      fprintf(stderr, "Error in accept()\n");
     }
     else {
      ((void) (((&md)->__fds_bits)[((inc) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((inc) % (8 * (int) sizeof (__fd_mask)))))));
      if(inc > numfds)
       numfds = inc;
      printf("Connected by someone!\n");
     }
    }
    else {
     if((msglen = recv(i, data, 1024 -1, 0)) <= 0) {
      if(msglen == 0)
       fprintf(stderr, "Socket %d disconnected.\n", i);
      else
       fprintf(stderr, "Error in recv()\n");
      close(i);
      ((void) (((&md)->__fds_bits)[((i) / (8 * (int) sizeof (__fd_mask)))] &= ~((__fd_mask) (1UL << ((i) % (8 * (int) sizeof (__fd_mask)))))));
     }
     else {
      char *index;
      int j;
      data[msglen] = '\0';
      printf("Got data: %s\nProcessing and sending...\n", data);
      if((index = strchr(data, ';')) != ((void *)0)) {
       for(j = 0; j < sizeof(cmd)/sizeof(cmd[0]); j++) {
        if(!strncmp(data, cmd[j].name, index-data)) {
         data = index + 1;
         cmd[j].func(i, data);
         break;
        }
       }
       if(!strncmp(data, "broadcast", index-data)) {
        printf("Sending broadcast...\n");
        data = index + 1;
        for(j = 0; j <= numfds; j++) {
         if(((((&md)->__fds_bits)[((j) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((j) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
          if(j != s && j != i) {
           send(j, data, strlen(data), 0);
          }
         }
        }
       }
      }
      send(i, data, strlen(data), 0);
     }
    }
   }
  }
 }
 close(s);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
 int s; int inc; int numfds;
 struct sockaddr_storage sinc;
 struct commands cmd[] = { {"reverse", reverse},
        {"whoami", whoami}
       };
 struct fd_set md; struct fd_set rd;
 if(argc < 3) {
  fprintf(stderr, "usage: %s <host> <port>\n", argv[0]);
  return 1;
 }
 s = con(argv[1], argv[2], 0);
 if(listen(s, 10) == -1) {
  close(s);
  fprintf(stderr, "Error listening!\n");
  return 1;
 }
 numfds = s;
 do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&md)->__fds_bits)[0]) : "memory"); } while (0);
 do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&rd)->__fds_bits)[0]) : "memory"); } while (0);
 ((void) (((&md)->__fds_bits)[((s) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((s) % (8 * (int) sizeof (__fd_mask)))))));
 while(1) {
  int msglen; int i;
  unsigned int addr_len;
  char *data = malloc(sizeof(char) * 1024);
  rd = md;
  if(select(numfds+1, &rd, 0, 0, 0) == -1) {
   fprintf(stderr, "Error in select()\n");
   return 1;
  }
  for(i = 0; i <= numfds; i++) {
   if(((((&rd)->__fds_bits)[((i) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((i) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
    if(i == s) {
     addr_len = sizeof sinc;
     if((inc = accept(s, (struct sockaddr *)&sinc, &addr_len)) == -1) {
      fprintf(stderr, "Error in accept()\n");
     }
     else {
      ((void) (((&md)->__fds_bits)[((inc) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((inc) % (8 * (int) sizeof (__fd_mask)))))));
      if(inc > numfds)
       numfds = inc;
      printf("Connected by someone!\n");
     }
    }
    else {
     if((msglen = recv(i, data, 1024 -1, 0)) <= 0) {
      if(msglen == 0)
       fprintf(stderr, "Socket %d disconnected.\n", i);
      else
       fprintf(stderr, "Error in recv()\n");
      close(i);
      ((void) (((&md)->__fds_bits)[((i) / (8 * (int) sizeof (__fd_mask)))] &= ~((__fd_mask) (1UL << ((i) % (8 * (int) sizeof (__fd_mask)))))));
     }
     else {
      char *index;
      int j;
      data[msglen] = '\0';
      printf("Got data: %s\nProcessing and sending...\n", data);
      if((index = strchr(data, ';')) != ((void *)0)) {
       for(j = 0; j < sizeof(cmd)/sizeof(cmd[0]); j++) {
        if(!strncmp(data, cmd[j].name, index-data)) {
         data = index + 1;
         cmd[j].func(i, data);
         break;
        }
       }
       if(!strncmp(data, "broadcast", index-data)) {
        printf("Sending broadcast...\n");
        data = index + 1;
        for(j = 0; j <= numfds; j++) {
         if(((((&md)->__fds_bits)[((j) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((j) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
          if(j != s && j != i) {
           send(j, data, strlen(data), 0);
          }
         }
        }
       }
      }
      send(i, data, strlen(data), 0);
     }
    }
   }
  }
 }
 close(s);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: inc int

variable_types: numfds int

variable_types: struct sockaddr_storage { unsigned short ss_family; char __ss_padding[-1]; unsigned long __ss_align; }

variable_types: struct commands { char *name; void (*func)(int, char *); } []

variable_types:
md
struct fd_set { long __fds_bits[-1]; }

variable_types:
rd
struct fd_set { long __fds_bits[-1]; }

variable_types: msglen int

variable_types: i int

variable_types:
index
char *

variable_types: j int

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


repo: profil/raytracer

original_code:
int sphere_intersect(struct ray r, struct sphere *spheres, int spheres_len, int *sphere_id) {
 int i;
 float t = 100000, distance = 0;
 for(i = 0; i < spheres_len; i++) {
  distance = sphere_collision(r, spheres[i]);
  if(distance > 0.0f) {
   if(distance < t) {
    t = distance;
    *sphere_id = i;
   }
  }
 }
 return t != 100000 ? t : 0;
}

canonical_original_code:
int sphere_intersect(struct ray r, struct sphere *spheres, int spheres_len, int *sphere_id) {
 int i;
 float t = 100000; float distance = 0;
 for(i = 0; i < spheres_len; i++) {
  distance = sphere_collision(r, spheres[i]);
  if(distance > 0.0f) {
   if(distance < t) {
    t = distance;
    *sphere_id = i;
   }
  }
 }
 return t != 100000 ? t : 0;
}

variable_types: struct ray { struct vector { float x; } p; struct vector d; }

variable_types: struct sphere { struct vector c; float r; unsigned int color; } *

variable_types: t float

variable_types: distance float

user_defined_types: struct ray { struct vector p; struct vector d; }


vec

decompiled_code:
__m128i __fastcall vec(float a1, float a2)
{
__m128i v3; // [rsp+0h] [rbp-14h] BYREF

v3.m128i_i64[0] = __PAIR64__(LODWORD(a2), LODWORD(a1));
return _mm_loadl_epi64(&v3);
}

canonical_decompiled_code:
__m128i __fastcall func0(float a1, float a2)
{
__m128i v3; // [rsp+0h] [rbp-14h] BYREF

v3.m128i_i64[0] = __PAIR64__(LODWORD(a2), LODWORD(a1));
return _mm_loadl_epi64(&v3);
}

original_code:
struct vector vec(float x, float y, float z) {
 struct vector c;
 c.x = x;
 c.y = y;
 c.z = z;
 return c;
}

variable_types: x float

variable_types: y float

variable_types: z float

variable_types:
c
struct vector { float x; }

return_type: struct vector { float x; }


add

original_code:
struct vector add(struct vector a, struct vector b) {
 struct vector c;
 c.x = a.x + b.x;
 c.y = a.y + b.y;
 c.z = a.z + b.z;
 return c;
}

variable_types:
a
struct vector

variable_types:
b
struct vector