addfunc

original_code:
void addfunc(envir *e,int pos,tsfunc *fun)
{
 tsval v;
 {(&v)->t=type_func;(&v)->func=fun;};
 ts_setarray(&e->funlist,pos,&v);
}

canonical_original_code:
void addfunc(struct envir *e, int pos, struct tsfunc *fun)
{
 struct tsval v;
 {(&v)->t=type_func;(&v)->func=fun;};
 ts_setarray(&e->funlist,pos,&v);
}

variable_types: pos int

variable_types:
fun
struct tsfunc *

variable_types: struct tsval { unsigned char t; int reg; union { struct tstable { struct tsgarbage { struct tsgarbage *next; unsigned char color; unsigned char type; } gchead; struct tnode { struct tsval key; struct tsval data; struct tnode *next; struct tnode *pre; unsigned char used; } *slot; struct tnode *head; int size; int used; } *tab; struct tsstr { struct tsgarbage gchead; unsigned int hash; unsigned char *buf; int len; } *str; struct tsarray { struct tsgarbage gchead; struct tsval *data; int enumptr; int size; int used; } *a; struct tsfunc { unsigned char functype; struct tsfunc *parent; struct envir { struct symtable { struct symnode { struct tsstr *key; int data; struct symnode *next; } *slot; struct symnode *head; int size; int used; } strt; struct symtable funt; struct tsarray funlist; struct csttable { struct cstnode { unsigned long long key; unsigned short data; struct cstnode *next; } *slot; struct cstnode *head; int size; int used; } cstt; struct tsfunc global; } *e; struct symtable symbol; struct tsarray local; struct tsarray global; struct tsval *reg[256]; unsigned int regus[32]; struct tsstr *name; union { unsigned int *code; int (*funbody)(struct tsvm { struct envir *e; int line; struct tsframe { int pc; int regbase; int varbase; struct tsfunc *funbody; } curf; struct tsframe *cstack; struct tsval *dstack; struct tsstr **strtable; int stsize; unsigned long long *cstt; int cstsize; struct tsfunc **ftlist; int ftsize; struct tsval retval; int csp; int dsp; char flag; int lastret; struct tsgarbage *gclist; int step_count; int gcobj_count; unsigned char gcstate; unsigned char gcflag; } *, int); }; int lastjump; int lastloop; int paramnum; int codesize; int used; int pc; } *func; double fnum; int inum; }; }


addbuiltin

repo: ototsuyume/tinyscript

original_code:
void addbuiltin(envir *e,funcdef fd[])
{
 tsstr *pname;
 tsfunc *func;
 tsval v;
 int pos,i=0;
 memset(&v,0,sizeof(tsval));
 while(fd[i].name[0]!=0)
 {
  pname = ts_newstring(e,(byte*)(fd[i].name),(uint)strlen((char*)fd[i].name));
  func = ts_newfunc(pname,e,1);
  func->functype = native;
  func->funbody = fd[i].fun;
  func->paramnum = fd[i].pcount;
  v.t = type_func;
  v.func = func;
  pos = e->funt.used;
  setsymbol(&e->funt,pname,pos);
  ts_appendarray(&e->funlist,&v);
  ++i;
 }
}

canonical_original_code:
void addbuiltin(struct envir *e, struct funcdef fd[])
{
 struct tsstr *pname;
 struct tsfunc *func;
 struct tsval v;
 int pos; int i = 0;
 memset(&v,0,sizeof(tsval));
 while(fd[i].name[0]!=0)
 {
  pname = ts_newstring(e,(unsigned char *)(fd[i].name),(unsigned int)strlen((char *)fd[i].name));
  func = ts_newfunc(pname,e,1);
  func->functype = native;
  func->funbody = fd[i].fun;
  func->paramnum = fd[i].pcount;
  v.t = type_func;
  v.func = func;
  pos = e->funt.used;
  setsymbol(&e->funt,pname,pos);
  ts_appendarray(&e->funlist,&v);
  ++i;
 }
}

variable_types: struct envir { struct symtable { struct symnode { struct tsstr { struct tsgarbage { struct tsgarbage *next; unsigned char color; unsigned char type; } gchead; unsigned int hash; unsigned char *buf; int len; } *key; int data; struct symnode *next; } *slot; struct symnode *head; int size; int used; } strt; struct symtable funt; struct tsarray { struct tsgarbage gchead; struct tsval { unsigned char t; int reg; union { struct tstable { struct tsgarbage gchead; struct tnode { struct tsval key; struct tsval data; struct tnode *next; struct tnode *pre; unsigned char used; } *slot; struct tnode *head; int size; int used; } *tab; struct tsstr *str; struct tsarray *a; struct tsfunc { unsigned char functype; struct tsfunc *parent; struct envir *e; struct symtable symbol; struct tsarray local; struct tsarray global; struct tsval *reg[256]; unsigned int regus[32]; struct tsstr *name; union { unsigned int *code; int (*funbody)(struct tsvm { struct envir *e; int line; struct tsframe { int pc; int regbase; int varbase; struct tsfunc *funbody; } curf; struct tsframe *cstack; struct tsval *dstack; struct tsstr **strtable; int stsize; unsigned long long *cstt; int cstsize; struct tsfunc **ftlist; int ftsize; struct tsval retval; int csp; int dsp; char flag; int lastret; struct tsgarbage *gclist; int step_count; int gcobj_count; unsigned char gcstate; unsigned char gcflag; } *, int); }; int lastjump; int lastloop; int paramnum; int codesize; int used; int pc; } *func; double fnum; int inum; }; } *data; int enumptr; int size; int used; } funlist; struct csttable { struct cstnode { unsigned long long key; unsigned short data; struct cstnode *next; } *slot; struct cstnode *head; int size; int used; } cstt; struct tsfunc global; } *

variable_types: struct funcdef { char *name; int (*fun)(struct tsvm *, int); int pcount; } []

variable_types: struct tsfunc { unsigned char functype; struct tsfunc *parent; struct envir { struct symtable { struct symnode { struct tsstr { struct tsgarbage { struct tsgarbage *next; unsigned char color; unsigned char type; } gchead; unsigned int hash; unsigned char *buf; int len; } *key; int data; struct symnode *next; } *slot; struct symnode *head; int size; int used; } strt; struct symtable funt; struct tsarray { struct tsgarbage gchead; struct tsval { unsigned char t; int reg; union { struct tstable { struct tsgarbage gchead; struct tnode { struct tsval key; struct tsval data; struct tnode *next; struct tnode *pre; unsigned char used; } *slot; struct tnode *head; int size; int used; } *tab; struct tsstr *str; struct tsarray *a; struct tsfunc *func; double fnum; int inum; }; } *data; int enumptr; int size; int used; } funlist; struct csttable { struct cstnode { unsigned long long key; unsigned short data; struct cstnode *next; } *slot; struct cstnode *head; int size; int used; } cstt; struct tsfunc global; } *e; struct symtable symbol; struct tsarray local; struct tsarray global; struct tsval *reg[256]; unsigned int regus[32]; struct tsstr *name; union { unsigned int *code; int (*funbody)(struct tsvm { struct envir *e; int line; struct tsframe { int pc; int regbase; int varbase; struct tsfunc *funbody; } curf; struct tsframe *cstack; struct tsval *dstack; struct tsstr **strtable; int stsize; unsigned long long *cstt; int cstsize; struct tsfunc **ftlist; int ftsize; struct tsval retval; int csp; int dsp; char flag; int lastret; struct tsgarbage *gclist; int step_count; int gcobj_count; unsigned char gcstate; unsigned char gcflag; } *, int); }; int lastjump; int lastloop; int paramnum; int codesize; int used; int pc; } *

variable_types: i int

return_type: void

user_defined_types: struct tsval { unsigned char t; int reg; union { struct tstable *tab; struct tsstr *str; struct tsarray *a; struct tsfunc *func; double fnum; int inum; }; }

user_defined_types: struct envir { struct symtable strt; struct symtable funt; struct tsarray funlist; struct csttable cstt; struct tsfunc global; }

user_defined_types: struct tsstr { struct tsgarbage gchead; unsigned int hash; unsigned char *buf; int len; }

user_defined_types: struct tsfunc { unsigned char functype; struct tsfunc *parent; struct envir *e; struct symtable symbol; struct tsarray local; struct tsarray global; struct tsval *reg[256]; unsigned int regus[32]; struct tsstr *name; union { unsigned int *code; int (*funbody)(struct tsvm *, int); }; int lastjump; int lastloop; int paramnum; int codesize; int used; int pc; }

user_defined_types: struct symtable { struct symnode *slot; struct symnode *head; int size; int used; }

user_defined_types: struct tsarray { struct tsgarbage gchead; struct tsval *data; int enumptr; int size; int used; }

user_defined_types: struct csttable { struct cstnode *slot; struct cstnode *head; int size; int used; }

user_defined_types: struct tstable { struct tsgarbage gchead; struct tnode *slot; struct tnode *head; int size; int used; }

user_defined_types: struct symnode { struct tsstr *key; int data; struct symnode *next; }

user_defined_types: struct tsvm { struct envir *e; int line; struct tsframe curf; struct tsframe *cstack; struct tsval *dstack; struct tsstr **strtable; int stsize; unsigned long long *cstt; int cstsize; struct tsfunc **ftlist; int ftsize; struct tsval retval; int csp; int dsp; char flag; int lastret; struct tsgarbage *gclist; int step_count; int gcobj_count; unsigned char gcstate; unsigned char gcflag; }


genhash

decompiled_code:
__int64 __fastcall genhash(unsigned __int8 *a1, int a2)
{
int v2; // eax
__int64 v3; // rdx
__int64 result; // rax

v2 = (*a1 + 1) << 7;
if ( a2 > 0 )
{
v3 = (__int64)&a1[a2 - 1 + 1];
do
v2 = *a1++ ^ (1000003 * v2);
while ( a1 != (unsigned __int8 *)v3 );
}
result = a2 ^ (unsigned int)v2;
if ( (_DWORD)result == -1 )
result = 4294967294LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 *a1, int a2)
{
int v2; // eax
__int64 v3; // rdx
__int64 result; // rax

v2 = (*a1 + 1) << 7;
if ( a2 > 0 )
{
v3 = (__int64)&a1[a2 - 1 + 1];
do
v2 = *a1++ ^ (1000003 * v2);
while ( a1 != (unsigned __int8 *)v3 );
}
result = a2 ^ (unsigned int)v2;
if ( (_DWORD)result == -1 )
result = 4294967294LL;
return result;
}

original_code:
int genhash(const byte *data,int len)
{
 uint s;
 int ret;
 s = len;
 ret = (*data+1)<<7;
 while(--len >= 0)
  ret = (1000003*ret)^*data++;
 ret^=s;
 if(ret == -1)
  ret = -2;
 return ret;
}

canonical_original_code:
int genhash(unsigned char *data, int len)
{
 unsigned int s;
 int ret;
 s = len;
 ret = (*data+1)<<7;
 while(--len >= 0)
  ret = (1000003*ret)^*data++;
 ret^=s;
 if(ret == -1)
  ret = -2;
 return ret;
}

variable_types:
data
unsigned char *

variable_types: len int

variable_types:
s
unsigned int

variable_types: ret int

return_type: int


loadbinary

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

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

original_code:
tsvm* loadbinary(char *buf)
{
 return ((void *)0);
}

canonical_original_code:
struct tsvm *loadbinary(char *buf)
{
 return ((void *)0);
}

variable_types:
buf
char *

return_type: struct tsvm { struct envir { struct symtable { struct symnode { struct tsstr { struct tsgarbage { struct tsgarbage *next; unsigned char color; unsigned char type; } gchead; unsigned int hash; unsigned char *buf; int len; } *key; int data; struct symnode *next; } *slot; struct symnode *head; int size; int used; } strt; struct symtable funt; struct tsarray { struct tsgarbage gchead; struct tsval { unsigned char t; int reg; union { struct tstable { struct tsgarbage gchead; struct tnode { struct tsval key; struct tsval data; struct tnode *next; struct tnode *pre; unsigned char used; } *slot; struct tnode *head; int size; int used; } *tab; struct tsstr *str; struct tsarray *a; struct tsfunc { unsigned char functype; struct tsfunc *parent; struct envir *e; struct symtable symbol; struct tsarray local; struct tsarray global; struct tsval *reg[256]; unsigned int regus[32]; struct tsstr *name; union { unsigned int *code; int (*funbody)(struct tsvm *, int); }; int lastjump; int lastloop; int paramnum; int codesize; int used; int pc; } *func; double fnum; int inum; }; } *data; int enumptr; int size; int used; } funlist; struct csttable { struct cstnode { unsigned long long key; unsigned short data; struct cstnode *next; } *slot; struct cstnode *head; int size; int used; } cstt; struct tsfunc global; } *e; int line; struct tsframe { int pc; int regbase; int varbase; struct tsfunc *funbody; } curf; struct tsframe *cstack; struct tsval *dstack; struct tsstr **strtable; int stsize; unsigned long long *cstt; int cstsize; struct tsfunc **ftlist; int ftsize; struct tsval retval; int csp; int dsp; char flag; int lastret; struct tsgarbage *gclist; int step_count; int gcobj_count; unsigned char gcstate; unsigned char gcflag; } *


loadsrc

decompiled_code:
__int64 __fastcall loadsrc(__int64 a1)
{
__int64 v2[36]; // [rsp+0h] [rbp-10188h] BYREF
int v3; // [rsp+120h] [rbp-10068h]

initlex(v2, a1);
gettoken(v2);
gettoken(v2);
while ( v3 != 281 )
dostatement(v2);
return newvm(v2[0]);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 v2[36]; // [rsp+0h] [rbp-10188h] BYREF
int v3; // [rsp+120h] [rbp-10068h]

initlex(v2, a1);
gettoken(v2);
gettoken(v2);
while ( v3 != 281 )
dostatement(v2);
return newvm(v2[0]);
}

original_code:
tsvm* loadsrc(char *buf)
{
 filestate fs;
 tsvm *vm;
 initlex(&fs,buf);
 gettoken(&fs);
 gettoken(&fs);
 while(((&fs)->cur.t)!=tk_eof)
  dostatement(&fs);
 vm = newvm(fs.envirnment);
 return vm;
}

canonical_original_code:
struct tsvm *loadsrc(char *buf)
{
 struct filestate fs;
 struct tsvm *vm;
 initlex(&fs,buf);
 gettoken(&fs);
 gettoken(&fs);
 while(((&fs)->cur.t)!=tk_eof)
  dostatement(&fs);
 vm = newvm(fs.envirnment);
 return vm;
}

variable_types: struct filestate { struct envir { struct symtable { struct symnode { struct tsstr { struct tsgarbage { struct tsgarbage *next; unsigned char color; unsigned char type; } gchead; unsigned int hash; unsigned char *buf; int len; } *key; int data; struct symnode *next; } *slot; struct symnode *head; int size; int used; } strt; struct symtable funt; struct tsarray { struct tsgarbage gchead; struct tsval { unsigned char t; int reg; union { struct tstable { struct tsgarbage gchead; struct tnode { struct tsval key; struct tsval data; struct tnode *next; struct tnode *pre; unsigned char used; } *slot; struct tnode *head; int size; int used; } *tab; struct tsstr *str; struct tsarray *a; struct tsfunc { unsigned char functype; struct tsfunc *parent; struct envir *e; struct symtable symbol; struct tsarray local; struct tsarray global; struct tsval *reg[256]; unsigned int regus[32]; struct tsstr *name; union { unsigned int *code; int (*funbody)(struct tsvm { struct envir *e; int line; struct tsframe { int pc; int regbase; int varbase; struct tsfunc *funbody; } curf; struct tsframe *cstack; struct tsval *dstack; struct tsstr **strtable; int stsize; unsigned long long *cstt; int cstsize; struct tsfunc **ftlist; int ftsize; struct tsval retval; int csp; int dsp; char flag; int lastret; struct tsgarbage *gclist; int step_count; int gcobj_count; unsigned char gcstate; unsigned char gcflag; } *, int); }; int lastjump; int lastloop; int paramnum; int codesize; int used; int pc; } *func; double fnum; int inum; }; } *data; int enumptr; int size; int used; } funlist; struct csttable { struct cstnode { unsigned long long key; unsigned short data; struct cstnode *next; } *slot; struct cstnode *head; int size; int used; } cstt; struct tsfunc global; } *envirnment; struct tsfunc *curframe; unsigned char enterlevel; unsigned char looplevel; unsigned char inifblock; unsigned char usedreg[256]; unsigned char regpos; struct tsval *cst2reg; struct token { int t; char *pos; union { struct tsstr *str; int inum; double fnum; }; } cur; struct token next; char *buff; char *pos; char *curl; char *nextl; int size; int line; char tkbuf[65535]; }

