vecpop

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

if ( !a1 )
_assert_fail("V", "src/vector.c", 0x33u, "vecpop");
if ( *a1 <= 0 )
_assert_fail("V->num > 0", "src/vector.c", 0x34u, "vecpop");
result = (unsigned int)(*a1 - 1);
*a1 = result;
return result;
}

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

if ( !a1 )
_assert_fail("V", "src/vector.c", 0x33u, "vecpop");
if ( *a1 <= 0 )
_assert_fail("V->num > 0", "src/vector.c", 0x34u, "vecpop");
result = (unsigned int)(*a1 - 1);
*a1 = result;
return result;
}

original_code:
void vecpop(vector_t V)
{
    ((void) sizeof ((V) ? 1 : 0), __extension__ ({ if (V) ; else __assert_fail ("V", "src/vector.c", 51, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((V->num > 0) ? 1 : 0), __extension__ ({ if (V->num > 0) ; else __assert_fail ("V->num > 0", "src/vector.c", 52, __extension__ __PRETTY_FUNCTION__); }));
    V->num--;
}

canonical_original_code:
void vecpop(struct vector *V)
{
    ((void) sizeof ((V) ? 1 : 0), __extension__ ({ if (V) ; else __assert_fail ("V", "src/vector.c", 51, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((V->num > 0) ? 1 : 0), __extension__ ({ if (V->num > 0) ; else __assert_fail ("V->num > 0", "src/vector.c", 52, __extension__ __PRETTY_FUNCTION__); }));
    V->num--;
}

user_defined_types: struct vector { int num; int max; int siz; void *buf; }


vecget

repo: rlk/electro

decompiled_code:
__int64 __fastcall vecget(__int64 a1, int a2)
{
if ( !a1 )
_assert_fail("V", "src/vector.c", 0x5Eu, "vecget");
if ( a2 < 0 || *(_DWORD *)a1 <= a2 )
_assert_fail("0 <= i && i < V->num", "src/vector.c", 0x5Fu, "vecget");
return *(_QWORD *)(a1 + 16) + *(_DWORD *)(a1 + 8) * a2;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int a2)
{
if ( !a1 )
_assert_fail("V", "src/vector.c", 0x5Eu, "vecget");
if ( a2 < 0 || *(_DWORD *)a1 <= a2 )
_assert_fail("0 <= i && i < V->num", "src/vector.c", 0x5Fu, "vecget");
return *(_QWORD *)(a1 + 16) + *(_DWORD *)(a1 + 8) * a2;
}

original_code:
void *vecget(vector_t V, int i)
{
    ((void) sizeof ((V) ? 1 : 0), __extension__ ({ if (V) ; else __assert_fail ("V", "src/vector.c", 94, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((0 <= i && i < V->num) ? 1 : 0), __extension__ ({ if (0 <= i && i < V->num) ; else __assert_fail ("0 <= i && i < V->num", "src/vector.c", 95, __extension__ __PRETTY_FUNCTION__); }));
    return ((char *) (V)->buf) + ((V)->siz * (i));
}

canonical_original_code:
void *vecget(struct vector *V, int i)
{
    ((void) sizeof ((V) ? 1 : 0), __extension__ ({ if (V) ; else __assert_fail ("V", "src/vector.c", 94, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((0 <= i && i < V->num) ? 1 : 0), __extension__ ({ if (0 <= i && i < V->num) ; else __assert_fail ("0 <= i && i < V->num", "src/vector.c", 95, __extension__ __PRETTY_FUNCTION__); }));
    return ((char *) (V)->buf) + ((V)->siz * (i));
}

variable_types: struct vector { int num; int max; int siz; void *buf; } *

variable_types: i int

return_type: void *


vecadd

decompiled_code:
__int64 __fastcall vecadd(__int64 a1)
{
int v1; // eax
int v2; // ebp
void *v3; // rax
unsigned int v4; // ebp
void *v5; // rax

if ( !a1 )
_assert_fail("V", "src/vector.c", 0x47u, "vecadd");
v1 = *(_DWORD *)(a1 + 4);
if ( *(_DWORD *)a1 == v1 )
{
v2 = 2 * v1;
if ( !v1 )
v2 = 1;
v3 = realloc(*(void **)(a1 + 16), *(_DWORD *)(a1 + 8) * v2);
if ( !v3 )
return (unsigned int)-1;
*(_DWORD *)(a1 + 4) = v2;
*(_QWORD *)(a1 + 16) = v3;
}
v4 = (*(_DWORD *)a1)++;
v5 = (void *)vecget(a1, v4);
memset(v5, 0, *(int *)(a1 + 8));
return v4;
}

original_code:
int vecadd(vector_t V)
{
    void *buf;
    int i;
    ((void) sizeof ((V) ? 1 : 0), __extension__ ({ if (V) ; else __assert_fail ("V", "src/vector.c", 71, __extension__ __PRETTY_FUNCTION__); }));
    if (V->num == V->max)
    {
        int max = (V->max == 0) ? 1 : 2 * V->max;
        if ((buf = realloc(V->buf, V->siz * max)))
        {
            V->max = max;
            V->buf = buf;
        }
        else return -1;
    }
    i = V->num++;
    memset(vecget(V, i), 0, V->siz);
    return i;
}

canonical_original_code:
int vecadd(struct vector *V)
{
    void *buf;
    int i;
    ((void) sizeof ((V) ? 1 : 0), __extension__ ({ if (V) ; else __assert_fail ("V", "src/vector.c", 71, __extension__ __PRETTY_FUNCTION__); }));
    if (V->num == V->max)
    {
        int max = (V->max == 0) ? 1 : 2 * V->max;
        if ((buf = realloc(V->buf, V->siz * max)))
        {
            V->max = max;
            V->buf = buf;
        }
        else return -1;
    }
    i = V->num++;
    memset(vecget(V, i), 0, V->siz);
    return i;
}

variable_types:
buf
void *

variable_types: max int

return_type: int


blit

repo: rlk/gigo

original_code:
static void blit(img *d, int x, int y, img *s, int X, int Y, int W, int H)
{
    const int c = (s->p < d->p) ? s->p : d->p;
    int i;
    int j;
    int k;

#pragma omp parallel for private(j)
    for (i = 0; i < H; i++)
        for (j = 0; j < W; j++)
            for (k = 0; k < c; k++)
                imgz(d, y + i, x + j)[k] = imgz(s, Y + i, X + j)[k];
}

canonical_original_code:
static void blit(struct img *d, int x, int y, struct img *s, int X, int Y, int W, int H)
{
    int c = (s->p < d->p) ? s->p : d->p;
    int i;
    int j;
    int k;

#pragma omp parallel for private(j)
    for (i = 0; i < H; i++)
        for (j = 0; j < W; j++)
            for (k = 0; k < c; k++)
                imgz(d, y + i, x + j)[k] = imgz(s, Y + i, X + j)[k];
}

variable_types: struct img { int f; void *a; int l; int n; int m; int p; int t; int s; int h; int w; } *

variable_types: x int

variable_types: y int

variable_types:
s
struct img *

variable_types: X int

variable_types: Y int

variable_types: W int

variable_types: H int

variable_types: c int

variable_types: j int

variable_types: k int

return_type: void


printhms

decompiled_code:
int __fastcall printhms(double a1)
{
__int64 v1; // rsi
double v2; // xmm0_8
unsigned int v3; // ebx
double v4; // xmm0_8

v1 = (unsigned int)((int)a1 / 3600);
v2 = a1 - (double)(3600 * (int)v1);
v3 = (int)v2 / 60;
v4 = v2 - (double)(int)(60 * v3);
if ( (_DWORD)v1 )
printf("%dh", v1);
if ( v3 )
printf("%dm", v3);
return printf("%.3fs", v4);
}

canonical_decompiled_code:
int __fastcall func5(double a1)
{
__int64 v1; // rsi
double v2; // xmm0_8
unsigned int v3; // ebx
double v4; // xmm0_8

v1 = (unsigned int)((int)a1 / 3600);
v2 = a1 - (double)(3600 * (int)v1);
v3 = (int)v2 / 60;
v4 = v2 - (double)(int)(60 * v3);
if ( (_DWORD)v1 )
printf("%dh", v1);
if ( v3 )
printf("%dm", v3);
return printf("%.3fs", v4);
}

original_code:
static inline void printhms(double s)
{
    int h = (int) s / 3600; s -= h * 3600;
    int m = (int) s / 60; s -= m * 60;
    if (h) printf("%dh", h);
    if (m) printf("%dm", m);
    printf("%.3fs", s);
}

variable_types: s double

variable_types: h int

variable_types: m int


original_code:
static float op_rmin(img *s, int k)
{
    int r;
    int c;
    int i;
    int j;
    float v = 3.40282346638528859811704183484516925e+38F;
    for (r = 0; r < s->h; r++)
        for (c = 0; c < s->w; c++)
            for (i = 0; i < s->s; i++)
                for (j = 0; j < s->s; j++)
                    if (v > creal(imgbuf(s, r, c, i, j)[k]))
                        v = creal(imgbuf(s, r, c, i, j)[k]);
    return v;
}

canonical_original_code:
static float op_rmin(struct img *s, int k)
{
    int r;
    int c;
    int i;
    int j;
    float v = 3.40282346638528859811704183484516925e+38F;
    for (r = 0; r < s->h; r++)
        for (c = 0; c < s->w; c++)
            for (i = 0; i < s->s; i++)
                for (j = 0; j < s->s; j++)
                    if (v > creal(imgbuf(s, r, c, i, j)[k]))
                        v = creal(imgbuf(s, r, c, i, j)[k]);
    return v;
}

variable_types: r int

variable_types: i int

variable_types: v float

return_type: float

user_defined_types: struct img { int f; void *a; int l; int n; int m; int p; int t; int s; int h; int w; }


original_code:
static float op_rmax(img *s, int k)
{
    int r;
    int c;
    int i;
    int j;
    float v = -3.40282346638528859811704183484516925e+38F;
    for (r = 0; r < s->h; r++)
        for (c = 0; c < s->w; c++)
            for (i = 0; i < s->s; i++)
                for (j = 0; j < s->s; j++)
                    if (v < creal(imgbuf(s, r, c, i, j)[k]))
                        v = creal(imgbuf(s, r, c, i, j)[k]);
    return v;
}

canonical_original_code:
static float op_rmax(struct img *s, int k)
{
    int r;
    int c;
    int i;
    int j;
    float v = -3.40282346638528859811704183484516925e+38F;
    for (r = 0; r < s->h; r++)
        for (c = 0; c < s->w; c++)
            for (i = 0; i < s->s; i++)
                for (j = 0; j < s->s; j++)
                    if (v < creal(imgbuf(s, r, c, i, j)[k]))
                        v = creal(imgbuf(s, r, c, i, j)[k]);
    return v;
}

variable_types: struct img { int f; void *a; int l; int n; int m; int p; int t; int s; int h; int w; } *


canonical_decompiled_code:
int __fastcall func4(double a1)
{
__int64 v1; // rsi
double v2; // xmm0_8
unsigned int v3; // ebx
double v4; // xmm0_8

v1 = (unsigned int)((int)a1 / 3600);
v2 = a1 - (double)(3600 * (int)v1);
v3 = (int)v2 / 60;
v4 = v2 - (double)(int)(60 * v3);
if ( (_DWORD)v1 )
printf("%dh", v1);
if ( v3 )
printf("%dm", v3);
return printf("%.3fs", v4);
}

canonical_original_code:
static inline void printhms(double s)
{
    int h = (int) s / 3600; s -= h * 3600;
    int m = (int) s / 60; s -= m * 60;
    if (h) printf("%dh", h);
    if (m) printf("%dm", m);
    printf("%.3fs", s);
}


original_code:
static float op_cmin(img *s, int k)
{
    int r;
    int c;
    int i;
    int j;
    float v = 3.40282346638528859811704183484516925e+38F;
    for (r = 0; r < s->h; r++)
        for (c = 0; c < s->w; c++)
            for (i = 0; i < s->s; i++)
                for (j = 0; j < s->s; j++)
                    if (v > cabs(imgbuf(s, r, c, i, j)[k]))
                        v = cabs(imgbuf(s, r, c, i, j)[k]);
    return v;
}

canonical_original_code:
static float op_cmin(struct img *s, int k)
{
    int r;
    int c;
    int i;
    int j;
    float v = 3.40282346638528859811704183484516925e+38F;
    for (r = 0; r < s->h; r++)
        for (c = 0; c < s->w; c++)
            for (i = 0; i < s->s; i++)
                for (j = 0; j < s->s; j++)
                    if (v > cabs(imgbuf(s, r, c, i, j)[k]))
                        v = cabs(imgbuf(s, r, c, i, j)[k]);
    return v;
}


original_code:
static float op_cmax(img *s, int k)
{
    int r;
    int c;
    int i;
    int j;
    float v = -3.40282346638528859811704183484516925e+38F;
    for (r = 0; r < s->h; r++)
        for (c = 0; c < s->w; c++)
            for (i = 0; i < s->s; i++)
                for (j = 0; j < s->s; j++)
                    if (v < cabs(imgbuf(s, r, c, i, j)[k]))
                        v = cabs(imgbuf(s, r, c, i, j)[k]);
    return v;
}

canonical_original_code:
static float op_cmax(struct img *s, int k)
{
    int r;
    int c;
    int i;
    int j;
    float v = -3.40282346638528859811704183484516925e+38F;
    for (r = 0; r < s->h; r++)
        for (c = 0; c < s->w; c++)
            for (i = 0; i < s->s; i++)
                for (j = 0; j < s->s; j++)
                    if (v < cabs(imgbuf(s, r, c, i, j)[k]))
                        v = cabs(imgbuf(s, r, c, i, j)[k]);
    return v;
}


original_code:
static inline int log2i(unsigned int n)
{
    unsigned int r, s;
    r = (n > 0xFFFFUL) << 4; n >>= r;
    s = (n > 0xFFUL ) << 3; n >>= s; r |= s;
    s = (n > 0xFUL ) << 2; n >>= s; r |= s;
    s = (n > 0x3UL ) << 1; n >>= s; r |= s;
    return (int) (r | (n >> 1));
}

canonical_original_code:
static inline int log2i(unsigned int n)
{
    unsigned int r; unsigned int s;
    r = (n > 0xFFFFUL) << 4; n >>= r;
    s = (n > 0xFFUL ) << 3; n >>= s; r |= s;
    s = (n > 0xFUL ) << 2; n >>= s; r |= s;
    s = (n > 0x3UL ) << 1; n >>= s; r |= s;
    return (int) (r | (n >> 1));
}

variable_types:
n
unsigned int

variable_types:
r
unsigned int

variable_types:
s
unsigned int


decompiled_code:
_BOOL8 __fastcall ispow2(int a1)
{
bool v1; // al

v1 = 0;
if ( a1 )
v1 = (a1 & (a1 - 1)) == 0;
return v1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(int a1)
{
bool v1; // al

v1 = 0;
if ( a1 )
v1 = (a1 & (a1 - 1)) == 0;
return v1;
}

original_code:
static inline _Bool ispow2(unsigned int n)
{
    return n && !(n & (n - 1));
}


circle

decompiled_code:
float __fastcall circle(float a1, float a2)
{
float result; // xmm0_4

if ( a2 > a1 )
result = *(float *)&LC0;
else
result = 0.0;
return result;
}

canonical_decompiled_code:
float __fastcall func1(float a1, float a2)
{
float result; // xmm0_4

if ( a2 > a1 )
result = *(float *)&LC0;
else
result = 0.0;
return result;
}

original_code:
static float circle(float dd, float rr)
{
    return dd < rr ? 1.f : 0.f;
}

variable_types: dd float

variable_types: rr float


calc

decompiled_code:
__int64 __fastcall calc(__int64 a1, int a2, float a3)
{
__int64 v4; // [rsp+0h] [rbp-38h] BYREF
float v5; // [rsp+8h] [rbp-30h]
int v6; // [rsp+Ch] [rbp-2Ch]
int v7; // [rsp+10h] [rbp-28h]
__int64 v8; // [rsp+20h] [rbp-18h] BYREF
int v9; // [rsp+28h] [rbp-10h]

v7 = 0;
v6 = a2;
v5 = a3;
v4 = a1;
GOMP_parallel(calc__omp_fn_0, &v4, 0LL, 0LL);
v9 = v7;
v8 = a1;
return GOMP_parallel(calc__omp_fn_1, &v8, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, int a2, float a3)
{
__int64 v4; // [rsp+0h] [rbp-38h] BYREF
float v5; // [rsp+8h] [rbp-30h]
int v6; // [rsp+Ch] [rbp-2Ch]
int v7; // [rsp+10h] [rbp-28h]
__int64 v8; // [rsp+20h] [rbp-18h] BYREF
int v9; // [rsp+28h] [rbp-10h]

v7 = 0;
v6 = a2;
v5 = a3;
v4 = a1;
GOMP_parallel(calc__omp_fn_0, &v4, 0LL, 0LL);
v9 = v7;
v8 = a1;
return GOMP_parallel(calc__omp_fn_1, &v8, 0LL, 0LL);
}

original_code:
static void calc(img *d, float rr, int op)
{
    int r;
    int c;
    int i;
    int j;
    int k;
    float t;
    float T = 0.f;

#pragma omp parallel for private(c, i, j, k, t) reduction(+:T)
    for (r = 0; r < d->h; r++)
        for (c = 0; c < d->w; c++)
            for (i = 0; i < d->s; i++)
                for (j = 0; j < d->s; j++)
                {
                    switch (op)
                    {
                    case 'c': t = circle(dd(d, r, c, i, j), rr); break;
                    case 'g': t = gauss (dd(d, r, c, i, j), rr); break;
                    }
                    T += t;
                    for (k = 0; k < d->p; ++k)
                        imgbuf(d, r, c, i, j)[k] = t;
                }

#pragma omp parallel for private(c, i, j, k)
    for (r = 0; r < d->h; r++)
        for (c = 0; c < d->w; c++)
            for (i = 0; i < d->s; i++)
                for (j = 0; j < d->s; j++)
                    for (k = 0; k < d->p; k++)
                        imgbuf(d, r, c, i, j)[k] /= T;
}

canonical_original_code:
static void calc(struct img *d, float rr, int op)
{
    int r;
    int c;
    int i;
    int j;
    int k;
    float t;
    float T = 0.f;

#pragma omp parallel for private(c, i, j, k, t) reduction(+:T)
    for (r = 0; r < d->h; r++)
        for (c = 0; c < d->w; c++)
            for (i = 0; i < d->s; i++)
                for (j = 0; j < d->s; j++)
                {
                    switch (op)
                    {
                    case 'c': t = circle(dd(d, r, c, i, j), rr); break;
                    case 'g': t = gauss (dd(d, r, c, i, j), rr); break;
                    }
                    T += t;
                    for (k = 0; k < d->p; ++k)
                        imgbuf(d, r, c, i, j)[k] = t;
                }

#pragma omp parallel for private(c, i, j, k)
    for (r = 0; r < d->h; r++)
        for (c = 0; c < d->w; c++)
            for (i = 0; i < d->s; i++)
                for (j = 0; j < d->s; j++)
                    for (k = 0; k < d->p; k++)
                        imgbuf(d, r, c, i, j)[k] /= T;
}

variable_types: op int

variable_types: t float

variable_types: T float


gauss

original_code:
static float gauss(float dd, float rr)
{
    const float a = 1.f / (2.f * 3.14159265358979323846264338327 * rr);
    const float b = -1.f / (2.f * rr);
    return a * expf(dd * b);
}

canonical_original_code:
static float gauss(float dd, float rr)
{
    float a = 1.f / (2.f * 3.14159265358979323846264338327 * rr);
    float b = -1.f / (2.f * rr);
    return a * expf(dd * b);
}

variable_types: a float

variable_types: b float


printhms

canonical_decompiled_code:
int __fastcall func9(double a1)
{
__int64 v1; // rsi
double v2; // xmm0_8
unsigned int v3; // ebx
double v4; // xmm0_8

v1 = (unsigned int)((int)a1 / 3600);
v2 = a1 - (double)(3600 * (int)v1);
v3 = (int)v2 / 60;
v4 = v2 - (double)(int)(60 * v3);
if ( (_DWORD)v1 )
printf("%dh", v1);
if ( v3 )
printf("%dm", v3);
return printf("%.3fs", v4);
}

variable_types: s double


revinit

decompiled_code:
__int64 __fastcall revinit(__int64 a1, int a2, int a3, _DWORD *a4)
{
unsigned int v4; // er12
__int64 result; // rax

if ( a3 == 1 )
{
*a4 = a1;
}
else
{
v4 = a3 / 2;
revinit(a1, (unsigned int)(2 * a2), (unsigned int)(a3 / 2));
result = revinit((unsigned int)(a2 + a1), (unsigned int)(2 * a2), v4);
}
return result;
}

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

if ( a3 == 1 )
{
*a4 = a1;
}
else
{
v4 = a3 / 2;
func0(a1, (unsigned int)(2 * a2), (unsigned int)(a3 / 2));
result = func0((unsigned int)(a2 + a1), (unsigned int)(2 * a2), v4);
}
return result;
}

original_code:
static void revinit(int a, int d, int n, int *x)
{
    if (n == 1)
        *x = a;
    else
    {
        revinit(a, d * 2, n / 2, x );
        revinit(a + d, d * 2, n / 2, x + n / 2);
    }
}

variable_types: a int

variable_types: d int

variable_types: n int

variable_types:
x
int *


offset

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

result = a1;
if ( a3 <= 0 )
result = ((1 << a2) - 1) & ((1 << (a2 - 1)) + a1);
return result;
}

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

result = a1;
if ( a3 <= 0 )
result = ((1 << a2) - 1) & ((1 << (a2 - 1)) + a1);
return result;
}

original_code:
static inline int offset(int x, int m, int s)
{
    if (s > 0)
        return x;
    else
    {
        const int n = 1 << (m - 1);
        const int o = (1 << m) - 1;
        return (x + n) & o;
    }
}

canonical_original_code:
static inline int offset(int x, int m, int s)
{
    if (s > 0)
        return x;
    else
    {
        int n = 1 << (m - 1);
        int o = (1 << m) - 1;
        return (x + n) & o;
    }
}

variable_types: x int

variable_types: m int

variable_types: s int

variable_types: o int


printhms

canonical_decompiled_code:
int __fastcall func13(double a1)
{
__int64 v1; // rsi
double v2; // xmm0_8
unsigned int v3; // ebx
double v4; // xmm0_8

v1 = (unsigned int)((int)a1 / 3600);
v2 = a1 - (double)(3600 * (int)v1);
v3 = (int)v2 / 60;
v4 = v2 - (double)(int)(60 * v3);
if ( (_DWORD)v1 )
printf("%dh", v1);
if ( v3 )
printf("%dm", v3);
return printf("%.3fs", v4);
}

variable_types: h int


setexe

decompiled_code:
void __fastcall setexe(__int64 a1)
{
executable = a1;
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1)
{
executable = a1;
}

original_code:
void setexe(const char *str)
{
    executable = str;
}

canonical_original_code:
void setexe(char *str)
{
    executable = str;
}

variable_types:
str
char *


printerr

decompiled_code:
int printerr(const char *a1, unsigned int a2, int a3, const char *a4, ...)
{
char *v6; // rax
gcc_va_list arg; // [rsp+8h] [rbp-F0h] BYREF

va_start(arg, a4);
if ( executable )
fprintf(stderr, "%s ", (const char *)executable);
if ( a1 && a2 )
{
fprintf(stderr, "(%s:%d) : ", a1, a2);
}
else if ( a1 )
{
fprintf(stderr, "(%s) : ", a1);
}
else if ( a2 )
{
fprintf(stderr, "(%d) : ", a2);
}
if ( a4 )
vfprintf(stderr, a4, arg);
if ( !a3 )
return fputc(10, stderr);
v6 = strerror(a3);
return fprintf(stderr, " : %s\n", v6);
}

canonical_decompiled_code:
int func1(const char *a1, unsigned int a2, int a3, const char *a4, ...)
{
char *v6; // rax
gcc_va_list arg; // [rsp+8h] [rbp-F0h] BYREF

va_start(arg, a4);
if ( executable )
fprintf(stderr, "%s ", (const char *)executable);
if ( a1 && a2 )
{
fprintf(stderr, "(%s:%d) : ", a1, a2);
}
else if ( a1 )
{
fprintf(stderr, "(%s) : ", a1);
}
else if ( a2 )
{
fprintf(stderr, "(%d) : ", a2);
}
if ( a4 )
vfprintf(stderr, a4, arg);
if ( !a3 )
return fputc(10, stderr);
v6 = strerror(a3);
return fprintf(stderr, " : %s\n", v6);
}

original_code:
void printerr(const char *file, int line, int err, const char *fmt, ...)
{
    va_list ap;
    __builtin_va_start(ap,fmt);
    {
        if (executable)
            fprintf(stderr, "%s ", executable);
        if (file && line)
            fprintf(stderr, "(%s:%d) : ", file, line);
        else if (file)
            fprintf(stderr, "(%s) : ", file);
        else if (line)
            fprintf(stderr, "(%d) : ", line);
        if (fmt)
           vfprintf(stderr, fmt, ap);
        if (err)
            fprintf(stderr, " : %s\n", strerror(err));
        else
            fprintf(stderr, "\n");
    }
    __builtin_va_end(ap);
}

canonical_original_code:
void printerr(char *file, int line, int err, char *fmt, ...)
{
    __builtin_va_list ap;
    __builtin_va_start(ap,fmt);
    {
        if (executable)
            fprintf(stderr, "%s ", executable);
        if (file && line)
            fprintf(stderr, "(%s:%d) : ", file, line);
        else if (file)
            fprintf(stderr, "(%s) : ", file);
        else if (line)
            fprintf(stderr, "(%d) : ", line);
        if (fmt)
           vfprintf(stderr, fmt, ap);
        if (err)
            fprintf(stderr, " : %s\n", strerror(err));
        else
            fprintf(stderr, "\n");
    }
    __builtin_va_end(ap);
}

variable_types:
file
char *

variable_types: line int

variable_types: err int

variable_types:
fmt
char *


in

repo: rlk/lightprobe

decompiled_code:
__int64 __fastcall in(int a1)
{
return i_0[a1];
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
return i_0[a1];
}

original_code:
static GLenum in(int c)
{
    static const GLenum i[] = { 0, 0x822E, 0x8230, 0x8815, 0x8814 };
    return i[c];
}

canonical_original_code:
static unsigned int in(int c)
{
    static unsigned int i[] = { 0, 0x822E, 0x8230, 0x8815, 0x8814 };
    return i[c];
}

variable_types: c int

variable_types:
i
unsigned int []

return_type: unsigned int


ex

decompiled_code:
__int64 __fastcall ex(int a1)
{
return e_1[a1];
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
return e_1[a1];
}

original_code:
static GLenum ex(int c)
{
    static const GLenum e[] = { 0, 0x2002, 0x8227, 0x1907, 0x1908 };
    return e[c];
}

canonical_original_code:
static unsigned int ex(int c)
{
    static unsigned int e[] = { 0, 0x2002, 0x8227, 0x1907, 0x1908 };
    return e[c];
}

variable_types:
e
unsigned int []


decompiled_code:
size_t test_framebuffer()
{
unsigned int v0; // eax
size_t result; // rax

v0 = _glewCheckFramebufferStatus(36160LL);
if ( v0 > 0x8CDD )
{
if ( v0 == 36182 )
return fwrite("Framebuffer incomplete multisample\n", 1uLL, 0x23uLL, stderr);
return fwrite("Framebuffer error\n", 1uLL, 0x12uLL, stderr);
}
if ( v0 <= 0x8CD4 )
{
if ( v0 == 33305 )
return fwrite("Framebuffer undefined\n", 1uLL, 0x16uLL, stderr);
return fwrite("Framebuffer error\n", 1uLL, 0x12uLL, stderr);
}
result = v0 - 36053;
switch ( (int)result )
{
case 0:
return result;
case 1:
result = fwrite("Framebuffer incomplete attachment\n", 1uLL, 0x22uLL, stderr);
break;
case 2:
result = fwrite("Framebuffer incomplete missing attachment\n", 1uLL, 0x2AuLL, stderr);
break;
case 6:
result = fwrite("Framebuffer incomplete draw buffer\n", 1uLL, 0x23uLL, stderr);
break;
case 7:
result = fwrite("Framebuffer incomplete read buffer\n", 1uLL, 0x23uLL, stderr);
break;
case 8:
result = fwrite("Framebuffer unsupported\n", 1uLL, 0x18uLL, stderr);
break;
default:
return fwrite("Framebuffer error\n", 1uLL, 0x12uLL, stderr);
}
return result;
}

canonical_decompiled_code:
size_t func3()
{
unsigned int v0; // eax
size_t result; // rax

v0 = _glewCheckFramebufferStatus(36160LL);
if ( v0 > 0x8CDD )
{
if ( v0 == 36182 )
return fwrite("Framebuffer incomplete multisample\n", 1uLL, 0x23uLL, stderr);
return fwrite("Framebuffer error\n", 1uLL, 0x12uLL, stderr);
}
if ( v0 <= 0x8CD4 )
{
if ( v0 == 33305 )
return fwrite("Framebuffer undefined\n", 1uLL, 0x16uLL, stderr);
return fwrite("Framebuffer error\n", 1uLL, 0x12uLL, stderr);
}
result = v0 - 36053;
switch ( (int)result )
{
case 0:
return result;
case 1:
result = fwrite("Framebuffer incomplete attachment\n", 1uLL, 0x22uLL, stderr);
break;
case 2:
result = fwrite("Framebuffer incomplete missing attachment\n", 1uLL, 0x2AuLL, stderr);
break;
case 6:
result = fwrite("Framebuffer incomplete draw buffer\n", 1uLL, 0x23uLL, stderr);
break;
case 7:
result = fwrite("Framebuffer incomplete read buffer\n", 1uLL, 0x23uLL, stderr);
break;
case 8:
result = fwrite("Framebuffer unsupported\n", 1uLL, 0x18uLL, stderr);
break;
default:
return fwrite("Framebuffer error\n", 1uLL, 0x12uLL, stderr);
}
return result;
}

original_code:
static void test_framebuffer()
{
    switch (__glewCheckFramebufferStatus(0x8D40))
    {
    case 0x8CD5:
        break;
    case 0x8219:
        fprintf(stderr, "Framebuffer undefined\n"); break;
    case 0x8CD6:
        fprintf(stderr, "Framebuffer incomplete attachment\n"); break;
    case 0x8CD7:
        fprintf(stderr, "Framebuffer incomplete missing attachment\n"); break;
    case 0x8CDB:
        fprintf(stderr, "Framebuffer incomplete draw buffer\n"); break;
    case 0x8CDC:
        fprintf(stderr, "Framebuffer incomplete read buffer\n"); break;
    case 0x8CDD:
        fprintf(stderr, "Framebuffer unsupported\n"); break;
    case 0x8D56:
        fprintf(stderr, "Framebuffer incomplete multisample\n"); break;
    default:
        fprintf(stderr, "Framebuffer error\n"); break;
    }
}


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

if ( *a1 != a2 || a1[1] != a3 || a1[2] != a4 )
{
size_color(0x84F5u, a1[4], a2, a3, a4);
*a1 = a2;
a1[1] = a3;
a1[2] = a4;
_glewBindFramebuffer(36160LL, a1[3]);
_glewFramebufferTexture2D(36160LL, 36064LL, 34037LL, a1[4], 0LL);
test_framebuffer();
result = _glewBindFramebuffer(36160LL, 0LL);
}
return result;
}

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

if ( *a1 != a2 || a1[1] != a3 || a1[2] != a4 )
{
func2(0x84F5u, a1[4], a2, a3, a4);
*a1 = a2;
a1[1] = a3;
a1[2] = a4;
_glewBindFramebuffer(36160LL, a1[3]);
_glewFramebufferTexture2D(36160LL, 36064LL, 34037LL, a1[4], 0LL);
func3();
result = _glewBindFramebuffer(36160LL, 0LL);
}
return result;
}

original_code:
void gl_size_framebuffer(gl_framebuffer *F, GLsizei w, GLsizei h, GLsizei c)
{
    if (F->w != w || F->h != h || F->c != c)
    {
        GLenum target = 0x84F5;
        size_color(target, F->color, w, h, c);
        F->w = w;
        F->h = h;
        F->c = c;
        __glewBindFramebuffer(0x8D40, F->frame);
        {
            __glewFramebufferTexture2D(0x8D40,
                                   0x8CE0, target, F->color, 0);
            test_framebuffer();
        }
        __glewBindFramebuffer(0x8D40, 0);
    }
}

canonical_original_code:
void gl_size_framebuffer(struct gl_framebuffer *F, int w, int h, int c)
{
    if (F->w != w || F->h != h || F->c != c)
    {
        unsigned int target = 0x84F5;
        size_color(target, F->color, w, h, c);
        F->w = w;
        F->h = h;
        F->c = c;
        __glewBindFramebuffer(0x8D40, F->frame);
        {
            __glewFramebufferTexture2D(0x8D40,
                                   0x8CE0, target, F->color, 0);
            test_framebuffer();
        }
        __glewBindFramebuffer(0x8D40, 0);
    }
}

variable_types: struct gl_framebuffer { int w; int h; int c; unsigned int frame; unsigned int color; unsigned int depth; } *

variable_types: w int

variable_types:
target
unsigned int


decompiled_code:
char __fastcall gl_init_framebuffer(unsigned int *a1, unsigned int a2, unsigned int a3, int a4)
{
char result; // al

_glewGenFramebuffers(1LL, a1 + 3);
glGenTextures(1LL, a1 + 4);
*a1 = 0;
a1[1] = 0;
a1[2] = 0;
result = a4 != 0;
if ( a4 != 0 && a3 != 0 )
{
if ( a2 )
result = gl_size_framebuffer(a1, a2, a3, a4);
}
return result;
}

canonical_decompiled_code:
char __fastcall func5(unsigned int *a1, unsigned int a2, unsigned int a3, int a4)
{
char result; // al

_glewGenFramebuffers(1LL, a1 + 3);
glGenTextures(1LL, a1 + 4);
*a1 = 0;
a1[1] = 0;
a1[2] = 0;
result = a4 != 0;
if ( a4 != 0 && a3 != 0 )
{
if ( a2 )
result = func4(a1, a2, a3, a4);
}
return result;
}

original_code:
void gl_init_framebuffer(gl_framebuffer *F, GLsizei w, GLsizei h, GLsizei c)
{
    __glewGenFramebuffers(1, &F->frame);
    glGenTextures (1, &F->color);
    F->w = 0;
    F->h = 0;
    F->c = 0;
    if (w && h && c) gl_size_framebuffer(F, w, h, c);
}

canonical_original_code:
void gl_init_framebuffer(struct gl_framebuffer *F, int w, int h, int c)
{
    __glewGenFramebuffers(1, &F->frame);
    glGenTextures (1, &F->color);
    F->w = 0;
    F->h = 0;
    F->c = 0;
    if (w && h && c) gl_size_framebuffer(F, w, h, c);
}

user_defined_types: struct gl_framebuffer { int w; int h; int c; unsigned int frame; unsigned int color; unsigned int depth; }


decompiled_code:
__int64 __fastcall gl_free_framebuffer(__int64 a1)
{
glDeleteTextures(1LL, a1 + 16);
return _glewDeleteFramebuffers(1LL, a1 + 12);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
glDeleteTextures(1LL, a1 + 16);
return _glewDeleteFramebuffers(1LL, a1 + 12);
}

original_code:
void gl_free_framebuffer(gl_framebuffer *F)
{
    glDeleteTextures (1, &F->color);
    __glewDeleteFramebuffers(1, &F->frame);
}

canonical_original_code:
void gl_free_framebuffer(struct gl_framebuffer *F)
{
    glDeleteTextures (1, &F->color);
    __glewDeleteFramebuffers(1, &F->frame);
}


decompiled_code:
void *__fastcall gl_copy_framebuffer(unsigned int *a1, int a2)
{
void *v2; // r12
unsigned int v3; // eax

_glewBindFramebuffer(36160LL, a1[3]);
v2 = malloc(4LL * (int)(a2 * a1[1] * *a1));
if ( v2 )
{
glReadBuffer(1028LL);
v3 = ex(a2);
glReadPixels(0LL, 0LL, *a1, a1[1], v3, 5126LL, v2);
}
_glewBindFramebuffer(36160LL, 0LL);
return v2;
}

canonical_decompiled_code:
void *__fastcall func7(unsigned int *a1, int a2)
{
void *v2; // r12
unsigned int v3; // eax

_glewBindFramebuffer(36160LL, a1[3]);
v2 = malloc(4LL * (int)(a2 * a1[1] * *a1));
if ( v2 )
{
glReadBuffer(1028LL);
v3 = func1(a2);
glReadPixels(0LL, 0LL, *a1, a1[1], v3, 5126LL, v2);
}
_glewBindFramebuffer(36160LL, 0LL);
return v2;
}

original_code:
void *gl_copy_framebuffer(gl_framebuffer *F, GLint c)
{
    GLubyte *p = 0;
    __glewBindFramebuffer(0x8D40, F->frame);
    {
        if ((p = (GLubyte *) malloc(F->w * F->h * c * sizeof (GLfloat))))
        {
            glReadBuffer(0x0404);
            glReadPixels(0, 0, F->w, F->h, ex(c), 0x1406, p);
        }
    }
    __glewBindFramebuffer(0x8D40, 0);
    return p;
}

canonical_original_code:
void *gl_copy_framebuffer(struct gl_framebuffer *F, int c)
{
    unsigned char *p = 0;
    __glewBindFramebuffer(0x8D40, F->frame);
    {
        if ((p = (unsigned char *) malloc(F->w * F->h * c * sizeof (GLfloat))))
        {
            glReadBuffer(0x0404);
            glReadPixels(0, 0, F->w, F->h, ex(c), 0x1406, p);
        }
    }
    __glewBindFramebuffer(0x8D40, 0);
    return p;
}

variable_types:
p
unsigned char *


decompiled_code:
__int64 __fastcall check_shader_log(__int64 a1, const char *a2)
{
const char *v2; // r12
unsigned int v3; // ebp
unsigned int v5; // er15
char *v6; // rax
char *v7; // r14
unsigned int v8; // [rsp+8h] [rbp-40h] BYREF
unsigned int v9[15]; // [rsp+Ch] [rbp-3Ch] BYREF

v2 = "vertex";
if ( (_DWORD)a1 != 35633 )
v2 = "fragment";
v9[0] = 0;
v8 = 0;
_glewGetShaderiv(a1, 35713LL, v9);
_glewGetShaderiv((unsigned int)a1, 35716LL, &v8);
v3 = v9[0];
if ( v9[0] )
return 1;
v5 = v8;
v6 = (char *)calloc((int)(v8 + 1), 1uLL);
v7 = v6;
if ( v6 )
{
_glewGetShaderInfoLog((unsigned int)a1, v5, 0LL, v6);
fprintf(stderr, "OpenGL %s shader error:\n%s\n%s", v2, v7, a2);
free(v7);
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, const char *a2)
{
const char *v2; // r12
unsigned int v3; // ebp
unsigned int v5; // er15
char *v6; // rax
char *v7; // r14
unsigned int v8; // [rsp+8h] [rbp-40h] BYREF
unsigned int v9[15]; // [rsp+Ch] [rbp-3Ch] BYREF

v2 = "vertex";
if ( (_DWORD)a1 != 35633 )
v2 = "fragment";
v9[0] = 0;
v8 = 0;
_glewGetShaderiv(a1, 35713LL, v9);
_glewGetShaderiv((unsigned int)a1, 35716LL, &v8);
v3 = v9[0];
if ( v9[0] )
return 1;
v5 = v8;
v6 = (char *)calloc((int)(v8 + 1), 1uLL);
v7 = v6;
if ( v6 )
{
_glewGetShaderInfoLog((unsigned int)a1, v5, 0LL, v6);
fprintf(stderr, "OpenGL %s shader error:\n%s\n%s", v2, v7, a2);
free(v7);
}
return v3;
}

original_code:
static int check_shader_log(GLuint shader, const unsigned char *glsl)
{
    const char *type = (shader == 0x8B31) ? "vertex" : "fragment";
    GLchar *p = 0;
    GLint s = 0;
    GLint n = 0;
    __glewGetShaderiv(shader, 0x8B81, &s);
    __glewGetShaderiv(shader, 0x8B84, &n);
    if (s == 0)
    {
        if ((p = (GLchar *) calloc(n + 1, 1)))
        {
            __glewGetShaderInfoLog(shader, n, ((void *)0), p);
            fprintf(stderr, "OpenGL %s shader error:\n%s\n%s", type, p, glsl);
            free(p);
        }
        return 0;
    }
    return 1;
}

canonical_original_code:
static int check_shader_log(unsigned int shader, unsigned char *glsl)
{
    char *type = (shader == 0x8B31) ? "vertex" : "fragment";
    char *p = 0;
    int s = 0;
    int n = 0;
    __glewGetShaderiv(shader, 0x8B81, &s);
    __glewGetShaderiv(shader, 0x8B84, &n);
    if (s == 0)
    {
        if ((p = (char *) calloc(n + 1, 1)))
        {
            __glewGetShaderInfoLog(shader, n, ((void *)0), p);
            fprintf(stderr, "OpenGL %s shader error:\n%s\n%s", type, p, glsl);
            free(p);
        }
        return 0;
    }
    return 1;
}

variable_types:
shader
unsigned int

variable_types:
glsl
unsigned char *

variable_types:
type
char *

variable_types:
p
char *

variable_types: n int


decompiled_code:
__int64 __fastcall load_shader(__int64 a1, const char *a2, int a3)
{
__int64 v3; // rbx
int v5; // [rsp+4h] [rbp-14h] BYREF
const char *v6; // [rsp+8h] [rbp-10h] BYREF

v6 = a2;
v5 = a3;
v3 = (unsigned int)_glewCreateShader();
_glewShaderSource(v3, 1LL, &v6, &v5);
_glewCompileShader((unsigned int)v3);
if ( !(unsigned int)check_shader_log((unsigned int)v3, v6) )
{
_glewDeleteShader((unsigned int)v3);
LODWORD(v3) = 0;
}
return (unsigned int)v3;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, const char *a2, int a3)
{
__int64 v3; // rbx
int v5; // [rsp+4h] [rbp-14h] BYREF
const char *v6; // [rsp+8h] [rbp-10h] BYREF

v6 = a2;
v5 = a3;
v3 = (unsigned int)_glewCreateShader();
_glewShaderSource(v3, 1LL, &v6, &v5);
_glewCompileShader((unsigned int)v3);
if ( !(unsigned int)func0((unsigned int)v3, v6) )
{
_glewDeleteShader((unsigned int)v3);
LODWORD(v3) = 0;
}
return (unsigned int)v3;
}

original_code:
static GLuint load_shader(GLenum type, const unsigned char *str,
                                             unsigned int len)
{
    GLuint shader = __glewCreateShader(type);
    __glewShaderSource (shader, 1, (const GLchar **) &str,
                               (const GLint *) &len);
    __glewCompileShader(shader);
    if (check_shader_log(shader, str))
        return shader;
    else
        __glewDeleteShader(shader);
    return 0;
}

canonical_original_code:
static unsigned int load_shader(unsigned int type, unsigned char *str, unsigned int len)
{
    unsigned int shader = __glewCreateShader(type);
    __glewShaderSource (shader, 1, (char **) &str,
                               (int *) &len);
    __glewCompileShader(shader);
    if (check_shader_log(shader, str))
        return shader;
    else
        __glewDeleteShader(shader);
    return 0;
}

variable_types:
type
unsigned int

variable_types:
str
unsigned char *

variable_types:
len
unsigned int


decompiled_code:
__int64 __fastcall check_program_log(__int64 a1)
{
unsigned int v1; // ebp
unsigned int v3; // er13
char *v4; // rax
char *v5; // r12
unsigned int v6; // [rsp+8h] [rbp-30h] BYREF
unsigned int v7[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v7[0] = 0;
v6 = 0;
_glewGetProgramiv(a1, 35714LL, v7);
_glewGetProgramiv((unsigned int)a1, 35716LL, &v6);
v1 = v7[0];
if ( v7[0] )
return 1;
v3 = v6;
v4 = (char *)calloc((int)(v6 + 1), 1uLL);
v5 = v4;
if ( v4 )
{
_glewGetProgramInfoLog((unsigned int)a1, v3, 0LL, v4);
fprintf(stderr, "OpenGL program linker error:\n%s", v5);
free(v5);
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
unsigned int v1; // ebp
unsigned int v3; // er13
char *v4; // rax
char *v5; // r12
unsigned int v6; // [rsp+8h] [rbp-30h] BYREF
unsigned int v7[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v7[0] = 0;
v6 = 0;
_glewGetProgramiv(a1, 35714LL, v7);
_glewGetProgramiv((unsigned int)a1, 35716LL, &v6);
v1 = v7[0];
if ( v7[0] )
return 1;
v3 = v6;
v4 = (char *)calloc((int)(v6 + 1), 1uLL);
v5 = v4;
if ( v4 )
{
_glewGetProgramInfoLog((unsigned int)a1, v3, 0LL, v4);
fprintf(stderr, "OpenGL program linker error:\n%s", v5);
free(v5);
}
return v1;
}

original_code:
static int check_program_log(GLuint program)
{
    GLchar *p = 0;
    GLint s = 0;
    GLint n = 0;
    __glewGetProgramiv(program, 0x8B82, &s);
    __glewGetProgramiv(program, 0x8B84, &n);
    if (s == 0)
    {
        if ((p = (GLchar *) calloc(n + 1, 1)))
        {
            __glewGetProgramInfoLog(program, n, ((void *)0), p);
            fprintf(stderr, "OpenGL program linker error:\n%s", p);
            free(p);
        }
        return 0;
    }
    return 1;
}

canonical_original_code:
static int check_program_log(unsigned int program)
{
    char *p = 0;
    int s = 0;
    int n = 0;
    __glewGetProgramiv(program, 0x8B82, &s);
    __glewGetProgramiv(program, 0x8B84, &n);
    if (s == 0)
    {
        if ((p = (char *) calloc(n + 1, 1)))
        {
            __glewGetProgramInfoLog(program, n, ((void *)0), p);
            fprintf(stderr, "OpenGL program linker error:\n%s", p);
            free(p);
        }
        return 0;
    }
    return 1;
}

variable_types:
program
unsigned int

variable_types: s int


decompiled_code:
__int64 __fastcall gl_load_vshader(const char *a1, int a2)
{
return load_shader(35633LL, a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func3(const char *a1, int a2)
{
return func1(35633LL, a1, a2);
}

original_code:
GLuint gl_load_vshader(const unsigned char *str, unsigned int len)
{
    return load_shader(0x8B31, str, len);
}

canonical_original_code:
unsigned int gl_load_vshader(unsigned char *str, unsigned int len)
{
    return load_shader(0x8B31, str, len);
}


decompiled_code:
__int64 __fastcall gl_load_fshader(const char *a1, int a2)
{
return load_shader(35632LL, a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func4(const char *a1, int a2)
{
return func1(35632LL, a1, a2);
}

original_code:
GLuint gl_load_fshader(const unsigned char *str, unsigned int len)
{
    return load_shader(0x8B30, str, len);
}

canonical_original_code:
unsigned int gl_load_fshader(unsigned char *str, unsigned int len)
{
    return load_shader(0x8B30, str, len);
}


decompiled_code:
__int64 __fastcall gl_load_program(unsigned int a1, unsigned int a2)
{
__int64 v2; // rbx

if ( a1 && a2 )
{
v2 = (unsigned int)_glewCreateProgram();
_glewAttachShader(v2, a1);
_glewAttachShader((unsigned int)v2, a2);
_glewLinkProgram((unsigned int)v2);
if ( !(unsigned int)check_program_log((unsigned int)v2) )
{
_glewDeleteProgram((unsigned int)v2);
LODWORD(v2) = 0;
}
}
else
{
LODWORD(v2) = 0;
}
return (unsigned int)v2;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int a1, unsigned int a2)
{
__int64 v2; // rbx

if ( a1 && a2 )
{
v2 = (unsigned int)_glewCreateProgram();
_glewAttachShader(v2, a1);
_glewAttachShader((unsigned int)v2, a2);
_glewLinkProgram((unsigned int)v2);
if ( !(unsigned int)func2((unsigned int)v2) )
{
_glewDeleteProgram((unsigned int)v2);
LODWORD(v2) = 0;
}
}
else
{
LODWORD(v2) = 0;
}
return (unsigned int)v2;
}

original_code:
GLuint gl_load_program(GLuint vert_shader, GLuint frag_shader)
{
    if (vert_shader && frag_shader)
    {
        GLuint program = __glewCreateProgram();
        __glewAttachShader(program, vert_shader);
        __glewAttachShader(program, frag_shader);
        __glewLinkProgram(program);
        if (check_program_log(program))
            return program;
        else
            __glewDeleteProgram(program);
    }
    return 0;
}

canonical_original_code:
unsigned int gl_load_program(unsigned int vert_shader, unsigned int frag_shader)
{
    if (vert_shader && frag_shader)
    {
        unsigned int program = __glewCreateProgram();
        __glewAttachShader(program, vert_shader);
        __glewAttachShader(program, frag_shader);
        __glewLinkProgram(program);
        if (check_program_log(program))
            return program;
        else
            __glewDeleteProgram(program);
    }
    return 0;
}


decompiled_code:
__int64 __fastcall gl_init_program(_DWORD *a1, const char *a2, int a3, const char *a4, int a5)
{
unsigned int v7; // eax
__int64 result; // rax

a1[1] = gl_load_vshader(a2, a3);
v7 = gl_load_fshader(a4, a5);
a1[2] = v7;
result = gl_load_program(a1[1], v7);
*a1 = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(_DWORD *a1, const char *a2, int a3, const char *a4, int a5)
{
unsigned int v7; // eax
__int64 result; // rax

a1[1] = func3(a2, a3);
v7 = func4(a4, a5);
a1[2] = v7;
result = func5(a1[1], v7);
*a1 = result;
return result;
}

original_code:
void gl_init_program(gl_program *P,
                     const unsigned char *vstr, unsigned int vlen,
                     const unsigned char *fstr, unsigned int flen)
{
    P->vshader = gl_load_vshader(vstr, vlen);
    P->fshader = gl_load_fshader(fstr, flen);
    P->program = gl_load_program(P->vshader, P->fshader);
}

canonical_original_code:
void gl_init_program(struct gl_program *P, unsigned char *vstr, unsigned int vlen, unsigned char *fstr, unsigned int flen)
{
    P->vshader = gl_load_vshader(vstr, vlen);
    P->fshader = gl_load_fshader(fstr, flen);
    P->program = gl_load_program(P->vshader, P->fshader);
}

variable_types: struct gl_program { unsigned int program; unsigned int vshader; unsigned int fshader; } *

variable_types:
vstr
unsigned char *

variable_types:
vlen
unsigned int

variable_types:
fstr
unsigned char *

variable_types:
flen
unsigned int


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

_glewDeleteProgram(*a1);
_glewDeleteShader(a1[1]);
result = _glewDeleteShader(a1[2]);
*a1 = 0;
a1[1] = 0;
a1[2] = 0;
return result;
}

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

_glewDeleteProgram(*a1);
_glewDeleteShader(a1[1]);
result = _glewDeleteShader(a1[2]);
*a1 = 0;
a1[1] = 0;
a1[2] = 0;
return result;
}

original_code:
void gl_free_program(gl_program *P)
{
    __glewDeleteProgram(P->program);
    __glewDeleteShader(P->vshader);
    __glewDeleteShader(P->fshader);
    P->program = 0;
    P->vshader = 0;
    P->fshader = 0;
}

canonical_original_code:
void gl_free_program(struct gl_program *P)
{
    __glewDeleteProgram(P->program);
    __glewDeleteShader(P->vshader);
    __glewDeleteShader(P->fshader);
    P->program = 0;
    P->vshader = 0;
    P->fshader = 0;
}

user_defined_types: struct gl_program { unsigned int program; unsigned int vshader; unsigned int fshader; }


decompiled_code:
__int64 __fastcall gl_uniform1i(unsigned int *a1, __int64 a2, unsigned int a3)
{
__int64 (__fastcall *v4)(_QWORD, _QWORD); // rbp
unsigned int v5; // eax

v4 = (__int64 (__fastcall *)(_QWORD, _QWORD))_glewUniform1i;
v5 = _glewGetUniformLocation(*a1);
return v4(v5, a3);
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int *a1, __int64 a2, unsigned int a3)
{
__int64 (__fastcall *v4)(_QWORD, _QWORD); // rbp
unsigned int v5; // eax

v4 = (__int64 (__fastcall *)(_QWORD, _QWORD))_glewUniform1i;
v5 = _glewGetUniformLocation(*a1);
return v4(v5, a3);
}

original_code:
void gl_uniform1i(const gl_program *P, const GLchar *name, GLint a)
{
    __glewUniform1i(__glewGetUniformLocation(P->program, name), a);
}

canonical_original_code:
void gl_uniform1i(struct gl_program *P, char *name, int a)
{
    __glewUniform1i(__glewGetUniformLocation(P->program, name), a);
}

variable_types:
name
char *

variable_types: a int


decompiled_code:
__int64 __fastcall gl_uniform1f(unsigned int *a1, float a2)
{
__int64 (__fastcall *v2)(_QWORD, float); // rbx
unsigned int v3; // eax

v2 = (__int64 (__fastcall *)(_QWORD, float))_glewUniform1f;
v3 = _glewGetUniformLocation(*a1);
return v2(v3, a2);
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned int *a1, float a2)
{
__int64 (__fastcall *v2)(_QWORD, float); // rbx
unsigned int v3; // eax

v2 = (__int64 (__fastcall *)(_QWORD, float))_glewUniform1f;
v3 = _glewGetUniformLocation(*a1);
return v2(v3, a2);
}

original_code:
void gl_uniform1f(const gl_program *P, const GLchar *name, GLfloat a)
{
    __glewUniform1f(__glewGetUniformLocation(P->program, name), a);
}

canonical_original_code:
void gl_uniform1f(struct gl_program *P, char *name, float a)
{
    __glewUniform1f(__glewGetUniformLocation(P->program, name), a);
}

variable_types: a float


decompiled_code:
__int64 __fastcall gl_uniform2f(unsigned int *a1, float a2, float a3)
{
__int64 (__fastcall *v3)(_QWORD, float, float); // rbx
unsigned int v4; // eax

v3 = (__int64 (__fastcall *)(_QWORD, float, float))_glewUniform2f;
v4 = _glewGetUniformLocation(*a1);
return v3(v4, a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned int *a1, float a2, float a3)
{
__int64 (__fastcall *v3)(_QWORD, float, float); // rbx
unsigned int v4; // eax

v3 = (__int64 (__fastcall *)(_QWORD, float, float))_glewUniform2f;
v4 = _glewGetUniformLocation(*a1);
return v3(v4, a2, a3);
}

original_code:
void gl_uniform2f(const gl_program *P, const GLchar *name, GLfloat a, GLfloat b)
{
    __glewUniform2f(__glewGetUniformLocation(P->program, name), a, b);
}

canonical_original_code:
void gl_uniform2f(struct gl_program *P, char *name, float a, float b)
{
    __glewUniform2f(__glewGetUniformLocation(P->program, name), a, b);
}

variable_types: b float


repo: rlk/scmtiff

original_code:
static inline long long log2i(long long n)
{
    unsigned long long v = (unsigned long long) n;
    unsigned long long r;
    unsigned long long s;
    r = (v > 0xFFFFFFFFULL) << 5; v >>= r;
    s = (v > 0xFFFFULL ) << 4; v >>= s; r |= s;
    s = (v > 0xFFULL ) << 3; v >>= s; r |= s;
    s = (v > 0xFULL ) << 2; v >>= s; r |= s;
    s = (v > 0x3ULL ) << 1; v >>= s; r |= s;
    return (long long) (r | (v >> 1));
}

variable_types:
n
long long

variable_types:
v
unsigned long long

variable_types:
r
unsigned long long

variable_types:
s
unsigned long long

return_type: long long


decompiled_code:
__int64 __fastcall scm_page_count(char a1)
{
return (1LL << (2 * a1 + 3)) - 2;
}

canonical_decompiled_code:
__int64 __fastcall func1(char a1)
{
return (1LL << (2 * a1 + 3)) - 2;
}

original_code:
static inline long long scm_page_count(long long d)
{
    return (1LL << (2 * d + 3)) - 2;
}

variable_types:
d
long long


decompiled_code:
__int64 __fastcall scm_page_level(__int64 a1)
{
return (log2i(a1 + 2) - 1) / 2;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
return (func0(a1 + 2) - 1) / 2;
}

original_code:
static inline long long scm_page_level(long long i)
{
    return (log2i(i + 2) - 1) / 2;
}

variable_types:
i
long long


original_code:
static inline long long scm_page_root(long long i)
{
    long long n = 1LL << (2 * scm_page_level(i));
    return (i - 2 * (n - 1)) / n;
}


original_code:
static inline long long scm_page_rank(long long i)
{
    long long n = 1LL << (2 * scm_page_level(i));
    return (i - 2 * (n - 1)) % n;
}


decompiled_code:
__int64 __fastcall scm_page_row(__int64 a1)
{
__int64 v1; // rbx

v1 = scm_page_rank(a1);
return v1 / (1LL << scm_page_level(a1));
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
__int64 v1; // rbx

v1 = func4(a1);
return v1 / (1LL << func2(a1));
}

original_code:
static inline long long scm_page_row(long long i)
{
    return scm_page_rank(i) / (1LL << scm_page_level(i));
}


decompiled_code:
__int64 __fastcall scm_page_col(__int64 a1)
{
__int64 v1; // rbx

v1 = scm_page_rank(a1);
return v1 % (1LL << scm_page_level(a1));
}

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

v1 = func4(a1);
return v1 % (1LL << func2(a1));
}

original_code:
static inline long long scm_page_col(long long i)
{
    return scm_page_rank(i) % (1LL << scm_page_level(i));
}


decompiled_code:
__int64 __fastcall scm_page_index(__int64 a1, char a2, __int64 a3, __int64 a4)
{
return (a3 << a2) + scm_page_count(a2 - 1) + (a1 << (2 * a2)) + a4;
}

original_code:
static inline long long scm_page_index(long long a, long long l,
                                       long long r, long long c)
{
    return scm_page_count(l - 1) + (a << (2 * l)) + (r << l) + c;
}

variable_types:
a
long long

variable_types:
l
long long

variable_types:
r
long long

variable_types:
c
long long


variable_types:
f
long long

variable_types: y double

variable_types: x double

variable_types:
v
double *

variable_types: s double

variable_types: t double

variable_types:
u
double [3]

variable_types: k double


original_code:
long long scm_page_north(long long i)
{
    long long l = scm_page_level(i);
    long long f = scm_page_root(i);
    long long r = scm_page_row(i);
    long long c = scm_page_col(i);
    long long n = 1LL << l, m = n - 1, t = m - c;
    if (r > 0) { r = r - 1; }
    else if (f == 0) { f = 2; r = t; c = m; }
    else if (f == 1) { f = 2; r = c; c = 0; }
    else if (f == 2) { f = 5; r = 0; c = t; }
    else if (f == 3) { f = 4; r = m; }
    else if (f == 4) { f = 2; r = m; }
    else { f = 2; r = 0; c = t; }
    return scm_page_index(f, l, r, c);
}

canonical_original_code:
long long scm_page_north(long long i)
{
    long long l = scm_page_level(i);
    long long f = scm_page_root(i);
    long long r = scm_page_row(i);
    long long c = scm_page_col(i);
    long long n = 1LL << l; long long m = n - 1; long long t = m - c;
    if (r > 0) { r = r - 1; }
    else if (f == 0) { f = 2; r = t; c = m; }
    else if (f == 1) { f = 2; r = c; c = 0; }
    else if (f == 2) { f = 5; r = 0; c = t; }
    else if (f == 3) { f = 4; r = m; }
    else if (f == 4) { f = 2; r = m; }
    else { f = 2; r = 0; c = t; }
    return scm_page_index(f, l, r, c);
}

variable_types:
n
long long

variable_types:
m
long long

variable_types:
t
long long


original_code:
long long scm_page_south(long long i)
{
    long long l = scm_page_level(i);
    long long f = scm_page_root(i);
    long long r = scm_page_row(i);
    long long c = scm_page_col(i);
    long long n = 1LL << l, m = n - 1, t = m - c;
    if (r < m) { r = r + 1; }
    else if (f == 0) { f = 3; r = c; c = m; }
    else if (f == 1) { f = 3; r = t; c = 0; }
    else if (f == 2) { f = 4; r = 0; }
    else if (f == 3) { f = 5; r = m; c = t; }
    else if (f == 4) { f = 3; r = 0; }
    else { f = 3; r = m; c = t; }
    return scm_page_index(f, l, r, c);
}

canonical_original_code:
long long scm_page_south(long long i)
{
    long long l = scm_page_level(i);
    long long f = scm_page_root(i);
    long long r = scm_page_row(i);
    long long c = scm_page_col(i);
    long long n = 1LL << l; long long m = n - 1; long long t = m - c;
    if (r < m) { r = r + 1; }
    else if (f == 0) { f = 3; r = c; c = m; }
    else if (f == 1) { f = 3; r = t; c = 0; }
    else if (f == 2) { f = 4; r = 0; }
    else if (f == 3) { f = 5; r = m; c = t; }
    else if (f == 4) { f = 3; r = 0; }
    else { f = 3; r = m; c = t; }
    return scm_page_index(f, l, r, c);
}


decompiled_code:
__int64 __fastcall scm_page_west(__int64 a1)
{
char v1; // bp
__int64 v2; // rbx
__int64 v3; // r12
__int64 v4; // rax
__int64 v5; // rcx
__int64 v7; // rax

v1 = scm_page_level(a1);
v2 = scm_page_root(a1);
v3 = scm_page_row(a1);
v4 = scm_page_col(a1);
v5 = v4 - 1;
if ( v4 <= 0 )
{
v5 = (1LL << v1) - 1;
if ( v2 )
{
switch ( v2 )
{
case 1LL:
v2 = 5LL;
break;
case 2LL:
v5 = v3;
v3 = 0LL;
v2 = 1LL;
break;
case 3LL:
v7 = v5 - v3;
v3 = (1LL << v1) - 1;
v5 = v7;
v2 = 1LL;
break;
default:
v2 = v2 == 4;
break;
}
}
else
{
v2 = 4LL;
}
}
return scm_page_index(v2, v1, v3, v5);
}

original_code:
long long scm_page_west(long long i)
{
    long long l = scm_page_level(i);
    long long f = scm_page_root(i);
    long long r = scm_page_row(i);
    long long c = scm_page_col(i);
    long long n = 1LL << l, m = n - 1, t = m - r;
    if (c > 0) { c = c - 1; }
    else if (f == 0) { f = 4; c = m; }
    else if (f == 1) { f = 5; c = m; }
    else if (f == 2) { f = 1; c = r; r = 0; }
    else if (f == 3) { f = 1; c = t; r = m; }
    else if (f == 4) { f = 1; c = m; }
    else { f = 0; c = m; }
    return scm_page_index(f, l, r, c);
}

canonical_original_code:
long long scm_page_west(long long i)
{
    long long l = scm_page_level(i);
    long long f = scm_page_root(i);
    long long r = scm_page_row(i);
    long long c = scm_page_col(i);
    long long n = 1LL << l; long long m = n - 1; long long t = m - r;
    if (c > 0) { c = c - 1; }
    else if (f == 0) { f = 4; c = m; }
    else if (f == 1) { f = 5; c = m; }
    else if (f == 2) { f = 1; c = r; r = 0; }
    else if (f == 3) { f = 1; c = t; r = m; }
    else if (f == 4) { f = 1; c = m; }
    else { f = 0; c = m; }
    return scm_page_index(f, l, r, c);
}


decompiled_code:
__int64 __fastcall scm_page_east(__int64 a1)
{
char v1; // r12
__int64 v2; // rbp
__int64 v3; // r13
__int64 v4; // rax
__int64 v5; // rdx
__int64 v6; // rcx

v1 = scm_page_level(a1);
v2 = scm_page_root(a1);
v3 = scm_page_row(a1);
v4 = scm_page_col(a1);
v5 = (1LL << v1) - 1;
v6 = v4 + 1;
if ( v4 >= v5 )
{
if ( v2 )
{
switch ( v2 )
{
case 1LL:
v6 = 0LL;
v2 = 4LL;
break;
case 2LL:
v6 = v5 - v3;
v3 = 0LL;
v2 = 0LL;
break;
case 3LL:
v6 = v3;
v3 = (1LL << v1) - 1;
v2 = 0LL;
break;
default:
v2 = v2 != 4;
v6 = 0LL;
break;
}
}
else
{
v6 = 0LL;
v2 = 5LL;
}
}
return scm_page_index(v2, v1, v3, v6);
}

original_code:
long long scm_page_east(long long i)
{
    long long l = scm_page_level(i);
    long long f = scm_page_root(i);
    long long r = scm_page_row(i);
    long long c = scm_page_col(i);
    long long n = 1LL << l, m = n - 1, t = m - r;
    if (c < m) { c = c + 1; }
    else if (f == 0) { f = 5; c = 0; }
    else if (f == 1) { f = 4; c = 0; }
    else if (f == 2) { f = 0; c = t; r = 0; }
    else if (f == 3) { f = 0; c = r; r = m; }
    else if (f == 4) { f = 0; c = 0; }
    else { f = 1; c = 0; }
    return scm_page_index(f, l, r, c);
}

canonical_original_code:
long long scm_page_east(long long i)
{
    long long l = scm_page_level(i);
    long long f = scm_page_root(i);
    long long r = scm_page_row(i);
    long long c = scm_page_col(i);
    long long n = 1LL << l; long long m = n - 1; long long t = m - r;
    if (c < m) { c = c + 1; }
    else if (f == 0) { f = 5; c = 0; }
    else if (f == 1) { f = 4; c = 0; }
    else if (f == 2) { f = 0; c = t; r = 0; }
    else if (f == 3) { f = 0; c = r; r = m; }
    else if (f == 4) { f = 0; c = 0; }
    else { f = 1; c = 0; }
    return scm_page_index(f, l, r, c);
}


decompiled_code:
void __fastcall scm_page_corners(__int64 a1, __int64 a2)
{
char v2; // r14
__int64 v3; // rbp
int v4; // er12
int v5; // er13
double v6; // xmm2_8
double v7; // r14
double v8; // r13
double v9; // r12

v2 = scm_page_level(a1);
v3 = scm_page_root(a1);
v4 = scm_page_row(a1);
v5 = scm_page_col(a1);
v6 = (double)(int)(1LL << v2);
v7 = (double)v5 / v6;
scm_vector(v3, a2, (double)v4 / v6, v7);
v8 = (double)(v5 + 1) / v6;
scm_vector(v3, a2 + 24, (double)v4 / v6, v8);
v9 = (double)(v4 + 1) / v6;
scm_vector(v3, a2 + 48, v9, v7);
scm_vector(v3, a2 + 72, v9, v8);
}

original_code:
void scm_page_corners(long long i, double *v)
{
    long long l = scm_page_level(i);
    long long f = scm_page_root(i);
    long long r = scm_page_row(i);
    long long c = scm_page_col(i);
    long long n = 1LL << l;
    scm_vector(f, (double) (r + 0) / n, (double) (c + 0) / n, v + 0);
    scm_vector(f, (double) (r + 0) / n, (double) (c + 1) / n, v + 3);
    scm_vector(f, (double) (r + 1) / n, (double) (c + 0) / n, v + 6);
    scm_vector(f, (double) (r + 1) / n, (double) (c + 1) / n, v + 9);
}


canonical_original_code:
static inline long long log2i(long long n)
{
    unsigned long long v = (unsigned long long) n;
    unsigned long long r;
    unsigned long long s;
    r = (v > 0xFFFFFFFFULL) << 5; v >>= r;
    s = (v > 0xFFFFULL ) << 4; v >>= s; r |= s;
    s = (v > 0xFFULL ) << 3; v >>= s; r |= s;
    s = (v > 0xFULL ) << 2; v >>= s; r |= s;
    s = (v > 0x3ULL ) << 1; v >>= s; r |= s;
    return (long long) (r | (v >> 1));
}

variable_types:
v
unsigned long long

variable_types:
r
unsigned long long

variable_types:
s
unsigned long long


canonical_original_code:
static inline long long scm_page_count(long long d)
{
    return (1LL << (2 * d + 3)) - 2;
}

variable_types:
d
long long


canonical_original_code:
static inline long long scm_page_level(long long i)
{
    return (log2i(i + 2) - 1) / 2;
}

variable_types:
i
long long


canonical_original_code:
static inline long long scm_page_root(long long i)
{
    long long n = 1LL << (2 * scm_page_level(i));
    return (i - 2 * (n - 1)) / n;
}


canonical_original_code:
static inline long long scm_page_rank(long long i)
{
    long long n = 1LL << (2 * scm_page_level(i));
    return (i - 2 * (n - 1)) % n;
}


canonical_original_code:
static inline long long scm_page_row(long long i)
{
    return scm_page_rank(i) / (1LL << scm_page_level(i));
}


canonical_original_code:
static inline long long scm_page_col(long long i)
{
    return scm_page_rank(i) % (1LL << scm_page_level(i));
}


canonical_original_code:
static inline long long scm_page_index(long long a, long long l, long long r, long long c)
{
    return scm_page_count(l - 1) + (a << (2 * l)) + (r << l) + c;
}

variable_types:
a
long long

variable_types:
l
long long

variable_types:
r
long long

variable_types:
c
long long


decompiled_code:
__int64 __fastcall scm_page_child(__int64 a1, __int64 a2)
{
__int64 v2; // r12
__int64 v3; // r13
char v4; // bp
__int64 v5; // rax

v2 = a2 % 2 + 2 * scm_page_col(a1);
v3 = a2 / 2 + 2 * scm_page_row(a1);
v4 = scm_page_level(a1);
v5 = scm_page_root(a1);
return scm_page_index(v5, v4 + 1, v3, v2);
}

original_code:
static inline long long scm_page_child(long long i, long long k)
{
    return scm_page_index(scm_page_root(i), scm_page_level(i) + 1,
                                            scm_page_row (i) * 2 + k / 2,
                                            scm_page_col (i) * 2 + k % 2);
}

variable_types:
k
long long


decompiled_code:
void __fastcall max_pixels(float *a1, float *a2, float *a3, float *a4, float *a5, int a6)
{
if ( a6 == 3 )
goto LABEL_11;
if ( a6 > 3 )
{
if ( a6 != 4 )
return;
a1[3] = fmaxf(fmaxf(a2[3], a3[3]), fmaxf(a4[3], a5[3]));
LABEL_11:
a1[2] = fmaxf(fmaxf(a2[2], a3[2]), fmaxf(a4[2], a5[2]));
goto LABEL_5;
}
if ( a6 == 1 )
{
LABEL_6:
*a1 = fmaxf(fmaxf(*a2, a3[1]), fmaxf(*a4, *a5));
return;
}
if ( a6 == 2 )
{
LABEL_5:
a1[1] = fmaxf(fmaxf(a2[1], a3[1]), fmaxf(a4[1], a5[1]));
goto LABEL_6;
}
}

canonical_decompiled_code:
void __fastcall func10(float *a1, float *a2, float *a3, float *a4, float *a5, int a6)
{
if ( a6 == 3 )
goto LABEL_11;
if ( a6 > 3 )
{
if ( a6 != 4 )
return;
a1[3] = fmaxf(fmaxf(a2[3], a3[3]), fmaxf(a4[3], a5[3]));
LABEL_11:
a1[2] = fmaxf(fmaxf(a2[2], a3[2]), fmaxf(a4[2], a5[2]));
goto LABEL_5;
}
if ( a6 == 1 )
{
LABEL_6:
*a1 = fmaxf(fmaxf(*a2, a3[1]), fmaxf(*a4, *a5));
return;
}
if ( a6 == 2 )
{
LABEL_5:
a1[1] = fmaxf(fmaxf(a2[1], a3[1]), fmaxf(a4[1], a5[1]));
goto LABEL_6;
}
}

variable_types:
p
float *

variable_types: c int


original_code:
static void box_pixels(float *p, int ki, int kj,
                                int qi, int qj, int c, int n, int O, float *q)
{
    const int pi = qi / 2 + ki * n / 2;
    const int pj = qj / 2 + kj * n / 2;
    float *q0 = q + ((n + 2) * (qi + 1) + (qj + 1)) * c;
    float *q1 = q + ((n + 2) * (qi + 1) + (qj + 2)) * c;
    float *q2 = q + ((n + 2) * (qi + 2) + (qj + 1)) * c;
    float *q3 = q + ((n + 2) * (qi + 2) + (qj + 2)) * c;
    float *pp = p + ((n + 2) * (pi + 1) + (pj + 1)) * c;
    switch (O)
    {
        case 0: sum_pixels(pp, q0, q1, q2, q3, c); break;
        case 1: max_pixels(pp, q0, q1, q2, q3, c); break;
        case 2: avg_pixels(pp, q0, q1, q2, q3, c); break;
    }
}

canonical_original_code:
static void box_pixels(float *p, int ki, int kj, int qi, int qj, int c, int n, int O, float *q)
{
    int pi = qi / 2 + ki * n / 2;
    int pj = qj / 2 + kj * n / 2;
    float *q0 = q + ((n + 2) * (qi + 1) + (qj + 1)) * c;
    float *q1 = q + ((n + 2) * (qi + 1) + (qj + 2)) * c;
    float *q2 = q + ((n + 2) * (qi + 2) + (qj + 1)) * c;
    float *q3 = q + ((n + 2) * (qi + 2) + (qj + 2)) * c;
    float *pp = p + ((n + 2) * (pi + 1) + (pj + 1)) * c;
    switch (O)
    {
        case 0: sum_pixels(pp, q0, q1, q2, q3, c); break;
        case 1: max_pixels(pp, q0, q1, q2, q3, c); break;
        case 2: avg_pixels(pp, q0, q1, q2, q3, c); break;
    }
}

variable_types: ki int

variable_types: kj int

variable_types: qi int

variable_types: qj int

variable_types: n int

variable_types: O int

variable_types:
q
float *

variable_types: pi int

variable_types: pj int

variable_types:
pp
float *


box

original_code:
static void box(float *p, int ki, int kj, int c, int n, int O, float *q)
{
    int qi;
    int qj;
#pragma omp parallel for private(qj)
    for (qi = 0; qi < n; qi += 2)
        for (qj = 0; qj < n; qj += 2)
            box_pixels(p, ki, kj, qi, qj, c, n, O, q);
}


sum

decompiled_code:
float __fastcall sum(float a1, float a2)
{
return a1 + a2;
}

canonical_decompiled_code:
float __fastcall func0(float a1, float a2)
{
return a1 + a2;
}

original_code:
static inline float sum(float a, float b)
{
    return a + b;
}

variable_types: a float

variable_types: b float


avg

original_code:
static inline float avg(float a, float b)
{
    if (a == 0.f) return b;
    if (b == 0.f) return a;
    return (a + b) * 0.5f;
}


blend

decompiled_code:
float *__fastcall blend(float *a1, float *a2, int a3)
{
__int64 v3; // rcx
float *result; // rax
float v5; // xmm1_4
float v6; // xmm0_4

v3 = 4LL * a3 - 4;
result = (float *)((char *)a2 + v3);
v5 = *(float *)((char *)a2 + v3);
v6 = 1.0 - v5;
switch ( a3 )
{
case 3:
goto LABEL_6;
case 4:
a1[2] = (float)(v6 * a1[2]) + (float)(v5 * a2[2]);
LABEL_6:
a1[1] = (float)(v6 * a1[1]) + (float)(v5 * a2[1]);
LABEL_7:
*a1 = (float)(v6 * *a1) + (float)(v5 * *a2);
break;
case 2:
goto LABEL_7;
}
*(float *)((char *)a1 + v3) = fmaxf(*(float *)((char *)a1 + v3), *result);
return result;
}

canonical_decompiled_code:
float *__fastcall func2(float *a1, float *a2, int a3)
{
__int64 v3; // rcx
float *result; // rax
float v5; // xmm1_4
float v6; // xmm0_4

v3 = 4LL * a3 - 4;
result = (float *)((char *)a2 + v3);
v5 = *(float *)((char *)a2 + v3);
v6 = 1.0 - v5;
switch ( a3 )
{
case 3:
goto LABEL_6;
case 4:
a1[2] = (float)(v6 * a1[2]) + (float)(v5 * a2[2]);
LABEL_6:
a1[1] = (float)(v6 * a1[1]) + (float)(v5 * a2[1]);
LABEL_7:
*a1 = (float)(v6 * *a1) + (float)(v5 * *a2);
break;
case 2:
goto LABEL_7;
}
*(float *)((char *)a1 + v3) = fmaxf(*(float *)((char *)a1 + v3), *result);
return result;
}

original_code:
static inline void blend(float *dst, const float *src, int c)
{
    const float a = src[c - 1];
    const float b = 1.f - src[c - 1];
    switch (c)
    {
        case 4: dst[2] = dst[2] * b + src[2] * a;
        case 3: dst[1] = dst[1] * b + src[1] * a;
        case 2: dst[0] = dst[0] * b + src[0] * a;
    }
    dst[c - 1] = (((dst[c - 1]) > (src[c - 1])) ? (dst[c - 1]) : (src[c - 1]));
}

canonical_original_code:
static inline void blend(float *dst, float *src, int c)
{
    float a = src[c - 1];
    float b = 1.f - src[c - 1];
    switch (c)
    {
        case 4: dst[2] = dst[2] * b + src[2] * a;
        case 3: dst[1] = dst[1] * b + src[1] * a;
        case 2: dst[0] = dst[0] * b + src[0] * a;
    }
    dst[c - 1] = (((dst[c - 1]) > (src[c - 1])) ? (dst[c - 1]) : (src[c - 1]));
}

variable_types:
dst
float *

variable_types:
src
float *


canonical_original_code:
static inline long long scm_page_child(long long i, long long k)
{
    return scm_page_index(scm_page_root(i), scm_page_level(i) + 1,
                                            scm_page_row (i) * 2 + k / 2,
                                            scm_page_col (i) * 2 + k % 2);
}

variable_types:
i
long long

variable_types:
k
long long


necessary

decompiled_code:
__int64 __fastcall necessary(__int64 a1, int a2, int a3)
{
float *v4; // rbp
int v5; // er15
__int64 result; // rax
int i; // er12
float *v8; // rax

v4 = (float *)pixel(a1, a2, a3, 1, 1);
v5 = 0;
result = 0LL;
if ( a2 <= 0 )
return result;
while ( 2 )
{
for ( i = 0; ; ++i )
{
v8 = (float *)pixel(a1, a2, a3, v5, i);
if ( a3 == 3 )
goto LABEL_5;
if ( a3 > 3 )
{
if ( a3 != 4 )
goto LABEL_8;
if ( v4[3] != v8[3] )
return 1LL;
LABEL_5:
if ( v4[2] != v8[2] )
return 1LL;
goto LABEL_14;
}
if ( a3 == 1 )
goto LABEL_7;
if ( a3 != 2 )
goto LABEL_8;
LABEL_14:
if ( v4[1] != v8[1] )
return 1LL;
LABEL_7:
if ( *v4 != *v8 )
return 1LL;
LABEL_8:
if ( a2 == i + 1 )
break;
}
if ( v5 != i )
{
++v5;
continue;
}
return 0LL;
}
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, int a2, int a3)
{
float *v4; // rbp
int v5; // er15
__int64 result; // rax
int i; // er12
float *v8; // rax

v4 = (float *)func9(a1, a2, a3, 1, 1);
v5 = 0;
result = 0LL;
if ( a2 <= 0 )
return result;
while ( 2 )
{
for ( i = 0; ; ++i )
{
v8 = (float *)func9(a1, a2, a3, v5, i);
if ( a3 == 3 )
goto LABEL_5;
if ( a3 > 3 )
{
if ( a3 != 4 )
goto LABEL_8;
if ( v4[3] != v8[3] )
return 1LL;
LABEL_5:
if ( v4[2] != v8[2] )
return 1LL;
goto LABEL_14;
}
if ( a3 == 1 )
goto LABEL_7;
if ( a3 != 2 )
goto LABEL_8;
LABEL_14:
if ( v4[1] != v8[1] )
return 1LL;
LABEL_7:
if ( *v4 != *v8 )
return 1LL;
LABEL_8:
if ( a2 == i + 1 )
break;
}
if ( v5 != i )
{
++v5;
continue;
}
return 0LL;
}
}

original_code:
static _Bool necessary(const float *p, int n, int c)
{
    const float *a = pixel(p, n, c, 1, 1);
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
        {
            const float *b = pixel(p, n, c, i, j);
            switch (c)
            {
                case 4: if (a[3] != b[3]) return 1;
                case 3: if (a[2] != b[2]) return 1;
                case 2: if (a[1] != b[1]) return 1;
                case 1: if (a[0] != b[0]) return 1;
            }
        }
    return 0;
}

canonical_original_code:
static _Bool necessary(float *p, int n, int c)
{
    float *a = pixel(p, n, c, 1, 1);
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
        {
            float *b = pixel(p, n, c, i, j);
            switch (c)
            {
                case 4: if (a[3] != b[3]) return 1;
                case 3: if (a[2] != b[2]) return 1;
                case 2: if (a[1] != b[1]) return 1;
                case 1: if (a[0] != b[0]) return 1;
            }
        }
    return 0;
}

variable_types:
p
float *

variable_types: c int

variable_types:
a
float *

variable_types: i int

variable_types: j int

variable_types:
b
float *


divide

decompiled_code:
void __fastcall divide(float *a1, int a2, float a3)
{
if ( a2 == 3 )
goto LABEL_11;
if ( a2 > 3 )
{
if ( a2 != 4 )
return;
a1[3] = a1[3] / a3;
LABEL_11:
a1[2] = a1[2] / a3;
goto LABEL_5;
}
if ( a2 == 1 )
{
LABEL_6:
*a1 = *a1 / a3;
return;
}
if ( a2 == 2 )
{
LABEL_5:
a1[1] = a1[1] / a3;
goto LABEL_6;
}
}

original_code:
static void divide(float *p, float d, int c)
{
    switch (c)
    {
        case 4: p[3] /= d;
        case 3: p[2] /= d;
        case 2: p[1] /= d;
        case 1: p[0] /= d;
    }
}

variable_types: d float


now

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

gettimeofday(&v1, 0LL);
return (double)SLODWORD(v1.tv_usec) / 1000000.0 + (double)SLODWORD(v1.tv_sec);
}

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

gettimeofday(&v1, 0LL);
return (double)SLODWORD(v1.tv_usec) / 1000000.0 + (double)SLODWORD(v1.tv_sec);
}

original_code:
static inline double now()
{
    struct timeval tv;
    gettimeofday(&tv, ((void *)0));
    return (double) tv.tv_sec + (double) tv.tv_usec / 1000000.0;
}

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

return_type: double


original_code:
void mid2(double *m, const double *a, const double *b)
{
    m[0] = a[0] + b[0];
    m[1] = a[1] + b[1];
    m[2] = a[2] + b[2];
    normalize(m);
}

variable_types:
m
double *

variable_types:
a
double *

variable_types:
b
double *


original_code:
void mid4(double *m, const double *a, const double *b,
                    const double *c, const double *d)
{
    m[0] = a[0] + b[0] + c[0] + d[0];
    m[1] = a[1] + b[1] + c[1] + d[1];
    m[2] = a[2] + b[2] + c[2] + d[2];
    normalize(m);
}

variable_types:
c
double *

variable_types:
d
double *


decompiled_code:
float __fastcall lerp1(float a1, float a2, float a3)
{
return (float)((float)(1.0 - a3) * a1) + (float)(a3 * a2);
}

canonical_decompiled_code:
float __fastcall func6(float a1, float a2, float a3)
{
return (float)((float)(1.0 - a3) * a1) + (float)(a3 * a2);
}

original_code:
float lerp1(float a, float b, float t)
{
    return b * t + a * (1.0f - t);
}

variable_types: a float

variable_types: b float

variable_types: t float


decompiled_code:
float __fastcall lerp2(float a1, float a2, float a3, float a4, float a5, float a6)
{
float v6; // xmm0_4
float v8; // [rsp+4h] [rbp-14h]

v8 = lerp1(a3, a4, a6);
v6 = lerp1(a1, a2, a6);
return lerp1(v6, v8, a5);
}

canonical_decompiled_code:
float __fastcall func7(float a1, float a2, float a3, float a4, float a5, float a6)
{
float v6; // xmm0_4
float v8; // [rsp+4h] [rbp-14h]

v8 = func6(a3, a4, a6);
v6 = func6(a1, a2, a6);
return func6(v6, v8, a5);
}

original_code:
float lerp2(float a, float b, float c, float d, float s, float t)
{
    return lerp1(lerp1(a, b, t), lerp1(c, d, t), s);
}

variable_types: c float

variable_types: s float


extcmp

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

v2 = strlen(a1);
v3 = strlen(a2);
return strcasecmp(&a1[v2 - v3], a2);
}

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

v2 = strlen(a1);
v3 = strlen(a2);
return strcasecmp(&a1[v2 - v3], a2);
}

original_code:
int extcmp(const char *name, const char *ext)
{
    return strcasecmp(name + strlen(name) - strlen(ext), ext);
}

canonical_original_code:
int extcmp(char *name, char *ext)
{
    return strcasecmp(name + strlen(name) - strlen(ext), ext);
}

variable_types:
name
char *

variable_types:
ext
char *


grow

original_code:
int grow(float *p, float *q, int c, int n)
{
    const int s = (n + 2) * c;
    const int a = (c - 1);
    float *P;
    float *Q;
    int N = 0;
    int i;
    int j;
    int d;
    memcpy(q, p, (size_t) (n + 2) * (n + 2) * c * sizeof (float));
#pragma omp parallel for private(j, P, Q, d) reduction(+:N)
    for (i = 1; i <= n; i++)
        for (j = 1; j <= n; j++)
        {
            P = p + ((n + 2) * i + j) * c;
            Q = q + ((n + 2) * i + j) * c;
            if (Q[a] == 0)
            {
                d = 0;
                if ((Q - s - c)[a]) { accumulate(P, Q - s - c, a); d++; }
                if ((Q - s )[a]) { accumulate(P, Q - s , a); d++; }
                if ((Q - s + c)[a]) { accumulate(P, Q - s + c, a); d++; }
                if ((Q - c)[a]) { accumulate(P, Q - c, a); d++; }
                if ((Q + c)[a]) { accumulate(P, Q + c, a); d++; }
                if ((Q + s - c)[a]) { accumulate(P, Q + s - c, a); d++; }
                if ((Q + s )[a]) { accumulate(P, Q + s , a); d++; }
                if ((Q + s + c)[a]) { accumulate(P, Q + s + c, a); d++; }
                if (d)
                {
                    divide(P, (float) d, a);
                    N++;
                }
            }
        }
    return N;
}

canonical_original_code:
int grow(float *p, float *q, int c, int n)
{
    int s = (n + 2) * c;
    int a = (c - 1);
    float *P;
    float *Q;
    int N = 0;
    int i;
    int j;
    int d;
    memcpy(q, p, (unsigned long) (n + 2) * (n + 2) * c * sizeof (float));
#pragma omp parallel for private(j, P, Q, d) reduction(+:N)
    for (i = 1; i <= n; i++)
        for (j = 1; j <= n; j++)
        {
            P = p + ((n + 2) * i + j) * c;
            Q = q + ((n + 2) * i + j) * c;
            if (Q[a] == 0)
            {
                d = 0;
                if ((Q - s - c)[a]) { accumulate(P, Q - s - c, a); d++; }
                if ((Q - s )[a]) { accumulate(P, Q - s , a); d++; }
                if ((Q - s + c)[a]) { accumulate(P, Q - s + c, a); d++; }
                if ((Q - c)[a]) { accumulate(P, Q - c, a); d++; }
                if ((Q + c)[a]) { accumulate(P, Q + c, a); d++; }
                if ((Q + s - c)[a]) { accumulate(P, Q + s - c, a); d++; }
                if ((Q + s )[a]) { accumulate(P, Q + s , a); d++; }
                if ((Q + s + c)[a]) { accumulate(P, Q + s + c, a); d++; }
                if (d)
                {
                    divide(P, (float) d, a);
                    N++;
                }
            }
        }
    return N;
}

variable_types:
p
float *

variable_types:
q
float *

variable_types: c int

variable_types: n int

variable_types: s int

variable_types: a int

variable_types:
P
float *

variable_types:
Q
float *

variable_types: N int

variable_types: i int

variable_types: d int


hms

decompiled_code:
int __fastcall hms(char *a1, int a2)
{
if ( a2 <= 60 )
return sprintf(a1, "%ds", (unsigned int)a2);
if ( a2 <= 3600 )
return sprintf(a1, "%dm %ds", (unsigned int)(a2 / 60), (unsigned int)(a2 % 60));
return sprintf(
a1,
"%dh %dm %ds",
(unsigned int)(a2 / 3600),
(unsigned int)(a2 % 3600 / 60),
(unsigned int)(a2 % 3600 % 60));
}

canonical_decompiled_code:
int __fastcall func11(char *a1, int a2)
{
if ( a2 <= 60 )
return sprintf(a1, "%ds", (unsigned int)a2);
if ( a2 <= 3600 )
return sprintf(a1, "%dm %ds", (unsigned int)(a2 / 60), (unsigned int)(a2 % 60));
return sprintf(
a1,
"%dh %dm %ds",
(unsigned int)(a2 / 3600),
(unsigned int)(a2 % 3600 / 60),
(unsigned int)(a2 % 3600 % 60));
}

original_code:
void hms(char *str, int s)
{
    int h = 0;
    int m = 0;
    if (s > 60.0)
    {
        if (s > 3600.0)
        {
            h = (int) s / 3600;
            s -= (int) h * 3600;
        }
        m = (int) s / 60;
        s -= (int) m * 60;
    }
    if (h) sprintf(str, "%dh %dm %ds", h, m, s);
    else if (m) sprintf(str, "%dm %ds", m, s);
    else sprintf(str, "%ds", s);
}

variable_types:
str
char *

variable_types: h int

variable_types: m int


decompiled_code:
void __fastcall report_init(int a1)
{
report_done = 0;
report_todo = a1;
}

canonical_decompiled_code:
void __fastcall func12(int a1)
{
report_done = 0;
report_todo = a1;
}

original_code:
void report_init(int n)
{
    report_done = 0;
    report_todo = n;
}


decompiled_code:
void report_step()
{
size_t v0; // rbx
int v1; // esi
double v2; // [rsp+0h] [rbp-210h]
char v3[256]; // [rsp+8h] [rbp-208h] BYREF
char v4[264]; // [rsp+108h] [rbp-108h] BYREF

++report_done;
if ( report_todo )
{
v0 = 0LL;
if ( dirty_2 )
{
while ( strlen(str_1) > v0 )
{
putchar(8);
++v0;
}
}
else
{
start_0 = now();
dirty_2 = 1;
}
v2 = now() - *(double *)&start_0;
hms(v3, (int)v2);
v1 = report_done;
if ( report_done )
v1 = (int)((double)report_todo * v2 / (double)report_done - v2);
hms(v4, v1);
sprintf(
str_1,
"Processed %d of %d (%.2f%%) %s passed, estimated %s remaining. ",
(unsigned int)report_done,
(unsigned int)report_todo,
(double)report_done * 100.0 / (double)report_todo,
v3,
v4);
if ( report_done >= report_todo )
puts(str_1);
else
printf("%s", str_1);
fflush(stdout);
}
}

canonical_decompiled_code:
void func13()
{
size_t v0; // rbx
int v1; // esi
double v2; // [rsp+0h] [rbp-210h]
char v3[256]; // [rsp+8h] [rbp-208h] BYREF
char v4[264]; // [rsp+108h] [rbp-108h] BYREF

++report_done;
if ( report_todo )
{
v0 = 0LL;
if ( dirty_2 )
{
while ( strlen(str_1) > v0 )
{
putchar(8);
++v0;
}
}
else
{
start_0 = func2();
dirty_2 = 1;
}
v2 = func2() - *(double *)&start_0;
func11(v3, (int)v2);
v1 = report_done;
if ( report_done )
v1 = (int)((double)report_todo * v2 / (double)report_done - v2);
func11(v4, v1);
sprintf(
str_1,
"Processed %d of %d (%.2f%%) %s passed, estimated %s remaining. ",
(unsigned int)report_done,
(unsigned int)report_todo,
(double)report_done * 100.0 / (double)report_todo,
v3,
v4);
if ( report_done >= report_todo )
puts(str_1);
else
printf("%s", str_1);
fflush(stdout);
}
}

original_code:
void report_step(void)
{
    report_done++;
    if (report_todo)
    {
        static char str[256];
        static int dirty = 0;
        static double start = 0;
        char passed[256];
        char remain[256];
        if (dirty)
        {
            for (int i = 0; i < strlen(str); i++)
                printf("\b");
        }
        else
        {
            start = now();
            dirty = 1;
        }
        double d = now() - start;
        hms(passed, d);
        hms(remain, report_done ? d * report_todo / report_done - d : 0);
        sprintf(str, "Processed %d of %d (%.2f%%) %s passed, "
                                     "estimated %s remaining. ",
                    report_done,
                    report_todo, 100.0 * report_done / report_todo,
                    passed, remain);
        if (report_done < report_todo)
            printf("%s", str);
        else
            printf("%s\n", str);
        fflush(stdout);
    }
}

canonical_original_code:
void report_step()
{
    report_done++;
    if (report_todo)
    {
        static char str[256];
        static int dirty = 0;
        static double start = 0;
        char passed[256];
        char remain[256];
        if (dirty)
        {
            for (int i = 0; i < strlen(str); i++)
                printf("\b");
        }
        else
        {
            start = now();
            dirty = 1;
        }
        double d = now() - start;
        hms(passed, d);
        hms(remain, report_done ? d * report_todo / report_done - d : 0);
        sprintf(str, "Processed %d of %d (%.2f%%) %s passed, "
                                     "estimated %s remaining. ",
                    report_done,
                    report_todo, 100.0 * report_done / report_todo,
                    passed, remain);
        if (report_done < report_todo)
            printf("%s", str);
        else
            printf("%s\n", str);
        fflush(stdout);
    }
}

variable_types:
str
char [256]

variable_types: dirty int

variable_types: start double

variable_types:
passed
char [256]

variable_types:
remain
char [256]

variable_types: d double


original_code:
static inline long long log2i(long long n)
{
    unsigned long long v = (unsigned long long) n;
    unsigned long long r;
    unsigned long long s;
    r = (v > 0xFFFFFFFFULL) << 5; v >>= r;
    s = (v > 0xFFFFULL ) << 4; v >>= s; r |= s;
    s = (v > 0xFFULL ) << 3; v >>= s; r |= s;
    s = (v > 0xFULL ) << 2; v >>= s; r |= s;
    s = (v > 0x3ULL ) << 1; v >>= s; r |= s;
    return (long long) (r | (v >> 1));
}

variable_types:
n
long long

variable_types:
v
unsigned long long

variable_types:
r
unsigned long long

variable_types:
s
unsigned long long


decompiled_code:
__int64 __fastcall scm_page_count(char a1)
{
return (1LL << (2 * a1 + 3)) - 2;
}

original_code:
static inline long long scm_page_count(long long d)
{
    return (1LL << (2 * d + 3)) - 2;
}

variable_types:
d
long long


decompiled_code:
__int64 __fastcall scm_page_level(__int64 a1)
{
return (log2i(a1 + 2) - 1) / 2;
}

original_code:
static inline long long scm_page_level(long long i)
{
    return (log2i(i + 2) - 1) / 2;
}

variable_types:
i
long long


original_code:
static inline long long scm_page_root(long long i)
{
    long long n = 1LL << (2 * scm_page_level(i));
    return (i - 2 * (n - 1)) / n;
}


original_code:
static inline long long scm_page_rank(long long i)
{
    long long n = 1LL << (2 * scm_page_level(i));
    return (i - 2 * (n - 1)) % n;
}


decompiled_code:
__int64 __fastcall scm_page_row(__int64 a1)
{
__int64 v1; // rbx

v1 = scm_page_rank(a1);
return v1 / (1LL << scm_page_level(a1));
}

original_code:
static inline long long scm_page_row(long long i)
{
    return scm_page_rank(i) / (1LL << scm_page_level(i));
}


decompiled_code:
__int64 __fastcall scm_page_col(__int64 a1)
{
__int64 v1; // rbx

v1 = scm_page_rank(a1);
return v1 % (1LL << scm_page_level(a1));
}

original_code:
static inline long long scm_page_col(long long i)
{
    return scm_page_rank(i) % (1LL << scm_page_level(i));
}


decompiled_code:
__int64 __fastcall scm_page_index(__int64 a1, char a2, __int64 a3, __int64 a4)
{
return (a3 << a2) + scm_page_count(a2 - 1) + (a1 << (2 * a2)) + a4;
}

original_code:
static inline long long scm_page_index(long long a, long long l,
                                       long long r, long long c)
{
    return scm_page_count(l - 1) + (a << (2 * l)) + (r << l) + c;
}

variable_types:
a
long long

variable_types:
l
long long

variable_types:
r
long long

variable_types:
c
long long


decompiled_code:
__int64 __fastcall scm_page_child(__int64 a1, __int64 a2)
{
__int64 v2; // r12
__int64 v3; // r13
char v4; // bp
__int64 v5; // rax

v2 = a2 % 2 + 2 * scm_page_col(a1);
v3 = a2 / 2 + 2 * scm_page_row(a1);
v4 = scm_page_level(a1);
v5 = scm_page_root(a1);
return scm_page_index(v5, v4 + 1, v3, v2);
}

original_code:
static inline long long scm_page_child(long long i, long long k)
{
    return scm_page_index(scm_page_root(i), scm_page_level(i) + 1,
                                            scm_page_row (i) * 2 + k / 2,
                                            scm_page_col (i) * 2 + k % 2);
}

variable_types:
k
long long


decompiled_code:
__int64 __fastcall init_tap(__int64 a1, int a2, int a3, _DWORD *a4)
{
unsigned int v4; // er12
__int64 result; // rax

if ( a3 == 1 )
{
*a4 = a1;
}
else
{
v4 = a3 / 2;
init_tap(a1, (unsigned int)(2 * a2), (unsigned int)(a3 / 2));
result = init_tap((unsigned int)(a2 + a1), (unsigned int)(2 * a2), v4);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, int a2, int a3, _DWORD *a4)
{
unsigned int v4; // er12
__int64 result; // rax

if ( a3 == 1 )
{
*a4 = a1;
}
else
{
v4 = a3 / 2;
func9(a1, (unsigned int)(2 * a2), (unsigned int)(a3 / 2));
result = func9((unsigned int)(a2 + a1), (unsigned int)(2 * a2), v4);
}
return result;
}

original_code:
static void init_tap(int a, int d, int n, int *x)
{
    if (n == 1)
        *x = a;
    else
    {
        init_tap(a, d * 2, n / 2, x );
        init_tap(a + d, d * 2, n / 2, x + n / 2);
    }
}

variable_types: a int

variable_types: d int

variable_types: n int

variable_types:
x
int *


overlap

decompiled_code:
__int64 __fastcall overlap(__int64 a1, unsigned int a2, __int64 a3, __int64 a4, __int64 a5)
{
__int64 v5; // r12
__int64 v6; // rbp
char *v7; // rbx
__int64 v9; // [rsp+8h] [rbp-60h]
char v10[88]; // [rsp+10h] [rbp-58h] BYREF

v5 = a5 << 10;
v6 = a4 << 10;
v9 = a3 << 10;
v7 = (char *)&tap;
while ( 1 )
{
scm_get_sample_center(a2, v9 + *(_DWORD *)v7 / 1024, v6 + *(_DWORD *)v7 % 1024, v5, v10);
if ( (unsigned int)img_locate(a1, v10) )
break;
v7 += 4;
if ( v7 == ".jpg" )
return 0LL;
}
return 1LL;
}

original_code:
static _Bool overlap(img *p, int f, long u, long v, long w)
{
    for (int t = 0; t < (1024 * 1024); ++t)
    {
        int i = tap[t] / 1024;
        int j = tap[t] % 1024;
        double c[3];
        scm_get_sample_center(f, 1024 * u + i, 1024 * v + j, 1024 * w, c);
        if (img_locate(p, c))
            return 1;
    }
    return 0;
}

canonical_original_code:
static _Bool overlap(struct img *p, int f, long u, long v, long w)
{
    for (int t = 0; t < (1024 * 1024); ++t)
    {
        int i = tap[t] / 1024;
        int j = tap[t] % 1024;
        double c[3];
        scm_get_sample_center(f, 1024 * u + i, 1024 * v + j, 1024 * w, c);
        if (img_locate(p, c))
            return 1;
    }
    return 0;
}

variable_types: struct img { void *p; unsigned long n; int w; int h; int c; int b; int g; int o; int d; void *q; float norm0; float norm1; double maximum_latitude; double minimum_latitude; double center_latitude; double easternmost_longitude; double westernmost_longitude; double center_longitude; double line_projection_offset; double sample_projection_offset; double map_resolution; double map_scale; double a_axis_radius; float scaling_factor; float offset; double latc; double lonc; int (*project)(struct img *, double *, double, double, double *); } *

variable_types: f int

variable_types: u long

variable_types: v long

variable_types: w long

variable_types: t int

variable_types: i int

variable_types: j int

variable_types:
c
double [3]


multisample

original_code:
static int multisample(img *p, int f, int i, int j, int n,
                                 long u, long v, long w, float *d)
{
    double c[12];
    double C[15];
    int N = 0;
    scm_get_sample_corners(f, n * u + i, n * v + j, n * w, c);
    quincunx(C, c);
    for (int l = 0; l < 5; l++)
    {
        float t[4];
        if (img_sample(p, C + l * 3, t))
        {
            switch (p->c)
            {
                case 4: d[3] += t[3];
                case 3: d[2] += t[2];
                case 2: d[1] += t[1];
                case 1: d[0] += t[0];
            }
            N += 1;
        }
    }
    if (N)
    {
        switch (p->c)
        {
            case 4: d[3] /= N;
            case 3: d[2] /= N;
            case 2: d[1] /= N;
            case 1: d[0] /= N;
        }
    }
    return N;
}

canonical_original_code:
static int multisample(struct img *p, int f, int i, int j, int n, long u, long v, long w, float *d)
{
    double c[12];
    double C[15];
    int N = 0;
    scm_get_sample_corners(f, n * u + i, n * v + j, n * w, c);
    quincunx(C, c);
    for (int l = 0; l < 5; l++)
    {
        float t[4];
        if (img_sample(p, C + l * 3, t))
        {
            switch (p->c)
            {
                case 4: d[3] += t[3];
                case 3: d[2] += t[2];
                case 2: d[1] += t[1];
                case 1: d[0] += t[0];
            }
            N += 1;
        }
    }
    if (N)
    {
        switch (p->c)
        {
            case 4: d[3] /= N;
            case 3: d[2] /= N;
            case 2: d[1] /= N;
            case 1: d[0] /= N;
        }
    }
    return N;
}

variable_types:
d
float *

variable_types:
c
double [12]

variable_types:
C
double [15]

variable_types: N int

variable_types: l int

variable_types:
t
float [4]

user_defined_types: struct img { void *p; unsigned long n; int w; int h; int c; int b; int g; int o; int d; void *q; float norm0; float norm1; double maximum_latitude; double minimum_latitude; double center_latitude; double easternmost_longitude; double westernmost_longitude; double center_longitude; double line_projection_offset; double sample_projection_offset; double map_resolution; double map_scale; double a_axis_radius; float scaling_factor; float offset; double latc; double lonc; int (*project)(struct img *, double *, double, double, double *); }


divide

original_code:
static void divide(float *p, float d, int c)
{
    switch (c)
    {
        case 4: p[3] /= d;
        case 3: p[2] /= d;
        case 2: p[1] /= d;
        case 1: p[0] /= d;
    }
}

variable_types:
p
float *

variable_types: d float

variable_types: c int


decompiled_code:
__int64 __fastcall get_int(const char *a1)
{
return strtol(a1, 0LL, 0);
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1)
{
return strtol(a1, 0LL, 0);
}

original_code:
static int get_int(const char *v)
{
    return (int) strtol(v, ((void *)0), 0);
}

canonical_original_code:
static int get_int(char *v)
{
    return (int) strtol(v, ((void *)0), 0);
}

variable_types:
v
char *


decompiled_code:
double __fastcall get_double(const char *a1)
{
return strtod(a1, 0LL);
}

canonical_decompiled_code:
double __fastcall func1(const char *a1)
{
return strtod(a1, 0LL);
}

original_code:
static double get_double(const char *v)
{
    return strtod(v, ((void *)0));
}

canonical_original_code:
static double get_double(char *v)
{
    return strtod(v, ((void *)0));
}


decompiled_code:
float __fastcall get_float(const char *a1)
{
return strtod(a1, 0LL);
}

canonical_decompiled_code:
float __fastcall func3(const char *a1)
{
return strtod(a1, 0LL);
}

original_code:
static float get_float(const char *v)
{
    return (float) strtod(v, ((void *)0));
}

canonical_original_code:
static float get_float(char *v)
{
    return (float) strtod(v, ((void *)0));
}


equals

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

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

original_code:
static int equals(const char *a, const char *b)
{
    return (strcasecmp(a, b) == 0) ? 1 : 0;
}

canonical_original_code:
static int equals(char *a, char *b)
{
    return (strcasecmp(a, b) == 0) ? 1 : 0;
}

variable_types:
a
char *

variable_types:
b
char *


decompiled_code:
double __fastcall get_scale(const char *a1, const char *a2)
{
double result; // xmm0_8

if ( !equals(a2, "M/PIX") && (equals(a2, "KM/PIX") || !equals(a2, "M/PIXEL") && equals(a2, "KM/PIXEL")) )
result = get_double(a1) * 1000.0;
else
result = get_double(a1);
return result;
}

canonical_decompiled_code:
double __fastcall func5(const char *a1, const char *a2)
{
double result; // xmm0_8

if ( !func4(a2, "M/PIX") && (func4(a2, "KM/PIX") || !func4(a2, "M/PIXEL") && func4(a2, "KM/PIXEL")) )
result = func1(a1) * 1000.0;
else
result = func1(a1);
return result;
}

original_code:
static double get_scale(const char *v, const char *u)
{
    if (equals(u, "M/PIX")) return get_double(v);
    if (equals(u, "KM/PIX")) return get_double(v) * 1000.0;
    if (equals(u, "M/PIXEL")) return get_double(v);
    if (equals(u, "KM/PIXEL")) return get_double(v) * 1000.0;
    return get_double(v);
}

canonical_original_code:
static double get_scale(char *v, char *u)
{
    if (equals(u, "M/PIX")) return get_double(v);
    if (equals(u, "KM/PIX")) return get_double(v) * 1000.0;
    if (equals(u, "M/PIXEL")) return get_double(v);
    if (equals(u, "KM/PIXEL")) return get_double(v) * 1000.0;
    return get_double(v);
}

variable_types:
u
char *


start

decompiled_code:
// positive sp value has been detected, the output may be wrong!
void __fastcall __noreturn start(__int64 a1, __int64 a2, void (*a3)(void))
{
__int64 v3; // rax
int v4; // esi
__int64 v5; // [rsp-8h] [rbp-8h] BYREF
char *retaddr; // [rsp+0h] [rbp+0h] BYREF

v4 = v5;
v5 = v3;
_libc_start_main(
(int (__fastcall *)(int, char **, char **))main,
v4,
&retaddr,
_libc_csu_init,
_libc_csu_fini,
a3,
&v5);
__halt();
}

canonical_decompiled_code:
void __fastcall __noreturn func1(__int64 a1, __int64 a2, void (*a3)(void))
{
__int64 v3; // rax
int v4; // esi
__int64 v5; // [rsp-8h] [rbp-8h] BYREF
char *retaddr; // [rsp+0h] [rbp+0h] BYREF

v4 = v5;
v5 = v3;
_libc_start_main(
(int (__fastcall *)(int, char **, char **))main,
v4,
&retaddr,
_libc_csu_init,
_libc_csu_fini,
a3,
&v5);
__halt();
}

original_code:
static int start(int argc, char **argv)
{
    if (data_init(argc, argv))
    {
        glDisable(0x0B50);
        glDisable(0x0B71);
        glEnable(0x0DE1);
        glEnable(0x0BE2);
        glPixelStorei(0x0CF5, 1);
        glBlendFunc(0x0302, 0x0303);
        prog_color = prog_init(vert_color, frag_color);
        cmap_color = cmap_init(prog_color);
        __glewUseProgram(0);
        jump(0);
        return 1;
    }
    return 0;
}

variable_types: argc int

variable_types:
argv
char **


setexe

decompiled_code:
void __fastcall setexe(__int64 a1)
{
executable = a1;
}

canonical_decompiled_code:
void __fastcall func7(__int64 a1)
{
executable = a1;
}

original_code:
void setexe(const char *str)
{
    executable = str;
}

canonical_original_code:
void setexe(char *str)
{
    executable = str;
}

variable_types:
str
char *


printerr

decompiled_code:
int printerr(const char *a1, unsigned int a2, int a3, const char *a4, ...)
{
char *v6; // rax
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

va_start(arg, a4);
if ( executable )
fprintf(stderr, "%s (%s:%d) : ", (const char *)executable, a1, a2);
else
fprintf(stderr, "(%s:%d) : ", a1, a2);
if ( a4 )
vfprintf(stderr, a4, arg);
if ( !a3 )
return fputc(10, stderr);
v6 = strerror(a3);
return fprintf(stderr, " : %s\n", v6);
}

canonical_decompiled_code:
int func8(const char *a1, unsigned int a2, int a3, const char *a4, ...)
{
char *v6; // rax
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

va_start(arg, a4);
if ( executable )
fprintf(stderr, "%s (%s:%d) : ", (const char *)executable, a1, a2);
else
fprintf(stderr, "(%s:%d) : ", a1, a2);
if ( a4 )
vfprintf(stderr, a4, arg);
if ( !a3 )
return fputc(10, stderr);
v6 = strerror(a3);
return fprintf(stderr, " : %s\n", v6);
}

original_code:
void printerr(const char *file, int line, int err, const char *fmt, ...)
{
    va_list ap;
    __builtin_va_start(ap,fmt);
    {
        if (executable)
            fprintf(stderr, "%s (%s:%d) : ", executable, file, line);
        else
            fprintf(stderr, "(%s:%d) : ", file, line);
        if (fmt)
           vfprintf(stderr, fmt, ap);
        if (err)
            fprintf(stderr, " : %s\n", strerror(err));
        else
            fprintf(stderr, "\n");
    }
    __builtin_va_end(ap);
}

canonical_original_code:
void printerr(char *file, int line, int err, char *fmt, ...)
{
    __builtin_va_list ap;
    __builtin_va_start(ap,fmt);
    {
        if (executable)
            fprintf(stderr, "%s (%s:%d) : ", executable, file, line);
        else
            fprintf(stderr, "(%s:%d) : ", file, line);
        if (fmt)
           vfprintf(stderr, fmt, ap);
        if (err)
            fprintf(stderr, " : %s\n", strerror(err));
        else
            fprintf(stderr, "\n");
    }
    __builtin_va_end(ap);
}

variable_types:
file
char *

variable_types: line int

variable_types: err int

variable_types:
fmt
char *


usage

decompiled_code:
__int64 __fastcall usage(const char *a1)
{
fprintf(stderr, "%s [-j n] [-z n] <src.tif> <dst.tif>\n", a1);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func10(const char *a1)
{
fprintf(stderr, "%s [-j n] [-z n] <src.tif> <dst.tif>\n", a1);
return 0xFFFFFFFFLL;
}

original_code:
static int usage(const char *exe)
{
    fprintf(stderr, "%s [-j n] [-z n] <src.tif> <dst.tif>\n", exe);
    return -1;
}

canonical_original_code:
static int usage(char *exe)
{
    fprintf(stderr, "%s [-j n] [-z n] <src.tif> <dst.tif>\n", exe);
    return -1;
}

variable_types:
exe
char *


lerp

decompiled_code:
double __fastcall lerp(double a1, double a2, double a3)
{
return (1.0 - a3) * a1 + a3 * a2;
}

canonical_decompiled_code:
double __fastcall func0(double a1, double a2, double a3)
{
return (1.0 - a3) * a1 + a3 * a2;
}

original_code:
static double lerp(double a, double b, double t)
{
    return b * t + a * (1.0 - t);
}

variable_types: a double

variable_types: b double

variable_types: t double


rectify

variable_types:
o
char *

variable_types: n int

variable_types:
N
float *

variable_types:
E
double *

variable_types:
L
double *

variable_types:
P
double *

variable_types: struct img { void *p; unsigned long n; int w; int h; int c; int b; int g; int o; int d; void *q; float norm0; float norm1; double maximum_latitude; double minimum_latitude; double center_latitude; double easternmost_longitude; double westernmost_longitude; double center_longitude; double line_projection_offset; double sample_projection_offset; double map_resolution; double map_scale; double a_axis_radius; float scaling_factor; float offset; double latc; double lonc; int (*project)(struct img *, double *, double, double, double *); } *

variable_types:
e
char *

variable_types:
out
char [256]

variable_types: i int

variable_types:
in
char *


accumulate

decompiled_code:
__int64 __fastcall accumulate(__int64 a1, float *a2, int a3, double a4, double a5)
{
double v6; // rbx
double v7; // r15
__int64 result; // rax
double v9; // [rsp+0h] [rbp-78h] BYREF
double sinx; // [rsp+8h] [rbp-70h] BYREF
int v11[4]; // [rsp+10h] [rbp-68h] BYREF
__int64 v12[11]; // [rsp+20h] [rbp-58h] BYREF

sincos(a4, &sinx, &v9);
v6 = v9;
v7 = sinx;
sincos(a5, &sinx, &v9);
*(double *)v12 = v6 * sinx;
*(double *)&v12[1] = v7;
*(double *)&v12[2] = v6 * v9;
result = img_sample(a1, v12, v11);
if ( (_DWORD)result )
{
if ( a3 != 3 )
{
if ( a3 <= 3 )
{
if ( a3 == 1 )
{
LABEL_8:
*a2 = *a2 + *(float *)v11;
return 1LL;
}
if ( a3 != 2 )
return 1LL;
LABEL_7:
a2[1] = a2[1] + *(float *)&v11[1];
goto LABEL_8;
}
result = 1LL;
if ( a3 != 4 )
return result;
a2[3] = a2[3] + *(float *)&v11[3];
}
a2[2] = a2[2] + *(float *)&v11[2];
goto LABEL_7;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, float *a2, int a3, double a4, double a5)
{
double v6; // rbx
double v7; // r15
__int64 result; // rax
double v9; // [rsp+0h] [rbp-78h] BYREF
double sinx; // [rsp+8h] [rbp-70h] BYREF
int v11[4]; // [rsp+10h] [rbp-68h] BYREF
__int64 v12[11]; // [rsp+20h] [rbp-58h] BYREF

sincos(a4, &sinx, &v9);
v6 = v9;
v7 = sinx;
sincos(a5, &sinx, &v9);
*(double *)v12 = v6 * sinx;
*(double *)&v12[1] = v7;
*(double *)&v12[2] = v6 * v9;
result = img_sample(a1, v12, v11);
if ( (_DWORD)result )
{
if ( a3 != 3 )
{
if ( a3 <= 3 )
{
if ( a3 == 1 )
{
LABEL_8:
*a2 = *a2 + *(float *)v11;
return 1LL;
}
if ( a3 != 2 )
return 1LL;
LABEL_7:
a2[1] = a2[1] + *(float *)&v11[1];
goto LABEL_8;
}
result = 1LL;
if ( a3 != 4 )
return result;
a2[3] = a2[3] + *(float *)&v11[3];
}
a2[2] = a2[2] + *(float *)&v11[2];
goto LABEL_7;
}
return result;
}

original_code:
static int accumulate(img *p, double lat, double lon, float *b, int c)
{
    double v[3];
    float t[4];
    v[0] = sin(lon) * cos(lat);
    v[1] = sin(lat);
    v[2] = cos(lon) * cos(lat);
    if (img_sample(p, v, t))
    {
        switch (c)
        {
            case 4: b[3] += t[3];
            case 3: b[2] += t[2];
            case 2: b[1] += t[1];
            case 1: b[0] += t[0];
        }
        return 1;
    }
    return 0;
}

canonical_original_code:
static int accumulate(struct img *p, double lat, double lon, float *b, int c)
{
    double v[3];
    float t[4];
    v[0] = sin(lon) * cos(lat);
    v[1] = sin(lat);
    v[2] = cos(lon) * cos(lat);
    if (img_sample(p, v, t))
    {
        switch (c)
        {
            case 4: b[3] += t[3];
            case 3: b[2] += t[2];
            case 2: b[1] += t[1];
            case 1: b[0] += t[0];
        }
        return 1;
    }
    return 0;
}

variable_types: lat double

variable_types: lon double

variable_types:
b
float *

variable_types: c int

variable_types:
v
double [3]

variable_types:
t
float [4]