decompiled_code:
__int64 __fastcall dlist_get_size(_QWORD **a1)
{
_QWORD *v1; // rax
unsigned int i; // er8

v1 = *a1;
for ( i = 0; v1; ++i )
v1 = (_QWORD *)*v1;
return i;
}

canonical_decompiled_code:
__int64 __fastcall func3(_QWORD **a1)
{
_QWORD *v1; // rax
unsigned int i; // er8

v1 = *a1;
for ( i = 0; v1; ++i )
v1 = (_QWORD *)*v1;
return i;
}

original_code:
int dlist_get_size( const struct dlist *dlist) {
    int count = 0;
    for (struct dlist_elem * elem = (dlist)->head; elem; elem = elem->next)
        count++;
    return count;
}

canonical_original_code:
int dlist_get_size(struct dlist *dlist) {
    int count = 0;
    for (struct dlist_elem *elem = (dlist)->head; elem; elem = elem->next)
        count++;
    return count;
}

variable_types: struct dlist { struct dlist_elem { struct dlist_elem *next; struct dlist_elem *prev; void *data; } *head; } *

variable_types: count int

user_defined_types: struct dlist { struct dlist_elem *head; }


repo: JohnAnthony/Structures

decompiled_code:
_BOOL8 __fastcall dlist_is_empty(_QWORD *a1)
{
return *a1 != 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(_QWORD *a1)
{
return *a1 != 0LL;
}

original_code:
int dlist_is_empty( const struct dlist *dlist) {
    return !! dlist->head;
}

canonical_original_code:
int dlist_is_empty(struct dlist *dlist) {
    return !! dlist->head;
}

return_type: int

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


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

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

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

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

original_code:
int dlist_ins_head( struct dlist *dlist,
                              void *data) {
    struct dlist_elem *elem;
    elem = malloc(sizeof(struct dlist_elem));
    if (elem == ((void *)0))
        return -1;
    elem->next = dlist->head;
    elem->prev = ((void *)0);
    elem->data = data;
    dlist->head = elem;
    return 0;
}

canonical_original_code:
int dlist_ins_head(struct dlist *dlist, void *data) {
    struct dlist_elem *elem;
    elem = malloc(sizeof(struct dlist_elem));
    if (elem == ((void *)0))
        return -1;
    elem->next = dlist->head;
    elem->prev = ((void *)0);
    elem->data = data;
    dlist->head = elem;
    return 0;
}

variable_types:
data
void *

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


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

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

original_code:
int dlist_ins_next( struct dlist_elem *elem,
                              void *data) {
    struct dlist_elem *elem_new;
    elem_new = malloc(sizeof(struct dlist_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 dlist_ins_next(struct dlist_elem *elem, void *data) {
    struct dlist_elem *elem_new;
    elem_new = malloc(sizeof(struct dlist_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;
}


decompiled_code:
__int64 __fastcall dlist_ins_prev(_QWORD *a1, __int64 a2, __int64 a3)
{
_QWORD *v4; // rax
_QWORD *v5; // rdx

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

original_code:
int dlist_ins_prev( struct dlist *dlist,
                                 struct dlist_elem *elem,
                              void *data) {
    struct dlist_elem *elem_new;
    elem_new = malloc(sizeof(struct dlist_elem));
    if (elem_new == ((void *)0))
        return -1;
    if (dlist->head == elem)
        dlist->head = elem_new;
    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 dlist_ins_prev(struct dlist *dlist, struct dlist_elem *elem, void *data) {
    struct dlist_elem *elem_new;
    elem_new = malloc(sizeof(struct dlist_elem));
    if (elem_new == ((void *)0))
        return -1;
    if (dlist->head == elem)
        dlist->head = elem_new;
    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:
elem
struct dlist_elem *


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

v2 = dlist_get_tail(a1);
return dlist_ins_next(v2, a2);
}

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

v2 = dlist_get_tail(a1);
return func6(v2, a2);
}

original_code:
int dlist_ins_tail( struct dlist *dlist,
                              void *data) {
    return dlist_ins_next(dlist_get_tail(dlist), data);
}

canonical_original_code:
int dlist_ins_tail(struct dlist *dlist, void *data) {
    return dlist_ins_next(dlist_get_tail(dlist), data);
}


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

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

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


decompiled_code:
__int64 __fastcall dlist_rem_head(_QWORD **a1, void (__fastcall *a2)(_QWORD))
{
_QWORD *v2; // rbp
_QWORD *v3; // rax

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

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

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

original_code:
int dlist_rem_head( struct dlist *dlist,
                              void (*destroy)(void *data)) {
    struct dlist_elem *elem;
    elem = dlist->head;
    if (elem == ((void *)0))
        return -1;
    dlist->head = elem->next;
    if (dlist->head != ((void *)0))
        dlist->head->prev = ((void *)0);
    if (destroy)
        destroy(elem->data);
    free(elem);
    return 0;
}

canonical_original_code:
int dlist_rem_head(struct dlist *dlist, void (*destroy)(void *data)) {
    struct dlist_elem *elem;
    elem = dlist->head;
    if (elem == ((void *)0))
        return -1;
    dlist->head = elem->next;
    if (dlist->head != ((void *)0))
        dlist->head->prev = ((void *)0);
    if (destroy)
        destroy(elem->data);
    free(elem);
    return 0;
}


decompiled_code:
__int64 __fastcall dlist_rem_tail(__int64 *a1)
{
__int64 *v1; // rax
void (__fastcall *v2)(__int64); // rdx

v1 = dlist_get_tail((_QWORD **)a1);
return dlist_rem_elem(a1, v1, v2);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 *a1)
{
__int64 *v1; // rax
void (__fastcall *v2)(__int64); // rdx

v1 = dlist_get_tail((_QWORD **)a1);
return func9(a1, v1, v2);
}

original_code:
int dlist_rem_tail( struct dlist *dlist,
                              void (*destroy)(void *data)) {
    return dlist_rem_elem(dlist, dlist_get_tail(dlist), destroy);
}

canonical_original_code:
int dlist_rem_tail(struct dlist *dlist, void (*destroy)(void *data)) {
    return dlist_rem_elem(dlist, dlist_get_tail(dlist), destroy);
}


decompiled_code:
__int64 __fastcall list_get_head(__int64 a1)
{
return *(_QWORD *)a1;
}

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

original_code:
struct list_elem* list_get_head( const struct list *list) {
    return list->head;
}

canonical_original_code:
struct list_elem *list_get_head(struct list *list) {
    return list->head;
}

variable_types: struct list { struct list_elem *head; } *

return_type: struct list_elem { struct list_elem *next; void *data; } *


decompiled_code:
__int64 __fastcall list_get_size(_QWORD **a1)
{
_QWORD *v1; // rax
unsigned int i; // er8

v1 = *a1;
for ( i = 0; v1; ++i )
v1 = (_QWORD *)*v1;
return i;
}

original_code:
int list_get_size( const struct list *list) {
    int count = 0;
    for (struct list_elem * elem = (list)->head; elem; elem = elem->next)
        count++;
    return count;
}

canonical_original_code:
int list_get_size(struct list *list) {
    int count = 0;
    for (struct list_elem *elem = (list)->head; elem; elem = elem->next)
        count++;
    return count;
}

variable_types: struct list { struct list_elem { struct list_elem *next; void *data; } *head; } *


decompiled_code:
_BOOL8 __fastcall list_is_empty(_QWORD *a1)
{
return *a1 != 0LL;
}

original_code:
int list_is_empty( const struct list *list) {
    return !! list->head;
}

canonical_original_code:
int list_is_empty(struct list *list) {
    return !! list->head;
}

user_defined_types: struct list_elem { struct list_elem *next; void *data; }


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

v2 = malloc(0x10uLL);
if ( !v2 )
return 0xFFFFFFFFLL;
v3 = *a1;
v2[1] = a2;
*a1 = (__int64)v2;
*v2 = v3;
return 0LL;
}

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

v2 = malloc(0x10uLL);
if ( !v2 )
return 0xFFFFFFFFLL;
v3 = *a1;
v2[1] = a2;
*a1 = (__int64)v2;
*v2 = v3;
return 0LL;
}

original_code:
int list_ins_head( struct list *list,
                             void *data) {
    struct list_elem *elem;
    elem = malloc(sizeof(struct list_elem));
    if (elem == ((void *)0))
        return -1;
    elem->next = list->head;
    elem->data = data;
    list->head = elem;
    return 0;
}

canonical_original_code:
int list_ins_head(struct list *list, void *data) {
    struct list_elem *elem;
    elem = malloc(sizeof(struct list_elem));
    if (elem == ((void *)0))
        return -1;
    elem->next = list->head;
    elem->data = data;
    list->head = elem;
    return 0;
}

variable_types: struct list_elem { struct list_elem *next; void *data; } *


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

v2 = malloc(0x10uLL);
if ( !v2 )
return 0xFFFFFFFFLL;
v3 = *a1;
v2[1] = a2;
*a1 = (__int64)v2;
*v2 = v3;
return 0LL;
}

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

v2 = malloc(0x10uLL);
if ( !v2 )
return 0xFFFFFFFFLL;
v3 = *a1;
v2[1] = a2;
*a1 = (__int64)v2;
*v2 = v3;
return 0LL;
}

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

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


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

v2 = list_get_tail(a1);
return list_ins_next(v2, a2);
}

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

v2 = list_get_tail(a1);
return func6(v2, a2);
}

original_code:
int list_ins_tail( struct list *list,
                             void *data) {
    return list_ins_next(list_get_tail(list), data);
}

canonical_original_code:
int list_ins_tail(struct list *list, void *data) {
    return list_ins_next(list_get_tail(list), data);
}


decompiled_code:
__int64 __fastcall list_rem_head(_QWORD *a1, void (__fastcall *a2)(_QWORD))
{
_QWORD *v2; // rbp
unsigned int v3; // er12

if ( list_is_empty(a1) )
return (unsigned int)-1;
v2 = (_QWORD *)*a1;
v3 = 0;
*a1 = *(_QWORD *)*a1;
if ( a2 )
a2(v2[1]);
free(v2);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func8(_QWORD *a1, void (__fastcall *a2)(_QWORD))
{
_QWORD *v2; // rbp
unsigned int v3; // er12

if ( func4(a1) )
return (unsigned int)-1;
v2 = (_QWORD *)*a1;
v3 = 0;
*a1 = *(_QWORD *)*a1;
if ( a2 )
a2(v2[1]);
free(v2);
return v3;
}

original_code:
int list_rem_head( struct list *list,
                             void (*destroy)(void *data)) {
    struct list_elem *elem;
    if (list_is_empty(list))
        return -1;
    elem = list->head;
    list->head = elem->next;
    if (destroy != ((void *)0))
        destroy(elem->data);
    free(elem);
    return 0;
}

canonical_original_code:
int list_rem_head(struct list *list, void (*destroy)(void *data)) {
    struct list_elem *elem;
    if (list_is_empty(list))
        return -1;
    elem = list->head;
    list->head = elem->next;
    if (destroy != ((void *)0))
        destroy(elem->data);
    free(elem);
    return 0;
}


decompiled_code:
__int64 __fastcall list_rem_next(__int64 a1, void (__fastcall *a2)(_QWORD))
{
_QWORD *v2; // rbp

v2 = *(_QWORD **)a1;
if ( !*(_QWORD *)a1 )
return 0xFFFFFFFFLL;
*(_QWORD *)a1 = *v2;
if ( a2 )
a2(*(_QWORD *)(a1 + 8));
free(v2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, void (__fastcall *a2)(_QWORD))
{
_QWORD *v2; // rbp

v2 = *(_QWORD **)a1;
if ( !*(_QWORD *)a1 )
return 0xFFFFFFFFLL;
*(_QWORD *)a1 = *v2;
if ( a2 )
a2(*(_QWORD *)(a1 + 8));
free(v2);
return 0LL;
}

original_code:
int list_rem_next( struct list_elem *elem,
                             void (*destroy)(void *data)) {
    struct list_elem *target;
    target = elem->next;
    if (target == ((void *)0))
        return -1;
    elem->next = target->next;
    if (destroy)
        destroy(elem->data);
    free(target);
    return 0;
}

canonical_original_code:
int list_rem_next(struct list_elem *elem, void (*destroy)(void *data)) {
    struct list_elem *target;
    target = elem->next;
    if (target == ((void *)0))
        return -1;
    elem->next = target->next;
    if (destroy)
        destroy(elem->data);
    free(target);
    return 0;
}


decompiled_code:
__int64 __fastcall list_rem_tail(_QWORD *a1, void (__fastcall *a2)(_QWORD))
{
_QWORD **v2; // rax
__int64 v4; // rdi
_QWORD *v5; // rax
_QWORD *v6; // rdx

v2 = (_QWORD **)list_get_head((__int64)a1);
if ( !v2 )
return 0xFFFFFFFFLL;
v4 = (__int64)v2;
v5 = *v2;
if ( !v5 )
return list_rem_head(a1, a2);
while ( 1 )
{
v6 = v5;
v5 = (_QWORD *)*v5;
if ( !v5 )
break;
v4 = (__int64)v6;
}
return list_rem_next(v4, a2);
}

canonical_decompiled_code:
__int64 __fastcall func10(_QWORD *a1, void (__fastcall *a2)(_QWORD))
{
_QWORD **v2; // rax
__int64 v4; // rdi
_QWORD *v5; // rax
_QWORD *v6; // rdx

v2 = (_QWORD **)func2((__int64)a1);
if ( !v2 )
return 0xFFFFFFFFLL;
v4 = (__int64)v2;
v5 = *v2;
if ( !v5 )
return func8(a1, a2);
while ( 1 )
{
v6 = v5;
v5 = (_QWORD *)*v5;
if ( !v5 )
break;
v4 = (__int64)v6;
}
return func9(v4, a2);
}

original_code:
int list_rem_tail( struct list *list,
                             void (*destroy)(void *data)){
    struct list_elem *elem;
    elem = list_get_head(list);
    if (elem == ((void *)0))
        return -1;
    if (elem->next == ((void *)0))
        return list_rem_head(list, destroy);
    while(elem->next->next != ((void *)0))
        elem = elem->next;
    return list_rem_next(elem, destroy);
}

canonical_original_code:
int list_rem_tail(struct list *list, void (*destroy)(void *data)){
    struct list_elem *elem;
    elem = list_get_head(list);
    if (elem == ((void *)0))
        return -1;
    if (elem->next == ((void *)0))
        return list_rem_head(list, destroy);
    while(elem->next->next != ((void *)0))
        elem = elem->next;
    return list_rem_next(elem, destroy);
}


decompiled_code:
__int64 __fastcall clist_get_size(_QWORD **a1)
{
_QWORD *v1; // rax
unsigned int i; // er8

v1 = *a1;
for ( i = 0; v1 != a1; ++i )
v1 = (_QWORD *)*v1;
return i;
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD **a1)
{
_QWORD *v1; // rax
unsigned int i; // er8

v1 = *a1;
for ( i = 0; v1 != a1; ++i )
v1 = (_QWORD *)*v1;
return i;
}

original_code:
int clist_get_size( const struct clist *clist) {
    int count = 0;
    for (struct clist_elem * elem = clist->link.next; elem != &clist->link; elem = elem->next)
        count++;
    return count;
}

canonical_original_code:
int clist_get_size(struct clist *clist) {
    int count = 0;
    for (struct clist_elem *elem = clist->link.next; elem != &clist->link; elem = elem->next)
        count++;
    return count;
}

variable_types: struct clist { struct clist_elem { struct clist_elem *next; void *data; } link; } *

variable_types: struct clist_elem { struct clist_elem *next; void *data; } *

user_defined_types: struct clist { struct clist_elem link; }


decompiled_code:
_BOOL8 __fastcall clist_is_empty(_QWORD *a1)
{
return *a1 == (_QWORD)a1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(_QWORD *a1)
{
return *a1 == (_QWORD)a1;
}

original_code:
int clist_is_empty( const struct clist *clist) {
    return clist->link.next == &clist->link;
}

canonical_original_code:
int clist_is_empty(struct clist *clist) {
    return clist->link.next == &clist->link;
}

user_defined_types: struct clist_elem { struct clist_elem *next; void *data; }


decompiled_code:
__int64 __fastcall clist_get_head(__int64 *a1)
{
_BOOL4 v1; // er8
__int64 result; // rax

v1 = clist_is_empty(a1);
result = 0LL;
if ( !v1 )
result = *a1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 *a1)
{
_BOOL4 v1; // er8
__int64 result; // rax

v1 = func2(a1);
result = 0LL;
if ( !v1 )
result = *a1;
return result;
}

original_code:
struct clist_elem* clist_get_head( const struct clist *clist) {
    return clist_is_empty(clist) ? ((void *)0) : clist->link.next;
}

canonical_original_code:
struct clist_elem *clist_get_head(struct clist *clist) {
    return clist_is_empty(clist) ? ((void *)0) : clist->link.next;
}

variable_types: struct clist { struct clist_elem link; } *

return_type: struct clist_elem { struct clist_elem *next; void *data; } *


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

v2 = malloc(0x10uLL);
if ( !v2 )
return 0xFFFFFFFFLL;
v3 = *a1;
v2[1] = a2;
*a1 = (__int64)v2;
*v2 = v3;
return 0LL;
}

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

v2 = malloc(0x10uLL);
if ( !v2 )
return 0xFFFFFFFFLL;
v3 = *a1;
v2[1] = a2;
*a1 = (__int64)v2;
*v2 = v3;
return 0LL;
}

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

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


decompiled_code:
// attributes: thunk
__int64 __fastcall clist_ins_head(__int64 *a1, __int64 a2)
{
return clist_ins_next(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 *a1, __int64 a2)
{
return func4(a1, a2);
}

original_code:
int clist_ins_head( struct clist *clist,
                              void *data) {
    return clist_ins_next(&clist->link, data);
}

canonical_original_code:
int clist_ins_head(struct clist *clist, void *data) {
    return clist_ins_next(&clist->link, data);
}


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

v2 = clist_get_tail(a1);
if ( v2 )
result = clist_ins_next(v2, a2);
else
result = 0xFFFFFFFFLL;
return result;
}

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

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

original_code:
int clist_ins_tail( struct clist *clist,
                              void *data) {
    struct clist_elem *elem;
    elem = clist_get_tail(clist);
    if (elem == ((void *)0))
        return -1;
    return clist_ins_next(elem, data);
}

canonical_original_code:
int clist_ins_tail(struct clist *clist, void *data) {
    struct clist_elem *elem;
    elem = clist_get_tail(clist);
    if (elem == ((void *)0))
        return -1;
    return clist_ins_next(elem, data);
}


decompiled_code:
__int64 __fastcall clist_rem_next(_QWORD *a1, _QWORD ***a2)
{
void (__fastcall *v2)(_QWORD); // rdx
unsigned int v3; // er12
_QWORD *v4; // rdi

if ( clist_is_empty(a1) )
return (unsigned int)-1;
v3 = 0;
**a2 = a2;
v4 = **a2;
*a2 = (_QWORD **)v4;
if ( v2 )
{
v2(v4[1]);
v4 = *a2;
}
free(v4);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func7(_QWORD *a1, _QWORD ***a2)
{
void (__fastcall *v2)(_QWORD); // rdx
unsigned int v3; // er12
_QWORD *v4; // rdi

if ( func2(a1) )
return (unsigned int)-1;
v3 = 0;
**a2 = a2;
v4 = **a2;
*a2 = (_QWORD **)v4;
if ( v2 )
{
v2(v4[1]);
v4 = *a2;
}
free(v4);
return v3;
}

original_code:
int clist_rem_next( struct clist *clist,
                                 struct clist_elem *elem,
                              void (*destroy)(void *data)) {
    if (clist_is_empty(clist))
        return -1;
    elem->next->next = elem;
    elem->next = elem->next->next;
    if (destroy != ((void *)0))
        destroy(elem->next->data);
    free(elem->next);
    return 0;
}

canonical_original_code:
int clist_rem_next(struct clist *clist, struct clist_elem *elem, void (*destroy)(void *data)) {
    if (clist_is_empty(clist))
        return -1;
    elem->next->next = elem;
    elem->next = elem->next->next;
    if (destroy != ((void *)0))
        destroy(elem->next->data);
    free(elem->next);
    return 0;
}

variable_types:
elem
struct clist_elem *


decompiled_code:
__int64 __fastcall clist_rem_head(_QWORD *a1)
{
__int64 result; // rax

if ( clist_is_empty(a1) )
result = 0xFFFFFFFFLL;
else
result = clist_rem_next(a1, (_QWORD ***)a1);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(_QWORD *a1)
{
__int64 result; // rax

if ( func2(a1) )
result = 0xFFFFFFFFLL;
else
result = func7(a1, (_QWORD ***)a1);
return result;
}

original_code:
int clist_rem_head( struct clist *clist,
                              void (*destroy)(void *data)) {
    if (clist_is_empty(clist))
        return -1;
    return clist_rem_next(clist, &clist->link, destroy);
}

canonical_original_code:
int clist_rem_head(struct clist *clist, void (*destroy)(void *data)) {
    if (clist_is_empty(clist))
        return -1;
    return clist_rem_next(clist, &clist->link, destroy);
}


decompiled_code:
__int64 __fastcall clist_rem_tail(_QWORD *a1)
{
_QWORD *v1; // rdx
_QWORD ***v2; // rsi
_QWORD *v3; // rdi
_QWORD ***v4; // rax

if ( clist_is_empty(a1) )
return 0xFFFFFFFFLL;
v2 = (_QWORD ***)*a1;
v3 = *(_QWORD **)*a1;
while ( 1 )
{
v4 = (_QWORD ***)v3;
v3 = (_QWORD *)*v3;
if ( v3 == v1 )
break;
v2 = v4;
}
return clist_rem_next(v3, v2);
}

canonical_decompiled_code:
__int64 __fastcall func9(_QWORD *a1)
{
_QWORD *v1; // rdx
_QWORD ***v2; // rsi
_QWORD *v3; // rdi
_QWORD ***v4; // rax

if ( func2(a1) )
return 0xFFFFFFFFLL;
v2 = (_QWORD ***)*a1;
v3 = *(_QWORD **)*a1;
while ( 1 )
{
v4 = (_QWORD ***)v3;
v3 = (_QWORD *)*v3;
if ( v3 == v1 )
break;
v2 = v4;
}
return func7(v3, v2);
}

original_code:
int clist_rem_tail( struct clist *clist,
                              void (*destroy)(void *data)) {
    struct clist_elem *pretail;
    if (clist_is_empty(clist))
        return -1;
    for(pretail = clist->link.next;
        pretail->next->next != &clist->link;
        pretail = pretail->next);
    return clist_rem_next(clist, pretail, destroy);
}

canonical_original_code:
int clist_rem_tail(struct clist *clist, void (*destroy)(void *data)) {
    struct clist_elem *pretail;
    if (clist_is_empty(clist))
        return -1;
    for(pretail = clist->link.next;
        pretail->next->next != &clist->link;
        pretail = pretail->next);
    return clist_rem_next(clist, pretail, destroy);
}


decompiled_code:
__int64 __fastcall cdlist_get_size(_QWORD **a1)
{
_QWORD *v1; // rax
unsigned int i; // er8

v1 = *a1;
for ( i = 0; v1 != a1; ++i )
v1 = (_QWORD *)*v1;
return i;
}

original_code:
int cdlist_get_size( const struct cdlist *cdlist) {
    int count = 0;
    for (struct cdlist_elem * elem = cdlist->link.next; elem != &cdlist->link; elem = elem->next)
        count++;
    return count;
}

canonical_original_code:
int cdlist_get_size(struct cdlist *cdlist) {
    int count = 0;
    for (struct cdlist_elem *elem = cdlist->link.next; elem != &cdlist->link; elem = elem->next)
        count++;
    return count;
}

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

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

user_defined_types: struct cdlist { struct cdlist_elem link; }


decompiled_code:
_BOOL8 __fastcall cdlist_is_empty(_QWORD *a1)
{
return *a1 == (_QWORD)a1;
}

original_code:
int cdlist_is_empty( const struct cdlist *cdlist) {
    return cdlist->link.next == &cdlist->link;
}

canonical_original_code:
int cdlist_is_empty(struct cdlist *cdlist) {
    return cdlist->link.next == &cdlist->link;
}

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


decompiled_code:
__int64 __fastcall cdlist_get_head(__int64 *a1)
{
_BOOL4 v1; // er8
__int64 result; // rax

v1 = cdlist_is_empty(a1);
result = 0LL;
if ( !v1 )
result = *a1;
return result;
}

original_code:
struct cdlist_elem* cdlist_get_head( const struct cdlist *cdlist) {
    return cdlist_is_empty(cdlist) ? ((void *)0) : cdlist->link.next;
}

canonical_original_code:
struct cdlist_elem *cdlist_get_head(struct cdlist *cdlist) {
    return cdlist_is_empty(cdlist) ? ((void *)0) : cdlist->link.next;
}

variable_types: struct cdlist { struct cdlist_elem link; } *

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


decompiled_code:
// attributes: thunk
__int64 __fastcall cdlist_get_tail(__int64 *a1)
{
return cdlist_get_head(a1);
}

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

original_code:
struct cdlist_elem* cdlist_get_tail( const struct cdlist *cdlist) {
    return cdlist_is_empty(cdlist) ? ((void *)0) : cdlist->link.next;
}

canonical_original_code:
struct cdlist_elem *cdlist_get_tail(struct cdlist *cdlist) {
    return cdlist_is_empty(cdlist) ? ((void *)0) : cdlist->link.next;
}


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[1] = a1;
*v2 = v3;
*(_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;
}


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

canonical_decompiled_code:
__int64 __fastcall func6(__int64 *a1, __int64 a2)
{
return func5(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);
}


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

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

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

v2 = malloc(0x18uLL);
if ( !v2 )
return 0xFFFFFFFFLL;
v3 = *(_QWORD **)(a1 + 8);
*v2 = a1;
*(_QWORD *)(a1 + 8) = v2;
v2[1] = v3;
*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;
}


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

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2)
{
return func7(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);
}


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

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

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

v2 = *(_QWORD *)ptr;
v3 = (_QWORD *)*((_QWORD *)ptr + 1);
*(_QWORD *)(v2 + 8) = v3;
*v3 = v2;
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;
}


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 func10(__int64 *a1, void (__fastcall *a2)(_QWORD))
{
void *v2; // rax
__int64 result; // rax

v2 = (void *)func3(a1);
if ( v2 )
result = func9(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:
// attributes: thunk
__int64 __fastcall cdlist_rem_tail(__int64 *a1, void (__fastcall *a2)(_QWORD))
{
return cdlist_rem_head(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 *a1, void (__fastcall *a2)(_QWORD))
{
return func10(a1, a2);
}

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);
}


main

canonical_name: main

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

v3 = 0;
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");
while ( 1 )
{
printf(
"% 4d % 8d % 8d % 8d\n",
v3,
(unsigned int)axes,
(unsigned int)dword_404068,
(unsigned int)g_nop_delay_hstep_dly);
if ( !axes )
break;
++v3;
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 v3; // ebx

v3 = 0;
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");
while ( 1 )
{
printf(
"% 4d % 8d % 8d % 8d\n",
v3,
(unsigned int)axes,
(unsigned int)dword_404068,
(unsigned int)g_nop_delay_hstep_dly);
if ( !axes )
break;
++v3;
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: 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; } *

variable_types: i int


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:
void __fastcall service_axis_loop(int *a1)
{
int v1; // edx
int v3; // esi
int v4; // eax
int v5; // esi
int v6; // edi
bool v7; // cc
int v8; // eax
int v9; // edi
int *v10; // rcx
int v11; // eax
int v12; // eax
int v13; // eax

v1 = *a1;
if ( !*a1 )
{
a1[2] = 0;
return;
}
v3 = a1[2];
v4 = g_velmin;
if ( v1 <= 0 )
{
v13 = -g_velmin;
if ( -g_velmin > v3 )
v13 = a1[2];
v6 = v13 - g_accel;
if ( g_accel * v1 >= v13 )
v6 = g_accel + v13;
v8 = -g_velmax;
a1[2] = v6;
if ( v8 <= v6 )
goto LABEL_8;
}
else
{
if ( g_velmin < v3 )
v4 = a1[2];
v5 = v4 - g_accel;
v6 = v4 + g_accel;
v7 = g_accel * v1 / 2 <= v4;
v8 = g_velmax;
if ( v7 )
v6 = v5;
a1[2] = v6;
if ( v8 >= v6 )
goto LABEL_8;
}
a1[2] = v8;
v6 = v8;
LABEL_8:
v9 = vel2halfstep(v6);
nop_delay(v9);
nop_delay(v9);
v11 = *v10;
if ( *v10 <= 0 )
{
v12 = v11 + 1;
--v10[1];
}
else
{
v12 = v11 - 1;
++v10[1];
}
*v10 = v12;
}

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;
    }
}

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; }


decompiled_code:
void __fastcall service_axis(int *a1)
{
int v2; // er9

if ( *a1 )
{
do
service_axis_loop(a1);
while ( v2 != 1 );
}
else
{
a1[2] = 0;
}
}

canonical_decompiled_code:
void __fastcall func12(int *a1)
{
int v2; // er9

if ( *a1 )
{
do
func11(a1);
while ( v2 != 1 );
}
else
{
a1[2] = 0;
}
}

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


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:
__int64 __fastcall SuperAngle(unsigned int a1)
{
__int64 result; // rax
int v2; // eax
unsigned int v3; // eax

result = a1;
if ( (a1 & 0x8000u) == 0 )
{
if ( (__int16)a1 > 4095 )
{
v3 = a1 - 4096;
LOWORD(v3) = (a1 - 4096) & 0xF000;
result = a1 - v3 - 4096;
}
}
else
{
HIWORD(v2) = ~HIWORD(a1);
LOWORD(v2) = ~(_WORD)a1 & 0xF000;
result = v2 + a1 + 4096;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1)
{
__int64 result; // rax
int v2; // eax
unsigned int v3; // eax

result = a1;
if ( (a1 & 0x8000u) == 0 )
{
if ( (__int16)a1 > 4095 )
{
v3 = a1 - 4096;
LOWORD(v3) = (a1 - 4096) & 0xF000;
result = a1 - v3 - 4096;
}
}
else
{
HIWORD(v2) = ~HIWORD(a1);
LOWORD(v2) = ~(_WORD)a1 & 0xF000;
result = v2 + a1 + 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; // er8

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

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

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; // er8

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

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

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; // er8

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

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

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; // er8

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

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

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; // er8

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

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

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; // er8

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

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

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; // er8

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

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

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; // er8

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; // er8

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 != 0);
if ( a1 > 0 )
result = 1LL;
return result;
}

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

result = (unsigned int)-(a1 != 0);
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 v1; // rdi
__int64 result; // rax

v0 = &d_sound;
do
{
v1 = *v0++;
result = Mix_FreeChunk(v1);
*(v0 - 1) = 0LL;
}
while ( v0 != &d_sound + 4 );
if ( music )
{
result = Mix_FreeMusic();
music = 0LL;
}
e_sound = 0LL;
return result;
}

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

v0 = &d_sound;
do
{
v1 = *v0++;
result = Mix_FreeChunk(v1);
*(v0 - 1) = 0LL;
}
while ( v0 != &d_sound + 4 );
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)
{
__int64 v2; // rdi

if ( a1 == (char)0x80 )
{
Mix_PauseMusic();
MusicPlaying = a1;
}
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);
v2 = music;
if ( !music )
{
printf("File not found: %s\n", spath);
v2 = music;
}
Mix_PlayMusic(v2, 0xFFFFFFFFLL);
}
MusicPlaying = a1;
}
}

