decompiled_code:
void *__fastcall ds_vector_maybe_expand(__int64 a1)
{
void *result; // rax
float v2; // xmm0_4

result = (void *)*(unsigned int *)(a1 + 4);
if ( *(_DWORD *)a1 >= (int)result )
{
v2 = (float)(int)result * 1.5;
*(_DWORD *)(a1 + 4) = (int)v2;
result = realloc(*(void **)(a1 + 8), 8LL * (int)v2);
*(_QWORD *)(a1 + 8) = result;
if ( !result )
_assert_fail("vec->data", "vector.c", 0xE7u, "ds_vector_maybe_expand");
}
return result;
}

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

result = (void *)*(unsigned int *)(a1 + 4);
if ( *(_DWORD *)a1 >= (int)result )
{
v2 = (float)(int)result * 1.5;
*(_DWORD *)(a1 + 4) = (int)v2;
result = realloc(*(void **)(a1 + 8), 8LL * (int)v2);
*(_QWORD *)(a1 + 8) = result;
if ( !result )
_assert_fail("vec->data", "vector.c", 0xE7u, "ds_vector_maybe_expand");
}
return result;
}

original_code:
static void
ds_vector_maybe_expand(struct DSVector *vec)
{
    if (vec->size < vec->capacity)
        return;
    vec->capacity *= DS_VECTOR_EXPAND_RATIO;
    vec->data = realloc(vec->data, vec->capacity * sizeof(vec->data));
    ((vec->data) ? (void) (0) : __assert_fail ("vec->data", "vector.c", 231, __extension__ __PRETTY_FUNCTION__));
}

variable_types: struct DSVector { int size; int capacity; void **data; } *


repo: BergerLab/CAST

decompiled_code:
_DWORD *ds_vector_create()
{
return ds_vector_create_capacity(10);
}

canonical_decompiled_code:
_DWORD *func3()
{
return ds_vector_create_capacity(10);
}

original_code:
struct DSVector *
ds_vector_create()
{
    return ds_vector_create_capacity(DS_VECTOR_BASE_CAPACITY);
}

canonical_original_code:
struct DSVector *ds_vector_create()
{
    return ds_vector_create_capacity(DS_VECTOR_BASE_CAPACITY);
}

return_type: struct DSVector { int size; int capacity; void **data; } *


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

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

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

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

original_code:
void
ds_vector_free(struct DSVector *vec)
{
    int32_t i;
    for (i = 0; i < vec->size; ++i)
        free(vec->data[i]);
    free(vec->data);
    free(vec);
}

canonical_original_code:
void ds_vector_free(struct DSVector *vec)
{
    int i;
    for (i = 0; i < vec->size; ++i)
        free(vec->data[i]);
    free(vec->data);
    free(vec);
}

variable_types: i int

return_type: void

user_defined_types: struct DSVector { int size; int capacity; void **data; }


decompiled_code:
void __fastcall ds_vector_free_no_data(void *ptr)
{
free(*((void **)ptr + 1));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func5(void *ptr)
{
free(*((void **)ptr + 1));
free(ptr);
}

original_code:
void
ds_vector_free_no_data(struct DSVector *vec)
{
    free(vec->data);
    free(vec);
}


decompiled_code:
__int64 __fastcall ds_vector_append(int *a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // rdx

ds_vector_maybe_expand((__int64)a1);
result = *a1;
v3 = *((_QWORD *)a1 + 1);
*a1 = result + 1;
*(_QWORD *)(v3 + 8 * result) = a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(int *a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // rdx

func2((__int64)a1);
result = *a1;
v3 = *((_QWORD *)a1 + 1);
*a1 = result + 1;
*(_QWORD *)(v3 + 8 * result) = a2;
return result;
}

original_code:
void
ds_vector_append(struct DSVector *vec, void* data)
{
    ds_vector_maybe_expand(vec);
    vec->data[vec->size++] = data;
}

canonical_original_code:
void ds_vector_append(struct DSVector *vec, void *data)
{
    ds_vector_maybe_expand(vec);
    vec->data[vec->size++] = data;
}

variable_types:
data
void *


original_code:
void
ds_vector_insert(struct DSVector *vec, void* data, int32_t index)
{
    int32_t i;
    if (index > vec->size)
        return;
    ds_vector_maybe_expand(vec);
    for (i = vec->size - 1; i >= index && i < (i + 1); --i)
        vec->data[i + 1] = vec->data[i];
    vec->data[index] = data;
    ++vec->size;
}

canonical_original_code:
void ds_vector_insert(struct DSVector *vec, void *data, int index)
{
    int i;
    if (index > vec->size)
        return;
    ds_vector_maybe_expand(vec);
    for (i = vec->size - 1; i >= index && i < (i + 1); --i)
        vec->data[i + 1] = vec->data[i];
    vec->data[index] = data;
    ++vec->size;
}

variable_types: index int


original_code:
void
ds_vector_remove(struct DSVector *vec, int32_t index)
{
    int32_t i;
    if (index >= vec->size)
        return;
    --vec->size;
    for (i = index; i < vec->size; ++i)
        vec->data[i] = vec->data[i + 1];
}

canonical_original_code:
void ds_vector_remove(struct DSVector *vec, int index)
{
    int i;
    if (index >= vec->size)
        return;
    --vec->size;
    for (i = index; i < vec->size; ++i)
        vec->data[i] = vec->data[i + 1];
}


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

if ( *(_DWORD *)a1 <= a2 )
result = 0LL;
else
result = *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * a2);
return result;
}

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

if ( *(_DWORD *)a1 <= a2 )
result = 0LL;
else
result = *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * a2);
return result;
}

original_code:
void *
ds_vector_get(struct DSVector *vec, int32_t index)
{
    if (index >= vec->size)
        return ((void *)0);
    return vec->data[index];
}

canonical_original_code:
void *ds_vector_get(struct DSVector *vec, int index)
{
    if (index >= vec->size)
        return ((void *)0);
    return vec->data[index];
}

return_type: void *


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

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

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

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

original_code:
void
ds_vector_set(struct DSVector *vec, void* data, int32_t index)
{
    if (index >= vec->size)
        return;
    vec->data[index] = data;
}

canonical_original_code:
void ds_vector_set(struct DSVector *vec, void *data, int index)
{
    if (index >= vec->size)
        return;
    vec->data[index] = data;
}


decompiled_code:
__int64 __fastcall ds_vector_swap(__int64 a1, unsigned int a2, unsigned int a3)
{
__int64 result; // rax
__int64 v4; // rcx
__int64 *v5; // rax
__int64 v6; // rsi

result = a3;
if ( (int)a2 >= (int)a3 )
result = a2;
if ( *(_DWORD *)a1 > (int)result )
{
v4 = *(_QWORD *)(a1 + 8);
v5 = (__int64 *)(v4 + 8LL * (int)a2);
v6 = *v5;
*v5 = *(_QWORD *)(v4 + 8LL * (int)a3);
result = *(_QWORD *)(a1 + 8);
*(_QWORD *)(result + 8LL * (int)a3) = v6;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, unsigned int a2, unsigned int a3)
{
__int64 result; // rax
__int64 v4; // rcx
__int64 *v5; // rax
__int64 v6; // rsi

result = a3;
if ( (int)a2 >= (int)a3 )
result = a2;
if ( *(_DWORD *)a1 > (int)result )
{
v4 = *(_QWORD *)(a1 + 8);
v5 = (__int64 *)(v4 + 8LL * (int)a2);
v6 = *v5;
*v5 = *(_QWORD *)(v4 + 8LL * (int)a3);
result = *(_QWORD *)(a1 + 8);
*(_QWORD *)(result + 8LL * (int)a3) = v6;
}
return result;
}

original_code:
void
ds_vector_swap(struct DSVector *vec, int32_t i, int32_t j)
{
    void *temp;
    if (i >= vec->size || j >= vec->size)
        return;
    temp = vec->data[i];
    vec->data[i] = vec->data[j];
    vec->data[j] = temp;
}

canonical_original_code:
void ds_vector_swap(struct DSVector *vec, int i, int j)
{
    void *temp;
    if (i >= vec->size || j >= vec->size)
        return;
    temp = vec->data[i];
    vec->data[i] = vec->data[j];
    vec->data[j] = temp;
}

variable_types: j int

variable_types:
temp
void *


decompiled_code:
void __fastcall ds_queue_free(void *ptr)
{
unsigned int v1; // eax
unsigned int v2; // eax

v1 = pthread_mutex_destroy((pthread_mutex_t *)((char *)ptr + 24));
if ( v1 )
{
fprintf(stderr, "Could not destroy mutex. Errno: %d\n", v1);
goto LABEL_5;
}
v2 = pthread_cond_destroy((pthread_cond_t *)((char *)ptr + 64));
if ( v2 )
{
fprintf(stderr, "Could not destroy cond var. Errno: %d\n", v2);
LABEL_5:
exit(1);
}
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
unsigned int v1; // eax
unsigned int v2; // eax

v1 = pthread_mutex_destroy((pthread_mutex_t *)((char *)ptr + 24));
if ( v1 )
{
fprintf(stderr, "Could not destroy mutex. Errno: %d\n", v1);
goto LABEL_5;
}
v2 = pthread_cond_destroy((pthread_cond_t *)((char *)ptr + 64));
if ( v2 )
{
fprintf(stderr, "Could not destroy cond var. Errno: %d\n", v2);
LABEL_5:
exit(1);
}
free(*(void **)ptr);
free(ptr);
}

original_code:
void
ds_queue_free(struct DSQueue *queue)
{
    int errno;
    if (0 != (errno = pthread_mutex_destroy(&queue->mutate))) {
        fprintf(stderr, "Could not destroy mutex. Errno: %d\n", errno);
        exit(1);
    }
    if (0 != (errno = pthread_cond_destroy(&queue->cond_length))) {
        fprintf(stderr, "Could not destroy cond var. Errno: %d\n", errno);
        exit(1);
    }
    free(queue->buf);
    free(queue);
}

variable_types: struct DSQueue { void **buf; unsigned int pos; unsigned int length; unsigned int capacity; _Bool closed; 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; } mutate; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } cond_length; } *

variable_types: errno int

user_defined_types: struct DSQueue { void **buf; unsigned int pos; unsigned int length; unsigned int capacity; _Bool closed; union pthread_mutex_t mutate; union pthread_cond_t cond_length; }

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

user_defined_types: union pthread_cond_t { struct __pthread_cond_s __data; char __size[48]; long 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 ds_queue_length(__int64 a1)
{
unsigned int v1; // er12

pthread_mutex_lock((pthread_mutex_t *)(a1 + 24));
v1 = *(_DWORD *)(a1 + 12);
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 24));
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
unsigned int v1; // er12

pthread_mutex_lock((pthread_mutex_t *)(a1 + 24));
v1 = *(_DWORD *)(a1 + 12);
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 24));
return v1;
}

original_code:
int
ds_queue_length(struct DSQueue *queue)
{
    int len;
    pthread_mutex_lock(&queue->mutate);
    len = queue->length;
    pthread_mutex_unlock(&queue->mutate);
    return len;
}

variable_types: len int

return_type: int

user_defined_types: struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; }

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


