repo: sashabaranov/random-walk

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
int v4; // er14
unsigned int v5; // er15
double v6; // xmm0_8
unsigned int v7; // eax
int v8; // eax
int v10; // er13
void *v11; // rbp
int i; // ebx
int *v13; // rax
double v14; // xmm1_8
__int64 v15; // rcx
int *v16; // rdx
double v17; // xmm2_8
double v18; // xmm3_8
double v19; // xmm0_8
double v20; // [rsp+8h] [rbp-90h]
double v21; // [rsp+8h] [rbp-90h]
double v22; // [rsp+10h] [rbp-88h]
int v23; // [rsp+18h] [rbp-80h]
int v24; // [rsp+1Ch] [rbp-7Ch]
int *v25; // [rsp+20h] [rbp-78h]
double v26; // [rsp+28h] [rbp-70h]

omp_get_wtime();
v26 = v6;
v7 = time(0LL);
srand(v7);
while ( 2 )
{
v8 = getopt(argc, (char *const *)argv, "d:N:c:K:M:h");
if ( v8 == -1 )
{
v10 = (int)pow((double)v23, (double)v24);
v11 = malloc(4LL * v10);
memset(v11, 0, v10);
v25 = (int *)calloc(v3, 4uLL);
if ( v3 <= 0 )
{
v17 = (double)v3;
v18 = 0.0 / (double)v3;
}
else
{
for ( i = 0; i != v3; ++i )
{
regenerate(v11, (unsigned int)v10, v5);
GOMP_parallel();
}
v13 = v25;
v14 = (double)v4;
v15 = (__int64)&v25[v3 - 1 + 1];
v16 = v25;
do
v22 = (double)*v16++ / v14 + v22;
while ( (int *)v15 != v16 );
v17 = (double)v3;
v18 = v22 / (double)v3;
do
{
v19 = (double)*v13++ / v14 - v18;
v20 = v19 * v19 + v20;
}
while ( (int *)v15 != v13 );
}
v21 = sqrt(v20 / v17);
omp_get_wtime();
printf("%d %f %f %f %d %d\n", v5, v18, v21, v21 - v26, (unsigned int)v4, (unsigned int)v3);
free(v11);
}
else
{
switch ( v8 )
{
case 'K':
v3 = atoi(_bss_start);
continue;
case 'M':
v4 = atoi(_bss_start);
continue;
case 'N':
v23 = atoi(_bss_start);
continue;
case 'c':
v5 = atoi(_bss_start);
continue;
case 'd':
v24 = atoi(_bss_start);
continue;
case 'h':
puts(
"Usage:\n"
"\t-d <number>\tDimensions count\n"
"\t-N <number>\tGrid size\n"
"\t-c <number>\tCops count\n"
"\t-K <number>\tGrid regenerations count\n"
"\t-M <number>\tSimulations count per regeneration\n"
"\t-s\t\tShouting between drunkards");
break;
default:
continue;
}
}
break;
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
int v4; // er14
unsigned int v5; // er15
double v6; // xmm0_8
unsigned int v7; // eax
int v8; // eax
int v10; // er13
void *v11; // rbp
int i; // ebx
int *v13; // rax
double v14; // xmm1_8
__int64 v15; // rcx
int *v16; // rdx
double v17; // xmm2_8
double v18; // xmm3_8
double v19; // xmm0_8
double v20; // [rsp+8h] [rbp-90h]
double v21; // [rsp+8h] [rbp-90h]
double v22; // [rsp+10h] [rbp-88h]
int v23; // [rsp+18h] [rbp-80h]
int v24; // [rsp+1Ch] [rbp-7Ch]
int *v25; // [rsp+20h] [rbp-78h]
double v26; // [rsp+28h] [rbp-70h]

omp_get_wtime();
v26 = v6;
v7 = time(0LL);
srand(v7);
while ( 2 )
{
v8 = getopt(argc, (char *const *)argv, "d:N:c:K:M:h");
if ( v8 == -1 )
{
v10 = (int)pow((double)v23, (double)v24);
v11 = malloc(4LL * v10);
memset(v11, 0, v10);
v25 = (int *)calloc(v3, 4uLL);
if ( v3 <= 0 )
{
v17 = (double)v3;
v18 = 0.0 / (double)v3;
}
else
{
for ( i = 0; i != v3; ++i )
{
func10(v11, (unsigned int)v10, v5);
GOMP_parallel();
}
v13 = v25;
v14 = (double)v4;
v15 = (__int64)&v25[v3 - 1 + 1];
v16 = v25;
do
v22 = (double)*v16++ / v14 + v22;
while ( (int *)v15 != v16 );
v17 = (double)v3;
v18 = v22 / (double)v3;
do
{
v19 = (double)*v13++ / v14 - v18;
v20 = v19 * v19 + v20;
}
while ( (int *)v15 != v13 );
}
v21 = sqrt(v20 / v17);
omp_get_wtime();
printf("%d %f %f %f %d %d\n", v5, v18, v21, v21 - v26, (unsigned int)v4, (unsigned int)v3);
free(v11);
}
else
{
switch ( v8 )
{
case 'K':
v3 = atoi(_bss_start);
continue;
case 'M':
v4 = atoi(_bss_start);
continue;
case 'N':
v23 = atoi(_bss_start);
continue;
case 'c':
v5 = atoi(_bss_start);
continue;
case 'd':
v24 = atoi(_bss_start);
continue;
case 'h':
puts(
"Usage:\n"
"\t-d <number>\tDimensions count\n"
"\t-N <number>\tGrid size\n"
"\t-c <number>\tCops count\n"
"\t-K <number>\tGrid regenerations count\n"
"\t-M <number>\tSimulations count per regeneration\n"
"\t-s\t\tShouting between drunkards");
break;
default:
continue;
}
}
break;
}
return 0;
}

original_code:
int main(int argc, char *argv[])
{
    double start = omp_get_wtime();
    srand ( time(((void *)0)) );
    int dim, N, grid_size;
    int cops;
    int K;
    int M;
    int i, j;
    int *grid, *stats;
    int threads_num, tid;
    int go_flag, count;
    unsigned short state[3];
    unsigned int seed;
    int res = 0;
    char* usage = "Usage:\n"
                  "\t-d <number>\tDimensions count\n"
                  "\t-N <number>\tGrid size\n"
                  "\t-c <number>\tCops count\n"
                  "\t-K <number>\tGrid regenerations count\n"
                  "\t-M <number>\tSimulations count per regeneration\n"
                  "\t-s\t\tShouting between drunkards\n";
    while((res = getopt(argc, argv, "d:N:c:K:M:h")) != -1)
    {
        switch(res)
        {
            case 'd': dim = atoi(optarg); break;
            case 'N': N = atoi(optarg); break;
            case 'c': cops = atoi(optarg); break;
            case 'K': K = atoi(optarg); break;
            case 'M': M = atoi(optarg); break;
            case 'h': printf("%s", usage); return 0;
        }
    }
    grid_size = pow(N, dim);
    grid = malloc(grid_size * sizeof(int));
    memset(grid, 0, grid_size);
    stats = calloc(K, sizeof(int));
    for(i = 0; i < K; ++i)
    {
        regenerate(grid, grid_size, cops);

#pragma omp parallel shared(grid, stats) private(j, tid, threads_num, state, seed, go_flag, count) firstprivate(i, grid_size, K, M, N, dim)
        {
            tid = omp_get_thread_num();
            threads_num = omp_get_num_threads();
            seed = time(((void *)0)) + (unsigned int) omp_get_thread_num();
            memcpy(state, &seed, sizeof(seed));
            int* drunkards = calloc(M/threads_num, sizeof(int));
            go_flag = M/threads_num;
            while(go_flag)
            {
                count = 0;
                for(j = 0; j < M/threads_num; ++j)
                {
                    if(drunkards[j] != -1)
                    {
                        ++ count;
                        drunkards[j] = step(drunkards[j], dim, grid_size, state, N);
                        if(grid[drunkards[j]] == 1)
                        {
                            drunkards[j] = -1;
                        }
                        if(drunkards[j] == grid_size)
                        {

#pragma omp atomic
                            stats[i] += 1;
                            drunkards[j] = -1;
                        }
                    }
                }
                if(count == 0) go_flag = 0;
            }
            free(drunkards);
        }
    }
    double avg, stddev;
    for(i = 0; i < K; ++i) avg += (double) stats[i] / M;
    avg /= K;
    for(i = 0; i < K; ++i) stddev += ((double)stats[i]/M - avg) * ((double)stats[i]/M - avg);
    stddev = sqrt(stddev / K);
    double end = omp_get_wtime();
    printf("%d %f %f %f %d %d\n", cops, avg, stddev, end - start, M, K);
    free(grid);
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    double start = omp_get_wtime();
    srand ( time(((void *)0)) );
    int dim; int N; int grid_size;
    int cops;
    int K;
    int M;
    int i; int j;
    int *grid; int *stats;
    int threads_num; int tid;
    int go_flag; int count;
    unsigned short state[3];
    unsigned int seed;
    int res = 0;
    char *usage = "Usage:\n"
                  "\t-d <number>\tDimensions count\n"
                  "\t-N <number>\tGrid size\n"
                  "\t-c <number>\tCops count\n"
                  "\t-K <number>\tGrid regenerations count\n"
                  "\t-M <number>\tSimulations count per regeneration\n"
                  "\t-s\t\tShouting between drunkards\n";
    while((res = getopt(argc, argv, "d:N:c:K:M:h")) != -1)
    {
        switch(res)
        {
            case 'd': dim = atoi(optarg); break;
            case 'N': N = atoi(optarg); break;
            case 'c': cops = atoi(optarg); break;
            case 'K': K = atoi(optarg); break;
            case 'M': M = atoi(optarg); break;
            case 'h': printf("%s", usage); return 0;
        }
    }
    grid_size = pow(N, dim);
    grid = malloc(grid_size * sizeof(int));
    memset(grid, 0, grid_size);
    stats = calloc(K, sizeof(int));
    for(i = 0; i < K; ++i)
    {
        regenerate(grid, grid_size, cops);

#pragma omp parallel shared(grid, stats) private(j, tid, threads_num, state, seed, go_flag, count) firstprivate(i, grid_size, K, M, N, dim)
        {
            tid = omp_get_thread_num();
            threads_num = omp_get_num_threads();
            seed = time(((void *)0)) + (unsigned int) omp_get_thread_num();
            memcpy(state, &seed, sizeof(seed));
            int *drunkards = calloc(M/threads_num, sizeof(int));
            go_flag = M/threads_num;
            while(go_flag)
            {
                count = 0;
                for(j = 0; j < M/threads_num; ++j)
                {
                    if(drunkards[j] != -1)
                    {
                        ++ count;
                        drunkards[j] = step(drunkards[j], dim, grid_size, state, N);
                        if(grid[drunkards[j]] == 1)
                        {
                            drunkards[j] = -1;
                        }
                        if(drunkards[j] == grid_size)
                        {

#pragma omp atomic
                            stats[i] += 1;
                            drunkards[j] = -1;
                        }
                    }
                }
                if(count == 0) go_flag = 0;
            }
            free(drunkards);
        }
    }
    double avg; double stddev;
    for(i = 0; i < K; ++i) avg += (double) stats[i] / M;
    avg /= K;
    for(i = 0; i < K; ++i) stddev += ((double)stats[i]/M - avg) * ((double)stats[i]/M - avg);
    stddev = sqrt(stddev / K);
    double end = omp_get_wtime();
    printf("%d %f %f %f %d %d\n", cops, avg, stddev, end - start, M, K);
    free(grid);
    return 0;
}

variable_types: argc int

variable_types: start double

variable_types: dim int

variable_types: N int

variable_types: cops int

variable_types: K int

variable_types: M int

variable_types: j int

variable_types:
grid
int *

variable_types:
stats
int *

variable_types: tid int

variable_types:
state
unsigned short [3]

variable_types:
seed
unsigned int

variable_types: res int

variable_types:
usage
char *

variable_types:
drunkards
int *

variable_types: avg double

variable_types: stddev double

variable_types: end double


rnd

decompiled_code:
__int64 __fastcall rnd(int a1, int a2, unsigned __int16 *a3)
{
return a1 + (unsigned int)(nrand48(a3) % a2);
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1, int a2, unsigned __int16 *a3)
{
return a1 + (unsigned int)(nrand48(a3) % a2);
}

original_code:
int rnd(int min, int max, unsigned short *state)
{
  return nrand48(state) % max + min;
}

variable_types: min int

variable_types: max int

variable_types:
state
unsigned short *

return_type: int


step

decompiled_code:
__int64 __fastcall step(unsigned int a1, int a2, int a3, unsigned __int16 *a4, int a5)
{
unsigned int v7; // er14
int v8; // er13
double v9; // r15
int v10; // eax
double v12; // [rsp+8h] [rbp-40h]

if ( a2 <= 0 )
return a1;
v7 = a1;
v8 = 0;
v9 = (double)a5;
do
{
v12 = pow(v9, (double)v8);
v10 = v7 + (int)((double)(int)rnd(-1, 3, a4) * v12);
if ( v10 <= a3 && v10 > 0 )
v7 = v10;
++v8;
}
while ( a2 != v8 );
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int a1, int a2, int a3, unsigned __int16 *a4, int a5)
{
unsigned int v7; // er14
int v8; // er13
double v9; // r15
int v10; // eax
double v12; // [rsp+8h] [rbp-40h]

if ( a2 <= 0 )
return a1;
v7 = a1;
v8 = 0;
v9 = (double)a5;
do
{
v12 = pow(v9, (double)v8);
v10 = v7 + (int)((double)(int)func7(-1, 3, a4) * v12);
if ( v10 <= a3 && v10 > 0 )
v7 = v10;
++v8;
}
while ( a2 != v8 );
return v7;
}

original_code:
int step(int offset, int dim, int grid_size, unsigned short *state, int N)
{
    int k, d;
    for(k = 0; k < dim; ++k)
    {
        d = pow(N, k) * rnd(-1, 3, state);
        if(offset + d > 0 && offset + d <= grid_size) offset += d;
    }
    return offset;
}