variable_types: struct tsvm { struct envir { struct symtable { struct symnode { struct tsstr { struct tsgarbage { struct tsgarbage *next; unsigned char color; unsigned char type; } gchead; unsigned int hash; unsigned char *buf; int len; } *key; int data; struct symnode *next; } *slot; struct symnode *head; int size; int used; } strt; struct symtable funt; struct tsarray { struct tsgarbage gchead; struct tsval { unsigned char t; int reg; union { struct tstable { struct tsgarbage gchead; struct tnode { struct tsval key; struct tsval data; struct tnode *next; struct tnode *pre; unsigned char used; } *slot; struct tnode *head; int size; int used; } *tab; struct tsstr *str; struct tsarray *a; struct tsfunc { unsigned char functype; struct tsfunc *parent; struct envir *e; struct symtable symbol; struct tsarray local; struct tsarray global; struct tsval *reg[256]; unsigned int regus[32]; struct tsstr *name; union { unsigned int *code; int (*funbody)(struct tsvm *, int); }; int lastjump; int lastloop; int paramnum; int codesize; int used; int pc; } *func; double fnum; int inum; }; } *data; int enumptr; int size; int used; } funlist; struct csttable { struct cstnode { unsigned long long key; unsigned short data; struct cstnode *next; } *slot; struct cstnode *head; int size; int used; } cstt; struct tsfunc global; } *e; int line; struct tsframe { int pc; int regbase; int varbase; struct tsfunc *funbody; } curf; struct tsframe *cstack; struct tsval *dstack; struct tsstr **strtable; int stsize; unsigned long long *cstt; int cstsize; struct tsfunc **ftlist; int ftsize; struct tsval retval; int csp; int dsp; char flag; int lastret; struct tsgarbage *gclist; int step_count; int gcobj_count; unsigned char gcstate; unsigned char gcflag; } *

user_defined_types: struct filestate { struct envir *envirnment; struct tsfunc *curframe; unsigned char enterlevel; unsigned char looplevel; unsigned char inifblock; unsigned char usedreg[256]; unsigned char regpos; struct tsval *cst2reg; struct token cur; struct token next; char *buff; char *pos; char *curl; char *nextl; int size; int line; char tkbuf[65535]; }


loadfile

decompiled_code:
__int64 __fastcall loadfile(const char *a1)
{
int v1; // edx
__int64 result; // rax
void *v3; // rax
struct stat v4; // [rsp+0h] [rbp-98h] BYREF

v1 = lstat(a1, &v4);
result = 0LL;
if ( !v1 )
{
v3 = readfile(a1);
result = loadsrc((__int64)v3);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(const char *a1)
{
int v1; // edx
__int64 result; // rax
void *v3; // rax
struct stat v4; // [rsp+0h] [rbp-98h] BYREF

v1 = lstat(a1, &v4);
result = 0LL;
if ( !v1 )
{
v3 = func0(a1);
result = func2((__int64)v3);
}
return result;
}

original_code:
tsvm* loadfile(const char* filename)
{
 char binfile[512];
 char *buf;
 uint filetime;
 tsvm *vm = ((void *)0);
 struct stat st;
 if(lstat(filename,&st)!=0)
  goto err;
 filetime = (uint)st.st_mtim.tv_sec;
 buf = readfile(filename);
 vm = loadsrc(buf);
err:
 return vm;
}

canonical_original_code:
struct tsvm *loadfile(char *filename)
{
 char binfile[512];
 char *buf;
 unsigned int filetime;
 struct tsvm *vm = ((void *)0);
 struct stat st;
 if(lstat(filename,&st)!=0)
  goto err;
 filetime = (unsigned int)st.st_mtim.tv_sec;
 buf = readfile(filename);
 vm = loadsrc(buf);
err:
 return vm;
}

variable_types:
filename
char *

variable_types:
binfile
char [512]

variable_types:
filetime
unsigned int

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

user_defined_types: struct tsframe { int pc; int regbase; int varbase; struct tsfunc *funbody; }

user_defined_types: struct cstnode { unsigned long long key; unsigned short data; struct cstnode *next; }

user_defined_types: struct tsgarbage { struct tsgarbage *next; unsigned char color; unsigned char type; }

user_defined_types: struct tnode { struct tsval key; struct tsval data; struct tnode *next; struct tnode *pre; unsigned char used; }


repo: ottypes/libot

decompiled_code:
size_t __fastcall str_num_bytes(const char *a1)
{
size_t result; // rax

if ( *(_QWORD *)a1 )
result = *((_QWORD *)a1 + 1);
else
result = strlen(a1 + 8);
return result;
}

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

if ( *(_QWORD *)a1 )
result = *((_QWORD *)a1 + 1);
else
result = strlen(a1 + 8);
return result;
}

original_code:
static inline size_t str_num_bytes(const str *s) {
  return s->mem ? s->num_bytes : strlen((const char *)s->chars);
}

canonical_original_code:
static inline unsigned long str_num_bytes(struct str *s) {
  return s->mem ? s->num_bytes : strlen((char *)s->chars);
}

variable_types: struct str { unsigned char *mem; union { struct { unsigned long num_bytes; unsigned long num_chars; }; unsigned char chars[-1]; }; } *

return_type: unsigned long


decompiled_code:
__int64 __fastcall str_num_chars(_QWORD *a1)
{
__int64 result; // rax

if ( *a1 )
result = a1[2];
else
result = strlen_utf8(a1 + 1);
return result;
}

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

if ( *a1 )
result = a1[2];
else
result = strlen_utf8(a1 + 1);
return result;
}

original_code:
static inline size_t str_num_chars(const str *s) {
  return s->mem ? s->num_chars : strlen_utf8(s->chars);
}

canonical_original_code:
static inline unsigned long str_num_chars(struct str *s) {
  return s->mem ? s->num_chars : strlen_utf8(s->chars);
}

user_defined_types: struct str { unsigned char *mem; union { struct { unsigned long num_bytes; unsigned long num_chars; }; unsigned char chars[-1]; }; }


decompiled_code:
void __fastcall str_init(__int64 a1)
{
*(_QWORD *)a1 = 0LL;
*(_BYTE *)(a1 + 8) = 0;
}

original_code:
void str_init(str *s) {
  s->mem = ((void *)0);
  s->chars[0] = '\0';
}

canonical_original_code:
void str_init(struct str *s) {
  s->mem = ((void *)0);
  s->chars[0] = '\0';
}


decompiled_code:
void __fastcall str_destroy(void **a1)
{
void *v1; // rdi

v1 = *a1;
if ( v1 )
free(v1);
}

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

v1 = *a1;
if ( v1 )
free(v1);
}

original_code:
void str_destroy(str *s) {
  if (s->mem) {
    free(s->mem);
  }
}

canonical_original_code:
void str_destroy(struct str *s) {
  if (s->mem) {
    free(s->mem);
  }
}


bf

repo: otz/brainf--k

decompiled_code:
int bf()
{
_BYTE *v0; // rax
_BYTE *v1; // rbp
_BYTE *v2; // rbx
_BYTE *v3; // rax

v0 = &data;
do
*v0++ = 0;
while ( v0 != (_BYTE *)&unk_40B5B0 );
v1 = &unk_407B18;
v2 = &tape;
do
{
LODWORD(v3) = (unsigned __int8)*v2;
if ( !(_BYTE)v3 )
break;
LODWORD(v3) = (unsigned __int8)((_BYTE)v3 - 43);
switch ( (char)v3 )
{
case 0:
++*v1;
break;
case 1:
LODWORD(v3) = getchar();
*v1 = (_BYTE)v3;
break;
case 2:
--*v1;
break;
case 3:
LODWORD(v3) = putchar((char)*v1);
break;
case 17:
--v1;
break;
case 19:
++v1;
break;
case 48:
if ( !*v1 )
{
v3 = forward(v2);
v2 = v3;
}
break;
case 50:
if ( *v1 )
{
v3 = backward(v2);
v2 = v3;
}
break;
default:
break;
}
++v2;
}
while ( v2 < (_BYTE *)&end );
return (int)v3;
}

canonical_decompiled_code:
int func7()
{
_BYTE *v0; // rax
_BYTE *v1; // rbp
_BYTE *v2; // rbx
_BYTE *v3; // rax

v0 = &data;
do
*v0++ = 0;
while ( v0 != (_BYTE *)&unk_40B5B0 );
v1 = &unk_407B18;
v2 = &tape;
do
{
LODWORD(v3) = (unsigned __int8)*v2;
if ( !(_BYTE)v3 )
break;
LODWORD(v3) = (unsigned __int8)((_BYTE)v3 - 43);
switch ( (char)v3 )
{
case 0:
++*v1;
break;
case 1:
LODWORD(v3) = getchar();
*v1 = (_BYTE)v3;
break;
case 2:
--*v1;
break;
case 3:
LODWORD(v3) = putchar((char)*v1);
break;
case 17:
--v1;
break;
case 19:
++v1;
break;
case 48:
if ( !*v1 )
{
v3 = forward(v2);
v2 = v3;
}
break;
case 50:
if ( *v1 )
{
v3 = backward(v2);
v2 = v3;
}
break;
default:
break;
}
++v2;
}
while ( v2 < (_BYTE *)&end );
return (int)v3;
}

original_code:
int bf()
{
 char *p = tape;
 char *d = data;
 while ( d < data + sizeof(data) )
  *(d++) = 0;
 d = data + sizeof(data) / 2;
 while ( p < tape + sizeof(tape) && *p) {
  switch (*p) {
   case ',': *d=getchar(); break;
   case '.': putchar(*d); break;
   case '+': (*d)++; break;
   case '-': (*d)--; break;
   case '<': d--; break;
   case '>': d++; break;
   case '[': if (!(*d)) p = forward(p); break;
   case ']': if (*d) p = backward(p); break;
   default:
    break;
  }
  p++;
 }
}

variable_types:
p
char *

variable_types:
d
char *


repo: oySophia/matrix

decompiled_code:
double d_random()
{
return ((double)(rand() % 0x7FFFFFFF) + 0.0) / 2147483647.0;
}

canonical_decompiled_code:
double func0()
{
return ((double)(rand() % 0x7FFFFFFF) + 0.0) / 2147483647.0;
}

variable_types: a int

variable_types: x double

return_type: double


original_code:
void generate_matrix(double *mat, int rows, int cols, int mark, double sparse) {
 int i, j;
 int m, n, range, step;
 if(mark) {
  m = 0;
  n = 0;
  for(i = 0; i < rows; ++i) {
   for(j = 0; j < cols; ++j) {
    mat[i * rows + j] = 0;
   }
  }
  range = 1 / sparse * 2;
  srand((int) time(0));
  while(1) {
   step = rand() % range;
   n += step;
   if(n >= cols) {
    n %= cols;
    m += 1;
   } else if((m != 0 || n != 0) && step == 0) {
    continue;
   }
   if(m >= rows) {
    break;
   }
   mat[m * rows + n] = (double)rand()/2147483647;
  }
 } else {
  srand((int) time(0));
  for(i = 0; i < rows; ++i) {
   for(j = 0; j < cols; ++j) {
    mat[i * rows + j] = d_random();
   }
  }
 }
 printf("get1\n");
 for(i = 0; i < rows; ++i) {
  for(j = 0; j < cols; ++j) {
   printf("%lf ", mat[i * rows + j]);
  }
  printf("\n");
 }
 printf("get2\n");
}

canonical_original_code:
void generate_matrix(double *mat, int rows, int cols, int mark, double sparse) {
 int i; int j;
 int m; int n; int range; int step;
 if(mark) {
  m = 0;
  n = 0;
  for(i = 0; i < rows; ++i) {
   for(j = 0; j < cols; ++j) {
    mat[i * rows + j] = 0;
   }
  }
  range = 1 / sparse * 2;
  srand((int) time(0));
  while(1) {
   step = rand() % range;
   n += step;
   if(n >= cols) {
    n %= cols;
    m += 1;
   } else if((m != 0 || n != 0) && step == 0) {
    continue;
   }
   if(m >= rows) {
    break;
   }
   mat[m * rows + n] = (double)rand()/2147483647;
  }
 } else {
  srand((int) time(0));
  for(i = 0; i < rows; ++i) {
   for(j = 0; j < cols; ++j) {
    mat[i * rows + j] = d_random();
   }
  }
 }
 printf("get1\n");
 for(i = 0; i < rows; ++i) {
  for(j = 0; j < cols; ++j) {
   printf("%lf ", mat[i * rows + j]);
  }
  printf("\n");
 }
 printf("get2\n");
}

variable_types:
mat
double *

variable_types: rows int

variable_types: cols int

variable_types: mark int

variable_types: sparse double

variable_types: i int

variable_types: j int

variable_types: m int

variable_types: n int

variable_types: range int

variable_types: step int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v3; // rax

v3 = malloc(0x3C0uLL);
generate_matrix(v3, 12LL, 10LL, 1LL, 0.001);
puts("1");
return 0;
}

original_code:
int main() {
 int m = 12, n = 10;
 double *matrix;;
 matrix = (double *) malloc (sizeof(double) * m * n);
 generate_matrix(matrix, m, n, 1, 0.001);
 printf("1\n");
 return 0;
}

canonical_original_code:
int main() {
 int m = 12; int n = 10;
 double *matrix;;
 matrix = (double *) malloc (sizeof(double) * m * n);
 generate_matrix(matrix, m, n, 1, 0.001);
 printf("1\n");
 return 0;
}

variable_types:
matrix
double *


repo: oySophia/multilib

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_DWORD *v3; // rax
_DWORD *v4; // rsi
_DWORD *v5; // rdx

v3 = malloc(0x18uLL);
v4 = v3;
qword_404068 = (__int64)v3;
v5 = v3 + 6;
do
*v3++ = 1;
while ( v3 != v5 );
printf("the tmp[i] = %d\n", v4);
qword_404068 += 4LL;
printf("the tmp[i] = %d\t\t %d\n", qword_404068, *(unsigned int *)qword_404068);
printf("the higher bit is %x, the lower bits are %x\n", 10LL, 11LL);
return 0;
}