decompiled_code:
__int64 __fastcall ds_queue_capacity(__int64 a1)
{
return *(unsigned int *)(a1 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
return *(unsigned int *)(a1 + 16);
}

original_code:
int
ds_queue_capacity(struct DSQueue *queue)
{
    return queue->capacity;
}


decompiled_code:
int __fastcall ds_queue_close(__int64 a1)
{
pthread_mutex_lock((pthread_mutex_t *)(a1 + 24));
*(_BYTE *)(a1 + 20) = 1;
pthread_cond_broadcast((pthread_cond_t *)(a1 + 64));
return pthread_mutex_unlock((pthread_mutex_t *)(a1 + 24));
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1)
{
pthread_mutex_lock((pthread_mutex_t *)(a1 + 24));
*(_BYTE *)(a1 + 20) = 1;
pthread_cond_broadcast((pthread_cond_t *)(a1 + 64));
return pthread_mutex_unlock((pthread_mutex_t *)(a1 + 24));
}

original_code:
void
ds_queue_close(struct DSQueue *queue)
{
    pthread_mutex_lock(&queue->mutate);
    queue->closed = 1;
    pthread_cond_broadcast(&queue->cond_length);
    pthread_mutex_unlock(&queue->mutate);
}


decompiled_code:
int __fastcall ds_queue_put(__int64 a1, __int64 a2)
{
pthread_mutex_t *v2; // r13
unsigned int v4; // ecx
unsigned int v5; // esi

v2 = (pthread_mutex_t *)(a1 + 24);
pthread_mutex_lock((pthread_mutex_t *)(a1 + 24));
if ( *(_BYTE *)(a1 + 20) )
_assert_fail("!queue->closed", "queue.c", 0x74u, "ds_queue_put");
v4 = *(_DWORD *)(a1 + 12);
v5 = *(_DWORD *)(a1 + 16);
if ( v4 == v5 )
{
do
{
pthread_cond_wait((pthread_cond_t *)(a1 + 64), v2);
v4 = *(_DWORD *)(a1 + 12);
v5 = *(_DWORD *)(a1 + 16);
}
while ( v4 == v5 );
if ( *(_BYTE *)(a1 + 20) )
_assert_fail("!queue->closed", "queue.c", 0x79u, "ds_queue_put");
}
if ( v5 <= v4 )
_assert_fail("queue->length < queue->capacity", "queue.c", 0x7Au, "ds_queue_put");
*(_QWORD *)(*(_QWORD *)a1 + 8LL * ((v4 + *(_DWORD *)(a1 + 8)) % v5)) = a2;
*(_DWORD *)(a1 + 12) = v4 + 1;
pthread_cond_broadcast((pthread_cond_t *)(a1 + 64));
return pthread_mutex_unlock(v2);
}

canonical_decompiled_code:
int __fastcall func4(__int64 a1, __int64 a2)
{
pthread_mutex_t *v2; // r13
unsigned int v4; // ecx
unsigned int v5; // esi

v2 = (pthread_mutex_t *)(a1 + 24);
pthread_mutex_lock((pthread_mutex_t *)(a1 + 24));
if ( *(_BYTE *)(a1 + 20) )
_assert_fail("!queue->closed", "queue.c", 0x74u, "ds_queue_put");
v4 = *(_DWORD *)(a1 + 12);
v5 = *(_DWORD *)(a1 + 16);
if ( v4 == v5 )
{
do
{
pthread_cond_wait((pthread_cond_t *)(a1 + 64), v2);
v4 = *(_DWORD *)(a1 + 12);
v5 = *(_DWORD *)(a1 + 16);
}
while ( v4 == v5 );
if ( *(_BYTE *)(a1 + 20) )
_assert_fail("!queue->closed", "queue.c", 0x79u, "ds_queue_put");
}
if ( v5 <= v4 )
_assert_fail("queue->length < queue->capacity", "queue.c", 0x7Au, "ds_queue_put");
*(_QWORD *)(*(_QWORD *)a1 + 8LL * ((v4 + *(_DWORD *)(a1 + 8)) % v5)) = a2;
*(_DWORD *)(a1 + 12) = v4 + 1;
pthread_cond_broadcast((pthread_cond_t *)(a1 + 64));
return pthread_mutex_unlock(v2);
}

original_code:
void
ds_queue_put(struct DSQueue *queue, void *item)
{
    pthread_mutex_lock(&queue->mutate);
    ((!queue->closed) ? (void) (0) : __assert_fail ("!queue->closed", "queue.c", 116, __extension__ __PRETTY_FUNCTION__));
    while (queue->length == queue->capacity)
        pthread_cond_wait(&queue->cond_length, &queue->mutate);
    ((!queue->closed) ? (void) (0) : __assert_fail ("!queue->closed", "queue.c", 121, __extension__ __PRETTY_FUNCTION__));
    ((queue->length < queue->capacity) ? (void) (0) : __assert_fail ("queue->length < queue->capacity", "queue.c", 122, __extension__ __PRETTY_FUNCTION__));
    queue->buf[(queue->pos + queue->length) % queue->capacity] = item;
    queue->length++;
    pthread_cond_broadcast(&queue->cond_length);
    pthread_mutex_unlock(&queue->mutate);
}

variable_types:
item
void *


decompiled_code:
__int64 __fastcall ds_queue_get(__int64 a1)
{
pthread_mutex_t *v1; // rbp
unsigned int v2; // ecx
__int64 result; // rax
unsigned int v4; // esi
__int64 *v5; // rdx
__int64 v6; // r12
unsigned int v7; // eax

v1 = (pthread_mutex_t *)(a1 + 24);
pthread_mutex_lock((pthread_mutex_t *)(a1 + 24));
v2 = *(_DWORD *)(a1 + 12);
if ( v2 )
{
LABEL_6:
v4 = *(_DWORD *)(a1 + 16);
if ( v4 < v2 )
_assert_fail("queue->length <= queue->capacity", "queue.c", 0x96u, "ds_queue_get");
v5 = (__int64 *)(*(_QWORD *)a1 + 8LL * *(unsigned int *)(a1 + 8));
v6 = *v5;
v7 = *(_DWORD *)(a1 + 8) + 1;
*v5 = 0LL;
*(_DWORD *)(a1 + 12) = v2 - 1;
*(_DWORD *)(a1 + 8) = v7 % v4;
pthread_cond_broadcast((pthread_cond_t *)(a1 + 64));
pthread_mutex_unlock(v1);
result = v6;
}
else
{
while ( !*(_BYTE *)(a1 + 20) )
{
pthread_cond_wait((pthread_cond_t *)(a1 + 64), v1);
v2 = *(_DWORD *)(a1 + 12);
if ( v2 )
goto LABEL_6;
}
pthread_mutex_unlock(v1);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
pthread_mutex_t *v1; // rbp
unsigned int v2; // ecx
__int64 result; // rax
unsigned int v4; // esi
__int64 *v5; // rdx
__int64 v6; // r12
unsigned int v7; // eax

v1 = (pthread_mutex_t *)(a1 + 24);
pthread_mutex_lock((pthread_mutex_t *)(a1 + 24));
v2 = *(_DWORD *)(a1 + 12);
if ( v2 )
{
LABEL_6:
v4 = *(_DWORD *)(a1 + 16);
if ( v4 < v2 )
_assert_fail("queue->length <= queue->capacity", "queue.c", 0x96u, "ds_queue_get");
v5 = (__int64 *)(*(_QWORD *)a1 + 8LL * *(unsigned int *)(a1 + 8));
v6 = *v5;
v7 = *(_DWORD *)(a1 + 8) + 1;
*v5 = 0LL;
*(_DWORD *)(a1 + 12) = v2 - 1;
*(_DWORD *)(a1 + 8) = v7 % v4;
pthread_cond_broadcast((pthread_cond_t *)(a1 + 64));
pthread_mutex_unlock(v1);
result = v6;
}
else
{
while ( !*(_BYTE *)(a1 + 20) )
{
pthread_cond_wait((pthread_cond_t *)(a1 + 64), v1);
v2 = *(_DWORD *)(a1 + 12);
if ( v2 )
goto LABEL_6;
}
pthread_mutex_unlock(v1);
result = 0LL;
}
return result;
}

original_code:
void *
ds_queue_get(struct DSQueue *queue)
{
    void *item;
    pthread_mutex_lock(&queue->mutate);
    while (queue->length == 0) {
        if (queue->closed) {
            pthread_mutex_unlock(&queue->mutate);
            return ((void *)0);
        }
        pthread_cond_wait(&queue->cond_length, &queue->mutate);
    }
    ((queue->length <= queue->capacity) ? (void) (0) : __assert_fail ("queue->length <= queue->capacity", "queue.c", 150, __extension__ __PRETTY_FUNCTION__));
    ((queue->length > 0) ? (void) (0) : __assert_fail ("queue->length > 0", "queue.c", 151, __extension__ __PRETTY_FUNCTION__));
    item = queue->buf[queue->pos];
    queue->buf[queue->pos] = ((void *)0);
    queue->pos = (queue->pos + 1) % queue->capacity;
    queue->length--;
    pthread_cond_broadcast(&queue->cond_length);
    pthread_mutex_unlock(&queue->mutate);
    return item;
}

canonical_original_code:
void *ds_queue_get(struct DSQueue *queue)
{
    void *item;
    pthread_mutex_lock(&queue->mutate);
    while (queue->length == 0) {
        if (queue->closed) {
            pthread_mutex_unlock(&queue->mutate);
            return ((void *)0);
        }
        pthread_cond_wait(&queue->cond_length, &queue->mutate);
    }
    ((queue->length <= queue->capacity) ? (void) (0) : __assert_fail ("queue->length <= queue->capacity", "queue.c", 150, __extension__ __PRETTY_FUNCTION__));
    ((queue->length > 0) ? (void) (0) : __assert_fail ("queue->length > 0", "queue.c", 151, __extension__ __PRETTY_FUNCTION__));
    item = queue->buf[queue->pos];
    queue->buf[queue->pos] = ((void *)0);
    queue->pos = (queue->pos + 1) % queue->capacity;
    queue->length--;
    pthread_cond_broadcast(&queue->cond_length);
    pthread_mutex_unlock(&queue->mutate);
    return item;
}


original_code:
static void
ds_list_unlink(struct DSLinkedList *lst, struct DSListNode *remove)
{
    if (remove == lst->first && remove == lst->last) {
        lst->first = ((void *)0);
        lst->last = ((void *)0);
    }
    else if (remove == lst->first) {
        lst->first = lst->first->next;
        lst->first->prev = ((void *)0);
    }
    else if (remove == lst->last) {
        lst->last = lst->last->prev;
        lst->last->next = ((void *)0);
    }
    else {
        remove->prev->next = remove->next;
        remove->next->prev = remove->prev;
    }
    --lst->length;
}

variable_types: struct DSLinkedList { unsigned int length; struct DSListNode { void *data; struct DSListNode *prev; struct DSListNode *next; } *first; struct DSListNode *last; } *

variable_types:
remove
struct DSListNode *

user_defined_types: struct DSLinkedList { unsigned int length; struct DSListNode *first; struct DSListNode *last; }


decompiled_code:
_QWORD *ds_list_create()
{
_QWORD *result; // rax

result = malloc(0x18uLL);
if ( !result )
_assert_fail("lst", "linkedlist.c", 0x19u, "ds_list_create");
*(_DWORD *)result = 0;
result[1] = 0LL;
result[2] = 0LL;
return result;
}

canonical_decompiled_code:
_QWORD *func1()
{
_QWORD *result; // rax

result = malloc(0x18uLL);
if ( !result )
_assert_fail("lst", "linkedlist.c", 0x19u, "ds_list_create");
*(_DWORD *)result = 0;
result[1] = 0LL;
result[2] = 0LL;
return result;
}

original_code:
struct DSLinkedList *
ds_list_create()
{
    struct DSLinkedList *lst;
    lst = malloc(sizeof(*lst));
    ((lst) ? (void) (0) : __assert_fail ("lst", "linkedlist.c", 25, __extension__ __PRETTY_FUNCTION__));
    lst->length = 0;
    lst->first = ((void *)0);
    lst->last = ((void *)0);
    return lst;
}

canonical_original_code:
struct DSLinkedList *ds_list_create()
{
    struct DSLinkedList *lst;
    lst = malloc(sizeof(*lst));
    ((lst) ? (void) (0) : __assert_fail ("lst", "linkedlist.c", 25, __extension__ __PRETTY_FUNCTION__));
    lst->length = 0;
    lst->first = ((void *)0);
    lst->last = ((void *)0);
    return lst;
}

return_type: struct DSLinkedList { unsigned int length; struct DSListNode { void *data; struct DSListNode *prev; struct DSListNode *next; } *first; struct DSListNode *last; } *


decompiled_code:
void __fastcall ds_list_free(void *ptr)
{
__int64 v1; // rbx
void **v2; // rbp

v1 = *((_QWORD *)ptr + 1);
while ( v1 )
{
v2 = (void **)v1;
v1 = *(_QWORD *)(v1 + 16);
free(*v2);
free(v2);
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
__int64 v1; // rbx
void **v2; // rbp

v1 = *((_QWORD *)ptr + 1);
while ( v1 )
{
v2 = (void **)v1;
v1 = *(_QWORD *)(v1 + 16);
free(*v2);
free(v2);
}
free(ptr);
}

original_code:
void
ds_list_free(struct DSLinkedList *lst)
{
    struct DSListNode *node, *temp;
    node = lst->first;
    while (node != ((void *)0)) {
        temp = node->next;
        free(node->data);
        free(node);
        node = temp;
    }
    free(lst);
}

canonical_original_code:
void ds_list_free(struct DSLinkedList *lst)
{
    struct DSListNode *node; struct DSListNode *temp;
    node = lst->first;
    while (node != ((void *)0)) {
        temp = node->next;
        free(node->data);
        free(node);
        node = temp;
    }
    free(lst);
}

variable_types: struct DSListNode { void *data; struct DSListNode *prev; struct DSListNode *next; } *


decompiled_code:
void __fastcall ds_list_free_no_data(void *ptr)
{
_QWORD *v2; // rbx
void *v3; // rdi

v2 = (_QWORD *)*((_QWORD *)ptr + 1);
while ( v2 )
{
v3 = v2;
v2 = (_QWORD *)v2[2];
free(v3);
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func3(void *ptr)
{
_QWORD *v2; // rbx
void *v3; // rdi

v2 = (_QWORD *)*((_QWORD *)ptr + 1);
while ( v2 )
{
v3 = v2;
v2 = (_QWORD *)v2[2];
free(v3);
}
free(ptr);
}

original_code:
void
ds_list_free_no_data(struct DSLinkedList *lst)
{
    struct DSListNode *node, *temp;
    node = lst->first;
    while (node != ((void *)0)) {
        temp = node->next;
        free(node);
        node = temp;
    }
    free(lst);
}

canonical_original_code:
void ds_list_free_no_data(struct DSLinkedList *lst)
{
    struct DSListNode *node; struct DSListNode *temp;
    node = lst->first;
    while (node != ((void *)0)) {
        temp = node->next;
        free(node);
        node = temp;
    }
    free(lst);
}

user_defined_types: struct DSListNode { void *data; struct DSListNode *prev; struct DSListNode *next; }


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

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

original_code:
void
ds_list_remove(struct DSLinkedList *lst, struct DSListNode *remove)
{
    ds_list_unlink(lst, remove);
    free(remove);
}


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

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

original_code:
void
ds_list_destroy(struct DSLinkedList *lst, struct DSListNode *remove)
{
    ds_list_unlink(lst, remove);
    free(remove->data);
    free(remove);
}


minimum

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

result = a1;
if ( (int)a2 <= (int)a1 )
result = a2;
return result;
}

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

result = a1;
if ( (int)a2 <= (int)a1 )
result = a2;
return result;
}

original_code: int minimum(int a, int b){return a<b?a:b;}

variable_types: a int

variable_types: b int


maximum

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

result = a1;
if ( (int)a2 >= (int)a1 )
result = a2;
return result;
}

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

result = a1;
if ( (int)a2 >= (int)a1 )
result = a2;
return result;
}

original_code: int maximum(int a, int b){return a>b?a:b;}


decompiled_code:
char *__fastcall to_octal_str(unsigned int a1)
{
char *v1; // rax
char *v2; // r12

v1 = (char *)malloc(0x10uLL);
if ( !v1 )
_assert_fail("buf", "edit_scripts.c", 0x10u, "to_octal_str");
v2 = v1;
sprintf(v1, "%o", a1);
return v2;
}

canonical_decompiled_code:
char *__fastcall func2(unsigned int a1)
{
char *v1; // rax
char *v2; // r12

v1 = (char *)malloc(0x10uLL);
if ( !v1 )
_assert_fail("buf", "edit_scripts.c", 0x10u, "to_octal_str");
v2 = v1;
sprintf(v1, "%o", a1);
return v2;
}

original_code:
char *to_octal_str(int i) {
    char *buf = malloc(16*sizeof(*buf));
    ((buf) ? (void) (0) : __assert_fail ("buf", "edit_scripts.c", 16, __extension__ __PRETTY_FUNCTION__));
    sprintf(buf, "%o", i);
    return buf;
}

variable_types:
buf
char *

return_type: char *


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

if ( a1 > 115 )
return 15LL;
if ( a1 <= 44 )
{
result = 8LL;
if ( a1 != -80 )
{
result = 9LL;
if ( a1 != -71 )
result = 15LL;
}
}
else
{
switch ( a1 )
{
case '-':
result = 12LL;
break;
case '0':
result = 0LL;
break;
case '1':
result = 1LL;
break;
case '2':
result = 2LL;
break;
case '3':
result = 3LL;
break;
case '4':
result = 4LL;
break;
case '5':
result = 5LL;
break;
case '6':
result = 6LL;
break;
case '7':
result = 7LL;
break;
case 'A':
result = 8LL;
break;
case 'C':
result = 9LL;
break;
case 'G':
result = 10LL;
break;
case 'T':
result = 11LL;
break;
case 'i':
result = 13LL;
break;
case 's':
result = 14LL;
break;
default:
return 15LL;
}
}
return result;
}

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