canonical_original_code:
int step(int offset, int dim, int grid_size, unsigned short *state, int N)
{
    int k; int d;
    for(k = 0; k < dim; ++k)
    {
        d = pow(N, k) * rnd(-1, 3, state);
        if(offset + d > 0 && offset + d <= grid_size) offset += d;
    }
    return offset;
}

variable_types: offset int

variable_types: dim int

variable_types: N int

variable_types: k int

variable_types: d int


regenerate

decompiled_code:
char *__fastcall regenerate(char *a1, int a2, int a3)
{
int v3; // er13
char *result; // rax

v3 = 0;
result = (char *)memset(a1, 0, 4LL * a2);
while ( v3 < a3 )
{
result = &a1[4 * (rand() % a2)];
if ( *(_DWORD *)result != 1 )
{
*(_DWORD *)result = 1;
++v3;
}
}
return result;
}

canonical_decompiled_code:
char *__fastcall func10(char *a1, int a2, int a3)
{
int v3; // er13
char *result; // rax

v3 = 0;
result = (char *)memset(a1, 0, 4LL * a2);
while ( v3 < a3 )
{
result = &a1[4 * (rand() % a2)];
if ( *(_DWORD *)result != 1 )
{
*(_DWORD *)result = 1;
++v3;
}
}
return result;
}

original_code:
void regenerate(int* grid, int grid_size, int cops)
{
    memset(grid, 0, grid_size * sizeof(int));
    int pos, count = 0;
    while(count < cops)
    {
         pos = rand() % grid_size;
         if(grid[pos] != 1)
         {
            grid[pos] = 1;
            ++ count;
         }
    }
}

canonical_original_code:
void regenerate(int *grid, int grid_size, int cops)
{
    memset(grid, 0, grid_size * sizeof(int));
    int pos; int count = 0;
    while(count < cops)
    {
         pos = rand() % grid_size;
         if(grid[pos] != 1)
         {
            grid[pos] = 1;
            ++ count;
         }
    }
}

variable_types:
grid
int *

variable_types: cops int

variable_types: pos int

variable_types: count int

return_type: void


repo: sashalevin/uvirtio

decompiled_code:
__int64 __fastcall vring_init(__int64 a1, unsigned int a2, __int64 a3, __int64 a4)
{
__int64 v4; // rdx
__int64 result; // rax

*(_DWORD *)a1 = a2;
*(_QWORD *)(a1 + 8) = a3;
v4 = 16LL * a2 + a3;
*(_QWORD *)(a1 + 16) = v4;
result = a4 + v4 + 2LL * a2 + 4 + 1;
*(_QWORD *)(a1 + 24) = result & -a4;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned int a2, __int64 a3, __int64 a4)
{
__int64 v4; // rdx
__int64 result; // rax

*(_DWORD *)a1 = a2;
*(_QWORD *)(a1 + 8) = a3;
v4 = 16LL * a2 + a3;
*(_QWORD *)(a1 + 16) = v4;
result = a4 + v4 + 2LL * a2 + 4 + 1;
*(_QWORD *)(a1 + 24) = result & -a4;
return result;
}

original_code:
static __inline__ void vring_init(struct vring *vr, unsigned int num, void *p,
         unsigned long align)
{
 vr->num = num;
 vr->desc = p;
 vr->avail = p + num*sizeof(struct vring_desc);
 vr->used = (void *)(((uintptr_t)&vr->avail->ring[num] + sizeof(__virtio16)
  + align-1) & ~(align - 1));
}

canonical_original_code:
static __inline__ void vring_init(struct vring *vr, unsigned int num, void *p, unsigned long align)
{
 vr->num = num;
 vr->desc = p;
 vr->avail = p + num*sizeof(struct vring_desc);
 vr->used = (void *)(((unsigned long)&vr->avail->ring[num] + sizeof(__virtio16)
  + align-1) & ~(align - 1));
}

variable_types: struct vring { unsigned int num; struct vring_desc { unsigned long long addr; unsigned int len; unsigned short flags; unsigned short next; } *desc; struct vring_avail { unsigned short flags; unsigned short idx; unsigned short ring[]; } *avail; struct vring_used { unsigned short flags; unsigned short idx; struct vring_used_elem { unsigned int id; unsigned int len; } ring[]; } *used; } *

variable_types:
num
unsigned int

variable_types:
p
void *

variable_types:
align
unsigned long

user_defined_types: struct vring { unsigned int num; struct vring_desc *desc; struct vring_avail *avail; struct vring_used *used; }

user_defined_types: struct vring_used { unsigned short flags; unsigned short idx; struct vring_used_elem ring[]; }


decompiled_code:
__int64 test1()
{
int v0; // ebp
int v1; // ebx
__int64 result; // rax
double v3; // xmm0_8

v0 = 2;
puts("simulator test 1");
puts("starting server");
system("gnome-terminal --window-with-profile=NAMEOFTHEPROFILE -x ./server ");
while ( 1 )
{
v1 = 101;
printf("delay");
do
{
putchar(46);
--v1;
}
while ( v1 );
putchar(10);
puts("starting client");
system("gnome-terminal --window-with-profile=NAMEOFTHEPROFILE -x ./client 127.0.0.1 ");
result = 0x412E848000000000LL;
v3 = 1000000.0;
do
v3 = v3 - 1.0;
while ( v3 >= 0.0 );
if ( v0 == 1 )
break;
v0 = 1;
}
return result;
}

canonical_decompiled_code:
__int64 func7()
{
int v0; // ebp
int v1; // ebx
__int64 result; // rax
double v3; // xmm0_8

v0 = 2;
puts("simulator test 1");
puts("starting server");
system("gnome-terminal --window-with-profile=NAMEOFTHEPROFILE -x ./server ");
while ( 1 )
{
v1 = 101;
printf("delay");
do
{
putchar(46);
--v1;
}
while ( v1 );
putchar(10);
puts("starting client");
system("gnome-terminal --window-with-profile=NAMEOFTHEPROFILE -x ./client 127.0.0.1 ");
result = 0x412E848000000000LL;
v3 = 1000000.0;
do
v3 = v3 - 1.0;
while ( v3 >= 0.0 );
if ( v0 == 1 )
break;
v0 = 1;
}
return result;
}

original_code:
void test1() {
    printf("simulator test 1\n");
    double delay = 100, wait = 1000000;
    char *client_str, *server_str, *server_str2;
    int count = 2, buf, status;
    pid_t pid;
    client_str = "gnome-terminal  --window-with-profile=NAMEOFTHEPROFILE -x ./client  127.0.0.1 ";
    server_str = "gnome-terminal --window-with-profile=NAMEOFTHEPROFILE -x ./server ";
    server_str2 = "./server";
    printf("starting server\n");
    system(server_str);
    while (count > 0) {
        count--;
        printf("delay");
        while (delay >= 0) {
            printf(".");
            delay--;
        }
        delay = 100;
        printf("\n");
         printf("starting client\n");
        system(client_str);
        while(wait>=0){
            wait--;
        }
        wait = 1000000;
    }
}

canonical_original_code:
void test1() {
    printf("simulator test 1\n");
    double delay = 100; double wait = 1000000;
    char *client_str; char *server_str; char *server_str2;
    int count = 2; int buf; int status;
    int pid;
    client_str = "gnome-terminal  --window-with-profile=NAMEOFTHEPROFILE -x ./client  127.0.0.1 ";
    server_str = "gnome-terminal --window-with-profile=NAMEOFTHEPROFILE -x ./server ";
    server_str2 = "./server";
    printf("starting server\n");
    system(server_str);
    while (count > 0) {
        count--;
        printf("delay");
        while (delay >= 0) {
            printf(".");
            delay--;
        }
        delay = 100;
        printf("\n");
         printf("starting client\n");
        system(client_str);
        while(wait>=0){
            wait--;
        }
        wait = 1000000;
    }
}

variable_types: delay double

variable_types: wait double

variable_types: buf int

variable_types: status int

variable_types: pid int


decompiled_code:
int test2()
{
puts("simulator test 2");
return printf("%%TEST_FAILED%% time=0 testname=test2 (simulator) message=error message sample\n");
}

canonical_decompiled_code:
int func8()
{
puts("simulator test 2");
return printf("%%TEST_FAILED%% time=0 testname=test2 (simulator) message=error message sample\n");
}

original_code:
void test2() {
    printf("simulator test 2\n");
    printf("%%TEST_FAILED%% time=0 testname=test2 (simulator) message=error message sample\n");
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
printf("%%SUITE_STARTING%% simulator\n");
printf("%%SUITE_STARTED%%\n");
printf("%%TEST_STARTED%% test1 (simulator)\n");
test1("%%TEST_STARTED%% test1 (simulator)\n", argv);
printf("%%TEST_FINISHED%% time=0 test1 (simulator) \n");
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
printf("%%SUITE_STARTING%% simulator\n");
printf("%%SUITE_STARTED%%\n");
printf("%%TEST_STARTED%% test1 (simulator)\n");
func7("%%TEST_STARTED%% test1 (simulator)\n", argv);
printf("%%TEST_FINISHED%% time=0 test1 (simulator) \n");
return 0;
}

original_code:
int main(int argc, char** argv) {
    printf("%%SUITE_STARTING%% simulator\n");
    printf("%%SUITE_STARTED%%\n");
    printf("%%TEST_STARTED%% test1 (simulator)\n");
    test1();
    printf("%%TEST_FINISHED%% time=0 test1 (simulator) \n");
    return (0);
}

canonical_original_code:
int main(int argc, char **argv) {
    printf("%%SUITE_STARTING%% simulator\n");
    printf("%%SUITE_STARTED%%\n");
    printf("%%TEST_STARTED%% test1 (simulator)\n");
    test1();
    printf("%%TEST_FINISHED%% time=0 test1 (simulator) \n");
    return (0);
}

variable_types: argc int

variable_types:
argv
char **


repo: sathesh/hash-library

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v3; // r13
unsigned int *v4; // rax
unsigned int *v5; // rbp
__int64 v6; // r12
int v7; // ebx
unsigned int *v8; // rax
__int64 v9; // rax
unsigned int v11; // [rsp+0h] [rbp-38h] BYREF
int v12; // [rsp+4h] [rbp-34h] BYREF
__int64 v13[6]; // [rsp+8h] [rbp-30h] BYREF

v3 = (void *)hash_init(10LL, 0LL, uint_key_cmp);
while ( 1 )
{
v11 = 777;
puts("\n\n\n0. quit\n1. Insert \n2. Delete \n3. Lookup \n4. Print Distribution");
printf("\tEnter ur option: ");
__isoc99_scanf();
getchar();
if ( !v11 )
return hash_deinit(v3);
if ( v11 == 3 )
{
printf("\nLook up key: ");
__isoc99_scanf();
v8 = (unsigned int *)hash_lookup(v3, v13);
if ( v8 )
printf("data: %u", *v8);
else
LABEL_20:
puts("key not found");
}
else if ( v11 > 3 )
{
if ( v11 == 4 )
{
v12 = 0;
hash_distribution(v3, v13, &v12);
if ( v12 > 0 )
{
v6 = 0LL;
do
{
printf("[%u]:", (unsigned int)v6);
if ( *(int *)(v13[0] + 4 * v6) > 0 )
{
v7 = 0;
do
{
++v7;
putchar(46);
}
while ( *(_DWORD *)(v13[0] + 4 * v6) > v7 );
}
++v6;
putchar(10);
}
while ( v12 > (int)v6 );
}
}
}
else if ( v11 == 1 )
{
v9 = create_data_box("%u", &v11);
if ( (unsigned int)hash_insert(v3, v9, v9) == 1 )
puts("Insert done");
else
puts("Insert failed");
}
else
{
printf("\nDelete key: ");
__isoc99_scanf();
v4 = (unsigned int *)hash_delete(v3, v13);
v5 = v4;
if ( !v4 )
goto LABEL_20;
printf("data: %u", *v4);
free(v5);
}
}
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v3; // r13
unsigned int *v4; // rax
unsigned int *v5; // rbp
__int64 v6; // r12
int v7; // ebx
unsigned int *v8; // rax
__int64 v9; // rax
unsigned int v11; // [rsp+0h] [rbp-38h] BYREF
int v12; // [rsp+4h] [rbp-34h] BYREF
__int64 v13[6]; // [rsp+8h] [rbp-30h] BYREF

v3 = (void *)hash_init(10LL, 0LL, uint_key_cmp);
while ( 1 )
{
v11 = 777;
puts("\n\n\n0. quit\n1. Insert \n2. Delete \n3. Lookup \n4. Print Distribution");
printf("\tEnter ur option: ");
__isoc99_scanf();
getchar();
if ( !v11 )
return func13(v3);
if ( v11 == 3 )
{
printf("\nLook up key: ");
__isoc99_scanf();
v8 = (unsigned int *)func16(v3, v13);
if ( v8 )
printf("data: %u", *v8);
else
LABEL_20:
puts("key not found");
}
else if ( v11 > 3 )
{
if ( v11 == 4 )
{
v12 = 0;
func14(v3, v13, &v12);
if ( v12 > 0 )
{
v6 = 0LL;
do
{
printf("[%u]:", (unsigned int)v6);
if ( *(int *)(v13[0] + 4 * v6) > 0 )
{
v7 = 0;
do
{
++v7;
putchar(46);
}
while ( *(_DWORD *)(v13[0] + 4 * v6) > v7 );
}
++v6;
putchar(10);
}
while ( v12 > (int)v6 );
}
}
}
else if ( v11 == 1 )
{
v9 = create_data_box("%u", &v11);
if ( (unsigned int)func15(v3, v9, v9) == 1 )
puts("Insert done");
else
puts("Insert failed");
}
else
{
printf("\nDelete key: ");
__isoc99_scanf();
v4 = (unsigned int *)func17(v3, v13);
v5 = v4;
if ( !v4 )
goto LABEL_20;
printf("data: %u", *v4);
free(v5);
}
}
}

