reshape

decompiled_code:
__int64 __fastcall reshape(int a1, int a2)
{
glViewport(0LL, 0LL, (unsigned int)a1, (unsigned int)a2);
glMatrixMode(5889LL);
glLoadIdentity();
glViewport(0LL, 0LL, (unsigned int)a1, (unsigned int)a2);
glMatrixMode(5889LL);
glLoadIdentity();
glFrustum(
-0.800000011920929,
0.800000011920929,
(float)(-0.80000001 / (float)((float)a1 / (float)a2)),
(float)(0.80000001 / (float)((float)a1 / (float)a2)),
3.0,
10.0);
gluLookAt(3.0, 3.0, 3.0, 0.0, 0.0, 0.0, 0.0, 1.0, 5889LL);
glMatrixMode(5888LL);
glLoadIdentity();
return glTranslatef(0.0, 0.0, -5.0);
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, int a2)
{
glViewport(0LL, 0LL, (unsigned int)a1, (unsigned int)a2);
glMatrixMode(5889LL);
glLoadIdentity();
glViewport(0LL, 0LL, (unsigned int)a1, (unsigned int)a2);
glMatrixMode(5889LL);
glLoadIdentity();
glFrustum(
-0.800000011920929,
0.800000011920929,
(float)(-0.80000001 / (float)((float)a1 / (float)a2)),
(float)(0.80000001 / (float)((float)a1 / (float)a2)),
3.0,
10.0);
gluLookAt(3.0, 3.0, 3.0, 0.0, 0.0, 0.0, 0.0, 1.0, 5889LL);
glMatrixMode(5888LL);
glLoadIdentity();
return glTranslatef(0.0, 0.0, -5.0);
}

original_code:
void reshape(int wid, int ht)
{
    float vp = 0.8f;
    float aspect = (float) wid / (float) ht;
    glViewport(0, 0, wid, ht);
    glMatrixMode(0x1701);
    glLoadIdentity();
    glViewport(0, 0, wid, ht);
    glMatrixMode(0x1701);
    glLoadIdentity();
    glFrustum(-vp, vp, -vp / aspect, vp / aspect, 3, 10.0);
 gluLookAt( 3.0f,
               3.0f,
               3.0f,
               0.0f,
               0.0f,
               0.0f,
               0.0f,
               1.0f,
               0.0f );
    glMatrixMode(0x1700);
    glLoadIdentity();
    glTranslatef(0.0, 0.0, -5.0);
}

variable_types: wid int

variable_types: ht int

variable_types: vp float

variable_types: aspect float


printOglError

