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

result = 0LL;
if ( a1 )
{
result = 0LL;
if ( *(_QWORD *)(*(_QWORD *)a1 + 8LL * *(int *)(a1 + 24)) )
{
(*(void (**)(void))(a1 + 48))();
*(_QWORD *)(*(_QWORD *)a1 + 8LL * (int)(*(_DWORD *)(a1 + 24))--) = 0LL;
*(_QWORD *)(a1 + 16) -= 8LL;
result = 1LL;
}
}
return result;
}

original_code:
int array_list_remove_last(array_list* array) {
    int removed;
    size_t size;
    removed = 0;
    size = sizeof(void*);
    if(array) {
        if(array->memory[array->index]) {
            removed = 1;
            array->free_func(array->memory[array->index]);
            array->memory[array->index] = ((void *)0);
            --array->index;
            array->used -= size;
        }
    }
    return removed;
}

canonical_original_code:
int array_list_remove_last(struct dynamic_array *array) {
    int removed;
    unsigned long size;
    removed = 0;
    size = sizeof(void *);
    if(array) {
        if(array->memory[array->index]) {
            removed = 1;
            array->free_func(array->memory[array->index]);
            array->memory[array->index] = ((void *)0);
            --array->index;
            array->used -= size;
        }
    }
    return removed;
}


repo: tbullard/npuzzle

decompiled_code:
__int64 __fastcall array_list_remove(__int64 a1, int a2)
{
int v2; // eax

if ( a2 < 0 )
return 1LL;
if ( a1 )
{
v2 = *(_DWORD *)(a1 + 24);
if ( v2 >= a2 )
{
if ( *(_QWORD *)(*(_QWORD *)a1 + 8LL * a2) )
{
if ( v2 == a2 )
{
array_list_remove_last(a1);
}
else
{
(*(void (**)(void))(a1 + 48))();
*(_QWORD *)(*(_QWORD *)a1 + 8LL * a2) = 0LL;
}
}
}
}
return 1LL;
}

original_code:
int array_list_remove(array_list* array, int index) {
    int removed;
    if(array) {
        if((index >= 0 && index <= array->index) && array->memory[index]) {
            removed = 1;
            if(index == array->index) {
                array_list_remove_last(array);
            } else {
                array->free_func(array->memory[index]);
                array->memory[index] = ((void *)0);
            }
        }
    }
    return removed;
}

canonical_original_code:
int array_list_remove(struct dynamic_array *array, int index) {
    int removed;
    if(array) {
        if((index >= 0 && index <= array->index) && array->memory[index]) {
            removed = 1;
            if(index == array->index) {
                array_list_remove_last(array);
            } else {
                array->free_func(array->memory[index]);
                array->memory[index] = ((void *)0);
            }
        }
    }
    return removed;
}

variable_types: struct dynamic_array { void **memory; unsigned long allocated; unsigned long used; int index; int (*comp_func)(void *, void *); void *(*copy_func)(void *); void (*free_func)(void *); } *

variable_types: index int

variable_types: removed int

return_type: int


decompiled_code:
__int64 __fastcall array_list_swap(__int64 a1, int a2, int a3)
{
__int64 result; // rax
int v4; // ebp
__int64 v5; // r12

result = 0LL;
if ( a1 )
{
v4 = a3;
if ( a2 < 0 || a3 < 0 )
{
result = 0LL;
}
else
{
if ( a2 >= a3 )
a3 = a2;
if ( *(_DWORD *)(a1 + 24) >= a3 )
{
v5 = *(_QWORD *)(*(_QWORD *)a1 + 8LL * a2);
array_list_insert(a1, a2, *(_QWORD *)(*(_QWORD *)a1 + 8LL * v4));
array_list_insert(a1, v4, v5);
result = 1LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, int a2, int a3)
{
__int64 result; // rax
int v4; // ebp
__int64 v5; // r12

result = 0LL;
if ( a1 )
{
v4 = a3;
if ( a2 < 0 || a3 < 0 )
{
result = 0LL;
}
else
{
if ( a2 >= a3 )
a3 = a2;
if ( *(_DWORD *)(a1 + 24) >= a3 )
{
v5 = *(_QWORD *)(*(_QWORD *)a1 + 8LL * a2);
func2(a1, a2, *(_QWORD *)(*(_QWORD *)a1 + 8LL * v4));
func2(a1, v4, v5);
result = 1LL;
}
}
}
return result;
}

original_code:
int array_list_swap(array_list* array, int a_index, int b_index) {
    int swapped;
    void* a_data;
    void* b_data;
    swapped = 0;
    if(array) {
        if((a_index >= 0 && b_index >= 0) &&
           (a_index <= array->index && b_index <= array->index)) {
            swapped = 1;
            a_data = array->memory[a_index] ? array->memory[a_index] : ((void *)0);
            b_data = array->memory[b_index] ? array->memory[b_index] : ((void *)0);
            array_list_insert(array, a_index, b_data);
            array_list_insert(array, b_index, a_data);
        }
    }
    return swapped;
}

canonical_original_code:
int array_list_swap(struct dynamic_array *array, int a_index, int b_index) {
    int swapped;
    void *a_data;
    void *b_data;
    swapped = 0;
    if(array) {
        if((a_index >= 0 && b_index >= 0) &&
           (a_index <= array->index && b_index <= array->index)) {
            swapped = 1;
            a_data = array->memory[a_index] ? array->memory[a_index] : ((void *)0);
            b_data = array->memory[b_index] ? array->memory[b_index] : ((void *)0);
            array_list_insert(array, a_index, b_data);
            array_list_insert(array, b_index, a_data);
        }
    }
    return swapped;
}

variable_types: swapped int

user_defined_types: struct dynamic_array { void **memory; unsigned long allocated; unsigned long used; int index; int (*comp_func)(void *, void *); void *(*copy_func)(void *); void (*free_func)(void *); }


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

result = 1LL;
if ( a1 )
result = *(_DWORD *)(a1 + 24) >> 31;
return result;
}

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

result = 1LL;
if ( a1 )
result = *(_DWORD *)(a1 + 24) >> 31;
return result;
}

original_code:
int array_list_is_empty(array_list* array) {
    int empty;
    empty = 1;
    if(array) {
        if(array->index >= 0) {
            empty = 0;
        }
    }
    return empty;
}

canonical_original_code:
int array_list_is_empty(struct dynamic_array *array) {
    int empty;
    empty = 1;
    if(array) {
        if(array->index >= 0) {
            empty = 0;
        }
    }
    return empty;
}

variable_types: empty int


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

result = 0LL;
if ( a1 )
result = *(_DWORD *)(a1 + 24) + 1;
return result;
}

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

result = 0LL;
if ( a1 )
result = *(_DWORD *)(a1 + 24) + 1;
return result;
}

original_code:
size_t array_list_length(array_list* array) {
    size_t length;
    length = 0;
    if(array) {
        length = array->index + 1;
    }
    return length;
}

canonical_original_code:
unsigned long array_list_length(struct dynamic_array *array) {
    unsigned long length;
    length = 0;
    if(array) {
        length = array->index + 1;
    }
    return length;
}

variable_types:
length
unsigned long

return_type: unsigned long


decompiled_code:
__int64 __fastcall array_list_remove_if(_QWORD *a1, unsigned int (*a2)(void))
{
unsigned __int64 v2; // rbx
unsigned int v3; // er14

v2 = 0LL;
v3 = 0;
if ( a1 )
{
while ( array_list_length((__int64)a1) > v2 )
{
if ( *(_QWORD *)(*a1 + 8 * v2) && a2() )
{
array_list_remove((__int64)a1, v2);
++v3;
}
++v2;
}
}
return v3;
}

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

v2 = 0LL;
v3 = 0;
if ( a1 )
{
while ( func7((__int64)a1) > v2 )
{
if ( *(_QWORD *)(*a1 + 8 * v2) && a2() )
{
func4((__int64)a1, v2);
++v3;
}
++v2;
}
}
return v3;
}

original_code:
int array_list_remove_if(array_list* array, generic_pred pred_func) {
    int i, count;
    count = 0;
    if(array) {
        for(i = 0; i < array_list_length(array); i++) {
            if(array->memory[i]) {
                if(pred_func(array->memory[i])) {
                    array_list_remove(array, i);
                    count++;
                }
            }
        }
    }
    return count;
}

canonical_original_code:
int array_list_remove_if(struct dynamic_array *array, int (*pred_func)(void *)) {
    int i; int count;
    count = 0;
    if(array) {
        for(i = 0; i < array_list_length(array); i++) {
            if(array->memory[i]) {
                if(pred_func(array->memory[i])) {
                    array_list_remove(array, i);
                    count++;
                }
            }
        }
    }
    return count;
}

variable_types: i int

variable_types: count int


decompiled_code:
_BOOL8 __fastcall array_list_contains(__int64 a1, __int64 a2)
{
unsigned __int64 v2; // rbx
_BOOL4 v3; // er12
unsigned __int64 v5; // rax

v2 = 0LL;
v3 = 0;
if ( a1 )
{
while ( 1 )
{
v5 = array_list_length(a1);
if ( v3 || v5 <= v2 )
break;
v3 = 0;
if ( *(_QWORD *)(*(_QWORD *)a1 + 8 * v2) )
v3 = (*(__int64 (__fastcall **)(__int64))(a1 + 32))(a2) == 0;
++v2;
}
}
return v3;
}

original_code:
int array_list_contains(array_list* array, const void* data) {
    int i, contains;
    contains = 0;
    if(array) {
        for(i = 0; i < array_list_length(array) && !contains; i++) {
            if(array->memory[i]) {
                if(!array->comp_func(data, array->memory[i])) {
                    contains = 1;
                }
            }
        }
    }
    return contains;
}

canonical_original_code:
int array_list_contains(struct dynamic_array *array, void *data) {
    int i; int contains;
    contains = 0;
    if(array) {
        for(i = 0; i < array_list_length(array) && !contains; i++) {
            if(array->memory[i]) {
                if(!array->comp_func(data, array->memory[i])) {
                    contains = 1;
                }
            }
        }
    }
    return contains;
}

variable_types:
data
void *

variable_types: contains int


original_code:
void array_list_empty(array_list* array) {
    int i;
    if(array) {
        for(i = 0; i < array_list_length(array); i++) {
            array->free_func(array->memory[i]);
            array->memory[i] = ((void *)0);
        }
        array->used = 0;
        array->index = -1;
    }
    return;
}

canonical_original_code:
void array_list_empty(struct dynamic_array *array) {
    int i;
    if(array) {
        for(i = 0; i < array_list_length(array); i++) {
            array->free_func(array->memory[i]);
            array->memory[i] = ((void *)0);
        }
        array->used = 0;
        array->index = -1;
    }
    return;
}

return_type: void


