original_code:
int hash_table_contains(hash_table* hash, const void* data) {
    int i, j, contains;
    unsigned int hash_key;
    bucket* cur_Bucket;
    contains = 0;
    if(hash) {
        if(!hash_table_is_empty(hash)) {
            i = 0;
            j = 0;
            hash_key = hash->hash_alg(data) % hash->capacity;
            cur_Bucket = hash->bucket_list[hash_key];
            while(cur_Bucket && !contains && j < hash->capacity) {
                i++;
                j++;
                if(!hash->comp_func(cur_Bucket->data, data)) {
                    if(!cur_Bucket->removed) {
                        contains = 1;
                    } else {
                        j = hash->capacity;
                    }
                }
                if(i + hash_key == hash->capacity) {
                    i = -hash_key;
                }
                cur_Bucket = hash->bucket_list[hash_key + i];
            }
        }
    }
    return contains;
}

canonical_original_code:
int hash_table_contains(struct linear_hash_table *hash, void *data) {
    int i; int j; int contains;
    unsigned int hash_key;
    struct hash_table_bucket *cur_Bucket;
    contains = 0;
    if(hash) {
        if(!hash_table_is_empty(hash)) {
            i = 0;
            j = 0;
            hash_key = hash->hash_alg(data) % hash->capacity;
            cur_Bucket = hash->bucket_list[hash_key];
            while(cur_Bucket && !contains && j < hash->capacity) {
                i++;
                j++;
                if(!hash->comp_func(cur_Bucket->data, data)) {
                    if(!cur_Bucket->removed) {
                        contains = 1;
                    } else {
                        j = hash->capacity;
                    }
                }
                if(i + hash_key == hash->capacity) {
                    i = -hash_key;
                }
                cur_Bucket = hash->bucket_list[hash_key + i];
            }
        }
    }
    return contains;
}

variable_types: contains int


repo: tbullard/npuzzle

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

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

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

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

original_code:
size_t hash_table_size(hash_table* hash) {
    size_t size;
    size = 0;
    if(hash) {
        size = hash->size;
    }
    return size;
}

canonical_original_code:
unsigned long hash_table_size(struct linear_hash_table *hash) {
    unsigned long size;
    size = 0;
    if(hash) {
        size = hash->size;
    }
    return size;
}

variable_types: struct linear_hash_table { struct hash_table_bucket { void *data; unsigned int hash_key; char removed; } **bucket_list; unsigned long size; unsigned long capacity; float cur_load_factor; float load_factor_limit; unsigned int (*hash_alg)(void *); int (*comp_func)(void *, void *); void *(*copy_func)(void *); void (*free_func)(void *); } *

variable_types:
size
unsigned long

return_type: unsigned long

user_defined_types: struct linear_hash_table { struct hash_table_bucket **bucket_list; unsigned long size; unsigned long capacity; float cur_load_factor; float load_factor_limit; unsigned int (*hash_alg)(void *); int (*comp_func)(void *, void *); void *(*copy_func)(void *); void (*free_func)(void *); }


original_code:
void hash_table_empty(hash_table* hash) {
    int i;
    bucket* cur_Bucket;
    if(hash) {
        hash->size = 0;
        for(i = 0; i < hash->capacity; i++) {
            cur_Bucket = hash->bucket_list[i];
            if(cur_Bucket) {
                hash->bucket_list[i] = ((void *)0);
                hash->free_func(cur_Bucket->data);
                free(cur_Bucket);
            }
        }
    }
    return;
}

canonical_original_code:
void hash_table_empty(struct linear_hash_table *hash) {
    int i;
    struct hash_table_bucket *cur_Bucket;
    if(hash) {
        hash->size = 0;
        for(i = 0; i < hash->capacity; i++) {
            cur_Bucket = hash->bucket_list[i];
            if(cur_Bucket) {
                hash->bucket_list[i] = ((void *)0);
                hash->free_func(cur_Bucket->data);
                free(cur_Bucket);
            }
        }
    }
    return;
}

variable_types: i int

variable_types: struct hash_table_bucket { void *data; unsigned int hash_key; char removed; } *

return_type: void


