lmemcpy

decompiled_code:
void *__fastcall lmemcpy(void *src, size_t n)
{
void *v2; // rax

v2 = (void *)GC_malloc(n);
return memcpy(v2, src, n);
}

canonical_decompiled_code:
void *__fastcall func5(void *src, size_t n)
{
void *v2; // rax

v2 = (void *)GC_malloc(n);
return memcpy(v2, src, n);
}

original_code:
void*
lmemcpy(void* src, size_t n)
{
    void* dest = GC_malloc(n);
    memcpy(dest, src, n);
    return dest;
}

canonical_original_code:
void *lmemcpy(void *src, unsigned long n)
{
    void *dest = GC_malloc(n);
    memcpy(dest, src, n);
    return dest;
}

variable_types:
src
void *

variable_types:
n
unsigned long

variable_types:
dest
void *


lslurp

repo: NatTuck/cakemark

decompiled_code:
__int64 __fastcall lslurp(char *a1)
{
__int64 v2; // [rsp+8h] [rbp-10h] BYREF

return lslurpb(a1, &v2);
}

canonical_decompiled_code:
__int64 __fastcall func8(char *a1)
{
__int64 v2; // [rsp+8h] [rbp-10h] BYREF

return func7(a1, &v2);
}

original_code:
char*
lslurp(const char* filename)
{
    size_t ignored;
    return (char*) lslurpb(filename, &ignored);
}

canonical_original_code:
char *lslurp(char *filename)
{
    unsigned long ignored;
    return (char *) lslurpb(filename, &ignored);
}

variable_types:
filename
char *

variable_types:
ignored
unsigned long

return_type: char *


