decompiled_code:
void **__fastcall dar_new_from_bytes(signed int a1, const void *a2, int a3)
{
void **v4; // rbp

v4 = 0LL;
if ( !(a3 % a1) )
{
v4 = (void **)dar_new(a1, a3 / a1);
memcpy(*v4, a2, a3);
*((_DWORD *)v4 + 3) += a3 / a1;
*((_DWORD *)v4 + 5) -= a3 / a1;
}
return v4;
}

canonical_decompiled_code:
void **__fastcall func6(signed int a1, const void *a2, int a3)
{
void **v4; // rbp

v4 = 0LL;
if ( !(a3 % a1) )
{
v4 = (void **)func5(a1, a3 / a1);
memcpy(*v4, a2, a3);
*((_DWORD *)v4 + 3) += a3 / a1;
*((_DWORD *)v4 + 5) -= a3 / a1;
}
return v4;
}

original_code:
dar_t * dar_new_from_bytes(int element_size, void * b, int len) {
    if ( len % element_size ) return ((void *)0);
    dar_t * r = dar_new(element_size, len / element_size);
    memcpy(r->data,b,len);
    r->element_count += len / element_size;
    r->element_free -= len / element_size;
    return r;
}

canonical_original_code:
struct dar *dar_new_from_bytes(int element_size, void *b, int len) {
    if ( len % element_size ) return ((void *)0);
    struct dar *r = dar_new(element_size, len / element_size);
    memcpy(r->data,b,len);
    r->element_count += len / element_size;
    r->element_free -= len / element_size;
    return r;
}

variable_types:
b
void *

variable_types: len int


repo: gabrielrussell/euler-c

decompiled_code:
void *__fastcall dar_store(__int64 a1, const void *a2, int a3)
{
return memcpy((void *)(*(_QWORD *)a1 + *(_DWORD *)(a1 + 16) * a3), a2, *(int *)(a1 + 16));
}

canonical_decompiled_code:
void *__fastcall func7(__int64 a1, const void *a2, int a3)
{
return memcpy((void *)(*(_QWORD *)a1 + *(_DWORD *)(a1 + 16) * a3), a2, *(int *)(a1 + 16));
}

original_code:
void dar_store(dar_t * a, void * e, int i) {
    memcpy(a->data + ( i * a->element_size), e, a->element_size);
}

canonical_original_code:
void dar_store(struct dar *a, void *e, int i) {
    memcpy(a->data + ( i * a->element_size), e, a->element_size);
}

variable_types: struct dar { void *data; int data_size; int element_count; int element_size; int element_free; } *

variable_types:
e
void *

variable_types: i int

return_type: void


decompiled_code:
void *__fastcall dar_push(__int64 a1, const void *a2)
{
void *result; // rax

dar_readyplus(a1, 1);
result = dar_store(a1, a2, *(_DWORD *)(a1 + 12));
++*(_DWORD *)(a1 + 12);
--*(_DWORD *)(a1 + 20);
return result;
}

canonical_decompiled_code:
void *__fastcall func8(__int64 a1, const void *a2)
{
void *result; // rax

func0(a1, 1);
result = func7(a1, a2, *(_DWORD *)(a1 + 12));
++*(_DWORD *)(a1 + 12);
--*(_DWORD *)(a1 + 20);
return result;
}

original_code:
void dar_push(dar_t * a, void * e) {
 dar_readyplus(a,1);
 dar_store(a,e,a->element_count);
 a->element_count++;
 a->element_free--;
}

canonical_original_code:
void dar_push(struct dar *a, void *e) {
 dar_readyplus(a,1);
 dar_store(a,e,a->element_count);
 a->element_count++;
 a->element_free--;
}

user_defined_types: struct dar { void *data; int data_size; int element_count; int element_size; int element_free; }


decompiled_code:
__int64 __fastcall dar_index(__int64 a1, int a2)
{
return *(_QWORD *)a1 + *(_DWORD *)(a1 + 16) * a2;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, int a2)
{
return *(_QWORD *)a1 + *(_DWORD *)(a1 + 16) * a2;
}

original_code:
void * dar_index( dar_t * a, int i ) {
    return a->data + a->element_size * i;
}

canonical_original_code:
void *dar_index(struct dar *a, int i) {
    return a->data + a->element_size * i;
}

return_type: void *


decompiled_code:
__int64 __fastcall dar_fetch(__int64 a1, void *a2, int a3)
{
__int64 result; // rax
const void *v4; // rax

if ( *(_DWORD *)(a1 + 12) <= a3 )
return 0LL;
result = 0LL;
if ( a3 >= 0 )
{
result = 1LL;
if ( a2 )
{
v4 = (const void *)dar_index(a1, a3);
memcpy(a2, v4, *(int *)(a1 + 16));
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, void *a2, int a3)
{
__int64 result; // rax
const void *v4; // rax

if ( *(_DWORD *)(a1 + 12) <= a3 )
return 0LL;
result = 0LL;
if ( a3 >= 0 )
{
result = 1LL;
if ( a2 )
{
v4 = (const void *)func9(a1, a3);
memcpy(a2, v4, *(int *)(a1 + 16));
result = 1LL;
}
}
return result;
}

original_code:
int dar_fetch(dar_t * a, void * e, int i) {
    if ( i > a->element_count - 1 ) return(0);
    if ( i < 0 ) return(0);
    if (e) memcpy(e, dar_index( a, i ), a->element_size);
    return(1);
}

canonical_original_code:
int dar_fetch(struct dar *a, void *e, int i) {
    if ( i > a->element_count - 1 ) return(0);
    if ( i < 0 ) return(0);
    if (e) memcpy(e, dar_index( a, i ), a->element_size);
    return(1);
}

return_type: int


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

result = *(unsigned int *)(a1 + 12);
if ( (_DWORD)result )
{
if ( !a2 || (result = dar_fetch(a1, a2, (int)result - 1), (_DWORD)result) )
{
--*(_DWORD *)(a1 + 12);
++*(_DWORD *)(a1 + 20);
result = 1LL;
}
}
return result;
}

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

result = *(unsigned int *)(a1 + 12);
if ( (_DWORD)result )
{
if ( !a2 || (result = func10(a1, a2, (int)result - 1), (_DWORD)result) )
{
--*(_DWORD *)(a1 + 12);
++*(_DWORD *)(a1 + 20);
result = 1LL;
}
}
return result;
}

original_code:
int dar_pop(dar_t * a,void *e ) {
        if ( ! a->element_count ) return(0);
 if (e) {
            if (!dar_fetch(a,e,a->element_count - 1 ))
                return(0);
        }
 a->element_count--;
 a->element_free++;
        return(1);
}

canonical_original_code:
int dar_pop(struct dar *a, void *e) {
        if ( ! a->element_count ) return(0);
 if (e) {
            if (!dar_fetch(a,e,a->element_count - 1 ))
                return(0);
        }
 a->element_count--;
 a->element_free++;
        return(1);
}


decompiled_code:
void *__fastcall dar_reverse(__int64 a1)
{
void *v1; // r12
int v2; // ebx
const void *v3; // rax

v1 = dar_new(*(_DWORD *)(a1 + 16), *(_DWORD *)(a1 + 12));
v2 = *(_DWORD *)(a1 + 12) - 1;
if ( v2 >= 0 )
{
do
{
v3 = (const void *)dar_index(a1, v2);
dar_push((__int64)v1, v3);
--v2;
}
while ( v2 != -1 );
}
return v1;
}

original_code:
dar_t * dar_reverse( dar_t * a ) {
    int i;
    dar_t * r = dar_new(a->element_size,a->element_count);
    for ( i=a->element_count-1; i>=0; i-- ) dar_push(r, dar_index( a , i) );
    return r;
}

canonical_original_code:
struct dar *dar_reverse(struct dar *a) {
    int i;
    struct dar *r = dar_new(a->element_size,a->element_count);
    for ( i=a->element_count-1; i>=0; i-- ) dar_push(r, dar_index( a , i) );
    return r;
}

variable_types:
a
struct dar *

return_type: struct dar { void *data; int data_size; int element_count; int element_size; int element_free; } *


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

result = *(unsigned int *)(a1 + 12);
if ( (int)result > a2 )
{
*(_DWORD *)(a1 + 12) = a2;
result = (unsigned int)(result - a2);
*(_DWORD *)(a1 + 20) += result;
}
return result;
}

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

result = *(unsigned int *)(a1 + 12);
if ( (int)result > a2 )
{
*(_DWORD *)(a1 + 12) = a2;
result = (unsigned int)(result - a2);
*(_DWORD *)(a1 + 20) += result;
}
return result;
}

original_code:
void dar_trim( dar_t * a, int i ) {
    int d;
    if ( a->element_count > i ) {
        d = a->element_count - i;
        a->element_count -= d;
        a->element_free += d;
    }
}

canonical_original_code:
void dar_trim(struct dar *a, int i) {
    int d;
    if ( a->element_count > i ) {
        d = a->element_count - i;
        a->element_count -= d;
        a->element_free += d;
    }
}

variable_types: d int


decompiled_code:
__int64 __fastcall string_array_itr_next(__int64 a1, const char **a2, size_t *a3)
{
int v3; // eax
const char **v4; // rcx
const char *v5; // rdi

v3 = *(_DWORD *)(*(_QWORD *)a1 + 8LL);
v4 = (const char **)(**(_QWORD **)a1 + 8LL * v3);
if ( !*v4 )
return 0LL;
*(_DWORD *)(*(_QWORD *)a1 + 8LL) = v3 + 1;
v5 = *v4;
*a2 = *v4;
*a3 = strlen(v5);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, const char **a2, size_t *a3)
{
int v3; // eax
const char **v4; // rcx
const char *v5; // rdi

v3 = *(_DWORD *)(*(_QWORD *)a1 + 8LL);
v4 = (const char **)(**(_QWORD **)a1 + 8LL * v3);
if ( !*v4 )
return 0LL;
*(_DWORD *)(*(_QWORD *)a1 + 8LL) = v3 + 1;
v5 = *v4;
*a2 = *v4;
*a3 = strlen(v5);
return 1LL;
}

original_code:
int string_array_itr_next ( itr_t * i, char **lineptr, size_t *n ) {
    string_array_itr_t *sai = i->context;
    if (!sai->array[sai->position]) return 0;
    *lineptr = sai->array[sai->position++];
    *n = strlen( *lineptr );
    return(1);
}

canonical_original_code:
int string_array_itr_next(struct itr *i, char **lineptr, unsigned long *n) {
    struct string_array_itr *sai = i->context;
    if (!sai->array[sai->position]) return 0;
    *lineptr = sai->array[sai->position++];
    *n = strlen( *lineptr );
    return(1);
}

variable_types: struct itr { void *context; void (*destructor)(struct itr *); int (*next)(struct itr *, char **, unsigned long *); } *

variable_types:
lineptr
char **

variable_types:
n
unsigned long *

variable_types: struct string_array_itr { char **array; int position; } *


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

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

original_code:
void string_array_itr_destroy( itr_t * i ) {
    free(i->context);
    free(i);
}

canonical_original_code:
void string_array_itr_destroy(struct itr *i) {
    free(i->context);
    free(i);
}

user_defined_types: struct itr { void *context; void (*destructor)(struct itr *); int (*next)(struct itr *, char **, unsigned long *); }