decompiled_code:
void __fastcall hash_table_kill(void *ptr)
{
if ( ptr )
{
hash_table_empty((__int64)ptr);
free(*(void **)ptr);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func6(void *ptr)
{
if ( ptr )
{
func5((__int64)ptr);
free(*(void **)ptr);
free(ptr);
}
}

original_code:
void hash_table_kill(hash_table* hash) {
    if(hash) {
        hash_table_empty(hash);
        free(hash->bucket_list);
        free(hash);
    }
    return;
}

canonical_original_code:
void hash_table_kill(struct linear_hash_table *hash) {
    if(hash) {
        hash_table_empty(hash);
        free(hash->bucket_list);
        free(hash);
    }
    return;
}

user_defined_types: struct hash_table_bucket { void *data; unsigned int hash_key; char removed; }


decompiled_code:
void __fastcall hash_table_dissolve(void *ptr)
{
char *v2; // r8
unsigned __int64 v3; // rbx
void **v4; // rax
void *v5; // rdi

if ( ptr )
{
v2 = *(char **)ptr;
if ( *((_QWORD *)ptr + 2) )
{
v3 = 0LL;
do
{
v4 = (void **)&v2[8 * v3];
v5 = *v4;
if ( *v4 )
{
*v4 = 0LL;
free(v5);
v2 = *(char **)ptr;
}
++v3;
}
while ( *((_QWORD *)ptr + 2) > v3 );
}
free(v2);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func7(void *ptr)
{
char *v2; // r8
unsigned __int64 v3; // rbx
void **v4; // rax
void *v5; // rdi

if ( ptr )
{
v2 = *(char **)ptr;
if ( *((_QWORD *)ptr + 2) )
{
v3 = 0LL;
do
{
v4 = (void **)&v2[8 * v3];
v5 = *v4;
if ( *v4 )
{
*v4 = 0LL;
free(v5);
v2 = *(char **)ptr;
}
++v3;
}
while ( *((_QWORD *)ptr + 2) > v3 );
}
free(v2);
free(ptr);
}
}

original_code:
void hash_table_dissolve(hash_table* hash) {
    int i;
    bucket* cur_Bucket;
    if(hash) {
        for(i = 0; i < hash->capacity; i++) {
            cur_Bucket = hash->bucket_list[i];
            if(cur_Bucket) {
                hash->bucket_list[i] = ((void *)0);
                free(cur_Bucket);
            }
        }
        free(hash->bucket_list);
        free(hash);
    }
    return;
}

canonical_original_code:
void hash_table_dissolve(struct linear_hash_table *hash) {
    int i;
    struct hash_table_bucket *cur_Bucket;
    if(hash) {
        for(i = 0; i < hash->capacity; i++) {
            cur_Bucket = hash->bucket_list[i];
            if(cur_Bucket) {
                hash->bucket_list[i] = ((void *)0);
                free(cur_Bucket);
            }
        }
        free(hash->bucket_list);
        free(hash);
    }
    return;
}


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

if ( a1 && !hash_table_is_empty((__int64)a1) && a1[2] )
{
v2 = 0LL;
do
{
v3 = *(_QWORD *)(*a1 + 8 * v2);
if ( v3 )
{
if ( !*(_BYTE *)(v3 + 12) )
a2(*(_QWORD *)v3);
}
++v2;
}
while ( a1[2] > v2 );
}
}

original_code:
void hash_table_traverse(hash_table* hash, generic_op do_func) {
    int i;
    bucket* cur_Bucket;
    if(hash) {
        if(!hash_table_is_empty(hash)) {
            for(i = 0; i < hash->capacity; i++) {
                cur_Bucket = hash->bucket_list[i];
                if(cur_Bucket) {
                    if(!cur_Bucket->removed) {
                        do_func(cur_Bucket->data);
                    }
                }
            }
        }
    }
    return;
}

canonical_original_code:
void hash_table_traverse(struct linear_hash_table *hash, void (*do_func)(void *)) {
    int i;
    struct hash_table_bucket *cur_Bucket;
    if(hash) {
        if(!hash_table_is_empty(hash)) {
            for(i = 0; i < hash->capacity; i++) {
                cur_Bucket = hash->bucket_list[i];
                if(cur_Bucket) {
                    if(!cur_Bucket->removed) {
                        do_func(cur_Bucket->data);
                    }
                }
            }
        }
    }
    return;
}


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

result = 0LL;
if ( a1 && a2 >= 0 && *(_DWORD *)(a1 + 24) >= a2 )
result = *(_QWORD *)(*(_QWORD *)a1 + 8LL * a2);
return result;
}

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

result = 0LL;
if ( a1 && a2 >= 0 && *(_DWORD *)(a1 + 24) >= a2 )
result = *(_QWORD *)(*(_QWORD *)a1 + 8LL * a2);
return result;
}

original_code:
void* array_list_get(array_list* array, int index) {
    void* data;
    data = ((void *)0);
    if(array) {
        if (index >= 0 && index <= array->index) {
            data = array->memory[index];
        }
    }
    return data;
}

canonical_original_code:
void *array_list_get(struct dynamic_array *array, int index) {
    void *data;
    data = ((void *)0);
    if(array) {
        if (index >= 0 && index <= array->index) {
            data = array->memory[index];
        }
    }
    return data;
}

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:
data
void *

return_type: void *


original_code:
int array_list_push(array_list* array, void* data) {
    int pushed;
    size_t toallocate;
    size_t size;
    size = sizeof(void*);
    pushed = 0;
    if(array) {
        pushed = 1;
        if ((array->allocated - array->used) < size) {
            toallocate = (array->allocated == 0) ? size :
                         (array->allocated * 2);
            array->memory = realloc(array->memory, toallocate);
            array->allocated = toallocate;
        }
        array->memory[++array->index] = data;
        array->used += size;
    }
    return pushed;
}

canonical_original_code:
int array_list_push(struct dynamic_array *array, void *data) {
    int pushed;
    unsigned long toallocate;
    unsigned long size;
    size = sizeof(void *);
    pushed = 0;
    if(array) {
        pushed = 1;
        if ((array->allocated - array->used) < size) {
            toallocate = (array->allocated == 0) ? size :
                         (array->allocated * 2);
            array->memory = realloc(array->memory, toallocate);
            array->allocated = toallocate;
        }
        array->memory[++array->index] = data;
        array->used += size;
    }
    return pushed;
}

variable_types: pushed int

variable_types:
toallocate
unsigned long

return_type: 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_insert(__int64 a1, int a2, __int64 a3)
{
__int64 result; // rax

result = 0LL;
if ( a1 && a2 >= 0 && *(_DWORD *)(a1 + 24) >= a2 )
{
*(_QWORD *)(*(_QWORD *)a1 + 8LL * a2) = a3;
result = 1LL;
}
return result;
}

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

result = 0LL;
if ( a1 && a2 >= 0 && *(_DWORD *)(a1 + 24) >= a2 )
{
*(_QWORD *)(*(_QWORD *)a1 + 8LL * a2) = a3;
result = 1LL;
}
return result;
}