decompiled_code:
__int64 __fastcall lstrvec_alloc(int a1)
{
__int64 result; // rax
__int64 v2; // r12

result = GC_malloc(16LL);
*(_DWORD *)result = a1;
v2 = result;
if ( a1 )
{
*(_QWORD *)(result + 8) = GC_malloc(8LL * a1);
result = v2;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1)
{
__int64 result; // rax
__int64 v2; // r12

result = GC_malloc(16LL);
*(_DWORD *)result = a1;
v2 = result;
if ( a1 )
{
*(_QWORD *)(result + 8) = GC_malloc(8LL * a1);
result = v2;
}
return result;
}

original_code:
lstrvec*
lstrvec_alloc(int size)
{
    lstrvec* vec = GC_malloc(sizeof(lstrvec));
    vec->size = size;
    if (size != 0)
        vec->xs = GC_malloc(size * sizeof(char*));
    return vec;
}

canonical_original_code:
struct lstrvec *lstrvec_alloc(int size)
{
    struct lstrvec *vec = GC_malloc(sizeof(lstrvec));
    vec->size = size;
    if (size != 0)
        vec->xs = GC_malloc(size * sizeof(char *));
    return vec;
}

variable_types: size int

variable_types: struct lstrvec { int size; char **xs; } *


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

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

original_code:
int
lstrvec_size(lstrvec* vec)
{
    return vec->size;
}

canonical_original_code:
int lstrvec_size(struct lstrvec *vec)
{
    return vec->size;
}

return_type: int


decompiled_code:
__int64 __fastcall lstrvec_get(unsigned int *a1, int a2)
{
__int64 v2; // rcx

v2 = *a1;
if ( a2 < 0 || a2 >= (int)v2 )
{
fprintf(stderr, "lstrvec: Out of bounds get(%d) (size = %d).\n", (unsigned int)a2, v2);
abort();
}
return lstrdup(*(const char **)(*((_QWORD *)a1 + 1) + 8LL * a2));
}

canonical_decompiled_code:
__int64 __fastcall func11(unsigned int *a1, int a2)
{
__int64 v2; // rcx

v2 = *a1;
if ( a2 < 0 || a2 >= (int)v2 )
{
fprintf(stderr, "lstrvec: Out of bounds get(%d) (size = %d).\n", (unsigned int)a2, v2);
abort();
}
return func1(*(const char **)(*((_QWORD *)a1 + 1) + 8LL * a2));
}

original_code:
char*
lstrvec_get(lstrvec* vec, int ii)
{
    if (ii < 0 || ii > vec->size - 1) {
        fprintf(stderr, "lstrvec: Out of bounds get(%d) (size = %d).\n",
                ii, vec->size);
        abort();
    }
    return lstrdup(vec->xs[ii]);
}

canonical_original_code:
char *lstrvec_get(struct lstrvec *vec, int ii)
{
    if (ii < 0 || ii > vec->size - 1) {
        fprintf(stderr, "lstrvec: Out of bounds get(%d) (size = %d).\n",
                ii, vec->size);
        abort();
    }
    return lstrdup(vec->xs[ii]);
}

variable_types: ii int


decompiled_code:
__int64 __fastcall lstrvec_set(unsigned int *a1, int a2, const char *a3)
{
__int64 v3; // rcx
__int64 *v4; // rbx
__int64 result; // rax

v3 = *a1;
if ( a2 < 0 || a2 >= (int)v3 )
{
fprintf(stderr, "lstrvec: Out of bounds get(%d) (size = %d).\n", (unsigned int)a2, v3);
abort();
}
v4 = (__int64 *)(*((_QWORD *)a1 + 1) + 8LL * a2);
result = lstrdup(a3);
*v4 = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(unsigned int *a1, int a2, const char *a3)
{
__int64 v3; // rcx
__int64 *v4; // rbx
__int64 result; // rax

v3 = *a1;
if ( a2 < 0 || a2 >= (int)v3 )
{
fprintf(stderr, "lstrvec: Out of bounds get(%d) (size = %d).\n", (unsigned int)a2, v3);
abort();
}
v4 = (__int64 *)(*((_QWORD *)a1 + 1) + 8LL * a2);
result = func1(a3);
*v4 = result;
return result;
}

original_code:
void
lstrvec_set(lstrvec* vec, int ii, char* vv)
{
    if (ii < 0 || ii > vec->size - 1) {
        fprintf(stderr, "lstrvec: Out of bounds get(%d) (size = %d).\n",
                ii, vec->size);
        abort();
    }
    vec->xs[ii] = lstrdup(vv);
}

canonical_original_code:
void lstrvec_set(struct lstrvec *vec, int ii, char *vv)
{
    if (ii < 0 || ii > vec->size - 1) {
        fprintf(stderr, "lstrvec: Out of bounds get(%d) (size = %d).\n",
                ii, vec->size);
        abort();
    }
    vec->xs[ii] = lstrdup(vv);
}

variable_types:
vv
char *

return_type: void


decompiled_code:
__int64 __fastcall lstrvec_contains(__int64 a1, const char *a2)
{
__int64 v2; // rbx

if ( *(int *)a1 <= 0 )
return 0LL;
v2 = 0LL;
do
{
if ( streq(a2, *(const char **)(*(_QWORD *)(a1 + 8) + 8 * v2)) )
return 1LL;
++v2;
}
while ( *(_DWORD *)a1 > (int)v2 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, const char *a2)
{
__int64 v2; // rbx

if ( *(int *)a1 <= 0 )
return 0LL;
v2 = 0LL;
do
{
if ( func0(a2, *(const char **)(*(_QWORD *)(a1 + 8) + 8 * v2)) )
return 1LL;
++v2;
}
while ( *(_DWORD *)a1 > (int)v2 );
return 0LL;
}

original_code:
int
lstrvec_contains(lstrvec* vec, const char* ss)
{
    int ii;
    for (ii = 0; ii < vec->size; ++ii) {
        if (streq(ss, vec->xs[ii]))
            return 1;
    }
    return 0;
}

canonical_original_code:
int lstrvec_contains(struct lstrvec *vec, char *ss)
{
    int ii;
    for (ii = 0; ii < vec->size; ++ii) {
        if (streq(ss, vec->xs[ii]))
            return 1;
    }
    return 0;
}

variable_types:
ss
char *


lwords

decompiled_code:
unsigned int *__fastcall lwords(const char *a1)
{
const char *v1; // rbx
int v2; // eax
int v3; // er8
int v4; // ebp
int v5; // eax
int v6; // er9
__int64 v7; // rcx
const char *v8; // rcx
const char *v9; // rsi
__int64 v10; // rdx
int v11; // edi
int v12; // edi
int v13; // er12
unsigned int *v14; // r13
const char *v15; // rax

v1 = (const char *)lstrdup(a1);
v2 = strlen(v1);
if ( v2 <= 0 )
{
v12 = 1;
v4 = 0;
goto LABEL_10;
}
v3 = v2;
v4 = 0;
v5 = 0;
v6 = 1;
do
{
while ( 1 )
{
v7 = v5++;
v8 = &v1[v7];
if ( *v8 == 32 )
break;
LABEL_3:
if ( v3 <= v5 )
goto LABEL_9;
}
*v8 = 0;
v9 = &v1[v5];
if ( *v9 != 32 )
{
v4 = v6++;
goto LABEL_3;
}
v10 = 0LL;
do
{
v9[v10] = 0;
v11 = v5 + v10++;
}
while ( v8[v10 + 1] == 32 );
v5 = v11 + 1;
v4 = v6++;
}
while ( v3 > v11 + 1 );
LABEL_9:
v12 = v6;
LABEL_10:
v13 = 0;
v14 = (unsigned int *)lstrvec_alloc(v12);
do
{
v15 = (const char *)lstrdup(v1);
lstrvec_set(v14, v13, v15);
v1 += strlen(v1);
do
++v1;
while ( !*v1 );
++v13;
}
while ( v13 <= v4 );
return v14;
}

canonical_decompiled_code:
unsigned int *__fastcall func14(const char *a1)
{
const char *v1; // rbx
int v2; // eax
int v3; // er8
int v4; // ebp
int v5; // eax
int v6; // er9
__int64 v7; // rcx
const char *v8; // rcx
const char *v9; // rsi
__int64 v10; // rdx
int v11; // edi
int v12; // edi
int v13; // er12
unsigned int *v14; // r13
const char *v15; // rax

v1 = (const char *)func1(a1);
v2 = strlen(v1);
if ( v2 <= 0 )
{
v12 = 1;
v4 = 0;
goto LABEL_10;
}
v3 = v2;
v4 = 0;
v5 = 0;
v6 = 1;
do
{
while ( 1 )
{
v7 = v5++;
v8 = &v1[v7];
if ( *v8 == 32 )
break;
LABEL_3:
if ( v3 <= v5 )
goto LABEL_9;
}
*v8 = 0;
v9 = &v1[v5];
if ( *v9 != 32 )
{
v4 = v6++;
goto LABEL_3;
}
v10 = 0LL;
do
{
v9[v10] = 0;
v11 = v5 + v10++;
}
while ( v8[v10 + 1] == 32 );
v5 = v11 + 1;
v4 = v6++;
}
while ( v3 > v11 + 1 );
LABEL_9:
v12 = v6;
LABEL_10:
v13 = 0;
v14 = (unsigned int *)func9(v12);
do
{
v15 = (const char *)func1(v1);
func12(v14, v13, v15);
v1 += strlen(v1);
do
++v1;
while ( !*v1 );
++v13;
}
while ( v13 <= v4 );
return v14;
}

original_code:
lstrvec*
lwords(const char* ss)
{
    char* aa = lstrdup(ss);
    int ii, jj;
    int nn = strlen(aa);
    int spaces = 0;
    lstrvec* xs;
    for (ii = 0; ii < nn; ++ii) {
        if (aa[ii] == ' ') {
            aa[ii] = '\0';
            spaces += 1;
            while (aa[ii + 1] == ' ') {
                ii += 1;
                aa[ii] = '\0';
            }
        }
    }
    xs = lstrvec_alloc(spaces + 1);
    for (ii = 0; ii < spaces + 1; ++ii) {
        lstrvec_set(xs, ii, lstrdup(aa));
        aa += strlen(aa);
        while(aa[0] == '\0')
            aa += 1;
    }
    return xs;
}

canonical_original_code:
struct lstrvec *lwords(char *ss)
{
    char *aa = lstrdup(ss);
    int ii; int jj;
    int nn = strlen(aa);
    int spaces = 0;
    struct lstrvec *xs;
    for (ii = 0; ii < nn; ++ii) {
        if (aa[ii] == ' ') {
            aa[ii] = '\0';
            spaces += 1;
            while (aa[ii + 1] == ' ') {
                ii += 1;
                aa[ii] = '\0';
            }
        }
    }
    xs = lstrvec_alloc(spaces + 1);
    for (ii = 0; ii < spaces + 1; ++ii) {
        lstrvec_set(xs, ii, lstrdup(aa));
        aa += strlen(aa);
        while(aa[0] == '\0')
            aa += 1;
    }
    return xs;
}

variable_types:
aa
char *

variable_types: jj int

variable_types: nn int

variable_types: spaces int

return_type: struct lstrvec { int size; char **xs; } *


lsplitc

decompiled_code:
unsigned int *__fastcall lsplitc(char a1, const char *a2)
{
const char *v2; // rbx
int v3; // eax
int v4; // edx
int v5; // er12
const char *v6; // rax
__int64 v7; // rdx
int v8; // ebp
unsigned int *v9; // r13
const char *v10; // rax

v2 = (const char *)lstrdup(a2);
v3 = strlen(v2);
if ( v3 <= 0 )
{
v5 = 1;
}
else
{
v4 = v3;
v5 = 1;
v6 = v2;
v7 = (__int64)&v2[v4 - 1 + 1];
do
{
if ( *v6 == a1 )
{
*v6 = 0;
++v5;
}
++v6;
}
while ( v6 != (const char *)v7 );
}
v8 = 0;
v9 = (unsigned int *)lstrvec_alloc(v5);
do
{
v10 = (const char *)lstrdup(v2);
lstrvec_set(v9, v8, v10);
v2 += strlen(v2);
do
++v2;
while ( !*v2 );
++v8;
}
while ( v8 != v5 );
return v9;
}

canonical_decompiled_code:
unsigned int *__fastcall func15(char a1, const char *a2)
{
const char *v2; // rbx
int v3; // eax
int v4; // edx
int v5; // er12
const char *v6; // rax
__int64 v7; // rdx
int v8; // ebp
unsigned int *v9; // r13
const char *v10; // rax

v2 = (const char *)func1(a2);
v3 = strlen(v2);
if ( v3 <= 0 )
{
v5 = 1;
}
else
{
v4 = v3;
v5 = 1;
v6 = v2;
v7 = (__int64)&v2[v4 - 1 + 1];
do
{
if ( *v6 == a1 )
{
*v6 = 0;
++v5;
}
++v6;
}
while ( v6 != (const char *)v7 );
}
v8 = 0;
v9 = (unsigned int *)func9(v5);
do
{
v10 = (const char *)func1(v2);
func12(v9, v8, v10);
v2 += strlen(v2);
do
++v2;
while ( !*v2 );
++v8;
}
while ( v8 != v5 );
return v9;
}

original_code:
lstrvec*
lsplitc(const char cc, const char* ss)
{
    char* aa = lstrdup(ss);
    int ii, jj;
    int nn = strlen(aa);
    int slots = 1;
    lstrvec* xs;
    for (ii = 0; ii < nn; ++ii) {
        if (aa[ii] == cc) {
            aa[ii] = '\0';
            slots += 1;
        }
    }
    xs = lstrvec_alloc(slots);
    for (ii = 0; ii < slots; ++ii) {
        lstrvec_set(xs, ii, lstrdup(aa));
        aa += strlen(aa);
        while(aa[0] == '\0')
            aa += 1;
    }
    return xs;
}

canonical_original_code:
struct lstrvec *lsplitc(char cc, char *ss)
{
    char *aa = lstrdup(ss);
    int ii; int jj;
    int nn = strlen(aa);
    int slots = 1;
    struct lstrvec *xs;
    for (ii = 0; ii < nn; ++ii) {
        if (aa[ii] == cc) {
            aa[ii] = '\0';
            slots += 1;
        }
    }
    xs = lstrvec_alloc(slots);
    for (ii = 0; ii < slots; ++ii) {
        lstrvec_set(xs, ii, lstrdup(aa));
        aa += strlen(aa);
        while(aa[0] == '\0')
            aa += 1;
    }
    return xs;
}

variable_types: cc char

variable_types: slots int


decompiled_code:
__int64 __fastcall mb_iterate(int a1, int a2, int a3, int a4, int a5, float a6, float a7, float a8)
{
__int64 result; // rax
float v9; // xmm6_4
float v10; // xmm5_4
float v11; // xmm0_4
__int128 v12; // xmm3
float v13; // xmm4_4
__int128 v14; // xmm1
float v15; // xmm2_4

result = 0LL;
v9 = (float)((float)((float)((float)((float)a4 / (float)a1) * 3.5) - 2.5) / a8) - a6;
v10 = (float)((float)((float)((float)((float)a3 / (float)a2) + (float)((float)a3 / (float)a2)) - 1.0) / a8) - a7;
if ( a5 > 0 )
{
v11 = 0.0;
LODWORD(v12) = 0;
v13 = 0.0;
v14 = 0LL;
do
{
*(float *)&v14 = *(float *)&v14 + v9;
result = (unsigned int)(result + 1);
v15 = *(float *)&v12 + *(float *)&v12;
v12 = v14;
*(float *)&v12 = *(float *)&v14 - v13;
v14 = v12;
*(float *)&v14 = *(float *)&v12 * *(float *)&v12;
v11 = (float)(v11 * v15) + v10;
v13 = v11 * v11;
}
while ( (float)((float)(*(float *)&v12 * *(float *)&v12) + (float)(v11 * v11)) < 4.0 && a5 > (int)result );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, int a2, int a3, int a4, int a5, float a6, float a7, float a8)
{
__int64 result; // rax
float v9; // xmm6_4
float v10; // xmm5_4
float v11; // xmm0_4
__int128 v12; // xmm3
float v13; // xmm4_4
__int128 v14; // xmm1
float v15; // xmm2_4

result = 0LL;
v9 = (float)((float)((float)((float)((float)a4 / (float)a1) * 3.5) - 2.5) / a8) - a6;
v10 = (float)((float)((float)((float)((float)a3 / (float)a2) + (float)((float)a3 / (float)a2)) - 1.0) / a8) - a7;
if ( a5 > 0 )
{
v11 = 0.0;
LODWORD(v12) = 0;
v13 = 0.0;
v14 = 0LL;
do
{
*(float *)&v14 = *(float *)&v14 + v9;
result = (unsigned int)(result + 1);
v15 = *(float *)&v12 + *(float *)&v12;
v12 = v14;
*(float *)&v12 = *(float *)&v14 - v13;
v14 = v12;
*(float *)&v14 = *(float *)&v12 * *(float *)&v12;
v11 = (float)(v11 * v15) + v10;
v13 = v11 * v11;
}
while ( (float)((float)(*(float *)&v12 * *(float *)&v12) + (float)(v11 * v11)) < 4.0 && a5 > (int)result );
}
return result;
}

original_code:
uint32_t
mb_iterate(int ww, int hh, int ii, int jj, float xc, float yc, float zz, int max)
{
    float x0 = (3.5f * ((float)jj/(float)ww) - 2.5f) / zz - xc;
    float y0 = (2.0f * ((float)ii/(float)hh) - 1.0f) / zz - yc;
    float xx = 0.0f;
    float yy = 0.0f;
    int kk = 0;
    while ((xx * xx + yy * yy < 4.0f) && (kk < max)) {
        float x1 = x0 + xx * xx - yy * yy;
        yy = y0 + 2 * xx * yy;
        xx = x1;
        kk += 1;
    }
    return kk;
}

canonical_original_code:
unsigned int mb_iterate(int ww, int hh, int ii, int jj, float xc, float yc, float zz, int max)
{
    float x0 = (3.5f * ((float)jj/(float)ww) - 2.5f) / zz - xc;
    float y0 = (2.0f * ((float)ii/(float)hh) - 1.0f) / zz - yc;
    float xx = 0.0f;
    float yy = 0.0f;
    int kk = 0;
    while ((xx * xx + yy * yy < 4.0f) && (kk < max)) {
        float x1 = x0 + xx * xx - yy * yy;
        yy = y0 + 2 * xx * yy;
        xx = x1;
        kk += 1;
    }
    return kk;
}

variable_types: ww int

variable_types: hh int

variable_types: xc float

variable_types: yc float

variable_types: zz float

variable_types: max int

variable_types: xx float

variable_types: yy float

variable_types: kk int

return_type: unsigned int


original_code:
void*
mb_job_main(void* info_ptr)
{
    mb_job_info* info = (mb_job_info*)info_ptr;
    for (int ii = info->job; ii < info->hh; ii += 144) {
        for (int jj = 0; jj < info->ww; ++jj) {
            uint32_t iters = mb_iterate(info->ww, info->hh, ii, jj, info->xc,
                    info->yc, info->zz, info->max);
            info->image[ii * info->ww + jj] = iters * (2 << 25) / (info->max + 2);
        }
    }
    return 0;
}

canonical_original_code:
void *mb_job_main(void *info_ptr)
{
    struct mb_job_info *info = (mb_job_info*)info_ptr;
    for (int ii = info->job; ii < info->hh; ii += 144) {
        for (int jj = 0; jj < info->ww; ++jj) {
            unsigned int iters = mb_iterate(info->ww, info->hh, ii, jj, info->xc,
                    info->yc, info->zz, info->max);
            info->image[ii * info->ww + jj] = iters * (2 << 25) / (info->max + 2);
        }
    }
    return 0;
}

variable_types: struct mb_job_info { int job; int ww; int hh; float xc; float yc; float zz; int max; unsigned int *image; } *

variable_types: ii int

variable_types:
iters
unsigned int

return_type: void *


mandelbrot

decompiled_code:
int __fastcall mandelbrot(__int64 a1, int a2, int a3, int a4, float a5, float a6, float a7)
{
int v7; // ebp
pthread_t *v8; // rbx
char *v9; // r15
pthread_t *v10; // r12
int result; // eax
pthread_t newthread[144]; // [rsp+20h] [rbp-1B38h] BYREF
char arg[5816]; // [rsp+4A0h] [rbp-16B8h] BYREF

v7 = 0;
v8 = newthread;
v9 = arg;
v10 = newthread;
printf("mandelbrot at %.04f, %.04f * %.04f\n", a5, a6, a7);
do
{
*(_DWORD *)v9 = v7;
*((_DWORD *)v9 + 2) = a3;
*((_DWORD *)v9 + 1) = a2;
*((_DWORD *)v9 + 6) = a4;
*((_QWORD *)v9 + 4) = a1;
*((float *)v9 + 3) = a5;
*((float *)v9 + 4) = a6;
*((float *)v9 + 5) = a7;
if ( pthread_create(v10, 0LL, mb_job_main, v9) )
_assert_fail("rv == 0", "mandelbrot.c", 0x4Fu, "mandelbrot");
++v7;
v9 += 40;
++v10;
}
while ( v7 != 144 );
do
{
result = pthread_join(*v8, 0LL);
if ( result )
_assert_fail("rv == 0", "mandelbrot.c", 0x54u, "mandelbrot");
++v8;
}
while ( v8 != (pthread_t *)arg );
return result;
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1, int a2, int a3, int a4, float a5, float a6, float a7)
{
int v7; // ebp
pthread_t *v8; // rbx
char *v9; // r15
pthread_t *v10; // r12
int result; // eax
pthread_t newthread[144]; // [rsp+20h] [rbp-1B38h] BYREF
char arg[5816]; // [rsp+4A0h] [rbp-16B8h] BYREF

v7 = 0;
v8 = newthread;
v9 = arg;
v10 = newthread;
printf("mandelbrot at %.04f, %.04f * %.04f\n", a5, a6, a7);
do
{
*(_DWORD *)v9 = v7;
*((_DWORD *)v9 + 2) = a3;
*((_DWORD *)v9 + 1) = a2;
*((_DWORD *)v9 + 6) = a4;
*((_QWORD *)v9 + 4) = a1;
*((float *)v9 + 3) = a5;
*((float *)v9 + 4) = a6;
*((float *)v9 + 5) = a7;
if ( pthread_create(v10, 0LL, mb_job_main, v9) )
_assert_fail("rv == 0", "mandelbrot.c", 0x4Fu, "mandelbrot");
++v7;
v9 += 40;
++v10;
}
while ( v7 != 144 );
do
{
result = pthread_join(*v8, 0LL);
if ( result )
_assert_fail("rv == 0", "mandelbrot.c", 0x54u, "mandelbrot");
++v8;
}
while ( v8 != (pthread_t *)arg );
return result;
}

original_code:
void
mandelbrot(uint32_t* image, int ww, int hh, float xx, float yy, float zz, int max)
{
    pthread_t jobs[144];
    mb_job_info infos[144];
    int rv, ii;
    printf("mandelbrot at %.04f, %.04f * %.04f\n", xx, yy, zz);
    for (ii = 0; ii < 144; ++ii) {
        infos[ii].job = ii;
        infos[ii].ww = ww;
        infos[ii].hh = hh;
        infos[ii].xc = xx;
        infos[ii].yc = yy;
        infos[ii].zz = zz;
        infos[ii].max = max;
        infos[ii].image = image;
        rv = pthread_create(&(jobs[ii]), 0, mb_job_main, &(infos[ii]));
        ((void) sizeof ((rv == 0) ? 1 : 0), __extension__ ({ if (rv == 0) ; else __assert_fail ("rv == 0", "mandelbrot.c", 79, __extension__ __PRETTY_FUNCTION__); }));
    }
    for (ii = 0; ii < 144; ++ii) {
        rv = pthread_join(jobs[ii], 0);
        ((void) sizeof ((rv == 0) ? 1 : 0), __extension__ ({ if (rv == 0) ; else __assert_fail ("rv == 0", "mandelbrot.c", 84, __extension__ __PRETTY_FUNCTION__); }));
    }
}

canonical_original_code:
void mandelbrot(unsigned int *image, int ww, int hh, float xx, float yy, float zz, int max)
{
    unsigned long jobs[144];
    struct mb_job_info infos[144];
    int rv; int ii;
    printf("mandelbrot at %.04f, %.04f * %.04f\n", xx, yy, zz);
    for (ii = 0; ii < 144; ++ii) {
        infos[ii].job = ii;
        infos[ii].ww = ww;
        infos[ii].hh = hh;
        infos[ii].xc = xx;
        infos[ii].yc = yy;
        infos[ii].zz = zz;
        infos[ii].max = max;
        infos[ii].image = image;
        rv = pthread_create(&(jobs[ii]), 0, mb_job_main, &(infos[ii]));
        ((void) sizeof ((rv == 0) ? 1 : 0), __extension__ ({ if (rv == 0) ; else __assert_fail ("rv == 0", "mandelbrot.c", 79, __extension__ __PRETTY_FUNCTION__); }));
    }
    for (ii = 0; ii < 144; ++ii) {
        rv = pthread_join(jobs[ii], 0);
        ((void) sizeof ((rv == 0) ? 1 : 0), __extension__ ({ if (rv == 0) ; else __assert_fail ("rv == 0", "mandelbrot.c", 84, __extension__ __PRETTY_FUNCTION__); }));
    }
}

variable_types:
image
unsigned int *

variable_types:
jobs
unsigned long [144]

variable_types: struct mb_job_info { int job; int ww; int hh; float xc; float yc; float zz; int max; unsigned int *image; } [144]

variable_types: rv int


decompiled_code:
void __fastcall __noreturn cake_carp(const char *a1, unsigned int a2, const char *a3)
{
fprintf(stderr, "\n carp at %s:%d\n%s\n\n", a1, a2, a3);
fflush(stderr);
fflush(stdout);
abort();
}

canonical_decompiled_code:
void __fastcall __noreturn func0(const char *a1, unsigned int a2, const char *a3)
{
fprintf(stderr, "\n carp at %s:%d\n%s\n\n", a1, a2, a3);
fflush(stderr);
fflush(stdout);
abort();
}

original_code:
void
cake_carp(const char* file, int line, const char* msg)
{
    fprintf(stderr, "\n carp at %s:%d\n%s\n\n", file, line, msg);
    fflush(stderr);
    fflush(stdout);
    abort();
}

canonical_original_code:
void cake_carp(char *file, int line, char *msg)
{
    fprintf(stderr, "\n carp at %s:%d\n%s\n\n", file, line, msg);
    fflush(stderr);
    fflush(stdout);
    abort();
}

variable_types:
file
char *

variable_types: line int

variable_types:
msg
char *


memeq

decompiled_code:
_BOOL8 __fastcall memeq(const void *a1, const void *a2, size_t a3)
{
return memcmp(a1, a2, a3) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(const void *a1, const void *a2, size_t a3)
{
return memcmp(a1, a2, a3) == 0;
}

original_code:
int
memeq(const void* aa, const void* bb, size_t nn)
{
    return memcmp(aa, bb, nn) == 0;
}

canonical_original_code:
int memeq(void *aa, void *bb, unsigned long nn)
{
    return memcmp(aa, bb, nn) == 0;
}

variable_types:
aa
void *

variable_types:
bb
void *

variable_types:
nn
unsigned long


decompiled_code:
int __fastcall cake_timer_reset(struct timespec *tp)
{
return clock_gettime(4, tp);
}

canonical_decompiled_code:
int __fastcall func0(struct timespec *tp)
{
return clock_gettime(4, tp);
}

original_code:
inline static
void
cake_timer_reset(cake_timer* tt)
{
    cake_timer_init();
    clock_gettime(4, &(tt->ts));
}

canonical_original_code:
inline static void cake_timer_reset(struct cake_timer *tt)
{
    cake_timer_init();
    clock_gettime(4, &(tt->ts));
}

variable_types: struct cake_timer { struct timespec { long tv_sec; long tv_nsec; } ts; } *

user_defined_types: struct cake_timer { struct timespec ts; }


decompiled_code:
double __fastcall cake_timer_read(_QWORD *a1)
{
double v1; // xmm2_8
struct timespec v3; // [rsp+0h] [rbp-18h] BYREF

clock_gettime(4, &v3);
v1 = cake_timer_ts_to_double_isra_0(*a1, a1[1]);
return cake_timer_ts_to_double_isra_0(v3.tv_sec, v3.tv_nsec) - v1;
}

canonical_decompiled_code:
double __fastcall func2(_QWORD *a1)
{
double v1; // xmm2_8
struct timespec v3; // [rsp+0h] [rbp-18h] BYREF

clock_gettime(4, &v3);
v1 = func1(*a1, a1[1]);
return func1(v3.tv_sec, v3.tv_nsec) - v1;
}

original_code:
inline static
double
cake_timer_read(cake_timer* tt)
{
    struct timespec ts1;
    clock_gettime(4, &ts1);
    double ss0 = cake_timer_ts_to_double(&(tt->ts));
    double ss1 = cake_timer_ts_to_double(&ts1);
    return ss1 - ss0;
}

canonical_original_code:
inline static double cake_timer_read(struct cake_timer *tt)
{
    struct timespec ts1;
    clock_gettime(4, &ts1);
    double ss0 = cake_timer_ts_to_double(&(tt->ts));
    double ss1 = cake_timer_ts_to_double(&ts1);
    return ss1 - ss0;
}

variable_types: struct timespec { long tv_sec; long tv_nsec; }

return_type: double


decompiled_code:
void *alloc_matrix()
{
return calloc(0x80000uLL, 1uLL);
}

canonical_decompiled_code:
void *func4()
{
return calloc(0x80000uLL, 1uLL);
}

original_code:
double*
alloc_matrix()
{
    double* mm = (double*) malloc((256 * 256 * sizeof(double)));
    for (int ii = 0; ii < (256 * 256); ++ii)
        mm[ii] = 0.0;
    return mm;
}

canonical_original_code:
double *alloc_matrix()
{
    double *mm = (double*) malloc((256 * 256 * sizeof(double)));
    for (int ii = 0; ii < (256 * 256); ++ii)
        mm[ii] = 0.0;
    return mm;
}

variable_types:
mm
double *

return_type: double *


decompiled_code:
_QWORD *alloc_identity_matrix()
{
_QWORD *v0; // rax
_QWORD *v1; // r8
_QWORD *v2; // rdx

v0 = alloc_matrix();
v1 = v0;
v2 = v0 + 65792;
do
{
*v0 = LC1;
v0 += 257;
}
while ( v2 != v0 );
return v1;
}

original_code:
double*
alloc_identity_matrix()
{
    double* mm = alloc_matrix();
    for (int ii = 0; ii < 256; ++ii)
        mm[ii * 256 + ii] = 1.0;
    return mm;
}

canonical_original_code:
double *alloc_identity_matrix()
{
    double *mm = alloc_matrix();
    for (int ii = 0; ii < 256; ++ii)
        mm[ii * 256 + ii] = 1.0;
    return mm;
}


decompiled_code:
double *__fastcall alloc_random_matrix(double a1)
{
double *v1; // r12
double *v2; // rbx

v1 = (double *)alloc_matrix();
v2 = v1;
do
{
++v2;
rand48();
*(v2 - 1) = a1;
}
while ( v2 != v1 + 0x10000 );
return v1;
}

canonical_decompiled_code:
double *__fastcall func6(double a1)
{
double *v1; // r12
double *v2; // rbx

v1 = (double *)func4();
v2 = v1;
do
{
++v2;
func3();
*(v2 - 1) = a1;
}
while ( v2 != v1 + 0x10000 );
return v1;
}

original_code:
double*
alloc_random_matrix()
{
    double* mm = alloc_matrix();
    for (int ii = 0; ii < (256 * 256); ++ii)
        mm[ii] = rand48();
    return mm;
}

canonical_original_code:
double *alloc_random_matrix()
{
    double *mm = alloc_matrix();
    for (int ii = 0; ii < (256 * 256); ++ii)
        mm[ii] = rand48();
    return mm;
}


decompiled_code:
__int64 __fastcall matrix_eq(__int64 a1, __int64 a2)
{
__int64 i; // rax
double v3; // xmm0_8
double v4; // xmm1_8

for ( i = 0LL; i != 0x10000; ++i )
{
v3 = *(double *)(a1 + 8 * i);
v4 = *(double *)(a2 + 8 * i);
if ( v3 != v4 )
{
printf("Error at %d: %.02f != %.02f\n", (unsigned int)i, v3, v4);
return 0LL;
}
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2)
{
__int64 i; // rax
double v3; // xmm0_8
double v4; // xmm1_8

for ( i = 0LL; i != 0x10000; ++i )
{
v3 = *(double *)(a1 + 8 * i);
v4 = *(double *)(a2 + 8 * i);
if ( v3 != v4 )
{
printf("Error at %d: %.02f != %.02f\n", (unsigned int)i, v3, v4);
return 0LL;
}
}
return 1LL;
}

original_code:
int
matrix_eq(double* aa, double* bb)
{
    for (int ii = 0; ii < (256 * 256); ++ii) {
        if (aa[ii] != bb[ii]) {
            printf("Error at %d: %.02f != %.02f\n",
                    ii, aa[ii], bb[ii]);
            return 0;
        }
    }
    return 1;
}

canonical_original_code:
int matrix_eq(double *aa, double *bb)
{
    for (int ii = 0; ii < (256 * 256); ++ii) {
        if (aa[ii] != bb[ii]) {
            printf("Error at %d: %.02f != %.02f\n",
                    ii, aa[ii], bb[ii]);
            return 0;
        }
    }
    return 1;
}

variable_types:
aa
double *

variable_types:
bb
double *


decompiled_code:
void rand48()
{
unsigned __int16 v0; // ax

if ( !seeded_1 )
{
v0 = getpid();
seeded_1 = 1;
seed_0[2] = v0;
}
erand48(seed_0);
}

canonical_decompiled_code:
void func3()
{
unsigned __int16 v0; // ax

if ( !seeded_1 )
{
v0 = getpid();
seeded_1 = 1;
seed_0[2] = v0;
}
erand48(seed_0);
}

original_code:
double
rand48()
{
    static unsigned short seed[3] = { 50, 461, 0 };
    static int seeded = 0;
    if (seeded == 0) {
        seed[2] = (short)getpid();
        seeded = 1;
    }
    return (double) erand48(seed);
}

variable_types:
seed
unsigned short [3]

variable_types: seeded int


decompiled_code:
int __fastcall print_matrix(__int64 a1)
{
double *v1; // rbp
double *v2; // rbx
double v3; // xmm0_8

v1 = (double *)(a1 + 2048);
do
{
v2 = v1 - 256;
do
{
v3 = *v2++;
printf("%.02f ", v3);
}
while ( v2 != v1 );
v1 = v2 + 256;
putchar(10);
}
while ( v2 + 256 != (double *)(a1 + 526336) );
return putchar(10);
}

original_code:
void
print_matrix(double* mm)
{
    for (int ii = 0; ii < 256; ++ii) {
        for (int jj = 0; jj < 256; ++jj) {
            printf("%.02f ", mm[ii * 256 + jj]);
        }
        printf("\n");
    }
    printf("\n");
}

canonical_original_code:
void print_matrix(double *mm)
{
    for (int ii = 0; ii < 256; ++ii) {
        for (int jj = 0; jj < 256; ++jj) {
            printf("%.02f ", mm[ii * 256 + jj]);
        }
        printf("\n");
    }
    printf("\n");
}

variable_types: ii int

variable_types: jj int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
double v3; // xmm0_8
unsigned int v4; // er14
char *v5; // rax
double *v6; // r12
_QWORD *v7; // r13
void *v8; // rbp
double v9; // xmm0_8
struct timespec v11[3]; // [rsp+0h] [rbp-38h] BYREF

v4 = 256;
if ( getenv("NUMBER_NOT_USED") )
{
v5 = getenv("NUMBER_NOT_USED");
v4 = atoi(v5);
}
v6 = alloc_random_matrix(v3);
v7 = alloc_identity_matrix();
v8 = alloc_matrix();
cake_timer_reset(v11);
mmul(v8, v7, v6, v4);
v9 = cake_timer_read(v11);
if ( (unsigned int)matrix_eq((__int64)v6, (__int64)v8) )
puts("[cake: OK]\nresult good");
else
puts("result bad =(");
printf("time: %.04f\n", v9);
free(v7);
free(v6);
free(v8);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
double v3; // xmm0_8
unsigned int v4; // er14
char *v5; // rax
double *v6; // r12
_QWORD *v7; // r13
void *v8; // rbp
double v9; // xmm0_8
struct timespec v11[3]; // [rsp+0h] [rbp-38h] BYREF

v4 = 256;
if ( getenv("NUMBER_NOT_USED") )
{
v5 = getenv("NUMBER_NOT_USED");
v4 = atoi(v5);
}
v6 = func6(v3);
v7 = func5();
v8 = func4();
func0(v11);
mmul(v8, v7, v6, v4);
v9 = func2(v11);
if ( (unsigned int)func7((__int64)v6, (__int64)v8) )
puts("[cake: OK]\nresult good");
else
puts("result bad =(");
printf("time: %.04f\n", v9);
free(v7);
free(v6);
free(v8);
return 0;
}

original_code:
int
main(int argc, char* argv[])
{
    int nn = 256;
    if (getenv("NUMBER_NOT_USED"))
        nn = atoi(getenv("NUMBER_NOT_USED"));
    double* aa = alloc_random_matrix();
    double* bb = alloc_identity_matrix();
    double* cc = alloc_matrix();
    cake_timer tm;
    cake_timer_reset(&tm);
    mmul(cc, bb, aa, nn);
    double secs = cake_timer_read(&tm);
    if (matrix_eq(aa, cc))
        printf("[cake: OK]\nresult good\n");
    else
        printf("result bad =(\n");
    printf("time: %.04f\n", secs);
    free(bb);
    free(aa);
    free(cc);
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    int nn = 256;
    if (getenv("NUMBER_NOT_USED"))
        nn = atoi(getenv("NUMBER_NOT_USED"));
    double *aa = alloc_random_matrix();
    double *bb = alloc_identity_matrix();
    double *cc = alloc_matrix();
    struct cake_timer tm;
    cake_timer_reset(&tm);
    mmul(cc, bb, aa, nn);
    double secs = cake_timer_read(&tm);
    if (matrix_eq(aa, cc))
        printf("[cake: OK]\nresult good\n");
    else
        printf("result bad =(\n");
    printf("time: %.04f\n", secs);
    free(bb);
    free(aa);
    free(cc);
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: nn int

variable_types:
cc
double *

variable_types: struct cake_timer { struct timespec { long tv_sec; long tv_nsec; } ts; }

variable_types: secs double


decompiled_code:
__int64 __fastcall cache_get(__int64 a1, __int64 a2)
{
int v2; // ebp
_QWORD *v3; // rbx

if ( !a2 )
cake_carp("file_hash.c", 39LL, "Why are we looking up a size 0 thing?");
v2 = 0;
v3 = cache;
do
{
if ( *v3 == a2 && (unsigned int)memeq(v3[1], a1, a2) )
return cache[3 * v2 + 2];
++v2;
v3 += 3;
}
while ( v2 != 10 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
int v2; // ebp
_QWORD *v3; // rbx

if ( !a2 )
cake_carp("file_hash.c", 39LL, "Why are we looking up a size 0 thing?");
v2 = 0;
v3 = cache;
do
{
if ( *v3 == a2 && (unsigned int)memeq(v3[1], a1, a2) )
return cache[3 * v2 + 2];
++v2;
v3 += 3;
}
while ( v2 != 10 );
return 0LL;
}

original_code:
static
char*
cache_get(const char* data, size_t size)
{
    if (size == 0)
        cake_carp("file_hash.c", 39, ("Why are we looking up a size 0 thing?"));
    for (int ii = 0; ii < 10; ++ii) {
        if (cache[ii].size != size)
            continue;
        if (memeq(cache[ii].data, data, size))
            return cache[ii].hash;
    }
    return 0;
}

canonical_original_code:
static char *cache_get(char *data, unsigned long size)
{
    if (size == 0)
        cake_carp("file_hash.c", 39, ("Why are we looking up a size 0 thing?"));
    for (int ii = 0; ii < 10; ++ii) {
        if (cache[ii].size != size)
            continue;
        if (memeq(cache[ii].data, data, size))
            return cache[ii].hash;
    }
    return 0;
}

variable_types:
data
char *

variable_types:
size
unsigned long


decompiled_code:
__int64 __fastcall cache_put(void *src, size_t n, __int64 a3)
{
int v4; // ebx
size_t *v5; // rbp
void *v6; // rax
__int64 result; // rax

v4 = cache_next;
v5 = &cache[3 * cache_next];
*v5 = n;
v6 = (void *)GC_malloc_atomic(n);
v5[1] = (size_t)v6;
memcpy(v6, src, n);
v5[2] = lstrdup(a3);
result = (unsigned int)((v4 + 1) % 10);
cache_next = (v4 + 1) % 10;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(void *src, size_t n, __int64 a3)
{
int v4; // ebx
size_t *v5; // rbp
void *v6; // rax
__int64 result; // rax

v4 = cache_next;
v5 = &cache[3 * cache_next];
*v5 = n;
v6 = (void *)GC_malloc_atomic(n);
v5[1] = (size_t)v6;
memcpy(v6, src, n);
v5[2] = lstrdup(a3);
result = (unsigned int)((v4 + 1) % 10);
cache_next = (v4 + 1) % 10;
return result;
}

original_code:
static
void
cache_put(const char* data, size_t size, const char* hash)
{
    int nn = cache_next;
    cache[nn].size = size;
    cache[nn].data = GC_malloc_atomic(size);
    memcpy(cache[nn].data, data, size);
    cache[nn].hash = lstrdup(hash);
    cache_next = (nn + 1) % 10;
}

canonical_original_code:
static void cache_put(char *data, unsigned long size, char *hash)
{
    int nn = cache_next;
    cache[nn].size = size;
    cache[nn].data = GC_malloc_atomic(size);
    memcpy(cache[nn].data, data, size);
    cache[nn].hash = lstrdup(hash);
    cache_next = (nn + 1) % 10;
}

variable_types:
hash
char *


streq

decompiled_code:
_BOOL8 __fastcall streq(const char *a1, const char *a2)
{
return strcmp(a1, a2) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(const char *a1, const char *a2)
{
return strcmp(a1, a2) == 0;
}

original_code:
int
streq(const char* aa, const char* bb)
{
    return strcmp(aa, bb) == 0;
}

canonical_original_code:
int streq(char *aa, char *bb)
{
    return strcmp(aa, bb) == 0;
}

variable_types:
aa
char *

variable_types:
bb
char *


carp

decompiled_code:
void __fastcall __noreturn carp(const char *a1)
{
fprintf(stderr, "FATAL: %s\n", a1);
fflush(stderr);
abort();
}

canonical_decompiled_code:
void __fastcall __noreturn func1(const char *a1)
{
fprintf(stderr, "FATAL: %s\n", a1);
fflush(stderr);
abort();
}

original_code:
void
carp(const char* msg)
{
    fprintf(stderr, "FATAL: %s\n", msg);
    fflush(stderr);
    abort();
}

canonical_original_code:
void carp(char *msg)
{
    fprintf(stderr, "FATAL: %s\n", msg);
    fflush(stderr);
    abort();
}

variable_types:
msg
char *


decompiled_code:
void __fastcall free_image(void *ptr)
{
free(*((void **)ptr + 2));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
free(*((void **)ptr + 2));
free(ptr);
}

original_code:
void
free_image(image* im)
{
    free(im->data);
    free(im);
}

canonical_original_code:
void free_image(struct image *im)
{
    free(im->data);
    free(im);
}

variable_types: struct image { unsigned long width; unsigned long height; unsigned char *data; } *


original_code:
void
gaussian_blur(image* im0, int sigma)
{
    ((void) sizeof ((sigma > 0) ? 1 : 0), __extension__ ({ if (sigma > 0) ; else __assert_fail ("sigma > 0", "ref_blur.c", 141, __extension__ __PRETTY_FUNCTION__); }));
    size_t ww = im0->width;
    size_t hh = im0->height;
    int rr = 3 * sigma;
    double bvec[2 * rr + 1];
    double bsum = 0.0;
    for (int kk = -rr; kk <= rr; ++kk) {
        int ii = kk + rr;
        bvec[ii] = gauss(kk, 0.0, sigma);
        bsum += bvec[ii];
    }
    for (int ii = 0; ii < 2 * rr + 1; ++ii) {
        bvec[ii] *= 1.0 / bsum;
    }
    image* im1 = alloc_image(ww, hh);
    for (int ii = 0; ii < hh; ++ii) {
        for (int jj = 0; jj < ww; ++jj) {
            double p1 = 0.0;
            for (int kk = -rr; kk <= rr; ++kk) {
                int jj0 = clamp(jj + kk, 0, ww - 1);
                p1 += bvec[kk + rr] * im0->data[ww*ii + jj0];
            }
            im1->data[ww*ii + jj] = clamp(round(p1), 0, 255);
        }
    }
    for (int jj = 0; jj < ww; ++jj) {
        for (int ii = 0; ii < hh; ++ii) {
            double p0 = 0.0;
            for (int kk = -rr; kk <= rr; ++kk) {
                int ii0 = clamp(ii + kk, 0, hh - 1);
                p0 += bvec[kk + rr] * im1->data[ww*ii0 + jj];
            }
            im0->data[ww*ii + jj] = clamp(round(p0), 0, 255);
        }
    }
    free_image(im1);
}

canonical_original_code:
void gaussian_blur(struct image *im0, int sigma)
{
    ((void) sizeof ((sigma > 0) ? 1 : 0), __extension__ ({ if (sigma > 0) ; else __assert_fail ("sigma > 0", "ref_blur.c", 141, __extension__ __PRETTY_FUNCTION__); }));
    unsigned long ww = im0->width;
    unsigned long hh = im0->height;
    int rr = 3 * sigma;
    double bvec[-1];
    double bsum = 0.0;
    for (int kk = -rr; kk <= rr; ++kk) {
        int ii = kk + rr;
        bvec[ii] = gauss(kk, 0.0, sigma);
        bsum += bvec[ii];
    }
    for (int ii = 0; ii < 2 * rr + 1; ++ii) {
        bvec[ii] *= 1.0 / bsum;
    }
    struct image *im1 = alloc_image(ww, hh);
    for (int ii = 0; ii < hh; ++ii) {
        for (int jj = 0; jj < ww; ++jj) {
            double p1 = 0.0;
            for (int kk = -rr; kk <= rr; ++kk) {
                int jj0 = clamp(jj + kk, 0, ww - 1);
                p1 += bvec[kk + rr] * im0->data[ww*ii + jj0];
            }
            im1->data[ww*ii + jj] = clamp(round(p1), 0, 255);
        }
    }
    for (int jj = 0; jj < ww; ++jj) {
        for (int ii = 0; ii < hh; ++ii) {
            double p0 = 0.0;
            for (int kk = -rr; kk <= rr; ++kk) {
                int ii0 = clamp(ii + kk, 0, hh - 1);
                p0 += bvec[kk + rr] * im1->data[ww*ii0 + jj];
            }
            im0->data[ww*ii + jj] = clamp(round(p0), 0, 255);
        }
    }
    free_image(im1);
}

variable_types: sigma int

variable_types:
ww
unsigned long

variable_types:
hh
unsigned long

variable_types: rr int

variable_types:
bvec
double [-1]

variable_types: bsum double

variable_types: kk int

user_defined_types: struct image { unsigned long width; unsigned long height; unsigned char *data; }


main

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

v3 = read_image(INPUT);
gaussian_blur(v3, 20);
write_image(OUTPUT, v3);
free_image(v3);
return 0;
}

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

v3 = read_image(INPUT);
func6(v3, 20);
func3(OUTPUT, v3);
func2(v3);
return 0;
}

original_code:
int
main(int argc, char* argv[])
{
    image* im = read_image(INPUT);
    gaussian_blur(im, SIGMA);
    write_image(OUTPUT, im);
    free_image(im);
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    struct image *im = read_image(INPUT);
    gaussian_blur(im, SIGMA);
    write_image(OUTPUT, im);
    free_image(im);
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


clUtilErrorString

decompiled_code:
const char *__fastcall clUtilErrorString(int a1)
{
const char *result; // rax

switch ( a1 )
{
case -64:
result = "CL_INVALID_PROPERTY";
break;
case -63:
result = "CL_INVALID_GLOBAL_WORK_SIZE";
break;
case -61:
result = "CL_INVALID_BUFFER_SIZE";
break;
case -59:
result = "CL_INVALID_OPERATION";
break;
case -57:
result = "CL_INVALID_EVENT_WAIT_LIST";
break;
case -56:
result = "CL_INVALID_GLOBAL_OFFSET";
break;
case -55:
result = "CL_INVALID_WORK_ITEM_SIZE";
break;
case -54:
result = "CL_INVALID_WORK_GROUP_SIZE";
break;
case -53:
result = "CL_INVALID_WORK_DIMENSION";
break;
case -52:
result = "CL_INVALID_KERNEL_ARGS";
break;
case -51:
result = "CL_INVALID_ARG_SIZE";
break;
case -50:
result = "CL_INVALID_ARG_VALUE";
break;
case -49:
result = "CL_INVALID_ARG_INDEX";
break;
case -48:
result = "CL_INVALID_KERNEL";
break;
case -47:
result = "CL_INVALID_KERNEL_DEFINITION";
break;
case -46:
result = "CL_INVALID_KERNEL_NAME";
break;
case -45:
result = "CL_INVALID_PROGRAM_EXECUTABLE";
break;
case -44:
result = "CL_INVALID_PROGRAM";
break;
case -41:
result = "CL_INVALID_SAMPLER";
break;
case -40:
result = "CL_INVALID_IMAGE_SIZE";
break;
case -38:
result = "CL_INVALID_MEM_OBJECT";
break;
case -37:
result = "CL_INVALID_HOST_PTR";
break;
case -36:
result = "CL_INVALID_COMMAND_QUEUE";
break;
case -34:
result = "CL_INVALID_CONTEXT";
break;
case -33:
result = "CL_INVALID_DEVICE";
break;
case -32:
result = "CL_INVALID_PLATFORM";
break;
case -31:
result = "CL_INVALID_DEVICE_TYPE";
break;
case -30:
result = "CL_INVALID_VALUE";
break;
case -14:
result = "CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST";
break;
case -13:
result = "CL_MISALIGNED_SUB_BUFFER_OFFSET";
break;
case -6:
result = "CL_OUT_OF_HOST_MEMORY";
break;
case -5:
result = "CL_OUT_OF_RESOURCES";
break;
case -4:
result = "CL_MEM_OBJECT_ALLOCATION_FAILURE";
break;
case -2:
result = "CL_DEVICE_NOT_AVAILABLE";
break;
case -1:
result = "CL_DEVICE_NOT_FOUND";
break;
case 0:
result = "CL_SUCCESS";
break;
default:
return result;
}
return result;
}

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

switch ( a1 )
{
case -64:
result = "CL_INVALID_PROPERTY";
break;
case -63:
result = "CL_INVALID_GLOBAL_WORK_SIZE";
break;
case -61:
result = "CL_INVALID_BUFFER_SIZE";
break;
case -59:
result = "CL_INVALID_OPERATION";
break;
case -57:
result = "CL_INVALID_EVENT_WAIT_LIST";
break;
case -56:
result = "CL_INVALID_GLOBAL_OFFSET";
break;
case -55:
result = "CL_INVALID_WORK_ITEM_SIZE";
break;
case -54:
result = "CL_INVALID_WORK_GROUP_SIZE";
break;
case -53:
result = "CL_INVALID_WORK_DIMENSION";
break;
case -52:
result = "CL_INVALID_KERNEL_ARGS";
break;
case -51:
result = "CL_INVALID_ARG_SIZE";
break;
case -50:
result = "CL_INVALID_ARG_VALUE";
break;
case -49:
result = "CL_INVALID_ARG_INDEX";
break;
case -48:
result = "CL_INVALID_KERNEL";
break;
case -47:
result = "CL_INVALID_KERNEL_DEFINITION";
break;
case -46:
result = "CL_INVALID_KERNEL_NAME";
break;
case -45:
result = "CL_INVALID_PROGRAM_EXECUTABLE";
break;
case -44:
result = "CL_INVALID_PROGRAM";
break;
case -41:
result = "CL_INVALID_SAMPLER";
break;
case -40:
result = "CL_INVALID_IMAGE_SIZE";
break;
case -38:
result = "CL_INVALID_MEM_OBJECT";
break;
case -37:
result = "CL_INVALID_HOST_PTR";
break;
case -36:
result = "CL_INVALID_COMMAND_QUEUE";
break;
case -34:
result = "CL_INVALID_CONTEXT";
break;
case -33:
result = "CL_INVALID_DEVICE";
break;
case -32:
result = "CL_INVALID_PLATFORM";
break;
case -31:
result = "CL_INVALID_DEVICE_TYPE";
break;
case -30:
result = "CL_INVALID_VALUE";
break;
case -14:
result = "CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST";
break;
case -13:
result = "CL_MISALIGNED_SUB_BUFFER_OFFSET";
break;
case -6:
result = "CL_OUT_OF_HOST_MEMORY";
break;
case -5:
result = "CL_OUT_OF_RESOURCES";
break;
case -4:
result = "CL_MEM_OBJECT_ALLOCATION_FAILURE";
break;
case -2:
result = "CL_DEVICE_NOT_AVAILABLE";
break;
case -1:
result = "CL_DEVICE_NOT_FOUND";
break;
case 0:
result = "CL_SUCCESS";
break;
default:
return result;
}
return result;
}

original_code:
const char * clUtilErrorString(cl_int error)
{
   switch(error) {
   case -2: return "CL_DEVICE_NOT_AVAILABLE";;
   case -1: return "CL_DEVICE_NOT_FOUND";;
   case -14: return "CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST";;
   case -49: return "CL_INVALID_ARG_INDEX";;
   case -51: return "CL_INVALID_ARG_SIZE";;
   case -50: return "CL_INVALID_ARG_VALUE";;
   case -61: return "CL_INVALID_BUFFER_SIZE";;
   case -36: return "CL_INVALID_COMMAND_QUEUE";;
   case -34: return "CL_INVALID_CONTEXT";;
   case -33: return "CL_INVALID_DEVICE";;
   case -31: return "CL_INVALID_DEVICE_TYPE";;
   case -57: return "CL_INVALID_EVENT_WAIT_LIST";;
   case -56: return "CL_INVALID_GLOBAL_OFFSET";;
   case -63: return "CL_INVALID_GLOBAL_WORK_SIZE";;
   case -37: return "CL_INVALID_HOST_PTR";;
   case -40: return "CL_INVALID_IMAGE_SIZE";;
   case -48: return "CL_INVALID_KERNEL";;
   case -52: return "CL_INVALID_KERNEL_ARGS";;
   case -47: return "CL_INVALID_KERNEL_DEFINITION";;
   case -46: return "CL_INVALID_KERNEL_NAME";;
   case -38: return "CL_INVALID_MEM_OBJECT";;
   case -59: return "CL_INVALID_OPERATION";;
   case -32: return "CL_INVALID_PLATFORM";;
   case -44: return "CL_INVALID_PROGRAM";;
   case -45: return "CL_INVALID_PROGRAM_EXECUTABLE";;
   case -64: return "CL_INVALID_PROPERTY";;
   case -41: return "CL_INVALID_SAMPLER";;
   case -30: return "CL_INVALID_VALUE";;
   case -53: return "CL_INVALID_WORK_DIMENSION";;
   case -54: return "CL_INVALID_WORK_GROUP_SIZE";;
   case -55: return "CL_INVALID_WORK_ITEM_SIZE";;
   case -4: return "CL_MEM_OBJECT_ALLOCATION_FAILURE";;
   case -13: return "CL_MISALIGNED_SUB_BUFFER_OFFSET";;
   case -6: return "CL_OUT_OF_HOST_MEMORY";;
   case -5: return "CL_OUT_OF_RESOURCES";;
   case 0: return "CL_SUCCESS";;
   }
}

canonical_original_code:
char *clUtilErrorString(int error)
{
   switch(error) {
   case -2: return "CL_DEVICE_NOT_AVAILABLE";;
   case -1: return "CL_DEVICE_NOT_FOUND";;
   case -14: return "CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST";;
   case -49: return "CL_INVALID_ARG_INDEX";;
   case -51: return "CL_INVALID_ARG_SIZE";;
   case -50: return "CL_INVALID_ARG_VALUE";;
   case -61: return "CL_INVALID_BUFFER_SIZE";;
   case -36: return "CL_INVALID_COMMAND_QUEUE";;
   case -34: return "CL_INVALID_CONTEXT";;
   case -33: return "CL_INVALID_DEVICE";;
   case -31: return "CL_INVALID_DEVICE_TYPE";;
   case -57: return "CL_INVALID_EVENT_WAIT_LIST";;
   case -56: return "CL_INVALID_GLOBAL_OFFSET";;
   case -63: return "CL_INVALID_GLOBAL_WORK_SIZE";;
   case -37: return "CL_INVALID_HOST_PTR";;
   case -40: return "CL_INVALID_IMAGE_SIZE";;
   case -48: return "CL_INVALID_KERNEL";;
   case -52: return "CL_INVALID_KERNEL_ARGS";;
   case -47: return "CL_INVALID_KERNEL_DEFINITION";;
   case -46: return "CL_INVALID_KERNEL_NAME";;
   case -38: return "CL_INVALID_MEM_OBJECT";;
   case -59: return "CL_INVALID_OPERATION";;
   case -32: return "CL_INVALID_PLATFORM";;
   case -44: return "CL_INVALID_PROGRAM";;
   case -45: return "CL_INVALID_PROGRAM_EXECUTABLE";;
   case -64: return "CL_INVALID_PROPERTY";;
   case -41: return "CL_INVALID_SAMPLER";;
   case -30: return "CL_INVALID_VALUE";;
   case -53: return "CL_INVALID_WORK_DIMENSION";;
   case -54: return "CL_INVALID_WORK_GROUP_SIZE";;
   case -55: return "CL_INVALID_WORK_ITEM_SIZE";;
   case -4: return "CL_MEM_OBJECT_ALLOCATION_FAILURE";;
   case -13: return "CL_MISALIGNED_SUB_BUFFER_OFFSET";;
   case -6: return "CL_OUT_OF_HOST_MEMORY";;
   case -5: return "CL_OUT_OF_RESOURCES";;
   case 0: return "CL_SUCCESS";;
   }
}

variable_types: error int


decompiled_code:
int __fastcall cl_perror(int a1)
{
const char *v1; // rax

v1 = cl_strerror(a1);
return fprintf(stderr, "OpenCL Error: %s\n", v1);
}

canonical_decompiled_code:
int __fastcall func1(int a1)
{
const char *v1; // rax

v1 = func0(a1);
return fprintf(stderr, "OpenCL Error: %s\n", v1);
}

original_code:
static void
cl_perror(int code)
{
    fprintf(stderr, "OpenCL Error: %s\n", cl_strerror(code));
}

variable_types: code int


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

original_code:
size_t
matrix_size(matrix * mm)
{
    return mm->rows * mm->cols;
}

canonical_original_code:
unsigned long matrix_size(struct matrix *mm)
{
    return mm->rows * mm->cols;
}

variable_types: struct matrix { float *data; unsigned long rows; unsigned long cols; } *

return_type: unsigned long


decompiled_code:
__int64 __fastcall matrix_bytes(__int64 a1)
{
return 4 * matrix_size(a1);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
return 4 * func3(a1);
}

original_code:
size_t
matrix_bytes(matrix * mm)
{
    return matrix_size(mm) * sizeof(float);
}

canonical_original_code:
unsigned long matrix_bytes(struct matrix *mm)
{
    return matrix_size(mm) * sizeof(float);
}

user_defined_types: struct matrix { float *data; unsigned long rows; unsigned long cols; }


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

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

original_code:
void
destroy_matrix(matrix * mm)
{
    free(mm->data);
    free(mm);
}

canonical_original_code:
void destroy_matrix(struct matrix *mm)
{
    free(mm->data);
    free(mm);
}


decompiled_code:
float *__fastcall set_cell(_QWORD *a1, __int64 a2, __int64 a3, float a4)
{
float *result; // rax

result = (float *)(*a1 + 4 * (a2 * a1[2] + a3));
*result = a4;
return result;
}

canonical_decompiled_code:
float *__fastcall func6(_QWORD *a1, __int64 a2, __int64 a3, float a4)
{
float *result; // rax

result = (float *)(*a1 + 4 * (a2 * a1[2] + a3));
*result = a4;
return result;
}

original_code:
void
set_cell(matrix * mm, size_t ii, size_t jj, float value)
{
    mm->data[ii * mm->cols + jj] = value;
}

canonical_original_code:
void set_cell(struct matrix *mm, unsigned long ii, unsigned long jj, float value)
{
    mm->data[ii * mm->cols + jj] = value;
}

variable_types:
ii
unsigned long

variable_types:
jj
unsigned long

variable_types: value float


decompiled_code:
float __fastcall get_cell(_QWORD *a1, __int64 a2, __int64 a3)
{
return *(float *)(*a1 + 4 * (a2 * a1[2] + a3));
}

canonical_decompiled_code:
float __fastcall func7(_QWORD *a1, __int64 a2, __int64 a3)
{
return *(float *)(*a1 + 4 * (a2 * a1[2] + a3));
}

original_code:
float
get_cell(matrix * mm, size_t ii, size_t jj)
{
    return mm->data[ii * mm->cols + jj];
}

canonical_original_code:
float get_cell(struct matrix *mm, unsigned long ii, unsigned long jj)
{
    return mm->data[ii * mm->cols + jj];
}

return_type: float


decompiled_code:
int __fastcall check_result(_QWORD *a1, _QWORD *a2)
{
__m128i v2; // xmm0
__m128i v3; // xmm0
float v5; // [rsp+14h] [rbp-1Ch]
float v6; // [rsp+18h] [rbp-18h]
unsigned __int64 j; // [rsp+20h] [rbp-10h]
unsigned __int64 i; // [rsp+28h] [rbp-8h]

v2 = (__m128i)0x3A83126Fu;
for ( i = 0LL; i < a1[1]; ++i )
{
for ( j = 1LL; j < a1[2]; ++j )
{
*(float *)v2.m128i_i32 = get_cell(a2, i, j);
v6 = COERCE_FLOAT(_mm_cvtsi128_si32(v2));
*(float *)v2.m128i_i32 = get_cell(a1, i, j);
v5 = COERCE_FLOAT(_mm_cvtsi128_si32(v2));
v3 = (__m128i)LODWORD(v6);
*(float *)v3.m128i_i32 = v6 - v5;
v2 = _mm_cvtsi32_si128(_mm_cvtsi128_si32(v3));
std::abs(*(float *)v2.m128i_i32);
if ( COERCE_FLOAT(_mm_cvtsi128_si32(v2)) > 0.001 )
{
puts("ERROR - Incorrect result.");
return printf("At %ld, %ld got %f instead of %f\n", i, j, v5, v6);
}
}
}
puts("Result is correct.");
return puts("[cake: OK]");
}

canonical_decompiled_code:
int __fastcall func9(_QWORD *a1, _QWORD *a2)
{
__m128i v2; // xmm0
__m128i v3; // xmm0
float v5; // [rsp+14h] [rbp-1Ch]
float v6; // [rsp+18h] [rbp-18h]
unsigned __int64 j; // [rsp+20h] [rbp-10h]
unsigned __int64 i; // [rsp+28h] [rbp-8h]

v2 = (__m128i)0x3A83126Fu;
for ( i = 0LL; i < a1[1]; ++i )
{
for ( j = 1LL; j < a1[2]; ++j )
{
*(float *)v2.m128i_i32 = func7(a2, i, j);
v6 = COERCE_FLOAT(_mm_cvtsi128_si32(v2));
*(float *)v2.m128i_i32 = func7(a1, i, j);
v5 = COERCE_FLOAT(_mm_cvtsi128_si32(v2));
v3 = (__m128i)LODWORD(v6);
*(float *)v3.m128i_i32 = v6 - v5;
v2 = _mm_cvtsi32_si128(_mm_cvtsi128_si32(v3));
std::func11(*(float *)v2.m128i_i32);
if ( COERCE_FLOAT(_mm_cvtsi128_si32(v2)) > 0.001 )
{
puts("ERROR - Incorrect result.");
return printf("At %ld, %ld got %f instead of %f\n", i, j, v5, v6);
}
}
}
puts("Result is correct.");
return puts("[cake: OK]");
}

original_code:
void
check_result(matrix * cc, matrix * aa)
{
    const float EPS = 0.001;
    for (size_t ii = 0; ii < cc->rows; ++ii) {
        for (size_t jj = 1; jj < cc->cols; ++jj) {
            float xx = get_cell(aa, ii, jj);
            float yy = get_cell(cc, ii, jj);
            if (abs(1*xx - yy) > EPS) {
                printf("ERROR - Incorrect result.\n");
                printf("At %ld, %ld got %f instead of %f\n",
                       ii, jj, yy, xx);
                return;
            }
        }
    }
    printf("Result is correct.\n");
    printf("[cake: OK]\n");
}

canonical_original_code:
void check_result(struct matrix *cc, struct matrix *aa)
{
    float EPS = 0.001;
    for (unsigned long ii = 0; ii < cc->rows; ++ii) {
        for (unsigned long jj = 1; jj < cc->cols; ++jj) {
            float xx = get_cell(aa, ii, jj);
            float yy = get_cell(cc, ii, jj);
            if (abs(1*xx - yy) > EPS) {
                printf("ERROR - Incorrect result.\n");
                printf("At %ld, %ld got %f instead of %f\n",
                       ii, jj, yy, xx);
                return;
            }
        }
    }
    printf("Result is correct.\n");
    printf("[cake: OK]\n");
}

variable_types:
aa
struct matrix *

variable_types: EPS float

variable_types: xx float

variable_types: yy float


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


canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
return 4 * func1(a1);
}


decompiled_code:
void __fastcall destroy_matrix(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func4(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}


decompiled_code:
__int64 __fastcall set_cell(__int64 *a1, __int64 a2, __int64 a3, float a4)
{
__int64 result; // rax

result = *a1;
*(float *)(*a1 + 4 * (a3 + a1[2] * a2)) = a4;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 *a1, __int64 a2, __int64 a3, float a4)
{
__int64 result; // rax

result = *a1;
*(float *)(*a1 + 4 * (a3 + a1[2] * a2)) = a4;
return result;
}


decompiled_code:
float __fastcall get_cell(_QWORD *a1, __int64 a2, __int64 a3)
{
return *(float *)(*a1 + 4 * (a3 + a1[2] * a2));
}

canonical_decompiled_code:
float __fastcall func6(_QWORD *a1, __int64 a2, __int64 a3)
{
return *(float *)(*a1 + 4 * (a3 + a1[2] * a2));
}


decompiled_code:
int __fastcall check_result(__int64 a1, _QWORD *a2, __m128i a3)
{
__int64 v3; // r10
unsigned __int64 v4; // r9
__int64 v6; // rbp
__int64 v7; // r12
float v8; // ebx
__int64 v9; // rdx
_QWORD *v10; // rcx
float v11; // xmm0_4
int result; // eax

v3 = *(_QWORD *)(a1 + 8);
if ( v3 )
{
v4 = *(_QWORD *)(a1 + 16);
v6 = 0LL;
while ( 1 )
{
v7 = 1LL;
if ( v4 > 1 )
break;
LABEL_8:
if ( v3 == ++v6 )
goto LABEL_9;
}
while ( 1 )
{
*(float *)a3.m128i_i32 = get_cell(a2, v6, v7);
v8 = COERCE_FLOAT(_mm_cvtsi128_si32(a3));
v11 = get_cell(v10, v6, v9);
if ( (float)(int)abs32((int)(float)(v8 - v11)) > 0.001 )
break;
if ( ++v7 == v4 )
goto LABEL_8;
}
puts("ERROR - Incorrect result.");
result = printf("At %ld, %ld got %f instead of %f\n", v6, v7, v11, v8);
}
else
{
LABEL_9:
puts("Result is correct.");
result = puts("[cake: OK]");
}
return result;
}

canonical_decompiled_code:
int __fastcall func8(__int64 a1, _QWORD *a2, __m128i a3)
{
__int64 v3; // r10
unsigned __int64 v4; // r9
__int64 v6; // rbp
__int64 v7; // r12
float v8; // ebx
__int64 v9; // rdx
_QWORD *v10; // rcx
float v11; // xmm0_4
int result; // eax

v3 = *(_QWORD *)(a1 + 8);
if ( v3 )
{
v4 = *(_QWORD *)(a1 + 16);
v6 = 0LL;
while ( 1 )
{
v7 = 1LL;
if ( v4 > 1 )
break;
LABEL_8:
if ( v3 == ++v6 )
goto LABEL_9;
}
while ( 1 )
{
*(float *)a3.m128i_i32 = func6(a2, v6, v7);
v8 = COERCE_FLOAT(_mm_cvtsi128_si32(a3));
v11 = func6(v10, v6, v9);
if ( (float)(int)abs32((int)(float)(v8 - v11)) > 0.001 )
break;
if ( ++v7 == v4 )
goto LABEL_8;
}
puts("ERROR - Incorrect result.");
result = printf("At %ld, %ld got %f instead of %f\n", v6, v7, v11, v8);
}
else
{
LABEL_9:
puts("Result is correct.");
result = puts("[cake: OK]");
}
return result;
}


decompiled_code:
int __fastcall timer_reset(struct timeval *a1)
{
return gettimeofday(a1, 0LL);
}

canonical_decompiled_code:
int __fastcall func0(struct timeval *a1)
{
return gettimeofday(a1, 0LL);
}

original_code:
void
timer_reset(timer* tt)
{
    struct timeval* tv = (struct timeval*)tt;
    gettimeofday(tv, 0);
}

canonical_original_code:
void timer_reset(struct timeval *tt)
{
    struct timeval *tv = (struct timeval*)tt;
    gettimeofday(tv, 0);
}

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


decompiled_code:
struct timeval *timer_alloc()
{
struct timeval *v0; // r12

v0 = (struct timeval *)malloc(0x10uLL);
timer_reset(v0);
return v0;
}

canonical_decompiled_code:
struct timeval *func1()
{
struct timeval *v0; // r12

v0 = (struct timeval *)malloc(0x10uLL);
func0(v0);
return v0;
}

original_code:
timer*
timer_alloc()
{
    timer* tt = (timer*) malloc(sizeof(timer));
    timer_reset(tt);
    return tt;
}

canonical_original_code:
struct timeval *timer_alloc()
{
    struct timeval *tt = (timer*) malloc(sizeof(timer));
    timer_reset(tt);
    return tt;
}

return_type: struct timeval { long tv_sec; long tv_usec; } *


decompiled_code:
double __fastcall timer_read(_QWORD *a1)
{
struct timeval v2; // [rsp+0h] [rbp-30h] BYREF

gettimeofday(&v2, 0LL);
return (double)SLODWORD(v2.tv_usec) / 1000000.0
+ (double)SLODWORD(v2.tv_sec)
- ((double)(int)a1[1] / 1000000.0
+ (double)(int)*a1);
}

canonical_decompiled_code:
double __fastcall func2(_QWORD *a1)
{
struct timeval v2; // [rsp+0h] [rbp-30h] BYREF

gettimeofday(&v2, 0LL);
return (double)SLODWORD(v2.tv_usec) / 1000000.0
+ (double)SLODWORD(v2.tv_sec)
- ((double)(int)a1[1] / 1000000.0
+ (double)(int)*a1);
}

original_code:
double
timer_read(timer* tt)
{
    const double MM = 1000000.0;
    struct timeval* tv0 = (struct timeval*)tt;
    struct timeval* tv1 = (struct timeval*)__builtin_alloca (sizeof(struct timeval));
    gettimeofday(tv1, 0);
    double s0 = tv0->tv_sec + ((double)tv0->tv_usec) / MM;
    double s1 = tv1->tv_sec + ((double)tv1->tv_usec) / MM;
    return s1 - s0;
}

canonical_original_code:
double timer_read(struct timeval *tt)
{
    double MM = 1000000.0;
    struct timeval *tv0 = (struct timeval*)tt;
    struct timeval *tv1 = (struct timeval*)__builtin_alloca (sizeof(struct timeval));
    gettimeofday(tv1, 0);
    double s0 = tv0->tv_sec + ((double)tv0->tv_usec) / MM;
    double s1 = tv1->tv_sec + ((double)tv1->tv_usec) / MM;
    return s1 - s0;
}

variable_types: MM double

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


decompiled_code:
// attributes: thunk
void timer_free(void *ptr)
{
free(ptr);
}

canonical_decompiled_code:
void func3(void *ptr)
{
free(ptr);
}

original_code:
void
timer_free(timer* tt)
{
    free(tt);
}

canonical_original_code:
void timer_free(struct timeval *tt)
{
    free(tt);
}


decompiled_code:
timeval *timer_alloc(void)
{
timeval *v1; // [rsp+8h] [rbp-8h]

v1 = (timeval *)malloc(0x10uLL);
timer_reset(v1);
return v1;
}

canonical_decompiled_code:
timeval *func0(void)
{
timeval *v1; // [rsp+8h] [rbp-8h]

v1 = (timeval *)malloc(0x10uLL);
func1(v1);
return v1;
}


decompiled_code:
int __fastcall timer_reset(timeval *a1)
{
return gettimeofday(a1, 0LL);
}

canonical_decompiled_code:
int __fastcall func1(timeval *a1)
{
return gettimeofday(a1, 0LL);
}


decompiled_code:
double __fastcall timer_read(timeval *a1)
{
void *v1; // rsp
__int64 v3; // [rsp+8h] [rbp-38h] BYREF
double v4; // [rsp+20h] [rbp-20h]
struct timeval *tv; // [rsp+28h] [rbp-18h]
timeval *v6; // [rsp+30h] [rbp-10h]
__int64 v7; // [rsp+38h] [rbp-8h]

HIBYTE(v3) = HIBYTE(a1);
v7 = 0x412E848000000000LL;
v6 = a1;
v1 = alloca(32LL);
tv = (struct timeval *)(16 * (((unsigned __int64)&v3 + 7) >> 4));
gettimeofday(tv, 0LL);
v4 = (double)(int)v6->tv_usec / 1000000.0 + (double)(int)v6->tv_sec;
return (double)(int)tv->tv_usec / 1000000.0 + (double)(int)tv->tv_sec - v4;
}

canonical_decompiled_code:
double __fastcall func2(timeval *a1)
{
void *v1; // rsp
__int64 v3; // [rsp+8h] [rbp-38h] BYREF
double v4; // [rsp+20h] [rbp-20h]
struct timeval *tv; // [rsp+28h] [rbp-18h]
timeval *v6; // [rsp+30h] [rbp-10h]
__int64 v7; // [rsp+38h] [rbp-8h]

HIBYTE(v3) = HIBYTE(a1);
v7 = 0x412E848000000000LL;
v6 = a1;
v1 = alloca(32LL);
tv = (struct timeval *)(16 * (((unsigned __int64)&v3 + 7) >> 4));
gettimeofday(tv, 0LL);
v4 = (double)(int)v6->tv_usec / 1000000.0 + (double)(int)v6->tv_sec;
return (double)(int)tv->tv_usec / 1000000.0 + (double)(int)tv->tv_sec - v4;
}


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

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


streq

decompiled_code:
_BOOL8 __fastcall streq(const char *a1, const char *a2)
{
return strcmp(a1, a2) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(const char *a1, const char *a2)
{
return strcmp(a1, a2) == 0;
}

original_code:
int
streq(const char* aa, const char* bb)
{
    return strcmp(aa, bb) == 0;
}

variable_types:
aa
char *

variable_types:
bb
char *


carp

decompiled_code:
void __fastcall __noreturn carp(const char *a1)
{
fprintf(stderr, "FATAL: %s\n", a1);
fflush(stderr);
abort();
}

canonical_decompiled_code:
void __fastcall __noreturn func1(const char *a1)
{
fprintf(stderr, "FATAL: %s\n", a1);
fflush(stderr);
abort();
}

original_code:
void
carp(const char* msg)
{
    fprintf(stderr, "FATAL: %s\n", msg);
    fflush(stderr);
    abort();
}

variable_types:
msg
char *


decompiled_code:
void __fastcall free_image(void *ptr)
{
free(*((void **)ptr + 2));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
free(*((void **)ptr + 2));
free(ptr);
}

original_code:
void
free_image(image* im)
{
    free(im->data);
    free(im);
}

variable_types: struct image { unsigned long width; unsigned long height; unsigned char *data; } *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbp
const char *v4; // rax
__int64 *v5; // r12

v3 = pclu_create_context(argc, argv, envp);
v4 = (const char *)pclu_context_info(v3);
printf("\n%s\n", v4);
v5 = read_image(INPUT);
cl_gaussian_blur(v3, v5, 20);
write_image(OUTPUT, v5);
free_image(v5);
pclu_destroy_context(v3);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbp
const char *v4; // rax
__int64 *v5; // r12

v3 = pclu_create_context(argc, argv, envp);
v4 = (const char *)pclu_context_info(v3);
printf("\n%s\n", v4);
v5 = read_image(INPUT);
func6(v3, v5, 20);
func3(OUTPUT, v5);
func2(v5);
pclu_destroy_context(v3);
return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rbx
__int64 v4; // r12
const char *v5; // rax
__int64 v6; // rsi
_BYTE v8[256]; // [rsp+0h] [rbp-118h] BYREF
char v9; // [rsp+100h] [rbp-18h] BYREF

v3 = v8;
v4 = pclu_create_context(argc, argv, envp);
v5 = (const char *)pclu_context_info(v4);
printf("\n%s\n", v5);
cl_get_ids(v4, (__int64)v8);
do
{
v6 = *(unsigned int *)v3;
v3 += 4;
printf("%d ", v6);
}
while ( v3 != &v9 );
putchar(10);
pclu_destroy_context(v4);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rbx
__int64 v4; // r12
const char *v5; // rax
__int64 v6; // rsi
_BYTE v8[256]; // [rsp+0h] [rbp-118h] BYREF
char v9; // [rsp+100h] [rbp-18h] BYREF

v3 = v8;
v4 = pclu_create_context(argc, argv, envp);
v5 = (const char *)pclu_context_info(v4);
printf("\n%s\n", v5);
func2(v4, (__int64)v8);
do
{
v6 = *(unsigned int *)v3;
v3 += 4;
printf("%d ", v6);
}
while ( v3 != &v9 );
putchar(10);
pclu_destroy_context(v4);
return 0;
}


decompiled_code:
int __fastcall cl_perror(int a1)
{
__int64 v1; // rdi
const char *v2; // rdx

v1 = (unsigned int)(a1 + 72);
v2 = "UNKNOWN_ERROR";
if ( (unsigned int)v1 <= 0x49 )
v2 = CSWTCH_130[v1];
return fprintf(stderr, "OpenCL Error: %s\n", v2);
}

canonical_decompiled_code:
int __fastcall func0(int a1)
{
__int64 v1; // rdi
const char *v2; // rdx

v1 = (unsigned int)(a1 + 72);
v2 = "UNKNOWN_ERROR";
if ( (unsigned int)v1 <= 0x49 )
v2 = CSWTCH_130[v1];
return fprintf(stderr, "OpenCL Error: %s\n", v2);
}

canonical_original_code:
static void cl_perror(int code)
{
    fprintf(stderr, "OpenCL Error: %s\n", cl_strerror(code));
}

variable_types: code int


exists

repo: NatTuck/libdrip

decompiled_code:
_BOOL8 __fastcall exists(const char *a1)
{
int v1; // er8
_BOOL8 result; // rax
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

v1 = lstat(a1, &v3);
result = 1LL;
if ( v1 == -1 )
result = *_errno_location() != 2;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(const char *a1)
{
int v1; // er8
_BOOL8 result; // rax
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

v1 = lstat(a1, &v3);
result = 1LL;
if ( v1 == -1 )
result = *_errno_location() != 2;
return result;
}

original_code:
static
int
exists(const char* filename)
{
    struct stat info;
    int rv = lstat(filename, &info);
    if (rv == -1 && (*__errno_location ()) == 2)
        return 0;
    else
        return 1;
}

canonical_original_code:
static int exists(char *filename)
{
    struct stat info;
    int rv = lstat(filename, &info);
    if (rv == -1 && (*__errno_location ()) == 2)
        return 0;
    else
        return 1;
}

variable_types:
filename
char *

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

variable_types: rv int

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


lslurp

decompiled_code:
__int64 __fastcall lslurp(char *a1)
{
__int64 v2; // [rsp+8h] [rbp-10h] BYREF

return lslurpb(a1, &v2);
}

canonical_decompiled_code:
__int64 __fastcall func3(char *a1)
{
__int64 v2; // [rsp+8h] [rbp-10h] BYREF

return func2(a1, &v2);
}

original_code:
char*
lslurp(const char* filename)
{
    size_t ignored;
    return (char*) lslurpb(filename, &ignored);
}

canonical_original_code:
char *lslurp(char *filename)
{
    unsigned long ignored;
    return (char *) lslurpb(filename, &ignored);
}

variable_types:
ignored
unsigned long


ldump

decompiled_code:
int __fastcall ldump(const char *a1, const char *a2)
{
size_t v2; // rax

v2 = strlen(a2);
return ldumpb(a1, a2, v2);
}

canonical_decompiled_code:
int __fastcall func5(const char *a1, const char *a2)
{
size_t v2; // rax

v2 = strlen(a2);
return func4(a1, a2, v2);
}

original_code:
void
ldump(const char* filename, const char* text)
{
    ldumpb(filename, (void*) text, strlen(text));
}

canonical_original_code:
void ldump(char *filename, char *text)
{
    ldumpb(filename, (void *) text, strlen(text));
}

variable_types:
text
char *


ltempname

decompiled_code:
const char *__fastcall ltempname(const char *a1)
{
__int64 v1; // rbx
const char *v2; // r13

v1 = getpid();
do
{
v1 = (17 * v1 + 5) % 0x10000;
v2 = (const char *)lsprintf("/tmp/%s-%04lx", a1, v1);
}
while ( exists(v2) );
return v2;
}

canonical_decompiled_code:
const char *__fastcall func6(const char *a1)
{
__int64 v1; // rbx
const char *v2; // r13

v1 = getpid();
do
{
v1 = (17 * v1 + 5) % 0x10000;
v2 = (const char *)lsprintf("/tmp/%s-%04lx", a1, v1);
}
while ( func0(v2) );
return v2;
}

original_code:
char*
ltempname(const char* prefix)
{
    struct stat info;
    char* name;
    long nn = (long) getpid();
    do {
        nn = (nn * 17 + 5) % 0x10000;
        name = lsprintf("/tmp/%s-%04lx", prefix, nn);
    } while(exists(name));
    return name;
}

canonical_original_code:
char *ltempname(char *prefix)
{
    struct stat info;
    char *name;
    long nn = (long) getpid();
    do {
        nn = (nn * 17 + 5) % 0x10000;
        name = lsprintf("/tmp/%s-%04lx", prefix, nn);
    } while(exists(name));
    return name;
}

variable_types:
prefix
char *

variable_types:
name
char *

variable_types: nn long

user_defined_types: struct timespec { long tv_sec; long tv_nsec; }


lshell

decompiled_code:
__int64 __fastcall lshell(const char *a1)
{
char *v1; // rbp
const char *v2; // rax
int v3; // eax
__int64 v4; // r12

v1 = (char *)ltempname("lshell");
v2 = (const char *)lsprintf("(%s) > %s", a1, v1);
v3 = system(v2);
if ( BYTE1(v3) )
{
fprintf(stderr, "lshell(%s) exited with status %d", a1, BYTE1(v3));
fflush(stderr);
abort();
}
v4 = lslurp(v1);
unlink(v1);
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func7(const char *a1)
{
char *v1; // rbp
const char *v2; // rax
int v3; // eax
__int64 v4; // r12

v1 = (char *)func6("lshell");
v2 = (const char *)lsprintf("(%s) > %s", a1, v1);
v3 = system(v2);
if ( BYTE1(v3) )
{
fprintf(stderr, "lshell(%s) exited with status %d", a1, BYTE1(v3));
fflush(stderr);
abort();
}
v4 = func3(v1);
unlink(v1);
return v4;
}

original_code:
char*
lshell(const char* cmd)
{
    char* filename = ltempname("lshell");
    char* full_cmd = lsprintf("(%s) > %s", cmd, filename);
    int rv = system(full_cmd);
    if ((((rv) & 0xff00) >> 8) != 0) {
        fprintf(stderr, "lshell(%s) exited with status %d", cmd, (((rv) & 0xff00) >> 8));
        fflush(stderr);
        abort();
    }
    char* output = lslurp(filename);
    unlink(filename);
    return output;
}

canonical_original_code:
char *lshell(char *cmd)
{
    char *filename = ltempname("lshell");
    char *full_cmd = lsprintf("(%s) > %s", cmd, filename);
    int rv = system(full_cmd);
    if ((((rv) & 0xff00) >> 8) != 0) {
        fprintf(stderr, "lshell(%s) exited with status %d", cmd, (((rv) & 0xff00) >> 8));
        fflush(stderr);
        abort();
    }
    char *output = lslurp(filename);
    unlink(filename);
    return output;
}

variable_types:
cmd
char *

variable_types:
output
char *


streq

canonical_original_code:
int streq(char *aa, char *bb)
{
    return strcmp(aa, bb) == 0;
}

variable_types:
aa
char *


lstrdup

decompiled_code:
__int64 __fastcall lstrdup(const char *a1)
{
size_t v1; // r13
__int64 v2; // r12

v1 = strlen(a1) + 1;
v2 = GC_malloc_atomic(v1);
strlcpy(v2, a1, v1);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1)
{
size_t v1; // r13
__int64 v2; // r12

v1 = strlen(a1) + 1;
v2 = GC_malloc_atomic(v1);
strlcpy(v2, a1, v1);
return v2;
}

original_code:
char*
lstrdup(const char* aa)
{
    size_t size = strlen(aa) + 1;
    char* bb = (char*) GC_malloc_atomic(size);
    strlcpy(bb, aa, size);
    return bb;
}

canonical_original_code:
char *lstrdup(char *aa)
{
    unsigned long size = strlen(aa) + 1;
    char *bb = (char*) GC_malloc_atomic(size);
    strlcpy(bb, aa, size);
    return bb;
}

variable_types:
size
unsigned long

variable_types:
bb
char *


lsprintf

decompiled_code:
char *lsprintf(char *format, ...)
{
size_t v1; // rbp
char *v2; // r12
gcc_va_list va; // [rsp+0h] [rbp-108h] BYREF
__m128i arg; // [rsp+18h] [rbp-F0h] BYREF
void *v6; // [rsp+28h] [rbp-E0h]

va_start(va, format);
arg = _mm_loadu_si128((const __m128i *)va);
v6 = va[0].reg_save_area;
v1 = vsnprintf(0LL, 0LL, format, va) + 1;
v2 = (char *)GC_malloc_atomic(v1);
vsnprintf(v2, v1, format, &arg);
return v2;
}

canonical_decompiled_code:
char *func2(char *format, ...)
{
size_t v1; // rbp
char *v2; // r12
gcc_va_list va; // [rsp+0h] [rbp-108h] BYREF
__m128i arg; // [rsp+18h] [rbp-F0h] BYREF
void *v6; // [rsp+28h] [rbp-E0h]

va_start(va, format);
arg = _mm_loadu_si128((const __m128i *)va);
v6 = va[0].reg_save_area;
v1 = vsnprintf(0LL, 0LL, format, va) + 1;
v2 = (char *)GC_malloc_atomic(v1);
vsnprintf(v2, v1, format, &arg);
return v2;
}

original_code:
char*
lsprintf(const char* fmt, ...)
{
    va_list ap1;
    va_list ap2;
    __builtin_va_start(ap1,fmt);
    __builtin_va_copy(ap2,ap1);
    int size = 1 + vsnprintf(0, 0, fmt, ap1);
    char* outp = (char*) GC_malloc_atomic(size);
    vsnprintf(outp, size, fmt, ap2);
    __builtin_va_end(ap1);
    __builtin_va_end(ap2);
    return outp;
}

canonical_original_code:
char *lsprintf(char *fmt, ...)
{
    __builtin_va_list ap1;
    __builtin_va_list ap2;
    __builtin_va_start(ap1,fmt);
    __builtin_va_copy(ap2,ap1);
    int size = 1 + vsnprintf(0, 0, fmt, ap1);
    char *outp = (char*) GC_malloc_atomic(size);
    vsnprintf(outp, size, fmt, ap2);
    __builtin_va_end(ap1);
    __builtin_va_end(ap2);
    return outp;
}

variable_types:
fmt
char *

variable_types: size int

variable_types:
outp
char *


lchomp

decompiled_code:
const char *__fastcall lchomp(const char *a1)
{
const char *v1; // r12
__int64 v2; // rax
const char *v3; // rdx
__int64 v4; // rax

v1 = (const char *)lstrdup(a1);
v2 = (int)(strlen(v1) - 1);
v3 = &v1[v2];
if ( v1[v2] == 10 )
{
v4 = (__int64)&v1[v2 - 1];
do
{
*v3 = 0;
v3 = (const char *)v4--;
}
while ( *(_BYTE *)(v4 + 1) == 10 );
}
return v1;
}

canonical_decompiled_code:
const char *__fastcall func3(const char *a1)
{
const char *v1; // r12
__int64 v2; // rax
const char *v3; // rdx
__int64 v4; // rax

v1 = (const char *)func1(a1);
v2 = (int)(strlen(v1) - 1);
v3 = &v1[v2];
if ( v1[v2] == 10 )
{
v4 = (__int64)&v1[v2 - 1];
do
{
*v3 = 0;
v3 = (const char *)v4--;
}
while ( *(_BYTE *)(v4 + 1) == 10 );
}
return v1;
}

original_code:
char*
lchomp(const char* ss)
{
    char* yy = lstrdup(ss);
    int nn = strlen(yy);
    int ii = nn - 1;
    while (yy[ii] == '\n') {
        yy[ii] = '\0';
        ii -= 1;
    }
    return yy;
}

canonical_original_code:
char *lchomp(char *ss)
{
    char *yy = lstrdup(ss);
    int nn = strlen(yy);
    int ii = nn - 1;
    while (yy[ii] == '\n') {
        yy[ii] = '\0';
        ii -= 1;
    }
    return yy;
}

variable_types:
ss
char *

variable_types:
yy
char *

variable_types: nn int

variable_types: ii int


lstripc

decompiled_code:
__int64 __fastcall lstripc(char a1, const char *a2)
{
size_t v4; // rax
int v5; // ecx
__int64 v6; // rdi
size_t v7; // r9
void *v8; // rsp
size_t i; // rax
char v10; // dl
char *v11; // rsi
char v13[15]; // [rsp+0h] [rbp-10h] BYREF

v4 = strlen(a2);
v5 = 0;
v6 = 0LL;
v7 = v4;
v8 = alloca(v4 + 10);
for ( i = 0LL; ; ++i )
{
v11 = &v13[v6];
if ( v7 <= i )
break;
v10 = a2[i];
if ( v10 != a1 )
{
*v11 = v10;
v6 = ++v5;
}
}
*v11 = 0;
return lstrdup(v13);
}

canonical_decompiled_code:
__int64 __fastcall func4(char a1, const char *a2)
{
size_t v4; // rax
int v5; // ecx
__int64 v6; // rdi
size_t v7; // r9
void *v8; // rsp
size_t i; // rax
char v10; // dl
char *v11; // rsi
char v13[15]; // [rsp+0h] [rbp-10h] BYREF

v4 = strlen(a2);
v5 = 0;
v6 = 0LL;
v7 = v4;
v8 = alloca(v4 + 10);
for ( i = 0LL; ; ++i )
{
v11 = &v13[v6];
if ( v7 <= i )
break;
v10 = a2[i];
if ( v10 != a1 )
{
*v11 = v10;
v6 = ++v5;
}
}
*v11 = 0;
return func1(v13);
}

original_code:
char*
lstripc(const char cc, const char* ss)
{
    char* yy = __builtin_alloca (strlen(ss) + 2);
    int jj = 0;
    for (int ii = 0; ii < strlen(ss); ++ii) {
        if (ss[ii] != cc) {
            yy[jj] = ss[ii];
            jj += 1;
        }
    }
    yy[jj] = 0;
    return lstrdup(yy);
}

canonical_original_code:
char *lstripc(char cc, char *ss)
{
    char *yy = __builtin_alloca (strlen(ss) + 2);
    int jj = 0;
    for (int ii = 0; ii < strlen(ss); ++ii) {
        if (ss[ii] != cc) {
            yy[jj] = ss[ii];
            jj += 1;
        }
    }
    yy[jj] = 0;
    return lstrdup(yy);
}

variable_types: cc char

variable_types: jj int


lmemcpy

decompiled_code:
void *__fastcall lmemcpy(void *src, size_t n)
{
void *v2; // rax

v2 = (void *)GC_malloc(n);
return memcpy(v2, src, n);
}

canonical_decompiled_code:
void *__fastcall func5(void *src, size_t n)
{
void *v2; // rax

v2 = (void *)GC_malloc(n);
return memcpy(v2, src, n);
}

original_code:
void*
lmemcpy(const void* src, size_t n)
{
    void* dest = GC_malloc(n);
    memcpy(dest, src, n);
    return dest;
}

canonical_original_code:
void *lmemcpy(void *src, unsigned long n)
{
    void *dest = GC_malloc(n);
    memcpy(dest, src, n);
    return dest;
}

variable_types:
src
void *

variable_types:
n
unsigned long

variable_types:
dest
void *


decompiled_code:
__int64 __fastcall lstrvec_alloc(int a1)
{
__int64 result; // rax
__int64 v2; // r12

result = GC_malloc(16LL);
*(_DWORD *)result = a1;
v2 = result;
if ( a1 )
{
*(_QWORD *)(result + 8) = GC_malloc(8LL * a1);
result = v2;
}
return result;
}

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

result = GC_malloc(16LL);
*(_DWORD *)result = a1;
v2 = result;
if ( a1 )
{
*(_QWORD *)(result + 8) = GC_malloc(8LL * a1);
result = v2;
}
return result;
}

original_code:
lstrvec*
lstrvec_alloc(int size)
{
    lstrvec* vec = GC_malloc(sizeof(lstrvec));
    vec->size = size;
    if (size != 0)
        vec->xs = GC_malloc(size * sizeof(char*));
    return vec;
}

canonical_original_code:
struct lstrvec *lstrvec_alloc(int size)
{
    struct lstrvec *vec = GC_malloc(sizeof(lstrvec));
    vec->size = size;
    if (size != 0)
        vec->xs = GC_malloc(size * sizeof(char *));
    return vec;
}

variable_types: struct lstrvec { int size; char **xs; } *


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

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

original_code:
int
lstrvec_size(lstrvec* vec)
{
    return vec->size;
}

canonical_original_code:
int lstrvec_size(struct lstrvec *vec)
{
    return vec->size;
}


decompiled_code:
__int64 __fastcall lstrvec_get(unsigned int *a1, int a2)
{
__int64 v2; // rcx

v2 = *a1;
if ( a2 < 0 || a2 >= (int)v2 )
{
fprintf(stderr, "lstrvec: Out of bounds get(%d) (size = %d).\n", (unsigned int)a2, v2);
abort();
}
return lstrdup(*(const char **)(*((_QWORD *)a1 + 1) + 8LL * a2));
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int *a1, int a2)
{
__int64 v2; // rcx

v2 = *a1;
if ( a2 < 0 || a2 >= (int)v2 )
{
fprintf(stderr, "lstrvec: Out of bounds get(%d) (size = %d).\n", (unsigned int)a2, v2);
abort();
}
return func1(*(const char **)(*((_QWORD *)a1 + 1) + 8LL * a2));
}

original_code:
char*
lstrvec_get(lstrvec* vec, int ii)
{
    if (ii < 0 || ii > vec->size - 1) {
        fprintf(stderr, "lstrvec: Out of bounds get(%d) (size = %d).\n",
                ii, vec->size);
        abort();
    }
    return lstrdup(vec->xs[ii]);
}

canonical_original_code:
char *lstrvec_get(struct lstrvec *vec, int ii)
{
    if (ii < 0 || ii > vec->size - 1) {
        fprintf(stderr, "lstrvec: Out of bounds get(%d) (size = %d).\n",
                ii, vec->size);
        abort();
    }
    return lstrdup(vec->xs[ii]);
}


decompiled_code:
__int64 __fastcall lstrvec_set(unsigned int *a1, int a2, const char *a3)
{
__int64 v3; // rcx
__int64 *v4; // rbx
__int64 result; // rax

v3 = *a1;
if ( a2 < 0 || a2 >= (int)v3 )
{
fprintf(stderr, "lstrvec: Out of bounds get(%d) (size = %d).\n", (unsigned int)a2, v3);
abort();
}
v4 = (__int64 *)(*((_QWORD *)a1 + 1) + 8LL * a2);
result = lstrdup(a3);
*v4 = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned int *a1, int a2, const char *a3)
{
__int64 v3; // rcx
__int64 *v4; // rbx
__int64 result; // rax

v3 = *a1;
if ( a2 < 0 || a2 >= (int)v3 )
{
fprintf(stderr, "lstrvec: Out of bounds get(%d) (size = %d).\n", (unsigned int)a2, v3);
abort();
}
v4 = (__int64 *)(*((_QWORD *)a1 + 1) + 8LL * a2);
result = func1(a3);
*v4 = result;
return result;
}

original_code:
void
lstrvec_set(lstrvec* vec, int ii, char* vv)
{
    if (ii < 0 || ii > vec->size - 1) {
        fprintf(stderr, "lstrvec: Out of bounds get(%d) (size = %d).\n",
                ii, vec->size);
        abort();
    }
    vec->xs[ii] = lstrdup(vv);
}

canonical_original_code:
void lstrvec_set(struct lstrvec *vec, int ii, char *vv)
{
    if (ii < 0 || ii > vec->size - 1) {
        fprintf(stderr, "lstrvec: Out of bounds get(%d) (size = %d).\n",
                ii, vec->size);
        abort();
    }
    vec->xs[ii] = lstrdup(vv);
}

variable_types:
vv
char *


decompiled_code:
__int64 __fastcall lstrvec_contains(__int64 a1, const char *a2)
{
__int64 v2; // rbx

if ( *(int *)a1 <= 0 )
return 0LL;
v2 = 0LL;
do
{
if ( streq(a2, *(const char **)(*(_QWORD *)(a1 + 8) + 8 * v2)) )
return 1LL;
++v2;
}
while ( *(_DWORD *)a1 > (int)v2 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, const char *a2)
{
__int64 v2; // rbx

if ( *(int *)a1 <= 0 )
return 0LL;
v2 = 0LL;
do
{
if ( func0(a2, *(const char **)(*(_QWORD *)(a1 + 8) + 8 * v2)) )
return 1LL;
++v2;
}
while ( *(_DWORD *)a1 > (int)v2 );
return 0LL;
}

original_code:
int
lstrvec_contains(lstrvec* vec, const char* ss)
{
    int ii;
    for (ii = 0; ii < vec->size; ++ii) {
        if (streq(ss, vec->xs[ii]))
            return 1;
    }
    return 0;
}

canonical_original_code:
int lstrvec_contains(struct lstrvec *vec, char *ss)
{
    int ii;
    for (ii = 0; ii < vec->size; ++ii) {
        if (streq(ss, vec->xs[ii]))
            return 1;
    }
    return 0;
}


lwords

decompiled_code:
unsigned int *__fastcall lwords(const char *a1)
{
const char *v1; // rbx
int v2; // eax
int v3; // er8
int v4; // ebp
int v5; // eax
int v6; // er9
__int64 v7; // rcx
const char *v8; // rcx
const char *v9; // rsi
__int64 v10; // rdx
int v11; // edi
int v12; // edi
int v13; // er12
unsigned int *v14; // r13
const char *v15; // rax

v1 = (const char *)lstrdup(a1);
v2 = strlen(v1);
if ( v2 <= 0 )
{
v12 = 1;
v4 = 0;
goto LABEL_10;
}
v3 = v2;
v4 = 0;
v5 = 0;
v6 = 1;
do
{
while ( 1 )
{
v7 = v5++;
v8 = &v1[v7];
if ( *v8 == 32 )
break;
LABEL_3:
if ( v3 <= v5 )
goto LABEL_9;
}
*v8 = 0;
v9 = &v1[v5];
if ( *v9 != 32 )
{
v4 = v6++;
goto LABEL_3;
}
v10 = 0LL;
do
{
v9[v10] = 0;
v11 = v5 + v10++;
}
while ( v8[v10 + 1] == 32 );
v5 = v11 + 1;
v4 = v6++;
}
while ( v3 > v11 + 1 );
LABEL_9:
v12 = v6;
LABEL_10:
v13 = 0;
v14 = (unsigned int *)lstrvec_alloc(v12);
do
{
v15 = (const char *)lstrdup(v1);
lstrvec_set(v14, v13, v15);
v1 += strlen(v1);
do
++v1;
while ( !*v1 );
++v13;
}
while ( v13 <= v4 );
return v14;
}

canonical_decompiled_code:
unsigned int *__fastcall func11(const char *a1)
{
const char *v1; // rbx
int v2; // eax
int v3; // er8
int v4; // ebp
int v5; // eax
int v6; // er9
__int64 v7; // rcx
const char *v8; // rcx
const char *v9; // rsi
__int64 v10; // rdx
int v11; // edi
int v12; // edi
int v13; // er12
unsigned int *v14; // r13
const char *v15; // rax

v1 = (const char *)func1(a1);
v2 = strlen(v1);
if ( v2 <= 0 )
{
v12 = 1;
v4 = 0;
goto LABEL_10;
}
v3 = v2;
v4 = 0;
v5 = 0;
v6 = 1;
do
{
while ( 1 )
{
v7 = v5++;
v8 = &v1[v7];
if ( *v8 == 32 )
break;
LABEL_3:
if ( v3 <= v5 )
goto LABEL_9;
}
*v8 = 0;
v9 = &v1[v5];
if ( *v9 != 32 )
{
v4 = v6++;
goto LABEL_3;
}
v10 = 0LL;
do
{
v9[v10] = 0;
v11 = v5 + v10++;
}
while ( v8[v10 + 1] == 32 );
v5 = v11 + 1;
v4 = v6++;
}
while ( v3 > v11 + 1 );
LABEL_9:
v12 = v6;
LABEL_10:
v13 = 0;
v14 = (unsigned int *)func6(v12);
do
{
v15 = (const char *)func1(v1);
func9(v14, v13, v15);
v1 += strlen(v1);
do
++v1;
while ( !*v1 );
++v13;
}
while ( v13 <= v4 );
return v14;
}

original_code:
lstrvec*
lwords(const char* ss)
{
    char* aa = lstrdup(ss);
    int ii, jj;
    int nn = strlen(aa);
    int spaces = 0;
    lstrvec* xs;
    for (ii = 0; ii < nn; ++ii) {
        if (aa[ii] == ' ') {
            aa[ii] = '\0';
            spaces += 1;
            while (aa[ii + 1] == ' ') {
                ii += 1;
                aa[ii] = '\0';
            }
        }
    }
    xs = lstrvec_alloc(spaces + 1);
    for (ii = 0; ii < spaces + 1; ++ii) {
        lstrvec_set(xs, ii, lstrdup(aa));
        aa += strlen(aa);
        while(aa[0] == '\0')
            aa += 1;
    }
    return xs;
}

canonical_original_code:
struct lstrvec *lwords(char *ss)
{
    char *aa = lstrdup(ss);
    int ii; int jj;
    int nn = strlen(aa);
    int spaces = 0;
    struct lstrvec *xs;
    for (ii = 0; ii < nn; ++ii) {
        if (aa[ii] == ' ') {
            aa[ii] = '\0';
            spaces += 1;
            while (aa[ii + 1] == ' ') {
                ii += 1;
                aa[ii] = '\0';
            }
        }
    }
    xs = lstrvec_alloc(spaces + 1);
    for (ii = 0; ii < spaces + 1; ++ii) {
        lstrvec_set(xs, ii, lstrdup(aa));
        aa += strlen(aa);
        while(aa[0] == '\0')
            aa += 1;
    }
    return xs;
}

variable_types:
aa
char *

variable_types: spaces int


lsplitc

decompiled_code:
unsigned int *__fastcall lsplitc(char a1, const char *a2)
{
const char *v2; // rbx
int v3; // eax
int v4; // edx
int v5; // er12
const char *v6; // rax
__int64 v7; // rdx
int v8; // ebp
unsigned int *v9; // r13
const char *v10; // rax

v2 = (const char *)lstrdup(a2);
v3 = strlen(v2);
if ( v3 <= 0 )
{
v5 = 1;
}
else
{
v4 = v3;
v5 = 1;
v6 = v2;
v7 = (__int64)&v2[v4 - 1 + 1];
do
{
if ( *v6 == a1 )
{
*v6 = 0;
++v5;
}
++v6;
}
while ( v6 != (const char *)v7 );
}
v8 = 0;
v9 = (unsigned int *)lstrvec_alloc(v5);
do
{
v10 = (const char *)lstrdup(v2);
lstrvec_set(v9, v8, v10);
v2 += strlen(v2);
do
++v2;
while ( !*v2 );
++v8;
}
while ( v8 != v5 );
return v9;
}

canonical_decompiled_code:
unsigned int *__fastcall func12(char a1, const char *a2)
{
const char *v2; // rbx
int v3; // eax
int v4; // edx
int v5; // er12
const char *v6; // rax
__int64 v7; // rdx
int v8; // ebp
unsigned int *v9; // r13
const char *v10; // rax

v2 = (const char *)func1(a2);
v3 = strlen(v2);
if ( v3 <= 0 )
{
v5 = 1;
}
else
{
v4 = v3;
v5 = 1;
v6 = v2;
v7 = (__int64)&v2[v4 - 1 + 1];
do
{
if ( *v6 == a1 )
{
*v6 = 0;
++v5;
}
++v6;
}
while ( v6 != (const char *)v7 );
}
v8 = 0;
v9 = (unsigned int *)func6(v5);
do
{
v10 = (const char *)func1(v2);
func9(v9, v8, v10);
v2 += strlen(v2);
do
++v2;
while ( !*v2 );
++v8;
}
while ( v8 != v5 );
return v9;
}

original_code:
lstrvec*
lsplitc(const char cc, const char* ss)
{
    char* aa = lstrdup(ss);
    int ii, jj;
    int nn = strlen(aa);
    int slots = 1;
    lstrvec* xs;
    for (ii = 0; ii < nn; ++ii) {
        if (aa[ii] == cc) {
            aa[ii] = '\0';
            slots += 1;
        }
    }
    xs = lstrvec_alloc(slots);
    for (ii = 0; ii < slots; ++ii) {
        lstrvec_set(xs, ii, lstrdup(aa));
        aa += strlen(aa);
        while(aa[0] == '\0')
            aa += 1;
    }
    return xs;
}

canonical_original_code:
struct lstrvec *lsplitc(char cc, char *ss)
{
    char *aa = lstrdup(ss);
    int ii; int jj;
    int nn = strlen(aa);
    int slots = 1;
    struct lstrvec *xs;
    for (ii = 0; ii < nn; ++ii) {
        if (aa[ii] == cc) {
            aa[ii] = '\0';
            slots += 1;
        }
    }
    xs = lstrvec_alloc(slots);
    for (ii = 0; ii < slots; ++ii) {
        lstrvec_set(xs, ii, lstrdup(aa));
        aa += strlen(aa);
        while(aa[0] == '\0')
            aa += 1;
    }
    return xs;
}

variable_types: slots int


decompiled_code:
void __fastcall __noreturn drip_carp_real(const char *a1, unsigned int a2, const char *a3)
{
fprintf(stderr, "Fatal error at %s:%d\n\t%s\n", a1, a2, a3);
fflush(stderr);
abort();
}

canonical_decompiled_code:
void __fastcall __noreturn func0(const char *a1, unsigned int a2, const char *a3)
{
fprintf(stderr, "Fatal error at %s:%d\n\t%s\n", a1, a2, a3);
fflush(stderr);
abort();
}

original_code:
void
drip_carp_real(const char* filename, const int line, const char* message)
{
    fprintf(stderr, "Fatal error at %s:%d\n\t%s\n", filename, line, message);
    fflush(stderr);
    abort();
}

canonical_original_code:
void drip_carp_real(char *filename, int line, char *message)
{
    fprintf(stderr, "Fatal error at %s:%d\n\t%s\n", filename, line, message);
    fflush(stderr);
    abort();
}

variable_types:
filename
char *

variable_types: line int

variable_types:
message
char *


repo: NatTuck/pancake

decompiled_code:
float rand48()
{
unsigned __int16 v1; // ax

if ( !seeded_1 )
{
v1 = getpid();
seeded_1 = 1;
seed_0[2] = v1;
}
return erand48(seed_0);
}

canonical_decompiled_code:
float func0()
{
unsigned __int16 v1; // ax

if ( !seeded_1 )
{
v1 = getpid();
seeded_1 = 1;
seed_0[2] = v1;
}
return erand48(seed_0);
}

original_code:
float
rand48()
{
    static unsigned short seed[3] = { 50, 461, 0 };
    static int seeded = 0;
    if (seeded == 0) {
        seed[2] = (short)getpid();
        seeded = 1;
    }
    return (float) erand48(seed);
}

variable_types:
seed
unsigned short [3]

variable_types: seeded int


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

original_code:
size_t
matrix_size(matrix * mm)
{
    return mm->rows * mm->cols;
}

canonical_original_code:
unsigned long matrix_size(struct matrix *mm)
{
    return mm->rows * mm->cols;
}

variable_types: struct matrix { float *data; unsigned long rows; unsigned long cols; } *


decompiled_code:
__int64 __fastcall matrix_bytes(__int64 a1)
{
return 4 * matrix_size(a1);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
return 4 * func1(a1);
}

original_code:
size_t
matrix_bytes(matrix * mm)
{
    return matrix_size(mm) * sizeof(float);
}

canonical_original_code:
unsigned long matrix_bytes(struct matrix *mm)
{
    return matrix_size(mm) * sizeof(float);
}


decompiled_code:
void __fastcall destroy_matrix(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func4(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

original_code:
void
destroy_matrix(matrix * mm)
{
    free(mm->data);
    free(mm);
}

canonical_original_code:
void destroy_matrix(struct matrix *mm)
{
    free(mm->data);
    free(mm);
}


decompiled_code:
__int64 __fastcall set_cell(__int64 *a1, __int64 a2, __int64 a3, float a4)
{
__int64 result; // rax

result = *a1;
*(float *)(*a1 + 4 * (a3 + a1[2] * a2)) = a4;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 *a1, __int64 a2, __int64 a3, float a4)
{
__int64 result; // rax

result = *a1;
*(float *)(*a1 + 4 * (a3 + a1[2] * a2)) = a4;
return result;
}

original_code:
void
set_cell(matrix * mm, size_t ii, size_t jj, float value)
{
    mm->data[ii * mm->cols + jj] = value;
}

canonical_original_code:
void set_cell(struct matrix *mm, unsigned long ii, unsigned long jj, float value)
{
    mm->data[ii * mm->cols + jj] = value;
}

variable_types:
ii
unsigned long

variable_types:
jj
unsigned long

variable_types: value float


decompiled_code:
float __fastcall get_cell(_QWORD *a1, __int64 a2, __int64 a3)
{
return *(float *)(*a1 + 4 * (a3 + a1[2] * a2));
}

canonical_decompiled_code:
float __fastcall func6(_QWORD *a1, __int64 a2, __int64 a3)
{
return *(float *)(*a1 + 4 * (a3 + a1[2] * a2));
}

original_code:
float
get_cell(matrix * mm, size_t ii, size_t jj)
{
    return mm->data[ii * mm->cols + jj];
}

canonical_original_code:
float get_cell(struct matrix *mm, unsigned long ii, unsigned long jj)
{
    return mm->data[ii * mm->cols + jj];
}


decompiled_code:
int __fastcall print_matrix(_QWORD *a1)
{
unsigned __int64 v1; // r12
unsigned __int64 v2; // rbx
__int64 v3; // rdx
float v4; // xmm0_4
int result; // eax

if ( a1[1] )
{
v1 = 0LL;
do
{
v2 = 0LL;
while ( a1[2] > v2 )
{
v3 = v2++;
v4 = get_cell(a1, v1, v3);
printf("%.02f", v4);
putchar(32);
}
++v1;
result = putchar(10);
}
while ( a1[1] > v1 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func7(_QWORD *a1)
{
unsigned __int64 v1; // r12
unsigned __int64 v2; // rbx
__int64 v3; // rdx
float v4; // xmm0_4
int result; // eax

if ( a1[1] )
{
v1 = 0LL;
do
{
v2 = 0LL;
while ( a1[2] > v2 )
{
v3 = v2++;
v4 = func6(a1, v1, v3);
printf("%.02f", v4);
putchar(32);
}
++v1;
result = putchar(10);
}
while ( a1[1] > v1 );
}
return result;
}

original_code:
void
print_matrix(matrix * mm)
{
    for (size_t ii = 0; ii < mm->rows; ++ii) {
        for (size_t jj = 0; jj < mm->cols; ++jj) {
            float xx = get_cell(mm, ii, jj);
            printf("%.02f", xx);
            printf(" ");
        }
        printf("\n");
    }
}

canonical_original_code:
void print_matrix(struct matrix *mm)
{
    for (unsigned long ii = 0; ii < mm->rows; ++ii) {
        for (unsigned long jj = 0; jj < mm->cols; ++jj) {
            float xx = get_cell(mm, ii, jj);
            printf("%.02f", xx);
            printf(" ");
        }
        printf("\n");
    }
}

variable_types: xx float


decompiled_code:
int __fastcall check_result(__int64 a1, _QWORD *a2, __m128i a3)
{
__int64 v3; // r10
__int64 v5; // rbp
unsigned __int64 v6; // r9
__int64 v7; // r12
float v8; // ebx
__int64 v9; // rdx
_QWORD *v10; // rcx
float v11; // xmm0_4

v3 = *(_QWORD *)(a1 + 8);
if ( !v3 )
return puts("Result is correct.");
v5 = 0LL;
v6 = *(_QWORD *)(a1 + 16);
while ( 1 )
{
v7 = 1LL;
if ( v6 > 1 )
break;
LABEL_8:
if ( v3 == ++v5 )
return puts("Result is correct.");
}
while ( 1 )
{
*(float *)a3.m128i_i32 = get_cell(a2, v5, v7);
v8 = COERCE_FLOAT(_mm_cvtsi128_si32(a3));
v11 = get_cell(v10, v5, v9);
if ( (float)(int)abs32((int)(float)(v8 - v11)) > 0.001 )
break;
if ( ++v7 == v6 )
goto LABEL_8;
}
puts("ERROR - Incorrect result.");
return printf("At %ld, %ld got %f instead of %f\n", v5, v7, v11, v8);
}

canonical_decompiled_code:
int __fastcall func8(__int64 a1, _QWORD *a2, __m128i a3)
{
__int64 v3; // r10
__int64 v5; // rbp
unsigned __int64 v6; // r9
__int64 v7; // r12
float v8; // ebx
__int64 v9; // rdx
_QWORD *v10; // rcx
float v11; // xmm0_4

v3 = *(_QWORD *)(a1 + 8);
if ( !v3 )
return puts("Result is correct.");
v5 = 0LL;
v6 = *(_QWORD *)(a1 + 16);
while ( 1 )
{
v7 = 1LL;
if ( v6 > 1 )
break;
LABEL_8:
if ( v3 == ++v5 )
return puts("Result is correct.");
}
while ( 1 )
{
*(float *)a3.m128i_i32 = func6(a2, v5, v7);
v8 = COERCE_FLOAT(_mm_cvtsi128_si32(a3));
v11 = func6(v10, v5, v9);
if ( (float)(int)abs32((int)(float)(v8 - v11)) > 0.001 )
break;
if ( ++v7 == v6 )
goto LABEL_8;
}
puts("ERROR - Incorrect result.");
return printf("At %ld, %ld got %f instead of %f\n", v5, v7, v11, v8);
}

original_code:
void
check_result(matrix * cc, matrix * aa)
{
    const float EPS = 0.001;
    for (size_t ii = 0; ii < cc->rows; ++ii) {
        for (size_t jj = 1; jj < cc->cols; ++jj) {
            float xx = get_cell(aa, ii, jj);
            float yy = get_cell(cc, ii, jj);
            if (abs(1*xx - yy) > EPS) {
                printf("ERROR - Incorrect result.\n");
                printf("At %ld, %ld got %f instead of %f\n",
                       ii, jj, yy, xx);
                return;
            }
        }
    }
    printf("Result is correct.\n");
}

canonical_original_code:
void check_result(struct matrix *cc, struct matrix *aa)
{
    float EPS = 0.001;
    for (unsigned long ii = 0; ii < cc->rows; ++ii) {
        for (unsigned long jj = 1; jj < cc->cols; ++jj) {
            float xx = get_cell(aa, ii, jj);
            float yy = get_cell(cc, ii, jj);
            if (abs(1*xx - yy) > EPS) {
                printf("ERROR - Incorrect result.\n");
                printf("At %ld, %ld got %f instead of %f\n",
                       ii, jj, yy, xx);
                return;
            }
        }
    }
    printf("Result is correct.\n");
}

variable_types:
aa
struct matrix *

variable_types: EPS float

variable_types: yy float


decompiled_code:
int __fastcall timer_reset(struct timeval *a1)
{
return gettimeofday(a1, 0LL);
}

canonical_decompiled_code:
int __fastcall func0(struct timeval *a1)
{
return gettimeofday(a1, 0LL);
}

original_code:
void
timer_reset(timer* tt)
{
    struct timeval* tv = (struct timeval*)tt;
    gettimeofday(tv, 0);
}

canonical_original_code:
void timer_reset(struct timeval *tt)
{
    struct timeval *tv = (struct timeval*)tt;
    gettimeofday(tv, 0);
}

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


decompiled_code:
struct timeval *timer_alloc()
{
struct timeval *v0; // r12

v0 = (struct timeval *)malloc(0x10uLL);
timer_reset(v0);
return v0;
}

canonical_decompiled_code:
struct timeval *func1()
{
struct timeval *v0; // r12

v0 = (struct timeval *)malloc(0x10uLL);
func0(v0);
return v0;
}

original_code:
timer*
timer_alloc()
{
    timer* tt = (timer*) malloc(sizeof(timer));
    timer_reset(tt);
    return tt;
}

canonical_original_code:
struct timeval *timer_alloc()
{
    struct timeval *tt = (timer*) malloc(sizeof(timer));
    timer_reset(tt);
    return tt;
}


decompiled_code:
double __fastcall timer_read(_QWORD *a1)
{
struct timeval v2; // [rsp+0h] [rbp-30h] BYREF

gettimeofday(&v2, 0LL);
return (double)SLODWORD(v2.tv_usec) / 1000000.0
+ (double)SLODWORD(v2.tv_sec)
- ((double)(int)a1[1] / 1000000.0
+ (double)(int)*a1);
}

canonical_decompiled_code:
double __fastcall func2(_QWORD *a1)
{
struct timeval v2; // [rsp+0h] [rbp-30h] BYREF

gettimeofday(&v2, 0LL);
return (double)SLODWORD(v2.tv_usec) / 1000000.0
+ (double)SLODWORD(v2.tv_sec)
- ((double)(int)a1[1] / 1000000.0
+ (double)(int)*a1);
}

original_code:
double
timer_read(timer* tt)
{
    const double MM = 1000000.0;
    struct timeval* tv0 = (struct timeval*)tt;
    struct timeval* tv1 = (struct timeval*)__builtin_alloca (sizeof(struct timeval));
    gettimeofday(tv1, 0);
    double s0 = tv0->tv_sec + ((double)tv0->tv_usec) / MM;
    double s1 = tv1->tv_sec + ((double)tv1->tv_usec) / MM;
    return s1 - s0;
}

canonical_original_code:
double timer_read(struct timeval *tt)
{
    double MM = 1000000.0;
    struct timeval *tv0 = (struct timeval*)tt;
    struct timeval *tv1 = (struct timeval*)__builtin_alloca (sizeof(struct timeval));
    gettimeofday(tv1, 0);
    double s0 = tv0->tv_sec + ((double)tv0->tv_usec) / MM;
    double s1 = tv1->tv_sec + ((double)tv1->tv_usec) / MM;
    return s1 - s0;
}

variable_types: MM double


decompiled_code:
// attributes: thunk
void timer_free(void *ptr)
{
free(ptr);
}

canonical_decompiled_code:
void func3(void *ptr)
{
free(ptr);
}

original_code:
void
timer_free(timer* tt)
{
    free(tt);
}

canonical_original_code:
void timer_free(struct timeval *tt)
{
    free(tt);
}


decompiled_code:
int __fastcall pclu_perror(int a1)
{
char *v1; // rax

v1 = pclu_strerror(a1);
return fprintf(stderr, "OpenCL Error: %s\n", v1);
}

canonical_decompiled_code:
int __fastcall func1(int a1)
{
char *v1; // rax

v1 = func0(a1);
return fprintf(stderr, "OpenCL Error: %s\n", v1);
}

original_code:
void
pclu_perror(int code)
{
    fprintf(stderr, "OpenCL Error: %s\n", pclu_strerror(code));
}

variable_types: code int