canonical_decompiled_code:
void __fastcall func3(char a1)
{
__int64 v2; // rdi

if ( a1 == (char)0x80 )
{
Mix_PauseMusic();
MusicPlaying = a1;
}
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);
v2 = music;
if ( !music )
{
printf("File not found: %s\n", spath);
v2 = music;
}
Mix_PlayMusic(v2, 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 )
{
v2 = (const char *)SDL_GetError();
fprintf(stderr, "Couldn't initialize SDL: %s\n", v2);
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 )
{
v0 = (const char *)SDL_GetError();
fprintf(stderr, "Couldn't open joystick 0: %s\n", v0);
}
}
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 )
{
v2 = (const char *)SDL_GetError();
fprintf(stderr, "Couldn't initialize SDL: %s\n", v2);
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 )
{
v0 = (const char *)SDL_GetError();
fprintf(stderr, "Couldn't open joystick 0: %s\n", v0);
}
}
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; // r9
unsigned __int8 *v1; // rdi
__int64 v2; // r8
__int64 i; // rcx
__int64 v4; // rsi
__int64 v5; // rdx
__int64 result; // rax

CoreProcInput();
SDL_LockSurface(screen);
v0 = screen;
v1 = (unsigned __int8 *)&scrbuf;
v2 = *(_QWORD *)(screen + 32);
do
{
for ( i = 0LL; i != 320; ++i )
{
v4 = 3LL * v1[i];
v5 = (*((unsigned __int8 *)&palette + v4 + 1) << 8) + (unsigned int)*((unsigned __int8 *)&palette + v4 + 2);
*(_DWORD *)(v2 + 4 * i) = v5 + (*((unsigned __int8 *)&palette + v4) << 16);
}
v1 += 320;
v2 += 1280LL;
}
while ( v1 != (unsigned __int8 *)((char *)&scrbuf + 76800) );
SDL_UnlockSurface(v0, v4, v5, 320LL, v2);
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; // r9
unsigned __int8 *v1; // rdi
__int64 v2; // r8
__int64 i; // rcx
__int64 v4; // rsi
__int64 v5; // rdx
__int64 result; // rax

