BitArrayOr

original_code:
void BitArrayOr(bit_array_t *dest,
           const bit_array_t *src1,
           const bit_array_t *src2)
{
    int i;
    if (src1 == ((void *)0))
    {
        return;
    }
    if (src2 == ((void *)0))
    {
        return;
    }
    if (dest == ((void *)0))
    {
        return;
    }
    if (src1->numBits != dest->numBits)
    {
        return;
    }
    if (src2->numBits != dest->numBits)
    {
        return;
    }
    for(i = 0; i < ((((dest->numBits) - 1) / 8) + 1); i++)
    {
        dest->array[i] = src1->array[i] | src2->array[i];
    }
}

canonical_original_code:
void BitArrayOr(struct bit_array_t *dest, struct bit_array_t *src1, struct bit_array_t *src2)
{
    int i;
    if (src1 == ((void *)0))
    {
        return;
    }
    if (src2 == ((void *)0))
    {
        return;
    }
    if (dest == ((void *)0))
    {
        return;
    }
    if (src1->numBits != dest->numBits)
    {
        return;
    }
    if (src2->numBits != dest->numBits)
    {
        return;
    }
    for(i = 0; i < ((((dest->numBits) - 1) / 8) + 1); i++)
    {
        dest->array[i] = src1->array[i] | src2->array[i];
    }
}


BitArrayXor

repo: betamos/Huffman-coding

original_code:
void BitArrayXor(bit_array_t *dest,
            const bit_array_t *src1,
            const bit_array_t *src2)
{
    int i;
    if (src1 == ((void *)0))
    {
        return;
    }
    if (src2 == ((void *)0))
    {
        return;
    }
    if (dest == ((void *)0))
    {
        return;
    }
    if (src1->numBits != dest->numBits)
    {
        return;
    }
    if (src2->numBits != dest->numBits)
    {
        return;
    }
    for(i = 0; i < ((((dest->numBits) - 1) / 8) + 1); i++)
    {
        dest->array[i] = src1->array[i] ^ src2->array[i];
    }
}

canonical_original_code:
void BitArrayXor(struct bit_array_t *dest, struct bit_array_t *src1, struct bit_array_t *src2)
{
    int i;
    if (src1 == ((void *)0))
    {
        return;
    }
    if (src2 == ((void *)0))
    {
        return;
    }
    if (dest == ((void *)0))
    {
        return;
    }
    if (src1->numBits != dest->numBits)
    {
        return;
    }
    if (src2->numBits != dest->numBits)
    {
        return;
    }
    for(i = 0; i < ((((dest->numBits) - 1) / 8) + 1); i++)
    {
        dest->array[i] = src1->array[i] ^ src2->array[i];
    }
}

variable_types: struct bit_array_t { unsigned char *array; unsigned int numBits; } *

variable_types: i int

return_type: void


BitArrayNot

original_code:
void BitArrayNot(bit_array_t *dest,
            const bit_array_t *src)
{
    int i, bits;
    unsigned char mask;
    if (src == ((void *)0))
    {
        return;
    }
    if (dest == ((void *)0))
    {
        return;
    }
    if (src->numBits != dest->numBits)
    {
        return;
    }
    for(i = 0; i < ((((dest->numBits) - 1) / 8) + 1); i++)
    {
        dest->array[i] = ~(src->array[i]);
    }
    bits = dest->numBits % 8;
    if (bits != 0)
    {
        mask = (0x7f * 2 + 1) << (8 - bits);
        dest->array[((dest->numBits - 1) / 8)] &= mask;
    }
}

canonical_original_code:
void BitArrayNot(struct bit_array_t *dest, struct bit_array_t *src)
{
    int i; int bits;
    unsigned char mask;
    if (src == ((void *)0))
    {
        return;
    }
    if (dest == ((void *)0))
    {
        return;
    }
    if (src->numBits != dest->numBits)
    {
        return;
    }
    for(i = 0; i < ((((dest->numBits) - 1) / 8) + 1); i++)
    {
        dest->array[i] = ~(src->array[i]);
    }
    bits = dest->numBits % 8;
    if (bits != 0)
    {
        mask = (0x7f * 2 + 1) << (8 - bits);
        dest->array[((dest->numBits - 1) / 8)] &= mask;
    }
}

variable_types:
src
struct bit_array_t *

variable_types: bits int

variable_types:
mask
unsigned char

user_defined_types: struct bit_array_t { unsigned char *array; unsigned int numBits; }


BitArrayShiftLeft

original_code:
void BitArrayShiftLeft(bit_array_t *ba, unsigned int shifts)
{
    int i, j;
    int chars = shifts / 8;
    shifts = shifts % 8;
    if (ba == ((void *)0))
    {
        return;
    }
    if (shifts >= ba->numBits)
    {
        BitArrayClearAll(ba);
        return;
    }
    if (chars > 0)
    {
        for (i = 0; (i + chars) < ((((ba->numBits) - 1) / 8) + 1); i++)
        {
            ba->array[i] = ba->array[i + chars];
        }
        for (i = ((((ba->numBits) - 1) / 8) + 1); chars > 0; chars--)
        {
            ba->array[i - chars] = 0;
        }
    }
    for (i = 0; i < shifts; i++)
    {
        for (j = 0; j < ((ba->numBits - 1) / 8); j++)
        {
            ba->array[j] <<= 1;
            if (ba->array[j + 1] & (1 << (8 - 1)))
            {
                ba->array[j] |= 0x01;
            }
        }
        ba->array[((ba->numBits - 1) / 8)] <<= 1;
    }
}

canonical_original_code:
void BitArrayShiftLeft(struct bit_array_t *ba, unsigned int shifts)
{
    int i; int j;
    int chars = shifts / 8;
    shifts = shifts % 8;
    if (ba == ((void *)0))
    {
        return;
    }
    if (shifts >= ba->numBits)
    {
        BitArrayClearAll(ba);
        return;
    }
    if (chars > 0)
    {
        for (i = 0; (i + chars) < ((((ba->numBits) - 1) / 8) + 1); i++)
        {
            ba->array[i] = ba->array[i + chars];
        }
        for (i = ((((ba->numBits) - 1) / 8) + 1); chars > 0; chars--)
        {
            ba->array[i - chars] = 0;
        }
    }
    for (i = 0; i < shifts; i++)
    {
        for (j = 0; j < ((ba->numBits - 1) / 8); j++)
        {
            ba->array[j] <<= 1;
            if (ba->array[j + 1] & (1 << (8 - 1)))
            {
                ba->array[j] |= 0x01;
            }
        }
        ba->array[((ba->numBits - 1) / 8)] <<= 1;
    }
}

variable_types:
shifts
unsigned int

variable_types: j int

variable_types: chars int


BitArrayShiftRight

original_code:
void BitArrayShiftRight(bit_array_t *ba, unsigned int shifts)
{
    int i, j;
    unsigned char mask;
    int chars = shifts / 8;
    shifts = shifts % 8;
    if (ba == ((void *)0))
    {
        return;
    }
    if (shifts >= ba->numBits)
    {
        BitArrayClearAll(ba);
        return;
    }
    if (chars > 0)
    {
        for (i = ((ba->numBits - 1) / 8); (i - chars) >= 0; i--)
        {
            ba->array[i] = ba->array[i - chars];
        }
        for (; chars > 0; chars--)
        {
            ba->array[chars - 1] = 0;
        }
    }
    for (i = 0; i < shifts; i++)
    {
        for (j = ((ba->numBits - 1) / 8); j > 0; j--)
        {
            ba->array[j] >>= 1;
            if (ba->array[j - 1] & 0x01)
            {
                ba->array[j] |= (1 << (8 - 1));
            }
        }
        ba->array[0] >>= 1;
    }
    i = ba->numBits % 8;
    if (i != 0)
    {
        mask = (0x7f * 2 + 1) << (8 - i);
        ba->array[((ba->numBits - 1) / 8)] &= mask;
    }
}

canonical_original_code:
void BitArrayShiftRight(struct bit_array_t *ba, unsigned int shifts)
{
    int i; int j;
    unsigned char mask;
    int chars = shifts / 8;
    shifts = shifts % 8;
    if (ba == ((void *)0))
    {
        return;
    }
    if (shifts >= ba->numBits)
    {
        BitArrayClearAll(ba);
        return;
    }
    if (chars > 0)
    {
        for (i = ((ba->numBits - 1) / 8); (i - chars) >= 0; i--)
        {
            ba->array[i] = ba->array[i - chars];
        }
        for (; chars > 0; chars--)
        {
            ba->array[chars - 1] = 0;
        }
    }
    for (i = 0; i < shifts; i++)
    {
        for (j = ((ba->numBits - 1) / 8); j > 0; j--)
        {
            ba->array[j] >>= 1;
            if (ba->array[j - 1] & 0x01)
            {
                ba->array[j] |= (1 << (8 - 1));
            }
        }
        ba->array[0] >>= 1;
    }
    i = ba->numBits % 8;
    if (i != 0)
    {
        mask = (0x7f * 2 + 1) << (8 - i);
        ba->array[((ba->numBits - 1) / 8)] &= mask;
    }
}


BitArrayDecrement

original_code:
void BitArrayDecrement(bit_array_t *ba)
{
    int i;
    unsigned char maxValue;
    unsigned char one;
    if (ba == ((void *)0))
    {
        return;
    }
    i = (ba->numBits % 8);
    if (i != 0)
    {
        maxValue = (0x7f * 2 + 1) << (8 - i);
        one = 1 << (8 - i);
    }
    else
    {
        maxValue = (0x7f * 2 + 1);
        one = 1;
    }
    for (i = ((ba->numBits - 1) / 8); i >= 0; i--)
    {
        if (ba->array[i] >= one)
        {
            ba->array[i] = ba->array[i] - one;
            return;
        }
        else
        {
            ba->array[i] = maxValue;
            maxValue = (0x7f * 2 + 1);
            one = 1;
        }
    }
}

canonical_original_code:
void BitArrayDecrement(struct bit_array_t *ba)
{
    int i;
    unsigned char maxValue;
    unsigned char one;
    if (ba == ((void *)0))
    {
        return;
    }
    i = (ba->numBits % 8);
    if (i != 0)
    {
        maxValue = (0x7f * 2 + 1) << (8 - i);
        one = 1 << (8 - i);
    }
    else
    {
        maxValue = (0x7f * 2 + 1);
        one = 1;
    }
    for (i = ((ba->numBits - 1) / 8); i >= 0; i--)
    {
        if (ba->array[i] >= one)
        {
            ba->array[i] = ba->array[i] - one;
            return;
        }
        else
        {
            ba->array[i] = maxValue;
            maxValue = (0x7f * 2 + 1);
            one = 1;
        }
    }
}

variable_types:
maxValue
unsigned char

variable_types:
one
unsigned char


BitArrayCompare

