decompiled_code:
__int64 __fastcall ya_timer_entry_schedule(__int64 a1, __int64 a2, _QWORD *a3)
{
__int64 v5; // rdi
__int64 v6; // rdi
__int64 v7; // rdi
__int64 v9; // [rsp+0h] [rbp-28h] BYREF
__int64 v10; // [rsp+8h] [rbp-20h]

if ( a3 == 0LL || a2 == 0 || !a1 )
_assert_fail("this && heap && delay", "src/timer.c", 0x6Cu, "ya_timer_entry_schedule");
ya_gettickcount(&v9);
v9 += *a3;
v10 += a3[1];
ya_time_val_normalize(&v9);
v5 = *(_QWORD *)(*(_QWORD *)(a2 + 96) + 8LL);
if ( v5 )
ya_pthread_mutex_lock(v5, "src/timer.c", 114LL);
*(_QWORD *)(*(_QWORD *)(a1 + 96) + 8LL) = v9;
*(_QWORD *)(*(_QWORD *)(a1 + 96) + 16LL) = v10;
*(_QWORD *)(*(_QWORD *)(a1 + 96) + 40LL) = a2;
v6 = ya_list_search(*(_QWORD *)(a2 + 96) + 24LL, &v9, bigger);
if ( v6 )
ya_list_insert_before(v6, a1);
else
ya_list_insert_before(*(_QWORD *)(a2 + 96) + 24LL, a1);
v7 = *(_QWORD *)(*(_QWORD *)(a2 + 96) + 8LL);
if ( v7 )
ya_pthread_mutex_unlock(v7);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2, _QWORD *a3)
{
__int64 v5; // rdi
__int64 v6; // rdi
__int64 v7; // rdi
__int64 v9; // [rsp+0h] [rbp-28h] BYREF
__int64 v10; // [rsp+8h] [rbp-20h]

if ( a3 == 0LL || a2 == 0 || !a1 )
_assert_fail("this && heap && delay", "src/timer.c", 0x6Cu, "ya_timer_entry_schedule");
ya_gettickcount(&v9);
v9 += *a3;
v10 += a3[1];
ya_time_val_normalize(&v9);
v5 = *(_QWORD *)(*(_QWORD *)(a2 + 96) + 8LL);
if ( v5 )
ya_pthread_mutex_lock(v5, "src/timer.c", 114LL);
*(_QWORD *)(*(_QWORD *)(a1 + 96) + 8LL) = v9;
*(_QWORD *)(*(_QWORD *)(a1 + 96) + 16LL) = v10;
*(_QWORD *)(*(_QWORD *)(a1 + 96) + 40LL) = a2;
v6 = ya_list_search(*(_QWORD *)(a2 + 96) + 24LL, &v9, bigger);
if ( v6 )
ya_list_insert_before(v6, a1);
else
ya_list_insert_before(*(_QWORD *)(a2 + 96) + 24LL, a1);
v7 = *(_QWORD *)(*(_QWORD *)(a2 + 96) + 8LL);
if ( v7 )
ya_pthread_mutex_unlock(v7);
return 0LL;
}

original_code:
static ya_status_t ya_timer_entry_schedule (void *this, ya_timer_heap_t *heap, const ya_time_val *delay)
{
 ya_time_val expires;
 ((void) sizeof ((this && heap && delay) ? 1 : 0), __extension__ ({ if (this && heap && delay) ; else __assert_fail ("this && heap && delay", "src/timer.c", 108, __extension__ __PRETTY_FUNCTION__); }));
 ya_gettickcount(&expires);
 do { (expires).sec += (*delay).sec; (expires).msec += (*delay).msec; ya_time_val_normalize(&(expires)); } while (0);
 if(((struct ya_timer_heap_private *)(((ya_timer_heap_t *)heap)->private))->mutex) {
  ya_pthread_mutex_lock(((struct ya_timer_heap_private *)(((ya_timer_heap_t *)heap)->private))->mutex, "src/timer.c", 114);
 }
 ((struct ya_timer_entry_private *)(((ya_timer_entry_t *)this)->private))->_timer_value.sec = expires.sec;
 ((struct ya_timer_entry_private *)(((ya_timer_entry_t *)this)->private))->_timer_value.msec = expires.msec;
 ((struct ya_timer_entry_private *)(((ya_timer_entry_t *)this)->private))->heap = heap;
 {
  ya_timer_entry_t *node = ya_list_search(&((struct ya_timer_heap_private *)(((ya_timer_heap_t *)heap)->private))->entrys, &expires, bigger);
  if(node) {
   ya_list_insert_before(node, this);
  }else {
   ya_list_insert_before(&((struct ya_timer_heap_private *)(((ya_timer_heap_t *)heap)->private))->entrys, this);
  }
 }
 if (((struct ya_timer_heap_private *)(((ya_timer_heap_t *)heap)->private))->mutex) {
  ya_pthread_mutex_unlock(((struct ya_timer_heap_private *)(((ya_timer_heap_t *)heap)->private))->mutex);
 }
 return YA_SUCCESS;
}

canonical_original_code:
static int ya_timer_entry_schedule(void *this, struct _ya_timer_heap *heap, struct ya_time_val *delay)
{
 struct ya_time_val expires;
 ((void) sizeof ((this && heap && delay) ? 1 : 0), __extension__ ({ if (this && heap && delay) ; else __assert_fail ("this && heap && delay", "src/timer.c", 108, __extension__ __PRETTY_FUNCTION__); }));
 ya_gettickcount(&expires);
 do { (expires).sec += (*delay).sec; (expires).msec += (*delay).msec; ya_time_val_normalize(&(expires)); } while (0);
 if(((struct ya_timer_heap_private *)(((struct _ya_timer_heap *)heap)->private))->mutex) {
  ya_pthread_mutex_lock(((struct ya_timer_heap_private *)(((struct _ya_timer_heap *)heap)->private))->mutex, "src/timer.c", 114);
 }
 ((struct ya_timer_entry_private *)(((struct _ya_timer_entry *)this)->private))->_timer_value.sec = expires.sec;
 ((struct ya_timer_entry_private *)(((struct _ya_timer_entry *)this)->private))->_timer_value.msec = expires.msec;
 ((struct ya_timer_entry_private *)(((struct _ya_timer_entry *)this)->private))->heap = heap;
 {
  struct _ya_timer_entry *node = ya_list_search(&((struct ya_timer_heap_private *)(((ya_timer_heap_t *)heap)->private))->entrys, &expires, bigger);
  if(node) {
   ya_list_insert_before(node, this);
  }else {
   ya_list_insert_before(&((struct ya_timer_heap_private *)(((struct _ya_timer_heap *)heap)->private))->entrys, this);
  }
 }
 if (((struct ya_timer_heap_private *)(((struct _ya_timer_heap *)heap)->private))->mutex) {
  ya_pthread_mutex_unlock(((struct ya_timer_heap_private *)(((struct _ya_timer_heap *)heap)->private))->mutex);
 }
 return YA_SUCCESS;
}

variable_types: struct _ya_timer_heap { struct BASE_CLASS_OBJECT { struct ya_list_t { void *prev; void *next; } list_node; void (*dtor)(void *obj); int ref; char class_name[64]; } _; void *private; void (*dtor)(void *obj); void (*set_lock)(void *_this, union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } *lock, int auto_del); unsigned int (*poll)(void *_this); } *

variable_types: struct ya_time_val { long sec; long msec; }


repo: nichelnich/yalib

decompiled_code:
void __fastcall ya_timer_heap_dtor(__int64 a1)
{
__int64 v2; // rax
__int64 v3; // rax
pthread_mutex_t *v4; // rdi

if ( !a1 )
_assert_fail("obj", "src/timer.c", 0xD1u, "ya_timer_heap_dtor");
while ( !(unsigned int)ya_list_empty(*(_QWORD *)(a1 + 96) + 24LL) )
{
v2 = ya_list_get(*(_QWORD *)(a1 + 96) + 24LL, 0LL);
if ( v2 )
(*(void (__fastcall **)(__int64))(v2 + 120))(v2);
}
v3 = *(_QWORD *)(a1 + 96);
v4 = *(pthread_mutex_t **)(v3 + 8);
if ( v4 && *(_DWORD *)(v3 + 16) )
pthread_mutex_destroy(v4);
free(*(void **)(a1 + 96));
}

canonical_decompiled_code:
void __fastcall func9(__int64 a1)
{
__int64 v2; // rax
__int64 v3; // rax
pthread_mutex_t *v4; // rdi

if ( !a1 )
_assert_fail("obj", "src/timer.c", 0xD1u, "ya_timer_heap_dtor");
while ( !(unsigned int)ya_list_empty(*(_QWORD *)(a1 + 96) + 24LL) )
{
v2 = ya_list_get(*(_QWORD *)(a1 + 96) + 24LL, 0LL);
if ( v2 )
(*(void (__fastcall **)(__int64))(v2 + 120))(v2);
}
v3 = *(_QWORD *)(a1 + 96);
v4 = *(pthread_mutex_t **)(v3 + 8);
if ( v4 && *(_DWORD *)(v3 + 16) )
pthread_mutex_destroy(v4);
free(*(void **)(a1 + 96));
}

original_code:
void ya_timer_heap_dtor(void *obj)
{
 ya_timer_heap_t *heap = (ya_timer_heap_t *) obj;
 ((void) sizeof ((obj) ? 1 : 0), __extension__ ({ if (obj) ; else __assert_fail ("obj", "src/timer.c", 209, __extension__ __PRETTY_FUNCTION__); }));
 while(!ya_list_empty(&((struct ya_timer_heap_private *)(((ya_timer_heap_t *)obj)->private))->entrys)) {
  ya_timer_entry_t *node;
  node = ya_list_get(&((struct ya_timer_heap_private *)(((ya_timer_heap_t *)obj)->private))->entrys, 0);
  if(node) {
   node->cancel(node);
  }
 }
 if(((struct ya_timer_heap_private *)(((ya_timer_heap_t *)obj)->private))->mutex && ((struct ya_timer_heap_private *)(((ya_timer_heap_t *)obj)->private))->auto_delete_lock) {
  pthread_mutex_destroy(((struct ya_timer_heap_private *)(((ya_timer_heap_t *)obj)->private))->mutex);
 }
 free(heap->private);
}

canonical_original_code:
void ya_timer_heap_dtor(void *obj)
{
 struct _ya_timer_heap *heap = (ya_timer_heap_t *) obj;
 ((void) sizeof ((obj) ? 1 : 0), __extension__ ({ if (obj) ; else __assert_fail ("obj", "src/timer.c", 209, __extension__ __PRETTY_FUNCTION__); }));
 while(!ya_list_empty(&((struct ya_timer_heap_private *)(((struct _ya_timer_heap *)obj)->private))->entrys)) {
  struct _ya_timer_entry *node;
  node = ya_list_get(&((struct ya_timer_heap_private *)(((struct _ya_timer_heap *)obj)->private))->entrys, 0);
  if(node) {
   node->cancel(node);
  }
 }
 if(((struct ya_timer_heap_private *)(((struct _ya_timer_heap *)obj)->private))->mutex && ((struct ya_timer_heap_private *)(((struct _ya_timer_heap *)obj)->private))->auto_delete_lock) {
  pthread_mutex_destroy(((struct ya_timer_heap_private *)(((struct _ya_timer_heap *)obj)->private))->mutex);
 }
 free(heap->private);
}

variable_types:
obj
void *

variable_types: struct _ya_timer_entry { struct BASE_CLASS_OBJECT { struct ya_list_t { void *prev; void *next; } list_node; void (*dtor)(void *obj); int ref; char class_name[64]; } _; void *private; void (*dtor)(void *obj); int (*schedule)(void *_this, struct _ya_timer_heap { struct BASE_CLASS_OBJECT _; void *private; void (*dtor)(void *obj); void (*set_lock)(void *_this, union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } *lock, int auto_del); unsigned int (*poll)(void *_this); } *heap, struct ya_time_val { long sec; long msec; } *delay); int (*cancel)(void *_this); int (*get_id)(void *_this); void *(*get_usr_data)(void *_this); int (*set_usr_data)(void *_this, void *usr_data); } *

return_type: void

user_defined_types: struct _ya_timer_heap { struct BASE_CLASS_OBJECT _; void *private; void (*dtor)(void *obj); void (*set_lock)(void *_this, union pthread_mutex_t *lock, int auto_del); unsigned int (*poll)(void *_this); }

user_defined_types: struct _ya_timer_entry { struct BASE_CLASS_OBJECT _; void *private; void (*dtor)(void *obj); int (*schedule)(void *_this, struct _ya_timer_heap *heap, struct ya_time_val *delay); int (*cancel)(void *_this); int (*get_id)(void *_this); void *(*get_usr_data)(void *_this); int (*set_usr_data)(void *_this, void *usr_data); }

user_defined_types: struct ya_timer_heap_private { unsigned int max_entries; union pthread_mutex_t *mutex; int auto_delete_lock; struct _ya_timer_entry entrys; }

user_defined_types: struct BASE_CLASS_OBJECT { struct ya_list_t list_node; void (*dtor)(void *obj); int ref; char class_name[64]; }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }


decompiled_code:
void __fastcall ya_timer_entry_dtor(__int64 a1)
{
if ( !a1 )
_assert_fail("obj", "src/timer.c", 0x102u, "ya_timer_entry_dtor");
if ( !(unsigned int)ya_list_original() )
(*(void (__fastcall **)(__int64))(a1 + 120))(a1);
free(*(void **)(a1 + 96));
}

canonical_decompiled_code:
void __fastcall func10(__int64 a1)
{
if ( !a1 )
_assert_fail("obj", "src/timer.c", 0x102u, "ya_timer_entry_dtor");
if ( !(unsigned int)ya_list_original() )
(*(void (__fastcall **)(__int64))(a1 + 120))(a1);
free(*(void **)(a1 + 96));
}

original_code:
void ya_timer_entry_dtor(void *obj)
{
 ya_timer_entry_t *entry = (ya_timer_entry_t *)obj;
 ((void) sizeof ((obj) ? 1 : 0), __extension__ ({ if (obj) ; else __assert_fail ("obj", "src/timer.c", 258, __extension__ __PRETTY_FUNCTION__); }));
 if(!ya_list_original(entry)) {
  entry->cancel(entry);
 }
 free(entry->private);
}

canonical_original_code:
void ya_timer_entry_dtor(void *obj)
{
 struct _ya_timer_entry *entry = (ya_timer_entry_t *)obj;
 ((void) sizeof ((obj) ? 1 : 0), __extension__ ({ if (obj) ; else __assert_fail ("obj", "src/timer.c", 258, __extension__ __PRETTY_FUNCTION__); }));
 if(!ya_list_original(entry)) {
  entry->cancel(entry);
 }
 free(entry->private);
}

user_defined_types: struct ya_list_t { void *prev; void *next; }