decompiled_code:
__int64 __fastcall mdjb_hash(__int64 a1, int a2)
{
char *v2; // rdx
__int64 v3; // rsi
__int64 result; // rax

if ( a2 - 1 < 0 )
return 0LL;
v2 = (char *)(a1 + a2 - 1);
v3 = a1 + a2 - 2 - (unsigned int)(a2 - 1);
LODWORD(result) = 0;
do
result = *v2-- ^ (unsigned int)(33 * result);
while ( v2 != (char *)v3 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2)
{
char *v2; // rdx
__int64 v3; // rsi
__int64 result; // rax

if ( a2 - 1 < 0 )
return 0LL;
v2 = (char *)(a1 + a2 - 1);
v3 = a1 + a2 - 2 - (unsigned int)(a2 - 1);
LODWORD(result) = 0;
do
result = *v2-- ^ (unsigned int)(33 * result);
while ( v2 != (char *)v3 );
return result;
}

original_code:
uint32_t mdjb_hash ( char * key, int l ) {
    uint32_t h = 0;
    while ( --l >= 0 ) h = 33 * h ^ key[l];
    return h;
}

canonical_original_code:
unsigned int mdjb_hash(char *key, int l) {
    unsigned int h = 0;
    while ( --l >= 0 ) h = 33 * h ^ key[l];
    return h;
}

variable_types:
key
char *

variable_types: l int

variable_types:
h
unsigned int

return_type: unsigned int


decompiled_code:
__int64 __fastcall ht_make_entry(void *src, int a2, const void *a3, int a4)
{
size_t v5; // r15
_DWORD *v6; // rax
__int64 v7; // rbx
void *v8; // rdi
__int64 result; // rax
int *v10; // rax

v5 = a4;
v6 = calloc(1uLL, a2 + (__int64)a4 + 42);
if ( v6 )
{
v7 = (__int64)v6;
*v6 = mdjb_hash((__int64)src, a2);
*(_QWORD *)(v7 + 8) = v7 + 40;
*(_DWORD *)(v7 + 16) = a2;
memcpy((void *)(v7 + 40), src, a2);
*(_BYTE *)(v7 + a2 + 40) = 0;
v8 = (void *)(v7 + a2 + 41);
*(_QWORD *)(v7 + 24) = v8;
*(_DWORD *)(v7 + 32) = a4;
memcpy(v8, a3, v5);
*(_BYTE *)(*(_QWORD *)(v7 + 24) + v5) = 0;
result = v7;
}
else
{
v10 = _errno_location();
error(1, *v10, "failure to calloc ht_entry_t");
result = ht_insert_entry();
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(void *src, int a2, const void *a3, int a4)
{
size_t v5; // r15
_DWORD *v6; // rax
__int64 v7; // rbx
void *v8; // rdi
__int64 result; // rax
int *v10; // rax

v5 = a4;
v6 = calloc(1uLL, a2 + (__int64)a4 + 42);
if ( v6 )
{
v7 = (__int64)v6;
*v6 = func0((__int64)src, a2);
*(_QWORD *)(v7 + 8) = v7 + 40;
*(_DWORD *)(v7 + 16) = a2;
memcpy((void *)(v7 + 40), src, a2);
*(_BYTE *)(v7 + a2 + 40) = 0;
v8 = (void *)(v7 + a2 + 41);
*(_QWORD *)(v7 + 24) = v8;
*(_DWORD *)(v7 + 32) = a4;
memcpy(v8, a3, v5);
*(_BYTE *)(*(_QWORD *)(v7 + 24) + v5) = 0;
result = v7;
}
else
{
v10 = _errno_location();
error(1, *v10, "failure to calloc ht_entry_t");
result = func2();
}
return result;
}

original_code:
ht_entry_t * ht_make_entry( char * key, int key_length, char * value, int value_length ) {
    ht_entry_t * e = calloc( 1, sizeof(ht_entry_t) + key_length + 1 + value_length + 1 );
    if ( e == ((void *)0) ) error(1,(*__errno_location ()),"failure to calloc  ht_entry_t");
    e->hash = mdjb_hash( key, key_length );
    e->key = (char *) e + sizeof(ht_entry_t);
    e->key_length = key_length;
    memcpy(e->key, key, key_length);
    e->key[key_length] = 0;
    e->value = (char *) e + sizeof(ht_entry_t) + key_length + 1;
    e->value_length = value_length;
    memcpy(e->value, value, value_length);
    e->value[value_length] = 0;
    return e;
}

canonical_original_code:
struct ht_entry *ht_make_entry(char *key, int key_length, char *value, int value_length) {
    struct ht_entry *e = calloc( 1, sizeof(ht_entry_t) + key_length + 1 + value_length + 1 );
    if ( e == ((void *)0) ) error(1,(*__errno_location ()),"failure to calloc  ht_entry_t");
    e->hash = mdjb_hash( key, key_length );
    e->key = (char *) e + sizeof(ht_entry_t);
    e->key_length = key_length;
    memcpy(e->key, key, key_length);
    e->key[key_length] = 0;
    e->value = (char *) e + sizeof(ht_entry_t) + key_length + 1;
    e->value_length = value_length;
    memcpy(e->value, value, value_length);
    e->value[value_length] = 0;
    return e;
}

variable_types:
value
char *

variable_types: struct ht_entry { unsigned int hash; char *key; int key_length; char *value; int value_length; } *


original_code:
void ht_grow(ht_t * ht) {
    ht_t ht_orig = *ht;
    ht->size = ht->size ? ht->size * 2 : 32;
    ht->table = calloc( 1, sizeof(ht_entry_t *) * ht->size );
    ht->num = 0;
    ht->free = ht->size / 2;
    int i;
    for ( i=0; i < ht_orig.size; i++ ) {
        if ( ht_orig.table[i] ) {
            ht_insert_entry(ht,ht_orig.table[i]);
        }
    }
    free(ht_orig.table);
}

canonical_original_code:
void ht_grow(struct ht *ht) {
    struct ht ht_orig = *ht;
    ht->size = ht->size ? ht->size * 2 : 32;
    ht->table = calloc( 1, sizeof(struct ht_entry *) * ht->size );
    ht->num = 0;
    ht->free = ht->size / 2;
    int i;
    for ( i=0; i < ht_orig.size; i++ ) {
        if ( ht_orig.table[i] ) {
            ht_insert_entry(ht,ht_orig.table[i]);
        }
    }
    free(ht_orig.table);
}

variable_types: struct ht { struct ht_entry { unsigned int hash; char *key; int key_length; char *value; int value_length; } **table; int size; int num; int free; } *

user_defined_types: struct ht { struct ht_entry **table; int size; int num; int free; }


original_code:
int ht_fetch( ht_t * ht, void * key, int key_length, void ** value, int * value_length ) {
    uint32_t hash = mdjb_hash( key, key_length );
    if (!ht->size) return(0);
    int hunt = hash % ht->size ;
    while ( ht->table[hunt] != ((void *)0) ) {
        if (ht->table[hunt]->hash == hash && ht->table[hunt]->key_length == key_length && memcmp(ht->table[hunt]->key,key,key_length) == 0 ) {
            *value = ht->table[hunt]->value;
            *value_length = ht->table[hunt]->value_length;
            return(1);
        }
        hunt = ( hunt + 1 ) % ht->size;
    }
    return(0);
}

canonical_original_code:
int ht_fetch(struct ht *ht, void *key, int key_length, void **value, int *value_length) {
    unsigned int hash = mdjb_hash( key, key_length );
    if (!ht->size) return(0);
    int hunt = hash % ht->size;
    while ( ht->table[hunt] != ((void *)0) ) {
        if (ht->table[hunt]->hash == hash && ht->table[hunt]->key_length == key_length && memcmp(ht->table[hunt]->key,key,key_length) == 0 ) {
            *value = ht->table[hunt]->value;
            *value_length = ht->table[hunt]->value_length;
            return(1);
        }
        hunt = ( hunt + 1 ) % ht->size;
    }
    return(0);
}

variable_types:
key
void *

variable_types:
value
void **

variable_types:
hash
unsigned int

variable_types: hunt int

user_defined_types: struct ht_entry { unsigned int hash; char *key; int key_length; char *value; int value_length; }


decompiled_code:
void __fastcall ht_destroy(void *ptr)
{
__int64 v2; // rbx
void *v3; // rdi

if ( *((int *)ptr + 2) > 0 )
{
v2 = 0LL;
do
{
v3 = *(void **)(*(_QWORD *)ptr + 8 * v2);
if ( v3 )
{
free(v3);
*(_QWORD *)(*(_QWORD *)ptr + 8 * v2) = 0LL;
}
++v2;
}
while ( *((_DWORD *)ptr + 2) > (int)v2 );
}
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func6(void *ptr)
{
__int64 v2; // rbx
void *v3; // rdi

if ( *((int *)ptr + 2) > 0 )
{
v2 = 0LL;
do
{
v3 = *(void **)(*(_QWORD *)ptr + 8 * v2);
if ( v3 )
{
free(v3);
*(_QWORD *)(*(_QWORD *)ptr + 8 * v2) = 0LL;
}
++v2;
}
while ( *((_DWORD *)ptr + 2) > (int)v2 );
}
free(*(void **)ptr);
free(ptr);
}

original_code:
void ht_destroy(ht_t * ht) {
    int i;
    for ( i = 0; i < ht->size ; i++ ) {
        if (ht->table[i]) {
            free(ht->table[i]);
            ht->table[i]=0;
        }
    }
    free(ht->table);
    free(ht);
}

canonical_original_code:
void ht_destroy(struct ht *ht) {
    int i;
    for ( i = 0; i < ht->size ; i++ ) {
        if (ht->table[i]) {
            free(ht->table[i]);
            ht->table[i]=0;
        }
    }
    free(ht->table);
    free(ht);
}

variable_types: i int


decompiled_code:
void *ht_new()
{
return calloc(1uLL, 0x18uLL);
}

canonical_decompiled_code:
void *func7()
{
return calloc(1uLL, 0x18uLL);
}

original_code:
ht_t * ht_new(void) {
    return(calloc(1,sizeof(ht_t)));
}

canonical_original_code:
struct ht *ht_new() {
    return(calloc(1,sizeof(ht_t)));
}

return_type: struct ht { struct ht_entry { unsigned int hash; char *key; int key_length; char *value; int value_length; } **table; int size; int num; int free; } *


factor

original_code:
ht_t * factor(uint64_t n) {
    ht_t * f = ht_new();
    uint64_t i,p,pc;
    uint64_t small_primes[10] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29 };
    for (p=0;p<10;p++) {
        pc = 0;
        while (n%small_primes[p]==0) {
            n/=small_primes[p];
            pc++;
        }
        if (pc) add_factor(f,small_primes[p],pc);
    }
    uint64_t limit = isqrt(n);
    for ( i=31; i<=limit; i+=2) {
        pc = 0;
        while (n%i==0) {
            n/=i;
            pc++;
        }
        if (pc) add_factor(f,i,pc);
        limit = isqrt(n);
    }
    if (n>1) add_factor(f,n,1);
    return f;
}

canonical_original_code:
struct ht *factor(unsigned long n) {
    struct ht *f = ht_new();
    unsigned long i; unsigned long p; unsigned long pc;
    unsigned long small_primes[10] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29 };
    for (p=0;p<10;p++) {
        pc = 0;
        while (n%small_primes[p]==0) {
            n/=small_primes[p];
            pc++;
        }
        if (pc) add_factor(f,small_primes[p],pc);
    }
    unsigned long limit = isqrt(n);
    for ( i=31; i<=limit; i+=2) {
        pc = 0;
        while (n%i==0) {
            n/=i;
            pc++;
        }
        if (pc) add_factor(f,i,pc);
        limit = isqrt(n);
    }
    if (n>1) add_factor(f,n,1);
    return f;
}

variable_types:
n
unsigned long

variable_types:
i
unsigned long

variable_types:
p
unsigned long

variable_types:
pc
unsigned long

variable_types:
limit
unsigned long


lcm

original_code:
void lcm( ht_t * a, ht_t * b ) {
    int i;
    for (i=0;i<b->size;i++) if (b->table[i]) {
        min_factor(a,*(uint64_t *)b->table[i]->key,*(uint64_t *)b->table[i]->value);
    }
}

canonical_original_code:
void lcm(struct ht *a, struct ht *b) {
    int i;
    for (i=0;i<b->size;i++) if (b->table[i]) {
        min_factor(a,*(unsigned long *)b->table[i]->key,*(unsigned long *)b->table[i]->value);
    }
}

variable_types:
b
struct ht *


defactor

original_code:
uint64_t defactor(ht_t * f) {
    uint64_t d=1,i,j,n,m;
    for (i=0;i<f->size;i++) if (f->table[i]) {
        n = *(uint64_t *)f->table[i]->key;
        m = *(uint64_t *)f->table[i]->value;
        for (j=0;j<m;j++) d*=n;
    }
    return(d);
}

canonical_original_code:
unsigned long defactor(struct ht *f) {
    unsigned long d = 1; unsigned long i; unsigned long j; unsigned long n; unsigned long m;
    for (i=0;i<f->size;i++) if (f->table[i]) {
        n = *(unsigned long *)f->table[i]->key;
        m = *(unsigned long *)f->table[i]->value;
        for (j=0;j<m;j++) d*=n;
    }
    return(d);
}

variable_types:
d
unsigned long

variable_types:
j
unsigned long

variable_types:
m
unsigned long

return_type: unsigned long


divisors

decompiled_code:
__int64 __fastcall divisors(unsigned __int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
unsigned __int64 v4; // r13
__int64 v5; // rbp
unsigned __int64 v6; // rdx
unsigned __int64 v7; // rcx
__int64 v8; // r12
__int64 v9; // rdx
__int64 v10; // rdx
unsigned __int64 v12; // [rsp+8h] [rbp-40h] BYREF
char v13[8]; // [rsp+10h] [rbp-38h] BYREF
unsigned __int64 v14[6]; // [rsp+18h] [rbp-30h] BYREF

v4 = isqrt(a1, a2, a3, a4);
v5 = dar_new(8LL, 8LL);
v8 = dar_new(8LL, 8LL);
v14[0] = 1LL;
if ( v4 )
{
v7 = 1LL;
do
{
if ( !(a1 % v7) )
{
v12 = a1 / v7;
dar_push(v5, v14, a1 % v7);
if ( v12 != v14[0] )
dar_push(v8, &v12, v9);
}
v6 = v14[0] + 1;
v14[0] = v6;
v7 = v6;
}
while ( v6 <= v4 );
}
while ( (unsigned int)dar_pop(v8, v13, v6, v7) )
dar_push(v5, v13, v10);
dar_destroy(v8);
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned __int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
unsigned __int64 v4; // r13
__int64 v5; // rbp
unsigned __int64 v6; // rdx
unsigned __int64 v7; // rcx
__int64 v8; // r12
__int64 v9; // rdx
__int64 v10; // rdx
unsigned __int64 v12; // [rsp+8h] [rbp-40h] BYREF
char v13[8]; // [rsp+10h] [rbp-38h] BYREF
unsigned __int64 v14[6]; // [rsp+18h] [rbp-30h] BYREF

v4 = isqrt(a1, a2, a3, a4);
v5 = dar_new(8LL, 8LL);
v8 = dar_new(8LL, 8LL);
v14[0] = 1LL;
if ( v4 )
{
v7 = 1LL;
do
{
if ( !(a1 % v7) )
{
v12 = a1 / v7;
dar_push(v5, v14, a1 % v7);
if ( v12 != v14[0] )
dar_push(v8, &v12, v9);
}
v6 = v14[0] + 1;
v14[0] = v6;
v7 = v6;
}
while ( v6 <= v4 );
}
while ( (unsigned int)dar_pop(v8, v13, v6, v7) )
dar_push(v5, v13, v10);
dar_destroy(v8);
return v5;
}

original_code:
dar_t * divisors( uint64_t n ) {
    uint64_t sqrt = isqrt( n ) ;
    int64_t i;
    dar_t * r = dar_new(sizeof(uint64_t),8 );
    dar_t * rtop = dar_new(sizeof(uint64_t),8 );
    for ( i = 1; i<=sqrt; i++ ) {
        if ( n % i == 0 ) {
            uint64_t j = n / i;
            dar_push(r,&i);
            if (j!=i) dar_push(rtop,&j);
        }
    }
    uint64_t k;
    while ( dar_pop(rtop,&k) ) dar_push(r, &k );
    dar_destroy(rtop);
    return r;
}

canonical_original_code:
struct dar *divisors(unsigned long n) {
    unsigned long sqrt = isqrt( n );
    long i;
    struct dar *r = dar_new(sizeof(uint64_t),8 );
    struct dar *rtop = dar_new(sizeof(uint64_t),8 );
    for ( i = 1; i<=sqrt; i++ ) {
        if ( n % i == 0 ) {
            unsigned long j = n / i;
            dar_push(r,&i);
            if (j!=i) dar_push(rtop,&j);
        }
    }
    unsigned long k;
    while ( dar_pop(rtop,&k) ) dar_push(r, &k );
    dar_destroy(rtop);
    return r;
}

variable_types:
sqrt
unsigned long

variable_types: i long

variable_types: struct dar { void *data; int data_size; int element_count; int element_size; int element_free; } *

variable_types:
k
unsigned long


decompiled_code:
__int64 __fastcall proper_divisors(unsigned __int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 v4; // rbx
__int64 v5; // rdx
__int64 v6; // rcx

v4 = divisors(a1, a2, a3, a4);
dar_pop(v4, 0LL, v5, v6);
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned __int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 v4; // rbx
__int64 v5; // rdx
__int64 v6; // rcx

v4 = func4(a1, a2, a3, a4);
dar_pop(v4, 0LL, v5, v6);
return v4;
}

original_code:
dar_t * proper_divisors( uint64_t n ) {
    dar_t * r = divisors( n );
    (void)dar_pop( r, ((void *)0) );
    return r;
}

canonical_original_code:
struct dar *proper_divisors(unsigned long n) {
    struct dar *r = divisors( n );
    (void)dar_pop( r, ((void *)0) );
    return r;
}


isqrt

decompiled_code:
__int64 __fastcall isqrt(unsigned __int64 a1)
{
__int64 v1; // rax
unsigned __int64 v2; // r9
__int64 v3; // rsi
unsigned __int64 v4; // rdx

if ( a1 > 0xFFFFFFFF )
{
v1 = 32LL;
}
else
{
v1 = 32LL;
do
--v1;
while ( 1LL << v1 > a1 );
}
v2 = 0LL;
v3 = 0LL;
do
{
v4 = (1LL << (2 * (unsigned __int8)v1)) + v2 + (v3 << ((unsigned __int8)v1 + 1));
if ( a1 >= v4 )
{
v3 |= 1LL << v1;
v2 = v4;
}
--v1;
}
while ( v1 != -1 );
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int64 a1)
{
__int64 v1; // rax
unsigned __int64 v2; // r9
__int64 v3; // rsi
unsigned __int64 v4; // rdx

if ( a1 > 0xFFFFFFFF )
{
v1 = 32LL;
}
else
{
v1 = 32LL;
do
--v1;
while ( 1LL << v1 > a1 );
}
v2 = 0LL;
v3 = 0LL;
do
{
v4 = (1LL << (2 * (unsigned __int8)v1)) + v2 + (v3 << ((unsigned __int8)v1 + 1));
if ( a1 >= v4 )
{
v3 |= 1LL << v1;
v2 = v4;
}
--v1;
}
while ( v1 != -1 );
return v3;
}

original_code:
uint64_t isqrt( uint64_t n ) {
    uint64_t r = 0;
    uint64_t s = 0;
    uint64_t ns;
    uint64_t p;
    p = 32;
    while ( (1UL << p) > n ) p--;
    do {
        ns = s + ( r << ( p + 1 ) ) + ( 1UL << ( p + p ) );
        if ( ns <= n ) {
            s = ns;
            r |= 1UL << p;
        }
    } while (p--);
    return r;
}

canonical_original_code:
unsigned long isqrt(unsigned long n) {
    unsigned long r = 0;
    unsigned long s = 0;
    unsigned long ns;
    unsigned long p;
    p = 32;
    while ( (1UL << p) > n ) p--;
    do {
        ns = s + ( r << ( p + 1 ) ) + ( 1UL << ( p + p ) );
        if ( ns <= n ) {
            s = ns;
            r |= 1UL << p;
        }
    } while (p--);
    return r;
}

variable_types:
r
unsigned long

variable_types:
s
unsigned long

variable_types:
ns
unsigned long


decompiled_code:
__int64 __fastcall next_prime(_QWORD *a1, __int64 a2)
{
unsigned __int64 v2; // r12
unsigned __int64 v3; // rbx
unsigned __int64 v5[6]; // [rsp+8h] [rbp-30h] BYREF

if ( *a1 )
{
LABEL_3:
++*a1;
v2 = isqrt();
if ( *(_DWORD *)(a2 + 12) )
{
v3 = 0LL;
do
{
dar_fetch(a2, v5, (unsigned int)v3);
if ( v5[0] > v2 )
break;
if ( !(*a1 % v5[0]) )
goto LABEL_3;
++v3;
}
while ( *(int *)(a2 + 12) > v3 );
}
}
else
{
*a1 = 2LL;
}
return dar_push(a2, a1);
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1, __int64 a2)
{
unsigned __int64 v2; // r12
unsigned __int64 v3; // rbx
unsigned __int64 v5[6]; // [rsp+8h] [rbp-30h] BYREF

if ( *a1 )
{
LABEL_3:
++*a1;
v2 = isqrt();
if ( *(_DWORD *)(a2 + 12) )
{
v3 = 0LL;
do
{
dar_fetch(a2, v5, (unsigned int)v3);
if ( v5[0] > v2 )
break;
if ( !(*a1 % v5[0]) )
goto LABEL_3;
++v3;
}
while ( *(int *)(a2 + 12) > v3 );
}
}
else
{
*a1 = 2LL;
}
return dar_push(a2, a1);
}

original_code:
void next_prime(uint64_t *n,dar_t *primes) {
    if (*n==0) {
        *n=2;
    } else {
        int is_prime;
        uint64_t i , p;
        do {
            (*n)++;
            is_prime = 1;
            uint64_t nsqr = isqrt(*n);
            for ( i=0; i < primes->element_count; i++) {
                (void)dar_fetch(primes,&p,i);
                if ( p > nsqr ) break;
                if ( ( *n % p ) == 0 ) {
                    is_prime = 0;
                    break;
                }
            }
        } while ( ! is_prime );
    }
    dar_push(primes,n);
}

canonical_original_code:
void next_prime(unsigned long *n, struct dar *primes) {
    if (*n==0) {
        *n=2;
    } else {
        int is_prime;
        unsigned long i; unsigned long p;
        do {
            (*n)++;
            is_prime = 1;
            unsigned long nsqr = isqrt(*n);
            for ( i=0; i < primes->element_count; i++) {
                (void)dar_fetch(primes,&p,i);
                if ( p > nsqr ) break;
                if ( ( *n % p ) == 0 ) {
                    is_prime = 0;
                    break;
                }
            }
        } while ( ! is_prime );
    }
    dar_push(primes,n);
}

variable_types:
n
unsigned long *

variable_types:
nsqr
unsigned long


split

decompiled_code:
__int64 __fastcall split(void *s, int a2, char a3, __int64 (__fastcall *a4)(__int64, void *, signed __int64), __int64 a5)
{
int v6; // er12
int v9; // er13
char *v10; // rax
char *v11; // rbx
__int64 result; // rax
void *v13; // rbx

if ( a2 <= 0 )
return 0LL;
v6 = a2;
v9 = a3;
while ( 1 )
{
v10 = (char *)memchr(s, v9, v6);
v11 = (char *)s + v6;
if ( v10 )
v11 = v10;
result = a4(a5, s, v11 - (_BYTE *)s);
if ( (_DWORD)result )
break;
v13 = v11 + 1;
v6 -= (_DWORD)v13 - (_DWORD)s;
if ( v6 <= 0 )
break;
s = v13;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(void *s, int a2, char a3, __int64 (__fastcall *a4)(__int64, void *, signed __int64), __int64 a5)
{
int v6; // er12
int v9; // er13
char *v10; // rax
char *v11; // rbx
__int64 result; // rax
void *v13; // rbx

if ( a2 <= 0 )
return 0LL;
v6 = a2;
v9 = a3;
while ( 1 )
{
v10 = (char *)memchr(s, v9, v6);
v11 = (char *)s + v6;
if ( v10 )
v11 = v10;
result = a4(a5, s, v11 - (_BYTE *)s);
if ( (_DWORD)result )
break;
v13 = v11 + 1;
v6 -= (_DWORD)v13 - (_DWORD)s;
if ( v6 <= 0 )
break;
s = v13;
}
return result;
}

original_code:
int split(char * string, int length, char seperator, int(*callback)(void *,char *, int), void * context ) {
    char * s = string;
    int l = length;
    char * m;
    int r;
    while (l>0) {
        if ( ! ( m = memchr(s,seperator,l) ) ) m = s+l;
        if ( ( r = callback(context,s,m-s) ) ) return r;
        l -= 1 + m - s;
        s = m + 1;
    }
    return 0;
}

canonical_original_code:
int split(char *string, int length, char seperator, int (*callback)(void *, char *, int), void *context) {
    char *s = string;
    int l = length;
    char *m;
    int r;
    while (l>0) {
        if ( ! ( m = memchr(s,seperator,l) ) ) m = s+l;
        if ( ( r = callback(context,s,m-s) ) ) return r;
        l -= 1 + m - s;
        s = m + 1;
    }
    return 0;
}

variable_types:
string
char *

variable_types: length int

variable_types: seperator char

variable_types:
callback
int (*)(void *, char *, int)

variable_types:
context
void *

variable_types:
s
char *

variable_types: l int

variable_types:
m
char *

variable_types: r int


decompiled_code:
__int64 __fastcall fnv_32_buf(unsigned __int8 *a1, __int64 a2, unsigned int a3)
{
__int64 result; // rax
unsigned __int8 *v4; // rsi

result = a3;
v4 = &a1[a2];
if ( a1 < v4 )
{
do
result = *a1++ ^ (unsigned int)(16777619 * result);
while ( v4 != a1 );
}
return result;
}

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

result = a3;
v4 = &a1[a2];
if ( a1 < v4 )
{
do
result = *a1++ ^ (unsigned int)(16777619 * result);
while ( v4 != a1 );
}
return result;
}

original_code:
uint32_t fnv_32_buf(void *buf, size_t len, uint32_t hval)
{
    unsigned char *bp = (unsigned char *)buf;
    unsigned char *be = bp + len;
    while (bp < be) {
 hval += (hval<<1) + (hval<<4) + (hval<<7) + (hval<<8) + (hval<<24);
 hval ^= (uint32_t)*bp++;
    }
    return hval;
}

canonical_original_code:
unsigned int fnv_32_buf(void *buf, unsigned long len, unsigned int hval)
{
    unsigned char *bp = (unsigned char *)buf;
    unsigned char *be = bp + len;
    while (bp < be) {
 hval += (hval<<1) + (hval<<4) + (hval<<7) + (hval<<8) + (hval<<24);
 hval ^= (unsigned int)*bp++;
    }
    return hval;
}

variable_types:
buf
void *

variable_types:
len
unsigned long

variable_types:
hval
unsigned int

variable_types:
bp
unsigned char *

variable_types:
be
unsigned char *


decompiled_code:
__int64 __fastcall realloc_buffer(__int64 a1, unsigned int a2)
{
void *v3; // rdi
void *v4; // rax

v3 = *(void **)(a1 + 24);
if ( v3 )
v4 = realloc(v3, a2);
else
v4 = malloc(a2);
if ( !v4 )
return 0xFFFFFFFFLL;
*(_DWORD *)(a1 + 16) = a2;
*(_QWORD *)(a1 + 24) = v4;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned int a2)
{
void *v3; // rdi
void *v4; // rax

v3 = *(void **)(a1 + 24);
if ( v3 )
v4 = realloc(v3, a2);
else
v4 = malloc(a2);
if ( !v4 )
return 0xFFFFFFFFLL;
*(_DWORD *)(a1 + 16) = a2;
*(_QWORD *)(a1 + 24) = v4;
return 0LL;
}

original_code:
static int realloc_buffer( dssl_decoder* d, uint32_t new_len )
{
 u_char* new_buff = ((void *)0);
 ((void)0);
 ((void)0);
 if( d->buff != ((void *)0) )
  new_buff = (u_char*) realloc( d->buff, new_len );
 else
  new_buff = (u_char*) malloc( new_len );
 if( new_buff == ((void *)0) ) return ((-1));
 d->buff_len = new_len;
 d->buff = new_buff;
 return 0;
}

canonical_original_code:
static int realloc_buffer(struct dssl_decoder_ *d, unsigned int new_len)
{
 unsigned char *new_buff = ((void *)0);
 ((void)0);
 ((void)0);
 if( d->buff != ((void *)0) )
  new_buff = (unsigned char *) realloc( d->buff, new_len );
 else
  new_buff = (unsigned char *) malloc( new_len );
 if( new_buff == ((void *)0) ) return ((-1));
 d->buff_len = new_len;
 d->buff = new_buff;
 return 0;
}

variable_types: struct dssl_decoder_ { void *handler_data; int (*handler)(void *state, enum NM_PacketDir_ { ePacketDirInvalid=0, ePacketDirFromClient=1, ePacketDirFromServer=2 } dir, unsigned char *data, unsigned int len, unsigned int *processed); unsigned int buff_len; unsigned int buff_used_len; unsigned char *buff; } *

user_defined_types: struct dssl_decoder_ { void *handler_data; int (*handler)(void *state, enum NM_PacketDir_ dir, unsigned char *data, unsigned int len, unsigned int *processed); unsigned int buff_len; unsigned int buff_used_len; unsigned char *buff; }


original_code:
void dssl_decoder_deinit( dssl_decoder* d )
{
 ((void)0);
 if( d->buff ) free( d->buff );
 d->buff = ((void *)0);
 d->buff_len = 0;
 d->buff_used_len = 0;
}

canonical_original_code:
void dssl_decoder_deinit(struct dssl_decoder_ *d)
{
 ((void)0);
 if( d->buff ) free( d->buff );
 d->buff = ((void *)0);
 d->buff_len = 0;
 d->buff_used_len = 0;
}

user_defined_types: enum NM_PacketDir_ { ePacketDirInvalid=0, ePacketDirFromClient=1, ePacketDirFromServer=2 }


decompiled_code:
__int64 __fastcall dssl_decoder_add_to_buffer(__int64 a1, const void *a2, unsigned int a3)
{
unsigned int v5; // esi
__int64 result; // rax

v5 = *(_DWORD *)(a1 + 20) + a3;
if ( *(_DWORD *)(a1 + 16) >= v5 || (result = realloc_buffer(a1, v5), !(_DWORD)result) )
{
memcpy((void *)(*(_QWORD *)(a1 + 24) + *(unsigned int *)(a1 + 20)), a2, a3);
*(_DWORD *)(a1 + 20) += a3;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, const void *a2, unsigned int a3)
{
unsigned int v5; // esi
__int64 result; // rax

v5 = *(_DWORD *)(a1 + 20) + a3;
if ( *(_DWORD *)(a1 + 16) >= v5 || (result = func0(a1, v5), !(_DWORD)result) )
{
memcpy((void *)(*(_QWORD *)(a1 + 24) + *(unsigned int *)(a1 + 20)), a2, a3);
*(_DWORD *)(a1 + 20) += a3;
result = 0LL;
}
return result;
}

original_code:
int dssl_decoder_add_to_buffer( dssl_decoder* d, u_char* data, uint32_t len )
{
 int rc = 0;
 if( d->buff_len < d->buff_used_len + len )
 {
  rc = realloc_buffer( d, d->buff_used_len + len );
 }
 if( rc == 0 )
 {
  ((void)0);
  memcpy( d->buff + d->buff_used_len, data, len );
  d->buff_used_len += len;
 }
 return rc;
}

canonical_original_code:
int dssl_decoder_add_to_buffer(struct dssl_decoder_ *d, unsigned char *data, unsigned int len)
{
 int rc = 0;
 if( d->buff_len < d->buff_used_len + len )
 {
  rc = realloc_buffer( d, d->buff_used_len + len );
 }
 if( rc == 0 )
 {
  ((void)0);
  memcpy( d->buff + d->buff_used_len, data, len );
  d->buff_used_len += len;
 }
 return rc;
}

variable_types:
data
unsigned char *

variable_types:
len
unsigned int

variable_types: rc int


decompiled_code:
__int64 __fastcall dssl_decoder_shift_buffer(__int64 a1, unsigned int a2)
{
unsigned int v2; // edx

v2 = *(_DWORD *)(a1 + 20);
if ( v2 > a2 )
memmove(*(void **)(a1 + 24), (const void *)(*(_QWORD *)(a1 + 24) + a2), v2 - a2);
*(_DWORD *)(a1 + 20) -= a2;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, unsigned int a2)
{
unsigned int v2; // edx

v2 = *(_DWORD *)(a1 + 20);
if ( v2 > a2 )
memmove(*(void **)(a1 + 24), (const void *)(*(_QWORD *)(a1 + 24) + a2), v2 - a2);
*(_DWORD *)(a1 + 20) -= a2;
return 0LL;
}

original_code:
int dssl_decoder_shift_buffer( dssl_decoder* d, uint32_t processed_len )
{
 ((void)0);
 ((void)0);
 if( d->buff_used_len > processed_len )
 {
  memmove( d->buff, d->buff + processed_len, d->buff_used_len - processed_len );
 }
 d->buff_used_len -= processed_len;
 return 0;
}

canonical_original_code:
int dssl_decoder_shift_buffer(struct dssl_decoder_ *d, unsigned int processed_len)
{
 ((void)0);
 ((void)0);
 if( d->buff_used_len > processed_len )
 {
  memmove( d->buff, d->buff + processed_len, d->buff_used_len - processed_len );
 }
 d->buff_used_len -= processed_len;
 return 0;
}


decompiled_code:
__int64 __fastcall dssl_decoder_process(__int64 a1, unsigned int a2, char *a3, unsigned int a4)
{
char *v4; // r13
unsigned int v5; // er12
unsigned int v6; // ebx
__int64 result; // rax
int v8[11]; // [rsp+0h] [rbp-2Ch] BYREF

if ( !*(_QWORD *)(a1 + 8) )
return 4294967286LL;
v4 = a3;
v5 = a4;
if ( *(_DWORD *)(a1 + 20) )
{
result = dssl_decoder_add_to_buffer(a1, a3, a4);
if ( (_DWORD)result )
{
v6 = 0;
goto LABEL_7;
}
v4 = *(char **)(a1 + 24);
v5 = *(_DWORD *)(a1 + 20);
}
if ( v5 )
{
v6 = 0;
do
{
v8[0] = 0;
result = (*(__int64 (__fastcall **)(_QWORD, _QWORD, char *, _QWORD, int *))(a1 + 8))(
*(_QWORD *)a1,
a2,
&v4[v6],
v5 - v6,
v8);
v6 += v8[0];
}
while ( !(_DWORD)result && v6 < v5 );
LABEL_7:
if ( (int)result < 0 )
return result;
goto LABEL_8;
}
v6 = 0;
result = 0LL;
LABEL_8:
if ( *(_DWORD *)(a1 + 20) )
return dssl_decoder_shift_buffer(a1, v6);
if ( v6 < v5 )
result = dssl_decoder_add_to_buffer(a1, &v4[v6], v5 - v6);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, unsigned int a2, char *a3, unsigned int a4)
{
char *v4; // r13
unsigned int v5; // er12
unsigned int v6; // ebx
__int64 result; // rax
int v8[11]; // [rsp+0h] [rbp-2Ch] BYREF

if ( !*(_QWORD *)(a1 + 8) )
return 4294967286LL;
v4 = a3;
v5 = a4;
if ( *(_DWORD *)(a1 + 20) )
{
result = func3(a1, a3, a4);
if ( (_DWORD)result )
{
v6 = 0;
goto LABEL_7;
}
v4 = *(char **)(a1 + 24);
v5 = *(_DWORD *)(a1 + 20);
}
if ( v5 )
{
v6 = 0;
do
{
v8[0] = 0;
result = (*(__int64 (__fastcall **)(_QWORD, _QWORD, char *, _QWORD, int *))(a1 + 8))(
*(_QWORD *)a1,
a2,
&v4[v6],
v5 - v6,
v8);
v6 += v8[0];
}
while ( !(_DWORD)result && v6 < v5 );
LABEL_7:
if ( (int)result < 0 )
return result;
goto LABEL_8;
}
v6 = 0;
result = 0LL;
LABEL_8:
if ( *(_DWORD *)(a1 + 20) )
return func4(a1, v6);
if ( v6 < v5 )
result = func3(a1, &v4[v6], v5 - v6);
return result;
}

original_code:
int dssl_decoder_process( dssl_decoder* d, NM_PacketDir dir, u_char* data, uint32_t len )
{
 uint32_t processed = 0;
 int rc = 0;
 if( !d->handler ) return ((-10));
 if( d->buff_used_len > 0 )
 {
  rc = dssl_decoder_add_to_buffer( d, data, len );
  if( rc == 0 )
  {
   data = d->buff;
   len = d->buff_used_len;
  }
 }
 while( rc == 0 && processed < len )
 {
  uint32_t p = 0;
  rc = d->handler( d->handler_data, dir, data + processed, len - processed, &p );
  processed += p;
 }
 if( !((rc) < 0) )
 {
  if( d->buff_used_len > 0 )
  {
   rc = dssl_decoder_shift_buffer( d, processed );
  }
  else if( processed < len )
  {
   rc = dssl_decoder_add_to_buffer( d, data + processed, len - processed );
  }
 }
 return rc;
}

canonical_original_code:
int dssl_decoder_process(struct dssl_decoder_ *d, enum NM_PacketDir_ dir, unsigned char *data, unsigned int len)
{
 unsigned int processed = 0;
 int rc = 0;
 if( !d->handler ) return ((-10));
 if( d->buff_used_len > 0 )
 {
  rc = dssl_decoder_add_to_buffer( d, data, len );
  if( rc == 0 )
  {
   data = d->buff;
   len = d->buff_used_len;
  }
 }
 while( rc == 0 && processed < len )
 {
  unsigned int p = 0;
  rc = d->handler( d->handler_data, dir, data + processed, len - processed, &p );
  processed += p;
 }
 if( !((rc) < 0) )
 {
  if( d->buff_used_len > 0 )
  {
   rc = dssl_decoder_shift_buffer( d, processed );
  }
  else if( processed < len )
  {
   rc = dssl_decoder_add_to_buffer( d, data + processed, len - processed );
  }
 }
 return rc;
}

variable_types: enum NM_PacketDir_ { ePacketDirInvalid=0, ePacketDirFromClient=1, ePacketDirFromServer=2 }

variable_types:
processed
unsigned int

variable_types:
p
unsigned int


nmLogMessage

decompiled_code:
void nmLogMessage()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
void nmLogMessage( uint32_t category, const char* fmt, ... )
{
}

canonical_original_code:
void nmLogMessage(unsigned int category, char *fmt, ...)
{
}

variable_types:
category
unsigned int

variable_types:
fmt
char *


decompiled_code:
__int64 __fastcall compare_cipher_suites(const void *a1, const void *a2)
{
return *(unsigned __int16 *)a1 - (unsigned int)*(unsigned __int16 *)a2;
}

canonical_decompiled_code:
__int64 __fastcall func0(const void *a1, const void *a2)
{
return *(unsigned __int16 *)a1 - (unsigned int)*(unsigned __int16 *)a2;
}

original_code:
static int compare_cipher_suites( const void* key, const void* elem )
{
 uint16_t id = *((uint16_t*)key);
 DSSL_CipherSuite* cs = (DSSL_CipherSuite*) elem;
 return id - cs->id;
}

canonical_original_code:
static int compare_cipher_suites(void *key, void *elem)
{
 unsigned short id = *((uint16_t*)key);
 struct _DSSL_CipherSuite *cs = (DSSL_CipherSuite*) elem;
 return id - cs->id;
}

variable_types:
key
void *

variable_types:
elem
void *

variable_types:
id
unsigned short

variable_types: struct _DSSL_CipherSuite { unsigned short id; unsigned short ssl_version; unsigned short key_ex; int export_key_bits; char *enc; char *digest; } *


decompiled_code:
void *__fastcall DSSL_GetCipherSuite(__int16 a1)
{
__int16 key[6]; // [rsp+Ch] [rbp-Ch] BYREF

key[0] = a1;
return bsearch(key, &suites, 0xCuLL, 0x20uLL, (__compar_fn_t)compare_cipher_suites);
}

canonical_decompiled_code:
void *__fastcall func1(__int16 a1)
{
__int16 key[6]; // [rsp+Ch] [rbp-Ch] BYREF

key[0] = a1;
return bsearch(key, &suites, 0xCuLL, 0x20uLL, (__compar_fn_t)compare_cipher_suites);
}

original_code:
DSSL_CipherSuite* DSSL_GetCipherSuite( uint16_t id )
{
 return (DSSL_CipherSuite*) bsearch( &id, suites,
   sizeof(suites)/sizeof(suites[0]), sizeof(suites[0]),
   compare_cipher_suites );
}

canonical_original_code:
struct _DSSL_CipherSuite *DSSL_GetCipherSuite(unsigned short id)
{
 return (struct _DSSL_CipherSuite *) bsearch( &id, suites,
   sizeof(suites)/sizeof(suites[0]), sizeof(suites[0]),
   compare_cipher_suites );
}

return_type: struct _DSSL_CipherSuite { unsigned short id; unsigned short ssl_version; unsigned short key_ex; int export_key_bits; char *enc; char *digest; } *


decompiled_code:
_BOOL8 __fastcall DSSL_CipherSuiteExportable(__int64 a1)
{
return *(_DWORD *)(a1 + 8) != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(__int64 a1)
{
return *(_DWORD *)(a1 + 8) != 0;
}

original_code:
int DSSL_CipherSuiteExportable( DSSL_CipherSuite* ss )
{
 return ss->export_key_bits != 0;
}

canonical_original_code:
int DSSL_CipherSuiteExportable(struct _DSSL_CipherSuite *ss)
{
 return ss->export_key_bits != 0;
}

user_defined_types: struct _DSSL_CipherSuite { unsigned short id; unsigned short ssl_version; unsigned short key_ex; int export_key_bits; char *enc; char *digest; }


getTcpSessionHash

decompiled_code:
__int64 __fastcall getTcpSessionHash(unsigned int a1, __int16 a2, unsigned int a3, __int16 a4)
{
unsigned int v4; // eax
unsigned int v5; // eax
unsigned int v6; // eax
__int64 result; // rax
unsigned int v8; // eax
unsigned int v9; // eax
unsigned int v10; // eax
__int16 v11[2]; // [rsp+0h] [rbp-18h] BYREF
unsigned int v12; // [rsp+4h] [rbp-14h] BYREF
__int16 v13[2]; // [rsp+8h] [rbp-10h] BYREF
int v14[3]; // [rsp+Ch] [rbp-Ch] BYREF

v14[0] = a1;
v12 = a3;
v13[0] = a2;
v11[0] = a4;
if ( a1 >= a3 )
{
v8 = fnv_32_buf(&v12, 4LL, 2166136261LL);
v9 = fnv_32_buf(v11, 2LL, v8);
v10 = fnv_32_buf(v14, 4LL, v9);
result = fnv_32_buf(v13, 2LL, v10);
}
else
{
v4 = fnv_32_buf(v14, 4LL, 2166136261LL);
v5 = fnv_32_buf(v13, 2LL, v4);
v6 = fnv_32_buf(&v12, 4LL, v5);
result = fnv_32_buf(v11, 2LL, v6);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1, __int16 a2, unsigned int a3, __int16 a4)
{
unsigned int v4; // eax
unsigned int v5; // eax
unsigned int v6; // eax
__int64 result; // rax
unsigned int v8; // eax
unsigned int v9; // eax
unsigned int v10; // eax
__int16 v11[2]; // [rsp+0h] [rbp-18h] BYREF
unsigned int v12; // [rsp+4h] [rbp-14h] BYREF
__int16 v13[2]; // [rsp+8h] [rbp-10h] BYREF
int v14[3]; // [rsp+Ch] [rbp-Ch] BYREF

v14[0] = a1;
v12 = a3;
v13[0] = a2;
v11[0] = a4;
if ( a1 >= a3 )
{
v8 = fnv_32_buf(&v12, 4LL, 2166136261LL);
v9 = fnv_32_buf(v11, 2LL, v8);
v10 = fnv_32_buf(v14, 4LL, v9);
result = fnv_32_buf(v13, 2LL, v10);
}
else
{
v4 = fnv_32_buf(v14, 4LL, 2166136261LL);
v5 = fnv_32_buf(v13, 2LL, v4);
v6 = fnv_32_buf(&v12, 4LL, v5);
result = fnv_32_buf(v11, 2LL, v6);
}
return result;
}

original_code:
static uint32_t getTcpSessionHash( uint32_t ip1, uint16_t port1, uint32_t ip2, uint16_t port2 )
{
 uint32_t hash;
 if( ip1 < ip2 )
 {
  hash = fnv_32_buf( &ip1, sizeof(ip1), ((uint32_t)0x811c9dc5) );
  hash = fnv_32_buf( &port1, sizeof(port1), hash );
  hash = fnv_32_buf( &ip2, sizeof(ip2), hash );
  hash = fnv_32_buf( &port2, sizeof(port2), hash );
 }
 else
 {
  hash = fnv_32_buf( &ip2, sizeof(ip2), ((uint32_t)0x811c9dc5) );
  hash = fnv_32_buf( &port2, sizeof(port2), hash );
  hash = fnv_32_buf( &ip1, sizeof(ip1), hash );
  hash = fnv_32_buf( &port1, sizeof(port1), hash );
 }
 return hash;
}

canonical_original_code:
static unsigned int getTcpSessionHash(unsigned int ip1, unsigned short port1, unsigned int ip2, unsigned short port2)
{
 unsigned int hash;
 if( ip1 < ip2 )
 {
  hash = fnv_32_buf( &ip1, sizeof(ip1), ((unsigned int)0x811c9dc5) );
  hash = fnv_32_buf( &port1, sizeof(port1), hash );
  hash = fnv_32_buf( &ip2, sizeof(ip2), hash );
  hash = fnv_32_buf( &port2, sizeof(port2), hash );
 }
 else
 {
  hash = fnv_32_buf( &ip2, sizeof(ip2), ((unsigned int)0x811c9dc5) );
  hash = fnv_32_buf( &port2, sizeof(port2), hash );
  hash = fnv_32_buf( &ip1, sizeof(ip1), hash );
  hash = fnv_32_buf( &port1, sizeof(port1), hash );
 }
 return hash;
}

variable_types:
hash
unsigned int


ICntInit

repo: gandrewstone/itl

original_code:
void ICntInit(ICnt* ths,int* parentOffsets, int* childOffsets,int markOffset)
{
  ths->objId = ICNT_ID;
  ths->first = 0;
  ths->size = 0;
  ths->flags = 0;
  ths->cookie = 0;
  ths->parentOffsets = parentOffsets;
  ths->childOffsets = childOffsets;
  ths->markOffset = markOffset;
}

canonical_original_code:
void ICntInit(struct ICnt *ths, int *parentOffsets, int *childOffsets, int markOffset)
{
  ths->objId = ICNT_ID;
  ths->first = 0;
  ths->size = 0;
  ths->flags = 0;
  ths->cookie = 0;
  ths->parentOffsets = parentOffsets;
  ths->childOffsets = childOffsets;
  ths->markOffset = markOffset;
}

variable_types: struct ICnt { int objId; char *first; int *parentOffsets; int *childOffsets; int markOffset; int size; int flags; char *cookie; } *

variable_types:
parentOffsets
int *

variable_types:
childOffsets
int *

variable_types: markOffset int


DilistInsert

original_code:
void DilistInsert(ICnt* ths, char* elem, char* parent)
{
  if (parent == 0)
    {
      ((void) sizeof ((ths->first == 0) ? 1 : 0), __extension__ ({ if (ths->first == 0) ; else __assert_fail ("ths->first == 0", "IPmt.c", 50, __extension__ __PRETTY_FUNCTION__); }));
      ths->first = elem;
      *((char**) (elem + (ths->childOffsets[Next]))) = elem;
      *((char**) (elem + (ths->parentOffsets[Prev]))) = elem;
    }
  else
    {
      char* child = *((char**) (parent + (ths->childOffsets[Next])));
      *((char**) (parent + (ths->childOffsets[Next]))) = elem;
      *((char**) (elem + (ths->parentOffsets[Prev]))) = parent;
      *((char**) (child + (ths->parentOffsets[Prev]))) = elem;
      *((char**) (elem + (ths->childOffsets[Next]))) = child;
    }
}

canonical_original_code:
void DilistInsert(struct ICnt *ths, char *elem, char *parent)
{
  if (parent == 0)
    {
      ((void) sizeof ((ths->first == 0) ? 1 : 0), __extension__ ({ if (ths->first == 0) ; else __assert_fail ("ths->first == 0", "IPmt.c", 50, __extension__ __PRETTY_FUNCTION__); }));
      ths->first = elem;
      *((char **) (elem + (ths->childOffsets[Next]))) = elem;
      *((char **) (elem + (ths->parentOffsets[Prev]))) = elem;
    }
  else
    {
      char *child = *((char**) (parent + (ths->childOffsets[Next])));
      *((char **) (parent + (ths->childOffsets[Next]))) = elem;
      *((char **) (elem + (ths->parentOffsets[Prev]))) = parent;
      *((char **) (child + (ths->parentOffsets[Prev]))) = elem;
      *((char **) (elem + (ths->childOffsets[Next]))) = child;
    }
}

variable_types:
elem
char *

variable_types:
parent
char *

variable_types:
child
char *

user_defined_types: struct ICnt { int objId; char *first; int *parentOffsets; int *childOffsets; int markOffset; int size; int flags; char *cookie; }


DilistRemove

original_code:
char* DilistRemove(ICnt* ths, char* elem)
{
  if (elem == 0) return elem;
  char* p = *((char**) (elem + (ths->parentOffsets[Prev])));
  char* n = *((char**) (elem + (ths->childOffsets[Next])));
  *((char**) (p + (ths->childOffsets[Next]))) = n;
  *((char**) (n + (ths->parentOffsets[Prev]))) = p;
  *((char**) (elem + (ths->childOffsets[Next]))) = 0;
  *((char**) (elem + (ths->parentOffsets[Prev]))) = 0;
  if (ths->first == elem)
    {
      if (n==elem) ths->first = 0;
      else ths->first = n;
    }
  return elem;
}

canonical_original_code:
char *DilistRemove(struct ICnt *ths, char *elem)
{
  if (elem == 0) return elem;
  char *p = *((char**) (elem + (ths->parentOffsets[Prev])));
  char *n = *((char**) (elem + (ths->childOffsets[Next])));
  *((char **) (p + (ths->childOffsets[Next]))) = n;
  *((char **) (n + (ths->parentOffsets[Prev]))) = p;
  *((char **) (elem + (ths->childOffsets[Next]))) = 0;
  *((char **) (elem + (ths->parentOffsets[Prev]))) = 0;
  if (ths->first == elem)
    {
      if (n==elem) ths->first = 0;
      else ths->first = n;
    }
  return elem;
}

variable_types:
p
char *

variable_types:
n
char *

return_type: char *


DilistPop

decompiled_code:
__int64 __fastcall DilistPop(__int64 a1)
{
return DilistRemove(a1, *(_QWORD *)(a1 + 8));
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
return func8(a1, *(_QWORD *)(a1 + 8));
}

original_code:
char* DilistPop(ICnt* ths)
{
  return DilistRemove(ths,ths->first);
}

canonical_original_code:
char *DilistPop(struct ICnt *ths)
{
  return DilistRemove(ths,ths->first);
}


DilistAppend

decompiled_code:
__int64 __fastcall DilistAppend(__int64 a1, __int64 a2)
{
__int64 v2; // rax
__int64 result; // rax

v2 = *(_QWORD *)(a1 + 8);
if ( v2 )
result = DilistInsert(a1, a2, *(_QWORD *)(v2 + **(int **)(a1 + 16)));
else
result = DilistInsert(a1, a2, 0LL);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, __int64 a2)
{
__int64 v2; // rax
__int64 result; // rax

v2 = *(_QWORD *)(a1 + 8);
if ( v2 )
result = func7(a1, a2, *(_QWORD *)(v2 + **(int **)(a1 + 16)));
else
result = func7(a1, a2, 0LL);
return result;
}

original_code:
void DilistAppend(ICnt* ths, char* elem)
{
  if (ths->first == 0) DilistInsert(ths, elem, 0);
  else DilistInsert(ths, elem, *((char**) (ths->first + (ths->parentOffsets[Prev]))));
}

canonical_original_code:
void DilistAppend(struct ICnt *ths, char *elem)
{
  if (ths->first == 0) DilistInsert(ths, elem, 0);
  else DilistInsert(ths, elem, *((char **) (ths->first + (ths->parentOffsets[Prev]))));
}


DilistPrepend

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

result = DilistAppend();
*(_QWORD *)(a1 + 8) = a2;
return result;
}

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

result = func10();
*(_QWORD *)(a1 + 8) = a2;
return result;
}

original_code:
void DilistPrepend(ICnt* ths, char* elem)
{
  DilistAppend(ths, elem);
  ths->first = elem;
}

canonical_original_code:
void DilistPrepend(struct ICnt *ths, char *elem)
{
  DilistAppend(ths, elem);
  ths->first = elem;
}


DilistPush

decompiled_code:
__int64 DilistPush()
{
return DilistPrepend();
}

canonical_decompiled_code:
__int64 func12()
{
return func11();
}

original_code:
void DilistPush(ICnt* ths, char* elem)
{
  return DilistPrepend(ths,elem);
}

canonical_original_code:
void DilistPush(struct ICnt *ths, char *elem)
{
  return DilistPrepend(ths,elem);
}


ReleaseWrapper

decompiled_code:
__int64 __fastcall ReleaseWrapper(__int64 a1, _QWORD *a2)
{
*a2 = 0LL;
a2[1] = 0LL;
return SlistHeapFree();
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1, _QWORD *a2)
{
*a2 = 0LL;
a2[1] = 0LL;
return SlistHeapFree();
}

original_code:
static void ReleaseWrapper(DlistHeadT* ths,DlistT* w)
{
  w->prev = 0;
  w->next = 0;
  w->data = 0;
  DlistHeapFree(ths,w);
}

canonical_original_code:
static void ReleaseWrapper(struct ICnt *ths, struct DlistT *w)
{
  w->prev = 0;
  w->next = 0;
  w->data = 0;
  DlistHeapFree(ths,w);
}

variable_types: struct DlistT { struct DlistT *next; struct DlistT *prev; char *data; } *


DlistInit

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

result = ICntInit(a1, &parentOffsets, &childOffsets, 0xFFFFFFFFLL);
*(_DWORD *)(a1 + 40) |= 1u;
return result;
}

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

result = func6(a1, &parentOffsets, &childOffsets, 0xFFFFFFFFLL);
*(_DWORD *)(a1 + 40) |= 1u;
return result;
}

original_code:
void DlistInit(DlistHeadT* ths)
{
  ICntInit(ths,parentOffsets,childOffsets,INVALID_OFFSET);
  ths->flags |= ALIVE;
}

canonical_original_code:
void DlistInit(struct ICnt *ths)
{
  ICntInit(ths,parentOffsets,childOffsets,INVALID_OFFSET);
  ths->flags |= ALIVE;
}


DlistCreate

decompiled_code:
__int64 DlistCreate()
{
__int64 v0; // rbx

v0 = DlistHeapAllocate();
DlistInit(v0, 56LL);
*(_DWORD *)(v0 + 40) |= 2u;
return v0;
}

canonical_decompiled_code:
__int64 func26()
{
__int64 v0; // rbx

v0 = DlistHeapAllocate();
func25(v0, 56LL);
*(_DWORD *)(v0 + 40) |= 2u;
return v0;
}

original_code:
DlistHeadT* DlistCreate()
{
    DlistHeadT* ths = (DlistHeadT*) DlistHeapAllocate(((void *)0),sizeof(DlistHeadT));
  DlistInit(ths);
  ths->flags |= ALLOCED;
  return ths;
}

canonical_original_code:
struct ICnt *DlistCreate()
{
    struct ICnt *ths = (DlistHeadT*) DlistHeapAllocate(((void *)0),sizeof(DlistHeadT));
  DlistInit(ths);
  ths->flags |= ALLOCED;
  return ths;
}

return_type: struct ICnt { int objId; char *first; int *parentOffsets; int *childOffsets; int markOffset; int size; int flags; char *cookie; } *


DlistFinalize

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

ASSERT();
result = *(unsigned int *)(a1 + 40);
*(_DWORD *)(a1 + 40) = 0;
if ( (result & 2) != 0 )
result = DlistHeapFree();
return result;
}

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

ASSERT();
result = *(unsigned int *)(a1 + 40);
*(_DWORD *)(a1 + 40) = 0;
if ( (result & 2) != 0 )
result = DlistHeapFree();
return result;
}