decompiled_code:
__int64 __fastcall BitArrayCompare(__int64 *a1, __int64 *a2)
{
int v2; // edx
int v3; // ecx
__int64 result; // rax
__int64 v5; // r8
__int64 v6; // rdi
__int64 v7; // rcx
__int64 v8; // rax
unsigned __int8 v9; // dl
unsigned __int8 v10; // si

if ( a1 )
{
if ( a2 )
{
v2 = *((_DWORD *)a1 + 2);
v3 = *((_DWORD *)a2 + 2);
result = (unsigned int)(v2 - v3);
if ( v2 == v3 )
{
v5 = *a1;
v6 = *a2;
v7 = ((unsigned int)(v2 - 1) >> 3) + 1;
v8 = 0LL;
while ( 1 )
{
v9 = *(_BYTE *)(v5 + v8);
v10 = *(_BYTE *)(v6 + v8);
if ( v9 != v10 )
break;
if ( ++v8 == v7 )
return 0LL;
}
result = v9 - (unsigned int)v10;
}
}
else
{
result = *((unsigned int *)a1 + 2);
}
}
else
{
result = 0LL;
if ( a2 )
result = (unsigned int)-*((_DWORD *)a2 + 2);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func18(__int64 *a1, __int64 *a2)
{
int v2; // edx
int v3; // ecx
__int64 result; // rax
__int64 v5; // r8
__int64 v6; // rdi
__int64 v7; // rcx
__int64 v8; // rax
unsigned __int8 v9; // dl
unsigned __int8 v10; // si

if ( a1 )
{
if ( a2 )
{
v2 = *((_DWORD *)a1 + 2);
v3 = *((_DWORD *)a2 + 2);
result = (unsigned int)(v2 - v3);
if ( v2 == v3 )
{
v5 = *a1;
v6 = *a2;
v7 = ((unsigned int)(v2 - 1) >> 3) + 1;
v8 = 0LL;
while ( 1 )
{
v9 = *(_BYTE *)(v5 + v8);
v10 = *(_BYTE *)(v6 + v8);
if ( v9 != v10 )
break;
if ( ++v8 == v7 )
return 0LL;
}
result = v9 - (unsigned int)v10;
}
}
else
{
result = *((unsigned int *)a1 + 2);
}
}
else
{
result = 0LL;
if ( a2 )
result = (unsigned int)-*((_DWORD *)a2 + 2);
}
return result;
}

original_code:
int BitArrayCompare(const bit_array_t *ba1, const bit_array_t *ba2)
{
    int i;
    if (ba1 == ((void *)0))
    {
        if (ba2 == ((void *)0))
        {
            return 0;
        }
        else
        {
            return -(ba2->numBits);
        }
    }
    if (ba2 == ((void *)0))
    {
        return (ba1->numBits);
    }
    if (ba1->numBits != ba2->numBits)
    {
        return(ba1->numBits - ba2->numBits);
    }
    for(i = 0; i <= ((ba1->numBits - 1) / 8); i++)
    {
        if (ba1->array[i] != ba2->array[i])
        {
            return(ba1->array[i] - ba2->array[i]);
        }
    }
    return 0;
}

canonical_original_code:
int BitArrayCompare(struct bit_array_t *ba1, struct bit_array_t *ba2)
{
    int i;
    if (ba1 == ((void *)0))
    {
        if (ba2 == ((void *)0))
        {
            return 0;
        }
        else
        {
            return -(ba2->numBits);
        }
    }
    if (ba2 == ((void *)0))
    {
        return (ba1->numBits);
    }
    if (ba1->numBits != ba2->numBits)
    {
        return(ba1->numBits - ba2->numBits);
    }
    for(i = 0; i <= ((ba1->numBits - 1) / 8); i++)
    {
        if (ba1->array[i] != ba2->array[i])
        {
            return(ba1->array[i] - ba2->array[i]);
        }
    }
    return 0;
}

return_type: int


decompiled_code:
void __fastcall pqueue_delete(void *ptr)
{
if ( ptr )
{
free(*((void **)ptr + 2));
free(ptr);
}
else
{
fprintf(stderr, "%s:%d %s", "lib/pqueue/pqueue.c", 40LL, "Priority Queue is already NULL. Nothing to free.");
}
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
if ( ptr )
{
free(*((void **)ptr + 2));
free(ptr);
}
else
{
fprintf(stderr, "%s:%d %s", "lib/pqueue/pqueue.c", 40LL, "Priority Queue is already NULL. Nothing to free.");
}
}

original_code:
void pqueue_delete(PQueue *q) {
    if (q == ((void *)0)) {
        fprintf(stderr, "%s:%d %s", "lib/pqueue/pqueue.c", 40, ("Priority Queue is already NULL. Nothing to free."));
        return;
    }
    free(q->data);
    free(q);
}

canonical_original_code:
void pqueue_delete(struct PQueue_s *q) {
    if (q == ((void *)0)) {
        fprintf(stderr, "%s:%d %s", "lib/pqueue/pqueue.c", 40, ("Priority Queue is already NULL. Nothing to free."));
        return;
    }
    free(q->data);
    free(q);
}

variable_types: struct PQueue_s { unsigned long size; unsigned long capacity; void **data; int (*cmp)(void *d1, void *d2); } *


decompiled_code:
int __fastcall pqueue_enqueue(__int64 a1, __int64 a2)
{
unsigned __int64 v2; // r13
__int64 v3; // rax
unsigned __int64 v4; // r12
unsigned __int64 v5; // rbp
__int64 v6; // rdx
__int64 v7; // rcx

if ( !a1 )
{
fprintf(stderr, "%s:%d NULL POINTER: %s n", "lib/pqueue/pqueue.c", 53LL, "q");
exit(-1);
}
if ( *(_QWORD *)a1 >= *(_QWORD *)(a1 + 8) )
{
LODWORD(v3) = fprintf(
stderr,
"%s:%d %s",
"lib/pqueue/pqueue.c",
55LL,
"Priority Queue is full. Cannot add another element .");
}
else
{
*(_QWORD *)(*(_QWORD *)(a1 + 16) + 8LL * *(_QWORD *)a1) = a2;
v2 = *(_QWORD *)a1;
v3 = *(_QWORD *)a1 + 1LL;
*(_QWORD *)a1 = v3;
if ( v2 )
{
do
{
v4 = v2;
v5 = v2 >> 1;
v2 = v5;
LODWORD(v3) = (*(__int64 (__fastcall **)(_QWORD, _QWORD))(a1 + 24))(
*(_QWORD *)(*(_QWORD *)(a1 + 16) + 8 * v4),
*(_QWORD *)(*(_QWORD *)(a1 + 16) + 8 * v5));
if ( (int)v3 <= 0 )
break;
v6 = *(_QWORD *)(a1 + 16);
v7 = *(_QWORD *)(v6 + 8 * v4);
*(_QWORD *)(v6 + 8 * v4) = *(_QWORD *)(v6 + 8 * v5);
v3 = *(_QWORD *)(a1 + 16);
*(_QWORD *)(v3 + 8 * v5) = v7;
}
while ( v4 > 1 );
}
}
return v3;
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1, __int64 a2)
{
unsigned __int64 v2; // r13
__int64 v3; // rax
unsigned __int64 v4; // r12
unsigned __int64 v5; // rbp
__int64 v6; // rdx
__int64 v7; // rcx

if ( !a1 )
{
fprintf(stderr, "%s:%d NULL POINTER: %s n", "lib/pqueue/pqueue.c", 53LL, "q");
exit(-1);
}
if ( *(_QWORD *)a1 >= *(_QWORD *)(a1 + 8) )
{
LODWORD(v3) = fprintf(
stderr,
"%s:%d %s",
"lib/pqueue/pqueue.c",
55LL,
"Priority Queue is full. Cannot add another element .");
}
else
{
*(_QWORD *)(*(_QWORD *)(a1 + 16) + 8LL * *(_QWORD *)a1) = a2;
v2 = *(_QWORD *)a1;
v3 = *(_QWORD *)a1 + 1LL;
*(_QWORD *)a1 = v3;
if ( v2 )
{
do
{
v4 = v2;
v5 = v2 >> 1;
v2 = v5;
LODWORD(v3) = (*(__int64 (__fastcall **)(_QWORD, _QWORD))(a1 + 24))(
*(_QWORD *)(*(_QWORD *)(a1 + 16) + 8 * v4),
*(_QWORD *)(*(_QWORD *)(a1 + 16) + 8 * v5));
if ( (int)v3 <= 0 )
break;
v6 = *(_QWORD *)(a1 + 16);
v7 = *(_QWORD *)(v6 + 8 * v4);
*(_QWORD *)(v6 + 8 * v4) = *(_QWORD *)(v6 + 8 * v5);
v3 = *(_QWORD *)(a1 + 16);
*(_QWORD *)(v3 + 8 * v5) = v7;
}
while ( v4 > 1 );
}
}
return v3;
}

original_code:
void pqueue_enqueue(PQueue *q, const void *data) {
    size_t i;
    void *tmp = ((void *)0);
    { if (((void *)0) == (q)) { fprintf(stderr, "%s:%d NULL POINTER: %s n", "lib/pqueue/pqueue.c", 53, "q"); exit(-1); } };
    if (q->size >= q->capacity) {
        fprintf(stderr, "%s:%d %s", "lib/pqueue/pqueue.c", 55, ("Priority Queue is full. Cannot add another element ."));
        return;
    }
    q->data[q->size] = (void*) data;
    i = q->size;
    q->size++;
    while(i > 0 && q->cmp(q->data[i], q->data[((i) / 2)]) > 0) {
        tmp = q->data[i];
        q->data[i] = q->data[((i) / 2)];
        q->data[((i) / 2)] = tmp;
        i = ((i) / 2);
    }
}

canonical_original_code:
void pqueue_enqueue(struct PQueue_s *q, void *data) {
    unsigned long i;
    void *tmp = ((void *)0);
    { if (((void *)0) == (q)) { fprintf(stderr, "%s:%d NULL POINTER: %s n", "lib/pqueue/pqueue.c", 53, "q"); exit(-1); } };
    if (q->size >= q->capacity) {
        fprintf(stderr, "%s:%d %s", "lib/pqueue/pqueue.c", 55, ("Priority Queue is full. Cannot add another element ."));
        return;
    }
    q->data[q->size] = (void *) data;
    i = q->size;
    q->size++;
    while(i > 0 && q->cmp(q->data[i], q->data[((i) / 2)]) > 0) {
        tmp = q->data[i];
        q->data[i] = q->data[((i) / 2)];
        q->data[((i) / 2)] = tmp;
        i = ((i) / 2);
    }
}

variable_types:
data
void *

variable_types:
i
unsigned long

variable_types:
tmp
void *

user_defined_types: struct PQueue_s { unsigned long size; unsigned long capacity; void **data; int (*cmp)(void *d1, void *d2); }


original_code:
void pqueue_heapify(PQueue *q, size_t idx) {
    void *tmp = ((void *)0);
    size_t l_idx, r_idx, lrg_idx;
    { if (((void *)0) == (q)) { fprintf(stderr, "%s:%d NULL POINTER: %s n", "lib/pqueue/pqueue.c", 93, "q"); exit(-1); } };
    l_idx = (2 * (idx) + 1);
    r_idx = (2 * (idx) + 2);
    if (l_idx < q->size && q->cmp(q->data[l_idx], q->data[idx]) > 0) {
        lrg_idx = l_idx;
    } else {
        lrg_idx = idx;
    }
    if (r_idx < q->size && q->cmp(q->data[r_idx], q->data[lrg_idx]) > 0) {
        lrg_idx = r_idx;
    }
    if (lrg_idx != idx) {
        tmp = q->data[lrg_idx];
        q->data[lrg_idx] = q->data[idx];
        q->data[idx] = tmp;
        pqueue_heapify(q, lrg_idx);
    }
}

canonical_original_code:
void pqueue_heapify(struct PQueue_s *q, unsigned long idx) {
    void *tmp = ((void *)0);
    unsigned long l_idx; unsigned long r_idx; unsigned long lrg_idx;
    { if (((void *)0) == (q)) { fprintf(stderr, "%s:%d NULL POINTER: %s n", "lib/pqueue/pqueue.c", 93, "q"); exit(-1); } };
    l_idx = (2 * (idx) + 1);
    r_idx = (2 * (idx) + 2);
    if (l_idx < q->size && q->cmp(q->data[l_idx], q->data[idx]) > 0) {
        lrg_idx = l_idx;
    } else {
        lrg_idx = idx;
    }
    if (r_idx < q->size && q->cmp(q->data[r_idx], q->data[lrg_idx]) > 0) {
        lrg_idx = r_idx;
    }
    if (lrg_idx != idx) {
        tmp = q->data[lrg_idx];
        q->data[lrg_idx] = q->data[idx];
        q->data[idx] = tmp;
        pqueue_heapify(q, lrg_idx);
    }
}

variable_types:
idx
unsigned long


decompiled_code:
__int64 __fastcall pqueue_dequeue(_QWORD *a1)
{
__int64 *v1; // rax
__int64 v2; // rbx

if ( !a1 )
{
fprintf(stderr, "%s:%d NULL POINTER: %s n", "lib/pqueue/pqueue.c", 77LL, "q");
exit(-1);
}
if ( *a1 )
{
v1 = (__int64 *)a1[2];
v2 = *v1;
*v1 = v1[--*a1];
pqueue_heapify((__int64)a1, 0LL);
}
else
{
fprintf(
stderr,
"%s:%d %s",
"lib/pqueue/pqueue.c",
78LL,
"Priority Queue underflow . Cannot remove another element .");
v2 = 0LL;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func3(_QWORD *a1)
{
__int64 *v1; // rax
__int64 v2; // rbx

if ( !a1 )
{
fprintf(stderr, "%s:%d NULL POINTER: %s n", "lib/pqueue/pqueue.c", 77LL, "q");
exit(-1);
}
if ( *a1 )
{
v1 = (__int64 *)a1[2];
v2 = *v1;
*v1 = v1[--*a1];
func2((__int64)a1, 0LL);
}
else
{
fprintf(
stderr,
"%s:%d %s",
"lib/pqueue/pqueue.c",
78LL,
"Priority Queue underflow . Cannot remove another element .");
v2 = 0LL;
}
return v2;
}

original_code:
void *pqueue_dequeue(PQueue *q) {
    void *data = ((void *)0);
    { if (((void *)0) == (q)) { fprintf(stderr, "%s:%d NULL POINTER: %s n", "lib/pqueue/pqueue.c", 77, "q"); exit(-1); } };
    if (q->size < 1) { fprintf(stderr, "%s:%d %s", "lib/pqueue/pqueue.c", 78, ("Priority Queue underflow . Cannot remove another element .")); return ((void *)0); } data = q->data[0];
    q->data[0] = q->data[q->size-1];
    q->size--;
    pqueue_heapify(q, 0);
    return (data);
}

canonical_original_code:
void *pqueue_dequeue(struct PQueue_s *q) {
    void *data = ((void *)0);
    { if (((void *)0) == (q)) { fprintf(stderr, "%s:%d NULL POINTER: %s n", "lib/pqueue/pqueue.c", 77, "q"); exit(-1); } };
    if (q->size < 1) { fprintf(stderr, "%s:%d %s", "lib/pqueue/pqueue.c", 78, ("Priority Queue underflow . Cannot remove another element .")); return ((void *)0); } data = q->data[0];
    q->data[0] = q->data[q->size-1];
    q->size--;
    pqueue_heapify(q, 0);
    return (data);
}

return_type: void *


DetermineEndianess

decompiled_code:
__int64 DetermineEndianess()
{
return 1LL;
}

canonical_decompiled_code:
__int64 func0()
{
return 1LL;
}

original_code:
endian_t DetermineEndianess(void)
{
    endian_t endian;
    endian_test_t endianTest;
    endianTest.word = 1;
    if (endianTest.bytes[0] == 1)
    {
        endian = BF_LITTLE_ENDIAN;
    }
    else if (endianTest.bytes[sizeof(unsigned long) - 1] == 1)
    {
        endian = BF_BIG_ENDIAN;
    }
    else
    {
        endian = BF_UNKNOWN_ENDIAN;
    }
    return endian;
}

canonical_original_code:
enum endian_t DetermineEndianess()
{
    enum endian_t endian;
    union endian_test_t endianTest;
    endianTest.word = 1;
    if (endianTest.bytes[0] == 1)
    {
        endian = BF_LITTLE_ENDIAN;
    }
    else if (endianTest.bytes[sizeof(unsigned long) - 1] == 1)
    {
        endian = BF_BIG_ENDIAN;
    }
    else
    {
        endian = BF_UNKNOWN_ENDIAN;
    }
    return endian;
}

variable_types: enum endian_t { BF_UNKNOWN_ENDIAN=0, BF_LITTLE_ENDIAN=1, BF_BIG_ENDIAN=2 }

variable_types: union endian_test_t { unsigned long word; unsigned char bytes[-1]; }


decompiled_code:
__int64 __fastcall compress_bytestats2tree(__int64 a1)
{
__int64 v1; // r12
__int64 i; // rbx
__int64 v3; // rax
unsigned int v4; // er13
__int64 v5; // rbx
__int64 v6; // rax
__int64 v7; // rax
__int64 v8; // rbx

v1 = pqueue_new(compare, *(unsigned int *)(a1 + 4));
for ( i = 0LL; i != 256; ++i )
{
if ( *(_DWORD *)(a1 + 4 * i + 8) )
{
v3 = tree_create_leaf((unsigned __int8)i);
pqueue_enqueue(v1, v3);
}
}
if ( *(_DWORD *)(a1 + 4) > 1u )
{
v4 = 1;
do
{
v5 = pqueue_dequeue(v1);
v6 = pqueue_dequeue(v1);
v7 = tree_create_branch(v5, v6);
pqueue_enqueue(v1, v7);
++v4;
}
while ( *(_DWORD *)(a1 + 4) > v4 );
}
v8 = pqueue_dequeue(v1);
pqueue_delete(v1);
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 v1; // r12
__int64 i; // rbx
__int64 v3; // rax
unsigned int v4; // er13
__int64 v5; // rbx
__int64 v6; // rax
__int64 v7; // rax
__int64 v8; // rbx

v1 = pqueue_new(compare, *(unsigned int *)(a1 + 4));
for ( i = 0LL; i != 256; ++i )
{
if ( *(_DWORD *)(a1 + 4 * i + 8) )
{
v3 = tree_create_leaf((unsigned __int8)i);
pqueue_enqueue(v1, v3);
}
}
if ( *(_DWORD *)(a1 + 4) > 1u )
{
v4 = 1;
do
{
v5 = pqueue_dequeue(v1);
v6 = pqueue_dequeue(v1);
v7 = tree_create_branch(v5, v6);
pqueue_enqueue(v1, v7);
++v4;
}
while ( *(_DWORD *)(a1 + 4) > v4 );
}
v8 = pqueue_dequeue(v1);
pqueue_delete(v1);
return v8;
}

original_code:
tree_node* compress_bytestats2tree(compress_bytestats *stats) {
  void* pq = pqueue_new(_compare, (size_t) stats->uniquebytes);
  tree_node *leaf, *leaf2;
  int i;
  for (i = 0; i < 256; i++) {
    if (stats->counts[i] > 0) {
      leaf = tree_create_leaf(i, stats->counts[i]);
      pqueue_enqueue(pq, (void *) leaf);
    }
  }
  for (i = 1; i < stats->uniquebytes; i++) {
    leaf = (tree_node *) pqueue_dequeue(pq);
    leaf2 = (tree_node *) pqueue_dequeue(pq);
    pqueue_enqueue(pq, (void *) tree_create_branch(leaf, leaf2));
  }
  leaf = (tree_node *) pqueue_dequeue(pq);
  pqueue_delete(pq);
  return leaf;
}

canonical_original_code:
struct tree_node *compress_bytestats2tree(struct compress_bytestats *stats) {
  void *pq = pqueue_new(_compare, (size_t) stats->uniquebytes);
  struct tree_node *leaf; struct tree_node *leaf2;
  int i;
  for (i = 0; i < 256; i++) {
    if (stats->counts[i] > 0) {
      leaf = tree_create_leaf(i, stats->counts[i]);
      pqueue_enqueue(pq, (void *) leaf);
    }
  }
  for (i = 1; i < stats->uniquebytes; i++) {
    leaf = (struct tree_node *) pqueue_dequeue(pq);
    leaf2 = (struct tree_node *) pqueue_dequeue(pq);
    pqueue_enqueue(pq, (void *) tree_create_branch(leaf, leaf2));
  }
  leaf = (struct tree_node *) pqueue_dequeue(pq);
  pqueue_delete(pq);
  return leaf;
}

variable_types: struct compress_bytestats { unsigned int totalcount; unsigned int uniquebytes; unsigned int counts[256]; } *

variable_types:
pq
void *

variable_types: struct tree_node { unsigned char content; unsigned int count; struct tree_node *left; } *


main

canonical_name: main

repo: betasam/apptemplate

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
_BYTE v4[56]; // [rsp+0h] [rbp-38h] BYREF

result = s32f_app_init(v4, s32f_fibonacci_app, envp);
if ( !result )
result = s32f_app_exec(v4, (unsigned int)argc, argv);
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
_BYTE v4[56]; // [rsp+0h] [rbp-38h] BYREF

result = func7(v4, s32f_fibonacci_app, envp);
if ( !result )
result = func8(v4, (unsigned int)argc, argv);
return result;
}

original_code:
int main(int argc, char *argv[])
{
    int s32v_retval = 0;
    app_t main_app;
    s32v_retval = s32f_app_init(&main_app, &s32f_fibonacci_app);
    if (s32v_retval == 0) {
        s32v_retval = s32f_app_exec(&main_app, argc, argv);
    }
    return s32v_retval;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    int s32v_retval = 0;
    struct _app_s main_app;
    s32v_retval = s32f_app_init(&main_app, &s32f_fibonacci_app);
    if (s32v_retval == 0) {
        s32v_retval = s32f_app_exec(&main_app, argc, argv);
    }
    return s32v_retval;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct _app_s { int s32v_state; int (*main)(int argc, char *argv[]); int s32v_return; }


repo: bezeredi/libdstructs

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

if ( a1 )
result = *(unsigned int *)(a1 + 24);
else
result = 0xFFFFFFFFLL;
return result;
}

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

if ( a1 )
result = *(unsigned int *)(a1 + 24);
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int ll_size(llist_t* const list) {
   return (list ? list->__size : -1);
}

canonical_original_code:
int ll_size(struct __llist_s *list) {
   return (list ? list->__size : -1);
}

variable_types: struct __llist_s { void *__first; void *__last; unsigned long __elem_size; int __size; } *


decompiled_code:
__int64 __fastcall ll_contains(__int64 *a1, const void *a2)
{
__int64 v2; // rbx
size_t v3; // r12

if ( !a1 )
return 0LL;
v2 = *a1;
v3 = a1[2];
if ( !*a1 )
return 0LL;
while ( memcmp(a2, *(const void **)v2, v3) )
{
v2 = *(_QWORD *)(v2 + 24);
if ( !v2 )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 *a1, const void *a2)
{
__int64 v2; // rbx
size_t v3; // r12

if ( !a1 )
return 0LL;
v2 = *a1;
v3 = a1[2];
if ( !*a1 )
return 0LL;
while ( memcmp(a2, *(const void **)v2, v3) )
{
v2 = *(_QWORD *)(v2 + 24);
if ( !v2 )
return 0LL;
}
return 1LL;
}

original_code:
int ll_contains(llist_t* const list, void* const elem) {
   __node_t *temp;
   size_t num_bytes;
   if(!list) return !1;
   temp = list->__first;
   num_bytes = list->__elem_size;
   while(temp) {
      if(memcmp(elem, temp->element, num_bytes) == 0)
         return 1;
      temp = temp->next;
   }
   return !1;
}

canonical_original_code:
int ll_contains(struct __llist_s *list, void *elem) {
   struct __node_s *temp;
   unsigned long num_bytes;
   if(!list) return !1;
   temp = list->__first;
   num_bytes = list->__elem_size;
   while(temp) {
      if(memcmp(elem, temp->element, num_bytes) == 0)
         return 1;
      temp = temp->next;
   }
   return !1;
}

variable_types:
elem
void *

variable_types: struct __node_s { void *element; int index; struct __node_s *prev; struct __node_s *next; } *

user_defined_types: struct __llist_s { void *__first; void *__last; unsigned long __elem_size; int __size; }


original_code:
int ll_add(llist_t* const list, int index, void* const elem) {
   __node_t *temp, *new;
   int count;
   if(!list) return !1;
   if(index < 0 || index > list->__size)
      return !1;
   new = malloc(sizeof(__node_t));
   if(!new) return !1;
   new->element = elem;
   new->index = index;
   new->prev = ((void *)0);
   new->next = ((void *)0);
   if((!ll_first(list))) {
      list->__first = new;
      list->__last = new;
      list->__size++;
      return 1;
   }
   if(index == list->__size) {
      temp = list->__last;
      temp->next = new;
      new->prev = temp;
      list->__last = new;
      list->__size++;
      return 1;
   }
   if(index == 0) {
      new->next = list->__first;
      ((__node_t*) list->__first)->prev = new;
      list->__first = new;
   }
   else {
      count = 0;
      temp = list->__first;
      while(temp->next) {
         if(count == index) {
            new->next = temp->next;
            new->prev = temp;
            temp->next->prev = new;
            temp->next = new;
            break;
         }
         temp = temp->next;
         count++;
      }
   }
   temp = new->next;
   list->__size++;
   return 1;
}

canonical_original_code:
int ll_add(struct __llist_s *list, int index, void *elem) {
   struct __node_s *temp; struct __node_s *new;
   int count;
   if(!list) return !1;
   if(index < 0 || index > list->__size)
      return !1;
   new = malloc(sizeof(__node_t));
   if(!new) return !1;
   new->element = elem;
   new->index = index;
   new->prev = ((void *)0);
   new->next = ((void *)0);
   if((!ll_first(list))) {
      list->__first = new;
      list->__last = new;
      list->__size++;
      return 1;
   }
   if(index == list->__size) {
      temp = list->__last;
      temp->next = new;
      new->prev = temp;
      list->__last = new;
      list->__size++;
      return 1;
   }
   if(index == 0) {
      new->next = list->__first;
      ((struct __node_s *) list->__first)->prev = new;
      list->__first = new;
   }
   else {
      count = 0;
      temp = list->__first;
      while(temp->next) {
         if(count == index) {
            new->next = temp->next;
            new->prev = temp;
            temp->next->prev = new;
            temp->next = new;
            break;
         }
         temp = temp->next;
         count++;
      }
   }
   temp = new->next;
   list->__size++;
   return 1;
}

variable_types: index int

variable_types: count int

user_defined_types: struct __node_s { void *element; int index; struct __node_s *prev; struct __node_s *next; }


decompiled_code:
__int64 __fastcall ll_addf(__int64 a1, __int64 a2)
{
return ll_add(a1, 0, a2);
}

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

original_code:
void ll_addf(llist_t* const list, void* const elem) {
   ll_add(list, 0, elem);
}

canonical_original_code:
void ll_addf(struct __llist_s *list, void *elem) {
   ll_add(list, 0, elem);
}


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

if ( a1 )
result = ll_add(a1, *(_DWORD *)(a1 + 24), a2);
return result;
}

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

if ( a1 )
result = func2(a1, *(_DWORD *)(a1 + 24), a2);
return result;
}

original_code:
void ll_addl(llist_t* const list, void* const elem) {
   if(!list) return;
   ll_add(list, list->__size, elem);
}

canonical_original_code:
void ll_addl(struct __llist_s *list, void *elem) {
   if(!list) return;
   ll_add(list, list->__size, elem);
}


decompiled_code:
__int64 __fastcall ll_indexof(__int64 *a1, const void *a2)
{
__int64 v2; // rbx
size_t v3; // r13
unsigned int v4; // ebp

if ( !a1 )
return (unsigned int)-1;
v2 = *a1;
v3 = a1[2];
if ( !*a1 )
return (unsigned int)-1;
v4 = 0;
while ( memcmp(a2, *(const void **)v2, v3) )
{
v2 = *(_QWORD *)(v2 + 24);
++v4;
if ( !v2 )
return (unsigned int)-1;
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 *a1, const void *a2)
{
__int64 v2; // rbx
size_t v3; // r13
unsigned int v4; // ebp

if ( !a1 )
return (unsigned int)-1;
v2 = *a1;
v3 = a1[2];
if ( !*a1 )
return (unsigned int)-1;
v4 = 0;
while ( memcmp(a2, *(const void **)v2, v3) )
{
v2 = *(_QWORD *)(v2 + 24);
++v4;
if ( !v2 )
return (unsigned int)-1;
}
return v4;
}

original_code:
int ll_indexof(llist_t* const list, void* const elem) {
   __node_t *temp;
   size_t num_bytes;
   int count;
   if(!list) return -1;
   temp = list->__first;
   num_bytes = list->__elem_size;
   count = 0;
   while(temp) {
      if(memcmp(elem, temp->element, num_bytes) == 0)
         return count;
      temp = temp->next;
      count++;
   }
   return -1;
}

canonical_original_code:
int ll_indexof(struct __llist_s *list, void *elem) {
   struct __node_s *temp;
   unsigned long num_bytes;
   int count;
   if(!list) return -1;
   temp = list->__first;
   num_bytes = list->__elem_size;
   count = 0;
   while(temp) {
      if(memcmp(elem, temp->element, num_bytes) == 0)
         return count;
      temp = temp->next;
      count++;
   }
   return -1;
}


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

if ( a1 )
{
while ( ll_first(a1) )
{
v1 = ll_remf(a1);
free(v1);
}
}
}

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

if ( a1 )
{
while ( ll_first(a1) )
{
v1 = ll_remf(a1);
free(v1);
}
}
}

original_code:
void ll_clear(llist_t* const list) {
   if(!list) return;
   while(!(!ll_first(list)))
      free(ll_remf(list));
}

canonical_original_code:
void ll_clear(struct __llist_s *list) {
   if(!list) return;
   while(!(!ll_first(list)))
      free(ll_remf(list));
}


decompiled_code:
void __fastcall ll_free(void *ptr)
{
if ( ptr )
{
ll_clear((__int64)ptr);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func8(void *ptr)
{
if ( ptr )
{
func7((__int64)ptr);
free(ptr);
}
}

original_code:
void ll_free(llist_t* const list) {
   if(!list) return;
   ll_clear(list);
   free(list);
}

canonical_original_code:
void ll_free(struct __llist_s *list) {
   if(!list) return;
   ll_clear(list);
   free(list);
}


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

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

original_code:
void li_free(ll_itr_t* const itr) {
   free(itr);
}

canonical_original_code:
void li_free(struct __ll_iter_s *itr) {
   free(itr);
}

variable_types: struct __ll_iter_s { void *__next; void *__prev; } *


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

if ( a1 )
result = *a1 != 0LL;
else
result = 0LL;
return result;
}

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

if ( a1 )
result = *a1 != 0LL;
else
result = 0LL;
return result;
}

original_code:
int li_hasnext(ll_itr_t* const itr) {
   if(!itr) return !1;
   return (itr->__next ? 1 : !1);
}

canonical_original_code:
int li_hasnext(struct __ll_iter_s *itr) {
   if(!itr) return !1;
   return (itr->__next ? 1 : !1);
}

user_defined_types: struct __ll_iter_s { void *__next; void *__prev; }


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

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

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

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

original_code:
int li_hasprev(ll_itr_t* const itr) {
   if(!itr) return !1;
   return (itr->__prev ? 1 : !1);
}

canonical_original_code:
int li_hasprev(struct __ll_iter_s *itr) {
   if(!itr) return !1;
   return (itr->__prev ? 1 : !1);
}


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

if ( a1 )
result = *(unsigned int *)(a1 + 20);
else
result = 0xFFFFFFFFLL;
return result;
}

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