func9();
SDL_LockSurface(screen);
v0 = screen;
v1 = (unsigned __int8 *)&scrbuf;
v2 = *(_QWORD *)(screen + 32);
do
{
for ( i = 0LL; i != 320; ++i )
{
v4 = 3LL * v1[i];
v5 = (*((unsigned __int8 *)&palette + v4 + 1) << 8) + (unsigned int)*((unsigned __int8 *)&palette + v4 + 2);
*(_DWORD *)(v2 + 4 * i) = v5 + (*((unsigned __int8 *)&palette + v4) << 16);
}
v1 += 320;
v2 += 1280LL;
}
while ( v1 != (unsigned __int8 *)((char *)&scrbuf + 76800) );
SDL_UnlockSurface(v0, v4, v5, 320LL, v2);
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()
{
unsigned __int64 i; // rax
__int64 j; // rax
__int64 v2; // rdx

for ( i = 0LL; ; ++i )
{
if ( i <= 0xEF )
{
*((_BYTE *)&NextColor0 + i) = i + 16;
continue;
}
*((_BYTE *)&NextColor0 + i) = i;
if ( (_WORD)i == 255 )
break;
}
for ( j = 0LL;
j != 256;
*((_BYTE *)&NextColor2 + j - 1) = *((_BYTE *)&NextColor0 + *((unsigned __int8 *)&NextColor0 + v2)) )
{
v2 = *((unsigned __int8 *)&NextColor0 + j++);
}
return ResetMap();
}