user_defined_types: struct ya_time_val { long sec; long msec; }

user_defined_types: struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; }


delete

decompiled_code:
void __fastcall delete(void *ptr)
{
(*((void (**)(void))ptr + 2))();
free(ptr);
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
(*((void (**)(void))ptr + 2))();
free(ptr);
}

original_code:
static void delete(void *obj)
{
 struct BASE_CLASS_OBJECT *class_obj = (struct BASE_CLASS_OBJECT *)obj;
 class_obj->dtor(class_obj);
 free(class_obj);
}

variable_types: struct BASE_CLASS_OBJECT { struct ya_list_t { void *prev; void *next; } list_node; void (*dtor)(void *obj); int ref; char class_name[64]; } *


decompiled_code:
__int64 base_class_ctor(__int64 a1, __int64 (__fastcall *a2)(__int64, __int64, __va_list_tag *), __int64 a3, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a3);
return a2(a1, a3, va);
}

canonical_decompiled_code:
__int64 func1(__int64 a1, __int64 (__fastcall *a2)(__int64, __int64, __va_list_tag *), __int64 a3, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a3);
return a2(a1, a3, va);
}

original_code:
void *base_class_ctor(void *obj, ctor_type ctor, dtor_type dtor, ...)
{
 void *ret;
 va_list ap;
 __builtin_va_start(ap,dtor);
 ret = ctor(obj, dtor, &ap);
 __builtin_va_end(ap);
 return ret;
}

canonical_original_code:
void *base_class_ctor(void *obj, void *ctor(void *obj, void (*dtor)(void *obj), __builtin_va_list *ap), void dtor(void *obj), ...)
{
 void *ret;
 __builtin_va_list ap;
 __builtin_va_start(ap,dtor);
 ret = ctor(obj, dtor, &ap);
 __builtin_va_end(ap);
 return ret;
}

variable_types: void *(void *obj, void (*dtor)(void *obj), __builtin_va_list *ap)

variable_types:
dtor
void (void *obj)

variable_types:
ret
void *

return_type: void *


decompiled_code:
void __fastcall ref_obj(__int64 a1)
{
++*(_DWORD *)(a1 + 24);
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1)
{
++*(_DWORD *)(a1 + 24);
}

original_code:
void ref_obj(void *obj)
{
 struct BASE_CLASS_OBJECT *class_obj = (struct BASE_CLASS_OBJECT *)obj;
 class_obj->ref ++;
}


new

decompiled_code:
char *new(__int64 a1, size_t a2, __int64 (__fastcall *a3)(char *, __int64, __va_list_tag *), __int64 a4, ...)
{
char *v6; // rax
char *v7; // rbx
gcc_va_list va; // [rsp+8h] [rbp-F0h] BYREF

v6 = (char *)calloc(1uLL, a2);
v7 = v6;
if ( v6 )
{
ya_list_init(v6);
*((_QWORD *)v7 + 2) = a4;
ref_obj((__int64)v7);
if ( a1 )
ya_strcpy(v7 + 28, a1, 64LL);
va_start(va, a4);
if ( !a3(v7, a4, va) )
{
free(v7);
v7 = 0LL;
}
}
return v7;
}

canonical_decompiled_code:
char *func3(__int64 a1, size_t a2, __int64 (__fastcall *a3)(char *, __int64, __va_list_tag *), __int64 a4, ...)
{
char *v6; // rax
char *v7; // rbx
gcc_va_list va; // [rsp+8h] [rbp-F0h] BYREF

v6 = (char *)calloc(1uLL, a2);
v7 = v6;
if ( v6 )
{
ya_list_init(v6);
*((_QWORD *)v7 + 2) = a4;
func2((__int64)v7);
if ( a1 )
ya_strcpy(v7 + 28, a1, 64LL);
va_start(va, a4);
if ( !a3(v7, a4, va) )
{
free(v7);
v7 = 0LL;
}
}
return v7;
}

original_code:
void *new(const char *name, size_t size, ctor_type ctor, dtor_type dtor, ...)
{
 struct BASE_CLASS_OBJECT *obj = calloc(1, size);
 va_list ap;
 void *ret;
 if (!obj) {
  return ((void *)0);
 }
 ya_list_init(obj);
 obj->dtor = dtor;
 ref_obj(obj);
 if(name) {
  ya_strcpy(obj->class_name, name, sizeof(obj->class_name));
 }
 __builtin_va_start(ap,dtor);
 ret = ctor(obj, dtor, &ap);
 __builtin_va_end(ap);
 if(!ret) {
  free(obj);
  return ((void *)0);
 }
 return obj;
}

canonical_original_code:
void *new(char *name, unsigned long size, void *ctor(void *obj, void (*dtor)(void *obj), __builtin_va_list *ap), void dtor(void *obj), ...)
{
 struct BASE_CLASS_OBJECT *obj = calloc(1, size);
 __builtin_va_list ap;
 void *ret;
 if (!obj) {
  return ((void *)0);
 }
 ya_list_init(obj);
 obj->dtor = dtor;
 ref_obj(obj);
 if(name) {
  ya_strcpy(obj->class_name, name, sizeof(obj->class_name));
 }
 __builtin_va_start(ap,dtor);
 ret = ctor(obj, dtor, &ap);
 __builtin_va_end(ap);
 if(!ret) {
  free(obj);
  return ((void *)0);
 }
 return obj;
}

variable_types:
name
char *

variable_types:
size
unsigned long


decompiled_code:
void __fastcall unref_obj(_DWORD *a1)
{
int v1; // eax

if ( a1 )
{
v1 = a1[6] - 1;
a1[6] = v1;
if ( v1 <= 0 )
delete(a1);
}
}

original_code:
void unref_obj(void *obj)
{
 struct BASE_CLASS_OBJECT *class_obj = (struct BASE_CLASS_OBJECT *)obj;
 if(!obj) {
  return ;
 }
 class_obj->ref --;
 if(class_obj->ref <= 0) {
  delete(obj);
 }
}


class

decompiled_code:
__int64 __fastcall class(__int64 a1)
{
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
return a1;
}

original_code:
struct BASE_CLASS_OBJECT *class(void *obj)
{
 return (struct BASE_CLASS_OBJECT *)obj;
}

return_type: struct BASE_CLASS_OBJECT { struct ya_list_t { void *prev; void *next; } list_node; void (*dtor)(void *obj); int ref; char class_name[64]; } *


decompiled_code:
int ya_log(__int64 a1, const char *a2, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a2);
return printf(a2, va);
}

canonical_decompiled_code:
int func0(__int64 a1, const char *a2, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a2);
return printf(a2, va);
}

original_code:
void ya_log(int level, const char *format, ...)
{
 va_list arg;
 __builtin_va_start(arg,format);
 printf(format, arg);
 __builtin_va_end(arg);
}

canonical_original_code:
void ya_log(int level, char *format, ...)
{
 __builtin_va_list arg;
 __builtin_va_start(arg,format);
 printf(format, arg);
 __builtin_va_end(arg);
}

variable_types: level int

variable_types:
format
char *


decompiled_code:
_BOOL8 __fastcall ya_list_empty(__int64 a1)
{
return *(_QWORD *)(a1 + 8) == a1;
}

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

original_code:
int ya_list_empty(const void *node)
{
    return ((ya_list_t*)node)->next == node;
}

canonical_original_code:
int ya_list_empty(void *node)
{
    return ((struct ya_list_t *)node)->next == node;
}

variable_types:
node
void *

return_type: int


decompiled_code:
_BOOL8 __fastcall ya_list_original(_QWORD *a1)
{
_BOOL8 result; // rax

result = 0LL;
if ( (_QWORD *)a1[1] == a1 )
result = *a1 == (_QWORD)a1;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(_QWORD *a1)
{
_BOOL8 result; // rax

result = 0LL;
if ( (_QWORD *)a1[1] == a1 )
result = *a1 == (_QWORD)a1;
return result;
}

original_code:
int ya_list_original(const void *node)
{
 return ((ya_list_t*)node)->next == node && ((ya_list_t*)node)->prev == node;
}

canonical_original_code:
int ya_list_original(void *node)
{
 return ((struct ya_list_t *)node)->next == node && ((struct ya_list_t *)node)->prev == node;
}


decompiled_code:
__int64 __fastcall ya_list_size(__int64 a1)
{
__int64 v1; // rax
unsigned int v2; // edx

v1 = *(_QWORD *)(a1 + 8);
if ( !v1 || a1 == v1 )
return 0;
v2 = 0;
do
{
++v2;
v1 = *(_QWORD *)(v1 + 8);
}
while ( v1 && a1 != v1 );
return v2;
}

original_code:
int ya_list_size(const void *list)
{
    const ya_list_t *node = (const ya_list_t*) ((const ya_list_t*)list)->next;
    int count = 0;
    while (node && node != list) {
 ++count;
 node = (ya_list_t*)node->next;
    }
    return count;
}

canonical_original_code:
int ya_list_size(void *list)
{
    struct ya_list_t *node = (const ya_list_t*) ((const ya_list_t*)list)->next;
    int count = 0;
    while (node && node != list) {
 ++count;
 node = (struct ya_list_t *)node->next;
    }
    return count;
}

variable_types:
list
void *

variable_types: struct ya_list_t { void *prev; void *next; } *

variable_types: count int


decompiled_code:
__int64 __fastcall ya_list_search(__int64 a1, __int64 a2, unsigned int (__fastcall *a3)(__int64, __int64))
{
__int64 v4; // rbx

v4 = *(_QWORD *)(a1 + 8);
if ( a1 == v4 )
return 0LL;
while ( a3(a2, v4) )
{
v4 = *(_QWORD *)(v4 + 8);
if ( a1 == v4 )
return 0LL;
}
if ( a1 == v4 )
v4 = 0LL;
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2, unsigned int (__fastcall *a3)(__int64, __int64))
{
__int64 v4; // rbx

v4 = *(_QWORD *)(a1 + 8);
if ( a1 == v4 )
return 0LL;
while ( a3(a2, v4) )
{
v4 = *(_QWORD *)(v4 + 8);
if ( a1 == v4 )
return 0LL;
}
if ( a1 == v4 )
v4 = 0LL;
return v4;
}

original_code:
void * ya_list_search(void *list, void *value,
          int (*comp)(void *value, const void *node))
{
 ya_list_t *p = (ya_list_t *) ((ya_list_t*)list)->next;
    while (p != list && (*comp)(value, p) != 0)
 p = (ya_list_t *) p->next;
    return p==list ? ((void *)0) : p;
}

canonical_original_code:
void *ya_list_search(void *list, void *value, int (*comp)(void *value, void *node))
{
 struct ya_list_t *p = (ya_list_t *) ((ya_list_t*)list)->next;
    while (p != list && (*comp)(value, p) != 0)
 p = (struct ya_list_t *) p->next;
    return p==list ? ((void *)0) : p;
}

variable_types:
value
void *

variable_types:
comp
int (*)(void *value, void *node)


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

result = *(_QWORD *)(a1 + 8);
if ( !result || a1 == result )
return 0LL;
if ( a2 )
{
v3 = 0;
while ( 1 )
{
++v3;
result = *(_QWORD *)(result + 8);
if ( !result || a1 == result )
break;
if ( a2 == v3 )
return result;
}
result = 0LL;
}
return result;
}

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

result = *(_QWORD *)(a1 + 8);
if ( !result || a1 == result )
return 0LL;
if ( a2 )
{
v3 = 0;
while ( 1 )
{
++v3;
result = *(_QWORD *)(result + 8);
if ( !result || a1 == result )
break;
if ( a2 == v3 )
return result;
}
result = 0LL;
}
return result;
}

original_code:
void *ya_list_get(const void *list, int pos)
{
 ya_list_t *node = (ya_list_t*) ((const ya_list_t*)list)->next;
 int count = 0;
 while (node && node != list) {
  if(count == pos) {
   return node;
  }
  ++count;
  node = (ya_list_t*)node->next;
 }
 return ((void *)0);
}

canonical_original_code:
void *ya_list_get(void *list, int pos)
{
 struct ya_list_t *node = (ya_list_t*) ((const ya_list_t*)list)->next;
 int count = 0;
 while (node && node != list) {
  if(count == pos) {
   return node;
  }
  ++count;
  node = (struct ya_list_t *)node->next;
 }
 return ((void *)0);
}

variable_types: pos int


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

*a2 = *a1;
a2[1] = a1;
barrier();
result = *a1;
*(_QWORD *)(*a1 + 8) = a2;
*a1 = (__int64)a2;
return result;
}

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

*a2 = *a1;
a2[1] = a1;
barrier();
result = *a1;
*(_QWORD *)(*a1 + 8) = a2;
*a1 = (__int64)a2;
return result;
}

original_code:
void ya_list_insert_before(void *pos, void *node)
{
    ((ya_list_t*)node)->prev = ((ya_list_t*)pos)->prev;
    ((ya_list_t*)node)->next = pos;
    barrier();
    ((ya_list_t*) ((ya_list_t*)pos)->prev)->next = node;
    ((ya_list_t*)pos)->prev = node;
}

canonical_original_code:
void ya_list_insert_before(void *pos, void *node)
{
    ((struct ya_list_t *)node)->prev = ((struct ya_list_t *)pos)->prev;
    ((struct ya_list_t *)node)->next = pos;
    barrier();
    ((struct ya_list_t *) ((struct ya_list_t *)pos)->prev)->next = node;
    ((struct ya_list_t *)pos)->prev = node;
}

variable_types:
pos
void *