if ( a1 )
result = *(unsigned int *)(a1 + 20);
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int v_size(vect_t* const v) {
   return (v ? v->__size : -1);
}

canonical_original_code:
int v_size(struct __vect_s *v) {
   return (v ? v->__size : -1);
}

variable_types: struct __vect_s { int **__elements; unsigned long __elem_size; int __cap; int __size; } *


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

if ( a1 )
result = *(unsigned int *)(a1 + 16);
else
result = 0xFFFFFFFFLL;
return result;
}

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

if ( a1 )
result = *(unsigned int *)(a1 + 16);
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int v_cap(vect_t* const v) {
   return (v ? v->__cap : -1);
}

canonical_original_code:
int v_cap(struct __vect_s *v) {
   return (v ? v->__cap : -1);
}

user_defined_types: struct __vect_s { int **__elements; unsigned long __elem_size; int __cap; int __size; }


original_code:
int v_add(vect_t* const v, int index, void* const elem) {
   int i, size;
   if(!v) return !1;
   if(index < 0 || index > v->__size)
      return !1;
   size = ++v->__size;
   if(size == v->__cap)
      __v_expand(v);
   for(i = size; i > index; i--)
      v->__elements[i] = v->__elements[i - 1];
   v->__elements[index] = elem;
   return 1;
}

