decompiled_code:
char *__fastcall c3600_nm_get_bay_info(int a1, unsigned int a2)
{
char *result; // rax
unsigned int v3; // edx
char *v4; // rax

if ( a1 == 3640 )
{
v3 = 4;
v4 = (char *)&c3640_nm_bays;
}
else if ( a1 == 3660 )
{
v3 = 7;
v4 = (char *)&c3660_nm_bays;
}
else
{
result = 0LL;
if ( a1 != 3620 )
return result;
v3 = 2;
v4 = (char *)&c3620_nm_bays;
}
if ( v3 <= a2 )
result = 0LL;
else
result = &v4[8 * a2];
return result;
}

canonical_decompiled_code:
char *__fastcall func0(int a1, unsigned int a2)
{
char *result; // rax
unsigned int v3; // edx
char *v4; // rax

if ( a1 == 3640 )
{
v3 = 4;
v4 = (char *)&c3640_nm_bays;
}
else if ( a1 == 3660 )
{
v3 = 7;
v4 = (char *)&c3660_nm_bays;
}
else
{
result = 0LL;
if ( a1 != 3620 )
return result;
v3 = 2;
v4 = (char *)&c3620_nm_bays;
}
if ( v3 <= a2 )
result = 0LL;
else
result = &v4[8 * a2];
return result;
}

original_code:
struct nm_bay_info *c3600_nm_get_bay_info(u_int chassis,u_int nm_bay)
{
   struct nm_bay_info *bay_info;
   u_int max_bays = 0;
   switch(chassis) {
      case 3620:
         bay_info = c3620_nm_bays;
         max_bays = 2;
         break;
      case 3640:
         bay_info = c3640_nm_bays;
         max_bays = 4;
         break;
      case 3660:
         bay_info = c3660_nm_bays;
         max_bays = 7;
         break;
   }
   if (nm_bay >= max_bays)
      return ((void *)0);
   return(&bay_info[nm_bay]);
}

canonical_original_code:
struct nm_bay_info *c3600_nm_get_bay_info(unsigned int chassis, unsigned int nm_bay)
{
   struct nm_bay_info *bay_info;
   unsigned int max_bays = 0;
   switch(chassis) {
      case 3620:
         bay_info = c3620_nm_bays;
         max_bays = 2;
         break;
      case 3640:
         bay_info = c3640_nm_bays;
         max_bays = 4;
         break;
      case 3660:
         bay_info = c3660_nm_bays;
         max_bays = 7;
         break;
   }
   if (nm_bay >= max_bays)
      return ((void *)0);
   return(&bay_info[nm_bay]);
}

variable_types:
chassis
unsigned int

variable_types: struct nm_bay_info { int pci_bridge_device; int pci_device; } *


repo: Groundworkstech/dynamips-gdb-mod

decompiled_code:
__int64 netio_filter_load_all()
{
netio_filter_add((__int64)&pf_freqdrop_def);
return netio_filter_add((__int64)&pf_capture_def);
}

canonical_decompiled_code:
__int64 func11()
{
func7((__int64)&pf_freqdrop_def);
return func7((__int64)&pf_capture_def);
}

original_code:
void netio_filter_load_all(void)
{
   netio_filter_add(&pf_freqdrop_def);
   netio_filter_add(&pf_capture_def);
}

canonical_original_code:
void netio_filter_load_all()
{
   netio_filter_add(&pf_freqdrop_def);
   netio_filter_add(&pf_capture_def);
}

return_type: void


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

gettimeofday(&v1, 0LL);
return 1000 * v1.tv_sec + v1.tv_usec / 0x3E8uLL;
}

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

gettimeofday(&v1, 0LL);
return 1000 * v1.tv_sec + v1.tv_usec / 0x3E8uLL;
}

original_code:
static inline m_tmcnt_t m_gettime(void)
{
   struct timeval tvp;
   gettimeofday(&tvp,((void *)0));
   return(((m_tmcnt_t)tvp.tv_sec * 1000) + ((m_tmcnt_t)tvp.tv_usec / 1000));
}

canonical_original_code:
static inline unsigned long long m_gettime()
{
   struct timeval tvp;
   gettimeofday(&tvp,((void *)0));
   return(((unsigned long long)tvp.tv_sec * 1000) + ((unsigned long long)tvp.tv_usec / 1000));
}

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

return_type: unsigned long long


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

gettimeofday(&v1, 0LL);
return v1.tv_usec + 1000000 * v1.tv_sec;
}

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

gettimeofday(&v1, 0LL);
return v1.tv_usec + 1000000 * v1.tv_sec;
}

original_code:
static inline m_tmcnt_t m_gettime_usec(void)
{
   struct timeval tvp;
   gettimeofday(&tvp,((void *)0));
   return(((m_tmcnt_t)tvp.tv_sec * 1000000) + (m_tmcnt_t)tvp.tv_usec);
}

canonical_original_code:
static inline unsigned long long m_gettime_usec()
{
   struct timeval tvp;
   gettimeofday(&tvp,((void *)0));
   return(((unsigned long long)tvp.tv_sec * 1000000) + (unsigned long long)tvp.tv_usec);
}

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


repo: GuglielmoS/Deflate

decompiled_code:
void *__fastcall Limited_List_init(_QWORD *a1)
{
void *result; // rax

result = malloc(8LL * a1[1]);
a1[4] = 0LL;
*a1 = result;
a1[3] = 0LL;
a1[2] = 0LL;
return result;
}

canonical_decompiled_code:
void *__fastcall func0(_QWORD *a1)
{
void *result; // rax

result = malloc(8LL * a1[1]);
a1[4] = 0LL;
*a1 = result;
a1[3] = 0LL;
a1[2] = 0LL;
return result;
}

original_code:
void Limited_List_init(Limited_List *ll)
{
    ll->values = (LL_Value*)malloc(sizeof(LL_Value)*ll->max_size);
    ll->next_pos = 0;
    ll->start_pos = 0;
    ll->cur_size = 0;
}

canonical_original_code:
void Limited_List_init(struct Limited_List *ll)
{
    ll->values = (unsigned long *)malloc(sizeof(LL_Value)*ll->max_size);
    ll->next_pos = 0;
    ll->start_pos = 0;
    ll->cur_size = 0;
}

variable_types: struct Limited_List { unsigned long *values; unsigned long max_size; unsigned long cur_size; unsigned long start_pos; unsigned long next_pos; } *


decompiled_code:
unsigned __int64 __fastcall Limited_List_add(__int64 *a1, __int64 a2)
{
__int64 v2; // rax
unsigned __int64 v3; // rcx
unsigned __int64 v4; // rax
unsigned __int64 result; // rax

v2 = *a1;
if ( !*a1 )
{
Limited_List_init(a1);
v2 = *a1;
}
*(_QWORD *)(v2 + 8 * a1[4]) = a2;
v3 = a1[1];
v4 = a1[2];
a1[4] = (a1[4] + 1) % v3;
if ( v3 <= v4 )
{
result = (a1[3] + 1) / v3;
a1[3] = (a1[3] + 1) % v3;
}
else
{
result = v4 + 1;
a1[2] = result;
}
return result;
}

original_code:
void Limited_List_add(Limited_List *ll, LL_Value value)
{
    if (ll->values == ((void *)0)) {
        Limited_List_init(ll);
    }
    ll->values[ll->next_pos] = value;
    ll->next_pos = (ll->next_pos + 1) % ll->max_size;
    if (ll->cur_size < ll->max_size) {
        ll->cur_size++;
    }
    else {
        ll->start_pos = (ll->start_pos + 1) % ll->max_size;
    }
}

canonical_original_code:
void Limited_List_add(struct Limited_List *ll, unsigned long value)
{
    if (ll->values == ((void *)0)) {
        Limited_List_init(ll);
    }
    ll->values[ll->next_pos] = value;
    ll->next_pos = (ll->next_pos + 1) % ll->max_size;
    if (ll->cur_size < ll->max_size) {
        ll->cur_size++;
    }
    else {
        ll->start_pos = (ll->start_pos + 1) % ll->max_size;
    }
}

variable_types:
value
unsigned long

user_defined_types: struct Limited_List { unsigned long *values; unsigned long max_size; unsigned long cur_size; unsigned long start_pos; unsigned long next_pos; }


decompiled_code:
void __fastcall Limited_List_destroy(void **a1)
{
void *v2; // rdi

v2 = *a1;
if ( v2 )
{
free(v2);
*a1 = 0LL;
}
}

canonical_decompiled_code:
void __fastcall func2(void **a1)
{
void *v2; // rdi

v2 = *a1;
if ( v2 )
{
free(v2);
*a1 = 0LL;
}
}

original_code:
void Limited_List_destroy(Limited_List *ll)
{
    if (ll->values) {
        free(ll->values);
        ll->values = ((void *)0);
    }
}

canonical_original_code:
void Limited_List_destroy(struct Limited_List *ll)
{
    if (ll->values) {
        free(ll->values);
        ll->values = ((void *)0);
    }
}


decompiled_code:
_QWORD *Bit_Vec_create()
{
_QWORD *v0; // r12
void *v1; // rax
_QWORD *result; // rax

v0 = malloc(0x18uLL);
if ( !v0 )
die_error("[ERROR-Bit_Vec_create] malloc (1st) failed!\n");
v1 = malloc(1uLL);
*v0 = v1;
if ( !v1 )
die_error("[ERROR-Bit_Vec_create] malloc (2nd) failed!\n");
v0[2] = 8LL;
result = v0;
v0[1] = 0LL;
return result;
}

canonical_decompiled_code:
_QWORD *func0()
{
_QWORD *v0; // r12
void *v1; // rax
_QWORD *result; // rax

v0 = malloc(0x18uLL);
if ( !v0 )
die_error("[ERROR-Bit_Vec_create] malloc (1st) failed!\n");
v1 = malloc(1uLL);
*v0 = v1;
if ( !v1 )
die_error("[ERROR-Bit_Vec_create] malloc (2nd) failed!\n");
v0[2] = 8LL;
result = v0;
v0[1] = 0LL;
return result;
}

original_code:
Bit_Vec* Bit_Vec_create()
{
    Bit_Vec *bv = (Bit_Vec*)malloc(sizeof(Bit_Vec));
    if (bv == ((void *)0)) {
        die_error("[ERROR-Bit_Vec_create] malloc (1st) failed!\n");
    }
    bv->buf = (uint8_t*)malloc(1);
    if (bv->buf == ((void *)0)) {
        die_error("[ERROR-Bit_Vec_create] malloc (2nd) failed!\n");
    }
    bv->max_size = 1*8;
    bv->cur_size = 0;
    return bv;
}

canonical_original_code:
struct Bit_Vec *Bit_Vec_create()
{
    struct Bit_Vec *bv = (Bit_Vec*)malloc(sizeof(Bit_Vec));
    if (bv == ((void *)0)) {
        die_error("[ERROR-Bit_Vec_create] malloc (1st) failed!\n");
    }
    bv->buf = (unsigned char *)malloc(1);
    if (bv->buf == ((void *)0)) {
        die_error("[ERROR-Bit_Vec_create] malloc (2nd) failed!\n");
    }
    bv->max_size = 1*8;
    bv->cur_size = 0;
    return bv;
}

variable_types: struct Bit_Vec { unsigned char *buf; unsigned long cur_size; unsigned long max_size; } *


decompiled_code:
void **__fastcall Bit_Vec_dup(__int64 a1)
{
void **v2; // r12
size_t v3; // r13
void *v4; // rax
void *v5; // rdi

v2 = (void **)malloc(0x18uLL);
if ( !v2 )
die_error("[ERROR-Bit_Vec_create_with_size] malloc (1st) failed!\n");
v3 = *(_QWORD *)(a1 + 16) >> 3;
v4 = malloc(v3);
*v2 = v4;
v5 = v4;
if ( !v4 )
{
die_error("[ERROR-Bit_Vec_create_with_size] malloc (2nd) failed!\n");
v5 = *v2;
v3 = *(_QWORD *)(a1 + 16) >> 3;
}
memcpy(v5, *(const void **)a1, v3);
v2[2] = *(void **)(a1 + 16);
v2[1] = *(void **)(a1 + 8);
return v2;
}

canonical_decompiled_code:
void **__fastcall func1(__int64 a1)
{
void **v2; // r12
size_t v3; // r13
void *v4; // rax
void *v5; // rdi

v2 = (void **)malloc(0x18uLL);
if ( !v2 )
die_error("[ERROR-Bit_Vec_create_with_size] malloc (1st) failed!\n");
v3 = *(_QWORD *)(a1 + 16) >> 3;
v4 = malloc(v3);
*v2 = v4;
v5 = v4;
if ( !v4 )
{
die_error("[ERROR-Bit_Vec_create_with_size] malloc (2nd) failed!\n");
v5 = *v2;
v3 = *(_QWORD *)(a1 + 16) >> 3;
}
memcpy(v5, *(const void **)a1, v3);
v2[2] = *(void **)(a1 + 16);
v2[1] = *(void **)(a1 + 8);
return v2;
}

original_code:
Bit_Vec* Bit_Vec_dup(Bit_Vec *bv)
{
    Bit_Vec *bv2 = (Bit_Vec*)malloc(sizeof(Bit_Vec));
    if (bv2 == ((void *)0)) {
        die_error("[ERROR-Bit_Vec_create_with_size] malloc (1st) failed!\n");
    }
    bv2->buf = (uint8_t*)malloc(bv->max_size/8);
    if (bv2->buf == ((void *)0)) {
        die_error("[ERROR-Bit_Vec_create_with_size] malloc (2nd) failed!\n");
    }
    memcpy(bv2->buf,bv->buf,bv->max_size/8);
    bv2->max_size = bv->max_size;
    bv2->cur_size = bv->cur_size;
    return bv2;
}

canonical_original_code:
struct Bit_Vec *Bit_Vec_dup(struct Bit_Vec *bv)
{
    struct Bit_Vec *bv2 = (Bit_Vec*)malloc(sizeof(Bit_Vec));
    if (bv2 == ((void *)0)) {
        die_error("[ERROR-Bit_Vec_create_with_size] malloc (1st) failed!\n");
    }
    bv2->buf = (unsigned char *)malloc(bv->max_size/8);
    if (bv2->buf == ((void *)0)) {
        die_error("[ERROR-Bit_Vec_create_with_size] malloc (2nd) failed!\n");
    }
    memcpy(bv2->buf,bv->buf,bv->max_size/8);
    bv2->max_size = bv->max_size;
    bv2->cur_size = bv->cur_size;
    return bv2;
}

variable_types:
bv
struct Bit_Vec *

return_type: struct Bit_Vec { unsigned char *buf; unsigned long cur_size; unsigned long max_size; } *


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

result = realloc(*(void **)a1, *(_QWORD *)(a1 + 16) >> 2);
*(_QWORD *)a1 = result;
if ( !result )
result = (void *)die_error("[ERROR-Bit_Vec_grow_store] realloc failed!\n");
*(_QWORD *)(a1 + 16) *= 2LL;
return result;
}

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

result = realloc(*(void **)a1, *(_QWORD *)(a1 + 16) >> 2);
*(_QWORD *)a1 = result;
if ( !result )
result = (void *)die_error("[ERROR-Bit_Vec_grow_store] realloc failed!\n");
*(_QWORD *)(a1 + 16) *= 2LL;
return result;
}

original_code:
void Bit_Vec_grow_store(Bit_Vec *bv)
{
    bv->buf = (uint8_t*)realloc(bv->buf, bv->max_size/4);
    if (bv->buf == ((void *)0)) {
        die_error("[ERROR-Bit_Vec_grow_store] realloc failed!\n");
    }
    bv->max_size *= 2;
}

canonical_original_code:
void Bit_Vec_grow_store(struct Bit_Vec *bv)
{
    bv->buf = (unsigned char *)realloc(bv->buf, bv->max_size/4);
    if (bv->buf == ((void *)0)) {
        die_error("[ERROR-Bit_Vec_grow_store] realloc failed!\n");
    }
    bv->max_size *= 2;
}