original_code:
void DlistFinalize(DlistHeadT* ths)
{
  ASSERT(ths && (ths->objId == ICNT_ID) && (ths->flags & ALIVE));
  int flags = ths->flags;
  ths->flags = 0;
  if (flags&ALLOCED) DlistHeapFree(((void *)0),ths);
}

canonical_original_code:
void DlistFinalize(struct ICnt *ths)
{
  ASSERT(ths && (ths->objId == ICNT_ID) && (ths->flags & ALIVE));
  int flags = ths->flags;
  ths->flags = 0;
  if (flags&ALLOCED) DlistHeapFree(((void *)0),ths);
}

variable_types: flags int


DlistPrepend

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

v2 = MakeWrapper_0(a1, a2);
return DilistPrepend(a1, v2);
}

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

v2 = MakeWrapper_0(a1, a2);
return func11(a1, v2);
}

original_code:
void DlistPrepend (DlistHeadT* ths, char* data)
{
  DlistT* elem = MakeWrapper(ths,data);
  DilistPrepend(ths, (char*) elem);
}

canonical_original_code:
void DlistPrepend(struct ICnt *ths, char *data)
{
  struct DlistT *elem = MakeWrapper(ths,data);
  DilistPrepend(ths, (char *) elem);
}

variable_types:
data
char *