canonical_original_code:
int v_add(struct __vect_s *v, int index, void *elem) {
   int i; int size;
   if(!v) return !1;
   if(index < 0 || index > v->__size)
      return !1;
   size = ++v->__size;
   if(size == v->__cap)
      __v_expand(v);
   for(i = size; i > index; i--)
      v->__elements[i] = v->__elements[i - 1];
   v->__elements[index] = elem;
   return 1;
}

variable_types: i int

variable_types: size int


decompiled_code:
__int64 __fastcall v_addf(__int64 a1, __int64 a2)
{
return v_add(a1, 0, a2);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2)
{
return func3(a1, 0, a2);
}

original_code:
void v_addf(vect_t* const v, void* const elem) {
   v_add(v, 0, elem);
}

canonical_original_code:
void v_addf(struct __vect_s *v, void *elem) {
   v_add(v, 0, elem);
}


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

if ( a1 )
result = v_add(a1, *(_DWORD *)(a1 + 20), a2);
return result;
}

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

if ( a1 )
result = func3(a1, *(_DWORD *)(a1 + 20), a2);
return result;
}

original_code:
void v_addl(vect_t* const v, void* const elem) {
   if(!v) return;
   v_add(v, v->__size, elem);
}

canonical_original_code:
void v_addl(struct __vect_s *v, void *elem) {
   if(!v) return;
   v_add(v, v->__size, elem);
}


decompiled_code:
__int64 __fastcall v_contains(__int64 a1, const void *a2)
{
size_t v2; // r12
int v3; // eax
const void **v4; // rbx
__int64 v5; // r13

if ( !a1 )
return 0LL;
v2 = *(_QWORD *)(a1 + 8);
v3 = *(_DWORD *)(a1 + 20);
if ( v3 <= 0 )
return 0LL;
v4 = *(const void ***)a1;
v5 = *(_QWORD *)a1 + 8LL * (unsigned int)(v3 - 1) + 8;
while ( memcmp(a2, *v4, v2) )
{
if ( ++v4 == (const void **)v5 )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, const void *a2)
{
size_t v2; // r12
int v3; // eax
const void **v4; // rbx
__int64 v5; // r13

if ( !a1 )
return 0LL;
v2 = *(_QWORD *)(a1 + 8);
v3 = *(_DWORD *)(a1 + 20);
if ( v3 <= 0 )
return 0LL;
v4 = *(const void ***)a1;
v5 = *(_QWORD *)a1 + 8LL * (unsigned int)(v3 - 1) + 8;
while ( memcmp(a2, *v4, v2) )
{
if ( ++v4 == (const void **)v5 )
return 0LL;
}
return 1LL;
}

original_code:
int v_contains(vect_t* const v, void* const elem) {
   size_t num_bytes;
   int i, size;
   if(!v) return !1;
   num_bytes = v->__elem_size;
   size = v->__size;
   for(i = 0; i < size; i++)
      if(memcmp(elem, v->__elements[i], num_bytes) == 0)
         return 1;
   return !1;
}

canonical_original_code:
int v_contains(struct __vect_s *v, void *elem) {
   unsigned long num_bytes;
   int i; int size;
   if(!v) return !1;
   num_bytes = v->__elem_size;
   size = v->__size;
   for(i = 0; i < size; i++)
      if(memcmp(elem, v->__elements[i], num_bytes) == 0)
         return 1;
   return !1;
}


decompiled_code:
__int64 __fastcall v_get(__int64 a1, int a2)
{
if ( a2 < 0 || !a1 )
return 0LL;
if ( *(_DWORD *)(a1 + 20) <= a2 )
return 0LL;
return *(_QWORD *)(*(_QWORD *)a1 + 8LL * a2);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, int a2)
{
if ( a2 < 0 || !a1 )
return 0LL;
if ( *(_DWORD *)(a1 + 20) <= a2 )
return 0LL;
return *(_QWORD *)(*(_QWORD *)a1 + 8LL * a2);
}

original_code:
void* v_get(vect_t* const v, int index) {
   if(!v) return ((void *)0);
   if(index < 0 || index >= v->__size)
      return ((void *)0);
   return v->__elements[index];
}

canonical_original_code:
void *v_get(struct __vect_s *v, int index) {
   if(!v) return ((void *)0);
   if(index < 0 || index >= v->__size)
      return ((void *)0);
   return v->__elements[index];
}


decompiled_code:
__int64 __fastcall v_first(__int64 a1)
{
return v_get(a1, 0);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
return func7(a1, 0);
}

original_code:
void* v_first(vect_t* const v) {
   return v_get(v, 0);
}

canonical_original_code:
void *v_first(struct __vect_s *v) {
   return v_get(v, 0);
}


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

if ( a1 )
result = v_get(a1, *(_DWORD *)(a1 + 20) - 1);
else
result = 0LL;
return result;
}

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

if ( a1 )
result = func7(a1, *(_DWORD *)(a1 + 20) - 1);
else
result = 0LL;
return result;
}

original_code:
void* v_last(vect_t* const v) {
   if(!v) return ((void *)0);
   return v_get(v, v->__size - 1);
}

canonical_original_code:
void *v_last(struct __vect_s *v) {
   if(!v) return ((void *)0);
   return v_get(v, v->__size - 1);
}


decompiled_code:
__int64 __fastcall v_indexof(__int64 *a1, const void *a2)
{
size_t v2; // r14
int v3; // ebp
__int64 v4; // r15
__int64 v5; // rbx
unsigned int v6; // er13

if ( !a1 )
return (unsigned int)-1;
v2 = a1[1];
v3 = *((_DWORD *)a1 + 5);
if ( v3 <= 0 )
return (unsigned int)-1;
v4 = *a1;
v5 = 0LL;
while ( 1 )
{
v6 = v5;
if ( !memcmp(a2, *(const void **)(v4 + 8 * v5), v2) )
break;
if ( ++v5 == v3 )
return (unsigned int)-1;
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 *a1, const void *a2)
{
size_t v2; // r14
int v3; // ebp
__int64 v4; // r15
__int64 v5; // rbx
unsigned int v6; // er13

if ( !a1 )
return (unsigned int)-1;
v2 = a1[1];
v3 = *((_DWORD *)a1 + 5);
if ( v3 <= 0 )
return (unsigned int)-1;
v4 = *a1;
v5 = 0LL;
while ( 1 )
{
v6 = v5;
if ( !memcmp(a2, *(const void **)(v4 + 8 * v5), v2) )
break;
if ( ++v5 == v3 )
return (unsigned int)-1;
}
return v6;
}

original_code:
int v_indexof(vect_t* const v, void* const elem) {
   size_t num_bytes;
   int i, size;
   if(!v) return -1;
   num_bytes = v->__elem_size;
   size = v->__size;
   for(i = 0; i < size; i++)
      if(memcmp(elem, v->__elements[i], num_bytes) == 0)
         return i;
   return -1;
}

canonical_original_code:
int v_indexof(struct __vect_s *v, void *elem) {
   unsigned long num_bytes;
   int i; int size;
   if(!v) return -1;
   num_bytes = v->__elem_size;
   size = v->__size;
   for(i = 0; i < size; i++)
      if(memcmp(elem, v->__elements[i], num_bytes) == 0)
         return i;
   return -1;
}


decompiled_code:
__int64 __fastcall v_clear(__int64 a1)
{
return v_apply(a1, &free);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
return func11(a1, &free);
}

original_code:
void v_clear(vect_t* const v) {
   v_apply(v, free);
}

canonical_original_code:
void v_clear(struct __vect_s *v) {
   v_apply(v, free);
}


decompiled_code:
void __fastcall v_free(void *ptr)
{
if ( ptr )
{
v_clear((__int64)ptr);
free(*(void **)ptr);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func13(void *ptr)
{
if ( ptr )
{
func12((__int64)ptr);
free(*(void **)ptr);
free(ptr);
}
}

original_code:
void v_free(vect_t* const v) {
   if(!v) return;
   v_clear(v);
   free(v->__elements);
   free(v);
}

canonical_original_code:
void v_free(struct __vect_s *v) {
   if(!v) return;
   v_clear(v);
   free(v->__elements);
   free(v);
}


original_code:
void* v_rem(vect_t* const v, int index) {
   void *target;
   int i, size;
   if(!v) return ((void *)0);
   if(index < 0 || index >= v->__size)
      return ((void *)0);
   if((!v_first(v))) return ((void *)0);
   size = v->__size;
   target = v->__elements[index];
   for(i = index; i < size; i++)
      v->__elements[i] = v->__elements[i + 1];
   v->__size--;
   return target;
}

canonical_original_code:
void *v_rem(struct __vect_s *v, int index) {
   void *target;
   int i; int size;
   if(!v) return ((void *)0);
   if(index < 0 || index >= v->__size)
      return ((void *)0);
   if((!v_first(v))) return ((void *)0);
   size = v->__size;
   target = v->__elements[index];
   for(i = index; i < size; i++)
      v->__elements[i] = v->__elements[i + 1];
   v->__size--;
   return target;
}

variable_types:
target
void *


decompiled_code:
__int64 __fastcall v_remf(__int64 a1)
{
return v_rem(a1, 0);
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1)
{
return func14(a1, 0);
}

original_code:
void* v_remf(vect_t* const v) {
   return v_rem(v, 0);
}

canonical_original_code:
void *v_remf(struct __vect_s *v) {
   return v_rem(v, 0);
}


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

if ( a1 )
result = v_rem(a1, *(_DWORD *)(a1 + 20) - 1);
else
result = 0LL;
return result;
}

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

if ( a1 )
result = func14(a1, *(_DWORD *)(a1 + 20) - 1);
else
result = 0LL;
return result;
}

original_code:
void* v_reml(vect_t* const v) {
   if(!v) return ((void *)0);
   return v_rem(v, v->__size - 1);
}

canonical_original_code:
void *v_reml(struct __vect_s *v) {
   if(!v) return ((void *)0);
   return v_rem(v, v->__size - 1);
}


decompiled_code:
__int64 __fastcall v_set(__int64 a1, int a2, __int64 a3)
{
__int64 *v3; // rcx
__int64 result; // rax

if ( a2 < 0 || !a1 )
return 0LL;
if ( *(_DWORD *)(a1 + 20) <= a2 )
return 0LL;
v3 = (__int64 *)(*(_QWORD *)a1 + 8LL * a2);
result = *v3;
*v3 = a3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1, int a2, __int64 a3)
{
__int64 *v3; // rcx
__int64 result; // rax

if ( a2 < 0 || !a1 )
return 0LL;
if ( *(_DWORD *)(a1 + 20) <= a2 )
return 0LL;
v3 = (__int64 *)(*(_QWORD *)a1 + 8LL * a2);
result = *v3;
*v3 = a3;
return result;
}

original_code:
void* v_set(vect_t* const v, int index, void* const elem) {
   void *target;
   if(!v) return ((void *)0);
   if(index < 0 || index >= v->__size)
      return ((void *)0);
   target = v->__elements[index];
   v->__elements[index] = elem;
   return target;
}

canonical_original_code:
void *v_set(struct __vect_s *v, int index, void *elem) {
   void *target;
   if(!v) return ((void *)0);
   if(index < 0 || index >= v->__size)
      return ((void *)0);
   target = v->__elements[index];
   v->__elements[index] = elem;
   return target;
}


decompiled_code:
void *__fastcall v_toarr(__int64 a1)
{
size_t v1; // rbp
void *result; // rax

if ( !a1 )
return 0LL;
v1 = 8LL * *(int *)(a1 + 20);
result = malloc(v1);
if ( result )
result = memcpy(result, *(const void **)a1, v1);
return result;
}

canonical_decompiled_code:
void *__fastcall func18(__int64 a1)
{
size_t v1; // rbp
void *result; // rax

if ( !a1 )
return 0LL;
v1 = 8LL * *(int *)(a1 + 20);
result = malloc(v1);
if ( result )
result = memcpy(result, *(const void **)a1, v1);
return result;
}

original_code:
void** v_toarr(vect_t* const v) {
   int **array;
   int size;
   if(!v) return ((void *)0);
   size = v->__size;
   array = malloc(sizeof(void*) * size);
   if(!array) return ((void *)0);
   array = memcpy(array, v->__elements, sizeof(void*) * size);
   return (void**) array;
}

canonical_original_code:
void **v_toarr(struct __vect_s *v) {
   int **array;
   int size;
   if(!v) return ((void *)0);
   size = v->__size;
   array = malloc(sizeof(void *) * size);
   if(!array) return ((void *)0);
   array = memcpy(array, v->__elements, sizeof(void *) * size);
   return (void **) array;
}

variable_types:
array
int **

return_type: void **


original_code:
void v_trim(vect_t* const v) {
   int size;
   if(!v) return;
   size = v->__size;
   v->__elements = realloc(v->__elements, sizeof(void*) * size);
   v->__cap = size;
}

canonical_original_code:
void v_trim(struct __vect_s *v) {
   int size;
   if(!v) return;
   size = v->__size;
   v->__elements = realloc(v->__elements, sizeof(void *) * size);
   v->__cap = size;
}


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

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

original_code:
void vi_free(v_itr_t* const itr) {
   free(itr);
}

canonical_original_code:
void vi_free(struct __v_itr_s *itr) {
   free(itr);
}

variable_types: struct __v_itr_s { struct __vect_s { int **__elements; unsigned long __elem_size; int __cap; int __size; } *vector; int pos; } *

user_defined_types: struct __v_itr_s { struct __vect_s *vector; int pos; }


decompiled_code:
_BOOL8 __fastcall vi_hasnext(_DWORD *a1)
{
_BOOL8 result; // rax

if ( a1 )
result = *(_DWORD *)(*(_QWORD *)a1 + 20LL) != a1[2];
else
result = 0LL;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func21(_DWORD *a1)
{
_BOOL8 result; // rax

if ( a1 )
result = *(_DWORD *)(*(_QWORD *)a1 + 20LL) != a1[2];
else
result = 0LL;
return result;
}

original_code:
int vi_hasnext(v_itr_t* const itr) {
   if(!itr) return !1;
   if(itr->pos == itr->vector->__size)
      return !1;
   return 1;
}

canonical_original_code:
int vi_hasnext(struct __v_itr_s *itr) {
   if(!itr) return !1;
   if(itr->pos == itr->vector->__size)
      return !1;
   return 1;
}


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

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

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

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

original_code:
int vi_hasprev(v_itr_t* const itr) {
   if(!itr) return !1;
   return (itr->pos ? 1 : !1);
}

canonical_original_code:
int vi_hasprev(struct __v_itr_s *itr) {
   if(!itr) return !1;
   return (itr->pos ? 1 : !1);
}


decompiled_code:
__int64 __fastcall vi_next(_DWORD *a1)
{
int v1; // eax
__int64 v2; // rdx

if ( !a1 )
return 0LL;
if ( !vi_hasnext(a1) )
return 0LL;
v1 = a1[2];
v2 = *(_QWORD *)(**(_QWORD **)a1 + 8LL * v1);
a1[2] = v1 + 1;
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func23(_DWORD *a1)
{
int v1; // eax
__int64 v2; // rdx

if ( !a1 )
return 0LL;
if ( !func21(a1) )
return 0LL;
v1 = a1[2];
v2 = *(_QWORD *)(**(_QWORD **)a1 + 8LL * v1);
a1[2] = v1 + 1;
return v2;
}

original_code:
void* vi_next(v_itr_t* const itr) {
   void *target;
   if(!itr) return ((void *)0);
   if(!vi_hasnext(itr)) return ((void *)0);
   target = itr->vector->__elements[itr->pos];
   itr->pos++;
   return target;
}

canonical_original_code:
void *vi_next(struct __v_itr_s *itr) {
   void *target;
   if(!itr) return ((void *)0);
   if(!vi_hasnext(itr)) return ((void *)0);
   target = itr->vector->__elements[itr->pos];
   itr->pos++;
   return target;
}


decompiled_code:
__int64 __fastcall vi_prev(__int64 a1)
{
int v1; // eax
__int64 v2; // rdx

if ( !a1 )
return 0LL;
if ( !vi_hasprev(a1) )
return 0LL;
v1 = *(_DWORD *)(a1 + 8);
v2 = *(_QWORD *)(**(_QWORD **)a1 + 8LL * v1);
*(_DWORD *)(a1 + 8) = v1 - 1;
return v2;
}

original_code:
void* vi_prev(v_itr_t* const itr) {
   void *target;
   if(!itr) return ((void *)0);
   if(!vi_hasprev(itr)) return ((void *)0);
   target = itr->vector->__elements[itr->pos];
   itr->pos--;
   return target;
}

canonical_original_code:
void *vi_prev(struct __v_itr_s *itr) {
   void *target;
   if(!itr) return ((void *)0);
   if(!vi_hasprev(itr)) return ((void *)0);
   target = itr->vector->__elements[itr->pos];
   itr->pos--;
   return target;
}


decompiled_code:
__int64 bst_root()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
return 0LL;
}

original_code:
void* bst_root(bst_t* const tree) {
   return ((void *)0);
}

canonical_original_code:
void *bst_root(struct __bst_s *tree) {
   return ((void *)0);
}

variable_types: struct __bst_s { void *__elem; unsigned long __elem_size; struct __bst_s *__left; struct __bst_s *__right; } *


decompiled_code:
__int64 __fastcall bst_size(__int64 a1)
{
return (unsigned int)-(a1 == 0);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return (unsigned int)-(a1 == 0);
}

original_code:
int bst_size(bst_t* const tree) {
   if(!tree) return -1;
   return 0;
}

canonical_original_code:
int bst_size(struct __bst_s *tree) {
   if(!tree) return -1;
   return 0;
}

user_defined_types: struct __bst_s { void *__elem; unsigned long __elem_size; struct __bst_s *__left; struct __bst_s *__right; }


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

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

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

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

original_code:
bst_t* bst_left(bst_t* const tree) {
   if(!tree) return ((void *)0);
   return tree->__left;
}

canonical_original_code:
struct __bst_s *bst_left(struct __bst_s *tree) {
   if(!tree) return ((void *)0);
   return tree->__left;
}

variable_types:
tree
struct __bst_s *

return_type: struct __bst_s { void *__elem; unsigned long __elem_size; struct __bst_s *__left; struct __bst_s *__right; } *


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

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

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

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

original_code:
bst_t* bst_right(bst_t* const tree) {
   if(!tree) return ((void *)0);
   return tree->__right;
}

canonical_original_code:
struct __bst_s *bst_right(struct __bst_s *tree) {
   if(!tree) return ((void *)0);
   return tree->__right;
}


decompiled_code:
__int64 bst_add()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func8()
{
return 0LL;
}

original_code:
int bst_add(bst_t* const tree, void* const elem) {
   if(!tree || !elem) return !1;
   return !1;
}

canonical_original_code:
int bst_add(struct __bst_s *tree, void *elem) {
   if(!tree || !elem) return !1;
   return !1;
}


decompiled_code:
__int64 bst_rem()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func9()
{
return 0LL;
}

original_code:
void* bst_rem(bst_t* const tree, void* const elem) {
   if(!tree || !elem) return ((void *)0);
   return ((void *)0);
}

canonical_original_code:
void *bst_rem(struct __bst_s *tree, void *elem) {
   if(!tree || !elem) return ((void *)0);
   return ((void *)0);
}


decompiled_code:
void *__fastcall bst_toarr(__int64 a1)
{
int v1; // eax

if ( !a1 )
return 0LL;
v1 = bst_size(a1);
return malloc(8LL * v1);
}

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

if ( !a1 )
return 0LL;
v1 = func3(a1);
return malloc(8LL * v1);
}

original_code:
void** bst_toarr(bst_t* const tree) {
   int **array;
   if(!tree) return ((void *)0);
   array = malloc(sizeof(void*) * bst_size(tree));
   if(!array) return ((void *)0);
   return (void**) array;
}

canonical_original_code:
void **bst_toarr(struct __bst_s *tree) {
   int **array;
   if(!tree) return ((void *)0);
   array = malloc(sizeof(void *) * bst_size(tree));
   if(!array) return ((void *)0);
   return (void **) array;
}


repo: bfabio/packddir

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

result = malloc(8uLL);
if ( !result )
{
fwrite("upackddir: malloc() failed.\n", 1uLL, 0x1CuLL, stderr);
exit(1);
}
result[1] = 0LL;
*result = 0LL;
return result;
}

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