user_defined_types: struct Bit_Vec { unsigned char *buf; unsigned long cur_size; unsigned long max_size; }


decompiled_code:
char __fastcall Bit_Vec_add_byte(_QWORD *a1, unsigned __int8 a2)
{
int v2; // ebx
char result; // al

v2 = 7;
do
result = Bit_Vec_add_bit(a1, ((int)a2 >> v2) & 1);
while ( v2-- != 0 );
return result;
}

canonical_decompiled_code:
char __fastcall func4(_QWORD *a1, unsigned __int8 a2)
{
int v2; // ebx
char result; // al

v2 = 7;
do
result = func3(a1, ((int)a2 >> v2) & 1);
while ( v2-- != 0 );
return result;
}

original_code:
void Bit_Vec_add_byte(Bit_Vec *bv, uint8_t byte)
{
    for (int i = 7; i >= 0; i--) {
        Bit_Vec_add_bit(bv, (((byte) >> (i)) & 0x01));
    }
}

canonical_original_code:
void Bit_Vec_add_byte(struct Bit_Vec *bv, unsigned char byte)
{
    for (int i = 7; i >= 0; i--) {
        Bit_Vec_add_bit(bv, (((byte) >> (i)) & 0x01));
    }
}

variable_types:
byte
unsigned char

variable_types: i int


decompiled_code:
char __fastcall Bit_Vec_add_bytes(_QWORD *a1, unsigned __int8 *a2, __int64 a3)
{
unsigned __int8 *v3; // rbp
unsigned __int8 *v4; // rbx
unsigned __int8 v5; // si
char result; // al

if ( a3 )
{
v3 = &a2[a3];
v4 = a2;
do
{
v5 = *v4++;
result = Bit_Vec_add_byte(a1, v5);
}
while ( v3 != v4 );
}
return result;
}

canonical_decompiled_code:
char __fastcall func6(_QWORD *a1, unsigned __int8 *a2, __int64 a3)
{
unsigned __int8 *v3; // rbp
unsigned __int8 *v4; // rbx
unsigned __int8 v5; // si
char result; // al

if ( a3 )
{
v3 = &a2[a3];
v4 = a2;
do
{
v5 = *v4++;
result = func4(a1, v5);
}
while ( v3 != v4 );
}
return result;
}

original_code:
void Bit_Vec_add_bytes(Bit_Vec *bv, uint8_t *bytes, size_t size)
{
    for (size_t i = 0; i < size; i++) {
        Bit_Vec_add_byte(bv, bytes[i]);
    }
}

canonical_original_code:
void Bit_Vec_add_bytes(struct Bit_Vec *bv, unsigned char *bytes, unsigned long size)
{
    for (unsigned long i = 0; i < size; i++) {
        Bit_Vec_add_byte(bv, bytes[i]);
    }
}

variable_types:
bytes
unsigned char *

variable_types:
size
unsigned long

variable_types:
i
unsigned long


decompiled_code:
char __fastcall Bit_Vec_add_word(_QWORD *a1, unsigned __int16 a2)
{
int v2; // ebx
char result; // al

v2 = 15;
do
result = Bit_Vec_add_bit(a1, ((int)a2 >> v2) & 1);
while ( v2-- != 0 );
return result;
}

canonical_decompiled_code:
char __fastcall func7(_QWORD *a1, unsigned __int16 a2)
{
int v2; // ebx
char result; // al

v2 = 15;
do
result = func3(a1, ((int)a2 >> v2) & 1);
while ( v2-- != 0 );
return result;
}

original_code:
void Bit_Vec_add_word(Bit_Vec *bv, uint16_t word)
{
    for (int i = 15; i >= 0; i--) {
        Bit_Vec_add_bit(bv, (((word) >> (i)) & 0x0001));
    }
}

canonical_original_code:
void Bit_Vec_add_word(struct Bit_Vec *bv, unsigned short word)
{
    for (int i = 15; i >= 0; i--) {
        Bit_Vec_add_bit(bv, (((word) >> (i)) & 0x0001));
    }
}

variable_types:
word
unsigned short


decompiled_code:
__int64 __fastcall Bit_Vec_get_bit(_QWORD *a1, unsigned __int64 a2)
{
return ((int)*(unsigned __int8 *)(*a1 + (a2 >> 3)) >> (~(_BYTE)a2 & 7)) & 1;
}

canonical_decompiled_code:
__int64 __fastcall func9(_QWORD *a1, unsigned __int64 a2)
{
return ((int)*(unsigned __int8 *)(*a1 + (a2 >> 3)) >> (~(_BYTE)a2 & 7)) & 1;
}

original_code:
uint8_t Bit_Vec_get_bit(Bit_Vec *bv, size_t bit_pos)
{
    return (((bv->buf[bit_pos/8]) >> (7-bit_pos%8)) & 0x01);
}

canonical_original_code:
unsigned char Bit_Vec_get_bit(struct Bit_Vec *bv, unsigned long bit_pos)
{
    return (((bv->buf[bit_pos/8]) >> (7-bit_pos%8)) & 0x01);
}

return_type: unsigned char


decompiled_code:
void **__fastcall Bit_Vec_concat(__int64 a1, _QWORD *a2)
{
void **v3; // r12
unsigned __int64 v4; // rbx
unsigned __int64 v5; // rsi
char v6; // al

v3 = Bit_Vec_dup(a1);
if ( a2[1] )
{
v4 = 0LL;
do
{
v5 = v4++;
v6 = Bit_Vec_get_bit(a2, v5);
Bit_Vec_add_bit(v3, v6);
}
while ( a2[1] > v4 );
}
return v3;
}

canonical_decompiled_code:
void **__fastcall func10(__int64 a1, _QWORD *a2)
{
void **v3; // r12
unsigned __int64 v4; // rbx
unsigned __int64 v5; // rsi
char v6; // al

v3 = func1(a1);
if ( a2[1] )
{
v4 = 0LL;
do
{
v5 = v4++;
v6 = func9(a2, v5);
func3(v3, v6);
}
while ( a2[1] > v4 );
}
return v3;
}

original_code:
Bit_Vec* Bit_Vec_concat(Bit_Vec *bv1, Bit_Vec *bv2)
{
    Bit_Vec *new_bv = Bit_Vec_dup(bv1);
    for (size_t i = 0; i < bv2->cur_size; i++) {
        Bit_Vec_add_bit(new_bv, Bit_Vec_get_bit(bv2, i));
    }
    return new_bv;
}

canonical_original_code:
struct Bit_Vec *Bit_Vec_concat(struct Bit_Vec *bv1, struct Bit_Vec *bv2)
{
    struct Bit_Vec *new_bv = Bit_Vec_dup(bv1);
    for (unsigned long i = 0; i < bv2->cur_size; i++) {
        Bit_Vec_add_bit(new_bv, Bit_Vec_get_bit(bv2, i));
    }
    return new_bv;
}


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

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
return *(_QWORD *)(a1 + 8);
}

original_code:
size_t Bit_Vec_size(Bit_Vec *bv)
{
    return bv->cur_size;
}

canonical_original_code:
unsigned long Bit_Vec_size(struct Bit_Vec *bv)
{
    return bv->cur_size;
}

return_type: unsigned long


decompiled_code:
void __fastcall Bit_Vec_destroy(__int64 a1)
{
void *v1; // rdi

if ( a1 )
{
*(_QWORD *)(a1 + 8) = 0LL;
v1 = *(void **)a1;
if ( v1 )
free(v1);
}
}

canonical_decompiled_code:
void __fastcall func12(__int64 a1)
{
void *v1; // rdi

if ( a1 )
{
*(_QWORD *)(a1 + 8) = 0LL;
v1 = *(void **)a1;
if ( v1 )
free(v1);
}
}

original_code:
void Bit_Vec_destroy(Bit_Vec *bv)
{
    if (bv != ((void *)0)) {
        bv->cur_size = 0;
        if (bv->buf) {
            free(bv->buf);
        }
    }
}

canonical_original_code:
void Bit_Vec_destroy(struct Bit_Vec *bv)
{
    if (bv != ((void *)0)) {
        bv->cur_size = 0;
        if (bv->buf) {
            free(bv->buf);
        }
    }
}


decompiled_code:
void __fastcall __noreturn die_error(const char *a1)
{
fputs(a1, stderr);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(const char *a1)
{
fputs(a1, stderr);
exit(1);
}

original_code:
void die_error(char *msg)
{
    fprintf(stderr, "%s", msg);
    exit(1);
}

variable_types:
msg
char *


decompiled_code:
void *LZ_Element_new()
{
void *result; // rax

result = malloc(8uLL);
if ( !result )
{
die_error("ERROR-LZ_new_element] malloc on LZ_Element failed!\n");
result = 0LL;
}
return result;
}

canonical_decompiled_code:
void *func0()
{
void *result; // rax

result = malloc(8uLL);
if ( !result )
{
die_error("ERROR-LZ_new_element] malloc on LZ_Element failed!\n");
result = 0LL;
}
return result;
}

original_code:
LZ_Element* LZ_Element_new()
{
    LZ_Element *e = (LZ_Element*)malloc(sizeof(LZ_Element));
    if (e == ((void *)0)) {
        die_error("ERROR-LZ_new_element] malloc on LZ_Element failed!\n");
    }
    return e;
}

canonical_original_code:
struct __lz_element *LZ_Element_new()
{
    struct __lz_element *e = (LZ_Element*)malloc(sizeof(LZ_Element));
    if (e == ((void *)0)) {
        die_error("ERROR-LZ_new_element] malloc on LZ_Element failed!\n");
    }
    return e;
}

variable_types: struct __lz_element { union LZ_Value { unsigned char l; struct LZ_Pair { unsigned short distance; unsigned short length; } p; } value; enum LZ_Type { _LZ_LITERAL=0, _LZ_PAIR=1 } type; } *

user_defined_types: struct __lz_element { union LZ_Value value; enum LZ_Type type; }

user_defined_types: union LZ_Value { unsigned char l; struct LZ_Pair p; }


decompiled_code:
void __fastcall LZ_Element_set_literal(__int64 a1, char a2)
{
*(_DWORD *)(a1 + 4) = 0;
*(_BYTE *)a1 = a2;
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1, char a2)
{
*(_DWORD *)(a1 + 4) = 0;
*(_BYTE *)a1 = a2;
}

original_code:
void LZ_Element_set_literal(LZ_Element *e, LZ_Literal literal)
{
    e->type = _LZ_LITERAL;
    e->value.l = literal;
}

canonical_original_code:
void LZ_Element_set_literal(struct __lz_element *e, unsigned char literal)
{
    e->type = _LZ_LITERAL;
    e->value.l = literal;
}

variable_types:
literal
unsigned char

user_defined_types: enum LZ_Type { _LZ_LITERAL=0, _LZ_PAIR=1 }

user_defined_types: struct LZ_Pair { unsigned short distance; unsigned short length; }


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

if ( (unsigned __int16)a1 <= 0x8Fu )
return (unsigned int)(a1 + 48);
if ( (unsigned __int16)a1 <= 0xFFu )
return (unsigned int)(a1 + 256);
result = (unsigned int)(a1 - 256);
if ( (unsigned __int16)a1 > 0x117u )
result = (unsigned int)(a1 - 88);
return result;
}

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

if ( (unsigned __int16)a1 <= 0x8Fu )
return (unsigned int)(a1 + 48);
if ( (unsigned __int16)a1 <= 0xFFu )
return (unsigned int)(a1 + 256);
result = (unsigned int)(a1 - 256);
if ( (unsigned __int16)a1 > 0x117u )
result = (unsigned int)(a1 - 88);
return result;
}

original_code:
uint16_t Huffman_get_prefix_code(uint16_t edoc)
{
    if (edoc <= 143) return edoc_init_values[0] + edoc;
    else if (edoc <= 255) return edoc_init_values[1] + (edoc - 144);
    else if (edoc <= 279) return edoc_init_values[2] + (edoc - 256);
    else return edoc_init_values[3] + (edoc - 280);
}

canonical_original_code:
unsigned short Huffman_get_prefix_code(unsigned short edoc)
{
    if (edoc <= 143) return edoc_init_values[0] + edoc;
    else if (edoc <= 255) return edoc_init_values[1] + (edoc - 144);
    else if (edoc <= 279) return edoc_init_values[2] + (edoc - 256);
    else return edoc_init_values[3] + (edoc - 280);
}

variable_types:
edoc
unsigned short

return_type: unsigned short