user_defined_types: struct DlistT { struct DlistT *next; struct DlistT *prev; char *data; }


DlistAppend

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

v2 = MakeWrapper_0(a1, a2);
return DilistAppend(a1, v2);
}

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

v2 = MakeWrapper_0(a1, a2);
return func10(a1, v2);
}

original_code:
void DlistAppend (DlistHeadT* ths, char* data)
{
  DlistT* elem = MakeWrapper(ths,data);
  DilistAppend(ths, (char*) elem);
}

canonical_original_code:
void DlistAppend(struct ICnt *ths, char *data)
{
  struct DlistT *elem = MakeWrapper(ths,data);
  DilistAppend(ths, (char *) elem);
}


DlistPush

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

v2 = MakeWrapper_0(a1, a2);
return DilistPush(a1, v2);
}

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

v2 = MakeWrapper_0(a1, a2);
return func12(a1, v2);
}

original_code:
void DlistPush (DlistHeadT* ths, char* data)
{
  DlistT* elem = MakeWrapper(ths,data);
  DilistPush(ths, (char*) elem);
}

canonical_original_code:
void DlistPush(struct ICnt *ths, char *data)
{
  struct DlistT *elem = MakeWrapper(ths,data);
  DilistPush(ths, (char *) elem);
}


DlistPop