result = malloc(8uLL);
if ( !result )
{
fwrite("upackddir: malloc() failed.\n", 1uLL, 0x1CuLL, stderr);
exit(1);
}
result[1] = 0LL;
*result = 0LL;
return result;
}

original_code:
list_t list_new()
{
 list_t l;
 l = malloc(sizeof(list_t));
 if (!l) {
  do { fprintf(stderr, "upackddir: " "malloc() failed.\n"); } while (0);
  exit(1);
 }
 l->first = l->last = ((void *)0);
 return l;
}

canonical_original_code:
struct list *list_new()
{
 struct list *l;
 l = malloc(sizeof(list_t));
 if (!l) {
  do { fprintf(stderr, "upackddir: " "malloc() failed.\n"); } while (0);
  exit(1);
 }
 l->first = l->last = ((void *)0);
 return l;
}

variable_types: struct list { struct list_node { struct list_node *prev; struct list_node *next; void *element; } *first; struct list_node *last; } *

user_defined_types: struct list { struct list_node *first; struct list_node *last; }


original_code:
void list_delete(list_t list, list_node_t node)
{
 if (list->first == list->last) {
  list->first = list->last = ((void *)0);
 } else if (node == list->first) {
  list->first = node->next;
 } else if (node == list->last) {
  list->last = node->prev;
 } else {
  node->prev->next = node->next;
  node->next->prev = node->prev;
 }
 free(node);
}

canonical_original_code:
void list_delete(struct list *list, struct list_node *node)
{
 if (list->first == list->last) {
  list->first = list->last = ((void *)0);
 } else if (node == list->first) {
  list->first = node->next;
 } else if (node == list->last) {
  list->last = node->prev;
 } else {
  node->prev->next = node->next;
  node->next->prev = node->prev;
 }
 free(node);
}

variable_types:
node
struct list_node *

user_defined_types: struct list_node { struct list_node *prev; struct list_node *next; void *element; }


decompiled_code:
_BOOL8 __fastcall list_empty(_QWORD *a1)
{
return *a1 != 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(_QWORD *a1)
{
return *a1 != 0LL;
}

original_code:
int list_empty(list_t list)
{
 return list->first ? 1 : 0;
}

canonical_original_code:
int list_empty(struct list *list)
{
 return list->first ? 1 : 0;
}


repo: bfeng/MG

decompiled_code:
int __fastcall check_err(int a1)
{
int result; // eax

if ( a1 )
{
puts("#Error relating to buffer create or desotry!!");
puts("#PLEASE ASK THE CODE WRITTER# if you see this.");
if ( a1 == -6 )
return puts("Out Of Host Memory");
if ( a1 >= -5 )
{
if ( a1 == -5 )
return puts("failure to allocate OpenCL resources on the device");
return puts("Impossible Error.");
}
if ( a1 != -38 )
{
if ( a1 == -36 )
return puts("invalid command queue");
return puts("Impossible Error.");
}
result = puts("Memroy Object Invalid");
}
return result;
}

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

if ( a1 )
{
puts("#Error relating to buffer create or desotry!!");
puts("#PLEASE ASK THE CODE WRITTER# if you see this.");
if ( a1 == -6 )
return puts("Out Of Host Memory");
if ( a1 >= -5 )
{
if ( a1 == -5 )
return puts("failure to allocate OpenCL resources on the device");
return puts("Impossible Error.");
}
if ( a1 != -38 )
{
if ( a1 == -36 )
return puts("invalid command queue");
return puts("Impossible Error.");
}
result = puts("Memroy Object Invalid");
}
return result;
}

original_code:
static void check_err(cl_int err)
{
  if(err != 0)
  {
    printf("#Error relating to buffer create or desotry!!\n");
    printf("#PLEASE ASK THE CODE WRITTER# if you see this.\n");
    switch(err)
    {
      case -38:
        printf("Memroy Object Invalid\n");
        break;
      case -5:
        printf("failure to allocate OpenCL resources on the device\n");
        break;
      case -6:
        printf("Out Of Host Memory\n");
        break;
      case -36:
        printf("invalid command queue\n");
        break;
      default:
        printf("Impossible Error.\n");
        break;
    }
  }
}

canonical_original_code:
static void check_err(int err)
{
  if(err != 0)
  {
    printf("#Error relating to buffer create or desotry!!\n");
    printf("#PLEASE ASK THE CODE WRITTER# if you see this.\n");
    switch(err)
    {
      case -38:
        printf("Memroy Object Invalid\n");
        break;
      case -5:
        printf("failure to allocate OpenCL resources on the device\n");
        break;
      case -6:
        printf("Out Of Host Memory\n");
        break;
      case -36:
        printf("invalid command queue\n");
        break;
      default:
        printf("Impossible Error.\n");
        break;
    }
  }
}

variable_types: err int


DisposeQueues

decompiled_code:
int DisposeQueues()
{
int v0; // eax
int v1; // eax
int v2; // eax
int v3; // eax

v0 = clReleaseMemObject(d_newJobs);
check_err(v0);
v1 = clReleaseMemObject(d_finishedJobs);
check_err(v1);
v2 = clReleaseMemObject(d_newJobs_array);
check_err(v2);
v3 = clReleaseMemObject(d_finishedJobs_array);
return check_err(v3);
}

canonical_decompiled_code:
int func3()
{
int v0; // eax
int v1; // eax
int v2; // eax
int v3; // eax

v0 = clReleaseMemObject(d_newJobs);
func0(v0);
v1 = clReleaseMemObject(d_finishedJobs);
func0(v1);
v2 = clReleaseMemObject(d_newJobs_array);
func0(v2);
v3 = clReleaseMemObject(d_finishedJobs_array);
return func0(v3);
}

original_code:
void DisposeQueues() {
   cl_int ERR;
   ERR = clReleaseMemObject(d_newJobs);
   check_err(ERR);
   ERR = clReleaseMemObject(d_finishedJobs);
   check_err(ERR);
   ERR = clReleaseMemObject(d_newJobs_array);
   check_err(ERR);
   ERR = clReleaseMemObject(d_finishedJobs_array);
   check_err(ERR);
}

canonical_original_code:
void DisposeQueues() {
   int ERR;
   ERR = clReleaseMemObject(d_newJobs);
   check_err(ERR);
   ERR = clReleaseMemObject(d_finishedJobs);
   check_err(ERR);
   ERR = clReleaseMemObject(d_newJobs_array);
   check_err(ERR);
   ERR = clReleaseMemObject(d_finishedJobs_array);
   check_err(ERR);
}

variable_types: ERR int


decompiled_code:
_BOOL8 __fastcall h_IsEmpty(_DWORD *a1)
{
return (a1[3] + 1) % a1[2] == a1[4];
}

original_code:
int h_IsEmpty(Queue Q) {
  return (Q->Rear+1)%Q->Capacity == Q->Front;
}

canonical_original_code:
int h_IsEmpty(struct QueueRecord *Q) {
  return (Q->Rear+1)%Q->Capacity == Q->Front;
}

variable_types: struct QueueRecord { struct JobDescription { int JobID; int JobType; int numThreads; int params; } *Array; int Capacity; int Rear; int Front; int ReadLock; } *

user_defined_types: struct QueueRecord { struct JobDescription *Array; int Capacity; int Rear; int Front; int ReadLock; }


decompiled_code:
_BOOL8 __fastcall h_IsFull(_DWORD *a1)
{
return (a1[3] + 2) % a1[2] == a1[4];
}

original_code:
int h_IsFull(Queue Q) {
  return (Q->Rear+2)%Q->Capacity == Q->Front;
}

canonical_original_code:
int h_IsFull(struct QueueRecord *Q) {
  return (Q->Rear+2)%Q->Capacity == Q->Front;
}

user_defined_types: struct JobDescription { int JobID; int JobType; int numThreads; int params; }


decompiled_code:
int __fastcall check_err3(int a1)
{
int result; // eax

if ( a1 )
{
puts("#Error relating to buffer read or write!!(SafeMemCopy)");
puts("#PLEASE ASK THE CODE WRITTER# if you see this.");
switch ( a1 )
{
case -59:
result = puts("invalid operation");
break;
case -57:
result = puts("invalid event list");
break;
case -38:
result = puts("Memroy Object Invalid");
break;
case -36:
result = puts("invalid command queue");
break;
case -34:
result = puts("invalid context");
break;
case -30:
result = puts("invalid value");
break;
case -6:
result = puts("Out Of Host Memory");
break;
case -5:
result = puts("failure to allocate OpenCL resources on the device");
break;
case -4:
result = puts("mem allocation failure");
break;
default:
result = puts("Impossible Error.");
break;
}
}
return result;
}

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

