decompiled_code:
__int64 __fastcall mt_unregister(void *ptr)
{
__int64 v1; // rax
_QWORD *v2; // rbp
__int64 v3; // r8
__int64 v4; // rax
__int64 v5; // rdx
__int64 result; // rax

if ( ptr )
{
v1 = mt_get_addr_by_mti((__int64)ptr);
v2 = (_QWORD *)v1;
if ( v1 )
{
v3 = *(_QWORD *)(v1 + 24);
if ( *(_BYTE *)(v1 + v3 + 56) != 0xCC )
fprintf(
stderr,
"%s : allocator %s : size %ld : %s(%d)\n",
"Warrning: buffer over run",
*(const char **)(v1 + 32),
v3,
*(const char **)(v1 + 40),
*(unsigned int *)(v1 + 48));
v4 = v2[1];
if ( v4 )
*(_QWORD *)(v4 + 16) = v2[2];
v5 = v2[2];
if ( v5 )
*(_QWORD *)(v5 + 8) = v4;
if ( (_QWORD *)__memory_trace_info_head_ == v2 )
__memory_trace_info_head_ = v5;
if ( (_QWORD *)__memory_trace_info_tail_ == v2 )
__memory_trace_info_tail_ = v2[1];
free(v2);
result = 0LL;
}
else
{
fprintf(
stderr,
"%s\n%s\n",
"Warrning: buffer addr in non mti header",
"if destroy memory table ? or mti register no use allocate buffer");
free(ptr);
result = 0xFFFFFFFFLL;
}
}
else
{
fprintf(stderr, "%s\n", "Warrning: buffer addr is NULL");
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(void *ptr)
{
__int64 v1; // rax
_QWORD *v2; // rbp
__int64 v3; // r8
__int64 v4; // rax
__int64 v5; // rdx
__int64 result; // rax

if ( ptr )
{
v1 = func4((__int64)ptr);
v2 = (_QWORD *)v1;
if ( v1 )
{
v3 = *(_QWORD *)(v1 + 24);
if ( *(_BYTE *)(v1 + v3 + 56) != 0xCC )
fprintf(
stderr,
"%s : allocator %s : size %ld : %s(%d)\n",
"Warrning: buffer over run",
*(const char **)(v1 + 32),
v3,
*(const char **)(v1 + 40),
*(unsigned int *)(v1 + 48));
v4 = v2[1];
if ( v4 )
*(_QWORD *)(v4 + 16) = v2[2];
v5 = v2[2];
if ( v5 )
*(_QWORD *)(v5 + 8) = v4;
if ( (_QWORD *)__memory_trace_info_head_ == v2 )
__memory_trace_info_head_ = v5;
if ( (_QWORD *)__memory_trace_info_tail_ == v2 )
__memory_trace_info_tail_ = v2[1];
free(v2);
result = 0LL;
}
else
{
fprintf(
stderr,
"%s\n%s\n",
"Warrning: buffer addr in non mti header",
"if destroy memory table ? or mti register no use allocate buffer");
free(ptr);
result = 0xFFFFFFFFLL;
}
}
else
{
fprintf(stderr, "%s\n", "Warrning: buffer addr is NULL");
result = 0LL;
}
return result;
}

original_code:
int mt_unregister(void *addr)
{
 mti *n;
 if(!addr){
  fprintf(stderr, "%s\n", "Warrning: buffer addr is NULL");
  return 0;
 }
 n = mt_get_addr_by_mti(addr);
 if(n == ((void *)0)){
  fprintf(stderr, "%s\n%s\n",
   "Warrning: buffer addr in non mti header",
   "if destroy memory table ? or mti register no use allocate buffer"
  );
  free(addr);
  return -1;
 }
 if((*((unsigned char*)n + sizeof(mti) + n->size) != 0xcc)){
  fprintf(stderr, "%s : allocator %s : size %ld : %s(%d)\n",
   "Warrning: buffer over run",
   n->callfunc, n->size, n->file, n->line
  );
 }
 if(n->prev)n->prev->next = n->next;
 if(n->next)n->next->prev = n->prev;
 if(___memory_trace_info_head___ == n){
  ___memory_trace_info_head___ = ___memory_trace_info_head___->next;
 }
 if(___memory_trace_info_tail___ == n){
  ___memory_trace_info_tail___ = ___memory_trace_info_tail___->prev;
 }
 memset(n, 0xdd, sizeof(mti) + n->size);
 free(n);
 return 0;
}

canonical_original_code:
int mt_unregister(void *addr)
{
 struct malloc_trace_info *n;
 if(!addr){
  fprintf(stderr, "%s\n", "Warrning: buffer addr is NULL");
  return 0;
 }
 n = mt_get_addr_by_mti(addr);
 if(n == ((void *)0)){
  fprintf(stderr, "%s\n%s\n",
   "Warrning: buffer addr in non mti header",
   "if destroy memory table ? or mti register no use allocate buffer"
  );
  free(addr);
  return -1;
 }
 if((*((unsigned char *)n + sizeof(mti) + n->size) != 0xcc)){
  fprintf(stderr, "%s : allocator %s : size %ld : %s(%d)\n",
   "Warrning: buffer over run",
   n->callfunc, n->size, n->file, n->line
  );
 }
 if(n->prev)n->prev->next = n->next;
 if(n->next)n->next->prev = n->prev;
 if(___memory_trace_info_head___ == n){
  ___memory_trace_info_head___ = ___memory_trace_info_head___->next;
 }
 if(___memory_trace_info_tail___ == n){
  ___memory_trace_info_tail___ = ___memory_trace_info_tail___->prev;
 }
 memset(n, 0xdd, sizeof(mti) + n->size);
 free(n);
 return 0;
}


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

v1 = mt_get_addr_by_mti(a1);
if ( v1 )
result = *(_QWORD *)(v1 + 24);
else
result = 0LL;
return result;
}

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

v1 = func4(a1);
if ( v1 )
result = *(_QWORD *)(v1 + 24);
else
result = 0LL;
return result;
}

original_code:
size_t mt_get_buf_size(void *addr)
{
 mti *mt;
 mt = mt_get_addr_by_mti(addr);
 if(!mt){
  return 0;
 }
 return mt->size;
}

canonical_original_code:
unsigned long mt_get_buf_size(void *addr)
{
 struct malloc_trace_info *mt;
 mt = mt_get_addr_by_mti(addr);
 if(!mt){
  return 0;
 }
 return mt->size;
}

variable_types:
addr
void *

variable_types: struct malloc_trace_info { char *head; struct malloc_trace_info *prev; struct malloc_trace_info *next; unsigned long size; char *callfunc; char *file; int line; } *

return_type: unsigned long


decompiled_code:
// attributes: thunk
__int64 mt_malloc()
{
return mt_register();
}

canonical_decompiled_code:
__int64 func0()
{
return mt_register();
}

original_code:
void *mt_malloc(size_t size, char *callfunc, char *file, int line)
{
 return mt_register(size, callfunc, file, line);
}

canonical_original_code:
void *mt_malloc(unsigned long size, char *callfunc, char *file, int line)
{
 return mt_register(size, callfunc, file, line);
}

variable_types:
size
unsigned long

variable_types:
callfunc
char *

variable_types:
file
char *

variable_types: line int

return_type: void *


decompiled_code:
// attributes: thunk
__int64 mt_free()
{
return mt_unregister();
}

canonical_decompiled_code:
__int64 func1()
{
return mt_unregister();
}

original_code:
int mt_free(void *addr)
{
 return mt_unregister(addr);
}

return_type: int


decompiled_code:
void *__fastcall mt_realloc(void *src, __int64 a2, __int64 a3, __int64 a4, unsigned int a5)
{
void *v5; // r12
size_t v6; // rax

v5 = (void *)mt_malloc(a2, a3, a4, a5);
if ( v5 )
{
v6 = mt_get_buf_size(src);
memmove(v5, src, v6);
mt_free(src);
}
return v5;
}

canonical_decompiled_code:
void *__fastcall func2(void *src, __int64 a2, __int64 a3, __int64 a4, unsigned int a5)
{
void *v5; // r12
size_t v6; // rax

v5 = (void *)func0(a2, a3, a4, a5);
if ( v5 )
{
v6 = mt_get_buf_size(src);
memmove(v5, src, v6);
func1(src);
}
return v5;
}

original_code:
void *mt_realloc(void *addr, size_t size, char *callfunc, char *file, int line)
{
 void *buf;
 buf = mt_malloc(size, callfunc, file, line);
 if(buf){
  memmove(buf, addr, mt_get_buf_size(addr));
  mt_free(addr);
 }
 return buf;
}

canonical_original_code:
void *mt_realloc(void *addr, unsigned long size, char *callfunc, char *file, int line)
{
 void *buf;
 buf = mt_malloc(size, callfunc, file, line);
 if(buf){
  memmove(buf, addr, mt_get_buf_size(addr));
  mt_free(addr);
 }
 return buf;
}

variable_types:
buf
void *


decompiled_code:
void *__fastcall mt_calloc(__int64 a1, __int64 a2, __int64 a3, __int64 a4, unsigned int a5)
{
void *v5; // rax
void *v6; // r8

v5 = (void *)mt_malloc(a1 * a2, a3, a4, a5);
v6 = v5;
if ( v5 )
v6 = memset(v5, 0, a1 * a2);
return v6;
}

canonical_decompiled_code:
void *__fastcall func3(__int64 a1, __int64 a2, __int64 a3, __int64 a4, unsigned int a5)
{
void *v5; // rax
void *v6; // r8

v5 = (void *)func0(a1 * a2, a3, a4, a5);
v6 = v5;
if ( v5 )
v6 = memset(v5, 0, a1 * a2);
return v6;
}

original_code:
void *mt_calloc(size_t size1, size_t size2, char *callfunc, char *file, int line)
{
 void *buf;
 buf = mt_malloc(size1 * size2, callfunc, file, line);
 if(buf){
  memset(buf, 0x00, size1 * size2);
 }
 return buf;
}

canonical_original_code:
void *mt_calloc(unsigned long size1, unsigned long size2, char *callfunc, char *file, int line)
{
 void *buf;
 buf = mt_malloc(size1 * size2, callfunc, file, line);
 if(buf){
  memset(buf, 0x00, size1 * size2);
 }
 return buf;
}


decompiled_code:
char *__fastcall mt_strdup(char *src, __int64 a2, __int64 a3, unsigned int a4)
{
size_t v6; // rax
char *v7; // rax
char *v8; // r8

v6 = strlen(src);
v7 = (char *)mt_malloc(v6 + 1, a2, a3, a4);
v8 = v7;
if ( v7 )
v8 = strcpy(v7, src);
return v8;
}

canonical_decompiled_code:
char *__fastcall func4(char *src, __int64 a2, __int64 a3, unsigned int a4)
{
size_t v6; // rax
char *v7; // rax
char *v8; // r8

v6 = strlen(src);
v7 = (char *)func0(v6 + 1, a2, a3, a4);
v8 = v7;
if ( v7 )
v8 = strcpy(v7, src);
return v8;
}

original_code:
char *mt_strdup(char *str, char *callfunc, char *file, int line)
{
 char *buf;
 buf = (char*)mt_malloc(sizeof(char) * (strlen(str) + 1), callfunc, file, line);
 if(buf){
  strcpy(buf, str);
 }
 return buf;
}

canonical_original_code:
char *mt_strdup(char *str, char *callfunc, char *file, int line)
{
 char *buf;
 buf = (char *)mt_malloc(sizeof(char) * (strlen(str) + 1), callfunc, file, line);
 if(buf){
  strcpy(buf, str);
 }
 return buf;
}

variable_types:
str
char *

variable_types:
buf
char *

return_type: char *


decompiled_code:
__int64 __fastcall msl_alloc(_QWORD *a1, __int64 a2)
{
*a1 = mt_register(a2, "msl_alloc", "./msl.c", 21LL);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1, __int64 a2)
{
*a1 = mt_register(a2, "msl_alloc", "./msl.c", 21LL);
return 0LL;
}

original_code:
int msl_alloc(void **buf, size_t size)
{
 *buf = mt_register(size, "msl_alloc", "./msl.c", 21);
 if(!buf){
  return -1;
 }
 return 0;
}

canonical_original_code:
int msl_alloc(void **buf, unsigned long size)
{
 *buf = mt_register(size, "msl_alloc", "./msl.c", 21);
 if(!buf){
  return -1;
 }
 return 0;
}

variable_types:
buf
void **