canonical_decompiled_code:
__int64 func0()
{
unsigned __int64 i; // rax
__int64 j; // rax
__int64 v2; // rdx

for ( i = 0LL; ; ++i )
{
if ( i <= 0xEF )
{
*((_BYTE *)&NextColor0 + i) = i + 16;
continue;
}
*((_BYTE *)&NextColor0 + i) = i;
if ( (_WORD)i == 255 )
break;
}
for ( j = 0LL;
j != 256;
*((_BYTE *)&NextColor2 + j - 1) = *((_BYTE *)&NextColor0 + *((unsigned __int8 *)&NextColor0 + v2)) )
{
v2 = *((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, __int16 a4)
{
unsigned __int64 result; // rax
int v7; // edx
int v8; // er9
__int64 v9; // r8
int v10; // esi
_BYTE *v11; // r10
__int64 v12; // r8
unsigned __int8 *v13; // rcx
int v14; // er10
__int64 v15; // rdx

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

canonical_decompiled_code:
unsigned __int64 __fastcall func2(__int16 a1, __int16 a2, __int16 a3, __int16 a4)
{
unsigned __int64 result; // rax
int v7; // edx
int v8; // er9
__int64 v9; // r8
int v10; // esi
_BYTE *v11; // r10
__int64 v12; // r8
unsigned __int8 *v13; // rcx
int v14; // er10
__int64 v15; // rdx

result = (unsigned int)a4;
v7 = a2;
if ( a2 <= (int)result )
{
v8 = a1;
v9 = (unsigned int)(a3 - a1);
v10 = a1 + 320 * a2;
v11 = &scrbuf[v9 + 1 + a1];
v12 = ~v9;
v13 = &v11[320 * v7];
v14 = v8 + 320 * (v7 + result) + 320 - 320 * v7;
do
{
result = (unsigned __int64)&v13[v12];
if ( v8 <= a3 )
{
do
{
v15 = *(unsigned __int8 *)result++;
*(_BYTE *)(result - 1) = *((_BYTE *)&NextColor2 + v15);
}
while ( (unsigned __int8 *)result != v13 );
}
v10 += 320;
v13 += 320;
}
while ( v10 != v14 );
}
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)
{
int v3; // er15
unsigned int v4; // ebx
unsigned int v6; // er13
__int64 v7; // r14
int v8; // esi
unsigned int v9; // er9
int v10; // er11
unsigned int v11; // ecx
unsigned int v12; // edx
unsigned int v13; // eax

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

canonical_decompiled_code:
void __fastcall func4(__int16 a1, __int16 a2, char a3)
{
int v3; // er15
unsigned int v4; // ebx
unsigned int v6; // er13
__int64 v7; // r14
int v8; // esi
unsigned int v9; // er9
int v10; // er11
unsigned int v11; // ecx
unsigned int v12; // edx
unsigned int v13; // eax

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

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

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; // rdi
int v2; // edx
unsigned int v3; // ebx
__int64 result; // rax

v1 = &mob[16 * (unsigned __int64)a1];
v2 = v1[2];
if ( !v1[10] )
{
v3 = *((unsigned __int8 *)v1 + 4);
result = (unsigned __int8)v2;
if ( (_BYTE)v2 != 1 )
goto LABEL_3;
LABEL_7:
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_9;
return result;
}
v1[10] = 0;
v3 = 15;
result = (unsigned __int8)v2;
if ( (_BYTE)v2 == 1 )
goto LABEL_7;
LABEL_3:
if ( (_DWORD)result == 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 )
{
result = vvis;
if ( vvis )
{
DrawLine2(vbufferx[0], vbuffery[0], vbufferx[1], vbuffery[1], v3);
DrawLine2(vbufferx[2], vbuffery[2], vbufferx[1], vbuffery[1], v3);
DrawLine2(vbufferx[2], vbuffery[2], vbufferx[3], vbuffery[3], v3);
result = DrawLine2(vbufferx[3], vbuffery[3], vbufferx[0], vbuffery[0], v3);
}
}
}
else if ( !(_DWORD)result )
{
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_9:
DrawLine2(vbufferx[0], vbuffery[0], vbufferx[1], vbuffery[1], v3);
DrawLine2(vbufferx[2], vbuffery[2], vbufferx[1], vbuffery[1], v3);
return DrawLine2(vbufferx[2], vbuffery[2], vbufferx[0], vbuffery[0], v3);
}
}
}
return result;
}

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

v1 = &mob[16 * (unsigned __int64)a1];
v2 = v1[2];
if ( !v1[10] )
{
v3 = *((unsigned __int8 *)v1 + 4);
result = (unsigned __int8)v2;
if ( (_BYTE)v2 != 1 )
goto LABEL_3;
LABEL_7:
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_9;
return result;
}
v1[10] = 0;
v3 = 15;
result = (unsigned __int8)v2;
if ( (_BYTE)v2 == 1 )
goto LABEL_7;
LABEL_3:
if ( (_DWORD)result == 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 )
{
result = vvis;
if ( vvis )
{
DrawLine2(vbufferx[0], vbuffery[0], vbufferx[1], vbuffery[1], v3);
DrawLine2(vbufferx[2], vbuffery[2], vbufferx[1], vbuffery[1], v3);
DrawLine2(vbufferx[2], vbuffery[2], vbufferx[3], vbuffery[3], v3);
result = DrawLine2(vbufferx[3], vbuffery[3], vbufferx[0], vbuffery[0], v3);
}
}
}
else if ( !(_DWORD)result )
{
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_9:
DrawLine2(vbufferx[0], vbuffery[0], vbufferx[1], vbuffery[1], v3);
DrawLine2(vbufferx[2], vbuffery[2], vbufferx[1], vbuffery[1], v3);
return DrawLine2(vbufferx[2], vbuffery[2], vbufferx[0], vbuffery[0], v3);
}
}
}
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:
__int64 RenderMobs()
{
__int64 v0; // rbp
int *v1; // rbx
__int64 result; // rax

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

canonical_decompiled_code:
__int64 func2()
{
__int64 v0; // rbp
int *v1; // rbx
__int64 result; // rax

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

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; // er14
__int64 result; // rax
int v2; // ebx
unsigned int v3; // ebp
unsigned int v4; // er13
char *v5; // r15
int v6; // eax
__int64 v7; // r14
int v8; // esi
__int64 v9; // rbx
int v10; // esi
unsigned int v11; // ebp
char *v12; // r12
int v13; // esi
unsigned int v14; // er15
char *v15; // r14
__int64 v16; // rbx
int v17; // esi
int v18; // esi
int v19; // esi
__int64 v20; // rdx
int v21; // er13
unsigned int v22; // ebp
int v23; // eax
int v24; // er14
char *v25; // r15
char *v26; // rcx
__int64 v27; // rbx
char *v28; // r15
int v29; // esi
char *v30; // rbx
unsigned int v31; // ebp
unsigned int v32; // er13
unsigned int v33; // er14
int v34; // esi
int v35; // esi
unsigned int v36; // ebp
unsigned int v37; // er15
char *v38; // r14
char *v39; // rcx
__int64 v40; // rbx
char *v41; // r14
int v42; // esi
char *v43; // rbx
int v44; // esi
int v45; // esi
char *v46; // [rsp+8h] [rbp-70h]
__int64 v47; // [rsp+8h] [rbp-70h]
char *v48; // [rsp+8h] [rbp-70h]
char *v49; // [rsp+10h] [rbp-68h]
char *v50; // [rsp+18h] [rbp-60h]
char *v51; // [rsp+20h] [rbp-58h]
unsigned int v52; // [rsp+2Ch] [rbp-4Ch]
char *v53; // [rsp+30h] [rbp-48h]
char *v54; // [rsp+38h] [rbp-40h]

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