if ( a1 )
{
puts("#Error relating to buffer read or write!!(SafeMemCopy)");
puts("#PLEASE ASK THE CODE WRITTER# if you see this.");
switch ( a1 )
{
case -59:
result = puts("invalid operation");
break;
case -57:
result = puts("invalid event list");
break;
case -38:
result = puts("Memroy Object Invalid");
break;
case -36:
result = puts("invalid command queue");
break;
case -34:
result = puts("invalid context");
break;
case -30:
result = puts("invalid value");
break;
case -6:
result = puts("Out Of Host Memory");
break;
case -5:
result = puts("failure to allocate OpenCL resources on the device");
break;
case -4:
result = puts("mem allocation failure");
break;
default:
result = puts("Impossible Error.");
break;
}
}
return result;
}

original_code:
static void check_err3(cl_int err)
{
  if(err != 0)
  {
    printf("#Error relating to buffer read or write!!(SafeMemCopy)\n");
    printf("#PLEASE ASK THE CODE WRITTER# if you see this.\n");
    switch(err)
    {
      case -38:
        printf("Memroy Object Invalid\n");
        break;
      case -5:
        printf("failure to allocate OpenCL resources on the device\n");
        break;
      case -6:
        printf("Out Of Host Memory\n");
        break;
      case -36:
        printf("invalid command queue\n");
        break;
      case -34:
        printf("invalid context\n");
        break;
      case -30:
        printf("invalid value\n");
        break;
      case -57:
        printf("invalid event list\n");
        break;
      case -4:
        printf("mem allocation failure\n");
        break;
      case -59:
        printf("invalid operation\n");
        break;
      default:
        printf("Impossible Error.\n");
    }
  }
}

canonical_original_code:
static void check_err3(int err)
{
  if(err != 0)
  {
    printf("#Error relating to buffer read or write!!(SafeMemCopy)\n");
    printf("#PLEASE ASK THE CODE WRITTER# if you see this.\n");
    switch(err)
    {
      case -38:
        printf("Memroy Object Invalid\n");
        break;
      case -5:
        printf("failure to allocate OpenCL resources on the device\n");
        break;
      case -6:
        printf("Out Of Host Memory\n");
        break;
      case -36:
        printf("invalid command queue\n");
        break;
      case -34:
        printf("invalid context\n");
        break;
      case -30:
        printf("invalid value\n");
        break;
      case -57:
        printf("invalid event list\n");
        break;
      case -4:
        printf("mem allocation failure\n");
        break;
      case -59:
        printf("invalid operation\n");
        break;
      default:
        printf("Impossible Error.\n");
    }
  }
}


main

repo: bfeng/msh

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
_BYTE v3[2048]; // [rsp+0h] [rbp-1108h] BYREF
char v4[2048]; // [rsp+800h] [rbp-908h] BYREF
char v5[264]; // [rsp+1000h] [rbp-108h] BYREF

e_variables = (__int64)malloc(0x1000uLL);
read_profile(v3, argv);
init_sh(v3);
while ( 1 )
{
print_prompt_sign(v3);
read_cmdline(v5);
if ( !strcmp("exit", v5) )
break;
execute(v5, v4);
}
exit(0);
}

original_code:
int main(void)
{
  char cmdline[256];
  char *argv[256];
  char * profile[256];
 e_variables=(struct env_var *)malloc(sizeof(struct env_var)*256);
  read_profile(profile);
  init_sh(profile);
  while (1)
  {
    print_prompt_sign(profile);
    read_cmdline(cmdline);
    if (strcmp("exit", cmdline) == 0)
      exit(0);
    execute(cmdline, argv);
  }
  puts("Bye");
  return 0;
}

canonical_original_code:
int main()
{
  char cmdline[256];
  char *argv[256];
  char *profile[256];
 e_variables=(struct env_var *)malloc(sizeof(struct env_var)*256);
  read_profile(profile);
  init_sh(profile);
  while (1)
  {
    print_prompt_sign(profile);
    read_cmdline(cmdline);
    if (strcmp("exit", cmdline) == 0)
      exit(0);
    execute(cmdline, argv);
  }
  puts("Bye");
  return 0;
}

variable_types:
cmdline
char [256]

variable_types:
argv
char *[256]

variable_types:
profile
char *[256]

user_defined_types: struct env_var { char *name; int value; }


repo: bgdev/calc