decompiled_code:
__int64 __fastcall DlistPop(__int64 a1)
{
_QWORD *v1; // rax
__int64 v2; // rbp

v1 = (_QWORD *)DilistPop();
if ( !v1 )
return 0LL;
v2 = v1[2];
ReleaseWrapper_0(a1, v1);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func31(__int64 a1)
{
_QWORD *v1; // rax
__int64 v2; // rbp

v1 = (_QWORD *)func9();
if ( !v1 )
return 0LL;
v2 = v1[2];
func24(a1, v1);
return v2;
}

original_code:
char* DlistPop (DlistHeadT* ths)
{
  char* ret;
  DlistT* elem = (DlistT*) DilistPop(ths);
  if (!elem) return 0;
  ret = elem->data;
  ReleaseWrapper(ths, elem);
  return ret;
}

canonical_original_code:
char *DlistPop(struct ICnt *ths)
{
  char *ret;
  struct DlistT *elem = (DlistT*) DilistPop(ths);
  if (!elem) return 0;
  ret = elem->data;
  ReleaseWrapper(ths, elem);
  return ret;
}

variable_types:
ret
char *


DlistRemoveFirst

decompiled_code:
__int64 DlistRemoveFirst()
{
return DlistPop();
}

canonical_decompiled_code:
__int64 func32()
{
return func31();
}

original_code:
char* DlistRemoveFirst (DlistHeadT* ths)
{
   return DlistPop(ths);
}

canonical_original_code:
char *DlistRemoveFirst(struct ICnt *ths)
{
   return DlistPop(ths);
}


DlistHeapAllocate

decompiled_code:
void *__fastcall DlistHeapAllocate(__int64 a1, size_t a2)
{
return malloc(a2);
}

canonical_decompiled_code:
void *__fastcall func0(__int64 a1, size_t a2)
{
return malloc(a2);
}

original_code:
void* DlistHeapAllocate(DlistHeadT* ths,unsigned long int amt)
{
  return malloc(amt);
}

canonical_original_code:
void *DlistHeapAllocate(struct ICnt *ths, unsigned long amt)
{
  return malloc(amt);
}

variable_types:
amt
unsigned long


DlistHeapFree

decompiled_code:
void __fastcall DlistHeapFree(__int64 a1, void *a2)
{
free(a2);
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1, void *a2)
{
free(a2);
}

original_code:
void DlistHeapFree(DlistHeadT* ths,void* ptr)
{
  free(ptr);
}

canonical_original_code:
void DlistHeapFree(struct ICnt *ths, void *ptr)
{
  free(ptr);
}

variable_types:
ptr
void *


TestDlist

decompiled_code:
__int64 TestDlist()
{
void *v0; // r12
__int64 v1; // rbx
void *v2; // rbp
__int64 v3; // rax

v0 = malloc(4uLL);
v1 = DlistCreate();
DlistPrepend(v1, v0);
v2 = (void *)DlistRemoveFirst(v1);
ASSERT(v0 == v2);
free(v2);
v3 = DlistRemoveFirst(v1);
ASSERT(v3 == 0);
return DlistFinalize(v1);
}

canonical_decompiled_code:
__int64 func2()
{
void *v0; // r12
__int64 v1; // rbx
void *v2; // rbp
__int64 v3; // rax

v0 = malloc(4uLL);
v1 = DlistCreate();
DlistPrepend(v1, v0);
v2 = (void *)DlistRemoveFirst(v1);
ASSERT(v0 == v2);
free(v2);
v3 = DlistRemoveFirst(v1);
ASSERT(v3 == 0);
return DlistFinalize(v1);
}

original_code:
void TestDlist(void)
{
  DlistHeadT* list;
  MyData* mn = malloc(sizeof(MyData));
  MyData* mn2;
  list = DlistCreate();
  DlistPrepend(list, (void*) mn);
  mn2 = (MyData* ) DlistRemoveFirst(list);
  ASSERT(mn == mn2);
  free(mn2);
  mn2 = (MyData* ) DlistRemoveFirst(list);
  ASSERT(mn2 == 0);
  DlistFinalize(list);
}

canonical_original_code:
void TestDlist()
{
  struct ICnt *list;
  struct MyData *mn = malloc(sizeof(MyData));
  struct MyData *mn2;
  list = DlistCreate();
  DlistPrepend(list, (void *) mn);
  mn2 = (struct MyData * ) DlistRemoveFirst(list);
  ASSERT(mn == mn2);
  free(mn2);
  mn2 = (struct MyData * ) DlistRemoveFirst(list);
  ASSERT(mn2 == 0);
  DlistFinalize(list);
}

variable_types:
mn
struct MyData { int i; } *


ASSERT

decompiled_code:
int __fastcall ASSERT(int a1)
{
int result; // eax

if ( !a1 )
result = printf("ASSERTION FAILED");
return result;
}

canonical_decompiled_code:
int __fastcall func6(int a1)
{
int result; // eax

if ( !a1 )
result = printf("ASSERTION FAILED");
return result;
}

original_code:
void ASSERT(int bool)
{
  if (!bool)
  {
    printf("ASSERTION FAILED");
  }
}

variable_types: bool int


TestDilist

decompiled_code:
int TestDilist()
{
int v0; // ebx
__int64 v1; // rax
_DWORD v3[6]; // [rsp+0h] [rbp-D8h] BYREF
char v4[8]; // [rsp+18h] [rbp-C0h] BYREF
int v5; // [rsp+20h] [rbp-B8h]
char v6[8]; // [rsp+30h] [rbp-A8h] BYREF
int v7; // [rsp+38h] [rbp-A0h]
char v8[8]; // [rsp+48h] [rbp-90h] BYREF
int v9; // [rsp+50h] [rbp-88h]
int v10; // [rsp+68h] [rbp-70h]
char v11[64]; // [rsp+80h] [rbp-58h] BYREF
int v12[2]; // [rsp+C0h] [rbp-18h] BYREF
int v13[4]; // [rsp+C8h] [rbp-10h] BYREF

v13[0] = 0;
v13[1] = -1;
v12[0] = 16;
v12[1] = -1;
v3[2] = 0;
v5 = 1;
v7 = 2;
v9 = 3;
v10 = 4;
ICntInit(v11, v13, v12, 0xFFFFFFFFLL);
DilistAppend(v11, v4);
DilistAppend(v11, v6);
DilistAppend(v11, v8);
DilistPrepend(v11, v3);
printf("\ndlist: ");
v0 = 4;
do
{
v1 = DilistPop(v11);
if ( v1 )
LODWORD(v1) = printf(" %d ", *(unsigned int *)(v1 + 8));
--v0;
}
while ( v0 );
return v1;
}

canonical_decompiled_code:
int func7()
{
int v0; // ebx
__int64 v1; // rax
_DWORD v3[6]; // [rsp+0h] [rbp-D8h] BYREF
char v4[8]; // [rsp+18h] [rbp-C0h] BYREF
int v5; // [rsp+20h] [rbp-B8h]
char v6[8]; // [rsp+30h] [rbp-A8h] BYREF
int v7; // [rsp+38h] [rbp-A0h]
char v8[8]; // [rsp+48h] [rbp-90h] BYREF
int v9; // [rsp+50h] [rbp-88h]
int v10; // [rsp+68h] [rbp-70h]
char v11[64]; // [rsp+80h] [rbp-58h] BYREF
int v12[2]; // [rsp+C0h] [rbp-18h] BYREF
int v13[4]; // [rsp+C8h] [rbp-10h] BYREF

v13[0] = 0;
v13[1] = -1;
v12[0] = 16;
v12[1] = -1;
v3[2] = 0;
v5 = 1;
v7 = 2;
v9 = 3;
v10 = 4;
ICntInit(v11, v13, v12, 0xFFFFFFFFLL);
DilistAppend(v11, v4);
DilistAppend(v11, v6);
DilistAppend(v11, v8);
DilistPrepend(v11, v3);
printf("\ndlist: ");
v0 = 4;
do
{
v1 = DilistPop(v11);
if ( v1 )
LODWORD(v1) = printf(" %d ", *(unsigned int *)(v1 + 8));
--v0;
}
while ( v0 );
return v1;
}

original_code:
void TestDilist(void)
{
  int i;
  int parentOffsets[] = { ((int) (unsigned long int) (&(((MyDNodeT *) 0)-> prev))), INVALID_OFFSET };
  int childOffsets[] = { ((int) (unsigned long int) (&(((MyDNodeT *) 0)-> next))), INVALID_OFFSET };
  ICnt dlist;
  MyDNodeT n[5];
  for (i=0;i<5;i++) n[i].i = i;
  ICntInit(&dlist, parentOffsets,childOffsets, INVALID_OFFSET);
  DilistAppend(&dlist, (char*) &n[1]);
  DilistAppend(&dlist, (char*)&n[2]);
  DilistAppend(&dlist, (char*)&n[3]);
  DilistPrepend(&dlist, (char*)&n[0]);
  printf("\ndlist: ");
  for (i=0;i<4;i++)
    {
      MyDNodeT* tmp = (MyDNodeT*) DilistPop(&dlist);
      if (tmp) printf (" %d ", tmp->i);
    }
}

canonical_original_code:
void TestDilist()
{
  int i;
  int parentOffsets[] = { ((int) (unsigned long int) (&(((MyDNodeT *) 0)-> prev))), INVALID_OFFSET };
  int childOffsets[] = { ((int) (unsigned long int) (&(((MyDNodeT *) 0)-> next))), INVALID_OFFSET };
  struct ICnt dlist;
  struct MyDNodeT n[5];
  for (i=0;i<5;i++) n[i].i = i;
  ICntInit(&dlist, parentOffsets,childOffsets, INVALID_OFFSET);
  DilistAppend(&dlist, (char *) &n[1]);
  DilistAppend(&dlist, (char *)&n[2]);
  DilistAppend(&dlist, (char *)&n[3]);
  DilistPrepend(&dlist, (char *)&n[0]);
  printf("\ndlist: ");
  for (i=0;i<4;i++)
    {
      struct MyDNodeT *tmp = (MyDNodeT*) DilistPop(&dlist);
      if (tmp) printf (" %d ", tmp->i);
    }
}

variable_types: i int

variable_types:
parentOffsets
int []

variable_types:
childOffsets
int []

variable_types: struct ICnt { int objId; char *first; int *parentOffsets; int *childOffsets; int markOffset; int size; int flags; char *cookie; }

variable_types: struct MyDNodeT { struct MyNodeT { int i; struct MyNodeT *next; } *prev; int i; struct MyNodeT *next; } [5]

variable_types: struct MyDNodeT { struct MyNodeT { int i; struct MyNodeT *next; } *prev; int i; struct MyNodeT *next; } *

user_defined_types: struct MyDNodeT { struct MyNodeT *prev; int i; struct MyNodeT *next; }


triangle

decompiled_code:
float __fastcall triangle(float a1, float a2)
{
return (float)(a1 * a2) * 0.5;
}

canonical_decompiled_code:
float __fastcall func7(float a1, float a2)
{
return (float)(a1 * a2) * 0.5;
}

original_code:
float triangle(float width,float height)
{
  float area;
  area=(width*height)/2.0;
  return(area);
}

canonical_original_code:
float triangle(float width, float height)
{
  float area;
  area=(width*height)/2.0;
  return(area);
}

variable_types: width float

variable_types: height float

variable_types: area float

return_type: float


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
float v3; // xmm0_4
float v4; // xmm0_4
float v5; // xmm0_4
float v6; // xmm0_4

v3 = triangle(1.8, 9.5);
printf("The area of traingle1 is %f \n", v3);
v4 = triangle(3.4000001, 2.9000001);
printf("The area of traingle1 is %f \n", v4);
v5 = triangle(7.5999999, 6.4000001);
printf("The area of traingle1 is %f \n", v5);
v6 = triangle(5.6999998, 4.6999998);
printf("The area of traingle1 is %f \n", v6);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
float v3; // xmm0_4
float v4; // xmm0_4
float v5; // xmm0_4
float v6; // xmm0_4

v3 = func7(1.8, 9.5);
printf("The area of traingle1 is %f \n", v3);
v4 = func7(3.4000001, 2.9000001);
printf("The area of traingle1 is %f \n", v4);
v5 = func7(7.5999999, 6.4000001);
printf("The area of traingle1 is %f \n", v5);
v6 = func7(5.6999998, 4.6999998);
printf("The area of traingle1 is %f \n", v6);
return 0;
}