original_code:
void main()
{
  unsigned int user_input;
  hash_handle_t hash_handle;
   hash_handle = hash_init(10,
                           ((void *)0),
                           uint_key_cmp);
  do
  {
    user_input = 777;
    printf("\n\n\n0. quit\n1. Insert \n2. Delete \n" "3. Lookup \n4. Print Distribution\n");
    printf("\tEnter ur option: ");
    scanf("%u", &user_input);
    getchar();
    if (user_input == 0)
      break;
    switch(user_input)
    {
      case 1:
        {
          data_box_t *data_box = create_data_box();
          if (1 == hash_insert(hash_handle, &data_box->data, data_box))
          {
            printf("Insert done\n");
          }
          else
          {
            printf("Insert failed\n");
          }
        }
        break;
      case 2:
        {
          data_box_t *data_box;
          unsigned int key;
          printf("\nDelete key: ");
          scanf("%u", &key);
          data_box = hash_delete(hash_handle, &key);
          if (data_box)
          {
            printf ("data: %u", data_box->data);
            free (data_box);
          }
          else
          {
            printf ("key not found\n");
          }
        }
        break;
      case 3:
        {
          data_box_t *data_box;
          unsigned int key;
          printf("\nLook up key: ");
          scanf("%u", &key);
          data_box = hash_lookup(hash_handle, &key);
          if (data_box)
            printf ("data: %u", data_box->data);
          else
            printf ("key not found\n");
        }
        break;
      case 4:
        {
          int bkt_size= 0;
          int *result;
          int i,j;
          hash_distribution(hash_handle, &result, &bkt_size);
          for (i=0; i< bkt_size; i++)
          {
              printf("[%u]:", i);
              for (j=0; j<result[i]; j++)
                printf(".");
              printf("\n");
          }
        }
    }
  }while(1);
  hash_deinit(hash_handle);
}

canonical_original_code:
void main()
{
  unsigned int user_input;
  void *hash_handle;
   hash_handle = hash_init(10,
                           ((void *)0),
                           uint_key_cmp);
  do
  {
    user_input = 777;
    printf("\n\n\n0. quit\n1. Insert \n2. Delete \n" "3. Lookup \n4. Print Distribution\n");
    printf("\tEnter ur option: ");
    scanf("%u", &user_input);
    getchar();
    if (user_input == 0)
      break;
    switch(user_input)
    {
      case 1:
        {
          struct data_box *data_box = create_data_box();
          if (1 == hash_insert(hash_handle, &data_box->data, data_box))
          {
            printf("Insert done\n");
          }
          else
          {
            printf("Insert failed\n");
          }
        }
        break;
      case 2:
        {
          struct data_box *data_box;
          unsigned int key;
          printf("\nDelete key: ");
          scanf("%u", &key);
          data_box = hash_delete(hash_handle, &key);
          if (data_box)
          {
            printf ("data: %u", data_box->data);
            free (data_box);
          }
          else
          {
            printf ("key not found\n");
          }
        }
        break;
      case 3:
        {
          struct data_box *data_box;
          unsigned int key;
          printf("\nLook up key: ");
          scanf("%u", &key);
          data_box = hash_lookup(hash_handle, &key);
          if (data_box)
            printf ("data: %u", data_box->data);
          else
            printf ("key not found\n");
        }
        break;
      case 4:
        {
          int bkt_size = 0;
          int *result;
          int i; int j;
          hash_distribution(hash_handle, &result, &bkt_size);
          for (i=0; i< bkt_size; i++)
          {
              printf("[%u]:", i);
              for (j=0; j<result[i]; j++)
                printf(".");
              printf("\n");
          }
        }
    }
  }while(1);
  hash_deinit(hash_handle);
}

variable_types: struct data_box { unsigned int data; } *

variable_types:
key
unsigned int

variable_types:
result
int *

variable_types: i int

variable_types: j int


decompiled_code:
__int64 __fastcall uint_key_cmp(_DWORD *a1, _DWORD *a2)
{
return (unsigned int)-(*a1 != *a2);
}

canonical_decompiled_code:
__int64 __fastcall func7(_DWORD *a1, _DWORD *a2)
{
return (unsigned int)-(*a1 != *a2);
}

original_code:
int uint_key_cmp(void *v1, void *v2)
{
  unsigned int *p1 = (unsigned int *)v1;
  unsigned int *p2 = (unsigned int *)v2;
  if (*p1 == *p2)
    return 0;
  else
    return -1;
}


decompiled_code:
_BOOL8 __fastcall cmp_char(_BYTE *a1, _BYTE *a2)
{
return *a1 != *a2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func8(_BYTE *a1, _BYTE *a2)
{
return *a1 != *a2;
}

original_code:
int cmp_char(char* a, char* b)
{
  if (*a == *b)
    return 0;
  else
    return 1;
}

canonical_original_code:
int cmp_char(char *a, char *b)
{
  if (*a == *b)
    return 0;
  else
    return 1;
}

variable_types:
a
char *

variable_types:
b
char *


decompiled_code:
__int64 __fastcall hash_function_int(unsigned int a1, _DWORD *a2)
{
return *a2 % a1;
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned int a1, _DWORD *a2)
{
return *a2 % a1;
}

original_code:
int hash_function_int(unsigned int bkt_size, void *key_p)
{
  return (*(unsigned int *)key_p%bkt_size);
}


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

v4 = *a1;
v5 = *((_QWORD *)a1 + 1);
if ( *a1 )
{
if ( !v5 )
LABEL_3:
__assert_fail(
"(bkt->length == 0 && bkt->head == NULL) || (bkt->length != 0 && bkt->head != NULL)",
"../hashlib/hash.c",
0xD9u,
"INSERT_NODE");
v6 = malloc(0x18uLL);
if ( v6 )
{
v6[1] = a2;
v6[2] = a3;
*v6 = v5;
LABEL_7:
*((_QWORD *)a1 + 1) = v6;
result = 1LL;
*a1 = v4 + 1;
return result;
}
}
else
{
if ( v5 )
goto LABEL_3;
v6 = malloc(0x18uLL);
if ( v6 )
{
*v6 = 0LL;
v6[1] = a2;
v6[2] = a3;
goto LABEL_7;
}
}
return 0LL;
}

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

v4 = *a1;
v5 = *((_QWORD *)a1 + 1);
if ( *a1 )
{
if ( !v5 )
LABEL_3:
__assert_fail(
"(bkt->length == 0 && bkt->head == NULL) || (bkt->length != 0 && bkt->head != NULL)",
"../hashlib/hash.c",
0xD9u,
"INSERT_NODE");
v6 = malloc(0x18uLL);
if ( v6 )
{
v6[1] = a2;
v6[2] = a3;
*v6 = v5;
LABEL_7:
*((_QWORD *)a1 + 1) = v6;
result = 1LL;
*a1 = v4 + 1;
return result;
}
}
else
{
if ( v5 )
goto LABEL_3;
v6 = malloc(0x18uLL);
if ( v6 )
{
*v6 = 0LL;
v6[1] = a2;
v6[2] = a3;
goto LABEL_7;
}
}
return 0LL;
}

original_code:
static int INSERT_NODE(hash_bkt_t *bkt, void *key, void *data)
{
  list_node_t *tmp;
  ((void) sizeof (((bkt->length == 0 && bkt->head == ((void *)0)) || (bkt->length != 0 && bkt->head != ((void *)0))) ? 1 : 0), __extension__ ({ if ((bkt->length == 0 && bkt->head == ((void *)0)) || (bkt->length != 0 && bkt->head != ((void *)0))) ; else __assert_fail ("(bkt->length == 0 && bkt->head == NULL) || (bkt->length != 0 && bkt->head != NULL)", "../hashlib/hash.c", 217, __extension__ __PRETTY_FUNCTION__); }));
  tmp = malloc(sizeof(list_node_t));
  if (!tmp)
    return 0;
  tmp->next = ((void *)0);
  tmp->key = key;
  tmp->data = data;
  if (!bkt->head)
  {
    tmp->next = ((void *)0);
  }
  else
  {
    tmp->next = bkt->head;
  }
  bkt->head = tmp;
  bkt->length++;
  return 1;
}

canonical_original_code:
static int INSERT_NODE(struct hash_bkt_struct *bkt, void *key, void *data)
{
  struct list_node *tmp;
  ((void) sizeof (((bkt->length == 0 && bkt->head == ((void *)0)) || (bkt->length != 0 && bkt->head != ((void *)0))) ? 1 : 0), __extension__ ({ if ((bkt->length == 0 && bkt->head == ((void *)0)) || (bkt->length != 0 && bkt->head != ((void *)0))) ; else __assert_fail ("(bkt->length == 0 && bkt->head == NULL) || (bkt->length != 0 && bkt->head != NULL)", "../hashlib/hash.c", 217, __extension__ __PRETTY_FUNCTION__); }));
  tmp = malloc(sizeof(list_node_t));
  if (!tmp)
    return 0;
  tmp->next = ((void *)0);
  tmp->key = key;
  tmp->data = data;
  if (!bkt->head)
  {
    tmp->next = ((void *)0);
  }
  else
  {
    tmp->next = bkt->head;
  }
  bkt->head = tmp;
  bkt->length++;
  return 1;
}

variable_types: struct hash_bkt_struct { unsigned int length; struct list_node { struct list_node *next; void *key; void *data; } *head; } *

variable_types:
key
void *

variable_types:
data
void *

user_defined_types: struct hash_bkt_struct { unsigned int length; struct list_node *head; }


decompiled_code:
__int64 __fastcall hashpjw_string(unsigned int a1, _BYTE *a2)
{
int v2; // edx
unsigned int v3; // eax

v2 = (char)*a2;
if ( !*a2 )
return 0LL;
v3 = 0;
do
{
v3 = v2 + 16 * v3;
if ( (v3 & 0xF0000000) != 0 )
v3 = ((int)(v3 & 0xF0000000) >> 24) ^ v3 & 0xFFFFFFF;
v2 = (char)*++a2;
}
while ( (_BYTE)v2 );
return v3 % a1;
}

canonical_decompiled_code:
__int64 __fastcall func12(unsigned int a1, _BYTE *a2)
{
int v2; // edx
unsigned int v3; // eax

v2 = (char)*a2;
if ( !*a2 )
return 0LL;
v3 = 0;
do
{
v3 = v2 + 16 * v3;
if ( (v3 & 0xF0000000) != 0 )
v3 = ((int)(v3 & 0xF0000000) >> 24) ^ v3 & 0xFFFFFFF;
v2 = (char)*++a2;
}
while ( (_BYTE)v2 );
return v3 % a1;
}

original_code:
int hashpjw_string(unsigned int bkt_size, const void *key)
{
  const char *ptr;
  int val;
  val = 0;
  ptr = key;
  while (*ptr != '\0') {
    int tmp;
    val = (val << 4) + (*ptr);
    if (tmp = (val & 0xf0000000)) {
      val = val ^ (tmp >> 24);
      val = val ^ tmp;
    }
    ptr++;
  }
  return val % bkt_size;
}

canonical_original_code:
int hashpjw_string(unsigned int bkt_size, void *key)
{
  char *ptr;
  int val;
  val = 0;
  ptr = key;
  while (*ptr != '\0') {
    int tmp;
    val = (val << 4) + (*ptr);
    if (tmp = (val & 0xf0000000)) {
      val = val ^ (tmp >> 24);
      val = val ^ tmp;
    }
    ptr++;
  }
  return val % bkt_size;
}

variable_types:
ptr
char *

variable_types: val int

variable_types: tmp int


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

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

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

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

original_code:
int hash_deinit(hash_handle_t handle)
{
  hash_root_t *root = (hash_root_t*)handle;
  int i;
  for (i=0; i<root->bkt_size; i++)
  {
    if (root->hash_bkt[i])
    {
      hash_bkt_deinit(root->hash_bkt[i]);
      free(root->hash_bkt[i]);
    }
  }
  free(root->hash_bkt);
  free(root);
}

canonical_original_code:
int hash_deinit(void *handle)
{
  struct hash_root *root = (hash_root_t*)handle;
  int i;
  for (i=0; i<root->bkt_size; i++)
  {
    if (root->hash_bkt[i])
    {
      hash_bkt_deinit(root->hash_bkt[i]);
      free(root->hash_bkt[i]);
    }
  }
  free(root->hash_bkt);
  free(root);
}

variable_types:
handle
void *

variable_types: struct hash_root { unsigned int bkt_size; int (*hash_fn)(unsigned int bkt_size, void *); int (*key_cmp_fn)(void *, void *); struct hash_bkt_struct { unsigned int length; struct list_node { struct list_node *next; void *key; void *data; } *head; } **hash_bkt; unsigned int total_elements; } *

user_defined_types: struct hash_root { unsigned int bkt_size; int (*hash_fn)(unsigned int bkt_size, void *); int (*key_cmp_fn)(void *, void *); struct hash_bkt_struct **hash_bkt; unsigned int total_elements; }


decompiled_code:
__int64 __fastcall hash_insert(unsigned int *a1, __int64 a2, __int64 a3)
{
int **v5; // r13
int *v6; // rdi
__int64 result; // rax
int *v8; // rax

v5 = (int **)(*((_QWORD *)a1 + 3) + 8LL * (*((unsigned int (__fastcall **)(_QWORD))a1 + 1))(*a1));
v6 = *v5;
if ( !*v5 )
{
v8 = (int *)malloc(0x10uLL);
*v5 = v8;
v6 = v8;
if ( !v8 )
return 0LL;
*v8 = 0;
*((_QWORD *)v8 + 1) = 0LL;
}
result = INSERT_NODE(v6, a2, a3);
if ( (_DWORD)result == 1 )
++a1[8];
return result;
}

canonical_decompiled_code:
__int64 __fastcall func15(unsigned int *a1, __int64 a2, __int64 a3)
{
int **v5; // r13
int *v6; // rdi
__int64 result; // rax
int *v8; // rax

v5 = (int **)(*((_QWORD *)a1 + 3) + 8LL * (*((unsigned int (__fastcall **)(_QWORD))a1 + 1))(*a1));
v6 = *v5;
if ( !*v5 )
{
v8 = (int *)malloc(0x10uLL);
*v5 = v8;
v6 = v8;
if ( !v8 )
return 0LL;
*v8 = 0;
*((_QWORD *)v8 + 1) = 0LL;
}
result = func11(v6, a2, a3);
if ( (_DWORD)result == 1 )
++a1[8];
return result;
}