decompiled_code:
__int64 __fastcall copy_x(_DWORD *a1)
{
__int64 result; // rax

result = (unsigned int)a1[1];
a1[4] = result;
a1[1] = *a1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(_DWORD *a1)
{
__int64 result; // rax

result = (unsigned int)a1[1];
a1[4] = result;
a1[1] = *a1;
return result;
}

original_code:
int
copy_x (struct calc *c)
{
  c->tmp = c->y;
  c->y = c->x;
  return c->tmp;
}

canonical_original_code:
int copy_x(struct calc *c)
{
  c->tmp = c->y;
  c->y = c->x;
  return c->tmp;
}

variable_types: struct calc { int x; int flags; int op; int tmp; } *


decompiled_code:
__int64 __fastcall is_operation(char a1)
{
return ((a1 & 0xFD) == 45) | (unsigned __int8)((unsigned __int8)(a1 - 42) <= 1u);
}

canonical_decompiled_code:
__int64 __fastcall func9(char a1)
{
return ((a1 & 0xFD) == 45) | (unsigned __int8)((unsigned __int8)(a1 - 42) <= 1u);
}

variable_types: c char


decompiled_code:
_BOOL8 __fastcall is_flag_on(__int64 a1, int a2)
{
return (*(_DWORD *)(a1 + 8) & a2) != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func11(__int64 a1, int a2)
{
return (*(_DWORD *)(a1 + 8) & a2) != 0;
}

original_code:
int
is_flag_on (struct calc *c, int flag)
{
  return !!(c->flags & flag);
}

canonical_original_code:
int is_flag_on(struct calc *c, int flag)
{
  return !!(c->flags & flag);
}

variable_types: flag int

user_defined_types: struct calc { int x; int flags; int op; int tmp; }


decompiled_code:
_BOOL8 __fastcall set_flag(__int64 a1, int a2, int a3)
{
_BOOL8 result; // rax
int v5; // ebx

result = is_flag_on(a1, a2);
if ( a3 )
v5 = *(_DWORD *)(a1 + 8) | a2;
else
v5 = *(_DWORD *)(a1 + 8) & ~a2;
*(_DWORD *)(a1 + 8) = v5;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func12(__int64 a1, int a2, int a3)
{
_BOOL8 result; // rax
int v5; // ebx

result = func11(a1, a2);
if ( a3 )
v5 = *(_DWORD *)(a1 + 8) | a2;
else
v5 = *(_DWORD *)(a1 + 8) & ~a2;
*(_DWORD *)(a1 + 8) = v5;
return result;
}

original_code:
int
set_flag (struct calc *c, int flag, int on)
{
  int prev = is_flag_on (c, flag);
  if (on)
    c->flags |= flag;
  else
    c->flags &= ~flag;
  return prev;
}

canonical_original_code:
int set_flag(struct calc *c, int flag, int on)
{
  int prev = is_flag_on (c, flag);
  if (on)
    c->flags |= flag;
  else
    c->flags &= ~flag;
  return prev;
}

variable_types: on int

variable_types: prev int


eq

decompiled_code:
__int64 __fastcall eq(int *a1)
{
unsigned int v1; // eax
int v2; // ecx
unsigned int v4; // eax

v1 = a1[3];
switch ( v1 )
{
case '*':
*a1 *= a1[1];
break;
case '+':
if ( set_flag((__int64)a1, 16, 1) )
v4 = a1[1];
else
v4 = copy_x(a1);
*a1 += v4;
break;
case '-':
if ( !set_flag((__int64)a1, 16, 1) )
swap_xy((unsigned int *)a1);
*a1 -= a1[1];
break;
case '/':
if ( !set_flag((__int64)a1, 16, 1) )
swap_xy((unsigned int *)a1);
v2 = a1[1];
if ( v2 )
*a1 /= v2;
else
set_flag((__int64)a1, 2, 1);
break;
}
set_flag((__int64)a1, 8, 0);
return (unsigned int)*a1;
}

canonical_decompiled_code:
__int64 __fastcall func13(int *a1)
{
unsigned int v1; // eax
int v2; // ecx
unsigned int v4; // eax

v1 = a1[3];
switch ( v1 )
{
case '*':
*a1 *= a1[1];
break;
case '+':
if ( func12((__int64)a1, 16, 1) )
v4 = a1[1];
else
v4 = func8(a1);
*a1 += v4;
break;
case '-':
if ( !func12((__int64)a1, 16, 1) )
func10((unsigned int *)a1);
*a1 -= a1[1];
break;
case '/':
if ( !func12((__int64)a1, 16, 1) )
func10((unsigned int *)a1);
v2 = a1[1];
if ( v2 )
*a1 /= v2;
else
func12((__int64)a1, 2, 1);
break;
}
func12((__int64)a1, 8, 0);
return (unsigned int)*a1;
}

original_code:
int
eq (struct calc *c)
{
  if (c->op == '*')
    c->x *= c->y;
  else if (c->op == '+')
    c->x += !set_flag (c, 0x10, 1) ? copy_x (c) : c->y;
  else if (c->op == '-')
    {
      if (!set_flag (c, 0x10, 1))
        swap_xy (c);
      c->x -= c->y;
    }
  else if (c->op == '/')
    {
      if (!set_flag (c, 0x10, 1))
        swap_xy (c);
      if (c->y == 0)
        set_flag (c, 0x2, 1);
      else
        c->x /= c->y;
    }
  set_flag (c, 0x8, 0);
  return c->x;
}

canonical_original_code:
int eq(struct calc *c)
{
  if (c->op == '*')
    c->x *= c->y;
  else if (c->op == '+')
    c->x += !set_flag (c, 0x10, 1) ? copy_x (c) : c->y;
  else if (c->op == '-')
    {
      if (!set_flag (c, 0x10, 1))
        swap_xy (c);
      c->x -= c->y;
    }
  else if (c->op == '/')
    {
      if (!set_flag (c, 0x10, 1))
        swap_xy (c);
      if (c->y == 0)
        set_flag (c, 0x2, 1);
      else
        c->x /= c->y;
    }
  set_flag (c, 0x8, 0);
  return c->x;
}


decompiled_code:
__int64 __fastcall calc_process_cmd(int *a1, char a2)
{
_BOOL4 v2; // edx
__int64 result; // rax

v2 = is_flag_on((__int64)a1, 2);
result = 0LL;
if ( !v2 )
{
if ( ((*__ctype_b_loc())[a2] & 0x800) != 0 )
{
if ( set_flag((__int64)a1, 1, 1) )
{
*a1 = a2 + 10 * *a1 - 48;
}
else
{
*a1 = a2 - 48;
set_flag((__int64)a1, 8, 1);
}
}
else if ( (unsigned int)is_operation(a2) )
{
if ( is_flag_on((__int64)a1, 8) )
eq(a1);
a1[1] = *a1;
a1[3] = a2;
set_flag((__int64)a1, 1, 0);
set_flag((__int64)a1, 16, 0);
}
else if ( a2 == 61 )
{
eq(a1);
set_flag((__int64)a1, 1, 0);
}
result = (unsigned int)*a1;
}
return result;
}

original_code:
int
calc_process_cmd (struct calc *c, char cmd)
{
  if (is_flag_on (c, 0x2))
    return 0;
  if (((*__ctype_b_loc ())[(int) ((cmd))] & (unsigned short int) _ISdigit))
    {
      if (!set_flag (c, 0x1, 1))
        {
          c->x = cmd - '0';
          set_flag (c, 0x8, 1);
        }
      else
        c->x = c->x * 10 + (cmd - '0');
    }
  else if (is_operation (cmd))
    {
      if (is_flag_on (c, 0x8))
        eq (c);
      c->y = c->x;
      c->op = cmd;
      set_flag (c, 0x1, 0);
      set_flag (c, 0x10, 0);
    }
  else if (cmd == '=')
    {
      eq (c);
      set_flag (c, 0x1, 0);
    }
  return c->x;
}

canonical_original_code:
int calc_process_cmd(struct calc *c, char cmd)
{
  if (is_flag_on (c, 0x2))
    return 0;
  if (((*__ctype_b_loc ())[(int) ((cmd))] & (unsigned short) _ISdigit))
    {
      if (!set_flag (c, 0x1, 1))
        {
          c->x = cmd - '0';
          set_flag (c, 0x8, 1);
        }
      else
        c->x = c->x * 10 + (cmd - '0');
    }
  else if (is_operation (cmd))
    {
      if (is_flag_on (c, 0x8))
        eq (c);
      c->y = c->x;
      c->op = cmd;
      set_flag (c, 0x1, 0);
      set_flag (c, 0x10, 0);
    }
  else if (cmd == '=')
    {
      eq (c);
      set_flag (c, 0x1, 0);
    }
  return c->x;
}

variable_types: cmd char


decompiled_code:
__int64 __fastcall calc_process_line(int *a1, char *a2)
{
char *v2; // rbx
char v3; // si
__int64 result; // rax

v2 = a2 + 1;
v3 = *a2;
if ( !v3 )
return 0LL;
do
{
result = calc_process_cmd(a1, v3);
v3 = *v2++;
}
while ( v3 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func15(int *a1, char *a2)
{
char *v2; // rbx
char v3; // si
__int64 result; // rax

v2 = a2 + 1;
v3 = *a2;
if ( !v3 )
return 0LL;
do
{
result = func14(a1, v3);
v3 = *v2++;
}
while ( v3 );
return result;
}

original_code:
int
calc_process_line (struct calc *calc, char *line)
{
  char c;
  int res;
  while ((c = *line++) != '\0')
    res = calc_process_cmd (calc, c);
  return res;
}

canonical_original_code:
int calc_process_line(struct calc *calc, char *line)
{
  char c;
  int res;
  while ((c = *line++) != '\0')
    res = calc_process_cmd (calc, c);
  return res;
}

variable_types:
line
char *

variable_types: res int


repo: bgnori/solverForPuzzleA

decompiled_code:
const char *test_fact_0()
{
const char *result; // rax

result = "test_fact_0";
if ( fact == 1 )
result = 0LL;
return result;
}

canonical_decompiled_code:
const char *func0()
{
const char *result; // rax

result = "test_fact_0";
if ( fact == 1 )
result = 0LL;
return result;
}

original_code:
static
const_char_p
test_fact_0(void)
{
    if (fact[0] != 1)
        return __func__;
    return ((void *)0);
}

canonical_original_code:
static char *test_fact_0()
{
    if (fact[0] != 1)
        return __func__;
    return ((void *)0);
}

return_type: char *


decompiled_code:
const char *test_fact_1()
{
const char *result; // rax

result = "test_fact_1";
if ( *((_DWORD *)&fact + 1) == 1 )
result = 0LL;
return result;
}

canonical_decompiled_code:
const char *func1()
{
const char *result; // rax

result = "test_fact_1";
if ( *((_DWORD *)&fact + 1) == 1 )
result = 0LL;
return result;
}

original_code:
static
const_char_p
test_fact_1(void)
{
    if (fact[1] != 1)
        return __func__;
    return ((void *)0);
}

canonical_original_code:
static char *test_fact_1()
{
    if (fact[1] != 1)
        return __func__;
    return ((void *)0);
}


decompiled_code:
const char *test_fact_6()
{
const char *result; // rax

result = "test_fact_6";
if ( fact[6] == 720 )
result = 0LL;
return result;
}

canonical_decompiled_code:
const char *func2()
{
const char *result; // rax

result = "test_fact_6";
if ( fact[6] == 720 )
result = 0LL;
return result;
}

original_code:
static
const_char_p
test_fact_6(void)
{
    if (fact[6] != 720)
        return __func__;
    return ((void *)0);
}

canonical_original_code:
static char *test_fact_6()
{
    if (fact[6] != 720)
        return __func__;
    return ((void *)0);
}


dfact

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

result = 1LL;
if ( a1 )
result = a1 * (unsigned int)dfact((unsigned int)(a1 - 1));
return result;
}

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

result = 1LL;
if ( a1 )
result = a1 * (unsigned int)func3((unsigned int)(a1 - 1));
return result;
}

original_code:
static
int
dfact(int n)
{
    if(n==0)
        return 1;
    return dfact(n-1) * n;
}

variable_types: n int


decompiled_code:
const char *test_fact_x()
{
__int64 v0; // rbx

v0 = 0LL;
while ( fact[v0] == (unsigned int)dfact(v0) )
{
if ( ++v0 == 11 )
return 0LL;
}
return "test_fact_x";
}

canonical_decompiled_code:
const char *func4()
{
__int64 v0; // rbx

v0 = 0LL;
while ( fact[v0] == (unsigned int)func3(v0) )
{
if ( ++v0 == 11 )
return 0LL;
}
return "test_fact_x";
}

original_code:
static
const_char_p
test_fact_x(void)
{
    int i;
    for (i=0; i < 11; i++){
        if (fact[i] != dfact(i))
            return __func__;
    }
    return ((void *)0);
}

canonical_original_code:
static char *test_fact_x()
{
    int i;
    for (i=0; i < 11; i++){
        if (fact[i] != dfact(i))
            return __func__;
    }
    return ((void *)0);
}

variable_types: i int


decompiled_code:
const char *test_with_bugs_all()
{
bool v0; // zf
const char *result; // rax
_BYTE v2[656]; // [rsp+0h] [rbp-328h] BYREF
_DWORD v3[38]; // [rsp+290h] [rbp-98h] BYREF

setUpBugTiles(v3);
setUpTrivialPlacemnet((__int64)v2);
v0 = (unsigned int)failed_at(v3, v2) == -1;
result = "test_with_bugs_all";
if ( v0 )
result = 0LL;
return result;
}

canonical_decompiled_code:
const char *func6()
{
bool v0; // zf
const char *result; // rax
_BYTE v2[656]; // [rsp+0h] [rbp-328h] BYREF
_DWORD v3[38]; // [rsp+290h] [rbp-98h] BYREF

func5(v3);
setUpTrivialPlacemnet((__int64)v2);
v0 = (unsigned int)failed_at(v3, v2) == -1;
result = "test_with_bugs_all";
if ( v0 )
result = 0LL;
return result;
}

original_code:
static
const_char_p
test_with_bugs_all(void)
{
    TTile tiles[9];
    TPlacement placement[9];
    setUpBugTiles(tiles);
    setUpTrivialPlacemnet(placement);
    if(failed_at(tiles, placement) != -1)
        return __func__;
    return ((void *)0);
}

canonical_original_code:
static char *test_with_bugs_all()
{
    struct TTile tiles[9];
    struct TPlacement placement[9];
    setUpBugTiles(tiles);
    setUpTrivialPlacemnet(placement);
    if(failed_at(tiles, placement) != -1)
        return __func__;
    return ((void *)0);
}

variable_types:
tiles
struct TTile { int fPattern[4]; } [9]

variable_types: struct TPlacement { int fPermutation[9]; int fRotation[9]; } [9]


decompiled_code:
const char *test_perfhash_max()
{
__int64 v0; // rax
int v2[14]; // [rsp+0h] [rbp-38h] BYREF

perfhash((unsigned int)(fact[9] - 1), v2);
v0 = 0LL;
while ( v2[v0] == 8 - (_DWORD)v0 )
{
if ( ++v0 == 9 )
return 0LL;
}
return "test_perfhash_max";
}

canonical_decompiled_code:
const char *func7()
{
__int64 v0; // rax
int v2[14]; // [rsp+0h] [rbp-38h] BYREF

perfhash((unsigned int)(fact[9] - 1), v2);
v0 = 0LL;
while ( v2[v0] == 8 - (_DWORD)v0 )
{
if ( ++v0 == 9 )
return 0LL;
}
return "test_perfhash_max";
}

original_code:
static
const_char_p
test_perfhash_max(void)
{
    int buf[9];
    int i;
    perfhash(fact[9] - 1, buf);
    for(i=0; i < 9; i++){
        if (buf[i] != 8 - i){
            return __func__;
        }
    }
    return ((void *)0);
}

canonical_original_code:
static char *test_perfhash_max()
{
    int buf[9];
    int i;
    perfhash(fact[9] - 1, buf);
    for(i=0; i < 9; i++){
        if (buf[i] != 8 - i){
            return __func__;
        }
    }
    return ((void *)0);
}

variable_types:
buf
int [9]


decompiled_code:
const char *test_perfhash_0()
{
__int64 v0; // rax
int v2[14]; // [rsp+0h] [rbp-38h] BYREF

perfhash(0LL, v2);
v0 = 0LL;
while ( v2[v0] == (_DWORD)v0 )
{
if ( ++v0 == 9 )
return 0LL;
}
return "test_perfhash_0";
}

canonical_decompiled_code:
const char *func8()
{
__int64 v0; // rax
int v2[14]; // [rsp+0h] [rbp-38h] BYREF

perfhash(0LL, v2);
v0 = 0LL;
while ( v2[v0] == (_DWORD)v0 )
{
if ( ++v0 == 9 )
return 0LL;
}
return "test_perfhash_0";
}

original_code:
static
const_char_p
test_perfhash_0(void)
{
    int buf[9];
    int i;
    perfhash(0, buf);
    for(i=0; i < 9; i++){
        if (buf[i] != i){
            return __func__;
        }
    }
    return ((void *)0);
}

canonical_original_code:
static char *test_perfhash_0()
{
    int buf[9];
    int i;
    perfhash(0, buf);
    for(i=0; i < 9; i++){
        if (buf[i] != i){
            return __func__;
        }
    }
    return ((void *)0);
}


decompiled_code:
const char *test_with_bugs_1_left_step3()
{
int v0; // ebx
bool v1; // zf
const char *result; // rax
_BYTE v3[656]; // [rsp+0h] [rbp-328h] BYREF
_DWORD v4[38]; // [rsp+290h] [rbp-98h] BYREF

setUpBugTiles(v4);
setUpTrivialPlacemnet((__int64)v3);
v0 = get_pattern(0LL, v4, v3, 3LL);
v1 = v0 == (unsigned int)get_pattern(1LL, v4, v3, 1LL);
result = "test_with_bugs_1_left_step3";
if ( v1 )
result = 0LL;
return result;
}

canonical_decompiled_code:
const char *func9()
{
int v0; // ebx
bool v1; // zf
const char *result; // rax
_BYTE v3[656]; // [rsp+0h] [rbp-328h] BYREF
_DWORD v4[38]; // [rsp+290h] [rbp-98h] BYREF

func5(v4);
setUpTrivialPlacemnet((__int64)v3);
v0 = get_pattern(0LL, v4, v3, 3LL);
v1 = v0 == (unsigned int)get_pattern(1LL, v4, v3, 1LL);
result = "test_with_bugs_1_left_step3";
if ( v1 )
result = 0LL;
return result;
}

original_code:
static
const_char_p
test_with_bugs_1_left_step3(void)
{
    TTile tiles[9];
    TPlacement placement[9];
    setUpBugTiles(tiles);
    setUpTrivialPlacemnet(placement);
    if ((get_pattern(0, tiles, placement, 3) ^ get_pattern(1, tiles, placement, 1) ^ (8+4+2+1)) != (8+4+2+1))
        return __func__;
    return ((void *)0);
}

canonical_original_code:
static char *test_with_bugs_1_left_step3()
{
    struct TTile tiles[9];
    struct TPlacement placement[9];
    setUpBugTiles(tiles);
    setUpTrivialPlacemnet(placement);
    if ((get_pattern(0, tiles, placement, 3) ^ get_pattern(1, tiles, placement, 1) ^ (8+4+2+1)) != (8+4+2+1))
        return __func__;
    return ((void *)0);
}

user_defined_types: struct TPlacement { int fPermutation[9]; int fRotation[9]; }


decompiled_code:
const char *test_with_bugs_1_left_step0()
{
bool v0; // zf
const char *result; // rax

v0 = (unsigned int)idx2h(1LL) == 0;
result = "test_with_bugs_1_left_step0";
if ( !v0 )
result = 0LL;
return result;
}

canonical_decompiled_code:
const char *func10()
{
bool v0; // zf
const char *result; // rax

v0 = (unsigned int)idx2h(1LL) == 0;
result = "test_with_bugs_1_left_step0";
if ( !v0 )
result = 0LL;
return result;
}

original_code:
static
const_char_p
test_with_bugs_1_left_step0(void)
{
    if(idx2h(1) == 0)
        return __func__;
    return ((void *)0);
}

canonical_original_code:
static char *test_with_bugs_1_left_step0()
{
    if(idx2h(1) == 0)
        return __func__;
    return ((void *)0);
}


decompiled_code:
const char *test_with_bugs_1_left_step2()
{
int v0; // ebx
unsigned int v1; // eax
bool v2; // zf
const char *result; // rax

v0 = idx2h(1LL);
v1 = idx2v(1LL);
v2 = (unsigned int)hv2idx((unsigned int)(v0 - 1), v1) == 0;
result = "test_with_bugs_1_left_step2";
if ( v2 )
result = 0LL;
return result;
}

canonical_decompiled_code:
const char *func11()
{
int v0; // ebx
unsigned int v1; // eax
bool v2; // zf
const char *result; // rax

v0 = idx2h(1LL);
v1 = idx2v(1LL);
v2 = (unsigned int)hv2idx((unsigned int)(v0 - 1), v1) == 0;
result = "test_with_bugs_1_left_step2";
if ( v2 )
result = 0LL;
return result;
}

original_code:
static
const_char_p
test_with_bugs_1_left_step2(void)
{
    int h, v, n, idx;
    idx = 1;
    h = idx2h(idx);
    v = idx2v(idx);
    n = hv2idx(h - 1, v);
    if ( n != 0)
        return __func__;
    return ((void *)0);
}

canonical_original_code:
static char *test_with_bugs_1_left_step2()
{
    int h; int v; int n; int idx;
    idx = 1;
    h = idx2h(idx);
    v = idx2v(idx);
    n = hv2idx(h - 1, v);
    if ( n != 0)
        return __func__;
    return ((void *)0);
}

variable_types: h int

variable_types: v int

variable_types: idx int


decompiled_code:
const char *test_with_bugs_1_left()
{
bool v0; // zf
const char *result; // rax
_BYTE v2[656]; // [rsp+0h] [rbp-328h] BYREF
_DWORD v3[38]; // [rsp+290h] [rbp-98h] BYREF

setUpBugTiles(v3);
setUpTrivialPlacemnet((__int64)v2);
v0 = (unsigned __int8)ok_left(1LL, v3, v2) == 0;
result = "test_with_bugs_1_left";
if ( !v0 )
result = 0LL;
return result;
}

canonical_decompiled_code:
const char *func12()
{
bool v0; // zf
const char *result; // rax
_BYTE v2[656]; // [rsp+0h] [rbp-328h] BYREF
_DWORD v3[38]; // [rsp+290h] [rbp-98h] BYREF

func5(v3);
setUpTrivialPlacemnet((__int64)v2);
v0 = (unsigned __int8)ok_left(1LL, v3, v2) == 0;
result = "test_with_bugs_1_left";
if ( !v0 )
result = 0LL;
return result;
}

original_code:
static
const_char_p
test_with_bugs_1_left(void)
{
    TTile tiles[9];
    TPlacement placement[9];
    setUpBugTiles(tiles);
    setUpTrivialPlacemnet(placement);
    if(!ok_left(1, tiles, placement))
        return __func__;
    return ((void *)0);
}

canonical_original_code:
static char *test_with_bugs_1_left()
{
    struct TTile tiles[9];
    struct TPlacement placement[9];
    setUpBugTiles(tiles);
    setUpTrivialPlacemnet(placement);
    if(!ok_left(1, tiles, placement))
        return __func__;
    return ((void *)0);
}


decompiled_code:
const char *test_ok_left_mismatch_1()
{
bool v0; // zf
const char *result; // rax
_BYTE v2[656]; // [rsp+0h] [rbp-328h] BYREF
_DWORD v3[38]; // [rsp+290h] [rbp-98h] BYREF

setUpBadTiles(v3);
setUpTrivialPlacemnet((__int64)v2);
v0 = (unsigned __int8)ok_left(1LL, v3, v2) == 0;
result = "test_ok_left_mismatch_1";
if ( v0 )
result = 0LL;
return result;
}

canonical_decompiled_code:
const char *func13()
{
bool v0; // zf
const char *result; // rax
_BYTE v2[656]; // [rsp+0h] [rbp-328h] BYREF
_DWORD v3[38]; // [rsp+290h] [rbp-98h] BYREF

setUpBadTiles(v3);
setUpTrivialPlacemnet((__int64)v2);
v0 = (unsigned __int8)ok_left(1LL, v3, v2) == 0;
result = "test_ok_left_mismatch_1";
if ( v0 )
result = 0LL;
return result;
}

original_code:
static
const_char_p
test_ok_left_mismatch_1(void)
{
    TTile tiles[9];
    TPlacement placement[9];
    setUpBadTiles(tiles);
    setUpTrivialPlacemnet(placement);
    if(ok_left(1, tiles, placement))
        return __func__;
    return ((void *)0);
}

canonical_original_code:
static char *test_ok_left_mismatch_1()
{
    struct TTile tiles[9];
    struct TPlacement placement[9];
    setUpBadTiles(tiles);
    setUpTrivialPlacemnet(placement);
    if(ok_left(1, tiles, placement))
        return __func__;
    return ((void *)0);
}


decompiled_code:
const char *test_ok_left_match_1()
{
bool v0; // zf
const char *result; // rax
_BYTE v2[656]; // [rsp+0h] [rbp-328h] BYREF
_DWORD v3[38]; // [rsp+290h] [rbp-98h] BYREF

setUpEasyTiles(v3);
setUpTrivialPlacemnet((__int64)v2);
v0 = (unsigned __int8)ok_left(1LL, v3, v2) == 0;
result = "test_ok_left_match_1";
if ( !v0 )
result = 0LL;
return result;
}

canonical_decompiled_code:
const char *func14()
{
bool v0; // zf
const char *result; // rax
_BYTE v2[656]; // [rsp+0h] [rbp-328h] BYREF
_DWORD v3[38]; // [rsp+290h] [rbp-98h] BYREF

setUpEasyTiles(v3);
setUpTrivialPlacemnet((__int64)v2);
v0 = (unsigned __int8)ok_left(1LL, v3, v2) == 0;
result = "test_ok_left_match_1";
if ( !v0 )
result = 0LL;
return result;
}

original_code:
static
const_char_p
test_ok_left_match_1(void)
{
    TTile tiles[9];
    TPlacement placement[9];
    setUpEasyTiles(tiles);
    setUpTrivialPlacemnet(placement);
    if(!ok_left(1, tiles, placement))
        return __func__;
    return ((void *)0);
}

canonical_original_code:
static char *test_ok_left_match_1()
{
    struct TTile tiles[9];
    struct TPlacement placement[9];
    setUpEasyTiles(tiles);
    setUpTrivialPlacemnet(placement);
    if(!ok_left(1, tiles, placement))
        return __func__;
    return ((void *)0);
}


decompiled_code:
const char *test_ok_left_match_0()
{
bool v0; // zf
const char *result; // rax
_BYTE v2[656]; // [rsp+0h] [rbp-328h] BYREF
_DWORD v3[38]; // [rsp+290h] [rbp-98h] BYREF

setUpEasyTiles(v3);
setUpTrivialPlacemnet((__int64)v2);
v0 = (unsigned __int8)ok_left(0LL, v3, v2) == 0;
result = "test_ok_left_match_0";
if ( !v0 )
result = 0LL;
return result;
}

canonical_decompiled_code:
const char *func15()
{
bool v0; // zf
const char *result; // rax
_BYTE v2[656]; // [rsp+0h] [rbp-328h] BYREF
_DWORD v3[38]; // [rsp+290h] [rbp-98h] BYREF

setUpEasyTiles(v3);
setUpTrivialPlacemnet((__int64)v2);
v0 = (unsigned __int8)ok_left(0LL, v3, v2) == 0;
result = "test_ok_left_match_0";
if ( !v0 )
result = 0LL;
return result;
}

original_code:
static
const_char_p
test_ok_left_match_0(void)
{
    TTile tiles[9];
    TPlacement placement[9];
    setUpEasyTiles(tiles);
    setUpTrivialPlacemnet(placement);
    if(!ok_left(0, tiles, placement))
        return __func__;
    return ((void *)0);
}

canonical_original_code:
static char *test_ok_left_match_0()
{
    struct TTile tiles[9];
    struct TPlacement placement[9];
    setUpEasyTiles(tiles);
    setUpTrivialPlacemnet(placement);
    if(!ok_left(0, tiles, placement))
        return __func__;
    return ((void *)0);
}


decompiled_code:
const char *test_ok_up_mismatch_3()
{
bool v0; // zf
const char *result; // rax
_BYTE v2[656]; // [rsp+0h] [rbp-328h] BYREF
_DWORD v3[38]; // [rsp+290h] [rbp-98h] BYREF

setUpBadTiles(v3);
setUpTrivialPlacemnet((__int64)v2);
v0 = (unsigned __int8)ok_up(3LL, v3, v2) == 0;
result = "test_ok_up_mismatch_3";
if ( v0 )
result = 0LL;
return result;
}

canonical_decompiled_code:
const char *func16()
{
bool v0; // zf
const char *result; // rax
_BYTE v2[656]; // [rsp+0h] [rbp-328h] BYREF
_DWORD v3[38]; // [rsp+290h] [rbp-98h] BYREF

setUpBadTiles(v3);
setUpTrivialPlacemnet((__int64)v2);
v0 = (unsigned __int8)ok_up(3LL, v3, v2) == 0;
result = "test_ok_up_mismatch_3";
if ( v0 )
result = 0LL;
return result;
}

original_code:
static
const_char_p
test_ok_up_mismatch_3(void)
{
    TTile tiles[9];
    TPlacement placement[9];
    setUpBadTiles(tiles);
    setUpTrivialPlacemnet(placement);
    if(ok_up(3, tiles, placement))
        return __func__;
    return ((void *)0);
}

canonical_original_code:
static char *test_ok_up_mismatch_3()
{
    struct TTile tiles[9];
    struct TPlacement placement[9];
    setUpBadTiles(tiles);
    setUpTrivialPlacemnet(placement);
    if(ok_up(3, tiles, placement))
        return __func__;
    return ((void *)0);
}


decompiled_code:
const char *test_ok_up_match_3()
{
bool v0; // zf
const char *result; // rax
_BYTE v2[656]; // [rsp+0h] [rbp-328h] BYREF
_DWORD v3[38]; // [rsp+290h] [rbp-98h] BYREF

setUpEasyTiles(v3);
setUpTrivialPlacemnet((__int64)v2);
v0 = (unsigned __int8)ok_up(0LL, v3, v2) == 0;
result = "test_ok_up_match_3";
if ( !v0 )
result = 0LL;
return result;
}

canonical_decompiled_code:
const char *func17()
{
bool v0; // zf
const char *result; // rax
_BYTE v2[656]; // [rsp+0h] [rbp-328h] BYREF
_DWORD v3[38]; // [rsp+290h] [rbp-98h] BYREF

setUpEasyTiles(v3);
setUpTrivialPlacemnet((__int64)v2);
v0 = (unsigned __int8)ok_up(0LL, v3, v2) == 0;
result = "test_ok_up_match_3";
if ( !v0 )
result = 0LL;
return result;
}

original_code:
static
const_char_p
test_ok_up_match_3(void)
{
    TTile tiles[9];
    TPlacement placement[9];
    setUpEasyTiles(tiles);
    setUpTrivialPlacemnet(placement);
    if(!ok_up(0, tiles, placement))
        return __func__;
    return ((void *)0);
}

canonical_original_code:
static char *test_ok_up_match_3()
{
    struct TTile tiles[9];
    struct TPlacement placement[9];
    setUpEasyTiles(tiles);
    setUpTrivialPlacemnet(placement);
    if(!ok_up(0, tiles, placement))
        return __func__;
    return ((void *)0);
}


decompiled_code:
const char *test_ok_up_match_0()
{
bool v0; // zf
const char *result; // rax
_BYTE v2[656]; // [rsp+0h] [rbp-328h] BYREF
_DWORD v3[38]; // [rsp+290h] [rbp-98h] BYREF

setUpEasyTiles(v3);
setUpTrivialPlacemnet((__int64)v2);
v0 = (unsigned __int8)ok_up(0LL, v3, v2) == 0;
result = "test_ok_up_match_0";
if ( !v0 )
result = 0LL;
return result;
}

canonical_decompiled_code:
const char *func18()
{
bool v0; // zf
const char *result; // rax
_BYTE v2[656]; // [rsp+0h] [rbp-328h] BYREF
_DWORD v3[38]; // [rsp+290h] [rbp-98h] BYREF

setUpEasyTiles(v3);
setUpTrivialPlacemnet((__int64)v2);
v0 = (unsigned __int8)ok_up(0LL, v3, v2) == 0;
result = "test_ok_up_match_0";
if ( !v0 )
result = 0LL;
return result;
}

original_code:
static
const_char_p
test_ok_up_match_0(void)
{
    TTile tiles[9];
    TPlacement placement[9];
    setUpEasyTiles(tiles);
    setUpTrivialPlacemnet(placement);
    if(!ok_up(0, tiles, placement))
        return __func__;
    return ((void *)0);
}

canonical_original_code:
static char *test_ok_up_match_0()
{
    struct TTile tiles[9];
    struct TPlacement placement[9];
    setUpEasyTiles(tiles);
    setUpTrivialPlacemnet(placement);
    if(!ok_up(0, tiles, placement))
        return __func__;
    return ((void *)0);
}


decompiled_code:
const char *test_rotate_fail()
{
char v0; // dl
const char *result; // rax
int v2; // edx
__int64 i; // rax
__int64 v4[4]; // [rsp+0h] [rbp-38h] BYREF
int v5; // [rsp+20h] [rbp-18h]

v4[0] = 0x300000000LL;
v4[1] = 0LL;
v4[2] = 0LL;
v4[3] = 0LL;
v5 = 0;
v0 = rotate(1LL, v4);
result = "test_rotate_fail";
if ( !v0 )
{
v2 = 1;
for ( i = 0LL; ; ++i )
{
if ( (_DWORD)i == 1 )
{
if ( HIDWORD(v4[0]) != 3 )
return "test_rotate_fail";
}
else
{
if ( *((_DWORD *)v4 + i) )
return "test_rotate_fail";
if ( v2 > 8 )
return 0LL;
}
++v2;
}
}
return result;
}

canonical_decompiled_code:
const char *func19()
{
char v0; // dl
const char *result; // rax
int v2; // edx
__int64 i; // rax
__int64 v4[4]; // [rsp+0h] [rbp-38h] BYREF
int v5; // [rsp+20h] [rbp-18h]

v4[0] = 0x300000000LL;
v4[1] = 0LL;
v4[2] = 0LL;
v4[3] = 0LL;
v5 = 0;
v0 = rotate(1LL, v4);
result = "test_rotate_fail";
if ( !v0 )
{
v2 = 1;
for ( i = 0LL; ; ++i )
{
if ( (_DWORD)i == 1 )
{
if ( HIDWORD(v4[0]) != 3 )
return "test_rotate_fail";
}
else
{
if ( *((_DWORD *)v4 + i) )
return "test_rotate_fail";
if ( v2 > 8 )
return 0LL;
}
++v2;
}
}
return result;
}

original_code:
static
const_char_p
test_rotate_fail(void)
{
    int buf[9] = {0,3,0,0,0,0,0,0,0,};
    int i;
    _Bool ret;
    ret = rotate(1, buf);
    if(ret){
        return __func__;
    }
    for(i=0; i < 9; i++){
        if (i == 1) {
            if (buf[i] != 3){
                return __func__;
            }
        }else{
            if (buf[i] != 0){
                return __func__;
            }
        }
    }
    return ((void *)0);
}

canonical_original_code:
static char *test_rotate_fail()
{
    int buf[9] = {0,3,0,0,0,0,0,0,0,};
    int i;
    _Bool ret;
    ret = rotate(1, buf);
    if(ret){
        return __func__;
    }
    for(i=0; i < 9; i++){
        if (i == 1) {
            if (buf[i] != 3){
                return __func__;
            }
        }else{
            if (buf[i] != 0){
                return __func__;
            }
        }
    }
    return ((void *)0);
}


decompiled_code:
const char *test_rotate_ok()
{
char v0; // dl
const char *result; // rax
int v2; // edx
__int64 i; // rax
__int64 v4[4]; // [rsp+0h] [rbp-38h] BYREF
int v5; // [rsp+20h] [rbp-18h]

v4[0] = 0LL;
v4[1] = 0LL;
v4[2] = 0LL;
v4[3] = 0LL;
v5 = 0;
v0 = rotate(1LL, v4);
result = "test_rotate_ok";
if ( v0 )
{
v2 = 1;
for ( i = 0LL; ; ++i )
{
if ( (_DWORD)i == 1 )
{
if ( HIDWORD(v4[0]) != 1 )
return "test_rotate_ok";
}
else
{
if ( *((_DWORD *)v4 + i) )
return "test_rotate_ok";
if ( v2 > 8 )
return 0LL;
}
++v2;
}
}
return result;
}

canonical_decompiled_code:
const char *func20()
{
char v0; // dl
const char *result; // rax
int v2; // edx
__int64 i; // rax
__int64 v4[4]; // [rsp+0h] [rbp-38h] BYREF
int v5; // [rsp+20h] [rbp-18h]

v4[0] = 0LL;
v4[1] = 0LL;
v4[2] = 0LL;
v4[3] = 0LL;
v5 = 0;
v0 = rotate(1LL, v4);
result = "test_rotate_ok";
if ( v0 )
{
v2 = 1;
for ( i = 0LL; ; ++i )
{
if ( (_DWORD)i == 1 )
{
if ( HIDWORD(v4[0]) != 1 )
return "test_rotate_ok";
}
else
{
if ( *((_DWORD *)v4 + i) )
return "test_rotate_ok";
if ( v2 > 8 )
return 0LL;
}
++v2;
}
}
return result;
}

original_code:
static
const_char_p
test_rotate_ok(void)
{
    int buf[9] = {0,0,0,0,0,0,0,0,0,};
    int i;
    _Bool ret;
    ret = rotate(1, buf);
    if(!ret){
        return __func__;
    }
    for(i=0; i < 9; i++){
        if (i == 1) {
            if (buf[i] != 1){
                return __func__;
            }
        }else{
            if (buf[i] != 0){
                return __func__;
            }
        }
    }
    return ((void *)0);
}

canonical_original_code:
static char *test_rotate_ok()
{
    int buf[9] = {0,0,0,0,0,0,0,0,0,};
    int i;
    _Bool ret;
    ret = rotate(1, buf);
    if(!ret){
        return __func__;
    }
    for(i=0; i < 9; i++){
        if (i == 1) {
            if (buf[i] != 1){
                return __func__;
            }
        }else{
            if (buf[i] != 0){
                return __func__;
            }
        }
    }
    return ((void *)0);
}