decompiled_code:
__int64 __fastcall cdlist_ins_next(__int64 *a1, __int64 a2)
{
_QWORD *v2; // rax
__int64 v3; // rdx

v2 = malloc(0x18uLL);
if ( !v2 )
return 0xFFFFFFFFLL;
v3 = *a1;
*v2 = *a1;
v2[1] = a1;
*(_QWORD *)(v3 + 8) = v2;
*(_QWORD *)v2[1] = v2;
v2[2] = a2;
return 0LL;
}

original_code:
int cdlist_ins_next( struct cdlist_elem *elem,
                              void *data) {
    struct cdlist_elem *elem_new;
    elem_new = malloc(sizeof(struct cdlist_elem));
    if (elem_new == ((void *)0))
        return -1;
    elem_new->next = elem->next;
    elem_new->prev = elem;
    elem_new->next->prev = elem_new;
    elem_new->prev->next = elem_new;
    elem_new->data = data;
    return 0;
}

canonical_original_code:
int cdlist_ins_next(struct cdlist_elem *elem, void *data) {
    struct cdlist_elem *elem_new;
    elem_new = malloc(sizeof(struct cdlist_elem));
    if (elem_new == ((void *)0))
        return -1;
    elem_new->next = elem->next;
    elem_new->prev = elem;
    elem_new->next->prev = elem_new;
    elem_new->prev->next = elem_new;
    elem_new->data = data;
    return 0;
}


repo: JohnAnthony/Structures