original_code:
int hash_insert(hash_handle_t handle, void *key, void* data)
{
  hash_root_t *root = (hash_root_t*)handle;
  unsigned int hash_index = root->hash_fn(root->bkt_size, key);
  int result;
  if (!root->hash_bkt[hash_index])
  {
     root->hash_bkt[hash_index] = malloc(sizeof(hash_bkt_t));
     if (!root->hash_bkt[hash_index])
       return 0;
     root->hash_bkt[hash_index]->length = 0;
     root->hash_bkt[hash_index]->head = ((void *)0);
  }
  result = INSERT_NODE(root->hash_bkt[hash_index], key, data);
  if (result == 1)
    root->total_elements++;
  return result;
}

canonical_original_code:
int hash_insert(void *handle, void *key, void *data)
{
  struct hash_root *root = (hash_root_t*)handle;
  unsigned int hash_index = root->hash_fn(root->bkt_size, key);
  int result;
  if (!root->hash_bkt[hash_index])
  {
     root->hash_bkt[hash_index] = malloc(sizeof(hash_bkt_t));
     if (!root->hash_bkt[hash_index])
       return 0;
     root->hash_bkt[hash_index]->length = 0;
     root->hash_bkt[hash_index]->head = ((void *)0);
  }
  result = INSERT_NODE(root->hash_bkt[hash_index], key, data);
  if (result == 1)
    root->total_elements++;
  return result;
}

variable_types: result int

user_defined_types: struct list_node { struct list_node *next; void *key; void *data; }


original_code:
void* hash_delete(hash_handle_t handle, void *key)
{
  hash_root_t *root = (hash_root_t*)handle;
  unsigned int hash_index = root->hash_fn(root->bkt_size, key);
  list_node_t *node_to_be_del = ((void *)0);
  hash_bkt_t *bkt = root->hash_bkt[hash_index];
  if (bkt == ((void *)0) || bkt->head == ((void *)0))
    return ((void *)0);
  if (root->key_cmp_fn(key, bkt->head->key) ==0)
  {
    node_to_be_del = bkt->head;
    bkt->head = bkt->head->next;
  }
  else
  {
    list_node_t *node = bkt->head;
    while (node->next)
    {
      if (root->key_cmp_fn(key, node->next->key) ==0)
      {
        list_node_t *tmp = node->next;
        node->next = tmp->next;
        node_to_be_del = tmp;
        break;
      }
      node = node->next;
    }
  }
  if (node_to_be_del)
  {
    void *data = node_to_be_del->data;
    free(node_to_be_del);
    bkt->length--;
    return data;
  }
  return ((void *)0);
}

canonical_original_code:
void *hash_delete(void *handle, void *key)
{
  struct hash_root *root = (hash_root_t*)handle;
  unsigned int hash_index = root->hash_fn(root->bkt_size, key);
  struct list_node *node_to_be_del = ((void *)0);
  struct hash_bkt_struct *bkt = root->hash_bkt[hash_index];
  if (bkt == ((void *)0) || bkt->head == ((void *)0))
    return ((void *)0);
  if (root->key_cmp_fn(key, bkt->head->key) ==0)
  {
    node_to_be_del = bkt->head;
    bkt->head = bkt->head->next;
  }
  else
  {
    struct list_node *node = bkt->head;
    while (node->next)
    {
      if (root->key_cmp_fn(key, node->next->key) ==0)
      {
        struct list_node *tmp = node->next;
        node->next = tmp->next;
        node_to_be_del = tmp;
        break;
      }
      node = node->next;
    }
  }
  if (node_to_be_del)
  {
    void *data = node_to_be_del->data;
    free(node_to_be_del);
    bkt->length--;
    return data;
  }
  return ((void *)0);
}

variable_types: struct list_node { struct list_node *next; void *key; void *data; } *

return_type: void *


