sub

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


scale

repo: profil/raytracer

original_code:
struct vector scale(float i, struct vector a) {
 struct vector c;
 c.x = a.x * i;
 c.y = a.y * i;
 c.z = a.z * i;
 return c;
}

variable_types: i float

variable_types:
a
struct vector

variable_types:
c
struct vector { float x; }

return_type: struct vector { float x; }


cross

decompiled_code:
__m128i __fastcall cross(double a1, float a2, double a3, float a4)
{
__m128i v5; // [rsp+24h] [rbp-14h] BYREF

*(float *)v5.m128i_i32 = (float)(*((float *)&a1 + 1) * a4) - (float)(a2 * *((float *)&a3 + 1));
*(float *)&v5.m128i_i32[1] = (float)(a2 * *(float *)&a3) - (float)(a4 * *(float *)&a1);
return _mm_loadl_epi64(&v5);
}

canonical_decompiled_code:
__m128i __fastcall func4(double a1, float a2, double a3, float a4)
{
__m128i v5; // [rsp+24h] [rbp-14h] BYREF

*(float *)v5.m128i_i32 = (float)(*((float *)&a1 + 1) * a4) - (float)(a2 * *((float *)&a3 + 1));
*(float *)&v5.m128i_i32[1] = (float)(a2 * *(float *)&a3) - (float)(a4 * *(float *)&a1);
return _mm_loadl_epi64(&v5);
}

original_code:
struct vector cross(struct vector a, struct vector b) {
 struct vector c;
 c.x = a.y*b.z - a.z*b.y;
 c.y = a.z*b.x - a.x*b.z;
 c.z = a.x*b.y - a.y*b.x;
 return c;
}

variable_types:
b
struct vector


dot

decompiled_code:
float __fastcall dot(double a1, float a2, double a3, float a4)
{
return (float)((float)(*(float *)&a1 * *(float *)&a3) + (float)(*((float *)&a1 + 1) * *((float *)&a3 + 1)))
+ (float)(a2 * a4);
}

canonical_decompiled_code:
float __fastcall func5(double a1, float a2, double a3, float a4)
{
return (float)((float)(*(float *)&a1 * *(float *)&a3) + (float)(*((float *)&a1 + 1) * *((float *)&a3 + 1)))
+ (float)(a2 * a4);
}

original_code:
float dot(struct vector a, struct vector b) {
 return a.x*b.x + a.y*b.y + a.z*b.z;
}

variable_types:
a
struct vector { float x; }

return_type: float


norm

decompiled_code:
__m128i __fastcall norm(double a1, float a2)
{
double v2; // xmm0_8
double v3; // xmm0_8
float v4; // xmm0_4

v2 = dot(a1, a2, a1, a2);
if ( v2 < 0.0 )
v3 = sqrt(v2);
else
v3 = sqrt(v2);
v4 = 1.0 / v3;
return scale(v4, a1);
}

canonical_decompiled_code:
__m128i __fastcall func6(double a1, float a2)
{
double v2; // xmm0_8
double v3; // xmm0_8
float v4; // xmm0_4

v2 = func5(a1, a2, a1, a2);
if ( v2 < 0.0 )
v3 = sqrt(v2);
else
v3 = sqrt(v2);
v4 = 1.0 / v3;
return func3(v4, a1);
}

original_code:
struct vector norm(struct vector a) {
 return scale(1.0f / sqrt(dot(a, a)), a);
}


clamp

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

result = 255LL;
if ( a1 <= 255 )
result = (unsigned int)a1;
return result;
}

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

result = 255LL;
if ( a1 <= 255 )
result = (unsigned int)a1;
return result;
}

original_code:
unsigned char clamp(int input) {
 if(input > 0xff) {
  return 0xff;
 }
 else {
  return (unsigned char)input;
 }
}

variable_types: input int

return_type: unsigned char


radiance

original_code:
unsigned int radiance(struct ray current_ray, struct sphere *spheres, int spheres_len, struct sphere *lights, int lights_len, int depth) {
 float distance, lambert, lambertAmount = 0;
 int sphere_id, i;
 unsigned int color;
 unsigned char r, g, b;
 struct sphere current_sphere;
 struct vector hit, normal;
 struct ray shadow;
 for(color = 0; depth < 5; depth++) {
  if((distance = sphere_intersect(current_ray, spheres, spheres_len, &sphere_id)) == 0) {
   break;
  }
  current_sphere = spheres[sphere_id];
  hit = add(current_ray.p, scale(distance, current_ray.d));
  normal = norm(sub(hit, current_sphere.c));
  r = current_sphere.color >> 16 & 0xff;
  g = current_sphere.color >> 8 & 0xff;
  b = current_sphere.color & 0xff;
  for(i = 0; i < lights_len; i++) {
   shadow.d = norm(sub(lights[i].c, hit));
   shadow.p = hit;
   if(!sphere_intersect(shadow, spheres, spheres_len, &sphere_id)) {
    if((lambert = dot(shadow.d, normal)) > 0.0f) {
     lambertAmount += lambert;
    }
   }
  }
  if(lambertAmount > 1)
   lambertAmount = 1;
  r = clamp(r * lambertAmount);
  g = clamp(g * lambertAmount);
  b = clamp(b * lambertAmount);
  color = r << 16 | g << 8 | b;
  current_ray.p = hit;
  current_ray.d = sub(current_ray.d, scale(2.0f * dot(normal, current_ray.d), normal));
 }
 return color;
}

canonical_original_code:
unsigned int radiance(struct ray current_ray, struct sphere *spheres, int spheres_len, struct sphere *lights, int lights_len, int depth) {
 float distance; float lambert; float lambertAmount = 0;
 int sphere_id; int i;
 unsigned int color;
 unsigned char r; unsigned char g; unsigned char b;
 struct sphere current_sphere;
 struct vector hit; struct vector normal;
 struct ray shadow;
 for(color = 0; depth < 5; depth++) {
  if((distance = sphere_intersect(current_ray, spheres, spheres_len, &sphere_id)) == 0) {
   break;
  }
  current_sphere = spheres[sphere_id];
  hit = add(current_ray.p, scale(distance, current_ray.d));
  normal = norm(sub(hit, current_sphere.c));
  r = current_sphere.color >> 16 & 0xff;
  g = current_sphere.color >> 8 & 0xff;
  b = current_sphere.color & 0xff;
  for(i = 0; i < lights_len; i++) {
   shadow.d = norm(sub(lights[i].c, hit));
   shadow.p = hit;
   if(!sphere_intersect(shadow, spheres, spheres_len, &sphere_id)) {
    if((lambert = dot(shadow.d, normal)) > 0.0f) {
     lambertAmount += lambert;
    }
   }
  }
  if(lambertAmount > 1)
   lambertAmount = 1;
  r = clamp(r * lambertAmount);
  g = clamp(g * lambertAmount);
  b = clamp(b * lambertAmount);
  color = r << 16 | g << 8 | b;
  current_ray.p = hit;
  current_ray.d = sub(current_ray.d, scale(2.0f * dot(normal, current_ray.d), normal));
 }
 return color;
}

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

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

variable_types:
lights
struct sphere *

variable_types: depth int

variable_types: distance float

variable_types: lambert float

variable_types: lambertAmount float

variable_types: i int

variable_types:
color
unsigned int

variable_types:
r
unsigned char

variable_types:
g
unsigned char

variable_types:
b
unsigned char

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

variable_types:
hit
struct vector { float x; }

variable_types:
normal
struct vector { float x; }

return_type: unsigned int

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


ray

decompiled_code:
__int64 __fastcall ray(__int64 a1, double a2, float a3, double a4, float a5)
{
__int64 result; // rax

result = a1;
*(double *)a1 = a2;
*(float *)(a1 + 8) = a3;
*(double *)(a1 + 12) = a4;
*(float *)(a1 + 20) = a5;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, double a2, float a3, double a4, float a5)
{
__int64 result; // rax

result = a1;
*(double *)a1 = a2;
*(float *)(a1 + 8) = a3;
*(double *)(a1 + 12) = a4;
*(float *)(a1 + 20) = a5;
return result;
}

original_code:
struct ray ray(struct vector p, struct vector d) {
 struct ray r;
 r.p = p;
 r.d = d;
 return r;
}

variable_types:
p
struct vector

variable_types:
d
struct vector

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


repo: programble/forklimit