if ( a1 > 115 )
return 15LL;
if ( a1 <= 44 )
{
result = 8LL;
if ( a1 != -80 )
{
result = 9LL;
if ( a1 != -71 )
result = 15LL;
}
}
else
{
switch ( a1 )
{
case '-':
result = 12LL;
break;
case '0':
result = 0LL;
break;
case '1':
result = 1LL;
break;
case '2':
result = 2LL;
break;
case '3':
result = 3LL;
break;
case '4':
result = 4LL;
break;
case '5':
result = 5LL;
break;
case '6':
result = 6LL;
break;
case '7':
result = 7LL;
break;
case 'A':
result = 8LL;
break;
case 'C':
result = 9LL;
break;
case 'G':
result = 10LL;
break;
case 'T':
result = 11LL;
break;
case 'i':
result = 13LL;
break;
case 's':
result = 14LL;
break;
default:
return 15LL;
}
}
return result;
}

original_code:
char to_half_byte(char c){
    switch (c) {
        case '0': return (char)0;
        case '1': return (char)1;
        case '2': return (char)2;
        case '3': return (char)3;
        case '4': return (char)4;
        case '5': return (char)5;
        case '6': return (char)6;
        case '7': return (char)7;
        case 'A': return (char)8;
        case 'C': return (char)9;
        case 'G': return (char)10;
        case 'T': return (char)11;
        case '-': return (char)12;
        case 'i': return (char)13;
        case 's': return (char)14;
        case '0' | (char)0x80: return (char)8;
        case '9' | (char)0x80: return (char)9;
        default: return (char)15;
    }
}

variable_types: c char

return_type: char


decompiled_code:
__int64 __fastcall half_byte_to_char(int a1)
{
unsigned __int8 v1; // di
__int64 result; // rax

if ( (char)a1 <= 7 )
return (unsigned int)(a1 + 48);
v1 = a1 - 8;
result = 78LL;
if ( v1 <= 6u )
result = (unsigned __int8)CSWTCH_21[v1];
return result;
}

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

if ( (char)a1 <= 7 )
return (unsigned int)(a1 + 48);
v1 = a1 - 8;
result = 78LL;
if ( v1 <= 6u )
result = (unsigned __int8)CSWTCH_21[v1];
return result;
}

original_code:
char half_byte_to_char(char h){
    if (h < 8)
        return '0' + h;
    switch (h) {
        case (char)8: return 'A';
        case (char)9: return 'C';
        case (char)10: return 'G';
        case (char)11: return 'T';
        case (char)12: return '-';
        case (char)13: return 'i';
        case (char)14: return 's';
        default: return 'N';
    }
}

variable_types: h char


original_code:
_Bool next_edit(char *edit_script, int *pos, struct edit_info *edit){
    int edit_length = 0, i = 0;
    if (((*__ctype_b_loc ())[(int) ((edit_script[(*pos)]))] & (unsigned short int) _ISdigit) || edit_script[(*pos)] == '\0')
        return 0;
    edit->is_subdel = edit_script[(*pos)++] == 's';
    edit->last_dist = 0;
    edit->str_length = 0;
    if (edit->str != ((void *)0))
        free(edit->str);
    while (((*__ctype_b_loc ())[(int) ((edit_script[(*pos)]))] & (unsigned short int) _ISdigit)) {
        edit->last_dist *= 8;
        edit->last_dist += edit_script[(*pos)++] - '0';
    }
    while (((*__ctype_b_loc ())[(int) ((edit_script[(*pos)+edit_length]))] & (unsigned short int) _ISupper) ||
                   edit_script[(*pos)+edit_length] == '-')
        edit_length++;
    edit->str = malloc((edit_length+1)*sizeof(*edit_script));
    ((edit->str) ? (void) (0) : __assert_fail ("edit->str", "edit_scripts.c", 232, __extension__ __PRETTY_FUNCTION__));
    edit->str_length = edit_length;
    while (((*__ctype_b_loc ())[(int) ((edit_script[(*pos)]))] & (unsigned short int) _ISupper) || edit_script[(*pos)] == '-')
        edit->str[i++] = edit_script[(*pos)++];
    return 1;
}

canonical_original_code:
_Bool next_edit(char *edit_script, int *pos, struct edit_info *edit){
    int edit_length = 0; int i = 0;
    if (((*__ctype_b_loc ())[(int) ((edit_script[(*pos)]))] & (unsigned short) _ISdigit) || edit_script[(*pos)] == '\0')
        return 0;
    edit->is_subdel = edit_script[(*pos)++] == 's';
    edit->last_dist = 0;
    edit->str_length = 0;
    if (edit->str != ((void *)0))
        free(edit->str);
    while (((*__ctype_b_loc ())[(int) ((edit_script[(*pos)]))] & (unsigned short) _ISdigit)) {
        edit->last_dist *= 8;
        edit->last_dist += edit_script[(*pos)++] - '0';
    }
    while (((*__ctype_b_loc ())[(int) ((edit_script[(*pos)+edit_length]))] & (unsigned short) _ISupper) ||
                   edit_script[(*pos)+edit_length] == '-')
        edit_length++;
    edit->str = malloc((edit_length+1)*sizeof(*edit_script));
    ((edit->str) ? (void) (0) : __assert_fail ("edit->str", "edit_scripts.c", 232, __extension__ __PRETTY_FUNCTION__));
    edit->str_length = edit_length;
    while (((*__ctype_b_loc ())[(int) ((edit_script[(*pos)]))] & (unsigned short) _ISupper) || edit_script[(*pos)] == '-')
        edit->str[i++] = edit_script[(*pos)++];
    return 1;
}

variable_types:
pos
int *

variable_types: struct edit_info { _Bool is_subdel; int last_dist; char *str; int str_length; } *

variable_types: i int


original_code:
char *read_edit_script(char *edit_script, char *orig, int length){
    struct edit_info edit;
    int orig_pos = 0, last_edit_str_len = 0, current = 0, script_pos = 1;
    char *str = malloc((2*length+1)*sizeof(*str));
    ((str) ? (void) (0) : __assert_fail ("str", "edit_scripts.c", 250, __extension__ __PRETTY_FUNCTION__));
    edit.str = ((void *)0);
    while (next_edit(edit_script, &script_pos, &edit)) {
        for (int i = 0; i < edit.last_dist - last_edit_str_len; i++)
            str[current++] = orig[orig_pos+i];
        orig_pos += edit.last_dist - last_edit_str_len;
        for (int i = 0; i < edit.str_length; i++)
            if (edit.str[i] != '-')
                str[current++] = edit.str[i];
        if (edit.is_subdel) orig_pos += edit.str_length;
        last_edit_str_len = edit.str_length;
    }
    free(edit.str);
    while (orig_pos < length)
        str[current++] = orig[orig_pos++];
    str = realloc(str, (current+1)*sizeof(*str));
    ((str) ? (void) (0) : __assert_fail ("str", "edit_scripts.c", 278, __extension__ __PRETTY_FUNCTION__));
    str[current] = '\0';
    if ((edit_script[0] & ((char)0x7f)) == '1') {
        char *str_fwd = str;
        str = string_revcomp(str_fwd, -1);
        free(str_fwd);
    }
    return str;
}

canonical_original_code:
char *read_edit_script(char *edit_script, char *orig, int length){
    struct edit_info edit;
    int orig_pos = 0; int last_edit_str_len = 0; int current = 0; int script_pos = 1;
    char *str = malloc((2*length+1)*sizeof(*str));
    ((str) ? (void) (0) : __assert_fail ("str", "edit_scripts.c", 250, __extension__ __PRETTY_FUNCTION__));
    edit.str = ((void *)0);
    while (next_edit(edit_script, &script_pos, &edit)) {
        for (int i = 0; i < edit.last_dist - last_edit_str_len; i++)
            str[current++] = orig[orig_pos+i];
        orig_pos += edit.last_dist - last_edit_str_len;
        for (int i = 0; i < edit.str_length; i++)
            if (edit.str[i] != '-')
                str[current++] = edit.str[i];
        if (edit.is_subdel) orig_pos += edit.str_length;
        last_edit_str_len = edit.str_length;
    }
    free(edit.str);
    while (orig_pos < length)
        str[current++] = orig[orig_pos++];
    str = realloc(str, (current+1)*sizeof(*str));
    ((str) ? (void) (0) : __assert_fail ("str", "edit_scripts.c", 278, __extension__ __PRETTY_FUNCTION__));
    str[current] = '\0';
    if ((edit_script[0] & ((char)0x7f)) == '1') {
        char *str_fwd = str;
        str = string_revcomp(str_fwd, -1);
        free(str_fwd);
    }
    return str;
}

variable_types:
orig
char *

variable_types: length int

variable_types: struct edit_info { _Bool is_subdel; int last_dist; char *str; int str_length; }

variable_types: current int

variable_types:
str
char *


decompiled_code:
// attributes: thunk
void opt_flag_free(void *ptr)
{
free(ptr);
}

canonical_decompiled_code:
void func6(void *ptr)
{
free(ptr);
}

original_code:
static void
opt_flag_free(struct opt_flag *flag)
{
    free(flag);
}

variable_types: struct opt_flag { _Bool parsed; enum opt_flag_types { OPT_BOOL=0, OPT_INT=1, OPT_DOUBLE=2, OPT_STRING=3 } type; char *name; char *usage; union { _Bool *b; int *i; double *d; char **s; } storage; union { _Bool b; int i; double d; char *s; } defval; } *

user_defined_types: struct opt_flag { _Bool parsed; enum opt_flag_types type; char *name; char *usage; union { _Bool *b; int *i; double *d; char **s; } storage; union { _Bool b; int i; double d; char *s; } defval; }


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

v1 = *(_DWORD *)(a1 + 4);
if ( v1 == 2 )
{
printf("--%s %f\n", *(const char **)(a1 + 8), *(double *)(a1 + 32));
}
else if ( v1 > 2 )
{
if ( v1 != 3 )
__assert_fail("false", "opt.c", 0x64u, "opt_flag_print_usage");
printf("--%s %s\n", *(const char **)(a1 + 8), *(const char **)(a1 + 32));
}
else if ( v1 )
{
printf("--%s %d\n", *(const char **)(a1 + 8), *(unsigned int *)(a1 + 32));
}
else
{
printf("--%s\n", *(const char **)(a1 + 8));
}
return printf("\t%s\n", *(const char **)(a1 + 16));
}

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

v1 = *(_DWORD *)(a1 + 4);
if ( v1 == 2 )
{
printf("--%s %f\n", *(const char **)(a1 + 8), *(double *)(a1 + 32));
}
else if ( v1 > 2 )
{
if ( v1 != 3 )
__assert_fail("false", "opt.c", 0x64u, "opt_flag_print_usage");
printf("--%s %s\n", *(const char **)(a1 + 8), *(const char **)(a1 + 32));
}
else if ( v1 )
{
printf("--%s %d\n", *(const char **)(a1 + 8), *(unsigned int *)(a1 + 32));
}
else
{
printf("--%s\n", *(const char **)(a1 + 8));
}
return printf("\t%s\n", *(const char **)(a1 + 16));
}

original_code:
static void
opt_flag_print_usage(struct opt_flag *flag)
{
    switch (flag->type) {
    case OPT_BOOL:
        printf("--%s\n", flag->name);
        break;
    case OPT_INT:
        printf("--%s %d\n", flag->name, flag->defval.i);
        break;
    case OPT_DOUBLE:
        printf("--%s %f\n", flag->name, flag->defval.d);
        break;
    case OPT_STRING:
        printf("--%s %s\n", flag->name, flag->defval.s);
        break;
    default:
        ((0) ? (void) (0) : __assert_fail ("false", "opt.c", 100, __extension__ __PRETTY_FUNCTION__));
        break;
    }
    printf("\t%s\n", flag->usage);
}

user_defined_types: enum opt_flag_types { OPT_BOOL=0, OPT_INT=1, OPT_DOUBLE=2, OPT_STRING=3 }