original_code:
int main()
{
  printf("The area of traingle1 is %f \n",triangle(1.8,9.5));
  printf("The area of traingle1 is %f \n",triangle(3.4,2.9));
  printf("The area of traingle1 is %f \n",triangle(7.6,6.4));
  printf("The area of traingle1 is %f \n",triangle(5.7,4.7));
  return(0);
}


decompiled_code:
_BOOL8 __fastcall can_print_it(char a1)
{
return ((*__ctype_b_loc())[a1] & 0x401) != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func7(char a1)
{
return ((*__ctype_b_loc())[a1] & 0x401) != 0;
}

original_code:
int can_print_it(char ch)
 {
     return ((*__ctype_b_loc ())[(int) ((ch))] & (unsigned short int) _ISalpha) || ((*__ctype_b_loc ())[(int) ((ch))] & (unsigned short int) _ISblank);
 }

canonical_original_code:
int can_print_it(char ch)
 {
     return ((*__ctype_b_loc ())[(int) ((ch))] & (unsigned short) _ISalpha) || ((*__ctype_b_loc ())[(int) ((ch))] & (unsigned short) _ISblank);
 }

variable_types: ch char


decompiled_code:
int __fastcall print_letters(char *a1)
{
char v1; // al
char *v2; // rbp
unsigned int v3; // ebx

v1 = *a1;
if ( *a1 )
{
v2 = a1 + 1;
do
{
v3 = v1;
if ( can_print_it(v1) )
printf("'%c' == %d ", v3, v3);
v1 = *v2++;
}
while ( v1 );
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func8(char *a1)
{
char v1; // al
char *v2; // rbp
unsigned int v3; // ebx

v1 = *a1;
if ( *a1 )
{
v2 = a1 + 1;
do
{
v3 = v1;
if ( func7(v1) )
printf("'%c' == %d ", v3, v3);
v1 = *v2++;
}
while ( v1 );
}
return putchar(10);
}

original_code:
void print_letters(char arg[])
 {
     int i = 0;
     for(i = 0; arg[i] != '\0'; i++) {
         char ch = arg[i];
         if(can_print_it(ch)) {
             printf("'%c' == %d ", ch, ch);
         }
     }
     printf("\n");
 }

variable_types:
arg
char []


decompiled_code:
int __fastcall print_arguments(int a1, char **a2)
{
char **v2; // rbx
int result; // eax

if ( a1 > 0 )
{
v2 = a2;
do
result = print_letters(*v2++);
while ( v2 != &a2[(unsigned int)(a1 - 1) + 1] );
}
return result;
}

canonical_decompiled_code:
int __fastcall func9(int a1, char **a2)
{
char **v2; // rbx
int result; // eax

if ( a1 > 0 )
{
v2 = a2;
do
result = func8(*v2++);
while ( v2 != &a2[(unsigned int)(a1 - 1) + 1] );
}
return result;
}

original_code:
void print_arguments(int argc, char *argv[])
 {
     int i = 0;
     for(i = 0; i < argc; i++) {
         print_letters(argv[i]);
     }
 }

variable_types: argc int

variable_types:
argv
char *[]


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
print_arguments(argc, (char **)argv);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func9(argc, (char **)argv);
return 0;
}

original_code:
int main(int argc, char *argv[])
 {
     print_arguments(argc, argv);
     return 0;
 }


repo: gannimo/traceDaemon

decompiled_code:
unsigned __int64 __fastcall avl_height(_QWORD *a1)
{
unsigned __int64 result; // rax
unsigned __int64 v2; // rbx
unsigned __int64 v3; // rax

result = 0LL;
if ( a1 )
{
v2 = avl_height(*a1);
v3 = avl_height(a1[1]);
if ( v2 >= v3 )
v3 = v2;
result = v3 + 1;
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func6(_QWORD *a1)
{
unsigned __int64 result; // rax
unsigned __int64 v2; // rbx
unsigned __int64 v3; // rax

result = 0LL;
if ( a1 )
{
v2 = func6(*a1);
v3 = func6(a1[1]);
if ( v2 >= v3 )
v3 = v2;
result = v3 + 1;
}
return result;
}

original_code:
static unsigned long avl_height(struct avl_node *node) {
    unsigned long height = 0;
    if (node != ((void *)0)) {
        unsigned long lheight = avl_height(node->left);
        unsigned long rheight = avl_height(node->right);
        height = 1 + ((lheight > rheight) ? lheight : rheight);
    }
    return height;
}

variable_types: struct avl_node { struct avl_node *left; struct avl_node *right; void *data; } *

variable_types:
height
unsigned long

variable_types:
lheight
unsigned long

variable_types:
rheight
unsigned long


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

result = *a1;
*a1 = *(_QWORD *)(*a1 + 8);
*(_QWORD *)(result + 8) = a1;
return result;
}

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

result = *a1;
*a1 = *(_QWORD *)(*a1 + 8);
*(_QWORD *)(result + 8) = a1;
return result;
}

original_code:
static struct avl_node *avl_llro(struct avl_node *parent) {
    struct avl_node *node = parent->left;
    parent->left = node->right;
    node->right = parent;
    return node;
}

variable_types:
parent
struct avl_node *

return_type: struct avl_node { struct avl_node *left; struct avl_node *right; void *data; } *


decompiled_code:
__int64 __fastcall avl_lrro(__int64 *a1)
{
*a1 = (__int64)avl_rrro(*a1);
return avl_llro(a1);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 *a1)
{
*a1 = (__int64)avl_rrro(*a1);
return func8(a1);
}

original_code:
static struct avl_node *avl_lrro(struct avl_node *parent) {
    struct avl_node *node = parent->left;
    parent->left = avl_rrro(node);
    return avl_llro(parent);
}

user_defined_types: struct avl_node { struct avl_node *left; struct avl_node *right; void *data; }


repo: garlick/pi-gpio-uinput

decompiled_code:
__int64 __fastcall gpio_shutdown_set(__int64 (*a1)(void), int a2, int a3)
{
int v5; // er9
int v6; // er10
__int64 v7; // rax
char v8; // r8
char v9; // di
int v10; // edx
unsigned int v11; // ebp

v5 = shutdown_key1_ix;
v6 = shutdown_key2_ix;
v7 = 0LL;
v8 = 0;
v9 = 0;
do
{
v10 = dword_6E4[4 * v7];
if ( v10 == a2 )
v5 = v7;
if ( v10 == a2 )
v9 = 1;
if ( v10 == a3 )
v6 = v7;
if ( v10 == a3 )
v8 = 1;
++v7;
}
while ( v7 != 18 );
if ( v9 )
shutdown_key1_ix = v5;
if ( v8 )
shutdown_key2_ix = v6;
v11 = shutdown_key1_ix;
if ( shutdown_key1_ix == -1 )
{
fwrite("gpio_shutdown_set: invalid keys\n", 1uLL, 0x20uLL, stderr);
}
else
{
shutdown_fun = a1;
v11 = 0;
}
return v11;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 (*a1)(void), int a2, int a3)
{
int v5; // er9
int v6; // er10
__int64 v7; // rax
char v8; // r8
char v9; // di
int v10; // edx
unsigned int v11; // ebp

v5 = shutdown_key1_ix;
v6 = shutdown_key2_ix;
v7 = 0LL;
v8 = 0;
v9 = 0;
do
{
v10 = dword_6E4[4 * v7];
if ( v10 == a2 )
v5 = v7;
if ( v10 == a2 )
v9 = 1;
if ( v10 == a3 )
v6 = v7;
if ( v10 == a3 )
v8 = 1;
++v7;
}
while ( v7 != 18 );
if ( v9 )
shutdown_key1_ix = v5;
if ( v8 )
shutdown_key2_ix = v6;
v11 = shutdown_key1_ix;
if ( shutdown_key1_ix == -1 )
{
fwrite("gpio_shutdown_set: invalid keys\n", 1uLL, 0x20uLL, stderr);
}
else
{
shutdown_fun = a1;
v11 = 0;
}
return v11;
}

original_code:
int gpio_shutdown_set (ShutFun fun, int key1, int key2)
{
    int i;
    for (i = 0; i < maplen; i++) {
        if (map[i].key == key1)
            shutdown_key1_ix = i;
        if (map[i].key == key2)
            shutdown_key2_ix = i;
    }
    if (shutdown_key1_ix == -1 || shutdown_key1_ix == -1) {
        fprintf (stderr, "gpio_shutdown_set: invalid keys\n");
        return -1;
    }
    shutdown_fun = fun;
    return 0;
}

canonical_original_code:
int gpio_shutdown_set(void (*fun)(), int key1, int key2)
{
    int i;
    for (i = 0; i < maplen; i++) {
        if (map[i].key == key1)
            shutdown_key1_ix = i;
        if (map[i].key == key2)
            shutdown_key2_ix = i;
    }
    if (shutdown_key1_ix == -1 || shutdown_key1_ix == -1) {
        fprintf (stderr, "gpio_shutdown_set: invalid keys\n");
        return -1;
    }
    shutdown_fun = fun;
    return 0;
}

variable_types:
fun
void (*)()

variable_types: i int


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

v2 = dword_6E4;
while ( a1(a2, (unsigned int)*v2) >= 0 )
{
v2 += 4;
if ( v2 == &shutdown_key1_ix )
return 0LL;
}
return 0xFFFFFFFFLL;
}

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

v2 = dword_6E4;
while ( a1(a2, (unsigned int)*v2) >= 0 )
{
v2 += 4;
if ( v2 == &shutdown_key1_ix )
return 0LL;
}
return 0xFFFFFFFFLL;
}

original_code:
int gpio_map_keys (KeyMapFun fun, void *arg)
{
    int i;
    for (i = 0; i < maplen; i++) {
        if (fun (arg, map[i].key) < 0)
            return -1;
    }
    return 0;
}

canonical_original_code:
int gpio_map_keys(int (*fun)(void *arg, int key), void *arg)
{
    int i;
    for (i = 0; i < maplen; i++) {
        if (fun (arg, map[i].key) < 0)
            return -1;
    }
    return 0;
}

variable_types:
fun
int (*)(void *arg, int key)

variable_types:
arg
void *


decompiled_code:
_BOOL8 gpio_init()
{
unsigned int *v0; // rbx
int v1; // eax
_BOOL8 result; // rax

v0 = (unsigned int *)↦
do
{
export(*v0);
input(*v0);
edge(*v0);
v1 = open_value(*v0);
v0[3] = v1;
result = read_value(v1);
v0[2] = result;
v0 += 4;
}
while ( v0 != (unsigned int *)&shutdown_key2_ix );
return result;
}