original_code:
int main(int argc, char *argv[]) {
 int x = 0xAB;
 int half = 4, i;
 tmp[1] = (int *) malloc (sizeof(int) * 6);
 for(i = 0; i < 6; ++i) {
  tmp[1][i] = 1;
 }
 printf("the tmp[i] = %d\n", tmp[1]);
 tmp[1] += 1;
 printf("the tmp[i] = %d	\t %d\n", tmp[1], tmp[1][0]);
 printf("the higher bit is %x, the lower bits are %x\n", x >> half, x ^ ((x >> half) << half));
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
 int x = 0xAB;
 int half = 4; int i;
 tmp[1] = (int *) malloc (sizeof(int) * 6);
 for(i = 0; i < 6; ++i) {
  tmp[1][i] = 1;
 }
 printf("the tmp[i] = %d\n", tmp[1]);
 tmp[1] += 1;
 printf("the tmp[i] = %d	\t %d\n", tmp[1], tmp[1][0]);
 printf("the higher bit is %x, the lower bits are %x\n", x >> half, x ^ ((x >> half) << half));
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: x int

variable_types: half int


decompiled_code:
__int64 __fastcall single_shift_multi_w32(__int64 a1, __int64 a2)
{
return gf_shift_multi(a1, a2, 32LL);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
return gf_shift_multi(a1, a2, 32LL);
}

original_code:
int single_shift_multi_w32(int x, int y) {
 int w = 32;
 return gf_shift_multi(x, y, w);
}

variable_types: y int

variable_types: w int


decompiled_code:
__int64 gf_create_split_w8_tables()
{
__int64 result; // rax
__int64 *v1; // rbx
void *v2; // rax
__int64 v3; // rbp
int j; // er14
__int64 k; // rbx
int i; // [rsp+0h] [rbp-4Ch]
__int64 v7; // [rsp+4h] [rbp-48h]
__int64 *v8; // [rsp+Ch] [rbp-40h]

result = 0LL;
if ( !gf_split_w8[0] )
{
if ( (int)gf_create_multi_tables(8LL) < 0 )
{
result = 0xFFFFFFFFLL;
}
else
{
v1 = gf_split_w8;
do
{
v2 = malloc(0x40000uLL);
*v1 = (__int64)v2;
if ( !v2 )
{
fwrite("ERROR----gf_split_w8 malloc failed!\n", 1uLL, 0x24uLL, stderr);
return 0xFFFFFFFFLL;
}
++v1;
}
while ( v1 != &gf_split_w8[7] );
for ( i = 0; i != 6; i += 3 )
{
v7 = i != 0;
v8 = &gf_split_w8[i + (i != 0) - v7];
do
{
v3 = v8[v7];
for ( j = 0; j != 256; ++j )
{
for ( k = 0LL; k != 256; ++k )
*(_DWORD *)(v3 + 4 * k) = gf_shift_multi(
(unsigned int)(j << (8 * i)),
(unsigned int)((_DWORD)k << (8 * v7)),
32LL);
v3 += 1024LL;
}
++v7;
}
while ( (int)v7 <= 3 );
}
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 result; // rax
__int64 *v1; // rbx
void *v2; // rax
__int64 v3; // rbp
int j; // er14
__int64 k; // rbx
int i; // [rsp+0h] [rbp-4Ch]
__int64 v7; // [rsp+4h] [rbp-48h]
__int64 *v8; // [rsp+Ch] [rbp-40h]

result = 0LL;
if ( !gf_split_w8[0] )
{
if ( (int)gf_create_multi_tables(8LL) < 0 )
{
result = 0xFFFFFFFFLL;
}
else
{
v1 = gf_split_w8;
do
{
v2 = malloc(0x40000uLL);
*v1 = (__int64)v2;
if ( !v2 )
{
fwrite("ERROR----gf_split_w8 malloc failed!\n", 1uLL, 0x24uLL, stderr);
return 0xFFFFFFFFLL;
}
++v1;
}
while ( v1 != &gf_split_w8[7] );
for ( i = 0; i != 6; i += 3 )
{
v7 = i != 0;
v8 = &gf_split_w8[i + (i != 0) - v7];
do
{
v3 = v8[v7];
for ( j = 0; j != 256; ++j )
{
for ( k = 0LL; k != 256; ++k )
*(_DWORD *)(v3 + 4 * k) = gf_shift_multi(
(unsigned int)(j << (8 * i)),
(unsigned int)((_DWORD)k << (8 * v7)),
32LL);
v3 += 1024LL;
}
++v7;
}
while ( (int)v7 <= 3 );
}
result = 0LL;
}
}
return result;
}

original_code:
int gf_create_split_w8_tables() {
 int x_orig, y_orig, i, j, x_ele, y_ele, index, ishift, jshift, *table;
 if(gf_split_w8[0] != ((void *)0)) return 0;
 if(gf_create_multi_tables(8) < 0) {
  return -1;
 }
 for(i = 0; i < 7; ++i) {
  gf_split_w8[i] = (int *) malloc (sizeof(int) * (1 << 16));
  if(gf_split_w8[i] == ((void *)0)) {
   fprintf(stderr, "ERROR----gf_split_w8 malloc failed!\n");
   return -1;
  }
 }
 for(i = 0; i < 4; i += 3) {
  ishift = i * 8;
  for(j = (i == 0? 0 : 1); j < 4; ++j) {
   jshift = j * 8;
   table = gf_split_w8[i + j];
   index = 0;
   for(x_orig = 0; x_orig < 256; ++x_orig) {
    x_ele = (x_orig << ishift);
    for(y_orig = 0; y_orig < 256; ++y_orig) {
     y_ele = (y_orig << jshift);
     table[index] = gf_shift_multi(x_ele, y_ele, 32);
     ++index;
    }
   }
  }
 }
 return 0;
}

canonical_original_code:
int gf_create_split_w8_tables() {
 int x_orig; int y_orig; int i; int j; int x_ele; int y_ele; int index; int ishift; int jshift; int *table;
 if(gf_split_w8[0] != ((void *)0)) return 0;
 if(gf_create_multi_tables(8) < 0) {
  return -1;
 }
 for(i = 0; i < 7; ++i) {
  gf_split_w8[i] = (int *) malloc (sizeof(int) * (1 << 16));
  if(gf_split_w8[i] == ((void *)0)) {
   fprintf(stderr, "ERROR----gf_split_w8 malloc failed!\n");
   return -1;
  }
 }
 for(i = 0; i < 4; i += 3) {
  ishift = i * 8;
  for(j = (i == 0? 0 : 1); j < 4; ++j) {
   jshift = j * 8;
   table = gf_split_w8[i + j];
   index = 0;
   for(x_orig = 0; x_orig < 256; ++x_orig) {
    x_ele = (x_orig << ishift);
    for(y_orig = 0; y_orig < 256; ++y_orig) {
     y_ele = (y_orig << jshift);
     table[index] = gf_shift_multi(x_ele, y_ele, 32);
     ++index;
    }
   }
  }
 }
 return 0;
}

variable_types: index int

variable_types: ishift int

variable_types: jshift int

variable_types:
table
int *


decompiled_code:
__int64 __fastcall gf_split_w8_multi(int a1, int a2)
{
__int64 *v3; // r11
unsigned int v4; // edi
int i; // er9
__int64 *v6; // rdx
int j; // ecx

v3 = gf_split_w8;
v4 = 0;
for ( i = 0; i != 4; ++i )
{
v6 = v3;
for ( j = 0; j != 32; j += 8 )
v4 ^= *(_DWORD *)(*v6++
+ 4LL
* ((unsigned __int16)((unsigned __int16)(a1 >> (8 * i)) << 8) | (unsigned int)(unsigned __int8)(a2 >> j)));
++v3;
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, int a2)
{
__int64 *v3; // r11
unsigned int v4; // edi
int i; // er9
__int64 *v6; // rdx
int j; // ecx

v3 = gf_split_w8;
v4 = 0;
for ( i = 0; i != 4; ++i )
{
v6 = v3;
for ( j = 0; j != 32; j += 8 )
v4 ^= *(_DWORD *)(*v6++
+ 4LL
* ((unsigned __int16)((unsigned __int16)(a1 >> (8 * i)) << 8) | (unsigned int)(unsigned __int8)(a2 >> j)));
++v3;
}
return v4;
}

original_code:
int gf_split_w8_multi(int x, int y) {
 int i, j, xx, yy, sum, x_8bits, y_8bits;
 sum = 0;
 x_8bits = 0;
 for(i = 0; i < 4; ++i) {
  xx = (((x >> x_8bits) & 255) << 8);
  y_8bits = 0;
  for(j = 0; j < 4; ++j) {
   yy = ((y >> y_8bits) & 255);
   sum ^= gf_split_w8[i + j][xx | yy];
   y_8bits += 8;
  }
  x_8bits += 8;
 }
 return sum;
}

canonical_original_code:
int gf_split_w8_multi(int x, int y) {
 int i; int j; int xx; int yy; int sum; int x_8bits; int y_8bits;
 sum = 0;
 x_8bits = 0;
 for(i = 0; i < 4; ++i) {
  xx = (((x >> x_8bits) & 255) << 8);
  y_8bits = 0;
  for(j = 0; j < 4; ++j) {
   yy = ((y >> y_8bits) & 255);
   sum ^= gf_split_w8[i + j][xx | yy];
   y_8bits += 8;
  }
  x_8bits += 8;
 }
 return sum;
}

variable_types: i int

variable_types: xx int

variable_types: yy int

variable_types: sum int


decompiled_code:
__int64 __fastcall single_split8_multi_w32(int a1, int a2)
{
if ( !gf_split_w8[0] && (int)gf_create_split_w8_tables() < 0 )
{
fwrite("ERROR -- cannot make log split_w8 tables for w = 32\n", 1uLL, 0x34uLL, stderr);
exit(1);
}
return gf_split_w8_multi(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, int a2)
{
if ( !gf_split_w8[0] && (int)func1() < 0 )
{
fwrite("ERROR -- cannot make log split_w8 tables for w = 32\n", 1uLL, 0x34uLL, stderr);
exit(1);
}
return func2(a1, a2);
}

original_code:
int single_split8_multi_w32(int x, int y) {
 if(gf_split_w8[0] == ((void *)0)) {
  if(gf_create_split_w8_tables() < 0) {
   fprintf(stderr, "ERROR -- cannot make log split_w8 tables for w = 32\n");
   exit(1);
  }
 }
 return gf_split_w8_multi(x, y);
}


decompiled_code:
void __fastcall gf_region_multiby2_w32(int *a1, int a2)
{
int *v2; // rbx
unsigned __int64 v3; // rcx
int v4; // edi
int v5; // edx

v2 = a1;
if ( prim == -1 )
prim = single_split8_multi_w32(0x80000000, 2);
v3 = (unsigned __int64)a1 + a2;
if ( (unsigned __int64)a1 < v3 )
{
v4 = prim;
do
{
v5 = 0;
if ( *v2 < 0 )
v5 = v4;
*v2 = v5 ^ (2 * *v2);
++v2;
}
while ( v3 > (unsigned __int64)v2 );
}
}

canonical_decompiled_code:
void __fastcall func4(int *a1, int a2)
{
int *v2; // rbx
unsigned __int64 v3; // rcx
int v4; // edi
int v5; // edx

v2 = a1;
if ( prim == -1 )
prim = func3(0x80000000, 2);
v3 = (unsigned __int64)a1 + a2;
if ( (unsigned __int64)a1 < v3 )
{
v4 = prim;
do
{
v5 = 0;
if ( *v2 < 0 )
v5 = v4;
*v2 = v5 ^ (2 * *v2);
++v2;
}
while ( v3 > (unsigned __int64)v2 );
}
}

original_code:
void gf_region_multiby2_w32(unsigned char *region, int nbytes) {
 int *start, *end;
 unsigned char *length;
 if(prim == -1) {
  prim = single_split8_multi_w32((1 << 31), 2);
 }
 length = region + nbytes;
 start = (int *)region;
 end = (int *)length;
 while(start < end) {
  *start = ((*start) << 1) ^ ((*start & 0x80000000) ? prim : 0);
  ++start;
 }
}

canonical_original_code:
void gf_region_multiby2_w32(unsigned char *region, int nbytes) {
 int *start; int *end;
 unsigned char *length;
 if(prim == -1) {
  prim = single_split8_multi_w32((1 << 31), 2);
 }
 length = region + nbytes;
 start = (int *)region;
 end = (int *)length;
 while(start < end) {
  *start = ((*start) << 1) ^ ((*start & 0x80000000) ? prim : 0);
  ++start;
 }
}

variable_types:
region
unsigned char *

variable_types: nbytes int

variable_types:
start
int *

variable_types:
end
int *

variable_types:
length
unsigned char *


original_code:
void gf_region_multiby2_w32_64(unsigned char *region, int nbytes) {
 uint64_t *start, *end;
 unsigned char *length;
 uint64_t tmp1, tmp2;
 if(prim_64 == -1UL) {
  tmp1 = (uint64_t) single_split8_multi_w32((1 << 31), 2);
  prim_64 = 0UL;
  while(tmp1 != 0UL) {
   prim_64 |= tmp1;
   tmp1 = tmp1 << 32UL;
  }
  tmp1 = (1UL << 32UL) - 2UL;
  mask1_64 = 0UL;
  while(tmp1 != 0UL) {
   mask1_64 |= tmp1;
   tmp1 = tmp1 << 32UL;
  }
  tmp1 = (1UL << 31UL);
  mask2_64 = 0UL;
  while(tmp1 != 0UL) {
   mask2_64 |= tmp1;
   tmp1 = tmp1 << 32UL;
  }
 }
 length = region + nbytes;
 start = (uint64_t *) region;
 end = (uint64_t *) length;
 while(start < end) {
  tmp1 = ((*start) << 1UL) & mask1_64;
  tmp2 = (*start) & mask2_64;
  tmp2 = (tmp2 << 1UL) - (tmp2 >> 31UL);
  *start = tmp1 ^ (tmp2 & prim_64);
  ++start;
 }
}

canonical_original_code:
void gf_region_multiby2_w32_64(unsigned char *region, int nbytes) {
 unsigned long *start; unsigned long *end;
 unsigned char *length;
 unsigned long tmp1; unsigned long tmp2;
 if(prim_64 == -1UL) {
  tmp1 = (unsigned long) single_split8_multi_w32((1 << 31), 2);
  prim_64 = 0UL;
  while(tmp1 != 0UL) {
   prim_64 |= tmp1;
   tmp1 = tmp1 << 32UL;
  }
  tmp1 = (1UL << 32UL) - 2UL;
  mask1_64 = 0UL;
  while(tmp1 != 0UL) {
   mask1_64 |= tmp1;
   tmp1 = tmp1 << 32UL;
  }
  tmp1 = (1UL << 31UL);
  mask2_64 = 0UL;
  while(tmp1 != 0UL) {
   mask2_64 |= tmp1;
   tmp1 = tmp1 << 32UL;
  }
 }
 length = region + nbytes;
 start = (unsigned long *) region;
 end = (unsigned long *) length;
 while(start < end) {
  tmp1 = ((*start) << 1UL) & mask1_64;
  tmp2 = (*start) & mask2_64;
  tmp2 = (tmp2 << 1UL) - (tmp2 >> 31UL);
  *start = tmp1 ^ (tmp2 & prim_64);
  ++start;
 }
}

variable_types:
start
unsigned long *

variable_types:
end
unsigned long *


original_code:
void gf_region_multi_w32(unsigned char *region,
  int multiby,
  int nbytes,
  unsigned char *reslt,
  int add) {
 uint32_t *r1, *r2;
 int i, j, k, xx, yy, x_8, y_8, tmp;
 int acache[4];
 r1 = (uint32_t *) region;
 r2 = (reslt == ((void *)0)) ? r1 : (uint32_t *) reslt;
 nbytes /= sizeof(uint32_t);
 if(gf_split_w8[0] == ((void *)0)) {
  if(gf_create_split_w8_tables() < 0) {
   fprintf(stderr, "ERROR--gf_region_multi_w32---couldn't make split multi-tables!\n");
   exit(1);
  }
 }
 x_8 = 0;
 for(i = 0; i < 4; ++i) {
  acache[i] = ((multiby >> x_8) & 255) << 8;
  x_8 += 8;
 }
 if(!add) {
  for(k = 0; k < nbytes; ++k) {
   tmp = 0;
   for(i = 0; i < 4; ++i) {
    xx = acache[i];
    y_8 = 0;
    for(j = 0; j < 4; ++j) {
     yy = (r1[k] >> y_8) & 255;
     tmp ^= gf_split_w8[i + j][xx | yy];
     y_8 += 8;
    }
   }
   r2[k] = tmp;
  }
 } else {
  for(k = 0; k < nbytes; ++k) {
   tmp = 0;
   for(i = 0; i < 4; ++i) {
    xx = acache[i];
    y_8 = 0;
    for(j = 0; j < 4; ++j) {
     yy = (r1[k] >> y_8) & 255;
     tmp ^= gf_split_w8[i + j][xx | yy];
     y_8 += 8;
    }
   }
   r2[k] = r2[k] ^ tmp;
  }
 }
 return;
}

canonical_original_code:
void gf_region_multi_w32(unsigned char *region, int multiby, int nbytes, unsigned char *reslt, int add) {
 unsigned int *r1; unsigned int *r2;
 int i; int j; int k; int xx; int yy; int x_8; int y_8; int tmp;
 int acache[4];
 r1 = (unsigned int *) region;
 r2 = (reslt == ((void *)0)) ? r1 : (unsigned int *) reslt;
 nbytes /= sizeof(unsigned int);
 if(gf_split_w8[0] == ((void *)0)) {
  if(gf_create_split_w8_tables() < 0) {
   fprintf(stderr, "ERROR--gf_region_multi_w32---couldn't make split multi-tables!\n");
   exit(1);
  }
 }
 x_8 = 0;
 for(i = 0; i < 4; ++i) {
  acache[i] = ((multiby >> x_8) & 255) << 8;
  x_8 += 8;
 }
 if(!add) {
  for(k = 0; k < nbytes; ++k) {
   tmp = 0;
   for(i = 0; i < 4; ++i) {
    xx = acache[i];
    y_8 = 0;
    for(j = 0; j < 4; ++j) {
     yy = (r1[k] >> y_8) & 255;
     tmp ^= gf_split_w8[i + j][xx | yy];
     y_8 += 8;
    }
   }
   r2[k] = tmp;
  }
 } else {
  for(k = 0; k < nbytes; ++k) {
   tmp = 0;
   for(i = 0; i < 4; ++i) {
    xx = acache[i];
    y_8 = 0;
    for(j = 0; j < 4; ++j) {
     yy = (r1[k] >> y_8) & 255;
     tmp ^= gf_split_w8[i + j][xx | yy];
     y_8 += 8;
    }
   }
   r2[k] = r2[k] ^ tmp;
  }
 }
 return;
}

variable_types: multiby int

variable_types:
reslt
unsigned char *

variable_types: add int

variable_types: j int

variable_types: k int

variable_types: tmp int

variable_types:
acache
int [4]


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

if ( (_DWORD)a1 )
result = gf_shift_inverse(a1, 32LL);
else
result = 0xFFFFFFFFLL;
return result;
}

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

if ( (_DWORD)a1 )
result = gf_shift_inverse(a1, 32LL);
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int gf_inverse_w32(int y) {
 if(y == 0) return -1;
 return gf_shift_inverse(y, 32);
}

variable_types: y int


decompiled_code:
__int64 __fastcall single_logtable_multi_w8(__int64 a1, __int64 a2)
{
return gf_logtable_multi(a1, a2, 8LL);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
return gf_logtable_multi(a1, a2, 8LL);
}

original_code:
int single_logtable_multi_w8(int x, int y) {
 int w = 8;
 return gf_logtable_multi(x, y, w);
}

variable_types: x int

variable_types: w int


decompiled_code:
__int64 __fastcall single_multitable_w8(__int64 a1, __int64 a2)
{
return gf_multitable_multi(a1, a2, 8LL);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
return gf_multitable_multi(a1, a2, 8LL);
}

original_code:
int single_multitable_w8(int x, int y) {
 int w = 8;
 return gf_multitable_multi(x, y, w);
}


decompiled_code:
__int64 __fastcall single_multi_lrtbl_w8(__int64 a1, __int64 a2)
{
return gf_multi_lr_multi(a1, a2, 8LL);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
return gf_multi_lr_multi(a1, a2, 8LL);
}

original_code:
int single_multi_lrtbl_w8(int x, int y) {
 int w = 8;
 return gf_multi_lr_multi(x, y, w);
}


decompiled_code:
__int64 __fastcall single_shift_multi_w8(__int64 a1, __int64 a2)
{
return gf_shift_multi(a1, a2, 8LL);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
return gf_shift_multi(a1, a2, 8LL);
}

original_code:
int single_shift_multi_w8(int x, int y) {
 int w = 8;
 return gf_shift_multi(x, y, w);
}


decompiled_code:
void __fastcall gf_region_multiby2_w8(unsigned int *a1, int a2)
{
unsigned int *v2; // rbx
unsigned __int64 v3; // rsi
int v4; // er9
int v5; // er8
int v6; // edi
int v7; // eax
int v8; // edx

v2 = a1;
if ( prim == -1 )
{
v7 = gf_multitable_multi(128LL, 2LL, 8LL);
prim = 0;
if ( v7 )
{
v8 = 0;
do
{
v8 |= v7;
v7 <<= 8;
}
while ( v7 );
prim = v8;
}
mask1 = -16843010;
mask2 = -2139062144;
}
v3 = (unsigned __int64)a1 + a2;
if ( (unsigned __int64)a1 < v3 )
{
v4 = mask1;
v5 = mask2;
v6 = prim;
do
{
*v2 = v4 & (2 * *v2) ^ v6 & (2 * (v5 & *v2) - ((v5 & *v2) >> 7));
++v2;
}
while ( v3 > (unsigned __int64)v2 );
}
}

canonical_decompiled_code:
void __fastcall func4(unsigned int *a1, int a2)
{
unsigned int *v2; // rbx
unsigned __int64 v3; // rsi
int v4; // er9
int v5; // er8
int v6; // edi
int v7; // eax
int v8; // edx

v2 = a1;
if ( prim == -1 )
{
v7 = gf_multitable_multi(128LL, 2LL, 8LL);
prim = 0;
if ( v7 )
{
v8 = 0;
do
{
v8 |= v7;
v7 <<= 8;
}
while ( v7 );
prim = v8;
}
mask1 = -16843010;
mask2 = -2139062144;
}
v3 = (unsigned __int64)a1 + a2;
if ( (unsigned __int64)a1 < v3 )
{
v4 = mask1;
v5 = mask2;
v6 = prim;
do
{
*v2 = v4 & (2 * *v2) ^ v6 & (2 * (v5 & *v2) - ((v5 & *v2) >> 7));
++v2;
}
while ( v3 > (unsigned __int64)v2 );
}
}

original_code:
void gf_region_multiby2_w8(unsigned char *region, int nbytes) {
 unsigned int *start, *end;
 unsigned char *length;
 unsigned int tmp1, tmp2;
 if(prim == -1) {
  tmp1 = gf_multitable_multi((1 << 7), 2, 8);
  prim = 0;
  while(tmp1 != 0) {
   prim |= tmp1;
   tmp1 = tmp1 << 8;
  }
  tmp1 = (1 << 8) - 2;
  mask1 = 0;
  while(tmp1 != 0) {
   mask1 |= tmp1;
   tmp1 = tmp1 << 8;
  }
  tmp1 = (1 << 7);
  mask2 = 0;
  while(tmp1 != 0) {
   mask2 |= tmp1;
   tmp1 = tmp1 << 8;
  }
 }
 length = region + nbytes;
 start = (unsigned int *) region;
 end = (unsigned int *) length;
 while(start < end) {
     tmp1 = ((*start) << 1) & mask1;
  tmp2 = (*start) & mask2;
  tmp2 = (tmp2 << 1) - (tmp2 >> 7);
  *start = (tmp1 ^ (tmp2 & prim));
  ++start;
 }
}

canonical_original_code:
void gf_region_multiby2_w8(unsigned char *region, int nbytes) {
 unsigned int *start; unsigned int *end;
 unsigned char *length;
 unsigned int tmp1; unsigned int tmp2;
 if(prim == -1) {
  tmp1 = gf_multitable_multi((1 << 7), 2, 8);
  prim = 0;
  while(tmp1 != 0) {
   prim |= tmp1;
   tmp1 = tmp1 << 8;
  }
  tmp1 = (1 << 8) - 2;
  mask1 = 0;
  while(tmp1 != 0) {
   mask1 |= tmp1;
   tmp1 = tmp1 << 8;
  }
  tmp1 = (1 << 7);
  mask2 = 0;
  while(tmp1 != 0) {
   mask2 |= tmp1;
   tmp1 = tmp1 << 8;
  }
 }
 length = region + nbytes;
 start = (unsigned int *) region;
 end = (unsigned int *) length;
 while(start < end) {
     tmp1 = ((*start) << 1) & mask1;
  tmp2 = (*start) & mask2;
  tmp2 = (tmp2 << 1) - (tmp2 >> 7);
  *start = (tmp1 ^ (tmp2 & prim));
  ++start;
 }
}

variable_types:
region
unsigned char *

variable_types:
start
unsigned int *

variable_types:
end
unsigned int *


original_code:
void gf_region_multiby2_w8_64(unsigned char *region, int nbytes) {
 uint64_t *start, *end;
 unsigned *length;
 uint64_t tmp1, tmp2;
 if(prim_64 == -1UL) {
  tmp1 = (uint64_t)gf_multitable_multi((1 << 7), 2, 8);
  prim_64 = 0UL;
  while(tmp1 != 0UL) {
   prim_64 |= tmp1;
   tmp1 = tmp1 << 8UL;
  }
  tmp1 = (1UL << 8UL) - 2UL;
  mask1_64 = 0UL;
  while(tmp1 != 0UL) {
   mask1_64 |= tmp1;
   tmp1 = (tmp1 << 8UL);
  }
  tmp1 = (1UL << 7UL);
  mask2_64 = 0UL;
  while(tmp1 != 0UL) {
      mask2_64 |= tmp1;
   tmp1 = tmp1 << 8UL;
  }
 }
 length = region + nbytes;
 start = (uint64_t *) region;
 end = (uint64_t *) length;
 while(start < end) {
  tmp1 = ((*start) << 1UL) & mask1_64;
  tmp2 = (*start) & mask2_64;
  tmp2 = (tmp2 << 1UL) - (tmp2 >> 7UL);
  *start = (tmp1) ^ (tmp2 & prim_64);
  ++start;
 }
}

canonical_original_code:
void gf_region_multiby2_w8_64(unsigned char *region, int nbytes) {
 unsigned long *start; unsigned long *end;
 unsigned int *length;
 unsigned long tmp1; unsigned long tmp2;
 if(prim_64 == -1UL) {
  tmp1 = (unsigned long)gf_multitable_multi((1 << 7), 2, 8);
  prim_64 = 0UL;
  while(tmp1 != 0UL) {
   prim_64 |= tmp1;
   tmp1 = tmp1 << 8UL;
  }
  tmp1 = (1UL << 8UL) - 2UL;
  mask1_64 = 0UL;
  while(tmp1 != 0UL) {
   mask1_64 |= tmp1;
   tmp1 = (tmp1 << 8UL);
  }
  tmp1 = (1UL << 7UL);
  mask2_64 = 0UL;
  while(tmp1 != 0UL) {
      mask2_64 |= tmp1;
   tmp1 = tmp1 << 8UL;
  }
 }
 length = region + nbytes;
 start = (unsigned long *) region;
 end = (unsigned long *) length;
 while(start < end) {
  tmp1 = ((*start) << 1UL) & mask1_64;
  tmp2 = (*start) & mask2_64;
  tmp2 = (tmp2 << 1UL) - (tmp2 >> 7UL);
  *start = (tmp1) ^ (tmp2 & prim_64);
  ++start;
 }
}

variable_types: nbytes int

variable_types:
length
unsigned int *


decompiled_code:
void __fastcall gf_region_multi_w8(unsigned __int8 *a1, unsigned int a2, int a3, unsigned __int8 *a4, int a5)
{
unsigned __int8 *v5; // rbp
unsigned __int8 *v6; // r12
unsigned __int8 *v7; // r13
__int64 v8; // r12
__int64 i; // rbx

if ( a4 )
{
v5 = a4;
if ( a5 )
{
if ( a3 > 0 )
{
v6 = a1;
v7 = &a1[a3];
do
*v5++ ^= gf_multitable_multi(a2, *v6++, 8LL);
while ( v6 != v7 );
}
return;
}
}
else
{
v5 = a1;
}
if ( a3 > 0 )
{
v8 = (unsigned int)a3;
for ( i = 0LL; i != v8; ++i )
v5[i] = gf_multitable_multi(a2, a1[i], 8LL);
}
}

canonical_decompiled_code:
void __fastcall func6(unsigned __int8 *a1, unsigned int a2, int a3, unsigned __int8 *a4, int a5)
{
unsigned __int8 *v5; // rbp
unsigned __int8 *v6; // r12
unsigned __int8 *v7; // r13
__int64 v8; // r12
__int64 i; // rbx

if ( a4 )
{
v5 = a4;
if ( a5 )
{
if ( a3 > 0 )
{
v6 = a1;
v7 = &a1[a3];
do
*v5++ ^= gf_multitable_multi(a2, *v6++, 8LL);
while ( v6 != v7 );
}
return;
}
}
else
{
v5 = a1;
}
if ( a3 > 0 )
{
v8 = (unsigned int)a3;
for ( i = 0LL; i != v8; ++i )
v5[i] = gf_multitable_multi(a2, a1[i], 8LL);
}
}

original_code:
void gf_region_multi_w8(unsigned char *region,
  int multiby,
  int nbytes,
  unsigned char *reslt,
  int add)
{
 unsigned char *r1, *r2;
 int i, lookup;
 r1 = region;
 r2 = (reslt == ((void *)0)) ? r1 : reslt;
 if(reslt == ((void *)0) || !add) {
  for(i = 0; i < nbytes; ++i) {
   lookup = gf_multitable_multi(multiby, r1[i], 8);
   r2[i] = lookup;
  }
 } else {
  for(i = 0; i < nbytes; ++i) {
   lookup = gf_multitable_multi(multiby, r1[i], 8);
   r2[i] ^= lookup;
  }
 }
}

canonical_original_code:
void gf_region_multi_w8(unsigned char *region, int multiby, int nbytes, unsigned char *reslt, int add)
{
 unsigned char *r1; unsigned char *r2;
 int i; int lookup;
 r1 = region;
 r2 = (reslt == ((void *)0)) ? r1 : reslt;
 if(reslt == ((void *)0) || !add) {
  for(i = 0; i < nbytes; ++i) {
   lookup = gf_multitable_multi(multiby, r1[i], 8);
   r2[i] = lookup;
  }
 } else {
  for(i = 0; i < nbytes; ++i) {
   lookup = gf_multitable_multi(multiby, r1[i], 8);
   r2[i] ^= lookup;
  }
 }
}

variable_types: i int

variable_types: lookup int


decompiled_code:
__int64 __fastcall gf_inverse_w8(unsigned int a1)
{
__int64 result; // rax

if ( a1 )
result = gf_single_div(1LL, a1, 8LL);
else
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int a1)
{
__int64 result; // rax

if ( a1 )
result = gf_single_div(1LL, a1, 8LL);
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int gf_inverse_w8(int y) {
 if(y == 0) return -1;
 return gf_single_div(1, y, 8);
}


original_code:
uint64_t gf_shift_multi_64(uint64_t x, uint64_t y) {
 uint64_t result = 0;
 uint64_t shift_y[64], x_binary;
 int i;
 shift_y[0] = y;
 for(i = 1; i < 64; ++i) {
  shift_y[i] = shift_y[i - 1];
  if(shift_y[i] & 0x8000000000000000) {
   shift_y[i] = shift_y[i] << 1;
   shift_y[i] = shift_y[i] ^ prim64;
  } else {
   shift_y[i] = shift_y[i] << 1;
  }
 }
 for(i = 0; i < 64; ++i) {
  x_binary = 1UL << i;
  if(x_binary & x) {
   result = result ^ shift_y[i];
  }
 }
 return result;
}

canonical_original_code:
unsigned long gf_shift_multi_64(unsigned long x, unsigned long y) {
 unsigned long result = 0;
 unsigned long shift_y[64]; unsigned long x_binary;
 int i;
 shift_y[0] = y;
 for(i = 1; i < 64; ++i) {
  shift_y[i] = shift_y[i - 1];
  if(shift_y[i] & 0x8000000000000000) {
   shift_y[i] = shift_y[i] << 1;
   shift_y[i] = shift_y[i] ^ prim64;
  } else {
   shift_y[i] = shift_y[i] << 1;
  }
 }
 for(i = 0; i < 64; ++i) {
  x_binary = 1UL << i;
  if(x_binary & x) {
   result = result ^ shift_y[i];
  }
 }
 return result;
}

variable_types:
x
unsigned long

variable_types:
y
unsigned long

variable_types:
result
unsigned long


original_code:
void gf_invert_binary_matrix_64(uint64_t *mat, uint64_t *inv) {
 int i, j;
 uint64_t tmp;
 int rows, cols;
 rows = cols = 64;
 for(i = 0; i < cols; ++i) {
  inv[i] = (1UL << i);
 }
 for(i = 0; i < cols; ++i) {
  if((mat[i] & (1UL << i)) == 0) {
   for(j = i + 1; j < rows && (mat[j] & (1UL << i)) == 0; ++j);
   if(j == rows) {
    printf("i = %du, j = %u\n", i, j);
    fprintf(stderr, "gf_invert_matrix_64: matrix not invertible!!\n");
    exit(1);
   }
   tmp = mat[i];
   mat[i] = mat[j];
   mat[j] = tmp;
   tmp = inv[i];
   inv[i] = inv[j];
   inv[j] = tmp;
  }
  for(j = i + 1; j != rows; ++j) {
   if((mat[j] & (1UL << i)) != 0) {
    mat[j] ^= mat[i];
    inv[j] ^= inv[i];
   }
  }
 }
 for(i = rows - 1; i >= 0; --i) {
  for(j = 0; j < i; ++j) {
   if((mat[j] & (1UL << i))) {
    mat[j] ^= mat[i];
    inv[j] ^= inv[i];
   }
  }
 }
}

canonical_original_code:
void gf_invert_binary_matrix_64(unsigned long *mat, unsigned long *inv) {
 int i; int j;
 unsigned long tmp;
 int rows; int cols;
 rows = cols = 64;
 for(i = 0; i < cols; ++i) {
  inv[i] = (1UL << i);
 }
 for(i = 0; i < cols; ++i) {
  if((mat[i] & (1UL << i)) == 0) {
   for(j = i + 1; j < rows && (mat[j] & (1UL << i)) == 0; ++j);
   if(j == rows) {
    printf("i = %du, j = %u\n", i, j);
    fprintf(stderr, "gf_invert_matrix_64: matrix not invertible!!\n");
    exit(1);
   }
   tmp = mat[i];
   mat[i] = mat[j];
   mat[j] = tmp;
   tmp = inv[i];
   inv[i] = inv[j];
   inv[j] = tmp;
  }
  for(j = i + 1; j != rows; ++j) {
   if((mat[j] & (1UL << i)) != 0) {
    mat[j] ^= mat[i];
    inv[j] ^= inv[i];
   }
  }
 }
 for(i = rows - 1; i >= 0; --i) {
  for(j = 0; j < i; ++j) {
   if((mat[j] & (1UL << i))) {
    mat[j] ^= mat[i];
    inv[j] ^= inv[i];
   }
  }
 }
}

variable_types:
mat
unsigned long *

variable_types:
inv
unsigned long *

variable_types: j int

variable_types:
tmp
unsigned long

variable_types: rows int

variable_types: cols int


original_code:
uint64_t gf_shift_inverse_64(uint64_t x) {
 uint64_t mat[64];
 uint64_t inv[64];
 int i;
 for(i = 0; i < 64; ++i) {
  mat[i] = x;
  if(x & 0x8000000000000000) {
   x = x << 1;
   x = x ^ prim64;
  } else {
   x = x << 1;
  }
 }
 gf_invert_binary_matrix_64(mat, inv);
 return inv[0];
}

canonical_original_code:
unsigned long gf_shift_inverse_64(unsigned long x) {
 unsigned long mat[64];
 unsigned long inv[64];
 int i;
 for(i = 0; i < 64; ++i) {
  mat[i] = x;
  if(x & 0x8000000000000000) {
   x = x << 1;
   x = x ^ prim64;
  } else {
   x = x << 1;
  }
 }
 gf_invert_binary_matrix_64(mat, inv);
 return inv[0];
}

variable_types:
mat
unsigned long [64]

variable_types:
inv
unsigned long [64]


decompiled_code:
__int64 __fastcall single_logtable_multi_w4(__int64 a1, __int64 a2)
{
return gf_logtable_multi(a1, a2, 4LL);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
return gf_logtable_multi(a1, a2, 4LL);
}

original_code:
int single_logtable_multi_w4(int x, int y) {
 int w = 4;
 return gf_logtable_multi(x, y, w);
}

variable_types: x int

variable_types: y int

variable_types: w int


decompiled_code:
__int64 __fastcall single_multitable_w4(__int64 a1, __int64 a2)
{
return gf_multitable_multi(a1, a2, 4LL);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
return gf_multitable_multi(a1, a2, 4LL);
}

original_code:
int single_multitable_w4(int x, int y) {
 int w = 4;
 return gf_multitable_multi(x, y, w);
}


decompiled_code:
__int64 __fastcall single_multi_lrtbl_w4(__int64 a1, __int64 a2)
{
return gf_multi_lr_multi(a1, a2, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
return gf_multi_lr_multi(a1, a2, 0LL);
}

original_code:
int single_multi_lrtbl_w4(int x, int y) {
 int w = 0;
 return gf_multi_lr_multi(x, y, w);
}


decompiled_code:
__int64 __fastcall single_shift_multi_w4(__int64 a1, __int64 a2)
{
return gf_shift_multi(a1, a2, 4LL);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
return gf_shift_multi(a1, a2, 4LL);
}

original_code:
int single_shift_multi_w4(int x, int y) {
 int w = 4;
 return gf_shift_multi(x, y, w);
}


decompiled_code:
void __fastcall gf_region_multiby2_w4(unsigned int *a1, int a2)
{
unsigned int *v2; // rbx
unsigned __int64 v3; // rsi
int v4; // er9
int v5; // er8
int v6; // edi
int v7; // eax
int v8; // edx
int v9; // edx
int v10; // ecx
int v11; // eax
int v12; // edx
int v13; // ecx
int v14; // eax

v2 = a1;
if ( prim == -1 )
{
v7 = gf_multitable_multi(8LL, 2LL, 4LL);
prim = 0;
if ( v7 )
{
v8 = 0;
do
{
v8 |= v7;
v7 *= 16;
}
while ( v7 );
prim = v8;
}
v9 = 8;
v10 = 0;
v11 = 14;
do
{
v10 |= v11;
v11 *= 16;
--v9;
}
while ( v9 );
mask1 = v10;
v12 = 8;
v13 = 0;
v14 = 8;
do
{
v13 |= v14;
v14 *= 16;
--v12;
}
while ( v12 );
mask2 = v13;
}
v3 = (unsigned __int64)a1 + a2;
if ( (unsigned __int64)a1 < v3 )
{
v4 = mask1;
v5 = mask2;
v6 = prim;
do
{
*v2 = v4 & (2 * *v2) ^ v6 & (2 * (v5 & *v2) - ((v5 & *v2) >> 3));
++v2;
}
while ( v3 > (unsigned __int64)v2 );
}
}

original_code:
void gf_region_multiby2_w4(unsigned char *region, int nbytes) {
 unsigned int *start, *end;
 unsigned char *length;
 unsigned int tmp1, tmp2;
 if(prim == -1) {
  tmp1 = gf_multitable_multi((1 << 3), 2, 4);
  prim = 0;
  while(tmp1 != 0) {
   prim |= tmp1;
   tmp1 = tmp1 << 4;
  }
  tmp1 = (1 << 4) - 2;
  mask1 = 0;
  while(tmp1 != 0) {
   mask1 |= tmp1;
   tmp1 = tmp1 << 4;
  }
  tmp1 = (1 << 3);
  mask2 = 0;
  while(tmp1 != 0) {
   mask2 |= tmp1;
   tmp1 = tmp1 << 4;
  }
 }
 length = region + nbytes;
 start = (unsigned int *) region;
 end = (unsigned int *) length;
 while(start < end) {
  tmp1 = ((*start) << 1) & mask1;
  tmp2 = (*start) & mask2;
  tmp2 = (tmp2 << 1) - (tmp2 >> 3);
  *start = (tmp1 ^ (tmp2 & prim));
  ++start;
 }
}

canonical_original_code:
void gf_region_multiby2_w4(unsigned char *region, int nbytes) {
 unsigned int *start; unsigned int *end;
 unsigned char *length;
 unsigned int tmp1; unsigned int tmp2;
 if(prim == -1) {
  tmp1 = gf_multitable_multi((1 << 3), 2, 4);
  prim = 0;
  while(tmp1 != 0) {
   prim |= tmp1;
   tmp1 = tmp1 << 4;
  }
  tmp1 = (1 << 4) - 2;
  mask1 = 0;
  while(tmp1 != 0) {
   mask1 |= tmp1;
   tmp1 = tmp1 << 4;
  }
  tmp1 = (1 << 3);
  mask2 = 0;
  while(tmp1 != 0) {
   mask2 |= tmp1;
   tmp1 = tmp1 << 4;
  }
 }
 length = region + nbytes;
 start = (unsigned int *) region;
 end = (unsigned int *) length;
 while(start < end) {
  tmp1 = ((*start) << 1) & mask1;
  tmp2 = (*start) & mask2;
  tmp2 = (tmp2 << 1) - (tmp2 >> 3);
  *start = (tmp1 ^ (tmp2 & prim));
  ++start;
 }
}

variable_types:
region
unsigned char *

variable_types: nbytes int

variable_types:
start
unsigned int *

variable_types:
end
unsigned int *

variable_types:
length
unsigned char *


original_code:
void gf_region_multiby2_w4_64(unsigned char *region, int nbytes) {
 uint64_t *start, *end;
 unsigned *length;
 uint64_t tmp1, tmp2;
 if(prim_64 == -1UL) {
  tmp1 = (uint64_t)gf_multitable_multi((1 << 3), 2, 4);
  prim_64 = 0UL;
  while(tmp1 != 0UL) {
   prim_64 |= tmp1;
   tmp1 = tmp1 << 4UL;
  }
  tmp1 = (1UL << 4UL) - 2UL;
  mask1_64 = 0UL;
  while(tmp1 != 0UL) {
   mask1_64 |= tmp1;
   tmp1 = (tmp1 << 4UL);
  }
  tmp1 = (1UL << 3UL);
  mask2_64 = 0UL;
  while(tmp1 != 0UL) {
   mask2_64 |= tmp1;
   tmp1 = tmp1 << 4UL;
  }
 }
 length = region + nbytes;
 start = (uint64_t *) region;
 end = (uint64_t *) length;
 while(start < end) {
  tmp1 = ((*start) << 1UL) & mask1_64;
  tmp2 = (*start) & mask2_64;
  tmp2 = (tmp2 << 1UL) - (tmp2 >> 3UL);
  *start = (tmp1) ^ (tmp2 & prim_64);
  ++start;
 }
}

canonical_original_code:
void gf_region_multiby2_w4_64(unsigned char *region, int nbytes) {
 unsigned long *start; unsigned long *end;
 unsigned int *length;
 unsigned long tmp1; unsigned long tmp2;
 if(prim_64 == -1UL) {
  tmp1 = (unsigned long)gf_multitable_multi((1 << 3), 2, 4);
  prim_64 = 0UL;
  while(tmp1 != 0UL) {
   prim_64 |= tmp1;
   tmp1 = tmp1 << 4UL;
  }
  tmp1 = (1UL << 4UL) - 2UL;
  mask1_64 = 0UL;
  while(tmp1 != 0UL) {
   mask1_64 |= tmp1;
   tmp1 = (tmp1 << 4UL);
  }
  tmp1 = (1UL << 3UL);
  mask2_64 = 0UL;
  while(tmp1 != 0UL) {
   mask2_64 |= tmp1;
   tmp1 = tmp1 << 4UL;
  }
 }
 length = region + nbytes;
 start = (unsigned long *) region;
 end = (unsigned long *) length;
 while(start < end) {
  tmp1 = ((*start) << 1UL) & mask1_64;
  tmp2 = (*start) & mask2_64;
  tmp2 = (tmp2 << 1UL) - (tmp2 >> 3UL);
  *start = (tmp1) ^ (tmp2 & prim_64);
  ++start;
 }
}

variable_types:
start
unsigned long *

variable_types:
end
unsigned long *

variable_types:
length
unsigned int *


decompiled_code:
__int64 __fastcall gf_inverse_w4(unsigned int a1)
{
__int64 result; // rax

if ( a1 )
result = gf_single_div(1LL, a1, 4LL);
else
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned int a1)
{
__int64 result; // rax

if ( a1 )
result = gf_single_div(1LL, a1, 4LL);
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int gf_inverse_w4(int y) {
 if(y == 0) return -1;
 return gf_single_div(1, y, 4);
}


decompiled_code:
__int64 __fastcall single_logtable_multi_w16(__int64 a1, __int64 a2)
{
return gf_logtable_multi(a1, a2, 16LL);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
return gf_logtable_multi(a1, a2, 16LL);
}

original_code:
int single_logtable_multi_w16(int x, int y) {
 int w = 16;
 return gf_logtable_multi(x, y, w);
}


decompiled_code:
__int64 __fastcall single_multi_lrtbl_w16(__int64 a1, __int64 a2)
{
return gf_multi_lr_multi(a1, a2, 16LL);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
return gf_multi_lr_multi(a1, a2, 16LL);
}

original_code:
int single_multi_lrtbl_w16(int x, int y) {
 int w = 16;
 return gf_multi_lr_multi(x, y, w);
}


decompiled_code:
__int64 __fastcall single_shift_multi_w16(__int64 a1, __int64 a2)
{
return gf_shift_multi(a1, a2, 16LL);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
return gf_shift_multi(a1, a2, 16LL);
}

original_code:
int single_shift_multi_w16(int x, int y) {
 int w = 16;
 return gf_shift_multi(x, y, w);
}


decompiled_code:
void __fastcall gf_region_multiby2_w16(unsigned int *a1, int a2)
{
unsigned int *v2; // rbx
unsigned __int64 v3; // rsi
int v4; // er9
int v5; // er8
int v6; // edi
int v7; // eax
int v8; // edx

v2 = a1;
if ( prim == -1 )
{
v7 = gf_logtable_multi(0x8000LL, 2LL, 16LL);
prim = 0;
if ( v7 )
{
v8 = 0;
do
{
v8 |= v7;
v7 <<= 16;
}
while ( v7 );
prim = v8;
}
mask1 = -65538;
mask2 = -2147450880;
}
v3 = (unsigned __int64)a1 + a2;
if ( (unsigned __int64)a1 < v3 )
{
v4 = mask1;
v5 = mask2;
v6 = prim;
do
{
*v2 = v4 & (2 * *v2) ^ v6 & (2 * (v5 & *v2) - ((v5 & *v2) >> 15));
++v2;
}
while ( v3 > (unsigned __int64)v2 );
}
}

canonical_decompiled_code:
void __fastcall func3(unsigned int *a1, int a2)
{
unsigned int *v2; // rbx
unsigned __int64 v3; // rsi
int v4; // er9
int v5; // er8
int v6; // edi
int v7; // eax
int v8; // edx

v2 = a1;
if ( prim == -1 )
{
v7 = gf_logtable_multi(0x8000LL, 2LL, 16LL);
prim = 0;
if ( v7 )
{
v8 = 0;
do
{
v8 |= v7;
v7 <<= 16;
}
while ( v7 );
prim = v8;
}
mask1 = -65538;
mask2 = -2147450880;
}
v3 = (unsigned __int64)a1 + a2;
if ( (unsigned __int64)a1 < v3 )
{
v4 = mask1;
v5 = mask2;
v6 = prim;
do
{
*v2 = v4 & (2 * *v2) ^ v6 & (2 * (v5 & *v2) - ((v5 & *v2) >> 15));
++v2;
}
while ( v3 > (unsigned __int64)v2 );
}
}

original_code:
void gf_region_multiby2_w16(unsigned char *region, int nbytes) {
 unsigned int *start, *end;
 unsigned char *length;
 unsigned int tmp1, tmp2;
 if(prim == -1) {
  tmp1 = gf_logtable_multi((1 << 15), 2, 16);
  prim = 0;
  while(tmp1 != 0) {
   prim |= tmp1;
   tmp1 = tmp1 << 16;
  }
  tmp1 = (1 << 16) - 2;
  mask1 = 0;
  while(tmp1 != 0) {
   mask1 |= tmp1;
   tmp1 = tmp1 << 16;
  }
  tmp1 = (1 << 15);
  mask2 = 0;
  while(tmp1 != 0) {
   mask2 |= tmp1;
   tmp1 = tmp1 << 16;
  }
 }
 length = region + nbytes;
 start = (unsigned int *) region;
 end = (unsigned int *) length;
 while(start < end) {
  tmp1 = ((*start) << 1) & mask1;
  tmp2 = (*start) & mask2;
  tmp2 = (tmp2 << 1) - (tmp2 >> 15);
  *start = (tmp1 ^ (tmp2 & prim));
  ++start;
 }
}

canonical_original_code:
void gf_region_multiby2_w16(unsigned char *region, int nbytes) {
 unsigned int *start; unsigned int *end;
 unsigned char *length;
 unsigned int tmp1; unsigned int tmp2;
 if(prim == -1) {
  tmp1 = gf_logtable_multi((1 << 15), 2, 16);
  prim = 0;
  while(tmp1 != 0) {
   prim |= tmp1;
   tmp1 = tmp1 << 16;
  }
  tmp1 = (1 << 16) - 2;
  mask1 = 0;
  while(tmp1 != 0) {
   mask1 |= tmp1;
   tmp1 = tmp1 << 16;
  }
  tmp1 = (1 << 15);
  mask2 = 0;
  while(tmp1 != 0) {
   mask2 |= tmp1;
   tmp1 = tmp1 << 16;
  }
 }
 length = region + nbytes;
 start = (unsigned int *) region;
 end = (unsigned int *) length;
 while(start < end) {
  tmp1 = ((*start) << 1) & mask1;
  tmp2 = (*start) & mask2;
  tmp2 = (tmp2 << 1) - (tmp2 >> 15);
  *start = (tmp1 ^ (tmp2 & prim));
  ++start;
 }
}


original_code:
void gf_region_multiby2_w16_64(unsigned char *region, int nbytes) {
 uint64_t *start, *end;
 unsigned *length;
 uint64_t tmp1, tmp2;
 if(prim_64 == -1UL) {
  tmp1 = (uint64_t)gf_logtable_multi((1 << 15), 2, 16);
  prim_64 = 0UL;
  while(tmp1 != 0UL) {
   prim_64 |= tmp1;
   tmp1 = tmp1 << 16UL;
  }
  tmp1 = (1UL << 16UL) - 2UL;
  mask1_64 = 0UL;
  while(tmp1 != 0UL) {
   mask1_64 |= tmp1;
   tmp1 = (tmp1 << 16UL);
  }
  tmp1 = (1UL << 15UL);
  mask2_64 = 0UL;
  while(tmp1 != 0UL) {
   mask2_64 |= tmp1;
   tmp1 = tmp1 << 16UL;
  }
 }
 length = region + nbytes;
 start = (uint64_t *) region;
 end = (uint64_t *) length;
 while(start < end) {
  tmp1 = ((*start) << 1UL) & mask1_64;
  tmp2 = (*start) & mask2_64;
  tmp2 = (tmp2 << 1UL) - (tmp2 >> 15UL);
  *start = (tmp1) ^ (tmp2 & prim_64);
  ++start;
 }
}

canonical_original_code:
void gf_region_multiby2_w16_64(unsigned char *region, int nbytes) {
 unsigned long *start; unsigned long *end;
 unsigned int *length;
 unsigned long tmp1; unsigned long tmp2;
 if(prim_64 == -1UL) {
  tmp1 = (unsigned long)gf_logtable_multi((1 << 15), 2, 16);
  prim_64 = 0UL;
  while(tmp1 != 0UL) {
   prim_64 |= tmp1;
   tmp1 = tmp1 << 16UL;
  }
  tmp1 = (1UL << 16UL) - 2UL;
  mask1_64 = 0UL;
  while(tmp1 != 0UL) {
   mask1_64 |= tmp1;
   tmp1 = (tmp1 << 16UL);
  }
  tmp1 = (1UL << 15UL);
  mask2_64 = 0UL;
  while(tmp1 != 0UL) {
   mask2_64 |= tmp1;
   tmp1 = tmp1 << 16UL;
  }
 }
 length = region + nbytes;
 start = (unsigned long *) region;
 end = (unsigned long *) length;
 while(start < end) {
  tmp1 = ((*start) << 1UL) & mask1_64;
  tmp2 = (*start) & mask2_64;
  tmp2 = (tmp2 << 1UL) - (tmp2 >> 15UL);
  *start = (tmp1) ^ (tmp2 & prim_64);
  ++start;
 }
}


decompiled_code:
unsigned __int64 __fastcall gf_region_multi_w16(_WORD *a1, unsigned int a2, int a3, _WORD *a4, int a5)
{
_WORD *v5; // r12
unsigned __int64 result; // rax
__int64 v7; // r13
_WORD *v8; // rbx
_WORD *v9; // rbp
char *v10; // rbx
__int64 v11; // rbp
int v12; // [rsp+Ch] [rbp-4Ch]
unsigned __int64 v13; // [rsp+18h] [rbp-40h] BYREF
char v14; // [rsp+20h] [rbp-38h] BYREF

if ( a4 )
{
v5 = a4;
result = (unsigned int)(a3 / 2);
v12 = a3 / 2;
if ( a2 )
{
if ( a5 )
{
v7 = 0LL;
if ( a3 > 1 )
{
do
{
v9 = &a1[v7];
v10 = (char *)&v13;
do
{
if ( *v9 )
*(_WORD *)v10 = gf_logtable_multi((unsigned __int16)*v9, a2, 16LL);
else
*(_WORD *)v10 = 0;
++v9;
v10 += 2;
}
while ( v10 != &v14 );
result = v13;
*(_QWORD *)&v5[v7] ^= v13;
v7 += 4LL;
}
while ( v12 > (int)v7 );
}
return result;
}
goto LABEL_22;
}
}
else
{
result = (unsigned int)a3 >> 31;
v12 = a3 / 2;
v5 = a1;
if ( a2 )
{
LABEL_22:
result = (unsigned int)v12;
if ( v12 > 0 )
{
v8 = a1;
result = (unsigned int)(v12 - 1);
v11 = (__int64)&a1[result + 1];
do
{
if ( *v8 )
{
result = gf_logtable_multi(a2, (unsigned __int16)*v8, 16LL);
*v5 = result;
}
else
{
*v5 = 0;
}
++v8;
++v5;
}
while ( v8 != (_WORD *)v11 );
}
return result;
}
v5 = a1;
}
if ( !a5 )
{
for ( result = (unsigned __int64)&v5[v12]; result > (unsigned __int64)v5; v5 += 4 )
*(_QWORD *)v5 = 0LL;
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func5(_WORD *a1, unsigned int a2, int a3, _WORD *a4, int a5)
{
_WORD *v5; // r12
unsigned __int64 result; // rax
__int64 v7; // r13
_WORD *v8; // rbx
_WORD *v9; // rbp
char *v10; // rbx
__int64 v11; // rbp
int v12; // [rsp+Ch] [rbp-4Ch]
unsigned __int64 v13; // [rsp+18h] [rbp-40h] BYREF
char v14; // [rsp+20h] [rbp-38h] BYREF

if ( a4 )
{
v5 = a4;
result = (unsigned int)(a3 / 2);
v12 = a3 / 2;
if ( a2 )
{
if ( a5 )
{
v7 = 0LL;
if ( a3 > 1 )
{
do
{
v9 = &a1[v7];
v10 = (char *)&v13;
do
{
if ( *v9 )
*(_WORD *)v10 = gf_logtable_multi((unsigned __int16)*v9, a2, 16LL);
else
*(_WORD *)v10 = 0;
++v9;
v10 += 2;
}
while ( v10 != &v14 );
result = v13;
*(_QWORD *)&v5[v7] ^= v13;
v7 += 4LL;
}
while ( v12 > (int)v7 );
}
return result;
}
goto LABEL_22;
}
}
else
{
result = (unsigned int)a3 >> 31;
v12 = a3 / 2;
v5 = a1;
if ( a2 )
{
LABEL_22:
result = (unsigned int)v12;
if ( v12 > 0 )
{
v8 = a1;
result = (unsigned int)(v12 - 1);
v11 = (__int64)&a1[result + 1];
do
{
if ( *v8 )
{
result = gf_logtable_multi(a2, (unsigned __int16)*v8, 16LL);
*v5 = result;
}
else
{
*v5 = 0;
}
++v8;
++v5;
}
while ( v8 != (_WORD *)v11 );
}
return result;
}
v5 = a1;
}
if ( !a5 )
{
for ( result = (unsigned __int64)&v5[v12]; result > (unsigned __int64)v5; v5 += 4 )
*(_QWORD *)v5 = 0LL;
}
return result;
}

original_code:
void gf_region_multi_w16(unsigned char *region,
  int multiby,
  int nbytes,
  unsigned char *reslt,
  int add) {
 unsigned short *r1, *r2, *cp;
 int i, j;
 unsigned long l, *lp2, *lptop;
 unsigned short *lp;
 int sol;
 r1 = (unsigned short *)region;
 r2 = (reslt == ((void *)0)) ? r1 : (unsigned short *)reslt;
 nbytes /= 2;
 if(multiby == 0) {
  if(!add) {
   lp2 = (unsigned long *) r2;
   r2 += nbytes;
   lptop = (unsigned long *) r2;
   while(lp2 < lptop) {
    *lp2 = 0;
    ++lp2;
   }
  }
  return;
 }
 if(reslt == ((void *)0) || !add) {
  for(i = 0; i < nbytes; ++i) {
   if(r1[i] == 0) {
    r2[i] = 0;
   } else{
    r2[i] = gf_logtable_multi(multiby, r1[i], 16);
   }
  }
 } else{
  sol = sizeof(long) / 2;
  lp2 = &l;
  lp = (unsigned short *) lp2;
  for(i = 0; i < nbytes; i += sol) {
   cp = r2 + i;
   lp2 = (unsigned long *)cp;
   for(j = 0; j < sol; ++j) {
    if(r1[i + j] == 0) {
     lp[j] = 0;
    } else {
     lp[j] = gf_logtable_multi(r1[i + j], multiby, 16);
    }
   }
   *lp2 = (*lp2) ^ l;
  }
 }
 return;
}

canonical_original_code:
void gf_region_multi_w16(unsigned char *region, int multiby, int nbytes, unsigned char *reslt, int add) {
 unsigned short *r1; unsigned short *r2; unsigned short *cp;
 int i; int j;
 unsigned long l; unsigned long *lp2; unsigned long *lptop;
 unsigned short *lp;
 int sol;
 r1 = (unsigned short *)region;
 r2 = (reslt == ((void *)0)) ? r1 : (unsigned short *)reslt;
 nbytes /= 2;
 if(multiby == 0) {
  if(!add) {
   lp2 = (unsigned long *) r2;
   r2 += nbytes;
   lptop = (unsigned long *) r2;
   while(lp2 < lptop) {
    *lp2 = 0;
    ++lp2;
   }
  }
  return;
 }
 if(reslt == ((void *)0) || !add) {
  for(i = 0; i < nbytes; ++i) {
   if(r1[i] == 0) {
    r2[i] = 0;
   } else{
    r2[i] = gf_logtable_multi(multiby, r1[i], 16);
   }
  }
 } else{
  sol = sizeof(long) / 2;
  lp2 = &l;
  lp = (unsigned short *) lp2;
  for(i = 0; i < nbytes; i += sol) {
   cp = r2 + i;
   lp2 = (unsigned long *)cp;
   for(j = 0; j < sol; ++j) {
    if(r1[i + j] == 0) {
     lp[j] = 0;
    } else {
     lp[j] = gf_logtable_multi(r1[i + j], multiby, 16);
    }
   }
   *lp2 = (*lp2) ^ l;
  }
 }
 return;
}

variable_types: multiby int

variable_types:
reslt
unsigned char *

variable_types: add int

variable_types:
cp
unsigned short *

variable_types: i int

variable_types: j int

variable_types:
l
unsigned long

variable_types:
lptop
unsigned long *

variable_types:
lp
unsigned short *

variable_types: sol int


decompiled_code:
__int64 __fastcall gf_inverse_w16(unsigned int a1)
{
__int64 result; // rax

if ( a1 )
result = gf_single_div(1LL, a1, 16LL);
else
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned int a1)
{
__int64 result; // rax

if ( a1 )
result = gf_single_div(1LL, a1, 16LL);
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int gf_inverse_w16(int y) {
 if(y == 0) return -1;
 return gf_single_div(1, y, 16);
}

variable_types: y int


decompiled_code:
int __fastcall mem_print(__int64 a1, int a2, int a3)
{
__int64 v4; // rbx

if ( a2 > 0 )
{
v4 = 1LL;
do
{
printf("%d ", *(unsigned __int8 *)(a1 + v4 - 1));
if ( !((int)v4 % a3) )
putchar(10);
++v4;
}
while ( v4 != a2 + 1 );
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1, int a2, int a3)
{
__int64 v4; // rbx

if ( a2 > 0 )
{
v4 = 1LL;
do
{
printf("%d ", *(unsigned __int8 *)(a1 + v4 - 1));
if ( !((int)v4 % a3) )
putchar(10);
++v4;
}
while ( v4 != a2 + 1 );
}
return putchar(10);
}

original_code:
void mem_print(unsigned char *mem, int len, int breaklen) {
 int i;
 for(i = 0; i < len; ++i) {
  printf("%d ", *(mem + i));
  if((i + 1) % breaklen == 0) {
   printf("\n");
  }
 }
 printf("\n");
}

variable_types:
mem
unsigned char *

variable_types: len int

variable_types: breaklen int


resize

repo: oyjw/SDB

original_code:
static int resize(struct sdb_map* sm,int newslots){
 struct node** newbuckets=calloc(1,sizeof(struct node*)*newslots);
 if(newbuckets==((void *)0)) return -1;
 int i;
 for(i=0;i<sm->slots;++i){
  if(sm->buckets[i]!=((void *)0)){
   struct node *n=sm->buckets[i];
   do{
    int hash=(n->key)%newslots;
    struct node* next=n->next;
    n->next=newbuckets[hash];
    newbuckets[hash]=n;
    n=next;
   }while(n!=((void *)0));
  }
 }
 struct node** old=sm->buckets;
 sm->buckets=newbuckets;
 sm->slots=newslots;
 free(old);
 return 0;
}

canonical_original_code:
static int resize(struct sdb_map *sm, int newslots){
 struct node **newbuckets = calloc(1,sizeof(struct node*)*newslots);
 if(newbuckets==((void *)0)) return -1;
 int i;
 for(i=0;i<sm->slots;++i){
  if(sm->buckets[i]!=((void *)0)){
   struct node *n = sm->buckets[i];
   do{
    int hash = (n->key)%newslots;
    struct node *next = n->next;
    n->next=newbuckets[hash];
    newbuckets[hash]=n;
    n=next;
   }while(n!=((void *)0));
  }
 }
 struct node **old = sm->buckets;
 sm->buckets=newbuckets;
 sm->slots=newslots;
 free(old);
 return 0;
}

variable_types: struct sdb_map { int slots; int size; struct node { void *data; int key; struct node *next; } **buckets; } *

variable_types: newslots int

variable_types: hash int

user_defined_types: struct sdb_map { int slots; int size; struct node **buckets; }


decompiled_code:
void __fastcall sdb_map_free(void *ptr)
{
__int64 v2; // rbp
_QWORD *v3; // rbx
void *v4; // rdi

if ( *(int *)ptr > 0 )
{
v2 = 0LL;
do
{
v3 = *(_QWORD **)(*((_QWORD *)ptr + 1) + 8 * v2);
while ( v3 )
{
v4 = v3;
v3 = (_QWORD *)v3[2];
free(v4);
}
++v2;
}
while ( *(_DWORD *)ptr > (int)v2 );
}
free(*((void **)ptr + 1));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
__int64 v2; // rbp
_QWORD *v3; // rbx
void *v4; // rdi

if ( *(int *)ptr > 0 )
{
v2 = 0LL;
do
{
v3 = *(_QWORD **)(*((_QWORD *)ptr + 1) + 8 * v2);
while ( v3 )
{
v4 = v3;
v3 = (_QWORD *)v3[2];
free(v4);
}
++v2;
}
while ( *(_DWORD *)ptr > (int)v2 );
}
free(*((void **)ptr + 1));
free(ptr);
}

original_code:
void sdb_map_free(struct sdb_map* sm){
 int i;
 for(i=0;i<sm->slots;++i){
  if(sm->buckets[i]!=((void *)0)){
   struct node *n=sm->buckets[i];
   do{
    struct node* next=n->next;
    free(n);
    n=next;
   }while(n!=((void *)0));
  }
 }
 free(sm->buckets);
 free(sm);
}

canonical_original_code:
void sdb_map_free(struct sdb_map *sm){
 int i;
 for(i=0;i<sm->slots;++i){
  if(sm->buckets[i]!=((void *)0)){
   struct node *n = sm->buckets[i];
   do{
    struct node *next = n->next;
    free(n);
    n=next;
   }while(n!=((void *)0));
  }
 }
 free(sm->buckets);
 free(sm);
}

variable_types: struct node { void *data; int key; struct node *next; } *


decompiled_code:
_QWORD *sdb_map_new()
{
_DWORD *v0; // rax
_QWORD *v1; // rbx
void *v2; // rbp

v0 = malloc(0x10uLL);
v1 = v0;
if ( v0 )
{
*v0 = 8;
v0[1] = 0;
v2 = calloc(1uLL, 0x40uLL);
v1[1] = v2;
if ( !v2 )
{
free(v1);
v1 = 0LL;
}
}
return v1;
}

canonical_decompiled_code:
_QWORD *func2()
{
_DWORD *v0; // rax
_QWORD *v1; // rbx
void *v2; // rbp

v0 = malloc(0x10uLL);
v1 = v0;
if ( v0 )
{
*v0 = 8;
v0[1] = 0;
v2 = calloc(1uLL, 0x40uLL);
v1[1] = v2;
if ( !v2 )
{
free(v1);
v1 = 0LL;
}
}
return v1;
}

original_code:
struct sdb_map* sdb_map_new(){
 struct sdb_map *sm=malloc(sizeof(struct sdb_map));
 if(sm==((void *)0)) return ((void *)0);
 sm->slots=8;
 sm->size=0;
 sm->buckets=calloc(1,sizeof(struct node*)*sm->slots);
 if(sm->buckets==((void *)0)) {
  free(sm);
  return ((void *)0);
 }
 return sm;
}

canonical_original_code:
struct sdb_map *sdb_map_new(){
 struct sdb_map *sm = malloc(sizeof(struct sdb_map));
 if(sm==((void *)0)) return ((void *)0);
 sm->slots=8;
 sm->size=0;
 sm->buckets=calloc(1,sizeof(struct node *)*sm->slots);
 if(sm->buckets==((void *)0)) {
  free(sm);
  return ((void *)0);
 }
 return sm;
}

return_type: struct sdb_map { int slots; int size; struct node { void *data; int key; struct node *next; } **buckets; } *


decompiled_code:
__int64 __fastcall sdb_map_put(__int64 a1, int a2, __int64 a3)
{
int v4; // er13
_QWORD *v5; // rax
_QWORD *v6; // rdx

if ( *(_DWORD *)(a1 + 4) >= *(_DWORD *)a1 && (int)resize(a1, 2 * *(_DWORD *)a1) < 0 )
return 0xFFFFFFFFLL;
v4 = a2 % *(_DWORD *)a1;
v5 = malloc(0x18uLL);
if ( !v5 )
return 0xFFFFFFFFLL;
v6 = (_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * v4);
v5[2] = *v6;
*((_DWORD *)v5 + 2) = a2;
*v5 = a3;
*v6 = v5;
++*(_DWORD *)(a1 + 4);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int a2, __int64 a3)
{
int v4; // er13
_QWORD *v5; // rax
_QWORD *v6; // rdx

if ( *(_DWORD *)(a1 + 4) >= *(_DWORD *)a1 && (int)func0(a1, 2 * *(_DWORD *)a1) < 0 )
return 0xFFFFFFFFLL;
v4 = a2 % *(_DWORD *)a1;
v5 = malloc(0x18uLL);
if ( !v5 )
return 0xFFFFFFFFLL;
v6 = (_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * v4);
v5[2] = *v6;
*((_DWORD *)v5 + 2) = a2;
*v5 = a3;
*v6 = v5;
++*(_DWORD *)(a1 + 4);
return 0LL;
}

original_code:
int sdb_map_put(struct sdb_map* sm,int key,void* data){
 if(sm->size>=sm->slots) {
  if(resize(sm,sm->slots*2)<0) return -1;
 }
 int hash=key%sm->slots;
 struct node* n=malloc(sizeof(struct node));
 if(n==((void *)0)) return -1;
 n->next=sm->buckets[hash];
 n->key=key;
 n->data=data;
 sm->buckets[hash]=n;
 sm->size++;
 return 0;
}

canonical_original_code:
int sdb_map_put(struct sdb_map *sm, int key, void *data){
 if(sm->size>=sm->slots) {
  if(resize(sm,sm->slots*2)<0) return -1;
 }
 int hash = key%sm->slots;
 struct node *n = malloc(sizeof(struct node));
 if(n==((void *)0)) return -1;
 n->next=sm->buckets[hash];
 n->key=key;
 n->data=data;
 sm->buckets[hash]=n;
 sm->size++;
 return 0;
}

variable_types: key int

variable_types:
data
void *

user_defined_types: struct node { void *data; int key; struct node *next; }


original_code:
int sdb_map_erase(struct sdb_map* sm,int key){
 int hash=key%sm->slots;
 struct node* n=sm->buckets[hash];
 struct node* prev=n;
 while(n!=((void *)0)){
  if(n->key==key) {
   if(prev==n) {
    sm->buckets[hash]=n->next;
   }else {
    prev->next=n->next;
   }
   free(n);
   return 0;
  }else {
   prev=n;
   n=n->next;
  }
 }
 return -1;
}

canonical_original_code:
int sdb_map_erase(struct sdb_map *sm, int key){
 int hash = key%sm->slots;
 struct node *n = sm->buckets[hash];
 struct node *prev = n;
 while(n!=((void *)0)){
  if(n->key==key) {
   if(prev==n) {
    sm->buckets[hash]=n->next;
   }else {
    prev->next=n->next;
   }
   free(n);
   return 0;
  }else {
   prev=n;
   n=n->next;
  }
 }
 return -1;
}


decompiled_code:
int __fastcall map_dump(__int64 a1)
{
__int64 v1; // rbp
__int64 i; // rbx

if ( *(int *)a1 > 0 )
{
v1 = 0LL;
do
{
for ( i = *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8 * v1); i; i = *(_QWORD *)(i + 16) )
fprintf(stderr, "n->key:%d ", *(unsigned int *)(i + 8));
++v1;
}
while ( *(_DWORD *)a1 > (int)v1 );
}
return fputc(10, stderr);
}

canonical_decompiled_code:
int __fastcall func5(__int64 a1)
{
__int64 v1; // rbp
__int64 i; // rbx

if ( *(int *)a1 > 0 )
{
v1 = 0LL;
do
{
for ( i = *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8 * v1); i; i = *(_QWORD *)(i + 16) )
fprintf(stderr, "n->key:%d ", *(unsigned int *)(i + 8));
++v1;
}
while ( *(_DWORD *)a1 > (int)v1 );
}
return fputc(10, stderr);
}

original_code:
void map_dump(sdb_map* sm){
    int i;
 for(i=0;i<sm->slots;++i){
  if(sm->buckets[i]!=((void *)0)){
   struct node *n=sm->buckets[i];
   while(n!=((void *)0)){
       fprintf(stderr,"n->key:%d  ",n->key);
                n=n->next;
   }
  }
 }
 fprintf(stderr,"\n");
}

canonical_original_code:
void map_dump(struct sdb_map *sm){
    int i;
 for(i=0;i<sm->slots;++i){
  if(sm->buckets[i]!=((void *)0)){
   struct node *n = sm->buckets[i];
   while(n!=((void *)0)){
       fprintf(stderr,"n->key:%d  ",n->key);
                n=n->next;
   }
  }
 }
 fprintf(stderr,"\n");
}


errdump

decompiled_code:
void __noreturn errdump(const char *a1, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a1);
vfprintf(stderr, a1, arg);
exit(1);
}

canonical_decompiled_code:
void __noreturn func0(const char *a1, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a1);
vfprintf(stderr, a1, arg);
exit(1);
}

original_code:
void errdump(char* msg,...){
    va_list ap;
    __builtin_va_start(ap,msg);
 vfprintf(stderr,msg,ap);
 __builtin_va_end(ap);
 exit(1);
}

canonical_original_code:
void errdump(char *msg, ...){
    __builtin_va_list ap;
    __builtin_va_start(ap,msg);
 vfprintf(stderr,msg,ap);
 __builtin_va_end(ap);
 exit(1);
}

variable_types:
msg
char *


tolowercase

decompiled_code:
size_t __fastcall tolowercase(char *s)
{
unsigned __int64 i; // rbx
size_t result; // rax

for ( i = 0LL; ; ++i )
{
result = strlen(s);
if ( result <= i )
break;
s[i] = (*_ctype_tolower_loc())[s[i]];
}
return result;
}

canonical_decompiled_code:
size_t __fastcall func1(char *s)
{
unsigned __int64 i; // rbx
size_t result; // rax

for ( i = 0LL; ; ++i )
{
result = strlen(s);
if ( result <= i )
break;
s[i] = (*_ctype_tolower_loc())[s[i]];
}
return result;
}

original_code:
void tolowercase(char* s){
 int i;
 for(i=0;i<strlen(s);++i)
  s[i]=tolower(s[i]);
}

canonical_original_code:
void tolowercase(char *s){
 int i;
 for(i=0;i<strlen(s);++i)
  s[i]=tolower(s[i]);
}

variable_types:
s
char *

variable_types: i int


repo: oyz/flvmerge

decompiled_code:
__int64 __fastcall FromInt32StringBe(unsigned int *a1)
{
return _byteswap_ulong(*a1);
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int *a1)
{
return _byteswap_ulong(*a1);
}

original_code:
unsigned int FromInt32StringBe(const unsigned char* const str)
{
    return ((str[0]<<24) |
     (str[1]<<16) |
     (str[2]<<8) |
     (str[3]));
}

canonical_original_code:
unsigned int FromInt32StringBe(unsigned char *str)
{
    return ((str[0]<<24) |
     (str[1]<<16) |
     (str[2]<<8) |
     (str[3]));
}

variable_types:
str
unsigned char *

return_type: unsigned int


decompiled_code:
__int64 __fastcall FromInt24StringBe(unsigned __int8 *a1)
{
return a1[2] | (a1[1] << 8) | (*a1 << 16);
}

original_code:
unsigned int FromInt24StringBe(const unsigned char* const str)
{
    return ((str[0]<<16) |
     (str[1]<<8) |
     (str[2]));
}

canonical_original_code:
unsigned int FromInt24StringBe(unsigned char *str)
{
    return ((str[0]<<16) |
     (str[1]<<8) |
     (str[2]));
}


GetTimestamp

original_code:
unsigned int GetTimestamp(const unsigned char* const pos)
{
    return ((pos[3]<<24) |
            (pos[0]<<16) |
     (pos[1]<<8) |
     (pos[2]));
}

canonical_original_code:
unsigned int GetTimestamp(unsigned char *pos)
{
    return ((pos[3]<<24) |
            (pos[0]<<16) |
     (pos[1]<<8) |
     (pos[2]));
}

variable_types:
pos
unsigned char *


PrintUsagesAndExit

decompiled_code:
void __noreturn PrintUsagesAndExit()
{
fwrite(
"usages:- [inputfilename1] [inputfilename2] ... [inputfilenameN] [mergefilename]\n"
"(must have two input files at least)\n",
1uLL,
0x75uLL,
stderr);
exit(1);
}

canonical_decompiled_code:
void __noreturn func5()
{
fwrite(
"usages:- [inputfilename1] [inputfilename2] ... [inputfilenameN] [mergefilename]\n"
"(must have two input files at least)\n",
1uLL,
0x75uLL,
stderr);
exit(1);
}

original_code:
static void PrintUsagesAndExit(void)
{
    fprintf(stderr, "usages:- [inputfilename1] [inputfilename2] ... [inputfilenameN] [mergefilename]\n"
     "(must have two input files at least)\n");
    exit(1);
}

canonical_original_code:
static void PrintUsagesAndExit()
{
    fprintf(stderr, "usages:- [inputfilename1] [inputfilename2] ... [inputfilenameN] [mergefilename]\n"
     "(must have two input files at least)\n");
    exit(1);
}


GetCurrentTimeInMicroseconds

decompiled_code:
__suseconds_t GetCurrentTimeInMicroseconds()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return v1.tv_usec + 1000000 * v1.tv_sec;
}

canonical_decompiled_code:
__suseconds_t func17()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return v1.tv_usec + 1000000 * v1.tv_sec;
}

original_code:
static long long GetCurrentTimeInMicroseconds(void)
{
    struct timeval tv;
    gettimeofday(&tv, ((void *)0));
    return (long long)tv.tv_sec*1000000 + tv.tv_usec;
}

canonical_original_code:
static long long GetCurrentTimeInMicroseconds()
{
    struct timeval tv;
    gettimeofday(&tv, ((void *)0));
    return (long long)tv.tv_sec*1000000 + tv.tv_usec;
}

variable_types: struct timeval { long tv_sec; long tv_usec; }

return_type: long long


original_code:
void list_init(List* li) {
    li->count = 0;
    li->head = ((void *)0);
    li->tail = ((void *)0);
}

canonical_original_code:
void list_init(struct List *li) {
    li->count = 0;
    li->head = ((void *)0);
    li->tail = ((void *)0);
}

variable_types: struct List { int count; struct Element { int value; int producer; struct Element *next; } *head; struct Element *tail; } *

user_defined_types: struct List { int count; struct Element *head; struct Element *tail; }


decompiled_code:
__int64 __fastcall list_insert(__int64 a1, __int64 a2)
{
__int64 result; // rax

if ( *(_DWORD *)a1 )
{
result = *(_QWORD *)(a1 + 16);
*(_QWORD *)(result + 8) = a2;
}
else
{
*(_QWORD *)(a1 + 8) = a2;
}
*(_QWORD *)(a1 + 16) = a2;
++*(_DWORD *)a1;
return result;
}

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

if ( *(_DWORD *)a1 )
{
result = *(_QWORD *)(a1 + 16);
*(_QWORD *)(result + 8) = a2;
}
else
{
*(_QWORD *)(a1 + 8) = a2;
}
*(_QWORD *)(a1 + 16) = a2;
++*(_DWORD *)a1;
return result;
}

original_code:
void list_insert(List* li, Element* el) {
    if(li->count == 0) {
        li->head = el;
        li->tail = el;
    }
    else {
        li->tail->next = el;
        li->tail = el;
    }
    li->count++;
}

canonical_original_code:
void list_insert(struct List *li, struct Element *el) {
    if(li->count == 0) {
        li->head = el;
        li->tail = el;
    }
    else {
        li->tail->next = el;
        li->tail = el;
    }
    li->count++;
}

variable_types:
el
struct Element *

user_defined_types: struct Element { int value; int producer; struct Element *next; }


decompiled_code:
__int64 __fastcall list_retrieve(int *a1)
{
int v1; // eax
__int64 v2; // rdx

v1 = *a1;
if ( !*a1 )
return 0LL;
v2 = *((_QWORD *)a1 + 1);
*((_QWORD *)a1 + 1) = *(_QWORD *)(v2 + 8);
*a1 = v1 - 1;
return v2;
}

original_code:
Element* list_retrieve(List* li) {
    if(li->count == 0) {
        return ((void *)0);
    }
    Element* el = li->head;
    li->head = li->head->next;
    li->count--;
    return el;
}

canonical_original_code:
struct Element *list_retrieve(struct List *li) {
    if(li->count == 0) {
        return ((void *)0);
    }
    struct Element *el = li->head;
    li->head = li->head->next;
    li->count--;
    return el;
}

variable_types: struct List { int count; struct Element *head; struct Element *tail; } *

variable_types: struct Element { int value; int producer; struct Element *next; } *


decompiled_code:
int __fastcall list_dump(__int64 a1)
{
unsigned int *v1; // rbx
int result; // eax

v1 = *(unsigned int **)(a1 + 8);
if ( v1 )
{
do
{
printf("%d ", *v1);
v1 = (unsigned int *)*((_QWORD *)v1 + 1);
}
while ( v1 );
result = puts("\n");
}
return result;
}

canonical_decompiled_code:
int __fastcall func12(__int64 a1)
{
unsigned int *v1; // rbx
int result; // eax

v1 = *(unsigned int **)(a1 + 8);
if ( v1 )
{
do
{
printf("%d ", *v1);
v1 = (unsigned int *)*((_QWORD *)v1 + 1);
}
while ( v1 );
result = puts("\n");
}
return result;
}

original_code:
void list_dump(List* li) {
    if(!li->head) return;
    Element* el = li->head;
    do {
        printf("%d ", el->value);
    } while(el = el->next);
    printf("\n\n");
}

canonical_original_code:
void list_dump(struct List *li) {
    if(!li->head) return;
    struct Element *el = li->head;
    do {
        printf("%d ", el->value);
    } while(el = el->next);
    printf("\n\n");
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v4; // rbx
pthread_t v5; // [rsp+8h] [rbp-20h] BYREF
pthread_t th; // [rsp+10h] [rbp-18h] BYREF
pthread_t newthread[2]; // [rsp+18h] [rbp-10h] BYREF

if ( argc == 4 )
{
infile = (char *)argv[1];
qword_4040C8 = (__int64)argv[2];
v4 = (char *)argv[3];
remove(v4);
list_init((__int64)buffer);
sem_init(&mutex, 0, 1u);
sem_init(&empty, 0, 0x64u);
sem_init(&full, 0, 0);
pthread_create(newthread, 0LL, (void *(*)(void *))produce, 0LL);
pthread_create(&th, 0LL, (void *(*)(void *))produce, (void *)1);
pthread_create(&v5, 0LL, (void *(*)(void *))consume, v4);
pthread_join(newthread[0], 0LL);
pthread_join(th, 0LL);
pthread_join(v5, 0LL);
sem_destroy(&mutex);
sem_destroy(&empty);
sem_destroy(&full);
}
else
{
puts("Usage: pc <infile1> <infile2> <outfile>");
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v4; // rbx
pthread_t v5; // [rsp+8h] [rbp-20h] BYREF
pthread_t th; // [rsp+10h] [rbp-18h] BYREF
pthread_t newthread[2]; // [rsp+18h] [rbp-10h] BYREF

if ( argc == 4 )
{
infile = (char *)argv[1];
qword_4040C8 = (__int64)argv[2];
v4 = (char *)argv[3];
remove(v4);
func7((__int64)buffer);
sem_init(&mutex, 0, 1u);
sem_init(&empty, 0, 0x64u);
sem_init(&full, 0, 0);
pthread_create(newthread, 0LL, (void *(*)(void *))produce, 0LL);
pthread_create(&th, 0LL, (void *(*)(void *))produce, (void *)1);
pthread_create(&v5, 0LL, (void *(*)(void *))consume, v4);
pthread_join(newthread[0], 0LL);
pthread_join(th, 0LL);
pthread_join(v5, 0LL);
sem_destroy(&mutex);
sem_destroy(&empty);
sem_destroy(&full);
}
else
{
puts("Usage: pc <infile1> <infile2> <outfile>");
}
return 0;
}

original_code:
int main(int argc, char** argv) {
    if(argc != 4) {
        printf("Usage: pc <infile1> <infile2> <outfile>\n");
        return 0;
    }
    infile[0] = argv[1];
    infile[1] = argv[2];
    char* outfile = argv[3];
    remove(outfile);
    list_init(&buffer);
    pthread_t producer1, producer2, consumer;
    sem_init(&mutex, 0, 1);
    sem_init(&empty, 0, 100);
    sem_init(&full, 0, 0);
    pthread_create(&producer1, ((void *)0), (void*)&produce, (void*) 0);
    pthread_create(&producer2, ((void *)0), (void*)&produce, (void*) 1);
    pthread_create(&consumer, ((void *)0), (void*)&consume, (void*) outfile);
    pthread_join(producer1, ((void *)0));
    pthread_join(producer2, ((void *)0));
    pthread_join(consumer, ((void *)0));
    sem_destroy(&mutex);
    sem_destroy(&empty);
    sem_destroy(&full);
    return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
    if(argc != 4) {
        printf("Usage: pc <infile1> <infile2> <outfile>\n");
        return 0;
    }
    infile[0] = argv[1];
    infile[1] = argv[2];
    char *outfile = argv[3];
    remove(outfile);
    list_init(&buffer);
    unsigned long producer1; unsigned long producer2; unsigned long consumer;
    sem_init(&mutex, 0, 1);
    sem_init(&empty, 0, 100);
    sem_init(&full, 0, 0);
    pthread_create(&producer1, ((void *)0), (void *)&produce, (void *) 0);
    pthread_create(&producer2, ((void *)0), (void *)&produce, (void *) 1);
    pthread_create(&consumer, ((void *)0), (void *)&consume, (void *) outfile);
    pthread_join(producer1, ((void *)0));
    pthread_join(producer2, ((void *)0));
    pthread_join(consumer, ((void *)0));
    sem_destroy(&mutex);
    sem_destroy(&empty);
    sem_destroy(&full);
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
outfile
char *

variable_types:
consumer
unsigned long


decompiled_code:
int __fastcall pair_compare(const void *a1, const void *a2)
{
return strcmp((const char *)a1, (const char *)a2);
}

canonical_decompiled_code:
int __fastcall func7(const void *a1, const void *a2)
{
return strcmp((const char *)a1, (const char *)a2);
}

original_code:
int pair_compare(const void *a, const void *b) {
    return strcmp((*(Pair*)a).word, (*(Pair*)b).word);
}

canonical_original_code:
int pair_compare(void *a, void *b) {
    return strcmp((*(struct Pair *)a).word, (*(struct Pair *)b).word);
}

variable_types:
a
void *

variable_types:
b
void *

user_defined_types: struct Pair { char word[100]; int count; }


hash

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

v1 = *a1;
if ( !*a1 )
return 0;
v2 = a1 + 1;
v3 = 0;
do
{
v3 += v1;
v1 = *v2++;
}
while ( v1 );
return v3;
}

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

v1 = *a1;
if ( !*a1 )
return 0;
v2 = a1 + 1;
v3 = 0;
do
{
v3 += v1;
v1 = *v2++;
}
while ( v1 );
return v3;
}

original_code:
int hash(char word[]) {
    int hash = 0;
    int i;
    for(i=0; word[i]; i++) {
        hash += (int) word[i];
    }
    return hash;
}

variable_types:
word
char []

variable_types: hash int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebx
unsigned int v4; // eax
int v6; // ebx
__int64 v7; // rax
void *v8; // rsp
pthread_t *v9; // r14
char *v10; // rbx
__int64 v11; // rbx
unsigned int v12; // eax
void *v13; // rsp
pthread_t *v14; // r14
char *v15; // rbx
__int64 v16; // rbx
unsigned int v17; // eax
unsigned int v18; // eax
__int64 v19; // [rsp+0h] [rbp-30h] BYREF
pthread_t newthread[5]; // [rsp+8h] [rbp-28h] BYREF

system("rm temp* out*");
if ( argc <= 4 )
{
puts("Usage: wordcount <M> <R> <infile1> ... <infileM> <finalfile>");
}
else
{
v3 = atoi(argv[1]);
M = v3;
v4 = atoi(argv[2]);
R = v4;
if ( v3 + 4 == argc )
{
printf("M:%d R:%d\n", v3, v4);
v6 = M;
input_files = malloc(8LL * M);
if ( v6 > 0 )
{
v7 = 0LL;
do
{
*((_QWORD *)input_files + v7) = argv[v7 + 3];
v6 = M;
++v7;
}
while ( M > (int)v7 );
}
final_file = (char *)argv[argc - 1];
v8 = alloca(8LL * v6);
if ( M > 0 )
{
v9 = (pthread_t *)&v19;
v10 = 0LL;
do
pthread_create(v9++, 0LL, (void *(*)(void *))parse, v10++);
while ( M > (int)v10 );
if ( M > 0 )
{
v11 = 0LL;
do
{
v12 = pthread_join(*(&v19 + v11), 0LL);
if ( v12 )
printf("error joining thread %d, error=%d\n", (unsigned int)v11, v12);
++v11;
}
while ( M > (int)v11 );
}
}
v13 = alloca(8LL * R);
if ( R > 0 )
{
v14 = (pthread_t *)&v19;
v15 = 0LL;
do
pthread_create(v14++, 0LL, (void *(*)(void *))count, v15++);
while ( R > (int)v15 );
if ( R > 0 )
{
v16 = 0LL;
do
{
v17 = pthread_join(*(&v19 + v16), 0LL);
if ( v17 )
printf("error joining thread %d, error=%d\n", (unsigned int)v16, v17);
++v16;
}
while ( R > (int)v16 );
}
}
pthread_create(newthread, 0LL, (void *(*)(void *))merge, 0LL);
v18 = pthread_join(newthread[0], 0LL);
if ( v18 )
printf("error joining merger thread, error=%d\n", v18);
puts("Word counting has been completed.");
free(input_files);
}
else
{
puts("Number of parameters does not match with M.\nUsage: wordcount <M> <R> <infile1> ... <infileM> <finalfile>");
}
}
return 0;
}

original_code:
int main(int argc, char** argv) {
    int i, err;
    system("rm temp* out*");
    if(argc < 5) {
        printf("Usage: wordcount <M> <R> <infile1> ... <infileM> <finalfile>\n");
        return 0;
    }
    M = atoi(argv[1]);
    R = atoi(argv[2]);
    if(argc != 4+M) {
        printf("Number of parameters does not match with M.\nUsage: wordcount <M> <R> <infile1> ... <infileM> <finalfile>\n");
        return 0;
    }
    printf("M:%d R:%d\n", M, R);
    input_files = (char**) malloc(M * sizeof(char*));
    for(i=0; i<M; i++) {
        input_files[i] = argv[i+3];
    }
    final_file = argv[argc-1];
    pthread_t parser_threads[M];
    for(i=0; i<M; i++) {
        pthread_create(&parser_threads[i], ((void *)0), (void*)&parse, (void*) i);
    }
    for(i=0; i<M; i++) {
        err = pthread_join(parser_threads[i], ((void *)0));
        if (err)
            printf("error joining thread %d, error=%d\n", i, err);
    }
    pthread_t counter_threads[R];
    for(i=0; i<R; i++) {
        pthread_create(&counter_threads[i], ((void *)0), (void*)&count, (void*) i);
    }
    for(i=0; i<R; i++) {
        err = pthread_join(counter_threads[i], ((void *)0));
        if (err)
            printf("error joining thread %d, error=%d\n", i, err);
    }
    pthread_t merger_thread;
    pthread_create(&merger_thread, ((void *)0), (void*)&merge, ((void *)0));
    err = pthread_join(merger_thread, ((void *)0));
    if (err)
        printf("error joining merger thread, error=%d\n", err);
    printf("Word counting has been completed.\n");
    free(input_files);
    return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
    int i; int err;
    system("rm temp* out*");
    if(argc < 5) {
        printf("Usage: wordcount <M> <R> <infile1> ... <infileM> <finalfile>\n");
        return 0;
    }
    M = atoi(argv[1]);
    R = atoi(argv[2]);
    if(argc != 4+M) {
        printf("Number of parameters does not match with M.\nUsage: wordcount <M> <R> <infile1> ... <infileM> <finalfile>\n");
        return 0;
    }
    printf("M:%d R:%d\n", M, R);
    input_files = (char **) malloc(M * sizeof(char *));
    for(i=0; i<M; i++) {
        input_files[i] = argv[i+3];
    }
    final_file = argv[argc-1];
    unsigned long parser_threads[-1];
    for(i=0; i<M; i++) {
        pthread_create(&parser_threads[i], ((void *)0), (void *)&parse, (void *) i);
    }
    for(i=0; i<M; i++) {
        err = pthread_join(parser_threads[i], ((void *)0));
        if (err)
            printf("error joining thread %d, error=%d\n", i, err);
    }
    unsigned long counter_threads[-1];
    for(i=0; i<R; i++) {
        pthread_create(&counter_threads[i], ((void *)0), (void *)&count, (void *) i);
    }
    for(i=0; i<R; i++) {
        err = pthread_join(counter_threads[i], ((void *)0));
        if (err)
            printf("error joining thread %d, error=%d\n", i, err);
    }
    unsigned long merger_thread;
    pthread_create(&merger_thread, ((void *)0), (void *)&merge, ((void *)0));
    err = pthread_join(merger_thread, ((void *)0));
    if (err)
        printf("error joining merger thread, error=%d\n", err);
    printf("Word counting has been completed.\n");
    free(input_files);
    return 0;
}

variable_types: err int