decompiled_code:
int __fastcall opt_config_print_defaults(__int64 a1)
{
int result; // eax
__int64 v3; // rbx
__int64 v4; // rdi

result = *(_DWORD *)(a1 + 8);
if ( result > 0 )
{
v3 = 0LL;
do
{
v4 = *(_QWORD *)(*(_QWORD *)a1 + 8 * v3++);
result = opt_flag_print_usage(v4);
}
while ( *(_DWORD *)(a1 + 8) > (int)v3 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func8(__int64 a1)
{
int result; // eax
__int64 v3; // rbx
__int64 v4; // rdi

result = *(_DWORD *)(a1 + 8);
if ( result > 0 )
{
v3 = 0LL;
do
{
v4 = *(_QWORD *)(*(_QWORD *)a1 + 8 * v3++);
result = func7(v4);
}
while ( *(_DWORD *)(a1 + 8) > (int)v3 );
}
return result;
}

original_code:
void
opt_config_print_defaults(struct opt_config *conf)
{
    int i;
    for (i = 0; i < conf->length; i++)
        opt_flag_print_usage(conf->flags[i]);
}

variable_types: struct opt_config { struct opt_flag { _Bool parsed; enum opt_flag_types { OPT_BOOL=0, OPT_INT=1, OPT_DOUBLE=2, OPT_STRING=3 } type; char *name; char *usage; union { _Bool *b; int *i; double *d; char **s; } storage; union { _Bool b; int i; double d; char *s; } defval; } **flags; int length; _Bool parsed; _Bool help; void (*usage)(struct opt_config *conf); } *

user_defined_types: struct opt_config { struct opt_flag **flags; int length; _Bool parsed; _Bool help; void (*usage)(struct opt_config *conf); }


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

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

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

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

original_code:
void
opt_config_free(struct opt_config *conf)
{
    int32_t i;
    for (i = 0; i < conf->length; i++)
        opt_flag_free(conf->flags[i]);
    free(conf->flags);
    free(conf);
}

canonical_original_code:
void opt_config_free(struct opt_config *conf)
{
    int i;
    for (i = 0; i < conf->length; i++)
        opt_flag_free(conf->flags[i]);
    free(conf->flags);
    free(conf);
}


decompiled_code:
// attributes: thunk
void opt_args_free(void *ptr)
{
free(ptr);
}

canonical_decompiled_code:
void func10(void *ptr)
{
free(ptr);
}

original_code:
void
opt_args_free(struct opt_args *args)
{
    free(args);
}

variable_types: struct opt_args { int nargs; char **args; } *


decompiled_code:
__int64 __fastcall opt_config_print_usage(__int64 a1)
{
return (*(__int64 (**)(void))(a1 + 16))();
}

original_code:
void
opt_config_print_usage(struct opt_config *conf)
{
    (*conf->usage)(conf);
}


decompiled_code:
_QWORD *opt_config_init()
{
_QWORD *v0; // rax
_QWORD *v1; // r12

v0 = malloc(0x18uLL);
if ( !v0 )
__assert_fail("conf", "opt.c", 0x13u, "opt_config_init");
v1 = v0;
*v0 = 0LL;
v0[2] = opt_config_print_defaults;
*((_WORD *)v0 + 6) = 0;
*((_DWORD *)v0 + 2) = 0;
opt_flag_bool(v0, (char *)v0 + 13, "help", "Shows this usage information.");
return v1;
}

canonical_decompiled_code:
_QWORD *func12()
{
_QWORD *v0; // rax
_QWORD *v1; // r12

v0 = malloc(0x18uLL);
if ( !v0 )
__assert_fail("conf", "opt.c", 0x13u, "opt_config_init");
v1 = v0;
*v0 = 0LL;
v0[2] = opt_config_print_defaults;
*((_WORD *)v0 + 6) = 0;
*((_DWORD *)v0 + 2) = 0;
opt_flag_bool(v0, (char *)v0 + 13, "help", "Shows this usage information.");
return v1;
}

original_code:
struct opt_config *
opt_config_init()
{
    struct opt_config *conf;
    conf = malloc(sizeof(*conf));
    ((conf) ? (void) (0) : __assert_fail ("conf", "opt.c", 19, __extension__ __PRETTY_FUNCTION__));
    conf->length = 0;
    conf->flags = ((void *)0);
    conf->parsed = 0;
    conf->usage = opt_config_print_defaults;
    conf->help = 0;
    opt_flag_bool(conf, &conf->help, "help",
                  "Shows this usage information.");
    return conf;
}

canonical_original_code:
struct opt_config *opt_config_init()
{
    struct opt_config *conf;
    conf = malloc(sizeof(*conf));
    ((conf) ? (void) (0) : __assert_fail ("conf", "opt.c", 19, __extension__ __PRETTY_FUNCTION__));
    conf->length = 0;
    conf->flags = ((void *)0);
    conf->parsed = 0;
    conf->usage = opt_config_print_defaults;
    conf->help = 0;
    opt_flag_bool(conf, &conf->help, "help",
                  "Shows this usage information.");
    return conf;
}

return_type: struct opt_config { struct opt_flag { _Bool parsed; enum opt_flag_types { OPT_BOOL=0, OPT_INT=1, OPT_DOUBLE=2, OPT_STRING=3 } type; char *name; char *usage; union { _Bool *b; int *i; double *d; char **s; } storage; union { _Bool b; int i; double d; char *s; } defval; } **flags; int length; _Bool parsed; _Bool help; void (*usage)(struct opt_config *conf); } *


trim

original_code:
char *trim(char *s, const char *totrim){
    int32_t i, j, start, end, slen, totrimlen, newlen;
    char *news;
    _Bool trimmed;
    slen = strlen(s);
    totrimlen = strlen(totrim);
    start = 0;
    for (i = 0; i < slen; i++) {
        trimmed = 0;
        for (j = 0; j < totrimlen; j++)
            if (totrim[j] == s[i]) {
                start++;
                trimmed = 1;
                break;
            }
        if (!trimmed)
            break;
    }
    for (i = slen - 1; i >= 0; i--) {
        trimmed = 0;
        for (j = 0; j < totrimlen; j++)
            if (totrim[j] == s[i]) {
                end--;
                trimmed = 1;
            }
        if (!trimmed)
            break;
    }
    end = i+1;
    newlen = (end >= start) ? (end - start) : 0;
    news = malloc((newlen+1)*sizeof(*news));
    ((news) ? (void) (0) : __assert_fail ("news", "util.c", 55, __extension__ __PRETTY_FUNCTION__));
    strncpy(news, s + start, newlen);
    news[newlen] = '\0';
    free(s);
    return news;
}

canonical_original_code:
char *trim(char *s, char *totrim){
    int i; int j; int start; int end; int slen; int totrimlen; int newlen;
    char *news;
    _Bool trimmed;
    slen = strlen(s);
    totrimlen = strlen(totrim);
    start = 0;
    for (i = 0; i < slen; i++) {
        trimmed = 0;
        for (j = 0; j < totrimlen; j++)
            if (totrim[j] == s[i]) {
                start++;
                trimmed = 1;
                break;
            }
        if (!trimmed)
            break;
    }
    for (i = slen - 1; i >= 0; i--) {
        trimmed = 0;
        for (j = 0; j < totrimlen; j++)
            if (totrim[j] == s[i]) {
                end--;
                trimmed = 1;
            }
        if (!trimmed)
            break;
    }
    end = i+1;
    newlen = (end >= start) ? (end - start) : 0;
    news = malloc((newlen+1)*sizeof(*news));
    ((news) ? (void) (0) : __assert_fail ("news", "util.c", 55, __extension__ __PRETTY_FUNCTION__));
    strncpy(news, s + start, newlen);
    news[newlen] = '\0';
    free(s);
    return news;
}

variable_types:
s
char *

variable_types:
totrim
char *

variable_types: j int

variable_types: start int

variable_types: end int

variable_types: slen int

variable_types: totrimlen int

variable_types: newlen int

variable_types:
news
char *


decompiled_code:
char *__fastcall trim_space(void *a1)
{
return trim(a1, " \r\n\t");
}

canonical_decompiled_code:
char *__fastcall func1(void *a1)
{
return func0(a1, " \r\n\t");
}

original_code:
char *trim_space(char *s){
    return trim(s, " \r\n\t");
}


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

result = sysconf(84);
if ( (int)result <= 0 )
result = 1LL;
return result;
}

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

result = sysconf(84);
if ( (int)result <= 0 )
result = 1LL;
return result;
}

original_code:
int32_t num_cpus(){
    int32_t cpus;
    cpus = (int32_t)sysconf(_SC_NPROCESSORS_ONLN);
    if (cpus <= 0)
        cpus = 1;
    return cpus;
}

canonical_original_code:
int num_cpus(){
    int cpus;
    cpus = (int)sysconf(_SC_NPROCESSORS_ONLN);
    if (cpus <= 0)
        cpus = 1;
    return cpus;
}

variable_types: cpus int


decompiled_code:
char *__fastcall str_slice(const char *a1, int a2, int a3)
{
char *v4; // rax

if ( a3 <= a2 )
_assert_fail("end > start", "util.c", 0x6Fu, "str_slice");
if ( a2 < 0 )
_assert_fail("start >= 0", "util.c", 0x70u, "str_slice");
if ( a3 > strlen(a1) )
_assert_fail("end <= strlen(str)", "util.c", 0x71u, "str_slice");
v4 = (char *)malloc(a3 + 1 - a2);
if ( !v4 )
_assert_fail("ret", "util.c", 0x74u, "str_slice");
return strncpy(v4, &a1[a2], a3 - a2);
}

canonical_decompiled_code:
char *__fastcall func4(const char *a1, int a2, int a3)
{
char *v4; // rax

if ( a3 <= a2 )
_assert_fail("end > start", "util.c", 0x6Fu, "str_slice");
if ( a2 < 0 )
_assert_fail("start >= 0", "util.c", 0x70u, "str_slice");
if ( a3 > strlen(a1) )
_assert_fail("end <= strlen(str)", "util.c", 0x71u, "str_slice");
v4 = (char *)malloc(a3 + 1 - a2);
if ( !v4 )
_assert_fail("ret", "util.c", 0x74u, "str_slice");
return strncpy(v4, &a1[a2], a3 - a2);
}

original_code:
char *str_slice(char *str, int32_t start, int32_t end){
    char *ret;
    ((end > start) ? (void) (0) : __assert_fail ("end > start", "util.c", 111, __extension__ __PRETTY_FUNCTION__));
    ((start >= 0) ? (void) (0) : __assert_fail ("start >= 0", "util.c", 112, __extension__ __PRETTY_FUNCTION__));
    ((end <= strlen(str)) ? (void) (0) : __assert_fail ("end <= strlen(str)", "util.c", 113, __extension__ __PRETTY_FUNCTION__));
    ret = malloc((1+end-start)*sizeof(*ret));
    ((ret) ? (void) (0) : __assert_fail ("ret", "util.c", 116, __extension__ __PRETTY_FUNCTION__));
    strncpy(ret, str + start, end - start);
    return ret;
}

canonical_original_code:
char *str_slice(char *str, int start, int end){
    char *ret;
    ((end > start) ? (void) (0) : __assert_fail ("end > start", "util.c", 111, __extension__ __PRETTY_FUNCTION__));
    ((start >= 0) ? (void) (0) : __assert_fail ("start >= 0", "util.c", 112, __extension__ __PRETTY_FUNCTION__));
    ((end <= strlen(str)) ? (void) (0) : __assert_fail ("end <= strlen(str)", "util.c", 113, __extension__ __PRETTY_FUNCTION__));
    ret = malloc((1+end-start)*sizeof(*ret));
    ((ret) ? (void) (0) : __assert_fail ("ret", "util.c", 116, __extension__ __PRETTY_FUNCTION__));
    strncpy(ret, str + start, end - start);
    return ret;
}

variable_types:
ret
char *


decompiled_code:
__int64 __fastcall is_substring(const char *a1, const char *a2)
{
unsigned int v2; // er14
int v4; // er13
int v5; // er8
int v6; // edi
__int64 v7; // rax
int v8; // edx

LOBYTE(v2) = a2 == 0LL || a1 == 0LL;
if ( (_BYTE)v2 )
_assert_fail("sub != NULL && str != NULL", "util.c", 0x7Du, "is_substring");
v4 = strlen(a1);
v5 = strlen(a2) - v4;
if ( v5 <= 0 )
return v2;
v6 = 0;
while ( 1 )
{
v7 = 1LL;
v8 = 0;
if ( v4 > 0 )
{
while ( a1[v7 - 1] == a2[v7 - 1] )
{
v8 = v7++;
if ( v7 == (unsigned int)(v4 - 1) + 2LL )
goto LABEL_10;
}
goto LABEL_8;
}
LABEL_10:
if ( v4 == v8 )
return 1LL;
LABEL_8:
++v6;
++a2;
if ( v6 == v5 )
return v2;
}
}

canonical_decompiled_code:
__int64 __fastcall func5(const char *a1, const char *a2)
{
unsigned int v2; // er14
int v4; // er13
int v5; // er8
int v6; // edi
__int64 v7; // rax
int v8; // edx

LOBYTE(v2) = a2 == 0LL || a1 == 0LL;
if ( (_BYTE)v2 )
_assert_fail("sub != NULL && str != NULL", "util.c", 0x7Du, "is_substring");
v4 = strlen(a1);
v5 = strlen(a2) - v4;
if ( v5 <= 0 )
return v2;
v6 = 0;
while ( 1 )
{
v7 = 1LL;
v8 = 0;
if ( v4 > 0 )
{
while ( a1[v7 - 1] == a2[v7 - 1] )
{
v8 = v7++;
if ( v7 == (unsigned int)(v4 - 1) + 2LL )
goto LABEL_10;
}
goto LABEL_8;
}
LABEL_10:
if ( v4 == v8 )
return 1LL;
LABEL_8:
++v6;
++a2;
if ( v6 == v5 )
return v2;
}
}

original_code:
_Bool is_substring(char *sub, char *str){
    ((sub != ((void *)0) && str != ((void *)0)) ? (void) (0) : __assert_fail ("sub != NULL && str != NULL", "util.c", 125, __extension__ __PRETTY_FUNCTION__));
    int len_sub = strlen(sub), len_str = strlen(str), i, j;
    for (i = 0; i < len_str-len_sub; i++) {
        for (j = 0; j < len_sub; j++)
            if (sub[j] != str[i+j])
                break;
        if (j == len_sub)
            return 1;
    }
    return 0;
}

canonical_original_code:
_Bool is_substring(char *sub, char *str){
    ((sub != ((void *)0) && str != ((void *)0)) ? (void) (0) : __assert_fail ("sub != NULL && str != NULL", "util.c", 125, __extension__ __PRETTY_FUNCTION__));
    int len_sub = strlen(sub); int len_str = strlen(str); int i; int j;
    for (i = 0; i < len_str-len_sub; i++) {
        for (j = 0; j < len_sub; j++)
            if (sub[j] != str[i+j])
                break;
        if (j == len_sub)
            return 1;
    }
    return 0;
}

variable_types:
sub
char *

variable_types: i int


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

if ( a1 == 64 )
return -1LL;
result = 0LL;
if ( a1 )
result = (1LL << a1) - 1;
return result;
}

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

if ( a1 == 64 )
return -1LL;
result = 0LL;
if ( a1 )
result = (1LL << a1) - 1;
return result;
}

original_code:
uint64_t make_mask(int bits){
    uint64_t mask = (uint64_t)1;
    if (bits == 64)
        return ~(uint64_t)0;
    if (bits == 0)
        return (uint64_t)0;
    mask <<= bits;
    return mask-1;
}

canonical_original_code:
unsigned long make_mask(int bits){
    unsigned long mask = (uint64_t)1;
    if (bits == 64)
        return ~(unsigned long)0;
    if (bits == 0)
        return (unsigned long)0;
    mask <<= bits;
    return mask-1;
}

variable_types: bits int

variable_types:
mask
unsigned long

return_type: unsigned long


decompiled_code:
__int64 __fastcall shift_left(__int64 a1, char a2)
{
return a1 << a2;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, char a2)
{
return a1 << a2;
}

original_code:
uint64_t shift_left(uint64_t x, int bits){
    return x<<bits;
}

canonical_original_code:
unsigned long shift_left(unsigned long x, int bits){
    return x<<bits;
}

variable_types:
x
unsigned long


decompiled_code:
__int64 __fastcall shift_right(__int64 a1, int a2)
{
__int64 v2; // rax
unsigned __int64 v3; // rdx

v2 = make_mask(64 - a2);
return (v3 >> a2) & v2;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int a2)
{
__int64 v2; // rax
unsigned __int64 v3; // rdx

v2 = func0(64 - a2);
return (v3 >> a2) & v2;
}

original_code:
uint64_t shift_right(uint64_t x, int bits){
    uint64_t mask = make_mask(64-bits);
    x >>= bits;
    return x & mask;
}

canonical_original_code:
unsigned long shift_right(unsigned long x, int bits){
    unsigned long mask = make_mask(64-bits);
    x >>= bits;
    return x & mask;
}