canonical_decompiled_code:
_BOOL8 func9()
{
unsigned int *v0; // rbx
int v1; // eax
_BOOL8 result; // rax

v0 = (unsigned int *)↦
do
{
func1(*v0);
func2(*v0);
func3(*v0);
v1 = func5(*v0);
v0[3] = v1;
result = func6(v1);
v0[2] = result;
v0 += 4;
}
while ( v0 != (unsigned int *)&shutdown_key2_ix );
return result;
}

original_code:
void gpio_init (void)
{
    int i;
    for (i = 0; i < maplen; i++) {
        _export (map[i].pin);
        _input (map[i].pin);
        _edge (map[i].pin);
        map[i].fd = _open_value (map[i].pin);
        map[i].state = _read_value (map[i].fd);
    }
}

canonical_original_code:
void gpio_init()
{
    int i;
    for (i = 0; i < maplen; i++) {
        _export (map[i].pin);
        _input (map[i].pin);
        _edge (map[i].pin);
        map[i].fd = _open_value (map[i].pin);
        map[i].state = _read_value (map[i].fd);
    }
}


decompiled_code:
int gpio_fini()
{
unsigned int *v0; // rbx
int result; // eax
int v2; // edi

v0 = (unsigned int *)↦
do
{
v2 = v0[3];
if ( v2 != -1 )
close(v2);
result = unexport(*v0);
v0 += 4;
}
while ( v0 != (unsigned int *)&shutdown_key2_ix );
return result;
}

canonical_decompiled_code:
int func10()
{
unsigned int *v0; // rbx
int result; // eax
int v2; // edi

v0 = (unsigned int *)↦
do
{
v2 = v0[3];
if ( v2 != -1 )
close(v2);
result = func4(*v0);
v0 += 4;
}
while ( v0 != (unsigned int *)&shutdown_key2_ix );
return result;
}

original_code:
void gpio_fini (void)
{
    int i;
    for (i = 0; i < maplen; i++) {
        if (map[i].fd != -1)
            close (map[i].fd);
            _unexport (map[i].pin);
    }
}

canonical_original_code:
void gpio_fini()
{
    int i;
    for (i = 0; i < maplen; i++) {
        if (map[i].fd != -1)
            close (map[i].fd);
            _unexport (map[i].pin);
    }
}


decompiled_code:
__int64 __fastcall gpio_event(_DWORD *a1)
{
struct pollfd *v2; // rdx
struct pollfd *v3; // rdi
struct pollfd *v4; // rax
int v5; // ebp
unsigned __int64 v6; // rbx
int v7; // eax
int v8; // er13
__int64 v9; // rbp

if ( !pfd_0 )
{
v2 = (struct pollfd *)malloc(0x90uLL);
pfd_0 = v2;
if ( !v2 )
{
fwrite("out of memory\n", 1uLL, 0xEuLL, stderr);
exit(1);
}
memset(v2, 0, 0x90uLL);
}
LABEL_10:
v6 = 0LL;
v5 = 0;
while ( 1 )
{
if ( (pfd_0[v6 / 8].revents & 2) != 0 )
{
pfd_0[v6 / 8].revents = 0;
usleep(0x1388u);
v7 = read_value(pfd_0[v6 / 8].fd);
v8 = v7;
if ( dword_6E8[v6 / 2] != v7 )
break;
}
v3 = pfd_0;
v4 = &pfd_0[v6 / 8];
v4->fd = dword_6EC[v6 / 2];
v4->events = 2;
v4->revents = 0;
++v5;
v6 += 8LL;
if ( v5 == 18 )
{
if ( poll(v3, 0x12uLL, -1) < 0 )
{
perror("poll");
exit(1);
}
goto LABEL_10;
}
}
v9 = 4LL * v5;
dword_6E8[v9] = v7;
shutdown_hook();
*a1 = v8 == 0;
return *(unsigned int *)((char *)&map + v9 * 4 + 4);
}

canonical_decompiled_code:
__int64 __fastcall func11(_DWORD *a1)
{
struct pollfd *v2; // rdx
struct pollfd *v3; // rdi
struct pollfd *v4; // rax
int v5; // ebp
unsigned __int64 v6; // rbx
int v7; // eax
int v8; // er13
__int64 v9; // rbp

if ( !pfd_0 )
{
v2 = (struct pollfd *)malloc(0x90uLL);
pfd_0 = v2;
if ( !v2 )
{
fwrite("out of memory\n", 1uLL, 0xEuLL, stderr);
exit(1);
}
memset(v2, 0, 0x90uLL);
}
LABEL_10:
v6 = 0LL;
v5 = 0;
while ( 1 )
{
if ( (pfd_0[v6 / 8].revents & 2) != 0 )
{
pfd_0[v6 / 8].revents = 0;
usleep(0x1388u);
v7 = func6(pfd_0[v6 / 8].fd);
v8 = v7;
if ( dword_6E8[v6 / 2] != v7 )
break;
}
v3 = pfd_0;
v4 = &pfd_0[v6 / 8];
v4->fd = dword_6EC[v6 / 2];
v4->events = 2;
v4->revents = 0;
++v5;
v6 += 8LL;
if ( v5 == 18 )
{
if ( poll(v3, 0x12uLL, -1) < 0 )
{
perror("poll");
exit(1);
}
goto LABEL_10;
}
}
v9 = 4LL * v5;
dword_6E8[v9] = v7;
func0();
*a1 = v8 == 0;
return *(unsigned int *)((char *)&map + v9 * 4 + 4);
}

original_code:
int gpio_event (int *vp)
{
    static struct pollfd *pfd = ((void *)0);
    int i, val;
    if (pfd == ((void *)0)) {
        pfd = malloc (sizeof (pfd[0]) * maplen);
        if (!pfd) {
            fprintf (stderr, "out of memory\n");
            exit(1);
        }
        memset (pfd, 0, sizeof (pfd[0]) * maplen);
    }
    for (;;) {
        for (i = 0; i < maplen; i++) {
            if ((pfd[i].revents & 0x002)) {
                pfd[i].revents = 0;
                usleep (5 * 1000);
                val = _read_value (pfd[i].fd);
                if (val != map[i].state) {
                    map[i].state = val;
                    _shutdown_hook ();
                    *vp = val == 0 ? 1 : 0;
                    return map[i].key;
                }
            }
            pfd[i].fd = map[i].fd;
            pfd[i].events = 0x002;
            pfd[i].revents = 0;
        }
        if (poll (pfd, maplen, -1) < 0) {
            perror ("poll");
            exit (1);
        }
    }
    return -1;
}

canonical_original_code:
int gpio_event(int *vp)
{
    static struct pollfd *pfd = ((void *)0);
    int i; int val;
    if (pfd == ((void *)0)) {
        pfd = malloc (sizeof (pfd[0]) * maplen);
        if (!pfd) {
            fprintf (stderr, "out of memory\n");
            exit(1);
        }
        memset (pfd, 0, sizeof (pfd[0]) * maplen);
    }
    for (;;) {
        for (i = 0; i < maplen; i++) {
            if ((pfd[i].revents & 0x002)) {
                pfd[i].revents = 0;
                usleep (5 * 1000);
                val = _read_value (pfd[i].fd);
                if (val != map[i].state) {
                    map[i].state = val;
                    _shutdown_hook ();
                    *vp = val == 0 ? 1 : 0;
                    return map[i].key;
                }
            }
            pfd[i].fd = map[i].fd;
            pfd[i].events = 0x002;
            pfd[i].revents = 0;
        }
        if (poll (pfd, maplen, -1) < 0) {
            perror ("poll");
            exit (1);
        }
    }
    return -1;
}

variable_types:
vp
int *

variable_types: struct pollfd { int fd; short events; short revents; } *

variable_types: val int


decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // er14
int v4; // er13
int v5; // er15
int v6; // eax
__int64 v7; // rax
__int64 v8; // rbp
unsigned int v9; // eax
unsigned int v10; // ebx
unsigned int v11[15]; // [rsp+Ch] [rbp-3Ch] BYREF

v3 = 0;
v4 = 0;
v5 = 0;
while ( 1 )
{
v6 = getopt_long(argc, (char *const *)argv, "fds", &longopts, 0LL);
if ( v6 == -1 )
break;
if ( v6 == 102 )
{
v5 = 1;
}
else if ( v6 == 115 )
{
v3 = 1;
}
else
{
if ( v6 != 100 )
usage();
v4 = 1;
}
}
gpio_init();
if ( !v3 || (int)gpio_shutdown_set(shutdown, 6LL, 1LL) >= 0 )
{
v7 = uinput_init();
v8 = v7;
if ( v7 )
{
if ( (int)gpio_map_keys(&uinput_init_key, v7) >= 0 )
{
uinput_create(v8);
if ( !v5 && daemon(0, 0) < 0 )
{
perror("daemon");
exit(1);
}
while ( 1 )
{
v9 = gpio_event(v11);
v10 = v9;
if ( v4 )
fprintf(stderr, "key_event key=0x%x val=%d\n", v9, v11[0]);
if ( (int)uinput_key_event(v8, v10, v11[0]) < 0 )
{
perror("uinput_key_event");
exit(1);
}
}
}
exit(1);
}
exit(1);
}
exit(1);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // er14
int v4; // er13
int v5; // er15
int v6; // eax
__int64 v7; // rax
__int64 v8; // rbp
unsigned int v9; // eax
unsigned int v10; // ebx
unsigned int v11[15]; // [rsp+Ch] [rbp-3Ch] BYREF

v3 = 0;
v4 = 0;
v5 = 0;
while ( 1 )
{
v6 = getopt_long(argc, (char *const *)argv, "fds", &longopts, 0LL);
if ( v6 == -1 )
break;
if ( v6 == 102 )
{
v5 = 1;
}
else if ( v6 == 115 )
{
v3 = 1;
}
else
{
if ( v6 != 100 )
func1();
v4 = 1;
}
}
gpio_init();
if ( !v3 || (int)gpio_shutdown_set(shutdown, 6LL, 1LL) >= 0 )
{
v7 = uinput_init();
v8 = v7;
if ( v7 )
{
if ( (int)gpio_map_keys(&uinput_init_key, v7) >= 0 )
{
uinput_create(v8);
if ( !v5 && daemon(0, 0) < 0 )
{
perror("daemon");
exit(1);
}
while ( 1 )
{
v9 = gpio_event(v11);
v10 = v9;
if ( v4 )
fprintf(stderr, "key_event key=0x%x val=%d\n", v9, v11[0]);
if ( (int)uinput_key_event(v8, v10, v11[0]) < 0 )
{
perror("uinput_key_event");
exit(1);
}
}
}
exit(1);
}
exit(1);
}
exit(1);
}

original_code:
int main (int argc, char *argv[])
{
 struct pollfd fds[1];
 char c;
 if (argc != 2)
  usage();
 fds[0].fd = open (argv[1], 00);
 if (fds[0].fd < 0) {
  perror (argv[1]);
  exit (1);
 }
 if (read (fds[0].fd, &c, 1) != 1) {
  perror ("read");
  exit (1);
 }
 fds[0].events = 0x002;
 fds[0].revents = 0;
 if (poll (fds, 1, -1) < 0) {
  perror ("poll");
  exit (1);
 }
 if (!(fds[0].revents & 0x002)) {
  fprintf (stderr, "poll returned with no events\n");
  exit (1);
 }
 usleep (5000);
 if (lseek (fds[0].fd, 0, 0) < 0) {
  perror ("lseek");
  exit (1);
 }
 if (read (fds[0].fd, &c, 1) != 1) {
  perror ("read");
  exit (1);
 }
 printf ("%c\n", c);
 exit (0);
}

canonical_original_code:
int main(int argc, char *argv[])
{
 struct pollfd fds[1];
 char c;
 if (argc != 2)
  usage();
 fds[0].fd = open (argv[1], 00);
 if (fds[0].fd < 0) {
  perror (argv[1]);
  exit (1);
 }
 if (read (fds[0].fd, &c, 1) != 1) {
  perror ("read");
  exit (1);
 }
 fds[0].events = 0x002;
 fds[0].revents = 0;
 if (poll (fds, 1, -1) < 0) {
  perror ("poll");
  exit (1);
 }
 if (!(fds[0].revents & 0x002)) {
  fprintf (stderr, "poll returned with no events\n");
  exit (1);
 }
 usleep (5000);
 if (lseek (fds[0].fd, 0, 0) < 0) {
  perror ("lseek");
  exit (1);
 }
 if (read (fds[0].fd, &c, 1) != 1) {
  perror ("read");
  exit (1);
 }
 printf ("%c\n", c);
 exit (0);
}

variable_types: struct pollfd { int fd; short events; short revents; } [1]

variable_types: c char


usage

decompiled_code:
void __noreturn usage()
{
fwrite(
"Usage: pigc [OPTIONS]\n"
" -f,--foreground do not fork and diassociate with tty\n"
" -d,--debug show keypresses on stderr\n"
" -s,--shutdown shutdown system when 5 and ESC simultaneously pressed\n",
1uLL,
0xCDuLL,
stderr);
exit(1);
}

canonical_decompiled_code:
void __noreturn func1()
{
fwrite(
"Usage: pigc [OPTIONS]\n"
" -f,--foreground do not fork and diassociate with tty\n"
" -d,--debug show keypresses on stderr\n"
" -s,--shutdown shutdown system when 5 and ESC simultaneously pressed\n",
1uLL,
0xCDuLL,
stderr);
exit(1);
}

original_code:
void usage(void)
{
 fprintf (stderr, "Usage: getpin value_path\n");
 exit (1);
}

canonical_original_code:
void usage()
{
 fprintf (stderr, "Usage: getpin value_path\n");
 exit (1);
}


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // eax
char buf; // [rsp+7h] [rbp-11h] BYREF
struct pollfd fds; // [rsp+8h] [rbp-10h] BYREF

if ( argc != 2 )
usage(argc, argv, envp);
v3 = open(argv[1], 0, envp);
fds.fd = v3;
if ( v3 >= 0 )
{
if ( (unsigned int)read(v3, &buf, 1uLL) != 1 )
{
perror("read");
exit(1);
}
fds.events = 2;
fds.revents = 0;
if ( poll(&fds, 1uLL, -1) >= 0 )
{
if ( (fds.revents & 2) == 0 )
{
fwrite("poll returned with no events\n", 1uLL, 0x1DuLL, stderr);
exit(1);
}
usleep(0x1388u);
if ( (int)lseek(fds.fd, 0LL, 0) >= 0 )
{
if ( (unsigned int)read(fds.fd, &buf, 1uLL) != 1 )
{
perror("read");
exit(1);
}
printf("%c\n", (unsigned int)buf);
exit(0);
}
perror("lseek");
exit(1);
}
perror("poll");
exit(1);
}
perror(argv[1]);
exit(1);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // eax
char buf; // [rsp+7h] [rbp-11h] BYREF
struct pollfd fds; // [rsp+8h] [rbp-10h] BYREF

if ( argc != 2 )
func7(argc, argv, envp);
v3 = open(argv[1], 0, envp);
fds.fd = v3;
if ( v3 >= 0 )
{
if ( (unsigned int)read(v3, &buf, 1uLL) != 1 )
{
perror("read");
exit(1);
}
fds.events = 2;
fds.revents = 0;
if ( poll(&fds, 1uLL, -1) >= 0 )
{
if ( (fds.revents & 2) == 0 )
{
fwrite("poll returned with no events\n", 1uLL, 0x1DuLL, stderr);
exit(1);
}
usleep(0x1388u);
if ( (int)lseek(fds.fd, 0LL, 0) >= 0 )
{
if ( (unsigned int)read(fds.fd, &buf, 1uLL) != 1 )
{
perror("read");
exit(1);
}
printf("%c\n", (unsigned int)buf);
exit(0);
}
perror("lseek");
exit(1);
}
perror("poll");
exit(1);
}
perror(argv[1]);
exit(1);
}