decompiled_code:
int __fastcall map_print(__int64 a1)
{
unsigned int *v1; // rbp
unsigned int *v2; // rbx
__int64 v3; // rsi
int result; // eax

if ( a1 )
{
v1 = (unsigned int *)(a1 + 4198396);
do
{
v2 = v1 - 0x100000;
do
{
v3 = *v2;
v2 += 1024;
printf("%d", v3);
}
while ( v2 != v1 );
--v1;
result = putchar(10);
}
while ( v1 != (unsigned int *)(a1 + 4194300) );
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1)
{
unsigned int *v1; // rbp
unsigned int *v2; // rbx
__int64 v3; // rsi
int result; // eax

if ( a1 )
{
v1 = (unsigned int *)(a1 + 4198396);
do
{
v2 = v1 - 0x100000;
do
{
v3 = *v2;
v2 += 1024;
printf("%d", v3);
}
while ( v2 != v1 );
--v1;
result = putchar(10);
}
while ( v1 != (unsigned int *)(a1 + 4194300) );
}
return result;
}


decompiled_code:
__int64 __fastcall map_is_block(__int64 a1, unsigned int a2, unsigned int a3)
{
__int64 result; // rax

if ( a2 > 0x3FF || a3 > 0x3FF )
result = 0LL;
else
result = *(unsigned int *)(a1 + 4 * ((int)a3 + ((__int64)(int)a2 << 10)));
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, unsigned int a2, unsigned int a3)
{
__int64 result; // rax

if ( a2 > 0x3FF || a3 > 0x3FF )
result = 0LL;
else
result = *(unsigned int *)(a1 + 4 * ((int)a3 + ((__int64)(int)a2 << 10)));
return result;
}

original_code:
int map_is_block(map_t* map, int x, int y)
{
  if(x < 0 || x >= 1024 || y < 0 || y >= 1024)
    return 0;
  return (*map)[x][y];
}

variable_types: x int

variable_types: y int


decompiled_code:
__int64 __fastcall raycaster_cast_xplanes(float *a1, __int64 *a2, double *a3)
{
float v4; // xmm0_4
int v5; // eax
double v6; // xmm1_8
double v7; // xmm0_8
double v8; // xmm0_8
unsigned int v9; // er12
__int64 v10; // rax
double v12; // [rsp+Ch] [rbp-30h] BYREF
__int64 v13; // [rsp+14h] [rbp-28h] BYREF
__int64 v14[4]; // [rsp+1Ch] [rbp-20h] BYREF

v4 = *a1;
v5 = (int)*a1;
HIDWORD(v6) = 0;
if ( *(float *)a2 < 0.0 )
{
v13 = *a2;
v14[0] = v13;
*(float *)&v6 = (float)((float)v5 - v4) - 0.000099999997;
vec2_scale_x_to(&v13, v6);
*(_QWORD *)&v7 = (unsigned int)LC1;
}
else
{
v13 = *a2;
v14[0] = v13;
*(float *)&v6 = (float)(v5 + 1) - v4;
vec2_scale_x_to(&v13, v6);
*(_QWORD *)&v7 = (unsigned int)LC0;
}
vec2_scale_x_to(v14, v7);
v8 = vec2_add(&v13, a1);
v12 = v8;
if ( *(float *)&v8 >= 0.0 )
{
while ( *(float *)&v8 < 1024.0 )
{
v9 = (int)*((float *)&v12 + 1);
v10 = map_get();
if ( (unsigned int)map_is_block(v10, (unsigned int)(int)*(float *)&v8, v9) )
{
*a3 = v12;
vec2_add(v14, &v12);
return 1LL;
}
v12 = vec2_add(v14, &v12);
LODWORD(v8) = LODWORD(v12);
if ( *(float *)&v12 < 0.0 )
return 0LL;
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(float *a1, __int64 *a2, double *a3)
{
float v4; // xmm0_4
int v5; // eax
double v6; // xmm1_8
double v7; // xmm0_8
double v8; // xmm0_8
unsigned int v9; // er12
__int64 v10; // rax
double v12; // [rsp+Ch] [rbp-30h] BYREF
__int64 v13; // [rsp+14h] [rbp-28h] BYREF
__int64 v14[4]; // [rsp+1Ch] [rbp-20h] BYREF

v4 = *a1;
v5 = (int)*a1;
HIDWORD(v6) = 0;
if ( *(float *)a2 < 0.0 )
{
v13 = *a2;
v14[0] = v13;
*(float *)&v6 = (float)((float)v5 - v4) - 0.000099999997;
vec2_scale_x_to(&v13, v6);
*(_QWORD *)&v7 = (unsigned int)LC1;
}
else
{
v13 = *a2;
v14[0] = v13;
*(float *)&v6 = (float)(v5 + 1) - v4;
vec2_scale_x_to(&v13, v6);
*(_QWORD *)&v7 = (unsigned int)LC0;
}
vec2_scale_x_to(v14, v7);
v8 = vec2_add(&v13, a1);
v12 = v8;
if ( *(float *)&v8 >= 0.0 )
{
while ( *(float *)&v8 < 1024.0 )
{
v9 = (int)*((float *)&v12 + 1);
v10 = map_get();
if ( (unsigned int)map_is_block(v10, (unsigned int)(int)*(float *)&v8, v9) )
{
*a3 = v12;
vec2_add(v14, &v12);
return 1LL;
}
v12 = vec2_add(v14, &v12);
LODWORD(v8) = LODWORD(v12);
if ( *(float *)&v12 < 0.0 )
return 0LL;
}
}
return 0LL;
}

original_code:
static int raycaster_cast_xplanes(const vec2_t* origin,
       const vec2_t* ray,
       vec2_t* intersection)
{
  unsigned char negative;
  vec2_t pt;
  vec2_t starter_offset;
  vec2_t offset;
  vec2_type x_off;
  int intersected;
  intersected = 0;
  if(ray->x < 0.0f)
    negative = 1;
  else
    negative = 0;
  x_off = ((int)origin->x + !negative) - origin->x;
  if(negative)
    x_off -= 0.0001f;
  starter_offset = *ray;
  offset = *ray;
  vec2_scale_x_to(&starter_offset, x_off);
  vec2_scale_x_to(&offset, negative ? -1.0 : 1.0);
  pt = vec2_add(&starter_offset, origin);
  while(!intersected && pt.x >= 0.0 && pt.x < 1024) {
    if(map_is_block(map_get(), (int)pt.x, (int)pt.y)) {
      *intersection = pt;
      intersected = 1;
    }
    pt = vec2_add(&offset, &pt);
  }
  return intersected;
}

canonical_original_code:
static int raycaster_cast_xplanes(struct vec2 *origin, struct vec2 *ray, struct vec2 *intersection)
{
  unsigned char negative;
  struct vec2 pt;
  struct vec2 starter_offset;
  struct vec2 offset;
  float x_off;
  int intersected;
  intersected = 0;
  if(ray->x < 0.0f)
    negative = 1;
  else
    negative = 0;
  x_off = ((int)origin->x + !negative) - origin->x;
  if(negative)
    x_off -= 0.0001f;
  starter_offset = *ray;
  offset = *ray;
  vec2_scale_x_to(&starter_offset, x_off);
  vec2_scale_x_to(&offset, negative ? -1.0 : 1.0);
  pt = vec2_add(&starter_offset, origin);
  while(!intersected && pt.x >= 0.0 && pt.x < 1024) {
    if(map_is_block(map_get(), (int)pt.x, (int)pt.y)) {
      *intersection = pt;
      intersected = 1;
    }
    pt = vec2_add(&offset, &pt);
  }
  return intersected;
}

variable_types:
origin
struct vec2 { float x; float y; } *

variable_types:
ray
struct vec2 *

variable_types:
intersection
struct vec2 *

variable_types:
negative
unsigned char

variable_types:
pt
struct vec2 { float x; float y; }

variable_types:
offset
struct vec2 { float x; float y; }

variable_types: intersected int


original_code:
static int raycaster_cast_yplanes(const vec2_t* origin,
       const vec2_t* ray,
       vec2_t* intersection)
{
  unsigned char negative;
  vec2_t pt;
  vec2_t starter_offset;
  vec2_t offset;
  vec2_type y_off;
  int intersected;
  intersected = 0;
  if(ray->y < 0.0f)
    negative = 1;
  else
    negative = 0;
  y_off = ((int)origin->y + !negative) - origin->y;
  if(negative)
    y_off -= 0.0001f;
  starter_offset = *ray;
  offset = *ray;
  vec2_scale_y_to(&starter_offset, y_off);
  vec2_scale_y_to(&offset, negative ? -1.0 : 1.0);
  pt = vec2_add(&starter_offset, origin);
  while(!intersected && pt.y >= 0.0 && pt.y < 1024) {
    if(map_is_block(map_get(), (int)pt.x, (int)pt.y)) {
      *intersection = pt;
      intersected = 1;
    }
    pt = vec2_add(&offset, &pt);
  }
  return intersected;
}

canonical_original_code:
static int raycaster_cast_yplanes(struct vec2 *origin, struct vec2 *ray, struct vec2 *intersection)
{
  unsigned char negative;
  struct vec2 pt;
  struct vec2 starter_offset;
  struct vec2 offset;
  float y_off;
  int intersected;
  intersected = 0;
  if(ray->y < 0.0f)
    negative = 1;
  else
    negative = 0;
  y_off = ((int)origin->y + !negative) - origin->y;
  if(negative)
    y_off -= 0.0001f;
  starter_offset = *ray;
  offset = *ray;
  vec2_scale_y_to(&starter_offset, y_off);
  vec2_scale_y_to(&offset, negative ? -1.0 : 1.0);
  pt = vec2_add(&starter_offset, origin);
  while(!intersected && pt.y >= 0.0 && pt.y < 1024) {
    if(map_is_block(map_get(), (int)pt.x, (int)pt.y)) {
      *intersection = pt;
      intersected = 1;
    }
    pt = vec2_add(&offset, &pt);
  }
  return intersected;
}


decompiled_code:
float __fastcall vec2_dist_from_cam_2(__int64 a1, __int64 a2)
{
float v2; // xmm0_4
double v4; // [rsp+0h] [rbp-18h] BYREF
double v5[2]; // [rsp+8h] [rbp-10h] BYREF

v4 = vec2_negate(a2);
v5[0] = vec2_add(a1, &v4);
v2 = vec2_dot(v5);
return v2 * v2;
}

canonical_decompiled_code:
float __fastcall func2(__int64 a1, __int64 a2)
{
float v2; // xmm0_4
double v4; // [rsp+0h] [rbp-18h] BYREF
double v5[2]; // [rsp+8h] [rbp-10h] BYREF

v4 = vec2_negate(a2);
v5[0] = vec2_add(a1, &v4);
v2 = vec2_dot(v5);
return v2 * v2;
}

original_code:
static vec2_type vec2_dist_from_cam_2(const vec2_t* test, const vec2_t* cam)
{
  vec2_t neg_cam;
  vec2_t heading;
  vec2_type dot;
  neg_cam = vec2_negate(cam);
  heading = vec2_add(test, &neg_cam);
  dot = vec2_dot(&heading, &heading);
  return pow(dot, 2.0);
}

canonical_original_code:
static float vec2_dist_from_cam_2(struct vec2 *test, struct vec2 *cam)
{
  struct vec2 neg_cam;
  struct vec2 heading;
  float dot;
  neg_cam = vec2_negate(cam);
  heading = vec2_add(test, &neg_cam);
  dot = vec2_dot(&heading, &heading);
  return pow(dot, 2.0);
}

variable_types:
test
struct vec2 { float x; float y; } *

variable_types:
cam
struct vec2 *

variable_types:
heading
struct vec2 { float x; float y; }

variable_types: dot float

return_type: float


decompiled_code:
__int64 __fastcall raycaster_cast(float *a1, __int64 *a2, _QWORD *a3)
{
unsigned int v4; // er12
float v5; // xmm1_4
float v6; // xmm0_4
__int64 v8; // [rsp+10h] [rbp-38h] BYREF
__int64 v9[6]; // [rsp+18h] [rbp-30h] BYREF

v4 = raycaster_cast_xplanes(a1, a2, (double *)&v8);
if ( (unsigned int)raycaster_cast_yplanes((__int64)a1, (__int64)a2, (double *)v9) )
{
v5 = vec2_dist_from_cam_2((__int64)v9, (__int64)a1);
if ( !v4 )
{
LABEL_9:
if ( v5 < 0.0 )
return 0;
goto LABEL_10;
}
}
else
{
v5 = *(float *)&LC1;
if ( !v4 )
return v4;
}
v6 = vec2_dist_from_cam_2((__int64)&v8, (__int64)a1);
if ( v6 < 0.0 )
goto LABEL_9;
if ( v5 < 0.0 || fminf(v6, v5) == v6 )
{
v4 = 1;
*a3 = v8;
return v4;
}
LABEL_10:
*a3 = v9[0];
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(float *a1, __int64 *a2, _QWORD *a3)
{
unsigned int v4; // er12
float v5; // xmm1_4
float v6; // xmm0_4
__int64 v8; // [rsp+10h] [rbp-38h] BYREF
__int64 v9[6]; // [rsp+18h] [rbp-30h] BYREF

v4 = func0(a1, a2, (double *)&v8);
if ( (unsigned int)func1((__int64)a1, (__int64)a2, (double *)v9) )
{
v5 = func2((__int64)v9, (__int64)a1);
if ( !v4 )
{
LABEL_9:
if ( v5 < 0.0 )
return 0;
goto LABEL_10;
}
}
else
{
v5 = *(float *)&LC1;
if ( !v4 )
return v4;
}
v6 = func2((__int64)&v8, (__int64)a1);
if ( v6 < 0.0 )
goto LABEL_9;
if ( v5 < 0.0 || fminf(v6, v5) == v6 )
{
v4 = 1;
*a3 = v8;
return v4;
}
LABEL_10:
*a3 = v9[0];
return 1LL;
}

original_code:
int raycaster_cast(const vec2_t* origin, const vec2_t* ray,
     vec2_t* intersection)
{
  vec2_t intersection_x;
  vec2_t intersection_y;
  vec2_type dist_x, dist_y;
  int ret_val;
  int cast_x, cast_y;
  ret_val = 0;
  dist_x = -1.0;
  dist_y = -1.0;
  cast_x = raycaster_cast_xplanes(origin, ray, &intersection_x);
  cast_y = raycaster_cast_yplanes(origin, ray, &intersection_y);
  if(cast_y)
    dist_y = vec2_dist_from_cam_2(&intersection_y, origin);
  if(cast_x)
    dist_x = vec2_dist_from_cam_2(&intersection_x, origin);
  if(dist_x < 0.0 && dist_y < 0.0) {
    ret_val = 0;
    goto raycaster_cleanup_cast_rays;
  }
  if(dist_x < 0.0) {
    intersection[0] = intersection_y;
    ret_val = 1;
    goto raycaster_cleanup_cast_rays;
  }
  if(dist_y < 0.0) {
    intersection[0] = intersection_x;
    ret_val = 1;
    goto raycaster_cleanup_cast_rays;
  }
  if(((dist_x) < (dist_y) ? (dist_x) : (dist_y)) == dist_x) {
    intersection[0] = intersection_x;
    ret_val = 1;
    goto raycaster_cleanup_cast_rays;
  } else {
    intersection[0] = intersection_y;
    ret_val = 1;
    goto raycaster_cleanup_cast_rays;
  }
 raycaster_cleanup_cast_rays:
  return ret_val;
}

canonical_original_code:
int raycaster_cast(struct vec2 *origin, struct vec2 *ray, struct vec2 *intersection)
{
  struct vec2 intersection_x;
  struct vec2 intersection_y;
  float dist_x; float dist_y;
  int ret_val;
  int cast_x; int cast_y;
  ret_val = 0;
  dist_x = -1.0;
  dist_y = -1.0;
  cast_x = raycaster_cast_xplanes(origin, ray, &intersection_x);
  cast_y = raycaster_cast_yplanes(origin, ray, &intersection_y);
  if(cast_y)
    dist_y = vec2_dist_from_cam_2(&intersection_y, origin);
  if(cast_x)
    dist_x = vec2_dist_from_cam_2(&intersection_x, origin);
  if(dist_x < 0.0 && dist_y < 0.0) {
    ret_val = 0;
    goto raycaster_cleanup_cast_rays;
  }
  if(dist_x < 0.0) {
    intersection[0] = intersection_y;
    ret_val = 1;
    goto raycaster_cleanup_cast_rays;
  }
  if(dist_y < 0.0) {
    intersection[0] = intersection_x;
    ret_val = 1;
    goto raycaster_cleanup_cast_rays;
  }
  if(((dist_x) < (dist_y) ? (dist_x) : (dist_y)) == dist_x) {
    intersection[0] = intersection_x;
    ret_val = 1;
    goto raycaster_cleanup_cast_rays;
  } else {
    intersection[0] = intersection_y;
    ret_val = 1;
    goto raycaster_cleanup_cast_rays;
  }
 raycaster_cleanup_cast_rays:
  return ret_val;
}


original_code:
void raycaster_cast_rays(const vec2_t* origin,
    const vec2_t* ray,
    vec2_type fov,
    vec2_t* intersections,
    size_t count)
{
  vec2_type lower_bound, upper_bound, d_theta;
  vec2_t bad_ray;
  int upper_ind, counter;
  upper_bound = fov * 0.5;
  lower_bound = -upper_bound;
  d_theta = fov / (vec2_type)count;
  bad_ray.x = -1.0;
  bad_ray.y = -1.0;
  upper_ind = (int)((upper_bound - lower_bound) / d_theta);
  for (counter = 0; counter < upper_ind; ++counter) {
    vec2_t current_ray;
    vec2_type theta;
    theta = counter * d_theta + lower_bound;
    memcpy(&current_ray, ray, sizeof(vec2_t));
    vec2_rotate(&current_ray, theta);
    if(!raycaster_cast(origin, &current_ray, intersections + counter))
      *((intersections) + (counter - 1)) = bad_ray;
  }
}

canonical_original_code:
void raycaster_cast_rays(struct vec2 *origin, struct vec2 *ray, float fov, struct vec2 *intersections, unsigned long count)
{
  float lower_bound; float upper_bound; float d_theta;
  struct vec2 bad_ray;
  int upper_ind; int counter;
  upper_bound = fov * 0.5;
  lower_bound = -upper_bound;
  d_theta = fov / (float)count;
  bad_ray.x = -1.0;
  bad_ray.y = -1.0;
  upper_ind = (int)((upper_bound - lower_bound) / d_theta);
  for (counter = 0; counter < upper_ind; ++counter) {
    struct vec2 current_ray;
    float theta;
    theta = counter * d_theta + lower_bound;
    memcpy(&current_ray, ray, sizeof(vec2_t));
    vec2_rotate(&current_ray, theta);
    if(!raycaster_cast(origin, &current_ray, intersections + counter))
      *((intersections) + (counter - 1)) = bad_ray;
  }
}

variable_types: fov float

variable_types:
intersections
struct vec2 *

variable_types:
count
unsigned long

variable_types: counter int

variable_types: theta float


decompiled_code:
int __fastcall time_update(double *a1)
{
int result; // eax
double v2; // xmm1_8
double v3; // xmm2_8
double v4; // xmm0_8
double v5; // xmm0_8
struct timeval v6; // [rsp+0h] [rbp-18h] BYREF

result = gettimeofday(&v6, 0LL);
v2 = a1[1];
v3 = (double)SLODWORD(v6.tv_sec);
v4 = (double)SLODWORD(v6.tv_usec) / 1000000.0;
*a1 = v2;
v5 = v4 + v3;
a1[1] = v5;
a1[2] = v5 - v2;
return result;
}

canonical_decompiled_code:
int __fastcall func0(double *a1)
{
int result; // eax
double v2; // xmm1_8
double v3; // xmm2_8
double v4; // xmm0_8
double v5; // xmm0_8
struct timeval v6; // [rsp+0h] [rbp-18h] BYREF

result = gettimeofday(&v6, 0LL);
v2 = a1[1];
v3 = (double)SLODWORD(v6.tv_sec);
v4 = (double)SLODWORD(v6.tv_usec) / 1000000.0;
*a1 = v2;
v5 = v4 + v3;
a1[1] = v5;
a1[2] = v5 - v2;
return result;
}

original_code:
void time_update(timespan* span)
{
  struct timeval tim;
  gettimeofday(&tim, 0);
  span->last = span->current;
  span->current = (double)tim.tv_sec + (tim.tv_usec / 1000000.0);
  span->elapsed = span->current - span->last;
}

canonical_original_code:
void time_update(struct timespan *span)
{
  struct timeval tim;
  gettimeofday(&tim, 0);
  span->last = span->current;
  span->current = (double)tim.tv_sec + (tim.tv_usec / 1000000.0);
  span->elapsed = span->current - span->last;
}

variable_types: struct timespan { double last; double current; double elapsed; } *

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


decompiled_code:
double __fastcall time_elapsed(__int64 a1)
{
return *(double *)(a1 + 16);
}

canonical_decompiled_code:
double __fastcall func1(__int64 a1)
{
return *(double *)(a1 + 16);
}

original_code:
double time_elapsed(timespan* span)
{
  return span->elapsed;
}

canonical_original_code:
double time_elapsed(struct timespan *span)
{
  return span->elapsed;
}

return_type: double

user_defined_types: struct timespan { double last; double current; double elapsed; }


decompiled_code:
void __fastcall vec2_rotate(float *a1, float a2)
{
float v2; // xmm3_4
float v3; // xmm0_4
float v4; // xmm1_4
float v5; // xmm2_4
float v6; // xmm0_4
double v7; // [rsp+0h] [rbp-18h] BYREF
double sinx[2]; // [rsp+8h] [rbp-10h] BYREF

sincos(a2, sinx, &v7);
v2 = a1[1];
v3 = sinx[0];
v4 = v7;
v5 = (float)(v4 * *a1) - (float)(v3 * v2);
v6 = (float)(v3 * *a1) + (float)(v4 * v2);
*a1 = v5;
a1[1] = v6;
}

canonical_decompiled_code:
void __fastcall func0(float *a1, float a2)
{
float v2; // xmm3_4
float v3; // xmm0_4
float v4; // xmm1_4
float v5; // xmm2_4
float v6; // xmm0_4
double v7; // [rsp+0h] [rbp-18h] BYREF
double sinx[2]; // [rsp+8h] [rbp-10h] BYREF

sincos(a2, sinx, &v7);
v2 = a1[1];
v3 = sinx[0];
v4 = v7;
v5 = (float)(v4 * *a1) - (float)(v3 * v2);
v6 = (float)(v3 * *a1) + (float)(v4 * v2);
*a1 = v5;
a1[1] = v6;
}

original_code:
void vec2_rotate(vec2_t* ray, vec2_type theta)
{
  float x, y, s_t, c_t;
  s_t = sin(theta);
  c_t = cos(theta);
  x = ray->x;
  y = ray->y;
  ray->x = x * c_t - y * s_t;
  ray->y = x * s_t + y * c_t;
}

canonical_original_code:
void vec2_rotate(struct vec2 *ray, float theta)
{
  float x; float y; float s_t; float c_t;
  s_t = sin(theta);
  c_t = cos(theta);
  x = ray->x;
  y = ray->y;
  ray->x = x * c_t - y * s_t;
  ray->y = x * s_t + y * c_t;
}

variable_types:
ray
struct vec2 { float x; float y; } *

variable_types: x float

variable_types: y float


decompiled_code:
float __fastcall vec2_dot(float *a1, float *a2)
{
return (float)(*a1 * *a2) + (float)(a1[1] * a2[1]);
}

canonical_decompiled_code:
float __fastcall func1(float *a1, float *a2)
{
return (float)(*a1 * *a2) + (float)(a1[1] * a2[1]);
}

original_code:
vec2_type vec2_dot(const vec2_t* ray1, const vec2_t* ray2)
{
  vec2_type dot_prod;
  dot_prod = ray1->x * ray2->x + ray1->y * ray2->y;
  return dot_prod;
}

canonical_original_code:
float vec2_dot(struct vec2 *ray1, struct vec2 *ray2)
{
  float dot_prod;
  dot_prod = ray1->x * ray2->x + ray1->y * ray2->y;
  return dot_prod;
}


decompiled_code:
void __fastcall vec2_scale(float *a1, float a2)
{
float v2; // xmm1_4
float v3; // xmm0_4

v2 = *a1 * a2;
v3 = a2 * a1[1];
*a1 = v2;
a1[1] = v3;
}

canonical_decompiled_code:
void __fastcall func2(float *a1, float a2)
{
float v2; // xmm1_4
float v3; // xmm0_4

v2 = *a1 * a2;
v3 = a2 * a1[1];
*a1 = v2;
a1[1] = v3;
}

original_code:
void vec2_scale(vec2_t* ray, vec2_type scale_fact)
{
  ray->x *= scale_fact;
  ray->y *= scale_fact;
}

canonical_original_code:
void vec2_scale(struct vec2 *ray, float scale_fact)
{
  ray->x *= scale_fact;
  ray->y *= scale_fact;
}


decompiled_code:
void __fastcall vec2_normalize(float *a1)
{
float v1; // xmm0_4
double v2; // xmm0_8
double v3; // xmm0_8
float v4; // xmm0_4

v1 = vec2_dot(a1, a1);
v2 = v1 * v1;
if ( v2 < 0.0 )
v3 = sqrt(v2);
else
v3 = sqrt(v2);
v4 = 1.0 / v3;
vec2_scale(a1, v4);
}

canonical_decompiled_code:
void __fastcall func3(float *a1)
{
float v1; // xmm0_4
double v2; // xmm0_8
double v3; // xmm0_8
float v4; // xmm0_4

v1 = func1(a1, a1);
v2 = v1 * v1;
if ( v2 < 0.0 )
v3 = sqrt(v2);
else
v3 = sqrt(v2);
v4 = 1.0 / v3;
func2(a1, v4);
}

original_code:
void vec2_normalize(vec2_t* ray)
{
  vec2_type scale_fact;
  scale_fact = 1.0 / sqrt(pow(vec2_dot(ray, ray),2.0));
  vec2_scale(ray, scale_fact);
}

canonical_original_code:
void vec2_normalize(struct vec2 *ray)
{
  float scale_fact;
  scale_fact = 1.0 / sqrt(pow(vec2_dot(ray, ray),2.0));
  vec2_scale(ray, scale_fact);
}


decompiled_code:
double __fastcall vec2_add(unsigned int *a1, float *a2)
{
__m128i v2; // xmm1
__m128i v3; // xmm0
double result; // xmm0_8

v2 = (__m128i)a1[1];
*(float *)v2.m128i_i32 = *(float *)v2.m128i_i32 + a2[1];
v3 = (__m128i)*a1;
*(float *)v3.m128i_i32 = *(float *)v3.m128i_i32 + *a2;
*(_QWORD *)&result = ((unsigned __int64)(unsigned int)_mm_cvtsi128_si32(v2) << 32) | (unsigned int)_mm_cvtsi128_si32(v3);
return result;
}

canonical_decompiled_code:
double __fastcall func4(unsigned int *a1, float *a2)
{
__m128i v2; // xmm1
__m128i v3; // xmm0
double result; // xmm0_8

v2 = (__m128i)a1[1];
*(float *)v2.m128i_i32 = *(float *)v2.m128i_i32 + a2[1];
v3 = (__m128i)*a1;
*(float *)v3.m128i_i32 = *(float *)v3.m128i_i32 + *a2;
*(_QWORD *)&result = ((unsigned __int64)(unsigned int)_mm_cvtsi128_si32(v2) << 32) | (unsigned int)_mm_cvtsi128_si32(v3);
return result;
}

original_code:
vec2_t vec2_add(const vec2_t* left, const vec2_t* right)
{
  vec2_t ray;
  ray.x = left->x + right->x;
  ray.y = left->y + right->y;
  return ray;
}

canonical_original_code:
struct vec2 vec2_add(struct vec2 *left, struct vec2 *right)
{
  struct vec2 ray;
  ray.x = left->x + right->x;
  ray.y = left->y + right->y;
  return ray;
}

variable_types:
left
struct vec2 *

variable_types:
right
struct vec2 *

variable_types:
ray
struct vec2 { float x; float y; }

return_type: struct vec2 { float x; float y; }


decompiled_code:
double __fastcall vec2_negate(unsigned int *a1)
{
double result; // xmm0_8

*(_QWORD *)&result = ((unsigned __int64)(unsigned int)_mm_cvtsi128_si32((__m128i)_mm_xor_ps(
(__m128)a1[1],
(__m128)(unsigned int)LC2)) << 32) | (unsigned int)_mm_cvtsi128_si32((__m128i)_mm_xor_ps((__m128)*a1, (__m128)(unsigned int)LC2));
return result;
}

canonical_decompiled_code:
double __fastcall func5(unsigned int *a1)
{
double result; // xmm0_8

*(_QWORD *)&result = ((unsigned __int64)(unsigned int)_mm_cvtsi128_si32((__m128i)_mm_xor_ps(
(__m128)a1[1],
(__m128)(unsigned int)LC2)) << 32) | (unsigned int)_mm_cvtsi128_si32((__m128i)_mm_xor_ps((__m128)*a1, (__m128)(unsigned int)LC2));
return result;
}

original_code:
vec2_t vec2_negate(const vec2_t* ray)
{
  vec2_t negation;
  negation.x = -ray->x;
  negation.y = -ray->y;
  return negation;
}

canonical_original_code:
struct vec2 vec2_negate(struct vec2 *ray)
{
  struct vec2 negation;
  negation.x = -ray->x;
  negation.y = -ray->y;
  return negation;
}

variable_types:
ray
struct vec2 *

variable_types:
negation
struct vec2 { float x; float y; }


decompiled_code:
void __fastcall vec2_scale_x_to(float *a1, float a2)
{
vec2_scale(a1, a2 / *a1);
}

canonical_decompiled_code:
void __fastcall func6(float *a1, float a2)
{
func2(a1, a2 / *a1);
}

original_code:
void vec2_scale_x_to(vec2_t* ray, vec2_type target)
{
  vec2_type scale_fact;
  scale_fact = target / ray->x;
  vec2_scale(ray, scale_fact);
}

canonical_original_code:
void vec2_scale_x_to(struct vec2 *ray, float target)
{
  float scale_fact;
  scale_fact = target / ray->x;
  vec2_scale(ray, scale_fact);
}

variable_types: target float


decompiled_code:
void __fastcall vec2_scale_y_to(float *a1, float a2)
{
vec2_scale(a1, a2 / a1[1]);
}

canonical_decompiled_code:
void __fastcall func7(float *a1, float a2)
{
func2(a1, a2 / a1[1]);
}

original_code:
void vec2_scale_y_to(vec2_t* ray, vec2_type target)
{
  vec2_type scale_fact;
  scale_fact = target / ray->y;
  vec2_scale(ray, scale_fact);
}

canonical_original_code:
void vec2_scale_y_to(struct vec2 *ray, float target)
{
  float scale_fact;
  scale_fact = target / ray->y;
  vec2_scale(ray, scale_fact);
}


decompiled_code:
void *texture_name_list_get()
{
return &name_list_0;
}

canonical_decompiled_code:
void *func0()
{
return &name_list_0;
}

original_code:
static texture_name_list_t* texture_name_list_get()
{
  static texture_name_list_t name_list;
  return &name_list;
}

canonical_original_code:
static struct texture_name_list_s *texture_name_list_get()
{
  static struct texture_name_list_s name_list;
  return &name_list;
}

return_type: struct texture_name_list_s { struct texture_name_s { char *name; unsigned char id; } names[255]; unsigned char size; } *

user_defined_types: struct texture_name_list_s { struct texture_name_s names[255]; unsigned char size; }


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

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

original_code:
int texture_cmp_name(const void * a, const void * b)
{
  const texture_name_t * name_a = a;
  const texture_name_t * name_b = b;
  return strcmp(name_a->name, name_b->name);
}

canonical_original_code:
int texture_cmp_name(void *a, void *b)
{
  struct texture_name_s *name_a = a;
  struct texture_name_s *name_b = b;
  return strcmp(name_a->name, name_b->name);
}

variable_types:
a
void *

variable_types:
b
void *

variable_types: struct texture_name_s { char *name; unsigned char id; } *


decompiled_code:
__int64 __fastcall texture_name_locate(const void *a1, _BYTE *a2)
{
unsigned __int8 *v2; // rax
size_t v3; // rcx
__compar_fn_t v4; // r8
_BYTE *v5; // rax
unsigned int v6; // er8

v2 = (unsigned __int8 *)texture_name_list_get();
v5 = bsearch(a1, v2, v2[4080], v3, v4);
v6 = 0;
if ( v5 )
{
v6 = 1;
*a2 = v5[8];
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func2(const void *a1, _BYTE *a2)
{
unsigned __int8 *v2; // rax
size_t v3; // rcx
__compar_fn_t v4; // r8
_BYTE *v5; // rax
unsigned int v6; // er8

v2 = (unsigned __int8 *)func0();
v5 = bsearch(a1, v2, v2[4080], v3, v4);
v6 = 0;
if ( v5 )
{
v6 = 1;
*a2 = v5[8];
}
return v6;
}

original_code:
static int8_t texture_name_locate(const char* name, uint8_t* id)
{
  texture_name_t* element;
  texture_name_list_t* list;
  list = texture_name_list_get();
  element = bsearch(name, list->names, list->size, sizeof(texture_name_t), &texture_cmp_name);
  if(element) {
    *id = element->id;
    return 1;
  } else {
    return 0;
  }
}

canonical_original_code:
static char texture_name_locate(char *name, unsigned char *id)
{
  struct texture_name_s *element;
  struct texture_name_list_s *list;
  list = texture_name_list_get();
  element = bsearch(name, list->names, list->size, sizeof(texture_name_t), &texture_cmp_name);
  if(element) {
    *id = element->id;
    return 1;
  } else {
    return 0;
  }
}

variable_types:
name
char *

variable_types:
id
unsigned char *

variable_types: struct texture_name_list_s { struct texture_name_s { char *name; unsigned char id; } names[255]; unsigned char size; } *

return_type: char


decompiled_code:
void texture_name_add()
{
unsigned __int8 *v0; // rdi
unsigned __int8 *v1; // rax
unsigned __int8 v2; // si
__int64 v3; // rcx
unsigned __int8 v4; // dl

v0 = (unsigned __int8 *)texture_name_list_get();
v1 = &v0[16 * v0[4080]];
v2 = v0[4080] + 1;
*(_QWORD *)v1 = v3;
v0[4080] = v2;
v1[8] = v4;
qsort(v0, v2, 0x10uLL, texture_cmp_name);
}

canonical_decompiled_code:
void func3()
{
unsigned __int8 *v0; // rdi
unsigned __int8 *v1; // rax
unsigned __int8 v2; // si
__int64 v3; // rcx
unsigned __int8 v4; // dl

v0 = (unsigned __int8 *)func0();
v1 = &v0[16 * v0[4080]];
v2 = v0[4080] + 1;
*(_QWORD *)v1 = v3;
v0[4080] = v2;
v1[8] = v4;
qsort(v0, v2, 0x10uLL, texture_cmp_name);
}

original_code:
static void texture_name_add(const char* name, uint8_t id)
{
  texture_name_list_t* list;
  list = texture_name_list_get();
  list->names[list->size].name = name;
  list->names[list->size++].id = id;
  qsort(list, list->size, sizeof(texture_name_t), &texture_cmp_name);
}

canonical_original_code:
static void texture_name_add(char *name, unsigned char id)
{
  struct texture_name_list_s *list;
  list = texture_name_list_get();
  list->names[list->size].name = name;
  list->names[list->size++].id = id;
  qsort(list, list->size, sizeof(texture_name_t), &texture_cmp_name);
}

variable_types:
id
unsigned char

user_defined_types: struct texture_name_s { char *name; unsigned char id; }


decompiled_code:
void __fastcall set_seed(__int64 a1)
{
unseeded = 0;
g_seed = a1;
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1)
{
unseeded = 0;
g_seed = a1;
}

original_code:
static void set_seed(uint64_t input)
{
  unseeded = 0;
  g_seed = input;
}

canonical_original_code:
static void set_seed(unsigned long input)
{
  unseeded = 0;
  g_seed = input;
}

variable_types:
input
unsigned long


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

if ( !unseeded )
return g_seed;
gettimeofday(&v1, 0LL);
unseeded = 0;
result = v1.tv_usec + (v1.tv_sec << 32);
g_seed = result;
return result;
}

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

if ( !unseeded )
return g_seed;
gettimeofday(&v1, 0LL);
unseeded = 0;
result = v1.tv_usec + (v1.tv_sec << 32);
g_seed = result;
return result;
}

original_code:
static uint64_t get_seed()
{
  if(unseeded) {
    struct timeval tim;
    gettimeofday(&tim, 0);
    g_seed = tim.tv_sec;
    g_seed <<= 32;
    g_seed += tim.tv_usec;
    unseeded = 0;
  }
  return g_seed;
}

canonical_original_code:
static unsigned long get_seed()
{
  if(unseeded) {
    struct timeval tim;
    gettimeofday(&tim, 0);
    g_seed = tim.tv_sec;
    g_seed <<= 32;
    g_seed += tim.tv_usec;
    unseeded = 0;
  }
  return g_seed;
}

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

return_type: unsigned long


decompiled_code:
void __fastcall xorshift_srand(__int64 a1)
{
if ( !a1 )
a1 = 1LL;
set_seed(a1);
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1)
{
if ( !a1 )
a1 = 1LL;
func0(a1);
}

original_code:
void xorshift_srand(uint64_t seed)
{
  set_seed(seed ? seed : 1);
}

canonical_original_code:
void xorshift_srand(unsigned long seed)
{
  set_seed(seed ? seed : 1);
}

variable_types:
seed
unsigned long


original_code:
uint64_t xorshift_rand(void)
{
  static const uint16_t a = 21;
  static const uint16_t b = 1;
  static const uint16_t c = 27;
  uint64_t y;
  y = get_seed();
  y ^= y<<a;
  y ^= y>>b;
  y ^= y<<c;
  set_seed(y);
  return y;
}

canonical_original_code:
unsigned long xorshift_rand()
{
  static unsigned short a = 21;
  static unsigned short b = 1;
  static unsigned short c = 27;
  unsigned long y;
  y = get_seed();
  y ^= y<<a;
  y ^= y>>b;
  y ^= y<<c;
  set_seed(y);
  return y;
}

variable_types:
a
unsigned short

variable_types:
b
unsigned short

variable_types:
c
unsigned short

variable_types:
y
unsigned long


original_code:
void enemy_director_add(enemy_director_t* dir, enemy_t* enemy)
{
  long_free_list_t* old_free;
  if(dir->first_free == 0)
    enemy_director_grow(dir);
  old_free = dir->first_free;
  dir->first_free = old_free->next;
  enemy->id = old_free->data;
  enemy->valid = 1;
  memcpy(dir->enemies + old_free->data, enemy, sizeof(enemy_t));
  free(old_free);
}

canonical_original_code:
void enemy_director_add(struct enemy_director_t *dir, struct enemy_t *enemy)
{
  struct long_free_list_t *old_free;
  if(dir->first_free == 0)
    enemy_director_grow(dir);
  old_free = dir->first_free;
  dir->first_free = old_free->next;
  enemy->id = old_free->data;
  enemy->valid = 1;
  memcpy(dir->enemies + old_free->data, enemy, sizeof(enemy_t));
  free(old_free);
}

variable_types: struct enemy_director_t { struct enemy_t { struct vec2 { float x; float y; } position; float width; long id; unsigned char valid; } *enemies; long size; long _max_size; struct long_free_list_t { long data; struct long_free_list_t *next; } *first_free; } *

variable_types:
enemy
struct enemy_t *

user_defined_types: struct enemy_director_t { struct enemy_t *enemies; long size; long _max_size; struct long_free_list_t *first_free; }

user_defined_types: struct enemy_t { struct vec2 position; float width; long id; unsigned char valid; }


decompiled_code:
void __fastcall enemy_director_free(__int64 a1)
{
_QWORD *v2; // rbx
void *v3; // rdi

v2 = *(_QWORD **)(a1 + 24);
while ( v2 )
{
v3 = v2;
v2 = (_QWORD *)v2[1];
free(v3);
}
free(*(void **)a1);
}

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

v2 = *(_QWORD **)(a1 + 24);
while ( v2 )
{
v3 = v2;
v2 = (_QWORD *)v2[1];
free(v3);
}
free(*(void **)a1);
}

original_code:
void enemy_director_free(enemy_director_t* dir)
{
  long_free_list_t* free_list;
  free_list = dir->first_free;
  while(free_list) {
    long_free_list_t* current;
    current = free_list;
    free_list = free_list->next;
    free(current);
  }
  free(dir->enemies);
}

canonical_original_code:
void enemy_director_free(struct enemy_director_t *dir)
{
  struct long_free_list_t *free_list;
  free_list = dir->first_free;
  while(free_list) {
    struct long_free_list_t *current;
    current = free_list;
    free_list = free_list->next;
    free(current);
  }
  free(dir->enemies);
}

variable_types: struct long_free_list_t { long data; struct long_free_list_t *next; } *


decompiled_code:
void *controller_new()
{
return calloc(0x3FCuLL, 1uLL);
}

canonical_decompiled_code:
void *func0()
{
return calloc(0x3FCuLL, 1uLL);
}

original_code:
controller_t* controller_new()
{
  struct controller_s * new_controller = malloc(sizeof(struct controller_s));
  memset(new_controller, 0, sizeof(controller_t));
  return new_controller;
}

canonical_original_code:
struct controller_s *controller_new()
{
  struct controller_s *new_controller = malloc(sizeof(struct controller_s));
  memset(new_controller, 0, sizeof(controller_t));
  return new_controller;
}

variable_types: struct controller_s { int state[-1]; } *


decompiled_code:
__int64 __fastcall controller_is_button_down(__int64 a1, int a2)
{
return *(unsigned int *)(a1 + 4LL * a2);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2)
{
return *(unsigned int *)(a1 + 4LL * a2);
}

original_code:
int controller_is_button_down(controller_t* ctrl, int keysym)
{
  return ctrl->state[keysym];
}

canonical_original_code:
int controller_is_button_down(struct controller_s *ctrl, int keysym)
{
  return ctrl->state[keysym];
}

variable_types: keysym int


decompiled_code:
_BOOL8 __fastcall controller_is_button_up(__int64 a1, int a2)
{
return *(_DWORD *)(a1 + 4LL * a2) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(__int64 a1, int a2)
{
return *(_DWORD *)(a1 + 4LL * a2) == 0;
}

original_code:
int controller_is_button_up(controller_t* ctrl, int keysym)
{
  return !(ctrl->state[keysym]);
}

canonical_original_code:
int controller_is_button_up(struct controller_s *ctrl, int keysym)
{
  return !(ctrl->state[keysym]);
}


decompiled_code:
void __fastcall controller_button_came_up(__int64 a1, int a2)
{
*(_DWORD *)(a1 + 4LL * a2) = 0;
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1, int a2)
{
*(_DWORD *)(a1 + 4LL * a2) = 0;
}

original_code:
void controller_button_came_up(controller_t* ctrl, int keysym)
{
  ctrl->state[keysym] = 0;
}

canonical_original_code:
void controller_button_came_up(struct controller_s *ctrl, int keysym)
{
  ctrl->state[keysym] = 0;
}


decompiled_code:
void __fastcall controller_button_went_down(__int64 a1, int a2)
{
*(_DWORD *)(a1 + 4LL * a2) = 1;
}

canonical_decompiled_code:
void __fastcall func4(__int64 a1, int a2)
{
*(_DWORD *)(a1 + 4LL * a2) = 1;
}

original_code:
void controller_button_went_down(controller_t* ctrl, int keysym)
{
  ctrl->state[keysym] = 1;
}

canonical_original_code:
void controller_button_went_down(struct controller_s *ctrl, int keysym)
{
  ctrl->state[keysym] = 1;
}


decompiled_code:
float __fastcall calculate_fov(float a1, float a2, float a3)
{
float v3; // xmm1_4

v3 = a2 * 0.5 / tan(a3 * 0.5);
return atan2(a1 * 0.5, v3);
}

canonical_decompiled_code:
float __fastcall func0(float a1, float a2, float a3)
{
float v3; // xmm1_4

v3 = a2 * 0.5 / tan(a3 * 0.5);
return atan2(a1 * 0.5, v3);
}

original_code:
vec2_type calculate_fov(vec2_type xres, vec2_type yres, vec2_type vfov)
{
  vec2_type out;
  vec2_type fd;
  fd = yres * 0.5 / tan(vfov * 0.5);
  out = atan2(xres * 0.5, fd);
  return out;
}

canonical_original_code:
float calculate_fov(float xres, float yres, float vfov)
{
  float out;
  float fd;
  fd = yres * 0.5 / tan(vfov * 0.5);
  out = atan2(xres * 0.5, fd);
  return out;
}

variable_types: xres float

variable_types: yres float

variable_types: vfov float

variable_types: out float

variable_types: fd float


decompiled_code:
__int64 __fastcall raycast_scene(__int64 a1, __int64 a2)
{
int v2; // ebx
__int64 v3; // rax
float v4; // xmm0_4

v2 = *(_DWORD *)(framebuffer_get() + 16);
v3 = framebuffer_get();
v4 = calculate_fov((float)v2, (float)*(int *)(v3 + 20), 90.0);
return raycaster_cast_rays(&state, (unsigned int)((_DWORD)&state + 8), a1, a2, v4);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
int v2; // ebx
__int64 v3; // rax
float v4; // xmm0_4

v2 = *(_DWORD *)(framebuffer_get() + 16);
v3 = framebuffer_get();
v4 = func0((float)v2, (float)*(int *)(v3 + 20), 90.0);
return raycaster_cast_rays(&state, (unsigned int)((_DWORD)&state + 8), a1, a2, v4);
}

original_code:
void raycast_scene(vec2_t* hits, const size_t num_hits)
{
  vec2_type theta;
  int width, height;
  width = framebuffer_get()->w;
  height = framebuffer_get()->h;
  theta = calculate_fov(width, height, 90.0);
  raycaster_cast_rays(&state.cam_pos, &state.cam_dir, theta,
        hits, num_hits);
}

canonical_original_code:
void raycast_scene(struct vec2 *hits, unsigned long num_hits)
{
  float theta;
  int width; int height;
  width = framebuffer_get()->w;
  height = framebuffer_get()->h;
  theta = calculate_fov(width, height, 90.0);
  raycaster_cast_rays(&state.cam_pos, &state.cam_dir, theta,
        hits, num_hits);
}

variable_types:
hits
struct vec2 { float x; float y; } *

variable_types: theta float

variable_types: width int

variable_types: height int


decompiled_code:
void __fastcall compute_cam_dists(__int64 a1, __int64 a2, __int64 a3)
{
__int64 i; // rbx
__int64 v6; // rdi
double v7; // [rsp+0h] [rbp-38h] BYREF
double v8[6]; // [rsp+8h] [rbp-30h] BYREF

if ( a2 )
{
for ( i = 0LL; i != a2; ++i )
{
v6 = a1;
a1 += 8LL;
v7 = vec2_negate(&state);
v8[0] = vec2_add(v6, &v7);
vec2_normalize((unsigned int)((_DWORD)&state + 8));
*(float *)(a3 + 4 * i) = vec2_dot((unsigned int)((_DWORD)&state + 8), v8);
}
}
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1, __int64 a2, __int64 a3)
{
__int64 i; // rbx
__int64 v6; // rdi
double v7; // [rsp+0h] [rbp-38h] BYREF
double v8[6]; // [rsp+8h] [rbp-30h] BYREF

if ( a2 )
{
for ( i = 0LL; i != a2; ++i )
{
v6 = a1;
a1 += 8LL;
v7 = vec2_negate(&state);
v8[0] = vec2_add(v6, &v7);
vec2_normalize((unsigned int)((_DWORD)&state + 8));
*(float *)(a3 + 4 * i) = vec2_dot((unsigned int)((_DWORD)&state + 8), v8);
}
}
}

original_code:
void compute_cam_dists(const vec2_t* hits, const size_t num_hits,
         vec2_type* dists)
{
  int i;
  vec2_t negative_origin;
  vec2_t result;
  i = 0;
  for(i = 0; i < num_hits; ++i) {
    vec2_type dist;
    negative_origin = vec2_negate(&state.cam_pos);
    result = vec2_add(&hits[i], &negative_origin);
    vec2_normalize(&state.cam_dir);
    dist = vec2_dot(&state.cam_dir, &result);
    dists[i] = dist;
  }
}

canonical_original_code:
void compute_cam_dists(struct vec2 *hits, unsigned long num_hits, float *dists)
{
  int i;
  struct vec2 negative_origin;
  struct vec2 result;
  i = 0;
  for(i = 0; i < num_hits; ++i) {
    float dist;
    negative_origin = vec2_negate(&state.cam_pos);
    result = vec2_add(&hits[i], &negative_origin);
    vec2_normalize(&state.cam_dir);
    dist = vec2_dot(&state.cam_dir, &result);
    dists[i] = dist;
  }
}

variable_types:
dists
float *

variable_types: i int

variable_types:
result
struct vec2 { float x; float y; }

variable_types: dist float


decompiled_code:
__int64 update_scene()
{
return time_update(&span);
}

canonical_decompiled_code:
__int64 func3()
{
return time_update(&span);
}

original_code:
void update_scene(void)
{
  time_update(&span);
}

canonical_original_code:
void update_scene()
{
  time_update(&span);
}


original_code:
uint32_t make_rgb(float r, float g, float b, SDL_PixelFormat* fmt)
{
  uint32_t color, red, green, blue;
  static const uint32_t white = 0xffffffff;
  red = (white & fmt->Rmask) >> fmt->Rshift;
  green = (white & fmt->Gmask) >> fmt->Gshift;
  blue = (white & fmt->Bmask) >> fmt->Bshift;
  red *= r;
  green *= g;
  blue *= b;
  color = red << fmt->Rshift;
  color += green << fmt->Gshift;
  color += blue << fmt->Bshift;
  return color;
}

canonical_original_code:
unsigned int make_rgb(float r, float g, float b, struct SDL_PixelFormat *fmt)
{
  unsigned int color; unsigned int red; unsigned int green; unsigned int blue;
  static unsigned int white = 0xffffffff;
  red = (white & fmt->Rmask) >> fmt->Rshift;
  green = (white & fmt->Gmask) >> fmt->Gshift;
  blue = (white & fmt->Bmask) >> fmt->Bshift;
  red *= r;
  green *= g;
  blue *= b;
  color = red << fmt->Rshift;
  color += green << fmt->Gshift;
  color += blue << fmt->Bshift;
  return color;
}

variable_types: r float

variable_types: g float

variable_types: b float

variable_types: struct SDL_PixelFormat { struct SDL_Palette { int ncolors; struct SDL_Color { unsigned char r; unsigned char g; unsigned char b; unsigned char unused; } *colors; } *palette; unsigned char BitsPerPixel; unsigned char BytesPerPixel; unsigned char Rloss; unsigned char Gloss; unsigned char Bloss; unsigned char Aloss; unsigned char Rshift; unsigned char Gshift; unsigned char Bshift; unsigned char Ashift; unsigned int Rmask; unsigned int Gmask; unsigned int Bmask; unsigned int Amask; unsigned int colorkey; unsigned char alpha; } *

variable_types:
color
unsigned int

variable_types:
red
unsigned int

variable_types:
green
unsigned int

variable_types:
blue
unsigned int

variable_types:
white
unsigned int

return_type: unsigned int

user_defined_types: struct SDL_PixelFormat { struct SDL_Palette *palette; unsigned char BitsPerPixel; unsigned char BytesPerPixel; unsigned char Rloss; unsigned char Gloss; unsigned char Bloss; unsigned char Aloss; unsigned char Rshift; unsigned char Gshift; unsigned char Bshift; unsigned char Ashift; unsigned int Rmask; unsigned int Gmask; unsigned int Bmask; unsigned int Amask; unsigned int colorkey; unsigned char alpha; }

user_defined_types: struct SDL_Palette { int ncolors; struct SDL_Color *colors; }


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

span[1] = 0LL;
time_update(span);
time_update(span);
state = 0x4060000040600000LL;
result = 3212836864LL;
*(&state + 1) = 3212836864LL;
return result;
}

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

span[1] = 0LL;
time_update(span);
time_update(span);
state = 0x4060000040600000LL;
result = 3212836864LL;
*(&state + 1) = 3212836864LL;
return result;
}

original_code:
void initialize_camera(void)
{
  span.current = 0.0;
  time_update(&span);
  time_update(&span);
  state.cam_pos.x = 3.5;
  state.cam_pos.y = 3.5;
  state.cam_dir.x = -1.0;
  state.cam_dir.y = 0.0;
}

canonical_original_code:
void initialize_camera()
{
  span.current = 0.0;
  time_update(&span);
  time_update(&span);
  state.cam_pos.x = 3.5;
  state.cam_pos.y = 3.5;
  state.cam_dir.x = -1.0;
  state.cam_dir.y = 0.0;
}


decompiled_code:
void __fastcall handle_normal_keys(char a1)
{
if ( a1 == 27 )
exit(0);
}

canonical_decompiled_code:
void __fastcall func1(char a1)
{
if ( a1 == 27 )
exit(0);
}

original_code:
void handle_normal_keys(unsigned char key, int x, int y)
{
  switch(key) {
  case 27:
    exit(0);
    break;
  }
}

variable_types:
key
unsigned char

variable_types: x int

variable_types: y int


decompiled_code:
void *framebuffer_wipe()
{
return memset(
*(void **)(framebuffer + 32),
0,
*(unsigned __int8 *)(*(_QWORD *)(framebuffer + 8) + 9LL)
* *(_DWORD *)(framebuffer + 20)
* *(_DWORD *)(framebuffer + 16));
}

canonical_decompiled_code:
void *func2()
{
return memset(
*(void **)(framebuffer + 32),
0,
*(unsigned __int8 *)(*(_QWORD *)(framebuffer + 8) + 9LL)
* *(_DWORD *)(framebuffer + 20)
* *(_DWORD *)(framebuffer + 16));
}

original_code:
void framebuffer_wipe()
{
  SDL_PixelFormat *fmt;
  fmt = framebuffer->format;
  memset(framebuffer->pixels,
  0, framebuffer->w*framebuffer->h*fmt->BytesPerPixel);
}

canonical_original_code:
void framebuffer_wipe()
{
  struct SDL_PixelFormat *fmt;
  fmt = framebuffer->format;
  memset(framebuffer->pixels,
  0, framebuffer->w*framebuffer->h*fmt->BytesPerPixel);
}

user_defined_types: struct SDL_Color { unsigned char r; unsigned char g; unsigned char b; unsigned char unused; }


repo: saulpw/brainfuck

decompiled_code:
int __fastcall dump_state(int a1)
{
char *v1; // rbx
__int64 v2; // rdx

v1 = &data;
fprintf(stderr, "IP=%d %c DP=%d ", a1, (unsigned int)code[a1], (unsigned int)dp);
do
{
v2 = (unsigned int)*v1++;
fprintf(stderr, "% 3d ", v2);
}
while ( v1 != (char *)&unk_4044EA );
return fputc(10, stderr);
}

canonical_decompiled_code:
int __fastcall func7(int a1)
{
char *v1; // rbx
__int64 v2; // rdx

v1 = &data;
fprintf(stderr, "IP=%d %c DP=%d ", a1, (unsigned int)code[a1], (unsigned int)dp);
do
{
v2 = (unsigned int)*v1++;
fprintf(stderr, "% 3d ", v2);
}
while ( v1 != (char *)&unk_4044EA );
return fputc(10, stderr);
}

original_code:
void dump_state(int ip)
{
    int i;
    fprintf(stderr, "IP=%d %c  DP=%d  ", ip, code[ip], dp);
    for (i=0; i < 10; i++)
        fprintf(stderr, "% 3d ", data[i]);
    fprintf(stderr, "\n");
}

variable_types: ip int


decompiled_code:
int __fastcall out_data(char a1)
{
FILE *v2; // rdi
int result; // eax

v2 = fpgolden;
if ( fpgolden && !verbose || (result = putchar(a1), (v2 = fpgolden) != 0LL) )
{
result = fgetc(v2);
if ( a1 != (_BYTE)result )
result = fprintf(stderr, "Unexpected output '%c' != golden '%c'\n", (unsigned int)a1, (unsigned int)(char)result);
}
return result;
}

canonical_decompiled_code:
int __fastcall func8(char a1)
{
FILE *v2; // rdi
int result; // eax

v2 = fpgolden;
if ( fpgolden && !verbose || (result = putchar(a1), (v2 = fpgolden) != 0LL) )
{
result = fgetc(v2);
if ( a1 != (_BYTE)result )
result = fprintf(stderr, "Unexpected output '%c' != golden '%c'\n", (unsigned int)a1, (unsigned int)(char)result);
}
return result;
}

original_code:
void out_data(char d)
{
    if (fpgolden == ((void *)0) || verbose)
        printf("%c", d);
    if (fpgolden)
    {
        char ch = fgetc(fpgolden);
        if (d != ch)
        {
            fprintf(stderr, "Unexpected output '%c' != golden '%c'\n", d, ch);
        }
    }
}

variable_types: d char

variable_types: ch char


scan

original_code:
int scan(const char *p, int start, int dir, char match, char recurse)
{
    int idx = start;
    int n = 1;
    do {
        if (idx < 0 || idx > ncode) return -2;
        idx += dir;
        if (p[idx] == recurse) ++n;
        else if (p[idx] == match) --n;
    } while (n != 0);
    return idx;
}

canonical_original_code:
int scan(char *p, int start, int dir, char match, char recurse)
{
    int idx = start;
    int n = 1;
    do {
        if (idx < 0 || idx > ncode) return -2;
        idx += dir;
        if (p[idx] == recurse) ++n;
        else if (p[idx] == match) --n;
    } while (n != 0);
    return idx;
}

variable_types:
p
char *

variable_types: start int

variable_types: dir int

variable_types: match char

variable_types: recurse char

variable_types: idx int

variable_types: n int


execute

decompiled_code:
__int64 __fastcall execute(int a1)
{
int v1; // ebp
__int64 v2; // rbx
__int64 result; // rax
__int64 v4; // rdi
char v5; // r8
char v6; // cl

v1 = a1;
if ( a1 >= 0 )
{
while ( 1 )
{
LABEL_2:
if ( ncode < v1 || (unsigned int)dp > 0x7530 )
goto LABEL_18;
v2 = code[v1];
if ( verbose > 2 )
dump_state(v1);
if ( (char)v2 <= 93 )
break;
if ( (_BYTE)v2 == 123 )
{
v5 = 123;
v6 = 125;
opcodes[code[v1 + 1]] = v1 + 2;
LABEL_22:
v1 = scan((__int64)code, v1, 1, v6, v5) + 1;
if ( v1 < 0 )
goto LABEL_18;
}
else
{
if ( (_BYTE)v2 == 125 )
return 1LL;
LABEL_14:
v4 = (unsigned int)opcodes[v2];
if ( (_DWORD)v4 )
{
result = execute(v4);
if ( (int)result <= 0 )
return result;
}
else if ( verbose > 1 )
{
fputc((char)v2, stderr);
}
LABEL_17:
if ( ++v1 < 0 )
goto LABEL_18;
}
}
if ( (char)v2 > 34 )
{
switch ( (char)v2 )
{
case '#':
if ( verbose )
dump_state(v1);
goto LABEL_17;
case '+':
++data[dp];
if ( ++v1 < 0 )
goto LABEL_18;
goto LABEL_2;
case ',':
data[dp] = getc(fpinput);
if ( ++v1 < 0 )
goto LABEL_18;
goto LABEL_2;
case '-':
--data[dp];
if ( ++v1 < 0 )
goto LABEL_18;
goto LABEL_2;
case '.':
out_data(data[dp]);
if ( ++v1 < 0 )
goto LABEL_18;
goto LABEL_2;
case '<':
--dp;
if ( ++v1 < 0 )
goto LABEL_18;
goto LABEL_2;
case '>':
++dp;
if ( ++v1 < 0 )
goto LABEL_18;
goto LABEL_2;
case '[':
v5 = 91;
v6 = 93;
if ( !data[dp] )
goto LABEL_22;
goto LABEL_17;
case ']':
if ( data[dp] )
v1 = scan((__int64)code, v1, -1, 91, 93);
goto LABEL_17;
default:
goto LABEL_14;
}
}
if ( !(_BYTE)v2 )
return 0LL;
goto LABEL_14;
}
LABEL_18:
fwrite("out-of-bounds: ", 1uLL, 0xFuLL, stderr);
dump_state(v1);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func10(int a1)
{
int v1; // ebp
__int64 v2; // rbx
__int64 result; // rax
__int64 v4; // rdi
char v5; // r8
char v6; // cl

v1 = a1;
if ( a1 >= 0 )
{
while ( 1 )
{
LABEL_2:
if ( ncode < v1 || (unsigned int)dp > 0x7530 )
goto LABEL_18;
v2 = code[v1];
if ( verbose > 2 )
func7(v1);
if ( (char)v2 <= 93 )
break;
if ( (_BYTE)v2 == 123 )
{
v5 = 123;
v6 = 125;
opcodes[code[v1 + 1]] = v1 + 2;
LABEL_22:
v1 = func9((__int64)code, v1, 1, v6, v5) + 1;
if ( v1 < 0 )
goto LABEL_18;
}
else
{
if ( (_BYTE)v2 == 125 )
return 1LL;
LABEL_14:
v4 = (unsigned int)opcodes[v2];
if ( (_DWORD)v4 )
{
result = func10(v4);
if ( (int)result <= 0 )
return result;
}
else if ( verbose > 1 )
{
fputc((char)v2, stderr);
}
LABEL_17:
if ( ++v1 < 0 )
goto LABEL_18;
}
}
if ( (char)v2 > 34 )
{
switch ( (char)v2 )
{
case '#':
if ( verbose )
func7(v1);
goto LABEL_17;
case '+':
++data[dp];
if ( ++v1 < 0 )
goto LABEL_18;
goto LABEL_2;
case ',':
data[dp] = getc(fpinput);
if ( ++v1 < 0 )
goto LABEL_18;
goto LABEL_2;
case '-':
--data[dp];
if ( ++v1 < 0 )
goto LABEL_18;
goto LABEL_2;
case '.':
func8(data[dp]);
if ( ++v1 < 0 )
goto LABEL_18;
goto LABEL_2;
case '<':
--dp;
if ( ++v1 < 0 )
goto LABEL_18;
goto LABEL_2;
case '>':
++dp;
if ( ++v1 < 0 )
goto LABEL_18;
goto LABEL_2;
case '[':
v5 = 91;
v6 = 93;
if ( !data[dp] )
goto LABEL_22;
goto LABEL_17;
case ']':
if ( data[dp] )
v1 = func9((__int64)code, v1, -1, 91, 93);
goto LABEL_17;
default:
goto LABEL_14;
}
}
if ( !(_BYTE)v2 )
return 0LL;
goto LABEL_14;
}
LABEL_18:
fwrite("out-of-bounds: ", 1uLL, 0xFuLL, stderr);
func7(v1);
return 0xFFFFFFFFLL;
}

original_code:
int execute(int ip)
{
    while (1) {
        if (ip < 0 || ip > ncode || dp < 0 || dp > sizeof(data))
        {
            fprintf(stderr, "out-of-bounds: ");
            dump_state(ip);
            return -1;
        }
        char op = code[ip];
        if (verbose >= 3) dump_state(ip);
        switch (op)
        {
        case '>': dp += 1; break;
        case '<': dp -= 1; break;
        case '+': data[dp] += 1; break;
        case '-': data[dp] -= 1; break;
        case '.': out_data(data[dp]); break;
        case ',': data[dp] = getc(fpinput); break;
        case '[': if (data[dp] == 0)
                    ip = scan(code, ip, 1, ']', '[');
                  break;
        case ']': if (data[dp] != 0)
                    ip = scan(code, ip, -1, '[', ']');
                  break;
        case 0: return 0;
        case '#': if (verbose) dump_state(ip); break;
        case '{':
                  opcodes[ code[ip+1] ] = ip+2;
                  ip = scan(code, ip, 1, '}', '{');
                  break;
        case '}': return 1;
        default:
                  if (opcodes[op] != 0) {
                    int r = execute(opcodes[op]);
                    if (r <= 0) return r;
                  } else
                  if (verbose >= 2) fprintf(stderr, "%c", op);
                  break;
        };
        ip += 1;
    }
}

variable_types: op char

variable_types: r int


repo: saulrh/Liberty-Daemon

decompiled_code:
void __fastcall fork_sig_handler(int a1)
{
if ( a1 == 10 )
exit(0);
}

canonical_decompiled_code:
void __fastcall func0(int a1)
{
if ( a1 == 10 )
exit(0);
}

original_code:
static void fork_sig_handler(int signum)
{
    switch(signum)
    {
        case 10: exit(0); break;
    }
}

variable_types: signum int


decompiled_code:
void __fastcall daemon_sig_handler(int a1)
{
switch ( a1 )
{
case 2:
case 3:
case 15:
daemon_sig_quit = 1;
break;
case 10:
daemon_sig_usr1 = 1;
break;
case 12:
daemon_sig_usr2 = 1;
break;
case 14:
case 17:
exit(1);
default:
return;
}
}

canonical_decompiled_code:
void __fastcall func1(int a1)
{
switch ( a1 )
{
case 2:
case 3:
case 15:
daemon_sig_quit = 1;
break;
case 10:
daemon_sig_usr1 = 1;
break;
case 12:
daemon_sig_usr2 = 1;
break;
case 14:
case 17:
exit(1);
default:
return;
}
}

original_code:
static void daemon_sig_handler(int signum)
{
    switch(signum)
    {
        case 14: exit(1); break;
        case 10: daemon_sig_usr1 = 1; break;
        case 12: daemon_sig_usr2 = 1; break;
        case 17: exit(1); break;
        case 2:
        case 3:
        case 15: daemon_sig_quit=1; break;
    }
}