decompiled_code:
__int64 __fastcall bytes_to_int(__int64 a1, int a2, int a3)
{
unsigned __int8 *v4; // rdx
__int64 v5; // rsi
__int64 result; // rax
__int64 v7; // rcx

if ( a3 <= 0 )
return 0LL;
v4 = (unsigned __int8 *)(a1 + a2);
v5 = (__int64)&v4[a3 - 1 + 1];
result = 0LL;
do
{
v7 = *v4++;
result = v7 | (result << 8);
}
while ( v4 != (unsigned __int8 *)v5 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, int a2, int a3)
{
unsigned __int8 *v4; // rdx
__int64 v5; // rsi
__int64 result; // rax
__int64 v7; // rcx

if ( a3 <= 0 )
return 0LL;
v4 = (unsigned __int8 *)(a1 + a2);
v5 = (__int64)&v4[a3 - 1 + 1];
result = 0LL;
do
{
v7 = *v4++;
result = v7 | (result << 8);
}
while ( v4 != (unsigned __int8 *)v5 );
return result;
}

original_code:
uint64_t bytes_to_int(char *bytes, int start, int size){
    int i;
    uint64_t val = (uint64_t)0, mask = (uint64_t)0xff;
    for (i = 0; i < size; i++) {
        uint64_t current_byte = ((uint64_t)(bytes[start+i])) & mask;
        val <<= 8;
        val |= current_byte;
    }
    return val;
}

canonical_original_code:
unsigned long bytes_to_int(char *bytes, int start, int size){
    int i;
    unsigned long val = (uint64_t)0; unsigned long mask = (uint64_t)0xff;
    for (i = 0; i < size; i++) {
        unsigned long current_byte = ((uint64_t)(bytes[start+i])) & mask;
        val <<= 8;
        val |= current_byte;
    }
    return val;
}

variable_types:
bytes
char *

variable_types: size int

variable_types:
val
unsigned long


decompiled_code:
__int64 __fastcall bases_match(char a1, int a2, int a3)
{
unsigned int v3; // eax
int v5; // edx

v5 = a1;
if ( a3 <= 0 )
{
v3 = (unsigned int)base_complement;
a2 = base_complement[(char)a2 - 65];
}
else
{
a2 = (char)a2;
}
LOBYTE(v3) = a1 != 78;
LOBYTE(v5) = a1 == a2;
return v5 & v3;
}

canonical_decompiled_code:
__int64 __fastcall func0(char a1, int a2, int a3)
{
unsigned int v3; // eax
int v5; // edx

v5 = a1;
if ( a3 <= 0 )
{
v3 = (unsigned int)base_complement;
a2 = base_complement[(char)a2 - 65];
}
else
{
a2 = (char)a2;
}
LOBYTE(v3) = a1 != 78;
LOBYTE(v5) = a1 == a2;
return v5 & v3;
}

original_code:
extern inline _Bool bases_match(char a, char b, int dir_prod){
    return a == (dir_prod > 0 ? b : base_complement[b-'A']) && a != 'N';
}

variable_types: a char

variable_types: b char


decompiled_code:
void __fastcall kmer_revcomp(_BYTE *a1, __int64 a2, int a3)
{
char *v3; // rax
__int64 v4; // rsi
__int64 v5; // rdx

if ( a3 > 0 )
{
v3 = (char *)(a2 + a3 - 1);
v4 = a2 + a3 - 2 - (unsigned int)(a3 - 1);
do
{
v5 = *v3--;
*a1++ = base_complement[v5 - 65];
}
while ( (char *)v4 != v3 );
}
}

canonical_decompiled_code:
void __fastcall func1(_BYTE *a1, __int64 a2, int a3)
{
char *v3; // rax
__int64 v4; // rsi
__int64 v5; // rdx

if ( a3 > 0 )
{
v3 = (char *)(a2 + a3 - 1);
v4 = a2 + a3 - 2 - (unsigned int)(a3 - 1);
do
{
v5 = *v3--;
*a1++ = base_complement[v5 - 65];
}
while ( (char *)v4 != v3 );
}
}

original_code:
extern inline void kmer_revcomp(char *revcomp, char *kmer, int k){
    for (int i = 0; i < k; i++)
        revcomp[i] = base_complement[kmer[k-i-1]-'A'];
}

variable_types:
revcomp
char *

variable_types:
kmer
char *

variable_types: k int


decompiled_code:
void __fastcall cb_link_to_coarse_free(void *ptr)
{
if ( ptr )
{
cb_link_to_coarse_free(*((void **)ptr + 5));
free(*(void **)ptr);
free(ptr);
}
}

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

original_code:
void cb_link_to_coarse_free(struct cb_link_to_coarse *link){
    if (link != ((void *)0)) {
        cb_link_to_coarse_free(link->next);
        free(link->diff);
        free(link);
    }
}

variable_types: struct cb_link_to_coarse { char *diff; unsigned long coarse_seq_id; unsigned long original_start; unsigned long original_end; unsigned short coarse_start; unsigned short coarse_end; struct cb_link_to_coarse *next; } *


decompiled_code:
void __fastcall cb_link_to_compressed_free(void *ptr)
{
if ( ptr )
{
cb_link_to_compressed_free(*((void **)ptr + 1));
free(*(void **)ptr);
free(ptr);
}
}

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

original_code:
void cb_link_to_compressed_free(struct cb_link_to_compressed *link){
    if (link != ((void *)0)) {
        cb_link_to_compressed_free(link->next);
        free(link->data);
        free(link);
    }
}

variable_types: struct cb_link_to_compressed { struct cb_link_to_compressed_data { _Bool dir; int org_seq_id; short coarse_start; short coarse_end; unsigned long original_start; unsigned long original_end; } *data; struct cb_link_to_compressed *next; } *

user_defined_types: struct cb_link_to_compressed { struct cb_link_to_compressed_data *data; struct cb_link_to_compressed *next; }


decompiled_code:
ssize_t __fastcall send_data(int fd, void *buf, struct sockaddr *addr)
{
size_t v4; // rax
ssize_t result; // rax

v4 = strlen((const char *)buf);
result = sendto(fd, buf, v4 + 1, 0, addr, 0x10u);
if ( (int)result < 0 )
{
perror("Sendto error ");
exit(1);
}
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func8(int fd, void *buf, struct sockaddr *addr)
{
size_t v4; // rax
ssize_t result; // rax

v4 = strlen((const char *)buf);
result = sendto(fd, buf, v4 + 1, 0, addr, 0x10u);
if ( (int)result < 0 )
{
perror("Sendto error ");
exit(1);
}
return result;
}

original_code:
int send_data(int sockfd, const void *buffer, struct sockaddr_in *serv_addr){
 int n;
 if(( n = sendto(sockfd, (char *) buffer, strlen(buffer)+1, 0, (struct sockaddr *) serv_addr, (socklen_t) sizeof(*serv_addr))) < 0 ){
  perror("Sendto error ");
  exit(1);
 }
}

canonical_original_code:
int send_data(int sockfd, void *buffer, struct sockaddr_in *serv_addr){
 int n;
 if(( n = sendto(sockfd, (char *) buffer, strlen(buffer)+1, 0, (struct sockaddr *) serv_addr, (unsigned int) sizeof(*serv_addr))) < 0 ){
  perror("Sendto error ");
  exit(1);
 }
}

variable_types: sockfd int

variable_types:
buffer
void *

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } *

variable_types: n int

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }

user_defined_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }


decompiled_code:
__int64 __fastcall start_connexion(const char *a1, const char *a2, const char *a3, int a4, struct sockaddr *a5)
{
char *v8; // rbp
size_t v9; // rax

v8 = (char *)calloc(1uLL, 0x108uLL);
*v8 = 0;
sprintf(v8, "%s%d", v8, (unsigned int)(strcmp(a1, "WRQ") == 0) + 1);
v9 = strlen(v8);
strcpy(&v8[v9], a2);
sprintf(v8, "%s%d", v8, 0LL);
strcat(v8, a3);
send_data(a4, v8, a5);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(const char *a1, const char *a2, const char *a3, int a4, struct sockaddr *a5)
{
char *v8; // rbp
size_t v9; // rax

v8 = (char *)calloc(1uLL, 0x108uLL);
*v8 = 0;
sprintf(v8, "%s%d", v8, (unsigned int)(strcmp(a1, "WRQ") == 0) + 1);
v9 = strlen(v8);
strcpy(&v8[v9], a2);
sprintf(v8, "%s%d", v8, 0LL);
strcat(v8, a3);
func8(a4, v8, a5);
return 0LL;
}

original_code:
int start_connexion(char *access_type, char *filename, char *mode, int sockfd, struct sockaddr_in *serv_addr){
 char *connexion_msg = calloc(sizeof(char), 264);
 int end = 0;
 short type = 0;
 if(strcmp(access_type, "WRQ") == 0) type++; type++;
 strcpy(connexion_msg, "");
 sprintf(connexion_msg, "%s%d", connexion_msg, type);
 strcat(connexion_msg, filename);
 sprintf(connexion_msg, "%s%d", connexion_msg, end);
 strcat(connexion_msg, mode);
 send_data(sockfd, connexion_msg, serv_addr);
 return 0;
 free(connexion_msg);
}

variable_types:
filename
char *

variable_types:
mode
char *

variable_types: end int

variable_types: type short


decompiled_code:
__int64 __fastcall recv_data(int a1, void *a2, size_t a3, __int64 a4, struct sockaddr *a5)
{
__int64 result; // rax
socklen_t addr_len[3]; // [rsp+Ch] [rbp-Ch] BYREF

addr_len[0] = 16;
LODWORD(result) = recvfrom(a1, a2, a3, 0, a5, addr_len);
if ( (int)result < 0 )
{
perror("Recv error ");
exit(1);
}
result = (int)result;
*((_BYTE *)a2 + (int)result) = 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(int a1, void *a2, size_t a3, __int64 a4, struct sockaddr *a5)
{
__int64 result; // rax
socklen_t addr_len[3]; // [rsp+Ch] [rbp-Ch] BYREF

addr_len[0] = 16;
LODWORD(result) = recvfrom(a1, a2, a3, 0, a5, addr_len);
if ( (int)result < 0 )
{
perror("Recv error ");
exit(1);
}
result = (int)result;
*((_BYTE *)a2 + (int)result) = 0;
return result;
}

original_code:
char *recv_data(int sockfd, char *buffer, size_t len, int flags, struct sockaddr_in *serv_addr){
 int n;
 socklen_t len_addr = sizeof(*serv_addr);
 if((n = recvfrom(sockfd, buffer, len, 0, (struct sockaddr *) serv_addr, &len_addr)) < 0){
  perror("Recv error ");
  exit(1);
 }
 buffer[n] = '\0';
}

canonical_original_code:
char *recv_data(int sockfd, char *buffer, unsigned long len, int flags, struct sockaddr_in *serv_addr){
 int n;
 unsigned int len_addr = sizeof(*serv_addr);
 if((n = recvfrom(sockfd, buffer, len, 0, (struct sockaddr *) serv_addr, &len_addr)) < 0){
  perror("Recv error ");
  exit(1);
 }
 buffer[n] = '\0';
}

variable_types:
buffer
char *

variable_types:
len
unsigned long

variable_types: flags int


decompiled_code:
char *__fastcall read_data_connexion(__int64 a1, const char *a2)
{
unsigned int v2; // eax

v2 = (unsigned int)strrchr(a2, 48);
*(_WORD *)a1 = *a2 - 48;
strcpy((char *)(a1 + 257), &a2[v2 - (_DWORD)a2 + 1]);
a2[strlen(a2) - 6] = 0;
return strcpy((char *)(a1 + 2), a2 + 1);
}

canonical_decompiled_code:
char *__fastcall func11(__int64 a1, const char *a2)
{
unsigned int v2; // eax

v2 = (unsigned int)strrchr(a2, 48);
*(_WORD *)a1 = *a2 - 48;
strcpy((char *)(a1 + 257), &a2[v2 - (_DWORD)a2 + 1]);
a2[strlen(a2) - 6] = 0;
return strcpy((char *)(a1 + 2), a2 + 1);
}

original_code:
int read_data_connexion(request_connexion *data_co, char *buffer){
 int end_index = strrchr(buffer, '0') - buffer;
 data_co->type = ((char) buffer[0])-'0';
 strcpy(data_co->mode, buffer+end_index+1);
 buffer[strlen(buffer)-6] = '\0';
 strcpy(data_co->filename, buffer+1);
}

canonical_original_code:
int read_data_connexion(struct request_connexion *data_co, char *buffer){
 int end_index = strrchr(buffer, '0') - buffer;
 data_co->type = ((char) buffer[0])-'0';
 strcpy(data_co->mode, buffer+end_index+1);
 buffer[strlen(buffer)-6] = '\0';
 strcpy(data_co->filename, buffer+1);
}

variable_types: struct request_connexion { short type; char filename[255]; char mode[6]; } *


decompiled_code:
__int64 __fastcall send_data_with_ACK(const char *a1, __int16 a2, int a3, struct sockaddr *a4)
{
char *v6; // rbp

v6 = (char *)calloc(1uLL, 0x204uLL);
sprintf(v6, "%2d%2d%s", 3LL, (unsigned int)a2, a1);
send_data(a3, v6, a4);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func12(const char *a1, __int16 a2, int a3, struct sockaddr *a4)
{
char *v6; // rbp

v6 = (char *)calloc(1uLL, 0x204uLL);
sprintf(v6, "%2d%2d%s", 3LL, (unsigned int)a2, a1);
func8(a3, v6, a4);
return 0LL;
}

original_code:
int send_data_with_ACK(char *buffer, short num_ACK, int sockfd, struct sockaddr_in *serv_addr){
 char *real_data = calloc(sizeof(char), 516);
 sprintf(real_data, "%2d%2d%s", 3, num_ACK, buffer);
 send_data(sockfd, real_data, serv_addr);
 return 0;
 free(real_data);
}


decompiled_code:
_BOOL8 __fastcall wait_ACK(__int16 a1, int a2, struct sockaddr *a3)
{
void *v4; // rbp

v4 = calloc(1uLL, 3uLL);
recv_data(a2, v4, 2uLL, 0LL, a3);
return a1 != atoi((const char *)v4);
}

canonical_decompiled_code:
_BOOL8 __fastcall func13(__int16 a1, int a2, struct sockaddr *a3)
{
void *v4; // rbp

v4 = calloc(1uLL, 3uLL);
func10(a2, v4, 2uLL, 0LL, a3);
return a1 != atoi((const char *)v4);
}

original_code:
int wait_ACK(short num_ACK_waited, int sockfd, struct sockaddr_in *serv_addr){
 char *num_ACK_received = calloc(sizeof(char), 3);
 recv_data(sockfd, num_ACK_received, 2, 0, serv_addr);
 if(atoi(num_ACK_received) == num_ACK_waited){
  return 0;
  free(num_ACK_received);
 }else{
  return 1;
  free(num_ACK_received);
 }
}


decompiled_code:
__int64 __fastcall send_ACK(__int16 a1, int a2, struct sockaddr *a3)
{
char *v4; // rbp

v4 = (char *)calloc(1uLL, 3uLL);
sprintf(v4, "%d", (unsigned int)a1);
send_data(a2, v4, a3);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int16 a1, int a2, struct sockaddr *a3)
{
char *v4; // rbp

v4 = (char *)calloc(1uLL, 3uLL);
sprintf(v4, "%d", (unsigned int)a1);
func8(a2, v4, a3);
return 0LL;
}

original_code:
int send_ACK(short num_ACK, int sockfd, struct sockaddr_in *serv_addr){
 char *num_ACK_s = calloc(sizeof(char), 3);
 sprintf(num_ACK_s, "%d", num_ACK);
 send_data(sockfd, num_ACK_s, serv_addr);
 return 0;
 free(num_ACK_s);
}


decompiled_code:
__int64 __fastcall read_data_with_ACK(char *dest, int a2, struct sockaddr *a3)
{
char *v4; // rax
char *v5; // r12
__int16 v6; // ax

v4 = (char *)calloc(1uLL, 3uLL);
*dest = 0;
v5 = v4;
recv_data(a2, dest, 0x203uLL, 0LL, a3);
strncpy(v5, dest + 2, 2uLL);
v5[2] = 0;
v6 = atoi(v5);
send_ACK(v6, a2, a3);
strcpy(dest, dest + 4);
free(v5);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func15(char *dest, int a2, struct sockaddr *a3)
{
char *v4; // rax
char *v5; // r12
__int16 v6; // ax

v4 = (char *)calloc(1uLL, 3uLL);
*dest = 0;
v5 = v4;
func10(a2, dest, 0x203uLL, 0LL, a3);
strncpy(v5, dest + 2, 2uLL);
v5[2] = 0;
v6 = atoi(v5);
func14(v6, a2, a3);
strcpy(dest, dest + 4);
free(v5);
return 0LL;
}

original_code:
int read_data_with_ACK(char *buffer, int sockfd, struct sockaddr_in *serv_addr){
 char *num_ACK_s = calloc(sizeof(char), 3);
 strcpy(buffer, "");
 recv_data(sockfd, buffer, 515, 0, serv_addr);
 strncpy(num_ACK_s, buffer+2, 2);
 num_ACK_s[2] = '\0';
 send_ACK(atoi(num_ACK_s), sockfd, serv_addr);
 strcpy(buffer, buffer + 4);
 free(num_ACK_s);
 return 0;
}


multiply

repo: Black--Rabbit/Operating-System

decompiled_code:
unsigned __int64 __fastcall multiply(__int64 a1, __int64 a2)
{
return ((unsigned __int64)(unsigned int)(HIDWORD(a2) * a1 + HIDWORD(a1) * a2) << 32) | (unsigned int)(a1 * a2 - HIDWORD(a1) * HIDWORD(a2));
}

canonical_decompiled_code:
unsigned __int64 __fastcall func0(__int64 a1, __int64 a2)
{
return ((unsigned __int64)(unsigned int)(HIDWORD(a2) * a1 + HIDWORD(a1) * a2) << 32) | (unsigned int)(a1 * a2 - HIDWORD(a1) * HIDWORD(a2));
}

original_code:
cmp_num multiply(cmp_num a, cmp_num b)
 {
  cmp_num result;
  result.real = ((a.real * b.real) - (a.img * b.img));
  result.img = ((a.real * b.img) + (a.img * b.real));
  return result;
 }

canonical_original_code:
struct complex multiply(struct complex a, struct complex b)
 {
  struct complex result;
  result.real = ((a.real * b.real) - (a.img * b.img));
  result.img = ((a.real * b.img) + (a.img * b.real));
  return result;
 }

variable_types:
a
struct complex

variable_types:
b
struct complex

variable_types:
result
struct complex { int real; int img; }

return_type: struct complex { int real; int img; }


decompiled_code:
unsigned __int64 __fastcall multiply_all(_DWORD *a1)
{
unsigned __int64 result; // rax
__int64 v2; // r9

result = multiply(*(_QWORD *)(arr + 16LL * *a1), *(_QWORD *)(arr + 16LL * *a1 + 8));
*(_QWORD *)(::result + 8 * v2) = result;
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func1(_DWORD *a1)
{
unsigned __int64 result; // rax
__int64 v2; // r9

result = func0(*(_QWORD *)(arr + 16LL * *a1), *(_QWORD *)(arr + 16LL * *a1 + 8));
*(_QWORD *)(::result + 8 * v2) = result;
return result;
}

original_code:
void *multiply_all(void *args)
 {
  int *x = (int*)args;
  cmp_num ans = multiply(arr[2 * (*x)], arr[2 * (*x) + 1]);
  result[*x] = ans;
 }

canonical_original_code:
void *multiply_all(void *args)
 {
  int *x = (int*)args;
  struct complex ans = multiply(arr[2 * (*x)], arr[2 * (*x) + 1]);
  result[*x] = ans;
 }

variable_types:
args
void *

variable_types:
x
int *

variable_types:
ans
struct complex { int real; int img; }


decompiled_code:
_BOOL8 __fastcall is_palindrome(int a1)
{
int v1; // edx
int v2; // ecx

if ( !a1 )
return 1LL;
v1 = a1;
v2 = 0;
do
{
v2 = v1 % 10 + 10 * v2;
v1 /= 10;
}
while ( v1 );
return a1 == v2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(int a1)
{
int v1; // edx
int v2; // ecx

if ( !a1 )
return 1LL;
v1 = a1;
v2 = 0;
do
{
v2 = v1 % 10 + 10 * v2;
v1 /= 10;
}
while ( v1 );
return a1 == v2;
}

original_code:
int is_palindrome (int num)
 {
  int temp = num;
  int rev = 0;
  while (num)
  {
   rev *= 10;
   rev += (num % 10);
   num /= 10;
  }
  if (temp == rev)
   return 1;
  return 0;
 }

canonical_original_code:
int is_palindrome(int num)
 {
  int temp = num;
  int rev = 0;
  while (num)
  {
   rev *= 10;
   rev += (num % 10);
   num /= 10;
  }
  if (temp == rev)
   return 1;
  return 0;
 }

variable_types: num int

variable_types: temp int

variable_types: rev int


original_code:
int is_colourfull (int num)
 {
  int nr_dig = 0;
  int temp = num;
  while (temp)
  {
   temp /= 10;
   nr_dig ++;
  }
  int arr_digits[nr_dig];
  temp = num;
  int i = nr_dig - 1;
  for (; i >= 0; i--)
  {
   arr_digits[i] = (temp % 10);
   temp /= 10;
  }
  int **substring = (int**)malloc(sizeof(int*) * nr_dig);
  for (i = 0; i < nr_dig; i++)
  {
   substring[i] = (int*)malloc(sizeof(int) * (nr_dig - i));
   int j;
   for( j =0 ; j < nr_dig - i ; j++)
   {
    substring[i][j] = 1;
    int k;
    for( k =0 ; k<i+1; k++)
    {
     substring[i][j] = substring[i][j] * arr_digits[j+k];
    }
   }
  }
  for (i = 0; i < nr_dig; i++)
  {
   int j = 0;
   for (; j < (nr_dig - i); j++)
   {
    int temp = substring[i][j];
    int i1,j1;
    for (i1 = 0; i1 < nr_dig; i1++)
     for (j1 = 0; j1 < (nr_dig - i1); j1++)
      if (temp == substring[i1][j1])
       if(i == i1 && j == j1)
        continue;
       else
        return 0;
   }
  }
  return 1;
 }

canonical_original_code:
int is_colourfull(int num)
 {
  int nr_dig = 0;
  int temp = num;
  while (temp)
  {
   temp /= 10;
   nr_dig ++;
  }
  int arr_digits[-1];
  temp = num;
  int i = nr_dig - 1;
  for (; i >= 0; i--)
  {
   arr_digits[i] = (temp % 10);
   temp /= 10;
  }
  int **substring = (int**)malloc(sizeof(int*) * nr_dig);
  for (i = 0; i < nr_dig; i++)
  {
   substring[i] = (int *)malloc(sizeof(int) * (nr_dig - i));
   int j;
   for( j =0 ; j < nr_dig - i ; j++)
   {
    substring[i][j] = 1;
    int k;
    for( k =0 ; k<i+1; k++)
    {
     substring[i][j] = substring[i][j] * arr_digits[j+k];
    }
   }
  }
  for (i = 0; i < nr_dig; i++)
  {
   int j = 0;
   for (; j < (nr_dig - i); j++)
   {
    int temp = substring[i][j];
    int i1; int j1;
    for (i1 = 0; i1 < nr_dig; i1++)
     for (j1 = 0; j1 < (nr_dig - i1); j1++)
      if (temp == substring[i1][j1])
       if(i == i1 && j == j1)
        continue;
       else
        return 0;
   }
  }
  return 1;
 }

variable_types: i int

variable_types:
substring
int **

variable_types: j int

variable_types: k int


findPath

decompiled_code:
void __fastcall __noreturn findPath(__int64 a1, unsigned int a2, unsigned int a3, int a4)
{
__int64 v4; // rbp
__int64 v6; // rbx
unsigned int v7; // er13
int v8; // ebx
__int64 v9; // rdx
__int64 v10; // rsi
__int64 v11; // [rsp+10h] [rbp-58h]
unsigned int v12; // [rsp+1Ch] [rbp-4Ch]
__WAIT_STATUS stat_loc; // [rsp+28h] [rbp-40h] BYREF

v4 = a4;
v6 = 8LL * (int)a3;
if ( *(_DWORD *)(*(_QWORD *)(a1 + v6) + 4LL * a4) != 1 )
{
stat_loc.__uptr = 0LL;
if ( a4 + 1 < (int)a2 )
{
v12 = a4 + 1;
v11 = 4LL * a4;
if ( !fork() )
{
if ( *(_DWORD *)(*(_QWORD *)(a1 + v6) + v11 + 4) != 2 )
findPath(a1, a2, a3, v12);
v9 = v12;
v10 = a3;
goto LABEL_19;
}
}
v7 = a3 + 1;
if ( (int)(a3 + 1) < (int)a2 && !fork() )
{
if ( *(_DWORD *)(*(_QWORD *)(a1 + v6 + 8) + 4 * v4) != 2 )
findPath(a1, a2, v7, (unsigned int)v4);
v9 = (unsigned int)v4;
v10 = v7;
LABEL_19:
printf("(%d, %d) ", v10, v9);
goto LABEL_14;
}
wait((__WAIT_STATUS)&stat_loc);
v8 = v4 | a3;
wait((__WAIT_STATUS)((char *)&stat_loc.__iptr + 4));
if ( (unsigned int)(LODWORD(stat_loc.__uptr) - 512) <= 0xFF
|| (unsigned int)(HIDWORD(stat_loc.__iptr) - 512) <= 0xFF )
{
printf("(%d, %d) ", a3, (unsigned int)v4);
if ( !v8 )
puts("MJ successfully rescued.");
LABEL_14:
exit(2);
}
if ( !v8 )
puts("Spiderman cannot rescue MJ.");
}
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func7(__int64 a1, unsigned int a2, unsigned int a3, int a4)
{
__int64 v4; // rbp
__int64 v6; // rbx
unsigned int v7; // er13
int v8; // ebx
__int64 v9; // rdx
__int64 v10; // rsi
__int64 v11; // [rsp+10h] [rbp-58h]
unsigned int v12; // [rsp+1Ch] [rbp-4Ch]
__WAIT_STATUS stat_loc; // [rsp+28h] [rbp-40h] BYREF

v4 = a4;
v6 = 8LL * (int)a3;
if ( *(_DWORD *)(*(_QWORD *)(a1 + v6) + 4LL * a4) != 1 )
{
stat_loc.__uptr = 0LL;
if ( a4 + 1 < (int)a2 )
{
v12 = a4 + 1;
v11 = 4LL * a4;
if ( !fork() )
{
if ( *(_DWORD *)(*(_QWORD *)(a1 + v6) + v11 + 4) != 2 )
func7(a1, a2, a3, v12);
v9 = v12;
v10 = a3;
goto LABEL_19;
}
}
v7 = a3 + 1;
if ( (int)(a3 + 1) < (int)a2 && !fork() )
{
if ( *(_DWORD *)(*(_QWORD *)(a1 + v6 + 8) + 4 * v4) != 2 )
func7(a1, a2, v7, (unsigned int)v4);
v9 = (unsigned int)v4;
v10 = v7;
LABEL_19:
printf("(%d, %d) ", v10, v9);
goto LABEL_14;
}
wait((__WAIT_STATUS)&stat_loc);
v8 = v4 | a3;
wait((__WAIT_STATUS)((char *)&stat_loc.__iptr + 4));
if ( (unsigned int)(LODWORD(stat_loc.__uptr) - 512) <= 0xFF
|| (unsigned int)(HIDWORD(stat_loc.__iptr) - 512) <= 0xFF )
{
printf("(%d, %d) ", a3, (unsigned int)v4);
if ( !v8 )
puts("MJ successfully rescued.");
LABEL_14:
exit(2);
}
if ( !v8 )
puts("Spiderman cannot rescue MJ.");
}
exit(1);
}

original_code:
void findPath (int **arr, int n, int i, int j)
 {
  if (arr[i][j] == 1)
   exit (1);
  int status_1 = 0;
  int status_2 = 0;
  pid_t right, down;
  if ((j + 1) < n)
  {
   right = fork();
   if (!right)
   {
    j++;
    if (arr[i][j] != 2)
     findPath (arr, n, i, j);
    else
           {
          printf ("(%d, %d) ", i, j);
          exit(2);
           }
   }
  }
  if ((i + 1) < n)
  {
   down = fork();
   if (!down)
   {
    i++;
    if (arr[i][j] != 2)
     findPath (arr, n, i, j);
    else
    {
          printf ("(%d, %d) ", i, j);
          exit(2);
    }
   }
  }
  wait (&status_1);
  wait (&status_2);
  if ((status_1/256) == 2 || (status_2/256) == 2)
  {
   printf ("(%d, %d) ", i, j);
   if (i == 0 && j == 0)
    printf ("MJ successfully rescued.\n");
   exit (2);
  }
  else
  {
   if (i == 0 && j == 0)
    printf ("Spiderman cannot rescue MJ.\n");
   exit (1);
  }
 }

canonical_original_code:
void findPath(int **arr, int n, int i, int j)
 {
  if (arr[i][j] == 1)
   exit (1);
  int status_1 = 0;
  int status_2 = 0;
  int right; int down;
  if ((j + 1) < n)
  {
   right = fork();
   if (!right)
   {
    j++;
    if (arr[i][j] != 2)
     findPath (arr, n, i, j);
    else
           {
          printf ("(%d, %d) ", i, j);
          exit(2);
           }
   }
  }
  if ((i + 1) < n)
  {
   down = fork();
   if (!down)
   {
    i++;
    if (arr[i][j] != 2)
     findPath (arr, n, i, j);
    else
    {
          printf ("(%d, %d) ", i, j);
          exit(2);
    }
   }
  }
  wait (&status_1);
  wait (&status_2);
  if ((status_1/256) == 2 || (status_2/256) == 2)
  {
   printf ("(%d, %d) ", i, j);
   if (i == 0 && j == 0)
    printf ("MJ successfully rescued.\n");
   exit (2);
  }
  else
  {
   if (i == 0 && j == 0)
    printf ("Spiderman cannot rescue MJ.\n");
   exit (1);
  }
 }

variable_types:
arr
int **

variable_types: n int

variable_types: right int

variable_types: down int


decompiled_code:
_BOOL8 __fastcall check_date(char *nptr, char *a2)
{
int v2; // ebx
int v3; // er8
_BOOL8 result; // rax
int v5; // ebx
int v6; // er8
int v7; // ebx

v2 = atoi(nptr + 6);
v3 = atoi(a2 + 6);
result = 0LL;
if ( v2 >= v3 )
{
result = 1LL;
if ( v2 <= v3 )
{
v5 = atoi(nptr + 3);
v6 = atoi(a2 + 3);
result = 0LL;
if ( v5 >= v6 )
{
result = 1LL;
if ( v5 <= v6 )
{
v7 = atoi(nptr);
result = v7 >= atoi(a2);
}
}
}
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(char *nptr, char *a2)
{
int v2; // ebx
int v3; // er8
_BOOL8 result; // rax
int v5; // ebx
int v6; // er8
int v7; // ebx

v2 = atoi(nptr + 6);
v3 = atoi(a2 + 6);
result = 0LL;
if ( v2 >= v3 )
{
result = 1LL;
if ( v2 <= v3 )
{
v5 = atoi(nptr + 3);
v6 = atoi(a2 + 3);
result = 0LL;
if ( v5 >= v6 )
{
result = 1LL;
if ( v5 <= v6 )
{
v7 = atoi(nptr);
result = v7 >= atoi(a2);
}
}
}
}
return result;
}

original_code:
int check_date (char *date1, char *date2)
 {
  int yy1 = atoi (date1 + 6);
  int yy2 = atoi (date2 + 6);
  if (yy1 < yy2)
   return 0;
  if (yy1 > yy2)
   return 1;
  int mm1 = atoi (date1 + 3);
  int mm2 = atoi (date2 + 3);
  if (mm1 < mm2)
   return 0;
  if (mm1 > mm2)
   return 1;
  int dd1 = atoi (date1);
  int dd2 = atoi (date2);
  if (dd1 < dd2)
   return 0;
  return 1;
 }

canonical_original_code:
int check_date(char *date1, char *date2)
 {
  int yy1 = atoi (date1 + 6);
  int yy2 = atoi (date2 + 6);
  if (yy1 < yy2)
   return 0;
  if (yy1 > yy2)
   return 1;
  int mm1 = atoi (date1 + 3);
  int mm2 = atoi (date2 + 3);
  if (mm1 < mm2)
   return 0;
  if (mm1 > mm2)
   return 1;
  int dd1 = atoi (date1);
  int dd2 = atoi (date2);
  if (dd1 < dd2)
   return 0;
  return 1;
 }


initBuf

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

*(_DWORD *)a1 = a2;
*(_DWORD *)(a1 + 4) = 0;
result = malloc(8LL * a2);
*(_QWORD *)(a1 + 8) = result;
return result;
}

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

*(_DWORD *)a1 = a2;
*(_DWORD *)(a1 + 4) = 0;
result = malloc(8LL * a2);
*(_QWORD *)(a1 + 8) = result;
return result;
}

original_code:
void initBuf(voidBuf* buf, int capa){
    buf->capa = capa;
    buf->nbElement = 0;
    buf->buffer = (void **)malloc(capa*sizeof(void*));
}

canonical_original_code:
void initBuf(struct voidBuf *buf, int capa){
    buf->capa = capa;
    buf->nbElement = 0;
    buf->buffer = (void **)malloc(capa*sizeof(void *));
}

variable_types: struct voidBuf { int capa; int nbElement; void **buffer; } *

variable_types: capa int


appendBuf

decompiled_code:
__int64 __fastcall appendBuf(void **a1, __int64 a2)
{
signed int v2; // eax
__int64 v3; // rcx
__int64 result; // rax
void *v5; // rax

printf("buffer total: %d %d\n", *((unsigned int *)a1 + 1), *(unsigned int *)a1);
v2 = *((_DWORD *)a1 + 1);
if ( v2 >= *(_DWORD *)a1 )
{
v5 = realloc(a1[1], 8LL * (*(_DWORD *)a1 + 1));
++*(_DWORD *)a1;
a1[1] = v5;
puts("buffer reallouer");
v2 = *((_DWORD *)a1 + 1);
}
v3 = v2;
result = (unsigned int)(v2 + 1);
*((_QWORD *)a1[1] + v3) = a2;
*((_DWORD *)a1 + 1) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(void **a1, __int64 a2)
{
signed int v2; // eax
__int64 v3; // rcx
__int64 result; // rax
void *v5; // rax

printf("buffer total: %d %d\n", *((unsigned int *)a1 + 1), *(unsigned int *)a1);
v2 = *((_DWORD *)a1 + 1);
if ( v2 >= *(_DWORD *)a1 )
{
v5 = realloc(a1[1], 8LL * (*(_DWORD *)a1 + 1));
++*(_DWORD *)a1;
a1[1] = v5;
puts("buffer reallouer");
v2 = *((_DWORD *)a1 + 1);
}
v3 = v2;
result = (unsigned int)(v2 + 1);
*((_QWORD *)a1[1] + v3) = a2;
*((_DWORD *)a1 + 1) = result;
return result;
}

original_code:
void appendBuf(voidBuf* buf, void* s){
    printf("buffer total: %d %d\n",buf->nbElement, buf->capa);
    if(buf->nbElement+1 > buf->capa){
        buf->buffer = (void **)realloc(buf->buffer, (buf->capa+1)*sizeof(void*));
        buf->capa = buf->capa+1;
        printf("buffer reallouer\n");
    }
    buf->buffer[buf->nbElement] = s;
    buf->nbElement = buf->nbElement+1;
}

canonical_original_code:
void appendBuf(struct voidBuf *buf, void *s){
    printf("buffer total: %d %d\n",buf->nbElement, buf->capa);
    if(buf->nbElement+1 > buf->capa){
        buf->buffer = (void **)realloc(buf->buffer, (buf->capa+1)*sizeof(void *));
        buf->capa = buf->capa+1;
        printf("buffer reallouer\n");
    }
    buf->buffer[buf->nbElement] = s;
    buf->nbElement = buf->nbElement+1;
}

variable_types:
s
void *

user_defined_types: struct voidBuf { int capa; int nbElement; void **buffer; }


readBuf

decompiled_code:
__int64 __fastcall readBuf(__int64 a1, int a2)
{
return *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * a2);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int a2)
{
return *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * a2);
}

original_code:
void* readBuf(voidBuf* buf, int pos){
    return buf->buffer[pos];
}

canonical_original_code:
void *readBuf(struct voidBuf *buf, int pos){
    return buf->buffer[pos];
}

variable_types: pos int


printVoidBuf

decompiled_code:
int __fastcall printVoidBuf(__int64 a1)
{
int result; // eax
__int64 v2; // rbx
__int64 v3; // rsi

result = *(_DWORD *)(a1 + 4);
if ( result > 0 )
{
v2 = 0LL;
do
{
v3 = *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8 * v2++);
result = printf("buf %d\n", v3);
}
while ( *(_DWORD *)(a1 + 4) > (int)v2 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1)
{
int result; // eax
__int64 v2; // rbx
__int64 v3; // rsi

result = *(_DWORD *)(a1 + 4);
if ( result > 0 )
{
v2 = 0LL;
do
{
v3 = *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8 * v2++);
result = printf("buf %d\n", v3);
}
while ( *(_DWORD *)(a1 + 4) > (int)v2 );
}
return result;
}

original_code:
void printVoidBuf(voidBuf* buf){
    int i;
    for(i=0 ; i < buf->nbElement ; i++)
        printf("buf %d\n",(int)buf->buffer[i]);
}

canonical_original_code:
void printVoidBuf(struct voidBuf *buf){
    int i;
    for(i=0 ; i < buf->nbElement ; i++)
        printf("buf %d\n",(int)buf->buffer[i]);
}


libererBuf

decompiled_code:
void __fastcall libererBuf(__int64 a1)
{
free(*(void **)(a1 + 8));
}

canonical_decompiled_code:
void __fastcall func4(__int64 a1)
{
free(*(void **)(a1 + 8));
}

original_code:
void libererBuf(voidBuf* buf){
     free(buf->buffer);
}

canonical_original_code:
void libererBuf(struct voidBuf *buf){
     free(buf->buffer);
}


initAnneau

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

pthread_cond_init(&cond_anneauATourner, 0LL);
pthread_cond_init(&cond_anneauAttenteAcces, 0LL);
pthread_mutex_init(&mutex_anneau, 0LL);
result = 0LL;
nbElementDansBuffer = 0;
memset(&bufferAnneau, 0, 0x80uLL);
bufComposantOuProduit[0] = 0LL;
nbElementQuiAccedeAnneau = 0;
continuerAnneau = 1;
bufComposantOuProduit[1] = 0LL;
bufComposantOuProduit[2] = 0LL;
bufComposantOuProduit[3] = 0LL;
return result;
}

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

pthread_cond_init(&cond_anneauATourner, 0LL);
pthread_cond_init(&cond_anneauAttenteAcces, 0LL);
pthread_mutex_init(&mutex_anneau, 0LL);
result = 0LL;
nbElementDansBuffer = 0;
memset(&bufferAnneau, 0, 0x80uLL);
bufComposantOuProduit[0] = 0LL;
nbElementQuiAccedeAnneau = 0;
continuerAnneau = 1;
bufComposantOuProduit[1] = 0LL;
bufComposantOuProduit[2] = 0LL;
bufComposantOuProduit[3] = 0LL;
return result;
}

original_code:
void initAnneau(){
    pthread_cond_init(&cond_anneauATourner, ((void *)0));
    pthread_cond_init(&cond_anneauAttenteAcces, ((void *)0));
 pthread_mutex_init(&mutex_anneau,((void *)0));
    int i;
    for(i=0;i<16;i++){
        bufComposantOuProduit[i] = 0;
        bufferAnneau[i] = ((void *)0);
    }
    nbElementDansBuffer = 0;
    nbElementQuiAccedeAnneau = 0;
    continuerAnneau = 1;
}


decompiled_code:
int th_tournerAnneau()
{
int v0; // ebp
__int64 v1; // rbx

while ( continuerAnneau == 1 )
{
pthread_mutex_lock(&mutex_anneau);
while ( nbElementQuiAccedeAnneau )
{
puts("Anneau mis en attente");
pthread_cond_wait(&cond_anneauAttenteAcces, &mutex_anneau);
}
v0 = HIDWORD(bufComposantOuProduit[3]);
v1 = bufferAnneau[15];
memmove((void *)(unsigned int)((_DWORD)bufComposantOuProduit + 4), bufComposantOuProduit, 0x3CuLL);
memmove((void *)(unsigned int)((_DWORD)bufferAnneau + 8), bufferAnneau, 0x78uLL);
LODWORD(bufComposantOuProduit[0]) = v0;
bufferAnneau[0] = v1;
pthread_cond_broadcast(&cond_anneauATourner);
pthread_mutex_unlock(&mutex_anneau);
}
return puts("Thread Anneau terminer");
}

canonical_decompiled_code:
int func1()
{
int v0; // ebp
__int64 v1; // rbx

while ( continuerAnneau == 1 )
{
pthread_mutex_lock(&mutex_anneau);
while ( nbElementQuiAccedeAnneau )
{
puts("Anneau mis en attente");
pthread_cond_wait(&cond_anneauAttenteAcces, &mutex_anneau);
}
v0 = HIDWORD(bufComposantOuProduit[3]);
v1 = bufferAnneau[15];
memmove((void *)(unsigned int)((_DWORD)bufComposantOuProduit + 4), bufComposantOuProduit, 0x3CuLL);
memmove((void *)(unsigned int)((_DWORD)bufferAnneau + 8), bufferAnneau, 0x78uLL);
LODWORD(bufComposantOuProduit[0]) = v0;
bufferAnneau[0] = v1;
pthread_cond_broadcast(&cond_anneauATourner);
pthread_mutex_unlock(&mutex_anneau);
}
return puts("Thread Anneau terminer");
}

original_code:
void th_tournerAnneau(){
    while(continuerAnneau == 1){
        pthread_mutex_lock(&mutex_anneau);
        while(nbElementQuiAccedeAnneau != 0){
            printf("Anneau mis en attente\n");
            pthread_cond_wait(&cond_anneauAttenteAcces, &mutex_anneau);
        }
        int i;
        int tmp = bufComposantOuProduit[16 -1];
        void* tmp2 = bufferAnneau[16 -1];
        for(i=16 -1;i>0;i--){
            bufComposantOuProduit[i] = bufComposantOuProduit[i-1];
            bufferAnneau[i] = bufferAnneau[i-1];
        }
        bufComposantOuProduit[0] = tmp;
        bufferAnneau[0] = tmp2;
        pthread_cond_broadcast(&cond_anneauATourner);
        pthread_mutex_unlock(&mutex_anneau);
    }
    printf("Thread Anneau terminer\n");
}

canonical_original_code:
void th_tournerAnneau(){
    while(continuerAnneau == 1){
        pthread_mutex_lock(&mutex_anneau);
        while(nbElementQuiAccedeAnneau != 0){
            printf("Anneau mis en attente\n");
            pthread_cond_wait(&cond_anneauAttenteAcces, &mutex_anneau);
        }
        int i;
        int tmp = bufComposantOuProduit[16 -1];
        void *tmp2 = bufferAnneau[16 -1];
        for(i=16 -1;i>0;i--){
            bufComposantOuProduit[i] = bufComposantOuProduit[i-1];
            bufferAnneau[i] = bufferAnneau[i-1];
        }
        bufComposantOuProduit[0] = tmp;
        bufferAnneau[0] = tmp2;
        pthread_cond_broadcast(&cond_anneauATourner);
        pthread_mutex_unlock(&mutex_anneau);
    }
    printf("Thread Anneau terminer\n");
}

variable_types: tmp int


isPostionBufLibre

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

pthread_mutex_lock(&mutex_anneau);
v1 = bufComposantOuProduit[a1];
++nbElementQuiAccedeAnneau;
if ( v1 )
{
puts("Pos non libre");
--nbElementQuiAccedeAnneau;
pthread_cond_signal(&cond_anneauAttenteAcces);
pthread_mutex_unlock(&mutex_anneau);
result = 0LL;
}
else
{
puts("Pos libre");
--nbElementQuiAccedeAnneau;
pthread_mutex_unlock(&mutex_anneau);
result = 1LL;
}
return result;
}

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

pthread_mutex_lock(&mutex_anneau);
v1 = bufComposantOuProduit[a1];
++nbElementQuiAccedeAnneau;
if ( v1 )
{
puts("Pos non libre");
--nbElementQuiAccedeAnneau;
pthread_cond_signal(&cond_anneauAttenteAcces);
pthread_mutex_unlock(&mutex_anneau);
result = 0LL;
}
else
{
puts("Pos libre");
--nbElementQuiAccedeAnneau;
pthread_mutex_unlock(&mutex_anneau);
result = 1LL;
}
return result;
}

original_code:
int isPostionBufLibre(int pos){
    pthread_mutex_lock(&mutex_anneau);
    nbElementQuiAccedeAnneau++;
    if(bufComposantOuProduit[pos] == 0){
        printf("Pos libre\n");
        nbElementQuiAccedeAnneau--;
        pthread_mutex_unlock(&mutex_anneau);
        return 1;
    }
    printf("Pos non libre\n");
    nbElementQuiAccedeAnneau--;
    pthread_cond_signal(&cond_anneauAttenteAcces);
    pthread_mutex_unlock(&mutex_anneau);
    return 0;
}


getPositionType

decompiled_code:
__int64 __fastcall getPositionType(int a1)
{
unsigned int v1; // er12

pthread_mutex_lock(&mutex_anneau);
v1 = bufComposantOuProduit[a1];
pthread_mutex_unlock(&mutex_anneau);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
unsigned int v1; // er12

pthread_mutex_lock(&mutex_anneau);
v1 = bufComposantOuProduit[a1];
pthread_mutex_unlock(&mutex_anneau);
return v1;
}

original_code:
int getPositionType(int pos){
    pthread_mutex_lock(&mutex_anneau);
    nbElementQuiAccedeAnneau++;
    int ret = bufComposantOuProduit[pos];
    nbElementQuiAccedeAnneau--;
    pthread_mutex_unlock(&mutex_anneau);
    return ret;
}

variable_types: ret int


getPositionDuRobot

decompiled_code:
__int64 __fastcall getPositionDuRobot(int a1)
{
__int64 v1; // rdi

v1 = (unsigned int)(a1 - 1);
if ( (unsigned int)v1 <= 5 )
return (unsigned int)CSWTCH_22[v1];
puts("Erreur position du robot avec numRobot");
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1)
{
__int64 v1; // rdi

v1 = (unsigned int)(a1 - 1);
if ( (unsigned int)v1 <= 5 )
return (unsigned int)CSWTCH_22[v1];
puts("Erreur position du robot avec numRobot");
return 0xFFFFFFFFLL;
}

original_code:
int getPositionDuRobot(int numRobot){
    switch (numRobot) {
        case 1:
            return 5;
            break;
        case 2:
            return 7;
            break;
        case 3:
            return 9;
            break;
        case 4:
            return 11;
            break;
        case 5:
            return 12;
            break;
        case 6:
            return 14;
            break;
        default:
            printf("Erreur position du robot avec numRobot\n");
            return -1;
            break;
    }
}

variable_types: numRobot int


getPointeur

decompiled_code:
__int64 __fastcall getPointeur(int a1)
{
__int64 v1; // r12

pthread_mutex_lock(&mutex_anneau);
v1 = bufferAnneau[a1];
pthread_mutex_unlock(&mutex_anneau);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1)
{
__int64 v1; // r12

pthread_mutex_lock(&mutex_anneau);
v1 = bufferAnneau[a1];
pthread_mutex_unlock(&mutex_anneau);
return v1;
}

original_code:
void* getPointeur(int pos){
    pthread_mutex_lock(&mutex_anneau);
    nbElementQuiAccedeAnneau++;
    void* ret = bufferAnneau[pos];
    nbElementQuiAccedeAnneau--;
    pthread_mutex_unlock(&mutex_anneau);
    return ret;
}

canonical_original_code:
void *getPointeur(int pos){
    pthread_mutex_lock(&mutex_anneau);
    nbElementQuiAccedeAnneau++;
    void *ret = bufferAnneau[pos];
    nbElementQuiAccedeAnneau--;
    pthread_mutex_unlock(&mutex_anneau);
    return ret;
}

variable_types:
ret
void *


prendreElement

decompiled_code:
__int64 __fastcall prendreElement(int a1)
{
__int64 v1; // r12

pthread_mutex_lock(&mutex_anneau);
--nbElementDansBuffer;
v1 = bufferAnneau[a1];
bufComposantOuProduit[a1] = 0;
bufferAnneau[a1] = 0LL;
pthread_cond_signal(&cond_anneauAttenteAcces);
pthread_mutex_unlock(&mutex_anneau);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1)
{
__int64 v1; // r12

pthread_mutex_lock(&mutex_anneau);
--nbElementDansBuffer;
v1 = bufferAnneau[a1];
bufComposantOuProduit[a1] = 0;
bufferAnneau[a1] = 0LL;
pthread_cond_signal(&cond_anneauAttenteAcces);
pthread_mutex_unlock(&mutex_anneau);
return v1;
}

original_code:
void* prendreElement(int positionBuffer){
    pthread_mutex_lock(&mutex_anneau);
    nbElementQuiAccedeAnneau++;
    void* elem = bufferAnneau[positionBuffer];
    nbElementDansBuffer--;
    bufComposantOuProduit[positionBuffer] = 0;
    bufferAnneau[positionBuffer] = ((void *)0);
    nbElementQuiAccedeAnneau--;
    pthread_cond_signal(&cond_anneauAttenteAcces);
    pthread_mutex_unlock(&mutex_anneau);
    return elem;
}

canonical_original_code:
void *prendreElement(int positionBuffer){
    pthread_mutex_lock(&mutex_anneau);
    nbElementQuiAccedeAnneau++;
    void *elem = bufferAnneau[positionBuffer];
    nbElementDansBuffer--;
    bufComposantOuProduit[positionBuffer] = 0;
    bufferAnneau[positionBuffer] = ((void *)0);
    nbElementQuiAccedeAnneau--;
    pthread_cond_signal(&cond_anneauAttenteAcces);
    pthread_mutex_unlock(&mutex_anneau);
    return elem;
}

variable_types: positionBuffer int

variable_types:
elem
void *


ajouterElement

decompiled_code:
int __fastcall ajouterElement(__int64 a1, int a2, int a3)
{
pthread_mutex_lock(&mutex_anneau);
++nbElementDansBuffer;
if ( a3 == 50 )
{
bufComposantOuProduit[a2] = 50;
}
else if ( a3 == 51 )
{
bufComposantOuProduit[a2] = 51;
}
bufferAnneau[a2] = a1;
pthread_cond_signal(&cond_anneauAttenteAcces);
return pthread_mutex_unlock(&mutex_anneau);
}

canonical_decompiled_code:
int __fastcall func7(__int64 a1, int a2, int a3)
{
pthread_mutex_lock(&mutex_anneau);
++nbElementDansBuffer;
if ( a3 == 50 )
{
bufComposantOuProduit[a2] = 50;
}
else if ( a3 == 51 )
{
bufComposantOuProduit[a2] = 51;
}
bufferAnneau[a2] = a1;
pthread_cond_signal(&cond_anneauAttenteAcces);
return pthread_mutex_unlock(&mutex_anneau);
}

original_code:
void ajouterElement(void *elem,int positionBuffer,int type){
    pthread_mutex_lock(&mutex_anneau);
    nbElementQuiAccedeAnneau++;
    nbElementDansBuffer++;
    switch(type){
        case 50:
            bufComposantOuProduit[positionBuffer] = 50;
            break;
        case 51:
            bufComposantOuProduit[positionBuffer] = 51;
            break;
    }
    bufferAnneau[positionBuffer] = elem;
    nbElementQuiAccedeAnneau--;
    pthread_cond_signal(&cond_anneauAttenteAcces);
    pthread_mutex_unlock(&mutex_anneau);
}

canonical_original_code:
void ajouterElement(void *elem, int positionBuffer, int type){
    pthread_mutex_lock(&mutex_anneau);
    nbElementQuiAccedeAnneau++;
    nbElementDansBuffer++;
    switch(type){
        case 50:
            bufComposantOuProduit[positionBuffer] = 50;
            break;
        case 51:
            bufComposantOuProduit[positionBuffer] = 51;
            break;
    }
    bufferAnneau[positionBuffer] = elem;
    nbElementQuiAccedeAnneau--;
    pthread_cond_signal(&cond_anneauAttenteAcces);
    pthread_mutex_unlock(&mutex_anneau);
}

variable_types: type int


printAnneau

decompiled_code:
int printAnneau()
{
__int64 v0; // rbx
int v1; // eax
__int64 v2; // rsi
__int64 v3; // rdx

v0 = 0LL;
pthread_mutex_lock(&mutex_anneau);
++nbElementQuiAccedeAnneau;
do
{
while ( 1 )
{
v1 = bufComposantOuProduit[v0];
if ( v1 == 50 )
{
printf("prod%d i=%d \n", *(unsigned int *)bufferAnneau[v0], (unsigned int)v0);
goto LABEL_3;
}
if ( v1 == 51 )
break;
printf("rien i=%d \n", (unsigned int)v0);
LABEL_3:
if ( ++v0 == 16 )
goto LABEL_7;
}
v2 = LODWORD(bufferAnneau[v0]);
v3 = (unsigned int)v0++;
printf("comp%d i=%d \n", v2, v3);
}
while ( v0 != 16 );
LABEL_7:
putchar(10);
--nbElementQuiAccedeAnneau;
pthread_cond_signal(&cond_anneauAttenteAcces);
return pthread_mutex_unlock(&mutex_anneau);
}

canonical_decompiled_code:
int func8()
{
__int64 v0; // rbx
int v1; // eax
__int64 v2; // rsi
__int64 v3; // rdx

v0 = 0LL;
pthread_mutex_lock(&mutex_anneau);
++nbElementQuiAccedeAnneau;
do
{
while ( 1 )
{
v1 = bufComposantOuProduit[v0];
if ( v1 == 50 )
{
printf("prod%d i=%d \n", *(unsigned int *)bufferAnneau[v0], (unsigned int)v0);
goto LABEL_3;
}
if ( v1 == 51 )
break;
printf("rien i=%d \n", (unsigned int)v0);
LABEL_3:
if ( ++v0 == 16 )
goto LABEL_7;
}
v2 = LODWORD(bufferAnneau[v0]);
v3 = (unsigned int)v0++;
printf("comp%d i=%d \n", v2, v3);
}
while ( v0 != 16 );
LABEL_7:
putchar(10);
--nbElementQuiAccedeAnneau;
pthread_cond_signal(&cond_anneauAttenteAcces);
return pthread_mutex_unlock(&mutex_anneau);
}

original_code:
void printAnneau(){
    pthread_mutex_lock(&mutex_anneau);
    nbElementQuiAccedeAnneau++;
    int i;
    for(i=0;i<16;i++){
        if(bufComposantOuProduit[i] == 50)
            printf("prod%d i=%d \n",((produit*)bufferAnneau[i])->numProduit,i);
        else if(bufComposantOuProduit[i] == 51)
            printf("comp%d i=%d \n",(int)bufferAnneau[i],i);
        else
            printf("rien i=%d \n",i);
    }
    printf("\n");
    nbElementQuiAccedeAnneau--;
    pthread_cond_signal(&cond_anneauAttenteAcces);
    pthread_mutex_unlock(&mutex_anneau);
}

canonical_original_code:
void printAnneau(){
    pthread_mutex_lock(&mutex_anneau);
    nbElementQuiAccedeAnneau++;
    int i;
    for(i=0;i<16;i++){
        if(bufComposantOuProduit[i] == 50)
            printf("prod%d i=%d \n",((struct _produit *)bufferAnneau[i])->numProduit,i);
        else if(bufComposantOuProduit[i] == 51)
            printf("comp%d i=%d \n",(int)bufferAnneau[i],i);
        else
            printf("rien i=%d \n",i);
    }
    printf("\n");
    nbElementQuiAccedeAnneau--;
    pthread_cond_signal(&cond_anneauAttenteAcces);
    pthread_mutex_unlock(&mutex_anneau);
}

variable_types: i int

user_defined_types: struct _produit { int numProduit; int nbCNecessaire; int composant; struct _pileFIFO listeDesOperationRequired; }

user_defined_types: struct _pileFIFO { struct _maillon *sommet; }

user_defined_types: struct _maillon { struct _maillon *next; int value; }


hasEnoughComposantToDoProd

decompiled_code:
__int64 __fastcall hasEnoughComposantToDoProd(int a1, int a2)
{
if ( a2 == 103 )
return 3 * (unsigned int)(a1 == 1);
if ( a2 > 103 )
{
if ( a2 == 104 )
return 4 * (unsigned int)(a1 == 2);
return 0LL;
}
if ( a2 != 101 )
{
if ( a2 == 102 )
return 2 * (unsigned int)(a1 == 3);
return 0LL;
}
return a1 == 3;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, int a2)
{
if ( a2 == 103 )
return 3 * (unsigned int)(a1 == 1);
if ( a2 > 103 )
{
if ( a2 == 104 )
return 4 * (unsigned int)(a1 == 2);
return 0LL;
}
if ( a2 != 101 )
{
if ( a2 == 102 )
return 2 * (unsigned int)(a1 == 3);
return 0LL;
}
return a1 == 3;
}

original_code:
int hasEnoughComposantToDoProd(int nb, int compo){
    switch (compo) {
        case 101:
            if(nb==3)
                return 1;
            break;
        case 102:
            if(nb==3)
                return 2;
            break;
        case 103:
            if(nb==1)
                return 3;
            break;
        case 104:
            if(nb==2)
                return 4;
            break;
    }
    return 0;
}

variable_types: nb int

variable_types: compo int