decompiled_code:
__int64 __fastcall Huffman_get_edoc_length(unsigned __int16 a1)
{
__int64 result; // rax

result = 8LL;
if ( a1 > 0x8Fu )
{
result = 9LL;
if ( a1 > 0xFFu )
{
LOBYTE(result) = a1 > 0x117u;
result = (unsigned int)(result + 7);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int16 a1)
{
__int64 result; // rax

result = 8LL;
if ( a1 > 0x8Fu )
{
result = 9LL;
if ( a1 > 0xFFu )
{
LOBYTE(result) = a1 > 0x117u;
result = (unsigned int)(result + 7);
}
}
return result;
}

original_code:
uint8_t Huffman_get_edoc_length(uint16_t edoc)
{
    if (edoc <= 143) return edoc_length[0];
    else if (edoc <= 255) return edoc_length[1];
    else if (edoc <= 279) return edoc_length[2];
    else return edoc_length[3];
}

canonical_original_code:
unsigned char Huffman_get_edoc_length(unsigned short edoc)
{
    if (edoc <= 143) return edoc_length[0];
    else if (edoc <= 255) return edoc_length[1];
    else if (edoc <= 279) return edoc_length[2];
    else return edoc_length[3];
}


decompiled_code:
__int64 __fastcall Huffman_get_end_block_separator(__int64 a1)
{
return Bit_Vec_add_n_ls_bits_from_byte(a1, 0LL, 7LL);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
return Bit_Vec_add_n_ls_bits_from_byte(a1, 0LL, 7LL);
}

original_code:
void Huffman_get_end_block_separator(Bit_Vec *bv)
{
    Bit_Vec_add_n_ls_bits_from_byte(bv, 0x00, 7);
}

canonical_original_code:
void Huffman_get_end_block_separator(struct Bit_Vec *bv)
{
    Bit_Vec_add_n_ls_bits_from_byte(bv, 0x00, 7);
}


decompiled_code:
__int64 __fastcall Huffman_get_literal_code(unsigned __int8 a1)
{
unsigned __int16 v1; // ax
unsigned __int8 v2; // cl
__int64 v3; // r8

Huffman_get_edoc_length(a1);
v1 = Huffman_get_prefix_code(a1);
return Bit_Vec_add_n_ls_bits_from_word(v3, v1, v2);
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned __int8 a1)
{
unsigned __int16 v1; // ax
unsigned __int8 v2; // cl
__int64 v3; // r8

func1(a1);
v1 = func0(a1);
return Bit_Vec_add_n_ls_bits_from_word(v3, v1, v2);
}

original_code:
void Huffman_get_literal_code(uint8_t literal, Bit_Vec *bv)
{
    Bit_Vec_add_n_ls_bits_from_word(bv, Huffman_get_prefix_code(literal), Huffman_get_edoc_length(literal));
}

canonical_original_code:
void Huffman_get_literal_code(unsigned char literal, struct Bit_Vec *bv)
{
    Bit_Vec_add_n_ls_bits_from_word(bv, Huffman_get_prefix_code(literal), Huffman_get_edoc_length(literal));
}


decompiled_code:
__int64 __fastcall Huffman_get_length_code(unsigned __int16 a1, __int64 a2)
{
__int64 v3; // rax
unsigned __int16 i; // dx
int v5; // ebx
int v6; // ebx
int v7; // edi
unsigned __int16 v8; // ax
unsigned __int8 v9; // cl

if ( a1 <= 3u )
{
v5 = 0;
i = 3;
}
else
{
v3 = 1LL;
for ( i = 4; ; i = lens[v3] )
{
v5 = v3++;
if ( a1 <= i )
break;
}
}
v6 = v5 - (i != a1);
v7 = (unsigned __int16)(v6 + 257);
Huffman_get_edoc_length(v7);
v8 = Huffman_get_prefix_code(v7);
Bit_Vec_add_n_ls_bits_from_word(a2, v8, v9);
return Bit_Vec_add_n_ls_bits_from_word(a2, (unsigned __int16)(a1 - lens[v6]), (unsigned __int8)lext[v6]);
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned __int16 a1, __int64 a2)
{
__int64 v3; // rax
unsigned __int16 i; // dx
int v5; // ebx
int v6; // ebx
int v7; // edi
unsigned __int16 v8; // ax
unsigned __int8 v9; // cl

if ( a1 <= 3u )
{
v5 = 0;
i = 3;
}
else
{
v3 = 1LL;
for ( i = 4; ; i = lens[v3] )
{
v5 = v3++;
if ( a1 <= i )
break;
}
}
v6 = v5 - (i != a1);
v7 = (unsigned __int16)(v6 + 257);
func1(v7);
v8 = func0(v7);
Bit_Vec_add_n_ls_bits_from_word(a2, v8, v9);
return Bit_Vec_add_n_ls_bits_from_word(a2, (unsigned __int16)(a1 - lens[v6]), (unsigned __int8)lext[v6]);
}

original_code:
void Huffman_get_length_code(uint16_t length, Bit_Vec *bv)
{
    int i = 0;
    while (lens[i] < length && i < 29) i++;
    if (lens[i] != length) i--;
    Bit_Vec_add_n_ls_bits_from_word(bv, Huffman_get_prefix_code(257 + i), Huffman_get_edoc_length(257 + i));
    Bit_Vec_add_n_ls_bits_from_word(bv, length - lens[i], lext[i]);
}

canonical_original_code:
void Huffman_get_length_code(unsigned short length, struct Bit_Vec *bv)
{
    int i = 0;
    while (lens[i] < length && i < 29) i++;
    if (lens[i] != length) i--;
    Bit_Vec_add_n_ls_bits_from_word(bv, Huffman_get_prefix_code(257 + i), Huffman_get_edoc_length(257 + i));
    Bit_Vec_add_n_ls_bits_from_word(bv, length - lens[i], lext[i]);
}

variable_types:
length
unsigned short


decompiled_code:
__int64 __fastcall Huffman_get_distance_code(unsigned __int16 a1, __int64 a2)
{
__int64 v3; // rax
unsigned __int16 i; // dx
unsigned int v5; // ebx
__int64 v6; // rsi

if ( a1 <= 1u )
{
v5 = 0;
i = 1;
}
else
{
v3 = 1LL;
for ( i = 2; ; i = dists[v3] )
{
v5 = v3++;
if ( a1 <= i )
break;
}
}
v6 = v5;
if ( a1 != i )
v6 = (unsigned __int16)--v5;
Bit_Vec_add_n_ls_bits_from_word(a2, v6, 5LL);
return Bit_Vec_add_n_ls_bits_from_word(a2, (unsigned __int16)(a1 - dists[v5]), (unsigned __int8)dext[v5]);
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned __int16 a1, __int64 a2)
{
__int64 v3; // rax
unsigned __int16 i; // dx
unsigned int v5; // ebx
__int64 v6; // rsi

if ( a1 <= 1u )
{
v5 = 0;
i = 1;
}
else
{
v3 = 1LL;
for ( i = 2; ; i = dists[v3] )
{
v5 = v3++;
if ( a1 <= i )
break;
}
}
v6 = v5;
if ( a1 != i )
v6 = (unsigned __int16)--v5;
Bit_Vec_add_n_ls_bits_from_word(a2, v6, 5LL);
return Bit_Vec_add_n_ls_bits_from_word(a2, (unsigned __int16)(a1 - dists[v5]), (unsigned __int8)dext[v5]);
}

original_code:
void Huffman_get_distance_code(uint16_t distance, Bit_Vec *bv)
{
    int i = 0;
    while (dists[i] < distance && i < 30) i++;
    if (dists[i] != distance) i--;
    Bit_Vec_add_n_ls_bits_from_word(bv, i, 5);
    Bit_Vec_add_n_ls_bits_from_word(bv, distance - dists[i], dext[i]);
}

canonical_original_code:
void Huffman_get_distance_code(unsigned short distance, struct Bit_Vec *bv)
{
    int i = 0;
    while (dists[i] < distance && i < 30) i++;
    if (dists[i] != distance) i--;
    Bit_Vec_add_n_ls_bits_from_word(bv, i, 5);
    Bit_Vec_add_n_ls_bits_from_word(bv, distance - dists[i], dext[i]);
}

variable_types:
distance
unsigned short


decompiled_code:
__int64 __fastcall Hash_Table_reset(__int64 a1)
{
__int64 v1; // rbp
__int64 v2; // rbx
__int64 v3; // rdi
__int64 result; // rax

v1 = a1 + 327680;
v2 = a1;
do
{
v3 = v2;
v2 += 40LL;
result = Limited_List_destroy(v3);
}
while ( v2 != v1 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
__int64 v1; // rbp
__int64 v2; // rbx
__int64 v3; // rdi
__int64 result; // rax

v1 = a1 + 327680;
v2 = a1;
do
{
v3 = v2;
v2 += 40LL;
result = Limited_List_destroy(v3);
}
while ( v2 != v1 );
return result;
}

original_code:
void Hash_Table_reset(Hash_Table ht)
{
    for (size_t i = 0; i < 8192; i++) {
        Limited_List_destroy(&ht[i]);
    }
}

canonical_original_code:
void Hash_Table_reset(struct Limited_List *ht)
{
    for (unsigned long i = 0; i < 8192; i++) {
        Limited_List_destroy(&ht[i]);
    }
}


decompiled_code:
__int64 __fastcall ft_fill_name(__int64 a1, char *a2, int a3, int a4)
{
__int64 result; // rax
char v6; // dl
__int64 v7; // rdi
__int64 v8; // rcx

result = (int)read(a4, a2, 0x80uLL);
a2[(int)result] = 0;
v6 = *a2;
v7 = a1 + 2288LL * a3;
if ( *a2 )
{
result = 1LL;
do
{
*(_BYTE *)(v7 + result + 3) = v6;
v8 = (int)result++;
v6 = a2[result - 1];
}
while ( v6 );
*(_BYTE *)(v7 + v8 + 4) = 0;
}
else
{
*(_BYTE *)(v7 + 4) = 0;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, char *a2, int a3, int a4)
{
__int64 result; // rax
char v6; // dl
__int64 v7; // rdi
__int64 v8; // rcx

result = (int)read(a4, a2, 0x80uLL);
a2[(int)result] = 0;
v6 = *a2;
v7 = a1 + 2288LL * a3;
if ( *a2 )
{
result = 1LL;
do
{
*(_BYTE *)(v7 + result + 3) = v6;
v8 = (int)result++;
v6 = a2[result - 1];
}
while ( v6 );
*(_BYTE *)(v7 + v8 + 4) = 0;
}
else
{
*(_BYTE *)(v7 + 4) = 0;
}
return result;
}

original_code:
void ft_fill_name(t_proc players[], char *buf, int no, int fd)
{
 int i;
 int n;
 i = 0;
 n = read(fd, buf, (128));
 buf[n] = 0;
 while (buf[i] != 0)
 {
  players[no].header.prog_name[i] = buf[i];
  ++i;
 }
 players[no].header.prog_name[i] = 0;
}

canonical_original_code:
void ft_fill_name(struct s_proc players[], char *buf, int no, int fd)
{
 int i;
 int n;
 i = 0;
 n = read(fd, buf, (128));
 buf[n] = 0;
 while (buf[i] != 0)
 {
  players[no].header.prog_name[i] = buf[i];
  ++i;
 }
 players[no].header.prog_name[i] = 0;
}

variable_types: struct s_proc { struct s_header { unsigned int magic; char prog_name[-1]; unsigned int prog_size; char comment[-1]; } header; unsigned int mem_size; int reg[16]; char carry; char pc; char *arena; int nb_players; struct s_list { void *content; unsigned long content_size; struct s_list *next; } *proc_list; } []

variable_types:
buf
char *

variable_types: no int

variable_types: fd int

variable_types: n int

user_defined_types: struct s_proc { struct s_header header; unsigned int mem_size; int reg[16]; char carry; char pc; char *arena; int nb_players; struct s_list *proc_list; }


decompiled_code:
__int64 __fastcall ft_fill_comment(__int64 a1, char *a2, int a3, int a4)
{
__int64 result; // rax
char v6; // dl
__int64 v7; // rdi
__int64 v8; // rcx

result = (int)read(a4, a2, 0x800uLL);
a2[(int)result] = 0;
v6 = *a2;
v7 = a1 + 2288LL * a3;
if ( *a2 )
{
result = 1LL;
do
{
*(_BYTE *)(v7 + result + 139) = v6;
v8 = (int)result++;
v6 = a2[result - 1];
}
while ( v6 );
*(_BYTE *)(v7 + v8 + 140) = 0;
}
else
{
*(_BYTE *)(v7 + 140) = 0;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, char *a2, int a3, int a4)
{
__int64 result; // rax
char v6; // dl
__int64 v7; // rdi
__int64 v8; // rcx

result = (int)read(a4, a2, 0x800uLL);
a2[(int)result] = 0;
v6 = *a2;
v7 = a1 + 2288LL * a3;
if ( *a2 )
{
result = 1LL;
do
{
*(_BYTE *)(v7 + result + 139) = v6;
v8 = (int)result++;
v6 = a2[result - 1];
}
while ( v6 );
*(_BYTE *)(v7 + v8 + 140) = 0;
}
else
{
*(_BYTE *)(v7 + 140) = 0;
}
return result;
}

original_code:
void ft_fill_comment(t_proc players[], char *buf, int no, int fd)
{
 int i;
 int n;
 i = 0;
 n = read(fd, buf, (2048));
 buf[n] = 0;
 while (buf[i] != 0)
 {
  players[no].header.comment[i] = buf[i];
  ++i;
 }
 players[no].header.comment[i] = 0;
}

canonical_original_code:
void ft_fill_comment(struct s_proc players[], char *buf, int no, int fd)
{
 int i;
 int n;
 i = 0;
 n = read(fd, buf, (2048));
 buf[n] = 0;
 while (buf[i] != 0)
 {
  players[no].header.comment[i] = buf[i];
  ++i;
 }
 players[no].header.comment[i] = 0;
}

user_defined_types: struct s_header { unsigned int magic; char prog_name[-1]; unsigned int prog_size; char comment[-1]; }

user_defined_types: struct s_list { void *content; unsigned long content_size; struct s_list *next; }


decompiled_code:
__int64 __fastcall ft_fill_memsize(__int64 a1, char *a2, int a3, int a4)
{
__int64 result; // rax
int v6; // edx
__int64 v7; // rdi

read(a4, a2, 8uLL);
result = 0LL;
v6 = 0;
v7 = a1 + 2288LL * a3;
*(_DWORD *)(v7 + 2192) = 0;
while ( result == 6 )
{
v6 += a2[6] << 8;
*(_DWORD *)(v7 + 2192) = v6;
LABEL_3:
++result;
}
v6 += a2[result];
*(_DWORD *)(v7 + 2192) = v6;
if ( result != 7 )
goto LABEL_3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, char *a2, int a3, int a4)
{
__int64 result; // rax
int v6; // edx
__int64 v7; // rdi

read(a4, a2, 8uLL);
result = 0LL;
v6 = 0;
v7 = a1 + 2288LL * a3;
*(_DWORD *)(v7 + 2192) = 0;
while ( result == 6 )
{
v6 += a2[6] << 8;
*(_DWORD *)(v7 + 2192) = v6;
LABEL_3:
++result;
}
v6 += a2[result];
*(_DWORD *)(v7 + 2192) = v6;
if ( result != 7 )
goto LABEL_3;
return result;
}

original_code:
void ft_fill_memsize(t_proc players[], char *buf, int no, int fd)
{
 int i;
 int n;
 i = 0;
 n = read(fd, buf, 8);
 players[no].mem_size = 0;
 while (i < 8)
 {
  if (i == 6)
   players[no].mem_size += ((unsigned int) buf[i]) << 8;
  else
   players[no].mem_size += (unsigned int) buf[i];
  ++i;
 }
}

canonical_original_code:
void ft_fill_memsize(struct s_proc players[], char *buf, int no, int fd)
{
 int i;
 int n;
 i = 0;
 n = read(fd, buf, 8);
 players[no].mem_size = 0;
 while (i < 8)
 {
  if (i == 6)
   players[no].mem_size += ((unsigned int) buf[i]) << 8;
  else
   players[no].mem_size += (unsigned int) buf[i];
  ++i;
 }
}


original_code:
void ft_print_champion(t_proc players)
{
 ft_putstr("Champion ");
 ft_putnbr(players.reg[0]);
 ft_putstr(" : ");
 ft_putstr(players.header.prog_name);
 ft_putstr("\nComment : ");
 ft_putstr(players.header.comment);
 ft_putstr("\n\n");
}

canonical_original_code:
void ft_print_champion(struct s_proc players)
{
 ft_putstr("Champion ");
 ft_putnbr(players.reg[0]);
 ft_putstr(" : ");
 ft_putstr(players.header.prog_name);
 ft_putstr("\nComment : ");
 ft_putstr(players.header.comment);
 ft_putstr("\n\n");
}

variable_types: struct s_proc { struct s_header { unsigned int magic; char prog_name[-1]; unsigned int prog_size; char comment[-1]; } header; unsigned int mem_size; int reg[16]; char carry; char pc; char *arena; int nb_players; struct s_list { void *content; unsigned long content_size; struct s_list *next; } *proc_list; }


decompiled_code:
int __fastcall ft_access(const char *a1)
{
int result; // eax

result = open(a1, 0);
if ( result < 0 )
{
ft_putstr(a1);
ft_putendl(": Couldn't open that file. Stopping.");
exit(1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(const char *a1)
{
int result; // eax

result = open(a1, 0);
if ( result < 0 )
{
ft_putstr(a1);
ft_putendl(": Couldn't open that file. Stopping.");
exit(1);
}
return result;
}

original_code:
int ft_access(char *str)
{
 int fd;
 if ((fd = open(str, 00)) < 0)
 {
  ft_putstr(str);
  ft_putendl(": Couldn't open that file. Stopping.");
  exit(1);
 }
 return (fd);
}

variable_types:
str
char *

return_type: int


original_code:
void ft_add_player(t_proc players[], int fd, char arena[], int nb_players)
{
 static int no = 0;
 int n;
 char *buf;
 int i;
 i = 0;
 players[no].nb_players = nb_players;
 buf = (char *) malloc(sizeof(char) * 4097);
 n = read(fd, buf, 4);
 buf[n] = 0;
 if (buf[1] != (char)(0xea83f3 >> 16) || buf[2] != (char)((0xea83f3 & 65280) >> 8) || buf[3] != (char)(0xea83f3 & 255))
 {
  ft_putendl(": incorrect magic number, stopping. D:");
  exit(2);
 }
 ft_fill_name(players, buf, (int)no, fd);
 ft_fill_memsize(players, buf, (int)no, fd);
 ft_fill_comment(players, buf, (int)no, fd);
 players[no].arena = arena;
 ft_fill_arena(players, buf, (int)no, fd);
 ft_print_champion(players[no]);
 ++no;
}

canonical_original_code:
void ft_add_player(struct s_proc players[], int fd, char arena[], int nb_players)
{
 static int no = 0;
 int n;
 char *buf;
 int i;
 i = 0;
 players[no].nb_players = nb_players;
 buf = (char *) malloc(sizeof(char) * 4097);
 n = read(fd, buf, 4);
 buf[n] = 0;
 if (buf[1] != (char)(0xea83f3 >> 16) || buf[2] != (char)((0xea83f3 & 65280) >> 8) || buf[3] != (char)(0xea83f3 & 255))
 {
  ft_putendl(": incorrect magic number, stopping. D:");
  exit(2);
 }
 ft_fill_name(players, buf, (int)no, fd);
 ft_fill_memsize(players, buf, (int)no, fd);
 ft_fill_comment(players, buf, (int)no, fd);
 players[no].arena = arena;
 ft_fill_arena(players, buf, (int)no, fd);
 ft_print_champion(players[no]);
 ++no;
}

variable_types:
arena
char []

variable_types: i int


decompiled_code:
void __fastcall ft_init_players(__int64 a1, int a2, __int64 a3, __int64 a4)
{
int v4; // er15
const char **v6; // rbp
int v7; // ebx
int v8; // er14

if ( a2 > 1 )
{
v4 = 0;
v6 = (const char **)(a3 + 8);
v7 = a2 - 1;
do
{
if ( **v6 != 45 )
{
if ( !v4 )
v4 = v7;
v8 = ft_access(*v6);
ft_add_player(a1, v8, a4, v4);
close(v8);
}
++v6;
--v7;
}
while ( v7 );
}
}

original_code:
void ft_init_players(t_proc players[], int argc, char *argv[], char arena[])
{
 int i;
 int fd;
 int nb;
 i = 1;
 nb = 0;
 while (i < argc)
 {
  if (argv[i][0] != '-')
  {
   if (nb == 0)
    nb = argc - i;
   fd = ft_access(argv[i]);
   ft_add_player(players, fd, arena, nb);
   close(fd);
  }
  ++i;
 }
}

canonical_original_code:
void ft_init_players(struct s_proc players[], int argc, char *argv[], char arena[])
{
 int i;
 int fd;
 int nb;
 i = 1;
 nb = 0;
 while (i < argc)
 {
  if (argv[i][0] != '-')
  {
   if (nb == 0)
    nb = argc - i;
   fd = ft_access(argv[i]);
   ft_add_player(players, fd, arena, nb);
   close(fd);
  }
  ++i;
 }
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: nb int


decompiled_code:
__int64 __fastcall ft_init(_QWORD *a1, __int64 a2, unsigned int a3, __int64 a4)
{
unsigned __int64 v5; // rdi

*a1 = 0LL;
v5 = (unsigned __int64)(a1 + 1);
*(_QWORD *)(v5 + 4080) = 0LL;
memset((void *)(v5 & 0xFFFFFFFFFFFFFFF8LL), 0, 8 * (((unsigned int)a1 - (v5 & 0xFFFFFFF8) + 4096) >> 3));
return ft_init_players(a2, a3, a4, a1);
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1, __int64 a2, unsigned int a3, __int64 a4)
{
unsigned __int64 v5; // rdi

*a1 = 0LL;
v5 = (unsigned __int64)(a1 + 1);
*(_QWORD *)(v5 + 4080) = 0LL;
memset((void *)(v5 & 0xFFFFFFFFFFFFFFF8LL), 0, 8 * (((unsigned int)a1 - (v5 & 0xFFFFFFF8) + 4096) >> 3));
return ft_init_players(a2, a3, a4, a1);
}

original_code:
void ft_init(char arena[], t_proc players[], int argc, char *argv[])
{
 int i;
 i = 0;
 while (i < (4*1024))
  arena[i++] = 0;
 ft_init_players(players, argc, argv, arena);
}

canonical_original_code:
void ft_init(char arena[], struct s_proc players[], int argc, char *argv[])
{
 int i;
 i = 0;
 while (i < (4*1024))
  arena[i++] = 0;
 ft_init_players(players, argc, argv, arena);
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v4; // [rsp-1000h] [rbp-33C8h] BYREF
char v5[9160]; // [rsp+0h] [rbp-23C8h] BYREF

if ( argc > 1 )
ft_init(&v4, (__int64)v5, argc, (__int64)argv);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v4; // [rsp-1000h] [rbp-33C8h] BYREF
char v5[9160]; // [rsp+0h] [rbp-23C8h] BYREF

if ( argc > 1 )
func0(&v4, (__int64)v5, argc, (__int64)argv);
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 char arena[(4*1024)];
 t_proc players[4];
 if (argc > 1)
  ft_init(arena, players, argc, argv);
 return (0);
}

canonical_original_code:
int main(int argc, char *argv[])
{
 char arena[-1];
 struct s_proc players[4];
 if (argc > 1)
  ft_init(arena, players, argc, argv);
 return (0);
}

variable_types:
arena
char [-1]

variable_types: struct s_proc { struct s_header { unsigned int magic; char prog_name[-1]; unsigned int prog_size; char comment[-1]; } header; unsigned int mem_size; int reg[16]; char carry; char pc; char *arena; int nb_players; struct s_list { void *content; unsigned long content_size; struct s_list *next; } *proc_list; } [4]


repo: GurniHelek/test

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

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

original_code:
int main()
{
    test_parser();
    return 0;
}

canonical_original_code:
int main()
{
    test_parser();
    return 0;
}


decompiled_code:
char *test_parser()
{
char *result; // rax
const char *v1; // rbx
__int64 v2; // rax
__int64 v3; // rax
__int128 v4; // [rsp+0h] [rbp-78h] BYREF
char s[16]; // [rsp+10h] [rbp-68h] BYREF
__m128i v6; // [rsp+20h] [rbp-58h]
__m128i v7; // [rsp+30h] [rbp-48h]
__m128i v8; // [rsp+40h] [rbp-38h]
__m128i v9; // [rsp+50h] [rbp-28h]
char v10[16]; // [rsp+60h] [rbp-18h] BYREF

strcpy(v10, "45673 : 1024\n");
*(__m128i *)s = _mm_load_si128((const __m128i *)&xmmword_402030);
v6 = _mm_load_si128((const __m128i *)&xmmword_402040);
v7 = _mm_load_si128((const __m128i *)&xmmword_402050);
v8 = _mm_load_si128((const __m128i *)&xmmword_402060);
v9 = _mm_load_si128((const __m128i *)&xmmword_402070);
v4 = 0LL;
puts(s);
result = strtok(s, "\n");
if ( result )
{
v1 = result;
do
{
puts(v1);
strncpy((char *)&v4, v1, 0xAuLL);
v2 = strtol((const char *)&v4, 0LL, 16);
printf("start_addr : 0x%08lx\n", v2);
strncpy((char *)&v4, v1 + 13, 0xAuLL);
v3 = strtol((const char *)&v4, 0LL, 16);
printf("end_addr : 0x%08lx\n", v3);
result = strtok(0LL, "\n");
v1 = result;
}
while ( result );
}
return result;
}

canonical_decompiled_code:
char *func7()
{
char *result; // rax
const char *v1; // rbx
__int64 v2; // rax
__int64 v3; // rax
__int128 v4; // [rsp+0h] [rbp-78h] BYREF
char s[16]; // [rsp+10h] [rbp-68h] BYREF
__m128i v6; // [rsp+20h] [rbp-58h]
__m128i v7; // [rsp+30h] [rbp-48h]
__m128i v8; // [rsp+40h] [rbp-38h]
__m128i v9; // [rsp+50h] [rbp-28h]
char v10[16]; // [rsp+60h] [rbp-18h] BYREF

strcpy(v10, "45673 : 1024\n");
*(__m128i *)s = _mm_load_si128((const __m128i *)&xmmword_402030);
v6 = _mm_load_si128((const __m128i *)&xmmword_402040);
v7 = _mm_load_si128((const __m128i *)&xmmword_402050);
v8 = _mm_load_si128((const __m128i *)&xmmword_402060);
v9 = _mm_load_si128((const __m128i *)&xmmword_402070);
v4 = 0LL;
puts(s);
result = strtok(s, "\n");
if ( result )
{
v1 = result;
do
{
puts(v1);
strncpy((char *)&v4, v1, 0xAuLL);
v2 = strtol((const char *)&v4, 0LL, 16);
printf("start_addr : 0x%08lx\n", v2);
strncpy((char *)&v4, v1 + 13, 0xAuLL);
v3 = strtol((const char *)&v4, 0LL, 16);
printf("end_addr : 0x%08lx\n", v3);
result = strtok(0LL, "\n");
v1 = result;
}
while ( result );
}
return result;
}

original_code:
void test_parser()
{
    char test_str[] = "0x0eadc0de - 0x13245671 : 1024\n0xdeadc0de - 0x13245672 : 1024\n0xdeadc0de - 0x13245673 : 1024\n";
    char* token = ((void *)0);
    char str_addr[16] = {0};
    printf("%s\n", test_str);
    token = strtok(test_str, "\n");
    while(token != ((void *)0))
    {
        printf("%s\n", token);
        strncpy(str_addr, token, 10);
        printf("start_addr : 0x%08lx\n", (long) strtol(str_addr, ((void *)0), 16));
        strncpy(str_addr, token + 13, 10);
        printf("end_addr : 0x%08lx\n", (long) strtol(str_addr, ((void *)0), 16));
        token = strtok(((void *)0), "\n");
    }
}

canonical_original_code:
void test_parser()
{
    char test_str[] = "0x0eadc0de - 0x13245671 : 1024\n0xdeadc0de - 0x13245672 : 1024\n0xdeadc0de - 0x13245673 : 1024\n";
    char *token = ((void *)0);
    char str_addr[16] = {0};
    printf("%s\n", test_str);
    token = strtok(test_str, "\n");
    while(token != ((void *)0))
    {
        printf("%s\n", token);
        strncpy(str_addr, token, 10);
        printf("start_addr : 0x%08lx\n", (long) strtol(str_addr, ((void *)0), 16));
        strncpy(str_addr, token + 13, 10);
        printf("end_addr : 0x%08lx\n", (long) strtol(str_addr, ((void *)0), 16));
        token = strtok(((void *)0), "\n");
    }
}

variable_types:
token
char *


setPort

repo: Guzunty/Pi

decompiled_code:
int __fastcall setPort(__int16 a1, __int16 a2)
{
int result; // eax

if ( a2 == 1 )
{
switch ( a1 )
{
case 1:
result = gpio;
*(_DWORD *)(gpio + 28LL) = 0x1000000;
break;
case 2:
result = gpio;
*(_DWORD *)(gpio + 28LL) = 0x800000;
break;
case 0:
result = gpio;
*(_DWORD *)(gpio + 28LL) = 0x20000;
break;
}
}
else
{
switch ( a1 )
{
case 1:
result = gpio;
*(_DWORD *)(gpio + 40LL) = 0x1000000;
break;
case 2:
result = gpio;
*(_DWORD *)(gpio + 40LL) = 0x800000;
break;
case 0:
*(_DWORD *)(gpio + 40LL) = 0x20000;
result = usleep(1u);
break;
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(__int16 a1, __int16 a2)
{
int result; // eax

if ( a2 == 1 )
{
switch ( a1 )
{
case 1:
result = gpio;
*(_DWORD *)(gpio + 28LL) = 0x1000000;
break;
case 2:
result = gpio;
*(_DWORD *)(gpio + 28LL) = 0x800000;
break;
case 0:
result = gpio;
*(_DWORD *)(gpio + 28LL) = 0x20000;
break;
}
}
else
{
switch ( a1 )
{
case 1:
result = gpio;
*(_DWORD *)(gpio + 40LL) = 0x1000000;
break;
case 2:
result = gpio;
*(_DWORD *)(gpio + 40LL) = 0x800000;
break;
case 0:
*(_DWORD *)(gpio + 40LL) = 0x20000;
result = usleep(1u);
break;
}
}
return result;
}

variable_types: p short

variable_types: val short


pulseClock

decompiled_code:
int pulseClock()
{
setPort(0, 0);
return setPort(0, 1);
}

canonical_decompiled_code:
int func1()
{
func0(0, 0);
return func0(0, 1);
}

original_code:
void pulseClock()
{
    setPort((short) 0,0);
    setPort((short) 0,1);
}


readTDOBit

decompiled_code:
__int64 readTDOBit()
{
return (*(_DWORD *)(gpio + 52LL) >> 22) & 1;
}

original_code:
unsigned char readTDOBit()
{
 if((*(gpio+13)&(1<<22))) {
  return( (unsigned char) 1 );
 }
 else {
  return( (unsigned char) 0 );
 }
}


decompiled_code:
int __fastcall output_error(int a1)
{
return printf("\n%s\n", *((const char **)&xsvf_pzErrorName + a1));
}

canonical_decompiled_code:
int __fastcall func4(int a1)
{
return printf("\n%s\n", *((const char **)&xsvf_pzErrorName + a1));
}

original_code:
void output_error(int error_code) {
 printf("\n%s\n",xsvf_pzErrorName[error_code]);
}


waitTime

decompiled_code:
int __fastcall waitTime(__int64 a1)
{
struct timespec v2; // [rsp+0h] [rbp-28h] BYREF
struct timespec remaining; // [rsp+10h] [rbp-18h] BYREF

setPort(0, 0);
v2.tv_nsec = 1000 * a1;
v2.tv_sec = 0LL;
return nanosleep(&v2, &remaining);
}

canonical_decompiled_code:
int __fastcall func5(__int64 a1)
{
struct timespec v2; // [rsp+0h] [rbp-28h] BYREF
struct timespec remaining; // [rsp+10h] [rbp-18h] BYREF

func0(0, 0);
v2.tv_nsec = 1000 * a1;
v2.tv_sec = 0LL;
return nanosleep(&v2, &remaining);
}

original_code:
void waitTime(long microsec)
{
 struct timespec ts, dummy;
    setPort((short) 0, 0);
    ts.tv_sec = 0;
    ts.tv_nsec = microsec * 1000L;
    nanosleep(&ts, &dummy);
}

canonical_original_code:
void waitTime(long microsec)
{
 struct timespec ts; struct timespec dummy;
    setPort((short) 0, 0);
    ts.tv_sec = 0;
    ts.tv_nsec = microsec * 1000L;
    nanosleep(&ts, &dummy);
}

variable_types: microsec long

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


decompiled_code:
__int64 setup_io()
{
int v0; // edi
__off_t v1; // r9
__int64 result; // rax
char v3[4120]; // [rsp+0h] [rbp-1018h] BYREF

mem_fd = open("/dev/mem", 1052674);
if ( mem_fd < 0 )
{
puts("\rError initializing IO. Consider using sudo.");
exit(-1);
}
v0 = open("/proc/cpuinfo", 1052672);
if ( v0 < 0 )
{
v1 = peri_base + 0x200000LL;
}
else
{
read(v0, v3, 0x1000uLL);
if ( strstr(v3, "BCM2708") )
{
v1 = 538968064LL;
peri_base = 0x20000000LL;
}
else
{
if ( !strstr(v3, "BCM2709") )
{
puts("\rERROR: Could not identify Pi peripheral model.");
exit(-1);
}
v1 = 1059061760LL;
peri_base = 1056964608LL;
}
}
gpio_map = mmap(0LL, 0x1000uLL, 3, 1, mem_fd, v1);
close(mem_fd);
result = gpio_map;
if ( gpio_map == -1LL )
{
printf("mmap error %d\n", 0xFFFFFFFFLL);
exit(-1);
}
gpio = gpio_map;
return result;
}

canonical_decompiled_code:
__int64 func6()
{
int v0; // edi
__off_t v1; // r9
__int64 result; // rax
char v3[4120]; // [rsp+0h] [rbp-1018h] BYREF

mem_fd = open("/dev/mem", 1052674);
if ( mem_fd < 0 )
{
puts("\rError initializing IO. Consider using sudo.");
exit(-1);
}
v0 = open("/proc/cpuinfo", 1052672);
if ( v0 < 0 )
{
v1 = peri_base + 0x200000LL;
}
else
{
read(v0, v3, 0x1000uLL);
if ( strstr(v3, "BCM2708") )
{
v1 = 538968064LL;
peri_base = 0x20000000LL;
}
else
{
if ( !strstr(v3, "BCM2709") )
{
puts("\rERROR: Could not identify Pi peripheral model.");
exit(-1);
}
v1 = 1059061760LL;
peri_base = 1056964608LL;
}
}
gpio_map = mmap(0LL, 0x1000uLL, 3, 1, mem_fd, v1);
close(mem_fd);
result = gpio_map;
if ( gpio_map == -1LL )
{
printf("mmap error %d\n", 0xFFFFFFFFLL);
exit(-1);
}
gpio = gpio_map;
return result;
}

original_code:
void setup_io()
{
 int proc_fd;
 char cpu_info[4096];
   if ((mem_fd = open("/dev/mem", 02|04010000) ) < 0) {
      printf("\rError initializing IO. Consider using sudo.\n");
      exit(-1);
   }
   if ((proc_fd = open("/proc/cpuinfo", 00|04010000) ) >= 0) {
      read(proc_fd, cpu_info, sizeof cpu_info);
      if (strstr(cpu_info, "BCM2708")) {
         peri_base = 0x20000000;
      } else if (strstr(cpu_info, "BCM2709")) {
         peri_base = 0x3f000000;
      } else {
         printf("\rERROR: Could not identify Pi peripheral model.\n");
         exit(-1);
      }
   }
   gpio_map = mmap(
      ((void *)0),
      (4*1024),
      0x1|0x2,
      0x01,
      mem_fd,
      (peri_base + 0x200000)
   );
   close(mem_fd);
   if (gpio_map == ((void *) -1)) {
      printf("mmap error %d\n", (int)gpio_map);
      exit(-1);
   }
   gpio = (volatile unsigned *)gpio_map;
}

canonical_original_code:
void setup_io()
{
 int proc_fd;
 char cpu_info[4096];
   if ((mem_fd = open("/dev/mem", 02|04010000) ) < 0) {
      printf("\rError initializing IO. Consider using sudo.\n");
      exit(-1);
   }
   if ((proc_fd = open("/proc/cpuinfo", 00|04010000) ) >= 0) {
      read(proc_fd, cpu_info, sizeof cpu_info);
      if (strstr(cpu_info, "BCM2708")) {
         peri_base = 0x20000000;
      } else if (strstr(cpu_info, "BCM2709")) {
         peri_base = 0x3f000000;
      } else {
         printf("\rERROR: Could not identify Pi peripheral model.\n");
         exit(-1);
      }
   }
   gpio_map = mmap(
      ((void *)0),
      (4*1024),
      0x1|0x2,
      0x01,
      mem_fd,
      (peri_base + 0x200000)
   );
   close(mem_fd);
   if (gpio_map == ((void *) -1)) {
      printf("mmap error %d\n", (int)gpio_map);
      exit(-1);
   }
   gpio = (unsigned int *)gpio_map;
}


portsInitialize

decompiled_code:
__int64 portsInitialize()
{
__int64 result; // rax
int v1; // edx
int v2; // edx
int v3; // edx
int v4; // edx

setup_io();
result = gpio;
v1 = *(_DWORD *)(gpio + 8LL);
BYTE1(v1) &= 0xF1u;
*(_DWORD *)(gpio + 8LL) = v1;
*(_DWORD *)(result + 4) &= 0xFF1FFFFF;
v2 = *(_DWORD *)(result + 8);
BYTE1(v2) &= 0x8Fu;
*(_DWORD *)(result + 8) = v2;
*(_DWORD *)(result + 8) &= 0xFFFFFE3F;
v3 = *(_DWORD *)(result + 8);
BYTE1(v3) |= 2u;
*(_DWORD *)(result + 8) = v3;
*(_DWORD *)(result + 4) |= 0x200000u;
v4 = *(_DWORD *)(result + 8);
BYTE1(v4) |= 0x10u;
*(_DWORD *)(result + 8) = v4;
return result;
}

canonical_decompiled_code:
__int64 func7()
{
__int64 result; // rax
int v1; // edx
int v2; // edx
int v3; // edx
int v4; // edx

func6();
result = gpio;
v1 = *(_DWORD *)(gpio + 8LL);
BYTE1(v1) &= 0xF1u;
*(_DWORD *)(gpio + 8LL) = v1;
*(_DWORD *)(result + 4) &= 0xFF1FFFFF;
v2 = *(_DWORD *)(result + 8);
BYTE1(v2) &= 0x8Fu;
*(_DWORD *)(result + 8) = v2;
*(_DWORD *)(result + 8) &= 0xFFFFFE3F;
v3 = *(_DWORD *)(result + 8);
BYTE1(v3) |= 2u;
*(_DWORD *)(result + 8) = v3;
*(_DWORD *)(result + 4) |= 0x200000u;
v4 = *(_DWORD *)(result + 8);
BYTE1(v4) |= 0x10u;
*(_DWORD *)(result + 8) = v4;
return result;
}


decompiled_code:
__int64 __fastcall gz_output_get(int a1)
{
if ( width < a1 >> 3 )
{
printf("Bit %d is out of range.", (unsigned int)a1);
exit(-1);
}
return ((int)spi_cache[a1 >> 3] >> (a1 & 7)) & 1;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
if ( width < a1 >> 3 )
{
printf("Bit %d is out of range.", (unsigned int)a1);
exit(-1);
}
return ((int)spi_cache[a1 >> 3] >> (a1 & 7)) & 1;
}

original_code:
int gz_output_get(int bit_to_read) {
  int byte_cnt = bit_to_read >> 3;
  if (byte_cnt > width) {
 printf("Bit %d is out of range.", bit_to_read);
 exit(-1);
  }
  else {
    return 0 == (spi_cache[byte_cnt] & (1 << (bit_to_read & 0x7))) ? 0 : 1;
  }
  return 0;
}


decompiled_code:
__int64 __fastcall spi_open(const char *a1)
{
int v1; // eax
__int64 result; // rax
int v3; // [rsp+4h] [rbp-24h] BYREF
int v4; // [rsp+8h] [rbp-20h] BYREF
int v5[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v3 = 0;
v4 = 8;
v5[0] = 10000000;
v1 = open(a1, 2);
spi_fd = v1;
if ( v1 < 0 )
{
printf("error opening %s\n", a1);
result = 0xFFFFFFFFLL;
}
else if ( ioctl(v1, 0x40016B01uLL, &v3) < 0 || ioctl(spi_fd, 0x40016B03uLL, &v4) < 0 )
{
result = 0xFFFFFFFFLL;
}
else
{
result = (unsigned int)(ioctl(spi_fd, 0x40046B04uLL, v5) >> 31);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1)
{
int v1; // eax
__int64 result; // rax
int v3; // [rsp+4h] [rbp-24h] BYREF
int v4; // [rsp+8h] [rbp-20h] BYREF
int v5[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v3 = 0;
v4 = 8;
v5[0] = 10000000;
v1 = open(a1, 2);
spi_fd = v1;
if ( v1 < 0 )
{
printf("error opening %s\n", a1);
result = 0xFFFFFFFFLL;
}
else if ( ioctl(v1, 0x40016B01uLL, &v3) < 0 || ioctl(spi_fd, 0x40016B03uLL, &v4) < 0 )
{
result = 0xFFFFFFFFLL;
}
else
{
result = (unsigned int)(ioctl(spi_fd, 0x40046B04uLL, v5) >> 31);
}
return result;
}

variable_types:
dev
char *


decompiled_code:
void *gz_spi_initialize()
{
void *result; // rax

spi_open("/dev/spidev0.0");
result = &initialized;
initialized = 1;
return result;
}

canonical_decompiled_code:
void *func2()
{
void *result; // rax

func1("/dev/spidev0.0");
result = &initialized;
initialized = 1;
return result;
}

original_code:
void gz_spi_initialize() {
  spi_open("/dev/spidev0.0");
  initialized = 1;
}


decompiled_code:
__int64 __fastcall gz_spi_open_port(const char *a1)
{
__int64 result; // rax

result = spi_open(a1);
initialized = 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(const char *a1)
{
__int64 result; // rax

result = func1(a1);
initialized = 1;
return result;
}

original_code:
int gz_spi_open_port(char * port) {
  int result;
  result = spi_open(port);
  initialized = 1;
  return result;
}

canonical_original_code:
int gz_spi_open_port(char *port) {
  int result;
  result = spi_open(port);
  initialized = 1;
  return result;
}

variable_types:
port
char *

variable_types: result int


transfer

decompiled_code:
void *__fastcall transfer(_QWORD *a1, __int16 a2)
{
char v2; // r8
int *v4; // rax
char *v5; // rax
_BYTE v6[12]; // [rsp+Ch] [rbp-2Ch] BYREF
void *v7; // [rsp+18h] [rbp-20h]
int v8; // [rsp+20h] [rbp-18h]
int v9; // [rsp+24h] [rbp-14h]
__int16 v10; // [rsp+28h] [rbp-10h]
char v11; // [rsp+2Ah] [rbp-Eh]
int v12; // [rsp+2Bh] [rbp-Dh]
char v13; // [rsp+2Fh] [rbp-9h]

v2 = width;
if ( width > 0 )
{
if ( (unsigned int)width >= 8 )
{
*(_QWORD *)v6 = *a1;
*(_QWORD *)&v6[width - 8] = *(_QWORD *)((char *)a1 + (unsigned int)width - 8);
qmemcpy(&v6[4], (char *)a1 - (v6 - &v6[4]), 8LL * ((v2 + (unsigned int)(v6 - &v6[4])) >> 3));
}
else if ( (width & 4) != 0 )
{
*(_DWORD *)v6 = *(_DWORD *)a1;
*(_DWORD *)&v6[width - 4] = *(_DWORD *)((char *)a1 + (unsigned int)width - 4);
}
else if ( width )
{
v6[0] = *(_BYTE *)a1;
if ( (width & 2) != 0 )
*(_WORD *)&v6[width - 2] = *(_WORD *)((char *)a1 + (unsigned int)width - 2);
}
}
v8 = v2;
v12 = 0;
v13 = 0;
*(_QWORD *)&v6[4] = v6;
v7 = &inbuf;
v10 = a2;
v9 = 10000000;
v11 = 8;
if ( ioctl(spi_fd, 0x40206B00uLL, &v6[4]) < 0 )
{
v4 = _errno_location();
v5 = strerror(*v4);
printf("spi: ERROR while sending - %s\r\n", v5);
}
return &inbuf;
}

canonical_decompiled_code:
void *__fastcall func4(_QWORD *a1, __int16 a2)
{
char v2; // r8
int *v4; // rax
char *v5; // rax
_BYTE v6[12]; // [rsp+Ch] [rbp-2Ch] BYREF
void *v7; // [rsp+18h] [rbp-20h]
int v8; // [rsp+20h] [rbp-18h]
int v9; // [rsp+24h] [rbp-14h]
__int16 v10; // [rsp+28h] [rbp-10h]
char v11; // [rsp+2Ah] [rbp-Eh]
int v12; // [rsp+2Bh] [rbp-Dh]
char v13; // [rsp+2Fh] [rbp-9h]

v2 = width;
if ( width > 0 )
{
if ( (unsigned int)width >= 8 )
{
*(_QWORD *)v6 = *a1;
*(_QWORD *)&v6[width - 8] = *(_QWORD *)((char *)a1 + (unsigned int)width - 8);
qmemcpy(&v6[4], (char *)a1 - (v6 - &v6[4]), 8LL * ((v2 + (unsigned int)(v6 - &v6[4])) >> 3));
}
else if ( (width & 4) != 0 )
{
*(_DWORD *)v6 = *(_DWORD *)a1;
*(_DWORD *)&v6[width - 4] = *(_DWORD *)((char *)a1 + (unsigned int)width - 4);
}
else if ( width )
{
v6[0] = *(_BYTE *)a1;
if ( (width & 2) != 0 )
*(_WORD *)&v6[width - 2] = *(_WORD *)((char *)a1 + (unsigned int)width - 2);
}
}
v8 = v2;
v12 = 0;
v13 = 0;
*(_QWORD *)&v6[4] = v6;
v7 = &inbuf;
v10 = a2;
v9 = 10000000;
v11 = 8;
if ( ioctl(spi_fd, 0x40206B00uLL, &v6[4]) < 0 )
{
v4 = _errno_location();
v5 = strerror(*v4);
printf("spi: ERROR while sending - %s\r\n", v5);
}
return &inbuf;
}

original_code:
unsigned char* transfer(unsigned char* data, int delay) {
  struct spi_ioc_transfer spi;
  unsigned char outbuf[4];
  int result;
  int i = 0;
  for(; i < width; i++) {
    outbuf[i] = data[i];
  }
  memset(&spi,0,sizeof(spi));
  spi.tx_buf = (unsigned long)&outbuf;
  spi.rx_buf = (unsigned long)&inbuf;
  spi.len = width;
  spi.delay_usecs = delay;
  spi.speed_hz = 10000000;
  spi.bits_per_word = 8;
  result = ioctl(spi_fd, (((1U) << (((0 +8)+8)+14)) | ((('k')) << (0 +8)) | (((0)) << 0) | ((((sizeof(char[((((1)*(sizeof (struct spi_ioc_transfer))) < (1 << 14)) ? ((1)*(sizeof (struct spi_ioc_transfer))) : 0)])))) << ((0 +8)+8))), &spi);
  if( result < 0){
        printf("spi: ERROR while sending - %s\r\n", strerror((*__errno_location ())));
  }
  return inbuf;
}

canonical_original_code:
unsigned char *transfer(unsigned char *data, int delay) {
  struct spi_ioc_transfer spi;
  unsigned char outbuf[4];
  int result;
  int i = 0;
  for(; i < width; i++) {
    outbuf[i] = data[i];
  }
  memset(&spi,0,sizeof(spi));
  spi.tx_buf = (unsigned long)&outbuf;
  spi.rx_buf = (unsigned long)&inbuf;
  spi.len = width;
  spi.delay_usecs = delay;
  spi.speed_hz = 10000000;
  spi.bits_per_word = 8;
  result = ioctl(spi_fd, (((1U) << (((0 +8)+8)+14)) | ((('k')) << (0 +8)) | (((0)) << 0) | ((((sizeof(char [-1])))) << ((0 +8)+8))), &spi);
  if( result < 0){
        printf("spi: ERROR while sending - %s\r\n", strerror((*__errno_location ())));
  }
  return inbuf;
}

variable_types:
data
unsigned char *

variable_types: delay int

variable_types: struct spi_ioc_transfer { unsigned long long tx_buf; unsigned long long rx_buf; unsigned int len; unsigned int speed_hz; unsigned short delay_usecs; unsigned char bits_per_word; unsigned char cs_change; unsigned char tx_nbits; unsigned char rx_nbits; unsigned short pad; }

variable_types:
outbuf
unsigned char [4]

return_type: unsigned char *


decompiled_code:
__int64 __fastcall gz_spi_set(int a1)
{
if ( !initialized )
gz_spi_initialize();
if ( width < a1 >> 3 )
{
printf("Bit %d is out of range.", (unsigned int)a1);
exit(-1);
}
spi_cache[a1 >> 3] |= 1 << (a1 & 7);
transfer(spi_cache, 0);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1)
{
if ( !initialized )
func2();
if ( width < a1 >> 3 )
{
printf("Bit %d is out of range.", (unsigned int)a1);
exit(-1);
}
spi_cache[a1 >> 3] |= 1 << (a1 & 7);
func4(spi_cache, 0);
return 0LL;
}

original_code:
int gz_spi_set(int bit_to_set) {
  if (!initialized) {
    gz_spi_initialize();
  }
  int byte_cnt = bit_to_set >> 3;
  if (byte_cnt > width) {
   printf("Bit %d is out of range.", bit_to_set);
   exit(-1);
  }
  else {
    spi_cache[byte_cnt] |= (1 << (bit_to_set & 0x7));
    transfer(spi_cache, 0);
  }
  return 0;
}


decompiled_code:
__int64 __fastcall gz_spi_reset(int a1)
{
if ( !initialized )
gz_spi_initialize();
if ( width < a1 >> 3 )
{
printf("Bit %d is out of range.", (unsigned int)a1);
exit(-1);
}
spi_cache[a1 >> 3] &= ~(1 << (a1 & 7));
transfer(spi_cache, 0);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1)
{
if ( !initialized )
func2();
if ( width < a1 >> 3 )
{
printf("Bit %d is out of range.", (unsigned int)a1);
exit(-1);
}
spi_cache[a1 >> 3] &= ~(1 << (a1 & 7));
func4(spi_cache, 0);
return 0LL;
}

original_code:
int gz_spi_reset(int bit_to_reset){
  if (!initialized) {
    gz_spi_initialize();
  }
  int byte_cnt = bit_to_reset >> 3;
  if (byte_cnt > width) {
 printf("Bit %d is out of range.", bit_to_reset);
 exit(-1);
  }
  else {
    spi_cache[byte_cnt] &= ~(1 << (bit_to_reset & 0x7));
    transfer(spi_cache, 0);
  }
  return 0;
}


decompiled_code:
__int64 __fastcall gz_spi_write(__int64 a1)
{
int v1; // ecx
__int64 v2; // rax
unsigned __int8 v3; // dl

if ( initialized )
{
v1 = width;
if ( width <= 0 )
goto LABEL_7;
}
else
{
gz_spi_initialize();
v1 = width;
if ( width <= 0 )
goto LABEL_7;
}
v2 = 0LL;
do
{
v3 = *(_BYTE *)(a1 + v2++);
spi_cache[v2 - 1] = v3;
}
while ( v1 > (int)v2 );
LABEL_7:
transfer(spi_cache, 0);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
int v1; // ecx
__int64 v2; // rax
unsigned __int8 v3; // dl

if ( initialized )
{
v1 = width;
if ( width <= 0 )
goto LABEL_7;
}
else
{
func2();
v1 = width;
if ( width <= 0 )
goto LABEL_7;
}
v2 = 0LL;
do
{
v3 = *(_BYTE *)(a1 + v2++);
spi_cache[v2 - 1] = v3;
}
while ( v1 > (int)v2 );
LABEL_7:
func4(spi_cache, 0);
return 0LL;
}

original_code:
int gz_spi_write(unsigned char* to_write) {
  if (!initialized) {
    gz_spi_initialize();
  }
  int i = 0;
  for (; i < width; i++) {
 spi_cache[i] = *to_write++;
  }
  transfer(spi_cache, 0);
  return 0;
}

canonical_original_code:
int gz_spi_write(unsigned char *to_write) {
  if (!initialized) {
    gz_spi_initialize();
  }
  int i = 0;
  for (; i < width; i++) {
 spi_cache[i] = *to_write++;
  }
  transfer(spi_cache, 0);
  return 0;
}

variable_types: i int


decompiled_code:
char *__fastcall gz_spi_read(__int64 a1)
{
char *result; // rax
char *v2; // rcx

if ( !initialized )
gz_spi_initialize();
result = (char *)transfer(spi_cache, 0);
v2 = result;
if ( width > 0 )
{
result = 0LL;
do
{
result[a1] = result[(_QWORD)v2];
++result;
}
while ( width > (int)result );
}
return result;
}

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

if ( !initialized )
func2();
result = (char *)func4(spi_cache, 0);
v2 = result;
if ( width > 0 )
{
result = 0LL;
do
{
result[a1] = result[(_QWORD)v2];
++result;
}
while ( width > (int)result );
}
return result;
}

original_code:
void gz_spi_read(unsigned char* result) {
  unsigned char* buffer;
  if (!initialized) {
    gz_spi_initialize();
  }
  buffer = transfer(spi_cache, 0);
  int i= 0;
  for (; i < width; i++) {
   result[i] = buffer[i];
  }
}

canonical_original_code:
void gz_spi_read(unsigned char *result) {
  unsigned char *buffer;
  if (!initialized) {
    gz_spi_initialize();
  }
  buffer = transfer(spi_cache, 0);
  int i = 0;
  for (; i < width; i++) {
   result[i] = buffer[i];
  }
}

variable_types:
result
unsigned char *

variable_types:
buffer
unsigned char *


decompiled_code:
__int64 __fastcall gz_spi_get(int a1)
{
if ( width < a1 >> 3 )
{
printf("Bit %d is out of range.", (unsigned int)a1);
exit(-1);
}
return ((int)*((unsigned __int8 *)transfer(spi_cache, 0) + (a1 >> 3)) >> (a1 & 7)) & 1;
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1)
{
if ( width < a1 >> 3 )
{
printf("Bit %d is out of range.", (unsigned int)a1);
exit(-1);
}
return ((int)*((unsigned __int8 *)func4(spi_cache, 0) + (a1 >> 3)) >> (a1 & 7)) & 1;
}

original_code:
int gz_spi_get(int bit_to_read) {
  unsigned char* buffer;
  int byte_cnt = bit_to_read >> 3;
  if (byte_cnt > width) {
 printf("Bit %d is out of range.", bit_to_read);
 exit(-1);
  }
  else {
 buffer = transfer(spi_cache, 0);
 return 0 == (buffer[byte_cnt] & (1 << (bit_to_read & 0x7))) ? 0 : 1;
  }
  return 0;
}

canonical_original_code:
int gz_spi_get(int bit_to_read) {
  unsigned char *buffer;
  int byte_cnt = bit_to_read >> 3;
  if (byte_cnt > width) {
 printf("Bit %d is out of range.", bit_to_read);
 exit(-1);
  }
  else {
 buffer = transfer(spi_cache, 0);
 return 0 == (buffer[byte_cnt] & (1 << (bit_to_read & 0x7))) ? 0 : 1;
  }
  return 0;
}


decompiled_code:
void *__fastcall gz_spi_set_width(unsigned int a1)
{
void *result; // rax

if ( a1 - 1 > 3 )
{
printf("Illegal buffer width %d. SPI buffer width must be 1, 2, 3 or 4.", a1);
exit(-1);
}
result = &width;
width = a1;
return result;
}

canonical_decompiled_code:
void *__fastcall func10(unsigned int a1)
{
void *result; // rax

if ( a1 - 1 > 3 )
{
printf("Illegal buffer width %d. SPI buffer width must be 1, 2, 3 or 4.", a1);
exit(-1);
}
result = &width;
width = a1;
return result;
}

original_code:
void gz_spi_set_width(int new_width) {
  if (new_width < 5 && new_width > 0) {
 width = new_width;
  }
  else {
 printf(
   "Illegal buffer width %d. SPI buffer width must be 1, 2, 3 or 4.",
   new_width);
 exit(-1);
  }
}


decompiled_code:
void *gz_spi_close()
{
void *result; // rax

if ( close(spi_fd) < 0 )
printf("ERROR closing spi device");
result = &initialized;
initialized = 0;
return result;
}

canonical_decompiled_code:
void *func11()
{
void *result; // rax

if ( close(spi_fd) < 0 )
printf("ERROR closing spi device");
result = &initialized;
initialized = 0;
return result;
}

original_code:
void gz_spi_close() {
  if (close(spi_fd) < 0) {
   printf("ERROR closing spi device");
  }
  initialized = 0;
}


decompiled_code:
__int64 __fastcall gz_clock_ena(unsigned int a1, int a2)
{
int v2; // eax
int v3; // ebp
int *v4; // rax
int v5; // edx
int *v6; // rax
int v7; // edx

v2 = open("/dev/mem", 1052674);
if ( v2 < 0 )
{
puts("\rError initializing IO. Consider using sudo.");
exit(-1);
}
if ( a1 > 1 )
{
puts("gz_clock_ena: Unsupported clock speed selected.");
puts("Supported speeds: GZ_CLK_5MHz (0) and GZ_CLK_125MHz (1).");
exit(-1);
}
v3 = a1 == 0 ? 1 : 6;
if ( a2 <= 1 )
{
puts("gz_clock_ena: Minimum divisor value is 2.");
exit(-1);
}
if ( a2 > 4095 )
{
printf("gz_clock_ena: Maximum divisor value is %d.\n", 4095LL);
exit(-1);
}
close(v2);
usleep(0x3E8u);
v4 = (int *)get_gpio_base();
v5 = *v4;
BYTE1(v5) = BYTE1(*v4) & 0x8F;
*v4 = v5;
v6 = (int *)get_gpio_base();
v7 = *v6;
BYTE1(v7) = BYTE1(*v6) | 0x40;
*v6 = v7;
*(_DWORD *)(get_clock_base() + 112) = v3 | 0x5A000000;
while ( (*(_DWORD *)(get_clock_base() + 112) & 0x80u) != 0 )
;
*(_DWORD *)(get_clock_base() + 116) = (a2 << 12) | 0x5A002000;
*(_DWORD *)(get_clock_base() + 112) = v3 | 0x5A000010;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, int a2)
{
int v2; // eax
int v3; // ebp
int *v4; // rax
int v5; // edx
int *v6; // rax
int v7; // edx

v2 = open("/dev/mem", 1052674);
if ( v2 < 0 )
{
puts("\rError initializing IO. Consider using sudo.");
exit(-1);
}
if ( a1 > 1 )
{
puts("gz_clock_ena: Unsupported clock speed selected.");
puts("Supported speeds: GZ_CLK_5MHz (0) and GZ_CLK_125MHz (1).");
exit(-1);
}
v3 = a1 == 0 ? 1 : 6;
if ( a2 <= 1 )
{
puts("gz_clock_ena: Minimum divisor value is 2.");
exit(-1);
}
if ( a2 > 4095 )
{
printf("gz_clock_ena: Maximum divisor value is %d.\n", 4095LL);
exit(-1);
}
close(v2);
usleep(0x3E8u);
v4 = (int *)get_gpio_base();
v5 = *v4;
BYTE1(v5) = BYTE1(*v4) & 0x8F;
*v4 = v5;
v6 = (int *)get_gpio_base();
v7 = *v6;
BYTE1(v7) = BYTE1(*v6) | 0x40;
*v6 = v7;
*(_DWORD *)(get_clock_base() + 112) = v3 | 0x5A000000;
while ( (*(_DWORD *)(get_clock_base() + 112) & 0x80u) != 0 )
;
*(_DWORD *)(get_clock_base() + 116) = (a2 << 12) | 0x5A002000;
*(_DWORD *)(get_clock_base() + 112) = v3 | 0x5A000010;
return 0LL;
}

original_code:
int gz_clock_ena(int speed, int divisor) {
  int speed_id = 6;
  int mem_fd;
  if ((mem_fd = open("/dev/mem", 02|04010000) ) < 0) {
     printf("\rError initializing IO. Consider using sudo.\n");
     exit(-1);
  }
  if (speed < 0 || speed > 1) {
    printf("gz_clock_ena: Unsupported clock speed selected.\n");
    printf("Supported speeds: GZ_CLK_5MHz (0) and GZ_CLK_125MHz (1).\n");
    exit(-1);
  }
  if (speed == 0) {
    speed_id = 1;
  }
  if (divisor < 2) {
    printf("gz_clock_ena: Minimum divisor value is 2.\n");
    exit(-1);
  }
  if (divisor > 0xfff) {
    printf("gz_clock_ena: Maximum divisor value is %d.\n", 0xfff);
    exit(-1);
  }
  close(mem_fd);
  usleep(1000);
  *(get_gpio_base()+((4)/10)) &= ~(7<<(((4)%10)*3));
  *(get_gpio_base()+(((4)/10))) |= (((0)<=3?(0)+4:(0)==4?3:2)<<(((4)%10)*3));
  *(get_clock_base() + 0x1C) = 0x5A000000 | speed_id;
  while (*(get_clock_base() + 0x1C) & (1 << 7)) {}
  *(get_clock_base() + 0x1D) = 0x5A002000 | (divisor << 12);
  *(get_clock_base() + 0x1C) = 0x5A000010 | speed_id;
  return 0;
}

variable_types: speed int

variable_types: divisor int


decompiled_code:
__int64 gz_clock_dis()
{
int *v0; // rax
int v1; // edx

v0 = (int *)get_gpio_base();
v1 = *v0;
BYTE1(v1) = BYTE1(*v0) & 0x8F;
*v0 = v1;
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
int *v0; // rax
int v1; // edx

v0 = (int *)get_gpio_base();
v1 = *v0;
BYTE1(v1) = BYTE1(*v0) & 0x8F;
*v0 = v1;
return 0LL;
}


decompiled_code:
void initialize_peripherals()
{
int v0; // er12
int v1; // edi
__off_t v2; // r9
void *v3; // r13
void *v4; // rbx
int v5; // eax
int v6; // edx
_BYTE *v7; // rax
_BYTE *v8; // rdx
_BYTE v9[72]; // [rsp+0h] [rbp-48h] BYREF

if ( !gpio_initialized )
{
v0 = open("/dev/mem", 1052674);
if ( v0 < 0 )
{
puts("\rError initializing IO. Consider using sudo.");
exit(-1);
}
v1 = open("/proc/device-tree/model", 1052672);
if ( v1 < 0 || (v5 = read(v1, v9, 0x20uLL), v5 <= 0) )
{
LABEL_4:
v2 = peri_base + 0x200000LL;
}
else
{
v6 = v5 - 1;
v7 = v9;
v8 = &v9[v6 + 1];
while ( *v7 != 50 )
{
if ( ++v7 == v8 )
goto LABEL_4;
}
v2 = 1059061760LL;
peri_base = 1056964608LL;
}
v3 = mmap(0LL, 0x1000uLL, 3, 1, v0, v2);
v4 = mmap(0LL, 0x1000uLL, 3, 1, v0, peri_base + 1052672LL);
close(v0);
if ( v3 == (void *)-1LL )
{
printf("error mapping gpio%d\n", 0xFFFFFFFFLL);
exit(-1);
}
if ( v4 == (void *)-1LL )
{
printf("error mapping clocks%d\n", 0xFFFFFFFFLL);
exit(-1);
}
gpio_initialized = 1;
gpio_base = v3;
clock_base = v4;
}
}

canonical_decompiled_code:
void func0()
{
int v0; // er12
int v1; // edi
__off_t v2; // r9
void *v3; // r13
void *v4; // rbx
int v5; // eax
int v6; // edx
_BYTE *v7; // rax
_BYTE *v8; // rdx
_BYTE v9[72]; // [rsp+0h] [rbp-48h] BYREF

if ( !gpio_initialized )
{
v0 = open("/dev/mem", 1052674);
if ( v0 < 0 )
{
puts("\rError initializing IO. Consider using sudo.");
exit(-1);
}
v1 = open("/proc/device-tree/model", 1052672);
if ( v1 < 0 || (v5 = read(v1, v9, 0x20uLL), v5 <= 0) )
{
LABEL_4:
v2 = peri_base + 0x200000LL;
}
else
{
v6 = v5 - 1;
v7 = v9;
v8 = &v9[v6 + 1];
while ( *v7 != 50 )
{
if ( ++v7 == v8 )
goto LABEL_4;
}
v2 = 1059061760LL;
peri_base = 1056964608LL;
}
v3 = mmap(0LL, 0x1000uLL, 3, 1, v0, v2);
v4 = mmap(0LL, 0x1000uLL, 3, 1, v0, peri_base + 1052672LL);
close(v0);
if ( v3 == (void *)-1LL )
{
printf("error mapping gpio%d\n", 0xFFFFFFFFLL);
exit(-1);
}
if ( v4 == (void *)-1LL )
{
printf("error mapping clocks%d\n", 0xFFFFFFFFLL);
exit(-1);
}
gpio_initialized = 1;
gpio_base = v3;
clock_base = v4;
}
}

original_code:
void initialize_peripherals() {
  if (!gpio_initialized) {
 int proc_fd;
 int mem_fd;
 char proc_model[32];
    if ((mem_fd = open("/dev/mem", 02|04010000) ) < 0) {
      printf("\rError initializing IO. Consider using sudo.\n");
      exit(-1);
    }
    if ((proc_fd = open("/proc/device-tree/model", 00|04010000) ) >= 0) {
   int i = 0;
   int len = 0;
      len = read(proc_fd, proc_model, sizeof proc_model);
      for (i = 0; i < len; i++) {
  if (proc_model[i] == '2') {
   peri_base = 0x3f000000;
   break;
     }
      }
    }
    void *gpio_map = mmap(
      ((void *)0),
      (4*1024),
      0x1|0x2,
      0x01,
      mem_fd,
      (peri_base + 0x200000)
    );
    void *clock_map = mmap(
      ((void *)0),
      (4*1024),
      0x1|0x2,
      0x01,
      mem_fd,
      (peri_base + 0x101000)
    );
    close(mem_fd);
    if (gpio_map == ((void *) -1)) {
      printf("error mapping gpio%d\n", (int)gpio_map);
      exit(-1);
    }
    if (clock_map == ((void *) -1)) {
      printf("error mapping clocks%d\n", (int)clock_map);
      exit(-1);
    }
    gpio_base = (volatile unsigned *)gpio_map;
    clock_base = (volatile unsigned *)clock_map;
    gpio_initialized = 1;
  }
}

canonical_original_code:
void initialize_peripherals() {
  if (!gpio_initialized) {
 int proc_fd;
 int mem_fd;
 char proc_model[32];
    if ((mem_fd = open("/dev/mem", 02|04010000) ) < 0) {
      printf("\rError initializing IO. Consider using sudo.\n");
      exit(-1);
    }
    if ((proc_fd = open("/proc/device-tree/model", 00|04010000) ) >= 0) {
   int i = 0;
   int len = 0;
      len = read(proc_fd, proc_model, sizeof proc_model);
      for (i = 0; i < len; i++) {
  if (proc_model[i] == '2') {
   peri_base = 0x3f000000;
   break;
     }
      }
    }
    void *gpio_map = mmap(
      ((void *)0),
      (4*1024),
      0x1|0x2,
      0x01,
      mem_fd,
      (peri_base + 0x200000)
    );
    void *clock_map = mmap(
      ((void *)0),
      (4*1024),
      0x1|0x2,
      0x01,
      mem_fd,
      (peri_base + 0x101000)
    );
    close(mem_fd);
    if (gpio_map == ((void *) -1)) {
      printf("error mapping gpio%d\n", (int)gpio_map);
      exit(-1);
    }
    if (clock_map == ((void *) -1)) {
      printf("error mapping clocks%d\n", (int)clock_map);
      exit(-1);
    }
    gpio_base = (unsigned int *)gpio_map;
    clock_base = (unsigned int *)clock_map;
    gpio_initialized = 1;
  }
}

variable_types: len int


decompiled_code:
__int64 get_peripheral_base()
{
if ( !gpio_initialized )
initialize_peripherals();
return peri_base;
}

canonical_decompiled_code:
__int64 func1()
{
if ( !gpio_initialized )
func0();
return peri_base;
}

original_code:
__off_t get_peripheral_base() {
  if (!gpio_initialized) {
    initialize_peripherals();
  }
  return peri_base;
}

canonical_original_code:
long get_peripheral_base() {
  if (!gpio_initialized) {
    initialize_peripherals();
  }
  return peri_base;
}

return_type: long


decompiled_code:
__int64 get_gpio_base()
{
if ( !gpio_initialized )
initialize_peripherals();
return gpio_base;
}

canonical_decompiled_code:
__int64 func2()
{
if ( !gpio_initialized )
func0();
return gpio_base;
}

original_code:
volatile unsigned * get_gpio_base() {
  if (!gpio_initialized) {
    initialize_peripherals();
  }
  return gpio_base;
}

canonical_original_code:
unsigned int *get_gpio_base() {
  if (!gpio_initialized) {
    initialize_peripherals();
  }
  return gpio_base;
}

return_type: unsigned int *


decompiled_code:
__int64 get_clock_base()
{
if ( !gpio_initialized )
initialize_peripherals();
return clock_base;
}

canonical_decompiled_code:
__int64 func3()
{
if ( !gpio_initialized )
func0();
return clock_base;
}

original_code:
volatile unsigned * get_clock_base() {
  if (!gpio_initialized) {
    initialize_peripherals();
  }
  return clock_base;
}

canonical_original_code:
unsigned int *get_clock_base() {
  if (!gpio_initialized) {
    initialize_peripherals();
  }
  return clock_base;
}


value

decompiled_code:
__int64 __fastcall value(__int16 *a1)
{
unsigned __int8 *v1; // rdx
__int64 result; // rax
__int64 v3; // rcx

if ( *a1 <= 0 )
return 0LL;
v1 = (unsigned __int8 *)(a1 + 1);
result = 0LL;
do
{
v3 = *v1++;
result = v3 | (result << 8);
}
while ( v1 != (unsigned __int8 *)((char *)a1 + (unsigned __int16)(*a1 - 1) + 3) );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int16 *a1)
{
unsigned __int8 *v1; // rdx
__int64 result; // rax
__int64 v3; // rcx

if ( *a1 <= 0 )
return 0LL;
v1 = (unsigned __int8 *)(a1 + 1);
result = 0LL;
do
{
v3 = *v1++;
result = v3 | (result << 8);
}
while ( v1 != (unsigned __int8 *)((char *)a1 + (unsigned __int16)(*a1 - 1) + 3) );
return result;
}

original_code:
long value( lenVal* plvValue )
{
 long lValue;
 short sIndex;
    lValue = 0;
 for ( sIndex = 0; sIndex < plvValue->len ; ++sIndex )
 {
  lValue <<= 8;
  lValue |= plvValue->val[ sIndex];
 }
 return( lValue );
}

canonical_original_code:
long value(struct var_len_byte *plvValue)
{
 long lValue;
 short sIndex;
    lValue = 0;
 for ( sIndex = 0; sIndex < plvValue->len ; ++sIndex )
 {
  lValue <<= 8;
  lValue |= plvValue->val[ sIndex];
 }
 return( lValue );
}

variable_types: struct var_len_byte { short len; unsigned char val[-1]; } *

variable_types: lValue long

variable_types: sIndex short


initLenVal

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

result = 1LL;
*(_BYTE *)(a1 + 2) = a2;
*(_WORD *)a1 = 1;
return result;
}

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

result = 1LL;
*(_BYTE *)(a1 + 2) = a2;
*(_WORD *)a1 = 1;
return result;
}

original_code:
void initLenVal( lenVal* plv,
                 long lValue )
{
 plv->len = 1;
 plv->val[0] = (unsigned char)lValue;
}

canonical_original_code:
void initLenVal(struct var_len_byte *plv, long lValue)
{
 plv->len = 1;
 plv->val[0] = (unsigned char)lValue;
}

user_defined_types: struct var_len_byte { short len; unsigned char val[-1]; }


EqualLenVal

original_code:
short EqualLenVal( lenVal* plvTdoExpected,
                   lenVal* plvTdoCaptured,
                   lenVal* plvTdoMask )
{
    short sEqual;
 short sIndex;
    unsigned char ucByteVal1;
    unsigned char ucByteVal2;
    unsigned char ucByteMask;
    sEqual = 1;
    sIndex = plvTdoExpected->len;
    while ( sEqual && sIndex-- )
    {
        ucByteVal1 = plvTdoExpected->val[ sIndex ];
        ucByteVal2 = plvTdoCaptured->val[ sIndex ];
        if ( plvTdoMask )
        {
            ucByteMask = plvTdoMask->val[ sIndex ];
            ucByteVal1 &= ucByteMask;
            ucByteVal2 &= ucByteMask;
        }
        if ( ucByteVal1 != ucByteVal2 )
        {
            sEqual = 0;
        }
    }
 return( sEqual );
}

canonical_original_code:
short EqualLenVal(struct var_len_byte *plvTdoExpected, struct var_len_byte *plvTdoCaptured, struct var_len_byte *plvTdoMask)
{
    short sEqual;
 short sIndex;
    unsigned char ucByteVal1;
    unsigned char ucByteVal2;
    unsigned char ucByteMask;
    sEqual = 1;
    sIndex = plvTdoExpected->len;
    while ( sEqual && sIndex-- )
    {
        ucByteVal1 = plvTdoExpected->val[ sIndex ];
        ucByteVal2 = plvTdoCaptured->val[ sIndex ];
        if ( plvTdoMask )
        {
            ucByteMask = plvTdoMask->val[ sIndex ];
            ucByteVal1 &= ucByteMask;
            ucByteVal2 &= ucByteMask;
        }
        if ( ucByteVal1 != ucByteVal2 )
        {
            sEqual = 0;
        }
    }
 return( sEqual );
}

variable_types:
plvTdoCaptured
struct var_len_byte *

variable_types:
plvTdoMask
struct var_len_byte *

variable_types: sEqual short

variable_types:
ucByteMask
unsigned char

return_type: short


RetBit

decompiled_code:
__int64 __fastcall RetBit(__int64 a1, int a2, char a3)
{
return ((int)*(unsigned __int8 *)(a2 + a1 + 2) >> (7 - a3)) & 1;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int a2, char a3)
{
return ((int)*(unsigned __int8 *)(a2 + a1 + 2) >> (7 - a3)) & 1;
}

original_code:
short RetBit( lenVal* plv,
              int iByte,
              int iBit )
{
    return( (short)( ( plv->val[ iByte ] >> ( 7 - iBit ) ) & 0x1 ) );
}

canonical_original_code:
short RetBit(struct var_len_byte *plv, int iByte, int iBit)
{
    return( (short)( ( plv->val[ iByte ] >> ( 7 - iBit ) ) & 0x1 ) );
}

variable_types: iByte int

variable_types: iBit int


SetBit

decompiled_code:
char __fastcall SetBit(__int64 a1, int a2, char a3, __int16 a4)
{
int v4; // edx
char result; // al
char v6; // dl

v4 = 1 << (7 - a3);
result = *(_BYTE *)(a1 + a2 + 2) & ~(_BYTE)v4;
v6 = result | v4;
if ( a4 )
result = v6;
*(_BYTE *)(a1 + a2 + 2) = result;
return result;
}

canonical_decompiled_code:
char __fastcall func4(__int64 a1, int a2, char a3, __int16 a4)
{
int v4; // edx
char result; // al
char v6; // dl

v4 = 1 << (7 - a3);
result = *(_BYTE *)(a1 + a2 + 2) & ~(_BYTE)v4;
v6 = result | v4;
if ( a4 )
result = v6;
*(_BYTE *)(a1 + a2 + 2) = result;
return result;
}

original_code:
void SetBit( lenVal* plv,
             int iByte,
             int iBit,
             short sVal )
{
    unsigned char ucByteVal;
    unsigned char ucBitMask;
    ucBitMask = (unsigned char)(1 << ( 7 - iBit ));
    ucByteVal = (unsigned char)(plv->val[ iByte ] & (~ucBitMask));
    if ( sVal )
    {
        ucByteVal |= ucBitMask;
    }
    plv->val[ iByte ] = ucByteVal;
}

canonical_original_code:
void SetBit(struct var_len_byte *plv, int iByte, int iBit, short sVal)
{
    unsigned char ucByteVal;
    unsigned char ucBitMask;
    ucBitMask = (unsigned char)(1 << ( 7 - iBit ));
    ucByteVal = (unsigned char)(plv->val[ iByte ] & (~ucBitMask));
    if ( sVal )
    {
        ucByteVal |= ucBitMask;
    }
    plv->val[ iByte ] = ucByteVal;
}

variable_types: sVal short

variable_types:
ucByteVal
unsigned char

variable_types:
ucBitMask
unsigned char


addVal

decompiled_code:
__int64 __fastcall addVal(_WORD *a1, unsigned __int16 *a2, __int64 a3)
{
__int64 result; // rax
int v6; // edx
bool v7; // cl
int v8; // edi
bool v9; // cf
bool v10; // zf

result = *a2;
*a1 = result;
v6 = result - 1;
if ( (_WORD)result )
{
v7 = 0;
do
{
v8 = *(unsigned __int8 *)(a3 + (__int16)v6 + 2);
result = v7 + v8 + (unsigned int)*((unsigned __int8 *)a2 + (__int16)v6 + 2);
v9 = (unsigned __int16)(v7 + v8 + *((unsigned __int8 *)a2 + (__int16)v6 + 2)) < 0xFFu;
v10 = v7 + (_WORD)v8 + *((unsigned __int8 *)a2 + (__int16)v6 + 2) == 255;
*((_BYTE *)a1 + (__int16)v6 + 2) = v7 + v8 + *((_BYTE *)a2 + (__int16)v6 + 2);
v7 = !v9 && !v10;
--v6;
}
while ( (_WORD)v6 != 0xFFFF );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(_WORD *a1, unsigned __int16 *a2, __int64 a3)
{
__int64 result; // rax
int v6; // edx
bool v7; // cl
int v8; // edi
bool v9; // cf
bool v10; // zf

result = *a2;
*a1 = result;
v6 = result - 1;
if ( (_WORD)result )
{
v7 = 0;
do
{
v8 = *(unsigned __int8 *)(a3 + (__int16)v6 + 2);
result = v7 + v8 + (unsigned int)*((unsigned __int8 *)a2 + (__int16)v6 + 2);
v9 = (unsigned __int16)(v7 + v8 + *((unsigned __int8 *)a2 + (__int16)v6 + 2)) < 0xFFu;
v10 = v7 + (_WORD)v8 + *((unsigned __int8 *)a2 + (__int16)v6 + 2) == 255;
*((_BYTE *)a1 + (__int16)v6 + 2) = v7 + v8 + *((_BYTE *)a2 + (__int16)v6 + 2);
v7 = !v9 && !v10;
--v6;
}
while ( (_WORD)v6 != 0xFFFF );
}
return result;
}

original_code:
void addVal( lenVal* plvResVal,
             lenVal* plvVal1,
             lenVal* plvVal2 )
{
 unsigned char ucCarry;
    unsigned short usSum;
    unsigned short usVal1;
    unsigned short usVal2;
 short sIndex;
 plvResVal->len = plvVal1->len;
    ucCarry = 0;
    sIndex = plvVal1->len;
    while ( sIndex-- )
    {
  usVal1 = plvVal1->val[ sIndex ];
  usVal2 = plvVal2->val[ sIndex ];
  usSum = (unsigned short)( usVal1 + usVal2 + ucCarry );
  ucCarry = (unsigned char)( ( usSum > 255 ) ? 1 : 0 );
  plvResVal->val[ sIndex ] = (unsigned char)usSum;
    }
}

canonical_original_code:
void addVal(struct var_len_byte *plvResVal, struct var_len_byte *plvVal1, struct var_len_byte *plvVal2)
{
 unsigned char ucCarry;
    unsigned short usSum;
    unsigned short usVal1;
    unsigned short usVal2;
 short sIndex;
 plvResVal->len = plvVal1->len;
    ucCarry = 0;
    sIndex = plvVal1->len;
    while ( sIndex-- )
    {
  usVal1 = plvVal1->val[ sIndex ];
  usVal2 = plvVal2->val[ sIndex ];
  usSum = (unsigned short)( usVal1 + usVal2 + ucCarry );
  ucCarry = (unsigned char)( ( usSum > 255 ) ? 1 : 0 );
  plvResVal->val[ sIndex ] = (unsigned char)usSum;
    }
}

variable_types:
ucCarry
unsigned char

variable_types:
usSum
unsigned short


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

v1 = *(const char **)(a1 + 16);
v2 = strlen(v1);
return spn_hash_bytes(v1, v2);
}

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

v1 = *(const char **)(a1 + 16);
v2 = strlen(v1);
return spn_hash_bytes(v1, v2);
}

original_code:
static unsigned long symstub_hash(void *obj)
{
 SymbolStub *symstub = obj;
 const char *name = symstub->name;
 size_t length = strlen(name);
 return spn_hash_bytes(name, length);
}

canonical_original_code:
static unsigned long symstub_hash(void *obj)
{
 struct SymbolStub *symstub = obj;
 char *name = symstub->name;
 unsigned long length = strlen(name);
 return spn_hash_bytes(name, length);
}

variable_types:
obj
void *

variable_types: struct SymbolStub { struct SpnObject { struct SpnClass { unsigned long instsz; unsigned long UID; char *name; int (*equal)(void *, void *); int (*compare)(void *, void *); unsigned long (*hashfn)(void *); char *(*description)(void *, int); void (*destructor)(void *); } *isa; unsigned int refcnt; } base; char *name; } *

variable_types:
name
char *

variable_types:
length
unsigned long

user_defined_types: struct SymbolStub { struct SpnObject base; char *name; }

user_defined_types: struct SpnObject { struct SpnClass *isa; unsigned int refcnt; }


decompiled_code:
_BOOL8 __fastcall symstub_equal(__int64 a1, __int64 a2)
{
return strcmp(*(const char **)(a1 + 16), *(const char **)(a2 + 16)) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(__int64 a1, __int64 a2)
{
return strcmp(*(const char **)(a1 + 16), *(const char **)(a2 + 16)) == 0;
}

original_code:
static int symstub_equal(void *lhs, void *rhs)
{
 SymbolStub *ls = lhs, *rs = rhs;
 return strcmp(ls->name, rs->name) == 0;
}

canonical_original_code:
static int symstub_equal(void *lhs, void *rhs)
{
 struct SymbolStub *ls = lhs; struct SymbolStub *rs = rhs;
 return strcmp(ls->name, rs->name) == 0;
}

variable_types:
lhs
void *

variable_types:
rhs
void *

user_defined_types: struct SpnClass { unsigned long instsz; unsigned long UID; char *name; int (*equal)(void *, void *); int (*compare)(void *, void *); unsigned long (*hashfn)(void *); char *(*description)(void *, int); void (*destructor)(void *); }


decompiled_code:
__int64 __fastcall nth_arg_idx(__int64 a1, int a2)
{
return (unsigned __int8)(*(_DWORD *)(a1 + 4LL * (a2 / 4)) >> (8 * (a2 % 4)));
}

original_code:
int nth_arg_idx(spn_uword *ip, int idx)
{
 int wordidx = idx / 4;
 int shift = 8 * (idx % 4);
 spn_uword word = ip[wordidx];
 int regidx = (word >> shift) & 0xff;
 return regidx;
}

canonical_original_code:
int nth_arg_idx(unsigned int *ip, int idx)
{
 int wordidx = idx / 4;
 int shift = 8 * (idx % 4);
 unsigned int word = ip[wordidx];
 int regidx = (word >> shift) & 0xff;
 return regidx;
}

variable_types:
ip
unsigned int *

variable_types: idx int

variable_types: wordidx int

variable_types: shift int

variable_types:
word
unsigned int

variable_types: regidx int


decompiled_code:
void __fastcall __noreturn spn_diev(char *format, __gnuc_va_list arg)
{
fwrite("fatal error in Sparkling: ", 1uLL, 0x1AuLL, stderr);
vfprintf(stderr, format, arg);
fflush(stderr);
abort();
}

canonical_decompiled_code:
void __fastcall __noreturn func3(char *format, __gnuc_va_list arg)
{
fwrite("fatal error in Sparkling: ", 1uLL, 0x1AuLL, stderr);
vfprintf(stderr, format, arg);
fflush(stderr);
abort();
}

original_code:
void spn_diev(const char *fmt, va_list args)
{
 fprintf(stderr, "fatal error in Sparkling: ");
 vfprintf(stderr, fmt, args);
 fflush(stderr);
 abort();
}

canonical_original_code:
void spn_diev(char *fmt, __builtin_va_list args)
{
 fprintf(stderr, "fatal error in Sparkling: ");
 vfprintf(stderr, fmt, args);
 fflush(stderr);
 abort();
}

variable_types:
fmt
char *


decompiled_code:
void __noreturn spn_die(char *a1, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-C8h] BYREF

va_start(arg, a1);
spn_diev(a1, arg);
}

canonical_decompiled_code:
void __noreturn func4(char *a1, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-C8h] BYREF

va_start(arg, a1);
func3(a1, arg);
}

original_code:
void spn_die(const char *fmt, ...)
{
 va_list args;
 __builtin_va_start(args,fmt);
 spn_diev(fmt, args);
 __builtin_va_end(args);
}

canonical_original_code:
void spn_die(char *fmt, ...)
{
 __builtin_va_list args;
 __builtin_va_start(args,fmt);
 spn_diev(fmt, args);
 __builtin_va_end(args);
}


decompiled_code:
void *__fastcall spn_malloc(size_t a1)
{
void *result; // rax

result = malloc(a1);
if ( !result )
{
if ( a1 )
spn_die("memory allocation of %lu bytes failed", a1);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func5(size_t a1)
{
void *result; // rax

result = malloc(a1);
if ( !result )
{
if ( a1 )
func4("memory allocation of %lu bytes failed", a1);
}
return result;
}

original_code:
void *spn_malloc(size_t n)
{
 void *ptr = malloc(n);
 if (ptr == ((void *)0) && n > 0) {
  unsigned long uln = n;
  spn_die("memory allocation of %lu bytes failed", uln);
 }
 return ptr;
}

canonical_original_code:
void *spn_malloc(unsigned long n)
{
 void *ptr = malloc(n);
 if (ptr == ((void *)0) && n > 0) {
  unsigned long uln = n;
  spn_die("memory allocation of %lu bytes failed", uln);
 }
 return ptr;
}

variable_types:
n
unsigned long

variable_types:
ptr
void *

variable_types:
uln
unsigned long

return_type: void *


decompiled_code:
void *__fastcall spn_realloc(void *a1, size_t a2)
{
void *result; // rax

result = realloc(a1, a2);
if ( !result )
{
if ( a2 )
spn_die("reallocation of pointer %p to size %lu failed", a1, a2);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func6(void *a1, size_t a2)
{
void *result; // rax

result = realloc(a1, a2);
if ( !result )
{
if ( a2 )
func4("reallocation of pointer %p to size %lu failed", a1, a2);
}
return result;
}

original_code:
void *spn_realloc(void *ptr, size_t n)
{
 void *ret = realloc(ptr, n);
 if (ret == ((void *)0) && n > 0) {
  unsigned long uln = n;
  spn_die("reallocation of pointer %p to size %lu failed", ptr, uln);
 }
 return ret;
}

canonical_original_code:
void *spn_realloc(void *ptr, unsigned long n)
{
 void *ret = realloc(ptr, n);
 if (ret == ((void *)0) && n > 0) {
  unsigned long uln = n;
  spn_die("reallocation of pointer %p to size %lu failed", ptr, uln);
 }
 return ret;
}

variable_types:
ret
void *


decompiled_code:
void *__fastcall spn_calloc(size_t a1, size_t a2)
{
void *result; // rax
size_t v3; // rsi

result = calloc(a1, a2);
if ( !result )
{
v3 = a2 * a1;
if ( v3 )
spn_die("allocation of %lu zero-init'ed bytes failed", v3);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func7(size_t a1, size_t a2)
{
void *result; // rax
size_t v3; // rsi

result = calloc(a1, a2);
if ( !result )
{
v3 = a2 * a1;
if ( v3 )
func4("allocation of %lu zero-init'ed bytes failed", v3);
}
return result;
}

original_code:
void *spn_calloc(size_t nelem, size_t elsize)
{
 void *ptr = calloc(nelem, elsize);
 if (ptr == ((void *)0) && nelem * elsize > 0) {
  unsigned long uln = nelem * elsize;
  spn_die("allocation of %lu zero-init'ed bytes failed", uln);
 }
 return ptr;
}

canonical_original_code:
void *spn_calloc(unsigned long nelem, unsigned long elsize)
{
 void *ptr = calloc(nelem, elsize);
 if (ptr == ((void *)0) && nelem * elsize > 0) {
  unsigned long uln = nelem * elsize;
  spn_die("allocation of %lu zero-init'ed bytes failed", uln);
 }
 return ptr;
}

variable_types:
nelem
unsigned long

variable_types:
elsize
unsigned long


decompiled_code:
__int64 __fastcall make_symstub(__int64 a1)
{
__int64 v1; // rax

v1 = spn_object_new(&SymbolStub_class);
*(_QWORD *)(v1 + 16) = a1;
return spn_makeobject(v1);
}

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

v1 = spn_object_new(&SymbolStub_class);
*(_QWORD *)(v1 + 16) = a1;
return spn_makeobject(v1);
}

original_code:
SpnValue make_symstub(const char *name)
{
 SymbolStub *obj = spn_object_new(&SymbolStub_class);
 obj->name = name;
 return spn_makeobject(obj);
}

canonical_original_code:
struct SpnValue make_symstub(char *name)
{
 struct SymbolStub *obj = spn_object_new(&SymbolStub_class);
 obj->name = name;
 return spn_makeobject(obj);
}

variable_types:
name
char *

variable_types: struct SymbolStub { struct SpnObject { struct SpnClass { unsigned long instsz; unsigned long UID; char *name; int (*equal)(void *, void *); int (*compare)(void *, void *); unsigned long (*hashfn)(void *); char *(*description)(void *, int); void (*destructor)(void *); } *isa; unsigned int refcnt; } base; char *name; } *

return_type: struct SpnValue { int type; union { int b; long i; double f; void *p; void *o; } v; }


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

if ( *(_BYTE *)a1 == 4 )
result = spn_object_member_of_class(*(_QWORD *)(a1 + 8), &SymbolStub_class);
else
result = 0LL;
return result;
}

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

if ( *(_BYTE *)a1 == 4 )
result = spn_object_member_of_class(*(_QWORD *)(a1 + 8), &SymbolStub_class);
else
result = 0LL;
return result;
}

original_code:
int is_symstub(const SpnValue *val)
{
 if ((((((val)->type) & 0x00ff)) == SPN_TTAG_OBJECT)) {
  SpnObject *obj = ((val)->v.o);
  return spn_object_member_of_class(obj, &SymbolStub_class);
 }
 return 0;
}

canonical_original_code:
int is_symstub(struct SpnValue *val)
{
 if ((((((val)->type) & 0x00ff)) == SPN_TTAG_OBJECT)) {
  struct SpnObject *obj = ((val)->v.o);
  return spn_object_member_of_class(obj, &SymbolStub_class);
 }
 return 0;
}

variable_types: struct SpnValue { int type; union { int b; long i; double f; void *p; void *o; } v; } *

variable_types: struct SpnObject { struct SpnClass { unsigned long instsz; unsigned long UID; char *name; int (*equal)(void *, void *); int (*compare)(void *, void *); unsigned long (*hashfn)(void *); char *(*description)(void *, int); void (*destructor)(void *); } *isa; unsigned int refcnt; } *


original_code:
void *spn_open_library(SpnString *modname)
{
 void *handle;
 char *libname = spn_malloc(modname->len + strlen(".so") + 1);
 memcpy(libname, modname->cstr, modname->len);
 strcpy(libname + modname->len, ".so");
 handle = dlopen(libname, 0x00001 | 0x00100);
 free(libname);
 return handle;
}

canonical_original_code:
void *spn_open_library(struct SpnString *modname)
{
 void *handle;
 char *libname = spn_malloc(modname->len + strlen(".so") + 1);
 memcpy(libname, modname->cstr, modname->len);
 strcpy(libname + modname->len, ".so");
 handle = dlopen(libname, 0x00001 | 0x00100);
 free(libname);
 return handle;
}

variable_types: struct SpnString { struct SpnObject { struct SpnClass { unsigned long instsz; unsigned long UID; char *name; int (*equal)(void *, void *); int (*compare)(void *, void *); unsigned long (*hashfn)(void *); char *(*description)(void *, int); void (*destructor)(void *); } *isa; unsigned int refcnt; } base; char *cstr; unsigned long len; int dealloc; int ishashed; unsigned long hash; } *

variable_types:
handle
void *

variable_types:
libname
char *

user_defined_types: struct SpnString { struct SpnObject base; char *cstr; unsigned long len; int dealloc; int ishashed; unsigned long hash; }


decompiled_code:
int __fastcall spn_close_library(void *handle)
{
return dlclose(handle);
}

canonical_decompiled_code:
int __fastcall func11(void *handle)
{
return dlclose(handle);
}

original_code:
void spn_close_library(void *handle)
{
 dlclose(handle);
}


decompiled_code:
void *__fastcall spn_get_symbol(void *handle, const char *name)
{
return dlsym(handle, name);
}

canonical_decompiled_code:
void *__fastcall func12(void *handle, const char *name)
{
return dlsym(handle, name);
}

original_code:
void *spn_get_symbol(void *handle, const char *symname)
{
 return dlsym(handle, symname);
}

canonical_original_code:
void *spn_get_symbol(void *handle, char *symname)
{
 return dlsym(handle, symname);
}

variable_types:
symname
char *


decompiled_code:
char *spn_dynamic_load_error()
{
return dlerror();
}

canonical_decompiled_code:
char *func13()
{
return dlerror();
}

original_code:
const char *spn_dynamic_load_error(void)
{
 return dlerror();
}

return_type: char *


original_code:
static int should_rehash(SpnHashMap *hm)
{
 return hm->allocsize == 0 || hm->count > hm->allocsize * 3 / 4;
}

canonical_original_code:
static int should_rehash(struct SpnHashMap *hm)
{
 return hm->allocsize == 0 || hm->count > hm->allocsize * 3 / 4;
}

variable_types: struct SpnHashMap { struct SpnObject { struct SpnClass { unsigned long instsz; unsigned long UID; char *name; int (*equal)(void *, void *); int (*compare)(void *, void *); unsigned long (*hashfn)(void *); char *(*description)(void *, int); void (*destructor)(void *); } *isa; unsigned int refcnt; } base; struct Bucket { struct SpnValue { int type; union { int b; long i; double f; void *p; void *o; } v; } key; struct SpnValue value; } *buckets; unsigned long allocsize; unsigned long count; unsigned long max_hash_offset; } *

user_defined_types: struct SpnHashMap { struct SpnObject base; struct Bucket *buckets; unsigned long allocsize; unsigned long count; unsigned long max_hash_offset; }

user_defined_types: struct Bucket { struct SpnValue key; struct SpnValue value; }


decompiled_code:
void __fastcall free_bucket_array(void *ptr, __int64 a2)
{
void *v2; // r14
char *v3; // rbx
__int64 v4; // r12
char *v5; // rdi

v2 = ptr;
if ( a2 )
{
v3 = (char *)ptr;
v4 = 0LL;
do
{
++v4;
spn_value_release(v3);
v5 = v3 + 16;
v3 += 32;
spn_value_release(v5);
}
while ( a2 != v4 );
}
free(v2);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr, __int64 a2)
{
void *v2; // r14
char *v3; // rbx
__int64 v4; // r12
char *v5; // rdi

v2 = ptr;
if ( a2 )
{
v3 = (char *)ptr;
v4 = 0LL;
do
{
++v4;
spn_value_release(v3);
v5 = v3 + 16;
v3 += 32;
spn_value_release(v5);
}
while ( a2 != v4 );
}
free(v2);
}

original_code:
static void free_bucket_array(Bucket *buckets, size_t n)
{
 size_t i;
 for (i = 0; i < n; i++) {
  spn_value_release(&buckets[i].key);
  spn_value_release(&buckets[i].value);
 }
 free(buckets);
}

canonical_original_code:
static void free_bucket_array(struct Bucket *buckets, unsigned long n)
{
 unsigned long i;
 for (i = 0; i < n; i++) {
  spn_value_release(&buckets[i].key);
  spn_value_release(&buckets[i].value);
 }
 free(buckets);
}

variable_types: struct Bucket { struct SpnValue { int type; union { int b; long i; double f; void *p; void *o; } v; } key; struct SpnValue value; } *

variable_types:
i
unsigned long


decompiled_code:
void __fastcall free_hashmap(__int64 a1)
{
free_bucket_array(*(void **)(a1 + 16), *(_QWORD *)(a1 + 24));
}

original_code:
static void free_hashmap(void *obj)
{
 SpnHashMap *hm = obj;
 free_bucket_array(hm->buckets, hm->allocsize);
}

canonical_original_code:
static void free_hashmap(void *obj)
{
 struct SpnHashMap *hm = obj;
 free_bucket_array(hm->buckets, hm->allocsize);
}

variable_types:
obj
void *

user_defined_types: struct SpnValue { int type; union { int b; long i; double f; void *p; void *o; } v; }