decompiled_code:
__int64 __fastcall msl_free(_QWORD *a1)
{
if ( !a1 )
return 0LL;
if ( *a1 )
{
mt_unregister();
*a1 = 0LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1)
{
if ( !a1 )
return 0LL;
if ( *a1 )
{
mt_unregister();
*a1 = 0LL;
}
return 0LL;
}

original_code:
int msl_free(void **buf)
{
 if(!buf || !*buf){
  return 0;
 }
 mt_unregister(*buf);
 *buf = ((void *)0);
 return 0;
}


EsLoadShader

repo: yougukepp/Qe

decompiled_code:
__int64 __fastcall EsLoadShader(__int64 a1, const char *a2)
{
unsigned int v2; // eax
unsigned int v3; // er12
unsigned int v5; // ebp
char *v6; // r13
__int64 v7; // rdi
const char *v8; // [rsp+8h] [rbp-30h] BYREF
int v9; // [rsp+18h] [rbp-20h] BYREF
int v10[7]; // [rsp+1Ch] [rbp-1Ch] BYREF

v8 = a2;
v2 = glCreateShader();
v3 = v2;
if ( v2 )
{
glShaderSource(v2, 1LL, &v8, 0LL);
glCompileShader(v3);
glGetShaderiv(v3, 35713LL, &v9);
if ( !v9 )
{
v10[0] = 0;
glGetShaderiv(v3, 35716LL, v10);
v5 = v10[0];
if ( v10[0] > 1 )
{
v6 = (char *)malloc(v10[0]);
glGetShaderInfoLog(v3, v5, 0LL, v6);
printf("Error compiling shader:%s\n", v6);
printf("shader content:\n%s", v8);
free(v6);
}
v7 = v3;
v3 = 0;
glDeleteShader(v7);
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, const char *a2)
{
unsigned int v2; // eax
unsigned int v3; // er12
unsigned int v5; // ebp
char *v6; // r13
__int64 v7; // rdi
const char *v8; // [rsp+8h] [rbp-30h] BYREF
int v9; // [rsp+18h] [rbp-20h] BYREF
int v10[7]; // [rsp+1Ch] [rbp-1Ch] BYREF

v8 = a2;
v2 = glCreateShader();
v3 = v2;
if ( v2 )
{
glShaderSource(v2, 1LL, &v8, 0LL);
glCompileShader(v3);
glGetShaderiv(v3, 35713LL, &v9);
if ( !v9 )
{
v10[0] = 0;
glGetShaderiv(v3, 35716LL, v10);
v5 = v10[0];
if ( v10[0] > 1 )
{
v6 = (char *)malloc(v10[0]);
glGetShaderInfoLog(v3, v5, 0LL, v6);
printf("Error compiling shader:%s\n", v6);
printf("shader content:\n%s", v8);
free(v6);
}
v7 = v3;
v3 = 0;
glDeleteShader(v7);
}
}
return v3;
}

original_code:
static GLuint EsLoadShader(GLenum type, const GLchar* shaderSrc)
{
   GLuint shader;
   GLint compiled;
   shader = glCreateShader(type);
   if(0 == shader)
   {
       return 0;
   }
   glShaderSource(shader, 1, &shaderSrc, ((void *)0));
   glCompileShader(shader);
   glGetShaderiv(shader, 0x8B81, &compiled);
   if(!compiled)
   {
      GLint infoLen = 0;
      glGetShaderiv(shader, 0x8B84, &infoLen);
      if(infoLen > 1)
      {
         GLchar* infoLog = malloc(sizeof(GLchar) * infoLen);
         glGetShaderInfoLog (shader, infoLen, ((void *)0), infoLog);
         printf("Error compiling shader:%s\n", infoLog);
         printf("shader content:\n%s", shaderSrc);
         free(infoLog);
      }
      glDeleteShader ( shader );
      return 0;
   }
   return shader;
}

canonical_original_code:
static unsigned int EsLoadShader(unsigned int type, char *shaderSrc)
{
   unsigned int shader;
   int compiled;
   shader = glCreateShader(type);
   if(0 == shader)
   {
       return 0;
   }
   glShaderSource(shader, 1, &shaderSrc, ((void *)0));
   glCompileShader(shader);
   glGetShaderiv(shader, 0x8B81, &compiled);
   if(!compiled)
   {
      int infoLen = 0;
      glGetShaderiv(shader, 0x8B84, &infoLen);
      if(infoLen > 1)
      {
         char *infoLog = malloc(sizeof(GLchar) * infoLen);
         glGetShaderInfoLog (shader, infoLen, ((void *)0), infoLog);
         printf("Error compiling shader:%s\n", infoLog);
         printf("shader content:\n%s", shaderSrc);
         free(infoLog);
      }
      glDeleteShader ( shader );
      return 0;
   }
   return shader;
}

variable_types:
type
unsigned int

variable_types:
shaderSrc
char *

variable_types:
shader
unsigned int

variable_types: compiled int

variable_types: infoLen int

variable_types:
infoLog
char *

return_type: unsigned int


EsLoaderProgram

decompiled_code:
__int64 __fastcall EsLoaderProgram(const char *a1, const char *a2)
{
unsigned int v2; // er12
__int64 result; // rax
unsigned int v4; // ebp
unsigned int v5; // eax
unsigned int v6; // ebx
__int64 v7; // rsi
unsigned int v8; // er12

v2 = EsLoadShader(35633LL, a1);
if ( !v2 )
return 0LL;
v4 = EsLoadShader(35632LL, a2);
if ( v4 )
{
v5 = glCreateProgram();
v6 = v5;
if ( v5 )
{
v7 = v2;
v8 = v5;
glAttachShader(v5, v7);
glAttachShader(v6, v4);
result = v8;
}
else
{
result = 0LL;
}
}
else
{
glDeleteShader(v2);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1, const char *a2)
{
unsigned int v2; // er12
__int64 result; // rax
unsigned int v4; // ebp
unsigned int v5; // eax
unsigned int v6; // ebx
__int64 v7; // rsi
unsigned int v8; // er12

v2 = func0(35633LL, a1);
if ( !v2 )
return 0LL;
v4 = func0(35632LL, a2);
if ( v4 )
{
v5 = glCreateProgram();
v6 = v5;
if ( v5 )
{
v7 = v2;
v8 = v5;
glAttachShader(v5, v7);
glAttachShader(v6, v4);
result = v8;
}
else
{
result = 0LL;
}
}
else
{
glDeleteShader(v2);
result = 0LL;
}
return result;
}

original_code:
GLuint EsLoaderProgram(const GLchar* vertexShaderSrc, const GLchar* fragmentShaderSrc)
{
    GLuint vertexShader;
    GLuint fragmentShader;
    GLuint programObject;
    vertexShader = EsLoadShader(0x8B31, vertexShaderSrc);
    if (0 == vertexShader)
    {
        return 0;
    }
    fragmentShader = EsLoadShader(0x8B30, fragmentShaderSrc);
    if(0 == fragmentShader)
    {
        glDeleteShader(vertexShader);
        return 0;
    }
    programObject = glCreateProgram();
    if(0 == programObject)
    {
        return 0;
    }
    glAttachShader(programObject, vertexShader);
    glAttachShader(programObject, fragmentShader);
    return programObject;
}

canonical_original_code:
unsigned int EsLoaderProgram(char *vertexShaderSrc, char *fragmentShaderSrc)
{
    unsigned int vertexShader;
    unsigned int fragmentShader;
    unsigned int programObject;
    vertexShader = EsLoadShader(0x8B31, vertexShaderSrc);
    if (0 == vertexShader)
    {
        return 0;
    }
    fragmentShader = EsLoadShader(0x8B30, fragmentShaderSrc);
    if(0 == fragmentShader)
    {
        glDeleteShader(vertexShader);
        return 0;
    }
    programObject = glCreateProgram();
    if(0 == programObject)
    {
        return 0;
    }
    glAttachShader(programObject, vertexShader);
    glAttachShader(programObject, fragmentShader);
    return programObject;
}

variable_types:
vertexShaderSrc
char *

variable_types:
fragmentShaderSrc
char *

variable_types:
vertexShader
unsigned int

variable_types:
fragmentShader
unsigned int

variable_types:
programObject
unsigned int


EsBindAttribLocation

decompiled_code:
__int64 __fastcall EsBindAttribLocation(unsigned int a1, __int64 a2, int a3)
{
__int64 v3; // r13
__int64 i; // rbx
__int64 v6; // rdx
__int64 v7; // rsi
__int64 result; // rax

if ( a3 > 0 )
{
v3 = a3;
for ( i = 0LL; i != v3; ++i )
{
v6 = *(_QWORD *)(a2 + 8 * i);
v7 = (unsigned int)i;
result = glBindAttribLocation(a1, v7, v6);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1, __int64 a2, int a3)
{
__int64 v3; // r13
__int64 i; // rbx
__int64 v6; // rdx
__int64 v7; // rsi
__int64 result; // rax

if ( a3 > 0 )
{
v3 = a3;
for ( i = 0LL; i != v3; ++i )
{
v6 = *(_QWORD *)(a2 + 8 * i);
v7 = (unsigned int)i;
result = glBindAttribLocation(a1, v7, v6);
}
}
return result;
}

original_code:
GLvoid EsBindAttribLocation(GLint programId, GLchar *pAttr[], GLint size)
{
    GLint i = 0;
    for(i=0; i<size; i++)
    {
        glBindAttribLocation(programId, i, *pAttr);
        pAttr++;
    }
}

canonical_original_code:
void EsBindAttribLocation(int programId, char *pAttr[], int size)
{
    int i = 0;
    for(i=0; i<size; i++)
    {
        glBindAttribLocation(programId, i, *pAttr);
        pAttr++;
    }
}

variable_types: programId int

variable_types:
pAttr
char *[]

variable_types: size int

variable_types: i int

return_type: void


EsLinkProgram

decompiled_code:
__int64 __fastcall EsLinkProgram(unsigned int a1)
{
__int64 result; // rax
unsigned int v2; // er12
char *v3; // r13
unsigned int v4; // [rsp+8h] [rbp-20h] BYREF
int v5[7]; // [rsp+Ch] [rbp-1Ch] BYREF

glLinkProgram();
glGetProgramiv(a1, 35714LL, &v4);
result = v4;
if ( !v4 )
{
v5[0] = 0;
glGetProgramiv(a1, 35716LL, v5);
v2 = v5[0];
if ( v5[0] > 1 )
{
v3 = (char *)malloc(v5[0]);
glGetProgramInfoLog(a1, v2, 0LL, v3);
printf("Error linking program:%s\n", v3);
free(v3);
}
result = glDeleteProgram(a1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1)
{
__int64 result; // rax
unsigned int v2; // er12
char *v3; // r13
unsigned int v4; // [rsp+8h] [rbp-20h] BYREF
int v5[7]; // [rsp+Ch] [rbp-1Ch] BYREF

glLinkProgram();
glGetProgramiv(a1, 35714LL, &v4);
result = v4;
if ( !v4 )
{
v5[0] = 0;
glGetProgramiv(a1, 35716LL, v5);
v2 = v5[0];
if ( v5[0] > 1 )
{
v3 = (char *)malloc(v5[0]);
glGetProgramInfoLog(a1, v2, 0LL, v3);
printf("Error linking program:%s\n", v3);
free(v3);
}
result = glDeleteProgram(a1);
}
return result;
}

original_code:
GLvoid EsLinkProgram(GLint programId)
{
    GLint linked;
    glLinkProgram(programId);
    glGetProgramiv(programId, 0x8B82, &linked);
    if(!linked)
    {
        GLint infoLen = 0;
        glGetProgramiv(programId, 0x8B84, &infoLen);
        if(infoLen > 1)
        {
            GLchar* infoLog = malloc(sizeof(GLchar) * infoLen);
            glGetProgramInfoLog(programId, infoLen, ((void *)0), infoLog);
            printf("Error linking program:%s\n", infoLog);
            free(infoLog);
        }
        glDeleteProgram(programId);
        return;
    }
}

canonical_original_code:
void EsLinkProgram(int programId)
{
    int linked;
    glLinkProgram(programId);
    glGetProgramiv(programId, 0x8B82, &linked);
    if(!linked)
    {
        int infoLen = 0;
        glGetProgramiv(programId, 0x8B84, &infoLen);
        if(infoLen > 1)
        {
            char *infoLog = malloc(sizeof(GLchar) * infoLen);
            glGetProgramInfoLog(programId, infoLen, ((void *)0), infoLog);
            printf("Error linking program:%s\n", infoLog);
            free(infoLog);
        }
        glDeleteProgram(programId);
        return;
    }
}

variable_types: linked int


repo: younix/crypt

original_code:
void
gen_table(char table[26][26], char rtable[26][26])
{
 char *abc = "abcdefghijklmnopqrstuvwxyz";
 for (int y = 0; y < 26; y++) {
  for (int x = 0; x < 26; x++) {
   table[y][x] = abc[x + y < 26 ? x + y: x + y - 26];
   rtable[y][x] = abc[x - y >= 0 ? x - y: x - y + 26];
  }
 }
}

variable_types:
table
char [26][26]

variable_types:
rtable
char [26][26]

variable_types:
abc
char *

variable_types: y int

variable_types: x int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er14
char *i; // rbp
int v5; // eax
char *v6; // rbp
char *v7; // rbx
__int64 v8; // rsi
size_t v10; // rbx
const unsigned __int16 **v11; // rax
__int64 v12; // r15
const __int32_t **v13; // rbx
int v14; // eax
__int64 v15; // rsi
size_t v16; // r13
int v17; // er12
__int16 v18; // ax
const __int32_t **v19; // rbx
int v20; // eax
__int64 v21; // rsi
int v22; // [rsp+Ch] [rbp-59Ch]
char v23[26]; // [rsp+10h] [rbp-598h] BYREF
char v24; // [rsp+2Ah] [rbp-57Eh] BYREF
char v25[14]; // [rsp+2C0h] [rbp-2E8h] BYREF
char v26[730]; // [rsp+2CEh] [rbp-2DAh] BYREF

i = 0LL;
gen_table(v23, v25, envp);
v22 = 0;
while ( 1 )
{
LABEL_2:
v5 = getopt(argc, (char *const *)argv, "dp:th");
if ( v5 == -1 )
{
if ( !i )
LABEL_11:
usage();
printf("pass: %s\n", i);
while ( 1 )
{
v17 = getchar();
if ( v17 == -1 )
return 0;
v16 = v3;
v18 = (*__ctype_b_loc())[v17] & 0x400;
if ( v22 )
{
if ( !v18 )
{
LABEL_27:
putchar(v17);
goto LABEL_21;
}
++v3;
v19 = __ctype_tolower_loc();
v20 = tolower(v17);
v21 = i[v16];
v16 = v3;
putchar(v26[26 * (*v19)[v21] - 2633 + v20]);
}
else
{
if ( !v18 )
goto LABEL_27;
++v3;
v13 = __ctype_tolower_loc();
v14 = tolower(v17);
v15 = i[v16];
v16 = v3;
putchar(v26[26 * (*v13)[v15] - 3321 + v14]);
}
LABEL_21:
if ( v16 > strlen(i) - 1 )
v3 = 0;
}
}
if ( v5 == 112 )
{
v10 = 0LL;
for ( i = strdup(_bss_start); ; i[v10++] = (*__ctype_tolower_loc())[v12] )
{
if ( strlen(i) <= v10 )
goto LABEL_2;
v11 = __ctype_b_loc();
v12 = i[v10];
if ( ((*v11)[v12] & 0x400) == 0 )
break;
}
fwrite("wrong charater in password!\n", 1uLL, 0x1CuLL, stderr);
return 1;
}
if ( v5 == 116 )
break;
v22 = 1;
if ( v5 != 100 )
goto LABEL_11;
}
v6 = &v24;
do
{
v7 = v6 - 26;
do
{
v8 = (unsigned int)*v7++;
printf("%c ", v8);
}
while ( v6 != v7 );
v6 += 26;
putchar(10);
}
while ( v6 != v26 );
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er14
char *i; // rbp
int v5; // eax
char *v6; // rbp
char *v7; // rbx
__int64 v8; // rsi
size_t v10; // rbx
const unsigned __int16 **v11; // rax
__int64 v12; // r15
const __int32_t **v13; // rbx
int v14; // eax
__int64 v15; // rsi
size_t v16; // r13
int v17; // er12
__int16 v18; // ax
const __int32_t **v19; // rbx
int v20; // eax
__int64 v21; // rsi
int v22; // [rsp+Ch] [rbp-59Ch]
char v23[26]; // [rsp+10h] [rbp-598h] BYREF
char v24; // [rsp+2Ah] [rbp-57Eh] BYREF
char v25[14]; // [rsp+2C0h] [rbp-2E8h] BYREF
char v26[730]; // [rsp+2CEh] [rbp-2DAh] BYREF

i = 0LL;
func7(v23, v25, envp);
v22 = 0;
while ( 1 )
{
LABEL_2:
v5 = getopt(argc, (char *const *)argv, "dp:th");
if ( v5 == -1 )
{
if ( !i )
LABEL_11:
func8();
printf("pass: %s\n", i);
while ( 1 )
{
v17 = getchar();
if ( v17 == -1 )
return 0;
v16 = v3;
v18 = (*__ctype_b_loc())[v17] & 0x400;
if ( v22 )
{
if ( !v18 )
{
LABEL_27:
putchar(v17);
goto LABEL_21;
}
++v3;
v19 = __ctype_tolower_loc();
v20 = tolower(v17);
v21 = i[v16];
v16 = v3;
putchar(v26[26 * (*v19)[v21] - 2633 + v20]);
}
else
{
if ( !v18 )
goto LABEL_27;
++v3;
v13 = __ctype_tolower_loc();
v14 = tolower(v17);
v15 = i[v16];
v16 = v3;
putchar(v26[26 * (*v13)[v15] - 3321 + v14]);
}
LABEL_21:
if ( v16 > strlen(i) - 1 )
v3 = 0;
}
}
if ( v5 == 112 )
{
v10 = 0LL;
for ( i = strdup(_bss_start); ; i[v10++] = (*__ctype_tolower_loc())[v12] )
{
if ( strlen(i) <= v10 )
goto LABEL_2;
v11 = __ctype_b_loc();
v12 = i[v10];
if ( ((*v11)[v12] & 0x400) == 0 )
break;
}
fwrite("wrong charater in password!\n", 1uLL, 0x1CuLL, stderr);
return 1;
}
if ( v5 == 116 )
break;
v22 = 1;
if ( v5 != 100 )
goto LABEL_11;
}
v6 = &v24;
do
{
v7 = v6 - 26;
do
{
v8 = (unsigned int)*v7++;
printf("%c ", v8);
}
while ( v6 != v7 );
v6 += 26;
putchar(10);
}
while ( v6 != v26 );
return 0;
}

original_code:
int
main(int argc, char**argv)
{
 int c, p, decode_flag = 0, ch;
 char *password = ((void *)0);
 char table[26][26], rtable[26][26];
 gen_table(table, rtable);
 while ((ch = getopt(argc, argv, "dp:th")) != -1) {
  switch (ch) {
  case 'd':
   decode_flag = 1;
   break;
  case 'p':
   password = strdup(optarg);
   for (int i = 0; i < strlen(password); i++) {
    if (((*__ctype_b_loc ())[(int) ((password[i]))] & (unsigned short int) _ISalpha)) {
     password[i] = tolower(password[i]);
    } else {
     fprintf(stderr,
         "wrong charater in password!\n");
     return 1;
    }
   }
   break;
  case 't':
   for (int y = 0; y < 26; y++) {
    for (int x = 0; x < 26; x++)
     printf("%c ", table[y][x]);
    printf("\n");
   }
   return 0;
  case 'h':
  default:
   usage();
  }
 }
 argc -= optind;
 argv += optind;
 if (password == ((void *)0))
  usage();
 printf("pass: %s\n", password);
 while ((c = getchar()) != (-1)) {
  if (!decode_flag && ((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISalpha)) {
   c = table[tolower(password[p]) - 'a'][tolower(c) - 'a'];
   printf("%c", c);
   p++;
  } else if (decode_flag && ((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISalpha)) {
   c = rtable[tolower(password[p]) - 'a'][tolower(c) -'a'];
   printf("%c", c);
   p++;
  } else {
   putchar(c);
  }
  if (p > strlen(password) - 1)
   p = 0;
 }
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 int c; int p; int decode_flag = 0; int ch;
 char *password = ((void *)0);
 char table[26][26]; char rtable[26][26];
 gen_table(table, rtable);
 while ((ch = getopt(argc, argv, "dp:th")) != -1) {
  switch (ch) {
  case 'd':
   decode_flag = 1;
   break;
  case 'p':
   password = strdup(optarg);
   for (int i = 0; i < strlen(password); i++) {
    if (((*__ctype_b_loc ())[(int) ((password[i]))] & (unsigned short) _ISalpha)) {
     password[i] = tolower(password[i]);
    } else {
     fprintf(stderr,
         "wrong charater in password!\n");
     return 1;
    }
   }
   break;
  case 't':
   for (int y = 0; y < 26; y++) {
    for (int x = 0; x < 26; x++)
     printf("%c ", table[y][x]);
    printf("\n");
   }
   return 0;
  case 'h':
  default:
   usage();
  }
 }
 argc -= optind;
 argv += optind;
 if (password == ((void *)0))
  usage();
 printf("pass: %s\n", password);
 while ((c = getchar()) != (-1)) {
  if (!decode_flag && ((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISalpha)) {
   c = table[tolower(password[p]) - 'a'][tolower(c) - 'a'];
   printf("%c", c);
   p++;
  } else if (decode_flag && ((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISalpha)) {
   c = rtable[tolower(password[p]) - 'a'][tolower(c) -'a'];
   printf("%c", c);
   p++;
  } else {
   putchar(c);
  }
  if (p > strlen(password) - 1)
   p = 0;
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: c int

variable_types: p int

variable_types: ch int

variable_types:
password
char *


usage

decompiled_code:
void __noreturn usage()
{
fwrite(
"usage: polybios [-dh] {-p PASSWORD | -t}\n"
"\n"
"OPTIONS\n"
"\t-d\tdecode\n"
"\t-p\tpassword\n"
"\t-t\tprint lookup table\n"
"\t-h\tshow this help message\n",
1uLL,
0x7CuLL,
stderr);
exit(1);
}

canonical_decompiled_code:
void __noreturn func8()
{
fwrite(
"usage: polybios [-dh] {-p PASSWORD | -t}\n"
"\n"
"OPTIONS\n"
"\t-d\tdecode\n"
"\t-p\tpassword\n"
"\t-t\tprint lookup table\n"
"\t-h\tshow this help message\n",
1uLL,
0x7CuLL,
stderr);
exit(1);
}

original_code:
void
usage(void)
{
 fprintf(stderr, "usage: polybios [-dh] {-p PASSWORD | -t}\n"
   "\n"
   "OPTIONS\n"
   "\t-d\tdecode\n"
   "\t-p\tpassword\n"
   "\t-t\tprint lookup table\n"
   "\t-h\tshow this help message\n");
 exit(1);
}

canonical_original_code:
void usage()
{
 fprintf(stderr, "usage: polybios [-dh] {-p PASSWORD | -t}\n"
   "\n"
   "OPTIONS\n"
   "\t-d\tdecode\n"
   "\t-p\tpassword\n"
   "\t-t\tprint lookup table\n"
   "\t-h\tshow this help message\n");
 exit(1);
}


main

repo: younix/pie

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // r15
int v4; // er14
int v5; // er13
int v6; // eax
int v7; // eax
void *v8; // rsp
double v9; // xmm0_8
const char *v10; // r8
double *v11; // r15
const char **v12; // r14
const char **v13; // r13
int v14; // ebx
int v15; // eax
const char *v16; // xmm4_8
double v17; // xmm8_8
__int64 v18; // r14
double v19; // xmm0_8
const char *v20; // r13
double v21; // xmm3_8
__int64 v22; // rbx
double v23; // xmm2_8
double v24; // xmm1_8
double v25; // xmm4_8
bool v26; // cf
bool v27; // zf
double v28; // xmm5_8
double v29; // xmm10_8
double v31; // [rsp+0h] [rbp-110h] BYREF
double v32; // [rsp+8h] [rbp-108h]
double v33; // [rsp+10h] [rbp-100h]
double v34; // [rsp+18h] [rbp-F8h]
double v35; // [rsp+20h] [rbp-F0h]
double v36; // [rsp+28h] [rbp-E8h]
double v37; // [rsp+30h] [rbp-E0h]
double v38; // [rsp+38h] [rbp-D8h]
double v39; // [rsp+40h] [rbp-D0h]
int fd[2]; // [rsp+48h] [rbp-C8h]
double cosx; // [rsp+50h] [rbp-C0h] BYREF
double sinx[23]; // [rsp+58h] [rbp-B8h] BYREF

v3 = "Picture of a pie chart";
v4 = 400;
v5 = 400;
*(_QWORD *)&sinx[7] = "#a40000";
*(_QWORD *)&sinx[2] = "#ef2929";
*(_QWORD *)&sinx[3] = "#729fcf";
*(_QWORD *)&sinx[4] = "#ad7fa8";
*(_QWORD *)&sinx[5] = "#fcaf3e";
*(_QWORD *)&sinx[6] = "#4e9a06";
*(_QWORD *)&sinx[8] = "#204a87";
*(_QWORD *)&sinx[9] = "#5c3566";
*(_QWORD *)&sinx[10] = "#ce5c00";
*(_QWORD *)&sinx[11] = "#73d216";
*(_QWORD *)&sinx[12] = "#cc0000";
*(_QWORD *)&sinx[13] = "#3465a4";
*(_QWORD *)&sinx[14] = "#75507b";
*(_QWORD *)&sinx[15] = "#f57900";
v39 = COERCE_DOUBLE("Pie chart");
while ( 2 )
{
v6 = getopt(argc, (char *const *)argv, "o:t:d:w:h:");
if ( v6 != -1 )
{
switch ( v6 )
{
case 'd':
v3 = strdup(optarg);
continue;
case 'h':
v4 = strtol(optarg, 0LL, 10);
continue;
case 'o':
v7 = open(optarg, 65, 438LL);
if ( v7 == -1 )
{
perror(optarg);
exit(1);
}
fd[0] = v7;
dup2(v7, 1);
close(fd[0]);
continue;
case 't':
v39 = COERCE_DOUBLE(strdup(optarg));
continue;
case 'w':
v5 = strtol(optarg, 0LL, 10);
continue;
default:
goto LABEL_23;
}
}
break;
}
fd[0] = argc - optind;
if ( argc - optind > 15 )
{
fprintf(stderr, "Too mutch data. Maximum of %d numbers are posibile.\n", 15LL);
exit(1);
}
if ( fd[0] <= 0 )
{
fwrite("no numbers found.\n", 1uLL, 0x12uLL, stderr);
LABEL_23:
usage();
}
v8 = alloca(4LL * fd[0]);
v9 = (double)(v5 / 2);
v34 = v9;
v33 = (double)(v4 / 2);
if ( v5 / 2 >= v4 / 2 )
v9 = (double)(v4 / 2);
v38 = v9 - 10.0;
if ( v9 - 10.0 < 5.0 )
{
fwrite("Your chart is too small to draw.\n", 1uLL, 0x21uLL, stderr);
exit(1);
}
v10 = v3;
*(_QWORD *)&v37 = optind;
v11 = &v31;
printf(
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"
"<svg xmlns:svg=\"http://www.w3.org/2000/svg\"\n"
" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.0\"\n"
" width=\"%d\" height=\"%d\" id=\"svg2\">\n"
"\t<title>%s</title>\n"
"\t<desc>%s</desc>\n",
(unsigned int)v5,
(unsigned int)v4,
*(const char **)&v39,
v10);
v12 = &argv[*(_QWORD *)&v37];
v13 = &(&argv[fd[0] - 1])[*(_QWORD *)&v37 + 1];
v14 = 0;
do
{
v15 = strtol(*v12, 0LL, 10);
*(_DWORD *)v11 = v15;
if ( v15 < 0 )
{
fwrite("negative input number\n", 1uLL, 0x16uLL, stderr);
exit(1);
}
++v12;
v14 += v15;
v11 = (double *)((char *)v11 + 4);
}
while ( v12 != v13 );
*(double *)&v16 = v38;
v17 = 0.0;
v18 = (unsigned int)fd[0];
v19 = (double)v14;
v20 = "#8ae234";
v21 = 0.0;
v22 = 0LL;
v23 = v38;
v32 = v19 / 360.0;
v31 = v19 * 0.5;
while ( 1 )
{
v37 = v23;
v24 = (double)*((int *)&v31 + v22);
v38 = v21;
v39 = *(double *)&v16;
*(double *)fd = v24;
v35 = v17 + v24 / v32;
sincos(0.0174532925199433 * v35, sinx, &cosx);
v25 = v39;
v26 = *(double *)fd < v31;
v27 = *(double *)fd == v31;
v28 = v39;
*(double *)fd = v39;
v29 = sinx[0] * v39;
++v22;
v39 = cosx * v39;
v36 = v29;
printf(
"\t<path d=\"M%f,%f L%f,%f A%f,%f 0 %d,1 %f,%f z\" fill=\"%s\" stroke=\"#FFFFFF\" stroke-width=\"3\" fill-opacity=\""
"1.0\" stroke-linejoin=\"round\" />\n",
v34,
v33,
v37 + v34,
v38 + v33,
v25,
v28,
!v26 && !v27,
v34 + v39,
v33 + v29,
v20);
if ( v18 == v22 )
break;
v20 = *(const char **)&sinx[v22 + 1];
v16 = *(const char **)fd;
v17 = v35;
v21 = v36;
v23 = v39;
}
puts("</svg>");
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // r15
int v4; // er14
int v5; // er13
int v6; // eax
int v7; // eax
void *v8; // rsp
double v9; // xmm0_8
const char *v10; // r8
double *v11; // r15
const char **v12; // r14
const char **v13; // r13
int v14; // ebx
int v15; // eax
const char *v16; // xmm4_8
double v17; // xmm8_8
__int64 v18; // r14
double v19; // xmm0_8
const char *v20; // r13
double v21; // xmm3_8
__int64 v22; // rbx
double v23; // xmm2_8
double v24; // xmm1_8
double v25; // xmm4_8
bool v26; // cf
bool v27; // zf
double v28; // xmm5_8
double v29; // xmm10_8
double v31; // [rsp+0h] [rbp-110h] BYREF
double v32; // [rsp+8h] [rbp-108h]
double v33; // [rsp+10h] [rbp-100h]
double v34; // [rsp+18h] [rbp-F8h]
double v35; // [rsp+20h] [rbp-F0h]
double v36; // [rsp+28h] [rbp-E8h]
double v37; // [rsp+30h] [rbp-E0h]
double v38; // [rsp+38h] [rbp-D8h]
double v39; // [rsp+40h] [rbp-D0h]
int fd[2]; // [rsp+48h] [rbp-C8h]
double cosx; // [rsp+50h] [rbp-C0h] BYREF
double sinx[23]; // [rsp+58h] [rbp-B8h] BYREF

v3 = "Picture of a pie chart";
v4 = 400;
v5 = 400;
*(_QWORD *)&sinx[7] = "#a40000";
*(_QWORD *)&sinx[2] = "#ef2929";
*(_QWORD *)&sinx[3] = "#729fcf";
*(_QWORD *)&sinx[4] = "#ad7fa8";
*(_QWORD *)&sinx[5] = "#fcaf3e";
*(_QWORD *)&sinx[6] = "#4e9a06";
*(_QWORD *)&sinx[8] = "#204a87";
*(_QWORD *)&sinx[9] = "#5c3566";
*(_QWORD *)&sinx[10] = "#ce5c00";
*(_QWORD *)&sinx[11] = "#73d216";
*(_QWORD *)&sinx[12] = "#cc0000";
*(_QWORD *)&sinx[13] = "#3465a4";
*(_QWORD *)&sinx[14] = "#75507b";
*(_QWORD *)&sinx[15] = "#f57900";
v39 = COERCE_DOUBLE("Pie chart");
while ( 2 )
{
v6 = getopt(argc, (char *const *)argv, "o:t:d:w:h:");
if ( v6 != -1 )
{
switch ( v6 )
{
case 'd':
v3 = strdup(optarg);
continue;
case 'h':
v4 = strtol(optarg, 0LL, 10);
continue;
case 'o':
v7 = open(optarg, 65, 438LL);
if ( v7 == -1 )
{
perror(optarg);
exit(1);
}
fd[0] = v7;
dup2(v7, 1);
close(fd[0]);
continue;
case 't':
v39 = COERCE_DOUBLE(strdup(optarg));
continue;
case 'w':
v5 = strtol(optarg, 0LL, 10);
continue;
default:
goto LABEL_23;
}
}
break;
}
fd[0] = argc - optind;
if ( argc - optind > 15 )
{
fprintf(stderr, "Too mutch data. Maximum of %d numbers are posibile.\n", 15LL);
exit(1);
}
if ( fd[0] <= 0 )
{
fwrite("no numbers found.\n", 1uLL, 0x12uLL, stderr);
LABEL_23:
func7();
}
v8 = alloca(4LL * fd[0]);
v9 = (double)(v5 / 2);
v34 = v9;
v33 = (double)(v4 / 2);
if ( v5 / 2 >= v4 / 2 )
v9 = (double)(v4 / 2);
v38 = v9 - 10.0;
if ( v9 - 10.0 < 5.0 )
{
fwrite("Your chart is too small to draw.\n", 1uLL, 0x21uLL, stderr);
exit(1);
}
v10 = v3;
*(_QWORD *)&v37 = optind;
v11 = &v31;
printf(
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"
"<svg xmlns:svg=\"http://www.w3.org/2000/svg\"\n"
" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.0\"\n"
" width=\"%d\" height=\"%d\" id=\"svg2\">\n"
"\t<title>%s</title>\n"
"\t<desc>%s</desc>\n",
(unsigned int)v5,
(unsigned int)v4,
*(const char **)&v39,
v10);
v12 = &argv[*(_QWORD *)&v37];
v13 = &(&argv[fd[0] - 1])[*(_QWORD *)&v37 + 1];
v14 = 0;
do
{
v15 = strtol(*v12, 0LL, 10);
*(_DWORD *)v11 = v15;
if ( v15 < 0 )
{
fwrite("negative input number\n", 1uLL, 0x16uLL, stderr);
exit(1);
}
++v12;
v14 += v15;
v11 = (double *)((char *)v11 + 4);
}
while ( v12 != v13 );
*(double *)&v16 = v38;
v17 = 0.0;
v18 = (unsigned int)fd[0];
v19 = (double)v14;
v20 = "#8ae234";
v21 = 0.0;
v22 = 0LL;
v23 = v38;
v32 = v19 / 360.0;
v31 = v19 * 0.5;
while ( 1 )
{
v37 = v23;
v24 = (double)*((int *)&v31 + v22);
v38 = v21;
v39 = *(double *)&v16;
*(double *)fd = v24;
v35 = v17 + v24 / v32;
sincos(0.0174532925199433 * v35, sinx, &cosx);
v25 = v39;
v26 = *(double *)fd < v31;
v27 = *(double *)fd == v31;
v28 = v39;
*(double *)fd = v39;
v29 = sinx[0] * v39;
++v22;
v39 = cosx * v39;
v36 = v29;
printf(
"\t<path d=\"M%f,%f L%f,%f A%f,%f 0 %d,1 %f,%f z\" fill=\"%s\" stroke=\"#FFFFFF\" stroke-width=\"3\" fill-opacity=\""
"1.0\" stroke-linejoin=\"round\" />\n",
v34,
v33,
v37 + v34,
v38 + v33,
v25,
v28,
!v26 && !v27,
v34 + v39,
v33 + v29,
v20);
if ( v18 == v22 )
break;
v20 = *(const char **)&sinx[v22 + 1];
v16 = *(const char **)fd;
v17 = v35;
v21 = v36;
v23 = v39;
}
puts("</svg>");
return 0;
}

original_code:
int
main(int argc, char **argv)
{
 char *color[] = {"#8ae234", "#ef2929", "#729fcf", "#ad7fa8", "#fcaf3e",
    "#4e9a06", "#a40000", "#204a87", "#5c3566", "#ce5c00",
    "#73d216", "#cc0000", "#3465a4", "#75507b", "#f57900"};
 int max_colors = sizeof(color) / sizeof(color[0]);
 int width = 400;
 int height = 400;
 char *title = "Pie chart";
 char *desc = "Picture of a pie chart";
 int ch, fd;
 while ((ch = getopt(argc, argv, "o:t:d:w:h:")) != -1) {
  switch (ch) {
  case 'o':
   if ((fd = open(optarg, 01|0100, 0400|0200
    |(0400 >> 3)|(0200 >> 3)|((0400 >> 3) >> 3)|((0200 >> 3) >> 3))) == -1) {
    perror(optarg);
    exit(1);
   }
   dup2(fd, 1);
   close(fd);
   break;
  case 't':
   title = strdup(optarg);
   break;
  case 'd':
   desc = strdup(optarg);
   break;
  case 'w':
   width = strtol(optarg, ((void *)0), 10);
   break;
  case 'h':
   height = strtol(optarg, ((void *)0), 10);
   break;
  default:
   usage();
  }
 }
 argc -= optind;
 argv += optind;
 if (argc > max_colors) {
  fprintf(stderr, "Too mutch data. "
   "Maximum of %d numbers are posibile.\n", max_colors);
  exit(1);
 } else if (argc < 1) {
  fprintf(stderr, "no numbers found.\n");
  usage();
 }
 int data[argc];
 double centerx = width / 2;
 double centery = height / 2;
 int laf = 0;
 double radius = ((centerx) < (centery) ? (centerx) : (centery)) - 10;
 if (radius < 5.0) {
  fprintf(stderr, "Your chart is too small to draw.\n");
  exit(1);
 }
 printf( "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"
  "<svg xmlns:svg=\"http://www.w3.org/2000/svg\"\n"
  "    xmlns=\"http://www.w3.org/2000/svg\" version=\"1.0\"\n"
  "    width=\"%d\" height=\"%d\" id=\"svg2\">\n"
  "\t<title>%s</title>\n"
  "\t<desc>%s</desc>\n",
  width, height, title, desc);
 int max = argc;
 int sum = 0;
 for (int i = 0; i < max; i++) {
  data[i] = strtol(argv[i], ((void *)0), 10);
  if (data[i] < 0) {
   fprintf(stderr, "negative input number\n");
   exit(1);
  }
  sum += data[i];
 }
 double deg = sum / 360.0;
 double jung = sum / 2.0;
 double dx = radius;
 double dy = 0.0;
 double oldangle = 0.0;
 for (int i = 0; i < max; i++) {
  double angle = oldangle + data[i] / deg;
  double x = cos(((3.14159265358979323846 / 180.0) * (angle))) * radius;
  double y = sin(((3.14159265358979323846 / 180.0) * (angle))) * radius;
  if (data[i] > jung)
   laf = 1;
  else
   laf = 0;
  double ax = centerx + x;
  double ay = centery + y;
  double adx = centerx + dx;
  double ady = centery + dy;
  printf( "\t<path d=\"M%f,%f"
   " L%f,%f"
   " A%f,%f 0 %d,1 %f,%f"
   " z\""
   " fill=\"%s\" stroke=\"#FFFFFF\" stroke-width=\"3\""
   " fill-opacity=\"1.0\" stroke-linejoin=\"round\" />\n",
   centerx, centery, adx, ady, radius, radius, laf, ax, ay,
   color[i]);
  dx = x; dy = y; oldangle = angle;
 }
 printf("</svg>\n");
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 char *color[] = {"#8ae234", "#ef2929", "#729fcf", "#ad7fa8", "#fcaf3e",
    "#4e9a06", "#a40000", "#204a87", "#5c3566", "#ce5c00",
    "#73d216", "#cc0000", "#3465a4", "#75507b", "#f57900"};
 int max_colors = sizeof(color) / sizeof(color[0]);
 int width = 400;
 int height = 400;
 char *title = "Pie chart";
 char *desc = "Picture of a pie chart";
 int ch; int fd;
 while ((ch = getopt(argc, argv, "o:t:d:w:h:")) != -1) {
  switch (ch) {
  case 'o':
   if ((fd = open(optarg, 01|0100, 0400|0200
    |(0400 >> 3)|(0200 >> 3)|((0400 >> 3) >> 3)|((0200 >> 3) >> 3))) == -1) {
    perror(optarg);
    exit(1);
   }
   dup2(fd, 1);
   close(fd);
   break;
  case 't':
   title = strdup(optarg);
   break;
  case 'd':
   desc = strdup(optarg);
   break;
  case 'w':
   width = strtol(optarg, ((void *)0), 10);
   break;
  case 'h':
   height = strtol(optarg, ((void *)0), 10);
   break;
  default:
   usage();
  }
 }
 argc -= optind;
 argv += optind;
 if (argc > max_colors) {
  fprintf(stderr, "Too mutch data. "
   "Maximum of %d numbers are posibile.\n", max_colors);
  exit(1);
 } else if (argc < 1) {
  fprintf(stderr, "no numbers found.\n");
  usage();
 }
 int data[-1];
 double centerx = width / 2;
 double centery = height / 2;
 int laf = 0;
 double radius = ((centerx) < (centery) ? (centerx) : (centery)) - 10;
 if (radius < 5.0) {
  fprintf(stderr, "Your chart is too small to draw.\n");
  exit(1);
 }
 printf( "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"
  "<svg xmlns:svg=\"http://www.w3.org/2000/svg\"\n"
  "    xmlns=\"http://www.w3.org/2000/svg\" version=\"1.0\"\n"
  "    width=\"%d\" height=\"%d\" id=\"svg2\">\n"
  "\t<title>%s</title>\n"
  "\t<desc>%s</desc>\n",
  width, height, title, desc);
 int max = argc;
 int sum = 0;
 for (int i = 0; i < max; i++) {
  data[i] = strtol(argv[i], ((void *)0), 10);
  if (data[i] < 0) {
   fprintf(stderr, "negative input number\n");
   exit(1);
  }
  sum += data[i];
 }
 double deg = sum / 360.0;
 double jung = sum / 2.0;
 double dx = radius;
 double dy = 0.0;
 double oldangle = 0.0;
 for (int i = 0; i < max; i++) {
  double angle = oldangle + data[i] / deg;
  double x = cos(((3.14159265358979323846 / 180.0) * (angle))) * radius;
  double y = sin(((3.14159265358979323846 / 180.0) * (angle))) * radius;
  if (data[i] > jung)
   laf = 1;
  else
   laf = 0;
  double ax = centerx + x;
  double ay = centery + y;
  double adx = centerx + dx;
  double ady = centery + dy;
  printf( "\t<path d=\"M%f,%f"
   " L%f,%f"
   " A%f,%f 0 %d,1 %f,%f"
   " z\""
   " fill=\"%s\" stroke=\"#FFFFFF\" stroke-width=\"3\""
   " fill-opacity=\"1.0\" stroke-linejoin=\"round\" />\n",
   centerx, centery, adx, ady, radius, radius, laf, ax, ay,
   color[i]);
  dx = x; dy = y; oldangle = angle;
 }
 printf("</svg>\n");
 return 0;
}

variable_types:
color
char *[]

variable_types: width int

variable_types: height int

variable_types:
title
char *

variable_types:
desc
char *

variable_types: fd int

variable_types:
data
int [-1]

variable_types: centerx double

variable_types: centery double

variable_types: laf int

variable_types: radius double

variable_types: max int

variable_types: sum int

variable_types: deg double

variable_types: jung double

variable_types: dx double

variable_types: dy double

variable_types: oldangle double

variable_types: angle double

variable_types: x double

variable_types: y double

variable_types: ax double

variable_types: ay double

variable_types: adx double

variable_types: ady double


usage

decompiled_code:
void __noreturn usage()
{
fwrite(
"pie [OPTIONS] NUM ...\n"
"\n"
"OPTIONS:\n"
"\t-t TITLE\tTitle of the chart.\n"
"\t-d DESCRIPTION\tDescription of the chart.\n"
"\t-o FILE\t\tOutput file for SVG data.\n",
1uLL,
0x8CuLL,
stderr);
exit(1);
}

canonical_decompiled_code:
void __noreturn func7()
{
fwrite(
"pie [OPTIONS] NUM ...\n"
"\n"
"OPTIONS:\n"
"\t-t TITLE\tTitle of the chart.\n"
"\t-d DESCRIPTION\tDescription of the chart.\n"
"\t-o FILE\t\tOutput file for SVG data.\n",
1uLL,
0x8CuLL,
stderr);
exit(1);
}

original_code:
void
usage(void)
{
 fprintf(stderr, "pie [OPTIONS] NUM ...\n"
   "\n"
   "OPTIONS:\n"
   "	-t TITLE	Title of the chart.\n"
   "	-d DESCRIPTION	Description of the chart.\n"
   "	-o FILE		Output file for SVG data.\n");
 exit(1);
}

canonical_original_code:
void usage()
{
 fprintf(stderr, "pie [OPTIONS] NUM ...\n"
   "\n"
   "OPTIONS:\n"
   "	-t TITLE	Title of the chart.\n"
   "	-d DESCRIPTION	Description of the chart.\n"
   "	-o FILE		Output file for SVG data.\n");
 exit(1);
}


isshow

repo: younix/sj

decompiled_code:
__int64 __fastcall isshow(const char *a1)
{
unsigned int v1; // er8
int v2; // edx

v1 = 1;
if ( strcmp(a1, "away") && strcmp(a1, "chat") && strcmp(a1, "dnd") )
{
v2 = *(unsigned __int8 *)a1 - 120;
if ( *a1 == 120 )
{
v2 = *((unsigned __int8 *)a1 + 1) - 97;
if ( a1[1] == 97 )
v2 = *((unsigned __int8 *)a1 + 2);
}
LOBYTE(v1) = v2 == 0;
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func7(const char *a1)
{
unsigned int v1; // er8
int v2; // edx

v1 = 1;
if ( strcmp(a1, "away") && strcmp(a1, "chat") && strcmp(a1, "dnd") )
{
v2 = *(unsigned __int8 *)a1 - 120;
if ( *a1 == 120 )
{
v2 = *((unsigned __int8 *)a1 + 1) - 97;
if ( a1[1] == 97 )
v2 = *((unsigned __int8 *)a1 + 2);
}
LOBYTE(v1) = v2 == 0;
}
return v1;
}

original_code:
_Bool
isshow(const char *show)
{
 if (strcmp(show, "away") == 0) return 1;
 if (strcmp(show, "chat") == 0) return 1;
 if (strcmp(show, "dnd") == 0) return 1;
 if (strcmp(show, "xa") == 0) return 1;
 return 0;
}

canonical_original_code:
_Bool isshow(char *show)
{
 if (strcmp(show, "away") == 0) return 1;
 if (strcmp(show, "chat") == 0) return 1;
 if (strcmp(show, "dnd") == 0) return 1;
 if (strcmp(show, "xa") == 0) return 1;
 return 0;
}

variable_types:
show
char *


istype

decompiled_code:
__int64 __fastcall istype(const char *a1)
{
unsigned int v1; // er8

v1 = 1;
if ( strcmp(a1, "subscribe") && strcmp(a1, "subscribed") && strcmp(a1, "unavailable") && strcmp(a1, "unsubscribe") )
LOBYTE(v1) = strcmp(a1, "unsubscribed") == 0;
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func8(const char *a1)
{
unsigned int v1; // er8

v1 = 1;
if ( strcmp(a1, "subscribe") && strcmp(a1, "subscribed") && strcmp(a1, "unavailable") && strcmp(a1, "unsubscribe") )
LOBYTE(v1) = strcmp(a1, "unsubscribed") == 0;
return v1;
}

original_code:
_Bool
istype(const char *type)
{
 if (strcmp(type, "subscribe") == 0) return 1;
 if (strcmp(type, "subscribed") == 0) return 1;
 if (strcmp(type, "unavailable") == 0) return 1;
 if (strcmp(type, "unsubscribe") == 0) return 1;
 if (strcmp(type, "unsubscribed") == 0) return 1;
 return 0;
}

canonical_original_code:
_Bool istype(char *type)
{
 if (strcmp(type, "subscribe") == 0) return 1;
 if (strcmp(type, "subscribed") == 0) return 1;
 if (strcmp(type, "unavailable") == 0) return 1;
 if (strcmp(type, "unsubscribe") == 0) return 1;
 if (strcmp(type, "unsubscribed") == 0) return 1;
 return 0;
}

variable_types:
type
char *


usage

decompiled_code:
void __noreturn usage()
{
fwrite(
"presence [-d <dir>] [-t <to>] [-s <show>] [-p <prio>] [type]\n"
" prio: -128..127\n"
" show: away|chat|dnd|xa\n"
" type: subscribe|subscribed|unavailable|unsubscribe|unsubscribed\n",
1uLL,
0xAAuLL,
stderr);
exit(1);
}

canonical_decompiled_code:
void __noreturn func9()
{
fwrite(
"presence [-d <dir>] [-t <to>] [-s <show>] [-p <prio>] [type]\n"
" prio: -128..127\n"
" show: away|chat|dnd|xa\n"
" type: subscribe|subscribed|unavailable|unsubscribe|unsubscribed\n",
1uLL,
0xAAuLL,
stderr);
exit(1);
}

original_code:
void
usage(void)
{
 fprintf(stderr,
  "presence [-d <dir>] [-t <to>] [-s <show>] [-p <prio>] [type]\n"
  "  prio: -128..127\n"
  "  show: away|chat|dnd|xa\n"
  "  type: subscribe|subscribed|unavailable|unsubscribe|"
      "unsubscribed\n");
 exit(1);
}

canonical_original_code:
void usage()
{
 fprintf(stderr,
  "presence [-d <dir>] [-t <to>] [-s <show>] [-p <prio>] [type]\n"
  "  prio: -128..127\n"
  "  show: away|chat|dnd|xa\n"
  "  type: subscribe|subscribed|unavailable|unsubscribe|"
      "unsubscribed\n");
 exit(1);
}


repo: younix/xii

decompiled_code:
void __noreturn usage()
{
fwrite("xii [-t <title>] [-e <window>] [-d <dir>] [-o <out>] [-i <in>]\n", 1uLL, 0x3FuLL, stderr);
exit(1);
}

canonical_decompiled_code:
void __noreturn func11()
{
fwrite("xii [-t <title>] [-e <window>] [-d <dir>] [-o <out>] [-i <in>]\n", 1uLL, 0x3FuLL, stderr);
exit(1);
}

original_code:
void
usage(void)
{
 fprintf(stderr,
     "xii [-t <title>] [-e <window>] [-d <dir>] [-o <out>] [-i <in>]\n");
 exit(1);
}

canonical_original_code:
void usage()
{
 fprintf(stderr,
     "xii [-t <title>] [-e <window>] [-d <dir>] [-o <out>] [-i <in>]\n");
 exit(1);
}


readInstruction

decompiled_code:
__int64 __fastcall readInstruction(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, unsigned __int16 a8)
{
__int64 v8; // rax
unsigned int v9; // er8
int v10; // edx
char v11; // cl

v8 = 0LL;
v9 = 0;
do
{
v10 = *(unsigned __int8 *)(a7 + a8 + v8);
v11 = 8 * v8++;
v9 |= v10 << v11;
}
while ( v8 != 4 );
return v9;
}

original_code:
uint32_t readInstruction(state_t st) {
 uint32_t res = 0;
 for (int i = 0; i < 4; i++) {
  res |= st.mem[st.pc + i] << (8 * i);
 }
 return res;
}

canonical_original_code:
unsigned int readInstruction(struct state st) {
 unsigned int res = 0;
 for (int i = 0; i < 4; i++) {
  res |= st.mem[st.pc + i] << (8 * i);
 }
 return res;
}

variable_types: struct state { unsigned char *mem; unsigned short pc; int reg[32]; int halt; }

variable_types:
res
unsigned int

variable_types: i int


getOpcode

decompiled_code:
__int64 __fastcall getOpcode(unsigned int a1)
{
return a1 >> 26;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1)
{
return a1 >> 26;
}

original_code:
uint8_t getOpcode(uint32_t inst) {
 uint32_t mask = 0xFC000000;
 uint32_t res = inst & mask;
 return res >> 26;
}

canonical_original_code:
unsigned char getOpcode(unsigned int inst) {
 unsigned int mask = 0xFC000000;
 unsigned int res = inst & mask;
 return res >> 26;
}

variable_types:
inst
unsigned int

variable_types:
mask
unsigned int

return_type: unsigned char


getAddr

decompiled_code:
__int64 __fastcall getAddr(unsigned int a1)
{
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1)
{
return a1;
}

original_code:
uint16_t getAddr(uint32_t inst) {
 uint32_t mask = 0x03FFFFFF;
 return mask & inst;
}

canonical_original_code:
unsigned short getAddr(unsigned int inst) {
 unsigned int mask = 0x03FFFFFF;
 return mask & inst;
}

return_type: unsigned short


decompiled_code:
__int64 __fastcall getR1(unsigned int a1)
{
return (a1 >> 21) & 0x1F;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1)
{
return (a1 >> 21) & 0x1F;
}

original_code:
uint8_t getR1(uint32_t inst) {
 uint32_t mask = 0x03E00000;
 return (inst & mask) >> 21;
}

canonical_original_code:
unsigned char getR1(unsigned int inst) {
 unsigned int mask = 0x03E00000;
 return (inst & mask) >> 21;
}


decompiled_code:
__int64 __fastcall getR2(unsigned int a1)
{
return HIWORD(a1) & 0x1F;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1)
{
return HIWORD(a1) & 0x1F;
}

original_code:
uint8_t getR2(uint32_t inst) {
 uint32_t mask = 0x001F0000;
 return (inst & mask) >> 16;
}

canonical_original_code:
unsigned char getR2(unsigned int inst) {
 unsigned int mask = 0x001F0000;
 return (inst & mask) >> 16;
}


decompiled_code:
__int64 __fastcall getR3(unsigned __int16 a1)
{
return a1 >> 11;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned __int16 a1)
{
return a1 >> 11;
}

original_code:
uint8_t getR3(uint32_t inst) {
 uint32_t mask = 0x0000F800;
 return (inst & mask) >> 11;
}

canonical_original_code:
unsigned char getR3(unsigned int inst) {
 unsigned int mask = 0x0000F800;
 return (inst & mask) >> 11;
}


getImm

decompiled_code:
// attributes: thunk
__int64 __fastcall getImm(unsigned int a1)
{
return getAddr(a1);
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned int a1)
{
return func2(a1);
}

original_code:
uint16_t getImm(uint32_t inst) {
 uint32_t mask = 0x0000FFFF;
 return (inst & mask);
}

canonical_original_code:
unsigned short getImm(unsigned int inst) {
 unsigned int mask = 0x0000FFFF;
 return (inst & mask);
}


signExtension

decompiled_code:
__int64 __fastcall signExtension(unsigned __int16 a1)
{
__int64 result; // rax

result = a1;
if ( (a1 & 0x8000u) != 0 )
result = a1 | 0xFFFF0000;
return result;
}

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

result = a1;
if ( (a1 & 0x8000u) != 0 )
result = a1 | 0xFFFF0000;
return result;
}

original_code:
int32_t signExtension(uint16_t val) {
 if (0x00008000 & val) {
  return 0xFFFF0000 | val;
 } else {
  return val;
 }
}

canonical_original_code:
int signExtension(unsigned short val) {
 if (0x00008000 & val) {
  return 0xFFFF0000 | val;
 } else {
  return val;
 }
}

variable_types:
val
unsigned short


printReg

decompiled_code:
int __fastcall printReg(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, int a7, __int64 a8)
{
__int64 v8; // rbx
__int64 v9; // rcx
__int64 v10; // rdx
int result; // eax

v8 = 0LL;
fprintf(stderr, "PC: %i\n\n", (unsigned __int16)a8);
do
{
v9 = *((unsigned int *)&a8 + v8 + 1);
v10 = (unsigned int)v8++;
result = fprintf(stderr, "R[%i]: %i\n", v10, v9);
}
while ( v8 != 32 );
return result;
}

canonical_decompiled_code:
int __fastcall func8(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, int a7, __int64 a8)
{
__int64 v8; // rbx
__int64 v9; // rcx
__int64 v10; // rdx
int result; // eax

v8 = 0LL;
fprintf(stderr, "PC: %i\n\n", (unsigned __int16)a8);
do
{
v9 = *((unsigned int *)&a8 + v8 + 1);
v10 = (unsigned int)v8++;
result = fprintf(stderr, "R[%i]: %i\n", v10, v9);
}
while ( v8 != 32 );
return result;
}

original_code:
void printReg(state_t st) {
 fprintf(stderr, "PC: %i\n\n", st.pc);
 for (int i = 0; i < 32; i++) {
  fprintf(stderr, "R[%i]: %i\n", i, st.reg[i]);
 }
}

canonical_original_code:
void printReg(struct state st) {
 fprintf(stderr, "PC: %i\n\n", st.pc);
 for (int i = 0; i < 32; i++) {
  fprintf(stderr, "R[%i]: %i\n", i, st.reg[i]);
 }
}

user_defined_types: struct state { unsigned char *mem; unsigned short pc; int reg[32]; int halt; }


repo: yshui/cgrouper

decompiled_code:
__int64 __fastcall cgroup_is_mounted(char *s1)
{
__int64 i; // r12

for ( i = cgroup_head; i; i = *(_QWORD *)(i + 16) )
{
if ( !strcmp(s1, *(const char **)i) )
break;
}
return i;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *s1)
{
__int64 i; // r12

for ( i = cgroup_head; i; i = *(_QWORD *)(i + 16) )
{
if ( !strcmp(s1, *(const char **)i) )
break;
}
return i;
}

original_code:
static struct cgroup_entry *cgroup_is_mounted(const char *type){
 struct cgroup_entry *entry;
 for ((entry) = ((&cgroup_head)->lh_first); (entry); (entry) = ((entry)->next.le_next))
  if(strcmp(type, entry->type) == 0)
   return entry;
 return ((void *)0);
}

canonical_original_code:
static struct cgroup_entry *cgroup_is_mounted(char *type){
 struct cgroup_entry *entry;
 for ((entry) = ((&cgroup_head)->lh_first); (entry); (entry) = ((entry)->next.le_next))
  if(strcmp(type, entry->type) == 0)
   return entry;
 return ((void *)0);
}

variable_types: struct cgroup_entry { char *type; char *mp; struct { struct cgroup_entry *le_next; struct cgroup_entry **le_prev; } next; } *


decompiled_code:
void __fastcall add_mount(char *s1, char *src)
{
__int64 v2; // rbx
size_t v3; // rax
char *v4; // rax
size_t v5; // rax

v2 = cgroup_head;
if ( cgroup_head )
{
while ( strcmp(s1, *(const char **)v2) )
{
v2 = *(_QWORD *)(v2 + 16);
if ( !v2 )
return;
}
if ( !*(_QWORD *)(v2 + 8) )
{
v3 = strlen(src);
v4 = (char *)malloc(v3 + 1);
*(_QWORD *)(v2 + 8) = v4;
strcpy(v4, src);
v5 = strlen(src);
if ( src[v5 - 1] == 47 )
*(_BYTE *)(*(_QWORD *)(v2 + 8) + v5 - 1) = 0;
}
}
}

canonical_decompiled_code:
void __fastcall func1(char *s1, char *src)
{
__int64 v2; // rbx
size_t v3; // rax
char *v4; // rax
size_t v5; // rax

v2 = cgroup_head;
if ( cgroup_head )
{
while ( strcmp(s1, *(const char **)v2) )
{
v2 = *(_QWORD *)(v2 + 16);
if ( !v2 )
return;
}
if ( !*(_QWORD *)(v2 + 8) )
{
v3 = strlen(src);
v4 = (char *)malloc(v3 + 1);
*(_QWORD *)(v2 + 8) = v4;
strcpy(v4, src);
v5 = strlen(src);
if ( src[v5 - 1] == 47 )
*(_BYTE *)(*(_QWORD *)(v2 + 8) + v5 - 1) = 0;
}
}
}

original_code:
static void add_mount(const char *type, const char *mp){
 struct cgroup_entry *cent;
 for ((cent) = ((&cgroup_head)->lh_first); (cent); (cent) = ((cent)->next.le_next))
  if(strcmp(type, cent->type) == 0){
   if(!cent->mp){
    cent->mp = malloc(strlen(mp)+1);
    strcpy(cent->mp, mp);
    if(mp[strlen(mp)-1] == '/')
     cent->mp[strlen(mp)-1] = 0;
   }
   return;
  }
}

canonical_original_code:
static void add_mount(char *type, char *mp){
 struct cgroup_entry *cent;
 for ((cent) = ((&cgroup_head)->lh_first); (cent); (cent) = ((cent)->next.le_next))
  if(strcmp(type, cent->type) == 0){
   if(!cent->mp){
    cent->mp = malloc(strlen(mp)+1);
    strcpy(cent->mp, mp);
    if(mp[strlen(mp)-1] == '/')
     cent->mp[strlen(mp)-1] = 0;
   }
   return;
  }
}

variable_types:
mp
char *

user_defined_types: struct cgroup_entry { char *type; char *mp; struct { struct cgroup_entry *le_next; struct cgroup_entry **le_prev; } next; }


decompiled_code:
__int64 __fastcall option_contain_cgroup_type(char *src)
{
size_t v2; // rax
char *v3; // rax
__int64 v4; // r12
char *v5; // rbp
char *v6; // rdi
__int64 result; // rax

v2 = strlen(src);
v3 = (char *)malloc(v2 + 1);
v4 = cgroup_head;
v5 = v3;
if ( cgroup_head )
{
while ( 1 )
{
strcpy(v5, src);
v6 = strtok(v5, ",");
if ( v6 )
break;
LABEL_7:
v4 = *(_QWORD *)(v4 + 16);
if ( !v4 )
goto LABEL_8;
}
while ( strcmp(v6, *(const char **)v4) )
{
v6 = strtok(0LL, ",");
if ( !v6 )
goto LABEL_7;
}
free(v5);
result = v4;
}
else
{
LABEL_8:
free(v5);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *src)
{
size_t v2; // rax
char *v3; // rax
__int64 v4; // r12
char *v5; // rbp
char *v6; // rdi
__int64 result; // rax

v2 = strlen(src);
v3 = (char *)malloc(v2 + 1);
v4 = cgroup_head;
v5 = v3;
if ( cgroup_head )
{
while ( 1 )
{
strcpy(v5, src);
v6 = strtok(v5, ",");
if ( v6 )
break;
LABEL_7:
v4 = *(_QWORD *)(v4 + 16);
if ( !v4 )
goto LABEL_8;
}
while ( strcmp(v6, *(const char **)v4) )
{
v6 = strtok(0LL, ",");
if ( !v6 )
goto LABEL_7;
}
free(v5);
result = v4;
}
else
{
LABEL_8:
free(v5);
result = 0LL;
}
return result;
}

original_code:
static struct cgroup_entry *option_contain_cgroup_type(const char *opts){
 struct cgroup_entry *cent;
 char *tmp_opts = malloc(strlen(opts)+1);
 for ((cent) = ((&cgroup_head)->lh_first); (cent); (cent) = ((cent)->next.le_next)){
  strcpy(tmp_opts, opts);
  char *opt = strtok(tmp_opts, ",");
  while(opt){
   if(strcmp(opt, cent->type) == 0){
    free(tmp_opts);
    return cent;
   }
   opt = strtok(((void *)0), ",");
  }
 }
 free(tmp_opts);
 return ((void *)0);
}

canonical_original_code:
static struct cgroup_entry *option_contain_cgroup_type(char *opts){
 struct cgroup_entry *cent;
 char *tmp_opts = malloc(strlen(opts)+1);
 for ((cent) = ((&cgroup_head)->lh_first); (cent); (cent) = ((cent)->next.le_next)){
  strcpy(tmp_opts, opts);
  char *opt = strtok(tmp_opts, ",");
  while(opt){
   if(strcmp(opt, cent->type) == 0){
    free(tmp_opts);
    return cent;
   }
   opt = strtok(((void *)0), ",");
  }
 }
 free(tmp_opts);
 return ((void *)0);
}

variable_types:
opts
char *

variable_types:
opt
char *

return_type: struct cgroup_entry { char *type; char *mp; struct { struct cgroup_entry *le_next; struct cgroup_entry **le_prev; } next; } *


decompiled_code:
char *__fastcall cgroup_mount(char *s1)
{
__int64 v1; // rax
__int64 v2; // r12
char *v4; // r12
char *v5; // rdi

v1 = cgroup_is_mounted(s1);
if ( v1 )
return *(char **)(v1 + 8);
v4 = (char *)malloc(0x1000uLL);
if ( snprintf(v4, 0x1000uLL, "/sys/fs/cgroup/%s", s1) > 4095 )
{
v2 = 0LL;
puts("cgroup name too long");
return (char *)v2;
}
if ( mount("cgroup", v4, "cgroup", 0x20000EuLL, s1) == -1 )
{
v5 = v4;
v2 = 0LL;
free(v5);
return (char *)v2;
}
add_mount(s1, v4);
return v4;
}

canonical_decompiled_code:
char *__fastcall func4(char *s1)
{
__int64 v1; // rax
__int64 v2; // r12
char *v4; // r12
char *v5; // rdi

v1 = func0(s1);
if ( v1 )
return *(char **)(v1 + 8);
v4 = (char *)malloc(0x1000uLL);
if ( snprintf(v4, 0x1000uLL, "/sys/fs/cgroup/%s", s1) > 4095 )
{
v2 = 0LL;
puts("cgroup name too long");
return (char *)v2;
}
if ( mount("cgroup", v4, "cgroup", 0x20000EuLL, s1) == -1 )
{
v5 = v4;
v2 = 0LL;
free(v5);
return (char *)v2;
}
func1(s1, v4);
return v4;
}

original_code:
const char *cgroup_mount(const char *type){
 struct cgroup_entry *entry;
 if((entry = cgroup_is_mounted(type)))
  return entry->mp;
 char *target = malloc(4096);
 int len = snprintf(target, 4096, "/sys/fs/cgroup/%s", type);
 if(len >= 4096){
  printf("cgroup name too long\n");
  return ((void *)0);
 }
 int ret = mount("cgroup", target, "cgroup", MS_NODEV|MS_NOEXEC|MS_NOSUID|MS_RELATIME, type);
 if(ret == -1){
  free(target);
  return ((void *)0);
 }
 add_mount(type, target);
 return target;
}

canonical_original_code:
char *cgroup_mount(char *type){
 struct cgroup_entry *entry;
 if((entry = cgroup_is_mounted(type)))
  return entry->mp;
 char *target = malloc(4096);
 int len = snprintf(target, 4096, "/sys/fs/cgroup/%s", type);
 if(len >= 4096){
  printf("cgroup name too long\n");
  return ((void *)0);
 }
 int ret = mount("cgroup", target, "cgroup", MS_NODEV|MS_NOEXEC|MS_NOSUID|MS_RELATIME, type);
 if(ret == -1){
  free(target);
  return ((void *)0);
 }
 add_mount(type, target);
 return target;
}

variable_types:
target
char *

variable_types: len int

variable_types: ret int


decompiled_code:
void __fastcall cgroup_put(void **a1)
{
free(*a1);
}

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

original_code:
void cgroup_put(struct cgroup *cgr){
 free(cgr->full_path);
}

variable_types:
cgr
struct cgroup { char *full_path; } *


decompiled_code:
__int64 cgroup_init()
{
return cgroup_get_mount();
}

canonical_decompiled_code:
__int64 func7()
{
return func3();
}

original_code:
int cgroup_init(){
 return cgroup_get_mount();
}


decompiled_code:
__int64 nl_connect()
{
unsigned int v0; // er12
int v2; // edi
struct sockaddr addr; // [rsp+4h] [rbp-14h] BYREF

v0 = socket(16, 2050, 11);
if ( v0 == -1 )
{
perror("socket");
}
else
{
*(_DWORD *)&addr.sa_data[6] = 1;
addr.sa_family = 16;
*(_DWORD *)&addr.sa_data[2] = getpid();
if ( bind(v0, &addr, 0xCu) == -1 )
{
perror("bind");
v2 = v0;
v0 = -1;
close(v2);
}
}
return v0;
}

canonical_decompiled_code:
__int64 func1()
{
unsigned int v0; // er12
int v2; // edi
struct sockaddr addr; // [rsp+4h] [rbp-14h] BYREF

v0 = socket(16, 2050, 11);
if ( v0 == -1 )
{
perror("socket");
}
else
{
*(_DWORD *)&addr.sa_data[6] = 1;
addr.sa_family = 16;
*(_DWORD *)&addr.sa_data[2] = getpid();
if ( bind(v0, &addr, 0xCu) == -1 )
{
perror("bind");
v2 = v0;
v0 = -1;
close(v2);
}
}
return v0;
}

original_code:
static int nl_connect()
{
 int rc;
 int nl_sock;
 struct sockaddr_nl sa_nl;
 nl_sock = socket(16, SOCK_DGRAM|SOCK_NONBLOCK, 11);
 if (nl_sock == -1) {
  perror("socket");
  return -1;
 }
 sa_nl.nl_family = 16;
 sa_nl.nl_groups = 0x1;
 sa_nl.nl_pid = getpid();
 rc = bind(nl_sock, (struct sockaddr *)&sa_nl, sizeof(sa_nl));
 if (rc == -1) {
  perror("bind");
  close(nl_sock);
  return -1;
 }
 return nl_sock;
}

variable_types: rc int

variable_types: struct sockaddr_nl { unsigned short nl_family; unsigned short nl_pad; unsigned int nl_pid; unsigned int nl_groups; }

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


zmalloc

decompiled_code:
void *__fastcall zmalloc(size_t a1)
{
return calloc(a1, 1uLL);
}

canonical_decompiled_code:
void *__fastcall func0(size_t a1)
{
return calloc(a1, 1uLL);
}

original_code:
void *zmalloc(size_t size){
 void *tmp = malloc(size);
 memset(tmp, 0, size);
 return tmp;
}

canonical_original_code:
void *zmalloc(unsigned long size){
 void *tmp = malloc(size);
 memset(tmp, 0, size);
 return tmp;
}

variable_types:
size
unsigned long

variable_types:
tmp
void *


repo: ystk/fs-test

decompiled_code:
void __fastcall __noreturn net_thread(void *a1)
{
FILE *v1; // rdi
int v2; // edx
int v3; // ebp
struct sockaddr v4; // [rsp+0h] [rbp-18h] BYREF

v1 = stderr;
fprintf(stderr, "Starting NET thread: %d\n", 94LL);
*(_DWORD *)&v4.sa_data[10] = 0;
*(_WORD *)v4.sa_data = _bswap_16_constprop_0(v1, 2LL, 0LL);
v4.sa_family = 2;
*(_QWORD *)&v4.sa_data[2] = (unsigned int)_bswap_32_constprop_0(2LL);
v3 = socket(2, 2, v2);
bind(v3, &v4, 0x10u);
net_recv_write(v3);
}

canonical_decompiled_code:
void __fastcall __noreturn func10(void *a1)
{
FILE *v1; // rdi
int v2; // edx
int v3; // ebp
struct sockaddr v4; // [rsp+0h] [rbp-18h] BYREF

v1 = stderr;
fprintf(stderr, "Starting NET thread: %d\n", 94LL);
*(_DWORD *)&v4.sa_data[10] = 0;
*(_WORD *)v4.sa_data = func8(v1, 2LL, 0LL);
v4.sa_family = 2;
*(_QWORD *)&v4.sa_data[2] = (unsigned int)func7(2LL);
v3 = socket(2, 2, v2);
bind(v3, &v4, 0x10u);
func9(v3);
}

original_code:
void *net_thread(void *net_args)
{
        int recv_soc;
        int recv_port = 13579;
        int stat;
        struct sockaddr_in recv_socaddr;
        fprintf(stderr,"Starting NET thread: %d\n", 94);
        memset(&recv_socaddr, 0, sizeof(struct sockaddr_in));
        recv_socaddr.sin_port = htons(recv_port);
        recv_socaddr.sin_family = 2;
        recv_socaddr.sin_addr.s_addr = htonl(((in_addr_t) 0x00000000));
        recv_soc = socket(2, SOCK_DGRAM, 0);
        stat = bind(recv_soc, (struct sockaddr_in *) &recv_socaddr,
                        sizeof(struct sockaddr_in));
        net_recv_write(recv_soc, &recv_socaddr);
        return 0;
}

canonical_original_code:
void *net_thread(void *net_args)
{
        int recv_soc;
        int recv_port = 13579;
        int stat;
        struct sockaddr_in recv_socaddr;
        fprintf(stderr,"Starting NET thread: %d\n", 94);
        memset(&recv_socaddr, 0, sizeof(struct sockaddr_in));
        recv_socaddr.sin_port = htons(recv_port);
        recv_socaddr.sin_family = 2;
        recv_socaddr.sin_addr.s_addr = htonl(((unsigned int) 0x00000000));
        recv_soc = socket(2, SOCK_DGRAM, 0);
        stat = bind(recv_soc, (struct sockaddr_in *) &recv_socaddr,
                        sizeof(struct sockaddr_in));
        net_recv_write(recv_soc, &recv_socaddr);
        return 0;
}

variable_types: stat int

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; }

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }


decompiled_code:
int __fastcall net_recv(int fd)
{
__int64 v1; // r14
char *v2; // rbp
char *v3; // rbx
__int64 v4; // r13
const char *v5; // rdx
int result; // eax

v1 = 0LL;
v2 = (char *)&unk_604140;
do
{
if ( w_progress == (_DWORD)v1 )
fprintf(stderr, "Buffer overflow: %d\n", 121LL);
v3 = v2 - 0x200000;
v4 = 40 * v1;
pthread_mutex_lock((pthread_mutex_t *)(40 * v1 + log_mutex));
net_ready = 1;
do
{
if ( recvfrom(fd, v3, 0x400uLL, 0, 0LL, 0LL) == -1 )
{
perror("recv");
close(fd);
exit(1);
}
v5 = v3;
v3 += 1024;
fprintf(stderr, "RECV: %s", v5);
}
while ( v3 != v2 );
++v1;
v2 = v3 + 0x200000;
result = pthread_mutex_unlock((pthread_mutex_t *)(v4 + log_mutex));
}
while ( v1 != 3 );
if ( w_progress == -1 )
{
fwrite("File I/O too slow\n", 1uLL, 0x12uLL, stderr);
exit(1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func11(int fd)
{
__int64 v1; // r14
char *v2; // rbp
char *v3; // rbx
__int64 v4; // r13
const char *v5; // rdx
int result; // eax

v1 = 0LL;
v2 = (char *)&unk_604140;
do
{
if ( w_progress == (_DWORD)v1 )
fprintf(stderr, "Buffer overflow: %d\n", 121LL);
v3 = v2 - 0x200000;
v4 = 40 * v1;
pthread_mutex_lock((pthread_mutex_t *)(40 * v1 + log_mutex));
net_ready = 1;
do
{
if ( recvfrom(fd, v3, 0x400uLL, 0, 0LL, 0LL) == -1 )
{
perror("recv");
close(fd);
exit(1);
}
v5 = v3;
v3 += 1024;
fprintf(stderr, "RECV: %s", v5);
}
while ( v3 != v2 );
++v1;
v2 = v3 + 0x200000;
result = pthread_mutex_unlock((pthread_mutex_t *)(v4 + log_mutex));
}
while ( v1 != 3 );
if ( w_progress == -1 )
{
fwrite("File I/O too slow\n", 1uLL, 0x12uLL, stderr);
exit(1);
}
return result;
}

original_code:
void net_recv(int soc, struct sockaddr_in *sockaddr, struct net_arg_struct *na)
{
        int i, j;
        ssize_t num_recv;
        char *rbufp;
        for (i = 0; i< 3; i++){
                if (w_progress == i){
                        fprintf(stderr,"Buffer overflow: %d\n", 121);
                }
                pthread_mutex_lock(&log_mutex[i]);
                net_ready = 1;
                for(j = 0; j<2048; j++){
                        rbufp = rbuf[i][j];
                        num_recv = recvfrom(soc, rbufp, 1024, 0, ((void *)0), ((void *)0));
                        if(num_recv == -1) {
                                perror("recv");
                                close(soc);
                                exit(1);
                        }
                        fprintf(stderr,"RECV: %s", rbufp);
                }
                pthread_mutex_unlock(&log_mutex[i]);
        }
        if (w_progress == -1){
                fprintf(stderr,"File I/O too slow\n");
                exit(1);
        }
}

canonical_original_code:
void net_recv(int soc, struct sockaddr_in *sockaddr, struct net_arg_struct *na)
{
        int i; int j;
        long num_recv;
        char *rbufp;
        for (i = 0; i< 3; i++){
                if (w_progress == i){
                        fprintf(stderr,"Buffer overflow: %d\n", 121);
                }
                pthread_mutex_lock(&log_mutex[i]);
                net_ready = 1;
                for(j = 0; j<2048; j++){
                        rbufp = rbuf[i][j];
                        num_recv = recvfrom(soc, rbufp, 1024, 0, ((void *)0), ((void *)0));
                        if(num_recv == -1) {
                                perror("recv");
                                close(soc);
                                exit(1);
                        }
                        fprintf(stderr,"RECV: %s", rbufp);
                }
                pthread_mutex_unlock(&log_mutex[i]);
        }
        if (w_progress == -1){
                fprintf(stderr,"File I/O too slow\n");
                exit(1);
        }
}

variable_types: soc int

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } *

variable_types: i int

variable_types: j int

variable_types:
rbufp
char *


decompiled_code:
void __noreturn fio_thread()
{
FILE *v0; // rax
FILE *v1; // r12
const char *v2; // rbp
__int64 i; // r14
const char *v4; // rbx
__int64 v5; // r13
const char *v6; // rdi

fprintf(stderr, "Starting LOG thread: %d\n", 153LL);
v0 = fopen("./log/log.txt", "w");
if ( net_ready != 1 )
{
while ( 1 )
sched_yield();
}
v1 = v0;
fprintf(stderr, "Starting logging: %d\n", 164LL);
while ( 1 )
{
v2 = (const char *)&unk_604140;
for ( i = 0LL; i != 3; ++i )
{
v4 = v2 - 0x200000;
v5 = 40 * i;
pthread_mutex_lock((pthread_mutex_t *)(40 * i + log_mutex));
w_progress = i;
do
{
v6 = v4;
v4 += 1024;
fputs(v6, v1);
}
while ( v4 != v2 );
v2 += 0x200000;
pthread_mutex_unlock((pthread_mutex_t *)(v5 + log_mutex));
}
}
}

canonical_decompiled_code:
void __noreturn func12()
{
FILE *v0; // rax
FILE *v1; // r12
const char *v2; // rbp
__int64 i; // r14
const char *v4; // rbx
__int64 v5; // r13
const char *v6; // rdi

fprintf(stderr, "Starting LOG thread: %d\n", 153LL);
v0 = fopen("./log/log.txt", "w");
if ( net_ready != 1 )
{
while ( 1 )
sched_yield();
}
v1 = v0;
fprintf(stderr, "Starting logging: %d\n", 164LL);
while ( 1 )
{
v2 = (const char *)&unk_604140;
for ( i = 0LL; i != 3; ++i )
{
v4 = v2 - 0x200000;
v5 = 40 * i;
pthread_mutex_lock((pthread_mutex_t *)(40 * i + log_mutex));
w_progress = i;
do
{
v6 = v4;
v4 += 1024;
fputs(v6, v1);
}
while ( v4 != v2 );
v2 += 0x200000;
pthread_mutex_unlock((pthread_mutex_t *)(v5 + log_mutex));
}
}
}

original_code:
void *fio_thread(void *fio_args)
{
        struct f_thr_args *fa = (struct f_thr_args *)fio_args;
        fio_main(fa);
        return ((void *)0);
}

variable_types: struct f_thr_args { int id; int id_max; int type; int count; long fsize; long wsize; int gran; long fnum; char *path; char *serv_ip; int port; int socket; struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } *serv_addr; } *

user_defined_types: struct f_thr_args { int id; int id_max; int type; int count; long fsize; long wsize; int gran; long fnum; char *path; char *serv_ip; int port; int socket; struct sockaddr_in *serv_addr; }


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
pthread_mutex_t *v3; // rbx
char v4; // [rsp+7h] [rbp-11h] BYREF
pthread_t newthread[2]; // [rsp+8h] [rbp-10h] BYREF

v3 = (pthread_mutex_t *)malloc(0x78uLL);
log_mutex = (__int64)v3;
pthread_mutex_init(v3, 0LL);
pthread_mutex_init(v3 + 1, 0LL);
pthread_mutex_init(v3 + 2, 0LL);
if ( pthread_create(newthread, 0LL, net_thread, &net_args) )
exit(1);
while ( 1 )
{
printf("COMMAND(q): ");
scanf("%c", &v4);
if ( v4 == 113 )
break;
fflush(0LL);
}
fflush(0LL);
exit(0);
}

original_code:
int main()
{
        int i;
        char com;
        pthread_t netthr;
        log_mutex = (pthread_mutex_t *)malloc(sizeof(pthread_mutex_t) * 3);
        for(i=0; i<3; i++){
                pthread_mutex_init(&log_mutex[i], ((void *)0));
        }
        if(pthread_create(&netthr, ((void *)0), net_thread, &net_args)){
                exit(1);
        }
        while(1){
                printf("COMMAND(q): ");
                scanf("%c", &com);
                if (com == 'q'){
                        fflush(((void *)0));
                        exit(0);
                }else{
                        fflush(((void *)0));
                }
        }
        pthread_join(netthr, ((void *)0));
}

canonical_original_code:
int main()
{
        int i;
        char com;
        unsigned long netthr;
        log_mutex = (union pthread_mutex_t *)malloc(sizeof(pthread_mutex_t) * 3);
        for(i=0; i<3; i++){
                pthread_mutex_init(&log_mutex[i], ((void *)0));
        }
        if(pthread_create(&netthr, ((void *)0), net_thread, &net_args)){
                exit(1);
        }
        while(1){
                printf("COMMAND(q): ");
                scanf("%c", &com);
                if (com == 'q'){
                        fflush(((void *)0));
                        exit(0);
                }else{
                        fflush(((void *)0));
                }
        }
        pthread_join(netthr, ((void *)0));
}

variable_types: com char

variable_types:
netthr
unsigned long

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }

user_defined_types: struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; }


decompiled_code:
int __fastcall bar_init(unsigned int count)
{
fprintf(stderr, "BAR_INIT(%d) ", count);
return pthread_barrier_init(&barrier, 0LL, count);
}

canonical_decompiled_code:
int __fastcall func0(unsigned int count)
{
fprintf(stderr, "BAR_INIT(%d) ", count);
return pthread_barrier_init(&barrier, 0LL, count);
}

original_code:
void bar_init(int num)
{
  fprintf(stderr, "BAR_INIT(%d) ", num);
  pthread_barrier_init(&barrier, ((void *)0), num);
}

variable_types: num int


decompiled_code:
int bar_wait()
{
return pthread_barrier_wait(&barrier);
}

canonical_decompiled_code:
int func1()
{
return pthread_barrier_wait(&barrier);
}

original_code:
void bar_wait(int id)
{
  pthread_barrier_wait(&barrier);
}

variable_types: id int


nrerror

decompiled_code:
void __fastcall __noreturn nrerror(char *s)
{
puts("Numerical Recipes run-time error...");
puts(s);
puts("...now exiting to system...");
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(char *s)
{
puts("Numerical Recipes run-time error...");
puts(s);
puts("...now exiting to system...");
exit(1);
}

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


vector

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

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

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

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

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

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

variable_types: nl long

variable_types: nh long

variable_types:
v
float *

return_type: float *


matrix

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

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

variable_types: nrl long

variable_types: nrh long

variable_types: ncl long

variable_types: nch long

variable_types: i long

variable_types: nrow long

variable_types: ncol long

variable_types:
m
float **

return_type: float **


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

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

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


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


loganREF

original_code:
float loganREF(float *REF, float *ROI, float k2, float *t, float *frd, int nframes, int stframe, int endframe, float *intercept, float *slope, float *Rsq)
{
float BP, r, *x, *y, *intgREF, *intgROI, *tmpx, *tmpy, mx, Sxx, Sx, k, Syy, Sy, my, xt, yt, Sxy,delta, sxx, syy, sxy;
int i;
intgREF=vector(0, nframes-1);
intgROI=vector(0, nframes-1);
tmpx=vector(0, nframes-1);
tmpy=vector(0, nframes-1);
x=vector(0, nframes-1);
y=vector(0, nframes-1);
tmpx[0]=REF[0]*t[0]/2./60.;
tmpy[0]=ROI[0]*t[0]/2./60.;
intgREF[0]=tmpx[0];
intgROI[0]=tmpy[0];
x[0]=(intgREF[0]+REF[0]/k2)/(ROI[0]+1.0e-2);
y[0]=intgROI[0]/(ROI[0]+1.0e-2);
for (i=1; i<nframes; i++)
 {
 intgREF[i]=intgREF[i-1]+(REF[i-1]+REF[i])*(t[i]-t[i-1])/2./60.;
 intgROI[i]=intgROI[i-1]+(ROI[i-1]+ROI[i])*(t[i]-t[i-1])/2./60.;
 x[i]=(intgREF[i]+REF[i]/k2)/(ROI[i]+1.0e-2);
 y[i]=intgROI[i]/(ROI[i]+1.0e-2);
 }
k=(float)(endframe-stframe+1);
mx=0.;
Sxx=0.;
my=0.;
Syy=0.;
Sxy=0.;
for (i=stframe-1; i<endframe; i++)
 {
 mx += x[i];
 Sxx += x[i]*x[i];
 my += y[i];
 Syy += y[i]*y[i];
 Sxy += x[i]*y[i];
 }
Sx = mx;
mx /= k;
sxx = Sxx - k*mx*mx;
delta = k*Sxx -Sx*Sx;
Sy = my;
my /= k;
syy = Syy - k*my*my;
sxy=0;
for (i=stframe-1; i<endframe; i++)
 {
 xt = x[i] - mx;
 yt = y[i] - my;
 sxy += xt*yt;
 }
if (sxx*syy>0) {
 r=sxy/sqrtf(sxx*syy);
 } else {
 r=0;
 }
*intercept=(Sxx*Sy-Sx*Sxy)/delta;
*slope=(k*Sxy-Sx*Sy)/delta;
*Rsq=r*r;
BP=*slope-1.;
return(BP);
}

canonical_original_code:
float loganREF(float *REF, float *ROI, float k2, float *t, float *frd, int nframes, int stframe, int endframe, float *intercept, float *slope, float *Rsq)
{
float BP; float r; float *x; float *y; float *intgREF; float *intgROI; float *tmpx; float *tmpy; float mx; float Sxx; float Sx; float k; float Syy; float Sy; float my; float xt; float yt; float Sxy; float delta; float sxx; float syy; float sxy;
int i;
intgREF=vector(0, nframes-1);
intgROI=vector(0, nframes-1);
tmpx=vector(0, nframes-1);
tmpy=vector(0, nframes-1);
x=vector(0, nframes-1);
y=vector(0, nframes-1);
tmpx[0]=REF[0]*t[0]/2./60.;
tmpy[0]=ROI[0]*t[0]/2./60.;
intgREF[0]=tmpx[0];
intgROI[0]=tmpy[0];
x[0]=(intgREF[0]+REF[0]/k2)/(ROI[0]+1.0e-2);
y[0]=intgROI[0]/(ROI[0]+1.0e-2);
for (i=1; i<nframes; i++)
 {
 intgREF[i]=intgREF[i-1]+(REF[i-1]+REF[i])*(t[i]-t[i-1])/2./60.;
 intgROI[i]=intgROI[i-1]+(ROI[i-1]+ROI[i])*(t[i]-t[i-1])/2./60.;
 x[i]=(intgREF[i]+REF[i]/k2)/(ROI[i]+1.0e-2);
 y[i]=intgROI[i]/(ROI[i]+1.0e-2);
 }
k=(float)(endframe-stframe+1);
mx=0.;
Sxx=0.;
my=0.;
Syy=0.;
Sxy=0.;
for (i=stframe-1; i<endframe; i++)
 {
 mx += x[i];
 Sxx += x[i]*x[i];
 my += y[i];
 Syy += y[i]*y[i];
 Sxy += x[i]*y[i];
 }
Sx = mx;
mx /= k;
sxx = Sxx - k*mx*mx;
delta = k*Sxx -Sx*Sx;
Sy = my;
my /= k;
syy = Syy - k*my*my;
sxy=0;
for (i=stframe-1; i<endframe; i++)
 {
 xt = x[i] - mx;
 yt = y[i] - my;
 sxy += xt*yt;
 }
if (sxx*syy>0) {
 r=sxy/sqrtf(sxx*syy);
 } else {
 r=0;
 }
*intercept=(Sxx*Sy-Sx*Sxy)/delta;
*slope=(k*Sxy-Sx*Sy)/delta;
*Rsq=r*r;
BP=*slope-1.;
return(BP);
}

variable_types:
REF
float *

variable_types:
ROI
float *

variable_types:
t
float *

variable_types:
frd
float *

variable_types: nframes int

variable_types: stframe int

variable_types: endframe int

variable_types:
intercept
float *

variable_types:
slope
float *

variable_types:
Rsq
float *

variable_types: BP float

variable_types: r float

variable_types:
x
float *

variable_types:
y
float *

variable_types:
intgREF
float *

variable_types:
intgROI
float *

variable_types:
tmpx
float *

variable_types:
tmpy
float *

variable_types: mx float

variable_types: Sxx float

variable_types: Sx float

variable_types: k float

variable_types: Syy float

variable_types: Sy float

variable_types: my float

variable_types: xt float

variable_types: yt float

variable_types: Sxy float

variable_types: delta float

variable_types: sxx float

variable_types: syy float

variable_types: sxy float

variable_types: i int

return_type: float


decompiled_code:
int Getifh_rcs()
{
return puts(rcsid);
}

canonical_decompiled_code:
int func0()
{
return puts(rcsid);
}

original_code: void Getifh_rcs (void) {printf ("%s\n", rcsid);}

canonical_original_code: void Getifh_rcs() {printf ("%s\n", rcsid);}


decompiled_code:
void __fastcall gauss3d(__int64 a1, int *a2, int *a3, int *a4, float *a5, float *a6)
{
int v6; // eax
int v7; // ebx
int v8; // esi
size_t v10; // rbp
float *v11; // r12
float *v12; // rbp
int v13; // er10
int *v14; // r12
int v15; // ebx
unsigned int v16; // eax
__int64 v17; // r15
int *v18; // rsi
int v19; // eax
int v20; // er12
int *v21; // r14
__int64 v22; // rcx
unsigned __int64 v23; // rdx
__int64 v24; // r13
float *v25; // rsi
char *v26; // r13
int *v27; // rbx
int v28; // esi
int v29; // eax
int v30; // ecx
int v31; // edx
float v32; // xmm0_4
int v33; // edx
double v34; // xmm0_8
int v35; // ebx
__int64 v36; // r15
int v37; // ecx
double v38; // xmm0_8
double v39; // xmm2_8
unsigned int v40; // er14
int v41; // eax
__int64 v42; // r13
int *v43; // r14
int v44; // ebx
__int64 v45; // r13
int v46; // eax
int *v47; // r12
int i; // er14
__int64 v49; // rdi
__int64 v50; // rcx
unsigned __int64 v51; // rdx
double v52; // [rsp+0h] [rbp-A8h]
int v53; // [rsp+0h] [rbp-A8h]
int v54; // [rsp+8h] [rbp-A0h]
float *v55; // [rsp+8h] [rbp-A0h]
float *ptr; // [rsp+10h] [rbp-98h]
double v57; // [rsp+18h] [rbp-90h]
int v58; // [rsp+18h] [rbp-90h]
int v59; // [rsp+24h] [rbp-84h]
int v60; // [rsp+28h] [rbp-80h]
int v61; // [rsp+28h] [rbp-80h]
int v62; // [rsp+2Ch] [rbp-7Ch]
int v64; // [rsp+38h] [rbp-70h]
double v65; // [rsp+38h] [rbp-70h]
int v67; // [rsp+40h] [rbp-68h]
float *v68; // [rsp+48h] [rbp-60h]
int *v69; // [rsp+48h] [rbp-60h]
int v70; // [rsp+54h] [rbp-54h] BYREF
int v71; // [rsp+58h] [rbp-50h] BYREF
int v72; // [rsp+5Ch] [rbp-4Ch] BYREF
int v73; // [rsp+60h] [rbp-48h] BYREF
int v74; // [rsp+64h] [rbp-44h] BYREF
int v75; // [rsp+68h] [rbp-40h] BYREF
int v76[15]; // [rsp+6Ch] [rbp-3Ch] BYREF

v6 = *a3;
v7 = *a4;
v62 = *a2;
v8 = *a2 & 1;
v75 = 1;
v76[0] = -1;
v73 = v6;
v74 = v7;
if ( v8 )
{
fwrite("gauss3d: nx not a multiple of 2\n", 1uLL, 0x20uLL, stderr);
exit(-1);
}
v70 = v62 / 2;
v71 = v62 / 2 + 1;
v72 = v71 * v6;
v10 = 4LL * v7 * v71 * v6;
v11 = (float *)malloc(v10);
if ( !v11 )
{
errm("gauss3d");
v7 = v74;
v10 = 4LL * v74 * v73 * v71;
}
v12 = (float *)malloc(v10);
if ( !v12 )
{
errm("gauss3d");
v7 = v74;
}
if ( v7 <= 0 )
{
v27 = &v75;
}
else
{
v64 = 0;
v13 = 0;
v68 = a5;
ptr = v11;
v14 = &v75;
v15 = 0;
v16 = (unsigned int)(v62 - 1) >> 1;
v60 = 2 * v16;
v17 = 4LL * (v16 + 1);
do
{
if ( v73 > 0 )
{
v18 = v14;
v19 = v13;
v20 = 0;
v21 = v18;
do
{
if ( v62 > 0 )
{
v22 = a1 + 4LL * v19;
v23 = 0LL;
do
{
ptr[v15 + v23 / 4] = *(float *)(v22 + 2 * v23);
v12[v15 + v23 / 4] = *(float *)(v22 + 2 * v23 + 4);
v23 += 4LL;
}
while ( v17 != v23 );
v19 += v60 + 2;
}
v54 = v19;
v24 = v15;
++v20;
v25 = &v12[v24];
v26 = (char *)&ptr[v24];
fft_(v26, v25, v21, &v70, v21, v76);
realt_(v26, v25, v21, &v70, v21, v76);
v15 += v71;
v19 = v54;
}
while ( v73 > v20 );
v13 = v54;
v14 = v21;
}
++v64;
}
while ( v74 > v64 );
v27 = v14;
a5 = v68;
v11 = ptr;
}
fft_(v11, v12, &v74, &v73, &v71, v76);
fft_(v11, v12, v27, &v74, &v72, v76);
v28 = v74;
v57 = -0.6931471805599453 / (float)(*a6 * *a6);
if ( v74 > 0 )
{
v67 = 0;
v29 = v73;
v30 = 0;
v31 = 0;
v69 = v27;
while ( 1 )
{
v61 = 0;
v32 = (float)v31;
v33 = 0;
v65 = (float)(v32 / (float)((float)v28 * a5[2]));
if ( v29 > 0 )
{
while ( 1 )
{
if ( v71 > 0 )
{
v35 = 0;
v36 = v30 + 1;
v34 = (float)((float)v33 / (float)((float)v29 * a5[1]));
v52 = v34 * v34;
do
{
v37 = v62 - v35;
if ( v62 / 2 >= v35 )
v37 = v35;
++v35;
v38 = exp(
((float)((float)v37 / (float)((float)v62 * *a5)) * (float)((float)v37 / (float)((float)v62 * *a5))
+ v52
+ v65 * v65)
* v57);
v30 = v36;
v39 = v38;
*(float *)&v38 = v11[v36 - 1] * v38;
v11[v36 - 1] = *(float *)&v38;
*(float *)&v38 = v12[v36 - 1] * v39;
v12[v36++ - 1] = *(float *)&v38;
}
while ( v71 > v35 );
v29 = v73;
}
if ( v29 <= ++v61 )
break;
v33 = v29 - v61;
if ( v29 >> 1 >= v61 )
v33 = v61;
}
v28 = v74;
}
if ( v28 <= ++v67 )
break;
v31 = v28 - v67;
if ( v28 >> 1 >= v67 )
v31 = v67;
}
v27 = v69;
}
fft_(v11, v12, v27, &v74, &v72, v27);
fft_(v11, v12, &v74, &v73, &v71, v27);
if ( v74 > 0 )
{
v55 = v11;
v59 = 0;
v40 = (unsigned int)(v62 - 1) >> 1;
v41 = 2 * v40;
v42 = v40 + 1;
v43 = v27;
v44 = 0;
v58 = v41;
v45 = 4 * v42;
v46 = 0;
do
{
if ( v73 > 0 )
{
v47 = v43;
for ( i = 0; i < v73; ++i )
{
v53 = v46;
v49 = v44;
realt_(&v55[v49], &v12[v49], v47, &v70, v47, v47);
fft_(&v55[v49], &v12[v49], v47, &v70, v47, v47);
v46 = v53;
if ( v62 > 0 )
{
v50 = a1 + 4LL * v53;
v51 = 0LL;
do
{
*(float *)(v50 + 2 * v51) = v55[v49 + v51 / 4];
*(float *)(v50 + 2 * v51 + 4) = v12[v49 + v51 / 4];
v51 += 4LL;
}
while ( v45 != v51 );
v46 = v53 + v58 + 2;
}
v44 += v71;
}
v43 = v47;
}
++v59;
}
while ( v74 > v59 );
v11 = v55;
}
free(v11);
free(v12);
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1, int *a2, int *a3, int *a4, float *a5, float *a6)
{
int v6; // eax
int v7; // ebx
int v8; // esi
size_t v10; // rbp
float *v11; // r12
float *v12; // rbp
int v13; // er10
int *v14; // r12
int v15; // ebx
unsigned int v16; // eax
__int64 v17; // r15
int *v18; // rsi
int v19; // eax
int v20; // er12
int *v21; // r14
__int64 v22; // rcx
unsigned __int64 v23; // rdx
__int64 v24; // r13
float *v25; // rsi
char *v26; // r13
int *v27; // rbx
int v28; // esi
int v29; // eax
int v30; // ecx
int v31; // edx
float v32; // xmm0_4
int v33; // edx
double v34; // xmm0_8
int v35; // ebx
__int64 v36; // r15
int v37; // ecx
double v38; // xmm0_8
double v39; // xmm2_8
unsigned int v40; // er14
int v41; // eax
__int64 v42; // r13
int *v43; // r14
int v44; // ebx
__int64 v45; // r13
int v46; // eax
int *v47; // r12
int i; // er14
__int64 v49; // rdi
__int64 v50; // rcx
unsigned __int64 v51; // rdx
double v52; // [rsp+0h] [rbp-A8h]
int v53; // [rsp+0h] [rbp-A8h]
int v54; // [rsp+8h] [rbp-A0h]
float *v55; // [rsp+8h] [rbp-A0h]
float *ptr; // [rsp+10h] [rbp-98h]
double v57; // [rsp+18h] [rbp-90h]
int v58; // [rsp+18h] [rbp-90h]
int v59; // [rsp+24h] [rbp-84h]
int v60; // [rsp+28h] [rbp-80h]
int v61; // [rsp+28h] [rbp-80h]
int v62; // [rsp+2Ch] [rbp-7Ch]
int v64; // [rsp+38h] [rbp-70h]
double v65; // [rsp+38h] [rbp-70h]
int v67; // [rsp+40h] [rbp-68h]
float *v68; // [rsp+48h] [rbp-60h]
int *v69; // [rsp+48h] [rbp-60h]
int v70; // [rsp+54h] [rbp-54h] BYREF
int v71; // [rsp+58h] [rbp-50h] BYREF
int v72; // [rsp+5Ch] [rbp-4Ch] BYREF
int v73; // [rsp+60h] [rbp-48h] BYREF
int v74; // [rsp+64h] [rbp-44h] BYREF
int v75; // [rsp+68h] [rbp-40h] BYREF
int v76[15]; // [rsp+6Ch] [rbp-3Ch] BYREF

v6 = *a3;
v7 = *a4;
v62 = *a2;
v8 = *a2 & 1;
v75 = 1;
v76[0] = -1;
v73 = v6;
v74 = v7;
if ( v8 )
{
fwrite("gauss3d: nx not a multiple of 2\n", 1uLL, 0x20uLL, stderr);
exit(-1);
}
v70 = v62 / 2;
v71 = v62 / 2 + 1;
v72 = v71 * v6;
v10 = 4LL * v7 * v71 * v6;
v11 = (float *)malloc(v10);
if ( !v11 )
{
errm("gauss3d");
v7 = v74;
v10 = 4LL * v74 * v73 * v71;
}
v12 = (float *)malloc(v10);
if ( !v12 )
{
errm("gauss3d");
v7 = v74;
}
if ( v7 <= 0 )
{
v27 = &v75;
}
else
{
v64 = 0;
v13 = 0;
v68 = a5;
ptr = v11;
v14 = &v75;
v15 = 0;
v16 = (unsigned int)(v62 - 1) >> 1;
v60 = 2 * v16;
v17 = 4LL * (v16 + 1);
do
{
if ( v73 > 0 )
{
v18 = v14;
v19 = v13;
v20 = 0;
v21 = v18;
do
{
if ( v62 > 0 )
{
v22 = a1 + 4LL * v19;
v23 = 0LL;
do
{
ptr[v15 + v23 / 4] = *(float *)(v22 + 2 * v23);
v12[v15 + v23 / 4] = *(float *)(v22 + 2 * v23 + 4);
v23 += 4LL;
}
while ( v17 != v23 );
v19 += v60 + 2;
}
v54 = v19;
v24 = v15;
++v20;
v25 = &v12[v24];
v26 = (char *)&ptr[v24];
fft_(v26, v25, v21, &v70, v21, v76);
realt_(v26, v25, v21, &v70, v21, v76);
v15 += v71;
v19 = v54;
}
while ( v73 > v20 );
v13 = v54;
v14 = v21;
}
++v64;
}
while ( v74 > v64 );
v27 = v14;
a5 = v68;
v11 = ptr;
}
fft_(v11, v12, &v74, &v73, &v71, v76);
fft_(v11, v12, v27, &v74, &v72, v76);
v28 = v74;
v57 = -0.6931471805599453 / (float)(*a6 * *a6);
if ( v74 > 0 )
{
v67 = 0;
v29 = v73;
v30 = 0;
v31 = 0;
v69 = v27;
while ( 1 )
{
v61 = 0;
v32 = (float)v31;
v33 = 0;
v65 = (float)(v32 / (float)((float)v28 * a5[2]));
if ( v29 > 0 )
{
while ( 1 )
{
if ( v71 > 0 )
{
v35 = 0;
v36 = v30 + 1;
v34 = (float)((float)v33 / (float)((float)v29 * a5[1]));
v52 = v34 * v34;
do
{
v37 = v62 - v35;
if ( v62 / 2 >= v35 )
v37 = v35;
++v35;
v38 = exp(
((float)((float)v37 / (float)((float)v62 * *a5)) * (float)((float)v37 / (float)((float)v62 * *a5))
+ v52
+ v65 * v65)
* v57);
v30 = v36;
v39 = v38;
*(float *)&v38 = v11[v36 - 1] * v38;
v11[v36 - 1] = *(float *)&v38;
*(float *)&v38 = v12[v36 - 1] * v39;
v12[v36++ - 1] = *(float *)&v38;
}
while ( v71 > v35 );
v29 = v73;
}
if ( v29 <= ++v61 )
break;
v33 = v29 - v61;
if ( v29 >> 1 >= v61 )
v33 = v61;
}
v28 = v74;
}
if ( v28 <= ++v67 )
break;
v31 = v28 - v67;
if ( v28 >> 1 >= v67 )
v31 = v67;
}
v27 = v69;
}
fft_(v11, v12, v27, &v74, &v72, v27);
fft_(v11, v12, &v74, &v73, &v71, v27);
if ( v74 > 0 )
{
v55 = v11;
v59 = 0;
v40 = (unsigned int)(v62 - 1) >> 1;
v41 = 2 * v40;
v42 = v40 + 1;
v43 = v27;
v44 = 0;
v58 = v41;
v45 = 4 * v42;
v46 = 0;
do
{
if ( v73 > 0 )
{
v47 = v43;
for ( i = 0; i < v73; ++i )
{
v53 = v46;
v49 = v44;
realt_(&v55[v49], &v12[v49], v47, &v70, v47, v47);
fft_(&v55[v49], &v12[v49], v47, &v70, v47, v47);
v46 = v53;
if ( v62 > 0 )
{
v50 = a1 + 4LL * v53;
v51 = 0LL;
do
{
*(float *)(v50 + 2 * v51) = v55[v49 + v51 / 4];
*(float *)(v50 + 2 * v51 + 4) = v12[v49 + v51 / 4];
v51 += 4LL;
}
while ( v45 != v51 );
v46 = v53 + v58 + 2;
}
v44 += v71;
}
v43 = v47;
}
++v59;
}
while ( v74 > v59 );
v11 = v55;
}
free(v11);
free(v12);
}

original_code:
void gauss3d (float *image, int *pnx, int *pny, int *pnz, float *cmppix, float *fhalf) {
 float *a, *b;
 double q, factor, f2, fx, fy, fz;
 int i, k, n1, n2, n2ny, jndex;
 int ix, iy, iz, nx, ny, nz, kx, ky, kz;
  int one = 1, negone = -1;
 nx = *pnx; ny = *pny; nz = *pnz;
 if (nx % 2) {
  fprintf (stderr, "gauss3d: nx not a multiple of 2\n");
  exit (-1);
 }
 n1 = nx/2;
 n2 = n1 + 1;
 n2ny = n2*ny;
 if (!(a = (float *) malloc (n2*ny*nz * sizeof (float)))) errm ("gauss3d");
 if (!(b = (float *) malloc (n2*ny*nz * sizeof (float)))) errm ("gauss3d");
 k = jndex = 0;
 for (iz = 0; iz < nz; iz++) {
 for (iy = 0; iy < ny; iy++) {
  for (i = ix = 0; ix < nx; ix += 2, i++) {
   (a + k)[i] = image[jndex++];
   (b + k)[i] = image[jndex++];
  }
  fft_ (a + k, b + k, &one, &n1, &one, &negone);
  realt_ (a + k, b + k, &one, &n1, &one, &negone);
  k += n2;
 }}
 fft_ (a, b, &nz, &ny, &n2, &negone);
 fft_ (a, b, &one, &nz, &n2ny, &negone);
 q = -log(2.)/((*fhalf)*(*fhalf));
 i = 0;
 for (iz = 0; iz < nz; iz++) {
  kz = (iz <= nz/2) ? iz : nz - iz;
  fz = kz/(nz*cmppix[2]);
 for (iy = 0; iy < ny; iy++) {
  ky = (iy <= ny/2) ? iy : ny - iy;
  fy = ky/(ny*cmppix[1]);
 for (ix = 0; ix < n2; ix++) {
  kx = (ix <= nx/2) ? ix : nx - ix;
  fx = kx/(nx*cmppix[0]);
  f2 = fx*fx + fy*fy + fz*fz;
  factor = exp (q*f2);
  a[i] *= factor;
   b[i] *= factor;
  i++;
 }}}
 fft_ (a, b, &one, &nz, &n2ny, &one);
 fft_ (a, b, &nz, &ny, &n2, &one);
 k = jndex = 0;
 for (iz = 0; iz < nz; iz++) {
 for (iy = 0; iy < ny; iy++) {
  realt_ (a + k, b + k, &one, &n1, &one, &one);
  fft_ (a + k, b + k, &one, &n1, &one, &one);
  for (i = ix = 0; ix < nx; ix += 2, i++) {
   image[jndex++] = (a + k)[i];
   image[jndex++] = (b + k)[i];
  }
  k += n2;
 }}
 free (a);
 free (b);
}

canonical_original_code:
void gauss3d(float *image, int *pnx, int *pny, int *pnz, float *cmppix, float *fhalf) {
 float *a; float *b;
 double q; double factor; double f2; double fx; double fy; double fz;
 int i; int k; int n1; int n2; int n2ny; int jndex;
 int ix; int iy; int iz; int nx; int ny; int nz; int kx; int ky; int kz;
  int one = 1; int negone = -1;
 nx = *pnx; ny = *pny; nz = *pnz;
 if (nx % 2) {
  fprintf (stderr, "gauss3d: nx not a multiple of 2\n");
  exit (-1);
 }
 n1 = nx/2;
 n2 = n1 + 1;
 n2ny = n2*ny;
 if (!(a = (float *) malloc (n2*ny*nz * sizeof (float)))) errm ("gauss3d");
 if (!(b = (float *) malloc (n2*ny*nz * sizeof (float)))) errm ("gauss3d");
 k = jndex = 0;
 for (iz = 0; iz < nz; iz++) {
 for (iy = 0; iy < ny; iy++) {
  for (i = ix = 0; ix < nx; ix += 2, i++) {
   (a + k)[i] = image[jndex++];
   (b + k)[i] = image[jndex++];
  }
  fft_ (a + k, b + k, &one, &n1, &one, &negone);
  realt_ (a + k, b + k, &one, &n1, &one, &negone);
  k += n2;
 }}
 fft_ (a, b, &nz, &ny, &n2, &negone);
 fft_ (a, b, &one, &nz, &n2ny, &negone);
 q = -log(2.)/((*fhalf)*(*fhalf));
 i = 0;
 for (iz = 0; iz < nz; iz++) {
  kz = (iz <= nz/2) ? iz : nz - iz;
  fz = kz/(nz*cmppix[2]);
 for (iy = 0; iy < ny; iy++) {
  ky = (iy <= ny/2) ? iy : ny - iy;
  fy = ky/(ny*cmppix[1]);
 for (ix = 0; ix < n2; ix++) {
  kx = (ix <= nx/2) ? ix : nx - ix;
  fx = kx/(nx*cmppix[0]);
  f2 = fx*fx + fy*fy + fz*fz;
  factor = exp (q*f2);
  a[i] *= factor;
   b[i] *= factor;
  i++;
 }}}
 fft_ (a, b, &one, &nz, &n2ny, &one);
 fft_ (a, b, &nz, &ny, &n2, &one);
 k = jndex = 0;
 for (iz = 0; iz < nz; iz++) {
 for (iy = 0; iy < ny; iy++) {
  realt_ (a + k, b + k, &one, &n1, &one, &one);
  fft_ (a + k, b + k, &one, &n1, &one, &one);
  for (i = ix = 0; ix < nx; ix += 2, i++) {
   image[jndex++] = (a + k)[i];
   image[jndex++] = (b + k)[i];
  }
  k += n2;
 }}
 free (a);
 free (b);
}

variable_types:
image
float *

variable_types:
pnx
int *

variable_types:
pny
int *

variable_types:
pnz
int *

variable_types:
cmppix
float *

variable_types:
fhalf
float *

variable_types:
a
float *

variable_types:
b
float *

variable_types: q double

variable_types: factor double

variable_types: fx double

variable_types: fy double

variable_types: fz double

variable_types: k int

variable_types: jndex int

variable_types: ix int

variable_types: iy int

variable_types: iz int

variable_types: nx int

variable_types: ny int

variable_types: nz int

variable_types: kx int

variable_types: ky int

variable_types: kz int

variable_types: one int

variable_types: negone int


repo: ytHu/symtable

decompiled_code:
__int64 __fastcall SymTable_hash(char *a1, unsigned int a2)
{
int v2; // edx
unsigned int v3; // eax
char *v4; // rdi
unsigned int v5; // er8

if ( !a1 )
_assert_fail("pcKey != NULL", "hash.c", 0xAu, "SymTable_hash");
v2 = *a1;
v3 = 0;
v4 = a1 + 1;
v5 = 0;
if ( (_BYTE)v2 )
{
do
{
++v4;
v3 = v2 + 65599 * v3;
v2 = *(v4 - 1);
}
while ( *(v4 - 1) );
v5 = v3 % a2;
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1, unsigned int a2)
{
int v2; // edx
unsigned int v3; // eax
char *v4; // rdi
unsigned int v5; // er8

if ( !a1 )
_assert_fail("pcKey != NULL", "hash.c", 0xAu, "SymTable_hash");
v2 = *a1;
v3 = 0;
v4 = a1 + 1;
v5 = 0;
if ( (_BYTE)v2 )
{
do
{
++v4;
v3 = v2 + 65599 * v3;
v2 = *(v4 - 1);
}
while ( *(v4 - 1) );
v5 = v3 % a2;
}
return v5;
}

original_code:
int SymTable_hash(const char *pcKey, int iBucketCount)
{
    enum { HASH_MULTIPLIER = 65599 };
    int i;
    unsigned int uiHash = 0U;
    ((pcKey != ((void *)0)) ? (void) (0) : __assert_fail ("pcKey != NULL", "hash.c", 10, __extension__ __PRETTY_FUNCTION__));
    for(i = 0; pcKey[i] != '\0'; i++)
        uiHash = uiHash * (unsigned int)HASH_MULTIPLIER + (unsigned int)pcKey[i];
    return (int)(uiHash%(unsigned int)iBucketCount);
}

canonical_original_code:
int SymTable_hash(char *pcKey, int iBucketCount)
{
    enum { HASH_MULTIPLIER = 65599 };
    int i;
    unsigned int uiHash = 0U;
    ((pcKey != ((void *)0)) ? (void) (0) : __assert_fail ("pcKey != NULL", "hash.c", 10, __extension__ __PRETTY_FUNCTION__));
    for(i = 0; pcKey[i] != '\0'; i++)
        uiHash = uiHash * (unsigned int)HASH_MULTIPLIER + (unsigned int)pcKey[i];
    return (int)(uiHash%(unsigned int)iBucketCount);
}

variable_types:
pcKey
char *

variable_types: iBucketCount int

variable_types: i int

variable_types:
uiHash
unsigned int