user_defined_types: struct pollfd { int fd; short events; short revents; }


usage

decompiled_code:
void __noreturn usage()
{
fwrite("Usage: getpin value_path\n", 1uLL, 0x19uLL, stderr);
exit(1);
}

canonical_decompiled_code:
void __noreturn func7()
{
fwrite("Usage: getpin value_path\n", 1uLL, 0x19uLL, stderr);
exit(1);
}


repo: garlick/pi-ted-envoy

decompiled_code:
__int64 __fastcall raw_power(unsigned __int8 *a1)
{
int v1; // edx
__int64 result; // rax

v1 = (a1[5] << 16) | (a1[4] << 8);
result = v1 | (unsigned int)a1[3];
if ( (v1 & 0x800000) != 0 )
result = v1 | a1[3] | 0xFF000000;
return result;
}

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

v1 = (a1[5] << 16) | (a1[4] << 8);
result = v1 | (unsigned int)a1[3];
if ( (v1 & 0x800000) != 0 )
result = v1 | a1[3] | 0xFF000000;
return result;
}

canonical_original_code:
static int raw_power(unsigned char *pkt)
{
 unsigned int i;
 i = (unsigned int)pkt[3] | (unsigned int)pkt[4] << 8 | (unsigned int)pkt[5] << 16;
 if (i & 0x00800000)
  i |= 0xff000000;
 return (int)i;
}

variable_types:
pkt
unsigned char *

variable_types:
i
unsigned int


decompiled_code:
__int64 __fastcall raw_voltage(unsigned __int8 *a1)
{
int v1; // edx
__int64 result; // rax

v1 = (a1[8] << 16) | (a1[7] << 8);
result = v1 | (unsigned int)a1[6];
if ( (v1 & 0x800000) != 0 )
result = v1 | a1[6] | 0xFF000000;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned __int8 *a1)
{
int v1; // edx
__int64 result; // rax

v1 = (a1[8] << 16) | (a1[7] << 8);
result = v1 | (unsigned int)a1[6];
if ( (v1 & 0x800000) != 0 )
result = v1 | a1[6] | 0xFF000000;
return result;
}

original_code:
static int32_t raw_voltage(uint8_t *pkt)
{
 uint32_t i;
 i = (uint32_t)pkt[6] | (uint32_t)pkt[7] << 8 | (uint32_t)pkt[8] << 16;
 if (i & 0x00800000)
  i |= 0xff000000;
 return (int32_t)i;
}

canonical_original_code:
static int raw_voltage(unsigned char *pkt)
{
 unsigned int i;
 i = (unsigned int)pkt[6] | (unsigned int)pkt[7] << 8 | (unsigned int)pkt[8] << 16;
 if (i & 0x00800000)
  i |= 0xff000000;
 return (int)i;
}


decompiled_code:
_BOOL8 __fastcall verify_cksum(_BYTE *a1)
{
_BYTE *v1; // rax
char v2; // dl

v1 = a1;
v2 = 0;
do
v2 += *v1++;
while ( v1 != a1 + 11 );
return a1[9] == v2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func9(_BYTE *a1)
{
_BYTE *v1; // rax
char v2; // dl

v1 = a1;
v2 = 0;
do
v2 += *v1++;
while ( v1 != a1 + 11 );
return a1[9] == v2;
}

original_code:
static int verify_cksum(uint8_t *pkt)
{
 int sum = 0;
 int i;
 for (i = 0; i < 11; i++)
  sum += pkt[i];
 sum &= 0xff;
 return (sum == pkt[9]);
}

canonical_original_code:
static int verify_cksum(unsigned char *pkt)
{
 int sum = 0;
 int i;
 for (i = 0; i < 11; i++)
  sum += pkt[i];
 sum &= 0xff;
 return (sum == pkt[9]);
}

variable_types: sum int


original_code:
int ted_read(int *addrp, int *countp, int *wattsp, int *voltsp)
{
 int cc, i;
 uint8_t c, pkt[11];
 double power, voltage;
 i = 0;
 while (i < 11 && (cc = fgetc(ted)) != (-1)) {
  c = ~(uint8_t)cc;
  if (c != 0x55 && i == 0)
   continue;
  pkt[i++] = c;
 }
 if (cc == (-1)) {
  if ((*__errno_location ()) == 0)
   (*__errno_location ()) = 5;
  return -1;
 }
 if (!verify_cksum (pkt)) {
  (*__errno_location ()) = 22;
  return -1;
 }
 voltage = 123.6 + (raw_voltage(pkt)/256 - 27620) / 85 * 0.4;
 power = 1.19 + 0.84 * ((raw_power(pkt)/256 - 288.0) / 204.0);
 if (addrp)
  *addrp = pkt[1];
 if (countp)
  *countp = pkt[2];
 if (wattsp)
  *wattsp = power * 1000;
 if (voltsp)
  *voltsp = voltage;
 return 0;
}

canonical_original_code:
int ted_read(int *addrp, int *countp, int *wattsp, int *voltsp)
{
 int cc; int i;
 unsigned char c; unsigned char pkt[11];
 double power; double voltage;
 i = 0;
 while (i < 11 && (cc = fgetc(ted)) != (-1)) {
  c = ~(unsigned char)cc;
  if (c != 0x55 && i == 0)
   continue;
  pkt[i++] = c;
 }
 if (cc == (-1)) {
  if ((*__errno_location ()) == 0)
   (*__errno_location ()) = 5;
  return -1;
 }
 if (!verify_cksum (pkt)) {
  (*__errno_location ()) = 22;
  return -1;
 }
 voltage = 123.6 + (raw_voltage(pkt)/256 - 27620) / 85 * 0.4;
 power = 1.19 + 0.84 * ((raw_power(pkt)/256 - 288.0) / 204.0);
 if (addrp)
  *addrp = pkt[1];
 if (countp)
  *countp = pkt[2];
 if (wattsp)
  *wattsp = power * 1000;
 if (voltsp)
  *voltsp = voltage;
 return 0;
}

variable_types:
addrp
int *

variable_types:
countp
int *

variable_types:
wattsp
int *

variable_types:
voltsp
int *

variable_types: cc int

variable_types:
c
unsigned char

variable_types:
pkt
unsigned char [11]

variable_types: power double

variable_types: voltage double


decompiled_code:
__int64 __fastcall ted_init(const char *a1)
{
int v1; // eax
int v2; // ebx
__int64 result; // rax
struct termios v4; // [rsp+0h] [rbp-48h] BYREF

v1 = open(a1, 2);
if ( v1 < 0 )
return 0xFFFFFFFFLL;
v2 = v1;
if ( flock(v1, 6) < 0 )
{
close(v2);
result = 0xFFFFFFFFLL;
}
else if ( tcgetattr(v2, &v4) < 0
|| (cfsetspeed(&v4, 9u),
v4.c_cflag = v4.c_cflag & 0xFFFFFE8F | 0x30,
cfmakeraw(&v4),
v4.c_cc[6] = 1,
v4.c_cc[5] = 0,
tcsetattr(v2, 0, &v4) < 0) )
{
close(v2);
result = 0xFFFFFFFFLL;
}
else
{
ted = fdopen(v2, "r");
result = (unsigned int)-(ted == 0LL);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(const char *a1)
{
int v1; // eax
int v2; // ebx
__int64 result; // rax
struct termios v4; // [rsp+0h] [rbp-48h] BYREF

v1 = open(a1, 2);
if ( v1 < 0 )
return 0xFFFFFFFFLL;
v2 = v1;
if ( flock(v1, 6) < 0 )
{
close(v2);
result = 0xFFFFFFFFLL;
}
else if ( tcgetattr(v2, &v4) < 0
|| (cfsetspeed(&v4, 9u),
v4.c_cflag = v4.c_cflag & 0xFFFFFE8F | 0x30,
cfmakeraw(&v4),
v4.c_cc[6] = 1,
v4.c_cc[5] = 0,
tcsetattr(v2, 0, &v4) < 0) )
{
close(v2);
result = 0xFFFFFFFFLL;
}
else
{
ted = fdopen(v2, "r");
result = (unsigned int)-(ted == 0LL);
}
return result;
}

original_code:
int ted_init(char *devname)
{
 int fd;
 struct termios tio;
 fd = open(devname, 02);
 if (fd < 0)
  return -1;
 if (flock(fd, 2 | 4) < 0) {
  close (fd);
  return -1;
 }
 if (tcgetattr(fd, &tio) < 0) {
  close (fd);
  return -1;
 }
 cfsetspeed(&tio, 0000011);
 tio.c_cflag &= ~0000060;
 tio.c_cflag |= 0000060;
 tio.c_cflag &= ~0000100;
 tio.c_cflag &= ~0000400;
 cfmakeraw(&tio);
 tio.c_cc[6] = 1;
 tio.c_cc[5] = 0;
 if (tcsetattr(fd, 0, &tio) < 0) {
  close (fd);
  return -1;
 }
 if ((ted = fdopen(fd, "r")) == ((void *)0))
  return -1;
 return 0;
}

variable_types:
devname
char *

variable_types: fd int

variable_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; }


decompiled_code:
int ted_fini()
{
return fclose(ted);
}

canonical_decompiled_code:
int func12()
{
return fclose(ted);
}

original_code:
void ted_fini (void)
{
 fclose (ted);
}

canonical_original_code:
void ted_fini()
{
 fclose (ted);
}


decompiled_code:
int __fastcall gpio_pin_pulse(unsigned int a1, int a2, int a3)
{
int v4; // ebp

export(a1);
direction(a1, "out");
v4 = open_value(a1, 2);
write_value(v4, a3);
usleep(1000 * a2);
write_value(v4, a3 == 0);
close(v4);
return unexport(a1);
}

canonical_decompiled_code:
int __fastcall func7(unsigned int a1, int a2, int a3)
{
int v4; // ebp

func0(a1);
func1(a1, "out");
v4 = func4(a1, 2);
func5(v4, a3);
usleep(1000 * a2);
func5(v4, a3 == 0);
close(v4);
return func2(a1);
}

original_code:
void gpio_pin_pulse (int pin, int msec, int active_value)
{
    int fd;
    _export (pin);
    _direction (pin, "out");
    fd = _open_value (pin, 02);
    _write_value (fd, active_value);
    usleep (msec * 1000);
    _write_value (fd, !active_value);
    close (fd);
    _unexport (pin);
}

canonical_original_code:
void gpio_pin_pulse(int pin, int msec, int active_value)
{
    int fd;
    _export (pin);
    _direction (pin, "out");
    fd = _open_value (pin, 02);
    _write_value (fd, active_value);
    usleep (msec * 1000);
    _write_value (fd, !active_value);
    close (fd);
    _unexport (pin);
}

variable_types: pin int

variable_types: msec int


decompiled_code:
int __fastcall gpio_keypress(unsigned int a1, int a2)
{
int v2; // ebx
struct pollfd fds; // [rsp+8h] [rbp-20h] BYREF

fds = 0LL;
export(a1);
direction(a1, "in");
edge(a1, "both");
v2 = open_value(a1, 0);
read_value(v2);
do
{
fds.fd = v2;
fds.revents = 0;
fds.events = 2;
if ( poll(&fds, 1uLL, -1) < 0 )
{
perror("poll");
exit(1);
}
usleep(0x1388u);
}
while ( read_value(v2) != a2 );
close(v2);
return unexport(a1);
}

canonical_decompiled_code:
int __fastcall func8(unsigned int a1, int a2)
{
int v2; // ebx
struct pollfd fds; // [rsp+8h] [rbp-20h] BYREF

fds = 0LL;
func0(a1);
func1(a1, "in");
func3(a1, "both");
v2 = func4(a1, 0);
func6(v2);
do
{
fds.fd = v2;
fds.revents = 0;
fds.events = 2;
if ( poll(&fds, 1uLL, -1) < 0 )
{
perror("poll");
exit(1);
}
usleep(0x1388u);
}
while ( func6(v2) != a2 );
close(v2);
return func2(a1);
}

original_code:
void gpio_keypress (int pin, int active_value)
{
    struct pollfd pfd[1];
    int val, fd;
    memset (pfd, 0, sizeof (pfd));
    _export (pin);
    _direction (pin, "in");
    _edge (pin, "both");
    fd = _open_value (pin, 00);
    val = _read_value (fd);
    do {
        pfd[0].fd = fd;
        pfd[0].revents = 0;
        pfd[0].events = 0x002;
        if (poll (pfd, 1, -1) < 0) {
            perror ("poll");
            exit (1);
        }
        usleep (1000 * 5);
        val = _read_value (fd);
    } while (val != active_value);
    close (fd);
    _unexport (pin);
}

canonical_original_code:
void gpio_keypress(int pin, int active_value)
{
    struct pollfd pfd[1];
    int val; int fd;
    memset (pfd, 0, sizeof (pfd));
    _export (pin);
    _direction (pin, "in");
    _edge (pin, "both");
    fd = _open_value (pin, 00);
    val = _read_value (fd);
    do {
        pfd[0].fd = fd;
        pfd[0].revents = 0;
        pfd[0].events = 0x002;
        if (poll (pfd, 1, -1) < 0) {
            perror ("poll");
            exit (1);
        }
        usleep (1000 * 5);
        val = _read_value (fd);
    } while (val != active_value);
    close (fd);
    _unexport (pin);
}

variable_types: struct pollfd { int fd; short events; short revents; } [1]

variable_types: val int


decompiled_code:
double __fastcall c2f(double a1)
{
return a1 * 9.0 / 5.0 + 32.0;
}

canonical_decompiled_code:
double __fastcall func8(double a1)
{
return a1 * 9.0 / 5.0 + 32.0;
}

original_code:
double c2f (double c)
{
 return 9.0*c/5.0 + 32.0;
}

canonical_original_code:
double c2f(double c)
{
 return 9.0*c/5.0 + 32.0;
}

variable_types: c double

return_type: double


decompiled_code:
ssize_t __fastcall oled_clear(int a1)
{
__int16 buf[5]; // [rsp+Eh] [rbp-Ah] BYREF

buf[0] = 19523;
return write(a1, buf, 2uLL);
}

canonical_decompiled_code:
ssize_t __fastcall func2(int a1)
{
__int16 buf[5]; // [rsp+Eh] [rbp-Ah] BYREF

buf[0] = 19523;
return func0(a1, buf, 2uLL);
}

original_code:
void
oled_clear(int fd)
{
    uint8_t buf[] = { 'C', 'L' };
    _write(fd, buf, sizeof (buf));
}

canonical_original_code:
void oled_clear(int fd)
{
    unsigned char buf[] = { 'C', 'L' };
    _write(fd, buf, sizeof (buf));
}

variable_types:
buf
unsigned char []


decompiled_code:
ssize_t __fastcall oled_cursor_set(int a1, char a2)
{
char buf[11]; // [rsp+Dh] [rbp-Bh] BYREF

buf[0] = 67;
buf[1] = 83;
buf[2] = a2;
return write(a1, buf, 3uLL);
}

canonical_decompiled_code:
ssize_t __fastcall func3(int a1, char a2)
{
char buf[11]; // [rsp+Dh] [rbp-Bh] BYREF

buf[0] = 67;
buf[1] = 83;
buf[2] = a2;
return func0(a1, buf, 3uLL);
}

original_code:
void
oled_cursor_set (int fd, _Bool val)
{
    uint8_t buf[] = { 'C', 'S', val ? 1 : 0 };
    _write(fd, buf, sizeof (buf));
}

canonical_original_code:
void oled_cursor_set(int fd, _Bool val)
{
    unsigned char buf[] = { 'C', 'S', val ? 1 : 0 };
    _write(fd, buf, sizeof (buf));
}