decompiled_code:
__int64 __fastcall ya_list_add(__int64 a1, _QWORD *a2, int a3)
{
__int64 *v5; // rdi
int v6; // eax
__int64 result; // rax

if ( !a2 )
return 0xFFFFFFFFLL;
if ( a3 == -1 || (int)ya_list_size(a1) <= a3 )
{
ya_list_insert_after(a1, a2);
result = 0LL;
}
else
{
v5 = *(__int64 **)(a1 + 8);
if ( (__int64 *)a1 != v5 )
{
v6 = 0;
if ( a3 > 0 )
{
do
{
++v6;
v5 = (__int64 *)v5[1];
}
while ( (__int64 *)a1 != v5 && a3 > v6 );
}
}
ya_list_insert_before(v5, a2);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, _QWORD *a2, int a3)
{
__int64 *v5; // rdi
int v6; // eax
__int64 result; // rax

if ( !a2 )
return 0xFFFFFFFFLL;
if ( a3 == -1 || (int)func4(a1) <= a3 )
{
ya_list_insert_after(a1, a2);
result = 0LL;
}
else
{
v5 = *(__int64 **)(a1 + 8);
if ( (__int64 *)a1 != v5 )
{
v6 = 0;
if ( a3 > 0 )
{
do
{
++v6;
v5 = (__int64 *)v5[1];
}
while ( (__int64 *)a1 != v5 && a3 > v6 );
}
}
func8(v5, a2);
result = 0LL;
}
return result;
}

original_code:
int ya_list_add(void *list, void *node, int pos)
{
 ya_list_t *cur_node = (ya_list_t*) ((ya_list_t*)list)->next;
 int count = 0;
 if (list == ((void *)0) || node == ((void *)0))
  return -1;
 if (pos == -1 || pos >= ya_list_size(list))
 {
  ya_list_insert_after(list, node);
  return 0;
 }
 while (cur_node != list && count < pos) {
  ++count;
  cur_node = (ya_list_t*)cur_node->next;
 }
 ya_list_insert_before(cur_node, node);
 return 0;
}

canonical_original_code:
int ya_list_add(void *list, void *node, int pos)
{
 struct ya_list_t *cur_node = (ya_list_t*) ((ya_list_t*)list)->next;
 int count = 0;
 if (list == ((void *)0) || node == ((void *)0))
  return -1;
 if (pos == -1 || pos >= ya_list_size(list))
 {
  ya_list_insert_after(list, node);
  return 0;
 }
 while (cur_node != list && count < pos) {
  ++count;
  cur_node = (struct ya_list_t *)cur_node->next;
 }
 ya_list_insert_before(cur_node, node);
 return 0;
}


decompiled_code:
void __fastcall ya_free(void **a1)
{
free(*a1);
*a1 = 0LL;
}

canonical_decompiled_code:
void __fastcall func0(void **a1)
{
free(*a1);
*a1 = 0LL;
}

original_code:
void ya_free(void **ptr)
{
 free(*ptr);
 *ptr = ((void *)0);
}

variable_types:
ptr
void **


decompiled_code:
__int64 __fastcall ya_pthread_mutex_lock(pthread_mutex_t *mutex, const char *a2, unsigned int a3)
{
pthread_t v4; // rbx
unsigned int v5; // ebp

v4 = pthread_self();
ya_log(3LL, "LOCK_BEGIN--tid:%d, info:%s:%d", v4, a2, a3);
v5 = pthread_mutex_lock(mutex);
ya_log(3LL, "LOCK_END--tid:%d", v4);
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func1(pthread_mutex_t *mutex, const char *a2, unsigned int a3)
{
pthread_t v4; // rbx
unsigned int v5; // ebp

v4 = pthread_self();
ya_log(3LL, "LOCK_BEGIN--tid:%d, info:%s:%d", v4, a2, a3);
v5 = pthread_mutex_lock(mutex);
ya_log(3LL, "LOCK_END--tid:%d", v4);
return v5;
}

original_code:
int ya_pthread_mutex_lock(pthread_mutex_t *mutex, const char *file, int line)
{
 int ret;
 ya_log(LOG_LEVEL_DEBUG, "LOCK_BEGIN--tid:%d, info:%s:%d", pthread_self(), file, line);
 ret = pthread_mutex_lock(mutex);
 ya_log(LOG_LEVEL_DEBUG, "LOCK_END--tid:%d", pthread_self());
 return ret;
}

canonical_original_code:
int ya_pthread_mutex_lock(union pthread_mutex_t *mutex, char *file, int line)
{
 int ret;
 ya_log(LOG_LEVEL_DEBUG, "LOCK_BEGIN--tid:%d, info:%s:%d", pthread_self(), file, line);
 ret = pthread_mutex_lock(mutex);
 ya_log(LOG_LEVEL_DEBUG, "LOCK_END--tid:%d", pthread_self());
 return ret;
}

variable_types: union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } *

variable_types:
file
char *

variable_types: line int

variable_types: ret int


decompiled_code:
__int64 __fastcall ya_pthread_mutex_trylock(pthread_mutex_t *mutex, const char *a2, unsigned int a3)
{
pthread_t v4; // rbp
unsigned int v5; // ebx

v4 = pthread_self();
ya_log(3LL, "TRYLOCK_BEGIN--tid:%d, info:%s:%d", v4, a2, a3);
v5 = pthread_mutex_trylock(mutex);
if ( v5 )
ya_log(3LL, "TRYLOCK_END_FIALED--tid:%d", v4);
else
ya_log(3LL, "TRYLOCK_END_SUCCEED--tid:%d", v4);
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func2(pthread_mutex_t *mutex, const char *a2, unsigned int a3)
{
pthread_t v4; // rbp
unsigned int v5; // ebx

v4 = pthread_self();
ya_log(3LL, "TRYLOCK_BEGIN--tid:%d, info:%s:%d", v4, a2, a3);
v5 = pthread_mutex_trylock(mutex);
if ( v5 )
ya_log(3LL, "TRYLOCK_END_FIALED--tid:%d", v4);
else
ya_log(3LL, "TRYLOCK_END_SUCCEED--tid:%d", v4);
return v5;
}

original_code:
int ya_pthread_mutex_trylock(pthread_mutex_t *mutex, const char *file, int line)
{
 int ret;
 ya_log(LOG_LEVEL_DEBUG, "TRYLOCK_BEGIN--tid:%d, info:%s:%d", pthread_self(), file, line);
 ret = pthread_mutex_trylock(mutex);
 if (0 == ret)
 {
  ya_log(LOG_LEVEL_DEBUG, "TRYLOCK_END_SUCCEED--tid:%d", pthread_self());
 }
 else
 {
  ya_log(LOG_LEVEL_DEBUG, "TRYLOCK_END_FIALED--tid:%d", pthread_self());
 }
 return ret;
}

canonical_original_code:
int ya_pthread_mutex_trylock(union pthread_mutex_t *mutex, char *file, int line)
{
 int ret;
 ya_log(LOG_LEVEL_DEBUG, "TRYLOCK_BEGIN--tid:%d, info:%s:%d", pthread_self(), file, line);
 ret = pthread_mutex_trylock(mutex);
 if (0 == ret)
 {
  ya_log(LOG_LEVEL_DEBUG, "TRYLOCK_END_SUCCEED--tid:%d", pthread_self());
 }
 else
 {
  ya_log(LOG_LEVEL_DEBUG, "TRYLOCK_END_FIALED--tid:%d", pthread_self());
 }
 return ret;
}


decompiled_code:
__int64 __fastcall ya_pthread_mutex_unlock(pthread_mutex_t *a1)
{
unsigned int v1; // ebx
pthread_t v2; // rax
const char *v3; // rcx

v1 = pthread_mutex_unlock(a1);
v2 = pthread_self();
ya_log(3LL, "UNLOCK--tid:%d, info:%s", v2, v3);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func3(pthread_mutex_t *a1)
{
unsigned int v1; // ebx
pthread_t v2; // rax
const char *v3; // rcx

v1 = pthread_mutex_unlock(a1);
v2 = pthread_self();
ya_log(3LL, "UNLOCK--tid:%d, info:%s", v2, v3);
return v1;
}

original_code:
int ya_pthread_mutex_unlock(pthread_mutex_t *mutex)
{
 int ret;
 ret = pthread_mutex_unlock(mutex);
 ya_log(LOG_LEVEL_DEBUG, "UNLOCK--tid:%d, info:%s", pthread_self());
 return ret;
}

canonical_original_code:
int ya_pthread_mutex_unlock(union pthread_mutex_t *mutex)
{
 int ret;
 ret = pthread_mutex_unlock(mutex);
 ya_log(LOG_LEVEL_DEBUG, "UNLOCK--tid:%d, info:%s", pthread_self());
 return ret;
}


decompiled_code:
__int64 __fastcall ya_gettickcount(__time_t *a1)
{
int v1; // eax
unsigned int v2; // ecx
struct timespec v4; // [rsp+0h] [rbp-18h] BYREF

v1 = clock_gettime(1, &v4);
v2 = 1;
if ( !v1 )
{
v2 = 0;
*a1 = v4.tv_sec;
a1[1] = v4.tv_nsec / 1000000;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func4(__time_t *a1)
{
int v1; // eax
unsigned int v2; // ecx
struct timespec v4; // [rsp+0h] [rbp-18h] BYREF

v1 = clock_gettime(1, &v4);
v2 = 1;
if ( !v1 )
{
v2 = 0;
*a1 = v4.tv_sec;
a1[1] = v4.tv_nsec / 1000000;
}
return v2;
}

original_code:
ya_status_t ya_gettickcount(ya_time_val *tv)
{
 struct timespec tp;
 if (clock_gettime(1, &tp) != 0)
 {
  return YA_ERROR;
 }
 tv->sec = tp.tv_sec;
 tv->msec = tp.tv_nsec / 1000000;
 return YA_SUCCESS;
}

canonical_original_code:
int ya_gettickcount(struct ya_time_val *tv)
{
 struct timespec tp;
 if (clock_gettime(1, &tp) != 0)
 {
  return YA_ERROR;
 }
 tv->sec = tp.tv_sec;
 tv->msec = tp.tv_nsec / 1000000;
 return YA_SUCCESS;
}

variable_types: struct ya_time_val { long sec; long msec; } *

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


original_code:
int ya_time_val_cmp(ya_time_val *t1, ya_time_val *t2)
{
 if (t1->msec + t1->sec * 1000 == t2->msec + t2->sec * 1000)
 {
  return 0;
 }
 else if (t1->msec + t1->sec * 1000 > t2->msec + t2->sec * 1000)
 {
  return 1;
 }
 else
 {
  return -1;
 }
}

canonical_original_code:
int ya_time_val_cmp(struct ya_time_val *t1, struct ya_time_val *t2)
{
 if (t1->msec + t1->sec * 1000 == t2->msec + t2->sec * 1000)
 {
  return 0;
 }
 else if (t1->msec + t1->sec * 1000 > t2->msec + t2->sec * 1000)
 {
  return 1;
 }
 else
 {
  return -1;
 }
}


decompiled_code:
int __fastcall ya_sleep(__int64 a1, __int64 a2)
{
struct timeval v3; // [rsp+0h] [rbp-18h] BYREF

v3.tv_sec = a2 / 1000000 + a1;
v3.tv_usec = a2 % 1000000;
return select(0, 0LL, 0LL, 0LL, &v3);
}

canonical_decompiled_code:
int __fastcall func7(__int64 a1, __int64 a2)
{
struct timeval v3; // [rsp+0h] [rbp-18h] BYREF

v3.tv_sec = a2 / 1000000 + a1;
v3.tv_usec = a2 % 1000000;
return select(0, 0LL, 0LL, 0LL, &v3);
}

original_code:
void ya_sleep(time_t sec, suseconds_t usec)
{
 struct timeval tv;
 tv.tv_sec = sec + usec / (1000000);
 tv.tv_usec = usec % (1000000);
 select(0, ((void *)0), ((void *)0), ((void *)0), &tv);
}

canonical_original_code:
void ya_sleep(long sec, long usec)
{
 struct timeval tv;
 tv.tv_sec = sec + usec / (1000000);
 tv.tv_usec = usec % (1000000);
 select(0, ((void *)0), ((void *)0), ((void *)0), &tv);
}

variable_types: sec long

variable_types: usec long

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


decompiled_code:
char *__fastcall ya_strcpy(char *dest, char *src, size_t a3)
{
if ( !dest || !src )
_assert_fail("dest && src", "src/string.c", 0xCu, "ya_strcpy");
memset(dest, 0, a3);
return strncpy(dest, src, a3 - 1);
}

canonical_decompiled_code:
char *__fastcall func0(char *dest, char *src, size_t a3)
{
if ( !dest || !src )
_assert_fail("dest && src", "src/string.c", 0xCu, "ya_strcpy");
memset(dest, 0, a3);
return strncpy(dest, src, a3 - 1);
}

original_code:
char *ya_strcpy(char *dest, const char *src, size_t n)
{
 ((void) sizeof ((dest && src) ? 1 : 0), __extension__ ({ if (dest && src) ; else __assert_fail ("dest && src", "src/string.c", 12, __extension__ __PRETTY_FUNCTION__); }));
 memset(dest, 0, n);
 return strncpy(dest, src, n - 1);
}

canonical_original_code:
char *ya_strcpy(char *dest, char *src, unsigned long n)
{
 ((void) sizeof ((dest && src) ? 1 : 0), __extension__ ({ if (dest && src) ; else __assert_fail ("dest && src", "src/string.c", 12, __extension__ __PRETTY_FUNCTION__); }));
 memset(dest, 0, n);
 return strncpy(dest, src, n - 1);
}

variable_types:
dest
char *

variable_types:
src
char *

variable_types:
n
unsigned long

return_type: char *


runBuddyBoxThread

repo: nicholasrobinson/BuddyBox-PPM

decompiled_code:
void __fastcall __noreturn runBuddyBoxThread(void *a1)
{
char *v1; // rbp

v1 = (char *)a1 + 32;
while ( 1 )
{
if ( !*((_DWORD *)a1 + 93) || !*((_DWORD *)a1 + 8) )
{
LABEL_14:
*((_DWORD *)a1 + 93) = 0;
pthread_exit(0LL);
}
if ( *((_DWORD *)a1 + 95) )
break;
if ( *((_DWORD *)a1 + 94) )
{
LABEL_4:
if ( !(unsigned int)readPortAudioStream(a1) )
goto LABEL_14;
if ( *((_DWORD *)a1 + 94) )
readBufferIntoBuddyBoxInputChannelBuffer(v1, *((_QWORD *)a1 + 1), *((unsigned int *)a1 + 4));
LABEL_7:
if ( *((_DWORD *)a1 + 95) )
writeBuddyBoxOutputChannelBufferIntoBuffer(v1, *((_QWORD *)a1 + 1), *((unsigned int *)a1 + 4));
}
}
if ( !(unsigned int)writePortAudioStream(a1) )
goto LABEL_14;
if ( !*((_DWORD *)a1 + 94) )
goto LABEL_7;
goto LABEL_4;
}

canonical_decompiled_code:
void __fastcall __noreturn func0(void *a1)
{
char *v1; // rbp

v1 = (char *)a1 + 32;
while ( 1 )
{
if ( !*((_DWORD *)a1 + 93) || !*((_DWORD *)a1 + 8) )
{
LABEL_14:
*((_DWORD *)a1 + 93) = 0;
pthread_exit(0LL);
}
if ( *((_DWORD *)a1 + 95) )
break;
if ( *((_DWORD *)a1 + 94) )
{
LABEL_4:
if ( !(unsigned int)readPortAudioStream(a1) )
goto LABEL_14;
if ( *((_DWORD *)a1 + 94) )
readBufferIntoBuddyBoxInputChannelBuffer(v1, *((_QWORD *)a1 + 1), *((unsigned int *)a1 + 4));
LABEL_7:
if ( *((_DWORD *)a1 + 95) )
writeBuddyBoxOutputChannelBufferIntoBuffer(v1, *((_QWORD *)a1 + 1), *((unsigned int *)a1 + 4));
}
}
if ( !(unsigned int)writePortAudioStream(a1) )
goto LABEL_14;
if ( !*((_DWORD *)a1 + 94) )
goto LABEL_7;
goto LABEL_4;
}

original_code:
void* runBuddyBoxThread(void *arguments)
{
    PASBuddyBox *pasBB = (PASBuddyBox *) arguments;
    while(pasBB->running && pasBB->bb.active &&
          (!pasBB->outputEnabled || writePortAudioStream(&pasBB->pas)) &&
          (!pasBB->inputEnabled || readPortAudioStream(&pasBB->pas)))
    {
        if (pasBB->inputEnabled)
            readBufferIntoBuddyBoxInputChannelBuffer(&pasBB->bb, pasBB->pas.bufferedSamples, pasBB->pas.bufferSize);
        if (pasBB->outputEnabled)
            writeBuddyBoxOutputChannelBufferIntoBuffer(&pasBB->bb, pasBB->pas.bufferedSamples, pasBB->pas.bufferSize);
    }
    pasBB->running = 0;
    pthread_exit(0);
}

canonical_original_code:
void *runBuddyBoxThread(void *arguments)
{
    struct PASBuddyBox *pasBB = (PASBuddyBox *) arguments;
    while(pasBB->running && pasBB->bb.active &&
          (!pasBB->outputEnabled || writePortAudioStream(&pasBB->pas)) &&
          (!pasBB->inputEnabled || readPortAudioStream(&pasBB->pas)))
    {
        if (pasBB->inputEnabled)
            readBufferIntoBuddyBoxInputChannelBuffer(&pasBB->bb, pasBB->pas.bufferedSamples, pasBB->pas.bufferSize);
        if (pasBB->outputEnabled)
            writeBuddyBoxOutputChannelBufferIntoBuffer(&pasBB->bb, pasBB->pas.bufferedSamples, pasBB->pas.bufferSize);
    }
    pasBB->running = 0;
    pthread_exit(0);
}

variable_types:
arguments
void *

variable_types: struct PASBuddyBox { struct PortAudioStream { unsigned int sampleRate; float *bufferedSamples; unsigned int bufferSize; void *stream; } pas; struct BuddyBox { unsigned int active; unsigned int negativeShift; unsigned int sampleRate; unsigned int input; unsigned int lastInput; unsigned int inputChannel; unsigned int inputChannelCount; unsigned int outputChannelCount; unsigned int inputSampleCount; unsigned int outputSampleCount; unsigned int elapsedInputSampleCounts; unsigned int maxElapsedInputSampleCount; unsigned int lastInputEdgeSampleCount; unsigned int inputSynchroFrameCount; unsigned int badInputFrameCount; unsigned int outputOverflowSampleCount; unsigned int outputOverflowBufferSize; unsigned int inputChannelBuffer[20]; unsigned int outputChannelBuffer[20]; float minInputSample; float maxInputSample; float inputChannelValues[20]; float *outputOverflowBuffer; } bb; unsigned long buddyBoxThread; unsigned int sampleRate; unsigned int running; unsigned int inputEnabled; unsigned int outputEnabled; } *

user_defined_types: struct PASBuddyBox { struct PortAudioStream pas; struct BuddyBox bb; unsigned long buddyBoxThread; unsigned int sampleRate; unsigned int running; unsigned int inputEnabled; unsigned int outputEnabled; }


initializeBuddyBoxThread

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

result = initializePortAudioStream(a1, a1[92]);
a1[93] = 0;
a1[94] = 1;
a1[95] = 1;
return result;
}

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

result = initializePortAudioStream(a1, a1[92]);
a1[93] = 0;
a1[94] = 1;
a1[95] = 1;
return result;
}

original_code:
void initializeBuddyBoxThread(PASBuddyBox *pasBB)
{
    initializePortAudioStream(&pasBB->pas, pasBB->sampleRate);
    pasBB->running = 0;
    pasBB->inputEnabled = 1;
    pasBB->outputEnabled = 1;
}

canonical_original_code:
void initializeBuddyBoxThread(struct PASBuddyBox *pasBB)
{
    initializePortAudioStream(&pasBB->pas, pasBB->sampleRate);
    pasBB->running = 0;
    pasBB->inputEnabled = 1;
    pasBB->outputEnabled = 1;
}

user_defined_types: struct PortAudioStream { unsigned int sampleRate; float *bufferedSamples; unsigned int bufferSize; void *stream; }

user_defined_types: struct BuddyBox { unsigned int active; unsigned int negativeShift; unsigned int sampleRate; unsigned int input; unsigned int lastInput; unsigned int inputChannel; unsigned int inputChannelCount; unsigned int outputChannelCount; unsigned int inputSampleCount; unsigned int outputSampleCount; unsigned int elapsedInputSampleCounts; unsigned int maxElapsedInputSampleCount; unsigned int lastInputEdgeSampleCount; unsigned int inputSynchroFrameCount; unsigned int badInputFrameCount; unsigned int outputOverflowSampleCount; unsigned int outputOverflowBufferSize; unsigned int inputChannelBuffer[20]; unsigned int outputChannelBuffer[20]; float minInputSample; float maxInputSample; float inputChannelValues[20]; float *outputOverflowBuffer; }


startBuddyBoxThread

decompiled_code:
int __fastcall startBuddyBoxThread(void *arg)
{
*((_DWORD *)arg + 93) = 1;
initializeBuddyBox((char *)arg + 32, *((unsigned int *)arg + 92));
return pthread_create((pthread_t *)arg + 45, 0LL, (void *(*)(void *))runBuddyBoxThread, arg);
}

canonical_decompiled_code:
int __fastcall func2(void *arg)
{
*((_DWORD *)arg + 93) = 1;
initializeBuddyBox((char *)arg + 32, *((unsigned int *)arg + 92));
return pthread_create((pthread_t *)arg + 45, 0LL, (void *(*)(void *))runBuddyBoxThread, arg);
}

original_code:
void startBuddyBoxThread(PASBuddyBox *pasBB)
{
    pasBB->running = 1;
    initializeBuddyBox(&pasBB->bb, pasBB->sampleRate);
    pthread_create(&pasBB->buddyBoxThread, ((void *)0), runBuddyBoxThread, pasBB);
}

canonical_original_code:
void startBuddyBoxThread(struct PASBuddyBox *pasBB)
{
    pasBB->running = 1;
    initializeBuddyBox(&pasBB->bb, pasBB->sampleRate);
    pthread_create(&pasBB->buddyBoxThread, ((void *)0), runBuddyBoxThread, pasBB);
}


stopBuddyBoxThread

decompiled_code:
void __fastcall stopBuddyBoxThread(__int64 a1)
{
*(_DWORD *)(a1 + 372) = 0;
}

original_code:
void stopBuddyBoxThread(PASBuddyBox *pasBB)
{
    pasBB->running = 0;
}

canonical_original_code:
void stopBuddyBoxThread(struct PASBuddyBox *pasBB)
{
    pasBB->running = 0;
}


joinBuddyBoxThread

decompiled_code:
int __fastcall joinBuddyBoxThread(__int64 a1)
{
return pthread_join(*(_QWORD *)(a1 + 360), 0LL);
}

canonical_decompiled_code:
int __fastcall func4(__int64 a1)
{
return pthread_join(*(_QWORD *)(a1 + 360), 0LL);
}

original_code:
void joinBuddyBoxThread(PASBuddyBox *pasBB)
{
    pthread_join(pasBB->buddyBoxThread, ((void *)0));
}

canonical_original_code:
void joinBuddyBoxThread(struct PASBuddyBox *pasBB)
{
    pthread_join(pasBB->buddyBoxThread, ((void *)0));
}


cleanupBuddyBoxThread

decompiled_code:
__int64 cleanupBuddyBoxThread()
{
return closePortAudioStream();
}

canonical_decompiled_code:
__int64 func5()
{
return closePortAudioStream();
}

original_code:
void cleanupBuddyBoxThread(PASBuddyBox *pasBB)
{
    closePortAudioStream(&pasBB->pas);
}

canonical_original_code:
void cleanupBuddyBoxThread(struct PASBuddyBox *pasBB)
{
    closePortAudioStream(&pasBB->pas);
}


isBuddyBoxThreadRunning

decompiled_code:
__int64 __fastcall isBuddyBoxThreadRunning(__int64 a1)
{
return *(unsigned int *)(a1 + 372);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
return *(unsigned int *)(a1 + 372);
}

original_code:
unsigned int isBuddyBoxThreadRunning(PASBuddyBox *pasBB)
{
    return pasBB->running;
}

canonical_original_code:
unsigned int isBuddyBoxThreadRunning(struct PASBuddyBox *pasBB)
{
    return pasBB->running;
}

return_type: unsigned int


isBuddyBoxThreadCalibrated

decompiled_code:
_BOOL8 __fastcall isBuddyBoxThreadCalibrated(__int64 a1)
{
return (unsigned int)isBuddyBoxInputCalibrating(a1 + 32) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func7(__int64 a1)
{
return (unsigned int)isBuddyBoxInputCalibrating(a1 + 32) == 0;
}

original_code:
unsigned int isBuddyBoxThreadCalibrated(PASBuddyBox *pasBB)
{
    return !isBuddyBoxInputCalibrating(&pasBB->bb);
}

canonical_original_code:
unsigned int isBuddyBoxThreadCalibrated(struct PASBuddyBox *pasBB)
{
    return !isBuddyBoxInputCalibrating(&pasBB->bb);
}


setBuddyBoxThreadOutputChannelCount

decompiled_code:
void __fastcall setBuddyBoxThreadOutputChannelCount(__int64 a1, int a2)
{
*(_DWORD *)(a1 + 60) = a2;
}

canonical_decompiled_code:
void __fastcall func8(__int64 a1, int a2)
{
*(_DWORD *)(a1 + 60) = a2;
}

original_code:
void setBuddyBoxThreadOutputChannelCount(PASBuddyBox *pasBB, unsigned int channelCount)
{
    pasBB->bb.outputChannelCount = channelCount;
}

canonical_original_code:
void setBuddyBoxThreadOutputChannelCount(struct PASBuddyBox *pasBB, unsigned int channelCount)
{
    pasBB->bb.outputChannelCount = channelCount;
}

variable_types:
channelCount
unsigned int


setBuddyBoxThreadOutputChannelValue

decompiled_code:
__int64 __fastcall setBuddyBoxThreadOutputChannelValue(__int64 a1)
{
return setBuddyBoxOutputChannelValue(a1 + 32);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
return setBuddyBoxOutputChannelValue(a1 + 32);
}

original_code:
void setBuddyBoxThreadOutputChannelValue(PASBuddyBox *pasBB, unsigned int channel, float channelValue)
{
    setBuddyBoxOutputChannelValue(&pasBB->bb, channel, channelValue);
}

canonical_original_code:
void setBuddyBoxThreadOutputChannelValue(struct PASBuddyBox *pasBB, unsigned int channel, float channelValue)
{
    setBuddyBoxOutputChannelValue(&pasBB->bb, channel, channelValue);
}

variable_types:
channel
unsigned int

variable_types: channelValue float


getBuddyBoxThreadInputChannelCount

decompiled_code:
__int64 __fastcall getBuddyBoxThreadInputChannelCount(__int64 a1)
{
return *(unsigned int *)(a1 + 56);
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
return *(unsigned int *)(a1 + 56);
}

original_code:
unsigned int getBuddyBoxThreadInputChannelCount(PASBuddyBox *pasBB)
{
    return pasBB->bb.inputChannelCount;
}

canonical_original_code:
unsigned int getBuddyBoxThreadInputChannelCount(struct PASBuddyBox *pasBB)
{
    return pasBB->bb.inputChannelCount;
}


getBuddyBoxThreadInputChannelValue

decompiled_code:
float __fastcall getBuddyBoxThreadInputChannelValue(__int64 a1, unsigned int a2)
{
return *(float *)(a1 + 4LL * a2 + 268);
}

canonical_decompiled_code:
float __fastcall func11(__int64 a1, unsigned int a2)
{
return *(float *)(a1 + 4LL * a2 + 268);
}

original_code:
float getBuddyBoxThreadInputChannelValue(PASBuddyBox *pasBB, unsigned int channel)
{
    return pasBB->bb.inputChannelValues[channel];
}

canonical_original_code:
float getBuddyBoxThreadInputChannelValue(struct PASBuddyBox *pasBB, unsigned int channel)
{
    return pasBB->bb.inputChannelValues[channel];
}

return_type: float


disableBuddyBoxThreadInput

decompiled_code:
void __fastcall disableBuddyBoxThreadInput(__int64 a1)
{
*(_DWORD *)(a1 + 376) = 0;
}

original_code:
void disableBuddyBoxThreadInput(PASBuddyBox *pasBB)
{
    pasBB->inputEnabled = 0;
}

canonical_original_code:
void disableBuddyBoxThreadInput(struct PASBuddyBox *pasBB)
{
    pasBB->inputEnabled = 0;
}


enableBuddyBoxThreadInput

decompiled_code:
void __fastcall enableBuddyBoxThreadInput(__int64 a1)
{
*(_DWORD *)(a1 + 376) = 1;
}

original_code:
void enableBuddyBoxThreadInput(PASBuddyBox *pasBB)
{
    pasBB->inputEnabled = 1;
}

canonical_original_code:
void enableBuddyBoxThreadInput(struct PASBuddyBox *pasBB)
{
    pasBB->inputEnabled = 1;
}


disableBuddyBoxThreadOutput

decompiled_code:
void __fastcall disableBuddyBoxThreadOutput(__int64 a1)
{
*(_DWORD *)(a1 + 380) = 0;
}

original_code:
void disableBuddyBoxThreadOutput(PASBuddyBox *pasBB)
{
    pasBB->outputEnabled = 0;
}

canonical_original_code:
void disableBuddyBoxThreadOutput(struct PASBuddyBox *pasBB)
{
    pasBB->outputEnabled = 0;
}


enableBuddyBoxThreadOutput

decompiled_code:
void __fastcall enableBuddyBoxThreadOutput(__int64 a1)
{
*(_DWORD *)(a1 + 380) = 1;
}

original_code:
void enableBuddyBoxThreadOutput(PASBuddyBox *pasBB)
{
    pasBB->outputEnabled = 1;
}

canonical_original_code:
void enableBuddyBoxThreadOutput(struct PASBuddyBox *pasBB)
{
    pasBB->outputEnabled = 1;
}


intHandler

decompiled_code:
void intHandler()
{
running = 0;
}

canonical_decompiled_code:
void func0()
{
running = 0;
}

original_code:
void intHandler(int sig) {
    running = 0;
}

variable_types: sig int


generateOutput

decompiled_code:
__int64 __fastcall generateOutput(__int64 a1)
{
__int64 v1; // r12
__int64 result; // rax
unsigned int v3; // ebx

v1 = (unsigned int)getBuddyBoxThreadInputChannelCount();
result = setBuddyBoxThreadOutputChannelCount(a1, v1);
if ( (_DWORD)v1 )
{
v3 = 0;
do
{
getBuddyBoxThreadInputChannelValue(a1, v3);
result = setBuddyBoxThreadOutputChannelValue(a1, v3++);
}
while ( (_DWORD)v1 != v3 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 v1; // r12
__int64 result; // rax
unsigned int v3; // ebx

v1 = (unsigned int)getBuddyBoxThreadInputChannelCount();
result = setBuddyBoxThreadOutputChannelCount(a1, v1);
if ( (_DWORD)v1 )
{
v3 = 0;
do
{
getBuddyBoxThreadInputChannelValue(a1, v3);
result = setBuddyBoxThreadOutputChannelValue(a1, v3++);
}
while ( (_DWORD)v1 != v3 );
}
return result;
}

original_code:
void generateOutput(PASBuddyBox *pasBB)
{
    unsigned int i, outputChannelCount;
    outputChannelCount = getBuddyBoxThreadInputChannelCount(pasBB);
    setBuddyBoxThreadOutputChannelCount(pasBB, outputChannelCount);
    for (i = 0; i < outputChannelCount; i++)
        setBuddyBoxThreadOutputChannelValue(pasBB, i, getBuddyBoxThreadInputChannelValue(pasBB, i));
}

canonical_original_code:
void generateOutput(struct PASBuddyBox *pasBB)
{
    unsigned int i; unsigned int outputChannelCount;
    outputChannelCount = getBuddyBoxThreadInputChannelCount(pasBB);
    setBuddyBoxThreadOutputChannelCount(pasBB, outputChannelCount);
    for (i = 0; i < outputChannelCount; i++)
        setBuddyBoxThreadOutputChannelValue(pasBB, i, getBuddyBoxThreadInputChannelValue(pasBB, i));
}

variable_types:
i
unsigned int

variable_types:
outputChannelCount
unsigned int


displayInput

decompiled_code:
int __fastcall displayInput(__int64 a1, double a2)
{
int v2; // eax
int v3; // ebp
unsigned int i; // ebx

v2 = getBuddyBoxThreadInputChannelCount();
if ( v2 )
{
v3 = v2;
for ( i = 0; i != v3; ++i )
{
getBuddyBoxThreadInputChannelValue(a1, i);
a2 = *(float *)&a2;
printf("%f\t", a2);
}
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1, double a2)
{
int v2; // eax
int v3; // ebp
unsigned int i; // ebx

v2 = getBuddyBoxThreadInputChannelCount();
if ( v2 )
{
v3 = v2;
for ( i = 0; i != v3; ++i )
{
getBuddyBoxThreadInputChannelValue(a1, i);
a2 = *(float *)&a2;
printf("%f\t", a2);
}
}
return putchar(10);
}

original_code:
void displayInput(PASBuddyBox *pasBB)
{
    unsigned int i, inputChannelCount;
    inputChannelCount = getBuddyBoxThreadInputChannelCount(pasBB);
    for (i = 0; i < inputChannelCount; i++)
        printf("%f\t", getBuddyBoxThreadInputChannelValue(pasBB, i));
    printf("\n");
}

canonical_original_code:
void displayInput(struct PASBuddyBox *pasBB)
{
    unsigned int i; unsigned int inputChannelCount;
    inputChannelCount = getBuddyBoxThreadInputChannelCount(pasBB);
    for (i = 0; i < inputChannelCount; i++)
        printf("%f\t", getBuddyBoxThreadInputChannelValue(pasBB, i));
    printf("\n");
}

variable_types:
inputChannelCount
unsigned int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
double v3; // xmm0_8
int v4; // eax
_DWORD v6[102]; // [rsp+0h] [rbp-198h] BYREF

signal(9, (__sighandler_t)intHandler);
signal(2, (__sighandler_t)intHandler);
v4 = 124000;
if ( argc > 1 )
v4 = strtol(argv[1], 0LL, 0);
v6[92] = v4;
initializeBuddyBoxThread(v6);
while ( running )
{
startBuddyBoxThread(v6);
while ( running )
{
if ( !(unsigned int)isBuddyBoxThreadRunning(v6) )
break;
generateOutput((__int64)v6);
if ( (unsigned int)isBuddyBoxThreadCalibrated(v6) )
displayInput((__int64)v6, v3);
usleep(0x186A0u);
}
stopBuddyBoxThread(v6);
joinBuddyBoxThread(v6);
}
cleanupBuddyBoxThread(v6);
puts("Program Halted...");
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
double v3; // xmm0_8
int v4; // eax
_DWORD v6[102]; // [rsp+0h] [rbp-198h] BYREF

signal(9, (__sighandler_t)intHandler);
signal(2, (__sighandler_t)intHandler);
v4 = 124000;
if ( argc > 1 )
v4 = strtol(argv[1], 0LL, 0);
v6[92] = v4;
initializeBuddyBoxThread(v6);
while ( running )
{
startBuddyBoxThread(v6);
while ( running )
{
if ( !(unsigned int)isBuddyBoxThreadRunning(v6) )
break;
func1((__int64)v6);
if ( (unsigned int)isBuddyBoxThreadCalibrated(v6) )
func2((__int64)v6, v3);
usleep(0x186A0u);
}
stopBuddyBoxThread(v6);
joinBuddyBoxThread(v6);
}
cleanupBuddyBoxThread(v6);
puts("Program Halted...");
return 0;
}

original_code:
int main(int argc, const char * argv[])
{
    signal(9, intHandler);
    signal(2, intHandler);
    PASBuddyBox pasBB;
    pasBB.sampleRate = (argc > 1) ? (unsigned int) strtol(argv[1], ((void *)0), 0) : DEFAULT_SAMPLE_RATE;
    initializeBuddyBoxThread(&pasBB);
    while(running)
    {
        startBuddyBoxThread(&pasBB);
        while(running && isBuddyBoxThreadRunning(&pasBB))
        {
            generateOutput(&pasBB);
            if (isBuddyBoxThreadCalibrated(&pasBB))
                displayInput(&pasBB);
            usleep(100000);
        }
        stopBuddyBoxThread(&pasBB);
        joinBuddyBoxThread(&pasBB);
    }
    cleanupBuddyBoxThread(&pasBB);
    printf("Program Halted...\n");
}

canonical_original_code:
int main(int argc, char *argv[])
{
    signal(9, intHandler);
    signal(2, intHandler);
    struct PASBuddyBox pasBB;
    pasBB.sampleRate = (argc > 1) ? (unsigned int) strtol(argv[1], ((void *)0), 0) : DEFAULT_SAMPLE_RATE;
    initializeBuddyBoxThread(&pasBB);
    while(running)
    {
        startBuddyBoxThread(&pasBB);
        while(running && isBuddyBoxThreadRunning(&pasBB))
        {
            generateOutput(&pasBB);
            if (isBuddyBoxThreadCalibrated(&pasBB))
                displayInput(&pasBB);
            usleep(100000);
        }
        stopBuddyBoxThread(&pasBB);
        joinBuddyBoxThread(&pasBB);
    }
    cleanupBuddyBoxThread(&pasBB);
    printf("Program Halted...\n");
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct PASBuddyBox { struct PortAudioStream { unsigned int sampleRate; float *bufferedSamples; unsigned int bufferSize; void *stream; } pas; struct BuddyBox { unsigned int active; unsigned int negativeShift; unsigned int sampleRate; unsigned int input; unsigned int lastInput; unsigned int inputChannel; unsigned int inputChannelCount; unsigned int outputChannelCount; unsigned int inputSampleCount; unsigned int outputSampleCount; unsigned int elapsedInputSampleCounts; unsigned int maxElapsedInputSampleCount; unsigned int lastInputEdgeSampleCount; unsigned int inputSynchroFrameCount; unsigned int badInputFrameCount; unsigned int outputOverflowSampleCount; unsigned int outputOverflowBufferSize; unsigned int inputChannelBuffer[20]; unsigned int outputChannelBuffer[20]; float minInputSample; float maxInputSample; float inputChannelValues[20]; float *outputOverflowBuffer; } bb; unsigned long buddyBoxThread; unsigned int sampleRate; unsigned int running; unsigned int inputEnabled; unsigned int outputEnabled; }


allocatePortAudioStreamBuffer

decompiled_code:
void *__fastcall allocatePortAudioStreamBuffer(__int64 a1)
{
void *v1; // rax

*(_DWORD *)(a1 + 16) = 4096;
v1 = malloc(0x4000uLL);
*(_QWORD *)(a1 + 8) = v1;
if ( !v1 )
{
puts("PortAudioStream:\tCould Not Allocate Sample Buffer.");
exit(1);
}
return memset(v1, 0, 0x4000uLL);
}

canonical_decompiled_code:
void *__fastcall func0(__int64 a1)
{
void *v1; // rax

*(_DWORD *)(a1 + 16) = 4096;
v1 = malloc(0x4000uLL);
*(_QWORD *)(a1 + 8) = v1;
if ( !v1 )
{
puts("PortAudioStream:\tCould Not Allocate Sample Buffer.");
exit(1);
}
return memset(v1, 0, 0x4000uLL);
}

original_code:
void allocatePortAudioStreamBuffer(PortAudioStream *pas)
    {
        pas->bufferSize = FRAMES_PER_BUFFER * NUM_CHANNELS;
        pas->bufferedSamples = (float *) malloc(pas->bufferSize * sizeof(float));
        if(pas->bufferedSamples == ((void *)0))
        {
            printf("PortAudioStream:\tCould Not Allocate Sample Buffer.\n");
            exit(1);
        }
        memset(pas->bufferedSamples, 0, pas->bufferSize * sizeof(float));
    }

canonical_original_code:
void allocatePortAudioStreamBuffer(struct PortAudioStream *pas)
    {
        pas->bufferSize = FRAMES_PER_BUFFER * NUM_CHANNELS;
        pas->bufferedSamples = (float *) malloc(pas->bufferSize * sizeof(float));
        if(pas->bufferedSamples == ((void *)0))
        {
            printf("PortAudioStream:\tCould Not Allocate Sample Buffer.\n");
            exit(1);
        }
        memset(pas->bufferedSamples, 0, pas->bufferSize * sizeof(float));
    }

variable_types: struct PortAudioStream { unsigned int sampleRate; float *bufferedSamples; unsigned int bufferSize; void *stream; } *


terminatePortAudioStream

decompiled_code:
__int64 __fastcall terminatePortAudioStream(__int64 a1)
{
if ( *(_QWORD *)(a1 + 24) )
{
Pa_AbortStream();
Pa_CloseStream(*(_QWORD *)(a1 + 24));
}
free(*(void **)(a1 + 8));
return Pa_Terminate();
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
if ( *(_QWORD *)(a1 + 24) )
{
Pa_AbortStream();
Pa_CloseStream(*(_QWORD *)(a1 + 24));
}
free(*(void **)(a1 + 8));
return Pa_Terminate();
}

original_code:
void terminatePortAudioStream(PortAudioStream *pas)
            {
                if(pas->stream)
                {
                    Pa_AbortStream(pas->stream);
                    Pa_CloseStream(pas->stream);
                }
                free(pas->bufferedSamples);
                Pa_Terminate();
            }

canonical_original_code:
void terminatePortAudioStream(struct PortAudioStream *pas)
            {
                if(pas->stream)
                {
                    Pa_AbortStream(pas->stream);
                    Pa_CloseStream(pas->stream);
                }
                free(pas->bufferedSamples);
                Pa_Terminate();
            }


decompiled_code:
void __fastcall __noreturn handlePortAudioStreamInitializationError(__int64 a1, unsigned int a2)
{
const char *v2; // rax

terminatePortAudioStream(a1);
fwrite("PortAudioStream:\tAn error occured.\n", 1uLL, 0x23uLL, stderr);
fprintf(stderr, "Error number:\t%d\n", a2);
v2 = (const char *)Pa_GetErrorText(a2);
fprintf(stderr, "Error message:\t%s\n", v2);
exit(-1);
}

canonical_decompiled_code:
void __fastcall __noreturn func2(__int64 a1, unsigned int a2)
{
const char *v2; // rax

func1(a1);
fwrite("PortAudioStream:\tAn error occured.\n", 1uLL, 0x23uLL, stderr);
fprintf(stderr, "Error number:\t%d\n", a2);
v2 = (const char *)Pa_GetErrorText(a2);
fprintf(stderr, "Error message:\t%s\n", v2);
exit(-1);
}

original_code:
void handlePortAudioStreamInitializationError(PortAudioStream *pas, PaError err)
        {
            terminatePortAudioStream(pas);
            fprintf(stderr, "PortAudioStream:\tAn error occured.\n");
            fprintf(stderr, "Error number:\t%d\n", err);
            fprintf(stderr, "Error message:\t%s\n", Pa_GetErrorText(err));
            exit(-1);
        }

canonical_original_code:
void handlePortAudioStreamInitializationError(struct PortAudioStream *pas, int err)
        {
            terminatePortAudioStream(pas);
            fprintf(stderr, "PortAudioStream:\tAn error occured.\n");
            fprintf(stderr, "Error number:\t%d\n", err);
            fprintf(stderr, "Error message:\t%s\n", Pa_GetErrorText(err));
            exit(-1);
        }

variable_types: err int


initializePortAudio

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

result = Pa_Initialize();
if ( (_DWORD)result )
handlePortAudioStreamInitializationError(a1, result);
return result;
}

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

result = Pa_Initialize();
if ( (_DWORD)result )
func2(a1, result);
return result;
}

original_code:
void initializePortAudio(PortAudioStream *pas)
    {
        PaError err;
        err = Pa_Initialize();
        if(err != paNoError)
            handlePortAudioStreamInitializationError(pas, err);
    }

canonical_original_code:
void initializePortAudio(struct PortAudioStream *pas)
    {
        int err;
        err = Pa_Initialize();
        if(err != paNoError)
            handlePortAudioStreamInitializationError(pas, err);
    }


configurePortAudioInputParameters

decompiled_code:
__int64 __fastcall configurePortAudioInputParameters(__int64 a1)
{
unsigned int v1; // eax
__int64 result; // rax

v1 = Pa_GetDefaultInputDevice();
*(_DWORD *)a1 = v1;
*(_DWORD *)(a1 + 4) = 1;
*(_QWORD *)(a1 + 8) = 1LL;
result = Pa_GetDeviceInfo(v1);
*(_OWORD *)(a1 + 16) = *(unsigned __int64 *)(result + 48);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
unsigned int v1; // eax
__int64 result; // rax

v1 = Pa_GetDefaultInputDevice();
*(_DWORD *)a1 = v1;
*(_DWORD *)(a1 + 4) = 1;
*(_QWORD *)(a1 + 8) = 1LL;
result = Pa_GetDeviceInfo(v1);
*(_OWORD *)(a1 + 16) = *(unsigned __int64 *)(result + 48);
return result;
}

original_code:
void configurePortAudioInputParameters(PaStreamParameters *inputParameters)
    {
        inputParameters->device = Pa_GetDefaultInputDevice();
        inputParameters->channelCount = NUM_CHANNELS;
        inputParameters->sampleFormat = ((PaSampleFormat) 0x00000001);
        inputParameters->suggestedLatency = Pa_GetDeviceInfo(inputParameters->device)->defaultHighInputLatency ;
        inputParameters->hostApiSpecificStreamInfo = ((void *)0);
    }

canonical_original_code:
void configurePortAudioInputParameters(struct PaStreamParameters *inputParameters)
    {
        inputParameters->device = Pa_GetDefaultInputDevice();
        inputParameters->channelCount = NUM_CHANNELS;
        inputParameters->sampleFormat = ((unsigned long) 0x00000001);
        inputParameters->suggestedLatency = Pa_GetDeviceInfo(inputParameters->device)->defaultHighInputLatency ;
        inputParameters->hostApiSpecificStreamInfo = ((void *)0);
    }

variable_types: struct PaStreamParameters { int device; int channelCount; unsigned long sampleFormat; double suggestedLatency; void *hostApiSpecificStreamInfo; } *


configurePortAudioOutputParameters

decompiled_code:
__int64 __fastcall configurePortAudioOutputParameters(__int64 a1)
{
unsigned int v1; // eax
__int64 result; // rax

v1 = Pa_GetDefaultOutputDevice();
*(_DWORD *)a1 = v1;
*(_DWORD *)(a1 + 4) = 1;
*(_QWORD *)(a1 + 8) = 1LL;
result = Pa_GetDeviceInfo(v1);
*(_OWORD *)(a1 + 16) = *(unsigned __int64 *)(result + 56);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
unsigned int v1; // eax
__int64 result; // rax

v1 = Pa_GetDefaultOutputDevice();
*(_DWORD *)a1 = v1;
*(_DWORD *)(a1 + 4) = 1;
*(_QWORD *)(a1 + 8) = 1LL;
result = Pa_GetDeviceInfo(v1);
*(_OWORD *)(a1 + 16) = *(unsigned __int64 *)(result + 56);
return result;
}

original_code:
void configurePortAudioOutputParameters(PaStreamParameters *outputParameters)
    {
        outputParameters->device = Pa_GetDefaultOutputDevice();
        outputParameters->channelCount = NUM_CHANNELS;
        outputParameters->sampleFormat = ((PaSampleFormat) 0x00000001);
        outputParameters->suggestedLatency = Pa_GetDeviceInfo(outputParameters->device)->defaultHighOutputLatency;
        outputParameters->hostApiSpecificStreamInfo = ((void *)0);
    }

canonical_original_code:
void configurePortAudioOutputParameters(struct PaStreamParameters *outputParameters)
    {
        outputParameters->device = Pa_GetDefaultOutputDevice();
        outputParameters->channelCount = NUM_CHANNELS;
        outputParameters->sampleFormat = ((unsigned long) 0x00000001);
        outputParameters->suggestedLatency = Pa_GetDeviceInfo(outputParameters->device)->defaultHighOutputLatency;
        outputParameters->hostApiSpecificStreamInfo = ((void *)0);
    }

user_defined_types: struct PaStreamParameters { int device; int channelCount; unsigned long sampleFormat; double suggestedLatency; void *hostApiSpecificStreamInfo; }


openPortAudioStream

decompiled_code:
__int64 __fastcall openPortAudioStream(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, char a7, int a8, int a9, int a10, char a11)
{
unsigned int v11; // eax
__int64 result; // rax

v11 = Pa_OpenStream(a1 + 24, &a11, &a7, 4096LL, 1LL, 0LL, (double)*(int *)a1, 0LL);
if ( v11 )
handlePortAudioStreamInitializationError(a1, v11);
result = Pa_StartStream(*(_QWORD *)(a1 + 24));
if ( (_DWORD)result )
handlePortAudioStreamInitializationError(a1, result);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, char a7, int a8, int a9, int a10, char a11)
{
unsigned int v11; // eax
__int64 result; // rax

v11 = Pa_OpenStream(a1 + 24, &a11, &a7, 4096LL, 1LL, 0LL, (double)*(int *)a1, 0LL);
if ( v11 )
func2(a1, v11);
result = Pa_StartStream(*(_QWORD *)(a1 + 24));
if ( (_DWORD)result )
func2(a1, result);
return result;
}

original_code:
void openPortAudioStream(PortAudioStream *pas, PaStreamParameters outputParameters, PaStreamParameters inputParameters)
    {
        PaError err;
        err = Pa_OpenStream(
            &pas->stream,
            &inputParameters,
            &outputParameters,
            pas->sampleRate,
            FRAMES_PER_BUFFER,
            ((PaStreamFlags) 0x00000001),
            ((void *)0),
            ((void *)0)
        );
        if(err != paNoError)
            handlePortAudioStreamInitializationError(pas, err);
        err = Pa_StartStream(pas->stream);
        if(err != paNoError)
            handlePortAudioStreamInitializationError(pas, err);
    }

canonical_original_code:
void openPortAudioStream(struct PortAudioStream *pas, struct PaStreamParameters outputParameters, struct PaStreamParameters inputParameters)
    {
        int err;
        err = Pa_OpenStream(
            &pas->stream,
            &inputParameters,
            &outputParameters,
            pas->sampleRate,
            FRAMES_PER_BUFFER,
            ((unsigned long) 0x00000001),
            ((void *)0),
            ((void *)0)
        );
        if(err != paNoError)
            handlePortAudioStreamInitializationError(pas, err);
        err = Pa_StartStream(pas->stream);
        if(err != paNoError)
            handlePortAudioStreamInitializationError(pas, err);
    }

variable_types: struct PaStreamParameters { int device; int channelCount; unsigned long sampleFormat; double suggestedLatency; void *hostApiSpecificStreamInfo; }


initializePortAudioStream

decompiled_code:
__int64 __fastcall initializePortAudioStream(_DWORD *a1, __int64 a2)
{
__int64 v2; // rdx
__int64 v3; // rcx
__int64 v4; // r8
__int64 v5; // r9
__int64 v7; // [rsp+0h] [rbp-48h] BYREF
__int64 v8; // [rsp+8h] [rbp-40h]
__int64 v9; // [rsp+10h] [rbp-38h]
__int64 v10; // [rsp+18h] [rbp-30h]
__int64 v11; // [rsp+20h] [rbp-28h] BYREF

*a1 = a2;
allocatePortAudioStreamBuffer((__int64)a1);
initializePortAudio((__int64)a1);
configurePortAudioInputParameters((__int64)&v11);
configurePortAudioOutputParameters((__int64)&v7);
return openPortAudioStream((__int64)a1, a2, v2, v3, v4, v5, v7, v8, v9, v10, v11);
}

original_code:
void initializePortAudioStream(PortAudioStream *pas, unsigned int sampleRate)
{
    PaStreamParameters inputParameters, outputParameters;
    pas->sampleRate = sampleRate;
    allocatePortAudioStreamBuffer(pas);
    initializePortAudio(pas);
    configurePortAudioInputParameters(&inputParameters);
    configurePortAudioOutputParameters(&outputParameters);
    openPortAudioStream(pas, outputParameters, inputParameters);
}

canonical_original_code:
void initializePortAudioStream(struct PortAudioStream *pas, unsigned int sampleRate)
{
    struct PaStreamParameters inputParameters; struct PaStreamParameters outputParameters;
    pas->sampleRate = sampleRate;
    allocatePortAudioStreamBuffer(pas);
    initializePortAudio(pas);
    configurePortAudioInputParameters(&inputParameters);
    configurePortAudioOutputParameters(&outputParameters);
    openPortAudioStream(pas, outputParameters, inputParameters);
}

variable_types:
sampleRate
unsigned int


readPortAudioStream

decompiled_code:
__int64 __fastcall readPortAudioStream(__int64 a1)
{
Pa_ReadStream(*(_QWORD *)(a1 + 24), *(_QWORD *)(a1 + 8), 4096LL);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
Pa_ReadStream(*(_QWORD *)(a1 + 24), *(_QWORD *)(a1 + 8), 4096LL);
return 1LL;
}

original_code:
unsigned int readPortAudioStream(PortAudioStream *pas)
{
    PaError err;
    err = Pa_ReadStream(pas->stream, pas->bufferedSamples, FRAMES_PER_BUFFER);
    if(err && (0))
        return handlePortAudioStreamFlowError(pas, err);
    else
        return 1;
}

canonical_original_code:
unsigned int readPortAudioStream(struct PortAudioStream *pas)
{
    int err;
    err = Pa_ReadStream(pas->stream, pas->bufferedSamples, FRAMES_PER_BUFFER);
    if(err && (0))
        return handlePortAudioStreamFlowError(pas, err);
    else
        return 1;
}


handlePortAudioStreamFlowError

decompiled_code:
__int64 __fastcall handlePortAudioStreamFlowError(__int64 a1, char a2)
{
terminatePortAudioStream(a1);
if ( (a2 & 2) != 0 )
fwrite("PortAudioStream:\tInput Overflow.\n", 1uLL, 0x21uLL, stderr);
if ( (a2 & 4) != 0 )
fwrite("PortAudioStream:\tOutput Underflow.\n", 1uLL, 0x23uLL, stderr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, char a2)
{
func1(a1);
if ( (a2 & 2) != 0 )
fwrite("PortAudioStream:\tInput Overflow.\n", 1uLL, 0x21uLL, stderr);
if ( (a2 & 4) != 0 )
fwrite("PortAudioStream:\tOutput Underflow.\n", 1uLL, 0x23uLL, stderr);
return 0LL;
}

original_code:
unsigned int handlePortAudioStreamFlowError(PortAudioStream *pas, PaError err)
    {
        terminatePortAudioStream(pas);
        if(err & ((PaStreamCallbackFlags) 0x00000002))
            fprintf(stderr, "PortAudioStream:\tInput Overflow.\n");
        if(err & ((PaStreamCallbackFlags) 0x00000004))
            fprintf(stderr, "PortAudioStream:\tOutput Underflow.\n");
        return 0;
    }

canonical_original_code:
unsigned int handlePortAudioStreamFlowError(struct PortAudioStream *pas, int err)
    {
        terminatePortAudioStream(pas);
        if(err & ((unsigned long) 0x00000002))
            fprintf(stderr, "PortAudioStream:\tInput Overflow.\n");
        if(err & ((unsigned long) 0x00000004))
            fprintf(stderr, "PortAudioStream:\tOutput Underflow.\n");
        return 0;
    }


writePortAudioStream

decompiled_code:
__int64 __fastcall writePortAudioStream(__int64 a1)
{
Pa_WriteStream(*(_QWORD *)(a1 + 24), *(_QWORD *)(a1 + 8), 4096LL);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
Pa_WriteStream(*(_QWORD *)(a1 + 24), *(_QWORD *)(a1 + 8), 4096LL);
return 1LL;
}

original_code:
unsigned int writePortAudioStream(PortAudioStream *pas)
{
    PaError err;
    err = Pa_WriteStream(pas->stream, pas->bufferedSamples, FRAMES_PER_BUFFER);
    if(err && (0))
        return handlePortAudioStreamFlowError(pas, err);
    else
        return 1;
}

canonical_original_code:
unsigned int writePortAudioStream(struct PortAudioStream *pas)
{
    int err;
    err = Pa_WriteStream(pas->stream, pas->bufferedSamples, FRAMES_PER_BUFFER);
    if(err && (0))
        return handlePortAudioStreamFlowError(pas, err);
    else
        return 1;
}


closePortAudioStream

decompiled_code:
__int64 __fastcall closePortAudioStream(__int64 a1)
{
unsigned int v1; // eax

v1 = Pa_StopStream(*(_QWORD *)(a1 + 24));
if ( v1 )
handlePortAudioStreamInitializationError(a1, v1);
return terminatePortAudioStream(a1);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
unsigned int v1; // eax

v1 = Pa_StopStream(*(_QWORD *)(a1 + 24));
if ( v1 )
func2(a1, v1);
return func1(a1);
}

original_code:
void closePortAudioStream(PortAudioStream *pas)
{
    PaError err;
    err = Pa_StopStream(pas->stream);
    if(err != paNoError)
        handlePortAudioStreamInitializationError(pas, err);
    terminatePortAudioStream(pas);
}

canonical_original_code:
void closePortAudioStream(struct PortAudioStream *pas)
{
    int err;
    err = Pa_StopStream(pas->stream);
    if(err != paNoError)
        handlePortAudioStreamInitializationError(pas, err);
    terminatePortAudioStream(pas);
}


repo: nichtverstehen/cync

decompiled_code:
__int64 __fastcall mlist_grow(_QWORD *a1, unsigned __int64 a2)
{
_QWORD *v3; // rdi
_QWORD *v4; // rax

v3 = (_QWORD *)(*a1 - 24LL);
if ( 0xFFFFFFFFFFFFFFE7LL / *v3 < a2 )
return 0xFFFFFFFFLL;
v4 = realloc(v3, a2 * *v3 + 24);
if ( !v4 )
return 0xFFFFFFFFLL;
v4[2] = a2;
*a1 = v4 + 3;
return 0LL;
}

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

v3 = (_QWORD *)(*a1 - 24LL);
if ( 0xFFFFFFFFFFFFFFE7LL / *v3 < a2 )
return 0xFFFFFFFFLL;
v4 = realloc(v3, a2 * *v3 + 24);
if ( !v4 )
return 0xFFFFFFFFLL;
v4[2] = a2;
*a1 = v4 + 3;
return 0LL;
}

original_code:
static int mlist_grow (void** list, size_t newsize)
{
 struct mlist_header_t* mlist = ((struct mlist_header_t*) *list - 1);
 const size_t elsize = mlist->elsize;
 const size_t maxelements = ((18446744073709551615UL) - sizeof (struct mlist_header_t)) / elsize;
 if (newsize > maxelements)
 {
  return -1;
 }
 mlist = realloc (mlist, sizeof (struct mlist_header_t) + newsize * elsize);
 if (!mlist)
 {
  return -1;
 }
 mlist->capacity = newsize;
 *list = mlist + 1;
 return 0;
}

canonical_original_code:
static int mlist_grow(void **list, unsigned long newsize)
{
 struct mlist_header_t *mlist = ((struct mlist_header_t*) *list - 1);
 unsigned long elsize = mlist->elsize;
 unsigned long maxelements = ((18446744073709551615UL) - sizeof (struct mlist_header_t)) / elsize;
 if (newsize > maxelements)
 {
  return -1;
 }
 mlist = realloc (mlist, sizeof (struct mlist_header_t) + newsize * elsize);
 if (!mlist)
 {
  return -1;
 }
 mlist->capacity = newsize;
 *list = mlist + 1;
 return 0;
}

variable_types:
list
void **

variable_types:
newsize
unsigned long

variable_types: struct mlist_header_t { unsigned long elsize; unsigned long len; unsigned long capacity; } *

variable_types:
elsize
unsigned long

variable_types:
maxelements
unsigned long


decompiled_code:
void __fastcall mlist_delete(__int64 a1)
{
free((void *)(a1 - 24));
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1)
{
free((void *)(a1 - 24));
}

original_code:
void mlist_delete (void* list)
{
 struct mlist_header_t* mlist = ((struct mlist_header_t*) list - 1);
 free (mlist);
}

canonical_original_code:
void mlist_delete(void *list)
{
 struct mlist_header_t *mlist = ((struct mlist_header_t*) list - 1);
 free (mlist);
}

variable_types:
list
void *

user_defined_types: struct mlist_header_t { unsigned long elsize; unsigned long len; unsigned long capacity; }


decompiled_code:
__int64 __fastcall mlist_len(__int64 a1)
{
return *(_QWORD *)(a1 - 16);
}

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

original_code:
size_t mlist_len (const void* list)
{
 const struct mlist_header_t* mlist = ((struct mlist_header_t*) list - 1);
 return mlist->len;
}

canonical_original_code:
unsigned long mlist_len(void *list)
{
 struct mlist_header_t *mlist = ((struct mlist_header_t*) list - 1);
 return mlist->len;
}

return_type: unsigned long


decompiled_code:
__int64 __fastcall mlist_capacity(__int64 a1)
{
return *(_QWORD *)(a1 - 8);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return *(_QWORD *)(a1 - 8);
}

original_code:
size_t mlist_capacity (const void* list)
{
 const struct mlist_header_t* mlist = ((struct mlist_header_t*) list - 1);
 return mlist->capacity;
}

canonical_original_code:
unsigned long mlist_capacity(void *list)
{
 struct mlist_header_t *mlist = ((struct mlist_header_t*) list - 1);
 return mlist->capacity;
}


decompiled_code:
char *__fastcall mlist_clone(__int64 a1)
{
size_t v1; // r12
char *v2; // rbp

v1 = *(_QWORD *)(a1 - 16) * *(_QWORD *)(a1 - 24) + 24LL;
v2 = (char *)malloc(v1);
memcpy(v2, (const void *)(a1 - 24), v1);
return v2 + 24;
}

canonical_decompiled_code:
char *__fastcall func4(__int64 a1)
{
size_t v1; // r12
char *v2; // rbp

v1 = *(_QWORD *)(a1 - 16) * *(_QWORD *)(a1 - 24) + 24LL;
v2 = (char *)malloc(v1);
memcpy(v2, (const void *)(a1 - 24), v1);
return v2 + 24;
}

original_code:
void* mlist_clone (const void* list)
{
 const struct mlist_header_t* mlist = ((struct mlist_header_t*) list - 1);
 const size_t cbs = sizeof (struct mlist_header_t) + mlist->elsize * mlist->len;
 struct mlist_header_t* newlist = malloc (cbs);
 memcpy (newlist, mlist, cbs);
 return &newlist[1];
}

canonical_original_code:
void *mlist_clone(void *list)
{
 struct mlist_header_t *mlist = ((struct mlist_header_t*) list - 1);
 unsigned long cbs = sizeof (struct mlist_header_t) + mlist->elsize * mlist->len;
 struct mlist_header_t *newlist = malloc (cbs);
 memcpy (newlist, mlist, cbs);
 return &newlist[1];
}

variable_types:
cbs
unsigned long


decompiled_code:
__int64 __fastcall mlist_add2(__int64 *a1, const void *a2, size_t a3)
{
__int64 v3; // rbx
unsigned __int64 v7; // rax
unsigned __int64 v8; // rdx
__int64 v9; // rbx
unsigned __int64 v10; // rdi
__int64 result; // rax
unsigned __int64 v12; // rsi

v3 = *a1;
if ( *(_QWORD *)(*a1 - 24) != a3 )
_assert_fail("mlist->elsize == elsize", "mlist.c", 0x56u, "mlist_add2");
v7 = *(_QWORD *)(v3 - 16);
v8 = *(_QWORD *)(v3 - 8);
if ( v7 > v8 )
_assert_fail("mlist->len <= mlist->capacity", "mlist.c", 0x57u, "mlist_add2");
if ( v7 > 0x7FFFFFFFFFFFFFFELL )
return -1LL;
v9 = v3 - 24;
if ( v7 == v8 )
{
v12 = 2 * v8;
if ( v8 > 0x7FFFFFFFFFFFFFFELL )
v12 = -1LL;
if ( (int)mlist_grow(a1, v12) < 0 )
return -1LL;
v9 = *a1 - 24;
}
v10 = *(_QWORD *)(v9 + 8);
if ( v10 >= *(_QWORD *)(v9 + 16) )
_assert_fail("mlist->len < mlist->capacity", "mlist.c", 0x69u, "mlist_add2");
memcpy((void *)(*a1 + a3 * v10), a2, a3);
result = *(_QWORD *)(v9 + 8);
*(_QWORD *)(v9 + 8) = result + 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 *a1, const void *a2, size_t a3)
{
__int64 v3; // rbx
unsigned __int64 v7; // rax
unsigned __int64 v8; // rdx
__int64 v9; // rbx
unsigned __int64 v10; // rdi
__int64 result; // rax
unsigned __int64 v12; // rsi

v3 = *a1;
if ( *(_QWORD *)(*a1 - 24) != a3 )
_assert_fail("mlist->elsize == elsize", "mlist.c", 0x56u, "mlist_add2");
v7 = *(_QWORD *)(v3 - 16);
v8 = *(_QWORD *)(v3 - 8);
if ( v7 > v8 )
_assert_fail("mlist->len <= mlist->capacity", "mlist.c", 0x57u, "mlist_add2");
if ( v7 > 0x7FFFFFFFFFFFFFFELL )
return -1LL;
v9 = v3 - 24;
if ( v7 == v8 )
{
v12 = 2 * v8;
if ( v8 > 0x7FFFFFFFFFFFFFFELL )
v12 = -1LL;
if ( (int)func0(a1, v12) < 0 )
return -1LL;
v9 = *a1 - 24;
}
v10 = *(_QWORD *)(v9 + 8);
if ( v10 >= *(_QWORD *)(v9 + 16) )
_assert_fail("mlist->len < mlist->capacity", "mlist.c", 0x69u, "mlist_add2");
memcpy((void *)(*a1 + a3 * v10), a2, a3);
result = *(_QWORD *)(v9 + 8);
*(_QWORD *)(v9 + 8) = result + 1;
return result;
}

original_code:
ssize_t mlist_add2 (void** list, const void* pel, size_t elsize)
{
 struct mlist_header_t* mlist = ((struct mlist_header_t*) *list - 1);
 ((void) sizeof ((mlist->elsize == elsize) ? 1 : 0), __extension__ ({ if (mlist->elsize == elsize) ; else __assert_fail ("mlist->elsize == elsize", "mlist.c", 86, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((mlist->len <= mlist->capacity) ? 1 : 0), __extension__ ({ if (mlist->len <= mlist->capacity) ; else __assert_fail ("mlist->len <= mlist->capacity", "mlist.c", 87, __extension__ __PRETTY_FUNCTION__); }));
 if (mlist->len >= 0x7fffffffffffffffL)
 {
  return -1;
 }
 if (mlist->capacity == mlist->len)
 {
  size_t newsize = mlist->capacity < ((18446744073709551615UL) >> 1) ? mlist->capacity << 1 : (18446744073709551615UL);
  if (mlist_grow (list, newsize) < 0)
  {
   return -1;
  }
  mlist = ((struct mlist_header_t*) *list - 1);
 }
 ((void) sizeof ((mlist->len < mlist->capacity) ? 1 : 0), __extension__ ({ if (mlist->len < mlist->capacity) ; else __assert_fail ("mlist->len < mlist->capacity", "mlist.c", 105, __extension__ __PRETTY_FUNCTION__); }));
 memcpy ((char*) *list + mlist->len * elsize, pel, elsize);
 mlist->len += 1;
 return mlist->len - 1;
}

canonical_original_code:
long mlist_add2(void **list, void *pel, unsigned long elsize)
{
 struct mlist_header_t *mlist = ((struct mlist_header_t*) *list - 1);
 ((void) sizeof ((mlist->elsize == elsize) ? 1 : 0), __extension__ ({ if (mlist->elsize == elsize) ; else __assert_fail ("mlist->elsize == elsize", "mlist.c", 86, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((mlist->len <= mlist->capacity) ? 1 : 0), __extension__ ({ if (mlist->len <= mlist->capacity) ; else __assert_fail ("mlist->len <= mlist->capacity", "mlist.c", 87, __extension__ __PRETTY_FUNCTION__); }));
 if (mlist->len >= 0x7fffffffffffffffL)
 {
  return -1;
 }
 if (mlist->capacity == mlist->len)
 {
  unsigned long newsize = mlist->capacity < ((18446744073709551615UL) >> 1) ? mlist->capacity << 1 : (18446744073709551615UL);
  if (mlist_grow (list, newsize) < 0)
  {
   return -1;
  }
  mlist = ((struct mlist_header_t *) *list - 1);
 }
 ((void) sizeof ((mlist->len < mlist->capacity) ? 1 : 0), __extension__ ({ if (mlist->len < mlist->capacity) ; else __assert_fail ("mlist->len < mlist->capacity", "mlist.c", 105, __extension__ __PRETTY_FUNCTION__); }));
 memcpy ((char *) *list + mlist->len * elsize, pel, elsize);
 mlist->len += 1;
 return mlist->len - 1;
}

variable_types:
pel
void *

return_type: long


decompiled_code:
unsigned __int64 __fastcall mlist_remove2(__int64 *a1, unsigned __int64 a2, size_t a3)
{
__int64 v5; // rbx
unsigned __int64 v6; // rsi
unsigned __int64 v7; // rsi
unsigned __int64 result; // rax
unsigned __int64 v9; // rsi

v5 = *a1;
v6 = *(_QWORD *)(*a1 - 16);
if ( v6 <= a2 )
_assert_fail("pos < mlist->len", "mlist.c", 0x73u, "mlist_remove2");
if ( *(_QWORD *)(v5 - 24) != a3 )
_assert_fail("mlist->elsize == elsize", "mlist.c", 0x74u, "mlist_remove2");
if ( v6 > *(_QWORD *)(v5 - 8) )
_assert_fail("mlist->len <= mlist->capacity", "mlist.c", 0x75u, "mlist_remove2");
v7 = v6 - 1;
if ( v7 > a2 )
memcpy((void *)(v5 + a3 * a2), (const void *)(v5 + a3 * v7), a3);
result = *(_QWORD *)(v5 - 16) - 1LL;
*(_QWORD *)(v5 - 16) = result;
v9 = *(_QWORD *)(v5 - 8) >> 1;
if ( v9 )
{
if ( result <= v9 )
result = mlist_grow(a1, v9);
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func6(__int64 *a1, unsigned __int64 a2, size_t a3)
{
__int64 v5; // rbx
unsigned __int64 v6; // rsi
unsigned __int64 v7; // rsi
unsigned __int64 result; // rax
unsigned __int64 v9; // rsi

v5 = *a1;
v6 = *(_QWORD *)(*a1 - 16);
if ( v6 <= a2 )
_assert_fail("pos < mlist->len", "mlist.c", 0x73u, "mlist_remove2");
if ( *(_QWORD *)(v5 - 24) != a3 )
_assert_fail("mlist->elsize == elsize", "mlist.c", 0x74u, "mlist_remove2");
if ( v6 > *(_QWORD *)(v5 - 8) )
_assert_fail("mlist->len <= mlist->capacity", "mlist.c", 0x75u, "mlist_remove2");
v7 = v6 - 1;
if ( v7 > a2 )
memcpy((void *)(v5 + a3 * a2), (const void *)(v5 + a3 * v7), a3);
result = *(_QWORD *)(v5 - 16) - 1LL;
*(_QWORD *)(v5 - 16) = result;
v9 = *(_QWORD *)(v5 - 8) >> 1;
if ( v9 )
{
if ( result <= v9 )
result = func0(a1, v9);
}
return result;
}

original_code:
void mlist_remove2 (void** list, size_t pos, size_t elsize)
{
 struct mlist_header_t* mlist = ((struct mlist_header_t*) *list - 1);
 ((void) sizeof ((pos < mlist->len) ? 1 : 0), __extension__ ({ if (pos < mlist->len) ; else __assert_fail ("pos < mlist->len", "mlist.c", 115, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((mlist->elsize == elsize) ? 1 : 0), __extension__ ({ if (mlist->elsize == elsize) ; else __assert_fail ("mlist->elsize == elsize", "mlist.c", 116, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((mlist->len <= mlist->capacity) ? 1 : 0), __extension__ ({ if (mlist->len <= mlist->capacity) ; else __assert_fail ("mlist->len <= mlist->capacity", "mlist.c", 117, __extension__ __PRETTY_FUNCTION__); }));
 if (pos < mlist->len - 1)
 {
  memcpy ((char*) *list + elsize * pos, (char*) *list + elsize * (mlist->len - 1), elsize);
 }
 mlist->len -= 1;
 if (mlist->len <= (mlist->capacity >> 1) && (mlist->capacity >> 1) >= 1 )
 {
  mlist_grow (list, mlist->capacity >> 1);
 }
}

canonical_original_code:
void mlist_remove2(void **list, unsigned long pos, unsigned long elsize)
{
 struct mlist_header_t *mlist = ((struct mlist_header_t*) *list - 1);
 ((void) sizeof ((pos < mlist->len) ? 1 : 0), __extension__ ({ if (pos < mlist->len) ; else __assert_fail ("pos < mlist->len", "mlist.c", 115, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((mlist->elsize == elsize) ? 1 : 0), __extension__ ({ if (mlist->elsize == elsize) ; else __assert_fail ("mlist->elsize == elsize", "mlist.c", 116, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((mlist->len <= mlist->capacity) ? 1 : 0), __extension__ ({ if (mlist->len <= mlist->capacity) ; else __assert_fail ("mlist->len <= mlist->capacity", "mlist.c", 117, __extension__ __PRETTY_FUNCTION__); }));
 if (pos < mlist->len - 1)
 {
  memcpy ((char *) *list + elsize * pos, (char *) *list + elsize * (mlist->len - 1), elsize);
 }
 mlist->len -= 1;
 if (mlist->len <= (mlist->capacity >> 1) && (mlist->capacity >> 1) >= 1 )
 {
  mlist_grow (list, mlist->capacity >> 1);
 }
}

variable_types:
pos
unsigned long


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

result = *a1;
if ( *(_QWORD *)(*a1 - 24) != a3 )
_assert_fail("mlist->elsize == elsize", "mlist.c", 0x89u, "mlist_reserve2");
if ( *(_QWORD *)(result - 8) <= a2 && *(_QWORD *)(result - 16) <= a2 )
result = mlist_grow(a1, a2);
return result;
}

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

result = *a1;
if ( *(_QWORD *)(*a1 - 24) != a3 )
_assert_fail("mlist->elsize == elsize", "mlist.c", 0x89u, "mlist_reserve2");
if ( *(_QWORD *)(result - 8) <= a2 && *(_QWORD *)(result - 16) <= a2 )
result = func0(a1, a2);
return result;
}

original_code:
void mlist_reserve2 (void** list, size_t len, size_t elsize)
{
 struct mlist_header_t* mlist = ((struct mlist_header_t*) *list - 1);
 ((void) sizeof ((mlist->elsize == elsize) ? 1 : 0), __extension__ ({ if (mlist->elsize == elsize) ; else __assert_fail ("mlist->elsize == elsize", "mlist.c", 137, __extension__ __PRETTY_FUNCTION__); }));
 if (mlist->capacity > len || len < mlist->len)
 {
  return;
 }
 mlist_grow (list, len);
}

canonical_original_code:
void mlist_reserve2(void **list, unsigned long len, unsigned long elsize)
{
 struct mlist_header_t *mlist = ((struct mlist_header_t*) *list - 1);
 ((void) sizeof ((mlist->elsize == elsize) ? 1 : 0), __extension__ ({ if (mlist->elsize == elsize) ; else __assert_fail ("mlist->elsize == elsize", "mlist.c", 137, __extension__ __PRETTY_FUNCTION__); }));
 if (mlist->capacity > len || len < mlist->len)
 {
  return;
 }
 mlist_grow (list, len);
}

variable_types:
len
unsigned long


decompiled_code:
__int64 __fastcall arl_close(void *a1)
{
free(a1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(void *a1)
{
free(a1);
return 0LL;
}

original_code:
int arl_close (AMY* my)
{
 free (my);
 return 0;
}

canonical_original_code:
int arl_close(struct AMY *my)
{
 free (my);
 return 0;
}

variable_types: struct AMY { int fd; char buf[1024]; unsigned long start; } *


decompiled_code:
_QWORD *hstack_new()
{
return hstack_new2(0x400uLL);
}

canonical_decompiled_code:
_QWORD *func0()
{
return hstack_new2(0x400uLL);
}

original_code:
hstack_t hstack_new ()
{
 return hstack_new2 (1024);
}

canonical_original_code:
struct hstack_header_t *hstack_new()
{
 return hstack_new2 (1024);
}

return_type: struct hstack_header_t { unsigned long capacity; unsigned long head; } *


decompiled_code:
void __fastcall hstack_delete(void *a1)
{
free(a1);
}

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

original_code:
void hstack_delete(hstack_t hstack)
{
 free (hstack);
}

canonical_original_code:
void hstack_delete(struct hstack_header_t *hstack)
{
 free (hstack);
}

variable_types: struct hstack_header_t { unsigned long capacity; unsigned long head; } *


decompiled_code:
unsigned __int64 *__fastcall hstack_push2(void **a1, const void *a2, size_t a3)
{
unsigned __int64 *result; // rax
__int64 v5; // rcx
unsigned __int64 v6; // r13
unsigned __int64 v7; // rdx
__int64 v8; // r12
unsigned __int64 v9; // r14
unsigned __int64 v10; // rdx

result = (unsigned __int64 *)*a1;
v5 = *((_QWORD *)*a1 + 1);
v6 = v5 + a3 + 16;
v7 = *(_QWORD *)*a1;
if ( v7 >= v6 )
{
LABEL_2:
v8 = (__int64)result + result[1] + 16;
*(_QWORD *)(v8 + a3 + 8) = a3 + 8;
result[1] += a3 + 8;
if ( a2 )
memcpy((void *)(v8 + 8), a2, a3);
else
memset((void *)(v8 + 8), 0, a3);
return (unsigned __int64 *)(v8 + 8);
}
v9 = v5 + 2 * a3 + 24;
v10 = 2 * v7;
if ( v9 < v10 )
v9 = v10;
result = (unsigned __int64 *)realloc(*a1, v9 + 16);
if ( result )
{
*result = v9;
*a1 = result;
if ( *result < v6 )
_assert_fail("need_capacity <= hstack->capacity", "hstack.c", 0x52u, "hstack_push2");
goto LABEL_2;
}
return result;
}

canonical_decompiled_code:
unsigned __int64 *__fastcall func2(void **a1, const void *a2, size_t a3)
{
unsigned __int64 *result; // rax
__int64 v5; // rcx
unsigned __int64 v6; // r13
unsigned __int64 v7; // rdx
__int64 v8; // r12
unsigned __int64 v9; // r14
unsigned __int64 v10; // rdx

result = (unsigned __int64 *)*a1;
v5 = *((_QWORD *)*a1 + 1);
v6 = v5 + a3 + 16;
v7 = *(_QWORD *)*a1;
if ( v7 >= v6 )
{
LABEL_2:
v8 = (__int64)result + result[1] + 16;
*(_QWORD *)(v8 + a3 + 8) = a3 + 8;
result[1] += a3 + 8;
if ( a2 )
memcpy((void *)(v8 + 8), a2, a3);
else
memset((void *)(v8 + 8), 0, a3);
return (unsigned __int64 *)(v8 + 8);
}
v9 = v5 + 2 * a3 + 24;
v10 = 2 * v7;
if ( v9 < v10 )
v9 = v10;
result = (unsigned __int64 *)realloc(*a1, v9 + 16);
if ( result )
{
*result = v9;
*a1 = result;
if ( *result < v6 )
_assert_fail("need_capacity <= hstack->capacity", "hstack.c", 0x52u, "hstack_push2");
goto LABEL_2;
}
return result;
}

original_code:
void* hstack_push2 (hstack_t* phstack, void* elem, size_t elsize)
{
 struct hstack_header_t* hstack = *phstack;
 const size_t need_capacity = hstack->head + 2 * sizeof (struct hstack_frame_t) + elsize;
 if (need_capacity > hstack->capacity)
 {
  const size_t new_capacity = ((hstack->capacity * 2) > (hstack->head + 3 * sizeof (struct hstack_frame_t) + 2 * elsize) ? hstack->capacity * 2 : hstack->head + 3 * sizeof (struct hstack_frame_t) + 2 * elsize);
  hstack = realloc (hstack, sizeof (struct hstack_header_t) + new_capacity);
  if (!hstack)
  {
   return ((void *)0);
  }
  hstack->capacity = new_capacity;
  *phstack = hstack;
 }
 ((void) sizeof ((need_capacity <= hstack->capacity) ? 1 : 0), __extension__ ({ if (need_capacity <= hstack->capacity) ; else __assert_fail ("need_capacity <= hstack->capacity", "hstack.c", 82, __extension__ __PRETTY_FUNCTION__); }));
 struct hstack_frame_t* topframe = (struct hstack_frame_t*) ((char*) ((struct hstack_header_t*) (hstack) + 1) + ((struct hstack_header_t*) hstack)->head);
 size_t framesize = sizeof (struct hstack_frame_t) + elsize;
 struct hstack_frame_t* dummyframe = (struct hstack_frame_t*) ((char*) topframe + framesize);
 dummyframe->prev_offset = framesize;
 hstack->head += framesize;
 if (elem)
 {
  memcpy ((&(topframe)->data[0]), elem, elsize);
 }
 else
 {
  memset ((&(topframe)->data[0]), 0, elsize);
 }
 return (&(topframe)->data[0]);
}

canonical_original_code:
void *hstack_push2(struct hstack_header_t **phstack, void *elem, unsigned long elsize)
{
 struct hstack_header_t *hstack = *phstack;
 unsigned long need_capacity = hstack->head + 2 * sizeof (struct hstack_frame_t) + elsize;
 if (need_capacity > hstack->capacity)
 {
  unsigned long new_capacity = ((hstack->capacity * 2) > (hstack->head + 3 * sizeof (struct hstack_frame_t) + 2 * elsize) ? hstack->capacity * 2 : hstack->head + 3 * sizeof (struct hstack_frame_t) + 2 * elsize);
  hstack = realloc (hstack, sizeof (struct hstack_header_t) + new_capacity);
  if (!hstack)
  {
   return ((void *)0);
  }
  hstack->capacity = new_capacity;
  *phstack = hstack;
 }
 ((void) sizeof ((need_capacity <= hstack->capacity) ? 1 : 0), __extension__ ({ if (need_capacity <= hstack->capacity) ; else __assert_fail ("need_capacity <= hstack->capacity", "hstack.c", 82, __extension__ __PRETTY_FUNCTION__); }));
 struct hstack_frame_t *topframe = (struct hstack_frame_t*) ((char*) ((struct hstack_header_t*) (hstack) + 1) + ((struct hstack_header_t*) hstack)->head);
 unsigned long framesize = sizeof (struct hstack_frame_t) + elsize;
 struct hstack_frame_t *dummyframe = (struct hstack_frame_t*) ((char*) topframe + framesize);
 dummyframe->prev_offset = framesize;
 hstack->head += framesize;
 if (elem)
 {
  memcpy ((&(topframe)->data[0]), elem, elsize);
 }
 else
 {
  memset ((&(topframe)->data[0]), 0, elsize);
 }
 return (&(topframe)->data[0]);
}

variable_types: struct hstack_header_t { unsigned long capacity; unsigned long head; } **

variable_types:
elem
void *

variable_types: struct hstack_frame_t { unsigned long prev_offset; char data[]; } *

variable_types:
framesize
unsigned long


decompiled_code:
__int64 __fastcall hstack_pop2(__int64 a1)
{
unsigned __int64 v1; // rax
unsigned __int64 v2; // rcx

v1 = *(_QWORD *)(*(_QWORD *)a1 + 8LL);
v2 = *(_QWORD *)(*(_QWORD *)a1 + v1 + 16);
if ( !v2 )
return 0xFFFFFFFFLL;
if ( v1 < v2 )
_assert_fail("hstack->head >= topframe->prev_offset", "hstack.c", 0x70u, "hstack_pop2");
*(_QWORD *)(*(_QWORD *)a1 + 8LL) = v1 - v2;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
unsigned __int64 v1; // rax
unsigned __int64 v2; // rcx

v1 = *(_QWORD *)(*(_QWORD *)a1 + 8LL);
v2 = *(_QWORD *)(*(_QWORD *)a1 + v1 + 16);
if ( !v2 )
return 0xFFFFFFFFLL;
if ( v1 < v2 )
_assert_fail("hstack->head >= topframe->prev_offset", "hstack.c", 0x70u, "hstack_pop2");
*(_QWORD *)(*(_QWORD *)a1 + 8LL) = v1 - v2;
return 0LL;
}

original_code:
int hstack_pop2 (hstack_t* phstack)
{
 struct hstack_header_t* hstack = *phstack;
 struct hstack_frame_t* topframe = (struct hstack_frame_t*) ((char*) ((struct hstack_header_t*) (hstack) + 1) + ((struct hstack_header_t*) hstack)->head);
 if (topframe->prev_offset == 0)
 {
  return -1;
 }
 ((void) sizeof ((hstack->head >= topframe->prev_offset) ? 1 : 0), __extension__ ({ if (hstack->head >= topframe->prev_offset) ; else __assert_fail ("hstack->head >= topframe->prev_offset", "hstack.c", 112, __extension__ __PRETTY_FUNCTION__); }));
 hstack->head = hstack->head - topframe->prev_offset;
 return 0;
}

canonical_original_code:
int hstack_pop2(struct hstack_header_t **phstack)
{
 struct hstack_header_t *hstack = *phstack;
 struct hstack_frame_t *topframe = (struct hstack_frame_t*) ((char*) ((struct hstack_header_t*) (hstack) + 1) + ((struct hstack_header_t*) hstack)->head);
 if (topframe->prev_offset == 0)
 {
  return -1;
 }
 ((void) sizeof ((hstack->head >= topframe->prev_offset) ? 1 : 0), __extension__ ({ if (hstack->head >= topframe->prev_offset) ; else __assert_fail ("hstack->head >= topframe->prev_offset", "hstack.c", 112, __extension__ __PRETTY_FUNCTION__); }));
 hstack->head = hstack->head - topframe->prev_offset;
 return 0;
}

user_defined_types: struct hstack_header_t { unsigned long capacity; unsigned long head; }

user_defined_types: struct hstack_frame_t { unsigned long prev_offset; char data[]; }


repo: nickappleton/digest

variable_types:
state
unsigned long *

variable_types:
words
unsigned char *

variable_types:
work
unsigned long [80]

variable_types:
h
unsigned long [8]

variable_types:
i
unsigned int

variable_types:
ch
unsigned long

variable_types:
maj
unsigned long


decompiled_code:
__int64 __fastcall sha2_query_digest_size(__int64 a1)
{
return *(unsigned int *)(*(_QWORD *)a1 + 136LL);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return *(unsigned int *)(*(_QWORD *)a1 + 136LL);
}

original_code:
static
unsigned
sha2_query_digest_size(const struct hash_s *hash)
{
 return hash->state->digest_bits;
}

canonical_original_code:
static unsigned int sha2_query_digest_size(struct hash_s *hash)
{
 return hash->state->digest_bits;
}

variable_types: struct hash_s { struct hash_pvt_s { unsigned int buffer_length; unsigned int buffer_index; unsigned char buffer_data[128]; unsigned int digest_bits; unsigned long length; union { unsigned long *h512; unsigned int *h256; } initial; union { unsigned long h512[8]; unsigned int h256[8]; } hash; unsigned long ivt[8]; } *state; void (*begin)(struct hash_s *hash); void (*process)(struct hash_s *hash, unsigned char *data, unsigned long size); void (*end)(struct hash_s *hash, unsigned char *result); void (*destroy)(struct hash_s *hash); unsigned int (*query_digest_size)(struct hash_s *hash); } *

user_defined_types: struct hash_s { struct hash_pvt_s *state; void (*begin)(struct hash_s *hash); void (*process)(struct hash_s *hash, unsigned char *data, unsigned long size); void (*end)(struct hash_s *hash, unsigned char *result); void (*destroy)(struct hash_s *hash); unsigned int (*query_digest_size)(struct hash_s *hash); }


decompiled_code:
void __fastcall sha2_destroy(void **a1)
{
free(*a1);
}

canonical_decompiled_code:
void __fastcall func2(void **a1)
{
free(*a1);
}

original_code:
static
void
sha2_destroy(struct hash_s *hash)
{
 free(hash->state);
}

user_defined_types: struct hash_pvt_s { unsigned int buffer_length; unsigned int buffer_index; unsigned char buffer_data[128]; unsigned int digest_bits; unsigned long length; union { unsigned long *h512; unsigned int *h256; } initial; union { unsigned long h512[8]; unsigned int h256[8]; } hash; unsigned long ivt[8]; }