decompiled_code:
__int64 __fastcall cdlist_ins_head(__int64 *a1, __int64 a2)
{
return cdlist_ins_next(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 *a1, __int64 a2)
{
return func6(a1, a2);
}

original_code:
int cdlist_ins_head( struct cdlist *cdlist,
                              void *data) {
    return cdlist_ins_next(&cdlist->link, data);
}

canonical_original_code:
int cdlist_ins_head(struct cdlist *cdlist, void *data) {
    return cdlist_ins_next(&cdlist->link, data);
}

variable_types: struct cdlist { struct cdlist_elem { struct cdlist_elem *next; struct cdlist_elem *prev; void *data; } link; } *

variable_types:
data
void *

return_type: int

user_defined_types: struct cdlist { struct cdlist_elem link; }


decompiled_code:
__int64 __fastcall cdlist_ins_prev(__int64 a1, __int64 a2)
{
_QWORD *v2; // rax
_QWORD *v3; // rdx

v2 = malloc(0x18uLL);
if ( !v2 )
return 0xFFFFFFFFLL;
*v2 = a1;
v3 = *(_QWORD **)(a1 + 8);
v2[1] = v3;
*(_QWORD *)(a1 + 8) = v2;
*v3 = v2;
v2[2] = a2;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2)
{
_QWORD *v2; // rax
_QWORD *v3; // rdx

v2 = malloc(0x18uLL);
if ( !v2 )
return 0xFFFFFFFFLL;
*v2 = a1;
v3 = *(_QWORD **)(a1 + 8);
v2[1] = v3;
*(_QWORD *)(a1 + 8) = v2;
*v3 = v2;
v2[2] = a2;
return 0LL;
}

original_code:
int cdlist_ins_prev( struct cdlist_elem *elem,
                              void *data) {
    struct cdlist_elem *elem_new;
    elem_new = malloc(sizeof(struct cdlist_elem));
    if (elem_new == ((void *)0))
        return -1;
    elem_new->next = elem;
    elem_new->prev = elem->prev;
    elem_new->next->prev = elem_new;
    elem_new->prev->next = elem_new;
    elem_new->data = data;
    return 0;
}

canonical_original_code:
int cdlist_ins_prev(struct cdlist_elem *elem, void *data) {
    struct cdlist_elem *elem_new;
    elem_new = malloc(sizeof(struct cdlist_elem));
    if (elem_new == ((void *)0))
        return -1;
    elem_new->next = elem;
    elem_new->prev = elem->prev;
    elem_new->next->prev = elem_new;
    elem_new->prev->next = elem_new;
    elem_new->data = data;
    return 0;
}

variable_types: struct cdlist_elem { struct cdlist_elem *next; struct cdlist_elem *prev; void *data; } *


decompiled_code:
__int64 __fastcall cdlist_ins_tail(__int64 a1, __int64 a2)
{
return cdlist_ins_prev(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 a2)
{
return func8(a1, a2);
}

original_code:
int cdlist_ins_tail( struct cdlist *cdlist,
                              void *data) {
    return cdlist_ins_prev(&cdlist->link, data);
}

canonical_original_code:
int cdlist_ins_tail(struct cdlist *cdlist, void *data) {
    return cdlist_ins_prev(&cdlist->link, data);
}

user_defined_types: struct cdlist_elem { struct cdlist_elem *next; struct cdlist_elem *prev; void *data; }


decompiled_code:
__int64 __fastcall cdlist_rem_elem(void *ptr, void (__fastcall *a2)(_QWORD))
{
_QWORD *v2; // rax

v2 = (_QWORD *)*((_QWORD *)ptr + 1);
*(_QWORD *)(*(_QWORD *)ptr + 8LL) = v2;
*v2 = *(_QWORD *)ptr;
if ( a2 )
a2(*((_QWORD *)ptr + 2));
free(ptr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(void *ptr, void (__fastcall *a2)(_QWORD))
{
_QWORD *v2; // rax

v2 = (_QWORD *)*((_QWORD *)ptr + 1);
*(_QWORD *)(*(_QWORD *)ptr + 8LL) = v2;
*v2 = *(_QWORD *)ptr;
if ( a2 )
a2(*((_QWORD *)ptr + 2));
free(ptr);
return 0LL;
}

original_code:
int cdlist_rem_elem( struct cdlist_elem *elem,
                              void (*destroy)(void *data)) {
    elem->next->prev = elem->prev;
    elem->prev->next = elem->next;
    if (destroy)
        destroy(elem->data);
    free(elem);
    return 0;
}

canonical_original_code:
int cdlist_rem_elem(struct cdlist_elem *elem, void (*destroy)(void *data)) {
    elem->next->prev = elem->prev;
    elem->prev->next = elem->next;
    if (destroy)
        destroy(elem->data);
    free(elem);
    return 0;
}

variable_types:
destroy
void (*)(void *data)


decompiled_code:
__int64 __fastcall cdlist_rem_head(__int64 *a1, void (__fastcall *a2)(_QWORD))
{
void *v2; // rax
__int64 result; // rax

v2 = (void *)cdlist_get_head(a1);
if ( v2 )
result = cdlist_rem_elem(v2, a2);
else
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 *a1, void (__fastcall *a2)(_QWORD))
{
void *v2; // rax
__int64 result; // rax

v2 = (void *)func4(a1);
if ( v2 )
result = func10(v2, a2);
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int cdlist_rem_head( struct cdlist *cdlist,
                              void (*destroy)(void *data)) {
    struct cdlist_elem *head;
    head = cdlist_get_head(cdlist);
    if (head == ((void *)0))
        return -1;
    return cdlist_rem_elem(head, destroy);
}

canonical_original_code:
int cdlist_rem_head(struct cdlist *cdlist, void (*destroy)(void *data)) {
    struct cdlist_elem *head;
    head = cdlist_get_head(cdlist);
    if (head == ((void *)0))
        return -1;
    return cdlist_rem_elem(head, destroy);
}


decompiled_code:
__int64 __fastcall cdlist_rem_tail(__int64 *a1, void (__fastcall *a2)(_QWORD))
{
void *v2; // rax
__int64 result; // rax

v2 = (void *)cdlist_get_tail(a1);
if ( v2 )
result = cdlist_rem_elem(v2, a2);
else
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 *a1, void (__fastcall *a2)(_QWORD))
{
void *v2; // rax
__int64 result; // rax

v2 = (void *)func5(a1);
if ( v2 )
result = func10(v2, a2);
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int cdlist_rem_tail( struct cdlist *cdlist,
                              void (*destroy)(void *data)) {
    struct cdlist_elem *tail;
    tail = cdlist_get_tail(cdlist);
    if (tail == ((void *)0))
        return -1;
    return cdlist_rem_elem(tail, destroy);
}

canonical_original_code:
int cdlist_rem_tail(struct cdlist *cdlist, void (*destroy)(void *data)) {
    struct cdlist_elem *tail;
    tail = cdlist_get_tail(cdlist);
    if (tail == ((void *)0))
        return -1;
    return cdlist_rem_elem(tail, destroy);
}


decompiled_code:
__int64 __fastcall vel2halfstep(int a1)
{
signed int v1; // edi

v1 = abs32(a1);
if ( g_velmin >= v1 )
v1 = g_velmin;
return (unsigned int)(g_hstep_c / v1);
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1)
{
signed int v1; // edi

v1 = abs32(a1);
if ( g_velmin >= v1 )
v1 = g_velmin;
return (unsigned int)(g_hstep_c / v1);
}

original_code:
unsigned int vel2halfstep(int velocity) {
    velocity = velocity > 0 ? velocity : -velocity;
    if (velocity < g_velmin) {
        velocity = g_velmin;
    }
    return g_hstep_c / velocity;
}

variable_types: velocity int

return_type: unsigned int


decompiled_code:
void gpio_clear()
{
;
}

canonical_decompiled_code:
void func8()
{
;
}

original_code:
void gpio_clear(int port, int pin) {
}

canonical_original_code:
void gpio_clear(int port, int pin) {
}

variable_types: port int

variable_types: pin int

return_type: void


decompiled_code:
void gpio_set()
{
;
}

canonical_decompiled_code:
void func9()
{
;
}

original_code:
void gpio_set(int port, int pin) {
}

canonical_original_code:
void gpio_set(int port, int pin) {
}


decompiled_code:
void __fastcall nop_delay(int a1)
{
g_nop_delay_hstep_dly = a1;
}

canonical_decompiled_code:
void __fastcall func10(int a1)
{
g_nop_delay_hstep_dly = a1;
}

original_code:
void nop_delay(unsigned hstep_dly) {
    g_nop_delay_hstep_dly = hstep_dly;
}

canonical_original_code:
void nop_delay(unsigned int hstep_dly) {
    g_nop_delay_hstep_dly = hstep_dly;
}


decompiled_code:
__int64 __fastcall service_axis_loop(int *a1)
{
__int64 result; // rax
int v2; // esi
int v3; // edx
int v4; // ebp
int v5; // eax
int v6; // ecx
bool v7; // cc
int v8; // eax

result = (unsigned int)*a1;
if ( (_DWORD)result )
{
if ( (int)result <= 0 )
{
if ( a1[2] >= -g_velmin )
a1[2] = -g_velmin;
v6 = a1[2];
v7 = v6 <= g_accel * (int)result;
v8 = v6 + g_accel;
if ( !v7 )
v8 = a1[2] - g_accel;
if ( -g_velmax > v8 )
v8 = -g_velmax;
a1[2] = v8;
}
else
{
if ( a1[2] <= g_velmin )
a1[2] = g_velmin;
v2 = a1[2];
v3 = v2 + g_accel;
if ( v2 >= g_accel * (int)result / 2 )
v3 = a1[2] - g_accel;
if ( g_velmax < v3 )
v3 = g_velmax;
a1[2] = v3;
}
v4 = vel2halfstep(a1[2]);
nop_delay(v4);
nop_delay(v4);
v5 = *a1;
if ( *a1 <= 0 )
{
result = (unsigned int)(v5 + 1);
*a1 = result;
--a1[1];
}
else
{
result = (unsigned int)(v5 - 1);
*a1 = result;
++a1[1];
}
}
else
{
a1[2] = 0;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(int *a1)
{
__int64 result; // rax
int v2; // esi
int v3; // edx
int v4; // ebp
int v5; // eax
int v6; // ecx
bool v7; // cc
int v8; // eax

result = (unsigned int)*a1;
if ( (_DWORD)result )
{
if ( (int)result <= 0 )
{
if ( a1[2] >= -g_velmin )
a1[2] = -g_velmin;
v6 = a1[2];
v7 = v6 <= g_accel * (int)result;
v8 = v6 + g_accel;
if ( !v7 )
v8 = a1[2] - g_accel;
if ( -g_velmax > v8 )
v8 = -g_velmax;
a1[2] = v8;
}
else
{
if ( a1[2] <= g_velmin )
a1[2] = g_velmin;
v2 = a1[2];
v3 = v2 + g_accel;
if ( v2 >= g_accel * (int)result / 2 )
v3 = a1[2] - g_accel;
if ( g_velmax < v3 )
v3 = g_velmax;
a1[2] = v3;
}
v4 = func7(a1[2]);
func10(v4);
func10(v4);
v5 = *a1;
if ( *a1 <= 0 )
{
result = (unsigned int)(v5 + 1);
*a1 = result;
--a1[1];
}
else
{
result = (unsigned int)(v5 - 1);
*a1 = result;
++a1[1];
}
}
else
{
a1[2] = 0;
}
return result;
}

original_code:
void service_axis_loop(axis_t *axis) {
    unsigned int hstep_dly;
    if (axis->step == 0) {
        ;
        axis->velocity = 0;
        return;
    }
    if (axis->step > 0) {
        if (axis->velocity <= g_velmin) {
            axis->velocity = g_velmin;
        }
        if (axis->velocity >= axis->step * g_accel / 2) {
            axis->velocity -= g_accel;
        } else {
            axis->velocity += g_accel;
        }
        if (axis->velocity > g_velmax) {
            axis->velocity = g_velmax;
        }
    } else {
        if (axis->velocity >= -g_velmin) {
            axis->velocity = -g_velmin;
        }
        if (axis->velocity <= axis->step * g_accel) {
            axis->velocity += g_accel;
        } else {
            axis->velocity -= g_accel;
        }
        if (axis->velocity < -g_velmax) {
            axis->velocity = -g_velmax;
        }
    }
    if (axis->velocity > 0) {
        gpio_clear(axis->dir_gpioport, axis->dir_gpios);
    } else {
        gpio_set(axis->dir_gpioport, axis->dir_gpios);
    }
    hstep_dly = vel2halfstep(axis->velocity);
    gpio_set(axis->step_gpioport, axis->step_gpios);
    nop_delay(hstep_dly);
    gpio_clear(axis->step_gpioport, axis->step_gpios);
    nop_delay(hstep_dly);
    if (axis->step > 0) {
        --axis->step;
        ++axis->stepped;
    } else {
        ++axis->step;
        --axis->stepped;
    }
}

canonical_original_code:
void service_axis_loop(struct axis_t *axis) {
    unsigned int hstep_dly;
    if (axis->step == 0) {
        ;
        axis->velocity = 0;
        return;
    }
    if (axis->step > 0) {
        if (axis->velocity <= g_velmin) {
            axis->velocity = g_velmin;
        }
        if (axis->velocity >= axis->step * g_accel / 2) {
            axis->velocity -= g_accel;
        } else {
            axis->velocity += g_accel;
        }
        if (axis->velocity > g_velmax) {
            axis->velocity = g_velmax;
        }
    } else {
        if (axis->velocity >= -g_velmin) {
            axis->velocity = -g_velmin;
        }
        if (axis->velocity <= axis->step * g_accel) {
            axis->velocity += g_accel;
        } else {
            axis->velocity -= g_accel;
        }
        if (axis->velocity < -g_velmax) {
            axis->velocity = -g_velmax;
        }
    }
    if (axis->velocity > 0) {
        gpio_clear(axis->dir_gpioport, axis->dir_gpios);
    } else {
        gpio_set(axis->dir_gpioport, axis->dir_gpios);
    }
    hstep_dly = vel2halfstep(axis->velocity);
    gpio_set(axis->step_gpioport, axis->step_gpios);
    nop_delay(hstep_dly);
    gpio_clear(axis->step_gpioport, axis->step_gpios);
    nop_delay(hstep_dly);
    if (axis->step > 0) {
        --axis->step;
        ++axis->stepped;
    } else {
        ++axis->step;
        --axis->stepped;
    }
}

variable_types: struct axis_t { int step; int stepped; int velocity; unsigned int step_gpioport; unsigned int step_gpios; unsigned int dir_gpioport; unsigned int dir_gpios; } *


decompiled_code:
__int64 __fastcall service_axis(int *a1)
{
int v1; // ebx
__int64 result; // rax

v1 = 10;
if ( *a1 )
{
do
{
result = service_axis_loop(a1);
--v1;
}
while ( v1 );
}
else
{
a1[2] = 0;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(int *a1)
{
int v1; // ebx
__int64 result; // rax

v1 = 10;
if ( *a1 )
{
do
{
result = func11(a1);
--v1;
}
while ( v1 );
}
else
{
a1[2] = 0;
}
return result;
}

original_code:
void service_axis(axis_t *axis) {
    if (!axis->step) {
        axis->velocity = 0;
        return;
    }
    for (int j = 0; j < 10; ++j) {
        service_axis_loop(axis);
    }
}

canonical_original_code:
void service_axis(struct axis_t *axis) {
    if (!axis->step) {
        axis->velocity = 0;
        return;
    }
    for (int j = 0; j < 10; ++j) {
        service_axis_loop(axis);
    }
}

variable_types: j int

user_defined_types: struct axis_t { int step; int stepped; int velocity; unsigned int step_gpioport; unsigned int step_gpios; unsigned int dir_gpioport; unsigned int dir_gpios; }


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int i; // ebx

g_accel = 325;
g_velmin = 325;
g_velmax = 9250;
g_hstep_c = 740000;
axes = 100;
printf("%4s %8s %8s %8s\n", "i", "step", "vel", "hstp_dly");
for ( i = 0; ; ++i )
{
printf(
"% 4d % 8d % 8d % 8d\n",
i,
(unsigned int)axes,
(unsigned int)dword_404068,
(unsigned int)g_nop_delay_hstep_dly);
if ( !axes )
break;
g_nop_delay_hstep_dly = -1;
service_axis_loop(&axes);
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int i; // ebx

g_accel = 325;
g_velmin = 325;
g_velmax = 9250;
g_hstep_c = 740000;
axes = 100;
printf("%4s %8s %8s %8s\n", "i", "step", "vel", "hstp_dly");
for ( i = 0; ; ++i )
{
printf(
"% 4d % 8d % 8d % 8d\n",
i,
(unsigned int)axes,
(unsigned int)dword_404068,
(unsigned int)g_nop_delay_hstep_dly);
if ( !axes )
break;
g_nop_delay_hstep_dly = -1;
func11(&axes);
}
return 0;
}

original_code:
int main(void) {
    axis_t *axis = &axes[0];
    g_accel = 325;
    g_velmin = 325;
    g_velmax = 9250;
    g_hstep_c = 740000;
    axis->step = 100;
    int i = 0;
    printf("%4s %8s %8s %8s\n", "i", "step", "vel", "hstp_dly");
    while (1) {
        printf("% 4d % 8d % 8d % 8d\n", i, axis->step, axis->velocity, g_nop_delay_hstep_dly);
        if (axis->step == 0) {
            break;
        }
        g_nop_delay_hstep_dly = -1;
        service_axis_loop(axis);
        i += 1;
    }
    return 0;
}

canonical_original_code:
int main() {
    struct axis_t *axis = &axes[0];
    g_accel = 325;
    g_velmin = 325;
    g_velmax = 9250;
    g_hstep_c = 740000;
    axis->step = 100;
    int i = 0;
    printf("%4s %8s %8s %8s\n", "i", "step", "vel", "hstp_dly");
    while (1) {
        printf("% 4d % 8d % 8d % 8d\n", i, axis->step, axis->velocity, g_nop_delay_hstep_dly);
        if (axis->step == 0) {
            break;
        }
        g_nop_delay_hstep_dly = -1;
        service_axis_loop(axis);
        i += 1;
    }
    return 0;
}

variable_types: i int


fastrange

repo: JohnnyonFlame/Worship-Vector

decompiled_code:
__int64 __fastcall fastrange(int a1, int a2)
{
__int64 result; // rax
int v3; // esi

result = abs32(a1);
v3 = abs32(a2);
if ( v3 >= (int)result )
result = (unsigned int)v3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, int a2)
{
__int64 result; // rax
int v3; // esi

result = abs32(a1);
v3 = abs32(a2);
if ( v3 >= (int)result )
result = (unsigned int)v3;
return result;
}

original_code:
Uint32 fastrange(Sint32 argx, Sint32 argy) {
 Sint32 rs0, rs1;
 rs0 = argx;
 rs1 = argy;
 if (rs0 < 0)
  rs0 = -rs0;
 if (rs1 < 0)
  rs1 = -rs1;
 if (rs0 > rs1)
  return rs0;
 else
  return rs1;
}

canonical_original_code:
unsigned int fastrange(int argx, int argy) {
 int rs0; int rs1;
 rs0 = argx;
 rs1 = argy;
 if (rs0 < 0)
  rs0 = -rs0;
 if (rs1 < 0)
  rs1 = -rs1;
 if (rs0 > rs1)
  return rs0;
 else
  return rs1;
}

variable_types: argx int

variable_types: argy int


calcturn

decompiled_code:
__int64 __fastcall calcturn(int a1, int a2)
{
__int64 result; // rax

result = (unsigned int)(a2 - a1);
if ( (int)result > 2048 )
return (unsigned int)(result - 4096);
if ( (int)result < -2048 )
result = (unsigned int)(result + 4096);
return result;
}

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

result = (unsigned int)(a2 - a1);
if ( (int)result > 2048 )
return (unsigned int)(result - 4096);
if ( (int)result < -2048 )
result = (unsigned int)(result + 4096);
return result;
}

original_code:
Sint32 calcturn(Sint32 angle0, Sint32 angle1) {
 Sint32 de = (angle1 - angle0);
 if (de > 2048)
  de = -4096 + de;
 else if (de < -2048)
  de = 4096 + de;
 return de;
}

canonical_original_code:
int calcturn(int angle0, int angle1) {
 int de = (angle1 - angle0);
 if (de > 2048)
  de = -4096 + de;
 else if (de < -2048)
  de = 4096 + de;
 return de;
}

variable_types: de int


zabs

decompiled_code:
__int64 __fastcall zabs(int a1)
{
return abs32(a1);
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
return abs32(a1);
}

original_code:
Sint32 zabs(Sint32 val) {
 if (val >= 0)
  return val;
 else
  return -val;
}

canonical_original_code:
int zabs(int val) {
 if (val >= 0)
  return val;
 else
  return -val;
}

variable_types: val int


SuperAngle

decompiled_code:
__int16 __fastcall SuperAngle(__int16 a1)
{
__int16 result; // ax
__int16 i; // dx

result = a1;
if ( a1 < 0 )
{
do
result += 4096;
while ( result < 0 );
result = (~a1 & 0xF000) + a1 + 4096;
}
if ( result > 4095 )
{
for ( i = result; i > 4095; i -= 4096 )
;
result = result - ((result - 4096) & 0xF000) - 4096;
}
return result;
}

canonical_decompiled_code:
__int16 __fastcall func3(__int16 a1)
{
__int16 result; // ax
__int16 i; // dx

result = a1;
if ( a1 < 0 )
{
do
result += 4096;
while ( result < 0 );
result = (~a1 & 0xF000) + a1 + 4096;
}
if ( result > 4095 )
{
for ( i = result; i > 4095; i -= 4096 )
;
result = result - ((result - 4096) & 0xF000) - 4096;
}
return result;
}

original_code:
Sint16 SuperAngle(Sint32 value) {
 Sint16 val = value;
 while (val < 0)
  val += 4096;
 while (val >= 4096)
  val -= 4096;
 return val;
}

canonical_original_code:
short SuperAngle(int value) {
 short val = value;
 while (val < 0)
  val += 4096;
 while (val >= 4096)
  val -= 4096;
 return val;
}

variable_types: value int

variable_types: val short

return_type: short


decompiled_code:
__int64 random2()
{
unsigned int v0; // edx

v0 = table_rnd[(unsigned __int16)rnd_seed] & 1;
rnd_seed = (rnd_seed + 1) & 0x3FF;
return v0;
}

canonical_decompiled_code:
__int64 func4()
{
unsigned int v0; // edx

v0 = table_rnd[(unsigned __int16)rnd_seed] & 1;
rnd_seed = (rnd_seed + 1) & 0x3FF;
return v0;
}

original_code:
Uint8 random2(void) {
 Uint8 ret = table_rnd[rnd_seed] & 1;
 rnd_seed = rnd_seed + 1;
 rnd_seed = rnd_seed & 1023;
 return ret;
}

canonical_original_code:
unsigned char random2() {
 unsigned char ret = table_rnd[rnd_seed] & 1;
 rnd_seed = rnd_seed + 1;
 rnd_seed = rnd_seed & 1023;
 return ret;
}

variable_types:
ret
unsigned char

return_type: unsigned char


decompiled_code:
__int64 random4()
{
unsigned int v0; // edx

v0 = table_rnd[(unsigned __int16)rnd_seed] & 3;
rnd_seed = (rnd_seed + 1) & 0x3FF;
return v0;
}

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

v0 = table_rnd[(unsigned __int16)rnd_seed] & 3;
rnd_seed = (rnd_seed + 1) & 0x3FF;
return v0;
}

original_code:
Uint8 random4(void) {
 Uint8 ret = table_rnd[rnd_seed] & 3;
 rnd_seed = rnd_seed + 1;
 rnd_seed = rnd_seed & 1023;
 return ret;
}

canonical_original_code:
unsigned char random4() {
 unsigned char ret = table_rnd[rnd_seed] & 3;
 rnd_seed = rnd_seed + 1;
 rnd_seed = rnd_seed & 1023;
 return ret;
}


decompiled_code:
__int64 random8()
{
unsigned int v0; // edx

v0 = table_rnd[(unsigned __int16)rnd_seed] & 7;
rnd_seed = (rnd_seed + 1) & 0x3FF;
return v0;
}

canonical_decompiled_code:
__int64 func6()
{
unsigned int v0; // edx

v0 = table_rnd[(unsigned __int16)rnd_seed] & 7;
rnd_seed = (rnd_seed + 1) & 0x3FF;
return v0;
}

original_code:
Uint8 random8(void) {
 Uint8 ret = table_rnd[rnd_seed] & 7;
 rnd_seed = rnd_seed + 1;
 rnd_seed = rnd_seed & 1023;
 return ret;
}

canonical_original_code:
unsigned char random8() {
 unsigned char ret = table_rnd[rnd_seed] & 7;
 rnd_seed = rnd_seed + 1;
 rnd_seed = rnd_seed & 1023;
 return ret;
}


decompiled_code:
__int64 random16()
{
unsigned int v0; // edx

v0 = table_rnd[(unsigned __int16)rnd_seed] & 0xF;
rnd_seed = (rnd_seed + 1) & 0x3FF;
return v0;
}

canonical_decompiled_code:
__int64 func7()
{
unsigned int v0; // edx

v0 = table_rnd[(unsigned __int16)rnd_seed] & 0xF;
rnd_seed = (rnd_seed + 1) & 0x3FF;
return v0;
}

original_code:
Uint8 random16(void) {
 Uint8 ret = table_rnd[rnd_seed] & 15;
 rnd_seed = rnd_seed + 1;
 rnd_seed = rnd_seed & 1023;
 return ret;
}

canonical_original_code:
unsigned char random16() {
 unsigned char ret = table_rnd[rnd_seed] & 15;
 rnd_seed = rnd_seed + 1;
 rnd_seed = rnd_seed & 1023;
 return ret;
}


decompiled_code:
__int64 random32()
{
unsigned int v0; // edx

v0 = table_rnd[(unsigned __int16)rnd_seed] & 0x1F;
rnd_seed = (rnd_seed + 1) & 0x3FF;
return v0;
}

canonical_decompiled_code:
__int64 func8()
{
unsigned int v0; // edx

v0 = table_rnd[(unsigned __int16)rnd_seed] & 0x1F;
rnd_seed = (rnd_seed + 1) & 0x3FF;
return v0;
}

original_code:
Uint8 random32(void) {
 Uint8 ret = table_rnd[rnd_seed] & 31;
 rnd_seed = rnd_seed + 1;
 rnd_seed = rnd_seed & 1023;
 return ret;
}

canonical_original_code:
unsigned char random32() {
 unsigned char ret = table_rnd[rnd_seed] & 31;
 rnd_seed = rnd_seed + 1;
 rnd_seed = rnd_seed & 1023;
 return ret;
}


decompiled_code:
__int64 random64()
{
unsigned int v0; // edx

v0 = table_rnd[(unsigned __int16)rnd_seed] & 0x3F;
rnd_seed = (rnd_seed + 1) & 0x3FF;
return v0;
}

canonical_decompiled_code:
__int64 func9()
{
unsigned int v0; // edx

v0 = table_rnd[(unsigned __int16)rnd_seed] & 0x3F;
rnd_seed = (rnd_seed + 1) & 0x3FF;
return v0;
}

original_code:
Uint8 random64(void) {
 Uint8 ret = table_rnd[rnd_seed] & 63;
 rnd_seed = rnd_seed + 1;
 rnd_seed = rnd_seed & 1023;
 return ret;
}

canonical_original_code:
unsigned char random64() {
 unsigned char ret = table_rnd[rnd_seed] & 63;
 rnd_seed = rnd_seed + 1;
 rnd_seed = rnd_seed & 1023;
 return ret;
}


decompiled_code:
__int64 random128()
{
unsigned int v0; // edx

v0 = table_rnd[(unsigned __int16)rnd_seed] & 0x7F;
rnd_seed = (rnd_seed + 1) & 0x3FF;
return v0;
}

canonical_decompiled_code:
__int64 func10()
{
unsigned int v0; // edx

v0 = table_rnd[(unsigned __int16)rnd_seed] & 0x7F;
rnd_seed = (rnd_seed + 1) & 0x3FF;
return v0;
}

original_code:
Uint8 random128(void) {
 Uint8 ret = table_rnd[rnd_seed] & 127;
 rnd_seed = rnd_seed + 1;
 rnd_seed = rnd_seed & 1023;
 return ret;
}

canonical_original_code:
unsigned char random128() {
 unsigned char ret = table_rnd[rnd_seed] & 127;
 rnd_seed = rnd_seed + 1;
 rnd_seed = rnd_seed & 1023;
 return ret;
}


decompiled_code:
__int64 random256()
{
unsigned int v0; // edx

v0 = (unsigned __int8)table_rnd[(unsigned __int16)rnd_seed];
rnd_seed = (rnd_seed + 1) & 0x3FF;
return v0;
}

canonical_decompiled_code:
__int64 func11()
{
unsigned int v0; // edx

v0 = (unsigned __int8)table_rnd[(unsigned __int16)rnd_seed];
rnd_seed = (rnd_seed + 1) & 0x3FF;
return v0;
}

original_code:
Uint8 random256(void) {
 Uint8 ret = table_rnd[rnd_seed];
 rnd_seed = rnd_seed + 1;
 rnd_seed = rnd_seed & 1023;
 return ret;
}

canonical_original_code:
unsigned char random256() {
 unsigned char ret = table_rnd[rnd_seed];
 rnd_seed = rnd_seed + 1;
 rnd_seed = rnd_seed & 1023;
 return ret;
}


zsign

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

result = (unsigned int)(a1 >> 31);
if ( a1 > 0 )
result = 1LL;
return result;
}

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

result = (unsigned int)(a1 >> 31);
if ( a1 > 0 )
result = 1LL;
return result;
}

original_code:
Sint32 zsign(Sint32 value) {
 if (value > 0)
  return 1;
 else if (value < 0)
  return -1;
 else
  return 0;
}

canonical_original_code:
int zsign(int value) {
 if (value > 0)
  return 1;
 else if (value < 0)
  return -1;
 else
  return 0;
}


ShutDownCore

decompiled_code:
void ShutDownCore()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
void ShutDownCore(void) {
}

canonical_original_code:
void ShutDownCore() {
}


FreeSound

decompiled_code:
__int64 FreeSound()
{
__int64 *v0; // rbx
__int64 result; // rax

v0 = &d_sound;
do
{
result = Mix_FreeChunk(*v0);
*v0++ = 0LL;
}
while ( v0 != (__int64 *)(unsigned int)((_DWORD)&d_sound + 32) );
if ( music )
{
result = Mix_FreeMusic();
music = 0LL;
}
e_sound = 0LL;
return result;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 *v0; // rbx
__int64 result; // rax

v0 = &d_sound;
do
{
result = Mix_FreeChunk(*v0);
*v0++ = 0LL;
}
while ( v0 != (__int64 *)(unsigned int)((_DWORD)&d_sound + 32) );
if ( music )
{
result = Mix_FreeMusic();
music = 0LL;
}
e_sound = 0LL;
return result;
}

original_code:
void FreeSound(void) {
 int i;
 for (i = 0; i < 4; i++) {
  Mix_FreeChunk(d_sound[i]);
  d_sound[i] = ((void *)0);
 }
 if (music != ((void *)0)) {
  Mix_FreeMusic(music);
  music = ((void *)0);
 }
 e_sound = ((void *)0);
}

canonical_original_code:
void FreeSound() {
 int i;
 for (i = 0; i < 4; i++) {
  Mix_FreeChunk(d_sound[i]);
  d_sound[i] = ((void *)0);
 }
 if (music != ((void *)0)) {
  Mix_FreeMusic(music);
  music = ((void *)0);
 }
 e_sound = ((void *)0);
}


Terminate

decompiled_code:
void Terminate(void)
{
FreeSound();
Mix_CloseAudio();
SDL_Quit();
}

canonical_decompiled_code:
void func2(void)
{
func1();
Mix_CloseAudio();
SDL_Quit();
}

canonical_original_code:
void Terminate() {
 FreeSound();
 Mix_CloseAudio();
 SDL_Quit();
}


PlayMusic

decompiled_code:
void __fastcall PlayMusic(char a1)
{
if ( a1 == (char)0x80 )
{
Mix_PauseMusic();
}
else
{
switch ( a1 )
{
case 1:
sprintf(spath, "DataSmasher.ogg", 1LL);
break;
case 2:
sprintf(spath, "Defense.ogg", 2LL);
break;
case 0:
sprintf(spath, "MainControl.ogg", 0LL);
break;
}
if ( musicon )
{
if ( music )
Mix_FreeMusic();
music = Mix_LoadMUS(spath);
if ( !music )
printf("File not found: %s\n", spath);
Mix_PlayMusic(music, 0xFFFFFFFFLL);
}
}
MusicPlaying = a1;
}

canonical_decompiled_code:
void __fastcall func3(char a1)
{
if ( a1 == (char)0x80 )
{
Mix_PauseMusic();
}
else
{
switch ( a1 )
{
case 1:
sprintf(spath, "DataSmasher.ogg", 1LL);
break;
case 2:
sprintf(spath, "Defense.ogg", 2LL);
break;
case 0:
sprintf(spath, "MainControl.ogg", 0LL);
break;
}
if ( musicon )
{
if ( music )
Mix_FreeMusic();
music = Mix_LoadMUS(spath);
if ( !music )
printf("File not found: %s\n", spath);
Mix_PlayMusic(music, 0xFFFFFFFFLL);
}
}
MusicPlaying = a1;
}

original_code:
void PlayMusic(unsigned char itrack) {
 if (itrack == 128)
  Mix_PauseMusic();
 else {
  switch (itrack) {
  case 0:
   sprintf(spath, "MainControl.ogg", itrack);
   break;
  case 1:
   sprintf(spath, "DataSmasher.ogg", itrack);
   break;
  case 2:
   sprintf(spath, "Defense.ogg", itrack);
   break;
  }
  if (musicon) {
   if (music != ((void *)0)) {
    Mix_FreeMusic(music);
   }
   music = Mix_LoadMUS(spath);
   if (music == ((void *)0)) {
    printf("File not found: %s\n", spath);
   }
   if (Mix_PlayMusic(music, -1)) {
   }
  }
 }
 MusicPlaying = itrack;
}

variable_types:
itrack
unsigned char


LoadSound

decompiled_code:
void LoadSound()
{
__int64 v0; // rax
__int64 v1; // rax
__int64 v2; // rax
__int64 v3; // rax

v0 = SDL_RWFromFile("Click.wav", "rb");
d_sound = Mix_LoadWAV_RW(v0, 1LL);
v1 = SDL_RWFromFile("Beep.wav", "rb");
*(&d_sound + 1) = Mix_LoadWAV_RW(v1, 1LL);
v2 = SDL_RWFromFile("Order.wav", "rb");
*(&d_sound + 2) = Mix_LoadWAV_RW(v2, 1LL);
v3 = SDL_RWFromFile("Victory.wav", "rb");
*(&d_sound + 3) = Mix_LoadWAV_RW(v3, 1LL);
PlayMusic(0);
}

canonical_decompiled_code:
void func4()
{
__int64 v0; // rax
__int64 v1; // rax
__int64 v2; // rax
__int64 v3; // rax

v0 = SDL_RWFromFile("Click.wav", "rb");
d_sound = Mix_LoadWAV_RW(v0, 1LL);
v1 = SDL_RWFromFile("Beep.wav", "rb");
*(&d_sound + 1) = Mix_LoadWAV_RW(v1, 1LL);
v2 = SDL_RWFromFile("Order.wav", "rb");
*(&d_sound + 2) = Mix_LoadWAV_RW(v2, 1LL);
v3 = SDL_RWFromFile("Victory.wav", "rb");
*(&d_sound + 3) = Mix_LoadWAV_RW(v3, 1LL);
func3(0);
}

original_code:
void LoadSound(void) {
 int i;
 d_sound[0] = Mix_LoadWAV_RW(SDL_RWFromFile("Click.wav", "rb"), 1);
 d_sound[1] = Mix_LoadWAV_RW(SDL_RWFromFile("Beep.wav", "rb"), 1);
 d_sound[2] = Mix_LoadWAV_RW(SDL_RWFromFile("Order.wav", "rb"), 1);
 d_sound[3] = Mix_LoadWAV_RW(SDL_RWFromFile("Victory.wav", "rb"), 1);
 for (i = 0; i < 4; i++) {
  if (d_sound[i] == ((void *)0)) {
  }
 }
 PlayMusic(0);
}

canonical_original_code:
void LoadSound() {
 int i;
 d_sound[0] = Mix_LoadWAV_RW(SDL_RWFromFile("Click.wav", "rb"), 1);
 d_sound[1] = Mix_LoadWAV_RW(SDL_RWFromFile("Beep.wav", "rb"), 1);
 d_sound[2] = Mix_LoadWAV_RW(SDL_RWFromFile("Order.wav", "rb"), 1);
 d_sound[3] = Mix_LoadWAV_RW(SDL_RWFromFile("Victory.wav", "rb"), 1);
 for (i = 0; i < 4; i++) {
  if (d_sound[i] == ((void *)0)) {
  }
 }
 PlayMusic(0);
}


PlaySound

decompiled_code:
__int64 __fastcall PlaySound(unsigned __int8 a1)
{
__int64 result; // rax

if ( soundon )
result = Mix_PlayChannelTimed(0xFFFFFFFFLL, d_sound[a1], 0LL, 0xFFFFFFFFLL);
return result;
}

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

if ( soundon )
result = Mix_PlayChannelTimed(0xFFFFFFFFLL, d_sound[a1], 0LL, 0xFFFFFFFFLL);
return result;
}

original_code:
void PlaySound(unsigned char ibank, signed char pan) {
 if (soundon) {
  if (Mix_PlayChannelTimed(-1,d_sound[ibank],0,-1) == -1) {
  }
 }
}

canonical_original_code:
void PlaySound(unsigned char ibank, char pan) {
 if (soundon) {
  if (Mix_PlayChannelTimed(-1,d_sound[ibank],0,-1) == -1) {
  }
 }
}

variable_types:
ibank
unsigned char

variable_types: pan char


PlaySoundEx

decompiled_code:
__int64 __fastcall PlaySoundEx(unsigned __int8 a1)
{
__int64 v1; // rax

sprintf(spath, "data/e%i.wav", a1);
Mix_SetPanning(0LL, 127LL, 127LL);
v1 = SDL_RWFromFile(spath, "rb");
e_sound = Mix_LoadWAV_RW(v1, 1LL);
return Mix_PlayChannelTimed(0xFFFFFFFFLL, e_sound, 0LL, 0xFFFFFFFFLL);
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned __int8 a1)
{
__int64 v1; // rax

sprintf(spath, "data/e%i.wav", a1);
Mix_SetPanning(0LL, 127LL, 127LL);
v1 = SDL_RWFromFile(spath, "rb");
e_sound = Mix_LoadWAV_RW(v1, 1LL);
return Mix_PlayChannelTimed(0xFFFFFFFFLL, e_sound, 0LL, 0xFFFFFFFFLL);
}

original_code:
void PlaySoundEx(unsigned char ibank, signed char pan) {
 sprintf(spath, "data/e%i.wav", ibank);
 Mix_SetPanning(0, 127, 127);
 e_sound = Mix_LoadWAV_RW(SDL_RWFromFile(spath, "rb"), 1);
 Mix_PlayChannelTimed(-1,e_sound,0,-1);
}

canonical_original_code:
void PlaySoundEx(unsigned char ibank, char pan) {
 sprintf(spath, "data/e%i.wav", ibank);
 Mix_SetPanning(0, 127, 127);
 e_sound = Mix_LoadWAV_RW(SDL_RWFromFile(spath, "rb"), 1);
 Mix_PlayChannelTimed(-1,e_sound,0,-1);
}


SetVolume

decompiled_code:
void __fastcall SetVolume(char a1)
{
volume = a1;
}

canonical_decompiled_code:
void __fastcall func7(char a1)
{
volume = a1;
}

original_code:
void SetVolume(unsigned char ivolume) {
 volume = ivolume;
}

variable_types:
ivolume
unsigned char


InitGameCore

decompiled_code:
void InitGameCore()
{
const char *v0; // rax
const char *v1; // rax
const char *v2; // rax

InitMath();
atexit(Terminate);
if ( (int)SDL_Init(560LL) < 0 )
{
v0 = (const char *)SDL_GetError();
fprintf(stderr, "Couldn't initialize SDL: %s\n", v0);
exit(1);
}
if ( (unsigned int)Mix_QuerySpec(&audio_rate, &audio_format, &audio_channels) )
{
v1 = (const char *)SDL_GetError();
printf("Mix_QuerySpec: %s\n", v1);
}
if ( (unsigned int)Mix_OpenAudio(
(unsigned int)audio_rate,
(unsigned __int16)audio_format,
(unsigned int)audio_channels,
(unsigned int)audio_buffers) )
{
puts("Unable to open audio!");
exit(1);
}
SDL_ShowCursor(0LL);
screen = SDL_SetVideoMode(320LL, 240LL, 32LL, 1073741825LL);
InitPalette();
if ( (int)SDL_NumJoysticks() > 0 )
{
joy = SDL_JoystickOpen(0LL);
if ( !joy )
{
v2 = (const char *)SDL_GetError();
fprintf(stderr, "Couldn't open joystick 0: %s\n", v2);
}
}
LoadSound();
SetVolume(volume);
}

canonical_decompiled_code:
void func8()
{
const char *v0; // rax
const char *v1; // rax
const char *v2; // rax

InitMath();
atexit(Terminate);
if ( (int)SDL_Init(560LL) < 0 )
{
v0 = (const char *)SDL_GetError();
fprintf(stderr, "Couldn't initialize SDL: %s\n", v0);
exit(1);
}
if ( (unsigned int)Mix_QuerySpec(&audio_rate, &audio_format, &audio_channels) )
{
v1 = (const char *)SDL_GetError();
printf("Mix_QuerySpec: %s\n", v1);
}
if ( (unsigned int)Mix_OpenAudio(
(unsigned int)audio_rate,
(unsigned __int16)audio_format,
(unsigned int)audio_channels,
(unsigned int)audio_buffers) )
{
puts("Unable to open audio!");
exit(1);
}
SDL_ShowCursor(0LL);
screen = SDL_SetVideoMode(320LL, 240LL, 32LL, 1073741825LL);
InitPalette();
if ( (int)SDL_NumJoysticks() > 0 )
{
joy = SDL_JoystickOpen(0LL);
if ( !joy )
{
v2 = (const char *)SDL_GetError();
fprintf(stderr, "Couldn't open joystick 0: %s\n", v2);
}
}
func4();
func7(volume);
}

original_code:
void InitGameCore(void) {
 InitMath();
 atexit(Terminate);
 if (SDL_Init(0x00000020 | 0x00000010 | 0x00000200) < 0) {
  fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
  exit(1);
 }
 if (Mix_QuerySpec(&audio_rate, &audio_format, &audio_channels)) {
  printf("Mix_QuerySpec: %s\n", SDL_GetError());
 }
 if (Mix_OpenAudio(audio_rate, audio_format, audio_channels,
   audio_buffers)) {
  printf("Unable to open audio!\n");
  exit(1);
 }
 SDL_ShowCursor(0);
 screen = SDL_SetVideoMode (320, 240, 32, 0x00000001 | 0x40000000);
 InitPalette();
 if (SDL_NumJoysticks() > 0) {
  joy = SDL_JoystickOpen(0);
  if (!joy) {
   fprintf(stderr, "Couldn't open joystick 0: %s\n", SDL_GetError());
  }
 }
 LoadSound();
 SetVolume(volume);
}

canonical_original_code:
void InitGameCore() {
 InitMath();
 atexit(Terminate);
 if (SDL_Init(0x00000020 | 0x00000010 | 0x00000200) < 0) {
  fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
  exit(1);
 }
 if (Mix_QuerySpec(&audio_rate, &audio_format, &audio_channels)) {
  printf("Mix_QuerySpec: %s\n", SDL_GetError());
 }
 if (Mix_OpenAudio(audio_rate, audio_format, audio_channels,
   audio_buffers)) {
  printf("Unable to open audio!\n");
  exit(1);
 }
 SDL_ShowCursor(0);
 screen = SDL_SetVideoMode (320, 240, 32, 0x00000001 | 0x40000000);
 InitPalette();
 if (SDL_NumJoysticks() > 0) {
  joy = SDL_JoystickOpen(0);
  if (!joy) {
   fprintf(stderr, "Couldn't open joystick 0: %s\n", SDL_GetError());
  }
 }
 LoadSound();
 SetVolume(volume);
}


GameCoreTick

decompiled_code:
__int64 GameCoreTick()
{
__int64 v0; // r8
unsigned __int8 *v1; // rdi
__int64 i; // rcx
__int64 v3; // rsi
__int64 v4; // rdx
__int64 result; // rax

CoreProcInput();
SDL_LockSurface(screen);
v0 = *(_QWORD *)(screen + 32);
v1 = (unsigned __int8 *)&scrbuf;
do
{
for ( i = 0LL; i != 320; ++i )
{
v3 = 3LL * v1[i];
v4 = (*((unsigned __int8 *)&palette + v3 + 1) << 8) + (unsigned int)*((unsigned __int8 *)&palette + v3 + 2);
*(_DWORD *)(v0 + 4 * i) = v4 + (*((unsigned __int8 *)&palette + v3) << 16);
}
v1 += 320;
v0 += 1280LL;
}
while ( v1 != (unsigned __int8 *)((char *)&scrbuf + 76800) );
SDL_UnlockSurface(screen, v3, v4, 320LL, v0);
SDL_Flip(screen);
if ( gamespeed > 0 )
SDL_Delay((unsigned int)(10 * gamespeed));
voiceon = 0;
result = Mix_Playing(0LL);
if ( (_DWORD)result )
voiceon = 1;
return result;
}

canonical_decompiled_code:
__int64 func10()
{
__int64 v0; // r8
unsigned __int8 *v1; // rdi
__int64 i; // rcx
__int64 v3; // rsi
__int64 v4; // rdx
__int64 result; // rax

func9();
SDL_LockSurface(screen);
v0 = *(_QWORD *)(screen + 32);
v1 = (unsigned __int8 *)&scrbuf;
do
{
for ( i = 0LL; i != 320; ++i )
{
v3 = 3LL * v1[i];
v4 = (*((unsigned __int8 *)&palette + v3 + 1) << 8) + (unsigned int)*((unsigned __int8 *)&palette + v3 + 2);
*(_DWORD *)(v0 + 4 * i) = v4 + (*((unsigned __int8 *)&palette + v3) << 16);
}
v1 += 320;
v0 += 1280LL;
}
while ( v1 != (unsigned __int8 *)((char *)&scrbuf + 76800) );
SDL_UnlockSurface(screen, v3, v4, 320LL, v0);
SDL_Flip(screen);
if ( gamespeed > 0 )
SDL_Delay((unsigned int)(10 * gamespeed));
voiceon = 0;
result = Mix_Playing(0LL);
if ( (_DWORD)result )
voiceon = 1;
return result;
}

original_code:
void GameCoreTick(void) {
 CoreProcInput();
 SDL_LockSurface(screen);
 int i, j;
 Uint32 *dest = screen->pixels;
 Uint8 *src = &scrbuf;
 int t;
 for (j=0; j<240; j++)
  for (i=0; i<320; i++)
  {
   t = *src++;
   *dest++ = palette[t][2] + (palette[t][1]<<8) + (palette[t][0]<<16);
  }
 SDL_UnlockSurface(screen);
 SDL_Flip(screen);
 if (gamespeed > 0)
  SDL_Delay(gamespeed * 10);
 voiceon = 0;
 if (Mix_Playing(0)) {
  voiceon = 1;
 } else {
 }
}

canonical_original_code:
void GameCoreTick() {
 CoreProcInput();
 SDL_LockSurface(screen);
 int i; int j;
 unsigned int *dest = screen->pixels;
 unsigned char *src = &scrbuf;
 int t;
 for (j=0; j<240; j++)
  for (i=0; i<320; i++)
  {
   t = *src++;
   *dest++ = palette[t][2] + (palette[t][1]<<8) + (palette[t][0]<<16);
  }
 SDL_UnlockSurface(screen);
 SDL_Flip(screen);
 if (gamespeed > 0)
  SDL_Delay(gamespeed * 10);
 voiceon = 0;
 if (Mix_Playing(0)) {
  voiceon = 1;
 } else {
 }
}

variable_types:
dest
unsigned int *

variable_types:
src
unsigned char *

variable_types: t int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
InitGameCore(argc, argv, envp);
InitGame();
StartGameLoop();
ShutDownCore();
return 0;
}

original_code:
int main(int argc, char *argv[]) {
 InitGameCore();
 InitGame();
 StartGameLoop();
 ShutDownCore();
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


StartGameLoop

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

for ( ; GameLoopEnabled; ++count )
{
GameFrame();
result = GameCoreTick();
}
return result;
}

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

for ( ; GameLoopEnabled; ++count )
{
GameFrame();
result = GameCoreTick();
}
return result;
}

original_code:
void StartGameLoop(void) {
 while (GameLoopEnabled) {
  GameFrame();
  GameCoreTick();
  count++;
 }
}

canonical_original_code:
void StartGameLoop() {
 while (GameLoopEnabled) {
  GameFrame();
  GameCoreTick();
  count++;
 }
}


InitGame

decompiled_code:
__int64 InitGame()
{
__int16 v0; // dx
__int64 i; // rax
__int64 j; // rax

v0 = 1;
for ( i = 0LL; (unsigned __int16)i <= 0xEFu; ++i )
{
*((_BYTE *)&NextColor0 + i) = i + 16;
LABEL_3:
++v0;
}
*((_BYTE *)&NextColor0 + i) = i;
if ( (unsigned __int16)v0 <= 0xFFu )
goto LABEL_3;
for ( j = 0LL; j != 256; ++j )
*((_BYTE *)&NextColor2 + j) = *((_BYTE *)&NextColor0
+ *((unsigned __int8 *)&NextColor0 + *((unsigned __int8 *)&NextColor0 + j)));
return ResetMap();
}

canonical_decompiled_code:
__int64 func0()
{
__int16 v0; // dx
__int64 i; // rax
__int64 j; // rax

v0 = 1;
for ( i = 0LL; (unsigned __int16)i <= 0xEFu; ++i )
{
*((_BYTE *)&NextColor0 + i) = i + 16;
LABEL_3:
++v0;
}
*((_BYTE *)&NextColor0 + i) = i;
if ( (unsigned __int16)v0 <= 0xFFu )
goto LABEL_3;
for ( j = 0LL; j != 256; ++j )
*((_BYTE *)&NextColor2 + j) = *((_BYTE *)&NextColor0
+ *((unsigned __int8 *)&NextColor0 + *((unsigned __int8 *)&NextColor0 + j)));
return ResetMap();
}

original_code:
void InitGame(void) {
 Uint16 i;
 for (i = 0; i < 256; i++) {
  if (i < 240)
   NextColor0[i] = i + 16;
  else
   NextColor0[i] = i;
 }
 for (i = 0; i < 256; i++)
  NextColor2[i] = NextColor0[NextColor0[NextColor0[i]]];
 ResetMap();
}

canonical_original_code:
void InitGame() {
 unsigned short i;
 for (i = 0; i < 256; i++) {
  if (i < 240)
   NextColor0[i] = i + 16;
  else
   NextColor0[i] = i;
 }
 for (i = 0; i < 256; i++)
  NextColor2[i] = NextColor0[NextColor0[NextColor0[i]]];
 ResetMap();
}

variable_types:
i
unsigned short


DrawLine

canonical_original_code:
void DrawLine(short x0, short y0, short x1, short y1, unsigned char color) {
 int x; int y; int i; int ii; int s; int nsx; int nsy;
 unsigned char onscreen = 1;
 if (x0 < 0)
  if (x1 < 0)
   onscreen = 0;
 if (x0 > 319)
  if (x1 > 319)
   onscreen = 0;
 if (y0 < 0)
  if (y1 < 0)
   onscreen = 0;
 if (y0 > 239)
  if (y1 > 239)
   onscreen = 0;
 if (x0 == x1)
  if (y0 == y1)
   onscreen = 0;
 if (onscreen) {
  if (zabs(y1 - y0) > zabs(x1 - x0))
   s = zabs(y1 - y0);
  else
   s = zabs(x1 - x0);
  nsx = (x1 - x0) * 65536 / s;
  nsy = (y1 - y0) * 65536 / s;
  x = x0 << 16;
  y = y0 << 16;
  for (i = 0; i < s; i++) {
   x = x + nsx;
   y = y + nsy;
   ii = (x >> 16) + (y >> 16) * 320;
   if ((ii >= 0) & (ii < 76800))
    if (x >= 0)
     if (x < 20971520)
      scrbuf[ii] = color;
  }
 }
}

variable_types:
color
unsigned char

variable_types: x int

variable_types: y int

variable_types: i int

variable_types: ii int

variable_types: s int

variable_types: nsx int

variable_types: nsy int

variable_types:
onscreen
unsigned char


canonical_original_code:
void DrawLine2(short x0, short y0, short x1, short y1, unsigned char color) {
 int x; int y; int i; int ii; int s; int nsx; int nsy;
 unsigned char onscreen = 1;
 if (x0 < 0)
  if (x1 < 0)
   onscreen = 0;
 if (x0 > 319)
  if (x1 > 319)
   onscreen = 0;
 if (y0 < 0)
  if (y1 < 0)
   onscreen = 0;
 if (y0 > 239)
  if (y1 > 239)
   onscreen = 0;
 if (x0 == x1)
  if (y0 == y1)
   onscreen = 0;
 if (onscreen) {
  if (zabs(y1 - y0) > zabs(x1 - x0))
   s = zabs(y1 - y0);
  else
   s = zabs(x1 - x0);
  nsx = (x1 - x0) * 65536 / s;
  nsy = (y1 - y0) * 65536 / s;
  x = x0 << 16;
  y = y0 << 16;
  for (i = 0; i < s; i++) {
   x = x + nsx;
   y = y + nsy;
   ii = (x >> 16) + (y >> 16) * 320;
   if ((ii >= 320) & (ii < 76480))
    if (x >= 65536)
     if (x < 20905984) {
      scrbuf[ii - 1] = color;
      scrbuf[ii - 320] = color;
      scrbuf[ii + 1] = color;
      scrbuf[ii + 320] = color;
     }
  }
 }
}


DarkRect

decompiled_code:
unsigned __int64 __fastcall DarkRect(__int16 a1, __int16 a2, __int16 a3, unsigned int a4)
{
unsigned __int64 result; // rax
int v7; // ecx
int v8; // esi
__int64 v9; // r8
_BYTE *v10; // rcx
int v11; // edi
int v12; // edi
__int64 v13; // r8

result = a4;
if ( a2 <= (__int16)a4 )
{
v7 = 320 * a2;
v8 = a1 + v7;
v9 = (unsigned int)(a3 - a1);
v10 = &scrbuf[v9 + 1 + a1 + v7];
v11 = a1 + 320 * (a2 + (__int16)result) + 320;
result = (unsigned int)(320 * a2);
v12 = v11 - result;
v13 = ~v9;
do
{
if ( a1 <= a3 )
{
result = (unsigned __int64)&v10[v13];
do
{
*(_BYTE *)result = *((_BYTE *)&NextColor2 + *(unsigned __int8 *)result);
++result;
}
while ( (_BYTE *)result != v10 );
}
v8 += 320;
v10 += 320;
}
while ( v8 != v12 );
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func2(__int16 a1, __int16 a2, __int16 a3, unsigned int a4)
{
unsigned __int64 result; // rax
int v7; // ecx
int v8; // esi
__int64 v9; // r8
_BYTE *v10; // rcx
int v11; // edi
int v12; // edi
__int64 v13; // r8

result = a4;
if ( a2 <= (__int16)a4 )
{
v7 = 320 * a2;
v8 = a1 + v7;
v9 = (unsigned int)(a3 - a1);
v10 = &scrbuf[v9 + 1 + a1 + v7];
v11 = a1 + 320 * (a2 + (__int16)result) + 320;
result = (unsigned int)(320 * a2);
v12 = v11 - result;
v13 = ~v9;
do
{
if ( a1 <= a3 )
{
result = (unsigned __int64)&v10[v13];
do
{
*(_BYTE *)result = *((_BYTE *)&NextColor2 + *(unsigned __int8 *)result);
++result;
}
while ( (_BYTE *)result != v10 );
}
v8 += 320;
v10 += 320;
}
while ( v8 != v12 );
}
return result;
}

original_code:
void DarkRect(Sint16 x0, Sint16 y0, Sint16 x1, Sint16 y1) {
 Sint32 x, y, i, ii;
 for (y = y0; y <= y1; y++) {
  ii = x0 + y * 320;
  for (x = x0; x <= x1; x++) {
   scrbuf[ii] = NextColor2[scrbuf[ii]];
   ii++;
  }
 }
}

canonical_original_code:
void DarkRect(short x0, short y0, short x1, short y1) {
 int x; int y; int i; int ii;
 for (y = y0; y <= y1; y++) {
  ii = x0 + y * 320;
  for (x = x0; x <= x1; x++) {
   scrbuf[ii] = NextColor2[scrbuf[ii]];
   ii++;
  }
 }
}


decompiled_code:
void __fastcall s_drawtext(__int16 a1, __int16 a2, char a3)
{
char v4; // r13
unsigned int v5; // ebp
unsigned int v6; // er11
int v7; // ebx
__int64 v8; // r12
int v9; // edi
unsigned int v10; // eax
unsigned int v11; // ecx
unsigned int v12; // edx
unsigned int v13; // esi
int v14; // er10

if ( l_textstring )
{
v4 = l_textstring;
if ( l_textstring > 0 )
{
v5 = a1;
v6 = a2;
v7 = 320 * a2;
v8 = 0LL;
v9 = a2 + 16;
do
{
v14 = ((*((char *)&s_textstring + v8) / 16) << 12) + 16 * (*((char *)&s_textstring + v8) % 16) - v5;
v13 = v5;
do
{
v11 = v7 + v13;
v12 = v13 + v14;
v10 = v6;
do
{
if ( v10 <= 0xEF && v13 <= 0x13F )
{
if ( sfont[v12] )
scrbuf[v11] = a3;
}
++v10;
v11 += 320;
v12 += 256;
}
while ( v10 != v9 );
++v13;
}
while ( v13 != v5 + 16 );
++v8;
v5 += 8;
}
while ( v4 > (int)v8 );
}
}
}

canonical_decompiled_code:
void __fastcall func4(__int16 a1, __int16 a2, char a3)
{
char v4; // r13
unsigned int v5; // ebp
unsigned int v6; // er11
int v7; // ebx
__int64 v8; // r12
int v9; // edi
unsigned int v10; // eax
unsigned int v11; // ecx
unsigned int v12; // edx
unsigned int v13; // esi
int v14; // er10

if ( l_textstring )
{
v4 = l_textstring;
if ( l_textstring > 0 )
{
v5 = a1;
v6 = a2;
v7 = 320 * a2;
v8 = 0LL;
v9 = a2 + 16;
do
{
v14 = ((*((char *)&s_textstring + v8) / 16) << 12) + 16 * (*((char *)&s_textstring + v8) % 16) - v5;
v13 = v5;
do
{
v11 = v7 + v13;
v12 = v13 + v14;
v10 = v6;
do
{
if ( v10 <= 0xEF && v13 <= 0x13F )
{
if ( sfont[v12] )
scrbuf[v11] = a3;
}
++v10;
v11 += 320;
v12 += 256;
}
while ( v10 != v9 );
++v13;
}
while ( v13 != v5 + 16 );
++v8;
v5 += 8;
}
while ( v4 > (int)v8 );
}
}
}

original_code:
void s_drawtext(Sint16 x, Sint16 y, Uint8 c) {
 int x1, y1, cx, cy, x2, y2, i, ix, iy;
 if (l_textstring != 0)
  for (i = 0; i < l_textstring; i++) {
   x1 = x + i * 8;
   y1 = y;
   x2 = s_textstring[i] % 16 * 16;
   y2 = s_textstring[i] / 16 * 16;
   for (ix = 0; ix < 16; ix++)
    for (iy = 0; iy < 16; iy++) {
     cx = x1 + ix;
     cy = y1 + iy;
     if ((cx >= 0) && (cy >= 0) && (cx < 320) && (cy < 240)) {
      if (sfont[x2 + ix + (iy + y2) * 256])
       scrbuf[cx + cy * 320] = c;
     }
    }
  }
}

canonical_original_code:
void s_drawtext(short x, short y, unsigned char c) {
 int x1; int y1; int cx; int cy; int x2; int y2; int i; int ix; int iy;
 if (l_textstring != 0)
  for (i = 0; i < l_textstring; i++) {
   x1 = x + i * 8;
   y1 = y;
   x2 = s_textstring[i] % 16 * 16;
   y2 = s_textstring[i] / 16 * 16;
   for (ix = 0; ix < 16; ix++)
    for (iy = 0; iy < 16; iy++) {
     cx = x1 + ix;
     cy = y1 + iy;
     if ((cx >= 0) && (cy >= 0) && (cx < 320) && (cy < 240)) {
      if (sfont[x2 + ix + (iy + y2) * 256])
       scrbuf[cx + cy * 320] = c;
     }
    }
  }
}

variable_types: x short

variable_types: y short

variable_types:
c
unsigned char

variable_types: cx int

variable_types: cy int

variable_types: ix int

variable_types: iy int


SpawnMob

decompiled_code:
__int64 SpawnMob()
{
__int64 result; // rax
int v1; // ecx
__int64 v2; // rcx
_DWORD *v3; // rsi
__int64 v4; // rdx
int v5; // eax

if ( mob[0] <= 0 )
{
v1 = 0;
LABEL_6:
v2 = (__int64)v1 << 6;
v3 = (int *)((char *)mob + v2);
v4 = 32LL * wave;
*(int *)((char *)mob + v2) = *(_DWORD *)((char *)&iwavedata + v4 + 4);
*(int *)((char *)&mob[1] + v2) = *(_DWORD *)((char *)&iwavedata + v4 + 12);
*(int *)((char *)&mob[2] + v2) = *(_DWORD *)((char *)&iwavedata + v4 + 8);
*(int *)((char *)&mob[3] + v2) = *(_DWORD *)((char *)&iwavedata + v4 + 16);
LODWORD(v2) = spawnx;
v3[4] = spawnx;
v5 = spawny;
v3[5] = spawny;
v3[6] = *(_DWORD *)((char *)&iwavedata + v4 + 24);
result = (unsigned int)(dirmap[32 * ((int)v2 / 0x20000) + v5 / 0x20000] << 10);
v3[7] = result;
v3[10] = 0;
goto LABEL_7;
}
LODWORD(result) = 0;
do
{
result = (unsigned int)(result + 1);
v1 = (unsigned __int8)result;
}
while ( mob[16 * (unsigned __int64)(unsigned __int8)result] > 0 && (result & 0x80u) == 0LL );
if ( (result & 0x80u) == 0LL )
goto LABEL_6;
LABEL_7:
zl_vibro = 10;
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 result; // rax
int v1; // ecx
__int64 v2; // rcx
_DWORD *v3; // rsi
__int64 v4; // rdx
int v5; // eax

if ( mob[0] <= 0 )
{
v1 = 0;
LABEL_6:
v2 = (__int64)v1 << 6;
v3 = (int *)((char *)mob + v2);
v4 = 32LL * wave;
*(int *)((char *)mob + v2) = *(_DWORD *)((char *)&iwavedata + v4 + 4);
*(int *)((char *)&mob[1] + v2) = *(_DWORD *)((char *)&iwavedata + v4 + 12);
*(int *)((char *)&mob[2] + v2) = *(_DWORD *)((char *)&iwavedata + v4 + 8);
*(int *)((char *)&mob[3] + v2) = *(_DWORD *)((char *)&iwavedata + v4 + 16);
LODWORD(v2) = spawnx;
v3[4] = spawnx;
v5 = spawny;
v3[5] = spawny;
v3[6] = *(_DWORD *)((char *)&iwavedata + v4 + 24);
result = (unsigned int)(dirmap[32 * ((int)v2 / 0x20000) + v5 / 0x20000] << 10);
v3[7] = result;
v3[10] = 0;
goto LABEL_7;
}
LODWORD(result) = 0;
do
{
result = (unsigned int)(result + 1);
v1 = (unsigned __int8)result;
}
while ( mob[16 * (unsigned __int64)(unsigned __int8)result] > 0 && (result & 0x80u) == 0LL );
if ( (result & 0x80u) == 0LL )
goto LABEL_6;
LABEL_7:
zl_vibro = 10;
return result;
}

original_code:
void SpawnMob(void) {
 Uint8 i = 0;
 while ((mob[i][0] > 0) & (i < 128))
  i++;
 if (i < 128) {
  mob[i][0] = iwavedata[wave][1];
  mob[i][1] = iwavedata[wave][3];
  mob[i][2] = iwavedata[wave][2];
  mob[i][3] = iwavedata[wave][4];
  mob[i][4] = spawnx;
  mob[i][5] = spawny;
  mob[i][6] = iwavedata[wave][6];
  mob[i][7] = 1024 * dirmap[spawnx / 65536 / 2][spawny / 65536 / 2];
  mob[i][10] = 0;
 }
 zl_vibro = 10;
}

canonical_original_code:
void SpawnMob() {
 unsigned char i = 0;
 while ((mob[i][0] > 0) & (i < 128))
  i++;
 if (i < 128) {
  mob[i][0] = iwavedata[wave][1];
  mob[i][1] = iwavedata[wave][3];
  mob[i][2] = iwavedata[wave][2];
  mob[i][3] = iwavedata[wave][4];
  mob[i][4] = spawnx;
  mob[i][5] = spawny;
  mob[i][6] = iwavedata[wave][6];
  mob[i][7] = 1024 * dirmap[spawnx / 65536 / 2][spawny / 65536 / 2];
  mob[i][10] = 0;
 }
 zl_vibro = 10;
}

variable_types:
i
unsigned char


MobModel

decompiled_code:
__int64 __fastcall MobModel(unsigned __int8 a1)
{
int v1; // eax
unsigned __int64 v2; // rdi
int v3; // edx
unsigned __int8 v4; // bl
__int64 result; // rax

v1 = a1;
v2 = (unsigned __int64)a1 << 6;
v3 = *(int *)((char *)&mob[2] + v2);
if ( *(int *)((char *)&mob[10] + v2) )
{
mob[16 * (__int64)v1 + 10] = 0;
v4 = 15;
}
else
{
v4 = mob[16 * (__int64)v1 + 1];
}
result = (unsigned __int8)v3;
if ( (_BYTE)v3 == 1 )
{
zlvertex = 0;
zlpoint(0x8000LL, 0LL, 0LL);
zlvertex = 1;
zlpoint(4294934528LL, 0LL, 0LL);
zlvertex = 2;
result = zlpoint(0LL, 60000LL, 0LL);
if ( vbufferz > 20000 && vvis )
goto LABEL_10;
}
else if ( (unsigned __int8)v3 == 2 )
{
zlvertex = 0;
zlpoint(0x8000LL, 0LL, 4294934528LL);
zlvertex = 1;
zlpoint(4294934528LL, 0LL, 4294934528LL);
zlvertex = 2;
zlpoint(4294934528LL, 0LL, 0x8000LL);
zlvertex = 3;
result = zlpoint(0x8000LL, 0LL, 0x8000LL);
if ( vbufferz > 20000 && vvis )
{
DrawLine2(vbufferx[0], vbuffery[0], vbufferx[1], vbuffery[1], v4);
DrawLine2(vbufferx[2], vbuffery[2], vbufferx[1], vbuffery[1], v4);
DrawLine2(vbufferx[2], vbuffery[2], vbufferx[3], vbuffery[3], v4);
result = DrawLine2(vbufferx[3], vbuffery[3], vbufferx[0], vbuffery[0], v4);
}
}
else if ( !(_BYTE)v3 )
{
zlvertex = 0;
zlpoint(0x8000LL, 25000LL, 4294934528LL);
zlvertex = 1;
zlpoint(4294934528LL, 25000LL, 4294934528LL);
zlvertex = 2;
result = zlpoint(0LL, 15000LL, 0x10000LL);
if ( vbufferz > 20000 )
{
if ( vvis )
{
LABEL_10:
DrawLine2(vbufferx[0], vbuffery[0], vbufferx[1], vbuffery[1], v4);
DrawLine2(vbufferx[2], vbuffery[2], vbufferx[1], vbuffery[1], v4);
return DrawLine2(vbufferx[2], vbuffery[2], vbufferx[0], vbuffery[0], v4);
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int8 a1)
{
int v1; // eax
unsigned __int64 v2; // rdi
int v3; // edx
unsigned __int8 v4; // bl
__int64 result; // rax

v1 = a1;
v2 = (unsigned __int64)a1 << 6;
v3 = *(int *)((char *)&mob[2] + v2);
if ( *(int *)((char *)&mob[10] + v2) )
{
mob[16 * (__int64)v1 + 10] = 0;
v4 = 15;
}
else
{
v4 = mob[16 * (__int64)v1 + 1];
}
result = (unsigned __int8)v3;
if ( (_BYTE)v3 == 1 )
{
zlvertex = 0;
zlpoint(0x8000LL, 0LL, 0LL);
zlvertex = 1;
zlpoint(4294934528LL, 0LL, 0LL);
zlvertex = 2;
result = zlpoint(0LL, 60000LL, 0LL);
if ( vbufferz > 20000 && vvis )
goto LABEL_10;
}
else if ( (unsigned __int8)v3 == 2 )
{
zlvertex = 0;
zlpoint(0x8000LL, 0LL, 4294934528LL);
zlvertex = 1;
zlpoint(4294934528LL, 0LL, 4294934528LL);
zlvertex = 2;
zlpoint(4294934528LL, 0LL, 0x8000LL);
zlvertex = 3;
result = zlpoint(0x8000LL, 0LL, 0x8000LL);
if ( vbufferz > 20000 && vvis )
{
DrawLine2(vbufferx[0], vbuffery[0], vbufferx[1], vbuffery[1], v4);
DrawLine2(vbufferx[2], vbuffery[2], vbufferx[1], vbuffery[1], v4);
DrawLine2(vbufferx[2], vbuffery[2], vbufferx[3], vbuffery[3], v4);
result = DrawLine2(vbufferx[3], vbuffery[3], vbufferx[0], vbuffery[0], v4);
}
}
else if ( !(_BYTE)v3 )
{
zlvertex = 0;
zlpoint(0x8000LL, 25000LL, 4294934528LL);
zlvertex = 1;
zlpoint(4294934528LL, 25000LL, 4294934528LL);
zlvertex = 2;
result = zlpoint(0LL, 15000LL, 0x10000LL);
if ( vbufferz > 20000 )
{
if ( vvis )
{
LABEL_10:
DrawLine2(vbufferx[0], vbuffery[0], vbufferx[1], vbuffery[1], v4);
DrawLine2(vbufferx[2], vbuffery[2], vbufferx[1], vbuffery[1], v4);
return DrawLine2(vbufferx[2], vbuffery[2], vbufferx[0], vbuffery[0], v4);
}
}
}
return result;
}

original_code:
void MobModel(Uint8 i) {
 Uint8 model = mob[i][2];
 Uint8 c = mob[i][1];
 if (mob[i][10]) {
  mob[i][10] = 0;
  c = 15;
 }
 switch (model) {
 case 0:
  zlvertex = 0;
  zlpoint(32768, 25000, -32768);
  zlvertex = 1;
  zlpoint(-32768, 25000, -32768);
  zlvertex = 2;
  zlpoint(0, 15000, 65536);
  if (vbufferz[0] > 20000)
   if (vvis[0]) {
    DrawLine2(vbufferx[0], vbuffery[0], vbufferx[1], vbuffery[1],
      c);
    DrawLine2(vbufferx[2], vbuffery[2], vbufferx[1], vbuffery[1],
      c);
    DrawLine2(vbufferx[2], vbuffery[2], vbufferx[0], vbuffery[0],
      c);
   }
  break;
 case 1:
  zlvertex = 0;
  zlpoint(32768, 000, 0);
  zlvertex = 1;
  zlpoint(-32768, 000, 0);
  zlvertex = 2;
  zlpoint(0, 60000, 0);
  if (vbufferz[0] > 20000)
   if (vvis[0]) {
    DrawLine2(vbufferx[0], vbuffery[0], vbufferx[1], vbuffery[1],
      c);
    DrawLine2(vbufferx[2], vbuffery[2], vbufferx[1], vbuffery[1],
      c);
    DrawLine2(vbufferx[2], vbuffery[2], vbufferx[0], vbuffery[0],
      c);
   }
  break;
 case 2:
  zlvertex = 0;
  zlpoint(32768, 0, -32768);
  zlvertex = 1;
  zlpoint(-32768, 0, -32768);
  zlvertex = 2;
  zlpoint(-32768, 0, 32768);
  zlvertex = 3;
  zlpoint(32768, 0, 32768);
  if (vbufferz[0] > 20000)
   if (vvis[0]) {
    DrawLine2(vbufferx[0], vbuffery[0], vbufferx[1], vbuffery[1],
      c);
    DrawLine2(vbufferx[2], vbuffery[2], vbufferx[1], vbuffery[1],
      c);
    DrawLine2(vbufferx[2], vbuffery[2], vbufferx[3], vbuffery[3],
      c);
    DrawLine2(vbufferx[3], vbuffery[3], vbufferx[0], vbuffery[0],
      c);
   }
  break;
 }
}

canonical_original_code:
void MobModel(unsigned char i) {
 unsigned char model = mob[i][2];
 unsigned char c = mob[i][1];
 if (mob[i][10]) {
  mob[i][10] = 0;
  c = 15;
 }
 switch (model) {
 case 0:
  zlvertex = 0;
  zlpoint(32768, 25000, -32768);
  zlvertex = 1;
  zlpoint(-32768, 25000, -32768);
  zlvertex = 2;
  zlpoint(0, 15000, 65536);
  if (vbufferz[0] > 20000)
   if (vvis[0]) {
    DrawLine2(vbufferx[0], vbuffery[0], vbufferx[1], vbuffery[1],
      c);
    DrawLine2(vbufferx[2], vbuffery[2], vbufferx[1], vbuffery[1],
      c);
    DrawLine2(vbufferx[2], vbuffery[2], vbufferx[0], vbuffery[0],
      c);
   }
  break;
 case 1:
  zlvertex = 0;
  zlpoint(32768, 000, 0);
  zlvertex = 1;
  zlpoint(-32768, 000, 0);
  zlvertex = 2;
  zlpoint(0, 60000, 0);
  if (vbufferz[0] > 20000)
   if (vvis[0]) {
    DrawLine2(vbufferx[0], vbuffery[0], vbufferx[1], vbuffery[1],
      c);
    DrawLine2(vbufferx[2], vbuffery[2], vbufferx[1], vbuffery[1],
      c);
    DrawLine2(vbufferx[2], vbuffery[2], vbufferx[0], vbuffery[0],
      c);
   }
  break;
 case 2:
  zlvertex = 0;
  zlpoint(32768, 0, -32768);
  zlvertex = 1;
  zlpoint(-32768, 0, -32768);
  zlvertex = 2;
  zlpoint(-32768, 0, 32768);
  zlvertex = 3;
  zlpoint(32768, 0, 32768);
  if (vbufferz[0] > 20000)
   if (vvis[0]) {
    DrawLine2(vbufferx[0], vbuffery[0], vbufferx[1], vbuffery[1],
      c);
    DrawLine2(vbufferx[2], vbuffery[2], vbufferx[1], vbuffery[1],
      c);
    DrawLine2(vbufferx[2], vbuffery[2], vbufferx[3], vbuffery[3],
      c);
    DrawLine2(vbufferx[3], vbuffery[3], vbufferx[0], vbuffery[0],
      c);
   }
  break;
 }
}

variable_types:
model
unsigned char


RenderMobs

decompiled_code:
void RenderMobs()
{
int *v0; // rbx
__int64 i; // rbp

v0 = mob;
for ( i = 0LL; i != 128; ++i )
{
if ( *v0 > 0
&& (int)zabs((unsigned int)(v0[4] - cursorx)) <= 458751
&& (int)zabs((unsigned int)(v0[5] - cursory)) <= 327679 )
{
zlpushmatrix();
zltranslate((unsigned int)v0[4], (unsigned int)v0[6], (unsigned int)-v0[5]);
zlrotatey((unsigned int)-v0[7]);
MobModel(i);
zlpopmatrix();
}
v0 += 16;
}
}

canonical_decompiled_code:
void func2()
{
int *v0; // rbx
__int64 i; // rbp

v0 = mob;
for ( i = 0LL; i != 128; ++i )
{
if ( *v0 > 0
&& (int)zabs((unsigned int)(v0[4] - cursorx)) <= 458751
&& (int)zabs((unsigned int)(v0[5] - cursory)) <= 327679 )
{
zlpushmatrix();
zltranslate((unsigned int)v0[4], (unsigned int)v0[6], (unsigned int)-v0[5]);
zlrotatey((unsigned int)-v0[7]);
func1(i);
zlpopmatrix();
}
v0 += 16;
}
}

original_code:
void RenderMobs(void) {
 Uint8 i, c;
 for (i = 0; i < 128; i++)
  if (mob[i][0] > 0)
   if (zabs(mob[i][4] - cursorx) < 7 * 65536)
    if (zabs(mob[i][5] - cursory) < 5 * 65536) {
     zlpushmatrix();
     zltranslate(mob[i][4], mob[i][6], -mob[i][5]);
     zlrotatey(-mob[i][7]);
     MobModel(i);
     zlpopmatrix();
    }
}

canonical_original_code:
void RenderMobs() {
 unsigned char i; unsigned char c;
 for (i = 0; i < 128; i++)
  if (mob[i][0] > 0)
   if (zabs(mob[i][4] - cursorx) < 7 * 65536)
    if (zabs(mob[i][5] - cursory) < 5 * 65536) {
     zlpushmatrix();
     zltranslate(mob[i][4], mob[i][6], -mob[i][5]);
     zlrotatey(-mob[i][7]);
     MobModel(i);
     zlpopmatrix();
    }
}


RenderCursor

decompiled_code:
__int64 RenderCursor()
{
int v0; // ebp
int v1; // ebx
__int64 result; // rax
unsigned int v3; // er12
char *v4; // r13
unsigned int v5; // er14
char *v6; // rbp
unsigned int v7; // er15
__int64 v8; // rbx
unsigned int v9; // er12
char *v10; // r13
char *v11; // rbp
unsigned int v12; // er15
__int64 v13; // rbx
signed int v14; // eax
unsigned int v15; // er12
unsigned int v16; // er13
char *v17; // r15
unsigned int v18; // ebp
__int64 v19; // rdx
char *v20; // rbx
char *v21; // rbx
unsigned int v22; // er12
int v23; // er13
char *v24; // r15
unsigned int v25; // ebp
__int64 v26; // r12
char *v27; // r14
char *v28; // r12
unsigned int v29; // eax
unsigned int v30; // ebx
int v31; // ecx
unsigned int v32; // er13
unsigned int v33; // ebp
unsigned int v34; // er13
char *v35; // [rsp+8h] [rbp-70h]
__int64 v36; // [rsp+8h] [rbp-70h]
char *v37; // [rsp+8h] [rbp-70h]
char *v38; // [rsp+8h] [rbp-70h]
unsigned int v39; // [rsp+10h] [rbp-68h]
char *v40; // [rsp+10h] [rbp-68h]
unsigned int v41; // [rsp+10h] [rbp-68h]
char *v42; // [rsp+18h] [rbp-60h]
int v43; // [rsp+18h] [rbp-60h]
unsigned int v44; // [rsp+24h] [rbp-54h]
int v45; // [rsp+28h] [rbp-50h]
int v46; // [rsp+2Ch] [rbp-4Ch]
char *v47; // [rsp+30h] [rbp-48h]
char *v48; // [rsp+38h] [rbp-40h]

v0 = cursorx / 0x10000;
v1 = cursory / 0x10000;
result = cursorvisual;
if ( cursorvisual == 3 )
{
v22 = 899 * count % 0x2710u;
zlvertex = 0;
v46 = -65536 * v1;
v23 = v0 << 16;
v47 = (char *)&mapz + 65 * v0;
v48 = &v47[v1];
v41 = (v0 << 16) - v22;
zlpoint(v41, (unsigned int)(10000 * *v48 + 25000), -65536 * v1 + v22);
zlvertex = 1;
v43 = (v0 << 16) + 0x10000;
v38 = (char *)&mapz + 65 * v0 + 65;
v24 = &v38[v1];
v44 = v43 + v22;
zlpoint(v43 + v22, (unsigned int)(10000 * *v24 + 25000), -65536 * v1 + v22);
zlvertex = 2;
v45 = ~v1 << 16;
v25 = v45 - v22;
v26 = v1 + 1;
v27 = &v38[v26];
zlpoint(v44, (unsigned int)(10000 * v38[v26] + 25000), v25);
zlvertex = 3;
v28 = &v47[v26];
zlpoint(v41, (unsigned int)(10000 * *v28 + 25000), v25);
v29 = 999 * count % 0x2710u + 10000;
zlvertex = 4;
v30 = v29 - (v1 << 16);
v31 = v23;
v32 = v29;
v33 = v31 - v29;
zlpoint(v31 - v29, (unsigned int)(10000 * *v48 + 5000), v29 + v46);
zlvertex = 5;
LODWORD(v38) = v32;
v34 = v32 + v43;
zlpoint(v34, (unsigned int)(10000 * *v24 + 5000), v30);
zlvertex = 6;
zlpoint(v34, (unsigned int)(10000 * *v27 + 5000), (unsigned int)(v45 - (_DWORD)v38));
zlvertex = 7;
zlpoint(v33, (unsigned int)(10000 * *v28 + 5000), (unsigned int)(v45 - (_DWORD)v38));
DrawLine2(vbufferx[0], vbuffery[0], vbufferx[1], vbuffery[1], 14LL);
DrawLine2(vbufferx[1], vbuffery[1], vbufferx[2], vbuffery[2], 14LL);
DrawLine2(vbufferx[2], vbuffery[2], vbufferx[3], vbuffery[3], 14LL);
DrawLine2(vbufferx[3], vbuffery[3], vbufferx[0], vbuffery[0], 14LL);
DrawLine2(vbufferx[4], vbuffery[4], vbufferx[5], vbuffery[5], 15LL);
DrawLine2(vbufferx[5], vbuffery[5], vbufferx[6], vbuffery[6], 15LL);
DrawLine2(vbufferx[6], vbuffery[6], vbufferx[7], vbuffery[7], 15LL);
result = DrawLine2(vbufferx[7], vbuffery[7], vbufferx[4], vbuffery[4], 15LL);
}
else if ( cursorvisual > 3u )
{
if ( cursorvisual == 4 )
{
zlvertex = 0;
v9 = v0 << 16;
v10 = (char *)&mapz + 65 * v0;
zlpoint((unsigned int)(v0 << 16), (unsigned int)(10000 * v10[v1] + 25000), (unsigned int)(-65536 * v1));
zlvertex = 1;
v11 = (char *)&mapz + 65 * v0 + 65;
zlpoint(v9 + 0x10000, (unsigned int)(10000 * v11[v1] + 25000), (unsigned int)(-65536 * v1));
zlvertex = 2;
v12 = ~v1 << 16;
v13 = v1 + 1;
zlpoint(v9 + 0x10000, (unsigned int)(10000 * v11[v13] + 25000), v12);
zlvertex = 3;
zlpoint(v9, (unsigned int)(10000 * v10[v13] + 25000), v12);
v14 = (count / 3u) & 3;
result = DrawLine2(
vbufferx[v14],
vbuffery[v14],
vbufferx[((_BYTE)v14 + 1) & 3],
vbuffery[((_BYTE)v14 + 1) & 3],
14LL);
}
}
else if ( cursorvisual == 1 )
{
zlvertex = 0;
v15 = -65536 * v1;
v16 = v0 << 16;
v40 = (char *)&mapz + 65 * v0;
v17 = &v40[v1];
zlpoint((unsigned int)(v0 << 16), (unsigned int)(10000 * *v17 + 25000), (unsigned int)(-65536 * v1));
zlvertex = 1;
v35 = (char *)&mapz + 65 * v0 + 65;
v42 = &v35[v1];
zlpoint((unsigned int)((v0 << 16) + 0x10000), (unsigned int)(10000 * *v42 + 25000), (unsigned int)(-65536 * v1));
zlvertex = 2;
v18 = ~v1 << 16;
v19 = v1 + 1;
v20 = v35;
v36 = v19;
v21 = &v20[v19];
zlpoint(v16 + 0x10000, (unsigned int)(10000 * *v21 + 25000), v18);
zlvertex = 3;
v37 = &v40[v36];
zlpoint(v16, (unsigned int)(10000 * *v37 + 25000), v18);
zlvertex = 4;
zlpoint(v16, (unsigned int)(10000 * *v17 + 5000), v15);
zlvertex = 5;
zlpoint(v16 + 0x10000, (unsigned int)(10000 * *v42 + 5000), v15);
zlvertex = 6;
zlpoint(v16 + 0x10000, (unsigned int)(10000 * *v21 + 5000), v18);
zlvertex = 7;
zlpoint(v16, (unsigned int)(10000 * *v37 + 5000), v18);
DrawLine2(vbufferx[1], vbuffery[1], vbufferx[3], vbuffery[3], 4LL);
DrawLine2(vbufferx[0], vbuffery[0], vbufferx[2], vbuffery[2], 4LL);
DrawLine2(vbufferx[5], vbuffery[5], vbufferx[7], vbuffery[7], 4LL);
result = DrawLine2(vbufferx[4], vbuffery[4], vbufferx[6], vbuffery[6], 4LL);
}
else if ( cursorvisual == 2 )
{
v3 = 899 * count % 0x2710u;
zlvertex = 0;
v4 = (char *)&mapz + 65 * v0;
v39 = (v0 << 16) - v3;
zlpoint(v39, (unsigned int)(10000 * v4[v1] + 25000), v3 - (v1 << 16));
zlvertex = 1;
v5 = (v0 << 16) + v3 + 0x10000;
v6 = (char *)&mapz + 65 * v0 + 65;
zlpoint(v5, (unsigned int)(10000 * v6[v1] + 25000), v3 - (v1 << 16));
zlvertex = 2;
v7 = (~v1 << 16) - v3;
v8 = v1 + 1;
zlpoint(v5, (unsigned int)(10000 * v6[v8] + 25000), v7);
zlvertex = 3;
zlpoint(v39, (unsigned int)(10000 * v4[v8] + 25000), v7);
DrawLine2(vbufferx[0], vbuffery[0], vbufferx[1], vbuffery[1], 14LL);
DrawLine2(vbufferx[1], vbuffery[1], vbufferx[2], vbuffery[2], 14LL);
DrawLine2(vbufferx[2], vbuffery[2], vbufferx[3], vbuffery[3], 14LL);
DrawLine2(vbufferx[3], vbuffery[3], vbufferx[0], vbuffery[0], 14LL);
DrawLine2(vbufferx[0], vbuffery[0], vbufferx[2], vbuffery[2], 15LL);
result = DrawLine2(vbufferx[1], vbuffery[1], vbufferx[3], vbuffery[3], 15LL);
}
return result;
}

original_code:
void RenderCursor(void) {
 Sint32 x = cursorx / 65536;
 Sint32 y = cursory / 65536;
 Uint8 c;
 Sint32 anim;
 switch (cursorvisual) {
 case 1:
  zlvertex = 0;
  zlpoint((x) * 65536, 25000 + mapz[x][y] * 10000, -(y) * 65536);
  zlvertex = 1;
  zlpoint((x + 1) * 65536, 25000 + mapz[x + 1][y] * 10000, -(y) * 65536);
  zlvertex = 2;
  zlpoint((x + 1) * 65536, 25000 + mapz[x + 1][y + 1] * 10000,
    -(y + 1) * 65536);
  zlvertex = 3;
  zlpoint((x) * 65536, 25000 + mapz[x][y + 1] * 10000, -(y + 1) * 65536);
  zlvertex = 4;
  zlpoint((x) * 65536, 5000 + mapz[x][y] * 10000, -(y) * 65536);
  zlvertex = 5;
  zlpoint((x + 1) * 65536, 5000 + mapz[x + 1][y] * 10000, -(y) * 65536);
  zlvertex = 6;
  zlpoint((x + 1) * 65536, 5000 + mapz[x + 1][y + 1] * 10000,
    -(y + 1) * 65536);
  zlvertex = 7;
  zlpoint((x) * 65536, 5000 + mapz[x][y + 1] * 10000, -(y + 1) * 65536);
  c = 4;
  DrawLine2(vbufferx[1], vbuffery[1], vbufferx[3], vbuffery[3], c);
  DrawLine2(vbufferx[0], vbuffery[0], vbufferx[2], vbuffery[2], c);
  DrawLine2(vbufferx[5], vbuffery[5], vbufferx[7], vbuffery[7], c);
  DrawLine2(vbufferx[4], vbuffery[4], vbufferx[6], vbuffery[6], c);
  break;
 case 2:
  anim = (count * 899) % 10000;
  zlvertex = 0;
  zlpoint((x) * 65536 - anim, 25000 + mapz[x][y] * 10000,
    -(y) * 65536 + anim);
  zlvertex = 1;
  zlpoint((x + 1) * 65536 + anim, 25000 + mapz[x + 1][y] * 10000,
    -(y) * 65536 + anim);
  zlvertex = 2;
  zlpoint((x + 1) * 65536 + anim, 25000 + mapz[x + 1][y + 1] * 10000,
    -(y + 1) * 65536 - anim);
  zlvertex = 3;
  zlpoint((x) * 65536 - anim, 25000 + mapz[x][y + 1] * 10000,
    -(y + 1) * 65536 - anim);
  c = 14;
  DrawLine2(vbufferx[0], vbuffery[0], vbufferx[1], vbuffery[1], c);
  DrawLine2(vbufferx[1], vbuffery[1], vbufferx[2], vbuffery[2], c);
  DrawLine2(vbufferx[2], vbuffery[2], vbufferx[3], vbuffery[3], c);
  DrawLine2(vbufferx[3], vbuffery[3], vbufferx[0], vbuffery[0], c);
  DrawLine2(vbufferx[0], vbuffery[0], vbufferx[2], vbuffery[2], 15);
  DrawLine2(vbufferx[1], vbuffery[1], vbufferx[3], vbuffery[3], 15);
  break;
 case 3:
  anim = (count * 899) % 10000;
  zlvertex = 0;
  zlpoint((x) * 65536 - anim, 25000 + mapz[x][y] * 10000,
    -(y) * 65536 + anim);
  zlvertex = 1;
  zlpoint((x + 1) * 65536 + anim, 25000 + mapz[x + 1][y] * 10000,
    -(y) * 65536 + anim);
  zlvertex = 2;
  zlpoint((x + 1) * 65536 + anim, 25000 + mapz[x + 1][y + 1] * 10000,
    -(y + 1) * 65536 - anim);
  zlvertex = 3;
  zlpoint((x) * 65536 - anim, 25000 + mapz[x][y + 1] * 10000,
    -(y + 1) * 65536 - anim);
  anim = 10000 + (count * 999) % 10000;
  zlvertex = 4;
  zlpoint((x) * 65536 - anim, 5000 + mapz[x][y] * 10000,
    -(y) * 65536 + anim);
  zlvertex = 5;
  zlpoint((x + 1) * 65536 + anim, 5000 + mapz[x + 1][y] * 10000,
    -(y) * 65536 + anim);
  zlvertex = 6;
  zlpoint((x + 1) * 65536 + anim, 5000 + mapz[x + 1][y + 1] * 10000,
    -(y + 1) * 65536 - anim);
  zlvertex = 7;
  zlpoint((x) * 65536 - anim, 5000 + mapz[x][y + 1] * 10000,
    -(y + 1) * 65536 - anim);
  c = 14;
  DrawLine2(vbufferx[0], vbuffery[0], vbufferx[1], vbuffery[1], c);
  DrawLine2(vbufferx[1], vbuffery[1], vbufferx[2], vbuffery[2], c);
  DrawLine2(vbufferx[2], vbuffery[2], vbufferx[3], vbuffery[3], c);
  DrawLine2(vbufferx[3], vbuffery[3], vbufferx[0], vbuffery[0], c);
  c = 15;
  DrawLine2(vbufferx[4], vbuffery[4], vbufferx[5], vbuffery[5], c);
  DrawLine2(vbufferx[5], vbuffery[5], vbufferx[6], vbuffery[6], c);
  DrawLine2(vbufferx[6], vbuffery[6], vbufferx[7], vbuffery[7], c);
  DrawLine2(vbufferx[7], vbuffery[7], vbufferx[4], vbuffery[4], c);
  break;
 case 4:
  zlvertex = 0;
  zlpoint((x) * 65536, 25000 + mapz[x][y] * 10000, -(y) * 65536);
  zlvertex = 1;
  zlpoint((x + 1) * 65536, 25000 + mapz[x + 1][y] * 10000, -(y) * 65536);
  zlvertex = 2;
  zlpoint((x + 1) * 65536, 25000 + mapz[x + 1][y + 1] * 10000,
    -(y + 1) * 65536);
  zlvertex = 3;
  zlpoint((x) * 65536, 25000 + mapz[x][y + 1] * 10000, -(y + 1) * 65536);
  c = 14;
  anim = (count / 3) % 4;
  DrawLine2(vbufferx[anim], vbuffery[anim], vbufferx[(anim + 1) % 4],
    vbuffery[(anim + 1) % 4], c);
  break;
 }
}

canonical_original_code:
void RenderCursor() {
 int x = cursorx / 65536;
 int y = cursory / 65536;
 unsigned char c;
 int anim;
 switch (cursorvisual) {
 case 1:
  zlvertex = 0;
  zlpoint((x) * 65536, 25000 + mapz[x][y] * 10000, -(y) * 65536);
  zlvertex = 1;
  zlpoint((x + 1) * 65536, 25000 + mapz[x + 1][y] * 10000, -(y) * 65536);
  zlvertex = 2;
  zlpoint((x + 1) * 65536, 25000 + mapz[x + 1][y + 1] * 10000,
    -(y + 1) * 65536);
  zlvertex = 3;
  zlpoint((x) * 65536, 25000 + mapz[x][y + 1] * 10000, -(y + 1) * 65536);
  zlvertex = 4;
  zlpoint((x) * 65536, 5000 + mapz[x][y] * 10000, -(y) * 65536);
  zlvertex = 5;
  zlpoint((x + 1) * 65536, 5000 + mapz[x + 1][y] * 10000, -(y) * 65536);
  zlvertex = 6;
  zlpoint((x + 1) * 65536, 5000 + mapz[x + 1][y + 1] * 10000,
    -(y + 1) * 65536);
  zlvertex = 7;
  zlpoint((x) * 65536, 5000 + mapz[x][y + 1] * 10000, -(y + 1) * 65536);
  c = 4;
  DrawLine2(vbufferx[1], vbuffery[1], vbufferx[3], vbuffery[3], c);
  DrawLine2(vbufferx[0], vbuffery[0], vbufferx[2], vbuffery[2], c);
  DrawLine2(vbufferx[5], vbuffery[5], vbufferx[7], vbuffery[7], c);
  DrawLine2(vbufferx[4], vbuffery[4], vbufferx[6], vbuffery[6], c);
  break;
 case 2:
  anim = (count * 899) % 10000;
  zlvertex = 0;
  zlpoint((x) * 65536 - anim, 25000 + mapz[x][y] * 10000,
    -(y) * 65536 + anim);
  zlvertex = 1;
  zlpoint((x + 1) * 65536 + anim, 25000 + mapz[x + 1][y] * 10000,
    -(y) * 65536 + anim);
  zlvertex = 2;
  zlpoint((x + 1) * 65536 + anim, 25000 + mapz[x + 1][y + 1] * 10000,
    -(y + 1) * 65536 - anim);
  zlvertex = 3;
  zlpoint((x) * 65536 - anim, 25000 + mapz[x][y + 1] * 10000,
    -(y + 1) * 65536 - anim);
  c = 14;
  DrawLine2(vbufferx[0], vbuffery[0], vbufferx[1], vbuffery[1], c);
  DrawLine2(vbufferx[1], vbuffery[1], vbufferx[2], vbuffery[2], c);
  DrawLine2(vbufferx[2], vbuffery[2], vbufferx[3], vbuffery[3], c);
  DrawLine2(vbufferx[3], vbuffery[3], vbufferx[0], vbuffery[0], c);
  DrawLine2(vbufferx[0], vbuffery[0], vbufferx[2], vbuffery[2], 15);
  DrawLine2(vbufferx[1], vbuffery[1], vbufferx[3], vbuffery[3], 15);
  break;
 case 3:
  anim = (count * 899) % 10000;
  zlvertex = 0;
  zlpoint((x) * 65536 - anim, 25000 + mapz[x][y] * 10000,
    -(y) * 65536 + anim);
  zlvertex = 1;
  zlpoint((x + 1) * 65536 + anim, 25000 + mapz[x + 1][y] * 10000,
    -(y) * 65536 + anim);
  zlvertex = 2;
  zlpoint((x + 1) * 65536 + anim, 25000 + mapz[x + 1][y + 1] * 10000,
    -(y + 1) * 65536 - anim);
  zlvertex = 3;
  zlpoint((x) * 65536 - anim, 25000 + mapz[x][y + 1] * 10000,
    -(y + 1) * 65536 - anim);
  anim = 10000 + (count * 999) % 10000;
  zlvertex = 4;
  zlpoint((x) * 65536 - anim, 5000 + mapz[x][y] * 10000,
    -(y) * 65536 + anim);
  zlvertex = 5;
  zlpoint((x + 1) * 65536 + anim, 5000 + mapz[x + 1][y] * 10000,
    -(y) * 65536 + anim);
  zlvertex = 6;
  zlpoint((x + 1) * 65536 + anim, 5000 + mapz[x + 1][y + 1] * 10000,
    -(y + 1) * 65536 - anim);
  zlvertex = 7;
  zlpoint((x) * 65536 - anim, 5000 + mapz[x][y + 1] * 10000,
    -(y + 1) * 65536 - anim);
  c = 14;
  DrawLine2(vbufferx[0], vbuffery[0], vbufferx[1], vbuffery[1], c);
  DrawLine2(vbufferx[1], vbuffery[1], vbufferx[2], vbuffery[2], c);
  DrawLine2(vbufferx[2], vbuffery[2], vbufferx[3], vbuffery[3], c);
  DrawLine2(vbufferx[3], vbuffery[3], vbufferx[0], vbuffery[0], c);
  c = 15;
  DrawLine2(vbufferx[4], vbuffery[4], vbufferx[5], vbuffery[5], c);
  DrawLine2(vbufferx[5], vbuffery[5], vbufferx[6], vbuffery[6], c);
  DrawLine2(vbufferx[6], vbuffery[6], vbufferx[7], vbuffery[7], c);
  DrawLine2(vbufferx[7], vbuffery[7], vbufferx[4], vbuffery[4], c);
  break;
 case 4:
  zlvertex = 0;
  zlpoint((x) * 65536, 25000 + mapz[x][y] * 10000, -(y) * 65536);
  zlvertex = 1;
  zlpoint((x + 1) * 65536, 25000 + mapz[x + 1][y] * 10000, -(y) * 65536);
  zlvertex = 2;
  zlpoint((x + 1) * 65536, 25000 + mapz[x + 1][y + 1] * 10000,
    -(y + 1) * 65536);
  zlvertex = 3;
  zlpoint((x) * 65536, 25000 + mapz[x][y + 1] * 10000, -(y + 1) * 65536);
  c = 14;
  anim = (count / 3) % 4;
  DrawLine2(vbufferx[anim], vbuffery[anim], vbufferx[(anim + 1) % 4],
    vbuffery[(anim + 1) % 4], c);
  break;
 }
}

variable_types: x int

variable_types: anim int


RenderLines

decompiled_code:
void RenderLines()
{
__int64 i; // rbx
__int64 v1; // rax

for ( i = 0LL; i != 0x2000; i += 64LL )
{
if ( *(int *)((char *)&vline + i) > 0 )
{
zlvertex = 0;
zlpoint(
*(unsigned int *)((char *)&vline + i + 8),
*(unsigned int *)((char *)&vline + i + 12),
(unsigned int)-*(_DWORD *)((char *)&vline + i + 16));
zlvertex = 1;
zlpoint(
*(unsigned int *)((char *)&vline + i + 20),
*(unsigned int *)((char *)&vline + i + 24),
(unsigned int)-*(_DWORD *)((char *)&vline + i + 28));
if ( vbufferz > 0 && *((int *)&vbufferz + 1) > 0 && vvis && *((_DWORD *)&vvis + 1) )
DrawLine2(vbufferx[0], vbuffery[0], vbufferx[1], vbuffery[1], *(unsigned int *)((char *)&vline + i + 4));
v1 = i;
do
{
*(_DWORD *)((char *)&vline + v1 + 8) += *(_DWORD *)((char *)&vline + v1 + 32);
v1 += 4LL;
}
while ( v1 != i + 24 );
--*(_DWORD *)((char *)&vline + i);
}
}
}

canonical_decompiled_code:
void func1()
{
__int64 i; // rbx
__int64 v1; // rax

for ( i = 0LL; i != 0x2000; i += 64LL )
{
if ( *(int *)((char *)&vline + i) > 0 )
{
zlvertex = 0;
zlpoint(
*(unsigned int *)((char *)&vline + i + 8),
*(unsigned int *)((char *)&vline + i + 12),
(unsigned int)-*(_DWORD *)((char *)&vline + i + 16));
zlvertex = 1;
zlpoint(
*(unsigned int *)((char *)&vline + i + 20),
*(unsigned int *)((char *)&vline + i + 24),
(unsigned int)-*(_DWORD *)((char *)&vline + i + 28));
if ( vbufferz > 0 && *((int *)&vbufferz + 1) > 0 && vvis && *((_DWORD *)&vvis + 1) )
DrawLine2(vbufferx[0], vbuffery[0], vbufferx[1], vbuffery[1], *(unsigned int *)((char *)&vline + i + 4));
v1 = i;
do
{
*(_DWORD *)((char *)&vline + v1 + 8) += *(_DWORD *)((char *)&vline + v1 + 32);
v1 += 4LL;
}
while ( v1 != i + 24 );
--*(_DWORD *)((char *)&vline + i);
}
}
}

original_code:
void RenderLines(void) {
 Uint8 i, k;
 for (i = 0; i < 128; i++)
  if (vline[i][0] > 0) {
   zlvertex = 0;
   zlpoint(vline[i][2], vline[i][3], -vline[i][4]);
   zlvertex = 1;
   zlpoint(vline[i][5], vline[i][6], -vline[i][7]);
   if (vbufferz[0] > 0)
    if (vbufferz[1] > 0)
     if (vvis[0])
      if (vvis[1])
       DrawLine2(vbufferx[0], vbuffery[0], vbufferx[1],
         vbuffery[1], vline[i][1]);
   for (k = 2; k < 8; k++)
    vline[i][k] += vline[i][k + 6];
   vline[i][0]--;
  }
}

canonical_original_code:
void RenderLines() {
 unsigned char i; unsigned char k;
 for (i = 0; i < 128; i++)
  if (vline[i][0] > 0) {
   zlvertex = 0;
   zlpoint(vline[i][2], vline[i][3], -vline[i][4]);
   zlvertex = 1;
   zlpoint(vline[i][5], vline[i][6], -vline[i][7]);
   if (vbufferz[0] > 0)
    if (vbufferz[1] > 0)
     if (vvis[0])
      if (vvis[1])
       DrawLine2(vbufferx[0], vbuffery[0], vbufferx[1],
         vbuffery[1], vline[i][1]);
   for (k = 2; k < 8; k++)
    vline[i][k] += vline[i][k + 6];
   vline[i][0]--;
  }
}

variable_types:
k
unsigned char


RenderObjects

decompiled_code:
void RenderObjects()
{
RenderMobs();
RenderLines();
}

canonical_decompiled_code:
void func2()
{
RenderMobs();
func1();
}

original_code:
void RenderObjects(void) {
 RenderMobs();
 RenderLines();
}


RaiseLand

variable_types: x char

variable_types: y char