decompiled_code:
void *__fastcall get_func_ptr(void *a1, const char *a2)
{
void *result; // rax
char *v3; // rax

result = dlsym(a1, a2);
if ( !result )
{
v3 = dlerror();
fprintf(stderr, "forklimit: cannot find function %s: %s\n", a2, v3);
exit(1);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func6(void *a1, const char *a2)
{
void *result; // rax
char *v3; // rax

result = dlsym(a1, a2);
if ( !result )
{
v3 = dlerror();
fprintf(stderr, "forklimit: cannot find function %s: %s\n", a2, v3);
exit(1);
}
return result;
}

original_code:
static inline void *get_func_ptr(void *handle, char *sym)
{
    void *ptr = dlsym(handle, sym);
    if (!ptr) {
        fprintf(stderr, "forklimit: " "cannot find function %s: %s\n", sym, dlerror());
        exit(1);
    }
    return ptr;
}

variable_types:
handle
void *

variable_types:
sym
char *

variable_types:
ptr
void *

return_type: void *


init

decompiled_code:
char *init()
{
void *v0; // rax
void *v1; // rbx
_DWORD *v2; // rax
char *v3; // rdi
char *v4; // rax
char *result; // rax
char *v6; // rax

v0 = dlopen("libc.so.6", 1);
if ( !v0 )
{
v6 = dlerror();
fprintf(stderr, "forklimit: cannot open libc: %s\n", v6);
exit(1);
}
v1 = v0;
fork_ptr = (__int64)get_func_ptr(v0, "fork");
execve_ptr = (__int64)get_func_ptr(v1, "execve");
v2 = mmap(0LL, 4uLL, 3, 33, -1, 0LL);
fork_count = (__int64)v2;
if ( v2 == (_DWORD *)-1LL )
{
perror("forklimit: mmap");
exit(1);
}
*v2 = 0;
v3 = getenv("FORK_LIMIT");
if ( v3 )
fork_limit = atoi(v3);
if ( !fork_limit )
fork_limit = 100;
v4 = getenv("LD_PRELOAD");
result = strdup(v4);
ld_preload = result;
return result;
}

canonical_decompiled_code:
char *func7()
{
void *v0; // rax
void *v1; // rbx
_DWORD *v2; // rax
char *v3; // rdi
char *v4; // rax
char *result; // rax
char *v6; // rax

v0 = dlopen("libc.so.6", 1);
if ( !v0 )
{
v6 = dlerror();
fprintf(stderr, "forklimit: cannot open libc: %s\n", v6);
exit(1);
}
v1 = v0;
fork_ptr = (__int64)func6(v0, "fork");
execve_ptr = (__int64)func6(v1, "execve");
v2 = mmap(0LL, 4uLL, 3, 33, -1, 0LL);
fork_count = (__int64)v2;
if ( v2 == (_DWORD *)-1LL )
{
perror("forklimit: mmap");
exit(1);
}
*v2 = 0;
v3 = getenv("FORK_LIMIT");
if ( v3 )
fork_limit = atoi(v3);
if ( !fork_limit )
fork_limit = 100;
v4 = getenv("LD_PRELOAD");
result = strdup(v4);
ld_preload = result;
return result;
}

original_code:
static void __attribute__((constructor)) init(void)
{
    void *handle = dlopen("libc.so.6", 0x00001);
    if (!handle) {
        fprintf(stderr, "forklimit: " "cannot open libc: %s\n", dlerror());
        exit(1);
    }
    fork_ptr = get_func_ptr(handle, "fork");
    execve_ptr = get_func_ptr(handle, "execve");
    fork_count = mmap(((void *)0), sizeof(int), 0x1 | 0x2, 0x20 | 0x01, -1, 0);
    if (fork_count == ((void *) -1)) {
        perror("forklimit: " "mmap");
        exit(1);
    }
    *fork_count = 0;
    char *env_limit = getenv("FORK_LIMIT");
    if (env_limit)
        fork_limit = atoi(env_limit);
    if (!fork_limit)
        fork_limit = 100;
    ld_preload = strdup(getenv("LD_PRELOAD"));
}

canonical_original_code:
static void init()
{
    void *handle = dlopen("libc.so.6", 0x00001);
    if (!handle) {
        fprintf(stderr, "forklimit: " "cannot open libc: %s\n", dlerror());
        exit(1);
    }
    fork_ptr = get_func_ptr(handle, "fork");
    execve_ptr = get_func_ptr(handle, "execve");
    fork_count = mmap(((void *)0), sizeof(int), 0x1 | 0x2, 0x20 | 0x01, -1, 0);
    if (fork_count == ((void *) -1)) {
        perror("forklimit: " "mmap");
        exit(1);
    }
    *fork_count = 0;
    char *env_limit = getenv("FORK_LIMIT");
    if (env_limit)
        fork_limit = atoi(env_limit);
    if (!fork_limit)
        fork_limit = 100;
    ld_preload = strdup(getenv("LD_PRELOAD"));
}

return_type: void


fork

decompiled_code:
__int64 fork()
{
_DWORD *v0; // rdx
int v1; // eax

v0 = (_DWORD *)fork_count;
if ( *(_DWORD *)fork_count == -1 )
exit(1);
v1 = *(_DWORD *)fork_count + 1;
*(_DWORD *)fork_count = v1;
if ( v1 > fork_limit )
{
*v0 = -1;
fwrite("forklimit: fork limit exceeded\n", 1uLL, 0x1FuLL, stderr);
exit(1);
}
return fork_ptr();
}

canonical_decompiled_code:
__int64 func8()
{
_DWORD *v0; // rdx
int v1; // eax

v0 = (_DWORD *)fork_count;
if ( *(_DWORD *)fork_count == -1 )
exit(1);
v1 = *(_DWORD *)fork_count + 1;
*(_DWORD *)fork_count = v1;
if ( v1 > fork_limit )
{
*v0 = -1;
fwrite("forklimit: fork limit exceeded\n", 1uLL, 0x1FuLL, stderr);
exit(1);
}
return fork_ptr();
}

original_code:
pid_t fork(void)
{
    if (*fork_count == -1)
        exit(1);
    if (++*fork_count > fork_limit) {
        *fork_count = -1;
        fprintf(stderr, "forklimit: " "fork limit exceeded\n");
        exit(1);
    }
    return (*fork_ptr)();
}

canonical_original_code:
int fork()
{
    if (*fork_count == -1)
        exit(1);
    if (++*fork_count > fork_limit) {
        *fork_count = -1;
        fprintf(stderr, "forklimit: " "fork limit exceeded\n");
        exit(1);
    }
    return (*fork_ptr)();
}

return_type: int


execve

decompiled_code:
__int64 __fastcall execve(__int64 a1, __int64 a2, const char **a3)
{
const char *v3; // rax
const char **v6; // r13
const char *v7; // r12
const char **v8; // rbx

v3 = *a3;
if ( !*a3 )
{
LABEL_7:
fwrite("forklimit: LD_PRELOAD changed\n", 1uLL, 0x1EuLL, stderr);
exit(1);
}
v6 = a3;
v7 = ld_preload;
v8 = a3;
while ( memcmp(v3, "LD_PRELOAD", 0xAuLL) || strcmp(v3 + 11, v7) )
{
v3 = *++v8;
if ( !*v8 )
goto LABEL_7;
}
return execve_ptr(a1, a2, v6);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 a2, const char **a3)
{
const char *v3; // rax
const char **v6; // r13
const char *v7; // r12
const char **v8; // rbx

v3 = *a3;
if ( !*a3 )
{
LABEL_7:
fwrite("forklimit: LD_PRELOAD changed\n", 1uLL, 0x1EuLL, stderr);
exit(1);
}
v6 = a3;
v7 = ld_preload;
v8 = a3;
while ( memcmp(v3, "LD_PRELOAD", 0xAuLL) || strcmp(v3 + 11, v7) )
{
v3 = *++v8;
if ( !*v8 )
goto LABEL_7;
}
return execve_ptr(a1, a2, v6);
}

original_code:
int execve(const char *filename, char *const argv[], char *const envp[])
{
    for (char *const *env = envp; *env; env++) {
        if (!strncmp(*env, "LD_PRELOAD", 10) && !strcmp(*env + 11, ld_preload))
            return (*execve_ptr)(filename, argv, envp);
    }
    fprintf(stderr, "forklimit: " "LD_PRELOAD changed\n");
    exit(1);
}

canonical_original_code:
int execve(char *filename, char *argv[], char *envp[])
{
    for (char **env = envp; *env; env++) {
        if (!strncmp(*env, "LD_PRELOAD", 10) && !strcmp(*env + 11, ld_preload))
            return (*execve_ptr)(filename, argv, envp);
    }
    fprintf(stderr, "forklimit: " "LD_PRELOAD changed\n");
    exit(1);
}

variable_types:
filename
char *

variable_types:
argv
char *[]

variable_types:
envp
char *[]

variable_types:
env
char **


repo: prosig/max-subarray

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

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

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

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

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

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

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

return_type: long


decompiled_code:
void __fastcall free_matrix(void *ptr, int a2)
{
void **v2; // rbx

if ( !ptr )
{
puts("[ERROR] could not free memory for matrix - already freed");
exit(1);
}
if ( a2 > 0 )
{
v2 = (void **)ptr;
do
free(*v2++);
while ( v2 != (void **)((char *)ptr + 8 * (unsigned int)(a2 - 1) + 8) );
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func12(void *ptr, int a2)
{
void **v2; // rbx

if ( !ptr )
{
puts("[ERROR] could not free memory for matrix - already freed");
exit(1);
}
if ( a2 > 0 )
{
v2 = (void **)ptr;
do
free(*v2++);
while ( v2 != (void **)((char *)ptr + 8 * (unsigned int)(a2 - 1) + 8) );
}
free(ptr);
}

original_code:
void
free_matrix(
    int** matrix,
    int n)
{
    if(!matrix)
    {
        printf("[ERROR] could not free memory for matrix - already freed\n");
        exit(1);
    }
    else
    {
        for (int i=0; i<n; i++)
        {
            free(matrix[i]);
        }
    }
    free(matrix);
}

canonical_original_code:
void free_matrix(int **matrix, int n)
{
    if(!matrix)
    {
        printf("[ERROR] could not free memory for matrix - already freed\n");
        exit(1);
    }
    else
    {
        for (int i = 0; i<n; i++)
        {
            free(matrix[i]);
        }
    }
    free(matrix);
}

variable_types:
matrix
int **

variable_types: n int

variable_types: i int


decompiled_code:
int __fastcall print_matrix(_QWORD *a1, int a2, int a3)
{
_QWORD *v4; // rbp
__int64 v5; // r12
__int64 v6; // rbx
int result; // eax

if ( a2 > 0 )
{
v4 = a1;
v5 = 4LL * (unsigned int)(a3 - 1) + 4;
do
{
v6 = 0LL;
if ( a3 > 0 )
{
do
{
printf("%d\t", *(unsigned int *)(*v4 + v6));
v6 += 4LL;
}
while ( v6 != v5 );
}
result = putchar(10);
++v4;
}
while ( v4 != &a1[(unsigned int)(a2 - 1) + 1] );
}
return result;
}

canonical_decompiled_code:
int __fastcall func15(_QWORD *a1, int a2, int a3)
{
_QWORD *v4; // rbp
__int64 v5; // r12
__int64 v6; // rbx
int result; // eax

if ( a2 > 0 )
{
v4 = a1;
v5 = 4LL * (unsigned int)(a3 - 1) + 4;
do
{
v6 = 0LL;
if ( a3 > 0 )
{
do
{
printf("%d\t", *(unsigned int *)(*v4 + v6));
v6 += 4LL;
}
while ( v6 != v5 );
}
result = putchar(10);
++v4;
}
while ( v4 != &a1[(unsigned int)(a2 - 1) + 1] );
}
return result;
}

original_code:
void
print_matrix(
    int **matrix,
    int m,
    int n)
{
    for(int i=0; i<m; i++)
    {
        for(int j=0; j<n; j++)
        {
            printf("%d\t", matrix[i][j]);
        }
        printf("\n");
    }
}

canonical_original_code:
void print_matrix(int **matrix, int m, int n)
{
    for(int i = 0; i<m; i++)
    {
        for(int j = 0; j<n; j++)
        {
            printf("%d\t", matrix[i][j]);
        }
        printf("\n");
    }
}

variable_types: m int

variable_types: j int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // ebx
char v6[112]; // [rsp+0h] [rbp-E8h] BYREF
char buf[111]; // [rsp+70h] [rbp-78h] BYREF
char v8; // [rsp+DFh] [rbp-9h]

v3 = open("/dev/testCharDevice", 2, envp);
if ( v3 == -1 )
{
printf("file %s either does not exit, or locked by another process, or you are not root!\n", "/dev/testCharDevice");
exit(-1);
}
v4 = v3;
printf("r - read from device,\nw- write from device\nEnter command: ");
__isoc99_scanf();
if ( v8 == 114 )
{
read(v4, v6, 0x64uLL);
printf("device: %s\n", v6);
}
else if ( v8 == 119 )
{
printf("enter data: ");
__isoc99_scanf();
write(v4, buf, 0x64uLL);
}
else
{
puts("command not recognized");
}
close(v4);
return 0;
}

original_code:
int main(int argc, char *argv[])
{
  int i, fd;
  char ch, write_buf[100], read_buf[100];
  fd = open("/dev/testCharDevice", 02);
  if(fd == -1){
    printf("file %s either does not exit, or locked by another process, or you are not root!\n", "/dev/testCharDevice");
    exit(-1);
  }
  printf("r - read from device,\nw- write from device\nEnter command: ");
  scanf("%c", &ch);
  switch (ch){
  case 'w':
    printf ("enter data: ");
    scanf("%s", write_buf);
    write(fd, write_buf, sizeof(write_buf));
    break;
  case 'r':
    read(fd, read_buf, sizeof(read_buf));
    printf ("device: %s\n", read_buf);
    break;
  default:
    printf ("command not recognized\n");
    break;
  }
  close(fd);
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
  int i; int fd;
  char ch; char write_buf[100]; char read_buf[100];
  fd = open("/dev/testCharDevice", 02);
  if(fd == -1){
    printf("file %s either does not exit, or locked by another process, or you are not root!\n", "/dev/testCharDevice");
    exit(-1);
  }
  printf("r - read from device,\nw- write from device\nEnter command: ");
  scanf("%c", &ch);
  switch (ch){
  case 'w':
    printf ("enter data: ");
    scanf("%s", write_buf);
    write(fd, write_buf, sizeof(write_buf));
    break;
  case 'r':
    read(fd, read_buf, sizeof(read_buf));
    printf ("device: %s\n", read_buf);
    break;
  default:
    printf ("command not recognized\n");
    break;
  }
  close(fd);
  return 0;
}

variable_types: argc int

variable_types: fd int

variable_types: ch char


repo: psankar/simplefs

decompiled_code:
__int64 __fastcall write_root_inode(int a1)
{
__int64 result; // rax
int v2; // [rsp+0h] [rbp-28h] BYREF
__int64 v3; // [rsp+8h] [rbp-20h]
__int64 v4; // [rsp+10h] [rbp-18h]
__int64 v5; // [rsp+18h] [rbp-10h]

v2 = 0x4000;
v3 = 1LL;
v4 = 4LL;
v5 = 1LL;
if ( write(a1, &v2, 0x20uLL) == 32 )
{
puts("root directory inode written succesfully");
result = 0LL;
}
else
{
puts("The inode store was not written properly. Retry your mkfs");
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1)
{
__int64 result; // rax
int v2; // [rsp+0h] [rbp-28h] BYREF
__int64 v3; // [rsp+8h] [rbp-20h]
__int64 v4; // [rsp+10h] [rbp-18h]
__int64 v5; // [rsp+18h] [rbp-10h]

v2 = 0x4000;
v3 = 1LL;
v4 = 4LL;
v5 = 1LL;
if ( write(a1, &v2, 0x20uLL) == 32 )
{
puts("root directory inode written succesfully");
result = 0LL;
}
else
{
puts("The inode store was not written properly. Retry your mkfs");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
static int write_root_inode(int fd)
{
 ssize_t ret;
 struct simplefs_inode root_inode;
 root_inode.mode = 0040000;
 root_inode.inode_no = SIMPLEFS_ROOTDIR_INODE_NUMBER;
 root_inode.data_block_number = SIMPLEFS_ROOTDIR_DATABLOCK_NUMBER;
 root_inode.dir_children_count = 1;
 ret = write(fd, &root_inode, sizeof(root_inode));
 if (ret != sizeof(root_inode)) {
  printf
      ("The inode store was not written properly. Retry your mkfs\n");
  return -1;
 }
 printf("root directory inode written succesfully\n");
 return 0;
}

canonical_original_code:
static int write_root_inode(int fd)
{
 long ret;
 struct simplefs_inode root_inode;
 root_inode.mode = 0040000;
 root_inode.inode_no = SIMPLEFS_ROOTDIR_INODE_NUMBER;
 root_inode.data_block_number = SIMPLEFS_ROOTDIR_DATABLOCK_NUMBER;
 root_inode.dir_children_count = 1;
 ret = write(fd, &root_inode, sizeof(root_inode));
 if (ret != sizeof(root_inode)) {
  printf
      ("The inode store was not written properly. Retry your mkfs\n");
  return -1;
 }
 printf("root directory inode written succesfully\n");
 return 0;
}

variable_types: ret long

variable_types: struct simplefs_inode { unsigned int mode; unsigned long inode_no; unsigned long data_block_number; union { unsigned long file_size; unsigned long dir_children_count; }; }


decompiled_code:
__int64 __fastcall write_journal_inode(int a1)
{
__int64 result; // rax
_QWORD v2[5]; // [rsp+0h] [rbp-28h] BYREF

v2[1] = 2LL;
v2[2] = 2LL;
if ( write(a1, v2, 0x20uLL) == 32 )
{
puts("journal inode written succesfully");
result = 0LL;
}
else
{
puts("Error while writing journal inode. Retry your mkfs");
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1)
{
__int64 result; // rax
_QWORD v2[5]; // [rsp+0h] [rbp-28h] BYREF

v2[1] = 2LL;
v2[2] = 2LL;
if ( write(a1, v2, 0x20uLL) == 32 )
{
puts("journal inode written succesfully");
result = 0LL;
}
else
{
puts("Error while writing journal inode. Retry your mkfs");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
static int write_journal_inode(int fd)
{
 ssize_t ret;
 struct simplefs_inode journal;
 journal.inode_no = SIMPLEFS_JOURNAL_INODE_NUMBER;
 journal.data_block_number = SIMPLEFS_JOURNAL_BLOCK_NUMBER;
 ret = write(fd, &journal, sizeof(journal));
 if (ret != sizeof(journal)) {
  printf("Error while writing journal inode. Retry your mkfs\n");
  return -1;
 }
 printf("journal inode written succesfully\n");
 return 0;
}

canonical_original_code:
static int write_journal_inode(int fd)
{
 long ret;
 struct simplefs_inode journal;
 journal.inode_no = SIMPLEFS_JOURNAL_INODE_NUMBER;
 journal.data_block_number = SIMPLEFS_JOURNAL_BLOCK_NUMBER;
 ret = write(fd, &journal, sizeof(journal));
 if (ret != sizeof(journal)) {
  printf("Error while writing journal inode. Retry your mkfs\n");
  return -1;
 }
 printf("journal inode written succesfully\n");
 return 0;
}

user_defined_types: struct simplefs_inode { unsigned int mode; unsigned long inode_no; unsigned long data_block_number; union { unsigned long file_size; unsigned long dir_children_count; }; }


decompiled_code:
__int64 __fastcall write_welcome_inode(int fd, const void *a2)
{
__int64 result; // rax

if ( write(fd, a2, 0x20uLL) == 32 )
{
puts("welcomefile inode written succesfully");
if ( lseek(fd, 4000LL, 1) == -1 )
{
puts("The padding bytes are not written properly. Retry your mkfs");
result = 0xFFFFFFFFLL;
}
else
{
puts("inode store padding bytes (after the three inodes) written sucessfully");
result = 0LL;
}
}
else
{
puts("The welcomefile inode was not written properly. Retry your mkfs");
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(int fd, const void *a2)
{
__int64 result; // rax

if ( write(fd, a2, 0x20uLL) == 32 )
{
puts("welcomefile inode written succesfully");
if ( lseek(fd, 4000LL, 1) == -1 )
{
puts("The padding bytes are not written properly. Retry your mkfs");
result = 0xFFFFFFFFLL;
}
else
{
puts("inode store padding bytes (after the three inodes) written sucessfully");
result = 0LL;
}
}
else
{
puts("The welcomefile inode was not written properly. Retry your mkfs");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
static int write_welcome_inode(int fd, const struct simplefs_inode *i)
{
 off_t nbytes;
 ssize_t ret;
 ret = write(fd, i, sizeof(*i));
 if (ret != sizeof(*i)) {
  printf
      ("The welcomefile inode was not written properly. Retry your mkfs\n");
  return -1;
 }
 printf("welcomefile inode written succesfully\n");
 nbytes = 4096 - (sizeof(*i) * 3);
 ret = lseek(fd, nbytes, 1);
 if (ret == (off_t)-1) {
  printf
      ("The padding bytes are not written properly. Retry your mkfs\n");
  return -1;
 }
 printf
     ("inode store padding bytes (after the three inodes) written sucessfully\n");
 return 0;
}

canonical_original_code:
static int write_welcome_inode(int fd, struct simplefs_inode *i)
{
 long nbytes;
 long ret;
 ret = write(fd, i, sizeof(*i));
 if (ret != sizeof(*i)) {
  printf
      ("The welcomefile inode was not written properly. Retry your mkfs\n");
  return -1;
 }
 printf("welcomefile inode written succesfully\n");
 nbytes = 4096 - (sizeof(*i) * 3);
 ret = lseek(fd, nbytes, 1);
 if (ret == (off_t)-1) {
  printf
      ("The padding bytes are not written properly. Retry your mkfs\n");
  return -1;
 }
 printf
     ("inode store padding bytes (after the three inodes) written sucessfully\n");
 return 0;
}

variable_types: struct simplefs_inode { unsigned int mode; unsigned long inode_no; unsigned long data_block_number; union { unsigned long file_size; unsigned long dir_children_count; }; } *

variable_types: nbytes long


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

if ( lseek(a1, 0x2000LL, 1) == -1 )
{
puts("Can't write journal. Retry you mkfs");
result = 0xFFFFFFFFLL;
}
else
{
puts("Journal written successfully");
result = 0LL;
}
return result;
}

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

if ( lseek(a1, 0x2000LL, 1) == -1 )
{
puts("Can't write journal. Retry you mkfs");
result = 0xFFFFFFFFLL;
}
else
{
puts("Journal written successfully");
result = 0LL;
}
return result;
}

original_code:
int write_journal(int fd)
{
 ssize_t ret;
 ret = lseek(fd, 4096 * SIMPLEFS_JOURNAL_BLOCKS, 1);
 if (ret == (off_t)-1) {
  printf("Can't write journal. Retry you mkfs\n");
  return -1;
 }
 printf("Journal written successfully\n");
 return 0;
}

canonical_original_code:
int write_journal(int fd)
{
 long ret;
 ret = lseek(fd, 4096 * SIMPLEFS_JOURNAL_BLOCKS, 1);
 if (ret == (off_t)-1) {
  printf("Can't write journal. Retry you mkfs\n");
  return -1;
 }
 printf("Journal written successfully\n");
 return 0;
}


decompiled_code:
__int64 __fastcall write_dirent(int fd, const void *a2)
{
__int64 result; // rax

if ( write(fd, a2, 0x108uLL) == 264 )
{
puts("root directory datablocks (name+inode_no pair for welcomefile) written succesfully");
if ( lseek(fd, 3832LL, 1) == -1 )
{
puts("Writing the padding for rootdirectory children datablock has failed");
result = 0xFFFFFFFFLL;
}
else
{
puts("padding after the rootdirectory children written succesfully");
result = 0LL;
}
}
else
{
puts("Writing the rootdirectory datablock (name+inode_no pair for welcomefile) has failed");
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(int fd, const void *a2)
{
__int64 result; // rax

if ( write(fd, a2, 0x108uLL) == 264 )
{
puts("root directory datablocks (name+inode_no pair for welcomefile) written succesfully");
if ( lseek(fd, 3832LL, 1) == -1 )
{
puts("Writing the padding for rootdirectory children datablock has failed");
result = 0xFFFFFFFFLL;
}
else
{
puts("padding after the rootdirectory children written succesfully");
result = 0LL;
}
}
else
{
puts("Writing the rootdirectory datablock (name+inode_no pair for welcomefile) has failed");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int write_dirent(int fd, const struct simplefs_dir_record *record)
{
 ssize_t nbytes = sizeof(*record), ret;
 ret = write(fd, record, nbytes);
 if (ret != nbytes) {
  printf
      ("Writing the rootdirectory datablock (name+inode_no pair for welcomefile) has failed\n");
  return -1;
 }
 printf
     ("root directory datablocks (name+inode_no pair for welcomefile) written succesfully\n");
 nbytes = 4096 - sizeof(*record);
 ret = lseek(fd, nbytes, 1);
 if (ret == (off_t)-1) {
  printf
      ("Writing the padding for rootdirectory children datablock has failed\n");
  return -1;
 }
 printf
     ("padding after the rootdirectory children written succesfully\n");
 return 0;
}

canonical_original_code:
int write_dirent(int fd, struct simplefs_dir_record *record)
{
 long nbytes = sizeof(*record); long ret;
 ret = write(fd, record, nbytes);
 if (ret != nbytes) {
  printf
      ("Writing the rootdirectory datablock (name+inode_no pair for welcomefile) has failed\n");
  return -1;
 }
 printf
     ("root directory datablocks (name+inode_no pair for welcomefile) written succesfully\n");
 nbytes = 4096 - sizeof(*record);
 ret = lseek(fd, nbytes, 1);
 if (ret == (off_t)-1) {
  printf
      ("Writing the padding for rootdirectory children datablock has failed\n");
  return -1;
 }
 printf
     ("padding after the rootdirectory children written succesfully\n");
 return 0;
}

variable_types: struct simplefs_dir_record { char filename[255]; unsigned long inode_no; } *


decompiled_code:
__int64 __fastcall write_block(int a1, const void *a2, size_t a3)
{
__int64 result; // rax

if ( a3 == write(a1, a2, a3) )
{
puts("block has been written succesfully");
result = 0LL;
}
else
{
puts("Writing file body has failed");
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(int a1, const void *a2, size_t a3)
{
__int64 result; // rax

if ( a3 == write(a1, a2, a3) )
{
puts("block has been written succesfully");
result = 0LL;
}
else
{
puts("Writing file body has failed");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int write_block(int fd, char *block, size_t len)
{
 ssize_t ret;
 ret = write(fd, block, len);
 if (ret != len) {
  printf("Writing file body has failed\n");
  return -1;
 }
 printf("block has been written succesfully\n");
 return 0;
}

canonical_original_code:
int write_block(int fd, char *block, unsigned long len)
{
 long ret;
 ret = write(fd, block, len);
 if (ret != len) {
  printf("Writing file body has failed\n");
  return -1;
 }
 printf("block has been written succesfully\n");
 return 0;
}

variable_types:
block
char *

variable_types:
len
unsigned long


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // ebx
_BOOL4 v5; // ebp
_BYTE v7[272]; // [rsp+0h] [rbp-178h] BYREF
int v8; // [rsp+110h] [rbp-68h] BYREF
__int64 v9; // [rsp+118h] [rbp-60h]
__int64 v10; // [rsp+120h] [rbp-58h]
size_t v11; // [rsp+128h] [rbp-50h]
char v12[72]; // [rsp+130h] [rbp-48h] BYREF

strcpy(v12, "Love is God. God is Love. Anbe Murugan.\n");
v8 = 0x8000;
v9 = 3LL;
v10 = 5LL;
v11 = 41LL;
qmemcpy(v7, "vanakkam", 0x108uLL);
if ( argc == 2 )
{
v3 = open(argv[1], 2);
v4 = v3;
if ( v3 == -1 )
{
perror("Error opening the device");
}
else
{
v5 = 1;
if ( !(unsigned int)write_superblock(v3)
&& !(unsigned int)write_root_inode(v4)
&& !(unsigned int)write_journal_inode(v4)
&& !(unsigned int)write_welcome_inode(v4, &v8)
&& !(unsigned int)write_journal(v4)
&& !(unsigned int)write_dirent(v4, v7) )
{
v5 = write_block(v4, v12, v11) != 0;
}
close(v4);
v4 = v5;
}
}
else
{
puts("Usage: mkfs-simplefs <device>");
v4 = -1;
}
return v4;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // ebx
_BOOL4 v5; // ebp
_BYTE v7[272]; // [rsp+0h] [rbp-178h] BYREF
int v8; // [rsp+110h] [rbp-68h] BYREF
__int64 v9; // [rsp+118h] [rbp-60h]
__int64 v10; // [rsp+120h] [rbp-58h]
size_t v11; // [rsp+128h] [rbp-50h]
char v12[72]; // [rsp+130h] [rbp-48h] BYREF

strcpy(v12, "Love is God. God is Love. Anbe Murugan.\n");
v8 = 0x8000;
v9 = 3LL;
v10 = 5LL;
v11 = 41LL;
qmemcpy(v7, "vanakkam", 0x108uLL);
if ( argc == 2 )
{
v3 = open(argv[1], 2);
v4 = v3;
if ( v3 == -1 )
{
perror("Error opening the device");
}
else
{
v5 = 1;
if ( !(unsigned int)func10(v3)
&& !(unsigned int)func7(v4)
&& !(unsigned int)func8(v4)
&& !(unsigned int)func9(v4, &v8)
&& !(unsigned int)func11(v4)
&& !(unsigned int)func12(v4, v7) )
{
v5 = func13(v4, v12, v11) != 0;
}
close(v4);
v4 = v5;
}
}
else
{
puts("Usage: mkfs-simplefs <device>");
v4 = -1;
}
return v4;
}

original_code:
int main(int argc, char *argv[])
{
 int fd;
 ssize_t ret;
 char welcomefile_body[] = "Love is God. God is Love. Anbe Murugan.\n";
 struct simplefs_inode welcome = {
  .mode = 0100000,
  .inode_no = (SIMPLEFS_JOURNAL_INODE_NUMBER + 1),
  .data_block_number = (SIMPLEFS_ROOTDIR_DATABLOCK_NUMBER + 1),
  .file_size = sizeof(welcomefile_body),
 };
 struct simplefs_dir_record record = {
  .filename = "vanakkam",
  .inode_no = (SIMPLEFS_JOURNAL_INODE_NUMBER + 1),
 };
 if (argc != 2) {
  printf("Usage: mkfs-simplefs <device>\n");
  return -1;
 }
 fd = open(argv[1], 02);
 if (fd == -1) {
  perror("Error opening the device");
  return -1;
 }
 ret = 1;
 do {
  if (write_superblock(fd))
   break;
  if (write_root_inode(fd))
   break;
  if (write_journal_inode(fd))
   break;
  if (write_welcome_inode(fd, &welcome))
   break;
  if (write_journal(fd))
   break;
  if (write_dirent(fd, &record))
   break;
  if (write_block(fd, welcomefile_body, welcome.file_size))
   break;
  ret = 0;
 } while (0);
 close(fd);
 return ret;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 int fd;
 long ret;
 char welcomefile_body[] = "Love is God. God is Love. Anbe Murugan.\n";
 struct simplefs_inode welcome = {
  .mode = 0100000,
  .inode_no = (SIMPLEFS_JOURNAL_INODE_NUMBER + 1),
  .data_block_number = (SIMPLEFS_ROOTDIR_DATABLOCK_NUMBER + 1),
  .file_size = sizeof(welcomefile_body),
 };
 struct simplefs_dir_record record = {
  .filename = "vanakkam",
  .inode_no = (SIMPLEFS_JOURNAL_INODE_NUMBER + 1),
 };
 if (argc != 2) {
  printf("Usage: mkfs-simplefs <device>\n");
  return -1;
 }
 fd = open(argv[1], 02);
 if (fd == -1) {
  perror("Error opening the device");
  return -1;
 }
 ret = 1;
 do {
  if (write_superblock(fd))
   break;
  if (write_root_inode(fd))
   break;
  if (write_journal_inode(fd))
   break;
  if (write_welcome_inode(fd, &welcome))
   break;
  if (write_journal(fd))
   break;
  if (write_dirent(fd, &record))
   break;
  if (write_block(fd, welcomefile_body, welcome.file_size))
   break;
  ret = 0;
 } while (0);
 close(fd);
 return ret;
}

variable_types:
argv
char *[]

variable_types: struct simplefs_dir_record { char filename[255]; unsigned long inode_no; }


createdisk

decompiled_code:
void __fastcall createdisk(char *file, int a2)
{
_DWORD *v2; // rbx
int v3; // eax
ssize_t v4; // rax

printf("Creating disk %s\n", file);
v2 = malloc(0x200uLL);
v3 = creat(file, 0x1C0u);
if ( v3 == -1 )
{
puts("createdisk creat() failed");
perror("createdisk");
exit(-1);
}
*v2 = -1;
v2[1] = 0;
v2[2] = 512;
v2[3] = a2;
v4 = write(v3, v2, 0x200uLL);
if ( v4 == -1 )
{
puts("createdisk: write failed");
perror("createdisk");
exit(-1);
}
if ( v2[2] != v4 )
{
puts("createdisk: write failed, too few bytes written");
perror("createdisk");
exit(-1);
}
close(*v2);
free(v2);
}

canonical_decompiled_code:
void __fastcall func7(char *file, int a2)
{
_DWORD *v2; // rbx
int v3; // eax
ssize_t v4; // rax

printf("Creating disk %s\n", file);
v2 = malloc(0x200uLL);
v3 = creat(file, 0x1C0u);
if ( v3 == -1 )
{
puts("createdisk creat() failed");
perror("createdisk");
exit(-1);
}
*v2 = -1;
v2[1] = 0;
v2[2] = 512;
v2[3] = a2;
v4 = write(v3, v2, 0x200uLL);
if ( v4 == -1 )
{
puts("createdisk: write failed");
perror("createdisk");
exit(-1);
}
if ( v2[2] != v4 )
{
puts("createdisk: write failed, too few bytes written");
perror("createdisk");
exit(-1);
}
close(*v2);
free(v2);
}

original_code:
void createdisk(char *disk_name, int size)
{
  printf("Creating disk %s\n", disk_name);
  int fd;
  disk_t disk = malloc(512);
  ssize_t bytes_written;
  fd = creat(disk_name, (0400|0200|0100));
  if(fd == -1) {
    printf("createdisk creat() failed\n");
    perror("createdisk");
    exit(-1);
  }
  disk->fd = -1;
  disk->last_block = 0;
  disk->block_size = 512;
  disk->size = size;
  bytes_written = write(fd, disk, 512);
  if(bytes_written == -1) {
    printf("createdisk: write failed\n");
    perror("createdisk");
    exit(-1);
  }
  if(bytes_written != disk->block_size) {
    printf("createdisk: write failed, too few bytes written\n");
    perror("createdisk");
    exit(-1);
  }
  close(disk->fd);
  free(disk);
  return;
}

canonical_original_code:
void createdisk(char *disk_name, int size)
{
  printf("Creating disk %s\n", disk_name);
  int fd;
  struct diskt *disk = malloc(512);
  long bytes_written;
  fd = creat(disk_name, (0400|0200|0100));
  if(fd == -1) {
    printf("createdisk creat() failed\n");
    perror("createdisk");
    exit(-1);
  }
  disk->fd = -1;
  disk->last_block = 0;
  disk->block_size = 512;
  disk->size = size;
  bytes_written = write(fd, disk, 512);
  if(bytes_written == -1) {
    printf("createdisk: write failed\n");
    perror("createdisk");
    exit(-1);
  }
  if(bytes_written != disk->block_size) {
    printf("createdisk: write failed, too few bytes written\n");
    perror("createdisk");
    exit(-1);
  }
  close(disk->fd);
  free(disk);
  return;
}

variable_types: size int

variable_types: struct diskt { int fd; int last_block; int block_size; int size; } *


opendisk

decompiled_code:
unsigned int *__fastcall opendisk(char *file)
{
unsigned int *v1; // rbx
int v2; // eax
int v3; // er12

v1 = (unsigned int *)malloc(0x200uLL);
printf("Opening disk %s\n", file);
v2 = open(file, 2);
if ( v2 == -1 )
{
puts("opendisk failed");
perror("opendisk");
exit(-1);
}
v3 = v2;
read(v2, v1, 0x200uLL);
*v1 = v3;
printf("Disk %s opened. size = %d, block size = %d\n", file, v1[3], v1[2]);
return v1;
}

canonical_decompiled_code:
unsigned int *__fastcall func8(char *file)
{
unsigned int *v1; // rbx
int v2; // eax
int v3; // er12

v1 = (unsigned int *)malloc(0x200uLL);
printf("Opening disk %s\n", file);
v2 = open(file, 2);
if ( v2 == -1 )
{
puts("opendisk failed");
perror("opendisk");
exit(-1);
}
v3 = v2;
read(v2, v1, 0x200uLL);
*v1 = v3;
printf("Disk %s opened. size = %d, block size = %d\n", file, v1[3], v1[2]);
return v1;
}

original_code:
disk_t opendisk(char *disk_name)
{
  int fd;
  disk_t disk = malloc(512);
  printf("Opening disk %s\n", disk_name);
  fd = open(disk_name, 02);
  if(fd == -1) {
    printf("opendisk failed\n");
    perror("opendisk");
    exit(-1);
  }
  read(fd, (void *) disk, 512);
  disk->fd = fd;
  printf("Disk %s opened. size = %d, block size = %d\n", disk_name, disk->size, disk->block_size);
  return(disk);
}

canonical_original_code:
struct diskt *opendisk(char *disk_name)
{
  int fd;
  struct diskt *disk = malloc(512);
  printf("Opening disk %s\n", disk_name);
  fd = open(disk_name, 02);
  if(fd == -1) {
    printf("opendisk failed\n");
    perror("opendisk");
    exit(-1);
  }
  read(fd, (void *) disk, 512);
  disk->fd = fd;
  printf("Disk %s opened. size = %d, block size = %d\n", disk_name, disk->size, disk->block_size);
  return(disk);
}

return_type: struct diskt { int fd; int last_block; int block_size; int size; } *


seekblock

decompiled_code:
__off_t __fastcall seekblock(int *a1, int a2)
{
__off_t result; // rax

if ( a2 < 0 )
{
puts("seekblock: tried to seek below the beginning of the disk!");
printf("seekblock: seek block %d, disk size is %d.\n", (unsigned int)a2, (unsigned int)a1[3]);
exit(-1);
}
if ( a1[3] <= a2 )
{
puts("seekblock: tried to seek past the end of the disk!");
printf(
"seekblock: seek block %d. Disk size is %d, so last block is %d.\n",
(unsigned int)a2,
(unsigned int)a1[3],
(unsigned int)(a1[3] - 1));
exit(-1);
}
result = lseek(*a1, a1[2] * (a2 + 1), 0);
if ( result == -1 )
{
puts("seekblock: lseek failed");
perror("seekblock");
exit(-1);
}
a1[1] = a2;
return result;
}

canonical_decompiled_code:
__off_t __fastcall func9(int *a1, int a2)
{
__off_t result; // rax

if ( a2 < 0 )
{
puts("seekblock: tried to seek below the beginning of the disk!");
printf("seekblock: seek block %d, disk size is %d.\n", (unsigned int)a2, (unsigned int)a1[3]);
exit(-1);
}
if ( a1[3] <= a2 )
{
puts("seekblock: tried to seek past the end of the disk!");
printf(
"seekblock: seek block %d. Disk size is %d, so last block is %d.\n",
(unsigned int)a2,
(unsigned int)a1[3],
(unsigned int)(a1[3] - 1));
exit(-1);
}
result = lseek(*a1, a1[2] * (a2 + 1), 0);
if ( result == -1 )
{
puts("seekblock: lseek failed");
perror("seekblock");
exit(-1);
}
a1[1] = a2;
return result;
}

original_code:
int seekblock(disk_t disk, int block)
{
  off_t offset;
  if(block < 0) {
    printf("seekblock: tried to seek below the beginning of the disk!\n");
    printf("seekblock: seek block %d, disk size is %d.\n", block, disk->size);
    exit(-1);
  }
  if(block >= disk->size) {
    printf("seekblock: tried to seek past the end of the disk!\n");
    printf("seekblock: seek block %d.  Disk size is %d, so last block is %d.\n", block, disk->size, disk->size-1);
    exit(-1);
  }
  offset = lseek(disk->fd, (block+1)*disk->block_size, 0);
  if(offset == -1) {
    printf("seekblock: lseek failed\n");
    perror("seekblock");
    exit(-1);
  }
  disk->last_block = block;
}

canonical_original_code:
int seekblock(struct diskt *disk, int block)
{
  long offset;
  if(block < 0) {
    printf("seekblock: tried to seek below the beginning of the disk!\n");
    printf("seekblock: seek block %d, disk size is %d.\n", block, disk->size);
    exit(-1);
  }
  if(block >= disk->size) {
    printf("seekblock: tried to seek past the end of the disk!\n");
    printf("seekblock: seek block %d.  Disk size is %d, so last block is %d.\n", block, disk->size, disk->size-1);
    exit(-1);
  }
  offset = lseek(disk->fd, (block+1)*disk->block_size, 0);
  if(offset == -1) {
    printf("seekblock: lseek failed\n");
    perror("seekblock");
    exit(-1);
  }
  disk->last_block = block;
}

variable_types: block int

variable_types: offset long

user_defined_types: struct diskt { int fd; int last_block; int block_size; int size; }


readblock

decompiled_code:
__int64 __fastcall readblock(int *a1, int a2, void *a3)
{
ssize_t v4; // rax

if ( a2 < 0 )
{
puts("readblock: There are no blocks < 0!!!");
exit(-1);
}
if ( a1[3] <= a2 )
{
puts("readblock: tried to read past the end of the disk!");
printf("readblock: read block %d, disk size is %d.\n", (unsigned int)a2, (unsigned int)a1[3]);
exit(-1);
}
if ( a1[1] + 1 != a2 )
seekblock(a1, a2);
v4 = read(*a1, a3, a1[2]);
if ( v4 == -1 )
{
puts("readblock read failed");
perror("readblock");
exit(-1);
}
if ( a1[2] != v4 )
{
puts("readblock: read failed, too few bytes read");
puts("readblock: probably because you read data that was not previously written.");
perror("readblock");
exit(-1);
}
a1[1] = a2;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(int *a1, int a2, void *a3)
{
ssize_t v4; // rax

if ( a2 < 0 )
{
puts("readblock: There are no blocks < 0!!!");
exit(-1);
}
if ( a1[3] <= a2 )
{
puts("readblock: tried to read past the end of the disk!");
printf("readblock: read block %d, disk size is %d.\n", (unsigned int)a2, (unsigned int)a1[3]);
exit(-1);
}
if ( a1[1] + 1 != a2 )
func9(a1, a2);
v4 = read(*a1, a3, a1[2]);
if ( v4 == -1 )
{
puts("readblock read failed");
perror("readblock");
exit(-1);
}
if ( a1[2] != v4 )
{
puts("readblock: read failed, too few bytes read");
puts("readblock: probably because you read data that was not previously written.");
perror("readblock");
exit(-1);
}
a1[1] = a2;
return 0LL;
}

original_code:
int readblock(disk_t disk, int block, unsigned char *databuf)
{
  off_t offset;
  ssize_t bytes_read;
  if(block < 0) {
    printf("readblock: There are no blocks < 0!!!\n");
    exit(-1);
  }
  if(block >= disk->size) {
    printf("readblock: tried to read past the end of the disk!\n");
    printf("readblock: read block %d, disk size is %d.\n", block, disk->size);
    exit(-1);
  }
  if(block != disk->last_block+1)
    seekblock(disk, block);
  bytes_read = read(disk->fd, (void *)databuf, disk->block_size);
  if(bytes_read == -1) {
    printf("readblock read failed\n");
    perror("readblock");
    exit(-1);
  }
  if(bytes_read != disk->block_size) {
    printf("readblock: read failed, too few bytes read\n");
    printf("readblock: probably because you read data that was not previously written.\n");
    perror("readblock");
    exit(-1);
  }
  disk->last_block = block;
  return 0;
}

canonical_original_code:
int readblock(struct diskt *disk, int block, unsigned char *databuf)
{
  long offset;
  long bytes_read;
  if(block < 0) {
    printf("readblock: There are no blocks < 0!!!\n");
    exit(-1);
  }
  if(block >= disk->size) {
    printf("readblock: tried to read past the end of the disk!\n");
    printf("readblock: read block %d, disk size is %d.\n", block, disk->size);
    exit(-1);
  }
  if(block != disk->last_block+1)
    seekblock(disk, block);
  bytes_read = read(disk->fd, (void *)databuf, disk->block_size);
  if(bytes_read == -1) {
    printf("readblock read failed\n");
    perror("readblock");
    exit(-1);
  }
  if(bytes_read != disk->block_size) {
    printf("readblock: read failed, too few bytes read\n");
    printf("readblock: probably because you read data that was not previously written.\n");
    perror("readblock");
    exit(-1);
  }
  disk->last_block = block;
  return 0;
}

variable_types:
databuf
unsigned char *


writeblock

decompiled_code:
__int64 __fastcall writeblock(int *a1, int a2, const void *a3)
{
ssize_t v4; // rax

if ( a2 < 0 )
{
puts("writeblock: There are no blocks < 0!!!");
exit(-1);
}
if ( a1[3] <= a2 )
{
puts("writeblock: tried to write past the end of the disk!");
printf("writeblock: write block %d, disk size is %d.\n", (unsigned int)a2, (unsigned int)a1[3]);
exit(-1);
}
if ( a1[1] + 1 != a2 )
seekblock(a1, a2);
a1[1] = a2;
v4 = write(*a1, a3, a1[2]);
if ( v4 == -1 )
{
puts("writeblock failed");
perror("writeblock");
exit(-1);
}
if ( a1[2] != v4 )
{
puts("writeblock: write failed, too few bytes written");
perror("writeblock");
exit(-1);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func11(int *a1, int a2, const void *a3)
{
ssize_t v4; // rax

if ( a2 < 0 )
{
puts("writeblock: There are no blocks < 0!!!");
exit(-1);
}
if ( a1[3] <= a2 )
{
puts("writeblock: tried to write past the end of the disk!");
printf("writeblock: write block %d, disk size is %d.\n", (unsigned int)a2, (unsigned int)a1[3]);
exit(-1);
}
if ( a1[1] + 1 != a2 )
func9(a1, a2);
a1[1] = a2;
v4 = write(*a1, a3, a1[2]);
if ( v4 == -1 )
{
puts("writeblock failed");
perror("writeblock");
exit(-1);
}
if ( a1[2] != v4 )
{
puts("writeblock: write failed, too few bytes written");
perror("writeblock");
exit(-1);
}
return 0LL;
}

original_code:
int writeblock(disk_t disk, int block, unsigned char *databuf)
{
  off_t offset;
  ssize_t bytes_written;
  if(block < 0) {
    printf("writeblock: There are no blocks < 0!!!\n");
    exit(-1);
  }
  if(block >= disk->size) {
    printf("writeblock: tried to write past the end of the disk!\n");
    printf("writeblock: write block %d, disk size is %d.\n", block, disk->size);
    exit(-1);
  }
  if(block != disk->last_block + 1)
    seekblock(disk, block);
  disk->last_block = block;
  bytes_written = write(disk->fd, databuf, disk->block_size);
  if(bytes_written == -1) {
    printf("writeblock failed\n");
    perror("writeblock");
    exit(-1);
  }
  if(bytes_written != disk->block_size) {
    printf("writeblock: write failed, too few bytes written\n");
    perror("writeblock");
    exit(-1);
  }
  return 0;
}

canonical_original_code:
int writeblock(struct diskt *disk, int block, unsigned char *databuf)
{
  long offset;
  long bytes_written;
  if(block < 0) {
    printf("writeblock: There are no blocks < 0!!!\n");
    exit(-1);
  }
  if(block >= disk->size) {
    printf("writeblock: tried to write past the end of the disk!\n");
    printf("writeblock: write block %d, disk size is %d.\n", block, disk->size);
    exit(-1);
  }
  if(block != disk->last_block + 1)
    seekblock(disk, block);
  disk->last_block = block;
  bytes_written = write(disk->fd, databuf, disk->block_size);
  if(bytes_written == -1) {
    printf("writeblock failed\n");
    perror("writeblock");
    exit(-1);
  }
  if(bytes_written != disk->block_size) {
    printf("writeblock: write failed, too few bytes written\n");
    perror("writeblock");
    exit(-1);
  }
  return 0;
}


usage

repo: psi-im/psimedia

decompiled_code:
int usage()
{
puts("usage: alsalatency rec (capture_device)");
puts(" alsalatency loop (play_device) (capture_device)");
putchar(10);
return puts("note: if capture_device or play_device are omitted, 'default' is assumed.\n");
}

canonical_decompiled_code:
int func7()
{
puts("usage: alsalatency rec (capture_device)");
puts(" alsalatency loop (play_device) (capture_device)");
putchar(10);
return puts("note: if capture_device or play_device are omitted, 'default' is assumed.\n");
}

original_code:
static void usage()
{
    printf("usage: alsalatency rec  (capture_device)\n");
    printf("       alsalatency loop (play_device) (capture_device)\n");
    printf("\n");
    printf("note: if capture_device or play_device are omitted, 'default' is assumed.\n\n");
}


repo: psilord/manifold

original_code:
void intqueue_free(IntQueue *iq)
{
 Symbol **sq = ((void *)0);
 int i, j;
 for (i = 0; i < iq->num_slices; i++)
 {
  sq = iq->slice[i];
  for (j = iq->slice_top[i]; j < iq->num_syms; j++)
  {
   if (sq[j] != ((void *)0))
   {
    symbol_free(sq[j]);
   }
  }
  free(iq->slice[i]);
 }
 free(iq->slice);
 free(iq->slice_top);
}

canonical_original_code:
void intqueue_free(struct IntQueue_s *iq)
{
 struct Symbol_s **sq = ((void *)0);
 int i; int j;
 for (i = 0; i < iq->num_slices; i++)
 {
  sq = iq->slice[i];
  for (j = iq->slice_top[i]; j < iq->num_syms; j++)
  {
   if (sq[j] != ((void *)0))
   {
    symbol_free(sq[j]);
   }
  }
  free(iq->slice[i]);
 }
 free(iq->slice);
 free(iq->slice_top);
}

variable_types: struct IntQueue_s { int num_syms; int num_slices; struct Symbol_s { unsigned short dim; float vec[1]; } ***slice; int *slice_top; int curr_slice; int ready; int ready_slice; } *

variable_types: i int

variable_types: j int

user_defined_types: struct IntQueue_s { int num_syms; int num_slices; struct Symbol_s ***slice; int *slice_top; int curr_slice; int ready; int ready_slice; }


original_code:
void intqueue_enqueue(IntQueue *iq, Symbol *sym)
{
 int i;
 Symbol **sq = ((void *)0);
 sq = iq->slice[iq->curr_slice];
 switch(iq->slice_top[iq->curr_slice])
 {
  case 0:
   symbol_free(sq[0]);
   for (i = 1; i < iq->num_syms; i++)
   {
    sq[i-1] = sq[i];
   }
   (iq->slice[iq->curr_slice])[iq->num_syms - 1] = sym;
   iq->ready = TRUE;
   iq->ready_slice = iq->curr_slice;
   break;
  case 1:
   for (i = iq->slice_top[iq->curr_slice]; i < iq->num_syms; i++)
   {
    sq[i-1] = sq[i];
   }
   (iq->slice[iq->curr_slice])[iq->num_syms - 1] = sym;
   iq->slice_top[iq->curr_slice]--;
   iq->ready = TRUE;
   iq->ready_slice = iq->curr_slice;
   break;
  default:
   for (i = iq->slice_top[iq->curr_slice]; i < iq->num_syms; i++)
   {
    sq[i-1] = sq[i];
   }
   (iq->slice[iq->curr_slice])[iq->num_syms - 1] = sym;
   iq->slice_top[iq->curr_slice]--;
   if (iq->ready == TRUE)
   {
    printf("intqueue_enqueue(): cannot go from ready to "
     "nonready!\n");
    exit(1);
   }
   iq->ready = FALSE;
   break;
 }
 iq->curr_slice = (iq->curr_slice + 1) % iq->num_slices;
}

canonical_original_code:
void intqueue_enqueue(struct IntQueue_s *iq, struct Symbol_s *sym)
{
 int i;
 struct Symbol_s **sq = ((void *)0);
 sq = iq->slice[iq->curr_slice];
 switch(iq->slice_top[iq->curr_slice])
 {
  case 0:
   symbol_free(sq[0]);
   for (i = 1; i < iq->num_syms; i++)
   {
    sq[i-1] = sq[i];
   }
   (iq->slice[iq->curr_slice])[iq->num_syms - 1] = sym;
   iq->ready = TRUE;
   iq->ready_slice = iq->curr_slice;
   break;
  case 1:
   for (i = iq->slice_top[iq->curr_slice]; i < iq->num_syms; i++)
   {
    sq[i-1] = sq[i];
   }
   (iq->slice[iq->curr_slice])[iq->num_syms - 1] = sym;
   iq->slice_top[iq->curr_slice]--;
   iq->ready = TRUE;
   iq->ready_slice = iq->curr_slice;
   break;
  default:
   for (i = iq->slice_top[iq->curr_slice]; i < iq->num_syms; i++)
   {
    sq[i-1] = sq[i];
   }
   (iq->slice[iq->curr_slice])[iq->num_syms - 1] = sym;
   iq->slice_top[iq->curr_slice]--;
   if (iq->ready == TRUE)
   {
    printf("intqueue_enqueue(): cannot go from ready to "
     "nonready!\n");
    exit(1);
   }
   iq->ready = FALSE;
   break;
 }
 iq->curr_slice = (iq->curr_slice + 1) % iq->num_slices;
}

variable_types:
sym
struct Symbol_s *

variable_types: struct Symbol_s { unsigned short dim; float vec[1]; } **


decompiled_code:
__int64 __fastcall intqueue_ready(__int64 a1)
{
return *(unsigned int *)(a1 + 28);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return *(unsigned int *)(a1 + 28);
}

original_code:
int intqueue_ready(IntQueue *iq)
{
 return iq->ready;
}

canonical_original_code:
int intqueue_ready(struct IntQueue_s *iq)
{
 return iq->ready;
}

user_defined_types: struct Symbol_s { unsigned short dim; float vec[1]; }


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

result = 0LL;
if ( a1[7] )
result = symbol_abstract(*(_QWORD *)(*((_QWORD *)a1 + 1) + 8LL * (int)a1[8]), *a1);
return result;
}

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

result = 0LL;
if ( a1[7] )
result = symbol_abstract(*(_QWORD *)(*((_QWORD *)a1 + 1) + 8LL * (int)a1[8]), *a1);
return result;
}

original_code:
Symbol* intqueue_dequeue(IntQueue *iq)
{
 Symbol *abstraction;
 if (iq->ready == FALSE)
 {
  return ((void *)0);
 }
 abstraction = symbol_abstract(iq->slice[iq->ready_slice], iq->num_syms);
 return abstraction;
}

canonical_original_code:
struct Symbol_s *intqueue_dequeue(struct IntQueue_s *iq)
{
 struct Symbol_s *abstraction;
 if (iq->ready == FALSE)
 {
  return ((void *)0);
 }
 abstraction = symbol_abstract(iq->slice[iq->ready_slice], iq->num_syms);
 return abstraction;
}

variable_types: struct IntQueue_s { int num_syms; int num_slices; struct Symbol_s ***slice; int *slice_top; int curr_slice; int ready; int ready_slice; } *

variable_types: struct Symbol_s { unsigned short dim; float vec[1]; } *


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

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

original_code:
int intqueue_integrations(IntQueue *iq)
{
 return iq->num_syms;
}

canonical_original_code:
int intqueue_integrations(struct IntQueue_s *iq)
{
 return iq->num_syms;
}


decompiled_code:
int __fastcall intqueue_stdout(unsigned int *a1)
{
const char *v1; // rsi
int result; // eax
__int64 v3; // r13
__int64 v4; // rbx
__int64 v5; // r14

puts("\t\tIntegration Queue:");
v1 = "TRUE";
if ( a1[7] != 1 )
v1 = "FALSE";
printf("\t\t\tReady: %s\n", v1);
printf("\t\t\tReady slice: %d\n", a1[8]);
printf("\t\t\tNum Syms: %d\n", *a1);
result = printf("\t\t\tNum Slices: %d\n", a1[1]);
if ( (int)a1[1] > 0 )
{
v3 = 0LL;
do
{
v5 = *(_QWORD *)(*((_QWORD *)a1 + 1) + 8 * v3);
result = printf("\t\t\t\tSlice: %d\n", (unsigned int)v3);
if ( (int)*a1 > 0 )
{
v4 = 0LL;
do
{
if ( *(_DWORD *)(*((_QWORD *)a1 + 2) + 4 * v3) <= (int)v4 )
{
printf("\t\t\t\t\t");
result = symbol_stdout(*(_QWORD *)(v5 + 8 * v4));
}
else
{
result = puts("\t\t\t\t\tN/A");
}
++v4;
}
while ( (int)*a1 > (int)v4 );
}
++v3;
}
while ( (int)a1[1] > (int)v3 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func6(unsigned int *a1)
{
const char *v1; // rsi
int result; // eax
__int64 v3; // r13
__int64 v4; // rbx
__int64 v5; // r14

puts("\t\tIntegration Queue:");
v1 = "TRUE";
if ( a1[7] != 1 )
v1 = "FALSE";
printf("\t\t\tReady: %s\n", v1);
printf("\t\t\tReady slice: %d\n", a1[8]);
printf("\t\t\tNum Syms: %d\n", *a1);
result = printf("\t\t\tNum Slices: %d\n", a1[1]);
if ( (int)a1[1] > 0 )
{
v3 = 0LL;
do
{
v5 = *(_QWORD *)(*((_QWORD *)a1 + 1) + 8 * v3);
result = printf("\t\t\t\tSlice: %d\n", (unsigned int)v3);
if ( (int)*a1 > 0 )
{
v4 = 0LL;
do
{
if ( *(_DWORD *)(*((_QWORD *)a1 + 2) + 4 * v3) <= (int)v4 )
{
printf("\t\t\t\t\t");
result = symbol_stdout(*(_QWORD *)(v5 + 8 * v4));
}
else
{
result = puts("\t\t\t\t\tN/A");
}
++v4;
}
while ( (int)*a1 > (int)v4 );
}
++v3;
}
while ( (int)a1[1] > (int)v3 );
}
return result;
}

original_code:
void intqueue_stdout(IntQueue *iq)
{
 int i, j;
 Symbol **sq = ((void *)0);
 printf("\t\tIntegration Queue:\n");
 printf("\t\t\tReady: %s\n", iq->ready==TRUE?"TRUE":"FALSE");
 printf("\t\t\tReady slice: %d\n", iq->ready_slice);
 printf("\t\t\tNum Syms: %d\n", iq->num_syms);
 printf("\t\t\tNum Slices: %d\n", iq->num_slices);
 for (i = 0; i < iq->num_slices; i++)
 {
  sq = iq->slice[i];
  printf("\t\t\t\tSlice: %d\n", i);
  for (j = 0; j < iq->num_syms; j++)
  {
   if (j < iq->slice_top[i]) {
    printf("\t\t\t\t\tN/A\n");
   } else {
    printf("\t\t\t\t\t");
    symbol_stdout(sq[j]);
   }
  }
 }
}

canonical_original_code:
void intqueue_stdout(struct IntQueue_s *iq)
{
 int i; int j;
 struct Symbol_s **sq = ((void *)0);
 printf("\t\tIntegration Queue:\n");
 printf("\t\t\tReady: %s\n", iq->ready==TRUE?"TRUE":"FALSE");
 printf("\t\t\tReady slice: %d\n", iq->ready_slice);
 printf("\t\t\tNum Syms: %d\n", iq->num_syms);
 printf("\t\t\tNum Slices: %d\n", iq->num_slices);
 for (i = 0; i < iq->num_slices; i++)
 {
  sq = iq->slice[i];
  printf("\t\t\t\tSlice: %d\n", i);
  for (j = 0; j < iq->num_syms; j++)
  {
   if (j < iq->slice_top[i]) {
    printf("\t\t\t\t\tN/A\n");
   } else {
    printf("\t\t\t\t\t");
    symbol_stdout(sq[j]);
   }
  }
 }
}


decompiled_code:
void test_symbol()
{
__int64 v0; // rbx
_QWORD *v1; // rbx
int v2[34]; // [rsp+0h] [rbp-88h] BYREF

v0 = symbol_init(10LL);
symbol_randomize(v0);
v2[0] = 1;
v2[1] = 5;
v2[2] = 1;
v2[3] = 3;
printf("Original symbol: ");
symbol_stdout(v0);
v1 = (_QWORD *)symbol_unabstract(v0, v2, 4LL);
puts("unabstracted symbols:");
printf("1 dimension : ");
symbol_stdout(*v1);
printf("5 dimensions: ");
symbol_stdout(v1[1]);
printf("1 dimension : ");
symbol_stdout(v1[2]);
printf("3 dimensions: ");
symbol_stdout(v1[3]);
symbol_free(*v1);
symbol_free(v1[1]);
symbol_free(v1[2]);
symbol_free(v1[3]);
free(v1);
}

canonical_decompiled_code:
void func3()
{
__int64 v0; // rbx
_QWORD *v1; // rbx
int v2[34]; // [rsp+0h] [rbp-88h] BYREF

v0 = symbol_init(10LL);
symbol_randomize(v0);
v2[0] = 1;
v2[1] = 5;
v2[2] = 1;
v2[3] = 3;
printf("Original symbol: ");
symbol_stdout(v0);
v1 = (_QWORD *)symbol_unabstract(v0, v2, 4LL);
puts("unabstracted symbols:");
printf("1 dimension : ");
symbol_stdout(*v1);
printf("5 dimensions: ");
symbol_stdout(v1[1]);
printf("1 dimension : ");
symbol_stdout(v1[2]);
printf("3 dimensions: ");
symbol_stdout(v1[3]);
symbol_free(*v1);
symbol_free(v1[1]);
symbol_free(v1[2]);
symbol_free(v1[3]);
free(v1);
}

original_code:
void test_symbol(void)
{
 Symbol *sym;
 Symbol **list;
 int dims[32];
 sym = symbol_init(10);
 symbol_randomize(sym);
 dims[0] = 1;
 dims[1] = 5;
 dims[2] = 1;
 dims[3] = 3;
 printf("Original symbol: ");
 symbol_stdout(sym);
 list = symbol_unabstract(sym, dims, 4);
 printf("unabstracted symbols:\n");
 printf("1 dimension : ");
 symbol_stdout(list[0]);
 printf("5 dimensions: ");
 symbol_stdout(list[1]);
 printf("1 dimension : ");
 symbol_stdout(list[2]);
 printf("3 dimensions: ");
 symbol_stdout(list[3]);
 symbol_free(list[0]);
 symbol_free(list[1]);
 symbol_free(list[2]);
 symbol_free(list[3]);
 free(list);
}

canonical_original_code:
void test_symbol()
{
 struct Symbol_s *sym;
 struct Symbol_s **list;
 int dims[32];
 sym = symbol_init(10);
 symbol_randomize(sym);
 dims[0] = 1;
 dims[1] = 5;
 dims[2] = 1;
 dims[3] = 3;
 printf("Original symbol: ");
 symbol_stdout(sym);
 list = symbol_unabstract(sym, dims, 4);
 printf("unabstracted symbols:\n");
 printf("1 dimension : ");
 symbol_stdout(list[0]);
 printf("5 dimensions: ");
 symbol_stdout(list[1]);
 printf("1 dimension : ");
 symbol_stdout(list[2]);
 printf("3 dimensions: ");
 symbol_stdout(list[3]);
 symbol_free(list[0]);
 symbol_free(list[1]);
 symbol_free(list[2]);
 symbol_free(list[3]);
 free(list);
}

variable_types:
dims
int [32]


decompiled_code:
__int64 test_intqueue()
{
__int64 v0; // r12
int i; // ebp
__int64 v2; // rbx

v0 = intqueue_init(2LL, 4LL);
for ( i = 0; i != 8; ++i )
{
v2 = symbol_init(3LL);
symbol_set_all(v2, (float)i);
intqueue_enqueue(v0, v2);
intqueue_stdout(v0);
}
return intqueue_free(v0);
}

canonical_decompiled_code:
__int64 func4()
{
__int64 v0; // r12
int i; // ebp
__int64 v2; // rbx

v0 = intqueue_init(2LL, 4LL);
for ( i = 0; i != 8; ++i )
{
v2 = symbol_init(3LL);
symbol_set_all(v2, (float)i);
intqueue_enqueue(v0, v2);
intqueue_stdout(v0);
}
return intqueue_free(v0);
}

original_code:
void test_intqueue(void)
{
 int i;
 Symbol *sym;
 IntQueue *iq;
 iq = intqueue_init(2, 4);
 for (i = 0; i < 8; i++)
 {
  sym = symbol_init(3);
  symbol_set_all(sym, i);
  intqueue_enqueue(iq, sym);
  intqueue_stdout(iq);
 }
 intqueue_free(iq);
}

canonical_original_code:
void test_intqueue()
{
 int i;
 struct Symbol_s *sym;
 struct IntQueue_s *iq;
 iq = intqueue_init(2, 4);
 for (i = 0; i < 8; i++)
 {
  sym = symbol_init(3);
  symbol_set_all(sym, i);
  intqueue_enqueue(iq, sym);
  intqueue_stdout(iq);
 }
 intqueue_free(iq);
}


decompiled_code:
__int64 __fastcall test_cortex_ascii(__int64 a1)
{
int v1; // ebx
int *v2; // rax
int *v3; // rbp
unsigned int v4; // er15
__int64 v5; // rax
__int64 v6; // r13
__int64 v7; // r14
char v8; // bl
const char *v9; // rax
unsigned int v11; // eax
__int64 v12; // rax
int v13; // eax
int v14; // er12
int v15; // [rsp+8h] [rbp-C0h]
unsigned int v16; // [rsp+Ch] [rbp-BCh]
__int64 v17; // [rsp+10h] [rbp-B8h]
__int64 v18; // [rsp+18h] [rbp-B0h]
int v19; // [rsp+20h] [rbp-A8h]
int v20; // [rsp+24h] [rbp-A4h]
int v21; // [rsp+28h] [rbp-A0h]
__int64 v22[10]; // [rsp+30h] [rbp-98h] BYREF
double v23; // [rsp+80h] [rbp-48h] BYREF
unsigned int v24; // [rsp+88h] [rbp-40h] BYREF
unsigned int v25[15]; // [rsp+8Ch] [rbp-3Ch] BYREF

v18 = input_init(1LL);
v17 = cortex_init(a1);
v15 = SDL_GetTicks();
v19 = v15 + 1000;
v16 = 0;
v20 = 0;
v1 = 0;
do
{
v12 = input_xlate_char(v18, (unsigned int)byte_BB0[v1]);
v22[0] = symbol_copy(v12);
cortex_process(v17, v22, 1LL, 0LL);
v13 = process_events(v25, &v24);
v14 = v13;
if ( v13 == 2 )
{
if ( v19 < v15 )
{
glClear(16640LL);
goto LABEL_27;
}
v20 = 0;
goto LABEL_17;
}
if ( v13 == 3 )
{
v2 = (int *)cortex_resolve(v17, v25[0], v24);
v3 = v2;
if ( v2 )
{
if ( *v2 > 0 )
{
v4 = 0;
v21 = v1;
do
{
v5 = inputrestable_input(v3, v4);
v6 = v5;
if ( *(_DWORD *)(v5 + 4) == 1 && *(int *)(v5 + 8) > 0 )
{
v7 = 0LL;
do
{
v8 = input_decode_to_char(v18, *(_QWORD *)(*(_QWORD *)(v6 + 16) + 8 * v7), &v23);
printf("For input %d, time step -%d: ", v4, (unsigned int)v7);
printf("char '%c' error %f\n", (unsigned int)v8, v23);
++v7;
}
while ( *(_DWORD *)(v6 + 8) > (int)v7 );
}
++v4;
}
while ( *v3 > (int)v4 );
v1 = v21;
}
inputrestable_destroy(v3);
}
LABEL_25:
if ( v19 < v15 )
{
glClear(16640LL);
if ( v20 != 1 )
{
LABEL_27:
cortex_draw(v17, 0LL);
v20 = 0;
goto LABEL_16;
}
LABEL_15:
cortex_draw(v17, 1LL);
v20 = 1;
LABEL_16:
SDL_GL_SwapBuffers();
v19 = v15 + 1000;
printf("Glyphs per second: %d\n", v16);
v16 = 0;
goto LABEL_17;
}
goto LABEL_17;
}
if ( v13 != 1 )
goto LABEL_25;
if ( v19 < v15 )
{
glClear(16640LL);
goto LABEL_15;
}
v20 = 1;
LABEL_17:
v15 = SDL_GetTicks();
v11 = glGetError();
if ( v11 )
{
v9 = (const char *)gluErrorString(v11);
printf("Opengl Error: %s\n", v9);
}
++v1;
if ( v1 == 216 * (v1 / 0xD8uLL) )
v1 = 0;
++v16;
}
while ( v14 != 4 );
cortex_free(v17);
return input_free(v18);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
int v1; // ebx
int *v2; // rax
int *v3; // rbp
unsigned int v4; // er15
__int64 v5; // rax
__int64 v6; // r13
__int64 v7; // r14
char v8; // bl
const char *v9; // rax
unsigned int v11; // eax
__int64 v12; // rax
int v13; // eax
int v14; // er12
int v15; // [rsp+8h] [rbp-C0h]
unsigned int v16; // [rsp+Ch] [rbp-BCh]
__int64 v17; // [rsp+10h] [rbp-B8h]
__int64 v18; // [rsp+18h] [rbp-B0h]
int v19; // [rsp+20h] [rbp-A8h]
int v20; // [rsp+24h] [rbp-A4h]
int v21; // [rsp+28h] [rbp-A0h]
__int64 v22[10]; // [rsp+30h] [rbp-98h] BYREF
double v23; // [rsp+80h] [rbp-48h] BYREF
unsigned int v24; // [rsp+88h] [rbp-40h] BYREF
unsigned int v25[15]; // [rsp+8Ch] [rbp-3Ch] BYREF

v18 = input_init(1LL);
v17 = cortex_init(a1);
v15 = SDL_GetTicks();
v19 = v15 + 1000;
v16 = 0;
v20 = 0;
v1 = 0;
do
{
v12 = input_xlate_char(v18, (unsigned int)byte_BB0[v1]);
v22[0] = symbol_copy(v12);
cortex_process(v17, v22, 1LL, 0LL);
v13 = func2(v25, &v24);
v14 = v13;
if ( v13 == 2 )
{
if ( v19 < v15 )
{
glClear(16640LL);
goto LABEL_27;
}
v20 = 0;
goto LABEL_17;
}
if ( v13 == 3 )
{
v2 = (int *)cortex_resolve(v17, v25[0], v24);
v3 = v2;
if ( v2 )
{
if ( *v2 > 0 )
{
v4 = 0;
v21 = v1;
do
{
v5 = inputrestable_input(v3, v4);
v6 = v5;
if ( *(_DWORD *)(v5 + 4) == 1 && *(int *)(v5 + 8) > 0 )
{
v7 = 0LL;
do
{
v8 = input_decode_to_char(v18, *(_QWORD *)(*(_QWORD *)(v6 + 16) + 8 * v7), &v23);
printf("For input %d, time step -%d: ", v4, (unsigned int)v7);
printf("char '%c' error %f\n", (unsigned int)v8, v23);
++v7;
}
while ( *(_DWORD *)(v6 + 8) > (int)v7 );
}
++v4;
}
while ( *v3 > (int)v4 );
v1 = v21;
}
inputrestable_destroy(v3);
}
LABEL_25:
if ( v19 < v15 )
{
glClear(16640LL);
if ( v20 != 1 )
{
LABEL_27:
cortex_draw(v17, 0LL);
v20 = 0;
goto LABEL_16;
}
LABEL_15:
cortex_draw(v17, 1LL);
v20 = 1;
LABEL_16:
SDL_GL_SwapBuffers();
v19 = v15 + 1000;
printf("Glyphs per second: %d\n", v16);
v16 = 0;
goto LABEL_17;
}
goto LABEL_17;
}
if ( v13 != 1 )
goto LABEL_25;
if ( v19 < v15 )
{
glClear(16640LL);
goto LABEL_15;
}
v20 = 1;
LABEL_17:
v15 = SDL_GetTicks();
v11 = glGetError();
if ( v11 )
{
v9 = (const char *)gluErrorString(v11);
printf("Opengl Error: %s\n", v9);
}
++v1;
if ( v1 == 216 * (v1 / 0xD8uLL) )
v1 = 0;
++v16;
}
while ( v14 != 4 );
cortex_free(v17);
return input_free(v18);
}

original_code:
void test_cortex_ascii(char *filename)
{
 Cortex *core = ((void *)0);
 int state = STATE_RUNNING;
 int sample, now, incr = 1000;
 int i, j, k;
 int mr, mc;
 int drawing_mode = SOM_STYLE_ACTUAL;
 int glerr;
 int iter = 0;
 char revc;
 double revcerr;
 char *alpha = "I am very happy that my reverse lookup code seems to work. "
     "It really fills me with joy that after such a long and "
     "hard amount of work, everything finally seems to be "
     "working. Let us see if the vision processor works.";
 Input *inp;
 InputResTable *irt;
 InputResolution *ires;
 Symbol *channels[10];
 int num_channels = 1;
 inp = input_init(1);
 core = cortex_init(filename);
 now = SDL_GetTicks();
 sample = now + incr;
 i = 0;
 while(state != STATE_EXIT)
 {
  channels[0] = symbol_copy(input_xlate_char(inp, alpha[i]));
  cortex_process(core, channels, num_channels, CORTEX_REQUEST_LEARN);
  state = process_events(&mr, &mc);
  switch (state)
  {
   case STATE_MOUSE_DOWN:
    irt = cortex_resolve(core, mr, mc);
    if (irt != ((void *)0))
    {
     for (j = 0; j < irt->num_inres; j++)
     {
      ires = inputrestable_input(irt, j);
      if (ires->active == TRUE)
      {
       for (k = 0; k < ires->num_time_steps; k++)
       {
        revc = input_decode_to_char(inp,
          ires->resolution[k], &revcerr);
        printf("For input %d, time step -%d: ", j, k);
        printf("char '%c' error %f\n", revc, revcerr);
       }
      }
     }
     inputrestable_destroy(irt);
    }
    break;
   case STATE_QUALITY:
    drawing_mode = SOM_STYLE_QUALITY;
    break;
   case STATE_ACTUAL:
    drawing_mode = SOM_STYLE_ACTUAL;
    break;
   default:
    ;
  }
  if (now > sample)
  {
   glClear(0x00004000 | 0x00000100);
   if (drawing_mode == SOM_STYLE_QUALITY)
   {
    cortex_draw(core, SOM_STYLE_QUALITY);
   }
   else if (drawing_mode == SOM_STYLE_ACTUAL)
   {
    cortex_draw(core, SOM_STYLE_ACTUAL);
   }
   SDL_GL_SwapBuffers();
   sample = now + incr;
   printf("Glyphs per second: %d\n", iter);
   iter = 0;
  }
  now = SDL_GetTicks();
  glerr = glGetError();
  if (glerr != 0)
  {
   printf("Opengl Error: %s\n", gluErrorString(glerr));
  }
  i++;
  if (!(i%strlen(alpha))) {
   i = 0;
  }
  iter++;
 }
 cortex_free(core);
 input_free(inp);
}

canonical_original_code:
void test_cortex_ascii(char *filename)
{
 struct Cortex_s *core = ((void *)0);
 int state = STATE_RUNNING;
 int sample; int now; int incr = 1000;
 int i; int j; int k;
 int mr; int mc;
 int drawing_mode = SOM_STYLE_ACTUAL;
 int glerr;
 int iter = 0;
 char revc;
 double revcerr;
 char *alpha = "I am very happy that my reverse lookup code seems to work. "
     "It really fills me with joy that after such a long and "
     "hard amount of work, everything finally seems to be "
     "working. Let us see if the vision processor works.";
 struct Input_s *inp;
 struct InputResTable_s *irt;
 struct InputResolution_s *ires;
 struct Symbol_s *channels[10];
 int num_channels = 1;
 inp = input_init(1);
 core = cortex_init(filename);
 now = SDL_GetTicks();
 sample = now + incr;
 i = 0;
 while(state != STATE_EXIT)
 {
  channels[0] = symbol_copy(input_xlate_char(inp, alpha[i]));
  cortex_process(core, channels, num_channels, CORTEX_REQUEST_LEARN);
  state = process_events(&mr, &mc);
  switch (state)
  {
   case STATE_MOUSE_DOWN:
    irt = cortex_resolve(core, mr, mc);
    if (irt != ((void *)0))
    {
     for (j = 0; j < irt->num_inres; j++)
     {
      ires = inputrestable_input(irt, j);
      if (ires->active == TRUE)
      {
       for (k = 0; k < ires->num_time_steps; k++)
       {
        revc = input_decode_to_char(inp,
          ires->resolution[k], &revcerr);
        printf("For input %d, time step -%d: ", j, k);
        printf("char '%c' error %f\n", revc, revcerr);
       }
      }
     }
     inputrestable_destroy(irt);
    }
    break;
   case STATE_QUALITY:
    drawing_mode = SOM_STYLE_QUALITY;
    break;
   case STATE_ACTUAL:
    drawing_mode = SOM_STYLE_ACTUAL;
    break;
   default:
    ;
  }
  if (now > sample)
  {
   glClear(0x00004000 | 0x00000100);
   if (drawing_mode == SOM_STYLE_QUALITY)
   {
    cortex_draw(core, SOM_STYLE_QUALITY);
   }
   else if (drawing_mode == SOM_STYLE_ACTUAL)
   {
    cortex_draw(core, SOM_STYLE_ACTUAL);
   }
   SDL_GL_SwapBuffers();
   sample = now + incr;
   printf("Glyphs per second: %d\n", iter);
   iter = 0;
  }
  now = SDL_GetTicks();
  glerr = glGetError();
  if (glerr != 0)
  {
   printf("Opengl Error: %s\n", gluErrorString(glerr));
  }
  i++;
  if (!(i%strlen(alpha))) {
   i = 0;
  }
  iter++;
 }
 cortex_free(core);
 input_free(inp);
}

variable_types:
filename
char *

variable_types: struct Cortex_s { int num_sec; struct Section_s { int serial_id; char *name; struct SOM_s { int mode; int bmu_row; struct SOMDesc_s { unsigned short dim; unsigned int train_iter; unsigned int rows; unsigned int cols; float (*radius_func)(struct SOM_s *s); } sd; int current_iter; float initial_radius; float half_life; struct Symbol_s { unsigned short dim; float vec[1]; } **neuron; float final_computation; float max_dist; float *qmap; } *som; int x; unsigned int mode; unsigned int state; struct Receptor_s { int num_slot; struct Slot_s { struct IntQueue_s { int num_syms; int num_slices; struct Symbol_s ***slice; int *slice_top; int curr_slice; int ready; int ready_slice; } *iq; int parent; int parent_kind; } *slot; } receptor; struct Emitter_s { int num_con; struct Connection_s { int section_id; int slot; } *con; } emitter; struct SecDisp_s { int learn_row; } secdisp; } *sec; int num_input; struct CortexInput_s { int serial_id; char *name; int dim; struct Symbol_s *sym; struct Emitter_s emitter; } *input; int num_exec; int *exec; int num_outchan; struct CortexOutputChannel_s { int serial_id; char *name; } *outchan; int num_outmap; struct CortexOutputMapping_s { int sec_id; int ochan_id; } *outmap; struct ReverseTable_s { int num_roots; struct ObservationTable_s { int serial_id; int num_obs; struct Observation_s { int serial_id; int obs; } *ob; } *root; } rt; struct WaveTable_s { int num_sec; struct WaveFront_s { int serial_id; int active; int needed_observations; int num_observations; struct ViewPoint_s { int num_sym; struct Symbol_s **sym; struct ViewPoint_s *next; } *views; } *wfs; } wt; } *

variable_types: state int

variable_types: sample int

variable_types: now int

variable_types: incr int

variable_types: k int

variable_types: mr int

variable_types: mc int

variable_types: glerr int

variable_types: iter int

variable_types: revc char

variable_types: revcerr double

variable_types:
alpha
char *

variable_types: struct Input_s { int dim; int printable; struct XlateTable_s { char c; struct Symbol_s { unsigned short dim; float vec[1]; } *sym; } xlt[256]; } *

variable_types: struct InputResTable_s { int num_inres; struct InputResolution_s { int serial_id; int active; int num_time_steps; struct Symbol_s { unsigned short dim; float vec[1]; } **resolution; } *inres; } *

variable_types: struct Symbol_s { unsigned short dim; float vec[1]; } *[10]

user_defined_types: struct Cortex_s { int num_sec; struct Section_s *sec; int num_input; struct CortexInput_s *input; int num_exec; int *exec; int num_outchan; struct CortexOutputChannel_s *outchan; int num_outmap; struct CortexOutputMapping_s *outmap; struct ReverseTable_s rt; struct WaveTable_s wt; }

user_defined_types: struct Input_s { int dim; int printable; struct XlateTable_s xlt[256]; }

user_defined_types: struct InputResTable_s { int num_inres; struct InputResolution_s *inres; }

user_defined_types: struct InputResolution_s { int serial_id; int active; int num_time_steps; struct Symbol_s **resolution; }

user_defined_types: struct ReverseTable_s { int num_roots; struct ObservationTable_s *root; }

user_defined_types: struct WaveTable_s { int num_sec; struct WaveFront_s *wfs; }

user_defined_types: struct Section_s { int serial_id; char *name; struct SOM_s *som; int x; unsigned int mode; unsigned int state; struct Receptor_s receptor; struct Emitter_s emitter; struct SecDisp_s secdisp; }

user_defined_types: struct XlateTable_s { char c; struct Symbol_s *sym; }

user_defined_types: struct Receptor_s { int num_slot; struct Slot_s *slot; }

user_defined_types: struct Emitter_s { int num_con; struct Connection_s *con; }

user_defined_types: struct ObservationTable_s { int serial_id; int num_obs; struct Observation_s *ob; }

user_defined_types: struct WaveFront_s { int serial_id; int active; int needed_observations; int num_observations; struct ViewPoint_s *views; }

user_defined_types: struct SOM_s { int mode; int bmu_row; struct SOMDesc_s sd; int current_iter; float initial_radius; float half_life; struct Symbol_s **neuron; float final_computation; float max_dist; float *qmap; }

user_defined_types: struct Slot_s { struct IntQueue_s *iq; int parent; int parent_kind; }


decompiled_code:
__int64 test_vinput()
{
__int64 v0; // r12
unsigned int i; // ebp
unsigned int j; // ebx

v0 = vinput_init(16LL, 16LL, 16LL, 16LL);
for ( i = 0; i != 16; ++i )
{
for ( j = 0; j != 16; ++j )
{
if ( (unsigned int)vinput_glyph_bit(v0, 1LL, 4LL, i, j) )
putchar(35);
else
putchar(46);
}
putchar(10);
}
return vinput_destroy(v0);
}

canonical_decompiled_code:
__int64 func6()
{
__int64 v0; // r12
unsigned int i; // ebp
unsigned int j; // ebx

v0 = vinput_init(16LL, 16LL, 16LL, 16LL);
for ( i = 0; i != 16; ++i )
{
for ( j = 0; j != 16; ++j )
{
if ( (unsigned int)vinput_glyph_bit(v0, 1LL, 4LL, i, j) )
putchar(35);
else
putchar(46);
}
putchar(10);
}
return vinput_destroy(v0);
}

original_code:
void test_vinput(void)
{
 VInput *vinp;
 int r, c;
 int bitval;
 vinp = vinput_init(16, 16, 16, 16);
 for (r = 0; r < 16; r++) {
  for (c = 0; c < 16; c++) {
   bitval = vinput_glyph_bit(vinp, 1, 4, r, c);
   if (bitval == 0) {
    printf(".");
   } else {
    printf("#");
   }
  }
  printf("\n");
 }
 vinput_destroy(vinp);
}

canonical_original_code:
void test_vinput()
{
 struct VInput_s *vinp;
 int r; int c;
 int bitval;
 vinp = vinput_init(16, 16, 16, 16);
 for (r = 0; r < 16; r++) {
  for (c = 0; c < 16; c++) {
   bitval = vinput_glyph_bit(vinp, 1, 4, r, c);
   if (bitval == 0) {
    printf(".");
   } else {
    printf("#");
   }
  }
  printf("\n");
 }
 vinput_destroy(vinp);
}

variable_types: struct VInput_s { int full_bit_rows; int full_bit_cols; int subimage_bit_rows; int subimage_bit_cols; int rows; int cols; unsigned char *bits; } *

variable_types: r int

variable_types: c int

variable_types: bitval int


decompiled_code:
__int64 __fastcall test_cortex_vision(__int64 a1)
{
__int64 v1; // r13
int v2; // er12
int v3; // er14
unsigned int v4; // ebx
unsigned int v5; // er15
void *v6; // rbp
int v7; // eax
int v8; // ebp
__int64 v9; // rax
void *v10; // rbp
int v11; // eax
__int64 v12; // rax
__int64 v13; // r14
unsigned int v14; // eax
const char *v15; // rax
__int64 v17; // [rsp+0h] [rbp-78h]
__int64 v18; // [rsp+8h] [rbp-70h]
unsigned int v19; // [rsp+14h] [rbp-64h]
__int64 v20; // [rsp+18h] [rbp-60h]
char v21[4]; // [rsp+20h] [rbp-58h] BYREF
char v22[4]; // [rsp+24h] [rbp-54h] BYREF
char v23[4]; // [rsp+28h] [rbp-50h] BYREF
char v24[4]; // [rsp+2Ch] [rbp-4Ch] BYREF
float v25; // [rsp+30h] [rbp-48h] BYREF
float v26; // [rsp+34h] [rbp-44h] BYREF
unsigned int v27; // [rsp+38h] [rbp-40h] BYREF
int v28[15]; // [rsp+3Ch] [rbp-3Ch] BYREF

v1 = vinput_init(16LL, 16LL, 16LL, 16LL);
v18 = cortex_init(a1);
v2 = SDL_GetTicks();
v3 = v2 - 1;
v20 = 0LL;
v4 = 0;
v5 = 0;
v19 = 0;
do
{
if ( v3 < v2 )
{
glClear(16640LL);
v6 = (void *)vinput_glyph(v1, v4);
v4 = (int)(v4 + 1) % 144;
vinput_draw_glyph(v1, v6, 300LL, 300LL);
vinput_draw_glyph(v1, v6, 400LL, 300LL);
v17 = cortex_process(v18, v6, 16LL, 0LL);
free(v6);
v7 = process_events(v28, &v27);
v8 = v7;
if ( v7 == 2 )
goto LABEL_23;
if ( v7 != 3 )
{
if ( v7 != 1 )
goto LABEL_5;
goto LABEL_16;
}
}
else
{
v10 = (void *)vinput_glyph(v1, v4);
v4 = (int)(v4 + 1) % 144;
vinput_draw_glyph(v1, v10, 300LL, 300LL);
vinput_draw_glyph(v1, v10, 400LL, 300LL);
v17 = cortex_process(v18, v10, 16LL, 0LL);
free(v10);
v11 = process_events(v28, &v27);
v8 = v11;
if ( v11 == 2 )
{
LABEL_23:
v8 = 2;
v19 = 0;
goto LABEL_20;
}
if ( v11 != 3 )
{
if ( v11 != 1 )
goto LABEL_21;
LABEL_16:
v8 = 1;
v19 = 1;
goto LABEL_20;
}
}
printf("Clicked: %d, %d\n", v27, (unsigned int)v28[0]);
if ( v20 )
inputrestable_destroy(v20);
v20 = cortex_resolve(v18, (unsigned int)v28[0], v27);
v8 = 3;
LABEL_20:
if ( v3 >= v2 )
{
LABEL_21:
if ( !v17 )
goto LABEL_10;
goto LABEL_9;
}
LABEL_5:
cortex_draw(v18, v19);
if ( v20 )
vinput_draw_irt(v1, v20, 600LL, 300LL);
v9 = *(_QWORD *)(v17 + 16);
if ( *(_DWORD *)v9 == 1 )
{
symbol_get_6(*(_QWORD *)(v9 + 24), &v26, &v25, v24, v23, v22, v21);
v12 = cortex_resolve(v18, (unsigned int)(int)v26, (unsigned int)(int)v25);
v13 = v12;
if ( v12 )
{
vinput_draw_irt(v1, v12, 500LL, 300LL);
inputrestable_destroy(v13);
}
}
SDL_GL_SwapBuffers();
v3 = v2 + 1000;
printf("Glyphs per second: %d\n", v5);
v5 = 0;
LABEL_9:
cortex_output_table_free(v17);
LABEL_10:
v2 = SDL_GetTicks();
if ( v2 > v3 )
{
v14 = glGetError();
if ( v14 )
{
v15 = (const char *)gluErrorString(v14);
printf("Opengl Error: %s\n", v15);
}
}
++v5;
}
while ( v8 != 4 );
cortex_free(v18);
return vinput_destroy(v1);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
__int64 v1; // r13
int v2; // er12
int v3; // er14
unsigned int v4; // ebx
unsigned int v5; // er15
void *v6; // rbp
int v7; // eax
int v8; // ebp
__int64 v9; // rax
void *v10; // rbp
int v11; // eax
__int64 v12; // rax
__int64 v13; // r14
unsigned int v14; // eax
const char *v15; // rax
__int64 v17; // [rsp+0h] [rbp-78h]
__int64 v18; // [rsp+8h] [rbp-70h]
unsigned int v19; // [rsp+14h] [rbp-64h]
__int64 v20; // [rsp+18h] [rbp-60h]
char v21[4]; // [rsp+20h] [rbp-58h] BYREF
char v22[4]; // [rsp+24h] [rbp-54h] BYREF
char v23[4]; // [rsp+28h] [rbp-50h] BYREF
char v24[4]; // [rsp+2Ch] [rbp-4Ch] BYREF
float v25; // [rsp+30h] [rbp-48h] BYREF
float v26; // [rsp+34h] [rbp-44h] BYREF
unsigned int v27; // [rsp+38h] [rbp-40h] BYREF
int v28[15]; // [rsp+3Ch] [rbp-3Ch] BYREF

v1 = vinput_init(16LL, 16LL, 16LL, 16LL);
v18 = cortex_init(a1);
v2 = SDL_GetTicks();
v3 = v2 - 1;
v20 = 0LL;
v4 = 0;
v5 = 0;
v19 = 0;
do
{
if ( v3 < v2 )
{
glClear(16640LL);
v6 = (void *)vinput_glyph(v1, v4);
v4 = (int)(v4 + 1) % 144;
vinput_draw_glyph(v1, v6, 300LL, 300LL);
vinput_draw_glyph(v1, v6, 400LL, 300LL);
v17 = cortex_process(v18, v6, 16LL, 0LL);
free(v6);
v7 = func2(v28, &v27);
v8 = v7;
if ( v7 == 2 )
goto LABEL_23;
if ( v7 != 3 )
{
if ( v7 != 1 )
goto LABEL_5;
goto LABEL_16;
}
}
else
{
v10 = (void *)vinput_glyph(v1, v4);
v4 = (int)(v4 + 1) % 144;
vinput_draw_glyph(v1, v10, 300LL, 300LL);
vinput_draw_glyph(v1, v10, 400LL, 300LL);
v17 = cortex_process(v18, v10, 16LL, 0LL);
free(v10);
v11 = func2(v28, &v27);
v8 = v11;
if ( v11 == 2 )
{
LABEL_23:
v8 = 2;
v19 = 0;
goto LABEL_20;
}
if ( v11 != 3 )
{
if ( v11 != 1 )
goto LABEL_21;
LABEL_16:
v8 = 1;
v19 = 1;
goto LABEL_20;
}
}
printf("Clicked: %d, %d\n", v27, (unsigned int)v28[0]);
if ( v20 )
inputrestable_destroy(v20);
v20 = cortex_resolve(v18, (unsigned int)v28[0], v27);
v8 = 3;
LABEL_20:
if ( v3 >= v2 )
{
LABEL_21:
if ( !v17 )
goto LABEL_10;
goto LABEL_9;
}
LABEL_5:
cortex_draw(v18, v19);
if ( v20 )
vinput_draw_irt(v1, v20, 600LL, 300LL);
v9 = *(_QWORD *)(v17 + 16);
if ( *(_DWORD *)v9 == 1 )
{
symbol_get_6(*(_QWORD *)(v9 + 24), &v26, &v25, v24, v23, v22, v21);
v12 = cortex_resolve(v18, (unsigned int)(int)v26, (unsigned int)(int)v25);
v13 = v12;
if ( v12 )
{
vinput_draw_irt(v1, v12, 500LL, 300LL);
inputrestable_destroy(v13);
}
}
SDL_GL_SwapBuffers();
v3 = v2 + 1000;
printf("Glyphs per second: %d\n", v5);
v5 = 0;
LABEL_9:
cortex_output_table_free(v17);
LABEL_10:
v2 = SDL_GetTicks();
if ( v2 > v3 )
{
v14 = glGetError();
if ( v14 )
{
v15 = (const char *)gluErrorString(v14);
printf("Opengl Error: %s\n", v15);
}
}
++v5;
}
while ( v8 != 4 );
cortex_free(v18);
return vinput_destroy(v1);
}

original_code:
void test_cortex_vision(char *filename)
{
 Cortex *core = ((void *)0);
 CortexOutputTable *ctxout = ((void *)0);
 int state = STATE_RUNNING;
 int sample, now, incr = 1000;
 int i;
 int mr, mc;
 int drawing_mode = SOM_STYLE_ACTUAL;
 int glerr;
 int iter = 0;
 int gindex;
 float ctx_row, ctx_col, row, col, n_row, n_col;
 VInput *vinp;
 InputResTable *irt = ((void *)0);
 InputResTable *self = ((void *)0);
 Symbol **channels;
 int num_channels = 16;
 vinp = vinput_init(16, 16, 16, 16);
 core = cortex_init(filename);
 now = SDL_GetTicks();
 sample = now - 1;
 i = 0;
 gindex = 0;
 while(state != STATE_EXIT)
 {
  if (now > sample)
  {
   glClear(0x00004000 | 0x00000100);
  }
  channels = vinput_glyph(vinp, gindex);
  gindex++;
  gindex %= 9 * 16;
  vinput_draw_glyph(vinp, channels, 300, 300);
  vinput_draw_glyph(vinp, channels, 400, 300);
  ctxout =
   cortex_process(core, channels, num_channels, CORTEX_REQUEST_LEARN);
  free(channels);
  state = process_events(&mr, &mc);
  switch (state)
  {
   case STATE_MOUSE_DOWN:
    printf("Clicked: %d, %d\n", mc, mr);
    if (irt != ((void *)0))
    {
     inputrestable_destroy(irt);
    }
    irt = cortex_resolve(core, mr, mc);
    break;
   case STATE_QUALITY:
    drawing_mode = SOM_STYLE_QUALITY;
    break;
   case STATE_ACTUAL:
    drawing_mode = SOM_STYLE_ACTUAL;
    break;
   default:
    ;
  }
  if (now > sample)
  {
   cortex_draw(core, drawing_mode);
   if (irt != ((void *)0))
   {
    vinput_draw_irt(vinp, irt, 600, 300);
   }
   if (ctxout->output[0].active == TRUE) {
    symbol_get_6(ctxout->output[0].osym,
     &ctx_row, &ctx_col, &row, &col, &n_row, &n_col);
    self = cortex_resolve(core, ctx_row, ctx_col);
    if (self != ((void *)0)) {
     vinput_draw_irt(vinp, self, 500, 300);
     inputrestable_destroy(self);
    }
   }
   SDL_GL_SwapBuffers();
   sample = now + incr;
   printf("Glyphs per second: %d\n", iter);
   iter = 0;
  }
  if (ctxout != ((void *)0)) {
   cortex_output_table_free(ctxout);
   ctxout = ((void *)0);
  }
  now = SDL_GetTicks();
  if (now > sample) {
   glerr = glGetError();
   if (glerr != 0)
   {
    printf("Opengl Error: %s\n", gluErrorString(glerr));
   }
  }
  iter++;
 }
 cortex_free(core);
 vinput_destroy(vinp);
}

canonical_original_code:
void test_cortex_vision(char *filename)
{
 struct Cortex_s *core = ((void *)0);
 struct CortexOutputTable_s *ctxout = ((void *)0);
 int state = STATE_RUNNING;
 int sample; int now; int incr = 1000;
 int i;
 int mr; int mc;
 int drawing_mode = SOM_STYLE_ACTUAL;
 int glerr;
 int iter = 0;
 int gindex;
 float ctx_row; float ctx_col; float row; float col; float n_row; float n_col;
 struct VInput_s *vinp;
 struct InputResTable_s *irt = ((void *)0);
 struct InputResTable_s *self = ((void *)0);
 struct Symbol_s **channels;
 int num_channels = 16;
 vinp = vinput_init(16, 16, 16, 16);
 core = cortex_init(filename);
 now = SDL_GetTicks();
 sample = now - 1;
 i = 0;
 gindex = 0;
 while(state != STATE_EXIT)
 {
  if (now > sample)
  {
   glClear(0x00004000 | 0x00000100);
  }
  channels = vinput_glyph(vinp, gindex);
  gindex++;
  gindex %= 9 * 16;
  vinput_draw_glyph(vinp, channels, 300, 300);
  vinput_draw_glyph(vinp, channels, 400, 300);
  ctxout =
   cortex_process(core, channels, num_channels, CORTEX_REQUEST_LEARN);
  free(channels);
  state = process_events(&mr, &mc);
  switch (state)
  {
   case STATE_MOUSE_DOWN:
    printf("Clicked: %d, %d\n", mc, mr);
    if (irt != ((void *)0))
    {
     inputrestable_destroy(irt);
    }
    irt = cortex_resolve(core, mr, mc);
    break;
   case STATE_QUALITY:
    drawing_mode = SOM_STYLE_QUALITY;
    break;
   case STATE_ACTUAL:
    drawing_mode = SOM_STYLE_ACTUAL;
    break;
   default:
    ;
  }
  if (now > sample)
  {
   cortex_draw(core, drawing_mode);
   if (irt != ((void *)0))
   {
    vinput_draw_irt(vinp, irt, 600, 300);
   }
   if (ctxout->output[0].active == TRUE) {
    symbol_get_6(ctxout->output[0].osym,
     &ctx_row, &ctx_col, &row, &col, &n_row, &n_col);
    self = cortex_resolve(core, ctx_row, ctx_col);
    if (self != ((void *)0)) {
     vinput_draw_irt(vinp, self, 500, 300);
     inputrestable_destroy(self);
    }
   }
   SDL_GL_SwapBuffers();
   sample = now + incr;
   printf("Glyphs per second: %d\n", iter);
   iter = 0;
  }
  if (ctxout != ((void *)0)) {
   cortex_output_table_free(ctxout);
   ctxout = ((void *)0);
  }
  now = SDL_GetTicks();
  if (now > sample) {
   glerr = glGetError();
   if (glerr != 0)
   {
    printf("Opengl Error: %s\n", gluErrorString(glerr));
   }
  }
  iter++;
 }
 cortex_free(core);
 vinput_destroy(vinp);
}

variable_types:
filename
char *

variable_types: struct Cortex_s { int num_sec; struct Section_s { int serial_id; char *name; struct SOM_s { int mode; int bmu_row; struct SOMDesc_s { unsigned short dim; unsigned int train_iter; unsigned int rows; unsigned int cols; float (*radius_func)(struct SOM_s *s); } sd; int current_iter; float initial_radius; float half_life; struct Symbol_s { unsigned short dim; float vec[1]; } **neuron; float final_computation; float max_dist; float *qmap; } *som; int x; unsigned int mode; unsigned int state; struct Receptor_s { int num_slot; struct Slot_s { struct IntQueue_s { int num_syms; int num_slices; struct Symbol_s ***slice; int *slice_top; int curr_slice; int ready; int ready_slice; } *iq; int parent; int parent_kind; } *slot; } receptor; struct Emitter_s { int num_con; struct Connection_s { int section_id; int slot; } *con; } emitter; struct SecDisp_s { int learn_row; } secdisp; } *sec; int num_input; struct CortexInput_s { int serial_id; char *name; int dim; struct Symbol_s *sym; struct Emitter_s emitter; } *input; int num_exec; int *exec; int num_outchan; struct CortexOutputChannel_s { int serial_id; char *name; } *outchan; int num_outmap; struct CortexOutputMapping_s { int sec_id; int ochan_id; } *outmap; struct ReverseTable_s { int num_roots; struct ObservationTable_s { int serial_id; int num_obs; struct Observation_s { int serial_id; int obs; } *ob; } *root; } rt; struct WaveTable_s { int num_sec; struct WaveFront_s { int serial_id; int active; int needed_observations; int num_observations; struct ViewPoint_s { int num_sym; struct Symbol_s **sym; struct ViewPoint_s *next; } *views; } *wfs; } wt; } *

variable_types: struct CortexOutputTable_s { int request; int mode; int num_output; struct CortexOutput_s { int active; struct CortexOutputChannel_s { int serial_id; char *name; } ochan; struct Symbol_s { unsigned short dim; float vec[1]; } *osym; } *output; } *

variable_types: state int

variable_types: sample int

variable_types: now int

variable_types: i int

variable_types: gindex int

variable_types: row float

variable_types: col float

user_defined_types: struct CortexOutputTable_s { int request; int mode; int num_output; struct CortexOutput_s *output; }

user_defined_types: struct VInput_s { int full_bit_rows; int full_bit_cols; int subimage_bit_rows; int subimage_bit_cols; int rows; int cols; unsigned char *bits; }

user_defined_types: struct CortexOutput_s { int active; struct CortexOutputChannel_s ochan; struct Symbol_s *osym; }


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rdi

setup_opengl(0x3C0u, 0x200u);
v3 = getpid();
srand48(v3);
test_turing_machine();
exit(0);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rdi

func0(0x3C0u, 0x200u);
v3 = getpid();
srand48(v3);
test_turing_machine();
exit(0);
}

original_code:
int main(int argc, char **argv)
{
 int width;
 int height;
 width = 960;
 height = 512;
 setup_opengl(width, height);
 srand48(getpid());
 test_turing_machine();
 exit(0);
}

variable_types: argc int

variable_types:
argv
char **

variable_types: width int

variable_types: height int


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

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

original_code:
int slqline_get_slid(SLQline *slql)
{
 return slql->slid;
}

canonical_original_code:
int slqline_get_slid(struct SLQline_s *slql)
{
 return slql->slid;
}

variable_types: struct SLQline_s { int slid; int dim; int width; struct Symbol_s { unsigned short dim; float vec[1]; } **line; struct SLQline_s *next; } *

user_defined_types: struct SLQline_s { int slid; int dim; int width; struct Symbol_s **line; struct SLQline_s *next; }


decompiled_code:
__int64 __fastcall slqline_line(__int64 a1)
{
return *(_QWORD *)(a1 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
return *(_QWORD *)(a1 + 16);
}

original_code:
Symbol** slqline_line(SLQline *slql)
{
 return slql->line;
}

canonical_original_code:
struct Symbol_s **slqline_line(struct SLQline_s *slql)
{
 return slql->line;
}

variable_types: struct SLQline_s { int slid; int dim; int width; struct Symbol_s **line; struct SLQline_s *next; } *

return_type: struct Symbol_s { unsigned short dim; float vec[1]; } **


decompiled_code:
__int64 __fastcall slqline_get_width(__int64 a1)
{
return *(unsigned int *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return *(unsigned int *)(a1 + 8);
}

original_code:
int slqline_get_width(SLQline *slql)
{
 return slql->width;
}

canonical_original_code:
int slqline_get_width(struct SLQline_s *slql)
{
 return slql->width;
}

user_defined_types: struct Symbol_s { unsigned short dim; float vec[1]; }


decompiled_code:
void __fastcall slqline_free(void *ptr)
{
__int64 v1; // rbx

if ( *((int *)ptr + 2) > 0 )
{
v1 = 0LL;
do
{
if ( *(_QWORD *)(*((_QWORD *)ptr + 2) + 8 * v1) )
{
symbol_free();
*(_QWORD *)(*((_QWORD *)ptr + 2) + 8 * v1) = 0LL;
}
++v1;
}
while ( *((_DWORD *)ptr + 2) > (int)v1 );
}
free(*((void **)ptr + 2));
free(ptr);
}

original_code:
void slqline_free(SLQline *slql)
{
 int i;
 for (i = 0; i < slql->width; i++)
 {
  if (slql->line[i] != ((void *)0))
  {
   symbol_free(slql->line[i]);
   slql->line[i] = ((void *)0);
  }
 }
 free(slql->line);
 slql->line = ((void *)0);
 slql->next = ((void *)0);
 free(slql);
}

canonical_original_code:
void slqline_free(struct SLQline_s *slql)
{
 int i;
 for (i = 0; i < slql->width; i++)
 {
  if (slql->line[i] != ((void *)0))
  {
   symbol_free(slql->line[i]);
   slql->line[i] = ((void *)0);
  }
 }
 free(slql->line);
 slql->line = ((void *)0);
 slql->next = ((void *)0);
 free(slql);
}


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

result = xmalloc(32LL);
*(_DWORD *)result = 0;
*(_DWORD *)(result + 4) = 0;
*(_DWORD *)(result + 8) = a1;
*(_QWORD *)(result + 16) = 0LL;
*(_QWORD *)(result + 24) = 0LL;
return result;
}

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

result = xmalloc(32LL);
*(_DWORD *)result = 0;
*(_DWORD *)(result + 4) = 0;
*(_DWORD *)(result + 8) = a1;
*(_QWORD *)(result + 16) = 0LL;
*(_QWORD *)(result + 24) = 0LL;
return result;
}

original_code:
SLQueue* slq_init(int span)
{
 SLQueue *slq = ((void *)0);
 slq = (SLQueue*)xmalloc(sizeof(SLQueue) * 1);
 slq->finished = FALSE;
 slq->count = 0;
 slq->span = span;
 slq->tail = ((void *)0);
 slq->head = ((void *)0);
 return slq;
}

canonical_original_code:
struct SLQueue_s *slq_init(int span)
{
 struct SLQueue_s *slq = ((void *)0);
 slq = (struct SLQueue_s *)xmalloc(sizeof(SLQueue) * 1);
 slq->finished = FALSE;
 slq->count = 0;
 slq->span = span;
 slq->tail = ((void *)0);
 slq->head = ((void *)0);
 return slq;
}

variable_types: span int

variable_types: struct SLQueue_s { int finished; int count; int span; struct SLQline_s { int slid; int dim; int width; struct Symbol_s { unsigned short dim; float vec[1]; } **line; struct SLQline_s *next; } *tail; struct SLQline_s *head; } *

user_defined_types: struct SLQueue_s { int finished; int count; int span; struct SLQline_s *tail; struct SLQline_s *head; }


decompiled_code:
void __fastcall slq_free(void *ptr)
{
_QWORD *v2; // rbx
void *v3; // rdi

v2 = (_QWORD *)*((_QWORD *)ptr + 2);
while ( v2 )
{
v3 = v2;
v2 = (_QWORD *)v2[3];
slqline_free(v3);
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func6(void *ptr)
{
_QWORD *v2; // rbx
void *v3; // rdi

v2 = (_QWORD *)*((_QWORD *)ptr + 2);
while ( v2 )
{
v3 = v2;
v2 = (_QWORD *)v2[3];
func4(v3);
}
free(ptr);
}

original_code:
void slq_free(SLQueue *slq)
{
 SLQline *curr;
 SLQline *deleted;
 curr = slq->tail;
 while(curr != ((void *)0))
 {
  deleted = curr;
  curr = curr->next;
  slqline_free(deleted);
 }
 slq->tail = ((void *)0);
 slq->head = ((void *)0);
 free(slq);
}

canonical_original_code:
void slq_free(struct SLQueue_s *slq)
{
 struct SLQline_s *curr;
 struct SLQline_s *deleted;
 curr = slq->tail;
 while(curr != ((void *)0))
 {
  deleted = curr;
  curr = curr->next;
  slqline_free(deleted);
 }
 slq->tail = ((void *)0);
 slq->head = ((void *)0);
 free(slq);
}


original_code:
void slq_enqueue(SLQueue *slq, SLQline *slql)
{
 if (slq->tail == ((void *)0))
 {
  slq->tail = slql;
  slq->head = slql;
 }
 else
 {
  slq->head->next = slql;
  slq->head = slql;
 }
 slq->count++;
}

canonical_original_code:
void slq_enqueue(struct SLQueue_s *slq, struct SLQline_s *slql)
{
 if (slq->tail == ((void *)0))
 {
  slq->tail = slql;
  slq->head = slql;
 }
 else
 {
  slq->head->next = slql;
  slq->head = slql;
 }
 slq->count++;
}

variable_types:
slql
struct SLQline_s *


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

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

original_code:
int slq_get_finished(SLQueue *slq)
{
 return slq->finished;
}

canonical_original_code:
int slq_get_finished(struct SLQueue_s *slq)
{
 return slq->finished;
}


decompiled_code:
_BOOL8 __fastcall slq_empty(__int64 a1)
{
return *(_DWORD *)(a1 + 4) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func10(__int64 a1)
{
return *(_DWORD *)(a1 + 4) == 0;
}

original_code:
int slq_empty(SLQueue *slq)
{
 if (slq->count == 0)
 {
  return TRUE;
 }
 return FALSE;
}

canonical_original_code:
int slq_empty(struct SLQueue_s *slq)
{
 if (slq->count == 0)
 {
  return TRUE;
 }
 return FALSE;
}


decompiled_code:
__int64 __fastcall slq_ready(unsigned int *a1)
{
_BOOL4 v1; // edx
__int64 result; // rax

v1 = slq_empty((__int64)a1);
result = 0LL;
if ( !v1 )
{
result = slq_get_finished(a1);
if ( (_DWORD)result != 1 )
result = (int)a1[1] > (int)a1[2];
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(unsigned int *a1)
{
_BOOL4 v1; // edx
__int64 result; // rax

v1 = func10((__int64)a1);
result = 0LL;
if ( !v1 )
{
result = func9(a1);
if ( (_DWORD)result != 1 )
result = (int)a1[1] > (int)a1[2];
}
return result;
}

original_code:
int slq_ready(SLQueue *slq)
{
 if (slq_empty(slq) == TRUE)
 {
  return FALSE;
 }
 if (slq_get_finished(slq) == TRUE)
 {
  return TRUE;
 }
 if (slq->count > slq->span)
 {
  return TRUE;
 }
 return FALSE;
}

canonical_original_code:
int slq_ready(struct SLQueue_s *slq)
{
 if (slq_empty(slq) == TRUE)
 {
  return FALSE;
 }
 if (slq_get_finished(slq) == TRUE)
 {
  return TRUE;
 }
 if (slq->count > slq->span)
 {
  return TRUE;
 }
 return FALSE;
}