decompiled_code:
__int64 __fastcall printOglError(const char *a1, unsigned int a2)
{
unsigned int v3; // eax
__int64 v4; // rdi
const char *v5; // rax
unsigned int v6; // eax

v3 = glGetError();
if ( !v3 )
return 0LL;
v4 = v3;
do
{
v5 = (const char *)gluErrorString(v4);
printf("glError in file %s @ line %d: %s\n", a1, a2, v5);
v6 = glGetError();
v4 = v6;
}
while ( v6 );
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(const char *a1, unsigned int a2)
{
unsigned int v3; // eax
__int64 v4; // rdi
const char *v5; // rax
unsigned int v6; // eax

v3 = glGetError();
if ( !v3 )
return 0LL;
v4 = v3;
do
{
v5 = (const char *)gluErrorString(v4);
printf("glError in file %s @ line %d: %s\n", a1, a2, v5);
v6 = glGetError();
v4 = v6;
}
while ( v6 );
return 1LL;
}

original_code:
int printOglError(char *file, int line)
{
    GLenum glErr;
    int retCode = 0;
    glErr = glGetError();
    while (glErr != 0)
    {
        printf("glError in file %s @ line %d: %s\n", file, line, gluErrorString(glErr));
        retCode = 1;
        glErr = glGetError();
    }
    return retCode;
}

canonical_original_code:
int printOglError(char *file, int line)
{
    unsigned int glErr;
    int retCode = 0;
    glErr = glGetError();
    while (glErr != 0)
    {
        printf("glError in file %s @ line %d: %s\n", file, line, gluErrorString(glErr));
        retCode = 1;
        glErr = glGetError();
    }
    return retCode;
}

variable_types:
file
char *

variable_types: line int

variable_types:
glErr
unsigned int

variable_types: retCode int

return_type: int


Args

decompiled_code:
__int64 __fastcall Args(int a1, __int64 a2)
{
const char **v2; // rax
int v3; // edx
const char *v4; // rcx

v2 = (const char **)(a2 + 8);
v3 = 1;
while ( 1 )
{
if ( v3 >= a1 )
return 1LL;
if ( strcmp(*v2, "-loop") )
break;
if ( ++v3 < a1 )
{
v4 = v2[1];
++v2;
if ( *v4 != 45 )
continue;
}
puts("-loop no count given.");
return 0LL;
}
printf("%s (Bad option)\n", *v2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1, __int64 a2)
{
const char **v2; // rax
int v3; // edx
const char *v4; // rcx

v2 = (const char **)(a2 + 8);
v3 = 1;
while ( 1 )
{
if ( v3 >= a1 )
return 1LL;
if ( strcmp(*v2, "-loop") )
break;
if ( ++v3 < a1 )
{
v4 = v2[1];
++v2;
if ( *v4 != 45 )
continue;
}
puts("-loop no count given.");
return 0LL;
}
printf("%s (Bad option)\n", *v2);
return 0LL;
}

original_code:
int Args(int argc, char **argv)
{
    int i;
    for (i = 1; i < argc; i++)
    {
        if (strcmp(argv[i], "-loop") == 0)
        {
            if (i+1 >= argc || argv[i+1][0] == '-')
            {
                printf("-loop no count given.\n");
                return 0;
            }
        }
        else
        {
            printf("%s (Bad option)\n", argv[i]);
            return 0;
        }
    }
    return 1;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: i int


updateAnim

decompiled_code:
__int64 updateAnim()
{
unsigned int v0; // eax

v0 = getUniLoc(ProgramObject, "currentTime");
if ( (float)(*(float *)&ParticleTime + 0.0020000001) > 15.0 )
ParticleTime = 0;
else
*(float *)&ParticleTime = *(float *)&ParticleTime + 0.0020000001;
glUniform1fARB(v0);
return printOglError("ogl2particle.c", 0x85u);
}

canonical_decompiled_code:
__int64 func5()
{
unsigned int v0; // eax

v0 = getUniLoc(ProgramObject, "currentTime");
if ( (float)(*(float *)&ParticleTime + 0.0020000001) > 15.0 )
ParticleTime = 0;
else
*(float *)&ParticleTime = *(float *)&ParticleTime + 0.0020000001;
glUniform1fARB(v0);
return func3("ogl2particle.c", 0x85u);
}

original_code:
void updateAnim()
{
    int location;
    location = getUniLoc(ProgramObject, "currentTime");
    ParticleTime += 0.002f;
    if (ParticleTime > 15.0)
        ParticleTime = 0.0;
    glUniform1fARB(location, ParticleTime);
    printOglError("ogl2particle.c", 133);
}

variable_types: location int

return_type: void


play

decompiled_code:
__int64 play()
{
updateAnim();
printOglError("ogl2particle.c", 0x8Du);
glutPostRedisplay();
return printOglError("ogl2particle.c", 0x8Fu);
}

canonical_decompiled_code:
__int64 func6()
{
func5();
func3("ogl2particle.c", 0x8Du);
glutPostRedisplay();
return func3("ogl2particle.c", 0x8Fu);
}

original_code:
void play(void)
{
    updateAnim();
    printOglError("ogl2particle.c", 141);
    glutPostRedisplay();
    printOglError("ogl2particle.c", 143);
}

canonical_original_code:
void play()
{
    updateAnim();
    printOglError("ogl2particle.c", 141);
    glutPostRedisplay();
    printOglError("ogl2particle.c", 143);
}


isExtensionSupported

decompiled_code:
__int64 __fastcall isExtensionSupported(char *s)
{
const char *v2; // r12
char *v3; // rbx
const char *v4; // rax

if ( !strchr(s, 32) && *s )
{
v2 = (const char *)glGetString(7939LL);
while ( 1 )
{
v3 = strstr(v2, s);
if ( !v3 )
break;
v4 = &v3[strlen(s)];
if ( v2 != v3 )
{
v2 = v4;
if ( *(v3 - 1) != 32 )
continue;
}
if ( (*v4 & 0xDF) == 0 )
return 1LL;
v2 = v4;
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(char *s)
{
const char *v2; // r12
char *v3; // rbx
const char *v4; // rax

if ( !strchr(s, 32) && *s )
{
v2 = (const char *)glGetString(7939LL);
while ( 1 )
{
v3 = strstr(v2, s);
if ( !v3 )
break;
v4 = &v3[strlen(s)];
if ( v2 != v3 )
{
v2 = v4;
if ( *(v3 - 1) != 32 )
continue;
}
if ( (*v4 & 0xDF) == 0 )
return 1LL;
v2 = v4;
}
}
return 0LL;
}

original_code:
int isExtensionSupported( const char *extension )
{
    const GLubyte *extensions = ((void *)0);
    const GLubyte *start;
    GLubyte *where, *terminator;
    where = (GLubyte *) strchr(extension, ' ');
    if (where || *extension == '\0')
        return 0;
    extensions = glGetString(0x1F03);
    start = extensions;
    for (;;) {
        where = (GLubyte *) strstr((const char *) start, extension);
        if (!where)
            break;
        terminator = where + strlen(extension);
        if (where == start || *(where - 1) == ' ')
            if (*terminator == ' ' || *terminator == '\0')
                return 1;
        start = terminator;
    }
    return 0;
}

canonical_original_code:
int isExtensionSupported(char *extension)
{
    unsigned char *extensions = ((void *)0);
    unsigned char *start;
    unsigned char *where; unsigned char *terminator;
    where = (unsigned char *) strchr(extension, ' ');
    if (where || *extension == '\0')
        return 0;
    extensions = glGetString(0x1F03);
    start = extensions;
    for (;;) {
        where = (unsigned char *) strstr((char *) start, extension);
        if (!where)
            break;
        terminator = where + strlen(extension);
        if (where == start || *(where - 1) == ' ')
            if (*terminator == ' ' || *terminator == '\0')
                return 1;
        start = terminator;
    }
    return 0;
}

variable_types:
extension
char *

variable_types:
extensions
unsigned char *

variable_types:
start
unsigned char *

variable_types:
where
unsigned char *

variable_types:
terminator
unsigned char *


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
__int64 v5; // rsi
int v6; // [rsp+Ch] [rbp-2Ch] BYREF
__int64 v7; // [rsp+10h] [rbp-28h] BYREF
__int64 v8[4]; // [rsp+18h] [rbp-20h] BYREF

v6 = argc;
if ( !(unsigned int)Args(argc, (__int64)argv) )
exit(0);
glutInit(&v6, argv);
glutInitDisplayMode(18LL);
glutInitWindowSize(500LL, 500LL);
glutCreateWindow("Fire and Smoke");
glutIdleFunc(play);
glutDisplayFunc(display);
glutKeyboardFunc(key);
glutReshapeFunc(reshape);
printOglError("ogl2particle.c", 0xFDu);
if ( (unsigned int)isExtensionSupported("GL_ARB_shader_objects")
&& (unsigned int)isExtensionSupported("GL_ARB_fragment_shader")
&& (unsigned int)isExtensionSupported("GL_ARB_vertex_shader")
&& (unsigned int)isExtensionSupported("GL_ARB_shading_language_100") )
{
createPoints(50000LL);
glDepthFunc(513LL);
glEnable(2929LL);
glClearColor(0.0, 0.67000002, 0.94, 1.0);
ParticleTime = 0;
readShaderSource("smoke", &v7, v8);
v5 = v8[0];
v3 = installParticleShaders(v7, v8[0]);
if ( v3 )
{
glutMainLoop();
v3 = 0;
}
else
{
printf("Error installing particle shaders");
_isoc99_scanf("%d", v5);
}
}
else
{
v3 = 1;
puts("OpenGL Shading Language extensions not available");
}
return v3;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
__int64 v5; // rsi
int v6; // [rsp+Ch] [rbp-2Ch] BYREF
__int64 v7; // [rsp+10h] [rbp-28h] BYREF
__int64 v8[4]; // [rsp+18h] [rbp-20h] BYREF

v6 = argc;
if ( !(unsigned int)func4(argc, (__int64)argv) )
exit(0);
glutInit(&v6, argv);
glutInitDisplayMode(18LL);
glutInitWindowSize(500LL, 500LL);
glutCreateWindow("Fire and Smoke");
glutIdleFunc(play);
glutDisplayFunc(display);
glutKeyboardFunc(key);
glutReshapeFunc(reshape);
func3("ogl2particle.c", 0xFDu);
if ( (unsigned int)func7("GL_ARB_shader_objects")
&& (unsigned int)func7("GL_ARB_fragment_shader")
&& (unsigned int)func7("GL_ARB_vertex_shader")
&& (unsigned int)func7("GL_ARB_shading_language_100") )
{
createPoints(50000LL);
glDepthFunc(513LL);
glEnable(2929LL);
glClearColor(0.0, 0.67000002, 0.94, 1.0);
ParticleTime = 0;
readShaderSource("smoke", &v7, v8);
v5 = v8[0];
v3 = installParticleShaders(v7, v8[0]);
if ( v3 )
{
glutMainLoop();
v3 = 0;
}
else
{
printf("Error installing particle shaders");
_isoc99_scanf("%d", v5);
}
}
else
{
v3 = 1;
puts("OpenGL Shading Language extensions not available");
}
return v3;
}

original_code:
int main( int argc, char **argv )
{
    int success = 0;
    GLcharARB *VertexShaderSource, *FragmentShaderSource;
    int error = 0;
    if (Args(argc, argv) == 0)
        exit(0);
    glutInit( &argc, argv );
    glutInitDisplayMode( 0x0000 | 0x0010 | 0x0002 );
    glutInitWindowSize(500, 500);
    window = glutCreateWindow( "Fire and Smoke" );
    glutIdleFunc( play );
    glutDisplayFunc( display );
    glutKeyboardFunc( key );
    glutReshapeFunc( reshape );
    printOglError("ogl2particle.c", 253);
    if ( !isExtensionSupported( "GL_ARB_shader_objects" ) ||
         !isExtensionSupported( "GL_ARB_fragment_shader" ) ||
         !isExtensionSupported( "GL_ARB_vertex_shader" ) ||
         !isExtensionSupported( "GL_ARB_shading_language_100" ) )
    {
        printf("OpenGL Shading Language extensions not available\n" );
        return 1;
    }
    if( error )
    {
        printf( "ERROR from wglGetProcAddress\n" );
    }
    createPoints( numParticles );
    glDepthFunc( 0x0201 );
    glEnable( 0x0B71 );
 glClearColor( 0.0f, 0.67f, 0.94f, 1.0f );
 ParticleTime = 0.0f;
    readShaderSource( "smoke", &VertexShaderSource, &FragmentShaderSource );
    success = installParticleShaders( VertexShaderSource, FragmentShaderSource );
    if ( success )
 {
  glutMainLoop();
 }
 else
 {
  printf( "Error installing particle shaders" );
  scanf( "%d", ParticleTime );
 }
    return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
    int success = 0;
    char *VertexShaderSource; char *FragmentShaderSource;
    int error = 0;
    if (Args(argc, argv) == 0)
        exit(0);
    glutInit( &argc, argv );
    glutInitDisplayMode( 0x0000 | 0x0010 | 0x0002 );
    glutInitWindowSize(500, 500);
    window = glutCreateWindow( "Fire and Smoke" );
    glutIdleFunc( play );
    glutDisplayFunc( display );
    glutKeyboardFunc( key );
    glutReshapeFunc( reshape );
    printOglError("ogl2particle.c", 253);
    if ( !isExtensionSupported( "GL_ARB_shader_objects" ) ||
         !isExtensionSupported( "GL_ARB_fragment_shader" ) ||
         !isExtensionSupported( "GL_ARB_vertex_shader" ) ||
         !isExtensionSupported( "GL_ARB_shading_language_100" ) )
    {
        printf("OpenGL Shading Language extensions not available\n" );
        return 1;
    }
    if( error )
    {
        printf( "ERROR from wglGetProcAddress\n" );
    }
    createPoints( numParticles );
    glDepthFunc( 0x0201 );
    glEnable( 0x0B71 );
 glClearColor( 0.0f, 0.67f, 0.94f, 1.0f );
 ParticleTime = 0.0f;
    readShaderSource( "smoke", &VertexShaderSource, &FragmentShaderSource );
    success = installParticleShaders( VertexShaderSource, FragmentShaderSource );
    if ( success )
 {
  glutMainLoop();
 }
 else
 {
  printf( "Error installing particle shaders" );
  scanf( "%d", ParticleTime );
 }
    return 0;
}

variable_types: success int

variable_types:
VertexShaderSource
char *

variable_types:
FragmentShaderSource
char *

variable_types: error int


getUniLoc

decompiled_code:
__int64 __fastcall getUniLoc(__int64 a1, const char *a2)
{
unsigned int v2; // er12

v2 = glGetUniformLocationARB();
if ( v2 == -1 )
printf("No such uniform named \"%s\"\n", a2);
printOglError("shader.c", 62LL);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, const char *a2)
{
unsigned int v2; // er12

v2 = glGetUniformLocationARB();
if ( v2 == -1 )
printf("No such uniform named \"%s\"\n", a2);
printOglError("shader.c", 62LL);
return v2;
}

original_code:
GLint getUniLoc(GLhandleARB program, const GLcharARB *name)
{
    GLint loc;
    loc = glGetUniformLocationARB(program, name);
    if (loc == -1)
        printf("No such uniform named \"%s\"\n", name);
    printOglError("shader.c", 62);
    return loc;
}

canonical_original_code:
int getUniLoc(unsigned int program, char *name)
{
    int loc;
    loc = glGetUniformLocationARB(program, name);
    if (loc == -1)
        printf("No such uniform named \"%s\"\n", name);
    printOglError("shader.c", 62);
    return loc;
}

variable_types:
program
unsigned int

variable_types:
name
char *

variable_types: loc int


printInfoLog

decompiled_code:
__int64 __fastcall printInfoLog(unsigned int a1)
{
unsigned int v1; // er13
char *v2; // rax
char *v3; // r12
int v5; // [rsp+8h] [rbp-20h] BYREF
int v6[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v5 = 0;
v6[0] = 0;
printOglError("shader.c", 75LL);
glGetObjectParameterivARB(a1, 35716LL, &v5);
printOglError("shader.c", 79LL);
v1 = v5;
if ( v5 > 0 )
{
v2 = (char *)malloc(v5);
v3 = v2;
if ( !v2 )
{
puts("ERROR: Could not allocate InfoLog buffer");
exit(1);
}
glGetInfoLogARB(a1, v1, v6, v2);
printf("InfoLog:\n%s\n\n", v3);
free(v3);
}
return printOglError("shader.c", 93LL);
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1)
{
unsigned int v1; // er13
char *v2; // rax
char *v3; // r12
int v5; // [rsp+8h] [rbp-20h] BYREF
int v6[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v5 = 0;
v6[0] = 0;
printOglError("shader.c", 75LL);
glGetObjectParameterivARB(a1, 35716LL, &v5);
printOglError("shader.c", 79LL);
v1 = v5;
if ( v5 > 0 )
{
v2 = (char *)malloc(v5);
v3 = v2;
if ( !v2 )
{
puts("ERROR: Could not allocate InfoLog buffer");
exit(1);
}
glGetInfoLogARB(a1, v1, v6, v2);
printf("InfoLog:\n%s\n\n", v3);
free(v3);
}
return printOglError("shader.c", 93LL);
}

original_code:
void printInfoLog(GLhandleARB obj)
{
    int infologLength = 0;
    int charsWritten = 0;
    GLcharARB *infoLog;
    printOglError("shader.c", 75);
    glGetObjectParameterivARB(obj, 0x8B84,
                                         &infologLength);
    printOglError("shader.c", 79);
    if (infologLength > 0)
    {
        infoLog = (GLcharARB*)malloc(infologLength);
        if (infoLog == ((void *)0))
        {
            printf("ERROR: Could not allocate InfoLog buffer\n");
            exit(1);
        }
        glGetInfoLogARB(obj, infologLength, &charsWritten, infoLog);
        printf("InfoLog:\n%s\n\n", infoLog);
        free(infoLog);
    }
    printOglError("shader.c", 93);
}

canonical_original_code:
void printInfoLog(unsigned int obj)
{
    int infologLength = 0;
    int charsWritten = 0;
    char *infoLog;
    printOglError("shader.c", 75);
    glGetObjectParameterivARB(obj, 0x8B84,
                                         &infologLength);
    printOglError("shader.c", 79);
    if (infologLength > 0)
    {
        infoLog = (char *)malloc(infologLength);
        if (infoLog == ((void *)0))
        {
            printf("ERROR: Could not allocate InfoLog buffer\n");
            exit(1);
        }
        glGetInfoLogARB(obj, infologLength, &charsWritten, infoLog);
        printf("InfoLog:\n%s\n\n", infoLog);
        free(infoLog);
    }
    printOglError("shader.c", 93);
}

variable_types:
obj
unsigned int

variable_types: infologLength int

variable_types: charsWritten int

variable_types:
infoLog
char *


shaderSize

decompiled_code:
__int64 __fastcall shaderSize(char *src, int a2)
{
char *v2; // rax
int v3; // eax
int v4; // ebp
unsigned int v5; // er12
char v7[136]; // [rsp+0h] [rbp-88h] BYREF

v2 = stpcpy(v7, src);
if ( a2 )
{
if ( a2 != 1 )
_assert_fail("0", "shader.c", 0x7Bu, "shaderSize");
strcpy(v2, ".frag");
}
else
{
strcpy(v2, ".vert");
}
v3 = open(v7, 0);
v4 = v3;
if ( v3 == -1 )
return (unsigned int)-1;
v5 = lseek(v3, 0LL, 2);
close(v4);
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *src, int a2)
{
char *v2; // rax
int v3; // eax
int v4; // ebp
unsigned int v5; // er12
char v7[136]; // [rsp+0h] [rbp-88h] BYREF

v2 = stpcpy(v7, src);
if ( a2 )
{
if ( a2 != 1 )
_assert_fail("0", "shader.c", 0x7Bu, "shaderSize");
strcpy(v2, ".frag");
}
else
{
strcpy(v2, ".vert");
}
v3 = open(v7, 0);
v4 = v3;
if ( v3 == -1 )
return (unsigned int)-1;
v5 = lseek(v3, 0LL, 2);
close(v4);
return v5;
}

original_code:
int shaderSize(char *fileName, EShaderType shaderType)
{
    int shader;
    char name[100];
    int count;
    strcpy(name, fileName);
    switch (shaderType)
    {
        case EVertexShader:
            strcat(name, ".vert");
            break;
        case EFragmentShader:
            strcat(name, ".frag");
            break;
        default:
            ((void) sizeof ((0) ? 1 : 0), __extension__ ({ if (0) ; else __assert_fail ("0", "shader.c", 123, __extension__ __PRETTY_FUNCTION__); }));
            break;
    }
    shader = open(name, 00);
    if (shader == -1)
        return -1;
    count = lseek(shader, 0, 2);
    close(shader);
    return count;
}

canonical_original_code:
int shaderSize(char *fileName, enum EShaderType shaderType)
{
    int shader;
    char name[100];
    int count;
    strcpy(name, fileName);
    switch (shaderType)
    {
        case EVertexShader:
            strcat(name, ".vert");
            break;
        case EFragmentShader:
            strcat(name, ".frag");
            break;
        default:
            ((void) sizeof ((0) ? 1 : 0), __extension__ ({ if (0) ; else __assert_fail ("0", "shader.c", 123, __extension__ __PRETTY_FUNCTION__); }));
            break;
    }
    shader = open(name, 00);
    if (shader == -1)
        return -1;
    count = lseek(shader, 0, 2);
    close(shader);
    return count;
}

variable_types:
fileName
char *

variable_types: enum EShaderType { EVertexShader=0, EFragmentShader=1 }

variable_types: shader int

variable_types:
name
char [100]

variable_types: count int


readShaderSource

decompiled_code:
__int64 __fastcall readShaderSource(char *src, void **a2, void **a3)
{
int v4; // er12
int v5; // eax
int v6; // er13
unsigned int v7; // er12
__int64 result; // rax

v4 = shaderSize(src, 0);
v5 = shaderSize(src, 1);
if ( v4 == -1 || (v6 = v5, v5 == -1) )
{
printf("Cannot determine size of the shader %s\n", src);
result = 0LL;
}
else
{
*a2 = malloc(v4);
*a3 = malloc(v6);
if ( (unsigned int)readShader(src, 0, *a2, v4) )
{
v7 = readShader(src, 1, *a3, v6);
if ( v7 )
v7 = 1;
else
printf("Cannot read the file %s.frag\n", src);
result = v7;
}
else
{
printf("Cannot read the file %s.vert\n", src);
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(char *src, void **a2, void **a3)
{
int v4; // er12
int v5; // eax
int v6; // er13
unsigned int v7; // er12
__int64 result; // rax

v4 = func2(src, 0);
v5 = func2(src, 1);
if ( v4 == -1 || (v6 = v5, v5 == -1) )
{
printf("Cannot determine size of the shader %s\n", src);
result = 0LL;
}
else
{
*a2 = malloc(v4);
*a3 = malloc(v6);
if ( (unsigned int)func3(src, 0, *a2, v4) )
{
v7 = func3(src, 1, *a3, v6);
if ( v7 )
v7 = 1;
else
printf("Cannot read the file %s.frag\n", src);
result = v7;
}
else
{
printf("Cannot read the file %s.vert\n", src);
result = 0LL;
}
}
return result;
}

original_code:
int readShaderSource(char *fileName, GLcharARB **vertexShader, GLcharARB **fragmentShader)
{
    int vSize, fSize;
    vSize = shaderSize(fileName, EVertexShader);
    fSize = shaderSize(fileName, EFragmentShader);
    if ((vSize == -1) || (fSize == -1))
    {
        printf("Cannot determine size of the shader %s\n", fileName);
        return 0;
    }
    *vertexShader = (GLcharARB *) malloc(vSize);
    *fragmentShader = (GLcharARB *) malloc(fSize);
    if (!readShader(fileName, EVertexShader, *vertexShader, vSize))
    {
        printf("Cannot read the file %s.vert\n", fileName);
        return 0;
    }
    if (!readShader(fileName, EFragmentShader, *fragmentShader, fSize)) {
        printf("Cannot read the file %s.frag\n", fileName);
        return 0;
    }
    return 1;
}

canonical_original_code:
int readShaderSource(char *fileName, char **vertexShader, char **fragmentShader)
{
    int vSize; int fSize;
    vSize = shaderSize(fileName, EVertexShader);
    fSize = shaderSize(fileName, EFragmentShader);
    if ((vSize == -1) || (fSize == -1))
    {
        printf("Cannot determine size of the shader %s\n", fileName);
        return 0;
    }
    *vertexShader = (char *) malloc(vSize);
    *fragmentShader = (char *) malloc(fSize);
    if (!readShader(fileName, EVertexShader, *vertexShader, vSize))
    {
        printf("Cannot read the file %s.vert\n", fileName);
        return 0;
    }
    if (!readShader(fileName, EFragmentShader, *fragmentShader, fSize)) {
        printf("Cannot read the file %s.frag\n", fileName);
        return 0;
    }
    return 1;
}

variable_types:
vertexShader
char **

variable_types:
fragmentShader
char **

variable_types: vSize int

variable_types: fSize int


installParticleShaders

decompiled_code:
__int64 __fastcall installParticleShaders(__int64 a1, __int64 a2)
{
unsigned int v3; // eax
__int64 v4; // [rsp+0h] [rbp-28h] BYREF
__int64 v5; // [rsp+8h] [rbp-20h] BYREF
int v6; // [rsp+14h] [rbp-14h] BYREF
int v7; // [rsp+18h] [rbp-10h] BYREF
int v8[3]; // [rsp+1Ch] [rbp-Ch] BYREF

v5 = a1;
v4 = a2;
VertexShaderObject = glCreateShaderObjectARB(35633LL);
FragmentShaderObject = glCreateShaderObjectARB(35632LL);
glShaderSourceARB((unsigned int)VertexShaderObject, 1LL, &v5, 0LL);
glShaderSourceARB((unsigned int)FragmentShaderObject, 1LL, &v4, 0LL);
glCompileShaderARB((unsigned int)VertexShaderObject);
printOglError("shader.c", 251LL);
glGetObjectParameterivARB((unsigned int)VertexShaderObject, 35713LL, &v6);
printInfoLog(VertexShaderObject);
glCompileShaderARB((unsigned int)FragmentShaderObject);
printOglError("shader.c", 260LL);
glGetObjectParameterivARB((unsigned int)FragmentShaderObject, 35713LL, &v7);
printInfoLog(FragmentShaderObject);
if ( !v6 )
return 0LL;
if ( !v7 )
return 0LL;
ProgramObject = glCreateProgramObjectARB();
glAttachObjectARB((unsigned int)ProgramObject, (unsigned int)VertexShaderObject);
glAttachObjectARB((unsigned int)ProgramObject, (unsigned int)FragmentShaderObject);
glBindAttribLocationARB((unsigned int)ProgramObject, 6LL, "velocity");
glBindAttribLocationARB((unsigned int)ProgramObject, 4LL, "startTime");
glBindAttribLocationARB((unsigned int)ProgramObject, 5LL, "random");
glLinkProgramARB((unsigned int)ProgramObject);
printOglError("shader.c", 283LL);
glGetObjectParameterivARB((unsigned int)ProgramObject, 35714LL, v8);
printInfoLog(ProgramObject);
if ( !v8[0] )
return 0LL;
glUseProgramObjectARB((unsigned int)ProgramObject);
v3 = getUniLoc((unsigned int)ProgramObject, "currentTime");
glUniform1fARB(v3, -5.0);
printOglError("shader.c", 298LL);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2)
{
unsigned int v3; // eax
__int64 v4; // [rsp+0h] [rbp-28h] BYREF
__int64 v5; // [rsp+8h] [rbp-20h] BYREF
int v6; // [rsp+14h] [rbp-14h] BYREF
int v7; // [rsp+18h] [rbp-10h] BYREF
int v8[3]; // [rsp+1Ch] [rbp-Ch] BYREF

v5 = a1;
v4 = a2;
VertexShaderObject = glCreateShaderObjectARB(35633LL);
FragmentShaderObject = glCreateShaderObjectARB(35632LL);
glShaderSourceARB((unsigned int)VertexShaderObject, 1LL, &v5, 0LL);
glShaderSourceARB((unsigned int)FragmentShaderObject, 1LL, &v4, 0LL);
glCompileShaderARB((unsigned int)VertexShaderObject);
printOglError("shader.c", 251LL);
glGetObjectParameterivARB((unsigned int)VertexShaderObject, 35713LL, &v6);
func1(VertexShaderObject);
glCompileShaderARB((unsigned int)FragmentShaderObject);
printOglError("shader.c", 260LL);
glGetObjectParameterivARB((unsigned int)FragmentShaderObject, 35713LL, &v7);
func1(FragmentShaderObject);
if ( !v6 )
return 0LL;
if ( !v7 )
return 0LL;
ProgramObject = glCreateProgramObjectARB();
glAttachObjectARB((unsigned int)ProgramObject, (unsigned int)VertexShaderObject);
glAttachObjectARB((unsigned int)ProgramObject, (unsigned int)FragmentShaderObject);
glBindAttribLocationARB((unsigned int)ProgramObject, 6LL, "velocity");
glBindAttribLocationARB((unsigned int)ProgramObject, 4LL, "startTime");
glBindAttribLocationARB((unsigned int)ProgramObject, 5LL, "random");
glLinkProgramARB((unsigned int)ProgramObject);
printOglError("shader.c", 283LL);
glGetObjectParameterivARB((unsigned int)ProgramObject, 35714LL, v8);
func1(ProgramObject);
if ( !v8[0] )
return 0LL;
glUseProgramObjectARB((unsigned int)ProgramObject);
v3 = func0((unsigned int)ProgramObject, "currentTime");
glUniform1fARB(v3, -5.0);
printOglError("shader.c", 298LL);
return 1LL;
}

original_code:
int installParticleShaders(GLcharARB *particleVertex,
                           GLcharARB *particleFragment)
{
    GLint vertCompiled, fragCompiled;
    GLint linked;
    VertexShaderObject = glCreateShaderObjectARB(0x8B31);
    FragmentShaderObject = glCreateShaderObjectARB(0x8B30);
    glShaderSourceARB(VertexShaderObject, 1, &particleVertex, ((void *)0));
    glShaderSourceARB(FragmentShaderObject, 1, &particleFragment, ((void *)0));
    glCompileShaderARB(VertexShaderObject);
    printOglError("shader.c", 251);
    glGetObjectParameterivARB(VertexShaderObject,
                0x8B81, &vertCompiled);
    printInfoLog(VertexShaderObject);
    glCompileShaderARB(FragmentShaderObject);
    printOglError("shader.c", 260);
    glGetObjectParameterivARB(FragmentShaderObject,
                0x8B81, &fragCompiled);
    printInfoLog(FragmentShaderObject);
    if (!vertCompiled || !fragCompiled)
        return 0;
    ProgramObject = glCreateProgramObjectARB();
    glAttachObjectARB(ProgramObject, VertexShaderObject);
    glAttachObjectARB(ProgramObject, FragmentShaderObject);
    glBindAttribLocationARB( ProgramObject, 6, "velocity" );
    glBindAttribLocationARB( ProgramObject, 4, "startTime" );
 glBindAttribLocationARB( ProgramObject, 5, "random" );
    glLinkProgramARB(ProgramObject);
    printOglError("shader.c", 283);
    glGetObjectParameterivARB(ProgramObject,
                0x8B82, &linked);
    printInfoLog(ProgramObject);
    if (!linked)
        return 0;
    glUseProgramObjectARB(ProgramObject);
    glUniform1fARB(getUniLoc(ProgramObject, "currentTime"), -5.0);
    printOglError("shader.c", 298);
    return 1;
}

canonical_original_code:
int installParticleShaders(char *particleVertex, char *particleFragment)
{
    int vertCompiled; int fragCompiled;
    int linked;
    VertexShaderObject = glCreateShaderObjectARB(0x8B31);
    FragmentShaderObject = glCreateShaderObjectARB(0x8B30);
    glShaderSourceARB(VertexShaderObject, 1, &particleVertex, ((void *)0));
    glShaderSourceARB(FragmentShaderObject, 1, &particleFragment, ((void *)0));
    glCompileShaderARB(VertexShaderObject);
    printOglError("shader.c", 251);
    glGetObjectParameterivARB(VertexShaderObject,
                0x8B81, &vertCompiled);
    printInfoLog(VertexShaderObject);
    glCompileShaderARB(FragmentShaderObject);
    printOglError("shader.c", 260);
    glGetObjectParameterivARB(FragmentShaderObject,
                0x8B81, &fragCompiled);
    printInfoLog(FragmentShaderObject);
    if (!vertCompiled || !fragCompiled)
        return 0;
    ProgramObject = glCreateProgramObjectARB();
    glAttachObjectARB(ProgramObject, VertexShaderObject);
    glAttachObjectARB(ProgramObject, FragmentShaderObject);
    glBindAttribLocationARB( ProgramObject, 6, "velocity" );
    glBindAttribLocationARB( ProgramObject, 4, "startTime" );
 glBindAttribLocationARB( ProgramObject, 5, "random" );
    glLinkProgramARB(ProgramObject);
    printOglError("shader.c", 283);
    glGetObjectParameterivARB(ProgramObject,
                0x8B82, &linked);
    printInfoLog(ProgramObject);
    if (!linked)
        return 0;
    glUseProgramObjectARB(ProgramObject);
    glUniform1fARB(getUniLoc(ProgramObject, "currentTime"), -5.0);
    printOglError("shader.c", 298);
    return 1;
}

variable_types:
particleVertex
char *

variable_types:
particleFragment
char *

variable_types: vertCompiled int

variable_types: fragCompiled int

variable_types: linked int


myrandom

decompiled_code:
float __fastcall myrandom(float a1, float a2)
{
return (float)((float)((float)rand() * 4.6566129e-10) * (float)(a2 - a1)) + a1;
}

canonical_decompiled_code:
float __fastcall func0(float a1, float a2)
{
return (float)((float)((float)rand() * 4.6566129e-10) * (float)(a2 - a1)) + a1;
}

original_code:
float myrandom( float low, float high )
{
 float range = high - low;
 float multiplier = ( float ) rand() / 2147483647;
 return range * multiplier + low;
}

canonical_original_code:
float myrandom(float low, float high)
{
 float range = high - low;
 float multiplier = ( float ) rand() / 2147483647;
 return range * multiplier + low;
}

variable_types: low float

variable_types: high float

variable_types: range float

variable_types: multiplier float

return_type: float


fireRed

decompiled_code:
float fireRed()
{
return 1.0 - myrandom(0.0, 0.2);
}

original_code:
float fireRed()
{
 return 1.0 - myrandom( 0.0f, 0.2f );
}


fireGreen

decompiled_code:
float fireGreen()
{
return myrandom(0.0, 0.5);
}

canonical_decompiled_code:
float func2()
{
return func0(0.0, 0.5);
}

original_code:
float fireGreen()
{
 return myrandom( 0.0f, 0.5f );
}


fireBlue

decompiled_code:
double fireBlue()
{
return 0.0;
}

canonical_decompiled_code:
double func3()
{
return 0.0;
}

original_code:
float fireBlue()
{
 return 0.0f;
}

canonical_original_code:
float fireBlue()
{
 return 0.0f;
}


fillRandom

decompiled_code:
void __fastcall fillRandom(int a1)
{
int v1; // er12
__int64 v2; // rbx
__int64 v3; // rbp

v1 = 3 * a1;
v2 = myrandoms;
if ( !myrandoms )
{
myrandoms = (__int64)malloc(4LL * v1);
v2 = myrandoms;
}
v3 = v2 + 4LL * v1;
if ( v1 > 0 )
{
do
{
v2 += 4LL;
*(float *)(v2 - 4) = myrandom(-1.0, 1.0);
}
while ( v3 != v2 );
}
}

canonical_decompiled_code:
void __fastcall func4(int a1)
{
int v1; // er12
__int64 v2; // rbx
__int64 v3; // rbp

v1 = 3 * a1;
v2 = myrandoms;
if ( !myrandoms )
{
myrandoms = (__int64)malloc(4LL * v1);
v2 = myrandoms;
}
v3 = v2 + 4LL * v1;
if ( v1 > 0 )
{
do
{
v2 += 4LL;
*(float *)(v2 - 4) = func0(-1.0, 1.0);
}
while ( v3 != v2 );
}
}

original_code:
void fillRandom( int numPoints )
{
 GLfloat* myrandomPointer;
 int counter;
 if ( myrandoms == ((void *)0) )
 {
  myrandoms = malloc( numPoints * 3 * sizeof( float ) );
 }
 myrandomPointer = myrandoms;
 for ( counter = 0; counter < numPoints * 3; counter++ )
 {
  *myrandomPointer = myrandom( -1.0f, 1.0f );
  myrandomPointer++;
 }
}

canonical_original_code:
void fillRandom(int numPoints)
{
 float *myrandomPointer;
 int counter;
 if ( myrandoms == ((void *)0) )
 {
  myrandoms = malloc( numPoints * 3 * sizeof( float ) );
 }
 myrandomPointer = myrandoms;
 for ( counter = 0; counter < numPoints * 3; counter++ )
 {
  *myrandomPointer = myrandom( -1.0f, 1.0f );
  myrandomPointer++;
 }
}

variable_types: numPoints int

variable_types:
myrandomPointer
float *

variable_types: counter int


createPoints

decompiled_code:
void __fastcall createPoints(int a1)
{
size_t v1; // r12
float *v2; // rbx
__int64 v3; // rbp
__int64 v4; // r12
__int64 v5; // r15
__int64 v6; // r13
double v7; // xmm0_8
float v8; // xmm0_4
double v9; // xmm1_8
float v10; // xmm0_4
float v11; // [rsp+0h] [rbp-58h]
double v12; // [rsp+0h] [rbp-58h]
int v13; // [rsp+Ch] [rbp-4Ch]
double cosx; // [rsp+10h] [rbp-48h] BYREF
double sinx[8]; // [rsp+18h] [rbp-40h] BYREF

if ( vertices )
free(vertices);
v1 = 12LL * a1;
vertices = malloc(v1);
v2 = (float *)vertices;
colors = (__int64)malloc(v1);
v3 = colors;
velocities = (__int64)malloc(v1);
v4 = velocities;
startTimes = (__int64)malloc(4LL * a1);
v5 = startTimes;
if ( a1 > 0 )
{
v6 = startTimes + 4LL * a1;
v7 = fireBlue();
v13 = LODWORD(v7);
do
{
v5 += 4LL;
v2 += 3;
v3 += 12LL;
v4 += 12LL;
v11 = myrandom(0.0, 1.0);
v8 = myrandom(0.0, 360.0);
*(v2 - 3) = 0.0;
v12 = (float)(v11 * 0.40000001);
sincos(v8, sinx, &cosx);
v9 = v12 * cosx;
v10 = sinx[0] * v12;
*(v2 - 2) = v10;
*(float *)&v9 = v9;
*(v2 - 1) = *(float *)&v9;
*(float *)(v3 - 12) = fireRed();
*(float *)(v3 - 8) = fireGreen();
*(_DWORD *)(v3 - 4) = v13;
*(float *)(v4 - 12) = myrandom(2.0, 10.0);
*(float *)(v4 - 8) = myrandom(0.5, 1.0);
*(float *)(v4 - 4) = myrandom(0.5, 1.0);
*(float *)(v5 - 4) = myrandom(0.0, 10.0);
}
while ( v5 != v6 );
}
fillRandom(a1);
}

original_code:
void createPoints( int numPoints )
{
 GLfloat* vertexPointer;
 GLfloat* colorPointer;
 GLfloat* velocityPointer;
 GLfloat* startTimePointer;
 float newRadius;
 float angle;
 GLint counter;
 if ( vertices != ((void *)0) )
 {
  free( vertices );
 }
 vertices = malloc( numPoints * 3 * sizeof( float ) );
 colors = malloc( numPoints * 3 * sizeof( float ) );
 velocities = malloc( numPoints * 3 * sizeof( float ) );
 startTimes = malloc( numPoints * sizeof( float ) );
 vertexPointer = vertices;
 colorPointer = colors;
 velocityPointer = velocities;
 startTimePointer = startTimes;
 for ( counter = 0; counter < numPoints; counter++ )
 {
  newRadius = myrandom( 0.0f, 1.0f ) * emitterRadius;
  angle = myrandom( 0.0f, 360.0f );
  *vertexPointer = 0.0f;
  *( vertexPointer + 1 ) = newRadius * sin( angle );
  *( vertexPointer + 2 ) = newRadius * cos( angle );
  vertexPointer += 3;
  *colorPointer = fireRed();
  *( colorPointer + 1 ) = fireGreen();
  *( colorPointer + 2 ) = fireBlue();
  colorPointer += 3;
  *velocityPointer = myrandom( 2.0f, 10.0f );
  *( velocityPointer + 1 ) = myrandom( 0.5f, 1.0f );
  *( velocityPointer + 2 ) = myrandom( 0.5f, 1.0f );
  velocityPointer += 3;
  *startTimePointer = myrandom( 0.0f, 10.0f );
  startTimePointer++;
 }
 fillRandom( numPoints );
}

canonical_original_code:
void createPoints(int numPoints)
{
 float *vertexPointer;
 float *colorPointer;
 float *velocityPointer;
 float *startTimePointer;
 float newRadius;
 float angle;
 int counter;
 if ( vertices != ((void *)0) )
 {
  free( vertices );
 }
 vertices = malloc( numPoints * 3 * sizeof( float ) );
 colors = malloc( numPoints * 3 * sizeof( float ) );
 velocities = malloc( numPoints * 3 * sizeof( float ) );
 startTimes = malloc( numPoints * sizeof( float ) );
 vertexPointer = vertices;
 colorPointer = colors;
 velocityPointer = velocities;
 startTimePointer = startTimes;
 for ( counter = 0; counter < numPoints; counter++ )
 {
  newRadius = myrandom( 0.0f, 1.0f ) * emitterRadius;
  angle = myrandom( 0.0f, 360.0f );
  *vertexPointer = 0.0f;
  *( vertexPointer + 1 ) = newRadius * sin( angle );
  *( vertexPointer + 2 ) = newRadius * cos( angle );
  vertexPointer += 3;
  *colorPointer = fireRed();
  *( colorPointer + 1 ) = fireGreen();
  *( colorPointer + 2 ) = fireBlue();
  colorPointer += 3;
  *velocityPointer = myrandom( 2.0f, 10.0f );
  *( velocityPointer + 1 ) = myrandom( 0.5f, 1.0f );
  *( velocityPointer + 2 ) = myrandom( 0.5f, 1.0f );
  velocityPointer += 3;
  *startTimePointer = myrandom( 0.0f, 10.0f );
  startTimePointer++;
 }
 fillRandom( numPoints );
}

variable_types:
vertexPointer
float *

variable_types:
colorPointer
float *

variable_types:
velocityPointer
float *

variable_types:
startTimePointer
float *

variable_types: newRadius float

variable_types: angle float


drawPoints

decompiled_code:
__int64 drawPoints()
{
fillRandom(50000);
glPointSize(2.0);
glVertexPointer(3LL, 5126LL, 0LL, vertices);
glColorPointer(3LL, 5126LL, 0LL, colors);
glVertexAttribPointerARB(6LL, 3LL, 5126LL, 0LL, 0LL, velocities);
glVertexAttribPointerARB(4LL, 1LL, 5126LL, 0LL, 0LL, startTimes);
glVertexAttribPointerARB(5LL, 3LL, 5126LL, 0LL, 0LL, myrandoms);
glEnableClientState(32884LL);
glEnableClientState(32886LL);
glEnableVertexAttribArrayARB(6LL);
glEnableVertexAttribArrayARB(4LL);
glEnableVertexAttribArrayARB(5LL);
glDrawArrays(0LL, 0LL, 50000LL);
glDisableClientState(32884LL);
glDisableClientState(32886LL);
glDisableVertexAttribArrayARB(6LL);
glDisableVertexAttribArrayARB(4LL);
return glDisableVertexAttribArrayARB(5LL);
}

canonical_decompiled_code:
__int64 func6()
{
func4(50000);
glPointSize(2.0);
glVertexPointer(3LL, 5126LL, 0LL, vertices);
glColorPointer(3LL, 5126LL, 0LL, colors);
glVertexAttribPointerARB(6LL, 3LL, 5126LL, 0LL, 0LL, velocities);
glVertexAttribPointerARB(4LL, 1LL, 5126LL, 0LL, 0LL, startTimes);
glVertexAttribPointerARB(5LL, 3LL, 5126LL, 0LL, 0LL, myrandoms);
glEnableClientState(32884LL);
glEnableClientState(32886LL);
glEnableVertexAttribArrayARB(6LL);
glEnableVertexAttribArrayARB(4LL);
glEnableVertexAttribArrayARB(5LL);
glDrawArrays(0LL, 0LL, 50000LL);
glDisableClientState(32884LL);
glDisableClientState(32886LL);
glDisableVertexAttribArrayARB(6LL);
glDisableVertexAttribArrayARB(4LL);
return glDisableVertexAttribArrayARB(5LL);
}

original_code:
void drawPoints()
{
 fillRandom( numParticles );
 glPointSize( 2.0 );
 glVertexPointer( 3, 0x1406, 0, vertices );
 glColorPointer( 3, 0x1406, 0, colors );
 glVertexAttribPointerARB( 6, 3, 0x1406, 0, 0, velocities );
 glVertexAttribPointerARB( 4, 1, 0x1406, 0, 0, startTimes );
 glVertexAttribPointerARB( 5, 3, 0x1406, 0, 0, myrandoms );
 glEnableClientState( 0x8074 );
 glEnableClientState( 0x8076 );
 glEnableVertexAttribArrayARB( 6 );
 glEnableVertexAttribArrayARB( 4 );
 glEnableVertexAttribArrayARB( 5 );
 glDrawArrays( 0x0000, 0, numParticles );
 glDisableClientState( 0x8074 );
 glDisableClientState( 0x8076 );
 glDisableVertexAttribArrayARB( 6 );
 glDisableVertexAttribArrayARB( 4 );
 glDisableVertexAttribArrayARB( 5 );
}


decompiled_code:
__int64 __fastcall md_get(const char *a1, void *a2)
{
return tt_get(a1, a2, 1);
}

canonical_decompiled_code:
__int64 __fastcall func4(const char *a1, void *a2)
{
return func1(a1, a2, 1);
}

original_code:
u32 md_get(u8 * path,u8 *md)
{
 return tt_get(path,md,META_DATA);
}

canonical_original_code:
unsigned int md_get(unsigned char *path, unsigned char *md)
{
 return tt_get(path,md,META_DATA);
}

variable_types:
path
unsigned char *

variable_types:
md
unsigned char *

return_type: unsigned int


decompiled_code:
__int64 __fastcall md_out(const char *a1)
{
return tt_out(a1, 1);
}

canonical_decompiled_code:
__int64 __fastcall func5(const char *a1)
{
return func2(a1, 1);
}

original_code:
u32 md_out(u8 *path)
{
 return tt_out(path,META_DATA);
}

canonical_original_code:
unsigned int md_out(unsigned char *path)
{
 return tt_out(path,META_DATA);
}


decompiled_code:
__int64 __fastcall md_put(const char *a1, __int64 a2)
{
return tt_put(a1, a2, 0xC20u, 1);
}

canonical_decompiled_code:
__int64 __fastcall func6(const char *a1, __int64 a2)
{
return func3(a1, a2, 0xC20u, 1);
}

original_code:
u32 md_put(u8 *path,u8 *md)
{
 return tt_put(path,md,sizeof(Meta_Data),META_DATA);
}

canonical_original_code:
unsigned int md_put(unsigned char *path, unsigned char *md)
{
 return tt_put(path,md,sizeof(Meta_Data),META_DATA);
}


decompiled_code:
__int64 __fastcall ion_get(const char *a1, void *a2)
{
return tt_get(a1, a2, 2);
}

canonical_decompiled_code:
__int64 __fastcall func7(const char *a1, void *a2)
{
return func1(a1, a2, 2);
}

original_code:
u32 ion_get(u8 * path,u8 *ion)
{
 return tt_get(path,ion,IO_NODE);
}

canonical_original_code:
unsigned int ion_get(unsigned char *path, unsigned char *ion)
{
 return tt_get(path,ion,IO_NODE);
}

variable_types:
ion
unsigned char *


decompiled_code:
__int64 __fastcall ion_out(const char *a1)
{
return tt_out(a1, 2);
}

canonical_decompiled_code:
__int64 __fastcall func8(const char *a1)
{
return func2(a1, 2);
}

original_code:
u32 ion_out(u8 *path)
{
 return tt_out(path,IO_NODE);
}

canonical_original_code:
unsigned int ion_out(unsigned char *path)
{
 return tt_out(path,IO_NODE);
}


decompiled_code:
__int64 __fastcall ion_put(const char *a1, __int64 a2)
{
return tt_put(a1, a2, 0x220u, 2);
}

canonical_decompiled_code:
__int64 __fastcall func9(const char *a1, __int64 a2)
{
return func3(a1, a2, 0x220u, 2);
}

original_code:
u32 ion_put(u8 *path,u8 *ion)
{
 return tt_put(path,ion,sizeof(IO_Node),IO_NODE);
}

canonical_original_code:
unsigned int ion_put(unsigned char *path, unsigned char *ion)
{
 return tt_put(path,ion,sizeof(IO_Node),IO_NODE);
}


decompiled_code:
__int64 __fastcall get_db_port(int a1)
{
if ( (unsigned int)(a1 - 1) <= 4 )
return (unsigned int)(a1 + 11210);
fwrite("UNRECOGNIZED VALUE TYPE!\n", 1uLL, 0x19uLL, stderr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
if ( (unsigned int)(a1 - 1) <= 4 )
return (unsigned int)(a1 + 11210);
fwrite("UNRECOGNIZED VALUE TYPE!\n", 1uLL, 0x19uLL, stderr);
return 0LL;
}

original_code:
u32 get_db_port(value_t vt)
{
 u32 db_port;
 switch(vt){
  case META_DATA:
   db_port = 11211;
   break;
  case IO_NODE:
   db_port = 11212;
   break;
  case FILE_NODE:
   db_port = 11213;
   break;
  case SWAP_NODE:
   db_port = 11214;
   break;
  case IO_DATA:
   db_port = 11215;
   break;
  default:
   fprintf(stderr,"UNRECOGNIZED VALUE TYPE!\n");
   db_port = 0;
   break;
 }
 return db_port;
}

canonical_original_code:
unsigned int get_db_port(enum value_t vt)
{
 unsigned int db_port;
 switch(vt){
  case META_DATA:
   db_port = 11211;
   break;
  case IO_NODE:
   db_port = 11212;
   break;
  case FILE_NODE:
   db_port = 11213;
   break;
  case SWAP_NODE:
   db_port = 11214;
   break;
  case IO_DATA:
   db_port = 11215;
   break;
  default:
   fprintf(stderr,"UNRECOGNIZED VALUE TYPE!\n");
   db_port = 0;
   break;
 }
 return db_port;
}

variable_types: enum value_t { META_DATA=1, IO_NODE=2, FILE_NODE=3, SWAP_NODE=4, IO_DATA=5 }


decompiled_code:
__int64 __fastcall tt_get(const char *a1, void *a2, int a3)
{
unsigned int v4; // ebx
__int64 v5; // rbp
__int64 v6; // r12
unsigned int v7; // eax
const char *v8; // rax
__int64 v9; // rdx
unsigned int v10; // er12
const void *v12; // r12
void *v13; // rdi
unsigned int v14; // eax
const char *v15; // rax
size_t n[5]; // [rsp+Ch] [rbp-2Ch] BYREF

v4 = strlen(a1);
v5 = tcrdbnew();
v6 = (unsigned int)get_db_port(a3);
printf("db_port -- %d\n", v6);
if ( (unsigned __int8)tcrdbopen(v5, "192.168.0.18", (unsigned int)v6) )
{
v12 = (const void *)tcrdbget(v5, a1, v4, n);
if ( v12 )
{
printf("(key=%s) tt_get success!\n", a1);
printf("%d bytes read\n", LODWORD(n[0]));
memcpy(a2, v12, LODWORD(n[0]));
v13 = (void *)v12;
v10 = 0;
free(v13);
}
else
{
v10 = 2;
v14 = tcrdbecode(v5);
v15 = (const char *)tcrdberrmsg(v14);
fprintf(stderr, "(key=%s) tt_get error:%s\n", a1, v15);
}
}
else
{
v7 = tcrdbecode(v5);
v8 = (const char *)tcrdberrmsg(v7);
v9 = (unsigned int)v6;
v10 = 1;
fprintf(stderr, "tt_get:open %d error -- %s\n", v9, v8);
}
tcrdbdel(v5);
return v10;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1, void *a2, int a3)
{
unsigned int v4; // ebx
__int64 v5; // rbp
__int64 v6; // r12
unsigned int v7; // eax
const char *v8; // rax
__int64 v9; // rdx
unsigned int v10; // er12
const void *v12; // r12
void *v13; // rdi
unsigned int v14; // eax
const char *v15; // rax
size_t n[5]; // [rsp+Ch] [rbp-2Ch] BYREF

v4 = strlen(a1);
v5 = tcrdbnew();
v6 = (unsigned int)func0(a3);
printf("db_port -- %d\n", v6);
if ( (unsigned __int8)tcrdbopen(v5, "192.168.0.18", (unsigned int)v6) )
{
v12 = (const void *)tcrdbget(v5, a1, v4, n);
if ( v12 )
{
printf("(key=%s) tt_get success!\n", a1);
printf("%d bytes read\n", LODWORD(n[0]));
memcpy(a2, v12, LODWORD(n[0]));
v13 = (void *)v12;
v10 = 0;
free(v13);
}
else
{
v10 = 2;
v14 = tcrdbecode(v5);
v15 = (const char *)tcrdberrmsg(v14);
fprintf(stderr, "(key=%s) tt_get error:%s\n", a1, v15);
}
}
else
{
v7 = tcrdbecode(v5);
v8 = (const char *)tcrdberrmsg(v7);
v9 = (unsigned int)v6;
v10 = 1;
fprintf(stderr, "tt_get:open %d error -- %s\n", v9, v8);
}
tcrdbdel(v5);
return v10;
}

original_code:
u32 tt_get(u8 *key,u8 *zv,value_t vt)
{
 u32 ecode;
 u32 nv;
 u32 rt = 0;
 u32 nk = strlen(key);
 u8 * value;
 TCRDB * rdb = tcrdbnew();
 u32 db_port = get_db_port(vt);
 printf("db_port -- %d\n",db_port);
 if(!tcrdbopen(rdb,"192.168.0.18",db_port)){
  ecode = tcrdbecode(rdb);
  fprintf(stderr,"tt_get:open %d error -- %s\n",db_port,tcrdberrmsg(ecode));
  rt = 1;
 }else{
     if((value = tcrdbget(rdb,key,nk,&nv)) == ((void *)0)){
      ecode = tcrdbecode(rdb);
      fprintf(stderr,"(key=%s) tt_get error:%s\n",key,tcrdberrmsg(ecode));
      rt = 2;
     }else{
      printf("(key=%s) tt_get success!\n",key);
   printf("%d bytes read\n",nv);
   memcpy(zv,value,nv);
   free(value);
     }
 }
 tcrdbdel(rdb);
 return rt;
}

canonical_original_code:
unsigned int tt_get(unsigned char *key, unsigned char *zv, enum value_t vt)
{
 unsigned int ecode;
 unsigned int nv;
 unsigned int rt = 0;
 unsigned int nk = strlen(key);
 unsigned char *value;
 struct TCRDB *rdb = tcrdbnew();
 unsigned int db_port = get_db_port(vt);
 printf("db_port -- %d\n",db_port);
 if(!tcrdbopen(rdb,"192.168.0.18",db_port)){
  ecode = tcrdbecode(rdb);
  fprintf(stderr,"tt_get:open %d error -- %s\n",db_port,tcrdberrmsg(ecode));
  rt = 1;
 }else{
     if((value = tcrdbget(rdb,key,nk,&nv)) == ((void *)0)){
      ecode = tcrdbecode(rdb);
      fprintf(stderr,"(key=%s) tt_get error:%s\n",key,tcrdberrmsg(ecode));
      rt = 2;
     }else{
      printf("(key=%s) tt_get success!\n",key);
   printf("%d bytes read\n",nv);
   memcpy(zv,value,nv);
   free(value);
     }
 }
 tcrdbdel(rdb);
 return rt;
}

variable_types:
key
unsigned char *

variable_types:
zv
unsigned char *

variable_types:
ecode
unsigned int

variable_types:
nv
unsigned int

variable_types:
rt
unsigned int

variable_types:
nk
unsigned int

variable_types:
value
unsigned char *

variable_types: struct TCRDB { union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mmtx; unsigned int eckey; char *host; int port; char *expr; int fd; struct TTSOCK { int fd; char buf[65536]; char *rp; char *ep; _Bool end; double to; double dl; } *sock; double timeout; int opts; } *

user_defined_types: enum value_t { META_DATA=1, IO_NODE=2, FILE_NODE=3, SWAP_NODE=4, IO_DATA=5 }

user_defined_types: struct TCRDB { union pthread_mutex_t mmtx; unsigned int eckey; char *host; int port; char *expr; int fd; struct TTSOCK *sock; double timeout; int opts; }

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


decompiled_code:
__int64 __fastcall tt_out(const char *a1, int a2)
{
__int64 v2; // rbp
__int64 v3; // r12
unsigned int v4; // eax
const char *v5; // rax
__int64 v6; // rdx
unsigned int v7; // er12
unsigned int v9; // eax
const char *v10; // rax

v2 = tcrdbnew();
v3 = (unsigned int)get_db_port(a2);
printf("db_port -- %d\n", v3);
if ( (unsigned __int8)tcrdbopen(v2, "192.168.0.18", (unsigned int)v3) )
{
if ( (unsigned __int8)tcrdbout2(v2, a1) )
{
v7 = 0;
printf("(key=%s) tt_out success!\n", a1);
}
else
{
v7 = 2;
v9 = tcrdbecode(v2);
v10 = (const char *)tcrdberrmsg(v9);
fprintf(stderr, "(key=%s) tt_out error:%s\n", a1, v10);
}
}
else
{
v4 = tcrdbecode(v2);
v5 = (const char *)tcrdberrmsg(v4);
v6 = (unsigned int)v3;
v7 = 1;
fprintf(stderr, "tt_out:open %d error -- %s\n", v6, v5);
}
tcrdbdel(v2);
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1, int a2)
{
__int64 v2; // rbp
__int64 v3; // r12
unsigned int v4; // eax
const char *v5; // rax
__int64 v6; // rdx
unsigned int v7; // er12
unsigned int v9; // eax
const char *v10; // rax

v2 = tcrdbnew();
v3 = (unsigned int)func0(a2);
printf("db_port -- %d\n", v3);
if ( (unsigned __int8)tcrdbopen(v2, "192.168.0.18", (unsigned int)v3) )
{
if ( (unsigned __int8)tcrdbout2(v2, a1) )
{
v7 = 0;
printf("(key=%s) tt_out success!\n", a1);
}
else
{
v7 = 2;
v9 = tcrdbecode(v2);
v10 = (const char *)tcrdberrmsg(v9);
fprintf(stderr, "(key=%s) tt_out error:%s\n", a1, v10);
}
}
else
{
v4 = tcrdbecode(v2);
v5 = (const char *)tcrdberrmsg(v4);
v6 = (unsigned int)v3;
v7 = 1;
fprintf(stderr, "tt_out:open %d error -- %s\n", v6, v5);
}
tcrdbdel(v2);
return v7;
}

original_code:
u32 tt_out(u8 *key,value_t vt)
{
 u32 ecode;
 u32 rt = 0;
 TCRDB * rdb = tcrdbnew();
 u32 db_port = get_db_port(vt);
 printf("db_port -- %d\n",db_port);
 if(!tcrdbopen(rdb,"192.168.0.18",db_port)){
  ecode = tcrdbecode(rdb);
  fprintf(stderr,"tt_out:open %d error -- %s\n",db_port,tcrdberrmsg(ecode));
  rt = 1;
 }else{
     if(tcrdbout2(rdb,key)){
         printf("(key=%s) tt_out success!\n",key);
     }else{
         ecode = tcrdbecode(rdb);
      fprintf(stderr,"(key=%s) tt_out error:%s\n",key,tcrdberrmsg(ecode));
      rt = 2;
     }
 }
 tcrdbdel(rdb);
 return rt;
}

canonical_original_code:
unsigned int tt_out(unsigned char *key, enum value_t vt)
{
 unsigned int ecode;
 unsigned int rt = 0;
 struct TCRDB *rdb = tcrdbnew();
 unsigned int db_port = get_db_port(vt);
 printf("db_port -- %d\n",db_port);
 if(!tcrdbopen(rdb,"192.168.0.18",db_port)){
  ecode = tcrdbecode(rdb);
  fprintf(stderr,"tt_out:open %d error -- %s\n",db_port,tcrdberrmsg(ecode));
  rt = 1;
 }else{
     if(tcrdbout2(rdb,key)){
         printf("(key=%s) tt_out success!\n",key);
     }else{
         ecode = tcrdbecode(rdb);
      fprintf(stderr,"(key=%s) tt_out error:%s\n",key,tcrdberrmsg(ecode));
      rt = 2;
     }
 }
 tcrdbdel(rdb);
 return rt;
}

user_defined_types: struct TTSOCK { int fd; char buf[65536]; char *rp; char *ep; _Bool end; double to; double dl; }

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


decompiled_code:
__int64 __fastcall tt_put(const char *a1, __int64 a2, unsigned int a3, int a4)
{
unsigned int v6; // ebx
__int64 v7; // rbp
__int64 v8; // r12
unsigned int v9; // eax
const char *v10; // rax
__int64 v11; // rdx
unsigned int v12; // er12
unsigned int v14; // eax
const char *v15; // rax

v6 = strlen(a1);
v7 = tcrdbnew();
v8 = (unsigned int)get_db_port(a4);
printf("db_port -- %d\n", v8);
if ( (unsigned __int8)tcrdbopen(v7, "192.168.0.18", (unsigned int)v8) )
{
if ( (unsigned __int8)tcrdbput(v7, a1, v6, a2, a3) )
{
v12 = 0;
printf("(key=%s) tt_put success!\n", a1);
}
else
{
v12 = 2;
v14 = tcrdbecode(v7);
v15 = (const char *)tcrdberrmsg(v14);
fprintf(stderr, "(key=%s) tt_put error:%s\n", a1, v15);
}
}
else
{
v9 = tcrdbecode(v7);
v10 = (const char *)tcrdberrmsg(v9);
v11 = (unsigned int)v8;
v12 = 1;
fprintf(stderr, "tt_put:open %d error -- %s\n", v11, v10);
}
tcrdbdel(v7);
return v12;
}

canonical_decompiled_code:
__int64 __fastcall func3(const char *a1, __int64 a2, unsigned int a3, int a4)
{
unsigned int v6; // ebx
__int64 v7; // rbp
__int64 v8; // r12
unsigned int v9; // eax
const char *v10; // rax
__int64 v11; // rdx
unsigned int v12; // er12
unsigned int v14; // eax
const char *v15; // rax

v6 = strlen(a1);
v7 = tcrdbnew();
v8 = (unsigned int)func0(a4);
printf("db_port -- %d\n", v8);
if ( (unsigned __int8)tcrdbopen(v7, "192.168.0.18", (unsigned int)v8) )
{
if ( (unsigned __int8)tcrdbput(v7, a1, v6, a2, a3) )
{
v12 = 0;
printf("(key=%s) tt_put success!\n", a1);
}
else
{
v12 = 2;
v14 = tcrdbecode(v7);
v15 = (const char *)tcrdberrmsg(v14);
fprintf(stderr, "(key=%s) tt_put error:%s\n", a1, v15);
}
}
else
{
v9 = tcrdbecode(v7);
v10 = (const char *)tcrdberrmsg(v9);
v11 = (unsigned int)v8;
v12 = 1;
fprintf(stderr, "tt_put:open %d error -- %s\n", v11, v10);
}
tcrdbdel(v7);
return v12;
}

original_code:
u32 tt_put(u8 * key,u8 *zv,u32 nv,value_t vt)
{
 u32 ecode;
 u32 rt = 0;
 u32 nk = strlen(key);
 TCRDB * rdb = tcrdbnew();
 u32 db_port = get_db_port(vt);
 printf("db_port -- %d\n",db_port);
 if(!tcrdbopen(rdb,"192.168.0.18",db_port)){
  ecode = tcrdbecode(rdb);
  fprintf(stderr,"tt_put:open %d error -- %s\n",db_port,tcrdberrmsg(ecode));
  rt = 1;
 }else{
     if(!tcrdbput(rdb,key,nk,zv,nv)){
      ecode = tcrdbecode(rdb);
      fprintf(stderr,"(key=%s) tt_put error:%s\n",key,tcrdberrmsg(ecode));
      rt = 2;
     }else{
   printf("(key=%s) tt_put success!\n",key);
     }
 }
 tcrdbdel(rdb);
 return rt;
}

canonical_original_code:
unsigned int tt_put(unsigned char *key, unsigned char *zv, unsigned int nv, enum value_t vt)
{
 unsigned int ecode;
 unsigned int rt = 0;
 unsigned int nk = strlen(key);
 struct TCRDB *rdb = tcrdbnew();
 unsigned int db_port = get_db_port(vt);
 printf("db_port -- %d\n",db_port);
 if(!tcrdbopen(rdb,"192.168.0.18",db_port)){
  ecode = tcrdbecode(rdb);
  fprintf(stderr,"tt_put:open %d error -- %s\n",db_port,tcrdberrmsg(ecode));
  rt = 1;
 }else{
     if(!tcrdbput(rdb,key,nk,zv,nv)){
      ecode = tcrdbecode(rdb);
      fprintf(stderr,"(key=%s) tt_put error:%s\n",key,tcrdberrmsg(ecode));
      rt = 2;
     }else{
   printf("(key=%s) tt_put success!\n",key);
     }
 }
 tcrdbdel(rdb);
 return rt;
}


decompiled_code:
__int64 __fastcall iod_get(const char *a1, unsigned int *a2)
{
unsigned int v2; // er14
__int64 v3; // rbp
__int64 v4; // r13
__int64 v5; // r13
__int64 result; // rax
unsigned int v7; // eax
const char *v8; // rax
unsigned int v9; // eax
const char *v10; // rax

v2 = strlen(a1);
v3 = tcrdbnew();
v4 = (unsigned int)get_db_port(5);
printf("db_port -- %d\n", v4);
if ( (unsigned __int8)tcrdbopen(v3, "192.168.0.18", (unsigned int)v4) )
{
v5 = tcrdbget(v3, a1, v2, a2);
if ( v5 )
{
printf("(key=%s) iod_get success!\n", a1);
printf("%d bytes read\n", *a2);
tcrdbdel(v3);
}
else
{
v9 = tcrdbecode(v3);
v10 = (const char *)tcrdberrmsg(v9);
fprintf(stderr, "(key=%s) iod_get error:%s\n", a1, v10);
}
result = v5;
}
else
{
v7 = tcrdbecode(v3);
v8 = (const char *)tcrdberrmsg(v7);
fprintf(stderr, "iod_get:open %d error -- %s\n", (unsigned int)v4, v8);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(const char *a1, unsigned int *a2)
{
unsigned int v2; // er14
__int64 v3; // rbp
__int64 v4; // r13
__int64 v5; // r13
__int64 result; // rax
unsigned int v7; // eax
const char *v8; // rax
unsigned int v9; // eax
const char *v10; // rax

v2 = strlen(a1);
v3 = tcrdbnew();
v4 = (unsigned int)func0(5);
printf("db_port -- %d\n", v4);
if ( (unsigned __int8)tcrdbopen(v3, "192.168.0.18", (unsigned int)v4) )
{
v5 = tcrdbget(v3, a1, v2, a2);
if ( v5 )
{
printf("(key=%s) iod_get success!\n", a1);
printf("%d bytes read\n", *a2);
tcrdbdel(v3);
}
else
{
v9 = tcrdbecode(v3);
v10 = (const char *)tcrdberrmsg(v9);
fprintf(stderr, "(key=%s) iod_get error:%s\n", a1, v10);
}
result = v5;
}
else
{
v7 = tcrdbecode(v3);
v8 = (const char *)tcrdberrmsg(v7);
fprintf(stderr, "iod_get:open %d error -- %s\n", (unsigned int)v4, v8);
result = 0LL;
}
return result;
}

original_code:
u8 *iod_get(u8 *key,u32 *nv)
{
 u32 ecode;
 u32 nk = strlen(key);
 u8 *value;
 TCRDB * rdb = tcrdbnew();
 u32 db_port = get_db_port(IO_DATA);
 printf("db_port -- %d\n",db_port);
 if(!tcrdbopen(rdb,"192.168.0.18",db_port)){
  ecode = tcrdbecode(rdb);
  fprintf(stderr,"iod_get:open %d error -- %s\n",db_port,tcrdberrmsg(ecode));
  return ((void *)0);
 }else{
     if((value = tcrdbget(rdb,key,nk,nv)) == ((void *)0)){
      ecode = tcrdbecode(rdb);
      fprintf(stderr,"(key=%s) iod_get error:%s\n",key,tcrdberrmsg(ecode));
   return ((void *)0);
  }else{
      printf("(key=%s) iod_get success!\n",key);
   printf("%d bytes read\n",*nv);
     }
 }
 tcrdbdel(rdb);
 return value;
}

canonical_original_code:
unsigned char *iod_get(unsigned char *key, unsigned int *nv)
{
 unsigned int ecode;
 unsigned int nk = strlen(key);
 unsigned char *value;
 struct TCRDB *rdb = tcrdbnew();
 unsigned int db_port = get_db_port(IO_DATA);
 printf("db_port -- %d\n",db_port);
 if(!tcrdbopen(rdb,"192.168.0.18",db_port)){
  ecode = tcrdbecode(rdb);
  fprintf(stderr,"iod_get:open %d error -- %s\n",db_port,tcrdberrmsg(ecode));
  return ((void *)0);
 }else{
     if((value = tcrdbget(rdb,key,nk,nv)) == ((void *)0)){
      ecode = tcrdbecode(rdb);
      fprintf(stderr,"(key=%s) iod_get error:%s\n",key,tcrdberrmsg(ecode));
   return ((void *)0);
  }else{
      printf("(key=%s) iod_get success!\n",key);
   printf("%d bytes read\n",*nv);
     }
 }
 tcrdbdel(rdb);
 return value;
}

variable_types:
nv
unsigned int *

return_type: unsigned char *


decompiled_code:
__int64 __fastcall iod_out(const char *a1)
{
return tt_out(a1, 5);
}

canonical_decompiled_code:
__int64 __fastcall func11(const char *a1)
{
return func2(a1, 5);
}

original_code:
u32 iod_out(u8 *key)
{
 return tt_out(key,IO_DATA);
}

canonical_original_code:
unsigned int iod_out(unsigned char *key)
{
 return tt_out(key,IO_DATA);
}


decompiled_code:
__int64 __fastcall iod_put(const char *a1, __int64 a2, unsigned int a3)
{
return tt_put(a1, a2, a3, 5);
}

canonical_decompiled_code:
__int64 __fastcall func12(const char *a1, __int64 a2, unsigned int a3)
{
return func3(a1, a2, a3, 5);
}

original_code:
u32 iod_put(u8 *key,u8 *value, u32 count)
{
 return tt_put(key,value,count,IO_DATA);
}

canonical_original_code:
unsigned int iod_put(unsigned char *key, unsigned char *value, unsigned int count)
{
 return tt_put(key,value,count,IO_DATA);
}

variable_types:
count
unsigned int


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

result = 0LL;
memset(&mutex_hash, 0, 0x328uLL);
return result;
}

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

result = 0LL;
memset(&mutex_hash, 0, 0x328uLL);
return result;
}

original_code:
int mutex_hash_init()
{
 int i;
 for(i = 0;i < 101;i++)
 {
  mutex_hash[i] = (zz_mutex*)0;
 }
 return 0;
}

canonical_original_code:
int mutex_hash_init()
{
 int i;
 for(i = 0;i < 101;i++)
 {
  mutex_hash[i] = (struct _mutex *)0;
 }
 return 0;
}

variable_types: i int

user_defined_types: struct _mutex { int count; union pthread_mutex_t p_mutex; char file_name[260]; struct _mutex *pre; struct _mutex *next; }


decompiled_code:
__int64 show_mutex_hash()
{
unsigned int v0; // er14
__int64 i; // rbp
const char *v2; // rbx
unsigned int v3; // er12

v0 = pthread_mutex_lock(&glob_mutex);
if ( v0 )
{
v0 = 1;
perror("glob_mutex thread_mutex_lock");
}
for ( i = 0LL; i != 101; ++i )
{
while ( 1 )
{
v2 = (const char *)mutex_hash[i];
if ( v2 )
break;
if ( ++i == 101 )
goto LABEL_9;
}
v3 = 0;
printf("--------Hash%3d ---------\n", (unsigned int)i);
do
{
++v3;
printf(" %3d %s\n", *(unsigned int *)v2, v2 + 48);
v2 = (const char *)*((_QWORD *)v2 + 40);
}
while ( v2 );
printf("--------Hash%3d over---len%3d------\n", (unsigned int)i, v3);
}
LABEL_9:
if ( !pthread_mutex_unlock(&glob_mutex) )
return v0;
perror("glob_mutex thread_mutex_unlock");
return 2LL;
}

canonical_decompiled_code:
__int64 func2()
{
unsigned int v0; // er14
__int64 i; // rbp
const char *v2; // rbx
unsigned int v3; // er12

v0 = pthread_mutex_lock(&glob_mutex);
if ( v0 )
{
v0 = 1;
perror("glob_mutex thread_mutex_lock");
}
for ( i = 0LL; i != 101; ++i )
{
while ( 1 )
{
v2 = (const char *)mutex_hash[i];
if ( v2 )
break;
if ( ++i == 101 )
goto LABEL_9;
}
v3 = 0;
printf("--------Hash%3d ---------\n", (unsigned int)i);
do
{
++v3;
printf(" %3d %s\n", *(unsigned int *)v2, v2 + 48);
v2 = (const char *)*((_QWORD *)v2 + 40);
}
while ( v2 );
printf("--------Hash%3d over---len%3d------\n", (unsigned int)i, v3);
}
LABEL_9:
if ( !pthread_mutex_unlock(&glob_mutex) )
return v0;
perror("glob_mutex thread_mutex_unlock");
return 2LL;
}

original_code:
int show_mutex_hash()
{
 int r = 0;
 int i,hash_len;
 zz_mutex * my_mutex;
 if(pthread_mutex_lock(&glob_mutex) != 0)
 {
  r = 1;
  perror("glob_mutex thread_mutex_lock");
 }
 for(i = 0;i < 101;i++)
 {
  if((my_mutex = mutex_hash[i]) == (zz_mutex*)0){continue;}
  printf("--------Hash%3d ---------\n",i);
  hash_len = 0;
  while(my_mutex)
  {
   hash_len++;
   printf("  %3d   %s\n",my_mutex->count,my_mutex->file_name);
   my_mutex = my_mutex->next;
  }
  printf("--------Hash%3d over---len%3d------\n",i,hash_len);
 }
 if(pthread_mutex_unlock(&glob_mutex) != 0)
 {
  r = 2;
  perror("glob_mutex thread_mutex_unlock");
 }
 return r;
}

canonical_original_code:
int show_mutex_hash()
{
 int r = 0;
 int i; int hash_len;
 struct _mutex *my_mutex;
 if(pthread_mutex_lock(&glob_mutex) != 0)
 {
  r = 1;
  perror("glob_mutex thread_mutex_lock");
 }
 for(i = 0;i < 101;i++)
 {
  if((my_mutex = mutex_hash[i]) == (struct _mutex *)0){continue;}
  printf("--------Hash%3d ---------\n",i);
  hash_len = 0;
  while(my_mutex)
  {
   hash_len++;
   printf("  %3d   %s\n",my_mutex->count,my_mutex->file_name);
   my_mutex = my_mutex->next;
  }
  printf("--------Hash%3d over---len%3d------\n",i,hash_len);
 }
 if(pthread_mutex_unlock(&glob_mutex) != 0)
 {
  r = 2;
  perror("glob_mutex thread_mutex_unlock");
 }
 return r;
}

variable_types: r int

variable_types: struct _mutex { int count; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } p_mutex; char file_name[260]; struct _mutex *pre; struct _mutex *next; } *


decompiled_code:
char *alloc_zz_mutex()
{
char *v0; // r12

v0 = (char *)malloc(0x148uLL);
if ( !pthread_mutex_init((pthread_mutex_t *)(v0 + 8), 0LL) )
return v0;
perror("pthread_mutex initialize fail");
free(v0);
return 0LL;
}

canonical_decompiled_code:
char *func3()
{
char *v0; // r12

v0 = (char *)malloc(0x148uLL);
if ( !pthread_mutex_init((pthread_mutex_t *)(v0 + 8), 0LL) )
return v0;
perror("pthread_mutex initialize fail");
free(v0);
return 0LL;
}

original_code:
zz_mutex * alloc_zz_mutex()
{
 zz_mutex * mtx = (zz_mutex*)malloc(sizeof(zz_mutex));
 if(pthread_mutex_init(&mtx->p_mutex,((void *)0)) != 0)
 {
  perror("pthread_mutex initialize fail");
  free(mtx);
  mtx = (zz_mutex*)0;
 }
 return mtx;
}

canonical_original_code:
struct _mutex *alloc_zz_mutex()
{
 struct _mutex *mtx = (zz_mutex*)malloc(sizeof(zz_mutex));
 if(pthread_mutex_init(&mtx->p_mutex,((void *)0)) != 0)
 {
  perror("pthread_mutex initialize fail");
  free(mtx);
  mtx = (struct _mutex *)0;
 }
 return mtx;
}

return_type: struct _mutex { int count; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } p_mutex; char file_name[260]; struct _mutex *pre; struct _mutex *next; } *


decompiled_code:
__int64 __fastcall free_zz_mutex(void *ptr)
{
unsigned int v1; // er12

v1 = pthread_mutex_destroy((pthread_mutex_t *)((char *)ptr + 8));
if ( v1 )
{
v1 = 1;
perror("pthread_mutex_destroy");
}
free(ptr);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func4(void *ptr)
{
unsigned int v1; // er12

v1 = pthread_mutex_destroy((pthread_mutex_t *)((char *)ptr + 8));
if ( v1 )
{
v1 = 1;
perror("pthread_mutex_destroy");
}
free(ptr);
return v1;
}

original_code:
int free_zz_mutex(zz_mutex * mtx)
{
 int r = 0;
 if(pthread_mutex_destroy(&mtx->p_mutex) != 0)
 {
  perror("pthread_mutex_destroy");
  r = 1;
 }
 free(mtx);
 return r;
}

canonical_original_code:
int free_zz_mutex(struct _mutex *mtx)
{
 int r = 0;
 if(pthread_mutex_destroy(&mtx->p_mutex) != 0)
 {
  perror("pthread_mutex_destroy");
  r = 1;
 }
 free(mtx);
 return r;
}


decompiled_code:
char *__fastcall get_zz_mutex(char *src, unsigned __int8 a2)
{
__int64 v2; // r15
char *v3; // r12
__int64 v5; // rax

v2 = (unsigned int)hash_func();
v3 = (char *)mutex_hash[v2];
if ( pthread_mutex_lock(&glob_mutex) )
perror("glob_mutex thread_mutex_lock");
puts("now traverse hash_chain");
if ( v3 )
{
while ( 1 )
{
printf("count -- %d file_name -- %s\n", *(unsigned int *)v3, v3 + 48);
if ( !strcmp(src, v3 + 48) )
break;
v3 = (char *)*((_QWORD *)v3 + 40);
if ( !v3 )
goto LABEL_11;
}
printf("%s -- hash --%d\n", src, (unsigned int)v2);
if ( a2 <= 1u )
{
puts("find a match muutex for lock || try_lock operation ");
++*(_DWORD *)v3;
}
else if ( a2 == 2 )
{
puts("find match mutex for unlock operation");
}
LABEL_8:
if ( !pthread_mutex_unlock(&glob_mutex) )
return v3;
LABEL_16:
perror("glob_mutex thread_mutex_unlock");
return v3;
}
LABEL_11:
printf("%s -- hash --%d\n", src, (unsigned int)v2);
if ( a2 > 1u )
{
if ( a2 == 2 )
puts("no mutex to unlock!");
v3 = 0LL;
goto LABEL_8;
}
puts("no match mutex for req,now allocate a new mutex ");
v3 = alloc_zz_mutex();
if ( !v3 )
{
puts("alloc_zz_mutex fail");
goto LABEL_8;
}
puts("alloc_mutex success!");
strcpy(v3 + 48, src);
v5 = mutex_hash[v2];
*((_QWORD *)v3 + 39) = 0LL;
*(_DWORD *)v3 = 1;
*((_QWORD *)v3 + 40) = v5;
if ( mutex_hash[v2] )
{
printf("mutex_hash[%d] is null\n", (unsigned int)v2);
*(_QWORD *)(mutex_hash[v2] + 312) = v3;
}
mutex_hash[v2] = (__int64)v3;
if ( pthread_mutex_unlock(&glob_mutex) )
goto LABEL_16;
return v3;
}

canonical_decompiled_code:
char *__fastcall func5(char *src, unsigned __int8 a2)
{
__int64 v2; // r15
char *v3; // r12
__int64 v5; // rax

v2 = (unsigned int)hash_func();
v3 = (char *)mutex_hash[v2];
if ( pthread_mutex_lock(&glob_mutex) )
perror("glob_mutex thread_mutex_lock");
puts("now traverse hash_chain");
if ( v3 )
{
while ( 1 )
{
printf("count -- %d file_name -- %s\n", *(unsigned int *)v3, v3 + 48);
if ( !strcmp(src, v3 + 48) )
break;
v3 = (char *)*((_QWORD *)v3 + 40);
if ( !v3 )
goto LABEL_11;
}
printf("%s -- hash --%d\n", src, (unsigned int)v2);
if ( a2 <= 1u )
{
puts("find a match muutex for lock || try_lock operation ");
++*(_DWORD *)v3;
}
else if ( a2 == 2 )
{
puts("find match mutex for unlock operation");
}
LABEL_8:
if ( !pthread_mutex_unlock(&glob_mutex) )
return v3;
LABEL_16:
perror("glob_mutex thread_mutex_unlock");
return v3;
}
LABEL_11:
printf("%s -- hash --%d\n", src, (unsigned int)v2);
if ( a2 > 1u )
{
if ( a2 == 2 )
puts("no mutex to unlock!");
v3 = 0LL;
goto LABEL_8;
}
puts("no match mutex for req,now allocate a new mutex ");
v3 = func3();
if ( !v3 )
{
puts("alloc_zz_mutex fail");
goto LABEL_8;
}
puts("alloc_mutex success!");
strcpy(v3 + 48, src);
v5 = mutex_hash[v2];
*((_QWORD *)v3 + 39) = 0LL;
*(_DWORD *)v3 = 1;
*((_QWORD *)v3 + 40) = v5;
if ( mutex_hash[v2] )
{
printf("mutex_hash[%d] is null\n", (unsigned int)v2);
*(_QWORD *)(mutex_hash[v2] + 312) = v3;
}
mutex_hash[v2] = (__int64)v3;
if ( pthread_mutex_unlock(&glob_mutex) )
goto LABEL_16;
return v3;
}

original_code:
zz_mutex * get_zz_mutex(char * file_name,char op_type)
{
 zz_mutex * my_mutex;
 zz_mutex * nmtx;
 unsigned int hash = hash_func(file_name);
 my_mutex = mutex_hash[hash];
 if(pthread_mutex_lock(&glob_mutex) != 0)
 {
  perror("glob_mutex thread_mutex_lock");
 }
 printf("now traverse hash_chain\n");
 while(my_mutex != (zz_mutex*)0)
 {
  printf("count -- %d file_name -- %s\n",my_mutex->count,my_mutex->file_name);
  if(strcmp(file_name,my_mutex->file_name) == 0){break;}
  my_mutex = my_mutex->next;
  continue;
 }
 printf("%s -- hash --%d\n",file_name,hash);
 if(op_type == MD_LOCK || op_type == MD_TRY_LOCK)
 {
  if(my_mutex == (zz_mutex*)0)
  {
   printf("no match mutex for req,now allocate a new mutex \n");
   if((nmtx = alloc_zz_mutex()) == (zz_mutex*)0)
   {
    printf("alloc_zz_mutex fail\n");
   }
   else
   {
    printf("alloc_mutex success!\n");
    my_mutex = nmtx;
    strcpy(nmtx->file_name,file_name);
    nmtx->count = 1;
    nmtx->next = mutex_hash[hash];
    nmtx->pre = (zz_mutex*)0;
    if(mutex_hash[hash] != (zz_mutex*)0)
    {
     printf("mutex_hash[%d] is null\n",hash);
     mutex_hash[hash]->pre = nmtx;
    }
    mutex_hash[hash] = nmtx;
   }
  }
  else
  {
   printf("find a match muutex for lock || try_lock operation \n");
   my_mutex->count++;
  }
 }
 else if(op_type == MD_UNLOCK)
 {
  if(my_mutex == (zz_mutex*)0)
  {
   printf("no mutex to unlock!\n");
  }
  else{printf("find match mutex for unlock operation\n");}
 }
 if(pthread_mutex_unlock(&glob_mutex) != 0)
 {
  perror("glob_mutex thread_mutex_unlock");
 }
 return my_mutex;
}

canonical_original_code:
struct _mutex *get_zz_mutex(char *file_name, char op_type)
{
 struct _mutex *my_mutex;
 struct _mutex *nmtx;
 unsigned int hash = hash_func(file_name);
 my_mutex = mutex_hash[hash];
 if(pthread_mutex_lock(&glob_mutex) != 0)
 {
  perror("glob_mutex thread_mutex_lock");
 }
 printf("now traverse hash_chain\n");
 while(my_mutex != (struct _mutex *)0)
 {
  printf("count -- %d file_name -- %s\n",my_mutex->count,my_mutex->file_name);
  if(strcmp(file_name,my_mutex->file_name) == 0){break;}
  my_mutex = my_mutex->next;
  continue;
 }
 printf("%s -- hash --%d\n",file_name,hash);
 if(op_type == MD_LOCK || op_type == MD_TRY_LOCK)
 {
  if(my_mutex == (struct _mutex *)0)
  {
   printf("no match mutex for req,now allocate a new mutex \n");
   if((nmtx = alloc_zz_mutex()) == (struct _mutex *)0)
   {
    printf("alloc_zz_mutex fail\n");
   }
   else
   {
    printf("alloc_mutex success!\n");
    my_mutex = nmtx;
    strcpy(nmtx->file_name,file_name);
    nmtx->count = 1;
    nmtx->next = mutex_hash[hash];
    nmtx->pre = (struct _mutex *)0;
    if(mutex_hash[hash] != (struct _mutex *)0)
    {
     printf("mutex_hash[%d] is null\n",hash);
     mutex_hash[hash]->pre = nmtx;
    }
    mutex_hash[hash] = nmtx;
   }
  }
  else
  {
   printf("find a match muutex for lock || try_lock operation \n");
   my_mutex->count++;
  }
 }
 else if(op_type == MD_UNLOCK)
 {
  if(my_mutex == (struct _mutex *)0)
  {
   printf("no mutex to unlock!\n");
  }
  else{printf("find match mutex for unlock operation\n");}
 }
 if(pthread_mutex_unlock(&glob_mutex) != 0)
 {
  perror("glob_mutex thread_mutex_unlock");
 }
 return my_mutex;
}

variable_types:
hash
unsigned int


decompiled_code:
__int64 __fastcall put_zz_mutex(void *ptr)
{
unsigned int v1; // er12
__int64 v3; // rax
__int64 v4; // rdx

v1 = pthread_mutex_lock(&glob_mutex);
if ( v1 )
{
v1 = 1;
perror("glob_mutex thread_mutex_lock");
}
if ( (*(_DWORD *)ptr)-- == 1 )
{
v3 = *((_QWORD *)ptr + 40);
if ( v3 )
*(_QWORD *)(v3 + 312) = *((_QWORD *)ptr + 39);
v4 = *((_QWORD *)ptr + 39);
if ( v4 )
*(_QWORD *)(v4 + 320) = v3;
else
mutex_hash[(int)hash_func((char *)ptr + 48)] = *((_QWORD *)ptr + 40);
free_zz_mutex(ptr);
}
if ( !pthread_mutex_unlock(&glob_mutex) )
return v1;
perror("glob_mutex thread_mutex_unlock");
return 2LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(void *ptr)
{
unsigned int v1; // er12
__int64 v3; // rax
__int64 v4; // rdx

v1 = pthread_mutex_lock(&glob_mutex);
if ( v1 )
{
v1 = 1;
perror("glob_mutex thread_mutex_lock");
}
if ( (*(_DWORD *)ptr)-- == 1 )
{
v3 = *((_QWORD *)ptr + 40);
if ( v3 )
*(_QWORD *)(v3 + 312) = *((_QWORD *)ptr + 39);
v4 = *((_QWORD *)ptr + 39);
if ( v4 )
*(_QWORD *)(v4 + 320) = v3;
else
mutex_hash[(int)hash_func((char *)ptr + 48)] = *((_QWORD *)ptr + 40);
func4(ptr);
}
if ( !pthread_mutex_unlock(&glob_mutex) )
return v1;
perror("glob_mutex thread_mutex_unlock");
return 2LL;
}

original_code:
int put_zz_mutex(zz_mutex * my_mutex)
{
 int r = 0;
 int hash;
 if(pthread_mutex_lock(&glob_mutex) != 0)
 {
  r = 1;
  perror("glob_mutex thread_mutex_lock");
 }
 if(--my_mutex->count == 0)
 {
  if(my_mutex->next != (zz_mutex*)0)
  {
   my_mutex->next->pre = my_mutex->pre;
  }
  if(my_mutex->pre != (zz_mutex*)0)
  {
   my_mutex->pre->next = my_mutex->next;
  }
  else
  {
   hash = hash_func(my_mutex->file_name);
   mutex_hash[hash] = my_mutex->next;
  }
  free_zz_mutex(my_mutex);
 }
 if(pthread_mutex_unlock(&glob_mutex) != 0)
 {
  r = 2;
  perror("glob_mutex thread_mutex_unlock");
 }
 return r;
}

canonical_original_code:
int put_zz_mutex(struct _mutex *my_mutex)
{
 int r = 0;
 int hash;
 if(pthread_mutex_lock(&glob_mutex) != 0)
 {
  r = 1;
  perror("glob_mutex thread_mutex_lock");
 }
 if(--my_mutex->count == 0)
 {
  if(my_mutex->next != (struct _mutex *)0)
  {
   my_mutex->next->pre = my_mutex->pre;
  }
  if(my_mutex->pre != (struct _mutex *)0)
  {
   my_mutex->pre->next = my_mutex->next;
  }
  else
  {
   hash = hash_func(my_mutex->file_name);
   mutex_hash[hash] = my_mutex->next;
  }
  free_zz_mutex(my_mutex);
 }
 if(pthread_mutex_unlock(&glob_mutex) != 0)
 {
  r = 2;
  perror("glob_mutex thread_mutex_unlock");
 }
 return r;
}

variable_types: hash int


decompiled_code:
void __fastcall __noreturn thread_func(void *a1)
{
_BYTE *v1; // rax
unsigned __int8 v2; // si
_DWORD *v3; // r12
char *v4; // rax
char *v5; // r13
unsigned __int8 v6; // al

v1 = malloc(8uLL);
v2 = *(_BYTE *)a1;
*v1 = 1;
v3 = v1;
v4 = get_zz_mutex((char *)a1 + 8, v2);
if ( v4 )
{
v5 = v4;
v6 = *(_BYTE *)a1;
if ( *(_BYTE *)a1 == 1 )
{
puts("TRY_LOCK operation,after get_zz_mutex:");
show_mutex_hash();
if ( pthread_mutex_trylock((pthread_mutex_t *)(v5 + 8)) )
{
puts("Try_Lock fail! put zz_mutex back");
put_zz_mutex(v5);
*(_BYTE *)v3 = 0;
v3[1] = 4;
}
else
{
puts("Try_Lock success!");
}
}
else if ( v6 == 2 )
{
if ( pthread_mutex_unlock((pthread_mutex_t *)(v5 + 8)) )
{
puts("Unlock fail!");
*(_BYTE *)v3 = 0;
v3[1] = 5;
}
else
{
puts("Unlock success! put zz_mutex back");
put_zz_mutex(v5);
}
}
else if ( v6 )
{
v3[1] = 6;
*(_BYTE *)v3 = 0;
}
else
{
puts("LOCK operation,after get_zz_mutex:");
show_mutex_hash();
if ( pthread_mutex_lock((pthread_mutex_t *)(v5 + 8)) )
{
puts("Lock fail! put zz_mutex back");
put_zz_mutex(v5);
*(_BYTE *)v3 = 0;
v3[1] = 3;
}
else
{
puts("Lock success!");
}
}
show_mutex_hash();
}
else
{
v3[1] = 2;
*(_BYTE *)v3 = 0;
}
if ( write(*((_DWORD *)a1 + 1), v3, 8uLL) == -1 )
perror("write");
close(*((_DWORD *)a1 + 1));
free(a1);
free(v3);
pthread_exit(0LL);
}

canonical_decompiled_code:
void __fastcall __noreturn func7(void *a1)
{
_BYTE *v1; // rax
unsigned __int8 v2; // si
_DWORD *v3; // r12
char *v4; // rax
char *v5; // r13
unsigned __int8 v6; // al

v1 = malloc(8uLL);
v2 = *(_BYTE *)a1;
*v1 = 1;
v3 = v1;
v4 = func5((char *)a1 + 8, v2);
if ( v4 )
{
v5 = v4;
v6 = *(_BYTE *)a1;
if ( *(_BYTE *)a1 == 1 )
{
puts("TRY_LOCK operation,after get_zz_mutex:");
func2();
if ( pthread_mutex_trylock((pthread_mutex_t *)(v5 + 8)) )
{
puts("Try_Lock fail! put zz_mutex back");
func6(v5);
*(_BYTE *)v3 = 0;
v3[1] = 4;
}
else
{
puts("Try_Lock success!");
}
}
else if ( v6 == 2 )
{
if ( pthread_mutex_unlock((pthread_mutex_t *)(v5 + 8)) )
{
puts("Unlock fail!");
*(_BYTE *)v3 = 0;
v3[1] = 5;
}
else
{
puts("Unlock success! put zz_mutex back");
func6(v5);
}
}
else if ( v6 )
{
v3[1] = 6;
*(_BYTE *)v3 = 0;
}
else
{
puts("LOCK operation,after get_zz_mutex:");
func2();
if ( pthread_mutex_lock((pthread_mutex_t *)(v5 + 8)) )
{
puts("Lock fail! put zz_mutex back");
func6(v5);
*(_BYTE *)v3 = 0;
v3[1] = 3;
}
else
{
puts("Lock success!");
}
}
func2();
}
else
{
v3[1] = 2;
*(_BYTE *)v3 = 0;
}
if ( write(*((_DWORD *)a1 + 1), v3, 8uLL) == -1 )
perror("write");
close(*((_DWORD *)a1 + 1));
free(a1);
free(v3);
pthread_exit(0LL);
}

original_code:
void * thread_func(void * arg)
{
 thread_arg * my_arg = (thread_arg *)arg;
 zz_mutex * my_mutex;
 md_mutex_res_packet * res_pkt = (md_mutex_res_packet*)malloc(sizeof(md_mutex_res_packet));
 res_pkt->ok_or_not = 01;
 if((my_mutex = get_zz_mutex(my_arg->file_name,my_arg->op_type)) == (zz_mutex *)0)
 {
  res_pkt->why_fail = ALLOC_MUTEX_FAIL;
  res_pkt->ok_or_not = 00;
 }
 else
 {
  switch(my_arg->op_type)
  {
   case MD_LOCK:
    printf("LOCK operation,after get_zz_mutex:\n");
    show_mutex_hash();
    if(pthread_mutex_lock(&my_mutex->p_mutex) != 0)
    {
     printf("Lock fail! put zz_mutex back\n");
     put_zz_mutex(my_mutex);
     res_pkt->why_fail = LOCK_FAIL;
     res_pkt->ok_or_not = 00;
    }
    else{printf("Lock success!\n");}
    break;
   case MD_TRY_LOCK:
    printf("TRY_LOCK operation,after get_zz_mutex:\n");
    show_mutex_hash();
    if(pthread_mutex_trylock(&my_mutex->p_mutex) != 0)
    {
     printf("Try_Lock fail! put zz_mutex back\n");
     put_zz_mutex(my_mutex);
     res_pkt->why_fail = TRY_LOCK_FAIL;
     res_pkt->ok_or_not = 00;
    }
    else{printf("Try_Lock success!\n");}
    break;
   case MD_UNLOCK:
    if(pthread_mutex_unlock(&my_mutex->p_mutex) == 0)
    {
     printf("Unlock success! put zz_mutex back\n");
     put_zz_mutex(my_mutex);
    }
    else
    {
     printf("Unlock fail!\n");
     res_pkt->why_fail = UNLOCK_FAIL;
     res_pkt->ok_or_not = 00;
    }
    break;
   default:
    res_pkt->why_fail = UNRECOGNIZED_OP_TYPE;
    res_pkt->ok_or_not = 00;
    break;
  }
  show_mutex_hash();
 }
 if(write(my_arg->client_sock_fd,res_pkt,sizeof(md_mutex_res_packet)) == -1)
 {
  perror("write");
 }
 close(my_arg->client_sock_fd);
 free((thread_arg *)arg);
 free(res_pkt);
 pthread_exit((void *)0);
}

canonical_original_code:
void *thread_func(void *arg)
{
 struct thread_arg *my_arg = (thread_arg *)arg;
 struct _mutex *my_mutex;
 struct md_mutex_res_packet *res_pkt = (md_mutex_res_packet*)malloc(sizeof(md_mutex_res_packet));
 res_pkt->ok_or_not = 01;
 if((my_mutex = get_zz_mutex(my_arg->file_name,my_arg->op_type)) == (struct _mutex *)0)
 {
  res_pkt->why_fail = ALLOC_MUTEX_FAIL;
  res_pkt->ok_or_not = 00;
 }
 else
 {
  switch(my_arg->op_type)
  {
   case MD_LOCK:
    printf("LOCK operation,after get_zz_mutex:\n");
    show_mutex_hash();
    if(pthread_mutex_lock(&my_mutex->p_mutex) != 0)
    {
     printf("Lock fail! put zz_mutex back\n");
     put_zz_mutex(my_mutex);
     res_pkt->why_fail = LOCK_FAIL;
     res_pkt->ok_or_not = 00;
    }
    else{printf("Lock success!\n");}
    break;
   case MD_TRY_LOCK:
    printf("TRY_LOCK operation,after get_zz_mutex:\n");
    show_mutex_hash();
    if(pthread_mutex_trylock(&my_mutex->p_mutex) != 0)
    {
     printf("Try_Lock fail! put zz_mutex back\n");
     put_zz_mutex(my_mutex);
     res_pkt->why_fail = TRY_LOCK_FAIL;
     res_pkt->ok_or_not = 00;
    }
    else{printf("Try_Lock success!\n");}
    break;
   case MD_UNLOCK:
    if(pthread_mutex_unlock(&my_mutex->p_mutex) == 0)
    {
     printf("Unlock success! put zz_mutex back\n");
     put_zz_mutex(my_mutex);
    }
    else
    {
     printf("Unlock fail!\n");
     res_pkt->why_fail = UNLOCK_FAIL;
     res_pkt->ok_or_not = 00;
    }
    break;
   default:
    res_pkt->why_fail = UNRECOGNIZED_OP_TYPE;
    res_pkt->ok_or_not = 00;
    break;
  }
  show_mutex_hash();
 }
 if(write(my_arg->client_sock_fd,res_pkt,sizeof(md_mutex_res_packet)) == -1)
 {
  perror("write");
 }
 close(my_arg->client_sock_fd);
 free((struct thread_arg *)arg);
 free(res_pkt);
 pthread_exit((void *)0);
}

variable_types:
arg
void *

variable_types: struct thread_arg { char op_type; int client_sock_fd; char file_name[260]; } *

variable_types: struct md_mutex_res_packet { char ok_or_not; enum fail_t { GLOB_MUTEX_LOCK_FAIL=0, GLOB_MUTEX_UNLOCK_FAIL=1, ALLOC_MUTEX_FAIL=2, LOCK_FAIL=3, TRY_LOCK_FAIL=4, UNLOCK_FAIL=5, UNRECOGNIZED_OP_TYPE=6 } why_fail; } *

return_type: void *

user_defined_types: struct md_mutex_res_packet { char ok_or_not; enum fail_t why_fail; }


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // edx
int v4; // er13
_BYTE *v5; // rax
_BYTE *v6; // r12
int v7; // ebx
unsigned int v8; // er12
size_t v9; // rdx
unsigned int v10; // eax
socklen_t addr_len; // [rsp+0h] [rbp-174h] BYREF
pthread_t newthread; // [rsp+4h] [rbp-170h] BYREF
char v13[16]; // [rsp+Ch] [rbp-168h] BYREF
struct sockaddr buf; // [rsp+1Ch] [rbp-158h] BYREF
struct sockaddr addr; // [rsp+2Ch] [rbp-148h] BYREF
int v16[78]; // [rsp+3Ch] [rbp-138h] BYREF

buf = 0LL;
buf.sa_family = 2;
inet_pton(2, "127.0.0.1", &buf.sa_data[2]);
*(_WORD *)buf.sa_data = _bswap_16(9378);
v4 = socket(2, 1, v3);
if ( bind(v4, &buf, 0x10u) != -1 )
{
mutex_hash_init();
show_mutex_hash();
listen(v4, 100);
while ( 1 )
{
puts("md_concurrent_access_control_server listening...");
memset(v16, 0, 0x108uLL);
*(_OWORD *)v13 = 0LL;
v7 = accept(v4, &addr, &addr_len);
inet_ntop(2, &addr.sa_data[2], v13, 0x10u);
v8 = (unsigned __int16)_bswap_16(*(__int16 *)addr.sa_data);
v10 = read(v7, v16, v9);
if ( v10 == -1 )
break;
printf("%d bytes read from client : ip - %s ^^ port - %d\n", v10, v13, v8);
v5 = calloc(0x10CuLL, 1uLL);
v6 = v5;
if ( !v5 )
{
perror("malloc");
exit(1);
}
*((_DWORD *)v5 + 1) = v7;
strcpy(v5 + 8, (const char *)&v16[1]);
*v6 = v16[0];
if ( pthread_create(&newthread, 0LL, (void *(*)(void *))thread_func, v6) )
{
perror("lock_thread_create");
exit(1);
}
}
perror("read");
exit(1);
}
perror("bind");
exit(1);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // edx
int v4; // er13
_BYTE *v5; // rax
_BYTE *v6; // r12
int v7; // ebx
unsigned int v8; // er12
size_t v9; // rdx
unsigned int v10; // eax
socklen_t addr_len; // [rsp+0h] [rbp-174h] BYREF
pthread_t newthread; // [rsp+4h] [rbp-170h] BYREF
char v13[16]; // [rsp+Ch] [rbp-168h] BYREF
struct sockaddr buf; // [rsp+1Ch] [rbp-158h] BYREF
struct sockaddr addr; // [rsp+2Ch] [rbp-148h] BYREF
int v16[78]; // [rsp+3Ch] [rbp-138h] BYREF

buf = 0LL;
buf.sa_family = 2;
inet_pton(2, "127.0.0.1", &buf.sa_data[2]);
*(_WORD *)buf.sa_data = func0(9378);
v4 = socket(2, 1, v3);
if ( bind(v4, &buf, 0x10u) != -1 )
{
func1();
func2();
listen(v4, 100);
while ( 1 )
{
puts("md_concurrent_access_control_server listening...");
memset(v16, 0, 0x108uLL);
*(_OWORD *)v13 = 0LL;
v7 = accept(v4, &addr, &addr_len);
inet_ntop(2, &addr.sa_data[2], v13, 0x10u);
v8 = (unsigned __int16)func0(*(__int16 *)addr.sa_data);
v10 = read(v7, v16, v9);
if ( v10 == -1 )
break;
printf("%d bytes read from client : ip - %s ^^ port - %d\n", v10, v13, v8);
v5 = calloc(0x10CuLL, 1uLL);
v6 = v5;
if ( !v5 )
{
perror("malloc");
exit(1);
}
*((_DWORD *)v5 + 1) = v7;
strcpy(v5 + 8, (const char *)&v16[1]);
*v6 = v16[0];
if ( pthread_create(&newthread, 0LL, (void *(*)(void *))thread_func, v6) )
{
perror("lock_thread_create");
exit(1);
}
}
perror("read");
exit(1);
}
perror("bind");
exit(1);
}

original_code:
int main()
{
 pthread_t thread_id;
 thread_arg * th_arg;
 md_mutex_req_packet req_pkt;
 char clnt_ip[16];
 int clnt_port;
 int listen_fd,connect_fd,addr_len,clnt_addr_len,n;
 struct sockaddr_in addr,clnt_addr;
 addr_len = sizeof(addr);
 bzero(&addr,addr_len);
 addr.sin_family = 2;
 inet_pton(2,"127.0.0.1",(void*)&addr.sin_addr);
 addr.sin_port = htons(9378);
 listen_fd = socket(2,SOCK_STREAM,0);
 if(bind(listen_fd,(struct sockaddr*)&addr,addr_len) == -1)
 {
  perror("bind");
  exit(1);
 }
 mutex_hash_init();
 show_mutex_hash();
 listen(listen_fd,100);
 for(;;)
 {
  printf("md_concurrent_access_control_server listening...\n");
  bzero(clnt_ip,16);
  bzero(&req_pkt,sizeof(req_pkt));
  connect_fd = accept(listen_fd,(struct sockaddr*)&clnt_addr,&clnt_addr_len);
  inet_ntop(2,(void *)&clnt_addr.sin_addr,clnt_ip,16);
  clnt_port = ntohs(clnt_addr.sin_port);
  if((n = read(connect_fd,&req_pkt,sizeof(req_pkt))) == -1)
  {
   perror("read");
   exit(1);
  }
  printf("%d bytes read from client : ip - %s ^^ port - %d\n",n,clnt_ip,clnt_port);
  th_arg = (thread_arg*)malloc(sizeof(thread_arg));
  if(th_arg == ((void *)0))
  {
   perror("malloc");
   exit(1);
  }
  bzero(th_arg,sizeof(thread_arg));
  th_arg->client_sock_fd = connect_fd;
  strcpy(th_arg->file_name,req_pkt.file_name);
  th_arg->op_type = req_pkt.op_type;
  if(pthread_create(&thread_id,((void *)0),thread_func,(void*)th_arg) != 0)
  {
   perror("lock_thread_create");
   exit(1);
  }
 }
 return 0;
}

canonical_original_code:
int main()
{
 unsigned long thread_id;
 struct thread_arg *th_arg;
 struct md_mutex_req_packet req_pkt;
 char clnt_ip[16];
 int clnt_port;
 int listen_fd; int connect_fd; int addr_len; int clnt_addr_len; int n;
 struct sockaddr_in addr; struct sockaddr_in clnt_addr;
 addr_len = sizeof(addr);
 bzero(&addr,addr_len);
 addr.sin_family = 2;
 inet_pton(2,"127.0.0.1",(void *)&addr.sin_addr);
 addr.sin_port = htons(9378);
 listen_fd = socket(2,SOCK_STREAM,0);
 if(bind(listen_fd,(struct sockaddr *)&addr,addr_len) == -1)
 {
  perror("bind");
  exit(1);
 }
 mutex_hash_init();
 show_mutex_hash();
 listen(listen_fd,100);
 for(;;)
 {
  printf("md_concurrent_access_control_server listening...\n");
  bzero(clnt_ip,16);
  bzero(&req_pkt,sizeof(req_pkt));
  connect_fd = accept(listen_fd,(struct sockaddr *)&clnt_addr,&clnt_addr_len);
  inet_ntop(2,(void *)&clnt_addr.sin_addr,clnt_ip,16);
  clnt_port = ntohs(clnt_addr.sin_port);
  if((n = read(connect_fd,&req_pkt,sizeof(req_pkt))) == -1)
  {
   perror("read");
   exit(1);
  }
  printf("%d bytes read from client : ip - %s ^^ port - %d\n",n,clnt_ip,clnt_port);
  th_arg = (struct thread_arg *)malloc(sizeof(thread_arg));
  if(th_arg == ((void *)0))
  {
   perror("malloc");
   exit(1);
  }
  bzero(th_arg,sizeof(thread_arg));
  th_arg->client_sock_fd = connect_fd;
  strcpy(th_arg->file_name,req_pkt.file_name);
  th_arg->op_type = req_pkt.op_type;
  if(pthread_create(&thread_id,((void *)0),thread_func,(void *)th_arg) != 0)
  {
   perror("lock_thread_create");
   exit(1);
  }
 }
 return 0;
}

variable_types: struct md_mutex_req_packet { enum op_t { MD_LOCK=0, MD_TRY_LOCK=1, MD_UNLOCK=2 } op_type; char file_name[260]; }

variable_types: n 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 md_mutex_req_packet { enum op_t op_type; char file_name[260]; }

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

user_defined_types: struct thread_arg { char op_type; int client_sock_fd; char file_name[260]; }

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


decompiled_code:
__int64 __fastcall atoi_u32(char *a1)
{
char v1; // al
unsigned int v2; // er8
unsigned __int8 v3; // al

v1 = *a1;
v2 = 0;
if ( !*a1 )
return v2;
while ( 1 )
{
v3 = v1 - 48;
if ( v3 > 9u )
break;
++a1;
v2 = (char)v3 + 10 * v2;
v1 = *a1;
if ( !*a1 )
return v2;
}
fwrite("Invalid character found in u32 string!\n", 1uLL, 0x27uLL, stderr);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1)
{
char v1; // al
unsigned int v2; // er8
unsigned __int8 v3; // al

v1 = *a1;
v2 = 0;
if ( !*a1 )
return v2;
while ( 1 )
{
v3 = v1 - 48;
if ( v3 > 9u )
break;
++a1;
v2 = (char)v3 + 10 * v2;
v1 = *a1;
if ( !*a1 )
return v2;
}
fwrite("Invalid character found in u32 string!\n", 1uLL, 0x27uLL, stderr);
return 0xFFFFFFFFLL;
}

original_code:
u32 atoi_u32(char *p)
{
 u32 i = 0;
 u32 j;
 char * ch = p;
 while(*ch != 00){
  if(*ch < '0' || *ch > '9'){
   fprintf(stderr,"Invalid character found in u32 string!\n");
   return -1;
  }
  j = (u32)(*ch - '0');
  i = 10*i + j;
  ch++;
 }
 return i;
}

canonical_original_code:
unsigned int atoi_u32(char *p)
{
 unsigned int i = 0;
 unsigned int j;
 char *ch = p;
 while(*ch != 00){
  if(*ch < '0' || *ch > '9'){
   fprintf(stderr,"Invalid character found in u32 string!\n");
   return -1;
  }
  j = (u32)(*ch - '0');
  i = 10*i + j;
  ch++;
 }
 return i;
}

variable_types:
p
char *

variable_types:
i
unsigned int

variable_types:
j
unsigned int

variable_types:
ch
char *


decompiled_code:
__int64 __fastcall atoi_u64(char *a1)
{
char v1; // al
__int64 v2; // r8
unsigned __int8 v3; // al

v1 = *a1;
v2 = 0LL;
if ( !*a1 )
return v2;
while ( 1 )
{
v3 = v1 - 48;
if ( v3 > 9u )
break;
++a1;
v2 = (char)v3 + 10 * v2;
v1 = *a1;
if ( !*a1 )
return v2;
}
fwrite("Invalid character found in u64 string!\n", 1uLL, 0x27uLL, stderr);
return -1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *a1)
{
char v1; // al
__int64 v2; // r8
unsigned __int8 v3; // al

v1 = *a1;
v2 = 0LL;
if ( !*a1 )
return v2;
while ( 1 )
{
v3 = v1 - 48;
if ( v3 > 9u )
break;
++a1;
v2 = (char)v3 + 10 * v2;
v1 = *a1;
if ( !*a1 )
return v2;
}
fwrite("Invalid character found in u64 string!\n", 1uLL, 0x27uLL, stderr);
return -1LL;
}

original_code:
u64 atoi_u64(char *p)
{
 u64 i = 0;
 u64 j;
 char * ch = p;
 while(*ch != 00){
  if(*ch < '0' || *ch > '9'){
   fprintf(stderr,"Invalid character found in u64 string!\n");
   return -1;
  }
  j = (u64)(*ch - '0');
  i = 10*i + j;
  ch++;
 }
 return i;
}

canonical_original_code:
unsigned long atoi_u64(char *p)
{
 unsigned long i = 0;
 unsigned long j;
 char *ch = p;
 while(*ch != 00){
  if(*ch < '0' || *ch > '9'){
   fprintf(stderr,"Invalid character found in u64 string!\n");
   return -1;
  }
  j = (u64)(*ch - '0');
  i = 10*i + j;
  ch++;
 }
 return i;
}

variable_types:
i
unsigned long

variable_types:
j
unsigned long

return_type: unsigned long


decompiled_code:
__int64 __fastcall get_cache_path(char *src, __int64 a2)
{
__m128i v2; // xmm0

v2 = _mm_load_si128((const __m128i *)&LC2);
*(_QWORD *)(a2 + 252) = 0LL;
memset(
(void *)((a2 + 8) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a2 - (((_DWORD)a2 + 8) & 0xFFFFFFF8) + 260) >> 3));
*(__m128i *)a2 = v2;
strcpy((char *)(a2 + 15), src);
return a2;
}

original_code:
char * get_cache_path(char * path,char * cache_path)
{
 char *p = cache_path + strlen("/mnt/supercache");
 memset(cache_path,0,260);
 strcpy(cache_path,"/mnt/supercache");
 strcpy(p,path);
 return cache_path;
}

canonical_original_code:
char *get_cache_path(char *path, char *cache_path)
{
 char *p = cache_path + strlen("/mnt/supercache");
 memset(cache_path,0,260);
 strcpy(cache_path,"/mnt/supercache");
 strcpy(p,path);
 return cache_path;
}

variable_types:
path
char *

return_type: char *


decompiled_code:
__int64 __fastcall get_dtc_path(char *src, __int64 a2)
{
*(_QWORD *)(a2 + 252) = 0LL;
memset(
(void *)((a2 + 8) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a2 - (((_DWORD)a2 + 8) & 0xFFFFFFF8) + 260) >> 3));
qmemcpy((void *)a2, "/mnt/dtcenter", 13);
strcpy((char *)(a2 + 13), src);
return a2;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *src, __int64 a2)
{
*(_QWORD *)(a2 + 252) = 0LL;
memset(
(void *)((a2 + 8) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a2 - (((_DWORD)a2 + 8) & 0xFFFFFFF8) + 260) >> 3));
qmemcpy((void *)a2, "/mnt/dtcenter", 13);
strcpy((char *)(a2 + 13), src);
return a2;
}

original_code:
char * get_dtc_path(char * path,char * dtc_path)
{
 char *p = dtc_path + strlen("/mnt/dtcenter");
 memset(dtc_path,0,260);
 strcpy(dtc_path,"/mnt/dtcenter");
 strcpy(p,path);
 return dtc_path;
}

canonical_original_code:
char *get_dtc_path(char *path, char *dtc_path)
{
 char *p = dtc_path + strlen("/mnt/dtcenter");
 memset(dtc_path,0,260);
 strcpy(dtc_path,"/mnt/dtcenter");
 strcpy(p,path);
 return dtc_path;
}


decompiled_code:
ssize_t __fastcall get_path_from_fd(unsigned int a1, char *a2)
{
unsigned int v2; // eax
_BYTE savedregs[1048]; // [rsp+0h] [rbp+0h] BYREF

memset(savedregs, 0, 0x400uLL);
v2 = getpid();
snprintf(savedregs, 0x400uLL, "/proc/%i/fd/%i", v2, a1);
return readlink(savedregs, a2, 0x104uLL);
}

canonical_decompiled_code:
ssize_t __fastcall func4(unsigned int a1, char *a2)
{
unsigned int v2; // eax
_BYTE savedregs[1048]; // [rsp+0h] [rbp+0h] BYREF

memset(savedregs, 0, 0x400uLL);
v2 = getpid();
snprintf(savedregs, 0x400uLL, "/proc/%i/fd/%i", v2, a1);
return readlink(savedregs, a2, 0x104uLL);
}

original_code:
int get_path_from_fd(int fd,char * path)
{
 char buf[1024];
 pid_t pid;
 memset(buf,0,1024);
 pid = getpid();
 snprintf(buf,1024,"/proc/%i/fd/%i",pid,fd);
 return readlink(buf,path,260);
}

canonical_original_code:
int get_path_from_fd(int fd, char *path)
{
 char buf[1024];
 int pid;
 memset(buf,0,1024);
 pid = getpid();
 snprintf(buf,1024,"/proc/%i/fd/%i",pid,fd);
 return readlink(buf,path,260);
}

variable_types: fd int

variable_types:
buf
char [1024]

variable_types: pid int


decompiled_code:
__int64 __fastcall pthread_block_sig(int signo)
{
unsigned int v1; // er12
sigset_t v3; // [rsp+0h] [rbp-98h] BYREF

sigemptyset(&v3);
sigaddset(&v3, signo);
v1 = pthread_sigmask(0, &v3, 0LL);
if ( v1 )
printf("Block signal -- %d fail!\n", (unsigned int)signo);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func5(int signo)
{
unsigned int v1; // er12
sigset_t v3; // [rsp+0h] [rbp-98h] BYREF

sigemptyset(&v3);
sigaddset(&v3, signo);
v1 = pthread_sigmask(0, &v3, 0LL);
if ( v1 )
printf("Block signal -- %d fail!\n", (unsigned int)signo);
return v1;
}

original_code:
int pthread_block_sig(int signo)
{
    int rt = 0;
    sigset_t st;
    sigemptyset(&st);
    sigaddset(&st,signo);
    rt = pthread_sigmask(0,&st,((void *)0));
    if(rt != 0)
    {
        printf("Block signal -- %d fail!\n",signo);
    }
    return rt;
}

canonical_original_code:
int pthread_block_sig(int signo)
{
    int rt = 0;
    struct __sigset_t st;
    sigemptyset(&st);
    sigaddset(&st,signo);
    rt = pthread_sigmask(0,&st,((void *)0));
    if(rt != 0)
    {
        printf("Block signal -- %d fail!\n",signo);
    }
    return rt;
}

variable_types: signo int

variable_types: rt int

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


decompiled_code:
__int64 __fastcall pthread_unblock_sig(int signo)
{
unsigned int v1; // er12
sigset_t v3; // [rsp+0h] [rbp-98h] BYREF

sigemptyset(&v3);
sigaddset(&v3, signo);
v1 = pthread_sigmask(1, &v3, 0LL);
if ( v1 )
printf("Unblock signal -- %d fail!\n", (unsigned int)signo);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func6(int signo)
{
unsigned int v1; // er12
sigset_t v3; // [rsp+0h] [rbp-98h] BYREF

sigemptyset(&v3);
sigaddset(&v3, signo);
v1 = pthread_sigmask(1, &v3, 0LL);
if ( v1 )
printf("Unblock signal -- %d fail!\n", (unsigned int)signo);
return v1;
}

original_code:
int pthread_unblock_sig(int signo)
{
    int rt = 0;
    sigset_t st;
    sigemptyset(&st);
    sigaddset(&st,signo);
    rt = pthread_sigmask(1,&st,((void *)0));
    if(rt != 0)
    {
        printf("Unblock signal -- %d fail!\n",signo);
    }
    return rt;
}

canonical_original_code:
int pthread_unblock_sig(int signo)
{
    int rt = 0;
    struct __sigset_t st;
    sigemptyset(&st);
    sigaddset(&st,signo);
    rt = pthread_sigmask(1,&st,((void *)0));
    if(rt != 0)
    {
        printf("Unblock signal -- %d fail!\n",signo);
    }
    return rt;
}

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