original_code:
int array_list_insert(array_list* array, int index, void* data) {
    int inserted;
    inserted = 0;
    if(array) {
        if (index >= 0 && index <= array->index) {
            inserted = 1;
            array->memory[index] = data;
        }
    }
    return inserted;
}

canonical_original_code:
int array_list_insert(struct dynamic_array *array, int index, void *data) {
    int inserted;
    inserted = 0;
    if(array) {
        if (index >= 0 && index <= array->index) {
            inserted = 1;
            array->memory[index] = data;
        }
    }
    return inserted;
}

variable_types: inserted int


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

variable_types: removed int


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


decompiled_code:
__int64 __fastcall array_list_swap(__int64 a1, int a2, int a3)
{
int v3; // er8
__int64 result; // rax
int v5; // er8
__int64 v6; // r9

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

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, int a2, int a3)
{
int v3; // er8
__int64 result; // rax
int v5; // er8
__int64 v6; // r9

v3 = a3;
result = 0LL;
if ( a1 )
{
if ( a2 < 0 || a3 < 0 )
{
result = 0LL;
}
else
{
if ( a2 >= a3 )
a3 = a2;
if ( *(_DWORD *)(a1 + 24) >= a3 )
{
func2(a1, a2, *(_QWORD *)(*(_QWORD *)a1 + 8LL * v3));
func2(a1, v5, v6);
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


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


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

v2 = 0;
if ( a1 )
{
v3 = array_list_length((__int64)a1);
for ( i = 0LL; i < v3; ++i )
{
if ( *(_QWORD *)(*a1 + 8 * i) )
{
if ( a2() )
{
++v2;
array_list_remove((__int64)a1, i);
}
v3 = array_list_length((__int64)a1);
}
}
}
return v2;
}

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

v2 = 0;
if ( a1 )
{
v3 = func7((__int64)a1);
for ( i = 0LL; i < v3; ++i )
{
if ( *(_QWORD *)(*a1 + 8 * i) )
{
if ( a2() )
{
++v2;
func4((__int64)a1, i);
}
v3 = func7((__int64)a1);
}
}
}
return v2;
}

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: count int


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

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

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 a2)
{
unsigned __int64 v2; // rbx
unsigned __int64 v3; // rax

if ( !a1 )
return 0LL;
v2 = 0LL;
v3 = func7(a1);
while ( v2 < v3 )
{
if ( *(_QWORD *)(*(_QWORD *)a1 + 8 * v2) )
{
if ( !(*(unsigned int (__fastcall **)(__int64))(a1 + 32))(a2) )
return 1LL;
v3 = func7(a1);
}
++v2;
}
return 0LL;
}

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


decompiled_code:
void __fastcall array_list_empty(__int64 a1)
{
unsigned __int64 i; // rbx

if ( a1 )
{
for ( i = 0LL; array_list_length(a1) > i; ++i )
{
(*(void (__fastcall **)(_QWORD))(a1 + 48))(*(_QWORD *)(*(_QWORD *)a1 + 8 * i));
*(_QWORD *)(*(_QWORD *)a1 + 8 * i) = 0LL;
}
*(_QWORD *)(a1 + 16) = 0LL;
*(_DWORD *)(a1 + 24) = -1;
}
}

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


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 v2; // rax
unsigned __int64 v3; // rdx
_QWORD *v4; // rdi

if ( ptr )
{
while ( 1 )
{
v2 = array_list_length((__int64)ptr);
v4 = *(_QWORD **)ptr;
if ( v2 <= v3 )
break;
v4[v3] = 0LL;
}
free(v4);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func12(void *ptr)
{
unsigned __int64 v2; // rax
unsigned __int64 v3; // rdx
_QWORD *v4; // rdi

if ( ptr )
{
while ( 1 )
{
v2 = func7((__int64)ptr);
v4 = *(_QWORD **)ptr;
if ( v2 <= v3 )
break;
v4[v3] = 0LL;
}
free(v4);
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
unsigned __int64 v3; // rax

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

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

if ( a1 )
{
v2 = 0LL;
v3 = func7((__int64)a1);
while ( v2 < v3 )
{
if ( *(_QWORD *)(*a1 + 8 * v2) )
{
a2();
v3 = func7((__int64)a1);
}
++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; // r12

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

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

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:
int __fastcall esl_thread_create_detached_ex(__int64 a1, __int64 a2, __int64 a3)
{
char *v4; // rax
_QWORD *v5; // rbp
pthread_attr_t *v6; // r12
int result; // eax
size_t v8; // rsi

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

canonical_decompiled_code:
int __fastcall func2(__int64 a1, __int64 a2, __int64 a3)
{
char *v4; // rax
_QWORD *v5; // rbp
pthread_attr_t *v6; // r12
int result; // eax
size_t v8; // rsi

if ( !a1 )
return 1;
v4 = (char *)malloc(0x58uLL);
v5 = v4;
if ( !v4 )
return 1;
*((_QWORD *)v4 + 3) = a3;
v6 = (pthread_attr_t *)(v4 + 32);
*((_QWORD *)v4 + 1) = a2;
*((_QWORD *)v4 + 2) = a1;
if ( pthread_attr_init((pthread_attr_t *)(v4 + 32)) )
{
LABEL_4:
free(v5);
return 1;
}
if ( pthread_attr_setdetachstate(v6, 1)
|| (v8 = v5[3]) != 0 && pthread_attr_setstacksize(v6, v8)
|| (result = pthread_create(v5, v6, (void *(*)(void *))thread_launch, v5)) != 0 )
{
pthread_attr_destroy(v6);
goto LABEL_4;
}
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:
int __fastcall esl_thread_create_detached(__int64 a1, __int64 a2)
{
return esl_thread_create_detached_ex(a1, a2, thread_default_stacksize);
}

canonical_decompiled_code:
int __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; // rbp
int result; // eax
pthread_mutexattr_t attr; // [rsp+Ch] [rbp-1Ch] BYREF

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

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

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

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

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

canonical_decompiled_code:
__int64 __fastcall func5(pthread_mutex_t **a1)
{
pthread_mutex_t *v1; // rbp

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

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


decompiled_code:
__int64 __fastcall esl_buffer_create(_QWORD *a1, __int64 a2, size_t a3, __int64 a4)
{
_QWORD *v6; // rax
_QWORD *v7; // rbp
void *v8; // rax
int v9; // edx
__int64 result; // rax

v6 = calloc(0x40uLL, 1uLL);
if ( !v6 )
return 1LL;
v7 = v6;
v8 = 0LL;
if ( !a3 || (v8 = calloc(a3, 1uLL), (*v7 = v8) != 0LL) )
{
v9 = buffer_id;
v7[5] = a4;
v7[4] = a3;
*((_DWORD *)v7 + 14) = v9;
buffer_id = v9 + 1;
v7[6] = a2;
*a1 = v7;
v7[1] = v8;
result = 0LL;
}
else
{
free(v7);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1, __int64 a2, size_t a3, __int64 a4)
{
_QWORD *v6; // rax
_QWORD *v7; // rbp
void *v8; // rax
int v9; // edx
__int64 result; // rax

v6 = calloc(0x40uLL, 1uLL);
if ( !v6 )
return 1LL;
v7 = v6;
v8 = 0LL;
if ( !a3 || (v8 = calloc(a3, 1uLL), (*v7 = v8) != 0LL) )
{
v9 = buffer_id;
v7[5] = a4;
v7[4] = a3;
*((_DWORD *)v7 + 14) = v9;
buffer_id = v9 + 1;
v7[6] = a2;
*a1 = v7;
v7[1] = v8;
result = 0LL;
}
else
{
free(v7);
result = 1LL;
}
return result;
}

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] = result + *a1;
}
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] = result + *a1;
}
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);
*(_QWORD *)(a1 + 8) += a2;
result -= a2;
*(_QWORD *)(a1 + 16) = result;
}
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);
*(_QWORD *)(a1 + 8) += a2;
result -= a2;
*(_QWORD *)(a1 + 16) = result;
}
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; // r12

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

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

variable_types:
data
void *


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


decompiled_code:
__int64 __fastcall esl_buffer_packet_count(__int64 a1)
{
char *v1; // rax
unsigned __int64 v2; // rdi
char v3; // si
__int64 v4; // r8
char v5; // cl
_BYTE *v6; // rdx
_BYTE *v7; // rax

v1 = *(char **)(a1 + 8);
v2 = (unsigned __int64)&v1[*(_QWORD *)(a1 + 16)];
if ( !v1 )
return 0LL;
v3 = *v1;
v4 = 0LL;
if ( *v1 && (unsigned __int64)v1 < v2 )
{
while ( 1 )
{
v5 = v1[1];
v6 = v1 + 1;
if ( v3 != 10 )
goto LABEL_5;
v7 = v1 + 2;
if ( v5 != 13 )
v7 = v6;
if ( (unsigned __int64)v7 <= v2 && *v7 == 10 )
{
v6 = v7 + 1;
v5 = v7[1];
++v4;
if ( v2 <= (unsigned __int64)(v7 + 1) )
return v4;
}
else
{
LABEL_5:
if ( v2 <= (unsigned __int64)v6 )
return v4;
}
if ( !v5 )
return v4;
v1 = v6;
v3 = v5;
}
}
return v4;
}

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 *v5; // rsi
char v7; // dl
unsigned __int64 v8; // rax
char v9; // cl
char *v10; // rcx
size_t v11; // rdx
size_t v12; // rcx

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

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:
maxlen
unsigned long


decompiled_code:
size_t __fastcall esl_buffer_write(__int64 a1, const void *a2, size_t a3)
{
void *v4; // rdi
size_t result; // rax
__int64 v7; // rdx
size_t v8; // rcx
__int64 v9; // rax
size_t v10; // r12
size_t v11; // rdx
void *v12; // rax

if ( !a1 )
_assert_fail("buffer != ((void *)0)", "esl_buffer.c", 0xFDu, "esl_buffer_write");
if ( !a2 )
_assert_fail("data != ((void *)0)", "esl_buffer.c", 0xFEu, "esl_buffer_write");
v4 = *(void **)a1;
if ( !v4 )
_assert_fail("buffer->data != ((void *)0)", "esl_buffer.c", 0xFFu, "esl_buffer_write");
result = *(_QWORD *)(a1 + 16);
if ( a3 )
{
v7 = *(_QWORD *)(a1 + 32);
if ( a3 > v7 - *(_QWORD *)(a1 + 24) )
{
v8 = *(_QWORD *)(a1 + 40);
if ( !v8 || v8 >= a3 + result )
{
memmove(v4, *(const void **)(a1 + 8), *(_QWORD *)(a1 + 16));
v4 = *(void **)a1;
result = *(_QWORD *)(a1 + 16);
v7 = *(_QWORD *)(a1 + 32);
*(_QWORD *)(a1 + 8) = *(_QWORD *)a1;
*(_QWORD *)(a1 + 24) = result;
}
}
if ( a3 <= v7 - result )
goto LABEL_10;
v10 = a3 + v7;
v11 = *(_QWORD *)(a1 + 48) + v7;
*(_QWORD *)(a1 + 8) = v4;
if ( v11 >= v10 )
v10 = v11;
v12 = realloc(v4, v10);
if ( v12
&& (*(_QWORD *)a1 = v12,
*(_QWORD *)(a1 + 8) = v12,
result = *(_QWORD *)(a1 + 16),
*(_QWORD *)(a1 + 32) = v10,
a3 <= v10 - result) )
{
LABEL_10:
memcpy((void *)(*(_QWORD *)(a1 + 8) + result), a2, a3);
v9 = *(_QWORD *)(a1 + 16);
*(_QWORD *)(a1 + 24) += a3;
result = a3 + v9;
*(_QWORD *)(a1 + 16) = result;
}
else
{
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
size_t __fastcall func11(__int64 a1, const void *a2, size_t a3)
{
void *v4; // rdi
size_t result; // rax
__int64 v7; // rdx
size_t v8; // rcx
__int64 v9; // rax
size_t v10; // r12
size_t v11; // rdx
void *v12; // rax

if ( !a1 )
_assert_fail("buffer != ((void *)0)", "esl_buffer.c", 0xFDu, "esl_buffer_write");
if ( !a2 )
_assert_fail("data != ((void *)0)", "esl_buffer.c", 0xFEu, "esl_buffer_write");
v4 = *(void **)a1;
if ( !v4 )
_assert_fail("buffer->data != ((void *)0)", "esl_buffer.c", 0xFFu, "esl_buffer_write");
result = *(_QWORD *)(a1 + 16);
if ( a3 )
{
v7 = *(_QWORD *)(a1 + 32);
if ( a3 > v7 - *(_QWORD *)(a1 + 24) )
{
v8 = *(_QWORD *)(a1 + 40);
if ( !v8 || v8 >= a3 + result )
{
memmove(v4, *(const void **)(a1 + 8), *(_QWORD *)(a1 + 16));
v4 = *(void **)a1;
result = *(_QWORD *)(a1 + 16);
v7 = *(_QWORD *)(a1 + 32);
*(_QWORD *)(a1 + 8) = *(_QWORD *)a1;
*(_QWORD *)(a1 + 24) = result;
}
}
if ( a3 <= v7 - result )
goto LABEL_10;
v10 = a3 + v7;
v11 = *(_QWORD *)(a1 + 48) + v7;
*(_QWORD *)(a1 + 8) = v4;
if ( v11 >= v10 )
v10 = v11;
v12 = realloc(v4, v10);
if ( v12
&& (*(_QWORD *)a1 = v12,
*(_QWORD *)(a1 + 8) = v12,
result = *(_QWORD *)(a1 + 16),
*(_QWORD *)(a1 + 32) = v10,
a3 <= v10 - result) )
{
LABEL_10:
memcpy((void *)(*(_QWORD *)(a1 + 8) + result), a2, a3);
v9 = *(_QWORD *)(a1 + 16);
*(_QWORD *)(a1 + 24) += a3;
result = a3 + v9;
*(_QWORD *)(a1 + 16) = result;
}
else
{
result = 0LL;
}
}
return result;
}

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 )
{
*a2 = 0;
v3 = v2 + 1;
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;
while ( 1 )
{
while ( v5 == 49 )
{
v5 = v6[1];
*a2 |= v7;
++v6;
v7 >>= 1;
if ( !v5 )
goto LABEL_9;
}
if ( v5 != 48 )
break;
v5 = *++v6;
v7 >>= 1;
if ( !v5 )
goto LABEL_9;
}
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);
result = 0xFFFFFFFFLL;
}
else
{
LABEL_9:
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 )
{
*a2 = 0;
v3 = v2 + 1;
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;
while ( 1 )
{
while ( v5 == 49 )
{
v5 = v6[1];
*a2 |= v7;
++v6;
v7 >>= 1;
if ( !v5 )
goto LABEL_9;
}
if ( v5 != 48 )
break;
v5 = *++v6;
v7 >>= 1;
if ( !v5 )
goto LABEL_9;
}
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);
result = 0xFFFFFFFFLL;
}
else
{
LABEL_9:
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; // er12
unsigned int v7; // eax
unsigned int v8; // er12
unsigned int v9; // eax
unsigned int v10; // er12
int v12[13]; // [rsp+4h] [rbp-34h] BYREF

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

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

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

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

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int8 a1, __int64 a2, unsigned int a3, unsigned int a4)
{
unsigned int v5; // er12
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 )
{
v5 = -8;
OscLog(3LL, "%s(%d, 0x%x, %u, %u): Invalid parameter!\n", "OscIpcSetParam", a1, a2, a3, a4);
return v5;
}
if ( (ipc[268 * a1 + 260] & 2) != 0 )
{
OscLog(3LL, "%s: Only works in blocking mode!\n", "OscIpcSetParam");
return (unsigned int)-902;
}
v5 = OscIpcSendMsg(a1, v7);
if ( v5 )
return v5;
v5 = OscIpcSend(a1, a2, a4);
if ( v5 )
return v5;
while ( (unsigned int)OscIpcRecvMsg(a1, v7) == -901 )
;
if ( v7[0] != 3 )
v5 = -903;
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; // er12
__int64 result; // rax
unsigned int v4; // er14
unsigned int *v5; // rax
unsigned int *v6; // rbp
int v7; // eax
unsigned int v8; // eax
int v9; // eax
int v10; // [rsp+4h] [rbp-34h] BYREF
int v11; // [rsp+8h] [rbp-30h]
unsigned int v12; // [rsp+Ch] [rbp-2Ch]

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

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

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

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, int *a2, unsigned __int8 a3)
{
int v3; // eax
__int64 v4; // r13
int v5; // eax
unsigned int v6; // eax
unsigned int v7; // er12
int v9[13]; // [rsp+4h] [rbp-34h] BYREF

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

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

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

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; // r12
__int64 result; // rax
__int64 v6; // r12
__int64 v7; // r12

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);
}
}
else if ( a2 == 4 )
{
result = v4;
++*(_WORD *)(a1 + 32);
return result;
}
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);
result = huffman(a1, 3LL, v6, &Temp);
++*(_WORD *)(a1 + 32);
return result;
}

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

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);
}
}
else if ( a2 == 4 )
{
result = v4;
++*(_WORD *)(a1 + 32);
return result;
}
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);
result = huffman(a1, 3LL, v6, &Temp);
++*(_WORD *)(a1 + 32);
return result;
}

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 *