decompiled_code:
void __fastcall array_list_kill(void *ptr)
{
if ( ptr )
{
array_list_empty((__int64)ptr);
free(*(void **)ptr);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func11(void *ptr)
{
if ( ptr )
{
func10((__int64)ptr);
free(*(void **)ptr);
free(ptr);
}
}

original_code:
void array_list_kill(array_list* array) {
    if(array) {
        array_list_empty(array);
        free(array->memory);
        free(array);
    }
    return;
}

canonical_original_code:
void array_list_kill(struct dynamic_array *array) {
    if(array) {
        array_list_empty(array);
        free(array->memory);
        free(array);
    }
    return;
}


decompiled_code:
void __fastcall array_list_dissolve(void *ptr)
{
unsigned __int64 v1; // rbx

v1 = 0LL;
if ( ptr )
{
while ( array_list_length((__int64)ptr) > v1 )
*(_QWORD *)(*(_QWORD *)ptr + 8 * v1++) = 0LL;
free(*(void **)ptr);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func12(void *ptr)
{
unsigned __int64 v1; // rbx

v1 = 0LL;
if ( ptr )
{
while ( func7((__int64)ptr) > v1 )
*(_QWORD *)(*(_QWORD *)ptr + 8 * v1++) = 0LL;
free(*(void **)ptr);
free(ptr);
}
}

original_code:
void array_list_dissolve(array_list* array) {
    int i;
    if(array) {
        for(i = 0; i < array_list_length(array); i++) {
            array->memory[i] = ((void *)0);
        }
        free(array->memory);
        free(array);
    }
    return;
}

canonical_original_code:
void array_list_dissolve(struct dynamic_array *array) {
    int i;
    if(array) {
        for(i = 0; i < array_list_length(array); i++) {
            array->memory[i] = ((void *)0);
        }
        free(array->memory);
        free(array);
    }
    return;
}


decompiled_code:
void __fastcall array_list_traverse(_QWORD *a1, void (*a2)(void))
{
unsigned __int64 v2; // rbx

v2 = 0LL;
if ( a1 )
{
while ( array_list_length((__int64)a1) > v2 )
{
if ( *(_QWORD *)(*a1 + 8 * v2) )
a2();
++v2;
}
}
}

canonical_decompiled_code:
void __fastcall func13(_QWORD *a1, void (*a2)(void))
{
unsigned __int64 v2; // rbx

v2 = 0LL;
if ( a1 )
{
while ( func7((__int64)a1) > v2 )
{
if ( *(_QWORD *)(*a1 + 8 * v2) )
a2();
++v2;
}
}
}

original_code:
void array_list_traverse(array_list* array, generic_op do_func) {
    int i;
    if(array) {
        for(i = 0; i < array_list_length(array); i++) {
            if(array->memory[i]) {
                do_func(array->memory[i]);
            }
        }
    }
    return;
}

canonical_original_code:
void array_list_traverse(struct dynamic_array *array, void (*do_func)(void *)) {
    int i;
    if(array) {
        for(i = 0; i < array_list_length(array); i++) {
            if(array->memory[i]) {
                do_func(array->memory[i]);
            }
        }
    }
    return;
}


repo: tbullock/freeswitch-openbsd

decompiled_code:
__int64 __fastcall thread_launch(void *a1)
{
__int64 v1; // rbp

v1 = (*((__int64 (__fastcall **)(void *, _QWORD))a1 + 2))(a1, *((_QWORD *)a1 + 1));
pthread_attr_destroy((pthread_attr_t *)((char *)a1 + 32));
free(a1);
return v1;
}

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

v1 = (*((__int64 (__fastcall **)(void *, _QWORD))a1 + 2))(a1, *((_QWORD *)a1 + 1));
pthread_attr_destroy((pthread_attr_t *)((char *)a1 + 32));
free(a1);
return v1;
}

original_code:
static void * thread_launch(void *args)
{
 void *exit_val;
    esl_thread_t *thread = (esl_thread_t *)args;
 exit_val = thread->function(thread, thread->private_data);
 pthread_attr_destroy(&thread->attribute);
 free(thread);
 return exit_val;
}

canonical_original_code:
static void *thread_launch(void *args)
{
 void *exit_val;
    struct esl_thread *thread = (esl_thread_t *)args;
 exit_val = thread->function(thread, thread->private_data);
 pthread_attr_destroy(&thread->attribute);
 free(thread);
 return exit_val;
}

variable_types:
args
void *

variable_types: struct esl_thread { unsigned long handle; void *private_data; void *(*function)(struct esl_thread *, void *); unsigned long stack_size; union pthread_attr_t { char __size[56]; long __align; } attribute; } *

return_type: void *

user_defined_types: struct esl_thread { unsigned long handle; void *private_data; void *(*function)(struct esl_thread *, void *); unsigned long stack_size; union pthread_attr_t attribute; }


decompiled_code:
__int64 __fastcall esl_thread_create_detached_ex(__int64 a1, __int64 a2, __int64 a3)
{
__int64 result; // rax
char *v5; // rax
_QWORD *v6; // rbx
pthread_attr_t *v7; // rbp
size_t v8; // rsi
int v9; // edx

result = 1LL;
if ( a1 )
{
v5 = (char *)malloc(0x58uLL);
v6 = v5;
if ( !v5 )
return 1LL;
*((_QWORD *)v5 + 1) = a2;
*((_QWORD *)v5 + 2) = a1;
*((_QWORD *)v5 + 3) = a3;
v7 = (pthread_attr_t *)(v5 + 32);
if ( pthread_attr_init((pthread_attr_t *)(v5 + 32)) )
goto LABEL_4;
if ( pthread_attr_setdetachstate(v7, 1)
|| (v8 = v6[3]) != 0 && pthread_attr_setstacksize(v7, v8)
|| (v9 = pthread_create(v6, v7, (void *(*)(void *))thread_launch, v6), result = 0LL, v9) )
{
pthread_attr_destroy(v7);
LABEL_4:
free(v6);
return 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, __int64 a3)
{
__int64 result; // rax
char *v5; // rax
_QWORD *v6; // rbx
pthread_attr_t *v7; // rbp
size_t v8; // rsi
int v9; // edx

result = 1LL;
if ( a1 )
{
v5 = (char *)malloc(0x58uLL);
v6 = v5;
if ( !v5 )
return 1LL;
*((_QWORD *)v5 + 1) = a2;
*((_QWORD *)v5 + 2) = a1;
*((_QWORD *)v5 + 3) = a3;
v7 = (pthread_attr_t *)(v5 + 32);
if ( pthread_attr_init((pthread_attr_t *)(v5 + 32)) )
goto LABEL_4;
if ( pthread_attr_setdetachstate(v7, 1)
|| (v8 = v6[3]) != 0 && pthread_attr_setstacksize(v7, v8)
|| (v9 = pthread_create(v6, v7, (void *(*)(void *))thread_launch, v6), result = 0LL, v9) )
{
pthread_attr_destroy(v7);
LABEL_4:
free(v6);
return 1LL;
}
}
return result;
}

original_code:
esl_status_t esl_thread_create_detached_ex(esl_thread_function_t func, void *data, size_t stack_size)
{
 esl_thread_t *thread = ((void *)0);
 esl_status_t status = ESL_FAIL;
 if (!func || !(thread = (esl_thread_t *)malloc(sizeof(esl_thread_t)))) {
  goto done;
 }
 thread->private_data = data;
 thread->function = func;
 thread->stack_size = stack_size;
 if (pthread_attr_init(&thread->attribute) != 0) goto fail;
 if (pthread_attr_setdetachstate(&thread->attribute, PTHREAD_CREATE_DETACHED) != 0) goto failpthread;
 if (thread->stack_size && pthread_attr_setstacksize(&thread->attribute, thread->stack_size) != 0) goto failpthread;
 if (pthread_create(&thread->handle, &thread->attribute, thread_launch, thread) != 0) goto failpthread;
 status = ESL_SUCCESS;
 goto done;
 failpthread:
 pthread_attr_destroy(&thread->attribute);
 fail:
 if (thread) {
  free(thread);
 }
 done:
 return status;
}

canonical_original_code:
enum esl_status_t esl_thread_create_detached_ex(void *(*func)(struct esl_thread *, void *), void *data, unsigned long stack_size)
{
 struct esl_thread *thread = ((void *)0);
 enum esl_status_t status = ESL_FAIL;
 if (!func || !(thread = (struct esl_thread *)malloc(sizeof(esl_thread_t)))) {
  goto done;
 }
 thread->private_data = data;
 thread->function = func;
 thread->stack_size = stack_size;
 if (pthread_attr_init(&thread->attribute) != 0) goto fail;
 if (pthread_attr_setdetachstate(&thread->attribute, PTHREAD_CREATE_DETACHED) != 0) goto failpthread;
 if (thread->stack_size && pthread_attr_setstacksize(&thread->attribute, thread->stack_size) != 0) goto failpthread;
 if (pthread_create(&thread->handle, &thread->attribute, thread_launch, thread) != 0) goto failpthread;
 status = ESL_SUCCESS;
 goto done;
 failpthread:
 pthread_attr_destroy(&thread->attribute);
 fail:
 if (thread) {
  free(thread);
 }
 done:
 return status;
}

variable_types: void *(*)(struct esl_thread { unsigned long handle; void *private_data; void *(*function)(struct esl_thread *, void *); unsigned long stack_size; union pthread_attr_t { char __size[56]; long __align; } attribute; } *, void *)

variable_types: enum esl_status_t { ESL_SUCCESS=0, ESL_FAIL=1, ESL_BREAK=2, ESL_DISCONNECTED=3, ESL_GENERR=4 }


decompiled_code:
__int64 __fastcall esl_thread_create_detached(__int64 a1, __int64 a2)
{
return esl_thread_create_detached_ex(a1, a2, thread_default_stacksize);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
return func2(a1, a2, thread_default_stacksize);
}

original_code:
esl_status_t esl_thread_create_detached(esl_thread_function_t func, void *data)
{
 return esl_thread_create_detached_ex(func, data, thread_default_stacksize);
}

canonical_original_code:
enum esl_status_t esl_thread_create_detached(void *(*func)(struct esl_thread *, void *), void *data)
{
 return esl_thread_create_detached_ex(func, data, thread_default_stacksize);
}

return_type: enum esl_status_t { ESL_SUCCESS=0, ESL_FAIL=1, ESL_BREAK=2, ESL_DISCONNECTED=3, ESL_GENERR=4 }

user_defined_types: union pthread_attr_t { char __size[56]; long __align; }


decompiled_code:
int __fastcall esl_mutex_create(pthread_mutex_t **a1)
{
pthread_mutex_t *v1; // rax
pthread_mutex_t *v2; // rbx
int result; // eax
pthread_mutexattr_t attr; // [rsp+Ch] [rbp-1Ch] BYREF

v1 = (pthread_mutex_t *)malloc(0x28uLL);
if ( !v1 )
return 1;
v2 = v1;
if ( pthread_mutexattr_init(&attr) )
{
free(v2);
result = 1;
}
else if ( pthread_mutexattr_settype(&attr, 1) || (result = pthread_mutex_init(v2, &attr)) != 0 )
{
pthread_mutexattr_destroy(&attr);
free(v2);
result = 1;
}
else
{
*a1 = v2;
}
return result;
}

canonical_decompiled_code:
int __fastcall func4(pthread_mutex_t **a1)
{
pthread_mutex_t *v1; // rax
pthread_mutex_t *v2; // rbx
int result; // eax
pthread_mutexattr_t attr; // [rsp+Ch] [rbp-1Ch] BYREF

v1 = (pthread_mutex_t *)malloc(0x28uLL);
if ( !v1 )
return 1;
v2 = v1;
if ( pthread_mutexattr_init(&attr) )
{
free(v2);
result = 1;
}
else if ( pthread_mutexattr_settype(&attr, 1) || (result = pthread_mutex_init(v2, &attr)) != 0 )
{
pthread_mutexattr_destroy(&attr);
free(v2);
result = 1;
}
else
{
*a1 = v2;
}
return result;
}

original_code:
esl_status_t esl_mutex_create(esl_mutex_t **mutex)
{
 esl_status_t status = ESL_FAIL;
 pthread_mutexattr_t attr;
 esl_mutex_t *check = ((void *)0);
 check = (esl_mutex_t *)malloc(sizeof(**mutex));
 if (!check)
  goto done;
 if (pthread_mutexattr_init(&attr)) {
  free(check);
  goto done;
 }
 if (pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE))
  goto fail;
 if (pthread_mutex_init(&check->mutex, &attr))
  goto fail;
 goto success;
 fail:
 pthread_mutexattr_destroy(&attr);
 free(check);
 goto done;
 success:
 *mutex = check;
 status = ESL_SUCCESS;
 done:
 return status;
}

canonical_original_code:
enum esl_status_t esl_mutex_create(struct esl_mutex **mutex)
{
 enum esl_status_t status = ESL_FAIL;
 union pthread_mutexattr_t attr;
 struct esl_mutex *check = ((void *)0);
 check = (struct esl_mutex *)malloc(sizeof(**mutex));
 if (!check)
  goto done;
 if (pthread_mutexattr_init(&attr)) {
  free(check);
  goto done;
 }
 if (pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE))
  goto fail;
 if (pthread_mutex_init(&check->mutex, &attr))
  goto fail;
 goto success;
 fail:
 pthread_mutexattr_destroy(&attr);
 free(check);
 goto done;
 success:
 *mutex = check;
 status = ESL_SUCCESS;
 done:
 return status;
}

variable_types: struct esl_mutex { 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; } mutex; } **

variable_types: union pthread_mutexattr_t { char __size[4]; int __align; }

user_defined_types: enum esl_status_t { ESL_SUCCESS=0, ESL_FAIL=1, ESL_BREAK=2, ESL_DISCONNECTED=3, ESL_GENERR=4 }

user_defined_types: struct esl_mutex { union pthread_mutex_t mutex; }

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:
__int64 __fastcall esl_mutex_destroy(pthread_mutex_t **a1)
{
pthread_mutex_t *v1; // rbx
__int64 result; // rax
int v3; // edx

v1 = *a1;
*a1 = 0LL;
result = 1LL;
if ( v1 )
{
v3 = pthread_mutex_destroy(v1);
result = 1LL;
if ( !v3 )
{
free(v1);
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(pthread_mutex_t **a1)
{
pthread_mutex_t *v1; // rbx
__int64 result; // rax
int v3; // edx

v1 = *a1;
*a1 = 0LL;
result = 1LL;
if ( v1 )
{
v3 = pthread_mutex_destroy(v1);
result = 1LL;
if ( !v3 )
{
free(v1);
result = 0LL;
}
}
return result;
}

original_code:
esl_status_t esl_mutex_destroy(esl_mutex_t **mutex)
{
 esl_mutex_t *mp = *mutex;
 *mutex = ((void *)0);
 if (!mp) {
  return ESL_FAIL;
 }
 if (pthread_mutex_destroy(&mp->mutex))
  return ESL_FAIL;
 free(mp);
 return ESL_SUCCESS;
}

canonical_original_code:
enum esl_status_t esl_mutex_destroy(struct esl_mutex **mutex)
{
 struct esl_mutex *mp = *mutex;
 *mutex = ((void *)0);
 if (!mp) {
  return ESL_FAIL;
 }
 if (pthread_mutex_destroy(&mp->mutex))
  return ESL_FAIL;
 free(mp);
 return ESL_SUCCESS;
}

variable_types: struct esl_mutex { 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; } mutex; } *


decompiled_code:
_BOOL8 __fastcall esl_mutex_lock(pthread_mutex_t *a1)
{
return pthread_mutex_lock(a1) != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func6(pthread_mutex_t *a1)
{
return pthread_mutex_lock(a1) != 0;
}

original_code:
esl_status_t esl_mutex_lock(esl_mutex_t *mutex)
{
 if (pthread_mutex_lock(&mutex->mutex))
  return ESL_FAIL;
 return ESL_SUCCESS;
}

canonical_original_code:
enum esl_status_t esl_mutex_lock(struct esl_mutex *mutex)
{
 if (pthread_mutex_lock(&mutex->mutex))
  return ESL_FAIL;
 return ESL_SUCCESS;
}

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


decompiled_code:
_BOOL8 __fastcall esl_mutex_trylock(pthread_mutex_t *a1)
{
return pthread_mutex_trylock(a1) != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func7(pthread_mutex_t *a1)
{
return pthread_mutex_trylock(a1) != 0;
}

original_code:
esl_status_t esl_mutex_trylock(esl_mutex_t *mutex)
{
 if (pthread_mutex_trylock(&mutex->mutex))
  return ESL_FAIL;
 return ESL_SUCCESS;
}

canonical_original_code:
enum esl_status_t esl_mutex_trylock(struct esl_mutex *mutex)
{
 if (pthread_mutex_trylock(&mutex->mutex))
  return ESL_FAIL;
 return ESL_SUCCESS;
}


decompiled_code:
_BOOL8 __fastcall esl_mutex_unlock(pthread_mutex_t *a1)
{
return pthread_mutex_unlock(a1) != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func8(pthread_mutex_t *a1)
{
return pthread_mutex_unlock(a1) != 0;
}

original_code:
esl_status_t esl_mutex_unlock(esl_mutex_t *mutex)
{
 if (pthread_mutex_unlock(&mutex->mutex))
  return ESL_FAIL;
 return ESL_SUCCESS;
}

canonical_original_code:
enum esl_status_t esl_mutex_unlock(struct esl_mutex *mutex)
{
 if (pthread_mutex_unlock(&mutex->mutex))
  return ESL_FAIL;
 return ESL_SUCCESS;
}


original_code:
esl_status_t esl_buffer_create(esl_buffer_t **buffer, esl_size_t blocksize, esl_size_t start_len, esl_size_t max_len)
{
 esl_buffer_t *new_buffer;
 new_buffer = malloc(sizeof(*new_buffer));
 if (new_buffer) {
  memset(new_buffer, 0, sizeof(*new_buffer));
  if (start_len) {
   new_buffer->data = malloc(start_len);
   if (!new_buffer->data) {
    free(new_buffer);
    return ESL_FAIL;
   }
   memset(new_buffer->data, 0, start_len);
  }
  new_buffer->max_len = max_len;
  new_buffer->datalen = start_len;
  new_buffer->id = buffer_id++;
  new_buffer->blocksize = blocksize;
  new_buffer->head = new_buffer->data;
  *buffer = new_buffer;
  return ESL_SUCCESS;
 }
 return ESL_FAIL;
}

canonical_original_code:
enum esl_status_t esl_buffer_create(struct esl_buffer **buffer, unsigned long blocksize, unsigned long start_len, unsigned long max_len)
{
 struct esl_buffer *new_buffer;
 new_buffer = malloc(sizeof(*new_buffer));
 if (new_buffer) {
  memset(new_buffer, 0, sizeof(*new_buffer));
  if (start_len) {
   new_buffer->data = malloc(start_len);
   if (!new_buffer->data) {
    free(new_buffer);
    return ESL_FAIL;
   }
   memset(new_buffer->data, 0, start_len);
  }
  new_buffer->max_len = max_len;
  new_buffer->datalen = start_len;
  new_buffer->id = buffer_id++;
  new_buffer->blocksize = blocksize;
  new_buffer->head = new_buffer->data;
  *buffer = new_buffer;
  return ESL_SUCCESS;
 }
 return ESL_FAIL;
}

variable_types: struct esl_buffer { unsigned char *data; unsigned char *head; unsigned long used; unsigned long actually_used; unsigned long datalen; unsigned long max_len; unsigned long blocksize; unsigned int id; int loops; } **

variable_types:
blocksize
unsigned long


decompiled_code:
__int64 __fastcall esl_buffer_len(__int64 a1)
{
if ( !a1 )
_assert_fail("buffer != ((void *)0)", "esl_buffer.c", 0x55u, "esl_buffer_len");
return *(_QWORD *)(a1 + 32);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
if ( !a1 )
_assert_fail("buffer != ((void *)0)", "esl_buffer.c", 0x55u, "esl_buffer_len");
return *(_QWORD *)(a1 + 32);
}

original_code:
esl_size_t esl_buffer_len(esl_buffer_t *buffer)
{
 ((void) sizeof ((buffer != ((void *)0)) ? 1 : 0), __extension__ ({ if (buffer != ((void *)0)) ; else __assert_fail ("buffer != ((void *)0)", "esl_buffer.c", 85, __extension__ __PRETTY_FUNCTION__); }));
 return buffer->datalen;
}

canonical_original_code:
unsigned long esl_buffer_len(struct esl_buffer *buffer)
{
 ((void) sizeof ((buffer != ((void *)0)) ? 1 : 0), __extension__ ({ if (buffer != ((void *)0)) ; else __assert_fail ("buffer != ((void *)0)", "esl_buffer.c", 85, __extension__ __PRETTY_FUNCTION__); }));
 return buffer->datalen;
}

variable_types: struct esl_buffer { unsigned char *data; unsigned char *head; unsigned long used; unsigned long actually_used; unsigned long datalen; unsigned long max_len; unsigned long blocksize; unsigned int id; int loops; } *


decompiled_code:
__int64 __fastcall esl_buffer_freespace(__int64 a1)
{
__int64 v1; // rdx
__int64 result; // rax

if ( !a1 )
_assert_fail("buffer != ((void *)0)", "esl_buffer.c", 0x5Eu, "esl_buffer_freespace");
v1 = *(_QWORD *)(a1 + 40);
result = 1000000LL;
if ( v1 )
result = v1 - *(_QWORD *)(a1 + 16);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 v1; // rdx
__int64 result; // rax

if ( !a1 )
_assert_fail("buffer != ((void *)0)", "esl_buffer.c", 0x5Eu, "esl_buffer_freespace");
v1 = *(_QWORD *)(a1 + 40);
result = 1000000LL;
if ( v1 )
result = v1 - *(_QWORD *)(a1 + 16);
return result;
}

original_code:
esl_size_t esl_buffer_freespace(esl_buffer_t *buffer)
{
 ((void) sizeof ((buffer != ((void *)0)) ? 1 : 0), __extension__ ({ if (buffer != ((void *)0)) ; else __assert_fail ("buffer != ((void *)0)", "esl_buffer.c", 94, __extension__ __PRETTY_FUNCTION__); }));
 if (buffer->max_len) {
  return (esl_size_t) (buffer->max_len - buffer->used);
 }
 return 1000000;
}

canonical_original_code:
unsigned long esl_buffer_freespace(struct esl_buffer *buffer)
{
 ((void) sizeof ((buffer != ((void *)0)) ? 1 : 0), __extension__ ({ if (buffer != ((void *)0)) ; else __assert_fail ("buffer != ((void *)0)", "esl_buffer.c", 94, __extension__ __PRETTY_FUNCTION__); }));
 if (buffer->max_len) {
  return (esl_size_t) (buffer->max_len - buffer->used);
 }
 return 1000000;
}

user_defined_types: struct esl_buffer { unsigned char *data; unsigned char *head; unsigned long used; unsigned long actually_used; unsigned long datalen; unsigned long max_len; unsigned long blocksize; unsigned int id; int loops; }


decompiled_code:
__int64 __fastcall esl_buffer_inuse(__int64 a1)
{
if ( !a1 )
_assert_fail("buffer != ((void *)0)", "esl_buffer.c", 0x69u, "esl_buffer_inuse");
return *(_QWORD *)(a1 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
if ( !a1 )
_assert_fail("buffer != ((void *)0)", "esl_buffer.c", 0x69u, "esl_buffer_inuse");
return *(_QWORD *)(a1 + 16);
}

original_code:
esl_size_t esl_buffer_inuse(esl_buffer_t *buffer)
{
 ((void) sizeof ((buffer != ((void *)0)) ? 1 : 0), __extension__ ({ if (buffer != ((void *)0)) ; else __assert_fail ("buffer != ((void *)0)", "esl_buffer.c", 105, __extension__ __PRETTY_FUNCTION__); }));
 return buffer->used;
}

canonical_original_code:
unsigned long esl_buffer_inuse(struct esl_buffer *buffer)
{
 ((void) sizeof ((buffer != ((void *)0)) ? 1 : 0), __extension__ ({ if (buffer != ((void *)0)) ; else __assert_fail ("buffer != ((void *)0)", "esl_buffer.c", 105, __extension__ __PRETTY_FUNCTION__); }));
 return buffer->used;
}


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

if ( !a1 )
_assert_fail("buffer != ((void *)0)", "esl_buffer.c", 0x72u, "esl_buffer_seek");
result = a1[2];
if ( result )
{
if ( result > a2 )
result = a2;
a1[2] = a1[3] - result;
a1[1] = *a1 + result;
}
return result;
}

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

if ( !a1 )
_assert_fail("buffer != ((void *)0)", "esl_buffer.c", 0x72u, "esl_buffer_seek");
result = a1[2];
if ( result )
{
if ( result > a2 )
result = a2;
a1[2] = a1[3] - result;
a1[1] = *a1 + result;
}
return result;
}

original_code:
esl_size_t esl_buffer_seek(esl_buffer_t *buffer, esl_size_t datalen)
{
 esl_size_t reading = 0;
 ((void) sizeof ((buffer != ((void *)0)) ? 1 : 0), __extension__ ({ if (buffer != ((void *)0)) ; else __assert_fail ("buffer != ((void *)0)", "esl_buffer.c", 114, __extension__ __PRETTY_FUNCTION__); }));
 if (buffer->used < 1) {
  buffer->used = 0;
  return 0;
 } else if (buffer->used >= datalen) {
  reading = datalen;
 } else {
  reading = buffer->used;
 }
 buffer->used = buffer->actually_used - reading;
 buffer->head = buffer->data + reading;
 return reading;
}

canonical_original_code:
unsigned long esl_buffer_seek(struct esl_buffer *buffer, unsigned long datalen)
{
 unsigned long reading = 0;
 ((void) sizeof ((buffer != ((void *)0)) ? 1 : 0), __extension__ ({ if (buffer != ((void *)0)) ; else __assert_fail ("buffer != ((void *)0)", "esl_buffer.c", 114, __extension__ __PRETTY_FUNCTION__); }));
 if (buffer->used < 1) {
  buffer->used = 0;
  return 0;
 } else if (buffer->used >= datalen) {
  reading = datalen;
 } else {
  reading = buffer->used;
 }
 buffer->used = buffer->actually_used - reading;
 buffer->head = buffer->data + reading;
 return reading;
}

variable_types:
datalen
unsigned long

variable_types:
reading
unsigned long


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

if ( !a1 )
_assert_fail("buffer != ((void *)0)", "esl_buffer.c", 0x87u, "esl_buffer_toss");
result = *(_QWORD *)(a1 + 16);
if ( result )
{
if ( result <= a2 )
a2 = *(_QWORD *)(a1 + 16);
result -= a2;
*(_QWORD *)(a1 + 16) = result;
*(_QWORD *)(a1 + 8) += a2;
}
return result;
}

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

if ( !a1 )
_assert_fail("buffer != ((void *)0)", "esl_buffer.c", 0x87u, "esl_buffer_toss");
result = *(_QWORD *)(a1 + 16);
if ( result )
{
if ( result <= a2 )
a2 = *(_QWORD *)(a1 + 16);
result -= a2;
*(_QWORD *)(a1 + 16) = result;
*(_QWORD *)(a1 + 8) += a2;
}
return result;
}

original_code:
esl_size_t esl_buffer_toss(esl_buffer_t *buffer, esl_size_t datalen)
{
 esl_size_t reading = 0;
 ((void) sizeof ((buffer != ((void *)0)) ? 1 : 0), __extension__ ({ if (buffer != ((void *)0)) ; else __assert_fail ("buffer != ((void *)0)", "esl_buffer.c", 135, __extension__ __PRETTY_FUNCTION__); }));
 if (buffer->used < 1) {
  buffer->used = 0;
  return 0;
 } else if (buffer->used >= datalen) {
  reading = datalen;
 } else {
  reading = buffer->used;
 }
 buffer->used -= reading;
 buffer->head += reading;
 return buffer->used;
}

canonical_original_code:
unsigned long esl_buffer_toss(struct esl_buffer *buffer, unsigned long datalen)
{
 unsigned long reading = 0;
 ((void) sizeof ((buffer != ((void *)0)) ? 1 : 0), __extension__ ({ if (buffer != ((void *)0)) ; else __assert_fail ("buffer != ((void *)0)", "esl_buffer.c", 135, __extension__ __PRETTY_FUNCTION__); }));
 if (buffer->used < 1) {
  buffer->used = 0;
  return 0;
 } else if (buffer->used >= datalen) {
  reading = datalen;
 } else {
  reading = buffer->used;
 }
 buffer->used -= reading;
 buffer->head += reading;
 return buffer->used;
}


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

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

original_code:
void esl_buffer_set_loops(esl_buffer_t *buffer, int loops)
{
 buffer->loops = loops;
}

canonical_original_code:
void esl_buffer_set_loops(struct esl_buffer *buffer, int loops)
{
 buffer->loops = loops;
}

variable_types: loops int


decompiled_code:
size_t __fastcall esl_buffer_read(__int64 a1, void *a2, size_t a3)
{
size_t v3; // rbp

if ( !a1 )
_assert_fail("buffer != ((void *)0)", "esl_buffer.c", 0xB0u, "esl_buffer_read");
if ( !a2 )
_assert_fail("data != ((void *)0)", "esl_buffer.c", 0xB1u, "esl_buffer_read");
v3 = *(_QWORD *)(a1 + 16);
if ( v3 )
{
if ( v3 > a3 )
v3 = a3;
memcpy(a2, *(const void **)(a1 + 8), v3);
*(_QWORD *)(a1 + 16) -= v3;
*(_QWORD *)(a1 + 8) += v3;
}
return v3;
}

canonical_decompiled_code:
size_t __fastcall func7(__int64 a1, void *a2, size_t a3)
{
size_t v3; // rbp

if ( !a1 )
_assert_fail("buffer != ((void *)0)", "esl_buffer.c", 0xB0u, "esl_buffer_read");
if ( !a2 )
_assert_fail("data != ((void *)0)", "esl_buffer.c", 0xB1u, "esl_buffer_read");
v3 = *(_QWORD *)(a1 + 16);
if ( v3 )
{
if ( v3 > a3 )
v3 = a3;
memcpy(a2, *(const void **)(a1 + 8), v3);
*(_QWORD *)(a1 + 16) -= v3;
*(_QWORD *)(a1 + 8) += v3;
}
return v3;
}

original_code:
esl_size_t esl_buffer_read(esl_buffer_t *buffer, void *data, esl_size_t datalen)
{
 esl_size_t reading = 0;
 ((void) sizeof ((buffer != ((void *)0)) ? 1 : 0), __extension__ ({ if (buffer != ((void *)0)) ; else __assert_fail ("buffer != ((void *)0)", "esl_buffer.c", 176, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((data != ((void *)0)) ? 1 : 0), __extension__ ({ if (data != ((void *)0)) ; else __assert_fail ("data != ((void *)0)", "esl_buffer.c", 177, __extension__ __PRETTY_FUNCTION__); }));
 if (buffer->used < 1) {
  buffer->used = 0;
  return 0;
 } else if (buffer->used >= datalen) {
  reading = datalen;
 } else {
  reading = buffer->used;
 }
 memcpy(data, buffer->head, reading);
 buffer->used -= reading;
 buffer->head += reading;
 return reading;
}

canonical_original_code:
unsigned long esl_buffer_read(struct esl_buffer *buffer, void *data, unsigned long datalen)
{
 unsigned long reading = 0;
 ((void) sizeof ((buffer != ((void *)0)) ? 1 : 0), __extension__ ({ if (buffer != ((void *)0)) ; else __assert_fail ("buffer != ((void *)0)", "esl_buffer.c", 176, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((data != ((void *)0)) ? 1 : 0), __extension__ ({ if (data != ((void *)0)) ; else __assert_fail ("data != ((void *)0)", "esl_buffer.c", 177, __extension__ __PRETTY_FUNCTION__); }));
 if (buffer->used < 1) {
  buffer->used = 0;
  return 0;
 } else if (buffer->used >= datalen) {
  reading = datalen;
 } else {
  reading = buffer->used;
 }
 memcpy(data, buffer->head, reading);
 buffer->used -= reading;
 buffer->head += reading;
 return reading;
}


decompiled_code:
size_t __fastcall esl_buffer_read_loop(__int64 a1, char *a2, size_t a3)
{
size_t result; // rax

result = esl_buffer_read(a1, a2, a3);
if ( a3 > result )
{
if ( *(_DWORD *)(a1 + 60) )
{
*(_QWORD *)(a1 + 8) = *(_QWORD *)a1;
*(_QWORD *)(a1 + 16) = *(_QWORD *)(a1 + 24);
result = esl_buffer_read(a1, &a2[result], a3 - result);
--*(_DWORD *)(a1 + 60);
}
}
return result;
}

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

result = func7(a1, a2, a3);
if ( a3 > result )
{
if ( *(_DWORD *)(a1 + 60) )
{
*(_QWORD *)(a1 + 8) = *(_QWORD *)a1;
*(_QWORD *)(a1 + 16) = *(_QWORD *)(a1 + 24);
result = func7(a1, &a2[result], a3 - result);
--*(_DWORD *)(a1 + 60);
}
}
return result;
}

original_code:
esl_size_t esl_buffer_read_loop(esl_buffer_t *buffer, void *data, esl_size_t datalen)
{
 esl_size_t len;
 if ((len = esl_buffer_read(buffer, data, datalen)) < datalen) {
  if (buffer->loops == 0) {
   return len;
  }
  buffer->head = buffer->data;
  buffer->used = buffer->actually_used;
  len = esl_buffer_read(buffer, (char*)data + len, datalen - len);
  buffer->loops--;
 }
 return len;
}

canonical_original_code:
unsigned long esl_buffer_read_loop(struct esl_buffer *buffer, void *data, unsigned long datalen)
{
 unsigned long len;
 if ((len = esl_buffer_read(buffer, data, datalen)) < datalen) {
  if (buffer->loops == 0) {
   return len;
  }
  buffer->head = buffer->data;
  buffer->used = buffer->actually_used;
  len = esl_buffer_read(buffer, (char *)data + len, datalen - len);
  buffer->loops--;
 }
 return len;
}

variable_types:
len
unsigned long


original_code:
esl_size_t esl_buffer_packet_count(esl_buffer_t *buffer)
{
 char *pe, *p, *e, *head = (char *) buffer->head;
 esl_size_t x = 0;
 ((void) sizeof ((buffer != ((void *)0)) ? 1 : 0), __extension__ ({ if (buffer != ((void *)0)) ; else __assert_fail ("buffer != ((void *)0)", "esl_buffer.c", 203, __extension__ __PRETTY_FUNCTION__); }));
 e = (head + buffer->used);
 for (p = head; p && *p && p < e; p++) {
  if (*p == '\n') {
   pe = p+1;
   if (*pe == '\r') pe++;
   if (pe <= e && *pe == '\n') {
    p = pe++;
    x++;
   }
  }
 }
 return x;
}

canonical_original_code:
unsigned long esl_buffer_packet_count(struct esl_buffer *buffer)
{
 char *pe; char *p; char *e; char *head = (char *) buffer->head;
 unsigned long x = 0;
 ((void) sizeof ((buffer != ((void *)0)) ? 1 : 0), __extension__ ({ if (buffer != ((void *)0)) ; else __assert_fail ("buffer != ((void *)0)", "esl_buffer.c", 203, __extension__ __PRETTY_FUNCTION__); }));
 e = (head + buffer->used);
 for (p = head; p && *p && p < e; p++) {
  if (*p == '\n') {
   pe = p+1;
   if (*pe == '\r') pe++;
   if (pe <= e && *pe == '\n') {
    p = pe++;
    x++;
   }
  }
 }
 return x;
}

variable_types:
pe
char *

variable_types:
p
char *

variable_types:
e
char *

variable_types:
head
char *

variable_types:
x
unsigned long


decompiled_code:
size_t __fastcall esl_buffer_read_packet(__int64 a1, void *a2, size_t a3)
{
char *v3; // r8
char *v6; // rsi
char v7; // dl
char *v8; // rax
char *v9; // rcx
char *v10; // rdx
size_t v11; // rax
size_t v12; // rdx

v3 = *(char **)(a1 + 8);
if ( !a2 )
_assert_fail("data != ((void *)0)", "esl_buffer.c", 0xE3u, "esl_buffer_read_packet");
v6 = &v3[*(_QWORD *)(a1 + 16)];
if ( v3 )
{
v7 = *v3;
if ( v3 < v6 && v7 )
{
v8 = v3 + 1;
while ( 1 )
{
if ( v7 == 10 )
{
v10 = &v8[*v8 == 13];
if ( v10 <= v6 && *v10 == 10 )
break;
}
v9 = v8;
v7 = *v8++;
if ( v6 <= v9 || !v7 )
{
v12 = 0LL;
return esl_buffer_read(a1, a2, v12);
}
}
v11 = v10 + 1 - v3;
v12 = a3;
if ( v11 <= a3 )
v12 = v11;
}
else
{
v12 = 0LL;
}
}
else
{
v12 = 0LL;
}
return esl_buffer_read(a1, a2, v12);
}

original_code:
esl_size_t esl_buffer_read_packet(esl_buffer_t *buffer, void *data, esl_size_t maxlen)
{
 char *pe, *p, *e, *head = (char *) buffer->head;
 esl_size_t datalen = 0;
 ((void) sizeof ((buffer != ((void *)0)) ? 1 : 0), __extension__ ({ if (buffer != ((void *)0)) ; else __assert_fail ("buffer != ((void *)0)", "esl_buffer.c", 226, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((data != ((void *)0)) ? 1 : 0), __extension__ ({ if (data != ((void *)0)) ; else __assert_fail ("data != ((void *)0)", "esl_buffer.c", 227, __extension__ __PRETTY_FUNCTION__); }));
 e = (head + buffer->used);
 for (p = head; p && *p && p < e; p++) {
  if (*p == '\n') {
   pe = p+1;
   if (*pe == '\r') pe++;
   if (pe <= e && *pe == '\n') {
    pe++;
    datalen = pe - head;
    if (datalen > maxlen) {
     datalen = maxlen;
    }
    break;
   }
  }
 }
 return esl_buffer_read(buffer, data, datalen);
}

canonical_original_code:
unsigned long esl_buffer_read_packet(struct esl_buffer *buffer, void *data, unsigned long maxlen)
{
 char *pe; char *p; char *e; char *head = (char *) buffer->head;
 unsigned long datalen = 0;
 ((void) sizeof ((buffer != ((void *)0)) ? 1 : 0), __extension__ ({ if (buffer != ((void *)0)) ; else __assert_fail ("buffer != ((void *)0)", "esl_buffer.c", 226, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((data != ((void *)0)) ? 1 : 0), __extension__ ({ if (data != ((void *)0)) ; else __assert_fail ("data != ((void *)0)", "esl_buffer.c", 227, __extension__ __PRETTY_FUNCTION__); }));
 e = (head + buffer->used);
 for (p = head; p && *p && p < e; p++) {
  if (*p == '\n') {
   pe = p+1;
   if (*pe == '\r') pe++;
   if (pe <= e && *pe == '\n') {
    pe++;
    datalen = pe - head;
    if (datalen > maxlen) {
     datalen = maxlen;
    }
    break;
   }
  }
 }
 return esl_buffer_read(buffer, data, datalen);
}

variable_types:
data
void *

variable_types:
maxlen
unsigned long


original_code:
esl_size_t esl_buffer_write(esl_buffer_t *buffer, const void *data, esl_size_t datalen)
{
 esl_size_t freespace, actual_freespace;
 ((void) sizeof ((buffer != ((void *)0)) ? 1 : 0), __extension__ ({ if (buffer != ((void *)0)) ; else __assert_fail ("buffer != ((void *)0)", "esl_buffer.c", 253, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((data != ((void *)0)) ? 1 : 0), __extension__ ({ if (data != ((void *)0)) ; else __assert_fail ("data != ((void *)0)", "esl_buffer.c", 254, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((buffer->data != ((void *)0)) ? 1 : 0), __extension__ ({ if (buffer->data != ((void *)0)) ; else __assert_fail ("buffer->data != ((void *)0)", "esl_buffer.c", 255, __extension__ __PRETTY_FUNCTION__); }));
 if (!datalen) {
  return buffer->used;
 }
 actual_freespace = buffer->datalen - buffer->actually_used;
 if (actual_freespace < datalen && (!buffer->max_len || (buffer->used + datalen <= buffer->max_len))) {
  memmove(buffer->data, buffer->head, buffer->used);
  buffer->head = buffer->data;
  buffer->actually_used = buffer->used;
 }
 freespace = buffer->datalen - buffer->used;
 if (freespace < datalen) {
  esl_size_t new_size, new_block_size;
  void *data1;
  new_size = buffer->datalen + datalen;
  new_block_size = buffer->datalen + buffer->blocksize;
  if (new_block_size > new_size) {
   new_size = new_block_size;
  }
  buffer->head = buffer->data;
  data1 = realloc(buffer->data, new_size);
  if (!data1) {
   return 0;
  }
  buffer->data = data1;
  buffer->head = buffer->data;
  buffer->datalen = new_size;
 }
 freespace = buffer->datalen - buffer->used;
 if (freespace < datalen) {
  return 0;
 } else {
  memcpy(buffer->head + buffer->used, data, datalen);
  buffer->used += datalen;
  buffer->actually_used += datalen;
 }
 return buffer->used;
}

canonical_original_code:
unsigned long esl_buffer_write(struct esl_buffer *buffer, void *data, unsigned long datalen)
{
 unsigned long freespace; unsigned long actual_freespace;
 ((void) sizeof ((buffer != ((void *)0)) ? 1 : 0), __extension__ ({ if (buffer != ((void *)0)) ; else __assert_fail ("buffer != ((void *)0)", "esl_buffer.c", 253, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((data != ((void *)0)) ? 1 : 0), __extension__ ({ if (data != ((void *)0)) ; else __assert_fail ("data != ((void *)0)", "esl_buffer.c", 254, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((buffer->data != ((void *)0)) ? 1 : 0), __extension__ ({ if (buffer->data != ((void *)0)) ; else __assert_fail ("buffer->data != ((void *)0)", "esl_buffer.c", 255, __extension__ __PRETTY_FUNCTION__); }));
 if (!datalen) {
  return buffer->used;
 }
 actual_freespace = buffer->datalen - buffer->actually_used;
 if (actual_freespace < datalen && (!buffer->max_len || (buffer->used + datalen <= buffer->max_len))) {
  memmove(buffer->data, buffer->head, buffer->used);
  buffer->head = buffer->data;
  buffer->actually_used = buffer->used;
 }
 freespace = buffer->datalen - buffer->used;
 if (freespace < datalen) {
  unsigned long new_size; unsigned long new_block_size;
  void *data1;
  new_size = buffer->datalen + datalen;
  new_block_size = buffer->datalen + buffer->blocksize;
  if (new_block_size > new_size) {
   new_size = new_block_size;
  }
  buffer->head = buffer->data;
  data1 = realloc(buffer->data, new_size);
  if (!data1) {
   return 0;
  }
  buffer->data = data1;
  buffer->head = buffer->data;
  buffer->datalen = new_size;
 }
 freespace = buffer->datalen - buffer->used;
 if (freespace < datalen) {
  return 0;
 } else {
  memcpy(buffer->head + buffer->used, data, datalen);
  buffer->used += datalen;
  buffer->actually_used += datalen;
 }
 return buffer->used;
}

variable_types:
freespace
unsigned long


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

result = esl_buffer_write((__int64)a1, a2, a3);
if ( !result )
{
esl_buffer_zero(a1);
result = esl_buffer_write((__int64)a1, a2, a3);
}
return result;
}

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

result = func11((__int64)a1, a2, a3);
if ( !result )
{
func12(a1);
result = func11((__int64)a1, a2, a3);
}
return result;
}

original_code:
esl_size_t esl_buffer_zwrite(esl_buffer_t *buffer, const void *data, esl_size_t datalen)
{
 esl_size_t w;
 if (!(w = esl_buffer_write(buffer, data, datalen))) {
  esl_buffer_zero(buffer);
  return esl_buffer_write(buffer, data, datalen);
 }
 return w;
}

canonical_original_code:
unsigned long esl_buffer_zwrite(struct esl_buffer *buffer, void *data, unsigned long datalen)
{
 unsigned long w;
 if (!(w = esl_buffer_write(buffer, data, datalen))) {
  esl_buffer_zero(buffer);
  return esl_buffer_write(buffer, data, datalen);
 }
 return w;
}

variable_types:
w
unsigned long


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

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

original_code:
void esl_buffer_destroy(esl_buffer_t **buffer)
{
 if (*buffer) {
  free((*buffer)->data);
  free(*buffer);
 }
 *buffer = ((void *)0);
}

canonical_original_code:
void esl_buffer_destroy(struct esl_buffer **buffer)
{
 if (*buffer) {
  free((*buffer)->data);
  free(*buffer);
 }
 *buffer = ((void *)0);
}


decompiled_code:
__int64 __fastcall alaw_to_ulaw(unsigned __int8 a1)
{
return (unsigned __int8)alaw_to_ulaw_table[a1];
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 a1)
{
return (unsigned __int8)alaw_to_ulaw_table[a1];
}

original_code:
uint8_t alaw_to_ulaw(uint8_t alaw)
{
 return alaw_to_ulaw_table[alaw];
}

canonical_original_code:
unsigned char alaw_to_ulaw(unsigned char alaw)
{
 return alaw_to_ulaw_table[alaw];
}

variable_types:
alaw
unsigned char

return_type: unsigned char


decompiled_code:
__int64 __fastcall ulaw_to_alaw(unsigned __int8 a1)
{
return (unsigned __int8)ulaw_to_alaw_table[a1];
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int8 a1)
{
return (unsigned __int8)ulaw_to_alaw_table[a1];
}

original_code:
uint8_t ulaw_to_alaw(uint8_t ulaw)
{
 return ulaw_to_alaw_table[ulaw];
}

canonical_original_code:
unsigned char ulaw_to_alaw(unsigned char ulaw)
{
 return ulaw_to_alaw_table[ulaw];
}

variable_types:
ulaw
unsigned char


decompiled_code:
__int64 __fastcall esl_config_get_cas_bits(const char *a1, _BYTE *a2)
{
char *v2; // rax
const char *v3; // rbp
const char *v4; // r9
char v5; // al
char *v6; // rdx
unsigned __int8 v7; // cl
__int64 result; // rax
char v9; // [rsp+Bh] [rbp-1Dh] BYREF
char v10; // [rsp+Ch] [rbp-1Ch] BYREF
char v11; // [rsp+Dh] [rbp-1Bh] BYREF
char v12[26]; // [rsp+Eh] [rbp-1Ah] BYREF

v2 = strchr(a1, 58);
if ( v2 )
{
v3 = v2 + 1;
*a2 = 0;
v12[1] = 0;
if ( (unsigned int)_isoc99_sscanf(v2 + 1, "%c%c%c%c", &v9, &v10, &v11, v12) == 4 )
{
esl_log("esl_config.c", "esl_config_get_cas_bits", 233LL, 7LL, "CAS bits specification found: %s\n", &v9);
v5 = v9;
if ( v9 )
{
v6 = &v9;
v7 = 8;
do
{
if ( v5 == 49 )
{
*a2 |= v7;
}
else if ( v5 != 48 )
{
esl_log(
"esl_config.c",
"esl_config_get_cas_bits",
239LL,
3LL,
"Invalid CAS pattern specified: %s, just 0 or 1 allowed for each bit\n",
v4);
return 0xFFFFFFFFLL;
}
v7 >>= 1;
v5 = *++v6;
}
while ( *v6 );
result = 0LL;
}
else
{
result = 0LL;
}
}
else
{
esl_log(
"esl_config.c",
"esl_config_get_cas_bits",
229LL,
3LL,
"Invalid CAS bits specified: %s, :xxxx definition expected, where x is 1 or 0\n",
v3);
result = 0xFFFFFFFFLL;
}
}
else
{
esl_log(
"esl_config.c",
"esl_config_get_cas_bits",
220LL,
3LL,
"No CAS bits specified: %s, :xxxx definition expected, where x is 1 or 0\n",
0LL);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(const char *a1, _BYTE *a2)
{
char *v2; // rax
const char *v3; // rbp
const char *v4; // r9
char v5; // al
char *v6; // rdx
unsigned __int8 v7; // cl
__int64 result; // rax
char v9; // [rsp+Bh] [rbp-1Dh] BYREF
char v10; // [rsp+Ch] [rbp-1Ch] BYREF
char v11; // [rsp+Dh] [rbp-1Bh] BYREF
char v12[26]; // [rsp+Eh] [rbp-1Ah] BYREF

v2 = strchr(a1, 58);
if ( v2 )
{
v3 = v2 + 1;
*a2 = 0;
v12[1] = 0;
if ( (unsigned int)_isoc99_sscanf(v2 + 1, "%c%c%c%c", &v9, &v10, &v11, v12) == 4 )
{
esl_log("esl_config.c", "esl_config_get_cas_bits", 233LL, 7LL, "CAS bits specification found: %s\n", &v9);
v5 = v9;
if ( v9 )
{
v6 = &v9;
v7 = 8;
do
{
if ( v5 == 49 )
{
*a2 |= v7;
}
else if ( v5 != 48 )
{
esl_log(
"esl_config.c",
"esl_config_get_cas_bits",
239LL,
3LL,
"Invalid CAS pattern specified: %s, just 0 or 1 allowed for each bit\n",
v4);
return 0xFFFFFFFFLL;
}
v7 >>= 1;
v5 = *++v6;
}
while ( *v6 );
result = 0LL;
}
else
{
result = 0LL;
}
}
else
{
esl_log(
"esl_config.c",
"esl_config_get_cas_bits",
229LL,
3LL,
"Invalid CAS bits specified: %s, :xxxx definition expected, where x is 1 or 0\n",
v3);
result = 0xFFFFFFFFLL;
}
}
else
{
esl_log(
"esl_config.c",
"esl_config_get_cas_bits",
220LL,
3LL,
"No CAS bits specified: %s, :xxxx definition expected, where x is 1 or 0\n",
0LL);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int esl_config_get_cas_bits(char *strvalue, unsigned char *outbits)
{
 char cas_bits[5];
 unsigned char bit = 0x8;
 char *double_colon = strchr(strvalue, ':');
 int x = 0;
 if (!double_colon) {
  esl_log("esl_config.c", (const char *)__func__, 220, 3, "No CAS bits specified: %s, :xxxx definition expected, where x is 1 or 0\n", double_colon);
  return -1;
 }
 double_colon++;
 *outbits = 0;
 cas_bits[4] = 0;
 if (sscanf(double_colon, "%c%c%c%c", &cas_bits[0], &cas_bits[1], &cas_bits[2], &cas_bits[3]) != 4) {
  esl_log("esl_config.c", (const char *)__func__, 229, 3, "Invalid CAS bits specified: %s, :xxxx definition expected, where x is 1 or 0\n", double_colon);
  return -1;
 }
 esl_log("esl_config.c", (const char *)__func__, 233, 7, "CAS bits specification found: %s\n", cas_bits);
 for (; cas_bits[x]; x++) {
  if ('1' == cas_bits[x]) {
   *outbits |= bit;
  } else if ('0' != cas_bits[x]) {
   esl_log("esl_config.c", (const char *)__func__, 239, 3, "Invalid CAS pattern specified: %s, just 0 or 1 allowed for each bit\n");
   return -1;
  }
  bit >>= 1;
 }
 return 0;
}

canonical_original_code:
int esl_config_get_cas_bits(char *strvalue, unsigned char *outbits)
{
 char cas_bits[5];
 unsigned char bit = 0x8;
 char *double_colon = strchr(strvalue, ':');
 int x = 0;
 if (!double_colon) {
  esl_log("esl_config.c", (char *)__func__, 220, 3, "No CAS bits specified: %s, :xxxx definition expected, where x is 1 or 0\n", double_colon);
  return -1;
 }
 double_colon++;
 *outbits = 0;
 cas_bits[4] = 0;
 if (sscanf(double_colon, "%c%c%c%c", &cas_bits[0], &cas_bits[1], &cas_bits[2], &cas_bits[3]) != 4) {
  esl_log("esl_config.c", (char *)__func__, 229, 3, "Invalid CAS bits specified: %s, :xxxx definition expected, where x is 1 or 0\n", double_colon);
  return -1;
 }
 esl_log("esl_config.c", (char *)__func__, 233, 7, "CAS bits specification found: %s\n", cas_bits);
 for (; cas_bits[x]; x++) {
  if ('1' == cas_bits[x]) {
   *outbits |= bit;
  } else if ('0' != cas_bits[x]) {
   esl_log("esl_config.c", (char *)__func__, 239, 3, "Invalid CAS pattern specified: %s, just 0 or 1 allowed for each bit\n");
   return -1;
  }
  bit >>= 1;
 }
 return 0;
}

variable_types:
strvalue
char *

variable_types:
outbits
unsigned char *

variable_types:
bit
unsigned char

variable_types: x int


OscIpcGetParam

decompiled_code:
__int64 __fastcall OscIpcGetParam(unsigned __int8 a1, __int64 a2, unsigned int a3, unsigned int a4)
{
unsigned int v5; // eax
unsigned int v6; // ebx
unsigned int v7; // eax
unsigned int v8; // eax
int v10[13]; // [rsp+4h] [rbp-34h] BYREF

v10[0] = 0;
v10[1] = a3;
v10[2] = a4;
if ( a1 <= 1u && ipc[a1 + 536] == 1 && a2 )
{
if ( (ipc[268 * a1 + 260] & 2) != 0 )
{
OscLog(3LL, "%s: Only works in blocking mode!\n", "OscIpcGetParam");
v6 = -902;
}
else
{
v5 = OscIpcSendMsg(a1, v10);
v6 = v5;
if ( v5 )
{
OscLog(3LL, "%s: Error sending message! (%d)\n", "OscIpcGetParam", v5);
}
else
{
do
{
v7 = OscIpcRecvMsg(a1, v10);
v6 = v7;
}
while ( v7 == -901 );
if ( v7 )
{
OscLog(3LL, "%s: Error receiving message! (%d)\n", "OscIpcGetParam", v7);
}
else if ( ((v10[0] - 2) & 0xFFFFFFFD) != 0 )
{
OscLog(3LL, "%s: Received wrong message!\n", "OscIpcGetParam");
v6 = -9;
}
else
{
do
{
v8 = OscIpcRecv(a1, a2, a4);
v6 = v8;
}
while ( v8 == -901 );
if ( v8 )
{
OscLog(3LL, "%s: Error receiving data! (%d)\n", "OscIpcGetParam", v8);
}
else if ( v10[0] != 2 )
{
v6 = -903;
}
}
}
}
}
else
{
OscLog(3LL, "%s(%d, 0x%x, %u, %u): Invalid parameter!\n", "OscIpcGetParam", a1, a2, a3, a4);
v6 = -8;
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 a1, __int64 a2, unsigned int a3, unsigned int a4)
{
unsigned int v5; // eax
unsigned int v6; // ebx
unsigned int v7; // eax
unsigned int v8; // eax
int v10[13]; // [rsp+4h] [rbp-34h] BYREF

v10[0] = 0;
v10[1] = a3;
v10[2] = a4;
if ( a1 <= 1u && ipc[a1 + 536] == 1 && a2 )
{
if ( (ipc[268 * a1 + 260] & 2) != 0 )
{
OscLog(3LL, "%s: Only works in blocking mode!\n", "OscIpcGetParam");
v6 = -902;
}
else
{
v5 = OscIpcSendMsg(a1, v10);
v6 = v5;
if ( v5 )
{
OscLog(3LL, "%s: Error sending message! (%d)\n", "OscIpcGetParam", v5);
}
else
{
do
{
v7 = OscIpcRecvMsg(a1, v10);
v6 = v7;
}
while ( v7 == -901 );
if ( v7 )
{
OscLog(3LL, "%s: Error receiving message! (%d)\n", "OscIpcGetParam", v7);
}
else if ( ((v10[0] - 2) & 0xFFFFFFFD) != 0 )
{
OscLog(3LL, "%s: Received wrong message!\n", "OscIpcGetParam");
v6 = -9;
}
else
{
do
{
v8 = OscIpcRecv(a1, a2, a4);
v6 = v8;
}
while ( v8 == -901 );
if ( v8 )
{
OscLog(3LL, "%s: Error receiving data! (%d)\n", "OscIpcGetParam", v8);
}
else if ( v10[0] != 2 )
{
v6 = -903;
}
}
}
}
}
else
{
OscLog(3LL, "%s(%d, 0x%x, %u, %u): Invalid parameter!\n", "OscIpcGetParam", a1, a2, a3, a4);
v6 = -8;
}
return v6;
}

original_code:
OSC_ERR OscIpcGetParam(const uint8 chanID,
  void *pData,
  const uint32 paramID,
  const uint32 paramSize)
{
 struct OSC_IPC_MSG msg;
 OSC_ERR err;
 msg.enCmd = CMD_RD_PARAM;
 msg.paramID = paramID;
 msg.paramProp = (uint32)paramSize;
 if(((chanID >= 2) || (ipc.arybIpcChansBusy[chanID] == 0) || (pData == ((void *)0))))
 {
  OscLog(ERROR, "%s(%d, 0x%x, %u, %u): Invalid parameter!\n",
    __func__, chanID, pData, paramID, paramSize);
  return -EINVALID_PARAMETER;
 }
 if((ipc.aryIpcChans[chanID].flags & F_IPC_NONBLOCKING))
 {
  OscLog(ERROR, "%s: Only works in blocking mode!\n", __func__);
  return -EBLOCKING_MODE_ONLY;
 }
 err = OscIpcSendMsg(chanID, &msg);
 if(err != SUCCESS)
 {
  OscLog(ERROR, "%s: Error sending message! (%d)\n",
    __func__,
    err);
  return err;
 }
 do
 {
  err = OscIpcRecvMsg(chanID, &msg);
 } while(err == -ENO_MSG_AVAIL);
 if(err != SUCCESS)
 {
  OscLog(ERROR, "%s: Error receiving message! (%d)\n",
    __func__,
    err);
  return err;
 }
 if((msg.enCmd != CMD_RD_PARAM_ACK && msg.enCmd != CMD_RD_PARAM_NACK))
 {
  OscLog(ERROR, "%s: Received wrong message!\n", __func__);
  return -EDEVICE;
 }
 do
 {
  err = OscIpcRecv(chanID, pData, paramSize);
 } while(err == -ENO_MSG_AVAIL);
 if(err != SUCCESS)
 {
  OscLog(ERROR, "%s: Error receiving data! (%d)\n",
    __func__,
    err);
  return err;
 }
 if((msg.enCmd == CMD_RD_PARAM_ACK))
 {
  return SUCCESS;
 }
 else
 {
  return -ENEGATIVE_ACKNOWLEDGE;
 }
}

canonical_original_code:
int OscIpcGetParam(unsigned char chanID, void *pData, unsigned int paramID, unsigned int paramSize)
{
 struct OSC_IPC_MSG msg;
 int err;
 msg.enCmd = CMD_RD_PARAM;
 msg.paramID = paramID;
 msg.paramProp = (unsigned int)paramSize;
 if(((chanID >= 2) || (ipc.arybIpcChansBusy[chanID] == 0) || (pData == ((void *)0))))
 {
  OscLog(ERROR, "%s(%d, 0x%x, %u, %u): Invalid parameter!\n",
    __func__, chanID, pData, paramID, paramSize);
  return -EINVALID_PARAMETER;
 }
 if((ipc.aryIpcChans[chanID].flags & F_IPC_NONBLOCKING))
 {
  OscLog(ERROR, "%s: Only works in blocking mode!\n", __func__);
  return -EBLOCKING_MODE_ONLY;
 }
 err = OscIpcSendMsg(chanID, &msg);
 if(err != SUCCESS)
 {
  OscLog(ERROR, "%s: Error sending message! (%d)\n",
    __func__,
    err);
  return err;
 }
 do
 {
  err = OscIpcRecvMsg(chanID, &msg);
 } while(err == -ENO_MSG_AVAIL);
 if(err != SUCCESS)
 {
  OscLog(ERROR, "%s: Error receiving message! (%d)\n",
    __func__,
    err);
  return err;
 }
 if((msg.enCmd != CMD_RD_PARAM_ACK && msg.enCmd != CMD_RD_PARAM_NACK))
 {
  OscLog(ERROR, "%s: Received wrong message!\n", __func__);
  return -EDEVICE;
 }
 do
 {
  err = OscIpcRecv(chanID, pData, paramSize);
 } while(err == -ENO_MSG_AVAIL);
 if(err != SUCCESS)
 {
  OscLog(ERROR, "%s: Error receiving data! (%d)\n",
    __func__,
    err);
  return err;
 }
 if((msg.enCmd == CMD_RD_PARAM_ACK))
 {
  return SUCCESS;
 }
 else
 {
  return -ENEGATIVE_ACKNOWLEDGE;
 }
}

variable_types:
chanID
unsigned char

variable_types:
pData
void *

variable_types:
paramID
unsigned int

variable_types:
paramSize
unsigned int

variable_types: struct OSC_IPC_MSG { enum EnIpcCmds { CMD_RD_PARAM=0, CMD_WR_PARAM=1, CMD_RD_PARAM_ACK=2, CMD_WR_PARAM_ACK=3, CMD_RD_PARAM_NACK=4, CMD_WR_PARAM_NACK=5 } enCmd; unsigned int paramID; unsigned int paramProp; }

variable_types: err int

user_defined_types: struct OSC_IPC_MSG { enum EnIpcCmds enCmd; unsigned int paramID; unsigned int paramProp; }


OscIpcSetParam

decompiled_code:
__int64 __fastcall OscIpcSetParam(unsigned __int8 a1, __int64 a2, unsigned int a3, unsigned int a4)
{
unsigned int v5; // ebx
int v7[13]; // [rsp+4h] [rbp-34h] BYREF

v7[0] = 1;
v7[1] = a3;
v7[2] = a4;
if ( a1 <= 1u && ipc[a1 + 536] == 1 && a2 )
{
if ( (ipc[268 * a1 + 260] & 2) != 0 )
{
OscLog(3LL, "%s: Only works in blocking mode!\n", "OscIpcSetParam");
v5 = -902;
}
else
{
v5 = OscIpcSendMsg(a1, v7);
if ( !v5 )
{
v5 = OscIpcSend(a1, a2, a4);
if ( !v5 )
{
while ( (unsigned int)OscIpcRecvMsg(a1, v7) == -901 )
;
if ( v7[0] != 3 )
v5 = -903;
}
}
}
}
else
{
OscLog(3LL, "%s(%d, 0x%x, %u, %u): Invalid parameter!\n", "OscIpcSetParam", a1, a2, a3, a4);
v5 = -8;
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int8 a1, __int64 a2, unsigned int a3, unsigned int a4)
{
unsigned int v5; // ebx
int v7[13]; // [rsp+4h] [rbp-34h] BYREF

v7[0] = 1;
v7[1] = a3;
v7[2] = a4;
if ( a1 <= 1u && ipc[a1 + 536] == 1 && a2 )
{
if ( (ipc[268 * a1 + 260] & 2) != 0 )
{
OscLog(3LL, "%s: Only works in blocking mode!\n", "OscIpcSetParam");
v5 = -902;
}
else
{
v5 = OscIpcSendMsg(a1, v7);
if ( !v5 )
{
v5 = OscIpcSend(a1, a2, a4);
if ( !v5 )
{
while ( (unsigned int)OscIpcRecvMsg(a1, v7) == -901 )
;
if ( v7[0] != 3 )
v5 = -903;
}
}
}
}
else
{
OscLog(3LL, "%s(%d, 0x%x, %u, %u): Invalid parameter!\n", "OscIpcSetParam", a1, a2, a3, a4);
v5 = -8;
}
return v5;
}

original_code:
OSC_ERR OscIpcSetParam(const uint8 chanID,
  void *pData,
  const uint32 paramID,
  const uint32 paramSize)
{
 struct OSC_IPC_MSG msg;
 OSC_ERR err;
 msg.enCmd = CMD_WR_PARAM;
 msg.paramID = paramID;
 msg.paramProp = paramSize;
 if(((chanID >= 2) || (ipc.arybIpcChansBusy[chanID] == 0) || (pData == ((void *)0))))
 {
  OscLog(ERROR, "%s(%d, 0x%x, %u, %u): Invalid parameter!\n",
    __func__, chanID, pData, paramID, paramSize);
  return -EINVALID_PARAMETER;
 }
 if((ipc.aryIpcChans[chanID].flags & F_IPC_NONBLOCKING))
 {
  OscLog(ERROR, "%s: Only works in blocking mode!\n", __func__);
  return -EBLOCKING_MODE_ONLY;
 }
 err = OscIpcSendMsg(chanID, &msg);
 if(err != SUCCESS)
 {
  return err;
 }
 err = OscIpcSend(chanID, pData, paramSize);
 if(err != SUCCESS)
 {
  return err;
 }
 do
 {
  err = OscIpcRecvMsg(chanID, &msg);
 } while(err == -ENO_MSG_AVAIL);
 if((msg.enCmd == CMD_WR_PARAM_ACK))
 {
  return SUCCESS;
 }
 else
 {
  return -ENEGATIVE_ACKNOWLEDGE;
 }
}

canonical_original_code:
int OscIpcSetParam(unsigned char chanID, void *pData, unsigned int paramID, unsigned int paramSize)
{
 struct OSC_IPC_MSG msg;
 int err;
 msg.enCmd = CMD_WR_PARAM;
 msg.paramID = paramID;
 msg.paramProp = paramSize;
 if(((chanID >= 2) || (ipc.arybIpcChansBusy[chanID] == 0) || (pData == ((void *)0))))
 {
  OscLog(ERROR, "%s(%d, 0x%x, %u, %u): Invalid parameter!\n",
    __func__, chanID, pData, paramID, paramSize);
  return -EINVALID_PARAMETER;
 }
 if((ipc.aryIpcChans[chanID].flags & F_IPC_NONBLOCKING))
 {
  OscLog(ERROR, "%s: Only works in blocking mode!\n", __func__);
  return -EBLOCKING_MODE_ONLY;
 }
 err = OscIpcSendMsg(chanID, &msg);
 if(err != SUCCESS)
 {
  return err;
 }
 err = OscIpcSend(chanID, pData, paramSize);
 if(err != SUCCESS)
 {
  return err;
 }
 do
 {
  err = OscIpcRecvMsg(chanID, &msg);
 } while(err == -ENO_MSG_AVAIL);
 if((msg.enCmd == CMD_WR_PARAM_ACK))
 {
  return SUCCESS;
 }
 else
 {
  return -ENEGATIVE_ACKNOWLEDGE;
 }
}

user_defined_types: enum EnIpcCmds { CMD_RD_PARAM=0, CMD_WR_PARAM=1, CMD_RD_PARAM_ACK=2, CMD_WR_PARAM_ACK=3, CMD_RD_PARAM_NACK=4, CMD_WR_PARAM_NACK=5 }


OscIpcGetRequest

decompiled_code:
__int64 __fastcall OscIpcGetRequest(unsigned __int8 a1, __int64 a2)
{
unsigned int v2; // ebx
unsigned int v4; // er14
unsigned int *v5; // rax
unsigned int *v6; // rbp
unsigned int v7; // eax
int v8; // [rsp+4h] [rbp-34h] BYREF
int v9; // [rsp+8h] [rbp-30h]
unsigned int v10; // [rsp+Ch] [rbp-2Ch]

if ( a1 <= 1u && ipc[a1 + 536] == 1 && a2 )
{
v2 = OscIpcRecvMsg(a1, &v8);
if ( !v2 )
{
v4 = v10;
v5 = (unsigned int *)malloc(v10 + 8LL);
v6 = v5;
if ( v5 )
{
*v5 = v4;
*(_QWORD *)(a2 + 8) = v5 + 1;
if ( v8 )
{
v2 = -9;
if ( v8 != 1 )
goto LABEL_13;
*(_DWORD *)a2 = 1;
*(_DWORD *)(a2 + 4) = v9;
do
{
usleep(1u);
v7 = OscIpcRecv(a1, *(_QWORD *)(a2 + 8), *v6);
v2 = v7;
}
while ( v7 == -901 );
if ( v7 )
LABEL_13:
free(v6);
}
else
{
*(_DWORD *)a2 = 0;
*(_DWORD *)(a2 + 4) = v9;
}
}
else
{
v2 = -5;
}
}
}
else
{
OscLog(3LL, "%s(%d, 0x%x): Invalid parameter!\n", "OscIpcGetRequest", a1, a2);
v2 = -8;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int8 a1, __int64 a2)
{
unsigned int v2; // ebx
unsigned int v4; // er14
unsigned int *v5; // rax
unsigned int *v6; // rbp
unsigned int v7; // eax
int v8; // [rsp+4h] [rbp-34h] BYREF
int v9; // [rsp+8h] [rbp-30h]
unsigned int v10; // [rsp+Ch] [rbp-2Ch]

if ( a1 <= 1u && ipc[a1 + 536] == 1 && a2 )
{
v2 = OscIpcRecvMsg(a1, &v8);
if ( !v2 )
{
v4 = v10;
v5 = (unsigned int *)malloc(v10 + 8LL);
v6 = v5;
if ( v5 )
{
*v5 = v4;
*(_QWORD *)(a2 + 8) = v5 + 1;
if ( v8 )
{
v2 = -9;
if ( v8 != 1 )
goto LABEL_13;
*(_DWORD *)a2 = 1;
*(_DWORD *)(a2 + 4) = v9;
do
{
usleep(1u);
v7 = OscIpcRecv(a1, *(_QWORD *)(a2 + 8), *v6);
v2 = v7;
}
while ( v7 == -901 );
if ( v7 )
LABEL_13:
free(v6);
}
else
{
*(_DWORD *)a2 = 0;
*(_DWORD *)(a2 + 4) = v9;
}
}
else
{
v2 = -5;
}
}
}
else
{
OscLog(3LL, "%s(%d, 0x%x): Invalid parameter!\n", "OscIpcGetRequest", a1, a2);
v2 = -8;
}
return v2;
}

original_code:
OSC_ERR OscIpcGetRequest(const uint8 chanID,
  struct OSC_IPC_REQUEST *pRequest)
{
 struct OSC_IPC_MSG msg;
 struct OSC_IPC_PARAM_MEMORY *pTempMem;
 OSC_ERR err = SUCCESS;
 if(((chanID >= 2) || (ipc.arybIpcChansBusy[chanID] == 0) || (pRequest == ((void *)0))))
 {
  OscLog(ERROR, "%s(%d, 0x%x): Invalid parameter!\n",
    __func__, chanID, pRequest);
  return -EINVALID_PARAMETER;
 }
 err = OscIpcRecvMsg(chanID, &msg);
 if(err != SUCCESS)
 {
  return err;
 }
 pTempMem =
  malloc(msg.paramProp + sizeof(struct OSC_IPC_PARAM_MEMORY));
 if(pTempMem == ((void *)0))
  return -EOUT_OF_MEMORY;
 pTempMem->memLen = msg.paramProp;
 pRequest->pAddr = &pTempMem->data;
 switch(msg.enCmd)
 {
 case CMD_RD_PARAM:
  pRequest->enType = REQ_TYPE_READ;
  pRequest->paramID = msg.paramID;
  return SUCCESS;
  break;
 case CMD_WR_PARAM:
  pRequest->enType = REQ_TYPE_WRITE;
  pRequest->paramID = msg.paramID;
  break;
 default:
  err = -EDEVICE;
  goto exit_fail;
 }
 do
 {
  usleep(1);
  err = OscIpcRecv(chanID, pRequest->pAddr, pTempMem->memLen);
 } while(err == -ENO_MSG_AVAIL);
 if(err != SUCCESS)
 {
  goto exit_fail;
 }
 return SUCCESS;
 exit_fail:
 free(pTempMem);
 return err;
}

canonical_original_code:
int OscIpcGetRequest(unsigned char chanID, struct OSC_IPC_REQUEST *pRequest)
{
 struct OSC_IPC_MSG msg;
 struct OSC_IPC_PARAM_MEMORY *pTempMem;
 int err = SUCCESS;
 if(((chanID >= 2) || (ipc.arybIpcChansBusy[chanID] == 0) || (pRequest == ((void *)0))))
 {
  OscLog(ERROR, "%s(%d, 0x%x): Invalid parameter!\n",
    __func__, chanID, pRequest);
  return -EINVALID_PARAMETER;
 }
 err = OscIpcRecvMsg(chanID, &msg);
 if(err != SUCCESS)
 {
  return err;
 }
 pTempMem =
  malloc(msg.paramProp + sizeof(struct OSC_IPC_PARAM_MEMORY));
 if(pTempMem == ((void *)0))
  return -EOUT_OF_MEMORY;
 pTempMem->memLen = msg.paramProp;
 pRequest->pAddr = &pTempMem->data;
 switch(msg.enCmd)
 {
 case CMD_RD_PARAM:
  pRequest->enType = REQ_TYPE_READ;
  pRequest->paramID = msg.paramID;
  return SUCCESS;
  break;
 case CMD_WR_PARAM:
  pRequest->enType = REQ_TYPE_WRITE;
  pRequest->paramID = msg.paramID;
  break;
 default:
  err = -EDEVICE;
  goto exit_fail;
 }
 do
 {
  usleep(1);
  err = OscIpcRecv(chanID, pRequest->pAddr, pTempMem->memLen);
 } while(err == -ENO_MSG_AVAIL);
 if(err != SUCCESS)
 {
  goto exit_fail;
 }
 return SUCCESS;
 exit_fail:
 free(pTempMem);
 return err;
}

variable_types: struct OSC_IPC_REQUEST { enum EnRequestType { REQ_TYPE_READ=0, REQ_TYPE_WRITE=1 } enType; unsigned int paramID; void *pAddr; } *

variable_types: struct OSC_IPC_PARAM_MEMORY { unsigned int memLen; char data; } *

user_defined_types: struct OSC_IPC_REQUEST { enum EnRequestType enType; unsigned int paramID; void *pAddr; }


OscIpcAckRequest

decompiled_code:
__int64 __fastcall OscIpcAckRequest(unsigned __int8 a1, __int64 a2, unsigned __int8 a3)
{
__int64 v3; // r14
unsigned int v4; // ebp
unsigned int v5; // eax
int v7[13]; // [rsp+4h] [rbp-34h] BYREF

if ( a1 <= 1u && ipc[a1 + 536] == 1 && a2 )
{
v3 = *(_QWORD *)(a2 + 8);
v7[2] = 0;
v7[1] = *(_DWORD *)(a2 + 4);
if ( a3 )
{
if ( *(_DWORD *)a2 )
{
v4 = -8;
if ( *(_DWORD *)a2 == 1 )
{
v7[0] = 3;
goto LABEL_10;
}
LABEL_12:
free((void *)(v3 - 4));
return v4;
}
v7[0] = 2;
}
else if ( *(_DWORD *)a2 )
{
v4 = -8;
if ( *(_DWORD *)a2 != 1 )
goto LABEL_12;
v7[0] = 5;
}
else
{
v7[0] = 4;
}
LABEL_10:
v5 = OscIpcSendMsg(a1, v7);
v4 = v5;
if ( v5 )
{
if ( v5 != -22 )
OscLog(3LL, "%s: Failed to send acknowledge!\n", "OscIpcAckRequest");
}
else if ( !*(_DWORD *)a2 )
{
v4 = OscIpcSend(a1, v3, *(unsigned int *)(v3 - 4));
if ( v4 )
OscLog(3LL, "%s: Unable to send data.\n", "OscIpcAckRequest");
}
goto LABEL_12;
}
OscLog(3LL, "%s(%d, 0x%x, %d): Invalid parameter!\n", "OscIpcAckRequest", a1, a2, a3);
return (unsigned int)-8;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned __int8 a1, __int64 a2, unsigned __int8 a3)
{
__int64 v3; // r14
unsigned int v4; // ebp
unsigned int v5; // eax
int v7[13]; // [rsp+4h] [rbp-34h] BYREF

if ( a1 <= 1u && ipc[a1 + 536] == 1 && a2 )
{
v3 = *(_QWORD *)(a2 + 8);
v7[2] = 0;
v7[1] = *(_DWORD *)(a2 + 4);
if ( a3 )
{
if ( *(_DWORD *)a2 )
{
v4 = -8;
if ( *(_DWORD *)a2 == 1 )
{
v7[0] = 3;
goto LABEL_10;
}
LABEL_12:
free((void *)(v3 - 4));
return v4;
}
v7[0] = 2;
}
else if ( *(_DWORD *)a2 )
{
v4 = -8;
if ( *(_DWORD *)a2 != 1 )
goto LABEL_12;
v7[0] = 5;
}
else
{
v7[0] = 4;
}
LABEL_10:
v5 = OscIpcSendMsg(a1, v7);
v4 = v5;
if ( v5 )
{
if ( v5 != -22 )
OscLog(3LL, "%s: Failed to send acknowledge!\n", "OscIpcAckRequest");
}
else if ( !*(_DWORD *)a2 )
{
v4 = OscIpcSend(a1, v3, *(unsigned int *)(v3 - 4));
if ( v4 )
OscLog(3LL, "%s: Unable to send data.\n", "OscIpcAckRequest");
}
goto LABEL_12;
}
OscLog(3LL, "%s(%d, 0x%x, %d): Invalid parameter!\n", "OscIpcAckRequest", a1, a2, a3);
return (unsigned int)-8;
}

original_code:
OSC_ERR OscIpcAckRequest(const uint8 chanID,
  const struct OSC_IPC_REQUEST *pRequest,
  const _Bool bSucceeded)
{
 struct OSC_IPC_MSG msg;
 struct OSC_IPC_PARAM_MEMORY *pMem;
 uint8 *pTemp;
 OSC_ERR err;
 if(((chanID >= 2) || (ipc.arybIpcChansBusy[chanID] == 0) || (pRequest == ((void *)0))))
 {
  OscLog(ERROR, "%s(%d, 0x%x, %d): Invalid parameter!\n",
    __func__, chanID, pRequest, bSucceeded);
  return -EINVALID_PARAMETER;
 }
 err = SUCCESS;
 pTemp = (uint8*)pRequest->pAddr;
 pTemp -= sizeof(pMem->memLen);
 pMem = (struct OSC_IPC_PARAM_MEMORY*)pTemp;
 msg.paramProp = 0;
 msg.paramID = pRequest->paramID;
 if((bSucceeded == 1))
 {
  switch(pRequest->enType)
  {
  case REQ_TYPE_READ:
   msg.enCmd = CMD_RD_PARAM_ACK;
   break;
  case REQ_TYPE_WRITE:
   msg.enCmd = CMD_WR_PARAM_ACK;
   break;
  default:
   err = -EINVALID_PARAMETER;
   goto exit;
  }
 } else {
  switch(pRequest->enType)
  {
  case REQ_TYPE_READ:
   msg.enCmd = CMD_RD_PARAM_NACK;
   break;
  case REQ_TYPE_WRITE:
   msg.enCmd = CMD_WR_PARAM_NACK;
   break;
  default:
   err = -EINVALID_PARAMETER;
   goto exit;
  }
 }
 err = OscIpcSendMsg(chanID, &msg);
 if(err != SUCCESS)
 {
  if(err != -ETRY_AGAIN)
  {
   OscLog(ERROR, "%s: Failed to send acknowledge!\n", __func__);
  }
  goto exit;
 }
 if(pRequest->enType == CMD_RD_PARAM)
 {
  err = OscIpcSend(chanID, &pMem->data, pMem->memLen);
  if(err != SUCCESS)
  {
   OscLog(ERROR, "%s: Unable to send data.\n", __func__);
   goto exit;
  }
 }
exit:
 free(pMem);
 return err;
}

canonical_original_code:
int OscIpcAckRequest(unsigned char chanID, struct OSC_IPC_REQUEST *pRequest, _Bool bSucceeded)
{
 struct OSC_IPC_MSG msg;
 struct OSC_IPC_PARAM_MEMORY *pMem;
 unsigned char *pTemp;
 int err;
 if(((chanID >= 2) || (ipc.arybIpcChansBusy[chanID] == 0) || (pRequest == ((void *)0))))
 {
  OscLog(ERROR, "%s(%d, 0x%x, %d): Invalid parameter!\n",
    __func__, chanID, pRequest, bSucceeded);
  return -EINVALID_PARAMETER;
 }
 err = SUCCESS;
 pTemp = (unsigned char *)pRequest->pAddr;
 pTemp -= sizeof(pMem->memLen);
 pMem = (struct OSC_IPC_PARAM_MEMORY *)pTemp;
 msg.paramProp = 0;
 msg.paramID = pRequest->paramID;
 if((bSucceeded == 1))
 {
  switch(pRequest->enType)
  {
  case REQ_TYPE_READ:
   msg.enCmd = CMD_RD_PARAM_ACK;
   break;
  case REQ_TYPE_WRITE:
   msg.enCmd = CMD_WR_PARAM_ACK;
   break;
  default:
   err = -EINVALID_PARAMETER;
   goto exit;
  }
 } else {
  switch(pRequest->enType)
  {
  case REQ_TYPE_READ:
   msg.enCmd = CMD_RD_PARAM_NACK;
   break;
  case REQ_TYPE_WRITE:
   msg.enCmd = CMD_WR_PARAM_NACK;
   break;
  default:
   err = -EINVALID_PARAMETER;
   goto exit;
  }
 }
 err = OscIpcSendMsg(chanID, &msg);
 if(err != SUCCESS)
 {
  if(err != -ETRY_AGAIN)
  {
   OscLog(ERROR, "%s: Failed to send acknowledge!\n", __func__);
  }
  goto exit;
 }
 if(pRequest->enType == CMD_RD_PARAM)
 {
  err = OscIpcSend(chanID, &pMem->data, pMem->memLen);
  if(err != SUCCESS)
  {
   OscLog(ERROR, "%s: Unable to send data.\n", __func__);
   goto exit;
  }
 }
exit:
 free(pMem);
 return err;
}

variable_types:
pTemp
unsigned char *

user_defined_types: struct OSC_IPC_PARAM_MEMORY { unsigned int memLen; char data; }

user_defined_types: enum EnRequestType { REQ_TYPE_READ=0, REQ_TYPE_WRITE=1 }


encodeMCU

decompiled_code:
__int64 __fastcall encodeMCU(__int64 a1, int a2, __int64 a3)
{
__int64 v4; // rbp
__int64 v6; // rbp
__int64 v7; // rbp

levelshift(Image);
DCT(Image);
quantization(Image, &ILqt, &Temp);
v4 = huffman(a1, 1LL, a3, &Temp);
if ( (unsigned int)(a2 - 2) <= 1 )
{
levelshift(Image + 128);
DCT(Image + 128);
quantization(Image + 128, &ILqt, &Temp);
v4 = huffman(a1, 1LL, v4, &Temp);
if ( a2 == 3 )
{
levelshift(Image + 256);
DCT(Image + 256);
quantization(Image + 256, &ILqt, &Temp);
v7 = huffman(a1, 1LL, v4, &Temp);
levelshift(Image + 384);
DCT(Image + 384);
quantization(Image + 384, &ILqt, &Temp);
v4 = huffman(a1, 1LL, v7, &Temp);
}
goto LABEL_6;
}
if ( a2 != 4 )
{
LABEL_6:
levelshift(Image + 512);
DCT(Image + 512);
quantization(Image + 512, &ICqt, &Temp);
v6 = huffman(a1, 2LL, v4, &Temp);
levelshift(Image + 640);
DCT(Image + 640);
quantization(Image + 640, &ICqt, &Temp);
v4 = huffman(a1, 3LL, v6, &Temp);
}
++*(_WORD *)(a1 + 32);
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2, __int64 a3)
{
__int64 v4; // rbp
__int64 v6; // rbp
__int64 v7; // rbp

levelshift(Image);
DCT(Image);
quantization(Image, &ILqt, &Temp);
v4 = huffman(a1, 1LL, a3, &Temp);
if ( (unsigned int)(a2 - 2) <= 1 )
{
levelshift(Image + 128);
DCT(Image + 128);
quantization(Image + 128, &ILqt, &Temp);
v4 = huffman(a1, 1LL, v4, &Temp);
if ( a2 == 3 )
{
levelshift(Image + 256);
DCT(Image + 256);
quantization(Image + 256, &ILqt, &Temp);
v7 = huffman(a1, 1LL, v4, &Temp);
levelshift(Image + 384);
DCT(Image + 384);
quantization(Image + 384, &ILqt, &Temp);
v4 = huffman(a1, 1LL, v7, &Temp);
}
goto LABEL_6;
}
if ( a2 != 4 )
{
LABEL_6:
levelshift(Image + 512);
DCT(Image + 512);
quantization(Image + 512, &ICqt, &Temp);
v6 = huffman(a1, 2LL, v4, &Temp);
levelshift(Image + 640);
DCT(Image + 640);
quantization(Image + 640, &ICqt, &Temp);
v4 = huffman(a1, 3LL, v6, &Temp);
}
++*(_WORD *)(a1 + 32);
return v4;
}

original_code:
uint8* encodeMCU (JPEG_ENCODER_STRUCTURE *jpeg_encoder_structure, uint32 image_format, uint8 *output_ptr)
{
 levelshift (Image->Y1);
 DCT ((int16 *)Image->Y1);
 quantization (Image->Y1, ILqt, Temp);
 output_ptr = huffman (jpeg_encoder_structure, 1, output_ptr, Temp);
 if (image_format == OSC_PICTURE_YUV_420 ||
     image_format == OSC_PICTURE_YUV_422)
 {
  levelshift (Image->Y2);
  DCT (Image->Y2);
  quantization (Image->Y2, ILqt, Temp);
  output_ptr = huffman (jpeg_encoder_structure, 1, output_ptr, Temp);
  if (image_format == OSC_PICTURE_YUV_420)
  {
   levelshift (Image->Y3);
   DCT (Image->Y3);
   quantization (Image->Y3, ILqt, Temp);
   output_ptr = huffman (jpeg_encoder_structure, 1, output_ptr, Temp);
   levelshift (Image->Y4);
   DCT (Image->Y4);
   quantization (Image->Y4, ILqt, Temp);
   output_ptr = huffman (jpeg_encoder_structure, 1, output_ptr, Temp);
  }
 }
 if (image_format != OSC_PICTURE_YUV_400)
 {
  levelshift (Image->CB);
  DCT (Image->CB);
  quantization (Image->CB, ICqt, Temp);
  output_ptr = huffman (jpeg_encoder_structure, 2, output_ptr, Temp);
  levelshift (Image->CR);
  DCT (Image->CR);
  quantization (Image->CR, ICqt, Temp);
  output_ptr = huffman (jpeg_encoder_structure, 3, output_ptr, Temp);
 }
 jpeg_encoder_structure->debug_pass++;
 return output_ptr;
}

canonical_original_code:
unsigned char *encodeMCU(struct JPEG_ENCODER_STRUCTURE *jpeg_encoder_structure, unsigned int image_format, unsigned char *output_ptr)
{
 levelshift (Image->Y1);
 DCT ((short *)Image->Y1);
 quantization (Image->Y1, ILqt, Temp);
 output_ptr = huffman (jpeg_encoder_structure, 1, output_ptr, Temp);
 if (image_format == OSC_PICTURE_YUV_420 ||
     image_format == OSC_PICTURE_YUV_422)
 {
  levelshift (Image->Y2);
  DCT (Image->Y2);
  quantization (Image->Y2, ILqt, Temp);
  output_ptr = huffman (jpeg_encoder_structure, 1, output_ptr, Temp);
  if (image_format == OSC_PICTURE_YUV_420)
  {
   levelshift (Image->Y3);
   DCT (Image->Y3);
   quantization (Image->Y3, ILqt, Temp);
   output_ptr = huffman (jpeg_encoder_structure, 1, output_ptr, Temp);
   levelshift (Image->Y4);
   DCT (Image->Y4);
   quantization (Image->Y4, ILqt, Temp);
   output_ptr = huffman (jpeg_encoder_structure, 1, output_ptr, Temp);
  }
 }
 if (image_format != OSC_PICTURE_YUV_400)
 {
  levelshift (Image->CB);
  DCT (Image->CB);
  quantization (Image->CB, ICqt, Temp);
  output_ptr = huffman (jpeg_encoder_structure, 2, output_ptr, Temp);
  levelshift (Image->CR);
  DCT (Image->CR);
  quantization (Image->CR, ICqt, Temp);
  output_ptr = huffman (jpeg_encoder_structure, 3, output_ptr, Temp);
 }
 jpeg_encoder_structure->debug_pass++;
 return output_ptr;
}

variable_types: struct JPEG_ENCODER_STRUCTURE { unsigned short mcu_width; unsigned short mcu_height; unsigned short horizontal_mcus; unsigned short vertical_mcus; unsigned short cols_in_right_mcus; unsigned short rows_in_bottom_mcus; unsigned short rows; unsigned short cols; unsigned short length_minus_mcu_width; unsigned short length_minus_width; unsigned short incr; unsigned short mcu_width_size; unsigned short offset; short ldc1; short ldc2; short ldc3; short debug_pass; } *

return_type: unsigned char *


OscJpgEncode

decompiled_code:
__int64 __fastcall OscJpgEncode(char **a1, const void *a2, unsigned int a3)
{
char *v4; // r13
_WORD *v5; // rbx
__int64 v6; // r12
unsigned __int16 v7; // ax
unsigned __int16 i; // r15
__int16 v9; // ax
__int16 v10; // ax
unsigned __int16 j; // bp
unsigned __int16 v12; // ax

v4 = *a1;
if ( !Image )
{
Image = (__int64)malloc(0x300uLL);
if ( !Image )
OscFatalErr("Could not allocate memory\n");
}
if ( !JpegStruct )
{
JpegStruct = (__int64)malloc(0x22uLL);
if ( !JpegStruct )
OscFatalErr("Could not allocate memory\n");
}
v5 = (_WORD *)JpegStruct;
if ( *((_DWORD *)a1 + 3) == 8 )
{
*((_DWORD *)a1 + 3) = 1;
BGR_2_444(v4, a2, *((unsigned __int16 *)a1 + 4), *((unsigned __int16 *)a1 + 5));
memcpy(v4, a2, 3 * *((unsigned __int16 *)a1 + 5) * *((unsigned __int16 *)a1 + 4));
}
if ( *((_DWORD *)a1 + 3) != 1 )
OscFatalErr("Unsupported Image Format in OscJpgEncode\n");
initialization(v5, *((_DWORD *)a1 + 3), *((unsigned __int16 *)a1 + 4), *((unsigned __int16 *)a1 + 5));
initialize_quantization_tables(a3);
v6 = write_markers(a2, *((unsigned int *)a1 + 3), *((unsigned __int16 *)a1 + 4), *((unsigned __int16 *)a1 + 5));
v7 = v5[3];
if ( v7 )
{
for ( i = 1; i <= v7; ++i )
{
if ( v7 <= i )
v9 = v5[5];
else
v9 = v5[1];
v5[6] = v9;
v12 = v5[2];
if ( v12 )
{
for ( j = 1; j <= v12; ++j )
{
if ( v12 <= j )
{
v5[7] = v5[4];
v10 = v5[9];
}
else
{
v5[7] = *v5;
v10 = v5[8];
}
v5[10] = v10;
read_format(Image, v5, v4);
v6 = encodeMCU((__int64)v5, *((_DWORD *)a1 + 3), v6);
v4 += (unsigned __int16)v5[11];
v12 = v5[2];
}
}
v4 += (unsigned __int16)v5[12];
v7 = v5[3];
}
}
close_bitstream(v6);
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func2(char **a1, const void *a2, unsigned int a3)
{
char *v4; // r13
_WORD *v5; // rbx
__int64 v6; // r12
unsigned __int16 v7; // ax
unsigned __int16 i; // r15
__int16 v9; // ax
__int16 v10; // ax
unsigned __int16 j; // bp
unsigned __int16 v12; // ax

v4 = *a1;
if ( !Image )
{
Image = (__int64)malloc(0x300uLL);
if ( !Image )
OscFatalErr("Could not allocate memory\n");
}
if ( !JpegStruct )
{
JpegStruct = (__int64)malloc(0x22uLL);
if ( !JpegStruct )
OscFatalErr("Could not allocate memory\n");
}
v5 = (_WORD *)JpegStruct;
if ( *((_DWORD *)a1 + 3) == 8 )
{
*((_DWORD *)a1 + 3) = 1;
BGR_2_444(v4, a2, *((unsigned __int16 *)a1 + 4), *((unsigned __int16 *)a1 + 5));
memcpy(v4, a2, 3 * *((unsigned __int16 *)a1 + 5) * *((unsigned __int16 *)a1 + 4));
}
if ( *((_DWORD *)a1 + 3) != 1 )
OscFatalErr("Unsupported Image Format in OscJpgEncode\n");
func0(v5, *((_DWORD *)a1 + 3), *((unsigned __int16 *)a1 + 4), *((unsigned __int16 *)a1 + 5));
initialize_quantization_tables(a3);
v6 = write_markers(a2, *((unsigned int *)a1 + 3), *((unsigned __int16 *)a1 + 4), *((unsigned __int16 *)a1 + 5));
v7 = v5[3];
if ( v7 )
{
for ( i = 1; i <= v7; ++i )
{
if ( v7 <= i )
v9 = v5[5];
else
v9 = v5[1];
v5[6] = v9;
v12 = v5[2];
if ( v12 )
{
for ( j = 1; j <= v12; ++j )
{
if ( v12 <= j )
{
v5[7] = v5[4];
v10 = v5[9];
}
else
{
v5[7] = *v5;
v10 = v5[8];
}
v5[10] = v10;
read_format(Image, v5, v4);
v6 = func1((__int64)v5, *((_DWORD *)a1 + 3), v6);
v4 += (unsigned __int16)v5[11];
v12 = v5[2];
}
}
v4 += (unsigned __int16)v5[12];
v7 = v5[3];
}
}
close_bitstream(v6);
return v6;
}

original_code:
uint8* OscJpgEncode(struct OSC_PICTURE *pic, uint8 *output_ptr, uint32 quality_factor)
{
 uint16 i, j;
 uint8 *input_ptr = (uint8 *)pic->data;
 JPEG_ENCODER_STRUCTURE *jpeg_encoder_structure;
 if (Image==((void *)0)) {
  Image = malloc(sizeof(struct IMGDATA));
  if (Image == ((void *)0))
   OscFatalErr("Could not allocate memory\n");
 }
 if (JpegStruct==((void *)0)) {
  JpegStruct= malloc(sizeof(JPEG_ENCODER_STRUCTURE));
  if (JpegStruct == ((void *)0))
   OscFatalErr("Could not allocate memory\n");
 }
 jpeg_encoder_structure = JpegStruct;
 if (pic->type == OSC_PICTURE_BGR_24)
 {
  pic->type = OSC_PICTURE_YUV_444;
  BGR_2_444 (input_ptr, output_ptr, pic->width, pic->height);
  memcpy(input_ptr, output_ptr, pic->width*pic->height*3);
 }
 if (pic->type != OSC_PICTURE_YUV_444)
 {
  OscFatalErr("Unsupported Image Format in OscJpgEncode\n");
 }
 initialization (jpeg_encoder_structure, pic->type, pic->width, pic->height);
 initialize_quantization_tables (quality_factor);
 output_ptr = write_markers (output_ptr, pic->type, pic->width, pic->height);
 for (i=1; i<=jpeg_encoder_structure->vertical_mcus; i++)
 {
  if (i < jpeg_encoder_structure->vertical_mcus)
   jpeg_encoder_structure->rows = jpeg_encoder_structure->mcu_height;
  else
   jpeg_encoder_structure->rows = jpeg_encoder_structure->rows_in_bottom_mcus;
  for (j=1; j<=jpeg_encoder_structure->horizontal_mcus; j++)
  {
   if (j < jpeg_encoder_structure->horizontal_mcus)
   {
    jpeg_encoder_structure->cols = jpeg_encoder_structure->mcu_width;
    jpeg_encoder_structure->incr = jpeg_encoder_structure->length_minus_mcu_width;
   }
   else
   {
    jpeg_encoder_structure->cols = jpeg_encoder_structure->cols_in_right_mcus;
    jpeg_encoder_structure->incr = jpeg_encoder_structure->length_minus_width;
   }
   read_format (Image, jpeg_encoder_structure, input_ptr);
   output_ptr = encodeMCU (jpeg_encoder_structure, pic->type, output_ptr);
   input_ptr += jpeg_encoder_structure->mcu_width_size;
  }
  input_ptr += jpeg_encoder_structure->offset;
 }
 close_bitstream (output_ptr);
 return output_ptr;
}

canonical_original_code:
unsigned char *OscJpgEncode(struct OSC_PICTURE *pic, unsigned char *output_ptr, unsigned int quality_factor)
{
 unsigned short i; unsigned short j;
 unsigned char *input_ptr = (uint8 *)pic->data;
 struct JPEG_ENCODER_STRUCTURE *jpeg_encoder_structure;
 if (Image==((void *)0)) {
  Image = malloc(sizeof(struct IMGDATA));
  if (Image == ((void *)0))
   OscFatalErr("Could not allocate memory\n");
 }
 if (JpegStruct==((void *)0)) {
  JpegStruct= malloc(sizeof(JPEG_ENCODER_STRUCTURE));
  if (JpegStruct == ((void *)0))
   OscFatalErr("Could not allocate memory\n");
 }
 jpeg_encoder_structure = JpegStruct;
 if (pic->type == OSC_PICTURE_BGR_24)
 {
  pic->type = OSC_PICTURE_YUV_444;
  BGR_2_444 (input_ptr, output_ptr, pic->width, pic->height);
  memcpy(input_ptr, output_ptr, pic->width*pic->height*3);
 }
 if (pic->type != OSC_PICTURE_YUV_444)
 {
  OscFatalErr("Unsupported Image Format in OscJpgEncode\n");
 }
 initialization (jpeg_encoder_structure, pic->type, pic->width, pic->height);
 initialize_quantization_tables (quality_factor);
 output_ptr = write_markers (output_ptr, pic->type, pic->width, pic->height);
 for (i=1; i<=jpeg_encoder_structure->vertical_mcus; i++)
 {
  if (i < jpeg_encoder_structure->vertical_mcus)
   jpeg_encoder_structure->rows = jpeg_encoder_structure->mcu_height;
  else
   jpeg_encoder_structure->rows = jpeg_encoder_structure->rows_in_bottom_mcus;
  for (j=1; j<=jpeg_encoder_structure->horizontal_mcus; j++)
  {
   if (j < jpeg_encoder_structure->horizontal_mcus)
   {
    jpeg_encoder_structure->cols = jpeg_encoder_structure->mcu_width;
    jpeg_encoder_structure->incr = jpeg_encoder_structure->length_minus_mcu_width;
   }
   else
   {
    jpeg_encoder_structure->cols = jpeg_encoder_structure->cols_in_right_mcus;
    jpeg_encoder_structure->incr = jpeg_encoder_structure->length_minus_width;
   }
   read_format (Image, jpeg_encoder_structure, input_ptr);
   output_ptr = encodeMCU (jpeg_encoder_structure, pic->type, output_ptr);
   input_ptr += jpeg_encoder_structure->mcu_width_size;
  }
  input_ptr += jpeg_encoder_structure->offset;
 }
 close_bitstream (output_ptr);
 return output_ptr;
}

variable_types: struct OSC_PICTURE { void *data; unsigned short width; unsigned short height; enum EnOscPictureType { OSC_PICTURE_GREYSCALE=0, OSC_PICTURE_YUV_444=1, OSC_PICTURE_YUV_422=2, OSC_PICTURE_YUV_420=3, OSC_PICTURE_YUV_400=4, OSC_PICTURE_CHROM_U=5, OSC_PICTURE_CHROM_V=6, OSC_PICTURE_HUE=7, OSC_PICTURE_BGR_24=8, OSC_PICTURE_RGB_24=9, OSC_PICTURE_BINARY=10 } type; } *

variable_types:
i
unsigned short

variable_types:
j
unsigned short

user_defined_types: struct IMGDATA { short Y1[64]; short Y2[64]; short Y3[64]; short Y4[64]; short CB[64]; short CR[64]; }

user_defined_types: struct OSC_PICTURE { void *data; unsigned short width; unsigned short height; enum EnOscPictureType type; }

user_defined_types: struct JPEG_ENCODER_STRUCTURE { unsigned short mcu_width; unsigned short mcu_height; unsigned short horizontal_mcus; unsigned short vertical_mcus; unsigned short cols_in_right_mcus; unsigned short rows_in_bottom_mcus; unsigned short rows; unsigned short cols; unsigned short length_minus_mcu_width; unsigned short length_minus_width; unsigned short incr; unsigned short mcu_width_size; unsigned short offset; short ldc1; short ldc2; short ldc3; short debug_pass; }


OscDmaCreate

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

result = 0LL;
memset(&dma, 0, 0x1F8uLL);
return result;
}

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

result = 0LL;
memset(&dma, 0, 0x1F8uLL);
return result;
}

original_code:
OSC_ERR OscDmaCreate()
{
 dma = (struct OSC_DMA) { };
 return SUCCESS;
}

canonical_original_code:
int OscDmaCreate()
{
 dma = (struct OSC_DMA) { };
 return SUCCESS;
}

user_defined_types: struct OSC_DMA { struct DMA_CHAIN dmaChains[2]; unsigned short nChainsAllocated; }

user_defined_types: struct DMA_CHAIN { unsigned int syncFlag; unsigned int nMoves; struct DMA_DESC arySrcDesc[-1]; struct DMA_DESC aryDstDesc[-1]; }

user_defined_types: struct DMA_DESC { unsigned long startAddr; unsigned short config; unsigned short xCount; short xModify; unsigned short yCount; short yModify; }


OscDmaResetChain

decompiled_code:
__int64 __fastcall OscDmaResetChain(__int64 a1, __int64 a2, const char *a3)
{
__int64 result; // rax

if ( !a1 )
return OscLog(3LL, "%s: Invalid parameter!\n", a3);
*(_DWORD *)(a1 + 4) = 0;
return result;
}

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

if ( !a1 )
return OscLog(3LL, "%s: Invalid parameter!\n", a3);
*(_DWORD *)(a1 + 4) = 0;
return result;
}

original_code:
inline void OscDmaResetChain(void *hChainHandle)
{
 struct DMA_CHAIN *pChain = (struct DMA_CHAIN*)hChainHandle;
 if((hChainHandle == ((void *)0)))
 {
     OscLog(ERROR, "%s: Invalid parameter!\n");
     return;
 }
 pChain->nMoves = 0;
}

variable_types:
hChainHandle
void *

variable_types: struct DMA_CHAIN { unsigned int syncFlag; unsigned int nMoves; struct DMA_DESC { unsigned long startAddr; unsigned short config; unsigned short xCount; short xModify; unsigned short yCount; short yModify; } arySrcDesc[-1]; struct DMA_DESC aryDstDesc[-1]; } *


OscDmaAllocChain

decompiled_code:
__int64 __fastcall OscDmaAllocChain(__int64 *a1, __int64 a2)
{
unsigned __int16 v2; // ax
__int64 result; // rax

if ( !a1 )
return 4294967288LL;
v2 = dma[248];
if ( v2 == 2 )
{
OscLog(4LL, "%s: All DMA chains already allocated!\n", "OscDmaAllocChain");
*a1 = 0LL;
result = 4294966196LL;
}
else
{
*a1 = (__int64)&dma[124 * v2];
++dma[248];
OscDmaResetChain(*a1, a2, (const char *)(31LL * v2));
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 *a1, __int64 a2)
{
unsigned __int16 v2; // ax
__int64 result; // rax

if ( !a1 )
return 4294967288LL;
v2 = dma[248];
if ( v2 == 2 )
{
OscLog(4LL, "%s: All DMA chains already allocated!\n", "OscDmaAllocChain");
*a1 = 0LL;
result = 4294966196LL;
}
else
{
*a1 = (__int64)&dma[124 * v2];
++dma[248];
func1(*a1, a2, (const char *)(31LL * v2));
result = 0LL;
}
return result;
}

original_code:
OSC_ERR OscDmaAllocChain(void **phChainHandle)
{
 struct DMA_CHAIN ** pChain;
 if((phChainHandle == ((void *)0)))
 {
  return -EINVALID_PARAMETER;
 }
 if((dma.nChainsAllocated == 2))
 {
  OscLog(WARN, "%s: All DMA chains already allocated!\n",
    __func__);
  *phChainHandle = ((void *)0);
  return -EDMA_NO_MORE_CHAINS_AVAILABLE;
 }
 pChain = (struct DMA_CHAIN**)phChainHandle;
 *pChain = &dma.dmaChains[dma.nChainsAllocated];
 dma.nChainsAllocated++;
 OscDmaResetChain(*pChain);
 return SUCCESS;
}

canonical_original_code:
int OscDmaAllocChain(void **phChainHandle)
{
 struct DMA_CHAIN **pChain;
 if((phChainHandle == ((void *)0)))
 {
  return -EINVALID_PARAMETER;
 }
 if((dma.nChainsAllocated == 2))
 {
  OscLog(WARN, "%s: All DMA chains already allocated!\n",
    __func__);
  *phChainHandle = ((void *)0);
  return -EDMA_NO_MORE_CHAINS_AVAILABLE;
 }
 pChain = (struct DMA_CHAIN **)phChainHandle;
 *pChain = &dma.dmaChains[dma.nChainsAllocated];
 dma.nChainsAllocated++;
 OscDmaResetChain(*pChain);
 return SUCCESS;
}

variable_types:
phChainHandle
void **

variable_types: struct DMA_CHAIN { unsigned int syncFlag; unsigned int nMoves; struct DMA_DESC { unsigned long startAddr; unsigned short config; unsigned short xCount; short xModify; unsigned short yCount; short yModify; } arySrcDesc[-1]; struct DMA_DESC aryDstDesc[-1]; } **


original_code:
OSC_ERR OscDmaAdd2DMove(void *hChainHandle,
  const void *pDstAddr,
  const enum EnDmaWdSize enDstWdSize,
  const uint16 dstXCount, const int32 dstXModify,
  const uint16 dstYCount, const int32 dstYModify,
  const void *pSrcAddr,
  const enum EnDmaWdSize enSrcWdSize,
  const uint16 srcXCount, const int32 srcXModify,
  const uint16 srcYCount, const int32 srcYModify)
{
 struct DMA_CHAIN *pChain = (struct DMA_CHAIN*)hChainHandle;
 struct DMA_DESC *pSrcDesc = &pChain->arySrcDesc[pChain->nMoves];
 struct DMA_DESC *pDstDesc = &pChain->aryDstDesc[pChain->nMoves];
 if((pChain->nMoves == 4))
 {
  return -EINVALID_PARAMETER;
 }
 pChain->nMoves++;
 pDstDesc->config = 0x00000700 | 0x00004000 | 0x00000001 | 0x00000002;
 pDstDesc->config |= enDstWdSize;
 pDstDesc->startAddr = (uintptr_t)pDstAddr;
 pDstDesc->xCount = dstXCount;
 pDstDesc->xModify = dstXModify;
 pDstDesc->yCount = dstYCount;
 pDstDesc->yModify = dstYModify;
 if(dstYCount > 1)
 {
  pDstDesc->config |= 0x00000010;
 }
 pSrcDesc->config = 0x00000700 | 0x00004000 | 0x00000001;
 pSrcDesc->config |= enSrcWdSize;
 pSrcDesc->startAddr = (uintptr_t)pSrcAddr;
 pSrcDesc->xCount = srcXCount;
 pSrcDesc->xModify = srcXModify;
 pSrcDesc->yCount = srcYCount;
 pSrcDesc->yModify = srcYModify;
 if(srcYCount > 1)
 {
  pSrcDesc->config |= 0x00000010;
 }
 {};
 {};
 return SUCCESS;
}

canonical_original_code:
int OscDmaAdd2DMove(void *hChainHandle, void *pDstAddr, enum EnDmaWdSize enDstWdSize, unsigned short dstXCount, int dstXModify, unsigned short dstYCount, int dstYModify, void *pSrcAddr, enum EnDmaWdSize enSrcWdSize, unsigned short srcXCount, int srcXModify, unsigned short srcYCount, int srcYModify)
{
 struct DMA_CHAIN *pChain = (struct DMA_CHAIN*)hChainHandle;
 struct DMA_DESC *pSrcDesc = &pChain->arySrcDesc[pChain->nMoves];
 struct DMA_DESC *pDstDesc = &pChain->aryDstDesc[pChain->nMoves];
 if((pChain->nMoves == 4))
 {
  return -EINVALID_PARAMETER;
 }
 pChain->nMoves++;
 pDstDesc->config = 0x00000700 | 0x00004000 | 0x00000001 | 0x00000002;
 pDstDesc->config |= enDstWdSize;
 pDstDesc->startAddr = (unsigned long)pDstAddr;
 pDstDesc->xCount = dstXCount;
 pDstDesc->xModify = dstXModify;
 pDstDesc->yCount = dstYCount;
 pDstDesc->yModify = dstYModify;
 if(dstYCount > 1)
 {
  pDstDesc->config |= 0x00000010;
 }
 pSrcDesc->config = 0x00000700 | 0x00004000 | 0x00000001;
 pSrcDesc->config |= enSrcWdSize;
 pSrcDesc->startAddr = (unsigned long)pSrcAddr;
 pSrcDesc->xCount = srcXCount;
 pSrcDesc->xModify = srcXModify;
 pSrcDesc->yCount = srcYCount;
 pSrcDesc->yModify = srcYModify;
 if(srcYCount > 1)
 {
  pSrcDesc->config |= 0x00000010;
 }
 {};
 {};
 return SUCCESS;
}

variable_types:
pDstAddr
void *

variable_types: enum EnDmaWdSize { DMA_WDSIZE_8=0, DMA_WDSIZE_16=4, DMA_WDSIZE_32=8 }

variable_types:
dstXCount
unsigned short

variable_types: dstXModify int

variable_types:
dstYCount
unsigned short

variable_types: dstYModify int

variable_types:
pSrcAddr
void *

variable_types:
srcXCount
unsigned short

variable_types: srcXModify int

variable_types:
srcYCount
unsigned short

variable_types: srcYModify int

variable_types: struct DMA_DESC { unsigned long startAddr; unsigned short config; unsigned short xCount; short xModify; unsigned short yCount; short yModify; } *


original_code:
inline OSC_ERR OscDmaAdd1DMove(void *hChainHandle,
  const void *pDstAddr,
  const enum EnDmaWdSize enDstWdSize,
  const uint16 dstCount, const int32 dstModify,
  const void *pSrcAddr,
  const enum EnDmaWdSize enSrcWdSize,
  const uint16 srcCount, const int32 srcModify)
{
 return OscDmaAdd2DMove(hChainHandle,
   pDstAddr,
   enDstWdSize,
   dstCount, dstModify,
   1, 4,
   pSrcAddr,
   enSrcWdSize,
   srcCount, srcModify,
   1, 4);
}

canonical_original_code:
inline int OscDmaAdd1DMove(void *hChainHandle, void *pDstAddr, enum EnDmaWdSize enDstWdSize, unsigned short dstCount, int dstModify, void *pSrcAddr, enum EnDmaWdSize enSrcWdSize, unsigned short srcCount, int srcModify)
{
 return OscDmaAdd2DMove(hChainHandle,
   pDstAddr,
   enDstWdSize,
   dstCount, dstModify,
   1, 4,
   pSrcAddr,
   enSrcWdSize,
   srcCount, srcModify,
   1, 4);
}

variable_types:
dstCount
unsigned short

variable_types: dstModify int

variable_types:
srcCount
unsigned short

variable_types: srcModify int

user_defined_types: enum EnDmaWdSize { DMA_WDSIZE_8=0, DMA_WDSIZE_16=4, DMA_WDSIZE_32=8 }


OscDmaAddSyncPoint

original_code:
OSC_ERR OscDmaAddSyncPoint(void *hChainHandle)
{
 struct DMA_CHAIN *pChain = (struct DMA_CHAIN*)hChainHandle;
 struct DMA_DESC *pSrcDesc = &pChain->arySrcDesc[pChain->nMoves];
 struct DMA_DESC *pDstDesc = &pChain->aryDstDesc[pChain->nMoves];
 uintptr_t allOnesAddr = (uintptr_t)&allOnes;
 uintptr_t syncFlagAddr = (uintptr_t)&pChain->syncFlag;
 if((pChain->nMoves > 4))
 {
  return -EINVALID_PARAMETER;
 }
 pChain->nMoves++;
 pDstDesc->config = 0x00000001 | 0x00000002;
 if((pChain->nMoves > 1))
 {
  pDstDesc->config |=
   (pChain->aryDstDesc[pChain->nMoves - 2].config & 0x0000000C);
 } else {
  pDstDesc->config |= 0x00000008;
 }
 pDstDesc->startAddr = (uintptr_t)syncFlagAddr;
 pDstDesc->xCount = 1;
 pDstDesc->xModify = 4;
 pDstDesc->yCount = 1;
 pDstDesc->yModify = 4;
 pSrcDesc->config = 0x00000001;
 if((pChain->nMoves > 1))
 {
  pSrcDesc->config |=
   (pChain->arySrcDesc[pChain->nMoves - 2].config & 0x0000000C);
 } else {
  pSrcDesc->config |= 0x00000008;
 }
 pSrcDesc->startAddr = (uintptr_t)allOnesAddr;
 pSrcDesc->xCount = 1;
 pSrcDesc->xModify = 4;
 pSrcDesc->yCount = 1;
 pSrcDesc->yModify = 4;
 {};
 {};
 return SUCCESS;
}

canonical_original_code:
int OscDmaAddSyncPoint(void *hChainHandle)
{
 struct DMA_CHAIN *pChain = (struct DMA_CHAIN*)hChainHandle;
 struct DMA_DESC *pSrcDesc = &pChain->arySrcDesc[pChain->nMoves];
 struct DMA_DESC *pDstDesc = &pChain->aryDstDesc[pChain->nMoves];
 unsigned long allOnesAddr = (uintptr_t)&allOnes;
 unsigned long syncFlagAddr = (uintptr_t)&pChain->syncFlag;
 if((pChain->nMoves > 4))
 {
  return -EINVALID_PARAMETER;
 }
 pChain->nMoves++;
 pDstDesc->config = 0x00000001 | 0x00000002;
 if((pChain->nMoves > 1))
 {
  pDstDesc->config |=
   (pChain->aryDstDesc[pChain->nMoves - 2].config & 0x0000000C);
 } else {
  pDstDesc->config |= 0x00000008;
 }
 pDstDesc->startAddr = (unsigned long)syncFlagAddr;
 pDstDesc->xCount = 1;
 pDstDesc->xModify = 4;
 pDstDesc->yCount = 1;
 pDstDesc->yModify = 4;
 pSrcDesc->config = 0x00000001;
 if((pChain->nMoves > 1))
 {
  pSrcDesc->config |=
   (pChain->arySrcDesc[pChain->nMoves - 2].config & 0x0000000C);
 } else {
  pSrcDesc->config |= 0x00000008;
 }
 pSrcDesc->startAddr = (unsigned long)allOnesAddr;
 pSrcDesc->xCount = 1;
 pSrcDesc->xModify = 4;
 pSrcDesc->yCount = 1;
 pSrcDesc->yModify = 4;
 {};
 {};
 return SUCCESS;
}

variable_types:
hChainHandle
void *

variable_types: struct DMA_CHAIN { unsigned int syncFlag; unsigned int nMoves; struct DMA_DESC { unsigned long startAddr; unsigned short config; unsigned short xCount; short xModify; unsigned short yCount; short yModify; } arySrcDesc[-1]; struct DMA_DESC aryDstDesc[-1]; } *

variable_types:
allOnesAddr
unsigned long

variable_types:
syncFlagAddr
unsigned long